@developerz.ai/ui-debugger-mcp 1.8.0 → 1.10.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 (205) hide show
  1. package/README.md +70 -52
  2. package/dist/adapters/android/adb.d.ts +19 -7
  3. package/dist/adapters/android/adb.js +50 -13
  4. package/dist/adapters/android/adb.js.map +1 -1
  5. package/dist/adapters/android/android-adapter.d.ts +42 -2
  6. package/dist/adapters/android/android-adapter.js +366 -36
  7. package/dist/adapters/android/android-adapter.js.map +1 -1
  8. package/dist/adapters/android/commands.js.map +1 -1
  9. package/dist/adapters/android/ports.js.map +1 -1
  10. package/dist/adapters/android/sdk.d.ts +65 -0
  11. package/dist/adapters/android/sdk.js +107 -0
  12. package/dist/adapters/android/sdk.js.map +1 -0
  13. package/dist/adapters/android/uiautomator.d.ts +23 -7
  14. package/dist/adapters/android/uiautomator.js +31 -7
  15. package/dist/adapters/android/uiautomator.js.map +1 -1
  16. package/dist/adapters/availability.d.ts +39 -0
  17. package/dist/adapters/availability.js +62 -0
  18. package/dist/adapters/availability.js.map +1 -0
  19. package/dist/adapters/browser/browser-adapter.d.ts +12 -22
  20. package/dist/adapters/browser/browser-adapter.js +133 -67
  21. package/dist/adapters/browser/browser-adapter.js.map +1 -1
  22. package/dist/adapters/browser/cdp.d.ts +15 -7
  23. package/dist/adapters/browser/cdp.js +25 -3
  24. package/dist/adapters/browser/cdp.js.map +1 -1
  25. package/dist/adapters/browser/filters.d.ts +1 -1
  26. package/dist/adapters/browser/filters.js.map +1 -1
  27. package/dist/adapters/browser/geometry.js.map +1 -1
  28. package/dist/adapters/browser/launch.d.ts +14 -5
  29. package/dist/adapters/browser/launch.js +14 -5
  30. package/dist/adapters/browser/launch.js.map +1 -1
  31. package/dist/adapters/browser/lifecycle.d.ts +58 -0
  32. package/dist/adapters/browser/lifecycle.js +98 -0
  33. package/dist/adapters/browser/lifecycle.js.map +1 -0
  34. package/dist/adapters/browser/log-filters.d.ts +2 -2
  35. package/dist/adapters/browser/log-filters.js.map +1 -1
  36. package/dist/adapters/browser/log-format.d.ts +14 -23
  37. package/dist/adapters/browser/log-format.js +16 -55
  38. package/dist/adapters/browser/log-format.js.map +1 -1
  39. package/dist/adapters/browser/tab-context.d.ts +30 -0
  40. package/dist/adapters/browser/tab-context.js +41 -0
  41. package/dist/adapters/browser/tab-context.js.map +1 -0
  42. package/dist/adapters/contract.d.ts +111 -5
  43. package/dist/adapters/contract.js +7 -2
  44. package/dist/adapters/contract.js.map +1 -1
  45. package/dist/adapters/desktop/atspi-busctl.d.ts +26 -0
  46. package/dist/adapters/desktop/atspi-busctl.js +330 -0
  47. package/dist/adapters/desktop/atspi-busctl.js.map +1 -0
  48. package/dist/adapters/desktop/atspi-parse.d.ts +39 -0
  49. package/dist/adapters/desktop/atspi-parse.js +155 -0
  50. package/dist/adapters/desktop/atspi-parse.js.map +1 -0
  51. package/dist/adapters/desktop/atspi.d.ts +75 -50
  52. package/dist/adapters/desktop/atspi.js +64 -285
  53. package/dist/adapters/desktop/atspi.js.map +1 -1
  54. package/dist/adapters/desktop/capture.d.ts +11 -20
  55. package/dist/adapters/desktop/capture.js +68 -37
  56. package/dist/adapters/desktop/capture.js.map +1 -1
  57. package/dist/adapters/desktop/desktop-adapter.d.ts +20 -2
  58. package/dist/adapters/desktop/desktop-adapter.js +91 -9
  59. package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
  60. package/dist/adapters/desktop/input.d.ts +18 -4
  61. package/dist/adapters/desktop/input.js +15 -10
  62. package/dist/adapters/desktop/input.js.map +1 -1
  63. package/dist/adapters/desktop/proc.d.ts +32 -4
  64. package/dist/adapters/desktop/proc.js +33 -6
  65. package/dist/adapters/desktop/proc.js.map +1 -1
  66. package/dist/adapters/factory.d.ts +12 -5
  67. package/dist/adapters/factory.js +29 -3
  68. package/dist/adapters/factory.js.map +1 -1
  69. package/dist/adapters/log-format.d.ts +32 -0
  70. package/dist/adapters/log-format.js +39 -0
  71. package/dist/adapters/log-format.js.map +1 -0
  72. package/dist/agent/belt/act.d.ts +440 -21
  73. package/dist/agent/belt/act.js +43 -6
  74. package/dist/agent/belt/act.js.map +1 -1
  75. package/dist/agent/belt/look.d.ts +471 -14
  76. package/dist/agent/belt/look.js +74 -12
  77. package/dist/agent/belt/look.js.map +1 -1
  78. package/dist/agent/belt/observe.d.ts +663 -42
  79. package/dist/agent/belt/observe.js +76 -12
  80. package/dist/agent/belt/observe.js.map +1 -1
  81. package/dist/agent/belt/report.d.ts +754 -48
  82. package/dist/agent/belt/report.js +121 -38
  83. package/dist/agent/belt/report.js.map +1 -1
  84. package/dist/agent/belt/trail.d.ts +44 -16
  85. package/dist/agent/belt/trail.js +46 -11
  86. package/dist/agent/belt/trail.js.map +1 -1
  87. package/dist/agent/capabilities.js.map +1 -1
  88. package/dist/agent/fallback.d.ts +33 -0
  89. package/dist/agent/fallback.js +84 -0
  90. package/dist/agent/fallback.js.map +1 -0
  91. package/dist/agent/loop.d.ts +54 -52
  92. package/dist/agent/loop.js +173 -176
  93. package/dist/agent/loop.js.map +1 -1
  94. package/dist/agent/models.d.ts +10 -6
  95. package/dist/agent/models.js +15 -9
  96. package/dist/agent/models.js.map +1 -1
  97. package/dist/agent/prompts/compose.d.ts +1 -1
  98. package/dist/agent/prompts/debug-agent.js +45 -8
  99. package/dist/agent/prompts/debug-agent.js.map +1 -1
  100. package/dist/agent/prompts/web-addendum.d.ts +1 -1
  101. package/dist/agent/prompts/web-addendum.js +15 -3
  102. package/dist/agent/prompts/web-addendum.js.map +1 -1
  103. package/dist/agent/provider.d.ts +38 -0
  104. package/dist/agent/provider.js +55 -3
  105. package/dist/agent/provider.js.map +1 -1
  106. package/dist/boot.d.ts +64 -0
  107. package/dist/boot.js +145 -0
  108. package/dist/boot.js.map +1 -0
  109. package/dist/cli/chromium-libs.d.ts +262 -0
  110. package/dist/cli/chromium-libs.js +522 -0
  111. package/dist/cli/chromium-libs.js.map +1 -0
  112. package/dist/cli/control.js +51 -9
  113. package/dist/cli/control.js.map +1 -1
  114. package/dist/cli/help.js +1 -1
  115. package/dist/cli/init.d.ts +54 -3
  116. package/dist/cli/init.js +89 -24
  117. package/dist/cli/init.js.map +1 -1
  118. package/dist/config/fingerprint.d.ts +6 -1
  119. package/dist/config/fingerprint.js +8 -4
  120. package/dist/config/fingerprint.js.map +1 -1
  121. package/dist/config/load.d.ts +50 -10
  122. package/dist/config/load.js +93 -27
  123. package/dist/config/load.js.map +1 -1
  124. package/dist/config/schema.d.ts +18 -6
  125. package/dist/config/schema.js +22 -7
  126. package/dist/config/schema.js.map +1 -1
  127. package/dist/errors.d.ts +14 -0
  128. package/dist/errors.js +18 -0
  129. package/dist/errors.js.map +1 -1
  130. package/dist/findings/schema.d.ts +44 -6
  131. package/dist/findings/schema.js +39 -3
  132. package/dist/findings/schema.js.map +1 -1
  133. package/dist/index.d.ts +1 -1
  134. package/dist/index.js +1 -1
  135. package/dist/index.js.map +1 -1
  136. package/dist/main.js +4 -76
  137. package/dist/main.js.map +1 -1
  138. package/dist/mcp/server.js.map +1 -1
  139. package/dist/mcp/tools/describe.d.ts +5 -4
  140. package/dist/mcp/tools/describe.js +14 -10
  141. package/dist/mcp/tools/describe.js.map +1 -1
  142. package/dist/mcp/tools/end-session.d.ts +3 -1
  143. package/dist/mcp/tools/end-session.js +7 -3
  144. package/dist/mcp/tools/end-session.js.map +1 -1
  145. package/dist/mcp/tools/output.d.ts +5 -4
  146. package/dist/mcp/tools/output.js +10 -2
  147. package/dist/mcp/tools/output.js.map +1 -1
  148. package/dist/mcp/tools/result.d.ts +10 -1
  149. package/dist/mcp/tools/result.js +8 -6
  150. package/dist/mcp/tools/result.js.map +1 -1
  151. package/dist/mcp/tools/start-debug.js +7 -5
  152. package/dist/mcp/tools/start-debug.js.map +1 -1
  153. package/dist/redact.d.ts +28 -0
  154. package/dist/redact.js +51 -0
  155. package/dist/redact.js.map +1 -0
  156. package/dist/services/catalog.d.ts +28 -0
  157. package/dist/services/catalog.js +65 -0
  158. package/dist/services/catalog.js.map +1 -0
  159. package/dist/services/debug-api.d.ts +172 -0
  160. package/dist/services/debug-api.js +9 -0
  161. package/dist/services/debug-api.js.map +1 -0
  162. package/dist/services/debug-service.d.ts +25 -173
  163. package/dist/services/debug-service.js +108 -175
  164. package/dist/services/debug-service.js.map +1 -1
  165. package/dist/services/login.d.ts +7 -2
  166. package/dist/services/login.js +210 -10
  167. package/dist/services/login.js.map +1 -1
  168. package/dist/services/retained-snapshot.d.ts +36 -0
  169. package/dist/services/retained-snapshot.js +63 -0
  170. package/dist/services/retained-snapshot.js.map +1 -0
  171. package/dist/services/session-builder.d.ts +26 -0
  172. package/dist/services/session-builder.js +46 -19
  173. package/dist/services/session-builder.js.map +1 -1
  174. package/dist/services/start-guards.d.ts +32 -0
  175. package/dist/services/start-guards.js +50 -0
  176. package/dist/services/start-guards.js.map +1 -0
  177. package/dist/services/summarize.d.ts +12 -3
  178. package/dist/services/summarize.js +13 -5
  179. package/dist/services/summarize.js.map +1 -1
  180. package/dist/session/cleanup.js.map +1 -1
  181. package/dist/session/findings-store.d.ts +2 -1
  182. package/dist/session/findings-store.js +30 -2
  183. package/dist/session/findings-store.js.map +1 -1
  184. package/dist/session/live-pointer.d.ts +19 -0
  185. package/dist/session/live-pointer.js +41 -0
  186. package/dist/session/live-pointer.js.map +1 -0
  187. package/dist/session/manager.d.ts +11 -1
  188. package/dist/session/manager.js +46 -2
  189. package/dist/session/manager.js.map +1 -1
  190. package/dist/session/owner-lock.d.ts +208 -0
  191. package/dist/session/owner-lock.js +499 -0
  192. package/dist/session/owner-lock.js.map +1 -0
  193. package/dist/session/process-identity.js.map +1 -1
  194. package/dist/session/session.js +61 -7
  195. package/dist/session/session.js.map +1 -1
  196. package/dist/session/state-file.d.ts +74 -14
  197. package/dist/session/state-file.js +203 -21
  198. package/dist/session/state-file.js.map +1 -1
  199. package/package.json +7 -7
  200. package/dist/adapters/android/android-adapter.test-helpers.d.ts +0 -52
  201. package/dist/adapters/android/android-adapter.test-helpers.js +0 -115
  202. package/dist/adapters/android/android-adapter.test-helpers.js.map +0 -1
  203. package/dist/mcp/server.test-helpers.d.ts +0 -23
  204. package/dist/mcp/server.test-helpers.js +0 -49
  205. package/dist/mcp/server.test-helpers.js.map +0 -1
