@uniqbit/mate-core 1.0.0-canary.0 → 1.0.0-canary.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (325) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/marketplace.json +14 -0
  2. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +8 -0
  3. package/claude-capability-plugins/companion-mentions/hooks/companion.ts +457 -0
  4. package/claude-capability-plugins/companion-mentions/hooks/hooks.json +1 -0
  5. package/claude-capability-plugins/companion-mentions/hooks/register.ts +403 -0
  6. package/claude-plugin/hooks/hooks.json +10 -1
  7. package/claude-plugin/hooks/tokensave-route.mjs +52 -0
  8. package/opencode-plugin/src/server.ts +4 -0
  9. package/opencode-plugin/src/tui.tsx +2 -0
  10. package/opencode-plugin/tui.tsx +2 -0
  11. package/package.json +45 -16
  12. package/src/brand/terminal.ts +5 -0
  13. package/src/cli/commands/artifact/apply-context.ts +275 -0
  14. package/src/cli/commands/artifact/artifact.ts +4 -0
  15. package/src/cli/commands/artifact/delivery/archive.ts +13 -5
  16. package/src/cli/commands/artifact/delivery/environment.ts +36 -13
  17. package/src/cli/commands/artifact/delivery/link.ts +35 -15
  18. package/src/cli/commands/artifact/delivery/output.ts +31 -0
  19. package/src/cli/commands/artifact/finish/command.ts +50 -5
  20. package/src/cli/commands/artifact/finish/engine.ts +44 -11
  21. package/src/cli/commands/artifact/finish/git.ts +132 -19
  22. package/src/cli/commands/artifact/finish/openspec.ts +6 -1
  23. package/src/cli/commands/artifact/finish/worktree-cleanup.ts +92 -0
  24. package/src/cli/commands/cap/index-cmd.ts +64 -15
  25. package/src/cli/commands/cap/tokensave.ts +7 -5
  26. package/src/cli/commands/companion/link.ts +14 -1
  27. package/src/cli/commands/companion/open.ts +16 -11
  28. package/src/cli/commands/companion/sync.ts +10 -0
  29. package/src/cli/commands/companion/tui.ts +17 -7
  30. package/src/cli/commands/companion/update.ts +74 -12
  31. package/src/cli/commands/doctor.ts +20 -5
  32. package/src/cli/commands/factory/factory.ts +301 -0
  33. package/src/cli/commands/install.ts +133 -9
  34. package/src/cli/commands/launch/shared.ts +16 -11
  35. package/src/cli/commands/report/index.ts +20 -1
  36. package/src/cli/commands/session/context.ts +102 -0
  37. package/src/cli/commands/setup.ts +44 -10
  38. package/src/cli/commands/studio/factory-credential.ts +49 -0
  39. package/src/cli/commands/studio/index.ts +29 -2
  40. package/src/cli/commands/studio/payload.ts +249 -15
  41. package/src/cli/commands/studio/routes.ts +41 -8
  42. package/src/cli/commands/studio/selection.ts +142 -16
  43. package/src/cli/commands/studio/server.ts +403 -364
  44. package/src/cli/commands/studio/services.ts +60 -0
  45. package/src/cli/commands/studio/studio-app.ts +67 -0
  46. package/src/cli/commands/studio/terminal-assets.ts +21 -33
  47. package/src/cli/commands/studio/terminal.ts +85 -15
  48. package/src/cli/commands/studio/views/model.ts +18 -0
  49. package/src/cli/commands/studio/views/vault/markdown-tree.ts +267 -0
  50. package/src/cli/commands/studio/views/vault/view.ts +185 -0
  51. package/src/cli/commands/studio/workset-session.ts +131 -0
  52. package/src/cli/commands/unwrap.ts +8 -0
  53. package/src/cli/commands/update.ts +27 -1
  54. package/src/cli/commands/working/cleanup.ts +10 -1
  55. package/src/cli/commands/working/link.ts +76 -0
  56. package/src/cli/commands/working/working.ts +10 -0
  57. package/src/cli/commands/working/worktree.ts +356 -0
  58. package/src/cli/companion-link-wizard.tsx +2 -0
  59. package/src/cli/companion-selector.tsx +2 -0
  60. package/src/cli/confirm.ts +2 -0
  61. package/src/cli/install-plan.tsx +127 -160
  62. package/src/cli/launch-selector.tsx +2 -0
  63. package/src/cli/main.ts +18 -0
  64. package/src/cli/parse-flags.ts +9 -1
  65. package/src/cli/repo-list-table.tsx +2 -0
  66. package/src/cli/setup-selector.tsx +79 -20
  67. package/src/cli/usage.ts +11 -1
  68. package/src/create-mate.ts +5 -4
  69. package/src/hooks/tokensave-route.ts +26 -0
  70. package/src/lib/apply-context/fingerprint.ts +174 -0
  71. package/src/lib/apply-context/protocol.ts +193 -0
  72. package/src/lib/components/confirm-prompt.tsx +21 -9
  73. package/src/lib/components/select-menu.tsx +10 -3
  74. package/src/lib/components/spinner.tsx +4 -2
  75. package/src/lib/components/startup-progress.tsx +227 -41
  76. package/src/lib/components/text-input-display.tsx +2 -0
  77. package/src/lib/components/wizard-footer.tsx +2 -0
  78. package/src/lib/components/wizard-header.tsx +13 -11
  79. package/src/lib/delivery/archive-change.ts +14 -2
  80. package/src/lib/delivery/branches.ts +29 -5
  81. package/src/lib/delivery/environment.ts +7 -1
  82. package/src/lib/delivery/forge.ts +2 -2
  83. package/src/lib/delivery/merge-git.ts +261 -0
  84. package/src/lib/delivery/overlap.ts +11 -4
  85. package/src/lib/delivery/record-delivery.ts +97 -10
  86. package/src/lib/delivery/record.ts +67 -7
  87. package/src/lib/delivery/refresh.ts +104 -10
  88. package/src/lib/delivery/repository-access.ts +46 -2
  89. package/src/lib/delivery/resolve-branch.ts +162 -0
  90. package/src/lib/delivery/token.ts +7 -41
  91. package/src/lib/factory/attach-client.ts +113 -0
  92. package/src/lib/factory/attach.ts +178 -0
  93. package/src/lib/factory/broker.ts +190 -0
  94. package/src/lib/factory/bun-commands.ts +39 -0
  95. package/src/lib/factory/client.ts +92 -0
  96. package/src/lib/factory/command.ts +61 -0
  97. package/src/lib/factory/credential-store.ts +153 -0
  98. package/src/lib/factory/frames.ts +77 -0
  99. package/src/lib/factory/ids.ts +58 -0
  100. package/src/lib/factory/keyed-serial.ts +27 -0
  101. package/src/lib/factory/outcomes/actions.ts +114 -0
  102. package/src/lib/factory/outcomes/index.ts +381 -0
  103. package/src/lib/factory/outcomes/lifecycle.ts +205 -0
  104. package/src/lib/factory/outcomes/runs.ts +81 -0
  105. package/src/lib/factory/outcomes/sessions.ts +38 -0
  106. package/src/lib/factory/prepare.ts +49 -0
  107. package/src/lib/factory/pty.ts +103 -0
  108. package/src/lib/factory/runner/companion-context.ts +178 -0
  109. package/src/lib/factory/runner/control.ts +92 -0
  110. package/src/lib/factory/runner/harness-agent.ts +250 -0
  111. package/src/lib/factory/runner/live.ts +159 -0
  112. package/src/lib/factory/runner/questions.ts +22 -0
  113. package/src/lib/factory/runner/rank.ts +26 -0
  114. package/src/lib/factory/runner/run-policy.ts +12 -0
  115. package/src/lib/factory/runner/run.ts +199 -0
  116. package/src/lib/factory/runner/scheduler.ts +416 -0
  117. package/src/lib/factory/runner/state.ts +233 -0
  118. package/src/lib/factory/runner/workflow.ts +542 -0
  119. package/src/lib/factory/runtime.ts +972 -0
  120. package/src/lib/factory/sandbox.ts +292 -0
  121. package/src/lib/factory/worktree-branch.ts +17 -0
  122. package/src/lib/install.ts +66 -14
  123. package/src/lib/live-progress.ts +36 -0
  124. package/src/lib/member-choices.ts +67 -0
  125. package/src/lib/orchestrator/adapters/base.ts +55 -22
  126. package/src/lib/orchestrator/adapters/claude.ts +6 -1
  127. package/src/lib/orchestrator/config-store.ts +3 -2
  128. package/src/lib/orchestrator/editor.ts +29 -23
  129. package/src/lib/orchestrator/projection-entries.ts +56 -21
  130. package/src/lib/orchestrator/projection-opencode-copies.ts +32 -15
  131. package/src/lib/orchestrator/projection-openspec-store.ts +54 -9
  132. package/src/lib/orchestrator/projection-types.ts +33 -1
  133. package/src/lib/orchestrator/session-context-link.ts +67 -0
  134. package/src/lib/orchestrator/setup-compatibilities.ts +55 -12
  135. package/src/lib/orchestrator/types.ts +5 -0
  136. package/src/lib/orchestrator/working-repo-projection.ts +50 -7
  137. package/src/lib/orchestrator/workspace-document.ts +105 -0
  138. package/src/lib/package-paths.ts +29 -0
  139. package/src/lib/runtime-directory-refresh.ts +17 -1
  140. package/src/lib/workset/record.ts +513 -0
  141. package/src/lib/workset/repositories.ts +55 -0
  142. package/src/lib/workset/stage.ts +148 -0
  143. package/src/lib/workset/stages.ts +113 -0
  144. package/src/lib/workset/worktree-index.ts +116 -0
  145. package/src/lib/workset/worktree.ts +830 -0
  146. package/src/opencode/companion-hooks.ts +45 -2
  147. package/src/opencode/enter-worktree.ts +72 -0
  148. package/src/opencode/tui.tsx +9 -4
  149. package/src/plugins.ts +1 -0
  150. package/src/runtime/claude-delivery-plan.ts +22 -5
  151. package/src/runtime/companion-git.ts +52 -10
  152. package/src/runtime/companion-guidance.ts +7 -7
  153. package/src/runtime/companion-lock.ts +30 -7
  154. package/src/runtime/env.ts +48 -3
  155. package/src/runtime/git-layout.ts +219 -0
  156. package/src/runtime/index.ts +24 -0
  157. package/src/runtime/physical-path.ts +111 -0
  158. package/src/runtime/policy.ts +36 -2
  159. package/src/runtime/runtime-directory.ts +5 -0
  160. package/src/runtime/secret-guard.ts +19 -5
  161. package/src/runtime/secret-patterns.ts +267 -34
  162. package/src/runtime/session-context.ts +98 -0
  163. package/src/runtime/tokensave-route.ts +152 -0
  164. package/src/runtime/wrap-state.ts +24 -16
  165. package/src/studio.ts +124 -0
  166. package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +10 -8
  167. package/src/templates/capabilities/openspec-cap/mate-v1/schema.yaml +16 -98
  168. package/src/templates/capabilities/openspec-cap/openspec-conventions.yaml +10 -2
  169. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +76 -18
  170. package/src/templates/mate-skills/agents/mate-apply-change/references/mate-compact-apply.md +47 -0
  171. package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +2 -0
  172. package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +32 -5
  173. package/src/templates/mate-skills/agents/mate-backfill-spec/SKILL.md +8 -1
  174. package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +16 -1
  175. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +22 -6
  176. package/src/templates/mate-skills/agents/mate-explore-change/references/openspec-explore.md +2 -0
  177. package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +8 -1
  178. package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +2 -2
  179. package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +7 -0
  180. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +55 -50
  181. package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +47 -0
  182. package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-propose.md +2 -0
  183. package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +2 -0
  184. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +29 -10
  185. package/src/templates/mate-skills/agents/mate-publish-artifact/references/openspec.md +4 -2
  186. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +21 -0
  187. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +13 -0
  188. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +76 -18
  189. package/src/templates/mate-skills/claude/mate-apply-change/references/mate-compact-apply.md +47 -0
  190. package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +2 -0
  191. package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +32 -5
  192. package/src/templates/mate-skills/claude/mate-backfill-spec/SKILL.md +8 -1
  193. package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +16 -1
  194. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +22 -6
  195. package/src/templates/mate-skills/claude/mate-explore-change/references/openspec-explore.md +2 -0
  196. package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +8 -1
  197. package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +2 -2
  198. package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +7 -0
  199. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +55 -50
  200. package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +47 -0
  201. package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-propose.md +2 -0
  202. package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +2 -0
  203. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +29 -10
  204. package/src/templates/mate-skills/claude/mate-publish-artifact/references/openspec.md +4 -2
  205. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +21 -0
  206. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +13 -0
  207. package/src/templates/mate-skills/openspec-references.ts +2 -0
  208. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +364 -224
  209. package/src/tools/setup/capabilities/companion-mentions.ts +27 -0
  210. package/src/tools/setup/capabilities/context-mode.ts +34 -5
  211. package/src/tools/setup/capabilities/graphify-secrets.ts +2 -14
  212. package/src/tools/setup/capabilities/graphify.ts +34 -7
  213. package/src/tools/setup/capabilities/openspec.ts +12 -2
  214. package/src/tools/setup/capabilities/react-doctor.ts +8 -1
  215. package/src/tools/setup/capabilities/rtk.ts +4 -0
  216. package/src/tools/setup/capabilities/tokensave.ts +77 -68
  217. package/src/tools/setup/engine.ts +3 -2
  218. package/src/tools/setup/install-contract.ts +8 -0
  219. package/src/tools/setup/mate-skill-copies.ts +51 -0
  220. package/src/tools/setup/package-managers/uv.ts +73 -11
  221. package/src/tools/setup/plugin.ts +5 -0
  222. package/src/tools/setup/providers/claude-plugin-hooks.ts +12 -0
  223. package/src/tools/setup/providers/claude-worktree-plugins.ts +122 -0
  224. package/src/tools/setup/providers/claude.ts +11 -5
  225. package/src/tools/setup/utils.ts +4 -0
  226. package/src/tools/setup/working-repo-cleanup.ts +29 -1
  227. package/src/tools/setup/working-repo-local-state.ts +252 -75
  228. package/src/tools/setup.ts +57 -16
  229. package/studio-dist/client/assets/companion-view-Csva26Ir.js +1 -0
  230. package/studio-dist/client/assets/delivery-path-DJMpRmiY.js +1 -0
  231. package/studio-dist/client/assets/dist-Dm7MtyHc.js +5 -0
  232. package/studio-dist/client/assets/factory-B7l9ZQyx.js +4 -0
  233. package/studio-dist/client/assets/index-n6uo_92S.js +40 -0
  234. package/studio-dist/client/assets/preload-helper-BLdHbfdN.js +1 -0
  235. package/studio-dist/client/assets/prepaint-CD5OpmTM.js +24 -0
  236. package/studio-dist/client/assets/queries-CN3JwMBX.js +1 -0
  237. package/studio-dist/client/assets/react-CabXf2Ds.js +1 -0
  238. package/studio-dist/client/assets/report-time-Dc-KOqQu.js +1 -0
  239. package/studio-dist/client/assets/reports-C01RsnMA.js +1 -0
  240. package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +1 -0
  241. package/studio-dist/client/assets/routes-4pbC-2Hj.js +1 -0
  242. package/studio-dist/client/assets/skills-CihQganl.js +1 -0
  243. package/studio-dist/client/assets/spec-areas-C2L48N4C.js +1 -0
  244. package/studio-dist/client/assets/specs-D24_35_K.js +1 -0
  245. package/studio-dist/client/assets/studio-DKxfi691.css +1 -0
  246. package/studio-dist/client/assets/studio-queries-rvbJupCy.js +3 -0
  247. package/studio-dist/client/assets/terminal-eU5fzQzv.css +1 -0
  248. package/studio-dist/client/assets/vault-Bd4CQiTK.js +1 -0
  249. package/studio-dist/client/assets/warnings-V_Ys51wJ.js +1 -0
  250. package/studio-dist/client/assets/wasm-inline-C2en61B5.js +1 -0
  251. package/studio-dist/client/assets/workflow-BJejeVwQ.js +1 -0
  252. package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-BQKuMdJW.js +3881 -0
  253. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +85 -0
  254. package/studio-dist/server/assets/actions-Bvgj9eb8.js +54 -0
  255. package/studio-dist/server/assets/actions-D8erOphH.js +44 -0
  256. package/studio-dist/server/assets/companion-view-aBady57v.js +33 -0
  257. package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +459 -0
  258. package/studio-dist/server/assets/createServerRpc-tK2lE9R2.js +11 -0
  259. package/studio-dist/server/assets/delivery-path-BkKNjgkf.js +778 -0
  260. package/studio-dist/server/assets/dist-DpJWKyCm.js +5582 -0
  261. package/studio-dist/server/assets/empty-plugin-adapters-Cipd4ZH4.js +4 -0
  262. package/studio-dist/server/assets/factory-D6xnjedJ.js +2385 -0
  263. package/studio-dist/server/assets/factory-DT3UzHlh.js +68 -0
  264. package/studio-dist/server/assets/model-PyPALjii.js +18 -0
  265. package/studio-dist/server/assets/prepaint-BMke0fo1.js +41 -0
  266. package/studio-dist/server/assets/queries-Ag2iL8q2.js +107 -0
  267. package/studio-dist/server/assets/react-COs0LHn-.js +51 -0
  268. package/studio-dist/server/assets/report-time-DAfzln-N.js +8 -0
  269. package/studio-dist/server/assets/reports-BnUNJVtx.js +126 -0
  270. package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +34 -0
  271. package/studio-dist/server/assets/router-BH--drIx.js +4298 -0
  272. package/studio-dist/server/assets/routes-khSDK1bV.js +361 -0
  273. package/studio-dist/server/assets/search-JAKurDNh.js +36 -0
  274. package/studio-dist/server/assets/shell-CboT2f66.js +51 -0
  275. package/studio-dist/server/assets/skills-MWYnWoKs.js +106 -0
  276. package/studio-dist/server/assets/spec-areas-DcnO6vW-.js +16 -0
  277. package/studio-dist/server/assets/specs-DE3w8hZP.js +155 -0
  278. package/studio-dist/server/assets/start-BW5ovN0k.js +33 -0
  279. package/studio-dist/server/assets/studio-BeltxxKt.js +216 -0
  280. package/studio-dist/server/assets/studio-queries-CLnP9kGu.js +3365 -0
  281. package/studio-dist/server/assets/utils-C9CX1kcy.js +221 -0
  282. package/studio-dist/server/assets/vault-BGulVoNh.js +70 -0
  283. package/studio-dist/server/assets/vault-CuyyhLyB.js +832 -0
  284. package/studio-dist/server/assets/views-Bd7cRr27.js +82 -0
  285. package/studio-dist/server/assets/warnings-BH05rOuG.js +15 -0
  286. package/studio-dist/server/assets/wasm-inline-CNeBKGwC.js +3 -0
  287. package/studio-dist/server/assets/workflow-BSuIKWqH.js +42 -0
  288. package/studio-dist/server/server.js +16220 -0
  289. package/src/cli/commands/studio/client-asset.ts +0 -16
  290. package/src/cli/commands/studio/views/client.ts +0 -44
  291. package/src/cli/commands/studio/views/companion-picker.tsx +0 -95
  292. package/src/cli/commands/studio/views/companion-selector.tsx +0 -94
  293. package/src/cli/commands/studio/views/dashboard/changes.tsx +0 -102
  294. package/src/cli/commands/studio/views/dashboard/index.tsx +0 -19
  295. package/src/cli/commands/studio/views/document.tsx +0 -910
  296. package/src/cli/commands/studio/views/error.tsx +0 -20
  297. package/src/cli/commands/studio/views/markdown.tsx +0 -250
  298. package/src/cli/commands/studio/views/palette.ts +0 -134
  299. package/src/cli/commands/studio/views/reports/index.tsx +0 -44
  300. package/src/cli/commands/studio/views/selection-fields.tsx +0 -14
  301. package/src/cli/commands/studio/views/skills/index.tsx +0 -68
  302. package/src/cli/commands/studio/views/specs/index.tsx +0 -149
  303. package/src/cli/commands/studio/views/studio-client/actions.ts +0 -51
  304. package/src/cli/commands/studio/views/studio-client/companion.ts +0 -13
  305. package/src/cli/commands/studio/views/studio-client/index.ts +0 -32
  306. package/src/cli/commands/studio/views/studio-client/keys.ts +0 -3
  307. package/src/cli/commands/studio/views/studio-client/main.ts +0 -3
  308. package/src/cli/commands/studio/views/studio-client/page.ts +0 -146
  309. package/src/cli/commands/studio/views/studio-client/panels.ts +0 -57
  310. package/src/cli/commands/studio/views/studio-client/reports.ts +0 -122
  311. package/src/cli/commands/studio/views/studio-client/theme.ts +0 -63
  312. package/src/cli/commands/studio/views/studio-client/vault-editor.ts +0 -166
  313. package/src/cli/commands/studio/views/studio-client/vault-pane.ts +0 -202
  314. package/src/cli/commands/studio/views/studio-client/vault-tree.ts +0 -258
  315. package/src/cli/commands/studio/views/studio-client.generated.ts +0 -2
  316. package/src/cli/commands/studio/views/styles.ts +0 -530
  317. package/src/cli/commands/studio/views/terminal.tsx +0 -484
  318. package/src/cli/commands/studio/views/vault/state.ts +0 -41
  319. package/src/cli/commands/studio/views/warnings.tsx +0 -21
  320. package/src/cli/commands/studio/views/workflow/delivery-path.tsx +0 -370
  321. package/src/cli/commands/studio/views/workflow/graph.ts +0 -220
  322. package/src/cli/commands/studio/views/workflow/index.tsx +0 -20
  323. package/src/cli/commands/studio/views/workflow/steps.ts +0 -278
  324. package/src/lib/components/theme.ts +0 -2
  325. package/src/tools/setup/git-utils.ts +0 -30
