@developerz.ai/ui-debugger-mcp 1.0.3 → 1.1.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 (71) hide show
  1. package/dist/adapters/android/android-adapter.d.ts +7 -0
  2. package/dist/adapters/android/android-adapter.js +52 -9
  3. package/dist/adapters/android/android-adapter.js.map +1 -1
  4. package/dist/adapters/android/commands.d.ts +11 -2
  5. package/dist/adapters/android/commands.js +21 -3
  6. package/dist/adapters/android/commands.js.map +1 -1
  7. package/dist/adapters/browser/browser-adapter.d.ts +26 -2
  8. package/dist/adapters/browser/browser-adapter.js +178 -13
  9. package/dist/adapters/browser/browser-adapter.js.map +1 -1
  10. package/dist/adapters/browser/query.d.ts +3 -2
  11. package/dist/adapters/browser/query.js +72 -4
  12. package/dist/adapters/browser/query.js.map +1 -1
  13. package/dist/adapters/contract.d.ts +16 -0
  14. package/dist/adapters/desktop/atspi.js +10 -1
  15. package/dist/adapters/desktop/atspi.js.map +1 -1
  16. package/dist/adapters/desktop/desktop-adapter.js +10 -1
  17. package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
  18. package/dist/adapters/desktop/input.js +8 -2
  19. package/dist/adapters/desktop/input.js.map +1 -1
  20. package/dist/adapters/desktop/proc.d.ts +6 -1
  21. package/dist/adapters/desktop/proc.js +12 -2
  22. package/dist/adapters/desktop/proc.js.map +1 -1
  23. package/dist/agent/belt/act.js +2 -1
  24. package/dist/agent/belt/act.js.map +1 -1
  25. package/dist/agent/belt/look.d.ts +40 -1
  26. package/dist/agent/belt/look.js +102 -6
  27. package/dist/agent/belt/look.js.map +1 -1
  28. package/dist/agent/belt/observe.d.ts +23 -8
  29. package/dist/agent/belt/observe.js +82 -24
  30. package/dist/agent/belt/observe.js.map +1 -1
  31. package/dist/agent/belt/report.d.ts +2 -0
  32. package/dist/agent/capabilities.d.ts +30 -0
  33. package/dist/agent/capabilities.js +50 -0
  34. package/dist/agent/capabilities.js.map +1 -0
  35. package/dist/agent/loop.d.ts +24 -6
  36. package/dist/agent/loop.js +81 -14
  37. package/dist/agent/loop.js.map +1 -1
  38. package/dist/agent/prompts/debug-agent.d.ts +1 -1
  39. package/dist/agent/prompts/debug-agent.js +6 -0
  40. package/dist/agent/prompts/debug-agent.js.map +1 -1
  41. package/dist/agent/prompts/web-addendum.d.ts +1 -1
  42. package/dist/agent/prompts/web-addendum.js +33 -3
  43. package/dist/agent/prompts/web-addendum.js.map +1 -1
  44. package/dist/agent/provider.d.ts +12 -3
  45. package/dist/agent/provider.js +13 -8
  46. package/dist/agent/provider.js.map +1 -1
  47. package/dist/cli/control.js +7 -0
  48. package/dist/cli/control.js.map +1 -1
  49. package/dist/errors.d.ts +12 -0
  50. package/dist/errors.js +20 -0
  51. package/dist/errors.js.map +1 -1
  52. package/dist/findings/schema.d.ts +2 -0
  53. package/dist/findings/schema.js +4 -0
  54. package/dist/findings/schema.js.map +1 -1
  55. package/dist/main.js +16 -3
  56. package/dist/main.js.map +1 -1
  57. package/dist/services/debug-service.d.ts +6 -2
  58. package/dist/services/debug-service.js +64 -24
  59. package/dist/services/debug-service.js.map +1 -1
  60. package/dist/services/session-builder.d.ts +6 -0
  61. package/dist/services/session-builder.js +5 -3
  62. package/dist/services/session-builder.js.map +1 -1
  63. package/dist/services/summarize.d.ts +3 -1
  64. package/dist/services/summarize.js +7 -4
  65. package/dist/services/summarize.js.map +1 -1
  66. package/dist/session/findings-store.js +20 -7
  67. package/dist/session/findings-store.js.map +1 -1
  68. package/dist/session/session.d.ts +3 -2
  69. package/dist/session/session.js +11 -6
  70. package/dist/session/session.js.map +1 -1
  71. package/package.json +1 -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);
