@developerz.ai/ui-debugger-mcp 1.1.0 → 1.2.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 (152) hide show
  1. package/README.md +22 -10
  2. package/dist/adapters/android/adb.d.ts +34 -5
  3. package/dist/adapters/android/adb.js +74 -20
  4. package/dist/adapters/android/adb.js.map +1 -1
  5. package/dist/adapters/android/android-adapter.d.ts +23 -7
  6. package/dist/adapters/android/android-adapter.js +106 -36
  7. package/dist/adapters/android/android-adapter.js.map +1 -1
  8. package/dist/adapters/android/android-adapter.test-helpers.d.ts +52 -0
  9. package/dist/adapters/android/android-adapter.test-helpers.js +115 -0
  10. package/dist/adapters/android/android-adapter.test-helpers.js.map +1 -0
  11. package/dist/adapters/android/commands.d.ts +27 -4
  12. package/dist/adapters/android/commands.js +66 -4
  13. package/dist/adapters/android/commands.js.map +1 -1
  14. package/dist/adapters/android/ports.d.ts +32 -0
  15. package/dist/adapters/android/ports.js +47 -0
  16. package/dist/adapters/android/ports.js.map +1 -0
  17. package/dist/adapters/android/uiautomator.d.ts +10 -2
  18. package/dist/adapters/android/uiautomator.js +36 -4
  19. package/dist/adapters/android/uiautomator.js.map +1 -1
  20. package/dist/adapters/browser/browser-adapter.d.ts +14 -13
  21. package/dist/adapters/browser/browser-adapter.js +69 -306
  22. package/dist/adapters/browser/browser-adapter.js.map +1 -1
  23. package/dist/adapters/browser/cdp.js +18 -11
  24. package/dist/adapters/browser/cdp.js.map +1 -1
  25. package/dist/adapters/browser/extractor.d.ts +49 -0
  26. package/dist/adapters/browser/extractor.js +208 -0
  27. package/dist/adapters/browser/extractor.js.map +1 -0
  28. package/dist/adapters/browser/filters.d.ts +15 -0
  29. package/dist/adapters/browser/filters.js +93 -0
  30. package/dist/adapters/browser/filters.js.map +1 -0
  31. package/dist/adapters/browser/launch.d.ts +41 -0
  32. package/dist/adapters/browser/launch.js +61 -0
  33. package/dist/adapters/browser/launch.js.map +1 -0
  34. package/dist/adapters/budget.d.ts +16 -0
  35. package/dist/adapters/budget.js +25 -0
  36. package/dist/adapters/budget.js.map +1 -0
  37. package/dist/adapters/contract.d.ts +13 -6
  38. package/dist/adapters/desktop/atspi.d.ts +15 -0
  39. package/dist/adapters/desktop/atspi.js +37 -17
  40. package/dist/adapters/desktop/atspi.js.map +1 -1
  41. package/dist/adapters/desktop/capture.js +8 -1
  42. package/dist/adapters/desktop/capture.js.map +1 -1
  43. package/dist/adapters/desktop/desktop-adapter.d.ts +9 -2
  44. package/dist/adapters/desktop/desktop-adapter.js +84 -32
  45. package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
  46. package/dist/adapters/desktop/input.d.ts +16 -1
  47. package/dist/adapters/desktop/input.js +30 -0
  48. package/dist/adapters/desktop/input.js.map +1 -1
  49. package/dist/adapters/desktop/proc.d.ts +18 -3
  50. package/dist/adapters/desktop/proc.js +48 -5
  51. package/dist/adapters/desktop/proc.js.map +1 -1
  52. package/dist/adapters/factory.d.ts +3 -1
  53. package/dist/adapters/factory.js +6 -2
  54. package/dist/adapters/factory.js.map +1 -1
  55. package/dist/adapters/limit.d.ts +10 -0
  56. package/dist/adapters/limit.js +19 -0
  57. package/dist/adapters/limit.js.map +1 -0
  58. package/dist/agent/belt/act.d.ts +27 -5
  59. package/dist/agent/belt/act.js +75 -17
  60. package/dist/agent/belt/act.js.map +1 -1
  61. package/dist/agent/belt/observe.d.ts +29 -15
  62. package/dist/agent/belt/observe.js +74 -19
  63. package/dist/agent/belt/observe.js.map +1 -1
  64. package/dist/agent/belt/report.d.ts +29 -9
  65. package/dist/agent/belt/report.js +77 -10
  66. package/dist/agent/belt/report.js.map +1 -1
  67. package/dist/agent/belt/trail.d.ts +34 -0
  68. package/dist/agent/belt/trail.js +64 -0
  69. package/dist/agent/belt/trail.js.map +1 -0
  70. package/dist/agent/capabilities.d.ts +4 -4
  71. package/dist/agent/capabilities.js +38 -13
  72. package/dist/agent/capabilities.js.map +1 -1
  73. package/dist/agent/loop.d.ts +58 -19
  74. package/dist/agent/loop.js +134 -46
  75. package/dist/agent/loop.js.map +1 -1
  76. package/dist/agent/prompts/compose.d.ts +9 -1
  77. package/dist/agent/prompts/compose.js +5 -4
  78. package/dist/agent/prompts/compose.js.map +1 -1
  79. package/dist/agent/prompts/debug-agent.d.ts +13 -1
  80. package/dist/agent/prompts/debug-agent.js +45 -11
  81. package/dist/agent/prompts/debug-agent.js.map +1 -1
  82. package/dist/agent/prompts/desktop-addendum.d.ts +1 -1
  83. package/dist/agent/prompts/desktop-addendum.js +1 -1
  84. package/dist/agent/prompts/web-addendum.d.ts +1 -1
  85. package/dist/agent/prompts/web-addendum.js +16 -18
  86. package/dist/agent/prompts/web-addendum.js.map +1 -1
  87. package/dist/cli/control.d.ts +3 -1
  88. package/dist/cli/control.js +26 -40
  89. package/dist/cli/control.js.map +1 -1
  90. package/dist/cli/help.d.ts +3 -1
  91. package/dist/cli/help.js +6 -2
  92. package/dist/cli/help.js.map +1 -1
  93. package/dist/cli/init.d.ts +3 -6
  94. package/dist/cli/init.js +64 -16
  95. package/dist/cli/init.js.map +1 -1
  96. package/dist/config/load.js +8 -1
  97. package/dist/config/load.js.map +1 -1
  98. package/dist/config/schema.d.ts +12 -5
  99. package/dist/config/schema.js +17 -7
  100. package/dist/config/schema.js.map +1 -1
  101. package/dist/errors.d.ts +14 -2
  102. package/dist/errors.js +24 -4
  103. package/dist/errors.js.map +1 -1
  104. package/dist/index.d.ts +1 -1
  105. package/dist/index.js +1 -1
  106. package/dist/main.js +22 -8
  107. package/dist/main.js.map +1 -1
  108. package/dist/mcp/server.d.ts +16 -1
  109. package/dist/mcp/server.js +23 -2
  110. package/dist/mcp/server.js.map +1 -1
  111. package/dist/mcp/server.test-helpers.d.ts +23 -0
  112. package/dist/mcp/server.test-helpers.js +49 -0
  113. package/dist/mcp/server.test-helpers.js.map +1 -0
  114. package/dist/mcp/tools/describe.js +5 -0
  115. package/dist/mcp/tools/describe.js.map +1 -1
  116. package/dist/mcp/tools/end-session.js +5 -0
  117. package/dist/mcp/tools/end-session.js.map +1 -1
  118. package/dist/mcp/tools/get-findings.js +23 -3
  119. package/dist/mcp/tools/get-findings.js.map +1 -1
  120. package/dist/mcp/tools/output.d.ts +50 -0
  121. package/dist/mcp/tools/output.js +55 -0
  122. package/dist/mcp/tools/output.js.map +1 -0
  123. package/dist/mcp/tools/result.d.ts +24 -1
  124. package/dist/mcp/tools/result.js +106 -5
  125. package/dist/mcp/tools/result.js.map +1 -1
  126. package/dist/mcp/tools/send-message.js +5 -0
  127. package/dist/mcp/tools/send-message.js.map +1 -1
  128. package/dist/mcp/tools/start-debug.js +7 -1
  129. package/dist/mcp/tools/start-debug.js.map +1 -1
  130. package/dist/services/debug-service.d.ts +38 -6
  131. package/dist/services/debug-service.js +122 -13
  132. package/dist/services/debug-service.js.map +1 -1
  133. package/dist/services/session-builder.d.ts +20 -3
  134. package/dist/services/session-builder.js +43 -13
  135. package/dist/services/session-builder.js.map +1 -1
  136. package/dist/session/atomic-write.d.ts +24 -0
  137. package/dist/session/atomic-write.js +39 -0
  138. package/dist/session/atomic-write.js.map +1 -0
  139. package/dist/session/findings-store.js +3 -4
  140. package/dist/session/findings-store.js.map +1 -1
  141. package/dist/session/process-identity.d.ts +16 -0
  142. package/dist/session/process-identity.js +29 -0
  143. package/dist/session/process-identity.js.map +1 -1
  144. package/dist/session/session.js +10 -2
  145. package/dist/session/session.js.map +1 -1
  146. package/dist/session/state-file.d.ts +51 -5
  147. package/dist/session/state-file.js +60 -8
  148. package/dist/session/state-file.js.map +1 -1
  149. package/dist/session/workspace.d.ts +11 -0
  150. package/dist/session/workspace.js +14 -1
  151. package/dist/session/workspace.js.map +1 -1
  152. package/package.json +4 -1
