@draht/coding-agent 2026.10.16 → 2026.10.19-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 +39 -0
- package/README.md +1 -0
- package/dist/bundle/chunks/{anthropic-messages-GAKYXF65.js → anthropic-messages-E2P6C3P7.js} +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-ZIXMK6JO.js → azure-openai-responses-JZMSTDIM.js} +1 -1
- package/dist/bundle/chunks/bedrock-converse-stream.js +20 -20
- package/dist/bundle/chunks/chunk-2JZLKNZ4.js +3 -0
- package/dist/bundle/chunks/{chunk-OWGSPJPZ.js → chunk-3DQNSI5W.js} +5 -5
- package/dist/bundle/chunks/{chunk-JFDPOIUH.js → chunk-4COXSQRQ.js} +1 -1
- package/dist/bundle/chunks/chunk-5QJFWTKA.js +4 -0
- package/dist/bundle/chunks/{chunk-TJ3AW62W.js → chunk-CQF6U56X.js} +1 -1
- package/dist/bundle/chunks/{chunk-RZKPFWMH.js → chunk-D3HO453P.js} +2 -2
- package/dist/bundle/chunks/{chunk-KVH4HR57.js → chunk-FHX2S5IG.js} +1 -1
- package/dist/bundle/chunks/chunk-GBFVS2SF.js +12 -0
- package/dist/bundle/chunks/{chunk-6APPDDHH.js → chunk-I2SOJ4JN.js} +3 -3
- package/dist/bundle/chunks/{chunk-BXSHCX3G.js → chunk-KY2BG6BC.js} +1 -1
- package/dist/bundle/chunks/chunk-LO6CVU2L.js +6 -0
- package/dist/bundle/chunks/{chunk-MIUVNYYW.js → chunk-QPCP4VHF.js} +123 -111
- package/dist/bundle/chunks/{chunk-KU5HAKZL.js → chunk-QVTLBSTH.js} +1 -1
- package/dist/bundle/chunks/{chunk-2VAF4XJI.js → chunk-U6LDZZGM.js} +10 -10
- package/dist/bundle/chunks/{chunk-D6TMD5Q2.js → chunk-UTRX2VHB.js} +8 -8
- package/dist/bundle/chunks/chunk-VXUJMEMO.js +2 -0
- package/dist/bundle/chunks/{chunk-NHTOADU6.js → chunk-X3YFUSCK.js} +1 -1
- package/dist/bundle/chunks/{cli-U7Y4VNNI.js → cli-VCHSHNKT.js} +1 -1
- package/dist/bundle/chunks/{execute-ZWB4PIQQ.js → execute-AGEWJLIO.js} +1 -1
- package/dist/bundle/chunks/{google-generative-ai-RPUPQ6PM.js → google-generative-ai-HPNDIAZD.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-EZES5QVQ.js → google-vertex-KPAWJ4SP.js} +1 -1
- package/dist/bundle/chunks/https-proxy-agent-WQIRL24U.js +13 -0
- package/dist/bundle/chunks/lib-ULKZYRGD.js +9 -0
- package/dist/bundle/chunks/{mistral-conversations-AOYGU43Y.js → mistral-conversations-FMSPWQ7A.js} +1 -1
- package/dist/bundle/chunks/{multipart-parser-AZP5BX2W.js → multipart-parser-HMCXZ4BD.js} +1 -1
- package/dist/bundle/chunks/{node-LQ52KV6B.js → node-4JNG6XQO.js} +1 -1
- package/dist/bundle/chunks/{node-C2JGH2OB.js → node-6IIDYB3K.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-M2Y77JEQ.js → openai-codex-responses-TU7NGPXE.js} +1 -1
- package/dist/bundle/chunks/{openai-completions-A4OKYOYV.js → openai-completions-GANCQQO5.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-6IXV53T3.js → openai-responses-ASDPAX3E.js} +1 -1
- package/dist/bundle/chunks/{openrouter-images-LYV4NKFM.js → openrouter-images-NROSQXMZ.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-KKMEUT3Z.js → pi-messages-2QEJYOAO.js} +1 -1
- package/dist/bundle/chunks/{runtime-PXJK4L7Y.js → runtime-2B56SZM6.js} +1 -1
- package/dist/bundle/chunks/{runtime-363BOYEO.js → runtime-TJ3EAMJK.js} +1 -1
- package/dist/bundle/chunks/{settings-manager-GEOZJXFQ.js → settings-manager-HC5RR36T.js} +1 -1
- package/dist/bundle/chunks/src-KDGO7EGF.js +4 -0
- package/dist/bundle/chunks/{virtual-modules-BEJ4ZJ3D.js → virtual-modules-XT4MP2GI.js} +1 -1
- 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/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +4 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/builtins/duet.d.ts +7 -1
- package/dist/core/builtins/duet.d.ts.map +1 -1
- package/dist/core/builtins/duet.js +83 -14
- package/dist/core/builtins/duet.js.map +1 -1
- package/dist/core/builtins/polyphase.d.ts.map +1 -1
- package/dist/core/builtins/polyphase.js +21 -2
- package/dist/core/builtins/polyphase.js.map +1 -1
- package/dist/core/builtins/subagent.d.ts +59 -2
- package/dist/core/builtins/subagent.d.ts.map +1 -1
- package/dist/core/builtins/subagent.js +258 -62
- package/dist/core/builtins/subagent.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +23 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +2 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +12 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybindings.d.ts +5 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +4 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/multi-agent/permission-gate.d.ts +18 -6
- package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
- package/dist/core/multi-agent/permission-gate.js +867 -59
- package/dist/core/multi-agent/permission-gate.js.map +1 -1
- package/dist/core/polyphase/approval.d.ts +6 -2
- package/dist/core/polyphase/approval.d.ts.map +1 -1
- package/dist/core/polyphase/approval.js +23 -35
- package/dist/core/polyphase/approval.js.map +1 -1
- package/dist/core/polyphase/child-events.js +1 -1
- package/dist/core/polyphase/child-events.js.map +1 -1
- package/dist/core/polyphase/child-process.d.ts.map +1 -1
- package/dist/core/polyphase/child-process.js +65 -7
- package/dist/core/polyphase/child-process.js.map +1 -1
- package/dist/core/polyphase/commands.d.ts.map +1 -1
- package/dist/core/polyphase/commands.js +46 -5
- package/dist/core/polyphase/commands.js.map +1 -1
- package/dist/core/polyphase/details.d.ts.map +1 -1
- package/dist/core/polyphase/details.js +5 -0
- package/dist/core/polyphase/details.js.map +1 -1
- package/dist/core/polyphase/permission-bridge.d.ts +128 -0
- package/dist/core/polyphase/permission-bridge.d.ts.map +1 -0
- package/dist/core/polyphase/permission-bridge.js +357 -0
- package/dist/core/polyphase/permission-bridge.js.map +1 -0
- package/dist/core/polyphase/render/run-block.d.ts.map +1 -1
- package/dist/core/polyphase/render/run-block.js +13 -4
- package/dist/core/polyphase/render/run-block.js.map +1 -1
- package/dist/core/polyphase/render/snapshot.d.ts +4 -0
- package/dist/core/polyphase/render/snapshot.d.ts.map +1 -1
- package/dist/core/polyphase/render/snapshot.js +4 -0
- package/dist/core/polyphase/render/snapshot.js.map +1 -1
- package/dist/core/polyphase/result-text.d.ts.map +1 -1
- package/dist/core/polyphase/result-text.js +23 -3
- package/dist/core/polyphase/result-text.js.map +1 -1
- package/dist/core/polyphase/session.d.ts +15 -1
- package/dist/core/polyphase/session.d.ts.map +1 -1
- package/dist/core/polyphase/session.js +36 -1
- package/dist/core/polyphase/session.js.map +1 -1
- package/dist/core/polyphase/settings.d.ts +1 -0
- package/dist/core/polyphase/settings.d.ts.map +1 -1
- package/dist/core/polyphase/settings.js +1 -1
- package/dist/core/polyphase/settings.js.map +1 -1
- package/dist/core/polyphase/store.d.ts +18 -0
- package/dist/core/polyphase/store.d.ts.map +1 -1
- package/dist/core/polyphase/store.js +38 -0
- package/dist/core/polyphase/store.js.map +1 -1
- package/dist/core/polyphase/types.d.ts +60 -3
- package/dist/core/polyphase/types.d.ts.map +1 -1
- package/dist/core/polyphase/types.js.map +1 -1
- package/dist/core/polyphase/ui/inspector.js +1 -1
- package/dist/core/polyphase/ui/inspector.js.map +1 -1
- package/dist/core/polyphase/workflow/agent-host.d.ts.map +1 -1
- package/dist/core/polyphase/workflow/agent-host.js +17 -3
- package/dist/core/polyphase/workflow/agent-host.js.map +1 -1
- package/dist/core/polyphase/workflow/guidance.d.ts.map +1 -1
- package/dist/core/polyphase/workflow/guidance.js +16 -5
- package/dist/core/polyphase/workflow/guidance.js.map +1 -1
- package/dist/core/polyphase/workflow/launch.d.ts +2 -1
- package/dist/core/polyphase/workflow/launch.d.ts.map +1 -1
- package/dist/core/polyphase/workflow/launch.js +22 -3
- package/dist/core/polyphase/workflow/launch.js.map +1 -1
- package/dist/core/polyphase/workflow/limits.d.ts +80 -0
- package/dist/core/polyphase/workflow/limits.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/limits.js +234 -0
- package/dist/core/polyphase/workflow/limits.js.map +1 -0
- package/dist/core/polyphase/workflow/runtime.d.ts +1 -1
- package/dist/core/polyphase/workflow/runtime.d.ts.map +1 -1
- package/dist/core/polyphase/workflow/runtime.js.map +1 -1
- package/dist/core/polyphase/workflow/tool.d.ts +1 -0
- package/dist/core/polyphase/workflow/tool.d.ts.map +1 -1
- package/dist/core/polyphase/workflow/tool.js +23 -2
- package/dist/core/polyphase/workflow/tool.js.map +1 -1
- package/dist/core/usage-totals.d.ts +5 -0
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +16 -0
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +2 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +3 -0
- package/dist/utils/shell.js.map +1 -1
- package/docs/duet.md +1 -1
- package/docs/environment-variables.md +3 -1
- package/docs/extensions.md +2 -1
- package/docs/keybindings.md +1 -0
- package/docs/polyphase.md +97 -33
- package/docs/settings.md +2 -2
- package/package.json +10 -10
- 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-IWTUBX6V.js +0 -4
- package/dist/bundle/chunks/chunk-TIA2T6EO.js +0 -3
- package/dist/bundle/chunks/https-proxy-agent-O2PVUIOI.js +0 -13
- package/dist/bundle/chunks/lib-XOG5PI3Y.js +0 -9
- package/dist/bundle/chunks/src-TIBHS42X.js +0 -4
- /package/dist/bundle/chunks/{chunk-ZZD35WKM.js → chunk-FBU742QF.js} +0 -0
- /package/dist/bundle/chunks/{chunk-SVNWI7EV.js → chunk-XHCO4PPH.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACpC;AAkDD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,WAAW,CAqDpE;AAED,eAAO,MAAM,eAAe,YAAI,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,CAAU,CAAC;AAEpH,6EAA6E;AAC7E,wBAAgB,mBAAmB,IAAI,WAAW,CAWjD;AAED,wBAAgB,WAAW,IAAI,MAAM,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACpC;AAkDD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,WAAW,CAqDpE;AAED,eAAO,MAAM,eAAe,YAAI,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,CAAU,CAAC;AAEpH,6EAA6E;AAC7E,wBAAgB,mBAAmB,IAAI,WAAW,CAWjD;AAED,wBAAgB,WAAW,IAAI,MAAM,CAAC,UAAU,CAqB/C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGxD;AAQD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEvD;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEzD;AAED,wBAAgB,2BAA2B,IAAI,IAAI,CAKlD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CA+BjD"}
|
package/dist/utils/shell.js
CHANGED
|
@@ -126,8 +126,11 @@ export function getShellEnv() {
|
|
|
126
126
|
// A draht started from a shell command must never inherit the parent's subagent/workflow
|
|
127
127
|
// child markers (src/core/polyphase/types.ts POLYPHASE_DEPTH_ENV/POLYPHASE_SCHEMA_FILE_ENV):
|
|
128
128
|
// otherwise it would run in restricted child mode even though it is the user's own session.
|
|
129
|
+
// Nor the permission-bridge marker (permission-bridge.ts POLYPHASE_PERMISSION_BRIDGE_ENV): under
|
|
130
|
+
// some other IPC parent (a test runner's worker, say) it would send its asks there and wait.
|
|
129
131
|
delete env.DRAHT_POLYPHASE_DEPTH;
|
|
130
132
|
delete env.DRAHT_POLYPHASE_SCHEMA_FILE;
|
|
133
|
+
delete env.DRAHT_POLYPHASE_PERMISSION_BRIDGE;
|
|
131
134
|
return env;
|
|
132
135
|
}
|
|
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CAAC;YACF,kFAAkF;YAClF,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACR,mCAAmC;QACpC,CAAC;IACF,CAAC;SAAM,CAAC;QACP,gCAAgC;QAChC,IAAI,CAAC;YACJ,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACR,iEAAiE;YACjE,IAAI,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC9B,CAAC;YAAC,MAAM,CAAC;gBACR,uBAAuB;YACxB,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { delimiter, join } from \"node:path\";\nimport { spawn, spawnSync } from \"child_process\";\nimport { getBinDir } from \"../config.ts\";\n\nexport interface ShellConfig {\n\tshell: string;\n\targs: string[];\n\tcommandTransport?: \"argv\" | \"stdin\";\n}\n\n/**\n * Find bash executable on PATH (cross-platform)\n */\nfunction isLegacyWslBashPath(path: string): boolean {\n\tconst normalized = path.replace(/\\//g, \"\\\\\").toLowerCase();\n\treturn /^[a-z]:\\\\windows\\\\(?:system32|sysnative)\\\\bash\\.exe$/.test(normalized);\n}\n\nfunction getBashShellConfig(shell: string): ShellConfig {\n\treturn isLegacyWslBashPath(shell) ? { shell, args: [\"-s\"], commandTransport: \"stdin\" } : { shell, args: [\"-c\"] };\n}\n\nfunction findExecutableOnPath(executable: string): string | null {\n\tif (process.platform === \"win32\") {\n\t\t// Windows: Use 'where' and verify file exists (where can return non-existent paths)\n\t\ttry {\n\t\t\tconst result = spawnSync(\"where\", [executable], {\n\t\t\t\tencoding: \"utf-8\",\n\t\t\t\ttimeout: 5000,\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (result.status === 0 && result.stdout) {\n\t\t\t\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\t\t\t\tif (firstMatch && existsSync(firstMatch)) {\n\t\t\t\t\treturn firstMatch;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore errors\n\t\t}\n\t\treturn null;\n\t}\n\n\t// Unix: Use 'which' and trust its output (handles Termux and special filesystems)\n\ttry {\n\t\tconst result = spawnSync(\"which\", [executable], { encoding: \"utf-8\", timeout: 5000 });\n\t\tif (result.status === 0 && result.stdout) {\n\t\t\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\t\t\tif (firstMatch) {\n\t\t\t\treturn firstMatch;\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Ignore errors\n\t}\n\treturn null;\n}\n\n/**\n * Resolve shell configuration based on platform and an optional explicit shell path.\n * Resolution order:\n * 1. User-specified shellPath\n * 2. On Windows: Git Bash in known locations, then bash on PATH\n * 3. On Unix: /bin/bash, then bash on PATH, then fallback to sh\n */\nexport function getShellConfig(customShellPath?: string): ShellConfig {\n\t// 1. Check user-specified shell path\n\tif (customShellPath) {\n\t\tif (existsSync(customShellPath)) {\n\t\t\treturn getBashShellConfig(customShellPath);\n\t\t}\n\t\tthrow new Error(`Custom shell path not found: ${customShellPath}`);\n\t}\n\n\tif (process.platform === \"win32\") {\n\t\t// 2. Try Git Bash in known locations\n\t\tconst paths: string[] = [];\n\t\tconst programFiles = process.env.ProgramFiles;\n\t\tif (programFiles) {\n\t\t\tpaths.push(`${programFiles}\\\\Git\\\\bin\\\\bash.exe`);\n\t\t}\n\t\tconst programFilesX86 = process.env[\"ProgramFiles(x86)\"];\n\t\tif (programFilesX86) {\n\t\t\tpaths.push(`${programFilesX86}\\\\Git\\\\bin\\\\bash.exe`);\n\t\t}\n\n\t\tfor (const path of paths) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\treturn getBashShellConfig(path);\n\t\t\t}\n\t\t}\n\n\t\t// 3. Fallback: search bash.exe on PATH (Cygwin, MSYS2, WSL, etc.)\n\t\tconst bashOnPath = findExecutableOnPath(\"bash.exe\");\n\t\tif (bashOnPath) {\n\t\t\treturn getBashShellConfig(bashOnPath);\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`No bash shell found. Options:\\n` +\n\t\t\t\t` 1. Install Git for Windows: https://git-scm.com/download/win\\n` +\n\t\t\t\t` 2. Add your bash to PATH (Cygwin, MSYS2, etc.)\\n` +\n\t\t\t\t\" 3. Set shellPath in settings.json\\n\\n\" +\n\t\t\t\t`Searched Git Bash in:\\n${paths.map((p) => ` ${p}`).join(\"\\n\")}`,\n\t\t);\n\t}\n\n\t// Unix: try /bin/bash, then bash on PATH, then fallback to sh\n\tif (existsSync(\"/bin/bash\")) {\n\t\treturn getBashShellConfig(\"/bin/bash\");\n\t}\n\n\tconst bashOnPath = findExecutableOnPath(\"bash\");\n\tif (bashOnPath) {\n\t\treturn getBashShellConfig(bashOnPath);\n\t}\n\n\treturn { shell: \"sh\", args: [\"-c\"] };\n}\n\nexport const POWERSHELL_ARGS = [\"-NoProfile\", \"-NonInteractive\", \"-ExecutionPolicy\", \"Bypass\", \"-Command\"] as const;\n\n/** Resolve PowerShell on Windows, preferring PowerShell 7 when available. */\nexport function getPowerShellConfig(): ShellConfig {\n\tif (process.platform !== \"win32\") {\n\t\tthrow new Error(\"The powershell tool is only available on Windows.\");\n\t}\n\n\tconst shell = findExecutableOnPath(\"pwsh.exe\") ?? findExecutableOnPath(\"powershell.exe\");\n\tif (!shell) {\n\t\tthrow new Error(\"No PowerShell executable found. Install PowerShell or add powershell.exe/pwsh.exe to PATH.\");\n\t}\n\n\treturn { shell, args: [...POWERSHELL_ARGS] };\n}\n\nexport function getShellEnv(): NodeJS.ProcessEnv {\n\tconst binDir = getBinDir();\n\tconst pathKey = Object.keys(process.env).find((key) => key.toLowerCase() === \"path\") ?? \"PATH\";\n\tconst currentPath = process.env[pathKey] ?? \"\";\n\tconst pathEntries = currentPath.split(delimiter).filter(Boolean);\n\tconst hasBinDir = pathEntries.includes(binDir);\n\tconst updatedPath = hasBinDir ? currentPath : [binDir, currentPath].filter(Boolean).join(delimiter);\n\n\tconst env = {\n\t\t...process.env,\n\t\t[pathKey]: updatedPath,\n\t};\n\t// A draht started from a shell command must never inherit the parent's subagent/workflow\n\t// child markers (src/core/polyphase/types.ts POLYPHASE_DEPTH_ENV/POLYPHASE_SCHEMA_FILE_ENV):\n\t// otherwise it would run in restricted child mode even though it is the user's own session.\n\tdelete env.DRAHT_POLYPHASE_DEPTH;\n\tdelete env.DRAHT_POLYPHASE_SCHEMA_FILE;\n\treturn env;\n}\n\n/**\n * Sanitize binary output for display/storage.\n * Removes characters that crash string-width or cause display issues:\n * - Control characters (except tab, newline, carriage return)\n * - Unicode interlinear annotation characters U+FFF9..U+FFFB (crash string-width due to a bug)\n */\nexport function sanitizeBinaryOutput(str: string): string {\n\t// All removed characters are single UTF-16 code units, so surrogate pairs are never split.\n\treturn str.replace(/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\uFFF9-\\uFFFB]/g, \"\");\n}\n\n/**\n * Detached child processes must be tracked so they can be killed on parent\n * shutdown signals (SIGHUP/SIGTERM).\n */\nconst trackedDetachedChildPids = new Set<number>();\n\nexport function trackDetachedChildPid(pid: number): void {\n\ttrackedDetachedChildPids.add(pid);\n}\n\nexport function untrackDetachedChildPid(pid: number): void {\n\ttrackedDetachedChildPids.delete(pid);\n}\n\nexport function killTrackedDetachedChildren(): void {\n\tfor (const pid of trackedDetachedChildPids) {\n\t\tkillProcessTree(pid);\n\t}\n\ttrackedDetachedChildPids.clear();\n}\n\n/**\n * Kill a process and all its children (cross-platform)\n */\nexport function killProcessTree(pid: number): void {\n\tif (process.platform === \"win32\") {\n\t\t// Use the trusted System32 executable so cleanup does not depend on PATH.\n\t\ttry {\n\t\t\tconst child = spawn(\n\t\t\t\tjoin(process.env.SystemRoot ?? \"C:\\\\Windows\", \"System32\", \"taskkill.exe\"),\n\t\t\t\t[\"/F\", \"/T\", \"/PID\", String(pid)],\n\t\t\t\t{\n\t\t\t\t\tstdio: \"ignore\",\n\t\t\t\t\tdetached: true,\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t},\n\t\t\t);\n\t\t\t// A failed spawn emits \"error\" asynchronously; consume it to avoid crashing Node.\n\t\t\tchild.once(\"error\", () => {});\n\t\t} catch {\n\t\t\t// Ignore errors if taskkill fails.\n\t\t}\n\t} else {\n\t\t// Use SIGKILL on Unix/Linux/Mac\n\t\ttry {\n\t\t\tprocess.kill(-pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t// Fallback to killing just the child if process group kill fails\n\t\t\ttry {\n\t\t\t\tprocess.kill(pid, \"SIGKILL\");\n\t\t\t} catch {\n\t\t\t\t// Process already dead\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAQzC;;GAEG;AACH,SAAS,mBAAmB,CAAC,IAAY;IACxC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAC3D,OAAO,sDAAsD,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa;IACxC,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,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AG,CAAC,CAAC;IACtB,CAAC;IACD,wBAAwB,CAAC,KAAK,EAAE,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IAC1C,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAClC,0EAA0E;QAC1E,IAAI,CAAC;YACJ,MAAM,KAAK,GAAG,KAAK,CAClB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,aAAa,EAAE,UAAU,EAAE,cAAc,CAAC,EACzE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EACjC;gBACC,KAAK,EAAE,QAAQ;gBACf,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE,IAAI;aACjB,CACD,CAAC;YACF,kFAAkF;YAClF,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACR,mCAAmC;QACpC,CAAC;IACF,CAAC;SAAM,CAAC;QACP,gCAAgC;QAChC,IAAI,CAAC;YACJ,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACR,iEAAiE;YACjE,IAAI,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC9B,CAAC;YAAC,MAAM,CAAC;gBACR,uBAAuB;YACxB,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { delimiter, join } from \"node:path\";\nimport { spawn, spawnSync } from \"child_process\";\nimport { getBinDir } from \"../config.ts\";\n\nexport interface ShellConfig {\n\tshell: string;\n\targs: string[];\n\tcommandTransport?: \"argv\" | \"stdin\";\n}\n\n/**\n * Find bash executable on PATH (cross-platform)\n */\nfunction isLegacyWslBashPath(path: string): boolean {\n\tconst normalized = path.replace(/\\//g, \"\\\\\").toLowerCase();\n\treturn /^[a-z]:\\\\windows\\\\(?:system32|sysnative)\\\\bash\\.exe$/.test(normalized);\n}\n\nfunction getBashShellConfig(shell: string): ShellConfig {\n\treturn isLegacyWslBashPath(shell) ? { shell, args: [\"-s\"], commandTransport: \"stdin\" } : { shell, args: [\"-c\"] };\n}\n\nfunction findExecutableOnPath(executable: string): string | null {\n\tif (process.platform === \"win32\") {\n\t\t// Windows: Use 'where' and verify file exists (where can return non-existent paths)\n\t\ttry {\n\t\t\tconst result = spawnSync(\"where\", [executable], {\n\t\t\t\tencoding: \"utf-8\",\n\t\t\t\ttimeout: 5000,\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (result.status === 0 && result.stdout) {\n\t\t\t\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\t\t\t\tif (firstMatch && existsSync(firstMatch)) {\n\t\t\t\t\treturn firstMatch;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore errors\n\t\t}\n\t\treturn null;\n\t}\n\n\t// Unix: Use 'which' and trust its output (handles Termux and special filesystems)\n\ttry {\n\t\tconst result = spawnSync(\"which\", [executable], { encoding: \"utf-8\", timeout: 5000 });\n\t\tif (result.status === 0 && result.stdout) {\n\t\t\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\t\t\tif (firstMatch) {\n\t\t\t\treturn firstMatch;\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Ignore errors\n\t}\n\treturn null;\n}\n\n/**\n * Resolve shell configuration based on platform and an optional explicit shell path.\n * Resolution order:\n * 1. User-specified shellPath\n * 2. On Windows: Git Bash in known locations, then bash on PATH\n * 3. On Unix: /bin/bash, then bash on PATH, then fallback to sh\n */\nexport function getShellConfig(customShellPath?: string): ShellConfig {\n\t// 1. Check user-specified shell path\n\tif (customShellPath) {\n\t\tif (existsSync(customShellPath)) {\n\t\t\treturn getBashShellConfig(customShellPath);\n\t\t}\n\t\tthrow new Error(`Custom shell path not found: ${customShellPath}`);\n\t}\n\n\tif (process.platform === \"win32\") {\n\t\t// 2. Try Git Bash in known locations\n\t\tconst paths: string[] = [];\n\t\tconst programFiles = process.env.ProgramFiles;\n\t\tif (programFiles) {\n\t\t\tpaths.push(`${programFiles}\\\\Git\\\\bin\\\\bash.exe`);\n\t\t}\n\t\tconst programFilesX86 = process.env[\"ProgramFiles(x86)\"];\n\t\tif (programFilesX86) {\n\t\t\tpaths.push(`${programFilesX86}\\\\Git\\\\bin\\\\bash.exe`);\n\t\t}\n\n\t\tfor (const path of paths) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\treturn getBashShellConfig(path);\n\t\t\t}\n\t\t}\n\n\t\t// 3. Fallback: search bash.exe on PATH (Cygwin, MSYS2, WSL, etc.)\n\t\tconst bashOnPath = findExecutableOnPath(\"bash.exe\");\n\t\tif (bashOnPath) {\n\t\t\treturn getBashShellConfig(bashOnPath);\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`No bash shell found. Options:\\n` +\n\t\t\t\t` 1. Install Git for Windows: https://git-scm.com/download/win\\n` +\n\t\t\t\t` 2. Add your bash to PATH (Cygwin, MSYS2, etc.)\\n` +\n\t\t\t\t\" 3. Set shellPath in settings.json\\n\\n\" +\n\t\t\t\t`Searched Git Bash in:\\n${paths.map((p) => ` ${p}`).join(\"\\n\")}`,\n\t\t);\n\t}\n\n\t// Unix: try /bin/bash, then bash on PATH, then fallback to sh\n\tif (existsSync(\"/bin/bash\")) {\n\t\treturn getBashShellConfig(\"/bin/bash\");\n\t}\n\n\tconst bashOnPath = findExecutableOnPath(\"bash\");\n\tif (bashOnPath) {\n\t\treturn getBashShellConfig(bashOnPath);\n\t}\n\n\treturn { shell: \"sh\", args: [\"-c\"] };\n}\n\nexport const POWERSHELL_ARGS = [\"-NoProfile\", \"-NonInteractive\", \"-ExecutionPolicy\", \"Bypass\", \"-Command\"] as const;\n\n/** Resolve PowerShell on Windows, preferring PowerShell 7 when available. */\nexport function getPowerShellConfig(): ShellConfig {\n\tif (process.platform !== \"win32\") {\n\t\tthrow new Error(\"The powershell tool is only available on Windows.\");\n\t}\n\n\tconst shell = findExecutableOnPath(\"pwsh.exe\") ?? findExecutableOnPath(\"powershell.exe\");\n\tif (!shell) {\n\t\tthrow new Error(\"No PowerShell executable found. Install PowerShell or add powershell.exe/pwsh.exe to PATH.\");\n\t}\n\n\treturn { shell, args: [...POWERSHELL_ARGS] };\n}\n\nexport function getShellEnv(): NodeJS.ProcessEnv {\n\tconst binDir = getBinDir();\n\tconst pathKey = Object.keys(process.env).find((key) => key.toLowerCase() === \"path\") ?? \"PATH\";\n\tconst currentPath = process.env[pathKey] ?? \"\";\n\tconst pathEntries = currentPath.split(delimiter).filter(Boolean);\n\tconst hasBinDir = pathEntries.includes(binDir);\n\tconst updatedPath = hasBinDir ? currentPath : [binDir, currentPath].filter(Boolean).join(delimiter);\n\n\tconst env = {\n\t\t...process.env,\n\t\t[pathKey]: updatedPath,\n\t};\n\t// A draht started from a shell command must never inherit the parent's subagent/workflow\n\t// child markers (src/core/polyphase/types.ts POLYPHASE_DEPTH_ENV/POLYPHASE_SCHEMA_FILE_ENV):\n\t// otherwise it would run in restricted child mode even though it is the user's own session.\n\t// Nor the permission-bridge marker (permission-bridge.ts POLYPHASE_PERMISSION_BRIDGE_ENV): under\n\t// some other IPC parent (a test runner's worker, say) it would send its asks there and wait.\n\tdelete env.DRAHT_POLYPHASE_DEPTH;\n\tdelete env.DRAHT_POLYPHASE_SCHEMA_FILE;\n\tdelete env.DRAHT_POLYPHASE_PERMISSION_BRIDGE;\n\treturn env;\n}\n\n/**\n * Sanitize binary output for display/storage.\n * Removes characters that crash string-width or cause display issues:\n * - Control characters (except tab, newline, carriage return)\n * - Unicode interlinear annotation characters U+FFF9..U+FFFB (crash string-width due to a bug)\n */\nexport function sanitizeBinaryOutput(str: string): string {\n\t// All removed characters are single UTF-16 code units, so surrogate pairs are never split.\n\treturn str.replace(/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\uFFF9-\\uFFFB]/g, \"\");\n}\n\n/**\n * Detached child processes must be tracked so they can be killed on parent\n * shutdown signals (SIGHUP/SIGTERM).\n */\nconst trackedDetachedChildPids = new Set<number>();\n\nexport function trackDetachedChildPid(pid: number): void {\n\ttrackedDetachedChildPids.add(pid);\n}\n\nexport function untrackDetachedChildPid(pid: number): void {\n\ttrackedDetachedChildPids.delete(pid);\n}\n\nexport function killTrackedDetachedChildren(): void {\n\tfor (const pid of trackedDetachedChildPids) {\n\t\tkillProcessTree(pid);\n\t}\n\ttrackedDetachedChildPids.clear();\n}\n\n/**\n * Kill a process and all its children (cross-platform)\n */\nexport function killProcessTree(pid: number): void {\n\tif (process.platform === \"win32\") {\n\t\t// Use the trusted System32 executable so cleanup does not depend on PATH.\n\t\ttry {\n\t\t\tconst child = spawn(\n\t\t\t\tjoin(process.env.SystemRoot ?? \"C:\\\\Windows\", \"System32\", \"taskkill.exe\"),\n\t\t\t\t[\"/F\", \"/T\", \"/PID\", String(pid)],\n\t\t\t\t{\n\t\t\t\t\tstdio: \"ignore\",\n\t\t\t\t\tdetached: true,\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t},\n\t\t\t);\n\t\t\t// A failed spawn emits \"error\" asynchronously; consume it to avoid crashing Node.\n\t\t\tchild.once(\"error\", () => {});\n\t\t} catch {\n\t\t\t// Ignore errors if taskkill fails.\n\t\t}\n\t} else {\n\t\t// Use SIGKILL on Unix/Linux/Mac\n\t\ttry {\n\t\t\tprocess.kill(-pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t// Fallback to killing just the child if process group kill fails\n\t\t\ttry {\n\t\t\t\tprocess.kill(pid, \"SIGKILL\");\n\t\t\t} catch {\n\t\t\t\t// Process already dead\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
package/docs/duet.md
CHANGED
|
@@ -39,4 +39,4 @@ Teammates can read project content and send it to their configured providers. Ch
|
|
|
39
39
|
|
|
40
40
|
## Cost and authentication
|
|
41
41
|
|
|
42
|
-
Every participant must already be authenticated. Parallel triage assignments make concurrent provider requests and are billed independently.
|
|
42
|
+
Every participant must already be authenticated. Parallel triage assignments make concurrent provider requests and are billed independently. In the `ask` permission mode, each delegation batch requires approval through Draht's permission gate; `auto`, the mode a session starts in, and `yolo` start it without asking. Explicit permission rules apply in every mode. Draht limits triage to one delegation batch per user prompt and records nested teammate usage in session totals. The lead is instructed to skip delegation when it would only add latency or cost.
|
|
@@ -74,7 +74,7 @@ When disabled, draht removes inherited values for these variables so nested drah
|
|
|
74
74
|
|
|
75
75
|
## Polyphase Child Coordination
|
|
76
76
|
|
|
77
|
-
These
|
|
77
|
+
These variables are internal: draht sets them on a subagent/workflow child process it spawns
|
|
78
78
|
and reads them back in that child; they are not meant to be set by hand. See
|
|
79
79
|
[Orchestrate Agents with Polyphase](polyphase.md).
|
|
80
80
|
|
|
@@ -82,6 +82,7 @@ and reads them back in that child; they are not meant to be set by hand. See
|
|
|
82
82
|
|----------|-------------|
|
|
83
83
|
| `DRAHT_POLYPHASE_DEPTH` | Nesting depth of this process: unset or `0` for the user's session, `n` in a child spawned by a process at depth `n-1`. Used to enforce `polyphase.maxDepth` and to exclude the `subagent` tool once the limit is reached. |
|
|
84
84
|
| `DRAHT_POLYPHASE_SCHEMA_FILE` | Path to a JSON Schema file for this agent's structured result. When set, the child registers a `polyphase_result` tool matching that schema; unset in every other process, including a child whose parent did not request structured output. |
|
|
85
|
+
| `DRAHT_POLYPHASE_PERMISSION_BRIDGE` | `1` when the parent answers this child's permission asks over the IPC channel it spawned the child with, so a tool call the child's own gate holds for approval is asked in the parent session instead of blocked. Unset in every other process, including a child whose parent does not serve its asks. |
|
|
85
86
|
|
|
86
87
|
## draht Process Configuration
|
|
87
88
|
|
|
@@ -100,6 +101,7 @@ These variables are read by draht itself:
|
|
|
100
101
|
| `DRAHT_SHARE_VIEWER_URL` | Base URL of a share viewer for `/share`; when unset, `/share` prints the gist URL |
|
|
101
102
|
| `DRAHT_RADIUS_GATEWAY` | Not consulted by the builtin Radius model provider (which always uses `https://radius.pi.dev`, or a per-provider `baseUrl` from provider config) or by `/bug`; currently has no effect on behavior |
|
|
102
103
|
| `DRAHT_BUG_REPORT_GATEWAY` | Override the `/bug` upload destination; default is `https://radius.draht.dev` |
|
|
104
|
+
| `DRAHT_PERMISSION_MODE` | Initial permission mode of the session: `ask`, `auto` (when unset or blank), or `yolo`, in any letter case; any other value, the old name `default` included, starts the session in `ask` with a warning. `/permissions`, `/yolo`, and `app.permissions.cycle` (`alt+m`) change it afterwards; a mode chosen that way outlasts `/new`, `/resume`, `/fork`, and `/reload` when it asks more than the starting mode. A session the gateway starts or resumes receives the gateway daemon's value, except `yolo`, which crosses only when the daemon's `DRAHT_RESUME_ENV_ALLOW` lists the variable. Polyphase children receive the session's current mode in this variable; see [Orchestrate Agents with Polyphase](polyphase.md#permissions) |
|
|
103
105
|
| `DRAHT_NO_ATTACHABLE` | Set to `1`/`true`/`yes` to stop sessions from registering an attach socket; overridden by `--attachable` |
|
|
104
106
|
| `DRAHT_HARDWARE_CURSOR` | Set to `1` to show the hardware cursor; see [Terminal setup](terminal-setup.md) |
|
|
105
107
|
| `DRAHT_HYPERLINKS` | Override OSC 8 hyperlink detection with `1`, `0`, or `auto` |
|
package/docs/extensions.md
CHANGED
|
@@ -78,6 +78,7 @@ Automatic retries, recovery, compaction, or queued work can continue afterward.
|
|
|
78
78
|
| Add a shortcut or CLI flag | `pi.registerShortcut()` or `pi.registerFlag()` |
|
|
79
79
|
| Send user or custom messages | `pi.sendUserMessage()` or `pi.sendMessage()` |
|
|
80
80
|
| Persist non-context session data | `pi.appendEntry()` |
|
|
81
|
+
| Record model-attributed usage outside a tool result | `pi.appendUsage()` |
|
|
81
82
|
| Change active tools, model, or thinking level | Session control methods on `pi` |
|
|
82
83
|
| Read or restore working-tree checkpoints | `pi.checkpoints` |
|
|
83
84
|
| Add a model provider | `pi.registerProvider()` |
|
|
@@ -136,7 +137,7 @@ A `user_bash` handler that returns `undefined` passes the command to the next ha
|
|
|
136
137
|
|
|
137
138
|
A custom tool defines a name, model-facing description, TypeBox parameter schema, and `execute()` function.
|
|
138
139
|
Its result requires model-facing `content` and a `details` field for rendering or state reconstruction.
|
|
139
|
-
Use `details: undefined` when there are no structured details. If the tool makes nested model calls, include their `usage` in the result so session totals remain accurate.
|
|
140
|
+
Use `details: undefined` when there are no structured details. If the tool makes nested model calls, include their `usage` in the result so session totals remain accurate. For model-attributed usage that happens outside any tool result — a host-side run reported only through a later custom message, for example — call `pi.appendUsage(kind, provider, model, usage, note?)` instead; it records a usage entry directly in the session's totals and cost breakdown. Record each unit of usage exactly once, and never for usage already reported through a tool result, and treat a throw (a stale ctx after the session ended) as a safe no-op.
|
|
140
141
|
|
|
141
142
|
Throw from `execute()` to produce a failed tool result.
|
|
142
143
|
Returning an object does not mark it as an error.
|
package/docs/keybindings.md
CHANGED
|
@@ -154,6 +154,7 @@ On native Windows, `app.suspend` has no default because Windows terminals do not
|
|
|
154
154
|
| `app.model.cycleBackward` | `shift+ctrl+p` (`alt+p` on Windows and WSL) | Cycle to previous model |
|
|
155
155
|
| `app.models.save` | `ctrl+s` | Save the selected default model or scoped model configuration to settings |
|
|
156
156
|
| `app.thinking.cycle` | `shift+tab` | Cycle thinking level |
|
|
157
|
+
| `app.permissions.cycle` | `alt+m` | Switch the permission mode between `auto` and `ask`; from `yolo`, back to `auto` |
|
|
157
158
|
| `app.context.cycle` | `ctrl+shift+l` | Cycle supported context-window sizes for the current model |
|
|
158
159
|
| `app.thinking.save` | `ctrl+s` | Save current thinking level to settings |
|
|
159
160
|
| `app.thinking.toggle` | `ctrl+t` | Collapse or expand thinking blocks |
|
package/docs/polyphase.md
CHANGED
|
@@ -170,7 +170,9 @@ capped and shaped so it stays informative without flooding context:
|
|
|
170
170
|
- **Workflow:** a header line (status, agent counts, elapsed, tokens, cost), a `Phases:` tally,
|
|
171
171
|
the returned value as pretty JSON (or text) capped at 32,000 characters, the last 30 `log(...)`
|
|
172
172
|
lines, up to 8,000 characters of console output, and up to 100 per-agent summary lines, followed
|
|
173
|
-
by any budget notice, script error (with its source line),
|
|
173
|
+
by any budget/time-limit notice, script error (with its source line), blocked-call note, and a
|
|
174
|
+
final `Limits:` line naming the token budget and time limit that applied (and their source), or
|
|
175
|
+
the disclaimer when one or both are absent.
|
|
174
176
|
|
|
175
177
|
Every mode appends, when applicable, a note about tool calls blocked inside subagents — see
|
|
176
178
|
[Permissions](#permissions) below.
|
|
@@ -224,9 +226,10 @@ The async body after `meta` uses:
|
|
|
224
226
|
|
|
225
227
|
- `agent(prompt, opts)` — starts one subagent and returns its final text, or (with `opts.schema`
|
|
226
228
|
set) the schema-validated object. Returns `null` when the agent failed, was cancelled (by the
|
|
227
|
-
user or the
|
|
228
|
-
output when a schema was requested — always
|
|
229
|
-
unknown `agentType`/model, an invalid `effort`,
|
|
229
|
+
user, the token budget, or the time limit), the budget was already exhausted, the time limit was
|
|
230
|
+
already reached, or produced no valid structured output when a schema was requested — always
|
|
231
|
+
check for `null`. Throws for invalid options, an unknown `agentType`/model, an invalid `effort`,
|
|
232
|
+
or the per-run agent cap.
|
|
230
233
|
`opts`: `{ label, phase, schema, model, effort, isolation: "worktree", agentType }`.
|
|
231
234
|
- `parallel(thunks)` — runs an array of zero-argument thunks (each should call `agent()`) and
|
|
232
235
|
waits for all of them (a barrier). A throwing thunk becomes `null` in the result array, with a
|
|
@@ -260,17 +263,53 @@ inside an `agent()` call is fine — only the script around it is restricted.
|
|
|
260
263
|
- Up to `polyphase.maxConcurrency` (default `clamp(cpuCount - 2, 2, 8)`) child processes running
|
|
261
264
|
at once across the whole session — shared with `subagent` and duet triage, so a workflow and a
|
|
262
265
|
concurrent `subagent` call compete for the same slots.
|
|
263
|
-
- A token budget (`budgetTokens` on the tool call, or `polyphase.defaultBudgetTokens`) is counted
|
|
264
|
-
in billable tokens. Once spent tokens reach the budget, every unfinished agent in the run is
|
|
265
|
-
cancelled and `agent()` starts returning `null`; a warning is logged once. Because output tokens
|
|
266
|
-
for an in-flight response often only arrive at that response's end, the actual spend can
|
|
267
|
-
overshoot the budget by up to one response per agent that was running at the moment the budget
|
|
268
|
-
was reached — this is a bound, not a guarantee of an exact stop.
|
|
269
266
|
- A workflow cannot start another workflow, and a workflow's agents are excluded from the
|
|
270
267
|
`duet_delegate` tool. See [Nesting depth](#nesting-depth).
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
268
|
+
|
|
269
|
+
#### Token budget and time limit
|
|
270
|
+
|
|
271
|
+
A workflow run's token budget and time limit each come from the first of these that applies,
|
|
272
|
+
independently of each other:
|
|
273
|
+
|
|
274
|
+
1. **The user's own prompt** — the prompt that enabled or requested the workflow (the keyword
|
|
275
|
+
turn, or a `/workflow <name> args`/`/<name> args` command's own `args`), parsed deterministically:
|
|
276
|
+
a `+` immediately followed by a number, standing alone as a word (bounded by whitespace or the
|
|
277
|
+
start/end of the text):
|
|
278
|
+
- token budget: `+500k`, `+1.5M`, `+200000` (optional `k`/`M` suffix, case-insensitive; minimum
|
|
279
|
+
1000 tokens — `+1`, `+2`, `+30` do not match).
|
|
280
|
+
- time limit: `+30min`, `+2h`, `+90s`, `+1h30min` (units `s`/`sec`, `min`, `h`/`hr`). A bare `m`
|
|
281
|
+
suffix always means million tokens, never minutes (`+2m` is a 2,000,000-token budget). A zero
|
|
282
|
+
duration is not a limit, and anything longer than about 24.8 days (the longest a single timer
|
|
283
|
+
can wait, less the backstop below) is capped to it.
|
|
284
|
+
For a command run, the matched directive is stripped from the `args` the script receives. A
|
|
285
|
+
steer or follow-up typed while the turn is still running only adds the limits it states itself;
|
|
286
|
+
it never clears the ones the turn started with.
|
|
287
|
+
2. **A tool/command parameter** — `budgetTokens` (a token count) and `timeLimit` (a duration
|
|
288
|
+
string, same grammar without the `+`) on the `workflow` tool call. The model is instructed to
|
|
289
|
+
set these only when the user stated a limit in words ("at most 300k tokens", "stop after 20
|
|
290
|
+
minutes"), never to invent one.
|
|
291
|
+
3. **Config** — `polyphase.defaultBudgetTokens` and `polyphase.workflowTimeoutMs`.
|
|
292
|
+
4. **None** — the run has no budget and no time limit at all; it runs until the script returns.
|
|
293
|
+
Author scripts with no stated limit to stop on their own once the goal is met (e.g. loop until
|
|
294
|
+
a verifier agent reports success), not on an arbitrary iteration count.
|
|
295
|
+
|
|
296
|
+
Whichever limits are missing get a disclaimer, consistently worded in three places: the approval
|
|
297
|
+
prompt's `Limits:` line, one narrator log line at the run's start (visible in the tool row, dock
|
|
298
|
+
and inspector), and the final result text's `Limits:` line. An applied limit's line also names its
|
|
299
|
+
source, e.g. `budget 500k tokens (from your prompt)`.
|
|
300
|
+
|
|
301
|
+
**Token budget.** Counted in billable tokens. Once spent tokens reach the budget, every unfinished
|
|
302
|
+
agent in the run is cancelled (`cancelReason: "budget"`) and `agent()` starts returning `null`; a
|
|
303
|
+
warning is logged once. Because output tokens for an in-flight response often only arrive at that
|
|
304
|
+
response's end, the actual spend can overshoot the budget by up to one response per agent that was
|
|
305
|
+
running at the moment the budget was reached — this is a bound, not a guarantee of an exact stop.
|
|
306
|
+
|
|
307
|
+
**Time limit.** Graceful, and mirrors the budget: once the limit elapses, the run is marked
|
|
308
|
+
reached (`timeLimit.reached` in its details), every running and queued agent is cancelled (`cancelReason: "time"`, shown as
|
|
309
|
+
`cancelled (time limit)`), and `agent()` starts returning `null` with a log line — but the script
|
|
310
|
+
itself keeps running, so it can still return partial results from whatever already finished. A
|
|
311
|
+
hard sandbox deadline 60 seconds past the time limit is the backstop, in case the script never
|
|
312
|
+
returns on its own.
|
|
274
313
|
|
|
275
314
|
### Structured output
|
|
276
315
|
|
|
@@ -319,35 +358,60 @@ process's stdout output: the final text a `draht -p` invocation prints is the mo
|
|
|
319
358
|
response, not a background command-run result that may finish after (or without) a model turn.
|
|
320
359
|
|
|
321
360
|
Command-run token and dollar cost are shown in the dock, the inspector, and the result message,
|
|
322
|
-
|
|
323
|
-
|
|
361
|
+
and are also added to the session footer's running totals and cost breakdown: once the run
|
|
362
|
+
finishes, one usage entry (kind `polyphase`, note `/<name> <label>`) is recorded per agent that
|
|
363
|
+
reported any usage, attributed to that agent's confirmed provider and model — or provider
|
|
364
|
+
`unknown` with the requested model string, for an agent whose model was never confirmed by the
|
|
365
|
+
child. `subagent` and `workflow` tool calls keep reporting usage through their tool result as
|
|
366
|
+
before, so a command run is the only path that goes through this extra entry; nothing is counted
|
|
367
|
+
twice.
|
|
324
368
|
|
|
325
369
|
## Permissions
|
|
326
370
|
|
|
327
371
|
Each `workflow` tool call and each `/<name>`/`/workflow` command run goes through the same
|
|
328
|
-
permission gate as every other tool call: an explicit `allow
|
|
329
|
-
applies as written
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
372
|
+
permission gate as every other tool call: an explicit `allow` or `deny` rule in
|
|
373
|
+
`.draht/permissions.yml` applies as written, and an `approve` rule asks in every mode but `yolo`.
|
|
374
|
+
Without a matching rule the session's permission mode decides. In `auto`, the mode a session
|
|
375
|
+
starts in, and in `yolo` the run starts without asking: every agent it starts runs the gate over
|
|
376
|
+
its own tool calls. In `ask` the call needs approval, shown with the workflow's name, phases
|
|
377
|
+
(with any per-phase model), source, truncated args, and limits (concurrency, max agents, token
|
|
378
|
+
budget and time limit, each with its source — see [Token budget and time
|
|
379
|
+
limit](#token-budget-and-time-limit)). A duet batch (`duet_delegate`) is gated the same way.
|
|
380
|
+
A `workflow` tool call with an invalid `meta` block is gated like any other and fails immediately
|
|
381
|
+
once it starts (in `ask`, the approval prompt describes it as invalid); a `/<name>`/`/workflow`
|
|
382
|
+
command run instead rejects an invalid `meta` block up front, before the gate. With no UI
|
|
383
|
+
available (print or JSON, or any other headless caller), a call that still needs approval is
|
|
384
|
+
blocked rather than left waiting; RPC mode has a UI context, so it forwards the approval to the
|
|
385
|
+
client as a `confirm` request instead.
|
|
336
386
|
|
|
337
387
|
Saved workflows under `.draht/workflows` require project trust, the same as `.draht/agents`: a
|
|
338
388
|
project that only contains a `workflows` directory under `.draht` still triggers the trust prompt,
|
|
339
389
|
because a saved workflow can start subagents just like a saved agent definition can.
|
|
340
390
|
|
|
341
|
-
**
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
391
|
+
**Permission mode inside subagents.** Every child spawned for the session — a `subagent` call, a
|
|
392
|
+
workflow's `agent()` call, or a duet teammate — gets `DRAHT_PERMISSION_MODE` in its environment
|
|
393
|
+
set, at spawn time, to the session's *current* permission mode (whatever `/permissions`,
|
|
394
|
+
`/yolo` or `alt+m` last set; before any of them, the parent process's own `DRAHT_PERMISSION_MODE`, and unset means
|
|
395
|
+
`auto`). A stale `DRAHT_PERMISSION_MODE` left in the parent's process
|
|
396
|
+
environment therefore never escalates a child past what the session currently uses. Deny rules in
|
|
397
|
+
`permissions.yml` still apply in the child regardless of mode, since the child loads and evaluates
|
|
398
|
+
them itself.
|
|
399
|
+
|
|
400
|
+
**Approvals inside subagents.** A subagent process has no UI of its own, so a tool call its gate
|
|
401
|
+
still holds for approval is asked in the parent session instead, over a private IPC channel to the
|
|
402
|
+
parent. The parent first decides it under its *own* current rules and mode — so switching the
|
|
403
|
+
session to `/permissions auto` or `/yolo` also covers asks from children that are already running
|
|
404
|
+
— and shows a dialog only when the call still needs a human. The dialog names the agent
|
|
405
|
+
(`Approve bash for subagent reviewer#1?`) and shows the call like any other permission ask; asks
|
|
406
|
+
from parallel agents are queued and shown one at a time, and the agent waits for the answer. A
|
|
407
|
+
`No` fails just that tool call inside the child, which is told it was denied in the parent session;
|
|
408
|
+
cancelling the agent or the run takes the dialog down. A parent without a UI of its own (print,
|
|
409
|
+
JSON) passes the ask on to its own polyphase parent, if it has one.
|
|
410
|
+
|
|
411
|
+
Only when nobody can be asked is the call blocked: it is surfaced with a warning line, a `⚠` glyph
|
|
412
|
+
in the row, and a note in the parent-model result text listing a few blocked samples. Allow such
|
|
413
|
+
calls with an `allow` rule in `permissions.yml`, or start the run in a less strict mode
|
|
414
|
+
(`/permissions auto` from `ask`, `/yolo`, or `DRAHT_PERMISSION_MODE` for a headless parent).
|
|
351
415
|
|
|
352
416
|
## Nesting depth
|
|
353
417
|
|
package/docs/settings.md
CHANGED
|
@@ -46,13 +46,13 @@ See [Choose a Model](models.md) for model selection and thinking controls.
|
|
|
46
46
|
| `polyphase.maxItemsPerCall` | number | `1024` | Items allowed per `parallel()`/`pipeline()` call. Range 1-4096. |
|
|
47
47
|
| `polyphase.workflowTool` | `"keyword"` \| `"always"` \| `"off"` | `"keyword"` | When the `workflow` tool is available: on the keyword, always, or never. |
|
|
48
48
|
| `polyphase.keyword` | string | `"polyphase"` | Keyword that enables the `workflow` tool for one prompt. Must match `/^[A-Za-z][A-Za-z0-9_-]{2,31}$/`. |
|
|
49
|
-
| `polyphase.defaultBudgetTokens` | number | Unlimited | Token budget for workflow
|
|
49
|
+
| `polyphase.defaultBudgetTokens` | number | Unlimited | Token budget for a workflow run, used only when the user's own prompt (e.g. `+500k`) and the `budgetTokens` tool/command parameter are both absent. Minimum `1000`. |
|
|
50
50
|
| `polyphase.resultChars` | number | `64000` | Characters of agent output returned to the parent model for a parallel `subagent` call, split across agents (2,000-16,000 each). Single, chain, and `workflow` calls use fixed caps instead. Range 8000-400000. |
|
|
51
51
|
| `polyphase.dock` | boolean | `true` | Show the running-agents dock above the editor. |
|
|
52
52
|
| `polyphase.maxDepth` | number | `2` | Delegation depth. A child spawned at this depth gets no `subagent` tool. Range 1-4. |
|
|
53
53
|
| `polyphase.liveUpdateMs` | number | `250` | Live update interval for tool rows, in milliseconds. Range 100-2000. |
|
|
54
54
|
| `polyphase.retainRuns` | number | `20` | Finished runs kept in memory for the agent inspector. Range 1-100. |
|
|
55
|
-
| `polyphase.workflowTimeoutMs` | number | `0` |
|
|
55
|
+
| `polyphase.workflowTimeoutMs` | number | `0` | Graceful time limit for a workflow run, in milliseconds, used only when the user's own prompt (e.g. `+30min`) and the `timeLimit` tool/command parameter are both absent. `0` means no limit. Past the limit, running/queued agents are cancelled and the script finishes with partial results; a hard sandbox deadline 60s later is the backstop. |
|
|
56
56
|
|
|
57
57
|
Available built-in tools are `read`, `bash`, `powershell`, `edit`, `write`, `grep`, `find`, and `ls`. `defaultTools` can also name `codemode` and `tool_search`, which built-in extensions register inactive, and other extension tools registered inactive.
|
|
58
58
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draht/coding-agent",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.19-1",
|
|
4
4
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"drahtConfig": {
|
|
@@ -47,16 +47,16 @@
|
|
|
47
47
|
"prepublishOnly": "node ../../scripts/sync-draht-tools.mjs && bun run clean && bun run build"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@draht/chord": "2026.10.
|
|
50
|
+
"@draht/chord": "2026.10.19-1",
|
|
51
51
|
"@mariozechner/jiti": "^2.6.2",
|
|
52
|
-
"@draht/agent-core": "2026.10.
|
|
53
|
-
"@draht/ai": "2026.10.
|
|
54
|
-
"@draht/codemode": "2026.10.
|
|
55
|
-
"@draht/mcp": "2026.10.
|
|
56
|
-
"@draht/rlm": "2026.10.
|
|
57
|
-
"@draht/router": "2026.10.
|
|
58
|
-
"@draht/tools": "2026.10.
|
|
59
|
-
"@draht/tui": "2026.10.
|
|
52
|
+
"@draht/agent-core": "2026.10.19-1",
|
|
53
|
+
"@draht/ai": "2026.10.19-1",
|
|
54
|
+
"@draht/codemode": "2026.10.19-1",
|
|
55
|
+
"@draht/mcp": "2026.10.19-1",
|
|
56
|
+
"@draht/rlm": "2026.10.19-1",
|
|
57
|
+
"@draht/router": "2026.10.19-1",
|
|
58
|
+
"@draht/tools": "2026.10.19-1",
|
|
59
|
+
"@draht/tui": "2026.10.19-1",
|
|
60
60
|
"@silvia-odwyer/photon-node": "^0.3.4",
|
|
61
61
|
"@sinclair/typebox": "^0.34.41",
|
|
62
62
|
"chalk": "^5.6.2",
|