// src/profile/fingerprint.ts
async function sha256Hex(text) {
  const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text));
  return Array.from(new Uint8Array(digest)).map((byte) => byte.toString(16).padStart(2, "0")).join("");
}
async function fingerprintAgentProfile(profile, context) {
  const systemPrompt = profile.prompt?.systemPrompt ?? "";
  const promptSha = await sha256Hex(systemPrompt);
  const mcpKeys = Object.keys(profile.mcp ?? {}).sort();
  const subagentNames = Object.keys(profile.subagents ?? {}).sort();
  const fileMountPaths = (profile.resources?.files ?? []).map((mount) => mount.path).sort();
  const connectionIds = (profile.connections ?? []).map((connection) => connection.alias ? `${connection.connectionId}:${connection.alias}` : connection.connectionId).sort();
  const hash = await sha256Hex(
    JSON.stringify([
      promptSha,
      mcpKeys,
      subagentNames,
      fileMountPaths,
      connectionIds,
      context?.model ?? null,
      context?.harness ?? null
    ])
  );
  return {
    hash,
    promptSha,
    promptBytes: new TextEncoder().encode(systemPrompt).length,
    mcpKeys,
    subagentNames,
    fileMountPaths,
    connectionIds,
    model: context?.model,
    harness: context?.harness
  };
}
function channelValue(fingerprint, channel) {
  const value = fingerprint[channel];
  if (Array.isArray(value)) return value.length === 0 ? "(none)" : value.join(",");
  return String(value ?? "(unset)");
}
var DRIFT_CHANNELS = [
  "promptSha",
  "promptBytes",
  "mcpKeys",
  "subagentNames",
  "fileMountPaths",
  "connectionIds",
  "model",
  "harness"
];
function diffProfileFingerprints(a, b) {
  const drift = [];
  for (const channel of DRIFT_CHANNELS) {
    const left = channelValue(a, channel);
    const right = channelValue(b, channel);
    if (left !== right) drift.push({ channel, a: left, b: right });
  }
  return { equal: drift.length === 0, drift };
}
function formatProfileDrift(drift) {
  if (drift.equal) return "profiles identical";
  const lines = drift.drift.map((entry) => `  ${entry.channel}: ${entry.a} != ${entry.b}`);
  return `profile drift on ${drift.drift.length} channel(s):
${lines.join("\n")}`;
}

export {
  fingerprintAgentProfile,
  diffProfileFingerprints,
  formatProfileDrift
};
//# sourceMappingURL=chunk-IVUN7FL7.js.map