@kya-os/cli 1.8.1 → 1.8.3

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 (385) hide show
  1. package/dist/commands/agent.d.ts +35 -0
  2. package/dist/commands/agent.d.ts.map +1 -0
  3. package/dist/commands/agent.js +321 -0
  4. package/dist/commands/agent.js.map +1 -0
  5. package/dist/commands/build.js +2 -2
  6. package/dist/commands/build.js.map +1 -1
  7. package/dist/commands/check.js +3 -3
  8. package/dist/commands/check.js.map +1 -1
  9. package/dist/commands/checkpoint-init.d.ts +1 -1
  10. package/dist/commands/checkpoint-init.d.ts.map +1 -1
  11. package/dist/commands/checkpoint-init.js +8 -41
  12. package/dist/commands/checkpoint-init.js.map +1 -1
  13. package/dist/commands/claim.js +2 -2
  14. package/dist/commands/claim.js.map +1 -1
  15. package/dist/commands/dco.d.ts +59 -0
  16. package/dist/commands/dco.d.ts.map +1 -1
  17. package/dist/commands/dco.js +280 -5
  18. package/dist/commands/dco.js.map +1 -1
  19. package/dist/commands/dev.js +1 -1
  20. package/dist/commands/dev.js.map +1 -1
  21. package/dist/commands/doctor.d.ts.map +1 -1
  22. package/dist/commands/doctor.js +18 -24
  23. package/dist/commands/doctor.js.map +1 -1
  24. package/dist/commands/env.js +6 -6
  25. package/dist/commands/env.js.map +1 -1
  26. package/dist/commands/identity.js +3 -3
  27. package/dist/commands/identity.js.map +1 -1
  28. package/dist/commands/init-stages.d.ts +141 -0
  29. package/dist/commands/init-stages.d.ts.map +1 -0
  30. package/dist/commands/init-stages.js +684 -0
  31. package/dist/commands/init-stages.js.map +1 -0
  32. package/dist/commands/init.d.ts +46 -16
  33. package/dist/commands/init.d.ts.map +1 -1
  34. package/dist/commands/init.js +229 -279
  35. package/dist/commands/init.js.map +1 -1
  36. package/dist/commands/orchestrator.d.ts +18 -0
  37. package/dist/commands/orchestrator.d.ts.map +1 -0
  38. package/dist/commands/orchestrator.js +251 -0
  39. package/dist/commands/orchestrator.js.map +1 -0
  40. package/dist/commands/register.d.ts +1 -1
  41. package/dist/commands/register.d.ts.map +1 -1
  42. package/dist/commands/register.js +35 -7
  43. package/dist/commands/register.js.map +1 -1
  44. package/dist/commands/review.d.ts +48 -0
  45. package/dist/commands/review.d.ts.map +1 -0
  46. package/dist/commands/review.js +220 -0
  47. package/dist/commands/review.js.map +1 -0
  48. package/dist/commands/rotate.js +4 -4
  49. package/dist/commands/rotate.js.map +1 -1
  50. package/dist/commands/score.d.ts +15 -0
  51. package/dist/commands/score.d.ts.map +1 -0
  52. package/dist/commands/score.js +471 -0
  53. package/dist/commands/score.js.map +1 -0
  54. package/dist/commands/start.js +3 -3
  55. package/dist/commands/start.js.map +1 -1
  56. package/dist/commands/status.js +1 -1
  57. package/dist/commands/status.js.map +1 -1
  58. package/dist/commands/verify.js +6 -6
  59. package/dist/commands/verify.js.map +1 -1
  60. package/dist/dco.d.ts +4 -0
  61. package/dist/dco.d.ts.map +1 -0
  62. package/dist/dco.js +23 -0
  63. package/dist/dco.js.map +1 -0
  64. package/dist/index.js +52 -9
  65. package/dist/orchestrator/daemon.d.ts +137 -0
  66. package/dist/orchestrator/daemon.d.ts.map +1 -0
  67. package/dist/orchestrator/daemon.js +242 -0
  68. package/dist/orchestrator/daemon.js.map +1 -0
  69. package/dist/orchestrator/db/dispatches.d.ts +108 -0
  70. package/dist/orchestrator/db/dispatches.d.ts.map +1 -0
  71. package/dist/orchestrator/db/dispatches.js +122 -0
  72. package/dist/orchestrator/db/dispatches.js.map +1 -0
  73. package/dist/orchestrator/db/index.d.ts +50 -0
  74. package/dist/orchestrator/db/index.d.ts.map +1 -0
  75. package/dist/orchestrator/db/index.js +116 -0
  76. package/dist/orchestrator/db/index.js.map +1 -0
  77. package/dist/orchestrator/db/journal.d.ts +93 -0
  78. package/dist/orchestrator/db/journal.d.ts.map +1 -0
  79. package/dist/orchestrator/db/journal.js +91 -0
  80. package/dist/orchestrator/db/journal.js.map +1 -0
  81. package/dist/orchestrator/db/liveness.d.ts +97 -0
  82. package/dist/orchestrator/db/liveness.d.ts.map +1 -0
  83. package/dist/orchestrator/db/liveness.js +105 -0
  84. package/dist/orchestrator/db/liveness.js.map +1 -0
  85. package/dist/orchestrator/db/mission.d.ts +78 -0
  86. package/dist/orchestrator/db/mission.d.ts.map +1 -0
  87. package/dist/orchestrator/db/mission.js +99 -0
  88. package/dist/orchestrator/db/mission.js.map +1 -0
  89. package/dist/orchestrator/db/schema.d.ts +14 -0
  90. package/dist/orchestrator/db/schema.d.ts.map +1 -0
  91. package/dist/orchestrator/db/schema.js +169 -0
  92. package/dist/orchestrator/db/schema.js.map +1 -0
  93. package/dist/orchestrator/db/tickets.d.ts +147 -0
  94. package/dist/orchestrator/db/tickets.d.ts.map +1 -0
  95. package/dist/orchestrator/db/tickets.js +238 -0
  96. package/dist/orchestrator/db/tickets.js.map +1 -0
  97. package/dist/orchestrator/db/verdicts.d.ts +187 -0
  98. package/dist/orchestrator/db/verdicts.d.ts.map +1 -0
  99. package/dist/orchestrator/db/verdicts.js +197 -0
  100. package/dist/orchestrator/db/verdicts.js.map +1 -0
  101. package/dist/orchestrator/events.d.ts +69 -0
  102. package/dist/orchestrator/events.d.ts.map +1 -0
  103. package/dist/orchestrator/events.js +20 -0
  104. package/dist/orchestrator/events.js.map +1 -0
  105. package/dist/orchestrator/github-credential-anchor-sender.d.ts +159 -0
  106. package/dist/orchestrator/github-credential-anchor-sender.d.ts.map +1 -0
  107. package/dist/orchestrator/github-credential-anchor-sender.js +313 -0
  108. package/dist/orchestrator/github-credential-anchor-sender.js.map +1 -0
  109. package/dist/orchestrator/hub-dispatch.d.ts +120 -0
  110. package/dist/orchestrator/hub-dispatch.d.ts.map +1 -0
  111. package/dist/orchestrator/hub-dispatch.js +257 -0
  112. package/dist/orchestrator/hub-dispatch.js.map +1 -0
  113. package/dist/orchestrator/hub-observer.d.ts +201 -0
  114. package/dist/orchestrator/hub-observer.d.ts.map +1 -0
  115. package/dist/orchestrator/hub-observer.js +474 -0
  116. package/dist/orchestrator/hub-observer.js.map +1 -0
  117. package/dist/orchestrator/journal-writer.d.ts +80 -0
  118. package/dist/orchestrator/journal-writer.d.ts.map +1 -0
  119. package/dist/orchestrator/journal-writer.js +113 -0
  120. package/dist/orchestrator/journal-writer.js.map +1 -0
  121. package/dist/orchestrator/mcp/server.d.ts +136 -0
  122. package/dist/orchestrator/mcp/server.d.ts.map +1 -0
  123. package/dist/orchestrator/mcp/server.js +582 -0
  124. package/dist/orchestrator/mcp/server.js.map +1 -0
  125. package/dist/orchestrator/mcp/stdio.d.ts +22 -0
  126. package/dist/orchestrator/mcp/stdio.d.ts.map +1 -0
  127. package/dist/orchestrator/mcp/stdio.js +51 -0
  128. package/dist/orchestrator/mcp/stdio.js.map +1 -0
  129. package/dist/orchestrator/review.d.ts +131 -0
  130. package/dist/orchestrator/review.d.ts.map +1 -0
  131. package/dist/orchestrator/review.js +322 -0
  132. package/dist/orchestrator/review.js.map +1 -0
  133. package/dist/tui/app.d.ts +33 -0
  134. package/dist/tui/app.d.ts.map +1 -0
  135. package/dist/tui/app.js +71 -0
  136. package/dist/tui/app.js.map +1 -0
  137. package/dist/tui/components.d.ts +110 -0
  138. package/dist/tui/components.d.ts.map +1 -0
  139. package/dist/tui/components.js +118 -0
  140. package/dist/tui/components.js.map +1 -0
  141. package/dist/tui/index.d.ts +30 -0
  142. package/dist/tui/index.d.ts.map +1 -0
  143. package/dist/tui/index.js +95 -0
  144. package/dist/tui/index.js.map +1 -0
  145. package/dist/tui/keymap.d.ts +33 -0
  146. package/dist/tui/keymap.d.ts.map +1 -0
  147. package/dist/tui/keymap.js +49 -0
  148. package/dist/tui/keymap.js.map +1 -0
  149. package/dist/tui/nav.d.ts +29 -0
  150. package/dist/tui/nav.d.ts.map +1 -0
  151. package/dist/tui/nav.js +39 -0
  152. package/dist/tui/nav.js.map +1 -0
  153. package/dist/tui/sanitize.d.ts +25 -0
  154. package/dist/tui/sanitize.d.ts.map +1 -0
  155. package/dist/tui/sanitize.js +36 -0
  156. package/dist/tui/sanitize.js.map +1 -0
  157. package/dist/tui/theme.d.ts +32 -0
  158. package/dist/tui/theme.d.ts.map +1 -0
  159. package/dist/tui/theme.js +63 -0
  160. package/dist/tui/theme.js.map +1 -0
  161. package/dist/tui/views/agents.d.ts +67 -0
  162. package/dist/tui/views/agents.d.ts.map +1 -0
  163. package/dist/tui/views/agents.js +231 -0
  164. package/dist/tui/views/agents.js.map +1 -0
  165. package/dist/tui/views/index.d.ts +93 -0
  166. package/dist/tui/views/index.d.ts.map +1 -0
  167. package/dist/tui/views/index.js +150 -0
  168. package/dist/tui/views/index.js.map +1 -0
  169. package/dist/tui/views/registry.d.ts +22 -0
  170. package/dist/tui/views/registry.d.ts.map +1 -0
  171. package/dist/tui/views/registry.js +110 -0
  172. package/dist/tui/views/registry.js.map +1 -0
  173. package/dist/utils/agent/backoff.d.ts +31 -0
  174. package/dist/utils/agent/backoff.d.ts.map +1 -0
  175. package/dist/utils/agent/backoff.js +51 -0
  176. package/dist/utils/agent/backoff.js.map +1 -0
  177. package/dist/utils/agent/markers.d.ts +87 -0
  178. package/dist/utils/agent/markers.d.ts.map +1 -0
  179. package/dist/utils/agent/markers.js +147 -0
  180. package/dist/utils/agent/markers.js.map +1 -0
  181. package/dist/utils/agent/review.d.ts +67 -0
  182. package/dist/utils/agent/review.d.ts.map +1 -0
  183. package/dist/utils/agent/review.js +305 -0
  184. package/dist/utils/agent/review.js.map +1 -0
  185. package/dist/utils/agent/spawn-agent.d.ts +117 -0
  186. package/dist/utils/agent/spawn-agent.d.ts.map +1 -0
  187. package/dist/utils/agent/spawn-agent.js +177 -0
  188. package/dist/utils/agent/spawn-agent.js.map +1 -0
  189. package/dist/utils/agent/task.d.ts +101 -0
  190. package/dist/utils/agent/task.d.ts.map +1 -0
  191. package/dist/utils/agent/task.js +357 -0
  192. package/dist/utils/agent/task.js.map +1 -0
  193. package/dist/utils/agent/verify.d.ts +47 -0
  194. package/dist/utils/agent/verify.d.ts.map +1 -0
  195. package/dist/utils/agent/verify.js +144 -0
  196. package/dist/utils/agent/verify.js.map +1 -0
  197. package/dist/utils/agent-detector.d.ts +48 -0
  198. package/dist/utils/agent-detector.d.ts.map +1 -0
  199. package/dist/utils/agent-detector.js +74 -0
  200. package/dist/utils/agent-detector.js.map +1 -0
  201. package/dist/utils/agent-profile-stage.d.ts +70 -0
  202. package/dist/utils/agent-profile-stage.d.ts.map +1 -0
  203. package/dist/utils/agent-profile-stage.js +153 -0
  204. package/dist/utils/agent-profile-stage.js.map +1 -0
  205. package/dist/utils/agent-profiles.d.ts +27 -0
  206. package/dist/utils/agent-profiles.d.ts.map +1 -0
  207. package/dist/utils/agent-profiles.js +61 -0
  208. package/dist/utils/agent-profiles.js.map +1 -0
  209. package/dist/utils/checkpoint-api.d.ts +1 -1
  210. package/dist/utils/checkpoint-api.js +1 -1
  211. package/dist/utils/checkpoint-env.d.ts +1 -1
  212. package/dist/utils/checkpoint-env.js +2 -2
  213. package/dist/utils/checkpoint-env.js.map +1 -1
  214. package/dist/utils/checkpoint-scaffold.d.ts +1 -1
  215. package/dist/utils/checkpoint-scaffold.js +1 -1
  216. package/dist/utils/cli-kit/browser.d.ts +24 -0
  217. package/dist/utils/cli-kit/browser.d.ts.map +1 -0
  218. package/dist/utils/cli-kit/browser.js +58 -0
  219. package/dist/utils/cli-kit/browser.js.map +1 -0
  220. package/dist/utils/cli-kit/claim-polling.d.ts +18 -0
  221. package/dist/utils/cli-kit/claim-polling.d.ts.map +1 -0
  222. package/dist/utils/{claim-polling.js → cli-kit/claim-polling.js} +19 -26
  223. package/dist/utils/cli-kit/claim-polling.js.map +1 -0
  224. package/dist/utils/cli-kit/diagnostics.d.ts +9 -0
  225. package/dist/utils/cli-kit/diagnostics.d.ts.map +1 -0
  226. package/dist/utils/cli-kit/diagnostics.js +11 -0
  227. package/dist/utils/cli-kit/diagnostics.js.map +1 -0
  228. package/dist/utils/cli-kit/fs-safe.d.ts +14 -0
  229. package/dist/utils/cli-kit/fs-safe.d.ts.map +1 -0
  230. package/dist/utils/cli-kit/fs-safe.js +20 -0
  231. package/dist/utils/cli-kit/fs-safe.js.map +1 -0
  232. package/dist/utils/cli-kit/index.d.ts +15 -0
  233. package/dist/utils/cli-kit/index.d.ts.map +1 -0
  234. package/dist/utils/cli-kit/index.js +10 -0
  235. package/dist/utils/cli-kit/index.js.map +1 -0
  236. package/dist/utils/cli-kit/json-file.d.ts +21 -0
  237. package/dist/utils/cli-kit/json-file.d.ts.map +1 -0
  238. package/dist/utils/cli-kit/json-file.js +51 -0
  239. package/dist/utils/cli-kit/json-file.js.map +1 -0
  240. package/dist/utils/cli-kit/marker-block.d.ts +26 -0
  241. package/dist/utils/cli-kit/marker-block.d.ts.map +1 -0
  242. package/dist/utils/cli-kit/marker-block.js +61 -0
  243. package/dist/utils/cli-kit/marker-block.js.map +1 -0
  244. package/dist/utils/cli-kit/paths.d.ts +15 -0
  245. package/dist/utils/cli-kit/paths.d.ts.map +1 -0
  246. package/dist/utils/cli-kit/paths.js +21 -0
  247. package/dist/utils/cli-kit/paths.js.map +1 -0
  248. package/dist/utils/cli-kit/secure-storage.d.ts +14 -0
  249. package/dist/utils/cli-kit/secure-storage.d.ts.map +1 -0
  250. package/dist/utils/cli-kit/secure-storage.js +20 -0
  251. package/dist/utils/cli-kit/secure-storage.js.map +1 -0
  252. package/dist/utils/cli-kit/step-report.d.ts +16 -0
  253. package/dist/utils/cli-kit/step-report.d.ts.map +1 -0
  254. package/dist/utils/cli-kit/step-report.js +36 -0
  255. package/dist/utils/cli-kit/step-report.js.map +1 -0
  256. package/dist/utils/dco/agent-metadata.d.ts +1 -1
  257. package/dist/utils/dco/agent-metadata.js +1 -1
  258. package/dist/utils/dco/agent-metadata.js.map +1 -1
  259. package/dist/utils/dco/claude-config.d.ts +18 -14
  260. package/dist/utils/dco/claude-config.d.ts.map +1 -1
  261. package/dist/utils/dco/claude-config.js +31 -97
  262. package/dist/utils/dco/claude-config.js.map +1 -1
  263. package/dist/utils/dco/dispatch.d.ts +134 -0
  264. package/dist/utils/dco/dispatch.d.ts.map +1 -0
  265. package/dist/utils/dco/dispatch.js +399 -0
  266. package/dist/utils/dco/dispatch.js.map +1 -0
  267. package/dist/utils/dco/fix.d.ts +122 -0
  268. package/dist/utils/dco/fix.d.ts.map +1 -0
  269. package/dist/utils/dco/fix.js +560 -0
  270. package/dist/utils/dco/fix.js.map +1 -0
  271. package/dist/utils/dco/git-config.d.ts.map +1 -1
  272. package/dist/utils/dco/git-config.js +5 -3
  273. package/dist/utils/dco/git-config.js.map +1 -1
  274. package/dist/utils/dco/github.d.ts +101 -0
  275. package/dist/utils/dco/github.d.ts.map +1 -1
  276. package/dist/utils/dco/github.js +133 -0
  277. package/dist/utils/dco/github.js.map +1 -1
  278. package/dist/utils/dco/paths.d.ts +1 -8
  279. package/dist/utils/dco/paths.d.ts.map +1 -1
  280. package/dist/utils/dco/paths.js +3 -12
  281. package/dist/utils/dco/paths.js.map +1 -1
  282. package/dist/utils/dco/render.d.ts +1 -1
  283. package/dist/utils/dco/render.d.ts.map +1 -1
  284. package/dist/utils/dco/render.js +4 -21
  285. package/dist/utils/dco/render.js.map +1 -1
  286. package/dist/utils/dco/resolve-agent.d.ts +54 -0
  287. package/dist/utils/dco/resolve-agent.d.ts.map +1 -0
  288. package/dist/utils/dco/resolve-agent.js +164 -0
  289. package/dist/utils/dco/resolve-agent.js.map +1 -0
  290. package/dist/utils/dco/setup.d.ts +10 -7
  291. package/dist/utils/dco/setup.d.ts.map +1 -1
  292. package/dist/utils/dco/setup.js +264 -200
  293. package/dist/utils/dco/setup.js.map +1 -1
  294. package/dist/utils/dco/signing-key-writer.d.ts +40 -0
  295. package/dist/utils/dco/signing-key-writer.d.ts.map +1 -0
  296. package/dist/utils/dco/signing-key-writer.js +76 -0
  297. package/dist/utils/dco/signing-key-writer.js.map +1 -0
  298. package/dist/utils/dco/ssh-key.d.ts +50 -0
  299. package/dist/utils/dco/ssh-key.d.ts.map +1 -1
  300. package/dist/utils/dco/ssh-key.js +129 -8
  301. package/dist/utils/dco/ssh-key.js.map +1 -1
  302. package/dist/utils/dco/status.d.ts +1 -1
  303. package/dist/utils/dco/status.d.ts.map +1 -1
  304. package/dist/utils/dco/status.js +3 -3
  305. package/dist/utils/dco/status.js.map +1 -1
  306. package/dist/utils/dco/verify.d.ts +170 -0
  307. package/dist/utils/dco/verify.d.ts.map +1 -0
  308. package/dist/utils/dco/verify.js +550 -0
  309. package/dist/utils/dco/verify.js.map +1 -0
  310. package/dist/utils/dependency-installer.d.ts +37 -0
  311. package/dist/utils/dependency-installer.d.ts.map +1 -0
  312. package/dist/utils/dependency-installer.js +32 -0
  313. package/dist/utils/dependency-installer.js.map +1 -0
  314. package/dist/utils/github-credential-stage.d.ts +87 -0
  315. package/dist/utils/github-credential-stage.d.ts.map +1 -0
  316. package/dist/utils/github-credential-stage.js +168 -0
  317. package/dist/utils/github-credential-stage.js.map +1 -0
  318. package/dist/utils/github-credential.d.ts +160 -0
  319. package/dist/utils/github-credential.d.ts.map +1 -0
  320. package/dist/utils/github-credential.js +308 -0
  321. package/dist/utils/github-credential.js.map +1 -0
  322. package/dist/utils/gitignore.d.ts +17 -0
  323. package/dist/utils/gitignore.d.ts.map +1 -0
  324. package/dist/utils/gitignore.js +40 -0
  325. package/dist/utils/gitignore.js.map +1 -0
  326. package/dist/utils/hub-config.d.ts +21 -0
  327. package/dist/utils/hub-config.d.ts.map +1 -0
  328. package/dist/utils/hub-config.js +28 -0
  329. package/dist/utils/hub-config.js.map +1 -0
  330. package/dist/utils/identity-heal.d.ts +16 -0
  331. package/dist/utils/identity-heal.d.ts.map +1 -0
  332. package/dist/utils/identity-heal.js +37 -0
  333. package/dist/utils/identity-heal.js.map +1 -0
  334. package/dist/utils/init/pipeline.d.ts +74 -0
  335. package/dist/utils/init/pipeline.d.ts.map +1 -0
  336. package/dist/utils/init/pipeline.js +96 -0
  337. package/dist/utils/init/pipeline.js.map +1 -0
  338. package/dist/utils/poll.d.ts +15 -1
  339. package/dist/utils/poll.d.ts.map +1 -1
  340. package/dist/utils/poll.js +6 -3
  341. package/dist/utils/poll.js.map +1 -1
  342. package/dist/utils/register-agent-identity.d.ts +67 -0
  343. package/dist/utils/register-agent-identity.d.ts.map +1 -0
  344. package/dist/utils/register-agent-identity.js +34 -0
  345. package/dist/utils/register-agent-identity.js.map +1 -0
  346. package/dist/utils/review/did-web-key.d.ts +34 -0
  347. package/dist/utils/review/did-web-key.d.ts.map +1 -0
  348. package/dist/utils/review/did-web-key.js +104 -0
  349. package/dist/utils/review/did-web-key.js.map +1 -0
  350. package/dist/utils/review/load-registry.d.ts +33 -0
  351. package/dist/utils/review/load-registry.d.ts.map +1 -0
  352. package/dist/utils/review/load-registry.js +62 -0
  353. package/dist/utils/review/load-registry.js.map +1 -0
  354. package/dist/utils/review/verdict-verify.d.ts +43 -0
  355. package/dist/utils/review/verdict-verify.d.ts.map +1 -0
  356. package/dist/utils/review/verdict-verify.js +53 -0
  357. package/dist/utils/review/verdict-verify.js.map +1 -0
  358. package/dist/utils/review-registry-writer.d.ts +52 -0
  359. package/dist/utils/review-registry-writer.d.ts.map +1 -0
  360. package/dist/utils/review-registry-writer.js +79 -0
  361. package/dist/utils/review-registry-writer.js.map +1 -0
  362. package/dist/utils/should-install-dependency.d.ts +17 -0
  363. package/dist/utils/should-install-dependency.d.ts.map +1 -0
  364. package/dist/utils/should-install-dependency.js +25 -0
  365. package/dist/utils/should-install-dependency.js.map +1 -0
  366. package/dist/utils/tool-readiness.d.ts +57 -0
  367. package/dist/utils/tool-readiness.d.ts.map +1 -0
  368. package/dist/utils/tool-readiness.js +114 -0
  369. package/dist/utils/tool-readiness.js.map +1 -0
  370. package/dist/utils/which.d.ts +2 -0
  371. package/dist/utils/which.d.ts.map +1 -0
  372. package/dist/utils/which.js +22 -0
  373. package/dist/utils/which.js.map +1 -0
  374. package/dist/version.d.ts +15 -0
  375. package/dist/version.d.ts.map +1 -0
  376. package/dist/version.js +29 -0
  377. package/dist/version.js.map +1 -0
  378. package/package.json +19 -6
  379. package/dist/utils/claim-polling.d.ts +0 -21
  380. package/dist/utils/claim-polling.d.ts.map +0 -1
  381. package/dist/utils/claim-polling.js.map +0 -1
  382. package/dist/utils/dco/fs-safe.d.ts +0 -14
  383. package/dist/utils/dco/fs-safe.d.ts.map +0 -1
  384. package/dist/utils/dco/fs-safe.js +0 -20
  385. package/dist/utils/dco/fs-safe.js.map +0 -1
