@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.
- package/README.md +63 -47
- package/dist/adapters/android/abortable.d.ts +6 -0
- package/dist/adapters/android/abortable.js +22 -0
- package/dist/adapters/android/abortable.js.map +1 -0
- package/dist/adapters/android/adb.d.ts +19 -7
- package/dist/adapters/android/adb.js +50 -13
- package/dist/adapters/android/adb.js.map +1 -1
- package/dist/adapters/android/android-adapter.d.ts +20 -12
- package/dist/adapters/android/android-adapter.js +113 -165
- package/dist/adapters/android/android-adapter.js.map +1 -1
- package/dist/adapters/android/commands.d.ts +10 -0
- package/dist/adapters/android/commands.js +22 -0
- package/dist/adapters/android/commands.js.map +1 -1
- package/dist/adapters/android/emulator.d.ts +41 -0
- package/dist/adapters/android/emulator.js +115 -0
- package/dist/adapters/android/emulator.js.map +1 -0
- package/dist/adapters/android/logcat.d.ts +87 -0
- package/dist/adapters/android/logcat.js +352 -0
- package/dist/adapters/android/logcat.js.map +1 -0
- package/dist/adapters/android/ports.js.map +1 -1
- package/dist/adapters/android/sdk.d.ts +65 -0
- package/dist/adapters/android/sdk.js +107 -0
- package/dist/adapters/android/sdk.js.map +1 -0
- package/dist/adapters/android/uiautomator.d.ts +23 -7
- package/dist/adapters/android/uiautomator.js +31 -7
- package/dist/adapters/android/uiautomator.js.map +1 -1
- package/dist/adapters/availability.d.ts +39 -0
- package/dist/adapters/availability.js +62 -0
- package/dist/adapters/availability.js.map +1 -0
- package/dist/adapters/browser/browser-adapter.d.ts +11 -22
- package/dist/adapters/browser/browser-adapter.js +90 -71
- package/dist/adapters/browser/browser-adapter.js.map +1 -1
- package/dist/adapters/browser/cdp.d.ts +22 -17
- package/dist/adapters/browser/cdp.js +118 -72
- package/dist/adapters/browser/cdp.js.map +1 -1
- package/dist/adapters/browser/exchange-read.d.ts +39 -0
- package/dist/adapters/browser/exchange-read.js +102 -0
- package/dist/adapters/browser/exchange-read.js.map +1 -0
- package/dist/adapters/browser/extractor.js +9 -2
- package/dist/adapters/browser/extractor.js.map +1 -1
- package/dist/adapters/browser/filters.d.ts +1 -1
- package/dist/adapters/browser/filters.js.map +1 -1
- package/dist/adapters/browser/geometry.js.map +1 -1
- package/dist/adapters/browser/launch.d.ts +14 -5
- package/dist/adapters/browser/launch.js +14 -5
- package/dist/adapters/browser/launch.js.map +1 -1
- package/dist/adapters/browser/lifecycle.d.ts +91 -0
- package/dist/adapters/browser/lifecycle.js +141 -0
- package/dist/adapters/browser/lifecycle.js.map +1 -0
- package/dist/adapters/browser/locate.d.ts +18 -2
- package/dist/adapters/browser/locate.js +48 -3
- package/dist/adapters/browser/locate.js.map +1 -1
- package/dist/adapters/browser/log-filters.d.ts +2 -2
- package/dist/adapters/browser/log-filters.js +15 -4
- package/dist/adapters/browser/log-filters.js.map +1 -1
- package/dist/adapters/browser/log-format.d.ts +23 -20
- package/dist/adapters/browser/log-format.js +133 -56
- package/dist/adapters/browser/log-format.js.map +1 -1
- package/dist/adapters/browser/tab-context.d.ts +30 -0
- package/dist/adapters/browser/tab-context.js +41 -0
- package/dist/adapters/browser/tab-context.js.map +1 -0
- package/dist/adapters/contract.d.ts +113 -10
- package/dist/adapters/contract.js +7 -2
- package/dist/adapters/contract.js.map +1 -1
- package/dist/adapters/desktop/atspi-busctl.d.ts +26 -0
- package/dist/adapters/desktop/atspi-busctl.js +332 -0
- package/dist/adapters/desktop/atspi-busctl.js.map +1 -0
- package/dist/adapters/desktop/atspi-parse.d.ts +39 -0
- package/dist/adapters/desktop/atspi-parse.js +155 -0
- package/dist/adapters/desktop/atspi-parse.js.map +1 -0
- package/dist/adapters/desktop/atspi.d.ts +81 -50
- package/dist/adapters/desktop/atspi.js +64 -285
- package/dist/adapters/desktop/atspi.js.map +1 -1
- package/dist/adapters/desktop/capture.d.ts +11 -20
- package/dist/adapters/desktop/capture.js +68 -37
- package/dist/adapters/desktop/capture.js.map +1 -1
- package/dist/adapters/desktop/desktop-adapter.d.ts +22 -2
- package/dist/adapters/desktop/desktop-adapter.js +202 -86
- package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
- package/dist/adapters/desktop/input.d.ts +19 -5
- package/dist/adapters/desktop/input.js +29 -13
- package/dist/adapters/desktop/input.js.map +1 -1
- package/dist/adapters/desktop/managed-app.d.ts +43 -0
- package/dist/adapters/desktop/managed-app.js +114 -0
- package/dist/adapters/desktop/managed-app.js.map +1 -0
- package/dist/adapters/desktop/proc.d.ts +34 -4
- package/dist/adapters/desktop/proc.js +37 -6
- package/dist/adapters/desktop/proc.js.map +1 -1
- package/dist/adapters/desktop/wait-poll.d.ts +17 -0
- package/dist/adapters/desktop/wait-poll.js +38 -0
- package/dist/adapters/desktop/wait-poll.js.map +1 -0
- package/dist/adapters/factory.d.ts +13 -6
- package/dist/adapters/factory.js +30 -4
- package/dist/adapters/factory.js.map +1 -1
- package/dist/adapters/log-format.d.ts +38 -0
- package/dist/adapters/log-format.js +47 -0
- package/dist/adapters/log-format.js.map +1 -0
- package/dist/agent/belt/act.d.ts +426 -23
- package/dist/agent/belt/act.js +44 -64
- package/dist/agent/belt/act.js.map +1 -1
- package/dist/agent/belt/look.d.ts +479 -16
- package/dist/agent/belt/look.js +94 -16
- package/dist/agent/belt/look.js.map +1 -1
- package/dist/agent/belt/observe.d.ts +652 -65
- package/dist/agent/belt/observe.js +119 -231
- package/dist/agent/belt/observe.js.map +1 -1
- package/dist/agent/belt/redact-output.d.ts +20 -0
- package/dist/agent/belt/redact-output.js +70 -0
- package/dist/agent/belt/redact-output.js.map +1 -0
- package/dist/agent/belt/report.d.ts +754 -48
- package/dist/agent/belt/report.js +121 -38
- package/dist/agent/belt/report.js.map +1 -1
- package/dist/agent/belt/same-origin.d.ts +21 -0
- package/dist/agent/belt/same-origin.js +38 -0
- package/dist/agent/belt/same-origin.js.map +1 -0
- package/dist/agent/belt/target-refs.d.ts +39 -0
- package/dist/agent/belt/target-refs.js +60 -0
- package/dist/agent/belt/target-refs.js.map +1 -0
- package/dist/agent/belt/trail.d.ts +44 -16
- package/dist/agent/belt/trail.js +46 -11
- package/dist/agent/belt/trail.js.map +1 -1
- package/dist/agent/belt/tree-targets.d.ts +79 -0
- package/dist/agent/belt/tree-targets.js +242 -0
- package/dist/agent/belt/tree-targets.js.map +1 -0
- package/dist/agent/capabilities.js.map +1 -1
- package/dist/agent/fallback.d.ts +33 -0
- package/dist/agent/fallback.js +84 -0
- package/dist/agent/fallback.js.map +1 -0
- package/dist/agent/loop-frames.d.ts +26 -0
- package/dist/agent/loop-frames.js +106 -0
- package/dist/agent/loop-frames.js.map +1 -0
- package/dist/agent/loop.d.ts +56 -65
- package/dist/agent/loop.js +122 -189
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/models.d.ts +10 -6
- package/dist/agent/models.js +15 -9
- package/dist/agent/models.js.map +1 -1
- package/dist/agent/prompts/compose.d.ts +1 -1
- package/dist/agent/prompts/debug-agent.js +48 -10
- package/dist/agent/prompts/debug-agent.js.map +1 -1
- package/dist/agent/prompts/web-addendum.d.ts +2 -2
- package/dist/agent/prompts/web-addendum.js +26 -25
- package/dist/agent/prompts/web-addendum.js.map +1 -1
- package/dist/agent/provider.d.ts +41 -1
- package/dist/agent/provider.js +59 -5
- package/dist/agent/provider.js.map +1 -1
- package/dist/boot.d.ts +64 -0
- package/dist/boot.js +147 -0
- package/dist/boot.js.map +1 -0
- package/dist/cli/chromium-libs.d.ts +267 -0
- package/dist/cli/chromium-libs.js +546 -0
- package/dist/cli/chromium-libs.js.map +1 -0
- package/dist/cli/control.js +79 -12
- package/dist/cli/control.js.map +1 -1
- package/dist/cli/init.d.ts +52 -3
- package/dist/cli/init.js +62 -10
- package/dist/cli/init.js.map +1 -1
- package/dist/config/load.d.ts +25 -8
- package/dist/config/load.js +50 -13
- package/dist/config/load.js.map +1 -1
- package/dist/config/schema.d.ts +18 -6
- package/dist/config/schema.js +34 -17
- package/dist/config/schema.js.map +1 -1
- package/dist/errors.d.ts +30 -15
- package/dist/errors.js +49 -30
- package/dist/errors.js.map +1 -1
- package/dist/findings/schema.d.ts +44 -6
- package/dist/findings/schema.js +39 -3
- package/dist/findings/schema.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.js +4 -82
- package/dist/main.js.map +1 -1
- package/dist/mcp/server.js +10 -1
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools/describe.d.ts +5 -4
- package/dist/mcp/tools/describe.js +14 -10
- package/dist/mcp/tools/describe.js.map +1 -1
- package/dist/mcp/tools/end-session.d.ts +3 -1
- package/dist/mcp/tools/end-session.js +8 -3
- package/dist/mcp/tools/end-session.js.map +1 -1
- package/dist/mcp/tools/output.d.ts +12 -4
- package/dist/mcp/tools/output.js +15 -2
- package/dist/mcp/tools/output.js.map +1 -1
- package/dist/mcp/tools/result.d.ts +10 -1
- package/dist/mcp/tools/result.js +12 -7
- package/dist/mcp/tools/result.js.map +1 -1
- package/dist/mcp/tools/start-debug.js +7 -5
- package/dist/mcp/tools/start-debug.js.map +1 -1
- package/dist/redact.d.ts +44 -0
- package/dist/redact.js +166 -0
- package/dist/redact.js.map +1 -0
- package/dist/services/auth-persona.d.ts +19 -0
- package/dist/services/auth-persona.js +32 -0
- package/dist/services/auth-persona.js.map +1 -0
- package/dist/services/catalog.d.ts +28 -0
- package/dist/services/catalog.js +65 -0
- package/dist/services/catalog.js.map +1 -0
- package/dist/services/debug-api.d.ts +179 -0
- package/dist/services/debug-api.js +9 -0
- package/dist/services/debug-api.js.map +1 -0
- package/dist/services/debug-service.d.ts +26 -174
- package/dist/services/debug-service.js +159 -227
- package/dist/services/debug-service.js.map +1 -1
- package/dist/services/foreign-findings.d.ts +22 -0
- package/dist/services/foreign-findings.js +38 -0
- package/dist/services/foreign-findings.js.map +1 -0
- package/dist/services/login-failure.d.ts +10 -0
- package/dist/services/login-failure.js +24 -0
- package/dist/services/login-failure.js.map +1 -0
- package/dist/services/login-selectors.d.ts +18 -0
- package/dist/services/login-selectors.js +44 -0
- package/dist/services/login-selectors.js.map +1 -0
- package/dist/services/login-session.d.ts +25 -0
- package/dist/services/login-session.js +59 -0
- package/dist/services/login-session.js.map +1 -0
- package/dist/services/login.d.ts +16 -29
- package/dist/services/login.js +269 -97
- package/dist/services/login.js.map +1 -1
- package/dist/services/replay.js +15 -3
- package/dist/services/replay.js.map +1 -1
- package/dist/services/retained-snapshot.d.ts +36 -0
- package/dist/services/retained-snapshot.js +63 -0
- package/dist/services/retained-snapshot.js.map +1 -0
- package/dist/services/session-builder.d.ts +26 -0
- package/dist/services/session-builder.js +63 -21
- package/dist/services/session-builder.js.map +1 -1
- package/dist/services/shutdown.d.ts +8 -4
- package/dist/services/shutdown.js +21 -8
- package/dist/services/shutdown.js.map +1 -1
- package/dist/services/start-guards.d.ts +37 -0
- package/dist/services/start-guards.js +61 -0
- package/dist/services/start-guards.js.map +1 -0
- package/dist/services/summarize.d.ts +12 -3
- package/dist/services/summarize.js +13 -5
- package/dist/services/summarize.js.map +1 -1
- package/dist/session/cleanup.d.ts +3 -2
- package/dist/session/cleanup.js +6 -2
- package/dist/session/cleanup.js.map +1 -1
- package/dist/session/finalize.d.ts +45 -0
- package/dist/session/finalize.js +150 -0
- package/dist/session/finalize.js.map +1 -0
- package/dist/session/findings-store.d.ts +2 -1
- package/dist/session/findings-store.js +30 -2
- package/dist/session/findings-store.js.map +1 -1
- package/dist/session/flock-backend.d.ts +117 -0
- package/dist/session/flock-backend.js +293 -0
- package/dist/session/flock-backend.js.map +1 -0
- package/dist/session/live-pointer.d.ts +19 -0
- package/dist/session/live-pointer.js +41 -0
- package/dist/session/live-pointer.js.map +1 -0
- package/dist/session/manager.d.ts +11 -1
- package/dist/session/manager.js +46 -2
- package/dist/session/manager.js.map +1 -1
- package/dist/session/owner-lock.d.ts +117 -0
- package/dist/session/owner-lock.js +218 -0
- package/dist/session/owner-lock.js.map +1 -0
- package/dist/session/process-identity.js.map +1 -1
- package/dist/session/session.js +40 -109
- package/dist/session/session.js.map +1 -1
- package/dist/session/state-file.d.ts +74 -14
- package/dist/session/state-file.js +211 -21
- package/dist/session/state-file.js.map +1 -1
- package/dist/session/workspace.d.ts +32 -2
- package/dist/session/workspace.js +65 -4
- package/dist/session/workspace.js.map +1 -1
- package/package.json +11 -11
- package/dist/adapters/android/android-adapter.test-helpers.d.ts +0 -52
- package/dist/adapters/android/android-adapter.test-helpers.js +0 -115
- package/dist/adapters/android/android-adapter.test-helpers.js.map +0 -1
- package/dist/mcp/server.test-helpers.d.ts +0 -23
- package/dist/mcp/server.test-helpers.js +0 -49
- package/dist/mcp/server.test-helpers.js.map +0 -1
package/dist/agent/loop.d.ts
CHANGED
|
@@ -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
|
|
13
|
-
* (
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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 {
|
|
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:
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
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
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* `
|
|
105
|
-
*
|
|
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
|
|
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
|
|
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
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
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,
|
|
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
|
|
170
|
-
* `
|
|
171
|
-
*
|
|
172
|
-
*
|
|
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?:
|
|
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>>;
|
package/dist/agent/loop.js
CHANGED
|
@@ -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
|
|
13
|
-
* (
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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 {
|
|
26
|
-
import {
|
|
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
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
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
|
|
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:
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
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
|
-
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* `
|
|
124
|
-
*
|
|
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
|
|
127
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
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,
|
|
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
|
-
//
|
|
243
|
-
//
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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: [...
|
|
257
|
-
bugs: [...
|
|
258
|
-
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
|
|
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 (
|
|
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
|
-
//
|
|
333
|
-
//
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
|
|
254
|
+
() => started >= maxSteps,
|
|
350
255
|
({ steps }) => steps.at(-1)?.toolResults.some((r) => r.toolName === 'report') ?? false,
|
|
351
256
|
],
|
|
352
|
-
prepareStep: ({ messages
|
|
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(
|
|
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 ===
|
|
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
|
|
368
|
-
//
|
|
369
|
-
//
|
|
370
|
-
//
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
|
|
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
|