@@ -127,7 +148,7 @@ function parseVisionReply(text) {
127
148
  * {@link Adapter}, {@link VisionGenerate} and {@link EvidenceRecorder} seams, so
128
149
  * it unit-tests against fakes with no network.
129
150
  */
130
- export async function runLook(adapter, generate, recorder, input) {
151
+ export async function runLook(adapter, generate, recorder, input, abortSignal) {
131
152
  const png = await adapter.screenshot();
132
153
  const { text } = await generate({
133
154
  system: VISION_SYSTEM_PROMPT,
@@ -140,21 +161,96 @@ export async function runLook(adapter, generate, recorder, input) {
140
161
  ],
141
162
  },
142
163
  ],
164
+ abortSignal,
143
165
  });
144
166
  const reply = parseVisionReply(text);
145
167
  const screenshot = await recorder.saveScreenshot(lookLabel(input), png);
146
168
  return { ...reply, screenshot };
147
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
+ }
148
230
  /** Build the `look` tool bound to one adapter + vision model + recorder, for the belt. */
149
231
  export function createLookTool(adapter, vision, recorder) {
150
- const generate = async ({ system, messages }) => {
151
- const { text } = await generateText({ model: vision, system, messages });
152
- return { text };
232
+ const modelId = typeof vision === 'string' ? vision : vision.modelId;
233
+ // Forward the abort signal into the vision call: on end_session / wall-clock
234
+ // timeout the SDK aborts the tool's execute — without the signal a stalled
235
+ // vision provider would block Session.close() (abort + await run) indefinitely.
236
+ const generate = async ({ system, messages, abortSignal }) => {
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
+ }
153
248
  };
249
+ const execute = createLookExecute(adapter, generate, recorder);
154
250
  return tool({
155
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.',
156
252
  inputSchema: LookInputSchema,
157
- execute: (input) => runLook(adapter, generate, recorder, input),
253
+ execute: (input, options) => execute(input, options.abortSignal),
158
254
  });
159
255
  }
160
256
  //# sourceMappingURL=look.js.map
@@ -1 +1 @@
1
- {"version":3,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AC;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"}
@@ -4,7 +4,9 @@
4
4
  * One SQL-like reader, four "tables" picked by `kind`, each routed to one method
5
5
  * on the shared {@link Adapter} contract:
6
6
  * - `tree` → `readState` (normalized UI nodes; DOM · a11y · view-hierarchy)
7
- * - `screenshot` → `screenshot` (PNG bytes, base64 — an evidence frame)
7
+ * - `screenshot` → `screenshot` (an evidence frame, SAVED to `screenshots/` — the
8
+ * driver is a blind text model and the SDK re-sends tool results every step, so
9
+ * the result carries the saved path, never the PNG bytes)
8
10
  * - `console` → `console` (captured console/error log, newest first)
9
11
  * - `network` → `network` (captured network exchanges, newest first)
10
12
  *
@@ -23,6 +25,7 @@
23
25
  */
24
26
  import { z } from 'zod';
25
27
  import type { Adapter, ConsoleEntry, NetworkEntry, Node } from '../../adapters/contract.js';
28
+ import type { EvidenceRecorder } from './look.js';
26
29
  /** `observe` input — flat + SQL-like; `kind` picks the table, the rest compose the read. */
27
30
  export declare const ObserveInputSchema: z.ZodObject<{
28
31
  kind: z.ZodEnum<{
@@ -37,6 +40,8 @@ export declare const ObserveInputSchema: z.ZodObject<{
37
40
  role: "role";
38
41
  bounds: "bounds";
39
42
  enabled: "enabled";
43
+ testid: "testid";
44
+ style: "style";
40
45
  }>>>;
41
46
  filters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
42
47
  limit: z.ZodOptional<z.ZodNumber>;
@@ -50,6 +55,7 @@ export declare const ObserveInputSchema: z.ZodObject<{
50
55
  height: z.ZodNumber;
51
56
  }, z.core.$strip>;
52
57
  enabled: z.ZodBoolean;
58
+ testid: z.ZodOptional<z.ZodString>;
53
59
  }, z.core.$strip>]>>;
54
60
  }, z.core.$strip>;
