@rivet-dev/pi 0.1.0 → 0.5.1

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 (66) hide show
  1. package/LICENSE +190 -0
  2. package/dist/actions.d.ts +188 -77
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +276 -103
  5. package/dist/actions.js.map +1 -1
  6. package/dist/actor-config.d.ts +32 -0
  7. package/dist/actor-config.d.ts.map +1 -0
  8. package/dist/actor-config.js +86 -0
  9. package/dist/actor-config.js.map +1 -0
  10. package/dist/actor-sqlite.d.ts +10 -0
  11. package/dist/actor-sqlite.d.ts.map +1 -0
  12. package/dist/actor-sqlite.js +32 -0
  13. package/dist/actor-sqlite.js.map +1 -0
  14. package/dist/actor-types.d.ts +34 -0
  15. package/dist/actor-types.d.ts.map +1 -0
  16. package/dist/actor-types.js +2 -0
  17. package/dist/actor-types.js.map +1 -0
  18. package/dist/actor.d.ts +27 -15
  19. package/dist/actor.d.ts.map +1 -1
  20. package/dist/actor.js +71 -78
  21. package/dist/actor.js.map +1 -1
  22. package/dist/credentials.d.ts +3 -4
  23. package/dist/credentials.d.ts.map +1 -1
  24. package/dist/credentials.js +11 -38
  25. package/dist/credentials.js.map +1 -1
  26. package/dist/drain.d.ts +12 -0
  27. package/dist/drain.d.ts.map +1 -0
  28. package/dist/drain.js +20 -0
  29. package/dist/drain.js.map +1 -0
  30. package/dist/durable.d.ts +24 -0
  31. package/dist/durable.d.ts.map +1 -0
  32. package/dist/durable.js +5 -0
  33. package/dist/durable.js.map +1 -0
  34. package/dist/errors.d.ts +8 -0
  35. package/dist/errors.d.ts.map +1 -0
  36. package/dist/errors.js +19 -0
  37. package/dist/errors.js.map +1 -0
  38. package/dist/index.d.ts +5 -4
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +1 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/models.d.ts +7 -33
  43. package/dist/models.d.ts.map +1 -1
  44. package/dist/models.js +4 -67
  45. package/dist/models.js.map +1 -1
  46. package/dist/runtime.d.ts +111 -43
  47. package/dist/runtime.d.ts.map +1 -1
  48. package/dist/runtime.js +444 -225
  49. package/dist/runtime.js.map +1 -1
  50. package/dist/storage.d.ts +27 -28
  51. package/dist/storage.d.ts.map +1 -1
  52. package/dist/storage.js +33 -55
  53. package/dist/storage.js.map +1 -1
  54. package/dist/tracing.d.ts +7 -4
  55. package/dist/tracing.d.ts.map +1 -1
  56. package/dist/tracing.js +11 -12
  57. package/dist/tracing.js.map +1 -1
  58. package/dist/watches.d.ts +77 -0
  59. package/dist/watches.d.ts.map +1 -0
  60. package/dist/watches.js +245 -0
  61. package/dist/watches.js.map +1 -0
  62. package/package.json +38 -15
  63. package/dist/sandbox.d.ts +0 -21
  64. package/dist/sandbox.d.ts.map +0 -1
  65. package/dist/sandbox.js +0 -185
  66. package/dist/sandbox.js.map +0 -1
