@developerz.ai/ui-debugger-mcp 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/README.md +22 -10
  2. package/dist/adapters/android/adb.d.ts +34 -5
  3. package/dist/adapters/android/adb.js +74 -20
  4. package/dist/adapters/android/adb.js.map +1 -1
  5. package/dist/adapters/android/android-adapter.d.ts +23 -7
  6. package/dist/adapters/android/android-adapter.js +106 -36
  7. package/dist/adapters/android/android-adapter.js.map +1 -1
  8. package/dist/adapters/android/android-adapter.test-helpers.d.ts +52 -0
  9. package/dist/adapters/android/android-adapter.test-helpers.js +115 -0
  10. package/dist/adapters/android/android-adapter.test-helpers.js.map +1 -0
  11. package/dist/adapters/android/commands.d.ts +27 -4
  12. package/dist/adapters/android/commands.js +66 -4
  13. package/dist/adapters/android/commands.js.map +1 -1
  14. package/dist/adapters/android/ports.d.ts +32 -0
  15. package/dist/adapters/android/ports.js +47 -0
  16. package/dist/adapters/android/ports.js.map +1 -0
  17. package/dist/adapters/android/uiautomator.d.ts +10 -2
  18. package/dist/adapters/android/uiautomator.js +36 -4
  19. package/dist/adapters/android/uiautomator.js.map +1 -1
  20. package/dist/adapters/browser/browser-adapter.d.ts +14 -13
  21. package/dist/adapters/browser/browser-adapter.js +69 -306
  22. package/dist/adapters/browser/browser-adapter.js.map +1 -1
  23. package/dist/adapters/browser/cdp.js +18 -11
  24. package/dist/adapters/browser/cdp.js.map +1 -1
  25. package/dist/adapters/browser/extractor.d.ts +49 -0
  26. package/dist/adapters/browser/extractor.js +208 -0
  27. package/dist/adapters/browser/extractor.js.map +1 -0
  28. package/dist/adapters/browser/filters.d.ts +15 -0
  29. package/dist/adapters/browser/filters.js +93 -0
  30. package/dist/adapters/browser/filters.js.map +1 -0
  31. package/dist/adapters/browser/launch.d.ts +41 -0
  32. package/dist/adapters/browser/launch.js +61 -0
  33. package/dist/adapters/browser/launch.js.map +1 -0
  34. package/dist/adapters/budget.d.ts +16 -0
  35. package/dist/adapters/budget.js +25 -0
  36. package/dist/adapters/budget.js.map +1 -0
  37. package/dist/adapters/contract.d.ts +13 -6
  38. package/dist/adapters/desktop/atspi.d.ts +15 -0
  39. package/dist/adapters/desktop/atspi.js +37 -17
  40. package/dist/adapters/desktop/atspi.js.map +1 -1
  41. package/dist/adapters/desktop/capture.js +8 -1
  42. package/dist/adapters/desktop/capture.js.map +1 -1
  43. package/dist/adapters/desktop/desktop-adapter.d.ts +9 -2
  44. package/dist/adapters/desktop/desktop-adapter.js +84 -32
  45. package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
  46. package/dist/adapters/desktop/input.d.ts +16 -1
  47. package/dist/adapters/desktop/input.js +30 -0
  48. package/dist/adapters/desktop/input.js.map +1 -1
  49. package/dist/adapters/desktop/proc.d.ts +18 -3
  50. package/dist/adapters/desktop/proc.js +48 -5
  51. package/dist/adapters/desktop/proc.js.map +1 -1
  52. package/dist/adapters/factory.d.ts +3 -1
  53. package/dist/adapters/factory.js +6 -2
  54. package/dist/adapters/factory.js.map +1 -1
  55. package/dist/adapters/limit.d.ts +10 -0
  56. package/dist/adapters/limit.js +19 -0
  57. package/dist/adapters/limit.js.map +1 -0
  58. package/dist/agent/belt/act.d.ts +27 -5
  59. package/dist/agent/belt/act.js +75 -17
  60. package/dist/agent/belt/act.js.map +1 -1
  61. package/dist/agent/belt/observe.d.ts +29 -15
  62. package/dist/agent/belt/observe.js +74 -19
  63. package/dist/agent/belt/observe.js.map +1 -1
  64. package/dist/agent/belt/report.d.ts +29 -9
  65. package/dist/agent/belt/report.js +77 -10
  66. package/dist/agent/belt/report.js.map +1 -1
  67. package/dist/agent/belt/trail.d.ts +34 -0
  68. package/dist/agent/belt/trail.js +64 -0
  69. package/dist/agent/belt/trail.js.map +1 -0
  70. package/dist/agent/capabilities.d.ts +4 -4
  71. package/dist/agent/capabilities.js +38 -13
  72. package/dist/agent/capabilities.js.map +1 -1
  73. package/dist/agent/loop.d.ts +58 -19
  74. package/dist/agent/loop.js +134 -46
  75. package/dist/agent/loop.js.map +1 -1
  76. package/dist/agent/prompts/compose.d.ts +9 -1
  77. package/dist/agent/prompts/compose.js +5 -4
  78. package/dist/agent/prompts/compose.js.map +1 -1
  79. package/dist/agent/prompts/debug-agent.d.ts +13 -1
  80. package/dist/agent/prompts/debug-agent.js +45 -11
  81. package/dist/agent/prompts/debug-agent.js.map +1 -1
  82. package/dist/agent/prompts/desktop-addendum.d.ts +1 -1
  83. package/dist/agent/prompts/desktop-addendum.js +1 -1
  84. package/dist/agent/prompts/web-addendum.d.ts +1 -1
  85. package/dist/agent/prompts/web-addendum.js +16 -18
  86. package/dist/agent/prompts/web-addendum.js.map +1 -1
  87. package/dist/cli/control.d.ts +3 -1
  88. package/dist/cli/control.js +26 -40
  89. package/dist/cli/control.js.map +1 -1
  90. package/dist/cli/help.d.ts +3 -1
  91. package/dist/cli/help.js +6 -2
  92. package/dist/cli/help.js.map +1 -1
  93. package/dist/cli/init.d.ts +3 -6
  94. package/dist/cli/init.js +64 -16
  95. package/dist/cli/init.js.map +1 -1
  96. package/dist/config/load.js +8 -1
  97. package/dist/config/load.js.map +1 -1
  98. package/dist/config/schema.d.ts +12 -5
  99. package/dist/config/schema.js +17 -7
  100. package/dist/config/schema.js.map +1 -1
  101. package/dist/errors.d.ts +14 -2
  102. package/dist/errors.js +24 -4
  103. package/dist/errors.js.map +1 -1
  104. package/dist/index.d.ts +1 -1
  105. package/dist/index.js +1 -1
  106. package/dist/main.js +22 -8
  107. package/dist/main.js.map +1 -1
  108. package/dist/mcp/server.d.ts +16 -1
  109. package/dist/mcp/server.js +23 -2
  110. package/dist/mcp/server.js.map +1 -1
  111. package/dist/mcp/server.test-helpers.d.ts +23 -0
  112. package/dist/mcp/server.test-helpers.js +49 -0
  113. package/dist/mcp/server.test-helpers.js.map +1 -0
  114. package/dist/mcp/tools/describe.js +5 -0
  115. package/dist/mcp/tools/describe.js.map +1 -1
  116. package/dist/mcp/tools/end-session.js +5 -0
  117. package/dist/mcp/tools/end-session.js.map +1 -1
  118. package/dist/mcp/tools/get-findings.js +23 -3
  119. package/dist/mcp/tools/get-findings.js.map +1 -1
  120. package/dist/mcp/tools/output.d.ts +50 -0
  121. package/dist/mcp/tools/output.js +55 -0
  122. package/dist/mcp/tools/output.js.map +1 -0
  123. package/dist/mcp/tools/result.d.ts +24 -1
  124. package/dist/mcp/tools/result.js +106 -5
  125. package/dist/mcp/tools/result.js.map +1 -1
  126. package/dist/mcp/tools/send-message.js +5 -0
  127. package/dist/mcp/tools/send-message.js.map +1 -1
  128. package/dist/mcp/tools/start-debug.js +7 -1
  129. package/dist/mcp/tools/start-debug.js.map +1 -1
  130. package/dist/services/debug-service.d.ts +38 -6
  131. package/dist/services/debug-service.js +122 -13
  132. package/dist/services/debug-service.js.map +1 -1
  133. package/dist/services/session-builder.d.ts +20 -3
  134. package/dist/services/session-builder.js +43 -13
  135. package/dist/services/session-builder.js.map +1 -1
  136. package/dist/session/atomic-write.d.ts +24 -0
  137. package/dist/session/atomic-write.js +39 -0
  138. package/dist/session/atomic-write.js.map +1 -0
  139. package/dist/session/findings-store.js +3 -4
  140. package/dist/session/findings-store.js.map +1 -1
  141. package/dist/session/process-identity.d.ts +16 -0
  142. package/dist/session/process-identity.js +29 -0
  143. package/dist/session/process-identity.js.map +1 -1
  144. package/dist/session/session.js +10 -2
  145. package/dist/session/session.js.map +1 -1
  146. package/dist/session/state-file.d.ts +51 -5
  147. package/dist/session/state-file.js +60 -8
  148. package/dist/session/state-file.js.map +1 -1
  149. package/dist/session/workspace.d.ts +11 -0
  150. package/dist/session/workspace.js +14 -1
  151. package/dist/session/workspace.js.map +1 -1
  152. package/package.json +4 -1
