@draht/coding-agent 2026.7.30 → 2026.9.5-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.
Files changed (459) hide show
  1. package/CHANGELOG.md +154 -0
  2. package/README.md +46 -2
  3. package/agents/debugger.md +12 -1
  4. package/agents/git-committer.md +1 -0
  5. package/agents/implementer.md +20 -0
  6. package/agents/investigator.md +75 -0
  7. package/agents/reviewer.md +7 -0
  8. package/agents/spec-reviewer.md +66 -0
  9. package/agents/verifier.md +4 -3
  10. package/bin/draht-tools.cjs +472 -41
  11. package/dist/agents/debugger.md +12 -1
  12. package/dist/agents/git-committer.md +1 -0
  13. package/dist/agents/implementer.md +20 -0
  14. package/dist/agents/investigator.md +75 -0
  15. package/dist/agents/reviewer.md +7 -0
  16. package/dist/agents/spec-reviewer.md +66 -0
  17. package/dist/agents/verifier.md +4 -3
  18. package/dist/cli/args.d.ts +10 -0
  19. package/dist/cli/args.d.ts.map +1 -1
  20. package/dist/cli/args.js +69 -2
  21. package/dist/cli/args.js.map +1 -1
  22. package/dist/cli/attach-mode.d.ts +61 -0
  23. package/dist/cli/attach-mode.d.ts.map +1 -1
  24. package/dist/cli/attach-mode.js +243 -5
  25. package/dist/cli/attach-mode.js.map +1 -1
  26. package/dist/cli/credential-print.d.ts +1 -1
  27. package/dist/cli/credential-print.d.ts.map +1 -1
  28. package/dist/cli/credential-print.js +5 -4
  29. package/dist/cli/credential-print.js.map +1 -1
  30. package/dist/config.d.ts +9 -0
  31. package/dist/config.d.ts.map +1 -1
  32. package/dist/config.js +31 -4
  33. package/dist/config.js.map +1 -1
  34. package/dist/core/agent-session-runtime.d.ts +17 -1
  35. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  36. package/dist/core/agent-session-runtime.js +87 -30
  37. package/dist/core/agent-session-runtime.js.map +1 -1
  38. package/dist/core/agent-session-services.d.ts +1 -1
  39. package/dist/core/agent-session-services.d.ts.map +1 -1
  40. package/dist/core/agent-session-services.js +1 -0
  41. package/dist/core/agent-session-services.js.map +1 -1
  42. package/dist/core/agent-session.d.ts +35 -16
  43. package/dist/core/agent-session.d.ts.map +1 -1
  44. package/dist/core/agent-session.js +149 -64
  45. package/dist/core/agent-session.js.map +1 -1
  46. package/dist/core/auth-storage.d.ts +5 -1
  47. package/dist/core/auth-storage.d.ts.map +1 -1
  48. package/dist/core/auth-storage.js +72 -15
  49. package/dist/core/auth-storage.js.map +1 -1
  50. package/dist/core/builtins/checkpoints.d.ts +20 -0
  51. package/dist/core/builtins/checkpoints.d.ts.map +1 -0
  52. package/dist/core/builtins/checkpoints.js +161 -0
  53. package/dist/core/builtins/checkpoints.js.map +1 -0
  54. package/dist/core/builtins/duet.d.ts +26 -0
  55. package/dist/core/builtins/duet.d.ts.map +1 -0
  56. package/dist/core/builtins/duet.js +660 -0
  57. package/dist/core/builtins/duet.js.map +1 -0
  58. package/dist/core/builtins/index.d.ts.map +1 -1
  59. package/dist/core/builtins/index.js +7 -1
  60. package/dist/core/builtins/index.js.map +1 -1
  61. package/dist/core/builtins/subagent.d.ts +24 -4
  62. package/dist/core/builtins/subagent.d.ts.map +1 -1
  63. package/dist/core/builtins/subagent.js +278 -35
  64. package/dist/core/builtins/subagent.js.map +1 -1
  65. package/dist/core/checkpoints/checkpoint-cli.d.ts +17 -0
  66. package/dist/core/checkpoints/checkpoint-cli.d.ts.map +1 -0
  67. package/dist/core/checkpoints/checkpoint-cli.js +78 -0
  68. package/dist/core/checkpoints/checkpoint-cli.js.map +1 -0
  69. package/dist/core/checkpoints/checkpoint-manager.d.ts +294 -0
  70. package/dist/core/checkpoints/checkpoint-manager.d.ts.map +1 -0
  71. package/dist/core/checkpoints/checkpoint-manager.js +865 -0
  72. package/dist/core/checkpoints/checkpoint-manager.js.map +1 -0
  73. package/dist/core/checkpoints/rewind.d.ts +141 -0
  74. package/dist/core/checkpoints/rewind.d.ts.map +1 -0
  75. package/dist/core/checkpoints/rewind.js +246 -0
  76. package/dist/core/checkpoints/rewind.js.map +1 -0
  77. package/dist/core/compaction/branch-summarization.d.ts +1 -1
  78. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  79. package/dist/core/compaction/branch-summarization.js +9 -4
  80. package/dist/core/compaction/branch-summarization.js.map +1 -1
  81. package/dist/core/compaction/compaction.d.ts +5 -0
  82. package/dist/core/compaction/compaction.d.ts.map +1 -1
  83. package/dist/core/compaction/compaction.js +25 -4
  84. package/dist/core/compaction/compaction.js.map +1 -1
  85. package/dist/core/extensions/index.d.ts +1 -1
  86. package/dist/core/extensions/index.d.ts.map +1 -1
  87. package/dist/core/extensions/index.js.map +1 -1
  88. package/dist/core/extensions/loader.d.ts.map +1 -1
  89. package/dist/core/extensions/loader.js +83 -20
  90. package/dist/core/extensions/loader.js.map +1 -1
  91. package/dist/core/extensions/runner.d.ts +13 -2
  92. package/dist/core/extensions/runner.d.ts.map +1 -1
  93. package/dist/core/extensions/runner.js +37 -2
  94. package/dist/core/extensions/runner.js.map +1 -1
  95. package/dist/core/extensions/types.d.ts +189 -6
  96. package/dist/core/extensions/types.d.ts.map +1 -1
  97. package/dist/core/extensions/types.js.map +1 -1
  98. package/dist/core/http-dispatcher.d.ts.map +1 -1
  99. package/dist/core/http-dispatcher.js +7 -0
  100. package/dist/core/http-dispatcher.js.map +1 -1
  101. package/dist/core/index.d.ts +1 -1
  102. package/dist/core/index.d.ts.map +1 -1
  103. package/dist/core/index.js.map +1 -1
  104. package/dist/core/keybindings.d.ts +5 -0
  105. package/dist/core/keybindings.d.ts.map +1 -1
  106. package/dist/core/keybindings.js +1 -0
  107. package/dist/core/keybindings.js.map +1 -1
  108. package/dist/core/model-registry.d.ts +3 -2
  109. package/dist/core/model-registry.d.ts.map +1 -1
  110. package/dist/core/model-registry.js +8 -8
  111. package/dist/core/model-registry.js.map +1 -1
  112. package/dist/core/model-resolver.d.ts.map +1 -1
  113. package/dist/core/model-resolver.js +34 -7
  114. package/dist/core/model-resolver.js.map +1 -1
  115. package/dist/core/model-runtime.d.ts +7 -1
  116. package/dist/core/model-runtime.d.ts.map +1 -1
  117. package/dist/core/model-runtime.js +30 -10
  118. package/dist/core/model-runtime.js.map +1 -1
  119. package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
  120. package/dist/core/multi-agent/permission-gate.js +4 -3
  121. package/dist/core/multi-agent/permission-gate.js.map +1 -1
  122. package/dist/core/multi-agent/worktree.d.ts +2 -0
  123. package/dist/core/multi-agent/worktree.d.ts.map +1 -1
  124. package/dist/core/multi-agent/worktree.js +2 -2
  125. package/dist/core/multi-agent/worktree.js.map +1 -1
  126. package/dist/core/package-manager.d.ts +7 -1
  127. package/dist/core/package-manager.d.ts.map +1 -1
  128. package/dist/core/package-manager.js +21 -44
  129. package/dist/core/package-manager.js.map +1 -1
  130. package/dist/core/permission-relay/index.d.ts +19 -0
  131. package/dist/core/permission-relay/index.d.ts.map +1 -0
  132. package/dist/core/permission-relay/index.js +49 -0
  133. package/dist/core/permission-relay/index.js.map +1 -0
  134. package/dist/core/permission-relay/relay-ui-context.d.ts +39 -0
  135. package/dist/core/permission-relay/relay-ui-context.d.ts.map +1 -0
  136. package/dist/core/permission-relay/relay-ui-context.js +788 -0
  137. package/dist/core/permission-relay/relay-ui-context.js.map +1 -0
  138. package/dist/core/permission-relay/types.d.ts +222 -0
  139. package/dist/core/permission-relay/types.d.ts.map +1 -0
  140. package/dist/core/permission-relay/types.js +15 -0
  141. package/dist/core/permission-relay/types.js.map +1 -0
  142. package/dist/core/pi-manifest.d.ts +14 -0
  143. package/dist/core/pi-manifest.d.ts.map +1 -0
  144. package/dist/core/pi-manifest.js +35 -0
  145. package/dist/core/pi-manifest.js.map +1 -0
  146. package/dist/core/project-trust.js +2 -2
  147. package/dist/core/project-trust.js.map +1 -1
  148. package/dist/core/resource-loader.d.ts +21 -0
  149. package/dist/core/resource-loader.d.ts.map +1 -1
  150. package/dist/core/resource-loader.js +101 -24
  151. package/dist/core/resource-loader.js.map +1 -1
  152. package/dist/core/sandbox/bash-operations.d.ts +149 -0
  153. package/dist/core/sandbox/bash-operations.d.ts.map +1 -0
  154. package/dist/core/sandbox/bash-operations.js +163 -0
  155. package/dist/core/sandbox/bash-operations.js.map +1 -0
  156. package/dist/core/sandbox/env.d.ts +83 -0
  157. package/dist/core/sandbox/env.d.ts.map +1 -0
  158. package/dist/core/sandbox/env.js +123 -0
  159. package/dist/core/sandbox/env.js.map +1 -0
  160. package/dist/core/sandbox/executor.d.ts +104 -0
  161. package/dist/core/sandbox/executor.d.ts.map +1 -0
  162. package/dist/core/sandbox/executor.js +92 -0
  163. package/dist/core/sandbox/executor.js.map +1 -0
  164. package/dist/core/sandbox/index.d.ts +36 -0
  165. package/dist/core/sandbox/index.d.ts.map +1 -0
  166. package/dist/core/sandbox/index.js +36 -0
  167. package/dist/core/sandbox/index.js.map +1 -0
  168. package/dist/core/sandbox/linux.d.ts +121 -0
  169. package/dist/core/sandbox/linux.d.ts.map +1 -0
  170. package/dist/core/sandbox/linux.js +260 -0
  171. package/dist/core/sandbox/linux.js.map +1 -0
  172. package/dist/core/sandbox/policy.d.ts +142 -0
  173. package/dist/core/sandbox/policy.d.ts.map +1 -0
  174. package/dist/core/sandbox/policy.js +297 -0
  175. package/dist/core/sandbox/policy.js.map +1 -0
  176. package/dist/core/sandbox/real-path.d.ts +112 -0
  177. package/dist/core/sandbox/real-path.d.ts.map +1 -0
  178. package/dist/core/sandbox/real-path.js +158 -0
  179. package/dist/core/sandbox/real-path.js.map +1 -0
  180. package/dist/core/sandbox/seatbelt-profile.d.ts +95 -0
  181. package/dist/core/sandbox/seatbelt-profile.d.ts.map +1 -0
  182. package/dist/core/sandbox/seatbelt-profile.js +239 -0
  183. package/dist/core/sandbox/seatbelt-profile.js.map +1 -0
  184. package/dist/core/sandbox/seatbelt.d.ts +95 -0
  185. package/dist/core/sandbox/seatbelt.d.ts.map +1 -0
  186. package/dist/core/sandbox/seatbelt.js +154 -0
  187. package/dist/core/sandbox/seatbelt.js.map +1 -0
  188. package/dist/core/sandbox/self-test.d.ts +109 -0
  189. package/dist/core/sandbox/self-test.d.ts.map +1 -0
  190. package/dist/core/sandbox/self-test.js +369 -0
  191. package/dist/core/sandbox/self-test.js.map +1 -0
  192. package/dist/core/sandbox/spawn.d.ts +33 -0
  193. package/dist/core/sandbox/spawn.d.ts.map +1 -0
  194. package/dist/core/sandbox/spawn.js +87 -0
  195. package/dist/core/sandbox/spawn.js.map +1 -0
  196. package/dist/core/sdk.d.ts.map +1 -1
  197. package/dist/core/sdk.js +3 -1
  198. package/dist/core/sdk.js.map +1 -1
  199. package/dist/core/session-manager.d.ts +60 -1
  200. package/dist/core/session-manager.d.ts.map +1 -1
  201. package/dist/core/session-manager.js +53 -6
  202. package/dist/core/session-manager.js.map +1 -1
  203. package/dist/core/settings-manager.d.ts +21 -0
  204. package/dist/core/settings-manager.d.ts.map +1 -1
  205. package/dist/core/settings-manager.js +36 -16
  206. package/dist/core/settings-manager.js.map +1 -1
  207. package/dist/core/skills.d.ts +3 -1
  208. package/dist/core/skills.d.ts.map +1 -1
  209. package/dist/core/skills.js +19 -6
  210. package/dist/core/skills.js.map +1 -1
  211. package/dist/core/slash-commands.d.ts.map +1 -1
  212. package/dist/core/slash-commands.js +1 -0
  213. package/dist/core/slash-commands.js.map +1 -1
  214. package/dist/core/soak/soak-log.d.ts +298 -0
  215. package/dist/core/soak/soak-log.d.ts.map +1 -0
  216. package/dist/core/soak/soak-log.js +660 -0
  217. package/dist/core/soak/soak-log.js.map +1 -0
  218. package/dist/core/soak/soak-reader.d.ts +60 -0
  219. package/dist/core/soak/soak-reader.d.ts.map +1 -0
  220. package/dist/core/soak/soak-reader.js +106 -0
  221. package/dist/core/soak/soak-reader.js.map +1 -0
  222. package/dist/core/socket-server/discovery.d.ts +78 -1
  223. package/dist/core/socket-server/discovery.d.ts.map +1 -1
  224. package/dist/core/socket-server/discovery.js +356 -37
  225. package/dist/core/socket-server/discovery.js.map +1 -1
  226. package/dist/core/socket-server/index.d.ts +10 -4
  227. package/dist/core/socket-server/index.d.ts.map +1 -1
  228. package/dist/core/socket-server/index.js +6 -3
  229. package/dist/core/socket-server/index.js.map +1 -1
  230. package/dist/core/socket-server/permission-delivery.d.ts +125 -0
  231. package/dist/core/socket-server/permission-delivery.d.ts.map +1 -0
  232. package/dist/core/socket-server/permission-delivery.js +152 -0
  233. package/dist/core/socket-server/permission-delivery.js.map +1 -0
  234. package/dist/core/socket-server/permission-registry.d.ts +301 -0
  235. package/dist/core/socket-server/permission-registry.d.ts.map +1 -0
  236. package/dist/core/socket-server/permission-registry.js +410 -0
  237. package/dist/core/socket-server/permission-registry.js.map +1 -0
  238. package/dist/core/socket-server/permission-relay.d.ts +81 -0
  239. package/dist/core/socket-server/permission-relay.d.ts.map +1 -0
  240. package/dist/core/socket-server/permission-relay.js +528 -0
  241. package/dist/core/socket-server/permission-relay.js.map +1 -0
  242. package/dist/core/socket-server/safe-text.d.ts +83 -0
  243. package/dist/core/socket-server/safe-text.d.ts.map +1 -0
  244. package/dist/core/socket-server/safe-text.js +277 -0
  245. package/dist/core/socket-server/safe-text.js.map +1 -0
  246. package/dist/core/socket-server/session-integration.d.ts +65 -2
  247. package/dist/core/socket-server/session-integration.d.ts.map +1 -1
  248. package/dist/core/socket-server/session-integration.js +434 -32
  249. package/dist/core/socket-server/session-integration.js.map +1 -1
  250. package/dist/core/socket-server/socket-client.d.ts +21 -2
  251. package/dist/core/socket-server/socket-client.d.ts.map +1 -1
  252. package/dist/core/socket-server/socket-client.js +52 -1
  253. package/dist/core/socket-server/socket-client.js.map +1 -1
  254. package/dist/core/socket-server/socket-server.d.ts +152 -1
  255. package/dist/core/socket-server/socket-server.d.ts.map +1 -1
  256. package/dist/core/socket-server/socket-server.js +775 -26
  257. package/dist/core/socket-server/socket-server.js.map +1 -1
  258. package/dist/core/socket-server/types.d.ts +106 -2
  259. package/dist/core/socket-server/types.d.ts.map +1 -1
  260. package/dist/core/socket-server/types.js +13 -1
  261. package/dist/core/socket-server/types.js.map +1 -1
  262. package/dist/core/system-prompt.d.ts.map +1 -1
  263. package/dist/core/system-prompt.js +8 -9
  264. package/dist/core/system-prompt.js.map +1 -1
  265. package/dist/core/tools/bash.d.ts +1 -1
  266. package/dist/core/tools/bash.d.ts.map +1 -1
  267. package/dist/core/tools/bash.js +5 -2
  268. package/dist/core/tools/bash.js.map +1 -1
  269. package/dist/core/tools/edit.d.ts.map +1 -1
  270. package/dist/core/tools/edit.js +17 -2
  271. package/dist/core/tools/edit.js.map +1 -1
  272. package/dist/core/tools/find.d.ts +3 -0
  273. package/dist/core/tools/find.d.ts.map +1 -1
  274. package/dist/core/tools/find.js +11 -18
  275. package/dist/core/tools/find.js.map +1 -1
  276. package/dist/core/trust-manager.d.ts +6 -4
  277. package/dist/core/trust-manager.d.ts.map +1 -1
  278. package/dist/core/trust-manager.js +55 -21
  279. package/dist/core/trust-manager.js.map +1 -1
  280. package/dist/extensions/index.d.ts.map +1 -1
  281. package/dist/extensions/index.js +5 -1
  282. package/dist/extensions/index.js.map +1 -1
  283. package/dist/extensions/llama/provider.d.ts.map +1 -1
  284. package/dist/extensions/llama/provider.js +5 -1
  285. package/dist/extensions/llama/provider.js.map +1 -1
  286. package/dist/extensions/stub-provider/index.d.ts +9 -0
  287. package/dist/extensions/stub-provider/index.d.ts.map +1 -0
  288. package/dist/extensions/stub-provider/index.js +13 -0
  289. package/dist/extensions/stub-provider/index.js.map +1 -0
  290. package/dist/extensions/stub-provider/provider.d.ts +77 -0
  291. package/dist/extensions/stub-provider/provider.d.ts.map +1 -0
  292. package/dist/extensions/stub-provider/provider.js +193 -0
  293. package/dist/extensions/stub-provider/provider.js.map +1 -0
  294. package/dist/hooks/gsd/draht-quality-gate.js +3 -3
  295. package/dist/index.d.ts +1 -1
  296. package/dist/index.d.ts.map +1 -1
  297. package/dist/index.js.map +1 -1
  298. package/dist/main.d.ts.map +1 -1
  299. package/dist/main.js +242 -45
  300. package/dist/main.js.map +1 -1
  301. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  302. package/dist/modes/interactive/components/config-selector.js +3 -2
  303. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  304. package/dist/modes/interactive/components/extension-selector.d.ts +49 -0
  305. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  306. package/dist/modes/interactive/components/extension-selector.js +202 -5
  307. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  308. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  309. package/dist/modes/interactive/components/session-selector.js +10 -2
  310. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  311. package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
  312. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  313. package/dist/modes/interactive/components/settings-selector.js +10 -0
  314. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  315. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  316. package/dist/modes/interactive/components/tool-execution.js +10 -1
  317. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  318. package/dist/modes/interactive/components/tree-selector.d.ts +20 -2
  319. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  320. package/dist/modes/interactive/components/tree-selector.js +21 -5
  321. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  322. package/dist/modes/interactive/interactive-mode.d.ts +97 -3
  323. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  324. package/dist/modes/interactive/interactive-mode.js +394 -24
  325. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  326. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  327. package/dist/modes/rpc/rpc-mode.js +165 -7
  328. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  329. package/dist/modes/rpc/rpc-types.d.ts +68 -1
  330. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  331. package/dist/modes/rpc/rpc-types.js.map +1 -1
  332. package/dist/prompts/commands/atomic-commit.md +1 -12
  333. package/dist/prompts/commands/brainstorm.md +12 -15
  334. package/dist/prompts/commands/create-verification-skill.md +108 -0
  335. package/dist/prompts/commands/discuss-phase.md +3 -14
  336. package/dist/prompts/commands/execute-phase.md +3 -11
  337. package/dist/prompts/commands/fix.md +41 -18
  338. package/dist/prompts/commands/grill.md +66 -0
  339. package/dist/prompts/commands/init-project.md +5 -15
  340. package/dist/prompts/commands/map-codebase.md +1 -13
  341. package/dist/prompts/commands/new-project.md +5 -15
  342. package/dist/prompts/commands/next-milestone.md +1 -13
  343. package/dist/prompts/commands/orchestrate.md +1 -1
  344. package/dist/prompts/commands/pause-work.md +1 -13
  345. package/dist/prompts/commands/plan-phase.md +2 -11
  346. package/dist/prompts/commands/progress.md +0 -13
  347. package/dist/prompts/commands/quick.md +3 -11
  348. package/dist/prompts/commands/resolve-conflicts.md +71 -0
  349. package/dist/prompts/commands/resume-work.md +0 -13
  350. package/dist/prompts/commands/review.md +4 -13
  351. package/dist/prompts/commands/triage.md +159 -0
  352. package/dist/prompts/commands/verify-work.md +4 -14
  353. package/dist/prompts/commands/why.md +135 -0
  354. package/dist/skills/atomic-reasoning/SKILL.md +115 -0
  355. package/dist/skills/blast-radius/SKILL.md +55 -0
  356. package/dist/skills/epistemics/SKILL.md +99 -0
  357. package/dist/skills/hexagon-animation/SKILL.md +49 -0
  358. package/dist/skills/hexagon-animation/generate.mjs +81 -0
  359. package/dist/skills/hexagon-animation/template.html +361 -0
  360. package/dist/skills/typescript-discipline/SKILL.md +50 -0
  361. package/dist/skills/typescript-discipline/references/patterns.md +294 -0
  362. package/dist/skills/unslop/SKILL.md +101 -0
  363. package/dist/utils/canonical-path.d.ts +28 -0
  364. package/dist/utils/canonical-path.d.ts.map +1 -0
  365. package/dist/utils/canonical-path.js +90 -0
  366. package/dist/utils/canonical-path.js.map +1 -0
  367. package/dist/utils/child-process.d.ts +12 -1
  368. package/dist/utils/child-process.d.ts.map +1 -1
  369. package/dist/utils/child-process.js +25 -8
  370. package/dist/utils/child-process.js.map +1 -1
  371. package/dist/utils/clipboard.d.ts +1 -1
  372. package/dist/utils/clipboard.d.ts.map +1 -1
  373. package/dist/utils/clipboard.js +22 -2
  374. package/dist/utils/clipboard.js.map +1 -1
  375. package/dist/utils/exif-orientation.d.ts.map +1 -1
  376. package/dist/utils/exif-orientation.js +2 -3
  377. package/dist/utils/exif-orientation.js.map +1 -1
  378. package/dist/utils/paths.d.ts +2 -7
  379. package/dist/utils/paths.d.ts.map +1 -1
  380. package/dist/utils/paths.js +13 -15
  381. package/dist/utils/paths.js.map +1 -1
  382. package/dist/utils/shell.d.ts.map +1 -1
  383. package/dist/utils/shell.js +6 -4
  384. package/dist/utils/shell.js.map +1 -1
  385. package/dist/utils/tools-manager.d.ts.map +1 -1
  386. package/dist/utils/tools-manager.js +3 -5
  387. package/dist/utils/tools-manager.js.map +1 -1
  388. package/docs/attachable-sessions.md +79 -0
  389. package/docs/compaction.md +21 -21
  390. package/docs/containerization.md +23 -23
  391. package/docs/custom-provider.md +16 -16
  392. package/docs/development.md +9 -9
  393. package/docs/docs.json +6 -2
  394. package/docs/duet.md +42 -0
  395. package/docs/extensions.md +58 -58
  396. package/docs/index.md +10 -10
  397. package/docs/json.md +7 -7
  398. package/docs/keybindings.md +6 -5
  399. package/docs/llama-cpp.md +6 -6
  400. package/docs/models.md +6 -6
  401. package/docs/packages.md +43 -43
  402. package/docs/prompt-templates.md +4 -4
  403. package/docs/providers.md +12 -12
  404. package/docs/quickstart.md +32 -32
  405. package/docs/rpc.md +83 -12
  406. package/docs/sdk.md +15 -15
  407. package/docs/security.md +18 -18
  408. package/docs/session-format.md +35 -13
  409. package/docs/sessions.md +17 -14
  410. package/docs/settings.md +25 -18
  411. package/docs/shell-aliases.md +2 -2
  412. package/docs/skills.md +12 -11
  413. package/docs/terminal-setup.md +12 -12
  414. package/docs/termux.md +6 -6
  415. package/docs/themes.md +11 -11
  416. package/docs/tmux.md +4 -4
  417. package/docs/tui.md +5 -5
  418. package/docs/usage.md +50 -50
  419. package/docs/windows.md +2 -2
  420. package/examples/extensions/overlay-qa-tests.ts +3 -3
  421. package/hooks/gsd/draht-quality-gate.js +3 -3
  422. package/package.json +11 -10
  423. package/prompts/commands/atomic-commit.md +1 -12
  424. package/prompts/commands/brainstorm.md +12 -15
  425. package/prompts/commands/create-verification-skill.md +108 -0
  426. package/prompts/commands/discuss-phase.md +3 -14
  427. package/prompts/commands/execute-phase.md +3 -11
  428. package/prompts/commands/fix.md +41 -18
  429. package/prompts/commands/grill.md +66 -0
  430. package/prompts/commands/init-project.md +5 -15
  431. package/prompts/commands/map-codebase.md +1 -13
  432. package/prompts/commands/new-project.md +5 -15
  433. package/prompts/commands/next-milestone.md +1 -13
  434. package/prompts/commands/orchestrate.md +1 -1
  435. package/prompts/commands/pause-work.md +1 -13
  436. package/prompts/commands/plan-phase.md +2 -11
  437. package/prompts/commands/progress.md +0 -13
  438. package/prompts/commands/quick.md +3 -11
  439. package/prompts/commands/resolve-conflicts.md +71 -0
  440. package/prompts/commands/resume-work.md +0 -13
  441. package/prompts/commands/review.md +4 -13
  442. package/prompts/commands/triage.md +159 -0
  443. package/prompts/commands/verify-work.md +4 -14
  444. package/prompts/commands/why.md +135 -0
  445. package/skills/atomic-reasoning/SKILL.md +115 -0
  446. package/skills/blast-radius/SKILL.md +55 -0
  447. package/skills/epistemics/SKILL.md +99 -0
  448. package/skills/hexagon-animation/SKILL.md +49 -0
  449. package/skills/hexagon-animation/generate.mjs +81 -0
  450. package/skills/hexagon-animation/template.html +361 -0
  451. package/skills/typescript-discipline/SKILL.md +50 -0
  452. package/skills/typescript-discipline/references/patterns.md +294 -0
  453. package/skills/unslop/SKILL.md +101 -0
  454. package/dist/prompts/agents/build.md +0 -86
  455. package/dist/prompts/agents/plan.md +0 -79
  456. package/dist/prompts/agents/verify.md +0 -69
  457. package/prompts/agents/build.md +0 -86
  458. package/prompts/agents/plan.md +0 -79
  459. package/prompts/agents/verify.md +0 -69