@@ -0,0 +1,245 @@
1
+ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
2
+ import { watchEvents, } from "@earendil-works/pi-durable";
3
+ import { deleteConnectionWatches, deleteWatch, loadWatches, saveWatch, } from "./storage.js";
4
+ export function createConnectionWatches() {
5
+ return { byConnection: new Map(), queue: Promise.resolve() };
6
+ }
7
+ function serially(watches, change) {
8
+ const run = watches.queue.then(change);
9
+ watches.queue = run.catch(() => { });
10
+ return run;
11
+ }
12
+ function watchKey(spec) {
13
+ switch (spec.kind) {
14
+ case "events":
15
+ case "view":
16
+ return `${spec.kind}:${spec.conversationId}`;
17
+ case "taskGraph":
18
+ return spec.kind;
19
+ case "doc":
20
+ return `doc:${spec.conversationId}:${spec.docKind}`;
21
+ }
22
+ }
23
+ /**
24
+ * Starts a watch for a connection, stored so it comes back after sleep, and
25
+ * returns the value it starts from. Watching the same thing again restarts
26
+ * it with a fresh value. `requireTarget` runs in the queue too, so a watch
27
+ * and an unwatch sent right after it take effect in the order they arrive.
28
+ */
29
+ export async function watch(actor, watches, harness, documents, connId, spec, requireTarget) {
30
+ const key = watchKey(spec);
31
+ return serially(watches, async () => {
32
+ await requireTarget();
33
+ await saveWatch(actor.db, { connId, key, spec });
34
+ return attach(actor, watches, harness, documents, connId, key, spec, false);
35
+ });
36
+ }
37
+ export async function unwatch(actor, watches, connId, spec) {
38
+ const key = watchKey(spec);
39
+ await serially(watches, async () => {
40
+ const active = watches.byConnection.get(connId)?.get(key);
41
+ watches.byConnection.get(connId)?.delete(key);
42
+ await active?.stop();
43
+ await deleteWatch(actor.db, connId, key);
44
+ });
45
+ }
46
+ /** Ends every watch of a connection that left. */
47
+ export async function unwatchConnection(actor, watches, connId) {
48
+ await serially(watches, async () => {
49
+ const active = [...(watches.byConnection.get(connId)?.values() ?? [])];
50
+ watches.byConnection.delete(connId);
51
+ await Promise.all(active.map((watch) => watch.stop()));
52
+ await deleteConnectionWatches(actor.db, connId);
53
+ });
54
+ }
55
+ /** Ends every watch of this generation, without forgetting them. Called when the harness closes. */
56
+ export async function stopAllWatches(watches) {
57
+ await serially(watches, async () => {
58
+ const active = [...watches.byConnection.values()].flatMap((byKey) => [
59
+ ...byKey.values(),
60
+ ]);
61
+ watches.byConnection.clear();
62
+ await Promise.all(active.map((watch) => watch.stop()));
63
+ });
64
+ }
65
+ /**
66
+ * Restarts the stored watches of connections that are still open, after wake
67
+ * or a reopen. Each sends its whole value as a `seq` 0 frame. Watches of
68
+ * connections that are gone are forgotten.
69
+ */
70
+ export async function reattachWatches(actor, watches, harness, documents) {
71
+ await serially(watches, async () => {
72
+ const open = new Set(actor.conns.keys());
73
+ for (const stored of await loadWatches(actor.db)) {
74
+ if (!open.has(stored.connId)) {
75
+ await deleteWatch(actor.db, stored.connId, stored.key);
76
+ continue;
77
+ }
78
+ try {
79
+ await attach(actor, watches, harness, documents, stored.connId, stored.key, stored.spec, true);
80
+ }
81
+ catch (error) {
82
+ actor.log.warn({
83
+ msg: "pi durable could not reattach a watch after wake",
84
+ connId: stored.connId,
85
+ watch: stored.key,
86
+ error,
87
+ });
88
+ }
89
+ }
90
+ });
91
+ }
92
+ async function attach(actor, watches, harness, documents, connId, key, spec, resend) {
93
+ const byKey = watches.byConnection.get(connId) ?? new Map();
94
+ watches.byConnection.set(connId, byKey);
95
+ await byKey.get(key)?.stop();
96
+ let seq = 0;
97
+ let active;
98
+ const send = (name, frame) => {
99
+ const conn = actor.conns.get(connId);
100
+ if (!conn) {
101
+ void active?.stop();
102
+ return;
103
+ }
104
+ conn.send(name, { ...frame, seq: seq++ });
105
+ };
106
+ const started = await start(actor.log, harness, documents, spec, send, resend);
107
+ active = started;
108
+ byKey.set(key, started);
109
+ if (!resend)
110
+ seq = 1;
111
+ return started.initial;
112
+ }
113
+ /** Starts the Pi watch. With `resend`, the initial value goes out as the first frame. */
114
+ async function start(log, harness, documents, spec, send, resend) {
115
+ const context = BACKGROUND_CONTEXT;
116
+ switch (spec.kind) {
117
+ case "events": {
118
+ const conversationId = spec.conversationId;
119
+ const stream = await watchEvents(harness, conversationId, context);
120
+ if (resend)
121
+ send("pi.events", {
122
+ conversationId,
123
+ events: [stream.snapshot],
124
+ });
125
+ stream.start(async (events) => send("pi.events", { conversationId, events }));
126
+ return {
127
+ initial: { snapshot: stream.snapshot },
128
+ stop: async () => void (await stream.stop()),
129
+ };
130
+ }
131
+ case "view": {
132
+ const conversationId = spec.conversationId;
133
+ const conversation = await harness.conversation(conversationId, context);
134
+ if (!conversation)
135
+ throw new Error(`conversation ${conversationId} does not exist`);
136
+ const view = await conversation.watch(context);
137
+ if (resend)
138
+ send("pi.view", { conversationId, value: view.value });
139
+ view.start(async (_value, ops) => send("pi.view", { conversationId, ops }));
140
+ return {
141
+ initial: { value: view.value },
142
+ stop: async () => void (await view.stop()),
143
+ };
144
+ }
145
+ case "taskGraph": {
146
+ const graph = await harness.watchTaskGraph(context);
147
+ if (resend)
148
+ send("pi.taskGraph", { value: graph.value });
149
+ graph.start(async (_value, ops) => send("pi.taskGraph", { ops }));
150
+ return {
151
+ initial: { value: graph.value },
152
+ stop: async () => void (await graph.stop()),
153
+ };
154
+ }
155
+ case "doc":
156
+ return startDoc(log, harness, documents, spec, send, resend);
157
+ }
158
+ }
159
+ /**
160
+ * Pi's `watchDoc` never creates a document, and its watch ends when the
161
+ * document is retired. While the document does not exist, the watch attaches
162
+ * when a commit creates it, and its value is the next frame.
163
+ */
164
+ async function startDoc(log, harness, documents, spec, send, resend) {
165
+ const token = documents.get(spec.docKind);
166
+ if (!token)
167
+ throw new Error(`document ${spec.docKind} is not listed in pi({ documents })`);
168
+ const { docKind: kind, conversationId } = spec;
169
+ const conversation = conversationId;
170
+ let docWatch;
171
+ let unsubscribe;
172
+ let stopped = false;
173
+ const follow = (handle, sendFirst) => {
174
+ docWatch = handle;
175
+ if (sendFirst)
176
+ send("pi.doc", { kind, conversationId, value: handle.value });
177
+ handle.start(async (value) => {
178
+ send("pi.doc", { kind, conversationId, value });
179
+ if (value !== null || stopped)
180
+ return;
181
+ // A retired document's watch ends, so wait for a commit that creates it again.
182
+ docWatch = undefined;
183
+ void handle.stop();
184
+ awaitCreation();
185
+ });
186
+ };
187
+ const awaitCreation = () => {
188
+ let attaching = false;
189
+ const attachCreated = async () => {
190
+ try {
191
+ const handle = await harness.watchDoc(token, conversation, BACKGROUND_CONTEXT);
192
+ if (stopped) {
193
+ await handle?.stop();
194
+ return;
195
+ }
196
+ if (!handle) {
197
+ attaching = false;
198
+ return;
199
+ }
200
+ unsubscribe?.();
201
+ unsubscribe = undefined;
202
+ follow(handle, true);
203
+ }
204
+ catch (error) {
205
+ // The next write to the document tries again.
206
+ attaching = false;
207
+ log.warn({
208
+ msg: "pi durable could not attach a document watch",
209
+ kind,
210
+ conversationId,
211
+ error,
212
+ });
213
+ }
214
+ };
215
+ unsubscribe = harness.subscribeCommits((publication) => {
216
+ const created = publication.changes.some((change) => change.type === "document" &&
217
+ change.record.kind === kind &&
218
+ change.conversationId === conversation &&
219
+ change.value !== null);
220
+ if (!created || attaching)
221
+ return;
222
+ attaching = true;
223
+ // Commit listeners must not call Pi Durable, so the watch attaches after the listener returns.
224
+ queueMicrotask(() => void attachCreated());
225
+ });
226
+ };
227
+ const existing = await harness.watchDoc(token, conversation, BACKGROUND_CONTEXT);
228
+ if (existing) {
229
+ follow(existing, resend);
230
+ }
231
+ else {
232
+ if (resend)
233
+ send("pi.doc", { kind, conversationId, value: null });
234
+ awaitCreation();
235
+ }
236
+ return {
237
+ initial: { value: existing?.value },
238
+ stop: async () => {
239
+ stopped = true;
240
+ unsubscribe?.();
241
+ await docWatch?.stop();
242
+ },
243
+ };
244
+ }
245
+ //# sourceMappingURL=watches.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watches.js","sourceRoot":"","sources":["../src/watches.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAUN,WAAW,GACX,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACN,uBAAuB,EACvB,WAAW,EACX,WAAW,EACX,SAAS,GAET,MAAM,cAAc,CAAC;AAuDtB,MAAM,UAAU,uBAAuB;IACtC,OAAO,EAAE,YAAY,EAAE,IAAI,GAAG,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;AAC9D,CAAC;AAED,SAAS,QAAQ,CAChB,OAA0B,EAC1B,MAAwB;IAExB,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACpC,OAAO,GAAG,CAAC;AACZ,CAAC;AAID,SAAS,QAAQ,CAAC,IAAe;IAChC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,QAAQ,CAAC;QACd,KAAK,MAAM;YACV,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;QAC9C,KA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CAAC,WAAW,EAAE,EAAE;YACtD,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CACvC,CAAC,MAAM,EAAE,EAAE,CACV,MAAM,CAAC,IAAI,KAAK,UAAU;gBAC1B,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI;gBAC3B,MAAM,CAAC,cAAc,KAAK,YAAY;gBACtC,MAAM,CAAC,KAAK,KAAK,IAAI,CACtB,CAAC;YACF,IAAI,CAAC,OAAO,IAAI,SAAS;gBAAE,OAAO;YAClC,SAAS,GAAG,IAAI,CAAC;YACjB,+FAA+F;YAC/F,cAAc,CAAC,GAAG,EAAE,CAAC,KAAK,aAAa,EAAE,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,CACtC,KAAK,EACL,YAAY,EACZ,kBAAkB,CAClB,CAAC;IACF,IAAI,QAAQ,EAAE,CAAC;QACd,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC;SAAM,CAAC;QACP,IAAI,MAAM;YAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,aAAa,EAAE,CAAC;IACjB,CAAC;IACD,OAAO;QACN,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE;QACnC,IAAI,EAAE,KAAK,IAAI,EAAE;YAChB,OAAO,GAAG,IAAI,CAAC;YACf,WAAW,EAAE,EAAE,CAAC;YAChB,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC;QACxB,CAAC;KACD,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,8 +1,25 @@
1
1
  {
2
2
  "name": "@rivet-dev/pi",
3
- "version": "0.1.0",
3
+ "version": "0.5.1",
4
4
  "description": "Run the Pi coding agent as a durable Rivet Actor",
5
5
  "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/rivet-dev/agents.git",
9
+ "directory": "packages/pi"
10
+ },
11
+ "homepage": "https://rivet.dev/agents/docs/pi",
12
+ "bugs": "https://github.com/rivet-dev/agents/issues",
13
+ "keywords": [
14
+ "pi",
15
+ "coding-agent",
16
+ "agent",
17
+ "ai",
18
+ "rivet",
19
+ "rivetkit",
20
+ "actors",
21
+ "durable"
22
+ ],
6
23
  "publishConfig": {
7
24
  "access": "public"
8
25
  },
