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

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 (168) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
  2. package/package.json +1 -1
  3. package/src/cli/commands/doctor.ts +51 -0
  4. package/src/cli/commands/friction.ts +558 -0
  5. package/src/cli/commands/studio/connection.ts +53 -0
  6. package/src/cli/commands/studio/routes.ts +3 -0
  7. package/src/cli/commands/studio/selection.ts +10 -1
  8. package/src/cli/commands/studio/server.ts +31 -0
  9. package/src/cli/commands/studio/services.ts +25 -0
  10. package/src/cli/commands/triage.ts +151 -0
  11. package/src/cli/commands/vscode/release-vsix.json +2 -2
  12. package/src/cli/main.ts +35 -13
  13. package/src/cli/plugin-commands.ts +6 -1
  14. package/src/cli/usage.ts +10 -0
  15. package/src/create-mate.ts +11 -5
  16. package/src/distribution.ts +2 -0
  17. package/src/hooks/validate-artifact-path.ts +64 -14
  18. package/src/lib/friction/describe.ts +42 -0
  19. package/src/lib/friction/fields.ts +60 -0
  20. package/src/lib/friction/mark.ts +156 -0
  21. package/src/lib/friction/view/model.ts +67 -0
  22. package/src/lib/friction/view/read.ts +136 -0
  23. package/src/lib/friction/view/select.ts +54 -0
  24. package/src/lib/orchestrator/adapters/claude.ts +5 -4
  25. package/src/lib/orchestrator/adapters/opencode.ts +2 -0
  26. package/src/lib/orchestrator/root-context.ts +23 -6
  27. package/src/lib/package-paths.ts +23 -15
  28. package/src/lib/session-attribution.ts +3 -7
  29. package/src/lib/triage/context.ts +186 -0
  30. package/src/lib/triage/launch.ts +52 -0
  31. package/src/lib/triage/prepare.ts +97 -0
  32. package/src/lib/triage/session.ts +126 -0
  33. package/src/opencode/companion-hooks.ts +53 -5
  34. package/src/opencode/projected-guidance.ts +2 -0
  35. package/src/playbooks/companion-guidance.ts +2 -2
  36. package/src/plugin-api.ts +5 -0
  37. package/src/runtime/command-friction.ts +97 -0
  38. package/src/runtime/companion-guidance.ts +32 -15
  39. package/src/runtime/friction-fingerprint.ts +35 -0
  40. package/src/runtime/friction-log.ts +352 -0
  41. package/src/runtime/friction-recorder.ts +199 -0
  42. package/src/runtime/friction-retention.ts +1 -0
  43. package/src/runtime/friction-state.ts +110 -0
  44. package/src/runtime/friction-switch.ts +26 -0
  45. package/src/runtime/friction-vocabulary.ts +42 -0
  46. package/src/runtime/projected-guidance.ts +2 -1
  47. package/src/runtime/secret-values.ts +16 -0
  48. package/src/runtime/session-id.ts +24 -0
  49. package/src/runtime/session-prepare-runner.ts +3 -0
  50. package/src/runtime/workflow/next-handoff-process.ts +2 -1
  51. package/src/studio.ts +41 -0
  52. package/src/templates/triage/PLAYBOOK.md +112 -0
  53. package/src/tools/setup/capabilities/rtk.ts +19 -8
  54. package/src/tools/setup/plugin.ts +5 -0
  55. package/src/tools/setup/service.ts +4 -0
  56. package/src/tools/setup.ts +16 -2
  57. package/studio-dist/client/assets/app-aIwDxf48.css +2 -0
  58. package/studio-dist/client/assets/button-CX0sWAJl.js +1 -0
  59. package/studio-dist/client/assets/combobox-BmA8RjOc.js +1 -0
  60. package/studio-dist/client/assets/{companion-view-BVaZNtiI.js → companion-view-DINdPF-b.js} +1 -1
  61. package/studio-dist/client/assets/fields-BobQ7zRF.js +1 -0
  62. package/studio-dist/client/assets/friction-YdYd3zaz.js +1 -0
  63. package/studio-dist/client/assets/getting-started-CY7NEtTw.js +1 -0
  64. package/studio-dist/client/assets/getting-started-djaQeWlu.js +1 -0
  65. package/studio-dist/client/assets/getting-started._topic-DVB8e5R9.js +1 -0
  66. package/studio-dist/client/assets/getting-started.index-DQvLHEr1.js +1 -0
  67. package/studio-dist/client/assets/graph-DbNnR884.js +2 -0
  68. package/studio-dist/client/assets/{graph-canvas-DDuzsNSx.js → graph-canvas-DIcAqwtK.js} +1 -1
  69. package/studio-dist/client/assets/guides-D6T6W_jV.js +1 -0
  70. package/studio-dist/client/assets/index-CysBCSxM.js +40 -0
  71. package/studio-dist/client/assets/markdown-view-jMiaBTSO.js +1 -0
  72. package/studio-dist/client/assets/{panel-B8F8sOKQ.js → panel-Csr49lBo.js} +1 -1
  73. package/studio-dist/client/assets/plugins._service._view-CEA_CcPe.js +1 -0
  74. package/studio-dist/client/assets/prepaint-CKsXyJOR.js +27 -0
  75. package/studio-dist/client/assets/{queries-axYk2u9L.js → queries-Dfp5deWj.js} +1 -1
  76. package/studio-dist/client/assets/react-BYUSgtBs.js +1 -0
  77. package/studio-dist/client/assets/reports-CLdgxxkg.js +1 -0
  78. package/studio-dist/client/assets/routes-DGilWbDE.js +1 -0
  79. package/studio-dist/client/assets/search-CXosfvYh.js +1 -0
  80. package/studio-dist/client/assets/select-DdebbX7K.js +1 -0
  81. package/studio-dist/client/assets/skills-C3zNkU8g.js +1 -0
  82. package/studio-dist/client/assets/{specs-DU1kqcp5.js → specs-Dl8HfGlU.js} +1 -1
  83. package/studio-dist/client/assets/specs-view-B_n0Pekv.js +1 -0
  84. package/studio-dist/client/assets/{steps-DhIFuAZy.js → steps-CKUno4lh.js} +1 -1
  85. package/studio-dist/client/assets/store-DyXbi6o9.js +1 -0
  86. package/studio-dist/client/assets/{studio-BR9j15J0.js → studio-0ueISxwP.js} +8 -8
  87. package/studio-dist/client/assets/{studio-queries-CFP_yTpr.js → studio-queries-BflKt9va.js} +2 -2
  88. package/studio-dist/client/assets/{usage-CHmwtkoM.js → usage-Blcl8kA_.js} +16 -16
  89. package/studio-dist/client/assets/useAnchoredPopupScrollLock-BBXJpX5L.js +1 -0
  90. package/studio-dist/client/assets/{useBaseQuery-BlC-AZ35.js → useBaseQuery-C2cjmeH2.js} +1 -1
  91. package/studio-dist/client/assets/useMutation-DI6LbvVa.js +1 -0
  92. package/studio-dist/client/assets/vault-Cb9DmM1i.js +1 -0
  93. package/studio-dist/client/assets/warnings-B-rvoW8q.js +1 -0
  94. package/studio-dist/client/assets/workflow-DN5T19jd.js +1 -0
  95. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-DAbZ6fzY.js → __23tanstack-start-server-fn-resolver-JoHQ5ihx.js} +30 -14
  96. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +66 -50
  97. package/studio-dist/server/assets/{button-BfoNadNR.js → button-B7e1fRyW.js} +228 -3
  98. package/studio-dist/server/assets/combobox--S_OmUfh.js +483 -0
  99. package/studio-dist/server/assets/{companion-view-DHUjPpA0.js → companion-view-D-vGM55e.js} +2 -2
  100. package/studio-dist/server/assets/{companions-kBrJZAd6.js → companions-Dr6IpNAb.js} +1 -1
  101. package/studio-dist/server/assets/{fields-BD_c65T1.js → fields-B4qM2ZwC.js} +1 -1
  102. package/studio-dist/server/assets/friction-CWOTjpCV.js +62 -0
  103. package/studio-dist/server/assets/friction-sLxaWY-H.js +903 -0
  104. package/studio-dist/server/assets/{getting-started-7P0oyWaM.js → getting-started-Cq5Pcnsr.js} +2 -2
  105. package/studio-dist/server/assets/{getting-started._topic-B1mV0kGz.js → getting-started._topic-CmWdl3u3.js} +2 -2
  106. package/studio-dist/server/assets/{getting-started.index-CeGtvUsm.js → getting-started.index-AB8xpTFY.js} +2 -2
  107. package/studio-dist/server/assets/{graph-BWtmJOH2.js → graph-B11ITte0.js} +1 -1
  108. package/studio-dist/server/assets/{graph-DSDVEELZ.js → graph-C_Hn-Wf_.js} +7 -8
  109. package/studio-dist/server/assets/{graph-canvas-CID9Nksc.js → graph-canvas-BthrSmPS.js} +2 -2
  110. package/studio-dist/server/assets/{guides-Bm3RbUB-.js → guides-B8HdeK_C.js} +1 -1
  111. package/studio-dist/server/assets/{guides-BLJenHwQ.js → guides-BVQ4pt5B.js} +1 -1
  112. package/studio-dist/server/assets/{guides.server-rHHqRuzV.js → guides.server-DqFQAStf.js} +1 -1
  113. package/studio-dist/server/assets/{markdown-view-D3v9x-cM.js → markdown-view-rwiiVcPC.js} +1 -1
  114. package/studio-dist/server/assets/{panel-yqOl5GMU.js → panel-CUxRIpYL.js} +3 -3
  115. package/studio-dist/server/assets/{plugins._service._view-DwqJX7s9.js → plugins._service._view-BSvGnlhU.js} +6 -4
  116. package/studio-dist/server/assets/prepaint-B28ClcPN.js +45 -0
  117. package/studio-dist/server/assets/{queries-DYmGrhNO.js → queries-S_Pl90IG.js} +1 -1
  118. package/studio-dist/server/assets/react-CiBZPDs8.js +45 -0
  119. package/studio-dist/server/assets/{reports-C4Y_Jd-x.js → reports-B9k98oE6.js} +1 -1
  120. package/studio-dist/server/assets/{reports-7yaPz7aP.js → reports-CJpAItPk.js} +6 -7
  121. package/studio-dist/server/assets/{router-Dnoq5auE.js → router-DF0etoNa.js} +627 -1563
  122. package/studio-dist/server/assets/{routes-Cok4p3mK.js → routes-6ylCLkyg.js} +7 -8
  123. package/studio-dist/server/assets/{search-DUK7Jl6f.js → search-b-yQesv3.js} +25 -2
  124. package/studio-dist/server/assets/{combobox-oxUI6r4V.js → select-CjuKScan.js} +34 -514
  125. package/studio-dist/server/assets/{shell-DNVXedgE.js → shell-DLkP7wG9.js} +2 -2
  126. package/studio-dist/server/assets/{skills-pKmuAs0F.js → skills-DGg0mWDM.js} +1 -1
  127. package/studio-dist/server/assets/{skills-D8qdXSku.js → skills-zeU80A9S.js} +7 -8
  128. package/studio-dist/server/assets/{specs-DeHYUNFp.js → specs-DDBNT_v1.js} +4 -4
  129. package/studio-dist/server/assets/{specs-view-BGn-5Ik_.js → specs-view-exvmWdg0.js} +9 -9
  130. package/studio-dist/server/assets/{steps-CV7Yk7L7.js → steps-D1tYAyWZ.js} +1 -1
  131. package/studio-dist/server/assets/store-kS7zk0Hr.js +93 -0
  132. package/studio-dist/server/assets/{studio-CB94np48.js → studio-qRvQjRpz.js} +47 -2
  133. package/studio-dist/server/assets/{studio-queries-BqZGBE70.js → studio-queries-qOXOYoPt.js} +66 -8
  134. package/studio-dist/server/assets/{usage-M6Gi6Km7.js → usage-C2um7YiV.js} +12 -43
  135. package/studio-dist/server/assets/{usage-j5jR9gX9.js → usage-Cwle9-xY.js} +1 -1
  136. package/studio-dist/server/assets/useAnchoredPopupScrollLock-kQBB3y_b.js +756 -0
  137. package/studio-dist/server/assets/{useBaseQuery-Tv_QJt9r.js → useBaseQuery--iH3rd-T.js} +1 -1
  138. package/studio-dist/server/assets/useMutation-C-WO6hCM.js +690 -0
  139. package/studio-dist/server/assets/{vault-PqVmssmW.js → vault-B8vgVIH9.js} +6 -6
  140. package/studio-dist/server/assets/{vault-lBlvSyD4.js → vault-CEBBRLMb.js} +1 -1
  141. package/studio-dist/server/assets/{views-CsFp1i1G.js → views-UgO0Qz_g.js} +2 -2
  142. package/studio-dist/server/assets/{warnings-BDs34j_m.js → warnings-BxK4VfV5.js} +1 -2
  143. package/studio-dist/server/assets/{workflow-T0eEldsa.js → workflow-BrTK632u.js} +8 -9
  144. package/studio-dist/server/server.js +2 -2
  145. package/studio-dist/client/assets/app-BFVyWHGo.css +0 -2
  146. package/studio-dist/client/assets/button-D6LrRkOG.js +0 -1
  147. package/studio-dist/client/assets/combobox-Dk2MMZWE.js +0 -1
  148. package/studio-dist/client/assets/fields-D_FYhxQr.js +0 -1
  149. package/studio-dist/client/assets/getting-started-ByWRg7hC.js +0 -1
  150. package/studio-dist/client/assets/getting-started-DZSjYC-b.js +0 -1
  151. package/studio-dist/client/assets/getting-started._topic-C6OyQ4G6.js +0 -1
  152. package/studio-dist/client/assets/getting-started.index-BkmPHdEm.js +0 -1
  153. package/studio-dist/client/assets/graph-7jm2XzyL.js +0 -2
  154. package/studio-dist/client/assets/guides-D9VTjWXP.js +0 -1
  155. package/studio-dist/client/assets/index-BBmFpG4y.js +0 -40
  156. package/studio-dist/client/assets/markdown-view-RL5YvfZg.js +0 -1
  157. package/studio-dist/client/assets/plugins._service._view-CynxTbMx.js +0 -1
  158. package/studio-dist/client/assets/react-r45OnJCw.js +0 -27
  159. package/studio-dist/client/assets/reports-BCAyXh6p.js +0 -1
  160. package/studio-dist/client/assets/routes-BFPqq89E.js +0 -1
  161. package/studio-dist/client/assets/skills-DTks_uBx.js +0 -1
  162. package/studio-dist/client/assets/specs-view-omrd_5P3.js +0 -1
  163. package/studio-dist/client/assets/store-DJ5cncKA.js +0 -1
  164. package/studio-dist/client/assets/vault-DRg8MScm.js +0 -1
  165. package/studio-dist/client/assets/warnings-UHFy6HAp.js +0 -1
  166. package/studio-dist/client/assets/workflow-Bv9vSfVV.js +0 -1
  167. package/studio-dist/server/assets/react-BO0uMhpm.js +0 -89
  168. package/studio-dist/server/assets/store-CWDGIp6x.js +0 -280
