@code-yeongyu/senpi-agent-core 2026.9.12 → 2026.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/harness/agent-harness.d.ts +639 -384
- package/dist/harness/agent-harness.d.ts.map +1 -1
- package/dist/harness/agent-harness.js +5 -250
- package/dist/harness/agent-harness.js.map +1 -1
- package/dist/harness/compaction/branch-summarization.d.ts +12 -6
- package/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/harness/compaction/branch-summarization.js +33 -27
- package/dist/harness/compaction/branch-summarization.js.map +1 -1
- package/dist/harness/compaction/compaction.d.ts +30 -8
- package/dist/harness/compaction/compaction.d.ts.map +1 -1
- package/dist/harness/compaction/compaction.js +53 -64
- package/dist/harness/compaction/compaction.js.map +1 -1
- package/dist/harness/config.d.ts +9 -0
- package/dist/harness/config.d.ts.map +1 -0
- package/dist/harness/config.js +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 +25 -28
- package/dist/harness/env/nodejs.d.ts.map +1 -1
- package/dist/harness/env/nodejs.js +368 -125
- package/dist/harness/env/nodejs.js.map +1 -1
- package/dist/harness/events.d.ts +20 -38
- package/dist/harness/events.d.ts.map +1 -1
- package/dist/harness/events.js +233 -55
- package/dist/harness/events.js.map +1 -1
- package/dist/harness/execution/assistant.d.ts +42 -0
- package/dist/harness/execution/assistant.d.ts.map +1 -0
- package/dist/harness/execution/assistant.js +82 -0
- package/dist/harness/execution/assistant.js.map +1 -0
- package/dist/harness/execution/effect-gate.d.ts +22 -0
- package/dist/harness/execution/effect-gate.d.ts.map +1 -0
- package/dist/harness/execution/effect-gate.js +48 -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 +404 -0
- package/dist/harness/hooks.js.map +1 -0
- package/dist/harness/messages.d.ts +2 -2
- package/dist/harness/messages.d.ts.map +1 -1
- package/dist/harness/messages.js.map +1 -1
- package/dist/harness/prompt-templates.d.ts +3 -2
- package/dist/harness/prompt-templates.d.ts.map +1 -1
- package/dist/harness/prompt-templates.js +17 -17
- package/dist/harness/prompt-templates.js.map +1 -1
- package/dist/harness/result.d.ts +93 -0
- package/dist/harness/result.d.ts.map +1 -1
- package/dist/harness/result.js +39 -0
- package/dist/harness/result.js.map +1 -1
- package/dist/harness/runtime/drive/boundary.d.ts +28 -0
- package/dist/harness/runtime/drive/boundary.d.ts.map +1 -0
- package/dist/harness/runtime/drive/boundary.js +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 +302 -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 +118 -0
- package/dist/harness/runtime/lane.d.ts.map +1 -0
- package/dist/harness/runtime/lane.js +1559 -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 +50 -0
- package/dist/harness/runtime/types.js.map +1 -0
- package/dist/harness/session/commit.d.ts +53 -0
- package/dist/harness/session/commit.d.ts.map +1 -0
- package/dist/harness/session/commit.js +57 -0
- package/dist/harness/session/commit.js.map +1 -0
- package/dist/harness/session/context.d.ts +6 -19
- package/dist/harness/session/context.d.ts.map +1 -1
- package/dist/harness/session/context.js +31 -53
- package/dist/harness/session/context.js.map +1 -1
- 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 +269 -0
- package/dist/harness/session/in-memory-storage-state.js.map +1 -0
- package/dist/harness/session/index.d.ts +9 -5
- package/dist/harness/session/index.d.ts.map +1 -1
- package/dist/harness/session/index.js +7 -4
- package/dist/harness/session/index.js.map +1 -1
- package/dist/harness/session/jsonl/codec.d.ts +19 -8
- package/dist/harness/session/jsonl/codec.d.ts.map +1 -1
- package/dist/harness/session/jsonl/codec.js +34 -219
- package/dist/harness/session/jsonl/codec.js.map +1 -1
- 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 +266 -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 +44 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts.map +1 -0
- package/dist/harness/session/jsonl/legacy-v3.js +454 -0
- package/dist/harness/session/jsonl/legacy-v3.js.map +1 -0
- package/dist/harness/session/jsonl/repo.d.ts +27 -24
- package/dist/harness/session/jsonl/repo.d.ts.map +1 -1
- package/dist/harness/session/jsonl/repo.js +276 -151
- package/dist/harness/session/jsonl/repo.js.map +1 -1
- package/dist/harness/session/jsonl/storage.d.ts +39 -41
- package/dist/harness/session/jsonl/storage.d.ts.map +1 -1
- package/dist/harness/session/jsonl/storage.js +175 -196
- package/dist/harness/session/jsonl/storage.js.map +1 -1
- package/dist/harness/session/jsonl/types.d.ts +23 -22
- package/dist/harness/session/jsonl/types.d.ts.map +1 -1
- package/dist/harness/session/jsonl/types.js +2 -1
- package/dist/harness/session/jsonl/types.js.map +1 -1
- package/dist/harness/session/memory.d.ts +44 -40
- package/dist/harness/session/memory.d.ts.map +1 -1
- package/dist/harness/session/memory.js +333 -115
- package/dist/harness/session/memory.js.map +1 -1
- package/dist/harness/session/mutation-line.d.ts +8 -0
- package/dist/harness/session/mutation-line.d.ts.map +1 -0
- package/dist/harness/session/mutation-line.js +22 -0
- package/dist/harness/session/mutation-line.js.map +1 -0
- package/dist/harness/session/session.d.ts +78 -51
- package/dist/harness/session/session.d.ts.map +1 -1
- package/dist/harness/session/session.js +327 -207
- package/dist/harness/session/session.js.map +1 -1
- package/dist/harness/session/testing/benchmark/datasets.d.ts +12 -0
- package/dist/harness/session/testing/benchmark/datasets.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/datasets.js +24 -0
- package/dist/harness/session/testing/benchmark/datasets.js.map +1 -0
- package/dist/harness/session/testing/benchmark/session-repo.d.ts +42 -0
- package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/session-repo.js +127 -0
- package/dist/harness/session/testing/benchmark/session-repo.js.map +1 -0
- package/dist/harness/session/testing/benchmark/storage.d.ts +25 -0
- package/dist/harness/session/testing/benchmark/storage.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/storage.js +114 -0
- package/dist/harness/session/testing/benchmark/storage.js.map +1 -0
- package/dist/harness/session/testing/conformance/session-repo.d.ts +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 +103 -0
- package/dist/harness/session/testing/gating-storage.js.map +1 -0
- package/dist/harness/session/testing/index.d.ts +9 -2
- package/dist/harness/session/testing/index.d.ts.map +1 -1
- package/dist/harness/session/testing/index.js +8 -1
- package/dist/harness/session/testing/index.js.map +1 -1
- package/dist/harness/session/testing/instrumented-storage.d.ts +11 -0
- package/dist/harness/session/testing/instrumented-storage.d.ts.map +1 -0
- package/dist/harness/session/testing/instrumented-storage.js +19 -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 +40 -0
- package/dist/harness/session/testing/storage-decorator.js.map +1 -0
- package/dist/harness/session/testing/types.d.ts +5 -7
- package/dist/harness/session/testing/types.d.ts.map +1 -1
- package/dist/harness/session/testing/types.js.map +1 -1
- package/dist/harness/session/types.d.ts +425 -265
- 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/session/values.d.ts +95 -0
- package/dist/harness/session/values.d.ts.map +1 -0
- package/dist/harness/session/values.js +81 -0
- package/dist/harness/session/values.js.map +1 -0
- package/dist/harness/skills.d.ts +3 -2
- package/dist/harness/skills.d.ts.map +1 -1
- package/dist/harness/skills.js +29 -26
- package/dist/harness/skills.js.map +1 -1
- package/dist/harness/telemetry.d.ts +64 -43
- package/dist/harness/telemetry.d.ts.map +1 -1
- package/dist/harness/telemetry.js +45 -26
- package/dist/harness/telemetry.js.map +1 -1
- package/dist/harness/tools/bash.d.ts +4 -4
- package/dist/harness/tools/bash.d.ts.map +1 -1
- package/dist/harness/tools/bash.js +66 -93
- package/dist/harness/tools/bash.js.map +1 -1
- package/dist/harness/tools/edit.d.ts.map +1 -1
- package/dist/harness/tools/edit.js +17 -13
- package/dist/harness/tools/edit.js.map +1 -1
- package/dist/harness/tools/file-mutation-queue.d.ts +2 -1
- package/dist/harness/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/harness/tools/file-mutation-queue.js +5 -5
- package/dist/harness/tools/file-mutation-queue.js.map +1 -1
- package/dist/harness/tools/path-utils.d.ts +3 -2
- package/dist/harness/tools/path-utils.d.ts.map +1 -1
- package/dist/harness/tools/path-utils.js +5 -5
- package/dist/harness/tools/path-utils.js.map +1 -1
- package/dist/harness/tools/read.d.ts +2 -1
- package/dist/harness/tools/read.d.ts.map +1 -1
- package/dist/harness/tools/read.js +4 -6
- package/dist/harness/tools/read.js.map +1 -1
- package/dist/harness/tools/write.d.ts.map +1 -1
- package/dist/harness/tools/write.js +12 -8
- package/dist/harness/tools/write.js.map +1 -1
- package/dist/harness/types.d.ts +128 -45
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/utils/adaptive-publisher.d.ts +24 -0
- package/dist/harness/utils/adaptive-publisher.d.ts.map +1 -0
- package/dist/harness/utils/adaptive-publisher.js +79 -0
- package/dist/harness/utils/adaptive-publisher.js.map +1 -0
- package/dist/harness/utils/output-capture.d.ts +31 -0
- package/dist/harness/utils/output-capture.d.ts.map +1 -0
- package/dist/harness/utils/output-capture.js +217 -0
- package/dist/harness/utils/output-capture.js.map +1 -0
- package/dist/harness/utils/shell-output.d.ts +19 -5
- package/dist/harness/utils/shell-output.d.ts.map +1 -1
- package/dist/harness/utils/shell-output.js +65 -192
- package/dist/harness/utils/shell-output.js.map +1 -1
- package/dist/harness/utils/truncate.d.ts +1 -0
- package/dist/harness/utils/truncate.d.ts.map +1 -1
- package/dist/harness/utils/truncate.js +1 -1
- package/dist/harness/utils/truncate.js.map +1 -1
- package/dist/harness/utils/usage.d.ts +4 -0
- package/dist/harness/utils/usage.d.ts.map +1 -0
- package/dist/harness/utils/usage.js +33 -0
- package/dist/harness/utils/usage.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/dist/search/index.d.ts +24 -16
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +1 -1
- package/dist/search/index.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +27 -6
- package/dist/harness/reducer.d.ts +0 -100
- package/dist/harness/reducer.d.ts.map +0 -1
- package/dist/harness/reducer.js +0 -420
- package/dist/harness/reducer.js.map +0 -1
- package/dist/harness/session/jsonl/errors.d.ts +0 -9
- package/dist/harness/session/jsonl/errors.d.ts.map +0 -1
- package/dist/harness/session/jsonl/errors.js +0 -18
- package/dist/harness/session/jsonl/errors.js.map +0 -1
- package/dist/harness/session/jsonl.d.ts +0 -3
- package/dist/harness/session/jsonl.d.ts.map +0 -1
- package/dist/harness/session/jsonl.js +0 -2
- package/dist/harness/session/jsonl.js.map +0 -1
- package/dist/harness/session/state.d.ts +0 -65
- package/dist/harness/session/state.d.ts.map +0 -1
- package/dist/harness/session/state.js +0 -320
- package/dist/harness/session/state.js.map +0 -1
- package/dist/harness/session/testing/conformance.d.ts +0 -4
- package/dist/harness/session/testing/conformance.d.ts.map +0 -1
- package/dist/harness/session/testing/conformance.js +0 -762
- package/dist/harness/session/testing/conformance.js.map +0 -1
- package/dist/search/scanning.d.ts +0 -29
- package/dist/search/scanning.d.ts.map +0 -1
- package/dist/search/scanning.js +0 -103
- package/dist/search/scanning.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/harness/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,eAAe,EAAE,MAAM,cAAc,CAAC;AAE7D,O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GAAG,CAAC,KAAK,aAAa;oBAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC;YAC3E,CAAC;YACD,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,KAAK,CAAC;gBAAE,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC;iBACtF,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,KAAK,CAAC;gBAAE,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACxE,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import type { HookHandler, HookInvocation, HookMap, HookName, Hooks } from \"./agent-harness.ts\";\nimport { type Context, withAbortSignal } from \"./context.ts\";\nimport type { Gate } from \"./execution/effect-gate.ts\";\nimport { startHarnessSpan } from \"./telemetry.ts\";\nimport type { AgentHarnessStreamOptions, AgentHarnessStreamOptionsPatch } from \"./types.ts\";\n\ninterface HookRegistration {\n\tid?: string;\n\thandler: (event: unknown, context: Context) => unknown | Promise<unknown>;\n}\n\ntype HookErrorReporter = (error: Error, hook: HookName, lane: string, context: Context) => void | Promise<void>;\n\n/** Ordered harness hook registry and aggregate runner. */\nexport class HookRegistry implements Hooks {\n\tprivate readonly registrations = new Map<HookName, HookRegistration[]>();\n\tprivate readonly reportError: HookErrorReporter;\n\tprivate closedError: Error | undefined;\n\n\tconstructor(reportError: HookErrorReporter) {\n\t\tthis.reportError = reportError;\n\t}\n\n\ton<TName extends HookName>(name: TName, handler: HookHandler<TName>, options: { id?: string } = {}): () => void {\n\t\tif (this.closedError !== undefined) throw this.closedError;\n\t\tconst registrations = this.registrations.get(name) ?? [];\n\t\tconst registration: HookRegistration = {\n\t\t\t...(options.id === undefined ? {} : { id: options.id }),\n\t\t\thandler: (event, context) => handler(event as HookInvocation<TName>, context),\n\t\t};\n\t\tregistrations.push(registration);\n\t\tthis.registrations.set(name, registrations);\n\t\treturn () => {\n\t\t\tconst index = registrations.indexOf(registration);\n\t\t\tif (index !== -1) registrations.splice(index, 1);\n\t\t};\n\t}\n\n\thas(name: HookName): boolean {\n\t\treturn (this.registrations.get(name)?.length ?? 0) !== 0;\n\t}\n\n\t/** Invoke one accepted-operation aggregate after synchronously passing its effect gate. */\n\trunWithGate<TName extends HookName>(\n\t\tname: TName,\n\t\tevent: HookInvocation<TName>,\n\t\tgate: Gate,\n\t\tcontext: Context,\n\t): Promise<HookMap[TName][\"result\"]> {\n\t\treturn gate.admit(() => {\n\t\t\tconst admittedContext = withAbortSignal(gate.signal, context);\n\t\t\tadmittedContext.abortSignal?.throwIfAborted();\n\t\t\treturn this.runAdmitted(name, event, admittedContext);\n\t\t});\n\t}\n\n\t/** Invoke a tool-hook aggregate with one telemetry span per registered handler. */\n\trunToolWithGate<TName extends \"before_tool\" | \"after_tool\">(\n\t\tname: TName,\n\t\tevent: HookInvocation<TName>,\n\t\tgate: Gate,\n\t\tcontext: Context,\n\t): Promise<HookMap[TName][\"result\"]> {\n\t\treturn gate.admit(() => {\n\t\t\tconst admittedContext = withAbortSignal(gate.signal, context);\n\t\t\tadmittedContext.abortSignal?.throwIfAborted();\n\t\t\treturn (\n\t\t\t\tname === \"before_tool\"\n\t\t\t\t\t? this.beforeTool(event as HookInvocation<\"before_tool\">, admittedContext)\n\t\t\t\t\t: this.afterTool(event as HookInvocation<\"after_tool\">, admittedContext)\n\t\t\t) as Promise<HookMap[TName][\"result\"]>;\n\t\t});\n\t}\n\n\tclose(error: Error): void {\n\t\tthis.closedError ??= error;\n\t}\n\n\tprivate async runAdmitted<TName extends HookName>(\n\t\tname: TName,\n\t\tevent: HookInvocation<TName>,\n\t\tcontext: Context,\n\t): Promise<HookMap[TName][\"result\"]> {\n\t\tif (this.closedError !== undefined) throw this.closedError;\n\t\tconst result = await this.aggregate(name, event, context);\n\t\treturn result as HookMap[TName][\"result\"];\n\t}\n\n\tprivate async aggregate(name: HookName, event: HookInvocation<HookName>, context: Context): Promise<unknown> {\n\t\tswitch (name) {\n\t\t\tcase \"before_run\":\n\t\t\t\treturn this.beforeRun(event as HookInvocation<\"before_run\">, context);\n\t\t\tcase \"before_drive\":\n\t\t\t\tawait this.invokeAllFailClosed(name, event as HookInvocation<\"before_drive\">, context);\n\t\t\t\treturn undefined;\n\t\t\tcase \"before_run_end\": {\n\t\t\t\tlet followUp: string | undefined;\n\t\t\t\tawait this.invokeAll(\n\t\t\t\t\tname,\n\t\t\t\t\tevent,\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tconst result = value as HookMap[\"before_run_end\"][\"result\"];\n\t\t\t\t\t\tif (result?.followUp !== undefined) followUp = result.followUp;\n\t\t\t\t\t},\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t\treturn followUp === undefined ? undefined : { followUp };\n\t\t\t}\n\t\t\tcase \"transform_context\":\n\t\t\t\treturn this.transformContext(event as HookInvocation<\"transform_context\">, context);\n\t\t\tcase \"before_request\":\n\t\t\t\treturn this.beforeRequest(event as HookInvocation<\"before_request\">, context);\n\t\t\tcase \"before_payload\":\n\t\t\t\treturn this.beforePayload(event as HookInvocation<\"before_payload\">, context);\n\t\t\tcase \"after_response\":\n\t\t\t\treturn this.afterResponse(event as HookInvocation<\"after_response\">, context);\n\t\t\tcase \"before_tool\":\n\t\t\t\treturn this.beforeTool(event as HookInvocation<\"before_tool\">, context);\n\t\t\tcase \"after_tool\":\n\t\t\t\treturn this.afterTool(event as HookInvocation<\"after_tool\">, context);\n\t\t\tcase \"before_compaction\":\n\t\t\t\treturn this.firstStructural(name, event as HookInvocation<\"before_compaction\">, \"compaction\", context);\n\t\t\tcase \"before_navigation\":\n\t\t\t\treturn this.firstStructural(name, event as HookInvocation<\"before_navigation\">, \"summary\", context);\n\t\t}\n\t}\n\n\tprivate async beforeRun(\n\t\tevent: HookInvocation<\"before_run\">,\n\t\tcontext: Context,\n\t): Promise<HookMap[\"before_run\"][\"result\"]> {\n\t\tlet prompt = event.prompt;\n\t\tlet injected: HookMap[\"before_run\"][\"event\"][\"prompt\"] = [];\n\t\tfor (const registration of this.registrationsFor(\"before_run\")) {\n\t\t\ttry {\n\t\t\t\tconst result = (await registration.handler(\n\t\t\t\t\t{ ...event, prompt },\n\t\t\t\t\tcontext,\n\t\t\t\t)) as HookMap[\"before_run\"][\"result\"];\n\t\t\t\tif (result?.messages !== undefined) {\n\t\t\t\t\tinjected = [...injected, ...result.messages];\n\t\t\t\t\tprompt = [...prompt, ...result.messages];\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tawait this.reportError(\n\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\"before_run\",\n\t\t\t\t\tevent.lane,\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn injected.length === 0 ? undefined : { messages: injected };\n\t}\n\n\tprivate async beforeTool(\n\t\tevent: HookInvocation<\"before_tool\">,\n\t\tcontext: Context,\n\t): Promise<HookMap[\"before_tool\"][\"result\"]> {\n\t\tlet args = event.args;\n\t\tlet block: { reason: string; terminate?: boolean } | undefined;\n\t\tfor (const registration of this.registrationsFor(\"before_tool\")) {\n\t\t\ttry {\n\t\t\t\tconst result = (await this.invokeToolRegistration(\n\t\t\t\t\t\"before_tool\",\n\t\t\t\t\tregistration,\n\t\t\t\t\t{ ...event, args },\n\t\t\t\t\tcontext,\n\t\t\t\t)) as HookMap[\"before_tool\"][\"result\"];\n\t\t\t\tif (result?.args !== undefined) args = result.args;\n\t\t\t\tif (result?.block !== undefined) {\n\t\t\t\t\tblock = result.block;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tconst normalized = error instanceof Error ? error : new Error(String(error));\n\t\t\t\tawait this.reportError(normalized, \"before_tool\", event.lane, context);\n\t\t\t\tblock = { reason: normalized.message };\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t...(args === event.args ? {} : { args }),\n\t\t\t...(block === undefined ? {} : { block }),\n\t\t};\n\t}\n\n\tprivate async transformContext(\n\t\tevent: HookInvocation<\"transform_context\">,\n\t\tcontext: Context,\n\t): Promise<HookMap[\"transform_context\"][\"result\"]> {\n\t\tlet messages = event.messages;\n\t\tlet systemPrompt = event.systemPrompt;\n\t\tfor (const registration of this.registrationsFor(\"transform_context\")) {\n\t\t\ttry {\n\t\t\t\tconst result = (await registration.handler(\n\t\t\t\t\t{\n\t\t\t\t\t\t...event,\n\t\t\t\t\t\tmessages,\n\t\t\t\t\t\tsystemPrompt,\n\t\t\t\t\t},\n\t\t\t\t\tcontext,\n\t\t\t\t)) as HookMap[\"transform_context\"][\"result\"];\n\t\t\t\tif (result?.messages !== undefined) messages = result.messages;\n\t\t\t\tif (result?.systemPrompt !== undefined) systemPrompt = result.systemPrompt;\n\t\t\t} catch (error) {\n\t\t\t\tawait this.reportError(\n\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\"transform_context\",\n\t\t\t\t\tevent.lane,\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn { messages, systemPrompt };\n\t}\n\n\tprivate async beforeRequest(\n\t\tevent: HookInvocation<\"before_request\">,\n\t\tcontext: Context,\n\t): Promise<HookMap[\"before_request\"][\"result\"]> {\n\t\tlet streamOptions = event.streamOptions;\n\t\tlet changed = false;\n\t\tfor (const registration of this.registrationsFor(\"before_request\")) {\n\t\t\ttry {\n\t\t\t\tconst result = (await registration.handler(\n\t\t\t\t\t{ ...event, streamOptions },\n\t\t\t\t\tcontext,\n\t\t\t\t)) as HookMap[\"before_request\"][\"result\"];\n\t\t\t\tif (result?.streamOptions !== undefined) {\n\t\t\t\t\tstreamOptions = applyStreamOptionsPatch(streamOptions, result.streamOptions);\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tawait this.reportError(\n\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\"before_request\",\n\t\t\t\t\tevent.lane,\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn changed ? { streamOptions: createStreamOptionsPatch(event.streamOptions, streamOptions) } : undefined;\n\t}\n\n\tprivate async beforePayload(\n\t\tevent: HookInvocation<\"before_payload\">,\n\t\tcontext: Context,\n\t): Promise<HookMap[\"before_payload\"][\"result\"]> {\n\t\tlet payload = event.payload;\n\t\tfor (const registration of this.registrationsFor(\"before_payload\")) {\n\t\t\ttry {\n\t\t\t\tconst result = (await registration.handler(\n\t\t\t\t\t{ ...event, payload },\n\t\t\t\t\tcontext,\n\t\t\t\t)) as HookMap[\"before_payload\"][\"result\"];\n\t\t\t\tif (result?.payload !== undefined) payload = result.payload;\n\t\t\t} catch (error) {\n\t\t\t\tawait this.reportError(\n\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\"before_payload\",\n\t\t\t\t\tevent.lane,\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn { payload };\n\t}\n\n\tprivate async afterResponse(\n\t\tevent: HookInvocation<\"after_response\">,\n\t\tcontext: Context,\n\t): Promise<HookMap[\"after_response\"][\"result\"]> {\n\t\tlet message = event.message;\n\t\tfor (const registration of this.registrationsFor(\"after_response\")) {\n\t\t\ttry {\n\t\t\t\tconst result = (await registration.handler(\n\t\t\t\t\t{ ...event, message },\n\t\t\t\t\tcontext,\n\t\t\t\t)) as HookMap[\"after_response\"][\"result\"];\n\t\t\t\tif (result?.message !== undefined) message = result.message;\n\t\t\t} catch (error) {\n\t\t\t\tawait this.reportError(\n\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\"after_response\",\n\t\t\t\t\tevent.lane,\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn { message };\n\t}\n\n\tprivate async afterTool(\n\t\tevent: HookInvocation<\"after_tool\">,\n\t\tcontext: Context,\n\t): Promise<HookMap[\"after_tool\"][\"result\"]> {\n\t\tlet current = {\n\t\t\tcontent: event.content,\n\t\t\tdetails: event.details,\n\t\t\tisError: event.isError,\n\t\t\tusage: event.usage,\n\t\t};\n\t\tconst aggregate: NonNullable<HookMap[\"after_tool\"][\"result\"]> = {};\n\t\tfor (const registration of this.registrationsFor(\"after_tool\")) {\n\t\t\ttry {\n\t\t\t\tconst result = (await this.invokeToolRegistration(\n\t\t\t\t\t\"after_tool\",\n\t\t\t\t\tregistration,\n\t\t\t\t\t{ ...event, ...current },\n\t\t\t\t\tcontext,\n\t\t\t\t)) as HookMap[\"after_tool\"][\"result\"];\n\t\t\t\tif (result === undefined) continue;\n\t\t\t\tif (result.content !== undefined) aggregate.content = result.content;\n\t\t\t\tif (result.details !== undefined) aggregate.details = result.details;\n\t\t\t\tif (result.isError !== undefined) aggregate.isError = result.isError;\n\t\t\t\tif (result.usage !== undefined) aggregate.usage = result.usage;\n\t\t\t\tif (result.terminate !== undefined) aggregate.terminate = result.terminate;\n\t\t\t\tcurrent = {\n\t\t\t\t\tcontent: result.content === undefined ? current.content : result.content,\n\t\t\t\t\tdetails: result.details === undefined ? current.details : result.details,\n\t\t\t\t\tisError: result.isError === undefined ? current.isError : result.isError,\n\t\t\t\t\tusage: result.usage === undefined ? current.usage : result.usage,\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tawait this.reportError(\n\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\"after_tool\",\n\t\t\t\t\tevent.lane,\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn Object.keys(aggregate).length === 0 ? undefined : aggregate;\n\t}\n\n\tprivate async firstStructural(\n\t\tname: \"before_compaction\" | \"before_navigation\",\n\t\tevent: HookInvocation<\"before_compaction\"> | HookInvocation<\"before_navigation\">,\n\t\tresultField: \"compaction\" | \"summary\",\n\t\tcontext: Context,\n\t): Promise<unknown> {\n\t\tfor (const registration of this.registrationsFor(name)) {\n\t\t\ttry {\n\t\t\t\tconst value = await registration.handler(event, context);\n\t\t\t\tif (value === undefined || value === null || typeof value !== \"object\") continue;\n\t\t\t\tconst result = value as Record<string, unknown>;\n\t\t\t\tif (result.decline === true && result[resultField] !== undefined) {\n\t\t\t\t\tawait this.reportError(\n\t\t\t\t\t\tnew Error(`${name} hook cannot return both decline and ${resultField}`),\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tevent.lane,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (result.decline === true || result[resultField] !== undefined) return value;\n\t\t\t} catch (error) {\n\t\t\t\tawait this.reportError(\n\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\tname,\n\t\t\t\t\tevent.lane,\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate invokeToolRegistration(\n\t\tname: \"before_tool\" | \"after_tool\",\n\t\tregistration: HookRegistration,\n\t\tevent: HookInvocation<\"before_tool\"> | HookInvocation<\"after_tool\">,\n\t\tcontext: Context,\n\t): Promise<unknown> {\n\t\treturn startHarnessSpan(\n\t\t\t\"pi.harness.hook\",\n\t\t\t{\n\t\t\t\t\"pi.lane.name\": event.lane,\n\t\t\t\t\"pi.operation.id\": event.runId,\n\t\t\t\t\"pi.hook.name\": name,\n\t\t\t\t...(registration.id === undefined ? {} : { \"pi.hook.registration_id\": registration.id }),\n\t\t\t},\n\t\t\tasync (span, spanContext) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await registration.handler(event, spanContext);\n\t\t\t\t\tconst blocked =\n\t\t\t\t\t\tname === \"before_tool\" &&\n\t\t\t\t\t\tresult !== null &&\n\t\t\t\t\t\ttypeof result === \"object\" &&\n\t\t\t\t\t\t\"block\" in result &&\n\t\t\t\t\t\tresult.block !== undefined;\n\t\t\t\t\tspan.setAttributes({ \"pi.hook.outcome\": blocked ? \"blocked\" : \"completed\" });\n\t\t\t\t\treturn result;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tspan.setAttributes({ \"pi.hook.outcome\": \"failed\" });\n\t\t\t\t\tspan.setStatus({ status: \"error\" });\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tprivate registrationsFor(name: HookName): HookRegistration[] {\n\t\treturn [...(this.registrations.get(name) ?? [])];\n\t}\n\n\tprivate async invokeAllFailClosed(\n\t\tname: \"before_drive\",\n\t\tevent: HookInvocation<\"before_drive\">,\n\t\tcontext: Context,\n\t): Promise<void> {\n\t\tfor (const registration of this.registrationsFor(name)) {\n\t\t\ttry {\n\t\t\t\tawait registration.handler(event, context);\n\t\t\t} catch (error) {\n\t\t\t\tconst normalized = error instanceof Error ? error : new Error(String(error));\n\t\t\t\tawait this.reportError(normalized, name, event.lane, context);\n\t\t\t\tthrow normalized;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async invokeAll(\n\t\tname: HookName,\n\t\tevent: HookInvocation<HookName>,\n\t\tapply: (value: unknown) => void,\n\t\tcontext: Context,\n\t): Promise<void> {\n\t\tfor (const registration of this.registrationsFor(name)) {\n\t\t\ttry {\n\t\t\t\tapply(await registration.handler(event, context));\n\t\t\t} catch (error) {\n\t\t\t\tawait this.reportError(\n\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\tname,\n\t\t\t\t\tevent.lane,\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function applyStreamOptionsPatch(\n\tbase: AgentHarnessStreamOptions,\n\tpatch: AgentHarnessStreamOptionsPatch,\n): AgentHarnessStreamOptions {\n\tconst next: AgentHarnessStreamOptions = { ...base };\n\tfor (const key of [\n\t\t\"transport\",\n\t\t\"timeoutMs\",\n\t\t\"maxRetries\",\n\t\t\"maxRetryDelayMs\",\n\t\t\"cacheRetention\",\n\t\t\"deferred\",\n\t] as const) {\n\t\tif (!(key in patch)) continue;\n\t\tconst value = patch[key];\n\t\tif (value === undefined) delete next[key];\n\t\telse Object.assign(next, { [key]: value });\n\t}\n\tif (\"headers\" in patch) {\n\t\tif (patch.headers === undefined) delete next.headers;\n\t\telse {\n\t\t\tconst headers = { ...next.headers };\n\t\t\tfor (const [key, value] of Object.entries(patch.headers)) {\n\t\t\t\tif (value === undefined) delete headers[key];\n\t\t\t\telse headers[key] = value;\n\t\t\t}\n\t\t\tnext.headers = headers;\n\t\t}\n\t}\n\tif (\"metadata\" in patch) {\n\t\tif (patch.metadata === undefined) delete next.metadata;\n\t\telse {\n\t\t\tconst metadata = { ...next.metadata };\n\t\t\tfor (const [key, value] of Object.entries(patch.metadata)) {\n\t\t\t\tif (value === undefined) delete metadata[key];\n\t\t\t\telse metadata[key] = value;\n\t\t\t}\n\t\t\tnext.metadata = metadata;\n\t\t}\n\t}\n\treturn next;\n}\n\nfunction createStreamOptionsPatch(\n\tbase: AgentHarnessStreamOptions,\n\tvalue: AgentHarnessStreamOptions,\n): AgentHarnessStreamOptionsPatch {\n\tconst patch: AgentHarnessStreamOptionsPatch = {};\n\tfor (const key of [\n\t\t\"transport\",\n\t\t\"timeoutMs\",\n\t\t\"maxRetries\",\n\t\t\"maxRetryDelayMs\",\n\t\t\"cacheRetention\",\n\t\t\"deferred\",\n\t] as const) {\n\t\tif (base[key] !== value[key]) Object.assign(patch, { [key]: value[key] });\n\t}\n\tif (base.headers !== value.headers) {\n\t\tif (value.headers === undefined) patch.headers = undefined;\n\t\telse {\n\t\t\tconst headers: Record<string, string | undefined> = {};\n\t\t\tfor (const key of Object.keys(base.headers ?? {})) {\n\t\t\t\tif (!(key in value.headers)) headers[key] = undefined;\n\t\t\t}\n\t\t\tfor (const [key, header] of Object.entries(value.headers)) {\n\t\t\t\tif (base.headers?.[key] !== header) headers[key] = header;\n\t\t\t}\n\t\t\tif (base.headers === undefined && Object.keys(headers).length === 0) patch.headers = {};\n\t\t\telse if (Object.keys(headers).length !== 0) patch.headers = headers;\n\t\t}\n\t}\n\tif (base.metadata !== value.metadata) {\n\t\tif (value.metadata === undefined) patch.metadata = undefined;\n\t\telse {\n\t\t\tconst metadata: Record<string, unknown | undefined> = {};\n\t\t\tfor (const key of Object.keys(base.metadata ?? {})) {\n\t\t\t\tif (!(key in value.metadata)) metadata[key] = undefined;\n\t\t\t}\n\t\t\tfor (const [key, metadataValue] of Object.entries(value.metadata)) {\n\t\t\t\tif (base.metadata?.[key] !== metadataValue) metadata[key] = metadataValue;\n\t\t\t}\n\t\t\tif (base.metadata === undefined && Object.keys(metadata).length === 0) patch.metadata = {};\n\t\t\telse if (Object.keys(metadata).length !== 0) patch.metadata = metadata;\n\t\t}\n\t}\n\treturn patch;\n}\n"]}
|
|
@@ -26,7 +26,7 @@ export interface CustomMessage<T = unknown> {
|
|
|
26
26
|
export interface BranchSummaryMessage {
|
|
27
27
|
role: "branchSummary";
|
|
28
28
|
summary: string;
|
|
29
|
-
fromId: string;
|
|
29
|
+
fromId: string | null;
|
|
30
30
|
timestamp: number;
|
|
31
31
|
}
|
|
32
32
|
export interface CompactionSummaryMessage {
|
|
@@ -45,7 +45,7 @@ declare module "../types.ts" {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
export declare function bashExecutionToText(msg: BashExecutionMessage): string;
|
|
48
|
-
export declare function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string | number): BranchSummaryMessage;
|
|
48
|
+
export declare function createBranchSummaryMessage(summary: string, fromId: string | null, timestamp: string | number): BranchSummaryMessage;
|
|
49
49
|
export declare function createCompactionSummaryMessage(summary: string, tokensBefore: number, timestamp: string | number): CompactionSummaryMessage;
|
|
50
50
|
export declare function createCustomMessage(customType: string, content: string | (TextContent | ImageContent)[], display: boolean, details: unknown | undefined, timestamp: string | number): CustomMessage;
|
|
51
51
|
export declare function convertToLlm(messages: AgentMessage[]): Message[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/harness/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,YAAY,EAAE,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,yBAAyB,wGAGrC,CAAC;AAEF,eAAO,MAAM,yBAAyB,iBAC3B,CAAC;AAEZ,eAAO,MAAM,qBAAqB,iGAGjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAElD,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,OAAO;IACzC,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,CAAC;IACjD,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,CAAC,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/harness/messages.ts"],"names":[],"mappings":"AAAA,OA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AS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,KAAK,mBAAmB;gBACvB,OAAO;oBACN,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACR,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,yBAAyB,GAAG,CAAC,CAAC,OAAO,GAAG,yBAAyB,EAAE;qBAClG;oBACD,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,KAAK,MAAM,CAAC;YACZ,KAAK,WAAW,CAAC;YACjB,KAAK,YAAY;gBAChB,OAAO,CAAC,CAAC;YACV;gBACC,OAAO,SAAS,CAAC;QACnB,CAAC;IACF,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAgB,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IAC/C,2EAA2E;IAC3E,oEAAoE;IACpE,kEAAkE;IAClE,OAAO,wBAAwB,CAAC,SAAS,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import { dropFailedAssistantTurns, type ImageContent, type Message, type TextContent } from \"@earendil-works/pi-ai\";\nimport type { AgentMessage } from \"../types.ts\";\n\nexport const COMPACTION_SUMMARY_PREFIX = `The conversation history before this point was compacted into the following summary:\n\n<summary>\n`;\n\nexport const COMPACTION_SUMMARY_SUFFIX = `\n</summary>`;\n\nexport const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;\n\nexport const BRANCH_SUMMARY_SUFFIX = `</summary>`;\n\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n\texcludeFromContext?: boolean;\n}\n\nexport interface CustomMessage<T = unknown> {\n\trole: \"custom\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdisplay: boolean;\n\tdetails?: T;\n\ttimestamp: number;\n}\n\nexport interface BranchSummaryMessage {\n\trole: \"branchSummary\";\n\tsummary: string;\n\tfromId: string | null;\n\ttimestamp: number;\n}\n\nexport interface CompactionSummaryMessage {\n\trole: \"compactionSummary\";\n\tsummary: string;\n\ttokensBefore: number;\n\tdetails?: unknown;\n\ttimestamp: number;\n}\n\ndeclare module \"../types.ts\" {\n\tinterface CustomAgentMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t\tcustom: CustomMessage;\n\t\tbranchSummary: BranchSummaryMessage;\n\t\tcompactionSummary: CompactionSummaryMessage;\n\t}\n}\n\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\nexport function createBranchSummaryMessage(\n\tsummary: string,\n\tfromId: string | null,\n\ttimestamp: string | number,\n): BranchSummaryMessage {\n\treturn {\n\t\trole: \"branchSummary\",\n\t\tsummary,\n\t\tfromId,\n\t\ttimestamp: typeof timestamp === \"number\" ? timestamp : new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCompactionSummaryMessage(\n\tsummary: string,\n\ttokensBefore: number,\n\ttimestamp: string | number,\n): CompactionSummaryMessage {\n\treturn {\n\t\trole: \"compactionSummary\",\n\t\tsummary,\n\t\ttokensBefore,\n\t\ttimestamp: typeof timestamp === \"number\" ? timestamp : new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCustomMessage(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: unknown | undefined,\n\ttimestamp: string | number,\n): CustomMessage {\n\treturn {\n\t\trole: \"custom\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\ttimestamp: typeof timestamp === \"number\" ? timestamp : new Date(timestamp).getTime(),\n\t};\n}\n\nexport function convertToLlm(messages: AgentMessage[]): Message[] {\n\tconst converted = messages\n\t\t.map((m): Message | undefined => {\n\t\t\tswitch (m.role) {\n\t\t\t\tcase \"bashExecution\":\n\t\t\t\t\tif (m.excludeFromContext) {\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"custom\": {\n\t\t\t\t\tconst content = typeof m.content === \"string\" ? [{ type: \"text\" as const, text: m.content }] : m.content;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase \"branchSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"compactionSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: COMPACTION_SUMMARY_PREFIX + m.summary + COMPACTION_SUMMARY_SUFFIX },\n\t\t\t\t\t\t],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"user\":\n\t\t\t\tcase \"assistant\":\n\t\t\t\tcase \"toolResult\":\n\t\t\t\t\treturn m;\n\t\t\t\tdefault:\n\t\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})\n\t\t.filter((m): m is Message => m !== undefined);\n\t// Failed provider turns (stopReason error/aborted) must not be replayed by\n\t// any lane that builds an LLM request from this output; dropping is\n\t// deterministic, so earlier requests stay a prefix of later ones.\n\treturn dropFailedAssistantTurns(converted);\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Context } from "./context.ts";
|
|
1
2
|
import { type ExecutionEnv, type PromptTemplate } from "./types.ts";
|
|
2
3
|
export type PromptTemplateDiagnosticCode = "file_info_failed" | "list_failed" | "read_failed" | "parse_failed";
|
|
3
4
|
/** Warning produced while loading prompt templates. */
|
|
@@ -17,7 +18,7 @@ export interface PromptTemplateDiagnostic {
|
|
|
17
18
|
* Directory inputs load direct `.md` children non-recursively. File inputs load explicit `.md` files. Missing paths and
|
|
18
19
|
* non-markdown files are skipped. Read and parse failures are returned as diagnostics.
|
|
19
20
|
*/
|
|
20
|
-
export declare function loadPromptTemplates(env: ExecutionEnv, paths: string | string[]): Promise<{
|
|
21
|
+
export declare function loadPromptTemplates(env: ExecutionEnv, paths: string | string[], context: Context): Promise<{
|
|
21
22
|
promptTemplates: PromptTemplate[];
|
|
22
23
|
diagnostics: PromptTemplateDiagnostic[];
|
|
23
24
|
}>;
|
|
@@ -30,7 +31,7 @@ export declare function loadPromptTemplates(env: ExecutionEnv, paths: string | s
|
|
|
30
31
|
export declare function loadSourcedPromptTemplates<TSource, TPromptTemplate extends PromptTemplate = PromptTemplate>(env: ExecutionEnv, inputs: Array<{
|
|
31
32
|
path: string;
|
|
32
33
|
source: TSource;
|
|
33
|
-
}>, mapPromptTemplate
|
|
34
|
+
}>, mapPromptTemplate: ((promptTemplate: PromptTemplate, source: TSource, context: Context) => TPromptTemplate) | undefined, context: Context): Promise<{
|
|
34
35
|
promptTemplates: Array<{
|
|
35
36
|
promptTemplate: TPromptTemplate;
|
|
36
37
|
source: TSource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-templates.d.ts","sourceRoot":"","sources":["../../src/harness/prompt-templates.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAiB,KAAK,cAAc,EAAwB,MAAM,YAAY,CAAC;AAEzG,MAAM,MAAM,4BAA4B,GAAG,kBAAkB,GAAG,aAAa,GAAG,aAAa,GAAG,cAAc,CAAC;AAE/G,uDAAuD;AACvD,MAAM,WAAW,wBAAwB;IACxC,gEAAgE;IAChE,IAAI,EAAE,SAAS,CAAC;IAChB,8BAA8B;IAC9B,IAAI,EAAE,4BAA4B,CAAC;IACnC,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;CACb;AAQD;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACxC,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"prompt-templates.d.ts","sourceRoot":"","sources":["../../src/harness/prompt-templates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,KAAK,YAAY,EAAiB,KAAK,cAAc,EAAwB,MAAM,YAAY,CAAC;AAEzG,MAAM,MAAM,4BAA4B,GAAG,kBAAkB,GAAG,aAAa,GAAG,aAAa,GAAG,cAAc,CAAC;AAE/G,uDAAuD;AACvD,MAAM,WAAW,wBAAwB;IACxC,gEAAgE;IAChE,IAAI,EAAE,SAAS,CAAC;IAChB,8BAA8B;IAC9B,IAAI,EAAE,4BAA4B,CAAC;IACnC,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;CACb;AAQD;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACxC,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EACxB,OAAO,EAAE,OAAO,GACd,OAAO,CAAC;IAAE,eAAe,EAAE,cAAc,EAAE,CAAC;IAAC,WAAW,EAAE,wBAAwB,EAAE,CAAA;CAAE,CAAC,CA6BzF;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,EAAE,eAAe,SAAS,cAAc,GAAG,cAAc,EAChH,GAAG,EAAE,YAAY,EACjB,MAAM,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC,EAChD,iBAAiB,EACd,CAAC,CAAC,cAAc,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,eAAe,CAAC,GACxF,SAAS,EACZ,OAAO,EAAE,OAAO,GACd,OAAO,CAAC;IACV,eAAe,EAAE,KAAK,CAAC;QAAE,cAAc,EAAE,eAAe,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC7E,WAAW,EAAE,KAAK,CAAC,wBAAwB,GAAG;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CACnE,CAAC,CAgBD;AA+HD,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAuB7D;AAED,uHAAuH;AACvH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAatE;AAED,qEAAqE;AACrE,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,cAAc,EAAE,IAAI,GAAE,MAAM,EAAO,GAAG,MAAM,CAEpG"}
|
|
@@ -6,11 +6,11 @@ import { toError } from "./types.js";
|
|
|
6
6
|
* Directory inputs load direct `.md` children non-recursively. File inputs load explicit `.md` files. Missing paths and
|
|
7
7
|
* non-markdown files are skipped. Read and parse failures are returned as diagnostics.
|
|
8
8
|
*/
|
|
9
|
-
export async function loadPromptTemplates(env, paths) {
|
|
9
|
+
export async function loadPromptTemplates(env, paths, context) {
|
|
10
10
|
const promptTemplates = [];
|
|
11
11
|
const diagnostics = [];
|
|
12
12
|
for (const path of Array.isArray(paths) ? paths : [paths]) {
|
|
13
|
-
const infoResult = await env.fileInfo(path);
|
|
13
|
+
const infoResult = await env.fileInfo(path, context);
|
|
14
14
|
if (!infoResult.ok) {
|
|
15
15
|
if (infoResult.error.code !== "not_found") {
|
|
16
16
|
diagnostics.push({
|
|
@@ -23,14 +23,14 @@ export async function loadPromptTemplates(env, paths) {
|
|
|
23
23
|
continue;
|
|
24
24
|
}
|
|
25
25
|
const info = infoResult.value;
|
|
26
|
-
const kind = await resolveKind(env, info, diagnostics);
|
|
26
|
+
const kind = await resolveKind(env, info, diagnostics, context);
|
|
27
27
|
if (kind === "directory") {
|
|
28
|
-
const result = await loadTemplatesFromDir(env, info.path);
|
|
28
|
+
const result = await loadTemplatesFromDir(env, info.path, context);
|
|
29
29
|
promptTemplates.push(...result.promptTemplates);
|
|
30
30
|
diagnostics.push(...result.diagnostics);
|
|
31
31
|
}
|
|
32
32
|
else if (kind === "file" && info.name.endsWith(".md")) {
|
|
33
|
-
const result = await loadTemplateFromFile(env, info.path, info.name);
|
|
33
|
+
const result = await loadTemplateFromFile(env, info.path, info.name, context);
|
|
34
34
|
if (result.promptTemplate)
|
|
35
35
|
promptTemplates.push(result.promptTemplate);
|
|
36
36
|
diagnostics.push(...result.diagnostics);
|
|
@@ -44,15 +44,15 @@ export async function loadPromptTemplates(env, paths) {
|
|
|
44
44
|
* Source values are preserved exactly and attached to every loaded prompt template and diagnostic. The agent package does
|
|
45
45
|
* not interpret source values; applications define their own provenance shape.
|
|
46
46
|
*/
|
|
47
|
-
export async function loadSourcedPromptTemplates(env, inputs, mapPromptTemplate) {
|
|
47
|
+
export async function loadSourcedPromptTemplates(env, inputs, mapPromptTemplate, context) {
|
|
48
48
|
const promptTemplates = [];
|
|
49
49
|
const diagnostics = [];
|
|
50
50
|
for (const input of inputs) {
|
|
51
|
-
const result = await loadPromptTemplates(env, input.path);
|
|
51
|
+
const result = await loadPromptTemplates(env, input.path, context);
|
|
52
52
|
for (const promptTemplate of result.promptTemplates) {
|
|
53
53
|
promptTemplates.push({
|
|
54
54
|
promptTemplate: mapPromptTemplate
|
|
55
|
-
? mapPromptTemplate(promptTemplate, input.source)
|
|
55
|
+
? mapPromptTemplate(promptTemplate, input.source, context)
|
|
56
56
|
: promptTemplate,
|
|
57
57
|
source: input.source,
|
|
58
58
|
});
|
|
@@ -62,10 +62,10 @@ export async function loadSourcedPromptTemplates(env, inputs, mapPromptTemplate)
|
|
|
62
62
|
}
|
|
63
63
|
return { promptTemplates, diagnostics };
|
|
64
64
|
}
|
|
65
|
-
async function loadTemplatesFromDir(env, dir) {
|
|
65
|
+
async function loadTemplatesFromDir(env, dir, context) {
|
|
66
66
|
const promptTemplates = [];
|
|
67
67
|
const diagnostics = [];
|
|
68
|
-
const entriesResult = await env.listDir(dir);
|
|
68
|
+
const entriesResult = await env.listDir(dir, context);
|
|
69
69
|
if (!entriesResult.ok) {
|
|
70
70
|
diagnostics.push({
|
|
71
71
|
type: "warning",
|
|
@@ -77,19 +77,19 @@ async function loadTemplatesFromDir(env, dir) {
|
|
|
77
77
|
}
|
|
78
78
|
const entries = entriesResult.value;
|
|
79
79
|
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
80
|
-
const kind = await resolveKind(env, entry, diagnostics);
|
|
80
|
+
const kind = await resolveKind(env, entry, diagnostics, context);
|
|
81
81
|
if (kind !== "file" || !entry.name.endsWith(".md"))
|
|
82
82
|
continue;
|
|
83
|
-
const result = await loadTemplateFromFile(env, entry.path, entry.name);
|
|
83
|
+
const result = await loadTemplateFromFile(env, entry.path, entry.name, context);
|
|
84
84
|
if (result.promptTemplate)
|
|
85
85
|
promptTemplates.push(result.promptTemplate);
|
|
86
86
|
diagnostics.push(...result.diagnostics);
|
|
87
87
|
}
|
|
88
88
|
return { promptTemplates, diagnostics };
|
|
89
89
|
}
|
|
90
|
-
async function loadTemplateFromFile(env, filePath, fileName) {
|
|
90
|
+
async function loadTemplateFromFile(env, filePath, fileName, context) {
|
|
91
91
|
const diagnostics = [];
|
|
92
|
-
const rawContent = await env.readTextFile(filePath);
|
|
92
|
+
const rawContent = await env.readTextFile(filePath, context);
|
|
93
93
|
if (!rawContent.ok) {
|
|
94
94
|
diagnostics.push({
|
|
95
95
|
type: "warning",
|
|
@@ -126,10 +126,10 @@ async function loadTemplateFromFile(env, filePath, fileName) {
|
|
|
126
126
|
diagnostics,
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
async function resolveKind(env, info, diagnostics) {
|
|
129
|
+
async function resolveKind(env, info, diagnostics, context) {
|
|
130
130
|
if (info.kind === "file" || info.kind === "directory")
|
|
131
131
|
return info.kind;
|
|
132
|
-
const canonicalPath = await env.canonicalPath(info.path);
|
|
132
|
+
const canonicalPath = await env.canonicalPath(info.path, context);
|
|
133
133
|
if (!canonicalPath.ok) {
|
|
134
134
|
if (canonicalPath.error.code !== "not_found") {
|
|
135
135
|
diagnostics.push({
|
|
@@ -141,7 +141,7 @@ async function resolveKind(env, info, diagnostics) {
|
|
|
141
141
|
}
|
|
142
142
|
return undefined;
|
|
143
143
|
}
|
|
144
|
-
const target = await env.fileInfo(canonicalPath.value);
|
|
144
|
+
const target = await env.fileInfo(canonicalPath.value, context);
|
|
145
145
|
if (!target.ok) {
|
|
146
146
|
if (target.error.code !== "not_found") {
|
|
147
147
|
diagnostics.push({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-templates.js","sourceRoot":"","sources":["../../src/harness/prompt-templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAsE,OAAO,EAAE,MAAM,YAAY,CAAC;AAsBzG;;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AC3F,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,2BAA2B,EAAE,CAAC,CAAC,EAAE,QAAgB,EAAE,SAAkB,EAAE,EAAE;QAChG,IAAI,KAAK,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QACvC,IAAI,KAAK,GAAG,CAAC;YAAE,KAAK,GAAG,CAAC,CAAC;QACzB,IAAI,SAAS;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnF,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IACjD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC;AACf,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,8BAA8B,CAAC,QAAwB,EAAE,IAAI,GAAa,EAAE;IAC3F,OAAO,cAAc,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { parse } from \"yaml\";\nimport { type ExecutionEnv, type FileInfo, type PromptTemplate, type Result, toError } from \"./types.ts\";\n\nexport type PromptTemplateDiagnosticCode = \"file_info_failed\" | \"list_failed\" | \"read_failed\" | \"parse_failed\";\n\n/** Warning produced while loading prompt templates. */\nexport interface PromptTemplateDiagnostic {\n\t/** Diagnostic severity. Currently only warnings are emitted. */\n\ttype: \"warning\";\n\t/** Stable diagnostic code. */\n\tcode: PromptTemplateDiagnosticCode;\n\t/** Human-readable diagnostic message. */\n\tmessage: string;\n\t/** Path associated with the diagnostic. */\n\tpath: string;\n}\n\ninterface PromptTemplateFrontmatter {\n\tdescription?: string;\n\t\"argument-hint\"?: string;\n\t[key: string]: unknown;\n}\n\n/**\n * Load prompt templates from one or more paths.\n *\n * Directory inputs load direct `.md` children non-recursively. File inputs load explicit `.md` files. Missing paths and\n * non-markdown files are skipped. Read and parse failures are returned as diagnostics.\n */\nexport async function loadPromptTemplates(\n\tenv: ExecutionEnv,\n\tpaths: string | string[],\n): Promise<{ promptTemplates: PromptTemplate[]; diagnostics: PromptTemplateDiagnostic[] }> {\n\tconst promptTemplates: PromptTemplate[] = [];\n\tconst diagnostics: PromptTemplateDiagnostic[] = [];\n\tfor (const path of Array.isArray(paths) ? paths : [paths]) {\n\t\tconst infoResult = await env.fileInfo(path);\n\t\tif (!infoResult.ok) {\n\t\t\tif (infoResult.error.code !== \"not_found\") {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\ttype: \"warning\",\n\t\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\t\tmessage: infoResult.error.message,\n\t\t\t\t\tpath,\n\t\t\t\t});\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst info = infoResult.value;\n\t\tconst kind = await resolveKind(env, info, diagnostics);\n\t\tif (kind === \"directory\") {\n\t\t\tconst result = await loadTemplatesFromDir(env, info.path);\n\t\t\tpromptTemplates.push(...result.promptTemplates);\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t} else if (kind === \"file\" && info.name.endsWith(\".md\")) {\n\t\t\tconst result = await loadTemplateFromFile(env, info.path, info.name);\n\t\t\tif (result.promptTemplate) promptTemplates.push(result.promptTemplate);\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t}\n\t}\n\treturn { promptTemplates, diagnostics };\n}\n\n/**\n * Load prompt templates from source-tagged paths.\n *\n * Source values are preserved exactly and attached to every loaded prompt template and diagnostic. The agent package does\n * not interpret source values; applications define their own provenance shape.\n */\nexport async function loadSourcedPromptTemplates<TSource, TPromptTemplate extends PromptTemplate = PromptTemplate>(\n\tenv: ExecutionEnv,\n\tinputs: Array<{ path: string; source: TSource }>,\n\tmapPromptTemplate?: (promptTemplate: PromptTemplate, source: TSource) => TPromptTemplate,\n): Promise<{\n\tpromptTemplates: Array<{ promptTemplate: TPromptTemplate; source: TSource }>;\n\tdiagnostics: Array<PromptTemplateDiagnostic & { source: TSource }>;\n}> {\n\tconst promptTemplates: Array<{ promptTemplate: TPromptTemplate; source: TSource }> = [];\n\tconst diagnostics: Array<PromptTemplateDiagnostic & { source: TSource }> = [];\n\tfor (const input of inputs) {\n\t\tconst result = await loadPromptTemplates(env, input.path);\n\t\tfor (const promptTemplate of result.promptTemplates) {\n\t\t\tpromptTemplates.push({\n\t\t\t\tpromptTemplate: mapPromptTemplate\n\t\t\t\t\t? mapPromptTemplate(promptTemplate, input.source)\n\t\t\t\t\t: (promptTemplate as TPromptTemplate),\n\t\t\t\tsource: input.source,\n\t\t\t});\n\t\t}\n\t\tfor (const diagnostic of result.diagnostics) diagnostics.push({ ...diagnostic, source: input.source });\n\t}\n\treturn { promptTemplates, diagnostics };\n}\n\nasync function loadTemplatesFromDir(\n\tenv: ExecutionEnv,\n\tdir: string,\n): Promise<{ promptTemplates: PromptTemplate[]; diagnostics: PromptTemplateDiagnostic[] }> {\n\tconst promptTemplates: PromptTemplate[] = [];\n\tconst diagnostics: PromptTemplateDiagnostic[] = [];\n\tconst entriesResult = await env.listDir(dir);\n\tif (!entriesResult.ok) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"list_failed\",\n\t\t\tmessage: entriesResult.error.message,\n\t\t\tpath: dir,\n\t\t});\n\t\treturn { promptTemplates, diagnostics };\n\t}\n\tconst entries = entriesResult.value;\n\n\tfor (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {\n\t\tconst kind = await resolveKind(env, entry, diagnostics);\n\t\tif (kind !== \"file\" || !entry.name.endsWith(\".md\")) continue;\n\t\tconst result = await loadTemplateFromFile(env, entry.path, entry.name);\n\t\tif (result.promptTemplate) promptTemplates.push(result.promptTemplate);\n\t\tdiagnostics.push(...result.diagnostics);\n\t}\n\treturn { promptTemplates, diagnostics };\n}\n\nasync function loadTemplateFromFile(\n\tenv: ExecutionEnv,\n\tfilePath: string,\n\tfileName: string,\n): Promise<{ promptTemplate: PromptTemplate | null; diagnostics: PromptTemplateDiagnostic[] }> {\n\tconst diagnostics: PromptTemplateDiagnostic[] = [];\n\tconst rawContent = await env.readTextFile(filePath);\n\tif (!rawContent.ok) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"read_failed\",\n\t\t\tmessage: rawContent.error.message,\n\t\t\tpath: filePath,\n\t\t});\n\t\treturn { promptTemplate: null, diagnostics };\n\t}\n\n\tconst parsed = parseFrontmatter<PromptTemplateFrontmatter>(rawContent.value);\n\tif (!parsed.ok) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"parse_failed\",\n\t\t\tmessage: parsed.error.message,\n\t\t\tpath: filePath,\n\t\t});\n\t\treturn { promptTemplate: null, diagnostics };\n\t}\n\n\tconst { frontmatter, body } = parsed.value;\n\tconst firstLine = body.split(\"\\n\").find((line) => line.trim());\n\tlet description = typeof frontmatter.description === \"string\" ? frontmatter.description : \"\";\n\tif (!description && firstLine) {\n\t\tdescription = firstLine.slice(0, 60);\n\t\tif (firstLine.length > 60) description += \"...\";\n\t}\n\treturn {\n\t\tpromptTemplate: {\n\t\t\tname: fileName.replace(/\\.md$/i, \"\"),\n\t\t\tdescription,\n\t\t\tcontent: body,\n\t\t},\n\t\tdiagnostics,\n\t};\n}\n\nasync function resolveKind(\n\tenv: ExecutionEnv,\n\tinfo: FileInfo,\n\tdiagnostics: PromptTemplateDiagnostic[],\n): Promise<\"file\" | \"directory\" | undefined> {\n\tif (info.kind === \"file\" || info.kind === \"directory\") return info.kind;\n\tconst canonicalPath = await env.canonicalPath(info.path);\n\tif (!canonicalPath.ok) {\n\t\tif (canonicalPath.error.code !== \"not_found\") {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\tmessage: canonicalPath.error.message,\n\t\t\t\tpath: info.path,\n\t\t\t});\n\t\t}\n\t\treturn undefined;\n\t}\n\tconst target = await env.fileInfo(canonicalPath.value);\n\tif (!target.ok) {\n\t\tif (target.error.code !== \"not_found\") {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\tmessage: target.error.message,\n\t\t\t\tpath: info.path,\n\t\t\t});\n\t\t}\n\t\treturn undefined;\n\t}\n\treturn target.value.kind === \"file\" || target.value.kind === \"directory\" ? target.value.kind : undefined;\n}\n\nfunction parseFrontmatter<T extends Record<string, unknown>>(\n\tcontent: string,\n): Result<{ frontmatter: T; body: string }, Error> {\n\ttry {\n\t\tconst normalized = content.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n\t\tif (!normalized.startsWith(\"---\")) return { ok: true, value: { frontmatter: {} as T, body: normalized } };\n\t\tconst endIndex = normalized.indexOf(\"\\n---\", 3);\n\t\tif (endIndex === -1) return { ok: true, value: { frontmatter: {} as T, body: normalized } };\n\t\tconst yamlString = normalized.slice(4, endIndex);\n\t\tconst body = normalized.slice(endIndex + 4).trim();\n\t\treturn { ok: true, value: { frontmatter: (parse(yamlString) ?? {}) as T, body } };\n\t} catch (error) {\n\t\treturn { ok: false, error: toError(error) };\n\t}\n}\n\n/** Parse an argument string using simple shell-style single and double quotes. */\nexport function parseCommandArgs(argsString: string): string[] {\n\tconst args: string[] = [];\n\tlet current = \"\";\n\tlet inQuote: string | null = null;\n\n\tfor (let i = 0; i < argsString.length; i++) {\n\t\tconst char = argsString[i]!;\n\t\tif (inQuote) {\n\t\t\tif (char === inQuote) inQuote = null;\n\t\t\telse current += char;\n\t\t} else if (char === '\"' || char === \"'\") {\n\t\t\tinQuote = char;\n\t\t} else if (char === \" \" || char === \"\\t\") {\n\t\t\tif (current) {\n\t\t\t\targs.push(current);\n\t\t\t\tcurrent = \"\";\n\t\t\t}\n\t\t} else {\n\t\t\tcurrent += char;\n\t\t}\n\t}\n\tif (current) args.push(current);\n\treturn args;\n}\n\n/** Substitute prompt template placeholders (`$1`, `$@`, `$ARGUMENTS`, `${@:N}`, `${@:N:L}`) with command arguments. */\nexport function substituteArgs(content: string, args: string[]): string {\n\tlet result = content;\n\tresult = result.replace(/\\$(\\d+)/g, (_, num: string) => args[parseInt(num, 10) - 1] ?? \"\");\n\tresult = result.replace(/\\$\\{@:(\\d+)(?::(\\d+))?\\}/g, (_, startStr: string, lengthStr?: string) => {\n\t\tlet start = parseInt(startStr, 10) - 1;\n\t\tif (start < 0) start = 0;\n\t\tif (lengthStr) return args.slice(start, start + parseInt(lengthStr, 10)).join(\" \");\n\t\treturn args.slice(start).join(\" \");\n\t});\n\tconst allArgs = args.join(\" \");\n\tresult = result.replace(/\\$ARGUMENTS/g, allArgs);\n\tresult = result.replace(/\\$@/g, allArgs);\n\treturn result;\n}\n\n/** Format a prompt template invocation with positional arguments. */\nexport function formatPromptTemplateInvocation(template: PromptTemplate, args: string[] = []): string {\n\treturn substituteArgs(template.content, args);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"prompt-templates.js","sourceRoot":"","sources":["../../src/harness/prompt-templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAsE,OAAO,EAAE,MAAM,YAAY,CAAC;AAsBzG;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,GAAiB,EACjB,KAAwB,EACxB,OAAgB;IAEhB,MAAM,eAAe,GAAqB,EAAE,CAAC;IAC7C,MAAM,WAAW,GAA+B,EAAE,CAAC;IACnD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KA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,GAAG,MAAM,CAAC,OAAO,CAAC,2BAA2B,EAAE,CAAC,CAAC,EAAE,QAAgB,EAAE,SAAkB,EAAE,EAAE;QAChG,IAAI,KAAK,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QACvC,IAAI,KAAK,GAAG,CAAC;YAAE,KAAK,GAAG,CAAC,CAAC;QACzB,IAAI,SAAS;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnF,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IACjD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC;AACf,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,8BAA8B,CAAC,QAAwB,EAAE,IAAI,GAAa,EAAE;IAC3F,OAAO,cAAc,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { parse } from \"yaml\";\nimport type { Context } from \"./context.ts\";\nimport { type ExecutionEnv, type FileInfo, type PromptTemplate, type Result, toError } from \"./types.ts\";\n\nexport type PromptTemplateDiagnosticCode = \"file_info_failed\" | \"list_failed\" | \"read_failed\" | \"parse_failed\";\n\n/** Warning produced while loading prompt templates. */\nexport interface PromptTemplateDiagnostic {\n\t/** Diagnostic severity. Currently only warnings are emitted. */\n\ttype: \"warning\";\n\t/** Stable diagnostic code. */\n\tcode: PromptTemplateDiagnosticCode;\n\t/** Human-readable diagnostic message. */\n\tmessage: string;\n\t/** Path associated with the diagnostic. */\n\tpath: string;\n}\n\ninterface PromptTemplateFrontmatter {\n\tdescription?: string;\n\t\"argument-hint\"?: string;\n\t[key: string]: unknown;\n}\n\n/**\n * Load prompt templates from one or more paths.\n *\n * Directory inputs load direct `.md` children non-recursively. File inputs load explicit `.md` files. Missing paths and\n * non-markdown files are skipped. Read and parse failures are returned as diagnostics.\n */\nexport async function loadPromptTemplates(\n\tenv: ExecutionEnv,\n\tpaths: string | string[],\n\tcontext: Context,\n): Promise<{ promptTemplates: PromptTemplate[]; diagnostics: PromptTemplateDiagnostic[] }> {\n\tconst promptTemplates: PromptTemplate[] = [];\n\tconst diagnostics: PromptTemplateDiagnostic[] = [];\n\tfor (const path of Array.isArray(paths) ? paths : [paths]) {\n\t\tconst infoResult = await env.fileInfo(path, context);\n\t\tif (!infoResult.ok) {\n\t\t\tif (infoResult.error.code !== \"not_found\") {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\ttype: \"warning\",\n\t\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\t\tmessage: infoResult.error.message,\n\t\t\t\t\tpath,\n\t\t\t\t});\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst info = infoResult.value;\n\t\tconst kind = await resolveKind(env, info, diagnostics, context);\n\t\tif (kind === \"directory\") {\n\t\t\tconst result = await loadTemplatesFromDir(env, info.path, context);\n\t\t\tpromptTemplates.push(...result.promptTemplates);\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t} else if (kind === \"file\" && info.name.endsWith(\".md\")) {\n\t\t\tconst result = await loadTemplateFromFile(env, info.path, info.name, context);\n\t\t\tif (result.promptTemplate) promptTemplates.push(result.promptTemplate);\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t}\n\t}\n\treturn { promptTemplates, diagnostics };\n}\n\n/**\n * Load prompt templates from source-tagged paths.\n *\n * Source values are preserved exactly and attached to every loaded prompt template and diagnostic. The agent package does\n * not interpret source values; applications define their own provenance shape.\n */\nexport async function loadSourcedPromptTemplates<TSource, TPromptTemplate extends PromptTemplate = PromptTemplate>(\n\tenv: ExecutionEnv,\n\tinputs: Array<{ path: string; source: TSource }>,\n\tmapPromptTemplate:\n\t\t| ((promptTemplate: PromptTemplate, source: TSource, context: Context) => TPromptTemplate)\n\t\t| undefined,\n\tcontext: Context,\n): Promise<{\n\tpromptTemplates: Array<{ promptTemplate: TPromptTemplate; source: TSource }>;\n\tdiagnostics: Array<PromptTemplateDiagnostic & { source: TSource }>;\n}> {\n\tconst promptTemplates: Array<{ promptTemplate: TPromptTemplate; source: TSource }> = [];\n\tconst diagnostics: Array<PromptTemplateDiagnostic & { source: TSource }> = [];\n\tfor (const input of inputs) {\n\t\tconst result = await loadPromptTemplates(env, input.path, context);\n\t\tfor (const promptTemplate of result.promptTemplates) {\n\t\t\tpromptTemplates.push({\n\t\t\t\tpromptTemplate: mapPromptTemplate\n\t\t\t\t\t? mapPromptTemplate(promptTemplate, input.source, context)\n\t\t\t\t\t: (promptTemplate as TPromptTemplate),\n\t\t\t\tsource: input.source,\n\t\t\t});\n\t\t}\n\t\tfor (const diagnostic of result.diagnostics) diagnostics.push({ ...diagnostic, source: input.source });\n\t}\n\treturn { promptTemplates, diagnostics };\n}\n\nasync function loadTemplatesFromDir(\n\tenv: ExecutionEnv,\n\tdir: string,\n\tcontext: Context,\n): Promise<{ promptTemplates: PromptTemplate[]; diagnostics: PromptTemplateDiagnostic[] }> {\n\tconst promptTemplates: PromptTemplate[] = [];\n\tconst diagnostics: PromptTemplateDiagnostic[] = [];\n\tconst entriesResult = await env.listDir(dir, context);\n\tif (!entriesResult.ok) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"list_failed\",\n\t\t\tmessage: entriesResult.error.message,\n\t\t\tpath: dir,\n\t\t});\n\t\treturn { promptTemplates, diagnostics };\n\t}\n\tconst entries = entriesResult.value;\n\n\tfor (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {\n\t\tconst kind = await resolveKind(env, entry, diagnostics, context);\n\t\tif (kind !== \"file\" || !entry.name.endsWith(\".md\")) continue;\n\t\tconst result = await loadTemplateFromFile(env, entry.path, entry.name, context);\n\t\tif (result.promptTemplate) promptTemplates.push(result.promptTemplate);\n\t\tdiagnostics.push(...result.diagnostics);\n\t}\n\treturn { promptTemplates, diagnostics };\n}\n\nasync function loadTemplateFromFile(\n\tenv: ExecutionEnv,\n\tfilePath: string,\n\tfileName: string,\n\tcontext: Context,\n): Promise<{ promptTemplate: PromptTemplate | null; diagnostics: PromptTemplateDiagnostic[] }> {\n\tconst diagnostics: PromptTemplateDiagnostic[] = [];\n\tconst rawContent = await env.readTextFile(filePath, context);\n\tif (!rawContent.ok) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"read_failed\",\n\t\t\tmessage: rawContent.error.message,\n\t\t\tpath: filePath,\n\t\t});\n\t\treturn { promptTemplate: null, diagnostics };\n\t}\n\n\tconst parsed = parseFrontmatter<PromptTemplateFrontmatter>(rawContent.value);\n\tif (!parsed.ok) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"parse_failed\",\n\t\t\tmessage: parsed.error.message,\n\t\t\tpath: filePath,\n\t\t});\n\t\treturn { promptTemplate: null, diagnostics };\n\t}\n\n\tconst { frontmatter, body } = parsed.value;\n\tconst firstLine = body.split(\"\\n\").find((line) => line.trim());\n\tlet description = typeof frontmatter.description === \"string\" ? frontmatter.description : \"\";\n\tif (!description && firstLine) {\n\t\tdescription = firstLine.slice(0, 60);\n\t\tif (firstLine.length > 60) description += \"...\";\n\t}\n\treturn {\n\t\tpromptTemplate: {\n\t\t\tname: fileName.replace(/\\.md$/i, \"\"),\n\t\t\tdescription,\n\t\t\tcontent: body,\n\t\t},\n\t\tdiagnostics,\n\t};\n}\n\nasync function resolveKind(\n\tenv: ExecutionEnv,\n\tinfo: FileInfo,\n\tdiagnostics: PromptTemplateDiagnostic[],\n\tcontext: Context,\n): Promise<\"file\" | \"directory\" | undefined> {\n\tif (info.kind === \"file\" || info.kind === \"directory\") return info.kind;\n\tconst canonicalPath = await env.canonicalPath(info.path, context);\n\tif (!canonicalPath.ok) {\n\t\tif (canonicalPath.error.code !== \"not_found\") {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\tmessage: canonicalPath.error.message,\n\t\t\t\tpath: info.path,\n\t\t\t});\n\t\t}\n\t\treturn undefined;\n\t}\n\tconst target = await env.fileInfo(canonicalPath.value, context);\n\tif (!target.ok) {\n\t\tif (target.error.code !== \"not_found\") {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\tmessage: target.error.message,\n\t\t\t\tpath: info.path,\n\t\t\t});\n\t\t}\n\t\treturn undefined;\n\t}\n\treturn target.value.kind === \"file\" || target.value.kind === \"directory\" ? target.value.kind : undefined;\n}\n\nfunction parseFrontmatter<T extends Record<string, unknown>>(\n\tcontent: string,\n): Result<{ frontmatter: T; body: string }, Error> {\n\ttry {\n\t\tconst normalized = content.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n\t\tif (!normalized.startsWith(\"---\")) return { ok: true, value: { frontmatter: {} as T, body: normalized } };\n\t\tconst endIndex = normalized.indexOf(\"\\n---\", 3);\n\t\tif (endIndex === -1) return { ok: true, value: { frontmatter: {} as T, body: normalized } };\n\t\tconst yamlString = normalized.slice(4, endIndex);\n\t\tconst body = normalized.slice(endIndex + 4).trim();\n\t\treturn { ok: true, value: { frontmatter: (parse(yamlString) ?? {}) as T, body } };\n\t} catch (error) {\n\t\treturn { ok: false, error: toError(error) };\n\t}\n}\n\n/** Parse an argument string using simple shell-style single and double quotes. */\nexport function parseCommandArgs(argsString: string): string[] {\n\tconst args: string[] = [];\n\tlet current = \"\";\n\tlet inQuote: string | null = null;\n\n\tfor (let i = 0; i < argsString.length; i++) {\n\t\tconst char = argsString[i]!;\n\t\tif (inQuote) {\n\t\t\tif (char === inQuote) inQuote = null;\n\t\t\telse current += char;\n\t\t} else if (char === '\"' || char === \"'\") {\n\t\t\tinQuote = char;\n\t\t} else if (char === \" \" || char === \"\\t\") {\n\t\t\tif (current) {\n\t\t\t\targs.push(current);\n\t\t\t\tcurrent = \"\";\n\t\t\t}\n\t\t} else {\n\t\t\tcurrent += char;\n\t\t}\n\t}\n\tif (current) args.push(current);\n\treturn args;\n}\n\n/** Substitute prompt template placeholders (`$1`, `$@`, `$ARGUMENTS`, `${@:N}`, `${@:N:L}`) with command arguments. */\nexport function substituteArgs(content: string, args: string[]): string {\n\tlet result = content;\n\tresult = result.replace(/\\$(\\d+)/g, (_, num: string) => args[parseInt(num, 10) - 1] ?? \"\");\n\tresult = result.replace(/\\$\\{@:(\\d+)(?::(\\d+))?\\}/g, (_, startStr: string, lengthStr?: string) => {\n\t\tlet start = parseInt(startStr, 10) - 1;\n\t\tif (start < 0) start = 0;\n\t\tif (lengthStr) return args.slice(start, start + parseInt(lengthStr, 10)).join(\" \");\n\t\treturn args.slice(start).join(\" \");\n\t});\n\tconst allArgs = args.join(\" \");\n\tresult = result.replace(/\\$ARGUMENTS/g, allArgs);\n\tresult = result.replace(/\\$@/g, allArgs);\n\treturn result;\n}\n\n/** Format a prompt template invocation with positional arguments. */\nexport function formatPromptTemplateInvocation(template: PromptTemplate, args: string[] = []): string {\n\treturn substituteArgs(template.content, args);\n}\n"]}
|
package/dist/harness/result.d.ts
CHANGED
|
@@ -31,10 +31,103 @@ export interface TaggedErrorFactory<Tag extends string> {
|
|
|
31
31
|
is(value: unknown): value is TaggedErrorValue<Tag>;
|
|
32
32
|
}
|
|
33
33
|
export declare function TaggedError<Tag extends string>(tag: Tag): TaggedErrorFactory<Tag>;
|
|
34
|
+
declare const LaneBusy_base: TaggedErrorFactory<"LaneBusy">;
|
|
35
|
+
export declare class LaneBusy extends LaneBusy_base<{
|
|
36
|
+
lane: string;
|
|
37
|
+
operationId: string;
|
|
38
|
+
operationKind: "run" | "compaction" | "navigation";
|
|
39
|
+
message: string;
|
|
40
|
+
}> {
|
|
41
|
+
}
|
|
42
|
+
declare const OperationMismatch_base: TaggedErrorFactory<"OperationMismatch">;
|
|
43
|
+
export declare class OperationMismatch extends OperationMismatch_base<{
|
|
44
|
+
lane: string;
|
|
45
|
+
expectedOperationId: string;
|
|
46
|
+
currentOperationId?: string;
|
|
47
|
+
lastOperationId?: string;
|
|
48
|
+
message: string;
|
|
49
|
+
}> {
|
|
50
|
+
}
|
|
51
|
+
declare const NoActiveRun_base: TaggedErrorFactory<"NoActiveRun">;
|
|
52
|
+
export declare class NoActiveRun extends NoActiveRun_base<{
|
|
53
|
+
lane: string;
|
|
54
|
+
message: string;
|
|
55
|
+
}> {
|
|
56
|
+
}
|
|
57
|
+
declare const NoActiveOperation_base: TaggedErrorFactory<"NoActiveOperation">;
|
|
58
|
+
export declare class NoActiveOperation extends NoActiveOperation_base<{
|
|
59
|
+
lane: string;
|
|
60
|
+
message: string;
|
|
61
|
+
}> {
|
|
62
|
+
}
|
|
63
|
+
declare const NothingToResume_base: TaggedErrorFactory<"NothingToResume">;
|
|
64
|
+
export declare class NothingToResume extends NothingToResume_base<{
|
|
65
|
+
lane: string;
|
|
66
|
+
message: string;
|
|
67
|
+
}> {
|
|
68
|
+
}
|
|
69
|
+
declare const NothingToCompact_base: TaggedErrorFactory<"NothingToCompact">;
|
|
70
|
+
export declare class NothingToCompact extends NothingToCompact_base<{
|
|
71
|
+
lane: string;
|
|
72
|
+
message: string;
|
|
73
|
+
}> {
|
|
74
|
+
}
|
|
75
|
+
declare const InvalidMessage_base: TaggedErrorFactory<"InvalidMessage">;
|
|
76
|
+
export declare class InvalidMessage extends InvalidMessage_base<{
|
|
77
|
+
lane: string;
|
|
78
|
+
reason: string;
|
|
79
|
+
message: string;
|
|
80
|
+
}> {
|
|
81
|
+
}
|
|
82
|
+
declare const InvalidNavigation_base: TaggedErrorFactory<"InvalidNavigation">;
|
|
83
|
+
export declare class InvalidNavigation extends InvalidNavigation_base<{
|
|
84
|
+
lane: string;
|
|
85
|
+
reason: string;
|
|
86
|
+
message: string;
|
|
87
|
+
}> {
|
|
88
|
+
}
|
|
89
|
+
declare const UnknownSkill_base: TaggedErrorFactory<"UnknownSkill">;
|
|
90
|
+
export declare class UnknownSkill extends UnknownSkill_base<{
|
|
91
|
+
name: string;
|
|
92
|
+
message: string;
|
|
93
|
+
}> {
|
|
94
|
+
}
|
|
95
|
+
declare const UnknownTemplate_base: TaggedErrorFactory<"UnknownTemplate">;
|
|
96
|
+
export declare class UnknownTemplate extends UnknownTemplate_base<{
|
|
97
|
+
name: string;
|
|
98
|
+
message: string;
|
|
99
|
+
}> {
|
|
100
|
+
}
|
|
101
|
+
declare const UnknownTarget_base: TaggedErrorFactory<"UnknownTarget">;
|
|
102
|
+
export declare class UnknownTarget extends UnknownTarget_base<{
|
|
103
|
+
targetId: string;
|
|
104
|
+
message: string;
|
|
105
|
+
}> {
|
|
106
|
+
}
|
|
107
|
+
declare const InvalidLane_base: TaggedErrorFactory<"InvalidLane">;
|
|
108
|
+
export declare class InvalidLane extends InvalidLane_base<{
|
|
109
|
+
lane: string;
|
|
110
|
+
reason: string;
|
|
111
|
+
message: string;
|
|
112
|
+
}> {
|
|
113
|
+
}
|
|
114
|
+
declare const Closed_base: TaggedErrorFactory<"Closed">;
|
|
115
|
+
export declare class Closed extends Closed_base<{
|
|
116
|
+
message: string;
|
|
117
|
+
}> {
|
|
118
|
+
}
|
|
119
|
+
export declare class HarnessFault extends Error {
|
|
120
|
+
readonly cause: unknown;
|
|
121
|
+
constructor(message: string, cause: unknown);
|
|
122
|
+
}
|
|
123
|
+
export declare class HarnessClosed extends Error {
|
|
124
|
+
constructor();
|
|
125
|
+
}
|
|
34
126
|
export type ErrorMatchers<TError extends TaggedErrorValue<string>, TValue> = {
|
|
35
127
|
[Tag in TError["_tag"]]: (error: Extract<TError, {
|
|
36
128
|
_tag: Tag;
|
|
37
129
|
}>) => TValue;
|
|
38
130
|
};
|
|
39
131
|
export declare function matchError<TError extends TaggedErrorValue<string>, TValue>(error: TError, matchers: ErrorMatchers<TError, TValue>): TValue;
|
|
132
|
+
export {};
|
|
40
133
|
//# sourceMappingURL=result.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/harness/result.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhG,eAAO,MAAM,MAAM;IAClB,EAAE,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IAGhD,GAAG,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;IAGjD,IAAI,CAAC,MAAM,EAAE,MAAM,UAAU,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,IAAI;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAG3F,KAAK,CAAC,MAAM,EAAE,MAAM,UAAU,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,IAAI;QAAE,EAAE,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;CAG7F,CAAC;AAEF,MAAM,WAAW,gBAAgB,CAAC,GAAG,SAAS,MAAM,CAAE,SAAQ,KAAK;IAClE,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC;IACnB,MAAM,IAAI;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE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,EAAE,MAAM,CAAA;CAAE,CAAC;CAAG;;AACzG,qBAAa,aAAc,SAAQ,mBAA6B;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;CAAG;;AACzG,qBAAa,WAAY,SAAQ,iBAA2B;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;CAAG;;AACL,qBAAa,MAAO,SAAQ,YAAsB;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;CAAG;AAEzE,qBAAa,YAAa,SAAQ,KAAK;IACtC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAExB,YAAY,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAI1C;CACD;AAED,qBAAa,aAAc,SAAQ,KAAK;IACvC,cAGC;CACD;AAED,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI;KAC3E,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,GAAG,CAAA;KAAE,CAAC,KAAK,MAAM;CAC1E,CAAC;AAEF,wBAAgB,UAAU,CAAC,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,EACzE,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,MAAM,CAGR"}
|
package/dist/harness/result.js
CHANGED
|
@@ -34,6 +34,45 @@ export function TaggedError(tag) {
|
|
|
34
34
|
}
|
|
35
35
|
return TaggedErrorClass;
|
|
36
36
|
}
|
|
37
|
+
export class LaneBusy extends TaggedError("LaneBusy") {
|
|
38
|
+
}
|
|
39
|
+
export class OperationMismatch extends TaggedError("OperationMismatch") {
|
|
40
|
+
}
|
|
41
|
+
export class NoActiveRun extends TaggedError("NoActiveRun") {
|
|
42
|
+
}
|
|
43
|
+
export class NoActiveOperation extends TaggedError("NoActiveOperation") {
|
|
44
|
+
}
|
|
45
|
+
export class NothingToResume extends TaggedError("NothingToResume") {
|
|
46
|
+
}
|
|
47
|
+
export class NothingToCompact extends TaggedError("NothingToCompact") {
|
|
48
|
+
}
|
|
49
|
+
export class InvalidMessage extends TaggedError("InvalidMessage") {
|
|
50
|
+
}
|
|
51
|
+
export class InvalidNavigation extends TaggedError("InvalidNavigation") {
|
|
52
|
+
}
|
|
53
|
+
export class UnknownSkill extends TaggedError("UnknownSkill") {
|
|
54
|
+
}
|
|
55
|
+
export class UnknownTemplate extends TaggedError("UnknownTemplate") {
|
|
56
|
+
}
|
|
57
|
+
export class UnknownTarget extends TaggedError("UnknownTarget") {
|
|
58
|
+
}
|
|
59
|
+
export class InvalidLane extends TaggedError("InvalidLane") {
|
|
60
|
+
}
|
|
61
|
+
export class Closed extends TaggedError("Closed") {
|
|
62
|
+
}
|
|
63
|
+
export class HarnessFault extends Error {
|
|
64
|
+
constructor(message, cause) {
|
|
65
|
+
super(message);
|
|
66
|
+
this.name = "HarnessFault";
|
|
67
|
+
this.cause = cause;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export class HarnessClosed extends Error {
|
|
71
|
+
constructor() {
|
|
72
|
+
super("AgentHarness was closed while the operation was active");
|
|
73
|
+
this.name = "HarnessClosed";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
37
76
|
export function matchError(error, matchers) {
|
|
38
77
|
const matcher = matchers[error._tag];
|
|
39
78
|
return matcher(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/harness/result.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,MAAM,GAAG;IACrB,EAAE,CAAS,KAAa;QACvB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC5B,CA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ok: true; value: TValue } | { ok: false; error: TError };\n\nexport const Result = {\n\tok<TValue>(value: TValue): Result<TValue, never> {\n\t\treturn { ok: true, value };\n\t},\n\terr<TError>(error: TError): Result<never, TError> {\n\t\treturn { ok: false, error };\n\t},\n\tisOk<TValue, TError>(result: Result<TValue, TError>): result is { ok: true; value: TValue } {\n\t\treturn result.ok;\n\t},\n\tisErr<TValue, TError>(result: Result<TValue, TError>): result is { ok: false; error: TError } {\n\t\treturn !result.ok;\n\t},\n};\n\nexport interface TaggedErrorValue<Tag extends string> extends Error {\n\treadonly _tag: Tag;\n\ttoJSON(): { _tag: Tag; message: string } & Record<string, unknown>;\n}\n\nexport interface TaggedErrorFactory<Tag extends string> {\n\tnew <Props extends { message: string }>(props: Props): TaggedErrorValue<Tag> & Readonly<Props>;\n\tis(value: unknown): value is TaggedErrorValue<Tag>;\n}\n\nexport function TaggedError<Tag extends string>(tag: Tag): TaggedErrorFactory<Tag> {\n\tclass TaggedErrorClass extends Error {\n\t\treadonly _tag = tag;\n\n\t\tconstructor(props: { message: string } & Record<string, unknown>) {\n\t\t\tsuper(props.message);\n\t\t\tthis.name = tag;\n\t\t\tObject.assign(this, props);\n\t\t}\n\n\t\ttoJSON(): { _tag: Tag; message: string } & Record<string, unknown> {\n\t\t\tconst payload: Record<string, unknown> = {};\n\t\t\tfor (const key of Object.keys(this)) {\n\t\t\t\tif (key !== \"_tag\") payload[key] = (this as unknown as Record<string, unknown>)[key];\n\t\t\t}\n\t\t\treturn { _tag: tag, message: this.message, ...payload };\n\t\t}\n\n\t\tstatic is(value: unknown): value is TaggedErrorValue<Tag> {\n\t\t\treturn value instanceof TaggedErrorClass;\n\t\t}\n\t}\n\treturn TaggedErrorClass as unknown as TaggedErrorFactory<Tag>;\n}\n\nexport type ErrorMatchers<TError extends TaggedErrorValue<string>, TValue> = {\n\t[Tag in TError[\"_tag\"]]: (error: Extract<TError, { _tag: Tag }>) => TValue;\n};\n\nexport function matchError<TError extends TaggedErrorValue<string>, TValue>(\n\terror: TError,\n\tmatchers: ErrorMatchers<TError, TValue>,\n): TValue {\n\tconst matcher = (matchers as unknown as Record<string, (value: TError) => TValue>)[error._tag];\n\treturn matcher(error);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/harness/result.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,MAAM,GAAG;IACrB,EAAE,CAAS,KAAa;QACvB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IACD,GAAG,CAAS,KAAa;QACxB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC;IACD,IAAI,CAAiB,MAA8B;QAClD,OAAO,MAAM,CAAC,EAAE,CAAC;IAClB,CAAC;IACD,KAAK,CAAiB,MAA8B;QACnD,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;IACnB,CAAC;CACD,CAAC;AAYF,MAAM,UAAU,WAAW,CAAqB,GAAQ;IACvD,MAAM,gBAAiB,SAAQ,KAAK;QAGnC,YAAY,KAAoD;YAC/D,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAHb,SAAI,GAAG,GAAG,CAAC;YAInB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;YAChB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC;QAED,MAAM;YACL,MAAM,OAAO,GAA4B,EAAE,CAAC;YAC5C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrC,IAAI,GAAG,KAAK,MAAM;oBAAE,OAAO,CAAC,GAAG,CAAC,GAAI,IAA2C,CAAC,GAAG,CAAC,CAAC;YACtF,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;QACzD,CA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,CAAC,wDAAwD,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC7B,CAAC;CACD;AAMD,MAAM,UAAU,UAAU,CACzB,KAAa,EACb,QAAuC;IAEvC,MAAM,OAAO,GAAI,QAAiE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/F,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC","sourcesContent":["export type Result<TValue, TError> = { ok: true; value: TValue } | { ok: false; error: TError };\n\nexport const Result = {\n\tok<TValue>(value: TValue): Result<TValue, never> {\n\t\treturn { ok: true, value };\n\t},\n\terr<TError>(error: TError): Result<never, TError> {\n\t\treturn { ok: false, error };\n\t},\n\tisOk<TValue, TError>(result: Result<TValue, TError>): result is { ok: true; value: TValue } {\n\t\treturn result.ok;\n\t},\n\tisErr<TValue, TError>(result: Result<TValue, TError>): result is { ok: false; error: TError } {\n\t\treturn !result.ok;\n\t},\n};\n\nexport interface TaggedErrorValue<Tag extends string> extends Error {\n\treadonly _tag: Tag;\n\ttoJSON(): { _tag: Tag; message: string } & Record<string, unknown>;\n}\n\nexport interface TaggedErrorFactory<Tag extends string> {\n\tnew <Props extends { message: string }>(props: Props): TaggedErrorValue<Tag> & Readonly<Props>;\n\tis(value: unknown): value is TaggedErrorValue<Tag>;\n}\n\nexport function TaggedError<Tag extends string>(tag: Tag): TaggedErrorFactory<Tag> {\n\tclass TaggedErrorClass extends Error {\n\t\treadonly _tag = tag;\n\n\t\tconstructor(props: { message: string } & Record<string, unknown>) {\n\t\t\tsuper(props.message);\n\t\t\tthis.name = tag;\n\t\t\tObject.assign(this, props);\n\t\t}\n\n\t\ttoJSON(): { _tag: Tag; message: string } & Record<string, unknown> {\n\t\t\tconst payload: Record<string, unknown> = {};\n\t\t\tfor (const key of Object.keys(this)) {\n\t\t\t\tif (key !== \"_tag\") payload[key] = (this as unknown as Record<string, unknown>)[key];\n\t\t\t}\n\t\t\treturn { _tag: tag, message: this.message, ...payload };\n\t\t}\n\n\t\tstatic is(value: unknown): value is TaggedErrorValue<Tag> {\n\t\t\treturn value instanceof TaggedErrorClass;\n\t\t}\n\t}\n\treturn TaggedErrorClass as unknown as TaggedErrorFactory<Tag>;\n}\n\nexport class LaneBusy extends TaggedError(\"LaneBusy\")<{\n\tlane: string;\n\toperationId: string;\n\toperationKind: \"run\" | \"compaction\" | \"navigation\";\n\tmessage: string;\n}> {}\nexport class OperationMismatch extends TaggedError(\"OperationMismatch\")<{\n\tlane: string;\n\texpectedOperationId: string;\n\tcurrentOperationId?: string;\n\tlastOperationId?: string;\n\tmessage: string;\n}> {}\nexport class NoActiveRun extends TaggedError(\"NoActiveRun\")<{ lane: string; message: string }> {}\nexport class NoActiveOperation extends TaggedError(\"NoActiveOperation\")<{ lane: string; message: string }> {}\nexport class NothingToResume extends TaggedError(\"NothingToResume\")<{ lane: string; message: string }> {}\nexport class NothingToCompact extends TaggedError(\"NothingToCompact\")<{ lane: string; message: string }> {}\nexport class InvalidMessage extends TaggedError(\"InvalidMessage\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class InvalidNavigation extends TaggedError(\"InvalidNavigation\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class UnknownSkill extends TaggedError(\"UnknownSkill\")<{ name: string; message: string }> {}\nexport class UnknownTemplate extends TaggedError(\"UnknownTemplate\")<{ name: string; message: string }> {}\nexport class UnknownTarget extends TaggedError(\"UnknownTarget\")<{ targetId: string; message: string }> {}\nexport class InvalidLane extends TaggedError(\"InvalidLane\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class Closed extends TaggedError(\"Closed\")<{ message: string }> {}\n\nexport class HarnessFault extends Error {\n\treadonly cause: unknown;\n\n\tconstructor(message: string, cause: unknown) {\n\t\tsuper(message);\n\t\tthis.name = \"HarnessFault\";\n\t\tthis.cause = cause;\n\t}\n}\n\nexport class HarnessClosed extends Error {\n\tconstructor() {\n\t\tsuper(\"AgentHarness was closed while the operation was active\");\n\t\tthis.name = \"HarnessClosed\";\n\t}\n}\n\nexport type ErrorMatchers<TError extends TaggedErrorValue<string>, TValue> = {\n\t[Tag in TError[\"_tag\"]]: (error: Extract<TError, { _tag: Tag }>) => TValue;\n};\n\nexport function matchError<TError extends TaggedErrorValue<string>, TValue>(\n\terror: TError,\n\tmatchers: ErrorMatchers<TError, TValue>,\n): TValue {\n\tconst matcher = (matchers as unknown as Record<string, (value: TError) => TValue>)[error._tag];\n\treturn matcher(error);\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { HarnessEvent, LaneQueuedItem } from "../../agent-harness.ts";
|
|
2
|
+
import type { AssistantReadyOperation, CheckpointOperation, CommitResult, NewEntry, NormalizedRetryPolicy, OperationScope, SessionReader, SummaryDecidingOperation, SummaryEffectPendingOperation, SummaryReadyOperation, Write } from "../../session/types.ts";
|
|
3
|
+
import type { Lane } from "../lane.ts";
|
|
4
|
+
import type { Drive, LaneState, ProcedureResult } from "../types.ts";
|
|
5
|
+
export interface BoundaryFinishPending {
|
|
6
|
+
kind: "finish_pending";
|
|
7
|
+
entryIds: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface BoundaryPlacement {
|
|
10
|
+
entries: NewEntry[];
|
|
11
|
+
writes: Write[];
|
|
12
|
+
tipId: string | null;
|
|
13
|
+
inbox: LaneState["inbox"];
|
|
14
|
+
triggerEntryId?: string;
|
|
15
|
+
queues?: LaneQueuedItem[];
|
|
16
|
+
}
|
|
17
|
+
type FinishBoundaryOperation = CheckpointOperation | SummaryDecidingOperation | SummaryReadyOperation | SummaryEffectPendingOperation;
|
|
18
|
+
export declare function normalizedRetryPolicy<TContext extends object | undefined>(lane: Lane<TContext>): NormalizedRetryPolicy;
|
|
19
|
+
export declare function assistantReadyAtBoundary<TContext extends object | undefined>(lane: Lane<TContext>, state: LaneState, scope: OperationScope, triggerEntryId: string, overflowRecoveryUsed: boolean): AssistantReadyOperation;
|
|
20
|
+
/** Select and materialize one boundary's lane-owned input without committing it. */
|
|
21
|
+
export declare function planBoundaryInbox<TContext extends object | undefined>(lane: Lane<TContext>, drive: Drive, state: LaneState, scope: OperationScope, reader: SessionReader, tipId: string | null, followUpWhenNoTrigger: boolean): Promise<BoundaryPlacement>;
|
|
22
|
+
export declare function boundaryPlacementEvents(placement: BoundaryPlacement, commit: CommitResult, firstWriteIndex: number, lane: string, runId: string): HarnessEvent[];
|
|
23
|
+
/** Replan after before_run_end and commit either renewed work or the terminal run result. */
|
|
24
|
+
export declare function finishRunBoundary<TContext extends object | undefined, TState extends FinishBoundaryOperation>(lane: Lane<TContext>, drive: Drive, capability: TState, continuation: Extract<CheckpointOperation["continuation"], {
|
|
25
|
+
kind: "may_finish";
|
|
26
|
+
}>, plannedEntryIds: readonly string[], pendingEvents?: HarnessEvent[]): Promise<ProcedureResult>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=boundary.d.ts.map
|