@@ -15,34 +32,40 @@
15
32
  ".": {
16
33
  "types": "./dist/index.d.ts",
17
34
  "default": "./dist/index.js"
35
+ },
36
+ "./durable": {
37
+ "types": "./dist/durable.d.ts",
38
+ "default": "./dist/durable.js"
18
39
  }
19
40
  },
20
41
  "main": "./dist/index.js",
21
42
  "types": "./dist/index.d.ts",
22
- "scripts": {
23
- "build": "tsc -p tsconfig.build.json",
24
- "check-types": "tsc --noEmit",
25
- "test": "vitest run"
26
- },
27
43
  "dependencies": {
28
- "@earendil-works/pi-coding-agent": "1.0.0",
44
+ "@earendil-works/pi-coding-agent": "^1.0.4",
29
45
  "@opentelemetry/api": "^1.1.0",
30
- "@rivet-dev/sandbox-adapter": "0.1.0",
31
- "rivetkit": "^2.3.22"
46
+ "@rivet-dev/sandbox-adapter": "0.5.1"
47
+ },
48
+ "peerDependencies": {
49
+ "@earendil-works/chord": "^1.0.0",
50
+ "@earendil-works/pi-durable": "^1.0.0",
51
+ "rivetkit": ">=2.3.23 <2.4.0"
32
52
  },
