@draht/coding-agent 2026.7.13 → 2026.9.5-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (614) hide show
  1. package/CHANGELOG.md +241 -0
  2. package/README.md +47 -2
  3. package/agents/debugger.md +12 -1
  4. package/agents/git-committer.md +1 -0
  5. package/agents/implementer.md +20 -0
  6. package/agents/investigator.md +75 -0
  7. package/agents/reviewer.md +7 -0
  8. package/agents/spec-reviewer.md +66 -0
  9. package/agents/verifier.md +4 -3
  10. package/bin/draht-tools.cjs +472 -41
  11. package/dist/agents/debugger.md +12 -1
  12. package/dist/agents/git-committer.md +1 -0
  13. package/dist/agents/implementer.md +20 -0
  14. package/dist/agents/investigator.md +75 -0
  15. package/dist/agents/reviewer.md +7 -0
  16. package/dist/agents/spec-reviewer.md +66 -0
  17. package/dist/agents/verifier.md +4 -3
  18. package/dist/bun/cli.js +2 -0
  19. package/dist/bun/cli.js.map +1 -1
  20. package/dist/cli/args.d.ts +10 -0
  21. package/dist/cli/args.d.ts.map +1 -1
  22. package/dist/cli/args.js +80 -3
  23. package/dist/cli/args.js.map +1 -1
  24. package/dist/cli/attach-mode.d.ts +61 -0
  25. package/dist/cli/attach-mode.d.ts.map +1 -1
  26. package/dist/cli/attach-mode.js +243 -5
  27. package/dist/cli/attach-mode.js.map +1 -1
  28. package/dist/cli/config-selector.js +1 -1
  29. package/dist/cli/config-selector.js.map +1 -1
  30. package/dist/cli/credential-print.d.ts +23 -0
  31. package/dist/cli/credential-print.d.ts.map +1 -0
  32. package/dist/cli/credential-print.js +117 -0
  33. package/dist/cli/credential-print.js.map +1 -0
  34. package/dist/cli/list-models.d.ts +2 -2
  35. package/dist/cli/list-models.d.ts.map +1 -1
  36. package/dist/cli/list-models.js +3 -3
  37. package/dist/cli/list-models.js.map +1 -1
  38. package/dist/cli/startup-ui.js +1 -1
  39. package/dist/cli/startup-ui.js.map +1 -1
  40. package/dist/config.d.ts +9 -0
  41. package/dist/config.d.ts.map +1 -1
  42. package/dist/config.js +31 -4
  43. package/dist/config.js.map +1 -1
  44. package/dist/core/agent-session-runtime.d.ts +17 -1
  45. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  46. package/dist/core/agent-session-runtime.js +90 -30
  47. package/dist/core/agent-session-runtime.js.map +1 -1
  48. package/dist/core/agent-session-services.d.ts +4 -7
  49. package/dist/core/agent-session-services.d.ts.map +1 -1
  50. package/dist/core/agent-session-services.js +24 -9
  51. package/dist/core/agent-session-services.js.map +1 -1
  52. package/dist/core/agent-session.d.ts +87 -27
  53. package/dist/core/agent-session.d.ts.map +1 -1
  54. package/dist/core/agent-session.js +337 -154
  55. package/dist/core/agent-session.js.map +1 -1
  56. package/dist/core/auth-storage.d.ts +20 -104
  57. package/dist/core/auth-storage.d.ts.map +1 -1
  58. package/dist/core/auth-storage.js +104 -260
  59. package/dist/core/auth-storage.js.map +1 -1
  60. package/dist/core/builtins/checkpoints.d.ts +20 -0
  61. package/dist/core/builtins/checkpoints.d.ts.map +1 -0
  62. package/dist/core/builtins/checkpoints.js +161 -0
  63. package/dist/core/builtins/checkpoints.js.map +1 -0
  64. package/dist/core/builtins/duet.d.ts +26 -0
  65. package/dist/core/builtins/duet.d.ts.map +1 -0
  66. package/dist/core/builtins/duet.js +660 -0
  67. package/dist/core/builtins/duet.js.map +1 -0
  68. package/dist/core/builtins/index.d.ts.map +1 -1
  69. package/dist/core/builtins/index.js +7 -1
  70. package/dist/core/builtins/index.js.map +1 -1
  71. package/dist/core/builtins/subagent.d.ts +24 -4
  72. package/dist/core/builtins/subagent.d.ts.map +1 -1
  73. package/dist/core/builtins/subagent.js +278 -35
  74. package/dist/core/builtins/subagent.js.map +1 -1
  75. package/dist/core/cache-stats.d.ts +2 -2
  76. package/dist/core/cache-stats.d.ts.map +1 -1
  77. package/dist/core/cache-stats.js +1 -1
  78. package/dist/core/cache-stats.js.map +1 -1
  79. package/dist/core/checkpoints/checkpoint-cli.d.ts +17 -0
  80. package/dist/core/checkpoints/checkpoint-cli.d.ts.map +1 -0
  81. package/dist/core/checkpoints/checkpoint-cli.js +78 -0
  82. package/dist/core/checkpoints/checkpoint-cli.js.map +1 -0
  83. package/dist/core/checkpoints/checkpoint-manager.d.ts +294 -0
  84. package/dist/core/checkpoints/checkpoint-manager.d.ts.map +1 -0
  85. package/dist/core/checkpoints/checkpoint-manager.js +865 -0
  86. package/dist/core/checkpoints/checkpoint-manager.js.map +1 -0
  87. package/dist/core/checkpoints/rewind.d.ts +141 -0
  88. package/dist/core/checkpoints/rewind.d.ts.map +1 -0
  89. package/dist/core/checkpoints/rewind.js +246 -0
  90. package/dist/core/checkpoints/rewind.js.map +1 -0
  91. package/dist/core/compaction/branch-summarization.d.ts +9 -3
  92. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  93. package/dist/core/compaction/branch-summarization.js +16 -14
  94. package/dist/core/compaction/branch-summarization.js.map +1 -1
  95. package/dist/core/compaction/compaction.d.ts +24 -3
  96. package/dist/core/compaction/compaction.d.ts.map +1 -1
  97. package/dist/core/compaction/compaction.js +96 -30
  98. package/dist/core/compaction/compaction.js.map +1 -1
  99. package/dist/core/compaction/utils.d.ts +1 -1
  100. package/dist/core/compaction/utils.d.ts.map +1 -1
  101. package/dist/core/compaction/utils.js +6 -17
  102. package/dist/core/compaction/utils.js.map +1 -1
  103. package/dist/core/context-windows.d.ts +7 -0
  104. package/dist/core/context-windows.d.ts.map +1 -0
  105. package/dist/core/context-windows.js +35 -0
  106. package/dist/core/context-windows.js.map +1 -0
  107. package/dist/core/extensions/index.d.ts +1 -1
  108. package/dist/core/extensions/index.d.ts.map +1 -1
  109. package/dist/core/extensions/index.js.map +1 -1
  110. package/dist/core/extensions/loader.d.ts.map +1 -1
  111. package/dist/core/extensions/loader.js +101 -23
  112. package/dist/core/extensions/loader.js.map +1 -1
  113. package/dist/core/extensions/runner.d.ts +19 -3
  114. package/dist/core/extensions/runner.d.ts.map +1 -1
  115. package/dist/core/extensions/runner.js +117 -2
  116. package/dist/core/extensions/runner.js.map +1 -1
  117. package/dist/core/extensions/types.d.ts +236 -9
  118. package/dist/core/extensions/types.d.ts.map +1 -1
  119. package/dist/core/extensions/types.js.map +1 -1
  120. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  121. package/dist/core/extensions/wrapper.js +22 -3
  122. package/dist/core/extensions/wrapper.js.map +1 -1
  123. package/dist/core/footer-data-provider.d.ts +10 -0
  124. package/dist/core/footer-data-provider.d.ts.map +1 -1
  125. package/dist/core/footer-data-provider.js +1 -1
  126. package/dist/core/footer-data-provider.js.map +1 -1
  127. package/dist/core/http-dispatcher.d.ts.map +1 -1
  128. package/dist/core/http-dispatcher.js +7 -0
  129. package/dist/core/http-dispatcher.js.map +1 -1
  130. package/dist/core/index.d.ts +1 -1
  131. package/dist/core/index.d.ts.map +1 -1
  132. package/dist/core/index.js.map +1 -1
  133. package/dist/core/keybindings.d.ts +18 -3
  134. package/dist/core/keybindings.d.ts.map +1 -1
  135. package/dist/core/keybindings.js +12 -3
  136. package/dist/core/keybindings.js.map +1 -1
  137. package/dist/core/model-config.d.ts +542 -0
  138. package/dist/core/model-config.d.ts.map +1 -0
  139. package/dist/core/model-config.js +247 -0
  140. package/dist/core/model-config.js.map +1 -0
  141. package/dist/core/model-registry.d.ts +19 -124
  142. package/dist/core/model-registry.d.ts.map +1 -1
  143. package/dist/core/model-registry.js +56 -727
  144. package/dist/core/model-registry.js.map +1 -1
  145. package/dist/core/model-resolver.d.ts +7 -6
  146. package/dist/core/model-resolver.d.ts.map +1 -1
  147. package/dist/core/model-resolver.js +74 -27
  148. package/dist/core/model-resolver.js.map +1 -1
  149. package/dist/core/model-runtime.d.ts +89 -0
  150. package/dist/core/model-runtime.d.ts.map +1 -0
  151. package/dist/core/model-runtime.js +451 -0
  152. package/dist/core/model-runtime.js.map +1 -0
  153. package/dist/core/models-store.d.ts +17 -0
  154. package/dist/core/models-store.d.ts.map +1 -0
  155. package/dist/core/models-store.js +46 -0
  156. package/dist/core/models-store.js.map +1 -0
  157. package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
  158. package/dist/core/multi-agent/permission-gate.js +4 -3
  159. package/dist/core/multi-agent/permission-gate.js.map +1 -1
  160. package/dist/core/multi-agent/worktree.d.ts +2 -0
  161. package/dist/core/multi-agent/worktree.d.ts.map +1 -1
  162. package/dist/core/multi-agent/worktree.js +2 -2
  163. package/dist/core/multi-agent/worktree.js.map +1 -1
  164. package/dist/core/package-manager.d.ts +7 -1
  165. package/dist/core/package-manager.d.ts.map +1 -1
  166. package/dist/core/package-manager.js +41 -45
  167. package/dist/core/package-manager.js.map +1 -1
  168. package/dist/core/permission-relay/index.d.ts +19 -0
  169. package/dist/core/permission-relay/index.d.ts.map +1 -0
  170. package/dist/core/permission-relay/index.js +49 -0
  171. package/dist/core/permission-relay/index.js.map +1 -0
  172. package/dist/core/permission-relay/relay-ui-context.d.ts +39 -0
  173. package/dist/core/permission-relay/relay-ui-context.d.ts.map +1 -0
  174. package/dist/core/permission-relay/relay-ui-context.js +788 -0
  175. package/dist/core/permission-relay/relay-ui-context.js.map +1 -0
  176. package/dist/core/permission-relay/types.d.ts +222 -0
  177. package/dist/core/permission-relay/types.d.ts.map +1 -0
  178. package/dist/core/permission-relay/types.js +15 -0
  179. package/dist/core/permission-relay/types.js.map +1 -0
  180. package/dist/core/pi-manifest.d.ts +14 -0
  181. package/dist/core/pi-manifest.d.ts.map +1 -0
  182. package/dist/core/pi-manifest.js +35 -0
  183. package/dist/core/pi-manifest.js.map +1 -0
  184. package/dist/core/project-trust.js +2 -2
  185. package/dist/core/project-trust.js.map +1 -1
  186. package/dist/core/prompt-templates.d.ts +1 -0
  187. package/dist/core/prompt-templates.d.ts.map +1 -1
  188. package/dist/core/prompt-templates.js +4 -4
  189. package/dist/core/prompt-templates.js.map +1 -1
  190. package/dist/core/provider-composer.d.ts +55 -0
  191. package/dist/core/provider-composer.d.ts.map +1 -0
  192. package/dist/core/provider-composer.js +375 -0
  193. package/dist/core/provider-composer.js.map +1 -0
  194. package/dist/core/radius.d.ts +2 -0
  195. package/dist/core/radius.d.ts.map +1 -0
  196. package/dist/core/radius.js +2 -0
  197. package/dist/core/radius.js.map +1 -0
  198. package/dist/core/remote-catalog-provider.d.ts +5 -0
  199. package/dist/core/remote-catalog-provider.d.ts.map +1 -0
  200. package/dist/core/remote-catalog-provider.js +115 -0
  201. package/dist/core/remote-catalog-provider.js.map +1 -0
  202. package/dist/core/resource-loader.d.ts +36 -0
  203. package/dist/core/resource-loader.d.ts.map +1 -1
  204. package/dist/core/resource-loader.js +159 -27
  205. package/dist/core/resource-loader.js.map +1 -1
  206. package/dist/core/runtime-credentials.d.ts +15 -0
  207. package/dist/core/runtime-credentials.d.ts.map +1 -0
  208. package/dist/core/runtime-credentials.js +35 -0
  209. package/dist/core/runtime-credentials.js.map +1 -0
  210. package/dist/core/sandbox/bash-operations.d.ts +149 -0
  211. package/dist/core/sandbox/bash-operations.d.ts.map +1 -0
  212. package/dist/core/sandbox/bash-operations.js +163 -0
  213. package/dist/core/sandbox/bash-operations.js.map +1 -0
  214. package/dist/core/sandbox/env.d.ts +83 -0
  215. package/dist/core/sandbox/env.d.ts.map +1 -0
  216. package/dist/core/sandbox/env.js +123 -0
  217. package/dist/core/sandbox/env.js.map +1 -0
  218. package/dist/core/sandbox/executor.d.ts +104 -0
  219. package/dist/core/sandbox/executor.d.ts.map +1 -0
  220. package/dist/core/sandbox/executor.js +92 -0
  221. package/dist/core/sandbox/executor.js.map +1 -0
  222. package/dist/core/sandbox/index.d.ts +36 -0
  223. package/dist/core/sandbox/index.d.ts.map +1 -0
  224. package/dist/core/sandbox/index.js +36 -0
  225. package/dist/core/sandbox/index.js.map +1 -0
  226. package/dist/core/sandbox/linux.d.ts +121 -0
  227. package/dist/core/sandbox/linux.d.ts.map +1 -0
  228. package/dist/core/sandbox/linux.js +260 -0
  229. package/dist/core/sandbox/linux.js.map +1 -0
  230. package/dist/core/sandbox/policy.d.ts +142 -0
  231. package/dist/core/sandbox/policy.d.ts.map +1 -0
  232. package/dist/core/sandbox/policy.js +297 -0
  233. package/dist/core/sandbox/policy.js.map +1 -0
  234. package/dist/core/sandbox/real-path.d.ts +112 -0
  235. package/dist/core/sandbox/real-path.d.ts.map +1 -0
  236. package/dist/core/sandbox/real-path.js +158 -0
  237. package/dist/core/sandbox/real-path.js.map +1 -0
  238. package/dist/core/sandbox/seatbelt-profile.d.ts +95 -0
  239. package/dist/core/sandbox/seatbelt-profile.d.ts.map +1 -0
  240. package/dist/core/sandbox/seatbelt-profile.js +239 -0
  241. package/dist/core/sandbox/seatbelt-profile.js.map +1 -0
  242. package/dist/core/sandbox/seatbelt.d.ts +95 -0
  243. package/dist/core/sandbox/seatbelt.d.ts.map +1 -0
  244. package/dist/core/sandbox/seatbelt.js +154 -0
  245. package/dist/core/sandbox/seatbelt.js.map +1 -0
  246. package/dist/core/sandbox/self-test.d.ts +109 -0
  247. package/dist/core/sandbox/self-test.d.ts.map +1 -0
  248. package/dist/core/sandbox/self-test.js +369 -0
  249. package/dist/core/sandbox/self-test.js.map +1 -0
  250. package/dist/core/sandbox/spawn.d.ts +33 -0
  251. package/dist/core/sandbox/spawn.d.ts.map +1 -0
  252. package/dist/core/sandbox/spawn.js +87 -0
  253. package/dist/core/sandbox/spawn.js.map +1 -0
  254. package/dist/core/sdk.d.ts +3 -6
  255. package/dist/core/sdk.d.ts.map +1 -1
  256. package/dist/core/sdk.js +25 -22
  257. package/dist/core/sdk.js.map +1 -1
  258. package/dist/core/session-manager.d.ts +74 -7
  259. package/dist/core/session-manager.d.ts.map +1 -1
  260. package/dist/core/session-manager.js +169 -34
  261. package/dist/core/session-manager.js.map +1 -1
  262. package/dist/core/settings-manager.d.ts +22 -1
  263. package/dist/core/settings-manager.d.ts.map +1 -1
  264. package/dist/core/settings-manager.js +36 -16
  265. package/dist/core/settings-manager.js.map +1 -1
  266. package/dist/core/skills.d.ts +3 -1
  267. package/dist/core/skills.d.ts.map +1 -1
  268. package/dist/core/skills.js +19 -6
  269. package/dist/core/skills.js.map +1 -1
  270. package/dist/core/slash-commands.d.ts.map +1 -1
  271. package/dist/core/slash-commands.js +1 -0
  272. package/dist/core/slash-commands.js.map +1 -1
  273. package/dist/core/soak/soak-log.d.ts +298 -0
  274. package/dist/core/soak/soak-log.d.ts.map +1 -0
  275. package/dist/core/soak/soak-log.js +660 -0
  276. package/dist/core/soak/soak-log.js.map +1 -0
  277. package/dist/core/soak/soak-reader.d.ts +60 -0
  278. package/dist/core/soak/soak-reader.d.ts.map +1 -0
  279. package/dist/core/soak/soak-reader.js +106 -0
  280. package/dist/core/soak/soak-reader.js.map +1 -0
  281. package/dist/core/socket-server/discovery.d.ts +78 -1
  282. package/dist/core/socket-server/discovery.d.ts.map +1 -1
  283. package/dist/core/socket-server/discovery.js +356 -37
  284. package/dist/core/socket-server/discovery.js.map +1 -1
  285. package/dist/core/socket-server/index.d.ts +10 -4
  286. package/dist/core/socket-server/index.d.ts.map +1 -1
  287. package/dist/core/socket-server/index.js +6 -3
  288. package/dist/core/socket-server/index.js.map +1 -1
  289. package/dist/core/socket-server/permission-delivery.d.ts +125 -0
  290. package/dist/core/socket-server/permission-delivery.d.ts.map +1 -0
  291. package/dist/core/socket-server/permission-delivery.js +152 -0
  292. package/dist/core/socket-server/permission-delivery.js.map +1 -0
  293. package/dist/core/socket-server/permission-registry.d.ts +301 -0
  294. package/dist/core/socket-server/permission-registry.d.ts.map +1 -0
  295. package/dist/core/socket-server/permission-registry.js +410 -0
  296. package/dist/core/socket-server/permission-registry.js.map +1 -0
  297. package/dist/core/socket-server/permission-relay.d.ts +81 -0
  298. package/dist/core/socket-server/permission-relay.d.ts.map +1 -0
  299. package/dist/core/socket-server/permission-relay.js +528 -0
  300. package/dist/core/socket-server/permission-relay.js.map +1 -0
  301. package/dist/core/socket-server/safe-text.d.ts +83 -0
  302. package/dist/core/socket-server/safe-text.d.ts.map +1 -0
  303. package/dist/core/socket-server/safe-text.js +277 -0
  304. package/dist/core/socket-server/safe-text.js.map +1 -0
  305. package/dist/core/socket-server/session-integration.d.ts +65 -2
  306. package/dist/core/socket-server/session-integration.d.ts.map +1 -1
  307. package/dist/core/socket-server/session-integration.js +434 -32
  308. package/dist/core/socket-server/session-integration.js.map +1 -1
  309. package/dist/core/socket-server/socket-client.d.ts +21 -2
  310. package/dist/core/socket-server/socket-client.d.ts.map +1 -1
  311. package/dist/core/socket-server/socket-client.js +52 -1
  312. package/dist/core/socket-server/socket-client.js.map +1 -1
  313. package/dist/core/socket-server/socket-server.d.ts +152 -1
  314. package/dist/core/socket-server/socket-server.d.ts.map +1 -1
  315. package/dist/core/socket-server/socket-server.js +775 -26
  316. package/dist/core/socket-server/socket-server.js.map +1 -1
  317. package/dist/core/socket-server/types.d.ts +106 -2
  318. package/dist/core/socket-server/types.d.ts.map +1 -1
  319. package/dist/core/socket-server/types.js +13 -1
  320. package/dist/core/socket-server/types.js.map +1 -1
  321. package/dist/core/system-prompt.d.ts.map +1 -1
  322. package/dist/core/system-prompt.js +10 -21
  323. package/dist/core/system-prompt.js.map +1 -1
  324. package/dist/core/tools/bash.d.ts +3 -1
  325. package/dist/core/tools/bash.d.ts.map +1 -1
  326. package/dist/core/tools/bash.js +39 -7
  327. package/dist/core/tools/bash.js.map +1 -1
  328. package/dist/core/tools/edit.d.ts.map +1 -1
  329. package/dist/core/tools/edit.js +17 -2
  330. package/dist/core/tools/edit.js.map +1 -1
  331. package/dist/core/tools/find.d.ts +3 -0
  332. package/dist/core/tools/find.d.ts.map +1 -1
  333. package/dist/core/tools/find.js +11 -18
  334. package/dist/core/tools/find.js.map +1 -1
  335. package/dist/core/tools/read.js +1 -1
  336. package/dist/core/tools/read.js.map +1 -1
  337. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  338. package/dist/core/tools/tool-definition-wrapper.js +3 -1
  339. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  340. package/dist/core/trust-manager.d.ts +6 -4
  341. package/dist/core/trust-manager.d.ts.map +1 -1
  342. package/dist/core/trust-manager.js +55 -21
  343. package/dist/core/trust-manager.js.map +1 -1
  344. package/dist/core/usage-totals.d.ts +19 -0
  345. package/dist/core/usage-totals.d.ts.map +1 -0
  346. package/dist/core/usage-totals.js +52 -0
  347. package/dist/core/usage-totals.js.map +1 -0
  348. package/dist/extensions/index.d.ts +3 -0
  349. package/dist/extensions/index.d.ts.map +1 -0
  350. package/dist/extensions/index.js +7 -0
  351. package/dist/extensions/index.js.map +1 -0
  352. package/dist/extensions/llama/client.d.ts +61 -0
  353. package/dist/extensions/llama/client.d.ts.map +1 -0
  354. package/dist/extensions/llama/client.js +300 -0
  355. package/dist/extensions/llama/client.js.map +1 -0
  356. package/dist/extensions/llama/huggingface.d.ts +23 -0
  357. package/dist/extensions/llama/huggingface.d.ts.map +1 -0
  358. package/dist/extensions/llama/huggingface.js +139 -0
  359. package/dist/extensions/llama/huggingface.js.map +1 -0
  360. package/dist/extensions/llama/index.d.ts +3 -0
  361. package/dist/extensions/llama/index.d.ts.map +1 -0
  362. package/dist/extensions/llama/index.js +208 -0
  363. package/dist/extensions/llama/index.js.map +1 -0
  364. package/dist/extensions/llama/provider.d.ts +10 -0
  365. package/dist/extensions/llama/provider.d.ts.map +1 -0
  366. package/dist/extensions/llama/provider.js +111 -0
  367. package/dist/extensions/llama/provider.js.map +1 -0
  368. package/dist/extensions/llama/ui.d.ts +42 -0
  369. package/dist/extensions/llama/ui.d.ts.map +1 -0
  370. package/dist/extensions/llama/ui.js +400 -0
  371. package/dist/extensions/llama/ui.js.map +1 -0
  372. package/dist/extensions/stub-provider/index.d.ts +9 -0
  373. package/dist/extensions/stub-provider/index.d.ts.map +1 -0
  374. package/dist/extensions/stub-provider/index.js +13 -0
  375. package/dist/extensions/stub-provider/index.js.map +1 -0
  376. package/dist/extensions/stub-provider/provider.d.ts +77 -0
  377. package/dist/extensions/stub-provider/provider.d.ts.map +1 -0
  378. package/dist/extensions/stub-provider/provider.js +193 -0
  379. package/dist/extensions/stub-provider/provider.js.map +1 -0
  380. package/dist/hooks/gsd/draht-quality-gate.js +3 -3
  381. package/dist/index.d.ts +4 -3
  382. package/dist/index.d.ts.map +1 -1
  383. package/dist/index.js +3 -3
  384. package/dist/index.js.map +1 -1
  385. package/dist/main.d.ts.map +1 -1
  386. package/dist/main.js +305 -61
  387. package/dist/main.js.map +1 -1
  388. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  389. package/dist/modes/interactive/components/assistant-message.js +22 -10
  390. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  391. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  392. package/dist/modes/interactive/components/config-selector.js +3 -2
  393. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  394. package/dist/modes/interactive/components/custom-editor.js +1 -1
  395. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  396. package/dist/modes/interactive/components/custom-message.d.ts +3 -1
  397. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  398. package/dist/modes/interactive/components/custom-message.js +9 -2
  399. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  400. package/dist/modes/interactive/components/extension-editor.d.ts +1 -2
  401. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  402. package/dist/modes/interactive/components/extension-editor.js +16 -46
  403. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  404. package/dist/modes/interactive/components/extension-selector.d.ts +49 -0
  405. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  406. package/dist/modes/interactive/components/extension-selector.js +202 -5
  407. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  408. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  409. package/dist/modes/interactive/components/footer.js +24 -23
  410. package/dist/modes/interactive/components/footer.js.map +1 -1
  411. package/dist/modes/interactive/components/login-dialog.d.ts +5 -5
  412. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  413. package/dist/modes/interactive/components/login-dialog.js +17 -8
  414. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  415. package/dist/modes/interactive/components/model-selector.d.ts +11 -4
  416. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  417. package/dist/modes/interactive/components/model-selector.js +74 -41
  418. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  419. package/dist/modes/interactive/components/oauth-selector.d.ts +4 -4
  420. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  421. package/dist/modes/interactive/components/oauth-selector.js +14 -25
  422. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  423. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  424. package/dist/modes/interactive/components/scoped-models-selector.js +22 -13
  425. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  426. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  427. package/dist/modes/interactive/components/session-selector.js +10 -2
  428. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  429. package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
  430. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  431. package/dist/modes/interactive/components/settings-selector.js +10 -0
  432. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  433. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  434. package/dist/modes/interactive/components/tool-execution.js +10 -1
  435. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  436. package/dist/modes/interactive/components/tree-selector.d.ts +25 -2
  437. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  438. package/dist/modes/interactive/components/tree-selector.js +68 -17
  439. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  440. package/dist/modes/interactive/external-editor.d.ts +12 -0
  441. package/dist/modes/interactive/external-editor.d.ts.map +1 -0
  442. package/dist/modes/interactive/external-editor.js +37 -0
  443. package/dist/modes/interactive/external-editor.js.map +1 -0
  444. package/dist/modes/interactive/interactive-mode.d.ts +107 -10
  445. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  446. package/dist/modes/interactive/interactive-mode.js +763 -285
  447. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  448. package/dist/modes/rpc/rpc-client.d.ts +4 -0
  449. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  450. package/dist/modes/rpc/rpc-client.js +7 -0
  451. package/dist/modes/rpc/rpc-client.js.map +1 -1
  452. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  453. package/dist/modes/rpc/rpc-mode.js +185 -9
  454. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  455. package/dist/modes/rpc/rpc-types.d.ts +79 -1
  456. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  457. package/dist/modes/rpc/rpc-types.js.map +1 -1
  458. package/dist/package-manager-cli.d.ts.map +1 -1
  459. package/dist/package-manager-cli.js +67 -5
  460. package/dist/package-manager-cli.js.map +1 -1
  461. package/dist/prompts/commands/atomic-commit.md +1 -12
  462. package/dist/prompts/commands/brainstorm.md +12 -15
  463. package/dist/prompts/commands/create-verification-skill.md +108 -0
  464. package/dist/prompts/commands/discuss-phase.md +3 -14
  465. package/dist/prompts/commands/execute-phase.md +3 -11
  466. package/dist/prompts/commands/fix.md +41 -18
  467. package/dist/prompts/commands/grill.md +66 -0
  468. package/dist/prompts/commands/init-project.md +5 -15
  469. package/dist/prompts/commands/map-codebase.md +1 -13
  470. package/dist/prompts/commands/new-project.md +5 -15
  471. package/dist/prompts/commands/next-milestone.md +1 -13
  472. package/dist/prompts/commands/orchestrate.md +1 -1
  473. package/dist/prompts/commands/pause-work.md +1 -13
  474. package/dist/prompts/commands/plan-phase.md +2 -11
  475. package/dist/prompts/commands/progress.md +0 -13
  476. package/dist/prompts/commands/quick.md +3 -11
  477. package/dist/prompts/commands/resolve-conflicts.md +71 -0
  478. package/dist/prompts/commands/resume-work.md +0 -13
  479. package/dist/prompts/commands/review.md +4 -13
  480. package/dist/prompts/commands/triage.md +159 -0
  481. package/dist/prompts/commands/verify-work.md +4 -14
  482. package/dist/prompts/commands/why.md +135 -0
  483. package/dist/skills/atomic-reasoning/SKILL.md +115 -0
  484. package/dist/skills/blast-radius/SKILL.md +55 -0
  485. package/dist/skills/epistemics/SKILL.md +99 -0
  486. package/dist/skills/hexagon-animation/SKILL.md +49 -0
  487. package/dist/skills/hexagon-animation/generate.mjs +81 -0
  488. package/dist/skills/hexagon-animation/template.html +361 -0
  489. package/dist/skills/typescript-discipline/SKILL.md +50 -0
  490. package/dist/skills/typescript-discipline/references/patterns.md +294 -0
  491. package/dist/skills/unslop/SKILL.md +101 -0
  492. package/dist/utils/canonical-path.d.ts +28 -0
  493. package/dist/utils/canonical-path.d.ts.map +1 -0
  494. package/dist/utils/canonical-path.js +90 -0
  495. package/dist/utils/canonical-path.js.map +1 -0
  496. package/dist/utils/child-process.d.ts +12 -1
  497. package/dist/utils/child-process.d.ts.map +1 -1
  498. package/dist/utils/child-process.js +25 -8
  499. package/dist/utils/child-process.js.map +1 -1
  500. package/dist/utils/clipboard-native.d.ts +1 -0
  501. package/dist/utils/clipboard-native.d.ts.map +1 -1
  502. package/dist/utils/clipboard-native.js.map +1 -1
  503. package/dist/utils/clipboard.d.ts +2 -0
  504. package/dist/utils/clipboard.d.ts.map +1 -1
  505. package/dist/utils/clipboard.js +53 -9
  506. package/dist/utils/clipboard.js.map +1 -1
  507. package/dist/utils/exif-orientation.d.ts.map +1 -1
  508. package/dist/utils/exif-orientation.js +2 -3
  509. package/dist/utils/exif-orientation.js.map +1 -1
  510. package/dist/utils/paths.d.ts +2 -7
  511. package/dist/utils/paths.d.ts.map +1 -1
  512. package/dist/utils/paths.js +13 -15
  513. package/dist/utils/paths.js.map +1 -1
  514. package/dist/utils/shell.d.ts.map +1 -1
  515. package/dist/utils/shell.js +6 -4
  516. package/dist/utils/shell.js.map +1 -1
  517. package/dist/utils/tools-manager.d.ts.map +1 -1
  518. package/dist/utils/tools-manager.js +3 -5
  519. package/dist/utils/tools-manager.js.map +1 -1
  520. package/dist/utils/version-check.d.ts.map +1 -1
  521. package/dist/utils/version-check.js +3 -1
  522. package/dist/utils/version-check.js.map +1 -1
  523. package/docs/attachable-sessions.md +79 -0
  524. package/docs/compaction.md +29 -24
  525. package/docs/containerization.md +23 -23
  526. package/docs/custom-provider.md +66 -32
  527. package/docs/development.md +9 -9
  528. package/docs/docs.json +6 -2
  529. package/docs/duet.md +42 -0
  530. package/docs/environment-variables.md +88 -0
  531. package/docs/extensions.md +278 -65
  532. package/docs/index.md +12 -10
  533. package/docs/json.md +12 -8
  534. package/docs/keybindings.md +8 -5
  535. package/docs/llama-cpp.md +99 -0
  536. package/docs/models.md +19 -8
  537. package/docs/packages.md +43 -42
  538. package/docs/prompt-templates.md +5 -4
  539. package/docs/providers.md +45 -11
  540. package/docs/quickstart.md +33 -33
  541. package/docs/rpc.md +190 -19
  542. package/docs/sdk.md +18 -15
  543. package/docs/security.md +18 -18
  544. package/docs/session-format.md +53 -15
  545. package/docs/sessions.md +17 -14
  546. package/docs/settings.md +26 -19
  547. package/docs/shell-aliases.md +2 -2
  548. package/docs/skills.md +12 -11
  549. package/docs/terminal-setup.md +12 -12
  550. package/docs/termux.md +6 -6
  551. package/docs/themes.md +11 -11
  552. package/docs/tmux.md +4 -4
  553. package/docs/tui.md +46 -31
  554. package/docs/usage.md +53 -63
  555. package/docs/windows.md +2 -2
  556. package/examples/extensions/custom-compaction.ts +4 -0
  557. package/examples/extensions/custom-provider-anthropic/index.ts +9 -3
  558. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  559. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  560. package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
  561. package/examples/extensions/gondolin/package.json +2 -2
  562. package/examples/extensions/handoff.ts +9 -1
  563. package/examples/extensions/kimi-deferred-tools.ts +61 -0
  564. package/examples/extensions/message-renderer.ts +2 -2
  565. package/examples/extensions/overlay-qa-tests.ts +3 -3
  566. package/examples/extensions/sandbox/package.json +1 -1
  567. package/examples/extensions/summarize.ts +3 -0
  568. package/examples/extensions/with-deps/package.json +1 -1
  569. package/examples/sdk/02-custom-model.ts +5 -8
  570. package/examples/sdk/09-api-keys-and-oauth.ts +15 -31
  571. package/examples/sdk/12-full-control.ts +9 -12
  572. package/hooks/gsd/draht-quality-gate.js +3 -3
  573. package/package.json +14 -11
  574. package/prompts/commands/atomic-commit.md +1 -12
  575. package/prompts/commands/brainstorm.md +12 -15
  576. package/prompts/commands/create-verification-skill.md +108 -0
  577. package/prompts/commands/discuss-phase.md +3 -14
  578. package/prompts/commands/execute-phase.md +3 -11
  579. package/prompts/commands/fix.md +41 -18
  580. package/prompts/commands/grill.md +66 -0
  581. package/prompts/commands/init-project.md +5 -15
  582. package/prompts/commands/map-codebase.md +1 -13
  583. package/prompts/commands/new-project.md +5 -15
  584. package/prompts/commands/next-milestone.md +1 -13
  585. package/prompts/commands/orchestrate.md +1 -1
  586. package/prompts/commands/pause-work.md +1 -13
  587. package/prompts/commands/plan-phase.md +2 -11
  588. package/prompts/commands/progress.md +0 -13
  589. package/prompts/commands/quick.md +3 -11
  590. package/prompts/commands/resolve-conflicts.md +71 -0
  591. package/prompts/commands/resume-work.md +0 -13
  592. package/prompts/commands/review.md +4 -13
  593. package/prompts/commands/triage.md +159 -0
  594. package/prompts/commands/verify-work.md +4 -14
  595. package/prompts/commands/why.md +135 -0
  596. package/skills/atomic-reasoning/SKILL.md +115 -0
  597. package/skills/blast-radius/SKILL.md +55 -0
  598. package/skills/epistemics/SKILL.md +99 -0
  599. package/skills/hexagon-animation/SKILL.md +49 -0
  600. package/skills/hexagon-animation/generate.mjs +81 -0
  601. package/skills/hexagon-animation/template.html +361 -0
  602. package/skills/typescript-discipline/SKILL.md +50 -0
  603. package/skills/typescript-discipline/references/patterns.md +294 -0
  604. package/skills/unslop/SKILL.md +101 -0
  605. package/dist/core/provider-display-names.d.ts +0 -2
  606. package/dist/core/provider-display-names.d.ts.map +0 -1
  607. package/dist/core/provider-display-names.js +0 -36
  608. package/dist/core/provider-display-names.js.map +0 -1
  609. package/dist/prompts/agents/build.md +0 -86
  610. package/dist/prompts/agents/plan.md +0 -79
  611. package/dist/prompts/agents/verify.md +0 -69
  612. package/prompts/agents/build.md +0 -86
  613. package/prompts/agents/plan.md +0 -79
  614. package/prompts/agents/verify.md +0 -69
