pi-deltabox 0.1.5 → 0.1.7

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/README.md CHANGED
@@ -50,9 +50,9 @@ for low-latency byte I/O. Linux and macOS also reuse an isolated Bash worker.
50
50
  as compatibility fallbacks.
51
51
  - **Three review modes** — review everything at the end of a task, after every
52
52
  tool call, or only after risky calls.
53
- - **Slash commands** — `/sandbox-status`, `/sandbox-review`,
54
- `/sandbox-commit`, `/sandbox-abort`, `/sandbox-skip`, `/sandbox-diff`,
55
- `/sandbox-mode`.
53
+ - **Slash commands** — `/deltabox-status`, `/deltabox-review`,
54
+ `/deltabox-commit`, `/deltabox-abort`, `/deltabox-sync`, `/deltabox-skip`,
55
+ `/deltabox-diff`, `/deltabox-mode`, `/deltabox-exit`.
56
56
  - **End-of-task nudge** — when a task finishes with pending changes, Pi tells
57
57
  you to review, commit, or abort them.
58
58
 
@@ -122,6 +122,7 @@ or both. Project values are merged over user-wide values, including nested
122
122
  "durability": "fast",
123
123
  "groupCommitMs": null
124
124
  },
125
+ "exit": "abort",
125
126
  "review": {
126
127
  "mode": "task"
127
128
  }
@@ -144,7 +145,7 @@ provider supports it.
144
145
 
145
146
  The extension reports the requested mode, resolved mode, provider, visibility,
146
147
  durability, rollback guarantee, fallback reason, and taint state through
147
- `/sandbox-status`. Fallback and unsafe rollback conditions are also shown as Pi
148
+ `/deltabox-status`. Fallback and unsafe rollback conditions are also shown as Pi
148
149
  notifications.
149
150
 
150
151
  ### Review modes
@@ -167,13 +168,15 @@ reached.
167
168
 
168
169
  | Command | Description |
169
170
  |---|---|
170
- | `/sandbox-status` | Show session status and pending change count |
171
- | `/sandbox-review` | Show the pending diff |
172
- | `/sandbox-commit` | Apply pending changes to the real project |
173
- | `/sandbox-abort` | Discard changes back to the active review scope |
174
- | `/sandbox-skip` | Keep changes pending and preserve the current rollback point |
175
- | `/sandbox-diff [from] [to]` | Diff between checkpoints |
176
- | `/sandbox-mode task\|tool\|risky` | Switch review mode at runtime |
171
+ | `/deltabox-status` | Show session status, exit policy, and pending change count |
172
+ | `/deltabox-review` | Show the pending diff |
173
+ | `/deltabox-commit` | Apply pending changes to the real project |
174
+ | `/deltabox-abort` | Discard changes back to the active review scope |
175
+ | `/deltabox-sync` | Sync sibling commits and list stale paths or conflict copies in a private session |
176
+ | `/deltabox-skip` | Keep changes pending and preserve the current rollback point |
177
+ | `/deltabox-diff [from] [to]` | Diff between checkpoints |
178
+ | `/deltabox-mode [task\|tool\|risky]` | Show or switch review mode at runtime |
179
+ | `/deltabox-exit [abort\|commit]` | Show or set the session exit policy for uncommitted changes |
177
180
 
178
181
  ## How it works
179
182
 
@@ -185,11 +188,18 @@ reached.
185
188
  client rather than creating another backend session.
186
189
  3. `none`-isolation project reads and writes use the controlled mount directly; native
187
190
  Buffer methods handle fallback paths without JSON or Base64.
188
- 4. `/sandbox-commit` accepts the current view; `/sandbox-abort` restores the
191
+ 4. `/deltabox-commit` accepts the current view; `/deltabox-abort` restores the
189
192
  active review scope. In through mode, host visibility is immediate. In
190
193
  private modes, publication happens at commit.
191
194
  5. Set `"transport": "serve"` or `"cli"` only when native loading is not
192
195
  available. These transports preserve the durable on-disk protocol.
196
+ 6. If Pi is killed or crashes without stopping its session, the next start
197
+ **recovers** it instead of starting fresh: the session keeps its pending
198
+ changes and its open review, and a notice tells you to settle them with
199
+ `/deltabox-review`, then `/deltabox-commit` or `/deltabox-abort`. Nothing is
200
+ committed or reverted on your behalf. This needs a deltabox-lite addon with
201
+ session ownership (native transport). If a session start fails, the next
202
+ turn, tool call, or command retries it.
193
203
 
