@deepseek-insight/dsi 0.8.2 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/build/client/_app/immutable/assets/0.cswkTiBk.css +2 -0
  2. package/build/client/_app/immutable/chunks/C7Sg_49n.js +1 -0
  3. package/build/client/_app/immutable/chunks/{CAoCg_fG.js → CnzmIbjr.js} +1 -1
  4. package/build/client/_app/immutable/chunks/DY0MQ1mO.js +1 -0
  5. package/build/client/_app/immutable/chunks/GKkjunMm.js +2 -0
  6. package/build/client/_app/immutable/entry/{app.DIq2Q3OX.js → app.DYNedUxy.js} +2 -2
  7. package/build/client/_app/immutable/entry/start.BzyrBssE.js +1 -0
  8. package/build/client/_app/immutable/nodes/{1.DKIIO5Pq.js → 1.CHB5qqQ9.js} +1 -1
  9. package/build/client/_app/immutable/nodes/{2.CpOJSq6u.js → 2.C6No1310.js} +222 -222
  10. package/build/client/_app/version.json +1 -1
  11. package/build/handler.js +4 -4
  12. package/build/index.js +4 -4
  13. package/build/server/chunks/chunks/{dsh-events.js-CGuF_had.js → dsh-events.js-BUkLR6ZV.js} +13 -1
  14. package/build/server/chunks/chunks/{git-probe.js-Cn_ugqcH.js → git-probe.js-CLF37SRh.js} +2 -2
  15. package/build/server/chunks/chunks/{internal2.js-DFG0wDsP.js → internal2.js-J3h-US64.js} +2 -2
  16. package/build/server/chunks/chunks/registry.js-CZNJZ0C-.js +1003 -0
  17. package/build/server/chunks/chunks/{state.js-Dki_Bq11.js → state.js-8RBD56dL.js} +2 -2
  18. package/build/server/chunks/chunks/{watcher.js-f54CFvdI.js → watcher.js-BVKnoQUw.js} +2 -2
  19. package/build/server/chunks/entries/endpoints/api/a2a/{_server.ts.js-DN0zl7cz.js → _server.ts.js-3kQCQuHT.js} +3 -3
  20. package/build/server/chunks/entries/endpoints/api/a2a/register/{_server.ts.js-C3byr74D.js → _server.ts.js-BUBTCLFn.js} +3 -3
  21. package/build/server/chunks/entries/endpoints/api/browser/_id_/activate/_server.ts.js-BdMJzENm.js +45 -0
  22. package/build/server/chunks/entries/endpoints/api/browser/_id_/close/{_server.ts.js-BKChU9D7.js → _server.ts.js-B5z9-N8Y.js} +2 -2
  23. package/build/server/chunks/entries/endpoints/api/browser/_id_/closetab/_server.ts.js-CnZHun5r.js +44 -0
  24. package/build/server/chunks/entries/endpoints/api/browser/_id_/element/_server.ts.js-C1oM2Ihf.js +43 -0
  25. package/build/server/chunks/entries/endpoints/api/browser/_id_/input/{_server.ts.js-CUFYX5kg.js → _server.ts.js-DmbqGRMg.js} +5 -4
  26. package/build/server/chunks/entries/endpoints/api/browser/_id_/mcp/{_server.ts.js-fg2eb_ZY.js → _server.ts.js-Cj80T1yH.js} +2 -2
  27. package/build/server/chunks/entries/endpoints/api/browser/_id_/navigate/{_server.ts.js-Dt1n31IP.js → _server.ts.js-6gi1UYTJ.js} +11 -7
  28. package/build/server/chunks/entries/endpoints/api/browser/_id_/opentab/_server.ts.js-Bhx_J7ot.js +47 -0
  29. package/build/server/chunks/entries/endpoints/api/browser/_id_/page/{_server.ts.js-DIF8juwJ.js → _server.ts.js-DvQXNnX9.js} +4 -3
  30. package/build/server/chunks/entries/endpoints/api/browser/_id_/stream/{_server.ts.js-BFdXJdhd.js → _server.ts.js-MflkVWUn.js} +2 -2
  31. package/build/server/chunks/entries/endpoints/api/browser/_id_/tabs/_server.ts.js-CoUSlLcP.js +34 -0
  32. package/build/server/chunks/entries/endpoints/api/browser/_id_/viewport/{_server.ts.js-BIF_7OHe.js → _server.ts.js-DNk4EgjJ.js} +6 -4
  33. package/build/server/chunks/entries/endpoints/api/browser/{_server.ts.js-B7yjEF1N.js → _server.ts.js-CECKap7O.js} +14 -4
  34. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/events/{_server.ts.js-lBsxHSo6.js → _server.ts.js-BzP30TXW.js} +2 -2
  35. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/history/{_server.ts.js-BrEgFdCF.js → _server.ts.js-B7YRQhuJ.js} +2 -2
  36. package/build/server/chunks/entries/endpoints/api/workspace/file-write/{_server.ts.js-BRhlbYEe.js → _server.ts.js-B-5YihUA.js} +3 -3
  37. package/build/server/chunks/entries/endpoints/api/workspace/git-events/{_server.ts.js-B9YI66ZL.js → _server.ts.js-DT5jRZFE.js} +3 -3
  38. package/build/server/chunks/entries/endpoints/api/workspace/git-file-head/{_server.ts.js-DSvXRZQL.js → _server.ts.js-DtW-utrd.js} +3 -3
  39. package/build/server/chunks/entries/endpoints/api/workspace/git-map/{_server.ts.js-8A0skdlM.js → _server.ts.js-8AIAo9jX.js} +3 -3
  40. package/build/server/chunks/entries/endpoints/api/workspace/git-status/{_server.ts.js-Bc6J3t3m.js → _server.ts.js-CMw96vjY.js} +3 -3
  41. package/build/server/chunks/entries/endpoints/api/workspace/write-gate/{_server.ts.js-CfL8Por5.js → _server.ts.js-DKufa14_.js} +3 -3
  42. package/build/server/chunks/entries/pages/{_error.svelte.js-EnDLC3Jj.js → _error.svelte.js-DRPduJdP.js} +3 -3
  43. package/build/server/chunks/entries/pages/{_page.server.ts.js-ar1DbW1v.js → _page.server.ts.js-7x6ZfGoB.js} +2 -2
  44. package/build/server/chunks/entries/pages/{_page.svelte.js-CQUo8VGL.js → _page.svelte.js-Dek8Q1_v.js} +430 -101
  45. package/build/server/chunks/{handler-BBp0LoYK.js → handler-DUyvzXsb.js} +3 -3
  46. package/build/server/chunks/{index.js-S4257Wcs.js → index.js-BrP1SRzN.js} +2 -2
  47. package/build/server/chunks/{manifest.js-DajiWH1H.js → manifest.js-C4z6aoYx.js} +58 -23
  48. package/build/server/chunks/nodes/{0.js-DtkNHIFx.js → 0.js-BuB3t8Br.js} +3 -3
  49. package/build/server/chunks/nodes/1.js-CW4V8ni8.js +9 -0
  50. package/build/server/chunks/nodes/{2.js-BORDEffk.js → 2.js-C-o9KF10.js} +5 -5
  51. package/package.json +2 -7
  52. package/template/.dsi/prompts.sqlite-shm +0 -0
  53. package/template/.dsi/prompts.sqlite-wal +0 -0
  54. package/template/.dsi/settings.yaml +2 -2
  55. package/build/client/_app/immutable/assets/0.DBVVEjy9.css +0 -2
  56. package/build/client/_app/immutable/chunks/BHodvdRc.js +0 -1
  57. package/build/client/_app/immutable/chunks/D-jXFTzB.js +0 -1
  58. package/build/client/_app/immutable/chunks/TTdBFs3C.js +0 -2
  59. package/build/client/_app/immutable/entry/start.E6P3Z7tx.js +0 -1
  60. package/build/server/chunks/chunks/registry.js-BC-TNdmn.js +0 -616
  61. package/build/server/chunks/nodes/1.js-OAvYMTzU.js +0 -9
  62. /package/build/client/_app/immutable/nodes/{0.Dm_ry-Pr.js → 0.DQYP6BCS.js} +0 -0
