@andorra-labs/code 0.1.18 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/account-jev-savings.d.ts +4 -0
- package/dist/src/account-jev-savings.js +92 -0
- package/dist/src/acp-agent.js +2 -2
- package/dist/src/agent-execution.js +347 -45
- package/dist/src/agent-mcp.js +7 -1
- package/dist/src/agent-modifiers.js +5 -7
- package/dist/src/analytics.d.ts +19 -1
- package/dist/src/analytics.js +9 -1
- package/dist/src/andorra/entry.js +15 -6
- package/dist/src/andorra/hosted.d.ts +8 -0
- package/dist/src/andorra/hosted.js +22 -3
- package/dist/src/andorra/streams.d.ts +49 -0
- package/dist/src/andorra/streams.js +98 -0
- package/dist/src/antigravity-acp.d.ts +28 -0
- package/dist/src/antigravity-acp.js +150 -0
- package/dist/src/antigravity-terminal.d.ts +2 -0
- package/dist/src/antigravity-terminal.js +214 -0
- package/dist/src/app-server/adaptive-routing-settings.d.ts +37 -0
- package/dist/src/app-server/adaptive-routing-settings.js +69 -0
- package/dist/src/app-server/artifact.d.ts +14 -0
- package/dist/src/app-server/artifact.js +46 -0
- package/dist/src/app-server/legal-protocol.d.ts +33 -0
- package/dist/src/app-server/legal-protocol.js +16 -0
- package/dist/src/app-server/protocol.d.ts +23 -3
- package/dist/src/app-server/protocol.js +3 -1
- package/dist/src/app-server/telemetry-protocol.d.ts +53 -0
- package/dist/src/app-server/telemetry-protocol.js +2 -0
- package/dist/src/app-server/telemetry.d.ts +38 -0
- package/dist/src/app-server/telemetry.js +163 -0
- package/dist/src/app-server/workspace.d.ts +3 -1
- package/dist/src/app-server/workspace.js +39 -8
- package/dist/src/app-server.d.ts +50 -25
- package/dist/src/app-server.js +1008 -400
- package/dist/src/auth/AuthManager.d.ts +11 -2
- package/dist/src/auth/AuthManager.js +56 -13
- package/dist/src/auth/index.d.ts +5 -1
- package/dist/src/auth/index.js +8 -1
- package/dist/src/auth/lifecycle.d.ts +13 -0
- package/dist/src/auth/lifecycle.js +109 -0
- package/dist/src/auth/store.d.ts +1 -0
- package/dist/src/auth/store.js +12 -0
- package/dist/src/auth/types.d.ts +12 -0
- package/dist/src/automation-runner.js +2 -0
- package/dist/src/automation-service.js +7 -2
- package/dist/src/benchmark-scores.d.ts +88 -0
- package/dist/src/benchmark-scores.js +302 -0
- package/dist/src/bridge/command.js +4 -1
- package/dist/src/bridge/control.js +2 -1
- package/dist/src/bridge/engines.d.ts +2 -0
- package/dist/src/bridge/engines.js +9 -0
- package/dist/src/bridge/host-ops.d.ts +2 -2
- package/dist/src/bridge/host-ops.js +4 -2
- package/dist/src/bridge/host.d.ts +2 -0
- package/dist/src/bridge/host.js +63 -12
- package/dist/src/bridge/protocol.d.ts +1 -0
- package/dist/src/bridge/protocol.js +1 -0
- package/dist/src/browser-panel-tool.d.ts +12 -0
- package/dist/src/browser-panel-tool.js +30 -3
- package/dist/src/browser-runner.js +53 -62
- package/dist/src/browser-server.js +10 -4
- package/dist/src/browser-session.d.ts +14 -0
- package/dist/src/browser-session.js +57 -12
- package/dist/src/browser-view.d.ts +40 -1
- package/dist/src/browser-view.js +163 -9
- package/dist/src/browser-window-style.d.ts +27 -0
- package/dist/src/browser-window-style.js +244 -0
- package/dist/src/claude-provider.d.ts +1 -0
- package/dist/src/claude-provider.js +77 -36
- package/dist/src/cli.js +235 -58
- package/dist/src/codex-provider.d.ts +1 -0
- package/dist/src/codex-provider.js +43 -7
- package/dist/src/coding-tools.d.ts +1 -0
- package/dist/src/coding-tools.js +19 -5
- package/dist/src/command-screens.d.ts +1 -1
- package/dist/src/command-screens.js +2 -2
- package/dist/src/commands.d.ts +8 -1
- package/dist/src/commands.js +67 -63
- package/dist/src/completion.js +5 -3
- package/dist/src/config.d.ts +14 -3
- package/dist/src/config.js +54 -16
- package/dist/src/context-budget.d.ts +11 -2
- package/dist/src/context-budget.js +23 -2
- package/dist/src/context-compaction.d.ts +10 -8
- package/dist/src/context-compaction.js +23 -24
- package/dist/src/deadline.js +1 -1
- package/dist/src/decision/DecisionManager.d.ts +5 -0
- package/dist/src/decision/DecisionManager.js +39 -2
- package/dist/src/decision/applyToolMenu.js +6 -2
- package/dist/src/decision/hostedPolicy.js +6 -4
- package/dist/src/decision/optimizationPolicy.d.ts +10 -0
- package/dist/src/decision/optimizationPolicy.js +23 -3
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +2 -1
- package/dist/src/decision/providers/AndorraDecisionProvider.js +17 -7
- package/dist/src/decision/providers/index.js +1 -1
- package/dist/src/decision/toolFamilies.js +1 -1
- package/dist/src/decision/types.d.ts +2 -0
- package/dist/src/efficiency.d.ts +75 -1
- package/dist/src/efficiency.js +114 -3
- package/dist/src/extensions.d.ts +2 -0
- package/dist/src/extensions.js +30 -20
- package/dist/src/github-app/agent-writes.d.ts +1 -1
- package/dist/src/github-app/agent-writes.js +1 -1
- package/dist/src/github-app/event-source.d.ts +0 -5
- package/dist/src/github-app/event-source.js +1 -31
- package/dist/src/github-app/metrics.d.ts +2 -5
- package/dist/src/github-app/metrics.js +2 -14
- package/dist/src/github-app/review-loop.d.ts +5 -5
- package/dist/src/github-app/review-loop.js +1 -1
- package/dist/src/github-app/review-node.d.ts +2 -2
- package/dist/src/github-app/triggers.d.ts +3 -3
- package/dist/src/glob-search.d.ts +1 -0
- package/dist/src/glob-search.js +3 -0
- package/dist/src/google-provider.d.ts +5 -28
- package/dist/src/google-provider.js +6 -141
- package/dist/src/graph-editor-session.d.ts +1 -0
- package/dist/src/graph-editor-session.js +2 -0
- package/dist/src/graph-health.js +3 -1
- package/dist/src/graph-runner.js +19 -13
- package/dist/src/graph-selection.d.ts +3 -1
- package/dist/src/graph-selection.js +2 -2
- package/dist/src/graph-server.d.ts +8 -1
- package/dist/src/graph-server.js +45 -10
- package/dist/src/graph-sync.d.ts +2 -1
- package/dist/src/graph-sync.js +13 -0
- package/dist/src/graph-ui/app.js +19 -8
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graphs.d.ts +17 -1
- package/dist/src/graphs.js +51 -5
- package/dist/src/grok-provider.js +17 -14
- package/dist/src/hardened-runtime.js +7 -4
- package/dist/src/jev-savings.d.ts +4 -0
- package/dist/src/jev-savings.js +13 -0
- package/dist/src/legal/client.d.ts +25 -0
- package/dist/src/legal/client.js +47 -0
- package/dist/src/legal/command.d.ts +13 -0
- package/dist/src/legal/command.js +98 -0
- package/dist/src/legal/documents.d.ts +2 -0
- package/dist/src/legal/documents.js +14 -0
- package/dist/src/legal/gate.d.ts +13 -0
- package/dist/src/legal/gate.js +96 -0
- package/dist/src/legal/manifest.d.ts +21 -0
- package/dist/src/legal/manifest.js +23 -0
- package/dist/src/legal/receipt.d.ts +13 -0
- package/dist/src/legal/receipt.js +137 -0
- package/dist/src/legal/release.d.ts +27 -0
- package/dist/src/legal/release.js +28 -0
- package/dist/src/managed-sign-in.d.ts +0 -1
- package/dist/src/managed-sign-in.js +0 -13
- package/dist/src/membership.d.ts +27 -1
- package/dist/src/membership.js +139 -7
- package/dist/src/model-metadata.js +3 -7
- package/dist/src/model-pool.d.ts +99 -0
- package/dist/src/model-pool.js +136 -0
- package/dist/src/model-relay/local.js +5 -0
- package/dist/src/model-relay/remote.d.ts +2 -0
- package/dist/src/model-relay/remote.js +4 -0
- package/dist/src/model-tiers.d.ts +13 -1
- package/dist/src/model-tiers.js +28 -4
- package/dist/src/opencode-cli-provider.js +59 -56
- package/dist/src/opencode-provider.js +16 -13
- package/dist/src/permissions.d.ts +5 -0
- package/dist/src/permissions.js +7 -0
- package/dist/src/plan-pass.js +2 -1
- package/dist/src/pool-scores.d.ts +45 -0
- package/dist/src/pool-scores.js +40 -0
- package/dist/src/provider-connection.js +3 -17
- package/dist/src/provider-engine.js +42 -12
- package/dist/src/provider-request-error.d.ts +8 -0
- package/dist/src/provider-request-error.js +12 -0
- package/dist/src/provider-settings.d.ts +1 -1
- package/dist/src/provider-settings.js +36 -18
- package/dist/src/provider-turn-deadline.d.ts +39 -0
- package/dist/src/provider-turn-deadline.js +139 -0
- package/dist/src/providers.d.ts +3 -9
- package/dist/src/providers.js +181 -146
- package/dist/src/pull-request-merge.d.ts +1 -8
- package/dist/src/pull-request-merge.js +0 -4
- package/dist/src/pull-requests.d.ts +82 -66
- package/dist/src/pull-requests.js +266 -276
- package/dist/src/qa/runtime/ProcessManager.d.ts +5 -1
- package/dist/src/qa/runtime/ProcessManager.js +9 -3
- package/dist/src/react-runtime.js +147 -56
- package/dist/src/reasoning-probe-cloud.d.ts +10 -0
- package/dist/src/reasoning-probe-cloud.js +209 -0
- package/dist/src/remote/engine-pool.d.ts +3 -0
- package/dist/src/remote/engine-pool.js +85 -18
- package/dist/src/remote/recovery.d.ts +6 -0
- package/dist/src/remote/recovery.js +37 -0
- package/dist/src/run-records.d.ts +13 -3
- package/dist/src/run-records.js +59 -34
- package/dist/src/runtime.d.ts +18 -1
- package/dist/src/runtime.js +25 -7
- package/dist/src/session-summary.d.ts +8 -0
- package/dist/src/session-summary.js +34 -0
- package/dist/src/sessions.d.ts +8 -0
- package/dist/src/sessions.js +12 -3
- package/dist/src/shell.js +6 -0
- package/dist/src/side-panel.js +36 -2
- package/dist/src/sign-in-detection.d.ts +1 -1
- package/dist/src/sign-in-detection.js +4 -10
- package/dist/src/sign-in-offer.js +1 -1
- package/dist/src/skill-commands.js +1 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +2 -2
- package/dist/src/skills/bundled/graph-manager/patterns.md +13 -19
- package/dist/src/skills/bundled/provenance.json +2 -2
- package/dist/src/subagent-run.js +50 -50
- package/dist/src/subscription-usage.d.ts +50 -0
- package/dist/src/subscription-usage.js +92 -0
- package/dist/src/task-checkout.d.ts +20 -4
- package/dist/src/task-checkout.js +78 -8
- package/dist/src/telemetry/access.d.ts +18 -0
- package/dist/src/telemetry/access.js +43 -0
- package/dist/src/telemetry/aggregate.d.ts +18 -2
- package/dist/src/telemetry/aggregate.js +22 -9
- package/dist/src/telemetry/capture-core.d.ts +33 -14
- package/dist/src/telemetry/capture-core.js +124 -25
- package/dist/src/telemetry/capture.d.ts +3 -2
- package/dist/src/telemetry/capture.js +21 -1
- package/dist/src/telemetry/decision-capture.js +4 -0
- package/dist/src/telemetry/emitter.d.ts +6 -7
- package/dist/src/telemetry/emitter.js +124 -29
- package/dist/src/telemetry/gate.d.ts +41 -2
- package/dist/src/telemetry/gate.js +89 -4
- package/dist/src/telemetry/home.d.ts +1 -0
- package/dist/src/telemetry/home.js +20 -0
- package/dist/src/telemetry/identity.d.ts +6 -3
- package/dist/src/telemetry/identity.js +19 -6
- package/dist/src/telemetry/lifecycle.d.ts +8 -0
- package/dist/src/telemetry/lifecycle.js +76 -0
- package/dist/src/telemetry/outbox.d.ts +13 -8
- package/dist/src/telemetry/outbox.js +68 -12
- package/dist/src/telemetry/permission-command.d.ts +38 -0
- package/dist/src/telemetry/permission-command.js +208 -0
- package/dist/src/telemetry/permission.d.ts +168 -0
- package/dist/src/telemetry/permission.js +662 -0
- package/dist/src/telemetry/record-installation.d.ts +1 -0
- package/dist/src/telemetry/record-installation.js +9 -0
- package/dist/src/telemetry/region-data.d.ts +12 -0
- package/dist/src/telemetry/region-data.js +1314 -0
- package/dist/src/telemetry/region.d.ts +34 -0
- package/dist/src/telemetry/region.js +87 -0
- package/dist/src/telemetry/run-privacy.d.ts +11 -0
- package/dist/src/telemetry/run-privacy.js +165 -0
- package/dist/src/telemetry/schema.d.ts +27 -6
- package/dist/src/telemetry/schema.js +109 -14
- package/dist/src/telemetry/state.d.ts +11 -7
- package/dist/src/telemetry/state.js +39 -6
- package/dist/src/telemetry/surface.d.ts +20 -3
- package/dist/src/telemetry/surface.js +71 -15
- package/dist/src/telemetry/uploader.d.ts +6 -11
- package/dist/src/telemetry/uploader.js +72 -46
- package/dist/src/telemetry/uploads.d.ts +5 -1
- package/dist/src/telemetry/uploads.js +25 -6
- package/dist/src/telemetry/version.d.ts +5 -0
- package/dist/src/telemetry/version.js +34 -0
- package/dist/src/telemetry/workspace.d.ts +4 -1
- package/dist/src/telemetry/workspace.js +18 -3
- package/dist/src/terminal-ui.d.ts +3 -0
- package/dist/src/terminal-ui.js +48 -6
- package/dist/src/thinking-level-detect.d.ts +3 -1
- package/dist/src/thinking-level-detect.js +8 -3
- package/dist/src/thinking-levels.d.ts +1 -1
- package/dist/src/thinking-levels.js +11 -4
- package/dist/src/timers.d.ts +2 -0
- package/dist/src/todos.d.ts +2 -1
- package/dist/src/todos.js +24 -4
- package/dist/src/tool-argument-coercion.d.ts +7 -0
- package/dist/src/tool-argument-coercion.js +49 -0
- package/dist/src/tool-catalog.d.ts +2 -2
- package/dist/src/tools.js +67 -22
- package/dist/src/transcript.js +2 -1
- package/dist/src/types.d.ts +14 -1
- package/dist/src/update.js +4 -0
- package/dist/src/usage-analytics.d.ts +7 -0
- package/dist/src/usage-analytics.js +85 -13
- package/dist/telemetry-consent-v1 +1 -0
- package/package.json +97 -96
package/dist/src/browser-view.js
CHANGED
|
@@ -6,9 +6,9 @@ import { dirname, join } from 'node:path';
|
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { observePage, observationResult } from './browser-observation.js';
|
|
8
8
|
import { externalAppPromptNote, externalAppScheme, guardExternalApps } from './browser-external-app.js';
|
|
9
|
+
import { browserPidsFromCdp, taskbarStyleApply } from './browser-window-style.js';
|
|
9
10
|
import { desktopUaOverride, hardenContext, stealthLaunchArgs, STEALTH_LOCALE, userAgentMetadata } from './browser-stealth.js';
|
|
10
11
|
export const VIEW_TAB_LIMIT = 6;
|
|
11
|
-
export const VIEW_SESSION_LIMIT = 4;
|
|
12
12
|
export const VIEW_IDLE_CLOSE_MS = 10 * 60 * 1000;
|
|
13
13
|
export const VIEW_HOLD_MAX_MS = 10 * 60 * 1000;
|
|
14
14
|
export const VIEW_FRAME_MIN_INTERVAL_MS = 16;
|
|
@@ -259,6 +259,10 @@ export function channelCandidate(channel, platform, chromiumExecutable) {
|
|
|
259
259
|
const EXTENSION_RESTART_POLL_MS = 5_000;
|
|
260
260
|
const EXTENSION_PROBE_TIMEOUT_MS = 4_000;
|
|
261
261
|
const PROFILE_CLOSE_TIMEOUT_MS = 5_000;
|
|
262
|
+
const PARK_WINDOW_POLL_MS = 250;
|
|
263
|
+
const PARK_WINDOW_ATTEMPTS = 20;
|
|
264
|
+
/** Upper bound on waiting for a restore script to finish before the next taskbar transition. */
|
|
265
|
+
const TASKBAR_RESTORE_WAIT_MS = 10_000;
|
|
262
266
|
const EXTENSION_PAGE_CLAIM_MS = 300;
|
|
263
267
|
export class BrowserViewManager {
|
|
264
268
|
emit;
|
|
@@ -266,6 +270,9 @@ export class BrowserViewManager {
|
|
|
266
270
|
options;
|
|
267
271
|
sessions = new Map();
|
|
268
272
|
desired = new Map();
|
|
273
|
+
// A desktop viewport the agent chose with browser.panel resize. It wins over the panel's own size
|
|
274
|
+
// until the agent resets it or the session is released; the panel letterboxes the frames meanwhile.
|
|
275
|
+
agentViewports = new Map();
|
|
269
276
|
displayScale = 1;
|
|
270
277
|
launching = new Map();
|
|
271
278
|
runtime = { state: 'checking' };
|
|
@@ -283,6 +290,12 @@ export class BrowserViewManager {
|
|
|
283
290
|
restartingProfiles = new Map();
|
|
284
291
|
restoring = new Map();
|
|
285
292
|
restartPoll;
|
|
293
|
+
/** The taskbar watcher holding each parked browser's real window out of the taskbar, keyed by its browser object. */
|
|
294
|
+
taskbarWatchers = new WeakMap();
|
|
295
|
+
/** A launch park still looking for its window, keyed by its browser object; an explicit move cancels it. */
|
|
296
|
+
pendingParks = new WeakMap();
|
|
297
|
+
/** The taskbar transition under way for each browser, so overlapping requests order after it. */
|
|
298
|
+
taskbarQueue = new WeakMap();
|
|
286
299
|
closed = false;
|
|
287
300
|
constructor(emit, launchBrowser, options = {}) {
|
|
288
301
|
this.emit = emit;
|
|
@@ -497,15 +510,102 @@ export class BrowserViewManager {
|
|
|
497
510
|
const session = browser?.newBrowserCDPSession?.();
|
|
498
511
|
if (!session)
|
|
499
512
|
return;
|
|
513
|
+
const pending = { cancelled: false };
|
|
514
|
+
this.pendingParks.set(browser, pending);
|
|
500
515
|
void Promise.resolve().then(() => session).then(async (cdp) => {
|
|
501
|
-
const windowId = await this.
|
|
502
|
-
if (windowId === undefined)
|
|
516
|
+
const windowId = await this.windowIdWhenPresent(cdp);
|
|
517
|
+
if (windowId === undefined || pending.cancelled)
|
|
503
518
|
return;
|
|
504
519
|
await cdp.send('Browser.setWindowBounds', { windowId, bounds: { windowState: 'normal', ...VIEW_OFFSCREEN_POSITION } });
|
|
505
|
-
|
|
520
|
+
if (pending.cancelled)
|
|
521
|
+
return;
|
|
522
|
+
// A parked window is still a taskbar button and an Alt-Tab entry on Windows;
|
|
523
|
+
// the watcher holds it out of both while it is offscreen (the pane shows the
|
|
524
|
+
// page by screencasting it, so the window needs no taskbar presence), and
|
|
525
|
+
// stops when the user asks to see the window on screen.
|
|
526
|
+
await this.setTaskbarHidden(browser, cdp, true);
|
|
527
|
+
}).catch(() => { }).finally(() => {
|
|
528
|
+
if (this.pendingParks.get(browser) === pending)
|
|
529
|
+
this.pendingParks.delete(browser);
|
|
530
|
+
});
|
|
506
531
|
}
|
|
507
532
|
catch { /* same: never let window parking break the launch */ }
|
|
508
533
|
}
|
|
534
|
+
/**
|
|
535
|
+
* An isolated launch starts with no web contents, and the real window only exists
|
|
536
|
+
* once a tab does; the park is worth asserting on that window, so wait briefly for
|
|
537
|
+
* it instead of giving up at launch time. A persistent launch already has its blank
|
|
538
|
+
* page at launch and lands on the first attempt.
|
|
539
|
+
*/
|
|
540
|
+
async windowIdWhenPresent(cdp) {
|
|
541
|
+
for (let attempt = 0; attempt < PARK_WINDOW_ATTEMPTS; attempt++) {
|
|
542
|
+
const windowId = await this.windowIdFor(cdp, undefined);
|
|
543
|
+
if (windowId !== undefined)
|
|
544
|
+
return windowId;
|
|
545
|
+
await new Promise(resolve => { const timer = setTimeout(resolve, PARK_WINDOW_POLL_MS); timer.unref?.(); });
|
|
546
|
+
}
|
|
547
|
+
return undefined;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Holds a parked browser's real window out of the taskbar and the Alt-Tab list, and
|
|
551
|
+
* returns it to normal window behaviour when the user asks to see it. The watcher is
|
|
552
|
+
* keyed by the browser object, so sessions of one browser share one watcher.
|
|
553
|
+
*/
|
|
554
|
+
async setTaskbarHidden(browser, cdp, hidden) {
|
|
555
|
+
if (!browser)
|
|
556
|
+
return;
|
|
557
|
+
// One transition at a time per browser: two overlapping requests could both pass
|
|
558
|
+
// the watcher check while the pid lookup resolves and each start a watcher, and a
|
|
559
|
+
// later release would only kill the recorded one while an orphan kept re-hiding
|
|
560
|
+
// the window. A request that overlaps waits for the in-flight one and decides on
|
|
561
|
+
// its result instead.
|
|
562
|
+
const base = (this.taskbarQueue.get(browser) ?? Promise.resolve()).catch(() => { });
|
|
563
|
+
const run = base.then(() => this.taskbarTransition(browser, cdp, hidden)).catch(() => { });
|
|
564
|
+
this.taskbarQueue.set(browser, run);
|
|
565
|
+
try {
|
|
566
|
+
await run;
|
|
567
|
+
}
|
|
568
|
+
finally {
|
|
569
|
+
if (this.taskbarQueue.get(browser) === run)
|
|
570
|
+
this.taskbarQueue.delete(browser);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
/** One serialized taskbar transition: start (hidden) or tear down (shown) the watcher for this browser. */
|
|
574
|
+
async taskbarTransition(browser, cdp, hidden) {
|
|
575
|
+
if (hidden) {
|
|
576
|
+
if (this.taskbarWatchers.has(browser))
|
|
577
|
+
return;
|
|
578
|
+
const pids = await browserPidsFromCdp(cdp).catch(() => []);
|
|
579
|
+
if (!pids.length)
|
|
580
|
+
return;
|
|
581
|
+
const watcher = taskbarStyleApply(pids, true);
|
|
582
|
+
if (watcher)
|
|
583
|
+
this.taskbarWatchers.set(browser, watcher);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const watcher = this.taskbarWatchers.get(browser);
|
|
587
|
+
if (!watcher)
|
|
588
|
+
return;
|
|
589
|
+
this.taskbarWatchers.delete(browser);
|
|
590
|
+
try {
|
|
591
|
+
watcher.kill();
|
|
592
|
+
}
|
|
593
|
+
catch { /* already gone */ }
|
|
594
|
+
// The taskbar does not refresh on ownership changes alone; ask it to put the
|
|
595
|
+
// button back explicitly so a shown browser is a normal window again at once.
|
|
596
|
+
const pids = await browserPidsFromCdp(cdp).catch(() => []);
|
|
597
|
+
if (!pids.length)
|
|
598
|
+
return;
|
|
599
|
+
const restore = taskbarStyleApply(pids, false);
|
|
600
|
+
// The restore runs as its own PowerShell process, so wait for it before the
|
|
601
|
+
// transition is done: a quick Hide would otherwise start its watcher while the
|
|
602
|
+
// restore's unconditional AddTab was still in flight, and that AddTab would put the
|
|
603
|
+
// parked window back into the taskbar. A hung restore only delays the next
|
|
604
|
+
// transition, bounded by the timeout below.
|
|
605
|
+
if (restore?.exit) {
|
|
606
|
+
await Promise.race([restore.exit, new Promise(resolve => { const timer = setTimeout(resolve, TASKBAR_RESTORE_WAIT_MS); timer.unref?.(); })]);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
509
609
|
/**
|
|
510
610
|
* Finds the id of the window that should be moved. The precise way is the target
|
|
511
611
|
* id of the tab the user is looking at; without one the browser target itself has
|
|
@@ -634,6 +734,13 @@ export class BrowserViewManager {
|
|
|
634
734
|
const session = this.sessions.get(sessionId);
|
|
635
735
|
if (!session || session.closing)
|
|
636
736
|
throw new Error('No browser tab is open for this session');
|
|
737
|
+
// An explicit move from the user cancels any launch park still looking for its
|
|
738
|
+
// window: the park would otherwise move the window back offscreen and hide it from
|
|
739
|
+
// the taskbar after this move ran, leaving the panel saying shown while the window
|
|
740
|
+
// sat parked.
|
|
741
|
+
const pending = this.pendingParks.get(this.browserFor(session));
|
|
742
|
+
if (pending)
|
|
743
|
+
pending.cancelled = true;
|
|
637
744
|
this.scheduleIdleClose(sessionId, session);
|
|
638
745
|
const cdp = await this.browserCdpFor(session);
|
|
639
746
|
const active = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
@@ -641,6 +748,9 @@ export class BrowserViewManager {
|
|
|
641
748
|
if (windowId === undefined)
|
|
642
749
|
throw new Error('The browser window could not be found to move');
|
|
643
750
|
await cdp.send('Browser.setWindowBounds', { windowId, bounds: { windowState: 'normal', ...position } });
|
|
751
|
+
// Showing the window gives it its normal window behaviour back (a taskbar button
|
|
752
|
+
// of its own); parking it again takes the button and the Alt-Tab entry away.
|
|
753
|
+
await this.setTaskbarHidden(this.browserFor(session), cdp, !activate);
|
|
644
754
|
if (activate) {
|
|
645
755
|
// Showing the window also raises the tab the panel is showing: the manager's
|
|
646
756
|
// selection and the native browser's selected tab are separate, so without
|
|
@@ -1313,13 +1423,11 @@ export class BrowserViewManager {
|
|
|
1313
1423
|
const inflight = this.launching.get(sessionId);
|
|
1314
1424
|
if (inflight)
|
|
1315
1425
|
return await inflight;
|
|
1316
|
-
if (this.sessions.size + this.launching.size >= VIEW_SESSION_LIMIT)
|
|
1317
|
-
throw new Error('Too many open panel browsers; close one first');
|
|
1318
1426
|
if (this.closed)
|
|
1319
1427
|
throw new Error('Application is shutting down');
|
|
1320
1428
|
const starting = (async () => {
|
|
1321
1429
|
const desired = this.desired.get(sessionId);
|
|
1322
|
-
const viewport =
|
|
1430
|
+
const viewport = this.viewportFor(sessionId, desired);
|
|
1323
1431
|
const opened = await this.openBrowserFor(sessionId, viewport, desired?.scale ?? this.displayScale);
|
|
1324
1432
|
if (this.closed) {
|
|
1325
1433
|
await this.disposeBrowser({ ...opened, tabs: new Map() });
|
|
@@ -1332,7 +1440,7 @@ export class BrowserViewManager {
|
|
|
1332
1440
|
const current = this.desired.get(sessionId);
|
|
1333
1441
|
const session = {
|
|
1334
1442
|
...opened, tabs: new Map(), activeTabId: undefined, pendingTabs: 0,
|
|
1335
|
-
viewport: current
|
|
1443
|
+
viewport: current ? this.viewportFor(sessionId, current) : viewport,
|
|
1336
1444
|
mode: current?.mode ?? 'desktop',
|
|
1337
1445
|
scale: current?.scale ?? this.displayScale,
|
|
1338
1446
|
streaming: current !== undefined, quality: current?.quality ?? VIEW_STREAM_QUALITY, idleTimer: undefined,
|
|
@@ -1575,9 +1683,16 @@ export class BrowserViewManager {
|
|
|
1575
1683
|
if (options.scale !== undefined)
|
|
1576
1684
|
this.displayScale = scale;
|
|
1577
1685
|
this.desired.set(sessionId, { viewport, quality, mode, scale });
|
|
1686
|
+
await this.applyStream(sessionId);
|
|
1687
|
+
}
|
|
1688
|
+
/** Applies the panel's last stream request, with the agent's viewport in place of the panel's size when it set one. */
|
|
1689
|
+
async applyStream(sessionId) {
|
|
1690
|
+
const desired = this.desired.get(sessionId);
|
|
1578
1691
|
const session = this.sessions.get(sessionId);
|
|
1579
|
-
if (!session)
|
|
1692
|
+
if (!desired || !session)
|
|
1580
1693
|
return;
|
|
1694
|
+
const { mode, quality, scale } = desired;
|
|
1695
|
+
const viewport = this.viewportFor(sessionId, desired);
|
|
1581
1696
|
session.streaming = true;
|
|
1582
1697
|
const modeChanged = mode !== session.mode;
|
|
1583
1698
|
const resized = viewport.width !== session.viewport.width || viewport.height !== session.viewport.height
|
|
@@ -1613,6 +1728,44 @@ export class BrowserViewManager {
|
|
|
1613
1728
|
if (reattached)
|
|
1614
1729
|
await this.captureFrame(sessionId, session, active);
|
|
1615
1730
|
}
|
|
1731
|
+
viewportFor(sessionId, desired) {
|
|
1732
|
+
if (desired?.mode === 'mobile')
|
|
1733
|
+
return { ...VIEW_MOBILE_VIEWPORT };
|
|
1734
|
+
const chosen = this.agentViewports.get(sessionId);
|
|
1735
|
+
return chosen ? { ...chosen } : desired?.viewport ?? clampViewport(undefined, undefined);
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Sets the desktop viewport the agent browses at, or with no size returns it to the panel's own size.
|
|
1739
|
+
* A page too crowded at the panel's width (collapsed menus, overlapping controls) gets room this way;
|
|
1740
|
+
* the panel shows the larger page scaled to fit. The user's mobile mode is theirs and is not overridden.
|
|
1741
|
+
*/
|
|
1742
|
+
async agentResize(sessionId, size) {
|
|
1743
|
+
const desired = this.desired.get(sessionId);
|
|
1744
|
+
const session = this.sessions.get(sessionId);
|
|
1745
|
+
if (size && (session?.mode ?? desired?.mode) === 'mobile') {
|
|
1746
|
+
throw new Error('The Browser panel is in mobile viewport mode (390x844), which the user chose; ask them to switch it back to desktop before resizing.');
|
|
1747
|
+
}
|
|
1748
|
+
if (size)
|
|
1749
|
+
this.agentViewports.set(sessionId, { width: size.width, height: size.height });
|
|
1750
|
+
else
|
|
1751
|
+
this.agentViewports.delete(sessionId);
|
|
1752
|
+
if (session && desired)
|
|
1753
|
+
await this.applyStream(sessionId);
|
|
1754
|
+
else if (session) {
|
|
1755
|
+
// A hidden panel keeps the mode it last streamed in, and mobile emulation stays at its fixed size.
|
|
1756
|
+
const viewport = session.mode === 'mobile' ? { ...VIEW_MOBILE_VIEWPORT } : this.viewportFor(sessionId, undefined);
|
|
1757
|
+
if (viewport.width !== session.viewport.width || viewport.height !== session.viewport.height) {
|
|
1758
|
+
session.viewport = viewport;
|
|
1759
|
+
const active = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
1760
|
+
if (active) {
|
|
1761
|
+
active.budget = undefined;
|
|
1762
|
+
await this.queueViewportMode(session, active);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
const viewport = this.sessions.get(sessionId)?.viewport ?? this.viewportFor(sessionId, desired);
|
|
1767
|
+
return { viewport: { ...viewport }, follows: this.agentViewports.has(sessionId) ? 'agent' : 'panel' };
|
|
1768
|
+
}
|
|
1616
1769
|
async input(sessionId, payload) {
|
|
1617
1770
|
const session = this.sessions.get(sessionId);
|
|
1618
1771
|
if (!session)
|
|
@@ -1891,6 +2044,7 @@ export class BrowserViewManager {
|
|
|
1891
2044
|
if (restoring)
|
|
1892
2045
|
restoring.cancelled = true;
|
|
1893
2046
|
this.incognito.delete(sessionId);
|
|
2047
|
+
this.agentViewports.delete(sessionId);
|
|
1894
2048
|
try {
|
|
1895
2049
|
await this.closeSession(sessionId, reason);
|
|
1896
2050
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A running taskbar style change. A watcher keeps running until killed; a restore is a
|
|
3
|
+
* one-shot whose `exit` resolves when its PowerShell process is done (the caller waits
|
|
4
|
+
* for it so a following transition cannot overlap the restore).
|
|
5
|
+
*/
|
|
6
|
+
export interface TaskbarWatcher {
|
|
7
|
+
kill(): void;
|
|
8
|
+
exit?: Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
/** The pids of the browser processes behind one CDP connection: the browser process is the one that owns the window. */
|
|
11
|
+
export declare function browserPidsFromCdp(cdp: any): Promise<number[]>;
|
|
12
|
+
/** The full PowerShell script for one watcher; empty when there is nothing to do. */
|
|
13
|
+
export declare function taskbarWatcherScript(pids: number[]): string;
|
|
14
|
+
/** The one-shot script that asks the taskbar to put the button back. */
|
|
15
|
+
export declare function taskbarRestoreScript(pids: number[]): string;
|
|
16
|
+
type Spawner = (file: string, args: string[]) => {
|
|
17
|
+
kill(): void;
|
|
18
|
+
exit?: Promise<void>;
|
|
19
|
+
} | undefined;
|
|
20
|
+
/** Test seam: stands in for the watcher process spawn. */
|
|
21
|
+
export declare function setTaskbarStyleSpawner(spawner: Spawner | undefined): void;
|
|
22
|
+
export declare function applyWindowsTaskbarStyle(pids: number[], hidden: boolean): TaskbarWatcher | undefined;
|
|
23
|
+
/** Test seam: stands in for the style change so view tests never spawn PowerShell. */
|
|
24
|
+
export declare function setTaskbarStyleApply(apply: (pids: number[], hidden: boolean) => TaskbarWatcher | undefined): void;
|
|
25
|
+
/** Starts (hidden=true) or tears down (hidden=false) the taskbar watcher for these pids. */
|
|
26
|
+
export declare function taskbarStyleApply(pids: number[], hidden: boolean): TaskbarWatcher | undefined;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
/**
|
|
3
|
+
* The panel's parked browser is a real Chromium window held offscreen, and Windows
|
|
4
|
+
* would still give it a taskbar button and an Alt-Tab entry. Making it a tool window
|
|
5
|
+
* does not last: Chromium re-applies its own window styles within a second, clearing
|
|
6
|
+
* the bit again. What does last is ownership: a window whose owner is not visible
|
|
7
|
+
* gets no taskbar button and is excluded from Alt-Tab, and Chromium never touches the
|
|
8
|
+
* owner. So this module runs a tiny watcher process whose only jobs are to hold a
|
|
9
|
+
* hidden proxy window and to set it as the owner of the browser's windows until the
|
|
10
|
+
* manager releases it (the user asked to see the browser) or the browser is gone.
|
|
11
|
+
*/
|
|
12
|
+
const WATCHER_SCRIPT = `
|
|
13
|
+
$ErrorActionPreference = 'Stop'
|
|
14
|
+
Add-Type -TypeDefinition @'
|
|
15
|
+
using System; using System.Text; using System.Threading; using System.Runtime.InteropServices;
|
|
16
|
+
public static class AndorraTaskbarWatcher
|
|
17
|
+
{
|
|
18
|
+
delegate bool EnumProc(IntPtr hWnd, IntPtr lParam);
|
|
19
|
+
delegate IntPtr WndProc(IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam);
|
|
20
|
+
|
|
21
|
+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
22
|
+
struct WNDCLASS { public uint style; public IntPtr wndProc; public int clsExtra, wndExtra; public IntPtr instance, icon, cursor, background; public string menuName; public string className; }
|
|
23
|
+
|
|
24
|
+
[DllImport("user32.dll")] static extern bool EnumWindows(EnumProc callback, IntPtr lParam);
|
|
25
|
+
[DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
|
|
26
|
+
[DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern int GetClassName(IntPtr hWnd, StringBuilder name, int max);
|
|
27
|
+
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtrW")] static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int index);
|
|
28
|
+
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtrW")] static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int index, IntPtr value);
|
|
29
|
+
[DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern ushort RegisterClassW(ref WNDCLASS wndClass);
|
|
30
|
+
[DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern IntPtr CreateWindowExW(uint exStyle, string className, string name, uint style, int x, int y, int width, int height, IntPtr parent, IntPtr menu, IntPtr instance, IntPtr param);
|
|
31
|
+
[DllImport("user32.dll")] static extern bool DestroyWindow(IntPtr hWnd);
|
|
32
|
+
[DllImport("user32.dll")] static extern IntPtr DefWindowProcW(IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam);
|
|
33
|
+
[DllImport("user32.dll")] static extern bool PeekMessageW(out MSG message, IntPtr hwnd, uint min, uint max, uint remove);
|
|
34
|
+
[DllImport("user32.dll")] static extern bool TranslateMessage(ref MSG message);
|
|
35
|
+
[DllImport("user32.dll")] static extern IntPtr DispatchMessageW(ref MSG message);
|
|
36
|
+
[DllImport("user32.dll")] static extern int MsgWaitForMultipleObjectsEx(int count, IntPtr[] handles, uint timeout, uint wakeMask, uint flags);
|
|
37
|
+
|
|
38
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
39
|
+
struct MSG { public IntPtr hwnd; public uint message; public IntPtr wParam; public IntPtr lParam; public uint time; public int pointX; public int pointY; }
|
|
40
|
+
|
|
41
|
+
const uint QS_ALLINPUT = 0x04FF;
|
|
42
|
+
const uint MWMO_INPUTAVAILABLE = 0x0004;
|
|
43
|
+
const uint PM_REMOVE = 0x0001;
|
|
44
|
+
|
|
45
|
+
const int GWL_HWNDPARENT = -8;
|
|
46
|
+
const int IDLE_TICKS_BEFORE_EXIT = 15;
|
|
47
|
+
|
|
48
|
+
static WndProc messageLoop = DefWindowProcW;
|
|
49
|
+
static IntPtr proxy;
|
|
50
|
+
|
|
51
|
+
static bool OwnsBrowserWindows(long[] processes)
|
|
52
|
+
{
|
|
53
|
+
bool found = false;
|
|
54
|
+
for (int i = 0; i < processes.Length; i++)
|
|
55
|
+
{
|
|
56
|
+
long pid = processes[i];
|
|
57
|
+
EnumWindows(delegate(IntPtr hWnd, IntPtr lParam)
|
|
58
|
+
{
|
|
59
|
+
uint owner;
|
|
60
|
+
GetWindowThreadProcessId(hWnd, out owner);
|
|
61
|
+
if (owner != (uint)pid) return true;
|
|
62
|
+
StringBuilder name = new StringBuilder(64);
|
|
63
|
+
GetClassName(hWnd, name, 64);
|
|
64
|
+
if (!name.ToString().StartsWith("Chrome_WidgetWin_1", StringComparison.Ordinal)) return true;
|
|
65
|
+
found = true;
|
|
66
|
+
if (GetWindowLongPtr(hWnd, GWL_HWNDPARENT) != proxy) SetWindowLongPtr(hWnd, GWL_HWNDPARENT, proxy);
|
|
67
|
+
return true;
|
|
68
|
+
}, IntPtr.Zero);
|
|
69
|
+
}
|
|
70
|
+
return found;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public static void Watch(long[] processes)
|
|
74
|
+
{
|
|
75
|
+
if (processes == null || processes.Length == 0) return;
|
|
76
|
+
WNDCLASS wndClass = new WNDCLASS();
|
|
77
|
+
wndClass.wndProc = Marshal.GetFunctionPointerForDelegate(messageLoop);
|
|
78
|
+
wndClass.className = "AndorraOwnerProxy";
|
|
79
|
+
wndClass.instance = Marshal.GetHINSTANCE(typeof(AndorraTaskbarWatcher).Module);
|
|
80
|
+
if (RegisterClassW(ref wndClass) == 0) return;
|
|
81
|
+
proxy = CreateWindowExW(0, "AndorraOwnerProxy", "andorra-owner-proxy", 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, wndClass.instance, IntPtr.Zero);
|
|
82
|
+
if (proxy == IntPtr.Zero) return;
|
|
83
|
+
try
|
|
84
|
+
{
|
|
85
|
+
int idleTicks = 0;
|
|
86
|
+
MSG message;
|
|
87
|
+
while (idleTicks < IDLE_TICKS_BEFORE_EXIT)
|
|
88
|
+
{
|
|
89
|
+
// As the owner of Chromium's windows the proxy shares their input queues,
|
|
90
|
+
// so this thread must service the proxy's window messages: an unresponsive
|
|
91
|
+
// owner window can stall browser focus/activation and leave synchronous
|
|
92
|
+
// broadcasts to it waiting for the sender to time out. Thread.Sleep does
|
|
93
|
+
// not pump messages, so wait for input or the next poll tick and drain
|
|
94
|
+
// whatever arrived before re-checking the browser's windows.
|
|
95
|
+
while (PeekMessageW(out message, IntPtr.Zero, 0, 0, PM_REMOVE))
|
|
96
|
+
{
|
|
97
|
+
TranslateMessage(ref message);
|
|
98
|
+
DispatchMessageW(ref message);
|
|
99
|
+
}
|
|
100
|
+
if (OwnsBrowserWindows(processes)) idleTicks = 0;
|
|
101
|
+
else idleTicks++;
|
|
102
|
+
MsgWaitForMultipleObjectsEx(0, null, 1000, QS_ALLINPUT, MWMO_INPUTAVAILABLE);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
finally { DestroyWindow(proxy); }
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
'@
|
|
109
|
+
[AndorraTaskbarWatcher]::Watch([long[]]@(__PIDS__))
|
|
110
|
+
`;
|
|
111
|
+
/**
|
|
112
|
+
* What runs when the manager asks to see the browser again: the taskbar only notices
|
|
113
|
+
* an owner change on window events, so the button is put back explicitly through
|
|
114
|
+
* ITaskbarList.AddTab instead of waiting for a refresh that may never come.
|
|
115
|
+
*/
|
|
116
|
+
const RESTORE_SCRIPT = `
|
|
117
|
+
$ErrorActionPreference = 'Stop'
|
|
118
|
+
Add-Type -TypeDefinition @'
|
|
119
|
+
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices;
|
|
120
|
+
public static class AndorraTaskbarRestore
|
|
121
|
+
{
|
|
122
|
+
[ComImport, Guid("56FDF342-FD6D-11d0-958A-006097C9A090"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
123
|
+
interface ITaskbarList
|
|
124
|
+
{
|
|
125
|
+
void HrInit();
|
|
126
|
+
void AddTab(IntPtr hwnd);
|
|
127
|
+
void DeleteTab(IntPtr hwnd);
|
|
128
|
+
void ActivateTab(IntPtr hwnd);
|
|
129
|
+
void SetActiveAlt(IntPtr hwnd);
|
|
130
|
+
}
|
|
131
|
+
[ComImport, Guid("56FDF344-FD6D-11d0-958A-006097C9A090")]
|
|
132
|
+
class TaskbarList { }
|
|
133
|
+
|
|
134
|
+
delegate bool EnumProc(IntPtr hWnd, IntPtr lParam);
|
|
135
|
+
[DllImport("user32.dll")] static extern bool EnumWindows(EnumProc callback, IntPtr lParam);
|
|
136
|
+
[DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
|
|
137
|
+
[DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern int GetClassName(IntPtr hWnd, StringBuilder name, int max);
|
|
138
|
+
|
|
139
|
+
public static void Restore(long[] processes)
|
|
140
|
+
{
|
|
141
|
+
if (processes == null || processes.Length == 0) return;
|
|
142
|
+
List<IntPtr> windows = new List<IntPtr>();
|
|
143
|
+
for (int i = 0; i < processes.Length; i++)
|
|
144
|
+
{
|
|
145
|
+
long pid = processes[i];
|
|
146
|
+
EnumWindows(delegate(IntPtr hWnd, IntPtr lParam)
|
|
147
|
+
{
|
|
148
|
+
uint owner;
|
|
149
|
+
GetWindowThreadProcessId(hWnd, out owner);
|
|
150
|
+
if (owner != (uint)pid) return true;
|
|
151
|
+
StringBuilder name = new StringBuilder(64);
|
|
152
|
+
GetClassName(hWnd, name, 64);
|
|
153
|
+
if (name.ToString().StartsWith("Chrome_WidgetWin_1", StringComparison.Ordinal)) windows.Add(hWnd);
|
|
154
|
+
return true;
|
|
155
|
+
}, IntPtr.Zero);
|
|
156
|
+
}
|
|
157
|
+
if (windows.Count == 0) return;
|
|
158
|
+
var list = (ITaskbarList)(object)new TaskbarList();
|
|
159
|
+
list.HrInit();
|
|
160
|
+
for (int i = 0; i < windows.Count; i++) list.AddTab(windows[i]);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
'@
|
|
164
|
+
[AndorraTaskbarRestore]::Restore([long[]]@(__PIDS__))
|
|
165
|
+
`;
|
|
166
|
+
/** The pids of the browser processes behind one CDP connection: the browser process is the one that owns the window. */
|
|
167
|
+
export async function browserPidsFromCdp(cdp) {
|
|
168
|
+
const info = await cdp.send('SystemInfo.getProcessInfo');
|
|
169
|
+
const entries = Array.isArray(info?.processInfo) ? info.processInfo : [];
|
|
170
|
+
return entries
|
|
171
|
+
.filter((entry) => entry?.type === 'browser'
|
|
172
|
+
&& Number.isSafeInteger(entry.id) && entry.id > 0)
|
|
173
|
+
.map((entry) => entry.id);
|
|
174
|
+
}
|
|
175
|
+
/** The full PowerShell script for one watcher; empty when there is nothing to do. */
|
|
176
|
+
export function taskbarWatcherScript(pids) {
|
|
177
|
+
return styleScript(pids, WATCHER_SCRIPT);
|
|
178
|
+
}
|
|
179
|
+
/** The one-shot script that asks the taskbar to put the button back. */
|
|
180
|
+
export function taskbarRestoreScript(pids) {
|
|
181
|
+
return styleScript(pids, RESTORE_SCRIPT);
|
|
182
|
+
}
|
|
183
|
+
const styleScript = (pids, template) => {
|
|
184
|
+
const targets = (Array.isArray(pids) ? pids : [])
|
|
185
|
+
.filter(pid => Number.isSafeInteger(pid) && pid > 0)
|
|
186
|
+
.map(String).join(',');
|
|
187
|
+
if (!targets)
|
|
188
|
+
return '';
|
|
189
|
+
return template.replace('__PIDS__', targets);
|
|
190
|
+
};
|
|
191
|
+
let taskbarStyleSpawnerImpl = undefined;
|
|
192
|
+
/** Test seam: stands in for the watcher process spawn. */
|
|
193
|
+
export function setTaskbarStyleSpawner(spawner) {
|
|
194
|
+
taskbarStyleSpawnerImpl = spawner;
|
|
195
|
+
}
|
|
196
|
+
function defaultSpawner(file, args) {
|
|
197
|
+
try {
|
|
198
|
+
const child = spawn(file, args, { stdio: 'ignore', windowsHide: true });
|
|
199
|
+
child.once('error', () => { });
|
|
200
|
+
child.unref?.();
|
|
201
|
+
const exit = new Promise(resolve => {
|
|
202
|
+
child.once('close', () => resolve());
|
|
203
|
+
child.once('error', () => resolve());
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
kill: () => { try {
|
|
207
|
+
child.kill();
|
|
208
|
+
}
|
|
209
|
+
catch { /* already gone */ } },
|
|
210
|
+
exit,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
export function applyWindowsTaskbarStyle(pids, hidden) {
|
|
218
|
+
if (process.platform !== 'win32')
|
|
219
|
+
return undefined;
|
|
220
|
+
const spawner = taskbarStyleSpawnerImpl ?? defaultSpawner;
|
|
221
|
+
if (!hidden) {
|
|
222
|
+
const script = taskbarRestoreScript(pids);
|
|
223
|
+
if (!script)
|
|
224
|
+
return undefined;
|
|
225
|
+
return spawner('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', encodeCommand(script)]);
|
|
226
|
+
}
|
|
227
|
+
const script = taskbarWatcherScript(pids);
|
|
228
|
+
if (!script)
|
|
229
|
+
return undefined;
|
|
230
|
+
const child = spawner('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', encodeCommand(script)]);
|
|
231
|
+
if (!child)
|
|
232
|
+
return undefined;
|
|
233
|
+
return child;
|
|
234
|
+
}
|
|
235
|
+
const encodeCommand = (script) => Buffer.from(script, 'utf16le').toString('base64');
|
|
236
|
+
let taskbarStyleImpl = applyWindowsTaskbarStyle;
|
|
237
|
+
/** Test seam: stands in for the style change so view tests never spawn PowerShell. */
|
|
238
|
+
export function setTaskbarStyleApply(apply) {
|
|
239
|
+
taskbarStyleImpl = apply;
|
|
240
|
+
}
|
|
241
|
+
/** Starts (hidden=true) or tears down (hidden=false) the taskbar watcher for these pids. */
|
|
242
|
+
export function taskbarStyleApply(pids, hidden) {
|
|
243
|
+
return taskbarStyleImpl(pids, hidden);
|
|
244
|
+
}
|
|
@@ -33,5 +33,6 @@ export declare function parseClaudeAuxiliaryResponse(output: string, maxTokens:
|
|
|
33
33
|
export declare function claudeRequestBlocks(messages: GenerateRequest['messages'], tools: GenerateRequest['tools']): object[];
|
|
34
34
|
export declare function createClaudeAdapter(_config: {
|
|
35
35
|
model: string;
|
|
36
|
+
reasoningEffort?: string;
|
|
36
37
|
}, dependencies?: ClaudeDependencies): ModelAdapter;
|
|
37
38
|
export {};
|