@@ -4,17 +4,118 @@
4
4
  * back BOTH as pretty-printed `text` (human/log readable) and as
5
5
  * `structuredContent` (the typed channel MCP clients parse). Keeps the five tool
6
6
  * handlers a single `toToolResult(await service.x(args))` line each.
7
+ *
8
+ * Two spec-alignment behaviors live here too, so no tool handler has to think
9
+ * about them:
10
+ * - **Truncation steering** (opt-in, see {@link ToolResultOptions.capLists}):
11
+ * a list over {@link MAX_LIST_ITEMS} gets capped and a trailing text block
12
+ * names the retrieval that returns it whole. Never capped without one — a
13
+ * dropped entry the caller cannot ask for again is silent data loss.
14
+ * - **`resource_link`s**: evidence paths (screenshots, `replay.mp4`, logs) ride
15
+ * as `resource_link` content items (file:// URIs) alongside the text block —
16
+ * the spec-blessed form, not inline path strings the caller has to notice.
7
17
  */
8
18
  /** A plain object value (not an array) — what every outer tool returns. */
9
19
  function isRecord(value) {
10
20
  return typeof value === 'object' && value !== null && !Array.isArray(value);
11
21
  }
12
- /** Wrap a service result as a tool response: pretty `text` plus `structuredContent` for records. */
13
- export function toToolResult(data) {
14
- const text = JSON.stringify(data, null, 2);
22
+ /** Cap on a top-level array field before it gets truncated for the response. */
23
+ const MAX_LIST_ITEMS = 20;
24
+ /** Keys whose string value — when an absolute path — is evidence worth linking. */
25
+ const EVIDENCE_KEYS = new Set(['screenshot', 'evidence']);
26
+ /** Guess a MIME type from an evidence path's extension; omit when unknown. */
27
+ function mimeTypeFor(path) {
28
+ if (path.endsWith('.png'))
29
+ return 'image/png';
30
+ if (path.endsWith('.jpg') || path.endsWith('.jpeg'))
31
+ return 'image/jpeg';
32
+ if (path.endsWith('.mp4'))
33
+ return 'video/mp4';
34
+ if (path.endsWith('.log'))
35
+ return 'text/plain';
36
+ return undefined;
37
+ }
38
+ /** Build one `resource_link` content item for an absolute evidence path. */
39
+ function resourceLink(path) {
40
+ const mimeType = mimeTypeFor(path);
15
41
  return {
16
- content: [{ type: 'text', text }],
17
- ...(isRecord(data) ? { structuredContent: data } : {}),
42
+ type: 'resource_link',
43
+ uri: new URL(path, 'file://').href,
44
+ name: path.split('/').pop() ?? path,
45
+ ...(mimeType !== undefined && { mimeType }),
46
+ };
47
+ }
48
+ /**
49
+ * Walk a (findings-shaped) value collecting `resource_link`s for every absolute
50
+ * path under an evidence-ish key. Only absolute paths qualify — `bugs[].evidence`
51
+ * doubles as free-text ("line 42"), so a relative-looking string is left as text,
52
+ * not linked. Dedupes by path (a replay path can be both `findings.evidence` and
53
+ * on a step).
54
+ */
55
+ function collectResourceLinks(value) {
56
+ const links = [];
57
+ const seen = new Set();
58
+ const walk = (node) => {
59
+ if (Array.isArray(node)) {
60
+ for (const item of node)
61
+ walk(item);
62
+ return;
63
+ }
64
+ if (!isRecord(node))
65
+ return;
66
+ for (const [key, val] of Object.entries(node)) {
67
+ if (typeof val === 'string' && EVIDENCE_KEYS.has(key) && val.startsWith('/')) {
68
+ if (!seen.has(val)) {
69
+ seen.add(val);
70
+ links.push(resourceLink(val));
71
+ }
72
+ }
73
+ else {
74
+ walk(val);
75
+ }
76
+ }
18
77
  };
78
+ walk(value);
79
+ return links;
80
+ }
81
+ /** Cap any top-level array field over {@link MAX_LIST_ITEMS}; report which ones. */
82
+ function capLists(data) {
83
+ const truncated = [];
84
+ const capped = {};
85
+ for (const [key, value] of Object.entries(data)) {
86
+ if (Array.isArray(value) && value.length > MAX_LIST_ITEMS) {
87
+ capped[key] = value.slice(0, MAX_LIST_ITEMS);
88
+ truncated.push(key);
89
+ }
90
+ else {
91
+ capped[key] = value;
92
+ }
93
+ }
94
+ return { capped, truncated };
95
+ }
96
+ /** Steering text appended when one or more lists got capped. */
97
+ function steeringNote(truncated) {
98
+ const fields = truncated.map((f) => `"${f}"`).join(', ');
99
+ return (`Truncated ${truncated.join(', ')} to the first ${MAX_LIST_ITEMS} items. ` +
100
+ `Call get_findings with fields=[${fields}] to read those arrays in full — ` +
101
+ 'a projected read is never truncated. The complete run also sits on disk: ' +
102
+ 'findings.json / replay.mp4 / the logs under the session workspace.');
103
+ }
104
+ /** Wrap a service result as a tool response: pretty `text` plus `structuredContent` for records. */
105
+ export function toToolResult(data, options = {}) {
106
+ if (!isRecord(data)) {
107
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
108
+ }
109
+ const { capped, truncated } = options.capLists
110
+ ? capLists(data)
111
+ : { capped: data, truncated: [] };
112
+ const content = [
113
+ { type: 'text', text: JSON.stringify(capped, null, 2) },
114
+ ];
115
+ if (truncated.length > 0) {
116
+ content.push({ type: 'text', text: steeringNote(truncated) });
117
+ }
118
+ content.push(...collectResourceLinks(capped));
119
+ return { content, structuredContent: capped };
19
120
  }
20
121
  //# sourceMappingURL=result.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/mcp/tools/result.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,2EAA2E;AAC3E,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,YAAY,CAAC,IAAa;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3C,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACjC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvD,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/mcp/tools/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,2EAA2E;AAC3E,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,gFAAgF;AAChF,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1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OAAO,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;IAE9C,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC"}
@@ -6,6 +6,7 @@
6
6
  * {@link DebugApi.send}, ack.
7
7
  */
8
8
  import { z } from 'zod';
9
+ import { AckSchema } from './output.js';
9
10
  import { toToolResult } from './result.js';
10
11
  /** Build the `send_message` outer tool bound to the debug service. */
11
12
  export function sendMessageTool(service) {
@@ -17,6 +18,9 @@ export function sendMessageTool(service) {
17
18
  description: 'Talk to the small driver agent mid-run: add work, redirect it, or answer a question. ' +
18
19
  'The message is folded into the conversation before the next step — the run keeps going, ' +
19
20
  'no restart. Use get_findings to see the effect.',
21
+ annotations: {
22
+ destructiveHint: false,
23
+ },
20
24
  inputSchema: {
21
25
  session_id: z.string().min(1).describe('The id returned by start_debug.'),
22
26
  message: z
@@ -24,6 +28,7 @@ export function sendMessageTool(service) {
24
28
  .min(1)
25
29
  .describe('The instruction for the driver, in plain language (e.g. "skip checkout, the bug is the login form").'),
26
30
  },
31
+ outputSchema: AckSchema,
27
32
  }, (args) => toToolResult(service.send(args)));
28
33
  },
29
34
  };
@@ -1 +1 @@
1
- {"version":3,"file":"send-message.js","sourceRoot":"","sources":["../../../src/mcp/tools/send-message.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,sEAAsE;AACtE,MAAM,UAAU,eAAe,CAAC,OAAiB;IAC/C,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,QAAQ,CAAC,MAAM;YACb,MAAM,CAAC,YAAY,CACjB,cAAc,EACd;gBACE,KAAK,EAAE,yBAAyB;gBAChC,WAAW,EACT,uFAAuF;oBACvF,0FAA0F;oBAC1F,iDAAiD;gBACnD,WAAW,EAAE;oBACX,U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AAC,CAAC,CAC3C,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -7,6 +7,7 @@
7
7
  * `{ session_id }` result.
8
8
  */
9
9
  import { z } from 'zod';
10
+ import { StartResultSchema } from './output.js';
10
11
  import { toToolResult } from './result.js';
11
12
  /** Build the `start_debug` outer tool bound to the debug service. */
12
13
  export function startDebugTool(service) {
@@ -19,6 +20,10 @@ export function startDebugTool(service) {
19
20
  '(e.g. "web"). It drives the UI autonomously and gathers findings (functional bugs + ' +
20
21
  'visual feedback). One run per project at a time. Returns { session_id }; then poll ' +
21
22
  'get_findings, steer with send_message, and close with end_session.',
23
+ annotations: {
24
+ destructiveHint: false,
25
+ openWorldHint: true,
26
+ },
22
27
  inputSchema: {
23
28
  target: z
24
29
  .string()
@@ -42,8 +47,9 @@ export function startDebugTool(service) {
42
47
  .positive()
43
48
  .max(2_147_483)
44
49
  .optional()
45
- .describe('Wall-clock cap in SECONDS before the run auto-ends (frees the browser/profile). Omit for the default (300s). Max 2_147_483 (Node timer ceiling once × 1000).'),
50
+ .describe('Wall-clock cap in SECONDS before the run auto-ends (frees the browser/profile), counted from this call — launching the browser and the first navigation spend it too. Omit for the default (300s). Max 2_147_483 (Node timer ceiling once × 1000).'),
46
51
  },
52
+ outputSchema: StartResultSchema,
47
53
  }, async ({ timeout, ...rest }) => toToolResult(await service.start({
48
54
  ...rest,
49
55
  ...(timeout !== undefined && { timeoutMs: timeout * 1000 }),
@@ -1 +1 @@
1
- {"version":3,"file":"start-debug.js","sourceRoot":"","sources":["../../../src/mcp/tools/start-debug.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,qEAAqE;AACrE,MAAM,UAAU,cAAc,CAAC,OAAiB;IAC9C,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,QAAQ,CAAC,MAAM;YACb,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,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -8,10 +8,22 @@
8
8
  * seam — so the orchestration here unit-tests with no browser or network. The MCP
9
9
  * handlers stay thin: validate input, call straight through to a method here.
10
10
  *
11
+ * One run per project holds *across processes* too: the manager only knows this
12
+ * server's memory, so `start` also consults the `state.json` breadcrumb and
13
+ * refuses when another live server already owns a run here (a dead owner's stale
14
+ * breadcrumb never blocks).
15
+ *
11
16
  * Sessions are keyed by cwd, but the tools speak `session_id`. Every id-bearing
12
17
  * call resolves the active session for the cwd and fails loud
13
18
  * ({@link SessionNotFoundError}) when the id does not match, so a stale id never
14
19
  * silently drives the wrong run.
20
+ *
21
+ * A run that ends *without* the caller asking (wall-clock timeout, SIGTERM, the
22
+ * MCP client dying) leaves the manager, but its findings must not vanish with it:
23
+ * the settled session is retained so `get_findings` keeps serving its terminal
24
+ * snapshot. `end_session` is the explicit forget; the next `start_debug`
25
+ * supersedes it. The retained snapshot holds no target resources (the adapter is
26
+ * already closed) and never participates in the one-run gate.
15
27
  */
16
28
  import type { ResolvedConfig } from '../config/load.js';
17
29
  import type { Target } from '../config/schema.js';
@@ -29,7 +41,11 @@ export interface StartInput {
29
41
  criteria?: string;
30
42
  /** Per-run URL the caller points the driver at (web); overrides the target's configured url. */
31
43
  url?: string;
32
- /** Wall-clock cap (ms) before the run auto-ends; defaults to {@link DEFAULT_SESSION_TIMEOUT_MS}. */
44
+ /**
45
+ * Wall-clock cap (ms) before the run auto-ends, counted from THIS call — assembly,
46
+ * launch and the first navigation spend it too. Defaults to
47
+ * {@link DEFAULT_SESSION_TIMEOUT_MS}.
48
+ */
33
49
  timeoutMs?: number;
34
50
  }
35
51
  /** `start_debug` output — the id to poll/redirect/end the run by. */
@@ -105,7 +121,7 @@ export interface DebugServiceDeps {
105
121
  state?: StatePort;
106
122
  /** Default wall-clock cap (ms) for a run; defaults to {@link DEFAULT_SESSION_TIMEOUT_MS}. */
107
123
  defaultTimeoutMs?: number;
108
- /** Injected clock (epoch ms) for session ids; defaults to `Date.now`. */
124
+ /** Injected clock (epoch ms) for session ids + the run deadline; defaults to `Date.now`. */
109
125
  now?: () => number;
110
126
  }
111
127
  export declare class DebugService implements DebugApi {
@@ -114,8 +130,14 @@ export declare class DebugService implements DebugApi {
114
130
  /**
115
131
  * Open a run: assemble the session, take the profile lock, point the adapter at
116
132
  * the target, and kick the loop off in the background. Fails loud if a run is
117
- * already active for this cwd ({@link SessionBusyError}); never leaks a launched
118
- * browser — a lost lock race or a failed `open` tears the session back down.
133
+ * already active for this cwd ({@link SessionBusyError}) — whether it belongs to
134
+ * this server (the manager / in-flight guard) or to another live one (the
135
+ * `state.json` breadcrumb); never leaks a launched browser — a lost lock race or
136
+ * a failed `open` tears the session back down.
137
+ *
138
+ * `timeout` is wall-clock from HERE: the deadline is fixed on entry and the
139
+ * remaining budget is threaded into the build and the first navigation, so a slow
140
+ * Chrome launch spends the caller's cap instead of sitting outside it.
119
141
  */
120
142
  start({ target, goal, criteria, url, timeoutMs }: StartInput): Promise<StartResult>;
121
143
  /**
@@ -124,11 +146,21 @@ export declare class DebugService implements DebugApi {
124
146
  * drains the inbox, so an ack then would silently drop the message.
125
147
  */
126
148
  send({ session_id, message }: SendInput): Ack;
127
- /** Snapshot the run's findings — optionally long-poll (`wait`) and/or project a subset (`fields`). */
149
+ /**
150
+ * Snapshot the run's findings — optionally long-poll (`wait`) and/or project a
151
+ * subset (`fields`). Serves the retained terminal snapshot once the run has
152
+ * auto-ended, so a timed-out run's partial findings stay reachable (the
153
+ * long-poll returns at once: a settled run has nothing left to wait for).
154
+ */
128
155
  getFindings({ session_id, wait, fields, }: GetFindingsInput): Promise<Findings | Partial<Findings>>;
129
156
  /** List configured targets (the whole catalog, or one when named) plus resolved models/workspace. */
130
157
  describe({ target }: DescribeInput): DescribeResult;
131
- /** End the active run: abort the loop, close the adapter, free the profile lock. */
158
+ /**
159
+ * End the active run: abort the loop, close the adapter, free the profile lock.
160
+ * Ending a run that already auto-ended (timeout / client death) is not an error
161
+ * — it just forgets the retained snapshot, so `end_session` reads the same
162
+ * either way and stays the one explicit forget.
163
+ */
132
164
  end({ session_id }: EndInput): Promise<Ack>;
133
165
  /**
134
166
  * End whatever run is active for this cwd, if any — the graceful-shutdown path
@@ -8,10 +8,22 @@
8
8
  * seam — so the orchestration here unit-tests with no browser or network. The MCP
9
9
  * handlers stay thin: validate input, call straight through to a method here.
10
10
  *
11
+ * One run per project holds *across processes* too: the manager only knows this
12
+ * server's memory, so `start` also consults the `state.json` breadcrumb and
13
+ * refuses when another live server already owns a run here (a dead owner's stale
14
+ * breadcrumb never blocks).
15
+ *
11
16
  * Sessions are keyed by cwd, but the tools speak `session_id`. Every id-bearing
12
17
  * call resolves the active session for the cwd and fails loud
13
18
  * ({@link SessionNotFoundError}) when the id does not match, so a stale id never
14
19
  * silently drives the wrong run.
20
+ *
21
+ * A run that ends *without* the caller asking (wall-clock timeout, SIGTERM, the
22
+ * MCP client dying) leaves the manager, but its findings must not vanish with it:
23
+ * the settled session is retained so `get_findings` keeps serving its terminal
24
+ * snapshot. `end_session` is the explicit forget; the next `start_debug`
25
+ * supersedes it. The retained snapshot holds no target resources (the adapter is
26
+ * already closed) and never participates in the one-run gate.
15
27
  */
16
28
  import { SessionBusyError, SessionNotFoundError, SessionSettledError, TargetNotFoundError, } from '../errors.js';
17
29
  import { noopStatePort } from '../session/state-file.js';
@@ -28,6 +40,13 @@ export class DebugService {
28
40
  #now;
29
41
  /** Live wall-clock timer for the active run; cleared when the run ends. */
30
42
  #timer;
43
+ /**
44
+ * The last run that auto-ended (timeout / SIGTERM / client death), kept settled
45
+ * and closed so `get_findings` can still read its partial findings + evidence.
46
+ * Dropped by `end_session` (the explicit forget) and superseded by the next run.
47
+ * Never consulted by the one-run gate — a retained snapshot cannot block a start.
48
+ */
49
+ #retained;
31
50
  /**
32
51
  * A `start()` is in flight (building/launching, slot not yet in the manager).
33
52
  * Set synchronously before the first await so a concurrent `start_debug` fails
@@ -47,8 +66,14 @@ export class DebugService {
47
66
  /**
48
67
  * Open a run: assemble the session, take the profile lock, point the adapter at
49
68
  * the target, and kick the loop off in the background. Fails loud if a run is
50
- * already active for this cwd ({@link SessionBusyError}); never leaks a launched
51
- * browser — a lost lock race or a failed `open` tears the session back down.
69
+ * already active for this cwd ({@link SessionBusyError}) — whether it belongs to
70
+ * this server (the manager / in-flight guard) or to another live one (the
71
+ * `state.json` breadcrumb); never leaks a launched browser — a lost lock race or
72
+ * a failed `open` tears the session back down.
73
+ *
74
+ * `timeout` is wall-clock from HERE: the deadline is fixed on entry and the
75
+ * remaining budget is threaded into the build and the first navigation, so a slow
76
+ * Chrome launch spends the caller's cap instead of sitting outside it.
52
77
  */
53
78
  async start({ target, goal, criteria, url, timeoutMs }) {
54
79
  const cwd = this.#cwd;
@@ -63,9 +88,13 @@ export class DebugService {
63
88
  'Wait for it to open (or end it) before starting another — one run per project at a time.');
64
89
  }
65
90
  this.#starting = true;
91
+ const deadline = this.#now() + (timeoutMs ?? this.#defaultTimeoutMs);
92
+ /** Budget left on the caller's cap; never negative — a blown budget is simply spent. */
93
+ const remaining = () => Math.max(0, deadline - this.#now());
66
94
  try {
95
+ await this.#assertNoForeignRun(cwd);
67
96
  const id = generateSessionId(this.#now());
68
- const built = await this.#build({ id, target, goal, criteria, url });
97
+ const built = await this.#build({ id, target, goal, criteria, url, timeoutMs: remaining() });
69
98
  try {
70
99
  this.#manager.start(cwd, built.session);
71
100
  }
@@ -73,23 +102,59 @@ export class DebugService {
73
102
  await built.session.close().catch(() => undefined);
74
103
  throw err;
75
104
  }
105
+ // This run owns the slot now — the previous run's retained snapshot is
106
+ // superseded (its findings.json stays on disk for the CLI / a human).
107
+ this.#retained = undefined;
76
108
  try {
77
- await built.open();
109
+ await built.open(remaining());
78
110
  built.session.start(built.run);
79
111
  }
80
112
  catch (err) {
81
113
  await this.#manager.end(cwd).catch(() => undefined);
82
114
  throw err;
83
115
  }
84
- await this.#state.record({ sessionId: id, target, goal });
85
- this.#armTimeout(timeoutMs ?? this.#defaultTimeoutMs);
116
+ // Armed BEFORE the breadcrumb write, on what is LEFT of the cap: a throwing
117
+ // StatePort must never leave a live run with no timer on it, and the launch
118
+ // already spent part of the budget.
119
+ this.#armTimeout(remaining());
120
+ try {
121
+ await this.#state.record({ sessionId: id, target, goal });
122
+ }
123
+ catch (err) {
124
+ // The caller gets no session_id back, so nothing could ever end this run —
125
+ // tear it down here (and drop any half-written breadcrumb) and fail loud.
126
+ this.#clearTimeout();
127
+ await this.#manager.end(cwd).catch(() => undefined);
128
+ await this.#state.clear().catch(() => undefined);
129
+ throw err;
130
+ }
86
131
  return { session_id: id };
87
132
  }
88
133
  finally {
89
134
  this.#starting = false;
90
135
  }
91
136
  }
92
- /** Arm the wall-clock cap: auto-end the run when it fires (replaces any prior timer). */
137
+ /**
138
+ * The other half of the one-run gate: another *live* server process holding a
139
+ * run on this project. The manager only sees this process's memory, so without
140
+ * this a second MCP client on the same cwd would launch a second run onto the
141
+ * same profile/emulator and overwrite the live breadcrumb (leaving the CLI
142
+ * pointing at the wrong pid). A dead or PID-recycled owner does not count — a
143
+ * crashed server's stale `running` file must never wedge the project shut.
144
+ */
145
+ async #assertNoForeignRun(cwd) {
146
+ const foreign = await this.#state.foreignRun();
147
+ if (foreign === null)
148
+ return;
149
+ throw new SessionBusyError(`Another ui-debugger-mcp server (pid ${foreign.pid}) already has a debug session ` +
150
+ `('${foreign.sessionId}') active for '${cwd}'. End it (or run 'ui-debugger-mcp stop') ` +
151
+ 'before starting another — one run per project at a time.');
152
+ }
153
+ /**
154
+ * Arm the wall-clock cap on what is LEFT of the run's budget: auto-end the run when
155
+ * it fires (replaces any prior timer). `0` — the launch outlived the whole cap —
156
+ * ends the run on the next tick rather than granting it a fresh one.
157
+ */
93
158
  #armTimeout(ms) {
94
159
  this.#clearTimeout();
95
160
  this.#timer = setTimeout(() => {
@@ -118,12 +183,15 @@ export class DebugService {
118
183
  session.pushMessage(message);
119
184
  return { ok: true, session_id };
120
185
  }
121
- /** Snapshot the run's findings — optionally long-poll (`wait`) and/or project a subset (`fields`). */
186
+ /**
187
+ * Snapshot the run's findings — optionally long-poll (`wait`) and/or project a
188
+ * subset (`fields`). Serves the retained terminal snapshot once the run has
189
+ * auto-ended, so a timed-out run's partial findings stay reachable (the
190
+ * long-poll returns at once: a settled run has nothing left to wait for).
191
+ */
122
192
  async getFindings({ session_id, wait, fields, }) {
123
- const session = this.#require(session_id);
124
- return fields && fields.length > 0
125
- ? session.snapshot(fields, wait)
126
- : session.snapshot(undefined, wait);
193
+ const session = this.#requireReadable(session_id);
194
+ return fields ? session.snapshot(fields, wait) : session.snapshot(undefined, wait);
127
195
  }
128
196
  /** List configured targets (the whole catalog, or one when named) plus resolved models/workspace. */
129
197
  describe({ target }) {
@@ -138,8 +206,15 @@ export class DebugService {
138
206
  workspace: this.#config.workspace,
139
207
  };
140
208
  }
141
- /** End the active run: abort the loop, close the adapter, free the profile lock. */
209
+ /**
210
+ * End the active run: abort the loop, close the adapter, free the profile lock.
211
+ * Ending a run that already auto-ended (timeout / client death) is not an error
212
+ * — it just forgets the retained snapshot, so `end_session` reads the same
213
+ * either way and stays the one explicit forget.
214
+ */
142
215
  async end({ session_id }) {
216
+ if (this.#forgetRetained(session_id))
217
+ return { ok: true, session_id };
143
218
  this.#require(session_id);
144
219
  this.#clearTimeout();
145
220
  // Clear the breadcrumb even when the close throws: the manager frees the slot
@@ -162,6 +237,10 @@ export class DebugService {
162
237
  this.#clearTimeout();
163
238
  if (!this.#manager.has(this.#cwd))
164
239
  return;
240
+ // Nobody asked for this end, so nobody has read the results yet: retain the
241
+ // session (settled + closed) so `get_findings` still serves them. Captured
242
+ // before the close, so even a failing teardown leaves the findings reachable.
243
+ this.#retained = this.#manager.get(this.#cwd);
165
244
  // Same contract as `end()`: the breadcrumb clears even when the close throws.
166
245
  try {
167
246
  await this.#manager.end(this.#cwd);
@@ -170,6 +249,36 @@ export class DebugService {
170
249
  await this.#state.clear();
171
250
  }
172
251
  }
252
+ /**
253
+ * Resolve the session a read names: the active run, or — once the manager is
254
+ * empty — the retained snapshot of the last auto-ended run, so a timed-out run's
255
+ * partial findings stay readable by their id until `end_session` or the next
256
+ * `start_debug`. A different id still fails loud.
257
+ */
258
+ #requireReadable(session_id) {
259
+ const retained = this.#retained;
260
+ if (retained === undefined || this.#manager.has(this.#cwd)) {
261
+ return this.#require(session_id);
262
+ }
263
+ if (retained.id !== session_id) {
264
+ throw new SessionNotFoundError(`No active debug session '${session_id}' for '${this.#cwd}' (the last run '${retained.id}' ` +
265
+ 'has ended; its findings are still readable under that id).');
266
+ }
267
+ return retained;
268
+ }
269
+ /**
270
+ * Forget the retained snapshot when the caller's `end_session` names it — the
271
+ * run is already torn down, so there is nothing left to close. Returns whether
272
+ * the id was the retained one (and it is now forgotten).
273
+ */
274
+ #forgetRetained(session_id) {
275
+ if (this.#manager.has(this.#cwd))
276
+ return false;
277
+ if (this.#retained?.id !== session_id)
278
+ return false;
279
+ this.#retained = undefined;
280
+ return true;
281
+ }
173
282
  /** Resolve the active session for this cwd, asserting its id matches the caller's. */
174
283
  #require(session_id) {
175
284
  const session = this.#manager.get(this.#cwd);
@@ -1 +1 @@
1
- {"version":3,"file":"debug-service.js","sourceRoot":"","sources":["../../src/services/debug-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAItB,OAAO,EAAE,aAAa,EAAkB,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,uFAAuF;AACvF,MAAM,CAAC,MAAM,0BAA0B,GAAG,OAAO,CAAC;AA+FlD,MAAM,OAAO,YAAY;IACd,QAAQ,CAA0B;IAClC,OAAO,CAAiB;IACxB,IAAI,CAAS;IACb,MAAM,CAAiB;IACvB,MAAM,CAAY;IAClB,i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MAAM,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC;IAC/D,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC;IAClE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,qFAAqF;AACrF,SAAS,cAAc,CAAC,IAAY,EAAE,MAAc;IAClD,MAAM,IAAI,GAAe;QACvB,IAAI;QACJ,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;QAC7C,WAAW,EAAE,IAAI;KAClB,CAAC;IACF,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;IACjE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -13,7 +13,7 @@
13
13
  * leaks a launched browser. The builder stays adapter- and model-blind past this
14
14
  * seam; swapping the driver model or the target never touches the service.
15
15
  */
16
- import type { LanguageModel } from 'ai';
16
+ import type { LanguageModel, Tool } from 'ai';
17
17
  import type { ResolvedConfig } from '../config/load.js';
18
18
  import type { Target } from '../config/schema.js';
19
19
  import { type LoopRunner, Session } from '../session/session.js';
@@ -51,13 +51,22 @@ export interface BuildSessionParams {
51
51
  criteria?: string;
52
52
  /** Per-run URL the caller points the driver at (web); overrides the target's configured url. */
53
53
  url?: string;
54
+ /**
55
+ * The run's remaining wall-clock budget (ms) at build time. Assembly happens inside
56
+ * the caller's `timeout`, so the launch/connect wait shortens to fit it.
57
+ */
58
+ timeoutMs?: number;
54
59
  }
55
60
  /** A built-but-unregistered session plus the seams the service fires post-lock. */
56
61
  export interface BuiltSession {
57
62
  /** Ready to register with the manager; not yet opened or started. */
58
63
  session: Session;
59
- /** Navigate the adapter to the target (launches/attaches the browser page). */
60
- open(): Promise<void>;
64
+ /**
65
+ * Navigate the adapter to the target (launches/attaches the browser page).
66
+ * `timeoutMs` is the run's budget left AFTER the build — the first navigation
67
+ * spends the caller's cap, never a fresh one of its own.
68
+ */
69
+ open(timeoutMs?: number): Promise<void>;
61
70
  /** The background loop runner handed to `session.start()`. */
62
71
  run: LoopRunner;
63
72
  }
@@ -65,6 +74,14 @@ export interface BuiltSession {
65
74
  export type SessionBuilder = (params: BuildSessionParams) => Promise<BuiltSession>;
66
75
  /** Bind {@link buildSession} to its shared deps, yielding the per-run {@link SessionBuilder}. */
67
76
  export declare function makeSessionBuilder(deps: SessionBuilderDeps): SessionBuilder;
77
+ /**
78
+ * Wrap a belt tool so every call records its input to `logs/agent.log`, and any
79
+ * thrown error is logged before it propagates — otherwise a belt failure (e.g. a
80
+ * selector that resolves nothing) is invisible: the SDK feeds it back to the model
81
+ * as a tool-error and the run just churns. The wrapper is transparent: same
82
+ * input/output, it only observes.
83
+ */
84
+ export declare function withToolLog(name: string, t: Tool, log: (line: string) => void): Tool;
68
85
  /**
69
86
  * Apply the caller's per-run `url` over the configured target (web only), and
70
87
  * require that a web target ends up with *some* URL. Lets the boss point the