@m4ike1/ion-agent-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +622 -0
- package/dist/agent-loop.d.ts +24 -0
- package/dist/agent-loop.d.ts.map +1 -0
- package/dist/agent-loop.js +560 -0
- package/dist/agent-loop.js.map +1 -0
- package/dist/agent.d.ts +122 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +422 -0
- package/dist/agent.js.map +1 -0
- package/dist/harness/agent-harness.d.ts +716 -0
- package/dist/harness/agent-harness.d.ts.map +1 -0
- package/dist/harness/agent-harness.js +6 -0
- package/dist/harness/agent-harness.js.map +1 -0
- package/dist/harness/compaction/branch-summarization.d.ts +68 -0
- package/dist/harness/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/harness/compaction/branch-summarization.js +176 -0
- package/dist/harness/compaction/branch-summarization.js.map +1 -0
- package/dist/harness/compaction/compaction.d.ts +126 -0
- package/dist/harness/compaction/compaction.d.ts.map +1 -0
- package/dist/harness/compaction/compaction.js +560 -0
- package/dist/harness/compaction/compaction.js.map +1 -0
- package/dist/harness/compaction/utils.d.ts +25 -0
- package/dist/harness/compaction/utils.d.ts.map +1 -0
- package/dist/harness/compaction/utils.js +120 -0
- package/dist/harness/compaction/utils.js.map +1 -0
- package/dist/harness/config.d.ts +9 -0
- package/dist/harness/config.d.ts.map +1 -0
- package/dist/harness/config.js +35 -0
- package/dist/harness/config.js.map +1 -0
- package/dist/harness/context.d.ts +9 -0
- package/dist/harness/context.d.ts.map +1 -0
- package/dist/harness/context.js +13 -0
- package/dist/harness/context.js.map +1 -0
- package/dist/harness/env/nodejs.d.ts +43 -0
- package/dist/harness/env/nodejs.d.ts.map +1 -0
- package/dist/harness/env/nodejs.js +865 -0
- package/dist/harness/env/nodejs.js.map +1 -0
- package/dist/harness/events.d.ts +25 -0
- package/dist/harness/events.d.ts.map +1 -0
- package/dist/harness/events.js +250 -0
- package/dist/harness/events.js.map +1 -0
- package/dist/harness/execution/assistant.d.ts +42 -0
- package/dist/harness/execution/assistant.d.ts.map +1 -0
- package/dist/harness/execution/assistant.js +82 -0
- package/dist/harness/execution/assistant.js.map +1 -0
- package/dist/harness/execution/effect-gate.d.ts +22 -0
- package/dist/harness/execution/effect-gate.d.ts.map +1 -0
- package/dist/harness/execution/effect-gate.js +49 -0
- package/dist/harness/execution/effect-gate.js.map +1 -0
- package/dist/harness/execution/tools.d.ts +67 -0
- package/dist/harness/execution/tools.d.ts.map +1 -0
- package/dist/harness/execution/tools.js +121 -0
- package/dist/harness/execution/tools.js.map +1 -0
- package/dist/harness/hooks.d.ts +38 -0
- package/dist/harness/hooks.d.ts.map +1 -0
- package/dist/harness/hooks.js +406 -0
- package/dist/harness/hooks.js.map +1 -0
- package/dist/harness/messages.d.ts +51 -0
- package/dist/harness/messages.d.ts.map +1 -0
- package/dist/harness/messages.js +102 -0
- package/dist/harness/messages.js.map +1 -0
- package/dist/harness/prompt-templates.d.ts +49 -0
- package/dist/harness/prompt-templates.d.ts.map +1 -0
- package/dist/harness/prompt-templates.js +225 -0
- package/dist/harness/prompt-templates.js.map +1 -0
- package/dist/harness/result.d.ts +133 -0
- package/dist/harness/result.d.ts.map +1 -0
- package/dist/harness/result.js +81 -0
- package/dist/harness/result.js.map +1 -0
- package/dist/harness/runtime/drive/boundary.d.ts +28 -0
- package/dist/harness/runtime/drive/boundary.d.ts.map +1 -0
- package/dist/harness/runtime/drive/boundary.js +173 -0
- package/dist/harness/runtime/drive/boundary.js.map +1 -0
- package/dist/harness/runtime/drive/checkpoint.d.ts +8 -0
- package/dist/harness/runtime/drive/checkpoint.d.ts.map +1 -0
- package/dist/harness/runtime/drive/checkpoint.js +133 -0
- package/dist/harness/runtime/drive/checkpoint.js.map +1 -0
- package/dist/harness/runtime/drive/deferred.d.ts +15 -0
- package/dist/harness/runtime/drive/deferred.d.ts.map +1 -0
- package/dist/harness/runtime/drive/deferred.js +179 -0
- package/dist/harness/runtime/drive/deferred.js.map +1 -0
- package/dist/harness/runtime/drive/generation.d.ts +8 -0
- package/dist/harness/runtime/drive/generation.d.ts.map +1 -0
- package/dist/harness/runtime/drive/generation.js +205 -0
- package/dist/harness/runtime/drive/generation.js.map +1 -0
- package/dist/harness/runtime/drive/reconcile.d.ts +5 -0
- package/dist/harness/runtime/drive/reconcile.d.ts.map +1 -0
- package/dist/harness/runtime/drive/reconcile.js +140 -0
- package/dist/harness/runtime/drive/reconcile.js.map +1 -0
- package/dist/harness/runtime/drive/recovery.d.ts +8 -0
- package/dist/harness/runtime/drive/recovery.d.ts.map +1 -0
- package/dist/harness/runtime/drive/recovery.js +85 -0
- package/dist/harness/runtime/drive/recovery.js.map +1 -0
- package/dist/harness/runtime/drive/response.d.ts +23 -0
- package/dist/harness/runtime/drive/response.d.ts.map +1 -0
- package/dist/harness/runtime/drive/response.js +394 -0
- package/dist/harness/runtime/drive/response.js.map +1 -0
- package/dist/harness/runtime/drive/retry.d.ts +4 -0
- package/dist/harness/runtime/drive/retry.d.ts.map +1 -0
- package/dist/harness/runtime/drive/retry.js +34 -0
- package/dist/harness/runtime/drive/retry.js.map +1 -0
- package/dist/harness/runtime/drive/structural.d.ts +32 -0
- package/dist/harness/runtime/drive/structural.d.ts.map +1 -0
- package/dist/harness/runtime/drive/structural.js +929 -0
- package/dist/harness/runtime/drive/structural.js.map +1 -0
- package/dist/harness/runtime/drive/terminal.d.ts +7 -0
- package/dist/harness/runtime/drive/terminal.d.ts.map +1 -0
- package/dist/harness/runtime/drive/terminal.js +49 -0
- package/dist/harness/runtime/drive/terminal.js.map +1 -0
- package/dist/harness/runtime/drive/tool-placement.d.ts +14 -0
- package/dist/harness/runtime/drive/tool-placement.d.ts.map +1 -0
- package/dist/harness/runtime/drive/tool-placement.js +244 -0
- package/dist/harness/runtime/drive/tool-placement.js.map +1 -0
- package/dist/harness/runtime/drive/tools.d.ts +6 -0
- package/dist/harness/runtime/drive/tools.d.ts.map +1 -0
- package/dist/harness/runtime/drive/tools.js +449 -0
- package/dist/harness/runtime/drive/tools.js.map +1 -0
- package/dist/harness/runtime/drive.d.ts +6 -0
- package/dist/harness/runtime/drive.d.ts.map +1 -0
- package/dist/harness/runtime/drive.js +93 -0
- package/dist/harness/runtime/drive.js.map +1 -0
- package/dist/harness/runtime/harness.d.ts +59 -0
- package/dist/harness/runtime/harness.d.ts.map +1 -0
- package/dist/harness/runtime/harness.js +311 -0
- package/dist/harness/runtime/harness.js.map +1 -0
- package/dist/harness/runtime/index.d.ts +2 -0
- package/dist/harness/runtime/index.d.ts.map +1 -0
- package/dist/harness/runtime/index.js +2 -0
- package/dist/harness/runtime/index.js.map +1 -0
- package/dist/harness/runtime/lane.d.ts +101 -0
- package/dist/harness/runtime/lane.d.ts.map +1 -0
- package/dist/harness/runtime/lane.js +1575 -0
- package/dist/harness/runtime/lane.js.map +1 -0
- package/dist/harness/runtime/progress.d.ts +15 -0
- package/dist/harness/runtime/progress.d.ts.map +1 -0
- package/dist/harness/runtime/progress.js +66 -0
- package/dist/harness/runtime/progress.js.map +1 -0
- package/dist/harness/runtime/reducer.d.ts +5 -0
- package/dist/harness/runtime/reducer.d.ts.map +1 -0
- package/dist/harness/runtime/reducer.js +240 -0
- package/dist/harness/runtime/reducer.js.map +1 -0
- package/dist/harness/runtime/restore.d.ts +24 -0
- package/dist/harness/runtime/restore.d.ts.map +1 -0
- package/dist/harness/runtime/restore.js +117 -0
- package/dist/harness/runtime/restore.js.map +1 -0
- package/dist/harness/runtime/transcript.d.ts +21 -0
- package/dist/harness/runtime/transcript.d.ts.map +1 -0
- package/dist/harness/runtime/transcript.js +72 -0
- package/dist/harness/runtime/transcript.js.map +1 -0
- package/dist/harness/runtime/types.d.ts +105 -0
- package/dist/harness/runtime/types.d.ts.map +1 -0
- package/dist/harness/runtime/types.js +61 -0
- package/dist/harness/runtime/types.js.map +1 -0
- package/dist/harness/session/commit.d.ts +53 -0
- package/dist/harness/session/commit.d.ts.map +1 -0
- package/dist/harness/session/commit.js +57 -0
- package/dist/harness/session/commit.js.map +1 -0
- package/dist/harness/session/context.d.ts +10 -0
- package/dist/harness/session/context.d.ts.map +1 -0
- package/dist/harness/session/context.js +49 -0
- package/dist/harness/session/context.js.map +1 -0
- package/dist/harness/session/fork-policy.d.ts +21 -0
- package/dist/harness/session/fork-policy.d.ts.map +1 -0
- package/dist/harness/session/fork-policy.js +55 -0
- package/dist/harness/session/fork-policy.js.map +1 -0
- package/dist/harness/session/fork.d.ts +16 -0
- package/dist/harness/session/fork.d.ts.map +1 -0
- package/dist/harness/session/fork.js +79 -0
- package/dist/harness/session/fork.js.map +1 -0
- package/dist/harness/session/in-memory-storage-state.d.ts +39 -0
- package/dist/harness/session/in-memory-storage-state.d.ts.map +1 -0
- package/dist/harness/session/in-memory-storage-state.js +276 -0
- package/dist/harness/session/in-memory-storage-state.js.map +1 -0
- package/dist/harness/session/index.d.ts +11 -0
- package/dist/harness/session/index.d.ts.map +1 -0
- package/dist/harness/session/index.js +9 -0
- package/dist/harness/session/index.js.map +1 -0
- package/dist/harness/session/jsonl/codec.d.ts +21 -0
- package/dist/harness/session/jsonl/codec.d.ts.map +1 -0
- package/dist/harness/session/jsonl/codec.js +45 -0
- package/dist/harness/session/jsonl/codec.js.map +1 -0
- package/dist/harness/session/jsonl/fork.d.ts +38 -0
- package/dist/harness/session/jsonl/fork.d.ts.map +1 -0
- package/dist/harness/session/jsonl/fork.js +264 -0
- package/dist/harness/session/jsonl/fork.js.map +1 -0
- package/dist/harness/session/jsonl/index.d.ts +4 -0
- package/dist/harness/session/jsonl/index.d.ts.map +1 -0
- package/dist/harness/session/jsonl/index.js +4 -0
- package/dist/harness/session/jsonl/index.js.map +1 -0
- package/dist/harness/session/jsonl/io.d.ts +14 -0
- package/dist/harness/session/jsonl/io.d.ts.map +1 -0
- package/dist/harness/session/jsonl/io.js +86 -0
- package/dist/harness/session/jsonl/io.js.map +1 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts +43 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts.map +1 -0
- package/dist/harness/session/jsonl/legacy-v3.js +462 -0
- package/dist/harness/session/jsonl/legacy-v3.js.map +1 -0
- package/dist/harness/session/jsonl/repo.d.ts +35 -0
- package/dist/harness/session/jsonl/repo.d.ts.map +1 -0
- package/dist/harness/session/jsonl/repo.js +301 -0
- package/dist/harness/session/jsonl/repo.js.map +1 -0
- package/dist/harness/session/jsonl/storage.d.ts +40 -0
- package/dist/harness/session/jsonl/storage.d.ts.map +1 -0
- package/dist/harness/session/jsonl/storage.js +200 -0
- package/dist/harness/session/jsonl/storage.js.map +1 -0
- package/dist/harness/session/jsonl/types.d.ts +39 -0
- package/dist/harness/session/jsonl/types.d.ts.map +1 -0
- package/dist/harness/session/jsonl/types.js +3 -0
- package/dist/harness/session/jsonl/types.js.map +1 -0
- package/dist/harness/session/memory.d.ts +48 -0
- package/dist/harness/session/memory.d.ts.map +1 -0
- package/dist/harness/session/memory.js +369 -0
- package/dist/harness/session/memory.js.map +1 -0
- package/dist/harness/session/mutation-line.d.ts +8 -0
- package/dist/harness/session/mutation-line.d.ts.map +1 -0
- package/dist/harness/session/mutation-line.js +21 -0
- package/dist/harness/session/mutation-line.js.map +1 -0
- package/dist/harness/session/session.d.ts +82 -0
- package/dist/harness/session/session.d.ts.map +1 -0
- package/dist/harness/session/session.js +361 -0
- package/dist/harness/session/session.js.map +1 -0
- package/dist/harness/session/testing/benchmark/datasets.d.ts +12 -0
- package/dist/harness/session/testing/benchmark/datasets.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/datasets.js +24 -0
- package/dist/harness/session/testing/benchmark/datasets.js.map +1 -0
- package/dist/harness/session/testing/benchmark/session-repo.d.ts +42 -0
- package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/session-repo.js +127 -0
- package/dist/harness/session/testing/benchmark/session-repo.js.map +1 -0
- package/dist/harness/session/testing/benchmark/storage.d.ts +25 -0
- package/dist/harness/session/testing/benchmark/storage.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/storage.js +114 -0
- package/dist/harness/session/testing/benchmark/storage.js.map +1 -0
- package/dist/harness/session/testing/conformance/session-repo.d.ts +23 -0
- package/dist/harness/session/testing/conformance/session-repo.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance/session-repo.js +809 -0
- package/dist/harness/session/testing/conformance/session-repo.js.map +1 -0
- package/dist/harness/session/testing/conformance/storage.d.ts +4 -0
- package/dist/harness/session/testing/conformance/storage.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance/storage.js +600 -0
- package/dist/harness/session/testing/conformance/storage.js.map +1 -0
- package/dist/harness/session/testing/gating-storage.d.ts +26 -0
- package/dist/harness/session/testing/gating-storage.d.ts.map +1 -0
- package/dist/harness/session/testing/gating-storage.js +100 -0
- package/dist/harness/session/testing/gating-storage.js.map +1 -0
- package/dist/harness/session/testing/index.d.ts +10 -0
- package/dist/harness/session/testing/index.d.ts.map +1 -0
- package/dist/harness/session/testing/index.js +9 -0
- package/dist/harness/session/testing/index.js.map +1 -0
- package/dist/harness/session/testing/instrumented-storage.d.ts +11 -0
- package/dist/harness/session/testing/instrumented-storage.d.ts.map +1 -0
- package/dist/harness/session/testing/instrumented-storage.js +16 -0
- package/dist/harness/session/testing/instrumented-storage.js.map +1 -0
- package/dist/harness/session/testing/storage-decorator.d.ts +20 -0
- package/dist/harness/session/testing/storage-decorator.d.ts.map +1 -0
- package/dist/harness/session/testing/storage-decorator.js +41 -0
- package/dist/harness/session/testing/storage-decorator.js.map +1 -0
- package/dist/harness/session/testing/types.d.ts +12 -0
- package/dist/harness/session/testing/types.d.ts.map +1 -0
- package/dist/harness/session/testing/types.js +2 -0
- package/dist/harness/session/testing/types.js.map +1 -0
- package/dist/harness/session/types.d.ts +512 -0
- package/dist/harness/session/types.d.ts.map +1 -0
- package/dist/harness/session/types.js +9 -0
- package/dist/harness/session/types.js.map +1 -0
- package/dist/harness/session/values.d.ts +95 -0
- package/dist/harness/session/values.d.ts.map +1 -0
- package/dist/harness/session/values.js +81 -0
- package/dist/harness/session/values.js.map +1 -0
- package/dist/harness/skills.d.ts +46 -0
- package/dist/harness/skills.d.ts.map +1 -0
- package/dist/harness/skills.js +326 -0
- package/dist/harness/skills.js.map +1 -0
- package/dist/harness/system-prompt.d.ts +3 -0
- package/dist/harness/system-prompt.d.ts.map +1 -0
- package/dist/harness/system-prompt.js +30 -0
- package/dist/harness/system-prompt.js.map +1 -0
- package/dist/harness/telemetry.d.ts +1242 -0
- package/dist/harness/telemetry.d.ts.map +1 -0
- package/dist/harness/telemetry.js +527 -0
- package/dist/harness/telemetry.js.map +1 -0
- package/dist/harness/tools/bash.d.ts +27 -0
- package/dist/harness/tools/bash.d.ts.map +1 -0
- package/dist/harness/tools/bash.js +105 -0
- package/dist/harness/tools/bash.js.map +1 -0
- package/dist/harness/tools/edit-diff.d.ts +89 -0
- package/dist/harness/tools/edit-diff.d.ts.map +1 -0
- package/dist/harness/tools/edit-diff.js +386 -0
- package/dist/harness/tools/edit-diff.js.map +1 -0
- package/dist/harness/tools/edit.d.ts +19 -0
- package/dist/harness/tools/edit.d.ts.map +1 -0
- package/dist/harness/tools/edit.js +108 -0
- package/dist/harness/tools/edit.js.map +1 -0
- package/dist/harness/tools/file-mutation-queue.d.ts +5 -0
- package/dist/harness/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/harness/tools/file-mutation-queue.js +46 -0
- package/dist/harness/tools/file-mutation-queue.js.map +1 -0
- package/dist/harness/tools/image.d.ts +3 -0
- package/dist/harness/tools/image.d.ts.map +1 -0
- package/dist/harness/tools/image.js +106 -0
- package/dist/harness/tools/image.js.map +1 -0
- package/dist/harness/tools/index.d.ts +6 -0
- package/dist/harness/tools/index.d.ts.map +1 -0
- package/dist/harness/tools/index.js +5 -0
- package/dist/harness/tools/index.js.map +1 -0
- package/dist/harness/tools/path-utils.d.ts +5 -0
- package/dist/harness/tools/path-utils.d.ts.map +1 -0
- package/dist/harness/tools/path-utils.js +26 -0
- package/dist/harness/tools/path-utils.js.map +1 -0
- package/dist/harness/tools/read.d.ts +35 -0
- package/dist/harness/tools/read.d.ts.map +1 -0
- package/dist/harness/tools/read.js +108 -0
- package/dist/harness/tools/read.js.map +1 -0
- package/dist/harness/tools/tool-context.d.ts +6 -0
- package/dist/harness/tools/tool-context.d.ts.map +1 -0
- package/dist/harness/tools/tool-context.js +2 -0
- package/dist/harness/tools/tool-context.js.map +1 -0
- package/dist/harness/tools/write.d.ts +11 -0
- package/dist/harness/tools/write.d.ts.map +1 -0
- package/dist/harness/tools/write.js +31 -0
- package/dist/harness/tools/write.js.map +1 -0
- package/dist/harness/types.d.ts +305 -0
- package/dist/harness/types.d.ts.map +1 -0
- package/dist/harness/types.js +75 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/harness/utils/adaptive-publisher.d.ts +24 -0
- package/dist/harness/utils/adaptive-publisher.d.ts.map +1 -0
- package/dist/harness/utils/adaptive-publisher.js +79 -0
- package/dist/harness/utils/adaptive-publisher.js.map +1 -0
- package/dist/harness/utils/output-capture.d.ts +31 -0
- package/dist/harness/utils/output-capture.d.ts.map +1 -0
- package/dist/harness/utils/output-capture.js +217 -0
- package/dist/harness/utils/output-capture.js.map +1 -0
- package/dist/harness/utils/shell-output.d.ts +29 -0
- package/dist/harness/utils/shell-output.d.ts.map +1 -0
- package/dist/harness/utils/shell-output.js +71 -0
- package/dist/harness/utils/shell-output.js.map +1 -0
- package/dist/harness/utils/truncate.d.ts +71 -0
- package/dist/harness/utils/truncate.d.ts.map +1 -0
- package/dist/harness/utils/truncate.js +296 -0
- package/dist/harness/utils/truncate.js.map +1 -0
- package/dist/harness/utils/usage.d.ts +4 -0
- package/dist/harness/utils/usage.d.ts.map +1 -0
- package/dist/harness/utils/usage.js +33 -0
- package/dist/harness/utils/usage.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +3 -0
- package/dist/node.js.map +1 -0
- package/dist/proxy.d.ts +72 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +310 -0
- package/dist/proxy.js.map +1 -0
- package/dist/search/index.d.ts +29 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +2 -0
- package/dist/search/index.js.map +1 -0
- package/dist/stream-fn.d.ts +10 -0
- package/dist/stream-fn.d.ts.map +1 -0
- package/dist/stream-fn.js +17 -0
- package/dist/stream-fn.js.map +1 -0
- package/dist/types.d.ts +416 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../src/harness/telemetry.ts"],"names":[],"mappings":"AAYA,OAAO,EAAgB,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AA6BvF,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,OAAO,EAAE,CAAC;IACV,KAAK,EAAE;QACN,gBAAgB,EAAE;YACjB,WAAW,EAAE,uCAAuC;YACpD,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;YACxB,eAAe,EAAE;gBAChB,kBAAkB,EAAE;oBACnB,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,iBAAiB,EAAE;oBAClB,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,sBAAsB;iBACnC;gBACD,cAAc,EAAE;oBACf,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,oBAAoB;iBACjC;gBACD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AE,OAAO,CAAC,CAAC,CACjF,CAAC;AAAA,CACF","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 \"@m4ike1/ion-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 \"@m4ike1/ion-telemetry\";\n\nexport const AI_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.ai.response.model\": { type: \"string\", description: \"Concrete response model\" },\n\t\t\t\t\"ion.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\"ion.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\"ion.ai.http.status_code\": { type: \"number\", description: \"Final HTTP status\" },\n\t\t\t\t\"ion.ai.usage.input_tokens\": { type: \"number\", description: \"Reported input tokens\" },\n\t\t\t\t\"ion.ai.usage.output_tokens\": { type: \"number\", description: \"Reported output tokens\" },\n\t\t\t\t\"ion.ai.usage.cache_read_tokens\": { type: \"number\", description: \"Reported cache-read tokens\" },\n\t\t\t\t\"ion.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\"ion.ai.usage.reasoning_tokens\": { type: \"number\", description: \"Reported reasoning tokens\" },\n\t\t\t\t\"ion.ai.usage.total_tokens\": { type: \"number\", description: \"Reported total tokens\" },\n\t\t\t\t\"ion.ai.usage.cost\": { type: \"number\", description: \"Reported total cost\" },\n\t\t\t\t\"ion.ai.stream.chunk_count\": { type: \"number\", description: \"Streamed update chunk count\" },\n\t\t\t\t\"ion.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\"ion.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\"ion.session.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Session id\",\n\t},\n\t\"ion.lane.name\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Lane name\",\n\t},\n\t\"ion.operation.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Durable operation id\",\n\t},\n\t\"ion.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\"ion.error.code\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Stable operation error code\",\n\t},\n\t\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.harness.checkpoint\": {\n\t\t\tdescription: \"One run checkpoint\",\n\t\t\tparents: { kind: \"spans\", spans: [\"ion.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"ion.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\"ion.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\"ion.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\"ion.harness.turn\": {\n\t\t\tdescription: \"One assistant response and its tool batch\",\n\t\t\tparents: { kind: \"spans\", spans: [\"ion.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"ion.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\"ion.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\"ion.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\"ion.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: [\"ion.harness.turn\", \"ion.harness.checkpoint\", \"ion.harness.compaction\", \"ion.harness.navigation\"],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.harness.tool\": {\n\t\t\tdescription: \"One raw phase-2 tool execution\",\n\t\t\tparents: { kind: \"spans\", spans: [\"ion.harness.turn\", \"ion.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.harness.run\",\n\t\t\t\t\t\"ion.harness.compaction\",\n\t\t\t\t\t\"ion.harness.navigation\",\n\t\t\t\t\t\"ion.harness.turn\",\n\t\t\t\t\t\"ion.harness.checkpoint\",\n\t\t\t\t],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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\"ion.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"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Static, Type } from "typebox";
|
|
2
|
+
import type { Context } from "../context.ts";
|
|
3
|
+
import type { AgentHarnessTool, ShellOutputTruncation } from "../types.ts";
|
|
4
|
+
import type { ExecutionToolContext } from "./tool-context.ts";
|
|
5
|
+
declare const bashSchema: Type.TObject<{
|
|
6
|
+
command: Type.TString;
|
|
7
|
+
timeout: Type.TOptional<Type.TNumber>;
|
|
8
|
+
}>;
|
|
9
|
+
export type BashToolInput = Static<typeof bashSchema>;
|
|
10
|
+
export interface BashToolDetails {
|
|
11
|
+
truncation?: ShellOutputTruncation;
|
|
12
|
+
fullOutputPath?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface BashExecution {
|
|
15
|
+
command: string;
|
|
16
|
+
cwd: string;
|
|
17
|
+
env: Record<string, string>;
|
|
18
|
+
inheritEnv: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type BashPrepare<TContext extends ExecutionToolContext = ExecutionToolContext> = (execution: BashExecution, toolContext: TContext, context: Context) => void | Promise<void>;
|
|
21
|
+
export interface BashToolOptions<TContext extends ExecutionToolContext = ExecutionToolContext> {
|
|
22
|
+
commandPrefix?: string;
|
|
23
|
+
prepare?: BashPrepare<TContext>;
|
|
24
|
+
}
|
|
25
|
+
export declare function createBashTool<TContext extends ExecutionToolContext = ExecutionToolContext>(options?: BashToolOptions<TContext>): AgentHarnessTool<TContext, typeof bashSchema, BashToolDetails | undefined>;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=bash.d.ts.map
|
|
@@ -0,0 +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,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAmB,MAAM,aAAa,CAAC;AAG5F,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,qBAAqB,CAAC;IACnC,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,WAAW,EAAE,QAAQ,EACrB,OAAO,EAAE,OAAO,KACZ,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,CA4F5E","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"]}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { applyShellOutputUpdate } from "../utils/output-capture.js";
|
|
3
|
+
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize } from "../utils/truncate.js";
|
|
4
|
+
const MAX_TIMEOUT_SECONDS = 2_147_483_647 / 1000;
|
|
5
|
+
const BASH_CHECKPOINT_INTERVAL_MS = 2_000;
|
|
6
|
+
const bashSchema = Type.Object({
|
|
7
|
+
command: Type.String({ description: "Bash command to execute" }),
|
|
8
|
+
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })),
|
|
9
|
+
});
|
|
10
|
+
function validateTimeout(timeout) {
|
|
11
|
+
if (timeout === undefined)
|
|
12
|
+
return;
|
|
13
|
+
if (!Number.isFinite(timeout) || timeout <= 0) {
|
|
14
|
+
throw new Error("Invalid timeout: must be a finite number of seconds");
|
|
15
|
+
}
|
|
16
|
+
if (timeout > MAX_TIMEOUT_SECONDS) {
|
|
17
|
+
throw new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function createBashTool(options) {
|
|
21
|
+
return {
|
|
22
|
+
name: "bash",
|
|
23
|
+
label: "bash",
|
|
24
|
+
description: `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.`,
|
|
25
|
+
parameters: bashSchema,
|
|
26
|
+
async execute(_toolCallId, { command, timeout }, onUpdate, toolContext, _invocation, context) {
|
|
27
|
+
validateTimeout(timeout);
|
|
28
|
+
const { env } = toolContext;
|
|
29
|
+
const execution = {
|
|
30
|
+
command: options?.commandPrefix ? `${options.commandPrefix}\n${command}` : command,
|
|
31
|
+
cwd: env.cwd,
|
|
32
|
+
env: {},
|
|
33
|
+
inheritEnv: true,
|
|
34
|
+
};
|
|
35
|
+
await options?.prepare?.(execution, toolContext, context);
|
|
36
|
+
let view;
|
|
37
|
+
let lastCheckpointAt = Date.now();
|
|
38
|
+
let lastCheckpoint;
|
|
39
|
+
let acceptingUpdates = true;
|
|
40
|
+
onUpdate({ content: [], details: undefined });
|
|
41
|
+
const result = await env.exec(execution.command, {
|
|
42
|
+
cwd: execution.cwd,
|
|
43
|
+
env: execution.env,
|
|
44
|
+
inheritEnv: execution.inheritEnv,
|
|
45
|
+
timeout,
|
|
46
|
+
capture: {
|
|
47
|
+
limits: { maxBytes: DEFAULT_MAX_BYTES, maxLines: DEFAULT_MAX_LINES, retain: "tail" },
|
|
48
|
+
spill: true,
|
|
49
|
+
},
|
|
50
|
+
onUpdate: (update) => {
|
|
51
|
+
if (!acceptingUpdates)
|
|
52
|
+
return;
|
|
53
|
+
view = applyShellOutputUpdate(view, update);
|
|
54
|
+
const snapshot = {
|
|
55
|
+
content: [{ type: "text", text: view.text }],
|
|
56
|
+
details: {
|
|
57
|
+
truncation: view.truncation.truncated ? view.truncation : undefined,
|
|
58
|
+
fullOutputPath: view.spillPath,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
const now = Date.now();
|
|
62
|
+
const encoded = JSON.stringify(snapshot);
|
|
63
|
+
const checkpoint = now - lastCheckpointAt >= BASH_CHECKPOINT_INTERVAL_MS && encoded !== lastCheckpoint;
|
|
64
|
+
onUpdate(snapshot, checkpoint ? { checkpoint: true } : undefined);
|
|
65
|
+
if (checkpoint) {
|
|
66
|
+
lastCheckpointAt = now;
|
|
67
|
+
lastCheckpoint = encoded;
|
|
68
|
+
}
|
|
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
|
+
}
|
|
83
|
+
else if (capture.truncation.truncatedBy === "lines") {
|
|
84
|
+
outputText += `\n\n[Showing lines ${startLine}-${endLine} of ${capture.truncation.totalLines}. Full output: ${capture.spillPath}]`;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
outputText += `\n\n[Showing lines ${startLine}-${endLine} of ${capture.truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${capture.spillPath}]`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (!result.ok) {
|
|
91
|
+
const status = result.error.code === "timeout"
|
|
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}`);
|
|
100
|
+
}
|
|
101
|
+
return { content: [{ type: "text", text: outputText || "(no output)" }], details };
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=bash.js.map
|
|
@@ -0,0 +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,2BAA2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E,CAC3F,CAAC;YACH,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,IAAI,aAAa,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;QAAA,CACnF;KACD,CAAC;AAAA,CACF","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"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared diff computation utilities for the edit and similar tools.
|
|
3
|
+
*/
|
|
4
|
+
export declare function detectLineEnding(content: string): "\r\n" | "\n";
|
|
5
|
+
export declare function normalizeToLF(text: string): string;
|
|
6
|
+
export declare function restoreLineEndings(text: string, ending: "\r\n" | "\n"): string;
|
|
7
|
+
/**
|
|
8
|
+
* Normalize text for fuzzy matching. Applies progressive transformations:
|
|
9
|
+
* - Strip trailing whitespace from each line
|
|
10
|
+
* - Normalize smart quotes to ASCII equivalents
|
|
11
|
+
* - Normalize Unicode dashes/hyphens to ASCII hyphen
|
|
12
|
+
* - Normalize special Unicode spaces to regular space
|
|
13
|
+
*/
|
|
14
|
+
export declare function normalizeForFuzzyMatch(text: string): string;
|
|
15
|
+
interface MatchedEdit {
|
|
16
|
+
editIndex: number;
|
|
17
|
+
matchIndex: number;
|
|
18
|
+
matchLength: number;
|
|
19
|
+
newText: string;
|
|
20
|
+
}
|
|
21
|
+
type TextReplacement = Pick<MatchedEdit, "matchIndex" | "matchLength" | "newText">;
|
|
22
|
+
/**
|
|
23
|
+
* Apply replacements matched against `baseContent` to `originalContent` while
|
|
24
|
+
* preserving unchanged line blocks from the original.
|
|
25
|
+
*
|
|
26
|
+
* This is useful when `baseContent` is a normalized view of the original. Each
|
|
27
|
+
* replacement is widened to the lines it actually touches, those touched lines
|
|
28
|
+
* are rewritten from the normalized base, and all other lines are copied back
|
|
29
|
+
* from `originalContent`. The actual replacement ranges drive preservation so
|
|
30
|
+
* duplicate normalized lines cannot be aligned to the wrong occurrence.
|
|
31
|
+
*/
|
|
32
|
+
export declare function applyReplacementsPreservingUnchangedLines(originalContent: string, baseContent: string, replacements: TextReplacement[]): string;
|
|
33
|
+
export interface FuzzyMatchResult {
|
|
34
|
+
/** Whether a match was found */
|
|
35
|
+
found: boolean;
|
|
36
|
+
/** The index where the match starts (in the content that should be used for replacement) */
|
|
37
|
+
index: number;
|
|
38
|
+
/** Length of the matched text */
|
|
39
|
+
matchLength: number;
|
|
40
|
+
/** Whether fuzzy matching was used (false = exact match) */
|
|
41
|
+
usedFuzzyMatch: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The content to use for replacement operations.
|
|
44
|
+
* When exact match: original content. When fuzzy match: normalized content.
|
|
45
|
+
*/
|
|
46
|
+
contentForReplacement: string;
|
|
47
|
+
}
|
|
48
|
+
export interface Edit {
|
|
49
|
+
oldText: string;
|
|
50
|
+
newText: string;
|
|
51
|
+
}
|
|
52
|
+
export interface AppliedEditsResult {
|
|
53
|
+
baseContent: string;
|
|
54
|
+
newContent: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Find oldText in content, trying exact match first, then fuzzy match.
|
|
58
|
+
* When fuzzy matching is used, the returned contentForReplacement is the
|
|
59
|
+
* fuzzy-normalized version of the content (trailing whitespace stripped,
|
|
60
|
+
* Unicode quotes/dashes normalized to ASCII).
|
|
61
|
+
*/
|
|
62
|
+
export declare function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult;
|
|
63
|
+
/** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */
|
|
64
|
+
export declare function stripBom(content: string): {
|
|
65
|
+
bom: string;
|
|
66
|
+
text: string;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Apply one or more exact-text replacements to LF-normalized content.
|
|
70
|
+
*
|
|
71
|
+
* All edits are matched against the same original content. Replacements are
|
|
72
|
+
* then applied in reverse order so offsets remain stable. If any edit needs
|
|
73
|
+
* fuzzy matching, the operation runs in fuzzy-normalized content space and then
|
|
74
|
+
* overlays those line-level changes onto the original content so unchanged line
|
|
75
|
+
* blocks keep their original bytes.
|
|
76
|
+
*/
|
|
77
|
+
export declare function applyEditsToNormalizedContent(normalizedContent: string, edits: Edit[], path: string): AppliedEditsResult;
|
|
78
|
+
/** Generate a standard unified patch. */
|
|
79
|
+
export declare function generateUnifiedPatch(path: string, oldContent: string, newContent: string, contextLines?: number): string;
|
|
80
|
+
/**
|
|
81
|
+
* Generate a display-oriented diff string with line numbers and context.
|
|
82
|
+
* Returns both the diff string and the first changed line number (in the new file).
|
|
83
|
+
*/
|
|
84
|
+
export declare function generateDiffString(oldContent: string, newContent: string, contextLines?: number): {
|
|
85
|
+
diff: string;
|
|
86
|
+
firstChangedLine: number | undefined;
|
|
87
|
+
};
|
|
88
|
+
export {};
|
|
89
|
+
//# sourceMappingURL=edit-diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit-diff.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM/D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAg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8CD;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC5C,iBAAiB,EAAE,MAAM,EACzB,KAAK,EAAE,IAAI,EAAE,EACb,IAAI,EAAE,MAAM,GACV,kBAAkB,CA0DpB;AAED,yCAAyC;AACzC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,SAAI,GAAG,MAAM,CAKnH;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CACjC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,YAAY,SAAI,GACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAuHxD","sourcesContent":["/**\n * Shared diff computation utilities for the edit and similar tools.\n */\n\nimport * as Diff from \"diff\";\n\nexport function detectLineEnding(content: string): \"\\r\\n\" | \"\\n\" {\n\tconst crlfIdx = content.indexOf(\"\\r\\n\");\n\tconst lfIdx = content.indexOf(\"\\n\");\n\tif (lfIdx === -1) return \"\\n\";\n\tif (crlfIdx === -1) return \"\\n\";\n\treturn crlfIdx < lfIdx ? \"\\r\\n\" : \"\\n\";\n}\n\nexport function normalizeToLF(text: string): string {\n\treturn text.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n}\n\nexport function restoreLineEndings(text: string, ending: \"\\r\\n\" | \"\\n\"): string {\n\treturn ending === \"\\r\\n\" ? text.replace(/\\n/g, \"\\r\\n\") : text;\n}\n\n/**\n * Normalize text for fuzzy matching. Applies progressive transformations:\n * - Strip trailing whitespace from each line\n * - Normalize smart quotes to ASCII equivalents\n * - Normalize Unicode dashes/hyphens to ASCII hyphen\n * - Normalize special Unicode spaces to regular space\n */\nexport function normalizeForFuzzyMatch(text: string): string {\n\treturn (\n\t\ttext\n\t\t\t.normalize(\"NFKC\")\n\t\t\t// Strip trailing whitespace per line\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => line.trimEnd())\n\t\t\t.join(\"\\n\")\n\t\t\t// Smart single quotes → '\n\t\t\t.replace(/[\\u2018\\u2019\\u201A\\u201B]/g, \"'\")\n\t\t\t// Smart double quotes → \"\n\t\t\t.replace(/[\\u201C\\u201D\\u201E\\u201F]/g, '\"')\n\t\t\t// Various dashes/hyphens → -\n\t\t\t// U+2010 hyphen, U+2011 non-breaking hyphen, U+2012 figure dash,\n\t\t\t// U+2013 en-dash, U+2014 em-dash, U+2015 horizontal bar, U+2212 minus\n\t\t\t.replace(/[\\u2010\\u2011\\u2012\\u2013\\u2014\\u2015\\u2212]/g, \"-\")\n\t\t\t// Special spaces → regular space\n\t\t\t// U+00A0 NBSP, U+2002-U+200A various spaces, U+202F narrow NBSP,\n\t\t\t// U+205F medium math space, U+3000 ideographic space\n\t\t\t.replace(/[\\u00A0\\u2002-\\u200A\\u202F\\u205F\\u3000]/g, \" \")\n\t);\n}\n\nfunction splitLinesWithEndings(content: string): string[] {\n\treturn content.match(/[^\\n]*\\n|[^\\n]+/g) ?? [];\n}\n\ninterface LineSpan {\n\tstart: number;\n\tend: number;\n}\n\ninterface MatchedEdit {\n\teditIndex: number;\n\tmatchIndex: number;\n\tmatchLength: number;\n\tnewText: string;\n}\n\ntype TextReplacement = Pick<MatchedEdit, \"matchIndex\" | \"matchLength\" | \"newText\">;\n\nfunction getLineSpans(content: string): LineSpan[] {\n\tlet offset = 0;\n\treturn splitLinesWithEndings(content).map((line) => {\n\t\tconst span = { start: offset, end: offset + line.length };\n\t\toffset = span.end;\n\t\treturn span;\n\t});\n}\n\nfunction getReplacementLineRange(lines: LineSpan[], replacement: TextReplacement) {\n\tconst replacementStart = replacement.matchIndex;\n\tconst replacementEnd = replacement.matchIndex + replacement.matchLength;\n\n\tlet startLine = -1;\n\tfor (let i = 0; i < lines.length; i++) {\n\t\tconst line = lines[i];\n\t\tif (replacementStart >= line.start && replacementStart < line.end) {\n\t\t\tstartLine = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (startLine === -1) {\n\t\tthrow new Error(\"Replacement range is outside the base content.\");\n\t}\n\n\tlet endLine = startLine;\n\twhile (endLine < lines.length && lines[endLine].end < replacementEnd) {\n\t\tendLine++;\n\t}\n\tif (endLine >= lines.length) {\n\t\tthrow new Error(\"Replacement range is outside the base content.\");\n\t}\n\n\treturn { startLine, endLine: endLine + 1 };\n}\n\nfunction applyReplacements(content: string, replacements: TextReplacement[], offset = 0): string {\n\tlet result = content;\n\tfor (let i = replacements.length - 1; i >= 0; i--) {\n\t\tconst replacement = replacements[i];\n\t\tconst matchIndex = replacement.matchIndex - offset;\n\t\tresult =\n\t\t\tresult.substring(0, matchIndex) + replacement.newText + result.substring(matchIndex + replacement.matchLength);\n\t}\n\treturn result;\n}\n\n/**\n * Apply replacements matched against `baseContent` to `originalContent` while\n * preserving unchanged line blocks from the original.\n *\n * This is useful when `baseContent` is a normalized view of the original. Each\n * replacement is widened to the lines it actually touches, those touched lines\n * are rewritten from the normalized base, and all other lines are copied back\n * from `originalContent`. The actual replacement ranges drive preservation so\n * duplicate normalized lines cannot be aligned to the wrong occurrence.\n */\nexport function applyReplacementsPreservingUnchangedLines(\n\toriginalContent: string,\n\tbaseContent: string,\n\treplacements: TextReplacement[],\n): string {\n\tconst originalLines = splitLinesWithEndings(originalContent);\n\tconst baseLines = getLineSpans(baseContent);\n\tif (originalLines.length !== baseLines.length) {\n\t\tthrow new Error(\"Cannot preserve unchanged lines because the base content has a different line count.\");\n\t}\n\n\tconst groups: Array<{ startLine: number; endLine: number; replacements: TextReplacement[] }> = [];\n\tconst sortedReplacements = [...replacements].sort((a, b) => a.matchIndex - b.matchIndex);\n\tfor (const replacement of sortedReplacements) {\n\t\tconst range = getReplacementLineRange(baseLines, replacement);\n\t\tconst current = groups[groups.length - 1];\n\t\tif (current && range.startLine < current.endLine) {\n\t\t\tcurrent.endLine = Math.max(current.endLine, range.endLine);\n\t\t\tcurrent.replacements.push(replacement);\n\t\t\tcontinue;\n\t\t}\n\t\tgroups.push({ ...range, replacements: [replacement] });\n\t}\n\n\tlet originalLineIndex = 0;\n\tlet result = \"\";\n\tfor (const group of groups) {\n\t\tresult += originalLines.slice(originalLineIndex, group.startLine).join(\"\");\n\n\t\tconst groupStartOffset = baseLines[group.startLine].start;\n\t\tconst groupEndOffset = baseLines[group.endLine - 1].end;\n\t\tresult += applyReplacements(\n\t\t\tbaseContent.slice(groupStartOffset, groupEndOffset),\n\t\t\tgroup.replacements,\n\t\t\tgroupStartOffset,\n\t\t);\n\t\toriginalLineIndex = group.endLine;\n\t}\n\tresult += originalLines.slice(originalLineIndex).join(\"\");\n\n\treturn result;\n}\n\nexport interface FuzzyMatchResult {\n\t/** Whether a match was found */\n\tfound: boolean;\n\t/** The index where the match starts (in the content that should be used for replacement) */\n\tindex: number;\n\t/** Length of the matched text */\n\tmatchLength: number;\n\t/** Whether fuzzy matching was used (false = exact match) */\n\tusedFuzzyMatch: boolean;\n\t/**\n\t * The content to use for replacement operations.\n\t * When exact match: original content. When fuzzy match: normalized content.\n\t */\n\tcontentForReplacement: string;\n}\n\nexport interface Edit {\n\toldText: string;\n\tnewText: string;\n}\n\nexport interface AppliedEditsResult {\n\tbaseContent: string;\n\tnewContent: string;\n}\n\n/**\n * Find oldText in content, trying exact match first, then fuzzy match.\n * When fuzzy matching is used, the returned contentForReplacement is the\n * fuzzy-normalized version of the content (trailing whitespace stripped,\n * Unicode quotes/dashes normalized to ASCII).\n */\nexport function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult {\n\t// Try exact match first\n\tconst exactIndex = content.indexOf(oldText);\n\tif (exactIndex !== -1) {\n\t\treturn {\n\t\t\tfound: true,\n\t\t\tindex: exactIndex,\n\t\t\tmatchLength: oldText.length,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// Try fuzzy match - work entirely in normalized space\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\tconst fuzzyIndex = fuzzyContent.indexOf(fuzzyOldText);\n\n\tif (fuzzyIndex === -1) {\n\t\treturn {\n\t\t\tfound: false,\n\t\t\tindex: -1,\n\t\t\tmatchLength: 0,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// When fuzzy matching, return offsets in normalized space. Callers can use\n\t// the normalized content to compute replacements, then decide how much of\n\t// that normalized output should be written back.\n\treturn {\n\t\tfound: true,\n\t\tindex: fuzzyIndex,\n\t\tmatchLength: fuzzyOldText.length,\n\t\tusedFuzzyMatch: true,\n\t\tcontentForReplacement: fuzzyContent,\n\t};\n}\n\n/** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */\nexport function stripBom(content: string): { bom: string; text: string } {\n\treturn content.startsWith(\"\\uFEFF\") ? { bom: \"\\uFEFF\", text: content.slice(1) } : { bom: \"\", text: content };\n}\n\nfunction countOccurrences(content: string, oldText: string): number {\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\treturn fuzzyContent.split(fuzzyOldText).length - 1;\n}\n\nfunction getNotFoundError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Could not find edits[${editIndex}] in ${path}. The oldText must match exactly including all whitespace and newlines.`,\n\t);\n}\n\nfunction getDuplicateError(path: string, editIndex: number, totalEdits: number, occurrences: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Found ${occurrences} occurrences of edits[${editIndex}] in ${path}. Each oldText must be unique. Please provide more context to make it unique.`,\n\t);\n}\n\nfunction getEmptyOldTextError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(`oldText must not be empty in ${path}.`);\n\t}\n\treturn new Error(`edits[${editIndex}].oldText must not be empty in ${path}.`);\n}\n\nfunction getNoChangeError(path: string, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`No changes made to ${path}. The replacement produced identical content. This might indicate an issue with special characters or the text not existing as expected.`,\n\t\t);\n\t}\n\treturn new Error(`No changes made to ${path}. The replacements produced identical content.`);\n}\n\n/**\n * Apply one or more exact-text replacements to LF-normalized content.\n *\n * All edits are matched against the same original content. Replacements are\n * then applied in reverse order so offsets remain stable. If any edit needs\n * fuzzy matching, the operation runs in fuzzy-normalized content space and then\n * overlays those line-level changes onto the original content so unchanged line\n * blocks keep their original bytes.\n */\nexport function applyEditsToNormalizedContent(\n\tnormalizedContent: string,\n\tedits: Edit[],\n\tpath: string,\n): AppliedEditsResult {\n\tconst normalizedEdits = edits.map((edit) => ({\n\t\toldText: normalizeToLF(edit.oldText),\n\t\tnewText: normalizeToLF(edit.newText),\n\t}));\n\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tif (normalizedEdits[i].oldText.length === 0) {\n\t\t\tthrow getEmptyOldTextError(path, i, normalizedEdits.length);\n\t\t}\n\t}\n\n\tconst initialMatches = normalizedEdits.map((edit) => fuzzyFindText(normalizedContent, edit.oldText));\n\tconst usedFuzzyMatch = initialMatches.some((match) => match.usedFuzzyMatch);\n\tconst replacementBaseContent = usedFuzzyMatch ? normalizeForFuzzyMatch(normalizedContent) : normalizedContent;\n\n\tconst matchedEdits: MatchedEdit[] = [];\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tconst edit = normalizedEdits[i];\n\t\tconst matchResult = fuzzyFindText(replacementBaseContent, edit.oldText);\n\t\tif (!matchResult.found) {\n\t\t\tthrow getNotFoundError(path, i, normalizedEdits.length);\n\t\t}\n\n\t\tconst occurrences = countOccurrences(replacementBaseContent, edit.oldText);\n\t\tif (occurrences > 1) {\n\t\t\tthrow getDuplicateError(path, i, normalizedEdits.length, occurrences);\n\t\t}\n\n\t\tmatchedEdits.push({\n\t\t\teditIndex: i,\n\t\t\tmatchIndex: matchResult.index,\n\t\t\tmatchLength: matchResult.matchLength,\n\t\t\tnewText: edit.newText,\n\t\t});\n\t}\n\n\tmatchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);\n\tfor (let i = 1; i < matchedEdits.length; i++) {\n\t\tconst previous = matchedEdits[i - 1];\n\t\tconst current = matchedEdits[i];\n\t\tif (previous.matchIndex + previous.matchLength > current.matchIndex) {\n\t\t\tthrow new Error(\n\t\t\t\t`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst baseContent = normalizedContent;\n\tconst newContent = usedFuzzyMatch\n\t\t? applyReplacementsPreservingUnchangedLines(normalizedContent, replacementBaseContent, matchedEdits)\n\t\t: applyReplacements(replacementBaseContent, matchedEdits);\n\n\tif (baseContent === newContent) {\n\t\tthrow getNoChangeError(path, normalizedEdits.length);\n\t}\n\n\treturn { baseContent, newContent };\n}\n\n/** Generate a standard unified patch. */\nexport function generateUnifiedPatch(path: string, oldContent: string, newContent: string, contextLines = 4): string {\n\treturn Diff.createTwoFilesPatch(path, path, oldContent, newContent, undefined, undefined, {\n\t\tcontext: contextLines,\n\t\theaderOptions: Diff.FILE_HEADERS_ONLY,\n\t});\n}\n\n/**\n * Generate a display-oriented diff string with line numbers and context.\n * Returns both the diff string and the first changed line number (in the new file).\n */\nexport function generateDiffString(\n\toldContent: string,\n\tnewContent: string,\n\tcontextLines = 4,\n): { diff: string; firstChangedLine: number | undefined } {\n\tconst parts = Diff.diffLines(oldContent, newContent);\n\tconst output: string[] = [];\n\n\tconst oldLines = oldContent.split(\"\\n\");\n\tconst newLines = newContent.split(\"\\n\");\n\tconst maxLineNum = Math.max(oldLines.length, newLines.length);\n\tconst lineNumWidth = String(maxLineNum).length;\n\n\tlet oldLineNum = 1;\n\tlet newLineNum = 1;\n\tlet lastWasChange = false;\n\tlet firstChangedLine: number | undefined;\n\n\tfor (let i = 0; i < parts.length; i++) {\n\t\tconst part = parts[i];\n\t\tconst raw = part.value.split(\"\\n\");\n\t\tif (raw[raw.length - 1] === \"\") {\n\t\t\traw.pop();\n\t\t}\n\n\t\tif (part.added || part.removed) {\n\t\t\t// Capture the first changed line (in the new file)\n\t\t\tif (firstChangedLine === undefined) {\n\t\t\t\tfirstChangedLine = newLineNum;\n\t\t\t}\n\n\t\t\t// Show the change\n\t\t\tfor (const line of raw) {\n\t\t\t\tif (part.added) {\n\t\t\t\t\tconst lineNum = String(newLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(`+${lineNum} ${line}`);\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t} else {\n\t\t\t\t\t// removed\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(`-${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlastWasChange = true;\n\t\t} else {\n\t\t\t// Context lines - only show a few before/after changes\n\t\t\tconst nextPartIsChange = i < parts.length - 1 && (parts[i + 1].added || parts[i + 1].removed);\n\t\t\tconst hasLeadingChange = lastWasChange;\n\t\t\tconst hasTrailingChange = nextPartIsChange;\n\n\t\t\tif (hasLeadingChange && hasTrailingChange) {\n\t\t\t\tif (raw.length <= contextLines * 2) {\n\t\t\t\t\tfor (const line of raw) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst leadingLines = raw.slice(0, contextLines);\n\t\t\t\t\tconst trailingLines = raw.slice(raw.length - contextLines);\n\t\t\t\t\tconst skippedLines = raw.length - leadingLines.length - trailingLines.length;\n\n\t\t\t\t\tfor (const line of leadingLines) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\n\t\t\t\t\tfor (const line of trailingLines) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (hasLeadingChange) {\n\t\t\t\tconst shownLines = raw.slice(0, contextLines);\n\t\t\t\tconst skippedLines = raw.length - shownLines.length;\n\n\t\t\t\tfor (const line of shownLines) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\n\t\t\t\tif (skippedLines > 0) {\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\t\t\t\t}\n\t\t\t} else if (hasTrailingChange) {\n\t\t\t\tconst skippedLines = Math.max(0, raw.length - contextLines);\n\t\t\t\tif (skippedLines > 0) {\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\t\t\t\t}\n\n\t\t\t\tfor (const line of raw.slice(skippedLines)) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Skip these context lines entirely\n\t\t\t\toldLineNum += raw.length;\n\t\t\t\tnewLineNum += raw.length;\n\t\t\t}\n\n\t\t\tlastWasChange = false;\n\t\t}\n\t}\n\n\treturn { diff: output.join(\"\\n\"), firstChangedLine };\n}\n"]}
|