pi-agent-browser-native 0.2.32 → 0.2.33
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 +27 -16
- package/docs/ARCHITECTURE.md +3 -2
- package/docs/COMMAND_REFERENCE.md +18 -10
- package/docs/ELECTRON.md +23 -4
- package/docs/RELEASE.md +4 -2
- package/docs/REQUIREMENTS.md +1 -1
- package/docs/SUPPORT_MATRIX.md +28 -16
- package/docs/TOOL_CONTRACT.md +29 -24
- package/extensions/agent-browser/index.ts +404 -4371
- package/extensions/agent-browser/lib/input-modes/electron.ts +170 -0
- package/extensions/agent-browser/lib/input-modes/job.ts +203 -0
- package/extensions/agent-browser/lib/input-modes/lookups.ts +447 -0
- package/extensions/agent-browser/lib/input-modes/params.ts +188 -0
- package/extensions/agent-browser/lib/input-modes/semantic-action.ts +107 -0
- package/extensions/agent-browser/lib/input-modes/shared.ts +46 -0
- package/extensions/agent-browser/lib/input-modes/types.ts +221 -0
- package/extensions/agent-browser/lib/input-modes.ts +41 -0
- package/extensions/agent-browser/lib/orchestration/browser-run/diagnostics.ts +696 -0
- package/extensions/agent-browser/lib/orchestration/browser-run/final-result.ts +450 -0
- package/extensions/agent-browser/lib/orchestration/browser-run/index.ts +46 -0
- package/extensions/agent-browser/lib/orchestration/browser-run/prepare.ts +711 -0
- package/extensions/agent-browser/lib/orchestration/browser-run/process-output.ts +386 -0
- package/extensions/agent-browser/lib/orchestration/browser-run/session-state.ts +868 -0
- package/extensions/agent-browser/lib/orchestration/browser-run/types.ts +476 -0
- package/extensions/agent-browser/lib/orchestration/browser-run.ts +1 -0
- package/extensions/agent-browser/lib/orchestration/input-plan.ts +338 -0
- package/extensions/agent-browser/lib/playbook.ts +12 -11
- package/extensions/agent-browser/lib/process.ts +106 -4
- package/extensions/agent-browser/lib/results/action-recommendations.ts +269 -0
- package/extensions/agent-browser/lib/results/artifact-manifest.ts +114 -0
- package/extensions/agent-browser/lib/results/artifact-state.ts +13 -0
- package/extensions/agent-browser/lib/results/categories.ts +106 -0
- package/extensions/agent-browser/lib/results/contracts.ts +220 -0
- package/extensions/agent-browser/lib/results/editable-ref-evidence.ts +72 -0
- package/extensions/agent-browser/lib/results/envelope.ts +2 -1
- package/extensions/agent-browser/lib/results/network.ts +64 -0
- package/extensions/agent-browser/lib/results/next-actions.ts +117 -0
- package/extensions/agent-browser/lib/results/presentation/artifacts.ts +506 -0
- package/extensions/agent-browser/lib/results/presentation/batch.ts +355 -0
- package/extensions/agent-browser/lib/results/presentation/common.ts +53 -0
- package/extensions/agent-browser/lib/results/presentation/content.ts +36 -0
- package/extensions/agent-browser/lib/results/presentation/diagnostics.ts +730 -0
- package/extensions/agent-browser/lib/results/presentation/errors.ts +125 -0
- package/extensions/agent-browser/lib/results/presentation/large-output.ts +182 -0
- package/extensions/agent-browser/lib/results/presentation/navigation.ts +216 -0
- package/extensions/agent-browser/lib/results/presentation/registry.ts +154 -0
- package/extensions/agent-browser/lib/results/presentation/skills.ts +143 -0
- package/extensions/agent-browser/lib/results/presentation.ts +87 -2399
- package/extensions/agent-browser/lib/results/recovery-actions.ts +139 -0
- package/extensions/agent-browser/lib/results/recovery-next-actions.ts +71 -0
- package/extensions/agent-browser/lib/results/selector-recovery.ts +312 -0
- package/extensions/agent-browser/lib/results/shared.ts +17 -789
- package/extensions/agent-browser/lib/results/snapshot-high-value-controls.ts +262 -0
- package/extensions/agent-browser/lib/results/snapshot-refs.ts +100 -0
- package/extensions/agent-browser/lib/results/snapshot-segments.ts +366 -0
- package/extensions/agent-browser/lib/results/snapshot-spill.ts +63 -0
- package/extensions/agent-browser/lib/results/snapshot.ts +37 -489
- package/extensions/agent-browser/lib/results/text.ts +40 -0
- package/extensions/agent-browser/lib/results.ts +16 -5
- package/extensions/agent-browser/lib/session-page-state.ts +486 -0
- package/package.json +2 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Purpose: Render upstream agent-browser skills output as native pi tool guidance.
|
|
3
|
+
* Responsibilities: Format skills list/path/get results and translate agent-browser shell snippets to agent_browser tool calls.
|
|
4
|
+
* Scope: Skills command presentation only.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { isRecord } from "../../parsing.js";
|
|
8
|
+
import type { CommandInfo } from "../../runtime.js";
|
|
9
|
+
import { getStringField, redactModelFacingText, stringifyModelFacing } from "./common.js";
|
|
10
|
+
|
|
11
|
+
function formatSkillsListText(skills: unknown[]): string {
|
|
12
|
+
if (skills.length === 0) return "No agent-browser skills found.";
|
|
13
|
+
return skills
|
|
14
|
+
.map((item, index) => {
|
|
15
|
+
if (!isRecord(item)) return `${index + 1}. ${stringifyModelFacing(item)}`;
|
|
16
|
+
const name = redactModelFacingText(getStringField(item, "name") ?? `(skill ${index + 1})`);
|
|
17
|
+
const description = getStringField(item, "description");
|
|
18
|
+
return description ? `${index + 1}. ${name} — ${redactModelFacingText(description)}` : `${index + 1}. ${name}`;
|
|
19
|
+
})
|
|
20
|
+
.join("\n");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getSkillContent(data: unknown): string | undefined {
|
|
24
|
+
if (typeof data === "string") return data;
|
|
25
|
+
if (isRecord(data) && typeof data.content === "string") return data.content;
|
|
26
|
+
if (!Array.isArray(data)) return undefined;
|
|
27
|
+
const content = data.flatMap((item) => (isRecord(item) && typeof item.content === "string" ? [item.content] : []));
|
|
28
|
+
return content.length > 0 ? content.join("\n\n") : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function splitShellWords(input: string): string[] | undefined {
|
|
32
|
+
const words: string[] = [];
|
|
33
|
+
let current = "";
|
|
34
|
+
let quote: 'single' | 'double' | undefined;
|
|
35
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
36
|
+
const char = input[index];
|
|
37
|
+
if (quote === "single") {
|
|
38
|
+
if (char === "'") quote = undefined;
|
|
39
|
+
else current += char;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (quote === "double") {
|
|
43
|
+
if (char === '"') quote = undefined;
|
|
44
|
+
else if (char === "\\" && index + 1 < input.length) {
|
|
45
|
+
index += 1;
|
|
46
|
+
current += input[index];
|
|
47
|
+
} else current += char;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (char === "'") {
|
|
51
|
+
quote = "single";
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (char === '"') {
|
|
55
|
+
quote = "double";
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (char === "\\" && index + 1 < input.length) {
|
|
59
|
+
index += 1;
|
|
60
|
+
current += input[index];
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (char === "#" && current.length === 0) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
if (/\s/.test(char)) {
|
|
67
|
+
if (current.length > 0) {
|
|
68
|
+
words.push(current);
|
|
69
|
+
current = "";
|
|
70
|
+
}
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
current += char;
|
|
74
|
+
}
|
|
75
|
+
if (quote) return undefined;
|
|
76
|
+
if (current.length > 0) words.push(current);
|
|
77
|
+
return words;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function formatNativeAgentBrowserCall(args: string[], stdin?: string): string {
|
|
81
|
+
return stdin === undefined
|
|
82
|
+
? `agent_browser { "args": ${JSON.stringify(args)} }`
|
|
83
|
+
: `agent_browser { "args": ${JSON.stringify(args)}, "stdin": ${JSON.stringify(stdin)} }`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function formatNativeSkillContent(content: string): string {
|
|
87
|
+
const lines = content.replace(/^allowed-tools:.*agent-browser.*\n?/gim, "").replace(/^```bash\s*$/gim, "```text").split("\n");
|
|
88
|
+
const output: string[] = [];
|
|
89
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
90
|
+
const line = lines[index];
|
|
91
|
+
const commandMatch = /^(\s*)agent-browser\s+(.+?)\s*$/.exec(line);
|
|
92
|
+
if (!commandMatch) {
|
|
93
|
+
output.push(line);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const indent = commandMatch[1];
|
|
97
|
+
const rawArgsText = commandMatch[2];
|
|
98
|
+
const heredocMatch = /^(.*?)\s+(<<-?)['"]?([A-Za-z_][A-Za-z0-9_]*)['"]?\s*$/.exec(rawArgsText);
|
|
99
|
+
const argsText = heredocMatch?.[1] ?? rawArgsText;
|
|
100
|
+
const args = splitShellWords(argsText);
|
|
101
|
+
if (!args || args.length === 0) {
|
|
102
|
+
output.push(line);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (!heredocMatch) {
|
|
106
|
+
output.push(`${indent}${formatNativeAgentBrowserCall(args)}`);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const stripsLeadingTabs = heredocMatch[2] === "<<-";
|
|
110
|
+
const delimiter = heredocMatch[3];
|
|
111
|
+
const stdinLines: string[] = [];
|
|
112
|
+
let cursor = index + 1;
|
|
113
|
+
while (cursor < lines.length) {
|
|
114
|
+
const candidate = stripsLeadingTabs ? lines[cursor].replace(/^\t+/, "") : lines[cursor];
|
|
115
|
+
if (candidate === delimiter) break;
|
|
116
|
+
stdinLines.push(candidate);
|
|
117
|
+
cursor += 1;
|
|
118
|
+
}
|
|
119
|
+
if (cursor >= lines.length) {
|
|
120
|
+
output.push(line);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
output.push(`${indent}${formatNativeAgentBrowserCall(args, stdinLines.join("\n"))}`);
|
|
124
|
+
index = cursor;
|
|
125
|
+
}
|
|
126
|
+
return output.join("\n");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function formatSkillsText(commandInfo: CommandInfo, data: unknown): string | undefined {
|
|
130
|
+
if (commandInfo.command !== "skills") return undefined;
|
|
131
|
+
if (commandInfo.subcommand === "path") return typeof data === "string" ? redactModelFacingText(data) : undefined;
|
|
132
|
+
if (commandInfo.subcommand === "list" && Array.isArray(data)) return formatSkillsListText(data);
|
|
133
|
+
const content = getSkillContent(data);
|
|
134
|
+
if (content) {
|
|
135
|
+
const note = [
|
|
136
|
+
"Pi native-tool note: upstream skill text was adapted for this native tool.",
|
|
137
|
+
"Use args for CLI tokens and stdin only for batch, eval --stdin, or auth save --password-stdin; do not pipe heredocs through bash unless the user explicitly asks for a bash workflow.",
|
|
138
|
+
].join("\n");
|
|
139
|
+
return `${note}\n\n${redactModelFacingText(formatNativeSkillContent(content))}`;
|
|
140
|
+
}
|
|
141
|
+
if (typeof data === "string") return redactModelFacingText(formatNativeSkillContent(data));
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|