@developerz.ai/ui-debugger-mcp 1.0.4 → 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 (161) 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 +81 -200
  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/browser/query.d.ts +3 -2
  35. package/dist/adapters/browser/query.js +68 -2
  36. package/dist/adapters/browser/query.js.map +1 -1
  37. package/dist/adapters/budget.d.ts +16 -0
  38. package/dist/adapters/budget.js +25 -0
  39. package/dist/adapters/budget.js.map +1 -0
  40. package/dist/adapters/contract.d.ts +29 -6
  41. package/dist/adapters/desktop/atspi.d.ts +15 -0
  42. package/dist/adapters/desktop/atspi.js +37 -17
  43. package/dist/adapters/desktop/atspi.js.map +1 -1
  44. package/dist/adapters/desktop/capture.js +8 -1
  45. package/dist/adapters/desktop/capture.js.map +1 -1
  46. package/dist/adapters/desktop/desktop-adapter.d.ts +9 -2
  47. package/dist/adapters/desktop/desktop-adapter.js +84 -32
  48. package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
  49. package/dist/adapters/desktop/input.d.ts +16 -1
  50. package/dist/adapters/desktop/input.js +30 -0
  51. package/dist/adapters/desktop/input.js.map +1 -1
  52. package/dist/adapters/desktop/proc.d.ts +18 -3
  53. package/dist/adapters/desktop/proc.js +48 -5
  54. package/dist/adapters/desktop/proc.js.map +1 -1
  55. package/dist/adapters/factory.d.ts +3 -1
  56. package/dist/adapters/factory.js +6 -2
  57. package/dist/adapters/factory.js.map +1 -1
  58. package/dist/adapters/limit.d.ts +10 -0
  59. package/dist/adapters/limit.js +19 -0
  60. package/dist/adapters/limit.js.map +1 -0
  61. package/dist/agent/belt/act.d.ts +27 -5
  62. package/dist/agent/belt/act.js +75 -17
  63. package/dist/agent/belt/act.js.map +1 -1
  64. package/dist/agent/belt/look.d.ts +37 -0
  65. package/dist/agent/belt/look.js +96 -4
  66. package/dist/agent/belt/look.js.map +1 -1
  67. package/dist/agent/belt/observe.d.ts +35 -9
  68. package/dist/agent/belt/observe.js +127 -18
  69. package/dist/agent/belt/observe.js.map +1 -1
  70. package/dist/agent/belt/report.d.ts +29 -9
  71. package/dist/agent/belt/report.js +77 -10
  72. package/dist/agent/belt/report.js.map +1 -1
  73. package/dist/agent/belt/trail.d.ts +34 -0
  74. package/dist/agent/belt/trail.js +64 -0
  75. package/dist/agent/belt/trail.js.map +1 -0
  76. package/dist/agent/capabilities.d.ts +30 -0
  77. package/dist/agent/capabilities.js +75 -0
  78. package/dist/agent/capabilities.js.map +1 -0
  79. package/dist/agent/loop.d.ts +68 -19
  80. package/dist/agent/loop.js +195 -51
  81. package/dist/agent/loop.js.map +1 -1
  82. package/dist/agent/prompts/compose.d.ts +9 -1
  83. package/dist/agent/prompts/compose.js +5 -4
  84. package/dist/agent/prompts/compose.js.map +1 -1
  85. package/dist/agent/prompts/debug-agent.d.ts +13 -1
  86. package/dist/agent/prompts/debug-agent.js +47 -7
  87. package/dist/agent/prompts/debug-agent.js.map +1 -1
  88. package/dist/agent/prompts/desktop-addendum.d.ts +1 -1
  89. package/dist/agent/prompts/desktop-addendum.js +1 -1
  90. package/dist/agent/prompts/web-addendum.d.ts +1 -1
  91. package/dist/agent/prompts/web-addendum.js +45 -17
  92. package/dist/agent/prompts/web-addendum.js.map +1 -1
  93. package/dist/agent/provider.d.ts +12 -3
  94. package/dist/agent/provider.js +13 -8
  95. package/dist/agent/provider.js.map +1 -1
  96. package/dist/cli/control.d.ts +3 -1
  97. package/dist/cli/control.js +26 -40
  98. package/dist/cli/control.js.map +1 -1
  99. package/dist/cli/help.d.ts +3 -1
  100. package/dist/cli/help.js +6 -2
  101. package/dist/cli/help.js.map +1 -1
  102. package/dist/cli/init.d.ts +3 -6
  103. package/dist/cli/init.js +64 -16
  104. package/dist/cli/init.js.map +1 -1
  105. package/dist/config/load.js +8 -1
  106. package/dist/config/load.js.map +1 -1
  107. package/dist/config/schema.d.ts +12 -5
  108. package/dist/config/schema.js +17 -7
  109. package/dist/config/schema.js.map +1 -1
  110. package/dist/errors.d.ts +22 -2
  111. package/dist/errors.js +36 -4
  112. package/dist/errors.js.map +1 -1
  113. package/dist/index.d.ts +1 -1
  114. package/dist/index.js +1 -1
  115. package/dist/main.js +38 -11
  116. package/dist/main.js.map +1 -1
  117. package/dist/mcp/server.d.ts +16 -1
  118. package/dist/mcp/server.js +23 -2
  119. package/dist/mcp/server.js.map +1 -1
  120. package/dist/mcp/server.test-helpers.d.ts +23 -0
  121. package/dist/mcp/server.test-helpers.js +49 -0
  122. package/dist/mcp/server.test-helpers.js.map +1 -0
  123. package/dist/mcp/tools/describe.js +5 -0
  124. package/dist/mcp/tools/describe.js.map +1 -1
  125. package/dist/mcp/tools/end-session.js +5 -0
  126. package/dist/mcp/tools/end-session.js.map +1 -1
  127. package/dist/mcp/tools/get-findings.js +23 -3
  128. package/dist/mcp/tools/get-findings.js.map +1 -1
  129. package/dist/mcp/tools/output.d.ts +50 -0
  130. package/dist/mcp/tools/output.js +55 -0
  131. package/dist/mcp/tools/output.js.map +1 -0
  132. package/dist/mcp/tools/result.d.ts +24 -1
  133. package/dist/mcp/tools/result.js +106 -5
  134. package/dist/mcp/tools/result.js.map +1 -1
  135. package/dist/mcp/tools/send-message.js +5 -0
  136. package/dist/mcp/tools/send-message.js.map +1 -1
  137. package/dist/mcp/tools/start-debug.js +7 -1
  138. package/dist/mcp/tools/start-debug.js.map +1 -1
  139. package/dist/services/debug-service.d.ts +38 -6
  140. package/dist/services/debug-service.js +122 -13
  141. package/dist/services/debug-service.js.map +1 -1
  142. package/dist/services/session-builder.d.ts +26 -3
  143. package/dist/services/session-builder.js +46 -14
  144. package/dist/services/session-builder.js.map +1 -1
  145. package/dist/session/atomic-write.d.ts +24 -0
  146. package/dist/session/atomic-write.js +39 -0
  147. package/dist/session/atomic-write.js.map +1 -0
  148. package/dist/session/findings-store.js +3 -4
  149. package/dist/session/findings-store.js.map +1 -1
  150. package/dist/session/process-identity.d.ts +16 -0
  151. package/dist/session/process-identity.js +29 -0
  152. package/dist/session/process-identity.js.map +1 -1
  153. package/dist/session/session.js +10 -2
  154. package/dist/session/session.js.map +1 -1
  155. package/dist/session/state-file.d.ts +51 -5
  156. package/dist/session/state-file.js +60 -8
  157. package/dist/session/state-file.js.map +1 -1
  158. package/dist/session/workspace.d.ts +11 -0
  159. package/dist/session/workspace.js +14 -1
  160. package/dist/session/workspace.js.map +1 -1
  161. package/package.json +4 -1
