@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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/harness/types.ts"],"names":[],"mappings":"AAUA,0CAA0C;AAC1C,MAAM,UAAU,EAAE,CAAiB,KAAa;IAC/C,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,GAAG,CAAiB,KAAa;IAChD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,+GAA+G;AAC/G,MAAM,UAAU,UAAU,CAAiB,MAA8B;IACxE,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,MAAM,CAAC,KAAK,CAAC;IACnC,OAAO,MAAM,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,wHAAwH;AACxH,MAAM,UAAU,cAAc,CAAgC,MAA8B;IAC3F,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7C,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,OAAO,CAAC,KAAc;IACrC,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;IACvD,IAAI,CAAC;QACJ,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACjC,CAAC;AACF,CAAC;AAmID,4DAA4D;AAC5D,MAAM,OAAO,SAAU,SAAQ,KAAK;IACnC,sCAAsC;IAC/B,IAAI,CAAgB;IAC3B,2EAA2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AK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD","sourcesContent":["import type { SimpleStreamOptions, Transport } from \"@draht/ai\";\nimport type { Static, TSchema } from \"typebox\";\nimport type { AgentTool, AgentToolResult } from \"../types.ts\";\nimport type { Context } from \"./context.ts\";\nimport type { JsonValue } from \"./session/types.ts\";\nimport type { TruncationResult } from \"./utils/truncate.ts\";\n\n/** Result of a fallible operation. Expected failures are returned as `ok: false` instead of thrown. */\nexport type Result<TValue, TError> = { ok: true; value: TValue } | { ok: false; error: TError };\n\n/** Create a successful {@link Result}. */\nexport function ok<TValue, TError>(value: TValue): Result<TValue, TError> {\n\treturn { ok: true, value };\n}\n\n/** Create a failed {@link Result}. */\nexport function err<TValue, TError>(error: TError): Result<TValue, TError> {\n\treturn { ok: false, error };\n}\n\n/** Return the success value or throw the failure error. Intended for tests and explicit adapter boundaries. */\nexport function getOrThrow<TValue, TError>(result: Result<TValue, TError>): TValue {\n\tif (!result.ok) throw result.error;\n\treturn result.value;\n}\n\n/** Return the success value or `undefined`. Only object values are allowed to avoid truthiness bugs with primitives. */\nexport function getOrUndefined<TValue extends object, TError>(result: Result<TValue, TError>): TValue | undefined {\n\treturn result.ok ? result.value : undefined;\n}\n\n/** Normalize unknown thrown values into Error instances before using them as typed error causes. */\nexport function toError(error: unknown): Error {\n\tif (error instanceof Error) return error;\n\tif (typeof error === \"string\") return new Error(error);\n\ttry {\n\t\treturn new Error(JSON.stringify(error));\n\t} catch {\n\t\treturn new Error(String(error));\n\t}\n}\n\n/**\n * Skill loaded from a `SKILL.md` file or provided by an application.\n *\n * `name`, `description`, and `filePath` are inserted into the system prompt in an XML-formatted block as suggested by agentskills.io.\n * Use {@link formatSkillsForSystemPrompt} to generate the spec-compatible system prompt block.\n */\nexport interface Skill {\n\t/** Stable skill name used for lookup and model-visible listings. */\n\tname: string;\n\t/** Short model-visible description of when to use the skill. */\n\tdescription: string;\n\t/** Full skill instructions. */\n\tcontent: string;\n\t/** Absolute path to the skill file. Used for model-visible location and resolving relative references. */\n\tfilePath: string;\n\t/** Exclude this skill from model-visible skill lists while still allowing explicit application invocation. */\n\tdisableModelInvocation?: boolean;\n}\n\n/** Prompt template that can be formatted into a prompt for explicit invocation. */\nexport interface PromptTemplate {\n\t/** Stable template name used for lookup or application command routing. */\n\tname: string;\n\t/** Optional description for command lists or autocomplete. */\n\tdescription?: string;\n\t/** Template content. Argument placeholders are formatted by `formatPromptTemplateInvocation`. */\n\tcontent: string;\n}\n\n/** Resources made available to explicit invocation methods and system-prompt callbacks. */\nexport interface AgentHarnessResources<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\t/** Prompt templates available for explicit invocation. */\n\tpromptTemplates?: TPromptTemplate[];\n\t/** Skills available to the model and explicit skill invocation. */\n\tskills?: TSkill[];\n}\n\n/** Options for one live harness tool progress update. */\nexport interface AgentHarnessToolUpdateOptions {\n\t/** Request replacement of this invocation's durable recovery checkpoint. */\n\tcheckpoint?: true;\n}\n\n/** Synchronous full-snapshot progress callback supplied to harness-native tools. */\nexport type AgentHarnessToolUpdateCallback<TDetails> = (\n\tpartialResult: AgentToolResult<TDetails>,\n\toptions?: AgentHarnessToolUpdateOptions,\n) => void;\n\n/** Stable harness identity for one logical tool call, unchanged during safe replay. */\nexport interface AgentHarnessToolInvocation {\n\t/** Opaque session-unique id equal to the call's reserved result-entry id. */\n\treadonly invocationId: string;\n\treadonly operationId: string;\n\treadonly turnId: string;\n\t/** Read one invocation-scoped durable replay memo. */\n\tgetMemo(name: string): Promise<JsonValue | undefined>;\n\t/** Set or delete one invocation-scoped durable replay memo. */\n\tsetMemo(name: string, value: JsonValue | undefined): Promise<void>;\n}\n\n/** Tool definition executed by an {@link AgentHarness} with an application-defined context. */\nexport type AgentHarnessTool<\n\tTContext extends object | undefined,\n\tTParameters extends TSchema = TSchema,\n\tTDetails = unknown,\n> = Omit<AgentTool<TParameters, TDetails>, \"execute\"> & {\n\t/** Execute the tool call with the context resolved for the current turn snapshot. */\n\texecute(\n\t\ttoolCallId: string,\n\t\tparams: Static<TParameters>,\n\t\tonUpdate: AgentHarnessToolUpdateCallback<TDetails>,\n\t\ttoolContext: TContext,\n\t\tinvocation: AgentHarnessToolInvocation,\n\t\tcontext: Context,\n\t): Promise<AgentToolResult<TDetails>>;\n};\n\n/** Static tool context or provider resolved for each turn snapshot. */\nexport type AgentHarnessToolContextSource<TContext extends object | undefined> =\n\t| TContext\n\t| ((context: Context) => TContext | Promise<TContext>);\n\n/** Curated provider request options owned by the harness and snapshotted per turn. */\nexport interface AgentHarnessStreamOptions {\n\t/** Preferred transport forwarded to the stream function. */\n\ttransport?: Transport;\n\t/** Provider request timeout in milliseconds. */\n\ttimeoutMs?: number;\n\t/** Maximum provider retry attempts. */\n\tmaxRetries?: number;\n\t/** Optional cap for provider-requested retry delays. */\n\tmaxRetryDelayMs?: number;\n\t/** Additional request headers merged with auth and lifecycle headers. */\n\theaders?: Record<string, string>;\n\t/** Provider metadata forwarded with requests. */\n\tmetadata?: SimpleStreamOptions[\"metadata\"];\n\t/** Provider cache retention hint. */\n\tcacheRetention?: SimpleStreamOptions[\"cacheRetention\"];\n\t/** Ask a capable provider to continue generation asynchronously. */\n\tdeferred?: boolean | { window?: \"15m\" | \"1h\" | \"24h\" };\n}\n\n/** Per-request stream option patch returned by provider hooks. */\nexport interface AgentHarnessStreamOptionsPatch\n\textends Omit<Partial<AgentHarnessStreamOptions>, \"headers\" | \"metadata\"> {\n\t/** Header patch. `undefined` values delete keys; explicit `headers: undefined` clears all headers. */\n\theaders?: Record<string, string | undefined>;\n\t/** Metadata patch. `undefined` values delete keys; explicit `metadata: undefined` clears all metadata. */\n\tmetadata?: Record<string, unknown | undefined>;\n}\n\n/** Kind of filesystem object as addressed by a {@link FileSystem}. Symlinks are not followed automatically. */\nexport type FileKind = \"file\" | \"directory\" | \"symlink\";\n\n/** Stable, backend-independent file error codes returned by {@link FileSystem} file operations. */\nexport type FileErrorCode =\n\t| \"aborted\"\n\t| \"not_found\"\n\t| \"permission_denied\"\n\t| \"not_directory\"\n\t| \"is_directory\"\n\t| \"invalid\"\n\t| \"not_supported\"\n\t| \"unknown\";\n\n/** Error returned by {@link FileSystem} file operations. */\nexport class FileError extends Error {\n\t/** Backend-independent error code. */\n\tpublic code: FileErrorCode;\n\t/** Absolute addressed path associated with the failure, when available. */\n\tpublic path?: string;\n\n\tconstructor(code: FileErrorCode, message: string, path?: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"FileError\";\n\t\tthis.code = code;\n\t\tthis.path = path;\n\t}\n}\n\n/** Stable, backend-independent execution error codes returned by {@link ExecutionEnv.exec}. */\nexport type ExecutionErrorCode =\n\t| \"aborted\"\n\t| \"timeout\"\n\t| \"shell_unavailable\"\n\t| \"spawn_error\"\n\t| \"callback_error\"\n\t| \"unknown\";\n\n/** Error returned by {@link ExecutionEnv.exec}. */\nexport class ExecutionError extends Error {\n\t/** Backend-independent error code. */\n\tpublic code: ExecutionErrorCode;\n\n\tconstructor(code: ExecutionErrorCode, message: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"ExecutionError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Stable compaction error codes returned by compaction helpers. */\nexport type CompactionErrorCode = \"aborted\" | \"summarization_failed\";\n\n/** Error returned by compaction helpers. */\nexport class CompactionError extends Error {\n\t/** Backend-independent error code. */\n\tpublic code: CompactionErrorCode;\n\n\tconstructor(code: CompactionErrorCode, message: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"CompactionError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Stable branch-summary error codes returned by branch summarization helpers. */\nexport type BranchSummaryErrorCode = \"aborted\" | \"summarization_failed\";\n\n/** Error returned by branch summarization helpers. */\nexport class BranchSummaryError extends Error {\n\t/** Backend-independent error code. */\n\tpublic code: BranchSummaryErrorCode;\n\n\tconstructor(code: BranchSummaryErrorCode, message: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"BranchSummaryError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Metadata for one filesystem object in a {@link FileSystem}. */\nexport interface FileInfo {\n\t/** Basename of {@link path}. */\n\tname: string;\n\t/** Absolute, syntactically normalized addressed path in the execution environment. Symlinks are not followed. */\n\tpath: string;\n\t/** Object kind. Symlink targets are not followed; use {@link FileSystem.canonicalPath} explicitly. */\n\tkind: FileKind;\n\t/** Size in bytes for the addressed filesystem object. */\n\tsize: number;\n\t/** Modification time as milliseconds since Unix epoch. */\n\tmtimeMs: number;\n}\n\n/** One UTF-8 line read from a text file. */\nexport interface TextLine {\n\ttext: string;\n\t/** Whether the line ended with `\\n`; callers use this to discard a torn final record. */\n\tterminated: boolean;\n}\n\n/** Pull-based UTF-8 line reader that preserves final-line termination. */\nexport interface TextLineReader {\n\treadLine(context: Context): Promise<Result<TextLine | undefined, FileError>>;\n\t/** Release the open file. Must be best-effort and must not throw or reject. */\n\tclose(context: Context): Promise<void>;\n}\n\n/**\n * Filesystem capability used by the harness.\n *\n * Paths passed to methods may be absolute or relative to {@link cwd}. Paths returned by file operations are addressed paths\n * in the filesystem namespace, but are not canonicalized through symlinks unless returned by {@link canonicalPath}.\n *\n * Operation methods must never throw or reject. All filesystem failures, including unexpected backend failures, must be\n * encoded in the returned {@link Result}. Implementations must preserve this invariant.\n */\nexport interface FileSystem {\n\t/** Current working directory for relative paths. */\n\tcwd: string;\n\n\t/** Return an absolute addressed path without requiring it to exist and without resolving symlinks. */\n\tabsolutePath(path: string, context: Context): Promise<Result<string, FileError>>;\n\t/** Join path segments in the filesystem namespace without requiring the result to exist. */\n\tjoinPath(parts: string[], context: Context): Promise<Result<string, FileError>>;\n\t/** Read a UTF-8 text file. */\n\treadTextFile(path: string, context: Context): Promise<Result<string, FileError>>;\n\t/** Open a UTF-8 text file for pull-based line reading. */\n\topenTextLineReader(path: string, context: Context): Promise<Result<TextLineReader, FileError>>;\n\t/** Read UTF-8 text lines. Implementations should stop once `maxLines` lines have been read. */\n\treadTextLines(\n\t\tpath: string,\n\t\toptions: { maxLines?: number } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<string[], FileError>>;\n\t/** Read a binary file. */\n\treadBinaryFile(path: string, context: Context): Promise<Result<Uint8Array, FileError>>;\n\t/** Create or overwrite a file, creating parent directories when supported. */\n\twriteFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;\n\t/** Create or append to a file, creating parent directories when supported. */\n\tappendFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;\n\t/** Atomically rename a file, replacing the destination when it exists. Does not copy across filesystems. */\n\trenameFile(sourcePath: string, destinationPath: string, context: Context): Promise<Result<void, FileError>>;\n\t/** Return metadata for the addressed path without following symlinks. */\n\tfileInfo(path: string, context: Context): Promise<Result<FileInfo, FileError>>;\n\t/** List direct children of a directory without following symlinks. */\n\tlistDir(path: string, context: Context): Promise<Result<FileInfo[], FileError>>;\n\t/** Return the canonical path for an existing path, resolving symlinks where supported. */\n\tcanonicalPath(path: string, context: Context): Promise<Result<string, FileError>>;\n\t/** Return false for missing paths. Other errors, such as permission failures, return a {@link FileError}. */\n\texists(path: string, context: Context): Promise<Result<boolean, FileError>>;\n\t/** Create a directory. Defaults to `recursive: true`. */\n\tcreateDir(\n\t\tpath: string,\n\t\toptions: { recursive?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<void, FileError>>;\n\t/** Remove a file or directory. Defaults to `recursive: false` and `force: false`. */\n\tremove(\n\t\tpath: string,\n\t\toptions: { recursive?: boolean; force?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<void, FileError>>;\n\t/** Create a temporary directory and return its absolute path. Defaults to `prefix: \"tmp-\"`. */\n\tcreateTempDir(prefix: string | undefined, context: Context): Promise<Result<string, FileError>>;\n\t/** Create a temporary file and return its absolute path. Defaults to `prefix: \"\"` and `suffix: \"\"`. */\n\tcreateTempFile(\n\t\toptions: { prefix?: string; suffix?: string } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<string, FileError>>;\n\n\t/** Release filesystem resources. Must be best-effort and must not throw or reject. */\n\tcleanup(context: Context): Promise<void>;\n}\n\n/** Which portion of bounded output survives after the limit is crossed. */\nexport type ShellOutputRetention = \"head\" | \"tail\";\n\n/** Source-side limits for one combined shell output view. */\nexport interface ShellOutputLimits {\n\tmaxBytes: number;\n\tmaxLines: number;\n\t/** Defaults to `\"tail\"`. */\n\tretain?: ShellOutputRetention;\n}\n\n/** Bounded shell capture requested by the caller. */\nexport interface ShellOutputCaptureOptions {\n\tlimits: ShellOutputLimits;\n\t/** Preserve complete output in an execution-environment-local file after the limits are crossed. */\n\tspill?: boolean;\n}\n\n/** Truncation metadata without a duplicate copy of the retained text. */\nexport type ShellOutputTruncation = Omit<TruncationResult, \"content\">;\n\n/** Metadata accompanying a bounded shell output view. */\nexport interface ShellOutputMetadata {\n\ttruncation: ShellOutputTruncation;\n\tspillPath?: string;\n\tlastLineBytes?: number;\n}\n\n/** Complete bounded shell output view. */\nexport interface ShellOutputView extends ShellOutputMetadata {\n\ttext: string;\n}\n\n/** Incremental source-side change to one bounded shell output view. */\nexport type ShellOutputUpdate =\n\t| { kind: \"replace\"; output: ShellOutputView }\n\t| { kind: \"append\"; text: string; metadata: ShellOutputMetadata }\n\t| { kind: \"slide\"; drop: number; text: string; metadata: ShellOutputMetadata }\n\t| { kind: \"metadata\"; metadata: ShellOutputMetadata };\n\n/** Bounded shell completion. Output text is delivered through {@link ShellExecOptions.onUpdate}. */\nexport interface ShellExecResult extends ShellOutputMetadata {\n\texitCode: number;\n}\n\n/** Options for {@link Shell.exec}. */\nexport interface ShellExecOptions {\n\t/** Working directory for the command. Relative paths are resolved against {@link ExecutionEnv.cwd}. Defaults to {@link ExecutionEnv.cwd}. */\n\tcwd?: string;\n\t/** Environment variables for the command. Values override inherited defaults when `inheritEnv` is true. */\n\tenv?: Record<string, string>;\n\t/** Whether to inherit the execution environment's default variables. Defaults to true. */\n\tinheritEnv?: boolean;\n\t/** Timeout in seconds. Implementations should return a timeout error when the command exceeds this duration. Defaults to no timeout. */\n\ttimeout?: number;\n\t/** Source-side bounded capture. Output is discarded when this and `onUpdate` are both absent. */\n\tcapture?: ShellOutputCaptureOptions;\n\t/** Called with bounded output changes. */\n\tonUpdate?: (update: ShellOutputUpdate, context: Context) => void;\n}\n\n/** Shell execution capability used by the harness. */\nexport interface Shell {\n\t/** Execute a shell command in {@link FileSystem.cwd} unless `options.cwd` is provided. */\n\texec(\n\t\tcommand: string,\n\t\toptions: ShellExecOptions | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<ShellExecResult, ExecutionError>>;\n\t/** Release shell resources. Must be best-effort and must not throw or reject. */\n\tcleanup(context: Context): Promise<void>;\n}\n\n/** Filesystem and process execution environment used by the harness. */\nexport interface ExecutionEnv extends FileSystem, Shell {}\n"]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export interface AdaptivePublisherOptions<TValue, TUpdate> {
|
|
2
|
-
snapshot(): TValue;
|
|
3
|
-
update(previous: TValue | undefined, current: TValue): TUpdate | undefined;
|
|
4
|
-
measure(update: TUpdate): number;
|
|
5
|
-
publish(update: TUpdate): void;
|
|
6
|
-
onError(error: unknown): void;
|
|
7
|
-
minIntervalMs?: number;
|
|
8
|
-
targetBytesPerSecond?: number;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Publishes the latest state without queuing intermediate mutations.
|
|
12
|
-
*
|
|
13
|
-
* The first dirty state after idle is immediate. Each publication then buys a
|
|
14
|
-
* delay proportional to its encoded size, with a minimum interval that also
|
|
15
|
-
* bounds event count. A single trailing timer guarantees eventual publication.
|
|
16
|
-
*/
|
|
17
|
-
export declare class AdaptivePublisher<TValue, TUpdate> {
|
|
18
|
-
#private;
|
|
19
|
-
constructor(options: AdaptivePublisherOptions<TValue, TUpdate>);
|
|
20
|
-
markDirty(): void;
|
|
21
|
-
flush(force?: boolean): void;
|
|
22
|
-
dispose(): void;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=adaptive-publisher.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adaptive-publisher.d.ts","sourceRoot":"","sources":["../../../src/harness/utils/adaptive-publisher.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB,CAAC,MAAM,EAAE,OAAO;IACxD,QAAQ,IAAI,MAAM,CAAC;IACnB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IAC3E,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IACjC,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IAC/B,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,qBAAa,iBAAiB,CAAC,MAAM,EAAE,OAAO;;IAU7C,YAAY,OAAO,EAAE,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,EAI7D;IAED,SAAS,IAAI,IAAI,CAShB;IAED,KAAK,CAAC,KAAK,UAAQ,GAAG,IAAI,CAuBzB;IAED,OAAO,IAAI,IAAI,CAId;CAaD"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Publishes the latest state without queuing intermediate mutations.
|
|
3
|
-
*
|
|
4
|
-
* The first dirty state after idle is immediate. Each publication then buys a
|
|
5
|
-
* delay proportional to its encoded size, with a minimum interval that also
|
|
6
|
-
* bounds event count. A single trailing timer guarantees eventual publication.
|
|
7
|
-
*/
|
|
8
|
-
export class AdaptivePublisher {
|
|
9
|
-
#options;
|
|
10
|
-
#minIntervalMs;
|
|
11
|
-
#targetBytesPerSecond;
|
|
12
|
-
#published;
|
|
13
|
-
#dirty = false;
|
|
14
|
-
#nextEmitAt = 0;
|
|
15
|
-
#timer;
|
|
16
|
-
#disposed = false;
|
|
17
|
-
constructor(options) {
|
|
18
|
-
this.#options = options;
|
|
19
|
-
this.#minIntervalMs = options.minIntervalMs ?? 100;
|
|
20
|
-
this.#targetBytesPerSecond = options.targetBytesPerSecond ?? 100 * 1024;
|
|
21
|
-
}
|
|
22
|
-
markDirty() {
|
|
23
|
-
if (this.#disposed)
|
|
24
|
-
return;
|
|
25
|
-
this.#dirty = true;
|
|
26
|
-
const wait = this.#nextEmitAt - Date.now();
|
|
27
|
-
if (wait <= 0) {
|
|
28
|
-
this.flush();
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
this.#armTimer(wait);
|
|
32
|
-
}
|
|
33
|
-
flush(force = false) {
|
|
34
|
-
if (this.#disposed || !this.#dirty)
|
|
35
|
-
return;
|
|
36
|
-
const now = Date.now();
|
|
37
|
-
if (!force && now < this.#nextEmitAt) {
|
|
38
|
-
this.#armTimer(this.#nextEmitAt - now);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (this.#timer !== undefined)
|
|
42
|
-
clearTimeout(this.#timer);
|
|
43
|
-
this.#timer = undefined;
|
|
44
|
-
const current = this.#options.snapshot();
|
|
45
|
-
const update = this.#options.update(this.#published, current);
|
|
46
|
-
if (update === undefined) {
|
|
47
|
-
this.#published = current;
|
|
48
|
-
this.#dirty = false;
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const encodedBytes = this.#options.measure(update);
|
|
52
|
-
this.#published = current;
|
|
53
|
-
this.#dirty = false;
|
|
54
|
-
this.#nextEmitAt = now + Math.max(this.#minIntervalMs, (encodedBytes * 1000) / this.#targetBytesPerSecond);
|
|
55
|
-
// Commit before delivery. A consumer may apply the update and then throw or
|
|
56
|
-
// reenter the producer; retaining the old baseline would duplicate that delta.
|
|
57
|
-
this.#options.publish(update);
|
|
58
|
-
}
|
|
59
|
-
dispose() {
|
|
60
|
-
if (this.#timer !== undefined)
|
|
61
|
-
clearTimeout(this.#timer);
|
|
62
|
-
this.#timer = undefined;
|
|
63
|
-
this.#disposed = true;
|
|
64
|
-
}
|
|
65
|
-
#armTimer(wait) {
|
|
66
|
-
if (this.#timer !== undefined)
|
|
67
|
-
return;
|
|
68
|
-
this.#timer = setTimeout(() => {
|
|
69
|
-
this.#timer = undefined;
|
|
70
|
-
try {
|
|
71
|
-
this.flush();
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
this.#options.onError(error);
|
|
75
|
-
}
|
|
76
|
-
}, wait);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=adaptive-publisher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adaptive-publisher.js","sourceRoot":"","sources":["../../../src/harness/utils/adaptive-publisher.ts"],"names":[],"mappings":"AAUA;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IACpB,QAAQ,CAA4C;IACpD,cAAc,CAAS;IACvB,qBAAqB,CAAS;IACvC,UAAU,CAAqB;IAC/B,MAAM,GAAG,KAAK,CAAC;IACf,WAAW,GAAG,CAAC,CAAC;IAChB,MAAM,CAA4C;IAClD,SAAS,GAAG,KAAK,CAAC;IAElB,YAAY,OAAkD;QAC7D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,aAAa,IAAI,GAAG,CAAC;QACnD,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,oBAAoB,IAAI,GAAG,GAAG,IAAI,CAAC;IACzE,CAAC;IAED,SAAS;QACR,IAAI,IAA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MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAC3G,4EAA4E;QAC5E,+EAA+E;QAC/E,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO;QACN,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,SAAS,CAAC,IAAY;QACrB,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,OAAO;QACtC,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE;YAC7B,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;YACxB,IAAI,CAAC;gBACJ,IAAI,CAAC,KAAK,EAAE,CAAC;YACd,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;QACF,CAAC,EAAE,IAAI,CAAC,CAAC;IACV,CAAC;CACD","sourcesContent":["export interface AdaptivePublisherOptions<TValue, TUpdate> {\n\tsnapshot(): TValue;\n\tupdate(previous: TValue | undefined, current: TValue): TUpdate | undefined;\n\tmeasure(update: TUpdate): number;\n\tpublish(update: TUpdate): void;\n\tonError(error: unknown): void;\n\tminIntervalMs?: number;\n\ttargetBytesPerSecond?: number;\n}\n\n/**\n * Publishes the latest state without queuing intermediate mutations.\n *\n * The first dirty state after idle is immediate. Each publication then buys a\n * delay proportional to its encoded size, with a minimum interval that also\n * bounds event count. A single trailing timer guarantees eventual publication.\n */\nexport class AdaptivePublisher<TValue, TUpdate> {\n\treadonly #options: AdaptivePublisherOptions<TValue, TUpdate>;\n\treadonly #minIntervalMs: number;\n\treadonly #targetBytesPerSecond: number;\n\t#published: TValue | undefined;\n\t#dirty = false;\n\t#nextEmitAt = 0;\n\t#timer: ReturnType<typeof setTimeout> | undefined;\n\t#disposed = false;\n\n\tconstructor(options: AdaptivePublisherOptions<TValue, TUpdate>) {\n\t\tthis.#options = options;\n\t\tthis.#minIntervalMs = options.minIntervalMs ?? 100;\n\t\tthis.#targetBytesPerSecond = options.targetBytesPerSecond ?? 100 * 1024;\n\t}\n\n\tmarkDirty(): void {\n\t\tif (this.#disposed) return;\n\t\tthis.#dirty = true;\n\t\tconst wait = this.#nextEmitAt - Date.now();\n\t\tif (wait <= 0) {\n\t\t\tthis.flush();\n\t\t\treturn;\n\t\t}\n\t\tthis.#armTimer(wait);\n\t}\n\n\tflush(force = false): void {\n\t\tif (this.#disposed || !this.#dirty) return;\n\t\tconst now = Date.now();\n\t\tif (!force && now < this.#nextEmitAt) {\n\t\t\tthis.#armTimer(this.#nextEmitAt - now);\n\t\t\treturn;\n\t\t}\n\t\tif (this.#timer !== undefined) clearTimeout(this.#timer);\n\t\tthis.#timer = undefined;\n\t\tconst current = this.#options.snapshot();\n\t\tconst update = this.#options.update(this.#published, current);\n\t\tif (update === undefined) {\n\t\t\tthis.#published = current;\n\t\t\tthis.#dirty = false;\n\t\t\treturn;\n\t\t}\n\t\tconst encodedBytes = this.#options.measure(update);\n\t\tthis.#published = current;\n\t\tthis.#dirty = false;\n\t\tthis.#nextEmitAt = now + Math.max(this.#minIntervalMs, (encodedBytes * 1000) / this.#targetBytesPerSecond);\n\t\t// Commit before delivery. A consumer may apply the update and then throw or\n\t\t// reenter the producer; retaining the old baseline would duplicate that delta.\n\t\tthis.#options.publish(update);\n\t}\n\n\tdispose(): void {\n\t\tif (this.#timer !== undefined) clearTimeout(this.#timer);\n\t\tthis.#timer = undefined;\n\t\tthis.#disposed = true;\n\t}\n\n\t#armTimer(wait: number): void {\n\t\tif (this.#timer !== undefined) return;\n\t\tthis.#timer = setTimeout(() => {\n\t\t\tthis.#timer = undefined;\n\t\t\ttry {\n\t\t\t\tthis.flush();\n\t\t\t} catch (error) {\n\t\t\t\tthis.#options.onError(error);\n\t\t\t}\n\t\t}, wait);\n\t}\n}\n"]}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Context } from "../context.ts";
|
|
2
|
-
import type { ShellOutputCaptureOptions, ShellOutputUpdate, ShellOutputView } from "../types.ts";
|
|
3
|
-
export declare const OUTPUT_MIN_EMIT_INTERVAL_MS = 100;
|
|
4
|
-
export declare const OUTPUT_TARGET_BYTES_PER_SECOND: number;
|
|
5
|
-
interface OutputCaptureHandlers {
|
|
6
|
-
onUpdate?: (update: ShellOutputUpdate, context: Context) => void;
|
|
7
|
-
onError(error: unknown): void;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Maintains and publishes one bounded shell-output view.
|
|
11
|
-
*
|
|
12
|
-
* Writes received while publication is rate-limited collapse into the latest
|
|
13
|
-
* view. Small changes remain responsive; complete window turnovers purchase a
|
|
14
|
-
* proportionally longer delay. The first update after idle and an explicit
|
|
15
|
-
* final flush are immediate.
|
|
16
|
-
*/
|
|
17
|
-
export declare class OutputCapture {
|
|
18
|
-
#private;
|
|
19
|
-
constructor(options: ShellOutputCaptureOptions | undefined, context: Context, handlers: OutputCaptureHandlers);
|
|
20
|
-
get truncated(): boolean;
|
|
21
|
-
push(chunk: string | Uint8Array): void;
|
|
22
|
-
finish(): void;
|
|
23
|
-
setSpillPath(path: string): void;
|
|
24
|
-
snapshot(): ShellOutputView;
|
|
25
|
-
flush(): void;
|
|
26
|
-
dispose(): void;
|
|
27
|
-
}
|
|
28
|
-
export declare function applyShellOutputUpdate(current: ShellOutputView | undefined, update: ShellOutputUpdate): ShellOutputView;
|
|
29
|
-
export declare function sanitizeShellOutput(text: string): string;
|
|
30
|
-
export {};
|
|
31
|
-
//# sourceMappingURL=output-capture.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"output-capture.d.ts","sourceRoot":"","sources":["../../../src/harness/utils/output-capture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,yBAAyB,EAAuB,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAItH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAC/C,eAAO,MAAM,8BAA8B,QAAa,CAAC;AAMzD,UAAU,qBAAqB;IAC9B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACjE,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,qBAAa,aAAa;;IAkBzB,YAAY,OAAO,EAAE,yBAAyB,GAAG,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAqB5G;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAQrC;IAED,MAAM,IAAI,IAAI,CAGb;IAED,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAK/B;IAED,QAAQ,IAAI,eAAe,CAoB1B;IAED,KAAK,IAAI,IAAI,CAGZ;IAED,OAAO,IAAI,IAAI,CAGd;CA4BD;AAED,wBAAgB,sBAAsB,CACrC,OAAO,EAAE,eAAe,GAAG,SAAS,EACpC,MAAM,EAAE,iBAAiB,GACvB,eAAe,CAWjB;AA+CD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { AdaptivePublisher } from "./adaptive-publisher.js";
|
|
2
|
-
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, truncateHead, truncateTail, utf8ByteLength } from "./truncate.js";
|
|
3
|
-
export const OUTPUT_MIN_EMIT_INTERVAL_MS = 100;
|
|
4
|
-
export const OUTPUT_TARGET_BYTES_PER_SECOND = 100 * 1024;
|
|
5
|
-
const INVALID_SHELL_OUTPUT = /[\x00-\x08\x0b-\x1f\ufff9-\ufffb]/g;
|
|
6
|
-
const textEncoder = new TextEncoder();
|
|
7
|
-
const textDecoder = new TextDecoder();
|
|
8
|
-
/**
|
|
9
|
-
* Maintains and publishes one bounded shell-output view.
|
|
10
|
-
*
|
|
11
|
-
* Writes received while publication is rate-limited collapse into the latest
|
|
12
|
-
* view. Small changes remain responsive; complete window turnovers purchase a
|
|
13
|
-
* proportionally longer delay. The first update after idle and an explicit
|
|
14
|
-
* final flush are immediate.
|
|
15
|
-
*/
|
|
16
|
-
export class OutputCapture {
|
|
17
|
-
#maxBytes;
|
|
18
|
-
#maxLines;
|
|
19
|
-
#retain;
|
|
20
|
-
#context;
|
|
21
|
-
#onUpdate;
|
|
22
|
-
#decoder = new TextDecoder();
|
|
23
|
-
#buffer = "";
|
|
24
|
-
#bufferBytes = 0;
|
|
25
|
-
#totalBytes = 0;
|
|
26
|
-
#newlines = 0;
|
|
27
|
-
#endsWithNewline = true;
|
|
28
|
-
#currentLineBytes = 0;
|
|
29
|
-
#spillPath;
|
|
30
|
-
#disposed = false;
|
|
31
|
-
#publisher;
|
|
32
|
-
constructor(options, context, handlers) {
|
|
33
|
-
this.#maxBytes = options?.limits.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
34
|
-
this.#maxLines = options?.limits.maxLines ?? DEFAULT_MAX_LINES;
|
|
35
|
-
this.#retain = options?.limits.retain ?? "tail";
|
|
36
|
-
this.#context = context;
|
|
37
|
-
this.#onUpdate = handlers.onUpdate;
|
|
38
|
-
if (!Number.isFinite(this.#maxBytes) || this.#maxBytes <= 0) {
|
|
39
|
-
throw new TypeError("Output maxBytes must be a positive finite number");
|
|
40
|
-
}
|
|
41
|
-
if (!Number.isInteger(this.#maxLines) || this.#maxLines <= 0) {
|
|
42
|
-
throw new TypeError("Output maxLines must be a positive integer");
|
|
43
|
-
}
|
|
44
|
-
this.#publisher = new AdaptivePublisher({
|
|
45
|
-
snapshot: () => this.snapshot(),
|
|
46
|
-
update: updateFrom,
|
|
47
|
-
measure: (update) => utf8ByteLength(JSON.stringify(update)),
|
|
48
|
-
publish: (update) => this.#onUpdate?.(update, this.#context),
|
|
49
|
-
onError: handlers.onError,
|
|
50
|
-
minIntervalMs: OUTPUT_MIN_EMIT_INTERVAL_MS,
|
|
51
|
-
targetBytesPerSecond: OUTPUT_TARGET_BYTES_PER_SECOND,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
get truncated() {
|
|
55
|
-
return this.#totalBytes > this.#maxBytes || this.#totalLines() > this.#maxLines;
|
|
56
|
-
}
|
|
57
|
-
push(chunk) {
|
|
58
|
-
if (this.#disposed)
|
|
59
|
-
return;
|
|
60
|
-
if (typeof chunk === "string") {
|
|
61
|
-
this.#appendText(this.#decoder.decode());
|
|
62
|
-
this.#appendText(chunk);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
this.#appendText(this.#decoder.decode(chunk, { stream: true }));
|
|
66
|
-
}
|
|
67
|
-
finish() {
|
|
68
|
-
if (this.#disposed)
|
|
69
|
-
return;
|
|
70
|
-
this.#appendText(this.#decoder.decode());
|
|
71
|
-
}
|
|
72
|
-
setSpillPath(path) {
|
|
73
|
-
if (this.#disposed || this.#spillPath === path)
|
|
74
|
-
return;
|
|
75
|
-
this.#spillPath = path;
|
|
76
|
-
this.#publisher.markDirty();
|
|
77
|
-
this.flush();
|
|
78
|
-
}
|
|
79
|
-
snapshot() {
|
|
80
|
-
const retained = this.#retain === "head"
|
|
81
|
-
? truncateHead(this.#buffer, { maxBytes: this.#maxBytes, maxLines: this.#maxLines })
|
|
82
|
-
: truncateTail(this.#buffer, { maxBytes: this.#maxBytes, maxLines: this.#maxLines });
|
|
83
|
-
const totalLines = this.#totalLines();
|
|
84
|
-
const truncated = this.truncated;
|
|
85
|
-
const { content, ...truncation } = retained;
|
|
86
|
-
return {
|
|
87
|
-
text: sanitizeShellOutput(content),
|
|
88
|
-
truncation: {
|
|
89
|
-
...truncation,
|
|
90
|
-
truncated,
|
|
91
|
-
truncatedBy: truncated ? (totalLines > this.#maxLines ? "lines" : "bytes") : null,
|
|
92
|
-
totalBytes: this.#totalBytes,
|
|
93
|
-
totalLines,
|
|
94
|
-
},
|
|
95
|
-
...(this.#spillPath === undefined ? {} : { spillPath: this.#spillPath }),
|
|
96
|
-
...(retained.lastLinePartial ? { lastLineBytes: this.#currentLineBytes } : {}),
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
flush() {
|
|
100
|
-
if (this.#disposed)
|
|
101
|
-
return;
|
|
102
|
-
this.#publisher.flush(true);
|
|
103
|
-
}
|
|
104
|
-
dispose() {
|
|
105
|
-
this.#publisher.dispose();
|
|
106
|
-
this.#disposed = true;
|
|
107
|
-
}
|
|
108
|
-
#appendText(text) {
|
|
109
|
-
if (text === "")
|
|
110
|
-
return;
|
|
111
|
-
const textBytes = utf8ByteLength(text);
|
|
112
|
-
this.#totalBytes += textBytes;
|
|
113
|
-
this.#newlines += countNewlines(text);
|
|
114
|
-
this.#endsWithNewline = text.endsWith("\n");
|
|
115
|
-
const lastNewline = text.lastIndexOf("\n");
|
|
116
|
-
this.#currentLineBytes =
|
|
117
|
-
lastNewline === -1 ? this.#currentLineBytes + textBytes : utf8ByteLength(text.slice(lastNewline + 1));
|
|
118
|
-
this.#buffer += text;
|
|
119
|
-
this.#bufferBytes += textBytes;
|
|
120
|
-
const guard = this.#maxBytes * 2;
|
|
121
|
-
if (this.#bufferBytes > guard * 2) {
|
|
122
|
-
this.#buffer =
|
|
123
|
-
this.#retain === "tail"
|
|
124
|
-
? trimToLastUtf8Bytes(this.#buffer, guard)
|
|
125
|
-
: trimToFirstUtf8Bytes(this.#buffer, guard);
|
|
126
|
-
this.#bufferBytes = utf8ByteLength(this.#buffer);
|
|
127
|
-
}
|
|
128
|
-
this.#publisher.markDirty();
|
|
129
|
-
}
|
|
130
|
-
#totalLines() {
|
|
131
|
-
return this.#newlines + (this.#endsWithNewline || this.#totalBytes === 0 ? 0 : 1);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
export function applyShellOutputUpdate(current, update) {
|
|
135
|
-
switch (update.kind) {
|
|
136
|
-
case "replace":
|
|
137
|
-
return update.output;
|
|
138
|
-
case "append":
|
|
139
|
-
return { text: `${current?.text ?? ""}${update.text}`, ...update.metadata };
|
|
140
|
-
case "slide":
|
|
141
|
-
return { text: `${current?.text.slice(update.drop) ?? ""}${update.text}`, ...update.metadata };
|
|
142
|
-
case "metadata":
|
|
143
|
-
return { text: current?.text ?? "", ...update.metadata };
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function updateFrom(previous, current) {
|
|
147
|
-
if (previous === undefined)
|
|
148
|
-
return { kind: "replace", output: current };
|
|
149
|
-
const metadata = {
|
|
150
|
-
truncation: current.truncation,
|
|
151
|
-
...(current.spillPath === undefined ? {} : { spillPath: current.spillPath }),
|
|
152
|
-
...(current.lastLineBytes === undefined ? {} : { lastLineBytes: current.lastLineBytes }),
|
|
153
|
-
};
|
|
154
|
-
if (current.text === previous.text)
|
|
155
|
-
return { kind: "metadata", metadata };
|
|
156
|
-
if (current.text.length > previous.text.length && current.text.slice(0, previous.text.length) === previous.text) {
|
|
157
|
-
return { kind: "append", text: current.text.slice(previous.text.length), metadata };
|
|
158
|
-
}
|
|
159
|
-
const shared = suffixPrefixOverlap(previous.text, current.text, Math.min(previous.text.length, current.text.length, current.truncation.maxBytes * 2));
|
|
160
|
-
if (shared > 0) {
|
|
161
|
-
return {
|
|
162
|
-
kind: "slide",
|
|
163
|
-
drop: previous.text.length - shared,
|
|
164
|
-
text: current.text.slice(shared),
|
|
165
|
-
metadata,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
return { kind: "replace", output: current };
|
|
169
|
-
}
|
|
170
|
-
function suffixPrefixOverlap(before, after, scan) {
|
|
171
|
-
if (before.length === 0 || after.length === 0 || scan === 0)
|
|
172
|
-
return 0;
|
|
173
|
-
const tail = before.length > scan ? before.slice(before.length - scan) : before;
|
|
174
|
-
for (const probeLength of [Math.min(64, after.length), 1]) {
|
|
175
|
-
const probe = after.slice(0, probeLength);
|
|
176
|
-
let candidates = 0;
|
|
177
|
-
for (let index = tail.indexOf(probe); index !== -1; index = tail.indexOf(probe, index + 1)) {
|
|
178
|
-
if (++candidates > 8)
|
|
179
|
-
break;
|
|
180
|
-
const overlapLength = tail.length - index;
|
|
181
|
-
if (overlapLength <= after.length && tail.slice(index) === after.slice(0, overlapLength)) {
|
|
182
|
-
return overlapLength;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (probeLength === 1)
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
return 0;
|
|
189
|
-
}
|
|
190
|
-
export function sanitizeShellOutput(text) {
|
|
191
|
-
return text.replace(INVALID_SHELL_OUTPUT, "");
|
|
192
|
-
}
|
|
193
|
-
function countNewlines(text) {
|
|
194
|
-
let count = 0;
|
|
195
|
-
for (let index = text.indexOf("\n"); index !== -1; index = text.indexOf("\n", index + 1))
|
|
196
|
-
count++;
|
|
197
|
-
return count;
|
|
198
|
-
}
|
|
199
|
-
function trimToLastUtf8Bytes(text, maxBytes) {
|
|
200
|
-
const bytes = textEncoder.encode(text);
|
|
201
|
-
if (bytes.length <= maxBytes)
|
|
202
|
-
return text;
|
|
203
|
-
let start = bytes.length - maxBytes;
|
|
204
|
-
while (start < bytes.length && ((bytes[start] ?? 0) & 0xc0) === 0x80)
|
|
205
|
-
start++;
|
|
206
|
-
return textDecoder.decode(bytes.subarray(start));
|
|
207
|
-
}
|
|
208
|
-
function trimToFirstUtf8Bytes(text, maxBytes) {
|
|
209
|
-
const bytes = textEncoder.encode(text);
|
|
210
|
-
if (bytes.length <= maxBytes)
|
|
211
|
-
return text;
|
|
212
|
-
let end = maxBytes;
|
|
213
|
-
while (end > 0 && ((bytes[end] ?? 0) & 0xc0) === 0x80)
|
|
214
|
-
end--;
|
|
215
|
-
return textDecoder.decode(bytes.subarray(0, end));
|
|
216
|
-
}
|
|
217
|
-
//# sourceMappingURL=output-capture.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"output-capture.js","sourceRoot":"","sources":["../../../src/harness/utils/output-capture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEjH,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAC/C,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,GAAG,IAAI,CAAC;AAEzD,MAAM,oBAAoB,GAAG,oCAAoC,CAAC;AAClE,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AACtC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAOtC;;;;;;;GAOG;AACH,MAAM,OAAO,aAAa;IAChB,SAAS,CAAS;IAClB,SAAS,CAAS;IAClB,OAAO,CAAkB;IACzB,QAAQ,CAAU;IAClB,SAAS,CAAoC;IAE7C,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC;IACtC,OAAO,GAAG,EAAE,CAAC;IACb,YAAY,GAAG,CAAC,CAAC;IACjB,WAAW,GAAG,CAAC,CAAC;IAChB,SAAS,GAAG,CAAC,CAAC;IACd,gBAAgB,GAAG,IAAI,CAAC;IACxB,iBAAiB,GAAG,CAAC,CAAC;IACtB,UAAU,CAAqB;IAC/B,SAAS,GAAG,KAAK,CAAC;IACT,UAAU,CAAwD;IAE3E,YAAY,OAA8C,EAAE,OAAgB,EAAE,QAA+B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,CAAC,IAAY,EAAE,QAAgB;IAC1D,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC;IACpC,OAAO,KAAK,GAAG,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI;QAAE,KAAK,EAAE,CAAC;IAC9E,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAY,EAAE,QAAgB;IAC3D,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,GAAG,GAAG,QAAQ,CAAC;IACnB,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI;QAAE,GAAG,EAAE,CAAC;IAC7D,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import type { Context } from \"../context.ts\";\nimport type { ShellOutputCaptureOptions, ShellOutputMetadata, ShellOutputUpdate, ShellOutputView } from \"../types.ts\";\nimport { AdaptivePublisher } from \"./adaptive-publisher.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, truncateHead, truncateTail, utf8ByteLength } from \"./truncate.ts\";\n\nexport const OUTPUT_MIN_EMIT_INTERVAL_MS = 100;\nexport const OUTPUT_TARGET_BYTES_PER_SECOND = 100 * 1024;\n\nconst INVALID_SHELL_OUTPUT = /[\\x00-\\x08\\x0b-\\x1f\\ufff9-\\ufffb]/g;\nconst textEncoder = new TextEncoder();\nconst textDecoder = new TextDecoder();\n\ninterface OutputCaptureHandlers {\n\tonUpdate?: (update: ShellOutputUpdate, context: Context) => void;\n\tonError(error: unknown): void;\n}\n\n/**\n * Maintains and publishes one bounded shell-output view.\n *\n * Writes received while publication is rate-limited collapse into the latest\n * view. Small changes remain responsive; complete window turnovers purchase a\n * proportionally longer delay. The first update after idle and an explicit\n * final flush are immediate.\n */\nexport class OutputCapture {\n\treadonly #maxBytes: number;\n\treadonly #maxLines: number;\n\treadonly #retain: \"head\" | \"tail\";\n\treadonly #context: Context;\n\treadonly #onUpdate: OutputCaptureHandlers[\"onUpdate\"];\n\n\treadonly #decoder = new TextDecoder();\n\t#buffer = \"\";\n\t#bufferBytes = 0;\n\t#totalBytes = 0;\n\t#newlines = 0;\n\t#endsWithNewline = true;\n\t#currentLineBytes = 0;\n\t#spillPath: string | undefined;\n\t#disposed = false;\n\treadonly #publisher: AdaptivePublisher<ShellOutputView, ShellOutputUpdate>;\n\n\tconstructor(options: ShellOutputCaptureOptions | undefined, context: Context, handlers: OutputCaptureHandlers) {\n\t\tthis.#maxBytes = options?.limits.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.#maxLines = options?.limits.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.#retain = options?.limits.retain ?? \"tail\";\n\t\tthis.#context = context;\n\t\tthis.#onUpdate = handlers.onUpdate;\n\t\tif (!Number.isFinite(this.#maxBytes) || this.#maxBytes <= 0) {\n\t\t\tthrow new TypeError(\"Output maxBytes must be a positive finite number\");\n\t\t}\n\t\tif (!Number.isInteger(this.#maxLines) || this.#maxLines <= 0) {\n\t\t\tthrow new TypeError(\"Output maxLines must be a positive integer\");\n\t\t}\n\t\tthis.#publisher = new AdaptivePublisher({\n\t\t\tsnapshot: () => this.snapshot(),\n\t\t\tupdate: updateFrom,\n\t\t\tmeasure: (update) => utf8ByteLength(JSON.stringify(update)),\n\t\t\tpublish: (update) => this.#onUpdate?.(update, this.#context),\n\t\t\tonError: handlers.onError,\n\t\t\tminIntervalMs: OUTPUT_MIN_EMIT_INTERVAL_MS,\n\t\t\ttargetBytesPerSecond: OUTPUT_TARGET_BYTES_PER_SECOND,\n\t\t});\n\t}\n\n\tget truncated(): boolean {\n\t\treturn this.#totalBytes > this.#maxBytes || this.#totalLines() > this.#maxLines;\n\t}\n\n\tpush(chunk: string | Uint8Array): void {\n\t\tif (this.#disposed) return;\n\t\tif (typeof chunk === \"string\") {\n\t\t\tthis.#appendText(this.#decoder.decode());\n\t\t\tthis.#appendText(chunk);\n\t\t\treturn;\n\t\t}\n\t\tthis.#appendText(this.#decoder.decode(chunk, { stream: true }));\n\t}\n\n\tfinish(): void {\n\t\tif (this.#disposed) return;\n\t\tthis.#appendText(this.#decoder.decode());\n\t}\n\n\tsetSpillPath(path: string): void {\n\t\tif (this.#disposed || this.#spillPath === path) return;\n\t\tthis.#spillPath = path;\n\t\tthis.#publisher.markDirty();\n\t\tthis.flush();\n\t}\n\n\tsnapshot(): ShellOutputView {\n\t\tconst retained =\n\t\t\tthis.#retain === \"head\"\n\t\t\t\t? truncateHead(this.#buffer, { maxBytes: this.#maxBytes, maxLines: this.#maxLines })\n\t\t\t\t: truncateTail(this.#buffer, { maxBytes: this.#maxBytes, maxLines: this.#maxLines });\n\t\tconst totalLines = this.#totalLines();\n\t\tconst truncated = this.truncated;\n\t\tconst { content, ...truncation } = retained;\n\t\treturn {\n\t\t\ttext: sanitizeShellOutput(content),\n\t\t\ttruncation: {\n\t\t\t\t...truncation,\n\t\t\t\ttruncated,\n\t\t\t\ttruncatedBy: truncated ? (totalLines > this.#maxLines ? \"lines\" : \"bytes\") : null,\n\t\t\t\ttotalBytes: this.#totalBytes,\n\t\t\t\ttotalLines,\n\t\t\t},\n\t\t\t...(this.#spillPath === undefined ? {} : { spillPath: this.#spillPath }),\n\t\t\t...(retained.lastLinePartial ? { lastLineBytes: this.#currentLineBytes } : {}),\n\t\t};\n\t}\n\n\tflush(): void {\n\t\tif (this.#disposed) return;\n\t\tthis.#publisher.flush(true);\n\t}\n\n\tdispose(): void {\n\t\tthis.#publisher.dispose();\n\t\tthis.#disposed = true;\n\t}\n\n\t#appendText(text: string): void {\n\t\tif (text === \"\") return;\n\t\tconst textBytes = utf8ByteLength(text);\n\t\tthis.#totalBytes += textBytes;\n\t\tthis.#newlines += countNewlines(text);\n\t\tthis.#endsWithNewline = text.endsWith(\"\\n\");\n\t\tconst lastNewline = text.lastIndexOf(\"\\n\");\n\t\tthis.#currentLineBytes =\n\t\t\tlastNewline === -1 ? this.#currentLineBytes + textBytes : utf8ByteLength(text.slice(lastNewline + 1));\n\t\tthis.#buffer += text;\n\t\tthis.#bufferBytes += textBytes;\n\n\t\tconst guard = this.#maxBytes * 2;\n\t\tif (this.#bufferBytes > guard * 2) {\n\t\t\tthis.#buffer =\n\t\t\t\tthis.#retain === \"tail\"\n\t\t\t\t\t? trimToLastUtf8Bytes(this.#buffer, guard)\n\t\t\t\t\t: trimToFirstUtf8Bytes(this.#buffer, guard);\n\t\t\tthis.#bufferBytes = utf8ByteLength(this.#buffer);\n\t\t}\n\t\tthis.#publisher.markDirty();\n\t}\n\n\t#totalLines(): number {\n\t\treturn this.#newlines + (this.#endsWithNewline || this.#totalBytes === 0 ? 0 : 1);\n\t}\n}\n\nexport function applyShellOutputUpdate(\n\tcurrent: ShellOutputView | undefined,\n\tupdate: ShellOutputUpdate,\n): ShellOutputView {\n\tswitch (update.kind) {\n\t\tcase \"replace\":\n\t\t\treturn update.output;\n\t\tcase \"append\":\n\t\t\treturn { text: `${current?.text ?? \"\"}${update.text}`, ...update.metadata };\n\t\tcase \"slide\":\n\t\t\treturn { text: `${current?.text.slice(update.drop) ?? \"\"}${update.text}`, ...update.metadata };\n\t\tcase \"metadata\":\n\t\t\treturn { text: current?.text ?? \"\", ...update.metadata };\n\t}\n}\n\nfunction updateFrom(previous: ShellOutputView | undefined, current: ShellOutputView): ShellOutputUpdate {\n\tif (previous === undefined) return { kind: \"replace\", output: current };\n\tconst metadata: ShellOutputMetadata = {\n\t\ttruncation: current.truncation,\n\t\t...(current.spillPath === undefined ? {} : { spillPath: current.spillPath }),\n\t\t...(current.lastLineBytes === undefined ? {} : { lastLineBytes: current.lastLineBytes }),\n\t};\n\tif (current.text === previous.text) return { kind: \"metadata\", metadata };\n\tif (current.text.length > previous.text.length && current.text.slice(0, previous.text.length) === previous.text) {\n\t\treturn { kind: \"append\", text: current.text.slice(previous.text.length), metadata };\n\t}\n\tconst shared = suffixPrefixOverlap(\n\t\tprevious.text,\n\t\tcurrent.text,\n\t\tMath.min(previous.text.length, current.text.length, current.truncation.maxBytes * 2),\n\t);\n\tif (shared > 0) {\n\t\treturn {\n\t\t\tkind: \"slide\",\n\t\t\tdrop: previous.text.length - shared,\n\t\t\ttext: current.text.slice(shared),\n\t\t\tmetadata,\n\t\t};\n\t}\n\treturn { kind: \"replace\", output: current };\n}\n\nfunction suffixPrefixOverlap(before: string, after: string, scan: number): number {\n\tif (before.length === 0 || after.length === 0 || scan === 0) return 0;\n\tconst tail = before.length > scan ? before.slice(before.length - scan) : before;\n\tfor (const probeLength of [Math.min(64, after.length), 1]) {\n\t\tconst probe = after.slice(0, probeLength);\n\t\tlet candidates = 0;\n\t\tfor (let index = tail.indexOf(probe); index !== -1; index = tail.indexOf(probe, index + 1)) {\n\t\t\tif (++candidates > 8) break;\n\t\t\tconst overlapLength = tail.length - index;\n\t\t\tif (overlapLength <= after.length && tail.slice(index) === after.slice(0, overlapLength)) {\n\t\t\t\treturn overlapLength;\n\t\t\t}\n\t\t}\n\t\tif (probeLength === 1) break;\n\t}\n\treturn 0;\n}\n\nexport function sanitizeShellOutput(text: string): string {\n\treturn text.replace(INVALID_SHELL_OUTPUT, \"\");\n}\n\nfunction countNewlines(text: string): number {\n\tlet count = 0;\n\tfor (let index = text.indexOf(\"\\n\"); index !== -1; index = text.indexOf(\"\\n\", index + 1)) count++;\n\treturn count;\n}\n\nfunction trimToLastUtf8Bytes(text: string, maxBytes: number): string {\n\tconst bytes = textEncoder.encode(text);\n\tif (bytes.length <= maxBytes) return text;\n\tlet start = bytes.length - maxBytes;\n\twhile (start < bytes.length && ((bytes[start] ?? 0) & 0xc0) === 0x80) start++;\n\treturn textDecoder.decode(bytes.subarray(start));\n}\n\nfunction trimToFirstUtf8Bytes(text: string, maxBytes: number): string {\n\tconst bytes = textEncoder.encode(text);\n\tif (bytes.length <= maxBytes) return text;\n\tlet end = maxBytes;\n\twhile (end > 0 && ((bytes[end] ?? 0) & 0xc0) === 0x80) end--;\n\treturn textDecoder.decode(bytes.subarray(0, end));\n}\n"]}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Context } from "../context.ts";
|
|
2
|
-
import { type ExecutionEnv, type ExecutionError, type Result, type ShellExecOptions } from "../types.ts";
|
|
3
|
-
import { sanitizeShellOutput } from "./output-capture.ts";
|
|
4
|
-
import { type TruncationResult } from "./truncate.ts";
|
|
5
|
-
export interface ShellCaptureProgress {
|
|
6
|
-
output: string;
|
|
7
|
-
truncation: TruncationResult;
|
|
8
|
-
fullOutputPath?: string;
|
|
9
|
-
lastLineBytes: number;
|
|
10
|
-
}
|
|
11
|
-
export interface ShellCaptureOptions extends Omit<ShellExecOptions, "capture" | "onUpdate"> {
|
|
12
|
-
onChunk?: (chunk: string, getProgress: () => ShellCaptureProgress, context: Context) => void;
|
|
13
|
-
/** Return shell execution failures with captured output instead of as a failed Result. */
|
|
14
|
-
returnExecutionErrors?: boolean;
|
|
15
|
-
}
|
|
16
|
-
export interface ShellCaptureResult extends ShellCaptureProgress {
|
|
17
|
-
exitCode: number | undefined;
|
|
18
|
-
cancelled: boolean;
|
|
19
|
-
truncated: boolean;
|
|
20
|
-
executionError?: ExecutionError;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Compatibility collector for callers that need one bounded final view.
|
|
24
|
-
* Source-side capture, adaptive publication, and spilling remain owned by the
|
|
25
|
-
* execution environment.
|
|
26
|
-
*/
|
|
27
|
-
export declare function executeShellWithCapture(env: ExecutionEnv, command: string, options: ShellCaptureOptions | undefined, context: Context): Promise<Result<ShellCaptureResult, ExecutionError>>;
|
|
28
|
-
export { sanitizeShellOutput as sanitizeBinaryOutput };
|
|
29
|
-
//# sourceMappingURL=shell-output.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shell-output.d.ts","sourceRoot":"","sources":["../../../src/harness/utils/shell-output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,gBAAgB,EAErB,MAAM,aAAa,CAAC;AACrB,OAAO,EAA0B,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAwC,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AAE1G,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,gBAAgB,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,UAAU,CAAC;IAC1F,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,oBAAoB,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7F,0FAA0F;IAC1F,qBAAqB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,kBAAmB,SAAQ,oBAAoB;IAC/D,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,cAAc,CAAC;CAChC;AAWD;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC5C,GAAG,EAAE,YAAY,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,mBAAmB,GAAG,SAAS,EACxC,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,MAAM,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC,CAyDrD;AAED,OAAO,EAAE,mBAAmB,IAAI,oBAAoB,EAAE,CAAC"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { err, ok, } from "../types.js";
|
|
2
|
-
import { applyShellOutputUpdate, sanitizeShellOutput } from "./output-capture.js";
|
|
3
|
-
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, truncateTail } from "./truncate.js";
|
|
4
|
-
function progressFrom(output) {
|
|
5
|
-
return {
|
|
6
|
-
output: output.text,
|
|
7
|
-
truncation: { content: output.text, ...output.truncation },
|
|
8
|
-
...(output.spillPath === undefined ? {} : { fullOutputPath: output.spillPath }),
|
|
9
|
-
lastLineBytes: output.lastLineBytes ?? 0,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Compatibility collector for callers that need one bounded final view.
|
|
14
|
-
* Source-side capture, adaptive publication, and spilling remain owned by the
|
|
15
|
-
* execution environment.
|
|
16
|
-
*/
|
|
17
|
-
export async function executeShellWithCapture(env, command, options, context) {
|
|
18
|
-
let output;
|
|
19
|
-
const result = await env.exec(command, {
|
|
20
|
-
cwd: options?.cwd,
|
|
21
|
-
env: options?.env,
|
|
22
|
-
inheritEnv: options?.inheritEnv,
|
|
23
|
-
timeout: options?.timeout,
|
|
24
|
-
capture: {
|
|
25
|
-
limits: { maxBytes: DEFAULT_MAX_BYTES, maxLines: DEFAULT_MAX_LINES, retain: "tail" },
|
|
26
|
-
spill: true,
|
|
27
|
-
},
|
|
28
|
-
onUpdate: (update, updateContext) => {
|
|
29
|
-
const previous = output;
|
|
30
|
-
output = applyShellOutputUpdate(output, update);
|
|
31
|
-
const chunk = update.kind === "append" || update.kind === "slide"
|
|
32
|
-
? update.text
|
|
33
|
-
: update.kind === "replace" && previous === undefined
|
|
34
|
-
? output.text
|
|
35
|
-
: undefined;
|
|
36
|
-
// A metadata-only update and a post-cap replacement contain no new
|
|
37
|
-
// incremental chunk. Reporting their complete view would duplicate bytes
|
|
38
|
-
// for callers that accumulate this compatibility callback.
|
|
39
|
-
if (chunk)
|
|
40
|
-
options?.onChunk?.(chunk, () => progressFrom(output), updateContext);
|
|
41
|
-
},
|
|
42
|
-
}, context);
|
|
43
|
-
if (output === undefined) {
|
|
44
|
-
const { content, ...truncation } = truncateTail("");
|
|
45
|
-
output = { text: content, truncation };
|
|
46
|
-
}
|
|
47
|
-
const progress = progressFrom(output);
|
|
48
|
-
if (!result.ok) {
|
|
49
|
-
if (result.error.code === "aborted" || context.abortSignal?.aborted) {
|
|
50
|
-
return ok({ ...progress, exitCode: undefined, cancelled: true, truncated: progress.truncation.truncated });
|
|
51
|
-
}
|
|
52
|
-
if (options?.returnExecutionErrors) {
|
|
53
|
-
return ok({
|
|
54
|
-
...progress,
|
|
55
|
-
exitCode: undefined,
|
|
56
|
-
cancelled: false,
|
|
57
|
-
truncated: progress.truncation.truncated,
|
|
58
|
-
executionError: result.error,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
return err(result.error);
|
|
62
|
-
}
|
|
63
|
-
return ok({
|
|
64
|
-
...progress,
|
|
65
|
-
exitCode: result.value.exitCode,
|
|
66
|
-
cancelled: false,
|
|
67
|
-
truncated: result.value.truncation.truncated,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
export { sanitizeShellOutput as sanitizeBinaryOutput };
|
|
71
|
-
//# sourceMappingURL=shell-output.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shell-output.js","sourceRoot":"","sources":["../../../src/harness/utils/shell-output.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S,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS;gBACxC,cAAc,EAAE,MAAM,CAAC,KAAK;aAC5B,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,EAAE,CAAC;QACT,GAAG,QAAQ;QACX,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ;QAC/B,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS;KAC5C,CAAC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,mBAAmB,IAAI,oBAAoB,EAAE,CAAC","sourcesContent":["import type { Context } from \"../context.ts\";\nimport {\n\ttype ExecutionEnv,\n\ttype ExecutionError,\n\terr,\n\tok,\n\ttype Result,\n\ttype ShellExecOptions,\n\ttype ShellOutputView,\n} from \"../types.ts\";\nimport { applyShellOutputUpdate, sanitizeShellOutput } from \"./output-capture.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult, truncateTail } from \"./truncate.ts\";\n\nexport interface ShellCaptureProgress {\n\toutput: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n\tlastLineBytes: number;\n}\n\nexport interface ShellCaptureOptions extends Omit<ShellExecOptions, \"capture\" | \"onUpdate\"> {\n\tonChunk?: (chunk: string, getProgress: () => ShellCaptureProgress, context: Context) => void;\n\t/** Return shell execution failures with captured output instead of as a failed Result. */\n\treturnExecutionErrors?: boolean;\n}\n\nexport interface ShellCaptureResult extends ShellCaptureProgress {\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\texecutionError?: ExecutionError;\n}\n\nfunction progressFrom(output: ShellOutputView): ShellCaptureProgress {\n\treturn {\n\t\toutput: output.text,\n\t\ttruncation: { content: output.text, ...output.truncation },\n\t\t...(output.spillPath === undefined ? {} : { fullOutputPath: output.spillPath }),\n\t\tlastLineBytes: output.lastLineBytes ?? 0,\n\t};\n}\n\n/**\n * Compatibility collector for callers that need one bounded final view.\n * Source-side capture, adaptive publication, and spilling remain owned by the\n * execution environment.\n */\nexport async function executeShellWithCapture(\n\tenv: ExecutionEnv,\n\tcommand: string,\n\toptions: ShellCaptureOptions | undefined,\n\tcontext: Context,\n): Promise<Result<ShellCaptureResult, ExecutionError>> {\n\tlet output: ShellOutputView | undefined;\n\tconst result = await env.exec(\n\t\tcommand,\n\t\t{\n\t\t\tcwd: options?.cwd,\n\t\t\tenv: options?.env,\n\t\t\tinheritEnv: options?.inheritEnv,\n\t\t\ttimeout: options?.timeout,\n\t\t\tcapture: {\n\t\t\t\tlimits: { maxBytes: DEFAULT_MAX_BYTES, maxLines: DEFAULT_MAX_LINES, retain: \"tail\" },\n\t\t\t\tspill: true,\n\t\t\t},\n\t\t\tonUpdate: (update, updateContext) => {\n\t\t\t\tconst previous = output;\n\t\t\t\toutput = applyShellOutputUpdate(output, update);\n\t\t\t\tconst chunk =\n\t\t\t\t\tupdate.kind === \"append\" || update.kind === \"slide\"\n\t\t\t\t\t\t? update.text\n\t\t\t\t\t\t: update.kind === \"replace\" && previous === undefined\n\t\t\t\t\t\t\t? output.text\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t// A metadata-only update and a post-cap replacement contain no new\n\t\t\t\t// incremental chunk. Reporting their complete view would duplicate bytes\n\t\t\t\t// for callers that accumulate this compatibility callback.\n\t\t\t\tif (chunk) options?.onChunk?.(chunk, () => progressFrom(output!), updateContext);\n\t\t\t},\n\t\t},\n\t\tcontext,\n\t);\n\n\tif (output === undefined) {\n\t\tconst { content, ...truncation } = truncateTail(\"\");\n\t\toutput = { text: content, truncation };\n\t}\n\tconst progress = progressFrom(output);\n\tif (!result.ok) {\n\t\tif (result.error.code === \"aborted\" || context.abortSignal?.aborted) {\n\t\t\treturn ok({ ...progress, exitCode: undefined, cancelled: true, truncated: progress.truncation.truncated });\n\t\t}\n\t\tif (options?.returnExecutionErrors) {\n\t\t\treturn ok({\n\t\t\t\t...progress,\n\t\t\t\texitCode: undefined,\n\t\t\t\tcancelled: false,\n\t\t\t\ttruncated: progress.truncation.truncated,\n\t\t\t\texecutionError: result.error,\n\t\t\t});\n\t\t}\n\t\treturn err(result.error);\n\t}\n\treturn ok({\n\t\t...progress,\n\t\texitCode: result.value.exitCode,\n\t\tcancelled: false,\n\t\ttruncated: result.value.truncation.truncated,\n\t});\n}\n\nexport { sanitizeShellOutput as sanitizeBinaryOutput };\n"]}
|