@kya-os/cli 1.7.0 → 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 (390) 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 +32 -0
  10. package/dist/commands/checkpoint-init.d.ts.map +1 -0
  11. package/dist/commands/checkpoint-init.js +521 -0
  12. package/dist/commands/checkpoint-init.js.map +1 -0
  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 +62 -11
  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 +86 -0
  210. package/dist/utils/checkpoint-api.d.ts.map +1 -0
  211. package/dist/utils/checkpoint-api.js +196 -0
  212. package/dist/utils/checkpoint-api.js.map +1 -0
  213. package/dist/utils/checkpoint-env.d.ts +23 -0
  214. package/dist/utils/checkpoint-env.d.ts.map +1 -0
  215. package/dist/utils/checkpoint-env.js +59 -0
  216. package/dist/utils/checkpoint-env.js.map +1 -0
  217. package/dist/utils/checkpoint-scaffold.d.ts +61 -0
  218. package/dist/utils/checkpoint-scaffold.d.ts.map +1 -0
  219. package/dist/utils/checkpoint-scaffold.js +268 -0
  220. package/dist/utils/checkpoint-scaffold.js.map +1 -0
  221. package/dist/utils/cli-kit/browser.d.ts +24 -0
  222. package/dist/utils/cli-kit/browser.d.ts.map +1 -0
  223. package/dist/utils/cli-kit/browser.js +58 -0
  224. package/dist/utils/cli-kit/browser.js.map +1 -0
  225. package/dist/utils/cli-kit/claim-polling.d.ts +18 -0
  226. package/dist/utils/cli-kit/claim-polling.d.ts.map +1 -0
  227. package/dist/utils/{claim-polling.js → cli-kit/claim-polling.js} +19 -26
  228. package/dist/utils/cli-kit/claim-polling.js.map +1 -0
  229. package/dist/utils/cli-kit/diagnostics.d.ts +9 -0
  230. package/dist/utils/cli-kit/diagnostics.d.ts.map +1 -0
  231. package/dist/utils/cli-kit/diagnostics.js +11 -0
  232. package/dist/utils/cli-kit/diagnostics.js.map +1 -0
  233. package/dist/utils/cli-kit/fs-safe.d.ts +14 -0
  234. package/dist/utils/cli-kit/fs-safe.d.ts.map +1 -0
  235. package/dist/utils/cli-kit/fs-safe.js +20 -0
  236. package/dist/utils/cli-kit/fs-safe.js.map +1 -0
  237. package/dist/utils/cli-kit/index.d.ts +15 -0
  238. package/dist/utils/cli-kit/index.d.ts.map +1 -0
  239. package/dist/utils/cli-kit/index.js +10 -0
  240. package/dist/utils/cli-kit/index.js.map +1 -0
  241. package/dist/utils/cli-kit/json-file.d.ts +21 -0
  242. package/dist/utils/cli-kit/json-file.d.ts.map +1 -0
  243. package/dist/utils/cli-kit/json-file.js +51 -0
  244. package/dist/utils/cli-kit/json-file.js.map +1 -0
  245. package/dist/utils/cli-kit/marker-block.d.ts +26 -0
  246. package/dist/utils/cli-kit/marker-block.d.ts.map +1 -0
  247. package/dist/utils/cli-kit/marker-block.js +61 -0
  248. package/dist/utils/cli-kit/marker-block.js.map +1 -0
  249. package/dist/utils/cli-kit/paths.d.ts +15 -0
  250. package/dist/utils/cli-kit/paths.d.ts.map +1 -0
  251. package/dist/utils/cli-kit/paths.js +21 -0
  252. package/dist/utils/cli-kit/paths.js.map +1 -0
  253. package/dist/utils/cli-kit/secure-storage.d.ts +14 -0
  254. package/dist/utils/cli-kit/secure-storage.d.ts.map +1 -0
  255. package/dist/utils/cli-kit/secure-storage.js +20 -0
  256. package/dist/utils/cli-kit/secure-storage.js.map +1 -0
  257. package/dist/utils/cli-kit/step-report.d.ts +16 -0
  258. package/dist/utils/cli-kit/step-report.d.ts.map +1 -0
  259. package/dist/utils/cli-kit/step-report.js +36 -0
  260. package/dist/utils/cli-kit/step-report.js.map +1 -0
  261. package/dist/utils/dco/agent-metadata.d.ts +1 -1
  262. package/dist/utils/dco/agent-metadata.js +1 -1
  263. package/dist/utils/dco/agent-metadata.js.map +1 -1
  264. package/dist/utils/dco/claude-config.d.ts +18 -8
  265. package/dist/utils/dco/claude-config.d.ts.map +1 -1
  266. package/dist/utils/dco/claude-config.js +33 -79
  267. package/dist/utils/dco/claude-config.js.map +1 -1
  268. package/dist/utils/dco/dispatch.d.ts +134 -0
  269. package/dist/utils/dco/dispatch.d.ts.map +1 -0
  270. package/dist/utils/dco/dispatch.js +399 -0
  271. package/dist/utils/dco/dispatch.js.map +1 -0
  272. package/dist/utils/dco/fix.d.ts +122 -0
  273. package/dist/utils/dco/fix.d.ts.map +1 -0
  274. package/dist/utils/dco/fix.js +560 -0
  275. package/dist/utils/dco/fix.js.map +1 -0
  276. package/dist/utils/dco/git-config.d.ts.map +1 -1
  277. package/dist/utils/dco/git-config.js +5 -3
  278. package/dist/utils/dco/git-config.js.map +1 -1
  279. package/dist/utils/dco/github.d.ts +101 -0
  280. package/dist/utils/dco/github.d.ts.map +1 -1
  281. package/dist/utils/dco/github.js +133 -0
  282. package/dist/utils/dco/github.js.map +1 -1
  283. package/dist/utils/dco/paths.d.ts +1 -8
  284. package/dist/utils/dco/paths.d.ts.map +1 -1
  285. package/dist/utils/dco/paths.js +3 -12
  286. package/dist/utils/dco/paths.js.map +1 -1
  287. package/dist/utils/dco/render.d.ts +1 -1
  288. package/dist/utils/dco/render.d.ts.map +1 -1
  289. package/dist/utils/dco/render.js +4 -21
  290. package/dist/utils/dco/render.js.map +1 -1
  291. package/dist/utils/dco/resolve-agent.d.ts +54 -0
  292. package/dist/utils/dco/resolve-agent.d.ts.map +1 -0
  293. package/dist/utils/dco/resolve-agent.js +164 -0
  294. package/dist/utils/dco/resolve-agent.js.map +1 -0
  295. package/dist/utils/dco/setup.d.ts +10 -7
  296. package/dist/utils/dco/setup.d.ts.map +1 -1
  297. package/dist/utils/dco/setup.js +264 -199
  298. package/dist/utils/dco/setup.js.map +1 -1
  299. package/dist/utils/dco/signing-key-writer.d.ts +40 -0
  300. package/dist/utils/dco/signing-key-writer.d.ts.map +1 -0
  301. package/dist/utils/dco/signing-key-writer.js +76 -0
  302. package/dist/utils/dco/signing-key-writer.js.map +1 -0
  303. package/dist/utils/dco/ssh-key.d.ts +50 -0
  304. package/dist/utils/dco/ssh-key.d.ts.map +1 -1
  305. package/dist/utils/dco/ssh-key.js +129 -8
  306. package/dist/utils/dco/ssh-key.js.map +1 -1
  307. package/dist/utils/dco/status.d.ts +1 -1
  308. package/dist/utils/dco/status.d.ts.map +1 -1
  309. package/dist/utils/dco/status.js +3 -3
  310. package/dist/utils/dco/status.js.map +1 -1
  311. package/dist/utils/dco/verify.d.ts +170 -0
  312. package/dist/utils/dco/verify.d.ts.map +1 -0
  313. package/dist/utils/dco/verify.js +550 -0
  314. package/dist/utils/dco/verify.js.map +1 -0
  315. package/dist/utils/dependency-installer.d.ts +37 -0
  316. package/dist/utils/dependency-installer.d.ts.map +1 -0
  317. package/dist/utils/dependency-installer.js +32 -0
  318. package/dist/utils/dependency-installer.js.map +1 -0
  319. package/dist/utils/github-credential-stage.d.ts +87 -0
  320. package/dist/utils/github-credential-stage.d.ts.map +1 -0
  321. package/dist/utils/github-credential-stage.js +168 -0
  322. package/dist/utils/github-credential-stage.js.map +1 -0
  323. package/dist/utils/github-credential.d.ts +160 -0
  324. package/dist/utils/github-credential.d.ts.map +1 -0
  325. package/dist/utils/github-credential.js +308 -0
  326. package/dist/utils/github-credential.js.map +1 -0
  327. package/dist/utils/gitignore.d.ts +17 -0
  328. package/dist/utils/gitignore.d.ts.map +1 -0
  329. package/dist/utils/gitignore.js +40 -0
  330. package/dist/utils/gitignore.js.map +1 -0
  331. package/dist/utils/hub-config.d.ts +21 -0
  332. package/dist/utils/hub-config.d.ts.map +1 -0
  333. package/dist/utils/hub-config.js +28 -0
  334. package/dist/utils/hub-config.js.map +1 -0
  335. package/dist/utils/identity-heal.d.ts +16 -0
  336. package/dist/utils/identity-heal.d.ts.map +1 -0
  337. package/dist/utils/identity-heal.js +37 -0
  338. package/dist/utils/identity-heal.js.map +1 -0
  339. package/dist/utils/init/pipeline.d.ts +74 -0
  340. package/dist/utils/init/pipeline.d.ts.map +1 -0
  341. package/dist/utils/init/pipeline.js +96 -0
  342. package/dist/utils/init/pipeline.js.map +1 -0
  343. package/dist/utils/poll.d.ts +64 -0
  344. package/dist/utils/poll.d.ts.map +1 -0
  345. package/dist/utils/poll.js +76 -0
  346. package/dist/utils/poll.js.map +1 -0
  347. package/dist/utils/register-agent-identity.d.ts +67 -0
  348. package/dist/utils/register-agent-identity.d.ts.map +1 -0
  349. package/dist/utils/register-agent-identity.js +34 -0
  350. package/dist/utils/register-agent-identity.js.map +1 -0
  351. package/dist/utils/review/did-web-key.d.ts +34 -0
  352. package/dist/utils/review/did-web-key.d.ts.map +1 -0
  353. package/dist/utils/review/did-web-key.js +104 -0
  354. package/dist/utils/review/did-web-key.js.map +1 -0
  355. package/dist/utils/review/load-registry.d.ts +33 -0
  356. package/dist/utils/review/load-registry.d.ts.map +1 -0
  357. package/dist/utils/review/load-registry.js +62 -0
  358. package/dist/utils/review/load-registry.js.map +1 -0
  359. package/dist/utils/review/verdict-verify.d.ts +43 -0
  360. package/dist/utils/review/verdict-verify.d.ts.map +1 -0
  361. package/dist/utils/review/verdict-verify.js +53 -0
  362. package/dist/utils/review/verdict-verify.js.map +1 -0
  363. package/dist/utils/review-registry-writer.d.ts +52 -0
  364. package/dist/utils/review-registry-writer.d.ts.map +1 -0
  365. package/dist/utils/review-registry-writer.js +79 -0
  366. package/dist/utils/review-registry-writer.js.map +1 -0
  367. package/dist/utils/should-install-dependency.d.ts +17 -0
  368. package/dist/utils/should-install-dependency.d.ts.map +1 -0
  369. package/dist/utils/should-install-dependency.js +25 -0
  370. package/dist/utils/should-install-dependency.js.map +1 -0
  371. package/dist/utils/tool-readiness.d.ts +57 -0
  372. package/dist/utils/tool-readiness.d.ts.map +1 -0
  373. package/dist/utils/tool-readiness.js +114 -0
  374. package/dist/utils/tool-readiness.js.map +1 -0
  375. package/dist/utils/which.d.ts +2 -0
  376. package/dist/utils/which.d.ts.map +1 -0
  377. package/dist/utils/which.js +22 -0
  378. package/dist/utils/which.js.map +1 -0
  379. package/dist/version.d.ts +15 -0
  380. package/dist/version.d.ts.map +1 -0
  381. package/dist/version.js +29 -0
  382. package/dist/version.js.map +1 -0
  383. package/package.json +19 -6
  384. package/dist/utils/claim-polling.d.ts +0 -21
  385. package/dist/utils/claim-polling.d.ts.map +0 -1
  386. package/dist/utils/claim-polling.js.map +0 -1
  387. package/dist/utils/dco/fs-safe.d.ts +0 -14
  388. package/dist/utils/dco/fs-safe.d.ts.map +0 -1
  389. package/dist/utils/dco/fs-safe.js +0 -20
  390. package/dist/utils/dco/fs-safe.js.map +0 -1
