trusted-user-agent 0.0.0-stage → 0.3.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.
- package/LICENSE +21 -0
- package/dist/acp/agent.js +601 -0
- package/dist/acp/backend.js +2 -0
- package/dist/acp/config-options.js +26 -0
- package/dist/acp/mock-backend.js +277 -0
- package/dist/acp/sdk-backend.js +495 -0
- package/dist/browser/mcp-acp-client.js +81 -0
- package/dist/browser/provider.js +1045 -0
- package/dist/browser/schemas.js +221 -0
- package/dist/capability-registry.js +92 -0
- package/dist/client-heartbeat.js +118 -0
- package/dist/compose/schemas.js +90 -0
- package/dist/contacts/schemas.js +26 -0
- package/dist/installer/cli.js +70 -0
- package/dist/installer/common.js +93 -0
- package/dist/installer/index.js +341 -0
- package/dist/installer/mcp-clients.js +555 -0
- package/dist/installer/mcp.js +166 -0
- package/dist/installer/platforms.js +277 -0
- package/dist/logger.js +54 -0
- package/dist/mail/schemas.js +98 -0
- package/dist/mutation/schemas.js +31 -0
- package/dist/native-host/broker-ipc.js +344 -0
- package/dist/native-host/framing.js +76 -0
- package/dist/native-host/main.js +520 -0
- package/dist/native-host/mcp-server.js +322 -0
- package/dist/native-host/mcp-stdio-bridge.js +179 -0
- package/dist/native-host/mcp-stdio-main.js +13 -0
- package/dist/native-host/relay.js +84 -0
- package/dist/native-host/skills-startup.js +167 -0
- package/dist/native-host/transport.js +248 -0
- package/dist/permission-store.js +207 -0
- package/dist/repl/fs-sandbox.js +187 -0
- package/dist/repl/provider.js +252 -0
- package/dist/repl/runtime.js +436 -0
- package/dist/repl/types.js +10 -0
- package/dist/repl/worker.js +731 -0
- package/dist/skills/extension.js +99 -0
- package/dist/skills/grants-file.js +145 -0
- package/dist/skills/isolated-runner.js +259 -0
- package/dist/skills/mock-session-factory.js +49 -0
- package/dist/skills/package-roots.js +25 -0
- package/dist/skills/pi-bridge.js +8 -0
- package/dist/skills/pi-integration.js +110 -0
- package/dist/skills/planner.js +128 -0
- package/dist/skills/registry.js +104 -0
- package/dist/skills/skills-protocol.js +253 -0
- package/dist/skills/skills-service.js +195 -0
- package/dist/tool-bridge.js +8 -0
- package/dist/workspace.js +70 -0
- package/extensions/pi-browser-tools.ts +65 -0
- package/extensions/pi-browser.ts +60 -0
- package/extensions/pi-skills.ts +14 -0
- package/native/pi-agent-host +2 -0
- package/native/pi-browser-host +5 -0
- package/native/pi-browser-host.cmd +3 -0
- package/node_modules/@pi-browser/protocol/.bundled-by-trusted-user-agent +0 -0
- package/node_modules/@pi-browser/protocol/dist/acp.d.ts +10 -0
- package/node_modules/@pi-browser/protocol/dist/acp.js +9 -0
- package/node_modules/@pi-browser/protocol/dist/browser-tools.d.ts +33 -0
- package/node_modules/@pi-browser/protocol/dist/browser-tools.js +478 -0
- package/node_modules/@pi-browser/protocol/dist/callers.d.ts +108 -0
- package/node_modules/@pi-browser/protocol/dist/callers.js +56 -0
- package/node_modules/@pi-browser/protocol/dist/compose-tools.d.ts +30 -0
- package/node_modules/@pi-browser/protocol/dist/compose-tools.js +175 -0
- package/node_modules/@pi-browser/protocol/dist/contacts-tools.d.ts +23 -0
- package/node_modules/@pi-browser/protocol/dist/contacts-tools.js +63 -0
- package/node_modules/@pi-browser/protocol/dist/control-tools.d.ts +32 -0
- package/node_modules/@pi-browser/protocol/dist/control-tools.js +201 -0
- package/node_modules/@pi-browser/protocol/dist/errors.d.ts +63 -0
- package/node_modules/@pi-browser/protocol/dist/errors.js +109 -0
- package/node_modules/@pi-browser/protocol/dist/index.d.ts +16 -0
- package/node_modules/@pi-browser/protocol/dist/index.js +16 -0
- package/node_modules/@pi-browser/protocol/dist/integration.d.ts +409 -0
- package/node_modules/@pi-browser/protocol/dist/integration.js +260 -0
- package/node_modules/@pi-browser/protocol/dist/jsonrpc.d.ts +33 -0
- package/node_modules/@pi-browser/protocol/dist/jsonrpc.js +31 -0
- package/node_modules/@pi-browser/protocol/dist/mail-mutation-tools.d.ts +27 -0
- package/node_modules/@pi-browser/protocol/dist/mail-mutation-tools.js +88 -0
- package/node_modules/@pi-browser/protocol/dist/mail-tools.d.ts +133 -0
- package/node_modules/@pi-browser/protocol/dist/mail-tools.js +245 -0
- package/node_modules/@pi-browser/protocol/dist/permission.d.ts +113 -0
- package/node_modules/@pi-browser/protocol/dist/permission.js +257 -0
- package/node_modules/@pi-browser/protocol/dist/skills.d.ts +304 -0
- package/node_modules/@pi-browser/protocol/dist/skills.js +473 -0
- package/node_modules/@pi-browser/protocol/dist/tool-capabilities.d.ts +18 -0
- package/node_modules/@pi-browser/protocol/dist/tool-capabilities.js +52 -0
- package/node_modules/@pi-browser/protocol/dist/transport.d.ts +17 -0
- package/node_modules/@pi-browser/protocol/dist/transport.js +17 -0
- package/node_modules/@pi-browser/protocol/package.json +14 -0
- package/package.json +71 -6
- package/skills/browser-walk/SKILL.md +98 -0
- package/README.md +0 -3
|
@@ -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,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,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" "$@"
|
|
File without changes
|
|
@@ -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,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
|