@earendil-works/pi-agent-core 0.84.3 → 0.85.0
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.map +1 -1
- package/dist/agent-loop.js +32 -25
- package/dist/agent-loop.js.map +1 -1
- package/dist/harness/agent-harness.d.ts +639 -384
- package/dist/harness/agent-harness.d.ts.map +1 -1
- package/dist/harness/agent-harness.js +5 -251
- package/dist/harness/agent-harness.js.map +1 -1
- package/dist/harness/compaction/branch-summarization.d.ts +12 -6
- package/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/harness/compaction/branch-summarization.js +33 -26
- package/dist/harness/compaction/branch-summarization.js.map +1 -1
- package/dist/harness/compaction/compaction.d.ts +30 -8
- package/dist/harness/compaction/compaction.d.ts.map +1 -1
- package/dist/harness/compaction/compaction.js +53 -63
- package/dist/harness/compaction/compaction.js.map +1 -1
- package/dist/harness/config.d.ts +9 -0
- package/dist/harness/config.d.ts.map +1 -0
- package/dist/harness/config.js +27 -0
- package/dist/harness/config.js.map +1 -0
- package/dist/harness/context.d.ts +9 -0
- package/dist/harness/context.d.ts.map +1 -0
- package/dist/harness/context.js +13 -0
- package/dist/harness/context.js.map +1 -0
- package/dist/harness/env/nodejs.d.ts +24 -28
- package/dist/harness/env/nodejs.d.ts.map +1 -1
- package/dist/harness/env/nodejs.js +242 -87
- package/dist/harness/env/nodejs.js.map +1 -1
- package/dist/harness/events.d.ts +20 -38
- package/dist/harness/events.d.ts.map +1 -1
- package/dist/harness/events.js +240 -55
- package/dist/harness/events.js.map +1 -1
- package/dist/harness/execution/assistant.d.ts +42 -0
- package/dist/harness/execution/assistant.d.ts.map +1 -0
- package/dist/harness/execution/assistant.js +82 -0
- package/dist/harness/execution/assistant.js.map +1 -0
- package/dist/harness/execution/effect-gate.d.ts +22 -0
- package/dist/harness/execution/effect-gate.d.ts.map +1 -0
- package/dist/harness/execution/effect-gate.js +49 -0
- package/dist/harness/execution/effect-gate.js.map +1 -0
- package/dist/harness/execution/tools.d.ts +67 -0
- package/dist/harness/execution/tools.d.ts.map +1 -0
- package/dist/harness/execution/tools.js +121 -0
- package/dist/harness/execution/tools.js.map +1 -0
- package/dist/harness/hooks.d.ts +38 -0
- package/dist/harness/hooks.d.ts.map +1 -0
- package/dist/harness/hooks.js +406 -0
- package/dist/harness/hooks.js.map +1 -0
- package/dist/harness/messages.d.ts +2 -2
- package/dist/harness/messages.d.ts.map +1 -1
- package/dist/harness/messages.js.map +1 -1
- package/dist/harness/prompt-templates.d.ts +3 -2
- package/dist/harness/prompt-templates.d.ts.map +1 -1
- package/dist/harness/prompt-templates.js +17 -17
- package/dist/harness/prompt-templates.js.map +1 -1
- package/dist/harness/result.d.ts +93 -0
- package/dist/harness/result.d.ts.map +1 -1
- package/dist/harness/result.js +40 -0
- package/dist/harness/result.js.map +1 -1
- package/dist/harness/runtime/drive/boundary.d.ts +28 -0
- package/dist/harness/runtime/drive/boundary.d.ts.map +1 -0
- package/dist/harness/runtime/drive/boundary.js +170 -0
- package/dist/harness/runtime/drive/boundary.js.map +1 -0
- package/dist/harness/runtime/drive/checkpoint.d.ts +8 -0
- package/dist/harness/runtime/drive/checkpoint.d.ts.map +1 -0
- package/dist/harness/runtime/drive/checkpoint.js +133 -0
- package/dist/harness/runtime/drive/checkpoint.js.map +1 -0
- package/dist/harness/runtime/drive/deferred.d.ts +15 -0
- package/dist/harness/runtime/drive/deferred.d.ts.map +1 -0
- package/dist/harness/runtime/drive/deferred.js +179 -0
- package/dist/harness/runtime/drive/deferred.js.map +1 -0
- package/dist/harness/runtime/drive/generation.d.ts +8 -0
- package/dist/harness/runtime/drive/generation.d.ts.map +1 -0
- package/dist/harness/runtime/drive/generation.js +205 -0
- package/dist/harness/runtime/drive/generation.js.map +1 -0
- package/dist/harness/runtime/drive/reconcile.d.ts +5 -0
- package/dist/harness/runtime/drive/reconcile.d.ts.map +1 -0
- package/dist/harness/runtime/drive/reconcile.js +140 -0
- package/dist/harness/runtime/drive/reconcile.js.map +1 -0
- package/dist/harness/runtime/drive/recovery.d.ts +8 -0
- package/dist/harness/runtime/drive/recovery.d.ts.map +1 -0
- package/dist/harness/runtime/drive/recovery.js +85 -0
- package/dist/harness/runtime/drive/recovery.js.map +1 -0
- package/dist/harness/runtime/drive/response.d.ts +23 -0
- package/dist/harness/runtime/drive/response.d.ts.map +1 -0
- package/dist/harness/runtime/drive/response.js +394 -0
- package/dist/harness/runtime/drive/response.js.map +1 -0
- package/dist/harness/runtime/drive/retry.d.ts +4 -0
- package/dist/harness/runtime/drive/retry.d.ts.map +1 -0
- package/dist/harness/runtime/drive/retry.js +37 -0
- package/dist/harness/runtime/drive/retry.js.map +1 -0
- package/dist/harness/runtime/drive/structural.d.ts +32 -0
- package/dist/harness/runtime/drive/structural.d.ts.map +1 -0
- package/dist/harness/runtime/drive/structural.js +929 -0
- package/dist/harness/runtime/drive/structural.js.map +1 -0
- package/dist/harness/runtime/drive/terminal.d.ts +7 -0
- package/dist/harness/runtime/drive/terminal.d.ts.map +1 -0
- package/dist/harness/runtime/drive/terminal.js +49 -0
- package/dist/harness/runtime/drive/terminal.js.map +1 -0
- package/dist/harness/runtime/drive/tool-placement.d.ts +14 -0
- package/dist/harness/runtime/drive/tool-placement.d.ts.map +1 -0
- package/dist/harness/runtime/drive/tool-placement.js +244 -0
- package/dist/harness/runtime/drive/tool-placement.js.map +1 -0
- package/dist/harness/runtime/drive/tools.d.ts +6 -0
- package/dist/harness/runtime/drive/tools.d.ts.map +1 -0
- package/dist/harness/runtime/drive/tools.js +449 -0
- package/dist/harness/runtime/drive/tools.js.map +1 -0
- package/dist/harness/runtime/drive.d.ts +6 -0
- package/dist/harness/runtime/drive.d.ts.map +1 -0
- package/dist/harness/runtime/drive.js +93 -0
- package/dist/harness/runtime/drive.js.map +1 -0
- package/dist/harness/runtime/harness.d.ts +59 -0
- package/dist/harness/runtime/harness.d.ts.map +1 -0
- package/dist/harness/runtime/harness.js +311 -0
- package/dist/harness/runtime/harness.js.map +1 -0
- package/dist/harness/runtime/index.d.ts +2 -0
- package/dist/harness/runtime/index.d.ts.map +1 -0
- package/dist/harness/runtime/index.js +2 -0
- package/dist/harness/runtime/index.js.map +1 -0
- package/dist/harness/runtime/lane.d.ts +101 -0
- package/dist/harness/runtime/lane.d.ts.map +1 -0
- package/dist/harness/runtime/lane.js +1575 -0
- package/dist/harness/runtime/lane.js.map +1 -0
- package/dist/harness/runtime/progress.d.ts +15 -0
- package/dist/harness/runtime/progress.d.ts.map +1 -0
- package/dist/harness/runtime/progress.js +66 -0
- package/dist/harness/runtime/progress.js.map +1 -0
- package/dist/harness/runtime/reducer.d.ts +5 -0
- package/dist/harness/runtime/reducer.d.ts.map +1 -0
- package/dist/harness/runtime/reducer.js +240 -0
- package/dist/harness/runtime/reducer.js.map +1 -0
- package/dist/harness/runtime/restore.d.ts +24 -0
- package/dist/harness/runtime/restore.d.ts.map +1 -0
- package/dist/harness/runtime/restore.js +117 -0
- package/dist/harness/runtime/restore.js.map +1 -0
- package/dist/harness/runtime/transcript.d.ts +21 -0
- package/dist/harness/runtime/transcript.d.ts.map +1 -0
- package/dist/harness/runtime/transcript.js +72 -0
- package/dist/harness/runtime/transcript.js.map +1 -0
- package/dist/harness/runtime/types.d.ts +105 -0
- package/dist/harness/runtime/types.d.ts.map +1 -0
- package/dist/harness/runtime/types.js +61 -0
- package/dist/harness/runtime/types.js.map +1 -0
- package/dist/harness/session/commit.d.ts +53 -0
- package/dist/harness/session/commit.d.ts.map +1 -0
- package/dist/harness/session/commit.js +57 -0
- package/dist/harness/session/commit.js.map +1 -0
- package/dist/harness/session/context.d.ts +6 -18
- package/dist/harness/session/context.d.ts.map +1 -1
- package/dist/harness/session/context.js +31 -49
- package/dist/harness/session/context.js.map +1 -1
- package/dist/harness/session/fork-policy.d.ts +13 -0
- package/dist/harness/session/fork-policy.d.ts.map +1 -0
- package/dist/harness/session/fork-policy.js +22 -0
- package/dist/harness/session/fork-policy.js.map +1 -0
- package/dist/harness/session/fork.d.ts +18 -0
- package/dist/harness/session/fork.d.ts.map +1 -0
- package/dist/harness/session/fork.js +127 -0
- package/dist/harness/session/fork.js.map +1 -0
- package/dist/harness/session/in-memory-storage-state.d.ts +39 -0
- package/dist/harness/session/in-memory-storage-state.d.ts.map +1 -0
- package/dist/harness/session/in-memory-storage-state.js +216 -0
- package/dist/harness/session/in-memory-storage-state.js.map +1 -0
- package/dist/harness/session/index.d.ts +9 -5
- package/dist/harness/session/index.d.ts.map +1 -1
- package/dist/harness/session/index.js +7 -4
- package/dist/harness/session/index.js.map +1 -1
- package/dist/harness/session/jsonl/codec.d.ts +19 -8
- package/dist/harness/session/jsonl/codec.d.ts.map +1 -1
- package/dist/harness/session/jsonl/codec.js +34 -218
- package/dist/harness/session/jsonl/codec.js.map +1 -1
- package/dist/harness/session/jsonl/index.d.ts +4 -0
- package/dist/harness/session/jsonl/index.d.ts.map +1 -0
- package/dist/harness/session/jsonl/index.js +4 -0
- package/dist/harness/session/jsonl/index.js.map +1 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts +18 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts.map +1 -0
- package/dist/harness/session/jsonl/legacy-v3.js +383 -0
- package/dist/harness/session/jsonl/legacy-v3.js.map +1 -0
- package/dist/harness/session/jsonl/repo.d.ts +26 -19
- package/dist/harness/session/jsonl/repo.d.ts.map +1 -1
- package/dist/harness/session/jsonl/repo.js +266 -156
- package/dist/harness/session/jsonl/repo.js.map +1 -1
- package/dist/harness/session/jsonl/storage.d.ts +39 -41
- package/dist/harness/session/jsonl/storage.d.ts.map +1 -1
- package/dist/harness/session/jsonl/storage.js +238 -181
- package/dist/harness/session/jsonl/storage.js.map +1 -1
- package/dist/harness/session/jsonl/types.d.ts +23 -22
- package/dist/harness/session/jsonl/types.d.ts.map +1 -1
- package/dist/harness/session/jsonl/types.js +2 -1
- package/dist/harness/session/jsonl/types.js.map +1 -1
- package/dist/harness/session/memory.d.ts +46 -40
- package/dist/harness/session/memory.d.ts.map +1 -1
- package/dist/harness/session/memory.js +346 -113
- package/dist/harness/session/memory.js.map +1 -1
- package/dist/harness/session/mutation-line.d.ts +8 -0
- package/dist/harness/session/mutation-line.d.ts.map +1 -0
- package/dist/harness/session/mutation-line.js +21 -0
- package/dist/harness/session/mutation-line.js.map +1 -0
- package/dist/harness/session/session.d.ts +78 -46
- package/dist/harness/session/session.d.ts.map +1 -1
- package/dist/harness/session/session.js +343 -209
- package/dist/harness/session/session.js.map +1 -1
- package/dist/harness/session/testing/benchmark/datasets.d.ts +12 -0
- package/dist/harness/session/testing/benchmark/datasets.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/datasets.js +24 -0
- package/dist/harness/session/testing/benchmark/datasets.js.map +1 -0
- package/dist/harness/session/testing/benchmark/session-repo.d.ts +42 -0
- package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/session-repo.js +127 -0
- package/dist/harness/session/testing/benchmark/session-repo.js.map +1 -0
- package/dist/harness/session/testing/benchmark/storage.d.ts +25 -0
- package/dist/harness/session/testing/benchmark/storage.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/storage.js +114 -0
- package/dist/harness/session/testing/benchmark/storage.js.map +1 -0
- package/dist/harness/session/testing/conformance/session-repo.d.ts +21 -0
- package/dist/harness/session/testing/conformance/session-repo.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance/session-repo.js +590 -0
- package/dist/harness/session/testing/conformance/session-repo.js.map +1 -0
- package/dist/harness/session/testing/conformance/storage.d.ts +4 -0
- package/dist/harness/session/testing/conformance/storage.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance/storage.js +600 -0
- package/dist/harness/session/testing/conformance/storage.js.map +1 -0
- package/dist/harness/session/testing/gating-storage.d.ts +26 -0
- package/dist/harness/session/testing/gating-storage.d.ts.map +1 -0
- package/dist/harness/session/testing/gating-storage.js +100 -0
- package/dist/harness/session/testing/gating-storage.js.map +1 -0
- package/dist/harness/session/testing/index.d.ts +9 -2
- package/dist/harness/session/testing/index.d.ts.map +1 -1
- package/dist/harness/session/testing/index.js +8 -1
- package/dist/harness/session/testing/index.js.map +1 -1
- package/dist/harness/session/testing/instrumented-storage.d.ts +11 -0
- package/dist/harness/session/testing/instrumented-storage.d.ts.map +1 -0
- package/dist/harness/session/testing/instrumented-storage.js +16 -0
- package/dist/harness/session/testing/instrumented-storage.js.map +1 -0
- package/dist/harness/session/testing/storage-decorator.d.ts +20 -0
- package/dist/harness/session/testing/storage-decorator.d.ts.map +1 -0
- package/dist/harness/session/testing/storage-decorator.js +41 -0
- package/dist/harness/session/testing/storage-decorator.js.map +1 -0
- package/dist/harness/session/testing/types.d.ts +5 -7
- package/dist/harness/session/testing/types.d.ts.map +1 -1
- package/dist/harness/session/testing/types.js.map +1 -1
- package/dist/harness/session/types.d.ts +424 -259
- package/dist/harness/session/types.d.ts.map +1 -1
- package/dist/harness/session/types.js +7 -8
- package/dist/harness/session/types.js.map +1 -1
- package/dist/harness/session/values.d.ts +95 -0
- package/dist/harness/session/values.d.ts.map +1 -0
- package/dist/harness/session/values.js +81 -0
- package/dist/harness/session/values.js.map +1 -0
- package/dist/harness/skills.d.ts +3 -2
- package/dist/harness/skills.d.ts.map +1 -1
- package/dist/harness/skills.js +29 -26
- package/dist/harness/skills.js.map +1 -1
- package/dist/harness/telemetry.d.ts +64 -43
- package/dist/harness/telemetry.d.ts.map +1 -1
- package/dist/harness/telemetry.js +45 -26
- package/dist/harness/telemetry.js.map +1 -1
- package/dist/harness/tools/bash.d.ts +4 -4
- package/dist/harness/tools/bash.d.ts.map +1 -1
- package/dist/harness/tools/bash.js +66 -93
- package/dist/harness/tools/bash.js.map +1 -1
- package/dist/harness/tools/edit.d.ts.map +1 -1
- package/dist/harness/tools/edit.js +10 -10
- package/dist/harness/tools/edit.js.map +1 -1
- package/dist/harness/tools/file-mutation-queue.d.ts +2 -1
- package/dist/harness/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/harness/tools/file-mutation-queue.js +5 -5
- package/dist/harness/tools/file-mutation-queue.js.map +1 -1
- package/dist/harness/tools/path-utils.d.ts +3 -2
- package/dist/harness/tools/path-utils.d.ts.map +1 -1
- package/dist/harness/tools/path-utils.js +5 -5
- package/dist/harness/tools/path-utils.js.map +1 -1
- package/dist/harness/tools/read.d.ts +2 -1
- package/dist/harness/tools/read.d.ts.map +1 -1
- package/dist/harness/tools/read.js +4 -6
- package/dist/harness/tools/read.js.map +1 -1
- package/dist/harness/tools/write.d.ts.map +1 -1
- package/dist/harness/tools/write.js +7 -7
- package/dist/harness/tools/write.js.map +1 -1
- package/dist/harness/types.d.ts +108 -45
- 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 +24 -0
- package/dist/harness/utils/adaptive-publisher.d.ts.map +1 -0
- package/dist/harness/utils/adaptive-publisher.js +79 -0
- package/dist/harness/utils/adaptive-publisher.js.map +1 -0
- package/dist/harness/utils/output-capture.d.ts +31 -0
- package/dist/harness/utils/output-capture.d.ts.map +1 -0
- package/dist/harness/utils/output-capture.js +217 -0
- package/dist/harness/utils/output-capture.js.map +1 -0
- package/dist/harness/utils/shell-output.d.ts +12 -5
- package/dist/harness/utils/shell-output.d.ts.map +1 -1
- package/dist/harness/utils/shell-output.js +64 -174
- package/dist/harness/utils/shell-output.js.map +1 -1
- package/dist/harness/utils/truncate.d.ts +1 -0
- package/dist/harness/utils/truncate.d.ts.map +1 -1
- package/dist/harness/utils/truncate.js +1 -1
- package/dist/harness/utils/truncate.js.map +1 -1
- package/dist/harness/utils/usage.d.ts +4 -0
- package/dist/harness/utils/usage.d.ts.map +1 -0
- package/dist/harness/utils/usage.js +33 -0
- package/dist/harness/utils/usage.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/dist/proxy.d.ts +2 -0
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +40 -10
- package/dist/proxy.js.map +1 -1
- package/dist/search/index.d.ts +24 -16
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +1 -1
- package/dist/search/index.js.map +1 -1
- package/dist/types.d.ts +5 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +25 -4
- package/dist/harness/reducer.d.ts +0 -100
- package/dist/harness/reducer.d.ts.map +0 -1
- package/dist/harness/reducer.js +0 -415
- package/dist/harness/reducer.js.map +0 -1
- package/dist/harness/session/jsonl/errors.d.ts +0 -9
- package/dist/harness/session/jsonl/errors.d.ts.map +0 -1
- package/dist/harness/session/jsonl/errors.js +0 -19
- package/dist/harness/session/jsonl/errors.js.map +0 -1
- package/dist/harness/session/jsonl.d.ts +0 -3
- package/dist/harness/session/jsonl.d.ts.map +0 -1
- package/dist/harness/session/jsonl.js +0 -2
- package/dist/harness/session/jsonl.js.map +0 -1
- package/dist/harness/session/state.d.ts +0 -65
- package/dist/harness/session/state.d.ts.map +0 -1
- package/dist/harness/session/state.js +0 -319
- package/dist/harness/session/state.js.map +0 -1
- package/dist/harness/session/testing/conformance.d.ts +0 -4
- package/dist/harness/session/testing/conformance.d.ts.map +0 -1
- package/dist/harness/session/testing/conformance.js +0 -762
- package/dist/harness/session/testing/conformance.js.map +0 -1
- package/dist/search/scanning.d.ts +0 -29
- package/dist/search/scanning.d.ts.map +0 -1
- package/dist/search/scanning.js +0 -103
- package/dist/search/scanning.js.map +0 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
function upsertTool(operation, tool) {
|
|
2
|
+
const index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === tool.toolCallId);
|
|
3
|
+
if (index === -1)
|
|
4
|
+
operation.runningTools.push(tool);
|
|
5
|
+
else
|
|
6
|
+
operation.runningTools[index] = tool;
|
|
7
|
+
}
|
|
8
|
+
function matchingOperation(snapshot, operationId) {
|
|
9
|
+
return snapshot.operation?.id === operationId ? snapshot.operation : undefined;
|
|
10
|
+
}
|
|
11
|
+
/** Apply one harness event to a mutable lane snapshot. Navigation completion requires a fresh snapshot. */
|
|
12
|
+
export function reduceLaneSnapshot(snapshot, event) {
|
|
13
|
+
if ("lane" in event && event.lane !== undefined && event.lane !== snapshot.lane && event.type !== "usage")
|
|
14
|
+
return;
|
|
15
|
+
switch (event.type) {
|
|
16
|
+
case "run_start":
|
|
17
|
+
snapshot.operation = {
|
|
18
|
+
id: event.runId,
|
|
19
|
+
kind: "run",
|
|
20
|
+
startedAt: event.startedAt,
|
|
21
|
+
fromTipId: snapshot.tipId,
|
|
22
|
+
status: "open",
|
|
23
|
+
runningTools: [],
|
|
24
|
+
};
|
|
25
|
+
return;
|
|
26
|
+
case "compaction_start":
|
|
27
|
+
if (snapshot.operation !== null)
|
|
28
|
+
return;
|
|
29
|
+
snapshot.operation = {
|
|
30
|
+
id: event.runId,
|
|
31
|
+
kind: "compaction",
|
|
32
|
+
startedAt: event.startedAt,
|
|
33
|
+
fromTipId: snapshot.tipId,
|
|
34
|
+
status: "open",
|
|
35
|
+
runningTools: [],
|
|
36
|
+
};
|
|
37
|
+
return;
|
|
38
|
+
case "navigation_start":
|
|
39
|
+
snapshot.operation = {
|
|
40
|
+
id: event.runId,
|
|
41
|
+
kind: "navigation",
|
|
42
|
+
startedAt: event.startedAt,
|
|
43
|
+
fromTipId: snapshot.tipId,
|
|
44
|
+
status: "open",
|
|
45
|
+
runningTools: [],
|
|
46
|
+
};
|
|
47
|
+
return;
|
|
48
|
+
case "operation_abort": {
|
|
49
|
+
const operation = matchingOperation(snapshot, event.operationId);
|
|
50
|
+
if (operation !== undefined)
|
|
51
|
+
operation.status = "aborting";
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
case "run_resume": {
|
|
55
|
+
const operation = matchingOperation(snapshot, event.runId);
|
|
56
|
+
if (operation !== undefined)
|
|
57
|
+
delete operation.deferred;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
case "run_suspend": {
|
|
61
|
+
const operation = matchingOperation(snapshot, event.runId);
|
|
62
|
+
if (operation === undefined)
|
|
63
|
+
return;
|
|
64
|
+
delete operation.streamingMessage;
|
|
65
|
+
operation.deferred = { handle: event.deferred, poll: event.poll };
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
case "retry_scheduled": {
|
|
69
|
+
const operation = matchingOperation(snapshot, event.runId);
|
|
70
|
+
if (operation !== undefined) {
|
|
71
|
+
operation.retry = {
|
|
72
|
+
attempt: event.attempt,
|
|
73
|
+
maxAttempts: event.maxAttempts,
|
|
74
|
+
nextAttemptAt: event.notBefore,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
case "retry_start":
|
|
80
|
+
case "retry_end": {
|
|
81
|
+
const operation = matchingOperation(snapshot, event.runId);
|
|
82
|
+
if (operation !== undefined)
|
|
83
|
+
delete operation.retry;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
case "message_start": {
|
|
87
|
+
if (event.runId === undefined ||
|
|
88
|
+
event.message.role !== "assistant" ||
|
|
89
|
+
event.message.stopReason !== "pending") {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const operation = matchingOperation(snapshot, event.runId);
|
|
93
|
+
if (operation !== undefined)
|
|
94
|
+
operation.streamingMessage = event.message;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
case "message_update": {
|
|
98
|
+
if (event.message.role !== "assistant")
|
|
99
|
+
return;
|
|
100
|
+
const operation = matchingOperation(snapshot, event.runId);
|
|
101
|
+
if (operation !== undefined)
|
|
102
|
+
operation.streamingMessage = event.message;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
case "message_end": {
|
|
106
|
+
if (event.runId === undefined)
|
|
107
|
+
return;
|
|
108
|
+
const operation = matchingOperation(snapshot, event.runId);
|
|
109
|
+
if (operation !== undefined)
|
|
110
|
+
delete operation.streamingMessage;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
case "tool_start": {
|
|
114
|
+
const operation = matchingOperation(snapshot, event.runId);
|
|
115
|
+
if (operation === undefined)
|
|
116
|
+
return;
|
|
117
|
+
upsertTool(operation, {
|
|
118
|
+
status: "running",
|
|
119
|
+
toolCallId: event.toolCallId,
|
|
120
|
+
toolName: event.toolName,
|
|
121
|
+
args: event.args,
|
|
122
|
+
});
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
case "tool_update": {
|
|
126
|
+
const operation = matchingOperation(snapshot, event.runId);
|
|
127
|
+
const tool = operation?.runningTools.find((candidate) => candidate.toolCallId === event.toolCallId);
|
|
128
|
+
if (tool?.status === "running")
|
|
129
|
+
tool.result = event.partialResult;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
case "tool_end": {
|
|
133
|
+
const operation = matchingOperation(snapshot, event.runId);
|
|
134
|
+
if (operation === undefined)
|
|
135
|
+
return;
|
|
136
|
+
const index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === event.toolCallId);
|
|
137
|
+
const current = operation.runningTools[index];
|
|
138
|
+
if (current === undefined)
|
|
139
|
+
return;
|
|
140
|
+
operation.runningTools[index] = {
|
|
141
|
+
status: "settled",
|
|
142
|
+
toolCallId: event.toolCallId,
|
|
143
|
+
toolName: event.toolName,
|
|
144
|
+
args: current.args,
|
|
145
|
+
result: event.result,
|
|
146
|
+
isError: event.isError,
|
|
147
|
+
};
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
case "entry_added": {
|
|
151
|
+
if (event.entry.type === "message" && event.entry.message.role === "toolResult") {
|
|
152
|
+
const operation = snapshot.operation;
|
|
153
|
+
if (operation !== null) {
|
|
154
|
+
const toolCallId = event.entry.message.toolCallId;
|
|
155
|
+
const index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === toolCallId);
|
|
156
|
+
if (index !== -1)
|
|
157
|
+
operation.runningTools.splice(index, 1);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (event.entry.type === "compaction")
|
|
161
|
+
snapshot.transcript.splice(0, snapshot.transcript.length, event.entry);
|
|
162
|
+
else
|
|
163
|
+
snapshot.transcript.push(event.entry);
|
|
164
|
+
snapshot.tipId = event.entry.id;
|
|
165
|
+
if (event.entry.type === "message")
|
|
166
|
+
snapshot.stats.messageCount += 1;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
case "queue_update":
|
|
170
|
+
snapshot.queues = event.queues;
|
|
171
|
+
return;
|
|
172
|
+
case "usage":
|
|
173
|
+
snapshot.stats.usage = event.totals;
|
|
174
|
+
return;
|
|
175
|
+
case "config_update":
|
|
176
|
+
if (!("lane" in event) || event.lane !== snapshot.lane)
|
|
177
|
+
return;
|
|
178
|
+
switch (event.property) {
|
|
179
|
+
case "model":
|
|
180
|
+
snapshot.configuration.model = event.value;
|
|
181
|
+
return;
|
|
182
|
+
case "thinkingLevel":
|
|
183
|
+
snapshot.configuration.thinkingLevel = event.value;
|
|
184
|
+
return;
|
|
185
|
+
case "activeTools":
|
|
186
|
+
snapshot.configuration.activeToolNames = event.value;
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
return;
|
|
190
|
+
case "run_end": {
|
|
191
|
+
const operation = matchingOperation(snapshot, event.runId);
|
|
192
|
+
if (operation?.kind !== "run")
|
|
193
|
+
return;
|
|
194
|
+
const record = {
|
|
195
|
+
operationId: event.runId,
|
|
196
|
+
kind: "run",
|
|
197
|
+
status: event.status,
|
|
198
|
+
...(event.status === "failed" ? { error: event.error } : {}),
|
|
199
|
+
fromTipId: event.fromTipId,
|
|
200
|
+
tipId: event.tipId,
|
|
201
|
+
startedAt: operation.startedAt,
|
|
202
|
+
endedAt: event.endedAt,
|
|
203
|
+
};
|
|
204
|
+
snapshot.lastResult = record;
|
|
205
|
+
snapshot.operation = null;
|
|
206
|
+
snapshot.tipId = event.tipId;
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
case "compaction_end": {
|
|
210
|
+
const operation = matchingOperation(snapshot, event.runId);
|
|
211
|
+
if (operation?.kind !== "compaction")
|
|
212
|
+
return;
|
|
213
|
+
const record = {
|
|
214
|
+
operationId: event.runId,
|
|
215
|
+
kind: "compaction",
|
|
216
|
+
status: event.status,
|
|
217
|
+
...(event.status === "failed" ? { error: event.error } : {}),
|
|
218
|
+
fromTipId: operation.fromTipId,
|
|
219
|
+
tipId: snapshot.tipId,
|
|
220
|
+
startedAt: operation.startedAt,
|
|
221
|
+
endedAt: event.endedAt,
|
|
222
|
+
};
|
|
223
|
+
snapshot.lastResult = record;
|
|
224
|
+
snapshot.operation = null;
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
case "navigation_end":
|
|
228
|
+
return "rebase";
|
|
229
|
+
case "fault":
|
|
230
|
+
snapshot.faulted = true;
|
|
231
|
+
return;
|
|
232
|
+
case "handler_error":
|
|
233
|
+
case "turn_start":
|
|
234
|
+
case "turn_end":
|
|
235
|
+
case "value_update":
|
|
236
|
+
case "lane_created":
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=reducer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reducer.js","sourceRoot":"","sources":["../../../src/harness/runtime/reducer.ts"],"names":[],"mappings":"AAOA,SAAS,UAAU,CAAC,SAAgC,EAAE,IAAmD,EAAQ;IAChH,MAAM,KAAK,GAAG,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC;IACxG,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;QAC/C,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;AAAA,CAC1C;AAED,S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AAQ,CAAC,SAAS,GAAG,IAAI,CAAC;YAC1B,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YAC7B,OAAO;QACR,CAAC;QACD,KAAK,gBAAgB,EAAE,CAAC;YACvB,MAAM,SAAS,GAAG,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YAC3D,IAAI,SAAS,EAAE,IAAI,KAAK,YAAY;gBAAE,OAAO;YAC7C,MAAM,MAAM,GAA0B;gBACrC,WAAW,EAAE,KAAK,CAAC,KAAK;gBACxB,IAAI,EAAE,YAAY;gBAClB,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC5D,SAAS,EAAE,SAAS,CAAC,SAAS;gBAC9B,KAAK,EAAE,QAAQ,CAAC,KAAK;gBACrB,SAAS,EAAE,SAAS,CAAC,SAAS;gBAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;aACtB,CAAC;YACF,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC;YAC7B,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;YAC1B,OAAO;QACR,CAAC;QACD,KAAK,gBAAgB;YACpB,OAAO,QAAQ,CAAC;QACjB,KAAK,OAAO;YACX,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC;YACxB,OAAO;QACR,KAAK,eAAe,CAAC;QACrB,KAAK,YAAY,CAAC;QAClB,KAAK,UAAU,CAAC;QAChB,KAAK,cAAc,CAAC;QACpB,KAAK,cAAc;YAClB,OAAO;IACT,CAAC;AAAA,CACD","sourcesContent":["import type { HarnessEvent, LaneSnapshot, LaneWatchEvent } from \"../agent-harness.ts\";\nimport type { OperationResultRecord } from \"../session/types.ts\";\n\nexport type LaneSnapshotReduction = \"rebase\" | undefined;\n\ntype LaneOperationSnapshot = NonNullable<LaneSnapshot[\"operation\"]>;\n\nfunction upsertTool(operation: LaneOperationSnapshot, tool: LaneOperationSnapshot[\"runningTools\"][number]): void {\n\tconst index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === tool.toolCallId);\n\tif (index === -1) operation.runningTools.push(tool);\n\telse operation.runningTools[index] = tool;\n}\n\nfunction matchingOperation(\n\tsnapshot: LaneSnapshot,\n\toperationId: string,\n): NonNullable<LaneSnapshot[\"operation\"]> | undefined {\n\treturn snapshot.operation?.id === operationId ? snapshot.operation : undefined;\n}\n\n/** Apply one harness event to a mutable lane snapshot. Navigation completion requires a fresh snapshot. */\nexport function reduceLaneSnapshot(\n\tsnapshot: LaneSnapshot,\n\tevent: HarnessEvent | LaneWatchEvent,\n): LaneSnapshotReduction {\n\tif (\"lane\" in event && event.lane !== undefined && event.lane !== snapshot.lane && event.type !== \"usage\") return;\n\tswitch (event.type) {\n\t\tcase \"run_start\":\n\t\t\tsnapshot.operation = {\n\t\t\t\tid: event.runId,\n\t\t\t\tkind: \"run\",\n\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\tfromTipId: snapshot.tipId,\n\t\t\t\tstatus: \"open\",\n\t\t\t\trunningTools: [],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"compaction_start\":\n\t\t\tif (snapshot.operation !== null) return;\n\t\t\tsnapshot.operation = {\n\t\t\t\tid: event.runId,\n\t\t\t\tkind: \"compaction\",\n\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\tfromTipId: snapshot.tipId,\n\t\t\t\tstatus: \"open\",\n\t\t\t\trunningTools: [],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"navigation_start\":\n\t\t\tsnapshot.operation = {\n\t\t\t\tid: event.runId,\n\t\t\t\tkind: \"navigation\",\n\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\tfromTipId: snapshot.tipId,\n\t\t\t\tstatus: \"open\",\n\t\t\t\trunningTools: [],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"operation_abort\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.operationId);\n\t\t\tif (operation !== undefined) operation.status = \"aborting\";\n\t\t\treturn;\n\t\t}\n\t\tcase \"run_resume\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) delete operation.deferred;\n\t\t\treturn;\n\t\t}\n\t\tcase \"run_suspend\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation === undefined) return;\n\t\t\tdelete operation.streamingMessage;\n\t\t\toperation.deferred = { handle: event.deferred, poll: event.poll };\n\t\t\treturn;\n\t\t}\n\t\tcase \"retry_scheduled\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) {\n\t\t\t\toperation.retry = {\n\t\t\t\t\tattempt: event.attempt,\n\t\t\t\t\tmaxAttempts: event.maxAttempts,\n\t\t\t\t\tnextAttemptAt: event.notBefore,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tcase \"retry_start\":\n\t\tcase \"retry_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) delete operation.retry;\n\t\t\treturn;\n\t\t}\n\t\tcase \"message_start\": {\n\t\t\tif (\n\t\t\t\tevent.runId === undefined ||\n\t\t\t\tevent.message.role !== \"assistant\" ||\n\t\t\t\tevent.message.stopReason !== \"pending\"\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) operation.streamingMessage = event.message;\n\t\t\treturn;\n\t\t}\n\t\tcase \"message_update\": {\n\t\t\tif (event.message.role !== \"assistant\") return;\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) operation.streamingMessage = event.message;\n\t\t\treturn;\n\t\t}\n\t\tcase \"message_end\": {\n\t\t\tif (event.runId === undefined) return;\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) delete operation.streamingMessage;\n\t\t\treturn;\n\t\t}\n\t\tcase \"tool_start\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation === undefined) return;\n\t\t\tupsertTool(operation, {\n\t\t\t\tstatus: \"running\",\n\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\ttoolName: event.toolName,\n\t\t\t\targs: event.args,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tcase \"tool_update\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tconst tool = operation?.runningTools.find((candidate) => candidate.toolCallId === event.toolCallId);\n\t\t\tif (tool?.status === \"running\") tool.result = event.partialResult;\n\t\t\treturn;\n\t\t}\n\t\tcase \"tool_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation === undefined) return;\n\t\t\tconst index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === event.toolCallId);\n\t\t\tconst current = operation.runningTools[index];\n\t\t\tif (current === undefined) return;\n\t\t\toperation.runningTools[index] = {\n\t\t\t\tstatus: \"settled\",\n\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\ttoolName: event.toolName,\n\t\t\t\targs: current.args,\n\t\t\t\tresult: event.result,\n\t\t\t\tisError: event.isError,\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tcase \"entry_added\": {\n\t\t\tif (event.entry.type === \"message\" && event.entry.message.role === \"toolResult\") {\n\t\t\t\tconst operation = snapshot.operation;\n\t\t\t\tif (operation !== null) {\n\t\t\t\t\tconst toolCallId = event.entry.message.toolCallId;\n\t\t\t\t\tconst index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === toolCallId);\n\t\t\t\t\tif (index !== -1) operation.runningTools.splice(index, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (event.entry.type === \"compaction\") snapshot.transcript.splice(0, snapshot.transcript.length, event.entry);\n\t\t\telse snapshot.transcript.push(event.entry);\n\t\t\tsnapshot.tipId = event.entry.id;\n\t\t\tif (event.entry.type === \"message\") snapshot.stats.messageCount += 1;\n\t\t\treturn;\n\t\t}\n\t\tcase \"queue_update\":\n\t\t\tsnapshot.queues = event.queues;\n\t\t\treturn;\n\t\tcase \"usage\":\n\t\t\tsnapshot.stats.usage = event.totals;\n\t\t\treturn;\n\t\tcase \"config_update\":\n\t\t\tif (!(\"lane\" in event) || event.lane !== snapshot.lane) return;\n\t\t\tswitch (event.property) {\n\t\t\t\tcase \"model\":\n\t\t\t\t\tsnapshot.configuration.model = event.value;\n\t\t\t\t\treturn;\n\t\t\t\tcase \"thinkingLevel\":\n\t\t\t\t\tsnapshot.configuration.thinkingLevel = event.value;\n\t\t\t\t\treturn;\n\t\t\t\tcase \"activeTools\":\n\t\t\t\t\tsnapshot.configuration.activeToolNames = event.value;\n\t\t\t\t\treturn;\n\t\t\t}\n\t\t\treturn;\n\t\tcase \"run_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation?.kind !== \"run\") return;\n\t\t\tconst record: OperationResultRecord = {\n\t\t\t\toperationId: event.runId,\n\t\t\t\tkind: \"run\",\n\t\t\t\tstatus: event.status,\n\t\t\t\t...(event.status === \"failed\" ? { error: event.error } : {}),\n\t\t\t\tfromTipId: event.fromTipId,\n\t\t\t\ttipId: event.tipId,\n\t\t\t\tstartedAt: operation.startedAt,\n\t\t\t\tendedAt: event.endedAt,\n\t\t\t};\n\t\t\tsnapshot.lastResult = record;\n\t\t\tsnapshot.operation = null;\n\t\t\tsnapshot.tipId = event.tipId;\n\t\t\treturn;\n\t\t}\n\t\tcase \"compaction_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation?.kind !== \"compaction\") return;\n\t\t\tconst record: OperationResultRecord = {\n\t\t\t\toperationId: event.runId,\n\t\t\t\tkind: \"compaction\",\n\t\t\t\tstatus: event.status,\n\t\t\t\t...(event.status === \"failed\" ? { error: event.error } : {}),\n\t\t\t\tfromTipId: operation.fromTipId,\n\t\t\t\ttipId: snapshot.tipId,\n\t\t\t\tstartedAt: operation.startedAt,\n\t\t\t\tendedAt: event.endedAt,\n\t\t\t};\n\t\t\tsnapshot.lastResult = record;\n\t\t\tsnapshot.operation = null;\n\t\t\treturn;\n\t\t}\n\t\tcase \"navigation_end\":\n\t\t\treturn \"rebase\";\n\t\tcase \"fault\":\n\t\t\tsnapshot.faulted = true;\n\t\t\treturn;\n\t\tcase \"handler_error\":\n\t\tcase \"turn_start\":\n\t\tcase \"turn_end\":\n\t\tcase \"value_update\":\n\t\tcase \"lane_created\":\n\t\t\treturn;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Context } from "../context.ts";
|
|
2
|
+
import type { LaneState as DurableLaneState, LaneConfiguration, Session, SessionReader } from "../session/types.ts";
|
|
3
|
+
import { type StoredValue } from "../session/values.ts";
|
|
4
|
+
import type { LaneState } from "./types.ts";
|
|
5
|
+
export type ClassifiedLaneStorage = {
|
|
6
|
+
kind: "absent";
|
|
7
|
+
} | {
|
|
8
|
+
kind: "branch";
|
|
9
|
+
tip: StoredValue<string | null>;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "lane";
|
|
12
|
+
tip: StoredValue<string | null>;
|
|
13
|
+
configuration: StoredValue<LaneConfiguration>;
|
|
14
|
+
laneState: StoredValue<DurableLaneState>;
|
|
15
|
+
};
|
|
16
|
+
export declare function readLaneStorage(reader: SessionReader, lane: string, context: Context): Promise<ClassifiedLaneStorage>;
|
|
17
|
+
/** Restore every complete configured AgentLane in one coherent Session read. */
|
|
18
|
+
export declare function restoreSession(session: Session, context: Context): Promise<Map<string, LaneState>>;
|
|
19
|
+
/** Restore one configured lane without starting work or interpreting its state. */
|
|
20
|
+
export declare function restoreLane(session: Session, lane: string, context: Context): Promise<LaneState>;
|
|
21
|
+
export declare function restoreLaneState(reader: SessionReader, lane: string, stored: Extract<ClassifiedLaneStorage, {
|
|
22
|
+
kind: "lane";
|
|
23
|
+
}>, context: Context): Promise<LaneState>;
|
|
24
|
+
//# sourceMappingURL=restore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restore.d.ts","sourceRoot":"","sources":["../../../src/harness/runtime/restore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EACX,SAAS,IAAI,gBAAgB,EAC7B,iBAAiB,EAGjB,OAAO,EACP,aAAa,EACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAON,KAAK,WAAW,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAiC5C,MAAM,MAAM,qBAAqB,GAC9B;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;CAAE,GACnD;IACA,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAChC,aAAa,EAAE,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAC9C,SAAS,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC;CACxC,CAAC;AAiBL,wBAAsB,eAAe,CACpC,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,qBAAqB,CAAC,CAOhC;AAED,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAuBlG;AAED,mFAAmF;AACnF,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAWhG;AAED,wBAAsB,gBAAgB,CACrC,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,CAAC,qBAAqB,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EACxD,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,SAAS,CAAC,CAmCpB","sourcesContent":["import type { Context } from \"../context.ts\";\nimport { SessionInvariantError } from \"../session/session.ts\";\nimport type {\n\tLaneState as DurableLaneState,\n\tLaneConfiguration,\n\tOperationMeta,\n\tOperationState,\n\tSession,\n\tSessionReader,\n} from \"../session/types.ts\";\nimport {\n\tbranchTip,\n\tbranchTipInventoryPrefix,\n\tlaneConfig,\n\tlaneState as laneStateValue,\n\toperationMeta,\n\toperationState,\n\ttype StoredValue,\n} from \"../session/values.ts\";\nimport type { LaneState } from \"./types.ts\";\n\nfunction isSummaryState(state: OperationState): state is Extract<OperationState, { at: `summary.${string}` }> {\n\treturn state.at.startsWith(\"summary.\");\n}\n\nfunction stateMatchesIntent(intent: OperationMeta[\"intent\"], state: OperationState): boolean {\n\tif (intent.kind === \"compaction\") return isSummaryState(state) && state.task.boundary.kind === \"finish\";\n\tif (intent.kind === \"navigation\") {\n\t\tif (state.at === \"navigation.ready_to_commit\") {\n\t\t\treturn !intent.summarize && state.targetId === intent.targetId && state.label === intent.label;\n\t\t}\n\t\treturn (\n\t\t\tintent.summarize &&\n\t\t\tisSummaryState(state) &&\n\t\t\tstate.task.boundary.kind === \"commit_navigation\" &&\n\t\t\tstate.task.boundary.targetId === intent.targetId &&\n\t\t\tstate.task.boundary.label === intent.label &&\n\t\t\tstate.task.customInstructions === intent.customInstructions\n\t\t);\n\t}\n\treturn (\n\t\tstate.at !== \"navigation.ready_to_commit\" &&\n\t\t(!isSummaryState(state) || state.task.boundary.kind === \"resume_checkpoint\")\n\t);\n}\n\ntype LaneValues = {\n\ttip: StoredValue<string | null> | undefined;\n\tconfiguration: StoredValue<LaneConfiguration> | undefined;\n\tlaneState: StoredValue<DurableLaneState> | undefined;\n};\n\nexport type ClassifiedLaneStorage =\n\t| { kind: \"absent\" }\n\t| { kind: \"branch\"; tip: StoredValue<string | null> }\n\t| {\n\t\t\tkind: \"lane\";\n\t\t\ttip: StoredValue<string | null>;\n\t\t\tconfiguration: StoredValue<LaneConfiguration>;\n\t\t\tlaneState: StoredValue<DurableLaneState>;\n\t };\n\nfunction classifyLaneStorage(lane: string, values: LaneValues): ClassifiedLaneStorage {\n\tconst { tip, configuration, laneState } = values;\n\tif (tip === undefined && configuration === undefined && laneState === undefined) {\n\t\treturn { kind: \"absent\" };\n\t}\n\tif (tip !== undefined && configuration === undefined && laneState === undefined) {\n\t\treturn { kind: \"branch\", tip };\n\t}\n\tif (tip === undefined) throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing branch.tip`);\n\tif (configuration === undefined)\n\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.config`);\n\tif (laneState === undefined) throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.state`);\n\treturn { kind: \"lane\", tip, configuration, laneState };\n}\n\nexport async function readLaneStorage(\n\treader: SessionReader,\n\tlane: string,\n\tcontext: Context,\n): Promise<ClassifiedLaneStorage> {\n\tconst [tip, configuration, laneState] = await Promise.all([\n\t\treader.getValue(branchTip(lane), context),\n\t\treader.getValue(laneConfig(lane), context),\n\t\treader.getValue(laneStateValue(lane), context),\n\t]);\n\treturn classifyLaneStorage(lane, { tip, configuration, laneState });\n}\n\n/** Restore every complete configured AgentLane in one coherent Session read. */\nexport function restoreSession(session: Session, context: Context): Promise<Map<string, LaneState>> {\n\treturn session.mutate(async (reader) => {\n\t\tconst [tips, configurations, states] = await Promise.all([\n\t\t\treader.scanValues(branchTipInventoryPrefix(), context),\n\t\t\treader.scanValues(laneConfig(\"\"), context),\n\t\t\treader.scanValues(laneStateValue(\"\"), context),\n\t\t]);\n\t\tconst tipByLane = new Map(tips.map((value) => [value.address.key, value]));\n\t\tconst configurationByLane = new Map(configurations.map((value) => [value.address.key, value]));\n\t\tconst stateByLane = new Map(states.map((value) => [value.address.key, value]));\n\t\tconst names = new Set([...tipByLane.keys(), ...configurationByLane.keys(), ...stateByLane.keys()]);\n\t\tconst restored = new Map<string, LaneState>();\n\t\tfor (const lane of names) {\n\t\t\tconst stored = classifyLaneStorage(lane, {\n\t\t\t\ttip: tipByLane.get(lane),\n\t\t\t\tconfiguration: configurationByLane.get(lane),\n\t\t\t\tlaneState: stateByLane.get(lane),\n\t\t\t});\n\t\t\tif (stored.kind !== \"lane\") continue;\n\t\t\trestored.set(lane, await restoreLaneState(reader, lane, stored, context));\n\t\t}\n\t\treturn restored;\n\t}, context);\n}\n\n/** Restore one configured lane without starting work or interpreting its state. */\nexport function restoreLane(session: Session, lane: string, context: Context): Promise<LaneState> {\n\treturn session.mutate(async (reader) => {\n\t\tconst stored = await readLaneStorage(reader, lane, context);\n\t\tif (stored.kind === \"absent\") {\n\t\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing branch.tip`);\n\t\t}\n\t\tif (stored.kind === \"branch\") {\n\t\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.config`);\n\t\t}\n\t\treturn restoreLaneState(reader, lane, stored, context);\n\t}, context);\n}\n\nexport async function restoreLaneState(\n\treader: SessionReader,\n\tlane: string,\n\tstored: Extract<ClassifiedLaneStorage, { kind: \"lane\" }>,\n\tcontext: Context,\n): Promise<LaneState> {\n\tconst operationId = stored.laneState.value.currentOperationId;\n\tlet operation: LaneState[\"operation\"] = null;\n\tif (operationId !== null) {\n\t\tconst [meta, state] = await Promise.all([\n\t\t\treader.getValue(operationMeta(operationId), context),\n\t\t\treader.getValue(operationState(operationId), context),\n\t\t]);\n\t\tif (meta === undefined) throw new SessionInvariantError(`Operation ${operationId} is missing op.meta`);\n\t\tif (state === undefined) throw new SessionInvariantError(`Operation ${operationId} is missing op.state`);\n\t\tif (meta.value.operationId !== operationId) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} metadata names operation ${JSON.stringify(meta.value.operationId)}`,\n\t\t\t);\n\t\t}\n\t\tif (meta.value.lane !== lane) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} belongs to lane ${JSON.stringify(meta.value.lane)}, not ${JSON.stringify(lane)}`,\n\t\t\t);\n\t\t}\n\t\tif (!stateMatchesIntent(meta.value.intent, state.value)) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} intent ${meta.value.intent.kind} does not match state ${state.value.at}`,\n\t\t\t);\n\t\t}\n\t\toperation = { meta: meta.value, state: state.value };\n\t}\n\n\treturn {\n\t\ttipId: stored.tip.value,\n\t\tconfiguration: stored.configuration.value,\n\t\tinbox: stored.laneState.value.inbox,\n\t\tlastOperationId: stored.laneState.value.lastOperationId,\n\t\toperation,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { SessionInvariantError } from "../session/session.js";
|
|
2
|
+
import { branchTip, branchTipInventoryPrefix, laneConfig, laneState as laneStateValue, operationMeta, operationState, } from "../session/values.js";
|
|
3
|
+
function isSummaryState(state) {
|
|
4
|
+
return state.at.startsWith("summary.");
|
|
5
|
+
}
|
|
6
|
+
function stateMatchesIntent(intent, state) {
|
|
7
|
+
if (intent.kind === "compaction")
|
|
8
|
+
return isSummaryState(state) && state.task.boundary.kind === "finish";
|
|
9
|
+
if (intent.kind === "navigation") {
|
|
10
|
+
if (state.at === "navigation.ready_to_commit") {
|
|
11
|
+
return !intent.summarize && state.targetId === intent.targetId && state.label === intent.label;
|
|
12
|
+
}
|
|
13
|
+
return (intent.summarize &&
|
|
14
|
+
isSummaryState(state) &&
|
|
15
|
+
state.task.boundary.kind === "commit_navigation" &&
|
|
16
|
+
state.task.boundary.targetId === intent.targetId &&
|
|
17
|
+
state.task.boundary.label === intent.label &&
|
|
18
|
+
state.task.customInstructions === intent.customInstructions);
|
|
19
|
+
}
|
|
20
|
+
return (state.at !== "navigation.ready_to_commit" &&
|
|
21
|
+
(!isSummaryState(state) || state.task.boundary.kind === "resume_checkpoint"));
|
|
22
|
+
}
|
|
23
|
+
function classifyLaneStorage(lane, values) {
|
|
24
|
+
const { tip, configuration, laneState } = values;
|
|
25
|
+
if (tip === undefined && configuration === undefined && laneState === undefined) {
|
|
26
|
+
return { kind: "absent" };
|
|
27
|
+
}
|
|
28
|
+
if (tip !== undefined && configuration === undefined && laneState === undefined) {
|
|
29
|
+
return { kind: "branch", tip };
|
|
30
|
+
}
|
|
31
|
+
if (tip === undefined)
|
|
32
|
+
throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing branch.tip`);
|
|
33
|
+
if (configuration === undefined)
|
|
34
|
+
throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.config`);
|
|
35
|
+
if (laneState === undefined)
|
|
36
|
+
throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.state`);
|
|
37
|
+
return { kind: "lane", tip, configuration, laneState };
|
|
38
|
+
}
|
|
39
|
+
export async function readLaneStorage(reader, lane, context) {
|
|
40
|
+
const [tip, configuration, laneState] = await Promise.all([
|
|
41
|
+
reader.getValue(branchTip(lane), context),
|
|
42
|
+
reader.getValue(laneConfig(lane), context),
|
|
43
|
+
reader.getValue(laneStateValue(lane), context),
|
|
44
|
+
]);
|
|
45
|
+
return classifyLaneStorage(lane, { tip, configuration, laneState });
|
|
46
|
+
}
|
|
47
|
+
/** Restore every complete configured AgentLane in one coherent Session read. */
|
|
48
|
+
export function restoreSession(session, context) {
|
|
49
|
+
return session.mutate(async (reader) => {
|
|
50
|
+
const [tips, configurations, states] = await Promise.all([
|
|
51
|
+
reader.scanValues(branchTipInventoryPrefix(), context),
|
|
52
|
+
reader.scanValues(laneConfig(""), context),
|
|
53
|
+
reader.scanValues(laneStateValue(""), context),
|
|
54
|
+
]);
|
|
55
|
+
const tipByLane = new Map(tips.map((value) => [value.address.key, value]));
|
|
56
|
+
const configurationByLane = new Map(configurations.map((value) => [value.address.key, value]));
|
|
57
|
+
const stateByLane = new Map(states.map((value) => [value.address.key, value]));
|
|
58
|
+
const names = new Set([...tipByLane.keys(), ...configurationByLane.keys(), ...stateByLane.keys()]);
|
|
59
|
+
const restored = new Map();
|
|
60
|
+
for (const lane of names) {
|
|
61
|
+
const stored = classifyLaneStorage(lane, {
|
|
62
|
+
tip: tipByLane.get(lane),
|
|
63
|
+
configuration: configurationByLane.get(lane),
|
|
64
|
+
laneState: stateByLane.get(lane),
|
|
65
|
+
});
|
|
66
|
+
if (stored.kind !== "lane")
|
|
67
|
+
continue;
|
|
68
|
+
restored.set(lane, await restoreLaneState(reader, lane, stored, context));
|
|
69
|
+
}
|
|
70
|
+
return restored;
|
|
71
|
+
}, context);
|
|
72
|
+
}
|
|
73
|
+
/** Restore one configured lane without starting work or interpreting its state. */
|
|
74
|
+
export function restoreLane(session, lane, context) {
|
|
75
|
+
return session.mutate(async (reader) => {
|
|
76
|
+
const stored = await readLaneStorage(reader, lane, context);
|
|
77
|
+
if (stored.kind === "absent") {
|
|
78
|
+
throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing branch.tip`);
|
|
79
|
+
}
|
|
80
|
+
if (stored.kind === "branch") {
|
|
81
|
+
throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.config`);
|
|
82
|
+
}
|
|
83
|
+
return restoreLaneState(reader, lane, stored, context);
|
|
84
|
+
}, context);
|
|
85
|
+
}
|
|
86
|
+
export async function restoreLaneState(reader, lane, stored, context) {
|
|
87
|
+
const operationId = stored.laneState.value.currentOperationId;
|
|
88
|
+
let operation = null;
|
|
89
|
+
if (operationId !== null) {
|
|
90
|
+
const [meta, state] = await Promise.all([
|
|
91
|
+
reader.getValue(operationMeta(operationId), context),
|
|
92
|
+
reader.getValue(operationState(operationId), context),
|
|
93
|
+
]);
|
|
94
|
+
if (meta === undefined)
|
|
95
|
+
throw new SessionInvariantError(`Operation ${operationId} is missing op.meta`);
|
|
96
|
+
if (state === undefined)
|
|
97
|
+
throw new SessionInvariantError(`Operation ${operationId} is missing op.state`);
|
|
98
|
+
if (meta.value.operationId !== operationId) {
|
|
99
|
+
throw new SessionInvariantError(`Operation ${operationId} metadata names operation ${JSON.stringify(meta.value.operationId)}`);
|
|
100
|
+
}
|
|
101
|
+
if (meta.value.lane !== lane) {
|
|
102
|
+
throw new SessionInvariantError(`Operation ${operationId} belongs to lane ${JSON.stringify(meta.value.lane)}, not ${JSON.stringify(lane)}`);
|
|
103
|
+
}
|
|
104
|
+
if (!stateMatchesIntent(meta.value.intent, state.value)) {
|
|
105
|
+
throw new SessionInvariantError(`Operation ${operationId} intent ${meta.value.intent.kind} does not match state ${state.value.at}`);
|
|
106
|
+
}
|
|
107
|
+
operation = { meta: meta.value, state: state.value };
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
tipId: stored.tip.value,
|
|
111
|
+
configuration: stored.configuration.value,
|
|
112
|
+
inbox: stored.laneState.value.inbox,
|
|
113
|
+
lastOperationId: stored.laneState.value.lastOperationId,
|
|
114
|
+
operation,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=restore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restore.js","sourceRoot":"","sources":["../../../src/harness/runtime/restore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAS9D,OAAO,EACN,SAAS,EACT,wBAAwB,EACxB,UAAU,EACV,SAAS,IAAI,cAAc,EAC3B,aAAa,EACb,cAAc,GAEd,MAAM,sBAAsB,CAAC;AAG9B,SAAS,cAAc,CAAC,KAAqB,EAAiE;IAC7G,OAAO,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;AAAA,CACvC;AAED,SAAS,k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,aAAa,WAAW,WAAW,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,yBAAyB,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,CAClG,CAAC;QACH,CAAC;QACD,SAAS,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IACtD,CAAC;IAED,OAAO;QACN,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK;QACvB,aAAa,EAAE,MAAM,CAAC,aAAa,CAAC,KAAK;QACzC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK;QACnC,eAAe,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,eAAe;QACvD,SAAS;KACT,CAAC;AAAA,CACF","sourcesContent":["import type { Context } from \"../context.ts\";\nimport { SessionInvariantError } from \"../session/session.ts\";\nimport type {\n\tLaneState as DurableLaneState,\n\tLaneConfiguration,\n\tOperationMeta,\n\tOperationState,\n\tSession,\n\tSessionReader,\n} from \"../session/types.ts\";\nimport {\n\tbranchTip,\n\tbranchTipInventoryPrefix,\n\tlaneConfig,\n\tlaneState as laneStateValue,\n\toperationMeta,\n\toperationState,\n\ttype StoredValue,\n} from \"../session/values.ts\";\nimport type { LaneState } from \"./types.ts\";\n\nfunction isSummaryState(state: OperationState): state is Extract<OperationState, { at: `summary.${string}` }> {\n\treturn state.at.startsWith(\"summary.\");\n}\n\nfunction stateMatchesIntent(intent: OperationMeta[\"intent\"], state: OperationState): boolean {\n\tif (intent.kind === \"compaction\") return isSummaryState(state) && state.task.boundary.kind === \"finish\";\n\tif (intent.kind === \"navigation\") {\n\t\tif (state.at === \"navigation.ready_to_commit\") {\n\t\t\treturn !intent.summarize && state.targetId === intent.targetId && state.label === intent.label;\n\t\t}\n\t\treturn (\n\t\t\tintent.summarize &&\n\t\t\tisSummaryState(state) &&\n\t\t\tstate.task.boundary.kind === \"commit_navigation\" &&\n\t\t\tstate.task.boundary.targetId === intent.targetId &&\n\t\t\tstate.task.boundary.label === intent.label &&\n\t\t\tstate.task.customInstructions === intent.customInstructions\n\t\t);\n\t}\n\treturn (\n\t\tstate.at !== \"navigation.ready_to_commit\" &&\n\t\t(!isSummaryState(state) || state.task.boundary.kind === \"resume_checkpoint\")\n\t);\n}\n\ntype LaneValues = {\n\ttip: StoredValue<string | null> | undefined;\n\tconfiguration: StoredValue<LaneConfiguration> | undefined;\n\tlaneState: StoredValue<DurableLaneState> | undefined;\n};\n\nexport type ClassifiedLaneStorage =\n\t| { kind: \"absent\" }\n\t| { kind: \"branch\"; tip: StoredValue<string | null> }\n\t| {\n\t\t\tkind: \"lane\";\n\t\t\ttip: StoredValue<string | null>;\n\t\t\tconfiguration: StoredValue<LaneConfiguration>;\n\t\t\tlaneState: StoredValue<DurableLaneState>;\n\t };\n\nfunction classifyLaneStorage(lane: string, values: LaneValues): ClassifiedLaneStorage {\n\tconst { tip, configuration, laneState } = values;\n\tif (tip === undefined && configuration === undefined && laneState === undefined) {\n\t\treturn { kind: \"absent\" };\n\t}\n\tif (tip !== undefined && configuration === undefined && laneState === undefined) {\n\t\treturn { kind: \"branch\", tip };\n\t}\n\tif (tip === undefined) throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing branch.tip`);\n\tif (configuration === undefined)\n\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.config`);\n\tif (laneState === undefined) throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.state`);\n\treturn { kind: \"lane\", tip, configuration, laneState };\n}\n\nexport async function readLaneStorage(\n\treader: SessionReader,\n\tlane: string,\n\tcontext: Context,\n): Promise<ClassifiedLaneStorage> {\n\tconst [tip, configuration, laneState] = await Promise.all([\n\t\treader.getValue(branchTip(lane), context),\n\t\treader.getValue(laneConfig(lane), context),\n\t\treader.getValue(laneStateValue(lane), context),\n\t]);\n\treturn classifyLaneStorage(lane, { tip, configuration, laneState });\n}\n\n/** Restore every complete configured AgentLane in one coherent Session read. */\nexport function restoreSession(session: Session, context: Context): Promise<Map<string, LaneState>> {\n\treturn session.mutate(async (reader) => {\n\t\tconst [tips, configurations, states] = await Promise.all([\n\t\t\treader.scanValues(branchTipInventoryPrefix(), context),\n\t\t\treader.scanValues(laneConfig(\"\"), context),\n\t\t\treader.scanValues(laneStateValue(\"\"), context),\n\t\t]);\n\t\tconst tipByLane = new Map(tips.map((value) => [value.address.key, value]));\n\t\tconst configurationByLane = new Map(configurations.map((value) => [value.address.key, value]));\n\t\tconst stateByLane = new Map(states.map((value) => [value.address.key, value]));\n\t\tconst names = new Set([...tipByLane.keys(), ...configurationByLane.keys(), ...stateByLane.keys()]);\n\t\tconst restored = new Map<string, LaneState>();\n\t\tfor (const lane of names) {\n\t\t\tconst stored = classifyLaneStorage(lane, {\n\t\t\t\ttip: tipByLane.get(lane),\n\t\t\t\tconfiguration: configurationByLane.get(lane),\n\t\t\t\tlaneState: stateByLane.get(lane),\n\t\t\t});\n\t\t\tif (stored.kind !== \"lane\") continue;\n\t\t\trestored.set(lane, await restoreLaneState(reader, lane, stored, context));\n\t\t}\n\t\treturn restored;\n\t}, context);\n}\n\n/** Restore one configured lane without starting work or interpreting its state. */\nexport function restoreLane(session: Session, lane: string, context: Context): Promise<LaneState> {\n\treturn session.mutate(async (reader) => {\n\t\tconst stored = await readLaneStorage(reader, lane, context);\n\t\tif (stored.kind === \"absent\") {\n\t\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing branch.tip`);\n\t\t}\n\t\tif (stored.kind === \"branch\") {\n\t\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.config`);\n\t\t}\n\t\treturn restoreLaneState(reader, lane, stored, context);\n\t}, context);\n}\n\nexport async function restoreLaneState(\n\treader: SessionReader,\n\tlane: string,\n\tstored: Extract<ClassifiedLaneStorage, { kind: \"lane\" }>,\n\tcontext: Context,\n): Promise<LaneState> {\n\tconst operationId = stored.laneState.value.currentOperationId;\n\tlet operation: LaneState[\"operation\"] = null;\n\tif (operationId !== null) {\n\t\tconst [meta, state] = await Promise.all([\n\t\t\treader.getValue(operationMeta(operationId), context),\n\t\t\treader.getValue(operationState(operationId), context),\n\t\t]);\n\t\tif (meta === undefined) throw new SessionInvariantError(`Operation ${operationId} is missing op.meta`);\n\t\tif (state === undefined) throw new SessionInvariantError(`Operation ${operationId} is missing op.state`);\n\t\tif (meta.value.operationId !== operationId) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} metadata names operation ${JSON.stringify(meta.value.operationId)}`,\n\t\t\t);\n\t\t}\n\t\tif (meta.value.lane !== lane) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} belongs to lane ${JSON.stringify(meta.value.lane)}, not ${JSON.stringify(lane)}`,\n\t\t\t);\n\t\t}\n\t\tif (!stateMatchesIntent(meta.value.intent, state.value)) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} intent ${meta.value.intent.kind} does not match state ${state.value.at}`,\n\t\t\t);\n\t\t}\n\t\toperation = { meta: meta.value, state: state.value };\n\t}\n\n\treturn {\n\t\ttipId: stored.tip.value,\n\t\tconfiguration: stored.configuration.value,\n\t\tinbox: stored.laneState.value.inbox,\n\t\tlastOperationId: stored.laneState.value.lastOperationId,\n\t\toperation,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AgentMessage } from "../../types.ts";
|
|
2
|
+
import type { HarnessEvent, LaneQueuedItem } from "../agent-harness.ts";
|
|
3
|
+
import type { Context } from "../context.ts";
|
|
4
|
+
import type { CommitResult, Entry, InboxItem, NewEntry, OperationState, SessionReader } from "../session/types.ts";
|
|
5
|
+
import type { Lane } from "./lane.ts";
|
|
6
|
+
import type { ContinueOperationResult, Drive } from "./types.ts";
|
|
7
|
+
export declare function chainEntries<T extends {
|
|
8
|
+
id: string;
|
|
9
|
+
}>(parentId: string | null, items: readonly T[]): Array<T & {
|
|
10
|
+
parentId: string | null;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function entryLifecycleEvents(entry: Entry, lane: string, runId?: string): HarnessEvent[];
|
|
13
|
+
export declare function committedEntryEvents(entries: readonly NewEntry[], commit: CommitResult, lane: string, runId?: string, firstWriteIndex?: number): HarnessEvent[];
|
|
14
|
+
export declare function readBoundedEntries<TContext extends object | undefined, TState extends OperationState>(lane: Lane<TContext>, drive: Drive, capability: TState): Promise<ContinueOperationResult<Entry[]>>;
|
|
15
|
+
export declare function readBoundedContext<TContext extends object | undefined, TState extends OperationState>(lane: Lane<TContext>, drive: Drive, capability: TState): Promise<ContinueOperationResult<AgentMessage[]>>;
|
|
16
|
+
export declare function readLaneQueues(reader: SessionReader, inbox: readonly InboxItem[], context: Context): Promise<LaneQueuedItem[]>;
|
|
17
|
+
export declare function readPendingMessages(reader: SessionReader, ids: readonly string[], description: string, context: Context): Promise<Array<{
|
|
18
|
+
entryId: string;
|
|
19
|
+
message: AgentMessage;
|
|
20
|
+
}>>;
|
|
21
|
+
//# sourceMappingURL=transcript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../../../src/harness/runtime/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEnH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,uBAAuB,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjE,wBAAgB,YAA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AAE,EACtB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,KAAK,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,CAAC,CAAC,CAU5D","sourcesContent":["import type { AgentMessage } from \"../../types.ts\";\nimport type { HarnessEvent, LaneQueuedItem } from \"../agent-harness.ts\";\nimport type { Context } from \"../context.ts\";\nimport { materializeCommittedEntry } from \"../session/commit.ts\";\nimport { buildSessionContext } from \"../session/context.ts\";\nimport { SessionInvariantError } from \"../session/session.ts\";\nimport type { CommitResult, Entry, InboxItem, NewEntry, OperationState, SessionReader } from \"../session/types.ts\";\nimport { pendingEntry } from \"../session/values.ts\";\nimport type { Lane } from \"./lane.ts\";\nimport type { ContinueOperationResult, Drive } from \"./types.ts\";\n\nexport function chainEntries<T extends { id: string }>(\n\tparentId: string | null,\n\titems: readonly T[],\n): Array<T & { parentId: string | null }> {\n\treturn items.map((item) => {\n\t\tconst entry = { ...item, parentId };\n\t\tparentId = item.id;\n\t\treturn entry;\n\t});\n}\n\nexport function entryLifecycleEvents(entry: Entry, lane: string, runId?: string): HarnessEvent[] {\n\tconst operation = runId === undefined ? {} : { runId };\n\treturn entry.type === \"message\"\n\t\t? [\n\t\t\t\t{ type: \"message_start\", lane, ...operation, message: entry.message },\n\t\t\t\t{ type: \"message_end\", lane, ...operation, message: entry.message, entryId: entry.id },\n\t\t\t\t{ type: \"entry_added\", lane, entry },\n\t\t\t]\n\t\t: [{ type: \"entry_added\", lane, entry }];\n}\n\nexport function committedEntryEvents(\n\tentries: readonly NewEntry[],\n\tcommit: CommitResult,\n\tlane: string,\n\trunId?: string,\n\tfirstWriteIndex = 0,\n): HarnessEvent[] {\n\treturn entries.flatMap((entry, index) =>\n\t\tentryLifecycleEvents(\n\t\t\tmaterializeCommittedEntry(entry, commit.seqs[firstWriteIndex + index]!, commit.timestamp),\n\t\t\tlane,\n\t\t\trunId,\n\t\t),\n\t);\n}\n\nexport function readBoundedEntries<TContext extends object | undefined, TState extends OperationState>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n): Promise<ContinueOperationResult<Entry[]>> {\n\treturn lane.continueOperation(\n\t\tcapability,\n\t\tasync (state, _current, _meta, reader) => {\n\t\t\tif (state.tipId === null) throw new SessionInvariantError(\"Run operation has no Branch tip\");\n\t\t\tconst entries = await reader.scanBranch(\n\t\t\t\t{ start: state.tipId, stopAtType: \"compaction\", order: \"newestFirst\" },\n\t\t\t\tdrive.context,\n\t\t\t);\n\t\t\treturn { kind: \"return\", result: entries.reverse() };\n\t\t},\n\t\tdrive.context,\n\t);\n}\n\nexport async function readBoundedContext<TContext extends object | undefined, TState extends OperationState>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n): Promise<ContinueOperationResult<AgentMessage[]>> {\n\tconst entries = await readBoundedEntries(lane, drive, capability);\n\tif (entries.kind === \"cancel_requested\") return entries;\n\treturn {\n\t\tkind: \"result\",\n\t\tvalue: await buildSessionContext(\n\t\t\tentries.value,\n\t\t\t{ entryProjectors: lane.readConfig().entryProjectors },\n\t\t\tdrive.context,\n\t\t),\n\t};\n}\n\nexport function readLaneQueues(\n\treader: SessionReader,\n\tinbox: readonly InboxItem[],\n\tcontext: Context,\n): Promise<LaneQueuedItem[]> {\n\treturn Promise.all(\n\t\tinbox.map(async (item): Promise<LaneQueuedItem> => {\n\t\t\tconst stored = await reader.getValue(pendingEntry(item.entryId), context);\n\t\t\tif (stored === undefined) {\n\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is missing its payload`);\n\t\t\t}\n\t\t\tif (stored.value.type === \"message\") {\n\t\t\t\treturn { entryId: item.entryId, kind: item.kind, type: \"message\", message: stored.value.payload };\n\t\t\t}\n\t\t\tif (item.kind !== \"write\") {\n\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is not a message`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tentryId: item.entryId,\n\t\t\t\tkind: \"write\",\n\t\t\t\ttype: \"custom\",\n\t\t\t\tcustomType: stored.value.customType,\n\t\t\t\t...(stored.value.payload === undefined ? {} : { data: stored.value.payload }),\n\t\t\t};\n\t\t}),\n\t);\n}\n\nexport function readPendingMessages(\n\treader: SessionReader,\n\tids: readonly string[],\n\tdescription: string,\n\tcontext: Context,\n): Promise<Array<{ entryId: string; message: AgentMessage }>> {\n\treturn Promise.all(\n\t\tids.map(async (entryId) => {\n\t\t\tconst value = await reader.getValue(pendingEntry(entryId), context);\n\t\t\tif (value?.value.type !== \"message\") {\n\t\t\t\tthrow new SessionInvariantError(`${description} ${entryId} is missing its message payload`);\n\t\t\t}\n\t\t\treturn { entryId, message: value.value.payload };\n\t\t}),\n\t);\n}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { materializeCommittedEntry } from "../session/commit.js";
|
|
2
|
+
import { buildSessionContext } from "../session/context.js";
|
|
3
|
+
import { SessionInvariantError } from "../session/session.js";
|
|
4
|
+
import { pendingEntry } from "../session/values.js";
|
|
5
|
+
export function chainEntries(parentId, items) {
|
|
6
|
+
return items.map((item) => {
|
|
7
|
+
const entry = { ...item, parentId };
|
|
8
|
+
parentId = item.id;
|
|
9
|
+
return entry;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export function entryLifecycleEvents(entry, lane, runId) {
|
|
13
|
+
const operation = runId === undefined ? {} : { runId };
|
|
14
|
+
return entry.type === "message"
|
|
15
|
+
? [
|
|
16
|
+
{ type: "message_start", lane, ...operation, message: entry.message },
|
|
17
|
+
{ type: "message_end", lane, ...operation, message: entry.message, entryId: entry.id },
|
|
18
|
+
{ type: "entry_added", lane, entry },
|
|
19
|
+
]
|
|
20
|
+
: [{ type: "entry_added", lane, entry }];
|
|
21
|
+
}
|
|
22
|
+
export function committedEntryEvents(entries, commit, lane, runId, firstWriteIndex = 0) {
|
|
23
|
+
return entries.flatMap((entry, index) => entryLifecycleEvents(materializeCommittedEntry(entry, commit.seqs[firstWriteIndex + index], commit.timestamp), lane, runId));
|
|
24
|
+
}
|
|
25
|
+
export function readBoundedEntries(lane, drive, capability) {
|
|
26
|
+
return lane.continueOperation(capability, async (state, _current, _meta, reader) => {
|
|
27
|
+
if (state.tipId === null)
|
|
28
|
+
throw new SessionInvariantError("Run operation has no Branch tip");
|
|
29
|
+
const entries = await reader.scanBranch({ start: state.tipId, stopAtType: "compaction", order: "newestFirst" }, drive.context);
|
|
30
|
+
return { kind: "return", result: entries.reverse() };
|
|
31
|
+
}, drive.context);
|
|
32
|
+
}
|
|
33
|
+
export async function readBoundedContext(lane, drive, capability) {
|
|
34
|
+
const entries = await readBoundedEntries(lane, drive, capability);
|
|
35
|
+
if (entries.kind === "cancel_requested")
|
|
36
|
+
return entries;
|
|
37
|
+
return {
|
|
38
|
+
kind: "result",
|
|
39
|
+
value: await buildSessionContext(entries.value, { entryProjectors: lane.readConfig().entryProjectors }, drive.context),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function readLaneQueues(reader, inbox, context) {
|
|
43
|
+
return Promise.all(inbox.map(async (item) => {
|
|
44
|
+
const stored = await reader.getValue(pendingEntry(item.entryId), context);
|
|
45
|
+
if (stored === undefined) {
|
|
46
|
+
throw new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is missing its payload`);
|
|
47
|
+
}
|
|
48
|
+
if (stored.value.type === "message") {
|
|
49
|
+
return { entryId: item.entryId, kind: item.kind, type: "message", message: stored.value.payload };
|
|
50
|
+
}
|
|
51
|
+
if (item.kind !== "write") {
|
|
52
|
+
throw new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is not a message`);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
entryId: item.entryId,
|
|
56
|
+
kind: "write",
|
|
57
|
+
type: "custom",
|
|
58
|
+
customType: stored.value.customType,
|
|
59
|
+
...(stored.value.payload === undefined ? {} : { data: stored.value.payload }),
|
|
60
|
+
};
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
export function readPendingMessages(reader, ids, description, context) {
|
|
64
|
+
return Promise.all(ids.map(async (entryId) => {
|
|
65
|
+
const value = await reader.getValue(pendingEntry(entryId), context);
|
|
66
|
+
if (value?.value.type !== "message") {
|
|
67
|
+
throw new SessionInvariantError(`${description} ${entryId} is missing its message payload`);
|
|
68
|
+
}
|
|
69
|
+
return { entryId, message: value.value.payload };
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=transcript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.js","sourceRoot":"","sources":["../../../src/harness/runtime/transcript.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD,MAAM,UAAU,YAAY,CAC3B,QAAuB,EACvB,KAAmB,EACsB;IACzC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC;QACpC,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC;QACnB,OAAO,KAAK,CAAC;IAAA,CACb,CAAC,CAAC;AAAA,CACH;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAY,EAAE,IAAY,EAAE,KAAc,EAAkB;IAChG,MAAM,SAAS,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;IACvD,OAAO,KAAK,CAAC,IAAI,KAAK,SAAS;QAC9B,CAAC,CAAC;YACA,EAAE,IAAI,EAAE,eAAe,EA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AC;QACnG,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC3B,MAAM,IAAI,qBAAqB,CAAC,WAAW,IAAI,CAAC,IAAI,UAAU,IAAI,CAAC,OAAO,mBAAmB,CAAC,CAAC;QAChG,CAAC;QACD,OAAO;YACN,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU;YACnC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;SAC7E,CAAC;IAAA,CACF,CAAC,CACF,CAAC;AAAA,CACF;AAED,MAAM,UAAU,mBAAmB,CAClC,MAAqB,EACrB,GAAsB,EACtB,WAAmB,EACnB,OAAgB,EAC6C;IAC7D,OAAO,OAAO,CAAC,GAAG,CACjB,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;QACpE,IAAI,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,IAAI,qBAAqB,CAAC,GAAG,WAAW,IAAI,OAAO,iCAAiC,CAAC,CAAC;QAC7F,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IAAA,CACjD,CAAC,CACF,CAAC;AAAA,CACF","sourcesContent":["import type { AgentMessage } from \"../../types.ts\";\nimport type { HarnessEvent, LaneQueuedItem } from \"../agent-harness.ts\";\nimport type { Context } from \"../context.ts\";\nimport { materializeCommittedEntry } from \"../session/commit.ts\";\nimport { buildSessionContext } from \"../session/context.ts\";\nimport { SessionInvariantError } from \"../session/session.ts\";\nimport type { CommitResult, Entry, InboxItem, NewEntry, OperationState, SessionReader } from \"../session/types.ts\";\nimport { pendingEntry } from \"../session/values.ts\";\nimport type { Lane } from \"./lane.ts\";\nimport type { ContinueOperationResult, Drive } from \"./types.ts\";\n\nexport function chainEntries<T extends { id: string }>(\n\tparentId: string | null,\n\titems: readonly T[],\n): Array<T & { parentId: string | null }> {\n\treturn items.map((item) => {\n\t\tconst entry = { ...item, parentId };\n\t\tparentId = item.id;\n\t\treturn entry;\n\t});\n}\n\nexport function entryLifecycleEvents(entry: Entry, lane: string, runId?: string): HarnessEvent[] {\n\tconst operation = runId === undefined ? {} : { runId };\n\treturn entry.type === \"message\"\n\t\t? [\n\t\t\t\t{ type: \"message_start\", lane, ...operation, message: entry.message },\n\t\t\t\t{ type: \"message_end\", lane, ...operation, message: entry.message, entryId: entry.id },\n\t\t\t\t{ type: \"entry_added\", lane, entry },\n\t\t\t]\n\t\t: [{ type: \"entry_added\", lane, entry }];\n}\n\nexport function committedEntryEvents(\n\tentries: readonly NewEntry[],\n\tcommit: CommitResult,\n\tlane: string,\n\trunId?: string,\n\tfirstWriteIndex = 0,\n): HarnessEvent[] {\n\treturn entries.flatMap((entry, index) =>\n\t\tentryLifecycleEvents(\n\t\t\tmaterializeCommittedEntry(entry, commit.seqs[firstWriteIndex + index]!, commit.timestamp),\n\t\t\tlane,\n\t\t\trunId,\n\t\t),\n\t);\n}\n\nexport function readBoundedEntries<TContext extends object | undefined, TState extends OperationState>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n): Promise<ContinueOperationResult<Entry[]>> {\n\treturn lane.continueOperation(\n\t\tcapability,\n\t\tasync (state, _current, _meta, reader) => {\n\t\t\tif (state.tipId === null) throw new SessionInvariantError(\"Run operation has no Branch tip\");\n\t\t\tconst entries = await reader.scanBranch(\n\t\t\t\t{ start: state.tipId, stopAtType: \"compaction\", order: \"newestFirst\" },\n\t\t\t\tdrive.context,\n\t\t\t);\n\t\t\treturn { kind: \"return\", result: entries.reverse() };\n\t\t},\n\t\tdrive.context,\n\t);\n}\n\nexport async function readBoundedContext<TContext extends object | undefined, TState extends OperationState>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n): Promise<ContinueOperationResult<AgentMessage[]>> {\n\tconst entries = await readBoundedEntries(lane, drive, capability);\n\tif (entries.kind === \"cancel_requested\") return entries;\n\treturn {\n\t\tkind: \"result\",\n\t\tvalue: await buildSessionContext(\n\t\t\tentries.value,\n\t\t\t{ entryProjectors: lane.readConfig().entryProjectors },\n\t\t\tdrive.context,\n\t\t),\n\t};\n}\n\nexport function readLaneQueues(\n\treader: SessionReader,\n\tinbox: readonly InboxItem[],\n\tcontext: Context,\n): Promise<LaneQueuedItem[]> {\n\treturn Promise.all(\n\t\tinbox.map(async (item): Promise<LaneQueuedItem> => {\n\t\t\tconst stored = await reader.getValue(pendingEntry(item.entryId), context);\n\t\t\tif (stored === undefined) {\n\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is missing its payload`);\n\t\t\t}\n\t\t\tif (stored.value.type === \"message\") {\n\t\t\t\treturn { entryId: item.entryId, kind: item.kind, type: \"message\", message: stored.value.payload };\n\t\t\t}\n\t\t\tif (item.kind !== \"write\") {\n\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is not a message`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tentryId: item.entryId,\n\t\t\t\tkind: \"write\",\n\t\t\t\ttype: \"custom\",\n\t\t\t\tcustomType: stored.value.customType,\n\t\t\t\t...(stored.value.payload === undefined ? {} : { data: stored.value.payload }),\n\t\t\t};\n\t\t}),\n\t);\n}\n\nexport function readPendingMessages(\n\treader: SessionReader,\n\tids: readonly string[],\n\tdescription: string,\n\tcontext: Context,\n): Promise<Array<{ entryId: string; message: AgentMessage }>> {\n\treturn Promise.all(\n\t\tids.map(async (entryId) => {\n\t\t\tconst value = await reader.getValue(pendingEntry(entryId), context);\n\t\t\tif (value?.value.type !== \"message\") {\n\t\t\t\tthrow new SessionInvariantError(`${description} ${entryId} is missing its message payload`);\n\t\t\t}\n\t\t\treturn { entryId, message: value.value.payload };\n\t\t}),\n\t);\n}\n"]}
|