@@ -1 +1 @@
1
- {"version":3,"file":"socket-server.js","sourceRoot":"","sources":["../../../src/core/socket-server/socket-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,YAAY,EAA4B,MAAM,UAAU,CAAC;AAClE,OAAO,IAAI,MAAM,WAAW,CAAC;AAgB7B;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IACf,UAAU,CAAS;IACnB,WAAW,CAAS;IACpB,SAAS,CAAS;IAClB,IAAI,CAAS;IACb,WAAW,CAAS;IACpB,mBAAmB,CAAU;IAEtC,OAAO,GAAkB,IAAI,CAAC;IAC9B,QAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC9C,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;IAExB,kDAAkD;IAClD,QAAQ,GAAsD,IAAI,CAAC;IAEnE,YAAY,OAA4B;QACvC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;QAC5C,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,IAAI,IAAI,CAAC;QAE9D,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,OAAO,CAAC,SAAS,OAAO,CAAC,CAAC;QAC7E,IAAI,CAAC,SAAS,GAA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ket server for attachable draht sessions\n *\n * Enables tmux-style multi-client attachment:\n * - Multiple readers/writers can connect simultaneously\n * - All clients see the same output\n * - Input from any client is echoed to all others\n * - Clients can join/leave without disrupting the session\n */\n\nimport { existsSync } from \"node:fs\";\nimport { mkdir, rm, writeFile } from \"node:fs/promises\";\nimport { createServer, type Server, type Socket } from \"node:net\";\nimport path from \"node:path\";\nimport type { ClientMessage, ClientMode, ConnectedClient, ServerMessage } from \"./types.js\";\n\nexport interface SocketServerOptions {\n\t/** Session ID (used for socket filename) */\n\tsessionId: string;\n\t/** Directory for socket files (default: ~/.draht/agent/sockets) */\n\tsocketDir: string;\n\t/** Current working directory (included in metadata) */\n\tcwd: string;\n\t/** Maximum number of concurrent clients */\n\tmaxClients?: number;\n\t/** Whether to echo input to all clients (tmux-style) */\n\tbroadcastInputEcho?: boolean;\n}\n\n/**\n * SocketServer manages a Unix domain socket for a single draht session.\n *\n * Clients connect, send input, and receive output in real-time.\n * All communication uses JSON-over-socket with newline framing.\n */\nexport class SocketServer {\n\treadonly #sessionId: string;\n\treadonly #socketPath: string;\n\treadonly #lockPath: string;\n\treadonly #cwd: string;\n\treadonly #maxClients: number;\n\treadonly #broadcastInputEcho: boolean;\n\n\t#server: Server | null = null;\n\t#clients = new Map<string, ConnectedClient>();\n\t#createdAt = new Date();\n\n\t/** Callback for input received from any client */\n\t#onInput: ((data: string, clientId: string) => void) | null = null;\n\n\tconstructor(options: SocketServerOptions) {\n\t\tthis.#sessionId = options.sessionId;\n\t\tthis.#cwd = options.cwd;\n\t\tthis.#maxClients = options.maxClients ?? 10;\n\t\tthis.#broadcastInputEcho = options.broadcastInputEcho ?? true;\n\n\t\tthis.#socketPath = path.join(options.socketDir, `${options.sessionId}.sock`);\n\t\tthis.#lockPath = path.join(options.socketDir, `${options.sessionId}.lock`);\n\t}\n\n\t/**\n\t * Start the socket server.\n\t * Creates socket directory, binds Unix socket, and starts listening.\n\t */\n\tasync start(): Promise<void> {\n\t\t// Ensure socket directory exists\n\t\tconst socketDir = path.dirname(this.#socketPath);\n\t\tawait mkdir(socketDir, { recursive: true, mode: 0o700 });\n\n\t\t// Clean up stale socket if it exists\n\t\tif (existsSync(this.#socketPath)) {\n\t\t\tawait rm(this.#socketPath, { force: true });\n\t\t}\n\n\t\t// Write PID lock file for cleanup on crash\n\t\tawait writeFile(this.#lockPath, `${process.pid}\\n${this.#cwd}\\n${this.#createdAt.toISOString()}`);\n\n\t\t// Create Unix domain socket server\n\t\tthis.#server = createServer((socket) => this.#handleConnection(socket));\n\n\t\t// Bind to socket path\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tthis.#server!.listen(this.#socketPath, () => resolve());\n\t\t\tthis.#server!.on(\"error\", reject);\n\t\t});\n\n\t\t// Set socket permissions (owner-only)\n\t\tawait import(\"node:fs/promises\").then((fs) => fs.chmod(this.#socketPath, 0o600));\n\t}\n\n\t/**\n\t * Stop the socket server and clean up.\n\t */\n\tasync stop(): Promise<void> {\n\t\t// Disconnect all clients\n\t\tfor (const client of this.#clients.values()) {\n\t\t\tclient.socket.end();\n\t\t}\n\t\tthis.#clients.clear();\n\n\t\t// Close server\n\t\tif (this.#server) {\n\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\tthis.#server!.close(() => resolve());\n\t\t\t});\n\t\t\tthis.#server = null;\n\t\t}\n\n\t\t// Clean up socket and lock files\n\t\tawait rm(this.#socketPath, { force: true });\n\t\tawait rm(this.#lockPath, { force: true });\n\t}\n\n\t/**\n\t * Broadcast output to all connected clients.\n\t *\n\t * @param data - Output text\n\t * @param stream - Output stream (stdout or stderr)\n\t */\n\tbroadcastOutput(data: string, stream: \"stdout\" | \"stderr\" = \"stdout\"): void {\n\t\tconst message: ServerMessage = {\n\t\t\ttype: \"output\",\n\t\t\tdata,\n\t\t\tstream,\n\t\t};\n\t\tthis.#broadcast(message);\n\t}\n\n\t/**\n\t * Set callback for input received from clients.\n\t */\n\tonInput(callback: (data: string, clientId: string) => void): void {\n\t\tthis.#onInput = callback;\n\t}\n\n\t/**\n\t * Get socket path for this session.\n\t */\n\tget socketPath(): string {\n\t\treturn this.#socketPath;\n\t}\n\n\t/**\n\t * Get number of connected clients.\n\t */\n\tget clientCount(): number {\n\t\treturn this.#clients.size;\n\t}\n\n\t/**\n\t * Handle new client connection.\n\t */\n\t#handleConnection(socket: Socket): void {\n\t\tlet clientId: string | null = null;\n\t\tlet _mode: ClientMode = \"read-write\";\n\t\tlet buffer = \"\";\n\n\t\t// Handle incoming data (JSON messages)\n\t\tsocket.on(\"data\", (data) => {\n\t\t\tbuffer += data.toString();\n\t\t\tconst lines = buffer.split(\"\\n\");\n\t\t\tbuffer = lines.pop() || \"\";\n\n\t\t\tfor (const line of lines) {\n\t\t\t\tif (!line.trim()) continue;\n\n\t\t\t\ttry {\n\t\t\t\t\tconst message = JSON.parse(line) as ClientMessage;\n\t\t\t\t\tthis.#handleClientMessage(message, socket, (id, m) => {\n\t\t\t\t\t\tclientId = id;\n\t\t\t\t\t\t_mode = m;\n\t\t\t\t\t});\n\t\t\t\t} catch (_err) {\n\t\t\t\t\tthis.#sendError(socket, \"Invalid JSON message\");\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Handle client disconnect\n\t\tsocket.on(\"close\", () => {\n\t\t\tif (clientId) {\n\t\t\t\tthis.#handleClientDisconnect(clientId);\n\t\t\t}\n\t\t});\n\n\t\tsocket.on(\"error\", () => {\n\t\t\tif (clientId) {\n\t\t\t\tthis.#handleClientDisconnect(clientId);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Handle a client message.\n\t */\n\t#handleClientMessage(\n\t\tmessage: ClientMessage,\n\t\tsocket: Socket,\n\t\tonAttach: (id: string, mode: ClientMode) => void,\n\t): void {\n\t\tswitch (message.type) {\n\t\t\tcase \"attach\": {\n\t\t\t\t// Check max clients\n\t\t\t\tif (this.#clients.size >= this.#maxClients) {\n\t\t\t\t\tthis.#sendError(socket, \"Maximum clients reached\");\n\t\t\t\t\tsocket.end();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Check for duplicate client ID\n\t\t\t\tif (this.#clients.has(message.clientId)) {\n\t\t\t\t\tthis.#sendError(socket, \"Client ID already connected\");\n\t\t\t\t\tsocket.end();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Register client\n\t\t\t\tconst client: ConnectedClient = {\n\t\t\t\t\tid: message.clientId,\n\t\t\t\t\tmode: message.mode,\n\t\t\t\t\tsocket,\n\t\t\t\t\tconnectedAt: new Date(),\n\t\t\t\t};\n\t\t\t\tthis.#clients.set(message.clientId, client);\n\t\t\t\tonAttach(message.clientId, message.mode);\n\n\t\t\t\t// Send session metadata\n\t\t\t\tconst metadata: ServerMessage = {\n\t\t\t\t\ttype: \"session_metadata\",\n\t\t\t\t\tsessionId: this.#sessionId,\n\t\t\t\t\tcwd: this.#cwd,\n\t\t\t\t\tcreatedAt: this.#createdAt.toISOString(),\n\t\t\t\t};\n\t\t\t\tthis.#send(socket, metadata);\n\n\t\t\t\t// Notify other clients\n\t\t\t\tconst joined: ServerMessage = {\n\t\t\t\t\ttype: \"client_joined\",\n\t\t\t\t\tclientId: message.clientId,\n\t\t\t\t\tmode: message.mode,\n\t\t\t\t};\n\t\t\t\tthis.#broadcast(joined, message.clientId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"input\": {\n\t\t\t\t// Check if client is in read-write mode\n\t\t\t\tconst client = this.#clients.get(message.clientId);\n\t\t\t\tif (!client || client.mode === \"read-only\") {\n\t\t\t\t\tthis.#sendError(socket, \"Read-only clients cannot send input\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Forward input to session\n\t\t\t\tif (this.#onInput) {\n\t\t\t\t\tthis.#onInput(message.data, message.clientId);\n\t\t\t\t}\n\n\t\t\t\t// Echo input to all other clients (tmux-style)\n\t\t\t\tif (this.#broadcastInputEcho) {\n\t\t\t\t\tconst echo: ServerMessage = {\n\t\t\t\t\t\ttype: \"input_echo\",\n\t\t\t\t\t\tdata: message.data,\n\t\t\t\t\t\tclientId: message.clientId,\n\t\t\t\t\t};\n\t\t\t\t\tthis.#broadcast(echo, message.clientId);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"detach\": {\n\t\t\t\tthis.#handleClientDisconnect(message.clientId);\n\t\t\t\tsocket.end();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Handle client disconnect.\n\t */\n\t#handleClientDisconnect(clientId: string): void {\n\t\tconst client = this.#clients.get(clientId);\n\t\tif (!client) return;\n\n\t\tthis.#clients.delete(clientId);\n\n\t\t// Notify other clients\n\t\tconst left: ServerMessage = {\n\t\t\ttype: \"client_left\",\n\t\t\tclientId,\n\t\t};\n\t\tthis.#broadcast(left);\n\t}\n\n\t/**\n\t * Broadcast a message to all clients (or all except one).\n\t */\n\t#broadcast(message: ServerMessage, excludeClientId?: string): void {\n\t\tconst json = `${JSON.stringify(message)}\\n`;\n\t\tfor (const client of this.#clients.values()) {\n\t\t\tif (client.id !== excludeClientId) {\n\t\t\t\tclient.socket.write(json);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Send a message to a specific socket.\n\t */\n\t#send(socket: Socket, message: ServerMessage): void {\n\t\tconst json = `${JSON.stringify(message)}\\n`;\n\t\tsocket.write(json);\n\t}\n\n\t/**\n\t * Send an error message to a specific socket.\n\t */\n\t#sendError(socket: Socket, message: string, code?: string): void {\n\t\tconst error: ServerMessage = {\n\t\t\ttype: \"error\",\n\t\t\tmessage,\n\t\t\tcode,\n\t\t};\n\t\tthis.#send(socket, error);\n\t}\n}\n"]}
1
+ {"version":3,"file":"socket-server.js","sourceRoot":"","sources":["../../../src/core/socket-server/socket-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAA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,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;YACtD,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;SAC/B,CAAC,CAAC;QAEH,2EAA2E;QAC3E,2EAA2E;QAC3E,yEAAyE;QACzE,IAAI,CAAC,mBAAmB,EAAE,CAAC,QAAQ,CAAC,CAAC;QAErC,uBAAuB;QACvB,MAAM,IAAI,GAAkB;YAC3B,IAAI,EAAE,aAAa;YACnB,QAAQ;SACR,CAAC;QACF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,OAAsB,EAAE,eAAwB;QAC1D,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;QAC5C,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC7C,IAAI,MAAM,CAAC,EAAE,KAAK,eAAe,EAAE,CAAC;gBACnC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;QACF,CAAC;IACF,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAc,EAAE,OAAsB;QAC3C,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;QAC5C,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,MAAc,EAAE,OAAe,EAAE,IAAa;QACxD,MAAM,KAAK,GAAkB;YAC5B,IAAI,EAAE,OAAO;YACb,OAAO;YACP,IAAI;SACJ,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;CACD","sourcesContent":["/**\n * SocketServer - Unix domain socket server for attachable draht sessions\n *\n * Enables tmux-style multi-client attachment:\n * - Multiple readers/writers can connect simultaneously\n * - All clients see the same output\n * - Input from any client is echoed to all others\n * - Clients can join/leave without disrupting the session\n */\n\nimport { rmSync } from \"node:fs\";\nimport { chmod, lstat, mkdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { createServer, type Server, type Socket } from \"node:net\";\nimport path from \"node:path\";\nimport { assertValidSessionId } from \"../session-manager.js\";\nimport { getSoakLog, SOAK_EVENTS, type SoakFields } from \"../soak/soak-log.js\";\nimport { currentUid, discoverSocketSessions, pidOwnership } from \"./discovery.js\";\nimport {\n\tCLIENT_MODES,\n\ttype ClientMessage,\n\ttype ClientMode,\n\ttype ConnectedClient,\n\tPERMISSION_RELAY_CAPABILITY,\n\ttype PermissionRequestMessage,\n\ttype PermissionResolvedMessage,\n\ttype PermissionResponseMessage,\n\ttype ServerMessage,\n} from \"./types.js\";\n\n/**\n * How long {@link SocketServer.stop} waits for peers to close their end before it\n * forces the remaining sockets down.\n */\nconst STOP_CLOSE_TIMEOUT_MS = 1000;\n\n/**\n * How long a lock file with no readable PID has to sit untouched before it counts as\n * debris rather than as a claim another starter is in the middle of writing.\n */\nconst UNWRITTEN_LOCK_STALE_MS = 10_000;\n\n/**\n * How many live attachable sockets one host may hold (R35-ALWAYS.4).\n *\n * There was no cap at all: 500 sockets bound in one process with zero refusals,\n * and `ulimit -n` on the development machine is 1048576, so the fd ceiling never\n * arrives to stop a crash-restart loop. 64 is far above real use — a heavy user\n * runs perhaps 10-20 concurrent sessions — and still low enough that a runaway is\n * caught while the machine is healthy. It is a per-host number, counted from the\n * sockets directory after the start-time sweep, not a per-process one: the point\n * is to bound what accumulates on disk, and a restart loop is a new process each\n * time.\n *\n * Overridable per server via {@link SocketServerOptions.maxLiveSockets}.\n */\nexport const DEFAULT_MAX_LIVE_SOCKETS = 64;\n\n/**\n * Longest client-supplied string this file will copy into the soak log.\n *\n * A `clientId` and a client `mode` arrive over the socket and are self-asserted.\n * They are recorded because a soak verdict has to be able to name which peer\n * churned — and bounded because the log is append-only for weeks and a peer must\n * not be able to make one line of it megabytes long.\n */\nconst SOAK_LABEL_MAX = 128;\n\n/**\n * One soak record, and nothing else: no stdout, no stderr, no throw. See the\n * three rules at the head of the same helper in `session-integration.ts`; the\n * helper is kept per-file rather than shared because the only places to share it\n * from are `soak-log.ts` (a finished file this task may not edit) or a fourth\n * module that would exist solely to hold six lines.\n *\n * `sessionId` is passed through as an ordinary field: the writer stamps its own\n * over it whenever it has one — which it does for every session process, set at\n * bind — and honours this one otherwise, so a `SocketServer` used outside a\n * session still records under the id it was refused for.\n */\nfunction soakRecord(event: string, fields: SoakFields, level: \"info\" | \"warn\" | \"error\" = \"info\"): void {\n\ttry {\n\t\tgetSoakLog().record(event, fields, level);\n\t} catch {\n\t\t// Deliberately empty, and deliberately not logged anywhere.\n\t}\n}\n\n/** A client-supplied value, made safe to put in a record: a bounded string, always. */\nfunction soakLabel(value: unknown): string {\n\tconst text = typeof value === \"string\" ? value : JSON.stringify(value);\n\treturn (text ?? String(value)).slice(0, SOAK_LABEL_MAX);\n}\n\nexport interface SocketServerOptions {\n\t/** Session ID (used for socket filename) */\n\tsessionId: string;\n\t/** Directory for socket files (default: ~/.draht/agent/sockets) */\n\tsocketDir: string;\n\t/** Current working directory (included in metadata) */\n\tcwd: string;\n\t/** Maximum number of concurrent clients */\n\tmaxClients?: number;\n\t/**\n\t * Maximum number of live attachable sockets this host may hold, counted after\n\t * the start-time sweep (default: {@link DEFAULT_MAX_LIVE_SOCKETS}).\n\t */\n\tmaxLiveSockets?: number;\n\t/** Whether to echo input to all clients (tmux-style) */\n\tbroadcastInputEcho?: boolean;\n}\n\n/**\n * Thrown when another live process already owns the socket for this session id.\n *\n * Taking the socket over would silently steal attachments from a running session,\n * so the second process refuses to bind instead.\n */\nexport class SocketSessionBusyError extends Error {\n\treadonly sessionId: string;\n\t/** PID of the owning process, or null when the lock exists but names no readable PID. */\n\treadonly ownerPid: number | null;\n\treadonly socketPath: string;\n\n\tconstructor(sessionId: string, ownerPid: number | null, socketPath: string) {\n\t\t// Two genuinely different situations - do not describe them the same way. A\n\t\t// readable PID means a live process really does own this session. An\n\t\t// unreadable lock usually means another process is claiming it right now, but\n\t\t// it is equally a lock left truncated by a process killed mid-claim, in which\n\t\t// case nothing is running and the claim clears itself shortly.\n\t\tsuper(\n\t\t\townerPid === null\n\t\t\t\t? `Session \"${sessionId}\" has an attachable lock that names no readable PID. ` +\n\t\t\t\t\t\t`Another process is probably claiming it right now; it can also be debris from a ` +\n\t\t\t\t\t\t`process killed mid-claim, in which case it clears itself within ` +\n\t\t\t\t\t\t`${Math.round(UNWRITTEN_LOCK_STALE_MS / 1000)}s. Retry shortly. Socket: ${socketPath}`\n\t\t\t\t: `Session \"${sessionId}\" is already attachable from a running process (PID ${ownerPid}). ` +\n\t\t\t\t\t\t`Attach to it instead, or stop that process. Socket: ${socketPath}`,\n\t\t);\n\t\tthis.name = \"SocketSessionBusyError\";\n\t\tthis.sessionId = sessionId;\n\t\tthis.ownerPid = ownerPid;\n\t\tthis.socketPath = socketPath;\n\t}\n}\n\n/**\n * Thrown when this host already holds as many live attachable sockets as it may.\n *\n * Names both the cap and the count that hit it, so an operator can tell a cap\n * from a bug without reading the source. Exported deliberately and by name: the\n * default-on start path branches on `error instanceof SocketCapReachedError` to\n * pick the one refusal message that must never be confused with a broken sockets\n * directory. A cap-hit is not a reason to refuse to START a session — that\n * decision belongs to the caller, and this class exists so the caller can make it.\n */\nexport class SocketCapReachedError extends Error {\n\treadonly sessionId: string;\n\t/** The cap that was enforced. */\n\treadonly cap: number;\n\t/** Live sockets counted, after debris was reaped. */\n\treadonly liveCount: number;\n\treadonly socketDir: string;\n\n\tconstructor(sessionId: string, cap: number, liveCount: number, socketDir: string) {\n\t\tsuper(\n\t\t\t`This machine already holds ${liveCount} live attachable sessions and the cap is ${cap}. ` +\n\t\t\t\t`Session \"${sessionId}\" was not registered. Stop a session you are no longer using, or raise ` +\n\t\t\t\t`the cap. Sockets: ${socketDir}`,\n\t\t);\n\t\tthis.name = \"SocketCapReachedError\";\n\t\tthis.sessionId = sessionId;\n\t\tthis.cap = cap;\n\t\tthis.liveCount = liveCount;\n\t\tthis.socketDir = socketDir;\n\t}\n}\n\n/**\n * Thrown when the sockets directory is not a directory this user owns privately.\n *\n * The 0700 mode was the ONLY same-owner protection that existed, and nothing\n * asserted it: there is not one `getuid()` call in the whole of coding-agent,\n * geist-core or the gateway. A world-writable directory holding a 0666 socket and\n * a lock naming root's pid 1 was listed as a live attachable session and would\n * have been dialled. Refusing is the point — silently `chmod`ing a directory this\n * process does not own would either fail with EPERM or, worse, succeed on a\n * directory somebody else planted.\n */\nexport class SocketDirectoryUnsafeError extends Error {\n\treadonly socketDir: string;\n\n\tconstructor(socketDir: string, reason: string) {\n\t\tsuper(`Refusing to publish an attachable session in ${socketDir}: ${reason}`);\n\t\tthis.name = \"SocketDirectoryUnsafeError\";\n\t\tthis.socketDir = socketDir;\n\t}\n}\n\n/**\n * SocketServer manages a Unix domain socket for a single draht session.\n *\n * Clients connect, send input, and receive output in real-time.\n * All communication uses JSON-over-socket with newline framing.\n */\nexport class SocketServer {\n\treadonly #sessionId: string;\n\treadonly #socketPath: string;\n\treadonly #lockPath: string;\n\treadonly #cwd: string;\n\treadonly #socketDir: string;\n\treadonly #maxClients: number;\n\treadonly #maxLiveSockets: number;\n\treadonly #broadcastInputEcho: boolean;\n\n\t#server: Server | null = null;\n\t#clients = new Map<string, ConnectedClient>();\n\t/**\n\t * Every accepted connection, including ones that never sent an `attach` frame.\n\t * `#clients` only holds attached peers, and shutdown has to reach the others too.\n\t */\n\t#sockets = new Set<Socket>();\n\t#createdAt = new Date();\n\t#stopped = false;\n\t/**\n\t * Whether THIS instance won the exclusive lock create. Only an owner may remove\n\t * the socket/lock files; an instance whose start() was refused must never delete\n\t * the live owner's files.\n\t */\n\t#ownsLock = false;\n\t#rejectListen: ((error: Error) => void) | null = null;\n\n\t/** Callback for input received from any client */\n\t#onInput: ((data: string, clientId: string) => void) | null = null;\n\n\t/**\n\t * Callback for a permission answer from a client. Nothing here decides\n\t * anything: this class is plumbing, and the pending-ask registry that owns\n\t * validation, first-answer-wins and expiry lives on the session side.\n\t *\n\t * With no callback registered, an answer is refused with a targeted\n\t * `PERMISSION_UNKNOWN_REQUEST` error rather than swallowed — a phone must be\n\t * able to tell \"answered\" from \"this draht is too old to have asked\".\n\t */\n\t#onPermissionResponse: ((message: PermissionResponseMessage, clientId: string) => void) | null = null;\n\n\t/**\n\t * Fired immediately after a newly attached client has been sent\n\t * `session_metadata`, so whatever holds unanswered asks can replay them to a\n\t * client that arrived after they were raised.\n\t */\n\t#onAttachReplay: ((clientId: string) => void) | null = null;\n\n\t/**\n\t * Fired when an attached client's connection ends. Everything that keeps\n\t * per-connection state outside this class resets it here.\n\t */\n\t#onClientDisconnect: ((clientId: string) => void) | null = null;\n\n\tconstructor(options: SocketServerOptions) {\n\t\t// The id becomes a path component of the .sock and .lock files, and it arrives here\n\t\t// straight from a session file on disk, so it is untrusted input. Reject anything\n\t\t// that is not a plain session id rather than trying to sanitize it.\n\t\tassertValidSessionId(options.sessionId);\n\t\tthis.#sessionId = options.sessionId;\n\t\tthis.#cwd = options.cwd;\n\t\tthis.#maxClients = options.maxClients ?? 10;\n\t\tthis.#maxLiveSockets = options.maxLiveSockets ?? DEFAULT_MAX_LIVE_SOCKETS;\n\t\tthis.#broadcastInputEcho = options.broadcastInputEcho ?? true;\n\n\t\tthis.#socketDir = options.socketDir;\n\t\tthis.#socketPath = path.join(options.socketDir, `${options.sessionId}.sock`);\n\t\tthis.#lockPath = path.join(options.socketDir, `${options.sessionId}.lock`);\n\t}\n\n\t/**\n\t * Start the socket server.\n\t * Creates socket directory, claims the session lock, binds the Unix socket, and listens.\n\t *\n\t * @throws {SocketSessionBusyError} When another live process already owns this session's socket.\n\t * @throws {SocketDirectoryUnsafeError} When the sockets directory is not a private directory of ours.\n\t * @throws {SocketCapReachedError} When this host already holds the maximum number of live sockets.\n\t */\n\tasync start(): Promise<void> {\n\t\t// Ensure socket directory exists and is owner-only. `mkdir` applies its mode only\n\t\t// when it creates the directory, and masks it with the umask, so re-assert it on\n\t\t// the path that created it.\n\t\tconst socketDir = path.dirname(this.#socketPath);\n\t\tconst created = await mkdir(socketDir, { recursive: true, mode: 0o700 });\n\t\tif (created !== undefined) await chmod(socketDir, 0o700);\n\n\t\t// Then assert it, every time, before anything is written into it.\n\t\tawait this.#assertSocketDirIsOurs(socketDir);\n\n\t\t// REAP ON START (R35-ALWAYS.4). Before this, start() touched only this session's\n\t\t// two paths and reaping happened ONLY inside discovery — so on a machine where no\n\t\t// phone and no daemon ever asks for the fleet, the directory grew without bound.\n\t\t// Measured: 25 start/SIGKILL cycles of the emitted binary left exactly 50 files,\n\t\t// strictly linear, zero reaped. A full sweep here is what makes \"N crash cycles\n\t\t// leave nothing behind\" true without a second process having to come along.\n\t\t//\n\t\t// Not sampled and not bounded: measured cost is 12-32 ms to scan 1000 live pairs\n\t\t// and 106 ms to reap 1000 dead ones, once per session start, against the cap\n\t\t// below. Sampling would trade a bounded, once-per-start cost for an unbounded\n\t\t// on-disk one.\n\t\tconst live = await discoverSocketSessions(socketDir);\n\n\t\t// THE CAP, counted after the sweep so debris can never be what refuses a session.\n\t\t// Our own id does not count against it: re-binding a session id we already hold\n\t\t// replaces one socket, it does not add one.\n\t\tconst others = live.filter((session) => session.sessionId !== this.#sessionId).length;\n\t\tif (others >= this.#maxLiveSockets) {\n\t\t\t// A refusal is the most interesting thing that can happen at a bind, and it is\n\t\t\t// the one outcome that leaves NO socket behind for anything else to notice.\n\t\t\tsoakRecord(\n\t\t\t\tSOAK_EVENTS.CLIENT_REJECTED,\n\t\t\t\t{\n\t\t\t\t\treason: \"socket_cap_reached\",\n\t\t\t\t\tsessionId: this.#sessionId,\n\t\t\t\t\tcap: this.#maxLiveSockets,\n\t\t\t\t\tliveSockets: others,\n\t\t\t\t},\n\t\t\t\t\"warn\",\n\t\t\t);\n\t\t\tthrow new SocketCapReachedError(this.#sessionId, this.#maxLiveSockets, others, socketDir);\n\t\t}\n\n\t\t// Take ownership of the session id before touching the socket path.\n\t\ttry {\n\t\t\tawait this.#claimLock();\n\t\t} catch (error) {\n\t\t\t// The busy twin (`draht -c` in a second terminal) is the commonest default-on\n\t\t\t// refusal there is and it is not environmental, so a soak that could not count\n\t\t\t// them would mistake the phase's most likely papercut for silence.\n\t\t\tif (error instanceof SocketSessionBusyError) {\n\t\t\t\tsoakRecord(\n\t\t\t\t\tSOAK_EVENTS.CLIENT_REJECTED,\n\t\t\t\t\t{ reason: \"session_busy\", sessionId: this.#sessionId, ownerPid: error.ownerPid },\n\t\t\t\t\t\"warn\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\n\t\ttry {\n\t\t\tthis.#server = createServer((socket) => this.#handleConnection(socket));\n\t\t\tconst server = this.#server;\n\n\t\t\t// One long-lived error listener: it rejects the pending listen() and swallows\n\t\t\t// post-startup server errors, which must not become uncaught exceptions.\n\t\t\tserver.on(\"error\", (error: Error) => {\n\t\t\t\tconst reject = this.#rejectListen;\n\t\t\t\tthis.#rejectListen = null;\n\t\t\t\treject?.(error);\n\t\t\t});\n\n\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\tthis.#rejectListen = reject;\n\t\t\t\tserver.listen(this.#socketPath, () => {\n\t\t\t\t\tthis.#rejectListen = null;\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\t});\n\n\t\t\t// bind(2) applies the process umask, so tighten the socket explicitly. Between\n\t\t\t// bind and this chmod the socket is still unreachable for other users: it can\n\t\t\t// only be named through the 0700 directory above, and Unix-domain permissions\n\t\t\t// are enforced at connect(2) time. Mutating the process-global umask instead\n\t\t\t// would leak into every unrelated file this process creates concurrently.\n\t\t\tawait chmod(this.#socketPath, 0o600);\n\t\t} catch (error) {\n\t\t\t// Never leave a lock behind that advertises a socket which was never bound.\n\t\t\tthis.#server = null;\n\t\t\tthis.#rejectListen = null;\n\t\t\tawait rm(this.#lockPath, { force: true }).catch(() => {});\n\t\t\tawait rm(this.#socketPath, { force: true }).catch(() => {});\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Stop the socket server and clean up.\n\t */\n\tasync stop(): Promise<void> {\n\t\tif (this.#stopped) return;\n\t\tthis.#stopped = true;\n\n\t\t// Half-close every accepted connection, not just the attached clients: a peer that\n\t\t// connected and never sent an `attach` frame is not in #clients, and leaving it open\n\t\t// would keep server.close() from ever calling back.\n\t\tfor (const socket of this.#sockets) {\n\t\t\ttry {\n\t\t\t\tsocket.end();\n\t\t\t} catch {}\n\t\t}\n\t\tthis.#clients.clear();\n\n\t\t// Close server\n\t\tif (this.#server) {\n\t\t\tconst server = this.#server;\n\t\t\tthis.#server = null;\n\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\t// A peer that never closes its own half - a non-Node bridge, say - must not be\n\t\t\t\t// able to wedge shutdown forever. Force the stragglers down after a grace\n\t\t\t\t// period and carry on; the .sock/.lock cleanup below then runs either way.\n\t\t\t\tconst timer = setTimeout(() => {\n\t\t\t\t\tfor (const socket of this.#sockets) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tsocket.destroy();\n\t\t\t\t\t\t} catch {}\n\t\t\t\t\t}\n\t\t\t\t\tthis.#sockets.clear();\n\t\t\t\t\tresolve();\n\t\t\t\t}, STOP_CLOSE_TIMEOUT_MS);\n\t\t\t\tserver.close(() => {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\t\tthis.#sockets.clear();\n\n\t\t// Clean up socket and lock files — but only if this instance owns them. A\n\t\t// server whose start() was refused with SocketSessionBusyError never claimed\n\t\t// the lock; deleting these paths would destroy the LIVE owner's files and let\n\t\t// a third process steal the session id.\n\t\tif (this.#ownsLock) {\n\t\t\tthis.#ownsLock = false;\n\t\t\tawait rm(this.#socketPath, { force: true });\n\t\t\tawait rm(this.#lockPath, { force: true });\n\t\t}\n\t}\n\n\t/**\n\t * Stop the socket server from a synchronous exit path.\n\t *\n\t * `process.on(\"exit\")` and signal handlers cannot await, so this does the same\n\t * teardown as {@link stop} without yielding to the event loop.\n\t */\n\tstopSync(): void {\n\t\tif (this.#stopped) return;\n\t\tthis.#stopped = true;\n\n\t\tfor (const socket of this.#sockets) {\n\t\t\ttry {\n\t\t\t\tsocket.destroy();\n\t\t\t} catch {}\n\t\t}\n\t\tthis.#sockets.clear();\n\t\tthis.#clients.clear();\n\n\t\tif (this.#server) {\n\t\t\tconst server = this.#server;\n\t\t\tthis.#server = null;\n\t\t\ttry {\n\t\t\t\tserver.close();\n\t\t\t} catch {}\n\t\t}\n\n\t\t// Only remove files this instance actually claimed — see stop().\n\t\tif (this.#ownsLock) {\n\t\t\tthis.#ownsLock = false;\n\t\t\ttry {\n\t\t\t\trmSync(this.#socketPath, { force: true });\n\t\t\t} catch {}\n\t\t\ttry {\n\t\t\t\trmSync(this.#lockPath, { force: true });\n\t\t\t} catch {}\n\t\t}\n\t}\n\n\t/**\n\t * Broadcast output to all connected clients.\n\t *\n\t * @param data - Output text\n\t * @param stream - Output stream (stdout or stderr)\n\t */\n\tbroadcastOutput(data: string, stream: \"stdout\" | \"stderr\" = \"stdout\"): void {\n\t\tconst message: ServerMessage = {\n\t\t\ttype: \"output\",\n\t\t\tdata,\n\t\t\tstream,\n\t\t};\n\t\tthis.#broadcast(message);\n\t}\n\n\t/**\n\t * Broadcast an error to all connected clients.\n\t */\n\tbroadcastError(message: string, code?: string): void {\n\t\tconst error: ServerMessage = { type: \"error\", message, code };\n\t\tthis.#broadcast(error);\n\t}\n\n\t/**\n\t * Send an error to one specific client, if it is still connected.\n\t */\n\tsendErrorToClient(clientId: string, message: string, code?: string): void {\n\t\tconst client = this.#clients.get(clientId);\n\t\tif (!client) return;\n\t\tthis.#sendError(client.socket, message, code);\n\t}\n\n\t/**\n\t * Send a permission ask to one client, if it is still connected and may have it.\n\t *\n\t * Silently does nothing for a client that is gone, read-only, or never\n\t * declared {@link PERMISSION_RELAY_CAPABILITY}: not being asked is the\n\t * correct outcome for all three, and none of them is an error the asker can\n\t * act on.\n\t */\n\tsendPermissionRequest(clientId: string, message: PermissionRequestMessage): void {\n\t\tconst client = this.#clients.get(clientId);\n\t\tif (!client || !this.#mayReceivePermissionFrames(client)) return;\n\t\tthis.#send(client.socket, message);\n\t}\n\n\t/**\n\t * Broadcast a permission ask to every client that may answer it.\n\t *\n\t * @returns the ids that were actually sent the ask — the asker needs to know\n\t * whether anybody at all can answer, and an empty result is the\n\t * honest answer \"nobody remote is listening\".\n\t */\n\tbroadcastPermissionRequest(message: PermissionRequestMessage): string[] {\n\t\tconst reached: string[] = [];\n\t\tfor (const client of this.#clients.values()) {\n\t\t\tif (!this.#mayReceivePermissionFrames(client)) continue;\n\t\t\tthis.#send(client.socket, message);\n\t\t\treached.push(client.id);\n\t\t}\n\t\treturn reached;\n\t}\n\n\t/**\n\t * Broadcast the outcome of a permission ask.\n\t *\n\t * Gated exactly like the ask itself: a client that could not have been asked\n\t * is not told how somebody else's ask ended, and a client that never declared\n\t * the capability is never sent a frame it cannot decode.\n\t */\n\tbroadcastPermissionResolved(message: PermissionResolvedMessage): void {\n\t\tfor (const client of this.#clients.values()) {\n\t\t\tif (!this.#mayReceivePermissionFrames(client)) continue;\n\t\t\tthis.#send(client.socket, message);\n\t\t}\n\t}\n\n\t/**\n\t * How many attached clients could answer a permission ask RIGHT NOW.\n\t *\n\t * Gated by exactly the predicate emission is gated by, so the count and the\n\t * fan-out can never disagree. This is what `ExtensionRunner.hasUI()` becomes\n\t * for a headless attachable session, and it must therefore stay honest in\n\t * both directions: reporting a client that cannot be asked turns today's loud\n\t * \"no UI available to request approval\" block into an instant `false` that\n\t * the permission gate reports as \"User denied approval\" — a user action in\n\t * the transcript that no user took.\n\t */\n\tget permissionCapableClientCount(): number {\n\t\tlet count = 0;\n\t\tfor (const client of this.#clients.values()) {\n\t\t\tif (this.#mayReceivePermissionFrames(client)) count++;\n\t\t}\n\t\treturn count;\n\t}\n\n\t/**\n\t * Whether this client is eligible for permission frames at all: read-write\n\t * (a read-only peer may watch but never decide) and capability-declaring.\n\t */\n\t#mayReceivePermissionFrames(client: ConnectedClient): boolean {\n\t\treturn client.mode !== \"read-only\" && client.capabilities.includes(PERMISSION_RELAY_CAPABILITY);\n\t}\n\n\t/**\n\t * Set callback for input received from clients.\n\t */\n\tonInput(callback: (data: string, clientId: string) => void): void {\n\t\tthis.#onInput = callback;\n\t}\n\n\t/**\n\t * Set callback for a permission answer received from a client.\n\t */\n\tonPermissionResponse(callback: (message: PermissionResponseMessage, clientId: string) => void): void {\n\t\tthis.#onPermissionResponse = callback;\n\t}\n\n\t/**\n\t * Set callback fired right after a client has been sent `session_metadata`,\n\t * for the clients that could actually be sent a permission frame.\n\t *\n\t * See the attach case for the gate and for what does — and does not —\n\t * authenticate the peer being replayed to.\n\t */\n\tonAttachReplay(callback: (clientId: string) => void): void {\n\t\tthis.#onAttachReplay = callback;\n\t}\n\n\t/**\n\t * Set callback fired when an attached client's connection ends, however it\n\t * ended — a graceful `detach`, a closed socket, or a socket error.\n\t *\n\t * Per-connection bookkeeping outside this class needs the same signal the\n\t * `client_left` broadcast carries, and it needs it for the same reason: a\n\t * client that reconnects under the same id is a NEW connection with nothing\n\t * on its screen. Whatever tracked what that client had already been shown has\n\t * to forget it here, or the reconnecting peer is never shown it again.\n\t */\n\tonClientDisconnect(callback: (clientId: string) => void): void {\n\t\tthis.#onClientDisconnect = callback;\n\t}\n\n\t/**\n\t * Get socket path for this session.\n\t */\n\tget socketPath(): string {\n\t\treturn this.#socketPath;\n\t}\n\n\t/**\n\t * Get the session id this socket is bound to.\n\t */\n\tget sessionId(): string {\n\t\treturn this.#sessionId;\n\t}\n\n\t/**\n\t * Get number of connected clients.\n\t */\n\tget clientCount(): number {\n\t\treturn this.#clients.size;\n\t}\n\n\t/**\n\t * Assert the sockets directory is a real directory, owned by this user, with no\n\t * group or other permission bits (R35-ALWAYS.3).\n\t *\n\t * `lstat`, not `stat`: a symlink pointing at a directory somebody else controls\n\t * would otherwise pass every check that follows.\n\t *\n\t * The one thing this does silently is re-tighten a loose mode on a directory that\n\t * IS ours — that is not a trust decision, it is the same `chmod` this method has\n\t * always done, and refusing there would strand every user whose directory predates\n\t * the mode being enforced. A directory owned by somebody else is refused outright:\n\t * `chmod`ing it would either fail with EPERM or succeed on a directory planted for\n\t * us to publish into.\n\t *\n\t * Off POSIX there are no uids and file modes do not mean this; the assertion is\n\t * skipped rather than faked.\n\t */\n\tasync #assertSocketDirIsOurs(socketDir: string): Promise<void> {\n\t\tconst uid = currentUid();\n\t\tif (uid === null) return;\n\n\t\tlet info = await lstat(socketDir).catch((error: NodeJS.ErrnoException) => {\n\t\t\tthrow new SocketDirectoryUnsafeError(socketDir, `it cannot be inspected (${error?.code ?? \"unknown\"})`);\n\t\t});\n\t\tif (!info.isDirectory()) {\n\t\t\tthrow new SocketDirectoryUnsafeError(socketDir, \"it is not a directory (a symlink is not one either)\");\n\t\t}\n\t\tif (info.uid !== uid) {\n\t\t\tthrow new SocketDirectoryUnsafeError(socketDir, `it belongs to uid ${info.uid}, not to uid ${uid}`);\n\t\t}\n\t\tif ((info.mode & 0o077) !== 0) {\n\t\t\tawait chmod(socketDir, 0o700).catch(() => {});\n\t\t\tinfo = await lstat(socketDir).catch(() => info);\n\t\t\tif ((info.mode & 0o077) !== 0) {\n\t\t\t\tthrow new SocketDirectoryUnsafeError(\n\t\t\t\t\tsocketDir,\n\t\t\t\t\t`it is readable or writable by other users (mode ${(info.mode & 0o777).toString(8)})`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Claim the session lock, or refuse when a live process already holds it.\n\t *\n\t * The lock file is created exclusively so two processes racing for the same session id\n\t * cannot both believe they won. An existing lock is only reaped when its PID is dead\n\t * (or is our own leftover, e.g. re-binding after a session switch). A lock that exists\n\t * but names no readable PID counts as held, not as dead: the exclusive create and the\n\t * PID write are two steps, and reaping in between would steal a live owner's session.\n\t */\n\tasync #claimLock(): Promise<void> {\n\t\t// Four lines. The first three are the published contract (pid, cwd, ISO creation\n\t\t// time) and both readers still accept exactly three, so locks written by older\n\t\t// builds — and the ones already on disk — keep parsing. The 4th is the OWNING\n\t\t// PROCESS's start time in epoch milliseconds, which is what lets a reader retire a\n\t\t// lock whose pid was recycled by a reboot instead of letting it poison the session\n\t\t// id forever. See `lockIsPreBootDebris` in discovery.ts for why that comparison,\n\t\t// and not a blanket age bound on readable-pid locks.\n\t\tconst processStartedAtMs = Math.round(Date.now() - process.uptime() * 1000);\n\t\tconst contents = `${process.pid}\\n${this.#cwd}\\n${this.#createdAt.toISOString()}\\n${processStartedAtMs}`;\n\n\t\tfor (let attempt = 0; attempt < 2; attempt++) {\n\t\t\ttry {\n\t\t\t\tawait writeFile(this.#lockPath, contents, { flag: \"wx\", mode: 0o600 });\n\t\t\t\t// A leftover socket from a dead owner cannot be connected to; remove it so\n\t\t\t\t// listen() can bind the path.\n\t\t\t\tawait rm(this.#socketPath, { force: true });\n\t\t\t\tthis.#ownsLock = true;\n\t\t\t\treturn;\n\t\t\t} catch (error) {\n\t\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"EEXIST\") throw error;\n\t\t\t}\n\n\t\t\t// A lock file that is not ours is not a claim on our session id. It can only\n\t\t\t// exist here because somebody with more privilege wrote it into a directory\n\t\t\t// start() has already asserted is ours and 0700, so it is debris — and treating\n\t\t\t// it as a live owner is exactly how a session id gets refused forever.\n\t\t\tconst foreignLock = await this.#lockIsForeign();\n\t\t\tconst ownerPid = foreignLock ? null : await this.#readLockPid();\n\t\t\tif (!foreignLock) {\n\t\t\t\tif (ownerPid === null) {\n\t\t\t\t\t// The lock exists but names no readable PID. The likely cause is a starter that\n\t\t\t\t\t// won the exclusive create microseconds ago and has not written its PID yet;\n\t\t\t\t\t// reaping it here would hand the same session id to two live processes. Only a\n\t\t\t\t\t// lock that has sat unwritten far longer than any write takes counts as debris.\n\t\t\t\t\tif (!(await this.#lockIsAbandoned())) {\n\t\t\t\t\t\tthrow new SocketSessionBusyError(this.#sessionId, null, this.#socketPath);\n\t\t\t\t\t}\n\t\t\t\t} else if (ownerPid !== process.pid && pidOwnership(ownerPid) === \"ours\") {\n\t\t\t\t\t// \"ours\" and not \"alive\": a pid we cannot signal is alive but belongs to\n\t\t\t\t\t// another user, so it cannot be a draht of ours holding this id — the file is\n\t\t\t\t\t// ours and only this uid could have written it. Reading EPERM as a live owner\n\t\t\t\t\t// is what made a lock naming root's pid 1 refuse a session id forever,\n\t\t\t\t\t// regardless of age. EPERM still means the PROCESS is alive (discovery never\n\t\t\t\t\t// reaps another user's session); it just stops meaning the LOCK is live.\n\t\t\t\t\tthrow new SocketSessionBusyError(this.#sessionId, ownerPid, this.#socketPath);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Dead owner, our own leftover, or abandoned debris: reap and retry the create.\n\t\t\tawait rm(this.#lockPath, { force: true });\n\t\t\tawait rm(this.#socketPath, { force: true });\n\t\t}\n\n\t\tthrow new Error(`Could not claim the attachable-session lock at ${this.#lockPath}`);\n\t}\n\n\t/**\n\t * Whether an existing lock with no readable PID is old enough to count as debris\n\t * rather than as a claim another process is in the middle of writing.\n\t */\n\tasync #lockIsAbandoned(): Promise<boolean> {\n\t\ttry {\n\t\t\tconst info = await stat(this.#lockPath);\n\t\t\treturn Date.now() - info.mtimeMs > UNWRITTEN_LOCK_STALE_MS;\n\t\t} catch {\n\t\t\t// It vanished while we looked at it: the session id is free again.\n\t\t\treturn true;\n\t\t}\n\t}\n\n\t/**\n\t * Whether an existing lock file belongs to another uid, or is not a plain file.\n\t *\n\t * Either way it is not a claim this process may honour: see {@link #claimLock}.\n\t * Off POSIX, where there are no uids, nothing is foreign.\n\t */\n\tasync #lockIsForeign(): Promise<boolean> {\n\t\tconst uid = currentUid();\n\t\ttry {\n\t\t\tconst info = await lstat(this.#lockPath);\n\t\t\tif (!info.isFile()) return true;\n\t\t\treturn uid !== null && info.uid !== uid;\n\t\t} catch {\n\t\t\t// It vanished while we looked at it; the retry re-creates it.\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Read the PID recorded in an existing lock file, or null when it is unreadable.\n\t */\n\tasync #readLockPid(): Promise<number | null> {\n\t\ttry {\n\t\t\tconst contents = await readFile(this.#lockPath, \"utf-8\");\n\t\t\tconst pid = Number.parseInt(contents.trim().split(\"\\n\")[0], 10);\n\t\t\treturn Number.isInteger(pid) ? pid : null;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Handle new client connection.\n\t */\n\t#handleConnection(socket: Socket): void {\n\t\tthis.#sockets.add(socket);\n\t\tlet clientId: string | null = null;\n\t\tlet _mode: ClientMode = \"read-write\";\n\t\tlet buffer = \"\";\n\n\t\t// Handle incoming data (JSON messages)\n\t\tsocket.on(\"data\", (data) => {\n\t\t\tbuffer += data.toString();\n\t\t\tconst lines = buffer.split(\"\\n\");\n\t\t\tbuffer = lines.pop() || \"\";\n\n\t\t\tfor (const line of lines) {\n\t\t\t\tif (!line.trim()) continue;\n\n\t\t\t\ttry {\n\t\t\t\t\tconst message = JSON.parse(line) as ClientMessage;\n\t\t\t\t\tthis.#handleClientMessage(message, socket, (id, m) => {\n\t\t\t\t\t\tclientId = id;\n\t\t\t\t\t\t_mode = m;\n\t\t\t\t\t});\n\t\t\t\t} catch (_err) {\n\t\t\t\t\tthis.#sendError(socket, \"Invalid JSON message\");\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Handle client disconnect\n\t\tsocket.on(\"close\", () => {\n\t\t\tthis.#sockets.delete(socket);\n\t\t\tif (clientId) {\n\t\t\t\tthis.#handleClientDisconnect(clientId);\n\t\t\t}\n\t\t});\n\n\t\tsocket.on(\"error\", () => {\n\t\t\tif (clientId) {\n\t\t\t\tthis.#handleClientDisconnect(clientId);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Handle a client message.\n\t */\n\t#handleClientMessage(\n\t\tmessage: ClientMessage,\n\t\tsocket: Socket,\n\t\tonAttach: (id: string, mode: ClientMode) => void,\n\t): void {\n\t\tswitch (message.type) {\n\t\t\tcase \"attach\": {\n\t\t\t\t// Check max clients\n\t\t\t\tif (this.#clients.size >= this.#maxClients) {\n\t\t\t\t\tthis.#sendError(socket, \"Maximum clients reached\");\n\t\t\t\t\tsoakRecord(\n\t\t\t\t\t\tSOAK_EVENTS.CLIENT_REJECTED,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treason: \"max_clients\",\n\t\t\t\t\t\t\tsessionId: this.#sessionId,\n\t\t\t\t\t\t\tclientId: soakLabel(message.clientId),\n\t\t\t\t\t\t\tmaxClients: this.#maxClients,\n\t\t\t\t\t\t\tclientCount: this.#clients.size,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"warn\",\n\t\t\t\t\t);\n\t\t\t\t\tsocket.end();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// The mode decides whether this peer's keystrokes reach the session, so\n\t\t\t\t// it is validated against the closed set rather than tested for one\n\t\t\t\t// value. A negative `=== \"read-only\"` check would let `mode: \"banana\"`\n\t\t\t\t// attach with full write access on the strength of not being the one\n\t\t\t\t// string that is refused.\n\t\t\t\tif (!CLIENT_MODES.includes(message.mode)) {\n\t\t\t\t\tthis.#sendError(socket, `Unknown client mode ${JSON.stringify(message.mode)}`, \"UNKNOWN_CLIENT_MODE\");\n\t\t\t\t\tsoakRecord(\n\t\t\t\t\t\tSOAK_EVENTS.CLIENT_REJECTED,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treason: \"unknown_client_mode\",\n\t\t\t\t\t\t\tsessionId: this.#sessionId,\n\t\t\t\t\t\t\tclientId: soakLabel(message.clientId),\n\t\t\t\t\t\t\tcode: \"UNKNOWN_CLIENT_MODE\",\n\t\t\t\t\t\t\tmode: soakLabel(message.mode),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"warn\",\n\t\t\t\t\t);\n\t\t\t\t\tsocket.end();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Check for duplicate client ID\n\t\t\t\tif (this.#clients.has(message.clientId)) {\n\t\t\t\t\tthis.#sendError(socket, \"Client ID already connected\");\n\t\t\t\t\tsoakRecord(\n\t\t\t\t\t\tSOAK_EVENTS.CLIENT_REJECTED,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treason: \"duplicate_client_id\",\n\t\t\t\t\t\t\tsessionId: this.#sessionId,\n\t\t\t\t\t\t\tclientId: soakLabel(message.clientId),\n\t\t\t\t\t\t\tclientCount: this.#clients.size,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"warn\",\n\t\t\t\t\t);\n\t\t\t\t\tsocket.end();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Register client\n\t\t\t\tconst client: ConnectedClient = {\n\t\t\t\t\tid: message.clientId,\n\t\t\t\t\tmode: message.mode,\n\t\t\t\t\tsocket,\n\t\t\t\t\tconnectedAt: new Date(),\n\t\t\t\t\t// Only strings, and only what was actually declared. An absent\n\t\t\t\t\t// `capabilities` is an older client, which is exactly the case the\n\t\t\t\t\t// gating exists for.\n\t\t\t\t\tcapabilities: Array.isArray(message.capabilities)\n\t\t\t\t\t\t? message.capabilities.filter((entry): entry is string => typeof entry === \"string\")\n\t\t\t\t\t\t: [],\n\t\t\t\t};\n\t\t\t\tthis.#clients.set(message.clientId, client);\n\t\t\t\tonAttach(message.clientId, message.mode);\n\n\t\t\t\t// THE `client_attach` SEAM (R35-ALWAYS.11). Here, and not at the\n\t\t\t\t// `onAttachReplay` hook one layer up, because this line is reached by EVERY\n\t\t\t\t// client while that hook is gated on the permission capability — see the note\n\t\t\t\t// at that callback in `session-integration.ts`. Recorded before the metadata\n\t\t\t\t// goes out, so an attach that dies mid-write is still counted.\n\t\t\t\tsoakRecord(SOAK_EVENTS.CLIENT_ATTACH, {\n\t\t\t\t\tclientId: soakLabel(message.clientId),\n\t\t\t\t\tsessionId: this.#sessionId,\n\t\t\t\t\tmode: soakLabel(message.mode),\n\t\t\t\t\tcapabilities: client.capabilities.map(soakLabel),\n\t\t\t\t\tclientCount: this.#clients.size,\n\t\t\t\t});\n\n\t\t\t\t// Send session metadata\n\t\t\t\tconst metadata: ServerMessage = {\n\t\t\t\t\ttype: \"session_metadata\",\n\t\t\t\t\tsessionId: this.#sessionId,\n\t\t\t\t\tcwd: this.#cwd,\n\t\t\t\t\tcreatedAt: this.#createdAt.toISOString(),\n\t\t\t\t};\n\t\t\t\tthis.#send(socket, metadata);\n\n\t\t\t\t// ── replay (R34-PERM.6) ───────────────────────────────────────────────\n\t\t\t\t//\n\t\t\t\t// Whatever holds unanswered asks gets its chance now: the client is\n\t\t\t\t// registered and has its metadata, so a replayed ask lands on a surface\n\t\t\t\t// that already knows which session it is looking at. This fires on EVERY\n\t\t\t\t// attach, including a reattach under a clientId this server has seen\n\t\t\t\t// before — a reconnecting peer is a new connection with nothing on its\n\t\t\t\t// screen, and it may be a whole new process.\n\t\t\t\t//\n\t\t\t\t// Gated by exactly the predicate emission is gated by, so a client that\n\t\t\t\t// could not have been sent an ask is not offered a backlog of them\n\t\t\t\t// either: a read-only peer may watch but never decide, and a client that\n\t\t\t\t// never declared PERMISSION_RELAY_CAPABILITY cannot render the dialog.\n\t\t\t\t//\n\t\t\t\t// WHAT AUTHENTICATES THE CLIENT BEING REPLAYED TO, stated rather than\n\t\t\t\t// invented: on this socket, nothing beyond the filesystem. The socket dir\n\t\t\t\t// is 0700 and the socket itself 0600 (see start()), so reaching this line\n\t\t\t\t// already means the peer runs as this user; `clientId` is SELF-ASSERTED\n\t\t\t\t// and is an addressing label, not a credential. The device credential\n\t\t\t\t// lives one hop up, at the gateway's `/attach`. A replay therefore hands\n\t\t\t\t// a local peer nothing it could not have had by attaching a moment\n\t\t\t\t// earlier and receiving the same ask in the ordinary broadcast.\n\t\t\t\tif (this.#mayReceivePermissionFrames(client)) {\n\t\t\t\t\tthis.#onAttachReplay?.(message.clientId);\n\t\t\t\t}\n\n\t\t\t\t// Notify other clients\n\t\t\t\tconst joined: ServerMessage = {\n\t\t\t\t\ttype: \"client_joined\",\n\t\t\t\t\tclientId: message.clientId,\n\t\t\t\t\tmode: message.mode,\n\t\t\t\t};\n\t\t\t\tthis.#broadcast(joined, message.clientId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"input\": {\n\t\t\t\t// Check if client is in read-write mode\n\t\t\t\tconst client = this.#clients.get(message.clientId);\n\t\t\t\tif (!client || client.mode === \"read-only\") {\n\t\t\t\t\tthis.#sendError(socket, \"Read-only clients cannot send input\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Forward input to session\n\t\t\t\tif (this.#onInput) {\n\t\t\t\t\tthis.#onInput(message.data, message.clientId);\n\t\t\t\t}\n\n\t\t\t\t// Echo input to all other clients (tmux-style)\n\t\t\t\tif (this.#broadcastInputEcho) {\n\t\t\t\t\tconst echo: ServerMessage = {\n\t\t\t\t\t\ttype: \"input_echo\",\n\t\t\t\t\t\tdata: message.data,\n\t\t\t\t\t\tclientId: message.clientId,\n\t\t\t\t\t};\n\t\t\t\t\tthis.#broadcast(echo, message.clientId);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"detach\": {\n\t\t\t\tthis.#handleClientDisconnect(message.clientId);\n\t\t\t\tsocket.end();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"permission_response\": {\n\t\t\t\tconst client = this.#clients.get(message.clientId);\n\t\t\t\tif (!client || client.socket !== socket) {\n\t\t\t\t\t// Either nobody attached under this id, or somebody else did. Both are\n\t\t\t\t\t// \"you are not that client\", said the same way so neither answer is an\n\t\t\t\t\t// oracle for which.\n\t\t\t\t\tthis.#sendError(socket, \"Unknown client\", \"PERMISSION_NOT_ATTACHED\");\n\t\t\t\t\tthis.#recordPermissionRefusal(\"permission_not_attached\", \"PERMISSION_NOT_ATTACHED\", message);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (client.mode === \"read-only\") {\n\t\t\t\t\tthis.#sendError(socket, \"Read-only clients cannot answer permissions\", \"PERMISSION_READ_ONLY\");\n\t\t\t\t\tthis.#recordPermissionRefusal(\"permission_read_only\", \"PERMISSION_READ_ONLY\", message);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!client.capabilities.includes(PERMISSION_RELAY_CAPABILITY)) {\n\t\t\t\t\t// It was never sent an ask, so it cannot be answering one it saw.\n\t\t\t\t\tthis.#sendError(\n\t\t\t\t\t\tsocket,\n\t\t\t\t\t\t`Client did not declare the ${PERMISSION_RELAY_CAPABILITY} capability on attach`,\n\t\t\t\t\t\t\"PERMISSION_NOT_CAPABLE\",\n\t\t\t\t\t);\n\t\t\t\t\tthis.#recordPermissionRefusal(\"permission_not_capable\", \"PERMISSION_NOT_CAPABLE\", message);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!this.#onPermissionResponse) {\n\t\t\t\t\t// Nothing in this process is holding permission asks. Saying so is the\n\t\t\t\t\t// point: silence here is indistinguishable from \"accepted\", and a phone\n\t\t\t\t\t// would sit forever on a dialog nobody is going to resolve.\n\t\t\t\t\tthis.#sendError(\n\t\t\t\t\t\tsocket,\n\t\t\t\t\t\t`No permission ask ${JSON.stringify(message.requestId)} is pending`,\n\t\t\t\t\t\t\"PERMISSION_UNKNOWN_REQUEST\",\n\t\t\t\t\t);\n\t\t\t\t\tthis.#recordPermissionRefusal(\"permission_unknown_request\", \"PERMISSION_UNKNOWN_REQUEST\", message);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.#onPermissionResponse(message, message.clientId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\t// A client message type this build does not know. Answering is what makes\n\t\t\t\t// version skew visible in the client→server direction: without this case\n\t\t\t\t// an unknown frame vanished with no reply at all, so a newer renderer\n\t\t\t\t// could not tell a draht that had handled its frame from one that had\n\t\t\t\t// never heard of it.\n\t\t\t\tconst unknown = (message as { type?: unknown }).type;\n\t\t\t\tthis.#sendError(socket, `Unknown message type ${JSON.stringify(unknown)}`, \"UNKNOWN_MESSAGE_TYPE\");\n\t\t\t\t// Version skew, counted. A week of these from one peer is a renderer that\n\t\t\t\t// needs upgrading, not a session that is misbehaving.\n\t\t\t\tsoakRecord(\n\t\t\t\t\tSOAK_EVENTS.CLIENT_REJECTED,\n\t\t\t\t\t{\n\t\t\t\t\t\treason: \"unknown_message_type\",\n\t\t\t\t\t\tsessionId: this.#sessionId,\n\t\t\t\t\t\tcode: \"UNKNOWN_MESSAGE_TYPE\",\n\t\t\t\t\t\tmessageType: soakLabel(unknown),\n\t\t\t\t\t},\n\t\t\t\t\t\"warn\",\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * A permission ANSWER that was refused before anything could decide anything.\n\t *\n\t * These are the records that carry a `requestId`, which is what lets a verdict\n\t * join this stream against the durable `permission_resolution` rows the session\n\t * writes: an ask that has a refused answer here and no resolution there is a\n\t * decision that never reached the agent. Nothing about the decision itself is\n\t * duplicated into this log — the session store owns that.\n\t */\n\t#recordPermissionRefusal(reason: string, code: string, message: PermissionResponseMessage): void {\n\t\tsoakRecord(\n\t\t\tSOAK_EVENTS.CLIENT_REJECTED,\n\t\t\t{\n\t\t\t\treason,\n\t\t\t\tcode,\n\t\t\t\tsessionId: this.#sessionId,\n\t\t\t\tclientId: soakLabel(message.clientId),\n\t\t\t\trequestId: soakLabel(message.requestId),\n\t\t\t},\n\t\t\t\"warn\",\n\t\t);\n\t}\n\n\t/**\n\t * Handle client disconnect.\n\t *\n\t * R34-PERM.6 — DO NOT MAKE THIS TOUCH A PENDING PERMISSION ASK. It removes a\n\t * CONNECTION and resets what that connection had been shown; it must never\n\t * drop, resolve, expire or cancel a registry entry. A client that was shown\n\t * an ask and then died would otherwise take the ask with it: the agent stays\n\t * parked in `beforeToolCall` forever with no surface left that can answer,\n\t * which is the wedge documented at `modes/rpc/rpc-mode.ts`. The ask stays\n\t * PENDING and is replayed to whoever attaches next, including this same\n\t * client coming back under the same id.\n\t *\n\t * Tidying this up so that \"leaving cleans up after itself\" is exactly the\n\t * regression this comment exists to stop.\n\t */\n\t#handleClientDisconnect(clientId: string): void {\n\t\tconst client = this.#clients.get(clientId);\n\t\tif (!client) return;\n\n\t\tthis.#clients.delete(clientId);\n\n\t\t// THE `client_detach` SEAM, symmetric with `client_attach` above: one record per\n\t\t// connection that was ever registered, whatever ended it — a `detach` frame, a\n\t\t// closed socket, or a peer that died. `#clients.get` guards re-entry, so a socket\n\t\t// that both errors and closes is recorded once.\n\t\tsoakRecord(SOAK_EVENTS.CLIENT_DETACH, {\n\t\t\tclientId: soakLabel(clientId),\n\t\t\tsessionId: this.#sessionId,\n\t\t\tmode: soakLabel(client.mode),\n\t\t\tconnectedMs: Date.now() - client.connectedAt.getTime(),\n\t\t\tclientCount: this.#clients.size,\n\t\t});\n\n\t\t// Per-connection state ONLY — see the note above. Before the other clients\n\t\t// are told, because a listener that keeps per-connection state has to have\n\t\t// dropped it by the time anything observable about this session changes.\n\t\tthis.#onClientDisconnect?.(clientId);\n\n\t\t// Notify other clients\n\t\tconst left: ServerMessage = {\n\t\t\ttype: \"client_left\",\n\t\t\tclientId,\n\t\t};\n\t\tthis.#broadcast(left);\n\t}\n\n\t/**\n\t * Broadcast a message to all clients (or all except one).\n\t */\n\t#broadcast(message: ServerMessage, excludeClientId?: string): void {\n\t\tconst json = `${JSON.stringify(message)}\\n`;\n\t\tfor (const client of this.#clients.values()) {\n\t\t\tif (client.id !== excludeClientId) {\n\t\t\t\tclient.socket.write(json);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Send a message to a specific socket.\n\t */\n\t#send(socket: Socket, message: ServerMessage): void {\n\t\tconst json = `${JSON.stringify(message)}\\n`;\n\t\tsocket.write(json);\n\t}\n\n\t/**\n\t * Send an error message to a specific socket.\n\t */\n\t#sendError(socket: Socket, message: string, code?: string): void {\n\t\tconst error: ServerMessage = {\n\t\t\ttype: \"error\",\n\t\t\tmessage,\n\t\t\tcode,\n\t\t};\n\t\tthis.#send(socket, error);\n\t}\n}\n"]}
@@ -6,15 +6,34 @@
6
6
  */
7
7
  /** Client connection mode */
8
8
  export type ClientMode = "read-write" | "read-only";
9
+ /**
10
+ * The capability a client declares in its `attach` frame to say it understands
11
+ * permission frames (R34-PERM.1).
12
+ *
13
+ * This is the whole skew story. `permission_request` / `permission_resolved` are
14
+ * sent ONLY to clients that named this, so a bridge built before geist/0.3 —
15
+ * whose attach line carries no `capabilities` at all — never receives a frame it
16
+ * cannot decode, and is therefore never dropped with a `protocol_error
17
+ * unknown_type` and close 1008. Emission is opt-in, not opt-out.
18
+ */
19
+ export declare const PERMISSION_RELAY_CAPABILITY = "permission-relay";
20
+ /** Every `ClientMode` there is, as a runtime value. `attach` is validated against it. */
21
+ export declare const CLIENT_MODES: readonly ClientMode[];
9
22
  /** Message types: Client → Server */
10
- export type ClientMessage = AttachMessage | InputMessage | DetachMessage;
23
+ export type ClientMessage = AttachMessage | InputMessage | DetachMessage | PermissionResponseMessage;
11
24
  /** Message types: Server → Client */
12
- export type ServerMessage = OutputMessage | InputEchoMessage | ClientJoinedMessage | ClientLeftMessage | SessionMetadataMessage | ErrorMessage;
25
+ export type ServerMessage = OutputMessage | InputEchoMessage | ClientJoinedMessage | ClientLeftMessage | SessionMetadataMessage | ErrorMessage | PermissionRequestMessage | PermissionResolvedMessage;
13
26
  /** Client requests to attach */
14
27
  export interface AttachMessage {
15
28
  type: "attach";
16
29
  clientId: string;
17
30
  mode: ClientMode;
31
+ /**
32
+ * What this client understands beyond the frames every client has always
33
+ * received. Absent means "an older client": it is sent nothing new.
34
+ * See {@link PERMISSION_RELAY_CAPABILITY}.
35
+ */
36
+ capabilities?: string[];
18
37
  }
19
38
  /** Client sends input to session */
20
39
  export interface InputMessage {
@@ -63,12 +82,97 @@ export interface ErrorMessage {
63
82
  message: string;
64
83
  code?: string;
65
84
  }
85
+ /**
86
+ * One answer a permission ask offers.
87
+ *
88
+ * `id` is opaque and is the only thing an answer may name — a client never
89
+ * sends a decision, it names one of the options it was actually offered, so the
90
+ * offered set stays the single source of truth about what may happen.
91
+ */
92
+ export interface PermissionOption {
93
+ id: string;
94
+ label: string;
95
+ }
96
+ /**
97
+ * Client answers a permission ask (R34-PERM.1).
98
+ *
99
+ * `optionId` must be one of the ids the matching `permission_request` carried;
100
+ * validating that against the immutable offered set is the session's job, not
101
+ * the transport's.
102
+ */
103
+ export interface PermissionResponseMessage {
104
+ type: "permission_response";
105
+ clientId: string;
106
+ requestId: string;
107
+ optionId: string;
108
+ }
109
+ /**
110
+ * Server asks an attached client to decide a permission (R34-PERM.1).
111
+ *
112
+ * Every free-text field here is attacker-influenced — the model chose the
113
+ * command, the path and the tool name — so all of it is neutralized and bounded
114
+ * where this frame is CONSTRUCTED (`safe-text.ts`), never where it is rendered.
115
+ * `truncated` says whether any of it had to be elided, so a surface can show
116
+ * that a decision is being made on an abbreviated string.
117
+ *
118
+ * `deadline` is ADVISORY RENDERING DATA only: it lets a surface draw a countdown.
119
+ * Real expiry binds solely to the session's own fail-closed timer — one clock —
120
+ * and a client that ignores this field changes no outcome.
121
+ */
122
+ export interface PermissionRequestMessage {
123
+ type: "permission_request";
124
+ requestId: string;
125
+ method: "confirm" | "select" | "input";
126
+ toolCallId: string;
127
+ toolName: string;
128
+ cwd: string;
129
+ title: string;
130
+ message: string;
131
+ command?: string;
132
+ path?: string;
133
+ operation?: string;
134
+ truncated: boolean;
135
+ options: PermissionOption[];
136
+ requestedAt: string;
137
+ deadline: string | null;
138
+ }
139
+ /**
140
+ * Server tells every capable client how a permission ask ended (R34-PERM.1).
141
+ *
142
+ * Broadcast after the ask is settled, so a surface that lost the race takes its
143
+ * prompt down and says who decided instead of leaving a dead dialog up.
144
+ * `chosenOptionId` and `clientId` are null for outcomes no client chose —
145
+ * `cancelled` and `expired`.
146
+ *
147
+ * `answered` is the NEUTRAL member (geist/0.4). A `select` or an `input` grants
148
+ * nothing and refuses nothing: no option of theirs declares a `decision`, so
149
+ * neither `approved` nor `denied` is a true thing to say about one, and the two
150
+ * words this wire used before it existed were each false in one direction —
151
+ * `cancelled` about an ask that was answered and whose tool call RAN, `approved`
152
+ * about a grant nobody made. It GRANTS NOTHING and every consumer must read it
153
+ * fail-closed; the choice that was actually made travels as `chosenOptionId`.
154
+ *
155
+ * MIRRORED: `PermissionResolvedFrameSchema.decision` in
156
+ * `packages/geist-protocol/src/wire.ts` is this union field for field, and
157
+ * `MIRRORED_FRAMES` in `scripts/check-geist-protocol.mjs` fails the build if the
158
+ * two sets ever differ — including by one member.
159
+ */
160
+ export interface PermissionResolvedMessage {
161
+ type: "permission_resolved";
162
+ requestId: string;
163
+ decision: "approved" | "denied" | "cancelled" | "expired" | "answered";
164
+ chosenOptionId: string | null;
165
+ surface: string;
166
+ clientId: string | null;
167
+ }
66
168
  /** Connected client state */
67
169
  export interface ConnectedClient {
68
170
  id: string;
69
171
  mode: ClientMode;
70
172
  socket: import("net").Socket;
71
173
  connectedAt: Date;
174
+ /** Exactly what this client declared on attach. Empty for a client that declared nothing. */
175
+ capabilities: string[];
72
176
  }
73
177
  /** Socket session discovery result */
74
178
  export interface SocketSessionInfo {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/socket-server/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,6BAA6B;AAC7B,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,WAAW,CAAC;AAEpD,qCAAqC;AACrC,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,YAAY,GAAG,aAAa,CAAC;AAEzE,qCAAqC;AACrC,MAAM,MAAM,aAAa,GACtB,aAAa,GACb,gBAAgB,GAChB,mBAAmB,GACnB,iBAAiB,GACjB,sBAAsB,GACtB,YAAY,CAAC;AAEhB,gCAAgC;AAChC,MAAM,WAAW,aAAa;IAC7B,IAAI,EA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E,IAAI,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACZ"}
@@ -4,5 +4,17 @@
4
4
  * JSON-based protocol for multi-client session attachment.
5
5
  * Inspired by tmux's multi-attach model.
6
6
  */
7
- export {};
7
+ /**
8
+ * The capability a client declares in its `attach` frame to say it understands
9
+ * permission frames (R34-PERM.1).
10
+ *
11
+ * This is the whole skew story. `permission_request` / `permission_resolved` are
12
+ * sent ONLY to clients that named this, so a bridge built before geist/0.3 —
13
+ * whose attach line carries no `capabilities` at all — never receives a frame it
14
+ * cannot decode, and is therefore never dropped with a `protocol_error
15
+ * unknown_type` and close 1008. Emission is opt-in, not opt-out.
16
+ */
17
+ export const PERMISSION_RELAY_CAPABILITY = "permission-relay";
18
+ /** Every `ClientMode` there is, as a runtime value. `attach` is validated against it. */
19
+ export const CLIENT_MODES = ["read-write", "read-only"];
8
20
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/socket-server/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG","sourcesContent":["/**\n * Socket Server Protocol Types\n *\n * JSON-based protocol for multi-client session attachment.\n * Inspired by tmux's multi-attach model.\n */\n\n/** Client connection mode */\nexport type ClientMode = \"read-write\" | \"read-only\";\n\n/** Message types: Client → Server */\nexport type ClientMessage = AttachMessage | InputMessage | DetachMessage;\n\n/** Message types: Server → Client */\nexport type ServerMessage =\n\t| OutputMessage\n\t| InputEchoMessage\n\t| ClientJoinedMessage\n\t| ClientLeftMessage\n\t| SessionMetadataMessage\n\t| ErrorMessage;\n\n/** Client requests to attach */\nexport interface AttachMessage {\n\ttype: \"attach\";\n\tclientId: string;\n\tmode: ClientMode;\n}\n\n/** Client sends input to session */\nexport interface InputMessage {\n\ttype: \"input\";\n\tdata: string;\n\tclientId: string;\n}\n\n/** Client detaches gracefully */\nexport interface DetachMessage {\n\ttype: \"detach\";\n\tclientId: string;\n}\n\n/** Server broadcasts output */\nexport interface OutputMessage {\n\ttype: \"output\";\n\tdata: string;\n\tstream: \"stdout\" | \"stderr\";\n}\n\n/** Server echoes input from one client to all others */\nexport interface InputEchoMessage {\n\ttype: \"input_echo\";\n\tdata: string;\n\tclientId: string; // Who typed it\n}\n\n/** Server notifies clients when another client joins */\nexport interface ClientJoinedMessage {\n\ttype: \"client_joined\";\n\tclientId: string;\n\tmode: ClientMode;\n}\n\n/** Server notifies clients when another client leaves */\nexport interface ClientLeftMessage {\n\ttype: \"client_left\";\n\tclientId: string;\n}\n\n/** Server sends session metadata on attach */\nexport interface SessionMetadataMessage {\n\ttype: \"session_metadata\";\n\tsessionId: string;\n\tcwd: string;\n\tcreatedAt: string;\n}\n\n/** Server reports an error */\nexport interface ErrorMessage {\n\ttype: \"error\";\n\tmessage: string;\n\tcode?: string;\n}\n\n/** Connected client state */\nexport interface ConnectedClient {\n\tid: string;\n\tmode: ClientMode;\n\tsocket: import(\"net\").Socket;\n\tconnectedAt: Date;\n}\n\n/** Socket session discovery result */\nexport interface SocketSessionInfo {\n\tsessionId: string;\n\tsocketPath: string;\n\tpid: number;\n\tcreatedAt: Date;\n\tcwd: string;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/socket-server/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAAkB,CAAC;AAE9D,yFAAyF;AACzF,MAAM,CAAC,MAAM,YAAY,GAA0B,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC","sourcesContent":["/**\n * Socket Server Protocol Types\n *\n * JSON-based protocol for multi-client session attachment.\n * Inspired by tmux's multi-attach model.\n */\n\n/** Client connection mode */\nexport type ClientMode = \"read-write\" | \"read-only\";\n\n/**\n * The capability a client declares in its `attach` frame to say it understands\n * permission frames (R34-PERM.1).\n *\n * This is the whole skew story. `permission_request` / `permission_resolved` are\n * sent ONLY to clients that named this, so a bridge built before geist/0.3 —\n * whose attach line carries no `capabilities` at all — never receives a frame it\n * cannot decode, and is therefore never dropped with a `protocol_error\n * unknown_type` and close 1008. Emission is opt-in, not opt-out.\n */\nexport const PERMISSION_RELAY_CAPABILITY = \"permission-relay\";\n\n/** Every `ClientMode` there is, as a runtime value. `attach` is validated against it. */\nexport const CLIENT_MODES: readonly ClientMode[] = [\"read-write\", \"read-only\"];\n\n/** Message types: Client → Server */\nexport type ClientMessage = AttachMessage | InputMessage | DetachMessage | PermissionResponseMessage;\n\n/** Message types: Server → Client */\nexport type ServerMessage =\n\t| OutputMessage\n\t| InputEchoMessage\n\t| ClientJoinedMessage\n\t| ClientLeftMessage\n\t| SessionMetadataMessage\n\t| ErrorMessage\n\t| PermissionRequestMessage\n\t| PermissionResolvedMessage;\n\n/** Client requests to attach */\nexport interface AttachMessage {\n\ttype: \"attach\";\n\tclientId: string;\n\tmode: ClientMode;\n\t/**\n\t * What this client understands beyond the frames every client has always\n\t * received. Absent means \"an older client\": it is sent nothing new.\n\t * See {@link PERMISSION_RELAY_CAPABILITY}.\n\t */\n\tcapabilities?: string[];\n}\n\n/** Client sends input to session */\nexport interface InputMessage {\n\ttype: \"input\";\n\tdata: string;\n\tclientId: string;\n}\n\n/** Client detaches gracefully */\nexport interface DetachMessage {\n\ttype: \"detach\";\n\tclientId: string;\n}\n\n/** Server broadcasts output */\nexport interface OutputMessage {\n\ttype: \"output\";\n\tdata: string;\n\tstream: \"stdout\" | \"stderr\";\n}\n\n/** Server echoes input from one client to all others */\nexport interface InputEchoMessage {\n\ttype: \"input_echo\";\n\tdata: string;\n\tclientId: string; // Who typed it\n}\n\n/** Server notifies clients when another client joins */\nexport interface ClientJoinedMessage {\n\ttype: \"client_joined\";\n\tclientId: string;\n\tmode: ClientMode;\n}\n\n/** Server notifies clients when another client leaves */\nexport interface ClientLeftMessage {\n\ttype: \"client_left\";\n\tclientId: string;\n}\n\n/** Server sends session metadata on attach */\nexport interface SessionMetadataMessage {\n\ttype: \"session_metadata\";\n\tsessionId: string;\n\tcwd: string;\n\tcreatedAt: string;\n}\n\n/** Server reports an error */\nexport interface ErrorMessage {\n\ttype: \"error\";\n\tmessage: string;\n\tcode?: string;\n}\n\n/**\n * One answer a permission ask offers.\n *\n * `id` is opaque and is the only thing an answer may name — a client never\n * sends a decision, it names one of the options it was actually offered, so the\n * offered set stays the single source of truth about what may happen.\n */\nexport interface PermissionOption {\n\tid: string;\n\tlabel: string;\n}\n\n/**\n * Client answers a permission ask (R34-PERM.1).\n *\n * `optionId` must be one of the ids the matching `permission_request` carried;\n * validating that against the immutable offered set is the session's job, not\n * the transport's.\n */\nexport interface PermissionResponseMessage {\n\ttype: \"permission_response\";\n\tclientId: string;\n\trequestId: string;\n\toptionId: string;\n}\n\n/**\n * Server asks an attached client to decide a permission (R34-PERM.1).\n *\n * Every free-text field here is attacker-influenced — the model chose the\n * command, the path and the tool name — so all of it is neutralized and bounded\n * where this frame is CONSTRUCTED (`safe-text.ts`), never where it is rendered.\n * `truncated` says whether any of it had to be elided, so a surface can show\n * that a decision is being made on an abbreviated string.\n *\n * `deadline` is ADVISORY RENDERING DATA only: it lets a surface draw a countdown.\n * Real expiry binds solely to the session's own fail-closed timer — one clock —\n * and a client that ignores this field changes no outcome.\n */\nexport interface PermissionRequestMessage {\n\ttype: \"permission_request\";\n\trequestId: string;\n\tmethod: \"confirm\" | \"select\" | \"input\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tcwd: string;\n\ttitle: string;\n\tmessage: string;\n\tcommand?: string;\n\tpath?: string;\n\toperation?: string;\n\ttruncated: boolean;\n\toptions: PermissionOption[];\n\trequestedAt: string;\n\tdeadline: string | null;\n}\n\n/**\n * Server tells every capable client how a permission ask ended (R34-PERM.1).\n *\n * Broadcast after the ask is settled, so a surface that lost the race takes its\n * prompt down and says who decided instead of leaving a dead dialog up.\n * `chosenOptionId` and `clientId` are null for outcomes no client chose —\n * `cancelled` and `expired`.\n *\n * `answered` is the NEUTRAL member (geist/0.4). A `select` or an `input` grants\n * nothing and refuses nothing: no option of theirs declares a `decision`, so\n * neither `approved` nor `denied` is a true thing to say about one, and the two\n * words this wire used before it existed were each false in one direction —\n * `cancelled` about an ask that was answered and whose tool call RAN, `approved`\n * about a grant nobody made. It GRANTS NOTHING and every consumer must read it\n * fail-closed; the choice that was actually made travels as `chosenOptionId`.\n *\n * MIRRORED: `PermissionResolvedFrameSchema.decision` in\n * `packages/geist-protocol/src/wire.ts` is this union field for field, and\n * `MIRRORED_FRAMES` in `scripts/check-geist-protocol.mjs` fails the build if the\n * two sets ever differ — including by one member.\n */\nexport interface PermissionResolvedMessage {\n\ttype: \"permission_resolved\";\n\trequestId: string;\n\tdecision: \"approved\" | \"denied\" | \"cancelled\" | \"expired\" | \"answered\";\n\tchosenOptionId: string | null;\n\tsurface: string;\n\tclientId: string | null;\n}\n\n/** Connected client state */\nexport interface ConnectedClient {\n\tid: string;\n\tmode: ClientMode;\n\tsocket: import(\"net\").Socket;\n\tconnectedAt: Date;\n\t/** Exactly what this client declared on attach. Empty for a client that declared nothing. */\n\tcapabilities: string[];\n}\n\n/** Socket session discovery result */\nexport interface SocketSessionInfo {\n\tsessionId: string;\n\tsocketPath: string;\n\tpid: number;\n\tcreatedAt: Date;\n\tcwd: string;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,WAAW,wBAAwB;IACxC,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,yBAAyB;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,gCAAgC;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,yBAAyB;IACzB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,MAAM,CAiJ3E"}
1
+ {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,WAAW,wBAAwB;IACxC,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,yBAAyB;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,gCAAgC;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,yBAAyB;IACzB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,MAAM,CAqI3E"}
@@ -6,16 +6,12 @@ import { formatSkillsForPrompt } from "./skills.js";
6
6
  /** Build the system prompt with tools, guidelines, and context */
7
7
  export function buildSystemPrompt(options) {
8
8
  const { customPrompt, selectedTools, toolSnippets, promptGuidelines, appendSystemPrompt, cwd, contextFiles: providedContextFiles, skills: providedSkills, } = options;
9
- const resolvedCwd = cwd;
10
- const promptCwd = resolvedCwd.replace(/\\/g, "/");
11
- const now = new Date();
12
- const year = now.getFullYear();
13
- const month = String(now.getMonth() + 1).padStart(2, "0");
14
- const day = String(now.getDate()).padStart(2, "0");
15
- const date = `${year}-${month}-${day}`;
9
+ const promptCwd = cwd.replace(/\\/g, "/");
16
10
  const appendSection = appendSystemPrompt ? `\n\n${appendSystemPrompt}` : "";
17
11
  const contextFiles = providedContextFiles ?? [];
18
12
  const skills = providedSkills ?? [];
13
+ const tools = selectedTools || ["read", "bash", "edit", "write"];
14
+ const skillFileReadTool = ["read", "bash"].find((tool) => tools.includes(tool));
19
15
  if (customPrompt) {
20
16
  let prompt = customPrompt;
21
17
  if (appendSection) {
@@ -30,13 +26,10 @@ export function buildSystemPrompt(options) {
30
26
  }
31
27
  prompt += "</project_context>\n";
32
28
  }
33
- // Append skills section (only if read tool is available)
34
- const customPromptHasRead = !selectedTools || selectedTools.includes("read");
35
- if (customPromptHasRead && skills.length > 0) {
36
- prompt += formatSkillsForPrompt(skills);
29
+ // Append skills when a tool capable of reading their files is available.
30
+ if (skillFileReadTool && skills.length > 0) {
31
+ prompt += formatSkillsForPrompt(skills, skillFileReadTool);
37
32
  }
38
- // Add date and working directory last
39
- prompt += `\nCurrent date: ${date}`;
40
33
  prompt += `\nCurrent working directory: ${promptCwd}`;
41
34
  return prompt;
42
35
  }
@@ -46,7 +39,6 @@ export function buildSystemPrompt(options) {
46
39
  const examplesPath = getExamplesPath();
47
40
  // Build tools list based on selected tools.
48
41
  // A tool appears in Available tools only when the caller provides a one-line snippet.
49
- const tools = selectedTools || ["read", "bash", "edit", "write"];
50
42
  const visibleTools = tools.filter((name) => !!toolSnippets?.[name]);
51
43
  const toolsList = visibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets[name]}`).join("\n") : "(none)";
52
44
  // Build guidelines based on which tools are actually available
@@ -63,7 +55,6 @@ export function buildSystemPrompt(options) {
63
55
  const hasGrep = tools.includes("grep");
64
56
  const hasFind = tools.includes("find");
65
57
  const hasLs = tools.includes("ls");
66
- const hasRead = tools.includes("read");
67
58
  // File exploration guidelines
68
59
  if (hasBash && !hasGrep && !hasFind && !hasLs) {
69
60
  addGuideline("Use bash for file operations like ls, rg, find");
@@ -93,7 +84,7 @@ ${APP_NAME} documentation (read only when the user asks about ${APP_NAME} itself
93
84
  - Additional docs: ${docsPath}
94
85
  - Examples: ${examplesPath} (extensions, custom tools, SDK)
95
86
  - When reading ${APP_NAME} docs or examples, resolve docs/... under Additional docs and examples/... under Examples, not the current working directory
96
- - When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), ${APP_NAME} packages (docs/packages.md)
87
+ - When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), ${APP_NAME} packages (docs/packages.md), environment variables (docs/environment-variables.md)
97
88
  - When working on ${APP_NAME} topics, read the docs and examples, and follow .md cross-references before implementing
98
89
  - Always read ${APP_NAME} .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;
99
90
  if (appendSection) {
@@ -108,12 +99,10 @@ ${APP_NAME} documentation (read only when the user asks about ${APP_NAME} itself
108
99
  }
109
100
  prompt += "</project_context>\n";
110
101
  }
111
- // Append skills section (only if read tool is available)
112
- if (hasRead && skills.length > 0) {
113
- prompt += formatSkillsForPrompt(skills);
102
+ // Append skills when a tool capable of reading their files is available.
103
+ if (skillFileReadTool && skills.length > 0) {
104
+ prompt += formatSkillsForPrompt(skills, skillFileReadTool);
114
105
  }
115
- // Add date and working directory last
116
- prompt += `\nCurrent date: ${date}`;
117
106
  prompt += `\nCurrent working directory: ${promptCwd}`;
118
107
  return prompt;
119
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAqBhE,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,OAAiC;IAClE,MAAM,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,GAAG,EACH,YAAY,EAAE,oBAAoB,EAClC,MAAM,EAAE,cAAc,GACtB,GAAG,OAAO,CAAC;IACZ,MAAM,WAAW,GAAG,GAAG,CAAC;IACxB,MAAM,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAElD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;IAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACnD,MAAM,IAAI,GAAG,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;IAEvC,MAAM,aAAa,GAAG,kBAAkB,CAAC,CAAC,CAAC,OAAO,kBAAkB,EAA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sCAAsC;IACtC,MAAM,IAAI,mBAAmB,IAAI,EAAE,CAAC;IACpC,MAAM,IAAI,gCAAgC,SAAS,EAAE,CAAC;IAEtD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { APP_NAME, getDocsPath, getExamplesPath, getReadmePath } from \"../config.ts\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.ts\";\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. */\n\tcwd: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t} = options;\n\tconst resolvedCwd = cwd;\n\tconst promptCwd = resolvedCwd.replace(/\\\\/g, \"/\");\n\n\tconst now = new Date();\n\tconst year = now.getFullYear();\n\tconst month = String(now.getMonth() + 1).padStart(2, \"0\");\n\tconst day = String(now.getDate()).padStart(2, \"0\");\n\tconst date = `${year}-${month}-${day}`;\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skills = providedSkills ?? [];\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n<project_context>\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `<project_instructions path=\"${filePath}\">\\n${content}\\n</project_instructions>\\n\\n`;\n\t\t\t}\n\t\t\tprompt += \"</project_context>\\n\";\n\t\t}\n\n\t\t// Append skills section (only if read tool is available)\n\t\tconst customPromptHasRead = !selectedTools || selectedTools.includes(\"read\");\n\t\tif (customPromptHasRead && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Add date and working directory last\n\t\tprompt += `\\nCurrent date: ${date}`;\n\t\tprompt += `\\nCurrent working directory: ${promptCwd}`;\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\n\t// Build tools list based on selected tools.\n\t// A tool appears in Available tools only when the caller provides a one-line snippet.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst visibleTools = tools.filter((name) => !!toolSnippets?.[name]);\n\tconst toolsList =\n\t\tvisibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets![name]}`).join(\"\\n\") : \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasGrep = tools.includes(\"grep\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst hasRead = tools.includes(\"read\");\n\n\t// File exploration guidelines\n\tif (hasBash && !hasGrep && !hasFind && !hasLs) {\n\t\taddGuideline(\"Use bash for file operations like ls, rg, find\");\n\t}\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\t// Always include these\n\taddGuideline(\"Be concise in your responses\");\n\taddGuideline(\"Show file paths clearly when working with files\");\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tlet prompt = `You are an expert coding assistant operating inside ${APP_NAME}, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n\n${APP_NAME} documentation (read only when the user asks about ${APP_NAME} itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When reading ${APP_NAME} docs or examples, resolve docs/... under Additional docs and examples/... under Examples, not the current working directory\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), ${APP_NAME} packages (docs/packages.md)\n- When working on ${APP_NAME} topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read ${APP_NAME} .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n<project_context>\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `<project_instructions path=\"${filePath}\">\\n${content}\\n</project_instructions>\\n\\n`;\n\t\t}\n\t\tprompt += \"</project_context>\\n\";\n\t}\n\n\t// Append skills section (only if read tool is available)\n\tif (hasRead && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date and working directory last\n\tprompt += `\\nCurrent date: ${date}`;\n\tprompt += `\\nCurrent working directory: ${promptCwd}`;\n\n\treturn prompt;\n}\n"]}
1
+ {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAqBhE,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,OAAiC;IAClE,MAAM,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,GAAG,EACH,YAAY,EAAE,oBAAoB,EAClC,MAAM,EAAE,cAAc,GACtB,GAAG,OAAO,CAAC;IACZ,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE1C,MAAM,aAAa,GAAG,kBAAkB,CAAC,CAAC,CAAC,OAAO,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAE5E,MAAM,YAAY,GAAG,oBAAoB,IAAI,EAAE,CAAC;IAChD,MAAM,MAAM,GAAG,cAAc,IAAI,EAAE,CAAC;IACpC,MAAM,KAAK,GAAG,aAAa,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACjE,MAAM,iBAAiB,GAAI,CAAC,MAAM,EAAE,MAAM,CAAW,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI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CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAElE,IAAI,MAAM,GAAG,uDAAuD,QAAQ;;;EAG3E,SAAS;;;;;EAKT,UAAU;;EAEV,QAAQ,sDAAsD,QAAQ;wBAChD,UAAU;qBACb,QAAQ;cACf,YAAY;iBACT,QAAQ;yVACgU,QAAQ;oBAC7U,QAAQ;gBACZ,QAAQ,2FAA2F,CAAC;IAEnH,IAAI,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,aAAa,CAAC;IACzB,CAAC;IAED,+BAA+B;IAC/B,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,2BAA2B,CAAC;QACtC,MAAM,IAAI,mDAAmD,CAAC;QAC9D,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;YACxD,MAAM,IAAI,+BAA+B,QAAQ,OAAO,OAAO,+BAA+B,CAAC;QAChG,CAAC;QACD,MAAM,IAAI,sBAAsB,CAAC;IAClC,CAAC;IAED,yEAAyE;IACzE,IAAI,iBAAiB,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,IAAI,gCAAgC,SAAS,EAAE,CAAC;IAEtD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { APP_NAME, getDocsPath, getExamplesPath, getReadmePath } from \"../config.ts\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.ts\";\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. */\n\tcwd: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t} = options;\n\tconst promptCwd = cwd.replace(/\\\\/g, \"/\");\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skills = providedSkills ?? [];\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst skillFileReadTool = ([\"read\", \"bash\"] as const).find((tool) => tools.includes(tool));\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n<project_context>\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `<project_instructions path=\"${filePath}\">\\n${content}\\n</project_instructions>\\n\\n`;\n\t\t\t}\n\t\t\tprompt += \"</project_context>\\n\";\n\t\t}\n\n\t\t// Append skills when a tool capable of reading their files is available.\n\t\tif (skillFileReadTool && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills, skillFileReadTool);\n\t\t}\n\n\t\tprompt += `\\nCurrent working directory: ${promptCwd}`;\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\n\t// Build tools list based on selected tools.\n\t// A tool appears in Available tools only when the caller provides a one-line snippet.\n\tconst visibleTools = tools.filter((name) => !!toolSnippets?.[name]);\n\tconst toolsList =\n\t\tvisibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets![name]}`).join(\"\\n\") : \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasGrep = tools.includes(\"grep\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\n\t// File exploration guidelines\n\tif (hasBash && !hasGrep && !hasFind && !hasLs) {\n\t\taddGuideline(\"Use bash for file operations like ls, rg, find\");\n\t}\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\t// Always include these\n\taddGuideline(\"Be concise in your responses\");\n\taddGuideline(\"Show file paths clearly when working with files\");\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tlet prompt = `You are an expert coding assistant operating inside ${APP_NAME}, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n\n${APP_NAME} documentation (read only when the user asks about ${APP_NAME} itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When reading ${APP_NAME} docs or examples, resolve docs/... under Additional docs and examples/... under Examples, not the current working directory\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), ${APP_NAME} packages (docs/packages.md), environment variables (docs/environment-variables.md)\n- When working on ${APP_NAME} topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read ${APP_NAME} .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n<project_context>\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `<project_instructions path=\"${filePath}\">\\n${content}\\n</project_instructions>\\n\\n`;\n\t\t}\n\t\tprompt += \"</project_context>\\n\";\n\t}\n\n\t// Append skills when a tool capable of reading their files is available.\n\tif (skillFileReadTool && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills, skillFileReadTool);\n\t}\n\n\tprompt += `\\nCurrent working directory: ${promptCwd}`;\n\n\treturn prompt;\n}\n"]}
@@ -21,7 +21,7 @@ export interface BashOperations {
21
21
  * @param command The command to execute
22
22
  * @param cwd Working directory
23
23
  * @param options Execution options
24
- * @returns Promise resolving to exit code (null if killed)
24
+ * @returns Promise resolving to exit code; 128 + signal number when killed by a signal, null when no exit status is known
25
25
  */
26
26
  exec: (command: string, cwd: string, options: {
27
27
  onData: (data: Buffer) => void;
@@ -54,6 +54,8 @@ export interface BashToolOptions {
54
54
  commandPrefix?: string;
55
55
  /** Optional explicit shell path from settings */
56
56
  shellPath?: string;
57
+ /** Expose current draht session metadata as DRAHT_* environment variables. Default: true */
58
+ exposeSessionEnvironment?: boolean;
57
59
  /** Hook to adjust command, cwd, or env before execution */
58
60
  spawnHook?: BashSpawnHook;
59
61
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGnD,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAY5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAItF,OAAO,EAAoD,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAkBxG,QAAA,MAAM,UAAU;;;EAGd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B;;;;;;OAMG;IACH,IAAI,EAAE,CACL,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;QACR,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;QAC/B,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;KACxB,KACG,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;CAC1C;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,cAAc,CAkE1F;AAED,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAA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