@draht/coding-agent 2026.7.30 → 2026.10.4-2

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 (1229) hide show
  1. package/CHANGELOG.md +606 -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/bun/cli.d.ts +1 -1
  19. package/dist/bun/cli.d.ts.map +1 -1
  20. package/dist/bun/cli.js +6 -3
  21. package/dist/bun/cli.js.map +1 -1
  22. package/dist/bun/sandbox-env-setup.d.ts +2 -0
  23. package/dist/bun/sandbox-env-setup.d.ts.map +1 -0
  24. package/dist/bun/sandbox-env-setup.js +4 -0
  25. package/dist/bun/sandbox-env-setup.js.map +1 -0
  26. package/dist/bundle/chunks/anthropic-messages-GAKYXF65.js +6 -0
  27. package/dist/bundle/chunks/anthropic.js +75 -0
  28. package/dist/bundle/chunks/azure-openai-responses-ZIXMK6JO.js +2 -0
  29. package/dist/bundle/chunks/bedrock-converse-stream.js +79 -0
  30. package/dist/bundle/chunks/chunk-2E5VODES.js +2 -0
  31. package/dist/bundle/chunks/chunk-2FBJKY7F.js +2 -0
  32. package/dist/bundle/chunks/chunk-2N4I6WXC.js +2 -0
  33. package/dist/bundle/chunks/chunk-5VZWYVZB.js +82 -0
  34. package/dist/bundle/chunks/chunk-63BK6WK2.js +2 -0
  35. package/dist/bundle/chunks/chunk-6MSE6LZ3.js +6 -0
  36. package/dist/bundle/chunks/chunk-6ZJKIMU7.js +2 -0
  37. package/dist/bundle/chunks/chunk-736QBNUZ.js +12 -0
  38. package/dist/bundle/chunks/chunk-BXSHCX3G.js +11 -0
  39. package/dist/bundle/chunks/chunk-CEJJ5XF2.js +170 -0
  40. package/dist/bundle/chunks/chunk-COF5JT7R.js +4 -0
  41. package/dist/bundle/chunks/chunk-D6TMD5Q2.js +44 -0
  42. package/dist/bundle/chunks/chunk-DPE4ALPU.js +146 -0
  43. package/dist/bundle/chunks/chunk-EBVYI75P.js +2 -0
  44. package/dist/bundle/chunks/chunk-GVXA72ZA.js +2 -0
  45. package/dist/bundle/chunks/chunk-H6FT43VC.js +137 -0
  46. package/dist/bundle/chunks/chunk-HJ72RANT.js +2 -0
  47. package/dist/bundle/chunks/chunk-HTJ3L72O.js +2 -0
  48. package/dist/bundle/chunks/chunk-HZ2UHMBT.js +2 -0
  49. package/dist/bundle/chunks/chunk-I5OKY6RH.js +11 -0
  50. package/dist/bundle/chunks/chunk-IWTUBX6V.js +4 -0
  51. package/dist/bundle/chunks/chunk-KPO5375S.js +2 -0
  52. package/dist/bundle/chunks/chunk-KVH4HR57.js +31 -0
  53. package/dist/bundle/chunks/chunk-LDAOC5RB.js +18 -0
  54. package/dist/bundle/chunks/chunk-ON6XU6AG.js +2 -0
  55. package/dist/bundle/chunks/chunk-QMN7OD6G.js +2 -0
  56. package/dist/bundle/chunks/chunk-RZKPFWMH.js +42 -0
  57. package/dist/bundle/chunks/chunk-SDRCE6OP.js +2 -0
  58. package/dist/bundle/chunks/chunk-SVNWI7EV.js +8 -0
  59. package/dist/bundle/chunks/chunk-TIA2T6EO.js +3 -0
  60. package/dist/bundle/chunks/chunk-VOFPZOUQ.js +1472 -0
  61. package/dist/bundle/chunks/chunk-XBUEMKIY.js +2 -0
  62. package/dist/bundle/chunks/chunk-XOGEYN4Q.js +2 -0
  63. package/dist/bundle/chunks/chunk-ZZD35WKM.js +2 -0
  64. package/dist/bundle/chunks/cli-SR5QBZH4.js +51 -0
  65. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-MJKOAE5S.js +2 -0
  66. package/dist/bundle/chunks/codemode-worker.js +315 -0
  67. package/dist/bundle/chunks/execute-VCYDHEYA.js +328 -0
  68. package/dist/bundle/chunks/github-copilot.js +2 -0
  69. package/dist/bundle/chunks/google-antigravity.js +75 -0
  70. package/dist/bundle/chunks/google-gemini-cli.js +75 -0
  71. package/dist/bundle/chunks/google-generative-ai-RPUPQ6PM.js +2 -0
  72. package/dist/bundle/chunks/google-vertex-EZES5QVQ.js +2 -0
  73. package/dist/bundle/chunks/https-proxy-agent-O2PVUIOI.js +13 -0
  74. package/dist/bundle/chunks/image-resize-worker.js +2 -0
  75. package/dist/bundle/chunks/jiti-loader-RKXLMQV2.js +2 -0
  76. package/dist/bundle/chunks/kimi-coding.js +2 -0
  77. package/dist/bundle/chunks/lib-XOG5PI3Y.js +9 -0
  78. package/dist/bundle/chunks/llama-cpp-classify-EJ5XMSQL.js +22 -0
  79. package/dist/bundle/chunks/meta.js +2 -0
  80. package/dist/bundle/chunks/mistral-conversations-AOYGU43Y.js +5 -0
  81. package/dist/bundle/chunks/multipart-parser-AZP5BX2W.js +3 -0
  82. package/dist/bundle/chunks/node-C2JGH2OB.js +2 -0
  83. package/dist/bundle/chunks/node-LQ52KV6B.js +16 -0
  84. package/dist/bundle/chunks/openai-chatgpt.js +75 -0
  85. package/dist/bundle/chunks/openai-codex-responses-M2Y77JEQ.js +10 -0
  86. package/dist/bundle/chunks/openai-codex.js +75 -0
  87. package/dist/bundle/chunks/openai-completions-A4OKYOYV.js +7 -0
  88. package/dist/bundle/chunks/openai-responses-6IXV53T3.js +3 -0
  89. package/dist/bundle/chunks/opencode-go.js +2 -0
  90. package/dist/bundle/chunks/openrouter-images-LYV4NKFM.js +2 -0
  91. package/dist/bundle/chunks/openrouter.js +75 -0
  92. package/dist/bundle/chunks/pi-messages-KKMEUT3Z.js +8 -0
  93. package/dist/bundle/chunks/radius.js +75 -0
  94. package/dist/bundle/chunks/runtime-6YJPGSP7.js +2 -0
  95. package/dist/bundle/chunks/settings-manager-D2EG7WDO.js +2 -0
  96. package/dist/bundle/chunks/src-TIBHS42X.js +4 -0
  97. package/dist/bundle/chunks/typesafe-system-one-YBEEY5XU.js +2 -0
  98. package/dist/bundle/chunks/virtual-modules-CBOAFAFT.js +2 -0
  99. package/dist/bundle/chunks/xai.js +75 -0
  100. package/dist/bundle/cli-runtime.js +3 -0
  101. package/dist/bundle/cli.js +5 -0
  102. package/dist/bundle/index.js +2 -0
  103. package/dist/bundle/rpc-entry.js +3 -0
  104. package/dist/cli/args.d.ts +14 -0
  105. package/dist/cli/args.d.ts.map +1 -1
  106. package/dist/cli/args.js +140 -22
  107. package/dist/cli/args.js.map +1 -1
  108. package/dist/cli/attach-mode.d.ts +61 -0
  109. package/dist/cli/attach-mode.d.ts.map +1 -1
  110. package/dist/cli/attach-mode.js +243 -5
  111. package/dist/cli/attach-mode.js.map +1 -1
  112. package/dist/cli/auth-check.d.ts +19 -0
  113. package/dist/cli/auth-check.d.ts.map +1 -0
  114. package/dist/cli/auth-check.js +50 -0
  115. package/dist/cli/auth-check.js.map +1 -0
  116. package/dist/cli/auth-command.d.ts +24 -0
  117. package/dist/cli/auth-command.d.ts.map +1 -0
  118. package/dist/cli/auth-command.js +103 -0
  119. package/dist/cli/auth-command.js.map +1 -0
  120. package/dist/cli/config-selector.d.ts.map +1 -1
  121. package/dist/cli/config-selector.js +3 -2
  122. package/dist/cli/config-selector.js.map +1 -1
  123. package/dist/cli/credential-print.d.ts +6 -4
  124. package/dist/cli/credential-print.d.ts.map +1 -1
  125. package/dist/cli/credential-print.js +47 -34
  126. package/dist/cli/credential-print.js.map +1 -1
  127. package/dist/cli/file-processor.d.ts +1 -1
  128. package/dist/cli/file-processor.d.ts.map +1 -1
  129. package/dist/cli/file-processor.js +2 -1
  130. package/dist/cli/file-processor.js.map +1 -1
  131. package/dist/cli/list-models.d.ts +1 -1
  132. package/dist/cli/list-models.d.ts.map +1 -1
  133. package/dist/cli/list-models.js +2 -2
  134. package/dist/cli/list-models.js.map +1 -1
  135. package/dist/cli/session-picker.d.ts +1 -1
  136. package/dist/cli/session-picker.d.ts.map +1 -1
  137. package/dist/cli/session-picker.js.map +1 -1
  138. package/dist/cli/setup.d.ts +2 -0
  139. package/dist/cli/setup.d.ts.map +1 -0
  140. package/dist/cli/setup.js +12 -0
  141. package/dist/cli/setup.js.map +1 -0
  142. package/dist/cli/startup-ui.d.ts +2 -2
  143. package/dist/cli/startup-ui.d.ts.map +1 -1
  144. package/dist/cli/startup-ui.js +42 -33
  145. package/dist/cli/startup-ui.js.map +1 -1
  146. package/dist/cli.js +3 -12
  147. package/dist/cli.js.map +1 -1
  148. package/dist/config.d.ts +29 -4
  149. package/dist/config.d.ts.map +1 -1
  150. package/dist/config.js +73 -10
  151. package/dist/config.js.map +1 -1
  152. package/dist/core/agent-session-runtime.d.ts +17 -1
  153. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  154. package/dist/core/agent-session-runtime.js +98 -32
  155. package/dist/core/agent-session-runtime.js.map +1 -1
  156. package/dist/core/agent-session-services.d.ts +2 -1
  157. package/dist/core/agent-session-services.d.ts.map +1 -1
  158. package/dist/core/agent-session-services.js +15 -0
  159. package/dist/core/agent-session-services.js.map +1 -1
  160. package/dist/core/agent-session.d.ts +266 -49
  161. package/dist/core/agent-session.d.ts.map +1 -1
  162. package/dist/core/agent-session.js +1503 -597
  163. package/dist/core/agent-session.js.map +1 -1
  164. package/dist/core/auth-storage.d.ts +25 -9
  165. package/dist/core/auth-storage.d.ts.map +1 -1
  166. package/dist/core/auth-storage.js +245 -45
  167. package/dist/core/auth-storage.js.map +1 -1
  168. package/dist/core/bug-report-upload.d.ts +11 -0
  169. package/dist/core/bug-report-upload.d.ts.map +1 -0
  170. package/dist/core/bug-report-upload.js +20 -0
  171. package/dist/core/bug-report-upload.js.map +1 -0
  172. package/dist/core/bug-report.d.ts +176 -0
  173. package/dist/core/bug-report.d.ts.map +1 -0
  174. package/dist/core/bug-report.js +292 -0
  175. package/dist/core/bug-report.js.map +1 -0
  176. package/dist/core/builtins/checkpoints.d.ts +20 -0
  177. package/dist/core/builtins/checkpoints.d.ts.map +1 -0
  178. package/dist/core/builtins/checkpoints.js +161 -0
  179. package/dist/core/builtins/checkpoints.js.map +1 -0
  180. package/dist/core/builtins/duet.d.ts +26 -0
  181. package/dist/core/builtins/duet.d.ts.map +1 -0
  182. package/dist/core/builtins/duet.js +660 -0
  183. package/dist/core/builtins/duet.js.map +1 -0
  184. package/dist/core/builtins/index.d.ts.map +1 -1
  185. package/dist/core/builtins/index.js +7 -1
  186. package/dist/core/builtins/index.js.map +1 -1
  187. package/dist/core/builtins/subagent.d.ts +24 -4
  188. package/dist/core/builtins/subagent.d.ts.map +1 -1
  189. package/dist/core/builtins/subagent.js +278 -35
  190. package/dist/core/builtins/subagent.js.map +1 -1
  191. package/dist/core/cache-stats.d.ts.map +1 -1
  192. package/dist/core/cache-stats.js +12 -1
  193. package/dist/core/cache-stats.js.map +1 -1
  194. package/dist/core/cache-warmer.d.ts +103 -0
  195. package/dist/core/cache-warmer.d.ts.map +1 -0
  196. package/dist/core/cache-warmer.js +356 -0
  197. package/dist/core/cache-warmer.js.map +1 -0
  198. package/dist/core/checkpoints/checkpoint-cli.d.ts +17 -0
  199. package/dist/core/checkpoints/checkpoint-cli.d.ts.map +1 -0
  200. package/dist/core/checkpoints/checkpoint-cli.js +78 -0
  201. package/dist/core/checkpoints/checkpoint-cli.js.map +1 -0
  202. package/dist/core/checkpoints/checkpoint-manager.d.ts +298 -0
  203. package/dist/core/checkpoints/checkpoint-manager.d.ts.map +1 -0
  204. package/dist/core/checkpoints/checkpoint-manager.js +901 -0
  205. package/dist/core/checkpoints/checkpoint-manager.js.map +1 -0
  206. package/dist/core/checkpoints/rewind.d.ts +143 -0
  207. package/dist/core/checkpoints/rewind.d.ts.map +1 -0
  208. package/dist/core/checkpoints/rewind.js +247 -0
  209. package/dist/core/checkpoints/rewind.js.map +1 -0
  210. package/dist/core/compaction/branch-summarization.d.ts +1 -1
  211. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  212. package/dist/core/compaction/branch-summarization.js +11 -6
  213. package/dist/core/compaction/branch-summarization.js.map +1 -1
  214. package/dist/core/compaction/compaction.d.ts +14 -6
  215. package/dist/core/compaction/compaction.d.ts.map +1 -1
  216. package/dist/core/compaction/compaction.js +221 -122
  217. package/dist/core/compaction/compaction.js.map +1 -1
  218. package/dist/core/compaction/utils.d.ts +2 -1
  219. package/dist/core/compaction/utils.d.ts.map +1 -1
  220. package/dist/core/compaction/utils.js +25 -18
  221. package/dist/core/compaction/utils.js.map +1 -1
  222. package/dist/core/crash-log.d.ts +27 -0
  223. package/dist/core/crash-log.d.ts.map +1 -0
  224. package/dist/core/crash-log.js +140 -0
  225. package/dist/core/crash-log.js.map +1 -0
  226. package/dist/core/defaults.d.ts +1 -0
  227. package/dist/core/defaults.d.ts.map +1 -1
  228. package/dist/core/defaults.js +9 -0
  229. package/dist/core/defaults.js.map +1 -1
  230. package/dist/core/experimental.js +1 -1
  231. package/dist/core/experimental.js.map +1 -1
  232. package/dist/core/export-html/template.css +10 -0
  233. package/dist/core/export-html/template.js +72 -18
  234. package/dist/core/extensions/index.d.ts +2 -2
  235. package/dist/core/extensions/index.d.ts.map +1 -1
  236. package/dist/core/extensions/index.js +1 -1
  237. package/dist/core/extensions/index.js.map +1 -1
  238. package/dist/core/extensions/jiti-loader.d.ts +2 -0
  239. package/dist/core/extensions/jiti-loader.d.ts.map +1 -0
  240. package/dist/core/extensions/jiti-loader.js +5 -0
  241. package/dist/core/extensions/jiti-loader.js.map +1 -0
  242. package/dist/core/extensions/loader.d.ts.map +1 -1
  243. package/dist/core/extensions/loader.js +298 -96
  244. package/dist/core/extensions/loader.js.map +1 -1
  245. package/dist/core/extensions/runner.d.ts +59 -9
  246. package/dist/core/extensions/runner.d.ts.map +1 -1
  247. package/dist/core/extensions/runner.js +410 -103
  248. package/dist/core/extensions/runner.js.map +1 -1
  249. package/dist/core/extensions/types.d.ts +701 -85
  250. package/dist/core/extensions/types.d.ts.map +1 -1
  251. package/dist/core/extensions/types.js +3 -0
  252. package/dist/core/extensions/types.js.map +1 -1
  253. package/dist/core/extensions/virtual-modules.d.ts +3 -0
  254. package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
  255. package/dist/core/extensions/virtual-modules.js +37 -0
  256. package/dist/core/extensions/virtual-modules.js.map +1 -0
  257. package/dist/core/extensions/wrapper.d.ts +2 -2
  258. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  259. package/dist/core/extensions/wrapper.js +3 -22
  260. package/dist/core/extensions/wrapper.js.map +1 -1
  261. package/dist/core/footer-data-provider.d.ts +1 -1
  262. package/dist/core/footer-data-provider.js +19 -18
  263. package/dist/core/footer-data-provider.js.map +1 -1
  264. package/dist/core/http-dispatcher.d.ts.map +1 -1
  265. package/dist/core/http-dispatcher.js +7 -0
  266. package/dist/core/http-dispatcher.js.map +1 -1
  267. package/dist/core/index.d.ts +2 -1
  268. package/dist/core/index.d.ts.map +1 -1
  269. package/dist/core/index.js.map +1 -1
  270. package/dist/core/keybindings.d.ts +88 -13
  271. package/dist/core/keybindings.d.ts.map +1 -1
  272. package/dist/core/keybindings.js +34 -7
  273. package/dist/core/keybindings.js.map +1 -1
  274. package/dist/core/mcp-servers.d.ts +119 -0
  275. package/dist/core/mcp-servers.d.ts.map +1 -0
  276. package/dist/core/mcp-servers.js +191 -0
  277. package/dist/core/mcp-servers.js.map +1 -0
  278. package/dist/core/messages.d.ts +1 -1
  279. package/dist/core/messages.d.ts.map +1 -1
  280. package/dist/core/messages.js +1 -0
  281. package/dist/core/messages.js.map +1 -1
  282. package/dist/core/model-config.d.ts +202 -20
  283. package/dist/core/model-config.d.ts.map +1 -1
  284. package/dist/core/model-config.js +53 -18
  285. package/dist/core/model-config.js.map +1 -1
  286. package/dist/core/model-registry.d.ts +21 -3
  287. package/dist/core/model-registry.d.ts.map +1 -1
  288. package/dist/core/model-registry.js +47 -10
  289. package/dist/core/model-registry.js.map +1 -1
  290. package/dist/core/model-resolver.d.ts +7 -5
  291. package/dist/core/model-resolver.d.ts.map +1 -1
  292. package/dist/core/model-resolver.js +62 -23
  293. package/dist/core/model-resolver.js.map +1 -1
  294. package/dist/core/model-runtime.d.ts +80 -15
  295. package/dist/core/model-runtime.d.ts.map +1 -1
  296. package/dist/core/model-runtime.js +466 -120
  297. package/dist/core/model-runtime.js.map +1 -1
  298. package/dist/core/models-store.d.ts +12 -7
  299. package/dist/core/models-store.d.ts.map +1 -1
  300. package/dist/core/models-store.js +87 -18
  301. package/dist/core/models-store.js.map +1 -1
  302. package/dist/core/multi-agent/fsm.js +8 -3
  303. package/dist/core/multi-agent/fsm.js.map +1 -1
  304. package/dist/core/multi-agent/mailbox.js +1 -3
  305. package/dist/core/multi-agent/mailbox.js.map +1 -1
  306. package/dist/core/multi-agent/permission-gate.d.ts +5 -2
  307. package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
  308. package/dist/core/multi-agent/permission-gate.js +601 -37
  309. package/dist/core/multi-agent/permission-gate.js.map +1 -1
  310. package/dist/core/multi-agent/task-board.js +2 -4
  311. package/dist/core/multi-agent/task-board.js.map +1 -1
  312. package/dist/core/multi-agent/worktree.d.ts +2 -0
  313. package/dist/core/multi-agent/worktree.d.ts.map +1 -1
  314. package/dist/core/multi-agent/worktree.js +3 -5
  315. package/dist/core/multi-agent/worktree.js.map +1 -1
  316. package/dist/core/nested-tool-calls.d.ts +102 -0
  317. package/dist/core/nested-tool-calls.d.ts.map +1 -0
  318. package/dist/core/nested-tool-calls.js +178 -0
  319. package/dist/core/nested-tool-calls.js.map +1 -0
  320. package/dist/core/package-manager.d.ts +16 -0
  321. package/dist/core/package-manager.d.ts.map +1 -1
  322. package/dist/core/package-manager.js +162 -69
  323. package/dist/core/package-manager.js.map +1 -1
  324. package/dist/core/permission-relay/index.d.ts +19 -0
  325. package/dist/core/permission-relay/index.d.ts.map +1 -0
  326. package/dist/core/permission-relay/index.js +49 -0
  327. package/dist/core/permission-relay/index.js.map +1 -0
  328. package/dist/core/permission-relay/relay-ui-context.d.ts +39 -0
  329. package/dist/core/permission-relay/relay-ui-context.d.ts.map +1 -0
  330. package/dist/core/permission-relay/relay-ui-context.js +788 -0
  331. package/dist/core/permission-relay/relay-ui-context.js.map +1 -0
  332. package/dist/core/permission-relay/types.d.ts +222 -0
  333. package/dist/core/permission-relay/types.d.ts.map +1 -0
  334. package/dist/core/permission-relay/types.js +15 -0
  335. package/dist/core/permission-relay/types.js.map +1 -0
  336. package/dist/core/pi-manifest.d.ts +14 -0
  337. package/dist/core/pi-manifest.d.ts.map +1 -0
  338. package/dist/core/pi-manifest.js +36 -0
  339. package/dist/core/pi-manifest.js.map +1 -0
  340. package/dist/core/project-trust.js +2 -2
  341. package/dist/core/project-trust.js.map +1 -1
  342. package/dist/core/prompt-templates.d.ts +6 -1
  343. package/dist/core/prompt-templates.d.ts.map +1 -1
  344. package/dist/core/prompt-templates.js +63 -37
  345. package/dist/core/prompt-templates.js.map +1 -1
  346. package/dist/core/provider-attribution.js +5 -5
  347. package/dist/core/provider-attribution.js.map +1 -1
  348. package/dist/core/provider-composer.d.ts +44 -20
  349. package/dist/core/provider-composer.d.ts.map +1 -1
  350. package/dist/core/provider-composer.js +151 -51
  351. package/dist/core/provider-composer.js.map +1 -1
  352. package/dist/core/radius.d.ts +13 -0
  353. package/dist/core/radius.d.ts.map +1 -1
  354. package/dist/core/radius.js +19 -0
  355. package/dist/core/radius.js.map +1 -1
  356. package/dist/core/remote-catalog-provider.d.ts +10 -3
  357. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  358. package/dist/core/remote-catalog-provider.js +105 -81
  359. package/dist/core/remote-catalog-provider.js.map +1 -1
  360. package/dist/core/resource-loader.d.ts +28 -1
  361. package/dist/core/resource-loader.d.ts.map +1 -1
  362. package/dist/core/resource-loader.js +319 -65
  363. package/dist/core/resource-loader.js.map +1 -1
  364. package/dist/core/runtime-credentials.d.ts +5 -5
  365. package/dist/core/runtime-credentials.d.ts.map +1 -1
  366. package/dist/core/runtime-credentials.js +13 -9
  367. package/dist/core/runtime-credentials.js.map +1 -1
  368. package/dist/core/sandbox/bash-operations.d.ts +149 -0
  369. package/dist/core/sandbox/bash-operations.d.ts.map +1 -0
  370. package/dist/core/sandbox/bash-operations.js +163 -0
  371. package/dist/core/sandbox/bash-operations.js.map +1 -0
  372. package/dist/core/sandbox/env.d.ts +83 -0
  373. package/dist/core/sandbox/env.d.ts.map +1 -0
  374. package/dist/core/sandbox/env.js +123 -0
  375. package/dist/core/sandbox/env.js.map +1 -0
  376. package/dist/core/sandbox/executor.d.ts +104 -0
  377. package/dist/core/sandbox/executor.d.ts.map +1 -0
  378. package/dist/core/sandbox/executor.js +93 -0
  379. package/dist/core/sandbox/executor.js.map +1 -0
  380. package/dist/core/sandbox/index.d.ts +36 -0
  381. package/dist/core/sandbox/index.d.ts.map +1 -0
  382. package/dist/core/sandbox/index.js +36 -0
  383. package/dist/core/sandbox/index.js.map +1 -0
  384. package/dist/core/sandbox/linux.d.ts +121 -0
  385. package/dist/core/sandbox/linux.d.ts.map +1 -0
  386. package/dist/core/sandbox/linux.js +260 -0
  387. package/dist/core/sandbox/linux.js.map +1 -0
  388. package/dist/core/sandbox/policy.d.ts +142 -0
  389. package/dist/core/sandbox/policy.d.ts.map +1 -0
  390. package/dist/core/sandbox/policy.js +297 -0
  391. package/dist/core/sandbox/policy.js.map +1 -0
  392. package/dist/core/sandbox/real-path.d.ts +112 -0
  393. package/dist/core/sandbox/real-path.d.ts.map +1 -0
  394. package/dist/core/sandbox/real-path.js +158 -0
  395. package/dist/core/sandbox/real-path.js.map +1 -0
  396. package/dist/core/sandbox/seatbelt-profile.d.ts +95 -0
  397. package/dist/core/sandbox/seatbelt-profile.d.ts.map +1 -0
  398. package/dist/core/sandbox/seatbelt-profile.js +239 -0
  399. package/dist/core/sandbox/seatbelt-profile.js.map +1 -0
  400. package/dist/core/sandbox/seatbelt.d.ts +95 -0
  401. package/dist/core/sandbox/seatbelt.d.ts.map +1 -0
  402. package/dist/core/sandbox/seatbelt.js +154 -0
  403. package/dist/core/sandbox/seatbelt.js.map +1 -0
  404. package/dist/core/sandbox/self-test.d.ts +109 -0
  405. package/dist/core/sandbox/self-test.d.ts.map +1 -0
  406. package/dist/core/sandbox/self-test.js +369 -0
  407. package/dist/core/sandbox/self-test.js.map +1 -0
  408. package/dist/core/sandbox/spawn.d.ts +33 -0
  409. package/dist/core/sandbox/spawn.d.ts.map +1 -0
  410. package/dist/core/sandbox/spawn.js +87 -0
  411. package/dist/core/sandbox/spawn.js.map +1 -0
  412. package/dist/core/sdk.d.ts +7 -5
  413. package/dist/core/sdk.d.ts.map +1 -1
  414. package/dist/core/sdk.js +103 -53
  415. package/dist/core/sdk.js.map +1 -1
  416. package/dist/core/session-cwd.js +1 -0
  417. package/dist/core/session-cwd.js.map +1 -1
  418. package/dist/core/session-export.d.ts +8 -0
  419. package/dist/core/session-export.d.ts.map +1 -0
  420. package/dist/core/session-export.js +33 -0
  421. package/dist/core/session-export.js.map +1 -0
  422. package/dist/core/session-manager.d.ts +134 -15
  423. package/dist/core/session-manager.d.ts.map +1 -1
  424. package/dist/core/session-manager.js +366 -149
  425. package/dist/core/session-manager.js.map +1 -1
  426. package/dist/core/settings-diagnostics.d.ts +9 -0
  427. package/dist/core/settings-diagnostics.d.ts.map +1 -0
  428. package/dist/core/settings-diagnostics.js +21 -0
  429. package/dist/core/settings-diagnostics.js.map +1 -0
  430. package/dist/core/settings-manager.d.ts +105 -4
  431. package/dist/core/settings-manager.d.ts.map +1 -1
  432. package/dist/core/settings-manager.js +274 -40
  433. package/dist/core/settings-manager.js.map +1 -1
  434. package/dist/core/skills.d.ts +3 -1
  435. package/dist/core/skills.d.ts.map +1 -1
  436. package/dist/core/skills.js +70 -39
  437. package/dist/core/skills.js.map +1 -1
  438. package/dist/core/slash-commands.d.ts.map +1 -1
  439. package/dist/core/slash-commands.js +4 -1
  440. package/dist/core/slash-commands.js.map +1 -1
  441. package/dist/core/soak/soak-log.d.ts +298 -0
  442. package/dist/core/soak/soak-log.d.ts.map +1 -0
  443. package/dist/core/soak/soak-log.js +666 -0
  444. package/dist/core/soak/soak-log.js.map +1 -0
  445. package/dist/core/soak/soak-reader.d.ts +60 -0
  446. package/dist/core/soak/soak-reader.d.ts.map +1 -0
  447. package/dist/core/soak/soak-reader.js +106 -0
  448. package/dist/core/soak/soak-reader.js.map +1 -0
  449. package/dist/core/socket-server/discovery.d.ts +78 -1
  450. package/dist/core/socket-server/discovery.d.ts.map +1 -1
  451. package/dist/core/socket-server/discovery.js +356 -37
  452. package/dist/core/socket-server/discovery.js.map +1 -1
  453. package/dist/core/socket-server/index.d.ts +10 -4
  454. package/dist/core/socket-server/index.d.ts.map +1 -1
  455. package/dist/core/socket-server/index.js +6 -3
  456. package/dist/core/socket-server/index.js.map +1 -1
  457. package/dist/core/socket-server/permission-delivery.d.ts +125 -0
  458. package/dist/core/socket-server/permission-delivery.d.ts.map +1 -0
  459. package/dist/core/socket-server/permission-delivery.js +152 -0
  460. package/dist/core/socket-server/permission-delivery.js.map +1 -0
  461. package/dist/core/socket-server/permission-registry.d.ts +301 -0
  462. package/dist/core/socket-server/permission-registry.d.ts.map +1 -0
  463. package/dist/core/socket-server/permission-registry.js +410 -0
  464. package/dist/core/socket-server/permission-registry.js.map +1 -0
  465. package/dist/core/socket-server/permission-relay.d.ts +81 -0
  466. package/dist/core/socket-server/permission-relay.d.ts.map +1 -0
  467. package/dist/core/socket-server/permission-relay.js +528 -0
  468. package/dist/core/socket-server/permission-relay.js.map +1 -0
  469. package/dist/core/socket-server/safe-text.d.ts +83 -0
  470. package/dist/core/socket-server/safe-text.d.ts.map +1 -0
  471. package/dist/core/socket-server/safe-text.js +277 -0
  472. package/dist/core/socket-server/safe-text.js.map +1 -0
  473. package/dist/core/socket-server/session-integration.d.ts +65 -2
  474. package/dist/core/socket-server/session-integration.d.ts.map +1 -1
  475. package/dist/core/socket-server/session-integration.js +434 -32
  476. package/dist/core/socket-server/session-integration.js.map +1 -1
  477. package/dist/core/socket-server/socket-client.d.ts +21 -2
  478. package/dist/core/socket-server/socket-client.d.ts.map +1 -1
  479. package/dist/core/socket-server/socket-client.js +52 -1
  480. package/dist/core/socket-server/socket-client.js.map +1 -1
  481. package/dist/core/socket-server/socket-server.d.ts +152 -1
  482. package/dist/core/socket-server/socket-server.d.ts.map +1 -1
  483. package/dist/core/socket-server/socket-server.js +786 -26
  484. package/dist/core/socket-server/socket-server.js.map +1 -1
  485. package/dist/core/socket-server/types.d.ts +108 -3
  486. package/dist/core/socket-server/types.d.ts.map +1 -1
  487. package/dist/core/socket-server/types.js +13 -1
  488. package/dist/core/socket-server/types.js.map +1 -1
  489. package/dist/core/source-info.d.ts +8 -0
  490. package/dist/core/source-info.d.ts.map +1 -1
  491. package/dist/core/source-info.js +16 -0
  492. package/dist/core/source-info.js.map +1 -1
  493. package/dist/core/system-prompt.d.ts +49 -6
  494. package/dist/core/system-prompt.d.ts.map +1 -1
  495. package/dist/core/system-prompt.js +126 -90
  496. package/dist/core/system-prompt.js.map +1 -1
  497. package/dist/core/tools/bash.d.ts +32 -2
  498. package/dist/core/tools/bash.d.ts.map +1 -1
  499. package/dist/core/tools/bash.js +83 -141
  500. package/dist/core/tools/bash.js.map +1 -1
  501. package/dist/core/tools/edit-diff.d.ts +0 -5
  502. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  503. package/dist/core/tools/edit-diff.js +2 -5
  504. package/dist/core/tools/edit-diff.js.map +1 -1
  505. package/dist/core/tools/edit.d.ts +5 -12
  506. package/dist/core/tools/edit.d.ts.map +1 -1
  507. package/dist/core/tools/edit.js +36 -173
  508. package/dist/core/tools/edit.js.map +1 -1
  509. package/dist/core/tools/find.d.ts +7 -0
  510. package/dist/core/tools/find.d.ts.map +1 -1
  511. package/dist/core/tools/find.js +22 -76
  512. package/dist/core/tools/find.js.map +1 -1
  513. package/dist/core/tools/grep.d.ts +4 -0
  514. package/dist/core/tools/grep.d.ts.map +1 -1
  515. package/dist/core/tools/grep.js +10 -62
  516. package/dist/core/tools/grep.js.map +1 -1
  517. package/dist/core/tools/index.d.ts +4 -1
  518. package/dist/core/tools/index.d.ts.map +1 -1
  519. package/dist/core/tools/index.js +18 -1
  520. package/dist/core/tools/index.js.map +1 -1
  521. package/dist/core/tools/ls.d.ts +4 -0
  522. package/dist/core/tools/ls.d.ts.map +1 -1
  523. package/dist/core/tools/ls.js +9 -50
  524. package/dist/core/tools/ls.js.map +1 -1
  525. package/dist/core/tools/output-accumulator.d.ts +11 -0
  526. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  527. package/dist/core/tools/output-accumulator.js +54 -12
  528. package/dist/core/tools/output-accumulator.js.map +1 -1
  529. package/dist/core/tools/powershell.d.ts +16 -0
  530. package/dist/core/tools/powershell.d.ts.map +1 -0
  531. package/dist/core/tools/powershell.js +39 -0
  532. package/dist/core/tools/powershell.js.map +1 -0
  533. package/dist/core/tools/read.d.ts +8 -1
  534. package/dist/core/tools/read.d.ts.map +1 -1
  535. package/dist/core/tools/read.js +16 -123
  536. package/dist/core/tools/read.js.map +1 -1
  537. package/dist/core/tools/render-utils.d.ts +6 -0
  538. package/dist/core/tools/render-utils.d.ts.map +1 -1
  539. package/dist/core/tools/render-utils.js +26 -0
  540. package/dist/core/tools/render-utils.js.map +1 -1
  541. package/dist/core/tools/renderers/bash.d.ts +12 -0
  542. package/dist/core/tools/renderers/bash.d.ts.map +1 -0
  543. package/dist/core/tools/renderers/bash.js +117 -0
  544. package/dist/core/tools/renderers/bash.js.map +1 -0
  545. package/dist/core/tools/renderers/edit.d.ts +23 -0
  546. package/dist/core/tools/renderers/edit.d.ts.map +1 -0
  547. package/dist/core/tools/renderers/edit.js +167 -0
  548. package/dist/core/tools/renderers/edit.js.map +1 -0
  549. package/dist/core/tools/renderers/find.d.ts +10 -0
  550. package/dist/core/tools/renderers/find.d.ts.map +1 -0
  551. package/dist/core/tools/renderers/find.js +64 -0
  552. package/dist/core/tools/renderers/find.js.map +1 -0
  553. package/dist/core/tools/renderers/grep.d.ts +10 -0
  554. package/dist/core/tools/renderers/grep.d.ts.map +1 -0
  555. package/dist/core/tools/renderers/grep.js +69 -0
  556. package/dist/core/tools/renderers/grep.js.map +1 -0
  557. package/dist/core/tools/renderers/index.d.ts +28 -0
  558. package/dist/core/tools/renderers/index.d.ts.map +1 -0
  559. package/dist/core/tools/renderers/index.js +47 -0
  560. package/dist/core/tools/renderers/index.js.map +1 -0
  561. package/dist/core/tools/renderers/ls.d.ts +10 -0
  562. package/dist/core/tools/renderers/ls.d.ts.map +1 -0
  563. package/dist/core/tools/renderers/ls.js +58 -0
  564. package/dist/core/tools/renderers/ls.js.map +1 -0
  565. package/dist/core/tools/renderers/read.d.ts +11 -0
  566. package/dist/core/tools/renderers/read.d.ts.map +1 -0
  567. package/dist/core/tools/renderers/read.js +130 -0
  568. package/dist/core/tools/renderers/read.js.map +1 -0
  569. package/dist/core/tools/renderers/write.d.ts +10 -0
  570. package/dist/core/tools/renderers/write.d.ts.map +1 -0
  571. package/dist/core/tools/renderers/write.js +153 -0
  572. package/dist/core/tools/renderers/write.js.map +1 -0
  573. package/dist/core/tools/tool-definition-wrapper.d.ts +5 -3
  574. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  575. package/dist/core/tools/tool-definition-wrapper.js +3 -1
  576. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  577. package/dist/core/tools/truncate.d.ts +14 -0
  578. package/dist/core/tools/truncate.d.ts.map +1 -1
  579. package/dist/core/tools/truncate.js +29 -0
  580. package/dist/core/tools/truncate.js.map +1 -1
  581. package/dist/core/tools/write.d.ts +4 -0
  582. package/dist/core/tools/write.d.ts.map +1 -1
  583. package/dist/core/tools/write.js +12 -147
  584. package/dist/core/tools/write.js.map +1 -1
  585. package/dist/core/trust-manager.d.ts +6 -4
  586. package/dist/core/trust-manager.d.ts.map +1 -1
  587. package/dist/core/trust-manager.js +59 -22
  588. package/dist/core/trust-manager.js.map +1 -1
  589. package/dist/core/usage-totals.d.ts +3 -1
  590. package/dist/core/usage-totals.d.ts.map +1 -1
  591. package/dist/core/usage-totals.js +28 -1
  592. package/dist/core/usage-totals.js.map +1 -1
  593. package/dist/core/virtual-models.d.ts +117 -0
  594. package/dist/core/virtual-models.d.ts.map +1 -0
  595. package/dist/core/virtual-models.js +124 -0
  596. package/dist/core/virtual-models.js.map +1 -0
  597. package/dist/experimental/micro/api.d.ts +81 -0
  598. package/dist/experimental/micro/api.d.ts.map +1 -0
  599. package/dist/experimental/micro/api.js +2 -0
  600. package/dist/experimental/micro/api.js.map +1 -0
  601. package/dist/experimental/micro/main.d.ts +3 -0
  602. package/dist/experimental/micro/main.d.ts.map +1 -0
  603. package/dist/experimental/micro/main.js +21 -0
  604. package/dist/experimental/micro/main.js.map +1 -0
  605. package/dist/experimental/micro/models.d.ts +11 -0
  606. package/dist/experimental/micro/models.d.ts.map +1 -0
  607. package/dist/experimental/micro/models.js +95 -0
  608. package/dist/experimental/micro/models.js.map +1 -0
  609. package/dist/experimental/micro/runtime.d.ts +12 -0
  610. package/dist/experimental/micro/runtime.d.ts.map +1 -0
  611. package/dist/experimental/micro/runtime.js +465 -0
  612. package/dist/experimental/micro/runtime.js.map +1 -0
  613. package/dist/experimental/micro/sessions.d.ts +10 -0
  614. package/dist/experimental/micro/sessions.d.ts.map +1 -0
  615. package/dist/experimental/micro/sessions.js +41 -0
  616. package/dist/experimental/micro/sessions.js.map +1 -0
  617. package/dist/experimental/micro/tools.d.ts +10 -0
  618. package/dist/experimental/micro/tools.d.ts.map +1 -0
  619. package/dist/experimental/micro/tools.js +96 -0
  620. package/dist/experimental/micro/tools.js.map +1 -0
  621. package/dist/experimental/micro/tui.d.ts +3 -0
  622. package/dist/experimental/micro/tui.d.ts.map +1 -0
  623. package/dist/experimental/micro/tui.js +510 -0
  624. package/dist/experimental/micro/tui.js.map +1 -0
  625. package/dist/experimental/mini/main.d.ts +7 -0
  626. package/dist/experimental/mini/main.d.ts.map +1 -0
  627. package/dist/experimental/mini/main.js +21 -0
  628. package/dist/experimental/mini/main.js.map +1 -0
  629. package/dist/experimental/mini/server/entry.d.ts +3 -0
  630. package/dist/experimental/mini/server/entry.d.ts.map +1 -0
  631. package/dist/experimental/mini/server/entry.js +11 -0
  632. package/dist/experimental/mini/server/entry.js.map +1 -0
  633. package/dist/experimental/mini/server/run.d.ts +13 -0
  634. package/dist/experimental/mini/server/run.d.ts.map +1 -0
  635. package/dist/experimental/mini/server/run.js +150 -0
  636. package/dist/experimental/mini/server/run.js.map +1 -0
  637. package/dist/experimental/mini/shared/protocol.d.ts +127 -0
  638. package/dist/experimental/mini/shared/protocol.d.ts.map +1 -0
  639. package/dist/experimental/mini/shared/protocol.js +13 -0
  640. package/dist/experimental/mini/shared/protocol.js.map +1 -0
  641. package/dist/experimental/mini/shared/rpc.d.ts +49 -0
  642. package/dist/experimental/mini/shared/rpc.d.ts.map +1 -0
  643. package/dist/experimental/mini/shared/rpc.js +171 -0
  644. package/dist/experimental/mini/shared/rpc.js.map +1 -0
  645. package/dist/experimental/mini/shared/transport.d.ts +35 -0
  646. package/dist/experimental/mini/shared/transport.d.ts.map +1 -0
  647. package/dist/experimental/mini/shared/transport.js +94 -0
  648. package/dist/experimental/mini/shared/transport.js.map +1 -0
  649. package/dist/experimental/mini/tui/run.d.ts +9 -0
  650. package/dist/experimental/mini/tui/run.d.ts.map +1 -0
  651. package/dist/experimental/mini/tui/run.js +62 -0
  652. package/dist/experimental/mini/tui/run.js.map +1 -0
  653. package/dist/experimental/mini/tui/session.d.ts +26 -0
  654. package/dist/experimental/mini/tui/session.d.ts.map +1 -0
  655. package/dist/experimental/mini/tui/session.js +94 -0
  656. package/dist/experimental/mini/tui/session.js.map +1 -0
  657. package/dist/experimental/mini/tui/view.d.ts +10 -0
  658. package/dist/experimental/mini/tui/view.d.ts.map +1 -0
  659. package/dist/experimental/mini/tui/view.js +461 -0
  660. package/dist/experimental/mini/tui/view.js.map +1 -0
  661. package/dist/experimental/mini/worker/entry.d.ts +3 -0
  662. package/dist/experimental/mini/worker/entry.d.ts.map +1 -0
  663. package/dist/experimental/mini/worker/entry.js +10 -0
  664. package/dist/experimental/mini/worker/entry.js.map +1 -0
  665. package/dist/experimental/mini/worker/lane-service.d.ts +44 -0
  666. package/dist/experimental/mini/worker/lane-service.d.ts.map +1 -0
  667. package/dist/experimental/mini/worker/lane-service.js +97 -0
  668. package/dist/experimental/mini/worker/lane-service.js.map +1 -0
  669. package/dist/experimental/mini/worker/models-service.d.ts +19 -0
  670. package/dist/experimental/mini/worker/models-service.d.ts.map +1 -0
  671. package/dist/experimental/mini/worker/models-service.js +136 -0
  672. package/dist/experimental/mini/worker/models-service.js.map +1 -0
  673. package/dist/experimental/mini/worker/run.d.ts +14 -0
  674. package/dist/experimental/mini/worker/run.d.ts.map +1 -0
  675. package/dist/experimental/mini/worker/run.js +88 -0
  676. package/dist/experimental/mini/worker/run.js.map +1 -0
  677. package/dist/extensions/codemode/execute.d.ts +16 -0
  678. package/dist/extensions/codemode/execute.d.ts.map +1 -0
  679. package/dist/extensions/codemode/execute.js +429 -0
  680. package/dist/extensions/codemode/execute.js.map +1 -0
  681. package/dist/extensions/codemode/execute.lazy.d.ts +3 -0
  682. package/dist/extensions/codemode/execute.lazy.d.ts.map +1 -0
  683. package/dist/extensions/codemode/execute.lazy.js +3 -0
  684. package/dist/extensions/codemode/execute.lazy.js.map +1 -0
  685. package/dist/extensions/codemode/index.d.ts +21 -0
  686. package/dist/extensions/codemode/index.d.ts.map +1 -0
  687. package/dist/extensions/codemode/index.js +31 -0
  688. package/dist/extensions/codemode/index.js.map +1 -0
  689. package/dist/extensions/codemode/renderer.d.ts +12 -0
  690. package/dist/extensions/codemode/renderer.d.ts.map +1 -0
  691. package/dist/extensions/codemode/renderer.js +137 -0
  692. package/dist/extensions/codemode/renderer.js.map +1 -0
  693. package/dist/extensions/codemode/tool.d.ts +123 -0
  694. package/dist/extensions/codemode/tool.d.ts.map +1 -0
  695. package/dist/extensions/codemode/tool.js +315 -0
  696. package/dist/extensions/codemode/tool.js.map +1 -0
  697. package/dist/extensions/codemode/worker.d.ts +7 -0
  698. package/dist/extensions/codemode/worker.d.ts.map +1 -0
  699. package/dist/extensions/codemode/worker.js +7 -0
  700. package/dist/extensions/codemode/worker.js.map +1 -0
  701. package/dist/extensions/index.d.ts.map +1 -1
  702. package/dist/extensions/index.js +13 -1
  703. package/dist/extensions/index.js.map +1 -1
  704. package/dist/extensions/llama/client.d.ts +8 -0
  705. package/dist/extensions/llama/client.d.ts.map +1 -1
  706. package/dist/extensions/llama/client.js +13 -0
  707. package/dist/extensions/llama/client.js.map +1 -1
  708. package/dist/extensions/llama/huggingface.js +2 -0
  709. package/dist/extensions/llama/huggingface.js.map +1 -1
  710. package/dist/extensions/llama/index.d.ts.map +1 -1
  711. package/dist/extensions/llama/index.js +13 -2
  712. package/dist/extensions/llama/index.js.map +1 -1
  713. package/dist/extensions/llama/provider.d.ts +4 -2
  714. package/dist/extensions/llama/provider.d.ts.map +1 -1
  715. package/dist/extensions/llama/provider.js +121 -15
  716. package/dist/extensions/llama/provider.js.map +1 -1
  717. package/dist/extensions/llama/ui.js +28 -12
  718. package/dist/extensions/llama/ui.js.map +1 -1
  719. package/dist/extensions/mcp/cli.d.ts +21 -0
  720. package/dist/extensions/mcp/cli.d.ts.map +1 -0
  721. package/dist/extensions/mcp/cli.js +500 -0
  722. package/dist/extensions/mcp/cli.js.map +1 -0
  723. package/dist/extensions/mcp/cli.lazy.d.ts +3 -0
  724. package/dist/extensions/mcp/cli.lazy.d.ts.map +1 -0
  725. package/dist/extensions/mcp/cli.lazy.js +3 -0
  726. package/dist/extensions/mcp/cli.lazy.js.map +1 -0
  727. package/dist/extensions/mcp/config.d.ts +72 -0
  728. package/dist/extensions/mcp/config.d.ts.map +1 -0
  729. package/dist/extensions/mcp/config.js +158 -0
  730. package/dist/extensions/mcp/config.js.map +1 -0
  731. package/dist/extensions/mcp/index.d.ts +76 -0
  732. package/dist/extensions/mcp/index.d.ts.map +1 -0
  733. package/dist/extensions/mcp/index.js +1055 -0
  734. package/dist/extensions/mcp/index.js.map +1 -0
  735. package/dist/extensions/mcp/log.d.ts +16 -0
  736. package/dist/extensions/mcp/log.d.ts.map +1 -0
  737. package/dist/extensions/mcp/log.js +66 -0
  738. package/dist/extensions/mcp/log.js.map +1 -0
  739. package/dist/extensions/mcp/oauth.d.ts +96 -0
  740. package/dist/extensions/mcp/oauth.d.ts.map +1 -0
  741. package/dist/extensions/mcp/oauth.js +333 -0
  742. package/dist/extensions/mcp/oauth.js.map +1 -0
  743. package/dist/extensions/mcp/resources.d.ts +43 -0
  744. package/dist/extensions/mcp/resources.d.ts.map +1 -0
  745. package/dist/extensions/mcp/resources.js +262 -0
  746. package/dist/extensions/mcp/resources.js.map +1 -0
  747. package/dist/extensions/mcp/runtime.d.ts +98 -0
  748. package/dist/extensions/mcp/runtime.d.ts.map +1 -0
  749. package/dist/extensions/mcp/runtime.js +394 -0
  750. package/dist/extensions/mcp/runtime.js.map +1 -0
  751. package/dist/extensions/mcp/runtime.lazy.d.ts +3 -0
  752. package/dist/extensions/mcp/runtime.lazy.d.ts.map +1 -0
  753. package/dist/extensions/mcp/runtime.lazy.js +3 -0
  754. package/dist/extensions/mcp/runtime.lazy.js.map +1 -0
  755. package/dist/extensions/mcp/tools.d.ts +84 -0
  756. package/dist/extensions/mcp/tools.d.ts.map +1 -0
  757. package/dist/extensions/mcp/tools.js +251 -0
  758. package/dist/extensions/mcp/tools.js.map +1 -0
  759. package/dist/extensions/mcp/ui.d.ts +60 -0
  760. package/dist/extensions/mcp/ui.d.ts.map +1 -0
  761. package/dist/extensions/mcp/ui.js +174 -0
  762. package/dist/extensions/mcp/ui.js.map +1 -0
  763. package/dist/extensions/stub-provider/index.d.ts +9 -0
  764. package/dist/extensions/stub-provider/index.d.ts.map +1 -0
  765. package/dist/extensions/stub-provider/index.js +13 -0
  766. package/dist/extensions/stub-provider/index.js.map +1 -0
  767. package/dist/extensions/stub-provider/provider.d.ts +77 -0
  768. package/dist/extensions/stub-provider/provider.d.ts.map +1 -0
  769. package/dist/extensions/stub-provider/provider.js +194 -0
  770. package/dist/extensions/stub-provider/provider.js.map +1 -0
  771. package/dist/extensions/tool-search/index.d.ts +12 -0
  772. package/dist/extensions/tool-search/index.d.ts.map +1 -0
  773. package/dist/extensions/tool-search/index.js +15 -0
  774. package/dist/extensions/tool-search/index.js.map +1 -0
  775. package/dist/extensions/tool-search/tool.d.ts +73 -0
  776. package/dist/extensions/tool-search/tool.d.ts.map +1 -0
  777. package/dist/extensions/tool-search/tool.js +189 -0
  778. package/dist/extensions/tool-search/tool.js.map +1 -0
  779. package/dist/hooks/gsd/draht-quality-gate.js +3 -3
  780. package/dist/index.d.ts +20 -11
  781. package/dist/index.d.ts.map +1 -1
  782. package/dist/index.js +12 -6
  783. package/dist/index.js.map +1 -1
  784. package/dist/main.d.ts +4 -0
  785. package/dist/main.d.ts.map +1 -1
  786. package/dist/main.js +365 -96
  787. package/dist/main.js.map +1 -1
  788. package/dist/migrations.d.ts +1 -1
  789. package/dist/migrations.js +7 -6
  790. package/dist/migrations.js.map +1 -1
  791. package/dist/modes/index.d.ts +1 -0
  792. package/dist/modes/index.d.ts.map +1 -1
  793. package/dist/modes/index.js.map +1 -1
  794. package/dist/modes/interactive/bug-report.d.ts +19 -0
  795. package/dist/modes/interactive/bug-report.d.ts.map +1 -0
  796. package/dist/modes/interactive/bug-report.js +211 -0
  797. package/dist/modes/interactive/bug-report.js.map +1 -0
  798. package/dist/modes/interactive/chat-viewport.d.ts +20 -0
  799. package/dist/modes/interactive/chat-viewport.d.ts.map +1 -0
  800. package/dist/modes/interactive/chat-viewport.js +28 -0
  801. package/dist/modes/interactive/chat-viewport.js.map +1 -0
  802. package/dist/modes/interactive/components/armin.js +10 -6
  803. package/dist/modes/interactive/components/armin.js.map +1 -1
  804. package/dist/modes/interactive/components/assistant-message.d.ts +6 -2
  805. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  806. package/dist/modes/interactive/components/assistant-message.js +38 -15
  807. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  808. package/dist/modes/interactive/components/bash-execution.js +9 -4
  809. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  810. package/dist/modes/interactive/components/bordered-loader.js +3 -0
  811. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  812. package/dist/modes/interactive/components/branch-summary-message.d.ts +1 -1
  813. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  814. package/dist/modes/interactive/components/branch-summary-message.js +15 -6
  815. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  816. package/dist/modes/interactive/components/compaction-summary-message.d.ts +1 -1
  817. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  818. package/dist/modes/interactive/components/compaction-summary-message.js +15 -6
  819. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  820. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  821. package/dist/modes/interactive/components/config-selector.js +38 -10
  822. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  823. package/dist/modes/interactive/components/countdown-timer.js +5 -0
  824. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  825. package/dist/modes/interactive/components/custom-editor.d.ts +10 -1
  826. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  827. package/dist/modes/interactive/components/custom-editor.js +54 -2
  828. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  829. package/dist/modes/interactive/components/custom-entry.js +4 -1
  830. package/dist/modes/interactive/components/custom-entry.js.map +1 -1
  831. package/dist/modes/interactive/components/custom-message.js +7 -1
  832. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  833. package/dist/modes/interactive/components/daxnuts.js +8 -6
  834. package/dist/modes/interactive/components/daxnuts.js.map +1 -1
  835. package/dist/modes/interactive/components/dynamic-border.js +1 -0
  836. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  837. package/dist/modes/interactive/components/extension-editor.d.ts +4 -1
  838. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  839. package/dist/modes/interactive/components/extension-editor.js +14 -3
  840. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  841. package/dist/modes/interactive/components/extension-input.d.ts +2 -0
  842. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  843. package/dist/modes/interactive/components/extension-input.js +14 -2
  844. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  845. package/dist/modes/interactive/components/extension-selector.d.ts +50 -0
  846. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  847. package/dist/modes/interactive/components/extension-selector.js +218 -6
  848. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  849. package/dist/modes/interactive/components/first-time-setup.d.ts +4 -4
  850. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  851. package/dist/modes/interactive/components/first-time-setup.js +12 -4
  852. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  853. package/dist/modes/interactive/components/footer.d.ts +7 -0
  854. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  855. package/dist/modes/interactive/components/footer.js +51 -6
  856. package/dist/modes/interactive/components/footer.js.map +1 -1
  857. package/dist/modes/interactive/components/index.d.ts +1 -1
  858. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  859. package/dist/modes/interactive/components/index.js.map +1 -1
  860. package/dist/modes/interactive/components/login-dialog.js +9 -3
  861. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  862. package/dist/modes/interactive/components/markdown-transform.d.ts +3 -0
  863. package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
  864. package/dist/modes/interactive/components/markdown-transform.js +19 -0
  865. package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
  866. package/dist/modes/interactive/components/mermaid.d.ts +11 -0
  867. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
  868. package/dist/modes/interactive/components/mermaid.js +75 -0
  869. package/dist/modes/interactive/components/mermaid.js.map +1 -0
  870. package/dist/modes/interactive/components/model-selector.d.ts +10 -4
  871. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  872. package/dist/modes/interactive/components/model-selector.js +101 -40
  873. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  874. package/dist/modes/interactive/components/oauth-selector.js +11 -3
  875. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  876. package/dist/modes/interactive/components/scoped-models-selector.d.ts +4 -0
  877. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  878. package/dist/modes/interactive/components/scoped-models-selector.js +60 -32
  879. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  880. package/dist/modes/interactive/components/session-selector.d.ts +5 -5
  881. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  882. package/dist/modes/interactive/components/session-selector.js +138 -80
  883. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  884. package/dist/modes/interactive/components/settings-selector.d.ts +25 -4
  885. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  886. package/dist/modes/interactive/components/settings-selector.js +240 -67
  887. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  888. package/dist/modes/interactive/components/settings-submenu.d.ts +72 -0
  889. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -0
  890. package/dist/modes/interactive/components/settings-submenu.js +165 -0
  891. package/dist/modes/interactive/components/settings-submenu.js.map +1 -0
  892. package/dist/modes/interactive/components/show-images-selector.js +1 -0
  893. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  894. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  895. package/dist/modes/interactive/components/skill-invocation-message.js +14 -5
  896. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  897. package/dist/modes/interactive/components/status-indicator.d.ts +3 -1
  898. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  899. package/dist/modes/interactive/components/status-indicator.js +12 -3
  900. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  901. package/dist/modes/interactive/components/theme-selector.js +2 -0
  902. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  903. package/dist/modes/interactive/components/themed-text.d.ts +17 -0
  904. package/dist/modes/interactive/components/themed-text.d.ts.map +1 -0
  905. package/dist/modes/interactive/components/themed-text.js +29 -0
  906. package/dist/modes/interactive/components/themed-text.js.map +1 -0
  907. package/dist/modes/interactive/components/thinking-selector.d.ts +15 -3
  908. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  909. package/dist/modes/interactive/components/thinking-selector.js +76 -18
  910. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  911. package/dist/modes/interactive/components/tool-execution.d.ts +21 -4
  912. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  913. package/dist/modes/interactive/components/tool-execution.js +88 -53
  914. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  915. package/dist/modes/interactive/components/tree-selector.d.ts +20 -2
  916. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  917. package/dist/modes/interactive/components/tree-selector.js +65 -23
  918. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  919. package/dist/modes/interactive/components/trust-selector.js +8 -2
  920. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  921. package/dist/modes/interactive/components/user-message-selector.js +6 -3
  922. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  923. package/dist/modes/interactive/components/user-message.d.ts +3 -1
  924. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  925. package/dist/modes/interactive/components/user-message.js +12 -2
  926. package/dist/modes/interactive/components/user-message.js.map +1 -1
  927. package/dist/modes/interactive/components/visual-truncate.d.ts +27 -3
  928. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  929. package/dist/modes/interactive/components/visual-truncate.js +39 -6
  930. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  931. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  932. package/dist/modes/interactive/external-editor.js +2 -1
  933. package/dist/modes/interactive/external-editor.js.map +1 -1
  934. package/dist/modes/interactive/interactive-mode.d.ts +166 -8
  935. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  936. package/dist/modes/interactive/interactive-mode.js +1690 -599
  937. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  938. package/dist/modes/interactive/model-catalog-refresh.d.ts +7 -0
  939. package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -0
  940. package/dist/modes/interactive/model-catalog-refresh.js +34 -0
  941. package/dist/modes/interactive/model-catalog-refresh.js.map +1 -0
  942. package/dist/modes/interactive/session-share.d.ts +23 -0
  943. package/dist/modes/interactive/session-share.d.ts.map +1 -0
  944. package/dist/modes/interactive/session-share.js +130 -0
  945. package/dist/modes/interactive/session-share.js.map +1 -0
  946. package/dist/modes/interactive/theme/dark.json +54 -63
  947. package/dist/modes/interactive/theme/light.json +52 -60
  948. package/dist/modes/interactive/theme/system-theme.d.ts +54 -0
  949. package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -0
  950. package/dist/modes/interactive/theme/system-theme.js +535 -0
  951. package/dist/modes/interactive/theme/system-theme.js.map +1 -0
  952. package/dist/modes/interactive/theme/theme-controller.d.ts +59 -7
  953. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  954. package/dist/modes/interactive/theme/theme-controller.js +164 -51
  955. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  956. package/dist/modes/interactive/theme/theme-json.d.ts +85 -0
  957. package/dist/modes/interactive/theme/theme-json.d.ts.map +1 -0
  958. package/dist/modes/interactive/theme/theme-json.js +132 -0
  959. package/dist/modes/interactive/theme/theme-json.js.map +1 -0
  960. package/dist/modes/interactive/theme/theme-schema.json +24 -3
  961. package/dist/modes/interactive/theme/theme.d.ts +80 -42
  962. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  963. package/dist/modes/interactive/theme/theme.js +274 -417
  964. package/dist/modes/interactive/theme/theme.js.map +1 -1
  965. package/dist/modes/interactive/tui-renderer.d.ts +22 -0
  966. package/dist/modes/interactive/tui-renderer.d.ts.map +1 -0
  967. package/dist/modes/interactive/tui-renderer.js +67 -0
  968. package/dist/modes/interactive/tui-renderer.js.map +1 -0
  969. package/dist/modes/json-event.d.ts +34 -0
  970. package/dist/modes/json-event.d.ts.map +1 -0
  971. package/dist/modes/json-event.js +29 -0
  972. package/dist/modes/json-event.js.map +1 -0
  973. package/dist/modes/print-mode.d.ts +1 -1
  974. package/dist/modes/print-mode.d.ts.map +1 -1
  975. package/dist/modes/print-mode.js +12 -2
  976. package/dist/modes/print-mode.js.map +1 -1
  977. package/dist/modes/rpc/rpc-client.d.ts +17 -9
  978. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  979. package/dist/modes/rpc/rpc-client.js +27 -15
  980. package/dist/modes/rpc/rpc-client.js.map +1 -1
  981. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  982. package/dist/modes/rpc/rpc-mode.js +179 -19
  983. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  984. package/dist/modes/rpc/rpc-types.d.ts +90 -2
  985. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  986. package/dist/modes/rpc/rpc-types.js.map +1 -1
  987. package/dist/package-manager-cli.d.ts +1 -0
  988. package/dist/package-manager-cli.d.ts.map +1 -1
  989. package/dist/package-manager-cli.js +217 -63
  990. package/dist/package-manager-cli.js.map +1 -1
  991. package/dist/prompts/commands/atomic-commit.md +1 -12
  992. package/dist/prompts/commands/brainstorm.md +12 -15
  993. package/dist/prompts/commands/create-verification-skill.md +108 -0
  994. package/dist/prompts/commands/discuss-phase.md +3 -14
  995. package/dist/prompts/commands/execute-phase.md +3 -11
  996. package/dist/prompts/commands/fix.md +41 -18
  997. package/dist/prompts/commands/grill.md +66 -0
  998. package/dist/prompts/commands/init-project.md +5 -15
  999. package/dist/prompts/commands/map-codebase.md +1 -13
  1000. package/dist/prompts/commands/new-project.md +5 -15
  1001. package/dist/prompts/commands/next-milestone.md +1 -13
  1002. package/dist/prompts/commands/orchestrate.md +1 -1
  1003. package/dist/prompts/commands/pause-work.md +1 -13
  1004. package/dist/prompts/commands/plan-phase.md +3 -11
  1005. package/dist/prompts/commands/progress.md +0 -13
  1006. package/dist/prompts/commands/quick.md +3 -11
  1007. package/dist/prompts/commands/resolve-conflicts.md +71 -0
  1008. package/dist/prompts/commands/resume-work.md +0 -13
  1009. package/dist/prompts/commands/review.md +6 -13
  1010. package/dist/prompts/commands/triage.md +159 -0
  1011. package/dist/prompts/commands/verify-work.md +5 -14
  1012. package/dist/prompts/commands/why.md +139 -0
  1013. package/dist/rpc-entry.js +1 -0
  1014. package/dist/rpc-entry.js.map +1 -1
  1015. package/dist/skills/atomic-reasoning/SKILL.md +115 -0
  1016. package/dist/skills/blast-radius/SKILL.md +56 -0
  1017. package/dist/skills/epistemics/SKILL.md +99 -0
  1018. package/dist/skills/explainers/SKILL.md +65 -0
  1019. package/dist/skills/hexagon-animation/SKILL.md +49 -0
  1020. package/dist/skills/hexagon-animation/generate.mjs +81 -0
  1021. package/dist/skills/hexagon-animation/template.html +361 -0
  1022. package/dist/skills/typescript-discipline/SKILL.md +50 -0
  1023. package/dist/skills/typescript-discipline/references/patterns.md +294 -0
  1024. package/dist/skills/unslop/SKILL.md +119 -0
  1025. package/dist/utils/abort.d.ts +5 -0
  1026. package/dist/utils/abort.d.ts.map +1 -0
  1027. package/dist/utils/abort.js +48 -0
  1028. package/dist/utils/abort.js.map +1 -0
  1029. package/dist/utils/canonical-path.d.ts +28 -0
  1030. package/dist/utils/canonical-path.d.ts.map +1 -0
  1031. package/dist/utils/canonical-path.js +90 -0
  1032. package/dist/utils/canonical-path.js.map +1 -0
  1033. package/dist/utils/changelog.js +1 -1
  1034. package/dist/utils/changelog.js.map +1 -1
  1035. package/dist/utils/child-process.d.ts +13 -2
  1036. package/dist/utils/child-process.d.ts.map +1 -1
  1037. package/dist/utils/child-process.js +26 -9
  1038. package/dist/utils/child-process.js.map +1 -1
  1039. package/dist/utils/clipboard-command.d.ts +7 -0
  1040. package/dist/utils/clipboard-command.d.ts.map +1 -0
  1041. package/dist/utils/clipboard-command.js +45 -0
  1042. package/dist/utils/clipboard-command.js.map +1 -0
  1043. package/dist/utils/clipboard-image.d.ts.map +1 -1
  1044. package/dist/utils/clipboard-image.js +60 -91
  1045. package/dist/utils/clipboard-image.js.map +1 -1
  1046. package/dist/utils/clipboard.d.ts +3 -1
  1047. package/dist/utils/clipboard.d.ts.map +1 -1
  1048. package/dist/utils/clipboard.js +123 -108
  1049. package/dist/utils/clipboard.js.map +1 -1
  1050. package/dist/utils/draht-user-agent.d.ts +2 -0
  1051. package/dist/utils/draht-user-agent.d.ts.map +1 -0
  1052. package/dist/utils/draht-user-agent.js +5 -0
  1053. package/dist/utils/draht-user-agent.js.map +1 -0
  1054. package/dist/utils/exif-orientation.d.ts +2 -1
  1055. package/dist/utils/exif-orientation.d.ts.map +1 -1
  1056. package/dist/utils/exif-orientation.js +2 -3
  1057. package/dist/utils/exif-orientation.js.map +1 -1
  1058. package/dist/utils/frontmatter.d.ts.map +1 -1
  1059. package/dist/utils/frontmatter.js +2 -1
  1060. package/dist/utils/frontmatter.js.map +1 -1
  1061. package/dist/utils/management-http.d.ts +25 -0
  1062. package/dist/utils/management-http.d.ts.map +1 -0
  1063. package/dist/utils/management-http.js +54 -0
  1064. package/dist/utils/management-http.js.map +1 -0
  1065. package/dist/utils/mime.js +1 -1
  1066. package/dist/utils/mime.js.map +1 -1
  1067. package/dist/utils/paths.d.ts +6 -10
  1068. package/dist/utils/paths.d.ts.map +1 -1
  1069. package/dist/utils/paths.js +23 -14
  1070. package/dist/utils/paths.js.map +1 -1
  1071. package/dist/utils/photon.d.ts +2 -1
  1072. package/dist/utils/photon.d.ts.map +1 -1
  1073. package/dist/utils/photon.js.map +1 -1
  1074. package/dist/utils/shell.d.ts +4 -3
  1075. package/dist/utils/shell.d.ts.map +1 -1
  1076. package/dist/utils/shell.js +26 -39
  1077. package/dist/utils/shell.js.map +1 -1
  1078. package/dist/utils/syntax-highlight.d.ts +1 -0
  1079. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  1080. package/dist/utils/syntax-highlight.js +62 -1
  1081. package/dist/utils/syntax-highlight.js.map +1 -1
  1082. package/dist/utils/text.d.ts +8 -0
  1083. package/dist/utils/text.d.ts.map +1 -0
  1084. package/dist/utils/text.js +9 -0
  1085. package/dist/utils/text.js.map +1 -0
  1086. package/dist/utils/tool-result-images.d.ts +21 -0
  1087. package/dist/utils/tool-result-images.d.ts.map +1 -0
  1088. package/dist/utils/tool-result-images.js +48 -0
  1089. package/dist/utils/tool-result-images.js.map +1 -0
  1090. package/dist/utils/tools-manager.d.ts +11 -1
  1091. package/dist/utils/tools-manager.d.ts.map +1 -1
  1092. package/dist/utils/tools-manager.js +56 -41
  1093. package/dist/utils/tools-manager.js.map +1 -1
  1094. package/dist/utils/version-check.d.ts +4 -1
  1095. package/dist/utils/version-check.d.ts.map +1 -1
  1096. package/dist/utils/version-check.js +30 -9
  1097. package/dist/utils/version-check.js.map +1 -1
  1098. package/dist/utils/wsl.d.ts +3 -0
  1099. package/dist/utils/wsl.d.ts.map +1 -0
  1100. package/dist/utils/wsl.js +15 -0
  1101. package/dist/utils/wsl.js.map +1 -0
  1102. package/dist/utils/zip.d.ts +7 -0
  1103. package/dist/utils/zip.d.ts.map +1 -0
  1104. package/dist/utils/zip.js +60 -0
  1105. package/dist/utils/zip.js.map +1 -0
  1106. package/docs/attachable-sessions.md +79 -0
  1107. package/docs/cli-integration.md +106 -0
  1108. package/docs/cli.md +374 -0
  1109. package/docs/compaction.md +107 -45
  1110. package/docs/configuration.md +47 -0
  1111. package/docs/containerization.md +100 -66
  1112. package/docs/custom-provider.md +109 -707
  1113. package/docs/docs.json +155 -95
  1114. package/docs/duet.md +42 -0
  1115. package/docs/environment-variables.md +30 -17
  1116. package/docs/extensions.md +169 -2811
  1117. package/docs/how-pi-works.md +53 -0
  1118. package/docs/images/interactive-mode.png +0 -0
  1119. package/docs/index.md +25 -69
  1120. package/docs/json.md +198 -57
  1121. package/docs/keybindings.md +89 -92
  1122. package/docs/llama-cpp.md +23 -8
  1123. package/docs/mcp.md +231 -0
  1124. package/docs/message-types.md +261 -0
  1125. package/docs/models.md +94 -478
  1126. package/docs/packages.md +68 -164
  1127. package/docs/prompt-templates.md +31 -68
  1128. package/docs/providers.md +118 -215
  1129. package/docs/quickstart.md +56 -109
  1130. package/docs/rpc-commands.md +860 -0
  1131. package/docs/rpc-extension-ui.md +200 -0
  1132. package/docs/rpc.md +186 -1494
  1133. package/docs/sdk.md +79 -1127
  1134. package/docs/security.md +77 -33
  1135. package/docs/session-format.md +98 -222
  1136. package/docs/sessions.md +36 -113
  1137. package/docs/settings.md +125 -251
  1138. package/docs/shell-aliases.md +85 -5
  1139. package/docs/skills.md +52 -188
  1140. package/docs/slash-commands.md +61 -0
  1141. package/docs/terminal-setup.md +132 -61
  1142. package/docs/termux.md +74 -84
  1143. package/docs/themes.md +91 -252
  1144. package/docs/tmux.md +31 -39
  1145. package/docs/tui.md +74 -891
  1146. package/docs/usage.md +54 -255
  1147. package/docs/virtual-models.md +114 -0
  1148. package/docs/windows.md +57 -7
  1149. package/examples/extensions/antigravity-image-gen.ts +9 -9
  1150. package/examples/extensions/bash-spawn-hook.ts +1 -1
  1151. package/examples/extensions/border-status-editor.ts +1 -1
  1152. package/examples/extensions/built-in-tool-renderer.ts +16 -40
  1153. package/examples/extensions/custom-compaction.ts +1 -16
  1154. package/examples/extensions/custom-provider-anthropic/index.ts +20 -13
  1155. package/examples/extensions/custom-provider-gitlab-duo/index.ts +4 -3
  1156. package/examples/extensions/custom-provider-gitlab-duo/test.ts +5 -5
  1157. package/examples/extensions/debug-provider.ts +90 -0
  1158. package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
  1159. package/examples/extensions/dynamic-resources/dynamic.json +3 -1
  1160. package/examples/extensions/git-checkpoint.ts +2 -2
  1161. package/examples/extensions/handoff.ts +2 -11
  1162. package/examples/extensions/jev-router.ts +113 -0
  1163. package/examples/extensions/minimal-mode.ts +24 -96
  1164. package/examples/extensions/notify.ts +3 -1
  1165. package/examples/extensions/overlay-qa-tests.ts +3 -3
  1166. package/examples/extensions/prompt-customizer.ts +19 -67
  1167. package/examples/extensions/qna.ts +3 -7
  1168. package/examples/extensions/subagent/agents.ts +40 -9
  1169. package/examples/extensions/subagent/index.ts +27 -4
  1170. package/examples/extensions/summarize.ts +7 -18
  1171. package/examples/extensions/titlebar-spinner.ts +1 -1
  1172. package/examples/rpc-client.ts +35 -0
  1173. package/examples/rpc-extension-ui.ts +38 -9
  1174. package/examples/sdk/02-custom-model.ts +1 -2
  1175. package/examples/sdk/06-extensions.ts +1 -1
  1176. package/examples/sdk/09-api-keys-and-oauth.ts +1 -1
  1177. package/examples/sdk/12-full-control.ts +1 -1
  1178. package/examples/sdk/14-codemode-mcp.ts +61 -0
  1179. package/hooks/gsd/draht-quality-gate.js +3 -3
  1180. package/package.json +28 -32
  1181. package/prompts/commands/atomic-commit.md +1 -12
  1182. package/prompts/commands/brainstorm.md +12 -15
  1183. package/prompts/commands/create-verification-skill.md +108 -0
  1184. package/prompts/commands/discuss-phase.md +3 -14
  1185. package/prompts/commands/execute-phase.md +3 -11
  1186. package/prompts/commands/fix.md +41 -18
  1187. package/prompts/commands/grill.md +66 -0
  1188. package/prompts/commands/init-project.md +5 -15
  1189. package/prompts/commands/map-codebase.md +1 -13
  1190. package/prompts/commands/new-project.md +5 -15
  1191. package/prompts/commands/next-milestone.md +1 -13
  1192. package/prompts/commands/orchestrate.md +1 -1
  1193. package/prompts/commands/pause-work.md +1 -13
  1194. package/prompts/commands/plan-phase.md +3 -11
  1195. package/prompts/commands/progress.md +0 -13
  1196. package/prompts/commands/quick.md +3 -11
  1197. package/prompts/commands/resolve-conflicts.md +71 -0
  1198. package/prompts/commands/resume-work.md +0 -13
  1199. package/prompts/commands/review.md +6 -13
  1200. package/prompts/commands/triage.md +159 -0
  1201. package/prompts/commands/verify-work.md +5 -14
  1202. package/prompts/commands/why.md +139 -0
  1203. package/skills/atomic-reasoning/SKILL.md +115 -0
  1204. package/skills/blast-radius/SKILL.md +56 -0
  1205. package/skills/epistemics/SKILL.md +99 -0
  1206. package/skills/explainers/SKILL.md +65 -0
  1207. package/skills/hexagon-animation/SKILL.md +49 -0
  1208. package/skills/hexagon-animation/generate.mjs +81 -0
  1209. package/skills/hexagon-animation/template.html +361 -0
  1210. package/skills/typescript-discipline/SKILL.md +50 -0
  1211. package/skills/typescript-discipline/references/patterns.md +294 -0
  1212. package/skills/unslop/SKILL.md +119 -0
  1213. package/dist/prompts/agents/build.md +0 -86
  1214. package/dist/prompts/agents/plan.md +0 -79
  1215. package/dist/prompts/agents/verify.md +0 -69
  1216. package/dist/utils/clipboard-native.d.ts +0 -11
  1217. package/dist/utils/clipboard-native.d.ts.map +0 -1
  1218. package/dist/utils/clipboard-native.js +0 -20
  1219. package/dist/utils/clipboard-native.js.map +0 -1
  1220. package/dist/utils/pi-user-agent.d.ts +0 -2
  1221. package/dist/utils/pi-user-agent.d.ts.map +0 -1
  1222. package/dist/utils/pi-user-agent.js +0 -5
  1223. package/dist/utils/pi-user-agent.js.map +0 -1
  1224. package/docs/development.md +0 -71
  1225. package/docs/tree.md +0 -231
  1226. package/examples/extensions/kimi-deferred-tools.ts +0 -61
  1227. package/prompts/agents/build.md +0 -86
  1228. package/prompts/agents/plan.md +0 -79
  1229. package/prompts/agents/verify.md +0 -69