@@ -26,10 +26,17 @@
26
26
  import { tool } from 'ai';
27
27
  import { z } from 'zod';
28
28
  import { AgentError } from '../../errors.js';
29
- /** The four observable channels `kind` selects (each routes to one contract method). */
30
- const OBSERVE_KINDS = ['tree', 'screenshot', 'console', 'network'];
31
- /** Selectable {@link Node} columns — the `fields` projection whitelist (contract-level). */
32
- const NODE_FIELDS = [
29
+ /**
30
+ * The four observable channels `kind` selects (each routes to one contract method).
31
+ * Exported so the prompt-vs-schema drift guard (`prompts/schema-drift.test.ts`) can
32
+ * assert every `kind:"…"` example the prompts teach is one the belt actually accepts.
33
+ */
34
+ export const OBSERVE_KINDS = ['tree', 'screenshot', 'console', 'network'];
35
+ /**
36
+ * Selectable {@link Node} columns — the `fields` projection whitelist (contract-level).
37
+ * Exported for the same drift guard as {@link OBSERVE_KINDS}.
38
+ */
39
+ export const NODE_FIELDS = [
33
40
  'role',
34
41
  'name',
35
42
  'bounds',
@@ -49,6 +56,14 @@ const DEFAULT_PROJECTION = [
49
56
  'enabled',
50
57
  'testid',
51
58
  ];
59
+ /**
60
+ * Rows a no-`limit` `console`/`network` read returns (newest first, so the cap keeps
61
+ * what just happened). The ring buffers hold 1000 entries each (`browser/cdp.ts`), the
62
+ * driver is told to check both channels after acting, and the SDK re-sends every tool
63
+ * result on every later step — so one unbounded read on a chatty page costs
64
+ * entries × remaining steps of context. An explicit `limit` (including `0`) still wins.
65
+ */
66
+ const DEFAULT_LOG_LIMIT = 50;
52
67
  /** One `filters` predicate value; arrays back `_in`-style set membership (matches `FilterValue`). */
53
68
  const FilterValueSchema = z.union([z.string(), z.number(), z.boolean(), z.array(z.string())]);
54
69
  /** On-screen rectangle backing a {@link Node} `within` reference. */
@@ -58,12 +73,19 @@ const BoundsSchema = z.object({
58
73
  width: z.number(),
59
74
  height: z.number(),
60
75
  });
61
- /** A {@link Node} echoed back as a `within` scope (the alternative to a selector string). */
76
+ /**
77
+ * A {@link Node} echoed back as a `within` scope (the alternative to a selector string).
78
+ *
79
+ * `bounds`/`enabled` are OPTIONAL: a `fields:["role","name"]` read — what the web
80
+ * addendum recommends for slim reads — returns neither, and rejecting the very node
81
+ * observe just handed back is the kind of contradiction that burns steps. Role + name
82
+ * are enough; {@link coerceWithin} turns a region-less node into a selector.
83
+ */
62
84
  const NodeSchema = z.object({
63
85
  role: z.string(),
64
86
  name: z.string(),
65
- bounds: BoundsSchema,
66
- enabled: z.boolean(),
87
+ bounds: BoundsSchema.optional(),
88
+ enabled: z.boolean().optional(),
67
89
  testid: z.string().optional(),
68
90
  });
69
91
  /** `observe` input — flat + SQL-like; `kind` picks the table, the rest compose the read. */
@@ -81,11 +103,16 @@ export const ObserveInputSchema = z.object({
81
103
  .record(z.string(), FilterValueSchema)
82
104
  .optional()
83
105
  .describe('WHERE-style predicates, e.g. { visible_eq: true } | { status_gte: 400 }; per-channel'),
84
- limit: z.number().int().nonnegative().optional().describe('cap how many rows return'),
106
+ limit: z
107
+ .number()
108
+ .int()
109
+ .nonnegative()
110
+ .optional()
111
+ .describe(`cap how many rows return (console/network default ${DEFAULT_LOG_LIMIT})`),
85
112
  within: z
86
113
  .union([z.string(), NodeSchema])
87
114
  .optional()
88
- .describe('tree scope: restrict to a subtree/region (a selector string, or a node OBJECT exactly as observe returned it — not a JSON string)'),
115
+ .describe('tree scope: restrict to a subtree/region (a selector string, or a node OBJECT exactly as observe returned it — role + name is enough, not a JSON string)'),
89
116
  });
90
117
  /** ARIA roles Playwright's `role=` engine accepts (others fall back to a text selector). */
91
118
  const ARIA_ROLES = new Set([
@@ -173,14 +200,40 @@ function pick(obj, keys) {
173
200
  return out;
174
201
  }
175
202
  /**
176
- * Accept a JSON-*stringified* node for `within`. Drivers routinely paste the node
177
- * back as a string (`within: "{\"role\": …}"`); before this coercion that string
178
- * fell through as a selector, normalized to `text={"role"…}`, matched nothing, and
179
- * returned an empty tree with no clue why — the single biggest step-waster observed.
180
- * Garbage-that-looks-like-JSON fails loud instead of silently reading the whole page.
203
+ * A `within` node as a contract {@link NodeRef}: its on-screen region when it has one,
204
+ * else the selector its testid/role/name resolve to — the same string `observe` would
205
+ * have attached to that node as `target`.
206
+ *
207
+ * Adapters scope a {@link Node} `within` by `bounds` ALONE, so a region-less node has
208
+ * to become a selector or it would silently read nothing. `enabled` is never read when
209
+ * scoping; the contract just requires the field, so a projection that dropped it
210
+ * defaults to `true` rather than throwing away an exact region.
211
+ */
212
+ function scopeOf(node) {
213
+ const { bounds } = node;
214
+ if (bounds !== undefined)
215
+ return { ...node, bounds, enabled: node.enabled ?? true };
216
+ const selector = baseSelector(node);
217
+ if (selector)
218
+ return selector;
219
+ throw new AgentError('observe `within` node has no `bounds` and no name/testid to resolve it — re-read with `fields` including "bounds", or pass a selector string');
220
+ }
221
+ /**
222
+ * Resolve `within` to something the {@link Adapter} contract takes — a selector string
223
+ * or a {@link Node}. Two coercions, each fixing a shape drivers actually produce:
224
+ *
225
+ * - a JSON-*stringified* node (`within: "{\"role\": …}"`). Before this it fell through
226
+ * as a selector, normalized to `text={"role"…}`, matched nothing, and returned an
227
+ * empty tree with no clue why — the single biggest step-waster observed.
228
+ * Garbage-that-looks-like-JSON fails loud instead of reading the whole page.
229
+ * - a node projected without `bounds` (`fields:["role","name"]`) → {@link scopeOf}.
181
230
  */
182
231
  export function coerceWithin(within) {
183
- if (typeof within !== 'string' || !within.trimStart().startsWith('{'))
232
+ if (within === undefined)
233
+ return undefined;
234
+ if (typeof within !== 'string')
235
+ return scopeOf(within);
236
+ if (!within.trimStart().startsWith('{'))
184
237
  return within;
185
238
  let data;
186
239
  try {
@@ -191,9 +244,9 @@ export function coerceWithin(within) {
191
244
  }
192
245
  const parsed = NodeSchema.safeParse(data);
193
246
  if (!parsed.success) {
194
- throw new AgentError('observe `within` was a JSON string but not a valid node (needs role/name/bounds/enabled) — pass a node from a previous observe, or a selector string');
247
+ throw new AgentError('observe `within` was a JSON string but not a valid node (needs role + name) — pass a node from a previous observe, or a selector string');
195
248
  }
196
- return parsed.data;
249
+ return scopeOf(parsed.data);
197
250
  }
198
251
  /**
199
252
  * Route one `observe` call to the adapter and shape the result. Pure over the
@@ -218,12 +271,14 @@ export async function runObserve(adapter, recorder, input) {
218
271
  const path = await recorder.saveScreenshot('observe', png);
219
272
  return { kind, path, bytes: png.byteLength };
220
273
  }
274
+ // Both log channels default to a bounded tail (see DEFAULT_LOG_LIMIT); an explicit
275
+ // `limit` — including `0` — passes through, invalid ones still die in the adapter.
221
276
  case 'console': {
222
- const entries = await adapter.console({ filters, limit });
277
+ const entries = await adapter.console({ filters, limit: limit ?? DEFAULT_LOG_LIMIT });
223
278
  return { kind, count: entries.length, entries };
224
279
  }
225
280
  case 'network': {
226
- const entries = await adapter.network({ filters, limit });
281
+ const entries = await adapter.network({ filters, limit: limit ?? DEFAULT_LOG_LIMIT });
227
282
  return { kind, count: entries.length, entries };
228
283
  }
229
284
  default: {
@@ -1 +1 @@
1
- {"version":3,"file":"observe.js","sourceRoot":"","sources":["../../../src/agent/belt/observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,wFAAwF;AACxF,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,CAAU,CAAC;AAE5E,4FAA4F;AAC5F,MAAM,WAAW,GAAG;IAClB,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,OAAO;CACgC,CAAC;AAE1C;;;;GAIG;AACH,MAAM,kBAAkB,GAAG;IACzB,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,QAAQ;CAC+B,CAAC;AAE1C,qGAAqG;AACrG,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAE9F,qEAAqE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ACH,CAAC;AACH,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAAE,QAA0B;IAC5E,OAAO,IAAI,CAAC;QACV,WAAW,EACT,mRAAmR;QACrR,WAAW,EAAE,kBAAkB;QAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC;KACzD,CAAC,CAAC;AACL,CAAC"}
@@ -86,23 +86,37 @@ export interface FindingsWriter {
86
86
  }
87
87
  /**
88
88
  * Build the canonical findings record from a validated report input. The base
89
- * verdict shape; {@link terminalFindings} overlays the loop's recorded act-trail
90
- * on top, so both the persisted write and the returned counts agree.
89
+ * verdict shape; {@link terminalFindings} merges the loop's recorded act-trail
90
+ * into its `steps`, so both the persisted write and the returned counts agree.
91
91
  */
92
92
  export declare function reportFindings(input: ReportInput): Findings;
93
+ /**
94
+ * Merge the driver's reported steps with the loop's recorded act-`trail`. Nothing
95
+ * is discarded: the driver's `ok: false` steps and notes (the prompt mandates
96
+ * them) survive alongside the mechanical trail and its evidence frames.
97
+ *
98
+ * The trail is the spine — it is the true chronology, recorded at act time — and
99
+ * each entry the driver restated verbatim (models commonly echo the `act` result
100
+ * label) is fused in place, driver fields winning, trail filling the gaps. Steps
101
+ * the driver reported that no trail entry matches — assertions, observations, acts
102
+ * from a step that also called `report` — follow in reported order, since nothing
103
+ * places them in the chronology. Both inputs keep their relative order, and equal
104
+ * labels pair up first-come-first-served, so repeating an action pairs each
105
+ * occurrence with a distinct trail entry.
106
+ */
107
+ export declare function mergeSteps(reported: readonly Step[], trail: readonly Step[]): Step[];
93
108
  /**
94
109
  * The authoritative terminal {@link Findings}: the report input with the loop's
95
- * recorded act-`trail` overlaid as `steps` whenever one was captured. The driver's
96
- * `report` rarely restates the steps it took (and the trail carries the evidence
97
- * frames), so the trail wins; the reported steps are the fallback for a run that
98
- * recorded none. The single source of truth for the terminal write AND the counts,
99
- * so they never drift (a `0`-step result returned over a trail-filled file).
110
+ * recorded act-`trail` merged into its `steps` (see {@link mergeSteps}) — never a
111
+ * wholesale replacement, which silently dropped every step the driver reported.
112
+ * The single source of truth for the terminal write AND the counts, so they never
113
+ * drift (a `0`-step result returned over a trail-filled file).
100
114
  */
101
115
  export declare function terminalFindings(input: ReportInput, trail?: readonly Step[]): Findings;
102
116
  /**
103
117
  * Write the terminal verdict and report the stop. Both the persisted findings and
104
118
  * the returned counts derive from one {@link terminalFindings} object — the loop's
105
- * `trail` (when present) is authoritative for `steps`. Pure over the
119
+ * `trail` merged with the driver's reported steps. Pure over the
106
120
  * {@link FindingsWriter} seam, so it unit-tests against a fake with no disk.
107
121
  */
108
122
  export declare function runReport(writer: FindingsWriter, input: ReportInput, trail?: readonly Step[]): Promise<ReportResult>;
@@ -110,8 +124,14 @@ export declare function runReport(writer: FindingsWriter, input: ReportInput, tr
110
124
  * Build the `report` tool bound to one findings store, for the debug agent's belt.
111
125
  * `getTrail` (when wired by the loop) supplies the recorded act-trail so the
112
126
  * written verdict and its counts both reflect the steps actually taken.
127
+ *
128
+ * It may be async — and the wired one is. `report` executes CONCURRENTLY with the
129
+ * other tool calls of its own step, so when the driver emits `act` + `report`
130
+ * together the act is still running here; the wired read is the act trail's
131
+ * `settled()`, which waits for it (see `belt/trail.ts`). Waiting is safe: the
132
+ * step's own `Promise.all` already awaits that act.
113
133
  */
114
- export declare function createReportTool(writer: FindingsWriter, getTrail?: () => readonly Step[]): import("ai").Tool<{
134
+ export declare function createReportTool(writer: FindingsWriter, getTrail?: () => readonly Step[] | Promise<readonly Step[]>): import("ai").Tool<{
115
135
  status: "passed" | "failed";
116
136
  steps: {
117
137
  step: string;
@@ -53,8 +53,8 @@ export const ReportInputSchema = z.object({
53
53
  });
54
54
  /**
55
55
  * Build the canonical findings record from a validated report input. The base
56
- * verdict shape; {@link terminalFindings} overlays the loop's recorded act-trail
57
- * on top, so both the persisted write and the returned counts agree.
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
58
  */
59
59
  export function reportFindings(input) {
60
60
  return {
@@ -65,22 +65,83 @@ export function reportFindings(input) {
65
65
  ...(input.summary !== undefined && { summary: input.summary }),
66
66
  };
67
67
  }
68
+ /** Pairing key for a reported step and a recorded one — case- and whitespace-insensitive. */
69
+ function stepKey(step) {
70
+ return step.step.trim().toLowerCase().replace(/\s+/g, ' ');
71
+ }
72
+ /**
73
+ * Fuse one reported step with the trail entry it restates: the driver's version
74
+ * wins field by field (its `ok`, its `note`), the recorded one fills what the
75
+ * driver left out — above all the evidence frame it never sees a path for.
76
+ */
77
+ function fuseStep(recorded, reported) {
78
+ const skipped = reported.skipped ?? recorded.skipped;
79
+ const note = reported.note ?? recorded.note;
80
+ const screenshot = reported.screenshot ?? recorded.screenshot;
81
+ return {
82
+ step: reported.step,
83
+ ok: reported.ok,
84
+ ...(skipped !== undefined && { skipped }),
85
+ ...(note !== undefined && { note }),
86
+ ...(screenshot !== undefined && { screenshot }),
87
+ };
88
+ }
89
+ /**
90
+ * Merge the driver's reported steps with the loop's recorded act-`trail`. Nothing
91
+ * is discarded: the driver's `ok: false` steps and notes (the prompt mandates
92
+ * them) survive alongside the mechanical trail and its evidence frames.
93
+ *
94
+ * The trail is the spine — it is the true chronology, recorded at act time — and
95
+ * each entry the driver restated verbatim (models commonly echo the `act` result
96
+ * label) is fused in place, driver fields winning, trail filling the gaps. Steps
97
+ * the driver reported that no trail entry matches — assertions, observations, acts
98
+ * from a step that also called `report` — follow in reported order, since nothing
99
+ * places them in the chronology. Both inputs keep their relative order, and equal
100
+ * labels pair up first-come-first-served, so repeating an action pairs each
101
+ * occurrence with a distinct trail entry.
102
+ */
103
+ export function mergeSteps(reported, trail) {
104
+ if (trail.length === 0)
105
+ return [...reported];
106
+ if (reported.length === 0)
107
+ return [...trail];
108
+ const pending = new Map();
109
+ reported.forEach((step, index) => {
110
+ const queue = pending.get(stepKey(step));
111
+ if (queue)
112
+ queue.push({ index, step });
113
+ else
114
+ pending.set(stepKey(step), [{ index, step }]);
115
+ });
116
+ const fused = new Set();
117
+ const merged = trail.map((recorded) => {
118
+ const hit = pending.get(stepKey(recorded))?.shift();
119
+ if (!hit)
120
+ return recorded;
121
+ fused.add(hit.index);
122
+ return fuseStep(recorded, hit.step);
123
+ });
124
+ for (const [index, step] of reported.entries()) {
125
+ if (!fused.has(index))
126
+ merged.push(step);
127
+ }
128
+ return merged;
129
+ }
68
130
  /**
69
131
  * The authoritative terminal {@link Findings}: the report input with the loop's
70
- * recorded act-`trail` overlaid as `steps` whenever one was captured. The driver's
71
- * `report` rarely restates the steps it took (and the trail carries the evidence
72
- * frames), so the trail wins; the reported steps are the fallback for a run that
73
- * recorded none. The single source of truth for the terminal write AND the counts,
74
- * so they never drift (a `0`-step result returned over a trail-filled file).
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).
75
136
  */
76
137
  export function terminalFindings(input, trail = []) {
77
138
  const findings = reportFindings(input);
78
- return trail.length > 0 ? { ...findings, steps: [...trail] } : findings;
139
+ return { ...findings, steps: mergeSteps(input.steps, trail) };
79
140
  }
80
141
  /**
81
142
  * Write the terminal verdict and report the stop. Both the persisted findings and
82
143
  * the returned counts derive from one {@link terminalFindings} object — the loop's
83
- * `trail` (when present) is authoritative for `steps`. Pure over the
144
+ * `trail` merged with the driver's reported steps. Pure over the
84
145
  * {@link FindingsWriter} seam, so it unit-tests against a fake with no disk.
85
146
  */
86
147
  export async function runReport(writer, input, trail = []) {
@@ -101,12 +162,18 @@ export async function runReport(writer, input, trail = []) {
101
162
  * Build the `report` tool bound to one findings store, for the debug agent's belt.
102
163
  * `getTrail` (when wired by the loop) supplies the recorded act-trail so the
103
164
  * written verdict and its counts both reflect the steps actually taken.
165
+ *
166
+ * 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
169
+ * `settled()`, which waits for it (see `belt/trail.ts`). Waiting is safe: the
170
+ * step's own `Promise.all` already awaits that act.
104
171
  */
105
172
  export function createReportTool(writer, getTrail) {
106
173
  return tool({
107
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.',
108
175
  inputSchema: ReportInputSchema,
109
- execute: (input) => runReport(writer, input, getTrail?.() ?? []),
176
+ execute: async (input) => runReport(writer, input, (await getTrail?.()) ?? []),
110
177
  });
111
178
  }
112
179
  //# 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,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAEpF,uFAAuF;AACvF,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAU,CAAC;AAExD;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,CAAC;SACN,IAAI,CAAC,iBAAiB,CAAC;SACvB,QAAQ,CACP,uFAAuF,CACxF;IACH,KAAK,EAAE,CAAC;SACL,KAAK,CAAC,UAAU,CAAC;SACjB,OAAO,CAAC,EAAE,CAAC;SACX,QAAQ,CAAC,0DAA0D,CAAC;IACvE,IAAI,EAAE,CAAC;SACJ,KAAK,CAAC,SAAS,CAAC;SACh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AAK,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,MAAM,QAAQ,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;KAC/E,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The run's shared act trail — the evidence spine `act` writes and `report` reads.
3
+ *
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
9
+ * flight. A trail lifted at step end reaches the terminal read too late: the
10
+ * verdict ships without the last thing the run did.
11
+ *
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.
16
+ */
17
+ import type { Step } from '../../findings/schema.js';
18
+ /**
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
+ */
23
+ export interface ActTrail {
24
+ /** Recorded steps in act order — the array the loop's running flush snapshots. */
25
+ readonly steps: Step[];
26
+ /** Announce an act in flight; call the returned function once it settles. */
27
+ begin(): () => void;
28
+ /** Record one finished act — `ok: true` with its frame, or `ok: false` with the error. */
29
+ record(step: Step): void;
30
+ /** The trail once no act is in flight — the read `report` takes before it writes. */
31
+ settled(): Promise<readonly Step[]>;
32
+ }
33
+ /** Build a fresh {@link ActTrail} for one run. */
34
+ export declare function createActTrail(): ActTrail;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The run's shared act trail — the evidence spine `act` writes and `report` reads.
3
+ *
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
9
+ * flight. A trail lifted at step end reaches the terminal read too late: the
10
+ * verdict ships without the last thing the run did.
11
+ *
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.
16
+ */
17
+ /** Let already-queued microtasks run — one full turn of the event loop. */
18
+ function nextTurn() {
19
+ return new Promise((resolve) => setTimeout(resolve, 0));
20
+ }
21
+ /** Build a fresh {@link ActTrail} for one run. */
22
+ export function createActTrail() {
23
+ const steps = [];
24
+ let inFlight = 0;
25
+ let idle = null;
26
+ let markIdle = null;
27
+ return {
28
+ steps,
29
+ begin() {
30
+ inFlight += 1;
31
+ idle ??= new Promise((resolve) => {
32
+ markIdle = resolve;
33
+ });
34
+ let settled = false;
35
+ return () => {
36
+ // Idempotent: a double-settle must not drop a sibling act's count.
37
+ if (settled)
38
+ return;
39
+ settled = true;
40
+ inFlight -= 1;
41
+ if (inFlight > 0)
42
+ return;
43
+ markIdle?.();
44
+ idle = null;
45
+ markIdle = null;
46
+ };
47
+ },
48
+ record(step) {
49
+ steps.push(step);
50
+ },
51
+ async settled() {
52
+ // Yield a full turn before checking: the sibling tool calls of this step are
53
+ // launched in microtasks, so an act listed AFTER `report` in the call list has
54
+ // not entered `begin()` yet when the terminal read starts. One turn guarantees
55
+ // every sibling has begun — otherwise the barrier would read an empty gate and
56
+ // miss exactly the act it exists to wait for.
57
+ await nextTurn();
58
+ while (idle !== null)
59
+ await idle;
60
+ return steps;
61
+ },
62
+ };
63
+ }
64
+ //# sourceMappingURL=trail.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trail.js","sourceRoot":"","sources":["../../../src/agent/belt/trail.ts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}
@@ -8,10 +8,10 @@
8
8
  *
9
9
  * Three-valued on purpose: `true` / `false` when the catalog answers, `null`
10
10
  * when it can't (endpoint missing, no `architecture` field — e.g. z.ai's
11
- * OpenAI-style `/models` — network error). Callers treat `null` as "don't
12
- * self-look": the separate-call path already fails soft (vision latch), while
13
- * an image pushed at a text-only DRIVER would poison every later step of the
14
- * run (the SDK re-sends tool results each turn).
11
+ * OpenAI-style `/models` — network error, malformed payload). Callers treat
12
+ * `null` as "don't self-look": the separate-call path already fails soft
13
+ * (vision latch), while an image pushed at a text-only DRIVER would poison
14
+ * every later step of the run (the SDK re-sends tool results each turn).
15
15
  */
16
16
  /**
17
17
  * The slice of `fetch` the probe needs — typed locally (the DOM lib is off
@@ -8,11 +8,35 @@
8
8
  *
9
9
  * Three-valued on purpose: `true` / `false` when the catalog answers, `null`
10
10
  * when it can't (endpoint missing, no `architecture` field — e.g. z.ai's
11
- * OpenAI-style `/models` — network error). Callers treat `null` as "don't
12
- * self-look": the separate-call path already fails soft (vision latch), while
13
- * an image pushed at a text-only DRIVER would poison every later step of the
14
- * run (the SDK re-sends tool results each turn).
11
+ * OpenAI-style `/models` — network error, malformed payload). Callers treat
12
+ * `null` as "don't self-look": the separate-call path already fails soft
13
+ * (vision latch), while an image pushed at a text-only DRIVER would poison
14
+ * every later step of the run (the SDK re-sends tool results each turn).
15
15
  */
16
+ import { z } from 'zod';
17
+ /** One models-catalog row, OpenRouter shape (other providers may omit `architecture`). */
18
+ const CatalogModelSchema = z.object({
19
+ id: z.string(),
20
+ architecture: z.object({ input_modalities: z.array(z.string()).optional() }).nullish(),
21
+ });
22
+ /**
23
+ * `/models` payload. A row that doesn't parse degrades to `null` and is skipped
24
+ * — one odd entry in a 300-model catalog must not blind the probe for every model.
25
+ */
26
+ const CatalogSchema = z.object({
27
+ data: z.array(CatalogModelSchema.nullable().catch(null)),
28
+ });
29
+ /**
30
+ * Catalog id for a routing-suffixed model id. The router accepts suffixes the
31
+ * `/models` catalog does not list as ids of their own — `#uptime` (the shipped
32
+ * default driver, `config/load.ts`), `:nitro`, `:floor`. Some suffixed ids ARE
33
+ * listed verbatim (`…:free`), so the probe tries the id as given first and only
34
+ * then falls back to this base form.
35
+ */
36
+ function baseModelId(modelId) {
37
+ const base = modelId.replace(/[#:].*$/, '');
38
+ return base || modelId; // nothing but suffix — no base to fall back to
39
+ }
16
40
  /**
17
41
  * Look the model up in the provider's `/models` catalog and report whether its
18
42
  * input modalities include `image`. `null` = the catalog can't say.
@@ -36,15 +60,16 @@ export async function supportsImageInput(baseUrl, apiKey, modelId, fetchImpl = f
36
60
  catch {
37
61
  return null;
38
62
  }
39
- const data = body.data;
40
- if (!Array.isArray(data))
41
- return null;
42
- const model = data.find((m) => m?.id === modelId);
43
- if (!model)
44
- return null;
45
- const modalities = model.architecture?.input_modalities;
46
- if (!Array.isArray(modalities))
47
- return null; // catalog exists but says nothing (e.g. z.ai)
63
+ const catalog = CatalogSchema.safeParse(body);
64
+ if (!catalog.success)
65
+ return null; // not a models catalog at all
66
+ const rows = catalog.data.data;
67
+ const base = baseModelId(modelId);
68
+ const model = rows.find((row) => row?.id === modelId) ??
69
+ (base === modelId ? undefined : rows.find((row) => row?.id === base));
70
+ const modalities = model?.architecture?.input_modalities;
71
+ if (!modalities)
72
+ return null; // model unlisted, or catalog says nothing (e.g. z.ai)
48
73
  return modalities.includes('image');
49
74
  }
50
75
  //# sourceMappingURL=capabilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../src/agent/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAiBH;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAe,EACf,MAAc,EACd,OAAe,EACf,YAAuB,KAAK;IAE5B,IAAI,GAAmC,CAAC;IACxC,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,SAAS,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAA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