@draht/coding-agent 2026.10.20 → 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 +31 -28
- package/dist/bundle/chunks/chunk-2JZLKNZ4.js +3 -0
- package/dist/bundle/chunks/chunk-3GDEPGTR.js +16 -0
- package/dist/bundle/chunks/chunk-5JW3NSTV.js +2 -0
- package/dist/bundle/chunks/{chunk-KVH4HR57.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-CLKG6K6Z.js +7 -0
- package/dist/bundle/chunks/chunk-DN7SM3LX.js +479 -0
- package/dist/bundle/chunks/{chunk-D6TMD5Q2.js → chunk-DOUMZTXH.js} +10 -10
- 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-GBFVS2SF.js +12 -0
- package/dist/bundle/chunks/chunk-GQXRTK54.js +20 -0
- package/dist/bundle/chunks/chunk-IGO52ZOY.js +132 -0
- package/dist/bundle/chunks/chunk-IT4RIOZD.js +2 -0
- 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-LO6CVU2L.js +6 -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-PYJB6AQ3.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/https-proxy-agent-WQIRL24U.js +13 -0
- package/dist/bundle/chunks/image-resize-worker.js +1 -1
- package/dist/bundle/chunks/lib-ULKZYRGD.js +9 -0
- 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/{multipart-parser-AZP5BX2W.js → multipart-parser-HMCXZ4BD.js} +1 -1
- package/dist/bundle/chunks/node-DXZFQBEO.js +16 -0
- package/dist/bundle/chunks/{node-C2JGH2OB.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/src-KDGO7EGF.js +4 -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-GAKYXF65.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-ZIXMK6JO.js +0 -2
- package/dist/bundle/chunks/chunk-2E5VODES.js +0 -2
- package/dist/bundle/chunks/chunk-2VAF4XJI.js +0 -146
- package/dist/bundle/chunks/chunk-4TVQYRQY.js +0 -2
- package/dist/bundle/chunks/chunk-6MSE6LZ3.js +0 -6
- package/dist/bundle/chunks/chunk-6ZJKIMU7.js +0 -2
- package/dist/bundle/chunks/chunk-736QBNUZ.js +0 -12
- package/dist/bundle/chunks/chunk-7TYCZN4Z.js +0 -137
- package/dist/bundle/chunks/chunk-BXSHCX3G.js +0 -11
- package/dist/bundle/chunks/chunk-GVXA72ZA.js +0 -2
- package/dist/bundle/chunks/chunk-I5OKY6RH.js +0 -11
- package/dist/bundle/chunks/chunk-IWTUBX6V.js +0 -4
- package/dist/bundle/chunks/chunk-KU5HAKZL.js +0 -4
- package/dist/bundle/chunks/chunk-MO3SCGBN.js +0 -18
- package/dist/bundle/chunks/chunk-N2QZNJT6.js +0 -65
- package/dist/bundle/chunks/chunk-PGJAHC3R.js +0 -107
- package/dist/bundle/chunks/chunk-QVFELZW2.js +0 -312
- package/dist/bundle/chunks/chunk-RZKPFWMH.js +0 -42
- package/dist/bundle/chunks/chunk-SDRCE6OP.js +0 -2
- package/dist/bundle/chunks/chunk-SVNWI7EV.js +0 -8
- package/dist/bundle/chunks/chunk-TIA2T6EO.js +0 -3
- package/dist/bundle/chunks/chunk-TOWVIJ2O.js +0 -1623
- package/dist/bundle/chunks/chunk-XBUEMKIY.js +0 -2
- package/dist/bundle/chunks/chunk-ZA4QNPJY.js +0 -82
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-MJKOAE5S.js +0 -2
- package/dist/bundle/chunks/execute-6N7T7VLY.js +0 -18
- package/dist/bundle/chunks/google-generative-ai-RPUPQ6PM.js +0 -2
- package/dist/bundle/chunks/google-vertex-EZES5QVQ.js +0 -2
- package/dist/bundle/chunks/https-proxy-agent-O2PVUIOI.js +0 -13
- package/dist/bundle/chunks/lib-XOG5PI3Y.js +0 -9
- package/dist/bundle/chunks/mistral-conversations-AOYGU43Y.js +0 -5
- package/dist/bundle/chunks/node-LQ52KV6B.js +0 -16
- package/dist/bundle/chunks/openai-codex-responses-M2Y77JEQ.js +0 -10
- package/dist/bundle/chunks/openai-completions-A4OKYOYV.js +0 -7
- package/dist/bundle/chunks/openai-responses-6IXV53T3.js +0 -3
- package/dist/bundle/chunks/openrouter-images-LYV4NKFM.js +0 -2
- package/dist/bundle/chunks/pi-messages-KKMEUT3Z.js +0 -8
- package/dist/bundle/chunks/runtime-363BOYEO.js +0 -3
- package/dist/bundle/chunks/runtime-D3KV73AE.js +0 -2
- package/dist/bundle/chunks/settings-manager-GEOZJXFQ.js +0 -2
- package/dist/bundle/chunks/src-TIBHS42X.js +0 -4
- package/dist/bundle/chunks/typesafe-system-one-YBEEY5XU.js +0 -2
- package/dist/bundle/chunks/virtual-modules-RLC4Y5MX.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-ZZD35WKM.js → chunk-MOOADNVS.js} +0 -0
|
@@ -1,50 +1,20 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: typescript-discipline
|
|
3
|
-
description:
|
|
3
|
+
description: Design or review TypeScript domain types, parsing boundaries, and type-safety trade-offs. Use when the task concerns type modeling, unsafe assertions, or exhaustive handling.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# TypeScript Discipline
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Use types to express the cases callers must handle, with the least complexity that keeps operations correct.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
- Model mutually exclusive states with discriminated unions. Enforce exhaustive handling so adding a variant reveals missing cases.
|
|
11
|
+
- Parse external data from `unknown` at the boundary into a named type. Keep business logic typed and avoid repeating already-established validation inside it.
|
|
12
|
+
- Prefer constructive representations when they remove invalid combinations. A non-empty tuple proves a head exists; it does not prove an arbitrary numeric index is in bounds.
|
|
13
|
+
- Strengthen a type where an operation requires it. An empty list is valid input for a sum; a head operation must require non-empty input or return an optional result.
|
|
14
|
+
- Brand primitives when mixing their meanings is a plausible defect. Match the project's brand convention and validate at construction.
|
|
15
|
+
- Avoid `any`, unchecked `as`, and non-null assertions. Narrow, validate, or revise the model; isolate and explain an assertion that the compiler cannot express.
|
|
16
|
+
- Derive shapes from authoritative schemas and existing types. Use `satisfies` to check a value against a type without a type assertion.
|
|
17
|
+
- Type predicates must check their full claim. A named guard is not evidence that its implementation is sound.
|
|
18
|
+
- Use named object arguments when they prevent confusion; follow existing APIs and consider allocation-sensitive paths.
|
|
11
19
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- **Make illegal states unrepresentable.** Model variants as a discriminated union, not as a bag of optional fields where contradictory combinations compile. The canonical anti-pattern: `{ completed: boolean; completedAt?: Date }` admits `completed: true` with `completedAt: undefined`, which means nothing. Derive the boolean from a single source (`completedAt !== null`) or model the variants explicitly: `{ kind: 'open' } | { kind: 'done'; at: Date }`. If a bug ever forces the question "wait, can this combination actually happen?", the type is too loose.
|
|
15
|
-
- **Types are constructions, not restrictions.** Build the type up from the values you want instead of carving them out of a looser type with runtime checks. A non-empty list is a head plus a rest, not a list with a length check. A valid time range is a start plus a duration, not two timestamps you must keep ordered. No representation is privileged — pick the shape that cannot build the illegal value, then expose the interface callers need on top of it.
|
|
16
|
-
- **Brand semantic primitives.** A `UserId` and an `OrderId` are both strings underneath but must not be interchangeable. Brand them, validate once at creation, trust the type downstream.
|
|
17
|
-
- **External data is untyped until parsed.** RPC payloads, JSON, CLI args, config files, environment variables, database rows: each gets a parse function at the boundary that turns unstructured input into the typed domain model. Validation lives at that boundary, once — inside the system there is typed data, no re-validation deep in call chains, and business logic in pure functions the boundary shell calls.
|
|
18
|
-
- **Don't lie to the compiler.** Casts and assertions that bypass the checker are runtime crashes waiting to happen. If the compiler can't prove a fact, prove it — validate, narrow, refine the model — or accept that the cast is a hazard you are choosing to carry. The cast buried today is the postmortem written next week.
|
|
19
|
-
- **Exhaustive matching is the compiler's job.** A match over a sum type must fail compilation when a new variant is added without a case, so the compiler tells the next author every place that needs updating.
|
|
20
|
-
- **Derive types from authoritative schemas.** When a protocol buffer, OpenAPI spec, GraphQL schema, or database migration already defines a shape, derive from it instead of hand-rolling a parallel type. Manual duplication drifts.
|
|
21
|
-
- **Strengthen a type only where partiality appears.** A runtime assertion, a null check, or a "should never happen" throw marks the spot where a type is too weak — push that check up into the type, then stop. The type system's job is to track the cases each use site must handle, not to describe the data as precisely as possible. `sum` of an empty list is 0, so it takes the plain list; `head` of an empty list has no answer, so it demands the non-empty one. Extra precision beyond totality costs reuse and ceremony and buys no safety.
|
|
22
|
-
|
|
23
|
-
## Rules (TypeScript syntax)
|
|
24
|
-
|
|
25
|
-
| Rule | Summary |
|
|
26
|
-
|------|---------|
|
|
27
|
-
| Discriminated unions | Model variants with a `kind` literal discriminant so impossible states can't be represented. No optional-field bags. |
|
|
28
|
-
| Branded types | Brand primitives with `& { readonly __brand: "X" }` so they can't be mixed up. Validate once at creation. |
|
|
29
|
-
| Constructive modeling | Build the shape so the illegal value can't be constructed: `[T, ...T[]]` for non-empty, `[T, T][]` for even length, `start` plus `duration` for a range. Not a runtime guard, not a wish for refinement types. |
|
|
30
|
-
| Simplest total type | Keep `T[]` while every operation on it stays total. Strengthen to a non-empty type only where the loose type forces a `!`, a cast, or a "should never happen" throw. |
|
|
31
|
-
| `unknown` over `any` | External data is `unknown`. `any` disables type checking everywhere it touches. |
|
|
32
|
-
| No `as` casts | Every `as` is a potential runtime crash. Cast only after validation has earned it. |
|
|
33
|
-
| Narrowing hierarchy | Discriminant switch > `in` operator > `typeof`/`instanceof` > user-defined type guard > `as`. |
|
|
34
|
-
| Type guards | Must verify the claim. A lying guard is worse than `as` — the bug hides behind a name that says it's safe. Name them `isX` or `hasX`. |
|
|
35
|
-
| Exhaustiveness | Assign to a `never`-typed local in default arms so the compiler errors when a new variant is added. |
|
|
36
|
-
| `satisfies` over `as` | Validates the value without widening literal types. |
|
|
37
|
-
| Boundary validation | Parse where data crosses in — into a named domain type, once. `Record<string, unknown>` (however spelled) stops at that parse. Inside: trust the types, no redundant re-validation, logic in pure functions the boundary shell calls. |
|
|
38
|
-
| Schema-derived types | Reach for `Pick`/`Omit`/`Parameters`/`ReturnType`/`Awaited`/`typeof` before declaring a new interface. |
|
|
39
|
-
| Object args | Pass objects, not positional arguments, so call sites are self-documenting. Skip on hot paths (per-frame render, tokenizers, parsers). |
|
|
40
|
-
|
|
41
|
-
Worked don't/do examples for every rule: `./references/patterns.md`.
|
|
42
|
-
|
|
43
|
-
## Self-Checks
|
|
44
|
-
|
|
45
|
-
- "Can I write a comment explaining when this combination of fields is valid?" If yes, the type is too loose — split it into a discriminated union.
|
|
46
|
-
- "Do two function arguments share a primitive type but mean different things?" Brand them.
|
|
47
|
-
- "Where did this `any`, this `as`, this `!` come from?" Trace it to the boundary and validate there instead.
|
|
48
|
-
- "If a new variant is added next month, will the compiler point at every place that needs a case?" If not, the match isn't exhaustive.
|
|
49
|
-
- "Is this type duplicating a shape another file or schema owns?" Derive instead.
|
|
50
|
-
- "Am I strengthening this type to keep an operation total, or just to be more precise?" If nothing would otherwise throw, keep the plain type.
|
|
20
|
+
See [boundary and totality patterns](./references/patterns.md) for the cases that commonly need care. Follow repository rules on imports and type definitions; consult installed dependency declarations rather than guessing external APIs.
|
|
@@ -1,294 +1,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Boundary and totality patterns
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Parse into a concrete value
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Brand primitives so they can't be mixed up. Validate once at creation; downstream code trusts the type.
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
type AgentId = string & { readonly __brand: "AgentId" };
|
|
11
|
-
|
|
12
|
-
function parseAgentId(input: string): AgentId {
|
|
13
|
-
if (!isUUID(input)) throw new Error(`Invalid agent id: ${input}`);
|
|
14
|
-
return input as AgentId;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function focusAgent(id: AgentId): void {
|
|
18
|
-
/* input is trusted */
|
|
19
|
-
}
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Match the `readonly __brand: 'X'` shape; don't invent a new convention.
|
|
23
|
-
|
|
24
|
-
## Discriminated unions
|
|
25
|
-
|
|
26
|
-
If a bug forces the question "wait, can this combination actually happen?", the type is too loose. Model variants with a literal discriminant: every variant shares the field name and each variant's value is unique, so impossible combos can't be represented.
|
|
27
|
-
|
|
28
|
-
```ts
|
|
29
|
-
// Don't. Boolean + optionals lets contradictory states exist.
|
|
30
|
-
type DiffState = { loading: boolean; diff?: GitDiff; error?: string };
|
|
31
|
-
|
|
32
|
-
// Do. Only valid states exist.
|
|
33
|
-
type DiffState =
|
|
34
|
-
| { kind: "loading" }
|
|
35
|
-
| { kind: "ready"; diff: GitDiff }
|
|
36
|
-
| { kind: "error"; error: string };
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Pick one discriminant name (`kind`, `type`, `tag`) per codebase and stick to it.
|
|
40
|
-
|
|
41
|
-
## Constructive modeling
|
|
42
|
-
|
|
43
|
-
Build the type from parts that are all legal instead of restricting a loose type with runtime checks. Adding is easier than subtracting.
|
|
44
|
-
|
|
45
|
-
Non-empty, via a variadic tuple:
|
|
46
|
-
|
|
47
|
-
```ts
|
|
48
|
-
type NonEmpty<T> = [T, ...T[]];
|
|
49
|
-
|
|
50
|
-
// Don't: T[] plus a length check every caller must repeat
|
|
51
|
-
function pickWinner(entries: string[]): string {
|
|
52
|
-
if (entries.length === 0) throw new Error("no entries");
|
|
53
|
-
return entries[Math.floor(Math.random() * entries.length)];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Do: an empty value of the type can't exist
|
|
57
|
-
function pickWinner(entries: NonEmpty<string>): string {
|
|
58
|
-
return entries[Math.floor(Math.random() * entries.length)];
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
Where a plain `T[]` arrives, narrow once with a guard. The fact then travels in the type:
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
const isNonEmpty = <T>(arr: T[]): arr is NonEmpty<T> => arr.length > 0;
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
Even length, as pairs — TypeScript has no refinement types (no `arr.length % 2 === 0` at the type level), and you don't need one:
|
|
69
|
-
|
|
70
|
-
```ts
|
|
71
|
-
type Pairs<T> = [T, T][];
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
A time range, as start plus duration:
|
|
75
|
-
|
|
76
|
-
```ts
|
|
77
|
-
// Don't: a comment holds the invariant
|
|
78
|
-
type TimeRange = { start: Date; end: Date }; // start <= end
|
|
79
|
-
|
|
80
|
-
// Do: a negative range can't be written; derive end when needed
|
|
81
|
-
type TimeRange = { start: Date; durationMs: number };
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Keep `durationMs` a plain number; brand it (per Branded types) only if a raw number could plausibly be passed where a duration is expected, not by reflex. A `Pairs<T>` is an even-length list under the interpretation you give it, the same way `{ start, durationMs }` is a range. Pick the representation that makes the bad state unconstructable, then expose the reading you need on top (`pairs.flat()`, a `rangeEnd()` helper).
|
|
85
|
-
|
|
86
|
-
## Simplest total type
|
|
87
|
-
|
|
88
|
-
Don't strengthen everything. Keep `T[]` while every operation on it is total:
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
const sum = (xs: number[]) => xs.reduce((a, b) => a + b, 0); // [] is 0, fine
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
Strengthen when the loose type forces a lie at a use site. The tells are `!`, `arr[0] as T`, and a "should never happen" throw:
|
|
95
|
-
|
|
96
|
-
```ts
|
|
97
|
-
// Don't: partiality smuggled past the compiler
|
|
98
|
-
function newestSession(sessions: Session[]): Session {
|
|
99
|
-
return sessions.at(0)!;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Do: strengthen the input; the assertion disappears
|
|
103
|
-
function newestSession(sessions: NonEmpty<Session>): Session {
|
|
104
|
-
return sessions[0];
|
|
105
|
-
}
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
Weakening the result to `Session | undefined` is the other total signature. Either way the empty case lands at the call site — the one place that knows what empty means.
|
|
109
|
-
|
|
110
|
-
## `unknown` over `any`
|
|
111
|
-
|
|
112
|
-
`any` disables type checking for everything it touches. External data is always `unknown`; narrow before use.
|
|
5
|
+
Construct the checked shape instead of casting partially checked external input:
|
|
113
6
|
|
|
114
7
|
```ts
|
|
115
|
-
|
|
116
|
-
function handle(input: any) {
|
|
117
|
-
return input.foo.bar;
|
|
118
|
-
}
|
|
8
|
+
type User = { id: string; active: boolean };
|
|
119
9
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
}
|
|
10
|
+
function parseUser(input: unknown): User {
|
|
11
|
+
if (typeof input !== "object" || input === null) throw new Error("expected user");
|
|
12
|
+
if (!("id" in input) || typeof input.id !== "string") throw new Error("expected id");
|
|
13
|
+
if (!("active" in input) || typeof input.active !== "boolean") throw new Error("expected active");
|
|
14
|
+
return { id: input.id, active: input.active };
|
|
125
15
|
}
|
|
126
16
|
```
|
|
127
17
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
## No `as` casts
|
|
18
|
+
Use the project's schema parser when available. Domain validation may be stricter than the TypeScript shape. A duration represented as `number` can still be negative, infinite, or NaN; validate those constraints before constructing a duration type when they matter.
|
|
131
19
|
|
|
132
|
-
|
|
20
|
+
## Strengthen only the needed operation
|
|
133
21
|
|
|
134
22
|
```ts
|
|
135
|
-
|
|
136
|
-
const user = data as User;
|
|
137
|
-
|
|
138
|
-
// Do. Earn the cast at the boundary; the checks narrow via typeof and `in`.
|
|
139
|
-
function parseUser(data: unknown): User {
|
|
140
|
-
if (typeof data !== "object" || data === null) {
|
|
141
|
-
throw new Error("expected object");
|
|
142
|
-
}
|
|
143
|
-
if (!("id" in data) || typeof data.id !== "string") {
|
|
144
|
-
throw new Error("expected string id");
|
|
145
|
-
}
|
|
146
|
-
// ... validate the remaining fields the same way
|
|
147
|
-
return data as User; // earned: every field was checked above
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
When refactoring an `as` out of existing code, identify why the compiler can't infer:
|
|
23
|
+
type NonEmpty<T> = readonly [T, ...T[]];
|
|
152
24
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
- Untyped boundary: add a parse function or schema.
|
|
156
|
-
- Genuinely inexpressible: use a branded type or `satisfies`.
|
|
157
|
-
|
|
158
|
-
## Narrowing hierarchy
|
|
159
|
-
|
|
160
|
-
From best to last-resort:
|
|
161
|
-
|
|
162
|
-
1. **Discriminated union switch / if.** The compiler narrows automatically.
|
|
163
|
-
2. **`in` operator.** `"key" in obj` narrows to the variants containing that key.
|
|
164
|
-
3. **`typeof` / `instanceof`.** For primitives and class instances.
|
|
165
|
-
4. **User-defined type guard.** When the above aren't enough.
|
|
166
|
-
5. **`as` cast.** Only after validation.
|
|
167
|
-
|
|
168
|
-
```ts
|
|
169
|
-
function area(s: Shape): number {
|
|
170
|
-
if ("radius" in s) return Math.PI * s.radius ** 2; // narrowed to circle
|
|
171
|
-
return s.width * s.height; // narrowed to rect
|
|
25
|
+
function first<T>(values: NonEmpty<T>): T {
|
|
26
|
+
return values[0];
|
|
172
27
|
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
## Type guards
|
|
176
28
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
```ts
|
|
180
|
-
function isCircle(s: Shape): s is Shape & { kind: "circle" } {
|
|
181
|
-
return s.kind === "circle";
|
|
29
|
+
function sum(values: readonly number[]): number {
|
|
30
|
+
return values.reduce((total, value) => total + value, 0);
|
|
182
31
|
}
|
|
183
32
|
```
|
|
184
33
|
|
|
185
|
-
|
|
34
|
+
A `NonEmpty<T>` proves index zero exists. A random or computed index still needs bounds reasoning; a tuple does not make every numeric lookup safe. Returning `T | undefined` is appropriate when absence is part of the caller's contract.
|
|
186
35
|
|
|
187
36
|
## Exhaustiveness
|
|
188
37
|
|
|
189
|
-
In default arms, assign the discriminant to a `never`-typed local. The compiler errors if a new variant is added without handling.
|
|
190
|
-
|
|
191
38
|
```ts
|
|
192
|
-
|
|
193
|
-
function area(s: Shape): number {
|
|
194
|
-
switch (s.kind) {
|
|
195
|
-
case "circle":
|
|
196
|
-
return Math.PI * s.radius ** 2;
|
|
197
|
-
case "rect":
|
|
198
|
-
return s.width * s.height;
|
|
199
|
-
default: {
|
|
200
|
-
const _exhaustive: never = s;
|
|
201
|
-
return _exhaustive;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
39
|
+
type Result = { kind: "ok"; value: string } | { kind: "error"; message: string };
|
|
205
40
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
case "
|
|
210
|
-
drawCircle(s);
|
|
211
|
-
break;
|
|
212
|
-
case "rect":
|
|
213
|
-
drawRect(s);
|
|
214
|
-
break;
|
|
41
|
+
function describe(result: Result): string {
|
|
42
|
+
switch (result.kind) {
|
|
43
|
+
case "ok": return result.value;
|
|
44
|
+
case "error": return result.message;
|
|
215
45
|
default: {
|
|
216
|
-
const
|
|
217
|
-
|
|
46
|
+
const exhaustive: never = result;
|
|
47
|
+
return exhaustive;
|
|
218
48
|
}
|
|
219
49
|
}
|
|
220
50
|
}
|
|
221
51
|
```
|
|
222
52
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
## `satisfies` over `as`
|
|
226
|
-
|
|
227
|
-
`satisfies` validates without widening literal types.
|
|
228
|
-
|
|
229
|
-
```ts
|
|
230
|
-
// Don't. Widens, loses literal types.
|
|
231
|
-
const config = { theme: "dark", cols: 3 } as Config;
|
|
232
|
-
|
|
233
|
-
// Do. Validates AND preserves literal types.
|
|
234
|
-
const config = { theme: "dark", cols: 3 } satisfies Config;
|
|
235
|
-
// config.theme is "dark" (literal), not string
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
## Boundary validation
|
|
239
|
-
|
|
240
|
-
Validate once where data crosses in; trust types inside. Scattered validation is noisy, redundant, and gives a false sense of safety.
|
|
241
|
-
|
|
242
|
-
- **At boundaries** (CLI args, config files, env vars, network payloads, database rows): parse into a named domain type, return errors, handle defensively.
|
|
243
|
-
- **Inside the system:** typed data, error propagation, no re-validation. No redundant null checks deep in call chains when the boundary already validated.
|
|
244
|
-
- **Across the boundary:** expose domain concepts, not the wire format — don't re-export transport, storage, or framework types through the public surface.
|
|
245
|
-
- **Wire formats** (proto, JSON-RPC): parse with unknown fields ignored so forward-compatible changes don't break old clients. **Persisted JSON:** versioned blob with a try/catch around the parse.
|
|
246
|
-
- Keep business logic in pure functions the boundary shell calls: parse functions as pure transforms from raw bytes to typed state, so the logic tests without the framework.
|
|
247
|
-
|
|
248
|
-
## Schema-derived types
|
|
249
|
-
|
|
250
|
-
When a `.proto`, OpenAPI spec, GraphQL schema, or database migration already defines a shape, derive from the generated types instead of duplicating them.
|
|
251
|
-
|
|
252
|
-
```ts
|
|
253
|
-
// Don't. Duplicate shape, drifts when the schema changes.
|
|
254
|
-
type CheckSummary = {
|
|
255
|
-
totalCount: number;
|
|
256
|
-
checks: { name: string; status: string }[];
|
|
257
|
-
};
|
|
258
|
-
function renderChecks(s: CheckSummary) {
|
|
259
|
-
/* ... */
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// Do. Derive from the generated schema type.
|
|
263
|
-
import type { ChecksMessage } from "<generated module>";
|
|
264
|
-
function renderChecks(s: Pick<ChecksMessage, "totalCount" | "checks">) {
|
|
265
|
-
/* ... */
|
|
266
|
-
}
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
Reach for `Pick`, `Omit`, `Parameters`, `ReturnType`, `Awaited`, `typeof` before writing a new interface.
|
|
270
|
-
|
|
271
|
-
## Object args
|
|
272
|
-
|
|
273
|
-
```ts
|
|
274
|
-
// Don't. Swap two args, still compiles.
|
|
275
|
-
openFile(uri, {
|
|
276
|
-
startLineNumber: 10,
|
|
277
|
-
startColumn: 1,
|
|
278
|
-
endLineNumber: 10,
|
|
279
|
-
endColumn: 1,
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
// Do. Order-independent, self-documenting.
|
|
283
|
-
openFile({
|
|
284
|
-
uri,
|
|
285
|
-
selection: {
|
|
286
|
-
startLineNumber: 10,
|
|
287
|
-
startColumn: 1,
|
|
288
|
-
endLineNumber: 10,
|
|
289
|
-
endColumn: 1,
|
|
290
|
-
},
|
|
291
|
-
});
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
Skip on hot paths: per-frame render, tokenizers, parsers, anything in a tight loop where the allocation cost matters.
|
|
53
|
+
The `never` assignment makes a newly added unhandled variant a compile error. Match the repository's existing exhaustive-switch convention.
|
package/skills/unslop/SKILL.md
CHANGED
|
@@ -1,119 +1,28 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: unslop
|
|
3
|
-
description:
|
|
3
|
+
description: Edit requested prose for clarity, specificity, and the reader's register, including simplified technical instructions when requested.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Unslop
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Apply to prose you are writing or were asked to edit: documentation, reports, handoffs, specs, commit bodies, and client-facing text. Preserve meaning and the author's intended tone. Do not sweep unrelated repository text.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Exclude code, identifiers, code comments, quoted evidence, and user-authored text outside the request. Draht's prompt and skill corpus is outside this skill's scope. Keep fixed formats exact, including conventional commit subjects, `red:`/`green:`/`refactor:`, `STATUS:` lines, frontmatter, and verdict-first reports.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Lead with the concrete fact or action. Name actors, mechanisms, and evidence. Replace promotional claims, vague attribution, filler, repeated conclusions, and unnecessary jargon with specific information or remove them. Preserve established project terminology.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
Use familiar words, active verbs, and stable names for the same concept. Vary sentence length when it improves readability. Use lists and headings for structure, not decoration. Keep uncertainty where the evidence requires it; editing for confidence must not turn an inference into a fact.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Match the register: technical reports need commands, results, and limits; explanatory prose can express a supported opinion and a more personal voice. Do not add artificial warmth or invented anecdotes.
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## Procedures and simplified technical English
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
2. Rewrite. Preserve meaning and register.
|
|
22
|
-
3. Add voice back — register-aware (see Adding Voice).
|
|
23
|
-
4. Self-audit: ask "What makes this obviously AI generated?" and fix the remaining tells.
|
|
20
|
+
For runbooks, setup instructions, warnings, and requested STE-style text:
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
- Give one action per numbered step and put conditions before the action.
|
|
23
|
+
- Place warnings before the action they protect and explain the concrete consequence.
|
|
24
|
+
- Use consistent terminology and exact command/path/error text.
|
|
25
|
+
- Prefer short sentences; aim for 20 words in procedures and 25 in descriptions.
|
|
26
|
+
- Keep necessary articles and context so brevity does not make instructions ambiguous.
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
### Content
|
|
30
|
-
|
|
31
|
-
- **Puffery and promotional language.** "pivotal moment", "testament to", "evolving landscape", "groundbreaking", "vibrant", "renowned", "stunning". Cut it; state what happened.
|
|
32
|
-
- **Superficial -ing phrases.** "highlighting...", "ensuring...", "showcasing...", "fostering...". Delete, or expand into a real statement with a real source.
|
|
33
|
-
- **Vague attributions.** "Experts believe", "reports suggest", "some argue". Name the source or delete. In a report this means citing the command or file, not "tests suggest".
|
|
34
|
-
|
|
35
|
-
### Language
|
|
36
|
-
|
|
37
|
-
- **AI vocabulary** (English-calibrated): additionally, crucial, delve, enduring, enhance, fostering, garner, interplay, intricate, landscape (abstract), pivotal, showcase, tapestry (abstract), testament, underscore, vibrant. Use the plain word.
|
|
38
|
-
- **Fancy ways to say "is".** "serves as", "stands as", "boasts", "features". Say "is" or "has".
|
|
39
|
-
- **"Not just X, but Y."** State the point directly.
|
|
40
|
-
- **Rule of three.** Ideas forced into groups of three. Use the natural number.
|
|
41
|
-
- **Synonym cycling.** Protagonist, main character, central figure, hero in one paragraph. Pick one term and repeat it — repeating the established name is precision, not monotony.
|
|
42
|
-
- **False ranges.** "from X to Y" where X and Y sit on no meaningful scale. List the items directly.
|
|
43
|
-
|
|
44
|
-
### Style
|
|
45
|
-
|
|
46
|
-
- **Dash moderation.** An em dash is punctuation, not a tell. Three per paragraph is. Do not chain them, do not let dashes replace every comma and period; vary the connective.
|
|
47
|
-
- **Colon crutches.** A colon is for a list or an example, not a mid-sentence connector. Rewrite so the point stands on its own.
|
|
48
|
-
- **Boldface spam.** Don't bold every noun, proper name, or acronym.
|
|
49
|
-
- **Inline-header lists.** The tell is a bold label and colon restating the line. A bold lead-in ending in a period, naming the item, followed by genuinely new detail is fine.
|
|
50
|
-
- **Headings** (English-only rule): sentence case, not title case.
|
|
51
|
-
- **Decorative emojis.** Remove from headings and bullets.
|
|
52
|
-
- **Curly quotes.** Replace with straight quotes.
|
|
53
|
-
|
|
54
|
-
### Communication Artifacts
|
|
55
|
-
|
|
56
|
-
The group most relevant to reports and handoffs.
|
|
57
|
-
|
|
58
|
-
- **Chatbot phrases.** "I hope this helps!", "Let me know if...", "Certainly!", "Found the smoking gun!". Remove.
|
|
59
|
-
- **Cutoff disclaimers.** "While specific details are limited...". Find the fact or drop the sentence.
|
|
60
|
-
- **Sycophancy.** "Great question!", "You're absolutely right!". Respond directly.
|
|
61
|
-
|
|
62
|
-
### Filler
|
|
63
|
-
|
|
64
|
-
- **Filler phrases** (English-calibrated). "In order to" becomes "To". "Due to the fact that" becomes "Because". "It is important to note that" gets deleted.
|
|
65
|
-
- **Hedging stacks.** "could potentially possibly be argued that it might" becomes "may".
|
|
66
|
-
- **Generic conclusions.** "The future looks bright." State the specific plan or fact, or end one sentence earlier.
|
|
67
|
-
|
|
68
|
-
### Jargon
|
|
69
|
-
|
|
70
|
-
- **Abstract metaphor nouns.** Substrate, wedge, vector, nexus, bedrock, modality, paradigm, north star, flywheel, endgame. These sound technical but hide a plainer concrete word: "substrate" becomes "base", "wedge in" becomes "add", "north star" / "flywheel" / "endgame" become the plain phrase. Pick the concrete word.
|
|
71
|
-
- **Carve-out.** A term defined in .planning/DOMAIN.md or established in the project's vocabulary is never slop — the ubiquitous-language rule wins over this list.
|
|
72
|
-
|
|
73
|
-
### Plain Speech
|
|
74
|
-
|
|
75
|
-
- **Name the mechanism, not the feeling.** "the database stays close at hand" names a feeling; "a column rename fails the build" names a mechanism. Restate every claim as a concrete instruction, fact, or number — or cut it. If the sentence could appear unchanged in another project's docs, it says nothing about this one. Cut it.
|
|
76
|
-
- **One idea per sentence.** If the reader has to backtrack to parse a sentence, split it or drop clauses.
|
|
77
|
-
- **Active voice with a named actor.** "queries are validated" becomes "the compiler validates queries". Passive is fine only when the actor is unknown or genuinely irrelevant.
|
|
78
|
-
- **Cut adverbs, or use the measured number.** "significantly improves" becomes the measured delta. An adverb propping up a weak verb means the verb is wrong.
|
|
79
|
-
- **Prefer the plain word** (English-calibrated). "utilize" becomes "use", "leverage" becomes "use", "facilitate" becomes "help", "numerous" becomes "many", "in the event that" becomes "if".
|
|
80
|
-
|
|
81
|
-
## Adding Voice
|
|
82
|
-
|
|
83
|
-
Removing patterns is half the job — voiceless prose is just as obviously machine-made. Register decides how much voice returns:
|
|
84
|
-
|
|
85
|
-
- **Docs and READMEs**: have opinions and react to facts instead of neutrally listing pros and cons; vary rhythm (short sentences, then longer ones that take their time); use "I" when it fits; be specific.
|
|
86
|
-
- **Reports, UAT reports, handoffs, client-facing text**: stay factual and concrete. Specificity is the voice there — name the file, the count, the command. No filler warmth, no manufactured mess.
|
|
87
|
-
|
|
88
|
-
## Controlled Register (STE-lite)
|
|
89
|
-
|
|
90
|
-
ASD-STE100 (Simplified Technical English) is a controlled language written for aircraft maintenance manuals. Its full rule set is strict. Going most of the way gives text that a tired or non-native reader can act on without rereading.
|
|
91
|
-
|
|
92
|
-
Use it for procedures, runbooks, setup and fix steps, warnings, and the "next steps" of a handoff. Also use it when the user asks for "STE", "ASD-STE100", "Simplified Technical English", or "make it easier to follow". Do not use it for docs and READMEs that need voice.
|
|
93
|
-
|
|
94
|
-
- **Sentence length.** At most 20 words in a procedure, at most 25 in a description.
|
|
95
|
-
- **One instruction per sentence.** Use the imperative: "Run `npm run check`." not "You should run the check."
|
|
96
|
-
- **Numbered steps, one action each.** Put the condition first: "If the check fails, read the first error."
|
|
97
|
-
- **Warnings before the step they protect.** Start with the instruction, then give the reason: "Do not delete `bun.lock`. The install is no longer reproducible."
|
|
98
|
-
- **One word, one meaning.** Pick one term for one thing and keep it. Terms from `.planning/DOMAIN.md` win.
|
|
99
|
-
- **Active voice, present tense** for descriptions.
|
|
100
|
-
- **Keep the articles.** "Open the file", not "Open file". Telegraphic style is not STE.
|
|
101
|
-
- **Paragraphs** have one topic and at most six sentences.
|
|
102
|
-
- **Technical names stay exact.** Commands, identifiers, paths, and error text are quoted verbatim even when they break the rules above.
|
|
103
|
-
|
|
104
|
-
STE is defined for English. For German text, apply the same limits by analogy: kurze Sätze, Imperativ in Anleitungen, ein Begriff pro Sache, Warnung vor dem Schritt.
|
|
105
|
-
|
|
106
|
-
## German Prose
|
|
107
|
-
|
|
108
|
-
The word lists above are English-calibrated. The discipline generalizes to German by category, not by translated catalog:
|
|
109
|
-
|
|
110
|
-
- **Füllwörter**: "im Grunde genommen", "quasi", "sozusagen" — streichen.
|
|
111
|
-
- **Werbesprache**: "innovativ", "ganzheitlich", "im heutigen digitalen Zeitalter", "spielt eine entscheidende Rolle" — sagen, was passiert ist.
|
|
112
|
-
- **Anglizismen-Slop**: "leveragen", "alignen" where a German word exists — use the German word.
|
|
113
|
-
- "nicht nur X, sondern auch Y" is the "not just X, but Y" tell verbatim: state the point directly.
|
|
114
|
-
- Style and format tells (dash chaining, bold spam, decorative emojis, curly quotes) and communication artifacts (chatbot phrases, disclaimers, sycophancy) are language-independent.
|
|
115
|
-
- The sentence-case-headings rule is English-only — German headings follow German orthography.
|
|
116
|
-
|
|
117
|
-
## Self-Audit
|
|
118
|
-
|
|
119
|
-
Before delivering, ask once more: "What makes this obviously AI generated?" Fix what you find.
|
|
28
|
+
These are practical readability guidelines, not a claim of certified ASD-STE100 compliance. Apply the same clarity principles to German while preserving German grammar and established technical terms.
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { createRequire as __drahtCreateRequire } from "node:module"; const require = __drahtCreateRequire(import.meta.url);
|
|
2
|
-
import{ANTHROPIC_FEDERATION_RULE_ID_ENV,ANTHROPIC_IDENTITY_TOKEN_FILE_ENV,ANTHROPIC_ORGANIZATION_ID_ENV,ANTHROPIC_SERVICE_ACCOUNT_ID_ENV,ANTHROPIC_WORKSPACE_ID_ENV}from"./chunk-XBUEMKIY.js";import{buildCopilotDynamicHeaders,hasCopilotVisionInput}from"./chunk-HTJ3L72O.js";import{Anthropic}from"./chunk-RZKPFWMH.js";import{retryProviderRequest}from"./chunk-KPO5375S.js";import{adjustMaxTokensForThinking,buildBaseOptions,clampMaxTokensToContext,getDrahtUserAgent,getJsonSchemaToolParameters,resolveJsonSchemaStrictSampling,transformMessages}from"./chunk-SDRCE6OP.js";import{sanitizeSurrogates}from"./chunk-63BK6WK2.js";import{headersToRecord}from"./chunk-EBVYI75P.js";import{getProviderEnvValue}from"./chunk-2N4I6WXC.js";import{parseJsonWithRepair,parseStreamingJson}from"./chunk-IWTUBX6V.js";import{calculateCost,getCurrentTools,getDeclaredTools,getInitialSystemMessage,getSystemMessageText,hasToolRedefinitions,renderSystemMessageUpdate,resolveTranscript}from"./chunk-I5OKY6RH.js";import{AssistantMessageEventStream,appendAssistantMessageDiagnostic}from"./chunk-GVXA72ZA.js";import"./chunk-HZ2UHMBT.js";function resolveCacheRetention(cacheRetention,env){return cacheRetention||(getProviderEnvValue("DRAHT_CACHE_RETENTION",env)==="long"?"long":"short")}function getCacheControl(model,cacheRetention,env){let retention=resolveCacheRetention(cacheRetention,env);if(retention==="none")return{retention};let ttl=retention==="long"&&getAnthropicCompat(model).supportsLongCacheRetention?"1h":void 0;return{retention,cacheControl:{type:"ephemeral",...ttl&&{ttl}}}}var claudeCodeVersion="2.1.280",claudeCodeTools=["Read","Write","Edit","Bash","Grep","Glob","AskUserQuestion","EnterPlanMode","ExitPlanMode","KillShell","NotebookEdit","Skill","Task","TaskOutput","TodoWrite","WebFetch","WebSearch"],ccToolLookup=new Map(claudeCodeTools.map(t=>[t.toLowerCase(),t])),toClaudeCodeName=name=>ccToolLookup.get(name.toLowerCase())??name,fromClaudeCodeName=(name,tools)=>{if(tools&&tools.length>0){let lowerName=name.toLowerCase(),matchedTool=tools.find(tool=>tool.name.toLowerCase()===lowerName);if(matchedTool)return matchedTool.name}return name};function convertContentBlocks(content){if(!content.some(c=>c.type==="image"))return sanitizeSurrogates(content.map(c=>c.text).join(`
|
|
3
|
-
`));let blocks=content.map(block=>block.type==="text"?{type:"text",text:sanitizeSurrogates(block.text)}:{type:"image",source:{type:"base64",media_type:block.mimeType,data:block.data}});return blocks.some(b=>b.type==="text")||blocks.unshift({type:"text",text:"(see attached image)"}),blocks}var FINE_GRAINED_TOOL_STREAMING_BETA="fine-grained-tool-streaming-2025-05-14",INTERLEAVED_THINKING_BETA="interleaved-thinking-2025-05-14",SERVER_SIDE_FALLBACK_BETA="server-side-fallback-2026-07-01",MID_CONVERSATION_OUTPUT_CONFIG_BETA="mid-conversation-output-config-2026-07-01",THINKING_BINDING_CONTROLS_BETA="thinking-binding-controls-2026-08-01",MID_CONVERSATION_TOOL_CHANGES_BETA="mid-conversation-tool-changes-2026-07-01",DEFERRED_TOOL_PLACEHOLDER={name:"__pi_deferred_placeholder__",description:"Reserved placeholder. Never available. Never call this.",input_schema:{type:"object",properties:{},required:[]},defer_loading:!0};function shouldUseServerSideFallbackBeta(model){return(model.compat?.allowedFallbackModels?.length??0)>0}function getAnthropicCompat(model){let isOpenRouter=model.provider==="openrouter"||model.baseUrl.includes("openrouter.ai");return{supportsEagerToolInputStreaming:model.compat?.supportsEagerToolInputStreaming??!0,supportsLongCacheRetention:model.compat?.supportsLongCacheRetention??!0,sendSessionAffinityHeaders:model.compat?.sendSessionAffinityHeaders??isOpenRouter,sessionAffinityFormat:model.compat?.sessionAffinityFormat??(isOpenRouter?"openrouter":void 0),supportsCacheControlOnTools:model.compat?.supportsCacheControlOnTools??!0,supportsTemperature:model.compat?.supportsTemperature??!0,allowEmptySignature:model.compat?.allowEmptySignature??!1,supportsStrictTools:model.compat?.supportsStrictTools??!1,supportsMidConvoSystemMessages:model.compat?.supportsMidConvoSystemMessages??!1,supportsMidConvoToolChanges:model.compat?.supportsMidConvoToolChanges??!1}}function mergeHeaders(...headerSources){let merged={};for(let headers of headerSources)headers&&Object.assign(merged,headers);return merged}function mergeClientHeaders(...headerSources){return mergeHeaders({"User-Agent":getDrahtUserAgent()},...headerSources)}function hasHeader(headers,name){if(!headers)return!1;let expected=name.toLowerCase();for(let[key,value]of Object.entries(headers))if(key.toLowerCase()===expected&&value!==null&&value.trim().length>0)return!0;return!1}function hasRequestAuth(apiKey,headers){return!!apiKey||hasHeader(headers,"authorization")||hasHeader(headers,"x-api-key")||hasHeader(headers,"cf-aig-authorization")}function assertRequestAuth(provider,apiKey,headers){if(!hasRequestAuth(apiKey,headers))throw new Error(`No API key for provider: ${provider}`)}var PiAnthropic=class extends Anthropic{_shouldResolveDefaultCredentials(){return!1}};function getAnthropicFederation(model,apiKey,headers,env){if(model.provider!=="anthropic"||hasRequestAuth(apiKey,headers))return;let federationRuleId=getProviderEnvValue(ANTHROPIC_FEDERATION_RULE_ID_ENV,env),organizationId=getProviderEnvValue(ANTHROPIC_ORGANIZATION_ID_ENV,env),identityTokenFile=getProviderEnvValue(ANTHROPIC_IDENTITY_TOKEN_FILE_ENV,env);if(!(!federationRuleId||!organizationId||!identityTokenFile))return{organization_id:organizationId,workspace_id:getProviderEnvValue(ANTHROPIC_WORKSPACE_ID_ENV,env),authentication:{type:"oidc_federation",federation_rule_id:federationRuleId,service_account_id:getProviderEnvValue(ANTHROPIC_SERVICE_ACCOUNT_ID_ENV,env),identity_token:{source:"file",path:identityTokenFile}}}}var federationClient,ANTHROPIC_MESSAGE_EVENTS=new Set(["message_start","message_delta","message_stop","content_block_start","content_block_delta","content_block_stop"]);function flushSseEvent(state){if(!state.event&&state.data.length===0)return null;let event={event:state.event,data:state.data.join(`
|
|
4
|
-
`),raw:[...state.raw]};return state.event=null,state.data=[],state.raw=[],event}function decodeSseLine(line,state){if(line==="")return flushSseEvent(state);if(state.raw.push(line),line.startsWith(":"))return null;let delimiterIndex=line.indexOf(":"),fieldName=delimiterIndex===-1?line:line.slice(0,delimiterIndex),value=delimiterIndex===-1?"":line.slice(delimiterIndex+1);return value.startsWith(" ")&&(value=value.slice(1)),fieldName==="event"?state.event=value:fieldName==="data"&&state.data.push(value),null}function nextLineBreakIndex(text){let carriageReturnIndex=text.indexOf("\r"),newlineIndex=text.indexOf(`
|
|
5
|
-
`);return carriageReturnIndex===-1?newlineIndex:newlineIndex===-1?carriageReturnIndex:Math.min(carriageReturnIndex,newlineIndex)}function consumeLine(text){let lineBreakIndex=nextLineBreakIndex(text);if(lineBreakIndex===-1)return null;let nextIndex=lineBreakIndex+1;return text[lineBreakIndex]==="\r"&&text[nextIndex]===`
|
|
6
|
-
`&&(nextIndex+=1),{line:text.slice(0,lineBreakIndex),rest:text.slice(nextIndex)}}async function*iterateSseMessages(body,signal){let reader=body.getReader(),decoder=new TextDecoder,state={event:null,data:[],raw:[]},buffer="";try{for(;;){if(signal?.aborted)throw new Error("Request was aborted");let{value,done}=await reader.read();if(done)break;buffer+=decoder.decode(value,{stream:!0});let consumed2=consumeLine(buffer);for(;consumed2;){buffer=consumed2.rest;let event=decodeSseLine(consumed2.line,state);event&&(yield event),consumed2=consumeLine(buffer)}}buffer+=decoder.decode();let consumed=consumeLine(buffer);for(;consumed;){buffer=consumed.rest;let event=decodeSseLine(consumed.line,state);event&&(yield event),consumed=consumeLine(buffer)}if(buffer.length>0){let event=decodeSseLine(buffer,state);event&&(yield event)}let trailingEvent=flushSseEvent(state);trailingEvent&&(yield trailingEvent)}finally{reader.releaseLock()}}async function*iterateAnthropicEvents(response,signal){if(!response.body)throw new Error("Attempted to iterate over an Anthropic response with no body");let sawMessageStart=!1,sawMessageEnd=!1;for await(let sse of iterateSseMessages(response.body,signal)){if(sse.event==="error")throw new Error(sse.data);if(ANTHROPIC_MESSAGE_EVENTS.has(sse.event??""))try{let event=parseJsonWithRepair(sse.data);event.type==="message_start"?sawMessageStart=!0:event.type==="message_stop"&&(sawMessageEnd=!0),yield event}catch(error){let message=error instanceof Error?error.message:String(error);throw new Error(`Could not parse Anthropic SSE event ${sse.event}: ${message}; data=${sse.data}; raw=${sse.raw.join("\\n")}`)}}if(sawMessageStart&&!sawMessageEnd)throw new Error("Anthropic stream ended before message_stop")}var stream=(model,context,options)=>{let stream2=new AssistantMessageEventStream,normalizedContext=resolveTranscript(context,getAnthropicCompat(model).supportsMidConvoSystemMessages),currentTools=getCurrentTools(normalizedContext.messages);return(async()=>{let providerThinkingLevel=model.compat?.supportsMidConvoEffort?options?.effort??"high":void 0,output={role:"assistant",content:[],api:model.api,provider:model.provider,model:model.id,...providerThinkingLevel===void 0?{}:{providerThinkingLevel},usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()};try{let client,isOAuth,usageModel=model,inputTransformations;if(options?.client)client=options.client,isOAuth=!1;else{let apiKey=options?.apiKey,federation=getAnthropicFederation(model,apiKey,options?.headers,options?.env);federation||assertRequestAuth(model.provider,apiKey,options?.headers);let copilotDynamicHeaders;if(model.provider==="github-copilot"){let hasImages=hasCopilotVisionInput(normalizedContext.messages);copilotDynamicHeaders=buildCopilotDynamicHeaders({messages:normalizedContext.messages,hasImages})}let cacheSessionId=resolveCacheRetention(options?.cacheRetention,options?.env)==="none"?void 0:options?.sessionId,created=createClient(model,apiKey,options?.headers,options?.fetch,copilotDynamicHeaders,cacheSessionId,federation);client=created.client,isOAuth=created.isOAuthToken}let params=buildParams(model,normalizedContext,isOAuth,options),nextParams=await options?.onPayload?.(params,model);nextParams!==void 0&&(params={...nextParams,stream:!0});let requestOptions={...options?.signal?{signal:options.signal}:{},...options?.timeoutMs!==void 0?{timeout:options.timeoutMs}:{},maxRetries:0},response=await retryProviderRequest(()=>client.beta.messages.create(params,requestOptions).asResponse(),{maxRetries:options?.maxRetries,maxRetryDelayMs:options?.maxRetryDelayMs,signal:options?.signal});await options?.onResponse?.({status:response.status,headers:headersToRecord(response.headers)},model),stream2.push({type:"start",partial:output});let blocks=output.content;for await(let event of iterateAnthropicEvents(response,options?.signal))if(await options?.onProviderStreamEvent?.(event,model),event.type==="message_start"){output.responseId=event.message.id;let transformations=event.message.input_transformations;Array.isArray(transformations)&&(inputTransformations=transformations);let responseModel=event.message.model;responseModel!==model.id&&(output.responseModel=responseModel);let fallbackCost=responseModel===model.id?void 0:model.compat?.allowedFallbackModels?.find(fallback=>fallback.provider===model.provider&&fallback.model===responseModel)?.cost;usageModel=fallbackCost?{...model,id:responseModel,cost:fallbackCost}:model,output.usage.input=event.message.usage.input_tokens||0,output.usage.output=event.message.usage.output_tokens||0,output.usage.cacheRead=event.message.usage.cache_read_input_tokens||0,output.usage.cacheWrite=event.message.usage.cache_creation_input_tokens||0,output.usage.cacheWrite1h=event.message.usage.cache_creation?.ephemeral_1h_input_tokens||0,output.usage.totalTokens=output.usage.input+output.usage.output+output.usage.cacheRead+output.usage.cacheWrite,calculateCost(usageModel,output.usage)}else if(event.type==="content_block_start"){if(event.content_block.type==="fallback"){if(output.content.length>0)throw new Error("Anthropic performed an unsupported mid-output model fallback");continue}if(event.content_block.type==="text"){let block={type:"text",text:event.content_block.text??"",index:event.index};output.content.push(block),stream2.push({type:"text_start",contentIndex:output.content.length-1,partial:output})}else if(event.content_block.type==="thinking"){let block={type:"thinking",thinking:event.content_block.thinking??"",thinkingSignature:event.content_block.signature??"",index:event.index};output.content.push(block),stream2.push({type:"thinking_start",contentIndex:output.content.length-1,partial:output})}else if(event.content_block.type==="redacted_thinking"){let block={type:"thinking",thinking:"[Reasoning redacted]",thinkingSignature:event.content_block.data,redacted:!0,index:event.index};output.content.push(block),stream2.push({type:"thinking_start",contentIndex:output.content.length-1,partial:output})}else if(event.content_block.type==="tool_use"){let block={type:"toolCall",id:event.content_block.id,name:isOAuth?fromClaudeCodeName(event.content_block.name,currentTools):event.content_block.name,arguments:event.content_block.input??{},partialJson:"",index:event.index};output.content.push(block),stream2.push({type:"toolcall_start",contentIndex:output.content.length-1,partial:output})}}else if(event.type==="content_block_delta"){if(event.delta.type==="text_delta"){let index=blocks.findIndex(b=>b.index===event.index),block=blocks[index];block&&block.type==="text"&&(block.text+=event.delta.text,stream2.push({type:"text_delta",contentIndex:index,delta:event.delta.text,partial:output}))}else if(event.delta.type==="thinking_delta"){let index=blocks.findIndex(b=>b.index===event.index),block=blocks[index];block&&block.type==="thinking"&&(block.thinking+=event.delta.thinking,stream2.push({type:"thinking_delta",contentIndex:index,delta:event.delta.thinking,partial:output}))}else if(event.delta.type==="input_json_delta"){let index=blocks.findIndex(b=>b.index===event.index),block=blocks[index];block&&block.type==="toolCall"&&(block.partialJson+=event.delta.partial_json,block.arguments=parseStreamingJson(block.partialJson),stream2.push({type:"toolcall_delta",contentIndex:index,delta:event.delta.partial_json,partial:output}))}else if(event.delta.type==="signature_delta"){let index=blocks.findIndex(b=>b.index===event.index),block=blocks[index];block&&block.type==="thinking"&&(block.thinkingSignature=block.thinkingSignature||"",block.thinkingSignature+=event.delta.signature)}}else if(event.type==="content_block_stop"){let index=blocks.findIndex(b=>b.index===event.index),block=blocks[index];block&&(delete block.index,block.type==="text"?stream2.push({type:"text_end",contentIndex:index,content:block.text,partial:output}):block.type==="thinking"?stream2.push({type:"thinking_end",contentIndex:index,content:block.thinking,partial:output}):block.type==="toolCall"&&(block.arguments=parseStreamingJson(block.partialJson),delete block.partialJson,stream2.push({type:"toolcall_end",contentIndex:index,toolCall:block,partial:output})))}else if(event.type==="message_delta"){let transformations=event.input_transformations;if(Array.isArray(transformations)&&(inputTransformations=transformations),event.delta.stop_reason){output.rawStopReason=event.delta.stop_reason;let stopReasonResult=mapStopReason(event.delta.stop_reason,event.delta.stop_details);output.stopReason=stopReasonResult.stopReason,stopReasonResult.errorMessage&&(output.errorMessage=stopReasonResult.errorMessage)}if(event.usage){event.usage.input_tokens!=null&&(output.usage.input=event.usage.input_tokens),event.usage.output_tokens!=null&&(output.usage.output=event.usage.output_tokens),event.usage.cache_read_input_tokens!=null&&(output.usage.cacheRead=event.usage.cache_read_input_tokens),event.usage.cache_creation_input_tokens!=null&&(output.usage.cacheWrite=event.usage.cache_creation_input_tokens);let cacheCreation=event.usage.cache_creation;cacheCreation?.ephemeral_1h_input_tokens!=null&&(output.usage.cacheWrite1h=cacheCreation.ephemeral_1h_input_tokens);let thinkingTokens=event.usage.output_tokens_details?.thinking_tokens;thinkingTokens!=null&&(output.usage.reasoning=thinkingTokens)}output.usage.totalTokens=output.usage.input+output.usage.output+output.usage.cacheRead+output.usage.cacheWrite,calculateCost(usageModel,output.usage)}if(options?.signal?.aborted)throw new Error("Request was aborted");if(output.stopReason==="pending")throw new Error("Anthropic stream ended without a stop reason");if(output.stopReason==="aborted"||output.stopReason==="error")throw new Error(output.errorMessage||"An unknown error occurred");inputTransformations&&inputTransformations.length>0&&appendAssistantMessageDiagnostic(output,{type:"anthropic_input_transformations",timestamp:Date.now(),details:{transformations:inputTransformations.map(transformation=>({type:transformation.type??void 0,path:transformation.path??void 0,reason:transformation.reason??void 0}))}}),stream2.push({type:"done",reason:output.stopReason,message:output}),stream2.end()}catch(error){for(let block of output.content)delete block.index,delete block.partialJson;output.stopReason=options?.signal?.aborted?"aborted":"error",output.errorMessage=error instanceof Error?error.message:JSON.stringify(error),stream2.push({type:"error",reason:output.stopReason,error:output}),stream2.end()}})(),stream2};function mapThinkingLevelToEffort(model,level){let mapped=level?model.thinkingLevelMap?.[level]:void 0;if(typeof mapped=="string")return mapped;switch(level){case"minimal":case"low":return"low";case"medium":return"medium";case"high":return"high";default:return"high"}}var streamSimple=(model,context,options)=>{getAnthropicFederation(model,options?.apiKey,options?.headers,options?.env)||assertRequestAuth(model.provider,options?.apiKey,options?.headers);let base={...buildBaseOptions(model,context,options,options?.apiKey),toolChoice:options?.toolChoice};if(!options?.reasoning)return stream(model,context,{...base,thinkingEnabled:!1});if(model.compat?.forceAdaptiveThinking===!0){let effort=mapThinkingLevelToEffort(model,options.reasoning);return stream(model,context,{...base,thinkingEnabled:!0,effort})}let adjusted=adjustMaxTokensForThinking(base.maxTokens,model.maxTokens,options.reasoning,options.thinkingBudgets),maxTokens=clampMaxTokensToContext(model,context,adjusted.maxTokens);return stream(model,context,{...base,maxTokens,thinkingEnabled:!0,thinkingBudgetTokens:Math.min(adjusted.thinkingBudget,Math.max(0,maxTokens-1024))})};function isOAuthToken(apiKey){return apiKey.includes("sk-ant-oat")}function createClient(model,apiKey,optionsHeaders,fetch,dynamicHeaders,sessionId,federation){if(model.provider==="github-copilot")return{client:new PiAnthropic({apiKey:null,authToken:apiKey??null,baseURL:model.baseUrl,dangerouslyAllowBrowser:!0,fetch,defaultHeaders:mergeClientHeaders({accept:"application/json","anthropic-dangerous-direct-browser-access":"true"},model.headers,dynamicHeaders,optionsHeaders)}),isOAuthToken:!1};if(apiKey&&isOAuthToken(apiKey))return{client:new PiAnthropic({apiKey:null,authToken:apiKey,baseURL:model.baseUrl,dangerouslyAllowBrowser:!0,fetch,defaultHeaders:mergeClientHeaders({accept:"application/json","anthropic-dangerous-direct-browser-access":"true","user-agent":`claude-cli/${claudeCodeVersion}`,"x-app":"cli"},model.headers,optionsHeaders)}),isOAuthToken:!0};let compat=getAnthropicCompat(model),sessionAffinityHeaders={};if(sessionId&&compat.sendSessionAffinityHeaders){let header=compat.sessionAffinityFormat==="openrouter"?"x-session-id":"x-session-affinity";sessionAffinityHeaders[header]=sessionId}let defaultHeaders=mergeClientHeaders({accept:"application/json","anthropic-dangerous-direct-browser-access":"true"},sessionAffinityHeaders,model.headers,optionsHeaders);if(federation){let key=JSON.stringify([model.baseUrl,federation]);if(federationClient?.key!==key||federationClient.fetch!==fetch){let client2=new PiAnthropic({apiKey:null,authToken:null,config:federation,baseURL:model.baseUrl,dangerouslyAllowBrowser:!0,fetch});federationClient={key,fetch,client:client2}}return{client:federationClient.client.withOptions({defaultHeaders}),isOAuthToken:!1}}return{client:new PiAnthropic({apiKey:apiKey??null,authToken:null,baseURL:model.baseUrl,dangerouslyAllowBrowser:!0,fetch,defaultHeaders}),isOAuthToken:!1}}function getBetaFeatures(model,context,isOAuthToken2,nativeToolChanges,options){let configuredFeatures;for(let headers of[model.headers,options?.headers])for(let[name,value]of Object.entries(headers??{}))name.toLowerCase()==="anthropic-beta"&&(configuredFeatures=value);if(configuredFeatures===null)return[];if(configuredFeatures!==void 0)return[...new Set(configuredFeatures.split(",").map(feature=>feature.trim()).filter(feature=>feature.length>0))];let features=[];return isOAuthToken2&&features.push("claude-code-20250219","oauth-2025-04-20"),shouldUseFineGrainedToolStreamingBeta(model,context)&&features.push(FINE_GRAINED_TOOL_STREAMING_BETA),model.reasoning&&options?.thinkingEnabled===!0&&(options.interleavedThinking??!0)&&model.compat?.forceAdaptiveThinking!==!0&&features.push(INTERLEAVED_THINKING_BETA),shouldUseServerSideFallbackBeta(model)&&features.push(SERVER_SIDE_FALLBACK_BETA),model.compat?.supportsMidConvoEffort===!0&&features.push(MID_CONVERSATION_OUTPUT_CONFIG_BETA,THINKING_BINDING_CONTROLS_BETA),nativeToolChanges&&features.push(MID_CONVERSATION_TOOL_CHANGES_BETA),[...new Set(features)]}function buildParams(model,context,isOAuthToken2,options){let{cacheControl}=getCacheControl(model,options?.cacheRetention,options?.env),compat=getAnthropicCompat(model),initialSystemMessage=getInitialSystemMessage(context.messages),initialSystemText=initialSystemMessage?getSystemMessageText(initialSystemMessage):"",transformedMessages=transformMessages(context.messages,model,normalizeToolCallId),conversationMessages=initialSystemMessage?transformedMessages.slice(1):transformedMessages,initialTools=initialSystemMessage?.toolsAdded??[],nativeToolChanges=compat.supportsMidConvoSystemMessages&&compat.supportsMidConvoToolChanges&&initialTools.length>0&&!hasToolRedefinitions(context.messages),converted=convertMessages(conversationMessages,isOAuthToken2,cacheControl,compat.allowEmptySignature,model.compat?.supportsMidConvoEffort===!0?model.provider:void 0,nativeToolChanges),activeEffort=options?.effort??"high",betaFeatures=getBetaFeatures(model,context,isOAuthToken2,nativeToolChanges,options),params={model:model.id,messages:model.compat?.supportsMidConvoEffort===!0?insertThinkingLevelMessages(converted,activeEffort):converted.messages,max_tokens:options?.maxTokens??model.maxTokens,stream:!0,...betaFeatures.length>0?{betas:betaFeatures}:{}};isOAuthToken2?(params.system=[{type:"text",text:"You are Claude Code, Anthropic's official CLI for Claude.",...cacheControl?{cache_control:cacheControl}:{}}],initialSystemText&¶ms.system.push({type:"text",text:sanitizeSurrogates(initialSystemText),...cacheControl?{cache_control:cacheControl}:{}})):initialSystemText&&(params.system=[{type:"text",text:sanitizeSurrogates(initialSystemText),...cacheControl?{cache_control:cacheControl}:{}}]),options?.temperature!==void 0&&!options?.thinkingEnabled&&model.compat?.supportsMidConvoEffort!==!0&&compat.supportsTemperature&&(params.temperature=options.temperature);let toolCacheControl=compat.supportsCacheControlOnTools?cacheControl:void 0;if(nativeToolChanges){let initialNames=new Set(initialTools.map(tool=>tool.name)),laterTools=getDeclaredTools(context.messages).filter(tool=>!initialNames.has(tool.name));params.tools=[...convertTools(initialTools,isOAuthToken2,compat.supportsEagerToolInputStreaming,compat.supportsStrictTools,toolCacheControl),DEFERRED_TOOL_PLACEHOLDER,...convertTools(laterTools,isOAuthToken2,compat.supportsEagerToolInputStreaming,compat.supportsStrictTools).map(tool=>({...tool,defer_loading:!0}))]}else{let tools=getCurrentTools(context.messages);tools.length>0&&(params.tools=convertTools(tools,isOAuthToken2,compat.supportsEagerToolInputStreaming,compat.supportsStrictTools,toolCacheControl))}if(model.compat?.supportsMidConvoEffort===!0)params.thinking={type:"adaptive",display:options?.thinkingDisplay??"summarized",block_binding:{prefix_mismatch_behavior:"drop_block"}},params.output_config={effort:"high"};else if(model.reasoning)if(options?.thinkingEnabled){let display=options.thinkingDisplay??"summarized";model.compat?.forceAdaptiveThinking===!0?(params.thinking={type:"adaptive",display},options.effort&&(params.output_config={effort:options.effort})):params.thinking={type:"enabled",budget_tokens:options.thinkingBudgetTokens||1024,display}}else options?.thinkingEnabled===!1&&model.thinkingLevelMap?.off!==null&&(params.thinking={type:"disabled"});if(options?.metadata){let userId=options.metadata.user_id;typeof userId=="string"&&(params.metadata={user_id:userId})}options?.toolChoice&&(typeof options.toolChoice=="string"?params.tool_choice={type:options.toolChoice}:params.tool_choice=options.toolChoice);let allowedFallbackModels=model.compat?.allowedFallbackModels;return allowedFallbackModels&&allowedFallbackModels.length>0&&(params.fallbacks=allowedFallbackModels.map(fallback=>({model:fallback.model}))),params}function normalizeToolCallId(id){return id.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,64)}function convertToolResult(msg){return{type:"tool_result",tool_use_id:msg.toolCallId,content:convertContentBlocks(msg.content),is_error:msg.isError}}function convertMessages(transformedMessages,isOAuthToken2,cacheControl,allowEmptySignature=!1,managedProvider,nativeToolChanges=!1){let params=[],assistantLevels=new Map,pendingSystemMessages=[],flushPendingSystemMessages=()=>{params.push(...pendingSystemMessages),pendingSystemMessages.length=0};for(let i=0;i<transformedMessages.length;i++){let msg=transformedMessages[i];if(msg.role==="system"){let text=renderSystemMessageUpdate(msg),blocks=[];if(text.length>0&&blocks.push({type:"text",text:sanitizeSurrogates(text)}),nativeToolChanges){for(let tool of msg.toolsRemoved??[])blocks.push({type:"tool_removal",tool:{type:"tool_reference",name:isOAuthToken2?toClaudeCodeName(tool.name):tool.name}});for(let tool of msg.toolsAdded??[])blocks.push({type:"tool_addition",tool:{type:"tool_reference",name:isOAuthToken2?toClaudeCodeName(tool.name):tool.name}})}blocks.length>0&&pendingSystemMessages.push({role:"system",content:blocks})}else if(msg.role==="user")if(typeof msg.content=="string")msg.content.trim().length>0&¶ms.push({role:"user",content:sanitizeSurrogates(msg.content)});else{let filteredBlocks=msg.content.map(item=>item.type==="text"?{type:"text",text:sanitizeSurrogates(item.text)}:{type:"image",source:{type:"base64",media_type:item.mimeType,data:item.data}}).filter(b=>b.type==="text"?b.text.trim().length>0:!0);if(filteredBlocks.length===0)continue;params.push({role:"user",content:filteredBlocks})}else if(msg.role==="assistant"){flushPendingSystemMessages();let blocks=[];for(let block of msg.content)if(block.type==="text"){if(block.text.trim().length===0)continue;blocks.push({type:"text",text:sanitizeSurrogates(block.text)})}else if(block.type==="thinking"){if(block.redacted){blocks.push({type:"redacted_thinking",data:block.thinkingSignature});continue}let thinkingSignature=block.thinkingSignature,hasThinkingSignature=!!thinkingSignature&&thinkingSignature.trim().length>0;if(block.thinking.trim().length===0&&!hasThinkingSignature)continue;hasThinkingSignature?blocks.push({type:"thinking",thinking:sanitizeSurrogates(block.thinking),signature:thinkingSignature}):blocks.push(allowEmptySignature?{type:"thinking",thinking:sanitizeSurrogates(block.thinking),signature:""}:{type:"text",text:sanitizeSurrogates(block.thinking)})}else block.type==="toolCall"&&blocks.push({type:"tool_use",id:block.id,name:isOAuthToken2?toClaudeCodeName(block.name):block.name,input:block.arguments??{}});if(blocks.length===0)continue;let messageIndex=params.length;params.push({role:"assistant",content:blocks}),managedProvider!==void 0&&msg.api==="anthropic-messages"&&msg.provider===managedProvider&&isAnthropicEffort(msg.providerThinkingLevel)&&assistantLevels.set(messageIndex,msg.providerThinkingLevel)}else if(msg.role==="toolResult"){let toolResults=[],j=i;for(;j<transformedMessages.length&&transformedMessages[j].role==="toolResult";)toolResults.push(convertToolResult(transformedMessages[j])),j++;i=j-1,params.push({role:"user",content:toolResults})}}if(flushPendingSystemMessages(),cacheControl&¶ms.length>0){let lastMessage=params[params.length-1];if(lastMessage.role==="user"||lastMessage.role==="system")if(Array.isArray(lastMessage.content)){let lastBlock=lastMessage.content[lastMessage.content.length-1];lastBlock&&(lastBlock.type==="text"||lastBlock.type==="image"||lastBlock.type==="tool_result"||lastBlock.type==="tool_addition"||lastBlock.type==="tool_removal")&&(lastBlock.cache_control=cacheControl)}else typeof lastMessage.content=="string"&&(lastMessage.content=[{type:"text",text:lastMessage.content,cache_control:cacheControl}])}return{messages:params,assistantLevels}}function isAnthropicEffort(value){return value==="low"||value==="medium"||value==="high"||value==="xhigh"||value==="max"}function insertThinkingLevelMessages(converted,activeEffort){let messages=[];for(let index=0;index<converted.messages.length;index++){let historicalEffort=converted.assistantLevels.get(index);historicalEffort!==void 0&&messages.push({role:"system",content:[],output_config:{effort:historicalEffort}}),messages.push(converted.messages[index])}return messages.push({role:"system",content:[],output_config:{effort:activeEffort}}),messages}function shouldUseFineGrainedToolStreamingBeta(model,context){return getCurrentTools(context.messages).length>0&&!getAnthropicCompat(model).supportsEagerToolInputStreaming}var ANTHROPIC_STRICT_UNSUPPORTED_KEYWORDS=new Set(["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","maxItems","uniqueItems","minContains","maxContains","minProperties","maxProperties"]),ANTHROPIC_STRICT_STRING_FORMATS=new Set(["date-time","time","date","duration","email","hostname","uri","ipv4","ipv6","uuid"]),isAnthropicStrictUnsupportedKeyword=(key,value)=>ANTHROPIC_STRICT_UNSUPPORTED_KEYWORDS.has(key)?!0:key==="minItems"?value!==0&&value!==1:key==="format"?typeof value!="string"||!ANTHROPIC_STRICT_STRING_FORMATS.has(value):!1;function convertTools(tools,isOAuthToken2,supportsEagerToolInputStreaming,supportsStrictTools,cacheControl){return tools?tools.map((tool,index)=>{let strict=resolveJsonSchemaStrictSampling(tool,supportsStrictTools,isAnthropicStrictUnsupportedKeyword),parameters=getJsonSchemaToolParameters(tool,strict),schema=parameters,legacyInputSchema={type:"object",properties:schema.properties??{},required:schema.required??[]},inputSchema=strict===!0?{...parameters,...legacyInputSchema}:legacyInputSchema;return{name:isOAuthToken2?toClaudeCodeName(tool.name):tool.name,description:tool.description,...supportsEagerToolInputStreaming?{eager_input_streaming:!0}:{},...strict===!0?{strict:!0}:{},input_schema:inputSchema,...cacheControl&&index===tools.length-1?{cache_control:cacheControl}:{}}}):[]}function mapStopReason(reason,stopDetails){switch(reason){case"end_turn":return{stopReason:"stop"};case"max_tokens":return{stopReason:"length"};case"tool_use":return{stopReason:"toolUse"};case"refusal":return{stopReason:"error",errorMessage:stopDetails?.explanation||"The model refused to complete the request"};case"pause_turn":return{stopReason:"stop"};case"stop_sequence":return{stopReason:"stop"};case"sensitive":return{stopReason:"error",errorMessage:"Provider stopped with: sensitive"};default:throw new Error(`Unhandled stop reason: ${reason}`)}}export{stream,streamSimple};
|