@humain/humain-code 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/bundle/chunks/{anthropic-messages-UZB5HJE3.js → anthropic-messages-XFCDMGD6.js} +4 -4
  3. package/dist/bundle/chunks/{azure-openai-responses-J3LCMWPQ.js → azure-openai-responses-F4KQM3NK.js} +3 -3
  4. package/dist/bundle/chunks/{chunk-7EONJCBE.js → chunk-2JNJJ6SZ.js} +1 -1
  5. package/dist/bundle/chunks/{chunk-3CGMVKHA.js → chunk-3E37CJCE.js} +1 -1
  6. package/dist/bundle/chunks/{chunk-SQ7NTRLJ.js → chunk-3PJ7NPWN.js} +20 -17
  7. package/dist/bundle/chunks/{chunk-WRYGY5XG.js → chunk-4MKATHT2.js} +1 -1
  8. package/dist/bundle/chunks/{chunk-ATFZAFMS.js → chunk-65FLSKDA.js} +1 -1
  9. package/dist/bundle/chunks/{chunk-P2Y2H7SD.js → chunk-6JTCRCNF.js} +2 -2
  10. package/dist/bundle/chunks/{chunk-CET2MXXN.js → chunk-6P6MMQUH.js} +1 -1
  11. package/dist/bundle/chunks/{chunk-APNPBT7Y.js → chunk-BRSLXHED.js} +1 -1
  12. package/dist/bundle/chunks/{chunk-KONLZKPL.js → chunk-E4VUW4RI.js} +1 -1
  13. package/dist/bundle/chunks/{chunk-R3VDXQW2.js → chunk-EFY2QPVP.js} +6 -6
  14. package/dist/bundle/chunks/{chunk-4EV7CK26.js → chunk-F2H47FRF.js} +1 -1
  15. package/dist/bundle/chunks/{chunk-KQXXBQ57.js → chunk-G2QMON4O.js} +382 -331
  16. package/dist/bundle/chunks/{chunk-TYN46EVI.js → chunk-GPLWWO5Q.js} +1 -1
  17. package/dist/bundle/chunks/{chunk-JV7VHOAY.js → chunk-H2B3WLIM.js} +2 -2
  18. package/dist/bundle/chunks/chunk-H7UPU2SH.js +2093 -0
  19. package/dist/bundle/chunks/{chunk-NNWNIBLG.js → chunk-JKX5EGOT.js} +1 -1
  20. package/dist/bundle/chunks/{chunk-4SFWYKL5.js → chunk-JQBZUFH7.js} +467 -440
  21. package/dist/bundle/chunks/{chunk-D3KYOSQY.js → chunk-JSHKS7VH.js} +1 -1
  22. package/dist/bundle/chunks/{chunk-C4DHVDYT.js → chunk-JX6YIPNK.js} +1 -1
  23. package/dist/bundle/chunks/{chunk-Z5UFSRO4.js → chunk-KI7CHPWC.js} +1 -1
  24. package/dist/bundle/chunks/{chunk-VKQNYZUA.js → chunk-KRBELWQH.js} +1 -1
  25. package/dist/bundle/chunks/{chunk-AI7EHDAX.js → chunk-LSRXA7OS.js} +1 -1
  26. package/dist/bundle/chunks/{chunk-WBSGWISD.js → chunk-M5TVWJ5T.js} +5 -4
  27. package/dist/bundle/chunks/{chunk-XVIQYONJ.js → chunk-MIAXMK5F.js} +1 -1
  28. package/dist/bundle/chunks/{chunk-WGXMYMPE.js → chunk-PFBAIRCY.js} +2 -2
  29. package/dist/bundle/chunks/{chunk-CU6KU7JK.js → chunk-PJXBU6CR.js} +47 -44
  30. package/dist/bundle/chunks/{chunk-OVDMYBIT.js → chunk-PWFM6AQQ.js} +1 -1
  31. package/dist/bundle/chunks/{chunk-PGVDL4KB.js → chunk-QFDZEUFU.js} +2 -2
  32. package/dist/bundle/chunks/{chunk-DD5UT56Y.js → chunk-R2KD2HFT.js} +67 -66
  33. package/dist/bundle/chunks/{chunk-EMBIUIQ2.js → chunk-T2ZGMEMV.js} +46 -45
  34. package/dist/bundle/chunks/{chunk-IOLLZXQN.js → chunk-U4EAJPMO.js} +138 -126
  35. package/dist/bundle/chunks/chunk-UZOIHLNU.js +23 -0
  36. package/dist/bundle/chunks/{chunk-QRYDGY5I.js → chunk-ZSWU5KKA.js} +1 -1
  37. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-ETKC6B2S.js → cloudflare-workers-ai-system-one-JEZVYITT.js} +1 -1
  38. package/dist/bundle/chunks/{compat-HS4ARZK3.js → compat-ELBUCH6U.js} +6 -6
  39. package/dist/bundle/chunks/{curator-server-TC7RVVN2.js → curator-server-QB4GITGS.js} +1 -1
  40. package/dist/bundle/chunks/{dist-NMEXYUP3.js → dist-CBODG4CA.js} +5 -5
  41. package/dist/bundle/chunks/{dist-5AQPJ2TI.js → dist-NERIS6SW.js} +1 -1
  42. package/dist/bundle/chunks/{dist-DYB3AR7C.js → dist-QSYDYE3Y.js} +7 -7
  43. package/dist/bundle/chunks/{easter-egg-3d-VVUF3C3X.js → easter-egg-3d-VZC5WOYV.js} +1 -1
  44. package/dist/bundle/chunks/{execute-I3WGGPWL.js → execute-6MEJJF2T.js} +2 -2
  45. package/dist/bundle/chunks/{extract-QHZTEVJP.js → extract-L373D6O7.js} +2 -2
  46. package/dist/bundle/chunks/{flow-implementer-QMN3HKE2.js → flow-implementer-3P3BHQ7E.js} +4 -4
  47. package/dist/bundle/chunks/github-copilot.js +53 -56
  48. package/dist/bundle/chunks/{google-generative-ai-ZND73WDQ.js → google-generative-ai-WIASMWS3.js} +2 -2
  49. package/dist/bundle/chunks/{google-vertex-YAH62YRM.js → google-vertex-WSPHRZIZ.js} +3 -3
  50. package/dist/bundle/chunks/{host-Q565BCXB.js → host-WOLZCWQQ.js} +1 -1
  51. package/dist/bundle/chunks/{inprocess-453SLFL5.js → inprocess-3PDJKE5F.js} +5 -5
  52. package/dist/bundle/chunks/interactive-mode-SDUO5OLD.js +5 -0
  53. package/dist/bundle/chunks/{llama-cpp-classify-Z4GZY4GC.js → llama-cpp-classify-KYZT532X.js} +1 -1
  54. package/dist/bundle/chunks/{mistral-conversations-7I5JURDP.js → mistral-conversations-7JYDDRUT.js} +2 -2
  55. package/dist/bundle/chunks/{node-IMSYVRPL.js → node-N7TPBUJB.js} +1 -1
  56. package/dist/bundle/chunks/{openai-codex-responses-LTHOMN37.js → openai-codex-responses-7PAML4NF.js} +3 -3
  57. package/dist/bundle/chunks/{openai-completions-W2X635EE.js → openai-completions-UJDAIGTK.js} +3 -3
  58. package/dist/bundle/chunks/{openai-decisions-TN2GNOYI.js → openai-decisions-JMSDGR7K.js} +1 -1
  59. package/dist/bundle/chunks/{openai-responses-DVY4QXOG.js → openai-responses-2WNCE6AY.js} +3 -3
  60. package/dist/bundle/chunks/{openrouter-images-SE2JMS44.js → openrouter-images-V3UCCO6X.js} +1 -1
  61. package/dist/bundle/chunks/{pi-messages-WAS6Z5L5.js → pi-messages-TQ7LJUNQ.js} +2 -2
  62. package/dist/bundle/chunks/{session-picker-XNVLSJ22.js → session-picker-EYKCMFQR.js} +1 -1
  63. package/dist/bundle/chunks/{startup-ui-3TCT465D.js → startup-ui-7ODOR34R.js} +2 -2
  64. package/dist/bundle/chunks/{trace-command-7ORDQ3JS.js → trace-command-VM7FBWPE.js} +4 -4
  65. package/dist/bundle/chunks/{typesafe-system-one-AAZH6S3I.js → typesafe-system-one-YP7GGN4C.js} +1 -1
  66. package/dist/bundle/chunks/{virtual-modules-CIVXCEAN.js → virtual-modules-IU5KWB2C.js} +10 -10
  67. package/dist/bundle/cli-runtime.js +5 -5
  68. package/dist/bundle/index.js +8 -8
  69. package/dist/bundle/rpc-entry.js +4 -4
  70. package/dist/cli/args.js +1 -1
  71. package/dist/cli/args.js.map +1 -1
  72. package/dist/cli/list-models.d.ts.map +1 -1
  73. package/dist/cli/list-models.js +16 -1
  74. package/dist/cli/list-models.js.map +1 -1
  75. package/dist/cli/setup.d.ts +1 -1
  76. package/dist/cli/setup.d.ts.map +1 -1
  77. package/dist/cli/setup.js +3 -2
  78. package/dist/cli/setup.js.map +1 -1
  79. package/dist/cli.js.map +1 -1
  80. package/dist/core/agent-session-runtime.d.ts +3 -0
  81. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  82. package/dist/core/agent-session-runtime.js +11 -2
  83. package/dist/core/agent-session-runtime.js.map +1 -1
  84. package/dist/core/keybindings.d.ts +24 -0
  85. package/dist/core/keybindings.d.ts.map +1 -1
  86. package/dist/core/keybindings.js +3 -0
  87. package/dist/core/keybindings.js.map +1 -1
  88. package/dist/core/model-registry.d.ts.map +1 -1
  89. package/dist/core/model-registry.js +12 -1
  90. package/dist/core/model-registry.js.map +1 -1
  91. package/dist/core/model-resolver.d.ts.map +1 -1
  92. package/dist/core/model-resolver.js +13 -9
  93. package/dist/core/model-resolver.js.map +1 -1
  94. package/dist/core/model-runtime.d.ts +11 -2
  95. package/dist/core/model-runtime.d.ts.map +1 -1
  96. package/dist/core/model-runtime.js +23 -6
  97. package/dist/core/model-runtime.js.map +1 -1
  98. package/dist/core/oauth-account-pool.d.ts +4 -0
  99. package/dist/core/oauth-account-pool.d.ts.map +1 -1
  100. package/dist/core/oauth-account-pool.js +104 -20
  101. package/dist/core/oauth-account-pool.js.map +1 -1
  102. package/dist/core/sdk.js +2 -2
  103. package/dist/core/sdk.js.map +1 -1
  104. package/dist/core/settings-manager.d.ts +4 -0
  105. package/dist/core/settings-manager.d.ts.map +1 -1
  106. package/dist/core/settings-manager.js +17 -0
  107. package/dist/core/settings-manager.js.map +1 -1
  108. package/dist/core/settings-schema.d.ts +2 -0
  109. package/dist/core/settings-schema.d.ts.map +1 -1
  110. package/dist/core/settings-schema.js +10 -0
  111. package/dist/core/settings-schema.js.map +1 -1
  112. package/dist/core/slash-commands.d.ts.map +1 -1
  113. package/dist/core/slash-commands.js +1 -0
  114. package/dist/core/slash-commands.js.map +1 -1
  115. package/dist/extensions/usage/confirmation.d.ts.map +1 -1
  116. package/dist/extensions/usage/confirmation.js +1 -1
  117. package/dist/extensions/usage/confirmation.js.map +1 -1
  118. package/dist/extensions/usage/index.js +6 -6
  119. package/dist/extensions/usage/index.js.map +1 -1
  120. package/dist/extensions/usage/panes.d.ts +5 -0
  121. package/dist/extensions/usage/panes.d.ts.map +1 -0
  122. package/dist/extensions/usage/panes.js +10 -0
  123. package/dist/extensions/usage/panes.js.map +1 -0
  124. package/dist/extensions/usage/popup.d.ts.map +1 -1
  125. package/dist/extensions/usage/popup.js +9 -18
  126. package/dist/extensions/usage/popup.js.map +1 -1
  127. package/dist/humain/gateway/client.d.ts.map +1 -1
  128. package/dist/humain/gateway/client.js +36 -9
  129. package/dist/humain/gateway/client.js.map +1 -1
  130. package/dist/humain/gateway/http.d.ts.map +1 -1
  131. package/dist/humain/gateway/http.js +26 -6
  132. package/dist/humain/gateway/http.js.map +1 -1
  133. package/dist/humain/gateway/provider.d.ts.map +1 -1
  134. package/dist/humain/gateway/provider.js +9 -2
  135. package/dist/humain/gateway/provider.js.map +1 -1
  136. package/dist/humain/hcode/contracts.d.ts +15 -0
  137. package/dist/humain/hcode/contracts.d.ts.map +1 -1
  138. package/dist/humain/hcode/contracts.js +85 -10
  139. package/dist/humain/hcode/contracts.js.map +1 -1
  140. package/dist/humain/hcode/environment.d.ts.map +1 -1
  141. package/dist/humain/hcode/environment.js +4 -2
  142. package/dist/humain/hcode/environment.js.map +1 -1
  143. package/dist/humain/hcode/facade.d.ts +12 -1
  144. package/dist/humain/hcode/facade.d.ts.map +1 -1
  145. package/dist/humain/hcode/facade.js +35 -8
  146. package/dist/humain/hcode/facade.js.map +1 -1
  147. package/dist/humain/hcode/images.d.ts.map +1 -1
  148. package/dist/humain/hcode/images.js +4 -2
  149. package/dist/humain/hcode/images.js.map +1 -1
  150. package/dist/humain/hcode/login-copy.d.ts.map +1 -1
  151. package/dist/humain/hcode/login-copy.js +11 -1
  152. package/dist/humain/hcode/login-copy.js.map +1 -1
  153. package/dist/humain/hcode/notices.d.ts +22 -1
  154. package/dist/humain/hcode/notices.d.ts.map +1 -1
  155. package/dist/humain/hcode/notices.js +34 -3
  156. package/dist/humain/hcode/notices.js.map +1 -1
  157. package/dist/humain/hcode/provider.d.ts +3 -1
  158. package/dist/humain/hcode/provider.d.ts.map +1 -1
  159. package/dist/humain/hcode/provider.js +126 -46
  160. package/dist/humain/hcode/provider.js.map +1 -1
  161. package/dist/humain/hcode/run-credential.d.ts +21 -0
  162. package/dist/humain/hcode/run-credential.d.ts.map +1 -0
  163. package/dist/humain/hcode/run-credential.js +140 -0
  164. package/dist/humain/hcode/run-credential.js.map +1 -0
  165. package/dist/humain/hcode/sandbox.d.ts +6 -0
  166. package/dist/humain/hcode/sandbox.d.ts.map +1 -0
  167. package/dist/humain/hcode/sandbox.js +139 -0
  168. package/dist/humain/hcode/sandbox.js.map +1 -0
  169. package/dist/humain/hcode/selection.d.ts +7 -2
  170. package/dist/humain/hcode/selection.d.ts.map +1 -1
  171. package/dist/humain/hcode/selection.js +29 -5
  172. package/dist/humain/hcode/selection.js.map +1 -1
  173. package/dist/humain/hcode/transport.d.ts +3 -2
  174. package/dist/humain/hcode/transport.d.ts.map +1 -1
  175. package/dist/humain/hcode/transport.js +22 -7
  176. package/dist/humain/hcode/transport.js.map +1 -1
  177. package/dist/humain/remote/broker.d.ts +84 -0
  178. package/dist/humain/remote/broker.d.ts.map +1 -0
  179. package/dist/humain/remote/broker.js +427 -0
  180. package/dist/humain/remote/broker.js.map +1 -0
  181. package/dist/humain/remote/deny-store.d.ts +12 -0
  182. package/dist/humain/remote/deny-store.d.ts.map +1 -0
  183. package/dist/humain/remote/deny-store.js +164 -0
  184. package/dist/humain/remote/deny-store.js.map +1 -0
  185. package/dist/humain/remote/enablement.d.ts +5 -0
  186. package/dist/humain/remote/enablement.d.ts.map +1 -0
  187. package/dist/humain/remote/enablement.js +8 -0
  188. package/dist/humain/remote/enablement.js.map +1 -0
  189. package/dist/humain/remote/environment.d.ts +11 -0
  190. package/dist/humain/remote/environment.d.ts.map +1 -0
  191. package/dist/humain/remote/environment.js +19 -0
  192. package/dist/humain/remote/environment.js.map +1 -0
  193. package/dist/humain/remote/host-watch.d.ts +21 -0
  194. package/dist/humain/remote/host-watch.d.ts.map +1 -0
  195. package/dist/humain/remote/host-watch.js +186 -0
  196. package/dist/humain/remote/host-watch.js.map +1 -0
  197. package/dist/humain/remote/ipc-posix.d.ts +5 -0
  198. package/dist/humain/remote/ipc-posix.d.ts.map +1 -0
  199. package/dist/humain/remote/ipc-posix.js +29 -0
  200. package/dist/humain/remote/ipc-posix.js.map +1 -0
  201. package/dist/humain/remote/ipc-windows.d.ts +3 -0
  202. package/dist/humain/remote/ipc-windows.d.ts.map +1 -0
  203. package/dist/humain/remote/ipc-windows.js +5 -0
  204. package/dist/humain/remote/ipc-windows.js.map +1 -0
  205. package/dist/humain/remote/ipc.d.ts +10 -0
  206. package/dist/humain/remote/ipc.d.ts.map +1 -0
  207. package/dist/humain/remote/ipc.js +19 -0
  208. package/dist/humain/remote/ipc.js.map +1 -0
  209. package/dist/humain/remote/protocol.d.ts +43 -0
  210. package/dist/humain/remote/protocol.d.ts.map +1 -0
  211. package/dist/humain/remote/protocol.js +76 -0
  212. package/dist/humain/remote/protocol.js.map +1 -0
  213. package/dist/humain/remote/relay-socket.d.ts +30 -0
  214. package/dist/humain/remote/relay-socket.d.ts.map +1 -0
  215. package/dist/humain/remote/relay-socket.js +137 -0
  216. package/dist/humain/remote/relay-socket.js.map +1 -0
  217. package/dist/humain/remote/secure-channel.d.ts +10 -0
  218. package/dist/humain/remote/secure-channel.d.ts.map +1 -0
  219. package/dist/humain/remote/secure-channel.js +5 -0
  220. package/dist/humain/remote/secure-channel.js.map +1 -0
  221. package/dist/humain/remote/terminal.d.ts +48 -0
  222. package/dist/humain/remote/terminal.d.ts.map +1 -0
  223. package/dist/humain/remote/terminal.js +119 -0
  224. package/dist/humain/remote/terminal.js.map +1 -0
  225. package/dist/humain/remote/tickets.d.ts +35 -0
  226. package/dist/humain/remote/tickets.d.ts.map +1 -0
  227. package/dist/humain/remote/tickets.js +132 -0
  228. package/dist/humain/remote/tickets.js.map +1 -0
  229. package/dist/main.d.ts +1 -1
  230. package/dist/main.d.ts.map +1 -1
  231. package/dist/main.js +13 -1
  232. package/dist/main.js.map +1 -1
  233. package/dist/modes/interactive/components/account-picker.d.ts +31 -0
  234. package/dist/modes/interactive/components/account-picker.d.ts.map +1 -0
  235. package/dist/modes/interactive/components/account-picker.js +150 -0
  236. package/dist/modes/interactive/components/account-picker.js.map +1 -0
  237. package/dist/modes/interactive/components/settings-selector.d.ts +6 -0
  238. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  239. package/dist/modes/interactive/components/settings-selector.js +26 -0
  240. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  241. package/dist/modes/interactive/components/status-indicator.d.ts +35 -1
  242. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  243. package/dist/modes/interactive/components/status-indicator.js +179 -3
  244. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  245. package/dist/modes/interactive/components/working-indicator-engine.d.ts +32 -0
  246. package/dist/modes/interactive/components/working-indicator-engine.d.ts.map +1 -0
  247. package/dist/modes/interactive/components/working-indicator-engine.js +112 -0
  248. package/dist/modes/interactive/components/working-indicator-engine.js.map +1 -0
  249. package/dist/modes/interactive/fullscreen.d.ts +13 -0
  250. package/dist/modes/interactive/fullscreen.d.ts.map +1 -0
  251. package/dist/modes/interactive/fullscreen.js +25 -0
  252. package/dist/modes/interactive/fullscreen.js.map +1 -0
  253. package/dist/modes/interactive/interactive-mode.d.ts +19 -3
  254. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  255. package/dist/modes/interactive/interactive-mode.js +341 -54
  256. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  257. package/dist/modes/interactive/oauth-account-format.d.ts +9 -0
  258. package/dist/modes/interactive/oauth-account-format.d.ts.map +1 -1
  259. package/dist/modes/interactive/oauth-account-format.js +31 -22
  260. package/dist/modes/interactive/oauth-account-format.js.map +1 -1
  261. package/dist/modes/interactive/theme/humain-dark.json +5 -4
  262. package/dist/modes/interactive/theme/humain-light.json +6 -5
  263. package/docs/cli.md +1 -1
  264. package/docs/development.md +7 -0
  265. package/docs/forge-run-bootstrap.md +46 -0
  266. package/docs/humain-code.md +2 -2
  267. package/docs/index.md +2 -1
  268. package/docs/keybindings.md +10 -0
  269. package/docs/providers.md +16 -6
  270. package/docs/quickstart.md +16 -2
  271. package/docs/settings.md +20 -0
  272. package/docs/slash-commands.md +4 -2
  273. package/docs/usage.md +2 -0
  274. package/npm-shrinkwrap.json +2 -2
  275. package/package.json +1 -1
  276. package/schemas/keybindings.schema.json +12 -0
  277. package/schemas/settings.schema.json +29 -0
  278. package/dist/bundle/chunks/chunk-IXQYPQRQ.js +0 -2079
  279. package/dist/bundle/chunks/chunk-J5TSAJGC.js +0 -22
  280. package/dist/bundle/chunks/chunk-YPZPCHNV.js +0 -3
  281. package/dist/bundle/chunks/interactive-mode-MVZOJ5OU.js +0 -5
