@earendil-works/pi-agent-core 0.87.1 → 0.99.1
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/README.md +4 -0
- package/dist/agent-loop.d.ts +27 -2
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +44 -15
- package/dist/agent-loop.js.map +1 -1
- package/dist/agent.d.ts +9 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +3 -0
- package/dist/agent.js.map +1 -1
- package/dist/harness/agent-harness.d.ts.map +1 -1
- package/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/harness/compaction/branch-summarization.js.map +1 -1
- package/dist/harness/compaction/compaction.d.ts.map +1 -1
- package/dist/harness/compaction/compaction.js.map +1 -1
- package/dist/harness/compaction/utils.d.ts.map +1 -1
- package/dist/harness/compaction/utils.js.map +1 -1
- package/dist/harness/config.d.ts.map +1 -1
- package/dist/harness/config.js.map +1 -1
- package/dist/harness/context.d.ts.map +1 -1
- package/dist/harness/context.js.map +1 -1
- package/dist/harness/env/nodejs.d.ts.map +1 -1
- package/dist/harness/env/nodejs.js.map +1 -1
- package/dist/harness/events.d.ts.map +1 -1
- package/dist/harness/events.js.map +1 -1
- package/dist/harness/execution/assistant.d.ts.map +1 -1
- package/dist/harness/execution/assistant.js.map +1 -1
- package/dist/harness/execution/effect-gate.d.ts.map +1 -1
- package/dist/harness/execution/effect-gate.js.map +1 -1
- package/dist/harness/execution/tools.d.ts.map +1 -1
- package/dist/harness/execution/tools.js.map +1 -1
- package/dist/harness/hooks.d.ts.map +1 -1
- package/dist/harness/hooks.js.map +1 -1
- package/dist/harness/messages.d.ts.map +1 -1
- package/dist/harness/messages.js.map +1 -1
- package/dist/harness/pico3/bash.d.ts.map +1 -1
- package/dist/harness/pico3/bash.js.map +1 -1
- package/dist/harness/pico3/bounded.d.ts.map +1 -1
- package/dist/harness/pico3/bounded.js.map +1 -1
- package/dist/harness/pico3/chord.d.ts.map +1 -1
- package/dist/harness/pico3/chord.js.map +1 -1
- package/dist/harness/pico3/context.d.ts.map +1 -1
- package/dist/harness/pico3/context.js.map +1 -1
- package/dist/harness/pico3/harness.d.ts +4 -3
- package/dist/harness/pico3/harness.d.ts.map +1 -1
- package/dist/harness/pico3/harness.js.map +1 -1
- package/dist/harness/pico3/hooks.d.ts +2 -2
- package/dist/harness/pico3/hooks.d.ts.map +1 -1
- package/dist/harness/pico3/hooks.js.map +1 -1
- package/dist/harness/pico3/index.d.ts.map +1 -1
- package/dist/harness/pico3/jsonl.d.ts.map +1 -1
- package/dist/harness/pico3/jsonl.js.map +1 -1
- package/dist/harness/pico3/kinds/collapse.d.ts.map +1 -1
- package/dist/harness/pico3/kinds/collapse.js.map +1 -1
- package/dist/harness/pico3/kinds/entries.d.ts.map +1 -1
- package/dist/harness/pico3/kinds/frames.d.ts.map +1 -1
- package/dist/harness/pico3/kinds/frames.js.map +1 -1
- package/dist/harness/pico3/kinds/generation.d.ts.map +1 -1
- package/dist/harness/pico3/kinds/generation.js.map +1 -1
- package/dist/harness/pico3/kinds/job.d.ts.map +1 -1
- package/dist/harness/pico3/kinds/job.js.map +1 -1
- package/dist/harness/pico3/kinds/plugin.d.ts.map +1 -1
- package/dist/harness/pico3/kinds/plugin.js.map +1 -1
- package/dist/harness/pico3/kinds/post-tools.d.ts.map +1 -1
- package/dist/harness/pico3/kinds/post-tools.js.map +1 -1
- package/dist/harness/pico3/kinds/task-api.d.ts.map +1 -1
- package/dist/harness/pico3/kinds/task-api.js.map +1 -1
- package/dist/harness/pico3/kinds/tool.d.ts.map +1 -1
- package/dist/harness/pico3/kinds/tool.js.map +1 -1
- package/dist/harness/pico3/legacy-tracker.d.ts +11 -0
- package/dist/harness/pico3/legacy-tracker.d.ts.map +1 -0
- package/dist/harness/pico3/legacy-tracker.js +41 -0
- package/dist/harness/pico3/legacy-tracker.js.map +1 -0
- package/dist/harness/pico3/membrane.d.ts.map +1 -1
- package/dist/harness/pico3/membrane.js.map +1 -1
- package/dist/harness/pico3/memory.d.ts +1 -1
- package/dist/harness/pico3/memory.d.ts.map +1 -1
- package/dist/harness/pico3/memory.js.map +1 -1
- package/dist/harness/pico3/scheduler.d.ts +3 -0
- package/dist/harness/pico3/scheduler.d.ts.map +1 -1
- package/dist/harness/pico3/scheduler.js.map +1 -1
- package/dist/harness/pico3/session.d.ts +3 -2
- package/dist/harness/pico3/session.d.ts.map +1 -1
- package/dist/harness/pico3/session.js +5 -4
- package/dist/harness/pico3/session.js.map +1 -1
- package/dist/harness/pico3/system.d.ts +1 -1
- package/dist/harness/pico3/system.d.ts.map +1 -1
- package/dist/harness/pico3/system.js.map +1 -1
- package/dist/harness/pico3/types.d.ts +1 -1
- package/dist/harness/pico3/types.d.ts.map +1 -1
- package/dist/harness/pico3/types.js.map +1 -1
- package/dist/harness/pico3/view.d.ts.map +1 -1
- package/dist/harness/pico3/view.js +6 -12
- package/dist/harness/pico3/view.js.map +1 -1
- package/dist/harness/prompt-templates.d.ts.map +1 -1
- package/dist/harness/prompt-templates.js.map +1 -1
- package/dist/harness/result.d.ts.map +1 -1
- package/dist/harness/result.js.map +1 -1
- package/dist/harness/runtime/drive/boundary.d.ts.map +1 -1
- package/dist/harness/runtime/drive/boundary.js.map +1 -1
- package/dist/harness/runtime/drive/checkpoint.d.ts.map +1 -1
- package/dist/harness/runtime/drive/checkpoint.js.map +1 -1
- package/dist/harness/runtime/drive/deferred.d.ts.map +1 -1
- package/dist/harness/runtime/drive/deferred.js.map +1 -1
- package/dist/harness/runtime/drive/generation.d.ts.map +1 -1
- package/dist/harness/runtime/drive/generation.js.map +1 -1
- package/dist/harness/runtime/drive/reconcile.d.ts.map +1 -1
- package/dist/harness/runtime/drive/reconcile.js.map +1 -1
- package/dist/harness/runtime/drive/recovery.d.ts.map +1 -1
- package/dist/harness/runtime/drive/recovery.js.map +1 -1
- package/dist/harness/runtime/drive/response.d.ts.map +1 -1
- package/dist/harness/runtime/drive/response.js.map +1 -1
- package/dist/harness/runtime/drive/retry.d.ts.map +1 -1
- package/dist/harness/runtime/drive/retry.js.map +1 -1
- package/dist/harness/runtime/drive/structural.d.ts.map +1 -1
- package/dist/harness/runtime/drive/structural.js.map +1 -1
- package/dist/harness/runtime/drive/terminal.d.ts.map +1 -1
- package/dist/harness/runtime/drive/terminal.js.map +1 -1
- package/dist/harness/runtime/drive/tool-placement.d.ts.map +1 -1
- package/dist/harness/runtime/drive/tool-placement.js.map +1 -1
- package/dist/harness/runtime/drive/tools.d.ts.map +1 -1
- package/dist/harness/runtime/drive/tools.js.map +1 -1
- package/dist/harness/runtime/drive.d.ts.map +1 -1
- package/dist/harness/runtime/drive.js.map +1 -1
- package/dist/harness/runtime/harness.d.ts.map +1 -1
- package/dist/harness/runtime/harness.js.map +1 -1
- package/dist/harness/runtime/index.d.ts.map +1 -1
- package/dist/harness/runtime/lane.d.ts +17 -0
- package/dist/harness/runtime/lane.d.ts.map +1 -1
- package/dist/harness/runtime/lane.js.map +1 -1
- package/dist/harness/runtime/progress.d.ts.map +1 -1
- package/dist/harness/runtime/progress.js.map +1 -1
- package/dist/harness/runtime/reducer.d.ts.map +1 -1
- package/dist/harness/runtime/reducer.js.map +1 -1
- package/dist/harness/runtime/restore.d.ts.map +1 -1
- package/dist/harness/runtime/restore.js.map +1 -1
- package/dist/harness/runtime/transcript.d.ts.map +1 -1
- package/dist/harness/runtime/transcript.js.map +1 -1
- package/dist/harness/runtime/types.d.ts.map +1 -1
- package/dist/harness/runtime/types.js.map +1 -1
- package/dist/harness/session/commit.d.ts.map +1 -1
- package/dist/harness/session/commit.js.map +1 -1
- package/dist/harness/session/context.d.ts.map +1 -1
- package/dist/harness/session/context.js.map +1 -1
- package/dist/harness/session/fork-policy.d.ts.map +1 -1
- package/dist/harness/session/fork-policy.js.map +1 -1
- package/dist/harness/session/fork.d.ts.map +1 -1
- package/dist/harness/session/fork.js.map +1 -1
- package/dist/harness/session/in-memory-storage-state.d.ts.map +1 -1
- package/dist/harness/session/in-memory-storage-state.js.map +1 -1
- package/dist/harness/session/index.d.ts.map +1 -1
- package/dist/harness/session/jsonl/codec.d.ts.map +1 -1
- package/dist/harness/session/jsonl/codec.js.map +1 -1
- package/dist/harness/session/jsonl/fork.d.ts.map +1 -1
- package/dist/harness/session/jsonl/fork.js.map +1 -1
- package/dist/harness/session/jsonl/index.d.ts.map +1 -1
- package/dist/harness/session/jsonl/io.d.ts.map +1 -1
- package/dist/harness/session/jsonl/io.js.map +1 -1
- package/dist/harness/session/jsonl/legacy-v3.d.ts +1 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts.map +1 -1
- package/dist/harness/session/jsonl/legacy-v3.js.map +1 -1
- package/dist/harness/session/jsonl/repo.d.ts.map +1 -1
- package/dist/harness/session/jsonl/repo.js.map +1 -1
- package/dist/harness/session/jsonl/storage.d.ts +1 -0
- package/dist/harness/session/jsonl/storage.d.ts.map +1 -1
- package/dist/harness/session/jsonl/storage.js.map +1 -1
- package/dist/harness/session/jsonl/types.d.ts.map +1 -1
- package/dist/harness/session/memory.d.ts.map +1 -1
- package/dist/harness/session/memory.js.map +1 -1
- package/dist/harness/session/mutation-line.d.ts.map +1 -1
- package/dist/harness/session/mutation-line.js.map +1 -1
- package/dist/harness/session/session.d.ts.map +1 -1
- package/dist/harness/session/session.js.map +1 -1
- package/dist/harness/session/testing/benchmark/datasets.d.ts.map +1 -1
- package/dist/harness/session/testing/benchmark/datasets.js.map +1 -1
- package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +1 -1
- package/dist/harness/session/testing/benchmark/session-repo.js.map +1 -1
- package/dist/harness/session/testing/benchmark/storage.d.ts.map +1 -1
- package/dist/harness/session/testing/benchmark/storage.js.map +1 -1
- package/dist/harness/session/testing/conformance/session-repo.d.ts.map +1 -1
- package/dist/harness/session/testing/conformance/session-repo.js.map +1 -1
- package/dist/harness/session/testing/conformance/storage.d.ts.map +1 -1
- package/dist/harness/session/testing/conformance/storage.js.map +1 -1
- package/dist/harness/session/testing/gating-storage.d.ts.map +1 -1
- package/dist/harness/session/testing/gating-storage.js.map +1 -1
- package/dist/harness/session/testing/index.d.ts.map +1 -1
- package/dist/harness/session/testing/instrumented-storage.d.ts.map +1 -1
- package/dist/harness/session/testing/instrumented-storage.js.map +1 -1
- package/dist/harness/session/testing/storage-decorator.d.ts.map +1 -1
- package/dist/harness/session/testing/storage-decorator.js.map +1 -1
- package/dist/harness/session/testing/types.d.ts.map +1 -1
- package/dist/harness/session/types.d.ts.map +1 -1
- package/dist/harness/session/types.js.map +1 -1
- package/dist/harness/session/values.d.ts +2 -2
- package/dist/harness/session/values.d.ts.map +1 -1
- package/dist/harness/session/values.js.map +1 -1
- package/dist/harness/skills.d.ts.map +1 -1
- package/dist/harness/skills.js.map +1 -1
- package/dist/harness/system-prompt.d.ts.map +1 -1
- package/dist/harness/system-prompt.js.map +1 -1
- package/dist/harness/telemetry.d.ts.map +1 -1
- package/dist/harness/telemetry.js.map +1 -1
- package/dist/harness/tools/bash.d.ts.map +1 -1
- package/dist/harness/tools/bash.js.map +1 -1
- package/dist/harness/tools/edit-diff.d.ts.map +1 -1
- package/dist/harness/tools/edit-diff.js.map +1 -1
- package/dist/harness/tools/edit.d.ts.map +1 -1
- package/dist/harness/tools/edit.js.map +1 -1
- package/dist/harness/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/harness/tools/file-mutation-queue.js.map +1 -1
- package/dist/harness/tools/image.d.ts.map +1 -1
- package/dist/harness/tools/image.js.map +1 -1
- package/dist/harness/tools/index.d.ts.map +1 -1
- package/dist/harness/tools/path-utils.d.ts.map +1 -1
- package/dist/harness/tools/path-utils.js.map +1 -1
- package/dist/harness/tools/read.d.ts.map +1 -1
- package/dist/harness/tools/read.js.map +1 -1
- package/dist/harness/tools/tool-context.d.ts.map +1 -1
- package/dist/harness/tools/write.d.ts.map +1 -1
- package/dist/harness/tools/write.js.map +1 -1
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/utils/adaptive-publisher.d.ts.map +1 -1
- package/dist/harness/utils/adaptive-publisher.js.map +1 -1
- package/dist/harness/utils/output-capture.d.ts.map +1 -1
- package/dist/harness/utils/output-capture.js.map +1 -1
- package/dist/harness/utils/shell-output.d.ts.map +1 -1
- package/dist/harness/utils/shell-output.js.map +1 -1
- package/dist/harness/utils/truncate.d.ts.map +1 -1
- package/dist/harness/utils/truncate.js.map +1 -1
- package/dist/harness/utils/usage.d.ts.map +1 -1
- package/dist/harness/utils/usage.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js.map +1 -1
- package/dist/search/index.d.ts.map +1 -1
- package/dist/stream-fn.d.ts.map +1 -1
- package/dist/stream-fn.js.map +1 -1
- package/dist/types.d.ts +30 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +9 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fork.js","sourceRoot":"","sources":["../../../src/harness/session/fork.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,4BAA4B,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE7G,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAgC,KAAK,EAAE,MAAM,aAAa,CAAC;AAepG,SAAS,uBAAuB,CAAI,MAAuC,EAAE,OAAiB
|
|
1
|
+
{"version":3,"file":"fork.js","sourceRoot":"","sources":["../../../src/harness/session/fork.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,4BAA4B,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE7G,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAgC,KAAK,EAAE,MAAM,aAAa,CAAC;AAepG,SAAS,uBAAuB,CAAI,MAAuC,EAAE,OAAiB;IAC7F,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,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C,GAAG,CAAC,CAAC,CAAC;QACxF,MAAM,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/E,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,EAAE,CAAC;YAC7D,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QACvG,CAAC;QACD,IAAI,OAAO,CAAC,KAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC,MAAM,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YACrG,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,gCAAgC,CAAC,CAAC;QAClG,CAAC;QACD,IACC,CAAC,MAAM,CAAC,eAAe,KAAK,KAAK,IAAI,OAAO,CAAC,KAAK,KAAK,MAAM,CAAC;YAC9D,GAAG,CAAC,KAAK,KAAK,IAAI;YAClB,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,EAC5B,CAAC;YACF,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAChG,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { type ForkCurrentStatePlan, projectForkCurrentStateWrite, selectBranchFork } from \"./fork-policy.ts\";\nimport type { Entry, ForkOptions } from \"./types.ts\";\nimport { branchTip, laneConfig, laneState, type StoredValue, type Value, value } from \"./values.ts\";\n\nexport interface ForkSourceSnapshot {\n\tentries: Entry[];\n\tscalarValues: StoredValue<unknown>[];\n\t/** False when a backend supplied only the requested branch rather than the full tree. */\n\tentriesComplete?: boolean;\n}\n\nexport interface ForkDestinationSnapshot {\n\tentries: Map<string, Entry>;\n\tscalarValues: StoredValue<unknown>[];\n\tnextSeq: number;\n}\n\nfunction storedValuesInNamespace<T>(values: readonly StoredValue<unknown>[], address: Value<T>): StoredValue<T>[] {\n\treturn values.filter((stored) => stored.address.namespace === address.namespace) as StoredValue<T>[];\n}\n\nfunction findStoredValue<T>(values: readonly StoredValue<unknown>[], address: Value<T>): StoredValue<T> | undefined {\n\treturn values.find(\n\t\t(stored) => stored.address.namespace === address.namespace && stored.address.key === address.key,\n\t) as StoredValue<T> | undefined;\n}\n\n/** Build the complete logical state for a forked destination session. */\nexport function createForkSnapshot(source: ForkSourceSnapshot, options: ForkOptions): ForkDestinationSnapshot {\n\tconst sourceEntries = new Map(source.entries.map((entry) => [entry.id, entry]));\n\tconst sourceTips = storedValuesInNamespace(source.scalarValues, branchTip(\"\"));\n\tvalidateForkSourceSnapshot(source, sourceEntries, sourceTips, options);\n\n\tconst { entryIds, plan } = selectForkContents(sourceEntries, sourceTips, options);\n\tconst entries = new Map<string, Entry>();\n\tfor (const id of entryIds) entries.set(id, sourceEntries.get(id)!);\n\n\tconst scalarValues: StoredValue<unknown>[] = [];\n\tlet nextSeq = Math.max(0, ...[...entries.values()].map((entry) => entry.seq)) + 1;\n\tfor (const stored of source.scalarValues) {\n\t\tconst projected = projectForkCurrentStateWrite(\n\t\t\t{\n\t\t\t\tkind: \"value\",\n\t\t\t\top: \"set\",\n\t\t\t\tseq: stored.seq,\n\t\t\t\tnamespace: stored.address.namespace,\n\t\t\t\tkey: stored.address.key,\n\t\t\t\tvalue: stored.value,\n\t\t\t},\n\t\t\tplan,\n\t\t\t(entryId) => entryIds.has(entryId),\n\t\t);\n\t\tif (projected !== undefined) {\n\t\t\tscalarValues.push({\n\t\t\t\taddress: value<unknown>(projected.namespace, projected.key),\n\t\t\t\tvalue: projected.value,\n\t\t\t\tseq: nextSeq++,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn { entries, scalarValues, nextSeq };\n}\n\nfunction selectForkContents(\n\tsourceEntries: Map<string, Entry>,\n\tsourceTips: StoredValue<string | null>[],\n\toptions: ForkOptions,\n): { entryIds: Set<string>; plan: ForkCurrentStatePlan } {\n\tconst entryIds = new Set<string>();\n\tif (options.scope === \"tree\") {\n\t\tfor (const id of sourceEntries.keys()) entryIds.add(id);\n\t\treturn { entryIds, plan: { scope: \"tree\" } };\n\t}\n\n\tconst sourceTip = sourceTips.find((stored) => stored.address.key === options.branch);\n\tconst plan = selectBranchFork(options, {\n\t\ttip: sourceTip?.value,\n\t\tgetParent: (entryId) => sourceEntries.get(entryId)?.parentId,\n\t\tselectEntry: (entryId) => entryIds.add(entryId),\n\t});\n\treturn { entryIds, plan };\n}\n\nfunction validateForkSourceSnapshot(\n\tsource: ForkSourceSnapshot,\n\tsourceEntries: Map<string, Entry>,\n\tsourceTips: StoredValue<string | null>[],\n\toptions: ForkOptions,\n): void {\n\tconst sourceTipKeys = new Set(sourceTips.map((stored) => stored.address.key));\n\n\tfor (const stored of source.scalarValues) {\n\t\tif (\n\t\t\t(stored.address.namespace === laneConfig(\"\").namespace ||\n\t\t\t\tstored.address.namespace === laneState(\"\").namespace) &&\n\t\t\t!sourceTipKeys.has(stored.address.key)\n\t\t) {\n\t\t\tthrow new Error(`Source session branch ${JSON.stringify(stored.address.key)} is missing branch.tip`);\n\t\t}\n\t}\n\tfor (const tip of sourceTips) {\n\t\tconst configuration = findStoredValue(source.scalarValues, laneConfig(tip.address.key));\n\t\tconst state = findStoredValue(source.scalarValues, laneState(tip.address.key));\n\t\tif ((configuration === undefined) !== (state === undefined)) {\n\t\t\tthrow new Error(`Source session branch ${JSON.stringify(tip.address.key)} has incomplete lane state`);\n\t\t}\n\t\tif (options.scope === \"branch\" && tip.address.key === options.branch && configuration === undefined) {\n\t\t\tthrow new Error(`Source branch ${JSON.stringify(options.branch)} is not a configured AgentLane`);\n\t\t}\n\t\tif (\n\t\t\t(source.entriesComplete !== false || options.scope === \"tree\") &&\n\t\t\ttip.value !== null &&\n\t\t\t!sourceEntries.has(tip.value)\n\t\t) {\n\t\t\tthrow new Error(`Source session branch ${JSON.stringify(tip.address.key)} has an unknown tip`);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-storage-state.d.ts","sourceRoot":"","sources":["../../../src/harness/session/in-memory-storage-state.ts"],"names":[],"mappings":"AACA,OAAO,EAGN,KAAK,cAAc,EACnB,KAAK,cAAc,EAGnB,MAAM,aAAa,CAAC;AAGrB,YAAY,EACX,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,cAAc,EACd,cAAc,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EACX,KAAK,EACL,SAAS,EACT,cAAc,EACd,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,QAAQ,EACR,SAAS,EACT,KAAK,EACL,MAAM,YAAY,CAAC;AACpB,OAAO,EAEN,KAAK,WAAW,EAChB,KAAK,eAAe,EAKpB,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,SAAS,EAEd,MAAM,aAAa,CAAC;AA0BrB;;;;;GAKG;AACH,qBAAa,oBAAoB;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;IACvC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAoC;IACjE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkC;IAC7D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwB;IAC9C,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,OAAO,CAAS;IAExB,cAQC;IAED,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,CAIhE;IAED,iBAAiB,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,GAAG,IAAI,CAKzD;IAED,6FAA6F;IAC7F,cAAc,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,GAAG,YAAY,CA4B9D;IAED,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,oBAAoB,CAoDrD;IAED,OAAO,CAAC,cAAc;IAkBtB,OAAO,CAAC,yBAAyB;IAuBjC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAKpC;IAED,UAAU,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAOrD;IAED,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAEzD;IAED,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,CAIhD;IAED,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,CAS9E;IAED,UAAU,CAAC,KAAK,EAAE,iBAAiB,GAAG,KAAK,EAAE,CA4B5C;IAED,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,GAAG,cAAc,EAAE,CAS9D;IAED,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,EAAE,CAkBrC;IAED,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,QAAQ,EAAE,CAMtC;IAED,QAAQ,IAAI,YAAY,CAEvB;IAED,UAAU,IAAI,MAAM,CAEnB;CACD","sourcesContent":["import { addUsage, emptyUsage } from \"../utils/usage.ts\";\nimport {\n\ttype CommittedListAppendWrite,\n\ttype CommittedValueSetWrite,\n\ttype CommittedWrite,\n\ttype PreparedCommit,\n\tprepareStorageCommit,\n\tvalidateCommittedWrites,\n} from \"./commit.ts\";\nimport { projectForkCurrentStateWrite, selectBranchFork } from \"./fork-policy.ts\";\n\nexport type {\n\tCommittedEntryWrite,\n\tCommittedListAppendWrite,\n\tCommittedListDeleteWrite,\n\tCommittedUsageWrite,\n\tCommittedValueDeleteWrite,\n\tCommittedValueSetWrite,\n\tCommittedWrite,\n\tPreparedCommit,\n} from \"./commit.ts\";\n\nimport type {\n\tEntry,\n\tEntryScan,\n\tEntryStructure,\n\tForkOptions,\n\tSessionStats,\n\tStorageBranchScan,\n\tUsageRow,\n\tUsageScan,\n\tWrite,\n} from \"./types.ts\";\nimport {\n\tbranchTip,\n\ttype ListElement,\n\ttype ListReadOptions,\n\tlaneConfig,\n\tlaneState,\n\tlist,\n\tresolveListReadOptions,\n\ttype StoredValue,\n\ttype Value,\n\ttype ValueList,\n\tvalue,\n} from \"./values.ts\";\n\ninterface StoredListSnapshot {\n\taddress: ValueList<unknown>;\n\telements: ListElement<unknown>[];\n}\n\ntype MemoryForkPlan =\n\t| { scope: \"tree\" }\n\t| { scope: \"branch\"; branch: string; destinationTip: string | null; entryIds: Set<string> };\n\nfunction physicalKey(namespace: string, key: string): string {\n\treturn `${namespace}\\u0000${key}`;\n}\n\nfunction compareKeys(left: string, right: string): number {\n\tconst leftCodePoints = Array.from(left, (character) => character.codePointAt(0)!);\n\tconst rightCodePoints = Array.from(right, (character) => character.codePointAt(0)!);\n\tconst length = Math.min(leftCodePoints.length, rightCodePoints.length);\n\tfor (let index = 0; index < length; index++) {\n\t\tconst difference = leftCodePoints[index]! - rightCodePoints[index]!;\n\t\tif (difference !== 0) return difference;\n\t}\n\treturn leftCodePoints.length - rightCodePoints.length;\n}\n\n/**\n * Complete materialized session state for MemoryStorage and JsonlStorage.\n *\n * This is intentionally unsuitable for database backends and long-running sessions that may not fit in memory.\n * Those backends should query indexed durable state and update durable aggregates within each commit transaction.\n */\nexport class InMemoryStorageState {\n\tprivate readonly entries: Map<string, Entry>;\n\tprivate readonly entriesBySeq: Entry[];\n\tprivate readonly scalarValues: Map<string, StoredValue<unknown>>;\n\tprivate readonly listValues: Map<string, StoredListSnapshot>;\n\tprivate readonly usage: Map<string, UsageRow>;\n\tprivate stats: SessionStats;\n\tprivate nextSeq: number;\n\n\tconstructor() {\n\t\tthis.entries = new Map();\n\t\tthis.entriesBySeq = [];\n\t\tthis.scalarValues = new Map();\n\t\tthis.listValues = new Map();\n\t\tthis.usage = new Map();\n\t\tthis.stats = { messageCount: 0, usage: emptyUsage() };\n\t\tthis.nextSeq = 1;\n\t}\n\n\tprepareCommit(writes: Write[], timestamp: number): PreparedCommit {\n\t\tconst prepared = prepareStorageCommit(writes, this.nextSeq, timestamp);\n\t\tthis.validateCommitted(prepared.writes);\n\t\treturn prepared;\n\t}\n\n\tvalidateCommitted(writes: readonly CommittedWrite[]): void {\n\t\tvalidateCommittedWrites(writes, this.nextSeq, {\n\t\t\thasEntryOrUsageId: (id) => this.entries.has(id) || this.usage.has(id),\n\t\t\thasEntryId: (id) => this.entries.has(id),\n\t\t});\n\t}\n\n\t/** Apply writes already accepted by validateCommitted() and return the post-apply totals. */\n\tapplyValidated(writes: readonly CommittedWrite[]): SessionStats {\n\t\tfor (const write of writes) {\n\t\t\tswitch (write.kind) {\n\t\t\t\tcase \"entry\": {\n\t\t\t\t\tconst { kind: _kind, ...entry } = write;\n\t\t\t\t\tthis.entries.set(entry.id, entry);\n\t\t\t\t\tthis.entriesBySeq.push(entry);\n\t\t\t\t\tif (entry.type === \"message\") this.stats = { ...this.stats, messageCount: this.stats.messageCount + 1 };\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"usage\": {\n\t\t\t\t\tconst { kind: _kind, ...row } = write;\n\t\t\t\t\tthis.usage.set(row.id, row);\n\t\t\t\t\tthis.stats = { ...this.stats, usage: addUsage(this.stats.usage, row.usage) };\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"value\":\n\t\t\t\t\tif (write.op === \"delete\") this.scalarValues.delete(physicalKey(write.namespace, write.key));\n\t\t\t\t\telse this.applyValueSetOrListAppend(write);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"list\":\n\t\t\t\t\tif (write.op === \"delete\") this.listValues.delete(physicalKey(write.namespace, write.key));\n\t\t\t\t\telse this.applyValueSetOrListAppend(write);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.nextSeq = write.seq + 1;\n\t\t}\n\t\treturn this.stats;\n\t}\n\n\tcreateFork(options: ForkOptions): InMemoryStorageState {\n\t\tconst plan = this.selectForkPlan(options);\n\n\t\tconst isEntryCopied = (entryId: string): boolean => {\n\t\t\tif (plan.scope === \"tree\") return true;\n\t\t\treturn plan.entryIds.has(entryId);\n\t\t};\n\t\tconst destination = new InMemoryStorageState();\n\t\tlet messageCount = 0;\n\t\tfor (const entry of this.entriesBySeq) {\n\t\t\tif (!isEntryCopied(entry.id)) continue;\n\t\t\tdestination.entries.set(entry.id, entry);\n\t\t\tdestination.entriesBySeq.push(entry);\n\t\t\tif (entry.type === \"message\") messageCount++;\n\t\t}\n\t\tdestination.stats = { ...destination.stats, messageCount };\n\n\t\tfor (const stored of this.scalarValues.values()) {\n\t\t\tconst projected = projectForkCurrentStateWrite(\n\t\t\t\t{\n\t\t\t\t\tkind: \"value\",\n\t\t\t\t\top: \"set\",\n\t\t\t\t\tseq: stored.seq,\n\t\t\t\t\tnamespace: stored.address.namespace,\n\t\t\t\t\tkey: stored.address.key,\n\t\t\t\t\tvalue: stored.value,\n\t\t\t\t},\n\t\t\t\tplan,\n\t\t\t\tisEntryCopied,\n\t\t\t);\n\t\t\tif (projected !== undefined) destination.applyValueSetOrListAppend(projected);\n\t\t}\n\n\t\tfor (const stored of this.listValues.values()) {\n\t\t\tfor (const element of stored.elements) {\n\t\t\t\tconst projected = projectForkCurrentStateWrite(\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: \"list\",\n\t\t\t\t\t\top: \"append\",\n\t\t\t\t\t\tseq: element.seq,\n\t\t\t\t\t\tnamespace: stored.address.namespace,\n\t\t\t\t\t\tkey: stored.address.key,\n\t\t\t\t\t\tvalue: element.value,\n\t\t\t\t\t},\n\t\t\t\t\tplan,\n\t\t\t\t\tisEntryCopied,\n\t\t\t\t);\n\t\t\t\tif (projected !== undefined) destination.applyValueSetOrListAppend(projected);\n\t\t\t}\n\t\t}\n\t\tdestination.nextSeq = this.nextSeq;\n\t\treturn destination;\n\t}\n\n\tprivate selectForkPlan(options: ForkOptions): MemoryForkPlan {\n\t\tif (options.scope === \"tree\") return { scope: \"tree\" };\n\n\t\tconst entryIds = new Set<string>();\n\t\tconst plan = selectBranchFork(options, {\n\t\t\ttip: this.getValue(branchTip(options.branch))?.value,\n\t\t\tgetParent: (entryId) => this.entries.get(entryId)?.parentId,\n\t\t\tselectEntry: (entryId) => entryIds.add(entryId),\n\t\t});\n\t\tif (\n\t\t\tthis.getValue(laneConfig(options.branch)) === undefined ||\n\t\t\tthis.getValue(laneState(options.branch)) === undefined\n\t\t) {\n\t\t\tthrow new Error(`Source branch ${JSON.stringify(options.branch)} is not a configured AgentLane`);\n\t\t}\n\t\treturn { ...plan, entryIds };\n\t}\n\n\tprivate applyValueSetOrListAppend(write: CommittedValueSetWrite | CommittedListAppendWrite): void {\n\t\tconst key = physicalKey(write.namespace, write.key);\n\t\tif (write.kind === \"value\") {\n\t\t\tthis.scalarValues.set(key, {\n\t\t\t\taddress: value<unknown>(write.namespace, write.key),\n\t\t\t\tvalue: write.value,\n\t\t\t\tseq: write.seq,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst element = { seq: write.seq, value: write.value };\n\t\tconst stored = this.listValues.get(key);\n\t\tif (stored === undefined) {\n\t\t\tthis.listValues.set(key, {\n\t\t\t\taddress: list<unknown>(write.namespace, write.key),\n\t\t\t\telements: [element],\n\t\t\t});\n\t\t} else {\n\t\t\tstored.elements.push(element);\n\t\t}\n\t}\n\n\tadvanceNextSeq(nextSeq: number): void {\n\t\tif (!Number.isSafeInteger(nextSeq) || nextSeq < 1) {\n\t\t\tthrow new Error(`Invalid storage sequence high-water mark: ${nextSeq}`);\n\t\t}\n\t\tthis.nextSeq = Math.max(this.nextSeq, nextSeq);\n\t}\n\n\tgetEntries(ids: readonly string[]): Map<string, Entry> {\n\t\tconst found = new Map<string, Entry>();\n\t\tfor (const id of ids) {\n\t\t\tconst entry = this.entries.get(id);\n\t\t\tif (entry !== undefined) found.set(id, entry);\n\t\t}\n\t\treturn found;\n\t}\n\n\tgetValue<T>(address: Value<T>): StoredValue<T> | undefined {\n\t\treturn this.scalarValues.get(physicalKey(address.namespace, address.key)) as StoredValue<T> | undefined;\n\t}\n\n\tscanValues<T>(prefix: Value<T>): StoredValue<T>[] {\n\t\treturn [...this.scalarValues.values()]\n\t\t\t.filter((stored) => stored.address.namespace === prefix.namespace && stored.address.key.startsWith(prefix.key))\n\t\t\t.sort((left, right) => compareKeys(left.address.key, right.address.key)) as StoredValue<T>[];\n\t}\n\n\treadList<T>(address: ValueList<T>, options?: ListReadOptions): ListElement<T>[] {\n\t\tconst resolved = resolveListReadOptions(options);\n\t\tconst elements = this.listValues.get(physicalKey(address.namespace, address.key))?.elements ?? [];\n\t\tconst filtered = elements.filter((element) => {\n\t\t\tif (resolved.cursor === undefined) return true;\n\t\t\treturn resolved.order === \"asc\" ? element.seq > resolved.cursor.seq : element.seq < resolved.cursor.seq;\n\t\t});\n\t\tconst ordered = resolved.order === \"asc\" ? filtered : [...filtered].reverse();\n\t\treturn ordered.slice(0, resolved.limit) as ListElement<T>[];\n\t}\n\n\tscanBranch(query: StorageBranchScan): Entry[] {\n\t\tconst start = this.entries.get(query.start);\n\t\tif (start === undefined) throw new Error(`Unknown branch start: ${query.start}`);\n\n\t\tconst path: Entry[] = [];\n\t\tlet entry: Entry | undefined = start;\n\t\twhile (entry !== undefined) {\n\t\t\tpath.push(entry);\n\t\t\tif (entry.parentId === null) break;\n\t\t\tentry = this.entries.get(entry.parentId);\n\t\t\tif (entry === undefined) throw new Error(\"Corrupt branch: missing parent\");\n\t\t}\n\t\tif (query.order === \"oldestFirst\") path.reverse();\n\n\t\tconst stopped: Entry[] = [];\n\t\tfor (const candidate of path) {\n\t\t\tstopped.push(candidate);\n\t\t\tif (candidate.id === query.stopAtId || candidate.type === query.stopAtType) break;\n\t\t}\n\t\tconst filtered = stopped\n\t\t\t.filter((candidate) => query.type === undefined || candidate.type === query.type)\n\t\t\t.filter((candidate) => query.customType === undefined || candidate.customType === query.customType)\n\t\t\t.filter(\n\t\t\t\t(candidate) =>\n\t\t\t\t\tquery.cursor === undefined ||\n\t\t\t\t\t(query.order === \"oldestFirst\" ? candidate.seq > query.cursor.seq : candidate.seq < query.cursor.seq),\n\t\t\t);\n\t\treturn query.limit === undefined ? filtered : filtered.slice(0, Math.max(0, query.limit));\n\t}\n\n\tscanBranchStructure(query: StorageBranchScan): EntryStructure[] {\n\t\treturn this.scanBranch(query).map((entry) => ({\n\t\t\tid: entry.id,\n\t\t\tparentId: entry.parentId,\n\t\t\tseq: entry.seq,\n\t\t\ttimestamp: entry.timestamp,\n\t\t\ttype: entry.type,\n\t\t\t...(entry.customType === undefined ? {} : { customType: entry.customType }),\n\t\t}));\n\t}\n\n\tscanEntries(query: EntryScan): Entry[] {\n\t\tconst limit = query.limit === undefined ? Number.POSITIVE_INFINITY : Math.max(0, Math.trunc(query.limit));\n\t\tconst entries: Entry[] = [];\n\t\tconst descending = query.order === \"desc\";\n\t\tlet index = descending ? this.entriesBySeq.length - 1 : 0;\n\t\twhile (index >= 0 && index < this.entriesBySeq.length && entries.length < limit) {\n\t\t\tconst entry = this.entriesBySeq[index]!;\n\t\t\tif (\n\t\t\t\t(query.type === undefined || entry.type === query.type) &&\n\t\t\t\t(query.customType === undefined || entry.customType === query.customType) &&\n\t\t\t\t(query.fromSeq === undefined || entry.seq >= query.fromSeq) &&\n\t\t\t\t(query.toSeq === undefined || entry.seq <= query.toSeq)\n\t\t\t) {\n\t\t\t\tentries.push(entry);\n\t\t\t}\n\t\t\tindex += descending ? -1 : 1;\n\t\t}\n\t\treturn entries;\n\t}\n\n\tscanUsage(query: UsageScan): UsageRow[] {\n\t\tconst rows = [...this.usage.values()]\n\t\t\t.filter((row) => query.fromSeq === undefined || row.seq >= query.fromSeq)\n\t\t\t.filter((row) => query.toSeq === undefined || row.seq <= query.toSeq)\n\t\t\t.sort((left, right) => (query.order === \"desc\" ? right.seq - left.seq : left.seq - right.seq));\n\t\treturn query.limit === undefined ? rows : rows.slice(0, Math.max(0, query.limit));\n\t}\n\n\tgetStats(): SessionStats {\n\t\treturn this.stats;\n\t}\n\n\tgetNextSeq(): number {\n\t\treturn this.nextSeq;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"in-memory-storage-state.d.ts","sourceRoot":"","sources":["../../../src/harness/session/in-memory-storage-state.ts"],"names":[],"mappings":"AACA,OAAO,EAGN,KAAK,cAAc,EACnB,KAAK,cAAc,EAGnB,MAAM,aAAa,CAAC;AAGrB,YAAY,EACX,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,cAAc,EACd,cAAc,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EACX,KAAK,EACL,SAAS,EACT,cAAc,EACd,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,QAAQ,EACR,SAAS,EACT,KAAK,EACL,MAAM,YAAY,CAAC;AACpB,OAAO,EAEN,KAAK,WAAW,EAChB,KAAK,eAAe,EAKpB,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,SAAS,EAEd,MAAM,aAAa,CAAC;AA0BrB;;;;;GAKG;AACH,qBAAa,oBAAoB;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;IACvC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAoC;IACjE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkC;IAC7D,OAAO,CAAC,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,YAAY,CAEvB;IAED,UAAU,IAAI,MAAM,CAEnB;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-storage-state.js","sourceRoot":"","sources":["../../../src/harness/session/in-memory-storage-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAKN,oBAAoB,EACpB,uBAAuB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAwBlF,OAAO,EACN,SAAS,EAGT,UAAU,EACV,SAAS,EACT,IAAI,EACJ,sBAAsB,EAItB,KAAK,GACL,MAAM,aAAa,CAAC;AAWrB,SAAS,WAAW,CAAC,SAAiB,EAAE,GAAW,EAAU;IAC5D,OAAO,GAAG,SAAS,SAAS,GAAG,EAAE,CAAC;AAAA,CAClC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,KAAa,EAAU;IACzD,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,CAAC;IAClF,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,CAAC;IACpF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IACvE,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC7C,MAAM,UAAU,GAAG,cAAc,CAAC,KAAK,CAAE,GAAG,eAAe,CAAC,KAAK,CAAE,CAAC;QACpE,IAAI,UAAU,KAAK,CAAC;YAAE,OAAO,UA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CAAC;QACD,OAAO,OAAO,CAAC;IAAA,CACf;IAED,SAAS,CAAC,KAAgB,EAAc;QACvC,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;aACnC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,GAAG,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC;aACxE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,GAAG,CAAC,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC;aACpE,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAChG,OAAO,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAAA,CAClF;IAED,QAAQ,GAAiB;QACxB,OAAO,IAAI,CAAC,KAAK,CAAC;IAAA,CAClB;IAED,UAAU,GAAW;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC;IAAA,CACpB;CACD","sourcesContent":["import { addUsage, emptyUsage } from \"../utils/usage.ts\";\nimport {\n\ttype CommittedListAppendWrite,\n\ttype CommittedValueSetWrite,\n\ttype CommittedWrite,\n\ttype PreparedCommit,\n\tprepareStorageCommit,\n\tvalidateCommittedWrites,\n} from \"./commit.ts\";\nimport { projectForkCurrentStateWrite, selectBranchFork } from \"./fork-policy.ts\";\n\nexport type {\n\tCommittedEntryWrite,\n\tCommittedListAppendWrite,\n\tCommittedListDeleteWrite,\n\tCommittedUsageWrite,\n\tCommittedValueDeleteWrite,\n\tCommittedValueSetWrite,\n\tCommittedWrite,\n\tPreparedCommit,\n} from \"./commit.ts\";\n\nimport type {\n\tEntry,\n\tEntryScan,\n\tEntryStructure,\n\tForkOptions,\n\tSessionStats,\n\tStorageBranchScan,\n\tUsageRow,\n\tUsageScan,\n\tWrite,\n} from \"./types.ts\";\nimport {\n\tbranchTip,\n\ttype ListElement,\n\ttype ListReadOptions,\n\tlaneConfig,\n\tlaneState,\n\tlist,\n\tresolveListReadOptions,\n\ttype StoredValue,\n\ttype Value,\n\ttype ValueList,\n\tvalue,\n} from \"./values.ts\";\n\ninterface StoredListSnapshot {\n\taddress: ValueList<unknown>;\n\telements: ListElement<unknown>[];\n}\n\ntype MemoryForkPlan =\n\t| { scope: \"tree\" }\n\t| { scope: \"branch\"; branch: string; destinationTip: string | null; entryIds: Set<string> };\n\nfunction physicalKey(namespace: string, key: string): string {\n\treturn `${namespace}\\u0000${key}`;\n}\n\nfunction compareKeys(left: string, right: string): number {\n\tconst leftCodePoints = Array.from(left, (character) => character.codePointAt(0)!);\n\tconst rightCodePoints = Array.from(right, (character) => character.codePointAt(0)!);\n\tconst length = Math.min(leftCodePoints.length, rightCodePoints.length);\n\tfor (let index = 0; index < length; index++) {\n\t\tconst difference = leftCodePoints[index]! - rightCodePoints[index]!;\n\t\tif (difference !== 0) return difference;\n\t}\n\treturn leftCodePoints.length - rightCodePoints.length;\n}\n\n/**\n * Complete materialized session state for MemoryStorage and JsonlStorage.\n *\n * This is intentionally unsuitable for database backends and long-running sessions that may not fit in memory.\n * Those backends should query indexed durable state and update durable aggregates within each commit transaction.\n */\nexport class InMemoryStorageState {\n\tprivate readonly entries: Map<string, Entry>;\n\tprivate readonly entriesBySeq: Entry[];\n\tprivate readonly scalarValues: Map<string, StoredValue<unknown>>;\n\tprivate readonly listValues: Map<string, StoredListSnapshot>;\n\tprivate readonly usage: Map<string, UsageRow>;\n\tprivate stats: SessionStats;\n\tprivate nextSeq: number;\n\n\tconstructor() {\n\t\tthis.entries = new Map();\n\t\tthis.entriesBySeq = [];\n\t\tthis.scalarValues = new Map();\n\t\tthis.listValues = new Map();\n\t\tthis.usage = new Map();\n\t\tthis.stats = { messageCount: 0, usage: emptyUsage() };\n\t\tthis.nextSeq = 1;\n\t}\n\n\tprepareCommit(writes: Write[], timestamp: number): PreparedCommit {\n\t\tconst prepared = prepareStorageCommit(writes, this.nextSeq, timestamp);\n\t\tthis.validateCommitted(prepared.writes);\n\t\treturn prepared;\n\t}\n\n\tvalidateCommitted(writes: readonly CommittedWrite[]): void {\n\t\tvalidateCommittedWrites(writes, this.nextSeq, {\n\t\t\thasEntryOrUsageId: (id) => this.entries.has(id) || this.usage.has(id),\n\t\t\thasEntryId: (id) => this.entries.has(id),\n\t\t});\n\t}\n\n\t/** Apply writes already accepted by validateCommitted() and return the post-apply totals. */\n\tapplyValidated(writes: readonly CommittedWrite[]): SessionStats {\n\t\tfor (const write of writes) {\n\t\t\tswitch (write.kind) {\n\t\t\t\tcase \"entry\": {\n\t\t\t\t\tconst { kind: _kind, ...entry } = write;\n\t\t\t\t\tthis.entries.set(entry.id, entry);\n\t\t\t\t\tthis.entriesBySeq.push(entry);\n\t\t\t\t\tif (entry.type === \"message\") this.stats = { ...this.stats, messageCount: this.stats.messageCount + 1 };\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"usage\": {\n\t\t\t\t\tconst { kind: _kind, ...row } = write;\n\t\t\t\t\tthis.usage.set(row.id, row);\n\t\t\t\t\tthis.stats = { ...this.stats, usage: addUsage(this.stats.usage, row.usage) };\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"value\":\n\t\t\t\t\tif (write.op === \"delete\") this.scalarValues.delete(physicalKey(write.namespace, write.key));\n\t\t\t\t\telse this.applyValueSetOrListAppend(write);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"list\":\n\t\t\t\t\tif (write.op === \"delete\") this.listValues.delete(physicalKey(write.namespace, write.key));\n\t\t\t\t\telse this.applyValueSetOrListAppend(write);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.nextSeq = write.seq + 1;\n\t\t}\n\t\treturn this.stats;\n\t}\n\n\tcreateFork(options: ForkOptions): InMemoryStorageState {\n\t\tconst plan = this.selectForkPlan(options);\n\n\t\tconst isEntryCopied = (entryId: string): boolean => {\n\t\t\tif (plan.scope === \"tree\") return true;\n\t\t\treturn plan.entryIds.has(entryId);\n\t\t};\n\t\tconst destination = new InMemoryStorageState();\n\t\tlet messageCount = 0;\n\t\tfor (const entry of this.entriesBySeq) {\n\t\t\tif (!isEntryCopied(entry.id)) continue;\n\t\t\tdestination.entries.set(entry.id, entry);\n\t\t\tdestination.entriesBySeq.push(entry);\n\t\t\tif (entry.type === \"message\") messageCount++;\n\t\t}\n\t\tdestination.stats = { ...destination.stats, messageCount };\n\n\t\tfor (const stored of this.scalarValues.values()) {\n\t\t\tconst projected = projectForkCurrentStateWrite(\n\t\t\t\t{\n\t\t\t\t\tkind: \"value\",\n\t\t\t\t\top: \"set\",\n\t\t\t\t\tseq: stored.seq,\n\t\t\t\t\tnamespace: stored.address.namespace,\n\t\t\t\t\tkey: stored.address.key,\n\t\t\t\t\tvalue: stored.value,\n\t\t\t\t},\n\t\t\t\tplan,\n\t\t\t\tisEntryCopied,\n\t\t\t);\n\t\t\tif (projected !== undefined) destination.applyValueSetOrListAppend(projected);\n\t\t}\n\n\t\tfor (const stored of this.listValues.values()) {\n\t\t\tfor (const element of stored.elements) {\n\t\t\t\tconst projected = projectForkCurrentStateWrite(\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: \"list\",\n\t\t\t\t\t\top: \"append\",\n\t\t\t\t\t\tseq: element.seq,\n\t\t\t\t\t\tnamespace: stored.address.namespace,\n\t\t\t\t\t\tkey: stored.address.key,\n\t\t\t\t\t\tvalue: element.value,\n\t\t\t\t\t},\n\t\t\t\t\tplan,\n\t\t\t\t\tisEntryCopied,\n\t\t\t\t);\n\t\t\t\tif (projected !== undefined) destination.applyValueSetOrListAppend(projected);\n\t\t\t}\n\t\t}\n\t\tdestination.nextSeq = this.nextSeq;\n\t\treturn destination;\n\t}\n\n\tprivate selectForkPlan(options: ForkOptions): MemoryForkPlan {\n\t\tif (options.scope === \"tree\") return { scope: \"tree\" };\n\n\t\tconst entryIds = new Set<string>();\n\t\tconst plan = selectBranchFork(options, {\n\t\t\ttip: this.getValue(branchTip(options.branch))?.value,\n\t\t\tgetParent: (entryId) => this.entries.get(entryId)?.parentId,\n\t\t\tselectEntry: (entryId) => entryIds.add(entryId),\n\t\t});\n\t\tif (\n\t\t\tthis.getValue(laneConfig(options.branch)) === undefined ||\n\t\t\tthis.getValue(laneState(options.branch)) === undefined\n\t\t) {\n\t\t\tthrow new Error(`Source branch ${JSON.stringify(options.branch)} is not a configured AgentLane`);\n\t\t}\n\t\treturn { ...plan, entryIds };\n\t}\n\n\tprivate applyValueSetOrListAppend(write: CommittedValueSetWrite | CommittedListAppendWrite): void {\n\t\tconst key = physicalKey(write.namespace, write.key);\n\t\tif (write.kind === \"value\") {\n\t\t\tthis.scalarValues.set(key, {\n\t\t\t\taddress: value<unknown>(write.namespace, write.key),\n\t\t\t\tvalue: write.value,\n\t\t\t\tseq: write.seq,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst element = { seq: write.seq, value: write.value };\n\t\tconst stored = this.listValues.get(key);\n\t\tif (stored === undefined) {\n\t\t\tthis.listValues.set(key, {\n\t\t\t\taddress: list<unknown>(write.namespace, write.key),\n\t\t\t\telements: [element],\n\t\t\t});\n\t\t} else {\n\t\t\tstored.elements.push(element);\n\t\t}\n\t}\n\n\tadvanceNextSeq(nextSeq: number): void {\n\t\tif (!Number.isSafeInteger(nextSeq) || nextSeq < 1) {\n\t\t\tthrow new Error(`Invalid storage sequence high-water mark: ${nextSeq}`);\n\t\t}\n\t\tthis.nextSeq = Math.max(this.nextSeq, nextSeq);\n\t}\n\n\tgetEntries(ids: readonly string[]): Map<string, Entry> {\n\t\tconst found = new Map<string, Entry>();\n\t\tfor (const id of ids) {\n\t\t\tconst entry = this.entries.get(id);\n\t\t\tif (entry !== undefined) found.set(id, entry);\n\t\t}\n\t\treturn found;\n\t}\n\n\tgetValue<T>(address: Value<T>): StoredValue<T> | undefined {\n\t\treturn this.scalarValues.get(physicalKey(address.namespace, address.key)) as StoredValue<T> | undefined;\n\t}\n\n\tscanValues<T>(prefix: Value<T>): StoredValue<T>[] {\n\t\treturn [...this.scalarValues.values()]\n\t\t\t.filter((stored) => stored.address.namespace === prefix.namespace && stored.address.key.startsWith(prefix.key))\n\t\t\t.sort((left, right) => compareKeys(left.address.key, right.address.key)) as StoredValue<T>[];\n\t}\n\n\treadList<T>(address: ValueList<T>, options?: ListReadOptions): ListElement<T>[] {\n\t\tconst resolved = resolveListReadOptions(options);\n\t\tconst elements = this.listValues.get(physicalKey(address.namespace, address.key))?.elements ?? [];\n\t\tconst filtered = elements.filter((element) => {\n\t\t\tif (resolved.cursor === undefined) return true;\n\t\t\treturn resolved.order === \"asc\" ? element.seq > resolved.cursor.seq : element.seq < resolved.cursor.seq;\n\t\t});\n\t\tconst ordered = resolved.order === \"asc\" ? filtered : [...filtered].reverse();\n\t\treturn ordered.slice(0, resolved.limit) as ListElement<T>[];\n\t}\n\n\tscanBranch(query: StorageBranchScan): Entry[] {\n\t\tconst start = this.entries.get(query.start);\n\t\tif (start === undefined) throw new Error(`Unknown branch start: ${query.start}`);\n\n\t\tconst path: Entry[] = [];\n\t\tlet entry: Entry | undefined = start;\n\t\twhile (entry !== undefined) {\n\t\t\tpath.push(entry);\n\t\t\tif (entry.parentId === null) break;\n\t\t\tentry = this.entries.get(entry.parentId);\n\t\t\tif (entry === undefined) throw new Error(\"Corrupt branch: missing parent\");\n\t\t}\n\t\tif (query.order === \"oldestFirst\") path.reverse();\n\n\t\tconst stopped: Entry[] = [];\n\t\tfor (const candidate of path) {\n\t\t\tstopped.push(candidate);\n\t\t\tif (candidate.id === query.stopAtId || candidate.type === query.stopAtType) break;\n\t\t}\n\t\tconst filtered = stopped\n\t\t\t.filter((candidate) => query.type === undefined || candidate.type === query.type)\n\t\t\t.filter((candidate) => query.customType === undefined || candidate.customType === query.customType)\n\t\t\t.filter(\n\t\t\t\t(candidate) =>\n\t\t\t\t\tquery.cursor === undefined ||\n\t\t\t\t\t(query.order === \"oldestFirst\" ? candidate.seq > query.cursor.seq : candidate.seq < query.cursor.seq),\n\t\t\t);\n\t\treturn query.limit === undefined ? filtered : filtered.slice(0, Math.max(0, query.limit));\n\t}\n\n\tscanBranchStructure(query: StorageBranchScan): EntryStructure[] {\n\t\treturn this.scanBranch(query).map((entry) => ({\n\t\t\tid: entry.id,\n\t\t\tparentId: entry.parentId,\n\t\t\tseq: entry.seq,\n\t\t\ttimestamp: entry.timestamp,\n\t\t\ttype: entry.type,\n\t\t\t...(entry.customType === undefined ? {} : { customType: entry.customType }),\n\t\t}));\n\t}\n\n\tscanEntries(query: EntryScan): Entry[] {\n\t\tconst limit = query.limit === undefined ? Number.POSITIVE_INFINITY : Math.max(0, Math.trunc(query.limit));\n\t\tconst entries: Entry[] = [];\n\t\tconst descending = query.order === \"desc\";\n\t\tlet index = descending ? this.entriesBySeq.length - 1 : 0;\n\t\twhile (index >= 0 && index < this.entriesBySeq.length && entries.length < limit) {\n\t\t\tconst entry = this.entriesBySeq[index]!;\n\t\t\tif (\n\t\t\t\t(query.type === undefined || entry.type === query.type) &&\n\t\t\t\t(query.customType === undefined || entry.customType === query.customType) &&\n\t\t\t\t(query.fromSeq === undefined || entry.seq >= query.fromSeq) &&\n\t\t\t\t(query.toSeq === undefined || entry.seq <= query.toSeq)\n\t\t\t) {\n\t\t\t\tentries.push(entry);\n\t\t\t}\n\t\t\tindex += descending ? -1 : 1;\n\t\t}\n\t\treturn entries;\n\t}\n\n\tscanUsage(query: UsageScan): UsageRow[] {\n\t\tconst rows = [...this.usage.values()]\n\t\t\t.filter((row) => query.fromSeq === undefined || row.seq >= query.fromSeq)\n\t\t\t.filter((row) => query.toSeq === undefined || row.seq <= query.toSeq)\n\t\t\t.sort((left, right) => (query.order === \"desc\" ? right.seq - left.seq : left.seq - right.seq));\n\t\treturn query.limit === undefined ? rows : rows.slice(0, Math.max(0, query.limit));\n\t}\n\n\tgetStats(): SessionStats {\n\t\treturn this.stats;\n\t}\n\n\tgetNextSeq(): number {\n\t\treturn this.nextSeq;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"in-memory-storage-state.js","sourceRoot":"","sources":["../../../src/harness/session/in-memory-storage-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAKN,oBAAoB,EACpB,uBAAuB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAwBlF,OAAO,EACN,SAAS,EAGT,UAAU,EACV,SAAS,EACT,IAAI,EACJ,sBAAsB,EAItB,KAAK,GACL,MAAM,aAAa,CAAC;AAWrB,SAAS,WAAW,CAAC,SAAiB,EAAE,GAAW;IAClD,OAAO,GAAG,SAAS,SAAS,GAAG,EAAE,CAAC;AACnC,CAAC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,KAAa;IAC/C,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,CAAC;IAClF,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,CAAC;IACpF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,MAAM,EAAE,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AC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;YACD,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,SAAS,CAAC,KAAgB;QACzB,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;aACnC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,GAAG,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC;aACxE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,GAAG,CAAC,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC;aACpE,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAChG,OAAO,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IACnF,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,UAAU;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD","sourcesContent":["import { addUsage, emptyUsage } from \"../utils/usage.ts\";\nimport {\n\ttype CommittedListAppendWrite,\n\ttype CommittedValueSetWrite,\n\ttype CommittedWrite,\n\ttype PreparedCommit,\n\tprepareStorageCommit,\n\tvalidateCommittedWrites,\n} from \"./commit.ts\";\nimport { projectForkCurrentStateWrite, selectBranchFork } from \"./fork-policy.ts\";\n\nexport type {\n\tCommittedEntryWrite,\n\tCommittedListAppendWrite,\n\tCommittedListDeleteWrite,\n\tCommittedUsageWrite,\n\tCommittedValueDeleteWrite,\n\tCommittedValueSetWrite,\n\tCommittedWrite,\n\tPreparedCommit,\n} from \"./commit.ts\";\n\nimport type {\n\tEntry,\n\tEntryScan,\n\tEntryStructure,\n\tForkOptions,\n\tSessionStats,\n\tStorageBranchScan,\n\tUsageRow,\n\tUsageScan,\n\tWrite,\n} from \"./types.ts\";\nimport {\n\tbranchTip,\n\ttype ListElement,\n\ttype ListReadOptions,\n\tlaneConfig,\n\tlaneState,\n\tlist,\n\tresolveListReadOptions,\n\ttype StoredValue,\n\ttype Value,\n\ttype ValueList,\n\tvalue,\n} from \"./values.ts\";\n\ninterface StoredListSnapshot {\n\taddress: ValueList<unknown>;\n\telements: ListElement<unknown>[];\n}\n\ntype MemoryForkPlan =\n\t| { scope: \"tree\" }\n\t| { scope: \"branch\"; branch: string; destinationTip: string | null; entryIds: Set<string> };\n\nfunction physicalKey(namespace: string, key: string): string {\n\treturn `${namespace}\\u0000${key}`;\n}\n\nfunction compareKeys(left: string, right: string): number {\n\tconst leftCodePoints = Array.from(left, (character) => character.codePointAt(0)!);\n\tconst rightCodePoints = Array.from(right, (character) => character.codePointAt(0)!);\n\tconst length = Math.min(leftCodePoints.length, rightCodePoints.length);\n\tfor (let index = 0; index < length; index++) {\n\t\tconst difference = leftCodePoints[index]! - rightCodePoints[index]!;\n\t\tif (difference !== 0) return difference;\n\t}\n\treturn leftCodePoints.length - rightCodePoints.length;\n}\n\n/**\n * Complete materialized session state for MemoryStorage and JsonlStorage.\n *\n * This is intentionally unsuitable for database backends and long-running sessions that may not fit in memory.\n * Those backends should query indexed durable state and update durable aggregates within each commit transaction.\n */\nexport class InMemoryStorageState {\n\tprivate readonly entries: Map<string, Entry>;\n\tprivate readonly entriesBySeq: Entry[];\n\tprivate readonly scalarValues: Map<string, StoredValue<unknown>>;\n\tprivate readonly listValues: Map<string, StoredListSnapshot>;\n\tprivate readonly usage: Map<string, UsageRow>;\n\tprivate stats: SessionStats;\n\tprivate nextSeq: number;\n\n\tconstructor() {\n\t\tthis.entries = new Map();\n\t\tthis.entriesBySeq = [];\n\t\tthis.scalarValues = new Map();\n\t\tthis.listValues = new Map();\n\t\tthis.usage = new Map();\n\t\tthis.stats = { messageCount: 0, usage: emptyUsage() };\n\t\tthis.nextSeq = 1;\n\t}\n\n\tprepareCommit(writes: Write[], timestamp: number): PreparedCommit {\n\t\tconst prepared = prepareStorageCommit(writes, this.nextSeq, timestamp);\n\t\tthis.validateCommitted(prepared.writes);\n\t\treturn prepared;\n\t}\n\n\tvalidateCommitted(writes: readonly CommittedWrite[]): void {\n\t\tvalidateCommittedWrites(writes, this.nextSeq, {\n\t\t\thasEntryOrUsageId: (id) => this.entries.has(id) || this.usage.has(id),\n\t\t\thasEntryId: (id) => this.entries.has(id),\n\t\t});\n\t}\n\n\t/** Apply writes already accepted by validateCommitted() and return the post-apply totals. */\n\tapplyValidated(writes: readonly CommittedWrite[]): SessionStats {\n\t\tfor (const write of writes) {\n\t\t\tswitch (write.kind) {\n\t\t\t\tcase \"entry\": {\n\t\t\t\t\tconst { kind: _kind, ...entry } = write;\n\t\t\t\t\tthis.entries.set(entry.id, entry);\n\t\t\t\t\tthis.entriesBySeq.push(entry);\n\t\t\t\t\tif (entry.type === \"message\") this.stats = { ...this.stats, messageCount: this.stats.messageCount + 1 };\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"usage\": {\n\t\t\t\t\tconst { kind: _kind, ...row } = write;\n\t\t\t\t\tthis.usage.set(row.id, row);\n\t\t\t\t\tthis.stats = { ...this.stats, usage: addUsage(this.stats.usage, row.usage) };\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"value\":\n\t\t\t\t\tif (write.op === \"delete\") this.scalarValues.delete(physicalKey(write.namespace, write.key));\n\t\t\t\t\telse this.applyValueSetOrListAppend(write);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"list\":\n\t\t\t\t\tif (write.op === \"delete\") this.listValues.delete(physicalKey(write.namespace, write.key));\n\t\t\t\t\telse this.applyValueSetOrListAppend(write);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.nextSeq = write.seq + 1;\n\t\t}\n\t\treturn this.stats;\n\t}\n\n\tcreateFork(options: ForkOptions): InMemoryStorageState {\n\t\tconst plan = this.selectForkPlan(options);\n\n\t\tconst isEntryCopied = (entryId: string): boolean => {\n\t\t\tif (plan.scope === \"tree\") return true;\n\t\t\treturn plan.entryIds.has(entryId);\n\t\t};\n\t\tconst destination = new InMemoryStorageState();\n\t\tlet messageCount = 0;\n\t\tfor (const entry of this.entriesBySeq) {\n\t\t\tif (!isEntryCopied(entry.id)) continue;\n\t\t\tdestination.entries.set(entry.id, entry);\n\t\t\tdestination.entriesBySeq.push(entry);\n\t\t\tif (entry.type === \"message\") messageCount++;\n\t\t}\n\t\tdestination.stats = { ...destination.stats, messageCount };\n\n\t\tfor (const stored of this.scalarValues.values()) {\n\t\t\tconst projected = projectForkCurrentStateWrite(\n\t\t\t\t{\n\t\t\t\t\tkind: \"value\",\n\t\t\t\t\top: \"set\",\n\t\t\t\t\tseq: stored.seq,\n\t\t\t\t\tnamespace: stored.address.namespace,\n\t\t\t\t\tkey: stored.address.key,\n\t\t\t\t\tvalue: stored.value,\n\t\t\t\t},\n\t\t\t\tplan,\n\t\t\t\tisEntryCopied,\n\t\t\t);\n\t\t\tif (projected !== undefined) destination.applyValueSetOrListAppend(projected);\n\t\t}\n\n\t\tfor (const stored of this.listValues.values()) {\n\t\t\tfor (const element of stored.elements) {\n\t\t\t\tconst projected = projectForkCurrentStateWrite(\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: \"list\",\n\t\t\t\t\t\top: \"append\",\n\t\t\t\t\t\tseq: element.seq,\n\t\t\t\t\t\tnamespace: stored.address.namespace,\n\t\t\t\t\t\tkey: stored.address.key,\n\t\t\t\t\t\tvalue: element.value,\n\t\t\t\t\t},\n\t\t\t\t\tplan,\n\t\t\t\t\tisEntryCopied,\n\t\t\t\t);\n\t\t\t\tif (projected !== undefined) destination.applyValueSetOrListAppend(projected);\n\t\t\t}\n\t\t}\n\t\tdestination.nextSeq = this.nextSeq;\n\t\treturn destination;\n\t}\n\n\tprivate selectForkPlan(options: ForkOptions): MemoryForkPlan {\n\t\tif (options.scope === \"tree\") return { scope: \"tree\" };\n\n\t\tconst entryIds = new Set<string>();\n\t\tconst plan = selectBranchFork(options, {\n\t\t\ttip: this.getValue(branchTip(options.branch))?.value,\n\t\t\tgetParent: (entryId) => this.entries.get(entryId)?.parentId,\n\t\t\tselectEntry: (entryId) => entryIds.add(entryId),\n\t\t});\n\t\tif (\n\t\t\tthis.getValue(laneConfig(options.branch)) === undefined ||\n\t\t\tthis.getValue(laneState(options.branch)) === undefined\n\t\t) {\n\t\t\tthrow new Error(`Source branch ${JSON.stringify(options.branch)} is not a configured AgentLane`);\n\t\t}\n\t\treturn { ...plan, entryIds };\n\t}\n\n\tprivate applyValueSetOrListAppend(write: CommittedValueSetWrite | CommittedListAppendWrite): void {\n\t\tconst key = physicalKey(write.namespace, write.key);\n\t\tif (write.kind === \"value\") {\n\t\t\tthis.scalarValues.set(key, {\n\t\t\t\taddress: value<unknown>(write.namespace, write.key),\n\t\t\t\tvalue: write.value,\n\t\t\t\tseq: write.seq,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst element = { seq: write.seq, value: write.value };\n\t\tconst stored = this.listValues.get(key);\n\t\tif (stored === undefined) {\n\t\t\tthis.listValues.set(key, {\n\t\t\t\taddress: list<unknown>(write.namespace, write.key),\n\t\t\t\telements: [element],\n\t\t\t});\n\t\t} else {\n\t\t\tstored.elements.push(element);\n\t\t}\n\t}\n\n\tadvanceNextSeq(nextSeq: number): void {\n\t\tif (!Number.isSafeInteger(nextSeq) || nextSeq < 1) {\n\t\t\tthrow new Error(`Invalid storage sequence high-water mark: ${nextSeq}`);\n\t\t}\n\t\tthis.nextSeq = Math.max(this.nextSeq, nextSeq);\n\t}\n\n\tgetEntries(ids: readonly string[]): Map<string, Entry> {\n\t\tconst found = new Map<string, Entry>();\n\t\tfor (const id of ids) {\n\t\t\tconst entry = this.entries.get(id);\n\t\t\tif (entry !== undefined) found.set(id, entry);\n\t\t}\n\t\treturn found;\n\t}\n\n\tgetValue<T>(address: Value<T>): StoredValue<T> | undefined {\n\t\treturn this.scalarValues.get(physicalKey(address.namespace, address.key)) as StoredValue<T> | undefined;\n\t}\n\n\tscanValues<T>(prefix: Value<T>): StoredValue<T>[] {\n\t\treturn [...this.scalarValues.values()]\n\t\t\t.filter((stored) => stored.address.namespace === prefix.namespace && stored.address.key.startsWith(prefix.key))\n\t\t\t.sort((left, right) => compareKeys(left.address.key, right.address.key)) as StoredValue<T>[];\n\t}\n\n\treadList<T>(address: ValueList<T>, options?: ListReadOptions): ListElement<T>[] {\n\t\tconst resolved = resolveListReadOptions(options);\n\t\tconst elements = this.listValues.get(physicalKey(address.namespace, address.key))?.elements ?? [];\n\t\tconst filtered = elements.filter((element) => {\n\t\t\tif (resolved.cursor === undefined) return true;\n\t\t\treturn resolved.order === \"asc\" ? element.seq > resolved.cursor.seq : element.seq < resolved.cursor.seq;\n\t\t});\n\t\tconst ordered = resolved.order === \"asc\" ? filtered : [...filtered].reverse();\n\t\treturn ordered.slice(0, resolved.limit) as ListElement<T>[];\n\t}\n\n\tscanBranch(query: StorageBranchScan): Entry[] {\n\t\tconst start = this.entries.get(query.start);\n\t\tif (start === undefined) throw new Error(`Unknown branch start: ${query.start}`);\n\n\t\tconst path: Entry[] = [];\n\t\tlet entry: Entry | undefined = start;\n\t\twhile (entry !== undefined) {\n\t\t\tpath.push(entry);\n\t\t\tif (entry.parentId === null) break;\n\t\t\tentry = this.entries.get(entry.parentId);\n\t\t\tif (entry === undefined) throw new Error(\"Corrupt branch: missing parent\");\n\t\t}\n\t\tif (query.order === \"oldestFirst\") path.reverse();\n\n\t\tconst stopped: Entry[] = [];\n\t\tfor (const candidate of path) {\n\t\t\tstopped.push(candidate);\n\t\t\tif (candidate.id === query.stopAtId || candidate.type === query.stopAtType) break;\n\t\t}\n\t\tconst filtered = stopped\n\t\t\t.filter((candidate) => query.type === undefined || candidate.type === query.type)\n\t\t\t.filter((candidate) => query.customType === undefined || candidate.customType === query.customType)\n\t\t\t.filter(\n\t\t\t\t(candidate) =>\n\t\t\t\t\tquery.cursor === undefined ||\n\t\t\t\t\t(query.order === \"oldestFirst\" ? candidate.seq > query.cursor.seq : candidate.seq < query.cursor.seq),\n\t\t\t);\n\t\treturn query.limit === undefined ? filtered : filtered.slice(0, Math.max(0, query.limit));\n\t}\n\n\tscanBranchStructure(query: StorageBranchScan): EntryStructure[] {\n\t\treturn this.scanBranch(query).map((entry) => ({\n\t\t\tid: entry.id,\n\t\t\tparentId: entry.parentId,\n\t\t\tseq: entry.seq,\n\t\t\ttimestamp: entry.timestamp,\n\t\t\ttype: entry.type,\n\t\t\t...(entry.customType === undefined ? {} : { customType: entry.customType }),\n\t\t}));\n\t}\n\n\tscanEntries(query: EntryScan): Entry[] {\n\t\tconst limit = query.limit === undefined ? Number.POSITIVE_INFINITY : Math.max(0, Math.trunc(query.limit));\n\t\tconst entries: Entry[] = [];\n\t\tconst descending = query.order === \"desc\";\n\t\tlet index = descending ? this.entriesBySeq.length - 1 : 0;\n\t\twhile (index >= 0 && index < this.entriesBySeq.length && entries.length < limit) {\n\t\t\tconst entry = this.entriesBySeq[index]!;\n\t\t\tif (\n\t\t\t\t(query.type === undefined || entry.type === query.type) &&\n\t\t\t\t(query.customType === undefined || entry.customType === query.customType) &&\n\t\t\t\t(query.fromSeq === undefined || entry.seq >= query.fromSeq) &&\n\t\t\t\t(query.toSeq === undefined || entry.seq <= query.toSeq)\n\t\t\t) {\n\t\t\t\tentries.push(entry);\n\t\t\t}\n\t\t\tindex += descending ? -1 : 1;\n\t\t}\n\t\treturn entries;\n\t}\n\n\tscanUsage(query: UsageScan): UsageRow[] {\n\t\tconst rows = [...this.usage.values()]\n\t\t\t.filter((row) => query.fromSeq === undefined || row.seq >= query.fromSeq)\n\t\t\t.filter((row) => query.toSeq === undefined || row.seq <= query.toSeq)\n\t\t\t.sort((left, right) => (query.order === \"desc\" ? right.seq - left.seq : left.seq - right.seq));\n\t\treturn query.limit === undefined ? rows : rows.slice(0, Math.max(0, query.limit));\n\t}\n\n\tgetStats(): SessionStats {\n\t\treturn this.stats;\n\t}\n\n\tgetNextSeq(): number {\n\t\treturn this.nextSeq;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/harness/session/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,cAAc,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACnH,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,KAAK,oBAAoB,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EACN,qBAAqB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,gBAAgB,EAChB,KAAK,uBAAuB,GAC5B,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACN,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,mCAAmC,EACnC,yBAAyB,EACzB,oBAAoB,EACpB,KAAK,2BAA2B,GAChC,MAAM,cAAc,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/harness/session/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,cAAc,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACnH,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,KAAK,oBAAoB,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EACN,qBAAqB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,gBAAgB,EAChB,KAAK,uBAAuB,GAC5B,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACN,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,mCAAmC,EACnC,yBAAyB,EACzB,oBAAoB,EACpB,KAAK,2BAA2B,GAChC,MAAM,cAAc,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/codec.ts"],"names":[],"mappings":"AAAA,OAAO,E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AG,KAAK,IAAI,qBAAqB,CAWtF;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAahF;AAED,MAAM,MAAM,wBAAwB,GACjC;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,kBAAkB,CAAA;CAAE,GAC5C;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAE1D,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAU7F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAA2B,MAAM,YAAY,CAAC;AAW3E,SAAS,QAAQ,CAAC,KAAc
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAA2B,MAAM,YAAY,CAAC;AAW3E,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAc,EAAE,OAAe;IAC5D,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAK,KAAgB,IAAI,OAAO,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACrD,OAAO,CACN,QAAQ,CAAC,KAAK,CAAC;QACf,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,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,8CAA8C,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IACzF,CAAC;IACD,IAAI,oBAAoB,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,IAAI,uBAAuB,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACtF,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import { err, ok, type Result } from \"../../types.ts\";\nimport { JSONL_FORMAT_VERSION, type JsonlStorageHeader } from \"./types.ts\";\n\nexport interface LegacyV3SessionHeader {\n\ttype: \"session\";\n\tversion: 3;\n\tid: string;\n\ttimestamp: string;\n\tcwd: string;\n\tparentSession?: string;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isSafeIntegerAtLeast(value: unknown, minimum: number): value is number {\n\treturn Number.isSafeInteger(value) && (value as number) >= minimum;\n}\n\nexport function isLegacyV3SessionHeader(value: unknown): value is LegacyV3SessionHeader {\n\treturn (\n\t\tisRecord(value) &&\n\t\tvalue.type === \"session\" &&\n\t\tvalue.version === 3 &&\n\t\ttypeof value.id === \"string\" &&\n\t\ttypeof value.cwd === \"string\" &&\n\t\ttypeof value.timestamp === \"string\" &&\n\t\tNumber.isFinite(Date.parse(value.timestamp)) &&\n\t\t(value.parentSession === undefined || typeof value.parentSession === \"string\")\n\t);\n}\n\nexport function isJsonlStorageHeader(value: unknown): value is JsonlStorageHeader {\n\treturn (\n\t\tisRecord(value) &&\n\t\tvalue.kind === \"header\" &&\n\t\tvalue.v === JSONL_FORMAT_VERSION &&\n\t\ttypeof value.id === \"string\" &&\n\t\ttypeof value.cwd === \"string\" &&\n\t\tisSafeIntegerAtLeast(value.storageVersion, 1) &&\n\t\tisSafeIntegerAtLeast(value.createdAt, 0) &&\n\t\t(value.nextSeq === undefined || isSafeIntegerAtLeast(value.nextSeq, 1)) &&\n\t\t(value.parentSessionId === undefined || typeof value.parentSessionId === \"string\") &&\n\t\t(value.legacyParentSessionPath === undefined || typeof value.legacyParentSessionPath === \"string\")\n\t);\n}\n\nexport type JsonlParsedSessionHeader =\n\t| { format: \"v4\"; header: JsonlStorageHeader }\n\t| { format: \"v3-legacy\"; header: LegacyV3SessionHeader };\n\nexport function parseJsonlSessionHeader(line: string): Result<JsonlParsedSessionHeader, Error> {\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(line);\n\t} catch (error) {\n\t\treturn err(new Error(\"Invalid JSONL session header: not valid JSON\", { cause: error }));\n\t}\n\tif (isJsonlStorageHeader(value)) return ok({ format: \"v4\", header: value });\n\tif (isLegacyV3SessionHeader(value)) return ok({ format: \"v3-legacy\", header: value });\n\treturn err(new Error(\"Unsupported JSONL session header\"));\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fork.d.ts","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/fork.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,gBAAgB,CAAC;AAQjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAyB,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE5E,UAAU,uBAAuB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACb;AA4LD,0FAA0F;AAC1F,MAAM,MAAM,cAAc,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,uBAAuB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpE;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,UAAU,EAAE,cAAc,CAAA;CAAE,CAAC;AA6ErD;;;;;;GAMG;AACH,wBAAsB,YAAY,CACjC,OAAO,EAAE;IACR,KAAK,EAAE,cAAc,CAAC;IACtB,UAAU,EAAE,UAAU,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,IAAI,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;IACvD,IAAI,EAAE,WAAW,CAAC;CAClB,EACD,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,IAAI,CAAC,CAwBf","sourcesContent":["import type { Context } from \"../../context.ts\";\nimport type { FileSystem, TextLineReader } from \"../../types.ts\";\nimport type {\n\tCommittedEntryWrite,\n\tCommittedListAppendWrite,\n\tCommittedValueSetWrite,\n\tCommittedWrite,\n} from \"../commit.ts\";\nimport { type ForkCurrentStatePlan, projectForkCurrentStateWrite, selectBranchFork } from \"../fork-policy.ts\";\nimport type { ForkOptions } from \"../types.ts\";\nimport { fileValue, parseJsonlTransaction, publishJsonl, readJsonlHeader } from \"./io.ts\";\nimport type { LegacyV3Source } from \"./legacy-v3.ts\";\nimport { JSONL_STORAGE_VERSION, type JsonlStorageHeader } from \"./types.ts\";\n\ninterface JsonlForkSourceMetadata {\n\tid: string;\n\tcwd: string;\n\tpath: string;\n}\n\nfunction physicalKey(namespace: string, key: string): string {\n\treturn `${namespace}\\u0000${key}`;\n}\n\nasync function readJsonlForkHeader(\n\treader: TextLineReader,\n\tsource: JsonlForkSourceMetadata,\n\tcontext: Context,\n): Promise<JsonlStorageHeader> {\n\tconst parsed = await readJsonlHeader(reader, source.path, context);\n\tif (parsed.format !== \"v4\") {\n\t\tthrow new Error(`Invalid JSONL storage ${source.path}: expected format 4 header`);\n\t}\n\tconst header = parsed.header;\n\tif (header.id !== source.id || header.cwd !== source.cwd) {\n\t\tthrow new Error(`Session identity does not match header: ${source.id}`);\n\t}\n\tif (header.storageVersion !== JSONL_STORAGE_VERSION) {\n\t\tthrow new Error(`Session ${source.id} uses unsupported storage version ${header.storageVersion}`);\n\t}\n\treturn header;\n}\n\nfunction reachesForkBoundary(writes: readonly CommittedWrite[], stopBeforeSeq: number | undefined): boolean {\n\tif (stopBeforeSeq === undefined || writes.length === 0) return false;\n\tconst first = writes[0]!;\n\tconst last = writes.at(-1)!;\n\tif (first.seq >= stopBeforeSeq) return true;\n\tif (last.seq >= stopBeforeSeq) {\n\t\tthrow new Error(`JSONL transaction crosses fork sequence boundary ${stopBeforeSeq}`);\n\t}\n\treturn false;\n}\n\n/** Read complete transactions after the header, never splitting a transaction at the sequence boundary. */\nasync function* readJsonlForkTransactions(\n\treader: TextLineReader,\n\tpath: string,\n\tstopBeforeSeq: number | undefined,\n\tcontext: Context,\n): AsyncIterable<CommittedWrite[]> {\n\twhile (true) {\n\t\tconst line = fileValue(await reader.readLine(context), `Failed to read JSONL fork source ${path}`);\n\t\tif (line === undefined || !line.terminated) break;\n\t\tconst writes = parseJsonlTransaction(line.text);\n\t\tif (reachesForkBoundary(writes, stopBeforeSeq)) break;\n\t\tyield writes;\n\t}\n}\n\nclass JsonlForkIndex {\n\tprivate readonly currentScalarSeqs = new Map<string, number>();\n\tprivate readonly branchTips = new Map<string, string | null>();\n\tprivate readonly firstSurvivingListSeqs = new Map<string, number>();\n\tprivate readonly entryParents = new Map<string, string | null>();\n\tprivate readonly copiedEntryIds = new Set<string>();\n\tprivate readonly laneConfigs = new Set<string>();\n\tprivate readonly laneStates = new Set<string>();\n\n\tapplyEntry(id: string, parentId: string | null): void {\n\t\tthis.entryParents.set(id, parentId);\n\t}\n\n\tapplyWrites(writes: readonly CommittedWrite[]): void {\n\t\tfor (const write of writes) {\n\t\t\tswitch (write.kind) {\n\t\t\t\tcase \"entry\":\n\t\t\t\t\tthis.applyEntry(write.id, write.parentId);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"value\": {\n\t\t\t\t\tconst key = physicalKey(write.namespace, write.key);\n\t\t\t\t\tif (write.op === \"delete\") {\n\t\t\t\t\t\tthis.currentScalarSeqs.delete(key);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.currentScalarSeqs.set(key, write.seq);\n\t\t\t\t\t}\n\t\t\t\t\tthis.applyLaneValue(write);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"list\": {\n\t\t\t\t\tconst key = physicalKey(write.namespace, write.key);\n\t\t\t\t\tif (write.op === \"delete\") this.firstSurvivingListSeqs.delete(key);\n\t\t\t\t\telse if (!this.firstSurvivingListSeqs.has(key)) this.firstSurvivingListSeqs.set(key, write.seq);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"usage\":\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate applyLaneValue(write: Extract<CommittedWrite, { kind: \"value\" }>): void {\n\t\tconst present = write.op === \"set\";\n\t\tswitch (write.namespace) {\n\t\t\tcase \"pi.branch.tip\":\n\t\t\t\tif (present) this.branchTips.set(write.key, write.value as string | null);\n\t\t\t\telse this.branchTips.delete(write.key);\n\t\t\t\tbreak;\n\t\t\tcase \"pi.lane.config\":\n\t\t\t\tif (present) this.laneConfigs.add(write.key);\n\t\t\t\telse this.laneConfigs.delete(write.key);\n\t\t\t\tbreak;\n\t\t\tcase \"pi.lane.state\":\n\t\t\t\tif (present) this.laneStates.add(write.key);\n\t\t\t\telse this.laneStates.delete(write.key);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tgetBranchTip(branch: string): string | null | undefined {\n\t\treturn this.branchTips.get(branch);\n\t}\n\n\thasCompleteLane(branch: string): boolean {\n\t\treturn this.laneConfigs.has(branch) && this.laneStates.has(branch);\n\t}\n\n\tgetCurrentScalarSeq(namespace: string, key: string): number | undefined {\n\t\treturn this.currentScalarSeqs.get(physicalKey(namespace, key));\n\t}\n\n\tisSurvivingListElement(namespace: string, key: string, seq: number): boolean {\n\t\tconst firstSeq = this.firstSurvivingListSeqs.get(physicalKey(namespace, key));\n\t\treturn firstSeq !== undefined && seq >= firstSeq;\n\t}\n\n\tgetParent(entryId: string): string | null | undefined {\n\t\treturn this.entryParents.get(entryId);\n\t}\n\n\tselectEntry(entryId: string): void {\n\t\tthis.copiedEntryIds.add(entryId);\n\t}\n\n\tisEntrySelected(entryId: string): boolean {\n\t\treturn this.copiedEntryIds.has(entryId);\n\t}\n}\n\n/**\n * Validate the source lanes and return the fork plan.\n *\n * Branch scope updates JsonlForkIndex's selected entries via index.selectEntry(): it selects the\n * destination tip and its ancestors after validating entryId and applying \"at\"/\"before\". The plan\n * records the branch name and destination tip; the copy pass uses the index to filter entries and labels.\n *\n * Tree scope leaves the index's selected entries unchanged because the copy pass keeps every entry.\n * Both formats use the same indexed metadata; this function performs no file I/O.\n */\nfunction selectJsonlFork(index: JsonlForkIndex, options: ForkOptions): ForkCurrentStatePlan {\n\tif (options.scope === \"tree\") return { scope: \"tree\" };\n\tconst plan = selectBranchFork(options, {\n\t\ttip: index.getBranchTip(options.branch),\n\t\tgetParent: (entryId) => index.getParent(entryId),\n\t\tselectEntry: (entryId) => index.selectEntry(entryId),\n\t});\n\tif (!index.hasCompleteLane(options.branch)) {\n\t\tthrow new Error(`Source branch ${JSON.stringify(options.branch)} is not a configured AgentLane`);\n\t}\n\treturn plan;\n}\n\ntype JsonlForkWrite = CommittedEntryWrite | CommittedValueSetWrite | CommittedListAppendWrite;\n\nfunction projectJsonlForkWrite(\n\twrite: CommittedWrite,\n\tindex: JsonlForkIndex,\n\tplan: ForkCurrentStatePlan,\n\tisEntryCopied: (entryId: string) => boolean,\n): JsonlForkWrite | undefined {\n\tswitch (write.kind) {\n\t\tcase \"entry\":\n\t\t\treturn isEntryCopied(write.id) ? write : undefined;\n\t\tcase \"value\":\n\t\t\tif (write.op !== \"set\") return undefined;\n\t\t\tif (index.getCurrentScalarSeq(write.namespace, write.key) !== write.seq) return undefined;\n\t\t\treturn projectForkCurrentStateWrite(write, plan, isEntryCopied);\n\t\tcase \"list\":\n\t\t\tif (write.op !== \"append\") return undefined;\n\t\t\tif (!index.isSurvivingListElement(write.namespace, write.key, write.seq)) return undefined;\n\t\t\treturn projectForkCurrentStateWrite(write, plan, isEntryCopied);\n\t\tcase \"usage\":\n\t\t\treturn undefined;\n\t}\n}\n\n/** Prepared fork input: format-4 file metadata or an already-normalized legacy source. */\nexport type JsonlForkInput =\n\t| { kind: \"open\"; metadata: JsonlForkSourceMetadata; nextSeq: number }\n\t| { kind: \"closed\"; metadata: JsonlForkSourceMetadata }\n\t| { kind: \"legacy-v3\"; normalized: LegacyV3Source };\n\n/**\n * Build the index used to select branch ancestry and identify current scalar/list writes.\n * Retains entry parent links, current-row sequences, and lane inventory, not entry payloads.\n * Returns the index and the source's nextSeq high-water mark; no destination writes occur here.\n *\n * V3: LegacyV3Source already scanned the file and assigned normalized IDs/sequences. Copy its\n * in-memory entry structures and derived values without reopening the file or calling writes(),\n * which would unnecessarily parse payloads and reconstruct compaction tails before fork selection.\n *\n * V4: Open the source file and fold complete transactions into the index. For an open source,\n * stop at the captured commit-queue sequence boundary. For a closed source, scan to EOF or a torn\n * final line and derive nextSeq from the header and highest complete write sequence.\n * The later copy pass reopens the source file in both formats and emits only selected writes.\n */\nasync function indexForkInput(\n\tinput: JsonlForkInput,\n\tfileSystem: FileSystem,\n\tcontext: Context,\n): Promise<{ index: JsonlForkIndex; nextSeq: number }> {\n\tconst index = new JsonlForkIndex();\n\tif (input.kind === \"legacy-v3\") {\n\t\tfor (const entry of input.normalized.entryStructures()) index.applyEntry(entry.id, entry.parentId);\n\t\tindex.applyWrites(input.normalized.values);\n\t\treturn { index, nextSeq: input.normalized.nextSeq };\n\t}\n\tconst reader = fileValue(\n\t\tawait fileSystem.openTextLineReader(input.metadata.path, context),\n\t\t`Failed to open JSONL fork source ${input.metadata.path}`,\n\t);\n\ttry {\n\t\tconst header = await readJsonlForkHeader(reader, input.metadata, context);\n\t\tconst stopBeforeSeq = input.kind === \"open\" ? input.nextSeq : undefined;\n\t\tlet highestCompleteSeq = 0;\n\t\tfor await (const writes of readJsonlForkTransactions(reader, input.metadata.path, stopBeforeSeq, context)) {\n\t\t\tindex.applyWrites(writes);\n\t\t\tif (writes.length !== 0) highestCompleteSeq = writes.at(-1)!.seq;\n\t\t}\n\t\treturn {\n\t\t\tindex,\n\t\t\tnextSeq: input.kind === \"open\" ? input.nextSeq : Math.max(header.nextSeq ?? 1, highestCompleteSeq + 1),\n\t\t};\n\t} finally {\n\t\tawait reader.close(context);\n\t}\n}\n\n/** Yield source writes; the caller owns final projection and filtering. */\nasync function* streamForkWrites(\n\tinput: JsonlForkInput,\n\tfileSystem: FileSystem,\n\tstopBeforeSeq: number,\n\tisEntryCopied: (entryId: string) => boolean,\n\tcontext: Context,\n): AsyncIterable<CommittedWrite> {\n\tif (input.kind === \"legacy-v3\") {\n\t\t// V3 filters early to avoid rereading messages and reconstructing unselected compaction tails.\n\t\t// V4 already stores complete payloads, so it streams all captured writes below.\n\t\t// Both formats still pass through projectJsonlForkWrite() for final filtering and transformation.\n\t\tyield* input.normalized.writes(context, isEntryCopied);\n\t\treturn;\n\t}\n\tconst reader = fileValue(\n\t\tawait fileSystem.openTextLineReader(input.metadata.path, context),\n\t\t`Failed to open JSONL fork source ${input.metadata.path}`,\n\t);\n\ttry {\n\t\tawait readJsonlForkHeader(reader, input.metadata, context);\n\t\tfor await (const writes of readJsonlForkTransactions(reader, input.metadata.path, stopBeforeSeq, context)) {\n\t\t\tyield* writes;\n\t\t}\n\t} finally {\n\t\tawait reader.close(context);\n\t}\n}\n\n/**\n * Index the source, validate the requested fork, and stream selected entries and current state\n * into an atomically published format-4 destination without modifying the source.\n * Preserve copied sequences and the source's nextSeq while excluding usage and open-operation state.\n * Source files must not be replaced or edited between passes; later append-only writes are excluded\n * by the captured sequence boundary or legacy record count. Does not open the destination Session.\n */\nexport async function runJsonlFork(\n\toptions: {\n\t\tinput: JsonlForkInput;\n\t\tfileSystem: FileSystem;\n\t\tdestinationPath: string;\n\t\tdestinationHeader: Omit<JsonlStorageHeader, \"nextSeq\">;\n\t\tfork: ForkOptions;\n\t},\n\tcontext: Context,\n): Promise<void> {\n\tconst { index, nextSeq } = await indexForkInput(options.input, options.fileSystem, context);\n\tlet fork = options.fork;\n\tif (options.input.kind === \"legacy-v3\" && fork.scope === \"branch\" && fork.entryId !== undefined) {\n\t\tfork = { ...fork, entryId: options.input.normalized.translateForkEntryId(fork.entryId) };\n\t}\n\tconst plan = selectJsonlFork(index, fork);\n\tconst isEntryCopied = (entryId: string): boolean => {\n\t\tif (plan.scope === \"tree\") return true;\n\t\treturn index.isEntrySelected(entryId);\n\t};\n\tawait publishJsonl(\n\t\toptions.fileSystem,\n\t\toptions.destinationPath,\n\t\t{ ...options.destinationHeader, nextSeq },\n\t\tcontext,\n\t\tasync (append) => {\n\t\t\tconst sourceWrites = streamForkWrites(options.input, options.fileSystem, nextSeq, isEntryCopied, context);\n\t\t\tfor await (const write of sourceWrites) {\n\t\t\t\tconst projected = projectJsonlForkWrite(write, index, plan, isEntryCopied);\n\t\t\t\tif (projected !== undefined) await append([projected]);\n\t\t\t}\n\t\t},\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fork.d.ts","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/fork.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,gBAAgB,CAAC;AAQjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OA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E,CAAC;IAC1F,CAAC;IACD,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1C,MAAM,aAAa,GAAG,CAAC,OAAe,EAAW,EAAE,CAAC;QACnD,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;QACvC,OAAO,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAAA,CACtC,CAAC;IACF,MAAM,YAAY,CACjB,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,eAAe,EACvB,EAAE,GAAG,OAAO,CAAC,iBAAiB,EAAE,OAAO,EAAE,EACzC,OAAO,EACP,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC;QACjB,MAAM,YAAY,GAAG,gBAAgB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;QAC1G,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,YAAY,EAAE,CAAC;YACxC,MAAM,SAAS,GAAG,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;YAC3E,IAAI,SAAS,KAAK,SAAS;gBAAE,MAAM,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QACxD,CAAC;IAAA,CACD,CACD,CAAC;AAAA,CACF","sourcesContent":["import type { Context } from \"../../context.ts\";\nimport type { FileSystem, TextLineReader } from \"../../types.ts\";\nimport type {\n\tCommittedEntryWrite,\n\tCommittedListAppendWrite,\n\tCommittedValueSetWrite,\n\tCommittedWrite,\n} from \"../commit.ts\";\nimport { type ForkCurrentStatePlan, projectForkCurrentStateWrite, selectBranchFork } from \"../fork-policy.ts\";\nimport type { ForkOptions } from \"../types.ts\";\nimport { fileValue, parseJsonlTransaction, publishJsonl, readJsonlHeader } from \"./io.ts\";\nimport type { LegacyV3Source } from \"./legacy-v3.ts\";\nimport { JSONL_STORAGE_VERSION, type JsonlStorageHeader } from \"./types.ts\";\n\ninterface JsonlForkSourceMetadata {\n\tid: string;\n\tcwd: string;\n\tpath: string;\n}\n\nfunction physicalKey(namespace: string, key: string): string {\n\treturn `${namespace}\\u0000${key}`;\n}\n\nasync function readJsonlForkHeader(\n\treader: TextLineReader,\n\tsource: JsonlForkSourceMetadata,\n\tcontext: Context,\n): Promise<JsonlStorageHeader> {\n\tconst parsed = await readJsonlHeader(reader, source.path, context);\n\tif (parsed.format !== \"v4\") {\n\t\tthrow new Error(`Invalid JSONL storage ${source.path}: expected format 4 header`);\n\t}\n\tconst header = parsed.header;\n\tif (header.id !== source.id || header.cwd !== source.cwd) {\n\t\tthrow new Error(`Session identity does not match header: ${source.id}`);\n\t}\n\tif (header.storageVersion !== JSONL_STORAGE_VERSION) {\n\t\tthrow new Error(`Session ${source.id} uses unsupported storage version ${header.storageVersion}`);\n\t}\n\treturn header;\n}\n\nfunction reachesForkBoundary(writes: readonly CommittedWrite[], stopBeforeSeq: number | undefined): boolean {\n\tif (stopBeforeSeq === undefined || writes.length === 0) return false;\n\tconst first = writes[0]!;\n\tconst last = writes.at(-1)!;\n\tif (first.seq >= stopBeforeSeq) return true;\n\tif (last.seq >= stopBeforeSeq) {\n\t\tthrow new Error(`JSONL transaction crosses fork sequence boundary ${stopBeforeSeq}`);\n\t}\n\treturn false;\n}\n\n/** Read complete transactions after the header, never splitting a transaction at the sequence boundary. */\nasync function* readJsonlForkTransactions(\n\treader: TextLineReader,\n\tpath: string,\n\tstopBeforeSeq: number | undefined,\n\tcontext: Context,\n): AsyncIterable<CommittedWrite[]> {\n\twhile (true) {\n\t\tconst line = fileValue(await reader.readLine(context), `Failed to read JSONL fork source ${path}`);\n\t\tif (line === undefined || !line.terminated) break;\n\t\tconst writes = parseJsonlTransaction(line.text);\n\t\tif (reachesForkBoundary(writes, stopBeforeSeq)) break;\n\t\tyield writes;\n\t}\n}\n\nclass JsonlForkIndex {\n\tprivate readonly currentScalarSeqs = new Map<string, number>();\n\tprivate readonly branchTips = new Map<string, string | null>();\n\tprivate readonly firstSurvivingListSeqs = new Map<string, number>();\n\tprivate readonly entryParents = new Map<string, string | null>();\n\tprivate readonly copiedEntryIds = new Set<string>();\n\tprivate readonly laneConfigs = new Set<string>();\n\tprivate readonly laneStates = new Set<string>();\n\n\tapplyEntry(id: string, parentId: string | null): void {\n\t\tthis.entryParents.set(id, parentId);\n\t}\n\n\tapplyWrites(writes: readonly CommittedWrite[]): void {\n\t\tfor (const write of writes) {\n\t\t\tswitch (write.kind) {\n\t\t\t\tcase \"entry\":\n\t\t\t\t\tthis.applyEntry(write.id, write.parentId);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"value\": {\n\t\t\t\t\tconst key = physicalKey(write.namespace, write.key);\n\t\t\t\t\tif (write.op === \"delete\") {\n\t\t\t\t\t\tthis.currentScalarSeqs.delete(key);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.currentScalarSeqs.set(key, write.seq);\n\t\t\t\t\t}\n\t\t\t\t\tthis.applyLaneValue(write);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"list\": {\n\t\t\t\t\tconst key = physicalKey(write.namespace, write.key);\n\t\t\t\t\tif (write.op === \"delete\") this.firstSurvivingListSeqs.delete(key);\n\t\t\t\t\telse if (!this.firstSurvivingListSeqs.has(key)) this.firstSurvivingListSeqs.set(key, write.seq);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"usage\":\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate applyLaneValue(write: Extract<CommittedWrite, { kind: \"value\" }>): void {\n\t\tconst present = write.op === \"set\";\n\t\tswitch (write.namespace) {\n\t\t\tcase \"pi.branch.tip\":\n\t\t\t\tif (present) this.branchTips.set(write.key, write.value as string | null);\n\t\t\t\telse this.branchTips.delete(write.key);\n\t\t\t\tbreak;\n\t\t\tcase \"pi.lane.config\":\n\t\t\t\tif (present) this.laneConfigs.add(write.key);\n\t\t\t\telse this.laneConfigs.delete(write.key);\n\t\t\t\tbreak;\n\t\t\tcase \"pi.lane.state\":\n\t\t\t\tif (present) this.laneStates.add(write.key);\n\t\t\t\telse this.laneStates.delete(write.key);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tgetBranchTip(branch: string): string | null | undefined {\n\t\treturn this.branchTips.get(branch);\n\t}\n\n\thasCompleteLane(branch: string): boolean {\n\t\treturn this.laneConfigs.has(branch) && this.laneStates.has(branch);\n\t}\n\n\tgetCurrentScalarSeq(namespace: string, key: string): number | undefined {\n\t\treturn this.currentScalarSeqs.get(physicalKey(namespace, key));\n\t}\n\n\tisSurvivingListElement(namespace: string, key: string, seq: number): boolean {\n\t\tconst firstSeq = this.firstSurvivingListSeqs.get(physicalKey(namespace, key));\n\t\treturn firstSeq !== undefined && seq >= firstSeq;\n\t}\n\n\tgetParent(entryId: string): string | null | undefined {\n\t\treturn this.entryParents.get(entryId);\n\t}\n\n\tselectEntry(entryId: string): void {\n\t\tthis.copiedEntryIds.add(entryId);\n\t}\n\n\tisEntrySelected(entryId: string): boolean {\n\t\treturn this.copiedEntryIds.has(entryId);\n\t}\n}\n\n/**\n * Validate the source lanes and return the fork plan.\n *\n * Branch scope updates JsonlForkIndex's selected entries via index.selectEntry(): it selects the\n * destination tip and its ancestors after validating entryId and applying \"at\"/\"before\". The plan\n * records the branch name and destination tip; the copy pass uses the index to filter entries and labels.\n *\n * Tree scope leaves the index's selected entries unchanged because the copy pass keeps every entry.\n * Both formats use the same indexed metadata; this function performs no file I/O.\n */\nfunction selectJsonlFork(index: JsonlForkIndex, options: ForkOptions): ForkCurrentStatePlan {\n\tif (options.scope === \"tree\") return { scope: \"tree\" };\n\tconst plan = selectBranchFork(options, {\n\t\ttip: index.getBranchTip(options.branch),\n\t\tgetParent: (entryId) => index.getParent(entryId),\n\t\tselectEntry: (entryId) => index.selectEntry(entryId),\n\t});\n\tif (!index.hasCompleteLane(options.branch)) {\n\t\tthrow new Error(`Source branch ${JSON.stringify(options.branch)} is not a configured AgentLane`);\n\t}\n\treturn plan;\n}\n\ntype JsonlForkWrite = CommittedEntryWrite | CommittedValueSetWrite | CommittedListAppendWrite;\n\nfunction projectJsonlForkWrite(\n\twrite: CommittedWrite,\n\tindex: JsonlForkIndex,\n\tplan: ForkCurrentStatePlan,\n\tisEntryCopied: (entryId: string) => boolean,\n): JsonlForkWrite | undefined {\n\tswitch (write.kind) {\n\t\tcase \"entry\":\n\t\t\treturn isEntryCopied(write.id) ? write : undefined;\n\t\tcase \"value\":\n\t\t\tif (write.op !== \"set\") return undefined;\n\t\t\tif (index.getCurrentScalarSeq(write.namespace, write.key) !== write.seq) return undefined;\n\t\t\treturn projectForkCurrentStateWrite(write, plan, isEntryCopied);\n\t\tcase \"list\":\n\t\t\tif (write.op !== \"append\") return undefined;\n\t\t\tif (!index.isSurvivingListElement(write.namespace, write.key, write.seq)) return undefined;\n\t\t\treturn projectForkCurrentStateWrite(write, plan, isEntryCopied);\n\t\tcase \"usage\":\n\t\t\treturn undefined;\n\t}\n}\n\n/** Prepared fork input: format-4 file metadata or an already-normalized legacy source. */\nexport type JsonlForkInput =\n\t| { kind: \"open\"; metadata: JsonlForkSourceMetadata; nextSeq: number }\n\t| { kind: \"closed\"; metadata: JsonlForkSourceMetadata }\n\t| { kind: \"legacy-v3\"; normalized: LegacyV3Source };\n\n/**\n * Build the index used to select branch ancestry and identify current scalar/list writes.\n * Retains entry parent links, current-row sequences, and lane inventory, not entry payloads.\n * Returns the index and the source's nextSeq high-water mark; no destination writes occur here.\n *\n * V3: LegacyV3Source already scanned the file and assigned normalized IDs/sequences. Copy its\n * in-memory entry structures and derived values without reopening the file or calling writes(),\n * which would unnecessarily parse payloads and reconstruct compaction tails before fork selection.\n *\n * V4: Open the source file and fold complete transactions into the index. For an open source,\n * stop at the captured commit-queue sequence boundary. For a closed source, scan to EOF or a torn\n * final line and derive nextSeq from the header and highest complete write sequence.\n * The later copy pass reopens the source file in both formats and emits only selected writes.\n */\nasync function indexForkInput(\n\tinput: JsonlForkInput,\n\tfileSystem: FileSystem,\n\tcontext: Context,\n): Promise<{ index: JsonlForkIndex; nextSeq: number }> {\n\tconst index = new JsonlForkIndex();\n\tif (input.kind === \"legacy-v3\") {\n\t\tfor (const entry of input.normalized.entryStructures()) index.applyEntry(entry.id, entry.parentId);\n\t\tindex.applyWrites(input.normalized.values);\n\t\treturn { index, nextSeq: input.normalized.nextSeq };\n\t}\n\tconst reader = fileValue(\n\t\tawait fileSystem.openTextLineReader(input.metadata.path, context),\n\t\t`Failed to open JSONL fork source ${input.metadata.path}`,\n\t);\n\ttry {\n\t\tconst header = await readJsonlForkHeader(reader, input.metadata, context);\n\t\tconst stopBeforeSeq = input.kind === \"open\" ? input.nextSeq : undefined;\n\t\tlet highestCompleteSeq = 0;\n\t\tfor await (const writes of readJsonlForkTransactions(reader, input.metadata.path, stopBeforeSeq, context)) {\n\t\t\tindex.applyWrites(writes);\n\t\t\tif (writes.length !== 0) highestCompleteSeq = writes.at(-1)!.seq;\n\t\t}\n\t\treturn {\n\t\t\tindex,\n\t\t\tnextSeq: input.kind === \"open\" ? input.nextSeq : Math.max(header.nextSeq ?? 1, highestCompleteSeq + 1),\n\t\t};\n\t} finally {\n\t\tawait reader.close(context);\n\t}\n}\n\n/** Yield source writes; the caller owns final projection and filtering. */\nasync function* streamForkWrites(\n\tinput: JsonlForkInput,\n\tfileSystem: FileSystem,\n\tstopBeforeSeq: number,\n\tisEntryCopied: (entryId: string) => boolean,\n\tcontext: Context,\n): AsyncIterable<CommittedWrite> {\n\tif (input.kind === \"legacy-v3\") {\n\t\t// V3 filters early to avoid rereading messages and reconstructing unselected compaction tails.\n\t\t// V4 already stores complete payloads, so it streams all captured writes below.\n\t\t// Both formats still pass through projectJsonlForkWrite() for final filtering and transformation.\n\t\tyield* input.normalized.writes(context, isEntryCopied);\n\t\treturn;\n\t}\n\tconst reader = fileValue(\n\t\tawait fileSystem.openTextLineReader(input.metadata.path, context),\n\t\t`Failed to open JSONL fork source ${input.metadata.path}`,\n\t);\n\ttry {\n\t\tawait readJsonlForkHeader(reader, input.metadata, context);\n\t\tfor await (const writes of readJsonlForkTransactions(reader, input.metadata.path, stopBeforeSeq, context)) {\n\t\t\tyield* writes;\n\t\t}\n\t} finally {\n\t\tawait reader.close(context);\n\t}\n}\n\n/**\n * Index the source, validate the requested fork, and stream selected entries and current state\n * into an atomically published format-4 destination without modifying the source.\n * Preserve copied sequences and the source's nextSeq while excluding usage and open-operation state.\n * Source files must not be replaced or edited between passes; later append-only writes are excluded\n * by the captured sequence boundary or legacy record count. Does not open the destination Session.\n */\nexport async function runJsonlFork(\n\toptions: {\n\t\tinput: JsonlForkInput;\n\t\tfileSystem: FileSystem;\n\t\tdestinationPath: string;\n\t\tdestinationHeader: Omit<JsonlStorageHeader, \"nextSeq\">;\n\t\tfork: ForkOptions;\n\t},\n\tcontext: Context,\n): Promise<void> {\n\tconst { index, nextSeq } = await indexForkInput(options.input, options.fileSystem, context);\n\tlet fork = options.fork;\n\tif (options.input.kind === \"legacy-v3\" && fork.scope === \"branch\" && fork.entryId !== undefined) {\n\t\tfork = { ...fork, entryId: options.input.normalized.translateForkEntryId(fork.entryId) };\n\t}\n\tconst plan = selectJsonlFork(index, fork);\n\tconst isEntryCopied = (entryId: string): boolean => {\n\t\tif (plan.scope === \"tree\") return true;\n\t\treturn index.isEntrySelected(entryId);\n\t};\n\tawait publishJsonl(\n\t\toptions.fileSystem,\n\t\toptions.destinationPath,\n\t\t{ ...options.destinationHeader, nextSeq },\n\t\tcontext,\n\t\tasync (append) => {\n\t\t\tconst sourceWrites = streamForkWrites(options.input, options.fileSystem, nextSeq, isEntryCopied, context);\n\t\t\tfor await (const write of sourceWrites) {\n\t\t\t\tconst projected = projectJsonlForkWrite(write, index, plan, isEntryCopied);\n\t\t\t\tif (projected !== undefined) await append([projected]);\n\t\t\t}\n\t\t},\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fork.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AI,KAAK,WAAW,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACjG,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IAC1F,CAAC;IACD,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1C,MAAM,aAAa,GAAG,CAAC,OAAe,EAAW,EAAE;QAClD,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;QACvC,OAAO,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC;IACF,MAAM,YAAY,CACjB,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,eAAe,EACvB,EAAE,GAAG,OAAO,CAAC,iBAAiB,EAAE,OAAO,EAAE,EACzC,OAAO,EACP,KAAK,EAAE,MAAM,EAAE,EAAE;QAChB,MAAM,YAAY,GAAG,gBAAgB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;QAC1G,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,YAAY,EAAE,CAAC;YACxC,MAAM,SAAS,GAAG,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;YAC3E,IAAI,SAAS,KAAK,SAAS;gBAAE,MAAM,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QACxD,CAAC;IACF,CAAC,CACD,CAAC;AACH,CAAC","sourcesContent":["import type { Context } from \"../../context.ts\";\nimport type { FileSystem, TextLineReader } from \"../../types.ts\";\nimport type {\n\tCommittedEntryWrite,\n\tCommittedListAppendWrite,\n\tCommittedValueSetWrite,\n\tCommittedWrite,\n} from \"../commit.ts\";\nimport { type ForkCurrentStatePlan, projectForkCurrentStateWrite, selectBranchFork } from \"../fork-policy.ts\";\nimport type { ForkOptions } from \"../types.ts\";\nimport { fileValue, parseJsonlTransaction, publishJsonl, readJsonlHeader } from \"./io.ts\";\nimport type { LegacyV3Source } from \"./legacy-v3.ts\";\nimport { JSONL_STORAGE_VERSION, type JsonlStorageHeader } from \"./types.ts\";\n\ninterface JsonlForkSourceMetadata {\n\tid: string;\n\tcwd: string;\n\tpath: string;\n}\n\nfunction physicalKey(namespace: string, key: string): string {\n\treturn `${namespace}\\u0000${key}`;\n}\n\nasync function readJsonlForkHeader(\n\treader: TextLineReader,\n\tsource: JsonlForkSourceMetadata,\n\tcontext: Context,\n): Promise<JsonlStorageHeader> {\n\tconst parsed = await readJsonlHeader(reader, source.path, context);\n\tif (parsed.format !== \"v4\") {\n\t\tthrow new Error(`Invalid JSONL storage ${source.path}: expected format 4 header`);\n\t}\n\tconst header = parsed.header;\n\tif (header.id !== source.id || header.cwd !== source.cwd) {\n\t\tthrow new Error(`Session identity does not match header: ${source.id}`);\n\t}\n\tif (header.storageVersion !== JSONL_STORAGE_VERSION) {\n\t\tthrow new Error(`Session ${source.id} uses unsupported storage version ${header.storageVersion}`);\n\t}\n\treturn header;\n}\n\nfunction reachesForkBoundary(writes: readonly CommittedWrite[], stopBeforeSeq: number | undefined): boolean {\n\tif (stopBeforeSeq === undefined || writes.length === 0) return false;\n\tconst first = writes[0]!;\n\tconst last = writes.at(-1)!;\n\tif (first.seq >= stopBeforeSeq) return true;\n\tif (last.seq >= stopBeforeSeq) {\n\t\tthrow new Error(`JSONL transaction crosses fork sequence boundary ${stopBeforeSeq}`);\n\t}\n\treturn false;\n}\n\n/** Read complete transactions after the header, never splitting a transaction at the sequence boundary. */\nasync function* readJsonlForkTransactions(\n\treader: TextLineReader,\n\tpath: string,\n\tstopBeforeSeq: number | undefined,\n\tcontext: Context,\n): AsyncIterable<CommittedWrite[]> {\n\twhile (true) {\n\t\tconst line = fileValue(await reader.readLine(context), `Failed to read JSONL fork source ${path}`);\n\t\tif (line === undefined || !line.terminated) break;\n\t\tconst writes = parseJsonlTransaction(line.text);\n\t\tif (reachesForkBoundary(writes, stopBeforeSeq)) break;\n\t\tyield writes;\n\t}\n}\n\nclass JsonlForkIndex {\n\tprivate readonly currentScalarSeqs = new Map<string, number>();\n\tprivate readonly branchTips = new Map<string, string | null>();\n\tprivate readonly firstSurvivingListSeqs = new Map<string, number>();\n\tprivate readonly entryParents = new Map<string, string | null>();\n\tprivate readonly copiedEntryIds = new Set<string>();\n\tprivate readonly laneConfigs = new Set<string>();\n\tprivate readonly laneStates = new Set<string>();\n\n\tapplyEntry(id: string, parentId: string | null): void {\n\t\tthis.entryParents.set(id, parentId);\n\t}\n\n\tapplyWrites(writes: readonly CommittedWrite[]): void {\n\t\tfor (const write of writes) {\n\t\t\tswitch (write.kind) {\n\t\t\t\tcase \"entry\":\n\t\t\t\t\tthis.applyEntry(write.id, write.parentId);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"value\": {\n\t\t\t\t\tconst key = physicalKey(write.namespace, write.key);\n\t\t\t\t\tif (write.op === \"delete\") {\n\t\t\t\t\t\tthis.currentScalarSeqs.delete(key);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.currentScalarSeqs.set(key, write.seq);\n\t\t\t\t\t}\n\t\t\t\t\tthis.applyLaneValue(write);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"list\": {\n\t\t\t\t\tconst key = physicalKey(write.namespace, write.key);\n\t\t\t\t\tif (write.op === \"delete\") this.firstSurvivingListSeqs.delete(key);\n\t\t\t\t\telse if (!this.firstSurvivingListSeqs.has(key)) this.firstSurvivingListSeqs.set(key, write.seq);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"usage\":\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate applyLaneValue(write: Extract<CommittedWrite, { kind: \"value\" }>): void {\n\t\tconst present = write.op === \"set\";\n\t\tswitch (write.namespace) {\n\t\t\tcase \"pi.branch.tip\":\n\t\t\t\tif (present) this.branchTips.set(write.key, write.value as string | null);\n\t\t\t\telse this.branchTips.delete(write.key);\n\t\t\t\tbreak;\n\t\t\tcase \"pi.lane.config\":\n\t\t\t\tif (present) this.laneConfigs.add(write.key);\n\t\t\t\telse this.laneConfigs.delete(write.key);\n\t\t\t\tbreak;\n\t\t\tcase \"pi.lane.state\":\n\t\t\t\tif (present) this.laneStates.add(write.key);\n\t\t\t\telse this.laneStates.delete(write.key);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tgetBranchTip(branch: string): string | null | undefined {\n\t\treturn this.branchTips.get(branch);\n\t}\n\n\thasCompleteLane(branch: string): boolean {\n\t\treturn this.laneConfigs.has(branch) && this.laneStates.has(branch);\n\t}\n\n\tgetCurrentScalarSeq(namespace: string, key: string): number | undefined {\n\t\treturn this.currentScalarSeqs.get(physicalKey(namespace, key));\n\t}\n\n\tisSurvivingListElement(namespace: string, key: string, seq: number): boolean {\n\t\tconst firstSeq = this.firstSurvivingListSeqs.get(physicalKey(namespace, key));\n\t\treturn firstSeq !== undefined && seq >= firstSeq;\n\t}\n\n\tgetParent(entryId: string): string | null | undefined {\n\t\treturn this.entryParents.get(entryId);\n\t}\n\n\tselectEntry(entryId: string): void {\n\t\tthis.copiedEntryIds.add(entryId);\n\t}\n\n\tisEntrySelected(entryId: string): boolean {\n\t\treturn this.copiedEntryIds.has(entryId);\n\t}\n}\n\n/**\n * Validate the source lanes and return the fork plan.\n *\n * Branch scope updates JsonlForkIndex's selected entries via index.selectEntry(): it selects the\n * destination tip and its ancestors after validating entryId and applying \"at\"/\"before\". The plan\n * records the branch name and destination tip; the copy pass uses the index to filter entries and labels.\n *\n * Tree scope leaves the index's selected entries unchanged because the copy pass keeps every entry.\n * Both formats use the same indexed metadata; this function performs no file I/O.\n */\nfunction selectJsonlFork(index: JsonlForkIndex, options: ForkOptions): ForkCurrentStatePlan {\n\tif (options.scope === \"tree\") return { scope: \"tree\" };\n\tconst plan = selectBranchFork(options, {\n\t\ttip: index.getBranchTip(options.branch),\n\t\tgetParent: (entryId) => index.getParent(entryId),\n\t\tselectEntry: (entryId) => index.selectEntry(entryId),\n\t});\n\tif (!index.hasCompleteLane(options.branch)) {\n\t\tthrow new Error(`Source branch ${JSON.stringify(options.branch)} is not a configured AgentLane`);\n\t}\n\treturn plan;\n}\n\ntype JsonlForkWrite = CommittedEntryWrite | CommittedValueSetWrite | CommittedListAppendWrite;\n\nfunction projectJsonlForkWrite(\n\twrite: CommittedWrite,\n\tindex: JsonlForkIndex,\n\tplan: ForkCurrentStatePlan,\n\tisEntryCopied: (entryId: string) => boolean,\n): JsonlForkWrite | undefined {\n\tswitch (write.kind) {\n\t\tcase \"entry\":\n\t\t\treturn isEntryCopied(write.id) ? write : undefined;\n\t\tcase \"value\":\n\t\t\tif (write.op !== \"set\") return undefined;\n\t\t\tif (index.getCurrentScalarSeq(write.namespace, write.key) !== write.seq) return undefined;\n\t\t\treturn projectForkCurrentStateWrite(write, plan, isEntryCopied);\n\t\tcase \"list\":\n\t\t\tif (write.op !== \"append\") return undefined;\n\t\t\tif (!index.isSurvivingListElement(write.namespace, write.key, write.seq)) return undefined;\n\t\t\treturn projectForkCurrentStateWrite(write, plan, isEntryCopied);\n\t\tcase \"usage\":\n\t\t\treturn undefined;\n\t}\n}\n\n/** Prepared fork input: format-4 file metadata or an already-normalized legacy source. */\nexport type JsonlForkInput =\n\t| { kind: \"open\"; metadata: JsonlForkSourceMetadata; nextSeq: number }\n\t| { kind: \"closed\"; metadata: JsonlForkSourceMetadata }\n\t| { kind: \"legacy-v3\"; normalized: LegacyV3Source };\n\n/**\n * Build the index used to select branch ancestry and identify current scalar/list writes.\n * Retains entry parent links, current-row sequences, and lane inventory, not entry payloads.\n * Returns the index and the source's nextSeq high-water mark; no destination writes occur here.\n *\n * V3: LegacyV3Source already scanned the file and assigned normalized IDs/sequences. Copy its\n * in-memory entry structures and derived values without reopening the file or calling writes(),\n * which would unnecessarily parse payloads and reconstruct compaction tails before fork selection.\n *\n * V4: Open the source file and fold complete transactions into the index. For an open source,\n * stop at the captured commit-queue sequence boundary. For a closed source, scan to EOF or a torn\n * final line and derive nextSeq from the header and highest complete write sequence.\n * The later copy pass reopens the source file in both formats and emits only selected writes.\n */\nasync function indexForkInput(\n\tinput: JsonlForkInput,\n\tfileSystem: FileSystem,\n\tcontext: Context,\n): Promise<{ index: JsonlForkIndex; nextSeq: number }> {\n\tconst index = new JsonlForkIndex();\n\tif (input.kind === \"legacy-v3\") {\n\t\tfor (const entry of input.normalized.entryStructures()) index.applyEntry(entry.id, entry.parentId);\n\t\tindex.applyWrites(input.normalized.values);\n\t\treturn { index, nextSeq: input.normalized.nextSeq };\n\t}\n\tconst reader = fileValue(\n\t\tawait fileSystem.openTextLineReader(input.metadata.path, context),\n\t\t`Failed to open JSONL fork source ${input.metadata.path}`,\n\t);\n\ttry {\n\t\tconst header = await readJsonlForkHeader(reader, input.metadata, context);\n\t\tconst stopBeforeSeq = input.kind === \"open\" ? input.nextSeq : undefined;\n\t\tlet highestCompleteSeq = 0;\n\t\tfor await (const writes of readJsonlForkTransactions(reader, input.metadata.path, stopBeforeSeq, context)) {\n\t\t\tindex.applyWrites(writes);\n\t\t\tif (writes.length !== 0) highestCompleteSeq = writes.at(-1)!.seq;\n\t\t}\n\t\treturn {\n\t\t\tindex,\n\t\t\tnextSeq: input.kind === \"open\" ? input.nextSeq : Math.max(header.nextSeq ?? 1, highestCompleteSeq + 1),\n\t\t};\n\t} finally {\n\t\tawait reader.close(context);\n\t}\n}\n\n/** Yield source writes; the caller owns final projection and filtering. */\nasync function* streamForkWrites(\n\tinput: JsonlForkInput,\n\tfileSystem: FileSystem,\n\tstopBeforeSeq: number,\n\tisEntryCopied: (entryId: string) => boolean,\n\tcontext: Context,\n): AsyncIterable<CommittedWrite> {\n\tif (input.kind === \"legacy-v3\") {\n\t\t// V3 filters early to avoid rereading messages and reconstructing unselected compaction tails.\n\t\t// V4 already stores complete payloads, so it streams all captured writes below.\n\t\t// Both formats still pass through projectJsonlForkWrite() for final filtering and transformation.\n\t\tyield* input.normalized.writes(context, isEntryCopied);\n\t\treturn;\n\t}\n\tconst reader = fileValue(\n\t\tawait fileSystem.openTextLineReader(input.metadata.path, context),\n\t\t`Failed to open JSONL fork source ${input.metadata.path}`,\n\t);\n\ttry {\n\t\tawait readJsonlForkHeader(reader, input.metadata, context);\n\t\tfor await (const writes of readJsonlForkTransactions(reader, input.metadata.path, stopBeforeSeq, context)) {\n\t\t\tyield* writes;\n\t\t}\n\t} finally {\n\t\tawait reader.close(context);\n\t}\n}\n\n/**\n * Index the source, validate the requested fork, and stream selected entries and current state\n * into an atomically published format-4 destination without modifying the source.\n * Preserve copied sequences and the source's nextSeq while excluding usage and open-operation state.\n * Source files must not be replaced or edited between passes; later append-only writes are excluded\n * by the captured sequence boundary or legacy record count. Does not open the destination Session.\n */\nexport async function runJsonlFork(\n\toptions: {\n\t\tinput: JsonlForkInput;\n\t\tfileSystem: FileSystem;\n\t\tdestinationPath: string;\n\t\tdestinationHeader: Omit<JsonlStorageHeader, \"nextSeq\">;\n\t\tfork: ForkOptions;\n\t},\n\tcontext: Context,\n): Promise<void> {\n\tconst { index, nextSeq } = await indexForkInput(options.input, options.fileSystem, context);\n\tlet fork = options.fork;\n\tif (options.input.kind === \"legacy-v3\" && fork.scope === \"branch\" && fork.entryId !== undefined) {\n\t\tfork = { ...fork, entryId: options.input.normalized.translateForkEntryId(fork.entryId) };\n\t}\n\tconst plan = selectJsonlFork(index, fork);\n\tconst isEntryCopied = (entryId: string): boolean => {\n\t\tif (plan.scope === \"tree\") return true;\n\t\treturn index.isEntrySelected(entryId);\n\t};\n\tawait publishJsonl(\n\t\toptions.fileSystem,\n\t\toptions.destinationPath,\n\t\t{ ...options.destinationHeader, nextSeq },\n\t\tcontext,\n\t\tasync (append) => {\n\t\t\tconst sourceWrites = streamForkWrites(options.input, options.fileSystem, nextSeq, isEntryCopied, context);\n\t\t\tfor await (const write of sourceWrites) {\n\t\t\t\tconst projected = projectJsonlForkWrite(write, index, plan, isEntryCopied);\n\t\t\t\tif (projected !== undefined) await append([projected]);\n\t\t\t}\n\t\t},\n\t);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/io.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,KAAK,EAOX,cAAc,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,wBAAwB,EAA2B,MAAM,YAAY,CAAC;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,CAG5E;AAED,wBAAsB,eAAe,CACpC,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,wBAAwB,CAAC,CAUnC;AA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AAM,GAAG,CAAC,CAG5E;AAED,wBAAsB,eAAe,CACpC,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,wBAAwB,CAAC,CAUnC;AAgCD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE,CAQpE;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,CAEnF;AAED,4FAA4F;AAC5F,wBAAsB,qBAAqB,CAC1C,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GACzE,OAAO,CAAC,IAAI,CAAC,CAkBf;AAED,qFAAqF;AACrF,wBAAsB,YAAY,CACjC,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,kBAAkB,EAC1B,OAAO,EAAE,OAAO,EAChB,iBAAiB,EAAE,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAChG,OAAO,CAAC,IAAI,CAAC,CAKf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/io.ts"],"names":[],"mappings":"AAWA,OAAO,EAAiC,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGpF,MAAM,UAAU,SAAS,CAAI,MAA4B,EAAE,MAAc
|
|
1
|
+
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/io.ts"],"names":[],"mappings":"AAWA,OAAO,EAAiC,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGpF,M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AAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;QAC5D,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC;AAED,qFAAqF;AACrF,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,UAAsB,EACtB,eAAuB,EACvB,MAA0B,EAC1B,OAAgB,EAChB,iBAAkG;IAElG,MAAM,qBAAqB,CAAC,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QAClF,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,iBAAiB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,yBAAyB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IACvF,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Context } from \"../../context.ts\";\nimport type { FileError, FileSystem, Result, TextLineReader } from \"../../types.ts\";\nimport type {\n\tCommittedEntryWrite,\n\tCommittedListAppendWrite,\n\tCommittedListDeleteWrite,\n\tCommittedUsageWrite,\n\tCommittedValueDeleteWrite,\n\tCommittedValueSetWrite,\n\tCommittedWrite,\n} from \"../commit.ts\";\nimport { type JsonlParsedSessionHeader, parseJsonlSessionHeader } from \"./codec.ts\";\nimport type { JsonlStorageHeader } from \"./types.ts\";\n\nexport function fileValue<T>(result: Result<T, FileError>, action: string): T {\n\tif (!result.ok) throw new Error(`${action}: ${result.error.message}`, { cause: result.error });\n\treturn result.value;\n}\n\nexport async function readJsonlHeader(\n\treader: TextLineReader,\n\tpath: string,\n\tcontext: Context,\n): Promise<JsonlParsedSessionHeader> {\n\tconst line = fileValue(await reader.readLine(context), `Failed to read JSONL storage ${path}`);\n\tif (line === undefined || !line.terminated || line.text === \"\") {\n\t\tthrow new Error(`Invalid JSONL storage ${path}: missing header`);\n\t}\n\tconst parsed = parseJsonlSessionHeader(line.text);\n\tif (!parsed.ok) {\n\t\tthrow new Error(`Invalid JSONL storage ${path}: invalid header`, { cause: parsed.error });\n\t}\n\treturn parsed.value;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction requireSafeInteger(value: unknown, field: string, minimum: number): void {\n\tif (!Number.isSafeInteger(value) || (value as number) < minimum) throw new Error(`Invalid JSONL ${field}`);\n}\n\nfunction parseCommittedWrite(value: unknown): CommittedWrite {\n\tif (!isRecord(value)) throw new Error(\"Invalid JSONL transaction write\");\n\trequireSafeInteger(value.seq, \"write seq\", 1);\n\tswitch (value.kind) {\n\t\tcase \"entry\":\n\t\t\trequireSafeInteger(value.timestamp, \"entry timestamp\", 0);\n\t\t\treturn value as unknown as CommittedEntryWrite;\n\t\tcase \"usage\":\n\t\t\treturn value as unknown as CommittedUsageWrite;\n\t\tcase \"value\":\n\t\t\tif (value.op === \"set\") return value as unknown as CommittedValueSetWrite;\n\t\t\tif (value.op === \"delete\") return value as unknown as CommittedValueDeleteWrite;\n\t\t\tthrow new Error(`Invalid JSONL value operation: ${String(value.op)}`);\n\t\tcase \"list\":\n\t\t\tif (value.op === \"append\") return value as unknown as CommittedListAppendWrite;\n\t\t\tif (value.op === \"delete\") return value as unknown as CommittedListDeleteWrite;\n\t\t\tthrow new Error(`Invalid JSONL list operation: ${String(value.op)}`);\n\t\tdefault:\n\t\t\tthrow new Error(`Invalid JSONL write kind: ${String(value.kind)}`);\n\t}\n}\n\nexport function parseJsonlTransaction(line: string): CommittedWrite[] {\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(line);\n\t} catch (error) {\n\t\tthrow new Error(\"Invalid JSONL transaction: not valid JSON\", { cause: error });\n\t}\n\treturn (Array.isArray(value) ? value : [value]).map(parseCommittedWrite);\n}\n\nexport function serializeJsonlTransaction(writes: readonly CommittedWrite[]): string {\n\treturn JSON.stringify(writes.length === 1 ? writes[0] : writes);\n}\n\n/** Publish only after the callback succeeds; it must await each append before returning. */\nexport async function publishFileAtomically(\n\tfileSystem: FileSystem,\n\tdestinationPath: string,\n\tcontext: Context,\n\twriteContent: (append: (content: string) => Promise<void>) => Promise<void>,\n): Promise<void> {\n\tconst tempPath = `${destinationPath}.tmp`;\n\ttry {\n\t\tfileValue(await fileSystem.writeFile(tempPath, \"\", context), `Failed to stage JSONL storage ${destinationPath}`);\n\t\tawait writeContent(async (content) => {\n\t\t\tfileValue(\n\t\t\t\tawait fileSystem.appendFile(tempPath, content, context),\n\t\t\t\t`Failed to append JSONL storage ${destinationPath}`,\n\t\t\t);\n\t\t});\n\t\tfileValue(\n\t\t\tawait fileSystem.renameFile(tempPath, destinationPath, context),\n\t\t\t`Failed to publish JSONL storage ${destinationPath}`,\n\t\t);\n\t} catch (error) {\n\t\tawait fileSystem.remove(tempPath, { force: true }, context);\n\t\tthrow error;\n\t}\n}\n\n/** Stream a header and complete transactions through the shared atomic publisher. */\nexport async function publishJsonl(\n\tfileSystem: FileSystem,\n\tdestinationPath: string,\n\theader: JsonlStorageHeader,\n\tcontext: Context,\n\twriteTransactions: (append: (writes: readonly CommittedWrite[]) => Promise<void>) => Promise<void>,\n): Promise<void> {\n\tawait publishFileAtomically(fileSystem, destinationPath, context, async (append) => {\n\t\tawait append(`${JSON.stringify(header)}\\n`);\n\t\tawait writeTransactions((writes) => append(`${serializeJsonlTransaction(writes)}\\n`));\n\t});\n}\n"]}
|
|
@@ -37,6 +37,7 @@ export declare class LegacyV3Source {
|
|
|
37
37
|
* Each pass owns its reader and message cache, sharing only the captured IDs and metadata.
|
|
38
38
|
*/
|
|
39
39
|
writes(context: Context, isEntrySelected?: (id: string) => boolean): AsyncIterable<CommittedEntryWrite | CommittedValueSetWrite>;
|
|
40
|
+
/** Replay only the captured prefix and verify its physical identities before materialization. */
|
|
40
41
|
private readCapturedEntries;
|
|
41
42
|
}
|
|
42
43
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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,OAAO,eAiBN;IAED;;;;;OAKG;IACH,OAAa,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAwBjG;IAEA,eAAe,IAAI,QAAQ,CAAC,IAAI,CAAC,mBAAmB,EAAE,IAAI,GAAG,UAAU,GAAG,KAAK,CAAC,CAAC,CAKjF;IAED,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAK7C;IAED,OAAO,CAAC,6BAA6B;IAgBrC;;;OAGG;IACI,MAAM,CACZ,OAAO,EAAE,OAAO,EAChB,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,GACvC,aAAa,CAAC,mBAAmB,GAAG,sBAAsB,CAAC,CAsB7D;YAGc,mBAAmB;CA8BlC","sourcesContent":["import type { ImageContent, TextContent, Usage } from \"@earendil-works/pi-ai\";\nimport { uuidv7 } from \"@earendil-works/pi-ai/utils/uuid\";\nimport type { AgentMessage, ThinkingLevel } from \"../../../types.ts\";\nimport type { Context } from \"../../context.ts\";\nimport { createBranchSummaryMessage, createCompactionSummaryMessage } from \"../../messages.ts\";\nimport type { FileSystem, TextLineReader } from \"../../types.ts\";\nimport { addUsage, emptyUsage } from \"../../utils/usage.ts\";\nimport type { CommittedEntryWrite, CommittedValueSetWrite } from \"../commit.ts\";\nimport type { JsonValue, LaneConfiguration } from \"../types.ts\";\nimport { branchTip, entryLabel, laneConfig, laneState, sessionName, setValue } from \"../values.ts\";\nimport { type LegacyV3SessionHeader, parseJsonlSessionHeader } from \"./codec.ts\";\nimport { fileValue, readJsonlHeader } from \"./io.ts\";\nimport {\n\tJSONL_FORMAT_VERSION,\n\tJSONL_STORAGE_VERSION,\n\ttype JsonlSessionMetadata,\n\ttype JsonlStorageHeader,\n} from \"./types.ts\";\n\ninterface LegacyV3EntryBase {\n\ttype: string;\n\tid: string;\n\tparentId: string | null;\n\ttimestamp: string;\n}\n\ninterface LegacyV3MessageEntry extends LegacyV3EntryBase {\n\ttype: \"message\";\n\tmessage: AgentMessage;\n}\n\ninterface LegacyV3CustomEntry extends LegacyV3EntryBase {\n\ttype: \"custom\";\n\tcustomType: string;\n\tdata?: JsonValue;\n}\n\ninterface LegacyV3CustomMessageEntry extends LegacyV3EntryBase {\n\ttype: \"custom_message\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdetails?: unknown;\n\tdisplay: boolean;\n}\n\ninterface LegacyV3BranchSummaryEntry extends LegacyV3EntryBase {\n\ttype: \"branch_summary\";\n\tfromId: string;\n\tsummary: string;\n\tdetails?: JsonValue;\n\tusage?: Usage;\n\tfromHook?: boolean;\n}\n\ninterface LegacyV3CompactionEntry extends LegacyV3EntryBase {\n\ttype: \"compaction\";\n\tsummary: string;\n\tfirstKeptEntryId: string;\n\ttokensBefore: number;\n\tdetails?: JsonValue;\n\tusage?: Usage;\n\tfromHook?: boolean;\n}\n\ninterface LegacyV3ModelChangeEntry extends LegacyV3EntryBase {\n\ttype: \"model_change\";\n\tprovider: string;\n\tmodelId: string;\n}\n\ninterface LegacyV3ThinkingLevelChangeEntry extends LegacyV3EntryBase {\n\ttype: \"thinking_level_change\";\n\tthinkingLevel: ThinkingLevel;\n}\n\ninterface LegacyV3ActiveToolsChangeEntry extends LegacyV3EntryBase {\n\ttype: \"active_tools_change\";\n\tactiveToolNames: string[];\n}\n\ninterface LegacyV3SessionInfoEntry extends LegacyV3EntryBase {\n\ttype: \"session_info\";\n\tname?: string;\n}\n\ninterface LegacyV3LabelEntry extends LegacyV3EntryBase {\n\ttype: \"label\";\n\ttargetId: string;\n\tlabel?: string;\n}\n\ninterface ImportedCustomMessage {\n\trole: \"custom\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdetails?: unknown;\n\tdisplay: boolean;\n\ttimestamp: number;\n}\n\ntype RetainedLegacyV3Entry =\n\t| LegacyV3MessageEntry\n\t| LegacyV3CustomEntry\n\t| LegacyV3CustomMessageEntry\n\t| LegacyV3BranchSummaryEntry\n\t| LegacyV3CompactionEntry;\n\ntype DiscardedLegacyV3Entry =\n\t| LegacyV3ModelChangeEntry\n\t| LegacyV3ThinkingLevelChangeEntry\n\t| LegacyV3ActiveToolsChangeEntry\n\t| LegacyV3SessionInfoEntry\n\t| LegacyV3LabelEntry;\n\ntype LegacyV3Entry = RetainedLegacyV3Entry | DiscardedLegacyV3Entry;\n\ninterface LegacyV3IndexBase {\n\tid: string;\n\tparentId: string | null;\n\t/** This node's new ID, or its parent's mapped ID when the node is discarded. */\n\tmappedId: string | null;\n}\n\ntype RetainedLegacyV3IndexEntry = LegacyV3IndexBase & { mappedId: string; seq: number } & (\n\t\t| { type: \"message\" | \"custom\" | \"custom_message\" }\n\t\t| { type: \"branch_summary\"; fromId: string }\n\t\t| { type: \"compaction\"; firstKeptEntryId: string }\n\t);\n\n/** Keep structure, labels, and configuration changes, but not conversation payloads. */\ntype LegacyV3IndexEntry =\n\t| RetainedLegacyV3IndexEntry\n\t| (LegacyV3IndexBase &\n\t\t\t(\n\t\t\t\t| Pick<LegacyV3LabelEntry, \"type\" | \"targetId\" | \"label\">\n\t\t\t\t| Pick<LegacyV3ModelChangeEntry, \"type\" | \"provider\" | \"modelId\">\n\t\t\t\t| Pick<LegacyV3ThinkingLevelChangeEntry, \"type\" | \"thinkingLevel\">\n\t\t\t\t| Pick<LegacyV3ActiveToolsChangeEntry, \"type\" | \"activeToolNames\">\n\t\t\t\t| { type: \"session_info\" }\n\t\t\t));\n\ntype LegacyV3CompactionIndexEntry = Extract<RetainedLegacyV3IndexEntry, { type: \"compaction\" }>;\n\ninterface LegacyV3Inventory {\n\tentries: ReadonlyMap<string, LegacyV3IndexEntry>;\n\timportedUsage: Usage;\n\tname: string | undefined;\n\tfinalId: string | null;\n\tnextSeq: number;\n}\n\ntype JsonlSessionMetadataBase = Omit<JsonlSessionMetadata, \"path\" | \"modifiedAt\">;\n\nasync function resolveLegacyV3ParentSessionId(\n\tfileSystem: FileSystem,\n\tparentSessionPath: string,\n\tcontext: Context,\n): Promise<string | undefined> {\n\tconst lines = await fileSystem.readTextLines(parentSessionPath, { maxLines: 1 }, context);\n\tif (!lines.ok || lines.value[0] === undefined) return undefined;\n\tconst parsed = parseJsonlSessionHeader(lines.value[0]);\n\treturn parsed.ok ? parsed.value.header.id : undefined;\n}\n\nexport async function metadataFromLegacyV3Header(\n\tfileSystem: FileSystem,\n\theader: LegacyV3SessionHeader,\n\tcontext: Context,\n): Promise<JsonlSessionMetadataBase> {\n\tconst metadata: JsonlSessionMetadataBase = {\n\t\tid: header.id,\n\t\tcreatedAt: Date.parse(header.timestamp),\n\t\tstorageVersion: JSONL_STORAGE_VERSION,\n\t\tcwd: header.cwd,\n\t};\n\tif (header.parentSession !== undefined) {\n\t\tconst parentSessionId = await resolveLegacyV3ParentSessionId(fileSystem, header.parentSession, context);\n\t\tif (parentSessionId !== undefined) metadata.parentSessionId = parentSessionId;\n\t\telse metadata.legacyParentSessionPath = header.parentSession;\n\t}\n\treturn metadata;\n}\n\nexport async function normalizeLegacyV3Header(\n\tfileSystem: FileSystem,\n\theader: LegacyV3SessionHeader,\n\tcontext: Context,\n): Promise<JsonlStorageHeader> {\n\treturn {\n\t\tv: JSONL_FORMAT_VERSION,\n\t\tkind: \"header\",\n\t\t...(await metadataFromLegacyV3Header(fileSystem, header, context)),\n\t};\n}\n\nfunction parseLegacyV3Entry(line: string): LegacyV3Entry {\n\tlet entry: LegacyV3Entry;\n\ttry {\n\t\tentry = JSON.parse(line) as LegacyV3Entry;\n\t} catch (error) {\n\t\tthrow new Error(\"Invalid legacy v3 JSONL record: not valid JSON\", { cause: error });\n\t}\n\tconst recordType: unknown = entry?.type;\n\tif (\n\t\trecordType !== \"message\" &&\n\t\trecordType !== \"custom\" &&\n\t\trecordType !== \"custom_message\" &&\n\t\trecordType !== \"branch_summary\" &&\n\t\trecordType !== \"compaction\" &&\n\t\trecordType !== \"model_change\" &&\n\t\trecordType !== \"thinking_level_change\" &&\n\t\trecordType !== \"active_tools_change\" &&\n\t\trecordType !== \"session_info\" &&\n\t\trecordType !== \"label\"\n\t) {\n\t\tthrow new Error(`Unsupported legacy v3 record type: ${String(recordType)}`);\n\t}\n\treturn entry;\n}\n\nfunction importedCustomMessage(entry: LegacyV3CustomMessageEntry): AgentMessage {\n\tconst message: ImportedCustomMessage = {\n\t\trole: \"custom\",\n\t\tcustomType: entry.customType,\n\t\tcontent: entry.content,\n\t\tdetails: entry.details,\n\t\tdisplay: entry.display,\n\t\ttimestamp: Date.parse(entry.timestamp),\n\t};\n\t// The coding-agent CustomAgentMessages declaration merge is not visible in this package.\n\treturn message as unknown as AgentMessage;\n}\n\nfunction isRetainedEntry<T extends LegacyV3Entry | LegacyV3IndexEntry>(\n\tentry: T,\n): entry is Extract<T, { type: RetainedLegacyV3Entry[\"type\"] }> {\n\treturn (\n\t\tentry.type !== \"model_change\" &&\n\t\tentry.type !== \"thinking_level_change\" &&\n\t\tentry.type !== \"active_tools_change\" &&\n\t\tentry.type !== \"session_info\" &&\n\t\tentry.type !== \"label\"\n\t);\n}\n\n/**\n * Resolve a legacy ID to its imported ID. Discarded records resolve to the minted ID of their\n * nearest retained ancestor.\n */\ntype ResolveLegacyId = (legacyId: string | null) => string | null;\n\n/** Parent mappings are already folded during the scan; later references need only a lookup. */\nfunction createLegacyIdResolver(entries: ReadonlyMap<string, LegacyV3IndexEntry>): ResolveLegacyId {\n\treturn (legacyId) => {\n\t\tif (legacyId === null) return null;\n\t\tconst mappedId = entries.get(legacyId)?.mappedId;\n\t\tif (mappedId === undefined) throw new Error(`Missing legacy v3 entry reference: ${legacyId}`);\n\t\treturn mappedId;\n\t};\n}\n\nfunction resolveBranchSummaryFromId(resolveLegacyId: ResolveLegacyId, legacyFromId: string): string | null {\n\t// Legacy branchWithSummary() encoded a root source as the \"root\" sentinel instead of null.\n\treturn legacyFromId === \"root\" ? null : resolveLegacyId(legacyFromId);\n}\n\nfunction projectContextMessage(entry: LegacyV3Entry, resolveLegacyId: ResolveLegacyId): AgentMessage | undefined {\n\tswitch (entry.type) {\n\t\tcase \"message\":\n\t\t\treturn entry.message;\n\t\tcase \"custom_message\":\n\t\t\treturn importedCustomMessage(entry);\n\t\tcase \"branch_summary\":\n\t\t\treturn entry.summary\n\t\t\t\t? createBranchSummaryMessage(\n\t\t\t\t\t\tentry.summary,\n\t\t\t\t\t\tresolveBranchSummaryFromId(resolveLegacyId, entry.fromId),\n\t\t\t\t\t\tentry.timestamp,\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\tcase \"compaction\":\n\t\t\treturn createCompactionSummaryMessage(entry.summary, entry.tokensBefore, entry.timestamp);\n\t\tcase \"custom\":\n\t\tcase \"model_change\":\n\t\tcase \"thinking_level_change\":\n\t\tcase \"active_tools_change\":\n\t\tcase \"session_info\":\n\t\tcase \"label\":\n\t\t\treturn undefined;\n\t}\n}\n\n/** Walk physical ancestry, including discarded nodes and the exact kept boundary. */\nfunction* retainedTailStructure(\n\tcompaction: LegacyV3CompactionIndexEntry,\n\tentriesById: ReadonlyMap<string, LegacyV3IndexEntry>,\n): Iterable<LegacyV3IndexEntry> {\n\tlet currentId = compaction.parentId;\n\twhile (currentId !== null) {\n\t\t// The scan guarantees that every parent exists earlier in the file, so cycles are impossible.\n\t\tconst entry = entriesById.get(currentId)!;\n\t\tyield entry;\n\t\tif (currentId === compaction.firstKeptEntryId) return;\n\t\tcurrentId = entry.parentId;\n\t}\n\tthrow new Error(\n\t\t`Legacy v3 compaction ${compaction.id} firstKeptEntryId is not on its parent branch: ${compaction.firstKeptEntryId}`,\n\t);\n}\n\nfunction normalizeRetainedEntry(\n\tentry: RetainedLegacyV3Entry,\n\tindexed: RetainedLegacyV3IndexEntry,\n\tretainedTail: AgentMessage[],\n\tresolveLegacyId: ResolveLegacyId,\n): CommittedEntryWrite {\n\tconst committedBase = {\n\t\tkind: \"entry\" as const,\n\t\tid: indexed.mappedId,\n\t\tparentId: resolveLegacyId(indexed.parentId),\n\t\tseq: indexed.seq,\n\t\ttimestamp: Date.parse(entry.timestamp),\n\t};\n\tif (entry.type === \"message\") {\n\t\treturn { ...committedBase, type: \"message\", message: entry.message };\n\t}\n\tif (entry.type === \"custom_message\") {\n\t\treturn {\n\t\t\t...committedBase,\n\t\t\ttype: \"message\",\n\t\t\tmessage: importedCustomMessage(entry),\n\t\t};\n\t}\n\tif (entry.type === \"branch_summary\") {\n\t\treturn {\n\t\t\t...committedBase,\n\t\t\ttype: \"branch_summary\",\n\t\t\tfromId: resolveBranchSummaryFromId(resolveLegacyId, entry.fromId),\n\t\t\tsummary: entry.summary,\n\t\t\tdetails: entry.details,\n\t\t\tusage: entry.usage,\n\t\t\tfromHook: entry.fromHook ?? false,\n\t\t};\n\t}\n\tif (entry.type === \"compaction\") {\n\t\treturn {\n\t\t\t...committedBase,\n\t\t\ttype: \"compaction\",\n\t\t\tsummary: entry.summary,\n\t\t\tretainedTail,\n\t\t\ttokensBefore: entry.tokensBefore,\n\t\t\tdetails: entry.details,\n\t\t\tusage: entry.usage,\n\t\t\tfromHook: entry.fromHook ?? false,\n\t\t};\n\t}\n\treturn {\n\t\t...committedBase,\n\t\ttype: \"custom\",\n\t\tcustomType: entry.customType,\n\t\tdata: entry.data,\n\t};\n}\n\nfunction selectedConfiguration(\n\tentriesById: ReadonlyMap<string, LegacyV3IndexEntry>,\n\tselectedId: string | null,\n): LaneConfiguration | undefined {\n\tconst remaining = new Set<LegacyV3IndexEntry[\"type\"]>([\n\t\t\"model_change\",\n\t\t\"thinking_level_change\",\n\t\t\"active_tools_change\",\n\t]);\n\tlet model: LaneConfiguration[\"model\"] | undefined;\n\tlet thinkingLevel: ThinkingLevel | undefined;\n\tlet activeToolNames: string[] | undefined;\n\tlet currentId = selectedId;\n\twhile (currentId !== null && remaining.size !== 0) {\n\t\tconst entry = entriesById.get(currentId)!;\n\t\t// Consume the nearest change even when invalid: older values must not become fallbacks.\n\t\tif (remaining.delete(entry.type)) {\n\t\t\tswitch (entry.type) {\n\t\t\t\tcase \"model_change\":\n\t\t\t\t\tmodel = { provider: entry.provider, modelId: entry.modelId };\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"thinking_level_change\":\n\t\t\t\t\tthinkingLevel = entry.thinkingLevel;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"active_tools_change\":\n\t\t\t\t\tactiveToolNames = [...entry.activeToolNames];\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tcurrentId = entry.parentId;\n\t}\n\tif (model === undefined || thinkingLevel === undefined) return undefined;\n\treturn { model, thinkingLevel, activeToolNames: activeToolNames ?? [] };\n}\n\nfunction indexLegacyV3Entry(\n\tentry: LegacyV3Entry,\n\tlineNumber: number,\n\tseq: number,\n\tentries: ReadonlyMap<string, LegacyV3IndexEntry>,\n): LegacyV3IndexEntry {\n\t// SessionManager appends after an existing leaf and writes extracted branches in parent order.\n\tconst mappedParentId = entry.parentId === null ? null : entries.get(entry.parentId)?.mappedId;\n\tif (mappedParentId === undefined) {\n\t\tthrow new Error(\n\t\t\t`Legacy v3 entry ${entry.id} has a missing or forward parent at line ${lineNumber}: ${entry.parentId}`,\n\t\t);\n\t}\n\tconst structure: LegacyV3IndexBase = {\n\t\tid: entry.id,\n\t\tparentId: entry.parentId,\n\t\tmappedId: mappedParentId,\n\t};\n\tif (!isRetainedEntry(entry)) {\n\t\tswitch (entry.type) {\n\t\t\tcase \"label\":\n\t\t\t\treturn { ...structure, type: entry.type, targetId: entry.targetId, label: entry.label };\n\t\t\tcase \"model_change\":\n\t\t\t\treturn { ...structure, type: entry.type, provider: entry.provider, modelId: entry.modelId };\n\t\t\tcase \"thinking_level_change\":\n\t\t\t\treturn { ...structure, type: entry.type, thinkingLevel: entry.thinkingLevel };\n\t\t\tcase \"active_tools_change\":\n\t\t\t\treturn { ...structure, type: entry.type, activeToolNames: entry.activeToolNames };\n\t\t\tcase \"session_info\":\n\t\t\t\treturn { ...structure, type: entry.type };\n\t\t}\n\t}\n\t// Null denotes the root, not a retained node identity that can be reminted.\n\tif (entry.id === null) throw new Error(\"Legacy v3 entry reference has no retained ancestor: null\");\n\tconst retained = {\n\t\t...structure,\n\t\tmappedId: uuidv7(Date.parse(entry.timestamp)),\n\t\tseq,\n\t};\n\tswitch (entry.type) {\n\t\tcase \"branch_summary\":\n\t\t\treturn { ...retained, type: entry.type, fromId: entry.fromId };\n\t\tcase \"compaction\":\n\t\t\treturn { ...retained, type: entry.type, firstKeptEntryId: entry.firstKeptEntryId };\n\t\tdefault:\n\t\t\treturn { ...retained, type: entry.type };\n\t}\n}\n\nfunction legacyEntryUsage(entry: LegacyV3Entry): Usage | undefined {\n\tswitch (entry.type) {\n\t\tcase \"message\":\n\t\t\treturn entry.message.role === \"assistant\" || entry.message.role === \"toolResult\"\n\t\t\t\t? entry.message.usage\n\t\t\t\t: undefined;\n\t\tcase \"compaction\":\n\t\tcase \"branch_summary\":\n\t\t\treturn entry.usage;\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nasync function readLegacyV3Inventory(reader: TextLineReader, context: Context): Promise<LegacyV3Inventory> {\n\tconst entries = new Map<string, LegacyV3IndexEntry>();\n\tlet nextSeq = 1;\n\tlet importedUsage = emptyUsage();\n\tlet name: string | undefined;\n\tlet finalId: string | null = null;\n\twhile (true) {\n\t\tconst line = fileValue(await reader.readLine(context), \"Failed to read legacy v3 source\");\n\t\tif (line === undefined || !line.terminated) break;\n\t\tconst lineNumber = entries.size + 2;\n\t\tconst entry = parseLegacyV3Entry(line.text);\n\t\tif (entries.has(entry.id)) throw new Error(`Duplicate legacy v3 entry id: ${entry.id}`);\n\t\tconst indexed = indexLegacyV3Entry(entry, lineNumber, nextSeq, entries);\n\t\tentries.set(entry.id, indexed);\n\t\tif (isRetainedEntry(indexed)) nextSeq++;\n\t\tfinalId = entry.id;\n\t\tif (entry.type === \"session_info\") name = entry.name;\n\t\tconst usage = legacyEntryUsage(entry);\n\t\tif (usage !== undefined) importedUsage = addUsage(importedUsage, usage);\n\t}\n\treturn { entries, nextSeq, importedUsage, name, finalId };\n}\n\nfunction normalizeLegacyV3Values(inventory: LegacyV3Inventory): CommittedValueSetWrite[] {\n\tconst { entries, name, finalId } = inventory;\n\tconst resolveLegacyId = createLegacyIdResolver(entries);\n\tlet nextSeq = inventory.nextSeq;\n\tconst values: CommittedValueSetWrite[] = [];\n\n\t// session name\n\tif (name) values.push({ ...setValue(sessionName, name), seq: nextSeq++ });\n\n\t// labels\n\tconst labels = new Map<string, string>();\n\tfor (const entry of entries.values()) {\n\t\tif (entry.type !== \"label\") continue;\n\t\tconst targetId = resolveLegacyId(entry.targetId);\n\t\tif (targetId === null) continue;\n\t\tif (entry.label) labels.set(targetId, entry.label);\n\t\telse labels.delete(targetId);\n\t}\n\tfor (const [targetId, label] of labels) {\n\t\tvalues.push({ ...setValue(entryLabel(targetId), label), seq: nextSeq++ });\n\t}\n\n\t// branch tip\n\tvalues.push({ ...setValue(branchTip(\"main\"), resolveLegacyId(finalId)), seq: nextSeq++ });\n\n\t// configuration\n\tconst configuration = selectedConfiguration(entries, finalId);\n\tif (configuration !== undefined) {\n\t\tvalues.push({ ...setValue(laneConfig(\"main\"), configuration), seq: nextSeq++ });\n\t\tvalues.push({\n\t\t\t...setValue(laneState(\"main\"), { currentOperationId: null, lastOperationId: null, inbox: [] }),\n\t\t\tseq: nextSeq++,\n\t\t});\n\t}\n\treturn values;\n}\n\n/**\n * A captured legacy file exposed as repeatable logical v4 writes.\n * Each pass reopens the path; callers must not replace or edit the source between passes.\n * Structural indexes, label/configuration metadata, and derived current values survive between scans.\n */\nexport class LegacyV3Source {\n\treadonly header: JsonlStorageHeader;\n\treadonly importedUsage: Usage;\n\treadonly nextSeq: number;\n\treadonly values: readonly CommittedValueSetWrite[];\n\tprivate readonly fileSystem: FileSystem;\n\tprivate readonly path: string;\n\tprivate readonly entries: ReadonlyMap<string, LegacyV3IndexEntry>;\n\tprivate readonly resolveLegacyId: ResolveLegacyId;\n\n\tprivate constructor(\n\t\tfileSystem: FileSystem,\n\t\tpath: string,\n\t\theader: JsonlStorageHeader,\n\t\tentries: ReadonlyMap<string, LegacyV3IndexEntry>,\n\t\timportedUsage: Usage,\n\t\tvalues: readonly CommittedValueSetWrite[],\n\t\tnextSeq: number,\n\t) {\n\t\tthis.fileSystem = fileSystem;\n\t\tthis.path = path;\n\t\tthis.header = header;\n\t\tthis.entries = entries;\n\t\tthis.resolveLegacyId = createLegacyIdResolver(entries);\n\t\tthis.importedUsage = importedUsage;\n\t\tthis.values = values;\n\t\tthis.nextSeq = nextSeq;\n\t}\n\n\t/**\n\t * Scan complete v3 records without modifying the file, ignoring an unterminated final line.\n\t * Build parent mappings, assign IDs stable for this source instance, and derive current values\n\t * and imported usage. Retain metadata, not conversation payloads or an open reader. writes()\n\t * reopens the path to materialize captured records and resolve their payload-specific references.\n\t */\n\tstatic async read(fileSystem: FileSystem, path: string, context: Context): Promise<LegacyV3Source> {\n\t\tconst reader = fileValue(\n\t\t\tawait fileSystem.openTextLineReader(path, context),\n\t\t\t`Failed to open legacy v3 source ${path}`,\n\t\t);\n\t\ttry {\n\t\t\tconst parsed = await readJsonlHeader(reader, path, context);\n\t\t\tif (parsed.format !== \"v3-legacy\") {\n\t\t\t\tthrow new Error(`Invalid legacy v3 JSONL storage ${path}: expected format 3 header`);\n\t\t\t}\n\t\t\tconst inventory = await readLegacyV3Inventory(reader, context);\n\t\t\tconst values = normalizeLegacyV3Values(inventory);\n\t\t\treturn new LegacyV3Source(\n\t\t\t\tfileSystem,\n\t\t\t\tpath,\n\t\t\t\tawait normalizeLegacyV3Header(fileSystem, parsed.header, context),\n\t\t\t\tinventory.entries,\n\t\t\t\tinventory.importedUsage,\n\t\t\t\tvalues,\n\t\t\t\tinventory.nextSeq + values.length,\n\t\t\t);\n\t\t} finally {\n\t\t\tawait reader.close(context);\n\t\t}\n\t}\n\n\t*entryStructures(): Iterable<Pick<CommittedEntryWrite, \"id\" | \"parentId\" | \"seq\">> {\n\t\tfor (const entry of this.entries.values()) {\n\t\t\tif (!isRetainedEntry(entry)) continue;\n\t\t\tyield { id: entry.mappedId, parentId: this.resolveLegacyId(entry.parentId), seq: entry.seq };\n\t\t}\n\t}\n\n\ttranslateForkEntryId(legacyId: string): string {\n\t\tconst entry = this.entries.get(legacyId);\n\t\tif (entry === undefined) throw new Error(`Legacy v3 fork entry does not exist: ${legacyId}`);\n\t\tif (!isRetainedEntry(entry)) throw new Error(`Legacy v3 fork entry is not a retained entry: ${legacyId}`);\n\t\treturn entry.mappedId;\n\t}\n\n\tprivate collectRequiredTailMessageIds(isEntrySelected?: (id: string) => boolean): Set<string> {\n\t\tconst requiredIds = new Set<string>();\n\t\tfor (const entry of this.entries.values()) {\n\t\t\tif (entry.type !== \"compaction\") continue;\n\t\t\tconst compactionIsSelected = isEntrySelected === undefined || isEntrySelected(entry.mappedId);\n\t\t\tif (!compactionIsSelected) continue;\n\n\t\t\t// Walk from the compaction's parent through firstKeptEntryId, inclusive.\n\t\t\tfor (const tailEntry of retainedTailStructure(entry, this.entries)) {\n\t\t\t\tconst canProduceContextMessage = isRetainedEntry(tailEntry) && tailEntry.type !== \"custom\";\n\t\t\t\tif (canProduceContextMessage) requiredIds.add(tailEntry.id);\n\t\t\t}\n\t\t}\n\t\treturn requiredIds;\n\t}\n\n\t/**\n\t * Stream normalized v4 entries, optionally filtered by reminted ID, followed by derived current values.\n\t * Each pass owns its reader and message cache, sharing only the captured IDs and metadata.\n\t */\n\tasync *writes(\n\t\tcontext: Context,\n\t\tisEntrySelected?: (id: string) => boolean,\n\t): AsyncIterable<CommittedEntryWrite | CommittedValueSetWrite> {\n\t\tconst requiredTailMessageIds = this.collectRequiredTailMessageIds(isEntrySelected);\n\t\t// Keep needed context messages for this entire pass; tails may revisit old or shared branches.\n\t\tconst tailMessagesByLegacyId = new Map<string, AgentMessage>();\n\t\tfor await (const { entry, indexed } of this.readCapturedEntries(context)) {\n\t\t\tif (requiredTailMessageIds.has(entry.id)) {\n\t\t\t\tconst message = projectContextMessage(entry, this.resolveLegacyId);\n\t\t\t\tif (message !== undefined) tailMessagesByLegacyId.set(entry.id, message);\n\t\t\t}\n\t\t\tif (!isRetainedEntry(indexed) || !isRetainedEntry(entry)) continue;\n\t\t\tif (isEntrySelected !== undefined && !isEntrySelected(indexed.mappedId)) continue;\n\t\t\tconst retainedTail: AgentMessage[] = [];\n\t\t\tif (indexed.type === \"compaction\") {\n\t\t\t\tfor (const ancestor of retainedTailStructure(indexed, this.entries)) {\n\t\t\t\t\tconst message = tailMessagesByLegacyId.get(ancestor.id);\n\t\t\t\t\tif (message !== undefined) retainedTail.push(message);\n\t\t\t\t}\n\t\t\t\tretainedTail.reverse();\n\t\t\t}\n\t\t\tyield normalizeRetainedEntry(entry, indexed, retainedTail, this.resolveLegacyId);\n\t\t}\n\t\tyield* this.values;\n\t}\n\n\t/** Replay only the captured prefix and verify its physical identities before materialization. */\n\tprivate async *readCapturedEntries(\n\t\tcontext: Context,\n\t): AsyncIterable<{ entry: LegacyV3Entry; indexed: LegacyV3IndexEntry }> {\n\t\tconst reader = fileValue(\n\t\t\tawait this.fileSystem.openTextLineReader(this.path, context),\n\t\t\t`Failed to reopen legacy v3 source ${this.path}`,\n\t\t);\n\t\ttry {\n\t\t\tconst parsed = await readJsonlHeader(reader, this.path, context);\n\t\t\tif (\n\t\t\t\tparsed.format !== \"v3-legacy\" ||\n\t\t\t\tparsed.header.id !== this.header.id ||\n\t\t\t\tparsed.header.cwd !== this.header.cwd\n\t\t\t) {\n\t\t\t\tthrow new Error(\"Legacy v3 source header changed\");\n\t\t\t}\n\t\t\tfor (const indexed of this.entries.values()) {\n\t\t\t\tconst line = fileValue(await reader.readLine(context), \"Failed to reread legacy v3 source\");\n\t\t\t\tif (line === undefined || !line.terminated)\n\t\t\t\t\tthrow new Error(\"Legacy v3 source ended before captured entries\");\n\t\t\t\tconst entry = parseLegacyV3Entry(line.text);\n\t\t\t\tif (entry.id !== indexed.id || entry.type !== indexed.type) {\n\t\t\t\t\tthrow new Error(\"Legacy v3 source changed\");\n\t\t\t\t}\n\t\t\t\tyield { entry, indexed };\n\t\t\t}\n\t\t} finally {\n\t\t\tawait reader.close(context);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"legacy-v3.d.ts","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/legacy-v3.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA6B,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAG9E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,gBAAgB,CAAC;AAEjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAGhF,OAAO,EAAE,KAAK,qBAAqB,EAA2B,MAAM,YAAY,CAAC;AAEjF,OAAO,EAGN,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,MAAM,YAAY,CAAC;AAsIpB,KAAK,wBAAwB,GAAG,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC;AAalF,wBAAsB,0BAA0B,CAC/C,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,qBAAqB,EAC7B,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,wBAAwB,CAAC,CAanC;AAED,wBAAsB,uBAAuB,CAC5C,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,qBAAqB,EAC7B,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,kBAAkB,CAAC,CAM7B;AAyUD;;;;GAIG;AACH,qBAAa,cAAc;IAC1B,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS,sBAAsB,EAAE,CAAC;IACnD,OA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