pi-agent-browser-native 0.2.44 → 0.2.46
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 +42 -0
- package/README.md +20 -15
- package/docs/ARCHITECTURE.md +12 -10
- package/docs/COMMAND_REFERENCE.md +49 -27
- package/docs/ELECTRON.md +1 -1
- package/docs/RELEASE.md +6 -5
- package/docs/REQUIREMENTS.md +6 -3
- package/docs/SUPPORT_MATRIX.md +17 -13
- package/docs/TOOL_CONTRACT.md +87 -46
- package/docs/platform-smoke.md +4 -3
- package/extensions/agent-browser/index.ts +43 -450
- package/extensions/agent-browser/lib/bash-guard.ts +205 -0
- package/extensions/agent-browser/lib/electron/cdp.ts +69 -0
- package/extensions/agent-browser/lib/electron/cleanup.ts +5 -58
- package/extensions/agent-browser/lib/electron/discovery.ts +2 -9
- package/extensions/agent-browser/lib/electron/launch.ts +11 -65
- package/extensions/agent-browser/lib/electron/text.ts +13 -0
- package/extensions/agent-browser/lib/fs-utils.ts +18 -0
- package/extensions/agent-browser/lib/input-modes/job.ts +207 -21
- package/extensions/agent-browser/lib/input-modes/params.ts +28 -11
- package/extensions/agent-browser/lib/input-modes/semantic-action.ts +22 -2
- package/extensions/agent-browser/lib/input-modes/types.ts +5 -1
- package/extensions/agent-browser/lib/input-modes.ts +1 -0
- package/extensions/agent-browser/lib/json-schema.ts +73 -0
- package/extensions/agent-browser/lib/orchestration/browser-run/click-dispatch.ts +82 -11
- package/extensions/agent-browser/lib/orchestration/browser-run/diagnostics.ts +159 -30
- package/extensions/agent-browser/lib/orchestration/browser-run/final-result.ts +53 -2
- package/extensions/agent-browser/lib/orchestration/browser-run/index.ts +1 -0
- package/extensions/agent-browser/lib/orchestration/browser-run/prepare.ts +751 -32
- package/extensions/agent-browser/lib/orchestration/browser-run/process-output.ts +38 -7
- package/extensions/agent-browser/lib/orchestration/browser-run/prompt-guards.ts +0 -46
- package/extensions/agent-browser/lib/orchestration/browser-run/session-state.ts +10 -1
- package/extensions/agent-browser/lib/orchestration/browser-run/types.ts +28 -1
- package/extensions/agent-browser/lib/orchestration/electron-host/index.ts +1 -6
- package/extensions/agent-browser/lib/orchestration/input-plan.ts +15 -3
- package/extensions/agent-browser/lib/orchestration/output-file.ts +86 -0
- package/extensions/agent-browser/lib/pi-tool-rendering.ts +252 -0
- package/extensions/agent-browser/lib/playbook.ts +26 -26
- package/extensions/agent-browser/lib/process.ts +1 -1
- package/extensions/agent-browser/lib/prompt-policy.ts +1 -18
- package/extensions/agent-browser/lib/results/artifact-manifest.ts +1 -4
- package/extensions/agent-browser/lib/results/artifact-state.ts +7 -3
- package/extensions/agent-browser/lib/results/contracts.ts +6 -2
- package/extensions/agent-browser/lib/results/envelope.ts +11 -2
- package/extensions/agent-browser/lib/results/network-routes.ts +7 -4
- package/extensions/agent-browser/lib/results/network.ts +7 -1
- package/extensions/agent-browser/lib/results/presentation/artifacts.ts +88 -20
- package/extensions/agent-browser/lib/results/presentation/batch.ts +84 -12
- package/extensions/agent-browser/lib/results/presentation/diagnostics.ts +81 -26
- package/extensions/agent-browser/lib/results/presentation/errors.ts +13 -0
- package/extensions/agent-browser/lib/results/presentation/registry.ts +60 -0
- package/extensions/agent-browser/lib/results/presentation.ts +10 -1
- package/extensions/agent-browser/lib/results/snapshot-high-value-controls.ts +16 -5
- package/extensions/agent-browser/lib/results/snapshot.ts +2 -0
- package/extensions/agent-browser/lib/runtime.ts +10 -1
- package/extensions/agent-browser/lib/session-page-state.ts +15 -6
- package/extensions/agent-browser/lib/string-enum-schema.ts +20 -0
- package/extensions/agent-browser/lib/web-search.ts +31 -13
- package/package.json +2 -2
- package/platform-smoke.config.mjs +5 -2
- package/scripts/platform-smoke/build-ubuntu-image.mjs +25 -0
- package/scripts/platform-smoke/crabbox-runner.mjs +5 -1
- package/scripts/platform-smoke/doctor.mjs +6 -2
- package/scripts/platform-smoke/linux-image/Dockerfile +3 -5
- package/scripts/platform-smoke/targets.mjs +2 -1
- package/extensions/agent-browser/lib/orchestration/browser-run/browser-action-model.ts +0 -154
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Purpose: Normalize planned browser argv into a small action model for prompt-derived guards.
|
|
3
|
-
* Responsibilities: Map command tokens and batch stdin steps to click-like and keyboard-submit actions with target labels.
|
|
4
|
-
* Scope: Best-effort finalizing-action detection only; does not model eval, generic fill/type, or non-Enter keyboard flows.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { SessionRefSnapshot } from "../../session-page-state.js";
|
|
8
|
-
import { parseValidBatchStepEntries } from "../batch-stdin.js";
|
|
9
|
-
|
|
10
|
-
const FINAL_ACTION_PATTERN = /\b(?:finish|place\s+(?:the\s+)?order|submit\s+(?:the\s+)?order|complete\s+(?:the\s+)?order|confirm\s+(?:the\s+)?order|purchase|buy\s+now|pay\s+now|finali[sz]e|submit\s+payment|checkout\s+complete)\b/i;
|
|
11
|
-
|
|
12
|
-
const CLICK_LIKE_COMMANDS = new Set(["click", "dblclick", "tap"]);
|
|
13
|
-
const FIND_CLICK_ACTIONS = new Set(["click", "dblclick", "tap"]);
|
|
14
|
-
const KEYBOARD_SUBMIT_KEYS = new Set(["enter", "return"]);
|
|
15
|
-
|
|
16
|
-
export type BrowserFinalizingActionKind = "click-like" | "keyboard-submit";
|
|
17
|
-
|
|
18
|
-
export interface BrowserFinalizingAction {
|
|
19
|
-
command: string[];
|
|
20
|
-
kind: BrowserFinalizingActionKind;
|
|
21
|
-
stepIndex?: number;
|
|
22
|
-
targetLabel?: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const STOP_BOUNDARY_GUARD_SCOPE = {
|
|
26
|
-
covered: [
|
|
27
|
-
"standalone click, dblclick, and tap",
|
|
28
|
-
"find … click|dblclick|tap",
|
|
29
|
-
"batch steps with the click-like shapes above",
|
|
30
|
-
"press <key> and key <key> when key is Enter or Return",
|
|
31
|
-
],
|
|
32
|
-
excluded: [
|
|
33
|
-
"eval --stdin and other scripted activation",
|
|
34
|
-
"fill, type, select, drag, and upload without an explicit click-like command",
|
|
35
|
-
"keyboard type/inserttext and keyboard shortcuts other than Enter/Return",
|
|
36
|
-
"semanticAction and job/qa compiled plans unless their batch stdin contains a covered step",
|
|
37
|
-
],
|
|
38
|
-
} as const;
|
|
39
|
-
|
|
40
|
-
function normalizeTargetText(value: string): string {
|
|
41
|
-
return value
|
|
42
|
-
.replace(/[_-]+/g, " ")
|
|
43
|
-
.replace(/[\[\]{}()#.'\"=:/]+/g, " ")
|
|
44
|
-
.replace(/\s+/g, " ")
|
|
45
|
-
.trim();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function matchesFinalActionLabel(value: string | undefined): boolean {
|
|
49
|
-
return value !== undefined && FINAL_ACTION_PATTERN.test(normalizeTargetText(value));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function parseRefId(value: string | undefined): string | undefined {
|
|
53
|
-
if (!value) return undefined;
|
|
54
|
-
const trimmed = value.trim();
|
|
55
|
-
const candidate = trimmed.startsWith("@") ? trimmed.slice(1) : trimmed.startsWith("ref=") ? trimmed.slice(4) : trimmed;
|
|
56
|
-
return /^e\d+$/.test(candidate) ? candidate : undefined;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function getRefTargetLabel(refSnapshot: SessionRefSnapshot | undefined, refId: string | undefined): string | undefined {
|
|
60
|
-
if (!refId) return undefined;
|
|
61
|
-
const ref = refSnapshot?.refs?.[refId];
|
|
62
|
-
return ref ? [ref.role, ref.name].filter(Boolean).join(" ") : undefined;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function getFlagValue(tokens: string[], flag: string): string | undefined {
|
|
66
|
-
for (const [index, token] of tokens.entries()) {
|
|
67
|
-
if (token === flag) return tokens[index + 1];
|
|
68
|
-
if (token.startsWith(`${flag}=`)) return token.slice(flag.length + 1);
|
|
69
|
-
}
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function getClickLikeTargetLabel(command: string[], refSnapshot: SessionRefSnapshot | undefined): string | undefined {
|
|
74
|
-
const target = command[1];
|
|
75
|
-
return getRefTargetLabel(refSnapshot, parseRefId(target)) ?? target;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function getFindClickTargetLabel(command: string[]): string | undefined {
|
|
79
|
-
if (command[0] !== "find") return undefined;
|
|
80
|
-
const actionIndex = command.findIndex((token, index) => index >= 3 && FIND_CLICK_ACTIONS.has(token));
|
|
81
|
-
if (actionIndex === -1) return undefined;
|
|
82
|
-
return getFlagValue(command, "--name") ?? command[2];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function getKeyboardSubmitKey(command: string[]): string | undefined {
|
|
86
|
-
const commandName = command[0];
|
|
87
|
-
if (commandName === "press" || commandName === "key") return command[1];
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function collectActionsFromCommand(command: string[], refSnapshot: SessionRefSnapshot | undefined, stepIndex?: number): BrowserFinalizingAction[] {
|
|
92
|
-
const actions: BrowserFinalizingAction[] = [];
|
|
93
|
-
if (CLICK_LIKE_COMMANDS.has(command[0] ?? "")) {
|
|
94
|
-
actions.push({
|
|
95
|
-
command,
|
|
96
|
-
kind: "click-like",
|
|
97
|
-
stepIndex,
|
|
98
|
-
targetLabel: getClickLikeTargetLabel(command, refSnapshot),
|
|
99
|
-
});
|
|
100
|
-
return actions;
|
|
101
|
-
}
|
|
102
|
-
if (command[0] === "find") {
|
|
103
|
-
const actionIndex = command.findIndex((token, index) => index >= 3 && FIND_CLICK_ACTIONS.has(token));
|
|
104
|
-
if (actionIndex !== -1) {
|
|
105
|
-
actions.push({
|
|
106
|
-
command,
|
|
107
|
-
kind: "click-like",
|
|
108
|
-
stepIndex,
|
|
109
|
-
targetLabel: getFindClickTargetLabel(command),
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
return actions;
|
|
113
|
-
}
|
|
114
|
-
const submitKey = getKeyboardSubmitKey(command)?.trim().toLowerCase();
|
|
115
|
-
if (submitKey && KEYBOARD_SUBMIT_KEYS.has(submitKey)) {
|
|
116
|
-
actions.push({
|
|
117
|
-
command,
|
|
118
|
-
kind: "keyboard-submit",
|
|
119
|
-
stepIndex,
|
|
120
|
-
targetLabel: submitKey,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
return actions;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function collectBrowserFinalizingActions(options: {
|
|
127
|
-
commandTokens: string[];
|
|
128
|
-
refSnapshot?: SessionRefSnapshot;
|
|
129
|
-
stdin?: string;
|
|
130
|
-
}): BrowserFinalizingAction[] {
|
|
131
|
-
const actions = collectActionsFromCommand(options.commandTokens, options.refSnapshot);
|
|
132
|
-
if (options.commandTokens[0] !== "batch") return actions;
|
|
133
|
-
for (const { index, step } of parseValidBatchStepEntries(options.stdin)) {
|
|
134
|
-
actions.push(...collectActionsFromCommand(step, options.refSnapshot, index));
|
|
135
|
-
}
|
|
136
|
-
return actions;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function shouldBlockFinalizingAction(action: BrowserFinalizingAction): boolean {
|
|
140
|
-
if (action.kind === "keyboard-submit") return true;
|
|
141
|
-
return matchesFinalActionLabel(action.targetLabel);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function findBlockedFinalizingAction(options: {
|
|
145
|
-
commandTokens: string[];
|
|
146
|
-
refSnapshot?: SessionRefSnapshot;
|
|
147
|
-
stdin?: string;
|
|
148
|
-
}): BrowserFinalizingAction | undefined {
|
|
149
|
-
for (const action of collectBrowserFinalizingActions(options)) {
|
|
150
|
-
if (!shouldBlockFinalizingAction(action)) continue;
|
|
151
|
-
return action;
|
|
152
|
-
}
|
|
153
|
-
return undefined;
|
|
154
|
-
}
|