@uniqbit/mate-core 0.21.1 → 1.0.0-canary.10

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 (467) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
  2. package/claude-plugin/hooks/hooks.json +32 -1
  3. package/claude-plugin/hooks/workflow-turn.mjs +68 -0
  4. package/opencode-plugin/src/companion.ts +6 -0
  5. package/opencode-plugin/src/server.ts +24 -0
  6. package/package.json +9 -4
  7. package/src/cli/commands/artifact/apply-context.ts +1 -0
  8. package/src/cli/commands/artifact/artifact.ts +16 -0
  9. package/src/cli/commands/artifact/delivery/archive.ts +37 -112
  10. package/src/cli/commands/artifact/delivery/branch-flags.ts +19 -1
  11. package/src/cli/commands/artifact/delivery/environment.ts +30 -90
  12. package/src/cli/commands/artifact/delivery/link.ts +26 -26
  13. package/src/cli/commands/artifact/delivery/output.ts +27 -4
  14. package/src/cli/commands/artifact/delivery/resolve.ts +102 -0
  15. package/src/cli/commands/artifact/delivery/submit.ts +171 -0
  16. package/src/cli/commands/artifact/delivery/take.ts +46 -0
  17. package/src/cli/commands/artifact/extract-repo-name.ts +1 -1
  18. package/src/cli/commands/artifact/finish/command.ts +486 -55
  19. package/src/cli/commands/artifact/finish/engine.ts +87 -69
  20. package/src/cli/commands/artifact/finish/finisher.ts +5 -12
  21. package/src/cli/commands/artifact/finish/git.ts +9 -10
  22. package/src/cli/commands/artifact/finish/openspec.ts +21 -174
  23. package/src/cli/commands/artifact/finish/secret-scan.ts +5 -43
  24. package/src/cli/commands/artifact/finish/worktree-cleanup.ts +57 -7
  25. package/src/cli/commands/artifact/pending/command.ts +187 -10
  26. package/src/cli/commands/artifact/pending/discovery.ts +7 -11
  27. package/src/cli/commands/artifact/project/command.ts +59 -0
  28. package/src/cli/commands/cap/tokensave.ts +2 -2
  29. package/src/cli/commands/companion/hub.ts +11 -6
  30. package/src/cli/commands/companion/link.ts +173 -46
  31. package/src/cli/commands/companion/list.ts +70 -14
  32. package/src/cli/commands/companion/sync.ts +18 -0
  33. package/src/cli/commands/companion/update.ts +4 -3
  34. package/src/cli/commands/doctor.ts +84 -4
  35. package/src/cli/commands/friction.ts +558 -0
  36. package/src/cli/commands/install.ts +9 -4
  37. package/src/cli/commands/plugin/install.ts +82 -35
  38. package/src/cli/commands/studio/companion-add.ts +12 -27
  39. package/src/cli/commands/studio/connection.ts +53 -0
  40. package/src/{lib/factory/outcomes/sessions.ts → cli/commands/studio/live-sessions.ts} +7 -5
  41. package/src/cli/commands/studio/mcp-manager.ts +162 -0
  42. package/src/cli/commands/studio/payload.ts +172 -17
  43. package/src/cli/commands/studio/reports.ts +19 -18
  44. package/src/cli/commands/studio/routes.ts +8 -24
  45. package/src/cli/commands/studio/selection.ts +13 -4
  46. package/src/cli/commands/studio/server.ts +267 -243
  47. package/src/cli/commands/studio/service-host.ts +269 -0
  48. package/src/cli/commands/studio/services.ts +53 -34
  49. package/src/cli/commands/studio/studio-app.ts +1 -0
  50. package/src/cli/commands/studio/terminal.ts +1 -1
  51. package/src/cli/commands/studio/vault.ts +41 -40
  52. package/src/cli/commands/studio/views/model.ts +1 -9
  53. package/src/cli/commands/studio/views/vault/markdown-tree.ts +6 -5
  54. package/src/cli/commands/triage.ts +172 -0
  55. package/src/cli/commands/vscode/release-vsix.json +2 -2
  56. package/src/cli/commands/workflow/workflow.ts +516 -0
  57. package/src/cli/commands/working/cleanup.ts +1 -18
  58. package/src/cli/companion-link-wizard.tsx +158 -91
  59. package/src/cli/install-plan.tsx +3 -0
  60. package/src/cli/main.ts +106 -26
  61. package/src/cli/plugin-commands.ts +6 -1
  62. package/src/cli/repo-list-table.tsx +73 -37
  63. package/src/cli/usage.ts +30 -9
  64. package/src/create-mate.ts +15 -6
  65. package/src/distribution.ts +2 -0
  66. package/src/factory-host.ts +75 -0
  67. package/src/hooks/companion-instructions.ts +19 -8
  68. package/src/hooks/hook-io.ts +3 -1
  69. package/src/hooks/session-banner.ts +25 -0
  70. package/src/hooks/validate-artifact-path.ts +73 -22
  71. package/src/hooks/workflow-turn.ts +219 -0
  72. package/src/index.ts +1 -0
  73. package/src/lib/apply-context/fingerprint.ts +2 -1
  74. package/src/lib/apply-context/protocol.ts +2 -2
  75. package/src/lib/artifact-trailer.ts +27 -0
  76. package/src/lib/change-layout.ts +83 -38
  77. package/src/lib/delivery/branch-template.ts +4 -12
  78. package/src/lib/delivery/checkout.ts +3 -2
  79. package/src/lib/delivery/environment.ts +129 -7
  80. package/src/lib/delivery/merge-git.ts +312 -28
  81. package/src/lib/delivery/overlap.ts +81 -16
  82. package/src/lib/delivery/record-delivery.ts +102 -9
  83. package/src/lib/delivery/record.ts +186 -24
  84. package/src/lib/delivery/refresh.ts +241 -152
  85. package/src/lib/delivery/remote.ts +66 -0
  86. package/src/lib/delivery/repository-access.ts +30 -66
  87. package/src/lib/delivery/stages.ts +83 -50
  88. package/src/lib/delivery/staging/apply-chain.ts +182 -0
  89. package/src/lib/delivery/staging/artifact-type.ts +101 -0
  90. package/src/lib/delivery/staging/declared-type.ts +277 -0
  91. package/src/lib/delivery/staging/linked-merges.ts +175 -0
  92. package/src/lib/delivery/staging/naming.ts +67 -0
  93. package/src/lib/delivery/staging/openspec-type.ts +166 -0
  94. package/src/lib/delivery/staging/pending-edit.ts +291 -0
  95. package/src/lib/delivery/staging/pending.ts +922 -0
  96. package/src/lib/delivery/staging/preflight.ts +239 -0
  97. package/src/lib/delivery/staging/project.ts +512 -0
  98. package/src/lib/delivery/staging/publish.ts +1024 -0
  99. package/src/lib/delivery/staging/refs.ts +258 -0
  100. package/src/lib/delivery/staging/registry.ts +73 -0
  101. package/src/lib/delivery/staging/replay.ts +310 -0
  102. package/src/lib/delivery/staging/requirement-blocks.ts +10 -0
  103. package/src/lib/delivery/staging/resolve.ts +264 -0
  104. package/src/lib/delivery/staging/settle-linked.ts +176 -0
  105. package/src/lib/delivery/staging/submit.ts +1050 -0
  106. package/src/lib/delivery/staging/worktree.ts +130 -0
  107. package/src/lib/delivery/submit-change.ts +569 -0
  108. package/src/lib/friction/describe.ts +42 -0
  109. package/src/lib/friction/fields.ts +60 -0
  110. package/src/lib/friction/mark.ts +194 -0
  111. package/src/lib/friction/view/model.ts +67 -0
  112. package/src/lib/friction/view/read.ts +145 -0
  113. package/src/lib/friction/view/select.ts +54 -0
  114. package/src/lib/git-key.ts +15 -0
  115. package/src/lib/install.ts +2 -0
  116. package/src/lib/mcp-manager/resolve.ts +88 -0
  117. package/src/lib/mcp-manager/store.ts +133 -0
  118. package/src/lib/mcp-manager/types.ts +72 -0
  119. package/src/lib/mcp-manager/validate.ts +242 -0
  120. package/src/lib/openspec-canonical-frontmatter.ts +159 -0
  121. package/src/lib/openspec-cli.ts +10 -5
  122. package/src/lib/orchestrator/adapters/base.ts +31 -20
  123. package/src/lib/orchestrator/adapters/claude.ts +21 -7
  124. package/src/lib/orchestrator/adapters/opencode.ts +4 -0
  125. package/src/lib/orchestrator/companion-git-sync.ts +152 -16
  126. package/src/lib/orchestrator/config-store.ts +30 -7
  127. package/src/lib/orchestrator/engine-floor.ts +16 -4
  128. package/src/lib/orchestrator/engine-guard.ts +7 -1
  129. package/src/lib/orchestrator/framework-context.ts +15 -1
  130. package/src/lib/orchestrator/projection-claude-links.ts +1 -0
  131. package/src/lib/orchestrator/refresh-working-claude-links.ts +1 -0
  132. package/src/lib/orchestrator/repo-local-store.ts +14 -0
  133. package/src/lib/orchestrator/repository-link.ts +80 -52
  134. package/src/lib/orchestrator/root-context.ts +40 -7
  135. package/src/lib/orchestrator/session-prepare.ts +11 -1
  136. package/src/lib/orchestrator/types.ts +4 -0
  137. package/src/lib/orchestrator/umbrella-checkouts.ts +4 -4
  138. package/src/lib/package-paths.ts +23 -15
  139. package/src/lib/prebuilt-workspace-prepare.ts +2 -1
  140. package/src/lib/prebuilt-workspace.ts +1 -0
  141. package/src/lib/session-attribution.ts +3 -7
  142. package/src/lib/session-state.ts +3 -2
  143. package/src/lib/skills-cli.ts +38 -0
  144. package/src/lib/tool-manifest.ts +73 -0
  145. package/src/lib/triage/context.ts +312 -0
  146. package/src/lib/triage/launch.ts +52 -0
  147. package/src/lib/triage/prepare.ts +112 -0
  148. package/src/lib/triage/session.ts +126 -0
  149. package/src/lib/workflow/declaration.ts +6 -0
  150. package/src/lib/workflow/handoff.ts +90 -0
  151. package/src/lib/workflow/hook-trust.ts +108 -0
  152. package/src/lib/workflow/position.ts +524 -0
  153. package/src/lib/workflow/report.ts +79 -0
  154. package/src/lib/workflow/work.ts +106 -0
  155. package/src/lib/workset/factory-local.ts +2 -2
  156. package/src/lib/workset/repositories.ts +2 -2
  157. package/src/lib/workset/stage.ts +4 -2
  158. package/src/lib/workset/stages.ts +64 -4
  159. package/src/lib/workset/worktree.ts +32 -14
  160. package/src/opencode/companion-hooks.ts +63 -14
  161. package/src/opencode/projected-guidance.ts +7 -2
  162. package/src/opencode/turn-hook.ts +241 -0
  163. package/src/playbooks/companion-guidance.ts +7 -4
  164. package/src/plugin-api.ts +48 -0
  165. package/src/runtime/artifact-trailers.ts +63 -0
  166. package/src/runtime/claude-hook-group.ts +2 -0
  167. package/src/runtime/command-arg.ts +15 -0
  168. package/src/runtime/command-friction.ts +97 -0
  169. package/src/runtime/companion-git-state.ts +155 -10
  170. package/src/runtime/companion-git.ts +86 -11
  171. package/src/runtime/companion-guidance.ts +120 -17
  172. package/src/runtime/companion-instructions.ts +1 -1
  173. package/src/runtime/companion-sync.ts +109 -21
  174. package/src/runtime/env-names.ts +2 -2
  175. package/src/runtime/env.ts +7 -6
  176. package/src/runtime/forge-remote.ts +54 -0
  177. package/src/runtime/friction-fingerprint.ts +35 -0
  178. package/src/runtime/friction-log.ts +376 -0
  179. package/src/runtime/friction-recorder.ts +212 -0
  180. package/src/runtime/friction-retention.ts +1 -0
  181. package/src/runtime/friction-state.ts +110 -0
  182. package/src/runtime/friction-switch.ts +26 -0
  183. package/src/runtime/friction-vocabulary.ts +42 -0
  184. package/src/runtime/git-layout.ts +21 -7
  185. package/src/runtime/git-tracked.ts +13 -2
  186. package/src/runtime/json-fields.ts +8 -0
  187. package/src/runtime/pending-records.ts +533 -0
  188. package/src/runtime/projected-guidance.ts +8 -3
  189. package/src/runtime/publication-secret-scan.ts +45 -0
  190. package/src/runtime/secret-patterns.ts +7 -5
  191. package/src/runtime/secret-values.ts +16 -0
  192. package/src/runtime/session-id.ts +24 -0
  193. package/src/runtime/session-prepare-runner.ts +3 -0
  194. package/src/runtime/skill-prefix.ts +75 -0
  195. package/src/runtime/submitted-arrivals.ts +547 -0
  196. package/src/runtime/turn-state.d.mts +14 -0
  197. package/src/runtime/turn-state.mjs +93 -0
  198. package/src/runtime/umbrella-children.ts +52 -0
  199. package/src/runtime/umbrella-folder.ts +31 -3
  200. package/src/runtime/workflow/change-folders.ts +66 -0
  201. package/src/runtime/workflow/declaration.ts +720 -0
  202. package/src/runtime/workflow/globs.ts +85 -0
  203. package/src/runtime/workflow/next-handoff-process.ts +99 -0
  204. package/src/runtime/workflow/turn.ts +311 -0
  205. package/src/runtime/workflow/workflow.ts +262 -0
  206. package/src/studio.ts +113 -23
  207. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/schema.yaml +3 -3
  208. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/design.md +1 -1
  209. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/proposal.md +1 -1
  210. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/tasks.md +1 -1
  211. package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +7 -3
  212. package/src/templates/capabilities/react-doctor/mate-react-doctor/SKILL.md +28 -0
  213. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +84 -28
  214. package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +1 -1
  215. package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +30 -68
  216. package/src/templates/mate-skills/agents/mate-backfill-spec/SKILL.md +23 -1
  217. package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +39 -8
  218. package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +38 -0
  219. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +65 -12
  220. package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +28 -0
  221. package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +28 -0
  222. package/src/templates/mate-skills/agents/mate-grilling/SKILL.md +25 -0
  223. package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +28 -0
  224. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +68 -28
  225. package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +13 -7
  226. package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +1 -1
  227. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +136 -86
  228. package/src/templates/mate-skills/agents/mate-publish-artifact/references/openspec.md +111 -100
  229. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +28 -3
  230. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +39 -5
  231. package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +138 -0
  232. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +84 -28
  233. package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +1 -1
  234. package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +30 -68
  235. package/src/templates/mate-skills/claude/mate-backfill-spec/SKILL.md +23 -1
  236. package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +39 -8
  237. package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +38 -0
  238. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +65 -12
  239. package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +28 -0
  240. package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +28 -0
  241. package/src/templates/mate-skills/claude/mate-grilling/SKILL.md +25 -0
  242. package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +28 -0
  243. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +68 -28
  244. package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +13 -7
  245. package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +1 -1
  246. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +136 -86
  247. package/src/templates/mate-skills/claude/mate-publish-artifact/references/openspec.md +111 -100
  248. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +28 -3
  249. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +39 -5
  250. package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +138 -0
  251. package/src/templates/mate-skills/openspec-references.ts +3 -2
  252. package/src/templates/triage/PLAYBOOK.md +120 -0
  253. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +678 -170
  254. package/src/tools/setup/capabilities/graphify.ts +23 -1
  255. package/src/tools/setup/capabilities/mcp-manager.ts +73 -0
  256. package/src/tools/setup/capabilities/openspec.ts +54 -15
  257. package/src/tools/setup/capabilities/rtk.ts +47 -94
  258. package/src/tools/setup/capabilities/tokensave.ts +79 -56
  259. package/src/tools/setup/context-services.ts +35 -6
  260. package/src/tools/setup/dynamic-plugins/api.ts +38 -0
  261. package/src/tools/setup/dynamic-plugins/audiences.ts +31 -16
  262. package/src/tools/setup/dynamic-plugins/host.ts +2 -32
  263. package/src/tools/setup/dynamic-plugins/hydrate.ts +32 -14
  264. package/src/tools/setup/dynamic-plugins/install.ts +2 -0
  265. package/src/tools/setup/dynamic-plugins/installed.ts +73 -0
  266. package/src/tools/setup/dynamic-plugins/loader.ts +12 -10
  267. package/src/tools/setup/dynamic-plugins/local.ts +492 -0
  268. package/src/tools/setup/dynamic-plugins/paths.ts +34 -6
  269. package/src/tools/setup/dynamic-plugins/verify.ts +34 -14
  270. package/src/tools/setup/dynamic-plugins/workspaces.ts +21 -12
  271. package/src/tools/setup/engine.ts +75 -4
  272. package/src/tools/setup/mate.ts +28 -1
  273. package/src/tools/setup/package-managers/bun.ts +8 -8
  274. package/src/tools/setup/plugin.ts +28 -1
  275. package/src/tools/setup/plugins/gitignore.ts +45 -12
  276. package/src/tools/setup/plugins/guidance.ts +4 -2
  277. package/src/tools/setup/providers/claude-format.ts +39 -2
  278. package/src/tools/setup/providers/claude-plugin-hooks.ts +18 -0
  279. package/src/tools/setup/providers/claude.ts +56 -6
  280. package/src/tools/setup/providers/opencode-format.ts +13 -3
  281. package/src/tools/setup/providers/opencode.ts +7 -18
  282. package/src/tools/setup/providers/relative-path-warnings.ts +26 -0
  283. package/src/tools/setup/service-registry.ts +69 -0
  284. package/src/tools/setup/service.ts +245 -0
  285. package/src/tools/setup/utils.ts +34 -4
  286. package/src/tools/setup.ts +16 -2
  287. package/studio-dist/client/assets/DialogTitle-B_G47-lk.js +1 -0
  288. package/studio-dist/client/assets/app-0NoFqMou.css +2 -0
  289. package/studio-dist/client/assets/button-D_0295cs.js +1 -0
  290. package/studio-dist/client/assets/cn-Cx_D6I3u.js +1 -0
  291. package/studio-dist/client/assets/combobox-D0iPQP50.js +1 -0
  292. package/studio-dist/client/assets/{companion-view-CrabvxS8.js → companion-view-D3A76MLj.js} +1 -1
  293. package/studio-dist/client/assets/fields-Ctheim1h.js +1 -0
  294. package/studio-dist/client/assets/friction-Cn9n_zBA.js +1 -0
  295. package/studio-dist/client/assets/getting-started-DgoVWbWo.js +1 -0
  296. package/studio-dist/client/assets/{getting-started-D6kgWwWZ.js → getting-started-MmLqvy01.js} +1 -1
  297. package/studio-dist/client/assets/getting-started._topic-DBF0khhz.js +1 -0
  298. package/studio-dist/client/assets/getting-started.index-BRdAVqIh.js +1 -0
  299. package/studio-dist/client/assets/graph-BVRdq46V.js +2 -0
  300. package/studio-dist/client/assets/{graph-canvas-Ba37Y5AE.js → graph-canvas-BNzd-eVb.js} +1 -1
  301. package/studio-dist/client/assets/guides-DY1W9LRs.js +1 -0
  302. package/studio-dist/client/assets/index-CuTIc9yd.js +40 -0
  303. package/studio-dist/client/assets/{markdown-view-BOX6x0rL.js → markdown-view-BqZQkk_k.js} +1 -1
  304. package/studio-dist/client/assets/mcp-CIFxmDs0.js +4 -0
  305. package/studio-dist/client/assets/panel-DafanLQ4.js +1 -0
  306. package/studio-dist/client/assets/plugins._service._view-xSRLxHNM.js +1 -0
  307. package/studio-dist/client/assets/prepaint-C--F50QZ.js +27 -0
  308. package/studio-dist/client/assets/{queries-RvHeXY12.js → queries-ByCoiacy.js} +1 -1
  309. package/studio-dist/client/assets/react-BYUSgtBs.js +1 -0
  310. package/studio-dist/client/assets/reports-Diryyked.js +1 -0
  311. package/studio-dist/client/assets/routes-DbRwPd55.js +1 -0
  312. package/studio-dist/client/assets/search-BDKQRwa5.js +1 -0
  313. package/studio-dist/client/assets/select-_9JT3hpU.js +1 -0
  314. package/studio-dist/client/assets/skills-D5a6ybQM.js +1 -0
  315. package/studio-dist/client/assets/{specs-B0ldF_6J.js → specs-COAWUTog.js} +1 -1
  316. package/studio-dist/client/assets/specs-view-9eTn9TcN.js +1 -0
  317. package/studio-dist/client/assets/steps-BS588WAV.js +1 -0
  318. package/studio-dist/client/assets/store-3cffhIO6.js +1 -0
  319. package/studio-dist/client/assets/studio-CG9eioSx.js +100 -0
  320. package/studio-dist/client/assets/studio-queries-BS1yR7Wc.js +2 -0
  321. package/studio-dist/client/assets/{usage-C2QJ_0IZ.js → usage-Ccl4d7w0.js} +15 -15
  322. package/studio-dist/client/assets/useAnchoredPopupScrollLock-D_y83VP7.js +1 -0
  323. package/studio-dist/client/assets/useBlocker-BQOfcu_f.js +1 -0
  324. package/studio-dist/client/assets/useMutation-BDmS2V6y.js +1 -0
  325. package/studio-dist/client/assets/usePopupHandleStore-BcqpNR-F.js +1 -0
  326. package/studio-dist/client/assets/vault-C1tOhQMe.js +1 -0
  327. package/studio-dist/client/assets/warnings-BZ_X1nkO.js +1 -0
  328. package/studio-dist/client/assets/workflow-Cm2fsnly.js +1 -0
  329. package/studio-dist/server/assets/DialogTitle-KSVhF_7V.js +421 -0
  330. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-Bn896ZYj.js → __23tanstack-start-server-fn-resolver-QQnIXyKi.js} +40 -28
  331. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +84 -74
  332. package/studio-dist/server/assets/{button-CgOIVdmD.js → button-C7EMLaX6.js} +229 -5527
  333. package/studio-dist/server/assets/cn-D7uJiH_O.js +5528 -0
  334. package/studio-dist/server/assets/{combobox-DV_s9W0s.js → combobox-Dc4_y20Y.js} +6 -5
  335. package/studio-dist/server/assets/{companion-view-BKVXD3TO.js → companion-view-CrSi37Mb.js} +2 -2
  336. package/studio-dist/server/assets/{companions-C7fctnU9.js → companions-CDSuLqA4.js} +1 -1
  337. package/studio-dist/server/assets/{fields-BbieQTD0.js → fields-BxBN6-Dz.js} +10 -2
  338. package/studio-dist/server/assets/friction-B1K8Kp8r.js +62 -0
  339. package/studio-dist/server/assets/friction-Vl3B6THL.js +943 -0
  340. package/studio-dist/server/assets/{getting-started-CRxMWorQ.js → getting-started-B3lu5W7M.js} +2 -2
  341. package/studio-dist/server/assets/{getting-started._topic-DJKQAzYl.js → getting-started._topic-EYtxZM-Y.js} +2 -2
  342. package/studio-dist/server/assets/{getting-started.index-D84gec1t.js → getting-started.index-CTaXYycH.js} +2 -2
  343. package/studio-dist/server/assets/{graph-DDZzXM1L.js → graph-Bhmk7H8V.js} +1 -1
  344. package/studio-dist/server/assets/{graph-CSje3029.js → graph-D3fXCaKt.js} +8 -8
  345. package/studio-dist/server/assets/{graph-canvas-22bWB5-2.js → graph-canvas-DIvTodML.js} +2 -2
  346. package/studio-dist/server/assets/{guides-IE-19POz.js → guides-BZWFpJl-.js} +1 -1
  347. package/studio-dist/server/assets/{guides-D9dk1Frq.js → guides-CHBkRO6R.js} +1 -1
  348. package/studio-dist/server/assets/{guides.server-vcYRY5wx.js → guides.server-DX9KRkcK.js} +1 -1
  349. package/studio-dist/server/assets/{markdown-view-BR8dJ7aR.js → markdown-view-qrCSkVta.js} +1 -1
  350. package/studio-dist/server/assets/mcp-Ljf4simO.js +1103 -0
  351. package/studio-dist/server/assets/mcp-manager-DohRwmJU.js +50 -0
  352. package/studio-dist/server/assets/{panel-BR_t9iMM.js → panel-CAwz4mKp.js} +6 -4
  353. package/studio-dist/server/assets/plugins._service._view-DUpAo5D_.js +97 -0
  354. package/studio-dist/server/assets/prepaint-BxZ-pU7t.js +45 -0
  355. package/studio-dist/server/assets/{queries-DWoTin-q.js → queries-W4LXzTnT.js} +1 -1
  356. package/studio-dist/server/assets/react-CiBZPDs8.js +45 -0
  357. package/studio-dist/server/assets/{reports-CQ9qQ1-n.js → reports-BVNSPHU3.js} +13 -7
  358. package/studio-dist/server/assets/{reports-dYDEoBeq.js → reports-CGG_wRN5.js} +1 -1
  359. package/studio-dist/server/assets/{router-DkRHNTpE.js → router-KH1x6ryF.js} +1039 -1096
  360. package/studio-dist/server/assets/{routes-B6GfOew4.js → routes-Bl90FC4R.js} +333 -38
  361. package/studio-dist/server/assets/search-BjG5f16n.js +110 -0
  362. package/studio-dist/server/assets/{select-Af7Wibii.js → select-B8q9tLbl.js} +5 -4
  363. package/studio-dist/server/assets/{shell-Hq-hXgnT.js → shell-C5emwofr.js} +12 -3
  364. package/studio-dist/server/assets/{skills-B7nEuVbx.js → skills-10l0eCfP.js} +8 -8
  365. package/studio-dist/server/assets/{skills-B_YYL7q8.js → skills-vG6TTvP1.js} +1 -1
  366. package/studio-dist/server/assets/{specs-BpLUFntA.js → specs-C1P2BEao.js} +4 -4
  367. package/studio-dist/server/assets/{specs-view-0peMVd22.js → specs-view-csUBtMWU.js} +10 -10
  368. package/studio-dist/server/assets/{steps-D56DApvK.js → steps-T4wXftgd.js} +88 -45
  369. package/studio-dist/server/assets/store-CWlRjv9s.js +93 -0
  370. package/studio-dist/server/assets/{studio-CAcKp3bM.js → studio-D-ZPWSMv.js} +1567 -59
  371. package/studio-dist/server/assets/{studio-queries-BtRGzDdh.js → studio-queries-DC273ifg.js} +66 -124
  372. package/studio-dist/server/assets/{usage-COdjd1gD.js → usage-CT3IWLJc.js} +13 -30
  373. package/studio-dist/server/assets/{usage-f6pqE1tm.js → usage-D4t_ibR8.js} +1 -1
  374. package/studio-dist/server/assets/{useAnchoredPopupScrollLock-DlBKHRw7.js → useAnchoredPopupScrollLock-BchJDJYg.js} +2 -2
  375. package/studio-dist/server/assets/useBlocker-CQtANHK8.js +111 -0
  376. package/studio-dist/server/assets/{useMutation-DzTZGenE.js → useMutation-0HbcKUsQ.js} +2 -2
  377. package/studio-dist/server/assets/usePopupHandleStore-B3SNGTic.js +26 -0
  378. package/studio-dist/server/assets/{vault-BDuIUq0F.js → vault-BIytrudF.js} +10 -117
  379. package/studio-dist/server/assets/{vault-BVLp6zu3.js → vault-MINXmyXA.js} +1 -1
  380. package/studio-dist/server/assets/{views-flRUr21z.js → views-DrmY_3J5.js} +7 -4
  381. package/studio-dist/server/assets/{warnings-CDy9pdgL.js → warnings-BVZCDbIz.js} +2 -2
  382. package/studio-dist/server/assets/{workflow-D9GKI2EV.js → workflow-DFdqnMtW.js} +57 -50
  383. package/studio-dist/server/server.js +2 -2
  384. package/tool-manifest.yaml +85 -0
  385. package/src/cli/commands/factory/factory.ts +0 -311
  386. package/src/cli/commands/studio/factory-credential.ts +0 -35
  387. package/src/cli/commands/studio/factory-git-tokens.ts +0 -40
  388. package/src/cli/commands/studio/factory-relay.ts +0 -18
  389. package/src/cli/commands/studio/repository-add.ts +0 -116
  390. package/src/cli/commands/studio/workset-session.ts +0 -164
  391. package/src/lib/delivery/archive-change.ts +0 -165
  392. package/src/lib/delivery/forge.ts +0 -279
  393. package/src/lib/delivery/token.ts +0 -24
  394. package/src/lib/factory/attach-client.ts +0 -123
  395. package/src/lib/factory/attach.ts +0 -178
  396. package/src/lib/factory/broker.ts +0 -187
  397. package/src/lib/factory/bun-commands.ts +0 -39
  398. package/src/lib/factory/client.ts +0 -113
  399. package/src/lib/factory/clone-url.ts +0 -39
  400. package/src/lib/factory/command.ts +0 -77
  401. package/src/lib/factory/credential-store.ts +0 -153
  402. package/src/lib/factory/frames.ts +0 -77
  403. package/src/lib/factory/git-auth.ts +0 -61
  404. package/src/lib/factory/git-credential-store.ts +0 -181
  405. package/src/lib/factory/ids.ts +0 -68
  406. package/src/lib/factory/outcomes/actions.ts +0 -130
  407. package/src/lib/factory/outcomes/index.ts +0 -457
  408. package/src/lib/factory/outcomes/lifecycle.ts +0 -212
  409. package/src/lib/factory/outcomes/runs.ts +0 -81
  410. package/src/lib/factory/prepare.ts +0 -55
  411. package/src/lib/factory/pty.ts +0 -103
  412. package/src/lib/factory/runner/companion-context.ts +0 -178
  413. package/src/lib/factory/runner/control.ts +0 -92
  414. package/src/lib/factory/runner/harness-agent.ts +0 -250
  415. package/src/lib/factory/runner/live.ts +0 -159
  416. package/src/lib/factory/runner/questions.ts +0 -22
  417. package/src/lib/factory/runner/rank.ts +0 -26
  418. package/src/lib/factory/runner/run-policy.ts +0 -12
  419. package/src/lib/factory/runner/run.ts +0 -199
  420. package/src/lib/factory/runner/scheduler.ts +0 -498
  421. package/src/lib/factory/runner/state.ts +0 -233
  422. package/src/lib/factory/runner/workflow.ts +0 -546
  423. package/src/lib/factory/runtime.ts +0 -1081
  424. package/src/lib/factory/sandbox.ts +0 -292
  425. package/src/lib/factory/worktree-branch.ts +0 -17
  426. package/src/templates/capabilities/openspec-cap/mate-v1/templates/explore-brief.md +0 -25
  427. package/studio-dist/client/assets/app-D9cw6szy.css +0 -2
  428. package/studio-dist/client/assets/artifacts-WD2ZXYrx.js +0 -1
  429. package/studio-dist/client/assets/button-Br0O1sXw.js +0 -1
  430. package/studio-dist/client/assets/combobox-DA7RAUUZ.js +0 -1
  431. package/studio-dist/client/assets/factory-DGS0E16C.js +0 -6
  432. package/studio-dist/client/assets/fields-6aXBpFhJ.js +0 -1
  433. package/studio-dist/client/assets/getting-started-Clde4w6P.js +0 -1
  434. package/studio-dist/client/assets/getting-started._topic-BiunccbT.js +0 -1
  435. package/studio-dist/client/assets/getting-started.index-DpiNoGw8.js +0 -1
  436. package/studio-dist/client/assets/graph-B_TCBVbu.js +0 -2
  437. package/studio-dist/client/assets/guides-Du_RtJxP.js +0 -1
  438. package/studio-dist/client/assets/index-Df8L1LQa.js +0 -40
  439. package/studio-dist/client/assets/panel-dbmCx7Mx.js +0 -1
  440. package/studio-dist/client/assets/react-3QStrcDO.js +0 -27
  441. package/studio-dist/client/assets/report-url-XRL0x1SY.js +0 -1
  442. package/studio-dist/client/assets/reports-r3IK7Doz.js +0 -1
  443. package/studio-dist/client/assets/routes-C0A5LTFc.js +0 -1
  444. package/studio-dist/client/assets/select-CnaMd617.js +0 -1
  445. package/studio-dist/client/assets/skills-CzjzHpBT.js +0 -1
  446. package/studio-dist/client/assets/specs-view-BnCLA0gW.js +0 -1
  447. package/studio-dist/client/assets/spinner-Dcm3fqK1.js +0 -1
  448. package/studio-dist/client/assets/steps-C0p2N1Pb.js +0 -1
  449. package/studio-dist/client/assets/store-Dw34catY.js +0 -1
  450. package/studio-dist/client/assets/studio-Cpz_HRHp.js +0 -100
  451. package/studio-dist/client/assets/studio-queries-ibmpFo6R.js +0 -2
  452. package/studio-dist/client/assets/useAnchoredPopupScrollLock-Bj-FWb8z.js +0 -1
  453. package/studio-dist/client/assets/useMutation-aAr2uiay.js +0 -1
  454. package/studio-dist/client/assets/vault-BGcxkSIY.js +0 -1
  455. package/studio-dist/client/assets/warnings-R1cE1rLf.js +0 -1
  456. package/studio-dist/client/assets/workflow-C2qTrMDH.js +0 -1
  457. package/studio-dist/server/assets/actions-DYSv-9VV.js +0 -60
  458. package/studio-dist/server/assets/artifacts-DnF9L3dZ.js +0 -216
  459. package/studio-dist/server/assets/factory-C7Ybg0xG.js +0 -3075
  460. package/studio-dist/server/assets/factory-Df5uAHjb.js +0 -116
  461. package/studio-dist/server/assets/react-CdqSUhaL.js +0 -89
  462. package/studio-dist/server/assets/report-url-BUXPcE_8.js +0 -9
  463. package/studio-dist/server/assets/search-BJnWLfkG.js +0 -55
  464. package/studio-dist/server/assets/spinner-CdwJW4VB.js +0 -20
  465. package/studio-dist/server/assets/store-Cs17okNG.js +0 -280
  466. /package/src/lib/{factory/keyed-serial.ts → keyed-serial.ts} +0 -0
  467. /package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/spec.md +0 -0
