{"version":3,"file":"context-handoff.d.ts","sourceRoot":"","sources":["../../../../src/core/long-horizon/adaptive/context-handoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACzC,gBAAgB,EAAE,SAAS;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrE,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,qBAAqB,EAAE,SAAS;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACzE,mBAAmB,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gBAAgB,EAAE,SAAS,CAAC,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,MAAM,CAAC,EAAE,CAAC;CAC/E;AAED,MAAM,WAAW,gBAAgB;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB;AAMD,uGAAuG;AACvG,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,gBAAgB,CAqB7E;AAoBD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE;;;EAWhH","sourcesContent":["/**\n * Context handoff and synthesis.\n *\n * A typed context packet for subagents and model-role transitions. Contains\n * only the objective, relevant criteria, selected evidence, selected file\n * references, structured state, bounded recent failures, explicit constraints,\n * and the required output schema — never full hidden reasoning, unrelated\n * transcript, unbounded logs, secrets, or stale cached conclusions as\n * authority. Subagent results are claims that the parent must validate.\n */\n\nimport type { AcceptanceCriterion } from \"./types.js\";\n\nexport interface ContextPacket {\n\tobjective: string;\n\tcriteria: readonly AcceptanceCriterion[];\n\tselectedEvidence: readonly { evidenceId: string; summary: string }[];\n\tselectedFileRefs: readonly string[];\n\tstructuredState: Record<string, unknown>;\n\tboundedRecentFailures: readonly { fingerprint: string; count: number }[];\n\texplicitConstraints: readonly string[];\n\trequiredOutputSchema?: string;\n\tforbiddenContent: readonly (\"secrets\" | \"reasoning\" | \"transcript\" | \"logs\")[];\n}\n\nexport interface PacketValidation {\n\tvalid: boolean;\n\treasons: string[];\n}\n\nconst TOO_MANY_FILES = 128;\nconst TOO_MANY_EVIDENCE = 256;\nconst MAX_FAILURE_ENTRIES = 16;\n\n/** Deterministically validate that a packet is bounded and contains no forbidden sensitive content. */\nexport function validateContextPacket(packet: ContextPacket): PacketValidation {\n\tconst reasons: string[] = [];\n\tif (!packet.objective || packet.objective.trim().length === 0) {\n\t\treasons.push(\"OBJECTIVE_REQUIRED\");\n\t}\n\tif (packet.selectedFileRefs.length > TOO_MANY_FILES) {\n\t\treasons.push(\"TOO_MANY_FILES\");\n\t}\n\tif (packet.selectedEvidence.length > TOO_MANY_EVIDENCE) {\n\t\treasons.push(\"TOO_MANY_EVIDENCE\");\n\t}\n\tif (packet.boundedRecentFailures.length > MAX_FAILURE_ENTRIES) {\n\t\treasons.push(\"TOO_MANY_FAILURES\");\n\t}\n\tif (packet.forbiddenContent.includes(\"secrets\") && hasSecretPattern(packet)) {\n\t\treasons.push(\"SECRET_CANDIDATE_IN_PACKET\");\n\t}\n\tif (packet.forbiddenContent.includes(\"reasoning\") && packet.structuredState.chainOfThought) {\n\t\treasons.push(\"HIDDEN_REASONING_IN_PACKET\");\n\t}\n\treturn { valid: reasons.length === 0, reasons };\n}\n\nfunction hasSecretPattern(packet: ContextPacket): boolean {\n\tconst sensitiveKeys = [\"apiKey\", \"token\", \"secret\", \"password\", \"privateKey\", \"credential\"];\n\tconst values: string[] = [];\n\tconst collect = (obj: unknown): void => {\n\t\tif (typeof obj === \"string\") values.push(obj);\n\t\telse if (obj && typeof obj === \"object\") {\n\t\t\tfor (const value of Object.values(obj as Record<string, unknown>)) collect(value);\n\t\t}\n\t};\n\tcollect(packet.structuredState);\n\tfor (const key of sensitiveKeys) {\n\t\tif (Object.hasOwn(packet.structuredState, key)) {\n\t\t\tif (typeof packet.structuredState[key] === \"string\") return true;\n\t\t}\n\t}\n\treturn values.some((v) => /(?:^|[^a-z0-9])(?:sk-|ghp_|Bearer\\s+)/iu.test(v));\n}\n\n/**\n * Reconcile contradictory child results: a deterministic claim validator.\n * The parent is authoritative — contradictory or unverifiable results become\n * explicit unresolved findings, never silently merged truth.\n */\nexport function reconcileChildResults(claims: readonly { childId: string; claim: unknown; supported?: boolean }[]) {\n\tconst contradictions: string[] = [];\n\tconst accepted: string[] = [];\n\tfor (const c of claims) {\n\t\tif (c.supported === false) {\n\t\t\tcontradictions.push(`${c.childId}:unsupported-claim`);\n\t\t} else {\n\t\t\taccepted.push(c.childId);\n\t\t}\n\t}\n\treturn { accepted, contradictions };\n}\n"]}