pi-agent-browser-native 0.2.48 → 0.2.49
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/CHANGELOG.md +17 -0
- package/README.md +16 -6
- package/dist/extensions/agent-browser/index.js +785 -0
- package/dist/extensions/agent-browser/lib/argv-descriptor.js +71 -0
- package/dist/extensions/agent-browser/lib/argv-grammar.js +121 -0
- package/dist/extensions/agent-browser/lib/bash-guard.js +190 -0
- package/dist/extensions/agent-browser/lib/command-policy.js +85 -0
- package/dist/extensions/agent-browser/lib/command-taxonomy.js +302 -0
- package/dist/extensions/agent-browser/lib/config-policy.js +686 -0
- package/dist/extensions/agent-browser/lib/config.js +122 -0
- package/dist/extensions/agent-browser/lib/electron/cdp.js +51 -0
- package/dist/extensions/agent-browser/lib/electron/cleanup.js +212 -0
- package/dist/extensions/agent-browser/lib/electron/discovery.js +633 -0
- package/dist/extensions/agent-browser/lib/electron/launch.js +351 -0
- package/{extensions/agent-browser/lib/electron/text.ts → dist/extensions/agent-browser/lib/electron/text.js} +5 -5
- package/dist/extensions/agent-browser/lib/executable-path.js +20 -0
- package/dist/extensions/agent-browser/lib/fs-utils.js +18 -0
- package/dist/extensions/agent-browser/lib/input-modes/electron.js +165 -0
- package/dist/extensions/agent-browser/lib/input-modes/job.js +519 -0
- package/dist/extensions/agent-browser/lib/input-modes/lookups.js +440 -0
- package/dist/extensions/agent-browser/lib/input-modes/params.js +164 -0
- package/dist/extensions/agent-browser/lib/input-modes/semantic-action.js +119 -0
- package/dist/extensions/agent-browser/lib/input-modes/shared.js +42 -0
- package/dist/extensions/agent-browser/lib/input-modes/types.js +21 -0
- package/dist/extensions/agent-browser/lib/input-modes.js +10 -0
- package/dist/extensions/agent-browser/lib/json-schema.js +58 -0
- package/dist/extensions/agent-browser/lib/launch-scoped-flags.js +59 -0
- package/dist/extensions/agent-browser/lib/navigation-policy.js +83 -0
- package/dist/extensions/agent-browser/lib/orchestration/batch-stdin.js +62 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/artifact-paths.js +39 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/click-dispatch.js +276 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/diagnostics.js +909 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result.js +443 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/index.js +47 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/direct-anchor-download.js +141 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/network-page-filter.js +108 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/scroll-shims.js +112 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-filter.js +158 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/wait-timeouts.js +54 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare.js +762 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output.js +491 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prompt-guards.js +40 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-artifacts.js +5 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state.js +731 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/types.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/index.js +718 -0
- package/dist/extensions/agent-browser/lib/orchestration/input-plan.js +247 -0
- package/dist/extensions/agent-browser/lib/orchestration/output-file.js +68 -0
- package/{extensions/agent-browser/lib/parsing.ts → dist/extensions/agent-browser/lib/parsing.js} +12 -11
- package/dist/extensions/agent-browser/lib/pi-tool-rendering.js +241 -0
- package/dist/extensions/agent-browser/lib/playbook.js +121 -0
- package/dist/extensions/agent-browser/lib/process.js +448 -0
- package/dist/extensions/agent-browser/lib/prompt-policy.js +91 -0
- package/dist/extensions/agent-browser/lib/results/action-recommendations.js +220 -0
- package/dist/extensions/agent-browser/lib/results/artifact-manifest.js +111 -0
- package/{extensions/agent-browser/lib/results/artifact-state.ts → dist/extensions/agent-browser/lib/results/artifact-state.js} +4 -8
- package/dist/extensions/agent-browser/lib/results/categories.js +76 -0
- package/dist/extensions/agent-browser/lib/results/confirmation.js +63 -0
- package/dist/extensions/agent-browser/lib/results/contracts.js +8 -0
- package/dist/extensions/agent-browser/lib/results/editable-ref-evidence.js +74 -0
- package/dist/extensions/agent-browser/lib/results/envelope.js +166 -0
- package/dist/extensions/agent-browser/lib/results/network-routes.js +92 -0
- package/dist/extensions/agent-browser/lib/results/network.js +73 -0
- package/dist/extensions/agent-browser/lib/results/next-actions.js +72 -0
- package/dist/extensions/agent-browser/lib/results/presentation/artifacts.js +515 -0
- package/dist/extensions/agent-browser/lib/results/presentation/batch.js +397 -0
- package/dist/extensions/agent-browser/lib/results/presentation/browser-profile-recovery.js +55 -0
- package/dist/extensions/agent-browser/lib/results/presentation/common.js +46 -0
- package/dist/extensions/agent-browser/lib/results/presentation/content.js +24 -0
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostics.js +960 -0
- package/dist/extensions/agent-browser/lib/results/presentation/errors.js +205 -0
- package/dist/extensions/agent-browser/lib/results/presentation/large-output.js +134 -0
- package/dist/extensions/agent-browser/lib/results/presentation/navigation.js +159 -0
- package/dist/extensions/agent-browser/lib/results/presentation/registry.js +216 -0
- package/dist/extensions/agent-browser/lib/results/presentation/semantic-action.js +104 -0
- package/dist/extensions/agent-browser/lib/results/presentation/skills.js +152 -0
- package/dist/extensions/agent-browser/lib/results/presentation.js +177 -0
- package/dist/extensions/agent-browser/lib/results/recovery-actions.js +107 -0
- package/dist/extensions/agent-browser/lib/results/recovery-next-actions.js +50 -0
- package/dist/extensions/agent-browser/lib/results/selector-recovery.js +225 -0
- package/{extensions/agent-browser/lib/results/shared.ts → dist/extensions/agent-browser/lib/results/shared.js} +0 -1
- package/dist/extensions/agent-browser/lib/results/snapshot-high-value-controls.js +208 -0
- package/dist/extensions/agent-browser/lib/results/snapshot-refs.js +78 -0
- package/dist/extensions/agent-browser/lib/results/snapshot-segments.js +331 -0
- package/dist/extensions/agent-browser/lib/results/snapshot-spill.js +40 -0
- package/dist/extensions/agent-browser/lib/results/snapshot.js +264 -0
- package/dist/extensions/agent-browser/lib/results/text.js +40 -0
- package/{extensions/agent-browser/lib/results.ts → dist/extensions/agent-browser/lib/results.js} +2 -32
- package/dist/extensions/agent-browser/lib/runtime.js +816 -0
- package/dist/extensions/agent-browser/lib/session-page-state.js +411 -0
- package/dist/extensions/agent-browser/lib/string-enum-schema.js +13 -0
- package/dist/extensions/agent-browser/lib/temp.js +498 -0
- package/dist/extensions/agent-browser/lib/web-search.js +562 -0
- package/docs/RELEASE.md +22 -11
- package/docs/SUPPORT_MATRIX.md +4 -3
- package/package.json +9 -5
- package/scripts/config.mjs +8 -2
- package/scripts/doctor.mjs +8 -7
- package/extensions/agent-browser/index.ts +0 -961
- package/extensions/agent-browser/lib/argv-descriptor.ts +0 -90
- package/extensions/agent-browser/lib/argv-grammar.ts +0 -128
- package/extensions/agent-browser/lib/bash-guard.ts +0 -205
- package/extensions/agent-browser/lib/command-policy.ts +0 -71
- package/extensions/agent-browser/lib/command-taxonomy.ts +0 -336
- package/extensions/agent-browser/lib/config-policy.js +0 -690
- package/extensions/agent-browser/lib/config.ts +0 -211
- package/extensions/agent-browser/lib/electron/cdp.ts +0 -69
- package/extensions/agent-browser/lib/electron/cleanup.ts +0 -235
- package/extensions/agent-browser/lib/electron/discovery.ts +0 -710
- package/extensions/agent-browser/lib/electron/launch.ts +0 -499
- package/extensions/agent-browser/lib/executable-path.ts +0 -19
- package/extensions/agent-browser/lib/fs-utils.ts +0 -18
- package/extensions/agent-browser/lib/input-modes/electron.ts +0 -170
- package/extensions/agent-browser/lib/input-modes/job.ts +0 -527
- package/extensions/agent-browser/lib/input-modes/lookups.ts +0 -447
- package/extensions/agent-browser/lib/input-modes/params.ts +0 -205
- package/extensions/agent-browser/lib/input-modes/semantic-action.ts +0 -127
- package/extensions/agent-browser/lib/input-modes/shared.ts +0 -46
- package/extensions/agent-browser/lib/input-modes/types.ts +0 -225
- package/extensions/agent-browser/lib/input-modes.ts +0 -45
- package/extensions/agent-browser/lib/json-schema.ts +0 -73
- package/extensions/agent-browser/lib/launch-scoped-flags.ts +0 -67
- package/extensions/agent-browser/lib/navigation-policy.ts +0 -95
- package/extensions/agent-browser/lib/orchestration/batch-stdin.ts +0 -65
- package/extensions/agent-browser/lib/orchestration/browser-run/artifact-paths.ts +0 -44
- package/extensions/agent-browser/lib/orchestration/browser-run/click-dispatch.ts +0 -280
- package/extensions/agent-browser/lib/orchestration/browser-run/diagnostics.ts +0 -914
- package/extensions/agent-browser/lib/orchestration/browser-run/final-result.ts +0 -521
- package/extensions/agent-browser/lib/orchestration/browser-run/index.ts +0 -53
- package/extensions/agent-browser/lib/orchestration/browser-run/prepare/direct-anchor-download.ts +0 -158
- package/extensions/agent-browser/lib/orchestration/browser-run/prepare/network-page-filter.ts +0 -116
- package/extensions/agent-browser/lib/orchestration/browser-run/prepare/scroll-shims.ts +0 -147
- package/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-filter.ts +0 -183
- package/extensions/agent-browser/lib/orchestration/browser-run/prepare/wait-timeouts.ts +0 -58
- package/extensions/agent-browser/lib/orchestration/browser-run/prepare.ts +0 -847
- package/extensions/agent-browser/lib/orchestration/browser-run/process-output.ts +0 -559
- package/extensions/agent-browser/lib/orchestration/browser-run/prompt-guards.ts +0 -47
- package/extensions/agent-browser/lib/orchestration/browser-run/session-artifacts.ts +0 -8
- package/extensions/agent-browser/lib/orchestration/browser-run/session-state.ts +0 -868
- package/extensions/agent-browser/lib/orchestration/browser-run/types.ts +0 -565
- package/extensions/agent-browser/lib/orchestration/electron-host/index.ts +0 -855
- package/extensions/agent-browser/lib/orchestration/input-plan.ts +0 -375
- package/extensions/agent-browser/lib/orchestration/output-file.ts +0 -86
- package/extensions/agent-browser/lib/pi-tool-rendering.ts +0 -267
- package/extensions/agent-browser/lib/playbook.ts +0 -142
- package/extensions/agent-browser/lib/process.ts +0 -516
- package/extensions/agent-browser/lib/prompt-policy.ts +0 -105
- package/extensions/agent-browser/lib/results/action-recommendations.ts +0 -264
- package/extensions/agent-browser/lib/results/artifact-manifest.ts +0 -111
- package/extensions/agent-browser/lib/results/categories.ts +0 -106
- package/extensions/agent-browser/lib/results/confirmation.ts +0 -76
- package/extensions/agent-browser/lib/results/contracts.ts +0 -241
- package/extensions/agent-browser/lib/results/editable-ref-evidence.ts +0 -72
- package/extensions/agent-browser/lib/results/envelope.ts +0 -195
- package/extensions/agent-browser/lib/results/network-routes.ts +0 -83
- package/extensions/agent-browser/lib/results/network.ts +0 -78
- package/extensions/agent-browser/lib/results/next-actions.ts +0 -117
- package/extensions/agent-browser/lib/results/presentation/artifacts.ts +0 -588
- package/extensions/agent-browser/lib/results/presentation/batch.ts +0 -450
- package/extensions/agent-browser/lib/results/presentation/browser-profile-recovery.ts +0 -67
- package/extensions/agent-browser/lib/results/presentation/common.ts +0 -53
- package/extensions/agent-browser/lib/results/presentation/content.ts +0 -36
- package/extensions/agent-browser/lib/results/presentation/diagnostics.ts +0 -923
- package/extensions/agent-browser/lib/results/presentation/errors.ts +0 -227
- package/extensions/agent-browser/lib/results/presentation/large-output.ts +0 -182
- package/extensions/agent-browser/lib/results/presentation/navigation.ts +0 -184
- package/extensions/agent-browser/lib/results/presentation/registry.ts +0 -242
- package/extensions/agent-browser/lib/results/presentation/semantic-action.ts +0 -131
- package/extensions/agent-browser/lib/results/presentation/skills.ts +0 -143
- package/extensions/agent-browser/lib/results/presentation.ts +0 -257
- package/extensions/agent-browser/lib/results/recovery-actions.ts +0 -139
- package/extensions/agent-browser/lib/results/recovery-next-actions.ts +0 -71
- package/extensions/agent-browser/lib/results/selector-recovery.ts +0 -320
- package/extensions/agent-browser/lib/results/snapshot-high-value-controls.ts +0 -273
- package/extensions/agent-browser/lib/results/snapshot-refs.ts +0 -100
- package/extensions/agent-browser/lib/results/snapshot-segments.ts +0 -366
- package/extensions/agent-browser/lib/results/snapshot-spill.ts +0 -63
- package/extensions/agent-browser/lib/results/snapshot.ts +0 -329
- package/extensions/agent-browser/lib/results/text.ts +0 -40
- package/extensions/agent-browser/lib/runtime.ts +0 -988
- package/extensions/agent-browser/lib/session-page-state.ts +0 -512
- package/extensions/agent-browser/lib/string-enum-schema.ts +0 -20
- package/extensions/agent-browser/lib/temp.ts +0 -577
- package/extensions/agent-browser/lib/web-search.ts +0 -728
- /package/{extensions/agent-browser/lib/orchestration/browser-run.ts → dist/extensions/agent-browser/lib/orchestration/browser-run.js} +0 -0
|
@@ -1,855 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Purpose: Own wrapper-side Electron host orchestration for agent_browser structured electron input.
|
|
3
|
-
* Responsibilities: Discover Electron apps, inspect/probe/cleanup wrapper-tracked Electron launches, and build Pi-facing Electron host results.
|
|
4
|
-
* Scope: Electron host actions that do not spawn the main upstream browser command; generic agent_browser execution stays in browser-run.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { ChildProcess } from "node:child_process";
|
|
8
|
-
|
|
9
|
-
import { cleanupElectronLaunchResources, inspectElectronLaunchStatus, type ElectronCleanupResult, type ElectronLaunchStatus } from "../../electron/cleanup.js";
|
|
10
|
-
import { discoverElectronApps, type ElectronDiscoveryResult } from "../../electron/discovery.js";
|
|
11
|
-
import type { ElectronCdpTarget, ElectronLaunchRecord } from "../../electron/launch.js";
|
|
12
|
-
import { boundElectronProbeString } from "../../electron/text.js";
|
|
13
|
-
import type { CompiledAgentBrowserElectron } from "../../input-modes.js";
|
|
14
|
-
import { isRecord } from "../../parsing.js";
|
|
15
|
-
import { buildAgentBrowserNextActions, buildAgentBrowserResultCategoryDetails } from "../../results.js";
|
|
16
|
-
import { appendUniqueAgentBrowserNextActions } from "../../results/next-actions.js";
|
|
17
|
-
import { extractRefSnapshotFromData, isAboutBlankUrl, normalizeSessionTabTarget, type SessionPageState, type SessionRefSnapshot, type SessionTabTarget } from "../../session-page-state.js";
|
|
18
|
-
import { redactSensitiveText } from "../../runtime.js";
|
|
19
|
-
import { collectElectronManagedSessionTarget } from "../browser-run/diagnostics.js";
|
|
20
|
-
import { buildElectronHostFailureResult, formatElectronTargetLines, redactToolDetails } from "../browser-run/final-result.js";
|
|
21
|
-
import {
|
|
22
|
-
buildElectronIdentifiers,
|
|
23
|
-
buildElectronMismatchNextActions,
|
|
24
|
-
buildElectronSessionMismatch,
|
|
25
|
-
closeManagedSession,
|
|
26
|
-
extractStringResultField,
|
|
27
|
-
findElectronLaunchRecordForSession,
|
|
28
|
-
formatElectronSessionMismatchText,
|
|
29
|
-
getActiveElectronRecords,
|
|
30
|
-
getLiveElectronRendererTargets,
|
|
31
|
-
runSessionCommandData,
|
|
32
|
-
} from "../browser-run/session-state.js";
|
|
33
|
-
import type { AgentBrowserToolResult, ElectronManagedSessionTarget, ElectronSessionMismatch } from "../browser-run/types.js";
|
|
34
|
-
|
|
35
|
-
export type { ElectronLaunchRecord } from "../../electron/launch.js";
|
|
36
|
-
|
|
37
|
-
const ELECTRON_PROFILE_ISOLATION_NOTE = "Profile note: electron.launch starts an isolated temporary profile; it does not reuse the app's normal signed-in profile or attach to an already-running authenticated app.";
|
|
38
|
-
const ELECTRON_EXISTING_AUTH_GUIDANCE = "For already-authenticated desktop app content, do not stop here: if host tools are allowed and the app is not running, launch the normal app with --remote-debugging-port=<port>, verify the port, then run agent_browser connect <port>; if it is already running without a debug port, ask before relaunching it.";
|
|
39
|
-
export const ELECTRON_PROFILE_ISOLATION_DETAILS = {
|
|
40
|
-
attachesToAlreadyRunningApp: false,
|
|
41
|
-
existingAuthenticatedAppGuidance: ELECTRON_EXISTING_AUTH_GUIDANCE,
|
|
42
|
-
hostDebugLaunchExample: "macOS: open -a <App Name> --args --remote-debugging-port=9222 --remote-allow-origins='*'; then agent_browser connect 9222 with sessionMode=fresh",
|
|
43
|
-
isolatedLaunch: true,
|
|
44
|
-
note: ELECTRON_PROFILE_ISOLATION_NOTE,
|
|
45
|
-
reusesExistingSignedInProfile: false,
|
|
46
|
-
} as const;
|
|
47
|
-
export const ELECTRON_POST_COMMAND_STATUS_SETTLE_MS = 250;
|
|
48
|
-
|
|
49
|
-
const ELECTRON_PROBE_MAX_TABS = 6;
|
|
50
|
-
const ELECTRON_PROBE_MAX_REF_IDS = 20;
|
|
51
|
-
const ELECTRON_PROBE_MAX_SNAPSHOT_LINES = 12;
|
|
52
|
-
const ELECTRON_PROBE_MAX_SNAPSHOT_CHARS = 1_600;
|
|
53
|
-
|
|
54
|
-
function formatElectronListVisibleText(result: ElectronDiscoveryResult): string {
|
|
55
|
-
const visibleApps = result.apps.slice(0, 10);
|
|
56
|
-
const visibleOmittedCount = Math.max(0, result.apps.length - visibleApps.length);
|
|
57
|
-
const header = result.omittedCount > 0
|
|
58
|
-
? `Electron apps (${result.apps.length} shown, ${result.omittedCount} omitted):`
|
|
59
|
-
: `Electron apps (${result.apps.length} found):`;
|
|
60
|
-
const lines = [header];
|
|
61
|
-
if (visibleApps.length === 0) {
|
|
62
|
-
lines.push(result.query ? `No Electron apps matched query "${result.query}".` : "No Electron apps found in the supported scan locations.");
|
|
63
|
-
} else {
|
|
64
|
-
for (const app of visibleApps) {
|
|
65
|
-
const identifier = app.bundleId ?? app.desktopId;
|
|
66
|
-
const path = app.appPath ?? app.executablePath;
|
|
67
|
-
const sensitivity = app.sensitivity ? ` [likely sensitive: ${app.sensitivity.categories.join(", ")}]` : "";
|
|
68
|
-
lines.push(`- ${app.name}${identifier ? ` (${identifier})` : ""}${sensitivity} — ${path}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (visibleOmittedCount > 0) {
|
|
72
|
-
lines.push(`${visibleOmittedCount} additional app(s) omitted from visible output; see details.electron.apps.`);
|
|
73
|
-
}
|
|
74
|
-
if (result.omittedCount > 0) {
|
|
75
|
-
lines.push(`${result.omittedCount} app(s) omitted by maxResults=${result.maxResults}.`);
|
|
76
|
-
}
|
|
77
|
-
if (result.apps.some((app) => app.sensitivity?.level === "likely-sensitive")) {
|
|
78
|
-
lines.push("Review likely-sensitive apps and use caller-owned allow/deny policy before launch.");
|
|
79
|
-
lines.push(ELECTRON_PROFILE_ISOLATION_NOTE);
|
|
80
|
-
lines.push(ELECTRON_EXISTING_AUTH_GUIDANCE);
|
|
81
|
-
}
|
|
82
|
-
return lines.join("\n");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function buildElectronListSuccessResult(compiledElectron: CompiledAgentBrowserElectron, discovery: ElectronDiscoveryResult): AgentBrowserToolResult {
|
|
86
|
-
const text = redactSensitiveText(formatElectronListVisibleText(discovery));
|
|
87
|
-
const sensitiveAppCount = discovery.apps.filter((app) => app.sensitivity?.level === "likely-sensitive").length;
|
|
88
|
-
const details = {
|
|
89
|
-
args: [] as string[],
|
|
90
|
-
compiledElectron,
|
|
91
|
-
electron: {
|
|
92
|
-
action: "list" as const,
|
|
93
|
-
apps: discovery.apps,
|
|
94
|
-
maxResults: discovery.maxResults,
|
|
95
|
-
omittedCount: discovery.omittedCount || undefined,
|
|
96
|
-
platform: discovery.platform,
|
|
97
|
-
profileIsolation: ELECTRON_PROFILE_ISOLATION_DETAILS,
|
|
98
|
-
query: discovery.query,
|
|
99
|
-
sensitiveAppCount: sensitiveAppCount || undefined,
|
|
100
|
-
skippedCount: discovery.skippedCount,
|
|
101
|
-
status: "succeeded" as const,
|
|
102
|
-
},
|
|
103
|
-
...buildAgentBrowserResultCategoryDetails({ args: [], succeeded: true }),
|
|
104
|
-
summary: discovery.omittedCount > 0
|
|
105
|
-
? `Electron app discovery found ${discovery.apps.length} app(s) and omitted ${discovery.omittedCount}.`
|
|
106
|
-
: `Electron app discovery found ${discovery.apps.length} app(s).`,
|
|
107
|
-
};
|
|
108
|
-
return {
|
|
109
|
-
content: [{ type: "text", text }],
|
|
110
|
-
details: redactToolDetails(details, []),
|
|
111
|
-
isError: false,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function buildElectronListFailureResult(compiledElectron: CompiledAgentBrowserElectron | undefined, error: unknown): AgentBrowserToolResult {
|
|
116
|
-
const errorText = error instanceof Error ? error.message : String(error);
|
|
117
|
-
const text = redactSensitiveText(`Electron app discovery failed: ${errorText}`);
|
|
118
|
-
const details = {
|
|
119
|
-
args: [] as string[],
|
|
120
|
-
compiledElectron,
|
|
121
|
-
electron: {
|
|
122
|
-
action: "list" as const,
|
|
123
|
-
error: errorText,
|
|
124
|
-
status: "failed" as const,
|
|
125
|
-
},
|
|
126
|
-
...buildAgentBrowserResultCategoryDetails({ args: [], errorText, succeeded: false }),
|
|
127
|
-
summary: "Electron app discovery failed.",
|
|
128
|
-
};
|
|
129
|
-
return {
|
|
130
|
-
content: [{ type: "text", text }],
|
|
131
|
-
details: redactToolDetails(details, []),
|
|
132
|
-
isError: true,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function isElectronLaunchRecord(value: unknown): value is ElectronLaunchRecord {
|
|
137
|
-
if (!isRecord(value)) return false;
|
|
138
|
-
return value.version === 1 &&
|
|
139
|
-
value.launchedByWrapper === true &&
|
|
140
|
-
typeof value.launchId === "string" &&
|
|
141
|
-
typeof value.appName === "string" &&
|
|
142
|
-
typeof value.executablePath === "string" &&
|
|
143
|
-
typeof value.userDataDir === "string" &&
|
|
144
|
-
typeof value.port === "number" &&
|
|
145
|
-
typeof value.createdAtMs === "number";
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function restoreElectronLaunchRecordsFromBranch(branch: unknown[]): Map<string, ElectronLaunchRecord> {
|
|
149
|
-
const records = new Map<string, ElectronLaunchRecord>();
|
|
150
|
-
for (const entry of branch) {
|
|
151
|
-
if (!isRecord(entry) || entry.type !== "message") continue;
|
|
152
|
-
const message = isRecord(entry.message) ? entry.message : undefined;
|
|
153
|
-
if (!message || message.toolName !== "agent_browser") continue;
|
|
154
|
-
const details = isRecord(message.details) ? message.details : undefined;
|
|
155
|
-
const electron = isRecord(details?.electron) ? details.electron : undefined;
|
|
156
|
-
if (!electron) continue;
|
|
157
|
-
const launch = isElectronLaunchRecord(electron.launch) ? electron.launch : undefined;
|
|
158
|
-
if (launch) records.set(launch.launchId, launch);
|
|
159
|
-
const cleanupRecords = isRecord(electron.cleanup) && Array.isArray(electron.cleanup.records) ? electron.cleanup.records : [];
|
|
160
|
-
for (const cleanupRecord of cleanupRecords) {
|
|
161
|
-
if (isElectronLaunchRecord(cleanupRecord)) records.set(cleanupRecord.launchId, cleanupRecord);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return records;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function selectElectronRecords(compiledElectron: Extract<CompiledAgentBrowserElectron, { action: "cleanup" | "status" }>, records: Map<string, ElectronLaunchRecord>): { error?: string; records?: ElectronLaunchRecord[] } {
|
|
168
|
-
if (compiledElectron.launchId) {
|
|
169
|
-
const record = records.get(compiledElectron.launchId);
|
|
170
|
-
return record ? { records: [record] } : { error: `No wrapper-tracked Electron launch found for launchId ${compiledElectron.launchId}.` };
|
|
171
|
-
}
|
|
172
|
-
if (compiledElectron.all) return { records: getActiveElectronRecords(records) };
|
|
173
|
-
const activeRecords = getActiveElectronRecords(records);
|
|
174
|
-
if (activeRecords.length === 0) return { records: [] };
|
|
175
|
-
if (activeRecords.length > 1) return { error: "Multiple wrapper-tracked Electron launches are active; pass electron.launchId or electron.all." };
|
|
176
|
-
return { records: activeRecords };
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function extractTargetsFromStatus(statuses: ElectronLaunchStatus[]): ElectronCdpTarget[] {
|
|
180
|
-
return statuses.flatMap((status) => status.targets);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
interface ElectronProbeContext {
|
|
184
|
-
launchId?: string;
|
|
185
|
-
mode: "current-managed-session" | "launchId";
|
|
186
|
-
note?: string;
|
|
187
|
-
sessionName: string;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function formatElectronStatusVisibleText(statuses: ElectronLaunchStatus[], records: ElectronLaunchRecord[], mismatches: ElectronSessionMismatch[] = [], managedSessions: ElectronManagedSessionTarget[] = []): string {
|
|
191
|
-
if (statuses.length === 0) return "Electron status: no active wrapper-tracked launches.";
|
|
192
|
-
const recordsByLaunchId = new Map(records.map((record) => [record.launchId, record]));
|
|
193
|
-
const managedSessionsByName = new Map(managedSessions.map((managedSession) => [managedSession.sessionName, managedSession]));
|
|
194
|
-
const lines = [`Electron status: ${statuses.length} wrapper-tracked launch(es).`];
|
|
195
|
-
for (const status of statuses) {
|
|
196
|
-
const record = recordsByLaunchId.get(status.launchId);
|
|
197
|
-
const sessionName = record?.sessionName;
|
|
198
|
-
const appName = record?.appName ?? "Electron launch";
|
|
199
|
-
const sessionText = sessionName ? `, sessionName ${sessionName}` : "";
|
|
200
|
-
lines.push(`- ${status.launchId}: ${appName}${sessionText}; ${status.portAlive ? "debug port alive" : "debug port dead"}${status.pidAlive === undefined ? "" : status.pidAlive ? ", pid alive" : ", pid dead"} (port ${status.port})`);
|
|
201
|
-
lines.push(` Identifiers: launchId ${status.launchId}; sessionName ${sessionName ?? "not attached"}.`);
|
|
202
|
-
for (const targetLine of formatElectronTargetLines(status.targets, 4)) lines.push(` ${targetLine}`);
|
|
203
|
-
const managedSession = sessionName ? managedSessionsByName.get(sessionName) : undefined;
|
|
204
|
-
if (managedSession?.error) lines.push(` Managed session warning: ${managedSession.error}`);
|
|
205
|
-
}
|
|
206
|
-
for (const mismatch of mismatches) lines.push("", formatElectronSessionMismatchText(mismatch));
|
|
207
|
-
return lines.join("\n");
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function buildElectronStatusResult(options: {
|
|
211
|
-
compiledElectron: CompiledAgentBrowserElectron;
|
|
212
|
-
managedSessions?: ElectronManagedSessionTarget[];
|
|
213
|
-
mismatches?: ElectronSessionMismatch[];
|
|
214
|
-
records: ElectronLaunchRecord[];
|
|
215
|
-
statuses: ElectronLaunchStatus[];
|
|
216
|
-
}): AgentBrowserToolResult {
|
|
217
|
-
const baseNextActions = options.records.flatMap((record) => buildAgentBrowserNextActions({
|
|
218
|
-
electron: { launchId: record.launchId, sessionName: record.sessionName, status: record.cleanupState },
|
|
219
|
-
resultCategory: "success",
|
|
220
|
-
successCategory: "completed",
|
|
221
|
-
}) ?? []);
|
|
222
|
-
const mismatchNextActions = (options.mismatches ?? []).flatMap((mismatch) => {
|
|
223
|
-
const record = options.records.find((candidate) => candidate.launchId === mismatch.launchId);
|
|
224
|
-
return record ? buildElectronMismatchNextActions(record, mismatch.liveTarget) : [];
|
|
225
|
-
});
|
|
226
|
-
const nextActions = options.mismatches?.length
|
|
227
|
-
? appendUniqueAgentBrowserNextActions([...mismatchNextActions], baseNextActions)
|
|
228
|
-
: appendUniqueAgentBrowserNextActions([...baseNextActions], mismatchNextActions);
|
|
229
|
-
const details = {
|
|
230
|
-
args: [] as string[],
|
|
231
|
-
compiledElectron: options.compiledElectron,
|
|
232
|
-
electron: {
|
|
233
|
-
action: "status" as const,
|
|
234
|
-
identifierList: options.records.length > 1 ? options.records.map(buildElectronIdentifiers) : undefined,
|
|
235
|
-
identifiers: options.records.length === 1 && options.records[0] ? buildElectronIdentifiers(options.records[0]) : undefined,
|
|
236
|
-
launches: options.records,
|
|
237
|
-
managedSession: options.managedSessions?.length === 1 ? options.managedSessions[0] : undefined,
|
|
238
|
-
managedSessions: options.managedSessions && options.managedSessions.length > 0 ? options.managedSessions : undefined,
|
|
239
|
-
sessionMismatch: options.mismatches?.length === 1 ? options.mismatches[0] : undefined,
|
|
240
|
-
sessionMismatches: options.mismatches && options.mismatches.length > 1 ? options.mismatches : undefined,
|
|
241
|
-
status: "succeeded" as const,
|
|
242
|
-
statuses: options.statuses,
|
|
243
|
-
targets: extractTargetsFromStatus(options.statuses),
|
|
244
|
-
},
|
|
245
|
-
nextActions: nextActions.length > 0 ? nextActions : undefined,
|
|
246
|
-
...buildAgentBrowserResultCategoryDetails({ args: [], succeeded: true }),
|
|
247
|
-
summary: options.statuses.length === 0 ? "Electron status found no active wrapper-tracked launches." : `Electron status inspected ${options.statuses.length} launch(es).`,
|
|
248
|
-
};
|
|
249
|
-
return { content: [{ type: "text", text: redactSensitiveText(formatElectronStatusVisibleText(options.statuses, options.records, options.mismatches, options.managedSessions)) }], details: redactToolDetails(details, []), isError: false };
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function formatElectronCleanupVisibleText(results: ElectronCleanupResult[]): string {
|
|
253
|
-
if (results.length === 0) return "Electron cleanup: no active wrapper-tracked launches.";
|
|
254
|
-
const lines = [`Electron cleanup: ${results.filter((result) => !result.partial).length}/${results.length} launch(es) fully cleaned.`];
|
|
255
|
-
for (const result of results) {
|
|
256
|
-
lines.push(`- ${result.summary}`);
|
|
257
|
-
for (const step of result.steps) lines.push(` - ${step.resource}: ${step.state}${step.error ? ` (${step.error})` : ""}`);
|
|
258
|
-
}
|
|
259
|
-
return lines.join("\n");
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function buildElectronCleanupResult(compiledElectron: CompiledAgentBrowserElectron, cleanupResults: ElectronCleanupResult[]): AgentBrowserToolResult {
|
|
263
|
-
const partial = cleanupResults.some((result) => result.partial);
|
|
264
|
-
const records = cleanupResults.map((result) => result.record);
|
|
265
|
-
const nextActions = cleanupResults.flatMap((result) => buildAgentBrowserNextActions({
|
|
266
|
-
electron: { launchId: result.launchId, sessionName: result.record.sessionName, status: result.record.cleanupState },
|
|
267
|
-
failureCategory: partial ? "cleanup-failed" : undefined,
|
|
268
|
-
resultCategory: partial ? "failure" : "success",
|
|
269
|
-
successCategory: partial ? undefined : "completed",
|
|
270
|
-
}) ?? []);
|
|
271
|
-
const errorText = partial ? cleanupResults.map((result) => result.summary).join("\n") : undefined;
|
|
272
|
-
const details = {
|
|
273
|
-
args: [] as string[],
|
|
274
|
-
compiledElectron,
|
|
275
|
-
electron: {
|
|
276
|
-
action: "cleanup" as const,
|
|
277
|
-
cleanup: { partial, records, results: cleanupResults },
|
|
278
|
-
status: partial ? "partial" as const : "succeeded" as const,
|
|
279
|
-
},
|
|
280
|
-
nextActions: nextActions.length > 0 ? nextActions : undefined,
|
|
281
|
-
...buildAgentBrowserResultCategoryDetails({ args: [], errorText, failureCategory: partial ? "cleanup-failed" : undefined, succeeded: !partial }),
|
|
282
|
-
summary: partial ? "Electron cleanup was partial." : "Electron cleanup completed.",
|
|
283
|
-
};
|
|
284
|
-
return { content: [{ type: "text", text: redactSensitiveText(formatElectronCleanupVisibleText(cleanupResults)) }], details: redactToolDetails(details, []), isError: partial };
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
interface ElectronProbeFocusedElement {
|
|
288
|
-
ariaLabel?: string;
|
|
289
|
-
id?: string;
|
|
290
|
-
isContentEditable?: boolean;
|
|
291
|
-
name?: string;
|
|
292
|
-
placeholder?: string;
|
|
293
|
-
role?: string;
|
|
294
|
-
tagName?: string;
|
|
295
|
-
textLength?: number;
|
|
296
|
-
textPreview?: string;
|
|
297
|
-
title?: string;
|
|
298
|
-
type?: string;
|
|
299
|
-
valueLength?: number;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
interface ElectronProbeTab {
|
|
303
|
-
active?: boolean;
|
|
304
|
-
index?: number;
|
|
305
|
-
tabId?: string;
|
|
306
|
-
title?: string;
|
|
307
|
-
type?: string;
|
|
308
|
-
url?: string;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
interface ElectronProbeSnapshotSummary {
|
|
312
|
-
lineCount: number;
|
|
313
|
-
omittedLineCount?: number;
|
|
314
|
-
omittedRefCount?: number;
|
|
315
|
-
refCount: number;
|
|
316
|
-
refIds: string[];
|
|
317
|
-
text?: string;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
interface ElectronProbeResult {
|
|
321
|
-
activeTab?: ElectronProbeTab;
|
|
322
|
-
errors?: string[];
|
|
323
|
-
focusedElement?: ElectronProbeFocusedElement;
|
|
324
|
-
refSnapshot?: SessionRefSnapshot;
|
|
325
|
-
sessionName: string;
|
|
326
|
-
snapshot?: ElectronProbeSnapshotSummary;
|
|
327
|
-
status: "partial" | "succeeded";
|
|
328
|
-
summary: string;
|
|
329
|
-
tabs?: {
|
|
330
|
-
omittedCount?: number;
|
|
331
|
-
shown: ElectronProbeTab[];
|
|
332
|
-
total: number;
|
|
333
|
-
};
|
|
334
|
-
title?: string;
|
|
335
|
-
url?: string;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
const ELECTRON_FOCUSED_ELEMENT_EVAL = `(() => {
|
|
339
|
-
const clean = (value, max = 80) => {
|
|
340
|
-
if (typeof value !== "string") return undefined;
|
|
341
|
-
const normalized = value.replace(/\\s+/g, " ").trim();
|
|
342
|
-
if (!normalized) return undefined;
|
|
343
|
-
return normalized.length > max ? normalized.slice(0, max - 3) + "..." : normalized;
|
|
344
|
-
};
|
|
345
|
-
const describeElement = (element) => {
|
|
346
|
-
if (!element || !(element instanceof Element)) return undefined;
|
|
347
|
-
const tagName = element.tagName.toLowerCase();
|
|
348
|
-
const inputLike = element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement;
|
|
349
|
-
const contentEditable = element instanceof HTMLElement && element.isContentEditable;
|
|
350
|
-
const containerLike = tagName === "body" || tagName === "html";
|
|
351
|
-
const rawText = element.textContent || "";
|
|
352
|
-
const exposeText = !inputLike && !contentEditable && !containerLike;
|
|
353
|
-
const text = exposeText ? clean(rawText) : undefined;
|
|
354
|
-
return {
|
|
355
|
-
tagName: clean(tagName, 40),
|
|
356
|
-
role: clean(element.getAttribute("role") || "", 60),
|
|
357
|
-
name: clean(element.getAttribute("aria-label") || element.getAttribute("title") || text || "", 80),
|
|
358
|
-
id: clean(element.id || "", 80),
|
|
359
|
-
type: clean(element.getAttribute("type") || "", 40),
|
|
360
|
-
placeholder: clean(element.getAttribute("placeholder") || "", 80),
|
|
361
|
-
ariaLabel: clean(element.getAttribute("aria-label") || "", 80),
|
|
362
|
-
title: clean(element.getAttribute("title") || "", 80),
|
|
363
|
-
textLength: !exposeText && rawText ? rawText.length : undefined,
|
|
364
|
-
textPreview: text,
|
|
365
|
-
valueLength: inputLike && typeof element.value === "string" ? element.value.length : undefined,
|
|
366
|
-
isContentEditable: contentEditable || undefined,
|
|
367
|
-
};
|
|
368
|
-
};
|
|
369
|
-
return { focusedElement: describeElement(document.activeElement) };
|
|
370
|
-
})()`;
|
|
371
|
-
|
|
372
|
-
function getTrimmedString(value: unknown): string | undefined {
|
|
373
|
-
return typeof value === "string" ? boundElectronProbeString(value) : undefined;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
function getOptionalBoolean(value: unknown): boolean | undefined {
|
|
377
|
-
return typeof value === "boolean" ? value : undefined;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
function getOptionalNumber(value: unknown): number | undefined {
|
|
381
|
-
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
function extractElectronFocusedElement(data: unknown): ElectronProbeFocusedElement | undefined {
|
|
385
|
-
const payload = isRecord(data) && isRecord(data.result) ? data.result : data;
|
|
386
|
-
const rawFocusedElement = isRecord(payload) && isRecord(payload.focusedElement) ? payload.focusedElement : isRecord(payload) ? payload : undefined;
|
|
387
|
-
if (!rawFocusedElement) return undefined;
|
|
388
|
-
const focusedElement: ElectronProbeFocusedElement = {
|
|
389
|
-
ariaLabel: getTrimmedString(rawFocusedElement.ariaLabel),
|
|
390
|
-
id: getTrimmedString(rawFocusedElement.id),
|
|
391
|
-
isContentEditable: getOptionalBoolean(rawFocusedElement.isContentEditable),
|
|
392
|
-
name: getTrimmedString(rawFocusedElement.name),
|
|
393
|
-
placeholder: getTrimmedString(rawFocusedElement.placeholder),
|
|
394
|
-
role: getTrimmedString(rawFocusedElement.role),
|
|
395
|
-
tagName: getTrimmedString(rawFocusedElement.tagName),
|
|
396
|
-
textLength: getOptionalNumber(rawFocusedElement.textLength),
|
|
397
|
-
textPreview: getTrimmedString(rawFocusedElement.textPreview),
|
|
398
|
-
title: getTrimmedString(rawFocusedElement.title),
|
|
399
|
-
type: getTrimmedString(rawFocusedElement.type),
|
|
400
|
-
valueLength: getOptionalNumber(rawFocusedElement.valueLength),
|
|
401
|
-
};
|
|
402
|
-
return Object.values(focusedElement).some((value) => value !== undefined) ? focusedElement : undefined;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
function extractElectronProbeTabs(data: unknown): { activeTab?: ElectronProbeTab; tabs?: ElectronProbeResult["tabs"] } {
|
|
406
|
-
const rawTabs = isRecord(data) && Array.isArray(data.tabs) ? data.tabs : Array.isArray(data) ? data : [];
|
|
407
|
-
const allTabs = rawTabs.filter(isRecord).map((tab, index): ElectronProbeTab => ({
|
|
408
|
-
active: getOptionalBoolean(tab.active),
|
|
409
|
-
index: typeof tab.index === "number" && Number.isInteger(tab.index) ? tab.index : index,
|
|
410
|
-
tabId: getTrimmedString(tab.tabId) ?? getTrimmedString(tab.id),
|
|
411
|
-
title: getTrimmedString(tab.title) ?? getTrimmedString(tab.label),
|
|
412
|
-
type: getTrimmedString(tab.type),
|
|
413
|
-
url: getTrimmedString(tab.url),
|
|
414
|
-
}));
|
|
415
|
-
if (allTabs.length === 0) return {};
|
|
416
|
-
const shown = allTabs.slice(0, ELECTRON_PROBE_MAX_TABS);
|
|
417
|
-
return {
|
|
418
|
-
activeTab: allTabs.find((tab) => tab.active) ?? allTabs[0],
|
|
419
|
-
tabs: {
|
|
420
|
-
omittedCount: allTabs.length > shown.length ? allTabs.length - shown.length : undefined,
|
|
421
|
-
shown,
|
|
422
|
-
total: allTabs.length,
|
|
423
|
-
},
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
function truncateElectronProbeSnapshotText(snapshotText: string | undefined): { lineCount: number; omittedLineCount?: number; text?: string } {
|
|
428
|
-
if (!snapshotText) return { lineCount: 0 };
|
|
429
|
-
const lines = snapshotText.split(/\r?\n/);
|
|
430
|
-
const shownLines: string[] = [];
|
|
431
|
-
let usedChars = 0;
|
|
432
|
-
for (const line of lines) {
|
|
433
|
-
if (shownLines.length >= ELECTRON_PROBE_MAX_SNAPSHOT_LINES) break;
|
|
434
|
-
const nextLength = usedChars + line.length + (shownLines.length > 0 ? 1 : 0);
|
|
435
|
-
if (nextLength > ELECTRON_PROBE_MAX_SNAPSHOT_CHARS) {
|
|
436
|
-
if (shownLines.length === 0) shownLines.push(`${line.slice(0, ELECTRON_PROBE_MAX_SNAPSHOT_CHARS - 3)}...`);
|
|
437
|
-
break;
|
|
438
|
-
}
|
|
439
|
-
shownLines.push(line);
|
|
440
|
-
usedChars = nextLength;
|
|
441
|
-
}
|
|
442
|
-
return {
|
|
443
|
-
lineCount: lines.length,
|
|
444
|
-
omittedLineCount: lines.length > shownLines.length ? lines.length - shownLines.length : undefined,
|
|
445
|
-
text: shownLines.length > 0 ? shownLines.join("\n") : undefined,
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
function summarizeElectronProbeSnapshot(data: unknown): { refSnapshot?: SessionRefSnapshot; snapshot?: ElectronProbeSnapshotSummary } {
|
|
450
|
-
const refSnapshot = extractRefSnapshotFromData(data);
|
|
451
|
-
const rawSnapshotText = isRecord(data) ? getTrimmedString(data.snapshot) : undefined;
|
|
452
|
-
const truncatedText = truncateElectronProbeSnapshotText(rawSnapshotText);
|
|
453
|
-
const refIds = refSnapshot?.refIds ?? [];
|
|
454
|
-
const shownRefIds = refIds.slice(0, ELECTRON_PROBE_MAX_REF_IDS);
|
|
455
|
-
const snapshot = refSnapshot || truncatedText.text
|
|
456
|
-
? {
|
|
457
|
-
lineCount: truncatedText.lineCount,
|
|
458
|
-
omittedLineCount: truncatedText.omittedLineCount,
|
|
459
|
-
omittedRefCount: refIds.length > shownRefIds.length ? refIds.length - shownRefIds.length : undefined,
|
|
460
|
-
refCount: refIds.length,
|
|
461
|
-
refIds: shownRefIds,
|
|
462
|
-
text: truncatedText.text,
|
|
463
|
-
}
|
|
464
|
-
: undefined;
|
|
465
|
-
return { refSnapshot, snapshot };
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
function getElectronProbeSummary(probe: Omit<ElectronProbeResult, "summary">): string {
|
|
469
|
-
const parts = [
|
|
470
|
-
probe.title ? `title "${probe.title}"` : undefined,
|
|
471
|
-
probe.url ? `url ${probe.url}` : undefined,
|
|
472
|
-
probe.focusedElement ? "focused element" : undefined,
|
|
473
|
-
probe.tabs ? `${probe.tabs.total} tab(s)` : undefined,
|
|
474
|
-
probe.snapshot ? `${probe.snapshot.refCount} ref(s)` : undefined,
|
|
475
|
-
].filter((item): item is string => item !== undefined);
|
|
476
|
-
return parts.length > 0 ? `Electron probe collected ${parts.join(", ")}.` : "Electron probe did not return current session state.";
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
async function runElectronProbeCommandData(options: {
|
|
480
|
-
args: string[];
|
|
481
|
-
cwd: string;
|
|
482
|
-
sessionName: string;
|
|
483
|
-
signal?: AbortSignal;
|
|
484
|
-
stdin?: string;
|
|
485
|
-
timeoutMs?: number;
|
|
486
|
-
}): Promise<{ data?: unknown; error?: string }> {
|
|
487
|
-
try {
|
|
488
|
-
return { data: await runSessionCommandData(options) };
|
|
489
|
-
} catch (error) {
|
|
490
|
-
return { error: error instanceof Error ? error.message : String(error) };
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
async function collectElectronProbe(options: {
|
|
495
|
-
cwd: string;
|
|
496
|
-
sessionName: string;
|
|
497
|
-
signal?: AbortSignal;
|
|
498
|
-
timeoutMs?: number;
|
|
499
|
-
}): Promise<ElectronProbeResult> {
|
|
500
|
-
const titleResult = await runElectronProbeCommandData({ args: ["get", "title"], cwd: options.cwd, sessionName: options.sessionName, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
501
|
-
const urlResult = await runElectronProbeCommandData({ args: ["get", "url"], cwd: options.cwd, sessionName: options.sessionName, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
502
|
-
const focusedResult = await runElectronProbeCommandData({ args: ["eval", "--stdin"], cwd: options.cwd, sessionName: options.sessionName, signal: options.signal, stdin: ELECTRON_FOCUSED_ELEMENT_EVAL, timeoutMs: options.timeoutMs });
|
|
503
|
-
const tabsResult = await runElectronProbeCommandData({ args: ["tab", "list"], cwd: options.cwd, sessionName: options.sessionName, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
504
|
-
const snapshotResult = await runElectronProbeCommandData({ args: ["snapshot", "-i"], cwd: options.cwd, sessionName: options.sessionName, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
505
|
-
const errors = [
|
|
506
|
-
titleResult.error ? `get title: ${titleResult.error}` : undefined,
|
|
507
|
-
urlResult.error ? `get url: ${urlResult.error}` : undefined,
|
|
508
|
-
focusedResult.error ? `focused element: ${focusedResult.error}` : undefined,
|
|
509
|
-
tabsResult.error ? `tab list: ${tabsResult.error}` : undefined,
|
|
510
|
-
snapshotResult.error ? `snapshot: ${snapshotResult.error}` : undefined,
|
|
511
|
-
].filter((item): item is string => item !== undefined).map((error) => boundElectronProbeString(error, 240) ?? "probe command failed");
|
|
512
|
-
const title = boundElectronProbeString(extractStringResultField(titleResult.data, "result") ?? extractStringResultField(titleResult.data, "title"), 160);
|
|
513
|
-
const url = boundElectronProbeString(extractStringResultField(urlResult.data, "result") ?? extractStringResultField(urlResult.data, "url"), 300);
|
|
514
|
-
const focusedElement = extractElectronFocusedElement(focusedResult.data);
|
|
515
|
-
const { activeTab, tabs } = extractElectronProbeTabs(tabsResult.data);
|
|
516
|
-
const { refSnapshot, snapshot } = summarizeElectronProbeSnapshot(snapshotResult.data);
|
|
517
|
-
const probeWithoutSummary = {
|
|
518
|
-
activeTab,
|
|
519
|
-
focusedElement,
|
|
520
|
-
errors: errors.length > 0 ? errors : undefined,
|
|
521
|
-
refSnapshot,
|
|
522
|
-
sessionName: options.sessionName,
|
|
523
|
-
snapshot,
|
|
524
|
-
status: errors.length === 0 && (title || url || focusedElement || tabs || snapshot) ? "succeeded" as const : "partial" as const,
|
|
525
|
-
tabs,
|
|
526
|
-
title,
|
|
527
|
-
url,
|
|
528
|
-
};
|
|
529
|
-
return { ...probeWithoutSummary, summary: getElectronProbeSummary(probeWithoutSummary) };
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
function formatElectronProbeFocusedElement(focusedElement: ElectronProbeFocusedElement | undefined): string | undefined {
|
|
533
|
-
if (!focusedElement) return undefined;
|
|
534
|
-
const label = focusedElement.name ?? focusedElement.textPreview ?? focusedElement.placeholder ?? focusedElement.ariaLabel ?? focusedElement.title;
|
|
535
|
-
const descriptor = [focusedElement.role, focusedElement.tagName].filter(Boolean).join("/") || "element";
|
|
536
|
-
const suffix = [
|
|
537
|
-
focusedElement.id ? `#${focusedElement.id}` : undefined,
|
|
538
|
-
focusedElement.type ? `type=${focusedElement.type}` : undefined,
|
|
539
|
-
focusedElement.valueLength !== undefined ? `valueLength=${focusedElement.valueLength}` : undefined,
|
|
540
|
-
focusedElement.textLength !== undefined ? `textLength=${focusedElement.textLength}` : undefined,
|
|
541
|
-
].filter((item): item is string => item !== undefined).join(", ");
|
|
542
|
-
return `Focused: ${descriptor}${label ? ` "${label}"` : ""}${suffix ? ` (${suffix})` : ""}`;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
function formatElectronProbeContextText(context: ElectronProbeContext): string {
|
|
546
|
-
if (context.mode === "launchId") {
|
|
547
|
-
return `Probe context: wrapper launch ${context.launchId} session ${context.sessionName}.`;
|
|
548
|
-
}
|
|
549
|
-
if (context.note) {
|
|
550
|
-
return `Probe context: current managed session ${context.sessionName}; ${context.note}`;
|
|
551
|
-
}
|
|
552
|
-
if (context.launchId) {
|
|
553
|
-
return `Probe context: current managed session ${context.sessionName} maps to Electron launch ${context.launchId}.`;
|
|
554
|
-
}
|
|
555
|
-
return `Probe context: current managed session ${context.sessionName} only; pass electron.probe.launchId to compare wrapper-tracked launch status.`;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
function formatElectronProbeLaunchStatusText(status: ElectronLaunchStatus | undefined, probe: ElectronProbeResult): string | undefined {
|
|
559
|
-
if (!status) return undefined;
|
|
560
|
-
const lines = [`Launch status: ${status.portAlive ? "debug port alive" : "debug port dead"}${status.pidAlive === undefined ? "" : status.pidAlive ? ", pid alive" : ", pid dead"}; ${status.targets.length} CDP target(s).`];
|
|
561
|
-
if (isAboutBlankUrl(probe.url) && (!status.portAlive || status.pidAlive === false || getLiveElectronRendererTargets(status.targets).length === 0)) {
|
|
562
|
-
lines.push("Electron lifecycle warning: the browser session is on about:blank and the wrapper launch has no live renderer target to reattach. Run electron.status, cleanup if dead, or relaunch the app.");
|
|
563
|
-
}
|
|
564
|
-
return lines.join("\n");
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
function formatElectronProbeVisibleText(options: {
|
|
568
|
-
context?: ElectronProbeContext;
|
|
569
|
-
mismatch?: ElectronSessionMismatch;
|
|
570
|
-
probe: ElectronProbeResult;
|
|
571
|
-
status?: ElectronLaunchStatus;
|
|
572
|
-
}): string {
|
|
573
|
-
const { context, mismatch, probe, status } = options;
|
|
574
|
-
const page = [probe.title, probe.url].filter(Boolean).join(" — ");
|
|
575
|
-
const lines = [`Electron probe: ${page || probe.sessionName}`];
|
|
576
|
-
if (context) lines.push(formatElectronProbeContextText(context));
|
|
577
|
-
const launchStatusText = formatElectronProbeLaunchStatusText(status, probe);
|
|
578
|
-
if (launchStatusText) lines.push(launchStatusText);
|
|
579
|
-
if (mismatch) lines.push(formatElectronSessionMismatchText(mismatch));
|
|
580
|
-
const focusedLine = formatElectronProbeFocusedElement(probe.focusedElement);
|
|
581
|
-
if (focusedLine) lines.push(focusedLine);
|
|
582
|
-
if (probe.tabs) {
|
|
583
|
-
const active = probe.activeTab;
|
|
584
|
-
lines.push(`Tabs: ${probe.tabs.total} total${probe.tabs.omittedCount ? ` (${probe.tabs.omittedCount} omitted)` : ""}${active ? `; active ${active.index ?? "?"}: ${[active.title, active.url].filter(Boolean).join(" — ") || active.tabId || "tab"}` : ""}`);
|
|
585
|
-
}
|
|
586
|
-
if (probe.snapshot) {
|
|
587
|
-
lines.push(`Snapshot: ${probe.snapshot.refCount} interactive ref(s)${probe.snapshot.omittedRefCount ? ` (${probe.snapshot.omittedRefCount} ref id(s) omitted)` : ""}.`);
|
|
588
|
-
if (probe.snapshot.text) lines.push(probe.snapshot.text);
|
|
589
|
-
if (probe.snapshot.omittedLineCount) lines.push(`... ${probe.snapshot.omittedLineCount} snapshot line(s) omitted`);
|
|
590
|
-
}
|
|
591
|
-
if (probe.status === "partial") lines.push("Some probe commands did not return data; use raw agent_browser commands for deeper diagnostics.");
|
|
592
|
-
if (probe.errors && probe.errors.length > 0) lines.push(`Probe warning: ${probe.errors.slice(0, 2).join("; ")}${probe.errors.length > 2 ? "; ..." : ""}`);
|
|
593
|
-
return lines.join("\n");
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
function buildElectronProbeResult(options: {
|
|
597
|
-
compiledElectron: CompiledAgentBrowserElectron;
|
|
598
|
-
mismatch?: ElectronSessionMismatch;
|
|
599
|
-
probe: ElectronProbeResult;
|
|
600
|
-
probeContext: ElectronProbeContext;
|
|
601
|
-
record?: ElectronLaunchRecord;
|
|
602
|
-
sessionTabTarget?: SessionTabTarget;
|
|
603
|
-
status?: ElectronLaunchStatus;
|
|
604
|
-
}): AgentBrowserToolResult {
|
|
605
|
-
const { refSnapshot: _refSnapshot, ...boundedProbe } = options.probe;
|
|
606
|
-
const baseNextActions = options.record ? buildAgentBrowserNextActions({
|
|
607
|
-
electron: { launchId: options.record.launchId, sessionName: options.record.sessionName, status: options.record.cleanupState },
|
|
608
|
-
resultCategory: "success",
|
|
609
|
-
successCategory: "completed",
|
|
610
|
-
}) ?? [] : [];
|
|
611
|
-
const mismatchNextActions = options.mismatch && options.record ? buildElectronMismatchNextActions(options.record, options.mismatch.liveTarget) : [];
|
|
612
|
-
const nextActions = options.mismatch
|
|
613
|
-
? appendUniqueAgentBrowserNextActions([...mismatchNextActions], baseNextActions)
|
|
614
|
-
: appendUniqueAgentBrowserNextActions([...baseNextActions], mismatchNextActions);
|
|
615
|
-
const details = {
|
|
616
|
-
args: [] as string[],
|
|
617
|
-
compiledElectron: options.compiledElectron,
|
|
618
|
-
electron: {
|
|
619
|
-
action: "probe" as const,
|
|
620
|
-
identifiers: options.record ? buildElectronIdentifiers(options.record) : undefined,
|
|
621
|
-
probe: boundedProbe,
|
|
622
|
-
probeContext: options.probeContext,
|
|
623
|
-
sessionMismatch: options.mismatch,
|
|
624
|
-
status: options.probe.status,
|
|
625
|
-
statusTargets: options.status?.targets,
|
|
626
|
-
launchStatus: options.status,
|
|
627
|
-
},
|
|
628
|
-
nextActions: nextActions.length > 0 ? nextActions : undefined,
|
|
629
|
-
...buildAgentBrowserResultCategoryDetails({ args: [], succeeded: true }),
|
|
630
|
-
sessionName: options.probe.sessionName,
|
|
631
|
-
sessionTabTarget: options.sessionTabTarget,
|
|
632
|
-
summary: options.mismatch?.summary ?? options.probe.summary,
|
|
633
|
-
usedImplicitSession: options.probeContext.mode === "current-managed-session",
|
|
634
|
-
};
|
|
635
|
-
return {
|
|
636
|
-
content: [{ type: "text", text: redactSensitiveText(formatElectronProbeVisibleText({ context: options.probeContext, mismatch: options.mismatch, probe: options.probe, status: options.status })) }],
|
|
637
|
-
details: redactToolDetails(details, []),
|
|
638
|
-
isError: false,
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
interface ElectronHostLaunchCleanupState {
|
|
643
|
-
electronChildProcesses: Map<string, ChildProcess>;
|
|
644
|
-
electronLaunchRecords: Map<string, ElectronLaunchRecord>;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
export async function cleanupTrackedElectronHostLaunches(options: ElectronHostLaunchCleanupState & {
|
|
648
|
-
cwd: string;
|
|
649
|
-
records: ElectronLaunchRecord[];
|
|
650
|
-
timeoutMs: number;
|
|
651
|
-
}): Promise<ElectronCleanupResult[]> {
|
|
652
|
-
const results: ElectronCleanupResult[] = [];
|
|
653
|
-
for (const record of options.records) {
|
|
654
|
-
const managedSessionCloseError = record.sessionName
|
|
655
|
-
? await closeManagedSession({ cwd: options.cwd, sessionName: record.sessionName, timeoutMs: options.timeoutMs })
|
|
656
|
-
: undefined;
|
|
657
|
-
const managedSessionStep = record.sessionName
|
|
658
|
-
? managedSessionCloseError
|
|
659
|
-
? { error: managedSessionCloseError, resource: "managed-session" as const, sessionName: record.sessionName, state: "failed" as const }
|
|
660
|
-
: { resource: "managed-session" as const, sessionName: record.sessionName, state: "removed" as const }
|
|
661
|
-
: undefined;
|
|
662
|
-
const cleanupResult = await cleanupElectronLaunchResources({
|
|
663
|
-
child: options.electronChildProcesses.get(record.launchId),
|
|
664
|
-
record,
|
|
665
|
-
timeoutMs: options.timeoutMs,
|
|
666
|
-
});
|
|
667
|
-
const cleanupRecord = record.sessionName && !managedSessionCloseError
|
|
668
|
-
? { ...cleanupResult.record, sessionName: undefined }
|
|
669
|
-
: cleanupResult.record;
|
|
670
|
-
const result: ElectronCleanupResult = managedSessionCloseError
|
|
671
|
-
? {
|
|
672
|
-
...cleanupResult,
|
|
673
|
-
partial: true,
|
|
674
|
-
record: { ...cleanupResult.record, cleanupState: "partial" },
|
|
675
|
-
remainingResources: [...new Set(["managed-session", ...cleanupResult.remainingResources])],
|
|
676
|
-
steps: [managedSessionStep, ...cleanupResult.steps].filter((step): step is NonNullable<typeof step> => step !== undefined),
|
|
677
|
-
summary: `Electron cleanup for ${record.launchId} is partial; managed session close failed.`,
|
|
678
|
-
}
|
|
679
|
-
: {
|
|
680
|
-
...cleanupResult,
|
|
681
|
-
record: cleanupRecord,
|
|
682
|
-
steps: [managedSessionStep, ...cleanupResult.steps].filter((step): step is NonNullable<typeof step> => step !== undefined),
|
|
683
|
-
};
|
|
684
|
-
results.push(result);
|
|
685
|
-
options.electronLaunchRecords.set(record.launchId, result.record);
|
|
686
|
-
if (!result.partial) options.electronChildProcesses.delete(record.launchId);
|
|
687
|
-
}
|
|
688
|
-
return results;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
export async function cleanupActiveElectronHostLaunches(options: ElectronHostLaunchCleanupState & {
|
|
692
|
-
cwd: string;
|
|
693
|
-
timeoutMs: number;
|
|
694
|
-
}): Promise<ElectronCleanupResult[]> {
|
|
695
|
-
const activeRecords = getActiveElectronRecords(options.electronLaunchRecords);
|
|
696
|
-
return activeRecords.length > 0
|
|
697
|
-
? cleanupTrackedElectronHostLaunches({ ...options, records: activeRecords })
|
|
698
|
-
: [];
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
export async function handleElectronHostInput(options: {
|
|
702
|
-
compiledElectron?: CompiledAgentBrowserElectron;
|
|
703
|
-
cwd: string;
|
|
704
|
-
electronChildProcesses: Map<string, ChildProcess>;
|
|
705
|
-
electronLaunchRecords: Map<string, ElectronLaunchRecord>;
|
|
706
|
-
implicitSessionCloseTimeoutMs: number;
|
|
707
|
-
managedSessionActive: boolean;
|
|
708
|
-
managedSessionName: string;
|
|
709
|
-
redactedCompiledElectron?: CompiledAgentBrowserElectron;
|
|
710
|
-
sessionPageState: SessionPageState;
|
|
711
|
-
signal?: AbortSignal;
|
|
712
|
-
}): Promise<AgentBrowserToolResult | undefined> {
|
|
713
|
-
const {
|
|
714
|
-
compiledElectron,
|
|
715
|
-
cwd,
|
|
716
|
-
electronChildProcesses,
|
|
717
|
-
electronLaunchRecords,
|
|
718
|
-
implicitSessionCloseTimeoutMs,
|
|
719
|
-
managedSessionActive,
|
|
720
|
-
managedSessionName,
|
|
721
|
-
redactedCompiledElectron,
|
|
722
|
-
sessionPageState,
|
|
723
|
-
signal,
|
|
724
|
-
} = options;
|
|
725
|
-
if (compiledElectron?.action === "list") {
|
|
726
|
-
try {
|
|
727
|
-
const discovery = await discoverElectronApps({ maxResults: compiledElectron.maxResults, query: compiledElectron.query });
|
|
728
|
-
return buildElectronListSuccessResult(redactedCompiledElectron ?? compiledElectron, discovery);
|
|
729
|
-
} catch (error) {
|
|
730
|
-
return buildElectronListFailureResult(redactedCompiledElectron ?? compiledElectron, error);
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
if (compiledElectron?.action === "status") {
|
|
734
|
-
const selection = selectElectronRecords(compiledElectron, electronLaunchRecords);
|
|
735
|
-
if (selection.error) return buildElectronHostFailureResult({ compiledElectron: redactedCompiledElectron ?? compiledElectron, errorText: selection.error, failureCategory: "validation-error" });
|
|
736
|
-
const records = selection.records ?? [];
|
|
737
|
-
const statuses = await Promise.all(records.map((record) => inspectElectronLaunchStatus(record)));
|
|
738
|
-
const managedSessions = (await Promise.all(records.map((record) => collectElectronManagedSessionTarget({
|
|
739
|
-
cwd,
|
|
740
|
-
sessionName: record.sessionName,
|
|
741
|
-
signal,
|
|
742
|
-
timeoutMs: compiledElectron.timeoutMs,
|
|
743
|
-
})))).filter((managedSession): managedSession is ElectronManagedSessionTarget => managedSession !== undefined);
|
|
744
|
-
const mismatches = managedSessions
|
|
745
|
-
.map((managedSession) => {
|
|
746
|
-
const record = records.find((candidate) => candidate.sessionName === managedSession.sessionName);
|
|
747
|
-
const status = record ? statuses.find((candidate) => candidate.launchId === record.launchId) : undefined;
|
|
748
|
-
return record && status ? buildElectronSessionMismatch({ managedSession, record, statusTargets: status.targets }) : undefined;
|
|
749
|
-
})
|
|
750
|
-
.filter((mismatch): mismatch is ElectronSessionMismatch => mismatch !== undefined);
|
|
751
|
-
return buildElectronStatusResult({
|
|
752
|
-
compiledElectron: redactedCompiledElectron ?? compiledElectron,
|
|
753
|
-
managedSessions,
|
|
754
|
-
mismatches,
|
|
755
|
-
records,
|
|
756
|
-
statuses,
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
if (compiledElectron?.action === "probe") {
|
|
760
|
-
const launchRecord = compiledElectron.launchId
|
|
761
|
-
? electronLaunchRecords.get(compiledElectron.launchId)
|
|
762
|
-
: findElectronLaunchRecordForSession(managedSessionName, electronLaunchRecords);
|
|
763
|
-
if (compiledElectron.launchId && !launchRecord) {
|
|
764
|
-
return buildElectronHostFailureResult({
|
|
765
|
-
compiledElectron: redactedCompiledElectron ?? compiledElectron,
|
|
766
|
-
errorText: `No wrapper-tracked Electron launch found for launchId ${compiledElectron.launchId}.`,
|
|
767
|
-
failureCategory: "validation-error",
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
|
-
if (compiledElectron.launchId && !launchRecord?.sessionName) {
|
|
771
|
-
return buildElectronHostFailureResult({
|
|
772
|
-
compiledElectron: redactedCompiledElectron ?? compiledElectron,
|
|
773
|
-
errorText: `electron.probe launchId ${compiledElectron.launchId} has no attached managed sessionName; reattach with connect or run electron.launch again.`,
|
|
774
|
-
failureCategory: "validation-error",
|
|
775
|
-
});
|
|
776
|
-
}
|
|
777
|
-
if (!compiledElectron.launchId && !managedSessionActive) {
|
|
778
|
-
return buildElectronHostFailureResult({
|
|
779
|
-
compiledElectron: redactedCompiledElectron ?? compiledElectron,
|
|
780
|
-
errorText: "electron.probe requires an active attached session. Run electron.launch or connect to an Electron debug port first.",
|
|
781
|
-
failureCategory: "validation-error",
|
|
782
|
-
});
|
|
783
|
-
}
|
|
784
|
-
const probeSessionName = compiledElectron.launchId ? launchRecord?.sessionName : managedSessionName;
|
|
785
|
-
if (!probeSessionName) {
|
|
786
|
-
return buildElectronHostFailureResult({
|
|
787
|
-
compiledElectron: redactedCompiledElectron ?? compiledElectron,
|
|
788
|
-
errorText: "electron.probe could not resolve a managed session to inspect.",
|
|
789
|
-
failureCategory: "validation-error",
|
|
790
|
-
});
|
|
791
|
-
}
|
|
792
|
-
try {
|
|
793
|
-
const status = launchRecord ? await inspectElectronLaunchStatus(launchRecord) : undefined;
|
|
794
|
-
const probe = await collectElectronProbe({ cwd, sessionName: probeSessionName, signal, timeoutMs: compiledElectron.timeoutMs });
|
|
795
|
-
const managedSession: ElectronManagedSessionTarget = {
|
|
796
|
-
sessionName: probe.sessionName,
|
|
797
|
-
title: probe.title ?? probe.activeTab?.title,
|
|
798
|
-
url: probe.url ?? probe.activeTab?.url,
|
|
799
|
-
};
|
|
800
|
-
const sessionMismatch = launchRecord && status
|
|
801
|
-
? buildElectronSessionMismatch({ managedSession, record: launchRecord, statusTargets: status.targets })
|
|
802
|
-
: undefined;
|
|
803
|
-
const probeContextNote = !launchRecord
|
|
804
|
-
? "No wrapper-tracked Electron launch matched this current managed session."
|
|
805
|
-
: !compiledElectron.launchId && launchRecord.sessionName && launchRecord.sessionName !== probe.sessionName
|
|
806
|
-
? `single active Electron launch ${launchRecord.launchId} uses wrapper session ${launchRecord.sessionName}; pass electron.probe.launchId to inspect that launch session directly.`
|
|
807
|
-
: undefined;
|
|
808
|
-
const probeContext: ElectronProbeContext = {
|
|
809
|
-
launchId: launchRecord?.launchId,
|
|
810
|
-
mode: compiledElectron.launchId ? "launchId" : "current-managed-session",
|
|
811
|
-
note: probeContextNote,
|
|
812
|
-
sessionName: probe.sessionName,
|
|
813
|
-
};
|
|
814
|
-
const sessionTabTarget = normalizeSessionTabTarget({
|
|
815
|
-
title: probe.title ?? probe.activeTab?.title ?? probe.refSnapshot?.target?.title,
|
|
816
|
-
url: probe.url ?? probe.activeTab?.url ?? probe.refSnapshot?.target?.url,
|
|
817
|
-
});
|
|
818
|
-
const pageStateUpdate = sessionPageState.beginUpdate();
|
|
819
|
-
if (sessionTabTarget) {
|
|
820
|
-
sessionPageState.applyTabTarget({ sessionName: probe.sessionName, target: sessionTabTarget, update: pageStateUpdate });
|
|
821
|
-
}
|
|
822
|
-
if (probe.refSnapshot) {
|
|
823
|
-
sessionPageState.applyRefSnapshot({
|
|
824
|
-
fallbackTarget: sessionTabTarget,
|
|
825
|
-
sessionName: probe.sessionName,
|
|
826
|
-
snapshot: probe.refSnapshot,
|
|
827
|
-
update: pageStateUpdate,
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
return buildElectronProbeResult({
|
|
831
|
-
compiledElectron: redactedCompiledElectron ?? compiledElectron,
|
|
832
|
-
mismatch: sessionMismatch,
|
|
833
|
-
probe,
|
|
834
|
-
probeContext,
|
|
835
|
-
record: launchRecord,
|
|
836
|
-
sessionTabTarget,
|
|
837
|
-
status,
|
|
838
|
-
});
|
|
839
|
-
} catch (error) {
|
|
840
|
-
const errorText = error instanceof Error ? error.message : String(error);
|
|
841
|
-
return buildElectronHostFailureResult({
|
|
842
|
-
compiledElectron: redactedCompiledElectron ?? compiledElectron,
|
|
843
|
-
errorText: `Electron probe failed: ${errorText}`,
|
|
844
|
-
failureCategory: "upstream-error",
|
|
845
|
-
});
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
if (compiledElectron?.action === "cleanup") {
|
|
849
|
-
const selection = selectElectronRecords(compiledElectron, electronLaunchRecords);
|
|
850
|
-
if (selection.error) return buildElectronHostFailureResult({ compiledElectron: redactedCompiledElectron ?? compiledElectron, errorText: selection.error, failureCategory: "validation-error" });
|
|
851
|
-
const cleanupResults = await cleanupTrackedElectronHostLaunches({ cwd, electronChildProcesses, electronLaunchRecords, records: selection.records ?? [], timeoutMs: compiledElectron.timeoutMs ?? implicitSessionCloseTimeoutMs });
|
|
852
|
-
return buildElectronCleanupResult(redactedCompiledElectron ?? compiledElectron, cleanupResults);
|
|
853
|
-
}
|
|
854
|
-
return undefined;
|
|
855
|
-
}
|