@draht/coding-agent 2026.7.7 → 2026.7.12-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 (532) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +2 -2
  3. package/agents/advisor.md +44 -0
  4. package/bin/draht-tools.cjs +1808 -988
  5. package/dist/agents/advisor.md +44 -0
  6. package/dist/bun/cli.d.ts.map +1 -1
  7. package/dist/bun/cli.js.map +1 -1
  8. package/dist/bun/register-bedrock.d.ts.map +1 -1
  9. package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
  10. package/dist/bun/restore-sandbox-env.js.map +1 -1
  11. package/dist/cli/args.d.ts.map +1 -1
  12. package/dist/cli/args.js +1 -1
  13. package/dist/cli/args.js.map +1 -1
  14. package/dist/cli/attach-mode.d.ts.map +1 -1
  15. package/dist/cli/attach-mode.js.map +1 -1
  16. package/dist/cli/config-selector.d.ts.map +1 -1
  17. package/dist/cli/config-selector.js.map +1 -1
  18. package/dist/cli/file-processor.d.ts.map +1 -1
  19. package/dist/cli/file-processor.js.map +1 -1
  20. package/dist/cli/initial-message.d.ts +1 -1
  21. package/dist/cli/initial-message.d.ts.map +1 -1
  22. package/dist/cli/initial-message.js.map +1 -1
  23. package/dist/cli/list-models.d.ts.map +1 -1
  24. package/dist/cli/list-models.js.map +1 -1
  25. package/dist/cli/list-sessions.d.ts.map +1 -1
  26. package/dist/cli/list-sessions.js.map +1 -1
  27. package/dist/cli/project-trust.d.ts.map +1 -1
  28. package/dist/cli/project-trust.js.map +1 -1
  29. package/dist/cli/session-picker.d.ts.map +1 -1
  30. package/dist/cli/session-picker.js.map +1 -1
  31. package/dist/cli/startup-ui.d.ts.map +1 -1
  32. package/dist/cli/startup-ui.js.map +1 -1
  33. package/dist/cli.d.ts.map +1 -1
  34. package/dist/cli.js.map +1 -1
  35. package/dist/config.d.ts.map +1 -1
  36. package/dist/config.js.map +1 -1
  37. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  38. package/dist/core/agent-session-runtime.js +0 -8
  39. package/dist/core/agent-session-runtime.js.map +1 -1
  40. package/dist/core/agent-session-services.d.ts.map +1 -1
  41. package/dist/core/agent-session-services.js +2 -0
  42. package/dist/core/agent-session-services.js.map +1 -1
  43. package/dist/core/agent-session.d.ts +44 -3
  44. package/dist/core/agent-session.d.ts.map +1 -1
  45. package/dist/core/agent-session.js +165 -136
  46. package/dist/core/agent-session.js.map +1 -1
  47. package/dist/core/auth-guidance.d.ts.map +1 -1
  48. package/dist/core/auth-guidance.js.map +1 -1
  49. package/dist/core/auth-storage.d.ts +4 -0
  50. package/dist/core/auth-storage.d.ts.map +1 -1
  51. package/dist/core/auth-storage.js +4 -7
  52. package/dist/core/auth-storage.js.map +1 -1
  53. package/dist/core/bash-executor.d.ts.map +1 -1
  54. package/dist/core/bash-executor.js.map +1 -1
  55. package/dist/core/builtins/index.d.ts +11 -0
  56. package/dist/core/builtins/index.d.ts.map +1 -0
  57. package/dist/core/builtins/index.js +11 -0
  58. package/dist/core/builtins/index.js.map +1 -0
  59. package/dist/core/builtins/subagent.d.ts +88 -1
  60. package/dist/core/builtins/subagent.d.ts.map +1 -1
  61. package/dist/core/builtins/subagent.js +263 -27
  62. package/dist/core/builtins/subagent.js.map +1 -1
  63. package/dist/core/cache-stats.d.ts +49 -0
  64. package/dist/core/cache-stats.d.ts.map +1 -0
  65. package/dist/core/cache-stats.js +101 -0
  66. package/dist/core/cache-stats.js.map +1 -0
  67. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  68. package/dist/core/compaction/branch-summarization.js.map +1 -1
  69. package/dist/core/compaction/compaction.d.ts +1 -2
  70. package/dist/core/compaction/compaction.d.ts.map +1 -1
  71. package/dist/core/compaction/compaction.js +51 -73
  72. package/dist/core/compaction/compaction.js.map +1 -1
  73. package/dist/core/compaction/index.d.ts.map +1 -1
  74. package/dist/core/compaction/utils.d.ts.map +1 -1
  75. package/dist/core/compaction/utils.js.map +1 -1
  76. package/dist/core/defaults.d.ts.map +1 -1
  77. package/dist/core/diagnostics.d.ts.map +1 -1
  78. package/dist/core/event-bus.d.ts.map +1 -1
  79. package/dist/core/event-bus.js.map +1 -1
  80. package/dist/core/exec.d.ts.map +1 -1
  81. package/dist/core/exec.js.map +1 -1
  82. package/dist/core/experimental.d.ts.map +1 -1
  83. package/dist/core/experimental.js.map +1 -1
  84. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  85. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  86. package/dist/core/export-html/index.d.ts.map +1 -1
  87. package/dist/core/export-html/index.js.map +1 -1
  88. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  89. package/dist/core/export-html/tool-renderer.js.map +1 -1
  90. package/dist/core/extensions/index.d.ts +1 -1
  91. package/dist/core/extensions/index.d.ts.map +1 -1
  92. package/dist/core/extensions/index.js.map +1 -1
  93. package/dist/core/extensions/loader.d.ts.map +1 -1
  94. package/dist/core/extensions/loader.js +23 -4
  95. package/dist/core/extensions/loader.js.map +1 -1
  96. package/dist/core/extensions/runner.d.ts.map +1 -1
  97. package/dist/core/extensions/runner.js +22 -52
  98. package/dist/core/extensions/runner.js.map +1 -1
  99. package/dist/core/extensions/types.d.ts +9 -9
  100. package/dist/core/extensions/types.d.ts.map +1 -1
  101. package/dist/core/extensions/types.js.map +1 -1
  102. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  103. package/dist/core/extensions/wrapper.js.map +1 -1
  104. package/dist/core/footer-data-provider.d.ts.map +1 -1
  105. package/dist/core/footer-data-provider.js +17 -18
  106. package/dist/core/footer-data-provider.js.map +1 -1
  107. package/dist/core/http-dispatcher.d.ts.map +1 -1
  108. package/dist/core/http-dispatcher.js.map +1 -1
  109. package/dist/core/index.d.ts +1 -1
  110. package/dist/core/index.d.ts.map +1 -1
  111. package/dist/core/index.js.map +1 -1
  112. package/dist/core/keybindings.d.ts.map +1 -1
  113. package/dist/core/keybindings.js +0 -1
  114. package/dist/core/keybindings.js.map +1 -1
  115. package/dist/core/messages.d.ts.map +1 -1
  116. package/dist/core/messages.js.map +1 -1
  117. package/dist/core/model-registry.d.ts +4 -6
  118. package/dist/core/model-registry.d.ts.map +1 -1
  119. package/dist/core/model-registry.js +39 -15
  120. package/dist/core/model-registry.js.map +1 -1
  121. package/dist/core/model-resolver.d.ts.map +1 -1
  122. package/dist/core/model-resolver.js.map +1 -1
  123. package/dist/core/multi-agent/fsm.d.ts +60 -0
  124. package/dist/core/multi-agent/fsm.d.ts.map +1 -0
  125. package/dist/core/multi-agent/fsm.js +90 -0
  126. package/dist/core/multi-agent/fsm.js.map +1 -0
  127. package/dist/core/multi-agent/index.d.ts +21 -0
  128. package/dist/core/multi-agent/index.d.ts.map +1 -0
  129. package/dist/core/multi-agent/index.js +21 -0
  130. package/dist/core/multi-agent/index.js.map +1 -0
  131. package/dist/core/multi-agent/mailbox.d.ts +56 -0
  132. package/dist/core/multi-agent/mailbox.d.ts.map +1 -0
  133. package/dist/core/multi-agent/mailbox.js +112 -0
  134. package/dist/core/multi-agent/mailbox.js.map +1 -0
  135. package/dist/core/multi-agent/permission-gate.d.ts +140 -0
  136. package/dist/core/multi-agent/permission-gate.d.ts.map +1 -0
  137. package/dist/core/multi-agent/permission-gate.js +669 -0
  138. package/dist/core/multi-agent/permission-gate.js.map +1 -0
  139. package/dist/core/multi-agent/task-board.d.ts +100 -0
  140. package/dist/core/multi-agent/task-board.d.ts.map +1 -0
  141. package/dist/core/multi-agent/task-board.js +141 -0
  142. package/dist/core/multi-agent/task-board.js.map +1 -0
  143. package/dist/core/multi-agent/worktree.d.ts +50 -0
  144. package/dist/core/multi-agent/worktree.d.ts.map +1 -0
  145. package/dist/core/multi-agent/worktree.js +148 -0
  146. package/dist/core/multi-agent/worktree.js.map +1 -0
  147. package/dist/core/output-guard.d.ts.map +1 -1
  148. package/dist/core/output-guard.js.map +1 -1
  149. package/dist/core/package-manager.d.ts.map +1 -1
  150. package/dist/core/package-manager.js +0 -6
  151. package/dist/core/package-manager.js.map +1 -1
  152. package/dist/core/project-trust.d.ts.map +1 -1
  153. package/dist/core/project-trust.js.map +1 -1
  154. package/dist/core/prompt-templates.d.ts.map +1 -1
  155. package/dist/core/prompt-templates.js.map +1 -1
  156. package/dist/core/provider-attribution.d.ts.map +1 -1
  157. package/dist/core/provider-attribution.js.map +1 -1
  158. package/dist/core/provider-display-names.d.ts.map +1 -1
  159. package/dist/core/resolve-config-value.d.ts.map +1 -1
  160. package/dist/core/resolve-config-value.js.map +1 -1
  161. package/dist/core/resource-loader.d.ts.map +1 -1
  162. package/dist/core/resource-loader.js +2 -46
  163. package/dist/core/resource-loader.js.map +1 -1
  164. package/dist/core/sdk.d.ts.map +1 -1
  165. package/dist/core/sdk.js +7 -1
  166. package/dist/core/sdk.js.map +1 -1
  167. package/dist/core/session-cwd.d.ts.map +1 -1
  168. package/dist/core/session-cwd.js +0 -1
  169. package/dist/core/session-cwd.js.map +1 -1
  170. package/dist/core/session-manager.d.ts.map +1 -1
  171. package/dist/core/session-manager.js +7 -11
  172. package/dist/core/session-manager.js.map +1 -1
  173. package/dist/core/settings-manager.d.ts +7 -3
  174. package/dist/core/settings-manager.d.ts.map +1 -1
  175. package/dist/core/settings-manager.js +17 -18
  176. package/dist/core/settings-manager.js.map +1 -1
  177. package/dist/core/skills.d.ts.map +1 -1
  178. package/dist/core/skills.js.map +1 -1
  179. package/dist/core/slash-commands.d.ts +1 -0
  180. package/dist/core/slash-commands.d.ts.map +1 -1
  181. package/dist/core/slash-commands.js +3 -3
  182. package/dist/core/slash-commands.js.map +1 -1
  183. package/dist/core/socket-server/discovery.d.ts.map +1 -1
  184. package/dist/core/socket-server/discovery.js.map +1 -1
  185. package/dist/core/socket-server/index.d.ts.map +1 -1
  186. package/dist/core/socket-server/session-integration.d.ts.map +1 -1
  187. package/dist/core/socket-server/session-integration.js.map +1 -1
  188. package/dist/core/socket-server/socket-client.d.ts.map +1 -1
  189. package/dist/core/socket-server/socket-client.js.map +1 -1
  190. package/dist/core/socket-server/socket-server.d.ts.map +1 -1
  191. package/dist/core/socket-server/socket-server.js.map +1 -1
  192. package/dist/core/socket-server/types.d.ts.map +1 -1
  193. package/dist/core/source-info.d.ts.map +1 -1
  194. package/dist/core/source-info.js.map +1 -1
  195. package/dist/core/system-prompt.d.ts.map +1 -1
  196. package/dist/core/system-prompt.js.map +1 -1
  197. package/dist/core/telemetry.d.ts.map +1 -1
  198. package/dist/core/telemetry.js.map +1 -1
  199. package/dist/core/timings.d.ts.map +1 -1
  200. package/dist/core/timings.js.map +1 -1
  201. package/dist/core/tools/bash.d.ts.map +1 -1
  202. package/dist/core/tools/bash.js +8 -5
  203. package/dist/core/tools/bash.js.map +1 -1
  204. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  205. package/dist/core/tools/edit-diff.js.map +1 -1
  206. package/dist/core/tools/edit.d.ts.map +1 -1
  207. package/dist/core/tools/edit.js.map +1 -1
  208. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  209. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  210. package/dist/core/tools/find.d.ts.map +1 -1
  211. package/dist/core/tools/find.js.map +1 -1
  212. package/dist/core/tools/grep.d.ts.map +1 -1
  213. package/dist/core/tools/grep.js.map +1 -1
  214. package/dist/core/tools/index.d.ts.map +1 -1
  215. package/dist/core/tools/index.js.map +1 -1
  216. package/dist/core/tools/ls.d.ts.map +1 -1
  217. package/dist/core/tools/ls.js.map +1 -1
  218. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  219. package/dist/core/tools/output-accumulator.js +12 -18
  220. package/dist/core/tools/output-accumulator.js.map +1 -1
  221. package/dist/core/tools/path-utils.d.ts.map +1 -1
  222. package/dist/core/tools/path-utils.js.map +1 -1
  223. package/dist/core/tools/read.d.ts.map +1 -1
  224. package/dist/core/tools/read.js.map +1 -1
  225. package/dist/core/tools/render-utils.d.ts.map +1 -1
  226. package/dist/core/tools/render-utils.js.map +1 -1
  227. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  228. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  229. package/dist/core/tools/truncate.d.ts.map +1 -1
  230. package/dist/core/tools/truncate.js.map +1 -1
  231. package/dist/core/tools/write.d.ts.map +1 -1
  232. package/dist/core/tools/write.js +0 -1
  233. package/dist/core/tools/write.js.map +1 -1
  234. package/dist/core/trust-manager.d.ts.map +1 -1
  235. package/dist/core/trust-manager.js +0 -1
  236. package/dist/core/trust-manager.js.map +1 -1
  237. package/dist/gsd/domain-validator.d.ts.map +1 -1
  238. package/dist/gsd/domain-validator.js.map +1 -1
  239. package/dist/gsd/domain.d.ts.map +1 -1
  240. package/dist/gsd/domain.js.map +1 -1
  241. package/dist/gsd/git.d.ts.map +1 -1
  242. package/dist/gsd/git.js.map +1 -1
  243. package/dist/gsd/hook-utils.d.ts.map +1 -1
  244. package/dist/gsd/hook-utils.js +3 -1
  245. package/dist/gsd/hook-utils.js.map +1 -1
  246. package/dist/gsd/index.d.ts.map +1 -1
  247. package/dist/gsd/index.js.map +1 -1
  248. package/dist/gsd/planning.d.ts.map +1 -1
  249. package/dist/gsd/planning.js.map +1 -1
  250. package/dist/hooks/gsd/draht-post-task.js +1 -1
  251. package/dist/hooks/gsd/draht-quality-gate.js +1 -1
  252. package/dist/index.d.ts +1 -1
  253. package/dist/index.d.ts.map +1 -1
  254. package/dist/index.js.map +1 -1
  255. package/dist/main.d.ts.map +1 -1
  256. package/dist/main.js +6 -0
  257. package/dist/main.js.map +1 -1
  258. package/dist/migrations.d.ts.map +1 -1
  259. package/dist/migrations.js.map +1 -1
  260. package/dist/modes/index.d.ts.map +1 -1
  261. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  262. package/dist/modes/interactive/components/armin.js +6 -10
  263. package/dist/modes/interactive/components/armin.js.map +1 -1
  264. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  265. package/dist/modes/interactive/components/assistant-message.js +1 -7
  266. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  267. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  268. package/dist/modes/interactive/components/bash-execution.js +4 -9
  269. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  270. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  271. package/dist/modes/interactive/components/bordered-loader.js +0 -3
  272. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  273. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  274. package/dist/modes/interactive/components/branch-summary-message.js +1 -3
  275. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  276. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  277. package/dist/modes/interactive/components/compaction-summary-message.js +1 -3
  278. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  279. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  280. package/dist/modes/interactive/components/config-selector.js +5 -22
  281. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  282. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  283. package/dist/modes/interactive/components/countdown-timer.js +0 -5
  284. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  285. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  286. package/dist/modes/interactive/components/custom-editor.js +1 -8
  287. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  288. package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
  289. package/dist/modes/interactive/components/custom-entry.js +1 -4
  290. package/dist/modes/interactive/components/custom-entry.js.map +1 -1
  291. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  292. package/dist/modes/interactive/components/custom-message.js +1 -6
  293. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  294. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  295. package/dist/modes/interactive/components/daxnuts.js +6 -8
  296. package/dist/modes/interactive/components/daxnuts.js.map +1 -1
  297. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  298. package/dist/modes/interactive/components/diff.js.map +1 -1
  299. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  300. package/dist/modes/interactive/components/dynamic-border.js +0 -1
  301. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  302. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
  303. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
  304. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  305. package/dist/modes/interactive/components/extension-editor.js +1 -7
  306. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  307. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  308. package/dist/modes/interactive/components/extension-input.js +2 -8
  309. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  310. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  311. package/dist/modes/interactive/components/extension-selector.js +1 -9
  312. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  313. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  314. package/dist/modes/interactive/components/first-time-setup.js +2 -4
  315. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  316. package/dist/modes/interactive/components/footer.d.ts +4 -0
  317. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  318. package/dist/modes/interactive/components/footer.js +2 -4
  319. package/dist/modes/interactive/components/footer.js.map +1 -1
  320. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  321. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  322. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  323. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  324. package/dist/modes/interactive/components/login-dialog.js +3 -9
  325. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  326. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  327. package/dist/modes/interactive/components/model-selector.js +8 -20
  328. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  329. package/dist/modes/interactive/components/oauth-selector.d.ts +3 -1
  330. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  331. package/dist/modes/interactive/components/oauth-selector.js +19 -18
  332. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  333. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  334. package/dist/modes/interactive/components/scoped-models-selector.js +9 -13
  335. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  336. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  337. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  338. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  339. package/dist/modes/interactive/components/session-selector.js +33 -57
  340. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  341. package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
  342. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  343. package/dist/modes/interactive/components/settings-selector.js +10 -14
  344. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  345. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  346. package/dist/modes/interactive/components/show-images-selector.js +0 -1
  347. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  348. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  349. package/dist/modes/interactive/components/skill-invocation-message.js +1 -3
  350. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  351. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  352. package/dist/modes/interactive/components/status-indicator.js +0 -2
  353. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  354. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  355. package/dist/modes/interactive/components/theme-selector.js +0 -2
  356. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  357. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  358. package/dist/modes/interactive/components/thinking-selector.js +0 -1
  359. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  360. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  361. package/dist/modes/interactive/components/tool-execution.js +9 -24
  362. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  363. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  364. package/dist/modes/interactive/components/tree-selector.js +18 -32
  365. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  366. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  367. package/dist/modes/interactive/components/trust-selector.js +0 -6
  368. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  369. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  370. package/dist/modes/interactive/components/user-message-selector.js +3 -6
  371. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  372. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  373. package/dist/modes/interactive/components/user-message.js +0 -3
  374. package/dist/modes/interactive/components/user-message.js.map +1 -1
  375. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  376. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  377. package/dist/modes/interactive/interactive-mode.d.ts +21 -0
  378. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  379. package/dist/modes/interactive/interactive-mode.js +312 -143
  380. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  381. package/dist/modes/interactive/model-search.d.ts.map +1 -1
  382. package/dist/modes/interactive/model-search.js.map +1 -1
  383. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  384. package/dist/modes/interactive/theme/theme-controller.js +2 -7
  385. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  386. package/dist/modes/interactive/theme/theme-schema.json +3 -4
  387. package/dist/modes/interactive/theme/theme.d.ts +4 -3
  388. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  389. package/dist/modes/interactive/theme/theme.js +8 -10
  390. package/dist/modes/interactive/theme/theme.js.map +1 -1
  391. package/dist/modes/print-mode.d.ts.map +1 -1
  392. package/dist/modes/print-mode.js +1 -1
  393. package/dist/modes/print-mode.js.map +1 -1
  394. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  395. package/dist/modes/rpc/jsonl.js.map +1 -1
  396. package/dist/modes/rpc/rpc-client.d.ts +6 -6
  397. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  398. package/dist/modes/rpc/rpc-client.js +10 -11
  399. package/dist/modes/rpc/rpc-client.js.map +1 -1
  400. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  401. package/dist/modes/rpc/rpc-mode.js +4 -1
  402. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  403. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  404. package/dist/package-manager-cli.d.ts.map +1 -1
  405. package/dist/package-manager-cli.js.map +1 -1
  406. package/dist/prompts/agents/build.md +38 -0
  407. package/dist/prompts/agents/plan.md +36 -0
  408. package/dist/prompts/agents/verify.md +36 -4
  409. package/dist/prompts/commands/brainstorm.md +16 -2
  410. package/dist/prompts/commands/discuss-phase.md +1 -1
  411. package/dist/prompts/commands/execute-phase.md +16 -3
  412. package/dist/prompts/commands/fix.md +13 -1
  413. package/dist/prompts/commands/init-project.md +1 -0
  414. package/dist/prompts/commands/map-codebase.md +9 -9
  415. package/dist/prompts/commands/new-project.md +1 -0
  416. package/dist/prompts/commands/next-milestone.md +3 -0
  417. package/dist/prompts/commands/orchestrate-loop.md +99 -0
  418. package/dist/prompts/commands/orchestrate.md +29 -6
  419. package/dist/prompts/commands/pause-work.md +2 -1
  420. package/dist/prompts/commands/plan-phase.md +6 -0
  421. package/dist/prompts/commands/quick.md +6 -2
  422. package/dist/prompts/commands/review.md +4 -1
  423. package/dist/prompts/commands/verify-work.md +10 -8
  424. package/dist/rlm-cli.d.ts +92 -0
  425. package/dist/rlm-cli.d.ts.map +1 -0
  426. package/dist/rlm-cli.js +379 -0
  427. package/dist/rlm-cli.js.map +1 -0
  428. package/dist/rpc-entry.d.ts.map +1 -1
  429. package/dist/rpc-entry.js.map +1 -1
  430. package/dist/utils/ansi.d.ts.map +1 -1
  431. package/dist/utils/ansi.js.map +1 -1
  432. package/dist/utils/changelog.d.ts.map +1 -1
  433. package/dist/utils/changelog.js.map +1 -1
  434. package/dist/utils/child-process.d.ts.map +1 -1
  435. package/dist/utils/child-process.js.map +1 -1
  436. package/dist/utils/clipboard-image.d.ts.map +1 -1
  437. package/dist/utils/clipboard-image.js +1 -1
  438. package/dist/utils/clipboard-image.js.map +1 -1
  439. package/dist/utils/clipboard-native.d.ts.map +1 -1
  440. package/dist/utils/clipboard-native.js.map +1 -1
  441. package/dist/utils/clipboard.d.ts.map +1 -1
  442. package/dist/utils/clipboard.js.map +1 -1
  443. package/dist/utils/deprecation.d.ts.map +1 -1
  444. package/dist/utils/deprecation.js.map +1 -1
  445. package/dist/utils/exif-orientation.d.ts.map +1 -1
  446. package/dist/utils/exif-orientation.js.map +1 -1
  447. package/dist/utils/frontmatter.d.ts.map +1 -1
  448. package/dist/utils/frontmatter.js.map +1 -1
  449. package/dist/utils/fs-watch.d.ts.map +1 -1
  450. package/dist/utils/fs-watch.js.map +1 -1
  451. package/dist/utils/git.d.ts.map +1 -1
  452. package/dist/utils/git.js.map +1 -1
  453. package/dist/utils/html.d.ts.map +1 -1
  454. package/dist/utils/html.js.map +1 -1
  455. package/dist/utils/image-convert.d.ts.map +1 -1
  456. package/dist/utils/image-convert.js.map +1 -1
  457. package/dist/utils/image-process.d.ts.map +1 -1
  458. package/dist/utils/image-process.js.map +1 -1
  459. package/dist/utils/image-resize-core.d.ts.map +1 -1
  460. package/dist/utils/image-resize-core.js.map +1 -1
  461. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  462. package/dist/utils/image-resize-worker.js.map +1 -1
  463. package/dist/utils/image-resize.d.ts.map +1 -1
  464. package/dist/utils/image-resize.js.map +1 -1
  465. package/dist/utils/json.d.ts.map +1 -1
  466. package/dist/utils/json.js.map +1 -1
  467. package/dist/utils/mime.d.ts.map +1 -1
  468. package/dist/utils/mime.js.map +1 -1
  469. package/dist/utils/notify.d.ts +3 -1
  470. package/dist/utils/notify.d.ts.map +1 -1
  471. package/dist/utils/notify.js +11 -4
  472. package/dist/utils/notify.js.map +1 -1
  473. package/dist/utils/open-browser.d.ts.map +1 -1
  474. package/dist/utils/open-browser.js.map +1 -1
  475. package/dist/utils/paths.d.ts.map +1 -1
  476. package/dist/utils/paths.js.map +1 -1
  477. package/dist/utils/photon.d.ts.map +1 -1
  478. package/dist/utils/photon.js.map +1 -1
  479. package/dist/utils/pi-user-agent.d.ts.map +1 -1
  480. package/dist/utils/pi-user-agent.js.map +1 -1
  481. package/dist/utils/shell.d.ts.map +1 -1
  482. package/dist/utils/shell.js.map +1 -1
  483. package/dist/utils/sleep.d.ts.map +1 -1
  484. package/dist/utils/sleep.js.map +1 -1
  485. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  486. package/dist/utils/syntax-highlight.js.map +1 -1
  487. package/dist/utils/tools-manager.d.ts.map +1 -1
  488. package/dist/utils/tools-manager.js.map +1 -1
  489. package/dist/utils/version-check.d.ts.map +1 -1
  490. package/dist/utils/version-check.js.map +1 -1
  491. package/dist/utils/windows-self-update.d.ts.map +1 -1
  492. package/dist/utils/windows-self-update.js.map +1 -1
  493. package/docs/custom-provider.md +4 -3
  494. package/docs/extensions.md +15 -10
  495. package/docs/models.md +49 -8
  496. package/docs/rpc.md +15 -5
  497. package/docs/sdk.md +1 -1
  498. package/docs/settings.md +3 -2
  499. package/docs/themes.md +5 -3
  500. package/docs/tui.md +1 -1
  501. package/docs/usage.md +2 -2
  502. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  503. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  504. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  505. package/examples/extensions/preset.ts +2 -2
  506. package/examples/extensions/reload-runtime.ts +2 -2
  507. package/examples/extensions/sandbox/package-lock.json +2 -2
  508. package/examples/extensions/sandbox/package.json +1 -1
  509. package/examples/extensions/with-deps/package-lock.json +2 -2
  510. package/examples/extensions/with-deps/package.json +1 -1
  511. package/examples/sdk/README.md +1 -1
  512. package/hooks/gsd/draht-post-task.js +1 -1
  513. package/hooks/gsd/draht-quality-gate.js +1 -1
  514. package/package.json +10 -8
  515. package/prompts/agents/build.md +38 -0
  516. package/prompts/agents/plan.md +36 -0
  517. package/prompts/agents/verify.md +36 -4
  518. package/prompts/commands/brainstorm.md +16 -2
  519. package/prompts/commands/discuss-phase.md +1 -1
  520. package/prompts/commands/execute-phase.md +16 -3
  521. package/prompts/commands/fix.md +13 -1
  522. package/prompts/commands/init-project.md +1 -0
  523. package/prompts/commands/map-codebase.md +9 -9
  524. package/prompts/commands/new-project.md +1 -0
  525. package/prompts/commands/next-milestone.md +3 -0
  526. package/prompts/commands/orchestrate-loop.md +99 -0
  527. package/prompts/commands/orchestrate.md +29 -6
  528. package/prompts/commands/pause-work.md +2 -1
  529. package/prompts/commands/plan-phase.md +6 -0
  530. package/prompts/commands/quick.md +6 -2
  531. package/prompts/commands/review.md +4 -1
  532. package/prompts/commands/verify-work.md +10 -8