@@ -11,7 +11,7 @@
11
11
  * Every write is best-effort. An unwritable record degrades to "a
12
12
  * synchronization is due", which is the safe direction.
13
13
  */
14
- import { createHash } from "node:crypto";
14
+ import { createHash, randomUUID } from "node:crypto";
15
15
  import fs from "node:fs";
16
16
  import os from "node:os";
17
17
  import path from "node:path";
@@ -30,11 +30,22 @@ export interface CompanionForkRecord {
30
30
  checkedAt: string;
31
31
  }
32
32
 
33
+ /** A change folder this checkout submitted, as it was pushed. */
34
+ export interface SubmittedFolder {
35
+ /** SHA-256 over the folder's relative file paths and contents. */
36
+ digest: string;
37
+ /** The same without the Delivery Record; absent on a record of an earlier Mate. */
38
+ content?: string;
39
+ submittedAt: string;
40
+ }
41
+
33
42
  export interface CompanionGitRecord {
34
43
  syncedAt?: string;
35
44
  /** Set while the last unattended run left work for a human; cleared on completion. */
36
45
  unfinishedReason?: string;
37
46
  fork?: CompanionForkRecord;
47
+ /** Change folders this checkout submitted, by companion-relative path. */
48
+ submitted?: Record<string, SubmittedFolder>;
38
49
  }
