@earendil-works/pi-agent-core 0.84.4 → 0.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +9 -0
- package/dist/agent-loop.js.map +1 -1
- 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 -251
- 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 -26
- 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 -63
- 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 +27 -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 +24 -28
- package/dist/harness/env/nodejs.d.ts.map +1 -1
- package/dist/harness/env/nodejs.js +239 -86
- 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 +240 -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 +49 -0
- package/dist/harness/execution/effect-gate.js.map +1 -0
- package/dist/harness/execution/tools.d.ts +67 -0
- package/dist/harness/execution/tools.d.ts.map +1 -0
- package/dist/harness/execution/tools.js +121 -0
- package/dist/harness/execution/tools.js.map +1 -0
- package/dist/harness/hooks.d.ts +38 -0
- package/dist/harness/hooks.d.ts.map +1 -0
- package/dist/harness/hooks.js +406 -0
- package/dist/harness/hooks.js.map +1 -0
- package/dist/harness/messages.d.ts +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 +40 -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 +170 -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 +37 -0
- package/dist/harness/runtime/drive/retry.js.map +1 -0
- package/dist/harness/runtime/drive/structural.d.ts +32 -0
- package/dist/harness/runtime/drive/structural.d.ts.map +1 -0
- package/dist/harness/runtime/drive/structural.js +929 -0
- package/dist/harness/runtime/drive/structural.js.map +1 -0
- package/dist/harness/runtime/drive/terminal.d.ts +7 -0
- package/dist/harness/runtime/drive/terminal.d.ts.map +1 -0
- package/dist/harness/runtime/drive/terminal.js +49 -0
- package/dist/harness/runtime/drive/terminal.js.map +1 -0
- package/dist/harness/runtime/drive/tool-placement.d.ts +14 -0
- package/dist/harness/runtime/drive/tool-placement.d.ts.map +1 -0
- package/dist/harness/runtime/drive/tool-placement.js +244 -0
- package/dist/harness/runtime/drive/tool-placement.js.map +1 -0
- package/dist/harness/runtime/drive/tools.d.ts +6 -0
- package/dist/harness/runtime/drive/tools.d.ts.map +1 -0
- package/dist/harness/runtime/drive/tools.js +449 -0
- package/dist/harness/runtime/drive/tools.js.map +1 -0
- package/dist/harness/runtime/drive.d.ts +6 -0
- package/dist/harness/runtime/drive.d.ts.map +1 -0
- package/dist/harness/runtime/drive.js +93 -0
- package/dist/harness/runtime/drive.js.map +1 -0
- package/dist/harness/runtime/harness.d.ts +59 -0
- package/dist/harness/runtime/harness.d.ts.map +1 -0
- package/dist/harness/runtime/harness.js +311 -0
- package/dist/harness/runtime/harness.js.map +1 -0
- package/dist/harness/runtime/index.d.ts +2 -0
- package/dist/harness/runtime/index.d.ts.map +1 -0
- package/dist/harness/runtime/index.js +2 -0
- package/dist/harness/runtime/index.js.map +1 -0
- package/dist/harness/runtime/lane.d.ts +101 -0
- package/dist/harness/runtime/lane.d.ts.map +1 -0
- package/dist/harness/runtime/lane.js +1575 -0
- package/dist/harness/runtime/lane.js.map +1 -0
- package/dist/harness/runtime/progress.d.ts +15 -0
- package/dist/harness/runtime/progress.d.ts.map +1 -0
- package/dist/harness/runtime/progress.js +66 -0
- package/dist/harness/runtime/progress.js.map +1 -0
- package/dist/harness/runtime/reducer.d.ts +5 -0
- package/dist/harness/runtime/reducer.d.ts.map +1 -0
- package/dist/harness/runtime/reducer.js +240 -0
- package/dist/harness/runtime/reducer.js.map +1 -0
- package/dist/harness/runtime/restore.d.ts +24 -0
- package/dist/harness/runtime/restore.d.ts.map +1 -0
- package/dist/harness/runtime/restore.js +117 -0
- package/dist/harness/runtime/restore.js.map +1 -0
- package/dist/harness/runtime/transcript.d.ts +21 -0
- package/dist/harness/runtime/transcript.d.ts.map +1 -0
- package/dist/harness/runtime/transcript.js +72 -0
- package/dist/harness/runtime/transcript.js.map +1 -0
- package/dist/harness/runtime/types.d.ts +105 -0
- package/dist/harness/runtime/types.d.ts.map +1 -0
- package/dist/harness/runtime/types.js +61 -0
- package/dist/harness/runtime/types.js.map +1 -0
- package/dist/harness/session/commit.d.ts +53 -0
- package/dist/harness/session/commit.d.ts.map +1 -0
- package/dist/harness/session/commit.js +57 -0
- package/dist/harness/session/commit.js.map +1 -0
- package/dist/harness/session/context.d.ts +6 -18
- package/dist/harness/session/context.d.ts.map +1 -1
- package/dist/harness/session/context.js +31 -49
- package/dist/harness/session/context.js.map +1 -1
- package/dist/harness/session/fork-policy.d.ts +13 -0
- package/dist/harness/session/fork-policy.d.ts.map +1 -0
- package/dist/harness/session/fork-policy.js +22 -0
- package/dist/harness/session/fork-policy.js.map +1 -0
- package/dist/harness/session/fork.d.ts +18 -0
- package/dist/harness/session/fork.d.ts.map +1 -0
- package/dist/harness/session/fork.js +127 -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 +216 -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 -218
- package/dist/harness/session/jsonl/codec.js.map +1 -1
- 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/legacy-v3.d.ts +18 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts.map +1 -0
- package/dist/harness/session/jsonl/legacy-v3.js +383 -0
- package/dist/harness/session/jsonl/legacy-v3.js.map +1 -0
- package/dist/harness/session/jsonl/repo.d.ts +26 -19
- package/dist/harness/session/jsonl/repo.d.ts.map +1 -1
- package/dist/harness/session/jsonl/repo.js +266 -156
- 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 +238 -181
- 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 +46 -40
- package/dist/harness/session/memory.d.ts.map +1 -1
- package/dist/harness/session/memory.js +346 -113
- 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 +21 -0
- package/dist/harness/session/mutation-line.js.map +1 -0
- package/dist/harness/session/session.d.ts +78 -46
- package/dist/harness/session/session.d.ts.map +1 -1
- package/dist/harness/session/session.js +343 -209
- 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 +21 -0
- package/dist/harness/session/testing/conformance/session-repo.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance/session-repo.js +590 -0
- package/dist/harness/session/testing/conformance/session-repo.js.map +1 -0
- package/dist/harness/session/testing/conformance/storage.d.ts +4 -0
- package/dist/harness/session/testing/conformance/storage.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance/storage.js +600 -0
- package/dist/harness/session/testing/conformance/storage.js.map +1 -0
- package/dist/harness/session/testing/gating-storage.d.ts +26 -0
- package/dist/harness/session/testing/gating-storage.d.ts.map +1 -0
- package/dist/harness/session/testing/gating-storage.js +100 -0
- package/dist/harness/session/testing/gating-storage.js.map +1 -0
- package/dist/harness/session/testing/index.d.ts +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 +16 -0
- package/dist/harness/session/testing/instrumented-storage.js.map +1 -0
- package/dist/harness/session/testing/storage-decorator.d.ts +20 -0
- package/dist/harness/session/testing/storage-decorator.d.ts.map +1 -0
- package/dist/harness/session/testing/storage-decorator.js +41 -0
- package/dist/harness/session/testing/storage-decorator.js.map +1 -0
- package/dist/harness/session/testing/types.d.ts +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 +424 -259
- package/dist/harness/session/types.d.ts.map +1 -1
- package/dist/harness/session/types.js +7 -8
- 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 +10 -10
- 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 +7 -7
- package/dist/harness/tools/write.js.map +1 -1
- package/dist/harness/types.d.ts +108 -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 +12 -5
- package/dist/harness/utils/shell-output.d.ts.map +1 -1
- package/dist/harness/utils/shell-output.js +64 -174
- 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/proxy.d.ts +2 -0
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +40 -10
- package/dist/proxy.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 +25 -4
- package/dist/harness/reducer.d.ts +0 -100
- package/dist/harness/reducer.d.ts.map +0 -1
- package/dist/harness/reducer.js +0 -415
- 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 -19
- 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 -319
- 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
|
@@ -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,C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,EAAE,cAAc,EAAE,IAAI,GAAE,MAAM,EAAO,GAAG,MAAM,CAEpG","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.d.ts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AW,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","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"]}
|
|
@@ -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;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,GAAiB,EACjB,KAAwB,EACkE;IAC1F,MAAM,eAAe,GAAqB,EAAE,CAAC;IAC7C,MAAM,WAAW,GAA+B,EAAE,CAAC;IACnD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3D,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;YACpB,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;gBAC3C,WAAW,CAAC,IAAI,CAAC;oBAChB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,kBAAkB;oBACxB,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO;oBACjC,IAAI;iBACJ,CAAC,CAAC;Y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,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;AAAA,CACd;AAED,qEAAqE;AACrE,MAAM,UAAU,8BAA8B,CAAC,QAAwB,EAAE,IAAI,GAAa,EAAE,EAAU;IACrG,OAAO,cAAc,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAAA,CAC9C","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,EAC0E;IAC1F,MAAM,eAAe,GAAqB,EAAE,CAAC;IAC7C,MAAM,WAAW,GAA+B,EAAE,CAAC;IACnD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3D,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACrD,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;YACpB,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;gBAC3C,WAAW,CAAC,IAAI,CAAC;oBAChB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,kBAAkB;oBACxB,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO;oBACjC,IAAI;iBACJ,CAAC,CAAC;YACJ,CAAC;YACD,SAAS;QACV,CAAC;QACD,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC;QAC9B,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE,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,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;AAAA,CACd;AAED,qEAAqE;AACrE,MAAM,UAAU,8BAA8B,CAAC,QAAwB,EAAE,IAAI,GAAa,EAAE,EAAU;IACrG,OAAO,cAAc,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAAA,CAC9C","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,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port 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.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;OACf,MAAM;QAGL,MAAM;SAGL,MAAM,EAAE,MAAM;;;;UAGb,MAAM,EAAE,MAAM;;;;CAGpB,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,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnE;AAED,MAAM,WAAW,kBAAkB,CAAC,GAAG,SAAS,MAAM;IACrD,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,KAAK,EAAE,KAAK,GAAG,gBAAgB,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/F,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAAC,GAAG,CAAC,CAAC;CACnD;AAED,wBAAgB,WAAW,CAAC,GAAG,SAAS,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAuBjF;;AAED,qBAAa,QAAS,SAAQ,cAAwB;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM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;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,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","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"]}
|
package/dist/harness/result.js
CHANGED
|
@@ -34,6 +34,46 @@ 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
|
+
cause;
|
|
65
|
+
constructor(message, cause) {
|
|
66
|
+
super(message);
|
|
67
|
+
this.name = "HarnessFault";
|
|
68
|
+
this.cause = cause;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export class HarnessClosed extends Error {
|
|
72
|
+
constructor() {
|
|
73
|
+
super("AgentHarness was closed while the operation was active");
|
|
74
|
+
this.name = "HarnessClosed";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
37
77
|
export function matchError(error, matchers) {
|
|
38
78
|
const matcher = matchers[error._tag];
|
|
39
79
|
return matcher(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/harness/result.ts"],"names":[],"mappings":"A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UAAU,UAAU,CACzB,KAAa,EACb,QAAuC,EAC9B;IACT,MAAM,OAAO,GAAI,QAAiE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/F,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;AAAA,CACtB","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 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,EAAyB;QAChD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAAA,CAC3B;IACD,GAAG,CAAS,KAAa,EAAyB;QACjD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAAA,CAC5B;IACD,IAAI,CAAiB,MAA8B,EAAyC;QAC3F,OAAO,MAAM,CAAC,EAAE,CAAC;IAAA,CACjB;IACD,KAAK,CAAiB,MAA8B,EAA0C;QAC7F,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;IAAA,CAClB;CACD,CAAC;AAYF,MAAM,UAAU,WAAW,CAAqB,GAAQ,EAA2B;IAClF,MAAM,gBAAiB,SAAQ,KAAK;QAC1B,IAAI,GAAG,GAAG,CAAC;QAEpB,YAAY,KAAoD,EAAE;YACjE,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;YAChB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAAA,CAC3B;QAED,MAAM,GAA6D;YAClE,MAAM,OAAO,GAA4B,EAAE,CAAC;YAC5C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,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AAM,OAAO,YAAa,SAAQ,KAAK;IAC7B,KAAK,CAAU;IAExB,YAAY,OAAe,EAAE,KAAc,EAAE;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAAA,CACnB;CACD;AAED,MAAM,OAAO,aAAc,SAAQ,KAAK;IACvC,cAAc;QACb,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAAA,CAC5B;CACD;AAMD,MAAM,UAAU,UAAU,CACzB,KAAa,EACb,QAAuC,EAC9B;IACT,MAAM,OAAO,GAAI,QAAiE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/F,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;AAAA,CACtB","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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../../../src/harness/runtime/drive/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG3E,OAAO,KAAK,EACX,uBAAuB,EACvB,mBAAmB,EACnB,YAAY,EACZ,QAAQ,EACR,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,wBAAwB,EACxB,6BAA6B,EAC7B,qBAAqB,EACrB,KAAK,EACL,M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AAE,OAAO,GAC5B,OAAO,CAAC,iBAAiB,CAAC,CA6D5B;AAED,wBAAgB,uBAAuB,CACtC,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,MAAM,EACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACX,YAAY,EAAE,CAKhB;AAED,6FAA6F;AAC7F,wBAAsB,iBAAiB,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EAAE,MAAM,SAAS,uBAAuB,EAClH,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,OAAO,CAAC,mBAAmB,CAAC,cAAc,CAAC,EAAE;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC,EAClF,eAAe,EAAE,SAAS,MAAM,EAAE,EAClC,aAAa,GAAE,YAAY,EAAO,GAChC,OAAO,CAAC,eAAe,CAAC,CA2F1B","sourcesContent":["import type { HarnessEvent, LaneQueuedItem } from \"../../agent-harness.ts\";\nimport { insertEntry } from \"../../session/commit.ts\";\nimport { SessionInvariantError } from \"../../session/session.ts\";\nimport type {\n\tAssistantReadyOperation,\n\tCheckpointOperation,\n\tCommitResult,\n\tNewEntry,\n\tNormalizedRetryPolicy,\n\tOperationScope,\n\tSessionReader,\n\tSummaryDecidingOperation,\n\tSummaryEffectPendingOperation,\n\tSummaryReadyOperation,\n\tWrite,\n} from \"../../session/types.ts\";\nimport { branchTip, deleteValue, pendingEntry, setValue } from \"../../session/values.ts\";\nimport type { Lane } from \"../lane.ts\";\nimport { committedEntryEvents, entryLifecycleEvents, readBoundedContext, readLaneQueues } from \"../transcript.ts\";\nimport type { Drive, LaneState, ProcedureResult } from \"../types.ts\";\nimport { operationCleanupWrites, operationResultRecord } from \"./terminal.ts\";\n\nexport interface BoundaryFinishPending {\n\tkind: \"finish_pending\";\n\tentryIds: string[];\n}\n\nexport interface BoundaryPlacement {\n\tentries: NewEntry[];\n\twrites: Write[];\n\ttipId: string | null;\n\tinbox: LaneState[\"inbox\"];\n\ttriggerEntryId?: string;\n\tqueues?: LaneQueuedItem[];\n}\n\ntype FinishBoundaryOperation =\n\t| CheckpointOperation\n\t| SummaryDecidingOperation\n\t| SummaryReadyOperation\n\t| SummaryEffectPendingOperation;\n\nexport function normalizedRetryPolicy<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n): NormalizedRetryPolicy {\n\tconst retry = lane.readConfig().retryPolicy;\n\treturn retry.enabled\n\t\t? { maxAttempts: retry.maxRetries + 1, baseDelayMs: retry.baseDelayMs }\n\t\t: { maxAttempts: 1, baseDelayMs: retry.baseDelayMs };\n}\n\nexport function assistantReadyAtBoundary<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tstate: LaneState,\n\tscope: OperationScope,\n\ttriggerEntryId: string,\n\toverflowRecoveryUsed: boolean,\n): AssistantReadyOperation {\n\tconst config = lane.readConfig();\n\treturn {\n\t\t...scope,\n\t\tat: \"assistant.ready\",\n\t\tgenerationContext: {\n\t\t\tstepId: lane.session.idGenerator.next(),\n\t\t\ttriggerEntryId,\n\t\t\tconfiguration: state.configuration,\n\t\t\tstreamOptions: config.streamOptions,\n\t\t\tretryPolicy: normalizedRetryPolicy(lane),\n\t\t\toverflowRecoveryUsed,\n\t\t},\n\t\tnextAttempt: 1,\n\t};\n}\n\n/** Select and materialize one boundary's lane-owned input without committing it. */\nexport async function planBoundaryInbox<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tstate: LaneState,\n\tscope: OperationScope,\n\treader: SessionReader,\n\ttipId: string | null,\n\tfollowUpWhenNoTrigger: boolean,\n): Promise<BoundaryPlacement> {\n\tconst steer = state.inbox.filter((item) => item.kind === \"steer\");\n\tconst selectedSteer = scope.settings.steeringMode === \"all\" ? steer : steer.slice(0, 1);\n\tlet selected = state.inbox.filter(\n\t\t(item) => item.kind === \"write\" || selectedSteer.some((candidate) => candidate.entryId === item.entryId),\n\t);\n\tconst load = (items: typeof selected) =>\n\t\tPromise.all(\n\t\t\titems.map(async (item) => {\n\t\t\t\tconst stored = await reader.getValue(pendingEntry(item.entryId), drive.context);\n\t\t\t\tif (stored === undefined) {\n\t\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is missing its payload`);\n\t\t\t\t}\n\t\t\t\tif (item.kind !== \"write\" && stored.value.type !== \"message\") {\n\t\t\t\t\tthrow new SessionInvariantError(`Queued ${item.kind} entry ${item.entryId} is not a message`);\n\t\t\t\t}\n\t\t\t\treturn { item, pending: stored.value };\n\t\t\t}),\n\t\t);\n\tlet pending = await load(selected);\n\tconst projects = (value: (typeof pending)[number][\"pending\"]): boolean =>\n\t\tvalue.type === \"message\" || lane.readConfig().entryProjectors[value.customType] !== undefined;\n\tif (followUpWhenNoTrigger && !pending.some(({ pending: value }) => projects(value))) {\n\t\tconst followUp = state.inbox.filter((item) => item.kind === \"followUp\");\n\t\tconst selectedFollowUp = scope.settings.followUpMode === \"all\" ? followUp : followUp.slice(0, 1);\n\t\tselected = [...selected, ...selectedFollowUp].sort((a, b) => state.inbox.indexOf(a) - state.inbox.indexOf(b));\n\t\tpending = await load(selected);\n\t}\n\n\tlet parentId = tipId;\n\tlet triggerEntryId: string | undefined;\n\tconst entries: NewEntry[] = pending.map(({ item, pending: value }) => {\n\t\tconst entry: NewEntry =\n\t\t\tvalue.type === \"message\"\n\t\t\t\t? { id: item.entryId, parentId, type: \"message\", message: value.payload }\n\t\t\t\t: {\n\t\t\t\t\t\tid: item.entryId,\n\t\t\t\t\t\tparentId,\n\t\t\t\t\t\ttype: \"custom\",\n\t\t\t\t\t\tcustomType: value.customType,\n\t\t\t\t\t\t...(value.payload === undefined ? {} : { data: value.payload }),\n\t\t\t\t\t};\n\t\tparentId = item.entryId;\n\t\tif (projects(value)) triggerEntryId = item.entryId;\n\t\treturn entry;\n\t});\n\tconst selectedIds = new Set(selected.map((item) => item.entryId));\n\tconst inbox = state.inbox.filter((item) => !selectedIds.has(item.entryId));\n\tconst queues = selected.length === 0 ? undefined : await readLaneQueues(reader, inbox, drive.context);\n\treturn {\n\t\tentries,\n\t\twrites: [\n\t\t\t...entries.map((entry) => insertEntry(entry)),\n\t\t\t...selected.map((item) => deleteValue(pendingEntry(item.entryId))),\n\t\t\t...(entries.length === 0 ? [] : [setValue(branchTip(lane.name), parentId)]),\n\t\t],\n\t\ttipId: parentId,\n\t\tinbox,\n\t\t...(triggerEntryId === undefined ? {} : { triggerEntryId }),\n\t\t...(queues === undefined ? {} : { queues }),\n\t};\n}\n\nexport function boundaryPlacementEvents(\n\tplacement: BoundaryPlacement,\n\tcommit: CommitResult,\n\tfirstWriteIndex: number,\n\tlane: string,\n\trunId: string,\n): HarnessEvent[] {\n\treturn [\n\t\t...committedEntryEvents(placement.entries, commit, lane, runId, firstWriteIndex),\n\t\t...(placement.queues === undefined ? [] : [{ type: \"queue_update\" as const, lane, queues: placement.queues }]),\n\t];\n}\n\n/** Replan after before_run_end and commit either renewed work or the terminal run result. */\nexport async function finishRunBoundary<TContext extends object | undefined, TState extends FinishBoundaryOperation>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n\tcontinuation: Extract<CheckpointOperation[\"continuation\"], { kind: \"may_finish\" }>,\n\tplannedEntryIds: readonly string[],\n\tpendingEvents: HarnessEvent[] = [],\n): Promise<ProcedureResult> {\n\tconst context = await readBoundedContext(lane, drive, capability);\n\tif (context.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tconst hook = await lane.hooks.runWithGate(\n\t\t\"before_run_end\",\n\t\t{ lane: lane.name, runId: drive.operationId, messages: context.value },\n\t\tdrive.gate,\n\t\tdrive.context,\n\t);\n\tconst followUp =\n\t\thook?.followUp === undefined\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tid: lane.session.idGenerator.next(),\n\t\t\t\t\tmessage: { role: \"user\" as const, content: hook.followUp, timestamp: Date.now() },\n\t\t\t\t};\n\tconst result = await lane.continueOperation<TState, ProcedureResult>(\n\t\tcapability,\n\t\tasync (state, current, meta, reader) => {\n\t\t\tconst placement = await planBoundaryInbox(lane, drive, state, current, reader, state.tipId, true);\n\t\t\tif (placement.triggerEntryId !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: placement.writes,\n\t\t\t\t\toperationState: assistantReadyAtBoundary(lane, state, current, placement.triggerEntryId, false),\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => [\n\t\t\t\t\t\t...pendingEvents,\n\t\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst hookPlanIsCurrent =\n\t\t\t\tplacement.entries.length === plannedEntryIds.length &&\n\t\t\t\tplacement.entries.every((entry, index) => entry.id === plannedEntryIds[index]);\n\t\t\tif (hookPlanIsCurrent && followUp !== undefined) {\n\t\t\t\tconst entry: NewEntry = {\n\t\t\t\t\tid: followUp.id,\n\t\t\t\t\tparentId: placement.tipId,\n\t\t\t\t\ttype: \"message\",\n\t\t\t\t\tmessage: followUp.message,\n\t\t\t\t};\n\t\t\t\tconst entryWriteIndex = placement.writes.length;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: [...placement.writes, insertEntry(entry), setValue(branchTip(lane.name), followUp.id)],\n\t\t\t\t\toperationState: assistantReadyAtBoundary(lane, state, current, followUp.id, false),\n\t\t\t\t\tlane: { tipId: followUp.id, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => [\n\t\t\t\t\t\t...pendingEvents,\n\t\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t\t...entryLifecycleEvents(\n\t\t\t\t\t\t\t{ ...entry, seq: commit.seqs[entryWriteIndex]!, timestamp: commit.timestamp },\n\t\t\t\t\t\t\tlane.name,\n\t\t\t\t\t\t\tdrive.operationId,\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (placement.tipId === null) throw new SessionInvariantError(\"Completed run has no tip\");\n\t\t\tif (continuation.includeFinalAssistant && current.latestAssistantEntryId === null) {\n\t\t\t\tthrow new SessionInvariantError(\"Completed run is missing its final assistant\");\n\t\t\t}\n\t\t\tconst record = operationResultRecord(meta, \"completed\", placement.tipId);\n\t\t\tconst cleanup = await operationCleanupWrites(reader, drive.operationId, current, drive.context);\n\t\t\treturn {\n\t\t\t\tkind: \"finish\",\n\t\t\t\twrites: [...placement.writes, ...cleanup],\n\t\t\t\trecord,\n\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\tmaterialize: () => ({ kind: \"settled\", outcome: record }) as const,\n\t\t\t\tevents: (commit) => [\n\t\t\t\t\t...pendingEvents,\n\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"run_end\",\n\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\tfromTipId: meta.sourceTipId,\n\t\t\t\t\t\ttipId: placement.tipId,\n\t\t\t\t\t\tendedAt: record.endedAt,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n\treturn result.kind === \"cancel_requested\" ? { kind: \"continue\" } : result.value;\n}\n"]}
|