pi-agent-browser-native 0.2.48 → 0.2.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +21 -11
  3. package/dist/extensions/agent-browser/index.js +808 -0
  4. package/dist/extensions/agent-browser/lib/argv-descriptor.js +71 -0
  5. package/dist/extensions/agent-browser/lib/argv-grammar.js +121 -0
  6. package/dist/extensions/agent-browser/lib/bash-guard.js +190 -0
  7. package/dist/extensions/agent-browser/lib/command-policy.js +85 -0
  8. package/dist/extensions/agent-browser/lib/command-taxonomy.js +302 -0
  9. package/dist/extensions/agent-browser/lib/config-policy.js +669 -0
  10. package/dist/extensions/agent-browser/lib/config.js +122 -0
  11. package/dist/extensions/agent-browser/lib/electron/cdp.js +51 -0
  12. package/dist/extensions/agent-browser/lib/electron/cleanup.js +212 -0
  13. package/dist/extensions/agent-browser/lib/electron/discovery.js +633 -0
  14. package/dist/extensions/agent-browser/lib/electron/launch.js +351 -0
  15. package/{extensions/agent-browser/lib/electron/text.ts → dist/extensions/agent-browser/lib/electron/text.js} +5 -5
  16. package/dist/extensions/agent-browser/lib/executable-path.js +20 -0
  17. package/dist/extensions/agent-browser/lib/fs-utils.js +18 -0
  18. package/dist/extensions/agent-browser/lib/input-modes/electron.js +165 -0
  19. package/dist/extensions/agent-browser/lib/input-modes/job.js +519 -0
  20. package/dist/extensions/agent-browser/lib/input-modes/lookups.js +440 -0
  21. package/dist/extensions/agent-browser/lib/input-modes/params.js +164 -0
  22. package/dist/extensions/agent-browser/lib/input-modes/semantic-action.js +119 -0
  23. package/dist/extensions/agent-browser/lib/input-modes/shared.js +42 -0
  24. package/dist/extensions/agent-browser/lib/input-modes/types.js +21 -0
  25. package/dist/extensions/agent-browser/lib/input-modes.js +10 -0
  26. package/dist/extensions/agent-browser/lib/json-schema.js +58 -0
  27. package/dist/extensions/agent-browser/lib/launch-scoped-flags.js +59 -0
  28. package/dist/extensions/agent-browser/lib/navigation-policy.js +83 -0
  29. package/dist/extensions/agent-browser/lib/orchestration/batch-stdin.js +62 -0
  30. package/dist/extensions/agent-browser/lib/orchestration/browser-run/artifact-paths.js +39 -0
  31. package/dist/extensions/agent-browser/lib/orchestration/browser-run/click-dispatch.js +276 -0
  32. package/dist/extensions/agent-browser/lib/orchestration/browser-run/diagnostics.js +909 -0
  33. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result.js +443 -0
  34. package/dist/extensions/agent-browser/lib/orchestration/browser-run/index.js +47 -0
  35. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/direct-anchor-download.js +141 -0
  36. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/network-page-filter.js +108 -0
  37. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/scroll-shims.js +112 -0
  38. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-filter.js +158 -0
  39. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/wait-timeouts.js +54 -0
  40. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare.js +762 -0
  41. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output.js +491 -0
  42. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prompt-guards.js +40 -0
  43. package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-artifacts.js +5 -0
  44. package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state.js +731 -0
  45. package/dist/extensions/agent-browser/lib/orchestration/browser-run/types.js +1 -0
  46. package/dist/extensions/agent-browser/lib/orchestration/electron-host/index.js +718 -0
  47. package/dist/extensions/agent-browser/lib/orchestration/input-plan.js +247 -0
  48. package/dist/extensions/agent-browser/lib/orchestration/output-file.js +68 -0
  49. package/{extensions/agent-browser/lib/parsing.ts → dist/extensions/agent-browser/lib/parsing.js} +12 -11
  50. package/dist/extensions/agent-browser/lib/pi-tool-rendering.js +241 -0
  51. package/dist/extensions/agent-browser/lib/playbook.js +121 -0
  52. package/dist/extensions/agent-browser/lib/process.js +363 -0
  53. package/dist/extensions/agent-browser/lib/prompt-policy.js +91 -0
  54. package/dist/extensions/agent-browser/lib/results/action-recommendations.js +220 -0
  55. package/dist/extensions/agent-browser/lib/results/artifact-manifest.js +111 -0
  56. package/{extensions/agent-browser/lib/results/artifact-state.ts → dist/extensions/agent-browser/lib/results/artifact-state.js} +4 -8
  57. package/dist/extensions/agent-browser/lib/results/categories.js +76 -0
  58. package/dist/extensions/agent-browser/lib/results/confirmation.js +63 -0
  59. package/dist/extensions/agent-browser/lib/results/contracts.js +8 -0
  60. package/dist/extensions/agent-browser/lib/results/editable-ref-evidence.js +74 -0
  61. package/dist/extensions/agent-browser/lib/results/envelope.js +166 -0
  62. package/dist/extensions/agent-browser/lib/results/network-routes.js +92 -0
  63. package/dist/extensions/agent-browser/lib/results/network.js +73 -0
  64. package/dist/extensions/agent-browser/lib/results/next-actions.js +72 -0
  65. package/dist/extensions/agent-browser/lib/results/presentation/artifacts.js +515 -0
  66. package/dist/extensions/agent-browser/lib/results/presentation/batch.js +397 -0
  67. package/dist/extensions/agent-browser/lib/results/presentation/browser-profile-recovery.js +55 -0
  68. package/dist/extensions/agent-browser/lib/results/presentation/common.js +46 -0
  69. package/dist/extensions/agent-browser/lib/results/presentation/content.js +24 -0
  70. package/dist/extensions/agent-browser/lib/results/presentation/diagnostics.js +956 -0
  71. package/dist/extensions/agent-browser/lib/results/presentation/errors.js +205 -0
  72. package/dist/extensions/agent-browser/lib/results/presentation/large-output.js +134 -0
  73. package/dist/extensions/agent-browser/lib/results/presentation/navigation.js +159 -0
  74. package/dist/extensions/agent-browser/lib/results/presentation/registry.js +216 -0
  75. package/dist/extensions/agent-browser/lib/results/presentation/semantic-action.js +104 -0
  76. package/dist/extensions/agent-browser/lib/results/presentation/skills.js +152 -0
  77. package/dist/extensions/agent-browser/lib/results/presentation.js +177 -0
  78. package/dist/extensions/agent-browser/lib/results/recovery-actions.js +107 -0
  79. package/dist/extensions/agent-browser/lib/results/recovery-next-actions.js +50 -0
  80. package/dist/extensions/agent-browser/lib/results/selector-recovery.js +225 -0
  81. package/{extensions/agent-browser/lib/results/shared.ts → dist/extensions/agent-browser/lib/results/shared.js} +0 -1
  82. package/dist/extensions/agent-browser/lib/results/snapshot-high-value-controls.js +208 -0
  83. package/dist/extensions/agent-browser/lib/results/snapshot-refs.js +78 -0
  84. package/dist/extensions/agent-browser/lib/results/snapshot-segments.js +331 -0
  85. package/dist/extensions/agent-browser/lib/results/snapshot-spill.js +40 -0
  86. package/dist/extensions/agent-browser/lib/results/snapshot.js +264 -0
  87. package/dist/extensions/agent-browser/lib/results/text.js +40 -0
  88. package/{extensions/agent-browser/lib/results.ts → dist/extensions/agent-browser/lib/results.js} +2 -32
  89. package/dist/extensions/agent-browser/lib/runtime.js +855 -0
  90. package/dist/extensions/agent-browser/lib/session-page-state.js +411 -0
  91. package/dist/extensions/agent-browser/lib/string-enum-schema.js +13 -0
  92. package/dist/extensions/agent-browser/lib/temp.js +498 -0
  93. package/dist/extensions/agent-browser/lib/web-search.js +562 -0
  94. package/docs/ARCHITECTURE.md +5 -5
  95. package/docs/COMMAND_REFERENCE.md +4 -4
  96. package/docs/RELEASE.md +22 -11
  97. package/docs/REQUIREMENTS.md +1 -1
  98. package/docs/SUPPORT_MATRIX.md +5 -4
  99. package/docs/TOOL_CONTRACT.md +1 -1
  100. package/package.json +9 -5
  101. package/scripts/config.mjs +14 -20
  102. package/scripts/doctor.mjs +8 -7
  103. package/extensions/agent-browser/index.ts +0 -961
  104. package/extensions/agent-browser/lib/argv-descriptor.ts +0 -90
  105. package/extensions/agent-browser/lib/argv-grammar.ts +0 -128
  106. package/extensions/agent-browser/lib/bash-guard.ts +0 -205
  107. package/extensions/agent-browser/lib/command-policy.ts +0 -71
  108. package/extensions/agent-browser/lib/command-taxonomy.ts +0 -336
  109. package/extensions/agent-browser/lib/config-policy.js +0 -690
  110. package/extensions/agent-browser/lib/config.ts +0 -211
  111. package/extensions/agent-browser/lib/electron/cdp.ts +0 -69
  112. package/extensions/agent-browser/lib/electron/cleanup.ts +0 -235
  113. package/extensions/agent-browser/lib/electron/discovery.ts +0 -710
  114. package/extensions/agent-browser/lib/electron/launch.ts +0 -499
  115. package/extensions/agent-browser/lib/executable-path.ts +0 -19
  116. package/extensions/agent-browser/lib/fs-utils.ts +0 -18
  117. package/extensions/agent-browser/lib/input-modes/electron.ts +0 -170
  118. package/extensions/agent-browser/lib/input-modes/job.ts +0 -527
  119. package/extensions/agent-browser/lib/input-modes/lookups.ts +0 -447
  120. package/extensions/agent-browser/lib/input-modes/params.ts +0 -205
  121. package/extensions/agent-browser/lib/input-modes/semantic-action.ts +0 -127
  122. package/extensions/agent-browser/lib/input-modes/shared.ts +0 -46
  123. package/extensions/agent-browser/lib/input-modes/types.ts +0 -225
  124. package/extensions/agent-browser/lib/input-modes.ts +0 -45
  125. package/extensions/agent-browser/lib/json-schema.ts +0 -73
  126. package/extensions/agent-browser/lib/launch-scoped-flags.ts +0 -67
  127. package/extensions/agent-browser/lib/navigation-policy.ts +0 -95
  128. package/extensions/agent-browser/lib/orchestration/batch-stdin.ts +0 -65
  129. package/extensions/agent-browser/lib/orchestration/browser-run/artifact-paths.ts +0 -44
  130. package/extensions/agent-browser/lib/orchestration/browser-run/click-dispatch.ts +0 -280
  131. package/extensions/agent-browser/lib/orchestration/browser-run/diagnostics.ts +0 -914
  132. package/extensions/agent-browser/lib/orchestration/browser-run/final-result.ts +0 -521
  133. package/extensions/agent-browser/lib/orchestration/browser-run/index.ts +0 -53
  134. package/extensions/agent-browser/lib/orchestration/browser-run/prepare/direct-anchor-download.ts +0 -158
  135. package/extensions/agent-browser/lib/orchestration/browser-run/prepare/network-page-filter.ts +0 -116
  136. package/extensions/agent-browser/lib/orchestration/browser-run/prepare/scroll-shims.ts +0 -147
  137. package/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-filter.ts +0 -183
  138. package/extensions/agent-browser/lib/orchestration/browser-run/prepare/wait-timeouts.ts +0 -58
  139. package/extensions/agent-browser/lib/orchestration/browser-run/prepare.ts +0 -847
  140. package/extensions/agent-browser/lib/orchestration/browser-run/process-output.ts +0 -559
  141. package/extensions/agent-browser/lib/orchestration/browser-run/prompt-guards.ts +0 -47
  142. package/extensions/agent-browser/lib/orchestration/browser-run/session-artifacts.ts +0 -8
  143. package/extensions/agent-browser/lib/orchestration/browser-run/session-state.ts +0 -868
  144. package/extensions/agent-browser/lib/orchestration/browser-run/types.ts +0 -565
  145. package/extensions/agent-browser/lib/orchestration/electron-host/index.ts +0 -855
  146. package/extensions/agent-browser/lib/orchestration/input-plan.ts +0 -375
  147. package/extensions/agent-browser/lib/orchestration/output-file.ts +0 -86
  148. package/extensions/agent-browser/lib/pi-tool-rendering.ts +0 -267
  149. package/extensions/agent-browser/lib/playbook.ts +0 -142
  150. package/extensions/agent-browser/lib/process.ts +0 -516
  151. package/extensions/agent-browser/lib/prompt-policy.ts +0 -105
  152. package/extensions/agent-browser/lib/results/action-recommendations.ts +0 -264
  153. package/extensions/agent-browser/lib/results/artifact-manifest.ts +0 -111
  154. package/extensions/agent-browser/lib/results/categories.ts +0 -106
  155. package/extensions/agent-browser/lib/results/confirmation.ts +0 -76
  156. package/extensions/agent-browser/lib/results/contracts.ts +0 -241
  157. package/extensions/agent-browser/lib/results/editable-ref-evidence.ts +0 -72
  158. package/extensions/agent-browser/lib/results/envelope.ts +0 -195
  159. package/extensions/agent-browser/lib/results/network-routes.ts +0 -83
  160. package/extensions/agent-browser/lib/results/network.ts +0 -78
  161. package/extensions/agent-browser/lib/results/next-actions.ts +0 -117
  162. package/extensions/agent-browser/lib/results/presentation/artifacts.ts +0 -588
  163. package/extensions/agent-browser/lib/results/presentation/batch.ts +0 -450
  164. package/extensions/agent-browser/lib/results/presentation/browser-profile-recovery.ts +0 -67
  165. package/extensions/agent-browser/lib/results/presentation/common.ts +0 -53
  166. package/extensions/agent-browser/lib/results/presentation/content.ts +0 -36
  167. package/extensions/agent-browser/lib/results/presentation/diagnostics.ts +0 -923
  168. package/extensions/agent-browser/lib/results/presentation/errors.ts +0 -227
  169. package/extensions/agent-browser/lib/results/presentation/large-output.ts +0 -182
  170. package/extensions/agent-browser/lib/results/presentation/navigation.ts +0 -184
  171. package/extensions/agent-browser/lib/results/presentation/registry.ts +0 -242
  172. package/extensions/agent-browser/lib/results/presentation/semantic-action.ts +0 -131
  173. package/extensions/agent-browser/lib/results/presentation/skills.ts +0 -143
  174. package/extensions/agent-browser/lib/results/presentation.ts +0 -257
  175. package/extensions/agent-browser/lib/results/recovery-actions.ts +0 -139
  176. package/extensions/agent-browser/lib/results/recovery-next-actions.ts +0 -71
  177. package/extensions/agent-browser/lib/results/selector-recovery.ts +0 -320
  178. package/extensions/agent-browser/lib/results/snapshot-high-value-controls.ts +0 -273
  179. package/extensions/agent-browser/lib/results/snapshot-refs.ts +0 -100
  180. package/extensions/agent-browser/lib/results/snapshot-segments.ts +0 -366
  181. package/extensions/agent-browser/lib/results/snapshot-spill.ts +0 -63
  182. package/extensions/agent-browser/lib/results/snapshot.ts +0 -329
  183. package/extensions/agent-browser/lib/results/text.ts +0 -40
  184. package/extensions/agent-browser/lib/runtime.ts +0 -988
  185. package/extensions/agent-browser/lib/session-page-state.ts +0 -512
  186. package/extensions/agent-browser/lib/string-enum-schema.ts +0 -20
  187. package/extensions/agent-browser/lib/temp.ts +0 -577
  188. package/extensions/agent-browser/lib/web-search.ts +0 -728
  189. /package/{extensions/agent-browser/lib/orchestration/browser-run.ts → dist/extensions/agent-browser/lib/orchestration/browser-run.js} +0 -0
