pi-deltabox 0.1.1 → 0.1.3
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 +37 -4
- package/dist/client.js +9 -4
- package/dist/extension.js +5 -0
- package/dist/powershell.js +21 -0
- package/dist/tools.js +81 -10
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Every filesystem change remains reviewable, committable, and abortable.
|
|
|
8
8
|
|
|
9
9
|
[](#license)
|
|
10
10
|
[](https://github.com/earendil-works/pi)
|
|
11
|
-
[](#)
|
|
11
|
+
[](#)
|
|
12
12
|
[](https://github.com/Ddnirvana/deltabox-lite)
|
|
13
13
|
|
|
14
14
|
</div>
|
|
@@ -17,8 +17,12 @@ pi-deltabox is a [Pi](https://github.com/earendil-works/pi) extension that
|
|
|
17
17
|
embeds a durable deltabox-lite session directly in the Pi Node process. `read`,
|
|
18
18
|
`write`, `edit`, `bash`, `grep`, `find`, and `ls` execute inside the selected
|
|
19
19
|
confined filesystem mode. The default `none` native path keeps coordinator
|
|
20
|
-
state
|
|
21
|
-
|
|
20
|
+
state hot, shares Pi's process environment, and uses the live mount directly
|
|
21
|
+
for low-latency byte I/O. Linux and macOS also reuse an isolated Bash worker.
|
|
22
|
+
|
|
23
|
+
## News
|
|
24
|
+
|
|
25
|
+
- **2026-10-21 — v0.1.3:** Windows x64 runtime installation, PowerShell tools for MXC-isolated sessions, and WinFsp write/diff/commit/abort fixes. Windows search/list tools use PowerShell; Linux/macOS retain Bash. Isolation remains opt-in (`deltabox`); the default is `none`.
|
|
22
26
|
|
|
23
27
|
## Demo
|
|
24
28
|
|
|
@@ -57,7 +61,9 @@ pi install npm:pi-deltabox # once published
|
|
|
57
61
|
pi install ./pi-deltabox # from a checkout
|
|
58
62
|
```
|
|
59
63
|
|
|
60
|
-
The npm package selects a native prebuild for Linux and macOS on x64 and arm64
|
|
64
|
+
The npm package selects a native prebuild for Linux and macOS on x64 and arm64,
|
|
65
|
+
or Windows on x64. Windows CB-CoW requires WinFsp. Pi uses Git Bash by default
|
|
66
|
+
for its Bash tool on Windows.
|
|
61
67
|
For a source checkout, build [deltabox-lite](https://github.com/Ddnirvana/deltabox-lite),
|
|
62
68
|
copy the addon to a `.node` path, and point the extension at both artifacts:
|
|
63
69
|
|
|
@@ -68,6 +74,33 @@ cp target/release/libdeltabox_node.dylib /tmp/deltabox.node # macOS
|
|
|
68
74
|
|
|
69
75
|
## Configure
|
|
70
76
|
|
|
77
|
+
### Windows PowerShell execution
|
|
78
|
+
|
|
79
|
+
On Windows the extension also overrides Pi's `powershell` tool. It runs through
|
|
80
|
+
the same DeltaBox session and review lifecycle as file writes. Windows `grep`,
|
|
81
|
+
`find`, and `ls` use PowerShell too (search patterns use .NET regular expressions
|
|
82
|
+
and PowerShell wildcard matching). PowerShell 7 on PATH is preferred, with
|
|
83
|
+
Windows PowerShell as fallback. Add the selected PowerShell installation to the
|
|
84
|
+
policy's filesystem read grants when using `isolation: "deltabox"`.
|
|
85
|
+
|
|
86
|
+
For Pi versions exposing the PowerShell tool, select it in `~/.pi/agent/settings.json`:
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{ "defaultTools": ["read", "powershell", "edit", "write"] }
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Set `"isolation": "deltabox"` and the desired `policy` path in `deltabox.json`
|
|
93
|
+
to enable MXC execution isolation. Use relative project paths in commands;
|
|
94
|
+
the command starts in the WinFsp view, while direct backing-project access is
|
|
95
|
+
denied. Git Bash is not a fallback when isolated PowerShell fails. The documented
|
|
96
|
+
Windows setup uses `allow_audit`; restricted networking requires an explicit
|
|
97
|
+
runtime policy, and this extension does not expose per-command network approval UI. Commands retain the native
|
|
98
|
+
runtime's deadline; cancellation is checked before execution, not during it.
|
|
99
|
+
|
|
100
|
+
After building, run `node tests/windows-powershell-real.mjs` with
|
|
101
|
+
`DELTABOX_BINARY` and `DELTABOX_NATIVE_ADDON` pointing to matching Windows builds
|
|
102
|
+
to verify the actual tools, review transactions, and filesystem denials.
|
|
103
|
+
|
|
71
104
|
Create `deltabox.json` in the project, in `~/.pi/agent` for user-wide defaults,
|
|
72
105
|
or both. Project values are merged over user-wide values, including nested
|
|
73
106
|
`review` settings:
|
package/dist/client.js
CHANGED
|
@@ -2,10 +2,11 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { realpathSync } from "node:fs";
|
|
3
3
|
import { mkdir, readFile as readFileBytes, writeFile as writeFileBytes, } from "node:fs/promises";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
|
-
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
|
+
import { dirname, isAbsolute, join, parse, relative, resolve, sep } from "node:path";
|
|
6
6
|
import { createInterface } from "node:readline";
|
|
7
7
|
const require = createRequire(import.meta.url);
|
|
8
8
|
const prebuildPackages = {
|
|
9
|
+
"win32-x64": "deltabox-lite-windows-x64",
|
|
9
10
|
"darwin-arm64": "deltabox-lite-darwin-arm64",
|
|
10
11
|
"darwin-x64": "deltabox-lite-darwin-x64",
|
|
11
12
|
"linux-arm64": "deltabox-lite-linux-arm64",
|
|
@@ -26,7 +27,7 @@ function bundledPackageRoot() {
|
|
|
26
27
|
}
|
|
27
28
|
function bundledBin() {
|
|
28
29
|
const root = bundledPackageRoot();
|
|
29
|
-
return root ? join(root, "bin", "deltabox") : null;
|
|
30
|
+
return root ? join(root, "bin", process.platform === "win32" ? "deltabox.exe" : "deltabox") : null;
|
|
30
31
|
}
|
|
31
32
|
function loadNativeBinding(project, nativeAddon) {
|
|
32
33
|
const packageRoot = bundledPackageRoot();
|
|
@@ -385,9 +386,13 @@ export class DeltaboxClient {
|
|
|
385
386
|
if (bytes.byteLength > this.directMountMaxWriteBytes) {
|
|
386
387
|
throw new Error(`native direct write exceeds ${this.directMountMaxWriteBytes} bytes`);
|
|
387
388
|
}
|
|
388
|
-
|
|
389
|
+
const parent = dirname(direct);
|
|
390
|
+
// Node rejects mkdir on a Windows drive root, including WinFsp mounts.
|
|
391
|
+
if (process.platform !== "win32" || parent !== parse(parent).root) {
|
|
392
|
+
await mkdir(parent, { recursive: true });
|
|
393
|
+
}
|
|
389
394
|
await writeFileBytes(direct, bytes);
|
|
390
|
-
await native.recordFileChanges(this.id(), [path]);
|
|
395
|
+
await native.recordFileChanges(this.id(), [process.platform === "win32" ? direct : path]);
|
|
391
396
|
}
|
|
392
397
|
else {
|
|
393
398
|
await native.writeFile(this.id(), path, bytes);
|
package/dist/extension.js
CHANGED
|
@@ -27,6 +27,11 @@ export function registerExtension(pi, dependencies = defaultDependencies) {
|
|
|
27
27
|
}
|
|
28
28
|
return client;
|
|
29
29
|
};
|
|
30
|
+
pi.on("tool_call", async (event) => {
|
|
31
|
+
if (process.platform === "win32" && config.isolation === "deltabox" && event.toolName === "bash") {
|
|
32
|
+
return { block: true, reason: "Git Bash is unavailable under Windows DeltaBox isolation. Use the powershell tool." };
|
|
33
|
+
}
|
|
34
|
+
});
|
|
30
35
|
pi.on("session_start", async (_event, ctx) => {
|
|
31
36
|
config = dependencies.loadConfig(dependencies.cwd());
|
|
32
37
|
mode = config.review.mode;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { delimiter, join } from "node:path";
|
|
3
|
+
export function powershellQuote(value) {
|
|
4
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
5
|
+
}
|
|
6
|
+
export function powershellArgv(command) {
|
|
7
|
+
const paths = (process.env.PATH ?? "").split(delimiter).filter(Boolean);
|
|
8
|
+
const shell = ["pwsh.exe", "powershell.exe"]
|
|
9
|
+
.flatMap(name => paths.map(dir => join(dir, name)))
|
|
10
|
+
.find(path => existsSync(path));
|
|
11
|
+
if (!shell)
|
|
12
|
+
throw new Error("PowerShell is unavailable: add pwsh.exe or powershell.exe to PATH.");
|
|
13
|
+
const preamble = "$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue'; "
|
|
14
|
+
+ "[Console]::OutputEncoding=[Text.UTF8Encoding]::new($false); $OutputEncoding=[Console]::OutputEncoding; "
|
|
15
|
+
+ "Set-Location -LiteralPath ([Environment]::CurrentDirectory); ";
|
|
16
|
+
return [shell, "-NoLogo", "-NoProfile", "-NonInteractive", "-InputFormat", "Text",
|
|
17
|
+
"-OutputFormat", "Text", "-EncodedCommand", Buffer.from(preamble + command, "utf16le").toString("base64")];
|
|
18
|
+
}
|
|
19
|
+
export function normalizePowerShellResult(result) {
|
|
20
|
+
return { ...result, stderr: result.stderr.replace(/^Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failed\.\r?\n/, "") };
|
|
21
|
+
}
|
package/dist/tools.js
CHANGED
|
@@ -1,12 +1,46 @@
|
|
|
1
|
-
import { resolve, isAbsolute } from "node:path";
|
|
1
|
+
import { resolve, isAbsolute, join, relative, sep } from "node:path";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
+
import { getShellConfig } from "@earendil-works/pi-coding-agent";
|
|
3
4
|
import { reviewPending } from "./review.js";
|
|
5
|
+
import { powershellArgv, powershellQuote, normalizePowerShellResult } from "./powershell.js";
|
|
4
6
|
function shellQuote(value) {
|
|
5
7
|
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
6
8
|
}
|
|
9
|
+
function bashExecutable() {
|
|
10
|
+
if (process.platform !== "win32")
|
|
11
|
+
return "bash";
|
|
12
|
+
const config = getShellConfig();
|
|
13
|
+
if (config.commandTransport === "stdin") {
|
|
14
|
+
throw new Error("Pi's legacy WSL Bash requires stdin command transport, which deltabox does not support");
|
|
15
|
+
}
|
|
16
|
+
return config.shell;
|
|
17
|
+
}
|
|
18
|
+
function bashPath(path) {
|
|
19
|
+
if (process.platform !== "win32")
|
|
20
|
+
return path;
|
|
21
|
+
const match = /^([a-z]):[\\/](.*)$/i.exec(path);
|
|
22
|
+
return match ? `/${match[1].toLowerCase()}/${match[2].replaceAll("\\", "/")}` : path;
|
|
23
|
+
}
|
|
24
|
+
async function shellTarget(client, target) {
|
|
25
|
+
if (process.platform !== "win32")
|
|
26
|
+
return target;
|
|
27
|
+
const session = await client.status();
|
|
28
|
+
if (!session.mountpoint)
|
|
29
|
+
return target;
|
|
30
|
+
const suffix = relative(session.project, target);
|
|
31
|
+
if (suffix === ".." || suffix.startsWith(`..${sep}`) || isAbsolute(suffix))
|
|
32
|
+
return target;
|
|
33
|
+
return join(session.mountpoint, suffix);
|
|
34
|
+
}
|
|
7
35
|
function toAbsolute(ctx, path) {
|
|
8
36
|
return isAbsolute(path) ? path : resolve(ctx.cwd, path);
|
|
9
37
|
}
|
|
38
|
+
function powershellTarget(cwd, target) {
|
|
39
|
+
const suffix = relative(cwd, target);
|
|
40
|
+
// Commands start in the session view; keep project paths relative to it.
|
|
41
|
+
return suffix === ".." || suffix.startsWith(`..${sep}`) || isAbsolute(suffix)
|
|
42
|
+
? target : suffix || ".";
|
|
43
|
+
}
|
|
10
44
|
function textResult(text) {
|
|
11
45
|
return {
|
|
12
46
|
content: [{ type: "text", text }],
|
|
@@ -64,7 +98,7 @@ export function makeTools(getClient, getConfig) {
|
|
|
64
98
|
new_string: Type.String({ description: "Replacement text" }),
|
|
65
99
|
replace_all: Type.Optional(Type.Boolean()),
|
|
66
100
|
});
|
|
67
|
-
|
|
101
|
+
const tools = [
|
|
68
102
|
{
|
|
69
103
|
name: "read",
|
|
70
104
|
label: "read (deltabox)",
|
|
@@ -134,7 +168,7 @@ export function makeTools(getClient, getConfig) {
|
|
|
134
168
|
: undefined;
|
|
135
169
|
let result;
|
|
136
170
|
try {
|
|
137
|
-
result = await client.exec([
|
|
171
|
+
result = await client.exec([bashExecutable(), "-c", p.command], {
|
|
138
172
|
label: "bash",
|
|
139
173
|
timeoutMs,
|
|
140
174
|
});
|
|
@@ -159,11 +193,13 @@ export function makeTools(getClient, getConfig) {
|
|
|
159
193
|
const p = params;
|
|
160
194
|
const client = getClient();
|
|
161
195
|
const target = toAbsolute(ctx, p.path ?? ".");
|
|
162
|
-
const result = await client.exec([
|
|
163
|
-
|
|
196
|
+
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 }`) : [
|
|
197
|
+
bashExecutable(),
|
|
164
198
|
"-c",
|
|
165
|
-
`grep -n -E ${shellQuote(p.pattern)} ${shellQuote(target)}`,
|
|
199
|
+
`grep -n -E ${shellQuote(p.pattern)} ${shellQuote(bashPath(await shellTarget(client, target)))}`,
|
|
166
200
|
]);
|
|
201
|
+
if (process.platform === "win32" && result.exit_code !== 0)
|
|
202
|
+
return execResult(normalizePowerShellResult(result));
|
|
167
203
|
if (result.exit_code !== 0)
|
|
168
204
|
return textResult("");
|
|
169
205
|
return textResult(result.stdout);
|
|
@@ -182,11 +218,13 @@ export function makeTools(getClient, getConfig) {
|
|
|
182
218
|
const client = getClient();
|
|
183
219
|
const target = toAbsolute(ctx, p.path ?? ".");
|
|
184
220
|
const pattern = p.pattern ?? "*";
|
|
185
|
-
const result = await client.exec([
|
|
186
|
-
|
|
221
|
+
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 }`) : [
|
|
222
|
+
bashExecutable(),
|
|
187
223
|
"-c",
|
|
188
|
-
`find ${shellQuote(target)} -name ${shellQuote(pattern)}`,
|
|
224
|
+
`find ${shellQuote(bashPath(await shellTarget(client, target)))} -name ${shellQuote(pattern)}`,
|
|
189
225
|
]);
|
|
226
|
+
if (process.platform === "win32" && result.exit_code !== 0)
|
|
227
|
+
return execResult(normalizePowerShellResult(result));
|
|
190
228
|
if (result.exit_code !== 0)
|
|
191
229
|
return textResult("");
|
|
192
230
|
return textResult(result.stdout);
|
|
@@ -203,11 +241,44 @@ export function makeTools(getClient, getConfig) {
|
|
|
203
241
|
const p = params;
|
|
204
242
|
const client = getClient();
|
|
205
243
|
const target = toAbsolute(ctx, p.path ?? ".");
|
|
206
|
-
const result = await client.exec(
|
|
244
|
+
const result = await client.exec(process.platform === "win32"
|
|
245
|
+
? powershellArgv(`Get-ChildItem -LiteralPath ${powershellQuote(powershellTarget(ctx.cwd, target))} -Force | Format-Table Mode, Length, Name -AutoSize | Out-String -Width 240`)
|
|
246
|
+
: [bashExecutable(), "-c", `ls -la ${shellQuote(bashPath(await shellTarget(client, target)))}`]);
|
|
247
|
+
if (process.platform === "win32" && result.exit_code !== 0)
|
|
248
|
+
return execResult(normalizePowerShellResult(result));
|
|
207
249
|
if (result.exit_code !== 0)
|
|
208
250
|
return textResult("");
|
|
209
251
|
return textResult(result.stdout);
|
|
210
252
|
},
|
|
211
253
|
},
|
|
212
254
|
];
|
|
255
|
+
if (process.platform === "win32") {
|
|
256
|
+
tools.push({
|
|
257
|
+
name: "powershell",
|
|
258
|
+
label: "powershell (deltabox)",
|
|
259
|
+
description: "Run PowerShell in the DeltaBox workspace. Use PowerShell syntax and relative project paths. Changes support review, commit and abort.",
|
|
260
|
+
parameters: bashSchema,
|
|
261
|
+
async execute(_id, params, signal, _onUpdate, ctx) {
|
|
262
|
+
if (signal?.aborted)
|
|
263
|
+
throw new Error("PowerShell command cancelled before execution");
|
|
264
|
+
const p = params;
|
|
265
|
+
const client = getClient();
|
|
266
|
+
const config = getConfig();
|
|
267
|
+
const argv = powershellArgv(p.command);
|
|
268
|
+
await beforeMutation(client, config);
|
|
269
|
+
try {
|
|
270
|
+
return execResult(normalizePowerShellResult(await client.exec(argv, {
|
|
271
|
+
label: "powershell",
|
|
272
|
+
timeoutMs: p.timeout !== undefined && p.timeout > 0 ? p.timeout * 1_000 : undefined,
|
|
273
|
+
})));
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
await afterMutation(client, config, ctx, "powershell");
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
// Do not auto-enable the incompatible Git Bash override in MXC sessions.
|
|
282
|
+
return process.platform === "win32" && getConfig().isolation === "deltabox"
|
|
283
|
+
? tools.filter(tool => tool.name !== "bash") : tools;
|
|
213
284
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-deltabox",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc -p tsconfig.json",
|
|
18
|
-
"test": "npm run build && tsc -p tsconfig.tests.json && node --test dist-test/tests/client.test.js dist-test/tests/commands.test.js dist-test/tests/config.test.js dist-test/tests/extension.test.js dist-test/tests/tools.test.js",
|
|
18
|
+
"test": "npm run build && tsc -p tsconfig.tests.json && node --test dist-test/tests/client.test.js dist-test/tests/commands.test.js dist-test/tests/config.test.js dist-test/tests/extension.test.js dist-test/tests/tools.test.js tests/powershell.test.mjs",
|
|
19
19
|
"bench:native": "npm run build && node perf/native-fastpath-bench.mjs"
|
|
20
20
|
},
|
|
21
21
|
"keywords": [
|
|
@@ -28,10 +28,11 @@
|
|
|
28
28
|
"typebox": "^1.3.10"
|
|
29
29
|
},
|
|
30
30
|
"optionalDependencies": {
|
|
31
|
-
"deltabox-lite-darwin-arm64": "0.1.
|
|
32
|
-
"deltabox-lite-darwin-x64": "0.1.
|
|
33
|
-
"deltabox-lite-linux-arm64": "0.1.
|
|
34
|
-
"deltabox-lite-linux-x64": "0.1.
|
|
31
|
+
"deltabox-lite-darwin-arm64": "0.1.4",
|
|
32
|
+
"deltabox-lite-darwin-x64": "0.1.4",
|
|
33
|
+
"deltabox-lite-linux-arm64": "0.1.4",
|
|
34
|
+
"deltabox-lite-linux-x64": "0.1.4",
|
|
35
|
+
"deltabox-lite-windows-x64": "0.1.4"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@earendil-works/pi-coding-agent": "^0.79.3",
|