@developerz.ai/ui-debugger-mcp 1.9.0 → 1.10.0

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 (201) hide show
  1. package/README.md +56 -44
  2. package/dist/adapters/android/adb.d.ts +19 -7
  3. package/dist/adapters/android/adb.js +50 -13
  4. package/dist/adapters/android/adb.js.map +1 -1
  5. package/dist/adapters/android/android-adapter.d.ts +42 -2
  6. package/dist/adapters/android/android-adapter.js +366 -36
  7. package/dist/adapters/android/android-adapter.js.map +1 -1
  8. package/dist/adapters/android/commands.js.map +1 -1
  9. package/dist/adapters/android/ports.js.map +1 -1
  10. package/dist/adapters/android/sdk.d.ts +65 -0
  11. package/dist/adapters/android/sdk.js +107 -0
  12. package/dist/adapters/android/sdk.js.map +1 -0
  13. package/dist/adapters/android/uiautomator.d.ts +23 -7
  14. package/dist/adapters/android/uiautomator.js +31 -7
  15. package/dist/adapters/android/uiautomator.js.map +1 -1
  16. package/dist/adapters/availability.d.ts +39 -0
  17. package/dist/adapters/availability.js +62 -0
  18. package/dist/adapters/availability.js.map +1 -0
  19. package/dist/adapters/browser/browser-adapter.d.ts +11 -22
  20. package/dist/adapters/browser/browser-adapter.js +98 -67
  21. package/dist/adapters/browser/browser-adapter.js.map +1 -1
  22. package/dist/adapters/browser/cdp.d.ts +15 -7
  23. package/dist/adapters/browser/cdp.js +25 -3
  24. package/dist/adapters/browser/cdp.js.map +1 -1
  25. package/dist/adapters/browser/filters.d.ts +1 -1
  26. package/dist/adapters/browser/filters.js.map +1 -1
  27. package/dist/adapters/browser/geometry.js.map +1 -1
  28. package/dist/adapters/browser/launch.d.ts +14 -5
  29. package/dist/adapters/browser/launch.js +14 -5
  30. package/dist/adapters/browser/launch.js.map +1 -1
  31. package/dist/adapters/browser/lifecycle.d.ts +58 -0
  32. package/dist/adapters/browser/lifecycle.js +98 -0
  33. package/dist/adapters/browser/lifecycle.js.map +1 -0
  34. package/dist/adapters/browser/log-filters.d.ts +2 -2
  35. package/dist/adapters/browser/log-filters.js.map +1 -1
  36. package/dist/adapters/browser/log-format.d.ts +14 -23
  37. package/dist/adapters/browser/log-format.js +16 -55
  38. package/dist/adapters/browser/log-format.js.map +1 -1
  39. package/dist/adapters/browser/tab-context.d.ts +30 -0
  40. package/dist/adapters/browser/tab-context.js +41 -0
  41. package/dist/adapters/browser/tab-context.js.map +1 -0
  42. package/dist/adapters/contract.d.ts +91 -5
  43. package/dist/adapters/contract.js +7 -2
  44. package/dist/adapters/contract.js.map +1 -1
  45. package/dist/adapters/desktop/atspi-busctl.d.ts +26 -0
  46. package/dist/adapters/desktop/atspi-busctl.js +330 -0
  47. package/dist/adapters/desktop/atspi-busctl.js.map +1 -0
  48. package/dist/adapters/desktop/atspi-parse.d.ts +39 -0
  49. package/dist/adapters/desktop/atspi-parse.js +155 -0
  50. package/dist/adapters/desktop/atspi-parse.js.map +1 -0
  51. package/dist/adapters/desktop/atspi.d.ts +75 -50
  52. package/dist/adapters/desktop/atspi.js +64 -285
  53. package/dist/adapters/desktop/atspi.js.map +1 -1
  54. package/dist/adapters/desktop/capture.d.ts +11 -20
  55. package/dist/adapters/desktop/capture.js +68 -37
  56. package/dist/adapters/desktop/capture.js.map +1 -1
  57. package/dist/adapters/desktop/desktop-adapter.d.ts +20 -2
  58. package/dist/adapters/desktop/desktop-adapter.js +91 -9
  59. package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
  60. package/dist/adapters/desktop/input.d.ts +18 -4
  61. package/dist/adapters/desktop/input.js +15 -10
  62. package/dist/adapters/desktop/input.js.map +1 -1
  63. package/dist/adapters/desktop/proc.d.ts +32 -4
  64. package/dist/adapters/desktop/proc.js +33 -6
  65. package/dist/adapters/desktop/proc.js.map +1 -1
  66. package/dist/adapters/factory.d.ts +12 -5
  67. package/dist/adapters/factory.js +29 -3
  68. package/dist/adapters/factory.js.map +1 -1
  69. package/dist/adapters/log-format.d.ts +32 -0
  70. package/dist/adapters/log-format.js +39 -0
  71. package/dist/adapters/log-format.js.map +1 -0
  72. package/dist/agent/belt/act.d.ts +421 -21
  73. package/dist/agent/belt/act.js +4 -4
  74. package/dist/agent/belt/act.js.map +1 -1
  75. package/dist/agent/belt/look.d.ts +471 -14
  76. package/dist/agent/belt/look.js +74 -12
  77. package/dist/agent/belt/look.js.map +1 -1
  78. package/dist/agent/belt/observe.d.ts +663 -42
  79. package/dist/agent/belt/observe.js +76 -12
  80. package/dist/agent/belt/observe.js.map +1 -1
  81. package/dist/agent/belt/report.d.ts +754 -48
  82. package/dist/agent/belt/report.js +121 -38
  83. package/dist/agent/belt/report.js.map +1 -1
  84. package/dist/agent/belt/trail.d.ts +44 -16
  85. package/dist/agent/belt/trail.js +46 -11
  86. package/dist/agent/belt/trail.js.map +1 -1
  87. package/dist/agent/capabilities.js.map +1 -1
  88. package/dist/agent/fallback.d.ts +33 -0
  89. package/dist/agent/fallback.js +84 -0
  90. package/dist/agent/fallback.js.map +1 -0
  91. package/dist/agent/loop.d.ts +54 -52
  92. package/dist/agent/loop.js +173 -176
  93. package/dist/agent/loop.js.map +1 -1
  94. package/dist/agent/models.d.ts +10 -6
  95. package/dist/agent/models.js +15 -9
  96. package/dist/agent/models.js.map +1 -1
  97. package/dist/agent/prompts/compose.d.ts +1 -1
  98. package/dist/agent/prompts/debug-agent.js +45 -8
  99. package/dist/agent/prompts/debug-agent.js.map +1 -1
  100. package/dist/agent/prompts/web-addendum.d.ts +1 -1
  101. package/dist/agent/prompts/web-addendum.js +15 -3
  102. package/dist/agent/prompts/web-addendum.js.map +1 -1
  103. package/dist/agent/provider.d.ts +38 -0
  104. package/dist/agent/provider.js +55 -3
  105. package/dist/agent/provider.js.map +1 -1
  106. package/dist/boot.d.ts +64 -0
  107. package/dist/boot.js +145 -0
  108. package/dist/boot.js.map +1 -0
  109. package/dist/cli/chromium-libs.d.ts +262 -0
  110. package/dist/cli/chromium-libs.js +522 -0
  111. package/dist/cli/chromium-libs.js.map +1 -0
  112. package/dist/cli/control.js +51 -9
  113. package/dist/cli/control.js.map +1 -1
  114. package/dist/cli/init.d.ts +52 -3
  115. package/dist/cli/init.js +62 -10
  116. package/dist/cli/init.js.map +1 -1
  117. package/dist/config/load.d.ts +25 -8
  118. package/dist/config/load.js +40 -13
  119. package/dist/config/load.js.map +1 -1
  120. package/dist/config/schema.d.ts +18 -6
  121. package/dist/config/schema.js +22 -7
  122. package/dist/config/schema.js.map +1 -1
  123. package/dist/errors.d.ts +14 -0
  124. package/dist/errors.js +18 -0
  125. package/dist/errors.js.map +1 -1
  126. package/dist/findings/schema.d.ts +44 -6
  127. package/dist/findings/schema.js +39 -3
  128. package/dist/findings/schema.js.map +1 -1
  129. package/dist/index.d.ts +1 -1
  130. package/dist/index.js +1 -1
  131. package/dist/index.js.map +1 -1
  132. package/dist/main.js +4 -82
  133. package/dist/main.js.map +1 -1
  134. package/dist/mcp/server.js.map +1 -1
  135. package/dist/mcp/tools/describe.d.ts +5 -4
  136. package/dist/mcp/tools/describe.js +14 -10
  137. package/dist/mcp/tools/describe.js.map +1 -1
  138. package/dist/mcp/tools/end-session.d.ts +3 -1
  139. package/dist/mcp/tools/end-session.js +7 -3
  140. package/dist/mcp/tools/end-session.js.map +1 -1
  141. package/dist/mcp/tools/output.d.ts +5 -4
  142. package/dist/mcp/tools/output.js +10 -2
  143. package/dist/mcp/tools/output.js.map +1 -1
  144. package/dist/mcp/tools/result.d.ts +10 -1
  145. package/dist/mcp/tools/result.js +8 -6
  146. package/dist/mcp/tools/result.js.map +1 -1
  147. package/dist/mcp/tools/start-debug.js +7 -5
  148. package/dist/mcp/tools/start-debug.js.map +1 -1
  149. package/dist/redact.d.ts +28 -0
  150. package/dist/redact.js +51 -0
  151. package/dist/redact.js.map +1 -0
  152. package/dist/services/catalog.d.ts +28 -0
  153. package/dist/services/catalog.js +65 -0
  154. package/dist/services/catalog.js.map +1 -0
  155. package/dist/services/debug-api.d.ts +172 -0
  156. package/dist/services/debug-api.js +9 -0
  157. package/dist/services/debug-api.js.map +1 -0
  158. package/dist/services/debug-service.d.ts +25 -173
  159. package/dist/services/debug-service.js +108 -175
  160. package/dist/services/debug-service.js.map +1 -1
  161. package/dist/services/login.d.ts +7 -2
  162. package/dist/services/login.js +203 -29
  163. package/dist/services/login.js.map +1 -1
  164. package/dist/services/retained-snapshot.d.ts +36 -0
  165. package/dist/services/retained-snapshot.js +63 -0
  166. package/dist/services/retained-snapshot.js.map +1 -0
  167. package/dist/services/session-builder.d.ts +26 -0
  168. package/dist/services/session-builder.js +46 -19
  169. package/dist/services/session-builder.js.map +1 -1
  170. package/dist/services/start-guards.d.ts +32 -0
  171. package/dist/services/start-guards.js +50 -0
  172. package/dist/services/start-guards.js.map +1 -0
  173. package/dist/services/summarize.d.ts +12 -3
  174. package/dist/services/summarize.js +13 -5
  175. package/dist/services/summarize.js.map +1 -1
  176. package/dist/session/cleanup.js.map +1 -1
  177. package/dist/session/findings-store.d.ts +2 -1
  178. package/dist/session/findings-store.js +30 -2
  179. package/dist/session/findings-store.js.map +1 -1
  180. package/dist/session/live-pointer.d.ts +19 -0
  181. package/dist/session/live-pointer.js +41 -0
  182. package/dist/session/live-pointer.js.map +1 -0
  183. package/dist/session/manager.d.ts +11 -1
  184. package/dist/session/manager.js +46 -2
  185. package/dist/session/manager.js.map +1 -1
  186. package/dist/session/owner-lock.d.ts +208 -0
  187. package/dist/session/owner-lock.js +499 -0
  188. package/dist/session/owner-lock.js.map +1 -0
  189. package/dist/session/process-identity.js.map +1 -1
  190. package/dist/session/session.js +61 -7
  191. package/dist/session/session.js.map +1 -1
  192. package/dist/session/state-file.d.ts +74 -14
  193. package/dist/session/state-file.js +203 -21
  194. package/dist/session/state-file.js.map +1 -1
  195. package/package.json +7 -7
  196. package/dist/adapters/android/android-adapter.test-helpers.d.ts +0 -52
  197. package/dist/adapters/android/android-adapter.test-helpers.js +0 -115
  198. package/dist/adapters/android/android-adapter.test-helpers.js.map +0 -1
  199. package/dist/mcp/server.test-helpers.d.ts +0 -23
  200. package/dist/mcp/server.test-helpers.js +0 -49
  201. package/dist/mcp/server.test-helpers.js.map +0 -1