194
204
  ## Performance benchmark
195
205
 
package/dist/client.js CHANGED
@@ -79,6 +79,31 @@ export function sessionNotices(info) {
79
79
  }
80
80
  return notices;
81
81
  }
82
+ export function recoveryNotices(recovery, project) {
83
+ if (!recovery)
84
+ return [];
85
+ const notices = [];
86
+ const next = recovery.pendingChanges === 0
87
+ ? "It has no pending changes."
88
+ : recovery.reviewActive
89
+ ? `It has ${recovery.pendingChanges} pending change(s); use /deltabox-review, then /deltabox-commit or /deltabox-abort.`
90
+ : `It has ${recovery.pendingChanges} pending change(s); use /deltabox-diff to inspect them.`;
91
+ notices.push({
92
+ code: "recovered",
93
+ level: "warning",
94
+ message: `Deltabox recovered session ${recovery.sessionId}, left running by a previous run that ended without stopping it. ${next}`,
95
+ });
96
+ if (recovery.otherOrphans.length > 0) {
97
+ notices.push({
98
+ code: "orphans",
99
+ level: "warning",
100
+ message: `${recovery.otherOrphans.length} other orphaned deltabox session(s) remain: ` +
101
+ `${recovery.otherOrphans.join(", ")}. Stop one with ` +
102
+ `\`deltabox session stop <id> --project ${project}\`.`,
103
+ });
104
+ }
105
+ return notices;
106
+ }
82
107
  export class DeltaboxClient {
83
108
  project;
84
109
  proc = null;
@@ -87,6 +112,8 @@ export class DeltaboxClient {
87
112
  nextId = 1;
88
113
  sessionId = null;
89
114
  sessionInfo = null;
115
+ starting = null;
116
+ recovery = null;
90
117
  native = null;
91
118
  bin;
92
119
  transport;
@@ -306,14 +333,74 @@ export class DeltaboxClient {
306
333
  parse(output) {
307
334
  return JSON.parse(output.stdout.toString("utf8"));
308
335
  }
336
+ /**
337
+ * Starts the session, or returns it if already started. Concurrent callers
338
+ * share one attempt, and a failed attempt is not remembered: the next call
339
+ * tries again instead of repeating a stale error.
340
+ */
309
341
  async start() {
310
342
  if (this.sessionId && this.sessionInfo)
311
343
  return this.sessionInfo;
344
+ this.starting ??= this.startOnce().finally(() => {
345
+ this.starting = null;
346
+ });
347
+ return this.starting;
348
+ }
349
+ /** Notices about a session `start` adopted instead of starting fresh. */
350
+ recoveryNotices() {
351
+ return recoveryNotices(this.recovery, this.project);
352
+ }
353
+ /**
354
+ * Adopts the newest orphan matching this client's filesystem configuration,
355
+ * so a restarted host picks up where a killed one stopped. Returns null
356
+ * when there is none, or when the addon predates session ownership.
357
+ */
358
+ async adoptOrphan(native) {
359
+ if (!native.orphanedSessions || !native.adoptSession)
360
+ return null;
361
+ const durability = this.filesystem.durability === "strict" ? "strict" : "process-crash";
362
+ const orphans = await native.orphanedSessions();
363
+ const candidates = [];
364
+ for (const id of orphans) {
365
+ try {
366
+ const info = await native.sessionStatus(id);
367
+ if (info.requested_fs_mode === this.filesystem.mode && info.durability === durability) {
368
+ candidates.push(info);
369
+ }
370
+ }
371
+ catch {
372
+ // Unreadable orphans stay for the user to stop by hand.
373
+ }
374
+ }
375
+ candidates.sort((a, b) => b.started_at_ms - a.started_at_ms);
376
+ for (const candidate of candidates) {
377
+ let info;
378
+ try {
379
+ info = await native.adoptSession(candidate.session_id);
380
+ }
381
+ catch {
382
+ continue; // another host adopted it first
383
+ }
384
+ // A run killed mid-turn leaves its review open; keeping it lets the
385
+ // user settle the recovered work with the usual review commands.
386
+ const review = await native.reviewStatus(info.session_id).catch(() => null);
387
+ this.recovery = {
388
+ sessionId: info.session_id,
389
+ pendingChanges: info.pending_changes,
390
+ reviewActive: review !== null,
391
+ otherOrphans: orphans.filter((id) => id !== info.session_id),
392
+ };
393
+ return info;
394
+ }
395
+ return null;
396
+ }
397
+ async startOnce() {
312
398
  const mode = this.filesystem.mode === "auto" ? null : this.filesystem.mode;
313
399
  const policy = this.policy ? resolve(this.project, this.policy) : null;
314
400
  let info;
315
401
  if (this.transport === "native") {
316
- info = await this.nativeRequired().startSession(policy ?? undefined, this.filesystem.durability, this.filesystem.groupCommitMs ?? undefined);
402
+ const native = this.nativeRequired();
403
+ info = (await this.adoptOrphan(native)) ?? await native.startSession(policy ?? undefined, this.filesystem.durability, this.filesystem.groupCommitMs ?? undefined);
317
404
  }
318
405
  else if (this.transport === "serve") {
319
406
  const info = (await this.request("session.start", {
@@ -511,6 +598,21 @@ export class DeltaboxClient {
511
598
  args.push("--to", to);
512
599
  return this.parse(await this.cli(args));
513
600
  }
601
+ async sync() {
602
+ if (this.transport === "native") {
603
+ const native = this.nativeRequired();
604
+ if (!native.sync) {
605
+ throw new Error("Upgrade the Deltabox native addon to a build with session sync support.");
606
+ }
607
+ return native.sync(this.id());
608
+ }
609
+ if (this.transport === "serve") {
610
+ return (await this.request("session.sync", {
611
+ session_id: this.id(),
612
+ }));
613
+ }
614
+ return this.parse(await this.cli(["sync", this.id(), ...this.projectArgs()]));
615
+ }
514
616
  async commit(checkpoint) {
515
617
  if (this.transport === "native") {
516
618
  return this.nativeRequired().commit(this.id(), checkpoint);
package/dist/commands.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { renderDiff } from "./format.js";
2
- export function registerCommands(pi, getClient, getConfig, setMode) {
3
- pi.registerCommand("sandbox-status", {
2
+ export function registerCommands(pi,
3
+ /** Resolves the started client; `ctx` receives any start notices. */
4
+ getClient, getConfig, setMode, setExitPolicy = () => undefined) {
5
+ pi.registerCommand("deltabox-status", {
4
6
  description: "Show deltabox-lite session status and pending change count",
5
7
  handler: async (_args, ctx) => {
6
- const client = getClient();
8
+ const client = await getClient(ctx);
7
9
  try {
8
10
  const status = await client.status();
9
11
  ctx.ui.notify([
@@ -16,6 +18,7 @@ export function registerCommands(pi, getClient, getConfig, setMode) {
16
18
  `Visibility: ${status.host_visibility}`,
17
19
  `Durability: ${status.durability}`,
18
20
  `Rollback: ${status.rollback_guarantee}${status.tainted ? " (tainted)" : ""}`,
21
+ `Exit policy: ${getConfig().exit}`,
19
22
  ...(status.fallback_reason ? [`Fallback: ${status.fallback_reason}`] : []),
20
23
  ].join("\n"), "info");
21
24
  }
@@ -24,10 +27,10 @@ export function registerCommands(pi, getClient, getConfig, setMode) {
24
27
  }
25
28
  },
26
29
  });
27
- pi.registerCommand("sandbox-review", {
30
+ pi.registerCommand("deltabox-review", {
28
31
  description: "Show the pending diff",
29
32
  handler: async (_args, ctx) => {
30
- const client = getClient();
33
+ const client = await getClient(ctx);
31
34
  try {
32
35
  const diff = await client.reviewDiff();
33
36
  const text = renderDiff(diff);
@@ -38,10 +41,10 @@ export function registerCommands(pi, getClient, getConfig, setMode) {
38
41
  }
39
42
  },
40
43
  });
41
- pi.registerCommand("sandbox-commit", {
44
+ pi.registerCommand("deltabox-commit", {
42
45
  description: "Commit pending changes to the real project",
43
46
  handler: async (_args, ctx) => {
44
- const client = getClient();
47
+ const client = await getClient(ctx);
45
48
  try {
46
49
  const result = await client.reviewCommit();
47
50
  ctx.ui.notify(`Committed ${result.applied} change(s) (${result.checkpoint_id.slice(0, 8)})`, "info");
@@ -51,10 +54,10 @@ export function registerCommands(pi, getClient, getConfig, setMode) {
51
54
  }
52
55
  },
53
56
  });
54
- pi.registerCommand("sandbox-abort", {
57
+ pi.registerCommand("deltabox-abort", {
55
58
  description: "Abort pending changes back to the head checkpoint",
56
59
  handler: async (_args, ctx) => {
57
- const client = getClient();
60
+ const client = await getClient(ctx);
58
61
  try {
59
62
  const result = await client.reviewAbort();
60
63
  ctx.ui.notify(`Aborted, restored ${result.restored} change(s)`, "info");
@@ -64,11 +67,36 @@ export function registerCommands(pi, getClient, getConfig, setMode) {
64
67
  }
65
68
  },
66
69
  });
67
- pi.registerCommand("sandbox-skip", {
70
+ pi.registerCommand("deltabox-sync", {
71
+ description: "Sync sibling commits and list paths to reconcile in a private session",
72
+ handler: async (args, ctx) => {
73
+ if (String(args ?? "").trim()) {
74
+ ctx.ui.notify("usage: /deltabox-sync", "warning");
75
+ return;
76
+ }
77
+ try {
78
+ const client = await getClient(ctx);
79
+ const result = await client.sync();
80
+ ctx.ui.notify([
81
+ `Folded ${result.folded_publications} sibling publication(s).`,
82
+ ...result.stale_paths.map((path) => `Stale path: ${path}`),
83
+ ...result.conflicts.map((conflict) => `Conflict: ${conflict.path} (host: ${conflict.host_kind})` +
84
+ (conflict.theirs ? ` — compare with ${conflict.theirs}` : "")),
85
+ ...(result.conflicts.length
86
+ ? ["Resolve each conflict at its original path before running /deltabox-commit."]
87
+ : []),
88
+ ].join("\n"), "info");
89
+ }
90
+ catch (error) {
91
+ ctx.ui.notify(`deltabox error: ${String(error)}`, "error");
92
+ }
93
+ },
94
+ });
95
+ pi.registerCommand("deltabox-skip", {
68
96
  description: "Keep pending changes and preserve the current rollback point",
69
97
  handler: async (_args, ctx) => {
70
98
  try {
71
- const active = await getClient().reviewSkip();
99
+ const active = await (await getClient(ctx)).reviewSkip();
72
100
  ctx.ui.notify(`Kept changes pending from ${active.checkpoint_id.slice(0, 8)}`, "info");
73
101
  }
74
102
  catch (error) {
@@ -76,10 +104,10 @@ export function registerCommands(pi, getClient, getConfig, setMode) {
76
104
  }
77
105
  },
78
106
  });
79
- pi.registerCommand("sandbox-diff", {
107
+ pi.registerCommand("deltabox-diff", {
80
108
  description: "Show the diff between two checkpoints (or base and head)",
81
109
  handler: async (args, ctx) => {
82
- const client = getClient();
110
+ const client = await getClient(ctx);
83
111
  const parts = String(args ?? "")
84
112
  .trim()
85
113
  .split(/\s+/)
@@ -93,16 +121,37 @@ export function registerCommands(pi, getClient, getConfig, setMode) {
93
121
  }
94
122
  },
95
123
  });
96
- pi.registerCommand("sandbox-mode", {
97
- description: "Set review mode: task, tool, or risky",
124
+ pi.registerCommand("deltabox-mode", {
125
+ description: "Show or set review mode: task, tool, or risky",
98
126
  handler: async (args, ctx) => {
99
- const mode = String(args ?? "").trim();
127
+ const trimmed = String(args ?? "").trim();
128
+ if (!trimmed) {
129
+ ctx.ui.notify(`review mode: ${getConfig().review.mode}. usage: /deltabox-mode task|tool|risky`, "info");
130
+ return;
131
+ }
132
+ const mode = trimmed;
100
133
  if (mode !== "task" && mode !== "tool" && mode !== "risky") {
101
- ctx.ui.notify("usage: /sandbox-mode task|tool|risky", "warning");
134
+ ctx.ui.notify("usage: /deltabox-mode task|tool|risky", "warning");
102
135
  return;
103
136
  }
104
137
  setMode(mode);
105
138
  ctx.ui.notify(`review mode set to ${mode}`, "info");
106
139
  },
107
140
  });
141
+ pi.registerCommand("deltabox-exit", {
142
+ description: "Show or set session exit policy: abort|commit",
143
+ handler: async (args, ctx) => {
144
+ const trimmed = String(args ?? "").trim();
145
+ if (!trimmed) {
146
+ ctx.ui.notify(`Exit policy: ${getConfig().exit}. Usage: /deltabox-exit [abort|commit]`, "info");
147
+ return;
148
+ }
149
+ if (trimmed !== "abort" && trimmed !== "commit") {
150
+ ctx.ui.notify("Usage: /deltabox-exit [abort|commit]", "warning");
151
+ return;
152
+ }
153
+ setExitPolicy(trimmed);
154
+ ctx.ui.notify(`Exit policy set to ${trimmed}.`, "info");
155
+ },
156
+ });
108
157
  }
package/dist/config.js CHANGED
@@ -16,6 +16,7 @@ export const DEFAULT_CONFIG = {
16
16
  durability: "fast",
17
17
  groupCommitMs: null,
18
18
  },
19
+ exit: "abort",
19
20
  review: {
20
21
  mode: "task",
21
22
  },
@@ -80,6 +81,7 @@ export function mergeConfig(base, raw) {
80
81
  ? null
81
82
  : base.filesystem.groupCommitMs,
82
83
  },
84
+ exit: value.exit === "abort" || value.exit === "commit" ? value.exit : base.exit,
83
85
  review: {
84
86
  mode: review.mode === "task" || review.mode === "tool" || review.mode === "risky"
85
87
  ? review.mode
package/dist/extension.js CHANGED
@@ -20,13 +20,45 @@ export function registerExtension(pi, dependencies = defaultDependencies) {
20
20
  let client = null;
21
21
  let config = dependencies.loadConfig(dependencies.cwd());
22
22
  let mode = config.review.mode;
23
- const getConfig = () => ({ ...config, review: { ...config.review, mode } });
23
+ let exitPolicy = config.exit;
24
+ const getConfig = () => ({
25
+ ...config,
26
+ exit: exitPolicy,
27
+ review: { ...config.review, mode },
28
+ });
24
29
  const getClient = () => {
25
30
  if (!client) {
26
31
  client = dependencies.createClient(dependencies.cwd(), config);
27
32
  }
28
33
  return client;
29
34
  };
35
+ // The client whose start notices were shown; each client announces once.
36
+ let announced = null;
37
+ /**
38
+ * The started client. A failed start is not sticky: the client is dropped,
39
+ * and the next tool call, command, or turn builds a fresh one and retries.
40
+ */
41
+ const ensureClient = async (ctx) => {
42
+ const current = getClient();
43
+ let info;
44
+ try {
45
+ info = await current.start();
46
+ }
47
+ catch (error) {
48
+ if (client === current) {
49
+ current.dispose();
50
+ client = null;
51
+ }
52
+ throw error;
53
+ }
54
+ if (ctx?.ui && announced !== current) {
55
+ announced = current;
56
+ for (const notice of [...current.recoveryNotices(), ...sessionNotices(info)]) {
57
+ ctx.ui.notify(notice.message, notice.level);
58
+ }
59
+ }
60
+ return current;
61
+ };
30
62
  pi.on("tool_call", async (event) => {
31
63
  if (process.platform === "win32" && config.isolation === "deltabox" && event.toolName === "bash") {
32
64
  return { block: true, reason: "Git Bash is unavailable under Windows DeltaBox isolation. Use the powershell tool." };
@@ -35,21 +67,32 @@ export function registerExtension(pi, dependencies = defaultDependencies) {
35
67
  pi.on("session_start", async (_event, ctx) => {
36
68
  config = dependencies.loadConfig(dependencies.cwd());
37
69
  mode = config.review.mode;
70
+ exitPolicy = config.exit;
38
71
  try {
39
- const info = await getClient().start();
40
- for (const notice of sessionNotices(info)) {
41
- ctx.ui.notify(notice.message, notice.level);
42
- }
72
+ await ensureClient(ctx);
43
73
  }
44
74
  catch (error) {
45
- client?.dispose();
46
- client = null;
47
75
  ctx.ui.notify(`deltabox session start failed: ${String(error)}`, "error");
48
76
  }
49
77
  });
50
78
  pi.on("session_shutdown", async (_event, ctx) => {
51
79
  if (client) {
52
80
  try {
81
+ if (await client.reviewStatus()) {
82
+ if (exitPolicy === "commit") {
83
+ const result = await client.reviewCommit();
84
+ if (result.applied > 0) {
85
+ ctx.ui.notify(`Deltabox: committed ${result.applied} pending change(s) on exit.`, "info");
86
+ }
87
+ }
88
+ else {
89
+ const result = await client.reviewAbort();
90
+ if (result.restored > 0) {
91
+ ctx.ui.notify(`Deltabox: rolled back ${result.restored} uncommitted change(s) on exit. ` +
92
+ 'Run /deltabox-commit or /deltabox-exit commit before exiting, or set "exit": "commit" in deltabox.json to keep them.', "warning");
93
+ }
94
+ }
95
+ }
53
96
  await client.stop();
54
97
  }
55
98
  catch (error) {
@@ -61,10 +104,11 @@ export function registerExtension(pi, dependencies = defaultDependencies) {
61
104
  }
62
105
  });
63
106
  pi.on("before_agent_start", async (_event, ctx) => {
64
- if (!client || mode !== "task")
107
+ if (mode !== "task")
65
108
  return;
66
109
  try {
67
- await client.reviewBegin("task", "agent-turn");
110
+ // Also the retry point after a failed session start.
111
+ await (await ensureClient(ctx)).reviewBegin("task", "agent-turn");
68
112
  }
69
113
  catch (error) {
70
114
  ctx.ui.notify(`deltabox review start failed: ${String(error)}`, "error");
@@ -79,7 +123,7 @@ export function registerExtension(pi, dependencies = defaultDependencies) {
79
123
  const diff = await client.reviewDiff();
80
124
  if (diff.pending_changes > 0) {
81
125
  const note = `Task finished with ${diff.pending_changes} pending change(s). ` +
82
- "Use /sandbox-review, /sandbox-commit, or /sandbox-abort.";
126
+ "Use /deltabox-review, /deltabox-commit, or /deltabox-abort.";
83
127
  ctx.ui.notify(note, "info");
84
128
  }
85
129
  }
@@ -87,11 +131,13 @@ export function registerExtension(pi, dependencies = defaultDependencies) {
87
131
  ctx.ui.notify(`deltabox review failed: ${String(error)}`, "error");
88
132
  }
89
133
  });
90
- for (const tool of makeTools(getClient, getConfig)) {
134
+ for (const tool of makeTools(ensureClient, getConfig)) {
91
135
  pi.registerTool(tool);
92
136
  }
93
- registerCommands(pi, getClient, getConfig, (next) => {
137
+ registerCommands(pi, ensureClient, getConfig, (next) => {
94
138
  mode = next;
139
+ }, (next) => {
140
+ exitPolicy = next;
95
141
  });
96
142
  }
97
143
  export default registerExtension;
package/dist/tools.js CHANGED
@@ -77,7 +77,9 @@ async function afterMutation(client, config, ctx, source) {
77
77
  await reviewPending(client, (ctx.ui ?? {}), source);
78
78
  }
79
79
  }
80
- export function makeTools(getClient, getConfig) {
80
+ export function makeTools(
81
+ /** Resolves the started client; `ctx` receives any start notices. */
82
+ getClient, getConfig) {
81
83
  const readSchema = Type.Object({
82
84
  path: Type.String({ description: "Path to the file to read" }),
83
85
  offset: Type.Optional(Type.Number({ description: "1-indexed first line" })),
@@ -106,7 +108,7 @@ export function makeTools(getClient, getConfig) {
106
108
  parameters: readSchema,
107
109
  async execute(_id, params, _signal, _onUpdate, ctx) {
108
110
  const p = params;
109
- const client = getClient();
111
+ const client = await getClient(ctx);
110
112
  const absolute = toAbsolute(ctx, p.path);
111
113
  const bytes = await client.readFile(absolute);
112
114
  const text = bytes.toString("utf8");
@@ -125,7 +127,7 @@ export function makeTools(getClient, getConfig) {
125
127
  parameters: pathSchema,
126
128
  async execute(_id, params, _signal, _onUpdate, ctx) {
127
129
  const p = params;
128
- const client = getClient();
130
+ const client = await getClient(ctx);
129
131
  await beforeMutation(client, getConfig());
130
132
  await client.writeFile(toAbsolute(ctx, p.path), p.content);
131
133
  await afterMutation(client, getConfig(), ctx, "write");
@@ -139,7 +141,7 @@ export function makeTools(getClient, getConfig) {
139
141
  parameters: editSchema,
140
142
  async execute(_id, params, _signal, _onUpdate, ctx) {
141
143
  const p = params;
142
- const client = getClient();
144
+ const client = await getClient(ctx);
143
145
  const absolute = toAbsolute(ctx, p.path);
144
146
  await beforeMutation(client, getConfig());
145
147
  const content = (await client.readFile(absolute)).toString("utf8");
@@ -161,7 +163,7 @@ export function makeTools(getClient, getConfig) {
161
163
  parameters: bashSchema,
162
164
  async execute(_id, params, signal, _onUpdate, ctx) {
163
165
  const p = params;
164
- const client = getClient();
166
+ const client = await getClient(ctx);
165
167
  await beforeMutation(client, getConfig());
166
168
  const timeoutMs = p.timeout !== undefined && p.timeout > 0
167
169
  ? p.timeout * 1_000
@@ -192,7 +194,7 @@ export function makeTools(getClient, getConfig) {
192
194
  }),
193
195
  async execute(_id, params, _signal, _onUpdate, ctx) {
194
196
  const p = params;
195
- const client = getClient();
197
+ const client = await getClient(ctx);
196
198
  const target = toAbsolute(ctx, p.path ?? ".");
197
199
  const result = await client.exec(process.platform === "win32" ? powershellArgv(`Get-ChildItem -LiteralPath ${powershellQuote(powershellTarget(ctx.cwd, target))} -File -Recurse | Select-String -Pattern ${powershellQuote(p.pattern)} | ForEach-Object { '{0}:{1}:{2}' -f $_.Path, $_.LineNumber, $_.Line }`) : [
198
200
  bashExecutable(),
@@ -216,7 +218,7 @@ export function makeTools(getClient, getConfig) {
216
218
  }),
217
219
  async execute(_id, params, _signal, _onUpdate, ctx) {
218
220
  const p = params;
219
- const client = getClient();
221
+ const client = await getClient(ctx);
220
222
  const target = toAbsolute(ctx, p.path ?? ".");
221
223
  const pattern = p.pattern ?? "*";
222
224
  const result = await client.exec(process.platform === "win32" ? powershellArgv(`Get-ChildItem -LiteralPath ${powershellQuote(powershellTarget(ctx.cwd, target))} -Recurse -Force | Where-Object { $_.Name -like ${powershellQuote(pattern)} } | ForEach-Object { $_.FullName }`) : [
@@ -240,7 +242,7 @@ export function makeTools(getClient, getConfig) {
240
242
  }),
241
243
  async execute(_id, params, _signal, _onUpdate, ctx) {
242
244
  const p = params;
243
- const client = getClient();
245
+ const client = await getClient(ctx);
244
246
  const target = toAbsolute(ctx, p.path ?? ".");
245
247
  const result = await client.exec(process.platform === "win32"
246
248
  ? powershellArgv(`Get-ChildItem -LiteralPath ${powershellQuote(powershellTarget(ctx.cwd, target))} -Force | Format-Table Mode, Length, Name -AutoSize | Out-String -Width 240`)
@@ -263,7 +265,7 @@ export function makeTools(getClient, getConfig) {
263
265
  if (signal?.aborted)
264
266
  throw new Error("PowerShell command cancelled before execution");
265
267
  const p = params;
266
- const client = getClient();
268
+ const client = await getClient(ctx);
267
269
  const config = getConfig();
268
270
  const argv = powershellArgv(p.command);
269
271
  await beforeMutation(client, config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-deltabox",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Pi extension: agent-native sandbox sessions with diff/commit/abort, powered by deltabox-lite",
6
6
  "type": "module",
@@ -28,11 +28,11 @@
28
28
  "typebox": "^1.3.10"
29
29
  },
30
30
  "optionalDependencies": {
31
- "deltabox-lite-darwin-arm64": "0.2.0",
32
- "deltabox-lite-darwin-x64": "0.2.0",
33
- "deltabox-lite-linux-arm64": "0.2.0",
34
- "deltabox-lite-linux-x64": "0.2.0",
35
- "deltabox-lite-windows-x64": "0.2.0"
31
+ "deltabox-lite-darwin-arm64": "0.5.0",
32
+ "deltabox-lite-darwin-x64": "0.5.0",
33
+ "deltabox-lite-linux-arm64": "0.5.0",
34
+ "deltabox-lite-linux-x64": "0.5.0",
35
+ "deltabox-lite-windows-x64": "0.5.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@earendil-works/pi-coding-agent": "^0.79.3",