@@ -33,6 +33,66 @@ import { capWait } from '../adapters/budget.js';
33
33
  import { AuthError, ConfigError } from '../errors.js';
34
34
  /** Whole-login default budget; the run's remaining cap may only shorten it. */
35
35
  const LOGIN_TIMEOUT_MS = 30_000;
36
+ /**
37
+ * How long ONE observation of the post-submit navigation may wait for the page
38
+ * to SETTLE, before the URL that decides whether the login took is read.
39
+ *
40
+ * A per-observation slice — NOT the cap on the proof. The proof watches the URL
41
+ * across the whole login budget ({@link LOGIN_TIMEOUT_MS}); each observation
42
+ * spends at most this long waiting for the network to go idle before the URL is
43
+ * read again.
44
+ *
45
+ * Why there is a wait at all: the URL read alone can miss a redirect that has
46
+ * been dispatched but has not landed yet, so each observation gives the page a
47
+ * bounded chance to finish its work before the URL is read.
48
+ *
49
+ * Why it is not the CAP: a login whose redirect lands later than this slice — a
50
+ * slow POST, a slow app — used to be read once, at the end of the slice, and
51
+ * reported as a FAILED login, with the credentials blamed for a navigation that
52
+ * had simply not happened yet. The proof now keeps watching instead of reading
53
+ * the URL once and giving up, and a settle wait that TIMES OUT (the page is
54
+ * still working) is not a verdict — it never ends the proof.
55
+ *
56
+ * Five seconds is chosen against what it is waiting for — one redirect hop on an
57
+ * app that has already answered the login POST — not against the runner. A
58
+ * caller with less than that left still shortens it via `capWait`.
59
+ */
60
+ const NAVIGATION_SETTLE_MS = 5_000;
61
+ /**
62
+ * How long the page must be observed IDLE **and UNMOVED** before a settled page
63
+ * that is still on the login page is called a REJECTED login.
64
+ *
65
+ * A settle observation is NOT a verdict, and reading the URL twice back to back
66
+ * is not evidence either: on a page that is already idle, Playwright's
67
+ * network-idle wait resolves INSTANTLY (`browser-adapter.ts`), so an app that
68
+ * answers the login POST and then navigates on a timer —
69
+ * `fetch('/api/login')` and `setTimeout(() => location.href = '/dashboard', 1000)`
70
+ * — is idle while its redirect is still PENDING. Blaming the credentials for
71
+ * that was wrong: nothing about them was.
72
+ *
73
+ * So the page has to STAY idle, and stay on the login page, for this long
74
+ * before the proof concludes the login was rejected. It bounds how long a
75
+ * redirect may sit PENDING: the navigation is dispatched, and if it has not
76
+ * fired within this window it is not going to.
77
+ *
78
+ * Two seconds is twice the delay of the case this exists for (a one-second
79
+ * timer), and it stays UNDER the settle slice — so a wrong password is still
80
+ * reported in seconds, faster than the fixed slice it replaced, and a rejected
81
+ * login never costs the whole budget.
82
+ *
83
+ * It is bounded by what is LEFT of the login's budget: a caller with less
84
+ * budget gets a shorter window, and a budget that runs out first ends the
85
+ * proof through the other diagnostic.
86
+ */
87
+ const SETTLE_CONFIRM_MS = 2_000;
88
+ /** Gap between two URL observations while the proof waits for a redirect to land. */
89
+ const OBSERVATION_INTERVAL_MS = 250;
90
+ /** Local sleep — the repo has no shared timer helper. */
91
+ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
92
+ /** The ms left before `deadline`, never negative — `capWait` rejects a negative budget. */
93
+ function remainingMs(deadline) {
94
+ return Math.max(0, deadline - Date.now());
95
+ }
36
96
  /**
37
97
  * Resolve `start_debug({as})` against the target's configured personas.
38
98
  *
@@ -119,10 +179,17 @@ export async function performLogin(adapter, options) {
119
179
  const { name, persona, loginUrl, timeoutMs } = options;
120
180
  const log = options.log ?? (() => undefined);
121
181
  const budget = capWait(LOGIN_TIMEOUT_MS, timeoutMs);
182
+ /**
183
+ * ONE deadline for the WHOLE login, taken before the first byte is spent:
184
+ * opening the page, filling the fields and submitting all come out of the
185
+ * same budget as the URL watch. A watch window that started fresh AFTER the
186
+ * submit would let the login overrun the cap it was handed.
187
+ */
188
+ const deadline = Date.now() + budget;
122
189
  const steps = [];