@@ -0,0 +1,903 @@
1
+ import { S as useRetryFocus, _ as useMarkFriction, b as RecordingReach, f as Route, g as frictionQuery, h as useBrowser, v as useSetFrictionRecording, x as RecordingState, y as RecordingButton } from "./router-DF0etoNa.js";
2
+ import { B as keepPreviousData } from "./studio-queries-qOXOYoPt.js";
3
+ import { Lr as cn, et as CommandLine, it as PAGE_PAD, lt as StatusWord, nt as EmptyNote, ot as Pills, r as Icon, rt as ListCard, t as Button, tt as Count, ut as ViewLoading, zr as useQuery } from "./button-B7e1fRyW.js";
4
+ import { _ as REPORT_KINDS, h as FRICTION_STATES, m as selectFriction$1, y as SUBJECT_TYPES } from "./studio-qRvQjRpz.js";
5
+ import { n as require_react, o as __toESM, t as require_jsx_runtime } from "./jsx-runtime-Bt0s0YKS.js";
6
+ import { a as Select, c as SelectTrigger, l as SelectValue, o as SelectContent, s as SelectItem } from "./select-CjuKScan.js";
7
+ import { a as FRICTION_VIEW_DAYS, n as oneOf } from "./search-b-yQesv3.js";
8
+ import { t as Input } from "./fields-B4qM2ZwC.js";
9
+ // ../mate-core/src/runtime/framework.ts
10
+ /**
11
+ * Framework identity: names everything identity-shaped — state directories
12
+ * (`~/.mate`, `.mate/`), managed-block markers, `MATE_*` env values, usage
13
+ * output, command hints, error prefixes, agent guidance, and permission
14
+ * entries. The distribution is always invoked as `mate`.
15
+ *
16
+ * Lives under `runtime/` because the import-isolated runtime subpath derives
17
+ * repo-local `.mate/` paths from it; `../framework` re-exports it.
18
+ */
19
+ var FRAMEWORK_NAME = "mate";
20
+ // src/views/friction/mark-actions.tsx
21
+ var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
22
+ var import_jsx_runtime = require_jsx_runtime();
23
+ var STATE_WORDS = {
24
+ fixed: {
25
+ label: "Fixed",
26
+ marker: "done"
27
+ },
28
+ reported: {
29
+ label: "Reported",
30
+ marker: "review"
31
+ },
32
+ dismissed: {
33
+ label: "Dismissed",
34
+ marker: "idle"
35
+ }
36
+ };
37
+ var BY = {
38
+ person: "by a person",
39
+ triage: "by triage",
40
+ studio: "in Studio"
41
+ };
42
+ var plural = (count, noun) => `${count} ${noun}${count === 1 ? "" : "s"}`;
43
+ /** The item's Friction State as one word with its marker; nothing for an unmarked item. */
44
+ function StateWord({ state }) {
45
+ if (!state) return null;
46
+ const word = STATE_WORDS[state.state];
47
+ return state.reopened ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusWord, {
48
+ marker: "warn",
49
+ children: "Reopened"
50
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusWord, {
51
+ marker: word.marker,
52
+ children: word.label
53
+ });
54
+ }
55
+ function ItemState({ state, time }) {
56
+ const word = STATE_WORDS[state.state];
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
58
+ className: "m-0 flex flex-wrap items-baseline gap-x-3 gap-y-1 text-xs text-muted",
59
+ children: [
60
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StateWord, { state }),
61
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
62
+ state.reopened ? "Fixed, then recorded again; marked " : `${word.label} `,
63
+ BY[state.by],
64
+ " ",
65
+ time
66
+ ] }),
67
+ state.state === "reported" && state.eventsSince !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
68
+ className: "tabular-nums",
69
+ children: [plural(state.eventsSince, "event"), " since reported"]
70
+ }) : null,
71
+ state.link ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
72
+ href: state.link,
73
+ target: "_blank",
74
+ rel: "noreferrer",
75
+ className: "text-text underline",
76
+ children: state.link
77
+ }) : null,
78
+ state.note ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
79
+ className: "text-text",
80
+ children: state.note
81
+ }) : null
82
+ ]
83
+ });
84
+ }
85
+ var NOTE = {
86
+ label: "Note (optional)",
87
+ key: "note",
88
+ type: "text"
89
+ };
90
+ var MARKS = {
91
+ fixed: {
92
+ action: "Mark fixed",
93
+ field: NOTE
94
+ },
95
+ reported: {
96
+ action: "Mark reported",
97
+ field: {
98
+ label: "Issue link (optional)",
99
+ key: "link",
100
+ type: "url"
101
+ }
102
+ },
103
+ dismissed: {
104
+ action: "Dismiss",
105
+ field: NOTE
106
+ }
107
+ };
108
+ function MarkActions({ name, handled, onMark }) {
109
+ const [draft, setDraft] = (0, import_react.useState)(null);
110
+ const [text, setText] = (0, import_react.useState)("");
111
+ const [pending, setPending] = (0, import_react.useState)(false);
112
+ const [refusal, setRefusal] = (0, import_react.useState)(null);
113
+ const fieldId = (0, import_react.useId)();
114
+ const field = (0, import_react.useRef)(null);
115
+ const openers = (0, import_react.useRef)({});
116
+ const cancelled = (0, import_react.useRef)(null);
117
+ (0, import_react.useEffect)(() => {
118
+ if (draft) field.current?.focus();
119
+ else if (cancelled.current) openers.current[cancelled.current]?.focus();
120
+ cancelled.current = null;
121
+ }, [draft]);
122
+ const close = () => {
123
+ setDraft(null);
124
+ setText("");
125
+ setRefusal(null);
126
+ };
127
+ const cancel = () => {
128
+ if (pending) return;
129
+ cancelled.current = draft;
130
+ close();
131
+ };
132
+ async function submit(state, input = {}) {
133
+ setPending(true);
134
+ setRefusal(null);
135
+ const refused = await onMark(state, input);
136
+ setPending(false);
137
+ if (refused) setRefusal(refused);
138
+ else close();
139
+ }
140
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
141
+ className: "grid gap-1.5",
142
+ children: [draft ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", {
143
+ "aria-label": `${MARKS[draft].action}: ${name}`,
144
+ className: "flex flex-wrap items-end gap-2",
145
+ onSubmit: (event) => {
146
+ event.preventDefault();
147
+ submit(draft, { [MARKS[draft].field.key]: text });
148
+ },
149
+ onKeyDown: (event) => {
150
+ if (event.key === "Escape") cancel();
151
+ },
152
+ children: [
153
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
154
+ htmlFor: fieldId,
155
+ className: "grid gap-1 text-xs text-muted",
156
+ children: [MARKS[draft].field.label, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input, {
157
+ id: fieldId,
158
+ ref: field,
159
+ type: MARKS[draft].field.type,
160
+ value: text,
161
+ onChange: (event) => setText(event.target.value),
162
+ className: "h-8 w-72 max-w-full"
163
+ })]
164
+ }),
165
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
166
+ size: "sm",
167
+ variant: "primary",
168
+ type: "submit",
169
+ disabled: pending,
170
+ children: MARKS[draft].action
171
+ }),
172
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
173
+ size: "sm",
174
+ onClick: cancel,
175
+ disabled: pending,
176
+ children: "Cancel"
177
+ })
178
+ ]
179
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
180
+ role: "group",
181
+ "aria-label": `Mark ${name}`,
182
+ className: "flex flex-wrap gap-2",
183
+ children: [FRICTION_STATES.map((state) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
184
+ ref: (button) => {
185
+ openers.current[state] = button;
186
+ },
187
+ size: "sm",
188
+ disabled: pending,
189
+ onClick: () => setDraft(state),
190
+ children: MARKS[state].action
191
+ }, state)), handled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
192
+ size: "sm",
193
+ disabled: pending,
194
+ onClick: () => void submit("open"),
195
+ children: "Reopen"
196
+ }) : null]
197
+ }), refusal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
198
+ className: "m-0 max-w-[70ch] text-xs text-bad",
199
+ role: "alert",
200
+ children: refusal
201
+ }) : null]
202
+ });
203
+ }
204
+ // src/views/friction/select-friction.ts
205
+ var DEFAULT_FRICTION_FILTERS = {
206
+ state: "open",
207
+ sort: "repeats"
208
+ };
209
+ function filtersFromSearch(search) {
210
+ return {
211
+ state: search.frictionState ?? DEFAULT_FRICTION_FILTERS.state,
212
+ type: search.frictionType,
213
+ kind: search.frictionKind,
214
+ sort: search.frictionSort ?? DEFAULT_FRICTION_FILTERS.sort
215
+ };
216
+ }
217
+ /** Defaults leave the address, so it stays short. */
218
+ function searchFromFilters(filters) {
219
+ return {
220
+ frictionState: filters.state === DEFAULT_FRICTION_FILTERS.state ? void 0 : filters.state,
221
+ frictionType: filters.type,
222
+ frictionKind: filters.kind,
223
+ frictionSort: filters.sort === DEFAULT_FRICTION_FILTERS.sort ? void 0 : filters.sort
224
+ };
225
+ }
226
+ /** Core's selection in the chosen order; most repeated is the view's own order. */
227
+ function selectFriction(view, filters) {
228
+ const shown = selectFriction$1(view, filters);
229
+ if (filters.sort !== "recent") return shown;
230
+ return {
231
+ ...shown,
232
+ groups: shown.groups.toSorted((a, b) => a.lastSeen < b.lastSeen ? 1 : a.lastSeen > b.lastSeen ? -1 : 0)
233
+ };
234
+ }
235
+ // src/views/friction/friction-view.tsx
236
+ var PERIODS = FRICTION_VIEW_DAYS.map((days) => ({
237
+ value: String(days),
238
+ label: `${days} days`
239
+ }));
240
+ var STATES = [
241
+ {
242
+ value: "open",
243
+ label: "Open"
244
+ },
245
+ {
246
+ value: "handled",
247
+ label: "Handled"
248
+ },
249
+ {
250
+ value: "all",
251
+ label: "All"
252
+ }
253
+ ];
254
+ var ANY = "any";
255
+ var KINDS = [{
256
+ value: ANY,
257
+ label: "All kinds"
258
+ }, ...REPORT_KINDS.map((kind) => ({
259
+ value: kind,
260
+ label: kind
261
+ }))];
262
+ var SORTS = [{
263
+ value: "repeats",
264
+ label: "Most repeated in one session"
265
+ }, {
266
+ value: "recent",
267
+ label: "Most recent"
268
+ }];
269
+ var RECORDED_SECTION = {
270
+ id: "friction-recorded",
271
+ title: "Recorded friction"
272
+ };
273
+ var REPORTS_SECTION = {
274
+ id: "friction-agent-reports",
275
+ title: "Agent reports"
276
+ };
277
+ var DATE_TIME = new Intl.DateTimeFormat(void 0, {
278
+ dateStyle: "medium",
279
+ timeStyle: "short"
280
+ });
281
+ /** Filled in after hydration: the server's time zone may differ from the viewer's. */
282
+ function FrictionTime({ at }) {
283
+ const browser = useBrowser();
284
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("time", {
285
+ dateTime: at,
286
+ children: browser ? DATE_TIME.format(Date.parse(at)) : ""
287
+ });
288
+ }
289
+ var DETAILS = "m-0 grid grid-cols-[max-content_minmax(0,1fr)] items-baseline gap-x-3 gap-y-1 @md:grid-cols-[6rem_minmax(0,1fr)]";
290
+ function Detail({ label, children }) {
291
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", {
292
+ className: "text-muted",
293
+ children: label
294
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", {
295
+ className: "m-0 min-w-0",
296
+ children
297
+ })] });
298
+ }
299
+ function Counted({ label, counts }) {
300
+ const entries = Object.entries(counts);
301
+ if (entries.length === 0) return null;
302
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Detail, {
303
+ label,
304
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
305
+ className: "flex flex-wrap gap-x-3 gap-y-1",
306
+ children: entries.map(([name, count]) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
307
+ className: "font-mono tabular-nums",
308
+ children: [
309
+ name,
310
+ " ",
311
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
312
+ className: "text-muted",
313
+ children: ["×", count]
314
+ })
315
+ ]
316
+ }, name))
317
+ })
318
+ });
319
+ }
320
+ function ItemFooter({ name, item, onMark }) {
321
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
322
+ className: "mt-1 grid gap-1.5",
323
+ children: [item.state ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ItemState, {
324
+ state: item.state,
325
+ time: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FrictionTime, { at: item.state.at })
326
+ }) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MarkActions, {
327
+ name,
328
+ handled: !item.open,
329
+ onMark
330
+ })]
331
+ });
332
+ }
333
+ function Fields({ fields }) {
334
+ const shown = fields.filter(([, text]) => text);
335
+ if (shown.length === 0) return null;
336
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dl", {
337
+ className: cn(DETAILS, "max-w-[70ch] text-sm"),
338
+ children: shown.map(([label, text]) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Detail, {
339
+ label,
340
+ children: text
341
+ }, label))
342
+ });
343
+ }
344
+ function Row({ focusKey, line, summary, children }) {
345
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", {
346
+ className: "border-t border-rule-soft first:border-t-0",
347
+ "data-friction-item": focusKey,
348
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("details", {
349
+ className: "group/friction",
350
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("summary", {
351
+ className: "grid cursor-pointer list-none grid-cols-[auto_minmax(0,1fr)] gap-x-2 px-4 py-2.5 hover:bg-surface focus-visible:-outline-offset-2 [&::-webkit-details-marker]:hidden",
352
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, {
353
+ name: "right",
354
+ className: "mt-1 size-3.5 text-muted transition-transform group-open/friction:rotate-90 motion-reduce:transition-none"
355
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
356
+ className: cn("flex min-w-0 flex-wrap items-baseline gap-x-4 gap-y-1", line),
357
+ children: summary
358
+ })]
359
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
360
+ className: "mr-4 mb-3 ml-9.5 grid gap-1.5 border-l border-rule-soft pl-3",
361
+ children
362
+ })]
363
+ })
364
+ });
365
+ }
366
+ var FACTS = "flex flex-wrap items-baseline gap-x-3 gap-y-0.5 font-mono text-xs whitespace-nowrap text-muted tabular-nums";
367
+ var LAST_SEEN_TRACK = "minmax(32ch,max-content)";
368
+ var AT_TRACK = "minmax(22ch,max-content)";
369
+ var STATE_TRACK = "11ch";
370
+ function Gap({ wide }) {
371
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
372
+ "aria-hidden": "true",
373
+ className: cn("hidden", wide)
374
+ });
375
+ }
376
+ function groupCounts(group) {
377
+ return [
378
+ `at most ${group.maxPerSession} in one session`,
379
+ plural(group.events, "event"),
380
+ plural(group.sessions, "session"),
381
+ group.reports.length > 0 ? plural(group.reports.length, "report") : null
382
+ ];
383
+ }
384
+ function groupTracks(groups, columns) {
385
+ const counts = groups.map(groupCounts);
386
+ const widest = (column) => Math.max(...counts.map((row) => row[column]?.length ?? 0), 0);
387
+ const tracks = [
388
+ 0,
389
+ 1,
390
+ 2
391
+ ].map((column) => `${widest(column)}ch`);
392
+ if (columns.reports) tracks.push(`${widest(3)}ch`);
393
+ tracks.push(LAST_SEEN_TRACK);
394
+ if (columns.state) tracks.push(STATE_TRACK);
395
+ return tracks.join(" ");
396
+ }
397
+ function reportTracks(stateColumn) {
398
+ return stateColumn ? `${AT_TRACK} ${STATE_TRACK}` : AT_TRACK;
399
+ }
400
+ var factsStyle = (tracks) => ({ "--friction-facts": tracks });
401
+ function StateCell({ state, column, wide }) {
402
+ if (state) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
403
+ className: "font-sans",
404
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StateWord, { state })
405
+ });
406
+ return column ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Gap, { wide }) : null;
407
+ }
408
+ function GroupItem({ group, columns, onMark }) {
409
+ const [peak, events, sessions, reports] = groupCounts(group);
410
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Row, {
411
+ focusKey: group.fingerprint,
412
+ line: "@5xl:grid @5xl:grid-cols-[minmax(0,1fr)_auto]",
413
+ summary: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
414
+ className: "m-0 min-w-0 flex-[1_1_16rem] text-base font-semibold",
415
+ children: group.title
416
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
417
+ className: cn(FACTS, "@3xl:grid @3xl:grid-cols-(--friction-facts)"),
418
+ children: [
419
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: peak }),
420
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: events }),
421
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: sessions }),
422
+ reports ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: reports }) : columns.reports ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Gap, { wide: "@3xl:block" }) : null,
423
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: ["last seen ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FrictionTime, { at: group.lastSeen })] }),
424
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StateCell, {
425
+ state: group.state,
426
+ column: columns.state,
427
+ wide: "@3xl:block"
428
+ })
429
+ ]
430
+ })] }),
431
+ children: [
432
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("dl", {
433
+ className: cn(DETAILS, "text-xs"),
434
+ children: [
435
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Detail, {
436
+ label: "Fingerprint",
437
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", {
438
+ className: "font-mono",
439
+ children: group.fingerprint
440
+ })
441
+ }),
442
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Detail, {
443
+ label: "First seen",
444
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FrictionTime, { at: group.firstSeen })
445
+ }),
446
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Detail, {
447
+ label: "Last seen",
448
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FrictionTime, { at: group.lastSeen })
449
+ }),
450
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Counted, {
451
+ label: "Mate",
452
+ counts: group.versions
453
+ }),
454
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Counted, {
455
+ label: "Paths",
456
+ counts: group.paths
457
+ }),
458
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Counted, {
459
+ label: "Flags",
460
+ counts: group.flags
461
+ })
462
+ ]
463
+ }),
464
+ group.reports.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
465
+ "aria-label": `Reports on ${group.title}`,
466
+ className: "mt-1",
467
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", {
468
+ className: "m-0 text-xs font-semibold text-muted",
469
+ children: plural(group.reports.length, "report")
470
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
471
+ className: "m-0 list-none p-0",
472
+ children: group.reports.map((report) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", {
473
+ className: "grid gap-1 border-t border-rule-soft py-2 first:border-t-0",
474
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
475
+ className: "flex flex-wrap items-baseline gap-x-2 text-xs text-muted",
476
+ children: [
477
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
478
+ className: "font-semibold text-text",
479
+ children: report.kind
480
+ }),
481
+ report.cost ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: report.cost }) : null,
482
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FrictionTime, { at: report.at })
483
+ ]
484
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Fields, { fields: [
485
+ ["Expected", report.expected],
486
+ ["Evidence", report.evidence],
487
+ ["Workaround", report.workaround]
488
+ ] })]
489
+ }, report.id))
490
+ })]
491
+ }) : null,
492
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ItemFooter, {
493
+ name: group.title,
494
+ item: group,
495
+ onMark
496
+ })
497
+ ]
498
+ });
499
+ }
500
+ function FreeReportItem({ report, stateColumn, onMark }) {
501
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Row, {
502
+ focusKey: report.id,
503
+ line: "@3xl:grid @3xl:grid-cols-[minmax(0,1fr)_auto]",
504
+ summary: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
505
+ className: "flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-1",
506
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
507
+ className: "m-0 min-w-0 font-mono text-sm leading-[1.375rem] font-semibold",
508
+ children: report.subject
509
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
510
+ className: "rounded-full border border-rule bg-page px-2 font-mono text-[0.7rem] text-text",
511
+ children: report.kind
512
+ })]
513
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
514
+ className: cn(FACTS, "@3xl:grid @3xl:grid-cols-(--friction-facts)"),
515
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(FrictionTime, { at: report.at }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StateCell, {
516
+ state: report.state,
517
+ column: stateColumn,
518
+ wide: "@3xl:block"
519
+ })]
520
+ })] }),
521
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Fields, { fields: [
522
+ ["Expected", report.expected],
523
+ ["Cost", report.cost],
524
+ ["Evidence", report.evidence],
525
+ ["Workaround", report.workaround]
526
+ ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ItemFooter, {
527
+ name: report.subject,
528
+ item: report,
529
+ onMark
530
+ })]
531
+ });
532
+ }
533
+ function Hidden({ hidden, onShowAll }) {
534
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
535
+ hidden === 1 ? "1 item is" : `${hidden} items are`,
536
+ " hidden by the filters.",
537
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
538
+ size: "sm",
539
+ onClick: onShowAll,
540
+ "data-show-all": true,
541
+ "aria-label": `Show all, including ${plural(hidden, "hidden item")}`,
542
+ children: "Show all"
543
+ })
544
+ ] });
545
+ }
546
+ function Overview({ view, shown, empty, onShowAll }) {
547
+ const sections = [[RECORDED_SECTION, shown.groups.length], [REPORTS_SECTION, shown.freeReports.length]];
548
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
549
+ "aria-label": "Overview",
550
+ className: "grid gap-2 text-sm",
551
+ children: [
552
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
553
+ className: "flex flex-wrap items-baseline gap-x-5 gap-y-1",
554
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
555
+ className: "m-0",
556
+ children: [
557
+ plural(view.events, "event"),
558
+ " in ",
559
+ plural(view.sessions, "session"),
560
+ " in the last",
561
+ " ",
562
+ view.days,
563
+ " days for the selected companion."
564
+ ]
565
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("nav", {
566
+ "aria-label": "Friction sections",
567
+ className: "flex flex-wrap gap-x-4 gap-y-1",
568
+ children: sections.map(([{ id, title }, count]) => count > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("a", {
569
+ href: `#${id}`,
570
+ className: "inline-flex items-center gap-1.5 rounded-control underline",
571
+ children: [title, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Count, { value: count })]
572
+ }, id) : null)
573
+ })]
574
+ }),
575
+ !empty && shown.hidden > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
576
+ className: "m-0 flex flex-wrap items-center gap-2 text-muted",
577
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Hidden, {
578
+ hidden: shown.hidden,
579
+ onShowAll
580
+ })
581
+ }) : null,
582
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
583
+ className: "flex flex-wrap items-center gap-x-3 gap-y-2",
584
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
585
+ className: "m-0 text-muted",
586
+ children: "To investigate, run this in your own terminal, inside the affected repository:"
587
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
588
+ className: "w-48 max-w-full",
589
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CommandLine, {
590
+ text: `${FRAMEWORK_NAME} triage`,
591
+ label: "command"
592
+ })
593
+ })]
594
+ })
595
+ ]
596
+ });
597
+ }
598
+ function Recording({ recording, toggle, button }) {
599
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
600
+ className: "grid gap-1",
601
+ children: [
602
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
603
+ className: "flex flex-wrap items-center gap-3",
604
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecordingState, { recording }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecordingButton, {
605
+ ref: button,
606
+ recording,
607
+ toggle
608
+ })]
609
+ }),
610
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecordingReach, {}),
611
+ toggle.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
612
+ className: "m-0 text-sm text-bad",
613
+ role: "alert",
614
+ children: toggle.error
615
+ }) : null
616
+ ]
617
+ });
618
+ }
619
+ function FilterSelect({ label, options, value, onChange, note, disabled }) {
620
+ const id = (0, import_react.useId)();
621
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
622
+ className: "flex items-center gap-2",
623
+ children: [
624
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
625
+ htmlFor: id,
626
+ className: "text-xs text-muted",
627
+ children: label
628
+ }),
629
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Select, {
630
+ items: options,
631
+ value,
632
+ disabled,
633
+ onValueChange: (next) => {
634
+ if (next !== null) onChange(next);
635
+ },
636
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectTrigger, {
637
+ id,
638
+ "aria-describedby": note ? `${id}-note` : void 0,
639
+ className: "h-7 w-auto",
640
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectValue, {})
641
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectContent, { children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItem, {
642
+ value: option.value,
643
+ children: option.label
644
+ }, option.value)) })]
645
+ }),
646
+ note ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
647
+ id: `${id}-note`,
648
+ className: "text-xs text-muted",
649
+ children: note
650
+ }) : null
651
+ ]
652
+ });
653
+ }
654
+ function Filters({ view, shown, filters, onFilters }) {
655
+ const types = [{
656
+ value: ANY,
657
+ label: "All types"
658
+ }, ...shown.types.map((type) => ({
659
+ value: type,
660
+ label: type
661
+ }))];
662
+ const noReports = selectFriction(view, {
663
+ ...filters,
664
+ kind: void 0
665
+ }).freeReports.length === 0;
666
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
667
+ className: "flex flex-wrap items-center gap-x-5 gap-y-2",
668
+ children: [
669
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FilterSelect, {
670
+ label: "Type",
671
+ options: types,
672
+ value: shown.type ?? ANY,
673
+ onChange: (type) => onFilters({
674
+ ...filters,
675
+ type: oneOf(SUBJECT_TYPES, type)
676
+ })
677
+ }),
678
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FilterSelect, {
679
+ label: "Kind",
680
+ options: KINDS,
681
+ value: filters.kind ?? ANY,
682
+ onChange: (kind) => onFilters({
683
+ ...filters,
684
+ kind: oneOf(REPORT_KINDS, kind)
685
+ }),
686
+ note: "Agent reports only",
687
+ disabled: noReports && filters.kind === void 0
688
+ }),
689
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FilterSelect, {
690
+ label: "Sort",
691
+ options: SORTS,
692
+ value: filters.sort,
693
+ onChange: (sort) => onFilters({
694
+ ...filters,
695
+ sort
696
+ })
697
+ })
698
+ ]
699
+ });
700
+ }
701
+ function Lists({ shown, empty, markItem, onShowAll }) {
702
+ if (empty) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(EmptyNote, {
703
+ className: "flex flex-wrap items-center gap-x-3 gap-y-2",
704
+ children: ["No item matches the filters. ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Hidden, {
705
+ hidden: shown.hidden,
706
+ onShowAll
707
+ })]
708
+ });
709
+ const groupColumns = {
710
+ reports: shown.groups.some((group) => group.reports.length > 0),
711
+ state: shown.groups.some((group) => group.state !== null)
712
+ };
713
+ const reportState = shown.freeReports.some((report) => report.state !== null);
714
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
715
+ className: "grid gap-4",
716
+ children: [shown.groups.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ListCard, {
717
+ ...RECORDED_SECTION,
718
+ count: shown.groups.length,
719
+ className: "wrap-anywhere",
720
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
721
+ className: "@container m-0 list-none p-0",
722
+ style: factsStyle(groupTracks(shown.groups, groupColumns)),
723
+ children: shown.groups.map((group) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GroupItem, {
724
+ group,
725
+ columns: groupColumns,
726
+ onMark: markItem(group.fingerprint, group.title)
727
+ }, group.fingerprint))
728
+ })
729
+ }) : null, shown.freeReports.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ListCard, {
730
+ ...REPORTS_SECTION,
731
+ count: shown.freeReports.length,
732
+ hint: "These reports are not attached to a recorded event.",
733
+ className: "wrap-anywhere",
734
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
735
+ className: "@container m-0 list-none p-0",
736
+ style: factsStyle(reportTracks(reportState)),
737
+ children: shown.freeReports.map((report) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FreeReportItem, {
738
+ report,
739
+ stateColumn: reportState,
740
+ onMark: markItem(report.id, report.subject)
741
+ }, report.id))
742
+ })
743
+ }) : null]
744
+ });
745
+ }
746
+ function FrictionPanel({ view, days, onDays, toggle, filters, onFilters, mark, recordingButton }) {
747
+ const recorded = view.events > 0 || view.freeReports.length > 0;
748
+ const shown = selectFriction(view, filters);
749
+ const [marked, setMarked] = (0, import_react.useState)(null);
750
+ const panel = (0, import_react.useRef)(null);
751
+ (0, import_react.useEffect)(() => {
752
+ if (!marked) return;
753
+ const row = (key) => key === null ? null : panel.current?.querySelector(`[data-friction-item="${CSS.escape(key)}"] summary`);
754
+ (row(marked.key) ?? row(marked.next) ?? panel.current?.querySelector("[data-show-all]"))?.focus();
755
+ }, [marked]);
756
+ const markItem = (key, name) => async (state, input) => {
757
+ const order = [...shown.groups.map((group) => group.fingerprint), ...shown.freeReports.map((report) => report.id)];
758
+ const index = order.indexOf(key);
759
+ const next = order[index + 1] ?? order[index - 1] ?? null;
760
+ let result;
761
+ try {
762
+ result = await mark({
763
+ target: key,
764
+ state,
765
+ ...input
766
+ });
767
+ } catch (error) {
768
+ return `The mark could not be saved: ${error instanceof Error ? error.message : String(error)}`;
769
+ }
770
+ if (!result.ok) return result.reason;
771
+ setMarked((last) => ({
772
+ announcementKey: (last?.announcementKey ?? 0) + 1,
773
+ key,
774
+ next,
775
+ message: `${name}: ${state === "open" ? "reopened" : `marked ${state}`}.`
776
+ }));
777
+ return null;
778
+ };
779
+ const showAll = () => {
780
+ [...panel.current?.querySelectorAll("[aria-label=\"State\"] button") ?? []].find((button) => button.textContent === "All")?.focus();
781
+ onFilters({
782
+ state: "all",
783
+ sort: filters.sort
784
+ });
785
+ };
786
+ const empty = shown.groups.length === 0 && shown.freeReports.length === 0;
787
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
788
+ ref: panel,
789
+ className: cn(PAGE_PAD, "grid min-w-0 gap-4 pt-3 pb-6"),
790
+ children: [
791
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Recording, {
792
+ recording: view.recording,
793
+ toggle,
794
+ button: recordingButton
795
+ }),
796
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
797
+ className: "grid gap-2",
798
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
799
+ className: "flex flex-wrap items-center gap-x-5 gap-y-2",
800
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Pills, {
801
+ label: "Period",
802
+ options: PERIODS,
803
+ value: String(days),
804
+ onChange: (value) => onDays(Number(value))
805
+ }), recorded ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Pills, {
806
+ label: "State",
807
+ options: STATES,
808
+ value: filters.state,
809
+ onChange: (state) => onFilters({
810
+ ...filters,
811
+ state
812
+ })
813
+ }) : null]
814
+ }), recorded ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Filters, {
815
+ view,
816
+ shown,
817
+ filters,
818
+ onFilters
819
+ }) : null]
820
+ }),
821
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
822
+ "aria-live": "polite",
823
+ className: "sr-only",
824
+ children: marked ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: marked.message }, marked.announcementKey) : null
825
+ }),
826
+ recorded ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
827
+ view.recording ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
828
+ className: "m-0 text-sm text-muted",
829
+ children: "Recording is off: nothing new is recorded. The records below were made while it was on."
830
+ }),
831
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Overview, {
832
+ view,
833
+ shown,
834
+ empty,
835
+ onShowAll: showAll
836
+ }),
837
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Lists, {
838
+ shown,
839
+ empty,
840
+ markItem,
841
+ onShowAll: showAll
842
+ })
843
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyNote, { children: view.recording ? `No friction was recorded in the last ${view.days} days.` : `Friction recording shows where Mate gets in an agent's way: its refusals and the ${FRAMEWORK_NAME} commands that fail in agent sessions on this machine. Recording is off; turn it on to start.` })
844
+ ]
845
+ });
846
+ }
847
+ function Friction({ companion, days, onDays, filters, onFilters }) {
848
+ const query = useQuery({
849
+ ...frictionQuery(companion, days),
850
+ enabled: useBrowser(),
851
+ placeholderData: keepPreviousData
852
+ });
853
+ const toggle = useSetFrictionRecording();
854
+ const mark = useMarkFriction();
855
+ const { button: recordingButton, retried } = useRetryFocus(query.isSuccess);
856
+ if (!query.data && !query.isError) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ViewLoading, { title: "Reading the Friction Log…" });
857
+ const failed = query.isError ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
858
+ className: cn(PAGE_PAD, "pt-3 text-sm"),
859
+ role: "alert",
860
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
861
+ className: "m-0 text-bad",
862
+ children: "The Friction Log could not be read."
863
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
864
+ className: "mt-3",
865
+ onClick: () => {
866
+ retried();
867
+ query.refetch();
868
+ },
869
+ disabled: query.isFetching,
870
+ children: "Retry"
871
+ })]
872
+ }) : null;
873
+ if (!query.data) return failed;
874
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [failed, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FrictionPanel, {
875
+ view: query.data,
876
+ days,
877
+ onDays,
878
+ toggle,
879
+ filters,
880
+ onFilters,
881
+ mark,
882
+ recordingButton
883
+ })] });
884
+ }
885
+ // src/routes/friction.tsx?tsr-split=component
886
+ var SplitComponent = function FrictionRoute() {
887
+ const search = Route.useSearch();
888
+ const navigate = Route.useNavigate();
889
+ return search.companion ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Friction, {
890
+ companion: search.companion,
891
+ days: search.frictionDays ?? 30,
892
+ onDays: (frictionDays) => void navigate({ search: (previous) => ({
893
+ ...previous,
894
+ frictionDays
895
+ }) }),
896
+ filters: filtersFromSearch(search),
897
+ onFilters: (filters) => void navigate({ search: (previous) => ({
898
+ ...previous,
899
+ ...searchFromFilters(filters)
900
+ }) })
901
+ }, search.companion) : null;
902
+ };
903
+ export { SplitComponent as component };