@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,158 @@
1
+ /**
2
+ * Real-path resolution for sandbox policy paths (R44-SBX.3).
3
+ *
4
+ * Every path that reaches a sandbox profile must first become the path the
5
+ * *kernel* sees, not the path a string spells. This is a security property, not
6
+ * tidiness: the write allowlist is the whole policy, so anything that lets one
7
+ * string name two different places lets the allowlist be widened silently.
8
+ *
9
+ * Two such mechanisms exist, and both are handled here:
10
+ *
11
+ * 1. **Symlinks.** A link inside the project pointing outside it (`<project>/link
12
+ * -> /somewhere/else`) makes `<project>/link/x` pass any `startsWith(project)`
13
+ * check while actually writing to `/somewhere/else/x`.
14
+ * 2. **`..` traversal.** `..` is *not* a lexical operation once symlinks are in
15
+ * play: `<project>/link/../x` is `/somewhere/x`, not `<project>/x`. Node's
16
+ * `path.join`/`path.resolve` collapse `..` lexically and would therefore
17
+ * produce exactly the wrong answer, so this module deliberately never uses
18
+ * them to build the path it resolves.
19
+ *
20
+ * ## Why `..` is walked here instead of being handed to `realpath(3)`
21
+ *
22
+ * The obvious implementation -- hand the raw spelling to `realpathSync.native`
23
+ * and let the OS walk it -- is **not portable, and the runtime it is wrong on is
24
+ * the one that ships**. Measured, same machine, same fixture
25
+ * (`<project>/link -> <outside>/sub`):
26
+ *
27
+ * | call | node 26 | bun 1.4 |
28
+ * |-----------------------------------------------|---------|------------|
29
+ * | `realpathSync(<project>/link/..)` | `<project>` (lexical, wrong) | `<project>` (lexical, wrong) |
30
+ * | `realpathSync.native(<project>/link/..)` | `<outside>` (POSIX, right) | `<project>` (lexical, **wrong**) |
31
+ *
32
+ * Bun's `realpathSync.native` collapses `..` lexically before resolving, exactly
33
+ * like the JS variant. The released `draht` binaries are built with `bun build
34
+ * --compile` (see `packages/coding-agent` `build:binary`), so delegating `..` to
35
+ * the OS would have meant `isPathWritable()` answering **true** for
36
+ * `<project>/link/../evil.txt` in every shipped binary -- a path the kernel
37
+ * writes to `<outside>/evil.txt`, outside the allowlist. That is R44-SBX.3
38
+ * defeated by the very call that was supposed to enforce it.
39
+ *
40
+ * So the guarantee this module actually makes, and the one the walk below
41
+ * implements, is:
42
+ *
43
+ * > `..` is never passed to the platform's `realpath`. The path is walked one
44
+ * > segment at a time by the shared `resolveRealSegment` primitive
45
+ * > (`src/utils/canonical-path.ts`) against an already fully-resolved prefix (a
46
+ * > single name, no `..`, so both runtimes agree and symlink chasing, `ELOOP` and
47
+ * > permission checks stay in the kernel); each `..` is applied to that resolved
48
+ * > prefix, which is where POSIX says it applies.
49
+ *
50
+ * That primitive also carries bun's second divergence — a backslash in a name is
51
+ * rewritten to `/` before the syscall, so `<dir>/a\b` resolves to a *different* real
52
+ * directory, one the kernel will never traverse for that spelling.
53
+ *
54
+ * `test/sandbox-real-path-runtime.test.ts` executes the same assertions under
55
+ * **both** node and bun and fails if the two disagree, so this claim is checked
56
+ * against the runtime that ships rather than only the one the tests run in.
57
+ *
58
+ * ## Paths that do not exist yet
59
+ *
60
+ * A configured write path may legitimately not exist yet (a build output dir, a
61
+ * cache root on a fresh machine). `realpath(3)` fails on those, and guessing is
62
+ * how allowlists get widened by accident. The rule here:
63
+ *
64
+ * - Resolve every segment that *does* exist (so no symlink anywhere in the
65
+ * existing prefix can widen anything).
66
+ * - Re-attach the remaining segments literally, since they name nothing yet.
67
+ * - If any remaining segment is `..`, **refuse**: `..` below a non-existent
68
+ * directory has no determinable target (it depends on what that directory
69
+ * turns out to be when created), and inventing one is precisely the silent
70
+ * widening this requirement forbids.
71
+ *
72
+ * The resolved leaf is only an *ancestor* guarantee -- someone could later create
73
+ * that leaf as a symlink pointing elsewhere. That is why `isPathWritable`
74
+ * (see `policy.ts`) re-resolves the candidate at check time rather than trusting
75
+ * the stored string, and why the kernel backends, not this module, are the
76
+ * enforcement boundary.
77
+ */
78
+ import { dirname, isAbsolute, join, sep } from "node:path";
79
+ import { resolveRealSegment } from "../../utils/canonical-path.js";
80
+ /** Joins without `path.join`'s lexical `..` collapsing (see module doc). */
81
+ function joinRaw(base, input) {
82
+ const trimmedBase = base.length > 1 && base.endsWith(sep) ? base.slice(0, -1) : base;
83
+ return `${trimmedBase}${sep}${input}`;
84
+ }
85
+ /**
86
+ * Resolves `input` to a real, absolute path. Never throws -- failures come back
87
+ * as `{ ok: false, reason }` so callers can drop the entry (narrowing the
88
+ * writable set) instead of falling back to an unresolved spelling.
89
+ */
90
+ export function resolveRealPath(input, options) {
91
+ if (input.trim() === "") {
92
+ return { ok: false, input, reason: "path is empty" };
93
+ }
94
+ if (!isAbsolute(options.base)) {
95
+ return { ok: false, input, reason: `base directory must be absolute, got ${JSON.stringify(options.base)}` };
96
+ }
97
+ const absolute = isAbsolute(input) ? input : joinRaw(options.base, input);
98
+ // Split on the separator ourselves rather than letting `realpath` see the
99
+ // whole spelling: this is the single line that makes the module's guarantee
100
+ // independent of how the host runtime chose to implement `..`.
101
+ const segments = absolute.split(sep);
102
+ /** Always fully symlink-resolved, so `..` against it is plain `dirname`. */
103
+ let resolved = sep;
104
+ /** Segments below the deepest existing directory. They name nothing yet. */
105
+ const pending = [];
106
+ for (const segment of segments) {
107
+ if (segment === "" || segment === ".")
108
+ continue;
109
+ if (pending.length > 0) {
110
+ if (segment === "..") {
111
+ return {
112
+ ok: false,
113
+ input,
114
+ reason: `refusing to resolve ${JSON.stringify(input)}: ".." appears below ${JSON.stringify(resolved)}, the deepest part of the path that exists, so its real target cannot be determined without guessing`,
115
+ };
116
+ }
117
+ pending.push(segment);
118
+ continue;
119
+ }
120
+ if (segment === "..") {
121
+ // `resolved` contains no symlink component, so its parent directory is
122
+ // its lexical parent -- which is exactly what POSIX `..` means here.
123
+ // `dirname("/")` is `"/"`, matching the kernel's `/.. == /`.
124
+ resolved = dirname(resolved);
125
+ continue;
126
+ }
127
+ // One plain name against a resolved prefix, so nothing is left for a runtime to
128
+ // collapse. Anything but ENOENT is "we cannot know what this names".
129
+ const step = resolveRealSegment(resolved, segment);
130
+ if (step.ok) {
131
+ resolved = step.path;
132
+ }
133
+ else if (step.missing) {
134
+ pending.push(segment);
135
+ }
136
+ else {
137
+ return { ok: false, input, reason: `cannot resolve ${JSON.stringify(input)}: ${step.reason}` };
138
+ }
139
+ }
140
+ const path = pending.length > 0 ? join(resolved, ...pending) : resolved;
141
+ return { ok: true, input, path, existed: pending.length === 0 };
142
+ }
143
+ /**
144
+ * True when `candidate` is `root` itself or lies underneath it. Both arguments
145
+ * must already be real paths -- this is a pure string comparison and makes no
146
+ * claim about symlinks; resolve first.
147
+ *
148
+ * Comparison is exact-case. On case-sensitive filesystems that is correct; on a
149
+ * case-insensitive one (default APFS/HFS+) it is stricter than the kernel, which
150
+ * can only produce a false "not contained", never a false "contained".
151
+ */
152
+ export function isContainedIn(candidate, root) {
153
+ if (candidate === root)
154
+ return true;
155
+ const prefix = root.endsWith(sep) ? root : `${root}${sep}`;
156
+ return candidate.startsWith(prefix);
157
+ }
158
+ //# sourceMappingURL=real-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"real-path.js","sourceRoot":"","sources":["../../../src/core/sandbox/real-path.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Real-path resolution for sandbox policy paths (R44-SBX.3).\n *\n * Every path that reaches a sandbox profile must first become the path the\n * *kernel* sees, not the path a string spells. This is a security property, not\n * tidiness: the write allowlist is the whole policy, so anything that lets one\n * string name two different places lets the allowlist be widened silently.\n *\n * Two such mechanisms exist, and both are handled here:\n *\n * 1. **Symlinks.** A link inside the project pointing outside it (`<project>/link\n * -> /somewhere/else`) makes `<project>/link/x` pass any `startsWith(project)`\n * check while actually writing to `/somewhere/else/x`.\n * 2. **`..` traversal.** `..` is *not* a lexical operation once symlinks are in\n * play: `<project>/link/../x` is `/somewhere/x`, not `<project>/x`. Node's\n * `path.join`/`path.resolve` collapse `..` lexically and would therefore\n * produce exactly the wrong answer, so this module deliberately never uses\n * them to build the path it resolves.\n *\n * ## Why `..` is walked here instead of being handed to `realpath(3)`\n *\n * The obvious implementation -- hand the raw spelling to `realpathSync.native`\n * and let the OS walk it -- is **not portable, and the runtime it is wrong on is\n * the one that ships**. Measured, same machine, same fixture\n * (`<project>/link -> <outside>/sub`):\n *\n * | call | node 26 | bun 1.4 |\n * |-----------------------------------------------|---------|------------|\n * | `realpathSync(<project>/link/..)` | `<project>` (lexical, wrong) | `<project>` (lexical, wrong) |\n * | `realpathSync.native(<project>/link/..)` | `<outside>` (POSIX, right) | `<project>` (lexical, **wrong**) |\n *\n * Bun's `realpathSync.native` collapses `..` lexically before resolving, exactly\n * like the JS variant. The released `draht` binaries are built with `bun build\n * --compile` (see `packages/coding-agent` `build:binary`), so delegating `..` to\n * the OS would have meant `isPathWritable()` answering **true** for\n * `<project>/link/../evil.txt` in every shipped binary -- a path the kernel\n * writes to `<outside>/evil.txt`, outside the allowlist. That is R44-SBX.3\n * defeated by the very call that was supposed to enforce it.\n *\n * So the guarantee this module actually makes, and the one the walk below\n * implements, is:\n *\n * > `..` is never passed to the platform's `realpath`. The path is walked one\n * > segment at a time by the shared `resolveRealSegment` primitive\n * > (`src/utils/canonical-path.ts`) against an already fully-resolved prefix (a\n * > single name, no `..`, so both runtimes agree and symlink chasing, `ELOOP` and\n * > permission checks stay in the kernel); each `..` is applied to that resolved\n * > prefix, which is where POSIX says it applies.\n *\n * That primitive also carries bun's second divergence — a backslash in a name is\n * rewritten to `/` before the syscall, so `<dir>/a\\b` resolves to a *different* real\n * directory, one the kernel will never traverse for that spelling.\n *\n * `test/sandbox-real-path-runtime.test.ts` executes the same assertions under\n * **both** node and bun and fails if the two disagree, so this claim is checked\n * against the runtime that ships rather than only the one the tests run in.\n *\n * ## Paths that do not exist yet\n *\n * A configured write path may legitimately not exist yet (a build output dir, a\n * cache root on a fresh machine). `realpath(3)` fails on those, and guessing is\n * how allowlists get widened by accident. The rule here:\n *\n * - Resolve every segment that *does* exist (so no symlink anywhere in the\n * existing prefix can widen anything).\n * - Re-attach the remaining segments literally, since they name nothing yet.\n * - If any remaining segment is `..`, **refuse**: `..` below a non-existent\n * directory has no determinable target (it depends on what that directory\n * turns out to be when created), and inventing one is precisely the silent\n * widening this requirement forbids.\n *\n * The resolved leaf is only an *ancestor* guarantee -- someone could later create\n * that leaf as a symlink pointing elsewhere. That is why `isPathWritable`\n * (see `policy.ts`) re-resolves the candidate at check time rather than trusting\n * the stored string, and why the kernel backends, not this module, are the\n * enforcement boundary.\n */\n\nimport { dirname, isAbsolute, join, sep } from \"node:path\";\nimport { resolveRealSegment } from \"../../utils/canonical-path.ts\";\n\nexport interface ResolveRealPathOptions {\n\t/** Absolute directory that relative inputs resolve against (normally the project cwd). */\n\tbase: string;\n}\n\nexport type RealPathResolution =\n\t| {\n\t\t\treadonly ok: true;\n\t\t\t/** The path as given. */\n\t\t\treadonly input: string;\n\t\t\t/** Absolute, fully symlink-resolved path. Contains no `.` or `..` segments. */\n\t\t\treadonly path: string;\n\t\t\t/** True when the whole path already existed; false when only its ancestor did. */\n\t\t\treadonly existed: boolean;\n\t }\n\t| {\n\t\t\treadonly ok: false;\n\t\t\treadonly input: string;\n\t\t\t/** Human-readable explanation, safe to surface in diagnostics. */\n\t\t\treadonly reason: string;\n\t };\n\n/** Joins without `path.join`'s lexical `..` collapsing (see module doc). */\nfunction joinRaw(base: string, input: string): string {\n\tconst trimmedBase = base.length > 1 && base.endsWith(sep) ? base.slice(0, -1) : base;\n\treturn `${trimmedBase}${sep}${input}`;\n}\n\n/**\n * Resolves `input` to a real, absolute path. Never throws -- failures come back\n * as `{ ok: false, reason }` so callers can drop the entry (narrowing the\n * writable set) instead of falling back to an unresolved spelling.\n */\nexport function resolveRealPath(input: string, options: ResolveRealPathOptions): RealPathResolution {\n\tif (input.trim() === \"\") {\n\t\treturn { ok: false, input, reason: \"path is empty\" };\n\t}\n\tif (!isAbsolute(options.base)) {\n\t\treturn { ok: false, input, reason: `base directory must be absolute, got ${JSON.stringify(options.base)}` };\n\t}\n\n\tconst absolute = isAbsolute(input) ? input : joinRaw(options.base, input);\n\n\t// Split on the separator ourselves rather than letting `realpath` see the\n\t// whole spelling: this is the single line that makes the module's guarantee\n\t// independent of how the host runtime chose to implement `..`.\n\tconst segments = absolute.split(sep);\n\t/** Always fully symlink-resolved, so `..` against it is plain `dirname`. */\n\tlet resolved: string = sep;\n\t/** Segments below the deepest existing directory. They name nothing yet. */\n\tconst pending: string[] = [];\n\n\tfor (const segment of segments) {\n\t\tif (segment === \"\" || segment === \".\") continue;\n\n\t\tif (pending.length > 0) {\n\t\t\tif (segment === \"..\") {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\tinput,\n\t\t\t\t\treason: `refusing to resolve ${JSON.stringify(input)}: \"..\" appears below ${JSON.stringify(\n\t\t\t\t\t\tresolved,\n\t\t\t\t\t)}, the deepest part of the path that exists, so its real target cannot be determined without guessing`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tpending.push(segment);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (segment === \"..\") {\n\t\t\t// `resolved` contains no symlink component, so its parent directory is\n\t\t\t// its lexical parent -- which is exactly what POSIX `..` means here.\n\t\t\t// `dirname(\"/\")` is `\"/\"`, matching the kernel's `/.. == /`.\n\t\t\tresolved = dirname(resolved);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// One plain name against a resolved prefix, so nothing is left for a runtime to\n\t\t// collapse. Anything but ENOENT is \"we cannot know what this names\".\n\t\tconst step = resolveRealSegment(resolved, segment);\n\t\tif (step.ok) {\n\t\t\tresolved = step.path;\n\t\t} else if (step.missing) {\n\t\t\tpending.push(segment);\n\t\t} else {\n\t\t\treturn { ok: false, input, reason: `cannot resolve ${JSON.stringify(input)}: ${step.reason}` };\n\t\t}\n\t}\n\n\tconst path = pending.length > 0 ? join(resolved, ...pending) : resolved;\n\treturn { ok: true, input, path, existed: pending.length === 0 };\n}\n\n/**\n * True when `candidate` is `root` itself or lies underneath it. Both arguments\n * must already be real paths -- this is a pure string comparison and makes no\n * claim about symlinks; resolve first.\n *\n * Comparison is exact-case. On case-sensitive filesystems that is correct; on a\n * case-insensitive one (default APFS/HFS+) it is stricter than the kernel, which\n * can only produce a false \"not contained\", never a false \"contained\".\n */\nexport function isContainedIn(candidate: string, root: string): boolean {\n\tif (candidate === root) return true;\n\tconst prefix = root.endsWith(sep) ? root : `${root}${sep}`;\n\treturn candidate.startsWith(prefix);\n}\n"]}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * SBPL (Seatbelt) profile generation from a `SandboxPolicy` (R44-SBX.1, macOS).
3
+ *
4
+ * Pure string building, deliberately separated from the backend that spawns
5
+ * `sandbox-exec`, so the exact bytes handed to the kernel are directly testable
6
+ * and diffable without running anything.
7
+ *
8
+ * ## The profile is an allow-list. It used to be a deny-list, and that was a bug
9
+ *
10
+ * Phase 44 shipped `(allow default)` plus targeted denies, on the argument that
11
+ * "an enumerable allowlist of everything a compiler touches does not exist". The
12
+ * argument is wrong, and two independent reviews proved it wrong with working
13
+ * escapes. A deny-list sandbox grants every capability nobody thought to
14
+ * enumerate, and on macOS the capabilities nobody enumerated included:
15
+ *
16
+ * - **`mach-lookup` to LaunchServices.** `open -a Calculator` inside the sandbox
17
+ * made launchd start Calculator *outside* it. Reproduced: an app bundle whose
18
+ * executable wrote to a path outside the write allowlist, launched via `open`,
19
+ * and the file appeared. The write allowlist and the network toggle are both
20
+ * irrelevant once you can ask launchd to run a program for you.
21
+ * - **`mach-priv-task-port`.** `lldb -p <pid>` inside the sandbox attached to an
22
+ * unsandboxed same-uid process and ran `expr (int)system("echo ... > outside")`
23
+ * in it. Reproduced with the network off.
24
+ * - **Unix-domain sockets.** A sandboxed process connected to the socket of an
25
+ * already-running unsandboxed daemon and injected a payload into it.
26
+ * - **Every pty on the machine**, via `(regex #"^/dev/ttys[0-9]*$")`, so a
27
+ * confined process could write a fake prompt into an unrelated terminal.
28
+ *
29
+ * So the shape is now the one Phase 28 used for the RLM REPL
30
+ * (`packages/rlm/sandbox/macos.sb`):
31
+ *
32
+ * (deny default) ; nothing, unless named below
33
+ * (allow <one capability at a time>) ; each with a reason it is here
34
+ * (deny <the escape routes>) ; restating intent where it matters
35
+ *
36
+ * The enumeration turned out to be small: **thirteen** capability allows, plus a
37
+ * network section of five, cover `bash`, `python3`, `node`, `git`, `npm`, `make`,
38
+ * `clang`, `curl`, `tar`, `sqlite3`, `openssl`, python `venv` and
39
+ * `multiprocessing`, node worker threads, and local HTTP servers. Each one below
40
+ * is here because a specific command failed without it, and the comment says
41
+ * which. Nothing is here "to be safe".
42
+ *
43
+ * ## Rules for changing this file
44
+ *
45
+ * 1. An allow needs a one-sentence justification naming what breaks without it.
46
+ * 2. Reach for the narrowest filter that works -- `(global-name "...")` over a
47
+ * bare `(allow mach-lookup)`, a `(literal "...")` over a `(subpath "...")`.
48
+ * 3. Verify the narrowing, do not assume it. `com.apple.system.notification_center`
49
+ * was in an earlier draft of this list and is not here now, because testing
50
+ * showed `com.apple.system.opendirectoryd.libinfo` alone was sufficient.
51
+ * 4. Every capability an escape used gets an explicit `(deny ...)` even though
52
+ * `(deny default)` already covers it, so the next reader can see the intent
53
+ * rather than having to re-derive it from an absence.
54
+ *
55
+ * ## Properties verified empirically on macOS 26.5 (darwin 25.5), not assumed
56
+ *
57
+ * - A write outside the allowlist fails with `EPERM`, whether spelled directly,
58
+ * reached through a symlink whose *link* sits inside an allowed directory, or
59
+ * performed by an interpreter. Seatbelt checks the resolved vnode, so the
60
+ * symlink case needs no rule of its own.
61
+ * - `(deny network*)` blocks a loopback TCP connect (`EPERM`, not a refused
62
+ * connection), which is what makes the R44-SBX.4 network probe meaningful.
63
+ * - **Privilege escalation is impossible by construction**: exec of a setuid
64
+ * binary is refused for *any* sandboxed process, so `sudo` fails at exec time
65
+ * regardless of the rules below. The explicit denies are a statement of intent.
66
+ * - A sandboxed process cannot re-enter `sandbox-exec` with a looser profile:
67
+ * the nested `sandbox_apply` fails with `EPERM`. Profiles compose by
68
+ * intersection and are inherited across `exec`.
69
+ *
70
+ * ## Untrusted strings in a profile
71
+ *
72
+ * `writePaths` can contain user-configured directories (`extraWritePaths` from
73
+ * settings). A path containing `"` would close the SBPL string literal early and
74
+ * let the rest of the path be parsed as profile source -- `(allow default)`
75
+ * smuggled in through a directory name. Backslash and quote are escaped;
76
+ * anything that cannot be represented at all (control characters, newlines)
77
+ * makes generation **throw**, which the backend turns into `unavailable`. A path
78
+ * we cannot render exactly is never rendered approximately.
79
+ */
80
+ import type { SandboxPolicy } from "./policy.ts";
81
+ /** Thrown when a policy cannot be rendered into a profile exactly. Backends turn this into `unavailable`. */
82
+ export declare class SandboxProfileError extends Error {
83
+ constructor(message: string);
84
+ }
85
+ /**
86
+ * Renders `value` as an SBPL string literal.
87
+ *
88
+ * Escapes what SBPL can escape and refuses what it cannot, rather than dropping
89
+ * or substituting characters -- a path rendered as something other than itself
90
+ * is a policy that does not match the policy that was reviewed.
91
+ */
92
+ export declare function quoteSbplString(value: string): string;
93
+ /** Generates the SBPL profile text for `policy`. Deterministic: same policy, same bytes. */
94
+ export declare function buildSeatbeltProfile(policy: SandboxPolicy): string;
95
+ //# sourceMappingURL=seatbelt-profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seatbelt-profile.d.ts","sourceRoot":"","sources":["../../../src/core/sandbox/seatbelt-profile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,6GAA6G;AAC7G,qBAAa,mBAAoB,SAAQ,KAAK;IAC7C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAyCD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAarD;AAED,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CA0KlE"}
@@ -0,0 +1,239 @@
1
+ /**
2
+ * SBPL (Seatbelt) profile generation from a `SandboxPolicy` (R44-SBX.1, macOS).
3
+ *
4
+ * Pure string building, deliberately separated from the backend that spawns
5
+ * `sandbox-exec`, so the exact bytes handed to the kernel are directly testable
6
+ * and diffable without running anything.
7
+ *
8
+ * ## The profile is an allow-list. It used to be a deny-list, and that was a bug
9
+ *
10
+ * Phase 44 shipped `(allow default)` plus targeted denies, on the argument that
11
+ * "an enumerable allowlist of everything a compiler touches does not exist". The
12
+ * argument is wrong, and two independent reviews proved it wrong with working
13
+ * escapes. A deny-list sandbox grants every capability nobody thought to
14
+ * enumerate, and on macOS the capabilities nobody enumerated included:
15
+ *
16
+ * - **`mach-lookup` to LaunchServices.** `open -a Calculator` inside the sandbox
17
+ * made launchd start Calculator *outside* it. Reproduced: an app bundle whose
18
+ * executable wrote to a path outside the write allowlist, launched via `open`,
19
+ * and the file appeared. The write allowlist and the network toggle are both
20
+ * irrelevant once you can ask launchd to run a program for you.
21
+ * - **`mach-priv-task-port`.** `lldb -p <pid>` inside the sandbox attached to an
22
+ * unsandboxed same-uid process and ran `expr (int)system("echo ... > outside")`
23
+ * in it. Reproduced with the network off.
24
+ * - **Unix-domain sockets.** A sandboxed process connected to the socket of an
25
+ * already-running unsandboxed daemon and injected a payload into it.
26
+ * - **Every pty on the machine**, via `(regex #"^/dev/ttys[0-9]*$")`, so a
27
+ * confined process could write a fake prompt into an unrelated terminal.
28
+ *
29
+ * So the shape is now the one Phase 28 used for the RLM REPL
30
+ * (`packages/rlm/sandbox/macos.sb`):
31
+ *
32
+ * (deny default) ; nothing, unless named below
33
+ * (allow <one capability at a time>) ; each with a reason it is here
34
+ * (deny <the escape routes>) ; restating intent where it matters
35
+ *
36
+ * The enumeration turned out to be small: **thirteen** capability allows, plus a
37
+ * network section of five, cover `bash`, `python3`, `node`, `git`, `npm`, `make`,
38
+ * `clang`, `curl`, `tar`, `sqlite3`, `openssl`, python `venv` and
39
+ * `multiprocessing`, node worker threads, and local HTTP servers. Each one below
40
+ * is here because a specific command failed without it, and the comment says
41
+ * which. Nothing is here "to be safe".
42
+ *
43
+ * ## Rules for changing this file
44
+ *
45
+ * 1. An allow needs a one-sentence justification naming what breaks without it.
46
+ * 2. Reach for the narrowest filter that works -- `(global-name "...")` over a
47
+ * bare `(allow mach-lookup)`, a `(literal "...")` over a `(subpath "...")`.
48
+ * 3. Verify the narrowing, do not assume it. `com.apple.system.notification_center`
49
+ * was in an earlier draft of this list and is not here now, because testing
50
+ * showed `com.apple.system.opendirectoryd.libinfo` alone was sufficient.
51
+ * 4. Every capability an escape used gets an explicit `(deny ...)` even though
52
+ * `(deny default)` already covers it, so the next reader can see the intent
53
+ * rather than having to re-derive it from an absence.
54
+ *
55
+ * ## Properties verified empirically on macOS 26.5 (darwin 25.5), not assumed
56
+ *
57
+ * - A write outside the allowlist fails with `EPERM`, whether spelled directly,
58
+ * reached through a symlink whose *link* sits inside an allowed directory, or
59
+ * performed by an interpreter. Seatbelt checks the resolved vnode, so the
60
+ * symlink case needs no rule of its own.
61
+ * - `(deny network*)` blocks a loopback TCP connect (`EPERM`, not a refused
62
+ * connection), which is what makes the R44-SBX.4 network probe meaningful.
63
+ * - **Privilege escalation is impossible by construction**: exec of a setuid
64
+ * binary is refused for *any* sandboxed process, so `sudo` fails at exec time
65
+ * regardless of the rules below. The explicit denies are a statement of intent.
66
+ * - A sandboxed process cannot re-enter `sandbox-exec` with a looser profile:
67
+ * the nested `sandbox_apply` fails with `EPERM`. Profiles compose by
68
+ * intersection and are inherited across `exec`.
69
+ *
70
+ * ## Untrusted strings in a profile
71
+ *
72
+ * `writePaths` can contain user-configured directories (`extraWritePaths` from
73
+ * settings). A path containing `"` would close the SBPL string literal early and
74
+ * let the rest of the path be parsed as profile source -- `(allow default)`
75
+ * smuggled in through a directory name. Backslash and quote are escaped;
76
+ * anything that cannot be represented at all (control characters, newlines)
77
+ * makes generation **throw**, which the backend turns into `unavailable`. A path
78
+ * we cannot render exactly is never rendered approximately.
79
+ */
80
+ /** Thrown when a policy cannot be rendered into a profile exactly. Backends turn this into `unavailable`. */
81
+ export class SandboxProfileError extends Error {
82
+ constructor(message) {
83
+ super(message);
84
+ this.name = "SandboxProfileError";
85
+ }
86
+ }
87
+ /**
88
+ * Device nodes a shell and its children need to write to in order to behave at
89
+ * all: `/dev/null` redirects, `/dev/fd` process substitution, pty allocation.
90
+ * None of these is filesystem persistence, so allowing them does not widen what
91
+ * the policy is about.
92
+ *
93
+ * `/dev/tty` is the per-process alias for the *controlling* terminal, so it can
94
+ * only ever reach the child's own terminal -- unlike the machine-wide
95
+ * `/dev/ttys*` regex this list used to carry, which is now the extension-gated
96
+ * pty rule in `buildSeatbeltProfile`.
97
+ */
98
+ const DEVICE_WRITE_RULES = [
99
+ '(literal "/dev/null")',
100
+ '(literal "/dev/zero")',
101
+ '(literal "/dev/random")',
102
+ '(literal "/dev/urandom")',
103
+ '(literal "/dev/stdin")',
104
+ '(literal "/dev/stdout")',
105
+ '(literal "/dev/stderr")',
106
+ '(literal "/dev/tty")',
107
+ '(literal "/dev/ptmx")',
108
+ '(subpath "/dev/fd")',
109
+ ];
110
+ /**
111
+ * Binaries whose entire purpose is to acquire another user's privileges. Denying
112
+ * exec of them states the invariant in the profile itself; the kernel's refusal
113
+ * to exec setuid binaries inside any sandbox is what actually enforces it.
114
+ */
115
+ const PRIVILEGE_ESCALATION_BINARIES = ["/usr/bin/sudo", "/usr/bin/su", "/usr/bin/sudoedit", "/usr/bin/login"];
116
+ /**
117
+ * The system resolver's socket. `getaddrinfo` on macOS reaches mDNSResponder
118
+ * through this unix socket, so without it every hostname fails to resolve even
119
+ * with IP networking fully allowed (measured: `curl` reports
120
+ * "Could not resolve host", `node` reports `ENOTFOUND`).
121
+ */
122
+ const DNS_RESOLVER_SOCKET = "/private/var/run/mDNSResponder";
123
+ /**
124
+ * Renders `value` as an SBPL string literal.
125
+ *
126
+ * Escapes what SBPL can escape and refuses what it cannot, rather than dropping
127
+ * or substituting characters -- a path rendered as something other than itself
128
+ * is a policy that does not match the policy that was reviewed.
129
+ */
130
+ export function quoteSbplString(value) {
131
+ for (const char of value) {
132
+ const code = char.codePointAt(0) ?? 0;
133
+ if (code < 0x20 || code === 0x7f) {
134
+ throw new SandboxProfileError(`cannot render path ${JSON.stringify(value)} into a sandbox profile: it contains a control character (U+${code
135
+ .toString(16)
136
+ .padStart(4, "0")
137
+ .toUpperCase()}) that SBPL string literals cannot represent`);
138
+ }
139
+ }
140
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
141
+ }
142
+ /** Generates the SBPL profile text for `policy`. Deterministic: same policy, same bytes. */
143
+ export function buildSeatbeltProfile(policy) {
144
+ if (policy.writePaths.length === 0) {
145
+ // Every backend needs somewhere to write (the shell's own tmp, at minimum),
146
+ // and an empty allowlist almost always means policy resolution silently
147
+ // dropped everything. Refusing surfaces that as `unavailable`.
148
+ throw new SandboxProfileError("cannot render a sandbox profile: the write allowlist is empty");
149
+ }
150
+ for (const path of policy.writePaths) {
151
+ if (path === "/") {
152
+ throw new SandboxProfileError("cannot render a sandbox profile: the write allowlist contains the filesystem root, which would confine nothing");
153
+ }
154
+ }
155
+ const writeSubpaths = policy.writePaths.map((path) => `(subpath ${quoteSbplString(path)})`).join(" ");
156
+ const lines = [
157
+ "(version 1)",
158
+ "",
159
+ ";; Generated from SandboxPolicy v1 by src/core/sandbox/seatbelt-profile.ts.",
160
+ ";; Do not edit by hand. Every allow below names the thing that breaks without it.",
161
+ "",
162
+ ";; ---------------------------------------------------------------------------",
163
+ ";; Deny by default. A capability nobody enumerated is a capability nobody",
164
+ ";; reviewed; the previous `(allow default)` shape left launchd, the debugger",
165
+ ";; interface and unix sockets open, each of which is a complete escape.",
166
+ ";; ---------------------------------------------------------------------------",
167
+ "(deny default)",
168
+ "",
169
+ ";; --- what running a developer command actually requires -------------------",
170
+ "",
171
+ ";; Running arbitrary binaries is the bash tool's entire purpose; confinement",
172
+ ";; here is over what those binaries may write and reach, not over which of",
173
+ ";; them exist. (Without it nothing runs at all: even `/bin/sh` fails to exec.)",
174
+ "(allow process-exec*)",
175
+ "",
176
+ ";; Every pipeline, subshell, `$(...)` and parallel build forks.",
177
+ "(allow process-fork)",
178
+ "",
179
+ ";; R44-SBX.2: v1 is read allow-all. Dev workflows read toolchains, caches and",
180
+ ";; dotfiles constantly, and a read-deny list is a v2 concern.",
181
+ "(allow file-read*)",
182
+ "",
183
+ ";; The policy: only these subtrees are writable. Seatbelt matches the resolved",
184
+ ";; vnode, so a symlink pointing out of one of these does not widen it.",
185
+ `(allow file-write* ${writeSubpaths})`,
186
+ "",
187
+ ";; Device nodes a shell needs to function. Not filesystem persistence.",
188
+ `(allow file-write* ${DEVICE_WRITE_RULES.join(" ")})`,
189
+ "",
190
+ ";; A pty the process allocates for itself (`script`, `node-pty`, `python -m pty`,",
191
+ ";; anything that wants a tty for a child). `pseudo-tty` issues the sandbox",
192
+ ";; extension that the following rule requires, so this grants the child *its",
193
+ ';; own* terminal and no other: the machine-wide `(regex #"^/dev/ttys[0-9]*$")`',
194
+ ";; this replaces let a confined process write a forged prompt into somebody",
195
+ ";; else's terminal. Idiom taken from Apple's own application.sb.",
196
+ "(allow pseudo-tty)",
197
+ '(allow file-read* file-write* (require-all (regex #"^/dev/ttys[0-9]*$") (extension "com.apple.sandbox.pty")))',
198
+ "",
199
+ ";; `isatty`, terminal size, and the termios calls every interactive-ish tool",
200
+ ";; makes on descriptors it has already opened.",
201
+ "(allow file-ioctl)",
202
+ "",
203
+ ";; `hw.ncpu`, `kern.osversion` and friends: node, python and make read these",
204
+ ";; during startup (`os.cpus()`, `sysctl -n hw.ncpu`, `uname -a`).",
205
+ "(allow sysctl-read)",
206
+ "",
207
+ ";; Job control over the command's own process tree -- `kill %1`, `make` killing",
208
+ ";; a stuck child, `trap`. `(target same-sandbox)` stops there: without the",
209
+ ";; filter a confined command can SIGKILL the agent that launched it (verified:",
210
+ ";; it could, under the old profile).",
211
+ "(allow signal (target same-sandbox))",
212
+ "",
213
+ ";; POSIX semaphores: `multiprocessing.Pool` fails with EPERM in `sem_unlink`",
214
+ ";; without this, which takes out most parallel Python.",
215
+ "(allow ipc-posix-sem)",
216
+ "",
217
+ ";; POSIX shared memory: `multiprocessing.shared_memory` and the data-science",
218
+ ";; stacks layered on it. A memory-object namespace -- no filesystem, exec or",
219
+ ";; network reach comes with it.",
220
+ "(allow ipc-posix-shm)",
221
+ "",
222
+ ";; User and group lookup (`getpwuid`). Without it `id -un` and `whoami` print",
223
+ ";; a bare uid, `os.userInfo()` throws ENOENT, and git cannot name an author.",
224
+ ";; One service, by name: a bare `(allow mach-lookup)` is what put LaunchServices",
225
+ ";; -- and therefore launchd -- back in reach.",
226
+ '(allow mach-lookup (global-name "com.apple.system.opendirectoryd.libinfo"))',
227
+ "",
228
+ ];
229
+ if (policy.network === "on") {
230
+ lines.push(";; --- network on ------------------------------------------------------------", "", ";; IP only, in both directions, plus binding a local port for a dev server.", "(allow network-outbound (remote ip))", "(allow network-inbound (local ip))", "(allow network-bind (local ip))", "", ";; The system resolver's socket, named exactly, or nothing resolves.", `(allow network-outbound (literal ${quoteSbplString(DNS_RESOLVER_SOCKET)}))`, "", ";; Unix-domain sockets, confined to the write allowlist: a command may run", ";; its own helper daemon inside its own writable area, and a directory it", ";; can already write into is one it could already plant a socket in -- so", ";; this grants nothing the write allowlist did not already grant. Sockets", ";; anywhere else -- docker.sock, a tmux or screen server, an emacs server --", ";; belong to *unsandboxed* daemons that execute what they are told, and", ";; reaching one is a full escape (verified: a confined process injected a", ";; payload into a listening daemon this way).", `(allow network-outbound network-bind ${writeSubpaths})`, "");
231
+ }
232
+ else {
233
+ lines.push(";; --- network off -----------------------------------------------------------", "", ";; Outbound, inbound, bind, and unix-domain sockets: the toggle means *no", ";; sockets*, not merely no IP. A loopback connect fails with EPERM rather", ";; than being refused, which is what the R44-SBX.4 self-test distinguishes.", "(deny network*)", "");
234
+ }
235
+ lines.push(";; --- escape routes, denied explicitly -------------------------------------", ";; `(deny default)` already covers every rule in this block. They are written", ";; out anyway so that the next person to widen an allow above can see what the", ";; widening must not reach.", "", ";; task_for_pid / ptrace-style attach. A confined command could otherwise take", ";; the task port of any same-uid process -- including the agent itself -- and", ";; execute code inside it (verified: `lldb -p` did exactly that, network off).", "(deny mach-priv-task-port)", "(deny mach-priv-host-port)", ";; Even a task *name* port hands out another process's address-space metadata.", "(deny mach-task-name)", ";; Reading other processes' state. Scoped to `others` deliberately: an", ";; unscoped `(deny process-info*)` also blocks a process inspecting itself,", ";; which aborts curl and anything else that calls `proc_pidinfo` on self.", ";; Known consequence: `pgrep` and other whole-machine process enumeration", ";; stop working inside the sandbox. `lsof -p $$` and a command's own job", ";; control still do. (`ps` was already refused -- it is setuid.)", "(deny process-info* (target others))", "", ";; Asking launchd or LaunchServices to start a process for us. That process", ";; would run *outside* this sandbox, which defeats the write allowlist and the", ";; network toggle at once (verified: `open -a` launched an app that then wrote", ";; outside the allowlist). `appleevent-send` is the same escape one hop over:", ";; scripting an already-running unsandboxed app into running a shell command.", "(deny job-creation)", "(deny lsopen)", "(deny appleevent-send)", "", ";; Authorization Services is the other way to ask the system for privileges.", "(deny authorization-right-obtain)", "", ";; No privilege escalation (R44-SBX.2). The kernel already refuses to exec a", ";; setuid binary from inside any sandbox -- verified: sudo fails EPERM even", ";; under a bare `(allow default)` profile -- and profiles are inherited across", ";; exec and cannot be loosened by re-entering sandbox-exec. These denies state", ";; the invariant explicitly; they are not what enforces it.", "(deny file-write-setugid)", `(deny process-exec* ${PRIVILEGE_ESCALATION_BINARIES.map((bin) => `(literal ${quoteSbplString(bin)})`).join(" ")})`);
236
+ lines.push("");
237
+ return lines.join("\n");
238
+ }
239
+ //# sourceMappingURL=seatbelt-profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seatbelt-profile.js","sourceRoot":"","sources":["../../../src/core/sandbox/seatbelt-profile.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * SBPL (Seatbelt) profile generation from a `SandboxPolicy` (R44-SBX.1, macOS).\n *\n * Pure string building, deliberately separated from the backend that spawns\n * `sandbox-exec`, so the exact bytes handed to the kernel are directly testable\n * and diffable without running anything.\n *\n * ## The profile is an allow-list. It used to be a deny-list, and that was a bug\n *\n * Phase 44 shipped `(allow default)` plus targeted denies, on the argument that\n * \"an enumerable allowlist of everything a compiler touches does not exist\". The\n * argument is wrong, and two independent reviews proved it wrong with working\n * escapes. A deny-list sandbox grants every capability nobody thought to\n * enumerate, and on macOS the capabilities nobody enumerated included:\n *\n * - **`mach-lookup` to LaunchServices.** `open -a Calculator` inside the sandbox\n * made launchd start Calculator *outside* it. Reproduced: an app bundle whose\n * executable wrote to a path outside the write allowlist, launched via `open`,\n * and the file appeared. The write allowlist and the network toggle are both\n * irrelevant once you can ask launchd to run a program for you.\n * - **`mach-priv-task-port`.** `lldb -p <pid>` inside the sandbox attached to an\n * unsandboxed same-uid process and ran `expr (int)system(\"echo ... > outside\")`\n * in it. Reproduced with the network off.\n * - **Unix-domain sockets.** A sandboxed process connected to the socket of an\n * already-running unsandboxed daemon and injected a payload into it.\n * - **Every pty on the machine**, via `(regex #\"^/dev/ttys[0-9]*$\")`, so a\n * confined process could write a fake prompt into an unrelated terminal.\n *\n * So the shape is now the one Phase 28 used for the RLM REPL\n * (`packages/rlm/sandbox/macos.sb`):\n *\n * (deny default) ; nothing, unless named below\n * (allow <one capability at a time>) ; each with a reason it is here\n * (deny <the escape routes>) ; restating intent where it matters\n *\n * The enumeration turned out to be small: **thirteen** capability allows, plus a\n * network section of five, cover `bash`, `python3`, `node`, `git`, `npm`, `make`,\n * `clang`, `curl`, `tar`, `sqlite3`, `openssl`, python `venv` and\n * `multiprocessing`, node worker threads, and local HTTP servers. Each one below\n * is here because a specific command failed without it, and the comment says\n * which. Nothing is here \"to be safe\".\n *\n * ## Rules for changing this file\n *\n * 1. An allow needs a one-sentence justification naming what breaks without it.\n * 2. Reach for the narrowest filter that works -- `(global-name \"...\")` over a\n * bare `(allow mach-lookup)`, a `(literal \"...\")` over a `(subpath \"...\")`.\n * 3. Verify the narrowing, do not assume it. `com.apple.system.notification_center`\n * was in an earlier draft of this list and is not here now, because testing\n * showed `com.apple.system.opendirectoryd.libinfo` alone was sufficient.\n * 4. Every capability an escape used gets an explicit `(deny ...)` even though\n * `(deny default)` already covers it, so the next reader can see the intent\n * rather than having to re-derive it from an absence.\n *\n * ## Properties verified empirically on macOS 26.5 (darwin 25.5), not assumed\n *\n * - A write outside the allowlist fails with `EPERM`, whether spelled directly,\n * reached through a symlink whose *link* sits inside an allowed directory, or\n * performed by an interpreter. Seatbelt checks the resolved vnode, so the\n * symlink case needs no rule of its own.\n * - `(deny network*)` blocks a loopback TCP connect (`EPERM`, not a refused\n * connection), which is what makes the R44-SBX.4 network probe meaningful.\n * - **Privilege escalation is impossible by construction**: exec of a setuid\n * binary is refused for *any* sandboxed process, so `sudo` fails at exec time\n * regardless of the rules below. The explicit denies are a statement of intent.\n * - A sandboxed process cannot re-enter `sandbox-exec` with a looser profile:\n * the nested `sandbox_apply` fails with `EPERM`. Profiles compose by\n * intersection and are inherited across `exec`.\n *\n * ## Untrusted strings in a profile\n *\n * `writePaths` can contain user-configured directories (`extraWritePaths` from\n * settings). A path containing `\"` would close the SBPL string literal early and\n * let the rest of the path be parsed as profile source -- `(allow default)`\n * smuggled in through a directory name. Backslash and quote are escaped;\n * anything that cannot be represented at all (control characters, newlines)\n * makes generation **throw**, which the backend turns into `unavailable`. A path\n * we cannot render exactly is never rendered approximately.\n */\n\nimport type { SandboxPolicy } from \"./policy.ts\";\n\n/** Thrown when a policy cannot be rendered into a profile exactly. Backends turn this into `unavailable`. */\nexport class SandboxProfileError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"SandboxProfileError\";\n\t}\n}\n\n/**\n * Device nodes a shell and its children need to write to in order to behave at\n * all: `/dev/null` redirects, `/dev/fd` process substitution, pty allocation.\n * None of these is filesystem persistence, so allowing them does not widen what\n * the policy is about.\n *\n * `/dev/tty` is the per-process alias for the *controlling* terminal, so it can\n * only ever reach the child's own terminal -- unlike the machine-wide\n * `/dev/ttys*` regex this list used to carry, which is now the extension-gated\n * pty rule in `buildSeatbeltProfile`.\n */\nconst DEVICE_WRITE_RULES = [\n\t'(literal \"/dev/null\")',\n\t'(literal \"/dev/zero\")',\n\t'(literal \"/dev/random\")',\n\t'(literal \"/dev/urandom\")',\n\t'(literal \"/dev/stdin\")',\n\t'(literal \"/dev/stdout\")',\n\t'(literal \"/dev/stderr\")',\n\t'(literal \"/dev/tty\")',\n\t'(literal \"/dev/ptmx\")',\n\t'(subpath \"/dev/fd\")',\n] as const;\n\n/**\n * Binaries whose entire purpose is to acquire another user's privileges. Denying\n * exec of them states the invariant in the profile itself; the kernel's refusal\n * to exec setuid binaries inside any sandbox is what actually enforces it.\n */\nconst PRIVILEGE_ESCALATION_BINARIES = [\"/usr/bin/sudo\", \"/usr/bin/su\", \"/usr/bin/sudoedit\", \"/usr/bin/login\"] as const;\n\n/**\n * The system resolver's socket. `getaddrinfo` on macOS reaches mDNSResponder\n * through this unix socket, so without it every hostname fails to resolve even\n * with IP networking fully allowed (measured: `curl` reports\n * \"Could not resolve host\", `node` reports `ENOTFOUND`).\n */\nconst DNS_RESOLVER_SOCKET = \"/private/var/run/mDNSResponder\";\n\n/**\n * Renders `value` as an SBPL string literal.\n *\n * Escapes what SBPL can escape and refuses what it cannot, rather than dropping\n * or substituting characters -- a path rendered as something other than itself\n * is a policy that does not match the policy that was reviewed.\n */\nexport function quoteSbplString(value: string): string {\n\tfor (const char of value) {\n\t\tconst code = char.codePointAt(0) ?? 0;\n\t\tif (code < 0x20 || code === 0x7f) {\n\t\t\tthrow new SandboxProfileError(\n\t\t\t\t`cannot render path ${JSON.stringify(value)} into a sandbox profile: it contains a control character (U+${code\n\t\t\t\t\t.toString(16)\n\t\t\t\t\t.padStart(4, \"0\")\n\t\t\t\t\t.toUpperCase()}) that SBPL string literals cannot represent`,\n\t\t\t);\n\t\t}\n\t}\n\treturn `\"${value.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"')}\"`;\n}\n\n/** Generates the SBPL profile text for `policy`. Deterministic: same policy, same bytes. */\nexport function buildSeatbeltProfile(policy: SandboxPolicy): string {\n\tif (policy.writePaths.length === 0) {\n\t\t// Every backend needs somewhere to write (the shell's own tmp, at minimum),\n\t\t// and an empty allowlist almost always means policy resolution silently\n\t\t// dropped everything. Refusing surfaces that as `unavailable`.\n\t\tthrow new SandboxProfileError(\"cannot render a sandbox profile: the write allowlist is empty\");\n\t}\n\tfor (const path of policy.writePaths) {\n\t\tif (path === \"/\") {\n\t\t\tthrow new SandboxProfileError(\n\t\t\t\t\"cannot render a sandbox profile: the write allowlist contains the filesystem root, which would confine nothing\",\n\t\t\t);\n\t\t}\n\t}\n\n\tconst writeSubpaths = policy.writePaths.map((path) => `(subpath ${quoteSbplString(path)})`).join(\" \");\n\n\tconst lines: string[] = [\n\t\t\"(version 1)\",\n\t\t\"\",\n\t\t\";; Generated from SandboxPolicy v1 by src/core/sandbox/seatbelt-profile.ts.\",\n\t\t\";; Do not edit by hand. Every allow below names the thing that breaks without it.\",\n\t\t\"\",\n\t\t\";; ---------------------------------------------------------------------------\",\n\t\t\";; Deny by default. A capability nobody enumerated is a capability nobody\",\n\t\t\";; reviewed; the previous `(allow default)` shape left launchd, the debugger\",\n\t\t\";; interface and unix sockets open, each of which is a complete escape.\",\n\t\t\";; ---------------------------------------------------------------------------\",\n\t\t\"(deny default)\",\n\t\t\"\",\n\t\t\";; --- what running a developer command actually requires -------------------\",\n\t\t\"\",\n\t\t\";; Running arbitrary binaries is the bash tool's entire purpose; confinement\",\n\t\t\";; here is over what those binaries may write and reach, not over which of\",\n\t\t\";; them exist. (Without it nothing runs at all: even `/bin/sh` fails to exec.)\",\n\t\t\"(allow process-exec*)\",\n\t\t\"\",\n\t\t\";; Every pipeline, subshell, `$(...)` and parallel build forks.\",\n\t\t\"(allow process-fork)\",\n\t\t\"\",\n\t\t\";; R44-SBX.2: v1 is read allow-all. Dev workflows read toolchains, caches and\",\n\t\t\";; dotfiles constantly, and a read-deny list is a v2 concern.\",\n\t\t\"(allow file-read*)\",\n\t\t\"\",\n\t\t\";; The policy: only these subtrees are writable. Seatbelt matches the resolved\",\n\t\t\";; vnode, so a symlink pointing out of one of these does not widen it.\",\n\t\t`(allow file-write* ${writeSubpaths})`,\n\t\t\"\",\n\t\t\";; Device nodes a shell needs to function. Not filesystem persistence.\",\n\t\t`(allow file-write* ${DEVICE_WRITE_RULES.join(\" \")})`,\n\t\t\"\",\n\t\t\";; A pty the process allocates for itself (`script`, `node-pty`, `python -m pty`,\",\n\t\t\";; anything that wants a tty for a child). `pseudo-tty` issues the sandbox\",\n\t\t\";; extension that the following rule requires, so this grants the child *its\",\n\t\t';; own* terminal and no other: the machine-wide `(regex #\"^/dev/ttys[0-9]*$\")`',\n\t\t\";; this replaces let a confined process write a forged prompt into somebody\",\n\t\t\";; else's terminal. Idiom taken from Apple's own application.sb.\",\n\t\t\"(allow pseudo-tty)\",\n\t\t'(allow file-read* file-write* (require-all (regex #\"^/dev/ttys[0-9]*$\") (extension \"com.apple.sandbox.pty\")))',\n\t\t\"\",\n\t\t\";; `isatty`, terminal size, and the termios calls every interactive-ish tool\",\n\t\t\";; makes on descriptors it has already opened.\",\n\t\t\"(allow file-ioctl)\",\n\t\t\"\",\n\t\t\";; `hw.ncpu`, `kern.osversion` and friends: node, python and make read these\",\n\t\t\";; during startup (`os.cpus()`, `sysctl -n hw.ncpu`, `uname -a`).\",\n\t\t\"(allow sysctl-read)\",\n\t\t\"\",\n\t\t\";; Job control over the command's own process tree -- `kill %1`, `make` killing\",\n\t\t\";; a stuck child, `trap`. `(target same-sandbox)` stops there: without the\",\n\t\t\";; filter a confined command can SIGKILL the agent that launched it (verified:\",\n\t\t\";; it could, under the old profile).\",\n\t\t\"(allow signal (target same-sandbox))\",\n\t\t\"\",\n\t\t\";; POSIX semaphores: `multiprocessing.Pool` fails with EPERM in `sem_unlink`\",\n\t\t\";; without this, which takes out most parallel Python.\",\n\t\t\"(allow ipc-posix-sem)\",\n\t\t\"\",\n\t\t\";; POSIX shared memory: `multiprocessing.shared_memory` and the data-science\",\n\t\t\";; stacks layered on it. A memory-object namespace -- no filesystem, exec or\",\n\t\t\";; network reach comes with it.\",\n\t\t\"(allow ipc-posix-shm)\",\n\t\t\"\",\n\t\t\";; User and group lookup (`getpwuid`). Without it `id -un` and `whoami` print\",\n\t\t\";; a bare uid, `os.userInfo()` throws ENOENT, and git cannot name an author.\",\n\t\t\";; One service, by name: a bare `(allow mach-lookup)` is what put LaunchServices\",\n\t\t\";; -- and therefore launchd -- back in reach.\",\n\t\t'(allow mach-lookup (global-name \"com.apple.system.opendirectoryd.libinfo\"))',\n\t\t\"\",\n\t];\n\n\tif (policy.network === \"on\") {\n\t\tlines.push(\n\t\t\t\";; --- network on ------------------------------------------------------------\",\n\t\t\t\"\",\n\t\t\t\";; IP only, in both directions, plus binding a local port for a dev server.\",\n\t\t\t\"(allow network-outbound (remote ip))\",\n\t\t\t\"(allow network-inbound (local ip))\",\n\t\t\t\"(allow network-bind (local ip))\",\n\t\t\t\"\",\n\t\t\t\";; The system resolver's socket, named exactly, or nothing resolves.\",\n\t\t\t`(allow network-outbound (literal ${quoteSbplString(DNS_RESOLVER_SOCKET)}))`,\n\t\t\t\"\",\n\t\t\t\";; Unix-domain sockets, confined to the write allowlist: a command may run\",\n\t\t\t\";; its own helper daemon inside its own writable area, and a directory it\",\n\t\t\t\";; can already write into is one it could already plant a socket in -- so\",\n\t\t\t\";; this grants nothing the write allowlist did not already grant. Sockets\",\n\t\t\t\";; anywhere else -- docker.sock, a tmux or screen server, an emacs server --\",\n\t\t\t\";; belong to *unsandboxed* daemons that execute what they are told, and\",\n\t\t\t\";; reaching one is a full escape (verified: a confined process injected a\",\n\t\t\t\";; payload into a listening daemon this way).\",\n\t\t\t`(allow network-outbound network-bind ${writeSubpaths})`,\n\t\t\t\"\",\n\t\t);\n\t} else {\n\t\tlines.push(\n\t\t\t\";; --- network off -----------------------------------------------------------\",\n\t\t\t\"\",\n\t\t\t\";; Outbound, inbound, bind, and unix-domain sockets: the toggle means *no\",\n\t\t\t\";; sockets*, not merely no IP. A loopback connect fails with EPERM rather\",\n\t\t\t\";; than being refused, which is what the R44-SBX.4 self-test distinguishes.\",\n\t\t\t\"(deny network*)\",\n\t\t\t\"\",\n\t\t);\n\t}\n\n\tlines.push(\n\t\t\";; --- escape routes, denied explicitly -------------------------------------\",\n\t\t\";; `(deny default)` already covers every rule in this block. They are written\",\n\t\t\";; out anyway so that the next person to widen an allow above can see what the\",\n\t\t\";; widening must not reach.\",\n\t\t\"\",\n\t\t\";; task_for_pid / ptrace-style attach. A confined command could otherwise take\",\n\t\t\";; the task port of any same-uid process -- including the agent itself -- and\",\n\t\t\";; execute code inside it (verified: `lldb -p` did exactly that, network off).\",\n\t\t\"(deny mach-priv-task-port)\",\n\t\t\"(deny mach-priv-host-port)\",\n\t\t\";; Even a task *name* port hands out another process's address-space metadata.\",\n\t\t\"(deny mach-task-name)\",\n\t\t\";; Reading other processes' state. Scoped to `others` deliberately: an\",\n\t\t\";; unscoped `(deny process-info*)` also blocks a process inspecting itself,\",\n\t\t\";; which aborts curl and anything else that calls `proc_pidinfo` on self.\",\n\t\t\";; Known consequence: `pgrep` and other whole-machine process enumeration\",\n\t\t\";; stop working inside the sandbox. `lsof -p $$` and a command's own job\",\n\t\t\";; control still do. (`ps` was already refused -- it is setuid.)\",\n\t\t\"(deny process-info* (target others))\",\n\t\t\"\",\n\t\t\";; Asking launchd or LaunchServices to start a process for us. That process\",\n\t\t\";; would run *outside* this sandbox, which defeats the write allowlist and the\",\n\t\t\";; network toggle at once (verified: `open -a` launched an app that then wrote\",\n\t\t\";; outside the allowlist). `appleevent-send` is the same escape one hop over:\",\n\t\t\";; scripting an already-running unsandboxed app into running a shell command.\",\n\t\t\"(deny job-creation)\",\n\t\t\"(deny lsopen)\",\n\t\t\"(deny appleevent-send)\",\n\t\t\"\",\n\t\t\";; Authorization Services is the other way to ask the system for privileges.\",\n\t\t\"(deny authorization-right-obtain)\",\n\t\t\"\",\n\t\t\";; No privilege escalation (R44-SBX.2). The kernel already refuses to exec a\",\n\t\t\";; setuid binary from inside any sandbox -- verified: sudo fails EPERM even\",\n\t\t\";; under a bare `(allow default)` profile -- and profiles are inherited across\",\n\t\t\";; exec and cannot be loosened by re-entering sandbox-exec. These denies state\",\n\t\t\";; the invariant explicitly; they are not what enforces it.\",\n\t\t\"(deny file-write-setugid)\",\n\t\t`(deny process-exec* ${PRIVILEGE_ESCALATION_BINARIES.map((bin) => `(literal ${quoteSbplString(bin)})`).join(\" \")})`,\n\t);\n\n\tlines.push(\"\");\n\treturn lines.join(\"\\n\");\n}\n"]}