@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
@@ -0,0 +1,294 @@
1
+ # TypeScript patterns
2
+
3
+ Worked don't/do examples for each rule in the table in `SKILL.md`. The principles behind them are language-agnostic; the syntax here is TypeScript's.
4
+
5
+ ## Branded types
6
+
7
+ Brand primitives so they can't be mixed up. Validate once at creation; downstream code trusts the type.
8
+
9
+ ```ts
10
+ type AgentId = string & { readonly __brand: "AgentId" };
11
+
12
+ function parseAgentId(input: string): AgentId {
13
+ if (!isUUID(input)) throw new Error(`Invalid agent id: ${input}`);
14
+ return input as AgentId;
15
+ }
16
+
17
+ function focusAgent(id: AgentId): void {
18
+ /* input is trusted */
19
+ }
20
+ ```
21
+
22
+ Match the `readonly __brand: 'X'` shape; don't invent a new convention.
23
+
24
+ ## Discriminated unions
25
+
26
+ If a bug forces the question "wait, can this combination actually happen?", the type is too loose. Model variants with a literal discriminant: every variant shares the field name and each variant's value is unique, so impossible combos can't be represented.
27
+
28
+ ```ts
29
+ // Don't. Boolean + optionals lets contradictory states exist.
30
+ type DiffState = { loading: boolean; diff?: GitDiff; error?: string };
31
+
32
+ // Do. Only valid states exist.
33
+ type DiffState =
34
+ | { kind: "loading" }
35
+ | { kind: "ready"; diff: GitDiff }
36
+ | { kind: "error"; error: string };
37
+ ```
38
+
39
+ Pick one discriminant name (`kind`, `type`, `tag`) per codebase and stick to it.
40
+
41
+ ## Constructive modeling
42
+
43
+ Build the type from parts that are all legal instead of restricting a loose type with runtime checks. Adding is easier than subtracting.
44
+
45
+ Non-empty, via a variadic tuple:
46
+
47
+ ```ts
48
+ type NonEmpty<T> = [T, ...T[]];
49
+
50
+ // Don't: T[] plus a length check every caller must repeat
51
+ function pickWinner(entries: string[]): string {
52
+ if (entries.length === 0) throw new Error("no entries");
53
+ return entries[Math.floor(Math.random() * entries.length)];
54
+ }
55
+
56
+ // Do: an empty value of the type can't exist
57
+ function pickWinner(entries: NonEmpty<string>): string {
58
+ return entries[Math.floor(Math.random() * entries.length)];
59
+ }
60
+ ```
61
+
62
+ Where a plain `T[]` arrives, narrow once with a guard. The fact then travels in the type:
63
+
64
+ ```ts
65
+ const isNonEmpty = <T>(arr: T[]): arr is NonEmpty<T> => arr.length > 0;
66
+ ```
67
+
68
+ Even length, as pairs — TypeScript has no refinement types (no `arr.length % 2 === 0` at the type level), and you don't need one:
69
+
70
+ ```ts
71
+ type Pairs<T> = [T, T][];
72
+ ```
73
+
74
+ A time range, as start plus duration:
75
+
76
+ ```ts
77
+ // Don't: a comment holds the invariant
78
+ type TimeRange = { start: Date; end: Date }; // start <= end
79
+
80
+ // Do: a negative range can't be written; derive end when needed
81
+ type TimeRange = { start: Date; durationMs: number };
82
+ ```
83
+
84
+ Keep `durationMs` a plain number; brand it (per Branded types) only if a raw number could plausibly be passed where a duration is expected, not by reflex. A `Pairs<T>` is an even-length list under the interpretation you give it, the same way `{ start, durationMs }` is a range. Pick the representation that makes the bad state unconstructable, then expose the reading you need on top (`pairs.flat()`, a `rangeEnd()` helper).
85
+
86
+ ## Simplest total type
87
+
88
+ Don't strengthen everything. Keep `T[]` while every operation on it is total:
89
+
90
+ ```ts
91
+ const sum = (xs: number[]) => xs.reduce((a, b) => a + b, 0); // [] is 0, fine
92
+ ```
93
+
94
+ Strengthen when the loose type forces a lie at a use site. The tells are `!`, `arr[0] as T`, and a "should never happen" throw:
95
+
96
+ ```ts
97
+ // Don't: partiality smuggled past the compiler
98
+ function newestSession(sessions: Session[]): Session {
99
+ return sessions.at(0)!;
100
+ }
101
+
102
+ // Do: strengthen the input; the assertion disappears
103
+ function newestSession(sessions: NonEmpty<Session>): Session {
104
+ return sessions[0];
105
+ }
106
+ ```
107
+
108
+ Weakening the result to `Session | undefined` is the other total signature. Either way the empty case lands at the call site — the one place that knows what empty means.
109
+
110
+ ## `unknown` over `any`
111
+
112
+ `any` disables type checking for everything it touches. External data is always `unknown`; narrow before use.
113
+
114
+ ```ts
115
+ // Don't
116
+ function handle(input: any) {
117
+ return input.foo.bar;
118
+ }
119
+
120
+ // Do
121
+ function handle(input: unknown) {
122
+ if (typeof input === "object" && input !== null && "foo" in input) {
123
+ // narrowed; the compiler verifies the access
124
+ }
125
+ }
126
+ ```
127
+
128
+ External sources include RPC payloads, `JSON.parse`, IPC, file contents, environment variables, and database results.
129
+
130
+ ## No `as` casts
131
+
132
+ Every `as` is a potential runtime crash. Cast only after validation has verified the claim — and the validation itself narrows without casting, or it proves nothing:
133
+
134
+ ```ts
135
+ // Don't
136
+ const user = data as User;
137
+
138
+ // Do. Earn the cast at the boundary; the checks narrow via typeof and `in`.
139
+ function parseUser(data: unknown): User {
140
+ if (typeof data !== "object" || data === null) {
141
+ throw new Error("expected object");
142
+ }
143
+ if (!("id" in data) || typeof data.id !== "string") {
144
+ throw new Error("expected string id");
145
+ }
146
+ // ... validate the remaining fields the same way
147
+ return data as User; // earned: every field was checked above
148
+ }
149
+ ```
150
+
151
+ When refactoring an `as` out of existing code, identify why the compiler can't infer:
152
+
153
+ - Missing discriminant: add one, switch to a discriminated union.
154
+ - Overly wide source type (e.g. `Record<string, unknown>`): narrow it.
155
+ - Untyped boundary: add a parse function or schema.
156
+ - Genuinely inexpressible: use a branded type or `satisfies`.
157
+
158
+ ## Narrowing hierarchy
159
+
160
+ From best to last-resort:
161
+
162
+ 1. **Discriminated union switch / if.** The compiler narrows automatically.
163
+ 2. **`in` operator.** `"key" in obj` narrows to the variants containing that key.
164
+ 3. **`typeof` / `instanceof`.** For primitives and class instances.
165
+ 4. **User-defined type guard.** When the above aren't enough.
166
+ 5. **`as` cast.** Only after validation.
167
+
168
+ ```ts
169
+ function area(s: Shape): number {
170
+ if ("radius" in s) return Math.PI * s.radius ** 2; // narrowed to circle
171
+ return s.width * s.height; // narrowed to rect
172
+ }
173
+ ```
174
+
175
+ ## Type guards
176
+
177
+ A guard must actually verify the claim. A lying guard is worse than `as` because the bug hides behind a name that says it's safe.
178
+
179
+ ```ts
180
+ function isCircle(s: Shape): s is Shape & { kind: "circle" } {
181
+ return s.kind === "circle";
182
+ }
183
+ ```
184
+
185
+ Prefer discriminant narrowing when possible — a guard adds a layer the reader has to follow.
186
+
187
+ ## Exhaustiveness
188
+
189
+ In default arms, assign the discriminant to a `never`-typed local. The compiler errors if a new variant is added without handling.
190
+
191
+ ```ts
192
+ // Value-returning switch
193
+ function area(s: Shape): number {
194
+ switch (s.kind) {
195
+ case "circle":
196
+ return Math.PI * s.radius ** 2;
197
+ case "rect":
198
+ return s.width * s.height;
199
+ default: {
200
+ const _exhaustive: never = s;
201
+ return _exhaustive;
202
+ }
203
+ }
204
+ }
205
+
206
+ // Void switch
207
+ function handle(s: Shape): void {
208
+ switch (s.kind) {
209
+ case "circle":
210
+ drawCircle(s);
211
+ break;
212
+ case "rect":
213
+ drawRect(s);
214
+ break;
215
+ default: {
216
+ const _exhaustive: never = s;
217
+ void _exhaustive;
218
+ }
219
+ }
220
+ }
221
+ ```
222
+
223
+ Return-style in value-returning switches; void-style in statement switches.
224
+
225
+ ## `satisfies` over `as`
226
+
227
+ `satisfies` validates without widening literal types.
228
+
229
+ ```ts
230
+ // Don't. Widens, loses literal types.
231
+ const config = { theme: "dark", cols: 3 } as Config;
232
+
233
+ // Do. Validates AND preserves literal types.
234
+ const config = { theme: "dark", cols: 3 } satisfies Config;
235
+ // config.theme is "dark" (literal), not string
236
+ ```
237
+
238
+ ## Boundary validation
239
+
240
+ Validate once where data crosses in; trust types inside. Scattered validation is noisy, redundant, and gives a false sense of safety.
241
+
242
+ - **At boundaries** (CLI args, config files, env vars, network payloads, database rows): parse into a named domain type, return errors, handle defensively.
243
+ - **Inside the system:** typed data, error propagation, no re-validation. No redundant null checks deep in call chains when the boundary already validated.
244
+ - **Across the boundary:** expose domain concepts, not the wire format — don't re-export transport, storage, or framework types through the public surface.
245
+ - **Wire formats** (proto, JSON-RPC): parse with unknown fields ignored so forward-compatible changes don't break old clients. **Persisted JSON:** versioned blob with a try/catch around the parse.
246
+ - Keep business logic in pure functions the boundary shell calls: parse functions as pure transforms from raw bytes to typed state, so the logic tests without the framework.
247
+
248
+ ## Schema-derived types
249
+
250
+ When a `.proto`, OpenAPI spec, GraphQL schema, or database migration already defines a shape, derive from the generated types instead of duplicating them.
251
+
252
+ ```ts
253
+ // Don't. Duplicate shape, drifts when the schema changes.
254
+ type CheckSummary = {
255
+ totalCount: number;
256
+ checks: { name: string; status: string }[];
257
+ };
258
+ function renderChecks(s: CheckSummary) {
259
+ /* ... */
260
+ }
261
+
262
+ // Do. Derive from the generated schema type.
263
+ import type { ChecksMessage } from "<generated module>";
264
+ function renderChecks(s: Pick<ChecksMessage, "totalCount" | "checks">) {
265
+ /* ... */
266
+ }
267
+ ```
268
+
269
+ Reach for `Pick`, `Omit`, `Parameters`, `ReturnType`, `Awaited`, `typeof` before writing a new interface.
270
+
271
+ ## Object args
272
+
273
+ ```ts
274
+ // Don't. Swap two args, still compiles.
275
+ openFile(uri, {
276
+ startLineNumber: 10,
277
+ startColumn: 1,
278
+ endLineNumber: 10,
279
+ endColumn: 1,
280
+ });
281
+
282
+ // Do. Order-independent, self-documenting.
283
+ openFile({
284
+ uri,
285
+ selection: {
286
+ startLineNumber: 10,
287
+ startColumn: 1,
288
+ endLineNumber: 10,
289
+ endColumn: 1,
290
+ },
291
+ });
292
+ ```
293
+
294
+ Skip on hot paths: per-frame render, tokenizers, parsers, anything in a tight loop where the allocation cost matters.
@@ -0,0 +1,101 @@
1
+ ---
2
+ name: unslop
3
+ description: Cut AI tells from prose deliverables the agent produces — docs, READMEs, reports, summaries, UAT reports, handoff documents, commit bodies, PR descriptions, client-facing text — then add voice back so the result is neither slop nor sterile. Use when writing or substantially editing any prose deliverable, or when the user says "unslop", "de-AI-ify", "sounds like AI", "make it sound human", or asks to clean up slop. Covers German prose by analogy (Füllwörter, Werbesprache, Anglizismen). Never applies to code, code comments, quoted output or evidence, machine-parsed formats (commit subjects, STATUS lines, frontmatter), or draht's own prompt and skill corpus.
4
+ ---
5
+
6
+ # Unslop
7
+
8
+ An editing pass over prose the agent produces. Run it while the deliverable is being written — as the report, doc, or handoff takes shape — never as a sweep over a repository. The job has two halves: cut the tells, then put voice back. Sterile prose is as recognizable as sloppy prose.
9
+
10
+ ## Scope
11
+
12
+ Unslop governs prose draht produces: docs, READMEs, reports, UAT reports, summaries, handoff documents, specs, commit bodies, PR descriptions, client-facing text.
13
+
14
+ It never applies to code, identifiers, or code comments, and never to user-authored text uninvited. Draht's own prompts and skills are not a target: the corpus legitimately uses em dashes and bold lead-ins as house style. This skill governs work products, not the toolchain's instruction files.
15
+
16
+ Edit only text you are producing or were asked to edit. Never rewrite quoted command output, error messages, evidence, or the user's own words. Fixed formats stay fixed: conventional-commit subject lines, red:/green:/refactor: prefixes, STATUS: lines, frontmatter, verdict-first report ordering.
17
+
18
+ ## Process
19
+
20
+ 1. Scan the text for the patterns below.
21
+ 2. Rewrite. Preserve meaning and register.
22
+ 3. Add voice back — register-aware (see Adding Voice).
23
+ 4. Self-audit: ask "What makes this obviously AI generated?" and fix the remaining tells.
24
+
25
+ ## Patterns
26
+
27
+ Every entry pairs the tell with its fix.
28
+
29
+ ### Content
30
+
31
+ - **Puffery and promotional language.** "pivotal moment", "testament to", "evolving landscape", "groundbreaking", "vibrant", "renowned", "stunning". Cut it; state what happened.
32
+ - **Superficial -ing phrases.** "highlighting...", "ensuring...", "showcasing...", "fostering...". Delete, or expand into a real statement with a real source.
33
+ - **Vague attributions.** "Experts believe", "reports suggest", "some argue". Name the source or delete. In a report this means citing the command or file, not "tests suggest".
34
+
35
+ ### Language
36
+
37
+ - **AI vocabulary** (English-calibrated): additionally, crucial, delve, enduring, enhance, fostering, garner, interplay, intricate, landscape (abstract), pivotal, showcase, tapestry (abstract), testament, underscore, vibrant. Use the plain word.
38
+ - **Fancy ways to say "is".** "serves as", "stands as", "boasts", "features". Say "is" or "has".
39
+ - **"Not just X, but Y."** State the point directly.
40
+ - **Rule of three.** Ideas forced into groups of three. Use the natural number.
41
+ - **Synonym cycling.** Protagonist, main character, central figure, hero in one paragraph. Pick one term and repeat it — repeating the established name is precision, not monotony.
42
+ - **False ranges.** "from X to Y" where X and Y sit on no meaningful scale. List the items directly.
43
+
44
+ ### Style
45
+
46
+ - **Dash moderation.** An em dash is punctuation, not a tell. Three per paragraph is. Do not chain them, do not let dashes replace every comma and period; vary the connective.
47
+ - **Colon crutches.** A colon is for a list or an example, not a mid-sentence connector. Rewrite so the point stands on its own.
48
+ - **Boldface spam.** Don't bold every noun, proper name, or acronym.
49
+ - **Inline-header lists.** The tell is a bold label and colon restating the line. A bold lead-in ending in a period, naming the item, followed by genuinely new detail is fine.
50
+ - **Headings** (English-only rule): sentence case, not title case.
51
+ - **Decorative emojis.** Remove from headings and bullets.
52
+ - **Curly quotes.** Replace with straight quotes.
53
+
54
+ ### Communication Artifacts
55
+
56
+ The group most relevant to reports and handoffs.
57
+
58
+ - **Chatbot phrases.** "I hope this helps!", "Let me know if...", "Certainly!", "Found the smoking gun!". Remove.
59
+ - **Cutoff disclaimers.** "While specific details are limited...". Find the fact or drop the sentence.
60
+ - **Sycophancy.** "Great question!", "You're absolutely right!". Respond directly.
61
+
62
+ ### Filler
63
+
64
+ - **Filler phrases** (English-calibrated). "In order to" becomes "To". "Due to the fact that" becomes "Because". "It is important to note that" gets deleted.
65
+ - **Hedging stacks.** "could potentially possibly be argued that it might" becomes "may".
66
+ - **Generic conclusions.** "The future looks bright." State the specific plan or fact, or end one sentence earlier.
67
+
68
+ ### Jargon
69
+
70
+ - **Abstract metaphor nouns.** Substrate, wedge, vector, nexus, bedrock, modality, paradigm, north star, flywheel, endgame. These sound technical but hide a plainer concrete word: "substrate" becomes "base", "wedge in" becomes "add", "north star" / "flywheel" / "endgame" become the plain phrase. Pick the concrete word.
71
+ - **Carve-out.** A term defined in .planning/DOMAIN.md or established in the project's vocabulary is never slop — the ubiquitous-language rule wins over this list.
72
+
73
+ ### Plain Speech
74
+
75
+ - **Name the mechanism, not the feeling.** "the database stays close at hand" names a feeling; "a column rename fails the build" names a mechanism. Restate every claim as a concrete instruction, fact, or number — or cut it. If the sentence could appear unchanged in another project's docs, it says nothing about this one. Cut it.
76
+ - **One idea per sentence.** If the reader has to backtrack to parse a sentence, split it or drop clauses.
77
+ - **Active voice with a named actor.** "queries are validated" becomes "the compiler validates queries". Passive is fine only when the actor is unknown or genuinely irrelevant.
78
+ - **Cut adverbs, or use the measured number.** "significantly improves" becomes the measured delta. An adverb propping up a weak verb means the verb is wrong.
79
+ - **Prefer the plain word** (English-calibrated). "utilize" becomes "use", "leverage" becomes "use", "facilitate" becomes "help", "numerous" becomes "many", "in the event that" becomes "if".
80
+
81
+ ## Adding Voice
82
+
83
+ Removing patterns is half the job — voiceless prose is just as obviously machine-made. Register decides how much voice returns:
84
+
85
+ - **Docs and READMEs**: have opinions and react to facts instead of neutrally listing pros and cons; vary rhythm (short sentences, then longer ones that take their time); use "I" when it fits; be specific.
86
+ - **Reports, UAT reports, handoffs, client-facing text**: stay factual and concrete. Specificity is the voice there — name the file, the count, the command. No filler warmth, no manufactured mess.
87
+
88
+ ## German Prose
89
+
90
+ The word lists above are English-calibrated. The discipline generalizes to German by category, not by translated catalog:
91
+
92
+ - **Füllwörter**: "im Grunde genommen", "quasi", "sozusagen" — streichen.
93
+ - **Werbesprache**: "innovativ", "ganzheitlich", "im heutigen digitalen Zeitalter", "spielt eine entscheidende Rolle" — sagen, was passiert ist.
94
+ - **Anglizismen-Slop**: "leveragen", "alignen" where a German word exists — use the German word.
95
+ - "nicht nur X, sondern auch Y" is the "not just X, but Y" tell verbatim: state the point directly.
96
+ - Style and format tells (dash chaining, bold spam, decorative emojis, curly quotes) and communication artifacts (chatbot phrases, disclaimers, sycophancy) are language-independent.
97
+ - The sentence-case-headings rule is English-only — German headings follow German orthography.
98
+
99
+ ## Self-Audit
100
+
101
+ Before delivering, ask once more: "What makes this obviously AI generated?" Fix what you find.
@@ -0,0 +1,28 @@
1
+ /** realpath collapses `..` lexically before following links, so this walks one segment at a time. */
2
+ export type SegmentResolution = {
3
+ readonly ok: true;
4
+ readonly path: string;
5
+ } | {
6
+ readonly ok: false;
7
+ readonly missing: boolean;
8
+ readonly reason: string;
9
+ };
10
+ /** `prefix` must be resolved, `segment` a single name or `..`. `missing` is ENOENT only: anything else means we cannot know. */
11
+ export declare function resolveRealSegment(prefix: string, segment: string): SegmentResolution;
12
+ export interface RealPrefix {
13
+ /** The deepest ancestor that resolved, symlink-free. */
14
+ real: string;
15
+ /** Segments below it, verbatim. */
16
+ unresolved: string[];
17
+ failed: boolean;
18
+ }
19
+ export declare function resolveRealPrefix(path: string): RealPrefix;
20
+ export declare function spellRealPrefix({ real, unresolved }: RealPrefix): string;
21
+ /** The real path, or `undefined` when any part of it could not be resolved. The only one a security decision may use. */
22
+ export declare function realPathStrict(path: string): string | undefined;
23
+ /** Trust-store keys only. Total, so the unresolved suffix is spelled literally and may name a directory we are not in. */
24
+ export declare function trustKeyPath(path: string): string;
25
+ /** Dedup and display identity only. Total, so equality holds no further than the filesystem could be read. */
26
+ export declare function comparablePath(path: string): string;
27
+ export declare function realHomeDir(): string | undefined;
28
+ //# sourceMappingURL=canonical-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-path.d.ts","sourceRoot":"","sources":["../../src/utils/canonical-path.ts"],"names":[],"mappings":"AAAA,qGAAqG;AAUrG,MAAM,MAAM,iBAAiB,GAC1B;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAQ9E,gIAAgI;AAChI,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAsBrF;AAED,MAAM,WAAW,UAAU;IAC1B,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;CAChB;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CA6B1D;AAED,wBAAgB,eAAe,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,UAAU,GAAG,MAAM,CAExE;AAED,yHAAyH;AACzH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG/D;AAED,0HAA0H;AAC1H,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,8GAA8G;AAC9G,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,WAAW,IAAI,MAAM,GAAG,SAAS,CAEhD"}
@@ -0,0 +1,90 @@
1
+ /** realpath collapses `..` lexically before following links, so this walks one segment at a time. */
2
+ // POSIX only: on win32 `\` is a data byte, so a junction is one lstat'd segment and never resolved.
3
+ import { lstatSync, realpathSync } from "node:fs";
4
+ import { homedir } from "node:os";
5
+ import { isAbsolute, join, parse } from "node:path";
6
+ import { normalizePath } from "./paths.js";
7
+ const realpathNative = realpathSync.native;
8
+ function errorCode(error) {
9
+ return typeof error === "object" && error !== null && "code" in error
10
+ ? String(error.code)
11
+ : undefined;
12
+ }
13
+ /** `prefix` must be resolved, `segment` a single name or `..`. `missing` is ENOENT only: anything else means we cannot know. */
14
+ export function resolveRealSegment(prefix, segment) {
15
+ const candidate = join(prefix, segment);
16
+ // bun rewrites `\` to `/` before the realpath syscall, answering for a path the kernel would not traverse.
17
+ if (candidate.includes("\\")) {
18
+ try {
19
+ if (lstatSync(candidate).isSymbolicLink()) {
20
+ return {
21
+ ok: false,
22
+ missing: false,
23
+ reason: `refusing to follow ${JSON.stringify(candidate)}: a symbolic link named through a backslash cannot be resolved on every runtime`,
24
+ };
25
+ }
26
+ return { ok: true, path: candidate };
27
+ }
28
+ catch (error) {
29
+ return { ok: false, missing: errorCode(error) === "ENOENT", reason: `${error.message}` };
30
+ }
31
+ }
32
+ try {
33
+ return { ok: true, path: realpathNative(candidate) };
34
+ }
35
+ catch (error) {
36
+ return { ok: false, missing: errorCode(error) === "ENOENT", reason: `${error.message}` };
37
+ }
38
+ }
39
+ export function resolveRealPrefix(path) {
40
+ const normalized = normalizePath(path, { expandTilde: false });
41
+ const expanded = normalized === "~" || normalized.startsWith("~/") ? homedir() + normalized.slice(1) : normalized;
42
+ const root = isAbsolute(expanded) ? parse(expanded).root : "";
43
+ let real = root || process.cwd();
44
+ const unresolved = [];
45
+ let failed = false;
46
+ // "/" only: splitting a backslash apart keys a real directory onto a path that does not exist.
47
+ for (const segment of expanded.slice(root.length).split("/")) {
48
+ if (segment === "" || segment === ".") {
49
+ continue;
50
+ }
51
+ if (unresolved.length > 0) {
52
+ if (segment === "..") {
53
+ unresolved.pop();
54
+ }
55
+ else {
56
+ unresolved.push(segment);
57
+ }
58
+ continue;
59
+ }
60
+ const resolved = resolveRealSegment(real, segment);
61
+ if (resolved.ok) {
62
+ real = resolved.path;
63
+ }
64
+ else {
65
+ failed = true;
66
+ unresolved.push(segment);
67
+ }
68
+ }
69
+ return { real, unresolved, failed };
70
+ }
71
+ export function spellRealPrefix({ real, unresolved }) {
72
+ return unresolved.length === 0 ? real : join(real, ...unresolved);
73
+ }
74
+ /** The real path, or `undefined` when any part of it could not be resolved. The only one a security decision may use. */
75
+ export function realPathStrict(path) {
76
+ const { real, failed } = resolveRealPrefix(path);
77
+ return failed ? undefined : real;
78
+ }
79
+ /** Trust-store keys only. Total, so the unresolved suffix is spelled literally and may name a directory we are not in. */
80
+ export function trustKeyPath(path) {
81
+ return spellRealPrefix(resolveRealPrefix(path));
82
+ }
83
+ /** Dedup and display identity only. Total, so equality holds no further than the filesystem could be read. */
84
+ export function comparablePath(path) {
85
+ return spellRealPrefix(resolveRealPrefix(path));
86
+ }
87
+ export function realHomeDir() {
88
+ return realPathStrict(process.env.HOME || homedir());
89
+ }
90
+ //# sourceMappingURL=canonical-path.js.map
@@ -0,0 +1 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iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,WAAW;IAC1B,OAAO,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC,CAAC;AACtD,CAAC","sourcesContent":["/** realpath collapses `..` lexically before following links, so this walks one segment at a time. */\n// POSIX only: on win32 `\\` is a data byte, so a junction is one lstat'd segment and never resolved.\n\nimport { lstatSync, realpathSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { isAbsolute, join, parse } from \"node:path\";\nimport { normalizePath } from \"./paths.ts\";\n\nconst realpathNative = realpathSync.native;\n\nexport type SegmentResolution =\n\t| { readonly ok: true; readonly path: string }\n\t| { readonly ok: false; readonly missing: boolean; readonly reason: string };\n\nfunction errorCode(error: unknown): string | undefined {\n\treturn typeof error === \"object\" && error !== null && \"code\" in error\n\t\t? String((error as { code?: unknown }).code)\n\t\t: undefined;\n}\n\n/** `prefix` must be resolved, `segment` a single name or `..`. `missing` is ENOENT only: anything else means we cannot know. */\nexport function resolveRealSegment(prefix: string, segment: string): SegmentResolution {\n\tconst candidate = join(prefix, segment);\n\t// bun rewrites `\\` to `/` before the realpath syscall, answering for a path the kernel would not traverse.\n\tif (candidate.includes(\"\\\\\")) {\n\t\ttry {\n\t\t\tif (lstatSync(candidate).isSymbolicLink()) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\tmissing: false,\n\t\t\t\t\treason: `refusing to follow ${JSON.stringify(candidate)}: a symbolic link named through a backslash cannot be resolved on every runtime`,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { ok: true, path: candidate };\n\t\t} catch (error) {\n\t\t\treturn { ok: false, missing: errorCode(error) === \"ENOENT\", reason: `${(error as Error).message}` };\n\t\t}\n\t}\n\ttry {\n\t\treturn { ok: true, path: realpathNative(candidate) };\n\t} catch (error) {\n\t\treturn { ok: false, missing: errorCode(error) === \"ENOENT\", reason: `${(error as Error).message}` };\n\t}\n}\n\nexport interface RealPrefix {\n\t/** The deepest ancestor that resolved, symlink-free. */\n\treal: string;\n\t/** Segments below it, verbatim. */\n\tunresolved: string[];\n\tfailed: boolean;\n}\n\nexport function resolveRealPrefix(path: string): RealPrefix {\n\tconst normalized = normalizePath(path, { expandTilde: false });\n\tconst expanded = normalized === \"~\" || normalized.startsWith(\"~/\") ? homedir() + normalized.slice(1) : normalized;\n\tconst root = isAbsolute(expanded) ? parse(expanded).root : \"\";\n\tlet real = root || process.cwd();\n\tconst unresolved: string[] = [];\n\tlet failed = false;\n\t// \"/\" only: splitting a backslash apart keys a real directory onto a path that does not exist.\n\tfor (const segment of expanded.slice(root.length).split(\"/\")) {\n\t\tif (segment === \"\" || segment === \".\") {\n\t\t\tcontinue;\n\t\t}\n\t\tif (unresolved.length > 0) {\n\t\t\tif (segment === \"..\") {\n\t\t\t\tunresolved.pop();\n\t\t\t} else {\n\t\t\t\tunresolved.push(segment);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst resolved = resolveRealSegment(real, segment);\n\t\tif (resolved.ok) {\n\t\t\treal = resolved.path;\n\t\t} else {\n\t\t\tfailed = true;\n\t\t\tunresolved.push(segment);\n\t\t}\n\t}\n\treturn { real, unresolved, failed };\n}\n\nexport function spellRealPrefix({ real, unresolved }: RealPrefix): string {\n\treturn unresolved.length === 0 ? real : join(real, ...unresolved);\n}\n\n/** The real path, or `undefined` when any part of it could not be resolved. The only one a security decision may use. */\nexport function realPathStrict(path: string): string | undefined {\n\tconst { real, failed } = resolveRealPrefix(path);\n\treturn failed ? undefined : real;\n}\n\n/** Trust-store keys only. Total, so the unresolved suffix is spelled literally and may name a directory we are not in. */\nexport function trustKeyPath(path: string): string {\n\treturn spellRealPrefix(resolveRealPrefix(path));\n}\n\n/** Dedup and display identity only. Total, so equality holds no further than the filesystem could be read. */\nexport function comparablePath(path: string): string {\n\treturn spellRealPrefix(resolveRealPrefix(path));\n}\n\nexport function realHomeDir(): string | undefined {\n\treturn realPathStrict(process.env.HOME || homedir());\n}\n"]}
@@ -1,5 +1,11 @@
1
1
  import { type ChildProcess, type ChildProcessByStdio, type SpawnOptions, type SpawnOptionsWithStdioTuple, type SpawnSyncOptionsWithStringEncoding, type SpawnSyncReturns, type StdioNull, type StdioPipe } from "node:child_process";
