@draht/coding-agent 2026.7.13 → 2026.9.5-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (614) hide show
  1. package/CHANGELOG.md +241 -0
  2. package/README.md +47 -2
  3. package/agents/debugger.md +12 -1
  4. package/agents/git-committer.md +1 -0
  5. package/agents/implementer.md +20 -0
  6. package/agents/investigator.md +75 -0
  7. package/agents/reviewer.md +7 -0
  8. package/agents/spec-reviewer.md +66 -0
  9. package/agents/verifier.md +4 -3
  10. package/bin/draht-tools.cjs +472 -41
  11. package/dist/agents/debugger.md +12 -1
  12. package/dist/agents/git-committer.md +1 -0
  13. package/dist/agents/implementer.md +20 -0
  14. package/dist/agents/investigator.md +75 -0
  15. package/dist/agents/reviewer.md +7 -0
  16. package/dist/agents/spec-reviewer.md +66 -0
  17. package/dist/agents/verifier.md +4 -3
  18. package/dist/bun/cli.js +2 -0
  19. package/dist/bun/cli.js.map +1 -1
  20. package/dist/cli/args.d.ts +10 -0
  21. package/dist/cli/args.d.ts.map +1 -1
  22. package/dist/cli/args.js +80 -3
  23. package/dist/cli/args.js.map +1 -1
  24. package/dist/cli/attach-mode.d.ts +61 -0
  25. package/dist/cli/attach-mode.d.ts.map +1 -1
  26. package/dist/cli/attach-mode.js +243 -5
  27. package/dist/cli/attach-mode.js.map +1 -1
  28. package/dist/cli/config-selector.js +1 -1
  29. package/dist/cli/config-selector.js.map +1 -1
  30. package/dist/cli/credential-print.d.ts +23 -0
  31. package/dist/cli/credential-print.d.ts.map +1 -0
  32. package/dist/cli/credential-print.js +117 -0
  33. package/dist/cli/credential-print.js.map +1 -0
  34. package/dist/cli/list-models.d.ts +2 -2
  35. package/dist/cli/list-models.d.ts.map +1 -1
  36. package/dist/cli/list-models.js +3 -3
  37. package/dist/cli/list-models.js.map +1 -1
  38. package/dist/cli/startup-ui.js +1 -1
  39. package/dist/cli/startup-ui.js.map +1 -1
  40. package/dist/config.d.ts +9 -0
  41. package/dist/config.d.ts.map +1 -1
  42. package/dist/config.js +31 -4
  43. package/dist/config.js.map +1 -1
  44. package/dist/core/agent-session-runtime.d.ts +17 -1
  45. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  46. package/dist/core/agent-session-runtime.js +90 -30
  47. package/dist/core/agent-session-runtime.js.map +1 -1
  48. package/dist/core/agent-session-services.d.ts +4 -7
  49. package/dist/core/agent-session-services.d.ts.map +1 -1
  50. package/dist/core/agent-session-services.js +24 -9
  51. package/dist/core/agent-session-services.js.map +1 -1
  52. package/dist/core/agent-session.d.ts +87 -27
  53. package/dist/core/agent-session.d.ts.map +1 -1
  54. package/dist/core/agent-session.js +337 -154
  55. package/dist/core/agent-session.js.map +1 -1
  56. package/dist/core/auth-storage.d.ts +20 -104
  57. package/dist/core/auth-storage.d.ts.map +1 -1
  58. package/dist/core/auth-storage.js +104 -260
  59. package/dist/core/auth-storage.js.map +1 -1
  60. package/dist/core/builtins/checkpoints.d.ts +20 -0
  61. package/dist/core/builtins/checkpoints.d.ts.map +1 -0
  62. package/dist/core/builtins/checkpoints.js +161 -0
  63. package/dist/core/builtins/checkpoints.js.map +1 -0
  64. package/dist/core/builtins/duet.d.ts +26 -0
  65. package/dist/core/builtins/duet.d.ts.map +1 -0
  66. package/dist/core/builtins/duet.js +660 -0
  67. package/dist/core/builtins/duet.js.map +1 -0
  68. package/dist/core/builtins/index.d.ts.map +1 -1
  69. package/dist/core/builtins/index.js +7 -1
  70. package/dist/core/builtins/index.js.map +1 -1
  71. package/dist/core/builtins/subagent.d.ts +24 -4
  72. package/dist/core/builtins/subagent.d.ts.map +1 -1
  73. package/dist/core/builtins/subagent.js +278 -35
  74. package/dist/core/builtins/subagent.js.map +1 -1
  75. package/dist/core/cache-stats.d.ts +2 -2
  76. package/dist/core/cache-stats.d.ts.map +1 -1
  77. package/dist/core/cache-stats.js +1 -1
  78. package/dist/core/cache-stats.js.map +1 -1
  79. package/dist/core/checkpoints/checkpoint-cli.d.ts +17 -0
  80. package/dist/core/checkpoints/checkpoint-cli.d.ts.map +1 -0
  81. package/dist/core/checkpoints/checkpoint-cli.js +78 -0
  82. package/dist/core/checkpoints/checkpoint-cli.js.map +1 -0
  83. package/dist/core/checkpoints/checkpoint-manager.d.ts +294 -0
  84. package/dist/core/checkpoints/checkpoint-manager.d.ts.map +1 -0
  85. package/dist/core/checkpoints/checkpoint-manager.js +865 -0
  86. package/dist/core/checkpoints/checkpoint-manager.js.map +1 -0
  87. package/dist/core/checkpoints/rewind.d.ts +141 -0
  88. package/dist/core/checkpoints/rewind.d.ts.map +1 -0
  89. package/dist/core/checkpoints/rewind.js +246 -0
  90. package/dist/core/checkpoints/rewind.js.map +1 -0
  91. package/dist/core/compaction/branch-summarization.d.ts +9 -3
  92. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  93. package/dist/core/compaction/branch-summarization.js +16 -14
  94. package/dist/core/compaction/branch-summarization.js.map +1 -1
  95. package/dist/core/compaction/compaction.d.ts +24 -3
  96. package/dist/core/compaction/compaction.d.ts.map +1 -1
  97. package/dist/core/compaction/compaction.js +96 -30
  98. package/dist/core/compaction/compaction.js.map +1 -1
  99. package/dist/core/compaction/utils.d.ts +1 -1
  100. package/dist/core/compaction/utils.d.ts.map +1 -1
  101. package/dist/core/compaction/utils.js +6 -17
  102. package/dist/core/compaction/utils.js.map +1 -1
  103. package/dist/core/context-windows.d.ts +7 -0
  104. package/dist/core/context-windows.d.ts.map +1 -0
  105. package/dist/core/context-windows.js +35 -0
  106. package/dist/core/context-windows.js.map +1 -0
  107. package/dist/core/extensions/index.d.ts +1 -1
  108. package/dist/core/extensions/index.d.ts.map +1 -1
  109. package/dist/core/extensions/index.js.map +1 -1
  110. package/dist/core/extensions/loader.d.ts.map +1 -1
  111. package/dist/core/extensions/loader.js +101 -23
  112. package/dist/core/extensions/loader.js.map +1 -1
  113. package/dist/core/extensions/runner.d.ts +19 -3
  114. package/dist/core/extensions/runner.d.ts.map +1 -1
  115. package/dist/core/extensions/runner.js +117 -2
  116. package/dist/core/extensions/runner.js.map +1 -1
  117. package/dist/core/extensions/types.d.ts +236 -9
  118. package/dist/core/extensions/types.d.ts.map +1 -1
  119. package/dist/core/extensions/types.js.map +1 -1
  120. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  121. package/dist/core/extensions/wrapper.js +22 -3
  122. package/dist/core/extensions/wrapper.js.map +1 -1
  123. package/dist/core/footer-data-provider.d.ts +10 -0
  124. package/dist/core/footer-data-provider.d.ts.map +1 -1
  125. package/dist/core/footer-data-provider.js +1 -1
  126. package/dist/core/footer-data-provider.js.map +1 -1
  127. package/dist/core/http-dispatcher.d.ts.map +1 -1
  128. package/dist/core/http-dispatcher.js +7 -0
  129. package/dist/core/http-dispatcher.js.map +1 -1
  130. package/dist/core/index.d.ts +1 -1
  131. package/dist/core/index.d.ts.map +1 -1
  132. package/dist/core/index.js.map +1 -1
  133. package/dist/core/keybindings.d.ts +18 -3
  134. package/dist/core/keybindings.d.ts.map +1 -1
  135. package/dist/core/keybindings.js +12 -3
  136. package/dist/core/keybindings.js.map +1 -1
  137. package/dist/core/model-config.d.ts +542 -0
  138. package/dist/core/model-config.d.ts.map +1 -0
  139. package/dist/core/model-config.js +247 -0
  140. package/dist/core/model-config.js.map +1 -0
  141. package/dist/core/model-registry.d.ts +19 -124
  142. package/dist/core/model-registry.d.ts.map +1 -1
  143. package/dist/core/model-registry.js +56 -727
  144. package/dist/core/model-registry.js.map +1 -1
  145. package/dist/core/model-resolver.d.ts +7 -6
  146. package/dist/core/model-resolver.d.ts.map +1 -1
  147. package/dist/core/model-resolver.js +74 -27
  148. package/dist/core/model-resolver.js.map +1 -1
  149. package/dist/core/model-runtime.d.ts +89 -0
  150. package/dist/core/model-runtime.d.ts.map +1 -0
  151. package/dist/core/model-runtime.js +451 -0
  152. package/dist/core/model-runtime.js.map +1 -0
  153. package/dist/core/models-store.d.ts +17 -0
  154. package/dist/core/models-store.d.ts.map +1 -0
  155. package/dist/core/models-store.js +46 -0
  156. package/dist/core/models-store.js.map +1 -0
  157. package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
  158. package/dist/core/multi-agent/permission-gate.js +4 -3
  159. package/dist/core/multi-agent/permission-gate.js.map +1 -1
  160. package/dist/core/multi-agent/worktree.d.ts +2 -0
  161. package/dist/core/multi-agent/worktree.d.ts.map +1 -1
  162. package/dist/core/multi-agent/worktree.js +2 -2
  163. package/dist/core/multi-agent/worktree.js.map +1 -1
  164. package/dist/core/package-manager.d.ts +7 -1
  165. package/dist/core/package-manager.d.ts.map +1 -1
  166. package/dist/core/package-manager.js +41 -45
  167. package/dist/core/package-manager.js.map +1 -1
  168. package/dist/core/permission-relay/index.d.ts +19 -0
  169. package/dist/core/permission-relay/index.d.ts.map +1 -0
  170. package/dist/core/permission-relay/index.js +49 -0
  171. package/dist/core/permission-relay/index.js.map +1 -0
  172. package/dist/core/permission-relay/relay-ui-context.d.ts +39 -0
  173. package/dist/core/permission-relay/relay-ui-context.d.ts.map +1 -0
  174. package/dist/core/permission-relay/relay-ui-context.js +788 -0
  175. package/dist/core/permission-relay/relay-ui-context.js.map +1 -0
  176. package/dist/core/permission-relay/types.d.ts +222 -0
  177. package/dist/core/permission-relay/types.d.ts.map +1 -0
  178. package/dist/core/permission-relay/types.js +15 -0
  179. package/dist/core/permission-relay/types.js.map +1 -0
  180. package/dist/core/pi-manifest.d.ts +14 -0
  181. package/dist/core/pi-manifest.d.ts.map +1 -0
  182. package/dist/core/pi-manifest.js +35 -0
  183. package/dist/core/pi-manifest.js.map +1 -0
  184. package/dist/core/project-trust.js +2 -2
  185. package/dist/core/project-trust.js.map +1 -1
  186. package/dist/core/prompt-templates.d.ts +1 -0
  187. package/dist/core/prompt-templates.d.ts.map +1 -1
  188. package/dist/core/prompt-templates.js +4 -4
  189. package/dist/core/prompt-templates.js.map +1 -1
  190. package/dist/core/provider-composer.d.ts +55 -0
  191. package/dist/core/provider-composer.d.ts.map +1 -0
  192. package/dist/core/provider-composer.js +375 -0
  193. package/dist/core/provider-composer.js.map +1 -0
  194. package/dist/core/radius.d.ts +2 -0
  195. package/dist/core/radius.d.ts.map +1 -0
  196. package/dist/core/radius.js +2 -0
  197. package/dist/core/radius.js.map +1 -0
  198. package/dist/core/remote-catalog-provider.d.ts +5 -0
  199. package/dist/core/remote-catalog-provider.d.ts.map +1 -0
  200. package/dist/core/remote-catalog-provider.js +115 -0
  201. package/dist/core/remote-catalog-provider.js.map +1 -0
  202. package/dist/core/resource-loader.d.ts +36 -0
  203. package/dist/core/resource-loader.d.ts.map +1 -1
  204. package/dist/core/resource-loader.js +159 -27
  205. package/dist/core/resource-loader.js.map +1 -1
  206. package/dist/core/runtime-credentials.d.ts +15 -0
  207. package/dist/core/runtime-credentials.d.ts.map +1 -0
  208. package/dist/core/runtime-credentials.js +35 -0
  209. package/dist/core/runtime-credentials.js.map +1 -0
  210. package/dist/core/sandbox/bash-operations.d.ts +149 -0
  211. package/dist/core/sandbox/bash-operations.d.ts.map +1 -0
  212. package/dist/core/sandbox/bash-operations.js +163 -0
  213. package/dist/core/sandbox/bash-operations.js.map +1 -0
  214. package/dist/core/sandbox/env.d.ts +83 -0
  215. package/dist/core/sandbox/env.d.ts.map +1 -0
  216. package/dist/core/sandbox/env.js +123 -0
  217. package/dist/core/sandbox/env.js.map +1 -0
  218. package/dist/core/sandbox/executor.d.ts +104 -0
  219. package/dist/core/sandbox/executor.d.ts.map +1 -0
  220. package/dist/core/sandbox/executor.js +92 -0
  221. package/dist/core/sandbox/executor.js.map +1 -0
  222. package/dist/core/sandbox/index.d.ts +36 -0
  223. package/dist/core/sandbox/index.d.ts.map +1 -0
  224. package/dist/core/sandbox/index.js +36 -0
  225. package/dist/core/sandbox/index.js.map +1 -0
  226. package/dist/core/sandbox/linux.d.ts +121 -0
  227. package/dist/core/sandbox/linux.d.ts.map +1 -0
  228. package/dist/core/sandbox/linux.js +260 -0
  229. package/dist/core/sandbox/linux.js.map +1 -0
  230. package/dist/core/sandbox/policy.d.ts +142 -0
  231. package/dist/core/sandbox/policy.d.ts.map +1 -0
  232. package/dist/core/sandbox/policy.js +297 -0
  233. package/dist/core/sandbox/policy.js.map +1 -0
  234. package/dist/core/sandbox/real-path.d.ts +112 -0
  235. package/dist/core/sandbox/real-path.d.ts.map +1 -0
  236. package/dist/core/sandbox/real-path.js +158 -0
  237. package/dist/core/sandbox/real-path.js.map +1 -0
  238. package/dist/core/sandbox/seatbelt-profile.d.ts +95 -0
  239. package/dist/core/sandbox/seatbelt-profile.d.ts.map +1 -0
  240. package/dist/core/sandbox/seatbelt-profile.js +239 -0
  241. package/dist/core/sandbox/seatbelt-profile.js.map +1 -0
  242. package/dist/core/sandbox/seatbelt.d.ts +95 -0
  243. package/dist/core/sandbox/seatbelt.d.ts.map +1 -0
  244. package/dist/core/sandbox/seatbelt.js +154 -0
  245. package/dist/core/sandbox/seatbelt.js.map +1 -0
  246. package/dist/core/sandbox/self-test.d.ts +109 -0
  247. package/dist/core/sandbox/self-test.d.ts.map +1 -0
  248. package/dist/core/sandbox/self-test.js +369 -0
  249. package/dist/core/sandbox/self-test.js.map +1 -0
  250. package/dist/core/sandbox/spawn.d.ts +33 -0
  251. package/dist/core/sandbox/spawn.d.ts.map +1 -0
  252. package/dist/core/sandbox/spawn.js +87 -0
  253. package/dist/core/sandbox/spawn.js.map +1 -0
  254. package/dist/core/sdk.d.ts +3 -6
  255. package/dist/core/sdk.d.ts.map +1 -1
  256. package/dist/core/sdk.js +25 -22
  257. package/dist/core/sdk.js.map +1 -1
  258. package/dist/core/session-manager.d.ts +74 -7
  259. package/dist/core/session-manager.d.ts.map +1 -1
  260. package/dist/core/session-manager.js +169 -34
  261. package/dist/core/session-manager.js.map +1 -1
  262. package/dist/core/settings-manager.d.ts +22 -1
  263. package/dist/core/settings-manager.d.ts.map +1 -1
  264. package/dist/core/settings-manager.js +36 -16
  265. package/dist/core/settings-manager.js.map +1 -1
  266. package/dist/core/skills.d.ts +3 -1
  267. package/dist/core/skills.d.ts.map +1 -1
  268. package/dist/core/skills.js +19 -6
  269. package/dist/core/skills.js.map +1 -1
  270. package/dist/core/slash-commands.d.ts.map +1 -1
  271. package/dist/core/slash-commands.js +1 -0
  272. package/dist/core/slash-commands.js.map +1 -1
  273. package/dist/core/soak/soak-log.d.ts +298 -0
  274. package/dist/core/soak/soak-log.d.ts.map +1 -0
  275. package/dist/core/soak/soak-log.js +660 -0
  276. package/dist/core/soak/soak-log.js.map +1 -0
  277. package/dist/core/soak/soak-reader.d.ts +60 -0
  278. package/dist/core/soak/soak-reader.d.ts.map +1 -0
  279. package/dist/core/soak/soak-reader.js +106 -0
  280. package/dist/core/soak/soak-reader.js.map +1 -0
  281. package/dist/core/socket-server/discovery.d.ts +78 -1
  282. package/dist/core/socket-server/discovery.d.ts.map +1 -1
  283. package/dist/core/socket-server/discovery.js +356 -37
  284. package/dist/core/socket-server/discovery.js.map +1 -1
  285. package/dist/core/socket-server/index.d.ts +10 -4
  286. package/dist/core/socket-server/index.d.ts.map +1 -1
  287. package/dist/core/socket-server/index.js +6 -3
  288. package/dist/core/socket-server/index.js.map +1 -1
  289. package/dist/core/socket-server/permission-delivery.d.ts +125 -0
  290. package/dist/core/socket-server/permission-delivery.d.ts.map +1 -0
  291. package/dist/core/socket-server/permission-delivery.js +152 -0
  292. package/dist/core/socket-server/permission-delivery.js.map +1 -0
  293. package/dist/core/socket-server/permission-registry.d.ts +301 -0
  294. package/dist/core/socket-server/permission-registry.d.ts.map +1 -0
  295. package/dist/core/socket-server/permission-registry.js +410 -0
  296. package/dist/core/socket-server/permission-registry.js.map +1 -0
  297. package/dist/core/socket-server/permission-relay.d.ts +81 -0
  298. package/dist/core/socket-server/permission-relay.d.ts.map +1 -0
  299. package/dist/core/socket-server/permission-relay.js +528 -0
  300. package/dist/core/socket-server/permission-relay.js.map +1 -0
  301. package/dist/core/socket-server/safe-text.d.ts +83 -0
  302. package/dist/core/socket-server/safe-text.d.ts.map +1 -0
  303. package/dist/core/socket-server/safe-text.js +277 -0
  304. package/dist/core/socket-server/safe-text.js.map +1 -0
  305. package/dist/core/socket-server/session-integration.d.ts +65 -2
  306. package/dist/core/socket-server/session-integration.d.ts.map +1 -1
  307. package/dist/core/socket-server/session-integration.js +434 -32
  308. package/dist/core/socket-server/session-integration.js.map +1 -1
  309. package/dist/core/socket-server/socket-client.d.ts +21 -2
  310. package/dist/core/socket-server/socket-client.d.ts.map +1 -1
  311. package/dist/core/socket-server/socket-client.js +52 -1
  312. package/dist/core/socket-server/socket-client.js.map +1 -1
  313. package/dist/core/socket-server/socket-server.d.ts +152 -1
  314. package/dist/core/socket-server/socket-server.d.ts.map +1 -1
  315. package/dist/core/socket-server/socket-server.js +775 -26
  316. package/dist/core/socket-server/socket-server.js.map +1 -1
  317. package/dist/core/socket-server/types.d.ts +106 -2
  318. package/dist/core/socket-server/types.d.ts.map +1 -1
  319. package/dist/core/socket-server/types.js +13 -1
  320. package/dist/core/socket-server/types.js.map +1 -1
  321. package/dist/core/system-prompt.d.ts.map +1 -1
  322. package/dist/core/system-prompt.js +10 -21
  323. package/dist/core/system-prompt.js.map +1 -1
  324. package/dist/core/tools/bash.d.ts +3 -1
  325. package/dist/core/tools/bash.d.ts.map +1 -1
  326. package/dist/core/tools/bash.js +39 -7
  327. package/dist/core/tools/bash.js.map +1 -1
  328. package/dist/core/tools/edit.d.ts.map +1 -1
  329. package/dist/core/tools/edit.js +17 -2
  330. package/dist/core/tools/edit.js.map +1 -1
  331. package/dist/core/tools/find.d.ts +3 -0
  332. package/dist/core/tools/find.d.ts.map +1 -1
  333. package/dist/core/tools/find.js +11 -18
  334. package/dist/core/tools/find.js.map +1 -1
  335. package/dist/core/tools/read.js +1 -1
  336. package/dist/core/tools/read.js.map +1 -1
  337. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  338. package/dist/core/tools/tool-definition-wrapper.js +3 -1
  339. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  340. package/dist/core/trust-manager.d.ts +6 -4
  341. package/dist/core/trust-manager.d.ts.map +1 -1
  342. package/dist/core/trust-manager.js +55 -21
  343. package/dist/core/trust-manager.js.map +1 -1
  344. package/dist/core/usage-totals.d.ts +19 -0
  345. package/dist/core/usage-totals.d.ts.map +1 -0
  346. package/dist/core/usage-totals.js +52 -0
  347. package/dist/core/usage-totals.js.map +1 -0
  348. package/dist/extensions/index.d.ts +3 -0
  349. package/dist/extensions/index.d.ts.map +1 -0
  350. package/dist/extensions/index.js +7 -0
  351. package/dist/extensions/index.js.map +1 -0
  352. package/dist/extensions/llama/client.d.ts +61 -0
  353. package/dist/extensions/llama/client.d.ts.map +1 -0
  354. package/dist/extensions/llama/client.js +300 -0
  355. package/dist/extensions/llama/client.js.map +1 -0
  356. package/dist/extensions/llama/huggingface.d.ts +23 -0
  357. package/dist/extensions/llama/huggingface.d.ts.map +1 -0
  358. package/dist/extensions/llama/huggingface.js +139 -0
  359. package/dist/extensions/llama/huggingface.js.map +1 -0
  360. package/dist/extensions/llama/index.d.ts +3 -0
  361. package/dist/extensions/llama/index.d.ts.map +1 -0
  362. package/dist/extensions/llama/index.js +208 -0
  363. package/dist/extensions/llama/index.js.map +1 -0
  364. package/dist/extensions/llama/provider.d.ts +10 -0
  365. package/dist/extensions/llama/provider.d.ts.map +1 -0
  366. package/dist/extensions/llama/provider.js +111 -0
  367. package/dist/extensions/llama/provider.js.map +1 -0
  368. package/dist/extensions/llama/ui.d.ts +42 -0
  369. package/dist/extensions/llama/ui.d.ts.map +1 -0
  370. package/dist/extensions/llama/ui.js +400 -0
  371. package/dist/extensions/llama/ui.js.map +1 -0
  372. package/dist/extensions/stub-provider/index.d.ts +9 -0
  373. package/dist/extensions/stub-provider/index.d.ts.map +1 -0
  374. package/dist/extensions/stub-provider/index.js +13 -0
  375. package/dist/extensions/stub-provider/index.js.map +1 -0
  376. package/dist/extensions/stub-provider/provider.d.ts +77 -0
  377. package/dist/extensions/stub-provider/provider.d.ts.map +1 -0
  378. package/dist/extensions/stub-provider/provider.js +193 -0
  379. package/dist/extensions/stub-provider/provider.js.map +1 -0
  380. package/dist/hooks/gsd/draht-quality-gate.js +3 -3
  381. package/dist/index.d.ts +4 -3
  382. package/dist/index.d.ts.map +1 -1
  383. package/dist/index.js +3 -3
  384. package/dist/index.js.map +1 -1
  385. package/dist/main.d.ts.map +1 -1
  386. package/dist/main.js +305 -61
  387. package/dist/main.js.map +1 -1
  388. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  389. package/dist/modes/interactive/components/assistant-message.js +22 -10
  390. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  391. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  392. package/dist/modes/interactive/components/config-selector.js +3 -2
  393. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  394. package/dist/modes/interactive/components/custom-editor.js +1 -1
  395. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  396. package/dist/modes/interactive/components/custom-message.d.ts +3 -1
  397. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  398. package/dist/modes/interactive/components/custom-message.js +9 -2
  399. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  400. package/dist/modes/interactive/components/extension-editor.d.ts +1 -2
  401. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  402. package/dist/modes/interactive/components/extension-editor.js +16 -46
  403. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  404. package/dist/modes/interactive/components/extension-selector.d.ts +49 -0
  405. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  406. package/dist/modes/interactive/components/extension-selector.js +202 -5
  407. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  408. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  409. package/dist/modes/interactive/components/footer.js +24 -23
  410. package/dist/modes/interactive/components/footer.js.map +1 -1
  411. package/dist/modes/interactive/components/login-dialog.d.ts +5 -5
  412. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  413. package/dist/modes/interactive/components/login-dialog.js +17 -8
  414. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  415. package/dist/modes/interactive/components/model-selector.d.ts +11 -4
  416. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  417. package/dist/modes/interactive/components/model-selector.js +74 -41
  418. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  419. package/dist/modes/interactive/components/oauth-selector.d.ts +4 -4
  420. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  421. package/dist/modes/interactive/components/oauth-selector.js +14 -25
  422. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  423. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  424. package/dist/modes/interactive/components/scoped-models-selector.js +22 -13
  425. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  426. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  427. package/dist/modes/interactive/components/session-selector.js +10 -2
  428. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  429. package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
  430. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  431. package/dist/modes/interactive/components/settings-selector.js +10 -0
  432. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  433. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  434. package/dist/modes/interactive/components/tool-execution.js +10 -1
  435. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  436. package/dist/modes/interactive/components/tree-selector.d.ts +25 -2
  437. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  438. package/dist/modes/interactive/components/tree-selector.js +68 -17
  439. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  440. package/dist/modes/interactive/external-editor.d.ts +12 -0
  441. package/dist/modes/interactive/external-editor.d.ts.map +1 -0
  442. package/dist/modes/interactive/external-editor.js +37 -0
  443. package/dist/modes/interactive/external-editor.js.map +1 -0
  444. package/dist/modes/interactive/interactive-mode.d.ts +107 -10
  445. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  446. package/dist/modes/interactive/interactive-mode.js +763 -285
  447. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  448. package/dist/modes/rpc/rpc-client.d.ts +4 -0
  449. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  450. package/dist/modes/rpc/rpc-client.js +7 -0
  451. package/dist/modes/rpc/rpc-client.js.map +1 -1
  452. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  453. package/dist/modes/rpc/rpc-mode.js +185 -9
  454. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  455. package/dist/modes/rpc/rpc-types.d.ts +79 -1
  456. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  457. package/dist/modes/rpc/rpc-types.js.map +1 -1
  458. package/dist/package-manager-cli.d.ts.map +1 -1
  459. package/dist/package-manager-cli.js +67 -5
  460. package/dist/package-manager-cli.js.map +1 -1
  461. package/dist/prompts/commands/atomic-commit.md +1 -12
  462. package/dist/prompts/commands/brainstorm.md +12 -15
  463. package/dist/prompts/commands/create-verification-skill.md +108 -0
  464. package/dist/prompts/commands/discuss-phase.md +3 -14
  465. package/dist/prompts/commands/execute-phase.md +3 -11
  466. package/dist/prompts/commands/fix.md +41 -18
  467. package/dist/prompts/commands/grill.md +66 -0
  468. package/dist/prompts/commands/init-project.md +5 -15
  469. package/dist/prompts/commands/map-codebase.md +1 -13
  470. package/dist/prompts/commands/new-project.md +5 -15
  471. package/dist/prompts/commands/next-milestone.md +1 -13
  472. package/dist/prompts/commands/orchestrate.md +1 -1
  473. package/dist/prompts/commands/pause-work.md +1 -13
  474. package/dist/prompts/commands/plan-phase.md +2 -11
  475. package/dist/prompts/commands/progress.md +0 -13
  476. package/dist/prompts/commands/quick.md +3 -11
  477. package/dist/prompts/commands/resolve-conflicts.md +71 -0
  478. package/dist/prompts/commands/resume-work.md +0 -13
  479. package/dist/prompts/commands/review.md +4 -13
  480. package/dist/prompts/commands/triage.md +159 -0
  481. package/dist/prompts/commands/verify-work.md +4 -14
  482. package/dist/prompts/commands/why.md +135 -0
  483. package/dist/skills/atomic-reasoning/SKILL.md +115 -0
  484. package/dist/skills/blast-radius/SKILL.md +55 -0
  485. package/dist/skills/epistemics/SKILL.md +99 -0
  486. package/dist/skills/hexagon-animation/SKILL.md +49 -0
  487. package/dist/skills/hexagon-animation/generate.mjs +81 -0
  488. package/dist/skills/hexagon-animation/template.html +361 -0
  489. package/dist/skills/typescript-discipline/SKILL.md +50 -0
  490. package/dist/skills/typescript-discipline/references/patterns.md +294 -0
  491. package/dist/skills/unslop/SKILL.md +101 -0
  492. package/dist/utils/canonical-path.d.ts +28 -0
  493. package/dist/utils/canonical-path.d.ts.map +1 -0
  494. package/dist/utils/canonical-path.js +90 -0
  495. package/dist/utils/canonical-path.js.map +1 -0
  496. package/dist/utils/child-process.d.ts +12 -1
  497. package/dist/utils/child-process.d.ts.map +1 -1
  498. package/dist/utils/child-process.js +25 -8
  499. package/dist/utils/child-process.js.map +1 -1
  500. package/dist/utils/clipboard-native.d.ts +1 -0
  501. package/dist/utils/clipboard-native.d.ts.map +1 -1
  502. package/dist/utils/clipboard-native.js.map +1 -1
  503. package/dist/utils/clipboard.d.ts +2 -0
  504. package/dist/utils/clipboard.d.ts.map +1 -1
  505. package/dist/utils/clipboard.js +53 -9
  506. package/dist/utils/clipboard.js.map +1 -1
  507. package/dist/utils/exif-orientation.d.ts.map +1 -1
  508. package/dist/utils/exif-orientation.js +2 -3
  509. package/dist/utils/exif-orientation.js.map +1 -1
  510. package/dist/utils/paths.d.ts +2 -7
  511. package/dist/utils/paths.d.ts.map +1 -1
  512. package/dist/utils/paths.js +13 -15
  513. package/dist/utils/paths.js.map +1 -1
  514. package/dist/utils/shell.d.ts.map +1 -1
  515. package/dist/utils/shell.js +6 -4
  516. package/dist/utils/shell.js.map +1 -1
  517. package/dist/utils/tools-manager.d.ts.map +1 -1
  518. package/dist/utils/tools-manager.js +3 -5
  519. package/dist/utils/tools-manager.js.map +1 -1
  520. package/dist/utils/version-check.d.ts.map +1 -1
  521. package/dist/utils/version-check.js +3 -1
  522. package/dist/utils/version-check.js.map +1 -1
  523. package/docs/attachable-sessions.md +79 -0
  524. package/docs/compaction.md +29 -24
  525. package/docs/containerization.md +23 -23
  526. package/docs/custom-provider.md +66 -32
  527. package/docs/development.md +9 -9
  528. package/docs/docs.json +6 -2
  529. package/docs/duet.md +42 -0
  530. package/docs/environment-variables.md +88 -0
  531. package/docs/extensions.md +278 -65
  532. package/docs/index.md +12 -10
  533. package/docs/json.md +12 -8
  534. package/docs/keybindings.md +8 -5
  535. package/docs/llama-cpp.md +99 -0
  536. package/docs/models.md +19 -8
  537. package/docs/packages.md +43 -42
  538. package/docs/prompt-templates.md +5 -4
  539. package/docs/providers.md +45 -11
  540. package/docs/quickstart.md +33 -33
  541. package/docs/rpc.md +190 -19
  542. package/docs/sdk.md +18 -15
  543. package/docs/security.md +18 -18
  544. package/docs/session-format.md +53 -15
  545. package/docs/sessions.md +17 -14
  546. package/docs/settings.md +26 -19
  547. package/docs/shell-aliases.md +2 -2
  548. package/docs/skills.md +12 -11
  549. package/docs/terminal-setup.md +12 -12
  550. package/docs/termux.md +6 -6
  551. package/docs/themes.md +11 -11
  552. package/docs/tmux.md +4 -4
  553. package/docs/tui.md +46 -31
  554. package/docs/usage.md +53 -63
  555. package/docs/windows.md +2 -2
  556. package/examples/extensions/custom-compaction.ts +4 -0
  557. package/examples/extensions/custom-provider-anthropic/index.ts +9 -3
  558. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  559. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  560. package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
  561. package/examples/extensions/gondolin/package.json +2 -2
  562. package/examples/extensions/handoff.ts +9 -1
  563. package/examples/extensions/kimi-deferred-tools.ts +61 -0
  564. package/examples/extensions/message-renderer.ts +2 -2
  565. package/examples/extensions/overlay-qa-tests.ts +3 -3
  566. package/examples/extensions/sandbox/package.json +1 -1
  567. package/examples/extensions/summarize.ts +3 -0
  568. package/examples/extensions/with-deps/package.json +1 -1
  569. package/examples/sdk/02-custom-model.ts +5 -8
  570. package/examples/sdk/09-api-keys-and-oauth.ts +15 -31
  571. package/examples/sdk/12-full-control.ts +9 -12
  572. package/hooks/gsd/draht-quality-gate.js +3 -3
  573. package/package.json +14 -11
  574. package/prompts/commands/atomic-commit.md +1 -12
  575. package/prompts/commands/brainstorm.md +12 -15
  576. package/prompts/commands/create-verification-skill.md +108 -0
  577. package/prompts/commands/discuss-phase.md +3 -14
  578. package/prompts/commands/execute-phase.md +3 -11
  579. package/prompts/commands/fix.md +41 -18
  580. package/prompts/commands/grill.md +66 -0
  581. package/prompts/commands/init-project.md +5 -15
  582. package/prompts/commands/map-codebase.md +1 -13
  583. package/prompts/commands/new-project.md +5 -15
  584. package/prompts/commands/next-milestone.md +1 -13
  585. package/prompts/commands/orchestrate.md +1 -1
  586. package/prompts/commands/pause-work.md +1 -13
  587. package/prompts/commands/plan-phase.md +2 -11
  588. package/prompts/commands/progress.md +0 -13
  589. package/prompts/commands/quick.md +3 -11
  590. package/prompts/commands/resolve-conflicts.md +71 -0
  591. package/prompts/commands/resume-work.md +0 -13
  592. package/prompts/commands/review.md +4 -13
  593. package/prompts/commands/triage.md +159 -0
  594. package/prompts/commands/verify-work.md +4 -14
  595. package/prompts/commands/why.md +135 -0
  596. package/skills/atomic-reasoning/SKILL.md +115 -0
  597. package/skills/blast-radius/SKILL.md +55 -0
  598. package/skills/epistemics/SKILL.md +99 -0
  599. package/skills/hexagon-animation/SKILL.md +49 -0
  600. package/skills/hexagon-animation/generate.mjs +81 -0
  601. package/skills/hexagon-animation/template.html +361 -0
  602. package/skills/typescript-discipline/SKILL.md +50 -0
  603. package/skills/typescript-discipline/references/patterns.md +294 -0
  604. package/skills/unslop/SKILL.md +101 -0
  605. package/dist/core/provider-display-names.d.ts +0 -2
  606. package/dist/core/provider-display-names.d.ts.map +0 -1
  607. package/dist/core/provider-display-names.js +0 -36
  608. package/dist/core/provider-display-names.js.map +0 -1
  609. package/dist/prompts/agents/build.md +0 -86
  610. package/dist/prompts/agents/plan.md +0 -79
  611. package/dist/prompts/agents/verify.md +0 -69
  612. package/prompts/agents/build.md +0 -86
  613. package/prompts/agents/plan.md +0 -79
  614. package/prompts/agents/verify.md +0 -69