@@ -0,0 +1,669 @@
1
+ /**
2
+ * Permission gate: a three-tier permission system that decides whether a
3
+ * tool call may proceed automatically, must be blocked, or must be confirmed
4
+ * by the user before it runs.
5
+ *
6
+ * SECURITY-CRITICAL: this module gates real bash/write tool calls. Prefer
7
+ * fail-safe (approve/deny) over fail-open (allow) whenever a decision is
8
+ * ambiguous.
9
+ *
10
+ * Configuration is read from `.draht/permissions.yml` (project) and
11
+ * `~/.draht/agent/permissions.yml` (global), e.g.:
12
+ *
13
+ * ```yaml
14
+ * rules:
15
+ * - tool: bash
16
+ * pattern: "rm -rf *"
17
+ * action: deny
18
+ * - tool: bash
19
+ * pattern: "git push *"
20
+ * action: approve
21
+ * - tool: read
22
+ * action: allow
23
+ * - tool: write
24
+ * paths: ["src/**"]
25
+ * action: allow
26
+ * - tool: write
27
+ * action: approve
28
+ * ```
29
+ *
30
+ * Rules are evaluated top-to-bottom; the first matching rule wins.
31
+ *
32
+ * On top of the rules sits a session-level `PermissionMode` (`default` /
33
+ * `auto` / `yolo`, see the type doc) that relaxes how unmatched calls and
34
+ * `approve` outcomes are handled — `deny` rules are never relaxed.
35
+ *
36
+ * `pattern` matching against bash commands is textual (no real shell
37
+ * parser), so `deny` and `allow`/`approve` patterns are matched with
38
+ * deliberately asymmetric strategies to stay fail-safe: `deny` scans every
39
+ * chained/wrapped/unwrapped piece of the command it can find (paranoid,
40
+ * over-matching is safe), while `allow`/`approve` require an exact
41
+ * chain-shape match and reject anything containing `$(...)`, backticks, or
42
+ * redirection (strict, under-matching just falls through to the default
43
+ * decision instead of silently authorizing more than intended). See the
44
+ * doc comment on `matchCommandPattern` below for details and known limits —
45
+ * in particular, `pattern` can never guarantee real path containment; use
46
+ * `paths` for that.
47
+ */
48
+ import { existsSync, readFileSync } from "node:fs";
49
+ import { isAbsolute, join, relative, resolve, sep } from "node:path";
50
+ import { minimatch } from "minimatch";
51
+ import { parse } from "yaml";
52
+ import { CONFIG_DIR_NAME, getAgentDir } from "../../config.js";
53
+ export const PERMISSION_MODES = ["default", "auto", "yolo"];
54
+ export function isPermissionMode(value) {
55
+ return typeof value === "string" && PERMISSION_MODES.includes(value);
56
+ }
57
+ const VALID_ACTIONS = ["deny", "allow", "approve"];
58
+ const RULES_FILE_NAME = "permissions.yml";
59
+ const PATH_SCOPED_TOOLS = new Set(["read", "write", "edit"]);
60
+ /** Read-only tools whose optional `path` arg defaults to the cwd when omitted. */
61
+ const READ_ONLY_PATH_TOOLS = new Set(["grep", "find", "ls"]);
62
+ /**
63
+ * Tools that are safe to run without confirmation because the call itself
64
+ * touches nothing: `subagent` only delegates — the spawned child process runs
65
+ * this same gate over every tool call it actually makes. Explicit rules can
66
+ * still `deny`/`approve` these.
67
+ */
68
+ const DEFAULT_ALLOWED_TOOLS = new Set(["subagent"]);
69
+ function isPermissionAction(value) {
70
+ return typeof value === "string" && VALID_ACTIONS.includes(value);
71
+ }
72
+ function validateRule(raw, index) {
73
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
74
+ throw new Error(`permissions.yml: rule at index ${index} must be an object`);
75
+ }
76
+ const record = raw;
77
+ if (typeof record.tool !== "string" || record.tool.length === 0) {
78
+ throw new Error(`permissions.yml: rule at index ${index} is missing a valid "tool" field`);
79
+ }
80
+ if (!isPermissionAction(record.action)) {
81
+ throw new Error(`permissions.yml: rule at index ${index} has an invalid "action" (must be one of ${VALID_ACTIONS.join(", ")})`);
82
+ }
83
+ const rule = { tool: record.tool, action: record.action };
84
+ if (record.pattern !== undefined) {
85
+ if (typeof record.pattern !== "string") {
86
+ throw new Error(`permissions.yml: rule at index ${index} has a non-string "pattern"`);
87
+ }
88
+ rule.pattern = record.pattern;
89
+ }
90
+ if (record.paths !== undefined) {
91
+ if (!Array.isArray(record.paths) || !record.paths.every((entry) => typeof entry === "string")) {
92
+ throw new Error(`permissions.yml: rule at index ${index} has an invalid "paths" (must be a string array)`);
93
+ }
94
+ rule.paths = record.paths;
95
+ }
96
+ return rule;
97
+ }
98
+ /**
99
+ * Parse a `permissions.yml` document (as a string) into an ordered list of
100
+ * rules. Returns an empty array for empty documents or documents without a
101
+ * `rules` key. Throws on malformed rule entries so misconfiguration fails
102
+ * loudly rather than silently degrading the gate.
103
+ */
104
+ export function parseRules(yamlText) {
105
+ const parsed = parse(yamlText);
106
+ if (parsed === null || parsed === undefined)
107
+ return [];
108
+ if (parsed.rules === undefined)
109
+ return [];
110
+ if (!Array.isArray(parsed.rules)) {
111
+ throw new Error('permissions.yml: "rules" must be an array');
112
+ }
113
+ return parsed.rules.map((raw, index) => validateRule(raw, index));
114
+ }
115
+ function readRulesFile(filePath) {
116
+ if (!existsSync(filePath))
117
+ return [];
118
+ return parseRules(readFileSync(filePath, "utf-8"));
119
+ }
120
+ /**
121
+ * Load and merge permission rules from the global (`~/.draht/agent/permissions.yml`)
122
+ * and project (`<projectDir>/.draht/permissions.yml`) config files.
123
+ *
124
+ * Loading order: global is read first, project is read after (so a project
125
+ * can be authored as a delta on top of the global defaults). Merge order is
126
+ * reversed relative to load order: project rules are placed *before* global
127
+ * rules in the returned array, so that under first-match-wins evaluation the
128
+ * project's rules take precedence over — i.e. "override" — the global ones.
129
+ */
130
+ export function loadRules(projectDir, globalDir) {
131
+ const globalRulesPath = join(globalDir ?? getAgentDir(), RULES_FILE_NAME);
132
+ const projectRulesPath = join(projectDir ?? process.cwd(), CONFIG_DIR_NAME, RULES_FILE_NAME);
133
+ const globalRules = readRulesFile(globalRulesPath);
134
+ const projectRules = readRulesFile(projectRulesPath);
135
+ return [...projectRules, ...globalRules];
136
+ }
137
+ /**
138
+ * Bash `pattern` matching against the raw command string can never be more
139
+ * than textual — it has no real shell parser behind it. A previous
140
+ * implementation matched the whole command string against the pattern with
141
+ * minimatch after stripping every "/" (to stop "*" from being blocked by
142
+ * minimatch's path-segment semantics). That was trivially bypassed: any
143
+ * prefix at all (a leading space, `sudo`, `/bin/`, `env`, chaining with `;`
144
+ * or `&&`, wrapping in `bash -c "..."`, double spaces, reordered combined
145
+ * flags like `-fr` vs `-rf`, or different case) defeated the anchored match,
146
+ * and — separately — a trailing-wildcard *allow* rule like
147
+ * `{ pattern: "npm test*", action: "allow" }` matched anything appended
148
+ * after it via `;`, `&&`, `|`, backticks, or `$(...)`, silently
149
+ * auto-approving injected commands.
150
+ *
151
+ * To stay fail-safe rather than fail-open, `deny` and `allow`/`approve` are
152
+ * matched with deliberately different, asymmetric strategies:
153
+ *
154
+ * - `deny` is matched *paranoidly*. The command is decomposed into every
155
+ * independently-executed piece we can find — split on chaining operators
156
+ * (`;`, `&&`, `||`, `|`, `&`, newlines); unwrapped from passthrough
157
+ * prefixes (`sudo`, `env`, `nice`, ...) and leading `VAR=val`
158
+ * assignments; unwrapped from `bash -c "..."` / `sh -c '...'` / `eval
159
+ * "..."`; unwrapped from `$(...)`/backtick substitutions; resolved from
160
+ * an absolute/relative path to a bare command name — recursively, up to
161
+ * a bounded depth/count. The pattern matches if *any* resulting
162
+ * candidate matches, after collapsing whitespace and canonicalizing
163
+ * combined short flags (so `-rf`/`-fr` compare equal), case-insensitively.
164
+ * Over-matching here is the safe failure mode.
165
+ * - `allow`/`approve` are matched *strictly*: the command is rejected
166
+ * outright if it contains any dynamic/opaque construct (`$(...)`,
167
+ * backticks, redirection `<`/`>`), and otherwise must have the exact same
168
+ * chain shape (same number of segments joined by the same operators) as
169
+ * the pattern, with each segment matched independently. A rule authored
170
+ * for `npm test*` therefore can never also authorize
171
+ * `npm test; rm -rf /` — the extra chained segment has no counterpart in
172
+ * the pattern, so the rule simply doesn't match (falling through to the
173
+ * default decision) instead of silently allowing it.
174
+ *
175
+ * KNOWN LIMITATION (not fixable with text matching alone): interpreter
176
+ * escape hatches. Once a command hands control to a language runtime, the
177
+ * payload is no longer shell and no shell-shaped pattern — `deny` rules
178
+ * included — can see into it: `python -c "os.system('rm -rf /')"` never
179
+ * surfaces `rm -rf /` as a match candidate, `python script.py` hides the
180
+ * danger in file contents the gate never reads, and
181
+ * `python -c "shutil.rmtree('/')"` involves no shell command at all. The
182
+ * built-in danger filter flags *inline eval* invocations (`python -c`,
183
+ * `node -e`, ...) so auto mode prompts on them, but script files and
184
+ * in-language equivalents are out of reach by construction. The gate is a
185
+ * guard against a confused agent, not a confinement boundary for a
186
+ * malicious one — a hard boundary needs OS-level sandboxing of the bash
187
+ * tool itself (Seatbelt/Landlock-style), not better string matching.
188
+ *
189
+ * KNOWN LIMITATION (not fixable with text matching alone): `pattern` cannot
190
+ * enforce real directory containment. A rule like
191
+ * `{ pattern: "cat /safe/dir/*", action: "allow" }` will still match
192
+ * `cat /safe/dir/../../../etc/passwd`, because from a glob's point of view
193
+ * `..` is just more characters absorbed by the trailing `*` — there is no
194
+ * shell/path awareness in a plain string pattern. Use the `paths` mechanism
195
+ * (which resolves real paths via `resolve`/`relative`, see `toMatchablePath`
196
+ * below) instead of `pattern` whenever a rule needs to be scoped to a
197
+ * directory; don't rely on `pattern` for path containment.
198
+ */
199
+ /** Command names that merely forward to another command without changing what ultimately runs. */
200
+ const PASSTHROUGH_PREFIXES = new Set([
201
+ "sudo",
202
+ "doas",
203
+ "command",
204
+ "exec",
205
+ "nice",
206
+ "nohup",
207
+ "env",
208
+ "time",
209
+ "stdbuf",
210
+ "ionice",
211
+ "chrt",
212
+ "setsid",
213
+ "xargs",
214
+ ]);
215
+ /** Shells whose `-c <command>` argument is itself a full command line to unwrap and re-check. */
216
+ const SHELL_C_WRAPPERS = new Set(["bash", "sh", "zsh", "ksh", "dash"]);
217
+ /** Constructs that make a command dynamic/opaque enough that allow/approve patterns must never match it. */
218
+ const DANGEROUS_CONSTRUCT_RE = /\$\(|`|<|>/;
219
+ /** Quote-aware split of a command string on top-level chain operators (`;`, `&&`, `||`, `|`, `&`, newlines). */
220
+ function splitChain(command) {
221
+ const segments = [];
222
+ let current = "";
223
+ let quote;
224
+ let operator;
225
+ let i = 0;
226
+ while (i < command.length) {
227
+ const ch = command[i];
228
+ if (quote) {
229
+ current += ch;
230
+ if (ch === quote)
231
+ quote = undefined;
232
+ i++;
233
+ continue;
234
+ }
235
+ if (ch === '"' || ch === "'") {
236
+ quote = ch;
237
+ current += ch;
238
+ i++;
239
+ continue;
240
+ }
241
+ if (ch === "\\" && i + 1 < command.length) {
242
+ current += ch + command[i + 1];
243
+ i += 2;
244
+ continue;
245
+ }
246
+ const two = command.slice(i, i + 2);
247
+ if (two === "&&" || two === "||") {
248
+ segments.push({ text: current, operator });
249
+ current = "";
250
+ operator = two;
251
+ i += 2;
252
+ continue;
253
+ }
254
+ if (ch === ";" || ch === "|" || ch === "&" || ch === "\n") {
255
+ segments.push({ text: current, operator });
256
+ current = "";
257
+ operator = ch === "\n" ? ";" : ch;
258
+ i += 1;
259
+ continue;
260
+ }
261
+ current += ch;
262
+ i++;
263
+ }
264
+ segments.push({ text: current, operator });
265
+ return segments;
266
+ }
267
+ function collapseWhitespace(text) {
268
+ return text.trim().replace(/\s+/g, " ");
269
+ }
270
+ /** Canonicalizes combined single-dash short-flag clusters (`-rf` / `-fr`) by sorting their letters. */
271
+ function normalizeFlagClusters(text) {
272
+ return text.replace(/(^|\s)-([A-Za-z]{2,})(?=\s|$)/g, (_match, pre, letters) => {
273
+ return `${pre}-${letters.split("").sort().join("")}`;
274
+ });
275
+ }
276
+ function normalizeForMatch(text) {
277
+ return normalizeFlagClusters(collapseWhitespace(text));
278
+ }
279
+ /** Resolves a leading `/some/path/cmd` (or `./cmd`, `../cmd`) first token down to its bare basename. */
280
+ function resolveBasenameOfFirstToken(text) {
281
+ const leadingWs = text.slice(0, text.length - text.trimStart().length);
282
+ const trimmed = text.trimStart();
283
+ const match = trimmed.match(/^(\S+)([\s\S]*)$/);
284
+ if (!match)
285
+ return text;
286
+ const [, firstToken, rest] = match;
287
+ if (!firstToken.includes("/"))
288
+ return text;
289
+ const basename = firstToken.slice(firstToken.lastIndexOf("/") + 1);
290
+ return leadingWs + basename + rest;
291
+ }
292
+ function stripLeadingBackslashEscape(text) {
293
+ return text.replace(/^(\s*)\\(?=[A-Za-z])/, "$1");
294
+ }
295
+ function stripEnvAssignments(text) {
296
+ return text.replace(/^\s*(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)+/, "");
297
+ }
298
+ /** Strips one leading passthrough-wrapper command (e.g. `sudo`, `env FOO=1`) and its own flags, if present. */
299
+ function stripPassthroughPrefix(text) {
300
+ const trimmed = text.replace(/^\s+/, "");
301
+ const match = trimmed.match(/^(\S+)((?:\s+-\S+)*)\s+/);
302
+ if (!match)
303
+ return { stripped: text, changed: false };
304
+ const token = match[1];
305
+ const basename = token.includes("/") ? token.slice(token.lastIndexOf("/") + 1) : token;
306
+ if (!PASSTHROUGH_PREFIXES.has(basename.toLowerCase()))
307
+ return { stripped: text, changed: false };
308
+ return { stripped: trimmed.slice(match[0].length), changed: true };
309
+ }
310
+ /** Extracts the inner command line from a `bash -c "..."` / `sh -c '...'` style wrapper, if present. */
311
+ function extractShellDashC(text) {
312
+ const trimmed = text.trim();
313
+ const match = trimmed.match(/^(\S+)(?:\s+-\S+)*\s+-c\s+(['"])([\s\S]*)\2\s*$/);
314
+ if (!match)
315
+ return undefined;
316
+ const token = match[1];
317
+ const basename = token.includes("/") ? token.slice(token.lastIndexOf("/") + 1) : token;
318
+ if (!SHELL_C_WRAPPERS.has(basename.toLowerCase()))
319
+ return undefined;
320
+ return match[3];
321
+ }
322
+ /** Extracts the inner command line from an `eval "..."` / `eval '...'` wrapper, if present. */
323
+ function extractEvalArg(text) {
324
+ const match = text.trim().match(/^eval\s+(['"])([\s\S]*)\1\s*$/i);
325
+ return match ? match[2] : undefined;
326
+ }
327
+ /** Extracts the contents of every `$(...)` and `` `...` `` command substitution found anywhere in `text`. */
328
+ function extractSubstitutions(text) {
329
+ const results = [];
330
+ let i = 0;
331
+ while (i < text.length) {
332
+ if (text[i] === "$" && text[i + 1] === "(") {
333
+ let depth = 1;
334
+ let j = i + 2;
335
+ while (j < text.length && depth > 0) {
336
+ if (text[j] === "(")
337
+ depth++;
338
+ else if (text[j] === ")")
339
+ depth--;
340
+ j++;
341
+ }
342
+ results.push(text.slice(i + 2, depth === 0 ? j - 1 : j));
343
+ i = j;
344
+ continue;
345
+ }
346
+ i++;
347
+ }
348
+ const backtickMatches = text.match(/`([^`]*)`/g);
349
+ if (backtickMatches) {
350
+ for (const m of backtickMatches)
351
+ results.push(m.slice(1, -1));
352
+ }
353
+ return results;
354
+ }
355
+ /**
356
+ * Returns the literal output of a simple `echo ...` command. This covers a
357
+ * substitution used as a command position, such as `$(echo rm -rf /)`, where
358
+ * the output is subsequently executed by the outer shell.
359
+ */
360
+ function extractSimpleEchoOutput(text) {
361
+ const match = text.match(/^\s*echo\s+([^$`]+?)\s*$/i);
362
+ return match?.[1];
363
+ }
364
+ const MAX_DENY_CANDIDATES = 50;
365
+ const MAX_DENY_DEPTH = 4;
366
+ /**
367
+ * Paranoidly enumerates every independently-executed "piece" of `command` a
368
+ * `deny` rule should be checked against: the raw command, each chained
369
+ * segment, prefix/wrapper-stripped variants of each segment, and the bodies
370
+ * of any `bash -c` / `eval` / `$(...)` / backtick constructs — recursively,
371
+ * bounded so adversarial input can't cause unbounded work.
372
+ */
373
+ function collectDenyCandidates(command) {
374
+ const seen = new Set();
375
+ const queue = [{ text: command, depth: 0 }];
376
+ while (queue.length > 0 && seen.size < MAX_DENY_CANDIDATES) {
377
+ const next = queue.shift();
378
+ if (!next)
379
+ break;
380
+ const { text, depth } = next;
381
+ if (seen.has(text))
382
+ continue;
383
+ seen.add(text);
384
+ if (depth >= MAX_DENY_DEPTH)
385
+ continue;
386
+ const enqueue = (candidate) => {
387
+ if (!seen.has(candidate) && seen.size + queue.length < MAX_DENY_CANDIDATES) {
388
+ queue.push({ text: candidate, depth: depth + 1 });
389
+ }
390
+ };
391
+ const segments = splitChain(text).map((s) => s.text);
392
+ const pieces = segments.length > 1 ? segments : [text];
393
+ for (const seg of segments)
394
+ enqueue(seg);
395
+ for (const piece of pieces) {
396
+ let working = stripLeadingBackslashEscape(piece);
397
+ working = stripEnvAssignments(working);
398
+ for (let guard = 0; guard < 5; guard++) {
399
+ const { stripped, changed } = stripPassthroughPrefix(working);
400
+ if (!changed)
401
+ break;
402
+ working = stripped;
403
+ }
404
+ enqueue(working);
405
+ const basenameResolved = resolveBasenameOfFirstToken(working);
406
+ enqueue(basenameResolved);
407
+ const shellC = extractShellDashC(working) ?? extractShellDashC(basenameResolved);
408
+ if (shellC !== undefined)
409
+ enqueue(shellC);
410
+ const evalArg = extractEvalArg(working) ?? extractEvalArg(basenameResolved);
411
+ if (evalArg !== undefined)
412
+ enqueue(evalArg);
413
+ for (const sub of extractSubstitutions(piece)) {
414
+ enqueue(sub);
415
+ const echoOutput = extractSimpleEchoOutput(sub);
416
+ if (echoOutput !== undefined)
417
+ enqueue(echoOutput);
418
+ }
419
+ }
420
+ }
421
+ return [...seen];
422
+ }
423
+ function globToRegExp(pattern) {
424
+ let source = "";
425
+ for (const ch of pattern) {
426
+ if (ch === "*")
427
+ source += ".*";
428
+ else if (ch === "?")
429
+ source += ".";
430
+ else
431
+ source += ch.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
432
+ }
433
+ return new RegExp(`^${source}$`, "is");
434
+ }
435
+ function matchDenyPattern(command, pattern) {
436
+ const regex = globToRegExp(normalizeForMatch(pattern));
437
+ return collectDenyCandidates(command).some((candidate) => regex.test(normalizeForMatch(candidate)));
438
+ }
439
+ /**
440
+ * Strictly matches `command` against an `allow`/`approve` `pattern`: any
441
+ * dynamic/opaque construct disqualifies the match outright, and the command
442
+ * must have the same chain shape (segment count and operators) as the
443
+ * pattern, with every segment matching independently. This is what stops a
444
+ * rule like `{ pattern: "npm test*", action: "allow" }` from also
445
+ * authorizing `npm test; rm -rf /` or `` npm test `rm -rf /` ``.
446
+ */
447
+ function matchAllowPattern(command, pattern) {
448
+ if (DANGEROUS_CONSTRUCT_RE.test(command))
449
+ return false;
450
+ const commandSegments = splitChain(command);
451
+ const patternSegments = splitChain(pattern);
452
+ if (commandSegments.length !== patternSegments.length)
453
+ return false;
454
+ for (let i = 0; i < commandSegments.length; i++) {
455
+ if (commandSegments[i].operator !== patternSegments[i].operator)
456
+ return false;
457
+ const cmdText = normalizeForMatch(commandSegments[i].text);
458
+ const cmdResolved = normalizeForMatch(resolveBasenameOfFirstToken(commandSegments[i].text));
459
+ const regex = globToRegExp(normalizeForMatch(patternSegments[i].text));
460
+ if (!regex.test(cmdText) && !regex.test(cmdResolved))
461
+ return false;
462
+ }
463
+ return true;
464
+ }
465
+ function matchCommandPattern(command, pattern, action) {
466
+ return action === "deny" ? matchDenyPattern(command, pattern) : matchAllowPattern(command, pattern);
467
+ }
468
+ /**
469
+ * Built-in danger filter backing `auto` mode. These are matched with the
470
+ * same paranoid strategy as `deny` rules (chain splitting, wrapper
471
+ * unwrapping, substitution extraction), so `echo hi && rm -rf /` or
472
+ * `bash -c "sudo dd ..."` still trip the filter.
473
+ *
474
+ * This is a *prompt* heuristic, not a security boundary: it decides which
475
+ * unmatched commands fall back to approval instead of auto-allow. It can
476
+ * never enumerate every destructive command — anything that must be hard
477
+ * blocked belongs in a `deny` rule in `permissions.yml`.
478
+ */
479
+ export const DANGEROUS_COMMAND_PATTERNS = [
480
+ // recursive/forced deletion (flag clusters normalize to sorted letters,
481
+ // so `-rf`/`-fr` become `-fr` and are caught by the `-f*` prefix; bare
482
+ // `-r`/`-R` by the `-r*` prefix via case-insensitive matching)
483
+ "rm -r*",
484
+ "rm -f*",
485
+ // privilege escalation
486
+ "sudo *",
487
+ "doas *",
488
+ "su *",
489
+ // raw disk / filesystem surgery
490
+ "dd *",
491
+ "mkfs*",
492
+ // system state
493
+ "shutdown*",
494
+ "reboot*",
495
+ "halt*",
496
+ "poweroff*",
497
+ // blanket permission changes
498
+ "chmod 777 *",
499
+ "chmod -R *",
500
+ "chown -R *",
501
+ // outward-facing / history-rewriting git and publishing
502
+ "git push*",
503
+ "git reset --hard*",
504
+ "git clean*",
505
+ "npm publish*",
506
+ "yarn publish*",
507
+ "pnpm publish*",
508
+ // pipe-to-shell installers
509
+ "curl * | *",
510
+ "wget * | *",
511
+ // inline interpreter eval — the code payload is another language the gate
512
+ // cannot parse, so `python -c "os.system('rm -rf /')"` would otherwise
513
+ // sail through as "not shell-dangerous". Running a script *file*
514
+ // (`python script.py`) is deliberately NOT flagged: it is everyday dev
515
+ // work, and the gate cannot see file contents anyway (see the module doc
516
+ // on interpreter escape hatches).
517
+ "python* -c*",
518
+ "node -e*",
519
+ "node --eval*",
520
+ "node -p*",
521
+ "bun -e*",
522
+ "bun --eval*",
523
+ "deno eval*",
524
+ "ruby -e*",
525
+ "perl -e*",
526
+ "php -r*",
527
+ ];
528
+ /**
529
+ * Returns the first built-in dangerous pattern the command matches, or
530
+ * `undefined` if the command passes the filter.
531
+ */
532
+ export function findDangerousPattern(command) {
533
+ return DANGEROUS_COMMAND_PATTERNS.find((pattern) => matchDenyPattern(command, pattern));
534
+ }
535
+ /** Normalize a (possibly relative or absolute) path into a forward-slash path relative to `cwd`, for glob matching. */
536
+ function toMatchablePath(filePath, cwd) {
537
+ const resolved = isAbsolute(filePath) ? filePath : resolve(cwd, filePath);
538
+ const rel = relative(cwd, resolved);
539
+ return rel.split(sep).join("/");
540
+ }
541
+ /** Whether `filePath` (relative or absolute) resolves to a location inside `cwd`. */
542
+ function isWithinProject(filePath, cwd) {
543
+ const resolved = isAbsolute(filePath) ? filePath : resolve(cwd, filePath);
544
+ const rel = relative(cwd, resolved);
545
+ return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
546
+ }
547
+ /**
548
+ * NOTE: this assumes the tool-call args carry a `command` string under the
549
+ * exact key `command`. If/when this gate is wired into actual tool
550
+ * dispatch, verify every gated tool's argument shape matches these
551
+ * hardcoded key names — a mismatch doesn't error, it just silently fails to
552
+ * match any `pattern`/`paths` rule and falls through to the (fail-safe)
553
+ * default decision. Not currently exploitable: nothing outside this module
554
+ * and its test calls `PermissionGate`/`loadRules` yet.
555
+ */
556
+ function getCommandArg(args) {
557
+ return typeof args.command === "string" ? args.command : undefined;
558
+ }
559
+ /** Prefers `file_path` over `path` when both are present; see the note on `getCommandArg` above. */
560
+ function getPathArg(args) {
561
+ if (typeof args.file_path === "string")
562
+ return args.file_path;
563
+ if (typeof args.path === "string")
564
+ return args.path;
565
+ return undefined;
566
+ }
567
+ function describeMatch(rule) {
568
+ const parts = [`tool=${rule.tool}`];
569
+ if (rule.pattern !== undefined)
570
+ parts.push(`pattern=${JSON.stringify(rule.pattern)}`);
571
+ if (rule.paths !== undefined)
572
+ parts.push(`paths=${JSON.stringify(rule.paths)}`);
573
+ return `matched rule (${parts.join(", ")}) -> ${rule.action}`;
574
+ }
575
+ function ruleMatches(rule, toolName, args, cwd) {
576
+ if (rule.tool !== "*" && rule.tool.toLowerCase() !== toolName)
577
+ return false;
578
+ if (rule.pattern !== undefined) {
579
+ const command = getCommandArg(args);
580
+ if (command === undefined || !matchCommandPattern(command, rule.pattern, rule.action))
581
+ return false;
582
+ }
583
+ if (rule.paths !== undefined) {
584
+ const filePath = getPathArg(args);
585
+ if (filePath === undefined)
586
+ return false;
587
+ const matchable = toMatchablePath(filePath, cwd);
588
+ if (!rule.paths.some((pattern) => minimatch(matchable, pattern, { dot: true })))
589
+ return false;
590
+ }
591
+ return true;
592
+ }
593
+ /**
594
+ * Evaluates tool calls against an ordered list of permission rules,
595
+ * returning a `deny` / `allow` / `approve` decision.
596
+ */
597
+ export class PermissionGate {
598
+ constructor(rules = [], options = {}) {
599
+ this.rules = rules;
600
+ this.cwd = options.cwd ?? process.cwd();
601
+ this.mode = options.mode ?? "default";
602
+ }
603
+ /** Evaluate a tool call. `args` should carry `command` for bash, or `path`/`file_path` for read/write/edit. */
604
+ evaluate(toolName, args = {}) {
605
+ const normalizedTool = toolName.toLowerCase();
606
+ for (const rule of this.rules) {
607
+ if (ruleMatches(rule, normalizedTool, args, this.cwd)) {
608
+ return this.applyMode({ action: rule.action, reason: describeMatch(rule) });
609
+ }
610
+ }
611
+ return this.applyMode(this.defaultDecision(normalizedTool, args));
612
+ }
613
+ /**
614
+ * Applies the session mode to a decision. `deny` is never relaxed by any
615
+ * mode; `yolo` downgrades every `approve` to `allow`.
616
+ */
617
+ applyMode(decision) {
618
+ if (this.mode === "yolo" && decision.action === "approve") {
619
+ return { action: "allow", reason: `yolo mode: auto-allowed (${decision.reason})` };
620
+ }
621
+ return decision;
622
+ }
623
+ defaultDecision(toolName, args) {
624
+ if (DEFAULT_ALLOWED_TOOLS.has(toolName)) {
625
+ return { action: "allow", reason: `no rule matched; "${toolName}" is allowed by default` };
626
+ }
627
+ if (toolName === "bash") {
628
+ if (this.mode === "auto") {
629
+ const command = getCommandArg(args);
630
+ if (command === undefined) {
631
+ return { action: "approve", reason: "auto mode: bash call without a command string requires approval" };
632
+ }
633
+ const dangerous = findDangerousPattern(command);
634
+ if (dangerous !== undefined) {
635
+ return {
636
+ action: "approve",
637
+ reason: `auto mode: command matched dangerous pattern ${JSON.stringify(dangerous)}, requires approval`,
638
+ };
639
+ }
640
+ return { action: "allow", reason: "auto mode: no rule matched and command passed the danger filter" };
641
+ }
642
+ return { action: "approve", reason: "no rule matched; bash commands require approval by default" };
643
+ }
644
+ if (PATH_SCOPED_TOOLS.has(toolName)) {
645
+ const filePath = getPathArg(args);
646
+ if (filePath !== undefined && isWithinProject(filePath, this.cwd)) {
647
+ return { action: "allow", reason: "no rule matched; allowed by default within the project" };
648
+ }
649
+ return {
650
+ action: "approve",
651
+ reason: "no rule matched; path is outside the project (or missing), requires approval",
652
+ };
653
+ }
654
+ if (READ_ONLY_PATH_TOOLS.has(toolName)) {
655
+ // Unlike read/write/edit, these tools treat a missing `path` as the
656
+ // cwd, so an absent path arg is within the project by definition.
657
+ const filePath = getPathArg(args) ?? ".";
658
+ if (isWithinProject(filePath, this.cwd)) {
659
+ return { action: "allow", reason: "no rule matched; read-only tool allowed by default within the project" };
660
+ }
661
+ return {
662
+ action: "approve",
663
+ reason: "no rule matched; path is outside the project, requires approval",
664
+ };
665
+ }
666
+ return { action: "approve", reason: `no rule matched for tool "${toolName}"; defaults to approve` };
667
+ }
668
+ }
669
+ //# sourceMappingURL=permission-gate.js.map