@@ -15,6 +15,12 @@
15
15
  * sub-schemas (`StepSchema` · `BugSchema` · `VisualIssueSchema`) so the verdict
16
16
  * the driver emits is byte-for-byte the verdict the store persists.
17
17
  *
18
+ * The write MERGES, never replaces: the run's streamed evidence — act steps,
19
+ * console errors, look issues the belt recorded as they happened — is carried
20
+ * into the verdict even when the driver's own arrays omit it. Omission cannot
21
+ * erase evidence; only `dismissStreamed: true` (a deliberate ruling-out) drops
22
+ * unrestated streamed entries.
23
+ *
18
24
  * Store-only seam: it touches just `writeFindings` via the {@link FindingsWriter}
19
25
  * slice — adapter-blind like the rest of the belt. Fails loud: an invalid verdict
20
26
  * surfaces the store's `FindingsError`; we never write a half-formed findings file
@@ -22,15 +28,22 @@
22
28
  */
23
29
  import { tool } from 'ai';
24
30
  import { z } from 'zod';
25
- import { BugSchema, StepSchema, VisualIssueSchema } from '../../findings/schema.js';
26
- /** Terminal verdicts `report` may emit — `running` is excluded (it isn't terminal). */
27
- const TERMINAL_STATUSES = ['passed', 'failed'];
31
+ import { BUG_KINDS, BugSchema, StepSchema, TERMINAL_STATUSES, VisualIssueSchema, } from '../../findings/schema.js';
32
+ import { evidenceKey } from './trail.js';
33
+ /** The empty evidence set — what a run with no wired trail streams. */
34
+ export const EMPTY_EVIDENCE = { steps: [], bugs: [], visual: [] };
28
35
  /**
29
36
  * `report` input — the findings shape with a terminal `status`. Reuses the
30
37
  * canonical findings sub-schemas so the emitted verdict matches what the store
31
38
  * persists; arrays default to `[]` so a clean pass needs only `{ status }`.
32
39
  */