@@ -16,9 +16,11 @@ import * as os from "node:os";
16
16
  import * as path from "node:path";
17
17
  import { Text } from "@draht/tui";
18
18
  import { Type } from "@sinclair/typebox";
19
- import { getAgentDir, getPackageDir, isBunBinary } from "../../config.js";
19
+ import { CONFIG_DIR_NAME, getAgentDir, getPackageDir, isBunBinary } from "../../config.js";
20
+ import { comparablePath, realPathStrict } from "../../utils/canonical-path.js";
20
21
  import { parseFrontmatter } from "../../utils/frontmatter.js";
21
- import { AgentFSM, isPermissionMode, loadRules, MailboxSystem, PERMISSION_MODES, PermissionGate, TaskBoard, WorktreeIsolator, } from "../multi-agent/index.js";
22
+ import { AgentFSM, isPermissionMode, loadRules, MailboxSystem, PERMISSION_MODES, PermissionGate, parseRules, TaskBoard, WorktreeIsolator, } from "../multi-agent/index.js";
23
+ import { boundedSafeText } from "../socket-server/safe-text.js";
22
24
  const MAX_PARALLEL = 8;
23
25
  const MAX_CONCURRENCY = 4;
24
26
  // ─── Multi-agent coordination primitives ───────────────────────────────────