2
2
  import type { Readable } from "node:stream";
3
+ /**
4
+ * Shell convention for a process terminated by a signal: 128 + signal number
5
+ * (137 for SIGKILL). Used when a child has no exit code so callers do not
6
+ * mistake a killed command for a successful one.
7
+ */
8
+ export declare function exitCodeForSignal(signal: NodeJS.Signals): number;
3
9
  export declare function spawnProcess(command: string, args: string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): ChildProcessByStdio<null, Readable, Readable>;
4
10
  export declare function spawnProcess(command: string, args: string[], options: SpawnOptions): ChildProcess;
5
11
  export declare function spawnProcessSync(command: string, args: string[], options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
@@ -13,6 +19,11 @@ export declare function spawnProcessSync(command: string, args: string[], option
13
19
  * the grace timer is re-armed on every chunk, so an actively writing descendant keeps
14
20
  * us reading, while a quiet inherited handle (e.g. a Windows daemonized descendant
15
21
  * that never lets `close` fire) still releases us after the grace elapses.
22
+ *
23
+ * Resolves the exit code, or `128 + signal number` when the child was killed by a
24
+ * signal (e.g. the OOM killer) and therefore has no exit code of its own.
16
25
  */
17
- export declare function waitForChildProcess(child: ChildProcess): Promise<number | null>;
26
+ export declare function waitForChildProcess(child: ChildProcess, options?: {
27
+ exitStdioGraceMs?: number;
28
+ }): Promise<number | null>;
18
29
  //# sourceMappingURL=child-process.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"child-process.d.ts","sourceRoot":"","sources":["../../src/utils/child-process.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,mBAAmB,EAGxB,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAC/B,KAAK,kCAAkC,EACvC,KAAK,gB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SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,GAClE,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACjD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,YAAY,CAAC;AAKnG,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,kCAAkC,GACzC,gBAAgB,CAAC,MAAM,CAAC,CAI1B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,YAAY,EACnB,OAAO,GAAE;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAO,GACzC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA6FxB"}
@@ -1,6 +1,15 @@
1
1
  import { spawn as nodeSpawn, spawnSync as nodeSpawnSync, } from "node:child_process";
2
+ import { constants as osConstants } from "node:os";
2
3
  import crossSpawn from "cross-spawn";
3
4
  const EXIT_STDIO_GRACE_MS = 100;
5
+ /**
6
+ * Shell convention for a process terminated by a signal: 128 + signal number
7
+ * (137 for SIGKILL). Used when a child has no exit code so callers do not
8
+ * mistake a killed command for a successful one.
9
+ */
10
+ export function exitCodeForSignal(signal) {
11
+ return 128 + (osConstants.signals[signal] ?? 0);
12
+ }
4
13
  export function spawnProcess(command, args, options) {
5
14
  return process.platform === "win32" ? crossSpawn(command, args, options) : nodeSpawn(command, args, options);
6
15
  }
@@ -19,12 +28,17 @@ export function spawnProcessSync(command, args, options) {
19
28
  * the grace timer is re-armed on every chunk, so an actively writing descendant keeps
20
29
  * us reading, while a quiet inherited handle (e.g. a Windows daemonized descendant
21
30
  * that never lets `close` fire) still releases us after the grace elapses.
31
+ *
32
+ * Resolves the exit code, or `128 + signal number` when the child was killed by a
33
+ * signal (e.g. the OOM killer) and therefore has no exit code of its own.
22
34
  */
23
- export function waitForChildProcess(child) {
35
+ export function waitForChildProcess(child, options = {}) {
36
+ const graceMs = options.exitStdioGraceMs ?? EXIT_STDIO_GRACE_MS;
24
37
  return new Promise((resolve, reject) => {
25
38
  let settled = false;
26
39
  let exited = false;
27
40
  let exitCode = null;
41
+ let exitSignal = null;
28
42
  let postExitTimer;
29
43
  let stdoutEnded = child.stdout === null;
30
44
  let stderrEnded = child.stderr === null;
@@ -41,26 +55,26 @@ export function waitForChildProcess(child) {
41
55
  child.stdout?.removeListener("data", onData);
42
56
  child.stderr?.removeListener("data", onData);
43
57
  };
44
- const finalize = (code) => {
58
+ const finalize = () => {
45
59
  if (settled)
46
60
  return;
47
61
  settled = true;
48
62
  cleanup();
49
63
  child.stdout?.destroy();
50
64
  child.stderr?.destroy();
51
- resolve(code);
65
+ resolve(exitCode ?? (exitSignal ? exitCodeForSignal(exitSignal) : null));
52
66
  };
53
67
  const maybeFinalizeAfterExit = () => {
54
68
  if (!exited || settled)
55
69
  return;
56
70
  if (stdoutEnded && stderrEnded) {
57
- finalize(exitCode);
71
+ finalize();
58
72
  }
59
73
  };
60
74
  const armIdleTimer = () => {
61
75
  if (postExitTimer)
62
76
  clearTimeout(postExitTimer);
63
- postExitTimer = setTimeout(() => finalize(exitCode), EXIT_STDIO_GRACE_MS);
77
+ postExitTimer = setTimeout(() => finalize(), graceMs);
64
78
  };
65
79
  const onData = () => {
66
80
  // Output is still arriving after exit; defer finalizing so we don't
@@ -83,16 +97,19 @@ export function waitForChildProcess(child) {
83
97
  cleanup();
84
98
  reject(err);
85
99
  };
86
- const onExit = (code) => {
100
+ const onExit = (code, signal) => {
87
101
  exited = true;
88
102
  exitCode = code;
103
+ exitSignal = signal;
89
104
  maybeFinalizeAfterExit();
90
105
  if (!settled) {
91
106
  armIdleTimer();
92
107
  }
93
108
  };
94
- const onClose = (code) => {
95
- finalize(code);
109
+ const onClose = (code, signal) => {
110
+ exitCode = code;
111
+ exitSignal = signal;
112
+ finalize();
96
113
  };
97
114
  child.stdout?.once("end", onStdoutEnd);
98
115
  child.stderr?.once("end", onStderrEnd);