39
50
 
40
51
  /** `HOME` first, matching the guard: a projected hook runs with whatever the session set. */
@@ -73,20 +84,122 @@ export function readCompanionGitRecord(
73
84
  }
74
85
  }
75
86
 
76
- /** Best-effort: a failure to record never fails its caller. */
87
+ /**
88
+ * Best-effort: a failure to record never fails its caller. Written to a temporary file and
89
+ * renamed, so a concurrent reader never sees a partial record.
90
+ */
77
91
  export function writeCompanionGitRecord(
78
92
  companionPath: string,
79
93
  record: CompanionGitRecord,
80
94
  homeDir?: string,
81
95
  ): boolean {
82
96
  const target = companionGitStatePath(companionPath, homeDir);
97
+ const temporary = `${target}.${process.pid}.tmp`;
83
98
  try {
84
99
  fs.mkdirSync(path.dirname(target), { recursive: true });
85
- fs.writeFileSync(target, `${JSON.stringify(record, null, 2)}\n`, "utf8");
100
+ fs.writeFileSync(temporary, `${JSON.stringify(record, null, 2)}\n`, "utf8");
101
+ fs.renameSync(temporary, target);
86
102
  return true;
87
103
  } catch {
104
+ fs.rmSync(temporary, { force: true });
105
+ return false;
106
+ }
107
+ }
108
+
109
+ /** A lock older than this was left by a writer that died holding it. */
110
+ const LOCK_STALE_MS = 10_000;
111
+ /** How long a writer waits for the lock before it writes unlocked. */
112
+ const LOCK_WAIT_MS = 2_000;
113
+
114
+ function sleepSync(ms: number): void {
115
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
116
+ }
117
+
118
+ /**
119
+ * Takes the record's lock file and returns its token, unique so it tells this lock apart
120
+ * from one taken after it; null when it cannot within {@link LOCK_WAIT_MS}.
121
+ */
122
+ function acquireLock(lock: string): string | null {
123
+ const giveUpAt = Date.now() + LOCK_WAIT_MS;
124
+ const token = `${process.pid} ${randomUUID()}`;
125
+ for (;;) {
126
+ try {
127
+ fs.mkdirSync(path.dirname(lock), { recursive: true });
128
+ fs.writeFileSync(lock, token, { flag: "wx" });
129
+ return token;
130
+ } catch (error) {
131
+ if ((error as NodeJS.ErrnoException).code !== "EEXIST") return null;
132
+ }
133
+ if (breakStaleLock(lock)) continue;
134
+ if (Date.now() >= giveUpAt) return null;
135
+ sleepSync(20);
136
+ }
137
+ }
138
+
139
+ function readLockToken(lock: string): string | null {
140
+ try {
141
+ return fs.readFileSync(lock, "utf8");
142
+ } catch {
143
+ return null;
144
+ }
145
+ }
146
+
147
+ /** A lock file left longer than {@link LOCK_STALE_MS}; never a directory or other entry. */
148
+ function isStale(file: string): boolean {
149
+ try {
150
+ const stat = fs.statSync(file);
151
+ return stat.isFile() && Date.now() - stat.mtimeMs > LOCK_STALE_MS;
152
+ } catch {
153
+ // Gone meanwhile, or unreadable; waiting decides.
154
+ return false;
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Removes `lock` when a dead writer left it; true when it did. Breakers take `<lock>.break`
160
+ * first, so only one checks and removes at a time and none can delete a lock another breaker
161
+ * let a waiter retake. A breaker that died holding it is removed once stale.
162
+ */
163
+ function breakStaleLock(lock: string): boolean {
164
+ if (!isStale(lock)) return false;
165
+ const breaker = `${lock}.break`;
166
+ try {
167
+ fs.writeFileSync(breaker, "", { flag: "wx" });
168
+ } catch {
169
+ if (isStale(breaker)) fs.rmSync(breaker, { force: true });
88
170
  return false;
89
171
  }
172
+ try {
173
+ if (!isStale(lock)) return false;
174
+ fs.rmSync(lock, { force: true });
175
+ return true;
176
+ } finally {
177
+ fs.rmSync(breaker, { force: true });
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Reads the record, applies `update` and writes the result under the record's lock, so
183
+ * concurrent sessions never drop each other's fields. Writes unlocked when the lock stays
184
+ * taken, as best-effort bookkeeping should.
185
+ */
186
+ function updateCompanionGitRecord(
187
+ companionPath: string,
188
+ update: (record: CompanionGitRecord) => CompanionGitRecord,
189
+ homeDir?: string,
190
+ ): boolean {
191
+ const lock = `${companionGitStatePath(companionPath, homeDir)}.lock`;
192
+ const token = acquireLock(lock);
193
+ try {
194
+ return writeCompanionGitRecord(
195
+ companionPath,
196
+ update(readCompanionGitRecord(companionPath, homeDir)),
197
+ homeDir,
198
+ );
199
+ } finally {
200
+ // Only its own: a lock held past the stale age may have been broken and retaken.
201
+ if (token !== null && readLockToken(lock) === token) fs.rmSync(lock, { force: true });
202
+ }
90
203
  }
91
204
 
92
205
  export function recordCompanionSync(
@@ -94,8 +207,11 @@ export function recordCompanionSync(
94
207
  at: Date = new Date(),
95
208
  homeDir?: string,
96
209
  ): boolean {
97
- const { unfinishedReason: _cleared, ...record } = readCompanionGitRecord(companionPath, homeDir);
98
- return writeCompanionGitRecord(companionPath, { ...record, syncedAt: at.toISOString() }, homeDir);
210
+ return updateCompanionGitRecord(
211
+ companionPath,
212
+ ({ unfinishedReason: _cleared, ...record }) => ({ ...record, syncedAt: at.toISOString() }),
213
+ homeDir,
214
+ );
99
215
  }
100
216
 
101
217
  /**
@@ -109,8 +225,11 @@ export function recordCompanionSyncUnfinished(
109
225
  reason: string,
110
226
  homeDir?: string,
111
227
  ): boolean {
112
- const { syncedAt: _stale, ...record } = readCompanionGitRecord(companionPath, homeDir);
113
- return writeCompanionGitRecord(companionPath, { ...record, unfinishedReason: reason }, homeDir);
228
+ return updateCompanionGitRecord(
229
+ companionPath,
230
+ ({ syncedAt: _stale, ...record }) => ({ ...record, unfinishedReason: reason }),
231
+ homeDir,
232
+ );
114
233
  }
115
234
 
116
235
  function withinInterval(stamp: string | undefined, intervalMs: number, now: Date): boolean {
@@ -147,10 +266,36 @@ export function recordForkVerdict(
147
266
  at: Date = new Date(),
148
267
  homeDir?: string,
149
268
  ): boolean {
150
- const record = readCompanionGitRecord(companionPath, homeDir);
151
- return writeCompanionGitRecord(
269
+ return updateCompanionGitRecord(
270
+ companionPath,
271
+ (record) => ({ ...record, fork: { ...verdict, checkedAt: at.toISOString() } }),
272
+ homeDir,
273
+ );
274
+ }
275
+
276
+ /** The change folders this checkout submitted, by companion-relative path. */
277
+ export function readSubmittedFolders(
278
+ companionPath: string,
279
+ homeDir?: string,
280
+ ): Record<string, SubmittedFolder> {
281
+ const submitted = readCompanionGitRecord(companionPath, homeDir).submitted;
282
+ return submitted && typeof submitted === "object" ? submitted : {};
283
+ }
284
+
285
+ /** Records `folders` as submitted from this checkout and forgets `forget`; best effort. */
286
+ export function updateSubmittedFolders(
287
+ companionPath: string,
288
+ folders: Record<string, SubmittedFolder>,
289
+ forget: readonly string[] = [],
290
+ homeDir?: string,
291
+ ): boolean {
292
+ return updateCompanionGitRecord(
152
293
  companionPath,
153
- { ...record, fork: { ...verdict, checkedAt: at.toISOString() } },
294
+ (record) => {
295
+ const submitted = { ...record.submitted, ...folders };
296
+ for (const folder of forget) delete submitted[folder];
297
+ return { ...record, submitted };
298
+ },
154
299
  homeDir,
155
300
  );
156
301
  }
@@ -33,6 +33,42 @@ export function outputLines(stdout: string): string[] {
33
33
  .filter(Boolean);
34
34
  }
35
35
 
36
+ /**
37
+ * Blob contents by spec from the output of `git cat-file --batch` fed `specs`, one per line.
38
+ * Per spec, in order: `<oid> <type> <size>\n<contents>\n`, or `<spec> missing\n`; missing
39
+ * and non-blob objects are left out. Null when the output is cut off or malformed.
40
+ */
41
+ export function parseBlobBatch(out: Buffer, specs: readonly string[]): Map<string, string> | null {
42
+ const blobs = new Map<string, string>();
43
+ let offset = 0;
44
+ for (const spec of specs) {
45
+ const end = out.indexOf(10, offset);
46
+ if (end < 0) return null;
47
+ const line = out.subarray(offset, end).toString("utf8");
48
+ offset = end + 1;
49
+ // The spec is echoed, spaces and all, so these are read off the end.
50
+ if (line.endsWith(" missing") || line.endsWith(" ambiguous")) continue;
51
+ const header = line.split(" ");
52
+ if (header.length !== 3) continue;
53
+ const size = Number(header[2]);
54
+ if (!Number.isInteger(size) || offset + size > out.length) return null;
55
+ if (header[1] === "blob") blobs.set(spec, out.subarray(offset, offset + size).toString("utf8"));
56
+ offset += size + 1;
57
+ }
58
+ return blobs;
59
+ }
60
+
61
+ /** Paths of a `-z` listing, unquoted, so a non-ASCII path survives. */
62
+ export function nulPaths(stdout: string): string[] {
63
+ return stdout.split("\0").filter(Boolean);
64
+ }
65
+
66
+ /**
67
+ * Git option that reads pathspecs as plain paths. A change name may hold `*`, `?` or `[`, and
68
+ * on the inbox it is a teammate's: as a pattern it would match other changes' folders.
69
+ */
70
+ export const LITERAL_PATHSPECS: readonly string[] = ["--literal-pathspecs"];
71
+
36
72
  /** Matches Git progress-meter lines such as `Updating files: 76% (11340/14790)` or `..., done.` */
37
73
  const GIT_PROGRESS_LINE = /^\S.*?: +\d+% \(\d+\/\d+\)(?:, done\.)?$/;
38
74
 
@@ -184,10 +220,15 @@ export interface CompanionGitOptions {
184
220
  export interface CompanionGit {
185
221
  /** Local command, captured. */
186
222
  run(args: readonly string[]): Promise<GitResult>;
223
+ /**
224
+ * Contents of the blobs `ids` by id, decoded as text, read in one `git cat-file --batch`
225
+ * however many there are. Ids that name no blob are left out; null when the command fails.
226
+ */
227
+ readBlobs(ids: readonly string[]): Promise<Map<string, string> | null>;
187
228
  /** `git fetch <args>`, SSH first for HTTP(S) remotes. */
188
229
  fetch(args?: readonly string[]): Promise<NetworkGitResult>;
189
- /** `git push <args>`, SSH first for HTTP(S) remotes. */
190
- push(args?: readonly string[]): Promise<NetworkGitResult>;
230
+ /** `git <gitOptions> push <args>`, SSH first for HTTP(S) remotes. */
231
+ push(args?: readonly string[], gitOptions?: readonly string[]): Promise<NetworkGitResult>;
191
232
  /** Clones `url` into `destination` (relative to the operation's directory), SSH first for HTTP(S). */
192
233
  clone(url: string, destination: string, options?: { branch?: string }): Promise<NetworkGitResult>;
193
234
  upstreamTarget(): Promise<UpstreamTarget | null>;
@@ -226,14 +267,15 @@ function spawnGit(
226
267
  cwd: string,
227
268
  args: readonly string[],
228
269
  env: Record<string, string | undefined>,
229
- options: { interactive: boolean; timeoutMs?: number },
230
- ): Promise<GitResult> {
270
+ options: { interactive: boolean; timeoutMs?: number; input?: string },
271
+ ): Promise<GitResult & { bytes?: Buffer }> {
231
272
  return new Promise((resolve) => {
232
273
  let settled = false;
233
274
  let timer: ReturnType<typeof setTimeout> | undefined;
234
275
  const stdout: Buffer[] = [];
235
276
  const stderr: Buffer[] = [];
236
- const finish = (result: GitResult) => {
277
+ const piped = options.input !== undefined;
278
+ const finish = (result: GitResult & { bytes?: Buffer }) => {
237
279
  if (settled) return;
238
280
  settled = true;
239
281
  if (timer) clearTimeout(timer);
@@ -246,7 +288,9 @@ function spawnGit(
246
288
  cwd,
247
289
  env,
248
290
  /** Interactive output goes to stderr so a caller's stdout (e.g. `--json`) stays clean. */
249
- stdio: options.interactive ? ["inherit", 2, "inherit"] : ["ignore", "pipe", "pipe"],
291
+ stdio: options.interactive
292
+ ? ["inherit", 2, "inherit"]
293
+ : [piped ? "pipe" : "ignore", "pipe", "pipe"],
250
294
  });
251
295
  } catch (error) {
252
296
  finish({ status: 1, stdout: "", stderr: (error as Error).message });
@@ -256,8 +300,18 @@ function spawnGit(
256
300
  child.stderr?.on("data", (chunk: Buffer) => stderr.push(chunk));
257
301
  child.once("error", (error) => finish({ status: 1, stdout: "", stderr: error.message }));
258
302
  child.once("close", (status) =>
259
- finish({ status: status ?? 1, stdout: decode(stdout), stderr: decode(stderr) }),
303
+ finish({
304
+ status: status ?? 1,
305
+ // Byte offsets matter to a caller that pipes input; the others read text.
306
+ ...(piped ? { stdout: "", bytes: Buffer.concat(stdout) } : { stdout: decode(stdout) }),
307
+ stderr: decode(stderr),
308
+ }),
260
309
  );
310
+ if (piped) {
311
+ // A command that exits early closes the pipe; its status reports the failure.
312
+ child.stdin?.on("error", () => {});
313
+ child.stdin?.end(options.input);
314
+ }
261
315
  if (options.timeoutMs !== undefined) {
262
316
  /** Resolved without awaiting `close`: an SSH grandchild may hold the pipes open. */
263
317
  timer = setTimeout(
@@ -313,6 +367,8 @@ export function companionGit(
313
367
  ): CompanionGit {
314
368
  const baseEnv: Record<string, string | undefined> = {
315
369
  ...gitEnvironment(options.env ?? process.env),
370
+ // Failures are told apart by Git's English messages.
371
+ LC_ALL: "C",
316
372
  ...(options.indexFile ? { GIT_INDEX_FILE: options.indexFile } : {}),
317
373
  };
318
374
  const mayPrompt = options.prompt === "if-terminal" && deps.isTerminal();
@@ -327,8 +383,12 @@ export function companionGit(
327
383
  async function exec(
328
384
  args: readonly string[],
329
385
  env: Record<string, string | undefined>,
330
- { interactive = false, capMs }: { interactive?: boolean; capMs?: number } = {},
331
- ): Promise<GitResult> {
386
+ {
387
+ interactive = false,
388
+ capMs,
389
+ input,
390
+ }: { interactive?: boolean; capMs?: number; input?: string } = {},
391
+ ): Promise<GitResult & { bytes?: Buffer }> {
332
392
  const remaining = deadline - Date.now();
333
393
  if (remaining <= 0) {
334
394
  return {
@@ -342,11 +402,24 @@ export function companionGit(
342
402
  return spawnGit(cwd, args, env, {
343
403
  interactive,
344
404
  timeoutMs: Number.isFinite(timeoutMs) ? timeoutMs : undefined,
405
+ ...(input === undefined ? {} : { input }),
345
406
  });
346
407
  }
347
408
 
348
409
  const run = (args: readonly string[]) => exec(args, capturedEnv, { capMs: options.commandCapMs });
349
410
 
411
+ async function readBlobs(ids: readonly string[]): Promise<Map<string, string> | null> {
412
+ const blobs = new Map<string, string>();
413
+ if (ids.length === 0) return blobs;
414
+ const result = await exec(["cat-file", "--batch"], capturedEnv, {
415
+ capMs: options.commandCapMs,
416
+ input: `${ids.join("\n")}\n`,
417
+ });
418
+ const out = result.bytes;
419
+ if (result.status !== 0 || !out) return null;
420
+ return parseBlobBatch(out, ids);
421
+ }
422
+
350
423
  /**
351
424
  * `never` appends `BatchMode=yes` to the SSH command Git would use anyway
352
425
  * (`GIT_SSH_COMMAND`, `GIT_SSH`, `core.sshCommand`, then `ssh`), so SSH
@@ -405,8 +478,9 @@ export function companionGit(
405
478
 
406
479
  return {
407
480
  run,
481
+ readBlobs,
408
482
  fetch: (args = []) => remoteNetwork(["fetch", ...args]),
409
- push: (args = []) => remoteNetwork(["push", ...args]),
483
+ push: (args = [], gitOptions = []) => remoteNetwork([...gitOptions, "push", ...args]),
410
484
  async clone(url, destination, { branch } = {}) {
411
485
  const cloneArgs = ["clone", ...(branch ? ["--branch", branch] : []), url, destination];
412
486
  const ssh = toSshUrl(url);
@@ -432,7 +506,8 @@ export function companionGit(
432
506
  };
433
507
  }
434
508
 
435
- function parseRemoteRef(stdout: string): UpstreamTarget | undefined {
509
+ /** `remote/branch` as an upstream target; undefined when it has no `/`. */
510
+ export function parseRemoteRef(stdout: string): UpstreamTarget | undefined {
436
511
  const ref = stdout.trim();
437
512
  const separator = ref.indexOf("/");
438
513
  if (separator <= 0 || separator === ref.length - 1) return undefined;
@@ -1,7 +1,10 @@
1
1
  import path from "node:path";
2
2
 
3
3
  import { FRAMEWORK_NAME } from "./framework";
4
+ import { REPORT_KINDS } from "./friction-vocabulary";
4
5
  import { GUIDANCE_FILE_VERSION, type MateGuidanceFile } from "./guidance";
6
+ import { readWorkflow } from "./workflow/declaration";
7
+ import type { DeclaredArtifactType } from "./workflow/workflow";
5
8
 
6
9
  /**
7
10
  * The guidance builders, on the session-runtime side of core.
@@ -32,10 +35,92 @@ export interface GuidanceContext {
32
35
  * a caller that cannot tell never drops the rule.
33
36
  */
34
37
  secretGuardrails?: boolean;
38
+ /** The artifact types the companion's workflow declares; each gets its reading rule. */
39
+ artifactTypes?: readonly GuidanceArtifactType[];
40
+ /** The skill stages the companion declares; absent when it declares none. */
41
+ stages?: readonly GuidanceStage[];
42
+ }
43
+
44
+ /** The paths of a declared artifact type its reading rule is built from. */
45
+ export type GuidanceArtifactType = Pick<
46
+ DeclaredArtifactType,
47
+ "name" | "change" | "published" | "archive"
48
+ >;
49
+
50
+ /** A declared stage as the rule names it: its id, its skills in order, or that people review. */
51
+ export interface GuidanceStage {
52
+ id: string;
53
+ steps: string[];
54
+ review?: true;
55
+ optional?: true;
56
+ }
57
+
58
+ export interface DeclaredGuidance {
59
+ artifactTypes: GuidanceArtifactType[];
60
+ stages?: GuidanceStage[];
61
+ }
62
+
63
+ /**
64
+ * What `companionPath`'s workflow adds to the guidance: its artifact types, and its declared
65
+ * stages when one runs a skill of the companion's own; Mate's stage skills report themselves, so
66
+ * a path of those alone needs no rule. An invalid declaration adds nothing, which keeps the
67
+ * built-in rules alone; the session banner names its problems.
68
+ */
69
+ export function declaredGuidance(companionPath: string): DeclaredGuidance {
70
+ const verdict = readWorkflow(companionPath);
71
+ if (!verdict.ok) return { artifactTypes: [] };
72
+ const { artifacts, stages } = verdict.workflow;
73
+ const ownSkills = stages.some(
74
+ (stage) => stage.kind === "skill" && stage.steps.some((step) => !step.own),
75
+ );
76
+ if (!ownSkills) return { artifactTypes: artifacts };
77
+ return {
78
+ artifactTypes: artifacts,
79
+ stages: stages.map((stage) => ({
80
+ id: stage.id,
81
+ steps: stage.kind === "skill" ? stage.steps.map((step) => step.skill) : [],
82
+ ...(stage.kind === "review" ? { review: true as const } : {}),
83
+ ...(stage.optional ? { optional: true as const } : {}),
84
+ })),
85
+ };
86
+ }
87
+
88
+ /**
89
+ * The declared Delivery Path, and the one thing a skill its author wrote does not do: report
90
+ * itself. Everything else, change or none, comes from what `workflow done` prints.
91
+ */
92
+ function stagesRule(stages: readonly GuidanceStage[]): string {
93
+ const order = stages
94
+ .map((stage) => {
95
+ const what = stage.review ? "reviewed by people" : stage.steps.join(", then ");
96
+ return `${stage.id} (${what}${stage.optional ? ", optional" : ""})`;
97
+ })
98
+ .join("; ");
99
+ return ` <rule id="workflow-stages" severity="critical">This companion's Delivery Path, declared in .mate/config/workflow.yaml, in order: ${order}. When one of these skills finishes without running ${FRAMEWORK_NAME} workflow done itself, run ${FRAMEWORK_NAME} workflow done "<skill>", adding the change name when there is one, and end your response with a final "## Next steps" section listing the actions it prints, running none of them.</rule>`;
100
+ }
101
+
102
+ /** `notes/{name}/` → `notes/`. */
103
+ const folderOf = (template: string): string => template.replace(/\{[a-z]+\}\/?$/, "");
104
+
105
+ /**
106
+ * What agents read as current for a declared type, on the model of the built-in
107
+ * `openspec-publish` rule. Its submitted folders have no `touches`, so one is read only when named.
108
+ */
109
+ function artifactTypeRule(type: GuidanceArtifactType): string {
110
+ const history = type.archive ? ` ${folderOf(type.archive)} is history.` : "";
111
+ return ` <rule id="artifact-${type.name}" severity="critical">${type.name}: ${type.published.join(", ")} is current. A submitted folder under ${folderOf(type.change)} is not the truth until publication lands it on the companion's default branch and is never current: read one only when the user names it, and revise one only when named (${FRAMEWORK_NAME} artifact take "<name>" when it is missing, then resubmit).${history}</rule>`;
35
112
  }
36
113
 
37
114
  const SECRET_HANDLING_RULE = ` <rule id="secret-handling" severity="critical">Never read, print, copy, or write secret files (.env, .env.*, keys, certificates, credential files such as .npmrc or .netrc) or secret values. To learn which variables exist, read only the example files (.env.example, .env.sample, .env.template, .env.dist). Refer to a secret by its variable name only. Do not print environment variables that may hold secrets. When a secret must be set or rotated, ask the user to do it instead of writing it yourself. Guarded calls are blocked; the companion's framework.yaml secrets block is the user's switch, not yours.</rule>`;
38
115
 
116
+ export const FRICTION_GUIDANCE = `## Friction
117
+
118
+ When ${FRAMEWORK_NAME} gets in your way without a refusal or error to point at, such as a skill step that does not fit or missing guidance, record it when it happens: \`${FRAMEWORK_NAME} friction report --kind <${REPORT_KINDS.join("|")}> --subject <type>:<name> --expected "<what you expected>" --evidence "<what you saw>"\`. Record one report per problem, then keep working on your task. When nothing went wrong, record nothing.`;
119
+
120
+ function withFriction(policy: string, friction: boolean | undefined): string {
121
+ return friction ? `${policy}\n\n${FRICTION_GUIDANCE}` : policy;
122
+ }
123
+
39
124
  export function hasGraphifyCapability(capabilities: GuidanceCapability[] = []): boolean {
40
125
  return capabilities.some((capability) => capability.name === "graphify");
41
126
  }
@@ -160,9 +245,8 @@ export function buildCompanionPolicyXml(
160
245
  lines.splice(
161
246
  lines.indexOf(" </mandatory-rules>"),
162
247
  0,
163
- ` <rule id="artifact-location" severity="critical">Agent artifacts MUST go to ${context.companionPath}, NEVER ${context.repository.path}. Artifacts include plans, specs, ADRs, todos, notes, handoffs, reasoning docs, and scratch files.</rule>`,
248
+ ` <rule id="artifact-location" severity="critical">Agent artifacts MUST go to ${context.companionPath}, NEVER ${context.repository.path}, which holds product code (README, docs, source, tests). Artifacts include plans, specs, ADRs, todos, notes, handoffs, reasoning docs, and scratch files.</rule>`,
164
249
  ` <rule id="pre-write-classification" severity="critical">Before ANY write, classify the target as product-code or agent-artifact. If unsure, treat it as agent-artifact.</rule>`,
165
- ` <rule id="product-code-location" severity="critical">Product code (README, docs, source, tests) belongs in the working-repository path; agent artifacts in the companion-repository path.</rule>`,
166
250
  ` <rule id="local-artifact-exception" severity="critical">Write an artifact in the working repository only when its exact path is gitignored AND intentionally local-only.</rule>`,
167
251
  ` <rule id="guardrail" severity="critical">Bad artifact writes to the working repository are rejected. The guardrail resolves relative paths against ${context.repository.path} and does not follow cd, so write artifacts, including shell redirects and tee, with absolute paths under ${context.companionPath}.</rule>`,
168
252
  ` <rule id="companion-multi-repository" severity="critical">This Companion Repository may serve multiple Working Repositories; the working-repository path is this session's single primary Working Repository (the product-code plane), not the full set. The Companion Repository is the shared artifact and context plane.</rule>`,
@@ -189,10 +273,14 @@ export function buildCompanionPolicyXml(
189
273
  if (hasOpenspecCapability(context.capabilities)) {
190
274
  lines.push(
191
275
  ` <rule id="openspec-scope" severity="critical">In OpenSpec, the frontmatter repository identifies the Working Repository; areas are repository-relative paths within that repository. Canonical specs use repository plus flat areas; change artifacts use paired scopes entries. In a monorepo, an Area normally stops at the package root. A cross-repository change may declare multiple scopes, but each resulting spec remains owned by one repository, and each requirement must bind its Area explicitly.</rule>`,
192
- ` <rule id="openspec-publish" severity="critical">Archiving an OpenSpec change is local and publishes nothing. Publish only through the mate-publish-artifact skill, whose sanctioned command is ${FRAMEWORK_NAME} artifact publish "<name>" --json: only after an explicit user selection and confirmation of the commit, tag, and push, and only for an archive whose delivery branch is merged; never hand-commit or hand-tag one. Publish never archives and never applies delta specs itself: archiving is a precondition (mate-archive-change, allowed before the merge), and publishing a still-active change is an error. Publish refuses to run anywhere but the companion's default branch.</rule>`,
276
+ ` <rule id="openspec-publish" severity="critical">Submit publishes nothing: it pushes an OpenSpec change folder (state: submitted) to the inbox mate/inbox to await its merge. A submitted change is not the truth: only publication lands it on the companion's default branch. openspec/specs/ is current; ${FRAMEWORK_NAME} artifact project "<name>" shows the unpublished outcome. ${FRAMEWORK_NAME} artifact pending --json --no-merge-check lists them with author, touched requirements, ref and path; read one (git show <ref>:<path>/<file>) only where it touches your work or the user names it; implement or revise one only when the user names it: ${FRAMEWORK_NAME} artifact take "<name>" brings it into the checkout when it is missing there, then resubmit it with mate-submit-change. Publish only through mate-publish-artifact (${FRAMEWORK_NAME} artifact publish "<name>" --json), after the user selects and confirms the commit and push, for a Delivery Group whose delivery branch is merged. It creates no tag. Never hand-commit or hand-tag one. Publish archives submitted changes and never submits: submitting is a precondition (mate-submit-change, before the merge).</rule>`,
193
277
  );
194
278
  }
195
279
 
280
+ for (const type of context.artifactTypes ?? []) lines.push(artifactTypeRule(type));
281
+
282
+ if (context.stages?.length) lines.push(stagesRule(context.stages));
283
+
196
284
  if (options.enteredWorktreeGit && hasRtkCapability(context.capabilities)) {
197
285
  lines.push(ENTERED_WORKTREE_GIT_RULE);
198
286
  }
@@ -205,17 +293,21 @@ export function buildCompanionPolicyXml(
205
293
  }
206
294
 
207
295
  /**
208
- * Build the merged single-string guidance: the companion-policy XML plus
209
- * codebase-exploration guidance appended when graphify or tokensave is
210
- * enabled. Used by providers (e.g. Claude) that inject one combined prompt
296
+ * Build the merged single-string guidance: the companion-policy XML, the
297
+ * friction section while the Friction Switch is on, and codebase-exploration
298
+ * guidance appended when graphify or tokensave is enabled. Used by providers (e.g. Claude) that inject one combined prompt
211
299
  * fragment rather than delivering exploration guidance separately; only that
212
300
  * form carries the Claude-only `entered-worktree-git` rule.
213
301
  */
214
302
  export function buildCompanionGuidance(
215
303
  context: GuidanceContext,
216
- options: { wrapperBinPath: string },
304
+ options: { wrapperBinPath: string; friction?: boolean },
217
305
  ): string {
218
- const lines = [buildCompanionPolicyXml(context, { ...options, enteredWorktreeGit: true })];
306
+ const policy = buildCompanionPolicyXml(context, {
307
+ wrapperBinPath: options.wrapperBinPath,
308
+ enteredWorktreeGit: true,
309
+ });
310
+ const lines = [withFriction(policy, options.friction)];
219
311
 
220
312
  const graphifyEnabled = hasGraphifyCapability(context.capabilities);
221
313
  const tokensaveEnabled = hasTokensaveCapability(context.capabilities);
@@ -249,19 +341,30 @@ export function buildCompanionGuidance(
249
341
  */
250
342
  export function buildOpenCodeGuidance(
251
343
  capabilities: GuidanceCapability[],
252
- options: { companionScoped?: boolean; secretGuardrails?: boolean } = {},
344
+ options: {
345
+ companionScoped?: boolean;
346
+ secretGuardrails?: boolean;
347
+ friction?: boolean;
348
+ artifactTypes?: readonly GuidanceArtifactType[];
349
+ stages?: readonly GuidanceStage[];
350
+ } = {},
253
351
  ): MateGuidanceFile {
254
352
  const repository = options.companionScoped
255
353
  ? undefined
256
354
  : { id: "$MATE_REPO_ID", path: "$MATE_REPO_PATH" };
257
- const companionGuidance = buildCompanionPolicyXml(
258
- {
259
- companionPath: "$MATE_ARTIFACT_PATH",
260
- repository,
261
- capabilities,
262
- secretGuardrails: options.secretGuardrails,
263
- },
264
- { wrapperBinPath: "$MATE_WRAPPER_BIN_PATH" },
355
+ const companionGuidance = withFriction(
356
+ buildCompanionPolicyXml(
357
+ {
358
+ companionPath: "$MATE_ARTIFACT_PATH",
359
+ repository,
360
+ capabilities,
361
+ secretGuardrails: options.secretGuardrails,
362
+ ...(options.artifactTypes ? { artifactTypes: options.artifactTypes } : {}),
363
+ ...(options.stages ? { stages: options.stages } : {}),
364
+ },
365
+ { wrapperBinPath: "$MATE_WRAPPER_BIN_PATH" },
366
+ ),
367
+ options.friction,
265
368
  );
266
369
  const graphifyEnabled = hasGraphifyCapability(capabilities);
267
370
  const tokensaveEnabled = hasTokensaveCapability(capabilities);
@@ -183,7 +183,7 @@ function segment(
183
183
  ];
184
184
  }
185
185
 
186
- function escapeAttribute(value: string): string {
186
+ export function escapeAttribute(value: string): string {
187
187
  return value.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;");
188
188
  }
189
189