@@ -0,0 +1,788 @@
1
+ /**
2
+ * RelayUIContext — the decorator that lets a remote surface answer a local dialog.
3
+ *
4
+ * It wraps EXACTLY `confirm`, `select` and `input`. Every other `ExtensionUIContext` member is
5
+ * hand-delegated verbatim. This is deliberately NOT a Proxy: `getEditorText`, `theme`,
6
+ * `getAllThemes`, `getTheme`, `getToolsExpanded` and `getEditorComponent` are synchronous reads of
7
+ * the base's local state, and `setWidget`/`setFooter`/`setHeader`/`custom` take component
8
+ * factories that cannot be serialized. `editor` and `custom` therefore stay purely local by
9
+ * documented exception.
10
+ *
11
+ * THE INVARIANT THIS FILE EXISTS TO HOLD: an offered option CARRIES the value the caller receives
12
+ * when it comes back. Nothing derives that value later — not from the option's index, not from its
13
+ * position relative to its siblings, not by matching labels across two arrays, not from a magic id.
14
+ * Every past defect here (an approval read as a denial, a denial read as an approval, an answered
15
+ * "Deny" resolved to the string "Allow") was one of those derivations. There is exactly one
16
+ * constructor of an offered option, {@link offer}, and it takes the caller-side value as an
17
+ * argument — so an option with no resolution cannot be built at all.
18
+ *
19
+ * ITS COROLLARY: a caller vocabulary this file cannot honour is REJECTED, never repaired.
20
+ * {@link classifyVocabulary} is the one gate, and it has exactly three outcomes — absent, valid,
21
+ * invalid. Invalid offers nothing remotely at all, so the ask falls to the local surface or to the
22
+ * raising method's own fail-closed default. Quietly substituting our default pair for a caller's
23
+ * rejected one would broadcast an approval that caller never authorised, and a human tapping it
24
+ * would run the gated call.
25
+ */
26
+ import { randomUUID } from "node:crypto";
27
+ import { isRelayEnded, RELAY_ANSWERED, RELAY_CANCELLED, } from "./types.js";
28
+ /**
29
+ * The caller-side meaning of each declared decision.
30
+ *
31
+ * A total map from the vocabulary's own word to the boolean a `confirm` caller receives. It is not
32
+ * a test of an id and not a position rule: the option says what it means, this only translates.
33
+ */
34
+ const CONFIRM_RESOLUTION = Object.freeze({
35
+ approve: true,
36
+ deny: false,
37
+ });
38
+ /**
39
+ * The frozen two-way vocabulary a bare `confirm` offers when the caller supplied no
40
+ * `detail.options`.
41
+ *
42
+ * These ids are a DEFAULT, never a test: a caller may offer any vocabulary it likes (T5's tool
43
+ * permission ask does), and every vocabulary states its own semantics through `decision`. Nothing
44
+ * in this file compares an answered id against a literal.
45
+ */
46
+ export const APPROVE_OPTION_ID = "approve";
47
+ export const DENY_OPTION_ID = "deny";
48
+ const DEFAULT_CONFIRM_OPTIONS = Object.freeze([
49
+ Object.freeze({ id: APPROVE_OPTION_ID, label: "Yes", decision: "approve" }),
50
+ Object.freeze({ id: DENY_OPTION_ID, label: "No", decision: "deny" }),
51
+ ]);
52
+ /**
53
+ * Nobody decided: the ask was dismissed from outside via the caller's own AbortSignal, the relay
54
+ * gave up while no local surface existed to fall back to, or the caller's own declared timeout
55
+ * expired with the decorator holding the only arm.
56
+ */
57
+ const SYSTEM_DECIDER = { surface: "system", clientId: null };
58
+ /**
59
+ * The ONE place an offered option is constructed.
60
+ *
61
+ * The caller-side value is an argument, supplied at construction from data the caller actually
62
+ * gave us — the option's own declared decision, or the very string the caller listed. No other
63
+ * function in this file builds an `OfferedOption`, so there is no second path where a resolution
64
+ * could be inferred after the fact.
65
+ *
66
+ * `declares` is optional and purely descriptive: `select` and `input` have no permission semantics
67
+ * to state. Passing it never changes `resolution`.
68
+ */
69
+ function offer(id, label, value, declares) {
70
+ return { id, label, resolution: { value }, declares };
71
+ }
72
+ /**
73
+ * Index a freshly minted list by id. Ids are wire handles; they are never parsed or ordered.
74
+ *
75
+ * Callers must have proved the ids unique first — `new Map` is last-wins, and letting array
76
+ * position silently pick which of two same-id options survives is precisely the inference this
77
+ * file exists to abolish. {@link classifyVocabulary} is that proof for caller-supplied
78
+ * vocabularies; the other two mints generate their own ids and cannot collide.
79
+ */
80
+ function offeredSet(options) {
81
+ // Callers must hand this a DENSE array. `new Map` iterates, so a hole reaches it as `undefined`
82
+ // and throws. Both mints guarantee density: `classifyVocabulary` builds its own frozen snapshot,
83
+ // and `mintSelectOptions` skips holes by index.
84
+ return new Map(options.map((option) => [option.id, option]));
85
+ }
86
+ /**
87
+ * The offered set of an ask with NO remote answerable option.
88
+ *
89
+ * Two asks reach it: a free-text `input`, whose answer is the text itself, and a `confirm` whose
90
+ * caller-supplied vocabulary did not survive validation. Both broadcast zero options, so both are
91
+ * decided by the local surface or by the method's own fail-closed default — never by a fabrication.
92
+ */
93
+ const NO_OFFERED_OPTIONS = new Map();
94
+ /**
95
+ * What a `confirm` answered on the LOCAL surface means, when the surface DID NOT SAY.
96
+ *
97
+ * `true` is unambiguous: no fail-closed path in this file, in the barrel's no-op, in interactive
98
+ * mode or in RPC mode ever produces `true`, so a `true` is always somebody approving.
99
+ *
100
+ * `false` is NOT unambiguous, and no cleverness about the boolean can make it so:
101
+ * `ExtensionUIContext.confirm` returns `Promise<boolean>`, so a human pressing "No" and a surface
102
+ * GIVING UP (RPC's `cancelPendingExtensionRequests` on shutdown, on stdin EOF, on abort;
103
+ * interactive's Esc) arrive here as the same value. ANY derivation from that boolean fabricates
104
+ * something, and this one fabricated a human's refusal for asks nobody ever saw.
105
+ *
106
+ * That is why this function is now the FALLBACK and not the rule. A surface states its own outcome
107
+ * through {@link ExtensionUIDialogOptions.reportOutcome} — the honest four-way `RelayOutcome` —
108
+ * and {@link race} prefers what it was told over what can be guessed. This runs only for a base
109
+ * that never called it, where today's behaviour is kept exactly as it was rather than replaced by
110
+ * a different guess. `chosenOptionId` is null because a surface that answered with a bare boolean
111
+ * never named one of the offered ids.
112
+ */
113
+ function confirmOutcome(value) {
114
+ return value ? { kind: "approved", chosenOptionId: null } : { kind: "denied", chosenOptionId: null };
115
+ }
116
+ /**
117
+ * What a `select` or `input` answered on the LOCAL surface means.
118
+ *
119
+ * These two methods have NO permission semantics, so neither `approved` nor `denied` may be said
120
+ * about them. `undefined` is both surfaces' documented "dismissed" value and is also this file's
121
+ * fail-closed fallback, so the two coincide honestly: either way nobody answered.
122
+ */
123
+ function choiceOutcome(value) {
124
+ return value === undefined ? RELAY_CANCELLED : RELAY_ANSWERED;
125
+ }
126
+ /**
127
+ * What an ANSWERED offered option means, read off that option and nothing else.
128
+ *
129
+ * `declares` is the option's own `decision` word, copied out when the option was minted and frozen
130
+ * with it — the same word the registry reads on its own side, so the two halves of a round trip
131
+ * cannot disagree. An option that declares nothing is a `select` entry: it ends the ask by being
132
+ * answered, and says nothing about permission.
133
+ */
134
+ function answeredOutcome(declares, chosenOptionId) {
135
+ if (declares === "approve")
136
+ return { kind: "approved", chosenOptionId };
137
+ if (declares === "deny")
138
+ return { kind: "denied", chosenOptionId };
139
+ return RELAY_ANSWERED;
140
+ }
141
+ export function createRelayUIContext(base, relay, baseIsLive, localSurface) {
142
+ /**
143
+ * The local surface, named for what it ACTUALLY is.
144
+ *
145
+ * Passed in rather than hardcoded: this decorator wraps whatever context the binding mode
146
+ * installed, and a literal `tui` here recorded an answer typed into the RPC surface — a process
147
+ * with no terminal UI at all — as a human at a terminal.
148
+ */
149
+ const localDecider = { surface: localSurface, clientId: null };
150
+ /** Evaluated LIVE on every call: clients attach and detach while a session is running. */
151
+ const hasAnswerSurface = () => baseIsLive || relay.readWriteClientCount() > 0;
152
+ function race(spec) {
153
+ // (f) Nobody can answer. Do not raise anything anywhere — hand back the base's own value so
154
+ // the caller's fail-closed branch fires exactly as it does with no relay installed.
155
+ if (!baseIsLive && relay.readWriteClientCount() === 0) {
156
+ return spec.runBase(spec.opts);
157
+ }
158
+ const externalSignal = spec.opts?.signal;
159
+ if (externalSignal?.aborted === true) {
160
+ // The undecorated surfaces check this upfront too; nothing should be shown at all.
161
+ return Promise.resolve(spec.fallback);
162
+ }
163
+ // (a) One id and one AbortController per ask.
164
+ const requestId = randomUUID();
165
+ const controller = new AbortController();
166
+ let settled = false;
167
+ let resolveOuter;
168
+ let rejectOuter;
169
+ const outer = new Promise((resolve, reject) => {
170
+ resolveOuter = resolve;
171
+ rejectOuter = reject;
172
+ });
173
+ // The caller's own signal is replaced below by ours, so forward it or an extension's
174
+ // programmatic dismissal would silently stop working under the decorator. It is removed
175
+ // again the moment the ask settles: a caller-owned signal outlives the ask and would
176
+ // otherwise collect one dead listener per dialog.
177
+ const onExternalAbort = () => {
178
+ settle(SYSTEM_DECIDER, spec.fallback, RELAY_CANCELLED);
179
+ };
180
+ const releaseExternalSignal = () => {
181
+ externalSignal?.removeEventListener("abort", onExternalAbort);
182
+ };
183
+ /** (g) The caller's declared timeout, armed only when the decorator owns the only arm. */
184
+ let expiry;
185
+ const releaseTimeout = () => {
186
+ if (expiry !== undefined) {
187
+ clearTimeout(expiry);
188
+ expiry = undefined;
189
+ }
190
+ };
191
+ /**
192
+ * (c) SYNCHRONOUS from the settled check through resolve(). A single `await` between the
193
+ * check and the assignment lets both answers through and produces two conflicting
194
+ * resolutions with no error at all, because the second resolve() is a silent no-op.
195
+ *
196
+ * (d) Order after a winner: mark settled -> resolve -> abort the losing surfaces ->
197
+ * withdraw. Aborting BEFORE resolving is a real defect: interactive mode honours
198
+ * `opts.signal` by resolving its selector to `undefined`, which its confirm wrapper maps to
199
+ * `false` — an abort-first implementation would feed a FABRICATED local deny back through
200
+ * this decorator and overwrite a remote approve.
201
+ *
202
+ * (e) Each teardown step is wrapped on its own, and this is what that does and does not buy.
203
+ *
204
+ * GUARANTEED: a `withdraw` that throws synchronously, a `withdraw` that returns a rejected
205
+ * promise (the shape a socket-writing registry naturally has), and a throwing `interpret`
206
+ * cannot escape this discarded `.then` as an unhandled rejection — fatal under Node's default
207
+ * --unhandled-rejections=throw — and cannot prevent the teardown steps behind them from
208
+ * running. The caller already has its answer before any of this executes.
209
+ *
210
+ * NOT GUARANTEED: `quietly(() => controller.abort())` does NOT contain a throw from an abort
211
+ * listener the BASE surface registered. `AbortController.abort()` dispatches synchronously
212
+ * through EventTarget, which reports a listener exception as an `uncaughtException` — it never
213
+ * propagates to the `abort()` call site, so neither try/catch nor `.catch()` can see it. That
214
+ * is inherent to EventTarget dispatch and is not something this decorator can fix.
215
+ */
216
+ const settle = (decidedBy, value, outcome) => {
217
+ if (settled) {
218
+ return;
219
+ }
220
+ settled = true;
221
+ resolveOuter(value);
222
+ quietly(releaseExternalSignal);
223
+ quietly(releaseTimeout);
224
+ quietly(() => controller.abort());
225
+ // The outcome is an ARGUMENT, never something the relay may reconstruct. THIS call site
226
+ // has just settled the ask and holds the value; the relay holds neither, and when it
227
+ // guessed it wrote `cancelled` over an approval whose command had already run.
228
+ quietly(() => relay.withdraw(requestId, decidedBy, outcome));
229
+ };
230
+ let relayDone = false;
231
+ let baseFailure;
232
+ /** Both sides are spent and the only outcome was an error from the local surface. */
233
+ const rejectIfExhausted = () => {
234
+ if (settled || !relayDone || baseFailure === undefined) {
235
+ return;
236
+ }
237
+ settled = true;
238
+ rejectOuter(baseFailure.error);
239
+ quietly(releaseExternalSignal);
240
+ quietly(releaseTimeout);
241
+ };
242
+ /**
243
+ * The relay is spent without a usable answer: nobody answered, it was withdrawn, it
244
+ * expired, it failed, or the answer named an option that was never offered.
245
+ *
246
+ * With a live local surface we simply keep waiting on it. With NO local surface there is
247
+ * nothing left to wait for, so the ask ends on its own fail-closed default — the wrapped
248
+ * no-op's `false` must never stand in as a decision, because a caller reports that as a
249
+ * user action in the transcript.
250
+ */
251
+ const relayExhausted = () => {
252
+ if (!baseIsLive) {
253
+ settle(SYSTEM_DECIDER, spec.fallback, RELAY_CANCELLED);
254
+ return;
255
+ }
256
+ rejectIfExhausted();
257
+ };
258
+ /**
259
+ * The offered set is the ONLY interpreter, and it is a plain lookup by the id that was
260
+ * broadcast: the answered option already carries its caller-side value. A free-text ask
261
+ * carries its answer verbatim instead.
262
+ *
263
+ * The OUTCOME comes back with the value, read off the very option that was answered — its own
264
+ * `declares` word and its own id. It is not derived from the value: two options of one
265
+ * vocabulary can share a caller-side value (`[allow, deny-once, deny-always]` has two `false`
266
+ * denials), so a value can never name the option that produced it. An option that declares
267
+ * nothing is a plain `select` entry and a free-text answer is an `input`: neither approves nor
268
+ * denies anything, and both report `answered`.
269
+ */
270
+ const interpret = (optionId) => {
271
+ const chosen = spec.offered.get(optionId);
272
+ if (chosen !== undefined) {
273
+ return { value: chosen.resolution.value, outcome: answeredOutcome(chosen.declares, chosen.id) };
274
+ }
275
+ try {
276
+ return spec.fromFreeText === undefined
277
+ ? undefined
278
+ : { value: spec.fromFreeText(optionId), outcome: RELAY_ANSWERED };
279
+ }
280
+ catch {
281
+ // An interpreter that blows up produced no answer. It must not settle the ask, and
282
+ // it must not escape this discarded `.then` as an unhandled rejection.
283
+ return undefined;
284
+ }
285
+ };
286
+ /**
287
+ * WHAT THE LOCAL SURFACE SAYS IT DID, when it is willing to say.
288
+ *
289
+ * `ExtensionUIContext.confirm` returns a bare `Promise<boolean>`: a human's "no" and a
290
+ * surface giving up are the same value, so anything derived from it fabricates something.
291
+ * The fix is not a cleverer derivation, it is asking. A surface calls `reportOutcome` with
292
+ * its own honest {@link RelayOutcome} just before it resolves, and that is what gets
293
+ * recorded — an rpc-mode shutdown becomes `cancelled` by the system instead of a human's
294
+ * refusal, and an operator who tapped `deny-once` gets that very id into the audit row
295
+ * instead of a `null` the boolean could never have carried.
296
+ *
297
+ * FIRST STATEMENT WINS, and a late one is ignored: this decorator aborts the losing surface
298
+ * as part of settling, and a surface that reports `cancelled` from its own abort listener
299
+ * must not overwrite the answer that just won. Totally non-throwing, because the base calls
300
+ * it synchronously from inside its own code.
301
+ */
302
+ let reported;
303
+ const callerReport = spec.opts?.reportOutcome;
304
+ const reportOutcome = (outcome) => {
305
+ if (reported === undefined && isRelayOutcome(outcome)) {
306
+ reported = outcome;
307
+ }
308
+ // A caller that supplied its own callback still hears from its surface: this decorator
309
+ // replaces the field on the way down and would otherwise silently swallow it.
310
+ if (callerReport !== undefined) {
311
+ try {
312
+ callerReport(outcome);
313
+ }
314
+ catch {
315
+ // A caller's own callback must not break the surface that called it.
316
+ }
317
+ }
318
+ };
319
+ /**
320
+ * WHO to name for an ask the local side settled. ONE rule, and it is total.
321
+ *
322
+ * `cancelled` means NOBODY ANSWERED — a shutdown, a stdin EOF, an abort, a surface's own
323
+ * timeout, a dismissal. Naming the surface for one of those puts a decision in the audit
324
+ * trail against a person who never made it, which is the same falsehood as calling it a
325
+ * denial, merely moved into a different field. It is the rule this module already applies
326
+ * to every OTHER cancellation — the caller's own abort, the declared timeout, an exhausted
327
+ * relay all settle with {@link SYSTEM_DECIDER} — so applying it here too is what makes
328
+ * "cancelled is attributed to the system, never to a surface that did not act" a property
329
+ * of this file rather than a habit of four call sites.
330
+ *
331
+ * Every other outcome names the surface that produced it: `approved`, `denied` and
332
+ * `answered` all report that somebody DID act, on this surface.
333
+ */
334
+ const deciderFor = (outcome) => outcome.kind === "cancelled" ? SYSTEM_DECIDER : localDecider;
335
+ externalSignal?.addEventListener("abort", onExternalAbort, { once: true });
336
+ // ONE usability verdict, read by the advisory `deadline` just below AND by the real clock at
337
+ // the bottom of this function. Guarding the two expressions separately is how a `NaN` timeout
338
+ // (an unset `Number(process.env.DRAHT_PERMISSION_TIMEOUT_MS)`) and an `Infinity` timeout (the
339
+ // idiomatic "never expire") reached `new Date(...).toISOString()` and threw a RangeError
340
+ // SYNCHRONOUSLY out of `confirm()`. Such an ask never reaches the relay and never fails
341
+ // closed: it propagates as an exception the permission gate reports as a TOOL ERROR rather
342
+ // than as a denial. A permission ask must fail closed; it must never throw. The verdict also
343
+ // bounds the MAGNITUDE, for the same reason and in the same one place — see
344
+ // {@link MAX_USABLE_TIMEOUT_MS}.
345
+ const declaredTimeout = usableTimeout(spec.opts?.timeout);
346
+ const ask = {
347
+ requestId,
348
+ method: spec.method,
349
+ title: spec.title,
350
+ message: spec.message,
351
+ detail: spec.opts?.detail,
352
+ // Derived from the offered set itself: nothing can be shown that cannot be answered.
353
+ // `decision` rides along for rendering — see OfferedOption.declares.
354
+ options: [...spec.offered.values()].map(({ id, label, declares }) => declares === undefined ? { id, label } : { id, label, decision: declares }),
355
+ requestedAt: new Date().toISOString(),
356
+ // Advisory rendering data only. Real expiry binds to the clock below, never to this.
357
+ deadline: declaredTimeout === undefined ? null : new Date(Date.now() + declaredTimeout).toISOString(),
358
+ };
359
+ // (b) Start BOTH surfaces — but ONLY when the mode actually bound one. A base that is not
360
+ // live is the barrel's no-op, whose `confirm` resolves `false` on the very next microtask:
361
+ // started, it wins every race outright and fabricates a user denial before the phone can
362
+ // even render the ask. (e) Both handlers swallow late results and late REJECTIONS against a
363
+ // settled ask — an unswallowed rejection is fatal under --unhandled-rejections=throw.
364
+ if (baseIsLive) {
365
+ callSafely(() => spec.runBase({ ...spec.opts, signal: controller.signal, reportOutcome })).then((value) => {
366
+ // TOLD beats DERIVED. `spec.localOutcome` is a reading of an ambiguous value and
367
+ // runs only for a base that stated nothing, which is what keeps every existing
368
+ // `ExtensionUIContext` implementer behaving exactly as it does today.
369
+ const outcome = reported ?? spec.localOutcome(value);
370
+ settle(deciderFor(outcome), value, outcome);
371
+ }, (error) => {
372
+ baseFailure = { error };
373
+ rejectIfExhausted();
374
+ });
375
+ }
376
+ callSafely(() => relay.raise(ask)).then((answer) => {
377
+ relayDone = true;
378
+ if (isRelayEnded(answer) && answer.requestId === requestId) {
379
+ // THE ASK IS OVER, not merely unanswerable HERE. The relay's clock ran out, or
380
+ // the session was stopped: it has already broadcast the ending and written the
381
+ // audit row. Waiting on the local surface now is the fail-OPEN defect — the
382
+ // dialog stayed on screen, a human tapped Approve, and the command ran against
383
+ // a durable record that says `expired`. `settle` aborts the local surface.
384
+ settle(answer.decidedBy, spec.fallback, RELAY_CANCELLED);
385
+ return;
386
+ }
387
+ if (answer === undefined || isRelayEnded(answer) || answer.requestId !== requestId) {
388
+ relayExhausted();
389
+ return;
390
+ }
391
+ const decided = interpret(answer.optionId);
392
+ if (decided === undefined) {
393
+ // An id nobody offered is not a choice anybody made: it is silence, not a dismissal.
394
+ relayExhausted();
395
+ return;
396
+ }
397
+ settle(answer.decidedBy, decided.value, decided.outcome);
398
+ }, () => {
399
+ relayDone = true;
400
+ relayExhausted();
401
+ });
402
+ // (g) With a live base, the local surface runs the caller's timeout itself (interactive mode
403
+ // shows the countdown) and this decorator must not add a second clock. With NO live base the
404
+ // decorator holds the only arm, so an unhonoured `opts.timeout` means the caller waits
405
+ // forever whenever the relay never resolves — where without a relay it would have failed
406
+ // closed instantly. On expiry the ask ends on the method's own fail-closed default,
407
+ // attributed to the system: nobody decided.
408
+ //
409
+ // This is deliberately NOT a default clock. When the caller declares no timeout — or declares
410
+ // one too large to arm honestly, see usableTimeout — the bound is the pending registry's own
411
+ // fail-closed timer (R34-PERM.6, a later task): one clock, owned there. All that happens here
412
+ // is that the caller's OWN declared timeout is respected, when it is a duration we can keep.
413
+ if (!baseIsLive && declaredTimeout !== undefined) {
414
+ expiry = setTimeout(() => {
415
+ settle(SYSTEM_DECIDER, spec.fallback, RELAY_CANCELLED);
416
+ }, declaredTimeout);
417
+ }
418
+ return outer;
419
+ }
420
+ return {
421
+ select(title, options, opts) {
422
+ return race({
423
+ method: "select",
424
+ title,
425
+ offered: mintSelectOptions(options),
426
+ opts,
427
+ fallback: undefined,
428
+ localOutcome: choiceOutcome,
429
+ runBase: (baseOpts) => base.select(title, options, baseOpts),
430
+ });
431
+ },
432
+ confirm(title, message, opts) {
433
+ return race({
434
+ method: "confirm",
435
+ title,
436
+ message,
437
+ offered: mintConfirmOptions(opts?.detail?.options),
438
+ opts,
439
+ fallback: false,
440
+ localOutcome: confirmOutcome,
441
+ runBase: (baseOpts) => base.confirm(title, message, baseOpts),
442
+ });
443
+ },
444
+ input(title, placeholder, opts) {
445
+ return race({
446
+ method: "input",
447
+ title,
448
+ message: placeholder,
449
+ // A free-text ask offers NOTHING answerable, exactly as `select` takes nothing from
450
+ // `detail.options`. Minting suggestions by id put the id namespace and the free-text
451
+ // namespace in one map, and the map was consulted first: a human who TYPED the literal
452
+ // text "allow-once" into an ask carrying a suggestion with that id got the suggestion's
453
+ // LABEL back instead of what they typed. `detail` still travels, for rendering only.
454
+ offered: NO_OFFERED_OPTIONS,
455
+ // The answer IS the text, verbatim.
456
+ fromFreeText: (text) => text,
457
+ opts,
458
+ fallback: undefined,
459
+ localOutcome: choiceOutcome,
460
+ runBase: (baseOpts) => base.input(title, placeholder, baseOpts),
461
+ });
462
+ },
463
+ // ---------------------------------------------------------------------------------------
464
+ // Hand-delegated, verbatim. Not a Proxy — see the file header.
465
+ // ---------------------------------------------------------------------------------------
466
+ notify(message, type) {
467
+ base.notify(message, type);
468
+ },
469
+ onTerminalInput(handler) {
470
+ return base.onTerminalInput(handler);
471
+ },
472
+ setStatus(key, text) {
473
+ base.setStatus(key, text);
474
+ },
475
+ setWorkingMessage(message) {
476
+ base.setWorkingMessage(message);
477
+ },
478
+ setWorkingVisible(visible) {
479
+ base.setWorkingVisible(visible);
480
+ },
481
+ setWorkingIndicator(options) {
482
+ base.setWorkingIndicator(options);
483
+ },
484
+ setHiddenThinkingLabel(label) {
485
+ base.setHiddenThinkingLabel(label);
486
+ },
487
+ // `content` is `never` so this single implementation satisfies both declared overloads.
488
+ setWidget(key, content, options) {
489
+ base.setWidget(key, content, options);
490
+ },
491
+ setFooter(factory) {
492
+ base.setFooter(factory);
493
+ },
494
+ setHeader(factory) {
495
+ base.setHeader(factory);
496
+ },
497
+ setTitle(title) {
498
+ base.setTitle(title);
499
+ },
500
+ /** Local by documented exception: the factory produces a live component. */
501
+ custom(factory, options) {
502
+ return base.custom(factory, options);
503
+ },
504
+ pasteToEditor(text) {
505
+ base.pasteToEditor(text);
506
+ },
507
+ setEditorText(text) {
508
+ base.setEditorText(text);
509
+ },
510
+ getEditorText() {
511
+ return base.getEditorText();
512
+ },
513
+ /** Local by documented exception: a multi-line editor is not a one-shot answerable ask. */
514
+ editor(title, prefill) {
515
+ return base.editor(title, prefill);
516
+ },
517
+ addAutocompleteProvider(factory) {
518
+ base.addAutocompleteProvider(factory);
519
+ },
520
+ setEditorComponent(factory) {
521
+ base.setEditorComponent(factory);
522
+ },
523
+ getEditorComponent() {
524
+ return base.getEditorComponent();
525
+ },
526
+ get theme() {
527
+ return base.theme;
528
+ },
529
+ getAllThemes() {
530
+ return base.getAllThemes();
531
+ },
532
+ getTheme(name) {
533
+ return base.getTheme(name);
534
+ },
535
+ setTheme(newTheme) {
536
+ return base.setTheme(newTheme);
537
+ },
538
+ getToolsExpanded() {
539
+ return base.getToolsExpanded();
540
+ },
541
+ setToolsExpanded(expanded) {
542
+ base.setToolsExpanded(expanded);
543
+ },
544
+ hasAnswerSurface,
545
+ };
546
+ }
547
+ /**
548
+ * Whether a surface's self-reported outcome is a {@link RelayOutcome} AT ALL.
549
+ *
550
+ * A VALIDITY test, not a meaning rule — the same discipline {@link classifyVocabulary} applies to a
551
+ * caller's vocabulary. `ExtensionUIContext` is implemented by third parties and by untyped JS
552
+ * extensions, so `reportOutcome("approved")` or `reportOutcome({kind: "maybe"})` is reachable, and
553
+ * a malformed report must fall back to today's derivation rather than become a decision word
554
+ * nothing downstream can read.
555
+ *
556
+ * What it deliberately does NOT do is cross-check the report against the value the surface
557
+ * resolved with. They are two different facts about the same act, the surface owns both, and
558
+ * inventing a tie-breaker between them would be exactly the derivation this file exists to
559
+ * abolish. A surface that lies about itself is a bug in that surface, not something a decorator
560
+ * can adjudicate.
561
+ */
562
+ function isRelayOutcome(value) {
563
+ if (typeof value !== "object" || value === null)
564
+ return false;
565
+ const { kind, chosenOptionId } = value;
566
+ if (kind === "answered" || kind === "cancelled")
567
+ return true;
568
+ if (kind !== "approved" && kind !== "denied")
569
+ return false;
570
+ // `chosenOptionId` is REQUIRED on these two — `null` is the honest report of a surface that
571
+ // answered without naming an offered id, and `undefined` is a field somebody forgot.
572
+ return chosenOptionId === null || typeof chosenOptionId === "string";
573
+ }
574
+ /** Turn a synchronous throw into a rejected promise so both race arms behave identically. */
575
+ function callSafely(fn) {
576
+ try {
577
+ return fn();
578
+ }
579
+ catch (error) {
580
+ return Promise.reject(error);
581
+ }
582
+ }
583
+ /**
584
+ * Run one teardown step and swallow whatever it fails with — synchronously OR asynchronously.
585
+ *
586
+ * Teardown happens after the caller already has its answer, from inside a discarded `.then`: a
587
+ * surface that blows up while being torn down cannot un-answer a settled ask, and must not become
588
+ * an unhandled rejection. `relay.withdraw` is declared `void` but the real registry writes to a
589
+ * socket, so the natural implementation is `async` — catching only synchronous throws would leave
590
+ * exactly that shape fatal. Each step is wrapped on its own so a failure in one does not skip the
591
+ * rest.
592
+ */
593
+ function quietly(step) {
594
+ try {
595
+ void Promise.resolve(step()).catch(() => {
596
+ // Deliberately ignored — see above.
597
+ });
598
+ }
599
+ catch {
600
+ // Deliberately ignored — see above.
601
+ }
602
+ }
603
+ /**
604
+ * The only words a permission vocabulary may use, as RUNTIME values rather than as a type.
605
+ *
606
+ * Derived from {@link CONFIRM_RESOLUTION}'s own keys so the two cannot drift: a word passes this
607
+ * gate if and only if there is a caller-side value to translate it into.
608
+ */
609
+ const DECISION_WORDS = new Set(Object.keys(CONFIRM_RESOLUTION));
610
+ /** Narrow a value read out of untyped data to a decision word. */
611
+ function isDecisionWord(value) {
612
+ return typeof value === "string" && DECISION_WORDS.has(value);
613
+ }
614
+ /**
615
+ * THE ONE PLACE a caller's vocabulary is validated.
616
+ *
617
+ * `CONFIRM_RESOLUTION` is total over the declared TYPE but not over runtime values: a detail that
618
+ * crossed a wire or came from an untyped JS extension can carry `decision: "maybe"`, and without
619
+ * this gate that option was offered, broadcast, answerable, and resolved a `Promise<boolean>` with
620
+ * `undefined`. Ids likewise must be unique before {@link offeredSet}'s last-wins `new Map` sees
621
+ * them, or ARRAY POSITION decides which of two same-id options survives while `detail.options` —
622
+ * the documented rendering carrier — still shows both, letting a tapped "Deny" resolve `true`.
623
+ *
624
+ * This is a validity test, not a meaning rule: no branch here reads an option's COUNT, POSITION or
625
+ * ID to decide what that option means. The emptiness check asks "is this a vocabulary at all", and
626
+ * a vocabulary of zero words is not one.
627
+ *
628
+ * It is TOTAL over runtime values, and its parameter is `unknown` to say so. The declared type is
629
+ * exactly what a detail crossing a wire or coming from an untyped JS extension need not honour, and
630
+ * every expression this gate writes must survive being handed the data it exists to police:
631
+ * `vocabulary.length` threw a TypeError on `null`, `for...of` threw "is not iterable" on an
632
+ * array-like `{0: {…}, length: 1}`, and a non-object entry threw on the first property read. A
633
+ * malformed container is INVALID — an outcome this file already knows how to fail closed on — and
634
+ * never an exception out of `confirm()`.
635
+ *
636
+ * Every field is read EXACTLY ONCE, here, and the verdict carries {@link ValidatedOption} copies
637
+ * rather than the caller's array. See {@link ValidatedOption} for what that buys.
638
+ */
639
+ function classifyVocabulary(vocabulary) {
640
+ if (vocabulary === undefined) {
641
+ return { kind: "absent" };
642
+ }
643
+ if (!Array.isArray(vocabulary)) {
644
+ return { kind: "invalid" };
645
+ }
646
+ const entries = vocabulary;
647
+ // A caller whose policy layer filtered its vocabulary down to nothing offered nothing. It did
648
+ // not ask for OUR yes/no pair, and must never have a "Yes" broadcast in its name.
649
+ if (entries.length === 0) {
650
+ return { kind: "invalid" };
651
+ }
652
+ const ids = new Set();
653
+ const snapshot = [];
654
+ for (const entry of entries) {
655
+ if (typeof entry !== "object" || entry === null) {
656
+ return { kind: "invalid" };
657
+ }
658
+ // The decision must be the option's OWN word. A bare `DECISION_WORDS.has(option.decision)`
659
+ // walks the prototype chain: with `Object.prototype.decision = "approve"` set anywhere in the
660
+ // process, an option that declared NOTHING was broadcast as an approval, and tapping its
661
+ // "Deny" label resolved `true`.
662
+ if (!Object.hasOwn(entry, "decision")) {
663
+ return { kind: "invalid" };
664
+ }
665
+ // One read per field, into locals. Everything below inspects these locals, never `entry`.
666
+ const { id, label, decision } = entry;
667
+ // `RelayAnswer.optionId` is typed `string`, so a non-string id is a promise the wire cannot
668
+ // keep: `[{id: 1, …deny}, {id: "1", …approve}]` passed the SameValueZero uniqueness proof
669
+ // (1 !== "1"), broadcast both, and a client honouring its own wire type by sending
670
+ // `String(1)` named the APPROVAL while the human had tapped "Deny". The type-conforming
671
+ // client was the one that got it wrong. An empty id is no handle at all.
672
+ if (typeof id !== "string" || id.length === 0) {
673
+ return { kind: "invalid" };
674
+ }
675
+ if (typeof label !== "string") {
676
+ return { kind: "invalid" };
677
+ }
678
+ if (!isDecisionWord(decision)) {
679
+ return { kind: "invalid" };
680
+ }
681
+ // KNOWN LATENT (accepted, not fixed): this proof is exact-string, so two ids differing only
682
+ // by Unicode normalisation form ("café" NFC vs NFD) are two distinct options here and one
683
+ // option in any client that normalises. Harmless for a hand-written vocabulary; a real risk
684
+ // the moment option ids are DERIVED from tool, path or command data — normalise here then.
685
+ if (ids.has(id)) {
686
+ return { kind: "invalid" };
687
+ }
688
+ ids.add(id);
689
+ snapshot.push(Object.freeze({ id, label, decision }));
690
+ }
691
+ return { kind: "valid", options: Object.freeze(snapshot) };
692
+ }
693
+ /**
694
+ * Mint the vocabulary of a `confirm`, ONCE, behind the one validation gate.
695
+ *
696
+ * Each offered option's caller-side value is read off the option ITSELF, from the `decision` its
697
+ * vocabulary declares. There is no position rule, so a denial in the middle of the list, a
698
+ * vocabulary with several denials, and a single-option vocabulary are all simply what they say they
699
+ * are. With NO caller vocabulary, the default yes/no pair is minted through the same one path.
700
+ *
701
+ * With an INVALID caller vocabulary, nothing is offered at all: the ask broadcasts an empty option
702
+ * list, so it is decided by the local surface if one is live and otherwise by `confirm`'s own
703
+ * fail-closed `false`. An invalid vocabulary is never silently replaced by a fabricated one, and it
704
+ * can never approve anything.
705
+ *
706
+ * Nothing is logged here on purpose. This decorator runs under a TUI that owns the terminal, and a
707
+ * stray `console.warn` mid-render corrupts the screen; the rejection is visible instead as an ask
708
+ * that carries the caller's `detail` but offers no remote option.
709
+ *
710
+ * An id that is not in the set at all is not an answer, which is where fail-closed lives: it can
711
+ * never become a decision attributed to a human who never touched it.
712
+ */
713
+ function mintConfirmOptions(vocabulary) {
714
+ const verdict = classifyVocabulary(vocabulary);
715
+ if (verdict.kind === "invalid") {
716
+ return NO_OFFERED_OPTIONS;
717
+ }
718
+ // BOTH arms are frozen data this file owns — the gate's snapshot, or our own default pair. The
719
+ // caller's array is never read again past validation, so what is minted here is exactly what was
720
+ // proved valid there.
721
+ const options = verdict.kind === "absent" ? DEFAULT_CONFIRM_OPTIONS : verdict.options;
722
+ return offeredSet(options.map((option) => offer(option.id, option.label, CONFIRM_RESOLUTION[option.decision], option.decision)));
723
+ }
724
+ /**
725
+ * The largest timeout this decorator will arm: `2^31-1` ms, about 24.85 days.
726
+ *
727
+ * ONE bound, because it is the smaller of the two real ceilings and therefore covers both.
728
+ *
729
+ * `setTimeout` stores its delay in a signed 32-bit int: anything larger is CLAMPED to 1ms with a
730
+ * `TimeoutOverflowWarning`. A 30-day timeout therefore advertised a deadline a month out and then
731
+ * settled `false` two milliseconds later, attributed to nobody — with no live base, every such ask
732
+ * fabricated a system denial before the phone could render it. Fail-closed, so it could not
733
+ * approve, but it contradicted this file's own promise that real expiry binds to the clock, and it
734
+ * broke the walk-away premise the relay exists for.
735
+ *
736
+ * Far above that, `new Date(Date.now() + t)` leaves the representable range (~8.64e15 ms from the
737
+ * epoch) and `.toISOString()` throws `RangeError: Invalid time value` SYNCHRONOUSLY, so
738
+ * `{ timeout: Number.MAX_SAFE_INTEGER }` — the idiomatic "never expire", which compiles cleanly —
739
+ * never reached either surface and arrived at the permission gate as a tool error, not a decision.
740
+ */
741
+ const MAX_USABLE_TIMEOUT_MS = 2_147_483_647;
742
+ /**
743
+ * ONE verdict for a caller's declared timeout: a real, ARMABLE duration, or nothing at all.
744
+ *
745
+ * A DELIBERATE choice, stated because both readings are defensible: a declared timeout above
746
+ * {@link MAX_USABLE_TIMEOUT_MS} is treated as NO timeout at all, not as one capped to the maximum.
747
+ * Capping invents a bound the caller never asked for and then acts on it — "never expire" would
748
+ * become a fabricated system denial 24 days in, which is the very defect above, merely postponed.
749
+ * And `Number.MAX_SAFE_INTEGER` and `Infinity` are two spellings of one intent, so they must not
750
+ * behave differently. "No usable timeout" already has a documented meaning here: the ask carries
751
+ * `deadline: null`, this decorator arms no clock of its own, and the bound falls to the pending
752
+ * registry's own fail-closed timer (R34-PERM.6) — one clock, owned there.
753
+ */
754
+ function usableTimeout(timeout) {
755
+ return typeof timeout === "number" && Number.isFinite(timeout) && timeout > 0 && timeout <= MAX_USABLE_TIMEOUT_MS
756
+ ? timeout
757
+ : undefined;
758
+ }
759
+ /**
760
+ * Mint the vocabulary of a `select`, ONCE, from the caller's OWN option list and nothing else.
761
+ *
762
+ * Every offered option resolves to the very string it was minted from, bound at construction. The
763
+ * id is a wire handle and nothing more: it is never parsed back into a position, and two identical
764
+ * labels stay two distinct answers.
765
+ *
766
+ * `detail.options` is a permission-DETAIL carrier and deliberately contributes nothing here. Laying
767
+ * a permission vocabulary over a label list — by position, or by label match — is exactly the
768
+ * inference that once resolved an answered "Deny" to the caller-side string "Allow". The detail
769
+ * still travels on the ask for rendering; it just never decides anything.
770
+ */
771
+ function mintSelectOptions(labels) {
772
+ // Iterate by index rather than with `labels.map`, which PRESERVES array holes: `new Map` then
773
+ // iterates the array iterator, hits the hole's `undefined` and throws "Iterator value undefined
774
+ // is not an entry object" synchronously out of the caller's `ui.select`. A caller reaches that
775
+ // with ordinary TypeScript — `for (…) if (keep) labels[i] = name` builds a sparse `string[]` —
776
+ // and the undecorated base does not throw, so the decorator would be introducing the crash.
777
+ // A hole has no label to render and no value to resolve to, so it is not offered at all; the
778
+ // surviving positions keep their own index in the id, so what IS offered stays answerable.
779
+ const options = [];
780
+ for (let position = 0; position < labels.length; position++) {
781
+ const label = labels[position];
782
+ if (typeof label !== "string")
783
+ continue;
784
+ options.push(offer(`option-${position}`, label, label));
785
+ }
786
+ return offeredSet(options);
787
+ }
788
+ //# sourceMappingURL=relay-ui-context.js.map