@@ -0,0 +1,684 @@
1
+ import chalk from "chalk";
2
+ import ora from "ora";
3
+ import { existsSync } from "fs";
4
+ import { join } from "path";
5
+ import { openUrlInBrowser, pollForClaimStatus, } from "../utils/cli-kit/index.js";
6
+ import { EnvManager } from "../utils/env-manager.js";
7
+ import { writeAgentMetadata } from "../utils/dco/agent-metadata.js";
8
+ import { patchIdentityDidInPlace } from "../utils/identity-heal.js";
9
+ import { isValidSlug } from "../utils/dco/paths.js";
10
+ import { installDependency } from "../utils/dependency-installer.js";
11
+ import { shouldInstallDependency } from "../utils/should-install-dependency.js";
12
+ import { runToolReadinessGate, } from "../utils/tool-readiness.js";
13
+ import { detectPlatform } from "../utils/platform-detector.js";
14
+ import { AGENT_DETECTION_TABLE } from "../utils/agent-detector.js";
15
+ import { runAgentProfileStage, } from "../utils/agent-profile-stage.js";
16
+ import { createRegisterAgentIdentity, } from "../utils/register-agent-identity.js";
17
+ import { mergeReviewRegistry } from "../utils/review-registry-writer.js";
18
+ import { isGhAuthenticated, isGhInstalled, getGhUser } from "../utils/dco/github.js";
19
+ import { cliEffects, EffectTrigger } from "../effects/cli-integration.js";
20
+ import { moduleExists, StageFatalError, } from "../utils/init/pipeline.js";
21
+ import { readHubConfig } from "../utils/hub-config.js";
22
+ import { readStoredCredential } from "../utils/github-credential.js";
23
+ import { readPendingAnchor } from "../orchestrator/github-credential-anchor-sender.js";
24
+ import { runGithubCredentialStage, } from "../utils/github-credential-stage.js";
25
+ // Only "github" and "hub" actually have "already configured, skip unless
26
+ // forced" branches for --reconfigure to bypass (githubStage/hubStage below,
27
+ // via reconfiguring()). readiness/identity/claim run unconditionally on
28
+ // every invocation already (nothing for --reconfigure to force), and
29
+ // profiles' own idempotency lives inside runAgentProfileStage with no
30
+ // force/reconfigure parameter of its own -- listing them here would accept
31
+ // `--reconfigure profiles` (etc.) as a "known stage" that silently does
32
+ // nothing, worse than the "not a known stage" warning it'd otherwise get.
33
+ export const RECONFIGURABLE_STAGES = ["github", "hub"];
34
+ export function isReconfigurableStage(value) {
35
+ return RECONFIGURABLE_STAGES.includes(value);
36
+ }
37
+ const AGENT_KIND_VALUES = AGENT_DETECTION_TABLE.map((row) => row.kind);
38
+ function isAgentKind(value) {
39
+ return AGENT_KIND_VALUES.includes(value);
40
+ }
41
+ /** Parses --profiles into valid AgentKinds; unknown tokens are dropped. */
42
+ export function parseProfilesFlag(raw) {
43
+ if (!raw)
44
+ return undefined;
45
+ return raw
46
+ .split(",")
47
+ .map((s) => s.trim())
48
+ .filter(isAgentKind);
49
+ }
50
+ export function printToolReadinessSummary(checks) {
51
+ console.log(chalk.bold("🔧 Tool Readiness"));
52
+ for (const check of checks) {
53
+ if (check.found && (check.tool !== "gh" || check.authenticated)) {
54
+ console.log(` ${chalk.green("✓")} ${check.tool}${check.version ? ` (${check.version})` : ""}`);
55
+ }
56
+ else if (check.found) {
57
+ console.log(` ${chalk.yellow("⚠")} ${check.tool}: ${check.installHint}`);
58
+ }
59
+ else {
60
+ console.log(` ${chalk.yellow("⚠")} ${check.tool} not found: ${check.installHint}`);
61
+ }
62
+ }
63
+ }
64
+ function printMcpModuleMissingError() {
65
+ console.error(chalk.red("Error: MCP-I module not available. Please ensure @kya-os/mcp-i is installed."));
66
+ console.error(chalk.yellow("Run: npm install @kya-os/mcp-i"));
67
+ }
68
+ // Cached across calls within the same process, exactly as init.ts did
69
+ // before this refactor -- CI validation may run before @kya-os/mcp-i is
70
+ // built, so the dynamic import can fail on the first `init()` call in a
71
+ // process and succeed on a later one once the workspace is built; once it
72
+ // succeeds, later calls in the SAME process reuse the resolved module
73
+ // instead of importing it again.
74
+ let cachedEnableMCPIdentityCLI = null;
75
+ /**
76
+ * Loads @kya-os/mcp-i's enableMCPIdentityCLI, offering to install it on
77
+ * failure (P14 commit 1).
78
+ */
79
+ async function loadMcpIdentityModule(options, isTTY) {
80
+ try {
81
+ const mcpModule = await import("@kya-os/mcp-i");
82
+ return mcpModule.enableMCPIdentityCLI;
83
+ }
84
+ catch {
85
+ const confirmInstall = async (message) => {
86
+ const inquirer = (await import("inquirer")).default;
87
+ const { answer } = await inquirer.prompt([
88
+ { type: "confirm", name: "answer", message, default: true },
89
+ ]);
90
+ return answer;
91
+ };
92
+ const wantsInstall = await shouldInstallDependency({ install: options.install, yes: options.yes }, isTTY, confirmInstall);
93
+ if (wantsInstall) {
94
+ const install = await installDependency({
95
+ packageManager: detectPlatform().packageManager,
96
+ packageName: "@kya-os/mcp-i",
97
+ });
98
+ if (install.success) {
99
+ try {
100
+ const mcpModule = await import("@kya-os/mcp-i");
101
+ return mcpModule.enableMCPIdentityCLI;
102
+ }
103
+ catch {
104
+ // Retry failed: fall through to the terminal error below.
105
+ }
106
+ }
107
+ }
108
+ printMcpModuleMissingError();
109
+ throw new StageFatalError(1, "MCP-I module not available");
110
+ }
111
+ }
112
+ /** Whether `--reconfigure <stage>` targets exactly this stage. */
113
+ function reconfiguring(ctx, stage) {
114
+ return ctx.options.reconfigure === stage;
115
+ }
116
+ /**
117
+ * Reads a value a prior stage MUST have already set on `ctx`, given the
118
+ * fixed order `INIT_STAGES` below runs in. `InitStageContext`'s later
119
+ * fields are typed optional because the pipeline populates them
120
+ * progressively; before this refactor they were plain local variables in
121
+ * one function body, sequentially assigned and narrowed by TypeScript's
122
+ * own control-flow analysis, which a shared mutable context loses. A bare
123
+ * `!` assertion would silently turn a future stage-ordering mistake (e.g.
124
+ * `claimStage` moved before `identityStage` in `INIT_STAGES`) into an
125
+ * opaque "Cannot read properties of undefined" deep inside whichever
126
+ * stage read the missing field; this throws a message that names the
127
+ * actual invariant that broke instead.
128
+ */
129
+ function requireStageValue(value, fieldName, stageName) {
130
+ if (value === undefined) {
131
+ throw new Error(`Internal error: the "${stageName}" stage requires ctx.${fieldName} to already be set by an earlier stage. Check INIT_STAGES's order in init-stages.ts.`);
132
+ }
133
+ return value;
134
+ }
135
+ /** Stage 1: readiness checks (git/gh/claude) and the @kya-os/mcp-i self-install. */
136
+ export const readinessStage = {
137
+ name: "readiness",
138
+ when: () => true,
139
+ run: async (ctx) => {
140
+ const readiness = await runToolReadinessGate({ interactive: ctx.isTTY });
141
+ printToolReadinessSummary(readiness.checks);
142
+ if (readiness.fatalMissing.length > 0) {
143
+ console.log(chalk.red(`\n❌ Required tool missing: ${readiness.fatalMissing.join(", ")}. Install it and re-run.`));
144
+ throw new StageFatalError(1, `Required tool missing: ${readiness.fatalMissing.join(", ")}`);
145
+ }
146
+ ctx.readiness = readiness;
147
+ console.log(chalk.bold("\n📋 Agent Configuration"));
148
+ console.log(` Name: ${ctx.options.name || "Auto-generated"}`);
149
+ console.log(` Platform: ${ctx.platform}`);
150
+ if (ctx.options.description) {
151
+ console.log(` Description: ${ctx.options.description}`);
152
+ }
153
+ if (ctx.options.repository) {
154
+ console.log(` Repository: ${ctx.options.repository}`);
155
+ }
156
+ const enableMCPIdentity = cachedEnableMCPIdentityCLI ??
157
+ (await loadMcpIdentityModule(ctx.options, ctx.isTTY));
158
+ cachedEnableMCPIdentityCLI = enableMCPIdentity;
159
+ ctx.enableMCPIdentity = enableMCPIdentity;
160
+ const warnings = readiness.checks
161
+ .filter((c) => !c.found || (c.tool === "gh" && !c.authenticated))
162
+ .map((c) => `${c.tool}: ${c.installHint}`);
163
+ return {
164
+ ok: true,
165
+ summaryLine: `Tool readiness: ${readiness.checks.filter((c) => c.found).length}/${readiness.checks.length} found.`,
166
+ warnings: warnings.length > 0 ? warnings : undefined,
167
+ };
168
+ },
169
+ };
170
+ /** Stage 2: project identity and registration (existing behavior, unchanged). */
171
+ /** The registration call's progress reporter: spinner text plus the CLI effects. */
172
+ function buildOnProgressHandler(spinner) {
173
+ return async (event) => {
174
+ switch (event.stage) {
175
+ case "checking_existing":
176
+ spinner.text = "Checking for existing identity...";
177
+ break;
178
+ case "generating_keys":
179
+ spinner.text = "Generating cryptographic keys...";
180
+ await cliEffects.showEffect(EffectTrigger.AGENT_IDENTITY_CREATE, `🤖 Generating Agent Identity\nCreating cryptographic keys...`, { skipExitPrompt: true });
181
+ break;
182
+ case "registering":
183
+ spinner.text = "Registering with Know-That-AI...";
184
+ await cliEffects.showEffect(EffectTrigger.DID_GENERATION, `🔐 Registering Agent\nConnecting to Know-That-AI...`, { skipExitPrompt: true });
185
+ break;
186
+ case "saving":
187
+ spinner.text = "Saving identity...";
188
+ break;
189
+ case "complete":
190
+ spinner.succeed("Identity created successfully!");
191
+ break;
192
+ }
193
+ };
194
+ }
195
+ /**
196
+ * The identity adapter mints a local PLACEHOLDER did (shape
197
+ * did:web:localhost:3000:agents:<8hex>) before registration even happens;
198
+ * only a claim URL + server-assigned slug mean registration actually
199
+ * completed and the registry has a real did:web record to resolve. Heals
200
+ * `.mcpi/identity.json` in place (when present) so the placeholder never
201
+ * outlives registration, and returns the DID every later stage/write must
202
+ * treat as authoritative from here on.
203
+ */
204
+ function healPlaceholderDid(result, options) {
205
+ const registrationSucceeded = Boolean(result.metadata.claimUrl && result.metadata.agentSlug);
206
+ let canonicalDid = null;
207
+ if (registrationSucceeded &&
208
+ !options.local &&
209
+ isValidSlug(result.metadata.agentSlug ?? "")) {
210
+ try {
211
+ const registryBaseUrl = options.endpoint || "https://knowthat.ai";
212
+ const parsedRegistryUrl = new URL(registryBaseUrl);
213
+ if (parsedRegistryUrl.protocol === "https:") {
214
+ canonicalDid = `did:web:${parsedRegistryUrl.hostname}:agents:${result.metadata.agentSlug}`;
215
+ }
216
+ }
217
+ catch {
218
+ // Malformed --endpoint: fall back to the placeholder did rather than
219
+ // guess at a host.
220
+ }
221
+ }
222
+ let effectiveDid = result.identity.did;
223
+ if (canonicalDid) {
224
+ const identityFilePath = join(process.cwd(), ".mcpi", "identity.json");
225
+ if (existsSync(identityFilePath)) {
226
+ try {
227
+ patchIdentityDidInPlace(identityFilePath, canonicalDid);
228
+ effectiveDid = canonicalDid;
229
+ }
230
+ catch (error) {
231
+ if (options.verbose) {
232
+ console.warn(chalk.yellow(`\n⚠️ Could not heal .mcpi/identity.json did: ${error.message}`));
233
+ }
234
+ }
235
+ }
236
+ }
237
+ return effectiveDid;
238
+ }
239
+ /** Persists the new identity's secrets to `.env.local`, new identities only. */
240
+ async function saveEnvVariables(result, effectiveDid, options) {
241
+ if (!(result.metadata.isNewIdentity && !options.skipRegistration))
242
+ return;
243
+ try {
244
+ const envManager = new EnvManager();
245
+ await envManager.updateEnvFile(".env.local", {
246
+ AGENT_PRIVATE_KEY: result.identity.privateKey,
247
+ AGENT_DID: effectiveDid,
248
+ AGENT_PUBLIC_KEY: result.identity.publicKey,
249
+ AGENT_KEY_ID: result.identity.kid,
250
+ KYA_VOUCHED_API_KEY: "", // Will be set when agent is claimed
251
+ ...(result.metadata.agentId && {
252
+ AGENT_ID: result.metadata.agentId,
253
+ }),
254
+ ...(result.metadata.agentSlug && {
255
+ AGENT_SLUG: result.metadata.agentSlug,
256
+ }),
257
+ });
258
+ if (options.verbose) {
259
+ console.log(chalk.gray("\n✅ Environment variables saved to .env.local"));
260
+ }
261
+ }
262
+ catch (error) {
263
+ if (options.verbose) {
264
+ console.warn(chalk.yellow("\n⚠️ Could not save environment variables:", error.message));
265
+ }
266
+ }
267
+ }
268
+ /** Persists public agent metadata (no secrets) to `.mcpi/agent.json`. */
269
+ function persistAgentMetadata(result, effectiveDid, agentName, options) {
270
+ const slug = result.metadata.agentSlug;
271
+ if (!(!options.skipRegistration && slug))
272
+ return;
273
+ try {
274
+ const registryBase = options.local
275
+ ? "http://localhost:3000"
276
+ : options.endpoint || "https://knowthat.ai";
277
+ writeAgentMetadata(process.cwd(), {
278
+ id: result.metadata.agentId,
279
+ slug,
280
+ name: agentName,
281
+ url: `${registryBase}/agents/${slug}`,
282
+ did: effectiveDid,
283
+ claimUrl: result.metadata.claimUrl,
284
+ registeredAt: new Date().toISOString(),
285
+ });
286
+ }
287
+ catch (error) {
288
+ console.warn(chalk.yellow(`\n⚠️ Could not write .mcpi/agent.json: ${error.message}`));
289
+ }
290
+ }
291
+ export const identityStage = {
292
+ name: "identity",
293
+ when: () => true,
294
+ run: async (ctx) => {
295
+ const options = ctx.options;
296
+ const enableMCPIdentity = requireStageValue(ctx.enableMCPIdentity, "enableMCPIdentity", "identity");
297
+ const spinner = ora("Setting up agent identity...").start();
298
+ // Default the agent name once and use it for BOTH registration and the
299
+ // persisted agent.json, so the display name always matches what was
300
+ // registered (never the slug). Uses || (not ??) so an empty --name also
301
+ // falls back, matching register.ts's default.
302
+ const agentName = options.name || "MCP-I Agent";
303
+ ctx.agentName = agentName;
304
+ try {
305
+ const result = await enableMCPIdentity({
306
+ name: agentName,
307
+ description: options.description,
308
+ repository: options.repository,
309
+ endpoint: options.local ? "http://localhost:3000" : options.endpoint,
310
+ logLevel: options.verbose ? "info" : "silent",
311
+ skipRegistration: options.skipRegistration,
312
+ onProgress: buildOnProgressHandler(spinner),
313
+ });
314
+ if (result.metadata.isNewIdentity) {
315
+ await cliEffects.showEffect(EffectTrigger.OPERATION_SUCCESS, `✅ Agent Identity Created\n\nDID: ${result.identity.did}`, { skipExitPrompt: true });
316
+ }
317
+ const effectiveDid = healPlaceholderDid(result, options);
318
+ await saveEnvVariables(result, effectiveDid, options);
319
+ persistAgentMetadata(result, effectiveDid, agentName, options);
320
+ ctx.registrationResult = result;
321
+ ctx.effectiveDid = effectiveDid;
322
+ return {
323
+ ok: true,
324
+ summaryLine: result.metadata.isNewIdentity
325
+ ? `Identity created (did: ${effectiveDid}).`
326
+ : `Identity already set up (did: ${effectiveDid}).`,
327
+ };
328
+ }
329
+ catch (error) {
330
+ spinner.fail("Failed to set up identity");
331
+ throw error;
332
+ }
333
+ },
334
+ };
335
+ /** Stage 3: claim flow (existing, unchanged). */
336
+ export const claimStage = {
337
+ name: "claim",
338
+ when: () => true,
339
+ run: async (ctx) => {
340
+ const options = ctx.options;
341
+ const result = requireStageValue(ctx.registrationResult, "registrationResult", "claim");
342
+ if (options.skipRegistration) {
343
+ return { ok: true, summaryLine: "Claim flow: skipped (--skip-registration)." };
344
+ }
345
+ if (!result.metadata.claimUrl) {
346
+ return { ok: true, summaryLine: "Claim flow: no claim needed." };
347
+ }
348
+ console.log(`\n${chalk.bold("🎫 Claim Your Agent:")}`);
349
+ console.log(` ${chalk.cyan(result.metadata.claimUrl)}`);
350
+ const { opened, reason } = await openUrlInBrowser(result.metadata.claimUrl);
351
+ if (opened) {
352
+ console.log(chalk.green("\n✅ Browser opened!"));
353
+ }
354
+ else if (reason === "non-tty") {
355
+ console.log(chalk.gray("\n Non-interactive environment detected — visit the link above."));
356
+ }
357
+ else {
358
+ console.log(chalk.yellow("\n⚠️ Could not open browser automatically"));
359
+ console.log(chalk.cyan(` Please visit: ${result.metadata.claimUrl}`));
360
+ }
361
+ if (options.skipClaimCheck) {
362
+ console.log(chalk.gray("\n Skipping claim check..."));
363
+ console.log(chalk.gray(" You can claim your agent anytime at the URL above."));
364
+ return { ok: true, summaryLine: "Claim flow: claim check skipped." };
365
+ }
366
+ console.log("\n");
367
+ const agentSlug = result.metadata.agentSlug || result.metadata.agentId || options.name || "unknown";
368
+ const apiEndpoint = options.local
369
+ ? "http://localhost:3000"
370
+ : options.endpoint || "https://knowthat.ai";
371
+ const claimed = await pollForClaimStatus(new URL(`/api/agents/${encodeURIComponent(agentSlug)}`, apiEndpoint).toString(), (body) => {
372
+ if (!body || typeof body !== "object")
373
+ return false;
374
+ const data = body;
375
+ return Boolean(data.userId ||
376
+ data.status === "active" ||
377
+ data.owner ||
378
+ data.claimedAt ||
379
+ data.isDraft === false);
380
+ }, { verbose: options.verbose });
381
+ if (claimed) {
382
+ console.clear();
383
+ console.log(chalk.green("🎉 Your agent is now claimed and ready to use!\n"));
384
+ return { ok: true, summaryLine: "Claim flow: claimed." };
385
+ }
386
+ return { ok: true, summaryLine: "Claim flow: pending claim." };
387
+ },
388
+ };
389
+ /**
390
+ * Runs a DCO setup for one newly-created agent profile (review-loop P18:
391
+ * the DCO prompt moves inside the per-agent profile step, asked once per
392
+ * agent rather than once globally -- init.ts's own end-of-run prompt below
393
+ * still covers the MAIN identity, which is not itself an agent profile).
394
+ * Interactive + TTY only, same guard shape as the main prompt.
395
+ */
396
+ async function offerPerAgentDco(slug) {
397
+ const inquirer = (await import("inquirer")).default;
398
+ const { setupDco } = await inquirer.prompt([
399
+ {
400
+ type: "confirm",
401
+ name: "setupDco",
402
+ message: `Set up commit signing and PR attribution for ${slug} now?`,
403
+ default: true,
404
+ },
405
+ ]);
406
+ if (!setupDco)
407
+ return;
408
+ const { runDcoSetup } = await import("../utils/dco/setup.js");
409
+ const { renderSetupResult } = await import("../utils/dco/render.js");
410
+ const dcoResult = await runDcoSetup({ interactive: true, agent: slug });
411
+ renderSetupResult(dcoResult);
412
+ }
413
+ /**
414
+ * Runs the agent-profile stage (P15 commit 6) and, for any profile it
415
+ * creates, merges an entry into the review registry (P15 commit 7) and
416
+ * offers per-agent DCO setup (P18).
417
+ */
418
+ async function runProfileStageAndUpdateRegistry(ctx) {
419
+ const options = ctx.options;
420
+ let githubLogin;
421
+ try {
422
+ if ((await isGhInstalled()) && (await isGhAuthenticated())) {
423
+ githubLogin = (await getGhUser()).login;
424
+ }
425
+ }
426
+ catch {
427
+ // Best-effort: profile slugs fall back to "agent-<kind>" below.
428
+ }
429
+ ctx.githubLogin = githubLogin;
430
+ const registerIdentity = createRegisterAgentIdentity({
431
+ endpoint: options.local ? "http://localhost:3000" : options.endpoint,
432
+ enableMCPIdentityCLIImpl: requireStageValue(ctx.enableMCPIdentity, "enableMCPIdentity", "profiles"),
433
+ });
434
+ const profileStageResult = await runAgentProfileStage({
435
+ interactive: ctx.isTTY,
436
+ profilesFlag: parseProfilesFlag(options.profiles),
437
+ skipProfiles: options.skipProfiles,
438
+ githubLogin,
439
+ registerIdentity,
440
+ });
441
+ if (profileStageResult.createdProfiles.length > 0) {
442
+ console.log(`\n${chalk.bold("🧩 Agent Profiles:")}`);
443
+ for (const profile of profileStageResult.createdProfiles) {
444
+ console.log(` ${chalk.green("✓")} ${profile.kind} (${profile.slug})`);
445
+ }
446
+ }
447
+ for (const error of profileStageResult.errors) {
448
+ console.log(chalk.yellow(` ⚠ Could not set up a profile for ${error.kind}: ${error.message}`));
449
+ }
450
+ if (profileStageResult.createdProfiles.length > 0 && githubLogin) {
451
+ const entries = profileStageResult.createdProfiles.map((profile) => ({
452
+ person: githubLogin,
453
+ githubLogin: githubLogin,
454
+ slug: profile.slug,
455
+ agentDid: profile.did,
456
+ reviews: true,
457
+ fixes: false,
458
+ }));
459
+ const registryResult = mergeReviewRegistry(entries, {
460
+ designateFixerCandidates: [profileStageResult.createdProfiles[0].did],
461
+ });
462
+ if (registryResult.status === "written") {
463
+ console.log(chalk.gray(` Updated review registry at ${registryResult.path}`));
464
+ }
465
+ else if (registryResult.status === "invalid-existing" ||
466
+ registryResult.status === "invalid-result") {
467
+ console.log(chalk.yellow(` ⚠ Review registry not updated: ${registryResult.error}`));
468
+ }
469
+ }
470
+ // Per-agent DCO prompt (P18): interactive + TTY only, one ask per newly
471
+ // created profile, never for a profile that already existed. Caught
472
+ // per-profile, not left to propagate: a signing-setup failure for one
473
+ // agent must not also skip the OTHER newly-created profiles' own DCO
474
+ // offer, and -- since profilesStage runs before github/hub in
475
+ // INIT_STAGES -- an uncaught throw here stops runStages entirely
476
+ // (StageFatalError is the only modeled way to do that on purpose),
477
+ // silently skipping GitHub credential onboarding and hub context too.
478
+ if (ctx.isTTY && !ctx.isTestEnv && options.dco !== false) {
479
+ for (const profile of profileStageResult.createdProfiles) {
480
+ try {
481
+ await offerPerAgentDco(profile.slug);
482
+ }
483
+ catch (error) {
484
+ console.log(chalk.yellow(` ⚠ Commit-signing setup for ${profile.slug} failed: ${error.message}`));
485
+ }
486
+ }
487
+ }
488
+ return profileStageResult;
489
+ }
490
+ /** Stage 4: agent detection and profiles (P15), absorbing the per-agent DCO prompt. */
491
+ export const profilesStage = {
492
+ name: "profiles",
493
+ when: () => true,
494
+ run: async (ctx) => {
495
+ if (ctx.options.skipRegistration) {
496
+ ctx.profileStageResult = null;
497
+ return { ok: true, summaryLine: "Agent profiles: skipped (--skip-registration)." };
498
+ }
499
+ const result = await runProfileStageAndUpdateRegistry(ctx);
500
+ ctx.profileStageResult = result;
501
+ if (result.errors.length > 0) {
502
+ return {
503
+ ok: false,
504
+ summaryLine: `Agent profiles: ${result.createdProfiles.length} created, ${result.errors.length} failed.`,
505
+ warnings: result.errors.map((e) => `${e.kind}: ${e.message}`),
506
+ };
507
+ }
508
+ if (result.createdProfiles.length > 0) {
509
+ return {
510
+ ok: true,
511
+ summaryLine: `Agent profiles: created ${result.createdProfiles.length} (${result.createdProfiles.map((p) => p.slug).join(", ")}).`,
512
+ };
513
+ }
514
+ if (result.skippedKinds.length > 0) {
515
+ return {
516
+ ok: true,
517
+ summaryLine: `Agent profiles already set up (${result.skippedKinds.length}).`,
518
+ };
519
+ }
520
+ if (result.detected.length === 0) {
521
+ return { ok: true, summaryLine: "Agent profiles: no agent harnesses detected." };
522
+ }
523
+ return { ok: true, summaryLine: "Agent profiles: none set up this run." };
524
+ },
525
+ };
526
+ /**
527
+ * Stage 5: GitHub credential onboarding. P16 landed (#704) with a real
528
+ * `runGithubCredentialStage` (utils/github-credential-stage.ts); this
529
+ * wraps it the same way the profiles stage above wraps
530
+ * `runAgentProfileStage`. `--skip-github` omits the stage entirely
531
+ * (`when`) rather than being threaded into the call, so `run` never
532
+ * executes when it's set -- matching the hub stage's own pattern below.
533
+ *
534
+ * The "already configured, skip unless forced" gate runs BEFORE calling
535
+ * `runGithubCredentialStage` at all: that function has no such short-
536
+ * circuit of its own (an interactive run with an existing credential
537
+ * re-prompts to rotate it every time, which is correct for a standalone
538
+ * `dco setup`-adjacent flow but not for this PR's own re-run design -- a
539
+ * second `kya-os init` on a configured machine should feel like opening
540
+ * the front door, not re-onboarding). Three DISTINCT reasons can force
541
+ * the call through, and they must not be conflated (each mix-up here was
542
+ * a real /get finding on an earlier version of this exact stage):
543
+ *
544
+ * - `--reconfigure github` / an explicit `--github-token-env`: a STATED
545
+ * intent to redo credential setup, so the call gets the normal
546
+ * `ctx.isTTY` interactivity (rotate-confirmation prompt and all,
547
+ * exactly as if nothing were configured yet).
548
+ * - A queued anchor with neither of those AND a credential that's still
549
+ * there (`retryPendingAnchorOnly`): ONLY a delivery retry, not a
550
+ * change to the credential itself, so it forces the call through but
551
+ * with `interactive: false` regardless of the real TTY --
552
+ * `runGithubCredentialStage` attempts the pending-anchor flush
553
+ * unconditionally before it ever looks at `interactive`, and
554
+ * `interactive: false` with no token-env makes it skip out via
555
+ * `resolveGithubTokenSource`'s non-interactive branch instead of
556
+ * falling through into acquire-and-rotate if the flush still can't
557
+ * reach the hub -- so a second `kya-os init` never re-opens "rotate
558
+ * your GitHub credential?" over a hub that just hasn't come back up
559
+ * yet.
560
+ * - A missing/corrupt credential (`!alreadyConfigured`), pending anchor
561
+ * or not: `readStoredCredential` (not a bare `existsSync`) means this
562
+ * reads as NOT configured, so it must get the FULL normal-interactivity
563
+ * flow to actually self-heal -- `retryPendingAnchorOnly` is false in
564
+ * this case specifically (it requires `alreadyConfigured`), so a
565
+ * leftover `pending-anchor.json` next to an absent/corrupt
566
+ * `credentials.json` doesn't also force `interactive: false` and wedge
567
+ * the self-heal behind a silent non-interactive skip.
568
+ */
569
+ export const githubStage = {
570
+ name: "github",
571
+ when: (ctx) => !ctx.options.skipGithub,
572
+ run: async (ctx) => {
573
+ const alreadyConfigured = Boolean(readStoredCredential());
574
+ const explicitlyForced = reconfiguring(ctx, "github") || Boolean(ctx.options.githubTokenEnv);
575
+ const hasPendingAnchor = Boolean(readPendingAnchor());
576
+ if (alreadyConfigured && !explicitlyForced && !hasPendingAnchor) {
577
+ return { ok: true, summaryLine: "GitHub credentials already set up." };
578
+ }
579
+ // Retry-only: the credential itself is fine (alreadyConfigured) and
580
+ // nothing explicit was asked for, but a queued anchor still needs
581
+ // its delivery retried -- this must NOT also fire when the
582
+ // credential is missing/corrupt (a real /get finding on the
583
+ // previous round's own fix): a leftover pending-anchor.json next to
584
+ // an absent or corrupt credentials.json must still get the normal
585
+ // interactive acquisition flow (readStoredCredential's own self-
586
+ // heal promise), not be forced non-interactive just because
587
+ // something is also queued for delivery.
588
+ const retryPendingAnchorOnly = alreadyConfigured && !explicitlyForced && hasPendingAnchor;
589
+ try {
590
+ const result = await runGithubCredentialStage({
591
+ interactive: ctx.isTTY && !retryPendingAnchorOnly,
592
+ githubTokenEnv: ctx.options.githubTokenEnv,
593
+ // --hub is this PR's own explicit, non-interactive override;
594
+ // DIDCOMM_HUB_ENDPOINT is the ambient fallback every hub-aware
595
+ // command in this codebase already reads. --hub naming a
596
+ // DIFFERENT endpoint than the env var must win, since it is the
597
+ // more specific, just-typed intent.
598
+ hubEndpoint: ctx.options.hub || process.env["DIDCOMM_HUB_ENDPOINT"],
599
+ });
600
+ switch (result.status) {
601
+ case "completed":
602
+ return {
603
+ ok: true,
604
+ summaryLine: `GitHub credential: ${result.githubLogin} (${result.anchorDelivery === "delivered" ? "anchored" : "anchor pending"}).`,
605
+ };
606
+ case "declined-rotation":
607
+ return {
608
+ ok: true,
609
+ summaryLine: "GitHub credential: kept existing (rotation declined).",
610
+ };
611
+ case "anchor-build-failed":
612
+ return {
613
+ ok: false,
614
+ summaryLine: `GitHub credential: ${result.githubLogin} saved locally, not yet anchored.`,
615
+ warnings: [result.reason],
616
+ };
617
+ case "skipped":
618
+ return {
619
+ ok: true,
620
+ summaryLine: `GitHub credential onboarding: skipped (${result.reason}).`,
621
+ };
622
+ }
623
+ }
624
+ catch (error) {
625
+ return {
626
+ ok: false,
627
+ summaryLine: "GitHub credential onboarding failed.",
628
+ warnings: [error.message],
629
+ };
630
+ }
631
+ },
632
+ };
633
+ /**
634
+ * Stage 6: hub context (review-loop P17). Same runtime-optional shape as
635
+ * the GitHub stage above; "already configured" reads `~/.mcpi/hub.json`
636
+ * through the existing read-only `readHubConfig()` helper (utils/
637
+ * hub-config.ts), so this stage's state-detection needs no dependency on
638
+ * P17's module either.
639
+ */
640
+ export const hubStage = {
641
+ name: "hub",
642
+ when: async (ctx) => {
643
+ if (ctx.options.skipHub)
644
+ return false;
645
+ return moduleExists("../utils/hub-context.js", import.meta.url);
646
+ },
647
+ run: async (ctx) => {
648
+ const existing = readHubConfig();
649
+ if (existing && !reconfiguring(ctx, "hub")) {
650
+ return { ok: true, summaryLine: `Hub context already set up (${existing.endpoint}).` };
651
+ }
652
+ /* v8 ignore start -- unreachable until P17's resolution module exists; see `when` above. */
653
+ return {
654
+ ok: true,
655
+ summaryLine: "Hub context: module found but resolution not yet wired (P17 lands separately).",
656
+ };
657
+ /* v8 ignore stop */
658
+ },
659
+ };
660
+ export const INIT_STAGES = [
661
+ readinessStage,
662
+ identityStage,
663
+ claimStage,
664
+ profilesStage,
665
+ githubStage,
666
+ hubStage,
667
+ ];
668
+ /** Human-readable reason an omitted stage produced no StageResult. */
669
+ export function omittedStageSummary(name, ctx) {
670
+ switch (name) {
671
+ case "github":
672
+ // githubStage.when is now a plain `!skipGithub` check (P16 landed,
673
+ // #704) -- --skip-github is the only reason this stage is ever
674
+ // omitted, unlike hub below (still gated on P17 not landing yet).
675
+ return "GitHub credential onboarding: skipped (--skip-github).";
676
+ case "hub":
677
+ return ctx.options.skipHub
678
+ ? "Hub context: skipped (--skip-hub)."
679
+ : "Hub context: skipped (not available yet).";
680
+ default:
681
+ return `${name}: skipped.`;
682
+ }
683
+ }
684
+ //# sourceMappingURL=init-stages.js.map