55
61
  export type ObserveInput = z.infer<typeof ObserveInputSchema>;
@@ -64,9 +70,8 @@ export type ObserveResult = {
64
70
  nodes: TreeNode[];
65
71
  } | {
66
72
  kind: 'screenshot';
67
- encoding: 'png';
73
+ path: string;
68
74
  bytes: number;
69
- data: string;
70
75
  } | {
71
76
  kind: 'console';
72
77
  count: number;
@@ -76,16 +81,25 @@ export type ObserveResult = {
76
81
  count: number;
77
82
  entries: NetworkEntry[];
78
83
  };
84
+ /**
85
+ * Accept a JSON-*stringified* node for `within`. Drivers routinely paste the node
86
+ * back as a string (`within: "{\"role\": …}"`); before this coercion that string
87
+ * fell through as a selector, normalized to `text={"role"…}`, matched nothing, and
88
+ * returned an empty tree with no clue why — the single biggest step-waster observed.
89
+ * Garbage-that-looks-like-JSON fails loud instead of silently reading the whole page.
90
+ */
91
+ export declare function coerceWithin(within: ObserveInput['within']): ObserveInput['within'];
79
92
  /**
80
93
  * Route one `observe` call to the adapter and shape the result. Pure over the
81
- * {@link Adapter} seam (no `tool()` wrapper), so it unit-tests against a fake.
94
+ * {@link Adapter} + {@link EvidenceRecorder} seams (no `tool()` wrapper), so it
95
+ * unit-tests against fakes.
82
96
  */
83
- export declare function runObserve(adapter: Adapter, input: ObserveInput): Promise<ObserveResult>;
84
- /** Build the `observe` tool bound to one adapter, for the debug agent's belt. */
85
- export declare function createObserveTool(adapter: Adapter): import("ai").Tool<{
97
+ export declare function runObserve(adapter: Adapter, recorder: EvidenceRecorder, input: ObserveInput): Promise<ObserveResult>;
98
+ /** Build the `observe` tool bound to one adapter + recorder, for the debug agent's belt. */
99
+ export declare function createObserveTool(adapter: Adapter, recorder: EvidenceRecorder): import("ai").Tool<{
86
100
  kind: "screenshot" | "console" | "network" | "tree";
87
101
  query?: string | undefined;
88
- fields?: ("name" | "role" | "bounds" | "enabled")[] | undefined;
102
+ fields?: ("name" | "role" | "bounds" | "enabled" | "testid" | "style")[] | undefined;
89
103
  filters?: Record<string, string | number | boolean | string[]> | undefined;
90
104
  limit?: number | undefined;
91
105
  within?: string | {
@@ -98,5 +112,6 @@ export declare function createObserveTool(adapter: Adapter): import("ai").Tool<{
98
112
  height: number;
99
113
  };
100
114
  enabled: boolean;
115
+ testid?: string | undefined;
101
116
  } | undefined;
102
117
  }, ObserveResult>;
@@ -4,7 +4,9 @@
4
4
  * One SQL-like reader, four "tables" picked by `kind`, each routed to one method
5
5
  * on the shared {@link Adapter} contract:
6
6
  * - `tree` → `readState` (normalized UI nodes; DOM · a11y · view-hierarchy)
7
- * - `screenshot` → `screenshot` (PNG bytes, base64 — an evidence frame)
7
+ * - `screenshot` → `screenshot` (an evidence frame, SAVED to `screenshots/` — the
8
+ * driver is a blind text model and the SDK re-sends tool results every step, so
9
+ * the result carries the saved path, never the PNG bytes)
8
10
  * - `console` → `console` (captured console/error log, newest first)
9
11
  * - `network` → `network` (captured network exchanges, newest first)
10
12
  *
@@ -27,7 +29,26 @@ import { AgentError } from '../../errors.js';
27
29
  /** The four observable channels `kind` selects (each routes to one contract method). */
28
30
  const OBSERVE_KINDS = ['tree', 'screenshot', 'console', 'network'];
29
31
  /** Selectable {@link Node} columns — the `fields` projection whitelist (contract-level). */
30
- const NODE_FIELDS = ['role', 'name', 'bounds', 'enabled'];
32
+ const NODE_FIELDS = [
33
+ 'role',
34
+ 'name',
35
+ 'bounds',
36
+ 'enabled',
37
+ 'testid',
38
+ 'style',
39
+ ];
40
+ /**
41
+ * Columns a no-`fields` read returns. `style` (colour + contrast per text node)
42
+ * is opt-in only — on a 200-node default read it would triple the payload the
43
+ * text driver re-reads every step for data it rarely needs.
44
+ */
45
+ const DEFAULT_PROJECTION = [
46
+ 'role',
47
+ 'name',
48
+ 'bounds',
49
+ 'enabled',
50
+ 'testid',
51
+ ];
31
52
  /** One `filters` predicate value; arrays back `_in`-style set membership (matches `FilterValue`). */
32
53
  const FilterValueSchema = z.union([z.string(), z.number(), z.boolean(), z.array(z.string())]);
33
54
  /** On-screen rectangle backing a {@link Node} `within` reference. */
@@ -43,6 +64,7 @@ const NodeSchema = z.object({
43
64
  name: z.string(),
44
65
  bounds: BoundsSchema,
45
66
  enabled: z.boolean(),
67
+ testid: z.string().optional(),
46
68
  });
47
69
  /** `observe` input — flat + SQL-like; `kind` picks the table, the rest compose the read. */
48
70
  export const ObserveInputSchema = z.object({
@@ -63,7 +85,7 @@ export const ObserveInputSchema = z.object({
63
85
  within: z
64
86
  .union([z.string(), NodeSchema])
65
87
  .optional()
66
- .describe('tree scope: restrict to a subtree/region (a selector or a node)'),
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)'),
67
89
  });
68
90
  /** ARIA roles Playwright's `role=` engine accepts (others fall back to a text selector). */
69
91
  const ARIA_ROLES = new Set([
@@ -98,6 +120,9 @@ const ARIA_ROLES = new Set([
98
120
  * `null` for an unnamed, non-semantic node (the agent targets those by other means).
99
121
  */
100
122
  function baseSelector(node) {
123
+ // A test hook beats everything: document-unique, stable across renames/moves.
124
+ if (node.testid)
125
+ return `data-testid=${JSON.stringify(node.testid)}`;
101
126
  const name = node.name.trim();
102
127
  if (node.role && ARIA_ROLES.has(node.role) && name) {
103
128
  return `role=${node.role}[name=${JSON.stringify(name)} i]`;
@@ -111,17 +136,24 @@ function baseSelector(node) {
111
136
  * `>> nth=` in document order — so the agent never has to invent a selector (the
112
137
  * #1 cause of wasted steps: a blind model guessing CSS that does not resolve).
113
138
  *
114
- * A `scoped` read (`within`/`filters`) returns a *subset*, so the `nth=` index —
115
- * and even a bare role/text selector — can resolve a different element when `act`
116
- * replays it with an unscoped `find`. In that case we emit no `target`: better the
117
- * agent falls back (visible text / `role "name"`) than act on the wrong node.
139
+ * A `scoped` read (`query`/`within`/`filters`) returns a *subset*, so the `nth=`
140
+ * index — and even a bare role/text selector — can resolve a different element when
141
+ * `act` replays it with an unscoped, document-wide `find` (e.g. header "Settings"
142
+ * instead of the sidebar "Settings" the narrowed read returned). In that case we
143
+ * emit no `target` — EXCEPT a `data-testid` one, which is document-unique and
144
+ * survives any scoping. Otherwise, better the agent falls back (visible text /
145
+ * `role "name"`) than act on the wrong node.
118
146
  */
119
147
  function withTargets(nodes, fields, scoped = false) {
120
148
  const seen = new Map();
149
+ const projection = fields && fields.length > 0 ? fields : DEFAULT_PROJECTION;
121
150
  return nodes.map((node) => {
122
- const projected = fields && fields.length > 0 ? pick(node, fields) : { ...node };
123
- if (scoped)
151
+ const projected = pick(node, projection);
152
+ if (scoped) {
153
+ if (node.testid)
154
+ projected.target = `data-testid=${JSON.stringify(node.testid)}`;
124
155
  return projected;
156
+ }
125
157
  const base = baseSelector(node);
126
158
  if (!base)
127
159
  return projected;
@@ -134,31 +166,57 @@ function withTargets(nodes, fields, scoped = false) {
134
166
  /** Pick a subset of keys off an object (a typed `SELECT cols`) for the `fields` projection. */
135
167
  function pick(obj, keys) {
136
168
  const out = {};
169
+ // Skip absent optionals (testid/style) so they never serialize as explicit nulls.
137
170
  for (const key of keys)
138
- out[key] = obj[key];
171
+ if (obj[key] !== undefined)
172
+ out[key] = obj[key];
139
173
  return out;
140
174
  }
175
+ /**
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.
181
+ */
182
+ export function coerceWithin(within) {
183
+ if (typeof within !== 'string' || !within.trimStart().startsWith('{'))
184
+ return within;
185
+ let data;
186
+ try {
187
+ data = JSON.parse(within);
188
+ }
189
+ catch {
190
+ 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');
191
+ }
192
+ const parsed = NodeSchema.safeParse(data);
193
+ 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');
195
+ }
196
+ return parsed.data;
197
+ }
141
198
  /**
142
199
  * Route one `observe` call to the adapter and shape the result. Pure over the
143
- * {@link Adapter} seam (no `tool()` wrapper), so it unit-tests against a fake.
200
+ * {@link Adapter} + {@link EvidenceRecorder} seams (no `tool()` wrapper), so it
201
+ * unit-tests against fakes.
144
202
  */
145
- export async function runObserve(adapter, input) {
203
+ export async function runObserve(adapter, recorder, input) {
146
204
  const { kind, query, fields, filters, limit, within } = input;
147
205
  switch (kind) {
148
206
  case 'tree': {
149
- const nodes = await adapter.readState({ query, filters, limit, within });
150
- const scoped = within !== undefined || filters !== undefined;
207
+ const scope = coerceWithin(within);
208
+ const nodes = await adapter.readState({ query, filters, limit, within: scope });
209
+ const scoped = query !== undefined || scope !== undefined || filters !== undefined;
151
210
  const projected = withTargets(nodes, fields, scoped);
152
211
  return { kind, count: projected.length, nodes: projected };
153
212
  }
154
213
  case 'screenshot': {
214
+ // Save the frame as evidence and return its path — never the base64 bytes:
215
+ // the driver is blind, and the SDK re-sends tool results on every later step,
216
+ // so an inlined PNG would permanently flood the text model's context.
155
217
  const png = await adapter.screenshot();
156
- return {
157
- kind,
158
- encoding: 'png',
159
- bytes: png.byteLength,
160
- data: Buffer.from(png).toString('base64'),
161
- };
218
+ const path = await recorder.saveScreenshot('observe', png);
219
+ return { kind, path, bytes: png.byteLength };
162
220
  }
163
221
  case 'console': {
164
222
  const entries = await adapter.console({ filters, limit });
@@ -174,12 +232,12 @@ export async function runObserve(adapter, input) {
174
232
  }
175
233
  }
176
234
  }
177
- /** Build the `observe` tool bound to one adapter, for the debug agent's belt. */
178
- export function createObserveTool(adapter) {
235
+ /** Build the `observe` tool bound to one adapter + recorder, for the debug agent's belt. */
236
+ export function createObserveTool(adapter, recorder) {
179
237
  return tool({
180
- description: 'Read the target without mutating it. Pick a channel with kind (tree=UI nodes, screenshot=PNG evidence, console=logs, network=requests); compose with query/fields/filters/limit/within. Use it to inspect state before and after acting.',
238
+ description: 'Read the target without mutating it. Pick a channel with kind (tree=UI nodes, screenshot=PNG evidence saved to screenshots/ — returns its path, console=logs, network=requests); compose with query/fields/filters/limit/within. Use it to inspect state before and after acting.',
181
239
  inputSchema: ObserveInputSchema,
182
- execute: (input) => runObserve(adapter, input),
240
+ execute: (input) => runObserve(adapter, recorder, input),
183
241
  });
184
242
  }
185
243
  //# sourceMappingURL=observe.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"observe.js","sourceRoot":"","sources":["../../../src/agent/belt/observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,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,C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;QACD,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;YAC1D,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;QAClD,CAAC;QACD,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;YAC1D,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;QAClD,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,WAAW,GAAU,IAAI,CAAC;YAChC,MAAM,IAAI,UAAU,CAAC,yBAAyB,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACvE,CAAC;IACH,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"}
@@ -35,6 +35,7 @@ export declare const ReportInputSchema: z.ZodObject<{
35
35
  steps: z.ZodDefault<z.ZodArray<z.ZodObject<{
36
36
  step: z.ZodString;
37
37
  ok: z.ZodBoolean;
38
+ skipped: z.ZodOptional<z.ZodBoolean>;
38
39
  note: z.ZodOptional<z.ZodString>;
39
40
  screenshot: z.ZodOptional<z.ZodString>;
40
41
  }, z.core.$strip>>>;
@@ -115,6 +116,7 @@ export declare function createReportTool(writer: FindingsWriter, getTrail?: () =
115
116
  steps: {
116
117
  step: string;
117
118
  ok: boolean;
119
+ skipped?: boolean | undefined;
118
120
  note?: string | undefined;
119
121
  screenshot?: string | undefined;
120
122
  }[];
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Model capability probe — can a model take image input?
3
+ *
4
+ * Decides whether `look` can hand the frame straight to the DRIVER (self-look:
5
+ * same model for control + vision) instead of a second blind vision call. The
6
+ * answer comes from the provider's `/models` catalog the way OpenRouter exposes
7
+ * it: `data[].architecture.input_modalities` (e.g. `["text","image"]`).
8
+ *
9
+ * Three-valued on purpose: `true` / `false` when the catalog answers, `null`
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).
15
+ */
16
+ /**
17
+ * The slice of `fetch` the probe needs — typed locally (the DOM lib is off
18
+ * project-wide), satisfied by the global `fetch` and by test fakes alike.
19
+ */
20
+ export type FetchLike = (url: string, init?: {
21
+ headers?: Record<string, string>;
22
+ }) => Promise<{
23
+ ok: boolean;
24
+ json(): Promise<unknown>;
25
+ }>;
26
+ /**
27
+ * Look the model up in the provider's `/models` catalog and report whether its
28
+ * input modalities include `image`. `null` = the catalog can't say.
29
+ */
30
+ export declare function supportsImageInput(baseUrl: string, apiKey: string, modelId: string, fetchImpl?: FetchLike): Promise<boolean | null>;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Model capability probe — can a model take image input?
3
+ *
4
+ * Decides whether `look` can hand the frame straight to the DRIVER (self-look:
5
+ * same model for control + vision) instead of a second blind vision call. The
6
+ * answer comes from the provider's `/models` catalog the way OpenRouter exposes
7
+ * it: `data[].architecture.input_modalities` (e.g. `["text","image"]`).
8
+ *
9
+ * Three-valued on purpose: `true` / `false` when the catalog answers, `null`
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).
15
+ */
16
+ /**
17
+ * Look the model up in the provider's `/models` catalog and report whether its
18
+ * input modalities include `image`. `null` = the catalog can't say.
19
+ */
20
+ export async function supportsImageInput(baseUrl, apiKey, modelId, fetchImpl = fetch) {
21
+ let res;
22
+ try {
23
+ res = await fetchImpl(`${baseUrl.replace(/\/$/, '')}/models`, {
24
+ headers: { Authorization: `Bearer ${apiKey}` },
25
+ });
26
+ }
27
+ catch {
28
+ return null; // catalog unreachable — not a run-blocking condition
29
+ }
30
+ if (!res.ok)
31
+ return null;
32
+ let body;
33
+ try {
34
+ body = await res.json();
35
+ }
36
+ catch {
37
+ return null;
38
+ }
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)
48
+ return modalities.includes('image');
49
+ }
50
+ //# sourceMappingURL=capabilities.js.map
@@ -0,0 +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,EAAE,CAAC,SAAS,EAAE;YAC5D,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,MAAM,EAAE,EAAE;SAC/C,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC,CAAC,qDAAqD;IACpE,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,IAAI,GAAI,IAA2B,CAAC,IAAI,CAAC;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,MAAM,KAAK,GAAI,IAAuB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,KAAK,OAAO,CAAC,CAAC;IACtE,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,MAAM,UAAU,GAAG,KAAK,CAAC,YAAY,EAAE,gBAAgB,CAAC;IACxD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC,CAAC,8CAA8C;IAC3F,OAAO,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC"}
@@ -6,8 +6,9 @@
6
6
  * or a safety step cap trips. Two things make it a *conversation*, not a job:
7
7
  *
8
8
  * - **inbox** — `prepareStep` drains the session inbox between steps and folds
9
- * any mid-run messages (the smart agent's `send_message`) into the next turn,
10
- * so the driver adapts without restarting.
9
+ * any mid-run messages (the smart agent's `send_message`) into a standing
10
+ * instruction block re-appended to EVERY turn (the SDK rebuilds each step's
11
+ * prompt from scratch), so the driver adapts without restarting or forgetting.
11
12
  * - **incremental findings** — `onStepFinish` lifts each step's `act` results
12
13
  * into a running step trail and flushes it as `status: 'running'` findings,
13
14
  * so `get_findings` shows live progress before the verdict lands.
@@ -56,13 +57,30 @@ export interface FinishedStep {
56
57
  }>;
57
58
  }
58
59
  /**
59
- * `prepareStep`: fold any mid-run messages into the next model turn. Drains the
60
- * inbox; when non-empty, appends one user message so the driver adapts before its
61
- * next action. Returns `{}` (no override) when the inbox is empty.
60
+ * `prepareStep`: fold mid-run messages into the next model turn. Drains the inbox
61
+ * into `standing` — the run-long list of caller instructions — then, while any
62
+ * exist, appends ONE user message rebuilt from the whole list.
63
+ *
64
+ * Rebuilt on EVERY step, not just the drain step: the SDK composes each step's
65
+ * prompt fresh from `[...initialMessages, ...responseMessages]` and never persists
66
+ * a `prepareStep` messages override, so an instruction injected once would reach
67
+ * the driver for exactly one step and then vanish. Because the base `messages`
68
+ * arrive without the previous step's injection, re-appending the single rebuilt
69
+ * block never accumulates duplicates. Returns `{}` when no instructions exist.
62
70
  */
63
- export declare function drainInboxIntoStep(inbox: LoopInbox, messages: ModelMessage[]): {
71
+ export declare function foldInstructionsIntoStep(inbox: LoopInbox, standing: string[], messages: ModelMessage[]): {
64
72
  messages: ModelMessage[];
65
73
  } | Record<string, never>;
74
+ /** What a pruned frame collapses to — tells the driver how to get a fresh one. */
75
+ export declare const STALE_FRAME_NOTE = "[stale frame removed \u2014 call look again for a fresh screenshot]";
76
+ /**
77
+ * Keep only the NEWEST self-look frame in the transcript. The SDK re-sends every
78
+ * tool result on every step, so each `look` image would otherwise ride along for
79
+ * the rest of the run — N looks × M steps of image tokens. Rebuilt per step in
80
+ * `prepareStep` (overrides never persist), like the instruction fold. Returns the
81
+ * SAME array when there is at most one frame, preserving the no-change fast path.
82
+ */
83
+ export declare function pruneStaleFrames(messages: ModelMessage[]): ModelMessage[];
66
84
  /** Steps left at or below which the driver is nudged to wrap up and `report`. */
67
85
  export declare const BUDGET_WARN = 6;
68
86
  /**