33
53
  "devDependencies": {
34
- "@earendil-works/pi-ai": "1.0.0",
54
+ "@earendil-works/chord": "^1.0.4",
55
+ "@earendil-works/pi-ai": "^1.0.4",
56
+ "@earendil-works/pi-durable": "^1.0.4",
35
57
  "@opentelemetry/sdk-trace-node": "2.11.0",
36
58
  "@types/node": "^24.0.0",
59
+ "rivetkit": "2.3.23",
37
60
  "typescript": "^5.9.2",
38
61
  "vitest": "^3.2.4"
39
62
  },
40
63
  "engines": {
41
64
  "node": ">=22.19.0"
42
65
  },
43
- "repository": {
44
- "type": "git",
45
- "url": "https://github.com/rivet-dev/rivet.git",
46
- "directory": "integrations/pi"
66
+ "scripts": {
67
+ "build": "tsc -p tsconfig.build.json",
68
+ "check-types": "tsc --noEmit",
69
+ "test": "vitest run"
47
70
  }
48
- }
71
+ }
package/dist/sandbox.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import { type BashOperations, type ToolDefinition } from "@earendil-works/pi-coding-agent";
2
- import type { Sandbox } from "@rivet-dev/sandbox-adapter";
3
- /**
4
- * Builds Pi's seven built-in coding tools with every file and shell operation
5
- * routed into the sandbox. Passed as `customTools`, they replace the built-in
6
- * tools of the same names.
7
- */
8
- export declare function createSandboxTools(sandbox: Sandbox): ToolDefinition<any, any, any>[];
9
- /**
10
- * Command execution for Pi's bash tool and `executeBash`, inside the sandbox.
11
- * Follows Pi's `BashOperations` contract: `timeout` is in seconds, and abort
12
- * and timeout reject with `aborted` and `timeout:<seconds>`.
13
- *
14
- * Pi passes the actor host's environment as `options.env`. It is not
15
- * forwarded, because it holds the host's provider keys; commands run with the
16
- * sandbox's own environment.
17
- */
18
- export declare function createSandboxBashOperations(sandbox: Sandbox): BashOperations;
19
- /** Resolves `path` against `root` and rejects anything outside it. */
20
- export declare function resolveSandboxPath(root: string, path: string): string;
21
- //# sourceMappingURL=sandbox.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,cAAc,EAUnB,KAAK,cAAc,EACnB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAO1D;;;;GAIG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,OAAO,GACd,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAgHjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,CAgB5E;AAED,sEAAsE;AACtE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAQrE"}
package/dist/sandbox.js DELETED
@@ -1,185 +0,0 @@
1
- import { posix } from "node:path";
2
- import { createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition, } from "@earendil-works/pi-coding-agent";
3
- const MAX_FIND_RESULTS = 1_000;
4
- const MAX_GREP_MATCHES = 1_000;
5
- const MAX_GREP_OUTPUT_BYTES = 512 * 1024;
6
- const IGNORED_DIRECTORIES = [".git", "node_modules"];
7
- /**
8
- * Builds Pi's seven built-in coding tools with every file and shell operation
9
- * routed into the sandbox. Passed as `customTools`, they replace the built-in
10
- * tools of the same names.
11
- */
12
- export function createSandboxTools(sandbox) {
13
- const root = normalizeRoot(sandbox.cwd);
14
- const resolvePath = (path) => resolveSandboxPath(root, path);
15
- const access = async (path) => {
16
- const resolved = resolvePath(path);
17
- if (!(await sandbox.exists(resolved))) {
18
- throw new Error(`Path not found: ${resolved}`);
19
- }
20
- };
21
- const readFile = async (path) => Buffer.from(await sandbox.readFile(resolvePath(path)));
22
- const writeFile = (path, content) => sandbox.writeFile(resolvePath(path), content);
23
- const read = createReadToolDefinition(root, {
24
- operations: {
25
- access,
26
- readFile,
27
- detectImageMimeType: async (path) => imageMimeType(path),
28
- },
29
- });
30
- const write = createWriteToolDefinition(root, {
31
- operations: {
32
- writeFile,
33
- mkdir: (path) => sandbox.mkdir(resolvePath(path)),
34
- },
35
- });
36
- const edit = createEditToolDefinition(root, {
37
- operations: { access, readFile, writeFile },
38
- });
39
- const bash = createBashToolDefinition(root, {
40
- operations: createSandboxBashOperations(sandbox),
41
- });
42
- const ls = createLsToolDefinition(root, {
43
- operations: {
44
- exists: (path) => sandbox.exists(resolvePath(path)),
45
- readdir: (path) => sandbox.readdir(resolvePath(path)),
46
- stat: async (path) => {
47
- const stat = await sandbox.stat(resolvePath(path));
48
- return { isDirectory: () => stat.isDirectory };
49
- },
50
- },
51
- });
52
- const find = createFindToolDefinition(root, {
53
- operations: {
54
- exists: (path) => sandbox.exists(resolvePath(path)),
55
- glob: async (pattern, searchDirectory, options) => {
56
- const searchRoot = resolvePath(searchDirectory);
57
- const result = await sandbox.exec(`find . -type f ${IGNORED_DIRECTORIES.map((directory) => `-not -path ${shellQuote(`*/${directory}/*`)}`).join(" ")}`, { cwd: searchRoot });
58
- if (result.exitCode !== 0) {
59
- throw new Error(result.stderr.trim() || `find exited with ${result.exitCode}`);
60
- }
61
- return result.stdout
62
- .split("\n")
63
- .map(stripDotSlash)
64
- .filter((path) => path.length > 0 && matchesToolGlob(path, pattern))
65
- .slice(0, Math.min(options.limit, MAX_FIND_RESULTS));
66
- },
67
- },
68
- });
69
- const grepBase = createGrepToolDefinition(root);
70
- const grep = {
71
- ...grepBase,
72
- execute: async (_toolCallId, params, signal) => {
73
- const searchPath = resolvePath(params.path ?? ".");
74
- const limit = Math.min(Math.max(1, params.limit ?? 100), MAX_GREP_MATCHES);
75
- const args = ["-r", "-n", "-I", "-H"];
76
- if (params.ignoreCase)
77
- args.push("-i");
78
- if (params.literal)
79
- args.push("-F");
80
- if (params.glob)
81
- args.push(`--include=${params.glob}`);
82
- if (params.context && params.context > 0) {
83
- args.push("-C", String(Math.floor(params.context)));
84
- }
85
- for (const directory of IGNORED_DIRECTORIES) {
86
- args.push(`--exclude-dir=${directory}`);
87
- }
88
- args.push("-e", params.pattern, "--", posix.relative(root, searchPath) || ".");
89
- const result = await sandbox.exec(`grep ${args.map(shellQuote).join(" ")}`, {
90
- cwd: root,
91
- signal,
92
- });
93
- if (result.exitCode !== 0 && result.exitCode !== 1) {
94
- throw new Error(result.stderr.trim() || `grep exited with ${result.exitCode}`);
95
- }
96
- const lines = result.stdout.replace(/\n$/, "").split("\n");
97
- const matched = lines[0] === "" ? [] : lines.map(stripDotSlash);
98
- const selected = matched.slice(0, limit);
99
- let output = selected.join("\n");
100
- let linesTruncated = false;
101
- if (Buffer.byteLength(output) > MAX_GREP_OUTPUT_BYTES) {
102
- output = Buffer.from(output).subarray(0, MAX_GREP_OUTPUT_BYTES).toString();
103
- linesTruncated = true;
104
- }
105
- const details = {};
106
- if (matched.length > selected.length)
107
- details.matchLimitReached = limit;
108
- if (linesTruncated)
109
- details.linesTruncated = true;
110
- return {
111
- content: [{ type: "text", text: output || "No matches found" }],
112
- details: Object.keys(details).length > 0 ? details : undefined,
113
- };
114
- },
115
- };
116
- return [read, bash, edit, write, grep, find, ls];
117
- }
118
- /**
119
- * Command execution for Pi's bash tool and `executeBash`, inside the sandbox.
120
- * Follows Pi's `BashOperations` contract: `timeout` is in seconds, and abort
121
- * and timeout reject with `aborted` and `timeout:<seconds>`.
122
- *
123
- * Pi passes the actor host's environment as `options.env`. It is not
124
- * forwarded, because it holds the host's provider keys; commands run with the
125
- * sandbox's own environment.
126
- */
127
- export function createSandboxBashOperations(sandbox) {
128
- const root = normalizeRoot(sandbox.cwd);
129
- return {
130
- async exec(command, requestedCwd, options) {
131
- const result = await sandbox.exec(command, {
132
- cwd: resolveSandboxPath(root, requestedCwd),
133
- timeoutMs: options.timeout === undefined ? undefined : options.timeout * 1000,
134
- signal: options.signal,
135
- onData: (chunk) => options.onData(Buffer.from(chunk)),
136
- });
137
- if (result.timedOut) {
138
- throw new Error(`timeout:${options.timeout}`);
139
- }
140
- return { exitCode: result.exitCode };
141
- },
142
- };
143
- }
144
- /** Resolves `path` against `root` and rejects anything outside it. */
145
- export function resolveSandboxPath(root, path) {
146
- const normalizedRoot = normalizeRoot(root);
147
- const resolved = posix.resolve(normalizedRoot, path);
148
- const prefix = normalizedRoot === "/" ? "/" : `${normalizedRoot}/`;
149
- if (resolved !== normalizedRoot && !resolved.startsWith(prefix)) {
150
- throw new Error(`Path escapes the sandbox working directory: ${path}`);
151
- }
152
- return resolved;
153
- }
154
- function normalizeRoot(path) {
155
- if (!posix.isAbsolute(path)) {
156
- throw new Error(`sandbox cwd must be an absolute POSIX path, received ${path}`);
157
- }
158
- return posix.normalize(path);
159
- }
160
- /** Pi's find semantics: a pattern without a slash matches the file name at any depth. */
161
- function matchesToolGlob(relativePath, pattern) {
162
- if (pattern.includes("/")) {
163
- return (posix.matchesGlob(relativePath, pattern) ||
164
- posix.matchesGlob(relativePath, `**/${pattern}`));
165
- }
166
- return posix.matchesGlob(posix.basename(relativePath), pattern);
167
- }
168
- function stripDotSlash(path) {
169
- return path.startsWith("./") ? path.slice(2) : path;
170
- }
171
- function imageMimeType(path) {
172
- const extension = posix.extname(path).toLowerCase();
173
- return {
174
- ".bmp": "image/bmp",
175
- ".gif": "image/gif",
176
- ".jpeg": "image/jpeg",
177
- ".jpg": "image/jpeg",
178
- ".png": "image/png",
179
- ".webp": "image/webp",
180
- }[extension];
181
- }
182
- function shellQuote(value) {
183
- return `'${value.replaceAll("'", `'"'"'`)}'`;
184
- }
185
- //# sourceMappingURL=sandbox.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAEN,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,GAIzB,MAAM,iCAAiC,CAAC;AAGzC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAC/B,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAC/B,MAAM,qBAAqB,GAAG,GAAG,GAAG,IAAI,CAAC;AACzC,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAErD;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CACjC,OAAgB;IAEhB,MAAM,IAAI,GAAG,aAAa,CAA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