@developerz.ai/ui-debugger-mcp 1.9.0 → 1.11.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 (274) hide show
  1. package/README.md +63 -47
  2. package/dist/adapters/android/abortable.d.ts +6 -0
  3. package/dist/adapters/android/abortable.js +22 -0
  4. package/dist/adapters/android/abortable.js.map +1 -0
  5. package/dist/adapters/android/adb.d.ts +19 -7
  6. package/dist/adapters/android/adb.js +50 -13
  7. package/dist/adapters/android/adb.js.map +1 -1
  8. package/dist/adapters/android/android-adapter.d.ts +20 -12
  9. package/dist/adapters/android/android-adapter.js +113 -165
  10. package/dist/adapters/android/android-adapter.js.map +1 -1
  11. package/dist/adapters/android/commands.d.ts +10 -0
  12. package/dist/adapters/android/commands.js +22 -0
  13. package/dist/adapters/android/commands.js.map +1 -1
  14. package/dist/adapters/android/emulator.d.ts +41 -0
  15. package/dist/adapters/android/emulator.js +115 -0
  16. package/dist/adapters/android/emulator.js.map +1 -0
  17. package/dist/adapters/android/logcat.d.ts +87 -0
  18. package/dist/adapters/android/logcat.js +352 -0
  19. package/dist/adapters/android/logcat.js.map +1 -0
  20. package/dist/adapters/android/ports.js.map +1 -1
  21. package/dist/adapters/android/sdk.d.ts +65 -0
  22. package/dist/adapters/android/sdk.js +107 -0
  23. package/dist/adapters/android/sdk.js.map +1 -0
  24. package/dist/adapters/android/uiautomator.d.ts +23 -7
  25. package/dist/adapters/android/uiautomator.js +31 -7
  26. package/dist/adapters/android/uiautomator.js.map +1 -1
  27. package/dist/adapters/availability.d.ts +39 -0
  28. package/dist/adapters/availability.js +62 -0
  29. package/dist/adapters/availability.js.map +1 -0
  30. package/dist/adapters/browser/browser-adapter.d.ts +11 -22
  31. package/dist/adapters/browser/browser-adapter.js +90 -71
  32. package/dist/adapters/browser/browser-adapter.js.map +1 -1
  33. package/dist/adapters/browser/cdp.d.ts +22 -17
  34. package/dist/adapters/browser/cdp.js +118 -72
  35. package/dist/adapters/browser/cdp.js.map +1 -1
  36. package/dist/adapters/browser/exchange-read.d.ts +39 -0
  37. package/dist/adapters/browser/exchange-read.js +102 -0
  38. package/dist/adapters/browser/exchange-read.js.map +1 -0
  39. package/dist/adapters/browser/extractor.js +9 -2
  40. package/dist/adapters/browser/extractor.js.map +1 -1
  41. package/dist/adapters/browser/filters.d.ts +1 -1
  42. package/dist/adapters/browser/filters.js.map +1 -1
  43. package/dist/adapters/browser/geometry.js.map +1 -1
  44. package/dist/adapters/browser/launch.d.ts +14 -5
  45. package/dist/adapters/browser/launch.js +14 -5
  46. package/dist/adapters/browser/launch.js.map +1 -1
  47. package/dist/adapters/browser/lifecycle.d.ts +91 -0
  48. package/dist/adapters/browser/lifecycle.js +141 -0
  49. package/dist/adapters/browser/lifecycle.js.map +1 -0
  50. package/dist/adapters/browser/locate.d.ts +18 -2
  51. package/dist/adapters/browser/locate.js +48 -3
  52. package/dist/adapters/browser/locate.js.map +1 -1
  53. package/dist/adapters/browser/log-filters.d.ts +2 -2
  54. package/dist/adapters/browser/log-filters.js +15 -4
  55. package/dist/adapters/browser/log-filters.js.map +1 -1
  56. package/dist/adapters/browser/log-format.d.ts +23 -20
  57. package/dist/adapters/browser/log-format.js +133 -56
  58. package/dist/adapters/browser/log-format.js.map +1 -1
  59. package/dist/adapters/browser/tab-context.d.ts +30 -0
  60. package/dist/adapters/browser/tab-context.js +41 -0
  61. package/dist/adapters/browser/tab-context.js.map +1 -0
  62. package/dist/adapters/contract.d.ts +113 -10
  63. package/dist/adapters/contract.js +7 -2
  64. package/dist/adapters/contract.js.map +1 -1
  65. package/dist/adapters/desktop/atspi-busctl.d.ts +26 -0
  66. package/dist/adapters/desktop/atspi-busctl.js +332 -0
  67. package/dist/adapters/desktop/atspi-busctl.js.map +1 -0
  68. package/dist/adapters/desktop/atspi-parse.d.ts +39 -0
  69. package/dist/adapters/desktop/atspi-parse.js +155 -0
  70. package/dist/adapters/desktop/atspi-parse.js.map +1 -0
  71. package/dist/adapters/desktop/atspi.d.ts +81 -50
  72. package/dist/adapters/desktop/atspi.js +64 -285
  73. package/dist/adapters/desktop/atspi.js.map +1 -1
  74. package/dist/adapters/desktop/capture.d.ts +11 -20
  75. package/dist/adapters/desktop/capture.js +68 -37
  76. package/dist/adapters/desktop/capture.js.map +1 -1
  77. package/dist/adapters/desktop/desktop-adapter.d.ts +22 -2
  78. package/dist/adapters/desktop/desktop-adapter.js +202 -86
  79. package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
  80. package/dist/adapters/desktop/input.d.ts +19 -5
  81. package/dist/adapters/desktop/input.js +29 -13
  82. package/dist/adapters/desktop/input.js.map +1 -1
  83. package/dist/adapters/desktop/managed-app.d.ts +43 -0
  84. package/dist/adapters/desktop/managed-app.js +114 -0
  85. package/dist/adapters/desktop/managed-app.js.map +1 -0
  86. package/dist/adapters/desktop/proc.d.ts +34 -4
  87. package/dist/adapters/desktop/proc.js +37 -6
  88. package/dist/adapters/desktop/proc.js.map +1 -1
  89. package/dist/adapters/desktop/wait-poll.d.ts +17 -0
  90. package/dist/adapters/desktop/wait-poll.js +38 -0
  91. package/dist/adapters/desktop/wait-poll.js.map +1 -0
  92. package/dist/adapters/factory.d.ts +13 -6
  93. package/dist/adapters/factory.js +30 -4
  94. package/dist/adapters/factory.js.map +1 -1
  95. package/dist/adapters/log-format.d.ts +38 -0
  96. package/dist/adapters/log-format.js +47 -0
  97. package/dist/adapters/log-format.js.map +1 -0
  98. package/dist/agent/belt/act.d.ts +426 -23
  99. package/dist/agent/belt/act.js +44 -64
  100. package/dist/agent/belt/act.js.map +1 -1
  101. package/dist/agent/belt/look.d.ts +479 -16
  102. package/dist/agent/belt/look.js +94 -16
  103. package/dist/agent/belt/look.js.map +1 -1
  104. package/dist/agent/belt/observe.d.ts +652 -65
  105. package/dist/agent/belt/observe.js +119 -231
  106. package/dist/agent/belt/observe.js.map +1 -1
  107. package/dist/agent/belt/redact-output.d.ts +20 -0
  108. package/dist/agent/belt/redact-output.js +70 -0
  109. package/dist/agent/belt/redact-output.js.map +1 -0
  110. package/dist/agent/belt/report.d.ts +754 -48
  111. package/dist/agent/belt/report.js +121 -38
  112. package/dist/agent/belt/report.js.map +1 -1
  113. package/dist/agent/belt/same-origin.d.ts +21 -0
  114. package/dist/agent/belt/same-origin.js +38 -0
  115. package/dist/agent/belt/same-origin.js.map +1 -0
  116. package/dist/agent/belt/target-refs.d.ts +39 -0
  117. package/dist/agent/belt/target-refs.js +60 -0
  118. package/dist/agent/belt/target-refs.js.map +1 -0
  119. package/dist/agent/belt/trail.d.ts +44 -16
  120. package/dist/agent/belt/trail.js +46 -11
  121. package/dist/agent/belt/trail.js.map +1 -1
  122. package/dist/agent/belt/tree-targets.d.ts +79 -0
  123. package/dist/agent/belt/tree-targets.js +242 -0
  124. package/dist/agent/belt/tree-targets.js.map +1 -0
  125. package/dist/agent/capabilities.js.map +1 -1
  126. package/dist/agent/fallback.d.ts +33 -0
  127. package/dist/agent/fallback.js +84 -0
  128. package/dist/agent/fallback.js.map +1 -0
  129. package/dist/agent/loop-frames.d.ts +26 -0
  130. package/dist/agent/loop-frames.js +106 -0
  131. package/dist/agent/loop-frames.js.map +1 -0
  132. package/dist/agent/loop.d.ts +56 -65
  133. package/dist/agent/loop.js +122 -189
  134. package/dist/agent/loop.js.map +1 -1
  135. package/dist/agent/models.d.ts +10 -6
  136. package/dist/agent/models.js +15 -9
  137. package/dist/agent/models.js.map +1 -1
  138. package/dist/agent/prompts/compose.d.ts +1 -1
  139. package/dist/agent/prompts/debug-agent.js +48 -10
  140. package/dist/agent/prompts/debug-agent.js.map +1 -1
  141. package/dist/agent/prompts/web-addendum.d.ts +2 -2
  142. package/dist/agent/prompts/web-addendum.js +26 -25
  143. package/dist/agent/prompts/web-addendum.js.map +1 -1
  144. package/dist/agent/provider.d.ts +41 -1
  145. package/dist/agent/provider.js +59 -5
  146. package/dist/agent/provider.js.map +1 -1
  147. package/dist/boot.d.ts +64 -0
  148. package/dist/boot.js +147 -0
  149. package/dist/boot.js.map +1 -0
  150. package/dist/cli/chromium-libs.d.ts +267 -0
  151. package/dist/cli/chromium-libs.js +546 -0
  152. package/dist/cli/chromium-libs.js.map +1 -0
  153. package/dist/cli/control.js +79 -12
  154. package/dist/cli/control.js.map +1 -1
  155. package/dist/cli/init.d.ts +52 -3
  156. package/dist/cli/init.js +62 -10
  157. package/dist/cli/init.js.map +1 -1
  158. package/dist/config/load.d.ts +25 -8
  159. package/dist/config/load.js +50 -13
  160. package/dist/config/load.js.map +1 -1
  161. package/dist/config/schema.d.ts +18 -6
  162. package/dist/config/schema.js +34 -17
  163. package/dist/config/schema.js.map +1 -1
  164. package/dist/errors.d.ts +30 -15
  165. package/dist/errors.js +49 -30
  166. package/dist/errors.js.map +1 -1
  167. package/dist/findings/schema.d.ts +44 -6
  168. package/dist/findings/schema.js +39 -3
  169. package/dist/findings/schema.js.map +1 -1
  170. package/dist/index.d.ts +1 -1
  171. package/dist/index.js +1 -1
  172. package/dist/index.js.map +1 -1
  173. package/dist/main.js +4 -82
  174. package/dist/main.js.map +1 -1
  175. package/dist/mcp/server.js +10 -1
  176. package/dist/mcp/server.js.map +1 -1
  177. package/dist/mcp/tools/describe.d.ts +5 -4
  178. package/dist/mcp/tools/describe.js +14 -10
  179. package/dist/mcp/tools/describe.js.map +1 -1
  180. package/dist/mcp/tools/end-session.d.ts +3 -1
  181. package/dist/mcp/tools/end-session.js +8 -3
  182. package/dist/mcp/tools/end-session.js.map +1 -1
  183. package/dist/mcp/tools/output.d.ts +12 -4
  184. package/dist/mcp/tools/output.js +15 -2
  185. package/dist/mcp/tools/output.js.map +1 -1
  186. package/dist/mcp/tools/result.d.ts +10 -1
  187. package/dist/mcp/tools/result.js +12 -7
  188. package/dist/mcp/tools/result.js.map +1 -1
  189. package/dist/mcp/tools/start-debug.js +7 -5
  190. package/dist/mcp/tools/start-debug.js.map +1 -1
  191. package/dist/redact.d.ts +44 -0
  192. package/dist/redact.js +166 -0
  193. package/dist/redact.js.map +1 -0
  194. package/dist/services/auth-persona.d.ts +19 -0
  195. package/dist/services/auth-persona.js +32 -0
  196. package/dist/services/auth-persona.js.map +1 -0
  197. package/dist/services/catalog.d.ts +28 -0
  198. package/dist/services/catalog.js +65 -0
  199. package/dist/services/catalog.js.map +1 -0
  200. package/dist/services/debug-api.d.ts +179 -0
  201. package/dist/services/debug-api.js +9 -0
  202. package/dist/services/debug-api.js.map +1 -0
  203. package/dist/services/debug-service.d.ts +26 -174
  204. package/dist/services/debug-service.js +159 -227
  205. package/dist/services/debug-service.js.map +1 -1
  206. package/dist/services/foreign-findings.d.ts +22 -0
  207. package/dist/services/foreign-findings.js +38 -0
  208. package/dist/services/foreign-findings.js.map +1 -0
  209. package/dist/services/login-failure.d.ts +10 -0
  210. package/dist/services/login-failure.js +24 -0
  211. package/dist/services/login-failure.js.map +1 -0
  212. package/dist/services/login-selectors.d.ts +18 -0
  213. package/dist/services/login-selectors.js +44 -0
  214. package/dist/services/login-selectors.js.map +1 -0
  215. package/dist/services/login-session.d.ts +25 -0
  216. package/dist/services/login-session.js +59 -0
  217. package/dist/services/login-session.js.map +1 -0
  218. package/dist/services/login.d.ts +16 -29
  219. package/dist/services/login.js +269 -97
  220. package/dist/services/login.js.map +1 -1
  221. package/dist/services/replay.js +15 -3
  222. package/dist/services/replay.js.map +1 -1
  223. package/dist/services/retained-snapshot.d.ts +36 -0
  224. package/dist/services/retained-snapshot.js +63 -0
  225. package/dist/services/retained-snapshot.js.map +1 -0
  226. package/dist/services/session-builder.d.ts +26 -0
  227. package/dist/services/session-builder.js +63 -21
  228. package/dist/services/session-builder.js.map +1 -1
  229. package/dist/services/shutdown.d.ts +8 -4
  230. package/dist/services/shutdown.js +21 -8
  231. package/dist/services/shutdown.js.map +1 -1
  232. package/dist/services/start-guards.d.ts +37 -0
  233. package/dist/services/start-guards.js +61 -0
  234. package/dist/services/start-guards.js.map +1 -0
  235. package/dist/services/summarize.d.ts +12 -3
  236. package/dist/services/summarize.js +13 -5
  237. package/dist/services/summarize.js.map +1 -1
  238. package/dist/session/cleanup.d.ts +3 -2
  239. package/dist/session/cleanup.js +6 -2
  240. package/dist/session/cleanup.js.map +1 -1
  241. package/dist/session/finalize.d.ts +45 -0
  242. package/dist/session/finalize.js +150 -0
  243. package/dist/session/finalize.js.map +1 -0
  244. package/dist/session/findings-store.d.ts +2 -1
  245. package/dist/session/findings-store.js +30 -2
  246. package/dist/session/findings-store.js.map +1 -1
  247. package/dist/session/flock-backend.d.ts +117 -0
  248. package/dist/session/flock-backend.js +293 -0
  249. package/dist/session/flock-backend.js.map +1 -0
  250. package/dist/session/live-pointer.d.ts +19 -0
  251. package/dist/session/live-pointer.js +41 -0
  252. package/dist/session/live-pointer.js.map +1 -0
  253. package/dist/session/manager.d.ts +11 -1
  254. package/dist/session/manager.js +46 -2
  255. package/dist/session/manager.js.map +1 -1
  256. package/dist/session/owner-lock.d.ts +117 -0
  257. package/dist/session/owner-lock.js +218 -0
  258. package/dist/session/owner-lock.js.map +1 -0
  259. package/dist/session/process-identity.js.map +1 -1
  260. package/dist/session/session.js +40 -109
  261. package/dist/session/session.js.map +1 -1
  262. package/dist/session/state-file.d.ts +74 -14
  263. package/dist/session/state-file.js +211 -21
  264. package/dist/session/state-file.js.map +1 -1
  265. package/dist/session/workspace.d.ts +32 -2
  266. package/dist/session/workspace.js +65 -4
  267. package/dist/session/workspace.js.map +1 -1
  268. package/package.json +11 -11
  269. package/dist/adapters/android/android-adapter.test-helpers.d.ts +0 -52
  270. package/dist/adapters/android/android-adapter.test-helpers.js +0 -115
  271. package/dist/adapters/android/android-adapter.test-helpers.js.map +0 -1
  272. package/dist/mcp/server.test-helpers.d.ts +0 -23
  273. package/dist/mcp/server.test-helpers.js +0 -49
  274. package/dist/mcp/server.test-helpers.js.map +0 -1