@@ -0,0 +1,397 @@
1
+ import { isRecord } from "../../parsing.js";
2
+ import { extractCommandTokens, parseCommandInfo, redactInvocationArgs, redactSensitiveText, redactSensitiveValue } from "../../runtime.js";
3
+ import { buildAgentBrowserNextActions } from "../action-recommendations.js";
4
+ import { formatSessionArtifactRetentionSummary } from "../artifact-manifest.js";
5
+ import { classifyAgentBrowserFailureCategory } from "../categories.js";
6
+ import { detectConfirmationRequired } from "../confirmation.js";
7
+ import { applyNetworkRouteRecords, buildNetworkRouteDiagnostics } from "../network-routes.js";
8
+ import { withOptionalSessionArgs } from "../next-actions.js";
9
+ import { stringifyModelFacing } from "./common.js";
10
+ import { buildArtifactVerificationSummary, classifyPresentationSuccessCategory, manifestHasNewNoticeWorthyEntries } from "./artifacts.js";
11
+ import { formatBatchStepCommand, getPresentationImages, getPresentationPaths, getPresentationText, isStringArray } from "./content.js";
12
+ import { buildPageChangeSummary } from "./navigation.js";
13
+ import { appendSelectorRecoveryHint, getClipboardWritePayloadCandidates, redactClipboardPermissionErrorValue } from "./errors.js";
14
+ export function isAgentBrowserBatchResultArray(value) {
15
+ return Array.isArray(value) && value.every(isRecord);
16
+ }
17
+ function isWaitTextAssertionCommand(command) {
18
+ return command?.[0] === "wait" && command.includes("--text");
19
+ }
20
+ function buildWaitTextAssertionFailureNextAction(sessionName) {
21
+ return {
22
+ id: "inspect-after-text-assertion-failure",
23
+ params: { args: withOptionalSessionArgs(sessionName, ["snapshot", "-i"]) },
24
+ reason: "Inspect the current page after the text assertion failed before concluding the expected text is absent.",
25
+ safety: "Read-only snapshot; use current refs or visible text from this page before retrying the assertion.",
26
+ tool: "agent_browser",
27
+ };
28
+ }
29
+ function mergePresentationNextActions(...groups) {
30
+ const actions = [];
31
+ const seen = new Set();
32
+ for (const group of groups) {
33
+ for (const action of group ?? []) {
34
+ if (seen.has(action.id))
35
+ continue;
36
+ actions.push(action);
37
+ seen.add(action.id);
38
+ }
39
+ }
40
+ return actions.length > 0 ? actions : undefined;
41
+ }
42
+ function formatBatchStepError(error) {
43
+ const errorText = stringifyModelFacing(error).trim();
44
+ const formattedErrorText = errorText.length > 0 ? `Error: ${errorText}` : "Error: batch step failed.";
45
+ return appendSelectorRecoveryHint(formattedErrorText);
46
+ }
47
+ function getBatchFailureDetails(steps) {
48
+ const failedSteps = steps.filter((step) => step.details.success === false);
49
+ if (failedSteps.length === 0)
50
+ return undefined;
51
+ const successCount = steps.length - failedSteps.length;
52
+ return {
53
+ failedStep: failedSteps[0].details,
54
+ failureCount: failedSteps.length,
55
+ successCount,
56
+ totalCount: steps.length,
57
+ };
58
+ }
59
+ function hasModelFacingArgRedaction(args) {
60
+ return args?.some((arg) => arg === "[REDACTED]" || arg.includes("%5BREDACTED%5D") || arg.includes("[REDACTED]")) === true;
61
+ }
62
+ function getStatefulCommandSensitiveValues(command) {
63
+ if (!command)
64
+ return [];
65
+ const tokens = extractCommandTokens(command);
66
+ const values = [];
67
+ if (tokens[0] === "cookies" && tokens[1] === "set" && tokens[3])
68
+ values.push(tokens[3]);
69
+ if (tokens[0] === "storage" && ["local", "session"].includes(tokens[1] ?? "") && tokens[2] === "set" && tokens[4])
70
+ values.push(tokens[4]);
71
+ for (let index = 0; index < tokens.length; index += 1) {
72
+ const token = tokens[index];
73
+ if (token === "--password" && tokens[index + 1])
74
+ values.push(tokens[index + 1]);
75
+ else if (token?.startsWith("--password="))
76
+ values.push(token.slice("--password=".length));
77
+ }
78
+ return values.filter((value) => value.length > 0);
79
+ }
80
+ function redactExactValues(value, sensitiveValues) {
81
+ if (sensitiveValues.length === 0)
82
+ return redactSensitiveValue(value);
83
+ if (typeof value === "string") {
84
+ let redacted = value;
85
+ for (const sensitiveValue of sensitiveValues)
86
+ redacted = redacted.split(sensitiveValue).join("[REDACTED]");
87
+ return redactSensitiveText(redacted);
88
+ }
89
+ if (Array.isArray(value))
90
+ return value.map((item) => redactExactValues(item, sensitiveValues));
91
+ if (!isRecord(value))
92
+ return value;
93
+ return redactSensitiveValue(Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [key, redactExactValues(entryValue, sensitiveValues)])));
94
+ }
95
+ function getTypedTextLength(command) {
96
+ return command?.[0] === "keyboard" && command[1] === "type" && typeof command[2] === "string"
97
+ ? Array.from(command[2]).length
98
+ : undefined;
99
+ }
100
+ function getWaitDelayMs(command) {
101
+ return command?.[0] === "wait" && typeof command[1] === "string" && /^\d+$/.test(command[1]) ? command[1] : undefined;
102
+ }
103
+ function formatBatchStepDetails(details, presentation) {
104
+ const inlineImageCount = getPresentationImages(presentation).length;
105
+ const status = details.success ? "succeeded" : "failed";
106
+ const lines = [`Step ${details.index + 1} — ${details.commandText} (${status})`];
107
+ if (details.text.length > 0)
108
+ lines.push(details.text);
109
+ if (inlineImageCount > 0)
110
+ lines.push(`(${inlineImageCount} inline image attachment${inlineImageCount === 1 ? "" : "s"} below)`);
111
+ return lines.join("\n");
112
+ }
113
+ function formatTypedSequenceSummary(steps, startIndex) {
114
+ let index = startIndex;
115
+ const firstDetails = steps[index]?.details;
116
+ if (!firstDetails?.success)
117
+ return undefined;
118
+ let target;
119
+ if (firstDetails.command?.[0] === "focus" && typeof firstDetails.command[1] === "string") {
120
+ target = firstDetails.command[1];
121
+ index += 1;
122
+ }
123
+ let typedCharCount = 0;
124
+ let typedStepCount = 0;
125
+ let delayMs;
126
+ while (index < steps.length) {
127
+ const details = steps[index]?.details;
128
+ if (!details?.success)
129
+ break;
130
+ const typedLength = getTypedTextLength(details.command);
131
+ if (typedLength === undefined)
132
+ break;
133
+ typedCharCount += typedLength;
134
+ typedStepCount += 1;
135
+ index += 1;
136
+ const nextDelay = getWaitDelayMs(steps[index]?.details.command);
137
+ const followingTypedLength = getTypedTextLength(steps[index + 1]?.details.command);
138
+ if (nextDelay !== undefined && followingTypedLength !== undefined && steps[index]?.details.success && steps[index + 1]?.details.success) {
139
+ if (delayMs !== undefined && delayMs !== nextDelay)
140
+ return undefined;
141
+ delayMs = nextDelay;
142
+ index += 1;
143
+ }
144
+ }
145
+ if (typedStepCount < 2)
146
+ return undefined;
147
+ let pressedKey;
148
+ const pressDetails = steps[index]?.details;
149
+ if (pressDetails?.success && pressDetails.command?.[0] === "press" && typeof pressDetails.command[1] === "string") {
150
+ pressedKey = pressDetails.command[1];
151
+ index += 1;
152
+ }
153
+ const firstStep = firstDetails.index + 1;
154
+ const lastStep = steps[index - 1]?.details.index + 1;
155
+ const stepRange = lastStep && lastStep > firstStep ? `${firstStep}-${lastStep}` : String(firstStep);
156
+ const commandLabel = target ? `type ${target}` : "keyboard type";
157
+ const lines = [
158
+ `Step ${stepRange} — ${commandLabel} (succeeded)`,
159
+ `Typed ${typedCharCount} char${typedCharCount === 1 ? "" : "s"}${delayMs ? ` with delayMs=${delayMs}` : ""}.`,
160
+ ];
161
+ if (pressedKey)
162
+ lines.push(`Pressed ${pressedKey}.`);
163
+ return { nextIndex: index, text: lines.join("\n") };
164
+ }
165
+ function formatBatchStepsText(steps) {
166
+ if (steps.length === 0)
167
+ return "(no batch steps)";
168
+ const lines = [];
169
+ for (let index = 0; index < steps.length;) {
170
+ const typedSequence = formatTypedSequenceSummary(steps, index);
171
+ if (typedSequence) {
172
+ lines.push(typedSequence.text);
173
+ index = typedSequence.nextIndex;
174
+ continue;
175
+ }
176
+ const step = steps[index];
177
+ if (step)
178
+ lines.push(formatBatchStepDetails(step.details, step.presentation));
179
+ index += 1;
180
+ }
181
+ return lines.join("\n\n");
182
+ }
183
+ async function buildBatchStepPresentation(options) {
184
+ const { artifactManifest, artifactRequest, buildNestedToolPresentation, cwd, index, item, networkRoutes, persistentArtifactStore, sessionName } = options;
185
+ const command = isStringArray(item.command) ? item.command : undefined;
186
+ const redactedCommand = command ? redactInvocationArgs(command) : undefined;
187
+ const commandText = formatBatchStepCommand(hasModelFacingArgRedaction(redactedCommand) ? redactedCommand : command, index);
188
+ if (item.success === false) {
189
+ const redactedErrorData = command?.[0] === "clipboard"
190
+ ? redactSensitiveValue(redactClipboardPermissionErrorValue({ command: "clipboard", subcommand: command[1] }, item.error, getClipboardWritePayloadCandidates(command)))
191
+ : redactExactValues(item.error, getStatefulCommandSensitiveValues(command));
192
+ const errorText = formatBatchStepError(redactedErrorData);
193
+ const failureCategory = classifyAgentBrowserFailureCategory({
194
+ args: command,
195
+ command: command?.[0],
196
+ errorText,
197
+ });
198
+ const confirmationRequired = detectConfirmationRequired(item.error);
199
+ const nextActions = mergePresentationNextActions(buildAgentBrowserNextActions({
200
+ args: command,
201
+ command: command?.[0],
202
+ confirmationId: confirmationRequired?.id,
203
+ failureCategory,
204
+ resultCategory: "failure",
205
+ }), isWaitTextAssertionCommand(command) ? [buildWaitTextAssertionFailureNextAction(sessionName)] : undefined);
206
+ const presentation = {
207
+ content: [{ type: "text", text: errorText }],
208
+ failureCategory,
209
+ nextActions,
210
+ resultCategory: "failure",
211
+ summary: errorText,
212
+ };
213
+ return {
214
+ details: {
215
+ artifactVerification: presentation.artifactVerification,
216
+ artifacts: presentation.artifacts,
217
+ command: redactedCommand,
218
+ commandText,
219
+ data: redactedErrorData,
220
+ failureCategory,
221
+ index,
222
+ nextActions,
223
+ resultCategory: "failure",
224
+ success: false,
225
+ summary: errorText,
226
+ text: errorText,
227
+ },
228
+ presentation,
229
+ };
230
+ }
231
+ const commandInfo = parseCommandInfo(command ?? []);
232
+ const networkRouteDiagnostics = commandInfo.command === "network" && commandInfo.subcommand === "requests"
233
+ ? buildNetworkRouteDiagnostics(item.result, networkRoutes)
234
+ : undefined;
235
+ const presentation = await buildNestedToolPresentation({
236
+ artifactManifest,
237
+ artifactRequest,
238
+ commandInfo,
239
+ cwd,
240
+ args: command,
241
+ envelope: { data: item.result, success: true },
242
+ networkRouteDiagnostics,
243
+ persistentArtifactStore,
244
+ sessionName,
245
+ });
246
+ const fullOutputPaths = getPresentationPaths({
247
+ primaryPath: presentation.fullOutputPath,
248
+ secondaryPaths: presentation.fullOutputPaths,
249
+ });
250
+ const imagePaths = getPresentationPaths({
251
+ primaryPath: presentation.imagePath,
252
+ secondaryPaths: presentation.imagePaths,
253
+ });
254
+ const text = getPresentationText(presentation) || presentation.summary;
255
+ const stepSucceeded = presentation.resultCategory !== "failure";
256
+ const nextActions = presentation.nextActions ?? buildAgentBrowserNextActions({
257
+ artifacts: presentation.artifacts,
258
+ args: command,
259
+ command: command?.[0],
260
+ failureCategory: presentation.failureCategory,
261
+ resultCategory: stepSucceeded ? "success" : "failure",
262
+ savedFilePath: presentation.savedFilePath,
263
+ successCategory: presentation.successCategory,
264
+ });
265
+ const pageChangeSummary = buildPageChangeSummary({
266
+ artifacts: presentation.artifacts,
267
+ commandInfo,
268
+ data: presentation.data,
269
+ nextActions,
270
+ savedFilePath: presentation.savedFilePath,
271
+ summary: presentation.summary,
272
+ });
273
+ return {
274
+ details: {
275
+ artifactVerification: presentation.artifactVerification,
276
+ artifacts: presentation.artifacts,
277
+ command: redactedCommand,
278
+ commandText,
279
+ data: presentation.data,
280
+ failureCategory: stepSucceeded ? undefined : presentation.failureCategory,
281
+ fullOutputPath: fullOutputPaths[0],
282
+ fullOutputPaths: fullOutputPaths.length > 0 ? fullOutputPaths : undefined,
283
+ imagePath: imagePaths[0],
284
+ imagePaths: imagePaths.length > 0 ? imagePaths : undefined,
285
+ index,
286
+ networkRouteDiagnostics: presentation.networkRouteDiagnostics,
287
+ nextActions,
288
+ pageChangeSummary,
289
+ resultCategory: stepSucceeded ? "success" : "failure",
290
+ savedFile: presentation.savedFile,
291
+ savedFilePath: presentation.savedFilePath,
292
+ success: stepSucceeded,
293
+ successCategory: stepSucceeded ? classifyPresentationSuccessCategory({ artifactVerification: presentation.artifactVerification, artifacts: presentation.artifacts, savedFile: presentation.savedFile }) : undefined,
294
+ summary: presentation.summary,
295
+ text,
296
+ },
297
+ presentation,
298
+ };
299
+ }
300
+ export async function buildBatchPresentation(options) {
301
+ const { artifactRequests, buildNestedToolPresentation, cwd, data, networkRoutes, persistentArtifactStore, sessionName, summary } = options;
302
+ const steps = [];
303
+ const protectedPersistentPaths = [];
304
+ let currentArtifactManifest = options.artifactManifest;
305
+ let currentNetworkRoutes = networkRoutes;
306
+ for (const [index, item] of data.entries()) {
307
+ const step = await buildBatchStepPresentation({
308
+ artifactManifest: currentArtifactManifest,
309
+ artifactRequest: artifactRequests?.[index],
310
+ buildNestedToolPresentation,
311
+ cwd,
312
+ index,
313
+ item,
314
+ networkRoutes: currentNetworkRoutes,
315
+ persistentArtifactStore: persistentArtifactStore ? { ...persistentArtifactStore, protectedPaths: protectedPersistentPaths } : undefined,
316
+ sessionName,
317
+ });
318
+ steps.push(step);
319
+ currentArtifactManifest = step.presentation.artifactManifest ?? currentArtifactManifest;
320
+ currentNetworkRoutes = applyNetworkRouteRecords(currentNetworkRoutes, isStringArray(item.command) ? extractCommandTokens(item.command) : undefined, item.success !== false && step.details.success);
321
+ protectedPersistentPaths.push(...getPresentationPaths({
322
+ primaryPath: step.presentation.fullOutputPath,
323
+ secondaryPaths: step.presentation.fullOutputPaths,
324
+ }));
325
+ }
326
+ const batchFailure = getBatchFailureDetails(steps);
327
+ const images = steps.flatMap((step) => getPresentationImages(step.presentation));
328
+ const artifacts = steps.flatMap((step) => step.presentation.artifacts ?? []);
329
+ const artifactVerification = buildArtifactVerificationSummary(artifacts);
330
+ const fullOutputPaths = steps.flatMap((step) => getPresentationPaths({
331
+ primaryPath: step.presentation.fullOutputPath,
332
+ secondaryPaths: step.presentation.fullOutputPaths,
333
+ }));
334
+ const imagePaths = steps.flatMap((step) => getPresentationPaths({
335
+ primaryPath: step.presentation.imagePath,
336
+ secondaryPaths: step.presentation.imagePaths,
337
+ }));
338
+ const redactedBatchData = steps.map(({ details }) => (details.success
339
+ ? { command: details.command, result: details.data, success: true }
340
+ : { command: details.command, error: details.text, success: false }));
341
+ const stepText = formatBatchStepsText(steps);
342
+ const batchSummary = batchFailure === undefined
343
+ ? summary
344
+ : `Batch failed: ${batchFailure.successCount}/${batchFailure.totalCount} succeeded`;
345
+ const failureHeader = batchFailure === undefined
346
+ ? undefined
347
+ : [
348
+ batchSummary,
349
+ `First failing step: ${batchFailure.failedStep.index + 1} — ${batchFailure.failedStep.commandText}`,
350
+ batchFailure.failureCount > 1 ? `${batchFailure.failureCount} steps failed. See the per-step results below.` : "See the per-step results below.",
351
+ ].join("\n");
352
+ const text = failureHeader ? `${failureHeader}\n\n${stepText}` : stepText;
353
+ const artifactRetentionSummary = currentArtifactManifest ? formatSessionArtifactRetentionSummary(currentArtifactManifest) : undefined;
354
+ const contentText = artifactRetentionSummary && manifestHasNewNoticeWorthyEntries(options.artifactManifest, currentArtifactManifest)
355
+ ? `${text}\n\n${artifactRetentionSummary}`
356
+ : text;
357
+ const nextActions = batchFailure
358
+ ? batchFailure.failedStep.nextActions
359
+ : buildAgentBrowserNextActions({ artifacts, command: "batch", resultCategory: "success" });
360
+ const changedSteps = steps.map((step) => step.details).filter((details) => details.pageChangeSummary !== undefined);
361
+ const pageChangeSummary = artifacts.length > 0
362
+ ? buildPageChangeSummary({
363
+ artifacts,
364
+ commandInfo: { command: "batch" },
365
+ data,
366
+ nextActions,
367
+ summary: batchSummary,
368
+ })
369
+ : changedSteps.length > 0
370
+ ? {
371
+ changeType: "mutation",
372
+ command: "batch",
373
+ nextActionIds: nextActions?.map((action) => action.id),
374
+ summary: `batch → mutation → ${changedSteps.length} changed step${changedSteps.length === 1 ? "" : "s"}`,
375
+ }
376
+ : undefined;
377
+ return {
378
+ artifactManifest: currentArtifactManifest,
379
+ artifactRetentionSummary,
380
+ artifactVerification,
381
+ artifacts: artifacts.length > 0 ? artifacts : undefined,
382
+ batchFailure,
383
+ batchSteps: steps.map((step) => step.details),
384
+ content: [{ type: "text", text: contentText }, ...images],
385
+ failureCategory: batchFailure?.failedStep.failureCategory,
386
+ data: redactedBatchData,
387
+ fullOutputPath: fullOutputPaths[0],
388
+ fullOutputPaths: fullOutputPaths.length > 0 ? fullOutputPaths : undefined,
389
+ imagePath: imagePaths[0],
390
+ imagePaths: imagePaths.length > 0 ? imagePaths : undefined,
391
+ nextActions,
392
+ pageChangeSummary,
393
+ resultCategory: batchFailure ? "failure" : "success",
394
+ successCategory: batchFailure ? undefined : classifyPresentationSuccessCategory({ artifactVerification, artifacts }),
395
+ summary: batchSummary,
396
+ };
397
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Purpose: Build browser profile/config recovery hints for launch/setup failures.
3
+ * Responsibilities: Recognize local Chrome/profile setup errors, avoid self-loop diagnostics, and emit canonical next actions.
4
+ * Scope: Error presentation only; upstream profile discovery and doctor execution remain normal agent_browser commands.
5
+ */
6
+ import { isOpenNavigationCommand } from "../../command-taxonomy.js";
7
+ import { getStartupScopedFlags } from "../../runtime.js";
8
+ import { buildNextToolAction } from "../next-actions.js";
9
+ const BROWSER_PROFILE_CONFIG_HINT = [
10
+ "Agent-browser profile/config hint: this looks like a local browser profile or Chrome user-data-dir setup problem, not a page-specific failure.",
11
+ "Do not keep retrying the same open/profile call. Run `profiles` and/or `doctor` through agent_browser, then tell the user whether Chrome/Chromium is installed, which Chrome profile directory names are available, or whether they need to configure a full profile/user-data directory path, a non-default Chromium-compatible `--executable-path`, or remove the profile requirement for public-page browsing.",
12
+ "Use the top-level `sessionMode: \"fresh\"` field for launch-scoped profile/debug/provider flags; do not pass `--session-mode` inside args.",
13
+ ].join(" ");
14
+ function looksLikeBrowserProfileConfigError(errorText) {
15
+ return /\b(?:No Chrome user data directory found|Cannot resolve profile name|Chrome user data directory|Chrome profile\s+.+?\s+not found|Available profiles|If you meant a directory path)\b/i.test(errorText);
16
+ }
17
+ function isLaunchOrSetupContext(args, commandInfo) {
18
+ const command = commandInfo.command;
19
+ if (command === "profiles" || command === "doctor")
20
+ return true;
21
+ if (command && isOpenNavigationCommand(command))
22
+ return true;
23
+ return (args ? getStartupScopedFlags(args) : []).length > 0;
24
+ }
25
+ function buildBrowserProfileConfigActions(commandInfo) {
26
+ const actions = [];
27
+ if (commandInfo.command !== "profiles") {
28
+ actions.push(buildNextToolAction({
29
+ args: ["profiles"],
30
+ id: "inspect-browser-profiles",
31
+ reason: "List browser profiles/user-data-dir candidates before retrying profile-based launch.",
32
+ safety: "Read-only local setup inspection; does not open a page or mutate browser state.",
33
+ }));
34
+ }
35
+ if (commandInfo.command !== "doctor") {
36
+ actions.push(buildNextToolAction({
37
+ args: ["doctor"],
38
+ id: "run-agent-browser-doctor",
39
+ reason: "Inspect local agent-browser browser installation/configuration before retrying.",
40
+ safety: "Read-only local diagnostics; report findings to the user before changing setup.",
41
+ }));
42
+ }
43
+ return actions;
44
+ }
45
+ export function buildBrowserProfileConfigRecovery(options) {
46
+ if (!looksLikeBrowserProfileConfigError(options.errorText))
47
+ return undefined;
48
+ if (!isLaunchOrSetupContext(options.args, options.commandInfo))
49
+ return undefined;
50
+ const actions = buildBrowserProfileConfigActions(options.commandInfo);
51
+ return {
52
+ actions: actions.length > 0 ? actions : undefined,
53
+ hint: BROWSER_PROFILE_CONFIG_HINT,
54
+ };
55
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Purpose: Share small presentation formatting and redaction helpers across result presentation modules.
3
+ * Responsibilities: Normalize scalar fields, stringify model-facing values, and apply sensitive-text redaction.
4
+ * Scope: Leaf helpers only; command-family formatting lives in sibling modules.
5
+ */
6
+ import { redactSensitiveText, redactSensitiveValue } from "../../runtime.js";
7
+ import { stringifyUnknown, truncateText } from "../text.js";
8
+ export function stringifyModelFacing(value) {
9
+ return stringifyUnknown(redactSensitiveValue(value));
10
+ }
11
+ export function parseJsonPreviewString(value) {
12
+ const trimmed = value.trim();
13
+ if (!trimmed.startsWith("{") && !trimmed.startsWith("["))
14
+ return value;
15
+ try {
16
+ return JSON.parse(trimmed);
17
+ }
18
+ catch {
19
+ return value;
20
+ }
21
+ }
22
+ export function redactModelFacingText(text) {
23
+ const parsed = parseJsonPreviewString(text);
24
+ if (parsed !== text) {
25
+ return stringifyModelFacing(parsed);
26
+ }
27
+ return redactSensitiveText(text);
28
+ }
29
+ export function redactModelFacingTextIfSensitive(text) {
30
+ return /(?:@|\b(?:access[_-]?key|api[_-]?key|auth|authorization|basic|bearer|connection[_-]?string|cookie|database[_-]?url|db[_-]?url|mongo(?:db)?[_-]?uri|pass(?:word)?|private[_-]?key|redis[_-]?url|secret|session[_-]?id|token)\b)/i.test(text)
31
+ ? redactModelFacingText(text)
32
+ : text;
33
+ }
34
+ export function getArrayField(data, key) {
35
+ return Array.isArray(data[key]) ? data[key] : undefined;
36
+ }
37
+ export function getStringField(data, key) {
38
+ const value = data[key];
39
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
40
+ }
41
+ export function formatCount(count, singular, plural = `${singular}s`) {
42
+ return `${count} ${count === 1 ? singular : plural}`;
43
+ }
44
+ export function firstLine(value, maxChars = 160) {
45
+ return truncateText(value.split("\n", 1)[0] ?? value, maxChars);
46
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Purpose: Share small ToolPresentation content helpers used by batch and compaction code.
3
+ * Responsibilities: Extract text/image/path fields and format batch step command labels.
4
+ * Scope: Pure ToolPresentation content helpers only.
5
+ */
6
+ export function isStringArray(value) {
7
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
8
+ }
9
+ export function getPresentationText(presentation) {
10
+ return presentation.content
11
+ .filter((part) => part.type === "text")
12
+ .map((part) => part.text.trim())
13
+ .filter((text) => text.length > 0)
14
+ .join("\n\n");
15
+ }
16
+ export function getPresentationImages(presentation) {
17
+ return presentation.content.filter((part) => part.type === "image");
18
+ }
19
+ export function getPresentationPaths(options) {
20
+ return options.secondaryPaths ?? (options.primaryPath ? [options.primaryPath] : []);
21
+ }
22
+ export function formatBatchStepCommand(command, index) {
23
+ return command && command.length > 0 ? command.join(" ") : `step-${index + 1}`;
24
+ }