@ponythewhite/base-context 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/base-context-runtime/pyproject.toml +1 -1
- package/dist/base-context-runtime/src/rlm/__init__.py +3 -0
- package/dist/base-context-runtime/src/rlm/harness.py +86 -48
- package/dist/base-context-runtime/test/test_harness.py +215 -140
- package/dist/base-context-runtime/uv.lock +1 -1
- package/dist/build-info.json +1 -1
- package/dist/bundle/amazon-bedrock.js +3 -3
- package/dist/bundle/{anthropic-UV5GZDGU.js → anthropic-5PSCZEER.js} +2 -7
- package/dist/bundle/{azure-openai-responses-WSNPXLYC.js → azure-openai-responses-AYTLJR33.js} +2 -2
- package/dist/bundle/{bundled-modules-PS66L3IT.js → bundled-modules-IGMJH2MU.js} +5 -5
- package/dist/bundle/{chunk-UPVDERMD.js → chunk-2IPDSTDR.js} +11 -9
- package/dist/bundle/chunk-D3KOF57W.js +22040 -0
- package/dist/bundle/{chunk-VCW3YDFF.js → chunk-EXEFSSF4.js} +1475 -562
- package/dist/bundle/{chunk-VSIYFWYI.js → chunk-KT2BNEPE.js} +21 -8
- package/dist/bundle/{chunk-KTNETTHI.js → chunk-Q3MBSBEB.js} +3 -101
- package/dist/bundle/{chunk-LFPWHI42.js → chunk-QKIFBA7N.js} +2 -2
- package/dist/bundle/{chunk-PFROC4EV.js → chunk-RVJVXZCS.js} +12 -9
- package/dist/bundle/{cli-main-MMHTK7EB.js → cli-main-BUK7QTHO.js} +4 -4
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/{google-T32FMD4G.js → google-HTMCUJ7X.js} +2 -2
- package/dist/bundle/{google-vertex-56KP6I3B.js → google-vertex-ZQO65AXF.js} +2 -2
- package/dist/bundle/{main-XAIVH4Y7.js → main-2FWHT2WZ.js} +5 -5
- package/dist/bundle/{mistral-WGBMYIVU.js → mistral-SB7LU56G.js} +1 -1
- package/dist/bundle/{openai-codex-responses-PIV2RQ3G.js → openai-codex-responses-5CEW4VN3.js} +53 -27
- package/dist/bundle/{openai-completions-64C3JPR4.js → openai-completions-BAZJQSS2.js} +1 -1
- package/dist/bundle/{openai-responses-UI7RSTDV.js → openai-responses-VHOE427P.js} +48 -5
- package/dist/core/agent-session.d.ts +6 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +177 -24
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/canonical-context.d.ts +8 -0
- package/dist/core/canonical-context.d.ts.map +1 -1
- package/dist/core/canonical-context.js +37 -5
- package/dist/core/canonical-context.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +2 -2
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +31 -13
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/context-epoch.d.ts +1 -1
- package/dist/core/context-epoch.d.ts.map +1 -1
- package/dist/core/context-epoch.js +2 -1
- package/dist/core/context-epoch.js.map +1 -1
- package/dist/core/extensions/types.d.ts +2 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/history-index-worker.d.ts.map +1 -1
- package/dist/core/history-index-worker.js +29 -8
- package/dist/core/history-index-worker.js.map +1 -1
- package/dist/core/history-index.d.ts +11 -1
- package/dist/core/history-index.d.ts.map +1 -1
- package/dist/core/history-index.js +2 -1
- package/dist/core/history-index.js.map +1 -1
- package/dist/core/inference-coordinator.d.ts.map +1 -1
- package/dist/core/inference-coordinator.js +108 -13
- package/dist/core/inference-coordinator.js.map +1 -1
- package/dist/core/kernel/bootstrap.d.ts.map +1 -1
- package/dist/core/kernel/bootstrap.js +97 -107
- package/dist/core/kernel/bootstrap.js.map +1 -1
- package/dist/core/kernel/repl-manager.d.ts.map +1 -1
- package/dist/core/kernel/repl-manager.js +11 -0
- package/dist/core/kernel/repl-manager.js.map +1 -1
- package/dist/core/kernel/shared.d.ts +2 -0
- package/dist/core/kernel/shared.d.ts.map +1 -1
- package/dist/core/kernel/shared.js.map +1 -1
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +4 -1
- package/dist/core/messages.js.map +1 -1
- package/dist/core/prompts/rlm.d.ts.map +1 -1
- package/dist/core/prompts/rlm.js +4 -2
- package/dist/core/prompts/rlm.js.map +1 -1
- package/dist/core/public-context.d.ts.map +1 -1
- package/dist/core/public-context.js +16 -0
- package/dist/core/public-context.js.map +1 -1
- package/dist/core/refinement/refinement.d.ts +19 -5
- package/dist/core/refinement/refinement.d.ts.map +1 -1
- package/dist/core/refinement/refinement.js +90 -35
- package/dist/core/refinement/refinement.js.map +1 -1
- package/dist/core/request-view-selection.d.ts +10 -2
- package/dist/core/request-view-selection.d.ts.map +1 -1
- package/dist/core/request-view-selection.js +235 -100
- package/dist/core/request-view-selection.js.map +1 -1
- package/dist/core/retained-tool-output.d.ts +28 -0
- package/dist/core/retained-tool-output.d.ts.map +1 -0
- package/dist/core/retained-tool-output.js +102 -0
- package/dist/core/retained-tool-output.js.map +1 -0
- package/dist/core/selective-recovery.d.ts +47 -3
- package/dist/core/selective-recovery.d.ts.map +1 -1
- package/dist/core/selective-recovery.js +428 -109
- package/dist/core/selective-recovery.js.map +1 -1
- package/dist/core/session-history-index.d.ts +3 -1
- package/dist/core/session-history-index.d.ts.map +1 -1
- package/dist/core/session-history-index.js +1 -1
- package/dist/core/session-history-index.js.map +1 -1
- package/dist/core/settings-manager.d.ts +5 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +3 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/system-prompt.d.ts +3 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +3 -3
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/task-frame.d.ts +1 -1
- package/dist/core/task-frame.d.ts.map +1 -1
- package/dist/core/task-frame.js +21 -1
- package/dist/core/task-frame.js.map +1 -1
- package/dist/core/task-state-reader.d.ts +10 -2
- package/dist/core/task-state-reader.d.ts.map +1 -1
- package/dist/core/task-state-reader.js +75 -9
- package/dist/core/task-state-reader.js.map +1 -1
- package/dist/core/tools/ipython.d.ts +5 -0
- package/dist/core/tools/ipython.d.ts.map +1 -1
- package/dist/core/tools/ipython.js +59 -17
- package/dist/core/tools/ipython.js.map +1 -1
- package/dist/core/tools/prime-context.d.ts.map +1 -1
- package/dist/core/tools/prime-context.js +1 -1
- package/dist/core/tools/prime-context.js.map +1 -1
- package/dist/core/view-units.d.ts +4 -0
- package/dist/core/view-units.d.ts.map +1 -1
- package/dist/core/view-units.js +28 -19
- package/dist/core/view-units.js.map +1 -1
- package/dist/installer.mjs +98 -77
- package/dist/modes/interactive/components/refinement-outcome-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/refinement-outcome-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +5 -5
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/skills/skill-creator/SKILL.md +18 -1
- package/docs/settings.md +45 -0
- package/docs/skills.md +77 -2
- package/package.json +4 -4
- package/skills/skill-creator/SKILL.md +18 -1
- package/dist/bundle/chunk-W46VZFI6.js +0 -21681
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selective-recovery.js","sourceRoot":"","sources":["../../src/core/selective-recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACxF,O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,CAAC,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC;YACrF,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;YACpB,+BAA+B,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;YACpE,aAAa,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QACxC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,MAAM,GACX,KAAK,YAAY,2BAA2B;gBAC5C,CAAC,KAAK,YAAY,KAAK,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YACjE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CACnB,CAAC,EACD,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,aAAa,EACzC,SAAS,EACT,EAAE,EACF,MAAM,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,8BAA8B,CAC1F,CAAC;QACH,CAAC;IACF,CAAC;IACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC1C,+BAA+B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACpD,OAAO,QAAQ,CAAC;AAAA,CAChB","sourcesContent":["import { StringEnum } from \"@ponythewhite/base-context-ai\";\nimport { type Static, Type } from \"typebox\";\nimport { Value } from \"typebox/value\";\nimport { AGENT_RESULT_CUSTOM_TYPE } from \"./agent-results.js\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { IndexedSourceEvent } from \"./history-index.js\";\nimport { SELECTED_SKILL_CUSTOM_TYPE, selectedSkillCapture } from \"./selected-skills.js\";\nimport { hydrateCapturedHistoryEntry, type SessionHistoryReadView } from \"./session-history-index.js\";\nimport type { SessionEntry } from \"./session-manager.js\";\nimport { projectTaskStateSource } from \"./task-state.js\";\n\nexport interface NativeRecoveryLimits {\n\tmaxBytes: number;\n\tmaxSourceBytes: number;\n\tmaxItems: number;\n\tmaxRequests: number;\n}\n\n/** Defaults match bounded index pages and 64KiB payload parts; all admission units are bytes or items. */\nexport const DEFAULT_NATIVE_RECOVERY_LIMITS: Readonly<NativeRecoveryLimits> = Object.freeze({\n\tmaxBytes: 64 * 1024,\n\tmaxSourceBytes: 1024 * 1024,\n\tmaxItems: 16,\n\tmaxRequests: 8,\n});\n\nconst exactString = Type.String({ minLength: 1, maxLength: 512 });\nconst byteLimit = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });\nconst operationSchema = Type.Object(\n\t{\n\t\taction: Type.Union([Type.Literal(\"read\"), Type.Literal(\"search\"), Type.Literal(\"recover\")]),\n\t\tref: Type.Optional(exactString),\n\t\trevision: Type.Optional(exactString),\n\t\tsourceSessionId: Type.Optional(exactString),\n\t\tfield: Type.Optional(exactString),\n\t\tneed: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: 8192,\n\t\t\t\tdescription:\n\t\t\t\t\t\"Literal text selector; alias of query. Prefer one field. If both are supplied, use identical text.\",\n\t\t\t}),\n\t\t),\n\t\tquery: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: 8192,\n\t\t\t\tdescription:\n\t\t\t\t\t\"Literal text selector; alias of need. Prefer one field. If both are supplied, use identical text.\",\n\t\t\t}),\n\t\t),\n\t\tstartLine: Type.Optional(byteLimit),\n\t\tendLine: Type.Optional(byteLimit),\n\t\tmaxBytes: Type.Optional(byteLimit),\n\t},\n\t{ additionalProperties: false },\n);\n\n/** A ref is a case-sensitive entry ID, never a path. Lines are one-based within each selected field. */\nexport const nativeRecoveryInputSchema = Type.Union([\n\toperationSchema,\n\tType.Object(\n\t\t{ action: Type.Literal(\"skill\"), name: exactString, maxBytes: Type.Optional(byteLimit) },\n\t\t{ additionalProperties: false },\n\t),\n\tType.Object(\n\t\t{\n\t\t\taction: Type.Literal(\"batch\"),\n\t\t\trequests: Type.Array(operationSchema, { minItems: 1, maxItems: 8 }),\n\t\t\tmaxBytes: Type.Optional(byteLimit),\n\t\t},\n\t\t{ additionalProperties: false },\n\t),\n]);\nconst providerOperationSchema = Type.Object(\n\t{ ...operationSchema.properties, action: StringEnum([\"read\", \"search\", \"recover\"] as const) },\n\t{ additionalProperties: false },\n);\n\n/** Provider-facing tools require an object root; execute still applies the strict union above. */\nexport const nativeRecoveryToolSchema = Type.Object(\n\t{\n\t\t...providerOperationSchema.properties,\n\t\taction: StringEnum([\"read\", \"search\", \"recover\", \"batch\", \"skill\"] as const),\n\t\tname: Type.Optional(exactString),\n\t\trequests: Type.Optional(Type.Array(providerOperationSchema, { minItems: 1, maxItems: 8 })),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type NativeRecoveryInput = Static<typeof nativeRecoveryInputSchema>;\nexport type NativeRecoveryOperation = Static<typeof operationSchema>;\nexport type NativeRecoveryStatus =\n\t| \"found\"\n\t| \"complete-miss\"\n\t| \"partial\"\n\t| \"not_authorized\"\n\t| \"unavailable\"\n\t| \"budget_refused\";\nexport type NativeRecoveryCoverage = \"complete\" | \"partial\" | \"unknown\";\nexport interface NativeRecoveryScope {\n\tkind: \"branch\";\n\t/** Missing coordinates mean capture was unavailable, not whole-source authority. */\n\tsourceSessionId?: string;\n\tleafId?: string | null;\n\tsourceSequence?: number;\n\tprojection: \"public-text-only\";\n}\nexport interface NativeRecoverySource {\n\tsourceSessionId: string;\n\tentryId: string;\n\trevision: string;\n\tfield: string;\n\tstartLine: number;\n\tendLine: number;\n}\nexport interface NativeRecoveryRecord extends Omit<NativeRecoverySource, \"entryId\"> {\n\tref: string;\n\tkind: string;\n\ttext: string;\n}\nexport interface NativeRecoveryResult {\n\trequestIndex: number;\n\tstatus: NativeRecoveryStatus;\n\tcoverage: NativeRecoveryCoverage;\n\trecords: NativeRecoveryRecord[];\n\treason?: string;\n}\nexport interface NativeRecoveryResponse {\n\tkind: \"native-recovery\";\n\tversion: 1;\n\tnativeRecovery: 1;\n\tauthority: \"tool-data\";\n\tfreshness: \"unknown\";\n\tscope: NativeRecoveryScope;\n\tstatus: NativeRecoveryStatus;\n\tcoverage: NativeRecoveryCoverage;\n\tsources: NativeRecoverySource[];\n\tresults: NativeRecoveryResult[];\n\treason?: string;\n}\n\n/** A cap smaller than the refusal envelope cannot be satisfied by returning clipped JSON. */\nexport class NativeRecoveryBudgetRefusal extends Error {\n\treadonly status = \"budget_refused\";\n\tconstructor() {\n\t\tsuper(\"Native recovery byte or item budget refused\");\n\t\tthis.name = \"NativeRecoveryBudgetRefusal\";\n\t}\n}\n\nexport function stringifyNativeRecoveryResponse(\n\tresponse: NativeRecoveryResponse,\n\tmaxBytes = DEFAULT_NATIVE_RECOVERY_LIMITS.maxBytes,\n): string {\n\ttry {\n\t\treturn stringifyBoundedJson(response, maxBytes);\n\t} catch {\n\t\tthrow new NativeRecoveryBudgetRefusal();\n\t}\n}\n\n/** Tool details carry reference metadata, not a second copy of the selected body. */\nexport function nativeRecoveryMetadata(response: NativeRecoveryResponse) {\n\treturn {\n\t\tkind: response.kind,\n\t\tversion: response.version,\n\t\tnativeRecovery: response.nativeRecovery,\n\t\tscope: response.scope,\n\t\tsources: response.sources,\n\t\tcoverage: response.coverage,\n\t\tauthority: response.authority,\n\t\tfreshness: response.freshness,\n\t\tstatus: response.status,\n\t};\n}\n\n/** Callers use fixed public reason codes, never raw exceptions or source locators. */\nexport function createNativeRecoveryRefusal(\n\tstatus: \"not_authorized\" | \"unavailable\" | \"budget_refused\",\n\treason: string,\n\tmaxBytes = DEFAULT_NATIVE_RECOVERY_LIMITS.maxBytes,\n): NativeRecoveryResponse {\n\tconst response: NativeRecoveryResponse = {\n\t\tkind: \"native-recovery\",\n\t\tversion: 1,\n\t\tnativeRecovery: 1,\n\t\tauthority: \"tool-data\",\n\t\tfreshness: \"unknown\",\n\t\tscope: { kind: \"branch\", projection: \"public-text-only\" },\n\t\tstatus,\n\t\tcoverage: \"unknown\",\n\t\tsources: [],\n\t\tresults: [],\n\t\treason,\n\t};\n\tstringifyNativeRecoveryResponse(response, maxBytes);\n\treturn response;\n}\n\ninterface PublicField {\n\tfield: string;\n\ttext: string;\n}\nfunction object(value: unknown): Record<string, unknown> | undefined {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)\n\t\t: undefined;\n}\n\n/** Select known public string fields; never traverse executed-input/provider envelopes, signatures or thinking. */\nfunction publicFields(\n\tentry: SessionEntry,\n\tmaxItems: number,\n\tqualification?: IndexedSourceEvent[\"qualification\"],\n): PublicField[] | undefined {\n\tif (entry.type === \"compaction\" || entry.type === \"branch_summary\") {\n\t\treturn typeof entry.summary === \"string\" ? [{ field: \"/summary\", text: entry.summary }] : undefined;\n\t}\n\tif (\n\t\tentry.type === \"custom\" &&\n\t\tentry.customType === AGENT_RESULT_CUSTOM_TYPE &&\n\t\tqualification === \"native-recovery\"\n\t) {\n\t\tconst findings = object(entry.data)?.findings;\n\t\treturn typeof findings === \"string\" ? [{ field: \"/data/findings\", text: findings }] : undefined;\n\t}\n\tlet content: unknown;\n\tlet field: string;\n\tlet role: unknown;\n\tif (\n\t\t(entry.type === \"custom\" || entry.type === \"custom_message\") &&\n\t\tqualification === \"native-recovery\" &&\n\t\tentry.customType === SELECTED_SKILL_CUSTOM_TYPE\n\t) {\n\t\tconst skill = selectedSkillCapture(entry);\n\t\tif (skill)\n\t\t\treturn [\n\t\t\t\t{ field: entry.type === \"custom\" ? \"/data/content\" : \"/content\", text: skill.content },\n\t\t\t\t{\n\t\t\t\t\tfield: `/${entry.type === \"custom\" ? \"data\" : \"details\"}/baseContextSelectedSkill/descriptor`,\n\t\t\t\t\ttext: JSON.stringify({ ...skill.descriptor, sourceInfo: undefined }),\n\t\t\t\t},\n\t\t\t];\n\t}\n\tif (entry.type === \"custom_message\") {\n\t\tcontent = entry.content;\n\t\tfield = \"/content\";\n\t\trole = \"custom\";\n\t} else if (entry.type === \"message\") {\n\t\tconst message = object(entry.message);\n\t\tif (!message || ![\"user\", \"assistant\", \"toolResult\", \"custom\"].includes(String(message.role))) return undefined;\n\t\tcontent = message.content;\n\t\trole = message.role;\n\t\tfield = \"/message/content\";\n\t} else return undefined;\n\tif (typeof content === \"string\") {\n\t\treturn role === \"user\" || role === \"custom\" ? [{ field, text: content }] : undefined;\n\t}\n\tif (!Array.isArray(content)) return undefined;\n\tif (content.length > maxItems) throw new NativeRecoveryBudgetRefusal();\n\tconst fields: PublicField[] = [];\n\tfor (let i = 0; i < content.length; i++) {\n\t\tconst block = object(content[i]);\n\t\tif (!block) return undefined;\n\t\tif (block.type === \"text\" && typeof block.text === \"string\") {\n\t\t\tif (fields.length >= maxItems) throw new NativeRecoveryBudgetRefusal();\n\t\t\tfields.push({ field: `${field}/${i}/text`, text: block.text });\n\t\t} else if (block.type === \"thinking\" && role === \"assistant\" && typeof block.thinking === \"string\") {\n\t\t\t// Thinking is unsupported by this v1 projection; this does not classify all thinking text as private.\n\t\t} else if (\n\t\t\tblock.type === \"toolCall\" &&\n\t\t\trole === \"assistant\" &&\n\t\t\ttypeof block.id === \"string\" &&\n\t\t\ttypeof block.name === \"string\" &&\n\t\t\tobject(block.arguments)\n\t\t) {\n\t\t\t// Assistant-authored string arguments are public action data, not executed-input/auth envelopes.\n\t\t\tconst arguments_ = block.arguments as Record<string, unknown>;\n\t\t\tlet visited = 0;\n\t\t\tfor (const key in arguments_) {\n\t\t\t\tif (!Object.hasOwn(arguments_, key)) continue;\n\t\t\t\tif (++visited > maxItems) throw new NativeRecoveryBudgetRefusal();\n\t\t\t\tconst value = arguments_[key];\n\t\t\t\t// v1 does not select nested/non-string argument fields; it does not label them private.\n\t\t\t\tif (typeof value !== \"string\") continue;\n\t\t\t\tif (fields.length >= maxItems) throw new NativeRecoveryBudgetRefusal();\n\t\t\t\tconst escaped = key.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n\t\t\t\tfields.push({ field: `${field}/${i}/arguments/${escaped}`, text: value });\n\t\t\t}\n\t\t} else if (\n\t\t\tblock.type === \"image\" &&\n\t\t\trole !== \"assistant\" &&\n\t\t\ttypeof block.data === \"string\" &&\n\t\t\ttypeof block.mimeType === \"string\"\n\t\t) {\n\t\t\t// This API selects text only; it makes no lossless multimodal claim.\n\t\t} else return undefined;\n\t}\n\treturn fields;\n}\n\nfunction outcome(\n\trequestIndex: number,\n\tstatus: NativeRecoveryStatus,\n\tcoverage: NativeRecoveryCoverage = \"unknown\",\n\trecords: NativeRecoveryRecord[] = [],\n\treason?: string,\n): NativeRecoveryResult {\n\treturn { requestIndex, status, coverage, records, ...(reason ? { reason } : {}) };\n}\n\nfunction assemble(scope: NativeRecoveryScope, results: NativeRecoveryResult[]): NativeRecoveryResponse {\n\tconst statuses = new Set(results.map((result) => result.status));\n\tconst status =\n\t\tstatuses.size === 1\n\t\t\t? results[0].status\n\t\t\t: results.every((result) => result.status === \"found\" || result.status === \"complete-miss\")\n\t\t\t\t? \"found\"\n\t\t\t\t: \"partial\";\n\tconst coverage = results.every((result) => result.coverage === \"complete\")\n\t\t? \"complete\"\n\t\t: results.some((result) => result.coverage === \"partial\")\n\t\t\t? \"partial\"\n\t\t\t: \"unknown\";\n\treturn {\n\t\tkind: \"native-recovery\",\n\t\tversion: 1,\n\t\tnativeRecovery: 1,\n\t\tauthority: \"tool-data\",\n\t\tfreshness: \"unknown\",\n\t\tscope,\n\t\tstatus,\n\t\tcoverage,\n\t\tresults,\n\t\tsources: results.flatMap((result) =>\n\t\t\tresult.records.map((record) => ({\n\t\t\t\tsourceSessionId: record.sourceSessionId,\n\t\t\t\tentryId: record.ref,\n\t\t\t\trevision: record.revision,\n\t\t\t\tfield: record.field,\n\t\t\t\tstartLine: record.startLine,\n\t\t\t\tendLine: record.endLine,\n\t\t\t})),\n\t\t),\n\t};\n}\n\n/** Shared runtime admission for the native tool and Python host bridge. */\nexport function parseNativeRecoveryInput(value: unknown): NativeRecoveryInput {\n\tlet request: NativeRecoveryInput;\n\ttry {\n\t\trequest = JSON.parse(stringifyBoundedJson(value, 128 * 1024)) as NativeRecoveryInput;\n\t} catch {\n\t\tthrow new NativeRecoveryBudgetRefusal();\n\t}\n\tif (!Value.Check(nativeRecoveryInputSchema, request)) throw new Error(\"Invalid native recovery request\");\n\treturn request;\n}\n\n/** The caller captures ONE server branch before entering this service, including for a batch. */\nexport async function recoverCapturedHistory(\n\tview: SessionHistoryReadView,\n\tinput: NativeRecoveryInput,\n\tlimits: NativeRecoveryLimits = DEFAULT_NATIVE_RECOVERY_LIMITS,\n\tsignal?: AbortSignal,\n): Promise<NativeRecoveryResponse> {\n\tconst cap = { ...limits };\n\tfor (const key of [\"maxBytes\", \"maxSourceBytes\", \"maxItems\", \"maxRequests\"] as const) {\n\t\tif (!Number.isSafeInteger(cap[key]) || cap[key] < 1) throw new NativeRecoveryBudgetRefusal();\n\t\tcap[key] = Math.min(cap[key], DEFAULT_NATIVE_RECOVERY_LIMITS[key]);\n\t}\n\t// Bound and detach input before schema traversal or the first await. Unknown selectors are rejected.\n\tlet request: NativeRecoveryInput;\n\ttry {\n\t\trequest = parseNativeRecoveryInput(input);\n\t} catch (error) {\n\t\treturn createNativeRecoveryRefusal(\n\t\t\terror instanceof NativeRecoveryBudgetRefusal ? \"budget_refused\" : \"unavailable\",\n\t\t\t\"invalid_request\",\n\t\t\tcap.maxBytes,\n\t\t);\n\t}\n\tconst maxBytes = Math.min(cap.maxBytes, request.maxBytes ?? cap.maxBytes);\n\tconst { sessionId: sourceSessionId, leafId, sourceSequence } = view.source;\n\tconst scope: NativeRecoveryScope = {\n\t\tkind: \"branch\",\n\t\tprojection: \"public-text-only\",\n\t\tsourceSessionId,\n\t\tleafId,\n\t\tsourceSequence,\n\t};\n\tif (request.action === \"skill\")\n\t\treturn createNativeRecoveryRefusal(\"not_authorized\", \"native_skill_selection_owner_required\", maxBytes);\n\tconst operations = request.action === \"batch\" ? request.requests : [request];\n\tconst results = operations.map((_, i) => outcome(i, \"budget_refused\", \"unknown\", [], \"not_admitted\"));\n\t// Reserve an explicit result for EVERY requested operation before touching canonical payloads.\n\tstringifyNativeRecoveryResponse(assemble(scope, results), maxBytes);\n\tif (operations.length > cap.maxRequests) return assemble(scope, results);\n\tlet sourceBytes = 0;\n\tlet examined = 0;\n\tlet selectedItems = 0;\n\tconst cache = new Map<string, { revision: string; entry: SessionEntry }>();\n\n\tasync function fieldsFor(metadata: IndexedSourceEvent, requestedField?: string): Promise<PublicField[] | undefined> {\n\t\tsignal?.throwIfAborted();\n\t\tlet cached = cache.get(metadata.id);\n\t\tif (cached && cached.revision !== metadata.revision) throw new Error(\"Captured revision changed\");\n\t\tif (!cached) {\n\t\t\tif (++examined > cap.maxItems || metadata.locator.length > cap.maxSourceBytes - sourceBytes) {\n\t\t\t\tthrow new NativeRecoveryBudgetRefusal();\n\t\t\t}\n\t\t\tsourceBytes += metadata.locator.length;\n\t\t\tconst hydrated = await hydrateCapturedHistoryEntry(metadata, metadata.locator.length, async (id, options) => {\n\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\treturn view.readPayload(id, options);\n\t\t\t});\n\t\t\tsignal?.throwIfAborted();\n\t\t\tcached = { revision: metadata.revision, entry: hydrated.entry };\n\t\t\tcache.set(metadata.id, cached);\n\t\t}\n\t\tif (requestedField === \"/nativeOrigin/submitted/text\") {\n\t\t\tif (\n\t\t\t\tcached.entry.type !== \"message\" ||\n\t\t\t\tmetadata.qualification !== \"native-admission\" ||\n\t\t\t\tmetadata.retention === \"retained-import\"\n\t\t\t)\n\t\t\t\treturn undefined;\n\t\t\t// Reuse the existing exact native-input qualification, not generic origin traversal.\n\t\t\t// The first qualifying projection is submitted.text; return before visiting content parts.\n\t\t\tfor (const projection of projectTaskStateSource({\n\t\t\t\tsessionId: sourceSessionId,\n\t\t\t\tsequence: metadata.sequence,\n\t\t\t\trevision: metadata.revision,\n\t\t\t\tqualification: metadata.qualification,\n\t\t\t\tretention: metadata.retention,\n\t\t\t\tentry: cached.entry,\n\t\t\t})) {\n\t\t\t\tif (\n\t\t\t\t\tprojection.source.field === requestedField &&\n\t\t\t\t\tprojection.authority === \"user\" &&\n\t\t\t\t\tprojection.attribution === \"source-backed\" &&\n\t\t\t\t\ttypeof projection.text === \"string\"\n\t\t\t\t) {\n\t\t\t\t\treturn [{ field: requestedField, text: projection.text }];\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t\treturn publicFields(cached.entry, cap.maxItems, metadata.qualification);\n\t}\n\n\tasync function recover(operation: NativeRecoveryOperation, i: number): Promise<NativeRecoveryResult> {\n\t\tif (operation.sourceSessionId !== undefined && operation.sourceSessionId !== scope.sourceSessionId) {\n\t\t\treturn outcome(i, \"not_authorized\", \"unknown\", [], \"source_not_in_capture\");\n\t\t}\n\t\tif (\n\t\t\t(operation.need !== undefined && operation.query !== undefined && operation.need !== operation.query) ||\n\t\t\t(operation.endLine !== undefined && operation.endLine < (operation.startLine ?? 1))\n\t\t) {\n\t\t\treturn outcome(i, \"unavailable\", \"unknown\", [], \"conflicting_selection\");\n\t\t}\n\t\tconst needle = operation.need ?? operation.query;\n\t\tlet candidates: IndexedSourceEvent[];\n\t\tlet coverage: NativeRecoveryCoverage;\n\t\tif (operation.ref !== undefined) {\n\t\t\tconst metadata = await view.get(operation.ref);\n\t\t\tif (!metadata || metadata.id !== operation.ref) {\n\t\t\t\treturn outcome(i, \"not_authorized\", \"unknown\", [], \"ref_not_in_captured_branch\");\n\t\t\t}\n\t\t\tif (operation.revision !== undefined && operation.revision !== metadata.revision) {\n\t\t\t\treturn outcome(i, \"unavailable\", \"unknown\", [], \"revision_mismatch\");\n\t\t\t}\n\t\t\tcandidates = [metadata];\n\t\t\tcoverage = \"complete\";\n\t\t} else {\n\t\t\tif (\n\t\t\t\toperation.action === \"read\" ||\n\t\t\t\tneedle === undefined ||\n\t\t\t\toperation.revision !== undefined ||\n\t\t\t\toperation.field !== undefined ||\n\t\t\t\toperation.startLine !== undefined ||\n\t\t\t\toperation.endLine !== undefined\n\t\t\t) {\n\t\t\t\treturn outcome(i, \"unavailable\", \"unknown\", [], \"exact_selection_requires_ref\");\n\t\t\t}\n\t\t\tif (Buffer.byteLength(needle) > 8192) throw new NativeRecoveryBudgetRefusal();\n\t\t\tif (examined >= cap.maxItems) throw new NativeRecoveryBudgetRefusal();\n\t\t\tconst page = await view.search(needle, cap.maxItems - examined);\n\t\t\tcandidates = page.events;\n\t\t\t// Search indexes token conjunctions, including non-public strings. It is not an exhaustive\n\t\t\t// literal-substring search even when its indexed text coverage is reported complete.\n\t\t\tcoverage =\n\t\t\t\tpage.coverage === \"partial\" || page.truncated || page.indexedThrough < sourceSequence\n\t\t\t\t\t? \"partial\"\n\t\t\t\t\t: \"unknown\";\n\t\t}\n\t\tconst records: NativeRecoveryRecord[] = [];\n\t\tlet unavailable = false;\n\t\tlet beyondWindow = false;\n\t\tlet needWindow = false;\n\t\tfor (const metadata of candidates) {\n\t\t\tconst fields = await fieldsFor(metadata, operation.field);\n\t\t\tif (!fields || (operation.field !== undefined && !fields.some((field) => field.field === operation.field))) {\n\t\t\t\tunavailable = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const selected of fields) {\n\t\t\t\tif (operation.field !== undefined && operation.field !== selected.field) continue;\n\t\t\t\tconst lines = selected.text.split(\"\\n\");\n\t\t\t\tlet startLine = operation.startLine ?? 1;\n\t\t\t\tlet endLine = Math.min(operation.endLine ?? lines.length, lines.length);\n\t\t\t\tif (needle !== undefined && operation.startLine === undefined && operation.endLine === undefined) {\n\t\t\t\t\tconst first = selected.text.indexOf(needle);\n\t\t\t\t\tif (first < 0) continue;\n\t\t\t\t\t// Select whole exact lines containing the first literal occurrence, including every\n\t\t\t\t\t// line of a multiline needle. A required huge line is refused, never prefix-clipped.\n\t\t\t\t\tstartLine = selected.text.slice(0, first).split(\"\\n\").length;\n\t\t\t\t\tendLine = startLine + needle.split(\"\\n\").length - 1;\n\t\t\t\t\tif (startLine > 1 || endLine < lines.length) needWindow = true;\n\t\t\t\t}\n\t\t\t\tif (startLine > lines.length) continue;\n\t\t\t\tconst text = lines.slice(startLine - 1, endLine).join(\"\\n\");\n\t\t\t\tif (needle !== undefined && !text.includes(needle)) continue;\n\t\t\t\tif (operation.endLine !== undefined && operation.endLine > lines.length) beyondWindow = true;\n\t\t\t\tif (selectedItems + records.length >= cap.maxItems) throw new NativeRecoveryBudgetRefusal();\n\t\t\t\trecords.push({\n\t\t\t\t\tref: metadata.id,\n\t\t\t\t\trevision: metadata.revision,\n\t\t\t\t\tsourceSessionId,\n\t\t\t\t\tkind: metadata.kind,\n\t\t\t\t\tfield: selected.field,\n\t\t\t\t\tstartLine,\n\t\t\t\t\tendLine,\n\t\t\t\t\ttext,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (operation.ref !== undefined && unavailable)\n\t\t\treturn outcome(i, \"unavailable\", \"unknown\", [], \"unsupported_public_field\");\n\t\tif (unavailable || beyondWindow || needWindow) coverage = \"partial\";\n\t\tconst status = coverage === \"complete\" ? (records.length ? \"found\" : \"complete-miss\") : \"partial\";\n\t\treturn outcome(\n\t\t\ti,\n\t\t\tstatus,\n\t\t\tcoverage,\n\t\t\trecords,\n\t\t\tcoverage === \"unknown\"\n\t\t\t\t? \"candidate_search_not_exhaustive\"\n\t\t\t\t: unavailable\n\t\t\t\t\t? \"unsupported_public_shape\"\n\t\t\t\t\t: beyondWindow\n\t\t\t\t\t\t? \"requested_end_beyond_source\"\n\t\t\t\t\t\t: needWindow\n\t\t\t\t\t\t\t? \"need_window\"\n\t\t\t\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\tfor (let i = 0; i < operations.length; i++) {\n\t\ttry {\n\t\t\tsignal?.throwIfAborted();\n\t\t\tconst result = await recover(operations[i], i);\n\t\t\tsignal?.throwIfAborted();\n\t\t\tstringifyBoundedJson(result, Math.min(maxBytes, operations[i].maxBytes ?? maxBytes));\n\t\t\tresults[i] = result;\n\t\t\tstringifyNativeRecoveryResponse(assemble(scope, results), maxBytes);\n\t\t\tselectedItems += result.records.length;\n\t\t} catch (error) {\n\t\t\tconst budget =\n\t\t\t\terror instanceof NativeRecoveryBudgetRefusal ||\n\t\t\t\t(error instanceof Error && /budget|limit/i.test(error.message));\n\t\t\tresults[i] = outcome(\n\t\t\t\ti,\n\t\t\t\tbudget ? \"budget_refused\" : \"unavailable\",\n\t\t\t\t\"unknown\",\n\t\t\t\t[],\n\t\t\t\tbudget ? \"operation_budget\" : signal?.aborted ? \"aborted\" : \"canonical_source_unavailable\",\n\t\t\t);\n\t\t}\n\t}\n\tconst response = assemble(scope, results);\n\tstringifyNativeRecoveryResponse(response, maxBytes);\n\treturn response;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"selective-recovery.js","sourceRoot":"","sources":["../../src/core/selective-recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,EACN,iBAAiB,EACjB,wBAAwB,EAExB,sBAAsB,EACtB,kBAAkB,GAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,2BAA2B,EAA+B,MAAM,4BAA4B,CAAC;AACtG,OAAO,EAAE,6BAA6B,EAAqB,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AASzD,0GAA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AAC,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC;YACrF,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;YACpB,+BAA+B,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;YACpE,aAAa,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QACxC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,MAAM,GACX,KAAK,YAAY,2BAA2B;gBAC5C,CAAC,KAAK,YAAY,KAAK,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YACjE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CACnB,CAAC,EACD,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,aAAa,EACzC,SAAS,EACT,EAAE,EACF,MAAM,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,8BAA8B,CAC1F,CAAC;QACH,CAAC;IACF,CAAC;IACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC1C,+BAA+B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACpD,OAAO,QAAQ,CAAC;AAAA,CAChB","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { StringEnum } from \"@ponythewhite/base-context-ai\";\nimport { type Static, Type } from \"typebox\";\nimport { Value } from \"typebox/value\";\nimport { AGENT_RESULT_CUSTOM_TYPE } from \"./agent-results.js\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { IndexedSourceEvent } from \"./history-index.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport {\n\tdecodedTextWindow,\n\tPUBLIC_TEXT_WINDOW_BYTES,\n\ttype RetainedToolOutput,\n\treadRetainedToolOutput,\n\tretainedToolOutput,\n} from \"./retained-tool-output.js\";\nimport { SELECTED_SKILL_CUSTOM_TYPE, selectedSkillCapture } from \"./selected-skills.js\";\nimport { hydrateCapturedHistoryEntry, type SessionHistoryReadView } from \"./session-history-index.js\";\nimport { getSessionArtifactPathForFile, type SessionEntry } from \"./session-manager.js\";\nimport { projectTaskStateSource } from \"./task-state.js\";\n\nexport interface NativeRecoveryLimits {\n\tmaxBytes: number;\n\tmaxSourceBytes: number;\n\tmaxItems: number;\n\tmaxRequests: number;\n}\n\n/** Defaults match bounded index pages and 64KiB payload parts; all admission units are bytes or items. */\nexport const DEFAULT_NATIVE_RECOVERY_LIMITS: Readonly<NativeRecoveryLimits> = Object.freeze({\n\tmaxBytes: 64 * 1024,\n\tmaxSourceBytes: 1024 * 1024,\n\tmaxItems: 16,\n\tmaxRequests: 8,\n});\n\nconst exactString = Type.String({ minLength: 1, maxLength: 512 });\nconst byteLimit = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });\nconst operationSchema = Type.Object(\n\t{\n\t\taction: Type.Union([Type.Literal(\"read\"), Type.Literal(\"search\"), Type.Literal(\"recover\")]),\n\t\tref: Type.Optional(exactString),\n\t\tcursor: Type.Optional(exactString),\n\t\tstartByte: Type.Optional(Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER })),\n\t\tendByte: Type.Optional(byteLimit),\n\t\trevision: Type.Optional(exactString),\n\t\tsourceSessionId: Type.Optional(exactString),\n\t\tfield: Type.Optional(exactString),\n\t\tneed: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: 8192,\n\t\t\t\tdescription:\n\t\t\t\t\t\"Literal text selector; alias of query. Prefer one field. If both are supplied, use identical text.\",\n\t\t\t}),\n\t\t),\n\t\tquery: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: 8192,\n\t\t\t\tdescription:\n\t\t\t\t\t\"Literal text selector; alias of need. Prefer one field. If both are supplied, use identical text.\",\n\t\t\t}),\n\t\t),\n\t\tstartLine: Type.Optional(byteLimit),\n\t\tendLine: Type.Optional(byteLimit),\n\t\tmaxBytes: Type.Optional(byteLimit),\n\t},\n\t{ additionalProperties: false },\n);\n\n/** A ref is a case-sensitive entry ID, never a path. Lines are one-based within each selected field. */\nexport const nativeRecoveryInputSchema = Type.Union([\n\toperationSchema,\n\tType.Object(\n\t\t{ action: Type.Literal(\"skill\"), name: exactString, maxBytes: Type.Optional(byteLimit) },\n\t\t{ additionalProperties: false },\n\t),\n\tType.Object(\n\t\t{\n\t\t\taction: Type.Literal(\"batch\"),\n\t\t\trequests: Type.Array(operationSchema, { minItems: 1, maxItems: 8 }),\n\t\t\tmaxBytes: Type.Optional(byteLimit),\n\t\t},\n\t\t{ additionalProperties: false },\n\t),\n]);\nconst providerOperationSchema = Type.Object(\n\t{ ...operationSchema.properties, action: StringEnum([\"read\", \"search\", \"recover\"] as const) },\n\t{ additionalProperties: false },\n);\n\n/** Provider-facing tools require an object root; execute still applies the strict union above. */\nexport const nativeRecoveryToolSchema = Type.Object(\n\t{\n\t\t...providerOperationSchema.properties,\n\t\taction: StringEnum([\"read\", \"search\", \"recover\", \"batch\", \"skill\"] as const),\n\t\tname: Type.Optional(exactString),\n\t\trequests: Type.Optional(Type.Array(providerOperationSchema, { minItems: 1, maxItems: 8 })),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type NativeRecoveryInput = Static<typeof nativeRecoveryInputSchema>;\nexport type NativeRecoveryOperation = Static<typeof operationSchema>;\nexport type NativeRecoveryStatus =\n\t| \"found\"\n\t| \"complete-miss\"\n\t| \"partial\"\n\t| \"not_authorized\"\n\t| \"unavailable\"\n\t| \"budget_refused\";\nexport type NativeRecoveryCoverage = \"complete\" | \"partial\" | \"unknown\";\nexport interface NativeRecoveryScope {\n\tkind: \"branch\";\n\t/** Missing coordinates mean capture was unavailable, not whole-source authority. */\n\tsourceSessionId?: string;\n\tleafId?: string | null;\n\tsourceSequence?: number;\n\tprojection: \"public-text-only\";\n}\nexport interface NativeRecoverySource {\n\tsourceSessionId: string;\n\tentryId: string;\n\trevision: string;\n\tfield: string;\n\tstartLine?: number;\n\tendLine?: number;\n\tstartByte?: number;\n\tendByte?: number;\n\tprefixOmitted?: boolean;\n\tsuffixOmitted?: boolean;\n}\nexport interface NativeRecoveryRecord extends Omit<NativeRecoverySource, \"entryId\"> {\n\tref: string;\n\tkind: string;\n\ttext: string;\n}\nexport interface NativeRecoveryResult {\n\trequestIndex: number;\n\tstatus: NativeRecoveryStatus;\n\tcoverage: NativeRecoveryCoverage;\n\trecords: NativeRecoveryRecord[];\n\tcursor?: string;\n\texhausted?: boolean;\n\treason?: string;\n}\nexport interface NativeRecoveryResponse {\n\tkind: \"native-recovery\";\n\tversion: 1;\n\tnativeRecovery: 1;\n\tauthority: \"tool-data\";\n\tfreshness: \"unknown\";\n\tscope: NativeRecoveryScope;\n\tstatus: NativeRecoveryStatus;\n\tcoverage: NativeRecoveryCoverage;\n\tsources: NativeRecoverySource[];\n\tresults: NativeRecoveryResult[];\n\treason?: string;\n}\n\n/** A cap smaller than the refusal envelope cannot be satisfied by returning clipped JSON. */\nexport class NativeRecoveryBudgetRefusal extends Error {\n\treadonly status = \"budget_refused\";\n\tconstructor() {\n\t\tsuper(\"Native recovery byte or item budget refused\");\n\t\tthis.name = \"NativeRecoveryBudgetRefusal\";\n\t}\n}\n\nexport function stringifyNativeRecoveryResponse(\n\tresponse: NativeRecoveryResponse,\n\tmaxBytes = DEFAULT_NATIVE_RECOVERY_LIMITS.maxBytes,\n): string {\n\ttry {\n\t\treturn stringifyBoundedJson(response, maxBytes);\n\t} catch {\n\t\tthrow new NativeRecoveryBudgetRefusal();\n\t}\n}\n\n/** Tool details carry reference metadata, not a second copy of the selected body. */\nexport function nativeRecoveryMetadata(response: NativeRecoveryResponse) {\n\treturn {\n\t\tkind: response.kind,\n\t\tversion: response.version,\n\t\tnativeRecovery: response.nativeRecovery,\n\t\tscope: response.scope,\n\t\tsources: response.sources,\n\t\tcoverage: response.coverage,\n\t\tauthority: response.authority,\n\t\tfreshness: response.freshness,\n\t\tstatus: response.status,\n\t};\n}\n\n/** Callers use fixed public reason codes, never raw exceptions or source locators. */\nexport function createNativeRecoveryRefusal(\n\tstatus: \"not_authorized\" | \"unavailable\" | \"budget_refused\",\n\treason: string,\n\tmaxBytes = DEFAULT_NATIVE_RECOVERY_LIMITS.maxBytes,\n): NativeRecoveryResponse {\n\tconst response: NativeRecoveryResponse = {\n\t\tkind: \"native-recovery\",\n\t\tversion: 1,\n\t\tnativeRecovery: 1,\n\t\tauthority: \"tool-data\",\n\t\tfreshness: \"unknown\",\n\t\tscope: { kind: \"branch\", projection: \"public-text-only\" },\n\t\tstatus,\n\t\tcoverage: \"unknown\",\n\t\tsources: [],\n\t\tresults: [],\n\t\treason,\n\t};\n\tstringifyNativeRecoveryResponse(response, maxBytes);\n\treturn response;\n}\n\ninterface PublicField {\n\tfield: string;\n\ttext: string;\n\tretained?: RetainedToolOutput;\n\tunavailable?: boolean;\n}\nfunction object(value: unknown): Record<string, unknown> | undefined {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)\n\t\t: undefined;\n}\n\n/** Select known public string fields; never traverse executed-input/provider envelopes, signatures or thinking. */\nfunction publicFields(\n\tentry: SessionEntry,\n\tmaxItems: number,\n\tqualification?: IndexedSourceEvent[\"qualification\"],\n): PublicField[] | undefined {\n\tif (entry.type === \"compaction\" || entry.type === \"branch_summary\") {\n\t\treturn typeof entry.summary === \"string\" ? [{ field: \"/summary\", text: entry.summary }] : undefined;\n\t}\n\tif (\n\t\tentry.type === \"custom\" &&\n\t\tentry.customType === AGENT_RESULT_CUSTOM_TYPE &&\n\t\tqualification === \"native-recovery\"\n\t) {\n\t\tconst findings = object(entry.data)?.findings;\n\t\treturn typeof findings === \"string\" ? [{ field: \"/data/findings\", text: findings }] : undefined;\n\t}\n\tlet content: unknown;\n\tlet field: string;\n\tlet role: unknown;\n\tif (\n\t\t(entry.type === \"custom\" || entry.type === \"custom_message\") &&\n\t\tqualification === \"native-recovery\" &&\n\t\tentry.customType === SELECTED_SKILL_CUSTOM_TYPE\n\t) {\n\t\tconst skill = selectedSkillCapture(entry);\n\t\tif (skill)\n\t\t\treturn [\n\t\t\t\t{ field: entry.type === \"custom\" ? \"/data/content\" : \"/content\", text: skill.content },\n\t\t\t\t{\n\t\t\t\t\tfield: `/${entry.type === \"custom\" ? \"data\" : \"details\"}/baseContextSelectedSkill/descriptor`,\n\t\t\t\t\ttext: JSON.stringify({ ...skill.descriptor, sourceInfo: undefined }),\n\t\t\t\t},\n\t\t\t];\n\t}\n\tif (entry.type === \"custom_message\") {\n\t\tcontent = entry.content;\n\t\tfield = \"/content\";\n\t\trole = \"custom\";\n\t} else if (entry.type === \"message\") {\n\t\tconst message = object(entry.message);\n\t\tif (!message || ![\"user\", \"assistant\", \"toolResult\", \"custom\"].includes(String(message.role))) return undefined;\n\t\tcontent = message.content;\n\t\trole = message.role;\n\t\tfield = \"/message/content\";\n\t} else return undefined;\n\tif (typeof content === \"string\") {\n\t\treturn role === \"user\" || role === \"custom\" ? [{ field, text: content }] : undefined;\n\t}\n\tif (!Array.isArray(content)) return undefined;\n\tif (content.length > maxItems) throw new NativeRecoveryBudgetRefusal();\n\tconst fields: PublicField[] = [];\n\tfor (let i = 0; i < content.length; i++) {\n\t\tconst block = object(content[i]);\n\t\tif (!block) return undefined;\n\t\tif (block.type === \"text\" && typeof block.text === \"string\") {\n\t\t\tif (fields.length >= maxItems) throw new NativeRecoveryBudgetRefusal();\n\t\t\tfields.push({ field: `${field}/${i}/text`, text: block.text });\n\t\t} else if (block.type === \"thinking\" && role === \"assistant\" && typeof block.thinking === \"string\") {\n\t\t\t// Thinking is unsupported by this v1 projection; this does not classify all thinking text as private.\n\t\t} else if (\n\t\t\tblock.type === \"toolCall\" &&\n\t\t\trole === \"assistant\" &&\n\t\t\ttypeof block.id === \"string\" &&\n\t\t\ttypeof block.name === \"string\" &&\n\t\t\tobject(block.arguments)\n\t\t) {\n\t\t\t// Assistant-authored string arguments are public action data, not executed-input/auth envelopes.\n\t\t\tconst arguments_ = block.arguments as Record<string, unknown>;\n\t\t\tlet visited = 0;\n\t\t\tfor (const key in arguments_) {\n\t\t\t\tif (!Object.hasOwn(arguments_, key)) continue;\n\t\t\t\tif (++visited > maxItems) throw new NativeRecoveryBudgetRefusal();\n\t\t\t\tconst value = arguments_[key];\n\t\t\t\t// v1 does not select nested/non-string argument fields; it does not label them private.\n\t\t\t\tif (typeof value !== \"string\") continue;\n\t\t\t\tif (fields.length >= maxItems) throw new NativeRecoveryBudgetRefusal();\n\t\t\t\tconst escaped = key.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n\t\t\t\tfields.push({ field: `${field}/${i}/arguments/${escaped}`, text: value });\n\t\t\t}\n\t\t} else if (\n\t\t\tblock.type === \"image\" &&\n\t\t\trole !== \"assistant\" &&\n\t\t\ttypeof block.data === \"string\" &&\n\t\t\ttypeof block.mimeType === \"string\"\n\t\t) {\n\t\t\t// This API selects text only; it makes no lossless multimodal claim.\n\t\t} else return undefined;\n\t}\n\treturn fields;\n}\n\nfunction outcome(\n\trequestIndex: number,\n\tstatus: NativeRecoveryStatus,\n\tcoverage: NativeRecoveryCoverage = \"unknown\",\n\trecords: NativeRecoveryRecord[] = [],\n\treason?: string,\n): NativeRecoveryResult {\n\treturn { requestIndex, status, coverage, records, ...(reason ? { reason } : {}) };\n}\n\nfunction assemble(scope: NativeRecoveryScope, results: NativeRecoveryResult[]): NativeRecoveryResponse {\n\tconst statuses = new Set(results.map((result) => result.status));\n\tconst status =\n\t\tstatuses.size === 1\n\t\t\t? results[0].status\n\t\t\t: results.every((result) => result.status === \"found\" || result.status === \"complete-miss\")\n\t\t\t\t? \"found\"\n\t\t\t\t: \"partial\";\n\tconst coverage = results.every((result) => result.coverage === \"complete\")\n\t\t? \"complete\"\n\t\t: results.some((result) => result.coverage === \"partial\")\n\t\t\t? \"partial\"\n\t\t\t: \"unknown\";\n\treturn {\n\t\tkind: \"native-recovery\",\n\t\tversion: 1,\n\t\tnativeRecovery: 1,\n\t\tauthority: \"tool-data\",\n\t\tfreshness: \"unknown\",\n\t\tscope,\n\t\tstatus,\n\t\tcoverage,\n\t\tresults,\n\t\tsources: results.flatMap((result) =>\n\t\t\tresult.records.map((record) => ({\n\t\t\t\tsourceSessionId: record.sourceSessionId,\n\t\t\t\tentryId: record.ref,\n\t\t\t\trevision: record.revision,\n\t\t\t\tfield: record.field,\n\t\t\t\tstartLine: record.startLine,\n\t\t\t\tendLine: record.endLine,\n\t\t\t\tstartByte: record.startByte,\n\t\t\t\tendByte: record.endByte,\n\t\t\t\tprefixOmitted: record.prefixOmitted,\n\t\t\t\tsuffixOmitted: record.suffixOmitted,\n\t\t\t})),\n\t\t),\n\t};\n}\n\n/** Shared runtime admission for the native tool and Python host bridge. */\nexport function parseNativeRecoveryInput(value: unknown): NativeRecoveryInput {\n\tlet request: NativeRecoveryInput;\n\ttry {\n\t\trequest = JSON.parse(stringifyBoundedJson(value, 128 * 1024)) as NativeRecoveryInput;\n\t} catch {\n\t\tthrow new NativeRecoveryBudgetRefusal();\n\t}\n\tif (!Value.Check(nativeRecoveryInputSchema, request)) throw new Error(\"Invalid native recovery request\");\n\treturn request;\n}\n\ninterface RecoveryCursorState {\n\tsource: SourceSnapshotRef;\n\toperation: NativeRecoveryOperation;\n\tafter: number;\n\tentryId?: string;\n\tfield: number;\n\tbyte: number;\n\tline: number;\n\toverlap: string;\n\tunavailable: boolean;\n\tmatched: boolean;\n}\n\n/** Session-owned, ephemeral searches. No read lease or canonical body survives a call. */\nexport class NativeRecoveryCursorStore {\n\tprivate readonly states = new Map<string, RecoveryCursorState>();\n\tprivate generation = 0;\n\tclear(): void {\n\t\tthis.states.clear();\n\t\tthis.generation++;\n\t}\n\tget(id: string): RecoveryCursorState | undefined {\n\t\treturn this.states.get(id);\n\t}\n\tdelete(id: string): void {\n\t\tthis.states.delete(id);\n\t}\n\tget version(): number {\n\t\treturn this.generation;\n\t}\n\tsave(state: RecoveryCursorState, version: number, id: string = randomUUID()): string {\n\t\tif (version !== this.generation) throw new Error(\"Expired recovery cursor\");\n\t\tthis.states.delete(id);\n\t\tthis.states.set(id, structuredClone(state));\n\t\twhile (this.states.size > 16) this.states.delete(this.states.keys().next().value!);\n\t\treturn id;\n\t}\n}\n\n/** The caller captures ONE server branch before entering this service, including for a batch. */\nexport async function recoverCapturedHistory(\n\tview: SessionHistoryReadView,\n\tinput: NativeRecoveryInput,\n\tlimits: NativeRecoveryLimits = DEFAULT_NATIVE_RECOVERY_LIMITS,\n\tsignal?: AbortSignal,\n\tcursors?: NativeRecoveryCursorStore,\n): Promise<NativeRecoveryResponse> {\n\tconst cap = { ...limits };\n\tfor (const key of [\"maxBytes\", \"maxSourceBytes\", \"maxItems\", \"maxRequests\"] as const) {\n\t\tif (!Number.isSafeInteger(cap[key]) || cap[key] < 1) throw new NativeRecoveryBudgetRefusal();\n\t\tcap[key] = Math.min(cap[key], DEFAULT_NATIVE_RECOVERY_LIMITS[key]);\n\t}\n\tlet request: NativeRecoveryInput;\n\ttry {\n\t\trequest = parseNativeRecoveryInput(input);\n\t} catch (error) {\n\t\treturn createNativeRecoveryRefusal(\n\t\t\terror instanceof NativeRecoveryBudgetRefusal ? \"budget_refused\" : \"unavailable\",\n\t\t\t\"invalid_request\",\n\t\t\tcap.maxBytes,\n\t\t);\n\t}\n\tconst maxBytes = Math.min(cap.maxBytes, request.maxBytes ?? cap.maxBytes);\n\tif (request.action === \"skill\")\n\t\treturn createNativeRecoveryRefusal(\"not_authorized\", \"native_skill_selection_owner_required\", maxBytes);\n\tconst operations = request.action === \"batch\" ? request.requests : [request];\n\tconst version = cursors?.version ?? 0;\n\tconst resumed = operations.map((operation) => (operation.cursor ? cursors?.get(operation.cursor) : undefined));\n\tconst anchor = resumed.find(Boolean)?.source;\n\tif (anchor) {\n\t\tif (resumed.some((state) => state && JSON.stringify(state.source) !== JSON.stringify(anchor)))\n\t\t\treturn createNativeRecoveryRefusal(\"unavailable\", \"conflicting_selection\", maxBytes);\n\t\ttry {\n\t\t\tif (!view.atSnapshot) throw new Error(\"Captured source is unavailable\");\n\t\t\tview = await view.atSnapshot(anchor);\n\t\t} catch {\n\t\t\treturn createNativeRecoveryRefusal(\"unavailable\", \"cursor_source_unavailable\", maxBytes);\n\t\t}\n\t}\n\tconst { sessionId: sourceSessionId, leafId, sourceSequence } = view.source;\n\tconst scope: NativeRecoveryScope = {\n\t\tkind: \"branch\",\n\t\tprojection: \"public-text-only\",\n\t\tsourceSessionId,\n\t\tleafId,\n\t\tsourceSequence,\n\t};\n\tconst results = operations.map((_, i) => outcome(i, \"budget_refused\", \"unknown\", [], \"not_admitted\"));\n\tstringifyNativeRecoveryResponse(assemble(scope, results), maxBytes);\n\tif (operations.length > cap.maxRequests) return assemble(scope, results);\n\tlet sourceBytes = 0;\n\tlet examined = 0;\n\tlet selectedItems = 0;\n\tconst cache = new Map<string, { revision: string; entry: SessionEntry }>();\n\n\tasync function fieldsFor(metadata: IndexedSourceEvent, requestedField?: string): Promise<PublicField[] | undefined> {\n\t\tsignal?.throwIfAborted();\n\t\tlet cached = cache.get(metadata.id);\n\t\tif (cached && cached.revision !== metadata.revision) throw new Error(\"Captured revision changed\");\n\t\tif (!cached) {\n\t\t\tif (metadata.locator.length > cap.maxSourceBytes - sourceBytes) throw new NativeRecoveryBudgetRefusal();\n\t\t\tsourceBytes += metadata.locator.length;\n\t\t\tconst hydrated = await hydrateCapturedHistoryEntry(metadata, metadata.locator.length, (id, options) =>\n\t\t\t\tview.readPayload(id, options),\n\t\t\t);\n\t\t\tsignal?.throwIfAborted();\n\t\t\tcached = { revision: metadata.revision, entry: hydrated.entry };\n\t\t\tcache.set(metadata.id, cached);\n\t\t}\n\t\tif (requestedField === \"/nativeOrigin/submitted/text\") {\n\t\t\tif (\n\t\t\t\tcached.entry.type !== \"message\" ||\n\t\t\t\tmetadata.qualification !== \"native-admission\" ||\n\t\t\t\tmetadata.retention === \"retained-import\"\n\t\t\t)\n\t\t\t\treturn undefined;\n\t\t\tfor (const projection of projectTaskStateSource({\n\t\t\t\tsessionId: sourceSessionId,\n\t\t\t\tsequence: metadata.sequence,\n\t\t\t\trevision: metadata.revision,\n\t\t\t\tqualification: metadata.qualification,\n\t\t\t\tretention: metadata.retention,\n\t\t\t\tentry: cached.entry,\n\t\t\t})) {\n\t\t\t\tif (\n\t\t\t\t\tprojection.source.field === requestedField &&\n\t\t\t\t\tprojection.authority === \"user\" &&\n\t\t\t\t\tprojection.attribution === \"source-backed\" &&\n\t\t\t\t\ttypeof projection.text === \"string\"\n\t\t\t\t)\n\t\t\t\t\treturn [{ field: requestedField, text: projection.text }];\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t\tconst fields = publicFields(cached.entry, DEFAULT_NATIVE_RECOVERY_LIMITS.maxItems, metadata.qualification);\n\t\tif (cached.entry.type === \"message\") {\n\t\t\tconst message = object(cached.entry.message);\n\t\t\tconst retained =\n\t\t\t\tmessage?.role === \"toolResult\" ? retainedToolOutput(object(message.details)?.retainedOutput) : undefined;\n\t\t\tconst field = fields?.find((field) => field.field === retained?.field);\n\t\t\tif (field && retained) {\n\t\t\t\tif (metadata.qualification === \"native-tool-execution\" && metadata.retention !== \"retained-import\")\n\t\t\t\t\tfield.retained = retained;\n\t\t\t\telse field.unavailable = true; // A preview is not the complete retained field, nor artifact authority.\n\t\t\t}\n\t\t}\n\t\treturn fields;\n\t}\n\n\tasync function recover(supplied: NativeRecoveryOperation, i: number): Promise<NativeRecoveryResult> {\n\t\tconst saved = resumed[i];\n\t\tif (supplied.cursor && !saved) return outcome(i, \"unavailable\", \"unknown\", [], \"expired_cursor\");\n\t\tif (saved && supplied.action === \"read\") return outcome(i, \"unavailable\", \"unknown\", [], \"conflicting_selection\");\n\t\tconst operation = saved ? { ...saved.operation, maxBytes: supplied.maxBytes } : supplied;\n\t\tconst needle = operation.need ?? operation.query;\n\t\tif (\n\t\t\tsaved &&\n\t\t\tObject.entries(supplied).some(\n\t\t\t\t([key, value]) =>\n\t\t\t\t\t![\"action\", \"cursor\", \"maxBytes\"].includes(key) &&\n\t\t\t\t\tvalue !==\n\t\t\t\t\t\t(key === \"need\" || key === \"query\" ? needle : saved.operation[key as keyof NativeRecoveryOperation]),\n\t\t\t)\n\t\t)\n\t\t\treturn outcome(i, \"unavailable\", \"unknown\", [], \"conflicting_selection\");\n\t\tif (operation.sourceSessionId !== undefined && operation.sourceSessionId !== sourceSessionId)\n\t\t\treturn outcome(i, \"not_authorized\", \"unknown\", [], \"source_not_in_capture\");\n\t\tif (\n\t\t\t(operation.need !== undefined && operation.query !== undefined && operation.need !== operation.query) ||\n\t\t\t(operation.endLine !== undefined && operation.endLine < (operation.startLine ?? 1)) ||\n\t\t\t(operation.endByte !== undefined && operation.endByte <= (operation.startByte ?? 0)) ||\n\t\t\t((operation.startByte !== undefined || operation.endByte !== undefined) &&\n\t\t\t\t(operation.startLine !== undefined || operation.endLine !== undefined))\n\t\t)\n\t\t\treturn outcome(i, \"unavailable\", \"unknown\", [], \"conflicting_selection\");\n\t\tif (\n\t\t\toperation.ref === undefined &&\n\t\t\t(operation.action === \"read\" ||\n\t\t\t\tneedle === undefined ||\n\t\t\t\toperation.revision !== undefined ||\n\t\t\t\toperation.startLine !== undefined ||\n\t\t\t\toperation.endLine !== undefined ||\n\t\t\t\toperation.startByte !== undefined ||\n\t\t\t\toperation.endByte !== undefined)\n\t\t)\n\t\t\treturn outcome(i, \"unavailable\", \"unknown\", [], \"exact_selection_requires_ref\");\n\t\tif (needle !== undefined && Buffer.byteLength(needle) > 8192) throw new NativeRecoveryBudgetRefusal();\n\t\tconst searching = needle !== undefined;\n\t\tconst continuable = operation.action !== \"read\" && searching;\n\t\tconst state: RecoveryCursorState = saved\n\t\t\t? structuredClone(saved)\n\t\t\t: {\n\t\t\t\t\tsource: { ...view.source },\n\t\t\t\t\toperation: { ...operation, cursor: undefined, maxBytes: undefined },\n\t\t\t\t\tafter: 0,\n\t\t\t\t\tfield: 0,\n\t\t\t\t\tbyte: 0,\n\t\t\t\t\tline: 1,\n\t\t\t\t\toverlap: \"\",\n\t\t\t\t\tunavailable: false,\n\t\t\t\t\tmatched: false,\n\t\t\t\t};\n\t\tconst records: NativeRecoveryRecord[] = [];\n\t\tlet partialWindow = false;\n\t\tlet reason: string | undefined;\n\t\tlet exhausted = false;\n\t\tlet windows = 0;\n\t\tconst cursorId = supplied.cursor ?? randomUUID();\n\t\tconst progress = (complete: boolean): NativeRecoveryResult => ({\n\t\t\t...outcome(\n\t\t\t\ti,\n\t\t\t\tcomplete && !state.unavailable && !partialWindow\n\t\t\t\t\t? records.length || state.matched\n\t\t\t\t\t\t? \"found\"\n\t\t\t\t\t\t: \"complete-miss\"\n\t\t\t\t\t: \"partial\",\n\t\t\t\tcomplete && !state.unavailable && !partialWindow ? \"complete\" : \"partial\",\n\t\t\t\trecords,\n\t\t\t\treason,\n\t\t\t),\n\t\t\t...(continuable ? { exhausted: complete, ...(!complete && cursors ? { cursor: cursorId } : {}) } : {}),\n\t\t});\n\t\tconst reserve = () => {\n\t\t\tconst candidate = progress(false);\n\t\t\tcandidate.reason = \"canonical_source_unavailable\";\n\t\t\tstringifyBoundedJson(candidate, Math.min(maxBytes, supplied.maxBytes ?? maxBytes));\n\t\t\tconst prospective = [...results];\n\t\t\tprospective[i] = candidate;\n\t\t\tstringifyNativeRecoveryResponse(assemble(scope, prospective), maxBytes);\n\t\t};\n\t\treserve(); // Keep cursor/status space before examining any source material.\n\t\tconst admit = (record: NativeRecoveryRecord): boolean => {\n\t\t\tif (selectedItems + records.length >= cap.maxItems) return false;\n\t\t\trecords.push(record);\n\t\t\ttry {\n\t\t\t\treserve();\n\t\t\t\treturn true;\n\t\t\t} catch {\n\t\t\t\trecords.pop();\n\t\t\t\treturn false;\n\t\t\t}\n\t\t};\n\t\tconst resetField = () => {\n\t\t\tstate.byte = 0;\n\t\t\tstate.line = 1;\n\t\t\tstate.overlap = \"\";\n\t\t};\n\t\tconst nextEntry = (metadata: IndexedSourceEvent) => {\n\t\t\tstate.after = metadata.sequence;\n\t\t\tdelete state.entryId;\n\t\t\tstate.field = 0;\n\t\t\tresetField();\n\t\t};\n\t\twhile (!exhausted) {\n\t\t\tsignal?.throwIfAborted();\n\t\t\tif (examined >= cap.maxItems) {\n\t\t\t\treason = \"scan_limit\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlet metadata: IndexedSourceEvent | undefined;\n\t\t\tlet afterPage: number | null | undefined;\n\t\t\tif (state.entryId || operation.ref) {\n\t\t\t\tmetadata = await view.get(state.entryId ?? operation.ref!);\n\t\t\t\tif (!metadata) return outcome(i, \"not_authorized\", \"unknown\", records, \"ref_not_in_captured_branch\");\n\t\t\t\tif (operation.revision !== undefined && metadata.revision !== operation.revision)\n\t\t\t\t\treturn outcome(i, \"unavailable\", \"unknown\", records, \"revision_mismatch\");\n\t\t\t} else {\n\t\t\t\tconst page = await view.page(state.after, 1, { scan: true });\n\t\t\t\tif (page.coverage !== \"complete\" || page.indexedThrough < sourceSequence) state.unavailable = true;\n\t\t\t\tmetadata = page.events[0];\n\t\t\t\tafterPage = page.nextAfter;\n\t\t\t\tif (!metadata) {\n\t\t\t\t\texamined++;\n\t\t\t\t\tif (afterPage === null) {\n\t\t\t\t\t\texhausted = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif (afterPage <= state.after) throw new Error(\"History scan did not advance\");\n\t\t\t\t\tstate.after = afterPage;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\texamined++;\n\t\t\tstate.entryId = metadata.id;\n\t\t\tif (\n\t\t\t\t!operation.ref &&\n\t\t\t\t![\"message\", \"custom_message\", \"compaction\", \"branch_summary\", \"custom\"].includes(metadata.kind)\n\t\t\t) {\n\t\t\t\tnextEntry(metadata);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (metadata.locator.length > cap.maxSourceBytes) {\n\t\t\t\tif (operation.action === \"read\")\n\t\t\t\t\treturn outcome(\n\t\t\t\t\t\ti,\n\t\t\t\t\t\toperation.startByte !== undefined || operation.endByte !== undefined\n\t\t\t\t\t\t\t? \"unavailable\"\n\t\t\t\t\t\t\t: \"budget_refused\",\n\t\t\t\t\t\t\"unknown\",\n\t\t\t\t\t\t[],\n\t\t\t\t\t\t\"field_window_unsupported\",\n\t\t\t\t\t);\n\t\t\t\tstate.unavailable = true;\n\t\t\t\treason = \"field_window_unsupported\";\n\t\t\t\tnextEntry(metadata);\n\t\t\t\tif (operation.ref) exhausted = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!cache.has(metadata.id) && metadata.locator.length > cap.maxSourceBytes - sourceBytes) {\n\t\t\t\treason = \"source_limit\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlet fields: PublicField[] | undefined;\n\t\t\ttry {\n\t\t\t\tfields = await fieldsFor(metadata, operation.field);\n\t\t\t} catch (error) {\n\t\t\t\tstate.unavailable = true;\n\t\t\t\treason =\n\t\t\t\t\terror instanceof NativeRecoveryBudgetRefusal\n\t\t\t\t\t\t? \"unsupported_public_shape\"\n\t\t\t\t\t\t: \"canonical_source_unavailable\";\n\t\t\t\tnextEntry(metadata);\n\t\t\t\tif (operation.ref) exhausted = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!fields || (operation.field !== undefined && !fields.some((field) => field.field === operation.field))) {\n\t\t\t\tif (operation.ref) return outcome(i, \"unavailable\", \"unknown\", records, \"unsupported_public_field\");\n\t\t\t\tif (!fields) state.unavailable = true;\n\t\t\t\tnextEntry(metadata);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet paused = false;\n\t\t\tfor (; state.field < fields.length; state.field++, resetField()) {\n\t\t\t\tconst field = fields[state.field];\n\t\t\t\tif (operation.field !== undefined && field.field !== operation.field) continue;\n\t\t\t\tif (field.unavailable) {\n\t\t\t\t\tstate.unavailable = true;\n\t\t\t\t\treason = \"retained_output_unavailable\";\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst total = field.retained?.byteLength ?? Buffer.byteLength(field.text);\n\t\t\t\tif (field.retained && !field.retained.captureComplete) {\n\t\t\t\t\tstate.unavailable = true;\n\t\t\t\t\treason = \"capture_incomplete\";\n\t\t\t\t}\n\t\t\t\tif (state.byte === 0 && operation.startByte !== undefined) state.byte = operation.startByte;\n\t\t\t\tif (operation.endByte !== undefined && operation.endByte > total) {\n\t\t\t\t\tpartialWindow = true;\n\t\t\t\t\treason = \"requested_end_beyond_source\";\n\t\t\t\t}\n\t\t\t\tconst byteSelection = operation.startByte !== undefined || operation.endByte !== undefined;\n\t\t\t\tlet readText = \"\";\n\t\t\t\tlet readStart = state.byte;\n\t\t\t\tlet readLine: number | undefined = byteSelection && state.byte > 0 ? undefined : state.line;\n\t\t\t\twhile (state.byte < total || (total === 0 && state.byte === 0)) {\n\t\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\t\tif (++windows > cap.maxItems) {\n\t\t\t\t\t\tpaused = true;\n\t\t\t\t\t\treason = \"scan_limit\";\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst allowance = field.retained\n\t\t\t\t\t\t? Math.min(PUBLIC_TEXT_WINDOW_BYTES, cap.maxSourceBytes - sourceBytes - 4)\n\t\t\t\t\t\t: PUBLIC_TEXT_WINDOW_BYTES;\n\t\t\t\t\tif (allowance < 4) {\n\t\t\t\t\t\tpaused = true;\n\t\t\t\t\t\treason = \"source_limit\";\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst stop = Math.min(total, operation.endByte ?? total, state.byte + allowance);\n\t\t\t\t\tif (stop < state.byte) break;\n\t\t\t\t\tlet window: { text: string; startByte: number; endByte: number };\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (field.retained) {\n\t\t\t\t\t\t\tif (!view.source.sessionFile) throw new Error(\"Retained output owner unavailable\");\n\t\t\t\t\t\t\tconst selected = await readRetainedToolOutput(\n\t\t\t\t\t\t\t\tgetSessionArtifactPathForFile(view.source.sessionFile, sourceSessionId),\n\t\t\t\t\t\t\t\tfield.retained,\n\t\t\t\t\t\t\t\tstate.byte,\n\t\t\t\t\t\t\t\tstop - state.byte,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tsourceBytes += selected.sourceBytes;\n\t\t\t\t\t\t\twindow = selected;\n\t\t\t\t\t\t} else window = decodedTextWindow(field.text, state.byte, stop);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tstate.unavailable = true;\n\t\t\t\t\t\treason = \"retained_output_unavailable\";\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst startLine = state.line;\n\t\t\t\t\tconst combined = state.overlap + window.text;\n\t\t\t\t\tconst combinedStart = window.startByte - Buffer.byteLength(state.overlap);\n\t\t\t\t\tconst combinedLine = startLine - (state.overlap.match(/\\n/g)?.length ?? 0);\n\t\t\t\t\tlet text = window.text;\n\t\t\t\t\tlet startByte = window.startByte;\n\t\t\t\t\tlet endByte = window.endByte;\n\t\t\t\t\tlet recordLine: number | undefined = byteSelection && state.byte > 0 ? undefined : startLine;\n\t\t\t\t\tlet selected = !searching;\n\t\t\t\t\tif (searching) {\n\t\t\t\t\t\tconst lines = combined.split(\"\\n\");\n\t\t\t\t\t\tconst skip = Math.max(0, (operation.startLine ?? 1) - combinedLine);\n\t\t\t\t\t\tconst take = Math.min(lines.length, (operation.endLine ?? Infinity) - combinedLine + 1);\n\t\t\t\t\t\tconst prefix = lines.slice(0, skip).join(\"\\n\") + (skip ? \"\\n\" : \"\");\n\t\t\t\t\t\tconst selectedText = lines.slice(skip, Math.max(skip, take)).join(\"\\n\");\n\t\t\t\t\t\tconst localMatch = selectedText.indexOf(needle!);\n\t\t\t\t\t\tconst first = localMatch < 0 ? -1 : prefix.length + localMatch;\n\t\t\t\t\t\tselected = first >= 0;\n\t\t\t\t\t\tif (selected) {\n\t\t\t\t\t\t\tconst start = Math.max(prefix.length, first === 0 ? 0 : combined.lastIndexOf(\"\\n\", first - 1) + 1);\n\t\t\t\t\t\t\tconst newline = combined.indexOf(\"\\n\", first + needle!.length);\n\t\t\t\t\t\t\ttext = combined.slice(\n\t\t\t\t\t\t\t\tstart,\n\t\t\t\t\t\t\t\tMath.min(prefix.length + selectedText.length, newline < 0 ? combined.length : newline),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tstartByte = combinedStart + Buffer.byteLength(combined.slice(0, start));\n\t\t\t\t\t\t\tendByte = startByte + Buffer.byteLength(text);\n\t\t\t\t\t\t\trecordLine =\n\t\t\t\t\t\t\t\tbyteSelection && (operation.startByte ?? 0) > 0\n\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t: combinedLine + (combined.slice(0, start).match(/\\n/g)?.length ?? 0);\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tBuffer.byteLength(text) > Math.max(Buffer.byteLength(needle!) + 256, Math.floor(maxBytes / 8))\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tconst matchByte = Buffer.byteLength(combined.slice(start, first));\n\t\t\t\t\t\t\t\tconst excerpt = decodedTextWindow(\n\t\t\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\t\t\tMath.max(0, matchByte - 128),\n\t\t\t\t\t\t\t\t\tmatchByte + Buffer.byteLength(needle!) + 128,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif (recordLine !== undefined)\n\t\t\t\t\t\t\t\t\trecordLine += decodedTextWindow(text, 0, excerpt.startByte).text.match(/\\n/g)?.length ?? 0;\n\t\t\t\t\t\t\t\ttext = excerpt.text;\n\t\t\t\t\t\t\t\tstartByte += excerpt.startByte;\n\t\t\t\t\t\t\t\tendByte = startByte + Buffer.byteLength(text);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (!byteSelection) {\n\t\t\t\t\t\tconst lines = text.split(\"\\n\");\n\t\t\t\t\t\tconst skip = Math.max(0, (operation.startLine ?? 1) - startLine);\n\t\t\t\t\t\tconst take = Math.min(lines.length, (operation.endLine ?? Infinity) - startLine + 1);\n\t\t\t\t\t\tselected = take > skip;\n\t\t\t\t\t\tif (selected) {\n\t\t\t\t\t\t\tconst prefix = lines.slice(0, skip).join(\"\\n\") + (skip ? \"\\n\" : \"\");\n\t\t\t\t\t\t\tstartByte += Buffer.byteLength(prefix);\n\t\t\t\t\t\t\ttext = lines.slice(skip, take).join(\"\\n\");\n\t\t\t\t\t\t\tendByte = startByte + Buffer.byteLength(text);\n\t\t\t\t\t\t\trecordLine = startLine + skip;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (selected) {\n\t\t\t\t\t\tif (!searching) {\n\t\t\t\t\t\t\tif (!readText) {\n\t\t\t\t\t\t\t\treadStart = startByte;\n\t\t\t\t\t\t\t\treadLine = recordLine;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treadText += text;\n\t\t\t\t\t\t\ttext = readText;\n\t\t\t\t\t\t\tstartByte = readStart;\n\t\t\t\t\t\t\trecordLine = readLine;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst record: NativeRecoveryRecord = {\n\t\t\t\t\t\t\tref: metadata.id,\n\t\t\t\t\t\t\trevision: metadata.revision,\n\t\t\t\t\t\t\tsourceSessionId,\n\t\t\t\t\t\t\tkind: metadata.kind,\n\t\t\t\t\t\t\tfield: field.field,\n\t\t\t\t\t\t\tstartByte,\n\t\t\t\t\t\t\tendByte,\n\t\t\t\t\t\t\tprefixOmitted: startByte > 0,\n\t\t\t\t\t\t\tsuffixOmitted: endByte < total,\n\t\t\t\t\t\t\t...(recordLine === undefined\n\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t: { startLine: recordLine, endLine: recordLine + (text.match(/\\n/g)?.length ?? 0) }),\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst done =\n\t\t\t\t\t\t\tsearching ||\n\t\t\t\t\t\t\twindow.endByte >= total ||\n\t\t\t\t\t\t\t(operation.endByte !== undefined && stop >= operation.endByte) ||\n\t\t\t\t\t\t\t(operation.endLine !== undefined &&\n\t\t\t\t\t\t\t\tstartLine + (window.text.match(/\\n/g)?.length ?? 0) > operation.endLine);\n\t\t\t\t\t\tif (done) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\toperation.endLine !== undefined &&\n\t\t\t\t\t\t\t\twindow.endByte >= total &&\n\t\t\t\t\t\t\t\tstartLine + (window.text.match(/\\n/g)?.length ?? 0) < operation.endLine\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tpartialWindow = true;\n\t\t\t\t\t\t\t\treason = \"requested_end_beyond_source\";\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!admit(record)) {\n\t\t\t\t\t\t\t\tpaused = true;\n\t\t\t\t\t\t\t\treason = \"output_limit\";\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tstate.matched = true;\n\t\t\t\t\t\t\tif (searching && (startByte > 0 || endByte < total) && operation.ref) {\n\t\t\t\t\t\t\t\tpartialWindow = true;\n\t\t\t\t\t\t\t\treason = \"need_window\";\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (Buffer.byteLength(readText) > maxBytes) throw new NativeRecoveryBudgetRefusal();\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\twindow.endByte <= state.byte ||\n\t\t\t\t\t\twindow.endByte >= total ||\n\t\t\t\t\t\t(operation.endByte !== undefined && window.endByte >= operation.endByte)\n\t\t\t\t\t)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tstate.byte = window.endByte;\n\t\t\t\t\tstate.line += window.text.match(/\\n/g)?.length ?? 0;\n\t\t\t\t\tlet tail = searching ? combined.slice(-needle!.length - 2) : \"\";\n\t\t\t\t\tif (tail.charCodeAt(0) >= 0xdc00 && tail.charCodeAt(0) <= 0xdfff) tail = tail.slice(1);\n\t\t\t\t\tstate.overlap = searching\n\t\t\t\t\t\t? decodedTextWindow(tail, Math.max(0, Buffer.byteLength(tail) - Buffer.byteLength(needle!) - 3)).text\n\t\t\t\t\t\t: \"\";\n\t\t\t\t}\n\t\t\t\tif (paused) break;\n\t\t\t}\n\t\t\tif (paused) break;\n\t\t\tnextEntry(metadata);\n\t\t\tif (operation.ref || afterPage === null) {\n\t\t\t\texhausted = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tsignal?.throwIfAborted();\n\t\tif (!exhausted && continuable && cursors) cursors.save(state, version, cursorId);\n\t\telse if (supplied.cursor && exhausted) cursors?.delete(supplied.cursor);\n\t\tif (!searching && !exhausted && records.length === 0)\n\t\t\treturn outcome(i, \"budget_refused\", \"unknown\", [], reason ?? \"operation_budget\");\n\t\treturn progress(exhausted);\n\t}\n\tfor (let i = 0; i < operations.length; i++) {\n\t\ttry {\n\t\t\tsignal?.throwIfAborted();\n\t\t\tconst result = await recover(operations[i], i);\n\t\t\tsignal?.throwIfAborted();\n\t\t\tstringifyBoundedJson(result, Math.min(maxBytes, operations[i].maxBytes ?? maxBytes));\n\t\t\tresults[i] = result;\n\t\t\tstringifyNativeRecoveryResponse(assemble(scope, results), maxBytes);\n\t\t\tselectedItems += result.records.length;\n\t\t} catch (error) {\n\t\t\tconst budget =\n\t\t\t\terror instanceof NativeRecoveryBudgetRefusal ||\n\t\t\t\t(error instanceof Error && /budget|limit/i.test(error.message));\n\t\t\tresults[i] = outcome(\n\t\t\t\ti,\n\t\t\t\tbudget ? \"budget_refused\" : \"unavailable\",\n\t\t\t\t\"unknown\",\n\t\t\t\t[],\n\t\t\t\tbudget ? \"operation_budget\" : signal?.aborted ? \"aborted\" : \"canonical_source_unavailable\",\n\t\t\t);\n\t\t}\n\t}\n\tconst response = assemble(scope, results);\n\tstringifyNativeRecoveryResponse(response, maxBytes);\n\treturn response;\n}\n"]}
|
|
@@ -12,7 +12,9 @@ export interface SessionHistoryReadView {
|
|
|
12
12
|
contextUpdates(target: ContextUpdateTarget): Promise<ContextUpdates>;
|
|
13
13
|
readContextUpdatePayload(id: string, target: ContextUpdateTarget, options?: HistoryPayloadReadOptions): Promise<CanonicalPayloadFragment | undefined>;
|
|
14
14
|
get(id: string): Promise<IndexedSourceEvent | undefined>;
|
|
15
|
-
page(after?: number, limit?: number
|
|
15
|
+
page(after?: number, limit?: number, options?: {
|
|
16
|
+
scan?: boolean;
|
|
17
|
+
}): Promise<HistoryIndexPage>;
|
|
16
18
|
search(query: string, limit?: number): Promise<HistoryIndexPage>;
|
|
17
19
|
taskEvidence(options?: TaskEvidenceOptions): Promise<TaskEvidencePage>;
|
|
18
20
|
readPayload(id: string, options?: HistoryPayloadReadOptions): Promise<CanonicalPayloadFragment | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-history-index.d.ts","sourceRoot":"","sources":["../../src/core/session-history-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,wBAAwB,EAE7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,YAAY,EACZ,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,K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\n\ttype CanonicalPayloadCursor,\n\ttype CanonicalPayloadFragment,\n\tMAX_CANONICAL_PAYLOAD_PART_BYTES,\n} from \"./canonical-payload-parts.js\";\nimport {\n\ttype BranchBootstrapState,\n\ttype ContextManifestOptions,\n\ttype ContextManifestPage,\n\ttype ContextUpdates,\n\ttype ContextUpdateTarget,\n\tHistoryIndex,\n\ttype HistoryIndexPage,\n\ttype HistoryPayloadReadOptions,\n\ttype IndexedSourceEvent,\n\ttype IpythonSentMessagesOptions,\n\ttype IpythonSentMessagesPage,\n\ttype ParentPathOptions,\n\ttype ParentPathPage,\n\ttype SourceBootstrapState,\n\ttype TaskEvidenceOptions,\n\ttype TaskEvidencePage,\n} from \"./history-index.js\";\nimport type { BoundRequestSink, SourceSnapshotRef } from \"./request-events.js\";\nimport type { SessionJournalState } from \"./session-journal-owner.js\";\nimport type { SessionEntry } from \"./session-manager.js\";\n\n/** One source/branch frontier shared by every operation in a captured request. */\nexport interface SessionHistoryReadView {\n\treadonly source: SourceSnapshotRef;\n\t/** A narrower ancestor/prefix on this same capture; its lifetime never outlives the parent read. */\n\tatSnapshot?(source: SourceSnapshotRef): Promise<SessionHistoryReadView>;\n\tcontextManifest(options?: ContextManifestOptions): Promise<ContextManifestPage>;\n\tcontextUpdates(target: ContextUpdateTarget): Promise<ContextUpdates>;\n\treadContextUpdatePayload(\n\t\tid: string,\n\t\ttarget: ContextUpdateTarget,\n\t\toptions?: HistoryPayloadReadOptions,\n\t): Promise<CanonicalPayloadFragment | undefined>;\n\tget(id: string): Promise<IndexedSourceEvent | undefined>;\n\tpage(after?: number, limit?: number): Promise<HistoryIndexPage>;\n\tsearch(query: string, limit?: number): Promise<HistoryIndexPage>;\n\ttaskEvidence(options?: TaskEvidenceOptions): Promise<TaskEvidencePage>;\n\treadPayload(id: string, options?: HistoryPayloadReadOptions): Promise<CanonicalPayloadFragment | undefined>;\n}\n\nexport interface BoundHistoryReadSink<View> extends Omit<BoundRequestSink, \"readHistory\"> {\n\treadHistory<T>(read: (view: View) => Promise<T>): Promise<T>;\n}\n\nexport interface BoundSessionRequestSink extends BoundHistoryReadSink<SessionHistoryReadView> {}\n\nexport interface SessionHistoryReadLimits {\n\tmaxEntries: number;\n\t/** Canonical frame bytes, not a decoded heap or tokenizer estimate. */\n\tmaxSourceBytes: number;\n}\n\nexport interface HydratedSessionHistoryEntry {\n\tentry: SessionEntry;\n\t/** Includes the exact locator/revision and lowering-only retention outside the payload. */\n\tsource: IndexedSourceEvent;\n}\n\nexport interface MaterializedSessionHistory {\n\tsource: SourceSnapshotRef;\n\tscope: \"branch\" | \"source\";\n\tentries: HydratedSessionHistoryEntry[];\n\tsourceBytes: number;\n}\n\n/** Bootstrap refs and booleans from the same pinned branch used for exact hydration. */\nexport interface SessionBranchBootstrapState extends BranchBootstrapState {\n\treadonly source: SourceSnapshotRef;\n}\n\n/** Exact parent-chain metadata from one captured canonical source and leaf. */\nexport interface SessionParentPathPage extends ParentPathPage {\n\treadonly source: SourceSnapshotRef;\n}\n\n/** Consume iterators inside the owning read callback. Materialized results are detached. */\nexport interface SessionHistoryReadScope {\n\treadonly source: SourceSnapshotRef;\n\treadonly scope: \"branch\" | \"source\";\n\treadonly branchContext: SessionHistoryReadView;\n\t/** Select the captured branch even when invoked from an explicit whole-source scope. */\n\tbranchBootstrap(): Promise<SessionBranchBootstrapState>;\n\t/** Chronological parent chain only; attached request evidence is not an ancestor. */\n\tparentPath(options?: ParentPathOptions): Promise<SessionParentPathPage>;\n\t/** Source scope only: use another leaf without changing the captured source or branchContext. */\n\tparentPathFrom(leafId: string | null, options?: ParentPathOptions): Promise<SessionParentPathPage>;\n\t/** Explicit whole-source relations, clipped to this captured prefix. */\n\tsourceLabel(targetId: string): Promise<IndexedSourceEvent | undefined>;\n\tsourceAssistantUsage(targetId: string): Promise<IndexedSourceEvent | undefined>;\n\t/** Exact sent-message refs on the original captured parent branch, even before a tool result. */\n\tipythonSentMessages(toolCallId: string, options?: IpythonSentMessagesOptions): Promise<IpythonSentMessagesPage>;\n\tget(id: string): Promise<IndexedSourceEvent | undefined>;\n\tpage(after?: number, limit?: number): Promise<HistoryIndexPage>;\n\tsearch(query: string, limit?: number): Promise<HistoryIndexPage>;\n\treadPayload(id: string, options?: HistoryPayloadReadOptions): Promise<CanonicalPayloadFragment | undefined>;\n\thydrateEntry(id: string, maxSourceBytes: number): Promise<HydratedSessionHistoryEntry | undefined>;\n\titerateEntries(limits: SessionHistoryReadLimits): AsyncGenerator<HydratedSessionHistoryEntry>;\n\tmaterialize(limits: SessionHistoryReadLimits): Promise<MaterializedSessionHistory>;\n}\n\nexport type HistoryReadQuery = <T>(operation: () => Promise<T>) => Promise<T>;\n\n/** Existing inference/request views remain strictly branch-scoped. */\nexport function createBranchHistoryReadView(\n\tindex: HistoryIndex,\n\tsource: SourceSnapshotRef,\n\tquery: HistoryReadQuery,\n): SessionHistoryReadView {\n\tconst sessionId = source.sessionId;\n\tconst scope = { leafId: source.leafId, through: source.sourceSequence };\n\treturn Object.freeze({\n\t\tsource,\n\t\tatSnapshot: async (requested: SourceSnapshotRef) => {\n\t\t\tconst captured = Object.freeze({ ...requested });\n\t\t\tif (\n\t\t\t\tcaptured.sessionId !== sessionId ||\n\t\t\t\tcaptured.sessionFile !== source.sessionFile ||\n\t\t\t\tcaptured.persistent !== source.persistent ||\n\t\t\t\t!Number.isSafeInteger(captured.sourceSequence) ||\n\t\t\t\tcaptured.sourceSequence < 0 ||\n\t\t\t\tcaptured.sourceSequence > source.sourceSequence\n\t\t\t)\n\t\t\t\tthrow new Error(\"Context epoch snapshot is outside its captured source\");\n\t\t\tif (captured.leafId !== null) {\n\t\t\t\tconst leaf = await query(() => index.get(sessionId, captured.leafId!, scope));\n\t\t\t\tif (!leaf || leaf.sequence > captured.sourceSequence)\n\t\t\t\t\tthrow new Error(\"Context epoch snapshot is outside its captured branch\");\n\t\t\t}\n\t\t\treturn createBranchHistoryReadView(index, captured, query);\n\t\t},\n\t\tcontextManifest: (options: ContextManifestOptions = {}) =>\n\t\t\tquery(() => index.contextManifest(sessionId, scope, options)),\n\t\tcontextUpdates: (target: ContextUpdateTarget) => query(() => index.contextUpdates(sessionId, scope, target)),\n\t\treadContextUpdatePayload: (id: string, target: ContextUpdateTarget, options: HistoryPayloadReadOptions = {}) =>\n\t\t\tquery(() => index.readContextUpdatePayload(sessionId, id, scope, target, options)),\n\t\tget: (id: string) => query(() => index.get(sessionId, id, scope)),\n\t\tpage: (after = 0, limit = 64) => query(() => index.page(sessionId, after, scope.through, limit, scope)),\n\t\tsearch: (text: string, limit = 16) => query(() => index.search(sessionId, text, scope.through, limit, scope)),\n\t\ttaskEvidence: (options: TaskEvidenceOptions = {}) => query(() => index.taskEvidence(sessionId, scope, options)),\n\t\treadPayload: (id: string, options: HistoryPayloadReadOptions = {}) =>\n\t\t\tquery(() => index.readPayload(sessionId, id, scope, options)),\n\t});\n}\n\nfunction positiveLimit(value: number): boolean {\n\treturn Number.isSafeInteger(value) && value > 0;\n}\n\n/** Reuse the same bounded payload/identity hydration for a captured branch adapter. */\nexport async function hydrateCapturedHistoryEntry(\n\tmetadata: IndexedSourceEvent,\n\tmaxSourceBytes: number,\n\treadPayload: SessionHistoryReadView[\"readPayload\"],\n): Promise<HydratedSessionHistoryEntry> {\n\tif (metadata.locator.length > maxSourceBytes) throw new Error(\"History entry source byte budget exceeded\");\n\tconst chunks: string[] = [];\n\tlet bytes = 0;\n\tlet cursor: CanonicalPayloadCursor | undefined;\n\tdo {\n\t\tconst fragment = await readPayload(metadata.id, {\n\t\t\tcursor,\n\t\t\tmaxBytes: Math.min(MAX_CANONICAL_PAYLOAD_PART_BYTES, maxSourceBytes - bytes),\n\t\t});\n\t\tif (!fragment) throw new Error(\"Captured history entry payload is unavailable\");\n\t\tbytes += fragment.byteLength;\n\t\tif (bytes > maxSourceBytes) throw new Error(\"History entry source byte budget exceeded\");\n\t\tchunks.push(fragment.text);\n\t\tcursor = fragment.nextCursor ?? undefined;\n\t} while (cursor);\n\tconst entry = JSON.parse(chunks.join(\"\")) as SessionEntry;\n\tif (\n\t\t!entry ||\n\t\ttypeof entry !== \"object\" ||\n\t\tentry.id !== metadata.id ||\n\t\tentry.type !== metadata.kind ||\n\t\tentry.parentId !== metadata.parentId\n\t)\n\t\tthrow new Error(\"Canonical history entry does not match indexed identity\");\n\treturn { entry, source: metadata };\n}\n\n/** Source access is selected explicitly, never by widening a coordinator's branch view. */\nexport function createSessionHistoryReadScope(\n\tindex: HistoryIndex,\n\tsource: SourceSnapshotRef,\n\tquery: HistoryReadQuery,\n\tscope: \"branch\" | \"source\",\n): SessionHistoryReadScope {\n\tconst sessionId = source.sessionId;\n\tconst branch = { leafId: source.leafId, through: source.sourceSequence };\n\tconst get = (id: string) =>\n\t\tquery(() =>\n\t\t\tscope === \"branch\" ? index.get(sessionId, id, branch) : index.getSource(sessionId, id, source.sourceSequence),\n\t\t);\n\tconst page = (after = 0, limit = 64) =>\n\t\tquery(() => index.page(sessionId, after, source.sourceSequence, limit, scope === \"branch\" ? branch : undefined));\n\tconst readPayload = (id: string, options: HistoryPayloadReadOptions = {}) =>\n\t\tquery(() =>\n\t\t\tscope === \"branch\"\n\t\t\t\t? index.readPayload(sessionId, id, branch, options)\n\t\t\t\t: index.readSourcePayload(sessionId, id, source.sourceSequence, options),\n\t\t);\n\n\tconst hydrate = (metadata: IndexedSourceEvent, maxSourceBytes: number) =>\n\t\thydrateCapturedHistoryEntry(metadata, maxSourceBytes, readPayload);\n\n\tasync function* iterateEntries(limits: SessionHistoryReadLimits): AsyncGenerator<HydratedSessionHistoryEntry> {\n\t\tconst { maxEntries, maxSourceBytes } = limits;\n\t\tif (!positiveLimit(maxEntries) || !positiveLimit(maxSourceBytes))\n\t\t\tthrow new Error(\"Invalid history materialization limits\");\n\t\tlet after = 0;\n\t\tlet entries = 0;\n\t\tlet sourceBytes = 0;\n\t\twhile (true) {\n\t\t\tconst selected = await page(after, Math.min(64, maxEntries - entries + 1));\n\t\t\tif (selected.indexedThrough < source.sourceSequence)\n\t\t\t\tthrow new Error(\"Captured history has incomplete index coverage\");\n\t\t\tfor (const metadata of selected.events) {\n\t\t\t\tif (++entries > maxEntries) throw new Error(\"History entry budget exceeded\");\n\t\t\t\tif (sourceBytes + metadata.locator.length > maxSourceBytes)\n\t\t\t\t\tthrow new Error(\"History source byte budget exceeded\");\n\t\t\t\tconst hydrated = await hydrate(metadata, maxSourceBytes - sourceBytes);\n\t\t\t\tsourceBytes += metadata.locator.length;\n\t\t\t\tyield hydrated;\n\t\t\t}\n\t\t\tif (selected.nextAfter === null) return;\n\t\t\tafter = selected.nextAfter;\n\t\t}\n\t}\n\n\treturn Object.freeze({\n\t\tsource,\n\t\tscope,\n\t\tbranchContext: createBranchHistoryReadView(index, source, query),\n\t\tbranchBootstrap: () => query(async () => ({ ...(await index.branchBootstrap(sessionId, branch)), source })),\n\t\tparentPath: (options: ParentPathOptions = {}) =>\n\t\t\tquery(async () => ({ ...(await index.parentPath(sessionId, branch, options)), source })),\n\t\tparentPathFrom: (leafId: string | null, options: ParentPathOptions = {}) =>\n\t\t\tquery(async () => {\n\t\t\t\tif (scope !== \"source\") throw new Error(\"Parent path selection requires a source-scoped history read\");\n\t\t\t\treturn {\n\t\t\t\t\t...(await index.parentPath(sessionId, { leafId, through: source.sourceSequence }, options)),\n\t\t\t\t\tsource,\n\t\t\t\t};\n\t\t\t}),\n\t\tsourceLabel: (targetId: string) => query(() => index.sourceLabel(sessionId, targetId, source.sourceSequence)),\n\t\tsourceAssistantUsage: (targetId: string) =>\n\t\t\tquery(() => index.sourceAssistantUsage(sessionId, targetId, source.sourceSequence)),\n\t\tipythonSentMessages: (toolCallId: string, options: IpythonSentMessagesOptions = {}) =>\n\t\t\tquery(() => index.ipythonSentMessages(sessionId, branch, toolCallId, options)),\n\t\tget,\n\t\tpage,\n\t\tsearch: (text: string, limit = 16) =>\n\t\t\tquery(() =>\n\t\t\t\tindex.search(sessionId, text, source.sourceSequence, limit, scope === \"branch\" ? branch : undefined),\n\t\t\t),\n\t\treadPayload,\n\t\thydrateEntry: async (id: string, maxSourceBytes: number) => {\n\t\t\tif (!positiveLimit(maxSourceBytes)) throw new Error(\"Invalid history entry source byte budget\");\n\t\t\tconst metadata = await get(id);\n\t\t\treturn metadata ? hydrate(metadata, maxSourceBytes) : undefined;\n\t\t},\n\t\titerateEntries: (limits: SessionHistoryReadLimits) => iterateEntries({ ...limits }),\n\t\tmaterialize: async (limits: SessionHistoryReadLimits) => {\n\t\t\tconst entries: HydratedSessionHistoryEntry[] = [];\n\t\t\tlet sourceBytes = 0;\n\t\t\tfor await (const entry of iterateEntries(limits)) {\n\t\t\t\tentries.push(entry);\n\t\t\t\tsourceBytes += entry.source.locator.length;\n\t\t\t}\n\t\t\treturn { source, scope, entries, sourceBytes };\n\t\t},\n\t});\n}\n\n/** A derived, coalescing feed. Canonical source ACKs do not depend on index availability. */\nexport class SessionHistoryIndex {\n\tprivate index?: HistoryIndex;\n\tprivate latest?: SessionJournalState;\n\tprivate indexedThrough = -1;\n\tprivate pumping?: Promise<void>;\n\tprivate failure?: unknown;\n\tprivate closing?: Promise<void>;\n\n\tconstructor(\n\t\tprivate readonly sessionId: string,\n\t\tprivate readonly path: string,\n\t) {}\n\n\t/** Retain at most one newer snapshot while the external worker indexes a prefix. */\n\tpublish(snapshot: SessionJournalState): void {\n\t\tif (this.closing) return;\n\t\tif (!this.latest || snapshot.nextSequence > this.latest.nextSequence) this.latest = { ...snapshot };\n\t\tthis.start();\n\t}\n\n\tprivate needsWork(): boolean {\n\t\treturn this.latest !== undefined && this.indexedThrough < this.latest.nextSequence - 1;\n\t}\n\n\tprivate start(): void {\n\t\tif (this.pumping || !this.needsWork()) return;\n\t\tthis.failure = undefined;\n\t\tconst job = this.pump();\n\t\tthis.pumping = job;\n\t\tvoid job.then(() => {\n\t\t\tthis.pumping = undefined;\n\t\t\tif (!this.failure && this.needsWork()) this.start();\n\t\t});\n\t}\n\n\tprivate async pump(): Promise<void> {\n\t\twhile (this.latest && this.needsWork()) {\n\t\t\tconst snapshot = this.latest;\n\t\t\ttry {\n\t\t\t\tthis.index ??= await HistoryIndex.open(this.path);\n\t\t\t\tconst frontier = await this.index.syncSource(this.sessionId, snapshot);\n\t\t\t\tthis.indexedThrough = frontier.indexedThrough;\n\t\t\t} catch (error) {\n\t\t\t\tthis.failure = error;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Callers must apply their captured sequence/branch scope to the following query. */\n\tasync synchronize(snapshot: SessionJournalState): Promise<HistoryIndex> {\n\t\tif (this.closing) throw new Error(\"Session history index is closing\");\n\t\tthis.publish(snapshot);\n\t\twhile (this.indexedThrough < snapshot.nextSequence - 1) {\n\t\t\tconst job = this.pumping;\n\t\t\tif (!job) throw this.failure ?? new Error(\"Session history index has incomplete coverage\");\n\t\t\tawait job;\n\t\t}\n\t\tif (!this.index) throw new Error(\"Session history index is unavailable\");\n\t\treturn this.index;\n\t}\n\n\t/** Internal current-owner bootstrap; never substitutes current facts for an older captured prefix. */\n\tasync currentSourceBootstrap(snapshot: SessionJournalState): Promise<SourceBootstrapState> {\n\t\tconst captured = { ...snapshot };\n\t\tconst index = await this.synchronize(captured);\n\t\treturn index.currentSourceBootstrap(this.sessionId, captured);\n\t}\n\n\t/** Finish accepted indexing, then wait for the external worker to close. */\n\tclose(): Promise<void> {\n\t\tthis.closing ??= (async () => {\n\t\t\twhile (this.pumping) await this.pumping;\n\t\t\tawait this.index?.close();\n\t\t})();\n\t\treturn this.closing;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session-history-index.d.ts","sourceRoot":"","sources":["../../src/core/session-history-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,wBAAwB,EAE7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,YAAY,EACZ,KAAK,gBAAgB,EACrB,KA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AAE,mBAAmB,GAAG,IAAI,CAI3C;IAED,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,KAAK;YAWC,IAAI;IAclB,sFAAsF;IAChF,WAAW,CAAC,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC,CAUtE;IAED,sGAAsG;IAChG,sBAAsB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAIzF;IAED,4EAA4E;IAC5E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAMrB;CACD","sourcesContent":["import {\n\ttype CanonicalPayloadCursor,\n\ttype CanonicalPayloadFragment,\n\tMAX_CANONICAL_PAYLOAD_PART_BYTES,\n} from \"./canonical-payload-parts.js\";\nimport {\n\ttype BranchBootstrapState,\n\ttype ContextManifestOptions,\n\ttype ContextManifestPage,\n\ttype ContextUpdates,\n\ttype ContextUpdateTarget,\n\tHistoryIndex,\n\ttype HistoryIndexPage,\n\ttype HistoryPayloadReadOptions,\n\ttype IndexedSourceEvent,\n\ttype IpythonSentMessagesOptions,\n\ttype IpythonSentMessagesPage,\n\ttype ParentPathOptions,\n\ttype ParentPathPage,\n\ttype SourceBootstrapState,\n\ttype TaskEvidenceOptions,\n\ttype TaskEvidencePage,\n} from \"./history-index.js\";\nimport type { BoundRequestSink, SourceSnapshotRef } from \"./request-events.js\";\nimport type { SessionJournalState } from \"./session-journal-owner.js\";\nimport type { SessionEntry } from \"./session-manager.js\";\n\n/** One source/branch frontier shared by every operation in a captured request. */\nexport interface SessionHistoryReadView {\n\treadonly source: SourceSnapshotRef;\n\t/** A narrower ancestor/prefix on this same capture; its lifetime never outlives the parent read. */\n\tatSnapshot?(source: SourceSnapshotRef): Promise<SessionHistoryReadView>;\n\tcontextManifest(options?: ContextManifestOptions): Promise<ContextManifestPage>;\n\tcontextUpdates(target: ContextUpdateTarget): Promise<ContextUpdates>;\n\treadContextUpdatePayload(\n\t\tid: string,\n\t\ttarget: ContextUpdateTarget,\n\t\toptions?: HistoryPayloadReadOptions,\n\t): Promise<CanonicalPayloadFragment | undefined>;\n\tget(id: string): Promise<IndexedSourceEvent | undefined>;\n\tpage(after?: number, limit?: number, options?: { scan?: boolean }): Promise<HistoryIndexPage>;\n\tsearch(query: string, limit?: number): Promise<HistoryIndexPage>;\n\ttaskEvidence(options?: TaskEvidenceOptions): Promise<TaskEvidencePage>;\n\treadPayload(id: string, options?: HistoryPayloadReadOptions): Promise<CanonicalPayloadFragment | undefined>;\n}\n\nexport interface BoundHistoryReadSink<View> extends Omit<BoundRequestSink, \"readHistory\"> {\n\treadHistory<T>(read: (view: View) => Promise<T>): Promise<T>;\n}\n\nexport interface BoundSessionRequestSink extends BoundHistoryReadSink<SessionHistoryReadView> {}\n\nexport interface SessionHistoryReadLimits {\n\tmaxEntries: number;\n\t/** Canonical frame bytes, not a decoded heap or tokenizer estimate. */\n\tmaxSourceBytes: number;\n}\n\nexport interface HydratedSessionHistoryEntry {\n\tentry: SessionEntry;\n\t/** Includes the exact locator/revision and lowering-only retention outside the payload. */\n\tsource: IndexedSourceEvent;\n}\n\nexport interface MaterializedSessionHistory {\n\tsource: SourceSnapshotRef;\n\tscope: \"branch\" | \"source\";\n\tentries: HydratedSessionHistoryEntry[];\n\tsourceBytes: number;\n}\n\n/** Bootstrap refs and booleans from the same pinned branch used for exact hydration. */\nexport interface SessionBranchBootstrapState extends BranchBootstrapState {\n\treadonly source: SourceSnapshotRef;\n}\n\n/** Exact parent-chain metadata from one captured canonical source and leaf. */\nexport interface SessionParentPathPage extends ParentPathPage {\n\treadonly source: SourceSnapshotRef;\n}\n\n/** Consume iterators inside the owning read callback. Materialized results are detached. */\nexport interface SessionHistoryReadScope {\n\treadonly source: SourceSnapshotRef;\n\treadonly scope: \"branch\" | \"source\";\n\treadonly branchContext: SessionHistoryReadView;\n\t/** Select the captured branch even when invoked from an explicit whole-source scope. */\n\tbranchBootstrap(): Promise<SessionBranchBootstrapState>;\n\t/** Chronological parent chain only; attached request evidence is not an ancestor. */\n\tparentPath(options?: ParentPathOptions): Promise<SessionParentPathPage>;\n\t/** Source scope only: use another leaf without changing the captured source or branchContext. */\n\tparentPathFrom(leafId: string | null, options?: ParentPathOptions): Promise<SessionParentPathPage>;\n\t/** Explicit whole-source relations, clipped to this captured prefix. */\n\tsourceLabel(targetId: string): Promise<IndexedSourceEvent | undefined>;\n\tsourceAssistantUsage(targetId: string): Promise<IndexedSourceEvent | undefined>;\n\t/** Exact sent-message refs on the original captured parent branch, even before a tool result. */\n\tipythonSentMessages(toolCallId: string, options?: IpythonSentMessagesOptions): Promise<IpythonSentMessagesPage>;\n\tget(id: string): Promise<IndexedSourceEvent | undefined>;\n\tpage(after?: number, limit?: number): Promise<HistoryIndexPage>;\n\tsearch(query: string, limit?: number): Promise<HistoryIndexPage>;\n\treadPayload(id: string, options?: HistoryPayloadReadOptions): Promise<CanonicalPayloadFragment | undefined>;\n\thydrateEntry(id: string, maxSourceBytes: number): Promise<HydratedSessionHistoryEntry | undefined>;\n\titerateEntries(limits: SessionHistoryReadLimits): AsyncGenerator<HydratedSessionHistoryEntry>;\n\tmaterialize(limits: SessionHistoryReadLimits): Promise<MaterializedSessionHistory>;\n}\n\nexport type HistoryReadQuery = <T>(operation: () => Promise<T>) => Promise<T>;\n\n/** Existing inference/request views remain strictly branch-scoped. */\nexport function createBranchHistoryReadView(\n\tindex: HistoryIndex,\n\tsource: SourceSnapshotRef,\n\tquery: HistoryReadQuery,\n): SessionHistoryReadView {\n\tconst sessionId = source.sessionId;\n\tconst scope = { leafId: source.leafId, through: source.sourceSequence };\n\treturn Object.freeze({\n\t\tsource,\n\t\tatSnapshot: async (requested: SourceSnapshotRef) => {\n\t\t\tconst captured = Object.freeze({ ...requested });\n\t\t\tif (\n\t\t\t\tcaptured.sessionId !== sessionId ||\n\t\t\t\tcaptured.sessionFile !== source.sessionFile ||\n\t\t\t\tcaptured.persistent !== source.persistent ||\n\t\t\t\t!Number.isSafeInteger(captured.sourceSequence) ||\n\t\t\t\tcaptured.sourceSequence < 0 ||\n\t\t\t\tcaptured.sourceSequence > source.sourceSequence\n\t\t\t)\n\t\t\t\tthrow new Error(\"Context epoch snapshot is outside its captured source\");\n\t\t\tif (captured.leafId !== null) {\n\t\t\t\tconst leaf = await query(() => index.get(sessionId, captured.leafId!, scope));\n\t\t\t\tif (!leaf || leaf.sequence > captured.sourceSequence)\n\t\t\t\t\tthrow new Error(\"Context epoch snapshot is outside its captured branch\");\n\t\t\t}\n\t\t\treturn createBranchHistoryReadView(index, captured, query);\n\t\t},\n\t\tcontextManifest: (options: ContextManifestOptions = {}) =>\n\t\t\tquery(() => index.contextManifest(sessionId, scope, options)),\n\t\tcontextUpdates: (target: ContextUpdateTarget) => query(() => index.contextUpdates(sessionId, scope, target)),\n\t\treadContextUpdatePayload: (id: string, target: ContextUpdateTarget, options: HistoryPayloadReadOptions = {}) =>\n\t\t\tquery(() => index.readContextUpdatePayload(sessionId, id, scope, target, options)),\n\t\tget: (id: string) => query(() => index.get(sessionId, id, scope)),\n\t\tpage: (after = 0, limit = 64, options: { scan?: boolean } = {}) =>\n\t\t\tquery(() => index.page(sessionId, after, scope.through, limit, scope, options)),\n\t\tsearch: (text: string, limit = 16) => query(() => index.search(sessionId, text, scope.through, limit, scope)),\n\t\ttaskEvidence: (options: TaskEvidenceOptions = {}) => query(() => index.taskEvidence(sessionId, scope, options)),\n\t\treadPayload: (id: string, options: HistoryPayloadReadOptions = {}) =>\n\t\t\tquery(() => index.readPayload(sessionId, id, scope, options)),\n\t});\n}\n\nfunction positiveLimit(value: number): boolean {\n\treturn Number.isSafeInteger(value) && value > 0;\n}\n\n/** Reuse the same bounded payload/identity hydration for a captured branch adapter. */\nexport async function hydrateCapturedHistoryEntry(\n\tmetadata: IndexedSourceEvent,\n\tmaxSourceBytes: number,\n\treadPayload: SessionHistoryReadView[\"readPayload\"],\n): Promise<HydratedSessionHistoryEntry> {\n\tif (metadata.locator.length > maxSourceBytes) throw new Error(\"History entry source byte budget exceeded\");\n\tconst chunks: string[] = [];\n\tlet bytes = 0;\n\tlet cursor: CanonicalPayloadCursor | undefined;\n\tdo {\n\t\tconst fragment = await readPayload(metadata.id, {\n\t\t\tcursor,\n\t\t\tmaxBytes: Math.min(MAX_CANONICAL_PAYLOAD_PART_BYTES, maxSourceBytes - bytes),\n\t\t});\n\t\tif (!fragment) throw new Error(\"Captured history entry payload is unavailable\");\n\t\tbytes += fragment.byteLength;\n\t\tif (bytes > maxSourceBytes) throw new Error(\"History entry source byte budget exceeded\");\n\t\tchunks.push(fragment.text);\n\t\tcursor = fragment.nextCursor ?? undefined;\n\t} while (cursor);\n\tconst entry = JSON.parse(chunks.join(\"\")) as SessionEntry;\n\tif (\n\t\t!entry ||\n\t\ttypeof entry !== \"object\" ||\n\t\tentry.id !== metadata.id ||\n\t\tentry.type !== metadata.kind ||\n\t\tentry.parentId !== metadata.parentId\n\t)\n\t\tthrow new Error(\"Canonical history entry does not match indexed identity\");\n\treturn { entry, source: metadata };\n}\n\n/** Source access is selected explicitly, never by widening a coordinator's branch view. */\nexport function createSessionHistoryReadScope(\n\tindex: HistoryIndex,\n\tsource: SourceSnapshotRef,\n\tquery: HistoryReadQuery,\n\tscope: \"branch\" | \"source\",\n): SessionHistoryReadScope {\n\tconst sessionId = source.sessionId;\n\tconst branch = { leafId: source.leafId, through: source.sourceSequence };\n\tconst get = (id: string) =>\n\t\tquery(() =>\n\t\t\tscope === \"branch\" ? index.get(sessionId, id, branch) : index.getSource(sessionId, id, source.sourceSequence),\n\t\t);\n\tconst page = (after = 0, limit = 64) =>\n\t\tquery(() => index.page(sessionId, after, source.sourceSequence, limit, scope === \"branch\" ? branch : undefined));\n\tconst readPayload = (id: string, options: HistoryPayloadReadOptions = {}) =>\n\t\tquery(() =>\n\t\t\tscope === \"branch\"\n\t\t\t\t? index.readPayload(sessionId, id, branch, options)\n\t\t\t\t: index.readSourcePayload(sessionId, id, source.sourceSequence, options),\n\t\t);\n\n\tconst hydrate = (metadata: IndexedSourceEvent, maxSourceBytes: number) =>\n\t\thydrateCapturedHistoryEntry(metadata, maxSourceBytes, readPayload);\n\n\tasync function* iterateEntries(limits: SessionHistoryReadLimits): AsyncGenerator<HydratedSessionHistoryEntry> {\n\t\tconst { maxEntries, maxSourceBytes } = limits;\n\t\tif (!positiveLimit(maxEntries) || !positiveLimit(maxSourceBytes))\n\t\t\tthrow new Error(\"Invalid history materialization limits\");\n\t\tlet after = 0;\n\t\tlet entries = 0;\n\t\tlet sourceBytes = 0;\n\t\twhile (true) {\n\t\t\tconst selected = await page(after, Math.min(64, maxEntries - entries + 1));\n\t\t\tif (selected.indexedThrough < source.sourceSequence)\n\t\t\t\tthrow new Error(\"Captured history has incomplete index coverage\");\n\t\t\tfor (const metadata of selected.events) {\n\t\t\t\tif (++entries > maxEntries) throw new Error(\"History entry budget exceeded\");\n\t\t\t\tif (sourceBytes + metadata.locator.length > maxSourceBytes)\n\t\t\t\t\tthrow new Error(\"History source byte budget exceeded\");\n\t\t\t\tconst hydrated = await hydrate(metadata, maxSourceBytes - sourceBytes);\n\t\t\t\tsourceBytes += metadata.locator.length;\n\t\t\t\tyield hydrated;\n\t\t\t}\n\t\t\tif (selected.nextAfter === null) return;\n\t\t\tafter = selected.nextAfter;\n\t\t}\n\t}\n\n\treturn Object.freeze({\n\t\tsource,\n\t\tscope,\n\t\tbranchContext: createBranchHistoryReadView(index, source, query),\n\t\tbranchBootstrap: () => query(async () => ({ ...(await index.branchBootstrap(sessionId, branch)), source })),\n\t\tparentPath: (options: ParentPathOptions = {}) =>\n\t\t\tquery(async () => ({ ...(await index.parentPath(sessionId, branch, options)), source })),\n\t\tparentPathFrom: (leafId: string | null, options: ParentPathOptions = {}) =>\n\t\t\tquery(async () => {\n\t\t\t\tif (scope !== \"source\") throw new Error(\"Parent path selection requires a source-scoped history read\");\n\t\t\t\treturn {\n\t\t\t\t\t...(await index.parentPath(sessionId, { leafId, through: source.sourceSequence }, options)),\n\t\t\t\t\tsource,\n\t\t\t\t};\n\t\t\t}),\n\t\tsourceLabel: (targetId: string) => query(() => index.sourceLabel(sessionId, targetId, source.sourceSequence)),\n\t\tsourceAssistantUsage: (targetId: string) =>\n\t\t\tquery(() => index.sourceAssistantUsage(sessionId, targetId, source.sourceSequence)),\n\t\tipythonSentMessages: (toolCallId: string, options: IpythonSentMessagesOptions = {}) =>\n\t\t\tquery(() => index.ipythonSentMessages(sessionId, branch, toolCallId, options)),\n\t\tget,\n\t\tpage,\n\t\tsearch: (text: string, limit = 16) =>\n\t\t\tquery(() =>\n\t\t\t\tindex.search(sessionId, text, source.sourceSequence, limit, scope === \"branch\" ? branch : undefined),\n\t\t\t),\n\t\treadPayload,\n\t\thydrateEntry: async (id: string, maxSourceBytes: number) => {\n\t\t\tif (!positiveLimit(maxSourceBytes)) throw new Error(\"Invalid history entry source byte budget\");\n\t\t\tconst metadata = await get(id);\n\t\t\treturn metadata ? hydrate(metadata, maxSourceBytes) : undefined;\n\t\t},\n\t\titerateEntries: (limits: SessionHistoryReadLimits) => iterateEntries({ ...limits }),\n\t\tmaterialize: async (limits: SessionHistoryReadLimits) => {\n\t\t\tconst entries: HydratedSessionHistoryEntry[] = [];\n\t\t\tlet sourceBytes = 0;\n\t\t\tfor await (const entry of iterateEntries(limits)) {\n\t\t\t\tentries.push(entry);\n\t\t\t\tsourceBytes += entry.source.locator.length;\n\t\t\t}\n\t\t\treturn { source, scope, entries, sourceBytes };\n\t\t},\n\t});\n}\n\n/** A derived, coalescing feed. Canonical source ACKs do not depend on index availability. */\nexport class SessionHistoryIndex {\n\tprivate index?: HistoryIndex;\n\tprivate latest?: SessionJournalState;\n\tprivate indexedThrough = -1;\n\tprivate pumping?: Promise<void>;\n\tprivate failure?: unknown;\n\tprivate closing?: Promise<void>;\n\n\tconstructor(\n\t\tprivate readonly sessionId: string,\n\t\tprivate readonly path: string,\n\t) {}\n\n\t/** Retain at most one newer snapshot while the external worker indexes a prefix. */\n\tpublish(snapshot: SessionJournalState): void {\n\t\tif (this.closing) return;\n\t\tif (!this.latest || snapshot.nextSequence > this.latest.nextSequence) this.latest = { ...snapshot };\n\t\tthis.start();\n\t}\n\n\tprivate needsWork(): boolean {\n\t\treturn this.latest !== undefined && this.indexedThrough < this.latest.nextSequence - 1;\n\t}\n\n\tprivate start(): void {\n\t\tif (this.pumping || !this.needsWork()) return;\n\t\tthis.failure = undefined;\n\t\tconst job = this.pump();\n\t\tthis.pumping = job;\n\t\tvoid job.then(() => {\n\t\t\tthis.pumping = undefined;\n\t\t\tif (!this.failure && this.needsWork()) this.start();\n\t\t});\n\t}\n\n\tprivate async pump(): Promise<void> {\n\t\twhile (this.latest && this.needsWork()) {\n\t\t\tconst snapshot = this.latest;\n\t\t\ttry {\n\t\t\t\tthis.index ??= await HistoryIndex.open(this.path);\n\t\t\t\tconst frontier = await this.index.syncSource(this.sessionId, snapshot);\n\t\t\t\tthis.indexedThrough = frontier.indexedThrough;\n\t\t\t} catch (error) {\n\t\t\t\tthis.failure = error;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Callers must apply their captured sequence/branch scope to the following query. */\n\tasync synchronize(snapshot: SessionJournalState): Promise<HistoryIndex> {\n\t\tif (this.closing) throw new Error(\"Session history index is closing\");\n\t\tthis.publish(snapshot);\n\t\twhile (this.indexedThrough < snapshot.nextSequence - 1) {\n\t\t\tconst job = this.pumping;\n\t\t\tif (!job) throw this.failure ?? new Error(\"Session history index has incomplete coverage\");\n\t\t\tawait job;\n\t\t}\n\t\tif (!this.index) throw new Error(\"Session history index is unavailable\");\n\t\treturn this.index;\n\t}\n\n\t/** Internal current-owner bootstrap; never substitutes current facts for an older captured prefix. */\n\tasync currentSourceBootstrap(snapshot: SessionJournalState): Promise<SourceBootstrapState> {\n\t\tconst captured = { ...snapshot };\n\t\tconst index = await this.synchronize(captured);\n\t\treturn index.currentSourceBootstrap(this.sessionId, captured);\n\t}\n\n\t/** Finish accepted indexing, then wait for the external worker to close. */\n\tclose(): Promise<void> {\n\t\tthis.closing ??= (async () => {\n\t\t\twhile (this.pumping) await this.pumping;\n\t\t\tawait this.index?.close();\n\t\t})();\n\t\treturn this.closing;\n\t}\n}\n"]}
|
|
@@ -26,7 +26,7 @@ export function createBranchHistoryReadView(index, source, query) {
|
|
|
26
26
|
contextUpdates: (target) => query(() => index.contextUpdates(sessionId, scope, target)),
|
|
27
27
|
readContextUpdatePayload: (id, target, options = {}) => query(() => index.readContextUpdatePayload(sessionId, id, scope, target, options)),
|
|
28
28
|
get: (id) => query(() => index.get(sessionId, id, scope)),
|
|
29
|
-
page: (after = 0, limit = 64) => query(() => index.page(sessionId, after, scope.through, limit, scope)),
|
|
29
|
+
page: (after = 0, limit = 64, options = {}) => query(() => index.page(sessionId, after, scope.through, limit, scope, options)),
|
|
30
30
|
search: (text, limit = 16) => query(() => index.search(sessionId, text, scope.through, limit, scope)),
|
|
31
31
|
taskEvidence: (options = {}) => query(() => index.taskEvidence(sessionId, scope, options)),
|
|
32
32
|
readPayload: (id, options = {}) => query(() => index.readPayload(sessionId, id, scope, options)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-history-index.js","sourceRoot":"","sources":["../../src/core/session-history-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,gCAAgC,GAChC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAMN,YAAY,GAWZ,MAAM,oBAAoB,CAAC;AAsF5B,sEAAsE;AACtE,MAAM,UAAU,2BAA2B,CAC1C,KAAmB,EACnB,MAAyB,EACzB,KAAuB,EACE;IACzB,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IACnC,MAAM,KAAK,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC;IACxE,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,MAAM;QACN,UAAU,EAAE,KAAK,EAAE,SAA4B,EAAE,EAAE,CAAC;YACnD,MAAM,QAAQ,GAA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AAK,CAAC,sCAAsC,CAAC,CAAC;QACzE,OAAO,IAAI,CAAC,KAAK,CAAC;IAAA,CAClB;IAED,sGAAsG;IACtG,KAAK,CAAC,sBAAsB,CAAC,QAA6B,EAAiC;QAC1F,MAAM,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC,sBAAsB,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAAA,CAC9D;IAED,4EAA4E;IAC5E,KAAK,GAAkB;QACtB,IAAI,CAAC,OAAO,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,OAAO;gBAAE,MAAM,IAAI,CAAC,OAAO,CAAC;YACxC,MAAM,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;QAAA,CAC1B,CAAC,EAAE,CAAC;QACL,OAAO,IAAI,CAAC,OAAO,CAAC;IAAA,CACpB;CACD","sourcesContent":["import {\n\ttype CanonicalPayloadCursor,\n\ttype CanonicalPayloadFragment,\n\tMAX_CANONICAL_PAYLOAD_PART_BYTES,\n} from \"./canonical-payload-parts.js\";\nimport {\n\ttype BranchBootstrapState,\n\ttype ContextManifestOptions,\n\ttype ContextManifestPage,\n\ttype ContextUpdates,\n\ttype ContextUpdateTarget,\n\tHistoryIndex,\n\ttype HistoryIndexPage,\n\ttype HistoryPayloadReadOptions,\n\ttype IndexedSourceEvent,\n\ttype IpythonSentMessagesOptions,\n\ttype IpythonSentMessagesPage,\n\ttype ParentPathOptions,\n\ttype ParentPathPage,\n\ttype SourceBootstrapState,\n\ttype TaskEvidenceOptions,\n\ttype TaskEvidencePage,\n} from \"./history-index.js\";\nimport type { BoundRequestSink, SourceSnapshotRef } from \"./request-events.js\";\nimport type { SessionJournalState } from \"./session-journal-owner.js\";\nimport type { SessionEntry } from \"./session-manager.js\";\n\n/** One source/branch frontier shared by every operation in a captured request. */\nexport interface SessionHistoryReadView {\n\treadonly source: SourceSnapshotRef;\n\t/** A narrower ancestor/prefix on this same capture; its lifetime never outlives the parent read. */\n\tatSnapshot?(source: SourceSnapshotRef): Promise<SessionHistoryReadView>;\n\tcontextManifest(options?: ContextManifestOptions): Promise<ContextManifestPage>;\n\tcontextUpdates(target: ContextUpdateTarget): Promise<ContextUpdates>;\n\treadContextUpdatePayload(\n\t\tid: string,\n\t\ttarget: ContextUpdateTarget,\n\t\toptions?: HistoryPayloadReadOptions,\n\t): Promise<CanonicalPayloadFragment | undefined>;\n\tget(id: string): Promise<IndexedSourceEvent | undefined>;\n\tpage(after?: number, limit?: number): Promise<HistoryIndexPage>;\n\tsearch(query: string, limit?: number): Promise<HistoryIndexPage>;\n\ttaskEvidence(options?: TaskEvidenceOptions): Promise<TaskEvidencePage>;\n\treadPayload(id: string, options?: HistoryPayloadReadOptions): Promise<CanonicalPayloadFragment | undefined>;\n}\n\nexport interface BoundHistoryReadSink<View> extends Omit<BoundRequestSink, \"readHistory\"> {\n\treadHistory<T>(read: (view: View) => Promise<T>): Promise<T>;\n}\n\nexport interface BoundSessionRequestSink extends BoundHistoryReadSink<SessionHistoryReadView> {}\n\nexport interface SessionHistoryReadLimits {\n\tmaxEntries: number;\n\t/** Canonical frame bytes, not a decoded heap or tokenizer estimate. */\n\tmaxSourceBytes: number;\n}\n\nexport interface HydratedSessionHistoryEntry {\n\tentry: SessionEntry;\n\t/** Includes the exact locator/revision and lowering-only retention outside the payload. */\n\tsource: IndexedSourceEvent;\n}\n\nexport interface MaterializedSessionHistory {\n\tsource: SourceSnapshotRef;\n\tscope: \"branch\" | \"source\";\n\tentries: HydratedSessionHistoryEntry[];\n\tsourceBytes: number;\n}\n\n/** Bootstrap refs and booleans from the same pinned branch used for exact hydration. */\nexport interface SessionBranchBootstrapState extends BranchBootstrapState {\n\treadonly source: SourceSnapshotRef;\n}\n\n/** Exact parent-chain metadata from one captured canonical source and leaf. */\nexport interface SessionParentPathPage extends ParentPathPage {\n\treadonly source: SourceSnapshotRef;\n}\n\n/** Consume iterators inside the owning read callback. Materialized results are detached. */\nexport interface SessionHistoryReadScope {\n\treadonly source: SourceSnapshotRef;\n\treadonly scope: \"branch\" | \"source\";\n\treadonly branchContext: SessionHistoryReadView;\n\t/** Select the captured branch even when invoked from an explicit whole-source scope. */\n\tbranchBootstrap(): Promise<SessionBranchBootstrapState>;\n\t/** Chronological parent chain only; attached request evidence is not an ancestor. */\n\tparentPath(options?: ParentPathOptions): Promise<SessionParentPathPage>;\n\t/** Source scope only: use another leaf without changing the captured source or branchContext. */\n\tparentPathFrom(leafId: string | null, options?: ParentPathOptions): Promise<SessionParentPathPage>;\n\t/** Explicit whole-source relations, clipped to this captured prefix. */\n\tsourceLabel(targetId: string): Promise<IndexedSourceEvent | undefined>;\n\tsourceAssistantUsage(targetId: string): Promise<IndexedSourceEvent | undefined>;\n\t/** Exact sent-message refs on the original captured parent branch, even before a tool result. */\n\tipythonSentMessages(toolCallId: string, options?: IpythonSentMessagesOptions): Promise<IpythonSentMessagesPage>;\n\tget(id: string): Promise<IndexedSourceEvent | undefined>;\n\tpage(after?: number, limit?: number): Promise<HistoryIndexPage>;\n\tsearch(query: string, limit?: number): Promise<HistoryIndexPage>;\n\treadPayload(id: string, options?: HistoryPayloadReadOptions): Promise<CanonicalPayloadFragment | undefined>;\n\thydrateEntry(id: string, maxSourceBytes: number): Promise<HydratedSessionHistoryEntry | undefined>;\n\titerateEntries(limits: SessionHistoryReadLimits): AsyncGenerator<HydratedSessionHistoryEntry>;\n\tmaterialize(limits: SessionHistoryReadLimits): Promise<MaterializedSessionHistory>;\n}\n\nexport type HistoryReadQuery = <T>(operation: () => Promise<T>) => Promise<T>;\n\n/** Existing inference/request views remain strictly branch-scoped. */\nexport function createBranchHistoryReadView(\n\tindex: HistoryIndex,\n\tsource: SourceSnapshotRef,\n\tquery: HistoryReadQuery,\n): SessionHistoryReadView {\n\tconst sessionId = source.sessionId;\n\tconst scope = { leafId: source.leafId, through: source.sourceSequence };\n\treturn Object.freeze({\n\t\tsource,\n\t\tatSnapshot: async (requested: SourceSnapshotRef) => {\n\t\t\tconst captured = Object.freeze({ ...requested });\n\t\t\tif (\n\t\t\t\tcaptured.sessionId !== sessionId ||\n\t\t\t\tcaptured.sessionFile !== source.sessionFile ||\n\t\t\t\tcaptured.persistent !== source.persistent ||\n\t\t\t\t!Number.isSafeInteger(captured.sourceSequence) ||\n\t\t\t\tcaptured.sourceSequence < 0 ||\n\t\t\t\tcaptured.sourceSequence > source.sourceSequence\n\t\t\t)\n\t\t\t\tthrow new Error(\"Context epoch snapshot is outside its captured source\");\n\t\t\tif (captured.leafId !== null) {\n\t\t\t\tconst leaf = await query(() => index.get(sessionId, captured.leafId!, scope));\n\t\t\t\tif (!leaf || leaf.sequence > captured.sourceSequence)\n\t\t\t\t\tthrow new Error(\"Context epoch snapshot is outside its captured branch\");\n\t\t\t}\n\t\t\treturn createBranchHistoryReadView(index, captured, query);\n\t\t},\n\t\tcontextManifest: (options: ContextManifestOptions = {}) =>\n\t\t\tquery(() => index.contextManifest(sessionId, scope, options)),\n\t\tcontextUpdates: (target: ContextUpdateTarget) => query(() => index.contextUpdates(sessionId, scope, target)),\n\t\treadContextUpdatePayload: (id: string, target: ContextUpdateTarget, options: HistoryPayloadReadOptions = {}) =>\n\t\t\tquery(() => index.readContextUpdatePayload(sessionId, id, scope, target, options)),\n\t\tget: (id: string) => query(() => index.get(sessionId, id, scope)),\n\t\tpage: (after = 0, limit = 64) => query(() => index.page(sessionId, after, scope.through, limit, scope)),\n\t\tsearch: (text: string, limit = 16) => query(() => index.search(sessionId, text, scope.through, limit, scope)),\n\t\ttaskEvidence: (options: TaskEvidenceOptions = {}) => query(() => index.taskEvidence(sessionId, scope, options)),\n\t\treadPayload: (id: string, options: HistoryPayloadReadOptions = {}) =>\n\t\t\tquery(() => index.readPayload(sessionId, id, scope, options)),\n\t});\n}\n\nfunction positiveLimit(value: number): boolean {\n\treturn Number.isSafeInteger(value) && value > 0;\n}\n\n/** Reuse the same bounded payload/identity hydration for a captured branch adapter. */\nexport async function hydrateCapturedHistoryEntry(\n\tmetadata: IndexedSourceEvent,\n\tmaxSourceBytes: number,\n\treadPayload: SessionHistoryReadView[\"readPayload\"],\n): Promise<HydratedSessionHistoryEntry> {\n\tif (metadata.locator.length > maxSourceBytes) throw new Error(\"History entry source byte budget exceeded\");\n\tconst chunks: string[] = [];\n\tlet bytes = 0;\n\tlet cursor: CanonicalPayloadCursor | undefined;\n\tdo {\n\t\tconst fragment = await readPayload(metadata.id, {\n\t\t\tcursor,\n\t\t\tmaxBytes: Math.min(MAX_CANONICAL_PAYLOAD_PART_BYTES, maxSourceBytes - bytes),\n\t\t});\n\t\tif (!fragment) throw new Error(\"Captured history entry payload is unavailable\");\n\t\tbytes += fragment.byteLength;\n\t\tif (bytes > maxSourceBytes) throw new Error(\"History entry source byte budget exceeded\");\n\t\tchunks.push(fragment.text);\n\t\tcursor = fragment.nextCursor ?? undefined;\n\t} while (cursor);\n\tconst entry = JSON.parse(chunks.join(\"\")) as SessionEntry;\n\tif (\n\t\t!entry ||\n\t\ttypeof entry !== \"object\" ||\n\t\tentry.id !== metadata.id ||\n\t\tentry.type !== metadata.kind ||\n\t\tentry.parentId !== metadata.parentId\n\t)\n\t\tthrow new Error(\"Canonical history entry does not match indexed identity\");\n\treturn { entry, source: metadata };\n}\n\n/** Source access is selected explicitly, never by widening a coordinator's branch view. */\nexport function createSessionHistoryReadScope(\n\tindex: HistoryIndex,\n\tsource: SourceSnapshotRef,\n\tquery: HistoryReadQuery,\n\tscope: \"branch\" | \"source\",\n): SessionHistoryReadScope {\n\tconst sessionId = source.sessionId;\n\tconst branch = { leafId: source.leafId, through: source.sourceSequence };\n\tconst get = (id: string) =>\n\t\tquery(() =>\n\t\t\tscope === \"branch\" ? index.get(sessionId, id, branch) : index.getSource(sessionId, id, source.sourceSequence),\n\t\t);\n\tconst page = (after = 0, limit = 64) =>\n\t\tquery(() => index.page(sessionId, after, source.sourceSequence, limit, scope === \"branch\" ? branch : undefined));\n\tconst readPayload = (id: string, options: HistoryPayloadReadOptions = {}) =>\n\t\tquery(() =>\n\t\t\tscope === \"branch\"\n\t\t\t\t? index.readPayload(sessionId, id, branch, options)\n\t\t\t\t: index.readSourcePayload(sessionId, id, source.sourceSequence, options),\n\t\t);\n\n\tconst hydrate = (metadata: IndexedSourceEvent, maxSourceBytes: number) =>\n\t\thydrateCapturedHistoryEntry(metadata, maxSourceBytes, readPayload);\n\n\tasync function* iterateEntries(limits: SessionHistoryReadLimits): AsyncGenerator<HydratedSessionHistoryEntry> {\n\t\tconst { maxEntries, maxSourceBytes } = limits;\n\t\tif (!positiveLimit(maxEntries) || !positiveLimit(maxSourceBytes))\n\t\t\tthrow new Error(\"Invalid history materialization limits\");\n\t\tlet after = 0;\n\t\tlet entries = 0;\n\t\tlet sourceBytes = 0;\n\t\twhile (true) {\n\t\t\tconst selected = await page(after, Math.min(64, maxEntries - entries + 1));\n\t\t\tif (selected.indexedThrough < source.sourceSequence)\n\t\t\t\tthrow new Error(\"Captured history has incomplete index coverage\");\n\t\t\tfor (const metadata of selected.events) {\n\t\t\t\tif (++entries > maxEntries) throw new Error(\"History entry budget exceeded\");\n\t\t\t\tif (sourceBytes + metadata.locator.length > maxSourceBytes)\n\t\t\t\t\tthrow new Error(\"History source byte budget exceeded\");\n\t\t\t\tconst hydrated = await hydrate(metadata, maxSourceBytes - sourceBytes);\n\t\t\t\tsourceBytes += metadata.locator.length;\n\t\t\t\tyield hydrated;\n\t\t\t}\n\t\t\tif (selected.nextAfter === null) return;\n\t\t\tafter = selected.nextAfter;\n\t\t}\n\t}\n\n\treturn Object.freeze({\n\t\tsource,\n\t\tscope,\n\t\tbranchContext: createBranchHistoryReadView(index, source, query),\n\t\tbranchBootstrap: () => query(async () => ({ ...(await index.branchBootstrap(sessionId, branch)), source })),\n\t\tparentPath: (options: ParentPathOptions = {}) =>\n\t\t\tquery(async () => ({ ...(await index.parentPath(sessionId, branch, options)), source })),\n\t\tparentPathFrom: (leafId: string | null, options: ParentPathOptions = {}) =>\n\t\t\tquery(async () => {\n\t\t\t\tif (scope !== \"source\") throw new Error(\"Parent path selection requires a source-scoped history read\");\n\t\t\t\treturn {\n\t\t\t\t\t...(await index.parentPath(sessionId, { leafId, through: source.sourceSequence }, options)),\n\t\t\t\t\tsource,\n\t\t\t\t};\n\t\t\t}),\n\t\tsourceLabel: (targetId: string) => query(() => index.sourceLabel(sessionId, targetId, source.sourceSequence)),\n\t\tsourceAssistantUsage: (targetId: string) =>\n\t\t\tquery(() => index.sourceAssistantUsage(sessionId, targetId, source.sourceSequence)),\n\t\tipythonSentMessages: (toolCallId: string, options: IpythonSentMessagesOptions = {}) =>\n\t\t\tquery(() => index.ipythonSentMessages(sessionId, branch, toolCallId, options)),\n\t\tget,\n\t\tpage,\n\t\tsearch: (text: string, limit = 16) =>\n\t\t\tquery(() =>\n\t\t\t\tindex.search(sessionId, text, source.sourceSequence, limit, scope === \"branch\" ? branch : undefined),\n\t\t\t),\n\t\treadPayload,\n\t\thydrateEntry: async (id: string, maxSourceBytes: number) => {\n\t\t\tif (!positiveLimit(maxSourceBytes)) throw new Error(\"Invalid history entry source byte budget\");\n\t\t\tconst metadata = await get(id);\n\t\t\treturn metadata ? hydrate(metadata, maxSourceBytes) : undefined;\n\t\t},\n\t\titerateEntries: (limits: SessionHistoryReadLimits) => iterateEntries({ ...limits }),\n\t\tmaterialize: async (limits: SessionHistoryReadLimits) => {\n\t\t\tconst entries: HydratedSessionHistoryEntry[] = [];\n\t\t\tlet sourceBytes = 0;\n\t\t\tfor await (const entry of iterateEntries(limits)) {\n\t\t\t\tentries.push(entry);\n\t\t\t\tsourceBytes += entry.source.locator.length;\n\t\t\t}\n\t\t\treturn { source, scope, entries, sourceBytes };\n\t\t},\n\t});\n}\n\n/** A derived, coalescing feed. Canonical source ACKs do not depend on index availability. */\nexport class SessionHistoryIndex {\n\tprivate index?: HistoryIndex;\n\tprivate latest?: SessionJournalState;\n\tprivate indexedThrough = -1;\n\tprivate pumping?: Promise<void>;\n\tprivate failure?: unknown;\n\tprivate closing?: Promise<void>;\n\n\tconstructor(\n\t\tprivate readonly sessionId: string,\n\t\tprivate readonly path: string,\n\t) {}\n\n\t/** Retain at most one newer snapshot while the external worker indexes a prefix. */\n\tpublish(snapshot: SessionJournalState): void {\n\t\tif (this.closing) return;\n\t\tif (!this.latest || snapshot.nextSequence > this.latest.nextSequence) this.latest = { ...snapshot };\n\t\tthis.start();\n\t}\n\n\tprivate needsWork(): boolean {\n\t\treturn this.latest !== undefined && this.indexedThrough < this.latest.nextSequence - 1;\n\t}\n\n\tprivate start(): void {\n\t\tif (this.pumping || !this.needsWork()) return;\n\t\tthis.failure = undefined;\n\t\tconst job = this.pump();\n\t\tthis.pumping = job;\n\t\tvoid job.then(() => {\n\t\t\tthis.pumping = undefined;\n\t\t\tif (!this.failure && this.needsWork()) this.start();\n\t\t});\n\t}\n\n\tprivate async pump(): Promise<void> {\n\t\twhile (this.latest && this.needsWork()) {\n\t\t\tconst snapshot = this.latest;\n\t\t\ttry {\n\t\t\t\tthis.index ??= await HistoryIndex.open(this.path);\n\t\t\t\tconst frontier = await this.index.syncSource(this.sessionId, snapshot);\n\t\t\t\tthis.indexedThrough = frontier.indexedThrough;\n\t\t\t} catch (error) {\n\t\t\t\tthis.failure = error;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Callers must apply their captured sequence/branch scope to the following query. */\n\tasync synchronize(snapshot: SessionJournalState): Promise<HistoryIndex> {\n\t\tif (this.closing) throw new Error(\"Session history index is closing\");\n\t\tthis.publish(snapshot);\n\t\twhile (this.indexedThrough < snapshot.nextSequence - 1) {\n\t\t\tconst job = this.pumping;\n\t\t\tif (!job) throw this.failure ?? new Error(\"Session history index has incomplete coverage\");\n\t\t\tawait job;\n\t\t}\n\t\tif (!this.index) throw new Error(\"Session history index is unavailable\");\n\t\treturn this.index;\n\t}\n\n\t/** Internal current-owner bootstrap; never substitutes current facts for an older captured prefix. */\n\tasync currentSourceBootstrap(snapshot: SessionJournalState): Promise<SourceBootstrapState> {\n\t\tconst captured = { ...snapshot };\n\t\tconst index = await this.synchronize(captured);\n\t\treturn index.currentSourceBootstrap(this.sessionId, captured);\n\t}\n\n\t/** Finish accepted indexing, then wait for the external worker to close. */\n\tclose(): Promise<void> {\n\t\tthis.closing ??= (async () => {\n\t\t\twhile (this.pumping) await this.pumping;\n\t\t\tawait this.index?.close();\n\t\t})();\n\t\treturn this.closing;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session-history-index.js","sourceRoot":"","sources":["../../src/core/session-history-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,gCAAgC,GAChC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAMN,YAAY,GAWZ,MAAM,oBAAoB,CAAC;AAsF5B,sEAAsE;AACtE,MAAM,UAAU,2BAA2B,CAC1C,KAAmB,EACnB,MAAyB,EACzB,KAAuB,EACE;IACzB,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IACnC,MAAM,KAAK,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC;IACxE,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,MAAM;QACN,UAAU,EAAE,KAAK,EAAE,SAA4B,EAAE,EAAE,CAAC;YACnD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;YACjD,IACC,QAAQ,CAAC,SAAS,KAAK,SAAS;gBAChC,QAAQ,CAAC,WAAW,KAAK,MAAM,CAAC,WAAW;gBAC3C,QAAQ,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU;gBACzC,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,cAAc,CAAC;gBAC9C,QAAQ,CAAC,cAA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,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC,sBAAsB,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAAA,CAC9D;IAED,4EAA4E;IAC5E,KAAK,GAAkB;QACtB,IAAI,CAAC,OAAO,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,OAAO;gBAAE,MAAM,IAAI,CAAC,OAAO,CAAC;YACxC,MAAM,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;QAAA,CAC1B,CAAC,EAAE,CAAC;QACL,OAAO,IAAI,CAAC,OAAO,CAAC;IAAA,CACpB;CACD","sourcesContent":["import {\n\ttype CanonicalPayloadCursor,\n\ttype CanonicalPayloadFragment,\n\tMAX_CANONICAL_PAYLOAD_PART_BYTES,\n} from \"./canonical-payload-parts.js\";\nimport {\n\ttype BranchBootstrapState,\n\ttype ContextManifestOptions,\n\ttype ContextManifestPage,\n\ttype ContextUpdates,\n\ttype ContextUpdateTarget,\n\tHistoryIndex,\n\ttype HistoryIndexPage,\n\ttype HistoryPayloadReadOptions,\n\ttype IndexedSourceEvent,\n\ttype IpythonSentMessagesOptions,\n\ttype IpythonSentMessagesPage,\n\ttype ParentPathOptions,\n\ttype ParentPathPage,\n\ttype SourceBootstrapState,\n\ttype TaskEvidenceOptions,\n\ttype TaskEvidencePage,\n} from \"./history-index.js\";\nimport type { BoundRequestSink, SourceSnapshotRef } from \"./request-events.js\";\nimport type { SessionJournalState } from \"./session-journal-owner.js\";\nimport type { SessionEntry } from \"./session-manager.js\";\n\n/** One source/branch frontier shared by every operation in a captured request. */\nexport interface SessionHistoryReadView {\n\treadonly source: SourceSnapshotRef;\n\t/** A narrower ancestor/prefix on this same capture; its lifetime never outlives the parent read. */\n\tatSnapshot?(source: SourceSnapshotRef): Promise<SessionHistoryReadView>;\n\tcontextManifest(options?: ContextManifestOptions): Promise<ContextManifestPage>;\n\tcontextUpdates(target: ContextUpdateTarget): Promise<ContextUpdates>;\n\treadContextUpdatePayload(\n\t\tid: string,\n\t\ttarget: ContextUpdateTarget,\n\t\toptions?: HistoryPayloadReadOptions,\n\t): Promise<CanonicalPayloadFragment | undefined>;\n\tget(id: string): Promise<IndexedSourceEvent | undefined>;\n\tpage(after?: number, limit?: number, options?: { scan?: boolean }): Promise<HistoryIndexPage>;\n\tsearch(query: string, limit?: number): Promise<HistoryIndexPage>;\n\ttaskEvidence(options?: TaskEvidenceOptions): Promise<TaskEvidencePage>;\n\treadPayload(id: string, options?: HistoryPayloadReadOptions): Promise<CanonicalPayloadFragment | undefined>;\n}\n\nexport interface BoundHistoryReadSink<View> extends Omit<BoundRequestSink, \"readHistory\"> {\n\treadHistory<T>(read: (view: View) => Promise<T>): Promise<T>;\n}\n\nexport interface BoundSessionRequestSink extends BoundHistoryReadSink<SessionHistoryReadView> {}\n\nexport interface SessionHistoryReadLimits {\n\tmaxEntries: number;\n\t/** Canonical frame bytes, not a decoded heap or tokenizer estimate. */\n\tmaxSourceBytes: number;\n}\n\nexport interface HydratedSessionHistoryEntry {\n\tentry: SessionEntry;\n\t/** Includes the exact locator/revision and lowering-only retention outside the payload. */\n\tsource: IndexedSourceEvent;\n}\n\nexport interface MaterializedSessionHistory {\n\tsource: SourceSnapshotRef;\n\tscope: \"branch\" | \"source\";\n\tentries: HydratedSessionHistoryEntry[];\n\tsourceBytes: number;\n}\n\n/** Bootstrap refs and booleans from the same pinned branch used for exact hydration. */\nexport interface SessionBranchBootstrapState extends BranchBootstrapState {\n\treadonly source: SourceSnapshotRef;\n}\n\n/** Exact parent-chain metadata from one captured canonical source and leaf. */\nexport interface SessionParentPathPage extends ParentPathPage {\n\treadonly source: SourceSnapshotRef;\n}\n\n/** Consume iterators inside the owning read callback. Materialized results are detached. */\nexport interface SessionHistoryReadScope {\n\treadonly source: SourceSnapshotRef;\n\treadonly scope: \"branch\" | \"source\";\n\treadonly branchContext: SessionHistoryReadView;\n\t/** Select the captured branch even when invoked from an explicit whole-source scope. */\n\tbranchBootstrap(): Promise<SessionBranchBootstrapState>;\n\t/** Chronological parent chain only; attached request evidence is not an ancestor. */\n\tparentPath(options?: ParentPathOptions): Promise<SessionParentPathPage>;\n\t/** Source scope only: use another leaf without changing the captured source or branchContext. */\n\tparentPathFrom(leafId: string | null, options?: ParentPathOptions): Promise<SessionParentPathPage>;\n\t/** Explicit whole-source relations, clipped to this captured prefix. */\n\tsourceLabel(targetId: string): Promise<IndexedSourceEvent | undefined>;\n\tsourceAssistantUsage(targetId: string): Promise<IndexedSourceEvent | undefined>;\n\t/** Exact sent-message refs on the original captured parent branch, even before a tool result. */\n\tipythonSentMessages(toolCallId: string, options?: IpythonSentMessagesOptions): Promise<IpythonSentMessagesPage>;\n\tget(id: string): Promise<IndexedSourceEvent | undefined>;\n\tpage(after?: number, limit?: number): Promise<HistoryIndexPage>;\n\tsearch(query: string, limit?: number): Promise<HistoryIndexPage>;\n\treadPayload(id: string, options?: HistoryPayloadReadOptions): Promise<CanonicalPayloadFragment | undefined>;\n\thydrateEntry(id: string, maxSourceBytes: number): Promise<HydratedSessionHistoryEntry | undefined>;\n\titerateEntries(limits: SessionHistoryReadLimits): AsyncGenerator<HydratedSessionHistoryEntry>;\n\tmaterialize(limits: SessionHistoryReadLimits): Promise<MaterializedSessionHistory>;\n}\n\nexport type HistoryReadQuery = <T>(operation: () => Promise<T>) => Promise<T>;\n\n/** Existing inference/request views remain strictly branch-scoped. */\nexport function createBranchHistoryReadView(\n\tindex: HistoryIndex,\n\tsource: SourceSnapshotRef,\n\tquery: HistoryReadQuery,\n): SessionHistoryReadView {\n\tconst sessionId = source.sessionId;\n\tconst scope = { leafId: source.leafId, through: source.sourceSequence };\n\treturn Object.freeze({\n\t\tsource,\n\t\tatSnapshot: async (requested: SourceSnapshotRef) => {\n\t\t\tconst captured = Object.freeze({ ...requested });\n\t\t\tif (\n\t\t\t\tcaptured.sessionId !== sessionId ||\n\t\t\t\tcaptured.sessionFile !== source.sessionFile ||\n\t\t\t\tcaptured.persistent !== source.persistent ||\n\t\t\t\t!Number.isSafeInteger(captured.sourceSequence) ||\n\t\t\t\tcaptured.sourceSequence < 0 ||\n\t\t\t\tcaptured.sourceSequence > source.sourceSequence\n\t\t\t)\n\t\t\t\tthrow new Error(\"Context epoch snapshot is outside its captured source\");\n\t\t\tif (captured.leafId !== null) {\n\t\t\t\tconst leaf = await query(() => index.get(sessionId, captured.leafId!, scope));\n\t\t\t\tif (!leaf || leaf.sequence > captured.sourceSequence)\n\t\t\t\t\tthrow new Error(\"Context epoch snapshot is outside its captured branch\");\n\t\t\t}\n\t\t\treturn createBranchHistoryReadView(index, captured, query);\n\t\t},\n\t\tcontextManifest: (options: ContextManifestOptions = {}) =>\n\t\t\tquery(() => index.contextManifest(sessionId, scope, options)),\n\t\tcontextUpdates: (target: ContextUpdateTarget) => query(() => index.contextUpdates(sessionId, scope, target)),\n\t\treadContextUpdatePayload: (id: string, target: ContextUpdateTarget, options: HistoryPayloadReadOptions = {}) =>\n\t\t\tquery(() => index.readContextUpdatePayload(sessionId, id, scope, target, options)),\n\t\tget: (id: string) => query(() => index.get(sessionId, id, scope)),\n\t\tpage: (after = 0, limit = 64, options: { scan?: boolean } = {}) =>\n\t\t\tquery(() => index.page(sessionId, after, scope.through, limit, scope, options)),\n\t\tsearch: (text: string, limit = 16) => query(() => index.search(sessionId, text, scope.through, limit, scope)),\n\t\ttaskEvidence: (options: TaskEvidenceOptions = {}) => query(() => index.taskEvidence(sessionId, scope, options)),\n\t\treadPayload: (id: string, options: HistoryPayloadReadOptions = {}) =>\n\t\t\tquery(() => index.readPayload(sessionId, id, scope, options)),\n\t});\n}\n\nfunction positiveLimit(value: number): boolean {\n\treturn Number.isSafeInteger(value) && value > 0;\n}\n\n/** Reuse the same bounded payload/identity hydration for a captured branch adapter. */\nexport async function hydrateCapturedHistoryEntry(\n\tmetadata: IndexedSourceEvent,\n\tmaxSourceBytes: number,\n\treadPayload: SessionHistoryReadView[\"readPayload\"],\n): Promise<HydratedSessionHistoryEntry> {\n\tif (metadata.locator.length > maxSourceBytes) throw new Error(\"History entry source byte budget exceeded\");\n\tconst chunks: string[] = [];\n\tlet bytes = 0;\n\tlet cursor: CanonicalPayloadCursor | undefined;\n\tdo {\n\t\tconst fragment = await readPayload(metadata.id, {\n\t\t\tcursor,\n\t\t\tmaxBytes: Math.min(MAX_CANONICAL_PAYLOAD_PART_BYTES, maxSourceBytes - bytes),\n\t\t});\n\t\tif (!fragment) throw new Error(\"Captured history entry payload is unavailable\");\n\t\tbytes += fragment.byteLength;\n\t\tif (bytes > maxSourceBytes) throw new Error(\"History entry source byte budget exceeded\");\n\t\tchunks.push(fragment.text);\n\t\tcursor = fragment.nextCursor ?? undefined;\n\t} while (cursor);\n\tconst entry = JSON.parse(chunks.join(\"\")) as SessionEntry;\n\tif (\n\t\t!entry ||\n\t\ttypeof entry !== \"object\" ||\n\t\tentry.id !== metadata.id ||\n\t\tentry.type !== metadata.kind ||\n\t\tentry.parentId !== metadata.parentId\n\t)\n\t\tthrow new Error(\"Canonical history entry does not match indexed identity\");\n\treturn { entry, source: metadata };\n}\n\n/** Source access is selected explicitly, never by widening a coordinator's branch view. */\nexport function createSessionHistoryReadScope(\n\tindex: HistoryIndex,\n\tsource: SourceSnapshotRef,\n\tquery: HistoryReadQuery,\n\tscope: \"branch\" | \"source\",\n): SessionHistoryReadScope {\n\tconst sessionId = source.sessionId;\n\tconst branch = { leafId: source.leafId, through: source.sourceSequence };\n\tconst get = (id: string) =>\n\t\tquery(() =>\n\t\t\tscope === \"branch\" ? index.get(sessionId, id, branch) : index.getSource(sessionId, id, source.sourceSequence),\n\t\t);\n\tconst page = (after = 0, limit = 64) =>\n\t\tquery(() => index.page(sessionId, after, source.sourceSequence, limit, scope === \"branch\" ? branch : undefined));\n\tconst readPayload = (id: string, options: HistoryPayloadReadOptions = {}) =>\n\t\tquery(() =>\n\t\t\tscope === \"branch\"\n\t\t\t\t? index.readPayload(sessionId, id, branch, options)\n\t\t\t\t: index.readSourcePayload(sessionId, id, source.sourceSequence, options),\n\t\t);\n\n\tconst hydrate = (metadata: IndexedSourceEvent, maxSourceBytes: number) =>\n\t\thydrateCapturedHistoryEntry(metadata, maxSourceBytes, readPayload);\n\n\tasync function* iterateEntries(limits: SessionHistoryReadLimits): AsyncGenerator<HydratedSessionHistoryEntry> {\n\t\tconst { maxEntries, maxSourceBytes } = limits;\n\t\tif (!positiveLimit(maxEntries) || !positiveLimit(maxSourceBytes))\n\t\t\tthrow new Error(\"Invalid history materialization limits\");\n\t\tlet after = 0;\n\t\tlet entries = 0;\n\t\tlet sourceBytes = 0;\n\t\twhile (true) {\n\t\t\tconst selected = await page(after, Math.min(64, maxEntries - entries + 1));\n\t\t\tif (selected.indexedThrough < source.sourceSequence)\n\t\t\t\tthrow new Error(\"Captured history has incomplete index coverage\");\n\t\t\tfor (const metadata of selected.events) {\n\t\t\t\tif (++entries > maxEntries) throw new Error(\"History entry budget exceeded\");\n\t\t\t\tif (sourceBytes + metadata.locator.length > maxSourceBytes)\n\t\t\t\t\tthrow new Error(\"History source byte budget exceeded\");\n\t\t\t\tconst hydrated = await hydrate(metadata, maxSourceBytes - sourceBytes);\n\t\t\t\tsourceBytes += metadata.locator.length;\n\t\t\t\tyield hydrated;\n\t\t\t}\n\t\t\tif (selected.nextAfter === null) return;\n\t\t\tafter = selected.nextAfter;\n\t\t}\n\t}\n\n\treturn Object.freeze({\n\t\tsource,\n\t\tscope,\n\t\tbranchContext: createBranchHistoryReadView(index, source, query),\n\t\tbranchBootstrap: () => query(async () => ({ ...(await index.branchBootstrap(sessionId, branch)), source })),\n\t\tparentPath: (options: ParentPathOptions = {}) =>\n\t\t\tquery(async () => ({ ...(await index.parentPath(sessionId, branch, options)), source })),\n\t\tparentPathFrom: (leafId: string | null, options: ParentPathOptions = {}) =>\n\t\t\tquery(async () => {\n\t\t\t\tif (scope !== \"source\") throw new Error(\"Parent path selection requires a source-scoped history read\");\n\t\t\t\treturn {\n\t\t\t\t\t...(await index.parentPath(sessionId, { leafId, through: source.sourceSequence }, options)),\n\t\t\t\t\tsource,\n\t\t\t\t};\n\t\t\t}),\n\t\tsourceLabel: (targetId: string) => query(() => index.sourceLabel(sessionId, targetId, source.sourceSequence)),\n\t\tsourceAssistantUsage: (targetId: string) =>\n\t\t\tquery(() => index.sourceAssistantUsage(sessionId, targetId, source.sourceSequence)),\n\t\tipythonSentMessages: (toolCallId: string, options: IpythonSentMessagesOptions = {}) =>\n\t\t\tquery(() => index.ipythonSentMessages(sessionId, branch, toolCallId, options)),\n\t\tget,\n\t\tpage,\n\t\tsearch: (text: string, limit = 16) =>\n\t\t\tquery(() =>\n\t\t\t\tindex.search(sessionId, text, source.sourceSequence, limit, scope === \"branch\" ? branch : undefined),\n\t\t\t),\n\t\treadPayload,\n\t\thydrateEntry: async (id: string, maxSourceBytes: number) => {\n\t\t\tif (!positiveLimit(maxSourceBytes)) throw new Error(\"Invalid history entry source byte budget\");\n\t\t\tconst metadata = await get(id);\n\t\t\treturn metadata ? hydrate(metadata, maxSourceBytes) : undefined;\n\t\t},\n\t\titerateEntries: (limits: SessionHistoryReadLimits) => iterateEntries({ ...limits }),\n\t\tmaterialize: async (limits: SessionHistoryReadLimits) => {\n\t\t\tconst entries: HydratedSessionHistoryEntry[] = [];\n\t\t\tlet sourceBytes = 0;\n\t\t\tfor await (const entry of iterateEntries(limits)) {\n\t\t\t\tentries.push(entry);\n\t\t\t\tsourceBytes += entry.source.locator.length;\n\t\t\t}\n\t\t\treturn { source, scope, entries, sourceBytes };\n\t\t},\n\t});\n}\n\n/** A derived, coalescing feed. Canonical source ACKs do not depend on index availability. */\nexport class SessionHistoryIndex {\n\tprivate index?: HistoryIndex;\n\tprivate latest?: SessionJournalState;\n\tprivate indexedThrough = -1;\n\tprivate pumping?: Promise<void>;\n\tprivate failure?: unknown;\n\tprivate closing?: Promise<void>;\n\n\tconstructor(\n\t\tprivate readonly sessionId: string,\n\t\tprivate readonly path: string,\n\t) {}\n\n\t/** Retain at most one newer snapshot while the external worker indexes a prefix. */\n\tpublish(snapshot: SessionJournalState): void {\n\t\tif (this.closing) return;\n\t\tif (!this.latest || snapshot.nextSequence > this.latest.nextSequence) this.latest = { ...snapshot };\n\t\tthis.start();\n\t}\n\n\tprivate needsWork(): boolean {\n\t\treturn this.latest !== undefined && this.indexedThrough < this.latest.nextSequence - 1;\n\t}\n\n\tprivate start(): void {\n\t\tif (this.pumping || !this.needsWork()) return;\n\t\tthis.failure = undefined;\n\t\tconst job = this.pump();\n\t\tthis.pumping = job;\n\t\tvoid job.then(() => {\n\t\t\tthis.pumping = undefined;\n\t\t\tif (!this.failure && this.needsWork()) this.start();\n\t\t});\n\t}\n\n\tprivate async pump(): Promise<void> {\n\t\twhile (this.latest && this.needsWork()) {\n\t\t\tconst snapshot = this.latest;\n\t\t\ttry {\n\t\t\t\tthis.index ??= await HistoryIndex.open(this.path);\n\t\t\t\tconst frontier = await this.index.syncSource(this.sessionId, snapshot);\n\t\t\t\tthis.indexedThrough = frontier.indexedThrough;\n\t\t\t} catch (error) {\n\t\t\t\tthis.failure = error;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Callers must apply their captured sequence/branch scope to the following query. */\n\tasync synchronize(snapshot: SessionJournalState): Promise<HistoryIndex> {\n\t\tif (this.closing) throw new Error(\"Session history index is closing\");\n\t\tthis.publish(snapshot);\n\t\twhile (this.indexedThrough < snapshot.nextSequence - 1) {\n\t\t\tconst job = this.pumping;\n\t\t\tif (!job) throw this.failure ?? new Error(\"Session history index has incomplete coverage\");\n\t\t\tawait job;\n\t\t}\n\t\tif (!this.index) throw new Error(\"Session history index is unavailable\");\n\t\treturn this.index;\n\t}\n\n\t/** Internal current-owner bootstrap; never substitutes current facts for an older captured prefix. */\n\tasync currentSourceBootstrap(snapshot: SessionJournalState): Promise<SourceBootstrapState> {\n\t\tconst captured = { ...snapshot };\n\t\tconst index = await this.synchronize(captured);\n\t\treturn index.currentSourceBootstrap(this.sessionId, captured);\n\t}\n\n\t/** Finish accepted indexing, then wait for the external worker to close. */\n\tclose(): Promise<void> {\n\t\tthis.closing ??= (async () => {\n\t\t\twhile (this.pumping) await this.pumping;\n\t\t\tawait this.index?.close();\n\t\t})();\n\t\treturn this.closing;\n\t}\n}\n"]}
|
|
@@ -157,6 +157,10 @@ export interface Settings {
|
|
|
157
157
|
mode?: "on" | "off";
|
|
158
158
|
};
|
|
159
159
|
autoRefine?: AutoRefineSettings;
|
|
160
|
+
/** Automatic scoped error-fix notes; explicit memory CRUD remains independent. */
|
|
161
|
+
learning?: {
|
|
162
|
+
enabled?: boolean;
|
|
163
|
+
};
|
|
160
164
|
branchSummary?: BranchSummarySettings;
|
|
161
165
|
retry?: RetrySettings;
|
|
162
166
|
hideThinkingBlock?: boolean;
|
|
@@ -302,6 +306,7 @@ export declare class SettingsManager {
|
|
|
302
306
|
};
|
|
303
307
|
/** Detached explicit configuration; the request path resolves and validates its model/effort. */
|
|
304
308
|
getAutoRefineModel(): AutoRefineModelSettings | undefined;
|
|
309
|
+
getLearningEnabled(): boolean;
|
|
305
310
|
getAutoRefineSettings(): {
|
|
306
311
|
enabled: boolean;
|
|
307
312
|
turnInterval: number;
|