@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,185 @@
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 { tool } from 'ai';
25
+ import { z } from 'zod';
26
+ import { AgentError } from '../../errors.js';
27
+ /** The four observable channels `kind` selects (each routes to one contract method). */
28
+ const OBSERVE_KINDS = ['tree', 'screenshot', 'console', 'network'];
29
+ /** Selectable {@link Node} columns — the `fields` projection whitelist (contract-level). */
30
+ const NODE_FIELDS = ['role', 'name', 'bounds', 'enabled'];
31
+ /** One `filters` predicate value; arrays back `_in`-style set membership (matches `FilterValue`). */
32
+ const FilterValueSchema = z.union([z.string(), z.number(), z.boolean(), z.array(z.string())]);
33
+ /** On-screen rectangle backing a {@link Node} `within` reference. */
34
+ const BoundsSchema = z.object({
35
+ x: z.number(),
36
+ y: z.number(),
37
+ width: z.number(),
38
+ height: z.number(),
39
+ });
40
+ /** A {@link Node} echoed back as a `within` scope (the alternative to a selector string). */
41
+ const NodeSchema = z.object({
42
+ role: z.string(),
43
+ name: z.string(),
44
+ bounds: BoundsSchema,
45
+ enabled: z.boolean(),
46
+ });
47
+ /** `observe` input — flat + SQL-like; `kind` picks the table, the rest compose the read. */
48
+ export const ObserveInputSchema = z.object({
49
+ kind: z.enum(OBSERVE_KINDS).describe('channel to read: tree | screenshot | console | network'),
50
+ query: z
51
+ .string()
52
+ .optional()
53
+ .describe('tree selector: CSS/role/text (web), a11y role+name (desktop), id/text (android)'),
54
+ fields: z
55
+ .array(z.enum(NODE_FIELDS))
56
+ .optional()
57
+ .describe('tree projection: return only these node columns (omit for all)'),
58
+ filters: z
59
+ .record(z.string(), FilterValueSchema)
60
+ .optional()
61
+ .describe('WHERE-style predicates, e.g. { visible_eq: true } | { status_gte: 400 }; per-channel'),
62
+ limit: z.number().int().nonnegative().optional().describe('cap how many rows return'),
63
+ within: z
64
+ .union([z.string(), NodeSchema])
65
+ .optional()
66
+ .describe('tree scope: restrict to a subtree/region (a selector or a node)'),
67
+ });
68
+ /** ARIA roles Playwright's `role=` engine accepts (others fall back to a text selector). */
69
+ const ARIA_ROLES = new Set([
70
+ 'button',
71
+ 'link',
72
+ 'checkbox',
73
+ 'radio',
74
+ 'textbox',
75
+ 'combobox',
76
+ 'slider',
77
+ 'heading',
78
+ 'img',
79
+ 'navigation',
80
+ 'main',
81
+ 'form',
82
+ 'list',
83
+ 'listitem',
84
+ 'tab',
85
+ 'menuitem',
86
+ 'switch',
87
+ 'dialog',
88
+ 'banner',
89
+ 'contentinfo',
90
+ 'region',
91
+ 'article',
92
+ 'search',
93
+ 'table',
94
+ ]);
95
+ /**
96
+ * The base selector for a node the agent can paste straight into `act`'s `target`.
97
+ * Role + accessible name when the role is ARIA-addressable, else the visible text.
98
+ * `null` for an unnamed, non-semantic node (the agent targets those by other means).
99
+ */
100
+ function baseSelector(node) {
101
+ const name = node.name.trim();
102
+ if (node.role && ARIA_ROLES.has(node.role) && name) {
103
+ return `role=${node.role}[name=${JSON.stringify(name)} i]`;
104
+ }
105
+ if (name)
106
+ return `text=${name}`;
107
+ return null;
108
+ }
109
+ /**
110
+ * Attach a copy-paste `target` to each tree node, disambiguating duplicates with
111
+ * `>> nth=` in document order — so the agent never has to invent a selector (the
112
+ * #1 cause of wasted steps: a blind model guessing CSS that does not resolve).
113
+ *
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.
118
+ */
119
+ function withTargets(nodes, fields, scoped = false) {
120
+ const seen = new Map();
121
+ return nodes.map((node) => {
122
+ const projected = fields && fields.length > 0 ? pick(node, fields) : { ...node };
123
+ if (scoped)
124
+ return projected;
125
+ const base = baseSelector(node);
126
+ if (!base)
127
+ return projected;
128
+ const k = seen.get(base) ?? 0;
129
+ seen.set(base, k + 1);
130
+ projected.target = k === 0 ? base : `${base} >> nth=${k}`;
131
+ return projected;
132
+ });
133
+ }
134
+ /** Pick a subset of keys off an object (a typed `SELECT cols`) for the `fields` projection. */
135
+ function pick(obj, keys) {
136
+ const out = {};
137
+ for (const key of keys)
138
+ out[key] = obj[key];
139
+ return out;
140
+ }
141
+ /**
142
+ * 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.
144
+ */
145
+ export async function runObserve(adapter, input) {
146
+ const { kind, query, fields, filters, limit, within } = input;
147
+ switch (kind) {
148
+ case 'tree': {
149
+ const nodes = await adapter.readState({ query, filters, limit, within });
150
+ const scoped = within !== undefined || filters !== undefined;
151
+ const projected = withTargets(nodes, fields, scoped);
152
+ return { kind, count: projected.length, nodes: projected };
153
+ }
154
+ case 'screenshot': {
155
+ const png = await adapter.screenshot();
156
+ return {
157
+ kind,
158
+ encoding: 'png',
159
+ bytes: png.byteLength,
160
+ data: Buffer.from(png).toString('base64'),
161
+ };
162
+ }
163
+ case 'console': {
164
+ const entries = await adapter.console({ filters, limit });
165
+ return { kind, count: entries.length, entries };
166
+ }
167
+ case 'network': {
168
+ const entries = await adapter.network({ filters, limit });
169
+ return { kind, count: entries.length, entries };
170
+ }
171
+ default: {
172
+ const unreachable = kind;
173
+ throw new AgentError(`unknown observe kind: ${String(unreachable)}`);
174
+ }
175
+ }
176
+ }
177
+ /** Build the `observe` tool bound to one adapter, for the debug agent's belt. */
178
+ export function createObserveTool(adapter) {
179
+ 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.',
181
+ inputSchema: ObserveInputSchema,
182
+ execute: (input) => runObserve(adapter, input),
183
+ });
184
+ }
185
+ //# sourceMappingURL=observe.js.map
@@ -0,0 +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,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,C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AAE,KAAK,CAAC;KAC/C,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * `report` — the driver's terminal verdict (inner belt).
3
+ *
4
+ * The loop's full stop. The driver calls `report` exactly once, when the goal is
5
+ * met (or the step limit is hit), to hand the smart agent a structured verdict:
6
+ * `{ status, steps[], bugs[], visual[], summary? }`.
7
+ * It Zod-validates that shape, writes the final `findings.json` through the store,
8
+ * and returns `stop: true` — the signal the agent loop ends on (`get_findings`
9
+ * then surfaces exactly this object to the smart agent; no prose parsing).
10
+ *
11
+ * `status` is the TERMINAL verdict only — `passed` | `failed`. `running` is the
12
+ * live in-flight state the session overlays before a verdict exists; emitting it
13
+ * here would be a contradiction (a run that is both concluded and not), so the
14
+ * input schema rejects it. The other fields reuse the canonical findings
15
+ * sub-schemas (`StepSchema` · `BugSchema` · `VisualIssueSchema`) so the verdict
16
+ * the driver emits is byte-for-byte the verdict the store persists.
17
+ *
18
+ * Store-only seam: it touches just `writeFindings` via the {@link FindingsWriter}
19
+ * slice — adapter-blind like the rest of the belt. Fails loud: an invalid verdict
20
+ * surfaces the store's `FindingsError`; we never write a half-formed findings file
21
+ * or silently fall back.
22
+ */
23
+ import { z } from 'zod';
24
+ import type { Findings, Step } from '../../findings/schema.js';
25
+ /**
26
+ * `report` input — the findings shape with a terminal `status`. Reuses the
27
+ * canonical findings sub-schemas so the emitted verdict matches what the store
28
+ * persists; arrays default to `[]` so a clean pass needs only `{ status }`.
29
+ */
30
+ export declare const ReportInputSchema: z.ZodObject<{
31
+ status: z.ZodEnum<{
32
+ passed: "passed";
33
+ failed: "failed";
34
+ }>;
35
+ steps: z.ZodDefault<z.ZodArray<z.ZodObject<{
36
+ step: z.ZodString;
37
+ ok: z.ZodBoolean;
38
+ note: z.ZodOptional<z.ZodString>;
39
+ screenshot: z.ZodOptional<z.ZodString>;
40
+ }, z.core.$strip>>>;
41
+ bugs: z.ZodDefault<z.ZodArray<z.ZodObject<{
42
+ kind: z.ZodEnum<{
43
+ console: "console";
44
+ network: "network";
45
+ flow: "flow";
46
+ }>;
47
+ detail: z.ZodString;
48
+ evidence: z.ZodOptional<z.ZodString>;
49
+ }, z.core.$strip>>>;
50
+ visual: z.ZodDefault<z.ZodArray<z.ZodObject<{
51
+ issue: z.ZodString;
52
+ where: z.ZodString;
53
+ severity: z.ZodEnum<{
54
+ low: "low";
55
+ medium: "medium";
56
+ high: "high";
57
+ }>;
58
+ screenshot: z.ZodOptional<z.ZodString>;
59
+ }, z.core.$strip>>>;
60
+ summary: z.ZodOptional<z.ZodString>;
61
+ }, z.core.$strip>;
62
+ export type ReportInput = z.infer<typeof ReportInputSchema>;
63
+ /** Structured `report` result — confirms the written verdict and signals the loop to stop. */
64
+ export interface ReportResult {
65
+ /** The terminal verdict written (mirrors the input discriminant). */
66
+ status: ReportInput['status'];
67
+ /** Path to the written `findings.json` (an evidence pointer, never the inlined blob). */
68
+ findings: string;
69
+ /** Counts derived from the written {@link Findings}, so the verdict reads without re-opening the file. */
70
+ counts: {
71
+ steps: number;
72
+ bugs: number;
73
+ visual: number;
74
+ };
75
+ /** Terminal signal: the agent loop ends after this call. `report` is the full stop. */
76
+ stop: true;
77
+ }
78
+ /**
79
+ * The slice of the findings store `report` writes through. {@link FindingsStore}
80
+ * satisfies it structurally, so the real store drops in; tests pass a fake.
81
+ */
82
+ export interface FindingsWriter {
83
+ /** Validate + write the final `findings.json` (overwrites); returns its path. */
84
+ writeFindings(findings: Findings): Promise<string>;
85
+ }
86
+ /**
87
+ * Build the canonical findings record from a validated report input. The base
88
+ * verdict shape; {@link terminalFindings} overlays the loop's recorded act-trail
89
+ * on top, so both the persisted write and the returned counts agree.
90
+ */
91
+ export declare function reportFindings(input: ReportInput): Findings;
92
+ /**
93
+ * The authoritative terminal {@link Findings}: the report input with the loop's
94
+ * recorded act-`trail` overlaid as `steps` whenever one was captured. The driver's
95
+ * `report` rarely restates the steps it took (and the trail carries the evidence
96
+ * frames), so the trail wins; the reported steps are the fallback for a run that
97
+ * recorded none. The single source of truth for the terminal write AND the counts,
98
+ * so they never drift (a `0`-step result returned over a trail-filled file).
99
+ */
100
+ export declare function terminalFindings(input: ReportInput, trail?: readonly Step[]): Findings;
101
+ /**
102
+ * Write the terminal verdict and report the stop. Both the persisted findings and
103
+ * the returned counts derive from one {@link terminalFindings} object — the loop's
104
+ * `trail` (when present) is authoritative for `steps`. Pure over the
105
+ * {@link FindingsWriter} seam, so it unit-tests against a fake with no disk.
106
+ */
107
+ export declare function runReport(writer: FindingsWriter, input: ReportInput, trail?: readonly Step[]): Promise<ReportResult>;
108
+ /**
109
+ * Build the `report` tool bound to one findings store, for the debug agent's belt.
110
+ * `getTrail` (when wired by the loop) supplies the recorded act-trail so the
111
+ * written verdict and its counts both reflect the steps actually taken.
112
+ */
113
+ export declare function createReportTool(writer: FindingsWriter, getTrail?: () => readonly Step[]): import("ai").Tool<{
114
+ status: "passed" | "failed";
115
+ steps: {
116
+ step: string;
117
+ ok: boolean;
118
+ note?: string | undefined;
119
+ screenshot?: string | undefined;
120
+ }[];
121
+ bugs: {
122
+ kind: "console" | "network" | "flow";
123
+ detail: string;
124
+ evidence?: string | undefined;
125
+ }[];
126
+ visual: {
127
+ issue: string;
128
+ where: string;
129
+ severity: "low" | "medium" | "high";
130
+ screenshot?: string | undefined;
131
+ }[];
132
+ summary?: string | undefined;
133
+ }, ReportResult>;
@@ -0,0 +1,112 @@
1
+ /**
2
+ * `report` — the driver's terminal verdict (inner belt).
3
+ *
4
+ * The loop's full stop. The driver calls `report` exactly once, when the goal is
5
+ * met (or the step limit is hit), to hand the smart agent a structured verdict:
6
+ * `{ status, steps[], bugs[], visual[], summary? }`.
7
+ * It Zod-validates that shape, writes the final `findings.json` through the store,
8
+ * and returns `stop: true` — the signal the agent loop ends on (`get_findings`
9
+ * then surfaces exactly this object to the smart agent; no prose parsing).
10
+ *
11
+ * `status` is the TERMINAL verdict only — `passed` | `failed`. `running` is the
12
+ * live in-flight state the session overlays before a verdict exists; emitting it
13
+ * here would be a contradiction (a run that is both concluded and not), so the
14
+ * input schema rejects it. The other fields reuse the canonical findings
15
+ * sub-schemas (`StepSchema` · `BugSchema` · `VisualIssueSchema`) so the verdict
16
+ * the driver emits is byte-for-byte the verdict the store persists.
17
+ *
18
+ * Store-only seam: it touches just `writeFindings` via the {@link FindingsWriter}
19
+ * slice — adapter-blind like the rest of the belt. Fails loud: an invalid verdict
20
+ * surfaces the store's `FindingsError`; we never write a half-formed findings file
21
+ * or silently fall back.
22
+ */
23
+ import { tool } from 'ai';
24
+ import { z } from 'zod';
25
+ import { BugSchema, StepSchema, VisualIssueSchema } from '../../findings/schema.js';
26
+ /** Terminal verdicts `report` may emit — `running` is excluded (it isn't terminal). */
27
+ const TERMINAL_STATUSES = ['passed', 'failed'];
28
+ /**
29
+ * `report` input — the findings shape with a terminal `status`. Reuses the
30
+ * canonical findings sub-schemas so the emitted verdict matches what the store
31
+ * persists; arrays default to `[]` so a clean pass needs only `{ status }`.
32
+ */
33
+ export const ReportInputSchema = z.object({
34
+ status: z
35
+ .enum(TERMINAL_STATUSES)
36
+ .describe('terminal verdict: passed (goal met, no blockers) | failed (blocking bug/visual issue)'),
37
+ steps: z
38
+ .array(StepSchema)
39
+ .default([])
40
+ .describe('ordered step trail: what you did and whether each was ok'),
41
+ bugs: z
42
+ .array(BugSchema)
43
+ .default([])
44
+ .describe('functional bugs found: { kind: console|network|flow, detail, evidence? }'),
45
+ visual: z
46
+ .array(VisualIssueSchema)
47
+ .default([])
48
+ .describe('visual issues from look: { issue, where, severity, screenshot? }'),
49
+ summary: z
50
+ .string()
51
+ .optional()
52
+ .describe('one-paragraph, actionable verdict for the smart agent: what broke, where, what to fix'),
53
+ });
54
+ /**
55
+ * Build the canonical findings record from a validated report input. The base
56
+ * verdict shape; {@link terminalFindings} overlays the loop's recorded act-trail
57
+ * on top, so both the persisted write and the returned counts agree.
58
+ */
59
+ export function reportFindings(input) {
60
+ return {
61
+ status: input.status,
62
+ steps: input.steps,
63
+ bugs: input.bugs,
64
+ visual: input.visual,
65
+ ...(input.summary !== undefined && { summary: input.summary }),
66
+ };
67
+ }
68
+ /**
69
+ * The authoritative terminal {@link Findings}: the report input with the loop's
70
+ * recorded act-`trail` overlaid as `steps` whenever one was captured. The driver's
71
+ * `report` rarely restates the steps it took (and the trail carries the evidence
72
+ * frames), so the trail wins; the reported steps are the fallback for a run that
73
+ * recorded none. The single source of truth for the terminal write AND the counts,
74
+ * so they never drift (a `0`-step result returned over a trail-filled file).
75
+ */
76
+ export function terminalFindings(input, trail = []) {
77
+ const findings = reportFindings(input);
78
+ return trail.length > 0 ? { ...findings, steps: [...trail] } : findings;
79
+ }
80
+ /**
81
+ * Write the terminal verdict and report the stop. Both the persisted findings and
82
+ * the returned counts derive from one {@link terminalFindings} object — the loop's
83
+ * `trail` (when present) is authoritative for `steps`. Pure over the
84
+ * {@link FindingsWriter} seam, so it unit-tests against a fake with no disk.
85
+ */
86
+ export async function runReport(writer, input, trail = []) {
87
+ const findings = terminalFindings(input, trail);
88
+ const path = await writer.writeFindings(findings);
89
+ return {
90
+ status: input.status,
91
+ findings: path,
92
+ counts: {
93
+ steps: findings.steps.length,
94
+ bugs: findings.bugs.length,
95
+ visual: findings.visual.length,
96
+ },
97
+ stop: true,
98
+ };
99
+ }
100
+ /**
101
+ * Build the `report` tool bound to one findings store, for the debug agent's belt.
102
+ * `getTrail` (when wired by the loop) supplies the recorded act-trail so the
103
+ * written verdict and its counts both reflect the steps actually taken.
104
+ */
105
+ export function createReportTool(writer, getTrail) {
106
+ return tool({
107
+ description: 'Emit the final structured findings and END the run. Call exactly once, when the goal is met or you hit the step limit. Validates and writes findings.json: status (passed|failed) plus steps/bugs/visual/summary. This is terminal — the loop stops after report, so do not act again. Make summary actionable for the smart agent: what broke, where, what to fix.',
108
+ inputSchema: ReportInputSchema,
109
+ execute: (input) => runReport(writer, input, getTrail?.() ?? []),
110
+ });
111
+ }
112
+ //# sourceMappingURL=report.js.map
@@ -0,0 +1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-0,0 +1,136 @@
1
+ /**
2
+ * The debug agent loop — the fast guy's run, as a conversation.
3
+ *
4
+ * A {@link ToolLoopAgent} drives the inner belt (`observe`/`act`/`look`/`report`)
5
+ * with the `driver` model until the goal is met (`report`, the terminal verdict)
6
+ * or a safety step cap trips. Two things make it a *conversation*, not a job:
7
+ *
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.
11
+ * - **incremental findings** — `onStepFinish` lifts each step's `act` results
12
+ * into a running step trail and flushes it as `status: 'running'` findings,
13
+ * so `get_findings` shows live progress before the verdict lands.
14
+ *
15
+ * Adapter-blind and model-blind like the belt: the loop never touches a protocol
16
+ * or a provider. It is pure over two seams — {@link LoopInbox} (drain) and
17
+ * {@link ProgressWriter} (flush) — so its logic unit-tests with no network. The
18
+ * `report` step owns the terminal write, so the running flush steps aside for it
19
+ * (never clobbers the verdict with a `running` snapshot). Abort propagates: an
20
+ * aborted run rejects loud (wired to `end_session`), never a silent half-finish.
21
+ */
22
+ import { type LanguageModel, type ModelMessage, type Tool, ToolLoopAgent } from 'ai';
23
+ import type { Findings, Step } from '../findings/schema.js';
24
+ /** Safety cap on driver steps before the loop force-stops (paired with `hasToolCall('report')`). */
25
+ export declare const DEFAULT_MAX_STEPS = 30;
26
+ /** Kickoff turn — the story lives in `instructions`; this nudges the driver to start the loop. */
27
+ export declare const KICKOFF_PROMPT = "Begin. Work toward the goal with observe/act/look, then call report exactly once with your verdict.";
28
+ /** The driver's inner belt — the four fat tools the loop drives (see `idea/mcp-tools.md`). */
29
+ export type BeltTools = {
30
+ observe: Tool;
31
+ act: Tool;
32
+ look: Tool;
33
+ report: Tool;
34
+ };
35
+ /** Inbox seam: the mid-run messages the smart agent injected, returned and cleared between steps. */
36
+ export interface LoopInbox {
37
+ /** Return all pending messages and clear them; `[]` when nothing is queued. */
38
+ drain(): readonly string[];
39
+ }
40
+ /** Progress seam: persist the running step trail so `get_findings` shows live progress before `report`. */
41
+ export interface ProgressWriter {
42
+ /** Validate + write the current (running) findings; returns the path written. */
43
+ writeFindings(findings: Findings): Promise<string>;
44
+ }
45
+ /** The slice of a finished step the running flush reads — `act` results carry the trail. */
46
+ export interface FinishedStep {
47
+ /** Tools called this step; a `report` call marks the terminal step (verdict owned elsewhere). */
48
+ toolCalls: ReadonlyArray<{
49
+ toolName: string;
50
+ input?: unknown;
51
+ }>;
52
+ /** Tool results this step; `act` outputs become step-trail entries. */
53
+ toolResults: ReadonlyArray<{
54
+ toolName: string;
55
+ output: unknown;
56
+ }>;
57
+ }
58
+ /**
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.
62
+ */
63
+ export declare function drainInboxIntoStep(inbox: LoopInbox, messages: ModelMessage[]): {
64
+ messages: ModelMessage[];
65
+ } | Record<string, never>;
66
+ /** Steps left at or below which the driver is nudged to wrap up and `report`. */
67
+ export declare const BUDGET_WARN = 6;
68
+ /**
69
+ * A step-budget reminder folded into the turn as the run nears its cap — so the
70
+ * driver converges on `report` instead of churning to the hard `stepCountIs` stop
71
+ * (which leaves an empty, verdict-less `failed` run). `null` while there is ample
72
+ * budget. `stepNumber` is the 0-based index of the step about to run.
73
+ */
74
+ export declare function budgetNudge(stepNumber: number, maxSteps: number): string | null;
75
+ /** Lift a finished step's `act` results into ordered step-trail entries (each with its frame). */
76
+ export declare function stepTrailFrom(toolResults: ReadonlyArray<{
77
+ toolName: string;
78
+ output: unknown;
79
+ }>): Step[];
80
+ /**
81
+ * Decide the running-findings write for a finished step. Steps aside for the
82
+ * terminal `report` step (it owns the verdict) and for steps that produced no
83
+ * `act` results; otherwise appends the fresh trail to `trail` (mutated in place)
84
+ * and returns the `running` findings to persist.
85
+ */
86
+ export declare function progressForStep(step: FinishedStep, trail: Step[]): Findings | null;
87
+ /** Everything the loop needs to run one debug session. */
88
+ export interface DebugAgentOptions {
89
+ /** fast guy — the blind text driver running the high-frequency click loop. */
90
+ model: LanguageModel;
91
+ /** The inner belt the driver drives: `observe`/`act`/`look`/`report`. */
92
+ tools: BeltTools;
93
+ /** Composed system prompt (base + target addendum + story + criteria). */
94
+ instructions: string;
95
+ /** Mid-run message inbox, drained in `prepareStep`. */
96
+ inbox: LoopInbox;
97
+ /** Where the running step trail is flushed after each step. */
98
+ progress: ProgressWriter;
99
+ /** Optional sink for a human-readable step trail (`logs/agent.log`). */
100
+ log?: AgentLog;
101
+ /**
102
+ * Shared act-trail the running flush appends to and the `report` tool overlays
103
+ * as the verdict's authoritative `steps` — pass the SAME array to
104
+ * {@link createReportTool}'s `getTrail` so the write and its counts agree.
105
+ * Defaults to a fresh array (the report tool then keeps the driver's steps).
106
+ */
107
+ trail?: Step[];
108
+ /** Step safety cap; defaults to {@link DEFAULT_MAX_STEPS}. */
109
+ maxSteps?: number;
110
+ }
111
+ /** Agent-log seam: one line per step (tool calls + any tool error), best-effort. */
112
+ export type AgentLog = (line: string) => void;
113
+ /** Summarize a finished step for `logs/agent.log`: the tools it called (+ input) + any error text. */
114
+ export declare function describeStep(step: FinishedStep, index: number): string;
115
+ /**
116
+ * Build the debug agent loop. The driver runs `observe`→`act`→`look` until it
117
+ * calls `report` (terminal) or hits the step cap. Between steps `prepareStep`
118
+ * folds in mid-run messages; after each step `onStepFinish` flushes the running
119
+ * trail (skipping the `report` step, which writes the final verdict itself).
120
+ */
121
+ export declare function createDebugAgent(options: DebugAgentOptions): ToolLoopAgent<never, BeltTools>;
122
+ /** How to run a built loop to its verdict. */
123
+ export interface RunDebugLoopOptions {
124
+ /** The agent from {@link createDebugAgent}. */
125
+ agent: ToolLoopAgent<never, BeltTools>;
126
+ /** Aborts the in-flight model/tool calls — wired to `end_session`. */
127
+ abortSignal?: AbortSignal;
128
+ /** Override the kickoff turn (defaults to {@link KICKOFF_PROMPT}). */
129
+ prompt?: string;
130
+ }
131
+ /**
132
+ * Run the loop to its verdict. Resolves with the agent's generate result once the
133
+ * driver reports (or the step cap trips); rejects if aborted (fail loud — the
134
+ * session decides what an aborted run means).
135
+ */
136
+ export declare function runDebugLoop(options: RunDebugLoopOptions): Promise<import("ai").GenerateTextResult<BeltTools, never>>;