@code-yeongyu/senpi-agent-core 2026.9.12-3 → 2026.9.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/dist/harness/agent-harness.d.ts +384 -639
- package/dist/harness/agent-harness.d.ts.map +1 -1
- package/dist/harness/agent-harness.js +250 -5
- package/dist/harness/agent-harness.js.map +1 -1
- package/dist/harness/compaction/branch-summarization.d.ts +6 -12
- package/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/harness/compaction/branch-summarization.js +27 -33
- package/dist/harness/compaction/branch-summarization.js.map +1 -1
- package/dist/harness/compaction/compaction.d.ts +8 -30
- package/dist/harness/compaction/compaction.d.ts.map +1 -1
- package/dist/harness/compaction/compaction.js +64 -53
- package/dist/harness/compaction/compaction.js.map +1 -1
- package/dist/harness/env/nodejs.d.ts +28 -25
- package/dist/harness/env/nodejs.d.ts.map +1 -1
- package/dist/harness/env/nodejs.js +125 -368
- package/dist/harness/env/nodejs.js.map +1 -1
- package/dist/harness/events.d.ts +38 -20
- package/dist/harness/events.d.ts.map +1 -1
- package/dist/harness/events.js +55 -233
- package/dist/harness/events.js.map +1 -1
- package/dist/harness/messages.d.ts +2 -2
- package/dist/harness/messages.d.ts.map +1 -1
- package/dist/harness/messages.js.map +1 -1
- package/dist/harness/prompt-templates.d.ts +2 -3
- package/dist/harness/prompt-templates.d.ts.map +1 -1
- package/dist/harness/prompt-templates.js +17 -17
- package/dist/harness/prompt-templates.js.map +1 -1
- package/dist/harness/reducer.d.ts +100 -0
- package/dist/harness/reducer.d.ts.map +1 -0
- package/dist/harness/reducer.js +420 -0
- package/dist/harness/reducer.js.map +1 -0
- package/dist/harness/result.d.ts +0 -93
- package/dist/harness/result.d.ts.map +1 -1
- package/dist/harness/result.js +0 -39
- package/dist/harness/result.js.map +1 -1
- package/dist/harness/session/context.d.ts +19 -6
- package/dist/harness/session/context.d.ts.map +1 -1
- package/dist/harness/session/context.js +53 -31
- package/dist/harness/session/context.js.map +1 -1
- package/dist/harness/session/index.d.ts +5 -9
- package/dist/harness/session/index.d.ts.map +1 -1
- package/dist/harness/session/index.js +4 -7
- package/dist/harness/session/index.js.map +1 -1
- package/dist/harness/session/jsonl/codec.d.ts +8 -19
- package/dist/harness/session/jsonl/codec.d.ts.map +1 -1
- package/dist/harness/session/jsonl/codec.js +219 -34
- package/dist/harness/session/jsonl/codec.js.map +1 -1
- package/dist/harness/session/jsonl/errors.d.ts +9 -0
- package/dist/harness/session/jsonl/errors.d.ts.map +1 -0
- package/dist/harness/session/jsonl/errors.js +18 -0
- package/dist/harness/session/jsonl/errors.js.map +1 -0
- package/dist/harness/session/jsonl/repo.d.ts +24 -27
- package/dist/harness/session/jsonl/repo.d.ts.map +1 -1
- package/dist/harness/session/jsonl/repo.js +151 -276
- package/dist/harness/session/jsonl/repo.js.map +1 -1
- package/dist/harness/session/jsonl/storage.d.ts +41 -39
- package/dist/harness/session/jsonl/storage.d.ts.map +1 -1
- package/dist/harness/session/jsonl/storage.js +196 -175
- package/dist/harness/session/jsonl/storage.js.map +1 -1
- package/dist/harness/session/jsonl/types.d.ts +22 -23
- package/dist/harness/session/jsonl/types.d.ts.map +1 -1
- package/dist/harness/session/jsonl/types.js +1 -2
- package/dist/harness/session/jsonl/types.js.map +1 -1
- package/dist/harness/session/jsonl.d.ts +3 -0
- package/dist/harness/session/jsonl.d.ts.map +1 -0
- package/dist/harness/session/jsonl.js +2 -0
- package/dist/harness/session/jsonl.js.map +1 -0
- package/dist/harness/session/memory.d.ts +40 -44
- package/dist/harness/session/memory.d.ts.map +1 -1
- package/dist/harness/session/memory.js +115 -333
- package/dist/harness/session/memory.js.map +1 -1
- package/dist/harness/session/session.d.ts +51 -78
- package/dist/harness/session/session.d.ts.map +1 -1
- package/dist/harness/session/session.js +207 -327
- package/dist/harness/session/session.js.map +1 -1
- package/dist/harness/session/state.d.ts +65 -0
- package/dist/harness/session/state.d.ts.map +1 -0
- package/dist/harness/session/state.js +320 -0
- package/dist/harness/session/state.js.map +1 -0
- package/dist/harness/session/testing/conformance.d.ts +4 -0
- package/dist/harness/session/testing/conformance.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance.js +762 -0
- package/dist/harness/session/testing/conformance.js.map +1 -0
- package/dist/harness/session/testing/index.d.ts +2 -9
- package/dist/harness/session/testing/index.d.ts.map +1 -1
- package/dist/harness/session/testing/index.js +1 -8
- package/dist/harness/session/testing/index.js.map +1 -1
- package/dist/harness/session/testing/types.d.ts +7 -5
- package/dist/harness/session/testing/types.d.ts.map +1 -1
- package/dist/harness/session/testing/types.js.map +1 -1
- package/dist/harness/session/types.d.ts +265 -425
- package/dist/harness/session/types.d.ts.map +1 -1
- package/dist/harness/session/types.js +7 -7
- package/dist/harness/session/types.js.map +1 -1
- package/dist/harness/skills.d.ts +2 -3
- package/dist/harness/skills.d.ts.map +1 -1
- package/dist/harness/skills.js +26 -29
- package/dist/harness/skills.js.map +1 -1
- package/dist/harness/telemetry.d.ts +43 -64
- package/dist/harness/telemetry.d.ts.map +1 -1
- package/dist/harness/telemetry.js +26 -45
- package/dist/harness/telemetry.js.map +1 -1
- package/dist/harness/tools/bash.d.ts +4 -4
- package/dist/harness/tools/bash.d.ts.map +1 -1
- package/dist/harness/tools/bash.js +93 -66
- package/dist/harness/tools/bash.js.map +1 -1
- package/dist/harness/tools/edit.d.ts.map +1 -1
- package/dist/harness/tools/edit.js +13 -17
- package/dist/harness/tools/edit.js.map +1 -1
- package/dist/harness/tools/file-mutation-queue.d.ts +1 -2
- package/dist/harness/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/harness/tools/file-mutation-queue.js +5 -5
- package/dist/harness/tools/file-mutation-queue.js.map +1 -1
- package/dist/harness/tools/path-utils.d.ts +2 -3
- package/dist/harness/tools/path-utils.d.ts.map +1 -1
- package/dist/harness/tools/path-utils.js +5 -5
- package/dist/harness/tools/path-utils.js.map +1 -1
- package/dist/harness/tools/read.d.ts +1 -2
- package/dist/harness/tools/read.d.ts.map +1 -1
- package/dist/harness/tools/read.js +6 -4
- package/dist/harness/tools/read.js.map +1 -1
- package/dist/harness/tools/write.d.ts.map +1 -1
- package/dist/harness/tools/write.js +8 -12
- package/dist/harness/tools/write.js.map +1 -1
- package/dist/harness/types.d.ts +45 -128
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/utils/shell-output.d.ts +5 -19
- package/dist/harness/utils/shell-output.d.ts.map +1 -1
- package/dist/harness/utils/shell-output.js +192 -65
- package/dist/harness/utils/shell-output.js.map +1 -1
- package/dist/harness/utils/truncate.d.ts +0 -1
- package/dist/harness/utils/truncate.d.ts.map +1 -1
- package/dist/harness/utils/truncate.js +1 -1
- package/dist/harness/utils/truncate.js.map +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/search/index.d.ts +16 -24
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +1 -1
- package/dist/search/index.js.map +1 -1
- package/dist/search/scanning.d.ts +29 -0
- package/dist/search/scanning.d.ts.map +1 -0
- package/dist/search/scanning.js +103 -0
- package/dist/search/scanning.js.map +1 -0
- package/dist/types.d.ts +0 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +6 -27
- 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/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 -48
- 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 -121
- package/dist/harness/execution/tools.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 -404
- package/dist/harness/hooks.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 -244
- 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 -302
- 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 -1559
- 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 -50
- 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/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 -269
- package/dist/harness/session/in-memory-storage-state.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 -266
- 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 -454
- package/dist/harness/session/jsonl/legacy-v3.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 -22
- package/dist/harness/session/mutation-line.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 -103
- package/dist/harness/session/testing/gating-storage.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 -19
- 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 -40
- package/dist/harness/session/testing/storage-decorator.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/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/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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../src/harness/telemetry.ts"],"names":[],"mappings":"AAYA,OAAO,EAAgB,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,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Q;oBACd,WAAW,EAAE,6CAA6C;iBAC1D;gBACD,qBAAqB,EAAE;oBACtB,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,4CAA4C;iBACzD;aACD;YACD,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,iCAAiC,EAAE;SACvE;KACD;CAC4C,CAAC;AAE/C,uFAAuF;AACvF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,mBAAmB,EAAE,wBAAwB,CAAU,CAAC;AA2BhG,MAAM,UAAU,gBAAgB,CAK/B,IAAU,EACV,UAAkF,EAClF,QAA0F,EAC1F,OAAgB;IAEhB,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,IAAmB,EAAE,EAAE,CAC3F,QAAQ,CAAC,IAAkC,EAAE,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CACjF,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n} from \"@earendil-works/pi-telemetry\";\nimport { type Context, getTelemetryContext, withTelemetryContext } from \"./context.ts\";\n\nexport type {\n\tAttributeValue,\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tSpanAttributes,\n\tSpanOptions,\n\tSpanStatus,\n\tTelemetryAttributeDefinition,\n\tTelemetryAttributeMetadata,\n\tTelemetryAttributeType,\n\tTelemetryContext,\n\tTelemetryEventAttributeDefinition,\n\tTelemetryEventDefinition,\n\tTelemetryParentDefinition,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n\tTelemetrySpanDefinition,\n\tTelemetryStartAttributeDefinition,\n\tTypedSpanStarter,\n} from \"@earendil-works/pi-telemetry\";\n\nexport const AI_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.ai.request\": {\n\t\t\tdescription: \"One logical request to an AI provider\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.ai.operation\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"stream\", \"fetch_deferred\", \"cancel_deferred\", \"generate_images\"],\n\t\t\t\t\tdescription: \"Logical provider operation\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.provider\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Selected provider id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.model\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested model id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.api\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Provider API id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.streaming\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this operation returns a stream\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.deferred\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Whether the operation requests or participates in deferred execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.ai.response.model\": { type: \"string\", description: \"Concrete response model\" },\n\t\t\t\t\"pi.ai.response.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Provider response id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.response.stop_reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"stop\", \"length\", \"tool_use\", \"error\", \"aborted\", \"deferred\"],\n\t\t\t\t\tdescription: \"Normalized terminal response reason\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.http.status_code\": { type: \"number\", description: \"Final HTTP status\" },\n\t\t\t\t\"pi.ai.usage.input_tokens\": { type: \"number\", description: \"Reported input tokens\" },\n\t\t\t\t\"pi.ai.usage.output_tokens\": { type: \"number\", description: \"Reported output tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_read_tokens\": { type: \"number\", description: \"Reported cache-read tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_write_tokens\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Reported cache-write tokens\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.usage.reasoning_tokens\": { type: \"number\", description: \"Reported reasoning tokens\" },\n\t\t\t\t\"pi.ai.usage.total_tokens\": { type: \"number\", description: \"Reported total tokens\" },\n\t\t\t\t\"pi.ai.usage.cost\": { type: \"number\", description: \"Reported total cost\" },\n\t\t\t\t\"pi.ai.stream.chunk_count\": { type: \"number\", description: \"Streamed update chunk count\" },\n\t\t\t\t\"pi.ai.stream.time_to_first_chunk_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Elapsed milliseconds to first update chunk\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.error.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tdescription: \"Provider or transport error class\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The operation throws or returns an error result\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\nexport type AiSpanName = TelemetrySchemaSpanName<typeof AI_TELEMETRY_SCHEMA>;\nexport type AiSpanStartAttributes<Name extends AiSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanEndAttributes<Name extends AiSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanAttributes<Name extends AiSpanName> = AiSpanStartAttributes<Name> & AiSpanEndAttributes<Name>;\nexport type AiSpanEventName<Name extends AiSpanName> = TelemetrySchemaSpanEventName<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpanEventAttributes<\n\tName extends AiSpanName,\n\tEventName extends AiSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof AI_TELEMETRY_SCHEMA, Name, EventName>;\nexport type AiTelemetrySpan<Name extends AiSpanName> = SchemaTelemetrySpan<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpan = TelemetrySchemaSpanUnion<typeof AI_TELEMETRY_SCHEMA>;\n\nexport function startAiSpan<Name extends AiSpanName, const Attributes extends AiSpanStartAttributes<Name>, Result>(\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<AiSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: AiTelemetrySpan<Name>, context: Context) => Result | Promise<Result>,\n\tcontext: Context,\n): Promise<Result> {\n\treturn getTelemetryContext(context).startSpan({ name, attributes }, (span) =>\n\t\tcallback(span as AiTelemetrySpan<Name>, withTelemetryContext(span, context)),\n\t);\n}\n\nconst HOOK_NAMES = [\n\t\"before_run\",\n\t\"before_drive\",\n\t\"before_run_end\",\n\t\"transform_context\",\n\t\"before_request\",\n\t\"before_payload\",\n\t\"after_response\",\n\t\"before_tool\",\n\t\"after_tool\",\n\t\"before_compaction\",\n\t\"before_navigation\",\n] as const;\n\nconst EVENT_TYPES = [\n\t\"run_start\",\n\t\"run_resume\",\n\t\"run_suspend\",\n\t\"operation_abort\",\n\t\"run_end\",\n\t\"fault\",\n\t\"handler_error\",\n\t\"turn_start\",\n\t\"turn_end\",\n\t\"retry_scheduled\",\n\t\"retry_start\",\n\t\"retry_end\",\n\t\"message_start\",\n\t\"message_update\",\n\t\"message_end\",\n\t\"tool_start\",\n\t\"tool_update\",\n\t\"tool_end\",\n\t\"entry_added\",\n\t\"queue_update\",\n\t\"value_update\",\n\t\"config_update\",\n\t\"compaction_start\",\n\t\"compaction_end\",\n\t\"navigation_start\",\n\t\"navigation_end\",\n\t\"lane_created\",\n\t\"usage\",\n] as const;\n\nconst operationStartAttributes = {\n\t\"pi.session.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Session id\",\n\t},\n\t\"pi.lane.name\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Lane name\",\n\t},\n\t\"pi.operation.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Durable operation id\",\n\t},\n\t\"pi.operation.recovery\": {\n\t\ttype: \"boolean\",\n\t\trequired: true,\n\t\tdescription: \"Whether this invocation resumes durable work\",\n\t},\n} as const;\n\nconst operationErrorAttributes = {\n\t\"pi.error.code\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Stable operation error code\",\n\t},\n\t\"pi.error.type\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Low-cardinality operation error class\",\n\t},\n} as const;\n\nexport const HARNESS_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.harness.run\": {\n\t\t\tdescription: \"One admitted in-process run invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"run\"],\n\t\t\t\t\tdescription: \"Run operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"aborted\", \"failed\", \"suspended\"],\n\t\t\t\t\tdescription: \"Run invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The run fails or throws\" },\n\t\t},\n\t\t\"pi.harness.compaction\": {\n\t\t\tdescription: \"One admitted in-process manual compaction invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"compaction\"],\n\t\t\t\t\tdescription: \"Compaction operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Compaction invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The compaction fails or throws\" },\n\t\t},\n\t\t\"pi.harness.navigation\": {\n\t\t\tdescription: \"One admitted in-process navigation invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"navigation\"],\n\t\t\t\t\tdescription: \"Navigation operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Navigation invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The navigation fails or throws\" },\n\t\t},\n\t\t\"pi.harness.checkpoint\": {\n\t\t\tdescription: \"One run checkpoint\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.checkpoint.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"normal\", \"abort_reconcile\"],\n\t\t\t\t\tdescription: \"Checkpoint purpose\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Checkpoint work throws\" },\n\t\t},\n\t\t\"pi.harness.turn\": {\n\t\t\tdescription: \"One assistant response and its tool batch\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local turn id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Turn work throws\" },\n\t\t},\n\t\t\"pi.harness.step\": {\n\t\t\tdescription: \"One durable retry attempt\",\n\t\t\tparents: {\n\t\t\t\tkind: \"spans\",\n\t\t\t\tspans: [\"pi.harness.turn\", \"pi.harness.checkpoint\", \"pi.harness.compaction\", \"pi.harness.navigation\"],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"assistant\", \"compaction\", \"branch_summary\"],\n\t\t\t\t\tdescription: \"Retryable step kind\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.attempt\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"One-based durable attempt number\",\n\t\t\t\t},\n\t\t\t\t\"pi.compaction.reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tvalues: [\"manual\", \"threshold\", \"overflow\"],\n\t\t\t\t\tdescription: \"Compaction trigger\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.step.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"succeeded\", \"retry\", \"failed\", \"aborted\", \"deferred\", \"overflow\"],\n\t\t\t\t\tdescription: \"Attempt outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The attempt retries, fails, or throws\" },\n\t\t},\n\t\t\"pi.harness.tool\": {\n\t\t\tdescription: \"One raw phase-2 tool execution\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.turn\", \"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local live turn id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Tool name\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.call_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Tool call id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.replay\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"never\", \"safe\"],\n\t\t\t\t\tdescription: \"Declared replay policy\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.recovery\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this is recovery execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.tool.is_error\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdescription: \"Whether raw phase-2 execution returned an error\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Raw phase-2 execution returns an error\" },\n\t\t},\n\t\t\"pi.harness.hook\": {\n\t\t\tdescription: \"One registered hook handler invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when accepted\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: HOOK_NAMES,\n\t\t\t\t\tdescription: \"Hook name\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.registration_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Optional hook registration metadata\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.hook.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"skipped\", \"blocked\", \"failed\"],\n\t\t\t\t\tdescription: \"Handler outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The handler throws\" },\n\t\t},\n\t\t\"pi.harness.sleep\": {\n\t\t\tdescription: \"One retry delay\",\n\t\t\tparents: {\n\t\t\t\tkind: \"spans\",\n\t\t\t\tspans: [\n\t\t\t\t\t\"pi.harness.run\",\n\t\t\t\t\t\"pi.harness.compaction\",\n\t\t\t\t\t\"pi.harness.navigation\",\n\t\t\t\t\t\"pi.harness.turn\",\n\t\t\t\t\t\"pi.harness.checkpoint\",\n\t\t\t\t],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.sleep.delay_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested delay in milliseconds\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.sleep.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"elapsed\", \"aborted\"],\n\t\t\t\t\tdescription: \"Delay outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Sleep work throws\" },\n\t\t},\n\t\t\"pi.harness.event_handler\": {\n\t\t\tdescription: \"One passive event listener invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.event.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tvalues: EVENT_TYPES,\n\t\t\t\t\tdescription: \"Delivered harness event type\",\n\t\t\t\t},\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name for lane-scoped events\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The listener throws\" },\n\t\t},\n\t\t\"pi.session.write\": {\n\t\t\tdescription: \"One committed session transaction\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.session.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Session id\",\n\t\t\t\t},\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name when supplied by the caller\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when supplied by the caller\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.item_count\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Number of writes in the transaction\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.item_kinds\": {\n\t\t\t\t\ttype: \"string[]\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\telementValues: [\"entry\", \"usage\", \"value\", \"list\"],\n\t\t\t\t\tdescription: \"Distinct write kinds in the transaction\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.session.first_seq\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"First committed sequence in the transaction\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.last_seq\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Last committed sequence in the transaction\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Storage rejects the transaction\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\n/** Combined typed span vocabulary for agent-owned AI-request and harness telemetry. */\nexport const AGENT_TELEMETRY_SCHEMAS = [AI_TELEMETRY_SCHEMA, HARNESS_TELEMETRY_SCHEMA] as const;\n\nexport type HarnessSpanName = TelemetrySchemaSpanName<typeof HARNESS_TELEMETRY_SCHEMA>;\nexport type HarnessSpanStartAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEndAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanAttributes<Name extends HarnessSpanName> = HarnessSpanStartAttributes<Name> &\n\tHarnessSpanEndAttributes<Name>;\nexport type HarnessSpanEventName<Name extends HarnessSpanName> = TelemetrySchemaSpanEventName<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEventAttributes<\n\tName extends HarnessSpanName,\n\tEventName extends HarnessSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof HARNESS_TELEMETRY_SCHEMA, Name, EventName>;\nexport type HarnessTelemetrySpan<Name extends HarnessSpanName> = SchemaTelemetrySpan<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpan = TelemetrySchemaSpanUnion<typeof HARNESS_TELEMETRY_SCHEMA>;\n\nexport function startHarnessSpan<\n\tName extends HarnessSpanName,\n\tconst Attributes extends HarnessSpanStartAttributes<Name>,\n\tResult,\n>(\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<HarnessSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: HarnessTelemetrySpan<Name>, context: Context) => Result | Promise<Result>,\n\tcontext: Context,\n): Promise<Result> {\n\treturn getTelemetryContext(context).startSpan({ name, attributes }, (span: TelemetrySpan) =>\n\t\tcallback(span as HarnessTelemetrySpan<Name>, withTelemetryContext(span, context)),\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../src/harness/telemetry.ts"],"names":[],"mappings":"AAyCA,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,OAAO,EAAE,CAAC;IACV,KAAK,EAAE;QACN,eAAe,EAAE;YAChB,WAAW,EAAE,uCAAuC;YACpD,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;YACxB,eAAe,EAAE;gBAChB,iBAAiB,EAAE;oBAClB,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,CAAC,QAAQ,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,CAAC;oBAC1E,WAAW,EAAE,4BAA4B;iBACzC;gBACD,gBAAgB,EAAE;oBACjB,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,sBAAsB;iBACnC;gBACD,aAAa,EAAE;oBACd,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,oBAAoB;iBACjC;gBACD,WAAW,EAAE;oBACZ,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,iBAAiB;iBAC9B;gBACD,iBAAiB,EAAE;oBAClB,IAAI,EAAE,SAAS;oBACf,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,yCAAyC;iBACtD;gBACD,gBAAgB,EAAE;oBACjB,IAAI,EAAE,SAAS;oBACf,QAAQ,EAAE,KAAK;oBACf,WAAW,EAAE,sEAAsE;iBACnF;aACD;YACD,aAAa,EAAE;gBACd,sBAAsB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,yBAAyB,EAAE;gBAClF,mBAAmB,EAAE;oBACpB,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,MAAM;oBACnB,WAA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I,EAAE,SAAS,EAAE,8BAA8B,EAAE;SACpE;KACD;CAC4C,CAAC;AAE/C,uFAAuF;AACvF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,mBAAmB,EAAE,wBAAwB,CAAU,CAAC;AA2BhG,MAAM,UAAU,gBAAgB,CAK/B,gBAAkC,EAClC,IAAU,EACV,UAAkF,EAClF,QAAwE;IAExE,OAAO,gBAAgB,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,IAAmB,EAAE,EAAE,CAC/E,QAAQ,CAAC,IAAkC,CAAC,CAC5C,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tTelemetryContext,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n} from \"@earendil-works/pi-telemetry\";\n\nexport type {\n\tAttributeValue,\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tSpanAttributes,\n\tSpanOptions,\n\tSpanStatus,\n\tTelemetryAttributeDefinition,\n\tTelemetryAttributeMetadata,\n\tTelemetryAttributeType,\n\tTelemetryContext,\n\tTelemetryEventAttributeDefinition,\n\tTelemetryEventDefinition,\n\tTelemetryParentDefinition,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n\tTelemetrySpanDefinition,\n\tTelemetryStartAttributeDefinition,\n\tTypedSpanStarter,\n} from \"@earendil-works/pi-telemetry\";\n\nexport const AI_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.ai.request\": {\n\t\t\tdescription: \"One logical request to an AI provider\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.ai.operation\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"stream\", \"fetch_deferred\", \"cancel_deferred\", \"generate_images\"],\n\t\t\t\t\tdescription: \"Logical provider operation\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.provider\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Selected provider id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.model\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested model id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.api\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Provider API id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.streaming\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this operation returns a stream\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.deferred\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Whether the operation requests or participates in deferred execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.ai.response.model\": { type: \"string\", description: \"Concrete response model\" },\n\t\t\t\t\"pi.ai.response.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Provider response id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.response.stop_reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"stop\", \"length\", \"tool_use\", \"error\", \"aborted\", \"deferred\"],\n\t\t\t\t\tdescription: \"Normalized terminal response reason\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.http.status_code\": { type: \"number\", description: \"Final HTTP status\" },\n\t\t\t\t\"pi.ai.usage.input_tokens\": { type: \"number\", description: \"Reported input tokens\" },\n\t\t\t\t\"pi.ai.usage.output_tokens\": { type: \"number\", description: \"Reported output tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_read_tokens\": { type: \"number\", description: \"Reported cache-read tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_write_tokens\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Reported cache-write tokens\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.usage.reasoning_tokens\": { type: \"number\", description: \"Reported reasoning tokens\" },\n\t\t\t\t\"pi.ai.usage.total_tokens\": { type: \"number\", description: \"Reported total tokens\" },\n\t\t\t\t\"pi.ai.usage.cost\": { type: \"number\", description: \"Reported total cost\" },\n\t\t\t\t\"pi.ai.stream.chunk_count\": { type: \"number\", description: \"Streamed update chunk count\" },\n\t\t\t\t\"pi.ai.stream.time_to_first_chunk_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Elapsed milliseconds to first update chunk\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.error.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tdescription: \"Provider or transport error class\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The operation throws or returns an error result\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\nexport type AiSpanName = TelemetrySchemaSpanName<typeof AI_TELEMETRY_SCHEMA>;\nexport type AiSpanStartAttributes<Name extends AiSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanEndAttributes<Name extends AiSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanAttributes<Name extends AiSpanName> = AiSpanStartAttributes<Name> & AiSpanEndAttributes<Name>;\nexport type AiSpanEventName<Name extends AiSpanName> = TelemetrySchemaSpanEventName<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpanEventAttributes<\n\tName extends AiSpanName,\n\tEventName extends AiSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof AI_TELEMETRY_SCHEMA, Name, EventName>;\nexport type AiTelemetrySpan<Name extends AiSpanName> = SchemaTelemetrySpan<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpan = TelemetrySchemaSpanUnion<typeof AI_TELEMETRY_SCHEMA>;\n\nexport function startAiSpan<Name extends AiSpanName, const Attributes extends AiSpanStartAttributes<Name>, Result>(\n\ttelemetryContext: TelemetryContext,\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<AiSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: AiTelemetrySpan<Name>) => Result | Promise<Result>,\n): Promise<Result> {\n\treturn telemetryContext.startSpan({ name, attributes }, (span) => callback(span as AiTelemetrySpan<Name>));\n}\n\nconst HOOK_NAMES = [\n\t\"before_run\",\n\t\"before_resume\",\n\t\"before_run_end\",\n\t\"transform_context\",\n\t\"before_request\",\n\t\"before_payload\",\n\t\"after_response\",\n\t\"before_tool\",\n\t\"after_tool\",\n\t\"before_compaction\",\n\t\"before_navigation\",\n] as const;\n\nconst EVENT_TYPES = [\n\t\"run_start\",\n\t\"run_resume\",\n\t\"run_suspend\",\n\t\"run_abort\",\n\t\"run_end\",\n\t\"fault\",\n\t\"handler_error\",\n\t\"turn_start\",\n\t\"turn_end\",\n\t\"retry_scheduled\",\n\t\"retry_start\",\n\t\"retry_end\",\n\t\"message_start\",\n\t\"message_update\",\n\t\"message_end\",\n\t\"tool_start\",\n\t\"tool_update\",\n\t\"tool_end\",\n\t\"entry_added\",\n\t\"write_pending\",\n\t\"queue_update\",\n\t\"fact_update\",\n\t\"config_update\",\n\t\"compaction_start\",\n\t\"compaction_end\",\n\t\"navigation_start\",\n\t\"navigation_end\",\n\t\"lane_created\",\n\t\"usage\",\n] as const;\n\nconst operationStartAttributes = {\n\t\"pi.session.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Session id\",\n\t},\n\t\"pi.lane.name\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Lane name\",\n\t},\n\t\"pi.operation.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Durable operation id\",\n\t},\n\t\"pi.operation.recovery\": {\n\t\ttype: \"boolean\",\n\t\trequired: true,\n\t\tdescription: \"Whether this invocation resumes durable work\",\n\t},\n} as const;\n\nconst operationErrorAttributes = {\n\t\"pi.error.code\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Stable operation error code\",\n\t},\n\t\"pi.error.type\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Low-cardinality operation error class\",\n\t},\n} as const;\n\nexport const HARNESS_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.harness.run\": {\n\t\t\tdescription: \"One admitted in-process run invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"run\"],\n\t\t\t\t\tdescription: \"Run operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"aborted\", \"failed\", \"suspended\"],\n\t\t\t\t\tdescription: \"Run invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The run fails or throws\" },\n\t\t},\n\t\t\"pi.harness.compaction\": {\n\t\t\tdescription: \"One admitted in-process manual compaction invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"compaction\"],\n\t\t\t\t\tdescription: \"Compaction operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Compaction invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The compaction fails or throws\" },\n\t\t},\n\t\t\"pi.harness.navigation\": {\n\t\t\tdescription: \"One admitted in-process navigation invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"navigation\"],\n\t\t\t\t\tdescription: \"Navigation operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Navigation invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The navigation fails or throws\" },\n\t\t},\n\t\t\"pi.harness.checkpoint\": {\n\t\t\tdescription: \"One run checkpoint\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.checkpoint.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"normal\", \"failure_drain\", \"abort_reconcile\"],\n\t\t\t\t\tdescription: \"Checkpoint purpose\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Checkpoint work throws\" },\n\t\t},\n\t\t\"pi.harness.turn\": {\n\t\t\tdescription: \"One assistant response and its tool batch\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local turn id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Turn work throws\" },\n\t\t},\n\t\t\"pi.harness.step\": {\n\t\t\tdescription: \"One durable retry attempt\",\n\t\t\tparents: {\n\t\t\t\tkind: \"spans\",\n\t\t\t\tspans: [\"pi.harness.turn\", \"pi.harness.checkpoint\", \"pi.harness.compaction\", \"pi.harness.navigation\"],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"assistant\", \"compaction\", \"branch_summary\"],\n\t\t\t\t\tdescription: \"Retryable step kind\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.attempt\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"One-based durable attempt number\",\n\t\t\t\t},\n\t\t\t\t\"pi.compaction.reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tvalues: [\"manual\", \"threshold\", \"overflow\"],\n\t\t\t\t\tdescription: \"Compaction trigger\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.step.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"succeeded\", \"retry\", \"failed\", \"aborted\", \"deferred\", \"overflow\"],\n\t\t\t\t\tdescription: \"Attempt outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The attempt retries, fails, or throws\" },\n\t\t},\n\t\t\"pi.harness.tool\": {\n\t\t\tdescription: \"One raw phase-2 tool execution\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.turn\", \"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local live turn id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Tool name\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.call_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Tool call id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.replay\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"never\", \"safe\"],\n\t\t\t\t\tdescription: \"Declared replay policy\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.recovery\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this is recovery execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.tool.is_error\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdescription: \"Whether raw phase-2 execution returned an error\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Raw phase-2 execution returns an error\" },\n\t\t},\n\t\t\"pi.harness.hook\": {\n\t\t\tdescription: \"One registered hook handler invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when accepted\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: HOOK_NAMES,\n\t\t\t\t\tdescription: \"Hook name\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.registration_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Stable hook registration id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.hook.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"skipped\", \"blocked\", \"failed\"],\n\t\t\t\t\tdescription: \"Handler outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The handler throws\" },\n\t\t},\n\t\t\"pi.harness.sleep\": {\n\t\t\tdescription: \"One retry delay\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.step\", \"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.sleep.delay_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested delay in milliseconds\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.sleep.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"elapsed\", \"aborted\"],\n\t\t\t\t\tdescription: \"Delay outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Sleep work throws\" },\n\t\t},\n\t\t\"pi.harness.event_handler\": {\n\t\t\tdescription: \"One passive event listener invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.event.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tvalues: EVENT_TYPES,\n\t\t\t\t\tdescription: \"Delivered harness event type\",\n\t\t\t\t},\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name for lane-scoped events\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The listener throws\" },\n\t\t},\n\t\t\"pi.session.write\": {\n\t\t\tdescription: \"One committed session mutation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when accepted\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.mutation\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"entry\", \"record\", \"lane\", \"fact\"],\n\t\t\t\t\tdescription: \"Session mutation kind\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.item_type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Entry, record, lane, or fact subtype\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.session.seq\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Committed session sequence when exposed\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Storage rejects the mutation\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\n/** Combined typed span vocabulary for agent-owned AI-request and harness telemetry. */\nexport const AGENT_TELEMETRY_SCHEMAS = [AI_TELEMETRY_SCHEMA, HARNESS_TELEMETRY_SCHEMA] as const;\n\nexport type HarnessSpanName = TelemetrySchemaSpanName<typeof HARNESS_TELEMETRY_SCHEMA>;\nexport type HarnessSpanStartAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEndAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanAttributes<Name extends HarnessSpanName> = HarnessSpanStartAttributes<Name> &\n\tHarnessSpanEndAttributes<Name>;\nexport type HarnessSpanEventName<Name extends HarnessSpanName> = TelemetrySchemaSpanEventName<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEventAttributes<\n\tName extends HarnessSpanName,\n\tEventName extends HarnessSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof HARNESS_TELEMETRY_SCHEMA, Name, EventName>;\nexport type HarnessTelemetrySpan<Name extends HarnessSpanName> = SchemaTelemetrySpan<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpan = TelemetrySchemaSpanUnion<typeof HARNESS_TELEMETRY_SCHEMA>;\n\nexport function startHarnessSpan<\n\tName extends HarnessSpanName,\n\tconst Attributes extends HarnessSpanStartAttributes<Name>,\n\tResult,\n>(\n\ttelemetryContext: TelemetryContext,\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<HarnessSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: HarnessTelemetrySpan<Name>) => Result | Promise<Result>,\n): Promise<Result> {\n\treturn telemetryContext.startSpan({ name, attributes }, (span: TelemetrySpan) =>\n\t\tcallback(span as HarnessTelemetrySpan<Name>),\n\t);\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Static, Type } from "typebox";
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
2
|
+
import type { AgentHarnessTool } from "../types.ts";
|
|
3
|
+
import { type TruncationResult } from "../utils/truncate.ts";
|
|
4
4
|
import type { ExecutionToolContext } from "./tool-context.ts";
|
|
5
5
|
declare const bashSchema: Type.TObject<{
|
|
6
6
|
command: Type.TString;
|
|
@@ -8,7 +8,7 @@ declare const bashSchema: Type.TObject<{
|
|
|
8
8
|
}>;
|
|
9
9
|
export type BashToolInput = Static<typeof bashSchema>;
|
|
10
10
|
export interface BashToolDetails {
|
|
11
|
-
truncation?:
|
|
11
|
+
truncation?: TruncationResult;
|
|
12
12
|
fullOutputPath?: string;
|
|
13
13
|
}
|
|
14
14
|
export interface BashExecution {
|
|
@@ -17,7 +17,7 @@ export interface BashExecution {
|
|
|
17
17
|
env: Record<string, string>;
|
|
18
18
|
inheritEnv: boolean;
|
|
19
19
|
}
|
|
20
|
-
export type BashPrepare<TContext extends ExecutionToolContext = ExecutionToolContext> = (execution: BashExecution,
|
|
20
|
+
export type BashPrepare<TContext extends ExecutionToolContext = ExecutionToolContext> = (execution: BashExecution, context: TContext, signal?: AbortSignal) => void | Promise<void>;
|
|
21
21
|
export interface BashToolOptions<TContext extends ExecutionToolContext = ExecutionToolContext> {
|
|
22
22
|
commandPrefix?: string;
|
|
23
23
|
prepare?: BashPrepare<TContext>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD,OAAO,EAAoD,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC/G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAK9D,QAAA,MAAM,UAAU;;;EAGd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB,IAAI,CACvF,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,QAAQ,EACjB,MAAM,CAAC,EAAE,WAAW,KAChB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,WAAW,eAAe,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB;IAC5F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;CAChC;AAYD,wBAAgB,cAAc,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB,EAC1F,OAAO,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,GACjC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CA4G5E"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
|
-
import {
|
|
2
|
+
import { getOrThrow } from "../types.js";
|
|
3
|
+
import { executeShellWithCapture } from "../utils/shell-output.js";
|
|
3
4
|
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize } from "../utils/truncate.js";
|
|
4
5
|
const MAX_TIMEOUT_SECONDS = 2_147_483_647 / 1000;
|
|
5
|
-
const
|
|
6
|
+
const BASH_UPDATE_THROTTLE_MS = 100;
|
|
6
7
|
const bashSchema = Type.Object({
|
|
7
8
|
command: Type.String({ description: "Bash command to execute" }),
|
|
8
9
|
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })),
|
|
@@ -21,84 +22,110 @@ export function createBashTool(options) {
|
|
|
21
22
|
return {
|
|
22
23
|
name: "bash",
|
|
23
24
|
label: "bash",
|
|
24
|
-
description: `Execute a bash command in the current working directory. Returns
|
|
25
|
+
description: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,
|
|
25
26
|
parameters: bashSchema,
|
|
26
|
-
async execute(_toolCallId, { command, timeout },
|
|
27
|
+
async execute(_toolCallId, { command, timeout }, signal, onUpdate, context) {
|
|
27
28
|
validateTimeout(timeout);
|
|
28
|
-
const { env } =
|
|
29
|
+
const { env } = context;
|
|
29
30
|
const execution = {
|
|
30
31
|
command: options?.commandPrefix ? `${options.commandPrefix}\n${command}` : command,
|
|
31
32
|
cwd: env.cwd,
|
|
32
33
|
env: {},
|
|
33
34
|
inheritEnv: true,
|
|
34
35
|
};
|
|
35
|
-
await options?.prepare?.(execution,
|
|
36
|
-
let
|
|
37
|
-
let
|
|
38
|
-
let
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
36
|
+
await options?.prepare?.(execution, context, signal);
|
|
37
|
+
let getLatestProgress;
|
|
38
|
+
let updateTimer;
|
|
39
|
+
let updateDirty = false;
|
|
40
|
+
let lastUpdateAt = 0;
|
|
41
|
+
const emitOutputUpdate = () => {
|
|
42
|
+
if (!onUpdate || !updateDirty || !getLatestProgress)
|
|
43
|
+
return;
|
|
44
|
+
updateDirty = false;
|
|
45
|
+
lastUpdateAt = Date.now();
|
|
46
|
+
const progress = getLatestProgress();
|
|
47
|
+
onUpdate({
|
|
48
|
+
content: [{ type: "text", text: progress.output }],
|
|
49
|
+
details: {
|
|
50
|
+
truncation: progress.truncation.truncated ? progress.truncation : undefined,
|
|
51
|
+
fullOutputPath: progress.fullOutputPath,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const clearUpdateTimer = () => {
|
|
56
|
+
if (!updateTimer)
|
|
57
|
+
return;
|
|
58
|
+
clearTimeout(updateTimer);
|
|
59
|
+
updateTimer = undefined;
|
|
60
|
+
};
|
|
61
|
+
const scheduleOutputUpdate = () => {
|
|
62
|
+
if (!onUpdate)
|
|
63
|
+
return;
|
|
64
|
+
updateDirty = true;
|
|
65
|
+
const delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);
|
|
66
|
+
if (delay <= 0) {
|
|
67
|
+
clearUpdateTimer();
|
|
68
|
+
emitOutputUpdate();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
updateTimer ??= setTimeout(() => {
|
|
72
|
+
updateTimer = undefined;
|
|
73
|
+
emitOutputUpdate();
|
|
74
|
+
}, delay);
|
|
75
|
+
};
|
|
76
|
+
onUpdate?.({ content: [], details: undefined });
|
|
77
|
+
try {
|
|
78
|
+
const capture = getOrThrow(await executeShellWithCapture(env, execution.command, {
|
|
79
|
+
cwd: execution.cwd,
|
|
80
|
+
env: execution.env,
|
|
81
|
+
inheritEnv: execution.inheritEnv,
|
|
82
|
+
timeout,
|
|
83
|
+
abortSignal: signal,
|
|
84
|
+
returnExecutionErrors: true,
|
|
85
|
+
onChunk: (_chunk, getProgress) => {
|
|
86
|
+
getLatestProgress = getProgress;
|
|
87
|
+
scheduleOutputUpdate();
|
|
88
|
+
},
|
|
89
|
+
}));
|
|
90
|
+
clearUpdateTimer();
|
|
91
|
+
getLatestProgress = () => capture;
|
|
92
|
+
updateDirty = true;
|
|
93
|
+
emitOutputUpdate();
|
|
94
|
+
let outputText = capture.output;
|
|
95
|
+
let details;
|
|
96
|
+
if (capture.truncation.truncated) {
|
|
97
|
+
details = { truncation: capture.truncation, fullOutputPath: capture.fullOutputPath };
|
|
98
|
+
const startLine = capture.truncation.totalLines - capture.truncation.outputLines + 1;
|
|
99
|
+
const endLine = capture.truncation.totalLines;
|
|
100
|
+
if (capture.truncation.lastLinePartial) {
|
|
101
|
+
const lastLineSize = formatSize(capture.lastLineBytes);
|
|
102
|
+
outputText += `\n\n[Showing last ${formatSize(capture.truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${capture.fullOutputPath}]`;
|
|
103
|
+
}
|
|
104
|
+
else if (capture.truncation.truncatedBy === "lines") {
|
|
105
|
+
outputText += `\n\n[Showing lines ${startLine}-${endLine} of ${capture.truncation.totalLines}. Full output: ${capture.fullOutputPath}]`;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
outputText += `\n\n[Showing lines ${startLine}-${endLine} of ${capture.truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${capture.fullOutputPath}]`;
|
|
68
109
|
}
|
|
69
|
-
},
|
|
70
|
-
}, context);
|
|
71
|
-
acceptingUpdates = false;
|
|
72
|
-
let outputText = view?.text ?? "";
|
|
73
|
-
const capture = result.ok ? { text: outputText, ...result.value } : view;
|
|
74
|
-
let details;
|
|
75
|
-
if (capture?.truncation.truncated) {
|
|
76
|
-
details = { truncation: capture.truncation, fullOutputPath: capture.spillPath };
|
|
77
|
-
const startLine = capture.truncation.totalLines - capture.truncation.outputLines + 1;
|
|
78
|
-
const endLine = capture.truncation.totalLines;
|
|
79
|
-
if (capture.truncation.lastLinePartial) {
|
|
80
|
-
const lastLineSize = formatSize(capture.lastLineBytes ?? capture.truncation.outputBytes);
|
|
81
|
-
outputText += `\n\n[Showing last ${formatSize(capture.truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${capture.spillPath}]`;
|
|
82
110
|
}
|
|
83
|
-
|
|
84
|
-
|
|
111
|
+
const appendStatus = (status) => `${outputText ? `${outputText}\n\n` : ""}${status}`;
|
|
112
|
+
if (capture.cancelled)
|
|
113
|
+
throw new Error(appendStatus("Command aborted"));
|
|
114
|
+
if (capture.executionError?.code === "timeout") {
|
|
115
|
+
throw new Error(appendStatus(`Command timed out after ${timeout} seconds`), {
|
|
116
|
+
cause: capture.executionError,
|
|
117
|
+
});
|
|
85
118
|
}
|
|
86
|
-
|
|
87
|
-
|
|
119
|
+
if (capture.executionError)
|
|
120
|
+
throw capture.executionError;
|
|
121
|
+
if (capture.exitCode !== 0 && capture.exitCode !== undefined) {
|
|
122
|
+
throw new Error(appendStatus(`Command exited with code ${capture.exitCode}`));
|
|
88
123
|
}
|
|
124
|
+
return { content: [{ type: "text", text: outputText || "(no output)" }], details };
|
|
89
125
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
? `Command timed out after ${timeout} seconds`
|
|
93
|
-
: result.error.code === "aborted"
|
|
94
|
-
? "Command aborted"
|
|
95
|
-
: result.error.message;
|
|
96
|
-
throw new Error(outputText ? `${outputText}\n\n${status}` : status, { cause: result.error });
|
|
97
|
-
}
|
|
98
|
-
if (result.value.exitCode !== 0) {
|
|
99
|
-
throw new Error(`${outputText ? `${outputText}\n\n` : ""}Command exited with code ${result.value.exitCode}`);
|
|
126
|
+
finally {
|
|
127
|
+
clearUpdateTimer();
|
|
100
128
|
}
|
|
101
|
-
return { content: [{ type: "text", text: outputText || "(no output)" }], details };
|
|
102
129
|
},
|
|
103
130
|
};
|
|
104
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/harness/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGxF,MAAM,mBAAmB,GAAG,aAAa,GAAG,IAAI,CAAC;AACjD,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAE1C,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;IAC9B,OAAO,EA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I,aAAa,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;QACpF,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { Context } from \"../context.ts\";\nimport type { AgentHarnessTool, ShellOutputTruncation, ShellOutputView } from \"../types.ts\";\nimport { applyShellOutputUpdate } from \"../utils/output-capture.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize } from \"../utils/truncate.ts\";\nimport type { ExecutionToolContext } from \"./tool-context.ts\";\n\nconst MAX_TIMEOUT_SECONDS = 2_147_483_647 / 1000;\nconst BASH_CHECKPOINT_INTERVAL_MS = 2_000;\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Bash command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: ShellOutputTruncation;\n\tfullOutputPath?: string;\n}\n\nexport interface BashExecution {\n\tcommand: string;\n\tcwd: string;\n\tenv: Record<string, string>;\n\tinheritEnv: boolean;\n}\n\nexport type BashPrepare<TContext extends ExecutionToolContext = ExecutionToolContext> = (\n\texecution: BashExecution,\n\ttoolContext: TContext,\n\tcontext: Context,\n) => void | Promise<void>;\n\nexport interface BashToolOptions<TContext extends ExecutionToolContext = ExecutionToolContext> {\n\tcommandPrefix?: string;\n\tprepare?: BashPrepare<TContext>;\n}\n\nfunction validateTimeout(timeout: number | undefined): void {\n\tif (timeout === undefined) return;\n\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\t}\n\tif (timeout > MAX_TIMEOUT_SECONDS) {\n\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t}\n}\n\nexport function createBashTool<TContext extends ExecutionToolContext = ExecutionToolContext>(\n\toptions?: BashToolOptions<TContext>,\n): AgentHarnessTool<TContext, typeof bashSchema, BashToolDetails | undefined> {\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription: `Execute a bash command in the current working directory. Returns combined stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tparameters: bashSchema,\n\t\tasync execute(_toolCallId, { command, timeout }, onUpdate, toolContext, _invocation, context) {\n\t\t\tvalidateTimeout(timeout);\n\t\t\tconst { env } = toolContext;\n\t\t\tconst execution: BashExecution = {\n\t\t\t\tcommand: options?.commandPrefix ? `${options.commandPrefix}\\n${command}` : command,\n\t\t\t\tcwd: env.cwd,\n\t\t\t\tenv: {},\n\t\t\t\tinheritEnv: true,\n\t\t\t};\n\t\t\tawait options?.prepare?.(execution, toolContext, context);\n\t\t\tlet view: ShellOutputView | undefined;\n\t\t\tlet lastCheckpointAt = Date.now();\n\t\t\tlet lastCheckpoint: string | undefined;\n\t\t\tlet acceptingUpdates = true;\n\n\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\tconst result = await env.exec(\n\t\t\t\texecution.command,\n\t\t\t\t{\n\t\t\t\t\tcwd: execution.cwd,\n\t\t\t\t\tenv: execution.env,\n\t\t\t\t\tinheritEnv: execution.inheritEnv,\n\t\t\t\t\ttimeout,\n\t\t\t\t\tcapture: {\n\t\t\t\t\t\tlimits: { maxBytes: DEFAULT_MAX_BYTES, maxLines: DEFAULT_MAX_LINES, retain: \"tail\" },\n\t\t\t\t\t\tspill: true,\n\t\t\t\t\t},\n\t\t\t\t\tonUpdate: (update) => {\n\t\t\t\t\t\tif (!acceptingUpdates) return;\n\t\t\t\t\t\tview = applyShellOutputUpdate(view, update);\n\t\t\t\t\t\tconst snapshot = {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: view.text }],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\ttruncation: view.truncation.truncated ? view.truncation : undefined,\n\t\t\t\t\t\t\t\tfullOutputPath: view.spillPath,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst now = Date.now();\n\t\t\t\t\t\tconst encoded = JSON.stringify(snapshot);\n\t\t\t\t\t\tconst checkpoint =\n\t\t\t\t\t\t\tnow - lastCheckpointAt >= BASH_CHECKPOINT_INTERVAL_MS && encoded !== lastCheckpoint;\n\t\t\t\t\t\tonUpdate(snapshot, checkpoint ? { checkpoint: true } : undefined);\n\t\t\t\t\t\tif (checkpoint) {\n\t\t\t\t\t\t\tlastCheckpointAt = now;\n\t\t\t\t\t\t\tlastCheckpoint = encoded;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t);\n\t\t\tacceptingUpdates = false;\n\n\t\t\tlet outputText = view?.text ?? \"\";\n\t\t\tconst capture = result.ok ? { text: outputText, ...result.value } : view;\n\t\t\tlet details: BashToolDetails | undefined;\n\t\t\tif (capture?.truncation.truncated) {\n\t\t\t\tdetails = { truncation: capture.truncation, fullOutputPath: capture.spillPath };\n\t\t\t\tconst startLine = capture.truncation.totalLines - capture.truncation.outputLines + 1;\n\t\t\t\tconst endLine = capture.truncation.totalLines;\n\t\t\t\tif (capture.truncation.lastLinePartial) {\n\t\t\t\t\tconst lastLineSize = formatSize(capture.lastLineBytes ?? capture.truncation.outputBytes);\n\t\t\t\t\toutputText += `\\n\\n[Showing last ${formatSize(capture.truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${capture.spillPath}]`;\n\t\t\t\t} else if (capture.truncation.truncatedBy === \"lines\") {\n\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${capture.truncation.totalLines}. Full output: ${capture.spillPath}]`;\n\t\t\t\t} else {\n\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${capture.truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${capture.spillPath}]`;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!result.ok) {\n\t\t\t\tconst status =\n\t\t\t\t\tresult.error.code === \"timeout\"\n\t\t\t\t\t\t? `Command timed out after ${timeout} seconds`\n\t\t\t\t\t\t: result.error.code === \"aborted\"\n\t\t\t\t\t\t\t? \"Command aborted\"\n\t\t\t\t\t\t\t: result.error.message;\n\t\t\t\tthrow new Error(outputText ? `${outputText}\\n\\n${status}` : status, { cause: result.error });\n\t\t\t}\n\t\t\tif (result.value.exitCode !== 0) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`${outputText ? `${outputText}\\n\\n` : \"\"}Command exited with code ${result.value.exitCode}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn { content: [{ type: \"text\", text: outputText || \"(no output)\" }], details };\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/harness/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAA6B,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAyB,MAAM,sBAAsB,CAAC;AAG/G,MAAM,mBAAmB,GAAG,aAAa,GAAG,IAAI,CAAC;AACjD,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;IAC9B,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;IAChE,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,mDAAmD,EAAE,CAAC,CAAC;CACzG,CAAC,CAAC;AA2BH,SAAS,eAAe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E,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,IAAI,aAAa,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;YACpF,CAAC;oBAAS,CAAC;gBACV,gBAAgB,EAAE,CAAC;YACpB,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { AgentHarnessTool } from \"../types.ts\";\nimport { getOrThrow } from \"../types.ts\";\nimport { executeShellWithCapture, type ShellCaptureProgress } from \"../utils/shell-output.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult } from \"../utils/truncate.ts\";\nimport type { ExecutionToolContext } from \"./tool-context.ts\";\n\nconst MAX_TIMEOUT_SECONDS = 2_147_483_647 / 1000;\nconst BASH_UPDATE_THROTTLE_MS = 100;\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Bash command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n}\n\nexport interface BashExecution {\n\tcommand: string;\n\tcwd: string;\n\tenv: Record<string, string>;\n\tinheritEnv: boolean;\n}\n\nexport type BashPrepare<TContext extends ExecutionToolContext = ExecutionToolContext> = (\n\texecution: BashExecution,\n\tcontext: TContext,\n\tsignal?: AbortSignal,\n) => void | Promise<void>;\n\nexport interface BashToolOptions<TContext extends ExecutionToolContext = ExecutionToolContext> {\n\tcommandPrefix?: string;\n\tprepare?: BashPrepare<TContext>;\n}\n\nfunction validateTimeout(timeout: number | undefined): void {\n\tif (timeout === undefined) return;\n\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\t}\n\tif (timeout > MAX_TIMEOUT_SECONDS) {\n\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t}\n}\n\nexport function createBashTool<TContext extends ExecutionToolContext = ExecutionToolContext>(\n\toptions?: BashToolOptions<TContext>,\n): AgentHarnessTool<TContext, typeof bashSchema, BashToolDetails | undefined> {\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tparameters: bashSchema,\n\t\tasync execute(_toolCallId, { command, timeout }, signal, onUpdate, context) {\n\t\t\tvalidateTimeout(timeout);\n\t\t\tconst { env } = context;\n\t\t\tconst execution: BashExecution = {\n\t\t\t\tcommand: options?.commandPrefix ? `${options.commandPrefix}\\n${command}` : command,\n\t\t\t\tcwd: env.cwd,\n\t\t\t\tenv: {},\n\t\t\t\tinheritEnv: true,\n\t\t\t};\n\t\t\tawait options?.prepare?.(execution, context, signal);\n\t\t\tlet getLatestProgress: (() => ShellCaptureProgress) | undefined;\n\t\t\tlet updateTimer: ReturnType<typeof setTimeout> | undefined;\n\t\t\tlet updateDirty = false;\n\t\t\tlet lastUpdateAt = 0;\n\n\t\t\tconst emitOutputUpdate = (): void => {\n\t\t\t\tif (!onUpdate || !updateDirty || !getLatestProgress) return;\n\t\t\t\tupdateDirty = false;\n\t\t\t\tlastUpdateAt = Date.now();\n\t\t\t\tconst progress = getLatestProgress();\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: progress.output }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\ttruncation: progress.truncation.truncated ? progress.truncation : undefined,\n\t\t\t\t\t\tfullOutputPath: progress.fullOutputPath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t};\n\t\t\tconst clearUpdateTimer = (): void => {\n\t\t\t\tif (!updateTimer) return;\n\t\t\t\tclearTimeout(updateTimer);\n\t\t\t\tupdateTimer = undefined;\n\t\t\t};\n\t\t\tconst scheduleOutputUpdate = (): void => {\n\t\t\t\tif (!onUpdate) return;\n\t\t\t\tupdateDirty = true;\n\t\t\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\t\t\tif (delay <= 0) {\n\t\t\t\t\tclearUpdateTimer();\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t}, delay);\n\t\t\t};\n\n\t\t\tonUpdate?.({ content: [], details: undefined });\n\t\t\ttry {\n\t\t\t\tconst capture = getOrThrow(\n\t\t\t\t\tawait executeShellWithCapture(env, execution.command, {\n\t\t\t\t\t\tcwd: execution.cwd,\n\t\t\t\t\t\tenv: execution.env,\n\t\t\t\t\t\tinheritEnv: execution.inheritEnv,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tabortSignal: signal,\n\t\t\t\t\t\treturnExecutionErrors: true,\n\t\t\t\t\t\tonChunk: (_chunk, getProgress) => {\n\t\t\t\t\t\t\tgetLatestProgress = getProgress;\n\t\t\t\t\t\t\tscheduleOutputUpdate();\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tclearUpdateTimer();\n\t\t\t\tgetLatestProgress = () => capture;\n\t\t\t\tupdateDirty = true;\n\t\t\t\temitOutputUpdate();\n\n\t\t\t\tlet outputText = capture.output;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tif (capture.truncation.truncated) {\n\t\t\t\t\tdetails = { truncation: capture.truncation, fullOutputPath: capture.fullOutputPath };\n\t\t\t\t\tconst startLine = capture.truncation.totalLines - capture.truncation.outputLines + 1;\n\t\t\t\t\tconst endLine = capture.truncation.totalLines;\n\t\t\t\t\tif (capture.truncation.lastLinePartial) {\n\t\t\t\t\t\tconst lastLineSize = formatSize(capture.lastLineBytes);\n\t\t\t\t\t\toutputText += `\\n\\n[Showing last ${formatSize(capture.truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${capture.fullOutputPath}]`;\n\t\t\t\t\t} else if (capture.truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${capture.truncation.totalLines}. Full output: ${capture.fullOutputPath}]`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${capture.truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${capture.fullOutputPath}]`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst appendStatus = (status: string): string => `${outputText ? `${outputText}\\n\\n` : \"\"}${status}`;\n\t\t\t\tif (capture.cancelled) throw new Error(appendStatus(\"Command aborted\"));\n\t\t\t\tif (capture.executionError?.code === \"timeout\") {\n\t\t\t\t\tthrow new Error(appendStatus(`Command timed out after ${timeout} seconds`), {\n\t\t\t\t\t\tcause: capture.executionError,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (capture.executionError) throw capture.executionError;\n\t\t\t\tif (capture.exitCode !== 0 && capture.exitCode !== undefined) {\n\t\t\t\t\tthrow new Error(appendStatus(`Command exited with code ${capture.exitCode}`));\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText || \"(no output)\" }], details };\n\t\t\t} finally {\n\t\t\t\tclearUpdateTimer();\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAa,MAAM,aAAa,CAAC;AAc/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAa9D,QAAA,MAAM,UAAU;;;;;;EASf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAUtD,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAqCD,wBAAgB,cAAc,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB,KAAK,gBAAgB,CAC/G,QAAQ,EACR,OAAO,UAAU,EACjB,eAAe,GAAG,SAAS,CAC3B,
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAa,MAAM,aAAa,CAAC;AAc/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAa9D,QAAA,MAAM,UAAU;;;;;;EASf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAUtD,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAqCD,wBAAgB,cAAc,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB,KAAK,gBAAgB,CAC/G,QAAQ,EACR,OAAO,UAAU,EACjB,eAAe,GAAG,SAAS,CAC3B,CAiEA"}
|
|
@@ -64,46 +64,42 @@ export function createEditTool() {
|
|
|
64
64
|
description: "Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.",
|
|
65
65
|
parameters: editSchema,
|
|
66
66
|
prepareArguments: prepareEditArguments,
|
|
67
|
-
async execute(_toolCallId, input, _onUpdate, { env, postMutate }
|
|
67
|
+
async execute(_toolCallId, input, signal, _onUpdate, { env, postMutate }) {
|
|
68
68
|
const { path, edits } = validateEditInput(input);
|
|
69
|
-
const absolutePath = await resolveToolPath(env, path,
|
|
69
|
+
const absolutePath = await resolveToolPath(env, path, signal);
|
|
70
70
|
return withFileMutationQueue(env, absolutePath, async () => {
|
|
71
|
-
if (
|
|
71
|
+
if (signal?.aborted)
|
|
72
72
|
throw new Error("Operation aborted");
|
|
73
|
-
const info = await env.fileInfo(absolutePath,
|
|
73
|
+
const info = await env.fileInfo(absolutePath, signal);
|
|
74
74
|
if (!info.ok)
|
|
75
75
|
throw editAccessError(path, info.error);
|
|
76
76
|
if (info.value.kind !== "file" && info.value.kind !== "symlink") {
|
|
77
77
|
throw new Error(`Could not edit file: ${path}. Path is not a file.`);
|
|
78
78
|
}
|
|
79
|
-
const readResult = await env.readTextFile(absolutePath,
|
|
79
|
+
const readResult = await env.readTextFile(absolutePath, signal);
|
|
80
80
|
if (!readResult.ok)
|
|
81
81
|
throw editAccessError(path, readResult.error);
|
|
82
|
-
if (
|
|
82
|
+
if (signal?.aborted)
|
|
83
83
|
throw new Error("Operation aborted");
|
|
84
84
|
const { bom, text: content } = stripBom(readResult.value);
|
|
85
85
|
const originalEnding = detectLineEnding(content);
|
|
86
86
|
const normalizedContent = normalizeToLF(content);
|
|
87
87
|
const { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);
|
|
88
|
-
if (
|
|
88
|
+
if (signal?.aborted)
|
|
89
89
|
throw new Error("Operation aborted");
|
|
90
90
|
const finalContent = bom + restoreLineEndings(newContent, originalEnding);
|
|
91
|
-
const writeResult = await env.writeFile(absolutePath, finalContent,
|
|
91
|
+
const writeResult = await env.writeFile(absolutePath, finalContent, signal);
|
|
92
92
|
if (!writeResult.ok)
|
|
93
93
|
throw editAccessError(path, writeResult.error);
|
|
94
|
-
if (
|
|
94
|
+
if (signal?.aborted)
|
|
95
95
|
throw new Error("Operation aborted");
|
|
96
|
-
const outcome = await runPostMutate(postMutate, {
|
|
97
|
-
|
|
98
|
-
path: absolutePath,
|
|
99
|
-
signal: context.abortSignal,
|
|
100
|
-
});
|
|
101
|
-
if (context.abortSignal?.aborted)
|
|
96
|
+
const outcome = await runPostMutate(postMutate, { tool: "edit", path: absolutePath, signal });
|
|
97
|
+
if (signal?.aborted)
|
|
102
98
|
throw new Error("Operation aborted");
|
|
103
99
|
let committedContent = newContent;
|
|
104
100
|
let rereadNote;
|
|
105
101
|
if (outcome.fileMayHaveChanged) {
|
|
106
|
-
const postMutateRead = await env.readTextFile(absolutePath,
|
|
102
|
+
const postMutateRead = await env.readTextFile(absolutePath, signal);
|
|
107
103
|
// The edit itself already landed, so an unreadable file is the hook's doing, not a
|
|
108
104
|
// failed edit. Report it as a note rather than an error that misattributes the failure.
|
|
109
105
|
if (postMutateRead.ok)
|
|
@@ -121,7 +117,7 @@ export function createEditTool() {
|
|
|
121
117
|
firstChangedLine: diffResult.firstChangedLine,
|
|
122
118
|
},
|
|
123
119
|
};
|
|
124
|
-
}
|
|
120
|
+
});
|
|
125
121
|
},
|
|
126
122
|
};
|
|
127
123
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/harness/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EACN,6BAA6B,EAC7B,gBAAgB,EAEhB,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,EAClB,QAAQ,GACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;A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EAAE,OAAO,CAAC,WAAW;iBAC3B,CAAC,CAAC;gBACH,IAAI,OAAO,CAAC,WAAW,EAAE,OAAO;oBAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;gBAEvE,IAAI,gBAAgB,GAAG,UAAU,CAAC;gBAClC,IAAI,UAA8B,CAAC;gBACnC,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;oBAChC,MAAM,cAAc,GAAG,MAAM,GAAG,CAAC,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;oBACrE,mFAAmF;oBACnF,wFAAwF;oBACxF,IAAI,cAAc,CAAC,EAAE;wBAAE,gBAAgB,GAAG,aAAa,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;;wBAE5F,UAAU,GAAG,wCAAwC,cAAc,CAAC,KAAK,CAAC,IAAI,yDAAyD,CAAC;gBAC1I,CAAC;gBAED,MAAM,UAAU,GAAG,kBAAkB,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;gBACrE,MAAM,IAAI,GAAG,oBAAoB,CAChC,yBAAyB,KAAK,CAAC,MAAM,gBAAgB,IAAI,GAAG,EAC5D,OAAO,CAAC,IAAI,EACZ,UAAU,CACV,CAAC;gBACF,OAAO;oBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;oBACjC,OAAO,EAAE;wBACR,IAAI,EAAE,UAAU,CAAC,IAAI;wBACrB,KAAK,EAAE,oBAAoB,CAAC,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;wBAChE,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;qBAC7C;iBACD,CAAC;YACH,CAAC,EACD,OAAO,CACP,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { AgentHarnessTool, FileError } from \"../types.ts\";\nimport {\n\tapplyEditsToNormalizedContent,\n\tdetectLineEnding,\n\ttype Edit,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n\tstripBom,\n} from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToolPath } from \"./path-utils.ts\";\nimport { appendPostMutateNote, runPostMutate } from \"./post-mutate.ts\";\nimport type { ExecutionToolContext } from \"./tool-context.ts\";\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.\",\n\t\t}),\n\t\tnewText: Type.String({ description: \"Replacement text for this targeted edit.\" }),\n\t},\n\t{},\n);\n\nconst editSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ description: \"Path to the file to edit (relative or absolute)\" }),\n\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\tdescription:\n\t\t\t\t\"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.\",\n\t\t}),\n\t},\n\t{},\n);\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = EditToolInput & { oldText?: unknown; newText?: unknown };\ntype SingleEditInput = { oldText: string; newText: string };\n\nfunction isSingleEditInput(value: unknown): value is SingleEditInput {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst edit = value as Record<string, unknown>;\n\treturn typeof edit.oldText === \"string\" && typeof edit.newText === \"string\";\n}\n\nexport interface EditToolDetails {\n\tdiff: string;\n\tpatch: string;\n\tfirstChangedLine?: number;\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\") return input as EditToolInput;\n\tconst args = input as Record<string, unknown>;\n\tif (typeof args.edits === \"string\") {\n\t\ttry {\n\t\t\tconst parsed: unknown = JSON.parse(args.edits);\n\t\t\tif (Array.isArray(parsed)) {\n\t\t\t\targs.edits = parsed;\n\t\t\t} else if (isSingleEditInput(parsed)) {\n\t\t\t\targs.edits = [parsed];\n\t\t\t}\n\t\t} catch {}\n\t} else if (isSingleEditInput(args.edits)) {\n\t\targs.edits = [args.edits];\n\t}\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText !== \"string\" || typeof legacy.newText !== \"string\") return args as EditToolInput;\n\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\treturn { ...rest, edits } as EditToolInput;\n}\n\nfunction validateEditInput(input: EditToolInput): { path: string; edits: Edit[] } {\n\tif (!Array.isArray(input.edits) || input.edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\treturn { path: input.path, edits: input.edits };\n}\n\nfunction editAccessError(path: string, error: FileError): Error {\n\treturn new Error(`Could not edit file: ${path}. Error code: ${error.code}.`, { cause: error });\n}\n\nexport function createEditTool<TContext extends ExecutionToolContext = ExecutionToolContext>(): AgentHarnessTool<\n\tTContext,\n\ttypeof editSchema,\n\tEditToolDetails | undefined\n> {\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.\",\n\t\tparameters: editSchema,\n\t\tprepareArguments: prepareEditArguments,\n\t\tasync execute(_toolCallId, input, _onUpdate, { env, postMutate }, _invocation, context) {\n\t\t\tconst { path, edits } = validateEditInput(input);\n\t\t\tconst absolutePath = await resolveToolPath(env, path, context);\n\t\t\treturn withFileMutationQueue(\n\t\t\t\tenv,\n\t\t\t\tabsolutePath,\n\t\t\t\tasync () => {\n\t\t\t\t\tif (context.abortSignal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t\tconst info = await env.fileInfo(absolutePath, context);\n\t\t\t\t\tif (!info.ok) throw editAccessError(path, info.error);\n\t\t\t\t\tif (info.value.kind !== \"file\" && info.value.kind !== \"symlink\") {\n\t\t\t\t\t\tthrow new Error(`Could not edit file: ${path}. Path is not a file.`);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst readResult = await env.readTextFile(absolutePath, context);\n\t\t\t\t\tif (!readResult.ok) throw editAccessError(path, readResult.error);\n\t\t\t\t\tif (context.abortSignal?.aborted) throw new Error(\"Operation aborted\");\n\n\t\t\t\t\tconst { bom, text: content } = stripBom(readResult.value);\n\t\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\t\tif (context.abortSignal?.aborted) throw new Error(\"Operation aborted\");\n\n\t\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\t\tconst writeResult = await env.writeFile(absolutePath, finalContent, context);\n\t\t\t\t\tif (!writeResult.ok) throw editAccessError(path, writeResult.error);\n\t\t\t\t\tif (context.abortSignal?.aborted) throw new Error(\"Operation aborted\");\n\n\t\t\t\t\tconst outcome = await runPostMutate(postMutate, {\n\t\t\t\t\t\ttool: \"edit\",\n\t\t\t\t\t\tpath: absolutePath,\n\t\t\t\t\t\tsignal: context.abortSignal,\n\t\t\t\t\t});\n\t\t\t\t\tif (context.abortSignal?.aborted) throw new Error(\"Operation aborted\");\n\n\t\t\t\t\tlet committedContent = newContent;\n\t\t\t\t\tlet rereadNote: string | undefined;\n\t\t\t\t\tif (outcome.fileMayHaveChanged) {\n\t\t\t\t\t\tconst postMutateRead = await env.readTextFile(absolutePath, context);\n\t\t\t\t\t\t// The edit itself already landed, so an unreadable file is the hook's doing, not a\n\t\t\t\t\t\t// failed edit. Report it as a note rather than an error that misattributes the failure.\n\t\t\t\t\t\tif (postMutateRead.ok) committedContent = normalizeToLF(stripBom(postMutateRead.value).text);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\trereadNote = `postMutate left the file unreadable: ${postMutateRead.error.code}. Reported diff describes the edit before the hook ran.`;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst diffResult = generateDiffString(baseContent, committedContent);\n\t\t\t\t\tconst text = appendPostMutateNote(\n\t\t\t\t\t\t`Successfully replaced ${edits.length} block(s) in ${path}.`,\n\t\t\t\t\t\toutcome.note,\n\t\t\t\t\t\trereadNote,\n\t\t\t\t\t);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tdiff: diffResult.diff,\n\t\t\t\t\t\t\tpatch: generateUnifiedPatch(path, baseContent, committedContent),\n\t\t\t\t\t\t\tfirstChangedLine: diffResult.firstChangedLine,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t);\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/harness/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EACN,6BAA6B,EAC7B,gBAAgB,EAEhB,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,EAClB,QAAQ,GACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGvE,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CACpC;IACC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC;QACpB,WAAW,EACV,uJAAuJ;KACxJ,CA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AAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;oBACpE,mFAAmF;oBACnF,wFAAwF;oBACxF,IAAI,cAAc,CAAC,EAAE;wBAAE,gBAAgB,GAAG,aAAa,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;;wBAE5F,UAAU,GAAG,wCAAwC,cAAc,CAAC,KAAK,CAAC,IAAI,yDAAyD,CAAC;gBAC1I,CAAC;gBAED,MAAM,UAAU,GAAG,kBAAkB,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;gBACrE,MAAM,IAAI,GAAG,oBAAoB,CAChC,yBAAyB,KAAK,CAAC,MAAM,gBAAgB,IAAI,GAAG,EAC5D,OAAO,CAAC,IAAI,EACZ,UAAU,CACV,CAAC;gBACF,OAAO;oBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;oBACjC,OAAO,EAAE;wBACR,IAAI,EAAE,UAAU,CAAC,IAAI;wBACrB,KAAK,EAAE,oBAAoB,CAAC,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;wBAChE,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;qBAC7C;iBACD,CAAC;YACH,CAAC,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { AgentHarnessTool, FileError } from \"../types.ts\";\nimport {\n\tapplyEditsToNormalizedContent,\n\tdetectLineEnding,\n\ttype Edit,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n\tstripBom,\n} from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToolPath } from \"./path-utils.ts\";\nimport { appendPostMutateNote, runPostMutate } from \"./post-mutate.ts\";\nimport type { ExecutionToolContext } from \"./tool-context.ts\";\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.\",\n\t\t}),\n\t\tnewText: Type.String({ description: \"Replacement text for this targeted edit.\" }),\n\t},\n\t{},\n);\n\nconst editSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ description: \"Path to the file to edit (relative or absolute)\" }),\n\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\tdescription:\n\t\t\t\t\"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.\",\n\t\t}),\n\t},\n\t{},\n);\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = EditToolInput & { oldText?: unknown; newText?: unknown };\ntype SingleEditInput = { oldText: string; newText: string };\n\nfunction isSingleEditInput(value: unknown): value is SingleEditInput {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst edit = value as Record<string, unknown>;\n\treturn typeof edit.oldText === \"string\" && typeof edit.newText === \"string\";\n}\n\nexport interface EditToolDetails {\n\tdiff: string;\n\tpatch: string;\n\tfirstChangedLine?: number;\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\") return input as EditToolInput;\n\tconst args = input as Record<string, unknown>;\n\tif (typeof args.edits === \"string\") {\n\t\ttry {\n\t\t\tconst parsed: unknown = JSON.parse(args.edits);\n\t\t\tif (Array.isArray(parsed)) {\n\t\t\t\targs.edits = parsed;\n\t\t\t} else if (isSingleEditInput(parsed)) {\n\t\t\t\targs.edits = [parsed];\n\t\t\t}\n\t\t} catch {}\n\t} else if (isSingleEditInput(args.edits)) {\n\t\targs.edits = [args.edits];\n\t}\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText !== \"string\" || typeof legacy.newText !== \"string\") return args as EditToolInput;\n\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\treturn { ...rest, edits } as EditToolInput;\n}\n\nfunction validateEditInput(input: EditToolInput): { path: string; edits: Edit[] } {\n\tif (!Array.isArray(input.edits) || input.edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\treturn { path: input.path, edits: input.edits };\n}\n\nfunction editAccessError(path: string, error: FileError): Error {\n\treturn new Error(`Could not edit file: ${path}. Error code: ${error.code}.`, { cause: error });\n}\n\nexport function createEditTool<TContext extends ExecutionToolContext = ExecutionToolContext>(): AgentHarnessTool<\n\tTContext,\n\ttypeof editSchema,\n\tEditToolDetails | undefined\n> {\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.\",\n\t\tparameters: editSchema,\n\t\tprepareArguments: prepareEditArguments,\n\t\tasync execute(_toolCallId, input, signal, _onUpdate, { env, postMutate }) {\n\t\t\tconst { path, edits } = validateEditInput(input);\n\t\t\tconst absolutePath = await resolveToolPath(env, path, signal);\n\t\t\treturn withFileMutationQueue(env, absolutePath, async () => {\n\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\tconst info = await env.fileInfo(absolutePath, signal);\n\t\t\t\tif (!info.ok) throw editAccessError(path, info.error);\n\t\t\t\tif (info.value.kind !== \"file\" && info.value.kind !== \"symlink\") {\n\t\t\t\t\tthrow new Error(`Could not edit file: ${path}. Path is not a file.`);\n\t\t\t\t}\n\n\t\t\t\tconst readResult = await env.readTextFile(absolutePath, signal);\n\t\t\t\tif (!readResult.ok) throw editAccessError(path, readResult.error);\n\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\n\t\t\t\tconst { bom, text: content } = stripBom(readResult.value);\n\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\n\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\tconst writeResult = await env.writeFile(absolutePath, finalContent, signal);\n\t\t\t\tif (!writeResult.ok) throw editAccessError(path, writeResult.error);\n\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\n\t\t\t\tconst outcome = await runPostMutate(postMutate, { tool: \"edit\", path: absolutePath, signal });\n\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\n\t\t\t\tlet committedContent = newContent;\n\t\t\t\tlet rereadNote: string | undefined;\n\t\t\t\tif (outcome.fileMayHaveChanged) {\n\t\t\t\t\tconst postMutateRead = await env.readTextFile(absolutePath, signal);\n\t\t\t\t\t// The edit itself already landed, so an unreadable file is the hook's doing, not a\n\t\t\t\t\t// failed edit. Report it as a note rather than an error that misattributes the failure.\n\t\t\t\t\tif (postMutateRead.ok) committedContent = normalizeToLF(stripBom(postMutateRead.value).text);\n\t\t\t\t\telse\n\t\t\t\t\t\trereadNote = `postMutate left the file unreadable: ${postMutateRead.error.code}. Reported diff describes the edit before the hook ran.`;\n\t\t\t\t}\n\n\t\t\t\tconst diffResult = generateDiffString(baseContent, committedContent);\n\t\t\t\tconst text = appendPostMutateNote(\n\t\t\t\t\t`Successfully replaced ${edits.length} block(s) in ${path}.`,\n\t\t\t\t\toutcome.note,\n\t\t\t\t\trereadNote,\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tdiff: diffResult.diff,\n\t\t\t\t\t\tpatch: generateUnifiedPatch(path, baseContent, committedContent),\n\t\t\t\t\t\tfirstChangedLine: diffResult.firstChangedLine,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Context } from "../context.ts";
|
|
2
1
|
import type { ExecutionEnv } from "../types.ts";
|
|
3
2
|
/** Serialize file mutations targeting the same environment and canonical path. */
|
|
4
|
-
export declare function withFileMutationQueue<T>(env: ExecutionEnv, path: string, fn: () => Promise<T
|
|
3
|
+
export declare function withFileMutationQueue<T>(env: ExecutionEnv, path: string, fn: () => Promise<T>): Promise<T>;
|
|
5
4
|
//# sourceMappingURL=file-mutation-queue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-mutation-queue.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/file-mutation-queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"file-mutation-queue.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/file-mutation-queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA2BhD,kFAAkF;AAClF,wBAAsB,qBAAqB,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CA2BhH"}
|