@draht/coding-agent 2026.10.20-1 → 2026.10.23-1
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/CHANGELOG.md +138 -0
- package/agents/advisor.md +2 -2
- package/agents/architect.md +11 -33
- package/agents/debugger.md +13 -54
- package/agents/git-committer.md +18 -42
- package/agents/implementer.md +14 -36
- package/agents/investigator.md +12 -63
- package/agents/reviewer.md +16 -44
- package/agents/security-auditor.md +22 -56
- package/agents/spec-reviewer.md +13 -53
- package/agents/verifier.md +14 -33
- package/bin/drahtbank.mjs +4 -0
- package/dist/agents/advisor.md +2 -2
- package/dist/agents/architect.md +11 -33
- package/dist/agents/debugger.md +13 -54
- package/dist/agents/git-committer.md +18 -42
- package/dist/agents/implementer.md +14 -36
- package/dist/agents/investigator.md +12 -63
- package/dist/agents/reviewer.md +16 -44
- package/dist/agents/security-auditor.md +22 -56
- package/dist/agents/spec-reviewer.md +13 -53
- package/dist/agents/verifier.md +14 -33
- package/dist/bundle/chunks/anthropic-messages-G57VPNTF.js +6 -0
- package/dist/bundle/chunks/anthropic.js +1 -1
- package/dist/bundle/chunks/azure-openai-responses-AYUCZ5WN.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +23 -20
- package/dist/bundle/chunks/chunk-3GDEPGTR.js +16 -0
- package/dist/bundle/chunks/chunk-5JW3NSTV.js +2 -0
- package/dist/bundle/chunks/{chunk-FHX2S5IG.js → chunk-6WESOD4H.js} +1 -1
- package/dist/bundle/chunks/chunk-76YNMQ57.js +2 -0
- package/dist/bundle/chunks/chunk-AC3MSTC6.js +2 -0
- package/dist/bundle/chunks/chunk-ACLWH5WQ.js +2 -0
- package/dist/bundle/chunks/chunk-BL72B6LV.js +82 -0
- package/dist/bundle/chunks/{chunk-5QJFWTKA.js → chunk-CLKG6K6Z.js} +5 -2
- package/dist/bundle/chunks/chunk-DN7SM3LX.js +479 -0
- package/dist/bundle/chunks/{chunk-UTRX2VHB.js → chunk-DOUMZTXH.js} +3 -3
- package/dist/bundle/chunks/chunk-DQ4G4IS4.js +20 -0
- package/dist/bundle/chunks/chunk-E4VZJRJ2.js +9 -0
- package/dist/bundle/chunks/chunk-FOYIPAAD.js +6 -0
- package/dist/bundle/chunks/chunk-FXCTQRNN.js +2 -0
- package/dist/bundle/chunks/chunk-GQXRTK54.js +20 -0
- package/dist/bundle/chunks/chunk-IGO52ZOY.js +132 -0
- package/dist/bundle/chunks/{chunk-VXUJMEMO.js → chunk-IT4RIOZD.js} +1 -1
- package/dist/bundle/chunks/chunk-JJKPUMH2.js +1424 -0
- package/dist/bundle/chunks/chunk-JNWRE5F4.js +2 -0
- package/dist/bundle/chunks/chunk-KSGHCBHT.js +2 -0
- package/dist/bundle/chunks/chunk-MBFTIGLS.js +2 -0
- package/dist/bundle/chunks/chunk-N26RGV3K.js +11 -0
- package/dist/bundle/chunks/{chunk-KPO5375S.js → chunk-RCRGGYLW.js} +1 -1
- package/dist/bundle/chunks/chunk-UCJ7FLSO.js +166 -0
- package/dist/bundle/chunks/chunk-USCN7R2E.js +2 -0
- package/dist/bundle/chunks/chunk-WFHH5SX6.js +4 -0
- package/dist/bundle/chunks/chunk-WYWBXNDO.js +6 -0
- package/dist/bundle/chunks/chunk-ZRPAOMVB.js +2 -0
- package/dist/bundle/chunks/{cli-VCHSHNKT.js → cli-HTUB6WOG.js} +6 -6
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-RRSO6OXX.js +2 -0
- package/dist/bundle/chunks/codemode-worker.js +188 -21
- package/dist/bundle/chunks/execute-UUPNZJJG.js +31 -0
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/google-generative-ai-VJSS5EBX.js +2 -0
- package/dist/bundle/chunks/google-vertex-K23DBWTT.js +2 -0
- package/dist/bundle/chunks/image-resize-worker.js +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-EJ5XMSQL.js → llama-cpp-classify-3VDXTYVJ.js} +3 -3
- package/dist/bundle/chunks/mistral-conversations-SKVQJGFZ.js +5 -0
- package/dist/bundle/chunks/node-DXZFQBEO.js +16 -0
- package/dist/bundle/chunks/{node-6IIDYB3K.js → node-LBZLUIBE.js} +1 -1
- package/dist/bundle/chunks/openai-chatgpt.js +1 -1
- package/dist/bundle/chunks/openai-codex-responses-LV4RIZL3.js +10 -0
- package/dist/bundle/chunks/openai-codex.js +1 -1
- package/dist/bundle/chunks/openai-completions-PUIR2V25.js +7 -0
- package/dist/bundle/chunks/openai-decisions-2DJLSYQF.js +5 -0
- package/dist/bundle/chunks/openai-responses-6ESQOXAF.js +4 -0
- package/dist/bundle/chunks/opencode-go.js +1 -1
- package/dist/bundle/chunks/openrouter-images-TVXBMY3V.js +2 -0
- package/dist/bundle/chunks/pi-messages-XS7FDWQI.js +8 -0
- package/dist/bundle/chunks/runtime-IB3XQ7E3.js +2 -0
- package/dist/bundle/chunks/runtime-LB35PK4J.js +3 -0
- package/dist/bundle/chunks/settings-manager-YNY5F4RU.js +2 -0
- package/dist/bundle/chunks/typesafe-system-one-67GAWZXE.js +2 -0
- package/dist/bundle/chunks/virtual-modules-U4CBGVMI.js +2 -0
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.d.ts +2 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +30 -8
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +4 -4
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/config.d.ts +18 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +44 -6
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +65 -8
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +240 -102
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +20 -13
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +42 -52
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/bug-report.d.ts +9 -1
- package/dist/core/bug-report.d.ts.map +1 -1
- package/dist/core/builtins/completion-checks.d.ts +3 -0
- package/dist/core/builtins/completion-checks.d.ts.map +1 -0
- package/dist/core/builtins/completion-checks.js +142 -0
- package/dist/core/builtins/completion-checks.js.map +1 -0
- package/dist/core/builtins/duet.d.ts.map +1 -1
- package/dist/core/builtins/duet.js +7 -5
- package/dist/core/builtins/duet.js.map +1 -1
- package/dist/core/builtins/git-safety.d.ts +3 -0
- package/dist/core/builtins/git-safety.d.ts.map +1 -0
- package/dist/core/builtins/git-safety.js +34 -0
- package/dist/core/builtins/git-safety.js.map +1 -0
- package/dist/core/builtins/index.d.ts.map +1 -1
- package/dist/core/builtins/index.js +4 -0
- package/dist/core/builtins/index.js.map +1 -1
- package/dist/core/client-identity.d.ts +8 -0
- package/dist/core/client-identity.d.ts.map +1 -0
- package/dist/core/client-identity.js +15 -0
- package/dist/core/client-identity.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +1 -2
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +2 -2
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +20 -15
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/utils.d.ts +6 -0
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js +7 -8
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +2 -0
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template.html +1 -0
- package/dist/core/export-html/template.js +23 -17
- package/dist/core/export-html/tool-renderer.d.ts +3 -3
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +5 -3
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
- package/dist/core/export-html/vendor/marked.min.js +30 -29
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +7 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +6 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +16 -4
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +61 -7
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +2 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/key-id-schema.d.ts +6 -0
- package/dist/core/key-id-schema.d.ts.map +1 -0
- package/dist/core/key-id-schema.js +16 -0
- package/dist/core/key-id-schema.js.map +1 -0
- package/dist/core/keybindings-schema.d.ts +4 -0
- package/dist/core/keybindings-schema.d.ts.map +1 -0
- package/dist/core/keybindings-schema.js +16 -0
- package/dist/core/keybindings-schema.js.map +1 -0
- package/dist/core/keybindings.d.ts +242 -75
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +30 -23
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/mcp-servers.d.ts +22 -0
- package/dist/core/mcp-servers.d.ts.map +1 -1
- package/dist/core/mcp-servers.js +72 -11
- package/dist/core/mcp-servers.js.map +1 -1
- package/dist/core/model-config.d.ts +1623 -74
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +70 -184
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +3 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +4 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +56 -43
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +253 -358
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +19 -10
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/nested-tool-calls.d.ts +1 -0
- package/dist/core/nested-tool-calls.d.ts.map +1 -1
- package/dist/core/nested-tool-calls.js +1 -0
- package/dist/core/nested-tool-calls.js.map +1 -1
- package/dist/core/package-manager.js +3 -3
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/polyphase/keyword.js +1 -1
- package/dist/core/polyphase/keyword.js.map +1 -1
- package/dist/core/polyphase/model-selection.d.ts.map +1 -1
- package/dist/core/polyphase/model-selection.js +15 -7
- package/dist/core/polyphase/model-selection.js.map +1 -1
- package/dist/core/polyphase/workflow/prelude.d.ts +2 -0
- package/dist/core/polyphase/workflow/prelude.d.ts.map +1 -1
- package/dist/core/polyphase/workflow/prelude.js +12 -16
- package/dist/core/polyphase/workflow/prelude.js.map +1 -1
- package/dist/core/polyphase/workflow/runtime.d.ts.map +1 -1
- package/dist/core/polyphase/workflow/runtime.js +2 -1
- package/dist/core/polyphase/workflow/runtime.js.map +1 -1
- package/dist/core/project-trust.d.ts.map +1 -1
- package/dist/core/project-trust.js +2 -1
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +7 -2
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-composer.d.ts +2 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +13 -0
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/radius.d.ts +2 -0
- package/dist/core/radius.d.ts.map +1 -1
- package/dist/core/radius.js +2 -0
- package/dist/core/radius.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts +12 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +84 -24
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts +3 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +7 -4
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +13 -4
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +27 -15
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +65 -0
- package/dist/core/settings-defaults.d.ts.map +1 -0
- package/dist/core/settings-defaults.js +66 -0
- package/dist/core/settings-defaults.js.map +1 -0
- package/dist/core/settings-manager.d.ts +17 -178
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +86 -57
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +269 -0
- package/dist/core/settings-schema.d.ts.map +1 -0
- package/dist/core/settings-schema.js +318 -0
- package/dist/core/settings-schema.js.map +1 -0
- package/dist/core/skills.d.ts +4 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +6 -1
- package/dist/core/skills.js.map +1 -1
- package/dist/core/system-prompt.d.ts +6 -0
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +10 -5
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +3 -5
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/grep.d.ts +8 -0
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +19 -7
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +2 -0
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +2 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +4 -10
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/path-utils.d.ts +1 -1
- package/dist/core/tools/path-utils.d.ts.map +1 -1
- package/dist/core/tools/path-utils.js +6 -6
- package/dist/core/tools/path-utils.js.map +1 -1
- package/dist/core/tools/read.d.ts +13 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +32 -2
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +20 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +67 -0
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js +7 -35
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/core/tools/renderers/edit.d.ts.map +1 -1
- package/dist/core/tools/renderers/edit.js +5 -4
- package/dist/core/tools/renderers/edit.js.map +1 -1
- package/dist/core/tools/renderers/index.d.ts +2 -2
- package/dist/core/tools/renderers/index.d.ts.map +1 -1
- package/dist/core/tools/renderers/index.js.map +1 -1
- package/dist/core/tools/renderers/read.d.ts.map +1 -1
- package/dist/core/tools/renderers/read.js +7 -11
- package/dist/core/tools/renderers/read.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +391 -80
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/index.d.ts.map +1 -1
- package/dist/extensions/codemode/index.js +3 -1
- package/dist/extensions/codemode/index.js.map +1 -1
- package/dist/extensions/codemode/renderer.d.ts +2 -2
- package/dist/extensions/codemode/renderer.d.ts.map +1 -1
- package/dist/extensions/codemode/renderer.js +9 -3
- package/dist/extensions/codemode/renderer.js.map +1 -1
- package/dist/extensions/codemode/tool.d.ts +22 -21
- package/dist/extensions/codemode/tool.d.ts.map +1 -1
- package/dist/extensions/codemode/tool.js +96 -123
- package/dist/extensions/codemode/tool.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +34 -11
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/extensions/mcp/cli.d.ts.map +1 -1
- package/dist/extensions/mcp/cli.js +27 -33
- package/dist/extensions/mcp/cli.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts +15 -3
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +49 -12
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/extensions/mcp/index.d.ts +4 -1
- package/dist/extensions/mcp/index.d.ts.map +1 -1
- package/dist/extensions/mcp/index.js +279 -129
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/oauth.d.ts +21 -11
- package/dist/extensions/mcp/oauth.d.ts.map +1 -1
- package/dist/extensions/mcp/oauth.js +166 -45
- package/dist/extensions/mcp/oauth.js.map +1 -1
- package/dist/extensions/mcp/resources.d.ts +3 -10
- package/dist/extensions/mcp/resources.d.ts.map +1 -1
- package/dist/extensions/mcp/resources.js +4 -5
- package/dist/extensions/mcp/resources.js.map +1 -1
- package/dist/extensions/mcp/runtime.d.ts +7 -7
- package/dist/extensions/mcp/runtime.d.ts.map +1 -1
- package/dist/extensions/mcp/runtime.js +31 -45
- package/dist/extensions/mcp/runtime.js.map +1 -1
- package/dist/extensions/mcp/tools.d.ts +7 -5
- package/dist/extensions/mcp/tools.d.ts.map +1 -1
- package/dist/extensions/mcp/tools.js +87 -29
- package/dist/extensions/mcp/tools.js.map +1 -1
- package/dist/extensions/mcp/ui.d.ts +3 -3
- package/dist/extensions/mcp/ui.d.ts.map +1 -1
- package/dist/extensions/mcp/ui.js +18 -6
- package/dist/extensions/mcp/ui.js.map +1 -1
- package/dist/extensions/tool-search/tool.d.ts +0 -2
- package/dist/extensions/tool-search/tool.d.ts.map +1 -1
- package/dist/extensions/tool-search/tool.js +2 -4
- package/dist/extensions/tool-search/tool.js.map +1 -1
- package/dist/hooks/checks/checks-runtime.cjs +215 -0
- package/dist/hooks/checks/git-safety.cjs +198 -0
- package/dist/hooks/checks/git-safety.d.cts +1 -0
- package/dist/hooks/gsd/draht-post-task.js +78 -39
- package/dist/hooks/gsd/draht-quality-gate.js +210 -122
- package/dist/hooks/gsd/package.json +3 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +11 -3
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/auth-url.d.ts +14 -0
- package/dist/modes/interactive/components/auth-url.d.ts.map +1 -0
- package/dist/modes/interactive/components/auth-url.js +37 -0
- package/dist/modes/interactive/components/auth-url.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +5 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +17 -14
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts +2 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js +5 -2
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +2 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +5 -2
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.d.ts +3 -1
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js +8 -2
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +1 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +3 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +38 -10
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +8 -2
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +24 -21
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/radius-login-selector.d.ts +15 -0
- package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/radius-login-selector.js +85 -0
- package/dist/modes/interactive/components/radius-login-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +3 -3
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +9 -8
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +2 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +5 -2
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +2 -2
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +12 -13
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +32 -45
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +2 -9
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +5 -4
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +43 -48
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +362 -278
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/program-status-reporter.d.ts +34 -0
- package/dist/modes/interactive/program-status-reporter.d.ts.map +1 -0
- package/dist/modes/interactive/program-status-reporter.js +110 -0
- package/dist/modes/interactive/program-status-reporter.js.map +1 -0
- package/dist/modes/interactive/theme/dark.json +1 -1
- package/dist/modes/interactive/theme/light.json +1 -1
- package/dist/modes/interactive/theme/system-theme.d.ts +2 -1
- package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/system-theme.js +16 -5
- package/dist/modes/interactive/theme/system-theme.js.map +1 -1
- package/dist/modes/interactive/theme/theme-schema.d.ts +28 -0
- package/dist/modes/interactive/theme/theme-schema.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-schema.js +105 -0
- package/dist/modes/interactive/theme/theme-schema.js.map +1 -0
- package/dist/modes/interactive/theme/theme-tokens.d.ts +257 -0
- package/dist/modes/interactive/theme/theme-tokens.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-tokens.js +94 -0
- package/dist/modes/interactive/theme/theme-tokens.js.map +1 -0
- package/dist/modes/interactive/theme/theme.d.ts +13 -16
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +22 -29
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +4 -0
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +26 -1
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/prompts/commands/atomic-commit.md +8 -6
- package/dist/prompts/commands/brainstorm.md +5 -149
- package/dist/prompts/commands/create-verification-skill.md +8 -48
- package/dist/prompts/commands/discuss-phase.md +6 -10
- package/dist/prompts/commands/execute-phase.md +18 -45
- package/dist/prompts/commands/fix.md +16 -128
- package/dist/prompts/commands/grill.md +6 -53
- package/dist/prompts/commands/init-project.md +13 -18
- package/dist/prompts/commands/map-codebase.md +3 -3
- package/dist/prompts/commands/new-project.md +12 -17
- package/dist/prompts/commands/next-milestone.md +4 -8
- package/dist/prompts/commands/orchestrate-loop.md +12 -12
- package/dist/prompts/commands/orchestrate.md +12 -11
- package/dist/prompts/commands/pause-work.md +1 -1
- package/dist/prompts/commands/plan-phase.md +15 -37
- package/dist/prompts/commands/quick.md +11 -64
- package/dist/prompts/commands/resolve-conflicts.md +2 -15
- package/dist/prompts/commands/triage.md +3 -14
- package/dist/prompts/commands/verify-work.md +15 -63
- package/dist/prompts/commands/why.md +18 -118
- package/dist/skills/atomic-reasoning/SKILL.md +6 -105
- package/dist/skills/blast-radius/SKILL.md +1 -1
- package/dist/skills/epistemics/SKILL.md +12 -87
- package/dist/skills/explainers/SKILL.md +1 -1
- package/dist/skills/typescript-discipline/SKILL.md +12 -42
- package/dist/skills/typescript-discipline/references/patterns.md +25 -266
- package/dist/skills/unslop/SKILL.md +14 -105
- package/dist/utils/ansi.d.ts +8 -0
- package/dist/utils/ansi.d.ts.map +1 -1
- package/dist/utils/ansi.js +30 -11
- package/dist/utils/ansi.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts.map +1 -1
- package/dist/utils/clipboard-command.js +3 -0
- package/dist/utils/clipboard-command.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +18 -12
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/draht-user-agent.d.ts +1 -0
- package/dist/utils/draht-user-agent.d.ts.map +1 -1
- package/dist/utils/draht-user-agent.js +3 -2
- package/dist/utils/draht-user-agent.js.map +1 -1
- package/dist/utils/image-convert.d.ts +12 -0
- package/dist/utils/image-convert.d.ts.map +1 -1
- package/dist/utils/image-convert.js +45 -6
- package/dist/utils/image-convert.js.map +1 -1
- package/dist/utils/image-resize-core.d.ts +12 -0
- package/dist/utils/image-resize-core.d.ts.map +1 -1
- package/dist/utils/image-resize-core.js +5 -0
- package/dist/utils/image-resize-core.js.map +1 -1
- package/dist/utils/image-resize-worker.js +3 -2
- package/dist/utils/image-resize-worker.js.map +1 -1
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js +9 -10
- package/dist/utils/image-resize.js.map +1 -1
- package/dist/utils/output-files.d.ts +15 -0
- package/dist/utils/output-files.d.ts.map +1 -0
- package/dist/utils/output-files.js +30 -0
- package/dist/utils/output-files.js.map +1 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +43 -13
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +6 -1
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +4 -3
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/cli-integration.md +1 -1
- package/docs/cli.md +30 -26
- package/docs/codemode.md +230 -0
- package/docs/compaction.md +5 -5
- package/docs/containerization.md +1 -1
- package/docs/custom-provider.md +53 -1
- package/docs/docs.json +17 -1
- package/docs/drahtbank.md +163 -0
- package/docs/environment-variables.md +5 -2
- package/docs/extensions.md +143 -13
- package/docs/index.md +1 -1
- package/docs/json.md +3 -3
- package/docs/keybindings.md +9 -5
- package/docs/llama-cpp.md +9 -2
- package/docs/mcp.md +59 -3
- package/docs/message-types.md +22 -4
- package/docs/models-configuration.md +187 -0
- package/docs/models.md +67 -4
- package/docs/nvidia-rtx-llama-cpp.md +96 -0
- package/docs/providers.md +70 -5
- package/docs/sdk.md +1 -1
- package/docs/settings.md +10 -8
- package/docs/terminal-setup.md +14 -0
- package/docs/themes.md +4 -2
- package/docs/tui.md +71 -1
- package/docs/usage.md +1 -1
- package/docs/windows.md +16 -2
- package/eval/drahtbank/adapters.d.mts +35 -0
- package/eval/drahtbank/adapters.mjs +192 -0
- package/eval/drahtbank/bank.d.mts +141 -0
- package/eval/drahtbank/bank.mjs +515 -0
- package/eval/drahtbank/cases-v2.d.mts +28 -0
- package/eval/drahtbank/cases-v2.mjs +164 -0
- package/eval/drahtbank/cases.d.mts +17 -0
- package/eval/drahtbank/cases.mjs +198 -0
- package/eval/drahtbank/cli.mjs +120 -0
- package/eval/drahtbank/grading-v2.d.mts +26 -0
- package/eval/drahtbank/grading-v2.mjs +227 -0
- package/eval/drahtbank/isolated-tools.ts +223 -0
- package/eval/drahtbank/isolation-worker.mjs +53 -0
- package/eval/drahtbank/isolation.d.mts +52 -0
- package/eval/drahtbank/isolation.mjs +345 -0
- package/eval/drahtbank/runtime-checks.d.mts +15 -0
- package/eval/drahtbank/runtime-checks.mjs +187 -0
- package/examples/extensions/dynamic-resources/dynamic.json +1 -1
- package/examples/extensions/minimal-mode.ts +4 -5
- package/examples/extensions/overlay-test.ts +2 -2
- package/examples/extensions/plan-mode/index.ts +6 -2
- package/examples/extensions/subagent/index.ts +4 -6
- package/hooks/checks/checks-runtime.cjs +215 -0
- package/hooks/checks/git-safety.cjs +198 -0
- package/hooks/checks/git-safety.d.cts +1 -0
- package/hooks/gsd/draht-post-task.js +78 -39
- package/hooks/gsd/draht-quality-gate.js +210 -122
- package/hooks/gsd/package.json +3 -0
- package/package.json +21 -16
- package/prompts/commands/atomic-commit.md +8 -6
- package/prompts/commands/brainstorm.md +5 -149
- package/prompts/commands/create-verification-skill.md +8 -48
- package/prompts/commands/discuss-phase.md +6 -10
- package/prompts/commands/execute-phase.md +18 -45
- package/prompts/commands/fix.md +16 -128
- package/prompts/commands/grill.md +6 -53
- package/prompts/commands/init-project.md +13 -18
- package/prompts/commands/map-codebase.md +3 -3
- package/prompts/commands/new-project.md +12 -17
- package/prompts/commands/next-milestone.md +4 -8
- package/prompts/commands/orchestrate-loop.md +12 -12
- package/prompts/commands/orchestrate.md +12 -11
- package/prompts/commands/pause-work.md +1 -1
- package/prompts/commands/plan-phase.md +15 -37
- package/prompts/commands/quick.md +11 -64
- package/prompts/commands/resolve-conflicts.md +2 -15
- package/prompts/commands/triage.md +3 -14
- package/prompts/commands/verify-work.md +15 -63
- package/prompts/commands/why.md +18 -118
- package/schemas/keybindings.schema.json +433 -0
- package/schemas/models.schema.json +1190 -0
- package/schemas/settings.schema.json +849 -0
- package/schemas/theme.schema.json +365 -0
- package/skills/atomic-reasoning/SKILL.md +6 -105
- package/skills/blast-radius/SKILL.md +1 -1
- package/skills/epistemics/SKILL.md +12 -87
- package/skills/explainers/SKILL.md +1 -1
- package/skills/typescript-discipline/SKILL.md +12 -42
- package/skills/typescript-discipline/references/patterns.md +25 -266
- package/skills/unslop/SKILL.md +14 -105
- package/dist/bundle/chunks/anthropic-messages-E2P6C3P7.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-JZMSTDIM.js +0 -2
- package/dist/bundle/chunks/chunk-2E5VODES.js +0 -2
- package/dist/bundle/chunks/chunk-3DQNSI5W.js +0 -137
- package/dist/bundle/chunks/chunk-4COXSQRQ.js +0 -18
- package/dist/bundle/chunks/chunk-D3HO453P.js +0 -42
- package/dist/bundle/chunks/chunk-GVXA72ZA.js +0 -2
- package/dist/bundle/chunks/chunk-I2SOJ4JN.js +0 -65
- package/dist/bundle/chunks/chunk-I5OKY6RH.js +0 -11
- package/dist/bundle/chunks/chunk-ILSPVHVH.js +0 -1623
- package/dist/bundle/chunks/chunk-KY2BG6BC.js +0 -11
- package/dist/bundle/chunks/chunk-PGJAHC3R.js +0 -107
- package/dist/bundle/chunks/chunk-QVFELZW2.js +0 -312
- package/dist/bundle/chunks/chunk-QVTLBSTH.js +0 -4
- package/dist/bundle/chunks/chunk-SDRCE6OP.js +0 -2
- package/dist/bundle/chunks/chunk-U6LDZZGM.js +0 -146
- package/dist/bundle/chunks/chunk-X3YFUSCK.js +0 -82
- package/dist/bundle/chunks/chunk-XBUEMKIY.js +0 -2
- package/dist/bundle/chunks/chunk-XHCO4PPH.js +0 -8
- package/dist/bundle/chunks/chunk-YH7HNI7D.js +0 -2
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-MJKOAE5S.js +0 -2
- package/dist/bundle/chunks/execute-AGEWJLIO.js +0 -18
- package/dist/bundle/chunks/google-generative-ai-HPNDIAZD.js +0 -2
- package/dist/bundle/chunks/google-vertex-KPAWJ4SP.js +0 -2
- package/dist/bundle/chunks/mistral-conversations-FMSPWQ7A.js +0 -5
- package/dist/bundle/chunks/node-4JNG6XQO.js +0 -16
- package/dist/bundle/chunks/openai-codex-responses-TU7NGPXE.js +0 -10
- package/dist/bundle/chunks/openai-completions-GANCQQO5.js +0 -7
- package/dist/bundle/chunks/openai-responses-ASDPAX3E.js +0 -3
- package/dist/bundle/chunks/openrouter-images-NROSQXMZ.js +0 -2
- package/dist/bundle/chunks/pi-messages-2QEJYOAO.js +0 -8
- package/dist/bundle/chunks/runtime-2B56SZM6.js +0 -2
- package/dist/bundle/chunks/runtime-TJ3EAMJK.js +0 -3
- package/dist/bundle/chunks/settings-manager-HC5RR36T.js +0 -2
- package/dist/bundle/chunks/typesafe-system-one-YBEEY5XU.js +0 -2
- package/dist/bundle/chunks/virtual-modules-XKLDADFR.js +0 -2
- package/dist/core/provider-attribution.d.ts +0 -4
- package/dist/core/provider-attribution.d.ts.map +0 -1
- package/dist/core/provider-attribution.js +0 -72
- package/dist/core/provider-attribution.js.map +0 -1
- package/dist/experimental/micro/api.d.ts +0 -81
- package/dist/experimental/micro/api.d.ts.map +0 -1
- package/dist/experimental/micro/api.js +0 -2
- package/dist/experimental/micro/api.js.map +0 -1
- package/dist/experimental/micro/main.d.ts +0 -3
- package/dist/experimental/micro/main.d.ts.map +0 -1
- package/dist/experimental/micro/main.js +0 -21
- package/dist/experimental/micro/main.js.map +0 -1
- package/dist/experimental/micro/models.d.ts +0 -11
- package/dist/experimental/micro/models.d.ts.map +0 -1
- package/dist/experimental/micro/models.js +0 -95
- package/dist/experimental/micro/models.js.map +0 -1
- package/dist/experimental/micro/runtime.d.ts +0 -12
- package/dist/experimental/micro/runtime.d.ts.map +0 -1
- package/dist/experimental/micro/runtime.js +0 -465
- package/dist/experimental/micro/runtime.js.map +0 -1
- package/dist/experimental/micro/sessions.d.ts +0 -10
- package/dist/experimental/micro/sessions.d.ts.map +0 -1
- package/dist/experimental/micro/sessions.js +0 -41
- package/dist/experimental/micro/sessions.js.map +0 -1
- package/dist/experimental/micro/tools.d.ts +0 -10
- package/dist/experimental/micro/tools.d.ts.map +0 -1
- package/dist/experimental/micro/tools.js +0 -96
- package/dist/experimental/micro/tools.js.map +0 -1
- package/dist/experimental/micro/tui.d.ts +0 -3
- package/dist/experimental/micro/tui.d.ts.map +0 -1
- package/dist/experimental/micro/tui.js +0 -510
- package/dist/experimental/micro/tui.js.map +0 -1
- package/dist/experimental/mini/main.d.ts +0 -7
- package/dist/experimental/mini/main.d.ts.map +0 -1
- package/dist/experimental/mini/main.js +0 -21
- package/dist/experimental/mini/main.js.map +0 -1
- package/dist/experimental/mini/server/entry.d.ts +0 -3
- package/dist/experimental/mini/server/entry.d.ts.map +0 -1
- package/dist/experimental/mini/server/entry.js +0 -11
- package/dist/experimental/mini/server/entry.js.map +0 -1
- package/dist/experimental/mini/server/run.d.ts +0 -13
- package/dist/experimental/mini/server/run.d.ts.map +0 -1
- package/dist/experimental/mini/server/run.js +0 -150
- package/dist/experimental/mini/server/run.js.map +0 -1
- package/dist/experimental/mini/shared/protocol.d.ts +0 -127
- package/dist/experimental/mini/shared/protocol.d.ts.map +0 -1
- package/dist/experimental/mini/shared/protocol.js +0 -13
- package/dist/experimental/mini/shared/protocol.js.map +0 -1
- package/dist/experimental/mini/shared/rpc.d.ts +0 -49
- package/dist/experimental/mini/shared/rpc.d.ts.map +0 -1
- package/dist/experimental/mini/shared/rpc.js +0 -171
- package/dist/experimental/mini/shared/rpc.js.map +0 -1
- package/dist/experimental/mini/shared/transport.d.ts +0 -35
- package/dist/experimental/mini/shared/transport.d.ts.map +0 -1
- package/dist/experimental/mini/shared/transport.js +0 -94
- package/dist/experimental/mini/shared/transport.js.map +0 -1
- package/dist/experimental/mini/tui/run.d.ts +0 -9
- package/dist/experimental/mini/tui/run.d.ts.map +0 -1
- package/dist/experimental/mini/tui/run.js +0 -62
- package/dist/experimental/mini/tui/run.js.map +0 -1
- package/dist/experimental/mini/tui/session.d.ts +0 -26
- package/dist/experimental/mini/tui/session.d.ts.map +0 -1
- package/dist/experimental/mini/tui/session.js +0 -94
- package/dist/experimental/mini/tui/session.js.map +0 -1
- package/dist/experimental/mini/tui/view.d.ts +0 -10
- package/dist/experimental/mini/tui/view.d.ts.map +0 -1
- package/dist/experimental/mini/tui/view.js +0 -461
- package/dist/experimental/mini/tui/view.js.map +0 -1
- package/dist/experimental/mini/worker/entry.d.ts +0 -3
- package/dist/experimental/mini/worker/entry.d.ts.map +0 -1
- package/dist/experimental/mini/worker/entry.js +0 -10
- package/dist/experimental/mini/worker/entry.js.map +0 -1
- package/dist/experimental/mini/worker/lane-service.d.ts +0 -44
- package/dist/experimental/mini/worker/lane-service.d.ts.map +0 -1
- package/dist/experimental/mini/worker/lane-service.js +0 -97
- package/dist/experimental/mini/worker/lane-service.js.map +0 -1
- package/dist/experimental/mini/worker/models-service.d.ts +0 -19
- package/dist/experimental/mini/worker/models-service.d.ts.map +0 -1
- package/dist/experimental/mini/worker/models-service.js +0 -136
- package/dist/experimental/mini/worker/models-service.js.map +0 -1
- package/dist/experimental/mini/worker/run.d.ts +0 -14
- package/dist/experimental/mini/worker/run.d.ts.map +0 -1
- package/dist/experimental/mini/worker/run.js +0 -88
- package/dist/experimental/mini/worker/run.js.map +0 -1
- package/dist/modes/interactive/theme/theme-json.d.ts +0 -85
- package/dist/modes/interactive/theme/theme-json.d.ts.map +0 -1
- package/dist/modes/interactive/theme/theme-json.js +0 -132
- package/dist/modes/interactive/theme/theme-json.js.map +0 -1
- package/dist/modes/interactive/theme/theme-schema.json +0 -361
- /package/dist/bundle/chunks/{chunk-FBU742QF.js → chunk-MOOADNVS.js} +0 -0
|
@@ -2,18 +2,16 @@
|
|
|
2
2
|
* Runs one codemode script in the sandbox. Split from tool.ts and loaded through
|
|
3
3
|
* execute.lazy.ts so the sandbox runtime only loads when a script runs.
|
|
4
4
|
*/
|
|
5
|
-
import { randomBytes } from "node:crypto";
|
|
6
|
-
import { writeFile } from "node:fs/promises";
|
|
7
|
-
import { tmpdir } from "node:os";
|
|
8
|
-
import { join } from "node:path";
|
|
9
5
|
import { CodemodeSandbox, loadQuickJSWasm, parseCodemodeSource, renderToolSample, toCodemodeIdentifier, } from "@draht/codemode";
|
|
10
6
|
import { getCodemodeWorkerSpecifier, getQuickJSWasmPath } from "../../config.js";
|
|
7
|
+
import { formatSize } from "../../core/tools/truncate.js";
|
|
11
8
|
import { combineUsage } from "../../core/usage-totals.js";
|
|
9
|
+
import { writeOutputFile } from "../../utils/output-files.js";
|
|
12
10
|
import { Bm25Ranker, createToolSearchDocument, DEFAULT_TOOL_SEARCH_LIMIT } from "../tool-search/tool.js";
|
|
13
|
-
import { CODEMODE_STORE_ENTRY_TYPE, getCodemodeCallableTools,
|
|
11
|
+
import { CODEMODE_DOCS_PATH, CODEMODE_STORE_ENTRY_TYPE, getCodemodeCallableTools, toCodemodeDeclaration, } from "./tool.js";
|
|
14
12
|
const ARGS_PREVIEW_CHARS = 200;
|
|
15
13
|
const ERROR_PREVIEW_CHARS = 500;
|
|
16
|
-
/**
|
|
14
|
+
/** `models.classify()` and `models.generateImages()` calls one script may have in flight; `Promise.all` over many items queues the rest. */
|
|
17
15
|
const MAX_CONCURRENT_MODEL_CALLS = 4;
|
|
18
16
|
/**
|
|
19
17
|
* Heap limit for the QuickJS VM. The worker shares pi's process, so without a limit a runaway
|
|
@@ -21,6 +19,56 @@ const MAX_CONCURRENT_MODEL_CALLS = 4;
|
|
|
21
19
|
* `InternalError: out of memory` inside the script.
|
|
22
20
|
*/
|
|
23
21
|
const CODEMODE_MEMORY_LIMIT_BYTES = 256 * 1024 * 1024;
|
|
22
|
+
// Shared across calls and sessions. Allow one replacement while a cancelled worker is still exiting.
|
|
23
|
+
const DEFAULT_MAX_CODEMODE_WORKERS = 2;
|
|
24
|
+
/** `DRAHT_CODEMODE_MAX_WORKERS` if it is a positive integer. Read per call so SDK hosts can set it at runtime. */
|
|
25
|
+
function maxCodemodeWorkers() {
|
|
26
|
+
const value = Number(process.env.DRAHT_CODEMODE_MAX_WORKERS);
|
|
27
|
+
return Number.isInteger(value) && value > 0 ? value : DEFAULT_MAX_CODEMODE_WORKERS;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* How long a script waits for a free worker before failing. Bounds the wait when every worker is
|
|
31
|
+
* held by a script that waits on another script, for example an in-process subagent that uses codemode.
|
|
32
|
+
*/
|
|
33
|
+
const CODEMODE_WORKER_WAIT_MS = 60_000;
|
|
34
|
+
let activeCodemodeWorkers = 0;
|
|
35
|
+
/** Scripts waiting for a worker, in arrival order. */
|
|
36
|
+
const codemodeWorkerWaiters = [];
|
|
37
|
+
/**
|
|
38
|
+
* Reserve one worker slot, waiting in arrival order while all are taken. Resolves with why it could
|
|
39
|
+
* not reserve one: the signal aborted, or `timeoutMs` passed.
|
|
40
|
+
*/
|
|
41
|
+
function reserveCodemodeWorker(signal, timeoutMs) {
|
|
42
|
+
if (signal?.aborted)
|
|
43
|
+
return Promise.resolve("aborted");
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
const settle = (outcome) => {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
signal?.removeEventListener("abort", onAbort);
|
|
48
|
+
const index = codemodeWorkerWaiters.indexOf(grant);
|
|
49
|
+
if (index >= 0)
|
|
50
|
+
codemodeWorkerWaiters.splice(index, 1);
|
|
51
|
+
resolve(outcome);
|
|
52
|
+
};
|
|
53
|
+
const grant = () => settle("reserved");
|
|
54
|
+
const onAbort = () => settle("aborted");
|
|
55
|
+
const timer = setTimeout(() => settle("timeout"), timeoutMs);
|
|
56
|
+
codemodeWorkerWaiters.push(grant);
|
|
57
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
58
|
+
admitCodemodeWorkers();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/** Give free slots to waiting scripts in arrival order. */
|
|
62
|
+
function admitCodemodeWorkers() {
|
|
63
|
+
while (codemodeWorkerWaiters.length > 0 && activeCodemodeWorkers < maxCodemodeWorkers()) {
|
|
64
|
+
activeCodemodeWorkers++;
|
|
65
|
+
codemodeWorkerWaiters.shift()?.();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function releaseCodemodeWorker() {
|
|
69
|
+
activeCodemodeWorkers--;
|
|
70
|
+
admitCodemodeWorkers();
|
|
71
|
+
}
|
|
24
72
|
const MODEL_TYPES = new Set(["chat", "image", "classifier"]);
|
|
25
73
|
function truncateText(text, maxChars) {
|
|
26
74
|
return text.length > maxChars ? `${text.slice(0, maxChars - 3)}...` : text;
|
|
@@ -59,6 +107,103 @@ function toModelInfo(model) {
|
|
|
59
107
|
delete info.headers;
|
|
60
108
|
return info;
|
|
61
109
|
}
|
|
110
|
+
/** `an image`, `a classifier`. */
|
|
111
|
+
function withArticle(word) {
|
|
112
|
+
return `${/^[aeiou]/.test(word) ? "an" : "a"} ${word}`;
|
|
113
|
+
}
|
|
114
|
+
/** A script value in an error message: `undefined`, `a string`, `an array`, or its keys (`{ prompt }`). */
|
|
115
|
+
function describeValue(value) {
|
|
116
|
+
if (value === undefined || value === null)
|
|
117
|
+
return String(value);
|
|
118
|
+
if (Array.isArray(value))
|
|
119
|
+
return value.length === 0 ? "an empty array" : "an array";
|
|
120
|
+
if (typeof value === "object") {
|
|
121
|
+
const keys = Object.keys(value);
|
|
122
|
+
if (keys.length === 0)
|
|
123
|
+
return "{}";
|
|
124
|
+
return `{ ${keys.slice(0, 6).join(", ")}${keys.length > 6 ? ", ..." : ""} }`;
|
|
125
|
+
}
|
|
126
|
+
return typeof value === "string" ? "a string" : `a ${typeof value}`;
|
|
127
|
+
}
|
|
128
|
+
const CLASSIFIER_CONTEXT_SHAPE = '{ state: { ... }, images?: [{ type: "image", data: <base64>, mimeType }], questions: { <id>: { type: "choice", instructions, criteria: { <label>: <meaning> } } | { type: "score", instructions, criteria: [<lowest level>, ..., <highest level>] } | { type: "bool", instructions, criteria: { true: <meaning>, false: <meaning> } } } }';
|
|
129
|
+
/** Check a script's classifier context, so mistakes fail with the expected shape instead of a provider error. */
|
|
130
|
+
function checkClassifierContext(context) {
|
|
131
|
+
const fail = (problem) => new Error(`models.classify() ${problem}. Expected context: ${CLASSIFIER_CONTEXT_SHAPE}. See "Classify" in ${CODEMODE_DOCS_PATH}.`);
|
|
132
|
+
if (typeof context !== "object" || context === null || Array.isArray(context)) {
|
|
133
|
+
throw fail(`expects a context object as its second argument, got ${describeValue(context)}`);
|
|
134
|
+
}
|
|
135
|
+
const { state, images, questions } = context;
|
|
136
|
+
if (typeof state !== "object" || state === null || Array.isArray(state)) {
|
|
137
|
+
throw fail(`context.state must be an object, got ${describeValue(state)}`);
|
|
138
|
+
}
|
|
139
|
+
if (images !== undefined) {
|
|
140
|
+
if (!Array.isArray(images))
|
|
141
|
+
throw fail(`context.images must be an array, got ${describeValue(images)}`);
|
|
142
|
+
images.forEach((image, index) => {
|
|
143
|
+
if (image?.type !== "image" || typeof image.data !== "string" || typeof image.mimeType !== "string") {
|
|
144
|
+
throw fail(`context.images[${index}] must be an image block, got ${describeValue(image)}`);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (typeof questions !== "object" ||
|
|
149
|
+
questions === null ||
|
|
150
|
+
Array.isArray(questions) ||
|
|
151
|
+
Object.keys(questions).length === 0) {
|
|
152
|
+
throw fail(`context.questions must map question IDs to questions, got ${describeValue(questions)}`);
|
|
153
|
+
}
|
|
154
|
+
const isStrings = (values) => values.length > 0 && values.every((value) => typeof value === "string");
|
|
155
|
+
for (const [id, question] of Object.entries(questions)) {
|
|
156
|
+
const at = `context.questions.${id}`;
|
|
157
|
+
if (typeof question !== "object" || question === null || Array.isArray(question)) {
|
|
158
|
+
throw fail(`${at} must be a question object, got ${describeValue(question)}`);
|
|
159
|
+
}
|
|
160
|
+
const { type, instructions, criteria } = question;
|
|
161
|
+
if (typeof instructions !== "string")
|
|
162
|
+
throw fail(`${at}.instructions must be a string`);
|
|
163
|
+
if (type === "choice") {
|
|
164
|
+
if (typeof criteria !== "object" ||
|
|
165
|
+
criteria === null ||
|
|
166
|
+
Array.isArray(criteria) ||
|
|
167
|
+
!isStrings(Object.values(criteria))) {
|
|
168
|
+
throw fail(`${at} is a "choice" question, so criteria must map each label to its meaning`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else if (type === "score") {
|
|
172
|
+
if (!Array.isArray(criteria) || !isStrings(criteria)) {
|
|
173
|
+
throw fail(`${at} is a "score" question, so criteria must list the levels as strings, lowest first`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else if (type === "bool") {
|
|
177
|
+
const labels = criteria;
|
|
178
|
+
if (typeof labels?.true !== "string" || typeof labels.false !== "string") {
|
|
179
|
+
throw fail(`${at} is a "bool" question, so criteria must be { true: string, false: string }`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
throw fail(`${at}.type must be "choice", "score", or "bool", got ${JSON.stringify(type)}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return context;
|
|
187
|
+
}
|
|
188
|
+
/** Check a script's image context, so mistakes such as `{ prompt }` fail with the expected shape. */
|
|
189
|
+
function checkImagesContext(context) {
|
|
190
|
+
const fail = (problem) => new Error(`models.generateImages() ${problem}. Expected context: { input: [{ type: "text", text: <prompt> }, ...optional { type: "image", data: <base64>, mimeType } references] }. See "Generate images" in ${CODEMODE_DOCS_PATH}.`);
|
|
191
|
+
if (typeof context !== "object" || context === null || Array.isArray(context)) {
|
|
192
|
+
throw fail(`expects a context object as its second argument, got ${describeValue(context)}`);
|
|
193
|
+
}
|
|
194
|
+
const { input } = context;
|
|
195
|
+
if (!Array.isArray(input) || input.length === 0) {
|
|
196
|
+
throw fail(`context.input must be a non-empty array of blocks, got ${describeValue(input)}`);
|
|
197
|
+
}
|
|
198
|
+
input.forEach((block, index) => {
|
|
199
|
+
if (block?.type === "text" && typeof block.text === "string")
|
|
200
|
+
return;
|
|
201
|
+
if (block?.type === "image" && typeof block.data === "string" && typeof block.mimeType === "string")
|
|
202
|
+
return;
|
|
203
|
+
throw fail(`context.input[${index}] must be a text or image block, got ${describeValue(block)}`);
|
|
204
|
+
});
|
|
205
|
+
return context;
|
|
206
|
+
}
|
|
62
207
|
/** Runs at most `limit` calls at once, in call order. */
|
|
63
208
|
function createLimiter(limit) {
|
|
64
209
|
let active = 0;
|
|
@@ -109,6 +254,66 @@ function valueText(value) {
|
|
|
109
254
|
return value;
|
|
110
255
|
return JSON.stringify(value) ?? String(value);
|
|
111
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Lay out the script's output so the model can tell items apart: providers join adjacent text
|
|
259
|
+
* blocks with a newline or with nothing. With more than one text item (`text()` or the returned
|
|
260
|
+
* value), each starts with a `==> text N/M <==` line. `console.*` lines follow all other output in
|
|
261
|
+
* one `<console_output>` block.
|
|
262
|
+
*/
|
|
263
|
+
function formatOutput(output) {
|
|
264
|
+
const total = output.filter((item) => item.type === "text" && !item.console).length;
|
|
265
|
+
const items = [];
|
|
266
|
+
const consoleLines = [];
|
|
267
|
+
let index = 0;
|
|
268
|
+
for (const item of output) {
|
|
269
|
+
if (item.type === "image") {
|
|
270
|
+
items.push(item);
|
|
271
|
+
}
|
|
272
|
+
else if (item.console) {
|
|
273
|
+
consoleLines.push(item.text);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
index++;
|
|
277
|
+
items.push({ type: "text", text: total > 1 ? `==> text ${index}/${total} <==\n${item.text}` : item.text });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (consoleLines.length > 0) {
|
|
281
|
+
items.push({ type: "text", text: `<console_output>\n${consoleLines.join("\n")}\n</console_output>` });
|
|
282
|
+
}
|
|
283
|
+
return items;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Join adjacent text items into one, each part starting on its own line. The separator check looks
|
|
287
|
+
* at the last non-empty part, not the joined text: reading the end of a growing concatenation makes
|
|
288
|
+
* V8 copy it on every item, which is quadratic (#10678).
|
|
289
|
+
*/
|
|
290
|
+
function joinAdjacentText(items) {
|
|
291
|
+
const joined = [];
|
|
292
|
+
let parts = [];
|
|
293
|
+
let lastPart = "";
|
|
294
|
+
const flush = () => {
|
|
295
|
+
if (parts.length > 0)
|
|
296
|
+
joined.push({ type: "text", text: parts.join("") });
|
|
297
|
+
parts = [];
|
|
298
|
+
lastPart = "";
|
|
299
|
+
};
|
|
300
|
+
for (const item of items) {
|
|
301
|
+
if (item.type !== "text") {
|
|
302
|
+
flush();
|
|
303
|
+
joined.push(item);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
if (lastPart !== "" && !lastPart.endsWith("\n")) {
|
|
307
|
+
parts.push("\n");
|
|
308
|
+
lastPart = "\n";
|
|
309
|
+
}
|
|
310
|
+
parts.push(item.text);
|
|
311
|
+
if (item.text !== "")
|
|
312
|
+
lastPart = item.text;
|
|
313
|
+
}
|
|
314
|
+
flush();
|
|
315
|
+
return joined;
|
|
316
|
+
}
|
|
112
317
|
function formatCallSummary(calls) {
|
|
113
318
|
if (calls.length === 0)
|
|
114
319
|
return "No tool calls were made.";
|
|
@@ -127,15 +332,55 @@ function formatError(result, calls) {
|
|
|
127
332
|
}
|
|
128
333
|
/** Write the full text output to a temp file, like bash does for truncated output. */
|
|
129
334
|
async function spillOutput(text) {
|
|
130
|
-
const path = join(tmpdir(), `draht-codemode-${randomBytes(8).toString("hex")}.txt`);
|
|
131
335
|
try {
|
|
132
|
-
await
|
|
133
|
-
return { path };
|
|
336
|
+
return { path: await writeOutputFile("draht-codemode", ".txt", text) };
|
|
134
337
|
}
|
|
135
338
|
catch (error) {
|
|
136
339
|
return { error: error instanceof Error ? error.message : String(error) };
|
|
137
340
|
}
|
|
138
341
|
}
|
|
342
|
+
/** File extensions of the image types `image()` accepts. Must list every type the sandbox's `image()` detects. */
|
|
343
|
+
const IMAGE_EXTENSIONS = {
|
|
344
|
+
"image/png": ".png",
|
|
345
|
+
"image/jpeg": ".jpg",
|
|
346
|
+
"image/gif": ".gif",
|
|
347
|
+
"image/webp": ".webp",
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* Save each image to a temp file and put a text item with its path before it. The model sees the
|
|
351
|
+
* image but has no other way to reach its bytes: scripts cannot write files, and `write` only takes
|
|
352
|
+
* text. Images shown more than once are saved once.
|
|
353
|
+
*/
|
|
354
|
+
async function saveImages(items) {
|
|
355
|
+
const labels = new Map();
|
|
356
|
+
const label = async ({ data, mimeType }) => {
|
|
357
|
+
const bytes = Buffer.from(data, "base64");
|
|
358
|
+
const kind = `${mimeType}, ${formatSize(bytes.length)}`;
|
|
359
|
+
const extension = IMAGE_EXTENSIONS[mimeType];
|
|
360
|
+
if (!extension)
|
|
361
|
+
throw new Error(`No file extension for image type ${mimeType}`);
|
|
362
|
+
// A failed write (disk full, unwritable temp dir) must not discard the result of a script whose
|
|
363
|
+
// tool calls already ran, so it becomes part of the label.
|
|
364
|
+
try {
|
|
365
|
+
const path = await writeOutputFile("draht-codemode", extension, bytes);
|
|
366
|
+
return `[Image saved to ${path} (${kind})]`;
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
return `[Image (${kind}) could not be saved: ${error instanceof Error ? error.message : String(error)}]`;
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
const result = await Promise.all(items.map(async (item) => {
|
|
373
|
+
if (item.type !== "image")
|
|
374
|
+
return [item];
|
|
375
|
+
let pending = labels.get(item.data);
|
|
376
|
+
if (!pending) {
|
|
377
|
+
pending = label(item);
|
|
378
|
+
labels.set(item.data, pending);
|
|
379
|
+
}
|
|
380
|
+
return [{ type: "text", text: await pending }, item];
|
|
381
|
+
}));
|
|
382
|
+
return result.flat();
|
|
383
|
+
}
|
|
139
384
|
/**
|
|
140
385
|
* Apply the token budget: when the combined text exceeds it, the text items become one
|
|
141
386
|
* item that keeps the start and end of the text, and images follow it. The full text is written to
|
|
@@ -188,14 +433,22 @@ export async function executeCodemode(toolCallId, input, signal, onUpdate, ctx,
|
|
|
188
433
|
const calls = [];
|
|
189
434
|
// Usage of the script's `models.*` calls. Nested tool calls report theirs through the session.
|
|
190
435
|
let modelUsage;
|
|
436
|
+
// Images returned by `models.generateImages()`, to notice a script that never shows them.
|
|
437
|
+
let generatedImages = 0;
|
|
438
|
+
const addGeneratedImages = (count) => {
|
|
439
|
+
generatedImages += count;
|
|
440
|
+
};
|
|
191
441
|
const addModelUsage = (usage) => {
|
|
192
442
|
modelUsage = modelUsage ? combineUsage(modelUsage, usage) : usage;
|
|
193
443
|
};
|
|
194
444
|
const snapshot = () => ({ calls: calls.map((call) => ({ ...call })) });
|
|
195
445
|
const publish = () => onUpdate?.({ content: [], details: snapshot() });
|
|
446
|
+
// Show the script as running before its first nested call, so the row's timer starts.
|
|
447
|
+
publish();
|
|
196
448
|
const callable = ctx ? getCodemodeCallableTools(ctx.tools) : [];
|
|
197
449
|
// ALL_TOOLS entries carry the declaration.
|
|
198
|
-
const
|
|
450
|
+
const guidelines = options.getToolGuidelines?.();
|
|
451
|
+
const samples = new Map(callable.map((tool) => [tool.name, renderToolSample(toCodemodeDeclaration(tool, guidelines?.get(tool.name)))]));
|
|
199
452
|
const sandboxTools = callable.map((tool) => ({
|
|
200
453
|
name: tool.name,
|
|
201
454
|
description: samples.get(tool.name),
|
|
@@ -226,33 +479,70 @@ export async function executeCodemode(toolCallId, input, signal, onUpdate, ctx,
|
|
|
226
479
|
return toScriptValue(tool, outcome);
|
|
227
480
|
},
|
|
228
481
|
}));
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
482
|
+
// The wait for a worker counts toward the script's deadline.
|
|
483
|
+
const deadline = sourceOptions.timeoutMs ?? Number.POSITIVE_INFINITY;
|
|
484
|
+
const waitStartedAt = performance.now();
|
|
485
|
+
const admission = await reserveCodemodeWorker(signal, Math.min(deadline, CODEMODE_WORKER_WAIT_MS));
|
|
486
|
+
const waitedMs = performance.now() - waitStartedAt;
|
|
487
|
+
if (admission !== "reserved") {
|
|
488
|
+
const waited = ((performance.now() - startedAt) / 1000).toFixed(1);
|
|
489
|
+
const reason = signal?.reason;
|
|
490
|
+
const error = admission === "aborted"
|
|
491
|
+
? `Script aborted: ${reason instanceof Error ? reason.message : "Execution aborted"}`
|
|
492
|
+
: deadline <= CODEMODE_WORKER_WAIT_MS
|
|
493
|
+
? `Script timed out: Execution timed out after ${deadline} ms while waiting for a free codemode worker`
|
|
494
|
+
: `No codemode worker became free within ${CODEMODE_WORKER_WAIT_MS / 1000} seconds. All ${maxCodemodeWorkers()} workers, shared by every session in this process, are held by other scripts. Retry after they finish.`;
|
|
495
|
+
return {
|
|
496
|
+
content: [
|
|
497
|
+
{ type: "text", text: `Script failed\nWall time ${waited} seconds\nOutput:\n` },
|
|
498
|
+
{ type: "text", text: `Script error:\n${error}\n\nThe script did not start.` },
|
|
499
|
+
],
|
|
500
|
+
details: snapshot(),
|
|
501
|
+
isError: true,
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
// The reservation covers the one worker this script starts. A launch that resumes after the result
|
|
505
|
+
// settled finds it released and starts no worker.
|
|
506
|
+
let reserved = true;
|
|
507
|
+
let sandbox;
|
|
242
508
|
let result;
|
|
243
509
|
try {
|
|
510
|
+
sandbox = new CodemodeSandbox({
|
|
511
|
+
tools: sandboxTools,
|
|
512
|
+
globals: [
|
|
513
|
+
...createDiscoveryGlobals(callable, samples, options),
|
|
514
|
+
...(options.models && ctx
|
|
515
|
+
? createModelGlobals(ctx.modelRegistry, toolCallId, calls, publish, addModelUsage, addGeneratedImages)
|
|
516
|
+
: []),
|
|
517
|
+
],
|
|
518
|
+
timeoutMs: Math.max(1, Math.round(deadline - waitedMs)),
|
|
519
|
+
memoryLimitBytes: CODEMODE_MEMORY_LIMIT_BYTES,
|
|
520
|
+
wasm: loadQuickJSWasm(getQuickJSWasmPath()),
|
|
521
|
+
workerUrl: getCodemodeWorkerSpecifier(),
|
|
522
|
+
acquireWorker: () => {
|
|
523
|
+
if (!reserved)
|
|
524
|
+
throw new Error("The script already settled");
|
|
525
|
+
// From here the sandbox releases the slot when the worker actually exits.
|
|
526
|
+
reserved = false;
|
|
527
|
+
return releaseCodemodeWorker;
|
|
528
|
+
},
|
|
529
|
+
});
|
|
244
530
|
const store = ctx ? readCodemodeStore(ctx.sessionManager.getBranch()) : {};
|
|
245
531
|
result = await sandbox.execute(code, { signal, store });
|
|
246
532
|
}
|
|
247
533
|
finally {
|
|
248
|
-
await sandbox
|
|
534
|
+
await sandbox?.close();
|
|
535
|
+
if (reserved) {
|
|
536
|
+
reserved = false;
|
|
537
|
+
releaseCodemodeWorker();
|
|
538
|
+
}
|
|
249
539
|
}
|
|
250
540
|
// Calls still marked running were cut off by the script ending, a timeout, or an abort.
|
|
251
541
|
for (const call of calls) {
|
|
252
542
|
if (call.status === "running")
|
|
253
543
|
call.status = "cancelled";
|
|
254
544
|
}
|
|
255
|
-
const
|
|
545
|
+
const scriptOutput = [...result.output];
|
|
256
546
|
if (result.ok) {
|
|
257
547
|
const { set, delete: deleted } = result.storeWrites;
|
|
258
548
|
if (Object.keys(set).length > 0 || deleted.length > 0) {
|
|
@@ -260,33 +550,40 @@ export async function executeCodemode(toolCallId, input, signal, onUpdate, ctx,
|
|
|
260
550
|
}
|
|
261
551
|
// pi extension: a returned value is appended like text().
|
|
262
552
|
if (result.value !== undefined)
|
|
263
|
-
|
|
553
|
+
scriptOutput.push({ type: "text", text: valueText(result.value) });
|
|
264
554
|
}
|
|
265
|
-
|
|
555
|
+
const items = formatOutput(scriptOutput);
|
|
556
|
+
if (!result.ok)
|
|
266
557
|
items.push({ type: "text", text: `Script error:\n${formatError(result, calls)}` });
|
|
558
|
+
if (generatedImages > 0 && !items.some((item) => item.type === "image")) {
|
|
559
|
+
items.push({
|
|
560
|
+
type: "text",
|
|
561
|
+
text: `Note: models.generateImages() returned ${generatedImages} image${generatedImages === 1 ? "" : "s"} that the script did not show. Show each image block of result.output with image(block).`,
|
|
562
|
+
});
|
|
267
563
|
}
|
|
268
|
-
const truncated = await truncateOutput(items, sourceOptions.maxOutputTokens ?? DEFAULT_MAX_OUTPUT_TOKENS);
|
|
564
|
+
const truncated = await truncateOutput(joinAdjacentText(items), sourceOptions.maxOutputTokens ?? DEFAULT_MAX_OUTPUT_TOKENS);
|
|
565
|
+
// After truncation, which joins the text items and moves images after them, so each path stays
|
|
566
|
+
// next to its image and is never cut.
|
|
567
|
+
const output = joinAdjacentText(await saveImages(truncated.items));
|
|
269
568
|
const wallTime = ((performance.now() - startedAt) / 1000).toFixed(1);
|
|
270
569
|
const header = `${result.ok ? "Script completed" : "Script failed"}\nWall time ${wallTime} seconds\nOutput:\n`;
|
|
271
570
|
const details = snapshot();
|
|
272
571
|
if (truncated.fullOutputPath)
|
|
273
572
|
details.fullOutputPath = truncated.fullOutputPath;
|
|
274
573
|
return {
|
|
275
|
-
content: [{ type: "text", text: header }, ...
|
|
574
|
+
content: [{ type: "text", text: header }, ...output],
|
|
276
575
|
details,
|
|
277
576
|
...(modelUsage ? { usage: modelUsage } : {}),
|
|
278
577
|
...(result.ok ? {} : { isError: true }),
|
|
279
578
|
};
|
|
280
579
|
}
|
|
281
580
|
/**
|
|
282
|
-
* Whether `query` names the namespace: its name
|
|
283
|
-
* `
|
|
581
|
+
* Whether `query` names the namespace: its name or one of its aliases, as written or as the same
|
|
582
|
+
* script identifier (`dev-radius` and `dev_radius` are both `dev_radius`).
|
|
284
583
|
*/
|
|
285
584
|
function isNamespaceName(namespace, query) {
|
|
286
|
-
const id = toCodemodeIdentifier(namespace);
|
|
287
585
|
const queryId = toCodemodeIdentifier(query);
|
|
288
|
-
|
|
289
|
-
return namespace === query || id === queryId || suffix(namespace) === query || suffix(id) === queryId;
|
|
586
|
+
return [namespace.name, ...(namespace.aliases ?? [])].some((name) => name === query || toCodemodeIdentifier(name) === queryId);
|
|
290
587
|
}
|
|
291
588
|
/**
|
|
292
589
|
* `searchTools()`, `describeTool()`, and `describeNamespace()`: ranked search and lookup over the
|
|
@@ -313,7 +610,7 @@ function createDiscoveryGlobals(tools, samples, options) {
|
|
|
313
610
|
}
|
|
314
611
|
const documents = tools.flatMap((tool) => {
|
|
315
612
|
const toolNamespace = options.getToolNamespace?.(tool.name);
|
|
316
|
-
if (namespace && (!toolNamespace || !isNamespaceName(toolNamespace
|
|
613
|
+
if (namespace && (!toolNamespace || !isNamespaceName(toolNamespace, namespace)))
|
|
317
614
|
return [];
|
|
318
615
|
return [createToolSearchDocument(tool, toolNamespace)];
|
|
319
616
|
});
|
|
@@ -342,7 +639,7 @@ function createDiscoveryGlobals(tools, samples, options) {
|
|
|
342
639
|
const names = [];
|
|
343
640
|
for (const tool of tools) {
|
|
344
641
|
const toolNamespace = options.getToolNamespace?.(tool.name);
|
|
345
|
-
if (!toolNamespace || !isNamespaceName(toolNamespace
|
|
642
|
+
if (!toolNamespace || !isNamespaceName(toolNamespace, name))
|
|
346
643
|
continue;
|
|
347
644
|
namespace ??= toolNamespace;
|
|
348
645
|
names.push(toCodemodeIdentifier(tool.name));
|
|
@@ -360,13 +657,59 @@ function createDiscoveryGlobals(tools, samples, options) {
|
|
|
360
657
|
];
|
|
361
658
|
}
|
|
362
659
|
/**
|
|
363
|
-
* `models.*` for scripts: the model registry methods
|
|
364
|
-
* Classifier calls appear as nested call rows so the renderer shows them, and their usage
|
|
365
|
-
* `addUsage`.
|
|
660
|
+
* `models.*` for scripts: the model registry methods documented in docs/codemode.md.
|
|
661
|
+
* Classifier and image calls appear as nested call rows so the renderer shows them, and their usage
|
|
662
|
+
* goes to `addUsage`. Rows show only the model, never prompts or image data.
|
|
366
663
|
*/
|
|
367
|
-
function createModelGlobals(models, toolCallId, calls, publish, addUsage) {
|
|
664
|
+
function createModelGlobals(models, toolCallId, calls, publish, addUsage, addGeneratedImages) {
|
|
368
665
|
const limit = createLimiter(MAX_CONCURRENT_MODEL_CALLS);
|
|
369
|
-
let
|
|
666
|
+
let callCount = 0;
|
|
667
|
+
/**
|
|
668
|
+
* Resolve the script's model by provider and id only, check the context, then run the call as a
|
|
669
|
+
* nested call row. A script-supplied baseUrl or headers must never receive the credentials.
|
|
670
|
+
*/
|
|
671
|
+
const runModelCall = async (name, type, [model, context], checkContext, run) => {
|
|
672
|
+
const listHint = `List the ${type} models you can use with models.getAvailableOfType("${type}").`;
|
|
673
|
+
const given = model;
|
|
674
|
+
if (typeof given?.provider !== "string" || typeof given.id !== "string") {
|
|
675
|
+
// undefined arrives as null: spread arguments cross the sandbox as a JSON array.
|
|
676
|
+
const undefinedHint = model === undefined || model === null
|
|
677
|
+
? " models.getModelOfType() returns undefined for an unknown provider or id."
|
|
678
|
+
: "";
|
|
679
|
+
throw new Error(`${name}() expects ${withArticle(type)} model as its first argument, got ${describeValue(model)}.${undefinedHint} ${listHint}`);
|
|
680
|
+
}
|
|
681
|
+
const provider = given.provider;
|
|
682
|
+
const id = given.id;
|
|
683
|
+
const ref = `${provider}/${id}`;
|
|
684
|
+
const resolved = models.getModelOfType(type, provider, id);
|
|
685
|
+
if (!resolved) {
|
|
686
|
+
const actualType = [...MODEL_TYPES].find((other) => other !== type && models.getModelOfType(other, provider, id) !== undefined);
|
|
687
|
+
throw new Error(actualType
|
|
688
|
+
? `"${ref}" is ${withArticle(actualType)} model, not ${withArticle(type)} model. ${listHint}`
|
|
689
|
+
: `Unknown ${type} model "${ref}". ${listHint}`);
|
|
690
|
+
}
|
|
691
|
+
const checked = checkContext(context);
|
|
692
|
+
const record = {
|
|
693
|
+
id: `${toolCallId}/${name}/${++callCount}`,
|
|
694
|
+
name,
|
|
695
|
+
args: `${resolved.provider}/${resolved.id}`,
|
|
696
|
+
status: "running",
|
|
697
|
+
};
|
|
698
|
+
calls.push(record);
|
|
699
|
+
publish();
|
|
700
|
+
const startedAt = performance.now();
|
|
701
|
+
const result = await limit(() => run(resolved, checked));
|
|
702
|
+
record.durationMs = performance.now() - startedAt;
|
|
703
|
+
record.status = result.stopReason === "stop" ? "ok" : result.stopReason === "aborted" ? "cancelled" : "error";
|
|
704
|
+
if (result.errorMessage)
|
|
705
|
+
record.error = truncateText(result.errorMessage, ERROR_PREVIEW_CHARS);
|
|
706
|
+
if (result.usage) {
|
|
707
|
+
record.cost = result.usage.cost.total;
|
|
708
|
+
addUsage(result.usage);
|
|
709
|
+
}
|
|
710
|
+
publish();
|
|
711
|
+
return result;
|
|
712
|
+
};
|
|
370
713
|
const implementations = {
|
|
371
714
|
"models.getModelsOfType": (args) => {
|
|
372
715
|
const [type, provider] = args;
|
|
@@ -380,50 +723,18 @@ function createModelGlobals(models, toolCallId, calls, publish, addUsage) {
|
|
|
380
723
|
"models.getModelOfType": (args) => {
|
|
381
724
|
const [type, provider, id] = args;
|
|
382
725
|
if (typeof provider !== "string" || typeof id !== "string") {
|
|
383
|
-
throw new Error(
|
|
726
|
+
throw new Error(`models.getModelOfType(type, provider, id) expects three strings, got (${args.map(describeValue).join(", ")}). The provider and the id are separate arguments, for example models.getModelOfType("classifier", "typesafe", "jev-latest").`);
|
|
384
727
|
}
|
|
385
728
|
const model = models.getModelOfType(toModelType(type), provider, id);
|
|
386
729
|
return model === undefined ? undefined : toModelInfo(model);
|
|
387
730
|
},
|
|
388
|
-
"models.classify":
|
|
389
|
-
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
ref === null ||
|
|
393
|
-
typeof ref.provider !== "string" ||
|
|
394
|
-
typeof ref.id !== "string") {
|
|
395
|
-
throw new Error("models.classify() expects a model from models.getModelOfType() or models.getAvailableOfType()");
|
|
396
|
-
}
|
|
397
|
-
// Only provider and id count. A script-supplied baseUrl or headers must never receive the credentials.
|
|
398
|
-
const resolved = models.getModelOfType("classifier", ref.provider, ref.id);
|
|
399
|
-
if (!resolved)
|
|
400
|
-
throw new Error(`Unknown classifier model "${ref.provider}/${ref.id}"`);
|
|
401
|
-
const record = {
|
|
402
|
-
id: `${toolCallId}/models.classify/${++classifyCount}`,
|
|
403
|
-
name: "models.classify",
|
|
404
|
-
args: `${resolved.provider}/${resolved.id}`,
|
|
405
|
-
status: "running",
|
|
406
|
-
};
|
|
407
|
-
calls.push(record);
|
|
408
|
-
publish();
|
|
409
|
-
const startedAt = performance.now();
|
|
410
|
-
const result = await limit(() => models.classify(resolved, context, { signal }));
|
|
411
|
-
record.durationMs = performance.now() - startedAt;
|
|
412
|
-
record.status = result.stopReason === "stop" ? "ok" : result.stopReason === "aborted" ? "cancelled" : "error";
|
|
413
|
-
if (result.errorMessage)
|
|
414
|
-
record.error = truncateText(result.errorMessage, ERROR_PREVIEW_CHARS);
|
|
415
|
-
if (result.usage) {
|
|
416
|
-
record.cost = result.usage.cost.total;
|
|
417
|
-
addUsage(result.usage);
|
|
418
|
-
}
|
|
419
|
-
publish();
|
|
731
|
+
"models.classify": (args, { signal }) => runModelCall("models.classify", "classifier", args, checkClassifierContext, (resolved, context) => models.classify(resolved, context, { signal })),
|
|
732
|
+
"models.generateImages": (args, { signal }) => runModelCall("models.generateImages", "image", args, checkImagesContext, async (resolved, context) => {
|
|
733
|
+
const result = await models.generateImages(resolved, context, { signal });
|
|
734
|
+
addGeneratedImages(result.output.filter((block) => block.type === "image").length);
|
|
420
735
|
return result;
|
|
421
|
-
},
|
|
736
|
+
}),
|
|
422
737
|
};
|
|
423
|
-
return
|
|
424
|
-
name: declaration.name,
|
|
425
|
-
spread: true,
|
|
426
|
-
execute: implementations[declaration.name],
|
|
427
|
-
}));
|
|
738
|
+
return Object.entries(implementations).map(([name, execute]) => ({ name, spread: true, execute }));
|
|
428
739
|
}
|
|
429
740
|
//# sourceMappingURL=execute.js.map
|