33
40
  export const ReportInputSchema = z.object({
41
+ /**
42
+ * Terminal verdicts `report` may emit — `running` is excluded: it is the
43
+ * in-flight state the session overlays before a verdict exists, and a run
44
+ * that is both concluded and not is a contradiction, so the input schema
45
+ * rejects it.
46
+ */
34
47
  status: z
35
48
  .enum(TERMINAL_STATUSES)
36
49
  .describe('terminal verdict: passed (goal met, no blockers) | failed (blocking bug/visual issue)'),
@@ -41,30 +54,20 @@ export const ReportInputSchema = z.object({
41
54
  bugs: z
42
55
  .array(BugSchema)
43
56
  .default([])
44
- .describe('functional bugs found: { kind: console|network|flow, detail, evidence? }'),
57
+ .describe(`functional bugs found: { kind: ${BUG_KINDS.join('|')}, detail, evidence? }`),
45
58
  visual: z
46
59
  .array(VisualIssueSchema)
47
60
  .default([])
48
61
  .describe('visual issues from look: { issue, where, severity, screenshot? }'),
62
+ dismissStreamed: z
63
+ .boolean()
64
+ .default(false)
65
+ .describe('findings you already surfaced (look issues, console errors) that you did not list above are carried into the verdict; set true ONLY to dismiss them deliberately'),
49
66
  summary: z
50
67
  .string()
51
68
  .optional()
52
69
  .describe('one-paragraph, actionable verdict for the smart agent: what broke, where, what to fix'),
53
70
  });
54
- /**
55
- * Build the canonical findings record from a validated report input. The base
56
- * verdict shape; {@link terminalFindings} merges the loop's recorded act-trail
57
- * into its `steps`, so both the persisted write and the returned counts agree.
58
- */
59
- export function reportFindings(input) {
60
- return {
61
- status: input.status,
62
- steps: input.steps,
63
- bugs: input.bugs,
64
- visual: input.visual,
65
- ...(input.summary !== undefined && { summary: input.summary }),
66
- };
67
- }
68
71
  /** Pairing key for a reported step and a recorded one — case- and whitespace-insensitive. */
69
72
  function stepKey(step) {
70
73
  return step.step.trim().toLowerCase().replace(/\s+/g, ' ');
@@ -128,24 +131,102 @@ export function mergeSteps(reported, trail) {
128
131
  return merged;
129
132
  }
130
133
  /**
131
- * The authoritative terminal {@link Findings}: the report input with the loop's
132
- * recorded act-`trail` merged into its `steps` (see {@link mergeSteps}) — never a
133
- * wholesale replacement, which silently dropped every step the driver reported.
134
- * The single source of truth for the terminal write AND the counts, so they never
135
- * drift (a `0`-step result returned over a trail-filled file).
134
+ * Fuse one reported bug with the streamed console error it restates: the
135
+ * driver's wording wins, the streamed row fills the evidence location the
136
+ * driver never saw.
137
+ */
138
+ function fuseBug(streamed, reported) {
139
+ const evidence = reported.evidence ?? streamed.evidence;
140
+ return {
141
+ kind: reported.kind,
142
+ detail: reported.detail,
143
+ ...(evidence !== undefined && { evidence }),
144
+ };
145
+ }
146
+ /**
147
+ * Fuse one reported visual issue with the streamed look issue it restates: the
148
+ * driver's wording wins, the streamed entry fills the screenshot path the
149
+ * driver never has at hand.
136
150
  */
137
- export function terminalFindings(input, trail = []) {
138
- const findings = reportFindings(input);
139
- return { ...findings, steps: mergeSteps(input.steps, trail) };
151
+ function fuseVisual(streamed, reported) {
152
+ const screenshot = reported.screenshot ?? streamed.screenshot;
153
+ return {
154
+ issue: reported.issue,
155
+ where: reported.where,
156
+ severity: reported.severity,
157
+ ...(screenshot !== undefined && { screenshot }),
158
+ };
140
159
  }
141
160
  /**
142
- * Write the terminal verdict and report the stop. Both the persisted findings and
143
- * the returned counts derive from one {@link terminalFindings} object — the loop's
144
- * `trail` merged with the driver's reported steps. Pure over the
161
+ * Merge reported findings with the streamed ones, streamed order as the spine —
162
+ * the same discipline as {@link mergeSteps}, for the bugs/visual streams. A
163
+ * restatement (matched by normalized key) fuses in place, driver fields winning
164
+ * and streamed evidence filling the gaps; reported entries that restate nothing
165
+ * append in reported order. Unrestated streamed entries are carried (`keep:
166
+ * true`) or dropped (`keep: false` — a deliberate `dismissStreamed`); `carried`
167
+ * counts what was included, so it is always 0 under `keep: false`.
168
+ */
169
+ function mergeStreamed(reported, streamed, keyOf, fuse, keep) {
170
+ const pending = new Map();
171
+ reported.forEach((item, index) => {
172
+ const queue = pending.get(keyOf(item));
173
+ if (queue)
174
+ queue.push({ index, item });
175
+ else
176
+ pending.set(keyOf(item), [{ index, item }]);
177
+ });
178
+ const fused = new Set();
179
+ const merged = [];
180
+ let carried = 0;
181
+ for (const entry of streamed) {
182
+ const hit = pending.get(keyOf(entry))?.shift();
183
+ if (hit) {
184
+ fused.add(hit.index);
185
+ merged.push(fuse(entry, hit.item));
186
+ }
187
+ else if (keep) {
188
+ carried += 1;
189
+ merged.push(entry);
190
+ }
191
+ }
192
+ for (const [index, item] of reported.entries()) {
193
+ if (!fused.has(index))
194
+ merged.push(item);
195
+ }
196
+ return { merged, carried };
197
+ }
198
+ /**
199
+ * Everything the terminal write needs, derived in ONE pass: the merged evidence
200
+ * streams and the carried counts. The single source of truth for the persisted
201
+ * findings AND the returned counts, so they never drift.
202
+ */
203
+ function mergeEvidence(input, evidence) {
204
+ const steps = mergeSteps(input.steps, evidence.steps);
205
+ const bugMerge = mergeStreamed(input.bugs, evidence.bugs, (bug) => evidenceKey(bug.detail), fuseBug, !input.dismissStreamed);
206
+ const visualMerge = mergeStreamed(input.visual, evidence.visual, (issue) => evidenceKey(issue.issue, issue.where), fuseVisual, !input.dismissStreamed);
207
+ return {
208
+ steps,
209
+ bugs: bugMerge.merged,
210
+ visual: visualMerge.merged,
211
+ // Already 0 across the board under `dismissStreamed` — nothing unrestated was kept.
212
+ carried: { bugs: bugMerge.carried, visual: visualMerge.carried },
213
+ };
214
+ }
215
+ /**
216
+ * Write the terminal verdict and report the stop. Both the persisted findings
217
+ * and the returned counts/carried derive from ONE {@link mergeEvidence} pass —
218
+ * the run's streamed evidence merged with the driver's verdict. Pure over the
145
219
  * {@link FindingsWriter} seam, so it unit-tests against a fake with no disk.
146
220
  */
147
- export async function runReport(writer, input, trail = []) {
148
- const findings = terminalFindings(input, trail);
221
+ export async function runReport(writer, input, evidence = EMPTY_EVIDENCE) {
222
+ const { steps, bugs, visual, carried } = mergeEvidence(input, evidence);
223
+ const findings = {
224
+ status: input.status,
225
+ steps,
226
+ bugs,
227
+ visual,
228
+ ...(input.summary !== undefined && { summary: input.summary }),
229
+ };
149
230
  const path = await writer.writeFindings(findings);
150
231
  return {
151
232
  status: input.status,
@@ -155,25 +236,27 @@ export async function runReport(writer, input, trail = []) {
155
236
  bugs: findings.bugs.length,
156
237
  visual: findings.visual.length,
157
238
  },
239
+ carried,
158
240
  stop: true,
159
241
  };
160
242
  }
161
243
  /**
162
244
  * Build the `report` tool bound to one findings store, for the debug agent's belt.
163
- * `getTrail` (when wired by the loop) supplies the recorded act-trail so the
164
- * written verdict and its counts both reflect the steps actually taken.
245
+ * `getTrail` (when wired by the loop) supplies the run's streamed evidence so the
246
+ * written verdict carries the console errors and look issues the belt recorded,
247
+ * not just what the driver chose to list.
165
248
  *
166
249
  * It may be async — and the wired one is. `report` executes CONCURRENTLY with the
167
- * other tool calls of its own step, so when the driver emits `act` + `report`
168
- * together the act is still running here; the wired read is the act trail's
250
+ * other tool calls of its own step, so when the driver emits `look` + `report`
251
+ * together the look is still running here; the wired read is the evidence trail's
169
252
  * `settled()`, which waits for it (see `belt/trail.ts`). Waiting is safe: the
170
- * step's own `Promise.all` already awaits that act.
253
+ * step's own `Promise.all` already awaits that call.
171
254
  */
172
255
  export function createReportTool(writer, getTrail) {
173
256
  return tool({
174
- description: 'Emit the final structured findings and END the run. Call exactly once, when the goal is met or you hit the step limit. Validates and writes findings.json: status (passed|failed) plus steps/bugs/visual/summary. This is terminal — the loop stops after report, so do not act again. Make summary actionable for the smart agent: what broke, where, what to fix.',
257
+ description: 'Emit the final structured findings and END the run. Call exactly once, when the goal is met or you hit the step limit. Validates and writes findings.json: status (passed|failed) plus steps/bugs/visual/summary. Console errors you surfaced earlier are carried in even if you forget to list them; look issues too when a separate vision model judges the looks. Dismissal is deliberate (dismissStreamed). This is terminal — the loop stops after report, so do not act again. Make summary actionable for the smart agent: what broke, where, what to fix.',
175
258
  inputSchema: ReportInputSchema,
176
- execute: async (input) => runReport(writer, input, (await getTrail?.()) ?? []),
259
+ execute: async (input) => runReport(writer, input, (await getTrail?.()) ?? EMPTY_EVIDENCE),
177
260
  });
178
261
  }
179
262
  //# sourceMappingURL=report.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"report.js","sourceRoot":"","sources":["../../../src/agent/belt/report.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAA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AG,MAAM,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAClD,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE;YACN,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM;YAC5B,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;YAC1B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM;SAC/B;QACD,OAAO;QACP,IAAI,EAAE,IAAI;KACX,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAsB,EACtB,QAAuD;IAEvD,OAAO,IAAI,CAAC;QACV,WAAW,EACT,miBAAmiB;QACriB,WAAW,EAAE,iBAAiB;QAC9B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,MAAM,QAAQ,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC;KAC3F,CAAC,CAAC;AACL,CAAC"}
@@ -1,34 +1,62 @@
1
1
  /**
2
- * The run's shared act trail — the evidence spine `act` writes and `report` reads.
2
+ * The run's shared evidence trail — the spine `act`/`look`/`observe` write and
3
+ * `report` reads.
3
4
  *
4
- * `act` records every step it finishes, ok or not, AT ACT TIME. The timing is the
5
- * whole point. The SDK runs a step's tool calls CONCURRENTLY (`Promise.all` over
6
- * the call list) and `onStepFinish` only fires once they have all settled, so when
7
- * the driver emits `act` and `report` in ONE step — which models do, despite the
8
- * prompt calling `report` terminal — `report` executes while that act is still in
5
+ * `act` records every step it finishes, ok or not, AT ACT TIME; `look` records
6
+ * each visual issue the vision guy flags; `observe` records every error-level
7
+ * console row it reads back. The timing is the whole point. The SDK runs a
8
+ * step's tool calls CONCURRENTLY (`Promise.all` over the call list) and
9
+ * `onStepFinish` only fires once they have all settled, so when the driver
10
+ * emits a tool and `report` in ONE step — which models do, despite the prompt
11
+ * calling `report` terminal — `report` executes while that tool is still in
9
12
  * flight. A trail lifted at step end reaches the terminal read too late: the
10
13
  * verdict ships without the last thing the run did.
11
14
  *
12
- * So the trail also counts the acts in flight and the terminal read waits for them
13
- * ({@link ActTrail.settled}). That can never deadlock: the step's own `Promise.all`
14
- * already awaits every act, so `report` only ever waits on work that must finish
15
- * for its own step to finish at all.
15
+ * So the trail also counts the work in flight and the terminal read waits for
16
+ * it ({@link ActTrail.settled}). That can never deadlock: the step's own
17
+ * `Promise.all` already awaits every tool call, so `report` only ever waits on
18
+ * work that must finish for its own step to finish at all.
16
19
  */
17
- import type { Step } from '../../findings/schema.js';
20
+ import type { Bug, Step, VisualIssue } from '../../findings/schema.js';
18
21
  /**
19
- * The shared trail: an ordered {@link Step} log plus the in-flight bookkeeping the
20
- * terminal read needs. One per run — `act` writes it, the loop's running flush
21
- * snapshots it, `report` merges it into the verdict.
22
+ * The three evidence streams a run accumulates, as `report` (and the loop's
23
+ * running flush) consume them. Live arrays — everything recorded so far, in
24
+ * call order, already deduped.
22
25
  */
23
- export interface ActTrail {
26
+ export interface TrailEvidence {
27
+ /** Ordered act steps, written by `act` as each act finishes. */
28
+ readonly steps: readonly Step[];
29
+ /** Bugs seen so far (console errors today), deduped by normalized detail. */
30
+ readonly bugs: readonly Bug[];
31
+ /** Visual issues seen so far, deduped by normalized issue + location. */
32
+ readonly visual: readonly VisualIssue[];
33
+ }
34
+ /**
35
+ * The shared trail: the run's {@link TrailEvidence} plus the in-flight
36
+ * bookkeeping the terminal read needs. One per run — `act` writes steps, `look`
37
+ * and `observe` write the streamed findings, the loop's running flush snapshots
38
+ * all three, `report` merges them into the verdict.
39
+ */
40
+ export interface ActTrail extends TrailEvidence {
24
41
  /** Recorded steps in act order — the array the loop's running flush snapshots. */
25
42
  readonly steps: Step[];
26
43
  /** Announce an act in flight; call the returned function once it settles. */
27
44
  begin(): () => void;
28
45
  /** Record one finished act — `ok: true` with its frame, or `ok: false` with the error. */
29
46
  record(step: Step): void;
47
+ /** Record one functional bug (a console error). Deduped by normalized `detail`. */
48
+ recordBug(bug: Bug): void;
49
+ /** Record one visual issue. Deduped by normalized `issue` + `where`. */
50
+ recordVisual(issue: VisualIssue): void;
30
51
  /** The trail once no act is in flight — the read `report` takes before it writes. */
31
- settled(): Promise<readonly Step[]>;
52
+ settled(): Promise<TrailEvidence>;
32
53
  }
54
+ /**
55
+ * Normalized pairing key for two descriptions of the same evidence — case- and
56
+ * whitespace-insensitive (the same normalization the running flush has always
57
+ * applied). One key per stream: bugs pair on {@link evidenceKey} of `detail`,
58
+ * visual issues on `issue` + `where`.
59
+ */
60
+ export declare function evidenceKey(...parts: string[]): string;
33
61
  /** Build a fresh {@link ActTrail} for one run. */
34
62
  export declare function createActTrail(): ActTrail;
@@ -1,19 +1,31 @@
1
1
  /**
2
- * The run's shared act trail — the evidence spine `act` writes and `report` reads.
2
+ * The run's shared evidence trail — the spine `act`/`look`/`observe` write and
3
+ * `report` reads.
3
4
  *
4
- * `act` records every step it finishes, ok or not, AT ACT TIME. The timing is the
5
- * whole point. The SDK runs a step's tool calls CONCURRENTLY (`Promise.all` over
6
- * the call list) and `onStepFinish` only fires once they have all settled, so when
7
- * the driver emits `act` and `report` in ONE step — which models do, despite the
8
- * prompt calling `report` terminal — `report` executes while that act is still in
5
+ * `act` records every step it finishes, ok or not, AT ACT TIME; `look` records
6
+ * each visual issue the vision guy flags; `observe` records every error-level
7
+ * console row it reads back. The timing is the whole point. The SDK runs a
8
+ * step's tool calls CONCURRENTLY (`Promise.all` over the call list) and
9
+ * `onStepFinish` only fires once they have all settled, so when the driver
10
+ * emits a tool and `report` in ONE step — which models do, despite the prompt
11
+ * calling `report` terminal — `report` executes while that tool is still in
9
12
  * flight. A trail lifted at step end reaches the terminal read too late: the
10
13
  * verdict ships without the last thing the run did.
11
14
  *
12
- * So the trail also counts the acts in flight and the terminal read waits for them
13
- * ({@link ActTrail.settled}). That can never deadlock: the step's own `Promise.all`
14
- * already awaits every act, so `report` only ever waits on work that must finish
15
- * for its own step to finish at all.
15
+ * So the trail also counts the work in flight and the terminal read waits for
16
+ * it ({@link ActTrail.settled}). That can never deadlock: the step's own
17
+ * `Promise.all` already awaits every tool call, so `report` only ever waits on
18
+ * work that must finish for its own step to finish at all.
16
19
  */
20
+ /**
21
+ * Normalized pairing key for two descriptions of the same evidence — case- and
22
+ * whitespace-insensitive (the same normalization the running flush has always
23
+ * applied). One key per stream: bugs pair on {@link evidenceKey} of `detail`,
24
+ * visual issues on `issue` + `where`.
25
+ */
26
+ export function evidenceKey(...parts) {
27
+ return parts.join(' @ ').trim().toLowerCase().replace(/\s+/g, ' ');
28
+ }
17
29
  /** Let already-queued microtasks run — one full turn of the event loop. */
18
30
  function nextTurn() {
19
31
  return new Promise((resolve) => setTimeout(resolve, 0));
@@ -21,11 +33,20 @@ function nextTurn() {
21
33
  /** Build a fresh {@link ActTrail} for one run. */
22
34
  export function createActTrail() {
23
35
  const steps = [];
36
+ const bugs = [];
37
+ const visual = [];
38
+ // Dedupe keys mirror the arrays: the console channel is a ring buffer read
39
+ // non-destructively, and looks repeat on an unchanged screen, so a re-read
40
+ // must add nothing.
41
+ const bugKeys = new Set();
42
+ const visualKeys = new Set();
24
43
  let inFlight = 0;
25
44
  let idle = null;
26
45
  let markIdle = null;
27
46
  return {
28
47
  steps,
48
+ bugs,
49
+ visual,
29
50
  begin() {
30
51
  inFlight += 1;
31
52
  idle ??= new Promise((resolve) => {
@@ -48,6 +69,20 @@ export function createActTrail() {
48
69
  record(step) {
49
70
  steps.push(step);
50
71
  },
72
+ recordBug(bug) {
73
+ const key = evidenceKey(bug.detail);
74
+ if (bugKeys.has(key))
75
+ return;
76
+ bugKeys.add(key);
77
+ bugs.push(bug);
78
+ },
79
+ recordVisual(issue) {
80
+ const key = evidenceKey(issue.issue, issue.where);
81
+ if (visualKeys.has(key))
82
+ return;
83
+ visualKeys.add(key);
84
+ visual.push(issue);
85
+ },
51
86
  async settled() {
52
87
  // Yield a full turn before checking: the sibling tool calls of this step are
53
88
  // launched in microtasks, so an act listed AFTER `report` in the call list has
@@ -57,7 +92,7 @@ export function createActTrail() {
57
92
  await nextTurn();
58
93
  while (idle !== null)
59
94
  await idle;
60
- return steps;
95
+ return { steps, bugs, visual };
61
96
  },
62
97
  };
63
98
  }
@@ -1 +1 @@
1
- {"version":3,"file":"trail.js","sourceRoot":"","sources":["../../../src/agent/belt/trail.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAoBH,2EAA2E;AAC3E,SAAS,QAAQ;IACf,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,cAAc;IAC5B,MAAM,KAAK,GAAW,EAAE,CAAC;IACzB,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,IAAI,GAAyB,IAAI,CAAC;IACtC,IAAI,QAAQ,GAAwB,IAAI,CAAC;IACzC,OAAO;QACL,KAAK;QACL,KAAK;YACH,QAAQ,IAAI,CAAC,CAAC;YACd,IAAI,KAAK,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBACrC,QAAQ,GAAG,OAAO,CAAC;YACrB,CAAC,CAAC,CAAC;YACH,IAAI,OAAO,GAAG,KAAK,CAAC;YACpB,OAAO,GAAG,EAAE;gBACV,mEAAmE;gBACnE,IAAI,OAAO;oBAAE,OAAO;gBACpB,OAAO,GAAG,IAAI,CAAC;gBACf,QAAQ,IAAI,CAAC,CAAC;gBACd,IAAI,QAAQ,GAAG,CAAC;oBAAE,OAAO;gBACzB,QAAQ,EAAE,EAAE,CAAC;gBACb,IAAI,GAAG,IAAI,CAAC;gBACZ,QAAQ,GAAG,IAAI,CAAC;YAClB,CAAC,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,IAAI;YACT,KAAK,CAAC,IAAI,CAAC,IAAI,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B,CAAC;SAC9C,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC,CAAC,mEAAmE;IAClF,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,IAAa,CAAC;IAClB,IAAI,CAAC;QACH,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAAG,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC,CAAC,8BAA8B;IAEjE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;IAC/B,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAClC,MAAM,KAAK,GACT,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,KAAK,OAAO,CAAC;QACvC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC;IAExE,MAAM,UAAU,GAAG,KAAK,EAAE,YAAY,EAAE,gBAAgB,CAAC;IACzD,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC,CAAC,sDAAsD;IACpF,OAAO,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Paid fallback behind a (free) primary model.
3
+ *
4
+ * The default roles run on OpenRouter `:free` models. Those are rate-limited
5
+ * per model (~20 req/min), capped per day, and upstream-throttled at random —
6
+ * measured 2026-11-14: `google/gemma-4-31b-it:free` answered a run's very first
7
+ * step with `429 … temporarily rate-limited upstream`, and the run failed after
8
+ * the SDK's three retries. So every role carries ONE paid fallback: when the
9
+ * primary fails with a transient/availability status, or answers with nothing
10
+ * at all, the SAME call is re-issued on the fallback model.
11
+ *
12
+ * Gateway-agnostic on purpose (no OpenRouter `models: []` body field): it works
13
+ * on any OpenAI-compatible router, and the fallback is observable — every
14
+ * switch is reported through `onFallback` (boot wires it to stderr).
15
+ */
16
+ import { type LanguageModel, wrapLanguageModel } from 'ai';
17
+ /** The wrapped model type `wrapLanguageModel` takes and returns. */
18
+ type WrappableModel = Parameters<typeof wrapLanguageModel>[0]['model'];
19
+ /** Why a call left the primary: an HTTP status, a transport error, or an empty answer. */
20
+ export interface FallbackEvent {
21
+ primary: string;
22
+ fallback: string;
23
+ reason: string;
24
+ }
25
+ export type OnFallback = (event: FallbackEvent) => void;
26
+ /** The fallback-worthy reason for an error, or `null` when it must propagate. */
27
+ export declare function fallbackReason(error: unknown): string | null;
28
+ /**
29
+ * `primary` with `fallback` behind it. Same `modelId` as the primary, so
30
+ * capability messages and logs keep naming the configured model.
31
+ */
32
+ export declare function withFallback(primary: WrappableModel, fallback: WrappableModel, onFallback: OnFallback): LanguageModel;
33
+ export {};
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Paid fallback behind a (free) primary model.
3
+ *
4
+ * The default roles run on OpenRouter `:free` models. Those are rate-limited
5
+ * per model (~20 req/min), capped per day, and upstream-throttled at random —
6
+ * measured 2026-11-14: `google/gemma-4-31b-it:free` answered a run's very first
7
+ * step with `429 … temporarily rate-limited upstream`, and the run failed after
8
+ * the SDK's three retries. So every role carries ONE paid fallback: when the
9
+ * primary fails with a transient/availability status, or answers with nothing
10
+ * at all, the SAME call is re-issued on the fallback model.
11
+ *
12
+ * Gateway-agnostic on purpose (no OpenRouter `models: []` body field): it works
13
+ * on any OpenAI-compatible router, and the fallback is observable — every
14
+ * switch is reported through `onFallback` (boot wires it to stderr).
15
+ */
16
+ import { APICallError, wrapLanguageModel } from 'ai';
17
+ /**
18
+ * Statuses that say "this model, right now, cannot serve you" — not "your
19
+ * request is wrong": 404 (a `:free` variant retired / no endpoints), 408, 429
20
+ * (per-model or daily free cap), every 5xx. A 400 is deliberately NOT here: it
21
+ * is a bad request (e.g. an image at a text-only model, which `look` turns
22
+ * into its vision latch), and re-sending it elsewhere would hide the defect.
23
+ */
24
+ function isUnavailable(status) {
25
+ return (status === undefined || status === 404 || status === 408 || status === 429 || status >= 500);
26
+ }
27
+ /** The fallback-worthy reason for an error, or `null` when it must propagate. */
28
+ export function fallbackReason(error) {
29
+ if (!APICallError.isInstance(error))
30
+ return null; // abort, validation, our own bugs
31
+ if (!isUnavailable(error.statusCode))
32
+ return null;
33
+ return error.statusCode === undefined
34
+ ? `transport error: ${error.message}`
35
+ : `HTTP ${error.statusCode}`;
36
+ }
37
+ /** A generate result with no text and no tool call — the model said nothing usable. */
38
+ function isEmpty(content) {
39
+ return !content.some((part) => part.type === 'tool-call' || (part.type === 'text' && (part.text ?? '').trim() !== ''));
40
+ }
41
+ /**
42
+ * `primary` with `fallback` behind it. Same `modelId` as the primary, so
43
+ * capability messages and logs keep naming the configured model.
44
+ */
45
+ export function withFallback(primary, fallback, onFallback) {
46
+ const ids = { primary: primary.modelId, fallback: fallback.modelId };
47
+ const fellBack = (reason) => onFallback({ ...ids, reason });
48
+ // `wrapLanguageModel` normalises both to the same spec version; call the
49
+ // fallback through a passthrough wrap so its `doGenerate` matches the primary's.
50
+ const backup = wrapLanguageModel({ model: fallback, middleware: {} });
51
+ return wrapLanguageModel({
52
+ model: primary,
53
+ middleware: {
54
+ wrapGenerate: async ({ doGenerate, params }) => {
55
+ try {
56
+ const result = await doGenerate();
57
+ if (!isEmpty(result.content))
58
+ return result;
59
+ fellBack('empty response');
60
+ }
61
+ catch (error) {
62
+ const reason = fallbackReason(error);
63
+ if (reason === null)
64
+ throw error;
65
+ fellBack(reason);
66
+ }
67
+ return backup.doGenerate(params);
68
+ },
69
+ wrapStream: async ({ doStream, params }) => {
70
+ try {
71
+ return await doStream();
72
+ }
73
+ catch (error) {
74
+ const reason = fallbackReason(error);
75
+ if (reason === null)
76
+ throw error;
77
+ fellBack(reason);
78
+ return backup.doStream(params);
79
+ }
80
+ },
81
+ },
82
+ });
83
+ }
84
+ //# sourceMappingURL=fallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fallback.js","sourceRoot":"","sources":["../../src/agent/fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAsB,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAczE;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,MAA0B;IAC/C,OAAO,CACL,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,IAAI,GAAG,CAC5F,CAAC;AACJ,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC,CAAC,kCAAkC;IACpF,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC;IAClD,OAAO,KAAK,CAAC,UAAU,KAAK,SAAS;QACnC,CAAC,CAAC,oBAAoB,KAAK,CAAC,OAAO,EAAE;QACrC,CAAC,CAAC,QAAQ,KAAK,CAAC,UAAU,EAAE,CAAC;AACjC,CAAC;AAED,uFAAuF;AACvF,SAAS,OAAO,CAAC,OAAuD;IACtE,OAAO,CAAC,OAAO,CAAC,IAAI,CAClB,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EA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