@@ -0,0 +1,313 @@
1
+ /**
2
+ * Anchoring a GitHub credential in the hub (review-loop P16, commit 3).
3
+ *
4
+ * Builds a signed `GithubCredentialAnchor` (see `@kya-os/contracts/handshake/
5
+ * github-credential-anchor.ts`) from a locally stored credential
6
+ * (`utils/github-credential.ts`) and delivers it to the configured hub over
7
+ * the SAME observer wire path `hub-observer.ts` speaks: `observe` hello,
8
+ * challenge, proof-of-possession -- see that file's module doc for why this
9
+ * package never imports `@kya-os/compute` and instead speaks the shared
10
+ * wire format directly. Unlike `HubObserver`, this is a ONE-SHOT
11
+ * connect/authenticate/submit/await-result/close, not a long-lived
12
+ * reconnecting subscription -- a different lifecycle for a different job,
13
+ * so it does not extend or wrap that class.
14
+ *
15
+ * The anchor is signed and the wire connection authenticated with the SAME
16
+ * key: the designated agent profile's signing key
17
+ * (`signingKeyPath(agentSlug)`, the exact file `dco setup`/`dco fix` already
18
+ * use -- see `ssh-key.ts`'s `parseEd25519SshPrivateKeyPem`). That is what
19
+ * lets the hub check "the anchor's proof verifies against the DID that
20
+ * authenticated this very connection" without a second key or a fresh
21
+ * resolution: the hub already knows this socket proved control of `did`
22
+ * before a single `credential_anchor` frame arrives.
23
+ *
24
+ * No hub configured, or the hub unreachable: the anchor is queued at
25
+ * `~/.mcpi/github/pending-anchor.json` (fingerprints and proof only -- by
26
+ * construction, since `GithubCredentialAnchorSchema` holds no secret) for a
27
+ * later `kya-os init` or P17's wrapper connection to deliver.
28
+ *
29
+ * @module cli/orchestrator/github-credential-anchor-sender
30
+ */
31
+ import { existsSync, readFileSync, rmSync } from "node:fs";
32
+ import { join } from "node:path";
33
+ import WebSocket from "ws";
34
+ import { GithubCredentialAnchorMessageSchema, GithubCredentialAnchorResultSchema, GithubCredentialAnchorSchema, ObserverHelloSchema, getGithubCredentialAnchorSigningString, } from "@kya-os/contracts/handshake";
35
+ import { publicJwkFor, respondToObserverChallenge } from "./hub-observer.js";
36
+ import { parseEd25519SshPrivateKeyPem, signWithEd25519Seed } from "../utils/dco/ssh-key.js";
37
+ import { signingKeyPath } from "../utils/dco/paths.js";
38
+ import { ensureSecureDir, writeFileAtomicSafe } from "../utils/cli-kit/index.js";
39
+ import { credentialsDir } from "../utils/github-credential.js";
40
+ /**
41
+ * Derive the `ObserverIdentity` (did + raw Ed25519 seed) an agent profile
42
+ * signs and authenticates with, from its converted signing key file
43
+ * (`signingKeyPath(agentSlug)`, the same file `dco setup`/`dco fix` use).
44
+ * Shared by {@link buildGithubCredentialAnchor} (a fresh anchor's signer)
45
+ * and `github-credential-stage.ts` (re-authenticating to deliver a
46
+ * previously queued anchor, where no new anchor is being built) so both
47
+ * paths derive the SAME identity for the same profile from one place.
48
+ */
49
+ export function identityForAgentProfile(agentDid, agentSlug, readSigningKeyPemImpl = (slug) => readFileSync(signingKeyPath(slug), "utf-8")) {
50
+ const pem = readSigningKeyPemImpl(agentSlug);
51
+ const { seed } = parseEd25519SshPrivateKeyPem(pem);
52
+ return { did: agentDid, privateKey: seed.toString("base64") };
53
+ }
54
+ /**
55
+ * Build and sign a `GithubCredentialAnchor` for `credential`. Signing stays
56
+ * entirely inside this module -- callers never touch key material, only the
57
+ * finished anchor and the identity derived alongside it (matching how
58
+ * `dco fix.ts` keeps its Ed25519 seed scoped to one function, extended here
59
+ * to the one extra byproduct -- the wire identity -- that a second read of
60
+ * the same file would otherwise require).
61
+ */
62
+ export function buildGithubCredentialAnchor(credential, fingerprints, params) {
63
+ const now = params.now ?? (() => new Date().toISOString());
64
+ const rest = {
65
+ githubLogin: credential.githubLogin,
66
+ tokenFingerprint: fingerprints.tokenFingerprint,
67
+ webhookSecretFingerprint: fingerprints.webhookSecretFingerprint,
68
+ scopes: credential.scopes,
69
+ agentDids: params.agentDids,
70
+ createdAt: now(),
71
+ ...(params.supersedes ? { supersedes: params.supersedes } : {}),
72
+ };
73
+ const identity = params.readSigningKeyPemImpl
74
+ ? identityForAgentProfile(params.agentDid, params.agentSlug, params.readSigningKeyPemImpl)
75
+ : identityForAgentProfile(params.agentDid, params.agentSlug);
76
+ const seed = Buffer.from(identity.privateKey, "base64");
77
+ const signingString = getGithubCredentialAnchorSigningString(rest);
78
+ const signature = signWithEd25519Seed(seed, Buffer.from(signingString, "utf8")).toString("base64url");
79
+ const anchor = GithubCredentialAnchorSchema.parse({
80
+ ...rest,
81
+ proof: { alg: "Ed25519", signature },
82
+ });
83
+ return { anchor, identity };
84
+ }
85
+ /**
86
+ * Connect to the hub as an authenticated observer, submit `anchor` once
87
+ * admitted, and resolve with whether the hub accepted it. Always settles
88
+ * (never hangs): a timeout, a socket error, or an early close all resolve
89
+ * `{ delivered: false, reason }` rather than rejecting -- the caller's
90
+ * fallback is "queue it locally," not "crash the init stage."
91
+ */
92
+ export function sendGithubCredentialAnchor(anchor, options) {
93
+ return new Promise((resolve) => {
94
+ let settled = false;
95
+ let sentAnchor = false;
96
+ const wsFactory = options.wsFactory ?? ((endpoint) => new WebSocket(endpoint));
97
+ let ws;
98
+ try {
99
+ ws = wsFactory(options.endpoint);
100
+ }
101
+ catch (err) {
102
+ resolve({ delivered: false, reason: message(err) });
103
+ return;
104
+ }
105
+ const finish = (result) => {
106
+ if (settled)
107
+ return;
108
+ settled = true;
109
+ clearTimeout(timer);
110
+ try {
111
+ ws.close();
112
+ }
113
+ catch {
114
+ /* already closing */
115
+ }
116
+ resolve(result);
117
+ };
118
+ const timer = setTimeout(() => {
119
+ finish({ delivered: false, reason: `hub at ${options.endpoint} did not respond in time` });
120
+ }, options.timeoutMs ?? 10000);
121
+ ws.on("open", () => {
122
+ try {
123
+ const hello = ObserverHelloSchema.parse({
124
+ type: "observe",
125
+ did: options.identity.did,
126
+ publicKey: publicJwkFor(options.identity),
127
+ });
128
+ ws.send(JSON.stringify(hello));
129
+ }
130
+ catch (err) {
131
+ finish({ delivered: false, reason: message(err) });
132
+ }
133
+ });
134
+ ws.on("error", (err) => finish({ delivered: false, reason: message(err) }));
135
+ ws.on("close", (code, reason) => {
136
+ finish({
137
+ delivered: false,
138
+ reason: `hub closed the connection (${code}${reason.length ? `: ${reason.toString()}` : ""})`,
139
+ });
140
+ });
141
+ ws.on("message", (raw) => {
142
+ void handleFrame(raw.toString());
143
+ });
144
+ async function handleFrame(text) {
145
+ if (settled)
146
+ return;
147
+ let msg;
148
+ try {
149
+ const parsed = JSON.parse(text);
150
+ if (typeof parsed !== "object" || parsed === null)
151
+ return;
152
+ msg = parsed;
153
+ }
154
+ catch {
155
+ return; // a frame we cannot parse is not a frame we can act on
156
+ }
157
+ if (msg["type"] === "challenge") {
158
+ try {
159
+ const frame = await respondToObserverChallenge(options.identity, msg);
160
+ if (frame)
161
+ ws.send(frame);
162
+ }
163
+ catch (err) {
164
+ finish({ delivered: false, reason: message(err) });
165
+ }
166
+ return;
167
+ }
168
+ // "snapshot" is the observer-admission signal (see hub-observer.ts) --
169
+ // once it lands, this socket is authenticated and may submit.
170
+ if (msg["type"] === "snapshot" && !sentAnchor) {
171
+ sentAnchor = true;
172
+ try {
173
+ const anchorMessage = GithubCredentialAnchorMessageSchema.parse({
174
+ type: "credential_anchor",
175
+ anchor,
176
+ });
177
+ ws.send(JSON.stringify(anchorMessage));
178
+ }
179
+ catch (err) {
180
+ finish({ delivered: false, reason: message(err) });
181
+ }
182
+ return;
183
+ }
184
+ if (msg["type"] === "credential_anchor_result") {
185
+ const result = GithubCredentialAnchorResultSchema.safeParse(msg);
186
+ if (!result.success) {
187
+ finish({ delivered: false, reason: "malformed credential_anchor_result frame from hub" });
188
+ return;
189
+ }
190
+ finish(result.data.ok
191
+ ? { delivered: true }
192
+ : { delivered: false, reason: result.data.error ?? "hub rejected the anchor" });
193
+ }
194
+ }
195
+ });
196
+ }
197
+ function message(err) {
198
+ return err instanceof Error ? err.message : String(err);
199
+ }
200
+ // ── Pending queue (offline path) ───────────────────────────────────────
201
+ /** ~/.mcpi/github/pending-anchor.json -- fingerprints and proof only; no secrets by construction. */
202
+ export function pendingAnchorPath() {
203
+ return join(credentialsDir(), "pending-anchor.json");
204
+ }
205
+ /**
206
+ * Queue `anchor` (signed by `signerDid`) at {@link pendingAnchorPath}.
207
+ * Never throws: a real filesystem error here (permissions, ENOSPC)
208
+ * degrades to a reported failure rather than propagating, matching
209
+ * {@link deliverGithubCredentialAnchor}'s own "never throws" contract -- a
210
+ * queue write is itself part of that degrade-to-pending path, not a
211
+ * separate one that could still blow past it.
212
+ */
213
+ function writePendingAnchor(anchor, signerDid) {
214
+ try {
215
+ ensureSecureDir(credentialsDir());
216
+ const record = { anchor, signerDid };
217
+ writeFileAtomicSafe(pendingAnchorPath(), JSON.stringify(record, null, 2) + "\n", 0o600);
218
+ return { ok: true };
219
+ }
220
+ catch (err) {
221
+ return { ok: false, reason: message(err) };
222
+ }
223
+ }
224
+ /** The queued anchor and its signer, or undefined if none is pending (or the file is unreadable/corrupt). */
225
+ export function readPendingAnchor() {
226
+ const path = pendingAnchorPath();
227
+ if (!existsSync(path))
228
+ return undefined;
229
+ try {
230
+ const parsed = JSON.parse(readFileSync(path, "utf-8"));
231
+ if (!parsed || typeof parsed !== "object")
232
+ return undefined;
233
+ const { anchor, signerDid } = parsed;
234
+ if (typeof signerDid !== "string" || signerDid.length === 0)
235
+ return undefined;
236
+ const result = GithubCredentialAnchorSchema.safeParse(anchor);
237
+ return result.success ? { anchor: result.data, signerDid } : undefined;
238
+ }
239
+ catch {
240
+ return undefined;
241
+ }
242
+ }
243
+ export function clearPendingAnchor() {
244
+ rmSync(pendingAnchorPath(), { force: true });
245
+ }
246
+ /**
247
+ * Deliver `anchor` to the hub if one is configured and reachable; otherwise
248
+ * queue it at {@link pendingAnchorPath} and exit cleanly. Never throws --
249
+ * every failure mode degrades to "pending," which is exactly the offline
250
+ * path the init stage needs to complete without a hub.
251
+ */
252
+ export async function deliverGithubCredentialAnchor(anchor, identity, options = {}) {
253
+ const onNotice = options.onNotice ?? (() => { });
254
+ if (!options.hubEndpoint) {
255
+ const queued = writePendingAnchor(anchor, identity.did);
256
+ onNotice(queued.ok
257
+ ? "No hub configured -- the GitHub credential anchor is pending and will be delivered on a later `kya-os init`."
258
+ : `No hub configured, and the anchor could not even be queued locally (${queued.reason}) -- the credential itself is still saved, but re-run \`kya-os init\` once this is fixed.`);
259
+ return { status: "pending", reason: "no hub configured" };
260
+ }
261
+ const sendImpl = options.sendImpl ?? sendGithubCredentialAnchor;
262
+ const result = await sendImpl(anchor, { endpoint: options.hubEndpoint, identity });
263
+ if (result.delivered) {
264
+ clearPendingAnchor();
265
+ return { status: "delivered" };
266
+ }
267
+ const queued = writePendingAnchor(anchor, identity.did);
268
+ onNotice(queued.ok
269
+ ? `Could not deliver the GitHub credential anchor to the hub (${result.reason}) -- it is pending.`
270
+ : `Could not deliver the GitHub credential anchor to the hub (${result.reason}), and it could not even be queued locally (${queued.reason}) -- the credential itself is still saved, but re-run \`kya-os init\` once this is fixed.`);
271
+ return { status: "pending", reason: result.reason };
272
+ }
273
+ /**
274
+ * Attempt delivery of a previously queued anchor (e.g. from a later
275
+ * `kya-os init`, or P17's wrapper connection). A no-op, reported distinctly,
276
+ * when nothing is queued.
277
+ *
278
+ * `resolveIdentity` maps the queued anchor's recorded `signerDid` to that
279
+ * profile's CURRENT identity -- never a caller-guessed one. `listProfiles()`
280
+ * has no defined order (`readdirSync`), so "the first profile on the
281
+ * machine" today is not reliably the profile that signed a PRIOR anchor;
282
+ * looking it up by the DID actually recorded at queue time is what makes
283
+ * this retry succeed instead of failing proof verification against the
284
+ * wrong key. Never throws, matching every other function in this module's
285
+ * "degrade to pending" contract: `resolveIdentity` typically ends up
286
+ * calling {@link identityForAgentProfile}, which reads a signing key file
287
+ * off disk and throws if it's missing or unreadable -- a real possibility
288
+ * (deleted, corrupted, permissions) that must fall through to "pending"
289
+ * exactly like a resolved-but-unusable identity, not crash the caller.
290
+ */
291
+ export async function deliverPendingGithubCredentialAnchor(resolveIdentity, options = {}) {
292
+ const pending = readPendingAnchor();
293
+ if (!pending)
294
+ return { status: "none" };
295
+ let identity;
296
+ let resolveError;
297
+ try {
298
+ identity = resolveIdentity(pending.signerDid);
299
+ }
300
+ catch (err) {
301
+ resolveError = message(err);
302
+ }
303
+ if (!identity) {
304
+ const onNotice = options.onNotice ?? (() => { });
305
+ const reason = resolveError
306
+ ? `the signing profile (${pending.signerDid}) could not be loaded (${resolveError})`
307
+ : `the signing profile (${pending.signerDid}) is no longer on this machine`;
308
+ onNotice(`Cannot retry delivering the queued GitHub credential anchor: ${reason}.`);
309
+ return { status: "pending", reason: `signer profile ${pending.signerDid} unresolvable: ${reason}` };
310
+ }
311
+ return deliverGithubCredentialAnchor(pending.anchor, identity, options);
312
+ }
313
+ //# sourceMappingURL=github-credential-anchor-sender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-credential-anchor-sender.js","sourceRoot":"","sources":["../../src/orchestrator/github-credential-anchor-sender.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,EACL,mCAAmC,EACnC,kCAAkC,EAClC,4BAA4B,EAC5B,mBAAmB,EACnB,sCAAsC,GAEvC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAyB,MAAM,mBAAmB,CAAC;AACpG,OAAO,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,MAAM,yB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EAAE,SAAS,EAAE,MAAM,EAAE,kBAAkB,OAAO,CAAC,SAAS,kBAAkB,MAAM,EAAE,EAAE,CAAC;IACtG,CAAC;IACD,OAAO,6BAA6B,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * The TUI's one control-plane action (review-loop P18 commit 4): dispatch
3
+ * a task to a connected agent.
4
+ *
5
+ * Trust boundary: this opens a short-lived, authenticated observer
6
+ * connection -- the SAME wire pattern `hub-observer.ts`'s long-lived
7
+ * `HubObserver` uses (contracts `./handshake`'s hello/challenge/proof
8
+ * frames, the #686 precedent), reusing its exported helpers rather than
9
+ * re-deriving the handshake. It sends exactly one `fleet.dispatch` frame,
10
+ * waits for exactly one `fleet.dispatch.result`, and closes -- no
11
+ * reconnect, no history, no long-lived state, because a TUI keystroke is
12
+ * a single request, not a subscription.
13
+ *
14
+ * `fleet.dispatch` here is NOT `@kya-os/compute`'s HTTP `fleet-mcp`
15
+ * surface (`packages/compute/src/didcomm/fleet-mcp.ts`), which is bearer-
16
+ * token/org-scoped and has no notion of a per-agent signing key. It is
17
+ * the wire-level message `packages/compute/src/didcomm/hub.ts` already
18
+ * handles directly on an admitted OBSERVER socket
19
+ * (`ws.on("message", ...)` inside `transport.onObserver`): a JSON frame
20
+ * `{ type: "fleet.dispatch", taskId, toDid, description, context?,
21
+ * timeoutMs? }`, answered with `{ type: "fleet.dispatch.result", taskId,
22
+ * status, response?, error?, ... }`. Reusing this existing hub-side
23
+ * handler is why this file adds nothing to `@kya-os/contracts` or
24
+ * `@kya-os/compute` -- the wire shape already exists and this PR's
25
+ * `Package:` line is `@kya-os/cli` alone.
26
+ *
27
+ * The hub proposes, the target's on-disk command allowlist (P17, epic
28
+ * decision 10) disposes: a refusal comes back as an ordinary
29
+ * `fleet.dispatch.result` with a non-"completed" status, which the caller
30
+ * renders as a refusal, not an error (see `AgentsView`'s handling of
31
+ * `status === "refused"`).
32
+ *
33
+ * @module cli/orchestrator/hub-dispatch
34
+ */
35
+ import WebSocket from "ws";
36
+ import { type ObserverIdentity } from "./hub-observer.js";
37
+ import type { AgentProfile } from "../utils/agent-profiles.js";
38
+ export interface DispatchWireResult {
39
+ taskId: string;
40
+ status: string;
41
+ response?: string;
42
+ error?: string;
43
+ ok: boolean;
44
+ }
45
+ export interface DispatchTaskConfig {
46
+ /** e.g. `ws://127.0.0.1:18821` or `wss://did-web-knowthat-ai-hub.fly.dev:4000`. */
47
+ endpoint: string;
48
+ /** Omit to connect anonymously, which only a loopback hub will accept. */
49
+ identity?: ObserverIdentity;
50
+ /** How long to wait for the observer handshake (hello/challenge/proof + snapshot). */
51
+ handshakeTimeoutMs?: number;
52
+ /** How long to wait for the fleet.dispatch.result frame once dispatched. */
53
+ dispatchTimeoutMs?: number;
54
+ /** Injectable transport seam for tests; defaults to the real `ws` client. */
55
+ wsFactory?: (endpoint: string) => WebSocket;
56
+ }
57
+ /**
58
+ * Opens one observer connection, authenticates if asked to, sends one
59
+ * `fleet.dispatch` frame for `targetDid`/`command`, and resolves with its
60
+ * `fleet.dispatch.result` -- or rejects on a connection/handshake/timeout
61
+ * failure. Always closes the socket before settling, on every path.
62
+ */
63
+ export declare function dispatchTask(config: DispatchTaskConfig, targetDid: string, command: string): Promise<DispatchWireResult>;
64
+ /**
65
+ * Is this endpoint loopback-only? Mirrors `isPlaintextNonLoopback`'s host
66
+ * set but answers a different question: that function asks "is this
67
+ * unencrypted AND remote" (a warn-but-allow case); this asks "is this
68
+ * unreachable from anywhere but this machine" (the ONLY case where
69
+ * connecting with no identity at all -- `--anonymous`-equivalent -- is
70
+ * appropriate for a write action like dispatch).
71
+ */
72
+ export declare function isLoopbackEndpoint(endpoint: string): boolean;
73
+ /**
74
+ * Builds the identity used to authenticate the dispatch connection, from
75
+ * the profile whose row is focused in the TUI. Every profile's key
76
+ * lives under `~/.mcpi/keys/<slug>` in the SSH-signing format
77
+ * `dco setup` writes (see `signing-key-writer.ts`); profiles never
78
+ * persist a raw seed on disk, so the seed is recovered from that SSH
79
+ * key via the same parser `dco fix` already uses to sign a fix
80
+ * attestation from the same file (`parseEd25519SshPrivateKeyPem`) rather
81
+ * than adding a second place that stores key material.
82
+ *
83
+ * Authenticating AS the profile being dispatched to -- rather than some
84
+ * separate "which of my identities is primary" concept, which does not
85
+ * exist anywhere else in this codebase -- is a deliberate scope
86
+ * decision: every profile under `~/.mcpi/keys/` belongs to the one
87
+ * operator running this TUI, so proving control of the row already in
88
+ * view is sufficient authorization and needs no new concept.
89
+ *
90
+ * Undefined if the key file is missing or not in the format this
91
+ * codebase writes -- the caller falls back to loopback-only anonymous
92
+ * dispatch in that case, matching `orchestrator daemon`'s own
93
+ * `--anonymous` precedent.
94
+ */
95
+ export declare function resolveProfileIdentity(profile: AgentProfile): ObserverIdentity | undefined;
96
+ export interface DispatchOutcome {
97
+ ok: boolean;
98
+ status: string;
99
+ detail?: string;
100
+ /**
101
+ * Set when `hubConfig.endpoint` is plaintext `ws://` to a non-loopback
102
+ * host: the same condition `orchestrator daemon` (`commands/
103
+ * orchestrator.ts`) warns about before attaching with a real identity,
104
+ * via the same `isPlaintextNonLoopback` helper. Surfaced through the
105
+ * outcome rather than a raw `console.warn` because this call happens
106
+ * from inside an active Ink render -- an unmediated console write here
107
+ * would corrupt the TUI's own screen buffer instead of reaching the user.
108
+ */
109
+ warning?: string;
110
+ }
111
+ /**
112
+ * The TUI-facing entry point: resolve the hub and the dispatching
113
+ * identity, dispatch, and reduce every failure mode (no hub configured,
114
+ * no usable key on a non-loopback hub, a transport/handshake error) to
115
+ * the same `DispatchOutcome` shape the agents view renders -- so the UI
116
+ * never has to distinguish "the wire call threw" from "the wire call
117
+ * returned an unhappy status".
118
+ */
119
+ export declare function dispatchToProfile(profile: AgentProfile, command: string, wsFactory?: DispatchTaskConfig["wsFactory"]): Promise<DispatchOutcome>;
120
+ //# sourceMappingURL=hub-dispatch.d.ts.map
@@ -0,0 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