@@ -9,10 +9,10 @@
9
9
  * any mid-run messages (the smart agent's `send_message`) into a standing
10
10
  * instruction block re-appended to EVERY turn (the SDK rebuilds each step's
11
11
  * prompt from scratch), so the driver adapts without restarting or forgetting.
12
- * - **incremental findings** — `onStepFinish` snapshots the shared act trail
13
- * (`act` records each step as it happens) plus `look`'s visual issues and
14
- * error-level console rows, and flushes them as `status: 'running'` findings,
15
- * so `get_findings` streams findings before the verdict lands, and a run that
12
+ * - **incremental findings** — `onStepFinish` snapshots the shared evidence
13
+ * trail (the belt's tools record each step, console error and look issue as
14
+ * it happens) and flushes it as `status: 'running'` findings, so
15
+ * `get_findings` streams findings before the verdict lands, and a run that
16
16
  * crashes, aborts or hits the step cap keeps everything surfaced so far.
17
17
  *
18
18
  * Adapter-blind and model-blind like the belt: the loop never touches a protocol
@@ -23,7 +23,8 @@
23
23
  * aborted run rejects loud (wired to `end_session`), never a silent half-finish.
24
24
  */
25
25
  import { type LanguageModel, type ModelMessage, type Tool, ToolLoopAgent } from 'ai';
26
- import type { Bug, Findings, Step, VisualIssue } from '../findings/schema.js';
26
+ import type { Findings } from '../findings/schema.js';
27
+ import type { ActTrail, TrailEvidence } from './belt/trail.js';
27
28
  /**
28
29
  * Safety cap on driver steps before the loop force-stops (paired with the
29
30
  * report-RESULT stop condition in {@link createDebugAgent}).
@@ -38,6 +39,12 @@ import type { Bug, Findings, Step, VisualIssue } from '../findings/schema.js';
38
39
  export declare const DEFAULT_MAX_STEPS = 60;
39
40
  /** Kickoff turn — the story lives in `instructions`; this nudges the driver to start the loop. */
40
41
  export declare const KICKOFF_PROMPT = "Begin. Work toward the goal with observe/act/look, then call report exactly once with your verdict.";
42
+ /**
43
+ * Re-entry turn after a step with NO tool call. The SDK ends a tool loop on any
44
+ * such step, so one line of prose ("I will now click Save.") used to end the
45
+ * whole run with no verdict — {@link runDebugLoop} re-enters with this instead.
46
+ */
47
+ export declare const NO_TOOL_CALL_NUDGE = "You replied without calling a tool, which does nothing. Continue with observe/act/look, or call report now if you are done.";
41
48
  /** The driver's inner belt — the four fat tools the loop drives (see `idea/mcp-tools.md`). */
42
49
  export type BeltTools = {
43
50
  observe: Tool;
@@ -85,72 +92,54 @@ export interface FinishedStep {
85
92
  * into `standing` — the run-long list of caller instructions — then, while any
86
93
  * exist, appends ONE user message rebuilt from the whole list.
87
94
  *
88
- * Rebuilt on EVERY step, not just the drain step: the SDK composes each step's
89
- * prompt fresh from `[...initialMessages, ...responseMessages]` and never persists
90
- * a `prepareStep` messages override, so an instruction injected once would reach
91
- * the driver for exactly one step and then vanish. Because the base `messages`
92
- * arrive without the previous step's injection, re-appending the single rebuilt
93
- * block never accumulates duplicates. Returns `{}` when no instructions exist.
95
+ * Rebuilt on EVERY step, not just the drain step: an instruction injected once
96
+ * must reach the driver on every later step too. AI SDK 7 persists the previous
97
+ * step's `prepareStep` override into the running transcript
98
+ * (`messagesForNextStep = [...stepMessages, ...stepResponseMessages]`), so the
99
+ * caller strips last step's fold/nudge first ({@link stripInjectedStepMessages})
100
+ * and this re-appends exactly one fresh block — never accumulation. Returns
101
+ * `{}` when no instructions exist.
94
102
  */
95
103
  export declare function foldInstructionsIntoStep(inbox: LoopInbox, standing: string[], messages: ModelMessage[]): {
96
104
  messages: ModelMessage[];
97
105
  } | Record<string, never>;
98
- /** What a pruned frame collapses to — tells the driver how to get a fresh one. */
99
- export declare const STALE_FRAME_NOTE = "[stale frame removed \u2014 call look again for a fresh screenshot]";
100
106
  /**
101
- * Keep only the NEWEST self-look frame in the transcript. The SDK re-sends every
102
- * tool result on every step, so each `look` image would otherwise ride along for
103
- * the rest of the run — N looks × M steps of image tokens. Rebuilt per step in
104
- * `prepareStep` (overrides never persist), like the instruction fold. Returns the
105
- * SAME array when there is at most one frame, preserving the no-change fast path.
107
+ * Drop the fold/nudge messages a PREVIOUS step's `prepareStep` injected.
108
+ *
109
+ * AI SDK 7 persists the override into the running transcript
110
+ * (`messagesForNextStep = [...stepMessages, ...stepResponseMessages]` in
111
+ * `generateText`); AI SDK 6 rebuilt each step's prompt from response messages
112
+ * alone and discarded it. Without stripping, the re-appended instruction fold
113
+ * duplicates one copy per step, and a stale earlier nudge precedes the fresh
114
+ * one (breaking fold-before-nudge ordering). Stripping first restores exactly
115
+ * the AI SDK 6 chain this loop was written against, so the rebuilt override is
116
+ * correct whether the SDK persists it or not.
106
117
  */
107
- export declare function pruneStaleFrames(messages: ModelMessage[]): ModelMessage[];
118
+ export declare function stripInjectedStepMessages(messages: ModelMessage[]): ModelMessage[];
108
119
  /** Steps left at or below which the driver is nudged to wrap up and `report`. */
109
120
  export declare const BUDGET_WARN = 6;
110
121
  /**
111
122
  * A step-budget reminder folded into the turn as the run nears its cap — so the
112
- * driver converges on `report` instead of churning to the hard `stepCountIs` stop
123
+ * driver converges on `report` instead of churning to the hard step-cap stop
113
124
  * (which leaves an empty, verdict-less `failed` run). `null` while there is ample
114
125
  * budget. `stepNumber` is the 0-based index of the step about to run.
115
126
  */
116
127
  export declare function budgetNudge(stepNumber: number, maxSteps: number): string | null;
117
- /**
118
- * Lift a finished step's `look` results into visual findings — each issue the
119
- * vision guy flagged, carrying the frame it was judged on as evidence.
120
- */
121
- export declare function visualFrom(toolResults: FinishedStep['toolResults']): VisualIssue[];
122
- /**
123
- * Lift a finished step's `observe` console reads into bugs — ERROR rows only
124
- * (warn/log/info are working noise, not findings). The console channel is a ring
125
- * buffer read non-destructively, so a re-read returns rows already lifted;
126
- * {@link progressForStep} dedupes by message before they land.
127
- */
128
- export declare function consoleBugsFrom(toolResults: FinishedStep['toolResults']): Bug[];
129
- /**
130
- * The run-long accumulators the running flush reads: the shared act-`steps` trail
131
- * (the SAME array the `act` and `report` tools hold) plus the findings streamed off
132
- * the belt — `look`'s visual issues and error-level console rows. Streaming those
133
- * is what keeps a crashed, aborted or step-capped run's findings file complete;
134
- * before, they lived only in model context until `report`.
135
- */
136
- export interface RunTrail {
137
- /** Ordered act trail, written by `act` as each act finishes (shared with `report`). */
138
- steps: Step[];
139
- /** Console bugs seen so far, deduped by message. */
140
- bugs: Bug[];
141
- /** Visual issues seen so far, deduped by issue + location. */
142
- visual: VisualIssue[];
143
- }
144
128
  /**
145
129
  * Decide the running-findings write for a finished step. Steps aside for the
146
130
  * terminal `report` step (it owns the verdict, and already merged the trail — see
147
- * `belt/report.ts`); otherwise appends this step's NEW `look` issues and console
148
- * errors to `running` (mutated in place) and returns the `running` findings to
149
- * persist — act steps are already on `running.steps`, recorded by `act` itself.
150
- * `null` when the step surfaced nothing new — no act, and every issue/error
151
- * already streamed.
131
+ * `belt/report.ts`); otherwise, when ANY evidence stream grew past what the last
132
+ * flush already persisted, return the running findings to persist — a snapshot
133
+ * COPY of the trail ({@link TrailEvidence}). `null` when the step surfaced
134
+ * nothing new: no act recorded, every issue/error already streamed.
135
+ *
136
+ * Growth is read off the trail, not off the step's own tool results: the belt
137
+ * records AT TOOL TIME — a FAILED act still lands on the trail (`belt/act.ts`
138
+ * records `ok: false` then rethrows, and AI SDK 6 routes a rejected call to a
139
+ * `tool-error` content part, never `toolResults`) — so the trail's growth is the
140
+ * one signal that covers successes, failures and streamed findings alike.
152
141
  */
153
- export declare function progressForStep(step: FinishedStep, running: RunTrail): Findings | null;
142
+ export declare function progressForStep(step: FinishedStep, evidence: TrailEvidence, flushed: TrailEvidence): Findings | null;
154
143
  /** Everything the loop needs to run one debug session. */
155
144
  export interface DebugAgentOptions {
156
145
  /** fast guy — the blind text driver running the high-frequency click loop. */
@@ -166,12 +155,14 @@ export interface DebugAgentOptions {
166
155
  /** Optional sink for a human-readable step trail (`logs/agent.log`). */
167
156
  log?: AgentLog;
168
157
  /**
169
- * Shared act-trail the `act` tool writes, the running flush snapshots and the
170
- * `report` tool merges into the verdict's `steps` — pass the SAME array the
171
- * belt's act trail holds so the write and its counts agree. Defaults to a fresh
172
- * array (an unwired loop then flushes no steps).
158
+ * Shared evidence trail the belt's tools record into — `act` writes each step
159
+ * as it finishes, `look` each flagged issue, `observe` each error-level console
160
+ * row — the running flush snapshots it after every step, and the `report` tool
161
+ * merges all three streams into the verdict. Pass the SAME trail the belt's
162
+ * tools were built with so the write, the flushes and their counts agree.
163
+ * Defaults to none: an unwired loop then has nothing to flush.
173
164
  */
174
- trail?: Step[];
165
+ trail?: ActTrail;
175
166
  /** Step safety cap; defaults to {@link DEFAULT_MAX_STEPS}. */
176
167
  maxSteps?: number;
177
168
  }
@@ -188,12 +179,6 @@ export declare const UNDELIVERED_NOTE = "Undelivered mid-run instruction(s) \u20
188
179
  * untouched — the schema, not this, decides what a valid verdict is.
189
180
  */
190
181
  export declare function appendUndelivered(input: unknown, pending: readonly string[]): unknown;
191
- /**
192
- * Build the debug agent loop. The driver runs `observe`→`act`→`look` until it
193
- * calls `report` (terminal) or hits the step cap. Between steps `prepareStep`
194
- * folds in mid-run messages; after each step `onStepFinish` flushes the running
195
- * trail (skipping the `report` step, which writes the final verdict itself).
196
- */
197
182
  export declare function createDebugAgent(options: DebugAgentOptions): ToolLoopAgent<never, BeltTools>;
198
183
  /** How to run a built loop to its verdict. */
199
184
  export interface RunDebugLoopOptions {
@@ -208,5 +193,11 @@ export interface RunDebugLoopOptions {
208
193
  * Run the loop to its verdict. Resolves with the agent's generate result once the
209
194
  * driver reports (or the step cap trips); rejects if aborted (fail loud — the
210
195
  * session decides what an aborted run means).
196
+ *
197
+ * A step with no tool call ends the SDK's loop, so while step budget remains the
198
+ * run re-enters with the transcript so far plus {@link NO_TOOL_CALL_NUDGE}. Each
199
+ * re-entry spends a step of the SAME run-long budget, so it can never spin.
200
+ * Only a NORMAL prose completion (`stop`) re-enters: a content-filtered, errored
201
+ * or truncated turn would just be re-asked the same way until the budget is gone.
211
202
  */
212
- export declare function runDebugLoop(options: RunDebugLoopOptions): Promise<import("ai").GenerateTextResult<BeltTools, never>>;
203
+ export declare function runDebugLoop(options: RunDebugLoopOptions): Promise<import("ai").GenerateTextResult<BeltTools, import("@ai-sdk/provider-utils").Context, never>>;
@@ -9,10 +9,10 @@
9
9
  * any mid-run messages (the smart agent's `send_message`) into a standing
10
10
  * instruction block re-appended to EVERY turn (the SDK rebuilds each step's
11
11
  * prompt from scratch), so the driver adapts without restarting or forgetting.
12
- * - **incremental findings** — `onStepFinish` snapshots the shared act trail
13
- * (`act` records each step as it happens) plus `look`'s visual issues and
14
- * error-level console rows, and flushes them as `status: 'running'` findings,
15
- * so `get_findings` streams findings before the verdict lands, and a run that
12
+ * - **incremental findings** — `onStepFinish` snapshots the shared evidence
13
+ * trail (the belt's tools record each step, console error and look issue as
14
+ * it happens) and flushes it as `status: 'running'` findings, so
15
+ * `get_findings` streams findings before the verdict lands, and a run that
16
16
  * crashes, aborts or hits the step cap keeps everything surfaced so far.
17
17
  *
18
18
  * Adapter-blind and model-blind like the belt: the loop never touches a protocol
@@ -22,8 +22,9 @@
22
22
  * (never clobbers the verdict with a `running` snapshot). Abort propagates: an
23
23
  * aborted run rejects loud (wired to `end_session`), never a silent half-finish.
24
24
  */
25
- import { stepCountIs, ToolLoopAgent } from 'ai';
26
- import { z } from 'zod';
25
+ import { ToolLoopAgent } from 'ai';
26
+ import { EMPTY_EVIDENCE } from './belt/report.js';
27
+ import { pruneStaleFrames } from './loop-frames.js';
27
28
  /**
28
29
  * Safety cap on driver steps before the loop force-stops (paired with the
29
30
  * report-RESULT stop condition in {@link createDebugAgent}).
@@ -39,39 +40,23 @@ export const DEFAULT_MAX_STEPS = 60;
39
40
  /** Kickoff turn — the story lives in `instructions`; this nudges the driver to start the loop. */
40
41
  export const KICKOFF_PROMPT = 'Begin. Work toward the goal with observe/act/look, then call report exactly once with your verdict.';
41
42
  /**
42
- * The `look` result fields lifted into streamed visual findings: the vision guy's
43
- * `issues[]` and the frame it judged (see `belt/look.ts`). A SELF-look result (a
44
- * multimodal driver judging the frame with its own eyes) carries no `issues`, so
45
- * it contributes nothing here — those issues reach findings via `report`.
43
+ * Re-entry turn after a step with NO tool call. The SDK ends a tool loop on any
44
+ * such step, so one line of prose ("I will now click Save.") used to end the
45
+ * whole run with no verdict — {@link runDebugLoop} re-enters with this instead.
46
46
  */
47
- const LookVisualSchema = z.object({
48
- screenshot: z.string().optional(),
49
- issues: z
50
- .array(z.object({
51
- what: z.string(),
52
- where: z.string(),
53
- severity: z.enum(['low', 'medium', 'high']),
54
- }))
55
- .default([]),
56
- });
57
- /** The `observe` console rows lifted into streamed bugs (see `belt/observe.ts`). */
58
- const ConsoleObserveSchema = z.object({
59
- kind: z.literal('console'),
60
- entries: z
61
- .array(z.object({ level: z.string(), text: z.string(), location: z.string().optional() }))
62
- .default([]),
63
- });
47
+ export const NO_TOOL_CALL_NUDGE = 'You replied without calling a tool, which does nothing. Continue with observe/act/look, or call report now if you are done.';
64
48
  /**
65
49
  * `prepareStep`: fold mid-run messages into the next model turn. Drains the inbox
66
50
  * into `standing` — the run-long list of caller instructions — then, while any
67
51
  * exist, appends ONE user message rebuilt from the whole list.
68
52
  *
69
- * Rebuilt on EVERY step, not just the drain step: the SDK composes each step's
70
- * prompt fresh from `[...initialMessages, ...responseMessages]` and never persists
71
- * a `prepareStep` messages override, so an instruction injected once would reach
72
- * the driver for exactly one step and then vanish. Because the base `messages`
73
- * arrive without the previous step's injection, re-appending the single rebuilt
74
- * block never accumulates duplicates. Returns `{}` when no instructions exist.
53
+ * Rebuilt on EVERY step, not just the drain step: an instruction injected once
54
+ * must reach the driver on every later step too. AI SDK 7 persists the previous
55
+ * step's `prepareStep` override into the running transcript
56
+ * (`messagesForNextStep = [...stepMessages, ...stepResponseMessages]`), so the
57
+ * caller strips last step's fold/nudge first ({@link stripInjectedStepMessages})
58
+ * and this re-appends exactly one fresh block — never accumulation. Returns
59
+ * `{}` when no instructions exist.
75
60
  */
76
61
  export function foldInstructionsIntoStep(inbox, standing, messages) {
77
62
  standing.push(...inbox.drain());
@@ -85,63 +70,45 @@ export function foldInstructionsIntoStep(inbox, standing, messages) {
85
70
  };
86
71
  return { messages: [...messages, injected] };
87
72
  }
88
- /** What a pruned frame collapses to — tells the driver how to get a fresh one. */
89
- export const STALE_FRAME_NOTE = '[stale frame removed — call look again for a fresh screenshot]';
90
- /** Whether a tool-result part carries a self-look frame (`content` output with `file-data`). */
91
- function isLookFrame(part) {
92
- if (typeof part !== 'object' || part === null)
73
+ /** The exact prefixes of every user message `prepareStep` itself injects. */
74
+ const INJECTED_PREFIXES = [
75
+ 'Mid-run instructions from the caller',
76
+ 'Step budget almost spent',
77
+ 'This is your final step',
78
+ ];
79
+ /**
80
+ * True for the fold/nudge messages `prepareStep` appends — and ONLY those: the
81
+ * content must be a plain string starting with one of the exact prefixes above,
82
+ * so a driver-authored message that merely mentions them never matches.
83
+ */
84
+ function isInjectedStepMessage(message) {
85
+ const { content } = message;
86
+ if (message.role !== 'user' || typeof content !== 'string')
93
87
  return false;
94
- const p = part;
95
- return (p.type === 'tool-result' &&
96
- p.toolName === 'look' &&
97
- p.output?.type === 'content' &&
98
- Array.isArray(p.output.value) &&
99
- p.output.value.some((v) => v?.type === 'file-data'));
100
- }
101
- /** Collapse every `file-data` part of a look tool-result to the stale-frame note. */
102
- function stripFrame(message) {
103
- if (!Array.isArray(message.content))
104
- return message;
105
- const content = message.content.map((part) => {
106
- if (!isLookFrame(part))
107
- return part;
108
- const p = part;
109
- return {
110
- ...part,
111
- output: {
112
- ...p.output,
113
- value: p.output.value.map((v) => v?.type === 'file-data' ? { type: 'text', text: STALE_FRAME_NOTE } : v),
114
- },
115
- };
116
- });
117
- return { ...message, content };
88
+ return INJECTED_PREFIXES.some((prefix) => content.startsWith(prefix));
118
89
  }
119
90
  /**
120
- * Keep only the NEWEST self-look frame in the transcript. The SDK re-sends every
121
- * tool result on every step, so each `look` image would otherwise ride along for
122
- * the rest of the run — N looks × M steps of image tokens. Rebuilt per step in
123
- * `prepareStep` (overrides never persist), like the instruction fold. Returns the
124
- * SAME array when there is at most one frame, preserving the no-change fast path.
91
+ * Drop the fold/nudge messages a PREVIOUS step's `prepareStep` injected.
92
+ *
93
+ * AI SDK 7 persists the override into the running transcript
94
+ * (`messagesForNextStep = [...stepMessages, ...stepResponseMessages]` in
95
+ * `generateText`); AI SDK 6 rebuilt each step's prompt from response messages
96
+ * alone and discarded it. Without stripping, the re-appended instruction fold
97
+ * duplicates one copy per step, and a stale earlier nudge precedes the fresh
98
+ * one (breaking fold-before-nudge ordering). Stripping first restores exactly
99
+ * the AI SDK 6 chain this loop was written against, so the rebuilt override is
100
+ * correct whether the SDK persists it or not.
125
101
  */
126
- export function pruneStaleFrames(messages) {
127
- const frameIndexes = [];
128
- messages.forEach((message, index) => {
129
- if (message.role === 'tool' &&
130
- Array.isArray(message.content) &&
131
- message.content.some(isLookFrame)) {
132
- frameIndexes.push(index);
133
- }
134
- });
135
- if (frameIndexes.length <= 1)
102
+ export function stripInjectedStepMessages(messages) {
103
+ if (!messages.some(isInjectedStepMessage))
136
104
  return messages;
137
- const stale = new Set(frameIndexes.slice(0, -1));
138
- return messages.map((message, index) => (stale.has(index) ? stripFrame(message) : message));
105
+ return messages.filter((message) => !isInjectedStepMessage(message));
139
106
  }
140
107
  /** Steps left at or below which the driver is nudged to wrap up and `report`. */
141
108
  export const BUDGET_WARN = 6;
142
109
  /**
143
110
  * A step-budget reminder folded into the turn as the run nears its cap — so the
144
- * driver converges on `report` instead of churning to the hard `stepCountIs` stop
111
+ * driver converges on `report` instead of churning to the hard step-cap stop
145
112
  * (which leaves an empty, verdict-less `failed` run). `null` while there is ample
146
113
  * budget. `stepNumber` is the 0-based index of the step about to run.
147
114
  */
@@ -154,84 +121,21 @@ export function budgetNudge(stepNumber, maxSteps) {
154
121
  }
155
122
  return `Step budget almost spent: ~${remaining} of ${maxSteps} steps left. Finish exploring and call \`report\` soon with all findings; an unreported run is wasted.`;
156
123
  }
157
- /**
158
- * Lift a finished step's `look` results into visual findings — each issue the
159
- * vision guy flagged, carrying the frame it was judged on as evidence.
160
- */
161
- export function visualFrom(toolResults) {
162
- const issues = [];
163
- for (const result of toolResults) {
164
- if (result.toolName !== 'look')
165
- continue;
166
- const parsed = LookVisualSchema.safeParse(result.output);
167
- if (!parsed.success)
168
- continue;
169
- const { screenshot } = parsed.data;
170
- for (const issue of parsed.data.issues) {
171
- issues.push({
172
- issue: issue.what,
173
- where: issue.where,
174
- severity: issue.severity,
175
- ...(screenshot !== undefined && { screenshot }),
176
- });
177
- }
178
- }
179
- return issues;
180
- }
181
- /**
182
- * Lift a finished step's `observe` console reads into bugs — ERROR rows only
183
- * (warn/log/info are working noise, not findings). The console channel is a ring
184
- * buffer read non-destructively, so a re-read returns rows already lifted;
185
- * {@link progressForStep} dedupes by message before they land.
186
- */
187
- export function consoleBugsFrom(toolResults) {
188
- const bugs = [];
189
- for (const result of toolResults) {
190
- if (result.toolName !== 'observe')
191
- continue;
192
- const parsed = ConsoleObserveSchema.safeParse(result.output);
193
- if (!parsed.success)
194
- continue;
195
- for (const entry of parsed.data.entries) {
196
- if (entry.level !== 'error')
197
- continue;
198
- bugs.push({
199
- kind: 'console',
200
- detail: entry.text,
201
- ...(entry.location !== undefined && { evidence: entry.location }),
202
- });
203
- }
204
- }
205
- return bugs;
206
- }
207
- /** Dedupe key for a streamed finding — its message, case- and whitespace-insensitive. */
208
- function messageKey(...parts) {
209
- return parts.join(' @ ').trim().toLowerCase().replace(/\s+/g, ' ');
210
- }
211
- /** Append the `fresh` entries whose key is not already present; returns how many landed. */
212
- function appendNew(into, fresh, key) {
213
- const seen = new Set(into.map(key));
214
- let added = 0;
215
- for (const item of fresh) {
216
- const k = key(item);
217
- if (seen.has(k))
218
- continue;
219
- seen.add(k);
220
- into.push(item);
221
- added += 1;
222
- }
223
- return added;
224
- }
225
124
  /**
226
125
  * Decide the running-findings write for a finished step. Steps aside for the
227
126
  * terminal `report` step (it owns the verdict, and already merged the trail — see
228
- * `belt/report.ts`); otherwise appends this step's NEW `look` issues and console
229
- * errors to `running` (mutated in place) and returns the `running` findings to
230
- * persist — act steps are already on `running.steps`, recorded by `act` itself.
231
- * `null` when the step surfaced nothing new — no act, and every issue/error
232
- * already streamed.
127
+ * `belt/report.ts`); otherwise, when ANY evidence stream grew past what the last
128
+ * flush already persisted, return the running findings to persist — a snapshot
129
+ * COPY of the trail ({@link TrailEvidence}). `null` when the step surfaced
130
+ * nothing new: no act recorded, every issue/error already streamed.
131
+ *
132
+ * Growth is read off the trail, not off the step's own tool results: the belt
133
+ * records AT TOOL TIME — a FAILED act still lands on the trail (`belt/act.ts`
134
+ * records `ok: false` then rethrows, and AI SDK 6 routes a rejected call to a
135
+ * `tool-error` content part, never `toolResults`) — so the trail's growth is the
136
+ * one signal that covers successes, failures and streamed findings alike.
233
137
  */
234
- export function progressForStep(step, running) {
138
+ export function progressForStep(step, evidence, flushed) {
235
139
  // Gated on the report RESULT, not the report CALL. A `report` whose arguments
236
140
  // fail the Zod schema is never executed (AI SDK 6 marks it `invalid` and feeds
237
141
  // the driver a tool-error), yet it still appears in `toolCalls` — so a call-gated
@@ -239,23 +143,18 @@ export function progressForStep(step, running) {
239
143
  // of a verdict that was never written.
240
144
  if (step.toolResults.some((result) => result.toolName === 'report'))
241
145
  return null;
242
- // Checked against `toolCalls`, NOT `toolResults`: a FAILED act still lands on
243
- // `running.steps` (`act` records `ok: false` at act time, then rethrows — see
244
- // `belt/act.ts`), but AI SDK 6 routes a rejected tool call to a `tool-error`
245
- // content part, never `toolResults` (see `describeStep` above). Gating on
246
- // `toolResults` would miss every failed act — exactly the step a crashed run
247
- // most needs preserved — unless the same step happened to also add a bug or
248
- // visual issue.
249
- const acted = step.toolCalls.some((call) => call.toolName === 'act');
250
- const bugs = appendNew(running.bugs, consoleBugsFrom(step.toolResults), (bug) => messageKey(bug.detail));
251
- const visual = appendNew(running.visual, visualFrom(step.toolResults), (issue) => messageKey(issue.issue, issue.where));
252
- if (!acted && bugs === 0 && visual === 0)
146
+ // The arrays only ever grow (append + dedupe), so a length past the last flush
147
+ // is exactly "this step surfaced something new".
148
+ const grew = evidence.steps.length > flushed.steps.length ||
149
+ evidence.bugs.length > flushed.bugs.length ||
150
+ evidence.visual.length > flushed.visual.length;
151
+ if (!grew)
253
152
  return null;
254
153
  return {
255
154
  status: 'running',
256
- steps: [...running.steps],
257
- bugs: [...running.bugs],
258
- visual: [...running.visual],
155
+ steps: [...evidence.steps],
156
+ bugs: [...evidence.bugs],
157
+ visual: [...evidence.visual],
259
158
  };
260
159
  }
261
160
  /** Summarize a finished step for `logs/agent.log`: the tools it called (+ input) + any error text. */
@@ -323,18 +222,24 @@ function withUndeliveredInbox(report, inbox) {
323
222
  * folds in mid-run messages; after each step `onStepFinish` flushes the running
324
223
  * trail (skipping the `report` step, which writes the final verdict itself).
325
224
  */
225
+ /** Run-long step budget of a built agent — shared by every `generate` re-entry. */
226
+ const stepsLeft = new WeakMap();
326
227
  export function createDebugAgent(options) {
327
- const { model, tools, instructions, inbox, progress, log, maxSteps = DEFAULT_MAX_STEPS, trail = [], } = options;
228
+ const { model, tools, instructions, inbox, progress, log, maxSteps = DEFAULT_MAX_STEPS, trail, } = options;
328
229
  let stepIndex = 0;
230
+ // Steps STARTED, run-long. The SDK's own `stepNumber` restarts at 0 on every
231
+ // `generate`, and `runDebugLoop` re-enters after a no-tool-call step — the cap
232
+ // and the budget nudge must count across re-entries, or a stalling driver
233
+ // would get a fresh budget each time.
234
+ let started = 0;
329
235
  // Run-long list of mid-run caller instructions: drained from the inbox once,
330
- // re-folded into EVERY step's prompt (the SDK never persists a prepareStep override).
236
+ // re-folded into EVERY step's prompt (AI SDK 7 persists the previous override;
237
+ // `stripInjectedStepMessages` drops it before the re-fold).
331
238
  const standing = [];
332
- // The running flush's accumulators. `steps` IS the shared act trail (same array
333
- // the `act` and `report` tools hold — `act` writes it at act time); bugs/visual
334
- // accumulate here only — they are streamed evidence, and the driver owns the
335
- // terminal verdict's own arrays.
336
- const running = { steps: trail, bugs: [], visual: [] };
337
- return new ToolLoopAgent({
239
+ // What the running flush has already persisted. The trail's arrays only grow,
240
+ // so growth past these lengths is exactly "this step surfaced something new".
241
+ let flushed = EMPTY_EVIDENCE;
242
+ const agent = new ToolLoopAgent({
338
243
  model,
339
244
  tools: { ...tools, report: withUndeliveredInbox(tools.report, inbox) },
340
245
  instructions,
@@ -346,42 +251,70 @@ export function createDebugAgent(options) {
346
251
  // `report` actually ran and wrote the verdict; anything else keeps the loop
347
252
  // going, and the driver gets the tool-error and retries.
348
253
  stopWhen: [
349
- stepCountIs(maxSteps),
254
+ () => started >= maxSteps,
350
255
  ({ steps }) => steps.at(-1)?.toolResults.some((r) => r.toolName === 'report') ?? false,
351
256
  ],
352
- prepareStep: ({ messages, stepNumber }) => {
257
+ prepareStep: ({ messages }) => {
258
+ const stepNumber = started;
259
+ started += 1;
260
+ // AI SDK 7 persists the previous step's override into `messages` — strip
261
+ // its fold/nudge so both rebuild fresh: the fold never duplicates, the
262
+ // nudge reflects THIS step's remaining budget.
263
+ const stripped = stripInjectedStepMessages(messages);
353
264
  // Self-look frame hygiene first: only the newest screenshot stays live.
354
- const pruned = pruneStaleFrames(messages);
265
+ const pruned = pruneStaleFrames(stripped);
355
266
  const withInbox = foldInstructionsIntoStep(inbox, standing, pruned);
356
267
  const base = 'messages' in withInbox ? withInbox.messages : pruned;
357
268
  const nudge = budgetNudge(stepNumber, maxSteps);
358
269
  if (nudge)
359
270
  return { messages: [...base, { role: 'user', content: nudge }] };
360
- if (base === messages)
271
+ if (base === stripped)
361
272
  return {};
362
273
  return { messages: base };
363
274
  },
364
275
  onStepFinish: async (step) => {
365
276
  stepIndex += 1;
366
277
  log?.(describeStep(step, stepIndex));
367
- // Stream this step's new `look` issues + console errors and flush a running
368
- // snapshot of the shared trail (`act` already recorded its own steps there).
369
- // The terminal `report` step writes its own verdict — with that same trail
370
- // merged into `steps` (see `createReportTool`) — so the running flush steps
371
- // aside for it (`progressForStep` returns null on the report step).
372
- const snapshot = progressForStep(step, running);
373
- if (snapshot)
278
+ // Stream whatever grew on the shared evidence trail this step (the belt's
279
+ // tools already recorded it). The terminal `report` step writes its own
280
+ // verdict — with that same trail merged in (see `createReportTool`) — so
281
+ // the running flush steps aside for it (`progressForStep` returns null).
282
+ const snapshot = progressForStep(step, trail ?? EMPTY_EVIDENCE, flushed);
283
+ if (snapshot) {
374
284
  await progress.writeFindings(snapshot);
285
+ flushed = {
286
+ steps: snapshot.steps,
287
+ bugs: snapshot.bugs,
288
+ visual: snapshot.visual,
289
+ };
290
+ }
375
291
  },
376
292
  });
293
+ stepsLeft.set(agent, () => maxSteps - started);
294
+ return agent;
377
295
  }
378
296
  /**
379
297
  * Run the loop to its verdict. Resolves with the agent's generate result once the
380
298
  * driver reports (or the step cap trips); rejects if aborted (fail loud — the
381
299
  * session decides what an aborted run means).
300
+ *
301
+ * A step with no tool call ends the SDK's loop, so while step budget remains the
302
+ * run re-enters with the transcript so far plus {@link NO_TOOL_CALL_NUDGE}. Each
303
+ * re-entry spends a step of the SAME run-long budget, so it can never spin.
304
+ * Only a NORMAL prose completion (`stop`) re-enters: a content-filtered, errored
305
+ * or truncated turn would just be re-asked the same way until the budget is gone.
382
306
  */
383
- export function runDebugLoop(options) {
307
+ export async function runDebugLoop(options) {
384
308
  const { agent, abortSignal, prompt = KICKOFF_PROMPT } = options;
385
- return agent.generate({ prompt, ...(abortSignal ? { abortSignal } : {}) });
309
+ const signal = abortSignal ? { abortSignal } : {};
310
+ const remaining = stepsLeft.get(agent) ?? (() => 0);
311
+ const messages = [{ role: 'user', content: prompt }];
312
+ let result = await agent.generate({ messages, ...signal });
313
+ const talkedInsteadOfActing = () => result.finishReason === 'stop' && result.steps.at(-1)?.toolCalls.length === 0;
314
+ while (talkedInsteadOfActing() && remaining() > 0) {
315
+ messages.push(...result.responseMessages, { role: 'user', content: NO_TOOL_CALL_NUDGE });
316
+ result = await agent.generate({ messages, ...signal });
317
+ }
318
+ return result;
386
319
  }
387
320
  //# sourceMappingURL=loop.js.map