@uniqbit/mate-core 0.20.0 → 0.21.1

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 (287) 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 +10 -1
  4. package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
  5. package/opencode-plugin/src/server.ts +9 -2
  6. package/package.json +2 -1
  7. package/src/cli/commands/artifact/delivery/environment.ts +28 -8
  8. package/src/cli/commands/artifact/delivery/link.ts +28 -9
  9. package/src/cli/commands/artifact/delivery/output.ts +7 -0
  10. package/src/cli/commands/companion/update.ts +2 -19
  11. package/src/cli/commands/factory/factory.ts +11 -1
  12. package/src/cli/commands/install.ts +47 -36
  13. package/src/cli/commands/launch/claude.ts +2 -0
  14. package/src/cli/commands/launch/shared.ts +33 -6
  15. package/src/cli/commands/plugin/install.ts +27 -11
  16. package/src/cli/commands/report/index.ts +180 -184
  17. package/src/cli/commands/report/markdown.ts +67 -72
  18. package/src/cli/commands/shared/companion-selection.ts +3 -1
  19. package/src/cli/commands/studio/access.ts +6 -14
  20. package/src/cli/commands/studio/areas.ts +112 -33
  21. package/src/cli/commands/studio/companion-add.ts +87 -0
  22. package/src/cli/commands/studio/companion-removal.ts +15 -8
  23. package/src/cli/commands/studio/factory-credential.ts +1 -15
  24. package/src/cli/commands/studio/factory-git-tokens.ts +40 -0
  25. package/src/cli/commands/studio/factory-relay.ts +18 -0
  26. package/src/cli/commands/studio/graph-model.ts +61 -0
  27. package/src/cli/commands/studio/graph.ts +336 -0
  28. package/src/cli/commands/studio/index.ts +4 -4
  29. package/src/cli/commands/studio/payload.ts +42 -15
  30. package/src/cli/commands/studio/repository-add.ts +116 -0
  31. package/src/cli/commands/studio/routes.ts +6 -0
  32. package/src/cli/commands/studio/selection.ts +12 -3
  33. package/src/cli/commands/studio/server.ts +127 -5
  34. package/src/cli/commands/studio/services.ts +40 -0
  35. package/src/cli/commands/studio/terminal.ts +45 -3
  36. package/src/cli/commands/studio/views/vault/markdown-tree.ts +84 -3
  37. package/src/cli/commands/studio/workset-session.ts +47 -14
  38. package/src/cli/commands/unwrap.ts +3 -0
  39. package/src/cli/commands/update.ts +2 -0
  40. package/src/cli/commands/vscode/release-vsix.json +4 -0
  41. package/src/cli/commands/vscode/setup.ts +71 -13
  42. package/src/cli/commands/vscode/vsix.ts +48 -7
  43. package/src/cli/commands/working/cleanup.ts +40 -8
  44. package/src/cli/commands/working/worktree.ts +176 -35
  45. package/src/cli/main.ts +17 -2
  46. package/src/cli/usage.ts +1 -1
  47. package/src/hooks/rtk-worktree-git.ts +48 -0
  48. package/src/hooks/validate-artifact-path.ts +38 -7
  49. package/src/lib/delivery/branch-template.ts +122 -0
  50. package/src/lib/delivery/branches.ts +21 -16
  51. package/src/lib/delivery/checkout.ts +102 -0
  52. package/src/lib/delivery/environment.ts +2 -0
  53. package/src/lib/delivery/merge-git.ts +13 -1
  54. package/src/lib/delivery/record-delivery.ts +83 -29
  55. package/src/lib/delivery/record.ts +15 -3
  56. package/src/lib/delivery/resolve-branch.ts +157 -110
  57. package/src/lib/factory/attach-client.ts +11 -1
  58. package/src/lib/factory/broker.ts +37 -40
  59. package/src/lib/factory/client.ts +22 -1
  60. package/src/lib/factory/clone-url.ts +39 -0
  61. package/src/lib/factory/command.ts +21 -5
  62. package/src/lib/factory/git-auth.ts +61 -0
  63. package/src/lib/factory/git-credential-store.ts +181 -0
  64. package/src/lib/factory/ids.ts +12 -2
  65. package/src/lib/factory/outcomes/actions.ts +20 -4
  66. package/src/lib/factory/outcomes/index.ts +77 -11
  67. package/src/lib/factory/outcomes/lifecycle.ts +9 -2
  68. package/src/lib/factory/outcomes/sessions.ts +23 -1
  69. package/src/lib/factory/prepare.ts +9 -3
  70. package/src/lib/factory/runner/scheduler.ts +96 -14
  71. package/src/lib/factory/runner/workflow.ts +5 -1
  72. package/src/lib/factory/runtime.ts +143 -43
  73. package/src/lib/orchestrator/companion-hub.ts +6 -1
  74. package/src/lib/orchestrator/engine-floor.ts +48 -0
  75. package/src/lib/orchestrator/launcher.ts +34 -1
  76. package/src/lib/orchestrator/projection-claude-commands.ts +2 -2
  77. package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
  78. package/src/lib/orchestrator/projection-claude-links.ts +32 -8
  79. package/src/lib/orchestrator/projection-claude-skills.ts +2 -2
  80. package/src/lib/orchestrator/projection-entries.ts +22 -18
  81. package/src/lib/orchestrator/projection-opencode-copies.ts +65 -21
  82. package/src/lib/orchestrator/projection-runtime-documents.ts +66 -43
  83. package/src/lib/orchestrator/projection-types.ts +28 -1
  84. package/src/lib/orchestrator/refresh-working-claude-links.ts +3 -1
  85. package/src/lib/orchestrator/session-prepare.ts +6 -1
  86. package/src/lib/orchestrator/setup-compatibilities.ts +1 -1
  87. package/src/lib/orchestrator/types.ts +4 -0
  88. package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
  89. package/src/lib/orchestrator/working-repo-projection.ts +24 -4
  90. package/src/lib/orchestrator/wrap-pass.ts +1 -0
  91. package/src/lib/public-npm.ts +95 -50
  92. package/src/lib/session-state.ts +72 -2
  93. package/src/lib/update-checker.ts +7 -1
  94. package/src/lib/usage/aggregate.ts +202 -0
  95. package/src/lib/usage/cache.ts +87 -0
  96. package/src/lib/usage/claude-pricing.ts +71 -0
  97. package/src/lib/usage/claude.ts +189 -0
  98. package/src/lib/usage/collect.ts +56 -0
  99. package/src/lib/usage/opencode.ts +188 -0
  100. package/src/lib/usage/records.ts +80 -0
  101. package/src/lib/usage/rtk-database.ts +72 -0
  102. package/src/lib/usage/savings.ts +209 -0
  103. package/src/lib/usage/scope.ts +182 -0
  104. package/src/lib/usage/source.ts +102 -0
  105. package/src/lib/usage/types.ts +143 -0
  106. package/src/lib/usage/window.ts +37 -0
  107. package/src/lib/workset/factory-local.ts +157 -0
  108. package/src/lib/workset/record.ts +25 -11
  109. package/src/lib/workset/repositories.ts +118 -25
  110. package/src/lib/workset/worktree-include.ts +161 -0
  111. package/src/lib/workset/worktree-index.ts +6 -2
  112. package/src/lib/workset/worktree.ts +591 -101
  113. package/src/opencode/companion-hooks.ts +46 -8
  114. package/src/opencode/companion-policy.ts +18 -5
  115. package/src/opencode/enter-worktree.ts +254 -6
  116. package/src/opencode/session-register.ts +2 -2
  117. package/src/runtime/claude-bg-isolation.ts +138 -0
  118. package/src/runtime/companion-git.ts +10 -2
  119. package/src/runtime/companion-guidance.ts +17 -4
  120. package/src/runtime/current-branch.ts +16 -2
  121. package/src/runtime/entered-worktree.ts +24 -0
  122. package/src/runtime/git-tracked.ts +60 -0
  123. package/src/runtime/repo-destination.ts +72 -0
  124. package/src/runtime/repo-local.ts +25 -3
  125. package/src/runtime/rtk-git-guard.ts +66 -0
  126. package/src/runtime/runtime-document-manifest.ts +229 -19
  127. package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
  128. package/src/runtime/secret-guard.ts +9 -2
  129. package/src/runtime/secret-policy-weakening.ts +122 -0
  130. package/src/runtime/serving-claude-wrap.ts +15 -2
  131. package/src/runtime/umbrella-folder.ts +56 -0
  132. package/src/runtime/wrap-state.ts +5 -13
  133. package/src/studio.ts +37 -0
  134. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +61 -6
  135. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +8 -4
  136. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +9 -5
  137. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +5 -4
  138. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +10 -4
  139. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +5 -1
  140. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +61 -6
  141. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +8 -4
  142. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +9 -5
  143. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +5 -4
  144. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +10 -4
  145. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +5 -1
  146. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +307 -42
  147. package/src/tools/setup/capabilities/rtk.ts +93 -1
  148. package/src/tools/setup/dynamic-plugins/audiences.ts +65 -21
  149. package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
  150. package/src/tools/setup/dynamic-plugins/hydrate.ts +4 -4
  151. package/src/tools/setup/dynamic-plugins/install.ts +24 -22
  152. package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
  153. package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
  154. package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
  155. package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
  156. package/src/tools/setup/mate.ts +3 -3
  157. package/src/tools/setup/plugins/gitignore.ts +15 -9
  158. package/src/tools/setup/providers/claude-plugin-hooks.ts +12 -0
  159. package/src/tools/setup/providers/claude.ts +25 -3
  160. package/src/tools/setup/utils.ts +4 -2
  161. package/src/tools/setup/working-repo-cleanup.ts +2 -2
  162. package/src/tools/setup/working-repo-local-state.ts +2 -0
  163. package/src/tools/setup.ts +25 -14
  164. package/studio-dist/client/assets/app-D9cw6szy.css +2 -0
  165. package/studio-dist/client/assets/artifacts-WD2ZXYrx.js +1 -0
  166. package/studio-dist/client/assets/button-Br0O1sXw.js +1 -0
  167. package/studio-dist/client/assets/combobox-DA7RAUUZ.js +1 -0
  168. package/studio-dist/client/assets/companion-view-CrabvxS8.js +1 -0
  169. package/studio-dist/client/assets/factory-DGS0E16C.js +6 -0
  170. package/studio-dist/client/assets/fields-6aXBpFhJ.js +1 -0
  171. package/studio-dist/client/assets/getting-started-Clde4w6P.js +1 -0
  172. package/studio-dist/client/assets/getting-started-D6kgWwWZ.js +1 -0
  173. package/studio-dist/client/assets/getting-started._topic-BiunccbT.js +1 -0
  174. package/studio-dist/client/assets/getting-started.index-DpiNoGw8.js +1 -0
  175. package/studio-dist/client/assets/graph-B_TCBVbu.js +2 -0
  176. package/studio-dist/client/assets/graph-canvas-Ba37Y5AE.js +3242 -0
  177. package/studio-dist/client/assets/guides-Du_RtJxP.js +1 -0
  178. package/studio-dist/client/assets/index-Df8L1LQa.js +40 -0
  179. package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
  180. package/studio-dist/client/assets/markdown-view-BOX6x0rL.js +1 -0
  181. package/studio-dist/client/assets/panel-dbmCx7Mx.js +1 -0
  182. package/studio-dist/client/assets/queries-RvHeXY12.js +1 -0
  183. package/studio-dist/client/assets/react-3QStrcDO.js +27 -0
  184. package/studio-dist/client/assets/report-url-XRL0x1SY.js +1 -0
  185. package/studio-dist/client/assets/reports-r3IK7Doz.js +1 -0
  186. package/studio-dist/client/assets/routes-C0A5LTFc.js +1 -0
  187. package/studio-dist/client/assets/select-CnaMd617.js +1 -0
  188. package/studio-dist/client/assets/skills-CzjzHpBT.js +1 -0
  189. package/studio-dist/client/assets/specs-B0ldF_6J.js +1 -0
  190. package/studio-dist/client/assets/specs-view-BnCLA0gW.js +1 -0
  191. package/studio-dist/client/assets/spinner-Dcm3fqK1.js +1 -0
  192. package/studio-dist/client/assets/steps-C0p2N1Pb.js +1 -0
  193. package/studio-dist/client/assets/store-Dw34catY.js +1 -0
  194. package/studio-dist/client/assets/studio-Cpz_HRHp.js +100 -0
  195. package/studio-dist/client/assets/studio-queries-ibmpFo6R.js +2 -0
  196. package/studio-dist/client/assets/usage-C2QJ_0IZ.js +55 -0
  197. package/studio-dist/client/assets/useAnchoredPopupScrollLock-Bj-FWb8z.js +1 -0
  198. package/studio-dist/client/assets/useMutation-aAr2uiay.js +1 -0
  199. package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
  200. package/studio-dist/client/assets/vault-BGcxkSIY.js +1 -0
  201. package/studio-dist/client/assets/warnings-R1cE1rLf.js +1 -0
  202. package/studio-dist/client/assets/workflow-C2qTrMDH.js +1 -0
  203. package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-Bn896ZYj.js +122 -0
  204. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +102 -35
  205. package/studio-dist/server/assets/{actions-Bvgj9eb8.js → actions-DYSv-9VV.js} +10 -4
  206. package/studio-dist/server/assets/artifacts-DnF9L3dZ.js +216 -0
  207. package/studio-dist/server/assets/{button-CIJqAhni.js → button-CgOIVdmD.js} +13 -1702
  208. package/studio-dist/server/assets/combobox-DV_s9W0s.js +483 -0
  209. package/studio-dist/server/assets/{companion-view-DISASvdJ.js → companion-view-BKVXD3TO.js} +3 -3
  210. package/studio-dist/server/assets/companions-C7fctnU9.js +31 -0
  211. package/studio-dist/server/assets/{createServerRpc-tK2lE9R2.js → createServerRpc-bFKFpGFG.js} +1 -1
  212. package/studio-dist/server/assets/{factory-DUTa0eDs.js → factory-C7Ybg0xG.js} +1256 -353
  213. package/studio-dist/server/assets/{factory-DGPmNGbo.js → factory-Df5uAHjb.js} +53 -6
  214. package/studio-dist/server/assets/fields-BbieQTD0.js +1190 -0
  215. package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
  216. package/studio-dist/server/assets/getting-started-CRxMWorQ.js +67 -0
  217. package/studio-dist/server/assets/getting-started._topic-DJKQAzYl.js +13 -0
  218. package/studio-dist/server/assets/getting-started.index-D84gec1t.js +13 -0
  219. package/studio-dist/server/assets/graph-CSje3029.js +801 -0
  220. package/studio-dist/server/assets/graph-DDZzXM1L.js +16 -0
  221. package/studio-dist/server/assets/graph-canvas-22bWB5-2.js +21066 -0
  222. package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
  223. package/studio-dist/server/assets/guides-D9dk1Frq.js +13 -0
  224. package/studio-dist/server/assets/guides-IE-19POz.js +5 -0
  225. package/studio-dist/server/assets/guides.server-vcYRY5wx.js +66 -0
  226. package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
  227. package/studio-dist/server/assets/{markdown-view-Bn7xPdks.js → markdown-view-BR8dJ7aR.js} +28 -9
  228. package/studio-dist/server/assets/{panel-3Jmn4awF.js → panel-BR_t9iMM.js} +4 -4
  229. package/studio-dist/server/assets/queries-DWoTin-q.js +32 -0
  230. package/studio-dist/server/assets/react-CdqSUhaL.js +89 -0
  231. package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
  232. package/studio-dist/server/assets/report-url-BUXPcE_8.js +9 -0
  233. package/studio-dist/server/assets/{reports-D6YMqhnO.js → reports-CQ9qQ1-n.js} +9 -10
  234. package/studio-dist/server/assets/{reports-C06RXVE2.js → reports-dYDEoBeq.js} +3 -3
  235. package/studio-dist/server/assets/{router-C8MGqlAY.js → router-DkRHNTpE.js} +787 -2862
  236. package/studio-dist/server/assets/{routes-BcFgvqf7.js → routes-B6GfOew4.js} +22 -171
  237. package/studio-dist/server/assets/{search-JAKurDNh.js → search-BJnWLfkG.js} +21 -2
  238. package/studio-dist/server/assets/select-Af7Wibii.js +1609 -0
  239. package/studio-dist/server/assets/{shell-DS3wUexh.js → shell-Hq-hXgnT.js} +6 -5
  240. package/studio-dist/server/assets/{skills-BEnOxiDl.js → skills-B7nEuVbx.js} +9 -8
  241. package/studio-dist/server/assets/{skills-CtrBAtX3.js → skills-B_YYL7q8.js} +3 -3
  242. package/studio-dist/server/assets/specs-BpLUFntA.js +51 -0
  243. package/studio-dist/server/assets/specs-view-0peMVd22.js +426 -0
  244. package/studio-dist/server/assets/spinner-CdwJW4VB.js +20 -0
  245. package/studio-dist/server/assets/{steps-Dq_CwY_s.js → steps-D56DApvK.js} +1 -1
  246. package/studio-dist/server/assets/store-Cs17okNG.js +280 -0
  247. package/studio-dist/server/assets/studio-CAcKp3bM.js +10340 -0
  248. package/studio-dist/server/assets/studio-queries-BtRGzDdh.js +1451 -0
  249. package/studio-dist/server/assets/usage-COdjd1gD.js +25570 -0
  250. package/studio-dist/server/assets/usage-f6pqE1tm.js +24 -0
  251. package/studio-dist/server/assets/useAnchoredPopupScrollLock-DlBKHRw7.js +756 -0
  252. package/studio-dist/server/assets/useMutation-DzTZGenE.js +690 -0
  253. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-M2GBs8s3.js → useSelector-DUmCUXAs.js} +4 -668
  254. package/studio-dist/server/assets/{vault-Fvxt2Tzl.js → vault-BDuIUq0F.js} +8 -5
  255. package/studio-dist/server/assets/{vault-BmWnryh3.js → vault-BVLp6zu3.js} +3 -3
  256. package/studio-dist/server/assets/{views-BgYa-za2.js → views-flRUr21z.js} +4 -4
  257. package/studio-dist/server/assets/{warnings-DzR6fyZh.js → warnings-CDy9pdgL.js} +3 -2
  258. package/studio-dist/server/assets/{delivery-path-C29fBynY.js → workflow-D9GKI2EV.js} +132 -106
  259. package/studio-dist/server/server.js +582 -8
  260. package/src/cli/commands/report/collector.ts +0 -288
  261. package/studio-dist/client/assets/app-CdPiFv59.css +0 -2
  262. package/studio-dist/client/assets/button-BIIHE0EQ.js +0 -3
  263. package/studio-dist/client/assets/companion-view-DM6YyXaR.js +0 -1
  264. package/studio-dist/client/assets/delivery-path-DELxj0Av.js +0 -1
  265. package/studio-dist/client/assets/factory-BZy0E8ty.js +0 -4
  266. package/studio-dist/client/assets/index-B3wkMzjA.js +0 -40
  267. package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +0 -1
  268. package/studio-dist/client/assets/panel-CbajlC3p.js +0 -1
  269. package/studio-dist/client/assets/prepaint-CwSrpdFA.js +0 -27
  270. package/studio-dist/client/assets/react-CN2GSx7x.js +0 -1
  271. package/studio-dist/client/assets/reports-DllhYQ5_.js +0 -1
  272. package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +0 -1
  273. package/studio-dist/client/assets/routes-COm-G3mK.js +0 -1
  274. package/studio-dist/client/assets/skills-DmWAy-jZ.js +0 -1
  275. package/studio-dist/client/assets/specs-BG3Wi3ln.js +0 -1
  276. package/studio-dist/client/assets/steps-DFsH3Neu.js +0 -1
  277. package/studio-dist/client/assets/vault-B2q1nBY5.js +0 -1
  278. package/studio-dist/client/assets/warnings-BSXIyuSQ.js +0 -1
  279. package/studio-dist/client/assets/workflow-DlsQD6Hc.js +0 -1
  280. package/studio-dist/server/assets/companions-BYbHWKOZ.js +0 -15
  281. package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +0 -459
  282. package/studio-dist/server/assets/prepaint-DJfTQ_VH.js +0 -45
  283. package/studio-dist/server/assets/react-Ce6dj15C.js +0 -46
  284. package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +0 -34
  285. package/studio-dist/server/assets/specs-C8rv34-5.js +0 -211
  286. package/studio-dist/server/assets/studio-BeltxxKt.js +0 -216
  287. package/studio-dist/server/assets/workflow-liRYecHk.js +0 -73
