@uniqbit/mate-core 1.0.0-canary.5 → 1.0.0-canary.6

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 (435) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
  2. package/claude-capability-plugins/companion-mentions/hooks/register.ts +1 -1
  3. package/claude-plugin/hooks/hooks.json +41 -1
  4. package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
  5. package/claude-plugin/hooks/workflow-turn.mjs +68 -0
  6. package/opencode-plugin/src/companion.ts +6 -0
  7. package/opencode-plugin/src/server.ts +33 -2
  8. package/package.json +5 -2
  9. package/src/cli/commands/artifact/apply-context.ts +1 -0
  10. package/src/cli/commands/artifact/artifact.ts +16 -0
  11. package/src/cli/commands/artifact/delivery/archive.ts +37 -112
  12. package/src/cli/commands/artifact/delivery/branch-flags.ts +19 -1
  13. package/src/cli/commands/artifact/delivery/environment.ts +32 -72
  14. package/src/cli/commands/artifact/delivery/link.ts +53 -34
  15. package/src/cli/commands/artifact/delivery/output.ts +25 -4
  16. package/src/cli/commands/artifact/delivery/resolve.ts +101 -0
  17. package/src/cli/commands/artifact/delivery/submit.ts +164 -0
  18. package/src/cli/commands/artifact/delivery/take.ts +45 -0
  19. package/src/cli/commands/artifact/extract-repo-name.ts +1 -1
  20. package/src/cli/commands/artifact/finish/command.ts +455 -43
  21. package/src/cli/commands/artifact/finish/engine.ts +79 -61
  22. package/src/cli/commands/artifact/finish/finisher.ts +5 -12
  23. package/src/cli/commands/artifact/finish/git.ts +9 -10
  24. package/src/cli/commands/artifact/finish/openspec.ts +21 -174
  25. package/src/cli/commands/artifact/finish/secret-scan.ts +5 -43
  26. package/src/cli/commands/artifact/finish/worktree-cleanup.ts +57 -7
  27. package/src/cli/commands/artifact/pending/command.ts +119 -6
  28. package/src/cli/commands/artifact/pending/discovery.ts +7 -11
  29. package/src/cli/commands/artifact/project/command.ts +60 -0
  30. package/src/cli/commands/companion/list.ts +70 -14
  31. package/src/cli/commands/companion/sync.ts +18 -0
  32. package/src/cli/commands/companion/update.ts +4 -19
  33. package/src/cli/commands/install.ts +48 -36
  34. package/src/cli/commands/launch/claude.ts +2 -0
  35. package/src/cli/commands/launch/shared.ts +33 -6
  36. package/src/cli/commands/plugin/install.ts +27 -11
  37. package/src/cli/commands/report/index.ts +180 -184
  38. package/src/cli/commands/report/markdown.ts +67 -72
  39. package/src/cli/commands/shared/companion-selection.ts +3 -1
  40. package/src/cli/commands/studio/access.ts +6 -14
  41. package/src/cli/commands/studio/areas.ts +112 -33
  42. package/src/cli/commands/studio/companion-add.ts +72 -0
  43. package/src/cli/commands/studio/companion-removal.ts +15 -8
  44. package/src/cli/commands/studio/graph-model.ts +61 -0
  45. package/src/cli/commands/studio/graph.ts +336 -0
  46. package/src/cli/commands/studio/index.ts +4 -4
  47. package/src/{lib/factory/outcomes/sessions.ts → cli/commands/studio/live-sessions.ts} +26 -2
  48. package/src/cli/commands/studio/payload.ts +214 -32
  49. package/src/cli/commands/studio/reports.ts +19 -18
  50. package/src/cli/commands/studio/routes.ts +5 -18
  51. package/src/cli/commands/studio/selection.ts +12 -5
  52. package/src/cli/commands/studio/server.ts +291 -191
  53. package/src/cli/commands/studio/service-host.ts +266 -0
  54. package/src/cli/commands/studio/services.ts +34 -16
  55. package/src/cli/commands/studio/studio-app.ts +1 -0
  56. package/src/cli/commands/studio/terminal.ts +45 -3
  57. package/src/cli/commands/studio/vault.ts +41 -40
  58. package/src/cli/commands/studio/views/model.ts +1 -9
  59. package/src/cli/commands/studio/views/vault/markdown-tree.ts +90 -8
  60. package/src/cli/commands/unwrap.ts +3 -0
  61. package/src/cli/commands/update.ts +2 -0
  62. package/src/cli/commands/vscode/release-vsix.json +4 -0
  63. package/src/cli/commands/vscode/setup.ts +71 -13
  64. package/src/cli/commands/vscode/vsix.ts +48 -7
  65. package/src/cli/commands/workflow/workflow.ts +516 -0
  66. package/src/cli/commands/working/cleanup.ts +40 -8
  67. package/src/cli/commands/working/worktree.ts +176 -35
  68. package/src/cli/main.ts +39 -10
  69. package/src/cli/repo-list-table.tsx +73 -37
  70. package/src/cli/usage.ts +19 -8
  71. package/src/factory-host.ts +69 -0
  72. package/src/hooks/companion-instructions.ts +19 -8
  73. package/src/hooks/hook-io.ts +3 -1
  74. package/src/hooks/rtk-worktree-git.ts +48 -0
  75. package/src/hooks/session-banner.ts +25 -0
  76. package/src/hooks/validate-artifact-path.ts +44 -12
  77. package/src/hooks/workflow-turn.ts +219 -0
  78. package/src/lib/apply-context/fingerprint.ts +2 -1
  79. package/src/lib/apply-context/protocol.ts +2 -2
  80. package/src/lib/artifact-trailer.ts +27 -0
  81. package/src/lib/change-layout.ts +83 -38
  82. package/src/lib/delivery/branch-template.ts +114 -0
  83. package/src/lib/delivery/branches.ts +21 -16
  84. package/src/lib/delivery/checkout.ts +103 -0
  85. package/src/lib/delivery/environment.ts +131 -7
  86. package/src/lib/delivery/merge-git.ts +282 -26
  87. package/src/lib/delivery/overlap.ts +68 -16
  88. package/src/lib/delivery/record-delivery.ts +178 -37
  89. package/src/lib/delivery/record.ts +201 -27
  90. package/src/lib/delivery/refresh.ts +212 -151
  91. package/src/lib/delivery/remote.ts +66 -0
  92. package/src/lib/delivery/repository-access.ts +19 -60
  93. package/src/lib/delivery/resolve-branch.ts +157 -110
  94. package/src/lib/delivery/stages.ts +83 -50
  95. package/src/lib/delivery/staging/apply-chain.ts +164 -0
  96. package/src/lib/delivery/staging/artifact-type.ts +101 -0
  97. package/src/lib/delivery/staging/declared-type.ts +277 -0
  98. package/src/lib/delivery/staging/naming.ts +64 -0
  99. package/src/lib/delivery/staging/openspec-type.ts +135 -0
  100. package/src/lib/delivery/staging/pending-edit.ts +291 -0
  101. package/src/lib/delivery/staging/pending.ts +780 -0
  102. package/src/lib/delivery/staging/project.ts +373 -0
  103. package/src/lib/delivery/staging/publish.ts +1024 -0
  104. package/src/lib/delivery/staging/refs.ts +258 -0
  105. package/src/lib/delivery/staging/registry.ts +73 -0
  106. package/src/lib/delivery/staging/replay.ts +308 -0
  107. package/src/lib/delivery/staging/requirement-blocks.ts +10 -0
  108. package/src/lib/delivery/staging/resolve.ts +264 -0
  109. package/src/lib/delivery/staging/settle-linked.ts +290 -0
  110. package/src/lib/delivery/staging/submit.ts +929 -0
  111. package/src/lib/delivery/staging/worktree.ts +130 -0
  112. package/src/lib/delivery/submit-change.ts +443 -0
  113. package/src/lib/git-key.ts +15 -0
  114. package/src/lib/install.ts +2 -0
  115. package/src/lib/openspec-canonical-frontmatter.ts +159 -0
  116. package/src/lib/orchestrator/adapters/base.ts +31 -20
  117. package/src/lib/orchestrator/adapters/claude.ts +16 -3
  118. package/src/lib/orchestrator/adapters/opencode.ts +2 -0
  119. package/src/lib/orchestrator/companion-git-sync.ts +152 -16
  120. package/src/lib/orchestrator/companion-hub.ts +6 -1
  121. package/src/lib/orchestrator/engine-floor.ts +48 -0
  122. package/src/lib/orchestrator/framework-context.ts +15 -1
  123. package/src/lib/orchestrator/launcher.ts +34 -1
  124. package/src/lib/orchestrator/projection-claude-commands.ts +2 -2
  125. package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
  126. package/src/lib/orchestrator/projection-claude-links.ts +33 -8
  127. package/src/lib/orchestrator/projection-claude-skills.ts +2 -2
  128. package/src/lib/orchestrator/projection-entries.ts +22 -18
  129. package/src/lib/orchestrator/projection-opencode-copies.ts +65 -21
  130. package/src/lib/orchestrator/projection-runtime-documents.ts +66 -43
  131. package/src/lib/orchestrator/projection-types.ts +28 -1
  132. package/src/lib/orchestrator/refresh-working-claude-links.ts +4 -1
  133. package/src/lib/orchestrator/session-prepare.ts +17 -2
  134. package/src/lib/orchestrator/setup-compatibilities.ts +1 -1
  135. package/src/lib/orchestrator/types.ts +4 -0
  136. package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
  137. package/src/lib/orchestrator/working-repo-projection.ts +24 -4
  138. package/src/lib/orchestrator/wrap-pass.ts +1 -0
  139. package/src/lib/prebuilt-workspace-prepare.ts +2 -1
  140. package/src/lib/prebuilt-workspace.ts +1 -0
  141. package/src/lib/public-npm.ts +95 -50
  142. package/src/lib/session-state.ts +74 -3
  143. package/src/lib/update-checker.ts +7 -1
  144. package/src/lib/usage/aggregate.ts +202 -0
  145. package/src/lib/usage/cache.ts +87 -0
  146. package/src/lib/usage/claude-pricing.ts +71 -0
  147. package/src/lib/usage/claude.ts +189 -0
  148. package/src/lib/usage/collect.ts +56 -0
  149. package/src/lib/usage/opencode.ts +188 -0
  150. package/src/lib/usage/records.ts +80 -0
  151. package/src/lib/usage/rtk-database.ts +72 -0
  152. package/src/lib/usage/savings.ts +209 -0
  153. package/src/lib/usage/scope.ts +182 -0
  154. package/src/lib/usage/source.ts +102 -0
  155. package/src/lib/usage/types.ts +143 -0
  156. package/src/lib/usage/window.ts +37 -0
  157. package/src/lib/workflow/declaration.ts +6 -0
  158. package/src/lib/workflow/handoff.ts +90 -0
  159. package/src/lib/workflow/hook-trust.ts +108 -0
  160. package/src/lib/workflow/position.ts +524 -0
  161. package/src/lib/workflow/report.ts +79 -0
  162. package/src/lib/workflow/work.ts +106 -0
  163. package/src/lib/workset/factory-local.ts +157 -0
  164. package/src/lib/workset/record.ts +25 -11
  165. package/src/lib/workset/repositories.ts +118 -25
  166. package/src/lib/workset/stage.ts +4 -2
  167. package/src/lib/workset/stages.ts +64 -4
  168. package/src/lib/workset/worktree-include.ts +161 -0
  169. package/src/lib/workset/worktree-index.ts +6 -2
  170. package/src/lib/workset/worktree.ts +622 -114
  171. package/src/opencode/companion-hooks.ts +52 -13
  172. package/src/opencode/companion-policy.ts +18 -5
  173. package/src/opencode/enter-worktree.ts +254 -6
  174. package/src/opencode/projected-guidance.ts +5 -2
  175. package/src/opencode/session-register.ts +2 -2
  176. package/src/opencode/turn-hook.ts +241 -0
  177. package/src/playbooks/companion-guidance.ts +6 -3
  178. package/src/plugin-api.ts +42 -0
  179. package/src/runtime/artifact-trailers.ts +63 -0
  180. package/src/runtime/claude-bg-isolation.ts +138 -0
  181. package/src/runtime/claude-hook-group.ts +2 -0
  182. package/src/runtime/companion-git-state.ts +155 -10
  183. package/src/runtime/companion-git.ts +96 -13
  184. package/src/runtime/companion-guidance.ts +107 -8
  185. package/src/runtime/companion-instructions.ts +1 -1
  186. package/src/runtime/companion-sync.ts +109 -21
  187. package/src/runtime/current-branch.ts +16 -2
  188. package/src/runtime/entered-worktree.ts +24 -0
  189. package/src/runtime/env-names.ts +2 -2
  190. package/src/runtime/env.ts +7 -6
  191. package/src/runtime/forge-remote.ts +48 -0
  192. package/src/runtime/git-layout.ts +21 -7
  193. package/src/runtime/git-tracked.ts +60 -0
  194. package/src/runtime/json-fields.ts +8 -0
  195. package/src/runtime/pending-records.ts +533 -0
  196. package/src/runtime/projected-guidance.ts +6 -2
  197. package/src/runtime/publication-secret-scan.ts +45 -0
  198. package/src/runtime/repo-destination.ts +72 -0
  199. package/src/runtime/repo-local.ts +25 -3
  200. package/src/runtime/rtk-git-guard.ts +66 -0
  201. package/src/runtime/runtime-document-manifest.ts +229 -19
  202. package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
  203. package/src/runtime/secret-guard.ts +9 -2
  204. package/src/runtime/secret-patterns.ts +3 -2
  205. package/src/runtime/secret-policy-weakening.ts +122 -0
  206. package/src/runtime/serving-claude-wrap.ts +15 -2
  207. package/src/runtime/skill-prefix.ts +75 -0
  208. package/src/runtime/submitted-arrivals.ts +547 -0
  209. package/src/runtime/turn-state.d.mts +14 -0
  210. package/src/runtime/turn-state.mjs +93 -0
  211. package/src/runtime/umbrella-children.ts +52 -0
  212. package/src/runtime/umbrella-folder.ts +84 -0
  213. package/src/runtime/workflow/change-folders.ts +66 -0
  214. package/src/runtime/workflow/declaration.ts +720 -0
  215. package/src/runtime/workflow/globs.ts +85 -0
  216. package/src/runtime/workflow/next-handoff-process.ts +98 -0
  217. package/src/runtime/workflow/turn.ts +309 -0
  218. package/src/runtime/workflow/workflow.ts +262 -0
  219. package/src/runtime/wrap-state.ts +5 -13
  220. package/src/studio.ts +71 -19
  221. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/schema.yaml +3 -3
  222. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/design.md +1 -1
  223. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/proposal.md +1 -1
  224. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/tasks.md +1 -1
  225. package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +3 -3
  226. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +103 -30
  227. package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +1 -1
  228. package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +7 -70
  229. package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +13 -7
  230. package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +10 -0
  231. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +46 -14
  232. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +50 -31
  233. package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +13 -7
  234. package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +1 -1
  235. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +114 -86
  236. package/src/templates/mate-skills/agents/mate-publish-artifact/references/openspec.md +111 -100
  237. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +11 -5
  238. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +16 -6
  239. package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +114 -0
  240. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +103 -30
  241. package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +1 -1
  242. package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +7 -70
  243. package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +13 -7
  244. package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +10 -0
  245. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +46 -14
  246. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +50 -31
  247. package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +13 -7
  248. package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +1 -1
  249. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +114 -86
  250. package/src/templates/mate-skills/claude/mate-publish-artifact/references/openspec.md +111 -100
  251. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +11 -5
  252. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +16 -6
  253. package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +114 -0
  254. package/src/templates/mate-skills/openspec-references.ts +3 -2
  255. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +912 -139
  256. package/src/tools/setup/capabilities/openspec.ts +54 -15
  257. package/src/tools/setup/capabilities/rtk.ts +98 -5
  258. package/src/tools/setup/capabilities/tokensave.ts +3 -2
  259. package/src/tools/setup/dynamic-plugins/api.ts +38 -0
  260. package/src/tools/setup/dynamic-plugins/audiences.ts +65 -21
  261. package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
  262. package/src/tools/setup/dynamic-plugins/host.ts +2 -32
  263. package/src/tools/setup/dynamic-plugins/hydrate.ts +4 -4
  264. package/src/tools/setup/dynamic-plugins/install.ts +24 -22
  265. package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
  266. package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
  267. package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
  268. package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
  269. package/src/tools/setup/engine.ts +20 -1
  270. package/src/tools/setup/mate.ts +5 -3
  271. package/src/tools/setup/package-managers/bun.ts +8 -8
  272. package/src/tools/setup/plugin.ts +9 -1
  273. package/src/tools/setup/plugins/gitignore.ts +15 -9
  274. package/src/tools/setup/plugins/guidance.ts +4 -2
  275. package/src/tools/setup/providers/claude-plugin-hooks.ts +30 -0
  276. package/src/tools/setup/providers/claude.ts +43 -6
  277. package/src/tools/setup/service-registry.ts +69 -0
  278. package/src/tools/setup/service.ts +233 -0
  279. package/src/tools/setup/utils.ts +28 -5
  280. package/src/tools/setup/working-repo-cleanup.ts +2 -2
  281. package/src/tools/setup/working-repo-local-state.ts +2 -0
  282. package/src/tools/setup.ts +25 -14
  283. package/studio-dist/client/assets/app-BFVyWHGo.css +2 -0
  284. package/studio-dist/client/assets/button-D6LrRkOG.js +1 -0
  285. package/studio-dist/client/assets/combobox-Dk2MMZWE.js +1 -0
  286. package/studio-dist/client/assets/companion-view-BVaZNtiI.js +1 -0
  287. package/studio-dist/client/assets/fields-D_FYhxQr.js +1 -0
  288. package/studio-dist/client/assets/getting-started-ByWRg7hC.js +1 -0
  289. package/studio-dist/client/assets/getting-started-DZSjYC-b.js +1 -0
  290. package/studio-dist/client/assets/getting-started._topic-C6OyQ4G6.js +1 -0
  291. package/studio-dist/client/assets/getting-started.index-BkmPHdEm.js +1 -0
  292. package/studio-dist/client/assets/graph-7jm2XzyL.js +2 -0
  293. package/studio-dist/client/assets/graph-canvas-DDuzsNSx.js +3242 -0
  294. package/studio-dist/client/assets/guides-D9VTjWXP.js +1 -0
  295. package/studio-dist/client/assets/index-BBmFpG4y.js +40 -0
  296. package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
  297. package/studio-dist/client/assets/markdown-view-RL5YvfZg.js +1 -0
  298. package/studio-dist/client/assets/panel-B8F8sOKQ.js +1 -0
  299. package/studio-dist/client/assets/plugins._service._view-CynxTbMx.js +1 -0
  300. package/studio-dist/client/assets/queries-axYk2u9L.js +1 -0
  301. package/studio-dist/client/assets/react-r45OnJCw.js +27 -0
  302. package/studio-dist/client/assets/reports-BCAyXh6p.js +1 -0
  303. package/studio-dist/client/assets/routes-BFPqq89E.js +1 -0
  304. package/studio-dist/client/assets/skills-DTks_uBx.js +1 -0
  305. package/studio-dist/client/assets/specs-DU1kqcp5.js +1 -0
  306. package/studio-dist/client/assets/specs-view-omrd_5P3.js +1 -0
  307. package/studio-dist/client/assets/steps-DhIFuAZy.js +1 -0
  308. package/studio-dist/client/assets/store-DJ5cncKA.js +1 -0
  309. package/studio-dist/client/assets/studio-BR9j15J0.js +100 -0
  310. package/studio-dist/client/assets/studio-queries-CFP_yTpr.js +2 -0
  311. package/studio-dist/client/assets/usage-CHmwtkoM.js +55 -0
  312. package/studio-dist/client/assets/useBaseQuery-BlC-AZ35.js +1 -0
  313. package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
  314. package/studio-dist/client/assets/vault-DRg8MScm.js +1 -0
  315. package/studio-dist/client/assets/warnings-UHFy6HAp.js +1 -0
  316. package/studio-dist/client/assets/workflow-Bv9vSfVV.js +1 -0
  317. package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-DAbZ6fzY.js +106 -0
  318. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +84 -39
  319. package/studio-dist/server/assets/{button-CIJqAhni.js → button-BfoNadNR.js} +14 -3750
  320. package/studio-dist/server/assets/combobox-oxUI6r4V.js +2089 -0
  321. package/studio-dist/server/assets/{companion-view-DISASvdJ.js → companion-view-DHUjPpA0.js} +3 -3
  322. package/studio-dist/server/assets/companions-kBrJZAd6.js +31 -0
  323. package/studio-dist/server/assets/{createServerRpc-tK2lE9R2.js → createServerRpc-bFKFpGFG.js} +1 -1
  324. package/studio-dist/server/assets/fields-BD_c65T1.js +1190 -0
  325. package/studio-dist/server/assets/getting-started-7P0oyWaM.js +67 -0
  326. package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
  327. package/studio-dist/server/assets/getting-started._topic-B1mV0kGz.js +13 -0
  328. package/studio-dist/server/assets/getting-started.index-CeGtvUsm.js +13 -0
  329. package/studio-dist/server/assets/graph-BWtmJOH2.js +16 -0
  330. package/studio-dist/server/assets/graph-DSDVEELZ.js +801 -0
  331. package/studio-dist/server/assets/graph-canvas-CID9Nksc.js +21066 -0
  332. package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
  333. package/studio-dist/server/assets/guides-BLJenHwQ.js +5 -0
  334. package/studio-dist/server/assets/guides-Bm3RbUB-.js +13 -0
  335. package/studio-dist/server/assets/guides.server-rHHqRuzV.js +66 -0
  336. package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
  337. package/studio-dist/server/assets/{markdown-view-Bn7xPdks.js → markdown-view-D3v9x-cM.js} +28 -9
  338. package/studio-dist/server/assets/{panel-3Jmn4awF.js → panel-yqOl5GMU.js} +5 -5
  339. package/studio-dist/server/assets/plugins._service._view-DwqJX7s9.js +92 -0
  340. package/studio-dist/server/assets/queries-DYmGrhNO.js +32 -0
  341. package/studio-dist/server/assets/react-BO0uMhpm.js +89 -0
  342. package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
  343. package/studio-dist/server/assets/{reports-D6YMqhnO.js → reports-7yaPz7aP.js} +15 -10
  344. package/studio-dist/server/assets/{reports-C06RXVE2.js → reports-C4Y_Jd-x.js} +3 -3
  345. package/studio-dist/server/assets/{router-C8MGqlAY.js → router-Dnoq5auE.js} +810 -1679
  346. package/studio-dist/server/assets/{routes-BcFgvqf7.js → routes-Cok4p3mK.js} +222 -76
  347. package/studio-dist/server/assets/{search-JAKurDNh.js → search-DUK7Jl6f.js} +21 -2
  348. package/studio-dist/server/assets/{shell-DS3wUexh.js → shell-DNVXedgE.js} +15 -6
  349. package/studio-dist/server/assets/{skills-BEnOxiDl.js → skills-D8qdXSku.js} +9 -8
  350. package/studio-dist/server/assets/{skills-CtrBAtX3.js → skills-pKmuAs0F.js} +3 -3
  351. package/studio-dist/server/assets/specs-DeHYUNFp.js +51 -0
  352. package/studio-dist/server/assets/specs-view-BGn-5Ik_.js +425 -0
  353. package/studio-dist/server/assets/{steps-Dq_CwY_s.js → steps-CV7Yk7L7.js} +88 -45
  354. package/studio-dist/server/assets/store-CWDGIp6x.js +280 -0
  355. package/studio-dist/server/assets/studio-CB94np48.js +10437 -0
  356. package/studio-dist/server/assets/studio-queries-BqZGBE70.js +1335 -0
  357. package/studio-dist/server/assets/usage-M6Gi6Km7.js +25584 -0
  358. package/studio-dist/server/assets/usage-j5jR9gX9.js +24 -0
  359. package/studio-dist/server/assets/useBaseQuery-Tv_QJt9r.js +2051 -0
  360. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-M2GBs8s3.js → useSelector-DUmCUXAs.js} +4 -668
  361. package/studio-dist/server/assets/{vault-Fvxt2Tzl.js → vault-PqVmssmW.js} +10 -7
  362. package/studio-dist/server/assets/{vault-BmWnryh3.js → vault-lBlvSyD4.js} +3 -3
  363. package/studio-dist/server/assets/{views-BgYa-za2.js → views-CsFp1i1G.js} +9 -6
  364. package/studio-dist/server/assets/{warnings-DzR6fyZh.js → warnings-BDs34j_m.js} +3 -2
  365. package/studio-dist/server/assets/{delivery-path-C29fBynY.js → workflow-T0eEldsa.js} +153 -120
  366. package/studio-dist/server/server.js +582 -8
  367. package/src/cli/commands/factory/factory.ts +0 -301
  368. package/src/cli/commands/report/collector.ts +0 -288
  369. package/src/cli/commands/studio/factory-credential.ts +0 -49
  370. package/src/cli/commands/studio/workset-session.ts +0 -131
  371. package/src/lib/delivery/archive-change.ts +0 -165
  372. package/src/lib/delivery/forge.ts +0 -279
  373. package/src/lib/delivery/token.ts +0 -24
  374. package/src/lib/factory/attach-client.ts +0 -113
  375. package/src/lib/factory/attach.ts +0 -178
  376. package/src/lib/factory/broker.ts +0 -190
  377. package/src/lib/factory/bun-commands.ts +0 -39
  378. package/src/lib/factory/client.ts +0 -92
  379. package/src/lib/factory/command.ts +0 -61
  380. package/src/lib/factory/credential-store.ts +0 -153
  381. package/src/lib/factory/frames.ts +0 -77
  382. package/src/lib/factory/ids.ts +0 -58
  383. package/src/lib/factory/outcomes/actions.ts +0 -114
  384. package/src/lib/factory/outcomes/index.ts +0 -391
  385. package/src/lib/factory/outcomes/lifecycle.ts +0 -205
  386. package/src/lib/factory/outcomes/runs.ts +0 -81
  387. package/src/lib/factory/prepare.ts +0 -49
  388. package/src/lib/factory/pty.ts +0 -103
  389. package/src/lib/factory/runner/companion-context.ts +0 -178
  390. package/src/lib/factory/runner/control.ts +0 -92
  391. package/src/lib/factory/runner/harness-agent.ts +0 -250
  392. package/src/lib/factory/runner/live.ts +0 -159
  393. package/src/lib/factory/runner/questions.ts +0 -22
  394. package/src/lib/factory/runner/rank.ts +0 -26
  395. package/src/lib/factory/runner/run-policy.ts +0 -12
  396. package/src/lib/factory/runner/run.ts +0 -199
  397. package/src/lib/factory/runner/scheduler.ts +0 -416
  398. package/src/lib/factory/runner/state.ts +0 -233
  399. package/src/lib/factory/runner/workflow.ts +0 -542
  400. package/src/lib/factory/runtime.ts +0 -981
  401. package/src/lib/factory/sandbox.ts +0 -292
  402. package/src/lib/factory/worktree-branch.ts +0 -17
  403. package/src/templates/capabilities/openspec-cap/mate-v1/templates/explore-brief.md +0 -25
  404. package/studio-dist/client/assets/app-CdPiFv59.css +0 -2
  405. package/studio-dist/client/assets/button-BIIHE0EQ.js +0 -3
  406. package/studio-dist/client/assets/companion-view-DM6YyXaR.js +0 -1
  407. package/studio-dist/client/assets/delivery-path-DELxj0Av.js +0 -1
  408. package/studio-dist/client/assets/factory-BZy0E8ty.js +0 -4
  409. package/studio-dist/client/assets/index-B3wkMzjA.js +0 -40
  410. package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +0 -1
  411. package/studio-dist/client/assets/panel-CbajlC3p.js +0 -1
  412. package/studio-dist/client/assets/prepaint-CwSrpdFA.js +0 -27
  413. package/studio-dist/client/assets/react-CN2GSx7x.js +0 -1
  414. package/studio-dist/client/assets/reports-DllhYQ5_.js +0 -1
  415. package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +0 -1
  416. package/studio-dist/client/assets/routes-COm-G3mK.js +0 -1
  417. package/studio-dist/client/assets/skills-DmWAy-jZ.js +0 -1
  418. package/studio-dist/client/assets/specs-BG3Wi3ln.js +0 -1
  419. package/studio-dist/client/assets/steps-DFsH3Neu.js +0 -1
  420. package/studio-dist/client/assets/vault-B2q1nBY5.js +0 -1
  421. package/studio-dist/client/assets/warnings-BSXIyuSQ.js +0 -1
  422. package/studio-dist/client/assets/workflow-DlsQD6Hc.js +0 -1
  423. package/studio-dist/server/assets/actions-Bvgj9eb8.js +0 -54
  424. package/studio-dist/server/assets/companions-BYbHWKOZ.js +0 -15
  425. package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +0 -459
  426. package/studio-dist/server/assets/factory-DGPmNGbo.js +0 -69
  427. package/studio-dist/server/assets/factory-DUTa0eDs.js +0 -2172
  428. package/studio-dist/server/assets/prepaint-DJfTQ_VH.js +0 -45
  429. package/studio-dist/server/assets/react-Ce6dj15C.js +0 -46
  430. package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +0 -34
  431. package/studio-dist/server/assets/specs-C8rv34-5.js +0 -211
  432. package/studio-dist/server/assets/studio-BeltxxKt.js +0 -216
  433. package/studio-dist/server/assets/workflow-liRYecHk.js +0 -73
  434. /package/src/lib/{factory/keyed-serial.ts → keyed-serial.ts} +0 -0
  435. /package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/spec.md +0 -0
