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

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 (249) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
  2. package/package.json +6 -3
  3. package/src/cli/commands/artifact/delivery/submit.ts +6 -4
  4. package/src/cli/commands/artifact/finish/command.ts +28 -11
  5. package/src/cli/commands/artifact/pending/command.ts +71 -7
  6. package/src/cli/commands/cap/tokensave.ts +2 -2
  7. package/src/cli/commands/companion/update.ts +2 -3
  8. package/src/cli/commands/doctor.ts +67 -4
  9. package/src/cli/commands/friction.ts +558 -0
  10. package/src/cli/commands/install.ts +8 -4
  11. package/src/cli/commands/plugin/install.ts +82 -35
  12. package/src/cli/commands/studio/connection.ts +53 -0
  13. package/src/cli/commands/studio/routes.ts +3 -0
  14. package/src/cli/commands/studio/selection.ts +10 -1
  15. package/src/cli/commands/studio/server.ts +31 -0
  16. package/src/cli/commands/studio/service-host.ts +3 -0
  17. package/src/cli/commands/studio/services.ts +25 -0
  18. package/src/cli/commands/triage.ts +172 -0
  19. package/src/cli/commands/vscode/release-vsix.json +2 -2
  20. package/src/cli/install-plan.tsx +3 -0
  21. package/src/cli/main.ts +85 -19
  22. package/src/cli/plugin-commands.ts +6 -1
  23. package/src/cli/usage.ts +12 -2
  24. package/src/create-mate.ts +11 -5
  25. package/src/distribution.ts +2 -0
  26. package/src/factory-host.ts +6 -0
  27. package/src/hooks/validate-artifact-path.ts +64 -14
  28. package/src/index.ts +1 -0
  29. package/src/lib/delivery/merge-git.ts +31 -7
  30. package/src/lib/delivery/overlap.ts +14 -1
  31. package/src/lib/delivery/repository-access.ts +11 -6
  32. package/src/lib/delivery/staging/apply-chain.ts +25 -7
  33. package/src/lib/delivery/staging/linked-merges.ts +175 -0
  34. package/src/lib/delivery/staging/naming.ts +3 -0
  35. package/src/lib/delivery/staging/openspec-type.ts +38 -7
  36. package/src/lib/delivery/staging/pending.ts +153 -11
  37. package/src/lib/delivery/staging/preflight.ts +239 -0
  38. package/src/lib/delivery/staging/project.ts +243 -104
  39. package/src/lib/delivery/staging/replay.ts +5 -3
  40. package/src/lib/delivery/staging/settle-linked.ts +5 -119
  41. package/src/lib/delivery/staging/submit.ts +139 -18
  42. package/src/lib/delivery/submit-change.ts +163 -37
  43. package/src/lib/friction/describe.ts +42 -0
  44. package/src/lib/friction/fields.ts +60 -0
  45. package/src/lib/friction/mark.ts +194 -0
  46. package/src/lib/friction/view/model.ts +67 -0
  47. package/src/lib/friction/view/read.ts +145 -0
  48. package/src/lib/friction/view/select.ts +54 -0
  49. package/src/lib/openspec-cli.ts +10 -5
  50. package/src/lib/orchestrator/adapters/claude.ts +5 -4
  51. package/src/lib/orchestrator/adapters/opencode.ts +2 -0
  52. package/src/lib/orchestrator/root-context.ts +23 -6
  53. package/src/lib/package-paths.ts +23 -15
  54. package/src/lib/session-attribution.ts +3 -7
  55. package/src/lib/skills-cli.ts +38 -0
  56. package/src/lib/tool-manifest.ts +73 -0
  57. package/src/lib/triage/context.ts +312 -0
  58. package/src/lib/triage/launch.ts +52 -0
  59. package/src/lib/triage/prepare.ts +112 -0
  60. package/src/lib/triage/session.ts +126 -0
  61. package/src/opencode/companion-hooks.ts +53 -5
  62. package/src/opencode/projected-guidance.ts +2 -0
  63. package/src/playbooks/companion-guidance.ts +2 -2
  64. package/src/plugin-api.ts +6 -0
  65. package/src/runtime/command-arg.ts +15 -0
  66. package/src/runtime/command-friction.ts +97 -0
  67. package/src/runtime/companion-guidance.ts +33 -16
  68. package/src/runtime/friction-fingerprint.ts +35 -0
  69. package/src/runtime/friction-log.ts +376 -0
  70. package/src/runtime/friction-recorder.ts +212 -0
  71. package/src/runtime/friction-retention.ts +1 -0
  72. package/src/runtime/friction-state.ts +110 -0
  73. package/src/runtime/friction-switch.ts +26 -0
  74. package/src/runtime/friction-vocabulary.ts +42 -0
  75. package/src/runtime/git-tracked.ts +13 -2
  76. package/src/runtime/projected-guidance.ts +2 -1
  77. package/src/runtime/secret-values.ts +16 -0
  78. package/src/runtime/session-id.ts +24 -0
  79. package/src/runtime/session-prepare-runner.ts +3 -0
  80. package/src/runtime/workflow/next-handoff-process.ts +2 -1
  81. package/src/studio.ts +47 -1
  82. package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +5 -1
  83. package/src/templates/capabilities/react-doctor/mate-react-doctor/SKILL.md +28 -0
  84. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +42 -4
  85. package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +27 -2
  86. package/src/templates/mate-skills/agents/mate-backfill-spec/SKILL.md +23 -1
  87. package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +26 -1
  88. package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +28 -0
  89. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +28 -3
  90. package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +28 -0
  91. package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +28 -0
  92. package/src/templates/mate-skills/agents/mate-grilling/SKILL.md +25 -0
  93. package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +28 -0
  94. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +28 -3
  95. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +28 -6
  96. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +27 -2
  97. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +28 -0
  98. package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +24 -2
  99. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +42 -4
  100. package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +27 -2
  101. package/src/templates/mate-skills/claude/mate-backfill-spec/SKILL.md +23 -1
  102. package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +26 -1
  103. package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +28 -0
  104. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +28 -3
  105. package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +28 -0
  106. package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +28 -0
  107. package/src/templates/mate-skills/claude/mate-grilling/SKILL.md +25 -0
  108. package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +28 -0
  109. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +28 -3
  110. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +28 -6
  111. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +27 -2
  112. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +28 -0
  113. package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +24 -2
  114. package/src/templates/triage/PLAYBOOK.md +120 -0
  115. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +108 -108
  116. package/src/tools/setup/capabilities/graphify.ts +23 -1
  117. package/src/tools/setup/capabilities/rtk.ts +46 -94
  118. package/src/tools/setup/capabilities/tokensave.ts +76 -54
  119. package/src/tools/setup/dynamic-plugins/audiences.ts +28 -14
  120. package/src/tools/setup/dynamic-plugins/hydrate.ts +32 -14
  121. package/src/tools/setup/dynamic-plugins/install.ts +2 -0
  122. package/src/tools/setup/dynamic-plugins/installed.ts +73 -0
  123. package/src/tools/setup/dynamic-plugins/loader.ts +12 -10
  124. package/src/tools/setup/dynamic-plugins/local.ts +492 -0
  125. package/src/tools/setup/dynamic-plugins/paths.ts +34 -6
  126. package/src/tools/setup/dynamic-plugins/verify.ts +34 -14
  127. package/src/tools/setup/dynamic-plugins/workspaces.ts +17 -8
  128. package/src/tools/setup/mate.ts +26 -1
  129. package/src/tools/setup/plugin.ts +5 -0
  130. package/src/tools/setup/plugins/gitignore.ts +45 -12
  131. package/src/tools/setup/service.ts +12 -0
  132. package/src/tools/setup/utils.ts +10 -1
  133. package/src/tools/setup.ts +16 -2
  134. package/studio-dist/client/assets/app-ggXJ_QVh.css +2 -0
  135. package/studio-dist/client/assets/button-amJ3g5oD.js +1 -0
  136. package/studio-dist/client/assets/cn-BQPKiwI4.js +1 -0
  137. package/studio-dist/client/assets/combobox-CJ7aGFid.js +1 -0
  138. package/studio-dist/client/assets/{companion-view-BVaZNtiI.js → companion-view-C_N237bf.js} +1 -1
  139. package/studio-dist/client/assets/fields-BAiGkJ5N.js +1 -0
  140. package/studio-dist/client/assets/friction-DqOU59v7.js +1 -0
  141. package/studio-dist/client/assets/getting-started-djaQeWlu.js +1 -0
  142. package/studio-dist/client/assets/getting-started-yp42dj5S.js +1 -0
  143. package/studio-dist/client/assets/getting-started._topic-C9zVXz_m.js +1 -0
  144. package/studio-dist/client/assets/getting-started.index-DWbDKICP.js +1 -0
  145. package/studio-dist/client/assets/graph-BYaD_5Bq.js +2 -0
  146. package/studio-dist/client/assets/{graph-canvas-DDuzsNSx.js → graph-canvas-ySGKMhmk.js} +1 -1
  147. package/studio-dist/client/assets/guides-D6T6W_jV.js +1 -0
  148. package/studio-dist/client/assets/index-Qx7reRPD.js +40 -0
  149. package/studio-dist/client/assets/markdown-view-jMiaBTSO.js +1 -0
  150. package/studio-dist/client/assets/panel-C4bf_h2W.js +1 -0
  151. package/studio-dist/client/assets/plugins._service._view-y6f2FDAB.js +1 -0
  152. package/studio-dist/client/assets/prepaint-CKsXyJOR.js +27 -0
  153. package/studio-dist/client/assets/{queries-axYk2u9L.js → queries-Dfp5deWj.js} +1 -1
  154. package/studio-dist/client/assets/react-BYUSgtBs.js +1 -0
  155. package/studio-dist/client/assets/reports-JFSwSueq.js +1 -0
  156. package/studio-dist/client/assets/routes-BdOWSgzK.js +1 -0
  157. package/studio-dist/client/assets/search-CXosfvYh.js +1 -0
  158. package/studio-dist/client/assets/select-BHYYWPhK.js +1 -0
  159. package/studio-dist/client/assets/skills-Bo9FLsBd.js +1 -0
  160. package/studio-dist/client/assets/{specs-DU1kqcp5.js → specs-BrCOjOch.js} +1 -1
  161. package/studio-dist/client/assets/specs-view-CdE2rlli.js +1 -0
  162. package/studio-dist/client/assets/{steps-DhIFuAZy.js → steps-CKUno4lh.js} +1 -1
  163. package/studio-dist/client/assets/store-C3vJq8Wj.js +1 -0
  164. package/studio-dist/client/assets/{studio-BR9j15J0.js → studio-0ueISxwP.js} +8 -8
  165. package/studio-dist/client/assets/{studio-queries-CFP_yTpr.js → studio-queries-BflKt9va.js} +2 -2
  166. package/studio-dist/client/assets/{usage-CHmwtkoM.js → usage-BLsLy0nN.js} +16 -16
  167. package/studio-dist/client/assets/useAnchoredPopupScrollLock-DC7f8GOp.js +1 -0
  168. package/studio-dist/client/assets/useMutation-uJUrejsi.js +1 -0
  169. package/studio-dist/client/assets/vault-BB1B_OhR.js +1 -0
  170. package/studio-dist/client/assets/warnings-CqOOGlPD.js +1 -0
  171. package/studio-dist/client/assets/workflow-BFzmI-06.js +1 -0
  172. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-DAbZ6fzY.js → __23tanstack-start-server-fn-resolver-gVfW5vIV.js} +30 -14
  173. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +66 -50
  174. package/studio-dist/server/assets/{button-BfoNadNR.js → button-D6bvrFmm.js} +226 -3478
  175. package/studio-dist/server/assets/cn-FXJAM0KO.js +5528 -0
  176. package/studio-dist/server/assets/combobox-D2MbYV1O.js +484 -0
  177. package/studio-dist/server/assets/{companion-view-DHUjPpA0.js → companion-view-Mf1ANbMb.js} +2 -2
  178. package/studio-dist/server/assets/{companions-kBrJZAd6.js → companions-Dr6IpNAb.js} +1 -1
  179. package/studio-dist/server/assets/{fields-BD_c65T1.js → fields-B4mAPETz.js} +2 -1
  180. package/studio-dist/server/assets/friction-9a5S1m7U.js +943 -0
  181. package/studio-dist/server/assets/friction-CWOTjpCV.js +62 -0
  182. package/studio-dist/server/assets/{getting-started-7P0oyWaM.js → getting-started-RU6tYU2Q.js} +2 -2
  183. package/studio-dist/server/assets/{getting-started._topic-B1mV0kGz.js → getting-started._topic-C02HGrC6.js} +2 -2
  184. package/studio-dist/server/assets/{getting-started.index-CeGtvUsm.js → getting-started.index-EzLRosbb.js} +2 -2
  185. package/studio-dist/server/assets/{graph-BWtmJOH2.js → graph-B11ITte0.js} +1 -1
  186. package/studio-dist/server/assets/{graph-DSDVEELZ.js → graph-CZ2H9Fzr.js} +8 -8
  187. package/studio-dist/server/assets/{graph-canvas-CID9Nksc.js → graph-canvas-rP5TT14Z.js} +2 -2
  188. package/studio-dist/server/assets/{guides-Bm3RbUB-.js → guides-B8HdeK_C.js} +1 -1
  189. package/studio-dist/server/assets/{guides-BLJenHwQ.js → guides-BGftp4wf.js} +1 -1
  190. package/studio-dist/server/assets/{guides.server-rHHqRuzV.js → guides.server-DqFQAStf.js} +1 -1
  191. package/studio-dist/server/assets/{markdown-view-D3v9x-cM.js → markdown-view-CArpV-CS.js} +1 -1
  192. package/studio-dist/server/assets/{panel-yqOl5GMU.js → panel-DR0iq46J.js} +4 -3
  193. package/studio-dist/server/assets/{plugins._service._view-DwqJX7s9.js → plugins._service._view-n7u2k5dF.js} +11 -6
  194. package/studio-dist/server/assets/prepaint-B28ClcPN.js +45 -0
  195. package/studio-dist/server/assets/{queries-DYmGrhNO.js → queries-D-yVP9i0.js} +1 -1
  196. package/studio-dist/server/assets/react-CiBZPDs8.js +45 -0
  197. package/studio-dist/server/assets/{reports-C4Y_Jd-x.js → reports-B9k98oE6.js} +1 -1
  198. package/studio-dist/server/assets/{reports-7yaPz7aP.js → reports-C2SmTgqh.js} +7 -7
  199. package/studio-dist/server/assets/{router-Dnoq5auE.js → router-CPt0TAk_.js} +654 -1565
  200. package/studio-dist/server/assets/{routes-Cok4p3mK.js → routes-CwH8LEy2.js} +8 -8
  201. package/studio-dist/server/assets/{search-DUK7Jl6f.js → search-b-yQesv3.js} +25 -2
  202. package/studio-dist/server/assets/{combobox-oxUI6r4V.js → select-C3i6TTX-.js} +35 -514
  203. package/studio-dist/server/assets/{shell-DNVXedgE.js → shell-CagqZZMZ.js} +4 -3
  204. package/studio-dist/server/assets/{skills-D8qdXSku.js → skills-C21Mg_8-.js} +8 -8
  205. package/studio-dist/server/assets/{skills-pKmuAs0F.js → skills-DGg0mWDM.js} +1 -1
  206. package/studio-dist/server/assets/{specs-DeHYUNFp.js → specs-DetoMiaB.js} +4 -4
  207. package/studio-dist/server/assets/{specs-view-BGn-5Ik_.js → specs-view-CmbfLDwN.js} +10 -9
  208. package/studio-dist/server/assets/{steps-CV7Yk7L7.js → steps-D1tYAyWZ.js} +1 -1
  209. package/studio-dist/server/assets/store-aC-I6f6o.js +93 -0
  210. package/studio-dist/server/assets/{studio-CB94np48.js → studio-qRvQjRpz.js} +47 -2
  211. package/studio-dist/server/assets/{studio-queries-BqZGBE70.js → studio-queries-Dqf-3nzj.js} +66 -8
  212. package/studio-dist/server/assets/{usage-M6Gi6Km7.js → usage-CS4CBK9D.js} +13 -44
  213. package/studio-dist/server/assets/{usage-j5jR9gX9.js → usage-Cwle9-xY.js} +1 -1
  214. package/studio-dist/server/assets/useAnchoredPopupScrollLock-BjMNgXv9.js +756 -0
  215. package/studio-dist/server/assets/useMutation-DpBIuWXt.js +690 -0
  216. package/studio-dist/server/assets/{vault-lBlvSyD4.js → vault-CEBBRLMb.js} +1 -1
  217. package/studio-dist/server/assets/{vault-PqVmssmW.js → vault-DVQidlId.js} +6 -6
  218. package/studio-dist/server/assets/{views-CsFp1i1G.js → views-UgO0Qz_g.js} +2 -2
  219. package/studio-dist/server/assets/{warnings-BDs34j_m.js → warnings-C7hgXpdk.js} +2 -2
  220. package/studio-dist/server/assets/{workflow-T0eEldsa.js → workflow-6dZZ1ofw.js} +9 -9
  221. package/studio-dist/server/server.js +2 -2
  222. package/tool-manifest.yaml +85 -0
  223. package/studio-dist/client/assets/app-BFVyWHGo.css +0 -2
  224. package/studio-dist/client/assets/button-D6LrRkOG.js +0 -1
  225. package/studio-dist/client/assets/combobox-Dk2MMZWE.js +0 -1
  226. package/studio-dist/client/assets/fields-D_FYhxQr.js +0 -1
  227. package/studio-dist/client/assets/getting-started-ByWRg7hC.js +0 -1
  228. package/studio-dist/client/assets/getting-started-DZSjYC-b.js +0 -1
  229. package/studio-dist/client/assets/getting-started._topic-C6OyQ4G6.js +0 -1
  230. package/studio-dist/client/assets/getting-started.index-BkmPHdEm.js +0 -1
  231. package/studio-dist/client/assets/graph-7jm2XzyL.js +0 -2
  232. package/studio-dist/client/assets/guides-D9VTjWXP.js +0 -1
  233. package/studio-dist/client/assets/index-BBmFpG4y.js +0 -40
  234. package/studio-dist/client/assets/markdown-view-RL5YvfZg.js +0 -1
  235. package/studio-dist/client/assets/panel-B8F8sOKQ.js +0 -1
  236. package/studio-dist/client/assets/plugins._service._view-CynxTbMx.js +0 -1
  237. package/studio-dist/client/assets/react-r45OnJCw.js +0 -27
  238. package/studio-dist/client/assets/reports-BCAyXh6p.js +0 -1
  239. package/studio-dist/client/assets/routes-BFPqq89E.js +0 -1
  240. package/studio-dist/client/assets/skills-DTks_uBx.js +0 -1
  241. package/studio-dist/client/assets/specs-view-omrd_5P3.js +0 -1
  242. package/studio-dist/client/assets/store-DJ5cncKA.js +0 -1
  243. package/studio-dist/client/assets/useBaseQuery-BlC-AZ35.js +0 -1
  244. package/studio-dist/client/assets/vault-DRg8MScm.js +0 -1
  245. package/studio-dist/client/assets/warnings-UHFy6HAp.js +0 -1
  246. package/studio-dist/client/assets/workflow-Bv9vSfVV.js +0 -1
  247. package/studio-dist/server/assets/react-BO0uMhpm.js +0 -89
  248. package/studio-dist/server/assets/store-CWDGIp6x.js +0 -280
  249. package/studio-dist/server/assets/useBaseQuery-Tv_QJt9r.js +0 -2051