@@ -48,6 +48,13 @@ export function hasTokensaveCapability(capabilities: GuidanceCapability[] = []):
48
48
  return capabilities.some((capability) => capability.name === "tokensave");
49
49
  }
50
50
 
51
+ export function hasRtkCapability(capabilities: GuidanceCapability[] = []): boolean {
52
+ return capabilities.some((capability) => capability.name === "rtk");
53
+ }
54
+
55
+ /** Claude only: no other runtime isolates a session it moved into a worktree. */
56
+ const ENTERED_WORKTREE_GIT_RULE = ` <rule id="entered-worktree-git" severity="critical">After EnterWorktree moves this session into a linked worktree, run every git command as RTK_DISABLED=1 git ... (for example RTK_DISABLED=1 git status): Claude Code's worktree guard refuses git run through RTK there. Run other commands as usual.</rule>`;
57
+
51
58
  export const GRAPHIFY_SHARED_COMPANION_PATH_CONTRACT =
52
59
  "$MATE_ARTIFACT_PATH/.graphify/$MATE_REPO_ID/graphify-out/";
53
60
  export const GRAPHIFY_COMPANION_PATH_CONTRACT =
@@ -107,7 +114,8 @@ export function buildCodebaseExplorationGuidanceSection(
107
114
 
108
115
  /**
109
116
  * Build just the `<companion-policy>` XML block: paths, CLI tools, and
110
- * mandatory rules (including the capability-gated `openspec-publish` rule).
117
+ * mandatory rules (including the capability-gated `openspec-publish` rule, and
118
+ * with `enteredWorktreeGit` the RTK-gated `entered-worktree-git` rule).
111
119
  * Does not include codebase-exploration guidance — see
112
120
  * `buildCompanionGuidance` for the merged single-string form, or call
113
121
  * `buildCodebaseExplorationGuidanceSection` directly when that guidance is
@@ -115,7 +123,7 @@ export function buildCodebaseExplorationGuidanceSection(
115
123
  */
116
124
  export function buildCompanionPolicyXml(
117
125
  context: GuidanceContext,
118
- options: { wrapperBinPath: string },
126
+ options: { wrapperBinPath: string; enteredWorktreeGit?: boolean },
119
127
  ): string {
120
128
  const { wrapperBinPath } = options;
121
129
  const lines = [
@@ -185,6 +193,10 @@ export function buildCompanionPolicyXml(
185
193
  );
186
194
  }
187
195
 
196
+ if (options.enteredWorktreeGit && hasRtkCapability(context.capabilities)) {
197
+ lines.push(ENTERED_WORKTREE_GIT_RULE);
198
+ }
199
+
188
200
  lines.push(" </mandatory-rules>");
189
201
 
190
202
  lines.push("</companion-policy>");
@@ -196,13 +208,14 @@ export function buildCompanionPolicyXml(
196
208
  * Build the merged single-string guidance: the companion-policy XML plus
197
209
  * codebase-exploration guidance appended when graphify or tokensave is
198
210
  * enabled. Used by providers (e.g. Claude) that inject one combined prompt
199
- * fragment rather than delivering exploration guidance separately.
211
+ * fragment rather than delivering exploration guidance separately; only that
212
+ * form carries the Claude-only `entered-worktree-git` rule.
200
213
  */
201
214
  export function buildCompanionGuidance(
202
215
  context: GuidanceContext,
203
216
  options: { wrapperBinPath: string },
204
217
  ): string {
205
- const lines = [buildCompanionPolicyXml(context, options)];
218
+ const lines = [buildCompanionPolicyXml(context, { ...options, enteredWorktreeGit: true })];
206
219
 
207
220
  const graphifyEnabled = hasGraphifyCapability(context.capabilities);
208
221
  const tokensaveEnabled = hasTokensaveCapability(context.capabilities);
@@ -1,10 +1,24 @@
1
1
  import { execFile } from "node:child_process";
2
2
 
3
- /** The branch checked out at `dir`; null when detached or outside Git. */
4
- export function currentBranch(dir: string): Promise<string | null> {
3
+ import { umbrellaChildFolders, umbrellaFolderOf, umbrellaMirroredBy } from "./umbrella-folder";
4
+
5
+ function checkedOut(dir: string): Promise<string | null> {
5
6
  return new Promise((resolve) => {
6
7
  execFile("git", ["symbolic-ref", "--quiet", "--short", "HEAD"], { cwd: dir }, (error, out) =>
7
8
  resolve(error ? null : out.trim() || null),
8
9
  );
9
10
  });
10
11
  }
12
+
13
+ /**
14
+ * The branch checked out at `dir`; null when detached or outside Git. In a mirrored
15
+ * umbrella worktree, the first attached child's in name order, as the VS Code extension
16
+ * shows it; in an Umbrella Repository, null.
17
+ */
18
+ export async function currentBranch(dir: string): Promise<string | null> {
19
+ const umbrella = umbrellaFolderOf(dir);
20
+ if (!umbrella) return checkedOut(dir);
21
+ if (!umbrellaMirroredBy(umbrella)) return null;
22
+ const branches = await Promise.all(umbrellaChildFolders(umbrella).map(checkedOut));
23
+ return branches.find((branch) => branch !== null) ?? null;
24
+ }
@@ -0,0 +1,24 @@
1
+ import path from "node:path";
2
+
3
+ import { checkoutRootOf, isDirectory, readGitLayout } from "./git-layout";
4
+
5
+ /** Claude Code's own worktrees, which RTK already leaves alone. */
6
+ const CLAUDE_WORKTREES = `${path.sep}${path.join(".claude", "worktrees")}${path.sep}`;
7
+
8
+ /**
9
+ * True when a Claude session moved into a linked worktree, as `EnterWorktree` does:
10
+ * `cwd` lies in a linked worktree outside `.claude/worktrees/`, and `projectDir`
11
+ * (`CLAUDE_PROJECT_DIR`, the folder the session started in) lies in another
12
+ * checkout or in none. False whenever either cannot be determined.
13
+ */
14
+ export function movedIntoLinkedWorktree(cwd: string, projectDir: string | undefined): boolean {
15
+ try {
16
+ if (!cwd || !projectDir || !isDirectory(projectDir)) return false;
17
+ const root = checkoutRootOf(cwd);
18
+ if (!root || readGitLayout(root)?.kind !== "linked") return false;
19
+ if (`${root}${path.sep}`.includes(CLAUDE_WORKTREES)) return false;
20
+ return checkoutRootOf(projectDir) !== root;
21
+ } catch {
22
+ return false;
23
+ }
24
+ }
@@ -0,0 +1,60 @@
1
+ import { execFile, execFileSync } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { promisify } from "node:util";
5
+
6
+ import { gitEnvironment } from "./companion-git";
7
+
8
+ /**
9
+ * Whether Git tracks a repo-relative path in a Working Repository. Any
10
+ * `ls-files` failure, a non-Git checkout included, reads as untracked.
11
+ */
12
+
13
+ const execFileAsync = promisify(execFile);
14
+
15
+ /** On a case-insensitive file system a tracked case variant opens as the same file. */
16
+ function listed(stdout: string, repoPath: string, relativePath: string): boolean {
17
+ const entries = stdout.split("\0").filter(Boolean);
18
+ if (entries.includes(relativePath)) return true;
19
+ const target = lstatOrNull(path.join(repoPath, relativePath));
20
+ return entries.some((entry) => {
21
+ const stat = lstatOrNull(path.join(repoPath, entry));
22
+ return target !== null && stat?.ino === target.ino && stat.dev === target.dev;
23
+ });
24
+ }
25
+
26
+ function lstatOrNull(candidate: string): fs.Stats | null {
27
+ try {
28
+ return fs.lstatSync(candidate);
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+
34
+ function lsFiles(repoPath: string, relativePath: string) {
35
+ return {
36
+ args: ["ls-files", "-z", "--", `:(icase,literal)${relativePath}`],
37
+ options: { cwd: path.resolve(repoPath), encoding: "utf8" as const, env: gitEnvironment() },
38
+ };
39
+ }
40
+
41
+ export async function gitTracks(repoPath: string, relativePath: string): Promise<boolean> {
42
+ try {
43
+ const { args, options } = lsFiles(repoPath, relativePath);
44
+ const { stdout } = await execFileAsync("git", args, options);
45
+ return listed(stdout, options.cwd, relativePath);
46
+ } catch {
47
+ return false;
48
+ }
49
+ }
50
+
51
+ /** For session-start readers that cannot await. */
52
+ export function gitTracksSync(repoPath: string, relativePath: string): boolean {
53
+ try {
54
+ const { args, options } = lsFiles(repoPath, relativePath);
55
+ const stdout = execFileSync("git", args, { ...options, stdio: ["ignore", "pipe", "ignore"] });
56
+ return listed(stdout, options.cwd, relativePath);
57
+ } catch {
58
+ return false;
59
+ }
60
+ }
@@ -0,0 +1,72 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ import { FRAMEWORK_NAME } from "./framework";
5
+ import { isWithin, physicalPath } from "./physical-path";
6
+
7
+ /**
8
+ * The one containment check for what Mate places inside a Working Repository:
9
+ * a destination must resolve inside the repository's physical path, and no
10
+ * folder below the root on the way to it may be a symbolic link. A symlinked
11
+ * repository root stays allowed, because the root is resolved first.
12
+ */
13
+
14
+ export type RepoDestination =
15
+ | {
16
+ kind: "inside";
17
+ /** Absolute, under `root`. */
18
+ path: string;
19
+ /** The repository's physical path; the bound for pruning. */
20
+ root: string;
21
+ }
22
+ | { kind: "refused"; warning: string };
23
+
24
+ /** `key` is repo-relative with POSIX separators. The leaf may be anything. */
25
+ export function repoDestination(repoPath: string, key: string): RepoDestination {
26
+ return resolve(repoPath, key, false);
27
+ }
28
+
29
+ /** {@link repoDestination}, and an existing leaf must be a real directory too. */
30
+ export function repoDirectory(repoPath: string, key: string): RepoDestination {
31
+ return resolve(repoPath, key, true);
32
+ }
33
+
34
+ /** The outcome warning for a refused destination. */
35
+ export function refusedDestinationWarning(key: string, reason: string): string {
36
+ return `${key} was skipped: ${reason}. ${FRAMEWORK_NAME} does not follow it out of the Working Repository.`;
37
+ }
38
+
39
+ function resolve(repoPath: string, key: string, directory: boolean): RepoDestination {
40
+ const root = physicalPath(path.resolve(repoPath));
41
+ const target = path.join(root, ...key.split("/"));
42
+ if (target === root || !isWithin(target, root)) {
43
+ return refused(key, `${key} is not inside the Working Repository`);
44
+ }
45
+ const segments = path.relative(root, target).split(path.sep);
46
+ let current = root;
47
+ for (const [index, segment] of segments.entries()) {
48
+ current = path.join(current, segment);
49
+ const stat = lstatOrNull(current);
50
+ if (stat === null) break;
51
+ const leaf = index === segments.length - 1;
52
+ if ((leaf && !directory) || stat.isDirectory()) continue;
53
+ const named = segments.slice(0, index + 1).join("/");
54
+ return refused(
55
+ key,
56
+ stat.isSymbolicLink() ? `${named} is a symbolic link` : `${named} is not a directory`,
57
+ );
58
+ }
59
+ return { kind: "inside", path: target, root };
60
+ }
61
+
62
+ function refused(key: string, reason: string): RepoDestination {
63
+ return { kind: "refused", warning: refusedDestinationWarning(key, reason) };
64
+ }
65
+
66
+ function lstatOrNull(candidate: string): fs.Stats | null {
67
+ try {
68
+ return fs.lstatSync(candidate);
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
@@ -28,19 +28,41 @@ export function companionLinkPath(repoPath: string): string {
28
28
  return path.join(repoLocalDirPath(repoPath), "companion");
29
29
  }
30
30
 
31
+ /** The Umbrella Repository `folder` would mirror as `<umbrella>.worktrees/<id>`; else null. */
32
+ export function mirroredUmbrellaOf(folder: string): string | null {
33
+ const parent = path.dirname(path.resolve(folder));
34
+ const name = path.basename(parent);
35
+ if (!name.endsWith(".worktrees") || name === ".worktrees") return null;
36
+ return path.join(path.dirname(parent), name.slice(0, -".worktrees".length));
37
+ }
38
+
39
+ /** A linked non-Git `<umbrella>.worktrees/<id>` folder: an umbrella's mirrored worktree. */
40
+ function isMirroredWorktree(folder: string): boolean {
41
+ return (
42
+ mirroredUmbrellaOf(folder) !== null &&
43
+ readGitLayout(folder) === null &&
44
+ fs.existsSync(repoLocalRegistryPath(folder))
45
+ );
46
+ }
47
+
31
48
  /**
32
49
  * `cwd` and each of its ancestors, nearest first, ending at the filesystem
33
50
  * root or after a linked worktree's root, so a worktree nested in the main
34
51
  * worktree never reads the main worktree's `.mate/`. A main worktree or a
35
52
  * submodule walks on, so a submodule still resolves to the outer repository.
36
- * Shared by the async and sync registry walks so the two cannot land on
37
- * different ancestors.
53
+ * A linked worktree directly in a mirrored worktree also yields that folder,
54
+ * which serves it as an Umbrella Repository serves its children. Shared by the
55
+ * async and sync registry walks so the two cannot land on different ancestors.
38
56
  */
39
57
  export function* ancestorDirectories(cwd: string): Generator<string> {
40
58
  let dir = path.resolve(cwd);
41
59
  for (;;) {
42
60
  yield dir;
43
- if (readGitLayout(dir)?.kind === "linked") return;
61
+ if (readGitLayout(dir)?.kind === "linked") {
62
+ const parent = path.dirname(dir);
63
+ if (isMirroredWorktree(parent)) yield parent;
64
+ return;
65
+ }
44
66
  const parent = path.dirname(dir);
45
67
  if (parent === dir) return;
46
68
  dir = parent;
@@ -0,0 +1,66 @@
1
+ import { spawnSync } from "node:child_process";
2
+
3
+ import { resolveCompanionRuntime } from "./env";
4
+ import { isCapabilityEnabled, readCompanionPolicy } from "./policy";
5
+
6
+ /**
7
+ * Claude Code's worktree guard refuses git behind a launcher, so `rtk git` fails
8
+ * in a session moved into a linked worktree. `RTK_DISABLED=1 git` passes both:
9
+ * RTK leaves that segment alone and the guard reads plain git.
10
+ */
11
+
12
+ /** RTK's rewrite of `command`, or null when it rewrites nothing or cannot answer. */
13
+ export type RewriteRunner = (command: string) => string | null;
14
+
15
+ const REWRITE_TIMEOUT_MS = 1_000;
16
+
17
+ /**
18
+ * `rtk rewrite`, the single source of truth RTK's own hooks use. It prints the
19
+ * rewrite on stdout and exits 3 (0 when already `rtk`), or prints nothing and
20
+ * exits 1; the exit code is ignored. A missing binary or a timeout answers null.
21
+ */
22
+ function rtkRewrite(command: string): string | null {
23
+ const result = spawnSync("rtk", ["rewrite", command], {
24
+ encoding: "utf8",
25
+ timeout: REWRITE_TIMEOUT_MS,
26
+ stdio: ["ignore", "pipe", "ignore"],
27
+ });
28
+ if (result.error || result.signal) return null;
29
+ return result.stdout.trim() || null;
30
+ }
31
+
32
+ const RTK_GIT = /(^|[\s;&|(])rtk git(?=\s|$)/g;
33
+
34
+ /**
35
+ * The command to run instead when RTK would run `command` as `rtk git`: RTK's
36
+ * rewrite with each `rtk git` as `RTK_DISABLED=1 git`, every other segment kept.
37
+ * Null otherwise, including when the runner fails.
38
+ */
39
+ export function runnableGitCommand(
40
+ command: string,
41
+ rewrite: RewriteRunner = rtkRewrite,
42
+ ): string | null {
43
+ let rewritten: string | null;
44
+ try {
45
+ rewritten = rewrite(command);
46
+ } catch {
47
+ return null;
48
+ }
49
+ if (!rewritten) return null;
50
+ const runnable = rewritten.replace(RTK_GIT, "$1RTK_DISABLED=1 git");
51
+ return runnable === rewritten ? null : runnable;
52
+ }
53
+
54
+ /** True when the policy of the companion at `companionPath` selects RTK. */
55
+ export function companionPolicySelectsRtk(companionPath: string): boolean {
56
+ return isCapabilityEnabled(readCompanionPolicy(companionPath), "rtk");
57
+ }
58
+
59
+ /** True when the companion of the session at `cwd` selects RTK; the launch environment wins. */
60
+ export function companionSelectsRtk(
61
+ cwd: string,
62
+ env: Record<string, string | undefined> = process.env,
63
+ ): boolean {
64
+ const { companionPath } = resolveCompanionRuntime(env, cwd).context;
65
+ return Boolean(companionPath) && companionPolicySelectsRtk(companionPath);
66
+ }
@@ -1,7 +1,10 @@
1
+ import fs from "node:fs";
1
2
  import fsp from "node:fs/promises";
2
3
  import path from "node:path";
3
4
 
4
- import { repoLocalDirPath } from "./repo-local";
5
+ import { FRAMEWORK_NAME } from "./framework";
6
+ import { gitTracksSync } from "./git-tracked";
7
+ import { repoLocalDirName, repoLocalDirPath } from "./repo-local";
5
8
  import { writeAtomic } from "./write-atomic";
6
9
 
7
10
  /**
@@ -23,6 +26,20 @@ export const OPENCODE_CONFIG_DOCUMENT = ".opencode/opencode.json";
23
26
  */
24
27
  export const CLAUDE_LOCAL_CONFIG_DOCUMENT = "~/.claude.json";
25
28
 
29
+ /**
30
+ * The closed set of documents a wrap places. A manifest naming any other is
31
+ * ignored at parse, and a surface rendering one fails to compile.
32
+ */
33
+ export const RUNTIME_DOCUMENTS = [
34
+ CLAUDE_SETTINGS_DOCUMENT,
35
+ CLAUDE_LOCAL_CONFIG_DOCUMENT,
36
+ OPENCODE_CONFIG_DOCUMENT,
37
+ ] as const;
38
+ export type RuntimeDocumentPath = (typeof RUNTIME_DOCUMENTS)[number];
39
+
40
+ /** Recorded by earlier releases; only ever withdrawn. */
41
+ export const LEGACY_RUNTIME_DOCUMENTS = [CLAUDE_MCP_DOCUMENT] as const;
42
+
26
43
  /** Where in {@link OPENCODE_CONFIG_DOCUMENT} the wrap renders its MCP servers. */
27
44
  export const OPENCODE_MCP_SERVERS_AT: readonly string[] = Object.freeze(["mcp", "servers"]);
28
45
 
@@ -57,8 +74,7 @@ export type ManagedRegion =
57
74
  * document, without a destination. The surface renders; the entry places.
58
75
  */
59
76
  export interface RenderedRuntimeDocument {
60
- /** Repo-relative with POSIX separators, or `~/`-prefixed for a user-global target. */
61
- readonly path: string;
77
+ readonly path: RuntimeDocumentPath;
62
78
  readonly regions: readonly ManagedRegion[];
63
79
  }
64
80
 
@@ -79,7 +95,7 @@ function nonEmpty(region: ManagedRegion): boolean {
79
95
 
80
96
  /** One rendered document of its non-empty regions, or none when every region is empty. */
81
97
  export function renderedDocument(
82
- documentPath: string,
98
+ documentPath: RuntimeDocumentPath,
83
99
  regions: ManagedRegion[],
84
100
  ): RenderedRuntimeDocument[] {
85
101
  const kept = regions.filter(nonEmpty);
@@ -122,32 +138,164 @@ function isRecord(value: unknown): value is Record<string, unknown> {
122
138
  return typeof value === "object" && value !== null && !Array.isArray(value);
123
139
  }
124
140
 
125
- /** Never throws: an absent, unparseable or foreign manifest reads as empty — Mate can rebuild it. */
126
- export function parseManifest(raw: string | null): Manifest {
127
- if (raw === null) return EMPTY_MANIFEST;
141
+ /** A manifest confined to the closed destination set, and the records it dropped. */
142
+ export interface ConfinedManifest {
143
+ manifest: Manifest;
144
+ /** Each dropped key, or `<document> region at <address>`, as recorded. */
145
+ rejected: string[];
146
+ }
147
+
148
+ const NO_REJECTIONS: ConfinedManifest = Object.freeze({ manifest: EMPTY_MANIFEST, rejected: [] });
149
+
150
+ /**
151
+ * Never throws: an absent, unparseable or foreign manifest reads as empty — Mate can rebuild it.
152
+ * `repoRoot` pins the one `~/.claude.json` region this repository may record.
153
+ */
154
+ export function parseManifest(raw: string | null, repoRoot: string): Manifest {
155
+ return confineManifest(raw, repoRoot).manifest;
156
+ }
157
+
158
+ /** {@link parseManifest}, also reporting what confinement dropped. */
159
+ export function confineManifest(raw: string | null, repoRoot: string): ConfinedManifest {
160
+ if (raw === null) return NO_REJECTIONS;
128
161
  let parsed: unknown;
129
162
  try {
130
163
  parsed = JSON.parse(raw) as unknown;
131
164
  } catch {
132
- return EMPTY_MANIFEST;
165
+ return NO_REJECTIONS;
133
166
  }
134
- return isRecord(parsed) ? manifestOf(parsed) : EMPTY_MANIFEST;
167
+ return isRecord(parsed) ? manifestOf(parsed, repoRoot) : NO_REJECTIONS;
135
168
  }
136
169
 
137
170
  /** For readers that rewrite on its strength: a manifest present but unparseable throws. */
138
- export function parseManifestStrict(raw: string | null): Manifest {
171
+ export function parseManifestStrict(raw: string | null, repoRoot: string): Manifest {
139
172
  if (raw === null) return EMPTY_MANIFEST;
140
173
  const parsed = JSON.parse(raw) as unknown;
141
174
  if (!isRecord(parsed)) throw new Error("runtime document manifest is not a JSON object");
142
- return manifestOf(parsed);
175
+ return manifestOf(parsed, repoRoot).manifest;
176
+ }
177
+
178
+ const PLACED_DOCUMENTS: ReadonlySet<string> = new Set([
179
+ ...RUNTIME_DOCUMENTS,
180
+ ...LEGACY_RUNTIME_DOCUMENTS,
181
+ ]);
182
+ const OPENCODE_COPY_PREFIX = ".opencode/";
183
+ const UNCOPIED_SEGMENTS: ReadonlySet<string> = new Set(["node_modules", ".DS_Store"]);
184
+ const LINK_KEY = /^\.claude\/(?:skills|commands)\/([^/]*)$/;
185
+
186
+ /** Control characters would inject exclude lines; a backslash is a separator on Windows. */
187
+ function isPlainSegment(segment: string): boolean {
188
+ return (
189
+ segment !== "" &&
190
+ segment !== "." &&
191
+ segment !== ".." &&
192
+ // oxlint-disable-next-line no-control-regex -- control characters are what this rejects
193
+ !/[\u0000-\u001f\u007f\\]/.test(segment)
194
+ );
195
+ }
196
+
197
+ /** A normalized POSIX path under `.opencode/` that a companion copy may occupy. */
198
+ export function isPlaceableCopyKey(key: string): boolean {
199
+ if (!key.startsWith(OPENCODE_COPY_PREFIX) || key === OPENCODE_CONFIG_DOCUMENT) return false;
200
+ return key
201
+ .slice(OPENCODE_COPY_PREFIX.length)
202
+ .split("/")
203
+ .every((segment) => isPlainSegment(segment) && !UNCOPIED_SEGMENTS.has(segment));
204
+ }
205
+
206
+ function isPlaceableLinkKey(key: string): boolean {
207
+ const name = LINK_KEY.exec(key)?.[1];
208
+ return name !== undefined && isPlainSegment(name);
209
+ }
210
+
211
+ /** Mate writes exactly one region there: this repository's MCP servers, by key. */
212
+ function isOwnLocalConfigRegion(region: unknown, localConfigAt: readonly string[]): boolean {
213
+ return (
214
+ isRecord(region) &&
215
+ region.kind === "map" &&
216
+ isAt(region.at, localConfigAt) &&
217
+ isRecord(region.entries) &&
218
+ !Object.hasOwn(region, "stripPrefix")
219
+ );
220
+ }
221
+
222
+ function regionLabel(documentPath: string, region: unknown): string {
223
+ const at = isRecord(region) && Array.isArray(region.at) ? JSON.stringify(region.at) : "?";
224
+ return `${documentPath} region at ${at}`;
225
+ }
226
+
227
+ function confinedDocuments(
228
+ recorded: Record<string, unknown>,
229
+ repoRoot: string,
230
+ rejected: string[],
231
+ ): Record<string, ManagedRegion[]> {
232
+ const localConfigAt = ["projects", path.resolve(repoRoot), "mcpServers"];
233
+ const kept: Record<string, ManagedRegion[]> = {};
234
+ for (const [documentPath, regions] of Object.entries(recorded)) {
235
+ if (!PLACED_DOCUMENTS.has(documentPath)) {
236
+ rejected.push(documentPath);
237
+ continue;
238
+ }
239
+ if (documentPath !== CLAUDE_LOCAL_CONFIG_DOCUMENT) {
240
+ kept[documentPath] = regions as ManagedRegion[];
241
+ continue;
242
+ }
243
+ const all: unknown[] = Array.isArray(regions) ? regions : [];
244
+ const own: unknown[] = [];
245
+ for (const region of all) {
246
+ if (isOwnLocalConfigRegion(region, localConfigAt)) own.push(region);
247
+ else rejected.push(regionLabel(documentPath, region));
248
+ }
249
+ if (own.length > 0) kept[documentPath] = own as ManagedRegion[];
250
+ else if (all.length === 0) rejected.push(documentPath);
251
+ }
252
+ return kept;
143
253
  }
144
254
 
145
- function manifestOf(parsed: Record<string, unknown>): Manifest {
255
+ function confinedRecords<T>(
256
+ recorded: Record<string, unknown>,
257
+ placeable: (key: string, record: unknown) => boolean,
258
+ rejected: string[],
259
+ ): Record<string, T> {
260
+ const kept: Record<string, T> = {};
261
+ for (const [key, record] of Object.entries(recorded)) {
262
+ if (placeable(key, record)) kept[key] = record as T;
263
+ else rejected.push(key);
264
+ }
265
+ return kept;
266
+ }
267
+
268
+ function manifestOf(parsed: Record<string, unknown>, repoRoot: string): ConfinedManifest {
269
+ const rejected: string[] = [];
270
+ const keptDocuments = isRecord(parsed.documents)
271
+ ? confinedDocuments(parsed.documents, repoRoot, rejected)
272
+ : {};
273
+ const keptRuntimes = isRecord(parsed.runtimes)
274
+ ? Object.fromEntries(
275
+ Object.entries(parsed.runtimes as Manifest["runtimes"]).filter(([documentPath]) =>
276
+ Object.hasOwn(keptDocuments, documentPath),
277
+ ),
278
+ )
279
+ : {};
280
+ const keptCopies = isRecord(parsed.copies)
281
+ ? confinedRecords<CopyRecord>(parsed.copies, isPlaceableCopyKey, rejected)
282
+ : {};
283
+ const keptLinks = isRecord(parsed.links)
284
+ ? confinedRecords<LinkRecord>(
285
+ parsed.links,
286
+ (key, record) =>
287
+ isPlaceableLinkKey(key) && isRecord(record) && typeof record.target === "string",
288
+ rejected,
289
+ )
290
+ : {};
146
291
  return {
147
- documents: isRecord(parsed.documents) ? (parsed.documents as Manifest["documents"]) : {},
148
- runtimes: isRecord(parsed.runtimes) ? (parsed.runtimes as Manifest["runtimes"]) : {},
149
- copies: isRecord(parsed.copies) ? (parsed.copies as Manifest["copies"]) : {},
150
- links: isRecord(parsed.links) ? (parsed.links as Manifest["links"]) : {},
292
+ manifest: {
293
+ documents: keptDocuments,
294
+ runtimes: keptRuntimes,
295
+ copies: keptCopies,
296
+ links: keptLinks,
297
+ },
298
+ rejected,
151
299
  };
152
300
  }
153
301
 
@@ -345,17 +493,37 @@ export function manifestPath(repoPath: string): string {
345
493
  return path.join(repoLocalDirPath(repoPath), RUNTIME_DOCUMENT_MANIFEST_FILE);
346
494
  }
347
495
 
496
+ /** Repo-relative, POSIX separators. */
497
+ export const MANIFEST_RELATIVE_PATH = `${repoLocalDirName()}/${RUNTIME_DOCUMENT_MANIFEST_FILE}`;
498
+
499
+ /** Mate never changes tracking within a command, so one answer per repository suffices. */
500
+ const trackedManifests = new Map<string, boolean>();
501
+
502
+ /**
503
+ * Whether Git tracks the manifest, which then reads as absent and is never
504
+ * written: a committed file is the repository's, not Mate's record. Spawns Git
505
+ * only when the file exists; a Git failure answers untracked.
506
+ */
507
+ export function manifestTracked(repoPath: string): boolean {
508
+ const root = path.resolve(repoPath);
509
+ const known = trackedManifests.get(root);
510
+ if (known !== undefined) return known;
511
+ if (!fs.existsSync(manifestPath(root))) return false;
512
+ const tracked = gitTracksSync(root, MANIFEST_RELATIVE_PATH);
513
+ trackedManifests.set(root, tracked);
514
+ return tracked;
515
+ }
516
+
348
517
  /**
349
518
  * The runtime document manifest at the Projection Root; empty when absent. A
350
519
  * read that failed for a reason other than absence throws, so a writer never
351
520
  * replaces a manifest it could not read.
352
521
  */
353
522
  export async function readManifest(repoPath: string): Promise<Manifest> {
354
- return parseManifest(await readManifestText(repoPath));
523
+ return parseManifest(await readManifestText(repoPath), repoPath);
355
524
  }
356
525
 
357
- /** `null` when absent; any other read failure throws. */
358
- export async function readManifestText(repoPath: string): Promise<string | null> {
526
+ async function readManifestFile(repoPath: string): Promise<string | null> {
359
527
  try {
360
528
  return await fsp.readFile(manifestPath(repoPath), "utf8");
361
529
  } catch (error) {
@@ -364,6 +532,47 @@ export async function readManifestText(repoPath: string): Promise<string | null>
364
532
  }
365
533
  }
366
534
 
535
+ /** `null` when absent or tracked by Git; any other read failure throws. */
536
+ export async function readManifestText(repoPath: string): Promise<string | null> {
537
+ const raw = await readManifestFile(repoPath);
538
+ return raw !== null && manifestTracked(repoPath) ? null : raw;
539
+ }
540
+
541
+ /** Lenient: `null` when absent, unreadable or tracked by Git. */
542
+ export function readManifestTextSync(repoPath: string): string | null {
543
+ let raw: string;
544
+ try {
545
+ raw = fs.readFileSync(manifestPath(repoPath), "utf8");
546
+ } catch {
547
+ return null;
548
+ }
549
+ return manifestTracked(repoPath) ? null : raw;
550
+ }
551
+
552
+ /** A key may hold a newline; quoting keeps it on one output line. */
553
+ function shown(key: string): string {
554
+ // oxlint-disable-next-line no-control-regex -- control characters are what this quotes
555
+ return /[\u0000-\u001f\u007f]/.test(key) ? JSON.stringify(key) : key;
556
+ }
557
+
558
+ /**
559
+ * What a pass tells the operator about the manifest: that Git tracks it, or
560
+ * each record it ignored. Lenient, like the readers it explains.
561
+ */
562
+ export async function readManifestNotices(repoPath: string): Promise<string[]> {
563
+ const raw = await readManifestFile(repoPath).catch(() => null);
564
+ if (raw === null) return [];
565
+ if (manifestTracked(repoPath)) {
566
+ return [
567
+ `${MANIFEST_RELATIVE_PATH} is tracked by Git, so its records were ignored and it is left as committed. Untrack it with \`git rm --cached ${MANIFEST_RELATIVE_PATH}\`, then wrap again.`,
568
+ ];
569
+ }
570
+ return confineManifest(raw, repoPath).rejected.map(
571
+ (key) =>
572
+ `${MANIFEST_RELATIVE_PATH} records ${shown(key)}, which is not a destination ${FRAMEWORK_NAME} places; it was ignored and will be dropped on the next write.`,
573
+ );
574
+ }
575
+
367
576
  /**
368
577
  * The one way the manifest changes: read, edit, then write it atomically — or
369
578
  * delete it once it records nothing. Every writer goes through here, so none
@@ -374,6 +583,7 @@ export async function updateManifest(
374
583
  edit: (manifest: Manifest) => Manifest,
375
584
  ): Promise<Manifest> {
376
585
  const next = edit(await readManifest(repoPath));
586
+ if (manifestTracked(repoPath)) return next;
377
587
  const target = manifestPath(repoPath);
378
588
  const contents = serializeManifest(next);
379
589
  if (contents === null) {