@developerz.ai/ui-debugger-mcp 1.0.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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +295 -0
  3. package/dist/adapters/android/adb.d.ts +38 -0
  4. package/dist/adapters/android/adb.js +72 -0
  5. package/dist/adapters/android/adb.js.map +1 -0
  6. package/dist/adapters/android/android-adapter.d.ts +63 -0
  7. package/dist/adapters/android/android-adapter.js +306 -0
  8. package/dist/adapters/android/android-adapter.js.map +1 -0
  9. package/dist/adapters/android/commands.d.ts +59 -0
  10. package/dist/adapters/android/commands.js +178 -0
  11. package/dist/adapters/android/commands.js.map +1 -0
  12. package/dist/adapters/android/uiautomator.d.ts +81 -0
  13. package/dist/adapters/android/uiautomator.js +296 -0
  14. package/dist/adapters/android/uiautomator.js.map +1 -0
  15. package/dist/adapters/browser/browser-adapter.d.ts +72 -0
  16. package/dist/adapters/browser/browser-adapter.js +434 -0
  17. package/dist/adapters/browser/browser-adapter.js.map +1 -0
  18. package/dist/adapters/browser/cdp.d.ts +83 -0
  19. package/dist/adapters/browser/cdp.js +308 -0
  20. package/dist/adapters/browser/cdp.js.map +1 -0
  21. package/dist/adapters/browser/query.d.ts +25 -0
  22. package/dist/adapters/browser/query.js +85 -0
  23. package/dist/adapters/browser/query.js.map +1 -0
  24. package/dist/adapters/contract.d.ts +159 -0
  25. package/dist/adapters/contract.js +22 -0
  26. package/dist/adapters/contract.js.map +1 -0
  27. package/dist/adapters/desktop/atspi.d.ts +95 -0
  28. package/dist/adapters/desktop/atspi.js +359 -0
  29. package/dist/adapters/desktop/atspi.js.map +1 -0
  30. package/dist/adapters/desktop/capture.d.ts +35 -0
  31. package/dist/adapters/desktop/capture.js +67 -0
  32. package/dist/adapters/desktop/capture.js.map +1 -0
  33. package/dist/adapters/desktop/desktop-adapter.d.ts +60 -0
  34. package/dist/adapters/desktop/desktop-adapter.js +215 -0
  35. package/dist/adapters/desktop/desktop-adapter.js.map +1 -0
  36. package/dist/adapters/desktop/input.d.ts +67 -0
  37. package/dist/adapters/desktop/input.js +191 -0
  38. package/dist/adapters/desktop/input.js.map +1 -0
  39. package/dist/adapters/desktop/proc.d.ts +23 -0
  40. package/dist/adapters/desktop/proc.js +38 -0
  41. package/dist/adapters/desktop/proc.js.map +1 -0
  42. package/dist/adapters/factory.d.ts +23 -0
  43. package/dist/adapters/factory.js +45 -0
  44. package/dist/adapters/factory.js.map +1 -0
  45. package/dist/agent/belt/act.d.ts +100 -0
  46. package/dist/agent/belt/act.js +166 -0
  47. package/dist/agent/belt/act.js.map +1 -0
  48. package/dist/agent/belt/look.d.ts +98 -0
  49. package/dist/agent/belt/look.js +160 -0
  50. package/dist/agent/belt/look.js.map +1 -0
  51. package/dist/agent/belt/observe.d.ts +102 -0
  52. package/dist/agent/belt/observe.js +185 -0
  53. package/dist/agent/belt/observe.js.map +1 -0
  54. package/dist/agent/belt/report.d.ts +133 -0
  55. package/dist/agent/belt/report.js +112 -0
  56. package/dist/agent/belt/report.js.map +1 -0
  57. package/dist/agent/loop.d.ts +136 -0
  58. package/dist/agent/loop.js +173 -0
  59. package/dist/agent/loop.js.map +1 -0
  60. package/dist/agent/models.d.ts +26 -0
  61. package/dist/agent/models.js +22 -0
  62. package/dist/agent/models.js.map +1 -0
  63. package/dist/agent/prompts/android-addendum.d.ts +12 -0
  64. package/dist/agent/prompts/android-addendum.js +76 -0
  65. package/dist/agent/prompts/android-addendum.js.map +1 -0
  66. package/dist/agent/prompts/compose.d.ts +30 -0
  67. package/dist/agent/prompts/compose.js +52 -0
  68. package/dist/agent/prompts/compose.js.map +1 -0
  69. package/dist/agent/prompts/debug-agent.d.ts +9 -0
  70. package/dist/agent/prompts/debug-agent.js +102 -0
  71. package/dist/agent/prompts/debug-agent.js.map +1 -0
  72. package/dist/agent/prompts/desktop-addendum.d.ts +10 -0
  73. package/dist/agent/prompts/desktop-addendum.js +66 -0
  74. package/dist/agent/prompts/desktop-addendum.js.map +1 -0
  75. package/dist/agent/prompts/web-addendum.d.ts +9 -0
  76. package/dist/agent/prompts/web-addendum.js +70 -0
  77. package/dist/agent/prompts/web-addendum.js.map +1 -0
  78. package/dist/agent/provider.d.ts +17 -0
  79. package/dist/agent/provider.js +29 -0
  80. package/dist/agent/provider.js.map +1 -0
  81. package/dist/cli/control.d.ts +19 -0
  82. package/dist/cli/control.js +152 -0
  83. package/dist/cli/control.js.map +1 -0
  84. package/dist/cli/help.d.ts +9 -0
  85. package/dist/cli/help.js +41 -0
  86. package/dist/cli/help.js.map +1 -0
  87. package/dist/cli/init.d.ts +20 -0
  88. package/dist/cli/init.js +119 -0
  89. package/dist/cli/init.js.map +1 -0
  90. package/dist/config/load.d.ts +64 -0
  91. package/dist/config/load.js +105 -0
  92. package/dist/config/load.js.map +1 -0
  93. package/dist/config/schema.d.ts +105 -0
  94. package/dist/config/schema.js +62 -0
  95. package/dist/config/schema.js.map +1 -0
  96. package/dist/errors.d.ts +41 -0
  97. package/dist/errors.js +90 -0
  98. package/dist/errors.js.map +1 -0
  99. package/dist/findings/schema.d.ts +64 -0
  100. package/dist/findings/schema.js +27 -0
  101. package/dist/findings/schema.js.map +1 -0
  102. package/dist/index.d.ts +2 -0
  103. package/dist/index.js +4 -0
  104. package/dist/index.js.map +1 -0
  105. package/dist/main.d.ts +2 -0
  106. package/dist/main.js +95 -0
  107. package/dist/main.js.map +1 -0
  108. package/dist/mcp/server.d.ts +25 -0
  109. package/dist/mcp/server.js +31 -0
  110. package/dist/mcp/server.js.map +1 -0
  111. package/dist/mcp/tools/describe.d.ts +12 -0
  112. package/dist/mcp/tools/describe.js +32 -0
  113. package/dist/mcp/tools/describe.js.map +1 -0
  114. package/dist/mcp/tools/end-session.d.ts +11 -0
  115. package/dist/mcp/tools/end-session.js +27 -0
  116. package/dist/mcp/tools/end-session.js.map +1 -0
  117. package/dist/mcp/tools/get-findings.d.ts +12 -0
  118. package/dist/mcp/tools/get-findings.js +42 -0
  119. package/dist/mcp/tools/get-findings.js.map +1 -0
  120. package/dist/mcp/tools/index.d.ts +17 -0
  121. package/dist/mcp/tools/index.js +24 -0
  122. package/dist/mcp/tools/index.js.map +1 -0
  123. package/dist/mcp/tools/result.d.ts +10 -0
  124. package/dist/mcp/tools/result.js +20 -0
  125. package/dist/mcp/tools/result.js.map +1 -0
  126. package/dist/mcp/tools/send-message.d.ts +11 -0
  127. package/dist/mcp/tools/send-message.js +31 -0
  128. package/dist/mcp/tools/send-message.js.map +1 -0
  129. package/dist/mcp/tools/start-debug.d.ts +12 -0
  130. package/dist/mcp/tools/start-debug.js +50 -0
  131. package/dist/mcp/tools/start-debug.js.map +1 -0
  132. package/dist/services/debug-service.d.ts +133 -0
  133. package/dist/services/debug-service.js +163 -0
  134. package/dist/services/debug-service.js.map +1 -0
  135. package/dist/services/replay.d.ts +102 -0
  136. package/dist/services/replay.js +184 -0
  137. package/dist/services/replay.js.map +1 -0
  138. package/dist/services/session-builder.d.ts +65 -0
  139. package/dist/services/session-builder.js +198 -0
  140. package/dist/services/session-builder.js.map +1 -0
  141. package/dist/services/summarize.d.ts +59 -0
  142. package/dist/services/summarize.js +93 -0
  143. package/dist/services/summarize.js.map +1 -0
  144. package/dist/session/findings-store.d.ts +52 -0
  145. package/dist/session/findings-store.js +176 -0
  146. package/dist/session/findings-store.js.map +1 -0
  147. package/dist/session/manager.d.ts +47 -0
  148. package/dist/session/manager.js +66 -0
  149. package/dist/session/manager.js.map +1 -0
  150. package/dist/session/process-identity.d.ts +45 -0
  151. package/dist/session/process-identity.js +81 -0
  152. package/dist/session/process-identity.js.map +1 -0
  153. package/dist/session/session.d.ts +156 -0
  154. package/dist/session/session.js +309 -0
  155. package/dist/session/session.js.map +1 -0
  156. package/dist/session/state-file.d.ts +72 -0
  157. package/dist/session/state-file.js +104 -0
  158. package/dist/session/state-file.js.map +1 -0
  159. package/dist/session/workspace.d.ts +60 -0
  160. package/dist/session/workspace.js +75 -0
  161. package/dist/session/workspace.js.map +1 -0
  162. package/package.json +53 -0
