@tangle-network/browser-agent-driver 0.24.2 → 0.25.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/dist/cli-preview.d.ts +59 -0
- package/dist/cli-preview.d.ts.map +1 -0
- package/dist/cli-preview.js +144 -0
- package/dist/cli-preview.js.map +1 -0
- package/dist/cli-share.d.ts +77 -0
- package/dist/cli-share.d.ts.map +1 -0
- package/dist/cli-share.js +141 -0
- package/dist/cli-share.js.map +1 -0
- package/dist/cli-ui.d.ts.map +1 -1
- package/dist/cli-ui.js +8 -4
- package/dist/cli-ui.js.map +1 -1
- package/dist/cli.js +153 -5
- package/dist/cli.js.map +1 -1
- package/dist/drivers/cursor-overlay.d.ts +18 -10
- package/dist/drivers/cursor-overlay.d.ts.map +1 -1
- package/dist/drivers/cursor-overlay.js +221 -30
- package/dist/drivers/cursor-overlay.js.map +1 -1
- package/dist/drivers/overlay-label.d.ts +33 -0
- package/dist/drivers/overlay-label.d.ts.map +1 -0
- package/dist/drivers/overlay-label.js +92 -0
- package/dist/drivers/overlay-label.js.map +1 -0
- package/dist/drivers/playwright.d.ts +22 -0
- package/dist/drivers/playwright.d.ts.map +1 -1
- package/dist/drivers/playwright.js +87 -9
- package/dist/drivers/playwright.js.map +1 -1
- package/dist/drivers/snapshot.d.ts +12 -0
- package/dist/drivers/snapshot.d.ts.map +1 -1
- package/dist/drivers/snapshot.js +17 -0
- package/dist/drivers/snapshot.js.map +1 -1
- package/dist/drivers/types.d.ts +8 -0
- package/dist/drivers/types.d.ts.map +1 -1
- package/dist/runner/interrupt-controller.d.ts +67 -0
- package/dist/runner/interrupt-controller.d.ts.map +1 -0
- package/dist/runner/interrupt-controller.js +142 -0
- package/dist/runner/interrupt-controller.js.map +1 -0
- package/dist/runner/overlay-narration.d.ts +83 -0
- package/dist/runner/overlay-narration.d.ts.map +1 -0
- package/dist/runner/overlay-narration.js +172 -0
- package/dist/runner/overlay-narration.js.map +1 -0
- package/dist/runner/runner.d.ts +9 -0
- package/dist/runner/runner.d.ts.map +1 -1
- package/dist/runner/runner.js +46 -0
- package/dist/runner/runner.js.map +1 -1
- package/dist/runner/stream-webhook.d.ts +70 -0
- package/dist/runner/stream-webhook.d.ts.map +1 -0
- package/dist/runner/stream-webhook.js +132 -0
- package/dist/runner/stream-webhook.js.map +1 -0
- package/dist/test-runner.d.ts +7 -0
- package/dist/test-runner.d.ts.map +1 -1
- package/dist/test-runner.js +3 -0
- package/dist/test-runner.js.map +1 -1
- package/dist/viewer/viewer.html +122 -8
- package/package.json +2 -2
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gen 32 — pause / resume / abort via keyboard in interactive runs.
|
|
3
|
+
*
|
|
4
|
+
* Registers a raw-mode stdin handler that maps three keys:
|
|
5
|
+
*
|
|
6
|
+
* p → pause the runner before the next turn
|
|
7
|
+
* r → resume a paused run
|
|
8
|
+
* q → abort (the same as Ctrl-C, but doesn't kill the TTY)
|
|
9
|
+
*
|
|
10
|
+
* The controller exposes a single `waitIfPaused()` the runner awaits at
|
|
11
|
+
* the top of every turn. When the user hits `p`, the next call blocks
|
|
12
|
+
* on a resume promise. On `r`, the promise resolves and the loop
|
|
13
|
+
* continues. On `q`, it throws an abort signal the runner treats as a
|
|
14
|
+
* graceful cancellation.
|
|
15
|
+
*
|
|
16
|
+
* Design notes:
|
|
17
|
+
* - Raw mode only applies to a TTY. Non-interactive runs (CI,
|
|
18
|
+
* `bad --cases ... --json`) never engage this controller.
|
|
19
|
+
* - Keyboard capture is OPT-IN via `--interrupt`. Without it, the
|
|
20
|
+
* stdin is untouched and this module is a no-op.
|
|
21
|
+
* - Keyboard capture deliberately does NOT interfere with copy/paste
|
|
22
|
+
* — we only listen for the specific bytes `p`, `r`, `q`, and let
|
|
23
|
+
* everything else fall through unmodified.
|
|
24
|
+
*/
|
|
25
|
+
import { EventEmitter } from 'node:events';
|
|
26
|
+
export class InterruptAborted extends Error {
|
|
27
|
+
constructor() {
|
|
28
|
+
super('run aborted by user (pressed q)');
|
|
29
|
+
this.name = 'InterruptAborted';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class InterruptController extends EventEmitter {
|
|
33
|
+
paused = false;
|
|
34
|
+
aborted = false;
|
|
35
|
+
resumeResolvers = [];
|
|
36
|
+
input;
|
|
37
|
+
onStatus;
|
|
38
|
+
attached = false;
|
|
39
|
+
handler = (buf) => this.onKey(buf);
|
|
40
|
+
prevRaw = false;
|
|
41
|
+
constructor(opts = {}) {
|
|
42
|
+
super();
|
|
43
|
+
this.input = opts.input ?? process.stdin;
|
|
44
|
+
this.onStatus = opts.onStatus ?? (() => { });
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Start listening for keystrokes. Returns a detach function the
|
|
48
|
+
* caller MUST invoke when the run ends (even on error) — otherwise
|
|
49
|
+
* stdin stays in raw mode and the TTY is hosed.
|
|
50
|
+
*/
|
|
51
|
+
attach() {
|
|
52
|
+
if (this.attached)
|
|
53
|
+
return () => this.detach();
|
|
54
|
+
if (!this.input.isTTY)
|
|
55
|
+
return () => { };
|
|
56
|
+
this.prevRaw = this.input.isRaw;
|
|
57
|
+
this.input.setRawMode(true);
|
|
58
|
+
this.input.resume();
|
|
59
|
+
this.input.on('data', this.handler);
|
|
60
|
+
this.attached = true;
|
|
61
|
+
this.onStatus('interrupt keys: [p] pause · [r] resume · [q] abort');
|
|
62
|
+
return () => this.detach();
|
|
63
|
+
}
|
|
64
|
+
detach() {
|
|
65
|
+
if (!this.attached)
|
|
66
|
+
return;
|
|
67
|
+
try {
|
|
68
|
+
this.input.off('data', this.handler);
|
|
69
|
+
this.input.setRawMode(this.prevRaw);
|
|
70
|
+
if (!process.stdin.isTTY || !this.prevRaw) {
|
|
71
|
+
this.input.pause();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch { /* best-effort on shutdown */ }
|
|
75
|
+
this.attached = false;
|
|
76
|
+
// Release any awaiters so the runner can unwind.
|
|
77
|
+
for (const r of this.resumeResolvers)
|
|
78
|
+
r();
|
|
79
|
+
this.resumeResolvers = [];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Called from the runner at the top of each turn. If the run is paused,
|
|
83
|
+
* awaits resume. If aborted, throws `InterruptAborted`.
|
|
84
|
+
*/
|
|
85
|
+
async waitIfPaused() {
|
|
86
|
+
if (this.aborted)
|
|
87
|
+
throw new InterruptAborted();
|
|
88
|
+
if (!this.paused)
|
|
89
|
+
return;
|
|
90
|
+
await new Promise((resolve) => this.resumeResolvers.push(resolve));
|
|
91
|
+
if (this.aborted)
|
|
92
|
+
throw new InterruptAborted();
|
|
93
|
+
}
|
|
94
|
+
/** Programmatically pause — useful from tests and SIGUSR1 handlers. */
|
|
95
|
+
pause() {
|
|
96
|
+
if (this.paused || this.aborted)
|
|
97
|
+
return;
|
|
98
|
+
this.paused = true;
|
|
99
|
+
this.emit('pause');
|
|
100
|
+
this.onStatus('⏸ paused — press [r] to resume or [q] to abort');
|
|
101
|
+
}
|
|
102
|
+
/** Programmatically resume. */
|
|
103
|
+
resume() {
|
|
104
|
+
if (!this.paused || this.aborted)
|
|
105
|
+
return;
|
|
106
|
+
this.paused = false;
|
|
107
|
+
this.emit('resume');
|
|
108
|
+
this.onStatus('▶ resumed');
|
|
109
|
+
for (const r of this.resumeResolvers)
|
|
110
|
+
r();
|
|
111
|
+
this.resumeResolvers = [];
|
|
112
|
+
}
|
|
113
|
+
/** Request a graceful abort. */
|
|
114
|
+
abort() {
|
|
115
|
+
if (this.aborted)
|
|
116
|
+
return;
|
|
117
|
+
this.aborted = true;
|
|
118
|
+
this.emit('abort');
|
|
119
|
+
this.onStatus('■ aborting — run will stop at the end of this turn');
|
|
120
|
+
for (const r of this.resumeResolvers)
|
|
121
|
+
r();
|
|
122
|
+
this.resumeResolvers = [];
|
|
123
|
+
}
|
|
124
|
+
get isPaused() { return this.paused; }
|
|
125
|
+
get isAborted() { return this.aborted; }
|
|
126
|
+
onKey(buf) {
|
|
127
|
+
// Match a single byte for p/r/q; fall through for everything else.
|
|
128
|
+
// Ctrl-C (0x03) from raw mode — forward as abort, else the process stays alive.
|
|
129
|
+
if (buf.length === 1 && buf[0] === 0x03) {
|
|
130
|
+
this.abort();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const ch = buf.toString('utf-8');
|
|
134
|
+
if (ch === 'p' || ch === 'P')
|
|
135
|
+
this.pause();
|
|
136
|
+
else if (ch === 'r' || ch === 'R')
|
|
137
|
+
this.resume();
|
|
138
|
+
else if (ch === 'q' || ch === 'Q')
|
|
139
|
+
this.abort();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=interrupt-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interrupt-controller.js","sourceRoot":"","sources":["../../src/runner/interrupt-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC;QACE,KAAK,CAAC,iCAAiC,CAAC,CAAA;QACxC,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;IAChC,CAAC;CACF;AASD,MAAM,OAAO,mBAAoB,SAAQ,YAAY;IAC3C,MAAM,GAAG,KAAK,CAAA;IACd,OAAO,GAAG,KAAK,CAAA;IACf,eAAe,GAAsB,EAAE,CAAA;IACvC,KAAK,CAAmB;IACxB,QAAQ,CAAqD;IAC7D,QAAQ,GAAG,KAAK,CAAA;IAChB,OAAO,GAAG,CAAC,GAAW,EAAQ,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAChD,OAAO,GAAG,KAAK,CAAA;IAEvB,YAAY,OAAmC,EAAE;QAC/C,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IA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GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAClB,IAAI,CAAC,QAAQ,CAAC,qDAAqD,CAAC,CAAA;QACpE,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,eAAe;YAAE,CAAC,EAAE,CAAA;QACzC,IAAI,CAAC,eAAe,GAAG,EAAE,CAAA;IAC3B,CAAC;IAED,IAAI,QAAQ,KAAc,OAAO,IAAI,CAAC,MAAM,CAAA,CAAC,CAAC;IAC9C,IAAI,SAAS,KAAc,OAAO,IAAI,CAAC,OAAO,CAAA,CAAC,CAAC;IAExC,KAAK,CAAC,GAAW;QACvB,mEAAmE;QACnE,gFAAgF;QAChF,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACxC,IAAI,CAAC,KAAK,EAAE,CAAA;YACZ,OAAM;QACR,CAAC;QACD,MAAM,EAAE,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;QAChC,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG;YAAE,IAAI,CAAC,KAAK,EAAE,CAAA;aACrC,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG;YAAE,IAAI,CAAC,MAAM,EAAE,CAAA;aAC3C,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG;YAAE,IAAI,CAAC,KAAK,EAAE,CAAA;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gen 32 — agent narration hooks for the cursor overlay.
|
|
3
|
+
*
|
|
4
|
+
* The runner emits `decide-completed` each turn with the LLM's raw
|
|
5
|
+
* reasoning text. That text carries three distinct signals the overlay
|
|
6
|
+
* wants to surface to a viewer:
|
|
7
|
+
*
|
|
8
|
+
* 1. **Current step** — a short phrase summarizing what the agent is
|
|
9
|
+
* about to do. Extracted from the first sentence of `reasoning`.
|
|
10
|
+
* 2. **Progress** — turn N of maxTurns, plus any inline progress
|
|
11
|
+
* ledger (`Done=[C-001, C-002, ...] Current=C-003`) the agent is
|
|
12
|
+
* already using in OFAC/batch-style prompts.
|
|
13
|
+
* 3. **Verdict moments** — conclusions like "POSITIVE MATCH",
|
|
14
|
+
* "CLEARED", "NEEDS REVIEW" that should fire a celebratory badge.
|
|
15
|
+
*
|
|
16
|
+
* These are pure functions — no I/O, no driver calls. The driver-facing
|
|
17
|
+
* hooks in runner.ts call them, then push results via
|
|
18
|
+
* `driver.setOverlayReasoning` / `setOverlayProgress` / `pushOverlayBadge`.
|
|
19
|
+
*
|
|
20
|
+
* Why a separate module: the runner is already 1500+ lines and dense;
|
|
21
|
+
* parsing logic belongs somewhere testable in isolation. Keeping this
|
|
22
|
+
* pure makes the overlay story auditable without standing up a browser.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Pull the first sentence (or first ~140 chars) of reasoning as a
|
|
26
|
+
* display summary. The reasoning panel renders the full text; this is a
|
|
27
|
+
* hook for callers that want a preview (e.g., badge text).
|
|
28
|
+
*/
|
|
29
|
+
export declare function summarizeReasoning(reasoning: string | undefined): string;
|
|
30
|
+
/**
|
|
31
|
+
* Parse a "Current=C-XXX" marker from the reasoning, if present. Used to
|
|
32
|
+
* enrich the progress label ("Turn 27 · C-003"). Returns undefined when
|
|
33
|
+
* the reasoning doesn't carry a ledger marker — NOT every run uses the
|
|
34
|
+
* ledger shape.
|
|
35
|
+
*/
|
|
36
|
+
export declare function extractCurrentMarker(reasoning: string | undefined): string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Parse a "Done=[...]" ledger from reasoning. Returns the count of
|
|
39
|
+
* completed items, or undefined when no ledger exists. Used to compute
|
|
40
|
+
* a second progress indicator (items done vs items total) orthogonal to
|
|
41
|
+
* turn-of-maxTurns.
|
|
42
|
+
*/
|
|
43
|
+
export declare function extractDoneCount(reasoning: string | undefined): number | undefined;
|
|
44
|
+
export interface VerdictEvent {
|
|
45
|
+
kind: 'positive' | 'cleared' | 'review';
|
|
46
|
+
text: string;
|
|
47
|
+
/** Raw verdict substring so we can dedupe later in the session */
|
|
48
|
+
marker: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Scan reasoning + action text for new verdict-worthy moments. Returns
|
|
52
|
+
* an array (possibly empty) of events the driver should surface as
|
|
53
|
+
* badges. The caller is responsible for deduplication across turns —
|
|
54
|
+
* this function returns ALL verdict markers visible in the text.
|
|
55
|
+
*
|
|
56
|
+
* For a reasoning string like:
|
|
57
|
+
* "C-003 PUTIN VLADIMIR: POSITIVE MATCH — Russia-EO14024 / SDN"
|
|
58
|
+
* emits: { kind: 'positive', text: 'C-003 PUTIN VLADIMIR · POSITIVE MATCH', marker: 'C-003:POSITIVE MATCH' }
|
|
59
|
+
*/
|
|
60
|
+
export declare function detectVerdicts(reasoning: string | undefined): VerdictEvent[];
|
|
61
|
+
/**
|
|
62
|
+
* Stateful tracker that holds the set of verdict markers already
|
|
63
|
+
* surfaced this session, so we don't re-emit the same badge every turn
|
|
64
|
+
* for a verdict the agent keeps mentioning in its progress ledger.
|
|
65
|
+
*/
|
|
66
|
+
export declare class VerdictTracker {
|
|
67
|
+
private seen;
|
|
68
|
+
/**
|
|
69
|
+
* Given new reasoning text, return only the verdicts that are NEW
|
|
70
|
+
* (haven't been emitted before in this session).
|
|
71
|
+
*/
|
|
72
|
+
accept(reasoning: string | undefined): VerdictEvent[];
|
|
73
|
+
reset(): void;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Build the progress label shown in the top-left chip of the overlay.
|
|
77
|
+
* Combines turn counter with an optional ledger marker.
|
|
78
|
+
*
|
|
79
|
+
* buildProgressLabel(5, 65) → "Turn 5 · 65 max"
|
|
80
|
+
* buildProgressLabel(5, 65, 'C-003') → "Turn 5 · C-003"
|
|
81
|
+
*/
|
|
82
|
+
export declare function buildProgressLabel(turn: number, maxTurns: number, marker?: string): string;
|
|
83
|
+
//# sourceMappingURL=overlay-narration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-narration.d.ts","sourceRoot":"","sources":["../../src/runner/overlay-narration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAQH;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAQxE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKtF;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAQlF;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAA;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,YAAY,EAAE,CA2C5E;AAED;;;;GAIG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,IAAI,CAAoB;IAEhC;;;OAGG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,YAAY,EAAE;IAWrD,KAAK,IAAI,IAAI;CAGd;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAGR"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gen 32 — agent narration hooks for the cursor overlay.
|
|
3
|
+
*
|
|
4
|
+
* The runner emits `decide-completed` each turn with the LLM's raw
|
|
5
|
+
* reasoning text. That text carries three distinct signals the overlay
|
|
6
|
+
* wants to surface to a viewer:
|
|
7
|
+
*
|
|
8
|
+
* 1. **Current step** — a short phrase summarizing what the agent is
|
|
9
|
+
* about to do. Extracted from the first sentence of `reasoning`.
|
|
10
|
+
* 2. **Progress** — turn N of maxTurns, plus any inline progress
|
|
11
|
+
* ledger (`Done=[C-001, C-002, ...] Current=C-003`) the agent is
|
|
12
|
+
* already using in OFAC/batch-style prompts.
|
|
13
|
+
* 3. **Verdict moments** — conclusions like "POSITIVE MATCH",
|
|
14
|
+
* "CLEARED", "NEEDS REVIEW" that should fire a celebratory badge.
|
|
15
|
+
*
|
|
16
|
+
* These are pure functions — no I/O, no driver calls. The driver-facing
|
|
17
|
+
* hooks in runner.ts call them, then push results via
|
|
18
|
+
* `driver.setOverlayReasoning` / `setOverlayProgress` / `pushOverlayBadge`.
|
|
19
|
+
*
|
|
20
|
+
* Why a separate module: the runner is already 1500+ lines and dense;
|
|
21
|
+
* parsing logic belongs somewhere testable in isolation. Keeping this
|
|
22
|
+
* pure makes the overlay story auditable without standing up a browser.
|
|
23
|
+
*/
|
|
24
|
+
const VERDICT_PATTERNS = [
|
|
25
|
+
{ re: /\bPOSITIVE\s+MATCH\b/i, kind: 'positive' },
|
|
26
|
+
{ re: /\bCLEARED\b/i, kind: 'cleared' },
|
|
27
|
+
{ re: /\bNEEDS\s+REVIEW\b/i, kind: 'review' },
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* Pull the first sentence (or first ~140 chars) of reasoning as a
|
|
31
|
+
* display summary. The reasoning panel renders the full text; this is a
|
|
32
|
+
* hook for callers that want a preview (e.g., badge text).
|
|
33
|
+
*/
|
|
34
|
+
export function summarizeReasoning(reasoning) {
|
|
35
|
+
if (!reasoning)
|
|
36
|
+
return '';
|
|
37
|
+
const collapsed = reasoning.replace(/\s+/g, ' ').trim();
|
|
38
|
+
if (!collapsed)
|
|
39
|
+
return '';
|
|
40
|
+
// Cut at sentence boundary if short; otherwise hard-truncate.
|
|
41
|
+
const firstSentence = collapsed.match(/^(.+?[.!?])\s/);
|
|
42
|
+
if (firstSentence && firstSentence[1].length <= 180)
|
|
43
|
+
return firstSentence[1];
|
|
44
|
+
return collapsed.length > 180 ? collapsed.slice(0, 177).trimEnd() + '…' : collapsed;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parse a "Current=C-XXX" marker from the reasoning, if present. Used to
|
|
48
|
+
* enrich the progress label ("Turn 27 · C-003"). Returns undefined when
|
|
49
|
+
* the reasoning doesn't carry a ledger marker — NOT every run uses the
|
|
50
|
+
* ledger shape.
|
|
51
|
+
*/
|
|
52
|
+
export function extractCurrentMarker(reasoning) {
|
|
53
|
+
if (!reasoning)
|
|
54
|
+
return undefined;
|
|
55
|
+
const m = reasoning.match(/Current\s*=\s*([A-Za-z0-9][\w-]*)/);
|
|
56
|
+
if (m)
|
|
57
|
+
return m[1];
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Parse a "Done=[...]" ledger from reasoning. Returns the count of
|
|
62
|
+
* completed items, or undefined when no ledger exists. Used to compute
|
|
63
|
+
* a second progress indicator (items done vs items total) orthogonal to
|
|
64
|
+
* turn-of-maxTurns.
|
|
65
|
+
*/
|
|
66
|
+
export function extractDoneCount(reasoning) {
|
|
67
|
+
if (!reasoning)
|
|
68
|
+
return undefined;
|
|
69
|
+
const m = reasoning.match(/Done\s*=\s*\[([^\]]*)\]/);
|
|
70
|
+
if (!m)
|
|
71
|
+
return undefined;
|
|
72
|
+
const body = m[1].trim();
|
|
73
|
+
if (!body)
|
|
74
|
+
return 0;
|
|
75
|
+
// Count comma-separated entries, tolerate trailing commas
|
|
76
|
+
return body.split(',').filter((s) => s.trim().length > 0).length;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Scan reasoning + action text for new verdict-worthy moments. Returns
|
|
80
|
+
* an array (possibly empty) of events the driver should surface as
|
|
81
|
+
* badges. The caller is responsible for deduplication across turns —
|
|
82
|
+
* this function returns ALL verdict markers visible in the text.
|
|
83
|
+
*
|
|
84
|
+
* For a reasoning string like:
|
|
85
|
+
* "C-003 PUTIN VLADIMIR: POSITIVE MATCH — Russia-EO14024 / SDN"
|
|
86
|
+
* emits: { kind: 'positive', text: 'C-003 PUTIN VLADIMIR · POSITIVE MATCH', marker: 'C-003:POSITIVE MATCH' }
|
|
87
|
+
*/
|
|
88
|
+
export function detectVerdicts(reasoning) {
|
|
89
|
+
if (!reasoning)
|
|
90
|
+
return [];
|
|
91
|
+
const out = [];
|
|
92
|
+
// Case: inline customer-ID prefix (OFAC-style)
|
|
93
|
+
// "C-003 confirmed POSITIVE MATCH" / "C-003: CLEARED"
|
|
94
|
+
// Trailer is comma-bounded so enumerations like
|
|
95
|
+
// "C-001 POSITIVE MATCH, C-002 CLEARED, C-003 NEEDS REVIEW"
|
|
96
|
+
// yield one event per customer, not one event for the whole line.
|
|
97
|
+
const inlineRe = /\b([A-Z]-\d{3,4})[^\w]{1,6}([^.,\n]*?(?:POSITIVE\s+MATCH|CLEARED|NEEDS\s+REVIEW)[^.,\n]*)/gi;
|
|
98
|
+
let m;
|
|
99
|
+
const seenInText = new Set();
|
|
100
|
+
while ((m = inlineRe.exec(reasoning)) !== null) {
|
|
101
|
+
const cid = m[1];
|
|
102
|
+
const snippet = m[2].replace(/\s+/g, ' ').trim();
|
|
103
|
+
const kind = snippet.match(/POSITIVE/i) ? 'positive' : snippet.match(/CLEARED/i) ? 'cleared' : 'review';
|
|
104
|
+
const marker = `${cid}:${kind.toUpperCase()}`;
|
|
105
|
+
// Dedupe within a single reasoning string — agent may restate
|
|
106
|
+
// "C-001 POSITIVE" later in the same line without intending a new event.
|
|
107
|
+
if (seenInText.has(marker))
|
|
108
|
+
continue;
|
|
109
|
+
seenInText.add(marker);
|
|
110
|
+
const shortSnippet = snippet.length > 60 ? snippet.slice(0, 57) + '…' : snippet;
|
|
111
|
+
out.push({
|
|
112
|
+
kind,
|
|
113
|
+
text: `${cid} · ${shortSnippet}`,
|
|
114
|
+
marker,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
// Fallback: bare verdict without customer ID. Only emit ONE per reasoning
|
|
118
|
+
// string in this mode (multiple would be noise without context).
|
|
119
|
+
if (out.length === 0) {
|
|
120
|
+
for (const pat of VERDICT_PATTERNS) {
|
|
121
|
+
const vm = reasoning.match(pat.re);
|
|
122
|
+
if (vm) {
|
|
123
|
+
out.push({
|
|
124
|
+
kind: pat.kind,
|
|
125
|
+
text: vm[0].replace(/\s+/g, ' ').trim().toUpperCase(),
|
|
126
|
+
marker: pat.kind.toUpperCase(),
|
|
127
|
+
});
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Stateful tracker that holds the set of verdict markers already
|
|
136
|
+
* surfaced this session, so we don't re-emit the same badge every turn
|
|
137
|
+
* for a verdict the agent keeps mentioning in its progress ledger.
|
|
138
|
+
*/
|
|
139
|
+
export class VerdictTracker {
|
|
140
|
+
seen = new Set();
|
|
141
|
+
/**
|
|
142
|
+
* Given new reasoning text, return only the verdicts that are NEW
|
|
143
|
+
* (haven't been emitted before in this session).
|
|
144
|
+
*/
|
|
145
|
+
accept(reasoning) {
|
|
146
|
+
const found = detectVerdicts(reasoning);
|
|
147
|
+
const fresh = [];
|
|
148
|
+
for (const v of found) {
|
|
149
|
+
if (this.seen.has(v.marker))
|
|
150
|
+
continue;
|
|
151
|
+
this.seen.add(v.marker);
|
|
152
|
+
fresh.push(v);
|
|
153
|
+
}
|
|
154
|
+
return fresh;
|
|
155
|
+
}
|
|
156
|
+
reset() {
|
|
157
|
+
this.seen.clear();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Build the progress label shown in the top-left chip of the overlay.
|
|
162
|
+
* Combines turn counter with an optional ledger marker.
|
|
163
|
+
*
|
|
164
|
+
* buildProgressLabel(5, 65) → "Turn 5 · 65 max"
|
|
165
|
+
* buildProgressLabel(5, 65, 'C-003') → "Turn 5 · C-003"
|
|
166
|
+
*/
|
|
167
|
+
export function buildProgressLabel(turn, maxTurns, marker) {
|
|
168
|
+
if (marker)
|
|
169
|
+
return `Turn ${turn} · ${marker}`;
|
|
170
|
+
return `Turn ${turn} / ${maxTurns}`;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=overlay-narration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-narration.js","sourceRoot":"","sources":["../../src/runner/overlay-narration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,MAAM,gBAAgB,GAA8D;IAClF,EAAE,EAAE,EAAE,uBAAuB,EAAE,IAAI,EAAE,UAAU,EAAE;IACjD,EAAE,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,EAAE;IACvC,EAAE,EAAE,EAAE,qBAAqB,EAAE,IAAI,EAAE,QAAQ,EAAE;CAC9C,CAAA;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAA6B;IAC9D,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAA;IACzB,MAAM,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;IACvD,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAA;IACzB,8DAA8D;IAC9D,MAAM,aAAa,GAAG,SAAS,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;IACtD,IAAI,aAAa,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,aAAa,CAAC,CAAC,CAAC,CAAA;IAC5E,OAAO,SAAS,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC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AAI,EAAE,GAAG,CAAC,IAAI;oBACd,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE;oBACrD,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE;iBAC/B,CAAC,CAAA;gBACF,MAAK;YACP,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,cAAc;IACjB,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAEhC;;;OAGG;IACH,MAAM,CAAC,SAA6B;QAClC,MAAM,KAAK,GAAG,cAAc,CAAC,SAAS,CAAC,CAAA;QACvC,MAAM,KAAK,GAAmB,EAAE,CAAA;QAChC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACtB,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;gBAAE,SAAQ;YACrC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;YACvB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACf,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAA;IACnB,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,QAAgB,EAChB,MAAe;IAEf,IAAI,MAAM;QAAE,OAAO,QAAQ,IAAI,MAAM,MAAM,EAAE,CAAA;IAC7C,OAAO,QAAQ,IAAI,MAAM,QAAQ,EAAE,CAAA;AACrC,CAAC"}
|
package/dist/runner/runner.d.ts
CHANGED
|
@@ -45,6 +45,14 @@ export interface BrowserAgentOptions {
|
|
|
45
45
|
config?: AgentConfig;
|
|
46
46
|
/** Called after each turn */
|
|
47
47
|
onTurn?: (turn: Turn) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Gen 32 — called at the top of every turn BEFORE observe().
|
|
50
|
+
* Used by the interrupt controller to block the loop while the user
|
|
51
|
+
* has the run paused (`p` keypress in an interactive attach). The
|
|
52
|
+
* promise resolves on resume or rejects with an abort signal to
|
|
53
|
+
* bail out cleanly.
|
|
54
|
+
*/
|
|
55
|
+
beforeTurn?: (turn: number) => Promise<void>;
|
|
48
56
|
/** Called when a first-time phase timing is observed */
|
|
49
57
|
onPhaseTiming?: (phase: 'navigate' | 'observe' | 'decide' | 'execute', durationMs: number) => void;
|
|
50
58
|
/** Reference trajectory to inject into brain context */
|
|
@@ -120,6 +128,7 @@ export declare class BrowserAgent {
|
|
|
120
128
|
private brain;
|
|
121
129
|
private config;
|
|
122
130
|
private onTurn?;
|
|
131
|
+
private beforeTurn?;
|
|
123
132
|
private onPhaseTiming?;
|
|
124
133
|
private referenceTrajectory?;
|
|
125
134
|
private projectStore?;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/runner/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAkC,MAAM,aAAa,CAAC;AAKvH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAuB/D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAa,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/runner/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,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,CACnC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,GAC5C,OAAO,CAAC,WAAW,CAAC,CAGtB"}
|
package/dist/runner/runner.js
CHANGED
|
@@ -34,6 +34,7 @@ import { buildOverrideProducers, buildScoutLinkRecommendationText, buildBranchLi
|
|
|
34
34
|
import { RunRegistry } from '../memory/run-registry.js';
|
|
35
35
|
import { ensureBus } from './events.js';
|
|
36
36
|
import { DecisionCache } from './decision-cache.js';
|
|
37
|
+
import { VerdictTracker, extractCurrentMarker, buildProgressLabel, } from './overlay-narration.js';
|
|
37
38
|
import { matchDeterministicPattern } from './deterministic-patterns.js';
|
|
38
39
|
/**
|
|
39
40
|
* Gen 6.1: detect that the agent is filling a multi-field form one input at
|
|
@@ -245,6 +246,7 @@ export class BrowserAgent {
|
|
|
245
246
|
brain;
|
|
246
247
|
config;
|
|
247
248
|
onTurn;
|
|
249
|
+
beforeTurn;
|
|
248
250
|
onPhaseTiming;
|
|
249
251
|
referenceTrajectory;
|
|
250
252
|
projectStore;
|
|
@@ -267,6 +269,7 @@ export class BrowserAgent {
|
|
|
267
269
|
this.config = options.config || {};
|
|
268
270
|
this.brain = new Brain(this.config);
|
|
269
271
|
this.onTurn = options.onTurn;
|
|
272
|
+
this.beforeTurn = options.beforeTurn;
|
|
270
273
|
this.onPhaseTiming = options.onPhaseTiming;
|
|
271
274
|
this.referenceTrajectory = options.referenceTrajectory;
|
|
272
275
|
this.bus = ensureBus(options.eventBus);
|
|
@@ -650,7 +653,26 @@ export class BrowserAgent {
|
|
|
650
653
|
}
|
|
651
654
|
}
|
|
652
655
|
}
|
|
656
|
+
// Gen 32 — overlay narration tracker. Per-session; accumulates verdict
|
|
657
|
+
// markers so a ledger the agent keeps re-emitting doesn't spam badges.
|
|
658
|
+
const verdictTracker = new VerdictTracker();
|
|
653
659
|
for (let i = 1 + plannerStartTurn; i <= maxTurns; i++) {
|
|
660
|
+
// Gen 32 — honor user-driven pause from the interrupt controller.
|
|
661
|
+
// Blocks until `r` is pressed (resume) or `q` is pressed (abort).
|
|
662
|
+
// A rejected beforeTurn is treated as an abort.
|
|
663
|
+
if (this.beforeTurn) {
|
|
664
|
+
try {
|
|
665
|
+
await this.beforeTurn(i);
|
|
666
|
+
}
|
|
667
|
+
catch (err) {
|
|
668
|
+
return buildResult({
|
|
669
|
+
success: false,
|
|
670
|
+
reason: err instanceof Error ? err.message : 'aborted',
|
|
671
|
+
turns,
|
|
672
|
+
totalMs: Date.now() - startTime,
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
}
|
|
654
676
|
if (scenario.signal?.aborted) {
|
|
655
677
|
return buildResult({
|
|
656
678
|
success: false,
|
|
@@ -1255,6 +1277,30 @@ export class BrowserAgent {
|
|
|
1255
1277
|
durationMs: decideDurationMs,
|
|
1256
1278
|
});
|
|
1257
1279
|
}
|
|
1280
|
+
// -- 4a. Gen 32 — narrate to the cursor overlay. Fire-and-forget.
|
|
1281
|
+
// Four signals pushed to the page-context overlay so a viewer of
|
|
1282
|
+
// the recorded video can READ the agent's work, not just watch it:
|
|
1283
|
+
// 1. Reasoning panel (top-right) — the agent's own text
|
|
1284
|
+
// 2. Progress bar + chip (top) — turn N with optional ledger marker
|
|
1285
|
+
// 3. Verdict badges (bottom-left) — POSITIVE/CLEARED/REVIEW events
|
|
1286
|
+
// All methods are no-ops when the overlay is disabled, and all page
|
|
1287
|
+
// calls are wrapped by the driver so a navigation race here can
|
|
1288
|
+
// never bubble up and break the run.
|
|
1289
|
+
try {
|
|
1290
|
+
if (this.driver.setOverlayReasoning) {
|
|
1291
|
+
void this.driver.setOverlayReasoning(reasoning ?? '');
|
|
1292
|
+
}
|
|
1293
|
+
if (this.driver.setOverlayProgress) {
|
|
1294
|
+
const marker = extractCurrentMarker(reasoning);
|
|
1295
|
+
void this.driver.setOverlayProgress(i, maxTurns, buildProgressLabel(i, maxTurns, marker));
|
|
1296
|
+
}
|
|
1297
|
+
if (this.driver.pushOverlayBadge) {
|
|
1298
|
+
const fresh = verdictTracker.accept(reasoning);
|
|
1299
|
+
for (const v of fresh)
|
|
1300
|
+
void this.driver.pushOverlayBadge(v.kind, v.text);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
catch { /* overlay narration is cosmetic; never let it break a run */ }
|
|
1258
1304
|
// -- 4b. Override pipeline — scored selection of post-decision overrides --
|
|
1259
1305
|
const overrideCtx = {
|
|
1260
1306
|
state,
|