@@ -87,9 +89,14 @@ function loadAgentsFromDir(dir, source) {
87
89
  return agents;
88
90
  }
89
91
  function findProjectAgentsDir(cwd) {
90
- let dir = cwd;
92
+ // The gate's own chain, from the raw spelling: `resolvePath` first would collapse `..`
93
+ // lexically, and a cwd that will not resolve has unknown ancestors to load from.
94
+ const realCwd = realPathStrict(cwd);
95
+ if (realCwd === undefined)
96
+ return null;
97
+ let dir = realCwd;
91
98
  while (true) {
92
- const candidate = path.join(dir, ".draht", "agents");
99
+ const candidate = path.join(dir, CONFIG_DIR_NAME, "agents");
93
100
  try {
94
101
  if (fs.statSync(candidate).isDirectory())
95
102
  return candidate;
@@ -101,12 +108,12 @@ function findProjectAgentsDir(cwd) {
101
108
  dir = parent;
102
109
  }
103
110
  }
104
- function discoverAgents(cwd, scope) {
111
+ export function discoverAgents(cwd, scope, projectTrusted) {
105
112
  // Shipped agents (bundled with the package) — lowest priority
106
113
  const shippedDir = path.join(getPackageDir(), "agents");
107
114
  const shippedAgents = loadAgentsFromDir(shippedDir, "user");
108
115
  const userDir = path.join(getAgentDir(), "agents");
109
- const projectDir = findProjectAgentsDir(cwd);
116
+ const projectDir = projectTrusted ? findProjectAgentsDir(cwd) : null;
110
117
  const userAgents = scope !== "project" ? loadAgentsFromDir(userDir, "user") : [];
111
118
  const projectAgents = scope !== "user" && projectDir ? loadAgentsFromDir(projectDir, "project") : [];
112
119
  // Priority: shipped < user < project
@@ -135,6 +142,14 @@ function cleanTemp(file, dir) {
135
142
  }
136
143
  catch { }
137
144
  }
145
+ function getFinalAssistant(messages) {
146
+ for (let index = messages.length - 1; index >= 0; index--) {
147
+ const message = messages[index];
148
+ if (message.role === "assistant")
149
+ return message;
150
+ }
151
+ return undefined;
152
+ }
138
153
  function getFinalText(messages) {
139
154
  for (let i = messages.length - 1; i >= 0; i--) {
140
155
  const msg = messages[i];
@@ -147,12 +162,42 @@ function getFinalText(messages) {
147
162
  }
148
163
  return "";
149
164
  }
165
+ function getCombinedUsage(messages) {
166
+ const usages = messages
167
+ .filter((message) => message.role === "assistant")
168
+ .map((message) => message.usage)
169
+ .filter((usage) => usage !== undefined);
170
+ if (usages.length === 0)
171
+ return undefined;
172
+ return usages.reduce((total, usage) => ({
173
+ input: total.input + usage.input,
174
+ output: total.output + usage.output,
175
+ cacheRead: total.cacheRead + usage.cacheRead,
176
+ cacheWrite: total.cacheWrite + usage.cacheWrite,
177
+ ...(total.cacheWrite1h !== undefined || usage.cacheWrite1h !== undefined
178
+ ? { cacheWrite1h: (total.cacheWrite1h ?? 0) + (usage.cacheWrite1h ?? 0) }
179
+ : {}),
180
+ ...(total.reasoning !== undefined || usage.reasoning !== undefined
181
+ ? { reasoning: (total.reasoning ?? 0) + (usage.reasoning ?? 0) }
182
+ : {}),
183
+ totalTokens: total.totalTokens + usage.totalTokens,
184
+ cost: {
185
+ input: total.cost.input + usage.cost.input,
186
+ output: total.cost.output + usage.cost.output,
187
+ cacheRead: total.cost.cacheRead + usage.cost.cacheRead,
188
+ cacheWrite: total.cost.cacheWrite + usage.cost.cacheWrite,
189
+ total: total.cost.total + usage.cost.total,
190
+ },
191
+ }));
192
+ }
150
193
  async function runAgent(cwd, agent, task, signal, step, onProgress) {
151
194
  const args = ["--mode", "json", "-p", "--no-session"];
152
195
  if (agent.model)
153
196
  args.push("--model", agent.model);
154
197
  if (agent.tools?.length)
155
198
  args.push("--tools", agent.tools.join(","));
199
+ if (agent.disableExtensions)
200
+ args.push("--no-extensions");
156
201
  let tmpFile = null;
157
202
  let tmpDir = null;
158
203
  if (agent.systemPrompt.trim()) {
@@ -161,16 +206,18 @@ async function runAgent(cwd, agent, task, signal, step, onProgress) {
161
206
  tmpDir = tmp.dir;
162
207
  args.push("--append-system-prompt", tmpFile);
163
208
  }
164
- args.push(`Task: ${task}`);
165
209
  const messages = [];
166
210
  let stderr = "";
167
211
  try {
168
- const exitCode = await new Promise((resolve) => {
212
+ const processExitCode = await new Promise((resolve) => {
213
+ let closed = false;
169
214
  const proc = spawn(DRAHT_BIN, [...DRAHT_ARGS_PREFIX, ...args], {
170
215
  cwd,
171
216
  shell: false,
172
- stdio: ["ignore", "pipe", "pipe"],
217
+ stdio: ["pipe", "pipe", "pipe"],
173
218
  });
219
+ proc.stdin.on("error", () => { });
220
+ proc.stdin.end(`Task: ${task}`);
174
221
  let buf = "";
175
222
  const processLine = (line) => {
176
223
  if (!line.trim())
@@ -212,18 +259,19 @@ async function runAgent(cwd, agent, task, signal, step, onProgress) {
212
259
  stderr += d.toString();
213
260
  });
214
261
  proc.on("close", (code) => {
262
+ closed = true;
215
263
  if (buf.trim())
216
264
  processLine(buf);
217
- resolve(code ?? 0);
265
+ resolve(code ?? 1);
218
266
  });
219
267
  proc.on("error", () => resolve(1));
220
268
  if (signal) {
221
269
  const kill = () => {
222
270
  proc.kill("SIGTERM");
223
271
  setTimeout(() => {
224
- if (!proc.killed)
272
+ if (!closed)
225
273
  proc.kill("SIGKILL");
226
- }, 5000);
274
+ }, 5000).unref();
227
275
  };
228
276
  if (signal.aborted)
229
277
  kill();
@@ -231,7 +279,17 @@ async function runAgent(cwd, agent, task, signal, step, onProgress) {
231
279
  signal.addEventListener("abort", kill, { once: true });
232
280
  }
233
281
  });
234
- return { agent: agent.name, task, exitCode, output: getFinalText(messages), stderr, step };
282
+ const finalAssistant = getFinalAssistant(messages);
283
+ const failedResponse = finalAssistant?.stopReason === "error" || finalAssistant?.stopReason === "aborted";
284
+ return {
285
+ agent: agent.name,
286
+ task,
287
+ exitCode: processExitCode === 0 && !failedResponse ? 0 : 1,
288
+ output: getFinalText(messages),
289
+ stderr: stderr || (failedResponse ? (finalAssistant.errorMessage ?? finalAssistant.stopReason) : ""),
290
+ usage: getCombinedUsage(messages),
291
+ step,
292
+ };
235
293
  }
236
294
  finally {
237
295
  if (tmpFile && tmpDir)
@@ -270,9 +328,11 @@ async function runAgentWithLifecycle(cwd, agent, task, opts) {
270
328
  fsm.transition("WORKING");
271
329
  const effectiveCwd = worktree ? worktreeIsolator.create(cwd, taskId) : cwd;
272
330
  const result = await runner(effectiveCwd, agent, task, opts.signal, opts.step, opts.onProgress);
273
- if (worktree) {
331
+ // effectiveCwd === cwd means create() fell back to cwd outside a git repo,
332
+ // where merge(taskId) would fabricate a failure for the unknown taskId.
333
+ if (worktree && effectiveCwd !== cwd) {
274
334
  if (result.exitCode === 0)
275
- worktreeIsolator.merge(taskId);
335
+ result.merge = worktreeIsolator.merge(taskId);
276
336
  worktreeIsolator.cleanup(taskId);
277
337
  }
278
338
  fsm.transition("RESPOND");
@@ -301,16 +361,18 @@ export async function runSingleTask(cwd, agent, task, opts = {}) {
301
361
  }
302
362
  /**
303
363
  * Parallel-mode orchestration: every task is posted to the shared TaskBoard
304
- * up front (with `{ agentType: agent.name }` requirements), then each worker
305
- * self-assigns (claims) its task before running — atomically, via the board —
306
- * so the board tracks every assignment made this call.
364
+ * up front (with `{ agentType: agent.name }` requirements), then atomically
365
+ * assigned to its corresponding worker. Direct assignment keeps concurrent
366
+ * orchestration calls from claiming one another's same-role tasks.
307
367
  */
308
368
  export async function runParallelTasks(cwd, items, opts = {}) {
309
369
  const postedIds = items.map((item) => taskBoard.post({ requirements: { agentType: item.agent.name }, description: item.task }));
310
370
  return runParallel(items, MAX_CONCURRENCY, async (item, i) => {
311
371
  const workerId = `parallel-${i}-${randomUUID()}`;
312
- const claimed = taskBoard.claim(workerId, { agentType: item.agent.name });
313
- const taskId = claimed?.id ?? postedIds[i];
372
+ const taskId = postedIds[i];
373
+ const assignment = taskBoard.assign(taskId, workerId);
374
+ if (!assignment.ok)
375
+ throw new Error(assignment.error);
314
376
  const result = await runAgentWithLifecycle(cwd, item.agent, item.task, {
315
377
  signal: opts.signal,
316
378
  onProgress: opts.makeOnProgress?.(item.agent.name),
@@ -369,6 +431,110 @@ export async function runChainTasks(cwd, steps, opts = {}) {
369
431
  }
370
432
  return results;
371
433
  }
434
+ /** Grapheme budget for every attacker-influenced string that travels in a permission ask. */
435
+ const PERMISSION_DETAIL_MAX_GRAPHEMES = 512;
436
+ /**
437
+ * Byte budget for the same strings, stated HERE and not left to the default, because this is the
438
+ * producer whose output has to fit a frame: one grapheme cluster admits unboundedly many combining
439
+ * marks, so 512 clusters of Zalgo weighed 383,246 bytes until this bound existed — accepted by the
440
+ * schema, then refused by the attach bridge, which closed the renderer's socket with 1008.
441
+ *
442
+ * 512 × 4 bytes: four is the widest a single code point is in UTF-8, so every ordinary cluster
443
+ * survives untouched. A `tool_permission` detail carries FIVE such fields — `toolCallId`,
444
+ * `toolName`, `cwd`, `reason`, and exactly one of `command` / `path` / `operation` — so at maximum
445
+ * it is 5 × 2048 = 10,240 bytes of free text plus a fixed option pair and a handful of keys: ~10 KiB
446
+ * against the 64 KiB `maxFrameBytes` a permission frame must fit into, which is never split.
447
+ */
448
+ const PERMISSION_DETAIL_MAX_BYTES = 512 * 4;
449
+ /**
450
+ * The vocabulary this phase offers for a tool permission ask.
451
+ *
452
+ * Frozen and shared: the same object identity is handed to every surface, so no renderer can
453
+ * quietly widen or reorder it. Each option states its OWN decision — nothing may infer approval
454
+ * from an option's position, id, or the array's length.
455
+ */
456
+ const TOOL_PERMISSION_OPTIONS = Object.freeze([
457
+ Object.freeze({ id: "approve", label: "Yes", decision: "approve" }),
458
+ Object.freeze({ id: "deny", label: "No", decision: "deny" }),
459
+ ]);
460
+ /**
461
+ * Neutralize-and-bound a single wire-bound string — in clusters AND bytes — RECORDING the verdict.
462
+ *
463
+ * `verdict` is a required parameter and not an optional convenience: this function used to return
464
+ * `boundedSafeText(...).value` and nothing else, and every caller silently dropped `.truncated`.
465
+ * Making the accumulator part of the signature is what stops a new field being added tomorrow that
466
+ * elides in silence — there is no way to call this and not answer the question.
467
+ */
468
+ function safeField(raw, verdict) {
469
+ const bounded = boundedSafeText(raw, PERMISSION_DETAIL_MAX_GRAPHEMES, PERMISSION_DETAIL_MAX_BYTES);
470
+ if (bounded.truncated)
471
+ verdict.truncated = true;
472
+ // `bounded.originalLength` is deliberately NOT carried: `PermissionRequestFrameSchema` in
473
+ // packages/geist-protocol/src/wire.ts has no field for it, so putting it on the detail would
474
+ // produce a number that reaches no wire. The elision marker inside `value` already names the
475
+ // count, which is how a surface recovers the original length today.
476
+ return bounded.value;
477
+ }
478
+ /**
479
+ * Build the canonical detail for a tool permission ask.
480
+ *
481
+ * Neutralization happens HERE, at construction, not at any protocol layer: three renderers
482
+ * (TUI, `draht --attach`, RPC) inherit this object, and the attach client is a bare `JSON.parse`
483
+ * cast that never passes through a schema. Constructing it safe is what makes all three safe.
484
+ */
485
+ function buildPermissionAskDetail(event, ctx, reason) {
486
+ const input = (event.input ?? {});
487
+ const verdict = { truncated: false };
488
+ const detail = {
489
+ kind: "tool_permission",
490
+ toolCallId: safeField(event.toolCallId, verdict),
491
+ toolName: safeField(event.toolName, verdict),
492
+ // `ctx.cwd` is the raw, un-normalised `config.cwd`; a symlinked worktree would otherwise
493
+ // read as a different project on the answering surface.
494
+ cwd: safeField(comparablePath(ctx.cwd), verdict),
495
+ reason: safeField(reason, verdict),
496
+ options: TOOL_PERMISSION_OPTIONS,
497
+ truncated: false,
498
+ };
499
+ const command = typeof input.command === "string" ? input.command : undefined;
500
+ const filePath = typeof input.file_path === "string" ? input.file_path : undefined;
501
+ const plainPath = typeof input.path === "string" ? input.path : undefined;
502
+ if (command !== undefined) {
503
+ detail.command = safeField(command, verdict);
504
+ }
505
+ else if (filePath !== undefined || plainPath !== undefined) {
506
+ detail.path = safeField((filePath ?? plainPath), verdict);
507
+ }
508
+ else {
509
+ // Every extension tool takes `Record<string, unknown>`, so there is always SOMETHING to
510
+ // show. Serializing the whole argument object beats an empty ask that asks the human to
511
+ // approve an unknown action.
512
+ detail.operation = safeField(serializeToolInput(input), verdict);
513
+ }
514
+ // Set LAST: the command/path/operation branch above is the field most likely to be elided, and
515
+ // it is assigned after the literal. Reading `verdict` any earlier reports on a partial detail.
516
+ detail.truncated = verdict.truncated;
517
+ return detail;
518
+ }
519
+ /** JSON-serialize a tool's argument object, degrading to a readable form rather than throwing. */
520
+ function serializeToolInput(input) {
521
+ try {
522
+ return JSON.stringify(input) ?? String(input);
523
+ }
524
+ catch {
525
+ // Cyclic or otherwise unserializable input must not crash the permission gate.
526
+ return Object.keys(input).join(", ");
527
+ }
528
+ }
529
+ const PERMISSION_RULES_FILE = "permissions.yml";
530
+ export function loadPermissionRules(projectDir, projectTrusted, globalDir) {
531
+ if (projectTrusted) {
532
+ return loadRules(projectDir, globalDir);
533
+ }
534
+ // Not loadRules(projectDir=undefined): that default is process.cwd(), i.e. the untrusted project itself.
535
+ const globalRulesPath = path.join(globalDir ?? getAgentDir(), PERMISSION_RULES_FILE);
536
+ return fs.existsSync(globalRulesPath) ? parseRules(fs.readFileSync(globalRulesPath, "utf-8")) : [];
537
+ }
372
538
  /**
373
539
  * Permission-gate hook point: builds a `tool_call` handler that consults a
374
540
  * `PermissionGate` before a tool executes. `deny` blocks the call outright;
@@ -384,11 +550,36 @@ export function createPermissionGateToolCallHandler(gate) {
384
550
  return { block: true, reason: decision.reason };
385
551
  }
386
552
  if (decision.action === "approve") {
553
+ // No answering surface at all: keep today's loud, operator-facing block verbatim rather
554
+ // than letting a no-op UI resolve `false` and be recorded as a user's denial.
387
555
  if (!ctx.hasUI) {
388
556
  return { block: true, reason: `${decision.reason} (no UI available to request approval)` };
389
557
  }
390
- const approved = await ctx.ui.confirm("Approve tool call?", `${event.toolName}: ${decision.reason}`);
558
+ const detail = buildPermissionAskDetail(event, ctx, decision.reason);
559
+ // Both positional strings are unchanged so every existing renderer keeps working; the
560
+ // canonical facts ride alongside them for surfaces that can render structure.
561
+ //
562
+ // `signal` is the turn's OWN abort signal, read live off the context (it is the active
563
+ // run's controller, minted fresh per run, so it is never a stale aborted one). A
564
+ // permission ask that inherits "wait forever" with no way to be dismissed is its own
565
+ // hazard: this ask parks the agent loop inside `beforeToolCall`, and before this the
566
+ // only things that could end it were a human answering and the relay's own backstop
567
+ // clock. Aborting the turn now takes the dialog down on every surface, and — because
568
+ // nobody answered — it is recorded as `cancelled` by the system rather than as this
569
+ // human's refusal.
570
+ const approved = await ctx.ui.confirm("Approve tool call?", `${event.toolName}: ${decision.reason}`, {
571
+ detail,
572
+ signal: ctx.signal,
573
+ });
391
574
  if (!approved) {
575
+ // The turn being aborted is NOT a refusal, and saying so in the transcript would put the
576
+ // same fabrication in front of the model that the durable record was just cleared of:
577
+ // the JSONL reads `cancelled` by `system`, so the reason the model sees must not read
578
+ // `User denied approval`. This branch became reachable the moment `signal` started being
579
+ // passed above — before that, an abort could not end an ask at all.
580
+ if (ctx.signal?.aborted) {
581
+ return { block: true, reason: "the turn was aborted before this call was approved" };
582
+ }
392
583
  return { block: true, reason: "User denied approval" };
393
584
  }
394
585
  return undefined;
@@ -414,11 +605,32 @@ const Params = Type.Object({
414
605
  worktree: Type.Optional(Type.Boolean({ description: "Opt-in: run each task in an isolated git worktree, merged back on success" })),
415
606
  });
416
607
  // ─── Rendering helpers ──────────────────────────────────────────────────────
608
+ /**
609
+ * Human-readable recovery notice for a failed worktree merge-back, or
610
+ * `undefined` when no merge was attempted or it succeeded. The branch name,
611
+ * the literal `git merge <branch>` command, and the word "resolve-conflicts"
612
+ * are the contract callers (and tests) rely on.
613
+ */
614
+ export function describeMergeFailure(result) {
615
+ if (!result.merge || result.merge.success)
616
+ return undefined;
617
+ const branch = result.merge.branch ?? "agent/<taskId>";
618
+ const conflicts = result.merge.conflicts?.length ? ` Conflicting paths: ${result.merge.conflicts.join(", ")}.` : "";
619
+ return (`Worktree merge-back FAILED: the agent's work is committed on the unmerged branch "${branch}" ` +
620
+ `and is NOT in the working tree.${conflicts} To integrate it, run \`git merge ${branch}\`, ` +
621
+ `then invoke the resolve-conflicts skill (/resolve-conflicts) to resolve the conflicts and finish the merge.`);
622
+ }
417
623
  function truncateTask(task, maxLen = 120) {
418
624
  const oneLine = task.replace(/\n/g, " ").trim();
419
625
  return oneLine.length > maxLen ? `${oneLine.slice(0, maxLen)}...` : oneLine;
420
626
  }
421
627
  export default function (pi) {
628
+ // Autocomplete gets no ctx, so the last trust answer a ctx gave for this cwd stands in; unseen cwds count as untrusted.
629
+ let lastProjectTrust;
630
+ const noteProjectTrust = (ctx) => {
631
+ lastProjectTrust = { cwd: ctx.cwd, trusted: ctx.isProjectTrusted() };
632
+ };
633
+ const rememberedProjectTrust = (cwd) => lastProjectTrust?.cwd === cwd ? lastProjectTrust.trusted : false;
422
634
  pi.registerTool({
423
635
  name: "subagent",
424
636
  label: "Subagent",
@@ -487,7 +699,8 @@ export default function (pi) {
487
699
  },
488
700
  async execute(_id, params, signal, onUpdate, ctx) {
489
701
  const scope = params.agentScope ?? "both";
490
- const agents = discoverAgents(ctx.cwd, scope);
702
+ noteProjectTrust(ctx);
703
+ const agents = discoverAgents(ctx.cwd, scope, ctx.isProjectTrusted());
491
704
  const available = agents.map((a) => a.name).join(", ") || "none";
492
705
  const find = (name) => agents.find((a) => a.name === name);
493
706
  const notFound = (name) => ({
@@ -530,6 +743,10 @@ export default function (pi) {
530
743
  emitProgress(agentName, `step ${i + 1}/${total}`);
531
744
  },
532
745
  });
746
+ const mergeNotices = results
747
+ .map(describeMergeFailure)
748
+ .filter((notice) => notice !== undefined);
749
+ const noticeBlock = mergeNotices.length > 0 ? `\n\n${mergeNotices.join("\n\n")}` : "";
533
750
  const last = results[results.length - 1];
534
751
  if (last.exitCode !== 0) {
535
752
  const failedIndex = results.length - 1;
@@ -537,7 +754,7 @@ export default function (pi) {
537
754
  content: [
538
755
  {
539
756
  type: "text",
540
- text: `Chain failed at step ${failedIndex + 1} (${params.chain[failedIndex].agent}):\n${last.output || last.stderr}`,
757
+ text: `Chain failed at step ${failedIndex + 1} (${params.chain[failedIndex].agent}):\n${last.output || last.stderr}${noticeBlock}`,
541
758
  },
542
759
  ],
543
760
  isError: true,
@@ -545,7 +762,10 @@ export default function (pi) {
545
762
  };
546
763
  }
547
764
  return {
548
- content: [{ type: "text", text: last.output || "(no output)" }],
765
+ content: [{ type: "text", text: `${last.output || "(no output)"}${noticeBlock}` }],
766
+ // A merge-back failure means a step's work did not land in the
767
+ // caller's tree, even though every step's agent succeeded.
768
+ ...(mergeNotices.length > 0 ? { isError: true } : {}),
549
769
  details: {},
550
770
  };
551
771
  }
@@ -572,12 +792,21 @@ export default function (pi) {
572
792
  worktree,
573
793
  makeOnProgress: (agentName) => makeProgressFn(agentName),
574
794
  });
575
- const ok = results.filter((r) => r.exitCode === 0).length;
795
+ const ok = results.filter((r) => r.exitCode === 0 && describeMergeFailure(r) === undefined).length;
576
796
  const summary = results
577
- .map((r) => `[${r.agent}] ${r.exitCode === 0 ? "ok" : "fail"} ${r.output.slice(0, 200)}`)
797
+ .map((r) => `[${r.agent}] ${r.exitCode !== 0 ? "fail" : describeMergeFailure(r) ? "merge-failed" : "ok"} ${r.output.slice(0, 200)}`)
578
798
  .join("\n\n");
799
+ const notices = results
800
+ .map(describeMergeFailure)
801
+ .filter((notice) => notice !== undefined);
802
+ const noticeBlock = notices.length > 0 ? `\n\n${notices.join("\n\n")}` : "";
579
803
  return {
580
- content: [{ type: "text", text: `Parallel: ${ok}/${results.length} succeeded\n\n${summary}` }],
804
+ content: [
805
+ {
806
+ type: "text",
807
+ text: `Parallel: ${ok}/${results.length} succeeded\n\n${summary}${noticeBlock}`,
808
+ },
809
+ ],
581
810
  details: {},
582
811
  };
583
812
  }
@@ -592,9 +821,13 @@ export default function (pi) {
592
821
  worktree,
593
822
  onProgress: makeProgressFn(params.agent),
594
823
  });
595
- const isError = result.exitCode !== 0;
824
+ const mergeNotice = describeMergeFailure(result);
825
+ // A merge-back failure means the delegated change did NOT land in
826
+ // the caller's tree — a plain success would mislead the orchestrator.
827
+ const isError = result.exitCode !== 0 || mergeNotice !== undefined;
828
+ const baseText = result.output || result.stderr || "(no output)";
596
829
  return {
597
- content: [{ type: "text", text: result.output || result.stderr || "(no output)" }],
830
+ content: [{ type: "text", text: mergeNotice ? `${baseText}\n\n${mergeNotice}` : baseText }],
598
831
  ...(isError ? { isError: true } : {}),
599
832
  details: {},
600
833
  };
@@ -609,8 +842,9 @@ export default function (pi) {
609
842
  // ── Permission gate hook point ────────────────────────────────────────────
610
843
  // Prepares the wiring point for the multi-agent permission gate: every tool
611
844
  // call in this process is offered to the gate before it runs. Rules are
612
- // (re)loaded per call so project-local `.draht/permissions.yml` edits and
613
- // per-session cwd changes take effect without an extension reload.
845
+ // (re)loaded per call so project-local `.draht/permissions.yml` edits — read
846
+ // only for a trusted project — and per-session cwd changes take effect
847
+ // without an extension reload.
614
848
  //
615
849
  // The session permission mode (default/auto/yolo) is session-scoped state,
616
850
  // settable via /permissions and /yolo below and seeded from
@@ -626,7 +860,13 @@ export default function (pi) {
626
860
  auto: "auto-approve bash unless the command looks dangerous (deny rules still block)",
627
861
  yolo: "no approval prompts this session (deny rules still block)",
628
862
  };
629
- pi.on("tool_call", (event, ctx) => createPermissionGateToolCallHandler(new PermissionGate(loadRules(ctx.cwd), { cwd: ctx.cwd, mode: permissionMode }))(event, ctx));
863
+ pi.on("tool_call", (event, ctx) => {
864
+ noteProjectTrust(ctx);
865
+ return createPermissionGateToolCallHandler(new PermissionGate(loadPermissionRules(ctx.cwd, ctx.isProjectTrusted()), {
866
+ cwd: ctx.cwd,
867
+ mode: permissionMode,
868
+ }))(event, ctx);
869
+ });
630
870
  // /permissions command — show or set the session permission mode
631
871
  pi.registerCommand("permissions", {
632
872
  description: `Show or set the session permission mode. Usage: /permissions [${PERMISSION_MODES.join("|")}]`,
@@ -665,7 +905,8 @@ export default function (pi) {
665
905
  pi.registerCommand("agent", {
666
906
  description: "Select an agent to handle your next prompts, or clear selection. Usage: /agent [name]",
667
907
  handler: async (args, ctx) => {
668
- const agents = discoverAgents(ctx.cwd, "both");
908
+ noteProjectTrust(ctx);
909
+ const agents = discoverAgents(ctx.cwd, "both", ctx.isProjectTrusted());
669
910
  if (args.trim()) {
670
911
  // Direct selection: /agent architect
671
912
  const name = args.trim();
@@ -708,13 +949,15 @@ export default function (pi) {
708
949
  }
709
950
  },
710
951
  getArgumentCompletions: (partial) => {
711
- const agents = discoverAgents(process.cwd(), "both");
952
+ const cwd = process.cwd();
953
+ const agents = discoverAgents(cwd, "both", rememberedProjectTrust(cwd));
712
954
  const names = ["none", ...agents.map((a) => a.name)];
713
955
  return names.filter((n) => n.startsWith(partial)).map((n) => ({ value: n, label: n }));
714
956
  },
715
957
  });
716
958
  // Intercept user input when an agent is selected
717
- pi.on("input", (event) => {
959
+ pi.on("input", (event, ctx) => {
960
+ noteProjectTrust(ctx);
718
961
  if (!selectedAgent)
719
962
  return { action: "continue" };
720
963
  // Don't intercept slash commands