@@ -0,0 +1,267 @@
1
+ import { type Token, type Tokens, Lexer } from "marked";
2
+
3
+ import { highlightNodes } from "../../../report/highlight";
4
+
5
+ /**
6
+ * A rendered markdown file as plain data: text, or an element the browser builds from a fixed
7
+ * set of tags and attributes. Parsing, highlighting and link resolution happen on the server,
8
+ * and no part of the file is ever inserted as markup.
9
+ */
10
+ export type MdNode = string | MdElement;
11
+
12
+ export interface MdElement {
13
+ t: MdTag;
14
+ a?: MdAttributes;
15
+ c?: MdNode[];
16
+ }
17
+
18
+ export type MdTag =
19
+ | "h1"
20
+ | "h2"
21
+ | "h3"
22
+ | "h4"
23
+ | "h5"
24
+ | "h6"
25
+ | "p"
26
+ | "pre"
27
+ | "code"
28
+ | "span"
29
+ | "blockquote"
30
+ | "hr"
31
+ | "ol"
32
+ | "ul"
33
+ | "li"
34
+ | "input"
35
+ | "div"
36
+ | "table"
37
+ | "thead"
38
+ | "tbody"
39
+ | "tr"
40
+ | "th"
41
+ | "td"
42
+ | "strong"
43
+ | "em"
44
+ | "del"
45
+ | "br"
46
+ | "a";
47
+
48
+ export interface MdAttributes {
49
+ className?: string;
50
+ start?: number;
51
+ checked?: boolean;
52
+ align?: "left" | "right" | "center";
53
+ /** Only an absolute `http`/`https` address; opened without access to the vault page. */
54
+ href?: string;
55
+ /** A companion-relative markdown path the link opens in the vault. */
56
+ note?: string;
57
+ }
58
+
59
+ const MARKDOWN_TARGET = /\.(md|markdown)$/i;
60
+ const SCHEME = /^[a-z][a-z0-9+.-]*:/i;
61
+
62
+ /**
63
+ * A relative link as a companion-relative markdown path, or `null` when it is anything
64
+ * else. Textual only: nothing is looked up on disk, so a missing note is the vault's to refuse.
65
+ */
66
+ export function resolveNoteLink(target: string, openPath: string): string | null {
67
+ if (!target || SCHEME.test(target) || target.startsWith("//") || target.startsWith("#")) {
68
+ return null;
69
+ }
70
+ let pathname = target.split(/[?#]/, 1)[0] ?? "";
71
+ try {
72
+ pathname = decodeURIComponent(pathname);
73
+ } catch {
74
+ return null;
75
+ }
76
+ if (pathname.includes("\\") || !MARKDOWN_TARGET.test(pathname)) return null;
77
+ const folder = pathname.startsWith("/") ? [] : openPath.split("/").filter(Boolean).slice(0, -1);
78
+ for (const part of pathname.split("/")) {
79
+ if (part === "" || part === ".") continue;
80
+ if (part === "..") {
81
+ if (folder.length === 0) return null;
82
+ folder.pop();
83
+ } else {
84
+ folder.push(part);
85
+ }
86
+ }
87
+ return folder.length > 0 ? folder.join("/") : null;
88
+ }
89
+
90
+ const el = (t: MdTag, c?: MdNode[], a?: MdAttributes): MdElement => ({
91
+ t,
92
+ ...(a ? { a } : {}),
93
+ ...(c ? { c } : {}),
94
+ });
95
+
96
+ function plainText(tokens: Token[] | undefined, fallback: string): string {
97
+ if (!tokens) return fallback;
98
+ return tokens
99
+ .map((token) => ("tokens" in token && token.tokens ? plainText(token.tokens, "") : token.raw))
100
+ .join("");
101
+ }
102
+
103
+ function highlighted(code: string, language: string | undefined): MdNode[] {
104
+ const map = (node: ReturnType<typeof highlightNodes>[number]): MdNode =>
105
+ node.type === "text"
106
+ ? node.value
107
+ : el("span", node.children.map(map), { className: node.classNames.join(" ") });
108
+ return highlightNodes(code, language).map(map);
109
+ }
110
+
111
+ /** The same mapping the server-rendered vault used, producing data instead of markup. */
112
+ class TreeMapper {
113
+ constructor(private readonly path: string) {}
114
+
115
+ blocks(tokens: Token[] | undefined): MdNode[] {
116
+ return (tokens ?? []).flatMap((token) => this.block(token));
117
+ }
118
+
119
+ inline(tokens: Token[] | undefined, fallback = ""): MdNode[] {
120
+ if (!tokens) return [fallback];
121
+ return tokens.map((token) => this.span(token));
122
+ }
123
+
124
+ private block(token: Token): MdNode[] {
125
+ switch (token.type) {
126
+ case "space":
127
+ case "def":
128
+ return [];
129
+ case "heading": {
130
+ const heading = token as Tokens.Heading;
131
+ const depth = Math.min(Math.max(heading.depth, 1), 6);
132
+ return [el(`h${depth}` as MdTag, this.inline(heading.tokens, heading.text))];
133
+ }
134
+ case "paragraph": {
135
+ const paragraph = token as Tokens.Paragraph;
136
+ return [el("p", this.inline(paragraph.tokens, paragraph.text))];
137
+ }
138
+ case "text": {
139
+ const text = token as Tokens.Text;
140
+ return [el("p", this.inline(text.tokens, text.text))];
141
+ }
142
+ case "code": {
143
+ const code = token as Tokens.Code;
144
+ const language = code.lang?.trim().split(/\s+/, 1)[0] || undefined;
145
+ return [
146
+ el("pre", [el("code", highlighted(code.text, language))], { className: "md-fence" }),
147
+ ];
148
+ }
149
+ case "blockquote":
150
+ return [el("blockquote", this.blocks((token as Tokens.Blockquote).tokens))];
151
+ case "hr":
152
+ return [el("hr")];
153
+ case "list":
154
+ return [this.list(token as Tokens.List)];
155
+ case "table":
156
+ return [this.table(token as Tokens.Table)];
157
+ case "html":
158
+ // Raw markup is shown as the text it is, never inserted.
159
+ return [el("p", [(token as Tokens.HTML).raw.trim()], { className: "md-raw" })];
160
+ default:
161
+ return [el("p", [token.raw])];
162
+ }
163
+ }
164
+
165
+ private list(list: Tokens.List): MdElement {
166
+ const start =
167
+ list.ordered && typeof list.start === "number" && list.start !== 1 ? list.start : undefined;
168
+ return el(
169
+ list.ordered ? "ol" : "ul",
170
+ list.items.map((item) => {
171
+ const body = item.tokens.filter((token) => token.type !== "checkbox");
172
+ const content = item.loose ? this.blocks(body) : this.tight(body);
173
+ return el(
174
+ "li",
175
+ item.task ? [el("input", undefined, { checked: !!item.checked }), ...content] : content,
176
+ item.task ? { className: "md-task" } : undefined,
177
+ );
178
+ }),
179
+ start !== undefined ? { start } : undefined,
180
+ );
181
+ }
182
+
183
+ /** A tight item's text sits in the item, not in a paragraph of its own. */
184
+ private tight(tokens: Token[]): MdNode[] {
185
+ return tokens.flatMap((token) =>
186
+ token.type === "text"
187
+ ? this.inline((token as Tokens.Text).tokens, (token as Tokens.Text).text)
188
+ : this.block(token),
189
+ );
190
+ }
191
+
192
+ private table(table: Tokens.Table): MdElement {
193
+ const cell = (tag: "th" | "td", value: Tokens.TableCell) =>
194
+ el(
195
+ tag,
196
+ this.inline(value.tokens, value.text),
197
+ value.align ? { align: value.align } : undefined,
198
+ );
199
+ return el(
200
+ "div",
201
+ [
202
+ el("table", [
203
+ el("thead", [
204
+ el(
205
+ "tr",
206
+ table.header.map((value) => cell("th", value)),
207
+ ),
208
+ ]),
209
+ el(
210
+ "tbody",
211
+ table.rows.map((row) =>
212
+ el(
213
+ "tr",
214
+ row.map((value) => cell("td", value)),
215
+ ),
216
+ ),
217
+ ),
218
+ ]),
219
+ ],
220
+ { className: "md-table" },
221
+ );
222
+ }
223
+
224
+ private span(token: Token): MdNode {
225
+ switch (token.type) {
226
+ case "text": {
227
+ const text = token as Tokens.Text;
228
+ return text.tokens ? el("span", this.inline(text.tokens)) : text.text;
229
+ }
230
+ case "escape":
231
+ return (token as Tokens.Escape).text;
232
+ case "strong":
233
+ return el("strong", this.inline((token as Tokens.Strong).tokens));
234
+ case "em":
235
+ return el("em", this.inline((token as Tokens.Em).tokens));
236
+ case "del":
237
+ return el("del", this.inline((token as Tokens.Del).tokens));
238
+ case "codespan":
239
+ return el("code", [(token as Tokens.Codespan).text]);
240
+ case "br":
241
+ return el("br");
242
+ case "link":
243
+ return this.link(token as Tokens.Link);
244
+ case "image": {
245
+ // Not requested or shown: only what the author said the image is.
246
+ const image = token as Tokens.Image;
247
+ return image.text || plainText(image.tokens, "");
248
+ }
249
+ case "html":
250
+ return (token as Tokens.HTML).raw;
251
+ default:
252
+ return token.raw;
253
+ }
254
+ }
255
+
256
+ private link(link: Tokens.Link): MdNode {
257
+ const label = this.inline(link.tokens, link.text);
258
+ if (/^https?:\/\//i.test(link.href)) return el("a", label, { href: link.href });
259
+ const note = resolveNoteLink(link.href, this.path);
260
+ return note === null ? el("span", label) : el("a", label, { note });
261
+ }
262
+ }
263
+
264
+ /** A markdown file as data the browser renders; `path` is where its relative links start. */
265
+ export function markdownTree(source: string, path: string): MdNode[] {
266
+ return new TreeMapper(path).blocks(new Lexer({ gfm: true }).lex(source));
267
+ }
@@ -0,0 +1,185 @@
1
+ import { errorMessage } from "../../../../../runtime/error-message";
2
+ import type { VaultManager, VaultTreeNode } from "../../vault";
3
+ import { markdownTree, type MdNode } from "./markdown-tree";
4
+
5
+ /**
6
+ * A tree entry as the browser gets it: a folder carries its entries only when it is on the
7
+ * open path, so what crosses to the page depends on the entries shown, not on the
8
+ * repository's size.
9
+ */
10
+ export interface VaultEntry {
11
+ name: string;
12
+ /** Companion-relative, `/`-separated. */
13
+ path: string;
14
+ kind: "file" | "directory";
15
+ /** Present only for an expanded folder. */
16
+ children?: VaultEntry[];
17
+ }
18
+
19
+ export interface VaultOpenFile {
20
+ path: string;
21
+ content: string;
22
+ token: string;
23
+ /** The content rendered on the server; links already resolved. */
24
+ markdown: MdNode[];
25
+ }
26
+
27
+ export interface VaultView {
28
+ /** `null` while the listing still runs; the page asks again with `wait`. */
29
+ tree: VaultEntry[] | null;
30
+ generation: number | null;
31
+ watching: boolean;
32
+ warning: string | null;
33
+ failure: string | null;
34
+ /** The requested folder, or `null` when none was named or the tree does not hold it. */
35
+ dir: string | null;
36
+ /** Whether a named folder was missing from the listed tree. */
37
+ dirMissing: boolean;
38
+ open: VaultOpenFile | null;
39
+ refusal: string | null;
40
+ }
41
+
42
+ export interface VaultViewRequest {
43
+ path?: string;
44
+ dir?: string;
45
+ refresh?: boolean;
46
+ /** Waits for the listing instead of answering without it. */
47
+ wait?: boolean;
48
+ }
49
+
50
+ /** Most matches a filter shows; the rest are counted, not sent. */
51
+ export const VAULT_FILTER_LIMIT = 200;
52
+
53
+ const segments = (relative: string): string[] => relative.split(/[\\/]/).filter(Boolean);
54
+ const key = (relative: string): string => segments(relative).join("/");
55
+
56
+ function byKindThenName(a: VaultTreeNode, b: VaultTreeNode): number {
57
+ if (a.kind !== b.kind) return a.kind === "directory" ? -1 : 1;
58
+ return a.name.localeCompare(b.name);
59
+ }
60
+
61
+ /** Folders on the path to the open file (not the file itself) and to the open folder. */
62
+ function expandedPaths(path: string | null, dir: string | null): Set<string> {
63
+ const expanded = new Set<string>();
64
+ const add = (relative: string, includeLast: boolean) => {
65
+ const parts = segments(relative);
66
+ const count = includeLast ? parts.length : parts.length - 1;
67
+ for (let index = 1; index <= count; index += 1) expanded.add(parts.slice(0, index).join("/"));
68
+ };
69
+ if (path) add(path, false);
70
+ if (dir) add(dir, true);
71
+ return expanded;
72
+ }
73
+
74
+ /** Sorted entries, folders first; only expanded folders keep theirs. */
75
+ function pruneTree(nodes: VaultTreeNode[], expanded: Set<string>): VaultEntry[] {
76
+ return nodes.toSorted(byKindThenName).map((node) => {
77
+ const path = key(node.path);
78
+ const entry: VaultEntry = { name: node.name, path, kind: node.kind };
79
+ if (node.kind === "directory" && expanded.has(path)) {
80
+ entry.children = pruneTree(node.children ?? [], expanded);
81
+ }
82
+ return entry;
83
+ });
84
+ }
85
+
86
+ /** Walks node names, so a requested folder is only ever one the listed tree holds. */
87
+ function findDirectory(tree: VaultTreeNode[], relative: string): VaultTreeNode | null {
88
+ let level = tree;
89
+ let found: VaultTreeNode | null = null;
90
+ for (const name of segments(relative)) {
91
+ found = level.find((node) => node.kind === "directory" && node.name === name) ?? null;
92
+ if (!found) return null;
93
+ level = found.children ?? [];
94
+ }
95
+ return found;
96
+ }
97
+
98
+ /** An open file with its rendered form, or the vault's refusal. */
99
+ export async function vaultFile(
100
+ manager: VaultManager,
101
+ companionPath: string,
102
+ path: string,
103
+ ): Promise<{ open: VaultOpenFile | null; refusal: string | null }> {
104
+ try {
105
+ const file = await manager.open(companionPath, path);
106
+ const relative = key(file.path);
107
+ return {
108
+ open: { ...file, path: relative, markdown: markdownTree(file.content, relative) },
109
+ refusal: null,
110
+ };
111
+ } catch (error) {
112
+ return { open: null, refusal: errorMessage(error) };
113
+ }
114
+ }
115
+
116
+ /** One vault page's state: the bounded tree, the open folder or file. */
117
+ export async function vaultView(
118
+ manager: VaultManager,
119
+ companionPath: string,
120
+ request: VaultViewRequest,
121
+ ): Promise<VaultView> {
122
+ const path = request.path ? key(request.path) : null;
123
+ const dir = request.dir ? key(request.dir) : null;
124
+ let failure: string | null = null;
125
+ let listed: Awaited<ReturnType<VaultManager["tree"]>> | null = null;
126
+ try {
127
+ listed = request.wait
128
+ ? await manager.tree(companionPath, request.refresh)
129
+ : await manager.prefetch(companionPath, request.refresh);
130
+ } catch (error) {
131
+ failure = errorMessage(error);
132
+ }
133
+ const file = path ? await vaultFile(manager, companionPath, path) : { open: null, refusal: null };
134
+ const found = listed && dir ? findDirectory(listed.tree, dir) : null;
135
+ return {
136
+ tree: listed ? pruneTree(listed.tree, expandedPaths(path, dir)) : null,
137
+ generation: listed?.generation ?? null,
138
+ watching: listed?.watching ?? false,
139
+ warning: listed?.warning ?? null,
140
+ failure,
141
+ dir: found ? dir : null,
142
+ dirMissing: Boolean(listed && dir && !found),
143
+ ...file,
144
+ };
145
+ }
146
+
147
+ /** A folder's entries when the viewer first expands it; `null` when the listed tree lacks it. */
148
+ export async function vaultChildren(
149
+ manager: VaultManager,
150
+ companionPath: string,
151
+ dir: string,
152
+ ): Promise<{ entries: VaultEntry[]; generation: number } | null> {
153
+ const listed = await manager.tree(companionPath);
154
+ const folder = findDirectory(listed.tree, dir);
155
+ if (!folder) return null;
156
+ return { entries: pruneTree(folder.children ?? [], new Set()), generation: listed.generation };
157
+ }
158
+
159
+ /** Files whose path contains `query`, over the whole listed tree, bounded; never touches the disk. */
160
+ export async function vaultMatches(
161
+ manager: VaultManager,
162
+ companionPath: string,
163
+ query: string,
164
+ ): Promise<{ shown: VaultEntry[]; total: number; generation: number }> {
165
+ const listed = await manager.tree(companionPath);
166
+ const needle = query.trim().toLowerCase();
167
+ const shown: VaultEntry[] = [];
168
+ let total = 0;
169
+ if (!needle) return { shown, total, generation: listed.generation };
170
+ const stack = listed.tree.toReversed();
171
+ while (stack.length > 0) {
172
+ const node = stack.pop()!;
173
+ if (node.kind === "directory") {
174
+ for (let index = (node.children?.length ?? 0) - 1; index >= 0; index -= 1) {
175
+ stack.push(node.children![index]!);
176
+ }
177
+ } else if (key(node.path).toLowerCase().includes(needle)) {
178
+ total += 1;
179
+ if (shown.length < VAULT_FILTER_LIMIT) {
180
+ shown.push({ name: node.name, path: key(node.path), kind: "file" });
181
+ }
182
+ }
183
+ }
184
+ return { shown, total, generation: listed.generation };
185
+ }
@@ -0,0 +1,131 @@
1
+ import { randomUUID } from "node:crypto";
2
+
3
+ import { type FactoryClient, factoryClient } from "../../../lib/factory/client";
4
+ import type { AttachStart } from "../../../lib/factory/attach-client";
5
+ import { prepareWorkset } from "../../../lib/factory/prepare";
6
+ import { writeWorkset } from "../../../lib/workset/record";
7
+ import { effectiveLaunchCompanion } from "./terminal-launch";
8
+ import type { StudioInventory } from "./inventory";
9
+ import { NO_CREDENTIAL } from "../../../lib/factory/credential-store";
10
+
11
+ /**
12
+ * Resolves a Workset session start: everything is checked and prepared on the server
13
+ * (credential, record, container, link, first turn), and the terminal is handed only
14
+ * the attach helper's argv. The browser names the Workset and nothing else.
15
+ */
16
+
17
+ export type WorksetLaunchResolution =
18
+ | { companionPath: string; workset: { id: string; title: string }; argv: string[] }
19
+ | { reason: string };
20
+
21
+ export interface WorksetResolverOptions {
22
+ collectInventory: () => Promise<StudioInventory>;
23
+ launchCompanion?: string | null;
24
+ /** The Mate invocation prefix the attach helper runs under. */
25
+ mateCommand: string[];
26
+ client?: () => FactoryClient | null;
27
+ env?: NodeJS.ProcessEnv;
28
+ now?: () => Date;
29
+ /** Skip the companion's Git synchronization in the session, as Studio's own launches do. */
30
+ noGit?: boolean;
31
+ /**
32
+ * While a person has control of the Workset's Outcome: the factory's Claude session the
33
+ * native session resumes. `null` lets the session start as it otherwise would.
34
+ */
35
+ takenOver?: (id: string) => Promise<{ claudeSession: string | null } | null>;
36
+ }
37
+
38
+ /** Claude Code's project directory for a working directory: every non-alphanumeric becomes `-`. */
39
+ const HAS_CONVERSATION =
40
+ 'd=$(printf %s "$PWD" | sed "s/[^A-Za-z0-9-]/-/g"); test -d "$HOME/.claude/projects/$d"';
41
+
42
+ /**
43
+ * Interactive Claude shows its first-run login screen until `~/.claude.json` says onboarding is
44
+ * done; the factory's headless turns never set it. Merged in place, every other key kept.
45
+ */
46
+ const ONBOARDED = [
47
+ "node",
48
+ "-e",
49
+ [
50
+ 'const fs = require("fs");',
51
+ "const file = `${process.env.HOME}/.claude.json`;",
52
+ "let config = {};",
53
+ 'try { config = JSON.parse(fs.readFileSync(file, "utf8")); } catch {}',
54
+ "if (config.hasCompletedOnboarding !== true) {",
55
+ " config.hasCompletedOnboarding = true;",
56
+ " fs.writeFileSync(`${file}.tmp`, JSON.stringify(config, null, 2));",
57
+ " fs.renameSync(`${file}.tmp`, file);",
58
+ "}",
59
+ ].join("\n"),
60
+ ];
61
+
62
+ export function createWorksetResolver(
63
+ options: WorksetResolverOptions,
64
+ ): (id: string, digest: string | null, session: string) => Promise<WorksetLaunchResolution> {
65
+ const clientFor = options.client ?? (() => factoryClient(options.env?.MATE_FACTORY_BROKER));
66
+ const now = options.now ?? (() => new Date());
67
+ return async (id, digest, session) => {
68
+ const client = clientFor();
69
+ if (!client) return { reason: "Workset sessions need the appliance's factory mode" };
70
+ const companion = await effectiveLaunchCompanion(
71
+ await options.collectInventory(),
72
+ options.launchCompanion,
73
+ digest,
74
+ );
75
+ if (!companion) return { reason: "no registered companion is selected" };
76
+ try {
77
+ if ((await client.info()).credential === null) {
78
+ return { reason: NO_CREDENTIAL };
79
+ }
80
+ const record = await prepareWorkset(client, companion.path, id, options.env);
81
+ const onboarded = await client.exec({ id, command: ONBOARDED });
82
+ if (onboarded.status !== 0)
83
+ return { reason: "the Workset's Claude settings could not be prepared" };
84
+
85
+ const takenOver = (await options.takenOver?.(id)) ?? null;
86
+ if (takenOver && !takenOver.claudeSession) {
87
+ return { reason: "this Outcome has no factory conversation to take over" };
88
+ }
89
+ const resumeSession = takenOver?.claudeSession;
90
+ let start: AttachStart;
91
+ if (resumeSession) {
92
+ start = "resume";
93
+ } else if (
94
+ record.changes.length === 0 &&
95
+ record.stage === "explore" &&
96
+ !record.extra.exploreStartedAt
97
+ ) {
98
+ start = "explore";
99
+ await writeWorkset(companion.path, {
100
+ ...record,
101
+ extra: { ...record.extra, exploreStartedAt: now().toISOString() },
102
+ });
103
+ } else {
104
+ const conversation = await client.exec({ id, command: ["sh", "-c", HAS_CONVERSATION] });
105
+ start = conversation.status === 0 ? "continue" : "clarify";
106
+ }
107
+ return {
108
+ companionPath: companion.path,
109
+ workset: { id, title: record.title },
110
+ argv: [
111
+ ...options.mateCommand,
112
+ "factory",
113
+ "attach",
114
+ id,
115
+ "--session",
116
+ session,
117
+ "--start",
118
+ start,
119
+ "--companion",
120
+ companion.path,
121
+ ...(resumeSession ? ["--resume-session", resumeSession] : []),
122
+ ...(options.noGit ? ["--no-git"] : []),
123
+ ],
124
+ };
125
+ } catch (error) {
126
+ return { reason: (error as Error).message };
127
+ }
128
+ };
129
+ }
130
+
131
+ export const newSessionId = () => randomUUID();
@@ -77,8 +77,15 @@ export async function runUnwrapCommand(
77
77
  return;
78
78
  }
79
79
 
80
+ const reportKept = () => {
81
+ if (!result.kept) return;
82
+ console.log(
83
+ ` Kept: ${result.kept.lines} copy exclude lines still needed by ${result.kept.keptFor.join(", ")}`,
84
+ );
85
+ };
80
86
  if (result.kind === "absent") {
81
87
  console.log(`Not wrapped: ${repository.id}`);
88
+ reportKept();
82
89
  return;
83
90
  }
84
91
 
@@ -89,6 +96,7 @@ export async function runUnwrapCommand(
89
96
  if (result.copies.length > 0) {
90
97
  console.log(` Withdrawn: ${result.copies.length} companion copies under .opencode/`);
91
98
  }
99
+ reportKept();
92
100
  console.log(
93
101
  `The next \`${FRAMEWORK_NAME} claude\` or \`${FRAMEWORK_NAME} opencode\` wraps this repository again.`,
94
102
  );
@@ -9,6 +9,8 @@ import {
9
9
  isNewer,
10
10
  } from "../../lib/update-checker";
11
11
  import { confirmPrompt } from "../../lib/components/confirm-prompt";
12
+ import { createStartupProgress } from "../../lib/components/startup-progress";
13
+ import { releaseTerminal } from "../../lib/live-progress";
12
14
  import { resolvePackageRoot } from "../../lib/package-root";
13
15
 
14
16
  type InstallResult = ReturnType<typeof installPublicPackageSync>;
@@ -34,6 +36,7 @@ export const updateCommandDeps = {
34
36
  getCurrentVersion,
35
37
  isNewer,
36
38
  confirmPrompt,
39
+ createProgress: createStartupProgress,
37
40
  isNpmManagedInstall: () => {
38
41
  const packageName = getUpdateConfig().packageName;
39
42
  const packageRoot = resolvePackageRoot(process.argv[1], packageName);
@@ -76,18 +79,35 @@ export const updateCommandDeps = {
76
79
  * unavailable, or the current Mate install is not npm-managed.
77
80
  */
78
81
  export async function runUpdateCommand(argv: string[]): Promise<void> {
82
+ const progress = updateCommandDeps.createProgress("Checking for updates");
83
+ try {
84
+ await runUpdate(argv, progress);
85
+ } finally {
86
+ progress.stop();
87
+ }
88
+ }
89
+
90
+ async function runUpdate(
91
+ argv: string[],
92
+ progress: ReturnType<typeof createStartupProgress>,
93
+ ): Promise<void> {
79
94
  const checkOnly = argv.includes("--check");
80
95
  const skipConfirm = argv.includes("--yes");
81
96
  const current = updateCommandDeps.getCurrentVersion();
82
97
 
83
98
  let latest: string;
84
99
  try {
85
- latest = await updateCommandDeps.fetchLatestVersion();
100
+ latest = await progress.step("registry", "Checking registry", () =>
101
+ updateCommandDeps.fetchLatestVersion(),
102
+ );
86
103
  } catch {
104
+ progress.stop();
87
105
  process.stderr.write(`${FRAMEWORK_NAME}: could not reach registry to check for updates\n`);
88
106
  process.exitCode = 1;
89
107
  return;
90
108
  }
109
+ // The version lines and the confirm prompt below own the terminal.
110
+ releaseTerminal();
91
111
 
92
112
  if (checkOnly) {
93
113
  if (updateCommandDeps.isNewer(latest, current)) {
@@ -140,14 +160,20 @@ export async function runUpdateCommand(argv: string[]): Promise<void> {
140
160
  return;
141
161
  }
142
162
 
163
+ // npm writes straight to the terminal: a labelled hand-over, no spinner.
164
+ progress.handOver("upgrade", `Upgrading to ${latest}`);
143
165
  const result = updateCommandDeps.installLatest(latest);
144
166
  if (result.status !== 0 || result.error) {
167
+ progress.fail("upgrade");
145
168
  process.stderr.write(
146
169
  `${FRAMEWORK_NAME}: upgrade command exited with status ${result.status ?? 1}\n`,
147
170
  );
148
171
  process.exitCode = 1;
149
172
  return;
150
173
  }
174
+ progress.succeed("upgrade");
175
+ // Post-install renders its own screen.
176
+ progress.stop();
151
177
 
152
178
  await updateCommandDeps.saveUpdateState(latest);
153
179