@deepseek-insight/dsi 0.8.2 → 0.8.3

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 (60) hide show
  1. package/build/client/_app/immutable/assets/0.DyOAkKS-.css +2 -0
  2. package/build/client/_app/immutable/chunks/{CAoCg_fG.js → BoHeiMOU.js} +1 -1
  3. package/build/client/_app/immutable/chunks/C9QAOGL1.js +2 -0
  4. package/build/client/_app/immutable/chunks/QJuSx3RG.js +1 -0
  5. package/build/client/_app/immutable/chunks/sC_8Ss7w.js +1 -0
  6. package/build/client/_app/immutable/entry/{app.DIq2Q3OX.js → app.S_mxIoOg.js} +2 -2
  7. package/build/client/_app/immutable/entry/start.BPQAB3iV.js +1 -0
  8. package/build/client/_app/immutable/nodes/{1.DKIIO5Pq.js → 1.D20V6eTe.js} +1 -1
  9. package/build/client/_app/immutable/nodes/{2.CpOJSq6u.js → 2.BHcBdFqH.js} +77 -77
  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-Ba5p8uFM.js} +2 -2
  16. package/build/server/chunks/chunks/{registry.js-BC-TNdmn.js → registry.js-C2MdrfNv.js} +388 -50
  17. package/build/server/chunks/chunks/{state.js-Dki_Bq11.js → state.js-BSiAgink.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-CogDOHKu.js +45 -0
  22. package/build/server/chunks/entries/endpoints/api/browser/_id_/close/{_server.ts.js-BKChU9D7.js → _server.ts.js-xOt7LnS1.js} +2 -2
  23. package/build/server/chunks/entries/endpoints/api/browser/_id_/closetab/_server.ts.js-CSmVPvSM.js +44 -0
  24. package/build/server/chunks/entries/endpoints/api/browser/_id_/element/_server.ts.js-BA40oCDW.js +43 -0
  25. package/build/server/chunks/entries/endpoints/api/browser/_id_/input/{_server.ts.js-CUFYX5kg.js → _server.ts.js-EX7eVzjp.js} +5 -4
  26. package/build/server/chunks/entries/endpoints/api/browser/_id_/mcp/{_server.ts.js-fg2eb_ZY.js → _server.ts.js-B_EcmyFt.js} +2 -2
  27. package/build/server/chunks/entries/endpoints/api/browser/_id_/navigate/{_server.ts.js-Dt1n31IP.js → _server.ts.js-C3dYbyS3.js} +11 -7
  28. package/build/server/chunks/entries/endpoints/api/browser/_id_/opentab/_server.ts.js-CMhJJO25.js +45 -0
  29. package/build/server/chunks/entries/endpoints/api/browser/_id_/page/{_server.ts.js-DIF8juwJ.js → _server.ts.js-DIW4uI2S.js} +4 -3
  30. package/build/server/chunks/entries/endpoints/api/browser/_id_/stream/{_server.ts.js-BFdXJdhd.js → _server.ts.js-CIPIlq5X.js} +2 -2
  31. package/build/server/chunks/entries/endpoints/api/browser/_id_/tabs/_server.ts.js-CoEdOiml.js +34 -0
  32. package/build/server/chunks/entries/endpoints/api/browser/_id_/viewport/{_server.ts.js-BIF_7OHe.js → _server.ts.js-CdELUoGT.js} +6 -4
  33. package/build/server/chunks/entries/endpoints/api/browser/{_server.ts.js-B7yjEF1N.js → _server.ts.js-ea6HpNGh.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-D8-G0evO.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-7xWLRsiZ.js} +212 -101
  45. package/build/server/chunks/{handler-BBp0LoYK.js → handler-BedQ0jP-.js} +3 -3
  46. package/build/server/chunks/{index.js-S4257Wcs.js → index.js-BF6tPPQs.js} +2 -2
  47. package/build/server/chunks/{manifest.js-DajiWH1H.js → manifest.js-3c0p7QAl.js} +58 -23
  48. package/build/server/chunks/nodes/{0.js-DtkNHIFx.js → 0.js-B3i7sGR_.js} +3 -3
  49. package/build/server/chunks/nodes/1.js-eUf50uxI.js +9 -0
  50. package/build/server/chunks/nodes/{2.js-BORDEffk.js → 2.js-CgnRGwm6.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/build/client/_app/immutable/assets/0.DBVVEjy9.css +0 -2
  55. package/build/client/_app/immutable/chunks/BHodvdRc.js +0 -1
  56. package/build/client/_app/immutable/chunks/D-jXFTzB.js +0 -1
  57. package/build/client/_app/immutable/chunks/TTdBFs3C.js +0 -2
  58. package/build/client/_app/immutable/entry/start.E6P3Z7tx.js +0 -1
  59. package/build/server/chunks/nodes/1.js-OAvYMTzU.js +0 -9
  60. /package/build/client/_app/immutable/nodes/{0.Dm_ry-Pr.js → 0.6dTmg1Xv.js} +0 -0
@@ -21,6 +21,10 @@ var BrowserRelay = class {
21
21
  latest = null;
22
22
  chain = Promise.resolve();
23
23
  started = false;
24
+ /** ADR-0040 D1: an INACTIVE tab's screencast is suspended (no Chrome-side
25
+ * encode, no wire cost) while the relay — ring, seq, subscribers — lives
26
+ * on, so re-activation resumes instead of rebuilding. */
27
+ paused = false;
24
28
  /** JPEG quality 0..100 — from BrowserConfig.screencastQuality
25
29
  * (default 90; yaml `browser.screencast:` override, amendment 3).
26
30
  * maxFps — ADR-0039 D1: target fps intent; start() derives CDP's
@@ -48,6 +52,33 @@ var BrowserRelay = class {
48
52
  everyNthFrame: Math.max(1, Math.round(30 / this.maxFps))
49
53
  });
50
54
  this.started = true;
55
+ this.paused = false;
56
+ }
57
+ /** Suspend the screencast, keep the relay (ADR-0040 D1). Idempotent. */
58
+ async pause() {
59
+ if (!this.cdp || !this.started || this.paused) return;
60
+ this.paused = true;
61
+ await this.cdp.send("Page.stopScreencast").catch(() => void 0);
62
+ }
63
+ /** Re-start the screencast after a pause (same dials). Idempotent. */
64
+ async resume() {
65
+ if (!this.cdp || !this.started || !this.paused) return;
66
+ this.paused = false;
67
+ await this.cdp.send("Page.startScreencast", {
68
+ format: "jpeg",
69
+ quality: this.quality,
70
+ everyNthFrame: Math.max(1, Math.round(30 / this.maxFps))
71
+ }).catch(() => void 0);
72
+ }
73
+ /** Activation MUST stream (ADR-0040 D4): START a never-started (lazily
74
+ * attached) relay, RESUME a paused one, no-op an already-streaming one.
75
+ * BUGFIX 2026-10-24: activate() called resume() only — a lazily attached
76
+ * tab (started=false) never began streaming and the mirror froze on its
77
+ * seeded boundary frame (the operator's hung second YouTube tab). */
78
+ async ensureStreaming() {
79
+ if (!this.cdp) throw new RelayClosedError();
80
+ if (!this.started) return this.start();
81
+ if (this.paused) return this.resume();
51
82
  }
52
83
  /** Deterministic first-frame seed (RCA 2026-10-23 The First Frame That
53
84
  * Never Knocked): a starved screencast birth leaves the ring empty
@@ -149,6 +180,31 @@ function sweepOrphanProfiles(keep) {
149
180
  });
150
181
  } catch {}
151
182
  }
183
+ /** Brain re-homing (BUGFIX 2026-10-25): release the stable brain port
184
+ * from any OTHER live session so the NEWEST glass binds it. The DSH
185
+ * preset's brain URL is static (9515) — without this, the agent keeps
186
+ * driving an older glass while the operator watches the new one. The
187
+ * evicted glass mirrors fine; its status strip honestly reports the
188
+ * brain down (ADR-0029 D7: the mirror never depends on the brain). */
189
+ function evictBrainPort(brainPort, exceptId) {
190
+ for (const e of state().entries.values()) {
191
+ if (e.id === exceptId || !e.mcpInProcess || e.mcpInProcess.port !== brainPort) continue;
192
+ const brain = e.mcpInProcess;
193
+ (async () => {
194
+ try {
195
+ await new Promise((res) => {
196
+ brain.httpServer?.closeAllConnections?.();
197
+ brain.httpServer?.close?.(() => res());
198
+ setTimeout(res, 1500);
199
+ });
200
+ await brain.connection?.close?.();
201
+ } catch {}
202
+ })();
203
+ e.mcpInProcess = null;
204
+ e.mcpHealth = "down";
205
+ e.mcpError = "brain re-homed to a newer glass";
206
+ }
207
+ }
152
208
  /** The in-process brain (D7): createConnection attached to the SAME headed
153
209
  * browser via cdpEndpoint, served over a SIBLING http listener (SSE +
154
210
  * messages endpoints) so a streamable-http MCP client (the DSH agent) can
@@ -299,8 +355,111 @@ var BrowserRegistry = class {
299
355
  }, Math.min(idleMs / 2, 3e4));
300
356
  s.reaperTimer.unref?.();
301
357
  }
358
+ /** The ACTIVE tab's relay — what the stream route binds (ADR-0040 D2). */
302
359
  relay(id) {
303
- return this.peek(id).relay;
360
+ const e = this.peek(id);
361
+ const h = e.activeTargetId ? e.tabs.get(e.activeTargetId) : null;
362
+ if (!h) throw new BrowserRegistryRefusal("CLOSED", "no active tab handle");
363
+ return h.relay;
364
+ }
365
+ /** Resolve a verb's target handle: explicit targetId, else the active tab
366
+ * (ADR-0040 D3 — one verb seam, optional pointer). An ENUMERATED but
367
+ * not-yet-attached target attaches lazily here — attach is not stream
368
+ * (D1): verbs may reach any tab the strip can list. */
369
+ async handleOf(e, targetId) {
370
+ const key = targetId ?? e.activeTargetId ?? void 0;
371
+ if (!key) throw new BrowserRegistryRefusal("NO_TARGET", "no active tab");
372
+ const have = e.tabs.get(key);
373
+ if (have) return have;
374
+ for (let attempt = 0; attempt < 5 && !e.tabs.has(key); attempt += 1) {
375
+ if (attempt > 0) await new Promise((r) => setTimeout(r, 400));
376
+ for (const page of e.context.pages()) {
377
+ const scdp = await e.context.newCDPSession(page);
378
+ let tid = null;
379
+ try {
380
+ tid = (await scdp.send("Target.getTargetInfo")).targetInfo?.targetId ?? null;
381
+ } catch {}
382
+ if (!tid || e.tabs.has(tid)) {
383
+ await scdp.detach().catch(() => void 0);
384
+ continue;
385
+ }
386
+ const cfg = readBrowserConfig();
387
+ const handle = {
388
+ targetId: tid,
389
+ cdp: scdp,
390
+ relay: new BrowserRelay(scdp, cfg.screencastQuality, cfg.screencastMaxFps),
391
+ page
392
+ };
393
+ this.applyPanelViewport(e, handle).catch(() => void 0);
394
+ await scdp.send("Page.enable").catch(() => void 0);
395
+ await this.applyPanelViewport(e, {
396
+ cdp: scdp,
397
+ relay: handle.relay,
398
+ page
399
+ }).catch(() => void 0);
400
+ e.tabs.set(tid, handle);
401
+ if (tid === key) break;
402
+ }
403
+ }
404
+ const h = e.tabs.get(key);
405
+ if (!h) throw new BrowserRegistryRefusal("NO_TARGET", "no such tab: " + key);
406
+ return h;
407
+ }
408
+ /** Enumerate the context's page targets (ADR-0040 D5 feed) — type:page
409
+ * only; iframes/omnibox/service workers are chrome noise (wire capture
410
+ * 2026-10-24). Read-only: never attaches, never streams (D1). */
411
+ async listTabs(id) {
412
+ const e = this.peek(id);
413
+ const src = (e.activeTargetId ? e.tabs.get(e.activeTargetId) : null)?.cdp ?? [...e.tabs.values()][0]?.cdp;
414
+ if (!src) return [];
415
+ return ((await src.send("Target.getTargets").catch(() => null))?.targetInfos ?? []).filter((t) => t.type === "page").map((t) => ({
416
+ targetId: t.targetId,
417
+ url: t.url,
418
+ title: t.title,
419
+ active: t.targetId === e.activeTargetId
420
+ }));
421
+ }
422
+ /** Attach (lazily), seed the first frame, re-apply the viewport, and move
423
+ * the active pointer (ADR-0040 D1/D2/D4). The OLD active relay pauses —
424
+ * only the active tab streams. Returns the boundary payload. */
425
+ async activate(id, targetId) {
426
+ const e = this.peek(id);
427
+ if (e.closed) throw new BrowserRegistryRefusal("CLOSED", "session is closing");
428
+ const h = await this.handleOf(e, targetId);
429
+ const old = e.activeTargetId ? e.tabs.get(e.activeTargetId) : null;
430
+ if (old && old.targetId !== targetId) await old.relay.pause().catch(() => void 0);
431
+ await h.cdp.send("Page.enable").catch(() => void 0);
432
+ await this.applyPanelViewport(e, h);
433
+ await h.cdp.send("Page.bringToFront").catch(() => void 0);
434
+ await h.relay.ensureStreaming().catch(() => void 0);
435
+ if (h.relay.latestFrame() === null) for (let i = 0; i < 10 && h.relay.latestFrame() === null; i += 1) await new Promise((r) => setTimeout(r, 100));
436
+ if (h.relay.latestFrame() === null) {
437
+ const cfg = readBrowserConfig();
438
+ const shot = await h.cdp.send("Page.captureScreenshot", {
439
+ format: "jpeg",
440
+ quality: cfg.screencastQuality
441
+ }).catch(() => null);
442
+ if (shot?.data) h.relay.seed({
443
+ seq: 0,
444
+ jpeg: shot.data,
445
+ metadata: { seeded: true }
446
+ });
447
+ }
448
+ e.activeTargetId = targetId;
449
+ let url = "";
450
+ let title = "";
451
+ try {
452
+ const pi = await this.pageInfo(id, targetId);
453
+ url = pi.url;
454
+ title = pi.title;
455
+ } catch {}
456
+ return {
457
+ targetId,
458
+ seq: h.relay.latestFrame()?.seq ?? 0,
459
+ jpeg: h.relay.latestFrame()?.jpeg ?? null,
460
+ url,
461
+ title
462
+ };
304
463
  }
305
464
  async open(options = {}) {
306
465
  const cfg = readBrowserConfig();
@@ -323,12 +482,13 @@ var BrowserRegistry = class {
323
482
  "--disable-renderer-backgrounding",
324
483
  "--disable-background-timer-throttling",
325
484
  "--autoplay-policy=no-user-gesture-required",
326
- "--window-position=-32000,-32000"
485
+ "--window-position=-32000,-32000",
486
+ "--window-size=" + (Math.max(200, Math.min(1920, options.width ?? 730)) + 6) + "," + (Math.max(120, Math.min(1080, options.height ?? 830)) + 70)
327
487
  ],
328
- viewport: {
329
- width: 1920,
330
- height: 1080
331
- },
488
+ viewport: options.headless ?? cfg.headless ? {
489
+ width: Math.max(200, Math.min(1920, options.width ?? 730)),
490
+ height: Math.max(120, Math.min(1080, options.height ?? 830))
491
+ } : null,
332
492
  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
493
  timezoneId: "America/New_York",
334
494
  locale: "en-US"
@@ -343,6 +503,17 @@ var BrowserRegistry = class {
343
503
  const pid = pidOfPort(port);
344
504
  const cdp = await context.newCDPSession(context.pages()[0] ?? await context.newPage());
345
505
  const relay = new BrowserRelay(cdp, cfg.screencastQuality, cfg.screencastMaxFps);
506
+ const tabs = /* @__PURE__ */ new Map();
507
+ let activeTargetId = null;
508
+ try {
509
+ activeTargetId = (await cdp.send("Target.getTargetInfo")).targetInfo?.targetId ?? null;
510
+ } catch {}
511
+ if (activeTargetId) tabs.set(activeTargetId, {
512
+ targetId: activeTargetId,
513
+ cdp,
514
+ relay,
515
+ page: context.pages()[0]
516
+ });
346
517
  await relay.start();
347
518
  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
519
  await cdp.send("Page.enable").catch(() => void 0);
@@ -365,8 +536,13 @@ var BrowserRegistry = class {
365
536
  const entry = {
366
537
  id,
367
538
  context,
368
- cdp,
369
- relay,
539
+ tabs,
540
+ activeTargetId,
541
+ viewport: {
542
+ width: Math.max(200, Math.min(1920, options.width ?? 730)),
543
+ height: Math.max(120, Math.min(1080, options.height ?? 830))
544
+ },
545
+ headless: options.headless ?? cfg.headless,
370
546
  port,
371
547
  pid,
372
548
  profileDir,
@@ -382,15 +558,17 @@ var BrowserRegistry = class {
382
558
  };
383
559
  state().entries.set(id, entry);
384
560
  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);
561
+ if (process.env.DSI_MCP_IN_PROCESS === "1") {
562
+ evictBrainPort(brainPort, id);
563
+ try {
564
+ entry.mcpInProcess = await startInProcessMcp(entry.port, brainPort, () => {
565
+ entry.lastMcpActivity = Date.now();
566
+ });
567
+ } catch (e) {
568
+ entry.mcpHealth = "down";
569
+ entry.mcpError = e.message;
570
+ }
571
+ } else this.spawnMcpChild(entry, cfg.mcpPin);
394
572
  }
395
573
  return {
396
574
  id,
@@ -462,7 +640,8 @@ var BrowserRegistry = class {
462
640
  errs.push(e);
463
641
  }
464
642
  try {
465
- entry.relay.stop();
643
+ for (const h of entry.tabs.values()) h.relay.stop();
644
+ entry.tabs.clear();
466
645
  } catch (e) {
467
646
  errs.push(e);
468
647
  }
@@ -488,13 +667,13 @@ var BrowserRegistry = class {
488
667
  /** Wait for the page's next load event, capped — the navigate idiom
489
668
  * (a send races the context teardown otherwise) shared by reload and
490
669
  * history travel (ADR-0031 D3/D4). */
491
- async waitLoad(e, capMs = 3e3) {
670
+ async waitLoad(h, capMs = 3e3) {
492
671
  await new Promise((res) => {
493
672
  const on = (p) => {
494
- e.cdp.off("Page.loadEventFired", on);
673
+ h.cdp.off("Page.loadEventFired", on);
495
674
  res();
496
675
  };
497
- e.cdp.on("Page.loadEventFired", on);
676
+ h.cdp.on("Page.loadEventFired", on);
498
677
  setTimeout(res, capMs);
499
678
  });
500
679
  }
@@ -502,37 +681,66 @@ var BrowserRegistry = class {
502
681
  * damage is the only reliable way to make screencast emit a frame. */
503
682
  async navigate(id, url, opts) {
504
683
  const e = this.peek(id);
505
- await e.cdp.send("Page.enable").catch(() => void 0);
684
+ const h = await this.handleOf(e, opts?.targetId);
685
+ await h.cdp.send("Page.enable").catch(() => void 0);
506
686
  if (opts?.waitLoad) {
507
- const loaded = this.waitLoad(e);
508
- await e.cdp.send("Page.navigate", { url });
687
+ const loaded = this.waitLoad(h);
688
+ await h.cdp.send("Page.navigate", { url });
509
689
  await loaded;
510
690
  return;
511
691
  }
512
- await e.cdp.send("Page.navigate", { url });
692
+ await h.cdp.send("Page.navigate", { url });
513
693
  }
514
694
  /** Match the page viewport to the panel's glass box (ADR-0031
515
695
  * amendment 2): the screencast frame then equals the panel size, so
516
696
  * the mirror shows content at native scale instead of zooming a
517
697
  * fixed default viewport. CDP-side clamps keep hostile sizes out. */
518
- async setViewport(id, width, height) {
698
+ async setViewport(id, width, height, targetId) {
699
+ console.log("[viewport] set", id.slice(0, 8), width + "x" + height, "target", targetId ?? "active");
519
700
  const w = Math.max(200, Math.min(8192, Math.round(width)));
520
701
  const h = Math.max(120, Math.min(8192, Math.round(height)));
521
702
  const e = this.peek(id);
522
- await e.cdp.send("Page.enable").catch(() => void 0);
523
- await e.cdp.send("Emulation.setDeviceMetricsOverride", {
703
+ e.viewport = {
524
704
  width: w,
525
- height: h,
526
- deviceScaleFactor: 0,
527
- mobile: false
705
+ height: h
706
+ };
707
+ const handle = await this.handleOf(e, targetId);
708
+ await handle.cdp.send("Page.enable").catch(() => void 0);
709
+ const prevSeq = handle.relay.latestFrame()?.seq ?? -1;
710
+ await this.applyPanelViewport(e, handle);
711
+ await this.seedAfterResize(handle, prevSeq).catch(() => void 0);
712
+ }
713
+ /** ADR-0041 D3: a resize must REPAINT, not wait for the next page
714
+ * change — the screencast speaks only on change, so a static page
715
+ * keeps the old-aspect frame letterboxed on the panel forever (the
716
+ * operator's black bands, 2026-10-25). Bounded grace for a FRESH
717
+ * frame (seq past prevSeq); silence answers with the deterministic
718
+ * captureScreenshot seed — activate()'s first-frame idiom re-fired
719
+ * for the resize path. Never hangs the verb past the grace. */
720
+ async seedAfterResize(handle, prevSeq) {
721
+ for (let i = 0; i < 10 && (handle.relay.latestFrame()?.seq ?? -1) === prevSeq; i += 1) await new Promise((r) => setTimeout(r, 100));
722
+ if ((handle.relay.latestFrame()?.seq ?? -1) !== prevSeq) return;
723
+ const cfg = readBrowserConfig();
724
+ const shot = await handle.cdp.send("Page.captureScreenshot", {
725
+ format: "jpeg",
726
+ quality: cfg.screencastQuality
727
+ }).catch(() => null);
728
+ if (shot?.data) handle.relay.seed({
729
+ seq: 0,
730
+ jpeg: shot.data,
731
+ metadata: {
732
+ seeded: true,
733
+ resize: true
734
+ }
528
735
  });
529
736
  }
530
737
  /** The history position (ADR-0031): every proxy-verb answer carries it
531
738
  * so the header's back/forward buttons stay honest at the ends. */
532
- async navInfo(id) {
739
+ async navInfo(id, targetId) {
533
740
  const e = this.peek(id);
534
- await e.cdp.send("Page.enable").catch(() => void 0);
535
- const hist = await e.cdp.send("Page.getNavigationHistory", {});
741
+ const h = await this.handleOf(e, targetId);
742
+ await h.cdp.send("Page.enable").catch(() => void 0);
743
+ const hist = await h.cdp.send("Page.getNavigationHistory", {});
536
744
  return {
537
745
  currentIndex: hist.currentIndex,
538
746
  entryCount: hist.entries.length
@@ -540,30 +748,32 @@ var BrowserRegistry = class {
540
748
  }
541
749
  /** Reload the session's active page (ADR-0031 D4): Page.reload keeps
542
750
  * the history entry, unlike re-navigating the current URL. */
543
- async reload(id) {
751
+ async reload(id, targetId) {
544
752
  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", {});
753
+ const h = await this.handleOf(e, targetId);
754
+ await h.cdp.send("Page.enable").catch(() => void 0);
755
+ const loaded = this.waitLoad(h);
756
+ await h.cdp.send("Page.reload", {});
548
757
  await loaded;
549
- return this.pageInfo(id);
758
+ return this.pageInfo(id, targetId);
550
759
  }
551
760
  /** Travel the browser's OWN back/forward list (ADR-0031 D3):
552
761
  * Page.getNavigationHistory picks the entry, Page.navigateToHistoryEntry
553
762
  * is the browser's travel verb — never Runtime.evaluate('history.back()'),
554
763
  * which races the teardown and lies about the browser-level list.
555
764
  * Bounds refusals keep the header buttons honest at the list ends. */
556
- async pageHistory(id, dir) {
765
+ async pageHistory(id, dir, targetId) {
557
766
  const e = this.peek(id);
558
- await e.cdp.send("Page.enable").catch(() => void 0);
559
- const hist = await e.cdp.send("Page.getNavigationHistory", {});
767
+ const h = await this.handleOf(e, targetId);
768
+ await h.cdp.send("Page.enable").catch(() => void 0);
769
+ const hist = await h.cdp.send("Page.getNavigationHistory", {});
560
770
  const target = dir === "back" ? hist.currentIndex - 1 : hist.currentIndex + 1;
561
771
  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 });
772
+ const loaded = this.waitLoad(h);
773
+ await h.cdp.send("Page.navigateToHistoryEntry", { entryId: hist.entries[target].id });
564
774
  await loaded;
565
775
  return {
566
- ...await this.pageInfo(id),
776
+ ...await this.pageInfo(id, targetId),
567
777
  currentIndex: target,
568
778
  entryCount: hist.entries.length
569
779
  };
@@ -589,9 +799,10 @@ var BrowserRegistry = class {
589
799
  * location read, the e2e's DOM-truth channel (the glass proves clicks
590
800
  * by effects the page itself reports), and the viewport-follow witness
591
801
  * (innerWidth/innerHeight prove the emulation landed, amend 2). */
592
- async pageInfo(id) {
802
+ async pageInfo(id, targetId) {
593
803
  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);
804
+ const h = await this.handleOf(e, targetId);
805
+ const raw = await this.evaluateCapped(h.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
806
  if (raw === null) return {
596
807
  url: "(busy)",
597
808
  title: "(busy)",
@@ -603,14 +814,141 @@ var BrowserRegistry = class {
603
814
  };
604
815
  return JSON.parse(raw);
605
816
  }
606
- dispatch(id, input) {
817
+ /** The page element under viewport coords — the glass context menu's
818
+ * data pass (BUGFIX 2026-10-25: Chrome's NATIVE right-click menu is
819
+ * browser UI and never renders in the screencast, so DSI supplies its
820
+ * own menu; this tells it what the right-click landed on). */
821
+ async elementAt(id, x, y, targetId) {
822
+ const e = this.peek(id);
823
+ const h = await this.handleOf(e, targetId);
824
+ const expr = "JSON.stringify((() => { const el = document.elementFromPoint(" + Number(x) + "," + Number(y) + "); if (!el) return { href: null, src: null, text: null }; const a = el.closest(\"a\"); const img = el.closest(\"img\"); return { href: a ? a.href : null, src: img ? (img.currentSrc || img.src) : null, text: (a && a.textContent || \"\").trim().slice(0, 80) || null }; })())";
825
+ const raw = await this.evaluateCapped(h.cdp, expr, 2e3);
826
+ if (raw === null) return {
827
+ href: null,
828
+ src: null,
829
+ text: null
830
+ };
831
+ try {
832
+ return JSON.parse(raw);
833
+ } catch {
834
+ return {
835
+ href: null,
836
+ src: null,
837
+ text: null
838
+ };
839
+ }
840
+ }
841
+ /** Open a NEW tab in the glass at `url` and make it the active face
842
+ * (the context menu's 'open in new tab' verbs). Returns the new tab. */
843
+ async openTab(id, url, opts) {
844
+ const e = this.peek(id);
845
+ if (e.closed) throw new BrowserRegistryRefusal("CLOSED", "session is closing");
846
+ const src = (e.activeTargetId ? e.tabs.get(e.activeTargetId) : null)?.cdp ?? [...e.tabs.values()][0]?.cdp;
847
+ if (!src) throw new BrowserRegistryRefusal("CLOSED", "no tab handle to create from");
848
+ const targetId = (await src.send("Target.createTarget", { url: "about:blank" }))?.targetId;
849
+ if (!targetId) throw new BrowserRegistryRefusal("NO_TARGET", "Target.createTarget returned no id");
850
+ await this.navigate(id, url, {
851
+ waitLoad: true,
852
+ targetId
853
+ });
854
+ if (opts?.activate ?? true) await this.activate(id, targetId);
855
+ const h = e.tabs.get(targetId);
856
+ const pi = await this.pageInfo(id, targetId).catch(() => ({
857
+ url,
858
+ title: ""
859
+ }));
860
+ return {
861
+ targetId,
862
+ seq: h?.relay.latestFrame()?.seq ?? 0,
863
+ jpeg: h?.relay.latestFrame()?.jpeg ?? null,
864
+ url: pi.url || url,
865
+ title: pi.title
866
+ };
867
+ }
868
+ /** Apply the remembered panel viewport by RESIZING THE WINDOW (round 10:
869
+ * emulation-on-headed renders the page centered in the big off-screen
870
+ * window — the small/cut-off mirror). Also clears any stale override. */
871
+ /** Resize the glass's WINDOW to the panel size and clear emulation.
872
+ * ROUND 10 (the REAL small/cut-off root cause, headed-proven):
873
+ * Emulation.setDeviceMetricsOverride on HEADED chrome renders the
874
+ * emulated viewport CENTERED INSIDE the physical off-screen window
875
+ * (black around it) and the screencast captures the whole window —
876
+ * the mirror shows a tiny page. Resizing the WINDOW itself makes the
877
+ * page fill it natively; the panel is the window's face (ADR-0029 D1).
878
+ * Re-asserted on every attach/switch/setViewport (round 11: something
879
+ * re-expands the window — the mirror shrinks again — so this is now
880
+ * idempotent and called from all three paths). */
881
+ async applyPanelViewport(e, handle) {
882
+ await handle.cdp.send("Page.enable").catch(() => void 0);
883
+ if (e.headless && handle.page) {
884
+ await Promise.race([handle.page.setViewportSize({
885
+ width: e.viewport.width,
886
+ height: e.viewport.height
887
+ }).catch(() => void 0), new Promise((res) => setTimeout(res, 2500))]);
888
+ return;
889
+ }
890
+ const race = async (p, fb) => await Promise.race([p.catch(() => fb), new Promise((res) => setTimeout(() => res(fb), 2500))]);
891
+ const anyCdp = handle.cdp;
892
+ const dims = await race(anyCdp.send("Runtime.evaluate", {
893
+ expression: "JSON.stringify({ oh: window.outerHeight - window.innerHeight, ow: window.outerWidth - window.innerWidth })",
894
+ returnByValue: true
895
+ }), null);
896
+ let chromeH = 0, chromeW = 0;
897
+ try {
898
+ const d = JSON.parse(dims && dims.result && dims.result.value || "{}");
899
+ chromeH = Number(d.oh) || 0;
900
+ chromeW = Number(d.ow) || 0;
901
+ } catch {}
902
+ const anyCdp2 = handle.cdp;
903
+ const win = await race(anyCdp2.send("Target.getWindowForTarget"), null);
904
+ if (win && win.windowId) {
905
+ await race(anyCdp2.send("Browser.setWindowBounds", {
906
+ windowId: win.windowId,
907
+ bounds: {
908
+ width: Math.max(200, e.viewport.width + chromeW),
909
+ height: Math.max(120, e.viewport.height + chromeH),
910
+ windowState: "normal"
911
+ }
912
+ }), null);
913
+ const check = await race(anyCdp2.send("Browser.getWindowForTarget", { targetId: e.activeTargetId }), null);
914
+ console.log("[window] resized ->", JSON.stringify(check && check.bounds ? check.bounds : check), "want", e.viewport.width + chromeW, "x", e.viewport.height + chromeH);
915
+ } else console.log("[window] no windowId — resize skipped (raced out)");
916
+ await race(anyCdp2.send("Emulation.clearDeviceMetricsOverride"), null);
917
+ }
918
+ /** Close ONE tab (the strip X): Target.closeTarget, stop its relay,
919
+ * drop the handle — and if it was the active face, the pointer moves
920
+ * to the first surviving tab (re-activated, first-frame contract
921
+ * re-fired). Closing the LAST tab is refused: the kill ladder owns
922
+ * session death (the trash is the operator-facing kill). */
923
+ async closeTab(id, targetId) {
924
+ const e = this.peek(id);
925
+ if (e.closed) throw new BrowserRegistryRefusal("CLOSED", "session is closing");
926
+ if (e.tabs.size <= 1) throw new BrowserRegistryRefusal("NO_TARGET", "cannot close the last tab — use the trash to close the glass");
927
+ const victim = e.tabs.get(targetId);
928
+ if (!victim) throw new BrowserRegistryRefusal("NO_TARGET", "no such tab: " + targetId);
929
+ victim.relay.stop();
930
+ e.tabs.delete(targetId);
931
+ await victim.cdp.send("Target.closeTarget", { targetId }).catch(() => void 0);
932
+ await victim.cdp.detach().catch(() => void 0);
933
+ if (e.activeTargetId === targetId) {
934
+ const next = [...e.tabs.keys()][0] ?? null;
935
+ e.activeTargetId = next;
936
+ if (next) await this.activate(id, next).catch(() => void 0);
937
+ else e.activeTargetId = null;
938
+ }
939
+ return {
940
+ ok: true,
941
+ activeTargetId: e.activeTargetId
942
+ };
943
+ }
944
+ async dispatch(id, input, targetId) {
607
945
  if (!state().entries.has(id) && state().closed.has(id)) throw new BrowserRegistryRefusal("CLOSED", "session was closed");
608
946
  const e = this.peek(id);
609
947
  if (e.closed) throw new BrowserRegistryRefusal("CLOSED", "session is closing");
610
- return e.relay.dispatch(input);
948
+ await (await this.handleOf(e, targetId)).relay.dispatch(input);
611
949
  }
612
950
  };
613
951
  var browserRegistry = new BrowserRegistry();
614
952
 
615
953
  export { BrowserRegistryRefusal as B, browserRegistry as b };
616
- //# sourceMappingURL=registry.js-BC-TNdmn.js.map
954
+ //# sourceMappingURL=registry.js-C2MdrfNv.js.map
@@ -1,6 +1,6 @@
1
1
  import { i as index_server_exports } from './index-server.js-DmIEbDVz.js';
2
2
  import './shared.js-HQ0rfhm4.js';
3
- import './internal2.js-DFG0wDsP.js';
3
+ import './internal2.js-Ba5p8uFM.js';
4
4
  import './exports.js-DH_tjtdv.js';
5
5
  import { U as snapshot, g as getContext, n as noop } from './server.js-B1bDXhHu.js';
6
6
  import { U as UI_LOCALES } from './config.js-vThvQeMn.js';
@@ -304,4 +304,4 @@ var page = {
304
304
  };
305
305
 
306
306
  export { afterNavigate as a, backtoworkspace2 as b, currentLocale as c, dshunreachable1 as d, replaceState as e, page as p, reapednote1 as r, sessionnotfound2 as s, t, unexpectederror1 as u };
307
- //# sourceMappingURL=state.js-Dki_Bq11.js.map
307
+ //# sourceMappingURL=state.js-BSiAgink.js.map
@@ -1,7 +1,7 @@
1
1
  import { c as readA2aConfig } from './insight-config.js-Dp_2gB5J.js';
2
2
  import { i as insertWaiting, o as openA2aDb, s as settleRow, p as pruneTerminalBefore, l as listWaiting } from './db.js-DQm6CZ_r.js';
3
3
  import { g as getDshConnection } from './dsh-connection.js-BgeraFA2.js';
4
- import { a as entryForEvent, h as historyToEvents } from './dsh-events.js-CGuF_had.js';
4
+ import { a as entryForEvent, h as historyToEvents } from './dsh-events.js-BUkLR6ZV.js';
5
5
 
6
6
  //#region src/lib/server/a2a/matcher.ts
7
7
  /**
@@ -470,4 +470,4 @@ function registerWatch(row) {
470
470
  }
471
471
 
472
472
  export { configureWatcher as c, ensureStarted as e, registerWatch as r };
473
- //# sourceMappingURL=watcher.js-f54CFvdI.js.map
473
+ //# sourceMappingURL=watcher.js-BVKnoQUw.js.map
@@ -1,5 +1,5 @@
1
1
  import { a as listRecent } from '../../../../chunks/db.js-DQm6CZ_r.js';
2
- import { e as ensureStarted } from '../../../../chunks/watcher.js-f54CFvdI.js';
2
+ import { e as ensureStarted } from '../../../../chunks/watcher.js-BVKnoQUw.js';
3
3
  import { j as json } from '../../../../chunks/utils.js-CAdNO8Tu.js';
4
4
  import '../../../../chunks/insight-config.js-Dp_2gB5J.js';
5
5
  import '../../../../chunks/config.js-vThvQeMn.js';
@@ -11,7 +11,7 @@ import 'yaml';
11
11
  import '../../../../chunks/settings-home2.js-f75-B6RI.js';
12
12
  import 'node:sqlite';
13
13
  import '../../../../chunks/dsh-connection.js-BgeraFA2.js';
14
- import '../../../../chunks/dsh-events.js-CGuF_had.js';
14
+ import '../../../../chunks/dsh-events.js-BUkLR6ZV.js';
15
15
  import '../../../../chunks/merge.js-yMwW440S.js';
16
16
  import '../../../../chunks/shared.js-HQ0rfhm4.js';
17
17
  import '../../../../chunks/uneval.js-BJ9Qq2SF.js';
@@ -61,4 +61,4 @@ var GET = ({ url }) => {
61
61
  };
62
62
 
63
63
  export { GET };
64
- //# sourceMappingURL=_server.ts.js-DN0zl7cz.js.map
64
+ //# sourceMappingURL=_server.ts.js-3kQCQuHT.js.map
@@ -1,6 +1,6 @@
1
1
  import { c as readA2aConfig } from '../../../../../chunks/insight-config.js-Dp_2gB5J.js';
2
2
  import { g as getDshConnection } from '../../../../../chunks/dsh-connection.js-BgeraFA2.js';
3
- import { c as configureWatcher, r as registerWatch } from '../../../../../chunks/watcher.js-f54CFvdI.js';
3
+ import { c as configureWatcher, r as registerWatch } from '../../../../../chunks/watcher.js-BVKnoQUw.js';
4
4
  import { m as mintA2aId } from '../../../../../chunks/a2a-protocol.js-C77mVg2Q.js';
5
5
  import { j as json } from '../../../../../chunks/utils.js-CAdNO8Tu.js';
6
6
  import '../../../../../chunks/config.js-vThvQeMn.js';
@@ -12,7 +12,7 @@ import 'yaml';
12
12
  import '../../../../../chunks/settings-home2.js-f75-B6RI.js';
13
13
  import '../../../../../chunks/db.js-DQm6CZ_r.js';
14
14
  import 'node:sqlite';
15
- import '../../../../../chunks/dsh-events.js-CGuF_had.js';
15
+ import '../../../../../chunks/dsh-events.js-BUkLR6ZV.js';
16
16
  import '../../../../../chunks/merge.js-yMwW440S.js';
17
17
  import '../../../../../chunks/shared.js-HQ0rfhm4.js';
18
18
  import '../../../../../chunks/uneval.js-BJ9Qq2SF.js';
@@ -99,4 +99,4 @@ var POST = async ({ request }) => {
99
99
  };
100
100
 
101
101
  export { POST };
102
- //# sourceMappingURL=_server.ts.js-C3byr74D.js.map
102
+ //# sourceMappingURL=_server.ts.js-BUBTCLFn.js.map