123
190
  /** Marks every step here as the pre-run login, not something the driver chose. */
124
191
  const note = `auth persona ${JSON.stringify(name)} — signed in before the run's first step`;
125
- log(`auth: signing in as ${JSON.stringify(name)} at ${loginUrl}`);
192
+ await log(`auth: signing in as ${JSON.stringify(name)} at ${loginUrl}`);
126
193
  await adapter.open(loginUrl, budget);
127
194
  steps.push({ step: `open ${loginUrl}`, ok: true, note });
128
195
  for (const [key, value] of Object.entries(persona.fields)) {
@@ -149,11 +216,11 @@ export async function performLogin(adapter, options) {
149
216
  }
150
217
  await adapter.click(submit);
151
218
  steps.push({ step: `click submit "${persona.submit}"`, ok: true, note });
152
- await assertSignedIn(adapter, options, budget);
219
+ await assertSignedIn(adapter, options, budget, deadline);
153
220
  // Where the login LANDED, not where the run was configured to start: submitting
154
221
  // usually redirects, so this is the page the driver's first step actually reads.
155
222
  const landed = await currentUrl(adapter);
156
- log(`auth: signed in as ${JSON.stringify(name)}${landed ? ` → ${landed}` : ''}`);
223
+ await log(`auth: signed in as ${JSON.stringify(name)}${landed ? ` → ${landed}` : ''}`);
157
224
  steps.push({ step: `signed in as "${name}"${landed ? ` → ${landed}` : ''}`, ok: true, note });
158
225
  return steps;
159
226
  }
