@draht/agent-core 2026.10.20 → 2026.10.23-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/dist/agent-loop.d.ts +6 -1
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +16 -2
- package/dist/agent-loop.js.map +1 -1
- package/dist/agent.d.ts +8 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +4 -0
- package/dist/agent.js.map +1 -1
- package/dist/index.d.ts +0 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -20
- package/dist/index.js.map +1 -1
- package/dist/proxy.d.ts +2 -5
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +2 -14
- package/dist/proxy.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -47
- package/dist/harness/agent-harness.d.ts +0 -716
- package/dist/harness/agent-harness.d.ts.map +0 -1
- package/dist/harness/agent-harness.js +0 -6
- package/dist/harness/agent-harness.js.map +0 -1
- package/dist/harness/compaction/branch-summarization.d.ts +0 -68
- package/dist/harness/compaction/branch-summarization.d.ts.map +0 -1
- package/dist/harness/compaction/branch-summarization.js +0 -176
- package/dist/harness/compaction/branch-summarization.js.map +0 -1
- package/dist/harness/compaction/compaction.d.ts +0 -126
- package/dist/harness/compaction/compaction.d.ts.map +0 -1
- package/dist/harness/compaction/compaction.js +0 -561
- package/dist/harness/compaction/compaction.js.map +0 -1
- package/dist/harness/compaction/utils.d.ts +0 -28
- package/dist/harness/compaction/utils.d.ts.map +0 -1
- package/dist/harness/compaction/utils.js +0 -123
- package/dist/harness/compaction/utils.js.map +0 -1
- package/dist/harness/config.d.ts +0 -9
- package/dist/harness/config.d.ts.map +0 -1
- package/dist/harness/config.js +0 -35
- package/dist/harness/config.js.map +0 -1
- package/dist/harness/context.d.ts +0 -9
- package/dist/harness/context.d.ts.map +0 -1
- package/dist/harness/context.js +0 -13
- package/dist/harness/context.js.map +0 -1
- package/dist/harness/env/nodejs.d.ts +0 -43
- package/dist/harness/env/nodejs.d.ts.map +0 -1
- package/dist/harness/env/nodejs.js +0 -865
- package/dist/harness/env/nodejs.js.map +0 -1
- package/dist/harness/events.d.ts +0 -24
- package/dist/harness/events.d.ts.map +0 -1
- package/dist/harness/events.js +0 -233
- package/dist/harness/events.js.map +0 -1
- package/dist/harness/execution/assistant.d.ts +0 -42
- package/dist/harness/execution/assistant.d.ts.map +0 -1
- package/dist/harness/execution/assistant.js +0 -82
- package/dist/harness/execution/assistant.js.map +0 -1
- package/dist/harness/execution/effect-gate.d.ts +0 -22
- package/dist/harness/execution/effect-gate.d.ts.map +0 -1
- package/dist/harness/execution/effect-gate.js +0 -49
- package/dist/harness/execution/effect-gate.js.map +0 -1
- package/dist/harness/execution/tools.d.ts +0 -67
- package/dist/harness/execution/tools.d.ts.map +0 -1
- package/dist/harness/execution/tools.js +0 -119
- package/dist/harness/execution/tools.js.map +0 -1
- package/dist/harness/execution-env.d.ts +0 -4
- package/dist/harness/execution-env.d.ts.map +0 -1
- package/dist/harness/execution-env.js +0 -3
- package/dist/harness/execution-env.js.map +0 -1
- package/dist/harness/hooks.d.ts +0 -38
- package/dist/harness/hooks.d.ts.map +0 -1
- package/dist/harness/hooks.js +0 -406
- package/dist/harness/hooks.js.map +0 -1
- package/dist/harness/messages.d.ts +0 -51
- package/dist/harness/messages.d.ts.map +0 -1
- package/dist/harness/messages.js +0 -103
- package/dist/harness/messages.js.map +0 -1
- package/dist/harness/pico3/bash.d.ts +0 -10
- package/dist/harness/pico3/bash.d.ts.map +0 -1
- package/dist/harness/pico3/bash.js +0 -25
- package/dist/harness/pico3/bash.js.map +0 -1
- package/dist/harness/pico3/bounded.d.ts +0 -21
- package/dist/harness/pico3/bounded.d.ts.map +0 -1
- package/dist/harness/pico3/bounded.js +0 -98
- package/dist/harness/pico3/bounded.js.map +0 -1
- package/dist/harness/pico3/chord.d.ts +0 -41
- package/dist/harness/pico3/chord.d.ts.map +0 -1
- package/dist/harness/pico3/chord.js +0 -147
- package/dist/harness/pico3/chord.js.map +0 -1
- package/dist/harness/pico3/context.d.ts +0 -16
- package/dist/harness/pico3/context.d.ts.map +0 -1
- package/dist/harness/pico3/context.js +0 -88
- package/dist/harness/pico3/context.js.map +0 -1
- package/dist/harness/pico3/harness.d.ts +0 -198
- package/dist/harness/pico3/harness.d.ts.map +0 -1
- package/dist/harness/pico3/harness.js +0 -654
- package/dist/harness/pico3/harness.js.map +0 -1
- package/dist/harness/pico3/hooks.d.ts +0 -10
- package/dist/harness/pico3/hooks.d.ts.map +0 -1
- package/dist/harness/pico3/hooks.js +0 -33
- package/dist/harness/pico3/hooks.js.map +0 -1
- package/dist/harness/pico3/index.d.ts +0 -19
- package/dist/harness/pico3/index.d.ts.map +0 -1
- package/dist/harness/pico3/index.js +0 -15
- package/dist/harness/pico3/index.js.map +0 -1
- package/dist/harness/pico3/jsonl.d.ts +0 -58
- package/dist/harness/pico3/jsonl.d.ts.map +0 -1
- package/dist/harness/pico3/jsonl.js +0 -325
- package/dist/harness/pico3/jsonl.js.map +0 -1
- package/dist/harness/pico3/kinds/collapse.d.ts +0 -49
- package/dist/harness/pico3/kinds/collapse.d.ts.map +0 -1
- package/dist/harness/pico3/kinds/collapse.js +0 -191
- package/dist/harness/pico3/kinds/collapse.js.map +0 -1
- package/dist/harness/pico3/kinds/entries.d.ts +0 -78
- package/dist/harness/pico3/kinds/entries.d.ts.map +0 -1
- package/dist/harness/pico3/kinds/entries.js +0 -13
- package/dist/harness/pico3/kinds/entries.js.map +0 -1
- package/dist/harness/pico3/kinds/frames.d.ts +0 -9
- package/dist/harness/pico3/kinds/frames.d.ts.map +0 -1
- package/dist/harness/pico3/kinds/frames.js +0 -75
- package/dist/harness/pico3/kinds/frames.js.map +0 -1
- package/dist/harness/pico3/kinds/generation.d.ts +0 -94
- package/dist/harness/pico3/kinds/generation.d.ts.map +0 -1
- package/dist/harness/pico3/kinds/generation.js +0 -504
- package/dist/harness/pico3/kinds/generation.js.map +0 -1
- package/dist/harness/pico3/kinds/job.d.ts +0 -44
- package/dist/harness/pico3/kinds/job.d.ts.map +0 -1
- package/dist/harness/pico3/kinds/job.js +0 -143
- package/dist/harness/pico3/kinds/job.js.map +0 -1
- package/dist/harness/pico3/kinds/plugin.d.ts +0 -15
- package/dist/harness/pico3/kinds/plugin.d.ts.map +0 -1
- package/dist/harness/pico3/kinds/plugin.js +0 -35
- package/dist/harness/pico3/kinds/plugin.js.map +0 -1
- package/dist/harness/pico3/kinds/post-tools.d.ts +0 -22
- package/dist/harness/pico3/kinds/post-tools.d.ts.map +0 -1
- package/dist/harness/pico3/kinds/post-tools.js +0 -145
- package/dist/harness/pico3/kinds/post-tools.js.map +0 -1
- package/dist/harness/pico3/kinds/task-api.d.ts +0 -3
- package/dist/harness/pico3/kinds/task-api.d.ts.map +0 -1
- package/dist/harness/pico3/kinds/task-api.js +0 -45
- package/dist/harness/pico3/kinds/task-api.js.map +0 -1
- package/dist/harness/pico3/kinds/tool.d.ts +0 -43
- package/dist/harness/pico3/kinds/tool.d.ts.map +0 -1
- package/dist/harness/pico3/kinds/tool.js +0 -373
- package/dist/harness/pico3/kinds/tool.js.map +0 -1
- package/dist/harness/pico3/legacy-tracker.d.ts +0 -11
- package/dist/harness/pico3/legacy-tracker.d.ts.map +0 -1
- package/dist/harness/pico3/legacy-tracker.js +0 -41
- package/dist/harness/pico3/legacy-tracker.js.map +0 -1
- package/dist/harness/pico3/membrane.d.ts +0 -23
- package/dist/harness/pico3/membrane.d.ts.map +0 -1
- package/dist/harness/pico3/membrane.js +0 -141
- package/dist/harness/pico3/membrane.js.map +0 -1
- package/dist/harness/pico3/memory.d.ts +0 -53
- package/dist/harness/pico3/memory.d.ts.map +0 -1
- package/dist/harness/pico3/memory.js +0 -264
- package/dist/harness/pico3/memory.js.map +0 -1
- package/dist/harness/pico3/scheduler.d.ts +0 -49
- package/dist/harness/pico3/scheduler.d.ts.map +0 -1
- package/dist/harness/pico3/scheduler.js +0 -438
- package/dist/harness/pico3/scheduler.js.map +0 -1
- package/dist/harness/pico3/session.d.ts +0 -264
- package/dist/harness/pico3/session.d.ts.map +0 -1
- package/dist/harness/pico3/session.js +0 -1348
- package/dist/harness/pico3/session.js.map +0 -1
- package/dist/harness/pico3/system.d.ts +0 -126
- package/dist/harness/pico3/system.d.ts.map +0 -1
- package/dist/harness/pico3/system.js +0 -244
- package/dist/harness/pico3/system.js.map +0 -1
- package/dist/harness/pico3/types.d.ts +0 -973
- package/dist/harness/pico3/types.d.ts.map +0 -1
- package/dist/harness/pico3/types.js +0 -106
- package/dist/harness/pico3/types.js.map +0 -1
- package/dist/harness/pico3/view.d.ts +0 -34
- package/dist/harness/pico3/view.d.ts.map +0 -1
- package/dist/harness/pico3/view.js +0 -411
- package/dist/harness/pico3/view.js.map +0 -1
- package/dist/harness/prompt-templates.d.ts +0 -49
- package/dist/harness/prompt-templates.d.ts.map +0 -1
- package/dist/harness/prompt-templates.js +0 -225
- package/dist/harness/prompt-templates.js.map +0 -1
- package/dist/harness/result.d.ts +0 -133
- package/dist/harness/result.d.ts.map +0 -1
- package/dist/harness/result.js +0 -81
- package/dist/harness/result.js.map +0 -1
- package/dist/harness/runtime/drive/boundary.d.ts +0 -28
- package/dist/harness/runtime/drive/boundary.d.ts.map +0 -1
- package/dist/harness/runtime/drive/boundary.js +0 -173
- package/dist/harness/runtime/drive/boundary.js.map +0 -1
- package/dist/harness/runtime/drive/checkpoint.d.ts +0 -8
- package/dist/harness/runtime/drive/checkpoint.d.ts.map +0 -1
- package/dist/harness/runtime/drive/checkpoint.js +0 -133
- package/dist/harness/runtime/drive/checkpoint.js.map +0 -1
- package/dist/harness/runtime/drive/deferred.d.ts +0 -15
- package/dist/harness/runtime/drive/deferred.d.ts.map +0 -1
- package/dist/harness/runtime/drive/deferred.js +0 -179
- package/dist/harness/runtime/drive/deferred.js.map +0 -1
- package/dist/harness/runtime/drive/generation.d.ts +0 -8
- package/dist/harness/runtime/drive/generation.d.ts.map +0 -1
- package/dist/harness/runtime/drive/generation.js +0 -205
- package/dist/harness/runtime/drive/generation.js.map +0 -1
- package/dist/harness/runtime/drive/reconcile.d.ts +0 -5
- package/dist/harness/runtime/drive/reconcile.d.ts.map +0 -1
- package/dist/harness/runtime/drive/reconcile.js +0 -140
- package/dist/harness/runtime/drive/reconcile.js.map +0 -1
- package/dist/harness/runtime/drive/recovery.d.ts +0 -8
- package/dist/harness/runtime/drive/recovery.d.ts.map +0 -1
- package/dist/harness/runtime/drive/recovery.js +0 -85
- package/dist/harness/runtime/drive/recovery.js.map +0 -1
- package/dist/harness/runtime/drive/response.d.ts +0 -23
- package/dist/harness/runtime/drive/response.d.ts.map +0 -1
- package/dist/harness/runtime/drive/response.js +0 -394
- package/dist/harness/runtime/drive/response.js.map +0 -1
- package/dist/harness/runtime/drive/retry.d.ts +0 -4
- package/dist/harness/runtime/drive/retry.d.ts.map +0 -1
- package/dist/harness/runtime/drive/retry.js +0 -34
- package/dist/harness/runtime/drive/retry.js.map +0 -1
- package/dist/harness/runtime/drive/structural.d.ts +0 -32
- package/dist/harness/runtime/drive/structural.d.ts.map +0 -1
- package/dist/harness/runtime/drive/structural.js +0 -929
- package/dist/harness/runtime/drive/structural.js.map +0 -1
- package/dist/harness/runtime/drive/terminal.d.ts +0 -7
- package/dist/harness/runtime/drive/terminal.d.ts.map +0 -1
- package/dist/harness/runtime/drive/terminal.js +0 -49
- package/dist/harness/runtime/drive/terminal.js.map +0 -1
- package/dist/harness/runtime/drive/tool-placement.d.ts +0 -14
- package/dist/harness/runtime/drive/tool-placement.d.ts.map +0 -1
- package/dist/harness/runtime/drive/tool-placement.js +0 -219
- package/dist/harness/runtime/drive/tool-placement.js.map +0 -1
- package/dist/harness/runtime/drive/tools.d.ts +0 -6
- package/dist/harness/runtime/drive/tools.d.ts.map +0 -1
- package/dist/harness/runtime/drive/tools.js +0 -449
- package/dist/harness/runtime/drive/tools.js.map +0 -1
- package/dist/harness/runtime/drive.d.ts +0 -6
- package/dist/harness/runtime/drive.d.ts.map +0 -1
- package/dist/harness/runtime/drive.js +0 -93
- package/dist/harness/runtime/drive.js.map +0 -1
- package/dist/harness/runtime/harness.d.ts +0 -59
- package/dist/harness/runtime/harness.d.ts.map +0 -1
- package/dist/harness/runtime/harness.js +0 -311
- package/dist/harness/runtime/harness.js.map +0 -1
- package/dist/harness/runtime/index.d.ts +0 -2
- package/dist/harness/runtime/index.d.ts.map +0 -1
- package/dist/harness/runtime/index.js +0 -2
- package/dist/harness/runtime/index.js.map +0 -1
- package/dist/harness/runtime/lane.d.ts +0 -118
- package/dist/harness/runtime/lane.d.ts.map +0 -1
- package/dist/harness/runtime/lane.js +0 -1575
- package/dist/harness/runtime/lane.js.map +0 -1
- package/dist/harness/runtime/progress.d.ts +0 -15
- package/dist/harness/runtime/progress.d.ts.map +0 -1
- package/dist/harness/runtime/progress.js +0 -66
- package/dist/harness/runtime/progress.js.map +0 -1
- package/dist/harness/runtime/reducer.d.ts +0 -5
- package/dist/harness/runtime/reducer.d.ts.map +0 -1
- package/dist/harness/runtime/reducer.js +0 -240
- package/dist/harness/runtime/reducer.js.map +0 -1
- package/dist/harness/runtime/restore.d.ts +0 -24
- package/dist/harness/runtime/restore.d.ts.map +0 -1
- package/dist/harness/runtime/restore.js +0 -117
- package/dist/harness/runtime/restore.js.map +0 -1
- package/dist/harness/runtime/transcript.d.ts +0 -21
- package/dist/harness/runtime/transcript.d.ts.map +0 -1
- package/dist/harness/runtime/transcript.js +0 -72
- package/dist/harness/runtime/transcript.js.map +0 -1
- package/dist/harness/runtime/types.d.ts +0 -105
- package/dist/harness/runtime/types.d.ts.map +0 -1
- package/dist/harness/runtime/types.js +0 -61
- package/dist/harness/runtime/types.js.map +0 -1
- package/dist/harness/session/commit.d.ts +0 -53
- package/dist/harness/session/commit.d.ts.map +0 -1
- package/dist/harness/session/commit.js +0 -57
- package/dist/harness/session/commit.js.map +0 -1
- package/dist/harness/session/context.d.ts +0 -10
- package/dist/harness/session/context.d.ts.map +0 -1
- package/dist/harness/session/context.js +0 -49
- package/dist/harness/session/context.js.map +0 -1
- package/dist/harness/session/fork-policy.d.ts +0 -21
- package/dist/harness/session/fork-policy.d.ts.map +0 -1
- package/dist/harness/session/fork-policy.js +0 -55
- package/dist/harness/session/fork-policy.js.map +0 -1
- package/dist/harness/session/fork.d.ts +0 -16
- package/dist/harness/session/fork.d.ts.map +0 -1
- package/dist/harness/session/fork.js +0 -79
- package/dist/harness/session/fork.js.map +0 -1
- package/dist/harness/session/in-memory-storage-state.d.ts +0 -39
- package/dist/harness/session/in-memory-storage-state.d.ts.map +0 -1
- package/dist/harness/session/in-memory-storage-state.js +0 -276
- package/dist/harness/session/in-memory-storage-state.js.map +0 -1
- package/dist/harness/session/index.d.ts +0 -11
- package/dist/harness/session/index.d.ts.map +0 -1
- package/dist/harness/session/index.js +0 -9
- package/dist/harness/session/index.js.map +0 -1
- package/dist/harness/session/jsonl/codec.d.ts +0 -21
- package/dist/harness/session/jsonl/codec.d.ts.map +0 -1
- package/dist/harness/session/jsonl/codec.js +0 -45
- package/dist/harness/session/jsonl/codec.js.map +0 -1
- package/dist/harness/session/jsonl/fork.d.ts +0 -38
- package/dist/harness/session/jsonl/fork.d.ts.map +0 -1
- package/dist/harness/session/jsonl/fork.js +0 -264
- package/dist/harness/session/jsonl/fork.js.map +0 -1
- package/dist/harness/session/jsonl/index.d.ts +0 -4
- package/dist/harness/session/jsonl/index.d.ts.map +0 -1
- package/dist/harness/session/jsonl/index.js +0 -4
- package/dist/harness/session/jsonl/index.js.map +0 -1
- package/dist/harness/session/jsonl/io.d.ts +0 -14
- package/dist/harness/session/jsonl/io.d.ts.map +0 -1
- package/dist/harness/session/jsonl/io.js +0 -86
- package/dist/harness/session/jsonl/io.js.map +0 -1
- package/dist/harness/session/jsonl/legacy-v3.d.ts +0 -44
- package/dist/harness/session/jsonl/legacy-v3.d.ts.map +0 -1
- package/dist/harness/session/jsonl/legacy-v3.js +0 -462
- package/dist/harness/session/jsonl/legacy-v3.js.map +0 -1
- package/dist/harness/session/jsonl/repo.d.ts +0 -35
- package/dist/harness/session/jsonl/repo.d.ts.map +0 -1
- package/dist/harness/session/jsonl/repo.js +0 -301
- package/dist/harness/session/jsonl/repo.js.map +0 -1
- package/dist/harness/session/jsonl/storage.d.ts +0 -41
- package/dist/harness/session/jsonl/storage.d.ts.map +0 -1
- package/dist/harness/session/jsonl/storage.js +0 -200
- package/dist/harness/session/jsonl/storage.js.map +0 -1
- package/dist/harness/session/jsonl/types.d.ts +0 -39
- package/dist/harness/session/jsonl/types.d.ts.map +0 -1
- package/dist/harness/session/jsonl/types.js +0 -3
- package/dist/harness/session/jsonl/types.js.map +0 -1
- package/dist/harness/session/memory.d.ts +0 -48
- package/dist/harness/session/memory.d.ts.map +0 -1
- package/dist/harness/session/memory.js +0 -369
- package/dist/harness/session/memory.js.map +0 -1
- package/dist/harness/session/mutation-line.d.ts +0 -8
- package/dist/harness/session/mutation-line.d.ts.map +0 -1
- package/dist/harness/session/mutation-line.js +0 -21
- package/dist/harness/session/mutation-line.js.map +0 -1
- package/dist/harness/session/session.d.ts +0 -82
- package/dist/harness/session/session.d.ts.map +0 -1
- package/dist/harness/session/session.js +0 -361
- package/dist/harness/session/session.js.map +0 -1
- package/dist/harness/session/testing/benchmark/datasets.d.ts +0 -12
- package/dist/harness/session/testing/benchmark/datasets.d.ts.map +0 -1
- package/dist/harness/session/testing/benchmark/datasets.js +0 -24
- package/dist/harness/session/testing/benchmark/datasets.js.map +0 -1
- package/dist/harness/session/testing/benchmark/session-repo.d.ts +0 -42
- package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +0 -1
- package/dist/harness/session/testing/benchmark/session-repo.js +0 -127
- package/dist/harness/session/testing/benchmark/session-repo.js.map +0 -1
- package/dist/harness/session/testing/benchmark/storage.d.ts +0 -25
- package/dist/harness/session/testing/benchmark/storage.d.ts.map +0 -1
- package/dist/harness/session/testing/benchmark/storage.js +0 -114
- package/dist/harness/session/testing/benchmark/storage.js.map +0 -1
- package/dist/harness/session/testing/conformance/session-repo.d.ts +0 -23
- package/dist/harness/session/testing/conformance/session-repo.d.ts.map +0 -1
- package/dist/harness/session/testing/conformance/session-repo.js +0 -809
- package/dist/harness/session/testing/conformance/session-repo.js.map +0 -1
- package/dist/harness/session/testing/conformance/storage.d.ts +0 -4
- package/dist/harness/session/testing/conformance/storage.d.ts.map +0 -1
- package/dist/harness/session/testing/conformance/storage.js +0 -600
- package/dist/harness/session/testing/conformance/storage.js.map +0 -1
- package/dist/harness/session/testing/gating-storage.d.ts +0 -26
- package/dist/harness/session/testing/gating-storage.d.ts.map +0 -1
- package/dist/harness/session/testing/gating-storage.js +0 -100
- package/dist/harness/session/testing/gating-storage.js.map +0 -1
- package/dist/harness/session/testing/index.d.ts +0 -10
- package/dist/harness/session/testing/index.d.ts.map +0 -1
- package/dist/harness/session/testing/index.js +0 -9
- package/dist/harness/session/testing/index.js.map +0 -1
- package/dist/harness/session/testing/instrumented-storage.d.ts +0 -11
- package/dist/harness/session/testing/instrumented-storage.d.ts.map +0 -1
- package/dist/harness/session/testing/instrumented-storage.js +0 -16
- package/dist/harness/session/testing/instrumented-storage.js.map +0 -1
- package/dist/harness/session/testing/storage-decorator.d.ts +0 -20
- package/dist/harness/session/testing/storage-decorator.d.ts.map +0 -1
- package/dist/harness/session/testing/storage-decorator.js +0 -41
- package/dist/harness/session/testing/storage-decorator.js.map +0 -1
- package/dist/harness/session/testing/types.d.ts +0 -12
- package/dist/harness/session/testing/types.d.ts.map +0 -1
- package/dist/harness/session/testing/types.js +0 -2
- package/dist/harness/session/testing/types.js.map +0 -1
- package/dist/harness/session/types.d.ts +0 -512
- package/dist/harness/session/types.d.ts.map +0 -1
- package/dist/harness/session/types.js +0 -9
- package/dist/harness/session/types.js.map +0 -1
- package/dist/harness/session/values.d.ts +0 -95
- package/dist/harness/session/values.d.ts.map +0 -1
- package/dist/harness/session/values.js +0 -81
- package/dist/harness/session/values.js.map +0 -1
- package/dist/harness/skills.d.ts +0 -46
- package/dist/harness/skills.d.ts.map +0 -1
- package/dist/harness/skills.js +0 -326
- package/dist/harness/skills.js.map +0 -1
- package/dist/harness/system-prompt.d.ts +0 -3
- package/dist/harness/system-prompt.d.ts.map +0 -1
- package/dist/harness/system-prompt.js +0 -30
- package/dist/harness/system-prompt.js.map +0 -1
- package/dist/harness/telemetry.d.ts +0 -1242
- package/dist/harness/telemetry.d.ts.map +0 -1
- package/dist/harness/telemetry.js +0 -527
- package/dist/harness/telemetry.js.map +0 -1
- package/dist/harness/tools/bash.d.ts +0 -27
- package/dist/harness/tools/bash.d.ts.map +0 -1
- package/dist/harness/tools/bash.js +0 -105
- package/dist/harness/tools/bash.js.map +0 -1
- package/dist/harness/tools/edit-diff.d.ts +0 -89
- package/dist/harness/tools/edit-diff.d.ts.map +0 -1
- package/dist/harness/tools/edit-diff.js +0 -386
- package/dist/harness/tools/edit-diff.js.map +0 -1
- package/dist/harness/tools/edit.d.ts +0 -19
- package/dist/harness/tools/edit.d.ts.map +0 -1
- package/dist/harness/tools/edit.js +0 -108
- package/dist/harness/tools/edit.js.map +0 -1
- package/dist/harness/tools/file-mutation-queue.d.ts +0 -5
- package/dist/harness/tools/file-mutation-queue.d.ts.map +0 -1
- package/dist/harness/tools/file-mutation-queue.js +0 -46
- package/dist/harness/tools/file-mutation-queue.js.map +0 -1
- package/dist/harness/tools/image.d.ts +0 -3
- package/dist/harness/tools/image.d.ts.map +0 -1
- package/dist/harness/tools/image.js +0 -106
- package/dist/harness/tools/image.js.map +0 -1
- package/dist/harness/tools/index.d.ts +0 -6
- package/dist/harness/tools/index.d.ts.map +0 -1
- package/dist/harness/tools/index.js +0 -5
- package/dist/harness/tools/index.js.map +0 -1
- package/dist/harness/tools/path-utils.d.ts +0 -5
- package/dist/harness/tools/path-utils.d.ts.map +0 -1
- package/dist/harness/tools/path-utils.js +0 -26
- package/dist/harness/tools/path-utils.js.map +0 -1
- package/dist/harness/tools/read.d.ts +0 -35
- package/dist/harness/tools/read.d.ts.map +0 -1
- package/dist/harness/tools/read.js +0 -108
- package/dist/harness/tools/read.js.map +0 -1
- package/dist/harness/tools/tool-context.d.ts +0 -6
- package/dist/harness/tools/tool-context.d.ts.map +0 -1
- package/dist/harness/tools/tool-context.js +0 -2
- package/dist/harness/tools/tool-context.js.map +0 -1
- package/dist/harness/tools/write.d.ts +0 -11
- package/dist/harness/tools/write.d.ts.map +0 -1
- package/dist/harness/tools/write.js +0 -31
- package/dist/harness/tools/write.js.map +0 -1
- package/dist/harness/types.d.ts +0 -305
- package/dist/harness/types.d.ts.map +0 -1
- package/dist/harness/types.js +0 -75
- package/dist/harness/types.js.map +0 -1
- package/dist/harness/utils/adaptive-publisher.d.ts +0 -24
- package/dist/harness/utils/adaptive-publisher.d.ts.map +0 -1
- package/dist/harness/utils/adaptive-publisher.js +0 -79
- package/dist/harness/utils/adaptive-publisher.js.map +0 -1
- package/dist/harness/utils/output-capture.d.ts +0 -31
- package/dist/harness/utils/output-capture.d.ts.map +0 -1
- package/dist/harness/utils/output-capture.js +0 -217
- package/dist/harness/utils/output-capture.js.map +0 -1
- package/dist/harness/utils/shell-output.d.ts +0 -29
- package/dist/harness/utils/shell-output.d.ts.map +0 -1
- package/dist/harness/utils/shell-output.js +0 -71
- package/dist/harness/utils/shell-output.js.map +0 -1
- package/dist/harness/utils/truncate.d.ts +0 -71
- package/dist/harness/utils/truncate.d.ts.map +0 -1
- package/dist/harness/utils/truncate.js +0 -296
- package/dist/harness/utils/truncate.js.map +0 -1
- package/dist/harness/utils/usage.d.ts +0 -4
- package/dist/harness/utils/usage.d.ts.map +0 -1
- package/dist/harness/utils/usage.js +0 -33
- package/dist/harness/utils/usage.js.map +0 -1
- package/dist/node.d.ts +0 -3
- package/dist/node.d.ts.map +0 -1
- package/dist/node.js +0 -3
- package/dist/node.js.map +0 -1
- package/dist/search/index.d.ts +0 -29
- package/dist/search/index.d.ts.map +0 -1
- package/dist/search/index.js +0 -2
- package/dist/search/index.js.map +0 -1
|
@@ -1,654 +0,0 @@
|
|
|
1
|
-
import { withAbortSignal } from "@draht/chord/context";
|
|
2
|
-
import { createHookRunners } from "./hooks.js";
|
|
3
|
-
import { chooseThrough, collapse } from "./kinds/collapse.js";
|
|
4
|
-
import { entries as builtinEntries } from "./kinds/entries.js";
|
|
5
|
-
import { generation } from "./kinds/generation.js";
|
|
6
|
-
import { job } from "./kinds/job.js";
|
|
7
|
-
import { plugin } from "./kinds/plugin.js";
|
|
8
|
-
import { postTools } from "./kinds/post-tools.js";
|
|
9
|
-
import { tool } from "./kinds/tool.js";
|
|
10
|
-
import { Scheduler } from "./scheduler.js";
|
|
11
|
-
import { isCoreKind, Session } from "./session.js";
|
|
12
|
-
import { systemSections } from "./system.js";
|
|
13
|
-
import { Forbidden, } from "./types.js";
|
|
14
|
-
import { ViewManager } from "./view.js";
|
|
15
|
-
const KERNEL = { type: "kernel" };
|
|
16
|
-
export class Harness {
|
|
17
|
-
session;
|
|
18
|
-
scheduler;
|
|
19
|
-
views;
|
|
20
|
-
kinds;
|
|
21
|
-
namespaces = new Map();
|
|
22
|
-
tools = new Map();
|
|
23
|
-
sectionMap = new Map();
|
|
24
|
-
entryKinds = new Map();
|
|
25
|
-
revisions = { sections: 0, tools: 0 };
|
|
26
|
-
plugins;
|
|
27
|
-
hookRegistrations = [];
|
|
28
|
-
conversationListeners = new Set();
|
|
29
|
-
onReport;
|
|
30
|
-
now;
|
|
31
|
-
ctx;
|
|
32
|
-
options;
|
|
33
|
-
resumed = false;
|
|
34
|
-
suspended = false;
|
|
35
|
-
static async open(storage, options, ctx) {
|
|
36
|
-
const h = new Harness(storage, options, ctx);
|
|
37
|
-
await h.init();
|
|
38
|
-
return h;
|
|
39
|
-
}
|
|
40
|
-
constructor(storage, options, ctx) {
|
|
41
|
-
this.ctx = ctx;
|
|
42
|
-
this.options = options;
|
|
43
|
-
this.now = options.now ?? Date.now;
|
|
44
|
-
this.onReport = (error) => {
|
|
45
|
-
try {
|
|
46
|
-
options.onReport?.(error);
|
|
47
|
-
}
|
|
48
|
-
catch { }
|
|
49
|
-
};
|
|
50
|
-
// Fixed core, installed internally. User kinds may not replace or shadow a built-in.
|
|
51
|
-
const builtins = [generation, tool, postTools, collapse, job, plugin];
|
|
52
|
-
this.kinds = new Map(builtins.map((k) => [k.name, k]));
|
|
53
|
-
for (const k of options.taskKinds ?? []) {
|
|
54
|
-
if (k.name.startsWith("pi."))
|
|
55
|
-
throw new Error(`task kind "${k.name}": names beginning with "pi." are reserved`);
|
|
56
|
-
if (this.kinds.has(k.name))
|
|
57
|
-
throw new Error(`task kind "${k.name}" registered twice`);
|
|
58
|
-
this.kinds.set(k.name, k);
|
|
59
|
-
}
|
|
60
|
-
for (const t of options.tools ?? [])
|
|
61
|
-
this.registerTool(t, "open");
|
|
62
|
-
for (const s of Object.values(systemSections))
|
|
63
|
-
this.sectionMap.set(s.key, s);
|
|
64
|
-
for (const s of options.sections ?? [])
|
|
65
|
-
this.registerSection(s, "open");
|
|
66
|
-
for (const e of Object.values(builtinEntries))
|
|
67
|
-
this.entryKinds.set(e.kind, e);
|
|
68
|
-
this.plugins = new Map(Object.entries(options.plugins ?? {}));
|
|
69
|
-
this.session = new Session(storage, this.kinds, this.namespaces, this.now); // throws if the Storage already has an owner; validates config disjointness
|
|
70
|
-
this.session.onReport = this.onReport;
|
|
71
|
-
this.views = new ViewManager(this.session, this.onReport);
|
|
72
|
-
this.session.lineListeners.add((result) => this.views.update(result));
|
|
73
|
-
this.session.listeners.add((result) => {
|
|
74
|
-
this.views.deliver();
|
|
75
|
-
for (const conversation of result.changes.conversations)
|
|
76
|
-
this.notifyConversation(conversation);
|
|
77
|
-
});
|
|
78
|
-
const self = this;
|
|
79
|
-
const hooksFor = createHookRunners(() => this.hookRegistrations, (c) => this.session.index.ancestors(c), this.onReport);
|
|
80
|
-
this.scheduler = new Scheduler({
|
|
81
|
-
session: this.session,
|
|
82
|
-
kinds: this.kinds,
|
|
83
|
-
onReport: this.onReport,
|
|
84
|
-
ctx,
|
|
85
|
-
runtime(task, invoker, _ictx) {
|
|
86
|
-
return {
|
|
87
|
-
taskId: task.id,
|
|
88
|
-
conversationId: task.conversationId,
|
|
89
|
-
kind: invoker.kind,
|
|
90
|
-
commit: (fn, c) => {
|
|
91
|
-
const owns = self.session.liveTasks.get(task.id)?.owns ?? [];
|
|
92
|
-
const docs = owns.flatMap((id) => [
|
|
93
|
-
{ doc: "rewindable", conversationId: id },
|
|
94
|
-
{ doc: "sticky", conversationId: id },
|
|
95
|
-
]);
|
|
96
|
-
return self.session
|
|
97
|
-
.commit(invoker, (tx, lineCtx) => fn(tx, self.session.liveTasks.get(task.id), lineCtx), c, {
|
|
98
|
-
docs,
|
|
99
|
-
})
|
|
100
|
-
.then((r) => r.value);
|
|
101
|
-
},
|
|
102
|
-
hooks: hooksFor(invoker.kind, { taskId: task.id, conversationId: task.conversationId }),
|
|
103
|
-
models: options.models,
|
|
104
|
-
tools: self.tools,
|
|
105
|
-
registries: {
|
|
106
|
-
sections: {
|
|
107
|
-
map: self.sectionMap,
|
|
108
|
-
get revision() {
|
|
109
|
-
return self.revisions.sections;
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
tools: {
|
|
113
|
-
map: self.tools,
|
|
114
|
-
get revision() {
|
|
115
|
-
return self.revisions.tools;
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
kinds: self.kinds,
|
|
120
|
-
processHost: options.processHost,
|
|
121
|
-
plugins: self.plugins,
|
|
122
|
-
now: self.now,
|
|
123
|
-
sleep: (untilMs, c) => new Promise((resolve, reject) => {
|
|
124
|
-
const ms = Math.max(0, untilMs - Date.now());
|
|
125
|
-
const t = setTimeout(() => {
|
|
126
|
-
c.abortSignal?.removeEventListener("abort", onAbort);
|
|
127
|
-
resolve();
|
|
128
|
-
}, ms);
|
|
129
|
-
const onAbort = () => {
|
|
130
|
-
clearTimeout(t);
|
|
131
|
-
reject(c.abortSignal?.reason ?? new Error("aborted"));
|
|
132
|
-
};
|
|
133
|
-
c.abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
134
|
-
}),
|
|
135
|
-
waitForInput: (id, c) => self.scheduler.waitForInput(id, c),
|
|
136
|
-
waitForTask: (id, c) => self.scheduler.waitForTask(id, c),
|
|
137
|
-
abortTask: async (id, c) => {
|
|
138
|
-
await self.session.onLine(async (lineCtx) => {
|
|
139
|
-
self.assertInvocation(invoker);
|
|
140
|
-
const target = self.session.liveTasks.get(id) ?? (await self.session.storage.task(id, lineCtx));
|
|
141
|
-
if (target === undefined)
|
|
142
|
-
throw new Error(`task ${id} not found`);
|
|
143
|
-
self.assertTaskConversationScope(task.id, target.conversationId);
|
|
144
|
-
}, c);
|
|
145
|
-
return self.scheduler.abortTask(id, c);
|
|
146
|
-
},
|
|
147
|
-
abortConversation: async (id, c) => {
|
|
148
|
-
await self.session.onLine(() => {
|
|
149
|
-
self.assertInvocation(invoker);
|
|
150
|
-
self.assertOwnedConversation(task.id, id);
|
|
151
|
-
}, c);
|
|
152
|
-
const h = await self.conversation(id, c);
|
|
153
|
-
if (h)
|
|
154
|
-
await h.abort(c);
|
|
155
|
-
},
|
|
156
|
-
createOwnedConversation: (spec, c) => self.session
|
|
157
|
-
.commit(KERNEL, (tx) => {
|
|
158
|
-
self.assertInvocation(invoker);
|
|
159
|
-
return tx.createOwnedConversation(task.id, task.conversationId, spec);
|
|
160
|
-
}, c)
|
|
161
|
-
.then((result) => result.value),
|
|
162
|
-
sendOwned: (id, input, c) => self.session
|
|
163
|
-
.commit(KERNEL, (tx) => {
|
|
164
|
-
self.assertInvocation(invoker);
|
|
165
|
-
self.assertOwnedConversation(task.id, id);
|
|
166
|
-
return tx.send(id, input);
|
|
167
|
-
}, c, {
|
|
168
|
-
docs: [
|
|
169
|
-
{ doc: "rewindable", conversationId: id },
|
|
170
|
-
{ doc: "sticky", conversationId: id },
|
|
171
|
-
],
|
|
172
|
-
})
|
|
173
|
-
.then((r) => r.value),
|
|
174
|
-
context: (c, at, cx) => self.session.commit(invoker, (tx) => tx.context(c, at), cx).then((r) => r.value),
|
|
175
|
-
newestEntry: (c, opts, cx) => self.session.commit(invoker, (tx) => tx.newestEntry(c, opts), cx).then((r) => r.value),
|
|
176
|
-
rewindable: (c, cx) => self.session
|
|
177
|
-
.commit(invoker, (tx) => tx.snapshot({ doc: "rewindable", conversationId: c }), cx, {
|
|
178
|
-
docs: [{ doc: "rewindable", conversationId: c }],
|
|
179
|
-
})
|
|
180
|
-
.then((r) => r.value),
|
|
181
|
-
sticky: (c, cx) => self.session
|
|
182
|
-
.commit(invoker, (tx) => tx.snapshot({ doc: "sticky", conversationId: c }), cx, {
|
|
183
|
-
docs: [{ doc: "sticky", conversationId: c }],
|
|
184
|
-
})
|
|
185
|
-
.then((r) => r.value),
|
|
186
|
-
rewindableAsOf: (c, at, cx) => self.session.commit(invoker, (tx) => tx.rewindableAsOf(c, at), cx).then((r) => r.value),
|
|
187
|
-
};
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
notifyConversation(conversation) {
|
|
192
|
-
if (this.conversationListeners.size === 0)
|
|
193
|
-
return;
|
|
194
|
-
const handle = this.handle(conversation);
|
|
195
|
-
for (const listener of [...this.conversationListeners]) {
|
|
196
|
-
try {
|
|
197
|
-
listener(handle);
|
|
198
|
-
}
|
|
199
|
-
catch (error) {
|
|
200
|
-
this.onReport(error);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
assertInvocation(invoker) {
|
|
205
|
-
if (!invoker.token.alive)
|
|
206
|
-
throw new Forbidden("operation from a finished invocation");
|
|
207
|
-
const live = this.session.liveTasks.get(invoker.id);
|
|
208
|
-
if (live === undefined)
|
|
209
|
-
throw new Forbidden("operation from a task that is not live");
|
|
210
|
-
if (invoker.mode === "run" && live.abort === true)
|
|
211
|
-
throw new Forbidden("operation from a marked run invocation");
|
|
212
|
-
}
|
|
213
|
-
assertTaskConversationScope(taskId, conversationId) {
|
|
214
|
-
const task = this.session.liveTasks.get(taskId);
|
|
215
|
-
if (task?.conversationId === conversationId)
|
|
216
|
-
return;
|
|
217
|
-
if (task?.owns.some((root) => this.session.index.subtree(root).has(conversationId)))
|
|
218
|
-
return;
|
|
219
|
-
throw new Forbidden(`conversation ${conversationId} is outside task ${taskId}'s subtree`);
|
|
220
|
-
}
|
|
221
|
-
assertOwnedConversation(taskId, conversationId) {
|
|
222
|
-
const task = this.session.liveTasks.get(taskId);
|
|
223
|
-
if (task === undefined || !task.owns.some((root) => this.session.index.subtree(root).has(conversationId))) {
|
|
224
|
-
throw new Forbidden(`conversation ${conversationId} is not owned by task ${taskId}`);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
async init() {
|
|
228
|
-
const { session } = this;
|
|
229
|
-
const convs = await session.read((s, ctx) => s.conversations(ctx), this.ctx);
|
|
230
|
-
for (const c of convs)
|
|
231
|
-
session.conversationRecords.set(c.id, c);
|
|
232
|
-
const live = await session.read((s, ctx) => s.scanTasks({ status: ["pending", "running"] }, ctx), this.ctx);
|
|
233
|
-
for (const task of live)
|
|
234
|
-
session.liveTasks.set(task.id, task);
|
|
235
|
-
// Owner tasks that are terminal but still own existing conversations: needed for ancestry.
|
|
236
|
-
const owners = new Set(convs.map((c) => c.owner).filter((o) => o !== undefined));
|
|
237
|
-
for (const id of owners)
|
|
238
|
-
if (!session.liveTasks.has(id)) {
|
|
239
|
-
const t = await session.read((s, ctx) => s.task(id, ctx), this.ctx);
|
|
240
|
-
if (t)
|
|
241
|
-
session.ownerTaskCache.set(id, t);
|
|
242
|
-
}
|
|
243
|
-
if (convs.length === 0) {
|
|
244
|
-
await session.commit(KERNEL, (tx) => tx.createConversation({ rewindable: this.options.root?.rewindable, sticky: this.options.root?.sticky }), this.ctx);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
resume() {
|
|
248
|
-
if (this.suspended)
|
|
249
|
-
throw new Error("cannot resume a suspended harness; reopen storage with a new harness");
|
|
250
|
-
if (this.resumed)
|
|
251
|
-
return;
|
|
252
|
-
this.resumed = true;
|
|
253
|
-
void this.reconcileOrphans()
|
|
254
|
-
.then(() => {
|
|
255
|
-
if (!this.suspended)
|
|
256
|
-
this.scheduler.resume();
|
|
257
|
-
})
|
|
258
|
-
.catch((error) => this.onReport(error));
|
|
259
|
-
}
|
|
260
|
-
async reconcileOrphans() {
|
|
261
|
-
const orphaned = [...this.session.liveTasks.values()].filter((task) => !this.kinds.has(task.kind));
|
|
262
|
-
if (orphaned.length === 0)
|
|
263
|
-
return;
|
|
264
|
-
const docs = [...new Set(orphaned.map((task) => task.conversationId))].map((conversationId) => ({ doc: "sticky", conversationId }));
|
|
265
|
-
await this.session.commit(KERNEL, (tx) => {
|
|
266
|
-
for (const task of orphaned)
|
|
267
|
-
tx.setTask({ ...task, status: "terminal", outcome: { status: "orphaned" } });
|
|
268
|
-
}, this.ctx, { docs });
|
|
269
|
-
}
|
|
270
|
-
quiescent() {
|
|
271
|
-
return this.scheduler.quiescent();
|
|
272
|
-
}
|
|
273
|
-
hold() {
|
|
274
|
-
if (!this.scheduler.quiescent())
|
|
275
|
-
throw new Error("cannot hold a non-quiescent harness; suspend it instead");
|
|
276
|
-
return this.scheduler.hold();
|
|
277
|
-
}
|
|
278
|
-
/** Cancel and join in-process invocations, clear transient waits, then close without terminalizing tasks. */
|
|
279
|
-
async suspend(ctx) {
|
|
280
|
-
if (this.suspended)
|
|
281
|
-
return;
|
|
282
|
-
this.suspended = true;
|
|
283
|
-
await this.scheduler.joinAll();
|
|
284
|
-
const tools = [...this.session.liveTasks.values()].filter((task) => task.kind === "pi.tool");
|
|
285
|
-
if (tools.length > 0) {
|
|
286
|
-
const docs = [...new Set(tools.map((task) => task.conversationId))].map((conversationId) => ({ doc: "sticky", conversationId }));
|
|
287
|
-
await this.session.commit(KERNEL, (tx) => {
|
|
288
|
-
for (const task of tools) {
|
|
289
|
-
const index = task.input.index;
|
|
290
|
-
const slot = tx.sticky(task.conversationId).turn.tools[index];
|
|
291
|
-
if (slot?.waitingOn !== undefined)
|
|
292
|
-
delete slot.waitingOn;
|
|
293
|
-
}
|
|
294
|
-
}, ctx, { docs });
|
|
295
|
-
}
|
|
296
|
-
this.views.close();
|
|
297
|
-
await this.session.close(ctx);
|
|
298
|
-
}
|
|
299
|
-
// --- registries --------------------------------------------------------------
|
|
300
|
-
registerTaskKind(kind) {
|
|
301
|
-
if (kind.name.startsWith("pi."))
|
|
302
|
-
throw new Error(`task kind "${kind.name}": names beginning with "pi." are reserved`);
|
|
303
|
-
if (this.kinds.has(kind.name))
|
|
304
|
-
throw new Error(`task kind "${kind.name}" already registered`);
|
|
305
|
-
this.session.defaults.register(kind);
|
|
306
|
-
this.kinds.set(kind.name, kind);
|
|
307
|
-
this.scheduler.kick();
|
|
308
|
-
return () => {
|
|
309
|
-
if (this.kinds.get(kind.name) !== kind)
|
|
310
|
-
return;
|
|
311
|
-
this.kinds.delete(kind.name);
|
|
312
|
-
this.session.defaults.unregister(kind);
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
namespace(id, defaults, opts = {}) {
|
|
316
|
-
if (!/^[a-z][a-z0-9_.-]*$/i.test(id) || id.startsWith("pi."))
|
|
317
|
-
throw new Error(`invalid namespace "${id}"`);
|
|
318
|
-
if (this.namespaces.has(id))
|
|
319
|
-
throw new Error(`namespace "${id}" already registered`);
|
|
320
|
-
const stored = JSON.parse(JSON.stringify(defaults));
|
|
321
|
-
const routes = new Map();
|
|
322
|
-
for (const doc of ["rewindable", "sticky", "session"]) {
|
|
323
|
-
for (const key of Object.keys(stored[doc] ?? {})) {
|
|
324
|
-
if (routes.has(key))
|
|
325
|
-
throw new Error(`namespace "${id}" key "${key}" is declared in more than one document`);
|
|
326
|
-
routes.set(key, doc);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
let token;
|
|
330
|
-
token = {
|
|
331
|
-
id,
|
|
332
|
-
unregister: () => {
|
|
333
|
-
if (this.namespaces.get(id)?.token !== token)
|
|
334
|
-
return;
|
|
335
|
-
this.namespaces.delete(id);
|
|
336
|
-
for (let index = this.hookRegistrations.length - 1; index >= 0; index--) {
|
|
337
|
-
if (this.hookRegistrations[index].namespace === token)
|
|
338
|
-
this.hookRegistrations.splice(index, 1);
|
|
339
|
-
}
|
|
340
|
-
},
|
|
341
|
-
};
|
|
342
|
-
const registration = {
|
|
343
|
-
token,
|
|
344
|
-
defaults: {
|
|
345
|
-
rewindable: stored.rewindable ?? {},
|
|
346
|
-
sticky: stored.sticky ?? {},
|
|
347
|
-
session: stored.session ?? {},
|
|
348
|
-
},
|
|
349
|
-
routes,
|
|
350
|
-
project: opts.view === undefined ? undefined : (slice) => opts.view(slice),
|
|
351
|
-
};
|
|
352
|
-
this.namespaces.set(id, registration);
|
|
353
|
-
return token;
|
|
354
|
-
}
|
|
355
|
-
/** Register a tool. A duplicate name rejects. Unregister removes only this exact declaration; idempotent. */
|
|
356
|
-
registerTool(tool, at = "runtime") {
|
|
357
|
-
if (this.tools.has(tool.name))
|
|
358
|
-
throw new Error(`tool "${tool.name}" already registered`);
|
|
359
|
-
this.tools.set(tool.name, tool);
|
|
360
|
-
this.revisions.tools++;
|
|
361
|
-
void at;
|
|
362
|
-
return () => {
|
|
363
|
-
if (this.tools.get(tool.name) === tool) {
|
|
364
|
-
this.tools.delete(tool.name);
|
|
365
|
-
this.revisions.tools++;
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
registerSection(section, at = "runtime") {
|
|
370
|
-
if (this.sectionMap.has(section.key))
|
|
371
|
-
throw new Error(`section "${section.key}" already registered`);
|
|
372
|
-
this.sectionMap.set(section.key, section);
|
|
373
|
-
this.revisions.sections++;
|
|
374
|
-
void at;
|
|
375
|
-
return () => {
|
|
376
|
-
if (this.sectionMap.get(section.key) === section) {
|
|
377
|
-
this.sectionMap.delete(section.key);
|
|
378
|
-
this.revisions.sections++;
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
registerEntryKind(kind) {
|
|
383
|
-
if (kind.kind.startsWith("pi."))
|
|
384
|
-
throw new Error(`entry kind "${kind.kind}": names beginning with "pi." are reserved`);
|
|
385
|
-
if (this.entryKinds.has(kind.kind))
|
|
386
|
-
throw new Error(`entry kind "${kind.kind}" already registered`);
|
|
387
|
-
this.entryKinds.set(kind.kind, kind);
|
|
388
|
-
return () => {
|
|
389
|
-
if (this.entryKinds.get(kind.kind) === kind)
|
|
390
|
-
this.entryKinds.delete(kind.kind);
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
/** Register namespace-bound handlers for one kind's hook points, harness-wide. Both tokens must be current. */
|
|
394
|
-
hooks(namespace, kind, handlers, _opts) {
|
|
395
|
-
return this.addHooks({ namespace: this.checkNamespace(namespace), kind: this.checkKind(kind), handlers });
|
|
396
|
-
}
|
|
397
|
-
checkKind(kind) {
|
|
398
|
-
if (this.kinds.get(kind.name) !== kind)
|
|
399
|
-
throw new Error(`kind "${kind.name}" is not the registered token`);
|
|
400
|
-
return kind;
|
|
401
|
-
}
|
|
402
|
-
checkNamespace(namespace) {
|
|
403
|
-
if (this.namespaces.get(namespace.id)?.token !== namespace)
|
|
404
|
-
throw new Forbidden(`namespace "${namespace.id}" is stale`);
|
|
405
|
-
return namespace;
|
|
406
|
-
}
|
|
407
|
-
addHooks(reg) {
|
|
408
|
-
this.hookRegistrations.push(reg);
|
|
409
|
-
let done = false;
|
|
410
|
-
return () => {
|
|
411
|
-
if (done)
|
|
412
|
-
return;
|
|
413
|
-
done = true;
|
|
414
|
-
const index = this.hookRegistrations.indexOf(reg);
|
|
415
|
-
if (index >= 0)
|
|
416
|
-
this.hookRegistrations.splice(index, 1);
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
// --- conversations -------------------------------------------------------------
|
|
420
|
-
async root(ctx) {
|
|
421
|
-
return this.conversation(1, ctx).then((c) => c);
|
|
422
|
-
}
|
|
423
|
-
onConversation(listener) {
|
|
424
|
-
this.conversationListeners.add(listener);
|
|
425
|
-
for (const conversation of this.session.conversationRecords.values()) {
|
|
426
|
-
try {
|
|
427
|
-
listener(this.handle(conversation));
|
|
428
|
-
}
|
|
429
|
-
catch (error) {
|
|
430
|
-
this.onReport(error);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
return () => this.conversationListeners.delete(listener);
|
|
434
|
-
}
|
|
435
|
-
async conversation(id, ctx) {
|
|
436
|
-
const c = await this.session.read((s, lineCtx) => s.conversation(id, lineCtx), ctx);
|
|
437
|
-
return c === undefined ? undefined : this.handle(c);
|
|
438
|
-
}
|
|
439
|
-
async createConversation(spec, ctx) {
|
|
440
|
-
const { input, ...rest } = spec;
|
|
441
|
-
const id = await this.session
|
|
442
|
-
.commit(KERNEL, async (tx) => {
|
|
443
|
-
const id = tx.createConversation(rest);
|
|
444
|
-
if (input !== undefined)
|
|
445
|
-
await tx.send(id, { content: input });
|
|
446
|
-
return id;
|
|
447
|
-
}, ctx)
|
|
448
|
-
.then((r) => r.value);
|
|
449
|
-
return (await this.conversation(id, ctx));
|
|
450
|
-
}
|
|
451
|
-
entries(scan, ctx) {
|
|
452
|
-
return this.session.read((s, lineCtx) => s.scanEntries(scan, lineCtx), ctx);
|
|
453
|
-
}
|
|
454
|
-
getTask(id, ctx) {
|
|
455
|
-
return this.session.read((s, lineCtx) => s.task(id, lineCtx), ctx);
|
|
456
|
-
}
|
|
457
|
-
async abortInput(id, ctx, conversationId) {
|
|
458
|
-
if (conversationId !== undefined) {
|
|
459
|
-
const input = await this.session.read((storage, lineCtx) => storage.input(id, lineCtx), ctx);
|
|
460
|
-
if (input !== undefined && input.conversationId !== conversationId)
|
|
461
|
-
throw new Forbidden(`input ${id} is outside conversation ${conversationId}`);
|
|
462
|
-
}
|
|
463
|
-
return this.inputHandle(id).abort(ctx);
|
|
464
|
-
}
|
|
465
|
-
abortTask(id, ctx) {
|
|
466
|
-
return this.scheduler.abortTask(id, ctx);
|
|
467
|
-
}
|
|
468
|
-
/** Durably mark a task for abort without signalling its invocation; the scheduler aborts it when it next drains. */
|
|
469
|
-
markTask(id, ctx) {
|
|
470
|
-
return this.session
|
|
471
|
-
.commit(KERNEL, async (tx) => {
|
|
472
|
-
const t = await tx.task(id);
|
|
473
|
-
if (t === undefined)
|
|
474
|
-
throw new Error(`task ${id} not found`);
|
|
475
|
-
if (t.status === "terminal")
|
|
476
|
-
return "terminal";
|
|
477
|
-
tx.markTask(id);
|
|
478
|
-
return "marked";
|
|
479
|
-
}, ctx)
|
|
480
|
-
.then((r) => r.value);
|
|
481
|
-
}
|
|
482
|
-
waitForIdle(ctx) {
|
|
483
|
-
return this.scheduler.waitForIdle(undefined, ctx);
|
|
484
|
-
}
|
|
485
|
-
waitForTask(id, ctx) {
|
|
486
|
-
return this.scheduler.waitForTask(id, ctx);
|
|
487
|
-
}
|
|
488
|
-
/** Signals every invocation, waits for them, closes storage. Writes nothing. */
|
|
489
|
-
async close(ctx) {
|
|
490
|
-
await this.suspend(ctx);
|
|
491
|
-
}
|
|
492
|
-
handle(c) {
|
|
493
|
-
const self = this;
|
|
494
|
-
const docs = [
|
|
495
|
-
{ doc: "rewindable", conversationId: c.id },
|
|
496
|
-
{ doc: "sticky", conversationId: c.id },
|
|
497
|
-
];
|
|
498
|
-
const hostInvoker = { type: "host", conversationId: c.id };
|
|
499
|
-
const kernelInvoker = { type: "kernel", conversationId: c.id };
|
|
500
|
-
const host = (fn, ctx) => self.session.commit(hostInvoker, (tx, lineCtx) => fn(tx, lineCtx), ctx, { docs }).then((r) => r.value);
|
|
501
|
-
const kernel = (fn, ctx) => self.session.commit(kernelInvoker, fn, ctx, { docs }).then((r) => r.value);
|
|
502
|
-
const config = {
|
|
503
|
-
get: (ctx) => host((tx) => {
|
|
504
|
-
const cfg = tx.config(c.id);
|
|
505
|
-
const out = {};
|
|
506
|
-
for (const key of self.session.defaults.route.keys())
|
|
507
|
-
out[key] = cfg.get(key);
|
|
508
|
-
return out;
|
|
509
|
-
}, ctx),
|
|
510
|
-
set: (patch, ctx) => host((tx) => {
|
|
511
|
-
const cfg = tx.config(c.id);
|
|
512
|
-
for (const [key, value] of Object.entries(patch)) {
|
|
513
|
-
if (value === undefined)
|
|
514
|
-
throw new Error(`config.set(${key}): use config.reset()`);
|
|
515
|
-
cfg.set(key, value);
|
|
516
|
-
}
|
|
517
|
-
}, ctx),
|
|
518
|
-
reset: (keys, ctx) => host((tx) => {
|
|
519
|
-
const cfg = tx.config(c.id);
|
|
520
|
-
for (const key of keys)
|
|
521
|
-
cfg.reset(String(key));
|
|
522
|
-
}, ctx),
|
|
523
|
-
};
|
|
524
|
-
return {
|
|
525
|
-
id: c.id,
|
|
526
|
-
config,
|
|
527
|
-
async send(input, ctx) {
|
|
528
|
-
const id = await kernel((tx) => tx.send(c.id, input), ctx);
|
|
529
|
-
return self.inputHandle(id);
|
|
530
|
-
},
|
|
531
|
-
write: (entry, ctx) => host((tx) => tx.write(c.id, entry), ctx),
|
|
532
|
-
commit: host,
|
|
533
|
-
rewindable: (ctx) => host((tx) => tx.snapshot({ doc: "rewindable", conversationId: c.id }), ctx),
|
|
534
|
-
sticky: (ctx) => host((tx) => tx.snapshot({ doc: "sticky", conversationId: c.id }), ctx),
|
|
535
|
-
context: (ctx) => host((tx) => tx.context(c.id), ctx),
|
|
536
|
-
async fork(at, spec, ctx) {
|
|
537
|
-
const id = await self.session.fork(c.id, at, spec, ctx);
|
|
538
|
-
return (await self.conversation(id, ctx));
|
|
539
|
-
},
|
|
540
|
-
collapse: (instructions, ctx) => kernel(async (tx) => {
|
|
541
|
-
const { entries } = await tx.context(c.id);
|
|
542
|
-
const state = tx.rewindable(c.id);
|
|
543
|
-
const through = chooseThrough(entries, state.keepRecent);
|
|
544
|
-
if (through === undefined)
|
|
545
|
-
throw new Error("nothing to collapse");
|
|
546
|
-
return tx.createTask({
|
|
547
|
-
kind: "pi.collapse",
|
|
548
|
-
conversationId: c.id,
|
|
549
|
-
background: true,
|
|
550
|
-
input: { reason: "manual", through, ...(instructions === undefined ? {} : { instructions }) },
|
|
551
|
-
});
|
|
552
|
-
}, ctx),
|
|
553
|
-
reset: async (handoff, ctx) => {
|
|
554
|
-
await kernel((tx) => tx.write(c.id, handoff === undefined
|
|
555
|
-
? { kind: "pi.reset", head: "self" }
|
|
556
|
-
: {
|
|
557
|
-
kind: "pi.handoff",
|
|
558
|
-
head: "self",
|
|
559
|
-
model: [{ role: "user", content: handoff, timestamp: self.now() }],
|
|
560
|
-
}), ctx);
|
|
561
|
-
},
|
|
562
|
-
async abort(ctx) {
|
|
563
|
-
const owned = [];
|
|
564
|
-
const marked = await kernel(async (tx) => {
|
|
565
|
-
const s = tx.sticky(c.id);
|
|
566
|
-
const withdrawn = s.inbox.filter((q) => q.mode !== "write").map((q) => q.id);
|
|
567
|
-
for (let i = s.inbox.length - 1; i >= 0; i--)
|
|
568
|
-
if (s.inbox[i].mode !== "write")
|
|
569
|
-
s.inbox.splice(i, 1);
|
|
570
|
-
await tx.resolveInputs(withdrawn, { status: "unanswered", reason: "aborted" });
|
|
571
|
-
for (const input of withdrawn)
|
|
572
|
-
tx.emit({ type: "input.aborted", input });
|
|
573
|
-
const ids = [];
|
|
574
|
-
for (const t of [...self.session.liveTasks.values()]) {
|
|
575
|
-
if (t.conversationId !== c.id || t.background)
|
|
576
|
-
continue;
|
|
577
|
-
for (const o of t.owns)
|
|
578
|
-
owned.push(o);
|
|
579
|
-
if (t.abort !== true)
|
|
580
|
-
tx.markTask(t.id);
|
|
581
|
-
ids.push(t.id);
|
|
582
|
-
}
|
|
583
|
-
return ids;
|
|
584
|
-
}, ctx);
|
|
585
|
-
for (const id of marked)
|
|
586
|
-
await self.scheduler.abortTask(id, ctx);
|
|
587
|
-
await self.scheduler.waitForIdle(c.id, ctx);
|
|
588
|
-
await Promise.all(owned.map((o) => self.scheduler.waitForIdle(o, ctx)));
|
|
589
|
-
},
|
|
590
|
-
waitForIdle: (ctx) => self.scheduler.waitForIdle(c.id, ctx),
|
|
591
|
-
hooks: (namespace, kind, handlers, opts) => self.addHooks({
|
|
592
|
-
namespace: self.checkNamespace(namespace),
|
|
593
|
-
kind: self.checkKind(kind),
|
|
594
|
-
handlers,
|
|
595
|
-
conversationId: c.id,
|
|
596
|
-
subtree: opts?.subtree,
|
|
597
|
-
}),
|
|
598
|
-
watch: (ctx) => self.watch(c, ctx),
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
/** Capture and subscribe in one line operation. */
|
|
602
|
-
async watch(conversation, ctx) {
|
|
603
|
-
return this.session
|
|
604
|
-
.commit({ type: "host", conversationId: conversation.id }, async (tx) => {
|
|
605
|
-
const entries = await captureActiveTranscript((scan) => tx.scanEntries(scan), conversation.id);
|
|
606
|
-
return this.views.watch(conversation, entries);
|
|
607
|
-
}, ctx, {
|
|
608
|
-
docs: [
|
|
609
|
-
{ doc: "rewindable", conversationId: conversation.id },
|
|
610
|
-
{ doc: "sticky", conversationId: conversation.id },
|
|
611
|
-
],
|
|
612
|
-
})
|
|
613
|
-
.then((result) => result.value);
|
|
614
|
-
}
|
|
615
|
-
inputHandle(id) {
|
|
616
|
-
return {
|
|
617
|
-
id,
|
|
618
|
-
result: (ctx) => this.session.read((s, lineCtx) => s.input(id, lineCtx), ctx),
|
|
619
|
-
wait: (ctx) => this.scheduler.waitForInput(id, ctx),
|
|
620
|
-
abort: (ctx) => this.session.commit(KERNEL, (tx) => tx.withdrawInput(id), ctx, { docs: [] }).then((r) => r.value),
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* §9: H = newest fork-visible entry with a head. Active transcript = H plus every fork-visible entry
|
|
626
|
-
* with id ≥ H.head, chronological, nothing dropped inside the range; the whole transcript if no head.
|
|
627
|
-
*/
|
|
628
|
-
export async function captureActiveTranscript(scan, conversationId) {
|
|
629
|
-
const [h] = await scan({ conversationId, withHead: true, limit: 1 });
|
|
630
|
-
const from = h?.head;
|
|
631
|
-
const out = [];
|
|
632
|
-
let before;
|
|
633
|
-
for (;;) {
|
|
634
|
-
const page = await scan({ conversationId, ...(before === undefined ? {} : { before }), limit: 256 });
|
|
635
|
-
let done = page.length < 256;
|
|
636
|
-
for (const e of page) {
|
|
637
|
-
if (from !== undefined && e.id < from) {
|
|
638
|
-
done = true;
|
|
639
|
-
break;
|
|
640
|
-
}
|
|
641
|
-
out.push(e);
|
|
642
|
-
}
|
|
643
|
-
if (done)
|
|
644
|
-
break;
|
|
645
|
-
before = page[page.length - 1].id;
|
|
646
|
-
}
|
|
647
|
-
return out.reverse();
|
|
648
|
-
}
|
|
649
|
-
export { withAbortSignal, isCoreKind };
|
|
650
|
-
export { applyEnvelope, WATCH_CAPACITY } from "./view.js";
|
|
651
|
-
/** The built-in kinds, as typed witnesses for `api.task`, `waitForTask`, and `hooks(kind, …)`. */
|
|
652
|
-
export const kinds = { generation, tool, postTools, collapse, job, plugin };
|
|
653
|
-
export const entries = builtinEntries;
|
|
654
|
-
//# sourceMappingURL=harness.js.map
|