@@ -0,0 +1,43 @@
1
+ export type PrincipalKey = Readonly<{
2
+ issuer: string;
3
+ subject: string;
4
+ accountId: string;
5
+ tenantId: string | null;
6
+ environment: string;
7
+ }>;
8
+ export type LiveRoute = Readonly<{
9
+ installId: string;
10
+ brokerEpoch: string;
11
+ sessionId: string;
12
+ attachmentId: string;
13
+ channelEpoch: string;
14
+ }>;
15
+ export type RemoteRole = "host" | "browser";
16
+ type Message = {
17
+ role: "user" | "assistant" | "toolResult";
18
+ text: string;
19
+ };
20
+ export type WatchFrame = {
21
+ type: "snapshot";
22
+ cursor: number;
23
+ messages: Message[];
24
+ historyTruncated: boolean;
25
+ } | {
26
+ type: "delta";
27
+ cursor: number;
28
+ message: Message;
29
+ } | {
30
+ type: "terminal-required";
31
+ reason: "local-input";
32
+ } | {
33
+ type: "ended";
34
+ };
35
+ export type HostWatchControl = {
36
+ type: "heartbeat";
37
+ } | {
38
+ type: "close";
39
+ };
40
+ export declare function decodeWatchFrame(bytes: Uint8Array): WatchFrame;
41
+ export declare function decodeHostWatchControl(bytes: Uint8Array): HostWatchControl;
42
+ export {};
43
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/humain/remote/protocol.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,O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extDecoder("utf-8", { fatal: true });
3
+ export function decodeWatchFrame(bytes) {
4
+ const value = parse(bytes, 1024 * 1024);
5
+ switch (value.type) {
6
+ case "snapshot":
7
+ if (exact(value, "type", "cursor", "messages", "historyTruncated") &&
8
+ cursor(value.cursor) &&
9
+ Array.isArray(value.messages) &&
10
+ value.messages.length <= 200 &&
11
+ value.messages.every(message) &&
12
+ typeof value.historyTruncated === "boolean") {
13
+ return {
14
+ type: value.type,
15
+ cursor: value.cursor,
16
+ messages: value.messages,
17
+ historyTruncated: value.historyTruncated,
18
+ };
19
+ }
20
+ break;
21
+ case "delta":
22
+ if (exact(value, "type", "cursor", "message") && cursor(value.cursor) && message(value.message)) {
23
+ return { type: value.type, cursor: value.cursor, message: value.message };
24
+ }
25
+ break;
26
+ case "terminal-required":
27
+ if (exact(value, "type", "reason") && value.reason === "local-input") {
28
+ return { type: value.type, reason: value.reason };
29
+ }
30
+ break;
31
+ case "ended":
32
+ if (exact(value, "type"))
33
+ return { type: value.type };
34
+ break;
35
+ }
36
+ throw invalid();
37
+ }
38
+ export function decodeHostWatchControl(bytes) {
39
+ const value = parse(bytes, 64 * 1024);
40
+ if (exact(value, "type") && (value.type === "heartbeat" || value.type === "close"))
41
+ return { type: value.type };
42
+ throw invalid();
43
+ }
44
+ function message(value) {
45
+ return (record(value) &&
46
+ exact(value, "role", "text") &&
47
+ (value.role === "user" || value.role === "assistant" || value.role === "toolResult") &&
48
+ typeof value.text === "string" &&
49
+ encoder.encode(value.text).byteLength <= (value.role === "toolResult" ? 16 : 32) * 1024);
50
+ }
51
+ function cursor(value) {
52
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
53
+ }
54
+ function record(value) {
55
+ return typeof value === "object" && value !== null && !Array.isArray(value);
56
+ }
57
+ function exact(value, ...keys) {
58
+ return Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
59
+ }
60
+ function parse(bytes, cap) {
61
+ if (bytes.byteLength > cap)
62
+ throw invalid();
63
+ try {
64
+ const value = JSON.parse(decoder.decode(bytes));
65
+ if (record(value))
66
+ return value;
67
+ }
68
+ catch {
69
+ // Decoder and parser errors can quote input; do not propagate them.
70
+ }
71
+ throw invalid();
72
+ }
73
+ function invalid() {
74
+ return new Error("Invalid remote frame");
75
+ }
76
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/humain/remote/protocol.ts"],"names":[],"mappings":"AA2BA,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAE1D,MAAM,UAAU,gBAAgB,CAAC,KAAiB;IACjD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,CAAC,CAAC;IACxC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,UAAU;YACd,IACC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,kBAAkB,CAAC;gBAC9D,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;gBACpB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC;gBAC7B,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,GAAG;gBAC5B,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC;gBAC7B,OAAO,KAAK,CAAC,gBAAgB,KAAK,SAAS,EAC1C,CAAC;gBACF,OAAO;oBACN,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ;oBACxB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;iBACxC,CAAC;YACH,CAAC;YACD,MAAM;QACP,KAAK,OAAO;YACX,IAAI,KAAK,CAAC,KAAK,EAAE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AC;QACR,oEAAoE;IACrE,CAAC;IACD,MAAM,OAAO,EAAE,CAAC;AACjB,CAAC;AAED,SAAS,OAAO;IACf,OAAO,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["// Local semantic frames; this is not an approved E2E wire profile.\nexport type PrincipalKey = Readonly<{\n\tissuer: string;\n\tsubject: string;\n\taccountId: string;\n\ttenantId: string | null;\n\tenvironment: string;\n}>;\nexport type LiveRoute = Readonly<{\n\tinstallId: string;\n\tbrokerEpoch: string;\n\tsessionId: string;\n\tattachmentId: string;\n\tchannelEpoch: string;\n}>;\nexport type RemoteRole = \"host\" | \"browser\";\n\ntype Message = { role: \"user\" | \"assistant\" | \"toolResult\"; text: string };\nexport type WatchFrame =\n\t| { type: \"snapshot\"; cursor: number; messages: Message[]; historyTruncated: boolean }\n\t| { type: \"delta\"; cursor: number; message: Message }\n\t| { type: \"terminal-required\"; reason: \"local-input\" }\n\t| { type: \"ended\" };\n\n// Proof and pairing controls are not admitted until their exact contracts are qualified.\nexport type HostWatchControl = { type: \"heartbeat\" } | { type: \"close\" };\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\nexport function decodeWatchFrame(bytes: Uint8Array): WatchFrame {\n\tconst value = parse(bytes, 1024 * 1024);\n\tswitch (value.type) {\n\t\tcase \"snapshot\":\n\t\t\tif (\n\t\t\t\texact(value, \"type\", \"cursor\", \"messages\", \"historyTruncated\") &&\n\t\t\t\tcursor(value.cursor) &&\n\t\t\t\tArray.isArray(value.messages) &&\n\t\t\t\tvalue.messages.length <= 200 &&\n\t\t\t\tvalue.messages.every(message) &&\n\t\t\t\ttypeof value.historyTruncated === \"boolean\"\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: value.type,\n\t\t\t\t\tcursor: value.cursor,\n\t\t\t\t\tmessages: value.messages,\n\t\t\t\t\thistoryTruncated: value.historyTruncated,\n\t\t\t\t};\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"delta\":\n\t\t\tif (exact(value, \"type\", \"cursor\", \"message\") && cursor(value.cursor) && message(value.message)) {\n\t\t\t\treturn { type: value.type, cursor: value.cursor, message: value.message };\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"terminal-required\":\n\t\t\tif (exact(value, \"type\", \"reason\") && value.reason === \"local-input\") {\n\t\t\t\treturn { type: value.type, reason: value.reason };\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"ended\":\n\t\t\tif (exact(value, \"type\")) return { type: value.type };\n\t\t\tbreak;\n\t}\n\tthrow invalid();\n}\n\nexport function decodeHostWatchControl(bytes: Uint8Array): HostWatchControl {\n\tconst value = parse(bytes, 64 * 1024);\n\tif (exact(value, \"type\") && (value.type === \"heartbeat\" || value.type === \"close\")) return { type: value.type };\n\tthrow invalid();\n}\n\nfunction message(value: unknown): value is Message {\n\treturn (\n\t\trecord(value) &&\n\t\texact(value, \"role\", \"text\") &&\n\t\t(value.role === \"user\" || value.role === \"assistant\" || value.role === \"toolResult\") &&\n\t\ttypeof value.text === \"string\" &&\n\t\tencoder.encode(value.text).byteLength <= (value.role === \"toolResult\" ? 16 : 32) * 1024\n\t);\n}\n\nfunction cursor(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\n\nfunction record(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction exact(value: Record<string, unknown>, ...keys: string[]): boolean {\n\treturn Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));\n}\n\nfunction parse(bytes: Uint8Array, cap: number): Record<string, unknown> {\n\tif (bytes.byteLength > cap) throw invalid();\n\ttry {\n\t\tconst value: unknown = JSON.parse(decoder.decode(bytes));\n\t\tif (record(value)) return value;\n\t} catch {\n\t\t// Decoder and parser errors can quote input; do not propagate them.\n\t}\n\tthrow invalid();\n}\n\nfunction invalid(): Error {\n\treturn new Error(\"Invalid remote frame\");\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import { type HcodeEnvironment } from "../hcode/environment.ts";
2
+ import type { LiveRoute } from "./protocol.ts";
3
+ export type RelayLane = "setup" | "watch";
4
+ /** Admitted relay connection. Carries opaque records only and never retries or queues beyond one write. */
5
+ export interface RelaySocket {
6
+ /** Aborts on peer close, protocol fault, consumer failure, slow socket or local close. */
7
+ readonly signal: AbortSignal;
8
+ /** False when the record was not written; a slow socket is closed rather than buffered. */
9
+ send(lane: RelayLane, frame: Uint8Array): boolean;
10
+ close(): void;
11
+ }
12
+ interface RelayTicket {
13
+ route: LiveRoute;
14
+ kind: "offer" | "pairing";
15
+ id: string;
16
+ token: string;
17
+ }
18
+ interface RelaySocketOptions {
19
+ environment?: HcodeEnvironment;
20
+ /** Identity-owner port: opens the URL with the Remote-audience credential for the exact account, never in the URL. */
21
+ connect(url: string): WebSocket;
22
+ ticket: RelayTicket;
23
+ receive(lane: RelayLane, frame: Uint8Array): void;
24
+ maxRecordBytes?: number;
25
+ signal?: AbortSignal;
26
+ }
27
+ /** Open the relay socket, present the one-use ticket first and resolve only on the relay's admission acknowledgement. */
28
+ export declare function openRelaySocket({ environment, connect, ticket, receive, maxRecordBytes, signal: parent, }: RelaySocketOptions): Promise<RelaySocket>;
29
+ export {};
30
+ //# sourceMappingURL=relay-socket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay-socket.d.ts","sourceRoot":"","sources":["../../../src/humain/remote/relay-socket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAA2B,MAAM,yBAAyB,CAAC;AAGzF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,2GAA2G;AAC3G,MAAM,WAAW,WAAW;IAC3B,0FAA0F;IAC1F,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,2FAA2F;IAC3F,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC;IAClD,KAAK,IAAI,IAAI,CAAC;CACd;AAED,UAAU,WAAW;IACpB,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACd;AAED,UAAU,kBAAkB;IAC3B,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B,sHAAsH;IACtH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IAClD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAMD,yHAAyH;AACzH,wBAAgB,eAAe,CAAC,EAC/B,WAAuC,EACvC,OAAO,EACP,MAAM,EACN,OAAO,EACP,cAA4B,EAC5B,MAAM,EAAE,MAAM,GACd,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAmH3C"}
@@ -0,0 +1,137 @@
1
+ // Ciphertext-only WSS connection to the Forge Remote relay; the transport a qualified SecureChannel wraps.
2
+ import { addAbortListener } from "node:events";
3
+ import { resolveHcodeEnvironment } from "../hcode/environment.js";
4
+ import { opaqueId } from "./broker.js";
5
+ import { remoteDestinations } from "./environment.js";
6
+ const lanes = ["setup", "watch"];
7
+ const routeKeys = ["installId", "brokerEpoch", "sessionId", "attachmentId", "channelEpoch"];
8
+ const ADMISSION_MS = 5_000;
9
+ /** Open the relay socket, present the one-use ticket first and resolve only on the relay's admission acknowledgement. */
10
+ export function openRelaySocket({ environment = resolveHcodeEnvironment(), connect, ticket, receive, maxRecordBytes = 1024 * 1024, signal: parent, }) {
11
+ // Fixed message: URLs, tickets and socket errors are not Remote diagnostics.
12
+ const unavailable = () => new Error("Remote relay unavailable");
13
+ if (parent?.aborted)
14
+ return Promise.reject(unavailable());
15
+ let destinations;
16
+ try {
17
+ destinations = remoteDestinations(environment);
18
+ }
19
+ catch {
20
+ return Promise.reject(unavailable());
21
+ }
22
+ const { route, kind, id, token } = ticket;
23
+ if ((kind !== "offer" && kind !== "pairing") ||
24
+ !opaqueId(id) ||
25
+ !/^[A-Za-z0-9_-]{43}$/.test(token) ||
26
+ !routeKeys.every((key) => opaqueId(route[key])))
27
+ return Promise.reject(unavailable());
28
+ const wire = JSON.stringify({
29
+ route: Object.fromEntries(routeKeys.map((key) => [key, route[key]])),
30
+ kind,
31
+ id,
32
+ token,
33
+ });
34
+ const lifetime = new AbortController();
35
+ let ws;
36
+ try {
37
+ ws = connect(destinations.relay);
38
+ }
39
+ catch {
40
+ return Promise.reject(unavailable());
41
+ }
42
+ ws.binaryType = "arraybuffer";
43
+ let admitted = false;
44
+ const finish = () => {
45
+ if (lifetime.signal.aborted)
46
+ return;
47
+ lifetime.abort();
48
+ try {
49
+ ws.close();
50
+ }
51
+ catch {
52
+ // The lifetime is already aborted; do not expose transport diagnostics.
53
+ }
54
+ };
55
+ const isLive = () => {
56
+ // An earlier parent observer can reenter before our abort listener runs.
57
+ if (parent?.aborted)
58
+ finish();
59
+ return !lifetime.signal.aborted;
60
+ };
61
+ const write = (data) => {
62
+ if (!isLive())
63
+ return false;
64
+ try {
65
+ if (ws.readyState !== WebSocket.OPEN) {
66
+ finish();
67
+ return false;
68
+ }
69
+ ws.send(data);
70
+ return true;
71
+ }
72
+ catch {
73
+ finish();
74
+ return false;
75
+ }
76
+ };
77
+ const relay = {
78
+ signal: lifetime.signal,
79
+ send(lane, frame) {
80
+ if (!isLive() || frame.byteLength > maxRecordBytes)
81
+ return false;
82
+ // Never enqueue a second record while any bytes of the first remain buffered.
83
+ if (ws.bufferedAmount !== 0) {
84
+ finish();
85
+ return false;
86
+ }
87
+ const record = new Uint8Array(frame.byteLength + 1);
88
+ record[0] = lanes.indexOf(lane);
89
+ record.set(frame, 1);
90
+ return write(record);
91
+ },
92
+ close: finish,
93
+ };
94
+ return new Promise((resolve, reject) => {
95
+ // Any end before the acknowledgement (timeout, abort, close, fault) rejects; later ends only abort.
96
+ const timer = setTimeout(finish, ADMISSION_MS);
97
+ let stopParent;
98
+ lifetime.signal.addEventListener("abort", () => {
99
+ clearTimeout(timer);
100
+ stopParent?.[Symbol.dispose]();
101
+ if (!admitted)
102
+ reject(unavailable());
103
+ }, { once: true });
104
+ if (!isLive())
105
+ return;
106
+ if (parent)
107
+ stopParent = addAbortListener(parent, finish);
108
+ ws.addEventListener("open", () => write(wire), { once: true });
109
+ ws.addEventListener("close", finish);
110
+ ws.addEventListener("error", finish);
111
+ ws.addEventListener("message", ({ data }) => {
112
+ if (!isLive())
113
+ return;
114
+ if (!(data instanceof ArrayBuffer))
115
+ return finish();
116
+ if (!admitted) {
117
+ if (data.byteLength !== 0)
118
+ return finish();
119
+ admitted = true;
120
+ clearTimeout(timer);
121
+ return resolve(relay);
122
+ }
123
+ const record = new Uint8Array(data);
124
+ const lane = lanes[record[0] ?? -1];
125
+ if (!lane || record.byteLength > maxRecordBytes + 1)
126
+ return finish();
127
+ try {
128
+ receive(lane, record.subarray(1));
129
+ }
130
+ catch {
131
+ // A failed consumer cannot continue the stream or surface record details through global error handlers.
132
+ finish();
133
+ }
134
+ });
135
+ });
136
+ }
137
+ //# sourceMappingURL=relay-socket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay-socket.js","sourceRoot":"","sources":["../../../src/humain/remote/relay-socket.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAyB,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAA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;gBACxG,MAAM,EAAE,CAAC;YACV,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Ciphertext-only WSS connection to the Forge Remote relay; the transport a qualified SecureChannel wraps.\nimport { addAbortListener } from \"node:events\";\nimport { type HcodeEnvironment, resolveHcodeEnvironment } from \"../hcode/environment.ts\";\nimport { opaqueId } from \"./broker.ts\";\nimport { remoteDestinations } from \"./environment.ts\";\nimport type { LiveRoute } from \"./protocol.ts\";\n\nexport type RelayLane = \"setup\" | \"watch\";\n\n/** Admitted relay connection. Carries opaque records only and never retries or queues beyond one write. */\nexport interface RelaySocket {\n\t/** Aborts on peer close, protocol fault, consumer failure, slow socket or local close. */\n\treadonly signal: AbortSignal;\n\t/** False when the record was not written; a slow socket is closed rather than buffered. */\n\tsend(lane: RelayLane, frame: Uint8Array): boolean;\n\tclose(): void;\n}\n\ninterface RelayTicket {\n\troute: LiveRoute;\n\tkind: \"offer\" | \"pairing\";\n\tid: string;\n\ttoken: string;\n}\n\ninterface RelaySocketOptions {\n\tenvironment?: HcodeEnvironment;\n\t/** Identity-owner port: opens the URL with the Remote-audience credential for the exact account, never in the URL. */\n\tconnect(url: string): WebSocket;\n\tticket: RelayTicket;\n\treceive(lane: RelayLane, frame: Uint8Array): void;\n\tmaxRecordBytes?: number;\n\tsignal?: AbortSignal;\n}\n\nconst lanes = [\"setup\", \"watch\"] as const;\nconst routeKeys = [\"installId\", \"brokerEpoch\", \"sessionId\", \"attachmentId\", \"channelEpoch\"] as const;\nconst ADMISSION_MS = 5_000;\n\n/** Open the relay socket, present the one-use ticket first and resolve only on the relay's admission acknowledgement. */\nexport function openRelaySocket({\n\tenvironment = resolveHcodeEnvironment(),\n\tconnect,\n\tticket,\n\treceive,\n\tmaxRecordBytes = 1024 * 1024,\n\tsignal: parent,\n}: RelaySocketOptions): Promise<RelaySocket> {\n\t// Fixed message: URLs, tickets and socket errors are not Remote diagnostics.\n\tconst unavailable = () => new Error(\"Remote relay unavailable\");\n\tif (parent?.aborted) return Promise.reject(unavailable());\n\tlet destinations: ReturnType<typeof remoteDestinations>;\n\ttry {\n\t\tdestinations = remoteDestinations(environment);\n\t} catch {\n\t\treturn Promise.reject(unavailable());\n\t}\n\tconst { route, kind, id, token } = ticket;\n\tif (\n\t\t(kind !== \"offer\" && kind !== \"pairing\") ||\n\t\t!opaqueId(id) ||\n\t\t!/^[A-Za-z0-9_-]{43}$/.test(token) ||\n\t\t!routeKeys.every((key) => opaqueId(route[key]))\n\t)\n\t\treturn Promise.reject(unavailable());\n\tconst wire = JSON.stringify({\n\t\troute: Object.fromEntries(routeKeys.map((key) => [key, route[key]])),\n\t\tkind,\n\t\tid,\n\t\ttoken,\n\t});\n\tconst lifetime = new AbortController();\n\tlet ws: WebSocket;\n\ttry {\n\t\tws = connect(destinations.relay);\n\t} catch {\n\t\treturn Promise.reject(unavailable());\n\t}\n\tws.binaryType = \"arraybuffer\";\n\tlet admitted = false;\n\tconst finish = () => {\n\t\tif (lifetime.signal.aborted) return;\n\t\tlifetime.abort();\n\t\ttry {\n\t\t\tws.close();\n\t\t} catch {\n\t\t\t// The lifetime is already aborted; do not expose transport diagnostics.\n\t\t}\n\t};\n\tconst isLive = () => {\n\t\t// An earlier parent observer can reenter before our abort listener runs.\n\t\tif (parent?.aborted) finish();\n\t\treturn !lifetime.signal.aborted;\n\t};\n\tconst write = (data: string | Uint8Array<ArrayBuffer>) => {\n\t\tif (!isLive()) return false;\n\t\ttry {\n\t\t\tif (ws.readyState !== WebSocket.OPEN) {\n\t\t\t\tfinish();\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tws.send(data);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\tfinish();\n\t\t\treturn false;\n\t\t}\n\t};\n\tconst relay: RelaySocket = {\n\t\tsignal: lifetime.signal,\n\t\tsend(lane, frame) {\n\t\t\tif (!isLive() || frame.byteLength > maxRecordBytes) return false;\n\t\t\t// Never enqueue a second record while any bytes of the first remain buffered.\n\t\t\tif (ws.bufferedAmount !== 0) {\n\t\t\t\tfinish();\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tconst record = new Uint8Array(frame.byteLength + 1);\n\t\t\trecord[0] = lanes.indexOf(lane);\n\t\t\trecord.set(frame, 1);\n\t\t\treturn write(record);\n\t\t},\n\t\tclose: finish,\n\t};\n\treturn new Promise((resolve, reject) => {\n\t\t// Any end before the acknowledgement (timeout, abort, close, fault) rejects; later ends only abort.\n\t\tconst timer = setTimeout(finish, ADMISSION_MS);\n\t\tlet stopParent: Disposable | undefined;\n\t\tlifetime.signal.addEventListener(\n\t\t\t\"abort\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tstopParent?.[Symbol.dispose]();\n\t\t\t\tif (!admitted) reject(unavailable());\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tif (!isLive()) return;\n\t\tif (parent) stopParent = addAbortListener(parent, finish);\n\t\tws.addEventListener(\"open\", () => write(wire), { once: true });\n\t\tws.addEventListener(\"close\", finish);\n\t\tws.addEventListener(\"error\", finish);\n\t\tws.addEventListener(\"message\", ({ data }: MessageEvent) => {\n\t\t\tif (!isLive()) return;\n\t\t\tif (!(data instanceof ArrayBuffer)) return finish();\n\t\t\tif (!admitted) {\n\t\t\t\tif (data.byteLength !== 0) return finish();\n\t\t\t\tadmitted = true;\n\t\t\t\tclearTimeout(timer);\n\t\t\t\treturn resolve(relay);\n\t\t\t}\n\t\t\tconst record = new Uint8Array(data);\n\t\t\tconst lane = lanes[record[0] ?? -1];\n\t\t\tif (!lane || record.byteLength > maxRecordBytes + 1) return finish();\n\t\t\ttry {\n\t\t\t\treceive(lane, record.subarray(1));\n\t\t\t} catch {\n\t\t\t\t// A failed consumer cannot continue the stream or surface record details through global error handlers.\n\t\t\t\tfinish();\n\t\t\t}\n\t\t});\n\t});\n}\n"]}
@@ -0,0 +1,10 @@
1
+ /** Established, authenticated watch channel. Implementations must never fall back to plaintext. */
2
+ export interface SecureChannel {
3
+ /** Aborts on permanent disconnect or failure, even when no frame is in flight. */
4
+ readonly signal: AbortSignal;
5
+ send(frame: Uint8Array): Promise<void>;
6
+ close(): void;
7
+ }
8
+ /** Fail closed until the exact production profile is independently qualified. */
9
+ export declare function createProductionSecureChannel(): SecureChannel;
10
+ //# sourceMappingURL=secure-channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-channel.d.ts","sourceRoot":"","sources":["../../../src/humain/remote/secure-channel.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,MAAM,WAAW,aAAa;IAC7B,kFAAkF;IAClF,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,KAAK,IAAI,IAAI,CAAC;CACd;AAED,iFAAiF;AACjF,wBAAgB,6BAA6B,IAAI,aAAa,CAE7D"}
@@ -0,0 +1,5 @@
1
+ /** Fail closed until the exact production profile is independently qualified. */
2
+ export function createProductionSecureChannel() {
3
+ throw new Error("Remote production channel is not qualified");
4
+ }
5
+ //# sourceMappingURL=secure-channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-channel.js","sourceRoot":"","sources":["../../../src/humain/remote/secure-channel.ts"],"names":[],"mappings":"AAQA,iFAAiF;AACjF,MAAM,UAAU,6BAA6B;IAC5C,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["/** Established, authenticated watch channel. Implementations must never fall back to plaintext. */\nexport interface SecureChannel {\n\t/** Aborts on permanent disconnect or failure, even when no frame is in flight. */\n\treadonly signal: AbortSignal;\n\tsend(frame: Uint8Array): Promise<void>;\n\tclose(): void;\n}\n\n/** Fail closed until the exact production profile is independently qualified. */\nexport function createProductionSecureChannel(): SecureChannel {\n\tthrow new Error(\"Remote production channel is not qualified\");\n}\n"]}
@@ -0,0 +1,48 @@
1
+ import { type HcodeEnvironment, type HcodeEnvironmentName } from "../hcode/environment.ts";
2
+ import type { PendingWatchCandidate, WatchBroker } from "./broker.ts";
3
+ import { remoteDestinations } from "./environment.ts";
4
+ import type { WatchProjection } from "./host-watch.ts";
5
+ import type { LiveRoute } from "./protocol.ts";
6
+ interface RemoteTerminalUI {
7
+ confirm(title: string, message: string, signal?: AbortSignal): Promise<boolean>;
8
+ notice(message: string): void;
9
+ }
10
+ interface RemoteDevice {
11
+ id: string;
12
+ expiresAt: number;
13
+ lastUsedAt: number | null;
14
+ }
15
+ /** Only a qualified local composition root may supply this session-scoped port. */
16
+ export interface RemoteTerminalSession {
17
+ share(): void;
18
+ off(): void;
19
+ pair(): Promise<void>;
20
+ devices(): Promise<readonly RemoteDevice[]>;
21
+ revoke(id: string): Promise<void>;
22
+ }
23
+ export interface TerminalWatchBinding {
24
+ /** Selected runtime environment, never an independently configurable Remote origin. */
25
+ environment: HcodeEnvironment;
26
+ broker: Pick<WatchBroker, "shareSession" | "routeFor" | "unshare" | "revokePairing">;
27
+ ui: RemoteTerminalUI;
28
+ lifetime: AbortSignal;
29
+ source: WatchProjection;
30
+ /** Publish and present locally using the selected destinations; erase bootstrap material on cancellation. */
31
+ publish(route: LiveRoute, signal: AbortSignal, destinations: Readonly<ReturnType<typeof remoteDestinations>>): Promise<void>;
32
+ /** Qualified lookup owns the protocol; these destinations do not authorize an HTTP request. */
33
+ devices(signal: AbortSignal, destinations: Readonly<ReturnType<typeof remoteDestinations>>): Promise<readonly RemoteDevice[]>;
34
+ present(candidate: PendingWatchCandidate): {
35
+ deviceFingerprint: string;
36
+ expiresAtLabel: string;
37
+ };
38
+ }
39
+ /** Bind the command to one terminal and a started broker; never advertise without a local share. */
40
+ export declare function bindRemoteTerminalSession(binding: TerminalWatchBinding): RemoteTerminalSession;
41
+ export declare function runRemoteCommand(input: string, ui: RemoteTerminalUI, session?: RemoteTerminalSession, environment?: HcodeEnvironmentName): Promise<void>;
42
+ export declare function confirmTerminalPairing(ui: RemoteTerminalUI, candidate: PendingWatchCandidate, signal: AbortSignal, present: {
43
+ deviceFingerprint: string;
44
+ expiresAtLabel: string;
45
+ }): Promise<"allow" | "deny">;
46
+ export declare function remoteWatchNotice(ui: Pick<RemoteTerminalUI, "notice">, id: string, reconnect: boolean): void;
47
+ export {};
48
+ //# sourceMappingURL=terminal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../../src/humain/remote/terminal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,oBAAoB,EAAoB,MAAM,yBAAyB,CAAC;AAC7G,OAAO,KAAK,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,UAAU,gBAAgB;IACzB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAChF,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,UAAU,YAAY;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,mFAAmF;AACnF,MAAM,WAAW,qBAAqB;IACrC,KAAK,IAAI,IAAI,CAAC;IACd,GAAG,IAAI,IAAI,CAAC;IACZ,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,OAAO,IAAI,OAAO,CAAC,SAAS,YAAY,EAAE,CAAC,CAAC;IAC5C,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,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AAM,CAAC,CAuB3B;AAED,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI,CAI5G"}
@@ -0,0 +1,119 @@
1
+ import { raceWithAbortSignal } from "../../utils/abort.js";
2
+ import { hcodeDisplayName } from "../hcode/environment.js";
3
+ import { remoteDestinations } from "./environment.js";
4
+ /** Bind the command to one terminal and a started broker; never advertise without a local share. */
5
+ export function bindRemoteTerminalSession(binding) {
6
+ const { broker, ui, lifetime, source } = binding;
7
+ const destinations = remoteDestinations(binding.environment);
8
+ let share;
9
+ return {
10
+ share() {
11
+ lifetime.throwIfAborted();
12
+ if (share)
13
+ return;
14
+ const abort = new AbortController();
15
+ const signal = AbortSignal.any([lifetime, abort.signal]);
16
+ const id = broker.shareSession(source, (id, reconnect) => remoteWatchNotice(ui, id, reconnect), signal, (candidate, signal) => confirmTerminalPairing(ui, candidate, signal, binding.present(candidate)), () => {
17
+ if (share?.abort === abort)
18
+ share = undefined;
19
+ abort.abort();
20
+ });
21
+ share = { id, abort, signal };
22
+ },
23
+ off() {
24
+ if (share)
25
+ broker.unshare(share.id);
26
+ },
27
+ async pair() {
28
+ if (!share || share.signal.aborted)
29
+ throw new Error("Remote share unavailable");
30
+ const { id, signal } = share;
31
+ const route = broker.routeFor(id);
32
+ await raceWithAbortSignal(binding.publish(route, signal, destinations), signal);
33
+ },
34
+ async devices() {
35
+ lifetime.throwIfAborted();
36
+ return raceWithAbortSignal(binding.devices(lifetime, destinations), lifetime);
37
+ },
38
+ async revoke(id) {
39
+ lifetime.throwIfAborted();
40
+ await broker.revokePairing(id);
41
+ },
42
+ };
43
+ }
44
+ export async function runRemoteCommand(input, ui, session, environment = "production") {
45
+ const notice = (message) => ui.notice(`${hcodeDisplayName(environment)}: ${message}`);
46
+ if (!session) {
47
+ notice("Remote unavailable: the secure watch profile is not approved.");
48
+ return;
49
+ }
50
+ const args = input.trim().split(/\s+/).slice(1);
51
+ try {
52
+ if (!args.length) {
53
+ session.share();
54
+ notice("Remote watch enabled for this session. Use /remote pair to request a new offer.");
55
+ }
56
+ else if (args.length === 1 && args[0] === "off") {
57
+ session.off();
58
+ notice("Remote watch is off for this session.");
59
+ }
60
+ else if (args.length === 1 && args[0] === "pair") {
61
+ await session.pair();
62
+ }
63
+ else if (args[0] === "devices" && args.length === 1) {
64
+ const devices = await session.devices();
65
+ notice(devices.length
66
+ ? devices
67
+ .map(({ id, expiresAt, lastUsedAt }) => `${safeLabel(id)} — expires ${new Date(expiresAt).toISOString()}, last use ${lastUsedAt === null ? "unknown" : new Date(lastUsedAt).toISOString()}`)
68
+ .join("\n")
69
+ : "No Remote devices on this install.");
70
+ }
71
+ else if (args.length === 3 && args[0] === "devices" && args[1] === "revoke") {
72
+ const selected = args[2];
73
+ const ids = [...new Set((await session.devices()).map(({ id }) => id))].filter((id) => id === selected || selected === "--all");
74
+ if (!ids.length) {
75
+ notice("No matching Remote devices on this install.");
76
+ return;
77
+ }
78
+ if (!(await ui.confirm("Revoke Remote access?", `Revoke ${ids.map(safeLabel).join(", ")} on this install only?`)))
79
+ return;
80
+ for (const id of ids)
81
+ await session.revoke(id);
82
+ notice("Remote revoke saved on this install.");
83
+ }
84
+ else {
85
+ notice("Usage: /remote [pair | off | devices [revoke <id|--all>]]");
86
+ }
87
+ }
88
+ catch {
89
+ notice("Remote operation could not be confirmed.");
90
+ }
91
+ }
92
+ export async function confirmTerminalPairing(ui, candidate, signal, present) {
93
+ if (signal.aborted)
94
+ return "deny";
95
+ const scope = candidate.mode === "uv"
96
+ ? "Watch only; device trust lasts at most 30 days. Reconnect requires phone verification."
97
+ : "Watch only; one attachment for at most five minutes, no reconnect.";
98
+ try {
99
+ const prompt = ui.confirm("Allow Remote watch?", [
100
+ `Account: ${safeLabel(candidate.principal.accountId)} — ${hcodeDisplayName(candidate.principal.environment)}`,
101
+ `Install: ${safeLabel(candidate.route.installId)}; share: ${safeLabel(candidate.route.sessionId)}`,
102
+ `Device: ${safeLabel(present.deviceFingerprint)}; confirmation expires: ${safeLabel(present.expiresAtLabel)}`,
103
+ scope,
104
+ "The device cannot run commands or answer terminal prompts.",
105
+ ].join("\n"), signal);
106
+ const allow = await raceWithAbortSignal(prompt, signal);
107
+ return allow === true && !signal.aborted ? "allow" : "deny";
108
+ }
109
+ catch {
110
+ return "deny";
111
+ }
112
+ }
113
+ export function remoteWatchNotice(ui, id, reconnect) {
114
+ ui.notice(`Remote watcher ${reconnect ? "reconnected" : "connected"}. Use /remote off or /remote devices revoke ${safeLabel(id)}.`);
115
+ }
116
+ function safeLabel(value) {
117
+ return value.slice(0, 160).replace(/[^\x20-\x7e]/g, "?");
118
+ }
119
+ //# sourceMappingURL=terminal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal.js","sourceRoot":"","sources":["../../../src/humain/remote/terminal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAoD,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE7G,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AA6CtD,oGAAoG;AACpG,MAAM,UAAU,yBAAyB,CAAC,OAA6B;IACtE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IACjD,MAAM,YAAY,GAAG,kBAAkB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC7D,IAAI,KAA8E,CAAC;IACnF,OAAO;QACN,KAAK;YACJ,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC1B,IAAI,KAAK;gBAAE,OAAO;YAClB,MAAM,KAAK,GAAG,IAAI,eAAe,EAAE,CAAC;YACpC,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,C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,MAAM,CAAC;QACR,OAAO,MAAM,CAAC;IACf,CAAC;AACF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,EAAoC,EAAE,EAAU,EAAE,SAAkB;IACrG,EAAE,CAAC,MAAM,CACR,kBAAkB,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,+CAA+C,SAAS,CAAC,EAAE,CAAC,GAAG,CACxH,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import { raceWithAbortSignal } from \"../../utils/abort.ts\";\nimport { type HcodeEnvironment, type HcodeEnvironmentName, hcodeDisplayName } from \"../hcode/environment.ts\";\nimport type { PendingWatchCandidate, WatchBroker } from \"./broker.ts\";\nimport { remoteDestinations } from \"./environment.ts\";\nimport type { WatchProjection } from \"./host-watch.ts\";\nimport type { LiveRoute } from \"./protocol.ts\";\n\ninterface RemoteTerminalUI {\n\tconfirm(title: string, message: string, signal?: AbortSignal): Promise<boolean>;\n\tnotice(message: string): void;\n}\n\ninterface RemoteDevice {\n\tid: string;\n\texpiresAt: number;\n\tlastUsedAt: number | null;\n}\n\n/** Only a qualified local composition root may supply this session-scoped port. */\nexport interface RemoteTerminalSession {\n\tshare(): void;\n\toff(): void;\n\tpair(): Promise<void>; // Render and erase bootstrap material locally, never through notice/history.\n\tdevices(): Promise<readonly RemoteDevice[]>;\n\trevoke(id: string): Promise<void>;\n}\n\nexport interface TerminalWatchBinding {\n\t/** Selected runtime environment, never an independently configurable Remote origin. */\n\tenvironment: HcodeEnvironment;\n\tbroker: Pick<WatchBroker, \"shareSession\" | \"routeFor\" | \"unshare\" | \"revokePairing\">;\n\tui: RemoteTerminalUI;\n\tlifetime: AbortSignal;\n\tsource: WatchProjection;\n\t/** Publish and present locally using the selected destinations; erase bootstrap material on cancellation. */\n\tpublish(\n\t\troute: LiveRoute,\n\t\tsignal: AbortSignal,\n\t\tdestinations: Readonly<ReturnType<typeof remoteDestinations>>,\n\t): Promise<void>;\n\t/** Qualified lookup owns the protocol; these destinations do not authorize an HTTP request. */\n\tdevices(\n\t\tsignal: AbortSignal,\n\t\tdestinations: Readonly<ReturnType<typeof remoteDestinations>>,\n\t): Promise<readonly RemoteDevice[]>;\n\tpresent(candidate: PendingWatchCandidate): { deviceFingerprint: string; expiresAtLabel: string };\n}\n\n/** Bind the command to one terminal and a started broker; never advertise without a local share. */\nexport function bindRemoteTerminalSession(binding: TerminalWatchBinding): RemoteTerminalSession {\n\tconst { broker, ui, lifetime, source } = binding;\n\tconst destinations = remoteDestinations(binding.environment);\n\tlet share: { id: string; abort: AbortController; signal: AbortSignal } | undefined;\n\treturn {\n\t\tshare() {\n\t\t\tlifetime.throwIfAborted();\n\t\t\tif (share) return;\n\t\t\tconst abort = new AbortController();\n\t\t\tconst signal = AbortSignal.any([lifetime, abort.signal]);\n\t\t\tconst id = broker.shareSession(\n\t\t\t\tsource,\n\t\t\t\t(id, reconnect) => remoteWatchNotice(ui, id, reconnect),\n\t\t\t\tsignal,\n\t\t\t\t(candidate, signal) => confirmTerminalPairing(ui, candidate, signal, binding.present(candidate)),\n\t\t\t\t() => {\n\t\t\t\t\tif (share?.abort === abort) share = undefined;\n\t\t\t\t\tabort.abort();\n\t\t\t\t},\n\t\t\t);\n\t\t\tshare = { id, abort, signal };\n\t\t},\n\t\toff() {\n\t\t\tif (share) broker.unshare(share.id);\n\t\t},\n\t\tasync pair() {\n\t\t\tif (!share || share.signal.aborted) throw new Error(\"Remote share unavailable\");\n\t\t\tconst { id, signal } = share;\n\t\t\tconst route = broker.routeFor(id);\n\t\t\tawait raceWithAbortSignal(binding.publish(route, signal, destinations), signal);\n\t\t},\n\t\tasync devices() {\n\t\t\tlifetime.throwIfAborted();\n\t\t\treturn raceWithAbortSignal(binding.devices(lifetime, destinations), lifetime);\n\t\t},\n\t\tasync revoke(id) {\n\t\t\tlifetime.throwIfAborted();\n\t\t\tawait broker.revokePairing(id);\n\t\t},\n\t};\n}\n\nexport async function runRemoteCommand(\n\tinput: string,\n\tui: RemoteTerminalUI,\n\tsession?: RemoteTerminalSession,\n\tenvironment: HcodeEnvironmentName = \"production\",\n): Promise<void> {\n\tconst notice = (message: string) => ui.notice(`${hcodeDisplayName(environment)}: ${message}`);\n\tif (!session) {\n\t\tnotice(\"Remote unavailable: the secure watch profile is not approved.\");\n\t\treturn;\n\t}\n\tconst args = input.trim().split(/\\s+/).slice(1);\n\ttry {\n\t\tif (!args.length) {\n\t\t\tsession.share();\n\t\t\tnotice(\"Remote watch enabled for this session. Use /remote pair to request a new offer.\");\n\t\t} else if (args.length === 1 && args[0] === \"off\") {\n\t\t\tsession.off();\n\t\t\tnotice(\"Remote watch is off for this session.\");\n\t\t} else if (args.length === 1 && args[0] === \"pair\") {\n\t\t\tawait session.pair();\n\t\t} else if (args[0] === \"devices\" && args.length === 1) {\n\t\t\tconst devices = await session.devices();\n\t\t\tnotice(\n\t\t\t\tdevices.length\n\t\t\t\t\t? devices\n\t\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t\t({ id, expiresAt, lastUsedAt }) =>\n\t\t\t\t\t\t\t\t\t`${safeLabel(id)} — expires ${new Date(expiresAt).toISOString()}, last use ${lastUsedAt === null ? \"unknown\" : new Date(lastUsedAt).toISOString()}`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.join(\"\\n\")\n\t\t\t\t\t: \"No Remote devices on this install.\",\n\t\t\t);\n\t\t} else if (args.length === 3 && args[0] === \"devices\" && args[1] === \"revoke\") {\n\t\t\tconst selected = args[2];\n\t\t\tconst ids = [...new Set((await session.devices()).map(({ id }) => id))].filter(\n\t\t\t\t(id) => id === selected || selected === \"--all\",\n\t\t\t);\n\t\t\tif (!ids.length) {\n\t\t\t\tnotice(\"No matching Remote devices on this install.\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (\n\t\t\t\t!(await ui.confirm(\n\t\t\t\t\t\"Revoke Remote access?\",\n\t\t\t\t\t`Revoke ${ids.map(safeLabel).join(\", \")} on this install only?`,\n\t\t\t\t))\n\t\t\t)\n\t\t\t\treturn;\n\t\t\tfor (const id of ids) await session.revoke(id);\n\t\t\tnotice(\"Remote revoke saved on this install.\");\n\t\t} else {\n\t\t\tnotice(\"Usage: /remote [pair | off | devices [revoke <id|--all>]]\");\n\t\t}\n\t} catch {\n\t\tnotice(\"Remote operation could not be confirmed.\");\n\t}\n}\n\nexport async function confirmTerminalPairing(\n\tui: RemoteTerminalUI,\n\tcandidate: PendingWatchCandidate,\n\tsignal: AbortSignal,\n\tpresent: { deviceFingerprint: string; expiresAtLabel: string },\n): Promise<\"allow\" | \"deny\"> {\n\tif (signal.aborted) return \"deny\";\n\tconst scope =\n\t\tcandidate.mode === \"uv\"\n\t\t\t? \"Watch only; device trust lasts at most 30 days. Reconnect requires phone verification.\"\n\t\t\t: \"Watch only; one attachment for at most five minutes, no reconnect.\";\n\ttry {\n\t\tconst prompt = ui.confirm(\n\t\t\t\"Allow Remote watch?\",\n\t\t\t[\n\t\t\t\t`Account: ${safeLabel(candidate.principal.accountId)} — ${hcodeDisplayName(candidate.principal.environment)}`,\n\t\t\t\t`Install: ${safeLabel(candidate.route.installId)}; share: ${safeLabel(candidate.route.sessionId)}`,\n\t\t\t\t`Device: ${safeLabel(present.deviceFingerprint)}; confirmation expires: ${safeLabel(present.expiresAtLabel)}`,\n\t\t\t\tscope,\n\t\t\t\t\"The device cannot run commands or answer terminal prompts.\",\n\t\t\t].join(\"\\n\"),\n\t\t\tsignal,\n\t\t);\n\t\tconst allow = await raceWithAbortSignal(prompt, signal);\n\t\treturn allow === true && !signal.aborted ? \"allow\" : \"deny\";\n\t} catch {\n\t\treturn \"deny\";\n\t}\n}\n\nexport function remoteWatchNotice(ui: Pick<RemoteTerminalUI, \"notice\">, id: string, reconnect: boolean): void {\n\tui.notice(\n\t\t`Remote watcher ${reconnect ? \"reconnected\" : \"connected\"}. Use /remote off or /remote devices revoke ${safeLabel(id)}.`,\n\t);\n}\n\nfunction safeLabel(value: string): string {\n\treturn value.slice(0, 160).replace(/[^\\x20-\\x7e]/g, \"?\");\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { type HcodeEnvironment } from "../hcode/environment.ts";
2
+ import type { HcodeAccountPort, HcodeAccountRef } from "../hcode/ports.ts";
3
+ import type { LiveRoute } from "./protocol.ts";
4
+ interface TicketRequest {
5
+ route: LiveRoute;
6
+ kind: "offer" | "pairing";
7
+ id: string;
8
+ }
9
+ interface TicketClientOptions {
10
+ environment?: HcodeEnvironment;
11
+ account: Pick<HcodeAccountPort, "status" | "subscribe">;
12
+ /** Identity-owner transport for the Remote audience only. Must fence the exact account before I/O. */
13
+ fetchRemote(expected: Readonly<HcodeAccountRef>, url: string, init: RequestInit): Promise<Response>;
14
+ /** Trusted install-key adapter. The private key never enters the ticket client. */
15
+ signInstallProof(expected: Readonly<HcodeAccountRef>, binding: Readonly<{
16
+ installId: string;
17
+ target: string;
18
+ challenge: string;
19
+ }>, signal: AbortSignal): Promise<string>;
20
+ now?: () => number;
21
+ }
22
+ /** Issue a scoped, short-lived host ticket without exposing credentials or retrying an ambiguous write. */
23
+ export declare function createRemoteTicketClient({ environment, account, fetchRemote, signInstallProof, now, }: TicketClientOptions): (reference: HcodeAccountRef, request: TicketRequest, parent?: AbortSignal) => Promise<Readonly<{
24
+ token: string;
25
+ expiresAt: number;
26
+ route: Readonly<{
27
+ installId: string;
28
+ brokerEpoch: string;
29
+ sessionId: string;
30
+ attachmentId: string;
31
+ channelEpoch: string;
32
+ }>;
33
+ }>>;
34
+ export {};
35
+ //# sourceMappingURL=tickets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tickets.d.ts","sourceRoot":"","sources":["../../../src/humain/remote/tickets.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAA2B,M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