@@ -161,11 +228,45 @@ export async function performLogin(adapter, options) {
161
228
  * Prove the login took, or fail loud. `expect` is the explicit proof; without one
162
229
  * the run requires that submitting LEFT the login page — a real signal, and the
163
230
  * error says how to replace it for an app that signs in without navigating.
231
+ *
232
+ * Without `expect` the proof WATCHES the active tab's URL across the whole
233
+ * login budget instead of reading it once after a fixed settle slice: a valid
234
+ * login whose redirect lands later than that slice used to be reported as a
235
+ * failed login, with the credentials blamed for a navigation that had simply
236
+ * not happened yet.
237
+ *
238
+ * A settled observation is not a verdict by itself. It only says the page
239
+ * finished its work — a redirect can be dispatched and still PENDING, and on
240
+ * an already-idle page the settle wait returns INSTANTLY, so two back-to-back
241
+ * reads prove nothing. The settled rejection therefore needs the page to stay
242
+ * idle AND unmoved for {@link SETTLE_CONFIRM_MS}; a redirect that lands inside
243
+ * that window is the login taking, not a rejected login.
244
+ *
245
+ * Two failures, and they say different things because the MEASUREMENTS differ:
246
+ *
247
+ * - **settled rejection** — the page was idle AND unmoved on the login page
248
+ * for its whole confirmation window, and that evidence was still CURRENT
249
+ * when the proof ended. The app finished its work and did not navigate: the
250
+ * login did not take, and the credentials are the first thing to check.
251
+ * - **unresolved proof** — the budget ran out without that evidence: the page
252
+ * never went idle, or it went idle once and went BUSY again (the app is
253
+ * still working — a quiet streak the page later voided is not evidence).
254
+ * The navigation may still have been in flight; nothing measured here
255
+ * implicates the credentials, so the error says that instead of guessing.
256
+ *
257
+ * Before either diagnostic, the URL is read ONE more time: the loop's last act
258
+ * is a sleep, and a redirect landing inside that final slice is a successful
259
+ * login the loop would otherwise never see.
164
260
  */
165
- async function assertSignedIn(adapter, { name, persona, loginUrl }, budget) {
261
+ async function assertSignedIn(adapter, { name, persona, loginUrl }, budget, deadline) {
166
262
  if (persona.expect !== undefined) {
167
263
  try {
168
- await adapter.waitFor({ query: persona.expect, timeout: budget });
264
+ // The SAME deadline as the URL watch: the whole login shares one budget,
265
+ // so `expect` waits on what is LEFT of it, never on a fresh one.
266
+ await adapter.waitFor({
267
+ query: persona.expect,
268
+ timeout: capWait(budget, remainingMs(deadline)),
269
+ });
169
270
  }
170
271
  catch (error) {
171
272
  throw new AuthError(`auth persona '${name}': submitted the form but '${persona.expect}' never appeared — ` +
@@ -174,17 +275,116 @@ async function assertSignedIn(adapter, { name, persona, loginUrl }, budget) {
174
275
  }
175
276
  return;
176
277
  }
177
- await adapter.waitFor({ networkIdle: true, timeout: budget }).catch(() => undefined);
178
- const after = await currentUrl(adapter);
179
- if (after === null) {
278
+ // A target with no tab concept cannot answer "did the page move?", and there
279
+ // is no `expect` to fall back on. Say so before spending a wait on it.
280
+ if (!adapter.tabs) {
180
281
  throw new AuthError(`auth persona '${name}': this target cannot report its current location, so the login ` +
181
282
  "cannot be verified — set 'expect' on the persona to a selector that only exists once signed in.");
182
283
  }
183
- if (samePage(after, loginUrl)) {
184
- throw new AuthError(`auth persona '${name}': still on ${after} after submitting '${persona.submit}' — the login ` +
284
+ /** The URL the last observation saw — the one a failure names. */
285
+ let lastUrl = loginUrl;
286
+ /**
287
+ * Whether the page's quiet streak is CURRENTLY intact: idle AND unmoved on
288
+ * the last observation, and not since invalidated by a busy one. A settled
289
+ * observation sets it; a busy one voids it — the app went back to work, so
290
+ * its earlier quiet is no longer evidence of anything.
291
+ */
292
+ let quiet = false;
293
+ /**
294
+ * When the current quiet streak began, or 0 when the page is not quiet. A
295
+ * page that goes busy again resets it: the app is still working, so the
296
+ * streak starts over.
297
+ */
298
+ let quietSince = 0;
299
+ /** How long the page must stay quiet before the credentials are blamed. */
300
+ let quietWindow = 0;
301
+ for (;;) {
302
+ const remaining = deadline - Date.now();
303
+ if (remaining <= 0)
304
+ break;
305
+ // One observation: give the page a bounded slice to settle. A REJECTED wait
306
+ // is not a verdict — it only says the page is still working (the POST is in
307
+ // flight, the redirect has not fired) — so the watch continues.
308
+ let settled = false;
309
+ try {
310
+ await adapter.waitFor({
311
+ networkIdle: true,
312
+ timeout: capWait(NAVIGATION_SETTLE_MS, remaining),
313
+ });
314
+ settled = true;
315
+ }
316
+ catch {
317
+ // not idle within the slice — keep watching
318
+ }
319
+ // The URL is what decides, and it is read after EVERY observation — settled
320
+ // or not. That is the whole fix: a redirect that lands late is still seen.
321
+ const after = await currentUrl(adapter);
322
+ if (after === null) {
323
+ throw new AuthError(`auth persona '${name}': this target cannot report its current location, so the login ` +
324
+ "cannot be verified — set 'expect' on the persona to a selector that only exists once signed in.");
325
+ }
326
+ lastUrl = after;
327
+ // The URL left the login page: the login took.
328
+ if (!samePage(after, loginUrl))
329
+ return;
330
+ if (!settled) {
331
+ // The page went busy again (or never settled): it is WORKING, not
332
+ // rejecting. Any quiet streak is void — a redirect may be on its way.
333
+ quietSince = 0;
334
+ quiet = false;
335
+ }
336
+ else {
337
+ quiet = true;
338
+ if (quietSince === 0) {
339
+ // The page just went quiet for the first time (or after being busy).
340
+ // How long it must STAY quiet is bounded by what is left of the budget
341
+ // AT THE MOMENT it went quiet — measured from the stamp, not from the
342
+ // start of the observation (the settle wait and the URL read already
343
+ // spent a slice of it): a caller with less budget gets a shorter
344
+ // window, and a budget that runs out first ends the proof through the
345
+ // other diagnostic.
346
+ quietSince = Date.now();
347
+ quietWindow = Math.min(SETTLE_CONFIRM_MS, Math.max(1, deadline - quietSince));
348
+ }
349
+ // The page is idle and has not moved. That is STILL not a rejection: the
350
+ // redirect can be pending (the app answered the login POST and will
351
+ // navigate on a timer). Only a page that stays idle AND unmoved for the
352
+ // whole quiet window is a rejected login — and a redirect that lands
353
+ // inside that window is the login taking.
354
+ if (Date.now() - quietSince >= quietWindow) {
355
+ throw new AuthError(`auth persona '${name}': still on ${after} after submitting '${persona.submit}' — the login ` +
356
+ 'did not take. Check the credentials and the field keys; if this app signs in WITHOUT ' +
357
+ "navigating away, set 'expect' on the persona to a selector that only exists once signed in.");
358
+ }
359
+ }
360
+ // Sleep only as long as the budget still allows: a fixed gap would carry
361
+ // the login PAST the caller's cap, which is the very overrun the shared
362
+ // deadline exists to prevent.
363
+ await delay(Math.min(OBSERVATION_INTERVAL_MS, remainingMs(deadline)));
364
+ }
365
+ // The budget ran out — but the loop's last act was a SLEEP, not a read, and
366
+ // the redirect can land inside it (a 275ms redirect on a 300ms budget lands
367
+ // between the last observation and this line). The URL is what decides, so
368
+ // read it once more before reporting anything.
369
+ const finalUrl = await currentUrl(adapter);
370
+ if (finalUrl !== null && !samePage(finalUrl, loginUrl))
371
+ return;
372
+ // Still on the login page. Which failure this is depends on what was
373
+ // MEASURED AT THE END, not on what was measured at any point before: only a
374
+ // quiet streak that is still INTACT and has held for its whole window is a
375
+ // confirmed rejection. A streak the page later invalidated — it went busy
376
+ // again and was still working when the budget ran out — proves nothing about
377
+ // the credentials, so it gets the unresolved diagnostic instead.
378
+ if (quiet && Date.now() - quietSince >= quietWindow) {
379
+ throw new AuthError(`auth persona '${name}': still on ${lastUrl} after submitting '${persona.submit}' — the login ` +
185
380
  'did not take. Check the credentials and the field keys; if this app signs in WITHOUT ' +
186
381
  "navigating away, set 'expect' on the persona to a selector that only exists once signed in.");
187
382
  }
383
+ throw new AuthError(`auth persona '${name}': still on ${lastUrl} after ${budget}ms — the login budget was exhausted ` +
384
+ 'without a settled-and-unmoved page to conclude from (the navigation never settled, or it ' +
385
+ 'settled and the page went busy again before the budget ran out), so the proof could not be ' +
386
+ 'completed. Nothing measured here says why the page did not leave the login page. ' +
387
+ "Raise the run's timeout, or set 'expect' on the persona to a selector that only exists once signed in.");
188
388
  }
189
389
  /** Same origin + same path — the query/hash a login flow adds (`?error=1`) does not make it a new page. */
190
390
  export function samePage(a, b) {
@@ -1 +1 @@
1
- {"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/services/login.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGtD,+EAA+E;AAC/E,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAShC;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,MAAc,EACd,UAAkB,EAClB,EAAsB;IAEtB,IAAI,EAAE,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACvC,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,IAAI,WAAW,CACnB,yDAAyD,UAAU,SAAS,MAAM,CAAC,OAAO,GAAG,CAC9F,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IACzB,iFAAiF;IACjF,iFAAiF;IACjF,MAAM,OAAO,GAAG,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACvE,IAAI,OAAO;QAAE,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B,IAAI,eAAe,OAAO,UAAU,MAAM,sCAAsC;QAC/F,2FAA2F;QAC3F,6FAA6F;QAC7F,mFAAmF;QACnF,wGAAwG,CAC3G,CAAC;AACJ,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,QAAQ,CAAC,CAAS,EAAE,CAAS;IAC3C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,CAAC;IAC1E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;AACH,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The retained snapshot — the last run that ended WITHOUT the caller asking.
3
+ *
4
+ * A run that auto-ends (wall-clock timeout, SIGTERM, the MCP client dying) is
5
+ * torn down, but its findings must not vanish with it: the settled session is
6
+ * kept so `get_findings` still serves its terminal snapshot and `describe` can
7
+ * still name it. `end_session` is the explicit forget; the next `start_debug`
8
+ * supersedes it.
9
+ *
10
+ * Split out of `debug-service.ts` to keep that file under the 500-LOC cap. The
11
+ * slot is deliberately NOT a gate: a retained snapshot never blocks a start and
12
+ * never takes new work — the one-run rule stays with the manager.
13
+ */
14
+ import type { Session } from '../session/session.js';
15
+ /** The retained slot: one settled run, kept readable until it is forgotten. */
16
+ export declare class RetainedSnapshot {
17
+ #private;
18
+ /** Keep `session` as the retained snapshot — the run that auto-ended. */
19
+ retain(session: Session): void;
20
+ /** Forget the retained snapshot (the explicit `end_session` forget, or a superseding run). */
21
+ clear(): void;
22
+ /** The retained snapshot, or `undefined` when there is none. */
23
+ peek(): Session | undefined;
24
+ /**
25
+ * Forget the snapshot when `sessionId` names it — the run is already torn down,
26
+ * so there is nothing left to close. Returns whether the id WAS the retained one
27
+ * (and it is now forgotten).
28
+ */
29
+ forget(sessionId: string): boolean;
30
+ /**
31
+ * The session a read names among the retained ones: the retained run itself, or
32
+ * a loud miss that names the run that IS readable — a caller holding a stale id
33
+ * must not be told the findings are gone when they are one id away.
34
+ */
35
+ requireRetained(sessionId: string, cwd: string): Session;
36
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * The retained snapshot — the last run that ended WITHOUT the caller asking.
3
+ *
4
+ * A run that auto-ends (wall-clock timeout, SIGTERM, the MCP client dying) is
5
+ * torn down, but its findings must not vanish with it: the settled session is
6
+ * kept so `get_findings` still serves its terminal snapshot and `describe` can
7
+ * still name it. `end_session` is the explicit forget; the next `start_debug`
8
+ * supersedes it.
9
+ *
10
+ * Split out of `debug-service.ts` to keep that file under the 500-LOC cap. The
11
+ * slot is deliberately NOT a gate: a retained snapshot never blocks a start and
12
+ * never takes new work — the one-run rule stays with the manager.
13
+ */
14
+ import { SessionNotFoundError } from '../errors.js';
15
+ /** The retained slot: one settled run, kept readable until it is forgotten. */
16
+ export class RetainedSnapshot {
17
+ /**
18
+ * The last run that auto-ended (timeout / SIGTERM / client death), kept settled
19
+ * and closed so `get_findings` can still read its partial findings + evidence.
20
+ * Dropped by `end_session` (the explicit forget) and superseded by the next run.
21
+ */
22
+ #session;
23
+ /** Keep `session` as the retained snapshot — the run that auto-ended. */
24
+ retain(session) {
25
+ this.#session = session;
26
+ }
27
+ /** Forget the retained snapshot (the explicit `end_session` forget, or a superseding run). */
28
+ clear() {
29
+ this.#session = undefined;
30
+ }
31
+ /** The retained snapshot, or `undefined` when there is none. */
32
+ peek() {
33
+ return this.#session;
34
+ }
35
+ /**
36
+ * Forget the snapshot when `sessionId` names it — the run is already torn down,
37
+ * so there is nothing left to close. Returns whether the id WAS the retained one
38
+ * (and it is now forgotten).
39
+ */
40
+ forget(sessionId) {
41
+ if (this.#session?.id !== sessionId)
42
+ return false;
43
+ this.#session = undefined;
44
+ return true;
45
+ }
46
+ /**
47
+ * The session a read names among the retained ones: the retained run itself, or
48
+ * a loud miss that names the run that IS readable — a caller holding a stale id
49
+ * must not be told the findings are gone when they are one id away.
50
+ */
51
+ requireRetained(sessionId, cwd) {
52
+ const retained = this.#session;
53
+ if (retained === undefined) {
54
+ throw new SessionNotFoundError(`No active debug session '${sessionId}' for '${cwd}'.`);
55
+ }
56
+ if (retained.id !== sessionId) {
57
+ throw new SessionNotFoundError(`No active debug session '${sessionId}' for '${cwd}' (the last run '${retained.id}' ` +
58
+ 'has ended; its findings are still readable under that id).');
59
+ }
60
+ return retained;
61
+ }
62
+ }
63
+ //# sourceMappingURL=retained-snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retained-snapshot.js","sourceRoot":"","sources":["../../src/services/retained-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGpD,+EAA+E;AAC/E,MAAM,OAAO,gBAAgB;IAC3B;;;;OAIG;IACH,QAAQ,CAAsB;IAE9B,yEAAyE;IACzE,MAAM,CAAC,OAAgB;QACrB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,8FAA8F;IAC9F,KAAK;QACH,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,gEAAgE;IAChE,IAAI;QACF,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAiB;QACtB,IAAI,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,eAAe,CAAC,SAAiB,EAAE,GAAW;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,IAAI,oBAAoB,CAAC,4BAA4B,SAAS,UAAU,GAAG,IAAI,CAAC,CAAC;QACzF,CAAC;QACD,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,IAAI,oBAAoB,CAC5B,4BAA4B,SAAS,UAAU,GAAG,oBAAoB,QAAQ,CAAC,EAAE,IAAI;gBACnF,4DAA4D,CAC/D,CAAC;QACJ,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
@@ -14,8 +14,11 @@
14
14
  * seam; swapping the driver model or the target never touches the service.
15
15
  */
16
16
  import type { LanguageModel, Tool } from 'ai';
17
+ import type { CaptureSink } from '../adapters/browser/cdp.js';
18
+ import { createAdapter } from '../adapters/factory.js';
17
19
  import type { ResolvedConfig } from '../config/load.js';
18
20
  import type { Target } from '../config/schema.js';
21
+ import { FindingsStore } from '../session/findings-store.js';
19
22
  import { type LoopRunner, Session } from '../session/session.js';
20
23
  import { type WorkspacePaths } from '../session/workspace.js';
21
24
  /** The three actors the belt + loop + post-verdict step bind to, resolved once and shared across runs. */
@@ -38,6 +41,16 @@ export interface SessionBuilderDeps {
38
41
  config: ResolvedConfig;
39
42
  models: BuilderModels;
40
43
  workspace: WorkspacePaths;
44
+ /**
45
+ * Adapter factory seam — the default is the real one ({@link createAdapter}),
46
+ * so every production caller is unchanged.
47
+ *
48
+ * A test injects a fake here to build a WEB target's session without a
49
+ * browser: `createAdapter` for a browser target LAUNCHES a headless Chromium,
50
+ * so asserting on what the builder wrote to disk used to need a browser
51
+ * binary on the machine.
52
+ */
53
+ createAdapter?: typeof createAdapter;
41
54
  }
42
55
  /** The per-run inputs `start_debug` hands over. */
43
56
  export interface BuildSessionParams {
@@ -85,6 +98,19 @@ export declare function makeSessionBuilder(deps: SessionBuilderDeps): SessionBui
85
98
  * input/output, it only observes.
86
99
  */
87
100
  export declare function withToolLog(name: string, t: Tool, log: (line: string) => void): Tool;
101
+ /**
102
+ * The run's durable capture sink: redact, THEN append to the session's log channel.
103
+ *
104
+ * One writer for every captured row, whoever produced it — the browser's CDP
105
+ * capture (console + network) and the android logcat drain alike. The adapters
106
+ * never touch disk; they hand lines to this seam and the session decides what
107
+ * lands in `logs/*.log`. Redaction happens HERE, on the way in, so no second
108
+ * (unredacted) path to the trail can exist.
109
+ *
110
+ * Fire-and-forget by design: a capture burst must never block the adapter that
111
+ * produced it, and a failed write must never fail the read that produced it.
112
+ */
113
+ export declare function createCaptureSink(store: FindingsStore, redact: (line: string) => string): CaptureSink;
88
114
  /**
89
115
  * Apply the caller's per-run `url` over the configured target (web only), and
90
116
  * require that a web target ends up with *some* URL. Lets the boss point the
@@ -15,7 +15,6 @@
15
15
  */
16
16
  import { mkdir, writeFile } from 'node:fs/promises';
17
17
  import { resolveTargetUrl } from '../adapters/browser/launch.js';
18
- import { createSecretRedactor } from '../adapters/browser/log-format.js';
19
18
  import { createAdapter } from '../adapters/factory.js';
20
19
  import { createActTool } from '../agent/belt/act.js';
21
20
  import { createLookTool, createSelfLookTool } from '../agent/belt/look.js';
@@ -25,6 +24,7 @@ import { createActTrail } from '../agent/belt/trail.js';
25
24
  import { createDebugAgent, runDebugLoop } from '../agent/loop.js';
26
25
  import { composeSystemPrompt } from '../agent/prompts/compose.js';
27
26
  import { ConfigError, TargetNotFoundError } from '../errors.js';
27
+ import { createSecretRedactor } from '../redact.js';
28
28
  import { pruneSessions, SESSION_RETENTION } from '../session/cleanup.js';
29
29
  import { FindingsStore } from '../session/findings-store.js';
30
30
  import { Session } from '../session/session.js';
@@ -71,6 +71,23 @@ export function withToolLog(name, t, log) {
71
71
  },
72
72
  };
73
73
  }
74
+ /**
75
+ * The run's durable capture sink: redact, THEN append to the session's log channel.
76
+ *
77
+ * One writer for every captured row, whoever produced it — the browser's CDP
78
+ * capture (console + network) and the android logcat drain alike. The adapters
79
+ * never touch disk; they hand lines to this seam and the session decides what
80
+ * lands in `logs/*.log`. Redaction happens HERE, on the way in, so no second
81
+ * (unredacted) path to the trail can exist.
82
+ *
83
+ * Fire-and-forget by design: a capture burst must never block the adapter that
84
+ * produced it, and a failed write must never fail the read that produced it.
85
+ */
86
+ export function createCaptureSink(store, redact) {
87
+ return (channel, line) => {
88
+ void store.appendLog(channel, redact(line)).catch(() => undefined);
89
+ };
90
+ }
74
91
  /** Map a config adapter kind to its prompt addendum target — one per shipped adapter. */
75
92
  function addendumTarget(adapter) {
76
93
  if (adapter === 'browser')
@@ -191,18 +208,21 @@ export async function buildSession(deps, params) {
191
208
  // run's dir even if the clock moved backwards since the previous one.
192
209
  await pruneSessions(workspace, { keep: SESSION_RETENTION, protect: id });
193
210
  const criteriaLines = splitLines(criteria);
211
+ const notes = splitLines(targetConfig.notes);
194
212
  const address = openAddress(targetConfig);
195
213
  const origin = runOrigin(targetConfig);
196
214
  await writeFile(paths.storyMd, renderStoryMd(target, address, goal, criteriaLines), 'utf8');
197
- const store = new FindingsStore(paths);
198
- // Bound once, applied to EVERY durable log line this run writes. A persona's
215
+ // Bound once, applied to findings text and EVERY durable log line. A persona's
199
216
  // values are typed into the app, so they come back at us through the form POST
200
217
  // in `network.log` and through anything an adapter error quotes — the same
201
218
  // posture `log-format.ts` already holds for credential headers and `?token=`.
202
219
  const redact = createSecretRedactor(auth ? Object.values(auth.persona.fields) : []);
203
- const onLog = (channel, line) => {
204
- void store.appendLog(channel, redact(line)).catch(() => undefined);
205
- };
220
+ // The store redacts findings TEXT on write; the sink redacts every captured
221
+ // row on its way in — one writer, one redaction gate.
222
+ const store = new FindingsStore(paths, redact);
223
+ // The run's ONE capture sink — the browser's CDP capture and the android logcat
224
+ // drain both stream into it, so every captured row is redacted on its way to disk.
225
+ const onLog = createCaptureSink(store, redact);
206
226
  // `profile` is a browser-target key — no other adapter has a profile dir. A managed
207
227
  // launch lives in it; attach ignores it (that browser keeps its own state).
208
228
  // `ensureWorkspace` pre-creates only the default dir, so a custom one is made here.
@@ -210,7 +230,11 @@ export async function buildSession(deps, params) {
210
230
  const profileDir = resolveProfileDir(workspace, profile);
211
231
  if (profile)
212
232
  await mkdir(profileDir, { recursive: true });
213
- const adapter = await createAdapter(target, effectiveConfig, profileDir, onLog, params.timeoutMs);
233
+ // The adapter factory seam: the real factory by default, a fake in tests that
234
+ // only care about what the builder WROTE (a web target's story.md) and not
235
+ // about the browser that would drive it.
236
+ const factory = deps.createAdapter ?? createAdapter;
237
+ const adapter = await factory(target, effectiveConfig, profileDir, onLog, params.timeoutMs);
214
238
  // The prompt's eye mode MUST match the `look` tool bound below — self-look tells
215
239
  // the driver to judge the attached frame itself; the vision variant tells it to ask
216
240
  // the vision guy (and how to cope when that model turns out to be text-only).
@@ -226,7 +250,7 @@ export async function buildSession(deps, params) {
226
250
  // The target's standing preconditions: config-level, so they are stated once
227
251
  // here instead of re-pasted into every `goal`. Length is capped at the config
228
252
  // boundary — this section rides along on every step.
229
- notes: splitLines(targetConfig.notes),
253
+ notes,
230
254
  });
231
255
  const appendAgentLog = (line) => store.appendLog('agent', redact(`${new Date().toISOString()} ${line}`));
232
256
  // High-frequency, fire-and-forget: the agent's own log sink + per-step tool logs.
@@ -244,12 +268,14 @@ export async function buildSession(deps, params) {
244
268
  // best-effort: logging must never break or mask the run
245
269
  }
246
270
  };
247
- // One trail per run, shared between the `act` tool (which records every step as
248
- // it finishes, `ok: false` included), the loop (which snapshots it into each
249
- // running flush) and the `report` tool (which merges it with the driver's
250
- // reported steps), so the persisted findings and the returned counts derive from
251
- // the same object. `report` reads it through `settled()`, so an act racing it in
252
- // the SAME step still makes the verdict.
271
+ // One evidence trail per run, shared between the belt's tools (which record
272
+ // into it as they run: `act` records every step, `look` each flagged visual
273
+ // issue, `observe` each error-level console row — deduped, at tool time), the
274
+ // loop (which snapshots all three streams into each running flush) and the
275
+ // `report` tool (which merges all three with the driver's verdict), so the
276
+ // persisted findings and the returned counts derive from the same object.
277
+ // `report` reads it through `settled()`, so evidence gathered in the SAME step
278
+ // still makes the verdict.
253
279
  //
254
280
  // Built HERE rather than inside `run` because the pre-run login (`open`, below)
255
281
  // happens first and has to land on the same trail: the driver did not do it, but
@@ -259,18 +285,18 @@ export async function buildSession(deps, params) {
259
285
  const agent = createDebugAgent({
260
286
  model: models.driver,
261
287
  tools: {
262
- observe: withToolLog('observe', createObserveTool(adapter, store), logAgent),
288
+ observe: withToolLog('observe', createObserveTool(adapter, store, trail, redact), logAgent),
263
289
  act: withToolLog('act', createActTool(adapter, store, trail, origin), logAgent),
264
290
  look: withToolLog('look', selfLook
265
291
  ? createSelfLookTool(adapter, store)
266
- : createLookTool(adapter, models.vision, store), logAgent),
292
+ : createLookTool(adapter, models.vision, store, trail, notes), logAgent),
267
293
  report: withToolLog('report', createReportTool(store, () => trail.settled()), logAgent),
268
294
  },
269
295
  instructions,
270
296
  inbox,
271
297
  progress,
272
298
  log: logAgent,
273
- trail: trail.steps,
299
+ trail,
274
300
  });
275
301
  await flushAgentLog(`run start: target=${target} goal=${JSON.stringify(goal)}`);
276
302
  try {
@@ -297,7 +323,7 @@ export async function buildSession(deps, params) {
297
323
  findingsStore: store,
298
324
  // Post-verdict seam: fills `findings.summary` over the summary model when the
299
325
  // driver left it empty (best-effort; the session wraps it fail-soft).
300
- summarize: createSummarize(models.summary),
326
+ summarize: createSummarize(models.summary, redact),
301
327
  // Post-verdict seam: stitches the ordered screenshots into a captioned
302
328
  // `replay.mp4` (ffmpeg) and records its path in `findings.evidence` for the PR.
303
329
  // `log` surfaces an absent ffmpeg loud in `agent.log`; the step skips, never crashes.
@@ -312,7 +338,8 @@ export async function buildSession(deps, params) {
312
338
  // Out-of-band and BEFORE the loop: the driver never sees the credentials, and
313
339
  // a login that cannot complete fails `start_debug` outright instead of handing
314
340
  // back a run that will report every screen behind it as empty. See `login.ts`.
315
- const steps = await signIn(adapter, auth, targetConfig, logAgent, timeoutMs);
341
+ // Login awaits this sink so open() returns with its auth trail durable.
342
+ const steps = await signIn(adapter, auth, targetConfig, flushAgentLog, timeoutMs);
316
343
  for (const step of steps)
317
344
  trail.record(step);
318
345
  },