@m4ike1/ion-agent-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +622 -0
- package/dist/agent-loop.d.ts +24 -0
- package/dist/agent-loop.d.ts.map +1 -0
- package/dist/agent-loop.js +560 -0
- package/dist/agent-loop.js.map +1 -0
- package/dist/agent.d.ts +122 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +422 -0
- package/dist/agent.js.map +1 -0
- package/dist/harness/agent-harness.d.ts +716 -0
- package/dist/harness/agent-harness.d.ts.map +1 -0
- package/dist/harness/agent-harness.js +6 -0
- package/dist/harness/agent-harness.js.map +1 -0
- package/dist/harness/compaction/branch-summarization.d.ts +68 -0
- package/dist/harness/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/harness/compaction/branch-summarization.js +176 -0
- package/dist/harness/compaction/branch-summarization.js.map +1 -0
- package/dist/harness/compaction/compaction.d.ts +126 -0
- package/dist/harness/compaction/compaction.d.ts.map +1 -0
- package/dist/harness/compaction/compaction.js +560 -0
- package/dist/harness/compaction/compaction.js.map +1 -0
- package/dist/harness/compaction/utils.d.ts +25 -0
- package/dist/harness/compaction/utils.d.ts.map +1 -0
- package/dist/harness/compaction/utils.js +120 -0
- package/dist/harness/compaction/utils.js.map +1 -0
- package/dist/harness/config.d.ts +9 -0
- package/dist/harness/config.d.ts.map +1 -0
- package/dist/harness/config.js +35 -0
- package/dist/harness/config.js.map +1 -0
- package/dist/harness/context.d.ts +9 -0
- package/dist/harness/context.d.ts.map +1 -0
- package/dist/harness/context.js +13 -0
- package/dist/harness/context.js.map +1 -0
- package/dist/harness/env/nodejs.d.ts +43 -0
- package/dist/harness/env/nodejs.d.ts.map +1 -0
- package/dist/harness/env/nodejs.js +865 -0
- package/dist/harness/env/nodejs.js.map +1 -0
- package/dist/harness/events.d.ts +25 -0
- package/dist/harness/events.d.ts.map +1 -0
- package/dist/harness/events.js +250 -0
- package/dist/harness/events.js.map +1 -0
- package/dist/harness/execution/assistant.d.ts +42 -0
- package/dist/harness/execution/assistant.d.ts.map +1 -0
- package/dist/harness/execution/assistant.js +82 -0
- package/dist/harness/execution/assistant.js.map +1 -0
- package/dist/harness/execution/effect-gate.d.ts +22 -0
- package/dist/harness/execution/effect-gate.d.ts.map +1 -0
- package/dist/harness/execution/effect-gate.js +49 -0
- package/dist/harness/execution/effect-gate.js.map +1 -0
- package/dist/harness/execution/tools.d.ts +67 -0
- package/dist/harness/execution/tools.d.ts.map +1 -0
- package/dist/harness/execution/tools.js +121 -0
- package/dist/harness/execution/tools.js.map +1 -0
- package/dist/harness/hooks.d.ts +38 -0
- package/dist/harness/hooks.d.ts.map +1 -0
- package/dist/harness/hooks.js +406 -0
- package/dist/harness/hooks.js.map +1 -0
- package/dist/harness/messages.d.ts +51 -0
- package/dist/harness/messages.d.ts.map +1 -0
- package/dist/harness/messages.js +102 -0
- package/dist/harness/messages.js.map +1 -0
- package/dist/harness/prompt-templates.d.ts +49 -0
- package/dist/harness/prompt-templates.d.ts.map +1 -0
- package/dist/harness/prompt-templates.js +225 -0
- package/dist/harness/prompt-templates.js.map +1 -0
- package/dist/harness/result.d.ts +133 -0
- package/dist/harness/result.d.ts.map +1 -0
- package/dist/harness/result.js +81 -0
- package/dist/harness/result.js.map +1 -0
- package/dist/harness/runtime/drive/boundary.d.ts +28 -0
- package/dist/harness/runtime/drive/boundary.d.ts.map +1 -0
- package/dist/harness/runtime/drive/boundary.js +173 -0
- package/dist/harness/runtime/drive/boundary.js.map +1 -0
- package/dist/harness/runtime/drive/checkpoint.d.ts +8 -0
- package/dist/harness/runtime/drive/checkpoint.d.ts.map +1 -0
- package/dist/harness/runtime/drive/checkpoint.js +133 -0
- package/dist/harness/runtime/drive/checkpoint.js.map +1 -0
- package/dist/harness/runtime/drive/deferred.d.ts +15 -0
- package/dist/harness/runtime/drive/deferred.d.ts.map +1 -0
- package/dist/harness/runtime/drive/deferred.js +179 -0
- package/dist/harness/runtime/drive/deferred.js.map +1 -0
- package/dist/harness/runtime/drive/generation.d.ts +8 -0
- package/dist/harness/runtime/drive/generation.d.ts.map +1 -0
- package/dist/harness/runtime/drive/generation.js +205 -0
- package/dist/harness/runtime/drive/generation.js.map +1 -0
- package/dist/harness/runtime/drive/reconcile.d.ts +5 -0
- package/dist/harness/runtime/drive/reconcile.d.ts.map +1 -0
- package/dist/harness/runtime/drive/reconcile.js +140 -0
- package/dist/harness/runtime/drive/reconcile.js.map +1 -0
- package/dist/harness/runtime/drive/recovery.d.ts +8 -0
- package/dist/harness/runtime/drive/recovery.d.ts.map +1 -0
- package/dist/harness/runtime/drive/recovery.js +85 -0
- package/dist/harness/runtime/drive/recovery.js.map +1 -0
- package/dist/harness/runtime/drive/response.d.ts +23 -0
- package/dist/harness/runtime/drive/response.d.ts.map +1 -0
- package/dist/harness/runtime/drive/response.js +394 -0
- package/dist/harness/runtime/drive/response.js.map +1 -0
- package/dist/harness/runtime/drive/retry.d.ts +4 -0
- package/dist/harness/runtime/drive/retry.d.ts.map +1 -0
- package/dist/harness/runtime/drive/retry.js +34 -0
- package/dist/harness/runtime/drive/retry.js.map +1 -0
- package/dist/harness/runtime/drive/structural.d.ts +32 -0
- package/dist/harness/runtime/drive/structural.d.ts.map +1 -0
- package/dist/harness/runtime/drive/structural.js +929 -0
- package/dist/harness/runtime/drive/structural.js.map +1 -0
- package/dist/harness/runtime/drive/terminal.d.ts +7 -0
- package/dist/harness/runtime/drive/terminal.d.ts.map +1 -0
- package/dist/harness/runtime/drive/terminal.js +49 -0
- package/dist/harness/runtime/drive/terminal.js.map +1 -0
- package/dist/harness/runtime/drive/tool-placement.d.ts +14 -0
- package/dist/harness/runtime/drive/tool-placement.d.ts.map +1 -0
- package/dist/harness/runtime/drive/tool-placement.js +244 -0
- package/dist/harness/runtime/drive/tool-placement.js.map +1 -0
- package/dist/harness/runtime/drive/tools.d.ts +6 -0
- package/dist/harness/runtime/drive/tools.d.ts.map +1 -0
- package/dist/harness/runtime/drive/tools.js +449 -0
- package/dist/harness/runtime/drive/tools.js.map +1 -0
- package/dist/harness/runtime/drive.d.ts +6 -0
- package/dist/harness/runtime/drive.d.ts.map +1 -0
- package/dist/harness/runtime/drive.js +93 -0
- package/dist/harness/runtime/drive.js.map +1 -0
- package/dist/harness/runtime/harness.d.ts +59 -0
- package/dist/harness/runtime/harness.d.ts.map +1 -0
- package/dist/harness/runtime/harness.js +311 -0
- package/dist/harness/runtime/harness.js.map +1 -0
- package/dist/harness/runtime/index.d.ts +2 -0
- package/dist/harness/runtime/index.d.ts.map +1 -0
- package/dist/harness/runtime/index.js +2 -0
- package/dist/harness/runtime/index.js.map +1 -0
- package/dist/harness/runtime/lane.d.ts +101 -0
- package/dist/harness/runtime/lane.d.ts.map +1 -0
- package/dist/harness/runtime/lane.js +1575 -0
- package/dist/harness/runtime/lane.js.map +1 -0
- package/dist/harness/runtime/progress.d.ts +15 -0
- package/dist/harness/runtime/progress.d.ts.map +1 -0
- package/dist/harness/runtime/progress.js +66 -0
- package/dist/harness/runtime/progress.js.map +1 -0
- package/dist/harness/runtime/reducer.d.ts +5 -0
- package/dist/harness/runtime/reducer.d.ts.map +1 -0
- package/dist/harness/runtime/reducer.js +240 -0
- package/dist/harness/runtime/reducer.js.map +1 -0
- package/dist/harness/runtime/restore.d.ts +24 -0
- package/dist/harness/runtime/restore.d.ts.map +1 -0
- package/dist/harness/runtime/restore.js +117 -0
- package/dist/harness/runtime/restore.js.map +1 -0
- package/dist/harness/runtime/transcript.d.ts +21 -0
- package/dist/harness/runtime/transcript.d.ts.map +1 -0
- package/dist/harness/runtime/transcript.js +72 -0
- package/dist/harness/runtime/transcript.js.map +1 -0
- package/dist/harness/runtime/types.d.ts +105 -0
- package/dist/harness/runtime/types.d.ts.map +1 -0
- package/dist/harness/runtime/types.js +61 -0
- package/dist/harness/runtime/types.js.map +1 -0
- package/dist/harness/session/commit.d.ts +53 -0
- package/dist/harness/session/commit.d.ts.map +1 -0
- package/dist/harness/session/commit.js +57 -0
- package/dist/harness/session/commit.js.map +1 -0
- package/dist/harness/session/context.d.ts +10 -0
- package/dist/harness/session/context.d.ts.map +1 -0
- package/dist/harness/session/context.js +49 -0
- package/dist/harness/session/context.js.map +1 -0
- package/dist/harness/session/fork-policy.d.ts +21 -0
- package/dist/harness/session/fork-policy.d.ts.map +1 -0
- package/dist/harness/session/fork-policy.js +55 -0
- package/dist/harness/session/fork-policy.js.map +1 -0
- package/dist/harness/session/fork.d.ts +16 -0
- package/dist/harness/session/fork.d.ts.map +1 -0
- package/dist/harness/session/fork.js +79 -0
- package/dist/harness/session/fork.js.map +1 -0
- package/dist/harness/session/in-memory-storage-state.d.ts +39 -0
- package/dist/harness/session/in-memory-storage-state.d.ts.map +1 -0
- package/dist/harness/session/in-memory-storage-state.js +276 -0
- package/dist/harness/session/in-memory-storage-state.js.map +1 -0
- package/dist/harness/session/index.d.ts +11 -0
- package/dist/harness/session/index.d.ts.map +1 -0
- package/dist/harness/session/index.js +9 -0
- package/dist/harness/session/index.js.map +1 -0
- package/dist/harness/session/jsonl/codec.d.ts +21 -0
- package/dist/harness/session/jsonl/codec.d.ts.map +1 -0
- package/dist/harness/session/jsonl/codec.js +45 -0
- package/dist/harness/session/jsonl/codec.js.map +1 -0
- package/dist/harness/session/jsonl/fork.d.ts +38 -0
- package/dist/harness/session/jsonl/fork.d.ts.map +1 -0
- package/dist/harness/session/jsonl/fork.js +264 -0
- package/dist/harness/session/jsonl/fork.js.map +1 -0
- package/dist/harness/session/jsonl/index.d.ts +4 -0
- package/dist/harness/session/jsonl/index.d.ts.map +1 -0
- package/dist/harness/session/jsonl/index.js +4 -0
- package/dist/harness/session/jsonl/index.js.map +1 -0
- package/dist/harness/session/jsonl/io.d.ts +14 -0
- package/dist/harness/session/jsonl/io.d.ts.map +1 -0
- package/dist/harness/session/jsonl/io.js +86 -0
- package/dist/harness/session/jsonl/io.js.map +1 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts +43 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts.map +1 -0
- package/dist/harness/session/jsonl/legacy-v3.js +462 -0
- package/dist/harness/session/jsonl/legacy-v3.js.map +1 -0
- package/dist/harness/session/jsonl/repo.d.ts +35 -0
- package/dist/harness/session/jsonl/repo.d.ts.map +1 -0
- package/dist/harness/session/jsonl/repo.js +301 -0
- package/dist/harness/session/jsonl/repo.js.map +1 -0
- package/dist/harness/session/jsonl/storage.d.ts +40 -0
- package/dist/harness/session/jsonl/storage.d.ts.map +1 -0
- package/dist/harness/session/jsonl/storage.js +200 -0
- package/dist/harness/session/jsonl/storage.js.map +1 -0
- package/dist/harness/session/jsonl/types.d.ts +39 -0
- package/dist/harness/session/jsonl/types.d.ts.map +1 -0
- package/dist/harness/session/jsonl/types.js +3 -0
- package/dist/harness/session/jsonl/types.js.map +1 -0
- package/dist/harness/session/memory.d.ts +48 -0
- package/dist/harness/session/memory.d.ts.map +1 -0
- package/dist/harness/session/memory.js +369 -0
- package/dist/harness/session/memory.js.map +1 -0
- package/dist/harness/session/mutation-line.d.ts +8 -0
- package/dist/harness/session/mutation-line.d.ts.map +1 -0
- package/dist/harness/session/mutation-line.js +21 -0
- package/dist/harness/session/mutation-line.js.map +1 -0
- package/dist/harness/session/session.d.ts +82 -0
- package/dist/harness/session/session.d.ts.map +1 -0
- package/dist/harness/session/session.js +361 -0
- package/dist/harness/session/session.js.map +1 -0
- package/dist/harness/session/testing/benchmark/datasets.d.ts +12 -0
- package/dist/harness/session/testing/benchmark/datasets.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/datasets.js +24 -0
- package/dist/harness/session/testing/benchmark/datasets.js.map +1 -0
- package/dist/harness/session/testing/benchmark/session-repo.d.ts +42 -0
- package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/session-repo.js +127 -0
- package/dist/harness/session/testing/benchmark/session-repo.js.map +1 -0
- package/dist/harness/session/testing/benchmark/storage.d.ts +25 -0
- package/dist/harness/session/testing/benchmark/storage.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/storage.js +114 -0
- package/dist/harness/session/testing/benchmark/storage.js.map +1 -0
- package/dist/harness/session/testing/conformance/session-repo.d.ts +23 -0
- package/dist/harness/session/testing/conformance/session-repo.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance/session-repo.js +809 -0
- package/dist/harness/session/testing/conformance/session-repo.js.map +1 -0
- package/dist/harness/session/testing/conformance/storage.d.ts +4 -0
- package/dist/harness/session/testing/conformance/storage.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance/storage.js +600 -0
- package/dist/harness/session/testing/conformance/storage.js.map +1 -0
- package/dist/harness/session/testing/gating-storage.d.ts +26 -0
- package/dist/harness/session/testing/gating-storage.d.ts.map +1 -0
- package/dist/harness/session/testing/gating-storage.js +100 -0
- package/dist/harness/session/testing/gating-storage.js.map +1 -0
- package/dist/harness/session/testing/index.d.ts +10 -0
- package/dist/harness/session/testing/index.d.ts.map +1 -0
- package/dist/harness/session/testing/index.js +9 -0
- package/dist/harness/session/testing/index.js.map +1 -0
- package/dist/harness/session/testing/instrumented-storage.d.ts +11 -0
- package/dist/harness/session/testing/instrumented-storage.d.ts.map +1 -0
- package/dist/harness/session/testing/instrumented-storage.js +16 -0
- package/dist/harness/session/testing/instrumented-storage.js.map +1 -0
- package/dist/harness/session/testing/storage-decorator.d.ts +20 -0
- package/dist/harness/session/testing/storage-decorator.d.ts.map +1 -0
- package/dist/harness/session/testing/storage-decorator.js +41 -0
- package/dist/harness/session/testing/storage-decorator.js.map +1 -0
- package/dist/harness/session/testing/types.d.ts +12 -0
- package/dist/harness/session/testing/types.d.ts.map +1 -0
- package/dist/harness/session/testing/types.js +2 -0
- package/dist/harness/session/testing/types.js.map +1 -0
- package/dist/harness/session/types.d.ts +512 -0
- package/dist/harness/session/types.d.ts.map +1 -0
- package/dist/harness/session/types.js +9 -0
- package/dist/harness/session/types.js.map +1 -0
- package/dist/harness/session/values.d.ts +95 -0
- package/dist/harness/session/values.d.ts.map +1 -0
- package/dist/harness/session/values.js +81 -0
- package/dist/harness/session/values.js.map +1 -0
- package/dist/harness/skills.d.ts +46 -0
- package/dist/harness/skills.d.ts.map +1 -0
- package/dist/harness/skills.js +326 -0
- package/dist/harness/skills.js.map +1 -0
- package/dist/harness/system-prompt.d.ts +3 -0
- package/dist/harness/system-prompt.d.ts.map +1 -0
- package/dist/harness/system-prompt.js +30 -0
- package/dist/harness/system-prompt.js.map +1 -0
- package/dist/harness/telemetry.d.ts +1242 -0
- package/dist/harness/telemetry.d.ts.map +1 -0
- package/dist/harness/telemetry.js +527 -0
- package/dist/harness/telemetry.js.map +1 -0
- package/dist/harness/tools/bash.d.ts +27 -0
- package/dist/harness/tools/bash.d.ts.map +1 -0
- package/dist/harness/tools/bash.js +105 -0
- package/dist/harness/tools/bash.js.map +1 -0
- package/dist/harness/tools/edit-diff.d.ts +89 -0
- package/dist/harness/tools/edit-diff.d.ts.map +1 -0
- package/dist/harness/tools/edit-diff.js +386 -0
- package/dist/harness/tools/edit-diff.js.map +1 -0
- package/dist/harness/tools/edit.d.ts +19 -0
- package/dist/harness/tools/edit.d.ts.map +1 -0
- package/dist/harness/tools/edit.js +108 -0
- package/dist/harness/tools/edit.js.map +1 -0
- package/dist/harness/tools/file-mutation-queue.d.ts +5 -0
- package/dist/harness/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/harness/tools/file-mutation-queue.js +46 -0
- package/dist/harness/tools/file-mutation-queue.js.map +1 -0
- package/dist/harness/tools/image.d.ts +3 -0
- package/dist/harness/tools/image.d.ts.map +1 -0
- package/dist/harness/tools/image.js +106 -0
- package/dist/harness/tools/image.js.map +1 -0
- package/dist/harness/tools/index.d.ts +6 -0
- package/dist/harness/tools/index.d.ts.map +1 -0
- package/dist/harness/tools/index.js +5 -0
- package/dist/harness/tools/index.js.map +1 -0
- package/dist/harness/tools/path-utils.d.ts +5 -0
- package/dist/harness/tools/path-utils.d.ts.map +1 -0
- package/dist/harness/tools/path-utils.js +26 -0
- package/dist/harness/tools/path-utils.js.map +1 -0
- package/dist/harness/tools/read.d.ts +35 -0
- package/dist/harness/tools/read.d.ts.map +1 -0
- package/dist/harness/tools/read.js +108 -0
- package/dist/harness/tools/read.js.map +1 -0
- package/dist/harness/tools/tool-context.d.ts +6 -0
- package/dist/harness/tools/tool-context.d.ts.map +1 -0
- package/dist/harness/tools/tool-context.js +2 -0
- package/dist/harness/tools/tool-context.js.map +1 -0
- package/dist/harness/tools/write.d.ts +11 -0
- package/dist/harness/tools/write.d.ts.map +1 -0
- package/dist/harness/tools/write.js +31 -0
- package/dist/harness/tools/write.js.map +1 -0
- package/dist/harness/types.d.ts +305 -0
- package/dist/harness/types.d.ts.map +1 -0
- package/dist/harness/types.js +75 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/harness/utils/adaptive-publisher.d.ts +24 -0
- package/dist/harness/utils/adaptive-publisher.d.ts.map +1 -0
- package/dist/harness/utils/adaptive-publisher.js +79 -0
- package/dist/harness/utils/adaptive-publisher.js.map +1 -0
- package/dist/harness/utils/output-capture.d.ts +31 -0
- package/dist/harness/utils/output-capture.d.ts.map +1 -0
- package/dist/harness/utils/output-capture.js +217 -0
- package/dist/harness/utils/output-capture.js.map +1 -0
- package/dist/harness/utils/shell-output.d.ts +29 -0
- package/dist/harness/utils/shell-output.d.ts.map +1 -0
- package/dist/harness/utils/shell-output.js +71 -0
- package/dist/harness/utils/shell-output.js.map +1 -0
- package/dist/harness/utils/truncate.d.ts +71 -0
- package/dist/harness/utils/truncate.d.ts.map +1 -0
- package/dist/harness/utils/truncate.js +296 -0
- package/dist/harness/utils/truncate.js.map +1 -0
- package/dist/harness/utils/usage.d.ts +4 -0
- package/dist/harness/utils/usage.d.ts.map +1 -0
- package/dist/harness/utils/usage.js +33 -0
- package/dist/harness/utils/usage.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +3 -0
- package/dist/node.js.map +1 -0
- package/dist/proxy.d.ts +72 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +310 -0
- package/dist/proxy.js.map +1 -0
- package/dist/search/index.d.ts +29 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +2 -0
- package/dist/search/index.js.map +1 -0
- package/dist/stream-fn.d.ts +10 -0
- package/dist/stream-fn.d.ts.map +1 -0
- package/dist/stream-fn.js +17 -0
- package/dist/stream-fn.js.map +1 -0
- package/dist/types.d.ts +416 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { AssistantMessageFrame } from "@m4ike1/ion-ai";
|
|
2
|
+
import type { AgentToolResult } from "../../types.ts";
|
|
3
|
+
import type { DurableStructuralPreparation, JsonValue, LaneConfiguration, LaneState, OperationMeta, OperationResultRecord, OperationState, PendingEntry } from "./types.ts";
|
|
4
|
+
declare const storedValueType: unique symbol;
|
|
5
|
+
export interface StoredAddressBase {
|
|
6
|
+
readonly namespace: string;
|
|
7
|
+
readonly key: string;
|
|
8
|
+
readonly kind: "value" | "list";
|
|
9
|
+
}
|
|
10
|
+
export interface Value<T> extends StoredAddressBase {
|
|
11
|
+
readonly kind: "value";
|
|
12
|
+
readonly [storedValueType]?: (value: T) => T;
|
|
13
|
+
}
|
|
14
|
+
export interface ValueList<T> extends StoredAddressBase {
|
|
15
|
+
readonly kind: "list";
|
|
16
|
+
readonly [storedValueType]?: (value: T) => T;
|
|
17
|
+
}
|
|
18
|
+
export interface StoredValue<T> {
|
|
19
|
+
address: Value<T>;
|
|
20
|
+
value: T;
|
|
21
|
+
seq: number;
|
|
22
|
+
}
|
|
23
|
+
export interface ListElement<T> {
|
|
24
|
+
seq: number;
|
|
25
|
+
value: T;
|
|
26
|
+
}
|
|
27
|
+
export interface ListCursor {
|
|
28
|
+
seq: number;
|
|
29
|
+
}
|
|
30
|
+
export interface ListReadOptions {
|
|
31
|
+
cursor?: ListCursor;
|
|
32
|
+
order?: "asc" | "desc";
|
|
33
|
+
limit?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface ResolvedListReadOptions {
|
|
36
|
+
cursor?: ListCursor;
|
|
37
|
+
order: "asc" | "desc";
|
|
38
|
+
limit: number;
|
|
39
|
+
}
|
|
40
|
+
export interface ValueSetWrite {
|
|
41
|
+
kind: "value";
|
|
42
|
+
op: "set";
|
|
43
|
+
namespace: string;
|
|
44
|
+
key: string;
|
|
45
|
+
value: unknown;
|
|
46
|
+
}
|
|
47
|
+
export interface ValueDeleteWrite {
|
|
48
|
+
kind: "value";
|
|
49
|
+
op: "delete";
|
|
50
|
+
namespace: string;
|
|
51
|
+
key: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ListAppendWrite {
|
|
54
|
+
kind: "list";
|
|
55
|
+
op: "append";
|
|
56
|
+
namespace: string;
|
|
57
|
+
key: string;
|
|
58
|
+
value: unknown;
|
|
59
|
+
}
|
|
60
|
+
export interface ListDeleteWrite {
|
|
61
|
+
kind: "list";
|
|
62
|
+
op: "delete";
|
|
63
|
+
namespace: string;
|
|
64
|
+
key: string;
|
|
65
|
+
}
|
|
66
|
+
export type ValueWrite = ValueSetWrite | ValueDeleteWrite;
|
|
67
|
+
export type ListWrite = ListAppendWrite | ListDeleteWrite;
|
|
68
|
+
export declare function value<T>(namespace: string, key?: string): Value<T>;
|
|
69
|
+
export declare function list<T>(namespace: string, key?: string): ValueList<T>;
|
|
70
|
+
export declare function setValue<T>(address: Value<T>, next: NoInfer<T>): ValueSetWrite;
|
|
71
|
+
export declare function deleteValue<T>(address: Value<T>): ValueDeleteWrite;
|
|
72
|
+
export declare function appendList<T>(address: ValueList<T>, element: NoInfer<T>): ListAppendWrite;
|
|
73
|
+
export declare function deleteList<T>(address: ValueList<T>): ListDeleteWrite;
|
|
74
|
+
export declare function resolveListReadOptions(options?: ListReadOptions): ResolvedListReadOptions;
|
|
75
|
+
export declare const branchTip: (branch: string) => Value<string | null>;
|
|
76
|
+
export declare const branchTipInventoryPrefix: () => Value<string | null>;
|
|
77
|
+
export declare const laneConfig: (lane: string) => Value<LaneConfiguration>;
|
|
78
|
+
export declare const laneState: (lane: string) => Value<LaneState>;
|
|
79
|
+
export declare const operationResult: (operationId: string) => Value<OperationResultRecord>;
|
|
80
|
+
export declare const operationMeta: (operationId: string) => Value<OperationMeta>;
|
|
81
|
+
export declare const operationState: (operationId: string) => Value<OperationState>;
|
|
82
|
+
export declare const operationToolArgs: (operationId: string, stepId: string, sourceIndex: number) => Value<Record<string, JsonValue>>;
|
|
83
|
+
export declare const operationToolMemo: (operationId: string, invocationId: string, name: string) => Value<JsonValue>;
|
|
84
|
+
export declare const operationPreparation: (operationId: string, taskId: string) => Value<DurableStructuralPreparation>;
|
|
85
|
+
export declare const operationToolArgsPrefix: (operationId: string, stepId?: string | undefined) => Value<Record<string, JsonValue>>;
|
|
86
|
+
export declare const operationToolMemoPrefix: (operationId: string, invocationId?: string | undefined) => Value<JsonValue>;
|
|
87
|
+
export declare const operationPreparationPrefix: (operationId: string) => Value<DurableStructuralPreparation>;
|
|
88
|
+
export declare const pendingEntry: (entryId: string) => Value<PendingEntry>;
|
|
89
|
+
export declare const pendingToolOutput: (operationId: string, invocationId: string) => Value<AgentToolResult<unknown>>;
|
|
90
|
+
export declare const pendingAssistantFrames: (operationId: string, responseEntryId: string) => ValueList<AssistantMessageFrame>;
|
|
91
|
+
export declare const pendingToolOutputPrefix: (operationId: string) => Value<AgentToolResult<unknown>>;
|
|
92
|
+
export declare const sessionName: Value<string>;
|
|
93
|
+
export declare const entryLabel: (entryId: string) => Value<string>;
|
|
94
|
+
export {};
|
|
95
|
+
//# sourceMappingURL=values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../../../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0DAC0C,CAAC;AAE/E,eAAO,MAAM,WAAW,eAAoC,CAAC;AAC7D,eAAO,MAAM,UAAU,oCAAiE,CAAC","sourcesContent":["import type { AssistantMessageFrame } from \"@m4ike1/ion-ai\";\nimport type { AgentToolResult } from \"../../types.ts\";\nimport type {\n\tDurableStructuralPreparation,\n\tJsonValue,\n\tLaneConfiguration,\n\tLaneState,\n\tOperationMeta,\n\tOperationResultRecord,\n\tOperationState,\n\tPendingEntry,\n} from \"./types.ts\";\n\ndeclare const storedValueType: unique symbol;\n\nexport interface StoredAddressBase {\n\treadonly namespace: string;\n\treadonly key: string;\n\treadonly kind: \"value\" | \"list\";\n}\n\nexport interface Value<T> extends StoredAddressBase {\n\treadonly kind: \"value\";\n\treadonly [storedValueType]?: (value: T) => T;\n}\n\nexport interface ValueList<T> extends StoredAddressBase {\n\treadonly kind: \"list\";\n\treadonly [storedValueType]?: (value: T) => T;\n}\n\nexport interface StoredValue<T> {\n\taddress: Value<T>;\n\tvalue: T;\n\tseq: number;\n}\n\nexport interface ListElement<T> {\n\tseq: number;\n\tvalue: T;\n}\n\nexport interface ListCursor {\n\tseq: number;\n}\n\nexport interface ListReadOptions {\n\tcursor?: ListCursor;\n\torder?: \"asc\" | \"desc\";\n\tlimit?: number;\n}\n\nexport interface ResolvedListReadOptions {\n\tcursor?: ListCursor;\n\torder: \"asc\" | \"desc\";\n\tlimit: number;\n}\n\nexport interface ValueSetWrite {\n\tkind: \"value\";\n\top: \"set\";\n\tnamespace: string;\n\tkey: string;\n\tvalue: unknown;\n}\n\nexport interface ValueDeleteWrite {\n\tkind: \"value\";\n\top: \"delete\";\n\tnamespace: string;\n\tkey: string;\n}\n\nexport interface ListAppendWrite {\n\tkind: \"list\";\n\top: \"append\";\n\tnamespace: string;\n\tkey: string;\n\tvalue: unknown;\n}\n\nexport interface ListDeleteWrite {\n\tkind: \"list\";\n\top: \"delete\";\n\tnamespace: string;\n\tkey: string;\n}\n\nexport type ValueWrite = ValueSetWrite | ValueDeleteWrite;\nexport type ListWrite = ListAppendWrite | ListDeleteWrite;\n\nfunction validateAddress(namespace: string, key: string): void {\n\tif (namespace.length === 0) throw new TypeError(\"Value namespace must not be empty\");\n\tif (namespace.includes(\"\\u0000\")) throw new TypeError(\"Value namespace must not contain \\\\u0000\");\n\tif (key.includes(\"\\u0000\")) throw new TypeError(\"Value key must not contain \\\\u0000\");\n}\n\nexport function value<T>(namespace: string, key = \"\"): Value<T> {\n\tvalidateAddress(namespace, key);\n\treturn Object.freeze({ namespace, key, kind: \"value\" }) as Value<T>;\n}\n\nexport function list<T>(namespace: string, key = \"\"): ValueList<T> {\n\tvalidateAddress(namespace, key);\n\treturn Object.freeze({ namespace, key, kind: \"list\" }) as ValueList<T>;\n}\n\nexport function setValue<T>(address: Value<T>, next: NoInfer<T>): ValueSetWrite {\n\treturn {\n\t\tkind: \"value\",\n\t\top: \"set\",\n\t\tnamespace: address.namespace,\n\t\tkey: address.key,\n\t\tvalue: next,\n\t};\n}\n\nexport function deleteValue<T>(address: Value<T>): ValueDeleteWrite {\n\treturn {\n\t\tkind: \"value\",\n\t\top: \"delete\",\n\t\tnamespace: address.namespace,\n\t\tkey: address.key,\n\t};\n}\n\nexport function appendList<T>(address: ValueList<T>, element: NoInfer<T>): ListAppendWrite {\n\treturn {\n\t\tkind: \"list\",\n\t\top: \"append\",\n\t\tnamespace: address.namespace,\n\t\tkey: address.key,\n\t\tvalue: element,\n\t};\n}\n\nexport function deleteList<T>(address: ValueList<T>): ListDeleteWrite {\n\treturn {\n\t\tkind: \"list\",\n\t\top: \"delete\",\n\t\tnamespace: address.namespace,\n\t\tkey: address.key,\n\t};\n}\n\nexport function resolveListReadOptions(options: ListReadOptions = {}): ResolvedListReadOptions {\n\tconst requestedLimit = options.limit ?? 1_000;\n\tif (!Number.isSafeInteger(requestedLimit) || requestedLimit <= 0) {\n\t\tthrow new TypeError(\"List read limit must be a positive safe integer\");\n\t}\n\treturn {\n\t\t...(options.cursor === undefined ? {} : { cursor: options.cursor }),\n\t\torder: options.order ?? \"asc\",\n\t\tlimit: Math.min(requestedLimit, 10_000),\n\t};\n}\n\nexport const branchTip = (branch: string) => value<string | null>(\"ion.branch.tip\", branch);\nexport const branchTipInventoryPrefix = () => value<string | null>(\"ion.branch.tip\");\nexport const laneConfig = (lane: string) => value<LaneConfiguration>(\"ion.lane.config\", lane);\nexport const laneState = (lane: string) => value<LaneState>(\"ion.lane.state\", lane);\nexport const operationResult = (operationId: string) => value<OperationResultRecord>(\"ion.result\", operationId);\n\nexport const operationMeta = (operationId: string) => value<OperationMeta>(\"ion.op.meta\", operationId);\nexport const operationState = (operationId: string) => value<OperationState>(\"ion.op.state\", operationId);\nexport const operationToolArgs = (operationId: string, stepId: string, sourceIndex: number) =>\n\tvalue<Record<string, JsonValue>>(\"ion.op.tool_args\", `${operationId}:${stepId}:${sourceIndex}`);\nexport const operationToolMemo = (operationId: string, invocationId: string, name: string) =>\n\tvalue<JsonValue>(\"ion.op.tool_memo\", `${operationId}:${invocationId}:${name}`);\nexport const operationPreparation = (operationId: string, taskId: string) =>\n\tvalue<DurableStructuralPreparation>(\"ion.op.preparation\", `${operationId}:${taskId}`);\n\nexport const operationToolArgsPrefix = (operationId: string, stepId?: string) =>\n\tvalue<Record<string, JsonValue>>(\n\t\t\"ion.op.tool_args\",\n\t\tstepId === undefined ? `${operationId}:` : `${operationId}:${stepId}:`,\n\t);\nexport const operationToolMemoPrefix = (operationId: string, invocationId?: string) =>\n\tvalue<JsonValue>(\n\t\t\"ion.op.tool_memo\",\n\t\tinvocationId === undefined ? `${operationId}:` : `${operationId}:${invocationId}:`,\n\t);\nexport const operationPreparationPrefix = (operationId: string) =>\n\tvalue<DurableStructuralPreparation>(\"ion.op.preparation\", `${operationId}:`);\n\nexport const pendingEntry = (entryId: string) => value<PendingEntry>(\"ion.pending.entry\", entryId);\nexport const pendingToolOutput = (operationId: string, invocationId: string) =>\n\tvalue<AgentToolResult<unknown>>(\"ion.pending.tool_output\", `${operationId}:${invocationId}`);\nexport const pendingAssistantFrames = (operationId: string, responseEntryId: string) =>\n\tlist<AssistantMessageFrame>(\"ion.pending.assistant_frame\", `${operationId}:${responseEntryId}`);\nexport const pendingToolOutputPrefix = (operationId: string) =>\n\tvalue<AgentToolResult<unknown>>(\"ion.pending.tool_output\", `${operationId}:`);\n\nexport const sessionName = value<string>(\"ion.session.name\");\nexport const entryLabel = (entryId: string) => value<string>(\"ion.entry.label\", entryId);\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
function validateAddress(namespace, key) {
|
|
2
|
+
if (namespace.length === 0)
|
|
3
|
+
throw new TypeError("Value namespace must not be empty");
|
|
4
|
+
if (namespace.includes("\u0000"))
|
|
5
|
+
throw new TypeError("Value namespace must not contain \\u0000");
|
|
6
|
+
if (key.includes("\u0000"))
|
|
7
|
+
throw new TypeError("Value key must not contain \\u0000");
|
|
8
|
+
}
|
|
9
|
+
export function value(namespace, key = "") {
|
|
10
|
+
validateAddress(namespace, key);
|
|
11
|
+
return Object.freeze({ namespace, key, kind: "value" });
|
|
12
|
+
}
|
|
13
|
+
export function list(namespace, key = "") {
|
|
14
|
+
validateAddress(namespace, key);
|
|
15
|
+
return Object.freeze({ namespace, key, kind: "list" });
|
|
16
|
+
}
|
|
17
|
+
export function setValue(address, next) {
|
|
18
|
+
return {
|
|
19
|
+
kind: "value",
|
|
20
|
+
op: "set",
|
|
21
|
+
namespace: address.namespace,
|
|
22
|
+
key: address.key,
|
|
23
|
+
value: next,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function deleteValue(address) {
|
|
27
|
+
return {
|
|
28
|
+
kind: "value",
|
|
29
|
+
op: "delete",
|
|
30
|
+
namespace: address.namespace,
|
|
31
|
+
key: address.key,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function appendList(address, element) {
|
|
35
|
+
return {
|
|
36
|
+
kind: "list",
|
|
37
|
+
op: "append",
|
|
38
|
+
namespace: address.namespace,
|
|
39
|
+
key: address.key,
|
|
40
|
+
value: element,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function deleteList(address) {
|
|
44
|
+
return {
|
|
45
|
+
kind: "list",
|
|
46
|
+
op: "delete",
|
|
47
|
+
namespace: address.namespace,
|
|
48
|
+
key: address.key,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function resolveListReadOptions(options = {}) {
|
|
52
|
+
const requestedLimit = options.limit ?? 1_000;
|
|
53
|
+
if (!Number.isSafeInteger(requestedLimit) || requestedLimit <= 0) {
|
|
54
|
+
throw new TypeError("List read limit must be a positive safe integer");
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
...(options.cursor === undefined ? {} : { cursor: options.cursor }),
|
|
58
|
+
order: options.order ?? "asc",
|
|
59
|
+
limit: Math.min(requestedLimit, 10_000),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export const branchTip = (branch) => value("ion.branch.tip", branch);
|
|
63
|
+
export const branchTipInventoryPrefix = () => value("ion.branch.tip");
|
|
64
|
+
export const laneConfig = (lane) => value("ion.lane.config", lane);
|
|
65
|
+
export const laneState = (lane) => value("ion.lane.state", lane);
|
|
66
|
+
export const operationResult = (operationId) => value("ion.result", operationId);
|
|
67
|
+
export const operationMeta = (operationId) => value("ion.op.meta", operationId);
|
|
68
|
+
export const operationState = (operationId) => value("ion.op.state", operationId);
|
|
69
|
+
export const operationToolArgs = (operationId, stepId, sourceIndex) => value("ion.op.tool_args", `${operationId}:${stepId}:${sourceIndex}`);
|
|
70
|
+
export const operationToolMemo = (operationId, invocationId, name) => value("ion.op.tool_memo", `${operationId}:${invocationId}:${name}`);
|
|
71
|
+
export const operationPreparation = (operationId, taskId) => value("ion.op.preparation", `${operationId}:${taskId}`);
|
|
72
|
+
export const operationToolArgsPrefix = (operationId, stepId) => value("ion.op.tool_args", stepId === undefined ? `${operationId}:` : `${operationId}:${stepId}:`);
|
|
73
|
+
export const operationToolMemoPrefix = (operationId, invocationId) => value("ion.op.tool_memo", invocationId === undefined ? `${operationId}:` : `${operationId}:${invocationId}:`);
|
|
74
|
+
export const operationPreparationPrefix = (operationId) => value("ion.op.preparation", `${operationId}:`);
|
|
75
|
+
export const pendingEntry = (entryId) => value("ion.pending.entry", entryId);
|
|
76
|
+
export const pendingToolOutput = (operationId, invocationId) => value("ion.pending.tool_output", `${operationId}:${invocationId}`);
|
|
77
|
+
export const pendingAssistantFrames = (operationId, responseEntryId) => list("ion.pending.assistant_frame", `${operationId}:${responseEntryId}`);
|
|
78
|
+
export const pendingToolOutputPrefix = (operationId) => value("ion.pending.tool_output", `${operationId}:`);
|
|
79
|
+
export const sessionName = value("ion.session.name");
|
|
80
|
+
export const entryLabel = (entryId) => value("ion.entry.label", entryId);
|
|
81
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.js","sourceRoot":"","sources":["../../../src/harness/session/values.ts"],"names":[],"mappings":"AA2FA,SAAS,eAAe,CAAC,SAAiB,EAAE,GAAW,EAAQ;IAC9D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;IACrF,IAAI,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,0CAA0C,CAAC,CAAC;IAClG,IAAI,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAC;AAAA,CACtF;AAED,MAAM,UAAU,KAAK,CAAI,SAAiB,EAAE,GAAG,GAAG,EAAE,EAAY;IAC/D,eAAe,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAa,CAAC;AAAA,CACpE;AAED,MAAM,UAAU,IAAI,CAAI,SAAiB,EAAE,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IAAI,YAAY,EAAE,CAAC,CAAC;AAC9F,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,WAAmB,EAAE,eAAuB,EAAE,EAAE,CACtF,IAAI,CAAwB,6BAA6B,EAAE,GAAG,WAAW,IAAI,eAAe,EAAE,CAAC,CAAC;AACjG,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,WAAmB,EAAE,EAAE,CAC9D,KAAK,CAA2B,yBAAyB,EAAE,GAAG,WAAW,GAAG,CAAC,CAAC;AAE/E,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAS,kBAAkB,CAAC,CAAC;AAC7D,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,KAAK,CAAS,iBAAiB,EAAE,OAAO,CAAC,CAAC","sourcesContent":["import type { AssistantMessageFrame } from \"@m4ike1/ion-ai\";\nimport type { AgentToolResult } from \"../../types.ts\";\nimport type {\n\tDurableStructuralPreparation,\n\tJsonValue,\n\tLaneConfiguration,\n\tLaneState,\n\tOperationMeta,\n\tOperationResultRecord,\n\tOperationState,\n\tPendingEntry,\n} from \"./types.ts\";\n\ndeclare const storedValueType: unique symbol;\n\nexport interface StoredAddressBase {\n\treadonly namespace: string;\n\treadonly key: string;\n\treadonly kind: \"value\" | \"list\";\n}\n\nexport interface Value<T> extends StoredAddressBase {\n\treadonly kind: \"value\";\n\treadonly [storedValueType]?: (value: T) => T;\n}\n\nexport interface ValueList<T> extends StoredAddressBase {\n\treadonly kind: \"list\";\n\treadonly [storedValueType]?: (value: T) => T;\n}\n\nexport interface StoredValue<T> {\n\taddress: Value<T>;\n\tvalue: T;\n\tseq: number;\n}\n\nexport interface ListElement<T> {\n\tseq: number;\n\tvalue: T;\n}\n\nexport interface ListCursor {\n\tseq: number;\n}\n\nexport interface ListReadOptions {\n\tcursor?: ListCursor;\n\torder?: \"asc\" | \"desc\";\n\tlimit?: number;\n}\n\nexport interface ResolvedListReadOptions {\n\tcursor?: ListCursor;\n\torder: \"asc\" | \"desc\";\n\tlimit: number;\n}\n\nexport interface ValueSetWrite {\n\tkind: \"value\";\n\top: \"set\";\n\tnamespace: string;\n\tkey: string;\n\tvalue: unknown;\n}\n\nexport interface ValueDeleteWrite {\n\tkind: \"value\";\n\top: \"delete\";\n\tnamespace: string;\n\tkey: string;\n}\n\nexport interface ListAppendWrite {\n\tkind: \"list\";\n\top: \"append\";\n\tnamespace: string;\n\tkey: string;\n\tvalue: unknown;\n}\n\nexport interface ListDeleteWrite {\n\tkind: \"list\";\n\top: \"delete\";\n\tnamespace: string;\n\tkey: string;\n}\n\nexport type ValueWrite = ValueSetWrite | ValueDeleteWrite;\nexport type ListWrite = ListAppendWrite | ListDeleteWrite;\n\nfunction validateAddress(namespace: string, key: string): void {\n\tif (namespace.length === 0) throw new TypeError(\"Value namespace must not be empty\");\n\tif (namespace.includes(\"\\u0000\")) throw new TypeError(\"Value namespace must not contain \\\\u0000\");\n\tif (key.includes(\"\\u0000\")) throw new TypeError(\"Value key must not contain \\\\u0000\");\n}\n\nexport function value<T>(namespace: string, key = \"\"): Value<T> {\n\tvalidateAddress(namespace, key);\n\treturn Object.freeze({ namespace, key, kind: \"value\" }) as Value<T>;\n}\n\nexport function list<T>(namespace: string, key = \"\"): ValueList<T> {\n\tvalidateAddress(namespace, key);\n\treturn Object.freeze({ namespace, key, kind: \"list\" }) as ValueList<T>;\n}\n\nexport function setValue<T>(address: Value<T>, next: NoInfer<T>): ValueSetWrite {\n\treturn {\n\t\tkind: \"value\",\n\t\top: \"set\",\n\t\tnamespace: address.namespace,\n\t\tkey: address.key,\n\t\tvalue: next,\n\t};\n}\n\nexport function deleteValue<T>(address: Value<T>): ValueDeleteWrite {\n\treturn {\n\t\tkind: \"value\",\n\t\top: \"delete\",\n\t\tnamespace: address.namespace,\n\t\tkey: address.key,\n\t};\n}\n\nexport function appendList<T>(address: ValueList<T>, element: NoInfer<T>): ListAppendWrite {\n\treturn {\n\t\tkind: \"list\",\n\t\top: \"append\",\n\t\tnamespace: address.namespace,\n\t\tkey: address.key,\n\t\tvalue: element,\n\t};\n}\n\nexport function deleteList<T>(address: ValueList<T>): ListDeleteWrite {\n\treturn {\n\t\tkind: \"list\",\n\t\top: \"delete\",\n\t\tnamespace: address.namespace,\n\t\tkey: address.key,\n\t};\n}\n\nexport function resolveListReadOptions(options: ListReadOptions = {}): ResolvedListReadOptions {\n\tconst requestedLimit = options.limit ?? 1_000;\n\tif (!Number.isSafeInteger(requestedLimit) || requestedLimit <= 0) {\n\t\tthrow new TypeError(\"List read limit must be a positive safe integer\");\n\t}\n\treturn {\n\t\t...(options.cursor === undefined ? {} : { cursor: options.cursor }),\n\t\torder: options.order ?? \"asc\",\n\t\tlimit: Math.min(requestedLimit, 10_000),\n\t};\n}\n\nexport const branchTip = (branch: string) => value<string | null>(\"ion.branch.tip\", branch);\nexport const branchTipInventoryPrefix = () => value<string | null>(\"ion.branch.tip\");\nexport const laneConfig = (lane: string) => value<LaneConfiguration>(\"ion.lane.config\", lane);\nexport const laneState = (lane: string) => value<LaneState>(\"ion.lane.state\", lane);\nexport const operationResult = (operationId: string) => value<OperationResultRecord>(\"ion.result\", operationId);\n\nexport const operationMeta = (operationId: string) => value<OperationMeta>(\"ion.op.meta\", operationId);\nexport const operationState = (operationId: string) => value<OperationState>(\"ion.op.state\", operationId);\nexport const operationToolArgs = (operationId: string, stepId: string, sourceIndex: number) =>\n\tvalue<Record<string, JsonValue>>(\"ion.op.tool_args\", `${operationId}:${stepId}:${sourceIndex}`);\nexport const operationToolMemo = (operationId: string, invocationId: string, name: string) =>\n\tvalue<JsonValue>(\"ion.op.tool_memo\", `${operationId}:${invocationId}:${name}`);\nexport const operationPreparation = (operationId: string, taskId: string) =>\n\tvalue<DurableStructuralPreparation>(\"ion.op.preparation\", `${operationId}:${taskId}`);\n\nexport const operationToolArgsPrefix = (operationId: string, stepId?: string) =>\n\tvalue<Record<string, JsonValue>>(\n\t\t\"ion.op.tool_args\",\n\t\tstepId === undefined ? `${operationId}:` : `${operationId}:${stepId}:`,\n\t);\nexport const operationToolMemoPrefix = (operationId: string, invocationId?: string) =>\n\tvalue<JsonValue>(\n\t\t\"ion.op.tool_memo\",\n\t\tinvocationId === undefined ? `${operationId}:` : `${operationId}:${invocationId}:`,\n\t);\nexport const operationPreparationPrefix = (operationId: string) =>\n\tvalue<DurableStructuralPreparation>(\"ion.op.preparation\", `${operationId}:`);\n\nexport const pendingEntry = (entryId: string) => value<PendingEntry>(\"ion.pending.entry\", entryId);\nexport const pendingToolOutput = (operationId: string, invocationId: string) =>\n\tvalue<AgentToolResult<unknown>>(\"ion.pending.tool_output\", `${operationId}:${invocationId}`);\nexport const pendingAssistantFrames = (operationId: string, responseEntryId: string) =>\n\tlist<AssistantMessageFrame>(\"ion.pending.assistant_frame\", `${operationId}:${responseEntryId}`);\nexport const pendingToolOutputPrefix = (operationId: string) =>\n\tvalue<AgentToolResult<unknown>>(\"ion.pending.tool_output\", `${operationId}:`);\n\nexport const sessionName = value<string>(\"ion.session.name\");\nexport const entryLabel = (entryId: string) => value<string>(\"ion.entry.label\", entryId);\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Context } from "./context.ts";
|
|
2
|
+
import { type ExecutionEnv, type Skill } from "./types.ts";
|
|
3
|
+
export type SkillDiagnosticCode = "file_info_failed" | "list_failed" | "read_failed" | "parse_failed" | "invalid_metadata";
|
|
4
|
+
/** Warning produced while loading skills. */
|
|
5
|
+
export interface SkillDiagnostic {
|
|
6
|
+
/** Diagnostic severity. Currently only warnings are emitted. */
|
|
7
|
+
type: "warning";
|
|
8
|
+
/** Stable diagnostic code. */
|
|
9
|
+
code: SkillDiagnosticCode;
|
|
10
|
+
/** Human-readable diagnostic message. */
|
|
11
|
+
message: string;
|
|
12
|
+
/** Path associated with the diagnostic. */
|
|
13
|
+
path: string;
|
|
14
|
+
}
|
|
15
|
+
/** Format a skill invocation prompt, optionally appending additional user instructions. */
|
|
16
|
+
export declare function formatSkillInvocation(skill: Skill, additionalInstructions?: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Load skills from one or more directories.
|
|
19
|
+
*
|
|
20
|
+
* Traverses directories recursively, loads `SKILL.md` files, loads direct root `.md` files with skill
|
|
21
|
+
* frontmatter, honors ignore files, and returns diagnostics for invalid declared skill files. Missing input
|
|
22
|
+
* directories are skipped.
|
|
23
|
+
*/
|
|
24
|
+
export declare function loadSkills(env: ExecutionEnv, dirs: string | string[], context: Context): Promise<{
|
|
25
|
+
skills: Skill[];
|
|
26
|
+
diagnostics: SkillDiagnostic[];
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Load skills from source-tagged directories.
|
|
30
|
+
*
|
|
31
|
+
* Source values are preserved exactly and attached to every loaded skill and diagnostic. The agent package does not
|
|
32
|
+
* interpret source values; applications define their own provenance shape.
|
|
33
|
+
*/
|
|
34
|
+
export declare function loadSourcedSkills<TSource, TSkill extends Skill = Skill>(env: ExecutionEnv, inputs: Array<{
|
|
35
|
+
path: string;
|
|
36
|
+
source: TSource;
|
|
37
|
+
}>, mapSkill: ((skill: Skill, source: TSource, context: Context) => TSkill) | undefined, context: Context): Promise<{
|
|
38
|
+
skills: Array<{
|
|
39
|
+
skill: TSkill;
|
|
40
|
+
source: TSource;
|
|
41
|
+
}>;
|
|
42
|
+
diagnostics: Array<SkillDiagnostic & {
|
|
43
|
+
source: TSource;
|
|
44
|
+
}>;
|
|
45
|
+
}>;
|
|
46
|
+
//# sourceMappingURL=skills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../../src/harness/skills.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,KAAK,YAAY,EAA8B,KAAK,KAAK,EAAW,MAAM,YAAY,CAAC;AAQhG,MAAM,MAAM,mBAAmB,GAC5B,kBAAkB,GAClB,aAAa,GACb,aAAa,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";\nimport { parse } from \"yaml\";\nimport type { Context } from \"./context.ts\";\nimport { type ExecutionEnv, type FileInfo, type Result, type Skill, toError } from \"./types.ts\";\n\nconst MAX_NAME_LENGTH = 64;\nconst MAX_DESCRIPTION_LENGTH = 1024;\nconst IGNORE_FILE_NAMES = [\".gitignore\", \".ignore\", \".fdignore\"];\n\ntype IgnoreMatcher = ReturnType<typeof ignore>;\n\nexport type SkillDiagnosticCode =\n\t| \"file_info_failed\"\n\t| \"list_failed\"\n\t| \"read_failed\"\n\t| \"parse_failed\"\n\t| \"invalid_metadata\";\n\n/** Warning produced while loading skills. */\nexport interface SkillDiagnostic {\n\t/** Diagnostic severity. Currently only warnings are emitted. */\n\ttype: \"warning\";\n\t/** Stable diagnostic code. */\n\tcode: SkillDiagnosticCode;\n\t/** Human-readable diagnostic message. */\n\tmessage: string;\n\t/** Path associated with the diagnostic. */\n\tpath: string;\n}\n\ninterface SkillFrontmatter {\n\tname?: string;\n\tdescription?: string;\n\t\"disable-model-invocation\"?: boolean;\n\t[key: string]: unknown;\n}\n\n/** Format a skill invocation prompt, optionally appending additional user instructions. */\nexport function formatSkillInvocation(skill: Skill, additionalInstructions?: string): string {\n\tconst skillBlock = `<skill name=\"${skill.name}\" location=\"${skill.filePath}\">\\nReferences are relative to ${dirnameEnvPath(skill.filePath)}.\\n\\n${skill.content}\\n</skill>`;\n\treturn additionalInstructions ? `${skillBlock}\\n\\n${additionalInstructions}` : skillBlock;\n}\n\n/**\n * Load skills from one or more directories.\n *\n * Traverses directories recursively, loads `SKILL.md` files, loads direct root `.md` files with skill\n * frontmatter, honors ignore files, and returns diagnostics for invalid declared skill files. Missing input\n * directories are skipped.\n */\nexport async function loadSkills(\n\tenv: ExecutionEnv,\n\tdirs: string | string[],\n\tcontext: Context,\n): Promise<{ skills: Skill[]; diagnostics: SkillDiagnostic[] }> {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: SkillDiagnostic[] = [];\n\tfor (const dir of Array.isArray(dirs) ? dirs : [dirs]) {\n\t\tconst rootInfoResult = await env.fileInfo(dir, context);\n\t\tif (!rootInfoResult.ok) {\n\t\t\tif (rootInfoResult.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: rootInfoResult.error.message,\n\t\t\t\t\tpath: dir,\n\t\t\t\t});\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst rootInfo = rootInfoResult.value;\n\t\tif ((await resolveKind(env, rootInfo, diagnostics, context)) !== \"directory\") continue;\n\t\tconst result = await loadSkillsFromDirInternal(env, rootInfo.path, true, ignore(), rootInfo.path, context);\n\t\tskills.push(...result.skills);\n\t\tdiagnostics.push(...result.diagnostics);\n\t}\n\treturn { skills, diagnostics };\n}\n\n/**\n * Load skills from source-tagged directories.\n *\n * Source values are preserved exactly and attached to every loaded skill and diagnostic. The agent package does not\n * interpret source values; applications define their own provenance shape.\n */\nexport async function loadSourcedSkills<TSource, TSkill extends Skill = Skill>(\n\tenv: ExecutionEnv,\n\tinputs: Array<{ path: string; source: TSource }>,\n\tmapSkill: ((skill: Skill, source: TSource, context: Context) => TSkill) | undefined,\n\tcontext: Context,\n): Promise<{\n\tskills: Array<{ skill: TSkill; source: TSource }>;\n\tdiagnostics: Array<SkillDiagnostic & { source: TSource }>;\n}> {\n\tconst skills: Array<{ skill: TSkill; source: TSource }> = [];\n\tconst diagnostics: Array<SkillDiagnostic & { source: TSource }> = [];\n\tfor (const input of inputs) {\n\t\tconst result = await loadSkills(env, input.path, context);\n\t\tfor (const skill of result.skills) {\n\t\t\tskills.push({\n\t\t\t\tskill: mapSkill ? mapSkill(skill, input.source, context) : (skill as TSkill),\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 { skills, diagnostics };\n}\n\nasync function loadSkillsFromDirInternal(\n\tenv: ExecutionEnv,\n\tdir: string,\n\tincludeRootFiles: boolean,\n\tignoreMatcher: IgnoreMatcher,\n\trootDir: string,\n\tcontext: Context,\n): Promise<{ skills: Skill[]; diagnostics: SkillDiagnostic[] }> {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: SkillDiagnostic[] = [];\n\n\tconst dirInfoResult = await env.fileInfo(dir, context);\n\tif (!dirInfoResult.ok) {\n\t\tif (dirInfoResult.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: dirInfoResult.error.message,\n\t\t\t\tpath: dir,\n\t\t\t});\n\t\t}\n\t\treturn { skills, diagnostics };\n\t}\n\tconst dirInfo = dirInfoResult.value;\n\tif ((await resolveKind(env, dirInfo, diagnostics, context)) !== \"directory\") return { skills, diagnostics };\n\n\tawait addIgnoreRules(env, ignoreMatcher, dir, rootDir, diagnostics, context);\n\n\tconst entriesResult = await env.listDir(dir, context);\n\tif (!entriesResult.ok) {\n\t\tdiagnostics.push({ type: \"warning\", code: \"list_failed\", message: entriesResult.error.message, path: dir });\n\t\treturn { skills, diagnostics };\n\t}\n\tconst entries = entriesResult.value;\n\n\tfor (const entry of entries) {\n\t\tif (entry.name !== \"SKILL.md\") continue;\n\t\tconst fullPath = entry.path;\n\t\tconst kind = await resolveKind(env, entry, diagnostics, context);\n\t\tif (kind !== \"file\") continue;\n\t\tconst relPath = relativeEnvPath(rootDir, fullPath);\n\t\tif (ignoreMatcher.ignores(relPath)) continue;\n\n\t\tconst result = await loadSkillFromFile(env, fullPath, dirInfo.name, context);\n\t\tif (result.skill) skills.push(result.skill);\n\t\tdiagnostics.push(...result.diagnostics);\n\t\treturn { skills, diagnostics };\n\t}\n\n\tfor (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {\n\t\tif (entry.name.startsWith(\".\") || entry.name === \"node_modules\") continue;\n\t\tconst fullPath = entry.path;\n\t\tconst kind = await resolveKind(env, entry, diagnostics, context);\n\t\tif (!kind) continue;\n\n\t\tconst relPath = relativeEnvPath(rootDir, fullPath);\n\t\tconst ignorePath = kind === \"directory\" ? `${relPath}/` : relPath;\n\t\tif (ignoreMatcher.ignores(ignorePath)) continue;\n\n\t\tif (kind === \"directory\") {\n\t\t\tconst result = await loadSkillsFromDirInternal(env, fullPath, false, ignoreMatcher, rootDir, context);\n\t\t\tskills.push(...result.skills);\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (kind !== \"file\" || !includeRootFiles || !entry.name.endsWith(\".md\")) continue;\n\t\tconst result = await loadSkillFromFile(env, fullPath, dirInfo.name, context);\n\t\tif (result.skill) skills.push(result.skill);\n\t\tdiagnostics.push(...result.diagnostics);\n\t}\n\n\treturn { skills, diagnostics };\n}\n\nasync function addIgnoreRules(\n\tenv: ExecutionEnv,\n\tig: IgnoreMatcher,\n\tdir: string,\n\trootDir: string,\n\tdiagnostics: SkillDiagnostic[],\n\tcontext: Context,\n): Promise<void> {\n\tconst relativeDir = relativeEnvPath(rootDir, dir);\n\tconst prefix = relativeDir ? `${relativeDir}/` : \"\";\n\n\tfor (const filename of IGNORE_FILE_NAMES) {\n\t\tconst ignorePathResult = await env.joinPath([dir, filename], context);\n\t\tif (!ignorePathResult.ok) {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\tmessage: ignorePathResult.error.message,\n\t\t\t\tpath: dir,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tconst ignorePath = ignorePathResult.value;\n\t\tconst info = await env.fileInfo(ignorePath, context);\n\t\tif (!info.ok) {\n\t\t\tif (info.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: info.error.message,\n\t\t\t\t\tpath: ignorePath,\n\t\t\t\t});\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (info.value.kind !== \"file\") continue;\n\t\tconst content = await env.readTextFile(ignorePath, context);\n\t\tif (!content.ok) {\n\t\t\tdiagnostics.push({ type: \"warning\", code: \"read_failed\", message: content.error.message, path: ignorePath });\n\t\t\tcontinue;\n\t\t}\n\t\tconst patterns = content.value\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((line) => prefixIgnorePattern(line, prefix))\n\t\t\t.filter((line): line is string => Boolean(line));\n\t\tif (patterns.length > 0) ig.add(patterns);\n\t}\n}\n\nfunction prefixIgnorePattern(line: string, prefix: string): string | null {\n\tconst trimmed = line.trim();\n\tif (!trimmed) return null;\n\tif (trimmed.startsWith(\"#\") && !trimmed.startsWith(\"\\\\#\")) return null;\n\n\tlet pattern = line;\n\tlet negated = false;\n\tif (pattern.startsWith(\"!\")) {\n\t\tnegated = true;\n\t\tpattern = pattern.slice(1);\n\t} else if (pattern.startsWith(\"\\\\!\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\tif (pattern.startsWith(\"/\")) pattern = pattern.slice(1);\n\tconst prefixed = prefix ? `${prefix}${pattern}` : pattern;\n\treturn negated ? `!${prefixed}` : prefixed;\n}\n\nasync function loadSkillFromFile(\n\tenv: ExecutionEnv,\n\tfilePath: string,\n\tparentDirName: string,\n\tcontext: Context,\n): Promise<{ skill: Skill | null; diagnostics: SkillDiagnostic[] }> {\n\tconst diagnostics: SkillDiagnostic[] = [];\n\tconst isDeclaredSkill =\n\t\tfilePath\n\t\t\t.replace(/[\\\\/]+$/, \"\")\n\t\t\t.split(/[\\\\/]/)\n\t\t\t.pop() === \"SKILL.md\";\n\tconst rawContent = await env.readTextFile(filePath, context);\n\tif (!rawContent.ok) {\n\t\tdiagnostics.push({ type: \"warning\", code: \"read_failed\", message: rawContent.error.message, path: filePath });\n\t\treturn { skill: null, diagnostics };\n\t}\n\n\tconst parsed = parseFrontmatter<SkillFrontmatter>(rawContent.value);\n\tif (!parsed.ok) {\n\t\tif (isDeclaredSkill) {\n\t\t\tdiagnostics.push({ type: \"warning\", code: \"parse_failed\", message: parsed.error.message, path: filePath });\n\t\t}\n\t\treturn { skill: null, diagnostics };\n\t}\n\n\tconst { frontmatter, body } = parsed.value;\n\tconst description = typeof frontmatter.description === \"string\" ? frontmatter.description : undefined;\n\tif (!isDeclaredSkill && (!description || description.trim() === \"\")) {\n\t\treturn { skill: null, diagnostics };\n\t}\n\n\tfor (const error of validateDescription(description)) {\n\t\tdiagnostics.push({ type: \"warning\", code: \"invalid_metadata\", message: error, path: filePath });\n\t}\n\n\tconst frontmatterName = typeof frontmatter.name === \"string\" ? frontmatter.name : undefined;\n\tconst name = frontmatterName || parentDirName;\n\tfor (const error of validateName(name, parentDirName)) {\n\t\tdiagnostics.push({ type: \"warning\", code: \"invalid_metadata\", message: error, path: filePath });\n\t}\n\n\tif (!description || description.trim() === \"\") {\n\t\treturn { skill: null, diagnostics };\n\t}\n\n\treturn {\n\t\tskill: {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\tcontent: body,\n\t\t\tfilePath,\n\t\t\tdisableModelInvocation: frontmatter[\"disable-model-invocation\"] === true,\n\t\t},\n\t\tdiagnostics,\n\t};\n}\n\nfunction validateName(name: string, parentDirName: string): string[] {\n\tconst errors: string[] = [];\n\tif (name !== parentDirName) errors.push(`name \"${name}\" does not match parent directory \"${parentDirName}\"`);\n\tif (name.length > MAX_NAME_LENGTH) errors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);\n\tif (!/^[a-z0-9-]+$/.test(name)) {\n\t\terrors.push(\"name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)\");\n\t}\n\tif (name.startsWith(\"-\") || name.endsWith(\"-\")) errors.push(\"name must not start or end with a hyphen\");\n\tif (name.includes(\"--\")) errors.push(\"name must not contain consecutive hyphens\");\n\treturn errors;\n}\n\nfunction validateDescription(description: string | undefined): string[] {\n\tconst errors: string[] = [];\n\tif (!description || description.trim() === \"\") {\n\t\terrors.push(\"description is required\");\n\t} else if (description.length > MAX_DESCRIPTION_LENGTH) {\n\t\terrors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);\n\t}\n\treturn errors;\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\nasync function resolveKind(\n\tenv: ExecutionEnv,\n\tinfo: FileInfo,\n\tdiagnostics: SkillDiagnostic[],\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 dirnameEnvPath(path: string): string {\n\tconst normalized = path.replace(/[\\\\/]+$/, \"\");\n\tconst separatorIndex = Math.max(normalized.lastIndexOf(\"/\"), normalized.lastIndexOf(\"\\\\\"));\n\tif (separatorIndex === 2 && normalized[1] === \":\") return normalized.slice(0, 3);\n\treturn separatorIndex <= 0 ? \"/\" : normalized.slice(0, separatorIndex);\n}\n\nfunction relativeEnvPath(root: string, path: string): string {\n\tconst normalizedRoot = root.replace(/\\\\/g, \"/\").replace(/\\/+$/, \"\");\n\tconst normalizedPath = path.replace(/\\\\/g, \"/\").replace(/\\/+$/, \"\");\n\tif (normalizedPath === normalizedRoot) return \"\";\n\treturn normalizedPath.startsWith(`${normalizedRoot}/`)\n\t\t? normalizedPath.slice(normalizedRoot.length + 1)\n\t\t: normalizedPath.replace(/^\\/+/, \"\");\n}\n"]}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import ignore from "ignore";
|
|
2
|
+
import { parse } from "yaml";
|
|
3
|
+
import { toError } from "./types.js";
|
|
4
|
+
const MAX_NAME_LENGTH = 64;
|
|
5
|
+
const MAX_DESCRIPTION_LENGTH = 1024;
|
|
6
|
+
const IGNORE_FILE_NAMES = [".gitignore", ".ignore", ".fdignore"];
|
|
7
|
+
/** Format a skill invocation prompt, optionally appending additional user instructions. */
|
|
8
|
+
export function formatSkillInvocation(skill, additionalInstructions) {
|
|
9
|
+
const skillBlock = `<skill name="${skill.name}" location="${skill.filePath}">\nReferences are relative to ${dirnameEnvPath(skill.filePath)}.\n\n${skill.content}\n</skill>`;
|
|
10
|
+
return additionalInstructions ? `${skillBlock}\n\n${additionalInstructions}` : skillBlock;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Load skills from one or more directories.
|
|
14
|
+
*
|
|
15
|
+
* Traverses directories recursively, loads `SKILL.md` files, loads direct root `.md` files with skill
|
|
16
|
+
* frontmatter, honors ignore files, and returns diagnostics for invalid declared skill files. Missing input
|
|
17
|
+
* directories are skipped.
|
|
18
|
+
*/
|
|
19
|
+
export async function loadSkills(env, dirs, context) {
|
|
20
|
+
const skills = [];
|
|
21
|
+
const diagnostics = [];
|
|
22
|
+
for (const dir of Array.isArray(dirs) ? dirs : [dirs]) {
|
|
23
|
+
const rootInfoResult = await env.fileInfo(dir, context);
|
|
24
|
+
if (!rootInfoResult.ok) {
|
|
25
|
+
if (rootInfoResult.error.code !== "not_found") {
|
|
26
|
+
diagnostics.push({
|
|
27
|
+
type: "warning",
|
|
28
|
+
code: "file_info_failed",
|
|
29
|
+
message: rootInfoResult.error.message,
|
|
30
|
+
path: dir,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const rootInfo = rootInfoResult.value;
|
|
36
|
+
if ((await resolveKind(env, rootInfo, diagnostics, context)) !== "directory")
|
|
37
|
+
continue;
|
|
38
|
+
const result = await loadSkillsFromDirInternal(env, rootInfo.path, true, ignore(), rootInfo.path, context);
|
|
39
|
+
skills.push(...result.skills);
|
|
40
|
+
diagnostics.push(...result.diagnostics);
|
|
41
|
+
}
|
|
42
|
+
return { skills, diagnostics };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Load skills from source-tagged directories.
|
|
46
|
+
*
|
|
47
|
+
* Source values are preserved exactly and attached to every loaded skill and diagnostic. The agent package does not
|
|
48
|
+
* interpret source values; applications define their own provenance shape.
|
|
49
|
+
*/
|
|
50
|
+
export async function loadSourcedSkills(env, inputs, mapSkill, context) {
|
|
51
|
+
const skills = [];
|
|
52
|
+
const diagnostics = [];
|
|
53
|
+
for (const input of inputs) {
|
|
54
|
+
const result = await loadSkills(env, input.path, context);
|
|
55
|
+
for (const skill of result.skills) {
|
|
56
|
+
skills.push({
|
|
57
|
+
skill: mapSkill ? mapSkill(skill, input.source, context) : skill,
|
|
58
|
+
source: input.source,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
for (const diagnostic of result.diagnostics)
|
|
62
|
+
diagnostics.push({ ...diagnostic, source: input.source });
|
|
63
|
+
}
|
|
64
|
+
return { skills, diagnostics };
|
|
65
|
+
}
|
|
66
|
+
async function loadSkillsFromDirInternal(env, dir, includeRootFiles, ignoreMatcher, rootDir, context) {
|
|
67
|
+
const skills = [];
|
|
68
|
+
const diagnostics = [];
|
|
69
|
+
const dirInfoResult = await env.fileInfo(dir, context);
|
|
70
|
+
if (!dirInfoResult.ok) {
|
|
71
|
+
if (dirInfoResult.error.code !== "not_found") {
|
|
72
|
+
diagnostics.push({
|
|
73
|
+
type: "warning",
|
|
74
|
+
code: "file_info_failed",
|
|
75
|
+
message: dirInfoResult.error.message,
|
|
76
|
+
path: dir,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return { skills, diagnostics };
|
|
80
|
+
}
|
|
81
|
+
const dirInfo = dirInfoResult.value;
|
|
82
|
+
if ((await resolveKind(env, dirInfo, diagnostics, context)) !== "directory")
|
|
83
|
+
return { skills, diagnostics };
|
|
84
|
+
await addIgnoreRules(env, ignoreMatcher, dir, rootDir, diagnostics, context);
|
|
85
|
+
const entriesResult = await env.listDir(dir, context);
|
|
86
|
+
if (!entriesResult.ok) {
|
|
87
|
+
diagnostics.push({ type: "warning", code: "list_failed", message: entriesResult.error.message, path: dir });
|
|
88
|
+
return { skills, diagnostics };
|
|
89
|
+
}
|
|
90
|
+
const entries = entriesResult.value;
|
|
91
|
+
for (const entry of entries) {
|
|
92
|
+
if (entry.name !== "SKILL.md")
|
|
93
|
+
continue;
|
|
94
|
+
const fullPath = entry.path;
|
|
95
|
+
const kind = await resolveKind(env, entry, diagnostics, context);
|
|
96
|
+
if (kind !== "file")
|
|
97
|
+
continue;
|
|
98
|
+
const relPath = relativeEnvPath(rootDir, fullPath);
|
|
99
|
+
if (ignoreMatcher.ignores(relPath))
|
|
100
|
+
continue;
|
|
101
|
+
const result = await loadSkillFromFile(env, fullPath, dirInfo.name, context);
|
|
102
|
+
if (result.skill)
|
|
103
|
+
skills.push(result.skill);
|
|
104
|
+
diagnostics.push(...result.diagnostics);
|
|
105
|
+
return { skills, diagnostics };
|
|
106
|
+
}
|
|
107
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
108
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
109
|
+
continue;
|
|
110
|
+
const fullPath = entry.path;
|
|
111
|
+
const kind = await resolveKind(env, entry, diagnostics, context);
|
|
112
|
+
if (!kind)
|
|
113
|
+
continue;
|
|
114
|
+
const relPath = relativeEnvPath(rootDir, fullPath);
|
|
115
|
+
const ignorePath = kind === "directory" ? `${relPath}/` : relPath;
|
|
116
|
+
if (ignoreMatcher.ignores(ignorePath))
|
|
117
|
+
continue;
|
|
118
|
+
if (kind === "directory") {
|
|
119
|
+
const result = await loadSkillsFromDirInternal(env, fullPath, false, ignoreMatcher, rootDir, context);
|
|
120
|
+
skills.push(...result.skills);
|
|
121
|
+
diagnostics.push(...result.diagnostics);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (kind !== "file" || !includeRootFiles || !entry.name.endsWith(".md"))
|
|
125
|
+
continue;
|
|
126
|
+
const result = await loadSkillFromFile(env, fullPath, dirInfo.name, context);
|
|
127
|
+
if (result.skill)
|
|
128
|
+
skills.push(result.skill);
|
|
129
|
+
diagnostics.push(...result.diagnostics);
|
|
130
|
+
}
|
|
131
|
+
return { skills, diagnostics };
|
|
132
|
+
}
|
|
133
|
+
async function addIgnoreRules(env, ig, dir, rootDir, diagnostics, context) {
|
|
134
|
+
const relativeDir = relativeEnvPath(rootDir, dir);
|
|
135
|
+
const prefix = relativeDir ? `${relativeDir}/` : "";
|
|
136
|
+
for (const filename of IGNORE_FILE_NAMES) {
|
|
137
|
+
const ignorePathResult = await env.joinPath([dir, filename], context);
|
|
138
|
+
if (!ignorePathResult.ok) {
|
|
139
|
+
diagnostics.push({
|
|
140
|
+
type: "warning",
|
|
141
|
+
code: "file_info_failed",
|
|
142
|
+
message: ignorePathResult.error.message,
|
|
143
|
+
path: dir,
|
|
144
|
+
});
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const ignorePath = ignorePathResult.value;
|
|
148
|
+
const info = await env.fileInfo(ignorePath, context);
|
|
149
|
+
if (!info.ok) {
|
|
150
|
+
if (info.error.code !== "not_found") {
|
|
151
|
+
diagnostics.push({
|
|
152
|
+
type: "warning",
|
|
153
|
+
code: "file_info_failed",
|
|
154
|
+
message: info.error.message,
|
|
155
|
+
path: ignorePath,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (info.value.kind !== "file")
|
|
161
|
+
continue;
|
|
162
|
+
const content = await env.readTextFile(ignorePath, context);
|
|
163
|
+
if (!content.ok) {
|
|
164
|
+
diagnostics.push({ type: "warning", code: "read_failed", message: content.error.message, path: ignorePath });
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const patterns = content.value
|
|
168
|
+
.split(/\r?\n/)
|
|
169
|
+
.map((line) => prefixIgnorePattern(line, prefix))
|
|
170
|
+
.filter((line) => Boolean(line));
|
|
171
|
+
if (patterns.length > 0)
|
|
172
|
+
ig.add(patterns);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function prefixIgnorePattern(line, prefix) {
|
|
176
|
+
const trimmed = line.trim();
|
|
177
|
+
if (!trimmed)
|
|
178
|
+
return null;
|
|
179
|
+
if (trimmed.startsWith("#") && !trimmed.startsWith("\\#"))
|
|
180
|
+
return null;
|
|
181
|
+
let pattern = line;
|
|
182
|
+
let negated = false;
|
|
183
|
+
if (pattern.startsWith("!")) {
|
|
184
|
+
negated = true;
|
|
185
|
+
pattern = pattern.slice(1);
|
|
186
|
+
}
|
|
187
|
+
else if (pattern.startsWith("\\!")) {
|
|
188
|
+
pattern = pattern.slice(1);
|
|
189
|
+
}
|
|
190
|
+
if (pattern.startsWith("/"))
|
|
191
|
+
pattern = pattern.slice(1);
|
|
192
|
+
const prefixed = prefix ? `${prefix}${pattern}` : pattern;
|
|
193
|
+
return negated ? `!${prefixed}` : prefixed;
|
|
194
|
+
}
|
|
195
|
+
async function loadSkillFromFile(env, filePath, parentDirName, context) {
|
|
196
|
+
const diagnostics = [];
|
|
197
|
+
const isDeclaredSkill = filePath
|
|
198
|
+
.replace(/[\\/]+$/, "")
|
|
199
|
+
.split(/[\\/]/)
|
|
200
|
+
.pop() === "SKILL.md";
|
|
201
|
+
const rawContent = await env.readTextFile(filePath, context);
|
|
202
|
+
if (!rawContent.ok) {
|
|
203
|
+
diagnostics.push({ type: "warning", code: "read_failed", message: rawContent.error.message, path: filePath });
|
|
204
|
+
return { skill: null, diagnostics };
|
|
205
|
+
}
|
|
206
|
+
const parsed = parseFrontmatter(rawContent.value);
|
|
207
|
+
if (!parsed.ok) {
|
|
208
|
+
if (isDeclaredSkill) {
|
|
209
|
+
diagnostics.push({ type: "warning", code: "parse_failed", message: parsed.error.message, path: filePath });
|
|
210
|
+
}
|
|
211
|
+
return { skill: null, diagnostics };
|
|
212
|
+
}
|
|
213
|
+
const { frontmatter, body } = parsed.value;
|
|
214
|
+
const description = typeof frontmatter.description === "string" ? frontmatter.description : undefined;
|
|
215
|
+
if (!isDeclaredSkill && (!description || description.trim() === "")) {
|
|
216
|
+
return { skill: null, diagnostics };
|
|
217
|
+
}
|
|
218
|
+
for (const error of validateDescription(description)) {
|
|
219
|
+
diagnostics.push({ type: "warning", code: "invalid_metadata", message: error, path: filePath });
|
|
220
|
+
}
|
|
221
|
+
const frontmatterName = typeof frontmatter.name === "string" ? frontmatter.name : undefined;
|
|
222
|
+
const name = frontmatterName || parentDirName;
|
|
223
|
+
for (const error of validateName(name, parentDirName)) {
|
|
224
|
+
diagnostics.push({ type: "warning", code: "invalid_metadata", message: error, path: filePath });
|
|
225
|
+
}
|
|
226
|
+
if (!description || description.trim() === "") {
|
|
227
|
+
return { skill: null, diagnostics };
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
skill: {
|
|
231
|
+
name,
|
|
232
|
+
description,
|
|
233
|
+
content: body,
|
|
234
|
+
filePath,
|
|
235
|
+
disableModelInvocation: frontmatter["disable-model-invocation"] === true,
|
|
236
|
+
},
|
|
237
|
+
diagnostics,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function validateName(name, parentDirName) {
|
|
241
|
+
const errors = [];
|
|
242
|
+
if (name !== parentDirName)
|
|
243
|
+
errors.push(`name "${name}" does not match parent directory "${parentDirName}"`);
|
|
244
|
+
if (name.length > MAX_NAME_LENGTH)
|
|
245
|
+
errors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);
|
|
246
|
+
if (!/^[a-z0-9-]+$/.test(name)) {
|
|
247
|
+
errors.push("name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)");
|
|
248
|
+
}
|
|
249
|
+
if (name.startsWith("-") || name.endsWith("-"))
|
|
250
|
+
errors.push("name must not start or end with a hyphen");
|
|
251
|
+
if (name.includes("--"))
|
|
252
|
+
errors.push("name must not contain consecutive hyphens");
|
|
253
|
+
return errors;
|
|
254
|
+
}
|
|
255
|
+
function validateDescription(description) {
|
|
256
|
+
const errors = [];
|
|
257
|
+
if (!description || description.trim() === "") {
|
|
258
|
+
errors.push("description is required");
|
|
259
|
+
}
|
|
260
|
+
else if (description.length > MAX_DESCRIPTION_LENGTH) {
|
|
261
|
+
errors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);
|
|
262
|
+
}
|
|
263
|
+
return errors;
|
|
264
|
+
}
|
|
265
|
+
function parseFrontmatter(content) {
|
|
266
|
+
try {
|
|
267
|
+
const normalized = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
268
|
+
if (!normalized.startsWith("---"))
|
|
269
|
+
return { ok: true, value: { frontmatter: {}, body: normalized } };
|
|
270
|
+
const endIndex = normalized.indexOf("\n---", 3);
|
|
271
|
+
if (endIndex === -1)
|
|
272
|
+
return { ok: true, value: { frontmatter: {}, body: normalized } };
|
|
273
|
+
const yamlString = normalized.slice(4, endIndex);
|
|
274
|
+
const body = normalized.slice(endIndex + 4).trim();
|
|
275
|
+
return { ok: true, value: { frontmatter: (parse(yamlString) ?? {}), body } };
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
return { ok: false, error: toError(error) };
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async function resolveKind(env, info, diagnostics, context) {
|
|
282
|
+
if (info.kind === "file" || info.kind === "directory")
|
|
283
|
+
return info.kind;
|
|
284
|
+
const canonicalPath = await env.canonicalPath(info.path, context);
|
|
285
|
+
if (!canonicalPath.ok) {
|
|
286
|
+
if (canonicalPath.error.code !== "not_found") {
|
|
287
|
+
diagnostics.push({
|
|
288
|
+
type: "warning",
|
|
289
|
+
code: "file_info_failed",
|
|
290
|
+
message: canonicalPath.error.message,
|
|
291
|
+
path: info.path,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
return undefined;
|
|
295
|
+
}
|
|
296
|
+
const target = await env.fileInfo(canonicalPath.value, context);
|
|
297
|
+
if (!target.ok) {
|
|
298
|
+
if (target.error.code !== "not_found") {
|
|
299
|
+
diagnostics.push({
|
|
300
|
+
type: "warning",
|
|
301
|
+
code: "file_info_failed",
|
|
302
|
+
message: target.error.message,
|
|
303
|
+
path: info.path,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|
|
308
|
+
return target.value.kind === "file" || target.value.kind === "directory" ? target.value.kind : undefined;
|
|
309
|
+
}
|
|
310
|
+
function dirnameEnvPath(path) {
|
|
311
|
+
const normalized = path.replace(/[\\/]+$/, "");
|
|
312
|
+
const separatorIndex = Math.max(normalized.lastIndexOf("/"), normalized.lastIndexOf("\\"));
|
|
313
|
+
if (separatorIndex === 2 && normalized[1] === ":")
|
|
314
|
+
return normalized.slice(0, 3);
|
|
315
|
+
return separatorIndex <= 0 ? "/" : normalized.slice(0, separatorIndex);
|
|
316
|
+
}
|
|
317
|
+
function relativeEnvPath(root, path) {
|
|
318
|
+
const normalizedRoot = root.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
319
|
+
const normalizedPath = path.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
320
|
+
if (normalizedPath === normalizedRoot)
|
|
321
|
+
return "";
|
|
322
|
+
return normalizedPath.startsWith(`${normalizedRoot}/`)
|
|
323
|
+
? normalizedPath.slice(normalizedRoot.length + 1)
|
|
324
|
+
: normalizedPath.replace(/^\/+/, "");
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=skills.js.map
|