@developerz.ai/ui-debugger-mcp 1.0.4 → 1.2.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 +22 -10
- package/dist/adapters/android/adb.d.ts +34 -5
- package/dist/adapters/android/adb.js +74 -20
- package/dist/adapters/android/adb.js.map +1 -1
- package/dist/adapters/android/android-adapter.d.ts +23 -7
- package/dist/adapters/android/android-adapter.js +106 -36
- package/dist/adapters/android/android-adapter.js.map +1 -1
- package/dist/adapters/android/android-adapter.test-helpers.d.ts +52 -0
- package/dist/adapters/android/android-adapter.test-helpers.js +115 -0
- package/dist/adapters/android/android-adapter.test-helpers.js.map +1 -0
- package/dist/adapters/android/commands.d.ts +27 -4
- package/dist/adapters/android/commands.js +66 -4
- package/dist/adapters/android/commands.js.map +1 -1
- package/dist/adapters/android/ports.d.ts +32 -0
- package/dist/adapters/android/ports.js +47 -0
- package/dist/adapters/android/ports.js.map +1 -0
- package/dist/adapters/android/uiautomator.d.ts +10 -2
- package/dist/adapters/android/uiautomator.js +36 -4
- package/dist/adapters/android/uiautomator.js.map +1 -1
- package/dist/adapters/browser/browser-adapter.d.ts +14 -13
- package/dist/adapters/browser/browser-adapter.js +81 -200
- package/dist/adapters/browser/browser-adapter.js.map +1 -1
- package/dist/adapters/browser/cdp.js +18 -11
- package/dist/adapters/browser/cdp.js.map +1 -1
- package/dist/adapters/browser/extractor.d.ts +49 -0
- package/dist/adapters/browser/extractor.js +208 -0
- package/dist/adapters/browser/extractor.js.map +1 -0
- package/dist/adapters/browser/filters.d.ts +15 -0
- package/dist/adapters/browser/filters.js +93 -0
- package/dist/adapters/browser/filters.js.map +1 -0
- package/dist/adapters/browser/launch.d.ts +41 -0
- package/dist/adapters/browser/launch.js +61 -0
- package/dist/adapters/browser/launch.js.map +1 -0
- package/dist/adapters/browser/query.d.ts +3 -2
- package/dist/adapters/browser/query.js +68 -2
- package/dist/adapters/browser/query.js.map +1 -1
- package/dist/adapters/budget.d.ts +16 -0
- package/dist/adapters/budget.js +25 -0
- package/dist/adapters/budget.js.map +1 -0
- package/dist/adapters/contract.d.ts +29 -6
- package/dist/adapters/desktop/atspi.d.ts +15 -0
- package/dist/adapters/desktop/atspi.js +37 -17
- package/dist/adapters/desktop/atspi.js.map +1 -1
- package/dist/adapters/desktop/capture.js +8 -1
- package/dist/adapters/desktop/capture.js.map +1 -1
- package/dist/adapters/desktop/desktop-adapter.d.ts +9 -2
- package/dist/adapters/desktop/desktop-adapter.js +84 -32
- package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
- package/dist/adapters/desktop/input.d.ts +16 -1
- package/dist/adapters/desktop/input.js +30 -0
- package/dist/adapters/desktop/input.js.map +1 -1
- package/dist/adapters/desktop/proc.d.ts +18 -3
- package/dist/adapters/desktop/proc.js +48 -5
- package/dist/adapters/desktop/proc.js.map +1 -1
- package/dist/adapters/factory.d.ts +3 -1
- package/dist/adapters/factory.js +6 -2
- package/dist/adapters/factory.js.map +1 -1
- package/dist/adapters/limit.d.ts +10 -0
- package/dist/adapters/limit.js +19 -0
- package/dist/adapters/limit.js.map +1 -0
- package/dist/agent/belt/act.d.ts +27 -5
- package/dist/agent/belt/act.js +75 -17
- package/dist/agent/belt/act.js.map +1 -1
- package/dist/agent/belt/look.d.ts +37 -0
- package/dist/agent/belt/look.js +96 -4
- package/dist/agent/belt/look.js.map +1 -1
- package/dist/agent/belt/observe.d.ts +35 -9
- package/dist/agent/belt/observe.js +127 -18
- package/dist/agent/belt/observe.js.map +1 -1
- package/dist/agent/belt/report.d.ts +29 -9
- package/dist/agent/belt/report.js +77 -10
- package/dist/agent/belt/report.js.map +1 -1
- package/dist/agent/belt/trail.d.ts +34 -0
- package/dist/agent/belt/trail.js +64 -0
- package/dist/agent/belt/trail.js.map +1 -0
- package/dist/agent/capabilities.d.ts +30 -0
- package/dist/agent/capabilities.js +75 -0
- package/dist/agent/capabilities.js.map +1 -0
- package/dist/agent/loop.d.ts +68 -19
- package/dist/agent/loop.js +195 -51
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/prompts/compose.d.ts +9 -1
- package/dist/agent/prompts/compose.js +5 -4
- package/dist/agent/prompts/compose.js.map +1 -1
- package/dist/agent/prompts/debug-agent.d.ts +13 -1
- package/dist/agent/prompts/debug-agent.js +47 -7
- package/dist/agent/prompts/debug-agent.js.map +1 -1
- package/dist/agent/prompts/desktop-addendum.d.ts +1 -1
- package/dist/agent/prompts/desktop-addendum.js +1 -1
- package/dist/agent/prompts/web-addendum.d.ts +1 -1
- package/dist/agent/prompts/web-addendum.js +45 -17
- package/dist/agent/prompts/web-addendum.js.map +1 -1
- package/dist/agent/provider.d.ts +12 -3
- package/dist/agent/provider.js +13 -8
- package/dist/agent/provider.js.map +1 -1
- package/dist/cli/control.d.ts +3 -1
- package/dist/cli/control.js +26 -40
- package/dist/cli/control.js.map +1 -1
- package/dist/cli/help.d.ts +3 -1
- package/dist/cli/help.js +6 -2
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/init.d.ts +3 -6
- package/dist/cli/init.js +64 -16
- package/dist/cli/init.js.map +1 -1
- package/dist/config/load.js +8 -1
- package/dist/config/load.js.map +1 -1
- package/dist/config/schema.d.ts +12 -5
- package/dist/config/schema.js +17 -7
- package/dist/config/schema.js.map +1 -1
- package/dist/errors.d.ts +22 -2
- package/dist/errors.js +36 -4
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/main.js +38 -11
- package/dist/main.js.map +1 -1
- package/dist/mcp/server.d.ts +16 -1
- package/dist/mcp/server.js +23 -2
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/server.test-helpers.d.ts +23 -0
- package/dist/mcp/server.test-helpers.js +49 -0
- package/dist/mcp/server.test-helpers.js.map +1 -0
- package/dist/mcp/tools/describe.js +5 -0
- package/dist/mcp/tools/describe.js.map +1 -1
- package/dist/mcp/tools/end-session.js +5 -0
- package/dist/mcp/tools/end-session.js.map +1 -1
- package/dist/mcp/tools/get-findings.js +23 -3
- package/dist/mcp/tools/get-findings.js.map +1 -1
- package/dist/mcp/tools/output.d.ts +50 -0
- package/dist/mcp/tools/output.js +55 -0
- package/dist/mcp/tools/output.js.map +1 -0
- package/dist/mcp/tools/result.d.ts +24 -1
- package/dist/mcp/tools/result.js +106 -5
- package/dist/mcp/tools/result.js.map +1 -1
- package/dist/mcp/tools/send-message.js +5 -0
- package/dist/mcp/tools/send-message.js.map +1 -1
- package/dist/mcp/tools/start-debug.js +7 -1
- package/dist/mcp/tools/start-debug.js.map +1 -1
- package/dist/services/debug-service.d.ts +38 -6
- package/dist/services/debug-service.js +122 -13
- package/dist/services/debug-service.js.map +1 -1
- package/dist/services/session-builder.d.ts +26 -3
- package/dist/services/session-builder.js +46 -14
- package/dist/services/session-builder.js.map +1 -1
- package/dist/session/atomic-write.d.ts +24 -0
- package/dist/session/atomic-write.js +39 -0
- package/dist/session/atomic-write.js.map +1 -0
- package/dist/session/findings-store.js +3 -4
- package/dist/session/findings-store.js.map +1 -1
- package/dist/session/process-identity.d.ts +16 -0
- package/dist/session/process-identity.js +29 -0
- package/dist/session/process-identity.js.map +1 -1
- package/dist/session/session.js +10 -2
- package/dist/session/session.js.map +1 -1
- package/dist/session/state-file.d.ts +51 -5
- package/dist/session/state-file.js +60 -8
- package/dist/session/state-file.js.map +1 -1
- package/dist/session/workspace.d.ts +11 -0
- package/dist/session/workspace.js +14 -1
- package/dist/session/workspace.js.map +1 -1
- package/package.json +4 -1
|
@@ -8,10 +8,22 @@
|
|
|
8
8
|
* seam — so the orchestration here unit-tests with no browser or network. The MCP
|
|
9
9
|
* handlers stay thin: validate input, call straight through to a method here.
|
|
10
10
|
*
|
|
11
|
+
* One run per project holds *across processes* too: the manager only knows this
|
|
12
|
+
* server's memory, so `start` also consults the `state.json` breadcrumb and
|
|
13
|
+
* refuses when another live server already owns a run here (a dead owner's stale
|
|
14
|
+
* breadcrumb never blocks).
|
|
15
|
+
*
|
|
11
16
|
* Sessions are keyed by cwd, but the tools speak `session_id`. Every id-bearing
|
|
12
17
|
* call resolves the active session for the cwd and fails loud
|
|
13
18
|
* ({@link SessionNotFoundError}) when the id does not match, so a stale id never
|
|
14
19
|
* silently drives the wrong run.
|
|
20
|
+
*
|
|
21
|
+
* A run that ends *without* the caller asking (wall-clock timeout, SIGTERM, the
|
|
22
|
+
* MCP client dying) leaves the manager, but its findings must not vanish with it:
|
|
23
|
+
* the settled session is retained so `get_findings` keeps serving its terminal
|
|
24
|
+
* snapshot. `end_session` is the explicit forget; the next `start_debug`
|
|
25
|
+
* supersedes it. The retained snapshot holds no target resources (the adapter is
|
|
26
|
+
* already closed) and never participates in the one-run gate.
|
|
15
27
|
*/
|
|
16
28
|
import { SessionBusyError, SessionNotFoundError, SessionSettledError, TargetNotFoundError, } from '../errors.js';
|
|
17
29
|
import { noopStatePort } from '../session/state-file.js';
|
|
@@ -28,6 +40,13 @@ export class DebugService {
|
|
|
28
40
|
#now;
|
|
29
41
|
/** Live wall-clock timer for the active run; cleared when the run ends. */
|
|
30
42
|
#timer;
|
|
43
|
+
/**
|
|
44
|
+
* The last run that auto-ended (timeout / SIGTERM / client death), kept settled
|
|
45
|
+
* and closed so `get_findings` can still read its partial findings + evidence.
|
|
46
|
+
* Dropped by `end_session` (the explicit forget) and superseded by the next run.
|
|
47
|
+
* Never consulted by the one-run gate — a retained snapshot cannot block a start.
|
|
48
|
+
*/
|
|
49
|
+
#retained;
|
|
31
50
|
/**
|
|
32
51
|
* A `start()` is in flight (building/launching, slot not yet in the manager).
|
|
33
52
|
* Set synchronously before the first await so a concurrent `start_debug` fails
|
|
@@ -47,8 +66,14 @@ export class DebugService {
|
|
|
47
66
|
/**
|
|
48
67
|
* Open a run: assemble the session, take the profile lock, point the adapter at
|
|
49
68
|
* the target, and kick the loop off in the background. Fails loud if a run is
|
|
50
|
-
* already active for this cwd ({@link SessionBusyError})
|
|
51
|
-
*
|
|
69
|
+
* already active for this cwd ({@link SessionBusyError}) — whether it belongs to
|
|
70
|
+
* this server (the manager / in-flight guard) or to another live one (the
|
|
71
|
+
* `state.json` breadcrumb); never leaks a launched browser — a lost lock race or
|
|
72
|
+
* a failed `open` tears the session back down.
|
|
73
|
+
*
|
|
74
|
+
* `timeout` is wall-clock from HERE: the deadline is fixed on entry and the
|
|
75
|
+
* remaining budget is threaded into the build and the first navigation, so a slow
|
|
76
|
+
* Chrome launch spends the caller's cap instead of sitting outside it.
|
|
52
77
|
*/
|
|
53
78
|
async start({ target, goal, criteria, url, timeoutMs }) {
|
|
54
79
|
const cwd = this.#cwd;
|
|
@@ -63,9 +88,13 @@ export class DebugService {
|
|
|
63
88
|
'Wait for it to open (or end it) before starting another — one run per project at a time.');
|
|
64
89
|
}
|
|
65
90
|
this.#starting = true;
|
|
91
|
+
const deadline = this.#now() + (timeoutMs ?? this.#defaultTimeoutMs);
|
|
92
|
+
/** Budget left on the caller's cap; never negative — a blown budget is simply spent. */
|
|
93
|
+
const remaining = () => Math.max(0, deadline - this.#now());
|
|
66
94
|
try {
|
|
95
|
+
await this.#assertNoForeignRun(cwd);
|
|
67
96
|
const id = generateSessionId(this.#now());
|
|
68
|
-
const built = await this.#build({ id, target, goal, criteria, url });
|
|
97
|
+
const built = await this.#build({ id, target, goal, criteria, url, timeoutMs: remaining() });
|
|
69
98
|
try {
|
|
70
99
|
this.#manager.start(cwd, built.session);
|
|
71
100
|
}
|
|
@@ -73,23 +102,59 @@ export class DebugService {
|
|
|
73
102
|
await built.session.close().catch(() => undefined);
|
|
74
103
|
throw err;
|
|
75
104
|
}
|
|
105
|
+
// This run owns the slot now — the previous run's retained snapshot is
|
|
106
|
+
// superseded (its findings.json stays on disk for the CLI / a human).
|
|
107
|
+
this.#retained = undefined;
|
|
76
108
|
try {
|
|
77
|
-
await built.open();
|
|
109
|
+
await built.open(remaining());
|
|
78
110
|
built.session.start(built.run);
|
|
79
111
|
}
|
|
80
112
|
catch (err) {
|
|
81
113
|
await this.#manager.end(cwd).catch(() => undefined);
|
|
82
114
|
throw err;
|
|
83
115
|
}
|
|
84
|
-
|
|
85
|
-
|
|
116
|
+
// Armed BEFORE the breadcrumb write, on what is LEFT of the cap: a throwing
|
|
117
|
+
// StatePort must never leave a live run with no timer on it, and the launch
|
|
118
|
+
// already spent part of the budget.
|
|
119
|
+
this.#armTimeout(remaining());
|
|
120
|
+
try {
|
|
121
|
+
await this.#state.record({ sessionId: id, target, goal });
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
// The caller gets no session_id back, so nothing could ever end this run —
|
|
125
|
+
// tear it down here (and drop any half-written breadcrumb) and fail loud.
|
|
126
|
+
this.#clearTimeout();
|
|
127
|
+
await this.#manager.end(cwd).catch(() => undefined);
|
|
128
|
+
await this.#state.clear().catch(() => undefined);
|
|
129
|
+
throw err;
|
|
130
|
+
}
|
|
86
131
|
return { session_id: id };
|
|
87
132
|
}
|
|
88
133
|
finally {
|
|
89
134
|
this.#starting = false;
|
|
90
135
|
}
|
|
91
136
|
}
|
|
92
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* The other half of the one-run gate: another *live* server process holding a
|
|
139
|
+
* run on this project. The manager only sees this process's memory, so without
|
|
140
|
+
* this a second MCP client on the same cwd would launch a second run onto the
|
|
141
|
+
* same profile/emulator and overwrite the live breadcrumb (leaving the CLI
|
|
142
|
+
* pointing at the wrong pid). A dead or PID-recycled owner does not count — a
|
|
143
|
+
* crashed server's stale `running` file must never wedge the project shut.
|
|
144
|
+
*/
|
|
145
|
+
async #assertNoForeignRun(cwd) {
|
|
146
|
+
const foreign = await this.#state.foreignRun();
|
|
147
|
+
if (foreign === null)
|
|
148
|
+
return;
|
|
149
|
+
throw new SessionBusyError(`Another ui-debugger-mcp server (pid ${foreign.pid}) already has a debug session ` +
|
|
150
|
+
`('${foreign.sessionId}') active for '${cwd}'. End it (or run 'ui-debugger-mcp stop') ` +
|
|
151
|
+
'before starting another — one run per project at a time.');
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Arm the wall-clock cap on what is LEFT of the run's budget: auto-end the run when
|
|
155
|
+
* it fires (replaces any prior timer). `0` — the launch outlived the whole cap —
|
|
156
|
+
* ends the run on the next tick rather than granting it a fresh one.
|
|
157
|
+
*/
|
|
93
158
|
#armTimeout(ms) {
|
|
94
159
|
this.#clearTimeout();
|
|
95
160
|
this.#timer = setTimeout(() => {
|
|
@@ -118,12 +183,15 @@ export class DebugService {
|
|
|
118
183
|
session.pushMessage(message);
|
|
119
184
|
return { ok: true, session_id };
|
|
120
185
|
}
|
|
121
|
-
/**
|
|
186
|
+
/**
|
|
187
|
+
* Snapshot the run's findings — optionally long-poll (`wait`) and/or project a
|
|
188
|
+
* subset (`fields`). Serves the retained terminal snapshot once the run has
|
|
189
|
+
* auto-ended, so a timed-out run's partial findings stay reachable (the
|
|
190
|
+
* long-poll returns at once: a settled run has nothing left to wait for).
|
|
191
|
+
*/
|
|
122
192
|
async getFindings({ session_id, wait, fields, }) {
|
|
123
|
-
const session = this.#
|
|
124
|
-
return fields
|
|
125
|
-
? session.snapshot(fields, wait)
|
|
126
|
-
: session.snapshot(undefined, wait);
|
|
193
|
+
const session = this.#requireReadable(session_id);
|
|
194
|
+
return fields ? session.snapshot(fields, wait) : session.snapshot(undefined, wait);
|
|
127
195
|
}
|
|
128
196
|
/** List configured targets (the whole catalog, or one when named) plus resolved models/workspace. */
|
|
129
197
|
describe({ target }) {
|
|
@@ -138,8 +206,15 @@ export class DebugService {
|
|
|
138
206
|
workspace: this.#config.workspace,
|
|
139
207
|
};
|
|
140
208
|
}
|
|
141
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* End the active run: abort the loop, close the adapter, free the profile lock.
|
|
211
|
+
* Ending a run that already auto-ended (timeout / client death) is not an error
|
|
212
|
+
* — it just forgets the retained snapshot, so `end_session` reads the same
|
|
213
|
+
* either way and stays the one explicit forget.
|
|
214
|
+
*/
|
|
142
215
|
async end({ session_id }) {
|
|
216
|
+
if (this.#forgetRetained(session_id))
|
|
217
|
+
return { ok: true, session_id };
|
|
143
218
|
this.#require(session_id);
|
|
144
219
|
this.#clearTimeout();
|
|
145
220
|
// Clear the breadcrumb even when the close throws: the manager frees the slot
|
|
@@ -162,6 +237,10 @@ export class DebugService {
|
|
|
162
237
|
this.#clearTimeout();
|
|
163
238
|
if (!this.#manager.has(this.#cwd))
|
|
164
239
|
return;
|
|
240
|
+
// Nobody asked for this end, so nobody has read the results yet: retain the
|
|
241
|
+
// session (settled + closed) so `get_findings` still serves them. Captured
|
|
242
|
+
// before the close, so even a failing teardown leaves the findings reachable.
|
|
243
|
+
this.#retained = this.#manager.get(this.#cwd);
|
|
165
244
|
// Same contract as `end()`: the breadcrumb clears even when the close throws.
|
|
166
245
|
try {
|
|
167
246
|
await this.#manager.end(this.#cwd);
|
|
@@ -170,6 +249,36 @@ export class DebugService {
|
|
|
170
249
|
await this.#state.clear();
|
|
171
250
|
}
|
|
172
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Resolve the session a read names: the active run, or — once the manager is
|
|
254
|
+
* empty — the retained snapshot of the last auto-ended run, so a timed-out run's
|
|
255
|
+
* partial findings stay readable by their id until `end_session` or the next
|
|
256
|
+
* `start_debug`. A different id still fails loud.
|
|
257
|
+
*/
|
|
258
|
+
#requireReadable(session_id) {
|
|
259
|
+
const retained = this.#retained;
|
|
260
|
+
if (retained === undefined || this.#manager.has(this.#cwd)) {
|
|
261
|
+
return this.#require(session_id);
|
|
262
|
+
}
|
|
263
|
+
if (retained.id !== session_id) {
|
|
264
|
+
throw new SessionNotFoundError(`No active debug session '${session_id}' for '${this.#cwd}' (the last run '${retained.id}' ` +
|
|
265
|
+
'has ended; its findings are still readable under that id).');
|
|
266
|
+
}
|
|
267
|
+
return retained;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Forget the retained snapshot when the caller's `end_session` names it — the
|
|
271
|
+
* run is already torn down, so there is nothing left to close. Returns whether
|
|
272
|
+
* the id was the retained one (and it is now forgotten).
|
|
273
|
+
*/
|
|
274
|
+
#forgetRetained(session_id) {
|
|
275
|
+
if (this.#manager.has(this.#cwd))
|
|
276
|
+
return false;
|
|
277
|
+
if (this.#retained?.id !== session_id)
|
|
278
|
+
return false;
|
|
279
|
+
this.#retained = undefined;
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
173
282
|
/** Resolve the active session for this cwd, asserting its id matches the caller's. */
|
|
174
283
|
#require(session_id) {
|
|
175
284
|
const session = this.#manager.get(this.#cwd);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug-service.js","sourceRoot":"","sources":["../../src/services/debug-service.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"debug-service.js","sourceRoot":"","sources":["../../src/services/debug-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAItB,OAAO,EAAE,aAAa,EAAkB,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,uFAAuF;AACvF,MAAM,CAAC,MAAM,0BAA0B,GAAG,OAAO,CAAC;AAmGlD,MAAM,OAAO,YAAY;IACd,QAAQ,CAA0B;IAClC,OAAO,CAAiB;IACxB,IAAI,CAAS;IACb,MAAM,CAAiB;IACvB,MAAM,CAAY;IAClB,iBAAiB,CAAS;IAC1B,IAAI,CAAe;IAC5B,2EAA2E;IAC3E,MAAM,CAA4C;IAClD;;;;;OAKG;IACH,SAAS,CAAsB;IAC/B;;;;;OAKG;IACH,SAAS,GAAG,KAAK,CAAC;IAElB,YAAY,IAAsB;QAChC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,IAAI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,MAAM,IAAI,oBAAoB,CAC5B,4BAA4B,UAAU,UAAU,IAAI,CAAC,IAAI,yBAAyB,OAAO,CAAC,EAAE,KAAK,CAClG,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAED,6FAA6F;AAC7F,SAAS,QAAQ,CAAC,MAAc;IAC9B,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC;IAC/D,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC;IAClE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,qFAAqF;AACrF,SAAS,cAAc,CAAC,IAAY,EAAE,MAAc;IAClD,MAAM,IAAI,GAAe;QACvB,IAAI;QACJ,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;QAC7C,WAAW,EAAE,IAAI;KAClB,CAAC;IACF,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;IACjE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* leaks a launched browser. The builder stays adapter- and model-blind past this
|
|
14
14
|
* seam; swapping the driver model or the target never touches the service.
|
|
15
15
|
*/
|
|
16
|
-
import type { LanguageModel } from 'ai';
|
|
16
|
+
import type { LanguageModel, Tool } from 'ai';
|
|
17
17
|
import type { ResolvedConfig } from '../config/load.js';
|
|
18
18
|
import type { Target } from '../config/schema.js';
|
|
19
19
|
import { type LoopRunner, Session } from '../session/session.js';
|
|
@@ -26,6 +26,12 @@ export interface BuilderModels {
|
|
|
26
26
|
vision: LanguageModel;
|
|
27
27
|
/** summary guy — condenses the terminal findings into one paragraph for the smart agent. */
|
|
28
28
|
summary: LanguageModel;
|
|
29
|
+
/**
|
|
30
|
+
* Control + vision are the SAME multimodal model (probed at boot via the
|
|
31
|
+
* provider catalog): `look` hands the frame straight to the driver instead
|
|
32
|
+
* of a second blind vision call.
|
|
33
|
+
*/
|
|
34
|
+
selfLook?: boolean;
|
|
29
35
|
}
|
|
30
36
|
/** What the builder needs that does not change between runs. */
|
|
31
37
|
export interface SessionBuilderDeps {
|
|
@@ -45,13 +51,22 @@ export interface BuildSessionParams {
|
|
|
45
51
|
criteria?: string;
|
|
46
52
|
/** Per-run URL the caller points the driver at (web); overrides the target's configured url. */
|
|
47
53
|
url?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The run's remaining wall-clock budget (ms) at build time. Assembly happens inside
|
|
56
|
+
* the caller's `timeout`, so the launch/connect wait shortens to fit it.
|
|
57
|
+
*/
|
|
58
|
+
timeoutMs?: number;
|
|
48
59
|
}
|
|
49
60
|
/** A built-but-unregistered session plus the seams the service fires post-lock. */
|
|
50
61
|
export interface BuiltSession {
|
|
51
62
|
/** Ready to register with the manager; not yet opened or started. */
|
|
52
63
|
session: Session;
|
|
53
|
-
/**
|
|
54
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Navigate the adapter to the target (launches/attaches the browser page).
|
|
66
|
+
* `timeoutMs` is the run's budget left AFTER the build — the first navigation
|
|
67
|
+
* spends the caller's cap, never a fresh one of its own.
|
|
68
|
+
*/
|
|
69
|
+
open(timeoutMs?: number): Promise<void>;
|
|
55
70
|
/** The background loop runner handed to `session.start()`. */
|
|
56
71
|
run: LoopRunner;
|
|
57
72
|
}
|
|
@@ -59,6 +74,14 @@ export interface BuiltSession {
|
|
|
59
74
|
export type SessionBuilder = (params: BuildSessionParams) => Promise<BuiltSession>;
|
|
60
75
|
/** Bind {@link buildSession} to its shared deps, yielding the per-run {@link SessionBuilder}. */
|
|
61
76
|
export declare function makeSessionBuilder(deps: SessionBuilderDeps): SessionBuilder;
|
|
77
|
+
/**
|
|
78
|
+
* Wrap a belt tool so every call records its input to `logs/agent.log`, and any
|
|
79
|
+
* thrown error is logged before it propagates — otherwise a belt failure (e.g. a
|
|
80
|
+
* selector that resolves nothing) is invisible: the SDK feeds it back to the model
|
|
81
|
+
* as a tool-error and the run just churns. The wrapper is transparent: same
|
|
82
|
+
* input/output, it only observes.
|
|
83
|
+
*/
|
|
84
|
+
export declare function withToolLog(name: string, t: Tool, log: (line: string) => void): Tool;
|
|
62
85
|
/**
|
|
63
86
|
* Apply the caller's per-run `url` over the configured target (web only), and
|
|
64
87
|
* require that a web target ends up with *some* URL. Lets the boss point the
|
|
@@ -13,17 +13,19 @@
|
|
|
13
13
|
* leaks a launched browser. The builder stays adapter- and model-blind past this
|
|
14
14
|
* seam; swapping the driver model or the target never touches the service.
|
|
15
15
|
*/
|
|
16
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
16
17
|
import { createAdapter } from '../adapters/factory.js';
|
|
17
18
|
import { createActTool } from '../agent/belt/act.js';
|
|
18
|
-
import { createLookTool } from '../agent/belt/look.js';
|
|
19
|
+
import { createLookTool, createSelfLookTool } from '../agent/belt/look.js';
|
|
19
20
|
import { createObserveTool } from '../agent/belt/observe.js';
|
|
20
21
|
import { createReportTool } from '../agent/belt/report.js';
|
|
22
|
+
import { createActTrail } from '../agent/belt/trail.js';
|
|
21
23
|
import { createDebugAgent, runDebugLoop } from '../agent/loop.js';
|
|
22
24
|
import { composeSystemPrompt } from '../agent/prompts/compose.js';
|
|
23
25
|
import { ConfigError, TargetNotFoundError } from '../errors.js';
|
|
24
26
|
import { FindingsStore } from '../session/findings-store.js';
|
|
25
27
|
import { Session } from '../session/session.js';
|
|
26
|
-
import { ensureSession, sessionPaths } from '../session/workspace.js';
|
|
28
|
+
import { ensureSession, resolveProfileDir, sessionPaths, } from '../session/workspace.js';
|
|
27
29
|
import { createReplayStep } from './replay.js';
|
|
28
30
|
import { createSummarize } from './summarize.js';
|
|
29
31
|
/** Bind {@link buildSession} to its shared deps, yielding the per-run {@link SessionBuilder}. */
|
|
@@ -47,7 +49,7 @@ function compactInput(input) {
|
|
|
47
49
|
* as a tool-error and the run just churns. The wrapper is transparent: same
|
|
48
50
|
* input/output, it only observes.
|
|
49
51
|
*/
|
|
50
|
-
function withToolLog(name, t, log) {
|
|
52
|
+
export function withToolLog(name, t, log) {
|
|
51
53
|
const original = t.execute;
|
|
52
54
|
if (!original)
|
|
53
55
|
return t;
|
|
@@ -115,6 +117,17 @@ function splitCriteria(criteria) {
|
|
|
115
117
|
.filter((line) => line.length > 0);
|
|
116
118
|
return lines.length > 0 ? lines : undefined;
|
|
117
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Render `sessions/<id>/story.md` — the human-readable record of what this run was
|
|
122
|
+
* asked to do, so a person poking through the workspace after the fact doesn't have
|
|
123
|
+
* to reconstruct the goal from `findings.json` alone.
|
|
124
|
+
*/
|
|
125
|
+
function renderStoryMd(target, goal, criteriaLines) {
|
|
126
|
+
const criteriaBlock = criteriaLines
|
|
127
|
+
? criteriaLines.map((line) => `- ${line}`).join('\n')
|
|
128
|
+
: '(none)';
|
|
129
|
+
return `# Story\n\n**Target:** ${target}\n\n## Goal\n\n${goal}\n\n## Criteria\n\n${criteriaBlock}\n`;
|
|
130
|
+
}
|
|
118
131
|
/**
|
|
119
132
|
* Assemble a debug run: adapter + belt + composed prompt + loop runner, all bound
|
|
120
133
|
* to a fresh {@link FindingsStore}. Throws {@link TargetNotFoundError} if `target`
|
|
@@ -137,15 +150,29 @@ export async function buildSession(deps, params) {
|
|
|
137
150
|
const addendum = addendumTarget(targetConfig.adapter);
|
|
138
151
|
const paths = sessionPaths(workspace, id);
|
|
139
152
|
await ensureSession(paths);
|
|
153
|
+
const criteriaLines = splitCriteria(criteria);
|
|
154
|
+
await writeFile(paths.storyMd, renderStoryMd(target, goal, criteriaLines), 'utf8');
|
|
140
155
|
const store = new FindingsStore(paths);
|
|
141
156
|
const onLog = (channel, line) => {
|
|
142
157
|
void store.appendLog(channel, line).catch(() => undefined);
|
|
143
158
|
};
|
|
144
|
-
|
|
159
|
+
// `profile` is a browser-target key — no other adapter has a profile dir. A managed
|
|
160
|
+
// launch lives in it; attach ignores it (that browser keeps its own state).
|
|
161
|
+
// `ensureWorkspace` pre-creates only the default dir, so a custom one is made here.
|
|
162
|
+
const profile = targetConfig.adapter === 'browser' ? targetConfig.profile : undefined;
|
|
163
|
+
const profileDir = resolveProfileDir(workspace, profile);
|
|
164
|
+
if (profile)
|
|
165
|
+
await mkdir(profileDir, { recursive: true });
|
|
166
|
+
const adapter = await createAdapter(target, effectiveConfig, profileDir, onLog, params.timeoutMs);
|
|
167
|
+
// The prompt's eye mode MUST match the `look` tool bound below — self-look tells
|
|
168
|
+
// the driver to judge the attached frame itself; the vision variant tells it to ask
|
|
169
|
+
// the vision guy (and how to cope when that model turns out to be text-only).
|
|
170
|
+
const selfLook = models.selfLook === true;
|
|
145
171
|
const instructions = composeSystemPrompt({
|
|
146
172
|
target: addendum,
|
|
147
173
|
story: goal,
|
|
148
|
-
criteria:
|
|
174
|
+
criteria: criteriaLines,
|
|
175
|
+
selfLook,
|
|
149
176
|
});
|
|
150
177
|
const appendAgentLog = (line) => store.appendLog('agent', `${new Date().toISOString()} ${line}`);
|
|
151
178
|
// High-frequency, fire-and-forget: the agent's own log sink + per-step tool logs.
|
|
@@ -164,23 +191,28 @@ export async function buildSession(deps, params) {
|
|
|
164
191
|
}
|
|
165
192
|
};
|
|
166
193
|
const run = async ({ inbox, progress, signal }) => {
|
|
167
|
-
// One trail per run, shared between the
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
|
|
194
|
+
// One trail per run, shared between the `act` tool (which records every step as
|
|
195
|
+
// it finishes, `ok: false` included), the loop (which snapshots it into each
|
|
196
|
+
// running flush) and the `report` tool (which merges it with the driver's
|
|
197
|
+
// reported steps), so the persisted findings and the returned counts derive from
|
|
198
|
+
// the same object. `report` reads it through `settled()`, so an act racing it in
|
|
199
|
+
// the SAME step still makes the verdict.
|
|
200
|
+
const trail = createActTrail();
|
|
171
201
|
const agent = createDebugAgent({
|
|
172
202
|
model: models.driver,
|
|
173
203
|
tools: {
|
|
174
204
|
observe: withToolLog('observe', createObserveTool(adapter, store), logAgent),
|
|
175
|
-
act: withToolLog('act', createActTool(adapter, store), logAgent),
|
|
176
|
-
look: withToolLog('look',
|
|
177
|
-
|
|
205
|
+
act: withToolLog('act', createActTool(adapter, store, trail), logAgent),
|
|
206
|
+
look: withToolLog('look', selfLook
|
|
207
|
+
? createSelfLookTool(adapter, store)
|
|
208
|
+
: createLookTool(adapter, models.vision, store), logAgent),
|
|
209
|
+
report: withToolLog('report', createReportTool(store, () => trail.settled()), logAgent),
|
|
178
210
|
},
|
|
179
211
|
instructions,
|
|
180
212
|
inbox,
|
|
181
213
|
progress,
|
|
182
214
|
log: logAgent,
|
|
183
|
-
trail,
|
|
215
|
+
trail: trail.steps,
|
|
184
216
|
});
|
|
185
217
|
await flushAgentLog(`run start: target=${target} goal=${JSON.stringify(goal)}`);
|
|
186
218
|
try {
|
|
@@ -215,7 +247,7 @@ export async function buildSession(deps, params) {
|
|
|
215
247
|
});
|
|
216
248
|
return {
|
|
217
249
|
session,
|
|
218
|
-
open: () => adapter.open(openAddress(targetConfig)),
|
|
250
|
+
open: (timeoutMs) => adapter.open(openAddress(targetConfig), timeoutMs),
|
|
219
251
|
run,
|
|
220
252
|
};
|
|
221
253
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-builder.js","sourceRoot":"","sources":["../../src/services/session-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"session-builder.js","sourceRoot":"","sources":["../../src/services/session-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,EAAE,SA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AAE,QAAQ,EAAE,CAAC;KACzF,CAAC,CAAC;IAEH,OAAO;QACL,OAAO;QACP,IAAI,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,SAAS,CAAC;QACvE,GAAG;KACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atomic file replace — how every cross-process file in the workspace is written.
|
|
3
|
+
*
|
|
4
|
+
* `state.json` and `findings.json` are read by processes other than the writer:
|
|
5
|
+
* `ui-debugger-mcp status` / `stop` run out-of-band, and a second server checks
|
|
6
|
+
* the breadcrumb through {@link FileStatePort.foreignRun}. A plain `writeFile`
|
|
7
|
+
* truncates first, so a reader that lands mid-write sees an empty or half-written
|
|
8
|
+
* file — and both readers treat that as "no run" / "corrupt findings". Writing a
|
|
9
|
+
* temp file and `rename(2)`-ing it into place is atomic on the same filesystem:
|
|
10
|
+
* a reader sees either the old bytes or the new ones, never a torn mix.
|
|
11
|
+
*
|
|
12
|
+
* The temp name carries the writer's pid plus a per-process counter, because the
|
|
13
|
+
* same target can have several writers at once (the server and a CLI invocation,
|
|
14
|
+
* or two {@link FindingsStore} instances on one session dir). A shared `.tmp`
|
|
15
|
+
* suffix would let one writer rename another's half-written bytes into place.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Replace `path` with `contents` atomically (temp file + rename).
|
|
19
|
+
*
|
|
20
|
+
* The parent directory must already exist — callers own that (they create more
|
|
21
|
+
* than just this file's dir). A failed write leaves no temp file behind and
|
|
22
|
+
* rethrows: the original file is untouched, so the failure is never silent.
|
|
23
|
+
*/
|
|
24
|
+
export declare function writeFileAtomic(path: string, contents: string): Promise<void>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atomic file replace — how every cross-process file in the workspace is written.
|
|
3
|
+
*
|
|
4
|
+
* `state.json` and `findings.json` are read by processes other than the writer:
|
|
5
|
+
* `ui-debugger-mcp status` / `stop` run out-of-band, and a second server checks
|
|
6
|
+
* the breadcrumb through {@link FileStatePort.foreignRun}. A plain `writeFile`
|
|
7
|
+
* truncates first, so a reader that lands mid-write sees an empty or half-written
|
|
8
|
+
* file — and both readers treat that as "no run" / "corrupt findings". Writing a
|
|
9
|
+
* temp file and `rename(2)`-ing it into place is atomic on the same filesystem:
|
|
10
|
+
* a reader sees either the old bytes or the new ones, never a torn mix.
|
|
11
|
+
*
|
|
12
|
+
* The temp name carries the writer's pid plus a per-process counter, because the
|
|
13
|
+
* same target can have several writers at once (the server and a CLI invocation,
|
|
14
|
+
* or two {@link FindingsStore} instances on one session dir). A shared `.tmp`
|
|
15
|
+
* suffix would let one writer rename another's half-written bytes into place.
|
|
16
|
+
*/
|
|
17
|
+
import { rename, rm, writeFile } from 'node:fs/promises';
|
|
18
|
+
/** Per-process counter — keeps concurrent writes inside one process distinct. */
|
|
19
|
+
let seq = 0;
|
|
20
|
+
/**
|
|
21
|
+
* Replace `path` with `contents` atomically (temp file + rename).
|
|
22
|
+
*
|
|
23
|
+
* The parent directory must already exist — callers own that (they create more
|
|
24
|
+
* than just this file's dir). A failed write leaves no temp file behind and
|
|
25
|
+
* rethrows: the original file is untouched, so the failure is never silent.
|
|
26
|
+
*/
|
|
27
|
+
export async function writeFileAtomic(path, contents) {
|
|
28
|
+
seq += 1;
|
|
29
|
+
const tmp = `${path}.tmp-${process.pid}-${seq}`;
|
|
30
|
+
try {
|
|
31
|
+
await writeFile(tmp, contents, 'utf8');
|
|
32
|
+
await rename(tmp, path);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
await rm(tmp, { force: true }).catch(() => undefined);
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=atomic-write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atomic-write.js","sourceRoot":"","sources":["../../src/session/atomic-write.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEzD,iFAAiF;AACjF,IAAI,GAAG,GAAG,CAAC,CAAC;AAEZ;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAY,EAAE,QAAgB;IAClE,GAAG,IAAI,CAAC,CAAC;IACT,MAAM,GAAG,GAAG,GAAG,IAAI,QAAQ,OAAO,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;IAChD,IAAI,CAAC;QACH,MAAM,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QACvC,MAAM,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACtD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
* Directories are created lazily (idempotent); bad findings fail loud via
|
|
13
13
|
* `FindingsError` — never a silent fallback.
|
|
14
14
|
*/
|
|
15
|
-
import { access, appendFile, mkdir, readdir, readFile,
|
|
15
|
+
import { access, appendFile, mkdir, readdir, readFile, writeFile } from 'node:fs/promises';
|
|
16
16
|
import { join } from 'node:path';
|
|
17
17
|
import { FindingsError } from '../errors.js';
|
|
18
18
|
import { FindingsSchema } from '../findings/schema.js';
|
|
19
|
+
import { writeFileAtomic } from './atomic-write.js';
|
|
19
20
|
/** Max slug length — keeps `NNN-<slug>.png` well under the 255-byte filename limit. */
|
|
20
21
|
const SLUG_MAX = 60;
|
|
21
22
|
/**
|
|
@@ -55,9 +56,7 @@ export class FindingsStore {
|
|
|
55
56
|
await this.#ensureDirs();
|
|
56
57
|
// Write-then-rename so a concurrent reader (get_findings, CLI `status`) never
|
|
57
58
|
// sees a torn/empty findings.json — rename is atomic on the same filesystem.
|
|
58
|
-
|
|
59
|
-
await writeFile(tmp, `${JSON.stringify(result.data, null, 2)}\n`, 'utf8');
|
|
60
|
-
await rename(tmp, this.#paths.findingsJson);
|
|
59
|
+
await writeFileAtomic(this.#paths.findingsJson, `${JSON.stringify(result.data, null, 2)}\n`);
|
|
61
60
|
return this.#paths.findingsJson;
|
|
62
61
|
}
|
|
63
62
|
/** Read + validate `findings.json`. Throws `FindingsError` if missing/corrupt. */
|
|
@@ -1 +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,
|
|
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,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAgBpD,uFAAuF;AACvF,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB;;;;GAIG;AACH,SAAS,IAAI,CAAC,KAAa;IACzB,MAAM,CAAC,GAAG,KAAK;SACZ,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,UAA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zB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC/C,IAAI,CAAC,cAAc,GAAG,GAAG,CAAC;YAC5B,CAAC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,IAAI,CAAC,SAAS,CAAC;QACrB,IAAI,CAAC,cAAc,IAAI,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,6EAA6E;IAC7E,KAAK,CAAC,WAAW;QACf,IAAI,OAAiB,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QACnD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,CAAC;QACX,CAAC;QACD,IAAI,GAAG,GAAG,CAAC,CAAC;QACZ,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACvC,IAAI,GAAG,KAAK,SAAS;gBAAE,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
|
@@ -43,3 +43,19 @@ export declare function parseStartTicks(stat: string): number | null;
|
|
|
43
43
|
export declare function captureIdentity(pid?: number): ProcessIdentity;
|
|
44
44
|
/** Match a recorded identity against whatever process currently owns `pid`. */
|
|
45
45
|
export declare function verifyIdentity(pid: number, recorded: ProcessIdentity): IdentityCheck;
|
|
46
|
+
/** Whether `pid` is a live process this user can see (`kill(pid, 0)`). */
|
|
47
|
+
export declare function isPidAlive(pid: number): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Is the process a breadcrumb records *genuinely* still our server — not an
|
|
50
|
+
* unrelated process that inherited a recycled PID?
|
|
51
|
+
*
|
|
52
|
+
* A verified `match` is alive; a `stale` (recycled) or `gone` PID is dead. When
|
|
53
|
+
* the identity can't be verified (non-Linux, or none recorded), fall back to a
|
|
54
|
+
* bare liveness probe — best effort, same as before this guard existed. The
|
|
55
|
+
* `check` comes back too so callers can say *why* (a recycled PID reads very
|
|
56
|
+
* differently from a clean exit).
|
|
57
|
+
*/
|
|
58
|
+
export declare function ownerAlive(pid: number, recorded: ProcessIdentity): {
|
|
59
|
+
check: IdentityCheck;
|
|
60
|
+
alive: boolean;
|
|
61
|
+
};
|