@@ -0,0 +1,159 @@
1
+ // oxlint-disable no-await-in-loop -- one canonical spec at a time
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+
5
+ import { parse } from "yaml";
6
+
7
+ import { archiveDirOf, deltaSpecs } from "./change-layout";
8
+ import { isMateSchema } from "./delivery/stages";
9
+ import { FRONTMATTER_PATTERN } from "./frontmatter";
10
+ import { BOM, DELTA_COMMENT_PATTERN, parseScopes, type ScopePair } from "./openspec-scopes";
11
+
12
+ type ProjectionResult =
13
+ | { ok: true; repository: string; areas: string[] }
14
+ | { ok: false; reason: string };
15
+
16
+ /** The opening line of a `mate:delta` comment, closed or not. */
17
+ const DELTA_COMMENT_OPENER = /^<!--[ \t]*mate:delta/;
18
+
19
+ const DELTA_TAGS = new Set(["openspec/change", "openspec/delta"]);
20
+
21
+ /**
22
+ * A header an agent copied from a delta: it declares `type: delta-spec`, carries a
23
+ * `change` key, or a delta tag. A nested `scopes` key alone does not count, since
24
+ * legacy canonical specs carry one.
25
+ */
26
+ function isDeltaShapedFrontmatter(yamlSource: string): boolean {
27
+ try {
28
+ const parsed = parse(yamlSource) as unknown;
29
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
30
+ const header = parsed as Record<string, unknown>;
31
+ if (header.type === "delta-spec" || "change" in header) return true;
32
+ const tags = Array.isArray(header.tags) ? header.tags : [header.tags];
33
+ return tags.some((tag) => typeof tag === "string" && DELTA_TAGS.has(tag));
34
+ } catch {
35
+ return false;
36
+ }
37
+ }
38
+
39
+ function projectDeltaScopes(scopes: ScopePair[]): ProjectionResult {
40
+ if (scopes.length === 0) return { ok: false, reason: "delta declares no scopes entries" };
41
+ const repositories = [...new Set(scopes.map((entry) => entry.repository))];
42
+ if (repositories.length > 1) {
43
+ return {
44
+ ok: false,
45
+ reason: `delta names ${repositories.length} repositories (${repositories.join(", ")}); a spec names exactly one`,
46
+ };
47
+ }
48
+ return {
49
+ ok: true,
50
+ repository: repositories[0],
51
+ areas: [...new Set(scopes.map((entry) => entry.area))],
52
+ };
53
+ }
54
+
55
+ async function archivedChangeUsesMateSchema(
56
+ companionPath: string,
57
+ anchorName: string,
58
+ ): Promise<boolean> {
59
+ try {
60
+ const metadataPath = path.join(
61
+ companionPath,
62
+ "openspec",
63
+ "changes",
64
+ "archive",
65
+ anchorName,
66
+ ".openspec.yaml",
67
+ );
68
+ const parsed = parse(await fs.readFile(metadataPath, "utf8")) as unknown;
69
+ if (!parsed || typeof parsed !== "object") return false;
70
+ const schema = (parsed as Record<string, unknown>).schema;
71
+ return typeof schema === "string" && isMateSchema(schema.trim());
72
+ } catch {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ /**
78
+ * The block through its closing line. Scope keys are omitted when the delta had
79
+ * none — a partial block beats no frontmatter.
80
+ */
81
+ function renderCanonicalFrontmatter(
82
+ capability: string,
83
+ scope: { repository: string; areas: string[] } | null,
84
+ ): string {
85
+ return [
86
+ "---",
87
+ "type: spec",
88
+ `capability: ${capability}`,
89
+ ...(scope ? [`repository: ${scope.repository}`, `areas: [${scope.areas.join(", ")}]`] : []),
90
+ "tags: [openspec/spec]",
91
+ "---",
92
+ "",
93
+ ].join("\n");
94
+ }
95
+
96
+ /**
97
+ * Repairs `openspec archive` output: prepends canonical frontmatter to main specs the
98
+ * archive run created bare, and replaces a delta-shaped header or `mate:delta` comment an
99
+ * agent copied onto one.
100
+ * Publish does not archive, so this runs the first time publish resolves that archive,
101
+ * however the archive was made.
102
+ *
103
+ * `openspec archive` rebuilds a brand-new main spec from a skeleton with no frontmatter slot,
104
+ * so scope metadata dies exactly once, at spec birth; existing specs keep theirs because only
105
+ * requirement blocks are spliced. Idempotent, and best-effort by design — the archive is
106
+ * durable input, so a failure here warns rather than refusing the publication.
107
+ */
108
+ export async function reconcileMainSpecFrontmatter(
109
+ companionPath: string,
110
+ anchorName: string,
111
+ ): Promise<string[]> {
112
+ if (!(await archivedChangeUsesMateSchema(companionPath, anchorName))) return [];
113
+
114
+ const archiveDir = path.join(archiveDirOf(companionPath), anchorName);
115
+ const reconciled: string[] = [];
116
+
117
+ for (const { file, canonical: canonicalRelative, capability } of await deltaSpecs(archiveDir)) {
118
+ if (capability === null) continue;
119
+ const canonicalPath = path.join(companionPath, canonicalRelative);
120
+
121
+ try {
122
+ const canonical = (await fs.readFile(canonicalPath, "utf8")).replace(BOM, "");
123
+ /** The body that follows the written block: the whole file, or what trails a delta-shaped header. */
124
+ let body = `\n${canonical}`;
125
+ if (DELTA_COMMENT_OPENER.test(canonical)) {
126
+ const header = DELTA_COMMENT_PATTERN.exec(canonical);
127
+ if (!header) continue;
128
+ body = canonical.slice(header[0].length);
129
+ } else if (canonical.startsWith("---")) {
130
+ const header = FRONTMATTER_PATTERN.exec(canonical);
131
+ if (!header || !isDeltaShapedFrontmatter(header[1])) continue;
132
+ body = canonical.slice(header[0].length);
133
+ }
134
+
135
+ const deltaSource = await fs.readFile(path.join(archiveDir, "specs", file), "utf8");
136
+ const scopes = parseScopes(deltaSource);
137
+ const projected = projectDeltaScopes(scopes);
138
+
139
+ /** Multi-repository is invalid input, so skip; absent scopes still earn a partial block. */
140
+ if (!projected.ok && scopes.length > 0) {
141
+ process.stderr.write(
142
+ `mate: skipped frontmatter for ${canonicalRelative}: ${projected.reason}\n`,
143
+ );
144
+ continue;
145
+ }
146
+ const head = renderCanonicalFrontmatter(
147
+ capability,
148
+ projected.ok ? { repository: projected.repository, areas: projected.areas } : null,
149
+ );
150
+ await fs.writeFile(canonicalPath, head + body, "utf8");
151
+ reconciled.push(canonicalRelative);
152
+ } catch (error) {
153
+ process.stderr.write(
154
+ `mate: could not reconcile frontmatter for ${canonicalRelative}: ${String(error)}\n`,
155
+ );
156
+ }
157
+ }
158
+ return reconciled;
159
+ }
@@ -1,4 +1,4 @@
1
- import { spawn } from "node:child_process";
1
+ import { type ChildProcess, spawn } from "node:child_process";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
4
 
@@ -193,30 +193,17 @@ export abstract class LaunchAdapter<C extends AdapterContext = AdapterContext> {
193
193
  const launch = await this.prepareLaunch(context, args);
194
194
 
195
195
  return new Promise((resolve, reject) => {
196
- const child = spawn(launch.command, launch.args, {
197
- cwd: context.launchWorkingDirectory,
198
- env: launch.env,
199
- stdio: this.interactive ? "inherit" : "pipe",
200
- });
201
-
202
- let stdout = "";
203
- let stderr = "";
204
-
205
- if (!this.interactive) {
206
- child.stdout?.on("data", (chunk) => {
207
- stdout += chunk.toString();
208
- });
209
- child.stderr?.on("data", (chunk) => {
210
- stderr += chunk.toString();
211
- });
212
- }
213
-
196
+ /**
197
+ * Installed before the spawn: the agent runs before `spawn` returns, and a signal in that gap
198
+ * would end the launch with the agent left running.
199
+ */
200
+ let child: ChildProcess | undefined;
214
201
  const forward = this.forwardsSignals();
215
202
  const handlers = new Map<NodeJS.Signals, () => void>();
216
203
  for (const signal of FORWARDED_SIGNALS) {
217
204
  const handler = () => {
218
205
  /** Installing a handler at all is what keeps the launch alive to wait for the agent. */
219
- if (forward && child.exitCode === null && child.signalCode === null) {
206
+ if (forward && child && child.exitCode === null && child.signalCode === null) {
220
207
  child.kill(signal);
221
208
  }
222
209
  };
@@ -228,6 +215,30 @@ export abstract class LaunchAdapter<C extends AdapterContext = AdapterContext> {
228
215
  handlers.clear();
229
216
  };
230
217
 
218
+ try {
219
+ child = spawn(launch.command, launch.args, {
220
+ cwd: context.launchWorkingDirectory,
221
+ env: launch.env,
222
+ stdio: this.interactive ? "inherit" : "pipe",
223
+ });
224
+ } catch (error) {
225
+ removeHandlers();
226
+ reject(error);
227
+ return;
228
+ }
229
+
230
+ let stdout = "";
231
+ let stderr = "";
232
+
233
+ if (!this.interactive) {
234
+ child.stdout?.on("data", (chunk) => {
235
+ stdout += chunk.toString();
236
+ });
237
+ child.stderr?.on("data", (chunk) => {
238
+ stderr += chunk.toString();
239
+ });
240
+ }
241
+
231
242
  child.on("error", (error) => {
232
243
  removeHandlers();
233
244
  reject(error);
@@ -1,7 +1,9 @@
1
1
  import crypto from "node:crypto";
2
2
  import { existsSync } from "node:fs";
3
3
  import fs from "node:fs/promises";
4
+ import os from "node:os";
4
5
  import path from "node:path";
6
+ import { which } from "bun";
5
7
 
6
8
  import { FRAMEWORK_NAME } from "../../../framework";
7
9
  import { buildCompanionGuidance } from "../../../playbooks/companion-guidance";
@@ -15,6 +17,7 @@ import { MATE_ENV } from "../../../runtime/env-names";
15
17
  import { SESSION_ORIGIN_ENV } from "../../../runtime/session-registry";
16
18
  import { resolveSecretPolicy } from "../../../runtime/policy";
17
19
  import { managedSessionKind } from "../../../runtime/session-kind";
20
+ import { umbrellaChildrenBlock } from "../../../runtime/umbrella-children";
18
21
  import { NOT_WRAPPED } from "../../../runtime/wrap-state";
19
22
  import { writeAtomic } from "../../../runtime/write-atomic";
20
23
  import {
@@ -272,7 +275,12 @@ export class ClaudeAdapter extends LaunchAdapter<ClaudeLaunchContext> {
272
275
 
273
276
  async prepareLaunch(context: ClaudeLaunchContext, args: string[]): Promise<PreparedLaunch> {
274
277
  const launch = await super.prepareLaunch(context, args);
275
- return isBackgroundLaunch(args) ? backgroundLaunch(context, launch) : launch;
278
+ const prepared = isBackgroundLaunch(args) ? await backgroundLaunch(context, launch) : launch;
279
+ if (process.platform === "win32" && !which("claude", { PATH: prepared.env.PATH ?? "" })) {
280
+ const nativeClaude = path.join(os.homedir(), ".local", "bin", "claude.exe");
281
+ if (existsSync(nativeClaude)) return { ...prepared, command: nativeClaude };
282
+ }
283
+ return prepared;
276
284
  }
277
285
 
278
286
  /** A failed Claude wrap pass names the entry that failed. */
@@ -302,7 +310,8 @@ export class ClaudeAdapter extends LaunchAdapter<ClaudeLaunchContext> {
302
310
  /**
303
311
  * Plan in, flags out; decides nothing. `--append-system-prompt` is
304
312
  * unconditional: no settings document can carry it. It holds the Agent
305
- * Guidance alone; the Companion Instructions come from the wrap's session hook.
313
+ * Guidance and, in an Umbrella Repository, the children block read from the
314
+ * folder at each call; the Companion Instructions come from the wrap's session hook.
306
315
  * `--plugin-dir` passes the folders `launchPluginFolders` names, from the
307
316
  * running install's bundled plugin.
308
317
  */
@@ -326,8 +335,12 @@ export class ClaudeAdapter extends LaunchAdapter<ClaudeLaunchContext> {
326
335
  ...context,
327
336
  secretGuardrails: resolveSecretPolicy(context.companionPath).guardrails,
328
337
  });
338
+ const children = context.repository ? umbrellaChildrenBlock(context.repository.path) : "";
329
339
  const { args: passthrough, prompts, boundary } = liftAppendedPrompts(args);
330
- const promptArgs = [APPEND_PROMPT_FLAG, [guidance, ...prompts].filter(Boolean).join("\n\n")];
340
+ const promptArgs = [
341
+ APPEND_PROMPT_FLAG,
342
+ [guidance, children, ...prompts].filter(Boolean).join("\n\n"),
343
+ ];
331
344
  const launchArgs = [...settingsArgs, ...mcpConfigArgs, ...pluginDirArgs];
332
345
 
333
346
  if (boundary === undefined) {
@@ -14,6 +14,7 @@ import { resolveSecretPolicy } from "../../../runtime/policy";
14
14
  import { ensureOpenCodeServer } from "../../opencode-server";
15
15
  import { validateOpenCodePluginAssets } from "../../package-paths";
16
16
  import { readOpenCodeConfig } from "../../../tools/setup/providers/opencode-format";
17
+ import { declaredGuidance } from "../../../runtime/companion-guidance";
17
18
  import { buildOpenCodeGuidance } from "../opencode-guidance";
18
19
  import type { PrepareResult } from "../session-prepare";
19
20
  import { LaunchPreflightError } from "../types";
@@ -171,6 +172,7 @@ export class OpenCodeAdapter extends LaunchAdapter {
171
172
  return buildOpenCodeGuidance(context.capabilities, {
172
173
  companionScoped: !context.repository,
173
174
  secretGuardrails: resolveSecretPolicy(context.companionPath).guardrails,
175
+ ...declaredGuidance(context.companionPath),
174
176
  });
175
177
  }
176
178
 
@@ -12,8 +12,19 @@ import {
12
12
  type UpstreamTarget,
13
13
  } from "../../runtime/companion-git";
14
14
  import { recordCompanionSync } from "../../runtime/companion-git-state";
15
+ import { errorMessage } from "../../runtime/error-message";
15
16
  import { withCompanionLock, type CompanionLockOptions } from "../../runtime/companion-lock";
17
+ import { inboxRefspec, trackingRefs } from "../../runtime/pending-records";
18
+ import {
19
+ discardSubmittedArrivals,
20
+ editedAfterSubmitWarning,
21
+ planSubmittedArrivals,
22
+ type SubmittedArrivals,
23
+ type SubmittedLayout,
24
+ } from "../../runtime/submitted-arrivals";
16
25
  import { FRAMEWORK_NAME } from "../../framework";
26
+ import { artifactTypes, defaultArtifactType } from "../delivery/staging/registry";
27
+ import { loadWorkflow } from "../workflow/declaration";
17
28
  import { LaunchPreflightError } from "./types";
18
29
 
19
30
  type GitCommandResult = GitResult;
@@ -23,12 +34,45 @@ export { describeGitFailure };
23
34
  export interface CompanionGitSyncOptions {
24
35
  /** Environment Git runs with. */
25
36
  env?: Record<string, string | undefined>;
37
+ /** Home of Mate's local companion state; `HOME` by default. */
38
+ stateHome?: string;
26
39
  }
27
40
 
28
41
  export interface CompanionGitSyncResult {
29
42
  skipped: boolean;
30
43
  changed: boolean;
31
44
  companionPath: string;
45
+ /** Submitted change folders discarded because their upstream copy or archive arrived. */
46
+ discarded?: string[];
47
+ /** Operator warnings, such as a submitted folder edited after submit. */
48
+ warnings?: string[];
49
+ }
50
+
51
+ /**
52
+ * The folders of the companion's artifact types, as the arrival check reads them: the built-in
53
+ * type's, then those its workflow declares. An invalid declaration leaves the built-in type.
54
+ */
55
+ async function submittedLayouts(companionPath: string): Promise<SubmittedLayout[]> {
56
+ const verdict = await loadWorkflow(companionPath).catch(() => null);
57
+ const types = verdict?.ok ? artifactTypes(undefined, verdict.workflow) : [defaultArtifactType()];
58
+ return types.map((type) => ({
59
+ source: type.source,
60
+ ...(type.archiveRoot === undefined
61
+ ? { trailer: type.name }
62
+ : { archiveRoot: type.archiveRoot }),
63
+ recordName: (id) => (type.isRecordId(id) ? type.recordName(id) : null),
64
+ }));
65
+ }
66
+
67
+ /** The arrivals of every layout as one plan; a folder belongs to one layout. */
68
+ function mergeArrivals(plans: readonly SubmittedArrivals[]): SubmittedArrivals {
69
+ return {
70
+ discard: plans.flatMap((plan) => plan.discard),
71
+ discardFiles: Object.assign({}, ...plans.map((plan) => plan.discardFiles)),
72
+ committed: Object.assign({}, ...plans.map((plan) => plan.committed)),
73
+ edited: plans.flatMap((plan) => plan.edited),
74
+ forget: plans.flatMap((plan) => plan.forget),
75
+ };
32
76
  }
33
77
 
34
78
  export class CompanionGitSyncError extends LaunchPreflightError {
@@ -95,17 +139,7 @@ export class CompanionGitSync {
95
139
  }
96
140
 
97
141
  await this.assertNoUnfinishedOperation(companionPath);
98
- const [target, before] = await Promise.all([
99
- this.resolveSyncTarget(companionPath),
100
- this.command(companionPath, ["status", "--porcelain=v1", "--untracked-files=all"]),
101
- ]);
102
- if (before.status !== 0) {
103
- throw this.failure(
104
- companionPath,
105
- `Unable to inspect the working tree: ${this.detail(before)}`,
106
- );
107
- }
108
- const dirty = outputLines(before.stdout).length > 0;
142
+ const target = await this.resolveSyncTarget(companionPath);
109
143
 
110
144
  const fetch = await this.fetch(companionPath, target, interactiveGit);
111
145
  if (fetch.status !== 0) {
@@ -130,6 +164,62 @@ export class CompanionGitSync {
130
164
  );
131
165
  }
132
166
 
167
+ const localGit = companionGit(companionPath, { prompt: "never", env: this.options.env });
168
+ // Read-only plans, one per type: read together.
169
+ const plans = await Promise.all(
170
+ (await submittedLayouts(companionPath)).map((layout) =>
171
+ planSubmittedArrivals(localGit, companionPath, target.ref, layout, this.options.stateHome),
172
+ ),
173
+ );
174
+ const arrivals = mergeArrivals(plans);
175
+ const discarded = await discardSubmittedArrivals(
176
+ localGit,
177
+ companionPath,
178
+ arrivals,
179
+ this.options.stateHome,
180
+ );
181
+ const warnings = arrivals.edited.map(editedAfterSubmitWarning);
182
+
183
+ const before = await this.command(companionPath, [
184
+ "status",
185
+ "--porcelain=v1",
186
+ "--untracked-files=all",
187
+ ]);
188
+ if (before.status !== 0) {
189
+ const lost = await restoreFailure(discarded);
190
+ const failure = this.failure(
191
+ companionPath,
192
+ `Unable to inspect the working tree: ${this.detail(before)}`,
193
+ );
194
+ throw withRestoreNote(companionPath, failure, lost);
195
+ }
196
+ const dirty = outputLines(before.stdout).length > 0;
197
+
198
+ let result: CompanionGitSyncResult;
199
+ try {
200
+ result = await this.mergeUpstream(
201
+ companionPath,
202
+ target,
203
+ dirty,
204
+ discarded.discarded,
205
+ warnings,
206
+ );
207
+ } catch (error) {
208
+ // A file the merge brought stays; only paths still missing get their submitted copy back.
209
+ const lost = await restoreFailure(discarded);
210
+ throw withRestoreNote(companionPath, error, lost);
211
+ }
212
+ await discarded.commit();
213
+ return result;
214
+ }
215
+
216
+ private async mergeUpstream(
217
+ companionPath: string,
218
+ target: SyncTarget,
219
+ dirty: boolean,
220
+ discarded: string[],
221
+ warnings: string[],
222
+ ): Promise<CompanionGitSyncResult> {
133
223
  let stashRef: string | undefined;
134
224
  if (dirty) {
135
225
  const stash = await this.command(companionPath, [
@@ -176,19 +266,34 @@ export class CompanionGitSync {
176
266
  skipped: false,
177
267
  changed: headBefore.stdout.trim() !== headAfter.stdout.trim(),
178
268
  companionPath,
269
+ ...(discarded.length > 0 ? { discarded } : {}),
270
+ ...(warnings.length > 0 ? { warnings } : {}),
179
271
  };
180
272
  }
181
273
 
182
- /** Only this fetch may prompt, and only when the caller is interactive. */
183
- private fetch(
274
+ /**
275
+ * Only this fetch may prompt, and only when the caller is interactive. The inbox rides along
276
+ * for the pending count.
277
+ */
278
+ private async fetch(
184
279
  companionPath: string,
185
280
  target: SyncTarget,
186
281
  interactiveGit: boolean,
187
282
  ): Promise<GitCommandResult> {
188
- return companionGit(companionPath, {
283
+ const git = companionGit(companionPath, {
189
284
  prompt: interactiveGit ? "if-terminal" : "never",
190
285
  env: this.options.env,
191
- }).fetch([target.remote, target.branch]);
286
+ });
287
+ const fetched = await git.fetch([target.remote, target.branch, inboxRefspec(target.remote)]);
288
+ if (fetched.status !== 0) return fetched;
289
+ // Publication lands on the default branch; a checkout tracking another branch fetches it too.
290
+ const prefix = `refs/remotes/${target.remote}/`;
291
+ const defaultRef = (await trackingRefs(companionPath))?.defaultRef;
292
+ if (defaultRef?.startsWith(prefix) && defaultRef !== `${prefix}${target.branch}`) {
293
+ const branch = defaultRef.slice(prefix.length);
294
+ await git.fetch([target.remote, `+refs/heads/${branch}:${defaultRef}`]);
295
+ }
296
+ return fetched;
192
297
  }
193
298
 
194
299
  private async mergeAndRestore(
@@ -260,10 +365,18 @@ export class CompanionGitSync {
260
365
  }
261
366
 
262
367
  // Keep the stash if dropping it fails; it remains a recoverable backup.
263
- await this.command(companionPath, ["stash", "drop", stashRef]);
368
+ await this.dropStash(companionPath, stashRef);
264
369
  }
265
370
  }
266
371
 
372
+ /** Drops the stash entry holding commit `stashRef`: `git stash drop` takes no commit id. */
373
+ private async dropStash(companionPath: string, stashRef: string): Promise<void> {
374
+ const listed = await this.command(companionPath, ["stash", "list", "--format=%H"]);
375
+ if (listed.status !== 0) return;
376
+ const index = outputLines(listed.stdout).indexOf(stashRef);
377
+ if (index >= 0) await this.command(companionPath, ["stash", "drop", "-q", `stash@{${index}}`]);
378
+ }
379
+
267
380
  private async assertSafeCompanionRoot(
268
381
  companionPath: string,
269
382
  workingRepoPath?: string,
@@ -429,6 +542,29 @@ export class CompanionGitSync {
429
542
  }
430
543
  }
431
544
 
545
+ /** Puts discarded submitted files back; a failure, naming where they are kept, is returned. */
546
+ async function restoreFailure(discarded: { restore: () => Promise<void> }): Promise<string | null> {
547
+ return discarded.restore().then(
548
+ () => null,
549
+ (error: unknown) => `Putting back discarded submitted folders failed: ${errorMessage(error)}.`,
550
+ );
551
+ }
552
+
553
+ /** `error`, its reason extended by `note` when restoring failed too. */
554
+ function withRestoreNote(companionPath: string, error: unknown, note: string | null): unknown {
555
+ if (!note) return error;
556
+ if (error instanceof CompanionGitSyncError) {
557
+ return new CompanionGitSyncError(
558
+ companionPath,
559
+ `${error.reason} ${note}`,
560
+ error.conflictingPaths,
561
+ error.recovery,
562
+ error.stashRef,
563
+ );
564
+ }
565
+ return new CompanionGitSyncError(companionPath, `${errorMessage(error)} ${note}`);
566
+ }
567
+
432
568
  /**
433
569
  * An attended operation waits for whoever holds the companion lock, however
434
570
  * long: the holder may be an operator answering a merge conflict. The line
@@ -14,6 +14,7 @@ import {
14
14
  type PluginInstallResult,
15
15
  } from "../../tools/setup/dynamic-plugins/install";
16
16
  import { hydrateDynamicPlugins } from "../../tools/setup/dynamic-plugins/hydrate";
17
+ import { dynamicPluginsWorkspaceRoot } from "../../tools/setup/dynamic-plugins/paths";
17
18
  import { applySetupCompatibilities } from "../../tools/setup";
18
19
  import { findRepoLocalRegistryFile } from "./repository-link";
19
20
  import { companionGit, describeGitFailure, type CompanionGit } from "../../runtime/companion-git";
@@ -350,7 +351,11 @@ export async function updateHubPlugins(
350
351
  const resolvedHubPath = path.resolve(hubPath);
351
352
  const results =
352
353
  declarations.length > 0
353
- ? await installDeclaredPlugins(resolvedHubPath, declarations, deps.installDeps)
354
+ ? await installDeclaredPlugins(
355
+ dynamicPluginsWorkspaceRoot(resolvedHubPath),
356
+ declarations,
357
+ deps.installDeps,
358
+ )
354
359
  : [];
355
360
  if (declarations.length > 0) {
356
361
  await (deps.hydrate ?? hydrateDynamicPlugins)({ companionPath: resolvedHubPath });
@@ -0,0 +1,48 @@
1
+ import path from "node:path";
2
+
3
+ import semver from "semver";
4
+
5
+ import { FRAMEWORK_NAME } from "../../framework";
6
+ import { YamlFileStore } from "./yaml-file-store";
7
+
8
+ /**
9
+ * Raw view of `framework.yaml`: `ConfigStore.load()` merges defaults, so saving
10
+ * its result would add keys the companion never declared.
11
+ */
12
+ class RawFrameworkConfigStore extends YamlFileStore<Record<string, unknown>> {
13
+ protected onMissing(): Promise<Record<string, unknown>> {
14
+ return Promise.resolve({});
15
+ }
16
+ }
17
+
18
+ function rawStore(companionPath: string): RawFrameworkConfigStore {
19
+ return new RawFrameworkConfigStore(
20
+ path.join(companionPath, `.${FRAMEWORK_NAME}`, "config", "framework.yaml"),
21
+ );
22
+ }
23
+
24
+ /** Sets `engines.mate` to `range`. Returns true when the file was rewritten. */
25
+ export async function writeEngineFloor(companionPath: string, range: string): Promise<boolean> {
26
+ const store = rawStore(companionPath);
27
+ const raw = (await store.load()) ?? {};
28
+ const engines = (raw.engines ?? {}) as Record<string, string>;
29
+ if (engines[FRAMEWORK_NAME] === range) return false;
30
+ await store.save({ ...raw, engines: { ...engines, [FRAMEWORK_NAME]: range } });
31
+ return true;
32
+ }
33
+
34
+ /**
35
+ * Raises `engines.mate` to `>=version` when it is absent or admits a lower
36
+ * version; a floor already at or above it, or a range that does not parse,
37
+ * is left alone. Returns true when the file was rewritten.
38
+ */
39
+ export async function raiseEngineFloor(companionPath: string, version: string): Promise<boolean> {
40
+ const raw = (await rawStore(companionPath).load()) ?? {};
41
+ const current = ((raw.engines ?? {}) as Record<string, unknown>)[FRAMEWORK_NAME];
42
+ if (typeof current === "string") {
43
+ if (semver.validRange(current) === null) return false;
44
+ const lowest = semver.minVersion(current);
45
+ if (lowest && semver.gte(lowest, version)) return false;
46
+ }
47
+ return writeEngineFloor(companionPath, `>=${version}`);
48
+ }
@@ -74,6 +74,14 @@ function makeContext(
74
74
  };
75
75
  }
76
76
 
77
+ /** The context of a companion already resolved, e.g. by a launch, with its Working Repository. */
78
+ export function companionContext(
79
+ companionPath: string,
80
+ repository?: LinkedRepository,
81
+ ): FrameworkContext {
82
+ return makeContext(companionPath, "working-repo", repository);
83
+ }
84
+
77
85
  function isStrictChildPath(parentPath: string, candidatePath: string): boolean {
78
86
  const relative = path.relative(parentPath, candidatePath);
79
87
  return relative !== "" && !relative.startsWith(".." + path.sep) && !path.isAbsolute(relative);
@@ -159,9 +167,11 @@ async function withResolvedHub(context: FrameworkContext): Promise<FrameworkCont
159
167
  // 1. MATE_ARTIFACT_PATH env var (agent-launched sessions)
160
168
  // 2. CompanionResolver — cwd inside a linked working repo
161
169
  // 3. Local .mate/config/framework.yaml in cwd (cwd is the companion itself)
170
+ // `write: false` skips the resolver's self-heal and stale-pointer prune, for read-only callers.
162
171
  export async function resolveFrameworkContext(
163
172
  cwd: string,
164
173
  globalConfigStore = new GlobalConfigStore(),
174
+ options: { write?: boolean } = {},
165
175
  ): Promise<FrameworkContext> {
166
176
  const envCompanionPath = process.env.MATE_ARTIFACT_PATH;
167
177
  if (envCompanionPath) {
@@ -171,7 +181,11 @@ export async function resolveFrameworkContext(
171
181
  );
172
182
  }
173
183
 
174
- const match = await new CompanionResolver(globalConfigStore).resolve(cwd);
184
+ const write = options.write !== false;
185
+ const { match } = await new CompanionResolver(globalConfigStore).resolveWithDiagnostics(cwd, {
186
+ logFailures: write,
187
+ write,
188
+ });
175
189
  if (match) {
176
190
  return withResolvedHub(
177
191
  makeContext(