@@ -0,0 +1,194 @@
1
+ import {
2
+ findEvent,
3
+ findEvents,
4
+ findFingerprint,
5
+ findReport,
6
+ type FrictionEvent,
7
+ type FrictionReport,
8
+ readReportIds,
9
+ } from "../../runtime/friction-log";
10
+ import {
11
+ FrictionStateFileError,
12
+ type FrictionStatesFile,
13
+ readFrictionStates,
14
+ updateFrictionStates,
15
+ } from "../../runtime/friction-state";
16
+ import type {
17
+ FrictionState,
18
+ FrictionStateOrigin,
19
+ MarkState,
20
+ } from "../../runtime/friction-vocabulary";
21
+ import type { LockOptions } from "../../runtime/session-registry";
22
+ import { cut, FrictionRefusal, refuseSecrets, type SecretScan } from "./fields";
23
+
24
+ export interface MarkInput {
25
+ note?: string;
26
+ link?: string;
27
+ by: FrictionStateOrigin;
28
+ }
29
+
30
+ export interface MarkDeps {
31
+ homeDir?: string;
32
+ now?: Date;
33
+ scan?: SecretScan;
34
+ lock?: LockOptions;
35
+ }
36
+
37
+ export type MarkResult =
38
+ | { ok: true; target: string; state: FrictionState | null }
39
+ | { ok: false; code: string; reason: string };
40
+
41
+ const REPORT_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
42
+
43
+ /** Report ids are stored in lower case; a fingerprint is kept exactly as given. */
44
+ const canonicalTarget = (target: string) =>
45
+ REPORT_ID.test(target) ? target.toLowerCase() : target;
46
+
47
+ const unknownTarget = (target: string) =>
48
+ new FrictionRefusal(
49
+ "unknown-target",
50
+ `${target} is no recorded fingerprint and no Free Report; nothing was changed.`,
51
+ );
52
+
53
+ const textOrNull = (text: string | undefined) => (text?.trim() ? cut(text) : null);
54
+
55
+ function checkLink(link: string | null, state: MarkState): void {
56
+ if (link === null) return;
57
+ if (state !== "reported") {
58
+ throw new FrictionRefusal(
59
+ "link-needs-reported",
60
+ "A link is kept only with the state reported (--state reported); nothing was changed.",
61
+ );
62
+ }
63
+ let protocol: string;
64
+ try {
65
+ protocol = new URL(link).protocol;
66
+ } catch {
67
+ protocol = "";
68
+ }
69
+ if (protocol !== "http:" && protocol !== "https:") {
70
+ throw new FrictionRefusal(
71
+ "invalid-link",
72
+ "The link must be an http or https URL; nothing was changed.",
73
+ );
74
+ }
75
+ }
76
+
77
+ /** A Friction Item a person can mark or triage, with its records from the whole Friction Log. */
78
+ export type FrictionTarget =
79
+ | { id: string; kind: "fingerprint"; events: FrictionEvent[] }
80
+ | { id: string; kind: "report"; report: FrictionReport };
81
+
82
+ /**
83
+ * Looks a fingerprint or Free Report id up in the whole Friction Log; throws a `FrictionRefusal`
84
+ * for an unknown id or a report on an event. `verb` names the action the refusal points to.
85
+ */
86
+ export function lookupFrictionTarget(
87
+ given: string,
88
+ options: { homeDir?: string; verb?: string } = {},
89
+ ): FrictionTarget {
90
+ const { homeDir, verb = "Mark" } = options;
91
+ const target = canonicalTarget(given);
92
+ if (!REPORT_ID.test(target)) {
93
+ const events = findEvents((event) => event.fingerprint === target, { homeDir });
94
+ if (events.length === 0) throw unknownTarget(target);
95
+ return { id: target, kind: "fingerprint", events };
96
+ }
97
+ const report = findReport(target, { homeDir });
98
+ if (!report) throw unknownTarget(target);
99
+ if (report.eventId) {
100
+ const event = findEvent(report.eventId, { homeDir });
101
+ throw new FrictionRefusal(
102
+ "report-on-event",
103
+ `${target} is a report on an event; it follows the state of its fingerprint${event ? ` ${event.fingerprint}` : ""}. ${verb} that fingerprint instead; nothing was changed.`,
104
+ );
105
+ }
106
+ return { id: target, kind: "report", report };
107
+ }
108
+
109
+ function resolveTarget(
110
+ target: string,
111
+ known: { fingerprints: object; reports: object },
112
+ homeDir?: string,
113
+ ): "fingerprints" | "reports" {
114
+ if (Object.hasOwn(known.fingerprints, target)) return "fingerprints";
115
+ if (Object.hasOwn(known.reports, target)) return "reports";
116
+ if (!REPORT_ID.test(target)) {
117
+ // Stops at the newest match; mark needs no full scan.
118
+ if (!findFingerprint(target, { homeDir })) throw unknownTarget(target);
119
+ return "fingerprints";
120
+ }
121
+ lookupFrictionTarget(target, { homeDir });
122
+ return "reports";
123
+ }
124
+
125
+ function forgetExpiredReports(
126
+ states: FrictionStatesFile,
127
+ idsReadBeforeScan: string[],
128
+ retained: Set<string>,
129
+ ): void {
130
+ for (const id of idsReadBeforeScan) {
131
+ if (!retained.has(id)) delete states.reports[id];
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Sets or, with `open`, clears the Friction State of a fingerprint or a Free Report. The checks
137
+ * live here once for every caller; the Friction Log is never written.
138
+ */
139
+ export async function markFriction(
140
+ given: string,
141
+ state: MarkState,
142
+ input: MarkInput,
143
+ deps: MarkDeps = {},
144
+ ): Promise<MarkResult> {
145
+ const target = canonicalTarget(given);
146
+ try {
147
+ const note = textOrNull(input.note);
148
+ const link = textOrNull(input.link);
149
+ checkLink(link, state);
150
+ const known = readFrictionStates(deps.homeDir);
151
+ const family = resolveTarget(target, known, deps.homeDir);
152
+ if (note !== null || link !== null) await refuseSecrets("The mark", [note, link], deps.scan);
153
+ const retained =
154
+ Object.keys(known.reports).length > 0 ? readReportIds({ homeDir: deps.homeDir }) : null;
155
+ if (family === "reports" && retained && !retained.has(target)) {
156
+ throw unknownTarget(target);
157
+ }
158
+ const next: FrictionState | null =
159
+ state === "open"
160
+ ? null
161
+ : {
162
+ state,
163
+ at: (deps.now ?? new Date()).toISOString(),
164
+ by: input.by,
165
+ note,
166
+ link,
167
+ };
168
+ await updateFrictionStates(
169
+ (states) => {
170
+ if (retained) forgetExpiredReports(states, Object.keys(known.reports), retained);
171
+ if (next) states[family][target] = next;
172
+ else delete states[family][target];
173
+ },
174
+ { homeDir: deps.homeDir, lock: deps.lock },
175
+ );
176
+ return { ok: true, target, state: next };
177
+ } catch (error) {
178
+ if (error instanceof FrictionRefusal) {
179
+ return { ok: false, code: error.code, reason: error.message };
180
+ }
181
+ if (error instanceof FrictionStateFileError) {
182
+ return {
183
+ ok: false,
184
+ code: "state-file-damaged",
185
+ reason: `${error.message}; it was left unchanged and nothing was marked. Repair or delete it to mark again.`,
186
+ };
187
+ }
188
+ return {
189
+ ok: false,
190
+ code: "write-failed",
191
+ reason: `The Friction State could not be written: ${error instanceof Error ? error.message : String(error)}`,
192
+ };
193
+ }
194
+ }
@@ -0,0 +1,67 @@
1
+ import type { FrictionReport } from "../../../runtime/friction-log";
2
+ import { FRICTION_RETENTION_DAYS } from "../../../runtime/friction-retention";
3
+ import type { FrictionState, SubjectType } from "../../../runtime/friction-vocabulary";
4
+
5
+ export const FRICTION_VIEW_DAYS = [7, 30, FRICTION_RETENTION_DAYS] as const;
6
+ export type FrictionViewDays = (typeof FRICTION_VIEW_DAYS)[number];
7
+
8
+ /** The period a value names, as a number or its text; `undefined` for any other. */
9
+ export function frictionViewDays(value: unknown): FrictionViewDays | undefined {
10
+ return FRICTION_VIEW_DAYS.find((days) => String(days) === String(value));
11
+ }
12
+
13
+ /** A fingerprint's Friction State with what later events tell about it, derived on read. */
14
+ export interface FrictionGroupState extends FrictionState {
15
+ /** Events of the period later than the mark. */
16
+ eventsSince: number;
17
+ /** `fixed`, yet recorded again after the mark. */
18
+ reopened: boolean;
19
+ }
20
+
21
+ export type FrictionItemState = FrictionState &
22
+ Partial<Pick<FrictionGroupState, "eventsSince" | "reopened">>;
23
+
24
+ export interface FrictionGroup {
25
+ fingerprint: string;
26
+ title: string;
27
+ /** The subject type a report on its events takes: `hook` for a refusal, `command` otherwise. */
28
+ subjectType: SubjectType;
29
+ events: number;
30
+ sessions: number;
31
+ /** The highest event count within one session. */
32
+ maxPerSession: number;
33
+ firstSeen: string;
34
+ lastSeen: string;
35
+ /** Mate version → event count. */
36
+ versions: Record<string, number>;
37
+ /** Companion path → event count. */
38
+ companions: Record<string, number>;
39
+ /** Path a refused call named → event count. */
40
+ paths: Record<string, number>;
41
+ /** Flag a failed command carried → event count. */
42
+ flags: Record<string, number>;
43
+ /** Reports on the group's events, newest first. */
44
+ reports: FrictionReport[];
45
+ state: FrictionGroupState | null;
46
+ /** Unmarked or reopened. */
47
+ open: boolean;
48
+ }
49
+
50
+ export interface FrictionFreeReport extends FrictionReport {
51
+ /** `null` for a subject of no known type. */
52
+ subjectType: SubjectType | null;
53
+ state: FrictionState | null;
54
+ open: boolean;
55
+ }
56
+
57
+ /** The Friction View of a scope and period; `mate friction list --json` and Studio carry it. */
58
+ export interface FrictionView {
59
+ recording: boolean;
60
+ days: number;
61
+ events: number;
62
+ sessions: number;
63
+ /** Most repeated within one session first, then by event count. */
64
+ groups: FrictionGroup[];
65
+ /** Newest first. */
66
+ freeReports: FrictionFreeReport[];
67
+ }
@@ -0,0 +1,145 @@
1
+ import {
2
+ readFriction,
3
+ type FrictionEvent,
4
+ type FrictionReport,
5
+ type FrictionScope,
6
+ } from "../../../runtime/friction-log";
7
+ import { readFrictionStates } from "../../../runtime/friction-state";
8
+ import { readFrictionSwitch } from "../../../runtime/friction-switch";
9
+ import { subjectTypeOf, type FrictionState } from "../../../runtime/friction-vocabulary";
10
+ import { describeFingerprint } from "../describe";
11
+ import { eventSubjectType } from "../fields";
12
+ import type { FrictionGroup, FrictionGroupState, FrictionView } from "./model";
13
+
14
+ // The one reader that joins the Friction Log with the Friction States (ADR-026); reads only.
15
+
16
+ interface FrictionWindow {
17
+ days: number;
18
+ homeDir?: string;
19
+ now?: Date;
20
+ }
21
+
22
+ export interface FrictionRecords {
23
+ events: FrictionEvent[];
24
+ /** The reports on those events wherever they were made, and the scope's Free Reports. */
25
+ reports: FrictionReport[];
26
+ /** The Friction States of the fingerprints and Free Reports in the records, and no other. */
27
+ states: {
28
+ fingerprints: Record<string, FrictionGroupState>;
29
+ reports: Record<string, FrictionState>;
30
+ };
31
+ }
32
+
33
+ function groupState(state: FrictionState, times: string[]): FrictionGroupState {
34
+ const markedAt = Date.parse(state.at);
35
+ const eventsSince = times.filter((at) => Date.parse(at) > markedAt).length;
36
+ return { ...state, eventsSince, reopened: state.state === "fixed" && eventsSince > 0 };
37
+ }
38
+
39
+ const byFingerprint = (events: FrictionEvent[]) =>
40
+ Map.groupBy(events, (event) => event.fingerprint);
41
+
42
+ export function readFrictionRecords(scope: FrictionScope, window: FrictionWindow): FrictionRecords {
43
+ const { events, reports } = readFriction(scope, {
44
+ sinceDays: window.days,
45
+ homeDir: window.homeDir,
46
+ now: window.now,
47
+ });
48
+ return joinFrictionStates(events, reports, window.homeDir);
49
+ }
50
+
51
+ /** Adds the Friction States of the given records' fingerprints and Free Reports. */
52
+ export function joinFrictionStates(
53
+ events: FrictionEvent[],
54
+ reports: FrictionReport[],
55
+ homeDir?: string,
56
+ ): FrictionRecords {
57
+ const stored = readFrictionStates(homeDir);
58
+ const fingerprints: Record<string, FrictionGroupState> = {};
59
+ for (const [fingerprint, grouped] of byFingerprint(events)) {
60
+ const state = stored.fingerprints[fingerprint];
61
+ if (state) {
62
+ fingerprints[fingerprint] = groupState(
63
+ state,
64
+ grouped.map((event) => event.at),
65
+ );
66
+ }
67
+ }
68
+ const freeStates: Record<string, FrictionState> = {};
69
+ for (const report of reports) {
70
+ const state = report.eventId ? undefined : stored.reports[report.id];
71
+ if (state) freeStates[report.id] = state;
72
+ }
73
+ return { events, reports, states: { fingerprints, reports: freeStates } };
74
+ }
75
+
76
+ const newestFirst = (reports: FrictionReport[]) =>
77
+ reports.toSorted((a, b) => b.at.localeCompare(a.at));
78
+
79
+ const strings = (value: unknown): string[] =>
80
+ Array.isArray(value) ? value.filter((item): item is string => typeof item === "string") : [];
81
+
82
+ function tally(counts: Record<string, number>, names: string[]): void {
83
+ for (const name of new Set(names)) counts[name] = (counts[name] ?? 0) + 1;
84
+ }
85
+
86
+ function toGroup(
87
+ fingerprint: string,
88
+ grouped: FrictionEvent[],
89
+ reportsByEvent: Map<string | null, FrictionReport[]>,
90
+ state: FrictionGroupState | undefined,
91
+ ): FrictionGroup {
92
+ const perSession = new Map<string, number>();
93
+ const versions: Record<string, number> = {};
94
+ const companions: Record<string, number> = {};
95
+ const paths: Record<string, number> = {};
96
+ const flags: Record<string, number> = {};
97
+ for (const event of grouped) {
98
+ perSession.set(event.sessionId, (perSession.get(event.sessionId) ?? 0) + 1);
99
+ versions[event.mateVersion] = (versions[event.mateVersion] ?? 0) + 1;
100
+ companions[event.companion] = (companions[event.companion] ?? 0) + 1;
101
+ tally(paths, strings(event.detail.paths));
102
+ tally(flags, strings(event.detail.flags));
103
+ }
104
+ const times = grouped.map((event) => event.at).toSorted();
105
+ return {
106
+ fingerprint,
107
+ title: describeFingerprint(fingerprint),
108
+ subjectType: eventSubjectType({ fingerprint }),
109
+ events: grouped.length,
110
+ sessions: perSession.size,
111
+ maxPerSession: Math.max(...perSession.values()),
112
+ firstSeen: times[0],
113
+ lastSeen: times[times.length - 1],
114
+ versions,
115
+ companions,
116
+ paths,
117
+ flags,
118
+ reports: newestFirst(grouped.flatMap((event) => reportsByEvent.get(event.id) ?? [])),
119
+ state: state ?? null,
120
+ open: !state || state.reopened,
121
+ };
122
+ }
123
+
124
+ export function readFrictionView(scope: FrictionScope, window: FrictionWindow): FrictionView {
125
+ const { events, reports, states } = readFrictionRecords(scope, window);
126
+ const reportsByEvent = Map.groupBy(
127
+ reports.filter((report) => report.eventId),
128
+ (report) => report.eventId,
129
+ );
130
+ const groups = [...byFingerprint(events)].map(([fingerprint, grouped]) =>
131
+ toGroup(fingerprint, grouped, reportsByEvent, states.fingerprints[fingerprint]),
132
+ );
133
+ groups.sort((a, b) => b.maxPerSession - a.maxPerSession || b.events - a.events);
134
+ return {
135
+ recording: readFrictionSwitch(window.homeDir),
136
+ days: window.days,
137
+ events: events.length,
138
+ sessions: new Set(events.map((event) => event.sessionId)).size,
139
+ groups,
140
+ freeReports: newestFirst(reports.filter((report) => !report.eventId)).map((report) => {
141
+ const state = states.reports[report.id] ?? null;
142
+ return { ...report, subjectType: subjectTypeOf(report.subject), state, open: !state };
143
+ }),
144
+ };
145
+ }
@@ -0,0 +1,54 @@
1
+ import {
2
+ SUBJECT_TYPES,
3
+ type ReportKind,
4
+ type StateFilter,
5
+ type SubjectType,
6
+ } from "../../../runtime/friction-vocabulary";
7
+ import type { FrictionFreeReport, FrictionGroup, FrictionView } from "./model";
8
+
9
+ export interface FrictionFilters {
10
+ state: StateFilter;
11
+ /** Absent means every type. */
12
+ type?: SubjectType;
13
+ /** Narrows Free Reports only; absent means every kind. */
14
+ kind?: ReportKind;
15
+ }
16
+
17
+ export interface FrictionShown {
18
+ groups: FrictionGroup[];
19
+ freeReports: FrictionFreeReport[];
20
+ /** Items of the period the filters leave out. */
21
+ hidden: number;
22
+ /** The subject types present in the period, in vocabulary order. */
23
+ types: SubjectType[];
24
+ /** The type filtered on; a type absent from the period reads as every type. */
25
+ type?: SubjectType;
26
+ }
27
+
28
+ /** The Friction Items the filters show, in the view's order. */
29
+ export function selectFriction(
30
+ view: Pick<FrictionView, "groups" | "freeReports">,
31
+ filters: FrictionFilters,
32
+ ): FrictionShown {
33
+ const present = new Set<SubjectType | null>([
34
+ ...view.groups.map((group) => group.subjectType),
35
+ ...view.freeReports.map((report) => report.subjectType),
36
+ ]);
37
+ const types = SUBJECT_TYPES.filter((type) => present.has(type));
38
+ const type = types.find((known) => known === filters.type);
39
+ const shown = (item: { open: boolean; subjectType: SubjectType | null }) =>
40
+ (filters.state === "all" || item.open === (filters.state === "open")) &&
41
+ (!type || item.subjectType === type);
42
+ const groups = view.groups.filter(shown);
43
+ const freeReports = view.freeReports.filter(
44
+ (report) => shown(report) && (!filters.kind || report.kind === filters.kind),
45
+ );
46
+ const total = view.groups.length + view.freeReports.length;
47
+ return {
48
+ groups,
49
+ freeReports,
50
+ hidden: total - groups.length - freeReports.length,
51
+ types,
52
+ type,
53
+ };
54
+ }
@@ -79,6 +79,15 @@ export const openSpecCliDeps = {
79
79
  locate: (): OpenSpecLocation => resolveOpenSpec(),
80
80
  };
81
81
 
82
+ /**
83
+ * How to start a CLI mate-core depends on. A JS entry runs on the current runtime, not its
84
+ * `#!/usr/bin/env node` shebang, which needs an executable bit and `node` on PATH and does
85
+ * not work on Windows.
86
+ */
87
+ export function bundledCliCommand(bin: string, args: string[]): [string, string[]] {
88
+ return /\.m?js$/.test(bin) ? [process.execPath, [bin, ...args]] : [bin, args];
89
+ }
90
+
82
91
  /** The CLI every OpenSpec process Mate starts runs. */
83
92
  export function locateOpenSpec(): OpenSpecLocation {
84
93
  return openSpecCliDeps.locate();
@@ -91,11 +100,7 @@ export function runOpenSpec(args: string[], options: OpenSpecRunOptions): Promis
91
100
  return Promise.resolve({ code: 1, stdout: "", stderr: location.missing, missing: true });
92
101
  }
93
102
  return new Promise((resolve) => {
94
- // A JS entry runs on the current runtime, not its `#!/usr/bin/env node` shebang,
95
- // which needs an executable bit and `node` on PATH and does not work on Windows.
96
- const [command, commandArgs] = location.bin.endsWith(".js")
97
- ? [process.execPath, [location.bin, ...args]]
98
- : [location.bin, args];
103
+ const [command, commandArgs] = bundledCliCommand(location.bin, args);
99
104
  const child = spawn(command, commandArgs, {
100
105
  cwd: options.cwd,
101
106
  env: { ...(options.env ?? process.env), ...OPENSPEC_ENV },
@@ -14,6 +14,7 @@ import {
14
14
  } from "../../../runtime/claude-delivery-plan";
15
15
  import { hookGroupKey, type ClaudeHookGroup } from "../../../runtime/claude-hook-group";
16
16
  import { MATE_ENV } from "../../../runtime/env-names";
17
+ import { readFrictionSwitch } from "../../../runtime/friction-switch";
17
18
  import { SESSION_ORIGIN_ENV } from "../../../runtime/session-registry";
18
19
  import { resolveSecretPolicy } from "../../../runtime/policy";
19
20
  import { managedSessionKind } from "../../../runtime/session-kind";
@@ -331,10 +332,10 @@ export class ClaudeAdapter extends LaunchAdapter<ClaudeLaunchContext> {
331
332
  const mcpConfigArgs =
332
333
  plan.mcp === "mcp-config" && mcpConfigPath ? ["--mcp-config", mcpConfigPath] : [];
333
334
 
334
- const guidance = buildCompanionGuidance({
335
- ...context,
336
- secretGuardrails: resolveSecretPolicy(context.companionPath).guardrails,
337
- });
335
+ const guidance = buildCompanionGuidance(
336
+ { ...context, secretGuardrails: resolveSecretPolicy(context.companionPath).guardrails },
337
+ { friction: readFrictionSwitch() },
338
+ );
338
339
  const children = context.repository ? umbrellaChildrenBlock(context.repository.path) : "";
339
340
  const { args: passthrough, prompts, boundary } = liftAppendedPrompts(args);
340
341
  const promptArgs = [
@@ -5,6 +5,7 @@ const fs = await import("node:fs/promises");
5
5
  const path = await import("node:path");
6
6
 
7
7
  import { MATE_ENV } from "../../../runtime/env";
8
+ import { readFrictionSwitch } from "../../../runtime/friction-switch";
8
9
  import { SESSION_ORIGIN_ENV } from "../../../runtime/session-registry";
9
10
  import { mainCheckoutOf } from "../../../runtime/git-layout";
10
11
  import { OPENCODE_PASSWORD } from "../../../runtime/opencode-server-record";
@@ -172,6 +173,7 @@ export class OpenCodeAdapter extends LaunchAdapter {
172
173
  return buildOpenCodeGuidance(context.capabilities, {
173
174
  companionScoped: !context.repository,
174
175
  secretGuardrails: resolveSecretPolicy(context.companionPath).guardrails,
176
+ friction: readFrictionSwitch(),
175
177
  ...declaredGuidance(context.companionPath),
176
178
  });
177
179
  }
@@ -7,7 +7,7 @@ import {
7
7
  type CompanionResolutionResult,
8
8
  findRepoLocalLinkedRepository,
9
9
  } from "./repository-link";
10
- import { ConfigStore, mergeWithDefaults } from "./config-store";
10
+ import { ConfigStore, defaultConfig, mergeWithDefaults } from "./config-store";
11
11
  import { GlobalConfigStore } from "./global-config-store";
12
12
  import type { FrameworkConfig, LinkedRepository } from "./types";
13
13
 
@@ -32,6 +32,8 @@ export interface RootContext {
32
32
 
33
33
  export interface RootContextDeps {
34
34
  globalConfigStore?: GlobalConfigStore;
35
+ /** `false` resolves without repairing the repo-local registry. */
36
+ write?: boolean;
35
37
  }
36
38
 
37
39
  const emptyResolution = (): CompanionResolutionResult => ({
@@ -44,8 +46,22 @@ function kindForConfig(config: FrameworkConfig): Exclude<RootKind, "core"> {
44
46
  return config.type === "hub" ? "hub" : config.type === "working" ? "working" : "companion";
45
47
  }
46
48
 
47
- async function loadRootConfig(rootPath: string): Promise<FrameworkConfig> {
49
+ async function loadRootConfig(
50
+ rootPath: string,
51
+ write?: boolean,
52
+ failures: CompanionResolutionResult["failures"] = [],
53
+ ): Promise<FrameworkConfig> {
48
54
  const configPath = path.join(rootPath, `.${FRAMEWORK_NAME}`, "config", "framework.yaml");
55
+ const missing =
56
+ write === false &&
57
+ (await fs.access(configPath).then(
58
+ () => false,
59
+ (error: NodeJS.ErrnoException) => error.code === "ENOENT",
60
+ ));
61
+ if (missing) {
62
+ failures.push({ companionPath: rootPath, message: `${configPath} is missing.` });
63
+ return mergeWithDefaults(defaultConfig());
64
+ }
49
65
  return mergeWithDefaults(await new ConfigStore(configPath).load());
50
66
  }
51
67
 
@@ -59,7 +75,8 @@ export async function resolveRootContext(
59
75
  const envRootPath = process.env.MATE_ARTIFACT_PATH;
60
76
  if (envRootPath) {
61
77
  const rootPath = path.resolve(envRootPath);
62
- const config = await loadRootConfig(rootPath);
78
+ const resolution = emptyResolution();
79
+ const config = await loadRootConfig(rootPath, deps.write, resolution.failures);
63
80
  return {
64
81
  kind: kindForConfig(config),
65
82
  origin: "env",
@@ -67,15 +84,15 @@ export async function resolveRootContext(
67
84
  config,
68
85
  repositoryId: process.env.MATE_REPO_ID ?? linkedRepository?.id,
69
86
  linkedRepository,
70
- resolution: emptyResolution(),
87
+ resolution,
71
88
  };
72
89
  }
73
90
 
74
91
  const resolver = new CompanionResolver(deps.globalConfigStore ?? new GlobalConfigStore());
75
- const resolution = await resolver.resolveWithDiagnostics(resolvedCwd);
92
+ const resolution = await resolver.resolveWithDiagnostics(resolvedCwd, { write: deps.write });
76
93
  if (resolution.match) {
77
94
  const rootPath = resolution.match.companionPath;
78
- const config = await loadRootConfig(rootPath);
95
+ const config = await loadRootConfig(rootPath, deps.write, resolution.failures);
79
96
  return {
80
97
  kind: kindForConfig(config),
81
98
  origin: "registry",
@@ -6,16 +6,23 @@ import { getActiveDistribution } from "../distribution";
6
6
 
7
7
  const require = createRequire(import.meta.url);
8
8
 
9
+ function resolveAsset(relative: string, bundled: string): string {
10
+ for (const root of getActiveDistribution().config.assetRoots ?? []) {
11
+ const candidate = path.join(root, relative);
12
+ if (fs.existsSync(candidate)) return candidate;
13
+ }
14
+ return bundled;
15
+ }
16
+
9
17
  /**
10
18
  * Resolved wrapper directory: a distribution asset root that ships
11
19
  * `wrappers/bin` wins over core's bundled default.
12
20
  */
13
21
  export function getWrapperBinPath(): string {
14
- for (const root of getActiveDistribution().config.assetRoots ?? []) {
15
- const candidate = path.join(root, "wrappers", "bin");
16
- if (fs.existsSync(candidate)) return candidate;
17
- }
18
- return path.resolve(import.meta.dirname, "../../wrappers/bin");
22
+ return resolveAsset(
23
+ path.join("wrappers", "bin"),
24
+ path.resolve(import.meta.dirname, "../../wrappers/bin"),
25
+ );
19
26
  }
20
27
 
21
28
  function canonicalDir(dir: string): string {
@@ -49,11 +56,7 @@ export function withoutMateWrapperDirs(
49
56
  * mate-core version.
50
57
  */
51
58
  export function getClaudePluginRoot(): string {
52
- for (const root of getActiveDistribution().config.assetRoots ?? []) {
53
- const candidate = path.join(root, "claude-plugin");
54
- if (fs.existsSync(candidate)) return candidate;
55
- }
56
- return path.resolve(import.meta.dirname, "../../claude-plugin");
59
+ return resolveAsset("claude-plugin", path.resolve(import.meta.dirname, "../../claude-plugin"));
57
60
  }
58
61
 
59
62
  /** mate-core's folder of the Claude plugins its built-in Capabilities contribute. */
@@ -99,11 +102,10 @@ export function validateClaudePluginAssets(pluginRoot = getClaudePluginRoot()):
99
102
  * projection, never a committed config.
100
103
  */
101
104
  export function getOpenCodePluginRoot(): string {
102
- for (const root of getActiveDistribution().config.assetRoots ?? []) {
103
- const candidate = path.join(root, "opencode-plugin");
104
- if (fs.existsSync(candidate)) return candidate;
105
- }
106
- return path.resolve(import.meta.dirname, "../../opencode-plugin");
105
+ return resolveAsset(
106
+ "opencode-plugin",
107
+ path.resolve(import.meta.dirname, "../../opencode-plugin"),
108
+ );
107
109
  }
108
110
 
109
111
  /** Root entries OpenCode resolves for a plugin referenced by directory path. */
@@ -124,6 +126,12 @@ export function validateOpenCodePluginAssets(pluginRoot = getOpenCodePluginRoot(
124
126
  }
125
127
  }
126
128
 
129
+ /** Resolved triage playbook: a distribution asset root's `templates/triage/PLAYBOOK.md` wins. */
130
+ export function getTriagePlaybookPath(): string {
131
+ const relative = path.join("templates", "triage", "PLAYBOOK.md");
132
+ return resolveAsset(relative, path.resolve(import.meta.dirname, "..", relative));
133
+ }
134
+
127
135
  export function getReactDoctorBinPath(): string {
128
136
  try {
129
137
  const entryPath = require.resolve("react-doctor");