@@ -1,616 +0,0 @@
1
- import { d as readBrowserConfig } from './insight-config.js-Dp_2gB5J.js';
2
- import { mkdirSync, rmSync, readdirSync } from 'node:fs';
3
- import { join } from 'node:path';
4
- import { spawn, spawnSync } from 'node:child_process';
5
- import { randomUUID } from 'node:crypto';
6
- import { chromium } from 'playwright-core';
7
-
8
- //#region src/lib/server/browser/relay.ts
9
- var RelayClosedError = class extends Error {
10
- constructor() {
11
- super("relay is closed");
12
- this.name = "RelayClosedError";
13
- }
14
- };
15
- var BrowserRelay = class {
16
- quality;
17
- maxFps;
18
- cdp;
19
- subscribers = /* @__PURE__ */ new Set();
20
- seq = 0;
21
- latest = null;
22
- chain = Promise.resolve();
23
- started = false;
24
- /** JPEG quality 0..100 — from BrowserConfig.screencastQuality
25
- * (default 90; yaml `browser.screencast:` override, amendment 3).
26
- * maxFps — ADR-0039 D1: target fps intent; start() derives CDP's
27
- * everyNthFrame from a nominal 30 Hz paint clock (clamp ≥1). */
28
- constructor(cdp, quality = 90, maxFps = 15) {
29
- this.quality = quality;
30
- this.maxFps = maxFps;
31
- this.cdp = cdp;
32
- }
33
- async start() {
34
- if (!this.cdp || this.started) throw new RelayClosedError();
35
- this.cdp.on("Page.screencastFrame", (ev) => {
36
- this.seq += 1;
37
- this.latest = {
38
- seq: this.seq,
39
- jpeg: ev.data,
40
- metadata: ev.metadata
41
- };
42
- for (const sub of this.subscribers) sub(this.latest);
43
- this.cdp?.send("Page.screencastFrameAck", { sessionId: ev.sessionId }).catch(() => void 0);
44
- });
45
- await this.cdp.send("Page.startScreencast", {
46
- format: "jpeg",
47
- quality: this.quality,
48
- everyNthFrame: Math.max(1, Math.round(30 / this.maxFps))
49
- });
50
- this.started = true;
51
- }
52
- /** Deterministic first-frame seed (RCA 2026-10-23 The First Frame That
53
- * Never Knocked): a starved screencast birth leaves the ring empty
54
- * FOREVER — screencast only speaks on paint damage. The opener synthesizes
55
- * the first frame via Page.captureScreenshot and seeds the ring here so
56
- * attachers get a frame immediately. Does not advance past a real frame. */
57
- seed(frame) {
58
- if (!this.cdp) throw new RelayClosedError();
59
- if (this.latest) return;
60
- this.seq += 1;
61
- this.latest = {
62
- ...frame,
63
- seq: this.seq
64
- };
65
- for (const sub of this.subscribers) sub(this.latest);
66
- }
67
- latestFrame() {
68
- if (!this.cdp) throw new RelayClosedError();
69
- return this.latest;
70
- }
71
- subscribe(fn) {
72
- if (!this.cdp) throw new RelayClosedError();
73
- this.subscribers.add(fn);
74
- return () => this.subscribers.delete(fn);
75
- }
76
- /** Serialized dispatch — every input waits for the previous one. */
77
- dispatch(input) {
78
- if (!this.cdp) return Promise.reject(new RelayClosedError());
79
- const run = async () => {
80
- if (!this.cdp) throw new RelayClosedError();
81
- if (input.kind === "mouse") await this.cdp.send("Input.dispatchMouseEvent", {
82
- type: input.type,
83
- x: input.x,
84
- y: input.y,
85
- button: input.button ?? "none",
86
- clickCount: input.clickCount,
87
- deltaX: input.deltaX,
88
- deltaY: input.deltaY,
89
- pointerType: "mouse"
90
- });
91
- else if (input.kind === "key") await this.cdp.send("Input.dispatchKeyEvent", {
92
- type: input.type,
93
- key: input.key,
94
- code: input.code,
95
- windowsVirtualKeyCode: input.windowsVirtualKeyCode,
96
- text: input.text
97
- });
98
- else await this.cdp.send("Input.insertText", { text: input.text });
99
- };
100
- const next = this.chain.then(run, run);
101
- this.chain = next.catch(() => void 0);
102
- return next;
103
- }
104
- stop() {
105
- const cdp = this.cdp;
106
- this.cdp = null;
107
- this.subscribers.clear();
108
- this.latest = null;
109
- if (cdp && this.started) cdp.send("Page.stopScreencast").catch(() => void 0);
110
- }
111
- };
112
- Number(process.env.DSI_MCP_PORT ?? 9515);
113
- /** The reaper's ONLY test — pure: a session is reaper-eligible when nobody
114
- * watches its stream AND its last MCP tool traffic is older than idleMs.
115
- * An active agent (traffic younger than idleMs) is NEVER eligible (D2). */
116
- function reaperEligible(e, idleMs, now) {
117
- if (e.streamSubscribers > 0) return false;
118
- return now - e.lastMcpActivity >= idleMs;
119
- }
120
- var BrowserRegistryRefusal = class extends Error {
121
- code;
122
- constructor(code, message) {
123
- super(message);
124
- this.name = "BrowserRegistryRefusal";
125
- this.code = code;
126
- }
127
- };
128
- function state() {
129
- const p = process;
130
- if (!p.__DSI_BROWSER_STATE__) {
131
- p.__DSI_BROWSER_STATE__ = {
132
- entries: /* @__PURE__ */ new Map(),
133
- closed: /* @__PURE__ */ new Set()
134
- };
135
- sweepOrphanProfiles(new Set([...p.__DSI_BROWSER_STATE__.entries.keys()].map((id) => id.slice(0, 8))));
136
- }
137
- return p.__DSI_BROWSER_STATE__;
138
- }
139
- /** Boot-time sweep of profile dirs left by sessions that died without a
140
- * close (crash, kill -9, reaper miss). keep = prefixes of LIVE entries —
141
- * a module hot reload re-runs state() init against a process-global map
142
- * that may hold live sessions, and this sweep must never delete one. */
143
- function sweepOrphanProfiles(keep) {
144
- try {
145
- const root = readBrowserConfig().profileRoot;
146
- for (const name of readdirSync(root)) if (!keep.has(name)) rmSync(join(root, name), {
147
- recursive: true,
148
- force: true
149
- });
150
- } catch {}
151
- }
152
- /** The in-process brain (D7): createConnection attached to the SAME headed
153
- * browser via cdpEndpoint, served over a SIBLING http listener (SSE +
154
- * messages endpoints) so a streamable-http MCP client (the DSH agent) can
155
- * reach it without a child process. Port = session port + 100 (9501...):
156
- * unique per session, out of the debug-port range. */
157
- async function startInProcessMcp(browserPort, brainPort, onTraffic) {
158
- const [{ createConnection }, { StreamableHTTPServerTransport }, http] = await Promise.all([
159
- import('@playwright/mcp'),
160
- import('@modelcontextprotocol/sdk/server/streamableHttp.js'),
161
- import('node:http')
162
- ]);
163
- const connection = await createConnection({ browser: { cdpEndpoint: "http://127.0.0.1:" + browserPort } });
164
- const transport = new StreamableHTTPServerTransport({
165
- sessionIdGenerator: void 0,
166
- enableJsonResponse: true
167
- });
168
- await connection.connect(transport);
169
- const server = http.createServer(async (req, res) => {
170
- if (new URL(req.url ?? "/", "http://127.0.0.1").pathname !== "/sse") {
171
- res.statusCode = 404;
172
- res.end();
173
- return;
174
- }
175
- onTraffic?.();
176
- try {
177
- await transport.handleRequest(req, res);
178
- } catch {
179
- if (!res.writableEnded) res.end();
180
- }
181
- });
182
- let port;
183
- try {
184
- port = await listen(server, brainPort);
185
- } catch {
186
- let lastErr = null;
187
- port = 0;
188
- for (let p = brainPort + 1; p <= brainPort + 60; p++) try {
189
- port = await listen(server, p);
190
- break;
191
- } catch (e) {
192
- lastErr = e;
193
- }
194
- if (port === 0) throw lastErr ?? /* @__PURE__ */ new Error("no free brain port in " + brainPort + "+ range");
195
- }
196
- return {
197
- connection,
198
- httpServer: server,
199
- port
200
- };
201
- }
202
- var listen = (server, port) => new Promise((res, rej) => {
203
- const onError = () => {
204
- server.off("listening", onListen);
205
- rej(/* @__PURE__ */ new Error("EADDRINUSE " + port));
206
- };
207
- const onListen = () => {
208
- server.off("error", onError);
209
- const a = server.address();
210
- res(typeof a === "object" && a ? a.port : port);
211
- };
212
- server.once("error", onError);
213
- server.once("listening", onListen);
214
- server.listen(port, "127.0.0.1");
215
- });
216
- function pidOfPort(port) {
217
- const p = spawnSync("lsof", [
218
- "-ti",
219
- "tcp:" + port,
220
- "-sTCP:LISTEN"
221
- ], { stdio: "pipe" });
222
- return p.status === 0 ? Number(p.stdout.toString().trim().split("\n")[0]) : null;
223
- }
224
- function portFree(port) {
225
- return spawnSync("lsof", [
226
- "-ti",
227
- "tcp:" + port,
228
- "-sTCP:LISTEN"
229
- ], { stdio: "pipe" }).status !== 0;
230
- }
231
- function freePort(preferred) {
232
- if (preferred && portFree(preferred)) return preferred;
233
- for (let p = 9400; p < 9500; p++) if (portFree(p)) return p;
234
- throw new Error("no free debug port in 9400..9499");
235
- }
236
- var BrowserRegistry = class {
237
- list() {
238
- return [...state().entries.values()].map((e) => ({
239
- id: e.id,
240
- port: e.port,
241
- pid: e.pid,
242
- profileDir: e.profileDir,
243
- createdAt: e.createdAt,
244
- mcp: e.mcpChild ? "child" : e.mcpInProcess ? "in-process" : "none",
245
- mcpHealth: e.mcpHealth,
246
- mcpError: e.mcpError
247
- }));
248
- }
249
- peek(id) {
250
- const e = state().entries.get(id);
251
- if (!e) throw new BrowserRegistryRefusal("NO_SESSION", "no such browser session");
252
- return e;
253
- }
254
- /** The brain's live SSE URL — the ACTUAL bound port (stable 9515 in the
255
- * common case, session-relative in the rare fallback). */
256
- mcpBrainUrl(id) {
257
- const e = this.peek(id);
258
- return "http://127.0.0.1:" + (e.mcpInProcess?.port ?? e.brainPort) + "/sse";
259
- }
260
- /** True when the id was closed (tombstoned) — routes use it to answer
261
- * 409 CLOSED instead of a misleading 404. */
262
- isClosed(id) {
263
- return state().closed.has(id);
264
- }
265
- /** Re-bind lookup (ADR-0030 D1): does this persisted id still own a live
266
- * session? Pure read — never creates, never throws. */
267
- findLive(id) {
268
- if (!id) return false;
269
- return state().entries.has(id) && !state().closed.has(id);
270
- }
271
- /** Reaper inputs — the routes call these so the registry never imports a
272
- * route (the wiring-point rule stays one-directional). */
273
- noteStreamOpen(id) {
274
- const e = state().entries.get(id);
275
- if (e) e.streamSubscribers += 1;
276
- }
277
- noteStreamClose(id) {
278
- const e = state().entries.get(id);
279
- if (e) e.streamSubscribers = Math.max(0, e.streamSubscribers - 1);
280
- }
281
- noteMcpTraffic(id) {
282
- const e = state().entries.get(id);
283
- if (e) e.lastMcpActivity = Date.now();
284
- }
285
- /** The idle reaper (ADR-0030 D2): a SAFETY NET, never the owner. A
286
- * session with zero stream subscribers and no MCP tool traffic for
287
- * `browser.idleMs` is closed through the SAME idempotent close(id) the
288
- * panel-close click uses. Headless-default makes this a correctness
289
- * requirement: an invisible browser must not outlive its last driver. */
290
- ensureReaper(idleMs) {
291
- const s = state();
292
- if (s.reaperTimer) return;
293
- s.reaperTimer = setInterval(() => {
294
- const now = Date.now();
295
- for (const e of state().entries.values()) {
296
- if (!reaperEligible(e, idleMs, now)) continue;
297
- this.close(e.id).catch(() => void 0);
298
- }
299
- }, Math.min(idleMs / 2, 3e4));
300
- s.reaperTimer.unref?.();
301
- }
302
- relay(id) {
303
- return this.peek(id).relay;
304
- }
305
- async open(options = {}) {
306
- const cfg = readBrowserConfig();
307
- const id = randomUUID();
308
- const port = freePort(options.port);
309
- const profileDir = join(cfg.profileRoot, id.slice(0, 8));
310
- mkdirSync(profileDir, { recursive: true });
311
- const ignoreDefaultArgs = ["--enable-automation", "--mute-audio"];
312
- const launch = (useChrome) => chromium.launchPersistentContext(profileDir, {
313
- ...useChrome ? { channel: "chrome" } : {},
314
- headless: options.headless ?? cfg.headless,
315
- ignoreDefaultArgs,
316
- args: [
317
- "--remote-debugging-port=" + port,
318
- "--no-first-run",
319
- "--disable-blink-features=AutomationControlled",
320
- "--disable-features=IsolateOrigins,site-per-process",
321
- "--disable-dev-shm-usage",
322
- "--disable-backgrounding-occluded-windows",
323
- "--disable-renderer-backgrounding",
324
- "--disable-background-timer-throttling",
325
- "--autoplay-policy=no-user-gesture-required",
326
- "--window-position=-32000,-32000"
327
- ],
328
- viewport: {
329
- width: 1920,
330
- height: 1080
331
- },
332
- userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
333
- timezoneId: "America/New_York",
334
- locale: "en-US"
335
- });
336
- let context;
337
- try {
338
- context = await launch(true);
339
- } catch (chromeErr) {
340
- context = await launch(false);
341
- }
342
- context.browser();
343
- const pid = pidOfPort(port);
344
- const cdp = await context.newCDPSession(context.pages()[0] ?? await context.newPage());
345
- const relay = new BrowserRelay(cdp, cfg.screencastQuality, cfg.screencastMaxFps);
346
- await relay.start();
347
- const start = options.url ?? "data:text/html,<title>Glass Browser</title><body style=\"font-family:system-ui;color:gray;display:grid;place-items:center;height:100vh;margin:0\">Glass Browser — waiting for the agent</body>";
348
- await cdp.send("Page.enable").catch(() => void 0);
349
- await cdp.send("Page.navigate", { url: start }).catch(() => void 0);
350
- await new Promise((r) => setTimeout(r, 600));
351
- if (relay.latestFrame() === null) for (let i = 0; i < 10 && relay.latestFrame() === null; i += 1) await new Promise((r) => setTimeout(r, 100));
352
- if (relay.latestFrame() === null) {
353
- const shot = await cdp.send("Page.captureScreenshot", {
354
- format: "jpeg",
355
- quality: cfg.screencastQuality
356
- }).catch(() => null);
357
- if (shot) relay.seed({
358
- seq: 0,
359
- jpeg: shot.data,
360
- metadata: { seeded: true }
361
- });
362
- }
363
- const brainPort = Number(process.env.DSI_MCP_PORT ?? cfg.brainPort);
364
- if (cfg.enabled) this.ensureReaper(cfg.idleMs);
365
- const entry = {
366
- id,
367
- context,
368
- cdp,
369
- relay,
370
- port,
371
- pid,
372
- profileDir,
373
- brainPort,
374
- streamSubscribers: 0,
375
- lastMcpActivity: Date.now(),
376
- mcpChild: null,
377
- mcpInProcess: null,
378
- mcpHealth: "up",
379
- mcpError: null,
380
- closed: false,
381
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
382
- };
383
- state().entries.set(id, entry);
384
- if (options.spawnMcp ?? true) {
385
- if (process.env.DSI_MCP_IN_PROCESS === "1") try {
386
- entry.mcpInProcess = await startInProcessMcp(entry.port, brainPort, () => {
387
- entry.lastMcpActivity = Date.now();
388
- });
389
- } catch (e) {
390
- entry.mcpHealth = "down";
391
- entry.mcpError = e.message;
392
- }
393
- else this.spawnMcpChild(entry, cfg.mcpPin);
394
- }
395
- return {
396
- id,
397
- port,
398
- pid,
399
- profileDir,
400
- createdAt: entry.createdAt,
401
- mcp: entry.mcpChild ? "child" : entry.mcpInProcess ? "in-process" : "none",
402
- mcpHealth: entry.mcpHealth,
403
- mcpError: entry.mcpError
404
- };
405
- }
406
- /** Wave 3 (3.1) owns the real arg matrix; Wave 1 wires the spawn so close
407
- * ordering (mcp child → cdp → browser) is pinned from day one. */
408
- spawnMcpChild(entry, mcpPin) {
409
- const child = spawn("npx", [
410
- "@playwright/mcp@" + mcpPin,
411
- "--cdp-endpoint",
412
- "http://127.0.0.1:" + entry.port
413
- ], {
414
- stdio: "ignore",
415
- detached: false
416
- });
417
- entry.mcpChild = child;
418
- child.on("error", (e) => {
419
- entry.mcpHealth = "down";
420
- entry.mcpError = String(e);
421
- });
422
- child.on("exit", (code) => {
423
- if (entry.mcpChild === child) {
424
- entry.mcpHealth = "down";
425
- entry.mcpError = "mcp child exited code " + code;
426
- }
427
- });
428
- }
429
- /** D8 owner-release. Idempotent: closing a closed id resolves cleanly. */
430
- async close(id) {
431
- const entry = state().entries.get(id);
432
- if (!entry) return {
433
- ok: true,
434
- alreadyClosed: true
435
- };
436
- if (entry.closed) {
437
- state().entries.delete(id);
438
- return {
439
- ok: true,
440
- alreadyClosed: true
441
- };
442
- }
443
- entry.closed = true;
444
- state().closed.add(id);
445
- if (state().closed.size > 256) state().closed.delete(state().closed.values().next().value);
446
- const errs = [];
447
- if (entry.mcpInProcess) try {
448
- const brain = entry.mcpInProcess;
449
- await new Promise((res) => {
450
- brain.httpServer?.closeAllConnections?.();
451
- brain.httpServer?.close?.(() => res());
452
- setTimeout(res, 2e3);
453
- });
454
- await brain.connection?.close?.();
455
- entry.mcpInProcess = null;
456
- } catch (e) {
457
- errs.push(e);
458
- }
459
- if (entry.mcpChild?.pid) try {
460
- entry.mcpChild.kill("SIGTERM");
461
- } catch (e) {
462
- errs.push(e);
463
- }
464
- try {
465
- entry.relay.stop();
466
- } catch (e) {
467
- errs.push(e);
468
- }
469
- try {
470
- await entry.context.close();
471
- } catch (e) {
472
- errs.push(e);
473
- }
474
- try {
475
- rmSync(entry.profileDir, {
476
- recursive: true,
477
- force: true
478
- });
479
- } catch (e) {
480
- errs.push(e);
481
- }
482
- state().entries.delete(id);
483
- return {
484
- ok: errs.length === 0,
485
- alreadyClosed: false
486
- };
487
- }
488
- /** Wait for the page's next load event, capped — the navigate idiom
489
- * (a send races the context teardown otherwise) shared by reload and
490
- * history travel (ADR-0031 D3/D4). */
491
- async waitLoad(e, capMs = 3e3) {
492
- await new Promise((res) => {
493
- const on = (p) => {
494
- e.cdp.off("Page.loadEventFired", on);
495
- res();
496
- };
497
- e.cdp.on("Page.loadEventFired", on);
498
- setTimeout(res, capMs);
499
- });
500
- }
501
- /** Navigate the session's active page — public because causing page
502
- * damage is the only reliable way to make screencast emit a frame. */
503
- async navigate(id, url, opts) {
504
- const e = this.peek(id);
505
- await e.cdp.send("Page.enable").catch(() => void 0);
506
- if (opts?.waitLoad) {
507
- const loaded = this.waitLoad(e);
508
- await e.cdp.send("Page.navigate", { url });
509
- await loaded;
510
- return;
511
- }
512
- await e.cdp.send("Page.navigate", { url });
513
- }
514
- /** Match the page viewport to the panel's glass box (ADR-0031
515
- * amendment 2): the screencast frame then equals the panel size, so
516
- * the mirror shows content at native scale instead of zooming a
517
- * fixed default viewport. CDP-side clamps keep hostile sizes out. */
518
- async setViewport(id, width, height) {
519
- const w = Math.max(200, Math.min(8192, Math.round(width)));
520
- const h = Math.max(120, Math.min(8192, Math.round(height)));
521
- const e = this.peek(id);
522
- await e.cdp.send("Page.enable").catch(() => void 0);
523
- await e.cdp.send("Emulation.setDeviceMetricsOverride", {
524
- width: w,
525
- height: h,
526
- deviceScaleFactor: 0,
527
- mobile: false
528
- });
529
- }
530
- /** The history position (ADR-0031): every proxy-verb answer carries it
531
- * so the header's back/forward buttons stay honest at the ends. */
532
- async navInfo(id) {
533
- const e = this.peek(id);
534
- await e.cdp.send("Page.enable").catch(() => void 0);
535
- const hist = await e.cdp.send("Page.getNavigationHistory", {});
536
- return {
537
- currentIndex: hist.currentIndex,
538
- entryCount: hist.entries.length
539
- };
540
- }
541
- /** Reload the session's active page (ADR-0031 D4): Page.reload keeps
542
- * the history entry, unlike re-navigating the current URL. */
543
- async reload(id) {
544
- const e = this.peek(id);
545
- await e.cdp.send("Page.enable").catch(() => void 0);
546
- const loaded = this.waitLoad(e);
547
- await e.cdp.send("Page.reload", {});
548
- await loaded;
549
- return this.pageInfo(id);
550
- }
551
- /** Travel the browser's OWN back/forward list (ADR-0031 D3):
552
- * Page.getNavigationHistory picks the entry, Page.navigateToHistoryEntry
553
- * is the browser's travel verb — never Runtime.evaluate('history.back()'),
554
- * which races the teardown and lies about the browser-level list.
555
- * Bounds refusals keep the header buttons honest at the list ends. */
556
- async pageHistory(id, dir) {
557
- const e = this.peek(id);
558
- await e.cdp.send("Page.enable").catch(() => void 0);
559
- const hist = await e.cdp.send("Page.getNavigationHistory", {});
560
- const target = dir === "back" ? hist.currentIndex - 1 : hist.currentIndex + 1;
561
- if (target < 0 || target >= hist.entries.length) throw new BrowserRegistryRefusal("CLOSED", "HISTORY_END — cannot go " + dir + " from index " + hist.currentIndex + " of " + hist.entries.length);
562
- const loaded = this.waitLoad(e);
563
- await e.cdp.send("Page.navigateToHistoryEntry", { entryId: hist.entries[target].id });
564
- await loaded;
565
- return {
566
- ...await this.pageInfo(id),
567
- currentIndex: target,
568
- entryCount: hist.entries.length
569
- };
570
- }
571
- /** Race an evaluate against a cap — a hung evaluate must never wedge a
572
- * route (the navigate-hang finding, spec W2 2.3 debugging). */
573
- async evaluateCapped(cdp, expr, capMs = 3e3) {
574
- let timer;
575
- const cap = new Promise((res) => {
576
- timer = setTimeout(() => res(null), capMs);
577
- });
578
- try {
579
- const res = await Promise.race([cdp.send("Runtime.evaluate", {
580
- expression: expr,
581
- returnByValue: true
582
- }), cap]);
583
- return res ? String(res.result?.value ?? "") : null;
584
- } finally {
585
- if (timer) clearTimeout(timer);
586
- }
587
- }
588
- /** The active page's url + title + inner viewport — the status strip's
589
- * location read, the e2e's DOM-truth channel (the glass proves clicks
590
- * by effects the page itself reports), and the viewport-follow witness
591
- * (innerWidth/innerHeight prove the emulation landed, amend 2). */
592
- async pageInfo(id) {
593
- const e = this.peek(id);
594
- const raw = await this.evaluateCapped(e.cdp, "JSON.stringify({ url: location.href, title: document.title, dpr: window.devicePixelRatio, innerWidth: window.innerWidth, innerHeight: window.innerHeight, playerError: (document.querySelector(\".ytp-error-content-wrap-reason, .ytp-error-content, [role=alert]\")?.textContent || \"\").trim() || null, mediaErrorCode: (document.querySelector(\"video\")?.error?.code) ?? null })", 3e3);
595
- if (raw === null) return {
596
- url: "(busy)",
597
- title: "(busy)",
598
- dpr: 1,
599
- innerWidth: 0,
600
- innerHeight: 0,
601
- playerError: null,
602
- mediaErrorCode: null
603
- };
604
- return JSON.parse(raw);
605
- }
606
- dispatch(id, input) {
607
- if (!state().entries.has(id) && state().closed.has(id)) throw new BrowserRegistryRefusal("CLOSED", "session was closed");
608
- const e = this.peek(id);
609
- if (e.closed) throw new BrowserRegistryRefusal("CLOSED", "session is closing");
610
- return e.relay.dispatch(input);
611
- }
612
- };
613
- var browserRegistry = new BrowserRegistry();
614
-
615
- export { BrowserRegistryRefusal as B, browserRegistry as b };
616
- //# sourceMappingURL=registry.js-BC-TNdmn.js.map
@@ -1,9 +0,0 @@
1
- const index = 1;
2
- let component_cache;
3
- const component = async () => component_cache ??= (await import('../entries/pages/_error.svelte.js-EnDLC3Jj.js')).default;
4
- const imports = ["_app/immutable/nodes/1.DKIIO5Pq.js","_app/immutable/chunks/cHj8EuyS.js","_app/immutable/chunks/xihTtKlq.js","_app/immutable/chunks/CAoCg_fG.js","_app/immutable/chunks/TTdBFs3C.js","_app/immutable/chunks/D-Rolhzs.js"];
5
- const stylesheets = [];
6
- const fonts = [];
7
-
8
- export { component, fonts, imports, index, stylesheets };
9
- //# sourceMappingURL=1.js-OAvYMTzU.js.map