@@ -20,7 +20,7 @@
20
20
  */
21
21
  import { generateText, tool } from 'ai';
22
22
  import { z } from 'zod';
23
- import { AgentError } from '../../errors.js';
23
+ import { AgentError, VisionUnavailableError } from '../../errors.js';
24
24
  /** `look` input — both optional: ask a `question`, and/or state the `expect`ed look. */
25
25
  export const LookInputSchema = z.object({
26
26
  question: z
@@ -91,6 +91,27 @@ function truncate(text, max = 200) {
91
91
  const trimmed = text.trim();
92
92
  return trimmed.length > max ? `${trimmed.slice(0, max)}…` : trimmed;
93
93
  }
94
+ /**
95
+ * Provider messages that mean "this model cannot take image input" — a permanent
96
+ * condition for the run, not a transient failure. Covers the OpenAI-compatible
97
+ * phrasings seen in the wild, e.g. z.ai's
98
+ * `messages.content.type is invalid, allowed values: ['text']` and OpenRouter's
99
+ * "model does not support image input" variants.
100
+ */
101
+ const IMAGE_REJECTION = /content[._\s]?type[^.]{0,40}(invalid|unsupported|not (allowed|supported))|allowed values[^.]{0,20}'?text'?|does(n'?t| not) support (image|vision|multimodal)|(image|vision|multimodal)[^.]{0,40}(is |are )?not supported|unsupported (image|content) type|invalid content type/i;
102
+ /** Whether a provider error says the vision model rejected image input (text-only model). */
103
+ export function isImageRejection(message) {
104
+ return IMAGE_REJECTION.test(message);
105
+ }
106
+ /** The latched, actionable message the driver gets when the vision model is text-only. */
107
+ export function visionUnavailableMessage(modelId, providerMessage) {
108
+ return (`look is unavailable for this run: vision model '${modelId}' rejected image input ` +
109
+ `(provider said: ${JSON.stringify(truncate(providerMessage, 140))}). The configured ` +
110
+ 'models.vision appears to be text-only — set it to a multimodal model in ' +
111
+ '.ui-debugger-mcp.json. Do NOT call look again this run; verify what you can from ' +
112
+ 'observe (tree/console/network) and state in your report summary that visual checks ' +
113
+ 'could not be performed.');
114
+ }
94
115
  /** Pull the JSON object out of a reply — tolerant of ```json fences and stray prose. */
95
116
  function extractJson(text) {
96
117
  const fenced = /```(?:json)?\s*([\s\S]*?)\s*```/i.exec(text);
@@ -146,19 +167,90 @@ export async function runLook(adapter, generate, recorder, input, abortSignal) {
146
167
  const screenshot = await recorder.saveScreenshot(lookLabel(input), png);
147
168
  return { ...reply, screenshot };
148
169
  }
170
+ /**
171
+ * Build `look`'s execute closure with the vision-unavailable latch: once a call
172
+ * dies on {@link VisionUnavailableError} (text-only vision model), every later
173
+ * call fails fast with the same guidance — no screenshot, no provider round-trip.
174
+ * Exported apart from the `tool()` wrapper so the latch unit-tests against fakes.
175
+ */
176
+ export function createLookExecute(adapter, generate, recorder) {
177
+ let unavailable;
178
+ return async (input, abortSignal) => {
179
+ if (unavailable)
180
+ throw unavailable;
181
+ try {
182
+ return await runLook(adapter, generate, recorder, input, abortSignal);
183
+ }
184
+ catch (e) {
185
+ if (e instanceof VisionUnavailableError)
186
+ unavailable = e;
187
+ throw e;
188
+ }
189
+ };
190
+ }
191
+ /**
192
+ * Build `look` for a MULTIMODAL driver (self-look): when control + vision are the
193
+ * SAME model, a second blind vision call wastes a round-trip and drops the run's
194
+ * context — instead the tool returns the frame itself as multimodal tool output
195
+ * (`toModelOutput` → `content` with a `file-data` part), so the driver looks at
196
+ * the screenshot with its own eyes, in full conversation context.
197
+ *
198
+ * Older frames are pruned from the transcript by the loop (`pruneStaleFrames`) so
199
+ * repeated looks never stack images in the re-sent history — only the newest frame
200
+ * stays live.
201
+ */
202
+ export function createSelfLookTool(adapter, recorder) {
203
+ return tool({
204
+ description: 'Capture the current screen and LOOK at it yourself — the screenshot is attached to this tool result and you are multimodal. Judge layout, alignment, colour, overlap, cut-off text against your question/expect. Only the newest frame stays in context (older ones are pruned), so call again after the screen changes.',
205
+ inputSchema: LookInputSchema,
206
+ execute: async (input) => {
207
+ const png = await adapter.screenshot();
208
+ const screenshot = await recorder.saveScreenshot(lookLabel(input), png);
209
+ return {
210
+ screenshot,
211
+ bytes: png.byteLength,
212
+ prompt: buildPrompt(input),
213
+ frame: Buffer.from(png).toString('base64'),
214
+ };
215
+ },
216
+ toModelOutput: ({ output }) => ({
217
+ type: 'content',
218
+ value: [
219
+ {
220
+ type: 'text',
221
+ text: `screenshot saved: ${output.screenshot}\n${output.prompt}\n` +
222
+ 'The frame is attached — judge it yourself and record any visual findings ' +
223
+ `(cite ${output.screenshot} as the evidence path).`,
224
+ },
225
+ { type: 'file-data', data: output.frame, mediaType: 'image/png' },
226
+ ],
227
+ }),
228
+ });
229
+ }
149
230
  /** Build the `look` tool bound to one adapter + vision model + recorder, for the belt. */
150
231
  export function createLookTool(adapter, vision, recorder) {
232
+ const modelId = typeof vision === 'string' ? vision : vision.modelId;
151
233
  // Forward the abort signal into the vision call: on end_session / wall-clock
152
234
  // timeout the SDK aborts the tool's execute — without the signal a stalled
153
235
  // vision provider would block Session.close() (abort + await run) indefinitely.
154
236
  const generate = async ({ system, messages, abortSignal }) => {
155
- const { text } = await generateText({ model: vision, system, messages, abortSignal });
156
- return { text };
237
+ try {
238
+ const { text } = await generateText({ model: vision, system, messages, abortSignal });
239
+ return { text };
240
+ }
241
+ catch (e) {
242
+ const message = e instanceof Error ? e.message : String(e);
243
+ if (isImageRejection(message)) {
244
+ throw new VisionUnavailableError(visionUnavailableMessage(modelId, message));
245
+ }
246
+ throw e;
247
+ }
157
248
  };
249
+ const execute = createLookExecute(adapter, generate, recorder);
158
250
  return tool({
159
251
  description: 'Ask the vision model to look at the current screen. Captures a screenshot and sends it with your question/expect to the multimodal "eyes", which judges how it looks (layout, alignment, colour, overlap, cut-off text). Returns { description, matches?, issues[] } with the screenshot saved as evidence. Use only when structure (observe) cannot answer — vision is slow and costly.',
160
252
  inputSchema: LookInputSchema,
161
- execute: (input, options) => runLook(adapter, generate, recorder, input, options.abortSignal),
253
+ execute: (input, options) => execute(input, options.abortSignal),
162
254
  });
163
255
  }
164
256
  //# sourceMappingURL=look.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"look.js","sourceRoot":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AM,OAAO,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC3D,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC9B,MAAM,IAAI,sBAAsB,CAAC,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YAC/E,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC,CAAC;IACF,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC/D,OAAO,IAAI,CAAC;QACV,WAAW,EACT,0XAA0X;QAC5X,WAAW,EAAE,eAAe;QAC5B,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC;KACjE,CAAC,CAAC;AACL,CAAC"}
@@ -24,8 +24,19 @@
24
24
  * swallow it or silently fall back.
25
25
  */
26
26
  import { z } from 'zod';
27
- import type { Adapter, ConsoleEntry, NetworkEntry, Node } from '../../adapters/contract.js';
27
+ import type { Adapter, ConsoleEntry, NetworkEntry, Node, NodeRef } from '../../adapters/contract.js';
28
28
  import type { EvidenceRecorder } from './look.js';
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 declare const OBSERVE_KINDS: readonly ["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 declare const NODE_FIELDS: readonly ["role", "name", "bounds", "enabled", "testid", "style"];
29
40
  /** `observe` input — flat + SQL-like; `kind` picks the table, the rest compose the read. */
30
41
  export declare const ObserveInputSchema: z.ZodObject<{
31
42
  kind: z.ZodEnum<{
@@ -37,22 +48,25 @@ export declare const ObserveInputSchema: z.ZodObject<{
37
48
  query: z.ZodOptional<z.ZodString>;
38
49
  fields: z.ZodOptional<z.ZodArray<z.ZodEnum<{
39
50
  name: "name";
40
- role: "role";
41
51
  bounds: "bounds";
42
52
  enabled: "enabled";
53
+ role: "role";
54
+ testid: "testid";
55
+ style: "style";
43
56
  }>>>;
44
57
  filters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
45
58
  limit: z.ZodOptional<z.ZodNumber>;
46
59
  within: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
47
60
  role: z.ZodString;
48
61
  name: z.ZodString;
49
- bounds: z.ZodObject<{
62
+ bounds: z.ZodOptional<z.ZodObject<{
50
63
  x: z.ZodNumber;
51
64
  y: z.ZodNumber;
52
65
  width: z.ZodNumber;
53
66
  height: z.ZodNumber;
54
- }, z.core.$strip>;
55
- enabled: z.ZodBoolean;
67
+ }, z.core.$strip>>;
68
+ enabled: z.ZodOptional<z.ZodBoolean>;
69
+ testid: z.ZodOptional<z.ZodString>;
56
70
  }, z.core.$strip>]>>;
57
71
  }, z.core.$strip>;
58
72
  export type ObserveInput = z.infer<typeof ObserveInputSchema>;
@@ -78,6 +92,17 @@ export type ObserveResult = {
78
92
  count: number;
79
93
  entries: NetworkEntry[];
80
94
  };
95
+ /**
96
+ * Resolve `within` to something the {@link Adapter} contract takes — a selector string
97
+ * or a {@link Node}. Two coercions, each fixing a shape drivers actually produce:
98
+ *
99
+ * - a JSON-*stringified* node (`within: "{\"role\": …}"`). Before this it fell through
100
+ * as a selector, normalized to `text={"role"…}`, matched nothing, and returned an
101
+ * empty tree with no clue why — the single biggest step-waster observed.
102
+ * Garbage-that-looks-like-JSON fails loud instead of reading the whole page.
103
+ * - a node projected without `bounds` (`fields:["role","name"]`) → {@link scopeOf}.
104
+ */
105
+ export declare function coerceWithin(within: ObserveInput['within']): NodeRef | undefined;
81
106
  /**
82
107
  * Route one `observe` call to the adapter and shape the result. Pure over the
83
108
  * {@link Adapter} + {@link EvidenceRecorder} seams (no `tool()` wrapper), so it
@@ -88,18 +113,19 @@ export declare function runObserve(adapter: Adapter, recorder: EvidenceRecorder,
88
113
  export declare function createObserveTool(adapter: Adapter, recorder: EvidenceRecorder): import("ai").Tool<{
89
114
  kind: "screenshot" | "console" | "network" | "tree";
90
115
  query?: string | undefined;
91
- fields?: ("name" | "role" | "bounds" | "enabled")[] | undefined;
116
+ fields?: ("name" | "bounds" | "enabled" | "role" | "testid" | "style")[] | undefined;
92
117
  filters?: Record<string, string | number | boolean | string[]> | undefined;
93
118
  limit?: number | undefined;
94
119
  within?: string | {
95
120
  role: string;
96
121
  name: string;
97
- bounds: {
122
+ bounds?: {
98
123
  x: number;
99
124
  y: number;
100
125
  width: number;
101
126
  height: number;
102
- };
103
- enabled: boolean;
127
+ } | undefined;
128
+ enabled?: boolean | undefined;
129
+ testid?: string | undefined;
104
130
  } | undefined;
105
131
  }, ObserveResult>;
@@ -26,10 +26,44 @@
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 = ['role', 'name', 'bounds', 'enabled'];
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 = [
40
+ 'role',
41
+ 'name',
42
+ 'bounds',
43
+ 'enabled',
44
+ 'testid',
45
+ 'style',
46
+ ];
47
+ /**
48
+ * Columns a no-`fields` read returns. `style` (colour + contrast per text node)
49
+ * is opt-in only — on a 200-node default read it would triple the payload the
50
+ * text driver re-reads every step for data it rarely needs.
51
+ */
52
+ const DEFAULT_PROJECTION = [
53
+ 'role',
54
+ 'name',
55
+ 'bounds',
56
+ 'enabled',
57
+ 'testid',
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;
33
67
  /** One `filters` predicate value; arrays back `_in`-style set membership (matches `FilterValue`). */
34
68
  const FilterValueSchema = z.union([z.string(), z.number(), z.boolean(), z.array(z.string())]);
35
69
  /** On-screen rectangle backing a {@link Node} `within` reference. */
@@ -39,12 +73,20 @@ const BoundsSchema = z.object({
39
73
  width: z.number(),
40
74
  height: z.number(),
41
75
  });
42
- /** 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
+ */
43
84
  const NodeSchema = z.object({
44
85
  role: z.string(),
45
86
  name: z.string(),
46
- bounds: BoundsSchema,
47
- enabled: z.boolean(),
87
+ bounds: BoundsSchema.optional(),
88
+ enabled: z.boolean().optional(),
89
+ testid: z.string().optional(),
48
90
  });
49
91
  /** `observe` input — flat + SQL-like; `kind` picks the table, the rest compose the read. */
50
92
  export const ObserveInputSchema = z.object({
@@ -61,11 +103,16 @@ export const ObserveInputSchema = z.object({
61
103
  .record(z.string(), FilterValueSchema)
62
104
  .optional()
63
105
  .describe('WHERE-style predicates, e.g. { visible_eq: true } | { status_gte: 400 }; per-channel'),
64
- 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})`),
65
112
  within: z
66
113
  .union([z.string(), NodeSchema])
67
114
  .optional()
68
- .describe('tree scope: restrict to a subtree/region (a selector or a node)'),
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)'),
69
116
  });
70
117
  /** ARIA roles Playwright's `role=` engine accepts (others fall back to a text selector). */
71
118
  const ARIA_ROLES = new Set([
@@ -100,6 +147,9 @@ const ARIA_ROLES = new Set([
100
147
  * `null` for an unnamed, non-semantic node (the agent targets those by other means).
101
148
  */
102
149
  function baseSelector(node) {
150
+ // A test hook beats everything: document-unique, stable across renames/moves.
151
+ if (node.testid)
152
+ return `data-testid=${JSON.stringify(node.testid)}`;
103
153
  const name = node.name.trim();
104
154
  if (node.role && ARIA_ROLES.has(node.role) && name) {
105
155
  return `role=${node.role}[name=${JSON.stringify(name)} i]`;
@@ -117,15 +167,20 @@ function baseSelector(node) {
117
167
  * index — and even a bare role/text selector — can resolve a different element when
118
168
  * `act` replays it with an unscoped, document-wide `find` (e.g. header "Settings"
119
169
  * instead of the sidebar "Settings" the narrowed read returned). In that case we
120
- * emit no `target`: better the agent falls back (visible text / `role "name"`) than
121
- * act on the wrong node.
170
+ * emit no `target` — EXCEPT a `data-testid` one, which is document-unique and
171
+ * survives any scoping. Otherwise, better the agent falls back (visible text /
172
+ * `role "name"`) than act on the wrong node.
122
173
  */
123
174
  function withTargets(nodes, fields, scoped = false) {
124
175
  const seen = new Map();
176
+ const projection = fields && fields.length > 0 ? fields : DEFAULT_PROJECTION;
125
177
  return nodes.map((node) => {
126
- const projected = fields && fields.length > 0 ? pick(node, fields) : { ...node };
127
- if (scoped)
178
+ const projected = pick(node, projection);
179
+ if (scoped) {
180
+ if (node.testid)
181
+ projected.target = `data-testid=${JSON.stringify(node.testid)}`;
128
182
  return projected;
183
+ }
129
184
  const base = baseSelector(node);
130
185
  if (!base)
131
186
  return projected;
@@ -138,10 +193,61 @@ function withTargets(nodes, fields, scoped = false) {
138
193
  /** Pick a subset of keys off an object (a typed `SELECT cols`) for the `fields` projection. */
139
194
  function pick(obj, keys) {
140
195
  const out = {};
196
+ // Skip absent optionals (testid/style) so they never serialize as explicit nulls.
141
197
  for (const key of keys)
142
- out[key] = obj[key];
198
+ if (obj[key] !== undefined)
199
+ out[key] = obj[key];
143
200
  return out;
144
201
  }
202
+ /**
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}.
230
+ */
231
+ export function coerceWithin(within) {
232
+ if (within === undefined)
233
+ return undefined;
234
+ if (typeof within !== 'string')
235
+ return scopeOf(within);
236
+ if (!within.trimStart().startsWith('{'))
237
+ return within;
238
+ let data;
239
+ try {
240
+ data = JSON.parse(within);
241
+ }
242
+ catch {
243
+ throw new AgentError('observe `within` looks like a JSON node but does not parse — pass the node OBJECT exactly as observe returned it, or a selector string');
244
+ }
245
+ const parsed = NodeSchema.safeParse(data);
246
+ if (!parsed.success) {
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');
248
+ }
249
+ return scopeOf(parsed.data);
250
+ }
145
251
  /**
146
252
  * Route one `observe` call to the adapter and shape the result. Pure over the
147
253
  * {@link Adapter} + {@link EvidenceRecorder} seams (no `tool()` wrapper), so it
@@ -151,8 +257,9 @@ export async function runObserve(adapter, recorder, input) {
151
257
  const { kind, query, fields, filters, limit, within } = input;
152
258
  switch (kind) {
153
259
  case 'tree': {
154
- const nodes = await adapter.readState({ query, filters, limit, within });
155
- const scoped = query !== undefined || within !== undefined || filters !== undefined;
260
+ const scope = coerceWithin(within);
261
+ const nodes = await adapter.readState({ query, filters, limit, within: scope });
262
+ const scoped = query !== undefined || scope !== undefined || filters !== undefined;
156
263
  const projected = withTargets(nodes, fields, scoped);
157
264
  return { kind, count: projected.length, nodes: projected };
158
265
  }
@@ -164,12 +271,14 @@ export async function runObserve(adapter, recorder, input) {
164
271
  const path = await recorder.saveScreenshot('observe', png);
165
272
  return { kind, path, bytes: png.byteLength };
166
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.
167
276
  case 'console': {
168
- const entries = await adapter.console({ filters, limit });
277
+ const entries = await adapter.console({ filters, limit: limit ?? DEFAULT_LOG_LIMIT });
169
278
  return { kind, count: entries.length, entries };
170
279
  }
171
280
  case 'network': {
172
- const entries = await adapter.network({ filters, limit });
281
+ const entries = await adapter.network({ filters, limit: limit ?? DEFAULT_LOG_LIMIT });
173
282
  return { kind, count: entries.length, entries };
174
283
  }
175
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,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAyC,CAAC;AAElG,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;AACrE,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;IACb,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;IACb,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,C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,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;