@draht/coding-agent 2026.7.13 → 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 (614) hide show
  1. package/CHANGELOG.md +241 -0
  2. package/README.md +47 -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/bun/cli.js +2 -0
  19. package/dist/bun/cli.js.map +1 -1
  20. package/dist/cli/args.d.ts +10 -0
  21. package/dist/cli/args.d.ts.map +1 -1
  22. package/dist/cli/args.js +80 -3
  23. package/dist/cli/args.js.map +1 -1
  24. package/dist/cli/attach-mode.d.ts +61 -0
  25. package/dist/cli/attach-mode.d.ts.map +1 -1
  26. package/dist/cli/attach-mode.js +243 -5
  27. package/dist/cli/attach-mode.js.map +1 -1
  28. package/dist/cli/config-selector.js +1 -1
  29. package/dist/cli/config-selector.js.map +1 -1
  30. package/dist/cli/credential-print.d.ts +23 -0
  31. package/dist/cli/credential-print.d.ts.map +1 -0
  32. package/dist/cli/credential-print.js +117 -0
  33. package/dist/cli/credential-print.js.map +1 -0
  34. package/dist/cli/list-models.d.ts +2 -2
  35. package/dist/cli/list-models.d.ts.map +1 -1
  36. package/dist/cli/list-models.js +3 -3
  37. package/dist/cli/list-models.js.map +1 -1
  38. package/dist/cli/startup-ui.js +1 -1
  39. package/dist/cli/startup-ui.js.map +1 -1
  40. package/dist/config.d.ts +9 -0
  41. package/dist/config.d.ts.map +1 -1
  42. package/dist/config.js +31 -4
  43. package/dist/config.js.map +1 -1
  44. package/dist/core/agent-session-runtime.d.ts +17 -1
  45. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  46. package/dist/core/agent-session-runtime.js +90 -30
  47. package/dist/core/agent-session-runtime.js.map +1 -1
  48. package/dist/core/agent-session-services.d.ts +4 -7
  49. package/dist/core/agent-session-services.d.ts.map +1 -1
  50. package/dist/core/agent-session-services.js +24 -9
  51. package/dist/core/agent-session-services.js.map +1 -1
  52. package/dist/core/agent-session.d.ts +87 -27
  53. package/dist/core/agent-session.d.ts.map +1 -1
  54. package/dist/core/agent-session.js +337 -154
  55. package/dist/core/agent-session.js.map +1 -1
  56. package/dist/core/auth-storage.d.ts +20 -104
  57. package/dist/core/auth-storage.d.ts.map +1 -1
  58. package/dist/core/auth-storage.js +104 -260
  59. package/dist/core/auth-storage.js.map +1 -1
  60. package/dist/core/builtins/checkpoints.d.ts +20 -0
  61. package/dist/core/builtins/checkpoints.d.ts.map +1 -0
  62. package/dist/core/builtins/checkpoints.js +161 -0
  63. package/dist/core/builtins/checkpoints.js.map +1 -0
  64. package/dist/core/builtins/duet.d.ts +26 -0
  65. package/dist/core/builtins/duet.d.ts.map +1 -0
  66. package/dist/core/builtins/duet.js +660 -0
  67. package/dist/core/builtins/duet.js.map +1 -0
  68. package/dist/core/builtins/index.d.ts.map +1 -1
  69. package/dist/core/builtins/index.js +7 -1
  70. package/dist/core/builtins/index.js.map +1 -1
  71. package/dist/core/builtins/subagent.d.ts +24 -4
  72. package/dist/core/builtins/subagent.d.ts.map +1 -1
  73. package/dist/core/builtins/subagent.js +278 -35
  74. package/dist/core/builtins/subagent.js.map +1 -1
  75. package/dist/core/cache-stats.d.ts +2 -2
  76. package/dist/core/cache-stats.d.ts.map +1 -1
  77. package/dist/core/cache-stats.js +1 -1
  78. package/dist/core/cache-stats.js.map +1 -1
  79. package/dist/core/checkpoints/checkpoint-cli.d.ts +17 -0
  80. package/dist/core/checkpoints/checkpoint-cli.d.ts.map +1 -0
  81. package/dist/core/checkpoints/checkpoint-cli.js +78 -0
  82. package/dist/core/checkpoints/checkpoint-cli.js.map +1 -0
  83. package/dist/core/checkpoints/checkpoint-manager.d.ts +294 -0
  84. package/dist/core/checkpoints/checkpoint-manager.d.ts.map +1 -0
  85. package/dist/core/checkpoints/checkpoint-manager.js +865 -0
  86. package/dist/core/checkpoints/checkpoint-manager.js.map +1 -0
  87. package/dist/core/checkpoints/rewind.d.ts +141 -0
  88. package/dist/core/checkpoints/rewind.d.ts.map +1 -0
  89. package/dist/core/checkpoints/rewind.js +246 -0
  90. package/dist/core/checkpoints/rewind.js.map +1 -0
  91. package/dist/core/compaction/branch-summarization.d.ts +9 -3
  92. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  93. package/dist/core/compaction/branch-summarization.js +16 -14
  94. package/dist/core/compaction/branch-summarization.js.map +1 -1
  95. package/dist/core/compaction/compaction.d.ts +24 -3
  96. package/dist/core/compaction/compaction.d.ts.map +1 -1
  97. package/dist/core/compaction/compaction.js +96 -30
  98. package/dist/core/compaction/compaction.js.map +1 -1
  99. package/dist/core/compaction/utils.d.ts +1 -1
  100. package/dist/core/compaction/utils.d.ts.map +1 -1
  101. package/dist/core/compaction/utils.js +6 -17
  102. package/dist/core/compaction/utils.js.map +1 -1
  103. package/dist/core/context-windows.d.ts +7 -0
  104. package/dist/core/context-windows.d.ts.map +1 -0
  105. package/dist/core/context-windows.js +35 -0
  106. package/dist/core/context-windows.js.map +1 -0
  107. package/dist/core/extensions/index.d.ts +1 -1
  108. package/dist/core/extensions/index.d.ts.map +1 -1
  109. package/dist/core/extensions/index.js.map +1 -1
  110. package/dist/core/extensions/loader.d.ts.map +1 -1
  111. package/dist/core/extensions/loader.js +101 -23
  112. package/dist/core/extensions/loader.js.map +1 -1
  113. package/dist/core/extensions/runner.d.ts +19 -3
  114. package/dist/core/extensions/runner.d.ts.map +1 -1
  115. package/dist/core/extensions/runner.js +117 -2
  116. package/dist/core/extensions/runner.js.map +1 -1
  117. package/dist/core/extensions/types.d.ts +236 -9
  118. package/dist/core/extensions/types.d.ts.map +1 -1
  119. package/dist/core/extensions/types.js.map +1 -1
  120. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  121. package/dist/core/extensions/wrapper.js +22 -3
  122. package/dist/core/extensions/wrapper.js.map +1 -1
  123. package/dist/core/footer-data-provider.d.ts +10 -0
  124. package/dist/core/footer-data-provider.d.ts.map +1 -1
  125. package/dist/core/footer-data-provider.js +1 -1
  126. package/dist/core/footer-data-provider.js.map +1 -1
  127. package/dist/core/http-dispatcher.d.ts.map +1 -1
  128. package/dist/core/http-dispatcher.js +7 -0
  129. package/dist/core/http-dispatcher.js.map +1 -1
  130. package/dist/core/index.d.ts +1 -1
  131. package/dist/core/index.d.ts.map +1 -1
  132. package/dist/core/index.js.map +1 -1
  133. package/dist/core/keybindings.d.ts +18 -3
  134. package/dist/core/keybindings.d.ts.map +1 -1
  135. package/dist/core/keybindings.js +12 -3
  136. package/dist/core/keybindings.js.map +1 -1
  137. package/dist/core/model-config.d.ts +542 -0
  138. package/dist/core/model-config.d.ts.map +1 -0
  139. package/dist/core/model-config.js +247 -0
  140. package/dist/core/model-config.js.map +1 -0
  141. package/dist/core/model-registry.d.ts +19 -124
  142. package/dist/core/model-registry.d.ts.map +1 -1
  143. package/dist/core/model-registry.js +56 -727
  144. package/dist/core/model-registry.js.map +1 -1
  145. package/dist/core/model-resolver.d.ts +7 -6
  146. package/dist/core/model-resolver.d.ts.map +1 -1
  147. package/dist/core/model-resolver.js +74 -27
  148. package/dist/core/model-resolver.js.map +1 -1
  149. package/dist/core/model-runtime.d.ts +89 -0
  150. package/dist/core/model-runtime.d.ts.map +1 -0
  151. package/dist/core/model-runtime.js +451 -0
  152. package/dist/core/model-runtime.js.map +1 -0
  153. package/dist/core/models-store.d.ts +17 -0
  154. package/dist/core/models-store.d.ts.map +1 -0
  155. package/dist/core/models-store.js +46 -0
  156. package/dist/core/models-store.js.map +1 -0
  157. package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
  158. package/dist/core/multi-agent/permission-gate.js +4 -3
  159. package/dist/core/multi-agent/permission-gate.js.map +1 -1
  160. package/dist/core/multi-agent/worktree.d.ts +2 -0
  161. package/dist/core/multi-agent/worktree.d.ts.map +1 -1
  162. package/dist/core/multi-agent/worktree.js +2 -2
  163. package/dist/core/multi-agent/worktree.js.map +1 -1
  164. package/dist/core/package-manager.d.ts +7 -1
  165. package/dist/core/package-manager.d.ts.map +1 -1
  166. package/dist/core/package-manager.js +41 -45
  167. package/dist/core/package-manager.js.map +1 -1
  168. package/dist/core/permission-relay/index.d.ts +19 -0
  169. package/dist/core/permission-relay/index.d.ts.map +1 -0
  170. package/dist/core/permission-relay/index.js +49 -0
  171. package/dist/core/permission-relay/index.js.map +1 -0
  172. package/dist/core/permission-relay/relay-ui-context.d.ts +39 -0
  173. package/dist/core/permission-relay/relay-ui-context.d.ts.map +1 -0
  174. package/dist/core/permission-relay/relay-ui-context.js +788 -0
  175. package/dist/core/permission-relay/relay-ui-context.js.map +1 -0
  176. package/dist/core/permission-relay/types.d.ts +222 -0
  177. package/dist/core/permission-relay/types.d.ts.map +1 -0
  178. package/dist/core/permission-relay/types.js +15 -0
  179. package/dist/core/permission-relay/types.js.map +1 -0
  180. package/dist/core/pi-manifest.d.ts +14 -0
  181. package/dist/core/pi-manifest.d.ts.map +1 -0
  182. package/dist/core/pi-manifest.js +35 -0
  183. package/dist/core/pi-manifest.js.map +1 -0
  184. package/dist/core/project-trust.js +2 -2
  185. package/dist/core/project-trust.js.map +1 -1
  186. package/dist/core/prompt-templates.d.ts +1 -0
  187. package/dist/core/prompt-templates.d.ts.map +1 -1
  188. package/dist/core/prompt-templates.js +4 -4
  189. package/dist/core/prompt-templates.js.map +1 -1
  190. package/dist/core/provider-composer.d.ts +55 -0
  191. package/dist/core/provider-composer.d.ts.map +1 -0
  192. package/dist/core/provider-composer.js +375 -0
  193. package/dist/core/provider-composer.js.map +1 -0
  194. package/dist/core/radius.d.ts +2 -0
  195. package/dist/core/radius.d.ts.map +1 -0
  196. package/dist/core/radius.js +2 -0
  197. package/dist/core/radius.js.map +1 -0
  198. package/dist/core/remote-catalog-provider.d.ts +5 -0
  199. package/dist/core/remote-catalog-provider.d.ts.map +1 -0
  200. package/dist/core/remote-catalog-provider.js +115 -0
  201. package/dist/core/remote-catalog-provider.js.map +1 -0
  202. package/dist/core/resource-loader.d.ts +36 -0
  203. package/dist/core/resource-loader.d.ts.map +1 -1
  204. package/dist/core/resource-loader.js +159 -27
  205. package/dist/core/resource-loader.js.map +1 -1
  206. package/dist/core/runtime-credentials.d.ts +15 -0
  207. package/dist/core/runtime-credentials.d.ts.map +1 -0
  208. package/dist/core/runtime-credentials.js +35 -0
  209. package/dist/core/runtime-credentials.js.map +1 -0
  210. package/dist/core/sandbox/bash-operations.d.ts +149 -0
  211. package/dist/core/sandbox/bash-operations.d.ts.map +1 -0
  212. package/dist/core/sandbox/bash-operations.js +163 -0
  213. package/dist/core/sandbox/bash-operations.js.map +1 -0
  214. package/dist/core/sandbox/env.d.ts +83 -0
  215. package/dist/core/sandbox/env.d.ts.map +1 -0
  216. package/dist/core/sandbox/env.js +123 -0
  217. package/dist/core/sandbox/env.js.map +1 -0
  218. package/dist/core/sandbox/executor.d.ts +104 -0
  219. package/dist/core/sandbox/executor.d.ts.map +1 -0
  220. package/dist/core/sandbox/executor.js +92 -0
  221. package/dist/core/sandbox/executor.js.map +1 -0
  222. package/dist/core/sandbox/index.d.ts +36 -0
  223. package/dist/core/sandbox/index.d.ts.map +1 -0
  224. package/dist/core/sandbox/index.js +36 -0
  225. package/dist/core/sandbox/index.js.map +1 -0
  226. package/dist/core/sandbox/linux.d.ts +121 -0
  227. package/dist/core/sandbox/linux.d.ts.map +1 -0
  228. package/dist/core/sandbox/linux.js +260 -0
  229. package/dist/core/sandbox/linux.js.map +1 -0
  230. package/dist/core/sandbox/policy.d.ts +142 -0
  231. package/dist/core/sandbox/policy.d.ts.map +1 -0
  232. package/dist/core/sandbox/policy.js +297 -0
  233. package/dist/core/sandbox/policy.js.map +1 -0
  234. package/dist/core/sandbox/real-path.d.ts +112 -0
  235. package/dist/core/sandbox/real-path.d.ts.map +1 -0
  236. package/dist/core/sandbox/real-path.js +158 -0
  237. package/dist/core/sandbox/real-path.js.map +1 -0
  238. package/dist/core/sandbox/seatbelt-profile.d.ts +95 -0
  239. package/dist/core/sandbox/seatbelt-profile.d.ts.map +1 -0
  240. package/dist/core/sandbox/seatbelt-profile.js +239 -0
  241. package/dist/core/sandbox/seatbelt-profile.js.map +1 -0
  242. package/dist/core/sandbox/seatbelt.d.ts +95 -0
  243. package/dist/core/sandbox/seatbelt.d.ts.map +1 -0
  244. package/dist/core/sandbox/seatbelt.js +154 -0
  245. package/dist/core/sandbox/seatbelt.js.map +1 -0
  246. package/dist/core/sandbox/self-test.d.ts +109 -0
  247. package/dist/core/sandbox/self-test.d.ts.map +1 -0
  248. package/dist/core/sandbox/self-test.js +369 -0
  249. package/dist/core/sandbox/self-test.js.map +1 -0
  250. package/dist/core/sandbox/spawn.d.ts +33 -0
  251. package/dist/core/sandbox/spawn.d.ts.map +1 -0
  252. package/dist/core/sandbox/spawn.js +87 -0
  253. package/dist/core/sandbox/spawn.js.map +1 -0
  254. package/dist/core/sdk.d.ts +3 -6
  255. package/dist/core/sdk.d.ts.map +1 -1
  256. package/dist/core/sdk.js +25 -22
  257. package/dist/core/sdk.js.map +1 -1
  258. package/dist/core/session-manager.d.ts +74 -7
  259. package/dist/core/session-manager.d.ts.map +1 -1
  260. package/dist/core/session-manager.js +169 -34
  261. package/dist/core/session-manager.js.map +1 -1
  262. package/dist/core/settings-manager.d.ts +22 -1
  263. package/dist/core/settings-manager.d.ts.map +1 -1
  264. package/dist/core/settings-manager.js +36 -16
  265. package/dist/core/settings-manager.js.map +1 -1
  266. package/dist/core/skills.d.ts +3 -1
  267. package/dist/core/skills.d.ts.map +1 -1
  268. package/dist/core/skills.js +19 -6
  269. package/dist/core/skills.js.map +1 -1
  270. package/dist/core/slash-commands.d.ts.map +1 -1
  271. package/dist/core/slash-commands.js +1 -0
  272. package/dist/core/slash-commands.js.map +1 -1
  273. package/dist/core/soak/soak-log.d.ts +298 -0
  274. package/dist/core/soak/soak-log.d.ts.map +1 -0
  275. package/dist/core/soak/soak-log.js +660 -0
  276. package/dist/core/soak/soak-log.js.map +1 -0
  277. package/dist/core/soak/soak-reader.d.ts +60 -0
  278. package/dist/core/soak/soak-reader.d.ts.map +1 -0
  279. package/dist/core/soak/soak-reader.js +106 -0
  280. package/dist/core/soak/soak-reader.js.map +1 -0
  281. package/dist/core/socket-server/discovery.d.ts +78 -1
  282. package/dist/core/socket-server/discovery.d.ts.map +1 -1
  283. package/dist/core/socket-server/discovery.js +356 -37
  284. package/dist/core/socket-server/discovery.js.map +1 -1
  285. package/dist/core/socket-server/index.d.ts +10 -4
  286. package/dist/core/socket-server/index.d.ts.map +1 -1
  287. package/dist/core/socket-server/index.js +6 -3
  288. package/dist/core/socket-server/index.js.map +1 -1
  289. package/dist/core/socket-server/permission-delivery.d.ts +125 -0
  290. package/dist/core/socket-server/permission-delivery.d.ts.map +1 -0
  291. package/dist/core/socket-server/permission-delivery.js +152 -0
  292. package/dist/core/socket-server/permission-delivery.js.map +1 -0
  293. package/dist/core/socket-server/permission-registry.d.ts +301 -0
  294. package/dist/core/socket-server/permission-registry.d.ts.map +1 -0
  295. package/dist/core/socket-server/permission-registry.js +410 -0
  296. package/dist/core/socket-server/permission-registry.js.map +1 -0
  297. package/dist/core/socket-server/permission-relay.d.ts +81 -0
  298. package/dist/core/socket-server/permission-relay.d.ts.map +1 -0
  299. package/dist/core/socket-server/permission-relay.js +528 -0
  300. package/dist/core/socket-server/permission-relay.js.map +1 -0
  301. package/dist/core/socket-server/safe-text.d.ts +83 -0
  302. package/dist/core/socket-server/safe-text.d.ts.map +1 -0
  303. package/dist/core/socket-server/safe-text.js +277 -0
  304. package/dist/core/socket-server/safe-text.js.map +1 -0
  305. package/dist/core/socket-server/session-integration.d.ts +65 -2
  306. package/dist/core/socket-server/session-integration.d.ts.map +1 -1
  307. package/dist/core/socket-server/session-integration.js +434 -32
  308. package/dist/core/socket-server/session-integration.js.map +1 -1
  309. package/dist/core/socket-server/socket-client.d.ts +21 -2
  310. package/dist/core/socket-server/socket-client.d.ts.map +1 -1
  311. package/dist/core/socket-server/socket-client.js +52 -1
  312. package/dist/core/socket-server/socket-client.js.map +1 -1
  313. package/dist/core/socket-server/socket-server.d.ts +152 -1
  314. package/dist/core/socket-server/socket-server.d.ts.map +1 -1
  315. package/dist/core/socket-server/socket-server.js +775 -26
  316. package/dist/core/socket-server/socket-server.js.map +1 -1
  317. package/dist/core/socket-server/types.d.ts +106 -2
  318. package/dist/core/socket-server/types.d.ts.map +1 -1
  319. package/dist/core/socket-server/types.js +13 -1
  320. package/dist/core/socket-server/types.js.map +1 -1
  321. package/dist/core/system-prompt.d.ts.map +1 -1
  322. package/dist/core/system-prompt.js +10 -21
  323. package/dist/core/system-prompt.js.map +1 -1
  324. package/dist/core/tools/bash.d.ts +3 -1
  325. package/dist/core/tools/bash.d.ts.map +1 -1
  326. package/dist/core/tools/bash.js +39 -7
  327. package/dist/core/tools/bash.js.map +1 -1
  328. package/dist/core/tools/edit.d.ts.map +1 -1
  329. package/dist/core/tools/edit.js +17 -2
  330. package/dist/core/tools/edit.js.map +1 -1
  331. package/dist/core/tools/find.d.ts +3 -0
  332. package/dist/core/tools/find.d.ts.map +1 -1
  333. package/dist/core/tools/find.js +11 -18
  334. package/dist/core/tools/find.js.map +1 -1
  335. package/dist/core/tools/read.js +1 -1
  336. package/dist/core/tools/read.js.map +1 -1
  337. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  338. package/dist/core/tools/tool-definition-wrapper.js +3 -1
  339. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  340. package/dist/core/trust-manager.d.ts +6 -4
  341. package/dist/core/trust-manager.d.ts.map +1 -1
  342. package/dist/core/trust-manager.js +55 -21
  343. package/dist/core/trust-manager.js.map +1 -1
  344. package/dist/core/usage-totals.d.ts +19 -0
  345. package/dist/core/usage-totals.d.ts.map +1 -0
  346. package/dist/core/usage-totals.js +52 -0
  347. package/dist/core/usage-totals.js.map +1 -0
  348. package/dist/extensions/index.d.ts +3 -0
  349. package/dist/extensions/index.d.ts.map +1 -0
  350. package/dist/extensions/index.js +7 -0
  351. package/dist/extensions/index.js.map +1 -0
  352. package/dist/extensions/llama/client.d.ts +61 -0
  353. package/dist/extensions/llama/client.d.ts.map +1 -0
  354. package/dist/extensions/llama/client.js +300 -0
  355. package/dist/extensions/llama/client.js.map +1 -0
  356. package/dist/extensions/llama/huggingface.d.ts +23 -0
  357. package/dist/extensions/llama/huggingface.d.ts.map +1 -0
  358. package/dist/extensions/llama/huggingface.js +139 -0
  359. package/dist/extensions/llama/huggingface.js.map +1 -0
  360. package/dist/extensions/llama/index.d.ts +3 -0
  361. package/dist/extensions/llama/index.d.ts.map +1 -0
  362. package/dist/extensions/llama/index.js +208 -0
  363. package/dist/extensions/llama/index.js.map +1 -0
  364. package/dist/extensions/llama/provider.d.ts +10 -0
  365. package/dist/extensions/llama/provider.d.ts.map +1 -0
  366. package/dist/extensions/llama/provider.js +111 -0
  367. package/dist/extensions/llama/provider.js.map +1 -0
  368. package/dist/extensions/llama/ui.d.ts +42 -0
  369. package/dist/extensions/llama/ui.d.ts.map +1 -0
  370. package/dist/extensions/llama/ui.js +400 -0
  371. package/dist/extensions/llama/ui.js.map +1 -0
  372. package/dist/extensions/stub-provider/index.d.ts +9 -0
  373. package/dist/extensions/stub-provider/index.d.ts.map +1 -0
  374. package/dist/extensions/stub-provider/index.js +13 -0
  375. package/dist/extensions/stub-provider/index.js.map +1 -0
  376. package/dist/extensions/stub-provider/provider.d.ts +77 -0
  377. package/dist/extensions/stub-provider/provider.d.ts.map +1 -0
  378. package/dist/extensions/stub-provider/provider.js +193 -0
  379. package/dist/extensions/stub-provider/provider.js.map +1 -0
  380. package/dist/hooks/gsd/draht-quality-gate.js +3 -3
  381. package/dist/index.d.ts +4 -3
  382. package/dist/index.d.ts.map +1 -1
  383. package/dist/index.js +3 -3
  384. package/dist/index.js.map +1 -1
  385. package/dist/main.d.ts.map +1 -1
  386. package/dist/main.js +305 -61
  387. package/dist/main.js.map +1 -1
  388. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  389. package/dist/modes/interactive/components/assistant-message.js +22 -10
  390. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  391. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  392. package/dist/modes/interactive/components/config-selector.js +3 -2
  393. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  394. package/dist/modes/interactive/components/custom-editor.js +1 -1
  395. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  396. package/dist/modes/interactive/components/custom-message.d.ts +3 -1
  397. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  398. package/dist/modes/interactive/components/custom-message.js +9 -2
  399. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  400. package/dist/modes/interactive/components/extension-editor.d.ts +1 -2
  401. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  402. package/dist/modes/interactive/components/extension-editor.js +16 -46
  403. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  404. package/dist/modes/interactive/components/extension-selector.d.ts +49 -0
  405. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  406. package/dist/modes/interactive/components/extension-selector.js +202 -5
  407. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  408. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  409. package/dist/modes/interactive/components/footer.js +24 -23
  410. package/dist/modes/interactive/components/footer.js.map +1 -1
  411. package/dist/modes/interactive/components/login-dialog.d.ts +5 -5
  412. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  413. package/dist/modes/interactive/components/login-dialog.js +17 -8
  414. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  415. package/dist/modes/interactive/components/model-selector.d.ts +11 -4
  416. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  417. package/dist/modes/interactive/components/model-selector.js +74 -41
  418. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  419. package/dist/modes/interactive/components/oauth-selector.d.ts +4 -4
  420. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  421. package/dist/modes/interactive/components/oauth-selector.js +14 -25
  422. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  423. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  424. package/dist/modes/interactive/components/scoped-models-selector.js +22 -13
  425. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  426. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  427. package/dist/modes/interactive/components/session-selector.js +10 -2
  428. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  429. package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
  430. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  431. package/dist/modes/interactive/components/settings-selector.js +10 -0
  432. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  433. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  434. package/dist/modes/interactive/components/tool-execution.js +10 -1
  435. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  436. package/dist/modes/interactive/components/tree-selector.d.ts +25 -2
  437. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  438. package/dist/modes/interactive/components/tree-selector.js +68 -17
  439. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  440. package/dist/modes/interactive/external-editor.d.ts +12 -0
  441. package/dist/modes/interactive/external-editor.d.ts.map +1 -0
  442. package/dist/modes/interactive/external-editor.js +37 -0
  443. package/dist/modes/interactive/external-editor.js.map +1 -0
  444. package/dist/modes/interactive/interactive-mode.d.ts +107 -10
  445. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  446. package/dist/modes/interactive/interactive-mode.js +763 -285
  447. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  448. package/dist/modes/rpc/rpc-client.d.ts +4 -0
  449. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  450. package/dist/modes/rpc/rpc-client.js +7 -0
  451. package/dist/modes/rpc/rpc-client.js.map +1 -1
  452. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  453. package/dist/modes/rpc/rpc-mode.js +185 -9
  454. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  455. package/dist/modes/rpc/rpc-types.d.ts +79 -1
  456. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  457. package/dist/modes/rpc/rpc-types.js.map +1 -1
  458. package/dist/package-manager-cli.d.ts.map +1 -1
  459. package/dist/package-manager-cli.js +67 -5
  460. package/dist/package-manager-cli.js.map +1 -1
  461. package/dist/prompts/commands/atomic-commit.md +1 -12
  462. package/dist/prompts/commands/brainstorm.md +12 -15
  463. package/dist/prompts/commands/create-verification-skill.md +108 -0
  464. package/dist/prompts/commands/discuss-phase.md +3 -14
  465. package/dist/prompts/commands/execute-phase.md +3 -11
  466. package/dist/prompts/commands/fix.md +41 -18
  467. package/dist/prompts/commands/grill.md +66 -0
  468. package/dist/prompts/commands/init-project.md +5 -15
  469. package/dist/prompts/commands/map-codebase.md +1 -13
  470. package/dist/prompts/commands/new-project.md +5 -15
  471. package/dist/prompts/commands/next-milestone.md +1 -13
  472. package/dist/prompts/commands/orchestrate.md +1 -1
  473. package/dist/prompts/commands/pause-work.md +1 -13
  474. package/dist/prompts/commands/plan-phase.md +2 -11
  475. package/dist/prompts/commands/progress.md +0 -13
  476. package/dist/prompts/commands/quick.md +3 -11
  477. package/dist/prompts/commands/resolve-conflicts.md +71 -0
  478. package/dist/prompts/commands/resume-work.md +0 -13
  479. package/dist/prompts/commands/review.md +4 -13
  480. package/dist/prompts/commands/triage.md +159 -0
  481. package/dist/prompts/commands/verify-work.md +4 -14
  482. package/dist/prompts/commands/why.md +135 -0
  483. package/dist/skills/atomic-reasoning/SKILL.md +115 -0
  484. package/dist/skills/blast-radius/SKILL.md +55 -0
  485. package/dist/skills/epistemics/SKILL.md +99 -0
  486. package/dist/skills/hexagon-animation/SKILL.md +49 -0
  487. package/dist/skills/hexagon-animation/generate.mjs +81 -0
  488. package/dist/skills/hexagon-animation/template.html +361 -0
  489. package/dist/skills/typescript-discipline/SKILL.md +50 -0
  490. package/dist/skills/typescript-discipline/references/patterns.md +294 -0
  491. package/dist/skills/unslop/SKILL.md +101 -0
  492. package/dist/utils/canonical-path.d.ts +28 -0
  493. package/dist/utils/canonical-path.d.ts.map +1 -0
  494. package/dist/utils/canonical-path.js +90 -0
  495. package/dist/utils/canonical-path.js.map +1 -0
  496. package/dist/utils/child-process.d.ts +12 -1
  497. package/dist/utils/child-process.d.ts.map +1 -1
  498. package/dist/utils/child-process.js +25 -8
  499. package/dist/utils/child-process.js.map +1 -1
  500. package/dist/utils/clipboard-native.d.ts +1 -0
  501. package/dist/utils/clipboard-native.d.ts.map +1 -1
  502. package/dist/utils/clipboard-native.js.map +1 -1
  503. package/dist/utils/clipboard.d.ts +2 -0
  504. package/dist/utils/clipboard.d.ts.map +1 -1
  505. package/dist/utils/clipboard.js +53 -9
  506. package/dist/utils/clipboard.js.map +1 -1
  507. package/dist/utils/exif-orientation.d.ts.map +1 -1
  508. package/dist/utils/exif-orientation.js +2 -3
  509. package/dist/utils/exif-orientation.js.map +1 -1
  510. package/dist/utils/paths.d.ts +2 -7
  511. package/dist/utils/paths.d.ts.map +1 -1
  512. package/dist/utils/paths.js +13 -15
  513. package/dist/utils/paths.js.map +1 -1
  514. package/dist/utils/shell.d.ts.map +1 -1
  515. package/dist/utils/shell.js +6 -4
  516. package/dist/utils/shell.js.map +1 -1
  517. package/dist/utils/tools-manager.d.ts.map +1 -1
  518. package/dist/utils/tools-manager.js +3 -5
  519. package/dist/utils/tools-manager.js.map +1 -1
  520. package/dist/utils/version-check.d.ts.map +1 -1
  521. package/dist/utils/version-check.js +3 -1
  522. package/dist/utils/version-check.js.map +1 -1
  523. package/docs/attachable-sessions.md +79 -0
  524. package/docs/compaction.md +29 -24
  525. package/docs/containerization.md +23 -23
  526. package/docs/custom-provider.md +66 -32
  527. package/docs/development.md +9 -9
  528. package/docs/docs.json +6 -2
  529. package/docs/duet.md +42 -0
  530. package/docs/environment-variables.md +88 -0
  531. package/docs/extensions.md +278 -65
  532. package/docs/index.md +12 -10
  533. package/docs/json.md +12 -8
  534. package/docs/keybindings.md +8 -5
  535. package/docs/llama-cpp.md +99 -0
  536. package/docs/models.md +19 -8
  537. package/docs/packages.md +43 -42
  538. package/docs/prompt-templates.md +5 -4
  539. package/docs/providers.md +45 -11
  540. package/docs/quickstart.md +33 -33
  541. package/docs/rpc.md +190 -19
  542. package/docs/sdk.md +18 -15
  543. package/docs/security.md +18 -18
  544. package/docs/session-format.md +53 -15
  545. package/docs/sessions.md +17 -14
  546. package/docs/settings.md +26 -19
  547. package/docs/shell-aliases.md +2 -2
  548. package/docs/skills.md +12 -11
  549. package/docs/terminal-setup.md +12 -12
  550. package/docs/termux.md +6 -6
  551. package/docs/themes.md +11 -11
  552. package/docs/tmux.md +4 -4
  553. package/docs/tui.md +46 -31
  554. package/docs/usage.md +53 -63
  555. package/docs/windows.md +2 -2
  556. package/examples/extensions/custom-compaction.ts +4 -0
  557. package/examples/extensions/custom-provider-anthropic/index.ts +9 -3
  558. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  559. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  560. package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
  561. package/examples/extensions/gondolin/package.json +2 -2
  562. package/examples/extensions/handoff.ts +9 -1
  563. package/examples/extensions/kimi-deferred-tools.ts +61 -0
  564. package/examples/extensions/message-renderer.ts +2 -2
  565. package/examples/extensions/overlay-qa-tests.ts +3 -3
  566. package/examples/extensions/sandbox/package.json +1 -1
  567. package/examples/extensions/summarize.ts +3 -0
  568. package/examples/extensions/with-deps/package.json +1 -1
  569. package/examples/sdk/02-custom-model.ts +5 -8
  570. package/examples/sdk/09-api-keys-and-oauth.ts +15 -31
  571. package/examples/sdk/12-full-control.ts +9 -12
  572. package/hooks/gsd/draht-quality-gate.js +3 -3
  573. package/package.json +14 -11
  574. package/prompts/commands/atomic-commit.md +1 -12
  575. package/prompts/commands/brainstorm.md +12 -15
  576. package/prompts/commands/create-verification-skill.md +108 -0
  577. package/prompts/commands/discuss-phase.md +3 -14
  578. package/prompts/commands/execute-phase.md +3 -11
  579. package/prompts/commands/fix.md +41 -18
  580. package/prompts/commands/grill.md +66 -0
  581. package/prompts/commands/init-project.md +5 -15
  582. package/prompts/commands/map-codebase.md +1 -13
  583. package/prompts/commands/new-project.md +5 -15
  584. package/prompts/commands/next-milestone.md +1 -13
  585. package/prompts/commands/orchestrate.md +1 -1
  586. package/prompts/commands/pause-work.md +1 -13
  587. package/prompts/commands/plan-phase.md +2 -11
  588. package/prompts/commands/progress.md +0 -13
  589. package/prompts/commands/quick.md +3 -11
  590. package/prompts/commands/resolve-conflicts.md +71 -0
  591. package/prompts/commands/resume-work.md +0 -13
  592. package/prompts/commands/review.md +4 -13
  593. package/prompts/commands/triage.md +159 -0
  594. package/prompts/commands/verify-work.md +4 -14
  595. package/prompts/commands/why.md +135 -0
  596. package/skills/atomic-reasoning/SKILL.md +115 -0
  597. package/skills/blast-radius/SKILL.md +55 -0
  598. package/skills/epistemics/SKILL.md +99 -0
  599. package/skills/hexagon-animation/SKILL.md +49 -0
  600. package/skills/hexagon-animation/generate.mjs +81 -0
  601. package/skills/hexagon-animation/template.html +361 -0
  602. package/skills/typescript-discipline/SKILL.md +50 -0
  603. package/skills/typescript-discipline/references/patterns.md +294 -0
  604. package/skills/unslop/SKILL.md +101 -0
  605. package/dist/core/provider-display-names.d.ts +0 -2
  606. package/dist/core/provider-display-names.d.ts.map +0 -1
  607. package/dist/core/provider-display-names.js +0 -36
  608. package/dist/core/provider-display-names.js.map +0 -1
  609. package/dist/prompts/agents/build.md +0 -86
  610. package/dist/prompts/agents/plan.md +0 -79
  611. package/dist/prompts/agents/verify.md +0 -69
  612. package/prompts/agents/build.md +0 -86
  613. package/prompts/agents/plan.md +0 -79
  614. package/prompts/agents/verify.md +0 -69
