trusted-user-agent 0.0.0-stage → 0.4.0

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 (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +232 -2
  3. package/dist/acp/agent.js +719 -0
  4. package/dist/acp/agents/connection.js +298 -0
  5. package/dist/acp/agents/manager.js +363 -0
  6. package/dist/acp/agents/registry.js +201 -0
  7. package/dist/acp/agents/relay-session.js +371 -0
  8. package/dist/acp/agents/session-index.js +102 -0
  9. package/dist/acp/backend.js +2 -0
  10. package/dist/acp/config-options.js +26 -0
  11. package/dist/acp/mock-backend.js +277 -0
  12. package/dist/acp/sdk-backend.js +495 -0
  13. package/dist/browser/mcp-acp-client.js +81 -0
  14. package/dist/browser/provider.js +1049 -0
  15. package/dist/browser/schemas.js +221 -0
  16. package/dist/capability-registry.js +92 -0
  17. package/dist/client-heartbeat.js +118 -0
  18. package/dist/compose/schemas.js +90 -0
  19. package/dist/contacts/schemas.js +26 -0
  20. package/dist/installer/cli.js +70 -0
  21. package/dist/installer/common.js +93 -0
  22. package/dist/installer/index.js +366 -0
  23. package/dist/installer/mcp-clients.js +555 -0
  24. package/dist/installer/mcp.js +166 -0
  25. package/dist/installer/platforms.js +277 -0
  26. package/dist/logger.js +54 -0
  27. package/dist/mail/schemas.js +98 -0
  28. package/dist/mutation/schemas.js +31 -0
  29. package/dist/native-host/broker-ipc.js +344 -0
  30. package/dist/native-host/framing.js +76 -0
  31. package/dist/native-host/main.js +545 -0
  32. package/dist/native-host/mcp-server.js +333 -0
  33. package/dist/native-host/mcp-stdio-bridge.js +184 -0
  34. package/dist/native-host/mcp-stdio-main.js +13 -0
  35. package/dist/native-host/relay.js +84 -0
  36. package/dist/native-host/skills-startup.js +167 -0
  37. package/dist/native-host/transport.js +248 -0
  38. package/dist/permission-store.js +207 -0
  39. package/dist/repl/fs-sandbox.js +187 -0
  40. package/dist/repl/provider.js +252 -0
  41. package/dist/repl/runtime.js +436 -0
  42. package/dist/repl/types.js +10 -0
  43. package/dist/repl/worker.js +731 -0
  44. package/dist/skills/extension.js +99 -0
  45. package/dist/skills/grants-file.js +145 -0
  46. package/dist/skills/isolated-runner.js +259 -0
  47. package/dist/skills/mock-session-factory.js +49 -0
  48. package/dist/skills/package-roots.js +25 -0
  49. package/dist/skills/pi-bridge.js +8 -0
  50. package/dist/skills/pi-integration.js +110 -0
  51. package/dist/skills/planner.js +128 -0
  52. package/dist/skills/registry.js +104 -0
  53. package/dist/skills/skills-protocol.js +253 -0
  54. package/dist/skills/skills-service.js +195 -0
  55. package/dist/tool-bridge.js +8 -0
  56. package/dist/workspace.js +70 -0
  57. package/extensions/pi-browser-tools.ts +65 -0
  58. package/extensions/pi-browser.ts +60 -0
  59. package/extensions/pi-skills.ts +14 -0
  60. package/native/pi-agent-host +2 -0
  61. package/native/pi-browser-host +5 -0
  62. package/native/pi-browser-host.cmd +3 -0
  63. package/node_modules/@pi-browser/protocol/.bundled-by-trusted-user-agent +0 -0
  64. package/node_modules/@pi-browser/protocol/dist/acp.d.ts +10 -0
  65. package/node_modules/@pi-browser/protocol/dist/acp.js +9 -0
  66. package/node_modules/@pi-browser/protocol/dist/agents.d.ts +51 -0
  67. package/node_modules/@pi-browser/protocol/dist/agents.js +44 -0
  68. package/node_modules/@pi-browser/protocol/dist/browser-tools.d.ts +33 -0
  69. package/node_modules/@pi-browser/protocol/dist/browser-tools.js +478 -0
  70. package/node_modules/@pi-browser/protocol/dist/callers.d.ts +123 -0
  71. package/node_modules/@pi-browser/protocol/dist/callers.js +58 -0
  72. package/node_modules/@pi-browser/protocol/dist/compose-tools.d.ts +30 -0
  73. package/node_modules/@pi-browser/protocol/dist/compose-tools.js +175 -0
  74. package/node_modules/@pi-browser/protocol/dist/contacts-tools.d.ts +23 -0
  75. package/node_modules/@pi-browser/protocol/dist/contacts-tools.js +63 -0
  76. package/node_modules/@pi-browser/protocol/dist/control-tools.d.ts +32 -0
  77. package/node_modules/@pi-browser/protocol/dist/control-tools.js +201 -0
  78. package/node_modules/@pi-browser/protocol/dist/errors.d.ts +63 -0
  79. package/node_modules/@pi-browser/protocol/dist/errors.js +109 -0
  80. package/node_modules/@pi-browser/protocol/dist/index.d.ts +17 -0
  81. package/node_modules/@pi-browser/protocol/dist/index.js +17 -0
  82. package/node_modules/@pi-browser/protocol/dist/integration.d.ts +414 -0
  83. package/node_modules/@pi-browser/protocol/dist/integration.js +270 -0
  84. package/node_modules/@pi-browser/protocol/dist/jsonrpc.d.ts +33 -0
  85. package/node_modules/@pi-browser/protocol/dist/jsonrpc.js +31 -0
  86. package/node_modules/@pi-browser/protocol/dist/mail-mutation-tools.d.ts +27 -0
  87. package/node_modules/@pi-browser/protocol/dist/mail-mutation-tools.js +88 -0
  88. package/node_modules/@pi-browser/protocol/dist/mail-tools.d.ts +133 -0
  89. package/node_modules/@pi-browser/protocol/dist/mail-tools.js +245 -0
  90. package/node_modules/@pi-browser/protocol/dist/permission.d.ts +113 -0
  91. package/node_modules/@pi-browser/protocol/dist/permission.js +257 -0
  92. package/node_modules/@pi-browser/protocol/dist/skills.d.ts +304 -0
  93. package/node_modules/@pi-browser/protocol/dist/skills.js +473 -0
  94. package/node_modules/@pi-browser/protocol/dist/tool-capabilities.d.ts +18 -0
  95. package/node_modules/@pi-browser/protocol/dist/tool-capabilities.js +52 -0
  96. package/node_modules/@pi-browser/protocol/dist/transport.d.ts +17 -0
  97. package/node_modules/@pi-browser/protocol/dist/transport.js +17 -0
  98. package/node_modules/@pi-browser/protocol/package.json +14 -0
  99. package/package.json +69 -4
  100. package/skills/browser-walk/SKILL.md +98 -0
@@ -0,0 +1,195 @@
1
+ /** Lower runs first: held submissions > explicit Active > speculative > passive. */
2
+ const KIND_RANK = { gate: 0, active: 1, speculative: 2, passive: 3 };
3
+ const DEFAULT_LIMITS = { maxConcurrent: 2, maxQueued: 64, agingMs: 5_000 };
4
+ export class SkillsService {
5
+ limits;
6
+ queue = [];
7
+ running = new Map();
8
+ replacements = new Map();
9
+ outstanding = new Set();
10
+ counts = {
11
+ done: 0, superseded: 0, aborted: 0, "timed-out": 0, failed: 0, unavailable: 0,
12
+ };
13
+ closed = false;
14
+ constructor(limits = {}) {
15
+ const merged = { ...DEFAULT_LIMITS, ...limits };
16
+ if (!Number.isInteger(merged.maxConcurrent) || merged.maxConcurrent < 1)
17
+ throw new Error("maxConcurrent must be >= 1");
18
+ if (!Number.isInteger(merged.maxQueued) || merged.maxQueued < 1)
19
+ throw new Error("maxQueued must be >= 1");
20
+ if (!Number.isFinite(merged.agingMs) || merged.agingMs <= 0)
21
+ throw new Error("agingMs must be > 0");
22
+ this.limits = merged;
23
+ }
24
+ /** Schedule a job. Resolves with the job's own fate; admission rejection
25
+ * resolves "unavailable" (required reviews degrade to unavailable, never clear). */
26
+ submit(request) {
27
+ if (this.closed)
28
+ return Promise.resolve({ status: "unavailable", reason: "service closed" });
29
+ const job = this.createJob(request);
30
+ const current = this.running.get(request.key);
31
+ if (current) {
32
+ // A newer job supersedes: register it as the replacement BEFORE
33
+ // settling the running job, whose settlement promotes exactly the
34
+ // replacement currently on record.
35
+ const pending = this.replacements.get(request.key);
36
+ if (pending)
37
+ this.cancelJob(pending, "superseded", `replaced by a newer ${request.kind} job`);
38
+ job.state = "replacement";
39
+ this.replacements.set(request.key, job);
40
+ this.cancelJob(current, "superseded", `superseded by a newer ${request.kind} job`);
41
+ }
42
+ else {
43
+ const index = this.queue.findIndex((entry) => entry.request.key === request.key);
44
+ if (index >= 0) {
45
+ // Coalesce in place: keep the older queue position.
46
+ this.cancelJob(this.queue[index], "superseded", `replaced by a newer ${request.kind} job`);
47
+ this.queue[index] = job;
48
+ }
49
+ else {
50
+ this.admit(job);
51
+ }
52
+ }
53
+ this.pump();
54
+ return job.promise;
55
+ }
56
+ /** Cancel a key's running and/or pending job. Returns how many were cancelled. */
57
+ cancel(key) {
58
+ let cancelled = 0;
59
+ const current = this.running.get(key);
60
+ if (current) {
61
+ this.cancelJob(current, "aborted", "cancelled");
62
+ cancelled += 1;
63
+ }
64
+ const pending = this.replacements.get(key);
65
+ if (pending) {
66
+ this.cancelJob(pending, "aborted", "cancelled");
67
+ cancelled += 1;
68
+ }
69
+ const index = this.queue.findIndex((entry) => entry.request.key === key);
70
+ if (index >= 0) {
71
+ this.cancelJob(this.queue[index], "aborted", "cancelled");
72
+ cancelled += 1;
73
+ }
74
+ return cancelled;
75
+ }
76
+ /** Abort all pending and running work; resolves once every job has settled. */
77
+ close() {
78
+ if (this.closed)
79
+ return Promise.resolve();
80
+ this.closed = true;
81
+ for (const job of [...this.queue, ...this.replacements.values(), ...this.running.values()]) {
82
+ this.cancelJob(job, "aborted", "service closed");
83
+ }
84
+ return Promise.all([...this.outstanding]).then(() => undefined);
85
+ }
86
+ get stats() {
87
+ return {
88
+ running: this.running.size,
89
+ queued: this.queue.length,
90
+ replacements: this.replacements.size,
91
+ closed: this.closed,
92
+ outcomes: { ...this.counts },
93
+ };
94
+ }
95
+ createJob(request) {
96
+ let resolve;
97
+ const promise = new Promise((settle) => { resolve = settle; });
98
+ const job = {
99
+ request,
100
+ queuedAt: Date.now(),
101
+ state: "queued",
102
+ controller: new AbortController(),
103
+ settled: false,
104
+ resolve: resolve,
105
+ promise,
106
+ };
107
+ this.outstanding.add(promise);
108
+ return job;
109
+ }
110
+ /** Put a job in the pending queue; under saturation required work displaces
111
+ * the oldest speculative/passive job first, everything else is unavailable. */
112
+ admit(job) {
113
+ if (this.queue.length < this.limits.maxQueued) {
114
+ this.queue.push(job);
115
+ return;
116
+ }
117
+ if (KIND_RANK[job.request.kind] <= KIND_RANK.active) {
118
+ const evictable = this.queue.find((entry) => KIND_RANK[entry.request.kind] >= KIND_RANK.speculative);
119
+ if (evictable) {
120
+ this.cancelJob(evictable, "unavailable", "displaced by required job under saturation");
121
+ this.queue.push(job);
122
+ return;
123
+ }
124
+ }
125
+ this.settleJob(job, { status: "unavailable", reason: "queue saturated" });
126
+ }
127
+ /** Start the highest-priority queued jobs while slots are free.
128
+ * Tie-break is FIFO. Aged non-gate jobs may rise to "active" rank, never past gate. */
129
+ pump() {
130
+ while (this.running.size < this.limits.maxConcurrent && this.queue.length > 0) {
131
+ const now = Date.now();
132
+ let best = 0;
133
+ for (let i = 1; i < this.queue.length; i++) {
134
+ if (this.score(this.queue[i], now) < this.score(this.queue[best], now))
135
+ best = i;
136
+ }
137
+ this.startJob(this.queue.splice(best, 1)[0]);
138
+ }
139
+ }
140
+ score(job, now) {
141
+ const rank = KIND_RANK[job.request.kind];
142
+ if (rank === KIND_RANK.gate)
143
+ return rank;
144
+ const aged = rank - Math.floor((now - job.queuedAt) / this.limits.agingMs);
145
+ return Math.max(aged, KIND_RANK.active);
146
+ }
147
+ startJob(job) {
148
+ job.state = "running";
149
+ this.running.set(job.request.key, job);
150
+ job.timer = setTimeout(() => {
151
+ job.controller.abort();
152
+ this.settleJob(job, { status: "timed-out", reason: `exceeded ${job.request.timeoutMs}ms deadline` });
153
+ }, job.request.timeoutMs);
154
+ // Settlement is idempotent: a worker that ignores the abort signal cannot
155
+ // overwrite the authoritative "timed-out" outcome (or vice versa). The
156
+ // settled guard covers cancellation between startJob and this microtask.
157
+ Promise.resolve()
158
+ .then(() => (job.settled ? undefined : job.request.run(job.controller.signal)))
159
+ .then((value) => this.settleJob(job, { status: "done", value }), (error) => this.settleJob(job, { status: "failed", error: error instanceof Error ? error : new Error(String(error)) }));
160
+ }
161
+ /** First outcome wins; detaches the job and promotes a replacement if the
162
+ * running slot for its key freed up. */
163
+ settleJob(job, outcome) {
164
+ if (job.settled)
165
+ return;
166
+ job.settled = true;
167
+ if (job.timer)
168
+ clearTimeout(job.timer);
169
+ if (job.state === "running") {
170
+ this.running.delete(job.request.key);
171
+ const replacement = this.replacements.get(job.request.key);
172
+ if (replacement) {
173
+ this.replacements.delete(job.request.key);
174
+ this.admit(replacement);
175
+ }
176
+ }
177
+ else if (job.state === "replacement") {
178
+ this.replacements.delete(job.request.key);
179
+ }
180
+ else {
181
+ const index = this.queue.indexOf(job);
182
+ if (index >= 0)
183
+ this.queue.splice(index, 1);
184
+ }
185
+ this.counts[outcome.status] += 1;
186
+ this.outstanding.delete(job.promise);
187
+ job.resolve(outcome);
188
+ this.pump();
189
+ }
190
+ cancelJob(job, status, reason) {
191
+ job.controller.abort();
192
+ this.settleJob(job, { status, reason });
193
+ }
194
+ }
195
+ //# sourceMappingURL=skills-service.js.map
@@ -0,0 +1,8 @@
1
+ let bridge;
2
+ export function setBrowserToolBridge(b) {
3
+ bridge = b;
4
+ }
5
+ export function getBrowserToolBridge() {
6
+ return bridge;
7
+ }
8
+ //# sourceMappingURL=tool-bridge.js.map
@@ -0,0 +1,70 @@
1
+ /**
2
+ * TaskWorkspace — per-task (per-ACP-session) filesystem scratch.
3
+ *
4
+ * Every task the agent runs gets its own private directory. It becomes the
5
+ * Pi session's cwd, so the model's native file tools (read/write/edit/bash)
6
+ * operate inside the task's scratch by default, and the `javascript` REPL is
7
+ * bound to the same directory (AcpAgent.bindWorkspace) so cell artifacts,
8
+ * checkpoints, images and documents all land in one place per task.
9
+ *
10
+ * A directory is provisioned before the Pi session is created (the cwd is a
11
+ * creation-time argument), so its name is a timestamp+random slug, not the
12
+ * Pi session id. The session-id -> directory mapping is owned by AcpAgent
13
+ * (state.cwd) and pushed to the REPL provider via ReplProvider.bindWorkspace.
14
+ */
15
+ import { mkdir } from "node:fs/promises";
16
+ import os from "node:os";
17
+ import path from "node:path";
18
+ import { randomBytes } from "node:crypto";
19
+ /** A cwd that carries no user intent — the add-on's "create with empty field" fallback. */
20
+ export function isNeutralCwd(cwd) {
21
+ if (typeof cwd !== "string")
22
+ return true;
23
+ const trimmed = cwd.trim();
24
+ if (trimmed === "")
25
+ return true;
26
+ if (trimmed === "/" || trimmed === "\\")
27
+ return true;
28
+ // A bare home directory is not a meaningful task scratch.
29
+ if (trimmed === os.homedir())
30
+ return true;
31
+ return false;
32
+ }
33
+ export class TaskWorkspace {
34
+ root;
35
+ constructor(opts = {}) {
36
+ this.root = opts.root ?? process.env.PI_BROWSER_WORKSPACE_DIR ?? path.join(os.homedir(), ".pi", "workspaces");
37
+ }
38
+ /**
39
+ * Provision a fresh per-task directory and return its absolute path.
40
+ * Named `YYYYMMDD-HHMMSS-<6hex>` so listings sort by creation time and two
41
+ * fast creations can never collide.
42
+ */
43
+ async create() {
44
+ const name = this.freshName();
45
+ const dir = path.join(this.root, name);
46
+ await mkdir(dir, { recursive: true, mode: 0o700 });
47
+ return dir;
48
+ }
49
+ /** Deterministic directory for a session id (resume/load + legacy REPL fallback). */
50
+ for(sessionId) {
51
+ return path.join(this.root, this.sanitize(sessionId));
52
+ }
53
+ /** mkdir 0700 the session-id-keyed directory and return its path. */
54
+ async ensure(sessionId) {
55
+ const dir = this.for(sessionId);
56
+ await mkdir(dir, { recursive: true, mode: 0o700 });
57
+ return dir;
58
+ }
59
+ freshName() {
60
+ const d = new Date();
61
+ const p = (n, w = 2) => String(n).padStart(w, "0");
62
+ const stamp = `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}` +
63
+ `-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}`;
64
+ return `${stamp}-${randomBytes(3).toString("hex")}`;
65
+ }
66
+ sanitize(id) {
67
+ return id.replace(/[^a-zA-Z0-9._-]/g, "_");
68
+ }
69
+ }
70
+ //# sourceMappingURL=workspace.js.map
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Pi extension: browser tools for in-process sibling sessions.
3
+ *
4
+ * Pi subagent sessions are created inside the broker process (pi-subagents
5
+ * children never get the session-level customTools that ACP sessions get).
6
+ * This extension plugs that gap: when it loads in a process with an active
7
+ * tool bridge (the Pi Browser native-host broker), it registers the add-on
8
+ * tool surface — Firefox's browser tools and Thunderbird's mail / compose /
9
+ * mail-organization / contacts tools — with execution routed through the
10
+ * provider's standard path (cross-app routing, permission prompts, activity
11
+ * tracking), same as the parent session's tools.
12
+ *
13
+ * Loaded explicitly via an agent's `extensions:` list, e.g.:
14
+ *
15
+ * ---
16
+ * name: browser
17
+ * extensions: ["<repo>/packages/pi-agent/extensions/pi-browser-tools.ts"]
18
+ * tools: ext:pi-browser-tools
19
+ * ---
20
+ *
21
+ * In a plain Pi session (no broker) the bridge is undefined and the
22
+ * extension registers nothing.
23
+ */
24
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
25
+ import { getBrowserToolBridge } from "../dist/tool-bridge.js";
26
+ import { BROWSER_TOOL_SCHEMAS } from "../dist/browser/schemas.js";
27
+ import { MAIL_TOOL_SCHEMAS } from "../dist/mail/schemas.js";
28
+ import { COMPOSE_TOOL_SCHEMAS } from "../dist/compose/schemas.js";
29
+ import { MAIL_MUTATION_TOOL_SCHEMAS } from "../dist/mutation/schemas.js";
30
+ import { CONTACTS_TOOL_SCHEMAS } from "../dist/contacts/schemas.js";
31
+
32
+ const TOOL_SCHEMAS = [
33
+ ...BROWSER_TOOL_SCHEMAS,
34
+ ...MAIL_TOOL_SCHEMAS,
35
+ ...COMPOSE_TOOL_SCHEMAS,
36
+ ...MAIL_MUTATION_TOOL_SCHEMAS,
37
+ ...CONTACTS_TOOL_SCHEMAS,
38
+ ];
39
+
40
+ export default function (pi: ExtensionAPI) {
41
+ pi.on("session_start", () => {
42
+ const bridge = getBrowserToolBridge();
43
+ if (!bridge) return; // plain pi session — no broker, nothing to register
44
+ for (const tool of TOOL_SCHEMAS) {
45
+ pi.registerTool({
46
+ name: tool.name,
47
+ label: tool.name,
48
+ description: tool.description,
49
+ parameters: tool.parameters,
50
+ execute: async (toolCallId, params) => {
51
+ const result = await bridge.call({
52
+ tool: tool.name,
53
+ args: params as Record<string, unknown>,
54
+ toolCallId,
55
+ });
56
+ return {
57
+ content: result.content,
58
+ details: { piBrowser: true, tool: tool.name },
59
+ ...(result.isError ? { isError: true } : {}),
60
+ };
61
+ },
62
+ });
63
+ }
64
+ });
65
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Pi extension: /pi-browser command (see docs/VERIFICATION.md item 2).
3
+ *
4
+ * Loaded by every Pi session via the package's conventional extensions/
5
+ * directory. It only registers a command; it never starts servers or
6
+ * touches the network at load time.
7
+ *
8
+ * Commands:
9
+ * /pi-browser install register the Firefox Native Messaging host
10
+ * /pi-browser status report installation state
11
+ * /pi-browser doctor status + live host probe (framed ping)
12
+ * /pi-browser uninstall remove the registration
13
+ * /pi-browser mcp [install|status|uninstall] [client]
14
+ * register the pi-browser MCP server (stdio bridge)
15
+ * in an MCP client's user config: pi (default,
16
+ * ~/.pi/agent/mcp.json), claude, codex, cursor,
17
+ * gemini, vscode, or all
18
+ */
19
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
20
+ import { PI_BROWSER } from "@pi-browser/protocol";
21
+
22
+ const VALID_COMMANDS = new Set(["install", "status", "doctor", "uninstall", "mcp"]);
23
+ const VALID_MCP_SUBS = new Set(["install", "status", "uninstall"]);
24
+ const VALID_MCP_CLIENTS = new Set(["pi", "claude", "codex", "cursor", "gemini", "vscode", "all"]);
25
+ const MCP_USAGE = "/pi-browser mcp [install|status|uninstall] [pi|claude|codex|cursor|gemini|vscode|all]";
26
+
27
+ export default function (pi: ExtensionAPI) {
28
+ pi.registerCommand("pi-browser", {
29
+ description: "Manage the Pi Browser Firefox integration: install | status | doctor | uninstall | mcp [install|status|uninstall] [client]",
30
+ handler: async (args, ctx) => {
31
+ const [command = "status", mcpSub, mcpClient] = (args ?? "").trim().split(/\s+/).filter(Boolean);
32
+ if (!VALID_COMMANDS.has(command)) {
33
+ ctx.ui.notify(
34
+ `/pi-browser [install|status|doctor|uninstall|mcp [install|status|uninstall] [client]] — register, check, probe, remove, or configure the ${PI_BROWSER.nativeHost} Firefox integration`,
35
+ "warning",
36
+ );
37
+ return;
38
+ }
39
+ if (
40
+ command === "mcp" &&
41
+ ((mcpSub !== undefined && !VALID_MCP_SUBS.has(mcpSub)) || (mcpClient !== undefined && !VALID_MCP_CLIENTS.has(mcpClient)))
42
+ ) {
43
+ ctx.ui.notify(MCP_USAGE, "warning");
44
+ return;
45
+ }
46
+ try {
47
+ const { runCommand, defaultPkgRoot } = await import("../dist/installer/index.js");
48
+ const result = await runCommand(
49
+ command,
50
+ { pkgRoot: defaultPkgRoot(), ...(mcpClient ? { mcpClient } : {}) },
51
+ mcpSub,
52
+ );
53
+ ctx.ui.notify(result.lines.join("\n"), result.ok ? "info" : "warning");
54
+ } catch (err) {
55
+ const message = err instanceof Error ? err.message : String(err);
56
+ ctx.ui.notify(`/pi-browser ${command} failed: ${message}`, "error");
57
+ }
58
+ },
59
+ });
60
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Pi extension: skills runtime (skills-runtime-design.md §10).
3
+ *
4
+ * Loaded explicitly via an agent's `extensions:` list in the host broker:
5
+ *
6
+ * extensions: ["<repo>/packages/pi-agent/extensions/pi-skills.ts"]
7
+ *
8
+ * The factory registers nothing in a plain pi session (no host bridge) and
9
+ * is never loaded into isolated job sessions (noExtensions). All behavior
10
+ * lives in src/skills/extension.ts so it is testable from the test build.
11
+ */
12
+ import { createSkillsExtensionFactory } from "../dist/skills/extension.js";
13
+
14
+ export default createSkillsExtensionFactory();
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ exec "/mnt/NVME2TB/.local/share/pi-node/node-v22.22.3-linux-x64/bin/node" "/home/acidhax/dev/personal/firefox-acp-addon/packages/pi-agent/dist/native-host/main.js" "$@"
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ # Node lives under $HOME so that confined browsers (e.g. snap Firefox) can
3
+ # exec it: the native host process inherits the browser's namespace.
4
+ export PI_BROWSER_LOG_FILE=/tmp/pi-browser-host.log
5
+ exec "$HOME/.local/lib/pi-browser/node" "/home/acidhax/dev/personal/firefox-acp-addon/packages/pi-agent/dist/native-host/main.js" "$@"
@@ -0,0 +1,3 @@
1
+ @echo off
2
+ rem Template launcher - replaced with absolute paths by `/pi-browser install`.
3
+ node "REPLACE_WITH_ABSOLUTE_DIST\native-host\main.js" %*
@@ -0,0 +1,10 @@
1
+ /**
2
+ * ACP (Agent Client Protocol) surface used by Pi Browser.
3
+ *
4
+ * Canonical types and method constants come from the official
5
+ * @agentclientprotocol/sdk package; this module re-exports the subset that
6
+ * both the Pi native host and the Firefox add-on consume.
7
+ */
8
+ export { AGENT_METHODS, CLIENT_METHODS, PROTOCOL_METHODS, PROTOCOL_VERSION, } from "@agentclientprotocol/sdk";
9
+ export type { InitializeRequest, InitializeResponse, AgentCapabilities, ClientCapabilities, PromptCapabilities, McpCapabilities, SessionCapabilities, Implementation, ProtocolVersion, NewSessionRequest, NewSessionResponse, LoadSessionRequest, LoadSessionResponse, ListSessionsRequest, ListSessionsResponse, ResumeSessionRequest, ResumeSessionResponse, CloseSessionRequest, CloseSessionResponse, SessionInfo, PromptRequest, PromptResponse, CancelNotification, StopReason, ContentBlock, TextContent, ImageContent as AcpImageContent, AudioContent, ResourceLink, EmbeddedResource, Usage, SessionNotification, SessionUpdate, ContentChunk, ToolCall, ToolCallUpdate, ToolCallContent, ToolCallStatus, ToolKind, ConfigOptionUpdate, SessionModeState, SessionMode, SessionConfigOption, SessionConfigSelect, SessionConfigBoolean, SessionConfigOptionCategory, SetSessionConfigOptionRequest, SetSessionConfigOptionResponse, McpServer, McpServerStdio, McpServerHttp, McpServerSse, McpServerAcp, McpServerAcpId, McpConnectionId, ConnectMcpRequest, ConnectMcpResponse, DisconnectMcpRequest, MessageMcpRequest, MessageMcpResponse, RequestPermissionRequest, RequestPermissionResponse, RequestPermissionOutcome, PermissionOption, PermissionOptionId, PermissionOptionKind, ToolCall as AcpToolCall, } from "@agentclientprotocol/sdk";
10
+ //# sourceMappingURL=acp.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * ACP (Agent Client Protocol) surface used by Pi Browser.
3
+ *
4
+ * Canonical types and method constants come from the official
5
+ * @agentclientprotocol/sdk package; this module re-exports the subset that
6
+ * both the Pi native host and the Firefox add-on consume.
7
+ */
8
+ export { AGENT_METHODS, CLIENT_METHODS, PROTOCOL_METHODS, PROTOCOL_VERSION, } from "@agentclientprotocol/sdk";
9
+ //# sourceMappingURL=acp.js.map
@@ -0,0 +1,51 @@
1
+ /**
2
+ * External ACP agents in the sidebar (openspec change `sidebar-acp-agents`).
3
+ *
4
+ * A sidebar, Space or pane session runs either on the built-in pi agent or
5
+ * on an external ACP agent (Claude Code, Codex, or one the user configures
6
+ * in `~/.pi/browser/agents.json`). The host relays such a session to the
7
+ * agent's ACP adapter and gives it the pi-browser tools through the stdio
8
+ * bridge, tied to the sidebar session.
9
+ *
10
+ * All of this is additive: an add-on that never asks `x-pi-browser/agents`
11
+ * and never sets `_meta.piBrowser.agent` keeps getting pi sessions; a host
12
+ * that doesn't answer `x-pi-browser/agents` makes new add-ons show no choice.
13
+ */
14
+ /** Client → host: the agents a new session can run on. */
15
+ export declare const AGENTS_METHOD = "x-pi-browser/agents";
16
+ /** Id of the built-in agent. A session without an agent id runs on pi. */
17
+ export declare const PI_AGENT_ID = "pi";
18
+ /** Environment variable naming the sidebar session a bridge belongs to. */
19
+ export declare const PARENT_SESSION_ENV = "PI_BROWSER_PARENT_SESSION";
20
+ /** One agent the user can pick in the new-session panel. */
21
+ export interface AgentInfo {
22
+ /** Stable id (`pi`, `claude`, `codex`, or an `agents.json` key). */
23
+ id: string;
24
+ /** Display name ("Claude Code"). */
25
+ name: string;
26
+ /** Whether a session can be started on it now. */
27
+ available: boolean;
28
+ /** Why it isn't available (for example the missing command). */
29
+ reason?: string;
30
+ }
31
+ /** Result of `x-pi-browser/agents`. */
32
+ export interface AgentsResult {
33
+ agents: AgentInfo[];
34
+ /** The agent the panel preselects when it has no remembered choice. */
35
+ defaultAgent: string;
36
+ /** Problem reading `agents.json` (the built-in agents are still listed). */
37
+ configError?: string;
38
+ }
39
+ /** `{id, name}` of an agent, as carried in `_meta.piBrowser.agent`. */
40
+ export interface AgentRef {
41
+ id: string;
42
+ name: string;
43
+ }
44
+ /**
45
+ * Read the requested agent id from `session/new` params
46
+ * (`_meta.piBrowser.agent`, a string id). Undefined means pi.
47
+ */
48
+ export declare function requestedAgentId(params: unknown): string | undefined;
49
+ /** Read `_meta.piBrowser.agent` (`{id, name}`) from a listed session or a permission request. */
50
+ export declare function agentRefOf(value: unknown): AgentRef | undefined;
51
+ //# sourceMappingURL=agents.d.ts.map
@@ -0,0 +1,44 @@
1
+ /**
2
+ * External ACP agents in the sidebar (openspec change `sidebar-acp-agents`).
3
+ *
4
+ * A sidebar, Space or pane session runs either on the built-in pi agent or
5
+ * on an external ACP agent (Claude Code, Codex, or one the user configures
6
+ * in `~/.pi/browser/agents.json`). The host relays such a session to the
7
+ * agent's ACP adapter and gives it the pi-browser tools through the stdio
8
+ * bridge, tied to the sidebar session.
9
+ *
10
+ * All of this is additive: an add-on that never asks `x-pi-browser/agents`
11
+ * and never sets `_meta.piBrowser.agent` keeps getting pi sessions; a host
12
+ * that doesn't answer `x-pi-browser/agents` makes new add-ons show no choice.
13
+ */
14
+ /** Client → host: the agents a new session can run on. */
15
+ export const AGENTS_METHOD = "x-pi-browser/agents";
16
+ /** Id of the built-in agent. A session without an agent id runs on pi. */
17
+ export const PI_AGENT_ID = "pi";
18
+ /** Environment variable naming the sidebar session a bridge belongs to. */
19
+ export const PARENT_SESSION_ENV = "PI_BROWSER_PARENT_SESSION";
20
+ /**
21
+ * Read the requested agent id from `session/new` params
22
+ * (`_meta.piBrowser.agent`, a string id). Undefined means pi.
23
+ */
24
+ export function requestedAgentId(params) {
25
+ const meta = params?._meta?.piBrowser?.agent;
26
+ if (typeof meta === "string" && meta.trim())
27
+ return meta.trim();
28
+ if (typeof meta === "object" && meta !== null && typeof meta.id === "string") {
29
+ const id = (meta.id).trim();
30
+ return id || undefined;
31
+ }
32
+ return undefined;
33
+ }
34
+ /** Read `_meta.piBrowser.agent` (`{id, name}`) from a listed session or a permission request. */
35
+ export function agentRefOf(value) {
36
+ const a = value?._meta?.piBrowser?.agent;
37
+ if (typeof a !== "object" || a === null)
38
+ return undefined;
39
+ const r = a;
40
+ if (typeof r.id !== "string" || !r.id)
41
+ return undefined;
42
+ return { id: r.id, name: typeof r.name === "string" && r.name ? r.name : r.id };
43
+ }
44
+ //# sourceMappingURL=agents.js.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * MCP-compatible browser tool definitions (PRODUCT.md §25).
3
+ *
4
+ * These schemas are transport-independent: the same names, arguments, and
5
+ * results are used whether tools are invoked over the private
6
+ * x-pi-browser/tool compatibility transport or over MCP (stdio/HTTP or
7
+ * MCP-over-ACP). The Firefox side implements the tools; the Pi side
8
+ * registers them as agent tools.
9
+ */
10
+ export interface BrowserToolDef {
11
+ name: string;
12
+ description: string;
13
+ /** JSON Schema (draft-07 compatible) for the tool arguments. */
14
+ inputSchema: Record<string, unknown>;
15
+ /** Read-only tools never mutate the bound tab; mutating tools always target the session-bound tab. */
16
+ readOnly: boolean;
17
+ }
18
+ /**
19
+ * Optional frame target for tools that run in a frame's content script.
20
+ * A frameId (number) or a URL substring (string) — the frames list in
21
+ * browser_get_dom's result is what the agent picks from. Absent = top frame.
22
+ */
23
+ export declare const BROWSER_FRAME_DESCRIPTION: string;
24
+ export declare const BROWSER_TOOLS: readonly BrowserToolDef[];
25
+ export declare function getBrowserTool(name: string): BrowserToolDef | undefined;
26
+ export declare function isBrowserTool(name: string): boolean;
27
+ export declare function isMutatingBrowserTool(name: string): boolean;
28
+ export declare const BROWSER_TOOL_NAMES: readonly string[];
29
+ export declare const REPL_TOOLS: readonly BrowserToolDef[];
30
+ export declare const REPL_TOOL_NAMES: readonly string[];
31
+ /** True for tools executed by the host REPL (never routed to the add-on). */
32
+ export declare function isReplTool(name: string): boolean;
33
+ //# sourceMappingURL=browser-tools.d.ts.map