@@ -0,0 +1,100 @@
1
+ /**
2
+ * `act` — the driver's write tool (inner belt).
3
+ *
4
+ * One verb, six intents, picked by an `action` enum on a flat input object (a
5
+ * discriminated union renders as a JSON-Schema `anyOf` that some tool-calling
6
+ * models can't fill — see {@link ActInputSchema}). Each intent routes through the
7
+ * shared {@link Adapter} contract so the loop stays
8
+ * adapter-blind — the same `act({ action: 'click', target })` drives web (CDP),
9
+ * desktop (X11/Wayland) or android (ADB):
10
+ * - `click` → `find` + `click` (resolve the node, then click it)
11
+ * - `type` → `find` + `type` (resolve the field, then type into it)
12
+ * - `navigate` → `open` (go to a URL / window / activity)
13
+ * - `wait` → `waitFor` (block on a node / network idle / timeout)
14
+ * - `key` → `pressKey` (press a key / chord on the focused element)
15
+ * - `scroll` → `scroll` (wheel the viewport, or a `target`-scoped region)
16
+ *
17
+ * Click/type resolve their target through `find` FIRST (not the selector overload
18
+ * baked into `click`/`type`) for two reasons: fail loud with a clear "no element
19
+ * matched" when the node is missing, and derive the step **label from the target**
20
+ * (its role + accessible name) for the evidence trail.
21
+ *
22
+ * After the action it records one step: a line to `logs/agent.log` plus an ordered
23
+ * post-action frame to `screenshots/` (the replay video). Recording is not
24
+ * best-effort — a failed capture surfaces, never a silent fallback.
25
+ */
26
+ import { z } from 'zod';
27
+ import type { Adapter } from '../../adapters/contract.js';
28
+ import type { LogChannel } from '../../session/findings-store.js';
29
+ /** The six action verbs `act` routes to the shared contract. */
30
+ export declare const ACT_ACTIONS: readonly ["click", "type", "key", "scroll", "navigate", "wait"];
31
+ /**
32
+ * `act` input — ONE flat object the driver fills per call: `action` picks the
33
+ * verb, the rest are its (optional) operands, validated per-action in
34
+ * {@link performAct}.
35
+ *
36
+ * Flat on purpose. A `z.discriminatedUnion('action', …)` renders as a JSON-Schema
37
+ * `anyOf`, which several tool-calling models — including our default driver
38
+ * (glm) — fail to populate: they emit the call with empty `{}` args and the run
39
+ * churns without ever acting. A single flat object with an enum discriminant is
40
+ * filled reliably, at the cost of moving "click needs a target", "type needs
41
+ * text" out of the schema and into a loud runtime check.
42
+ */
43
+ export declare const ActInputSchema: z.ZodObject<{
44
+ action: z.ZodEnum<{
45
+ type: "type";
46
+ key: "key";
47
+ click: "click";
48
+ scroll: "scroll";
49
+ navigate: "navigate";
50
+ wait: "wait";
51
+ }>;
52
+ target: z.ZodOptional<z.ZodString>;
53
+ text: z.ZodOptional<z.ZodString>;
54
+ key: z.ZodOptional<z.ZodString>;
55
+ direction: z.ZodOptional<z.ZodEnum<{
56
+ up: "up";
57
+ down: "down";
58
+ left: "left";
59
+ right: "right";
60
+ }>>;
61
+ amount: z.ZodOptional<z.ZodNumber>;
62
+ networkIdle: z.ZodOptional<z.ZodBoolean>;
63
+ timeout: z.ZodOptional<z.ZodNumber>;
64
+ }, z.core.$strip>;
65
+ export type ActInput = z.infer<typeof ActInputSchema>;
66
+ /** Structured `act` result — confirms the intent and points at the evidence frame. */
67
+ export interface ActResult {
68
+ /** The action performed (mirrors the input discriminant). */
69
+ action: ActInput['action'];
70
+ /** Target-derived step label, e.g. `click button "Save"`. */
71
+ label: string;
72
+ /** Path to the post-action screenshot saved as evidence. */
73
+ screenshot: string;
74
+ }
75
+ /**
76
+ * The slice of the findings store `act` records through. {@link FindingsStore}
77
+ * satisfies it structurally, so the real store drops in; tests pass a fake.
78
+ */
79
+ export interface StepRecorder {
80
+ /** Append a line to `logs/<channel>.log`. */
81
+ appendLog(channel: LogChannel, line: string): Promise<string>;
82
+ /** Save a PNG frame as `screenshots/NNN-<label>.png`. */
83
+ saveScreenshot(label: string, data: Uint8Array): Promise<string>;
84
+ }
85
+ /**
86
+ * Route one `act` call through the {@link Adapter}, then record the step. Pure
87
+ * over the contract + {@link StepRecorder} seams, so it unit-tests against fakes.
88
+ */
89
+ export declare function runAct(adapter: Adapter, recorder: StepRecorder, input: ActInput): Promise<ActResult>;
90
+ /** Build the `act` tool bound to one adapter + recorder, for the debug agent's belt. */
91
+ export declare function createActTool(adapter: Adapter, recorder: StepRecorder): import("ai").Tool<{
92
+ action: "type" | "key" | "click" | "scroll" | "navigate" | "wait";
93
+ target?: string | undefined;
94
+ text?: string | undefined;
95
+ key?: string | undefined;
96
+ direction?: "up" | "down" | "left" | "right" | undefined;
97
+ amount?: number | undefined;
98
+ networkIdle?: boolean | undefined;
99
+ timeout?: number | undefined;
100
+ }, ActResult>;
@@ -0,0 +1,166 @@
1
+ /**
2
+ * `act` — the driver's write tool (inner belt).
3
+ *
4
+ * One verb, six intents, picked by an `action` enum on a flat input object (a
5
+ * discriminated union renders as a JSON-Schema `anyOf` that some tool-calling
6
+ * models can't fill — see {@link ActInputSchema}). Each intent routes through the
7
+ * shared {@link Adapter} contract so the loop stays
8
+ * adapter-blind — the same `act({ action: 'click', target })` drives web (CDP),
9
+ * desktop (X11/Wayland) or android (ADB):
10
+ * - `click` → `find` + `click` (resolve the node, then click it)
11
+ * - `type` → `find` + `type` (resolve the field, then type into it)
12
+ * - `navigate` → `open` (go to a URL / window / activity)
13
+ * - `wait` → `waitFor` (block on a node / network idle / timeout)
14
+ * - `key` → `pressKey` (press a key / chord on the focused element)
15
+ * - `scroll` → `scroll` (wheel the viewport, or a `target`-scoped region)
16
+ *
17
+ * Click/type resolve their target through `find` FIRST (not the selector overload
18
+ * baked into `click`/`type`) for two reasons: fail loud with a clear "no element
19
+ * matched" when the node is missing, and derive the step **label from the target**
20
+ * (its role + accessible name) for the evidence trail.
21
+ *
22
+ * After the action it records one step: a line to `logs/agent.log` plus an ordered
23
+ * post-action frame to `screenshots/` (the replay video). Recording is not
24
+ * best-effort — a failed capture surfaces, never a silent fallback.
25
+ */
26
+ import { tool } from 'ai';
27
+ import { z } from 'zod';
28
+ import { AgentError } from '../../errors.js';
29
+ /** The six action verbs `act` routes to the shared contract. */
30
+ export const ACT_ACTIONS = ['click', 'type', 'key', 'scroll', 'navigate', 'wait'];
31
+ /**
32
+ * `act` input — ONE flat object the driver fills per call: `action` picks the
33
+ * verb, the rest are its (optional) operands, validated per-action in
34
+ * {@link performAct}.
35
+ *
36
+ * Flat on purpose. A `z.discriminatedUnion('action', …)` renders as a JSON-Schema
37
+ * `anyOf`, which several tool-calling models — including our default driver
38
+ * (glm) — fail to populate: they emit the call with empty `{}` args and the run
39
+ * churns without ever acting. A single flat object with an enum discriminant is
40
+ * filled reliably, at the cost of moving "click needs a target", "type needs
41
+ * text" out of the schema and into a loud runtime check.
42
+ */
43
+ export const ActInputSchema = z.object({
44
+ action: z.enum(ACT_ACTIONS).describe('what to do: click | type | key | scroll | navigate | wait'),
45
+ target: z
46
+ .string()
47
+ .optional()
48
+ .describe('what to act on — CSS, role+name (button "Save"), or visible text (web); navigate: URL/window/activity; wait: selector to await; scroll: region to scroll within (optional)'),
49
+ text: z.string().optional().describe('text to type (action=type)'),
50
+ key: z
51
+ .string()
52
+ .optional()
53
+ .describe('key or chord to press (action=key), e.g. Enter | Tab | Escape | Control+A'),
54
+ direction: z
55
+ .enum(['up', 'down', 'left', 'right'])
56
+ .optional()
57
+ .describe('scroll direction (action=scroll)'),
58
+ amount: z.number().int().positive().optional().describe('pixels to scroll (action=scroll)'),
59
+ networkIdle: z
60
+ .boolean()
61
+ .optional()
62
+ .describe('wait until in-flight requests settle (action=wait, web)'),
63
+ timeout: z
64
+ .number()
65
+ .int()
66
+ .positive()
67
+ .optional()
68
+ .describe('hard cap in ms; throws on expiry (action=wait)'),
69
+ });
70
+ /** Resolve a selector to a node via `find`, failing loud when nothing matches. */
71
+ async function resolve(adapter, target) {
72
+ const node = await adapter.find({ query: target });
73
+ if (!node)
74
+ throw new AgentError(`act: no element matched ${JSON.stringify(target)}`);
75
+ return node;
76
+ }
77
+ /** Target-derived label for a resolved node — `role "name"`, or just `role` when unnamed. */
78
+ function describeNode(node) {
79
+ const name = node.name.trim();
80
+ return name ? `${node.role} ${JSON.stringify(name)}` : node.role;
81
+ }
82
+ /** Describe what a `wait` is blocking on, for the step label. */
83
+ function describeWait(query, networkIdle, timeout) {
84
+ const parts = [
85
+ query ? JSON.stringify(query) : undefined,
86
+ networkIdle ? 'network idle' : undefined,
87
+ timeout ? `${timeout}ms` : undefined,
88
+ ].filter((part) => part !== undefined);
89
+ return parts.length > 0 ? parts.join(' + ') : 'next frame';
90
+ }
91
+ /**
92
+ * Require an operand the flat schema can't enforce per-action; fail loud when
93
+ * omitted. Generic over `T extends string` so it preserves narrow unions (e.g.
94
+ * `scroll`'s `direction` enum) instead of widening them back to `string`.
95
+ */
96
+ function required(value, field, action) {
97
+ if (value === undefined || value === '') {
98
+ throw new AgentError(`act '${action}' requires '${field}'`);
99
+ }
100
+ return value;
101
+ }
102
+ /** Perform one action against the contract and return its target-derived step label. */
103
+ async function performAct(adapter, input) {
104
+ switch (input.action) {
105
+ case 'click': {
106
+ const node = await resolve(adapter, required(input.target, 'target', 'click'));
107
+ await adapter.click(node);
108
+ return `click ${describeNode(node)}`;
109
+ }
110
+ case 'type': {
111
+ // Validate `text` before resolving the target: a stale selector must not mask
112
+ // the real `requires 'text'` failure, nor cost an unnecessary `find()`.
113
+ const text = required(input.text, 'text', 'type');
114
+ const node = await resolve(adapter, required(input.target, 'target', 'type'));
115
+ await adapter.type(node, text);
116
+ return `type ${text.length} chars into ${describeNode(node)}`;
117
+ }
118
+ case 'navigate': {
119
+ const target = required(input.target, 'target', 'navigate');
120
+ await adapter.open(target);
121
+ return `navigate to ${target}`;
122
+ }
123
+ case 'wait': {
124
+ await adapter.waitFor({
125
+ query: input.target,
126
+ networkIdle: input.networkIdle,
127
+ timeout: input.timeout,
128
+ });
129
+ return `wait for ${describeWait(input.target, input.networkIdle, input.timeout)}`;
130
+ }
131
+ case 'key': {
132
+ const key = required(input.key, 'key', 'key');
133
+ await adapter.pressKey(key);
134
+ return `key ${key}`;
135
+ }
136
+ case 'scroll': {
137
+ const direction = required(input.direction, 'direction', 'scroll');
138
+ await adapter.scroll({ direction, amount: input.amount, within: input.target });
139
+ return `scroll ${direction}${input.amount !== undefined ? ` ${input.amount}px` : ''}`;
140
+ }
141
+ default: {
142
+ const unreachable = input.action;
143
+ throw new AgentError(`unknown act action: ${JSON.stringify(unreachable)}`);
144
+ }
145
+ }
146
+ }
147
+ /**
148
+ * Route one `act` call through the {@link Adapter}, then record the step. Pure
149
+ * over the contract + {@link StepRecorder} seams, so it unit-tests against fakes.
150
+ */
151
+ export async function runAct(adapter, recorder, input) {
152
+ const label = await performAct(adapter, input);
153
+ const png = await adapter.screenshot();
154
+ const screenshot = await recorder.saveScreenshot(label, png);
155
+ await recorder.appendLog('agent', `act ${label} → ${screenshot}`);
156
+ return { action: input.action, label, screenshot };
157
+ }
158
+ /** Build the `act` tool bound to one adapter + recorder, for the debug agent's belt. */
159
+ export function createActTool(adapter, recorder) {
160
+ return tool({
161
+ description: 'Drive the target with one action, chosen by action: click | type | key | scroll | navigate | wait. Resolves target via find, then routes to the adapter (click/type/open/waitFor) and records a step to agent.log plus a post-action screenshot. Use observe to read state before and after.',
162
+ inputSchema: ActInputSchema,
163
+ execute: (input) => runAct(adapter, recorder, input),
164
+ });
165
+ }
166
+ //# sourceMappingURL=act.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"act.js","sourceRoot":"","sources":["../../../src/agent/belt/act.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,gEAAgE;AAChE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAU,CAAC;AAE3F;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,C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,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;AACrD,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,aAAa,CAAC,OAAgB,EAAE,QAAsB;IACpE,OAAO,IAAI,CAAC;QACV,WAAW,EACT,8RAA8R;QAChS,WAAW,EAAE,cAAc;QAC3B,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC;KACrD,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * `look` — the driver's eyes (inner belt; the vision seam).
3
+ *
4
+ * The driver is a fast, **blind** text model: it acts on structure, never pixels.
5
+ * When it needs visual judgment ("is the button centred?", "does this match the
6
+ * design?") it calls `look`, which:
7
+ * 1. captures the current frame via the shared {@link Adapter} (`screenshot`),
8
+ * 2. sends that frame + the driver's question/expectation to the **vision guy**
9
+ * (the multimodal model bound to the `vision` role — see `idea/models.md`),
10
+ * 3. returns the vision guy's structured judgment `{ description, matches?,
11
+ * issues[] }`, with the screenshot saved and its path attached as evidence.
12
+ *
13
+ * Adapter-blind like the rest of the belt — it only reaches the contract's
14
+ * `screenshot`. The model call is hidden behind a small {@link VisionGenerate}
15
+ * seam so {@link runLook} unit-tests against a fake (no network); `createLookTool`
16
+ * wires the real `generateText({ model: vision, … })`.
17
+ *
18
+ * Fails loud: a vision reply that is not JSON, or that breaks the schema, throws
19
+ * an {@link AgentError} — we never silently fall back to half-parsed prose.
20
+ */
21
+ import type { LanguageModel, ModelMessage } from 'ai';
22
+ import { z } from 'zod';
23
+ import type { Adapter } from '../../adapters/contract.js';
24
+ /** `look` input — both optional: ask a `question`, and/or state the `expect`ed look. */
25
+ export declare const LookInputSchema: z.ZodObject<{
26
+ question: z.ZodOptional<z.ZodString>;
27
+ expect: z.ZodOptional<z.ZodString>;
28
+ }, z.core.$strip>;
29
+ export type LookInput = z.infer<typeof LookInputSchema>;
30
+ /** One visual issue the vision guy flags: what, where, and how bad. */
31
+ declare const LookIssueSchema: z.ZodObject<{
32
+ what: z.ZodString;
33
+ where: z.ZodString;
34
+ severity: z.ZodEnum<{
35
+ low: "low";
36
+ medium: "medium";
37
+ high: "high";
38
+ }>;
39
+ }, z.core.$strip>;
40
+ export type LookIssue = z.infer<typeof LookIssueSchema>;
41
+ /** The vision guy's reply, parsed from its JSON output (before evidence is attached). */
42
+ declare const VisionReplySchema: z.ZodObject<{
43
+ description: z.ZodString;
44
+ matches: z.ZodOptional<z.ZodBoolean>;
45
+ issues: z.ZodDefault<z.ZodArray<z.ZodObject<{
46
+ what: z.ZodString;
47
+ where: z.ZodString;
48
+ severity: z.ZodEnum<{
49
+ low: "low";
50
+ medium: "medium";
51
+ high: "high";
52
+ }>;
53
+ }, z.core.$strip>>>;
54
+ }, z.core.$strip>;
55
+ type VisionReply = z.infer<typeof VisionReplySchema>;
56
+ /** Structured `look` result — the vision judgment plus the saved evidence frame. */
57
+ export type LookResult = VisionReply & {
58
+ /** Path to the screenshot saved as evidence for the visual finding. */
59
+ screenshot: string;
60
+ };
61
+ /** What `look` asks the vision model: our system prompt + the user frame/question. */
62
+ export interface VisionRequest {
63
+ system: string;
64
+ messages: ModelMessage[];
65
+ }
66
+ /**
67
+ * The model seam `look` calls through. `createLookTool` binds it to the real
68
+ * `generateText({ model: vision, … })`; tests pass a fake returning canned text.
69
+ */
70
+ export type VisionGenerate = (req: VisionRequest) => Promise<{
71
+ text: string;
72
+ }>;
73
+ /**
74
+ * The slice of the findings store `look` records evidence through.
75
+ * {@link FindingsStore} satisfies it structurally; tests pass a fake.
76
+ */
77
+ export interface EvidenceRecorder {
78
+ /** Save a PNG frame as `screenshots/NNN-<label>.png`; returns its path. */
79
+ saveScreenshot(label: string, data: Uint8Array): Promise<string>;
80
+ }
81
+ /**
82
+ * Our system prompt for the vision guy — provider-agnostic, owned in-repo.
83
+ * Pins the reply to the exact JSON `look` parses, so any competent multimodal
84
+ * model behaves the same (never relies on a 3rd-party default).
85
+ */
86
+ export declare const VISION_SYSTEM_PROMPT = "You are the vision guy \u2014 the eyes of a blind UI-testing driver.\nYou are given a screenshot of the target UI plus a question and/or an expected look.\nDescribe what you see and judge how it looks: layout, alignment, spacing, colour,\noverlap, cut-off or unreadable text \u2014 anything that looks broken or off.\n\nReply with ONLY a JSON object (no prose, no markdown fences) of this exact shape:\n\n{\n \"description\": \"what you see, answering the question if one was asked\",\n \"matches\": true, // include ONLY when an expected look was given: does it match it?\n \"issues\": [ // visual problems found; [] when there are none\n { \"what\": \"the problem\", \"where\": \"where on screen\", \"severity\": \"low\" | \"medium\" | \"high\" }\n ]\n}\n\nSeverity: high = broken layout / overlap / invisible interactive element;\nmedium = misalignment / bad spacing / contrast issue; low = minor polish.\nBe concrete about \"where\" (e.g. \"top-right header\", \"primary submit button\").\nOutput the JSON object and nothing else.";
87
+ /**
88
+ * Capture the frame, ask the vision guy, attach the evidence. Pure over the
89
+ * {@link Adapter}, {@link VisionGenerate} and {@link EvidenceRecorder} seams, so
90
+ * it unit-tests against fakes with no network.
91
+ */
92
+ export declare function runLook(adapter: Adapter, generate: VisionGenerate, recorder: EvidenceRecorder, input: LookInput): Promise<LookResult>;
93
+ /** Build the `look` tool bound to one adapter + vision model + recorder, for the belt. */
94
+ export declare function createLookTool(adapter: Adapter, vision: LanguageModel, recorder: EvidenceRecorder): import("ai").Tool<{
95
+ question?: string | undefined;
96
+ expect?: string | undefined;
97
+ }, LookResult>;
98
+ export {};
@@ -0,0 +1,160 @@
1
+ /**
2
+ * `look` — the driver's eyes (inner belt; the vision seam).
3
+ *
4
+ * The driver is a fast, **blind** text model: it acts on structure, never pixels.
5
+ * When it needs visual judgment ("is the button centred?", "does this match the
6
+ * design?") it calls `look`, which:
7
+ * 1. captures the current frame via the shared {@link Adapter} (`screenshot`),
8
+ * 2. sends that frame + the driver's question/expectation to the **vision guy**
9
+ * (the multimodal model bound to the `vision` role — see `idea/models.md`),
10
+ * 3. returns the vision guy's structured judgment `{ description, matches?,
11
+ * issues[] }`, with the screenshot saved and its path attached as evidence.
12
+ *
13
+ * Adapter-blind like the rest of the belt — it only reaches the contract's
14
+ * `screenshot`. The model call is hidden behind a small {@link VisionGenerate}
15
+ * seam so {@link runLook} unit-tests against a fake (no network); `createLookTool`
16
+ * wires the real `generateText({ model: vision, … })`.
17
+ *
18
+ * Fails loud: a vision reply that is not JSON, or that breaks the schema, throws
19
+ * an {@link AgentError} — we never silently fall back to half-parsed prose.
20
+ */
21
+ import { generateText, tool } from 'ai';
22
+ import { z } from 'zod';
23
+ import { AgentError } from '../../errors.js';
24
+ /** `look` input — both optional: ask a `question`, and/or state the `expect`ed look. */
25
+ export const LookInputSchema = z.object({
26
+ question: z
27
+ .string()
28
+ .optional()
29
+ .describe('what to judge, e.g. "is the Checkout button centred?" | "where is the error?"'),
30
+ expect: z
31
+ .string()
32
+ .optional()
33
+ .describe('the intended look to compare against, e.g. "a centred blue primary button"'),
34
+ });
35
+ /** Severity of a visual issue — mirrors the findings `VisualIssue` scale. */
36
+ const SEVERITIES = ['low', 'medium', 'high'];
37
+ /** One visual issue the vision guy flags: what, where, and how bad. */
38
+ const LookIssueSchema = z.object({
39
+ what: z.string().describe('the visual problem, e.g. "text is cut off"'),
40
+ where: z.string().describe('where on screen, e.g. "top-right card header"'),
41
+ severity: z.enum(SEVERITIES).describe('low (polish) | medium (off) | high (broken)'),
42
+ });
43
+ /** The vision guy's reply, parsed from its JSON output (before evidence is attached). */
44
+ const VisionReplySchema = z.object({
45
+ description: z.string().describe('what the vision guy sees / its answer'),
46
+ matches: z.boolean().optional().describe('did it match `expect`? present only when expected'),
47
+ issues: z.array(LookIssueSchema).default([]).describe('visual problems; [] when none'),
48
+ });
49
+ /**
50
+ * Our system prompt for the vision guy — provider-agnostic, owned in-repo.
51
+ * Pins the reply to the exact JSON `look` parses, so any competent multimodal
52
+ * model behaves the same (never relies on a 3rd-party default).
53
+ */
54
+ export const VISION_SYSTEM_PROMPT = `\
55
+ You are the vision guy — the eyes of a blind UI-testing driver.
56
+ You are given a screenshot of the target UI plus a question and/or an expected look.
57
+ Describe what you see and judge how it looks: layout, alignment, spacing, colour,
58
+ overlap, cut-off or unreadable text — anything that looks broken or off.
59
+
60
+ Reply with ONLY a JSON object (no prose, no markdown fences) of this exact shape:
61
+
62
+ {
63
+ "description": "what you see, answering the question if one was asked",
64
+ "matches": true, // include ONLY when an expected look was given: does it match it?
65
+ "issues": [ // visual problems found; [] when there are none
66
+ { "what": "the problem", "where": "where on screen", "severity": "low" | "medium" | "high" }
67
+ ]
68
+ }
69
+
70
+ Severity: high = broken layout / overlap / invisible interactive element;
71
+ medium = misalignment / bad spacing / contrast issue; low = minor polish.
72
+ Be concrete about "where" (e.g. "top-right header", "primary submit button").
73
+ Output the JSON object and nothing else.`;
74
+ /** Compose the driver's question + expectation into the vision guy's user prompt. */
75
+ function buildPrompt({ question, expect }) {
76
+ const parts = [];
77
+ if (question)
78
+ parts.push(`Question: ${question}`);
79
+ if (expect)
80
+ parts.push(`Expected look: ${expect}`);
81
+ if (parts.length === 0)
82
+ parts.push('Describe what you see and flag any visual issues.');
83
+ return parts.join('\n');
84
+ }
85
+ /** Short label for the evidence frame's filename — the question, then the expectation. */
86
+ function lookLabel({ question, expect }) {
87
+ return question ?? expect ?? 'look';
88
+ }
89
+ /** Trim a model reply for an error message so we never dump a wall of text. */
90
+ function truncate(text, max = 200) {
91
+ const trimmed = text.trim();
92
+ return trimmed.length > max ? `${trimmed.slice(0, max)}…` : trimmed;
93
+ }
94
+ /** Pull the JSON object out of a reply — tolerant of ```json fences and stray prose. */
95
+ function extractJson(text) {
96
+ const fenced = /```(?:json)?\s*([\s\S]*?)\s*```/i.exec(text);
97
+ const body = fenced?.[1] ?? text;
98
+ const start = body.indexOf('{');
99
+ const end = body.lastIndexOf('}');
100
+ if (start === -1 || end === -1 || end < start) {
101
+ throw new AgentError(`look: no JSON object in vision reply: ${truncate(text)}`);
102
+ }
103
+ return body.slice(start, end + 1);
104
+ }
105
+ /** Parse + validate the vision guy's reply; fail loud on non-JSON or a bad shape. */
106
+ function parseVisionReply(text) {
107
+ let data;
108
+ try {
109
+ data = JSON.parse(extractJson(text));
110
+ }
111
+ catch (e) {
112
+ if (e instanceof AgentError)
113
+ throw e;
114
+ throw new AgentError(`look: vision reply was not valid JSON: ${e instanceof Error ? e.message : String(e)}`);
115
+ }
116
+ const result = VisionReplySchema.safeParse(data);
117
+ if (!result.success) {
118
+ const issues = result.error.issues
119
+ .map((i) => `${i.path.map(String).join('.') || '(root)'}: ${i.message}`)
120
+ .join('; ');
121
+ throw new AgentError(`look: vision reply failed validation: ${issues}`);
122
+ }
123
+ return result.data;
124
+ }
125
+ /**
126
+ * Capture the frame, ask the vision guy, attach the evidence. Pure over the
127
+ * {@link Adapter}, {@link VisionGenerate} and {@link EvidenceRecorder} seams, so
128
+ * it unit-tests against fakes with no network.
129
+ */
130
+ export async function runLook(adapter, generate, recorder, input) {
131
+ const png = await adapter.screenshot();
132
+ const { text } = await generate({
133
+ system: VISION_SYSTEM_PROMPT,
134
+ messages: [
135
+ {
136
+ role: 'user',
137
+ content: [
138
+ { type: 'text', text: buildPrompt(input) },
139
+ { type: 'image', image: png, mediaType: 'image/png' },
140
+ ],
141
+ },
142
+ ],
143
+ });
144
+ const reply = parseVisionReply(text);
145
+ const screenshot = await recorder.saveScreenshot(lookLabel(input), png);
146
+ return { ...reply, screenshot };
147
+ }
148
+ /** Build the `look` tool bound to one adapter + vision model + recorder, for the belt. */
149
+ export function createLookTool(adapter, vision, recorder) {
150
+ const generate = async ({ system, messages }) => {
151
+ const { text } = await generateText({ model: vision, system, messages });
152
+ return { text };
153
+ };
154
+ return tool({
155
+ 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
+ inputSchema: LookInputSchema,
157
+ execute: (input) => runLook(adapter, generate, recorder, input),
158
+ });
159
+ }
160
+ //# sourceMappingURL=look.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"look.js","sourceRoot":"","sources":["../../../src/agent/belt/look.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,wFAAwF;AACxF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,QAAQ,EAAE,CAAC;SACR,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CAAC,+EAA+E,CAAC;IAC5F,MAAM,EAAE,CAAC;SACN,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CAAC,4EAA4E,CAAC;CAC1F,CAAC,CAAC;AAIH,6EAA6E;AAC7E,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAC;AAEtD,uEAAuE;AACvE,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;IACvE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+CAA+C,CAAC;IAC3E,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,6CAA6C,CAAC;CACrF,CAAC,CAAC;AAIH,yFAAyF;AACzF,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,uCAAuC,CAAC;IACzE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,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AI,EAAE,CAAC;IAClB,CAAC,CAAC;IACF,OAAO,IAAI,CAAC;QACV,WAAW,EACT,0XAA0X;QAC5X,WAAW,EAAE,eAAe;QAC5B,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC;KAChE,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * `observe` — the driver's read tool (inner belt).
3
+ *
4
+ * One SQL-like reader, four "tables" picked by `kind`, each routed to one method
5
+ * on the shared {@link Adapter} contract:
6
+ * - `tree` → `readState` (normalized UI nodes; DOM · a11y · view-hierarchy)
7
+ * - `screenshot` → `screenshot` (PNG bytes, base64 — an evidence frame)
8
+ * - `console` → `console` (captured console/error log, newest first)
9
+ * - `network` → `network` (captured network exchanges, newest first)
10
+ *
11
+ * Adapter-blind: routes through the contract only — it never learns the protocol
12
+ * underneath. Composition lives in params (`query`/`fields`/`filters`/`limit`/
13
+ * `within`), like a `SELECT` — see `idea/mcp-tools.md`.
14
+ *
15
+ * Whitelisting is split, and neither side is an injection surface:
16
+ * - **fields** (the `SELECT` projection) are whitelisted HERE to the contract's
17
+ * {@link NodeField}s via the Zod enum, then projected after the read.
18
+ * - **filters** (`WHERE field_op`) pass through and are whitelisted by the
19
+ * ADAPTER, which throws on an unknown key (per-adapter key sets differ).
20
+ *
21
+ * Fails loud: a bad filter/limit surfaces the adapter's `AdapterError`; we never
22
+ * swallow it or silently fall back.
23
+ */
24
+ import { z } from 'zod';
25
+ import type { Adapter, ConsoleEntry, NetworkEntry, Node } from '../../adapters/contract.js';
26
+ /** `observe` input — flat + SQL-like; `kind` picks the table, the rest compose the read. */
27
+ export declare const ObserveInputSchema: z.ZodObject<{
28
+ kind: z.ZodEnum<{
29
+ screenshot: "screenshot";
30
+ console: "console";
31
+ network: "network";
32
+ tree: "tree";
33
+ }>;
34
+ query: z.ZodOptional<z.ZodString>;
35
+ fields: z.ZodOptional<z.ZodArray<z.ZodEnum<{
36
+ name: "name";
37
+ role: "role";
38
+ bounds: "bounds";
39
+ enabled: "enabled";
40
+ }>>>;
41
+ filters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
42
+ limit: z.ZodOptional<z.ZodNumber>;
43
+ within: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
44
+ role: z.ZodString;
45
+ name: z.ZodString;
46
+ bounds: z.ZodObject<{
47
+ x: z.ZodNumber;
48
+ y: z.ZodNumber;
49
+ width: z.ZodNumber;
50
+ height: z.ZodNumber;
51
+ }, z.core.$strip>;
52
+ enabled: z.ZodBoolean;
53
+ }, z.core.$strip>]>>;
54
+ }, z.core.$strip>;
55
+ export type ObserveInput = z.infer<typeof ObserveInputSchema>;
56
+ /** A tree node projected for the agent, plus a ready-to-use `target` selector for `act`. */
57
+ export type TreeNode = Partial<Node> & {
58
+ target?: string;
59
+ };
60
+ /** Structured `observe` result, discriminated on `kind` (mirrors the input channel). */
61
+ export type ObserveResult = {
62
+ kind: 'tree';
63
+ count: number;
64
+ nodes: TreeNode[];
65
+ } | {
66
+ kind: 'screenshot';
67
+ encoding: 'png';
68
+ bytes: number;
69
+ data: string;
70
+ } | {
71
+ kind: 'console';
72
+ count: number;
73
+ entries: ConsoleEntry[];
74
+ } | {
75
+ kind: 'network';
76
+ count: number;
77
+ entries: NetworkEntry[];
78
+ };
79
+ /**
80
+ * 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.
82
+ */
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<{
86
+ kind: "screenshot" | "console" | "network" | "tree";
87
+ query?: string | undefined;
88
+ fields?: ("name" | "role" | "bounds" | "enabled")[] | undefined;
89
+ filters?: Record<string, string | number | boolean | string[]> | undefined;
90
+ limit?: number | undefined;
91
+ within?: string | {
92
+ role: string;
93
+ name: string;
94
+ bounds: {
95
+ x: number;
96
+ y: number;
97
+ width: number;
98
+ height: number;
99
+ };
100
+ enabled: boolean;
101
+ } | undefined;
102
+ }, ObserveResult>;