@@ -0,0 +1,369 @@
1
+ /**
2
+ * Startup self-test (R44-SBX.4) -- the only thing that may report `available`.
3
+ *
4
+ * Phase 28 established the pattern: prove the sandbox holds before trusting it
5
+ * (`packages/rlm/src/session.ts` sends a `self_test` message and refuses the
6
+ * session unless the driver reports network and file reads actually blocked).
7
+ * This is the same idea applied to a shell backend, with one addition that
8
+ * turned out to matter more than the original probe.
9
+ *
10
+ * ## Why the probe is two-sided
11
+ *
12
+ * The obvious self-test -- "try to write outside the allowlist, expect failure"
13
+ * -- passes for the *worst possible* backend. Measured on macOS: a profile with
14
+ * a syntax error makes `sandbox-exec` exit 65 **without ever running the
15
+ * command**. The write does not happen, no file appears, and a one-sided probe
16
+ * concludes "confined" about a backend that cannot confine anything. It would
17
+ * then report `available`, and every downstream permission decision would
18
+ * inherit that lie -- precisely the failure this requirement exists to prevent.
19
+ *
20
+ * So every probe carries a positive control as well as a negative one:
21
+ *
22
+ * | control | probe | proves |
23
+ * |----------|----------------------------------|---------------------------------|
24
+ * | positive | write *inside* the allowlist | the sandbox ran the command |
25
+ * | negative | write *outside* the allowlist | writes are actually confined |
26
+ * | positive | loopback connect, network **on** | the network probe can connect |
27
+ * | negative | loopback connect, network **off**| the network is actually cut |
28
+ * | negative | exec a setuid-root binary | privileges cannot be acquired |
29
+ *
30
+ * A broken profile fails the positive controls. An over-permissive profile
31
+ * (`(allow default)` and nothing else) fails the negative ones. Both answer
32
+ * `unavailable`. There is no third outcome.
33
+ *
34
+ * ## The privilege-escalation probe, and what it is actually worth
35
+ *
36
+ * `SandboxPolicy.allowPrivilegeEscalation` is typed as the literal `false`
37
+ * precisely because it is an invariant no caller may widen -- yet the self-test
38
+ * used to grant `available` without testing it at all, and `linux.ts` leans on
39
+ * this self-test as its entire safety argument. So the probe now attempts the
40
+ * escalation from inside the throwaway sandbox and reports two facts:
41
+ *
42
+ * - **`privilegeEscalation`** -- it locates a setuid-root binary on the host
43
+ * (`sudo`, then `su`) and executes it. Three outcomes matter:
44
+ * `escalated:*` (it acquired uid 0 -- an outright failure), `exec-refused:*`
45
+ * (the kernel refused to `exec` a setuid binary from inside the sandbox), and
46
+ * `ran:*` (it executed but did not acquire privileges).
47
+ * - **`noNewPrivs`** -- on Linux, `NoNewPrivs` from `/proc/self/status`. `1` is
48
+ * the kernel's own guarantee that no `exec` can gain privileges, which is
49
+ * exactly the mechanism `linux.ts` claims bubblewrap gives it (and that
50
+ * Landlock requires); `not-linux` elsewhere.
51
+ *
52
+ * The verdict is fail-closed and requires *evidence*, not absence of failure:
53
+ * `escalated:*` and `NoNewPrivs: 0` are failures, and a pass needs either
54
+ * `exec-refused:*` or `NoNewPrivs: 1`. A bare `ran:*` is deliberately **not**
55
+ * enough -- on a host where the user simply has no `sudo` rights, an entirely
56
+ * unconfined process produces the same `ran:*`, which is the one-sided-probe
57
+ * mistake this module already refuses to make elsewhere.
58
+ *
59
+ * Measured on macOS 25.5: `exec` of `/usr/bin/sudo` from inside *any* seatbelt
60
+ * sandbox fails `EPERM` (`exec-refused:EPERM`), while the same `exec` outside
61
+ * one succeeds -- so on darwin the negative control has a real positive control
62
+ * behind it. On Linux under bubblewrap the evidence is `NoNewPrivs: 1`; the
63
+ * `unshare` fallback establishes neither and therefore reports `unavailable`,
64
+ * which is the fail-closed reading of an invariant that backend cannot show it
65
+ * holds.
66
+ *
67
+ * ## Evidence comes from outside the sandbox
68
+ *
69
+ * The probe reports what it observed, but the probe runs inside the thing under
70
+ * test, so its word alone is not evidence. Every negative control is confirmed
71
+ * from the parent: the file the probe was told to create must not exist on disk
72
+ * afterwards, and the loopback listener -- a real server in this process -- must
73
+ * not have accepted a connection. A backend that lets a write through but
74
+ * garbles its own stderr still fails.
75
+ *
76
+ * ## Why network is probed even for a network-on session
77
+ *
78
+ * The self-test runs once per backend instance and covers both axes, so the
79
+ * cached answer is valid for any policy the session later uses. If network-off
80
+ * enforcement is broken while write confinement works, the backend reports
81
+ * `unavailable` even for sessions that would have run with network on. That is
82
+ * deliberately conservative: `available` is a claim about the backend, and half
83
+ * a backend is not one.
84
+ */
85
+ import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
86
+ import { createServer } from "node:net";
87
+ import { tmpdir } from "node:os";
88
+ import { join } from "node:path";
89
+ import { SANDBOX_POLICY_VERSION } from "./policy.js";
90
+ import { resolveRealPath } from "./real-path.js";
91
+ /** Prefixes the probe's single result line so it survives interleaved tool output. */
92
+ const PROBE_MARKER = "__DRAHT_SANDBOX_PROBE__";
93
+ const PROBE_CONNECT_TIMEOUT_MS = 3_000;
94
+ /** Seconds. Generous: a cold `sandbox-exec` + node start on a loaded machine is still far under this. */
95
+ const DEFAULT_PROBE_TIMEOUT_SECONDS = 30;
96
+ /**
97
+ * The probe. Written to disk outside the writable area (so reaching it also
98
+ * exercises read allow-all) and run through the backend's real `exec` path --
99
+ * same wrapper, same profile generation, same env -- because a self-test that
100
+ * takes a different path than production tests a different thing.
101
+ *
102
+ * Node rather than shell built-ins: `process.execPath` is guaranteed present and
103
+ * its behaviour does not vary with which `sh` the host resolved, so a "blocked"
104
+ * verdict is never really "this shell has no `/dev/tcp`".
105
+ */
106
+ const PROBE_SOURCE = `import { writeFileSync, readFileSync, statSync } from "node:fs";
107
+ import { spawnSync } from "node:child_process";
108
+ import { connect } from "node:net";
109
+
110
+ const config = JSON.parse(readFileSync(process.argv[2], "utf8"));
111
+ const result = {
112
+ insideWrite: "not-attempted",
113
+ outsideWrite: "not-attempted",
114
+ loopback: "not-attempted",
115
+ privilegeEscalation: "not-attempted",
116
+ noNewPrivs: "not-attempted",
117
+ };
118
+
119
+ function attempt(file) {
120
+ try {
121
+ writeFileSync(file, "probe");
122
+ return "wrote";
123
+ } catch (err) {
124
+ return "blocked:" + (err.code ?? err.message);
125
+ }
126
+ }
127
+
128
+ /** Binaries whose whole purpose is to run as another user. Only ones we can invoke harmlessly. */
129
+ const SETUID_CANDIDATES = ["/usr/bin/sudo", "/bin/sudo", "/usr/local/bin/sudo", "/usr/bin/su", "/bin/su"];
130
+
131
+ function findSetuidRoot() {
132
+ const found = [];
133
+ for (const path of SETUID_CANDIDATES) {
134
+ try {
135
+ const stat = statSync(path);
136
+ if (stat.uid === 0 && (stat.mode & 0o4000) !== 0) found.push(path);
137
+ } catch {}
138
+ }
139
+ return found;
140
+ }
141
+
142
+ function attemptEscalation() {
143
+ const found = findSetuidRoot();
144
+ if (found.length === 0) return "no-setuid-root-binary";
145
+ const sudo = found.find((path) => path.endsWith("/sudo"));
146
+ const bin = sudo ?? found[0];
147
+ // -n never prompts, so this cannot hang on a password. A printed uid of 0 means
148
+ // the escalation actually happened, which is the thing being detected.
149
+ const args = sudo ? ["-n", "id", "-u"] : ["--version"];
150
+ let run;
151
+ try {
152
+ run = spawnSync(bin, args, { encoding: "utf8", timeout: 5000, stdio: ["ignore", "pipe", "pipe"] });
153
+ } catch (err) {
154
+ return "attempt-failed:" + (err.code ?? err.message);
155
+ }
156
+ if (run.error) {
157
+ const code = run.error.code ?? run.error.message;
158
+ // EPERM/EACCES at exec time is the sandbox refusing to run a setuid binary.
159
+ if (code === "EPERM" || code === "EACCES") return "exec-refused:" + code;
160
+ return "attempt-failed:" + code;
161
+ }
162
+ if (sudo && run.status === 0 && (run.stdout ?? "").trim() === "0") return "escalated:euid=0";
163
+ return "ran:" + bin + ":exit=" + run.status;
164
+ }
165
+
166
+ function readNoNewPrivs() {
167
+ if (process.platform !== "linux") return "not-linux";
168
+ try {
169
+ const match = /^NoNewPrivs:\\s*(\\d+)/m.exec(readFileSync("/proc/self/status", "utf8"));
170
+ return match ? match[1] : "unreported";
171
+ } catch (err) {
172
+ return "unreadable:" + (err.code ?? err.message);
173
+ }
174
+ }
175
+
176
+ result.insideWrite = attempt(config.insideFile);
177
+ result.outsideWrite = attempt(config.outsideFile);
178
+ result.privilegeEscalation = attemptEscalation();
179
+ result.noNewPrivs = readNoNewPrivs();
180
+
181
+ result.loopback = await new Promise((resolve) => {
182
+ const socket = connect({ host: "127.0.0.1", port: config.loopbackPort });
183
+ let settled = false;
184
+ const finish = (value) => {
185
+ if (settled) return;
186
+ settled = true;
187
+ socket.destroy();
188
+ resolve(value);
189
+ };
190
+ socket.setTimeout(config.connectTimeoutMs, () => finish("blocked:ETIMEDOUT"));
191
+ socket.once("connect", () => finish("connected"));
192
+ socket.once("error", (err) => finish("blocked:" + (err.code ?? err.message)));
193
+ });
194
+
195
+ process.stdout.write("\\n" + config.marker + JSON.stringify(result) + "\\n");
196
+ `;
197
+ /** Single-quoted shell word: the only character needing care inside `'...'` is `'` itself. */
198
+ function shellQuote(value) {
199
+ return `'${value.replace(/'/g, `'\\''`)}'`;
200
+ }
201
+ function probePolicy(writeRoot, network) {
202
+ return Object.freeze({
203
+ version: SANDBOX_POLICY_VERSION,
204
+ writePaths: Object.freeze([writeRoot]),
205
+ read: "allow-all",
206
+ network,
207
+ allowPrivilegeEscalation: false,
208
+ });
209
+ }
210
+ function parseReport(output) {
211
+ const index = output.lastIndexOf(PROBE_MARKER);
212
+ if (index === -1)
213
+ return null;
214
+ const line = output.slice(index + PROBE_MARKER.length).split("\n", 1)[0];
215
+ try {
216
+ const parsed = JSON.parse(line ?? "");
217
+ if (parsed && typeof parsed === "object")
218
+ return parsed;
219
+ return null;
220
+ }
221
+ catch {
222
+ return null;
223
+ }
224
+ }
225
+ function unavailable(backendName, detail) {
226
+ return { available: false, reason: `${backendName} sandbox self-test failed: ${detail}` };
227
+ }
228
+ /**
229
+ * The `allowPrivilegeEscalation: false` invariant, checked against what the probe
230
+ * actually observed. Returns the failure detail, or `null` when the invariant is
231
+ * demonstrated. See the module doc for why `ran:*` on its own is not evidence.
232
+ */
233
+ function privilegeEscalationFailure(report) {
234
+ const escalation = report.privilegeEscalation;
235
+ const noNewPrivs = report.noNewPrivs;
236
+ if (escalation === undefined || noNewPrivs === undefined || escalation === "not-attempted") {
237
+ // Positive control for this probe: an older or garbled probe that never ran
238
+ // the escalation attempt must not be read as "escalation is impossible".
239
+ return `the probe did not report a privilege-escalation attempt (privilegeEscalation: ${JSON.stringify(escalation)}), so the allowPrivilegeEscalation invariant was not tested`;
240
+ }
241
+ if (escalation.startsWith("escalated")) {
242
+ return `a setuid-root binary acquired privileges inside the sandbox (${escalation}), so the allowPrivilegeEscalation invariant does not hold`;
243
+ }
244
+ if (noNewPrivs === "0") {
245
+ return "the kernel reports NoNewPrivs: 0 inside the sandbox, so an exec can still gain privileges through a setuid binary";
246
+ }
247
+ const proven = escalation.startsWith("exec-refused:") || noNewPrivs === "1";
248
+ if (!proven) {
249
+ return `the allowPrivilegeEscalation invariant could not be demonstrated (escalation probe: ${escalation}, NoNewPrivs: ${noNewPrivs}) -- the sandbox neither refused to exec a setuid-root binary nor set PR_SET_NO_NEW_PRIVS, so a host that merely lacks sudo rights would look identical`;
250
+ }
251
+ return null;
252
+ }
253
+ /**
254
+ * Runs the self-test in a throwaway sandbox and returns the status the backend
255
+ * may report. Never throws: any error is itself a failed self-test, and a
256
+ * self-test that blew up is not one that passed.
257
+ */
258
+ export async function runSandboxSelfTest(options) {
259
+ const { backendName } = options;
260
+ const timeoutSeconds = options.timeoutSeconds ?? DEFAULT_PROBE_TIMEOUT_SECONDS;
261
+ let root;
262
+ let server;
263
+ try {
264
+ const created = mkdtempSync(join(tmpdir(), "draht-sandbox-selftest-"));
265
+ // Real-path the throwaway root for the same reason R44-SBX.3 real-paths
266
+ // policy paths: on macOS `os.tmpdir()` is `/var/folders/...`, a symlink to
267
+ // `/private/var/folders/...`, and the kernel matches the resolved vnode. An
268
+ // unresolved root here makes the *positive* control fail -- which is how
269
+ // this was found, and a good argument for having a positive control.
270
+ const resolvedRoot = resolveRealPath(created, { base: created });
271
+ if (!resolvedRoot.ok) {
272
+ rmSync(created, { recursive: true, force: true });
273
+ return unavailable(backendName, `could not resolve the throwaway probe directory: ${resolvedRoot.reason}`);
274
+ }
275
+ root = resolvedRoot.path;
276
+ const inside = join(root, "inside");
277
+ const outside = join(root, "outside");
278
+ mkdirSync(inside);
279
+ mkdirSync(outside);
280
+ let accepted = 0;
281
+ server = createServer((socket) => {
282
+ accepted += 1;
283
+ socket.destroy();
284
+ });
285
+ const listening = server;
286
+ await new Promise((resolve, reject) => {
287
+ listening.once("error", reject);
288
+ listening.listen(0, "127.0.0.1", resolve);
289
+ });
290
+ const address = listening.address();
291
+ const port = typeof address === "object" && address !== null ? address.port : 0;
292
+ if (port === 0)
293
+ return unavailable(backendName, "could not open a loopback listener for the network probe");
294
+ const probeRoot = root;
295
+ const probeScript = join(probeRoot, "probe.mjs");
296
+ writeFileSync(probeScript, PROBE_SOURCE, { mode: 0o600 });
297
+ /** One phase: writes a fresh config, runs the probe, returns what actually happened. */
298
+ const runPhase = async (phase) => {
299
+ const insideFile = join(inside, `${phase}.txt`);
300
+ const outsideFile = join(outside, `${phase}.txt`);
301
+ const configFile = join(probeRoot, `${phase}.json`);
302
+ writeFileSync(configFile, JSON.stringify({
303
+ insideFile,
304
+ outsideFile,
305
+ loopbackPort: port,
306
+ connectTimeoutMs: PROBE_CONNECT_TIMEOUT_MS,
307
+ marker: PROBE_MARKER,
308
+ }), { mode: 0o600 });
309
+ const connectionsBefore = accepted;
310
+ const command = `${shellQuote(process.execPath)} ${shellQuote(probeScript)} ${shellQuote(configFile)}`;
311
+ const { output } = await options.run(command, inside, probePolicy(inside, phase === "network-off" ? "off" : "on"), timeoutSeconds);
312
+ const report = parseReport(output);
313
+ if (!report) {
314
+ // No marker line means the probe never ran to completion. A broken
315
+ // profile lands here (sandbox-exec exits before exec'ing anything) --
316
+ // the single most important case not to mistake for confinement.
317
+ return unavailable(backendName, `the ${phase} probe never reported a result, so the sandbox could not be shown to run commands at all (output: ${JSON.stringify(output.slice(-400))})`);
318
+ }
319
+ return { report, outsideFile, connectionsBefore };
320
+ };
321
+ // --- Phase 1: network on. Positive controls plus the write negative control.
322
+ const first = await runPhase("network-on");
323
+ if ("available" in first)
324
+ return first;
325
+ if (first.report.insideWrite !== "wrote") {
326
+ return unavailable(backendName, `a write inside the allowlist was rejected (${first.report.insideWrite}) -- the profile does not grant the access the policy describes`);
327
+ }
328
+ if (first.report.outsideWrite === "wrote" || existsSync(first.outsideFile)) {
329
+ return unavailable(backendName, `a write outside the allowlist succeeded (${first.report.outsideWrite}), so the sandbox does not confine writes`);
330
+ }
331
+ if (first.report.loopback !== "connected") {
332
+ return unavailable(backendName, `the loopback probe could not connect with network allowed (${first.report.loopback}), so network confinement cannot be demonstrated either way`);
333
+ }
334
+ if (accepted === first.connectionsBefore) {
335
+ return unavailable(backendName, "the loopback listener saw no connection with network allowed, so the network probe proves nothing");
336
+ }
337
+ const escalationFailure = privilegeEscalationFailure(first.report);
338
+ if (escalationFailure)
339
+ return unavailable(backendName, escalationFailure);
340
+ // --- Phase 2: network off. The network negative control.
341
+ const second = await runPhase("network-off");
342
+ if ("available" in second)
343
+ return second;
344
+ if (second.report.outsideWrite === "wrote" || existsSync(second.outsideFile)) {
345
+ return unavailable(backendName, "a write outside the allowlist succeeded with network off");
346
+ }
347
+ if (second.report.loopback === "connected") {
348
+ return unavailable(backendName, "a loopback connection succeeded while the policy had network off");
349
+ }
350
+ if (accepted !== second.connectionsBefore) {
351
+ return unavailable(backendName, "the loopback listener accepted a connection while the policy had network off, so the network denial does not hold");
352
+ }
353
+ const escalationFailureOff = privilegeEscalationFailure(second.report);
354
+ if (escalationFailureOff)
355
+ return unavailable(backendName, `${escalationFailureOff} (with network off)`);
356
+ return { available: true };
357
+ }
358
+ catch (err) {
359
+ return unavailable(backendName, `the self-test itself failed: ${err instanceof Error ? err.message : String(err)}`);
360
+ }
361
+ finally {
362
+ const openServer = server;
363
+ if (openServer)
364
+ await new Promise((resolve) => openServer.close(() => resolve()));
365
+ if (root)
366
+ rmSync(root, { recursive: true, force: true });
367
+ }
368
+ }
369
+ //# sourceMappingURL=self-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"self-test.js","sourceRoot":"","sources":["../../../src/core/sandbox/self-test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmFG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpF,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,sBAAsB,EAAsB,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,sFAAsF;AACtF,MAAM,YAAY,GAAG,yBAAyB,CAAC;AAE/C,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAEvC,yGAAyG;AACzG,MAAM,6BAA6B,GAAG,EAAE,CAAC;AAEzC;;;;;;;;;GASG;AACH,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0FpB,CAAC;AAgCF,8FAA8F;AAC9F,SAAS,UAAU,CAAC,KAAa;IAChC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC;AAC5C,CAAC;AAED,SAAS,WAAW,CAAC,SAAiB,EAAE,OAAqB;IAC5D,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,sBAAsB;QAC/B,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC;QACtC,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AC,CAAC;QACrG,CAAC;QACD,IAAI,QAAQ,KAAK,MAAM,CAAC,iBAAiB,EAAE,CAAC;YAC3C,OAAO,WAAW,CACjB,WAAW,EACX,mHAAmH,CACnH,CAAC;QACH,CAAC;QACD,MAAM,oBAAoB,GAAG,0BAA0B,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACvE,IAAI,oBAAoB;YAAE,OAAO,WAAW,CAAC,WAAW,EAAE,GAAG,oBAAoB,qBAAqB,CAAC,CAAC;QAExG,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,OAAO,WAAW,CACjB,WAAW,EACX,gCAAgC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAClF,CAAC;IACH,CAAC;YAAS,CAAC;QACV,MAAM,UAAU,GAAG,MAAM,CAAC;QAC1B,IAAI,UAAU;YAAE,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACxF,IAAI,IAAI;YAAE,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;AACF,CAAC","sourcesContent":["/**\n * Startup self-test (R44-SBX.4) -- the only thing that may report `available`.\n *\n * Phase 28 established the pattern: prove the sandbox holds before trusting it\n * (`packages/rlm/src/session.ts` sends a `self_test` message and refuses the\n * session unless the driver reports network and file reads actually blocked).\n * This is the same idea applied to a shell backend, with one addition that\n * turned out to matter more than the original probe.\n *\n * ## Why the probe is two-sided\n *\n * The obvious self-test -- \"try to write outside the allowlist, expect failure\"\n * -- passes for the *worst possible* backend. Measured on macOS: a profile with\n * a syntax error makes `sandbox-exec` exit 65 **without ever running the\n * command**. The write does not happen, no file appears, and a one-sided probe\n * concludes \"confined\" about a backend that cannot confine anything. It would\n * then report `available`, and every downstream permission decision would\n * inherit that lie -- precisely the failure this requirement exists to prevent.\n *\n * So every probe carries a positive control as well as a negative one:\n *\n * | control | probe | proves |\n * |----------|----------------------------------|---------------------------------|\n * | positive | write *inside* the allowlist | the sandbox ran the command |\n * | negative | write *outside* the allowlist | writes are actually confined |\n * | positive | loopback connect, network **on** | the network probe can connect |\n * | negative | loopback connect, network **off**| the network is actually cut |\n * | negative | exec a setuid-root binary | privileges cannot be acquired |\n *\n * A broken profile fails the positive controls. An over-permissive profile\n * (`(allow default)` and nothing else) fails the negative ones. Both answer\n * `unavailable`. There is no third outcome.\n *\n * ## The privilege-escalation probe, and what it is actually worth\n *\n * `SandboxPolicy.allowPrivilegeEscalation` is typed as the literal `false`\n * precisely because it is an invariant no caller may widen -- yet the self-test\n * used to grant `available` without testing it at all, and `linux.ts` leans on\n * this self-test as its entire safety argument. So the probe now attempts the\n * escalation from inside the throwaway sandbox and reports two facts:\n *\n * - **`privilegeEscalation`** -- it locates a setuid-root binary on the host\n * (`sudo`, then `su`) and executes it. Three outcomes matter:\n * `escalated:*` (it acquired uid 0 -- an outright failure), `exec-refused:*`\n * (the kernel refused to `exec` a setuid binary from inside the sandbox), and\n * `ran:*` (it executed but did not acquire privileges).\n * - **`noNewPrivs`** -- on Linux, `NoNewPrivs` from `/proc/self/status`. `1` is\n * the kernel's own guarantee that no `exec` can gain privileges, which is\n * exactly the mechanism `linux.ts` claims bubblewrap gives it (and that\n * Landlock requires); `not-linux` elsewhere.\n *\n * The verdict is fail-closed and requires *evidence*, not absence of failure:\n * `escalated:*` and `NoNewPrivs: 0` are failures, and a pass needs either\n * `exec-refused:*` or `NoNewPrivs: 1`. A bare `ran:*` is deliberately **not**\n * enough -- on a host where the user simply has no `sudo` rights, an entirely\n * unconfined process produces the same `ran:*`, which is the one-sided-probe\n * mistake this module already refuses to make elsewhere.\n *\n * Measured on macOS 25.5: `exec` of `/usr/bin/sudo` from inside *any* seatbelt\n * sandbox fails `EPERM` (`exec-refused:EPERM`), while the same `exec` outside\n * one succeeds -- so on darwin the negative control has a real positive control\n * behind it. On Linux under bubblewrap the evidence is `NoNewPrivs: 1`; the\n * `unshare` fallback establishes neither and therefore reports `unavailable`,\n * which is the fail-closed reading of an invariant that backend cannot show it\n * holds.\n *\n * ## Evidence comes from outside the sandbox\n *\n * The probe reports what it observed, but the probe runs inside the thing under\n * test, so its word alone is not evidence. Every negative control is confirmed\n * from the parent: the file the probe was told to create must not exist on disk\n * afterwards, and the loopback listener -- a real server in this process -- must\n * not have accepted a connection. A backend that lets a write through but\n * garbles its own stderr still fails.\n *\n * ## Why network is probed even for a network-on session\n *\n * The self-test runs once per backend instance and covers both axes, so the\n * cached answer is valid for any policy the session later uses. If network-off\n * enforcement is broken while write confinement works, the backend reports\n * `unavailable` even for sessions that would have run with network on. That is\n * deliberately conservative: `available` is a claim about the backend, and half\n * a backend is not one.\n */\n\nimport { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from \"node:fs\";\nimport { createServer, type Server } from \"node:net\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport type { SandboxStatus } from \"./executor.ts\";\nimport { SANDBOX_POLICY_VERSION, type SandboxPolicy } from \"./policy.ts\";\nimport { resolveRealPath } from \"./real-path.ts\";\n\n/** Prefixes the probe's single result line so it survives interleaved tool output. */\nconst PROBE_MARKER = \"__DRAHT_SANDBOX_PROBE__\";\n\nconst PROBE_CONNECT_TIMEOUT_MS = 3_000;\n\n/** Seconds. Generous: a cold `sandbox-exec` + node start on a loaded machine is still far under this. */\nconst DEFAULT_PROBE_TIMEOUT_SECONDS = 30;\n\n/**\n * The probe. Written to disk outside the writable area (so reaching it also\n * exercises read allow-all) and run through the backend's real `exec` path --\n * same wrapper, same profile generation, same env -- because a self-test that\n * takes a different path than production tests a different thing.\n *\n * Node rather than shell built-ins: `process.execPath` is guaranteed present and\n * its behaviour does not vary with which `sh` the host resolved, so a \"blocked\"\n * verdict is never really \"this shell has no `/dev/tcp`\".\n */\nconst PROBE_SOURCE = `import { writeFileSync, readFileSync, statSync } from \"node:fs\";\nimport { spawnSync } from \"node:child_process\";\nimport { connect } from \"node:net\";\n\nconst config = JSON.parse(readFileSync(process.argv[2], \"utf8\"));\nconst result = {\n\tinsideWrite: \"not-attempted\",\n\toutsideWrite: \"not-attempted\",\n\tloopback: \"not-attempted\",\n\tprivilegeEscalation: \"not-attempted\",\n\tnoNewPrivs: \"not-attempted\",\n};\n\nfunction attempt(file) {\n\ttry {\n\t\twriteFileSync(file, \"probe\");\n\t\treturn \"wrote\";\n\t} catch (err) {\n\t\treturn \"blocked:\" + (err.code ?? err.message);\n\t}\n}\n\n/** Binaries whose whole purpose is to run as another user. Only ones we can invoke harmlessly. */\nconst SETUID_CANDIDATES = [\"/usr/bin/sudo\", \"/bin/sudo\", \"/usr/local/bin/sudo\", \"/usr/bin/su\", \"/bin/su\"];\n\nfunction findSetuidRoot() {\n\tconst found = [];\n\tfor (const path of SETUID_CANDIDATES) {\n\t\ttry {\n\t\t\tconst stat = statSync(path);\n\t\t\tif (stat.uid === 0 && (stat.mode & 0o4000) !== 0) found.push(path);\n\t\t} catch {}\n\t}\n\treturn found;\n}\n\nfunction attemptEscalation() {\n\tconst found = findSetuidRoot();\n\tif (found.length === 0) return \"no-setuid-root-binary\";\n\tconst sudo = found.find((path) => path.endsWith(\"/sudo\"));\n\tconst bin = sudo ?? found[0];\n\t// -n never prompts, so this cannot hang on a password. A printed uid of 0 means\n\t// the escalation actually happened, which is the thing being detected.\n\tconst args = sudo ? [\"-n\", \"id\", \"-u\"] : [\"--version\"];\n\tlet run;\n\ttry {\n\t\trun = spawnSync(bin, args, { encoding: \"utf8\", timeout: 5000, stdio: [\"ignore\", \"pipe\", \"pipe\"] });\n\t} catch (err) {\n\t\treturn \"attempt-failed:\" + (err.code ?? err.message);\n\t}\n\tif (run.error) {\n\t\tconst code = run.error.code ?? run.error.message;\n\t\t// EPERM/EACCES at exec time is the sandbox refusing to run a setuid binary.\n\t\tif (code === \"EPERM\" || code === \"EACCES\") return \"exec-refused:\" + code;\n\t\treturn \"attempt-failed:\" + code;\n\t}\n\tif (sudo && run.status === 0 && (run.stdout ?? \"\").trim() === \"0\") return \"escalated:euid=0\";\n\treturn \"ran:\" + bin + \":exit=\" + run.status;\n}\n\nfunction readNoNewPrivs() {\n\tif (process.platform !== \"linux\") return \"not-linux\";\n\ttry {\n\t\tconst match = /^NoNewPrivs:\\\\s*(\\\\d+)/m.exec(readFileSync(\"/proc/self/status\", \"utf8\"));\n\t\treturn match ? match[1] : \"unreported\";\n\t} catch (err) {\n\t\treturn \"unreadable:\" + (err.code ?? err.message);\n\t}\n}\n\nresult.insideWrite = attempt(config.insideFile);\nresult.outsideWrite = attempt(config.outsideFile);\nresult.privilegeEscalation = attemptEscalation();\nresult.noNewPrivs = readNoNewPrivs();\n\nresult.loopback = await new Promise((resolve) => {\n\tconst socket = connect({ host: \"127.0.0.1\", port: config.loopbackPort });\n\tlet settled = false;\n\tconst finish = (value) => {\n\t\tif (settled) return;\n\t\tsettled = true;\n\t\tsocket.destroy();\n\t\tresolve(value);\n\t};\n\tsocket.setTimeout(config.connectTimeoutMs, () => finish(\"blocked:ETIMEDOUT\"));\n\tsocket.once(\"connect\", () => finish(\"connected\"));\n\tsocket.once(\"error\", (err) => finish(\"blocked:\" + (err.code ?? err.message)));\n});\n\nprocess.stdout.write(\"\\\\n\" + config.marker + JSON.stringify(result) + \"\\\\n\");\n`;\n\ninterface ProbeReport {\n\tinsideWrite: string;\n\toutsideWrite: string;\n\tloopback: string;\n\t/** See the module doc: `escalated:*` / `exec-refused:*` / `ran:*` / `no-setuid-root-binary`. */\n\tprivilegeEscalation?: string;\n\t/** Linux `/proc/self/status` `NoNewPrivs`, or `not-linux`. */\n\tnoNewPrivs?: string;\n}\n\n/**\n * Runs one command through the backend under test and returns its exit code and\n * combined output. Backends pass their own `exec` here so the self-test and\n * production execution cannot drift apart.\n */\nexport type SandboxSelfTestRunner = (\n\tcommand: string,\n\tcwd: string,\n\tpolicy: SandboxPolicy,\n\ttimeoutSeconds: number,\n) => Promise<{ exitCode: number | null; output: string }>;\n\nexport interface SandboxSelfTestOptions {\n\t/** Backend name, used only to make the failure reason say who failed. */\n\tbackendName: string;\n\trun: SandboxSelfTestRunner;\n\t/** Seconds. Defaults to 30. */\n\ttimeoutSeconds?: number;\n}\n\n/** Single-quoted shell word: the only character needing care inside `'...'` is `'` itself. */\nfunction shellQuote(value: string): string {\n\treturn `'${value.replace(/'/g, `'\\\\''`)}'`;\n}\n\nfunction probePolicy(writeRoot: string, network: \"on\" | \"off\"): SandboxPolicy {\n\treturn Object.freeze({\n\t\tversion: SANDBOX_POLICY_VERSION,\n\t\twritePaths: Object.freeze([writeRoot]),\n\t\tread: \"allow-all\",\n\t\tnetwork,\n\t\tallowPrivilegeEscalation: false,\n\t});\n}\n\nfunction parseReport(output: string): ProbeReport | null {\n\tconst index = output.lastIndexOf(PROBE_MARKER);\n\tif (index === -1) return null;\n\tconst line = output.slice(index + PROBE_MARKER.length).split(\"\\n\", 1)[0];\n\ttry {\n\t\tconst parsed = JSON.parse(line ?? \"\");\n\t\tif (parsed && typeof parsed === \"object\") return parsed as ProbeReport;\n\t\treturn null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction unavailable(backendName: string, detail: string): SandboxStatus {\n\treturn { available: false, reason: `${backendName} sandbox self-test failed: ${detail}` };\n}\n\n/**\n * The `allowPrivilegeEscalation: false` invariant, checked against what the probe\n * actually observed. Returns the failure detail, or `null` when the invariant is\n * demonstrated. See the module doc for why `ran:*` on its own is not evidence.\n */\nfunction privilegeEscalationFailure(report: ProbeReport): string | null {\n\tconst escalation = report.privilegeEscalation;\n\tconst noNewPrivs = report.noNewPrivs;\n\tif (escalation === undefined || noNewPrivs === undefined || escalation === \"not-attempted\") {\n\t\t// Positive control for this probe: an older or garbled probe that never ran\n\t\t// the escalation attempt must not be read as \"escalation is impossible\".\n\t\treturn `the probe did not report a privilege-escalation attempt (privilegeEscalation: ${JSON.stringify(\n\t\t\tescalation,\n\t\t)}), so the allowPrivilegeEscalation invariant was not tested`;\n\t}\n\tif (escalation.startsWith(\"escalated\")) {\n\t\treturn `a setuid-root binary acquired privileges inside the sandbox (${escalation}), so the allowPrivilegeEscalation invariant does not hold`;\n\t}\n\tif (noNewPrivs === \"0\") {\n\t\treturn \"the kernel reports NoNewPrivs: 0 inside the sandbox, so an exec can still gain privileges through a setuid binary\";\n\t}\n\tconst proven = escalation.startsWith(\"exec-refused:\") || noNewPrivs === \"1\";\n\tif (!proven) {\n\t\treturn `the allowPrivilegeEscalation invariant could not be demonstrated (escalation probe: ${escalation}, NoNewPrivs: ${noNewPrivs}) -- the sandbox neither refused to exec a setuid-root binary nor set PR_SET_NO_NEW_PRIVS, so a host that merely lacks sudo rights would look identical`;\n\t}\n\treturn null;\n}\n\n/**\n * Runs the self-test in a throwaway sandbox and returns the status the backend\n * may report. Never throws: any error is itself a failed self-test, and a\n * self-test that blew up is not one that passed.\n */\nexport async function runSandboxSelfTest(options: SandboxSelfTestOptions): Promise<SandboxStatus> {\n\tconst { backendName } = options;\n\tconst timeoutSeconds = options.timeoutSeconds ?? DEFAULT_PROBE_TIMEOUT_SECONDS;\n\n\tlet root: string | undefined;\n\tlet server: Server | undefined;\n\ttry {\n\t\tconst created = mkdtempSync(join(tmpdir(), \"draht-sandbox-selftest-\"));\n\t\t// Real-path the throwaway root for the same reason R44-SBX.3 real-paths\n\t\t// policy paths: on macOS `os.tmpdir()` is `/var/folders/...`, a symlink to\n\t\t// `/private/var/folders/...`, and the kernel matches the resolved vnode. An\n\t\t// unresolved root here makes the *positive* control fail -- which is how\n\t\t// this was found, and a good argument for having a positive control.\n\t\tconst resolvedRoot = resolveRealPath(created, { base: created });\n\t\tif (!resolvedRoot.ok) {\n\t\t\trmSync(created, { recursive: true, force: true });\n\t\t\treturn unavailable(backendName, `could not resolve the throwaway probe directory: ${resolvedRoot.reason}`);\n\t\t}\n\t\troot = resolvedRoot.path;\n\t\tconst inside = join(root, \"inside\");\n\t\tconst outside = join(root, \"outside\");\n\t\tmkdirSync(inside);\n\t\tmkdirSync(outside);\n\n\t\tlet accepted = 0;\n\t\tserver = createServer((socket) => {\n\t\t\taccepted += 1;\n\t\t\tsocket.destroy();\n\t\t});\n\t\tconst listening = server;\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tlistening.once(\"error\", reject);\n\t\t\tlistening.listen(0, \"127.0.0.1\", resolve);\n\t\t});\n\t\tconst address = listening.address();\n\t\tconst port = typeof address === \"object\" && address !== null ? address.port : 0;\n\t\tif (port === 0) return unavailable(backendName, \"could not open a loopback listener for the network probe\");\n\n\t\tconst probeRoot = root;\n\t\tconst probeScript = join(probeRoot, \"probe.mjs\");\n\t\twriteFileSync(probeScript, PROBE_SOURCE, { mode: 0o600 });\n\n\t\t/** One phase: writes a fresh config, runs the probe, returns what actually happened. */\n\t\tconst runPhase = async (\n\t\t\tphase: \"network-on\" | \"network-off\",\n\t\t): Promise<{ report: ProbeReport; outsideFile: string; connectionsBefore: number } | SandboxStatus> => {\n\t\t\tconst insideFile = join(inside, `${phase}.txt`);\n\t\t\tconst outsideFile = join(outside, `${phase}.txt`);\n\t\t\tconst configFile = join(probeRoot, `${phase}.json`);\n\t\t\twriteFileSync(\n\t\t\t\tconfigFile,\n\t\t\t\tJSON.stringify({\n\t\t\t\t\tinsideFile,\n\t\t\t\t\toutsideFile,\n\t\t\t\t\tloopbackPort: port,\n\t\t\t\t\tconnectTimeoutMs: PROBE_CONNECT_TIMEOUT_MS,\n\t\t\t\t\tmarker: PROBE_MARKER,\n\t\t\t\t}),\n\t\t\t\t{ mode: 0o600 },\n\t\t\t);\n\t\t\tconst connectionsBefore = accepted;\n\t\t\tconst command = `${shellQuote(process.execPath)} ${shellQuote(probeScript)} ${shellQuote(configFile)}`;\n\t\t\tconst { output } = await options.run(\n\t\t\t\tcommand,\n\t\t\t\tinside,\n\t\t\t\tprobePolicy(inside, phase === \"network-off\" ? \"off\" : \"on\"),\n\t\t\t\ttimeoutSeconds,\n\t\t\t);\n\t\t\tconst report = parseReport(output);\n\t\t\tif (!report) {\n\t\t\t\t// No marker line means the probe never ran to completion. A broken\n\t\t\t\t// profile lands here (sandbox-exec exits before exec'ing anything) --\n\t\t\t\t// the single most important case not to mistake for confinement.\n\t\t\t\treturn unavailable(\n\t\t\t\t\tbackendName,\n\t\t\t\t\t`the ${phase} probe never reported a result, so the sandbox could not be shown to run commands at all (output: ${JSON.stringify(\n\t\t\t\t\t\toutput.slice(-400),\n\t\t\t\t\t)})`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn { report, outsideFile, connectionsBefore };\n\t\t};\n\n\t\t// --- Phase 1: network on. Positive controls plus the write negative control.\n\t\tconst first = await runPhase(\"network-on\");\n\t\tif (\"available\" in first) return first;\n\t\tif (first.report.insideWrite !== \"wrote\") {\n\t\t\treturn unavailable(\n\t\t\t\tbackendName,\n\t\t\t\t`a write inside the allowlist was rejected (${first.report.insideWrite}) -- the profile does not grant the access the policy describes`,\n\t\t\t);\n\t\t}\n\t\tif (first.report.outsideWrite === \"wrote\" || existsSync(first.outsideFile)) {\n\t\t\treturn unavailable(\n\t\t\t\tbackendName,\n\t\t\t\t`a write outside the allowlist succeeded (${first.report.outsideWrite}), so the sandbox does not confine writes`,\n\t\t\t);\n\t\t}\n\t\tif (first.report.loopback !== \"connected\") {\n\t\t\treturn unavailable(\n\t\t\t\tbackendName,\n\t\t\t\t`the loopback probe could not connect with network allowed (${first.report.loopback}), so network confinement cannot be demonstrated either way`,\n\t\t\t);\n\t\t}\n\t\tif (accepted === first.connectionsBefore) {\n\t\t\treturn unavailable(\n\t\t\t\tbackendName,\n\t\t\t\t\"the loopback listener saw no connection with network allowed, so the network probe proves nothing\",\n\t\t\t);\n\t\t}\n\t\tconst escalationFailure = privilegeEscalationFailure(first.report);\n\t\tif (escalationFailure) return unavailable(backendName, escalationFailure);\n\n\t\t// --- Phase 2: network off. The network negative control.\n\t\tconst second = await runPhase(\"network-off\");\n\t\tif (\"available\" in second) return second;\n\t\tif (second.report.outsideWrite === \"wrote\" || existsSync(second.outsideFile)) {\n\t\t\treturn unavailable(backendName, \"a write outside the allowlist succeeded with network off\");\n\t\t}\n\t\tif (second.report.loopback === \"connected\") {\n\t\t\treturn unavailable(backendName, \"a loopback connection succeeded while the policy had network off\");\n\t\t}\n\t\tif (accepted !== second.connectionsBefore) {\n\t\t\treturn unavailable(\n\t\t\t\tbackendName,\n\t\t\t\t\"the loopback listener accepted a connection while the policy had network off, so the network denial does not hold\",\n\t\t\t);\n\t\t}\n\t\tconst escalationFailureOff = privilegeEscalationFailure(second.report);\n\t\tif (escalationFailureOff) return unavailable(backendName, `${escalationFailureOff} (with network off)`);\n\n\t\treturn { available: true };\n\t} catch (err) {\n\t\treturn unavailable(\n\t\t\tbackendName,\n\t\t\t`the self-test itself failed: ${err instanceof Error ? err.message : String(err)}`,\n\t\t);\n\t} finally {\n\t\tconst openServer = server;\n\t\tif (openServer) await new Promise<void>((resolve) => openServer.close(() => resolve()));\n\t\tif (root) rmSync(root, { recursive: true, force: true });\n\t}\n}\n"]}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Spawning a wrapped, confined child.
3
+ *
4
+ * Both platform backends produce the same shape -- a wrapper binary
5
+ * (`sandbox-exec`, `bwrap`, `unshare`) whose trailing arguments are the ordinary
6
+ * shell invocation -- so the process plumbing lives here once: streaming,
7
+ * timeout, abort, process-tree teardown.
8
+ *
9
+ * It deliberately mirrors `createLocalBashOperations` in `../tools/bash.ts`
10
+ * (detached process group, `killProcessTree` on abort/timeout, `waitForChildProcess`
11
+ * so a chatty descendant's output is not truncated) rather than reimplementing
12
+ * the semantics, because R44-SBX.6 requires the sandboxed backend to be a drop-in
13
+ * for the local one: a command that times out or is cancelled must behave the
14
+ * same whether or not it ran confined.
15
+ *
16
+ * Killing the *tree* matters more here than it does unsandboxed. The wrapper is
17
+ * the direct child; the shell and everything it spawns are grandchildren.
18
+ * Signalling only the wrapper would leave the real work running -- still
19
+ * confined, but no longer attached to anything that will reap it.
20
+ */
21
+ export interface SandboxedSpawnOptions {
22
+ cwd: string;
23
+ env: NodeJS.ProcessEnv;
24
+ onData: (data: Buffer) => void;
25
+ signal?: AbortSignal;
26
+ /** Seconds, matching the bash tool's units. */
27
+ timeout?: number;
28
+ }
29
+ /** Spawns `command args...` and streams its combined output. Resolves with the exit code (`null` if killed). */
30
+ export declare function spawnSandboxedProcess(command: string, args: readonly string[], options: SandboxedSpawnOptions): Promise<{
31
+ exitCode: number | null;
32
+ }>;
33
+ //# sourceMappingURL=spawn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../../src/core/sandbox/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAMH,MAAM,WAAW,qBAAqB;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAaD,gHAAgH;AAChH,wBAAsB,qBAAqB,CAC1C,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,EAAE,qBAAqB,GAC5B,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAyCtC"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Spawning a wrapped, confined child.
3
+ *
4
+ * Both platform backends produce the same shape -- a wrapper binary
5
+ * (`sandbox-exec`, `bwrap`, `unshare`) whose trailing arguments are the ordinary
6
+ * shell invocation -- so the process plumbing lives here once: streaming,
7
+ * timeout, abort, process-tree teardown.
8
+ *
9
+ * It deliberately mirrors `createLocalBashOperations` in `../tools/bash.ts`
10
+ * (detached process group, `killProcessTree` on abort/timeout, `waitForChildProcess`
11
+ * so a chatty descendant's output is not truncated) rather than reimplementing
12
+ * the semantics, because R44-SBX.6 requires the sandboxed backend to be a drop-in
13
+ * for the local one: a command that times out or is cancelled must behave the
14
+ * same whether or not it ran confined.
15
+ *
16
+ * Killing the *tree* matters more here than it does unsandboxed. The wrapper is
17
+ * the direct child; the shell and everything it spawns are grandchildren.
18
+ * Signalling only the wrapper would leave the real work running -- still
19
+ * confined, but no longer attached to anything that will reap it.
20
+ */
21
+ import { spawn } from "node:child_process";
22
+ import { waitForChildProcess } from "../../utils/child-process.js";
23
+ import { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from "../../utils/shell.js";
24
+ const MAX_TIMEOUT_MS = 2_147_483_647;
25
+ function resolveTimeoutMs(timeout) {
26
+ if (timeout === undefined)
27
+ return undefined;
28
+ if (!Number.isFinite(timeout) || timeout <= 0)
29
+ throw new Error("Invalid timeout: must be a finite number of seconds");
30
+ const timeoutMs = timeout * 1000;
31
+ if (timeoutMs > MAX_TIMEOUT_MS)
32
+ throw new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_MS / 1000} seconds`);
33
+ return timeoutMs;
34
+ }
35
+ /** Spawns `command args...` and streams its combined output. Resolves with the exit code (`null` if killed). */
36
+ export async function spawnSandboxedProcess(command, args, options) {
37
+ const timeoutMs = resolveTimeoutMs(options.timeout);
38
+ if (options.signal?.aborted)
39
+ throw new Error("aborted");
40
+ const child = spawn(command, [...args], {
41
+ cwd: options.cwd,
42
+ detached: process.platform !== "win32",
43
+ env: options.env,
44
+ stdio: ["ignore", "pipe", "pipe"],
45
+ windowsHide: true,
46
+ });
47
+ if (child.pid)
48
+ trackDetachedChildPid(child.pid);
49
+ let timedOut = false;
50
+ let timeoutHandle;
51
+ const onAbort = () => {
52
+ if (child.pid)
53
+ killProcessTree(child.pid);
54
+ };
55
+ try {
56
+ if (timeoutMs !== undefined) {
57
+ timeoutHandle = setTimeout(() => {
58
+ timedOut = true;
59
+ if (child.pid)
60
+ killProcessTree(child.pid);
61
+ }, timeoutMs);
62
+ }
63
+ child.stdout?.on("data", options.onData);
64
+ child.stderr?.on("data", options.onData);
65
+ if (options.signal) {
66
+ if (options.signal.aborted)
67
+ onAbort();
68
+ else
69
+ options.signal.addEventListener("abort", onAbort, { once: true });
70
+ }
71
+ const exitCode = await waitForChildProcess(child);
72
+ if (options.signal?.aborted)
73
+ throw new Error("aborted");
74
+ if (timedOut)
75
+ throw new Error(`timeout:${options.timeout}`);
76
+ return { exitCode };
77
+ }
78
+ finally {
79
+ if (child.pid)
80
+ untrackDetachedChildPid(child.pid);
81
+ if (timeoutHandle)
82
+ clearTimeout(timeoutHandle);
83
+ if (options.signal)
84
+ options.signal.removeEventListener("abort", onAbort);
85
+ }
86
+ }
87
+ //# sourceMappingURL=spawn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spawn.js","sourceRoot":"","sources":["../../../src/core/sandbox/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAWvG,MAAM,cAAc,GAAG,aAAa,CAAC;AAErC,SAAS,gBAAgB,CAAC,OAA2B;IACpD,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC5C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACxE,MAAM,SAAS,GAAG,OAAO,GAAG,IAAI,CAAC;IACjC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C;QACD,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACzC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO;gBAAE,OAAO,EAAE,CAAC;;gBACjC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACxE,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAClD,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;QACxD,IAAI,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,WAAW,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5D,OAAO,EAAE,QAAQ,EAAE,CAAC;IACrB,CAAC;YAAS,CAAC;QACV,IAAI,KAAK,CAAC,GAAG;YAAE,uBAAuB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClD,IAAI,aAAa;YAAE,YAAY,CAAC,aAAa,CAAC,CAAC;QAC/C,IAAI,OAAO,CAAC,MAAM;YAAE,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1E,CAAC;AACF,CAAC","sourcesContent":["/**\n * Spawning a wrapped, confined child.\n *\n * Both platform backends produce the same shape -- a wrapper binary\n * (`sandbox-exec`, `bwrap`, `unshare`) whose trailing arguments are the ordinary\n * shell invocation -- so the process plumbing lives here once: streaming,\n * timeout, abort, process-tree teardown.\n *\n * It deliberately mirrors `createLocalBashOperations` in `../tools/bash.ts`\n * (detached process group, `killProcessTree` on abort/timeout, `waitForChildProcess`\n * so a chatty descendant's output is not truncated) rather than reimplementing\n * the semantics, because R44-SBX.6 requires the sandboxed backend to be a drop-in\n * for the local one: a command that times out or is cancelled must behave the\n * same whether or not it ran confined.\n *\n * Killing the *tree* matters more here than it does unsandboxed. The wrapper is\n * the direct child; the shell and everything it spawns are grandchildren.\n * Signalling only the wrapper would leave the real work running -- still\n * confined, but no longer attached to anything that will reap it.\n */\n\nimport { spawn } from \"node:child_process\";\nimport { waitForChildProcess } from \"../../utils/child-process.ts\";\nimport { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\n\nexport interface SandboxedSpawnOptions {\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n\tonData: (data: Buffer) => void;\n\tsignal?: AbortSignal;\n\t/** Seconds, matching the bash tool's units. */\n\ttimeout?: number;\n}\n\nconst MAX_TIMEOUT_MS = 2_147_483_647;\n\nfunction resolveTimeoutMs(timeout: number | undefined): number | undefined {\n\tif (timeout === undefined) return undefined;\n\tif (!Number.isFinite(timeout) || timeout <= 0)\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\tconst timeoutMs = timeout * 1000;\n\tif (timeoutMs > MAX_TIMEOUT_MS) throw new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_MS / 1000} seconds`);\n\treturn timeoutMs;\n}\n\n/** Spawns `command args...` and streams its combined output. Resolves with the exit code (`null` if killed). */\nexport async function spawnSandboxedProcess(\n\tcommand: string,\n\targs: readonly string[],\n\toptions: SandboxedSpawnOptions,\n): Promise<{ exitCode: number | null }> {\n\tconst timeoutMs = resolveTimeoutMs(options.timeout);\n\tif (options.signal?.aborted) throw new Error(\"aborted\");\n\n\tconst child = spawn(command, [...args], {\n\t\tcwd: options.cwd,\n\t\tdetached: process.platform !== \"win32\",\n\t\tenv: options.env,\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\twindowsHide: true,\n\t});\n\tif (child.pid) trackDetachedChildPid(child.pid);\n\n\tlet timedOut = false;\n\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\tconst onAbort = () => {\n\t\tif (child.pid) killProcessTree(child.pid);\n\t};\n\n\ttry {\n\t\tif (timeoutMs !== undefined) {\n\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\ttimedOut = true;\n\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t}, timeoutMs);\n\t\t}\n\t\tchild.stdout?.on(\"data\", options.onData);\n\t\tchild.stderr?.on(\"data\", options.onData);\n\t\tif (options.signal) {\n\t\t\tif (options.signal.aborted) onAbort();\n\t\t\telse options.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t}\n\t\tconst exitCode = await waitForChildProcess(child);\n\t\tif (options.signal?.aborted) throw new Error(\"aborted\");\n\t\tif (timedOut) throw new Error(`timeout:${options.timeout}`);\n\t\treturn { exitCode };\n\t} finally {\n\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\tif (options.signal) options.signal.removeEventListener(\"abort\", onAbort);\n\t}\n}\n"]}
@@ -1,9 +1,8 @@
1
1
  import { type ThinkingLevel } from "@draht/agent-core";
2
2
  import { type Model } from "@draht/ai/compat";
3
3
  import { AgentSession } from "./agent-session.ts";
4
- import { AuthStorage } from "./auth-storage.ts";
5
4
  import type { LoadExtensionsResult, SessionStartEvent, ToolDefinition } from "./extensions/index.ts";
6
- import { ModelRegistry } from "./model-registry.ts";
5
+ import { ModelRuntime } from "./model-runtime.ts";
7
6
  import type { ResourceLoader } from "./resource-loader.ts";
8
7
  import { SessionManager } from "./session-manager.ts";
9
8
  import { SettingsManager } from "./settings-manager.ts";
@@ -13,10 +12,8 @@ export interface CreateAgentSessionOptions {
13
12
  cwd?: string;
14
13
  /** Global config directory. Default: ~/.pi/agent */
15
14
  agentDir?: string;
16
- /** Auth storage for credentials. Default: AuthStorage.create(agentDir/auth.json) */
17
- authStorage?: AuthStorage;
18
- /** Model registry. Default: ModelRegistry.create(authStorage, agentDir/models.json) */
19
- modelRegistry?: ModelRegistry;
15
+ /** Canonical model/auth runtime. Defaults to a runtime using agentDir/auth.json and models.json. */
16
+ modelRuntime?: ModelRuntime;
20
17
  /** Model to use. Default: from settings, else first available */
21
18
  model?: Model<any>;
22
19
  /** Thinking level. Default: from settings, else 'medium' (clamped to model capabilities) */
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/core/sdk.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAoC,KAAK,KAAK,EAAgB,MAAM,kBAAkB,CAAC;AAG9F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,KAAK,EAAmB,oBAAoB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAwB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EACN,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,eAAe,EAEf,qBAAqB,EACrB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,yBAAyB;IACzC,4EAA4E;IAC5E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,oFAAoF;IACpF,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,uFAAuF;IACvF,aAAa,CAAC,EAAE,aAAa,CAAC;IAE9B,iEAAiE;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