@developerz.ai/ui-debugger-mcp 1.0.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/LICENSE +21 -0
- package/README.md +295 -0
- package/dist/adapters/android/adb.d.ts +38 -0
- package/dist/adapters/android/adb.js +72 -0
- package/dist/adapters/android/adb.js.map +1 -0
- package/dist/adapters/android/android-adapter.d.ts +63 -0
- package/dist/adapters/android/android-adapter.js +306 -0
- package/dist/adapters/android/android-adapter.js.map +1 -0
- package/dist/adapters/android/commands.d.ts +59 -0
- package/dist/adapters/android/commands.js +178 -0
- package/dist/adapters/android/commands.js.map +1 -0
- package/dist/adapters/android/uiautomator.d.ts +81 -0
- package/dist/adapters/android/uiautomator.js +296 -0
- package/dist/adapters/android/uiautomator.js.map +1 -0
- package/dist/adapters/browser/browser-adapter.d.ts +72 -0
- package/dist/adapters/browser/browser-adapter.js +434 -0
- package/dist/adapters/browser/browser-adapter.js.map +1 -0
- package/dist/adapters/browser/cdp.d.ts +83 -0
- package/dist/adapters/browser/cdp.js +308 -0
- package/dist/adapters/browser/cdp.js.map +1 -0
- package/dist/adapters/browser/query.d.ts +25 -0
- package/dist/adapters/browser/query.js +85 -0
- package/dist/adapters/browser/query.js.map +1 -0
- package/dist/adapters/contract.d.ts +159 -0
- package/dist/adapters/contract.js +22 -0
- package/dist/adapters/contract.js.map +1 -0
- package/dist/adapters/desktop/atspi.d.ts +95 -0
- package/dist/adapters/desktop/atspi.js +359 -0
- package/dist/adapters/desktop/atspi.js.map +1 -0
- package/dist/adapters/desktop/capture.d.ts +35 -0
- package/dist/adapters/desktop/capture.js +67 -0
- package/dist/adapters/desktop/capture.js.map +1 -0
- package/dist/adapters/desktop/desktop-adapter.d.ts +60 -0
- package/dist/adapters/desktop/desktop-adapter.js +215 -0
- package/dist/adapters/desktop/desktop-adapter.js.map +1 -0
- package/dist/adapters/desktop/input.d.ts +67 -0
- package/dist/adapters/desktop/input.js +191 -0
- package/dist/adapters/desktop/input.js.map +1 -0
- package/dist/adapters/desktop/proc.d.ts +23 -0
- package/dist/adapters/desktop/proc.js +38 -0
- package/dist/adapters/desktop/proc.js.map +1 -0
- package/dist/adapters/factory.d.ts +23 -0
- package/dist/adapters/factory.js +45 -0
- package/dist/adapters/factory.js.map +1 -0
- package/dist/agent/belt/act.d.ts +100 -0
- package/dist/agent/belt/act.js +166 -0
- package/dist/agent/belt/act.js.map +1 -0
- package/dist/agent/belt/look.d.ts +98 -0
- package/dist/agent/belt/look.js +160 -0
- package/dist/agent/belt/look.js.map +1 -0
- package/dist/agent/belt/observe.d.ts +102 -0
- package/dist/agent/belt/observe.js +185 -0
- package/dist/agent/belt/observe.js.map +1 -0
- package/dist/agent/belt/report.d.ts +133 -0
- package/dist/agent/belt/report.js +112 -0
- package/dist/agent/belt/report.js.map +1 -0
- package/dist/agent/loop.d.ts +136 -0
- package/dist/agent/loop.js +173 -0
- package/dist/agent/loop.js.map +1 -0
- package/dist/agent/models.d.ts +26 -0
- package/dist/agent/models.js +22 -0
- package/dist/agent/models.js.map +1 -0
- package/dist/agent/prompts/android-addendum.d.ts +12 -0
- package/dist/agent/prompts/android-addendum.js +76 -0
- package/dist/agent/prompts/android-addendum.js.map +1 -0
- package/dist/agent/prompts/compose.d.ts +30 -0
- package/dist/agent/prompts/compose.js +52 -0
- package/dist/agent/prompts/compose.js.map +1 -0
- package/dist/agent/prompts/debug-agent.d.ts +9 -0
- package/dist/agent/prompts/debug-agent.js +102 -0
- package/dist/agent/prompts/debug-agent.js.map +1 -0
- package/dist/agent/prompts/desktop-addendum.d.ts +10 -0
- package/dist/agent/prompts/desktop-addendum.js +66 -0
- package/dist/agent/prompts/desktop-addendum.js.map +1 -0
- package/dist/agent/prompts/web-addendum.d.ts +9 -0
- package/dist/agent/prompts/web-addendum.js +70 -0
- package/dist/agent/prompts/web-addendum.js.map +1 -0
- package/dist/agent/provider.d.ts +17 -0
- package/dist/agent/provider.js +29 -0
- package/dist/agent/provider.js.map +1 -0
- package/dist/cli/control.d.ts +19 -0
- package/dist/cli/control.js +152 -0
- package/dist/cli/control.js.map +1 -0
- package/dist/cli/help.d.ts +9 -0
- package/dist/cli/help.js +41 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/init.d.ts +20 -0
- package/dist/cli/init.js +119 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/config/load.d.ts +64 -0
- package/dist/config/load.js +105 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/schema.d.ts +105 -0
- package/dist/config/schema.js +62 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/errors.d.ts +41 -0
- package/dist/errors.js +90 -0
- package/dist/errors.js.map +1 -0
- package/dist/findings/schema.d.ts +64 -0
- package/dist/findings/schema.js +27 -0
- package/dist/findings/schema.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +95 -0
- package/dist/main.js.map +1 -0
- package/dist/mcp/server.d.ts +25 -0
- package/dist/mcp/server.js +31 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/describe.d.ts +12 -0
- package/dist/mcp/tools/describe.js +32 -0
- package/dist/mcp/tools/describe.js.map +1 -0
- package/dist/mcp/tools/end-session.d.ts +11 -0
- package/dist/mcp/tools/end-session.js +27 -0
- package/dist/mcp/tools/end-session.js.map +1 -0
- package/dist/mcp/tools/get-findings.d.ts +12 -0
- package/dist/mcp/tools/get-findings.js +42 -0
- package/dist/mcp/tools/get-findings.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +17 -0
- package/dist/mcp/tools/index.js +24 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/result.d.ts +10 -0
- package/dist/mcp/tools/result.js +20 -0
- package/dist/mcp/tools/result.js.map +1 -0
- package/dist/mcp/tools/send-message.d.ts +11 -0
- package/dist/mcp/tools/send-message.js +31 -0
- package/dist/mcp/tools/send-message.js.map +1 -0
- package/dist/mcp/tools/start-debug.d.ts +12 -0
- package/dist/mcp/tools/start-debug.js +50 -0
- package/dist/mcp/tools/start-debug.js.map +1 -0
- package/dist/services/debug-service.d.ts +133 -0
- package/dist/services/debug-service.js +163 -0
- package/dist/services/debug-service.js.map +1 -0
- package/dist/services/replay.d.ts +102 -0
- package/dist/services/replay.js +184 -0
- package/dist/services/replay.js.map +1 -0
- package/dist/services/session-builder.d.ts +65 -0
- package/dist/services/session-builder.js +198 -0
- package/dist/services/session-builder.js.map +1 -0
- package/dist/services/summarize.d.ts +59 -0
- package/dist/services/summarize.js +93 -0
- package/dist/services/summarize.js.map +1 -0
- package/dist/session/findings-store.d.ts +52 -0
- package/dist/session/findings-store.js +176 -0
- package/dist/session/findings-store.js.map +1 -0
- package/dist/session/manager.d.ts +47 -0
- package/dist/session/manager.js +66 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/session/process-identity.d.ts +45 -0
- package/dist/session/process-identity.js +81 -0
- package/dist/session/process-identity.js.map +1 -0
- package/dist/session/session.d.ts +156 -0
- package/dist/session/session.js +309 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/state-file.d.ts +72 -0
- package/dist/session/state-file.js +104 -0
- package/dist/session/state-file.js.map +1 -0
- package/dist/session/workspace.d.ts +60 -0
- package/dist/session/workspace.js +75 -0
- package/dist/session/workspace.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session builder — assemble one debug run from the resolved config.
|
|
3
|
+
*
|
|
4
|
+
* The heavy wiring behind `start_debug`, in one focused place: resolve the
|
|
5
|
+
* target adapter (CDP browser today), build the inner belt
|
|
6
|
+
* (`observe`/`act`/`look`/`report`) over it, compose the system prompt, and
|
|
7
|
+
* bundle the loop runner the {@link Session} drives in the background. All of it
|
|
8
|
+
* binds to a single per-run {@link FindingsStore} so the running progress trail
|
|
9
|
+
* and the terminal `report` write to the same `findings.json`.
|
|
10
|
+
*
|
|
11
|
+
* Returns an *un-registered* session plus the `open`/`run` seams the service
|
|
12
|
+
* fires only AFTER it has taken the project's profile lock — so a busy race never
|
|
13
|
+
* leaks a launched browser. The builder stays adapter- and model-blind past this
|
|
14
|
+
* seam; swapping the driver model or the target never touches the service.
|
|
15
|
+
*/
|
|
16
|
+
import { createAdapter } from '../adapters/factory.js';
|
|
17
|
+
import { createActTool } from '../agent/belt/act.js';
|
|
18
|
+
import { createLookTool } from '../agent/belt/look.js';
|
|
19
|
+
import { createObserveTool } from '../agent/belt/observe.js';
|
|
20
|
+
import { createReportTool } from '../agent/belt/report.js';
|
|
21
|
+
import { createDebugAgent, runDebugLoop } from '../agent/loop.js';
|
|
22
|
+
import { composeSystemPrompt } from '../agent/prompts/compose.js';
|
|
23
|
+
import { TargetNotFoundError } from '../errors.js';
|
|
24
|
+
import { FindingsStore } from '../session/findings-store.js';
|
|
25
|
+
import { Session } from '../session/session.js';
|
|
26
|
+
import { ensureSession, sessionPaths } from '../session/workspace.js';
|
|
27
|
+
import { createReplayStep } from './replay.js';
|
|
28
|
+
import { createSummarize } from './summarize.js';
|
|
29
|
+
/** Bind {@link buildSession} to its shared deps, yielding the per-run {@link SessionBuilder}. */
|
|
30
|
+
export function makeSessionBuilder(deps) {
|
|
31
|
+
return (params) => buildSession(deps, params);
|
|
32
|
+
}
|
|
33
|
+
/** Compact one-line JSON of a tool input for the agent log (truncated, never throws). */
|
|
34
|
+
function compactInput(input) {
|
|
35
|
+
try {
|
|
36
|
+
const s = JSON.stringify(input);
|
|
37
|
+
return s.length > 200 ? `${s.slice(0, 199)}…` : s;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return String(input);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Wrap a belt tool so every call records its input to `logs/agent.log`, and any
|
|
45
|
+
* thrown error is logged before it propagates — otherwise a belt failure (e.g. a
|
|
46
|
+
* selector that resolves nothing) is invisible: the SDK feeds it back to the model
|
|
47
|
+
* as a tool-error and the run just churns. The wrapper is transparent: same
|
|
48
|
+
* input/output, it only observes.
|
|
49
|
+
*/
|
|
50
|
+
function withToolLog(name, t, log) {
|
|
51
|
+
const original = t.execute;
|
|
52
|
+
if (!original)
|
|
53
|
+
return t;
|
|
54
|
+
return {
|
|
55
|
+
...t,
|
|
56
|
+
execute: async (input, options) => {
|
|
57
|
+
log(`${name} ${compactInput(input)}`);
|
|
58
|
+
try {
|
|
59
|
+
return await original(input, options);
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
log(`${name} ERROR ${err instanceof Error ? err.message : String(err)}`);
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Map a config adapter kind to its prompt addendum target — one per shipped adapter. */
|
|
69
|
+
function addendumTarget(adapter) {
|
|
70
|
+
if (adapter === 'browser')
|
|
71
|
+
return 'web';
|
|
72
|
+
if (adapter === 'desktop')
|
|
73
|
+
return 'desktop';
|
|
74
|
+
return 'android';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The address `open()` hands the adapter: the URL to navigate to (web), or the
|
|
78
|
+
* window-title hint (desktop — empty when `window` is unset, so the launched
|
|
79
|
+
* window is driven), or empty for android (boot the emulator / attach, then the
|
|
80
|
+
* agent launches the app itself via `act navigate` using the package/activity in
|
|
81
|
+
* the story). The managed launch command itself lives in the target config.
|
|
82
|
+
*/
|
|
83
|
+
function openAddress(target) {
|
|
84
|
+
if (target.adapter === 'browser')
|
|
85
|
+
return target.url;
|
|
86
|
+
if (target.adapter === 'desktop')
|
|
87
|
+
return target.window?.title ?? '';
|
|
88
|
+
return '';
|
|
89
|
+
}
|
|
90
|
+
/** Split a free-text criteria blob into per-line rules; `undefined` when empty/absent. */
|
|
91
|
+
function splitCriteria(criteria) {
|
|
92
|
+
if (criteria === undefined)
|
|
93
|
+
return undefined;
|
|
94
|
+
const lines = criteria
|
|
95
|
+
.split('\n')
|
|
96
|
+
.map((line) => line.trim())
|
|
97
|
+
.filter((line) => line.length > 0);
|
|
98
|
+
return lines.length > 0 ? lines : undefined;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Assemble a debug run: adapter + belt + composed prompt + loop runner, all bound
|
|
102
|
+
* to a fresh {@link FindingsStore}. Throws {@link TargetNotFoundError} if `target`
|
|
103
|
+
* is not configured — BEFORE any device or browser launches, so a bad request never
|
|
104
|
+
* leaks a process.
|
|
105
|
+
*/
|
|
106
|
+
export async function buildSession(deps, params) {
|
|
107
|
+
const { config, models, workspace } = deps;
|
|
108
|
+
const { id, target, goal, criteria } = params;
|
|
109
|
+
const targetConfig = config.targets[target];
|
|
110
|
+
if (!targetConfig) {
|
|
111
|
+
throw new TargetNotFoundError(`target '${target}' not found in config.targets`);
|
|
112
|
+
}
|
|
113
|
+
const addendum = addendumTarget(targetConfig.adapter);
|
|
114
|
+
const paths = sessionPaths(workspace, id);
|
|
115
|
+
await ensureSession(paths);
|
|
116
|
+
const store = new FindingsStore(paths);
|
|
117
|
+
const onLog = (channel, line) => {
|
|
118
|
+
void store.appendLog(channel, line).catch(() => undefined);
|
|
119
|
+
};
|
|
120
|
+
const adapter = await createAdapter(target, config, workspace.chromeUserData, onLog);
|
|
121
|
+
const instructions = composeSystemPrompt({
|
|
122
|
+
target: addendum,
|
|
123
|
+
story: goal,
|
|
124
|
+
criteria: splitCriteria(criteria),
|
|
125
|
+
});
|
|
126
|
+
const appendAgentLog = (line) => store.appendLog('agent', `${new Date().toISOString()} ${line}`);
|
|
127
|
+
// High-frequency, fire-and-forget: the agent's own log sink + per-step tool logs.
|
|
128
|
+
const logAgent = (line) => {
|
|
129
|
+
void appendAgentLog(line).catch(() => undefined);
|
|
130
|
+
};
|
|
131
|
+
// Run-lifecycle breadcrumbs (start/end/error) are AWAITED: on the crash path the
|
|
132
|
+
// process can exit before a fire-and-forget write flushes, losing the very failure
|
|
133
|
+
// we're trying to diagnose. A logging error here is swallowed, never masking the run.
|
|
134
|
+
const flushAgentLog = async (line) => {
|
|
135
|
+
try {
|
|
136
|
+
await appendAgentLog(line);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
// best-effort: logging must never break or mask the run
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const run = async ({ inbox, progress, signal }) => {
|
|
143
|
+
// One trail per run, shared between the loop (which appends each act step) and
|
|
144
|
+
// the `report` tool (which overlays it as the verdict's authoritative steps), so
|
|
145
|
+
// the persisted findings and the returned counts derive from the same object.
|
|
146
|
+
const trail = [];
|
|
147
|
+
const agent = createDebugAgent({
|
|
148
|
+
model: models.driver,
|
|
149
|
+
tools: {
|
|
150
|
+
observe: withToolLog('observe', createObserveTool(adapter), logAgent),
|
|
151
|
+
act: withToolLog('act', createActTool(adapter, store), logAgent),
|
|
152
|
+
look: withToolLog('look', createLookTool(adapter, models.vision, store), logAgent),
|
|
153
|
+
report: withToolLog('report', createReportTool(store, () => trail), logAgent),
|
|
154
|
+
},
|
|
155
|
+
instructions,
|
|
156
|
+
inbox,
|
|
157
|
+
progress,
|
|
158
|
+
log: logAgent,
|
|
159
|
+
trail,
|
|
160
|
+
});
|
|
161
|
+
await flushAgentLog(`run start: target=${target} goal=${JSON.stringify(goal)}`);
|
|
162
|
+
try {
|
|
163
|
+
const result = await runDebugLoop({ agent, abortSignal: signal });
|
|
164
|
+
await flushAgentLog('run end: loop resolved (driver reported or step cap reached)');
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
// Surface the real failure to disk BEFORE the session folds it into `failed` —
|
|
169
|
+
// awaited, so a crash that exits the process can't race past the flush and leave
|
|
170
|
+
// agent.log empty (the exact case this trace is here to diagnose).
|
|
171
|
+
await flushAgentLog(`run error: ${err instanceof Error ? `${err.name}: ${err.message}` : String(err)}`);
|
|
172
|
+
if (err instanceof Error && err.stack) {
|
|
173
|
+
await flushAgentLog(err.stack.split('\n').slice(0, 8).join('\n'));
|
|
174
|
+
}
|
|
175
|
+
throw err;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const session = new Session({
|
|
179
|
+
id,
|
|
180
|
+
story: goal,
|
|
181
|
+
criteria,
|
|
182
|
+
adapter,
|
|
183
|
+
findingsStore: store,
|
|
184
|
+
// Post-verdict seam: fills `findings.summary` over the summary model when the
|
|
185
|
+
// driver left it empty (best-effort; the session wraps it fail-soft).
|
|
186
|
+
summarize: createSummarize(models.summary),
|
|
187
|
+
// Post-verdict seam: stitches the ordered screenshots into a captioned
|
|
188
|
+
// `replay.mp4` (ffmpeg) and records its path in `findings.evidence` for the PR.
|
|
189
|
+
// `log` surfaces an absent ffmpeg loud in `agent.log`; the step skips, never crashes.
|
|
190
|
+
replay: createReplayStep({ screenshots: store, output: paths.replayMp4, log: logAgent }),
|
|
191
|
+
});
|
|
192
|
+
return {
|
|
193
|
+
session,
|
|
194
|
+
open: () => adapter.open(openAddress(targetConfig)),
|
|
195
|
+
run,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=session-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-builder.js","sourceRoot":"","sources":["../../src/services/session-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAmB,MAAM,6BAA6B,CAAC;AAGnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,c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C,WAAW,CAAC,YAAY,CAAC,CAAC;QACnD,GAAG;KACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `summarize` — the summary actor: condense a run's findings into one actionable
|
|
3
|
+
* paragraph for the smart agent.
|
|
4
|
+
*
|
|
5
|
+
* The driver may finish a run without writing its own `summary` — it hit the step
|
|
6
|
+
* cap, or just emitted the structured verdict and left the prose out. This service
|
|
7
|
+
* fills that gap: it takes the terminal findings (the verdict plus every functional
|
|
8
|
+
* `bug` and `visual` issue) and asks the summary model — the cheap text role, see
|
|
9
|
+
* `idea/models.md` — for a single paragraph the smart agent can act on: what broke,
|
|
10
|
+
* where, what to fix.
|
|
11
|
+
*
|
|
12
|
+
* The model call hides behind a small {@link SummaryGenerate} seam so the core
|
|
13
|
+
* {@link summarize} unit-tests against a fake with no network — the same shape as
|
|
14
|
+
* `look`'s vision seam. {@link createSummarize} binds the real
|
|
15
|
+
* `generateText({ model: summary, … })` into the {@link SummarizeStep} the session
|
|
16
|
+
* invokes once the verdict settles.
|
|
17
|
+
*
|
|
18
|
+
* Fails loud: an empty model reply throws an {@link AgentError} — we never pass a
|
|
19
|
+
* blank string off as a summary. The session wraps the call in its own fail-soft
|
|
20
|
+
* policy (a missing summary must never block teardown), so loud here, soft there.
|
|
21
|
+
*/
|
|
22
|
+
import type { LanguageModel } from 'ai';
|
|
23
|
+
import type { Findings } from '../findings/schema.js';
|
|
24
|
+
import type { SummarizeStep } from '../session/session.js';
|
|
25
|
+
/** What `summarize` asks the summary model: our system prompt + the findings digest. */
|
|
26
|
+
export interface SummaryRequest {
|
|
27
|
+
system: string;
|
|
28
|
+
prompt: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The model seam `summarize` calls through. {@link createSummarize} binds it to the
|
|
32
|
+
* real `generateText({ model: summary, … })`; tests pass a fake returning canned text.
|
|
33
|
+
*/
|
|
34
|
+
export type SummaryGenerate = (req: SummaryRequest) => Promise<{
|
|
35
|
+
text: string;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Our system prompt for the summary guy — provider-agnostic, owned in-repo. Pins the
|
|
39
|
+
* reply to one tight, actionable paragraph so any competent text model behaves the
|
|
40
|
+
* same (never relies on a 3rd-party default).
|
|
41
|
+
*/
|
|
42
|
+
export declare const SUMMARY_SYSTEM_PROMPT = "You are the summary guy \u2014 you condense a UI debug run into one paragraph for the\nsmart agent that will fix the code.\nYou are given the run's verdict plus every functional bug and visual issue it found.\nWrite ONE plain-text paragraph (no markdown, no lists, no headings, no preamble) that\nstates the verdict, then what broke, where, and what to fix \u2014 concrete and ordered by\nseverity. If nothing broke, say so plainly. Output only the paragraph.";
|
|
43
|
+
/**
|
|
44
|
+
* Render the findings into the compact, plain-text digest the summary model reasons
|
|
45
|
+
* over: the verdict, then the functional bugs and visual issues (or "none").
|
|
46
|
+
*/
|
|
47
|
+
export declare function findingsDigest(findings: Findings): string;
|
|
48
|
+
/**
|
|
49
|
+
* Condense findings into one actionable paragraph. Pure over the
|
|
50
|
+
* {@link SummaryGenerate} seam, so it unit-tests against a fake with no network.
|
|
51
|
+
* @throws {AgentError} if the summary model returns a blank reply.
|
|
52
|
+
*/
|
|
53
|
+
export declare function summarize(generate: SummaryGenerate, findings: Findings): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Bind {@link summarize} to the summary model, yielding the {@link SummarizeStep} the
|
|
56
|
+
* session calls after the verdict settles. The model is the only thing that varies
|
|
57
|
+
* between deployments; everything else (prompt, digest) is owned in-repo.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createSummarize(model: LanguageModel): SummarizeStep;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `summarize` — the summary actor: condense a run's findings into one actionable
|
|
3
|
+
* paragraph for the smart agent.
|
|
4
|
+
*
|
|
5
|
+
* The driver may finish a run without writing its own `summary` — it hit the step
|
|
6
|
+
* cap, or just emitted the structured verdict and left the prose out. This service
|
|
7
|
+
* fills that gap: it takes the terminal findings (the verdict plus every functional
|
|
8
|
+
* `bug` and `visual` issue) and asks the summary model — the cheap text role, see
|
|
9
|
+
* `idea/models.md` — for a single paragraph the smart agent can act on: what broke,
|
|
10
|
+
* where, what to fix.
|
|
11
|
+
*
|
|
12
|
+
* The model call hides behind a small {@link SummaryGenerate} seam so the core
|
|
13
|
+
* {@link summarize} unit-tests against a fake with no network — the same shape as
|
|
14
|
+
* `look`'s vision seam. {@link createSummarize} binds the real
|
|
15
|
+
* `generateText({ model: summary, … })` into the {@link SummarizeStep} the session
|
|
16
|
+
* invokes once the verdict settles.
|
|
17
|
+
*
|
|
18
|
+
* Fails loud: an empty model reply throws an {@link AgentError} — we never pass a
|
|
19
|
+
* blank string off as a summary. The session wraps the call in its own fail-soft
|
|
20
|
+
* policy (a missing summary must never block teardown), so loud here, soft there.
|
|
21
|
+
*/
|
|
22
|
+
import { generateText } from 'ai';
|
|
23
|
+
import { AgentError } from '../errors.js';
|
|
24
|
+
/**
|
|
25
|
+
* Our system prompt for the summary guy — provider-agnostic, owned in-repo. Pins the
|
|
26
|
+
* reply to one tight, actionable paragraph so any competent text model behaves the
|
|
27
|
+
* same (never relies on a 3rd-party default).
|
|
28
|
+
*/
|
|
29
|
+
export const SUMMARY_SYSTEM_PROMPT = `\
|
|
30
|
+
You are the summary guy — you condense a UI debug run into one paragraph for the
|
|
31
|
+
smart agent that will fix the code.
|
|
32
|
+
You are given the run's verdict plus every functional bug and visual issue it found.
|
|
33
|
+
Write ONE plain-text paragraph (no markdown, no lists, no headings, no preamble) that
|
|
34
|
+
states the verdict, then what broke, where, and what to fix — concrete and ordered by
|
|
35
|
+
severity. If nothing broke, say so plainly. Output only the paragraph.`;
|
|
36
|
+
/** One functional bug, rendered for the digest. */
|
|
37
|
+
function bugLine(bug) {
|
|
38
|
+
const evidence = bug.evidence ? ` (evidence: ${bug.evidence})` : '';
|
|
39
|
+
return `- [${bug.kind}] ${bug.detail}${evidence}`;
|
|
40
|
+
}
|
|
41
|
+
/** One visual issue, rendered for the digest. */
|
|
42
|
+
function visualLine(issue) {
|
|
43
|
+
return `- [${issue.severity}] ${issue.issue} @ ${issue.where}`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Render the findings into the compact, plain-text digest the summary model reasons
|
|
47
|
+
* over: the verdict, then the functional bugs and visual issues (or "none").
|
|
48
|
+
*/
|
|
49
|
+
export function findingsDigest(findings) {
|
|
50
|
+
const lines = [`Verdict: ${findings.status}.`];
|
|
51
|
+
if (findings.bugs.length > 0) {
|
|
52
|
+
lines.push(`Functional bugs (${findings.bugs.length}):`, ...findings.bugs.map(bugLine));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
lines.push('Functional bugs: none.');
|
|
56
|
+
}
|
|
57
|
+
if (findings.visual.length > 0) {
|
|
58
|
+
lines.push(`Visual issues (${findings.visual.length}):`, ...findings.visual.map(visualLine));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
lines.push('Visual issues: none.');
|
|
62
|
+
}
|
|
63
|
+
return lines.join('\n');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Condense findings into one actionable paragraph. Pure over the
|
|
67
|
+
* {@link SummaryGenerate} seam, so it unit-tests against a fake with no network.
|
|
68
|
+
* @throws {AgentError} if the summary model returns a blank reply.
|
|
69
|
+
*/
|
|
70
|
+
export async function summarize(generate, findings) {
|
|
71
|
+
const { text } = await generate({
|
|
72
|
+
system: SUMMARY_SYSTEM_PROMPT,
|
|
73
|
+
prompt: findingsDigest(findings),
|
|
74
|
+
});
|
|
75
|
+
const paragraph = text.trim();
|
|
76
|
+
if (paragraph.length === 0) {
|
|
77
|
+
throw new AgentError('summarize: summary model returned an empty reply');
|
|
78
|
+
}
|
|
79
|
+
return paragraph;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Bind {@link summarize} to the summary model, yielding the {@link SummarizeStep} the
|
|
83
|
+
* session calls after the verdict settles. The model is the only thing that varies
|
|
84
|
+
* between deployments; everything else (prompt, digest) is owned in-repo.
|
|
85
|
+
*/
|
|
86
|
+
export function createSummarize(model) {
|
|
87
|
+
const generate = async ({ system, prompt }) => {
|
|
88
|
+
const { text } = await generateText({ model, system, prompt });
|
|
89
|
+
return { text };
|
|
90
|
+
};
|
|
91
|
+
return (findings) => summarize(generate, findings);
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=summarize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summarize.js","sourceRoot":"","sources":["../../src/services/summarize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAgB1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;uEAMkC,CAAC;AAExE,mDAAmD;AACnD,SAAS,OAAO,CAAC,GAA6B;IAC5C,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,eAAe,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACpE,OAAO,MAAM,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,MAAM,GAAG,QAAQ,EAAE,CAAC;AACpD,CAAC;AAED,iDAAiD;AACjD,SAAS,UAAU,CAAC,KAAiC;IACnD,OAAO,MAAM,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,KAAK,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;AACjE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,QAAkB;IAC/C,MAAM,KAAK,GAAa,CAAC,YAAY,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAEzD,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,K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,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAC/D,OAAO,EAAE,IAAI,EAAE,CAAC;IAClB,CAAC,CAAC;IACF,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Findings store — the session's evidence locker on disk.
|
|
3
|
+
*
|
|
4
|
+
* Persists everything the small agent produces during a run, under the session
|
|
5
|
+
* paths from `workspace.ts`:
|
|
6
|
+
* - `findings.json` structured verdict, Zod-validated on write + read
|
|
7
|
+
* - `logs/{console,network,agent}.log` appended trails (caller owns the format)
|
|
8
|
+
* - `screenshots/NNN-step.png` ordered frames, auto-numbered for the replay video
|
|
9
|
+
*
|
|
10
|
+
* Every write returns the absolute path it wrote, so findings can reference
|
|
11
|
+
* evidence by path instead of inlining blobs into the smart agent's context.
|
|
12
|
+
* Directories are created lazily (idempotent); bad findings fail loud via
|
|
13
|
+
* `FindingsError` — never a silent fallback.
|
|
14
|
+
*/
|
|
15
|
+
import type { Findings } from '../findings/schema.js';
|
|
16
|
+
import type { SessionPaths } from './workspace.js';
|
|
17
|
+
/** Append-only log channels backing `logs/<channel>.log`. */
|
|
18
|
+
export type LogChannel = 'console' | 'network' | 'agent';
|
|
19
|
+
/** One ordered screenshot frame — the raw material for the replay video. */
|
|
20
|
+
export interface ScreenshotFrame {
|
|
21
|
+
/** The `NNN` sequence parsed from the filename (ascending = capture order). */
|
|
22
|
+
seq: number;
|
|
23
|
+
/** Absolute path to the PNG. */
|
|
24
|
+
path: string;
|
|
25
|
+
/** Step label de-slugged from the filename (`001-clicked-login.png` → `clicked login`). */
|
|
26
|
+
label: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class FindingsStore {
|
|
29
|
+
#private;
|
|
30
|
+
constructor(paths: SessionPaths);
|
|
31
|
+
/** Validate + write `findings.json` (overwrites). Returns its path. */
|
|
32
|
+
writeFindings(findings: Findings): Promise<string>;
|
|
33
|
+
/** Read + validate `findings.json`. Throws `FindingsError` if missing/corrupt. */
|
|
34
|
+
readFindings(): Promise<Findings>;
|
|
35
|
+
/**
|
|
36
|
+
* Read + validate `findings.json` if it exists yet; `null` if the agent has
|
|
37
|
+
* not written one. Absence is normal (early in a run); a present-but-corrupt
|
|
38
|
+
* file still throws `FindingsError` via `readFindings` — never swallowed.
|
|
39
|
+
*/
|
|
40
|
+
tryReadFindings(): Promise<Findings | null>;
|
|
41
|
+
/** Append a line to `logs/<channel>.log` (newline added if absent). Returns its path. */
|
|
42
|
+
appendLog(channel: LogChannel, line: string): Promise<string>;
|
|
43
|
+
/** Save a PNG as `screenshots/NNN-<label>.png` (auto-numbered). Returns its path. */
|
|
44
|
+
saveScreenshot(label: string, data: Uint8Array): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* List saved screenshots as ordered frames (`NNN-<label>.png`), ascending by
|
|
47
|
+
* sequence — the capture order the replay video stitches. Returns `[]` when none
|
|
48
|
+
* were saved yet (or the dir is missing); files that don't match the pattern are
|
|
49
|
+
* skipped. Decodes the step label back from the filename slug.
|
|
50
|
+
*/
|
|
51
|
+
listScreenshots(): Promise<ScreenshotFrame[]>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Findings store — the session's evidence locker on disk.
|
|
3
|
+
*
|
|
4
|
+
* Persists everything the small agent produces during a run, under the session
|
|
5
|
+
* paths from `workspace.ts`:
|
|
6
|
+
* - `findings.json` structured verdict, Zod-validated on write + read
|
|
7
|
+
* - `logs/{console,network,agent}.log` appended trails (caller owns the format)
|
|
8
|
+
* - `screenshots/NNN-step.png` ordered frames, auto-numbered for the replay video
|
|
9
|
+
*
|
|
10
|
+
* Every write returns the absolute path it wrote, so findings can reference
|
|
11
|
+
* evidence by path instead of inlining blobs into the smart agent's context.
|
|
12
|
+
* Directories are created lazily (idempotent); bad findings fail loud via
|
|
13
|
+
* `FindingsError` — never a silent fallback.
|
|
14
|
+
*/
|
|
15
|
+
import { access, appendFile, mkdir, readdir, readFile, writeFile } from 'node:fs/promises';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import { FindingsError } from '../errors.js';
|
|
18
|
+
import { FindingsSchema } from '../findings/schema.js';
|
|
19
|
+
/** Max slug length — keeps `NNN-<slug>.png` well under the 255-byte filename limit. */
|
|
20
|
+
const SLUG_MAX = 60;
|
|
21
|
+
/**
|
|
22
|
+
* Make a label filesystem-safe for a screenshot name; `step` if it empties out.
|
|
23
|
+
* Capped at {@link SLUG_MAX} chars — a long `look` question must never overflow the
|
|
24
|
+
* filename limit (`ENAMETOOLONG`) and sink the screenshot write.
|
|
25
|
+
*/
|
|
26
|
+
function slug(label) {
|
|
27
|
+
const s = label
|
|
28
|
+
.toLowerCase()
|
|
29
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
30
|
+
.replace(/^-+|-+$/g, '')
|
|
31
|
+
.slice(0, SLUG_MAX)
|
|
32
|
+
.replace(/-+$/g, '');
|
|
33
|
+
return s || 'step';
|
|
34
|
+
}
|
|
35
|
+
export class FindingsStore {
|
|
36
|
+
#paths;
|
|
37
|
+
/** Cached mkdir promise — directories are ensured once per instance. */
|
|
38
|
+
#dirsReady = null;
|
|
39
|
+
/** Highest screenshot sequence seen; lazily seeded from disk (resume-safe). */
|
|
40
|
+
#screenshotSeq = null;
|
|
41
|
+
constructor(paths) {
|
|
42
|
+
this.#paths = paths;
|
|
43
|
+
}
|
|
44
|
+
/** Validate + write `findings.json` (overwrites). Returns its path. */
|
|
45
|
+
async writeFindings(findings) {
|
|
46
|
+
const result = FindingsSchema.safeParse(findings);
|
|
47
|
+
if (!result.success) {
|
|
48
|
+
const issues = result.error.issues
|
|
49
|
+
.map((i) => `${i.path.map(String).join('.') || '(root)'}: ${i.message}`)
|
|
50
|
+
.join('; ');
|
|
51
|
+
throw new FindingsError(`Refusing to write invalid findings: ${issues}`);
|
|
52
|
+
}
|
|
53
|
+
await this.#ensureDirs();
|
|
54
|
+
await writeFile(this.#paths.findingsJson, `${JSON.stringify(result.data, null, 2)}\n`, 'utf8');
|
|
55
|
+
return this.#paths.findingsJson;
|
|
56
|
+
}
|
|
57
|
+
/** Read + validate `findings.json`. Throws `FindingsError` if missing/corrupt. */
|
|
58
|
+
async readFindings() {
|
|
59
|
+
let raw;
|
|
60
|
+
try {
|
|
61
|
+
raw = await readFile(this.#paths.findingsJson, 'utf8');
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
throw new FindingsError(`Failed to read findings.json: ${e instanceof Error ? e.message : String(e)}`);
|
|
65
|
+
}
|
|
66
|
+
let data;
|
|
67
|
+
try {
|
|
68
|
+
data = JSON.parse(raw);
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
throw new FindingsError(`findings.json is not valid JSON: ${e instanceof Error ? e.message : String(e)}`);
|
|
72
|
+
}
|
|
73
|
+
const result = FindingsSchema.safeParse(data);
|
|
74
|
+
if (!result.success) {
|
|
75
|
+
const issues = result.error.issues
|
|
76
|
+
.map((i) => `${i.path.map(String).join('.') || '(root)'}: ${i.message}`)
|
|
77
|
+
.join('; ');
|
|
78
|
+
throw new FindingsError(`findings.json is invalid: ${issues}`);
|
|
79
|
+
}
|
|
80
|
+
return result.data;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Read + validate `findings.json` if it exists yet; `null` if the agent has
|
|
84
|
+
* not written one. Absence is normal (early in a run); a present-but-corrupt
|
|
85
|
+
* file still throws `FindingsError` via `readFindings` — never swallowed.
|
|
86
|
+
*/
|
|
87
|
+
async tryReadFindings() {
|
|
88
|
+
try {
|
|
89
|
+
await access(this.#paths.findingsJson);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
return this.readFindings();
|
|
95
|
+
}
|
|
96
|
+
/** Append a line to `logs/<channel>.log` (newline added if absent). Returns its path. */
|
|
97
|
+
async appendLog(channel, line) {
|
|
98
|
+
await this.#ensureDirs();
|
|
99
|
+
const file = join(this.#paths.logs, `${channel}.log`);
|
|
100
|
+
await appendFile(file, line.endsWith('\n') ? line : `${line}\n`, 'utf8');
|
|
101
|
+
return file;
|
|
102
|
+
}
|
|
103
|
+
/** Save a PNG as `screenshots/NNN-<label>.png` (auto-numbered). Returns its path. */
|
|
104
|
+
async saveScreenshot(label, data) {
|
|
105
|
+
await this.#ensureDirs();
|
|
106
|
+
const seq = await this.#nextSeq();
|
|
107
|
+
const file = join(this.#paths.screenshots, `${String(seq).padStart(3, '0')}-${slug(label)}.png`);
|
|
108
|
+
await writeFile(file, data);
|
|
109
|
+
return file;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* List saved screenshots as ordered frames (`NNN-<label>.png`), ascending by
|
|
113
|
+
* sequence — the capture order the replay video stitches. Returns `[]` when none
|
|
114
|
+
* were saved yet (or the dir is missing); files that don't match the pattern are
|
|
115
|
+
* skipped. Decodes the step label back from the filename slug.
|
|
116
|
+
*/
|
|
117
|
+
async listScreenshots() {
|
|
118
|
+
let entries;
|
|
119
|
+
try {
|
|
120
|
+
entries = await readdir(this.#paths.screenshots);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
const frames = [];
|
|
126
|
+
for (const entry of entries) {
|
|
127
|
+
const match = /^(\d+)-(.*)\.png$/.exec(entry);
|
|
128
|
+
const digits = match?.[1];
|
|
129
|
+
const slug = match?.[2];
|
|
130
|
+
if (digits === undefined || slug === undefined)
|
|
131
|
+
continue;
|
|
132
|
+
frames.push({
|
|
133
|
+
seq: Number(digits),
|
|
134
|
+
path: join(this.#paths.screenshots, entry),
|
|
135
|
+
label: slug.replace(/-+/g, ' ').trim() || 'step',
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return frames.sort((a, b) => a.seq - b.seq);
|
|
139
|
+
}
|
|
140
|
+
/** Create `screenshots/` + `logs/` (and the session root) once; idempotent. */
|
|
141
|
+
#ensureDirs() {
|
|
142
|
+
if (this.#dirsReady === null) {
|
|
143
|
+
this.#dirsReady = Promise.all([
|
|
144
|
+
mkdir(this.#paths.screenshots, { recursive: true }),
|
|
145
|
+
mkdir(this.#paths.logs, { recursive: true }),
|
|
146
|
+
]).then(() => undefined);
|
|
147
|
+
}
|
|
148
|
+
return this.#dirsReady;
|
|
149
|
+
}
|
|
150
|
+
/** Next screenshot index, seeding from existing files so resume never overwrites. */
|
|
151
|
+
async #nextSeq() {
|
|
152
|
+
if (this.#screenshotSeq === null) {
|
|
153
|
+
this.#screenshotSeq = await this.#scanMaxSeq();
|
|
154
|
+
}
|
|
155
|
+
this.#screenshotSeq += 1;
|
|
156
|
+
return this.#screenshotSeq;
|
|
157
|
+
}
|
|
158
|
+
/** Highest `NNN-` prefix already in `screenshots/`, or 0 if none/missing. */
|
|
159
|
+
async #scanMaxSeq() {
|
|
160
|
+
let entries;
|
|
161
|
+
try {
|
|
162
|
+
entries = await readdir(this.#paths.screenshots);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return 0;
|
|
166
|
+
}
|
|
167
|
+
let max = 0;
|
|
168
|
+
for (const entry of entries) {
|
|
169
|
+
const num = /^(\d+)-/.exec(entry)?.[1];
|
|
170
|
+
if (num !== undefined)
|
|
171
|
+
max = Math.max(max, Number(num));
|
|
172
|
+
}
|
|
173
|
+
return max;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=findings-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findings-store.js","sourceRoot":"","sources":["../../src/session/findings-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAE,IA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project (cwd) = one session (`idea/overview.md`, `idea/architecture.md`).
|
|
5
|
+
* That project's persistent Chrome profile can only be driven by a single
|
|
6
|
+
* browser at a time, so the manager is the in-process gate that holds the
|
|
7
|
+
* profile lock: while a session is registered for a cwd, a second `start()`
|
|
8
|
+
* fails loud with `SessionBusyError`. Ending the session frees the lock.
|
|
9
|
+
*
|
|
10
|
+
* The manager is deliberately blind to what a session *is* — it only needs the
|
|
11
|
+
* `ManagedSession` surface (an id + how to close it). The concrete session
|
|
12
|
+
* (agent loop, adapter, findings store) is wired in later tasks.
|
|
13
|
+
*/
|
|
14
|
+
/** The minimal surface the manager needs to own a session's lifecycle. */
|
|
15
|
+
export interface ManagedSession {
|
|
16
|
+
/** Stable session id (e.g. from `generateSessionId`). */
|
|
17
|
+
readonly id: string;
|
|
18
|
+
/** Release everything the run holds — abort the loop, close the adapter, free the profile. */
|
|
19
|
+
close(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Registry of active debug sessions, keyed by absolute cwd.
|
|
23
|
+
* @typeParam S - concrete session type (defaults to the bare `ManagedSession` surface).
|
|
24
|
+
*/
|
|
25
|
+
export declare class SessionManager<S extends ManagedSession = ManagedSession> {
|
|
26
|
+
#private;
|
|
27
|
+
/**
|
|
28
|
+
* Register `session` as the active run for `cwd`, taking the project's profile lock.
|
|
29
|
+
* @returns the same session, for ergonomic inline construction.
|
|
30
|
+
* @throws {SessionBusyError} if a session is already active for this cwd.
|
|
31
|
+
*/
|
|
32
|
+
start(cwd: string, session: S): S;
|
|
33
|
+
/**
|
|
34
|
+
* Get the active session for `cwd`.
|
|
35
|
+
* @throws {SessionNotFoundError} if no session is active for this cwd.
|
|
36
|
+
*/
|
|
37
|
+
get(cwd: string): S;
|
|
38
|
+
/** Whether a session is currently active for `cwd` (non-throwing). */
|
|
39
|
+
has(cwd: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* End the active session for `cwd`: free the profile lock, then close the session.
|
|
42
|
+
* The slot is released *before* `close()` runs, so a failed teardown never wedges
|
|
43
|
+
* the project — the close error still propagates to the caller.
|
|
44
|
+
* @throws {SessionNotFoundError} if no session is active for this cwd.
|
|
45
|
+
*/
|
|
46
|
+
end(cwd: string): Promise<void>;
|
|
47
|
+
}
|