pi-agent-browser-native 0.2.47 → 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 +63 -19
- package/README.md +52 -19
- 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/ARCHITECTURE.md +10 -10
- package/docs/COMMAND_REFERENCE.md +35 -21
- package/docs/ELECTRON.md +3 -3
- package/docs/RELEASE.md +46 -26
- package/docs/REQUIREMENTS.md +1 -1
- package/docs/SUPPORT_MATRIX.md +35 -106
- package/docs/TOOL_CONTRACT.md +23 -21
- package/package.json +12 -8
- package/scripts/agent-browser-capability-baseline.mjs +6 -3
- package/scripts/config.mjs +8 -2
- package/scripts/doctor.mjs +19 -17
- package/scripts/platform-smoke.mjs +1 -1
- package/extensions/agent-browser/index.ts +0 -952
- 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 -209
- 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 -451
- 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/click-dispatch.ts +0 -257
- package/extensions/agent-browser/lib/orchestration/browser-run/diagnostics.ts +0 -912
- package/extensions/agent-browser/lib/orchestration/browser-run/final-result.ts +0 -512
- package/extensions/agent-browser/lib/orchestration/browser-run/index.ts +0 -53
- package/extensions/agent-browser/lib/orchestration/browser-run/prepare.ts +0 -1481
- package/extensions/agent-browser/lib/orchestration/browser-run/process-output.ts +0 -564
- package/extensions/agent-browser/lib/orchestration/browser-run/prompt-guards.ts +0 -47
- package/extensions/agent-browser/lib/orchestration/browser-run/session-state.ts +0 -868
- package/extensions/agent-browser/lib/orchestration/browser-run/types.ts +0 -564
- 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 -252
- 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 -721
- /package/{extensions/agent-browser/lib/orchestration/browser-run.ts → dist/extensions/agent-browser/lib/orchestration/browser-run.js} +0 -0
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Purpose: Render parsed agent-browser results into concise pi-facing summaries, text content, and optional inline image attachments.
|
|
3
|
-
* Responsibilities: Orchestrate specialized presentation modules, attach inline images within size limits, and keep generic record formatting distinct from envelope parsing.
|
|
4
|
-
* Scope: Presentation shaping only; upstream stdout parsing and snapshot compaction internals live in separate modules.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { CompiledAgentBrowserSemanticAction } from "../input-modes/types.js";
|
|
8
|
-
import { isRecord } from "../parsing.js";
|
|
9
|
-
import type { CommandInfo } from "../runtime.js";
|
|
10
|
-
import type { PersistentSessionArtifactStore } from "../temp.js";
|
|
11
|
-
import { buildAgentBrowserNextActions } from "./action-recommendations.js";
|
|
12
|
-
import { buildAgentBrowserResultCategoryDetails } from "./categories.js";
|
|
13
|
-
import { detectConfirmationRequired } from "./confirmation.js";
|
|
14
|
-
import type {
|
|
15
|
-
AgentBrowserEnvelope,
|
|
16
|
-
AgentBrowserNextAction,
|
|
17
|
-
NetworkRouteDiagnostic,
|
|
18
|
-
SessionArtifactManifest,
|
|
19
|
-
ToolPresentation,
|
|
20
|
-
} from "./contracts.js";
|
|
21
|
-
import { buildSnapshotPresentation } from "./snapshot.js";
|
|
22
|
-
import { parseJsonPreviewString, redactModelFacingText, stringifyModelFacing } from "./presentation/common.js";
|
|
23
|
-
import {
|
|
24
|
-
applyArtifactManifest,
|
|
25
|
-
attachInlineImage,
|
|
26
|
-
buildArtifactVerificationSummary,
|
|
27
|
-
buildManifestEntriesForFileArtifacts,
|
|
28
|
-
classifyPresentationSuccessCategory,
|
|
29
|
-
extractFileArtifacts,
|
|
30
|
-
extractImagePath,
|
|
31
|
-
formatArtifactMetadataLines,
|
|
32
|
-
formatArtifactSummary,
|
|
33
|
-
formatMissingArtifactFailureText,
|
|
34
|
-
getSavedFileDetails,
|
|
35
|
-
hasMissingFileArtifact,
|
|
36
|
-
isManifestFileArtifact,
|
|
37
|
-
type ArtifactRequestContext,
|
|
38
|
-
} from "./presentation/artifacts.js";
|
|
39
|
-
import { buildBatchPresentation, isAgentBrowserBatchResultArray } from "./presentation/batch.js";
|
|
40
|
-
import { getPresentationPaths } from "./presentation/content.js";
|
|
41
|
-
import {
|
|
42
|
-
buildNetworkRequestsNextActions,
|
|
43
|
-
buildStreamNextActions,
|
|
44
|
-
enrichStreamStatusData,
|
|
45
|
-
formatNetworkRouteDiagnosticsText,
|
|
46
|
-
redactPresentationData,
|
|
47
|
-
} from "./presentation/diagnostics.js";
|
|
48
|
-
import { buildErrorPresentation } from "./presentation/errors.js";
|
|
49
|
-
import { compactLargePresentationOutput } from "./presentation/large-output.js";
|
|
50
|
-
import { buildPageChangeSummary } from "./presentation/navigation.js";
|
|
51
|
-
import { formatPresentationContentText, formatPresentationSummary } from "./presentation/registry.js";
|
|
52
|
-
import { resolvePresentationCommandInfo } from "./presentation/semantic-action.js";
|
|
53
|
-
|
|
54
|
-
function sanitizeModelFacingPresentation(presentation: ToolPresentation): ToolPresentation {
|
|
55
|
-
presentation.content = presentation.content.map((item) => {
|
|
56
|
-
if (item.type !== "text") return item;
|
|
57
|
-
const parsed = parseJsonPreviewString(item.text);
|
|
58
|
-
return parsed === item.text ? item : { ...item, text: stringifyModelFacing(parsed) };
|
|
59
|
-
});
|
|
60
|
-
presentation.summary = redactModelFacingText(presentation.summary);
|
|
61
|
-
return presentation;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function mergeNextActions(...groups: Array<AgentBrowserNextAction[] | undefined>): AgentBrowserNextAction[] | undefined {
|
|
65
|
-
const merged = groups.flatMap((group) => group ?? []);
|
|
66
|
-
return merged.length > 0 ? merged : undefined;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function shouldAddAnnotatedScreenshotGuidance(commandInfo: CommandInfo, args: string[] | undefined): boolean {
|
|
70
|
-
return commandInfo.command === "screenshot" && (args?.includes("--annotate") ?? false);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export async function buildToolPresentation(options: {
|
|
74
|
-
artifactManifest?: SessionArtifactManifest;
|
|
75
|
-
args?: string[];
|
|
76
|
-
artifactRequest?: ArtifactRequestContext;
|
|
77
|
-
batchArtifactRequests?: Array<ArtifactRequestContext | undefined>;
|
|
78
|
-
commandInfo: CommandInfo;
|
|
79
|
-
compiledSemanticAction?: CompiledAgentBrowserSemanticAction;
|
|
80
|
-
cwd: string;
|
|
81
|
-
envelope?: AgentBrowserEnvelope;
|
|
82
|
-
errorText?: string;
|
|
83
|
-
networkRouteDiagnostics?: NetworkRouteDiagnostic[];
|
|
84
|
-
networkRoutes?: import("./contracts.js").NetworkRouteRecord[];
|
|
85
|
-
persistentArtifactStore?: PersistentSessionArtifactStore;
|
|
86
|
-
sessionName?: string;
|
|
87
|
-
}): Promise<ToolPresentation> {
|
|
88
|
-
const {
|
|
89
|
-
args,
|
|
90
|
-
artifactManifest,
|
|
91
|
-
artifactRequest,
|
|
92
|
-
commandInfo,
|
|
93
|
-
compiledSemanticAction,
|
|
94
|
-
cwd,
|
|
95
|
-
envelope,
|
|
96
|
-
errorText,
|
|
97
|
-
networkRouteDiagnostics,
|
|
98
|
-
networkRoutes,
|
|
99
|
-
persistentArtifactStore,
|
|
100
|
-
sessionName,
|
|
101
|
-
} = options;
|
|
102
|
-
const presentationCommandInfo = resolvePresentationCommandInfo(commandInfo, compiledSemanticAction);
|
|
103
|
-
|
|
104
|
-
if (errorText) {
|
|
105
|
-
return buildErrorPresentation({ args, commandInfo, errorText, sessionName });
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const data = enrichStreamStatusData(commandInfo, envelope?.data);
|
|
109
|
-
const presentationData = redactPresentationData(commandInfo, data);
|
|
110
|
-
const artifacts = await extractFileArtifacts({ artifactManifest, artifactRequest, commandInfo: presentationCommandInfo, cwd, data, sessionName });
|
|
111
|
-
const artifactVerification = buildArtifactVerificationSummary(artifacts);
|
|
112
|
-
const artifactSummary = formatArtifactSummary(artifacts);
|
|
113
|
-
const summary = artifactSummary ?? formatPresentationSummary(commandInfo, data, compiledSemanticAction);
|
|
114
|
-
const artifactText = artifacts.length > 0 ? formatArtifactMetadataLines(artifacts).join("\n") : undefined;
|
|
115
|
-
|
|
116
|
-
let presentation: ToolPresentation;
|
|
117
|
-
if (commandInfo.command === "batch" && isAgentBrowserBatchResultArray(data)) {
|
|
118
|
-
presentation = await buildBatchPresentation({
|
|
119
|
-
artifactManifest,
|
|
120
|
-
artifactRequests: options.batchArtifactRequests,
|
|
121
|
-
buildNestedToolPresentation: buildToolPresentation,
|
|
122
|
-
cwd,
|
|
123
|
-
data,
|
|
124
|
-
networkRoutes,
|
|
125
|
-
persistentArtifactStore,
|
|
126
|
-
sessionName,
|
|
127
|
-
summary,
|
|
128
|
-
});
|
|
129
|
-
} else if (commandInfo.command === "snapshot" && isRecord(data)) {
|
|
130
|
-
presentation = await buildSnapshotPresentation(data, persistentArtifactStore, artifactManifest);
|
|
131
|
-
} else {
|
|
132
|
-
presentation = {
|
|
133
|
-
artifactVerification,
|
|
134
|
-
artifacts: artifacts.length > 0 ? artifacts : undefined,
|
|
135
|
-
content: [{ type: "text", text: artifactText ?? formatPresentationContentText(commandInfo, data, compiledSemanticAction) }],
|
|
136
|
-
data: presentationData,
|
|
137
|
-
summary,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (networkRouteDiagnostics && networkRouteDiagnostics.length > 0 && presentation.content[0]?.type === "text") {
|
|
142
|
-
const diagnosticText = formatNetworkRouteDiagnosticsText(networkRouteDiagnostics);
|
|
143
|
-
if (diagnosticText) presentation.content[0] = { ...presentation.content[0], text: `${diagnosticText}\n\n${presentation.content[0].text}` };
|
|
144
|
-
presentation.networkRouteDiagnostics = networkRouteDiagnostics;
|
|
145
|
-
}
|
|
146
|
-
if (artifacts.length > 0 && !presentation.artifacts) {
|
|
147
|
-
presentation.artifacts = artifacts;
|
|
148
|
-
}
|
|
149
|
-
presentation.artifactVerification = presentation.artifactVerification ?? artifactVerification;
|
|
150
|
-
if (isRecord(data)) {
|
|
151
|
-
const savedFile = getSavedFileDetails(commandInfo, data);
|
|
152
|
-
if (savedFile) {
|
|
153
|
-
presentation.savedFile = savedFile;
|
|
154
|
-
presentation.savedFilePath = savedFile.path;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (shouldAddAnnotatedScreenshotGuidance(commandInfo, args) && presentation.content[0]?.type === "text") {
|
|
159
|
-
const guidance = "Annotated screenshot note: dense pages can produce overlapping labels. If the labels are noisy, capture a scoped element screenshot, take a non-annotated screenshot, or use snapshot -i high-value refs as the machine-readable map.";
|
|
160
|
-
presentation.content[0] = { ...presentation.content[0], text: `${presentation.content[0].text}\n\n${guidance}` };
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const imagePath = artifactRequest?.absolutePath ?? extractImagePath(commandInfo, cwd, data);
|
|
164
|
-
const presentationWithImage = imagePath ? await attachInlineImage(presentation, imagePath) : presentation;
|
|
165
|
-
const compactedPresentation = await compactLargePresentationOutput({
|
|
166
|
-
artifactManifest,
|
|
167
|
-
commandInfo,
|
|
168
|
-
data: presentationData,
|
|
169
|
-
persistentArtifactStore,
|
|
170
|
-
presentation: presentationWithImage,
|
|
171
|
-
});
|
|
172
|
-
const presentationWithManifest = applyArtifactManifest(
|
|
173
|
-
compactedPresentation,
|
|
174
|
-
compactedPresentation.artifactManifest ?? artifactManifest,
|
|
175
|
-
buildManifestEntriesForFileArtifacts(artifacts.filter(isManifestFileArtifact)),
|
|
176
|
-
);
|
|
177
|
-
const currentSpillPaths = new Set(getPresentationPaths({
|
|
178
|
-
primaryPath: presentationWithManifest.fullOutputPath,
|
|
179
|
-
secondaryPaths: presentationWithManifest.fullOutputPaths,
|
|
180
|
-
}));
|
|
181
|
-
presentationWithManifest.artifactVerification = buildArtifactVerificationSummary(
|
|
182
|
-
artifacts,
|
|
183
|
-
presentationWithManifest.artifactManifest,
|
|
184
|
-
currentSpillPaths,
|
|
185
|
-
) ?? presentationWithManifest.artifactVerification;
|
|
186
|
-
|
|
187
|
-
const confirmationRequired = detectConfirmationRequired(data);
|
|
188
|
-
const missingArtifactFailureText = formatMissingArtifactFailureText(presentationWithManifest.artifacts);
|
|
189
|
-
if (missingArtifactFailureText && hasMissingFileArtifact(presentationWithManifest.artifacts)) {
|
|
190
|
-
presentationWithManifest.resultCategory = "failure";
|
|
191
|
-
presentationWithManifest.failureCategory = "artifact-missing";
|
|
192
|
-
presentationWithManifest.successCategory = undefined;
|
|
193
|
-
presentationWithManifest.summary = missingArtifactFailureText;
|
|
194
|
-
if (presentationWithManifest.content[0]?.type === "text") {
|
|
195
|
-
presentationWithManifest.content[0] = { ...presentationWithManifest.content[0], text: `${missingArtifactFailureText}\n\n${presentationWithManifest.content[0].text}` };
|
|
196
|
-
} else {
|
|
197
|
-
presentationWithManifest.content.unshift({ type: "text", text: missingArtifactFailureText });
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (!presentationWithManifest.resultCategory) {
|
|
202
|
-
const categoryDetails = buildAgentBrowserResultCategoryDetails({
|
|
203
|
-
artifacts: presentationWithManifest.artifacts,
|
|
204
|
-
command: presentationCommandInfo.command,
|
|
205
|
-
confirmationRequired: confirmationRequired !== undefined,
|
|
206
|
-
errorText: envelope?.success === false ? presentationWithManifest.summary : undefined,
|
|
207
|
-
savedFile: presentationWithManifest.savedFile,
|
|
208
|
-
succeeded: envelope?.success !== false,
|
|
209
|
-
});
|
|
210
|
-
presentationWithManifest.resultCategory = categoryDetails.resultCategory;
|
|
211
|
-
presentationWithManifest.successCategory = categoryDetails.resultCategory === "success"
|
|
212
|
-
? classifyPresentationSuccessCategory({
|
|
213
|
-
artifactVerification: presentationWithManifest.artifactVerification,
|
|
214
|
-
artifacts: presentationWithManifest.artifacts,
|
|
215
|
-
savedFile: presentationWithManifest.savedFile,
|
|
216
|
-
})
|
|
217
|
-
: categoryDetails.successCategory;
|
|
218
|
-
presentationWithManifest.failureCategory = categoryDetails.failureCategory;
|
|
219
|
-
}
|
|
220
|
-
if (presentationWithManifest.resultCategory === "success") {
|
|
221
|
-
presentationWithManifest.successCategory = classifyPresentationSuccessCategory({
|
|
222
|
-
artifactVerification: presentationWithManifest.artifactVerification,
|
|
223
|
-
artifacts: presentationWithManifest.artifacts,
|
|
224
|
-
savedFile: presentationWithManifest.savedFile,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const genericNextActions = presentationWithManifest.nextActions ? undefined : buildAgentBrowserNextActions({
|
|
229
|
-
artifacts: presentationWithManifest.artifacts,
|
|
230
|
-
args,
|
|
231
|
-
command: presentationCommandInfo.command,
|
|
232
|
-
confirmationId: confirmationRequired?.id,
|
|
233
|
-
failureCategory: presentationWithManifest.failureCategory,
|
|
234
|
-
resultCategory: presentationWithManifest.resultCategory ?? "success",
|
|
235
|
-
savedFilePath: presentationWithManifest.savedFilePath,
|
|
236
|
-
successCategory: presentationWithManifest.successCategory,
|
|
237
|
-
});
|
|
238
|
-
const networkNextActions = commandInfo.command === "network" && commandInfo.subcommand === "requests" && presentationWithManifest.resultCategory === "success"
|
|
239
|
-
? buildNetworkRequestsNextActions(data, sessionName, presentationWithManifest.networkRouteDiagnostics)
|
|
240
|
-
: undefined;
|
|
241
|
-
const streamNextActions = presentationWithManifest.resultCategory === "success" ? buildStreamNextActions(commandInfo, data, sessionName) : undefined;
|
|
242
|
-
presentationWithManifest.nextActions = mergeNextActions(
|
|
243
|
-
presentationWithManifest.nextActions,
|
|
244
|
-
genericNextActions,
|
|
245
|
-
networkNextActions,
|
|
246
|
-
streamNextActions,
|
|
247
|
-
);
|
|
248
|
-
presentationWithManifest.pageChangeSummary = presentationWithManifest.pageChangeSummary ?? buildPageChangeSummary({
|
|
249
|
-
artifacts: presentationWithManifest.artifacts,
|
|
250
|
-
commandInfo: presentationCommandInfo,
|
|
251
|
-
data,
|
|
252
|
-
nextActions: presentationWithManifest.nextActions,
|
|
253
|
-
savedFilePath: presentationWithManifest.savedFilePath,
|
|
254
|
-
summary: presentationWithManifest.summary,
|
|
255
|
-
});
|
|
256
|
-
return sanitizeModelFacingPresentation(presentationWithManifest);
|
|
257
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Purpose: Centralize recovery-oriented nextAction ids and action construction.
|
|
3
|
-
* Responsibilities: Build tab/about:blank/no-active-page/connected-session follow-ups and rich-input recovery ids.
|
|
4
|
-
* Scope: Recovery action contracts only; result category classification and artifact follow-ups live elsewhere.
|
|
5
|
-
* Usage: Imported by shared result action builders and the extension entrypoint.
|
|
6
|
-
* Invariants/Assumptions: Ids are public machine-readable contracts mirrored by docs and tests.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { buildNextToolAction, type AgentBrowserNextAction, withOptionalSessionArgs } from "./next-actions.js";
|
|
10
|
-
|
|
11
|
-
export type AgentBrowserRecoveryKind = "about-blank" | "connected-session" | "no-active-page" | "tab-drift";
|
|
12
|
-
|
|
13
|
-
export interface AgentBrowserRecoveryContext {
|
|
14
|
-
kind: AgentBrowserRecoveryKind;
|
|
15
|
-
recoveryApplied?: boolean;
|
|
16
|
-
selectedTab?: string;
|
|
17
|
-
sessionName?: string;
|
|
18
|
-
targetTitle?: string;
|
|
19
|
-
targetUrl?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const AGENT_BROWSER_RECOVERY_NEXT_ACTION_IDS = {
|
|
23
|
-
aboutBlankListTabs: "list-tabs-for-about-blank-recovery",
|
|
24
|
-
connectedSessionListTabs: "list-connected-session-tabs",
|
|
25
|
-
genericTabDriftListTabs: "list-tabs-for-recovery",
|
|
26
|
-
noActivePageListTabs: "list-tabs-after-no-active-page",
|
|
27
|
-
selectIntendedTabAfterDrift: "select-intended-tab-after-drift",
|
|
28
|
-
snapshotAfterTabRecovery: "snapshot-after-tab-recovery",
|
|
29
|
-
tabDriftListTabs: "list-tabs-for-tab-drift-recovery",
|
|
30
|
-
} as const;
|
|
31
|
-
|
|
32
|
-
export const AGENT_BROWSER_RICH_INPUT_RECOVERY_NEXT_ACTION_IDS = {
|
|
33
|
-
click: "click-current-editable-ref",
|
|
34
|
-
focus: "focus-current-editable-ref",
|
|
35
|
-
} as const;
|
|
36
|
-
|
|
37
|
-
export type AgentBrowserRichInputRecoveryNextActionKind = keyof typeof AGENT_BROWSER_RICH_INPUT_RECOVERY_NEXT_ACTION_IDS;
|
|
38
|
-
|
|
39
|
-
function getNumberedAgentBrowserNextActionId(baseId: string, index: number, total: number): string {
|
|
40
|
-
return total > 1 ? `${baseId}-${index + 1}` : baseId;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function getAgentBrowserRichInputRecoveryNextActionId(kind: AgentBrowserRichInputRecoveryNextActionKind, index: number, candidateCount: number): string {
|
|
44
|
-
return getNumberedAgentBrowserNextActionId(AGENT_BROWSER_RICH_INPUT_RECOVERY_NEXT_ACTION_IDS[kind], index, candidateCount);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function getAgentBrowserRichInputRecoveryNextActionIds(candidateCount: number): string[] {
|
|
48
|
-
const ids: string[] = [];
|
|
49
|
-
for (let index = 0; index < candidateCount; index += 1) {
|
|
50
|
-
ids.push(
|
|
51
|
-
getAgentBrowserRichInputRecoveryNextActionId("focus", index, candidateCount),
|
|
52
|
-
getAgentBrowserRichInputRecoveryNextActionId("click", index, candidateCount),
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return ids;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function getRecoveryTargetDescription(recovery: AgentBrowserRecoveryContext): string {
|
|
59
|
-
const target = [recovery.targetTitle, recovery.targetUrl].filter((item): item is string => item !== undefined && item.length > 0).join(" at ");
|
|
60
|
-
return target.length > 0 ? target : "the intended tab";
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function isStableTabId(tab: string | undefined): tab is string {
|
|
64
|
-
return /^t\d+$/.test(tab ?? "");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function buildTabSnapshotRecoveryAction(options: {
|
|
68
|
-
id: string;
|
|
69
|
-
reason: string;
|
|
70
|
-
recovery: AgentBrowserRecoveryContext;
|
|
71
|
-
safety: string;
|
|
72
|
-
sessionArgs: (args: string[]) => string[];
|
|
73
|
-
tabId: string;
|
|
74
|
-
}): AgentBrowserNextAction {
|
|
75
|
-
if (options.recovery.recoveryApplied === true) {
|
|
76
|
-
return buildNextToolAction({
|
|
77
|
-
args: options.sessionArgs(["snapshot", "-i"]),
|
|
78
|
-
id: options.id,
|
|
79
|
-
reason: options.reason,
|
|
80
|
-
safety: options.safety,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return buildNextToolAction({
|
|
84
|
-
args: options.sessionArgs(["batch"]),
|
|
85
|
-
id: options.id,
|
|
86
|
-
reason: `${options.reason} The batch selects the stable tab before snapshotting.`,
|
|
87
|
-
safety: `${options.safety} The snapshot retry is atomic with tab selection, so it does not assume the intended tab is already active.`,
|
|
88
|
-
stdin: JSON.stringify([["tab", options.tabId], ["snapshot", "-i"]]),
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function buildRecoveryNextActions(recovery: AgentBrowserRecoveryContext): AgentBrowserNextAction[] {
|
|
93
|
-
const sessionArgs = (args: string[]) => withOptionalSessionArgs(recovery.sessionName, args);
|
|
94
|
-
if (recovery.kind === "connected-session") {
|
|
95
|
-
return [
|
|
96
|
-
buildNextToolAction({
|
|
97
|
-
args: sessionArgs(["tab", "list"]),
|
|
98
|
-
id: AGENT_BROWSER_RECOVERY_NEXT_ACTION_IDS.connectedSessionListTabs,
|
|
99
|
-
reason: "Inspect tabs exposed by the connected CDP endpoint before assuming the app surface is active.",
|
|
100
|
-
safety: "Read-only. Raw connect can succeed before the desktop app has an active rendered page.",
|
|
101
|
-
}),
|
|
102
|
-
];
|
|
103
|
-
}
|
|
104
|
-
if (recovery.kind === "no-active-page") {
|
|
105
|
-
return [
|
|
106
|
-
buildNextToolAction({
|
|
107
|
-
args: sessionArgs(["tab", "list"]),
|
|
108
|
-
id: AGENT_BROWSER_RECOVERY_NEXT_ACTION_IDS.noActivePageListTabs,
|
|
109
|
-
reason: "The snapshot found no active page; inspect the session tabs before retrying refs.",
|
|
110
|
-
safety: "Read-only tab listing for the same connected session.",
|
|
111
|
-
}),
|
|
112
|
-
];
|
|
113
|
-
}
|
|
114
|
-
const targetDescription = getRecoveryTargetDescription(recovery);
|
|
115
|
-
const listAction = buildNextToolAction({
|
|
116
|
-
args: sessionArgs(["tab", "list"]),
|
|
117
|
-
id: recovery.kind === "about-blank" ? AGENT_BROWSER_RECOVERY_NEXT_ACTION_IDS.aboutBlankListTabs : AGENT_BROWSER_RECOVERY_NEXT_ACTION_IDS.tabDriftListTabs,
|
|
118
|
-
reason: `Inspect tabs for ${targetDescription} before continuing after tab drift.`,
|
|
119
|
-
safety: "Read-only tab listing; prefer stable tN tab ids over positional tab guesses.",
|
|
120
|
-
});
|
|
121
|
-
if (!isStableTabId(recovery.selectedTab)) return [listAction];
|
|
122
|
-
return [
|
|
123
|
-
listAction,
|
|
124
|
-
buildNextToolAction({
|
|
125
|
-
args: sessionArgs(["tab", recovery.selectedTab]),
|
|
126
|
-
id: AGENT_BROWSER_RECOVERY_NEXT_ACTION_IDS.selectIntendedTabAfterDrift,
|
|
127
|
-
reason: `Re-select ${targetDescription} with the stable tab id already observed by the wrapper.`,
|
|
128
|
-
safety: "Switches only the active tab in this browser session; it does not mutate page content.",
|
|
129
|
-
}),
|
|
130
|
-
buildTabSnapshotRecoveryAction({
|
|
131
|
-
id: AGENT_BROWSER_RECOVERY_NEXT_ACTION_IDS.snapshotAfterTabRecovery,
|
|
132
|
-
reason: "Refresh interactive refs on the recovered tab before using @e refs again.",
|
|
133
|
-
recovery,
|
|
134
|
-
safety: "Read-only snapshot. Treat previous refs as stale until this succeeds.",
|
|
135
|
-
sessionArgs,
|
|
136
|
-
tabId: recovery.selectedTab,
|
|
137
|
-
}),
|
|
138
|
-
];
|
|
139
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Purpose: Build session-aware recovery nextActions that combine result category policy with known session/tab context.
|
|
3
|
-
* Responsibilities: Prefix recovery argv with the active session and adapt tab/about:blank/no-active/stale-ref contexts into stable nextAction lists.
|
|
4
|
-
* Scope: Recovery nextAction assembly only; diagnostic detection and action-list merge ordering stay in the extension entrypoint.
|
|
5
|
-
* Usage: Imported by the extension entrypoint when adding recovery nextActions to tool details.
|
|
6
|
-
* Invariants/Assumptions: Action ids and argv ordering are public contracts; session prefixing must not double-prefix explicit --session args.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { buildAgentBrowserNextActions } from "./action-recommendations.js";
|
|
10
|
-
import { type AgentBrowserNextAction, withOptionalSessionArgs } from "./next-actions.js";
|
|
11
|
-
|
|
12
|
-
export interface TabRecoveryCorrection {
|
|
13
|
-
selectedTab?: string;
|
|
14
|
-
targetTitle?: string;
|
|
15
|
-
targetUrl?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface TabRecoveryTarget {
|
|
19
|
-
title?: string;
|
|
20
|
-
url?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function buildConnectedSessionNextActions(sessionName: string | undefined): AgentBrowserNextAction[] {
|
|
24
|
-
if (!sessionName) return [];
|
|
25
|
-
return buildAgentBrowserNextActions({
|
|
26
|
-
recovery: { kind: "connected-session", sessionName },
|
|
27
|
-
resultCategory: "success",
|
|
28
|
-
successCategory: "completed",
|
|
29
|
-
}) ?? [];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function buildNoActivePageNextActions(sessionName: string | undefined): AgentBrowserNextAction[] {
|
|
33
|
-
if (!sessionName) return [];
|
|
34
|
-
return buildAgentBrowserNextActions({
|
|
35
|
-
recovery: { kind: "no-active-page", sessionName },
|
|
36
|
-
resultCategory: "failure",
|
|
37
|
-
}) ?? [];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function buildSessionTabRecoveryNextActions(options: {
|
|
41
|
-
kind: "about-blank" | "tab-drift";
|
|
42
|
-
recoveryApplied?: boolean;
|
|
43
|
-
resultCategory?: "failure" | "success";
|
|
44
|
-
sessionName?: string;
|
|
45
|
-
tabCorrection?: TabRecoveryCorrection;
|
|
46
|
-
target?: TabRecoveryTarget;
|
|
47
|
-
}): AgentBrowserNextAction[] {
|
|
48
|
-
const resultCategory = options.resultCategory ?? "success";
|
|
49
|
-
return buildAgentBrowserNextActions({
|
|
50
|
-
recovery: {
|
|
51
|
-
kind: options.kind,
|
|
52
|
-
recoveryApplied: options.recoveryApplied,
|
|
53
|
-
selectedTab: options.tabCorrection?.selectedTab,
|
|
54
|
-
sessionName: options.sessionName,
|
|
55
|
-
targetTitle: options.tabCorrection?.targetTitle ?? options.target?.title,
|
|
56
|
-
targetUrl: options.tabCorrection?.targetUrl ?? options.target?.url,
|
|
57
|
-
},
|
|
58
|
-
resultCategory,
|
|
59
|
-
successCategory: resultCategory === "success" ? "completed" : undefined,
|
|
60
|
-
}) ?? [];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function buildSessionAwareStaleRefNextActions(sessionName: string | undefined): AgentBrowserNextAction[] {
|
|
64
|
-
return (buildAgentBrowserNextActions({ failureCategory: "stale-ref", resultCategory: "failure" }) ?? []).map((action) => {
|
|
65
|
-
const actionArgs = action.params?.args;
|
|
66
|
-
return {
|
|
67
|
-
...action,
|
|
68
|
-
params: action.params && actionArgs ? { ...action.params, args: withOptionalSessionArgs(sessionName, actionArgs) } : action.params,
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
}
|