@@ -7,10 +7,150 @@
7
7
  * - Input from any client is echoed to all others
8
8
  * - Clients can join/leave without disrupting the session
9
9
  */
10
- import { existsSync } from "node:fs";
11
- import { mkdir, rm, writeFile } from "node:fs/promises";
10
+ import { rmSync } from "node:fs";
11
+ import { chmod, lstat, mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
12
12
  import { createServer } from "node:net";
13
13
  import path from "node:path";
14
+ import { assertValidSessionId } from "../session-manager.js";
15
+ import { getSoakLog, SOAK_EVENTS } from "../soak/soak-log.js";
16
+ import { currentUid, discoverSocketSessions, pidOwnership } from "./discovery.js";
17
+ import { CLIENT_MODES, PERMISSION_RELAY_CAPABILITY, } from "./types.js";
18
+ /**
19
+ * How long {@link SocketServer.stop} waits for peers to close their end before it
20
+ * forces the remaining sockets down.
21
+ */
22
+ const STOP_CLOSE_TIMEOUT_MS = 1000;
23
+ /**
24
+ * How long a lock file with no readable PID has to sit untouched before it counts as
25
+ * debris rather than as a claim another starter is in the middle of writing.
26
+ */
27
+ const UNWRITTEN_LOCK_STALE_MS = 10_000;
28
+ /**
29
+ * How many live attachable sockets one host may hold (R35-ALWAYS.4).
30
+ *
31
+ * There was no cap at all: 500 sockets bound in one process with zero refusals,
32
+ * and `ulimit -n` on the development machine is 1048576, so the fd ceiling never
33
+ * arrives to stop a crash-restart loop. 64 is far above real use — a heavy user
34
+ * runs perhaps 10-20 concurrent sessions — and still low enough that a runaway is
35
+ * caught while the machine is healthy. It is a per-host number, counted from the
36
+ * sockets directory after the start-time sweep, not a per-process one: the point
37
+ * is to bound what accumulates on disk, and a restart loop is a new process each
38
+ * time.
39
+ *
40
+ * Overridable per server via {@link SocketServerOptions.maxLiveSockets}.
41
+ */
42
+ export const DEFAULT_MAX_LIVE_SOCKETS = 64;
43
+ /**
44
+ * Longest client-supplied string this file will copy into the soak log.
45
+ *
46
+ * A `clientId` and a client `mode` arrive over the socket and are self-asserted.
47
+ * They are recorded because a soak verdict has to be able to name which peer
48
+ * churned — and bounded because the log is append-only for weeks and a peer must
49
+ * not be able to make one line of it megabytes long.
50
+ */
51
+ const SOAK_LABEL_MAX = 128;
52
+ /**
53
+ * One soak record, and nothing else: no stdout, no stderr, no throw. See the
54
+ * three rules at the head of the same helper in `session-integration.ts`; the
55
+ * helper is kept per-file rather than shared because the only places to share it
56
+ * from are `soak-log.ts` (a finished file this task may not edit) or a fourth
57
+ * module that would exist solely to hold six lines.
58
+ *
59
+ * `sessionId` is passed through as an ordinary field: the writer stamps its own
60
+ * over it whenever it has one — which it does for every session process, set at
61
+ * bind — and honours this one otherwise, so a `SocketServer` used outside a
62
+ * session still records under the id it was refused for.
63
+ */
64
+ function soakRecord(event, fields, level = "info") {
65
+ try {
66
+ getSoakLog().record(event, fields, level);
67
+ }
68
+ catch {
69
+ // Deliberately empty, and deliberately not logged anywhere.
70
+ }
71
+ }
72
+ /** A client-supplied value, made safe to put in a record: a bounded string, always. */
73
+ function soakLabel(value) {
74
+ const text = typeof value === "string" ? value : JSON.stringify(value);
75
+ return (text ?? String(value)).slice(0, SOAK_LABEL_MAX);
76
+ }
77
+ /**
78
+ * Thrown when another live process already owns the socket for this session id.
79
+ *
80
+ * Taking the socket over would silently steal attachments from a running session,
81
+ * so the second process refuses to bind instead.
82
+ */
83
+ export class SocketSessionBusyError extends Error {
84
+ sessionId;
85
+ /** PID of the owning process, or null when the lock exists but names no readable PID. */
86
+ ownerPid;
87
+ socketPath;
88
+ constructor(sessionId, ownerPid, socketPath) {
89
+ // Two genuinely different situations - do not describe them the same way. A
90
+ // readable PID means a live process really does own this session. An
91
+ // unreadable lock usually means another process is claiming it right now, but
92
+ // it is equally a lock left truncated by a process killed mid-claim, in which
93
+ // case nothing is running and the claim clears itself shortly.
94
+ super(ownerPid === null
95
+ ? `Session "${sessionId}" has an attachable lock that names no readable PID. ` +
96
+ `Another process is probably claiming it right now; it can also be debris from a ` +
97
+ `process killed mid-claim, in which case it clears itself within ` +
98
+ `${Math.round(UNWRITTEN_LOCK_STALE_MS / 1000)}s. Retry shortly. Socket: ${socketPath}`
99
+ : `Session "${sessionId}" is already attachable from a running process (PID ${ownerPid}). ` +
100
+ `Attach to it instead, or stop that process. Socket: ${socketPath}`);
101
+ this.name = "SocketSessionBusyError";
102
+ this.sessionId = sessionId;
103
+ this.ownerPid = ownerPid;
104
+ this.socketPath = socketPath;
105
+ }
106
+ }
107
+ /**
108
+ * Thrown when this host already holds as many live attachable sockets as it may.
109
+ *
110
+ * Names both the cap and the count that hit it, so an operator can tell a cap
111
+ * from a bug without reading the source. Exported deliberately and by name: the
112
+ * default-on start path branches on `error instanceof SocketCapReachedError` to
113
+ * pick the one refusal message that must never be confused with a broken sockets
114
+ * directory. A cap-hit is not a reason to refuse to START a session — that
115
+ * decision belongs to the caller, and this class exists so the caller can make it.
116
+ */
117
+ export class SocketCapReachedError extends Error {
118
+ sessionId;
119
+ /** The cap that was enforced. */
120
+ cap;
121
+ /** Live sockets counted, after debris was reaped. */
122
+ liveCount;
123
+ socketDir;
124
+ constructor(sessionId, cap, liveCount, socketDir) {
125
+ super(`This machine already holds ${liveCount} live attachable sessions and the cap is ${cap}. ` +
126
+ `Session "${sessionId}" was not registered. Stop a session you are no longer using, or raise ` +
127
+ `the cap. Sockets: ${socketDir}`);
128
+ this.name = "SocketCapReachedError";
129
+ this.sessionId = sessionId;
130
+ this.cap = cap;
131
+ this.liveCount = liveCount;
132
+ this.socketDir = socketDir;
133
+ }
134
+ }
135
+ /**
136
+ * Thrown when the sockets directory is not a directory this user owns privately.
137
+ *
138
+ * The 0700 mode was the ONLY same-owner protection that existed, and nothing
139
+ * asserted it: there is not one `getuid()` call in the whole of coding-agent,
140
+ * geist-core or the gateway. A world-writable directory holding a 0666 socket and
141
+ * a lock naming root's pid 1 was listed as a live attachable session and would
142
+ * have been dialled. Refusing is the point — silently `chmod`ing a directory this
143
+ * process does not own would either fail with EPERM or, worse, succeed on a
144
+ * directory somebody else planted.
145
+ */
146
+ export class SocketDirectoryUnsafeError extends Error {
147
+ socketDir;
148
+ constructor(socketDir, reason) {
149
+ super(`Refusing to publish an attachable session in ${socketDir}: ${reason}`);
150
+ this.name = "SocketDirectoryUnsafeError";
151
+ this.socketDir = socketDir;
152
+ }
153
+ }
14
154
  /**
15
155
  * SocketServer manages a Unix domain socket for a single draht session.
16
156
  *
@@ -22,64 +162,244 @@ export class SocketServer {
22
162
  #socketPath;
23
163
  #lockPath;
24
164
  #cwd;
165
+ #socketDir;
25
166
  #maxClients;
167
+ #maxLiveSockets;
26
168
  #broadcastInputEcho;
27
169
  #server = null;
28
170
  #clients = new Map();
171
+ /**
172
+ * Every accepted connection, including ones that never sent an `attach` frame.
173
+ * `#clients` only holds attached peers, and shutdown has to reach the others too.
174
+ */
175
+ #sockets = new Set();
29
176
  #createdAt = new Date();
177
+ #stopped = false;
178
+ /**
179
+ * Whether THIS instance won the exclusive lock create. Only an owner may remove
180
+ * the socket/lock files; an instance whose start() was refused must never delete
181
+ * the live owner's files.
182
+ */
183
+ #ownsLock = false;
184
+ #rejectListen = null;
30
185
  /** Callback for input received from any client */
31
186
  #onInput = null;
187
+ /**
188
+ * Callback for a permission answer from a client. Nothing here decides
189
+ * anything: this class is plumbing, and the pending-ask registry that owns
190
+ * validation, first-answer-wins and expiry lives on the session side.
191
+ *
192
+ * With no callback registered, an answer is refused with a targeted
193
+ * `PERMISSION_UNKNOWN_REQUEST` error rather than swallowed — a phone must be
194
+ * able to tell "answered" from "this draht is too old to have asked".
195
+ */
196
+ #onPermissionResponse = null;
197
+ /**
198
+ * Fired immediately after a newly attached client has been sent
199
+ * `session_metadata`, so whatever holds unanswered asks can replay them to a
200
+ * client that arrived after they were raised.
201
+ */
202
+ #onAttachReplay = null;
203
+ /**
204
+ * Fired when an attached client's connection ends. Everything that keeps
205
+ * per-connection state outside this class resets it here.
206
+ */
207
+ #onClientDisconnect = null;
32
208
  constructor(options) {
209
+ // The id becomes a path component of the .sock and .lock files, and it arrives here
210
+ // straight from a session file on disk, so it is untrusted input. Reject anything
211
+ // that is not a plain session id rather than trying to sanitize it.
212
+ assertValidSessionId(options.sessionId);
33
213
  this.#sessionId = options.sessionId;
34
214
  this.#cwd = options.cwd;
35
215
  this.#maxClients = options.maxClients ?? 10;
216
+ this.#maxLiveSockets = options.maxLiveSockets ?? DEFAULT_MAX_LIVE_SOCKETS;
36
217
  this.#broadcastInputEcho = options.broadcastInputEcho ?? true;
218
+ this.#socketDir = options.socketDir;
37
219
  this.#socketPath = path.join(options.socketDir, `${options.sessionId}.sock`);
38
220
  this.#lockPath = path.join(options.socketDir, `${options.sessionId}.lock`);
39
221
  }
40
222
  /**
41
223
  * Start the socket server.
42
- * Creates socket directory, binds Unix socket, and starts listening.
224
+ * Creates socket directory, claims the session lock, binds the Unix socket, and listens.
225
+ *
226
+ * @throws {SocketSessionBusyError} When another live process already owns this session's socket.
227
+ * @throws {SocketDirectoryUnsafeError} When the sockets directory is not a private directory of ours.
228
+ * @throws {SocketCapReachedError} When this host already holds the maximum number of live sockets.
43
229
  */
44
230
  async start() {
45
- // Ensure socket directory exists
231
+ // Ensure socket directory exists and is owner-only. `mkdir` applies its mode only
232
+ // when it creates the directory, and masks it with the umask, so re-assert it on
233
+ // the path that created it.
46
234
  const socketDir = path.dirname(this.#socketPath);
47
- await mkdir(socketDir, { recursive: true, mode: 0o700 });
48
- // Clean up stale socket if it exists
49
- if (existsSync(this.#socketPath)) {
50
- await rm(this.#socketPath, { force: true });
235
+ const created = await mkdir(socketDir, { recursive: true, mode: 0o700 });
236
+ if (created !== undefined)
237
+ await chmod(socketDir, 0o700);
238
+ // Then assert it, every time, before anything is written into it.
239
+ await this.#assertSocketDirIsOurs(socketDir);
240
+ // REAP ON START (R35-ALWAYS.4). Before this, start() touched only this session's
241
+ // two paths and reaping happened ONLY inside discovery — so on a machine where no
242
+ // phone and no daemon ever asks for the fleet, the directory grew without bound.
243
+ // Measured: 25 start/SIGKILL cycles of the emitted binary left exactly 50 files,
244
+ // strictly linear, zero reaped. A full sweep here is what makes "N crash cycles
245
+ // leave nothing behind" true without a second process having to come along.
246
+ //
247
+ // Not sampled and not bounded: measured cost is 12-32 ms to scan 1000 live pairs
248
+ // and 106 ms to reap 1000 dead ones, once per session start, against the cap
249
+ // below. Sampling would trade a bounded, once-per-start cost for an unbounded
250
+ // on-disk one.
251
+ const live = await discoverSocketSessions(socketDir);
252
+ // THE CAP, counted after the sweep so debris can never be what refuses a session.
253
+ // Our own id does not count against it: re-binding a session id we already hold
254
+ // replaces one socket, it does not add one.
255
+ const others = live.filter((session) => session.sessionId !== this.#sessionId).length;
256
+ if (others >= this.#maxLiveSockets) {
257
+ // A refusal is the most interesting thing that can happen at a bind, and it is
258
+ // the one outcome that leaves NO socket behind for anything else to notice.
259
+ soakRecord(SOAK_EVENTS.CLIENT_REJECTED, {
260
+ reason: "socket_cap_reached",
261
+ sessionId: this.#sessionId,
262
+ cap: this.#maxLiveSockets,
263
+ liveSockets: others,
264
+ }, "warn");
265
+ throw new SocketCapReachedError(this.#sessionId, this.#maxLiveSockets, others, socketDir);
266
+ }
267
+ // Take ownership of the session id before touching the socket path.
268
+ try {
269
+ await this.#claimLock();
270
+ }
271
+ catch (error) {
272
+ // The busy twin (`draht -c` in a second terminal) is the commonest default-on
273
+ // refusal there is and it is not environmental, so a soak that could not count
274
+ // them would mistake the phase's most likely papercut for silence.
275
+ if (error instanceof SocketSessionBusyError) {
276
+ soakRecord(SOAK_EVENTS.CLIENT_REJECTED, { reason: "session_busy", sessionId: this.#sessionId, ownerPid: error.ownerPid }, "warn");
277
+ }
278
+ throw error;
279
+ }
280
+ try {
281
+ this.#server = createServer((socket) => this.#handleConnection(socket));
282
+ const server = this.#server;
283
+ // One long-lived error listener: it rejects the pending listen() and swallows
284
+ // post-startup server errors, which must not become uncaught exceptions.
285
+ server.on("error", (error) => {
286
+ const reject = this.#rejectListen;
287
+ this.#rejectListen = null;
288
+ reject?.(error);
289
+ });
290
+ await new Promise((resolve, reject) => {
291
+ this.#rejectListen = reject;
292
+ server.listen(this.#socketPath, () => {
293
+ this.#rejectListen = null;
294
+ resolve();
295
+ });
296
+ });
297
+ // bind(2) applies the process umask, so tighten the socket explicitly. Between
298
+ // bind and this chmod the socket is still unreachable for other users: it can
299
+ // only be named through the 0700 directory above, and Unix-domain permissions
300
+ // are enforced at connect(2) time. Mutating the process-global umask instead
301
+ // would leak into every unrelated file this process creates concurrently.
302
+ await chmod(this.#socketPath, 0o600);
303
+ }
304
+ catch (error) {
305
+ // Never leave a lock behind that advertises a socket which was never bound.
306
+ this.#server = null;
307
+ this.#rejectListen = null;
308
+ await rm(this.#lockPath, { force: true }).catch(() => { });
309
+ await rm(this.#socketPath, { force: true }).catch(() => { });
310
+ throw error;
51
311
  }
52
- // Write PID lock file for cleanup on crash
53
- await writeFile(this.#lockPath, `${process.pid}\n${this.#cwd}\n${this.#createdAt.toISOString()}`);
54
- // Create Unix domain socket server
55
- this.#server = createServer((socket) => this.#handleConnection(socket));
56
- // Bind to socket path
57
- await new Promise((resolve, reject) => {
58
- this.#server.listen(this.#socketPath, () => resolve());
59
- this.#server.on("error", reject);
60
- });
61
- // Set socket permissions (owner-only)
62
- await import("node:fs/promises").then((fs) => fs.chmod(this.#socketPath, 0o600));
63
312
  }
64
313
  /**
65
314
  * Stop the socket server and clean up.
66
315
  */
67
316
  async stop() {
68
- // Disconnect all clients
69
- for (const client of this.#clients.values()) {
70
- client.socket.end();
317
+ if (this.#stopped)
318
+ return;
319
+ this.#stopped = true;
320
+ // Half-close every accepted connection, not just the attached clients: a peer that
321
+ // connected and never sent an `attach` frame is not in #clients, and leaving it open
322
+ // would keep server.close() from ever calling back.
323
+ for (const socket of this.#sockets) {
324
+ try {
325
+ socket.end();
326
+ }
327
+ catch { }
71
328
  }
72
329
  this.#clients.clear();
73
330
  // Close server
74
331
  if (this.#server) {
332
+ const server = this.#server;
333
+ this.#server = null;
75
334
  await new Promise((resolve) => {
76
- this.#server.close(() => resolve());
335
+ // A peer that never closes its own half - a non-Node bridge, say - must not be
336
+ // able to wedge shutdown forever. Force the stragglers down after a grace
337
+ // period and carry on; the .sock/.lock cleanup below then runs either way.
338
+ const timer = setTimeout(() => {
339
+ for (const socket of this.#sockets) {
340
+ try {
341
+ socket.destroy();
342
+ }
343
+ catch { }
344
+ }
345
+ this.#sockets.clear();
346
+ resolve();
347
+ }, STOP_CLOSE_TIMEOUT_MS);
348
+ server.close(() => {
349
+ clearTimeout(timer);
350
+ resolve();
351
+ });
77
352
  });
353
+ }
354
+ this.#sockets.clear();
355
+ // Clean up socket and lock files — but only if this instance owns them. A
356
+ // server whose start() was refused with SocketSessionBusyError never claimed
357
+ // the lock; deleting these paths would destroy the LIVE owner's files and let
358
+ // a third process steal the session id.
359
+ if (this.#ownsLock) {
360
+ this.#ownsLock = false;
361
+ await rm(this.#socketPath, { force: true });
362
+ await rm(this.#lockPath, { force: true });
363
+ }
364
+ }
365
+ /**
366
+ * Stop the socket server from a synchronous exit path.
367
+ *
368
+ * `process.on("exit")` and signal handlers cannot await, so this does the same
369
+ * teardown as {@link stop} without yielding to the event loop.
370
+ */
371
+ stopSync() {
372
+ if (this.#stopped)
373
+ return;
374
+ this.#stopped = true;
375
+ for (const socket of this.#sockets) {
376
+ try {
377
+ socket.destroy();
378
+ }
379
+ catch { }
380
+ }
381
+ this.#sockets.clear();
382
+ this.#clients.clear();
383
+ if (this.#server) {
384
+ const server = this.#server;
78
385
  this.#server = null;
386
+ try {
387
+ server.close();
388
+ }
389
+ catch { }
390
+ }
391
+ // Only remove files this instance actually claimed — see stop().
392
+ if (this.#ownsLock) {
393
+ this.#ownsLock = false;
394
+ try {
395
+ rmSync(this.#socketPath, { force: true });
396
+ }
397
+ catch { }
398
+ try {
399
+ rmSync(this.#lockPath, { force: true });
400
+ }
401
+ catch { }
79
402
  }
80
- // Clean up socket and lock files
81
- await rm(this.#socketPath, { force: true });
82
- await rm(this.#lockPath, { force: true });
83
403
  }
84
404
  /**
85
405
  * Broadcast output to all connected clients.
@@ -95,28 +415,299 @@ export class SocketServer {
95
415
  };
96
416
  this.#broadcast(message);
97
417
  }
418
+ /**
419
+ * Broadcast an error to all connected clients.
420
+ */
421
+ broadcastError(message, code) {
422
+ const error = { type: "error", message, code };
423
+ this.#broadcast(error);
424
+ }
425
+ /**
426
+ * Send an error to one specific client, if it is still connected.
427
+ */
428
+ sendErrorToClient(clientId, message, code) {
429
+ const client = this.#clients.get(clientId);
430
+ if (!client)
431
+ return;
432
+ this.#sendError(client.socket, message, code);
433
+ }
434
+ /**
435
+ * Send a permission ask to one client, if it is still connected and may have it.
436
+ *
437
+ * Silently does nothing for a client that is gone, read-only, or never
438
+ * declared {@link PERMISSION_RELAY_CAPABILITY}: not being asked is the
439
+ * correct outcome for all three, and none of them is an error the asker can
440
+ * act on.
441
+ */
442
+ sendPermissionRequest(clientId, message) {
443
+ const client = this.#clients.get(clientId);
444
+ if (!client || !this.#mayReceivePermissionFrames(client))
445
+ return;
446
+ this.#send(client.socket, message);
447
+ }
448
+ /**
449
+ * Broadcast a permission ask to every client that may answer it.
450
+ *
451
+ * @returns the ids that were actually sent the ask — the asker needs to know
452
+ * whether anybody at all can answer, and an empty result is the
453
+ * honest answer "nobody remote is listening".
454
+ */
455
+ broadcastPermissionRequest(message) {
456
+ const reached = [];
457
+ for (const client of this.#clients.values()) {
458
+ if (!this.#mayReceivePermissionFrames(client))
459
+ continue;
460
+ this.#send(client.socket, message);
461
+ reached.push(client.id);
462
+ }
463
+ return reached;
464
+ }
465
+ /**
466
+ * Broadcast the outcome of a permission ask.
467
+ *
468
+ * Gated exactly like the ask itself: a client that could not have been asked
469
+ * is not told how somebody else's ask ended, and a client that never declared
470
+ * the capability is never sent a frame it cannot decode.
471
+ */
472
+ broadcastPermissionResolved(message) {
473
+ for (const client of this.#clients.values()) {
474
+ if (!this.#mayReceivePermissionFrames(client))
475
+ continue;
476
+ this.#send(client.socket, message);
477
+ }
478
+ }
479
+ /**
480
+ * How many attached clients could answer a permission ask RIGHT NOW.
481
+ *
482
+ * Gated by exactly the predicate emission is gated by, so the count and the
483
+ * fan-out can never disagree. This is what `ExtensionRunner.hasUI()` becomes
484
+ * for a headless attachable session, and it must therefore stay honest in
485
+ * both directions: reporting a client that cannot be asked turns today's loud
486
+ * "no UI available to request approval" block into an instant `false` that
487
+ * the permission gate reports as "User denied approval" — a user action in
488
+ * the transcript that no user took.
489
+ */
490
+ get permissionCapableClientCount() {
491
+ let count = 0;
492
+ for (const client of this.#clients.values()) {
493
+ if (this.#mayReceivePermissionFrames(client))
494
+ count++;
495
+ }
496
+ return count;
497
+ }
498
+ /**
499
+ * Whether this client is eligible for permission frames at all: read-write
500
+ * (a read-only peer may watch but never decide) and capability-declaring.
501
+ */
502
+ #mayReceivePermissionFrames(client) {
503
+ return client.mode !== "read-only" && client.capabilities.includes(PERMISSION_RELAY_CAPABILITY);
504
+ }
98
505
  /**
99
506
  * Set callback for input received from clients.
100
507
  */
101
508
  onInput(callback) {
102
509
  this.#onInput = callback;
103
510
  }
511
+ /**
512
+ * Set callback for a permission answer received from a client.
513
+ */
514
+ onPermissionResponse(callback) {
515
+ this.#onPermissionResponse = callback;
516
+ }
517
+ /**
518
+ * Set callback fired right after a client has been sent `session_metadata`,
519
+ * for the clients that could actually be sent a permission frame.
520
+ *
521
+ * See the attach case for the gate and for what does — and does not —
522
+ * authenticate the peer being replayed to.
523
+ */
524
+ onAttachReplay(callback) {
525
+ this.#onAttachReplay = callback;
526
+ }
527
+ /**
528
+ * Set callback fired when an attached client's connection ends, however it
529
+ * ended — a graceful `detach`, a closed socket, or a socket error.
530
+ *
531
+ * Per-connection bookkeeping outside this class needs the same signal the
532
+ * `client_left` broadcast carries, and it needs it for the same reason: a
533
+ * client that reconnects under the same id is a NEW connection with nothing
534
+ * on its screen. Whatever tracked what that client had already been shown has
535
+ * to forget it here, or the reconnecting peer is never shown it again.
536
+ */
537
+ onClientDisconnect(callback) {
538
+ this.#onClientDisconnect = callback;
539
+ }
104
540
  /**
105
541
  * Get socket path for this session.
106
542
  */
107
543
  get socketPath() {
108
544
  return this.#socketPath;
109
545
  }
546
+ /**
547
+ * Get the session id this socket is bound to.
548
+ */
549
+ get sessionId() {
550
+ return this.#sessionId;
551
+ }
110
552
  /**
111
553
  * Get number of connected clients.
112
554
  */
113
555
  get clientCount() {
114
556
  return this.#clients.size;
115
557
  }
558
+ /**
559
+ * Assert the sockets directory is a real directory, owned by this user, with no
560
+ * group or other permission bits (R35-ALWAYS.3).
561
+ *
562
+ * `lstat`, not `stat`: a symlink pointing at a directory somebody else controls
563
+ * would otherwise pass every check that follows.
564
+ *
565
+ * The one thing this does silently is re-tighten a loose mode on a directory that
566
+ * IS ours — that is not a trust decision, it is the same `chmod` this method has
567
+ * always done, and refusing there would strand every user whose directory predates
568
+ * the mode being enforced. A directory owned by somebody else is refused outright:
569
+ * `chmod`ing it would either fail with EPERM or succeed on a directory planted for
570
+ * us to publish into.
571
+ *
572
+ * Off POSIX there are no uids and file modes do not mean this; the assertion is
573
+ * skipped rather than faked.
574
+ */
575
+ async #assertSocketDirIsOurs(socketDir) {
576
+ const uid = currentUid();
577
+ if (uid === null)
578
+ return;
579
+ let info = await lstat(socketDir).catch((error) => {
580
+ throw new SocketDirectoryUnsafeError(socketDir, `it cannot be inspected (${error?.code ?? "unknown"})`);
581
+ });
582
+ if (!info.isDirectory()) {
583
+ throw new SocketDirectoryUnsafeError(socketDir, "it is not a directory (a symlink is not one either)");
584
+ }
585
+ if (info.uid !== uid) {
586
+ throw new SocketDirectoryUnsafeError(socketDir, `it belongs to uid ${info.uid}, not to uid ${uid}`);
587
+ }
588
+ if ((info.mode & 0o077) !== 0) {
589
+ await chmod(socketDir, 0o700).catch(() => { });
590
+ info = await lstat(socketDir).catch(() => info);
591
+ if ((info.mode & 0o077) !== 0) {
592
+ throw new SocketDirectoryUnsafeError(socketDir, `it is readable or writable by other users (mode ${(info.mode & 0o777).toString(8)})`);
593
+ }
594
+ }
595
+ }
596
+ /**
597
+ * Claim the session lock, or refuse when a live process already holds it.
598
+ *
599
+ * The lock file is created exclusively so two processes racing for the same session id
600
+ * cannot both believe they won. An existing lock is only reaped when its PID is dead
601
+ * (or is our own leftover, e.g. re-binding after a session switch). A lock that exists
602
+ * but names no readable PID counts as held, not as dead: the exclusive create and the
603
+ * PID write are two steps, and reaping in between would steal a live owner's session.
604
+ */
605
+ async #claimLock() {
606
+ // Four lines. The first three are the published contract (pid, cwd, ISO creation
607
+ // time) and both readers still accept exactly three, so locks written by older
608
+ // builds — and the ones already on disk — keep parsing. The 4th is the OWNING
609
+ // PROCESS's start time in epoch milliseconds, which is what lets a reader retire a
610
+ // lock whose pid was recycled by a reboot instead of letting it poison the session
611
+ // id forever. See `lockIsPreBootDebris` in discovery.ts for why that comparison,
612
+ // and not a blanket age bound on readable-pid locks.
613
+ const processStartedAtMs = Math.round(Date.now() - process.uptime() * 1000);
614
+ const contents = `${process.pid}\n${this.#cwd}\n${this.#createdAt.toISOString()}\n${processStartedAtMs}`;
615
+ for (let attempt = 0; attempt < 2; attempt++) {
616
+ try {
617
+ await writeFile(this.#lockPath, contents, { flag: "wx", mode: 0o600 });
618
+ // A leftover socket from a dead owner cannot be connected to; remove it so
619
+ // listen() can bind the path.
620
+ await rm(this.#socketPath, { force: true });
621
+ this.#ownsLock = true;
622
+ return;
623
+ }
624
+ catch (error) {
625
+ if (error?.code !== "EEXIST")
626
+ throw error;
627
+ }
628
+ // A lock file that is not ours is not a claim on our session id. It can only
629
+ // exist here because somebody with more privilege wrote it into a directory
630
+ // start() has already asserted is ours and 0700, so it is debris — and treating
631
+ // it as a live owner is exactly how a session id gets refused forever.
632
+ const foreignLock = await this.#lockIsForeign();
633
+ const ownerPid = foreignLock ? null : await this.#readLockPid();
634
+ if (!foreignLock) {
635
+ if (ownerPid === null) {
636
+ // The lock exists but names no readable PID. The likely cause is a starter that
637
+ // won the exclusive create microseconds ago and has not written its PID yet;
638
+ // reaping it here would hand the same session id to two live processes. Only a
639
+ // lock that has sat unwritten far longer than any write takes counts as debris.
640
+ if (!(await this.#lockIsAbandoned())) {
641
+ throw new SocketSessionBusyError(this.#sessionId, null, this.#socketPath);
642
+ }
643
+ }
644
+ else if (ownerPid !== process.pid && pidOwnership(ownerPid) === "ours") {
645
+ // "ours" and not "alive": a pid we cannot signal is alive but belongs to
646
+ // another user, so it cannot be a draht of ours holding this id — the file is
647
+ // ours and only this uid could have written it. Reading EPERM as a live owner
648
+ // is what made a lock naming root's pid 1 refuse a session id forever,
649
+ // regardless of age. EPERM still means the PROCESS is alive (discovery never
650
+ // reaps another user's session); it just stops meaning the LOCK is live.
651
+ throw new SocketSessionBusyError(this.#sessionId, ownerPid, this.#socketPath);
652
+ }
653
+ }
654
+ // Dead owner, our own leftover, or abandoned debris: reap and retry the create.
655
+ await rm(this.#lockPath, { force: true });
656
+ await rm(this.#socketPath, { force: true });
657
+ }
658
+ throw new Error(`Could not claim the attachable-session lock at ${this.#lockPath}`);
659
+ }
660
+ /**
661
+ * Whether an existing lock with no readable PID is old enough to count as debris
662
+ * rather than as a claim another process is in the middle of writing.
663
+ */
664
+ async #lockIsAbandoned() {
665
+ try {
666
+ const info = await stat(this.#lockPath);
667
+ return Date.now() - info.mtimeMs > UNWRITTEN_LOCK_STALE_MS;
668
+ }
669
+ catch {
670
+ // It vanished while we looked at it: the session id is free again.
671
+ return true;
672
+ }
673
+ }
674
+ /**
675
+ * Whether an existing lock file belongs to another uid, or is not a plain file.
676
+ *
677
+ * Either way it is not a claim this process may honour: see {@link #claimLock}.
678
+ * Off POSIX, where there are no uids, nothing is foreign.
679
+ */
680
+ async #lockIsForeign() {
681
+ const uid = currentUid();
682
+ try {
683
+ const info = await lstat(this.#lockPath);
684
+ if (!info.isFile())
685
+ return true;
686
+ return uid !== null && info.uid !== uid;
687
+ }
688
+ catch {
689
+ // It vanished while we looked at it; the retry re-creates it.
690
+ return false;
691
+ }
692
+ }
693
+ /**
694
+ * Read the PID recorded in an existing lock file, or null when it is unreadable.
695
+ */
696
+ async #readLockPid() {
697
+ try {
698
+ const contents = await readFile(this.#lockPath, "utf-8");
699
+ const pid = Number.parseInt(contents.trim().split("\n")[0], 10);
700
+ return Number.isInteger(pid) ? pid : null;
701
+ }
702
+ catch {
703
+ return null;
704
+ }
705
+ }
116
706
  /**
117
707
  * Handle new client connection.
118
708
  */
119
709
  #handleConnection(socket) {
710
+ this.#sockets.add(socket);
120
711
  let clientId = null;
121
712
  let _mode = "read-write";
122
713
  let buffer = "";
@@ -142,6 +733,7 @@ export class SocketServer {
142
733
  });
143
734
  // Handle client disconnect
144
735
  socket.on("close", () => {
736
+ this.#sockets.delete(socket);
145
737
  if (clientId) {
146
738
  this.#handleClientDisconnect(clientId);
147
739
  }
@@ -161,12 +753,42 @@ export class SocketServer {
161
753
  // Check max clients
162
754
  if (this.#clients.size >= this.#maxClients) {
163
755
  this.#sendError(socket, "Maximum clients reached");
756
+ soakRecord(SOAK_EVENTS.CLIENT_REJECTED, {
757
+ reason: "max_clients",
758
+ sessionId: this.#sessionId,
759
+ clientId: soakLabel(message.clientId),
760
+ maxClients: this.#maxClients,
761
+ clientCount: this.#clients.size,
762
+ }, "warn");
763
+ socket.end();
764
+ return;
765
+ }
766
+ // The mode decides whether this peer's keystrokes reach the session, so
767
+ // it is validated against the closed set rather than tested for one
768
+ // value. A negative `=== "read-only"` check would let `mode: "banana"`
769
+ // attach with full write access on the strength of not being the one
770
+ // string that is refused.
771
+ if (!CLIENT_MODES.includes(message.mode)) {
772
+ this.#sendError(socket, `Unknown client mode ${JSON.stringify(message.mode)}`, "UNKNOWN_CLIENT_MODE");
773
+ soakRecord(SOAK_EVENTS.CLIENT_REJECTED, {
774
+ reason: "unknown_client_mode",
775
+ sessionId: this.#sessionId,
776
+ clientId: soakLabel(message.clientId),
777
+ code: "UNKNOWN_CLIENT_MODE",
778
+ mode: soakLabel(message.mode),
779
+ }, "warn");
164
780
  socket.end();
165
781
  return;
166
782
  }
167
783
  // Check for duplicate client ID
168
784
  if (this.#clients.has(message.clientId)) {
169
785
  this.#sendError(socket, "Client ID already connected");
786
+ soakRecord(SOAK_EVENTS.CLIENT_REJECTED, {
787
+ reason: "duplicate_client_id",
788
+ sessionId: this.#sessionId,
789
+ clientId: soakLabel(message.clientId),
790
+ clientCount: this.#clients.size,
791
+ }, "warn");
170
792
  socket.end();
171
793
  return;
172
794
  }
@@ -176,9 +798,27 @@ export class SocketServer {
176
798
  mode: message.mode,
177
799
  socket,
178
800
  connectedAt: new Date(),
801
+ // Only strings, and only what was actually declared. An absent
802
+ // `capabilities` is an older client, which is exactly the case the
803
+ // gating exists for.
804
+ capabilities: Array.isArray(message.capabilities)
805
+ ? message.capabilities.filter((entry) => typeof entry === "string")
806
+ : [],
179
807
  };
180
808
  this.#clients.set(message.clientId, client);
181
809
  onAttach(message.clientId, message.mode);
810
+ // THE `client_attach` SEAM (R35-ALWAYS.11). Here, and not at the
811
+ // `onAttachReplay` hook one layer up, because this line is reached by EVERY
812
+ // client while that hook is gated on the permission capability — see the note
813
+ // at that callback in `session-integration.ts`. Recorded before the metadata
814
+ // goes out, so an attach that dies mid-write is still counted.
815
+ soakRecord(SOAK_EVENTS.CLIENT_ATTACH, {
816
+ clientId: soakLabel(message.clientId),
817
+ sessionId: this.#sessionId,
818
+ mode: soakLabel(message.mode),
819
+ capabilities: client.capabilities.map(soakLabel),
820
+ clientCount: this.#clients.size,
821
+ });
182
822
  // Send session metadata
183
823
  const metadata = {
184
824
  type: "session_metadata",
@@ -187,6 +827,31 @@ export class SocketServer {
187
827
  createdAt: this.#createdAt.toISOString(),
188
828
  };
189
829
  this.#send(socket, metadata);
830
+ // ── replay (R34-PERM.6) ───────────────────────────────────────────────
831
+ //
832
+ // Whatever holds unanswered asks gets its chance now: the client is
833
+ // registered and has its metadata, so a replayed ask lands on a surface
834
+ // that already knows which session it is looking at. This fires on EVERY
835
+ // attach, including a reattach under a clientId this server has seen
836
+ // before — a reconnecting peer is a new connection with nothing on its
837
+ // screen, and it may be a whole new process.
838
+ //
839
+ // Gated by exactly the predicate emission is gated by, so a client that
840
+ // could not have been sent an ask is not offered a backlog of them
841
+ // either: a read-only peer may watch but never decide, and a client that
842
+ // never declared PERMISSION_RELAY_CAPABILITY cannot render the dialog.
843
+ //
844
+ // WHAT AUTHENTICATES THE CLIENT BEING REPLAYED TO, stated rather than
845
+ // invented: on this socket, nothing beyond the filesystem. The socket dir
846
+ // is 0700 and the socket itself 0600 (see start()), so reaching this line
847
+ // already means the peer runs as this user; `clientId` is SELF-ASSERTED
848
+ // and is an addressing label, not a credential. The device credential
849
+ // lives one hop up, at the gateway's `/attach`. A replay therefore hands
850
+ // a local peer nothing it could not have had by attaching a moment
851
+ // earlier and receiving the same ask in the ordinary broadcast.
852
+ if (this.#mayReceivePermissionFrames(client)) {
853
+ this.#onAttachReplay?.(message.clientId);
854
+ }
190
855
  // Notify other clients
191
856
  const joined = {
192
857
  type: "client_joined",
@@ -223,16 +888,111 @@ export class SocketServer {
223
888
  socket.end();
224
889
  break;
225
890
  }
891
+ case "permission_response": {
892
+ const client = this.#clients.get(message.clientId);
893
+ if (!client || client.socket !== socket) {
894
+ // Either nobody attached under this id, or somebody else did. Both are
895
+ // "you are not that client", said the same way so neither answer is an
896
+ // oracle for which.
897
+ this.#sendError(socket, "Unknown client", "PERMISSION_NOT_ATTACHED");
898
+ this.#recordPermissionRefusal("permission_not_attached", "PERMISSION_NOT_ATTACHED", message);
899
+ return;
900
+ }
901
+ if (client.mode === "read-only") {
902
+ this.#sendError(socket, "Read-only clients cannot answer permissions", "PERMISSION_READ_ONLY");
903
+ this.#recordPermissionRefusal("permission_read_only", "PERMISSION_READ_ONLY", message);
904
+ return;
905
+ }
906
+ if (!client.capabilities.includes(PERMISSION_RELAY_CAPABILITY)) {
907
+ // It was never sent an ask, so it cannot be answering one it saw.
908
+ this.#sendError(socket, `Client did not declare the ${PERMISSION_RELAY_CAPABILITY} capability on attach`, "PERMISSION_NOT_CAPABLE");
909
+ this.#recordPermissionRefusal("permission_not_capable", "PERMISSION_NOT_CAPABLE", message);
910
+ return;
911
+ }
912
+ if (!this.#onPermissionResponse) {
913
+ // Nothing in this process is holding permission asks. Saying so is the
914
+ // point: silence here is indistinguishable from "accepted", and a phone
915
+ // would sit forever on a dialog nobody is going to resolve.
916
+ this.#sendError(socket, `No permission ask ${JSON.stringify(message.requestId)} is pending`, "PERMISSION_UNKNOWN_REQUEST");
917
+ this.#recordPermissionRefusal("permission_unknown_request", "PERMISSION_UNKNOWN_REQUEST", message);
918
+ return;
919
+ }
920
+ this.#onPermissionResponse(message, message.clientId);
921
+ break;
922
+ }
923
+ default: {
924
+ // A client message type this build does not know. Answering is what makes
925
+ // version skew visible in the client→server direction: without this case
926
+ // an unknown frame vanished with no reply at all, so a newer renderer
927
+ // could not tell a draht that had handled its frame from one that had
928
+ // never heard of it.
929
+ const unknown = message.type;
930
+ this.#sendError(socket, `Unknown message type ${JSON.stringify(unknown)}`, "UNKNOWN_MESSAGE_TYPE");
931
+ // Version skew, counted. A week of these from one peer is a renderer that
932
+ // needs upgrading, not a session that is misbehaving.
933
+ soakRecord(SOAK_EVENTS.CLIENT_REJECTED, {
934
+ reason: "unknown_message_type",
935
+ sessionId: this.#sessionId,
936
+ code: "UNKNOWN_MESSAGE_TYPE",
937
+ messageType: soakLabel(unknown),
938
+ }, "warn");
939
+ break;
940
+ }
226
941
  }
227
942
  }
943
+ /**
944
+ * A permission ANSWER that was refused before anything could decide anything.
945
+ *
946
+ * These are the records that carry a `requestId`, which is what lets a verdict
947
+ * join this stream against the durable `permission_resolution` rows the session
948
+ * writes: an ask that has a refused answer here and no resolution there is a
949
+ * decision that never reached the agent. Nothing about the decision itself is
950
+ * duplicated into this log — the session store owns that.
951
+ */
952
+ #recordPermissionRefusal(reason, code, message) {
953
+ soakRecord(SOAK_EVENTS.CLIENT_REJECTED, {
954
+ reason,
955
+ code,
956
+ sessionId: this.#sessionId,
957
+ clientId: soakLabel(message.clientId),
958
+ requestId: soakLabel(message.requestId),
959
+ }, "warn");
960
+ }
228
961
  /**
229
962
  * Handle client disconnect.
963
+ *
964
+ * R34-PERM.6 — DO NOT MAKE THIS TOUCH A PENDING PERMISSION ASK. It removes a
965
+ * CONNECTION and resets what that connection had been shown; it must never
966
+ * drop, resolve, expire or cancel a registry entry. A client that was shown
967
+ * an ask and then died would otherwise take the ask with it: the agent stays
968
+ * parked in `beforeToolCall` forever with no surface left that can answer,
969
+ * which is the wedge documented at `modes/rpc/rpc-mode.ts`. The ask stays
970
+ * PENDING and is replayed to whoever attaches next, including this same
971
+ * client coming back under the same id.
972
+ *
973
+ * Tidying this up so that "leaving cleans up after itself" is exactly the
974
+ * regression this comment exists to stop.
230
975
  */
231
976
  #handleClientDisconnect(clientId) {
232
977
  const client = this.#clients.get(clientId);
233
978
  if (!client)
234
979
  return;
235
980
  this.#clients.delete(clientId);
981
+ // THE `client_detach` SEAM, symmetric with `client_attach` above: one record per
982
+ // connection that was ever registered, whatever ended it — a `detach` frame, a
983
+ // closed socket, or a peer that died. `#clients.get` guards re-entry, so a socket
984
+ // that both errors and closes is recorded once.
985
+ soakRecord(SOAK_EVENTS.CLIENT_DETACH, {
986
+ clientId: soakLabel(clientId),
987
+ sessionId: this.#sessionId,
988
+ mode: soakLabel(client.mode),
989
+ connectedMs: Date.now() - client.connectedAt.getTime(),
990
+ clientCount: this.#clients.size,
991
+ });
992
+ // Per-connection state ONLY — see the note above. Before the other clients
993
+ // are told, because a listener that keeps per-connection state has to have
994
+ // dropped it by the time anything observable about this session changes.
995
+ this.#onClientDisconnect?.(clientId);
236
996
  // Notify other clients
237
997
  const left = {
238
998
  type: "client_left",