@trim21/personal-pi-extensions 0.0.185 → 0.0.186

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/bwrap/index.ts +18 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.0.185",
3
+ "version": "0.0.186",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
@@ -11,11 +11,12 @@
11
11
  *
12
12
  * ## Modes
13
13
  *
14
- * Three modes, switchable at runtime:
14
+ * Four modes, switchable at runtime:
15
15
  *
16
16
  * allow-all No sandbox. Network allowed. All commands run natively.
17
17
  * workspace-write Sandbox enabled, network blocked. Project dir + /tmp writable.
18
18
  * Model can request full access via bash tool parameter.
19
+ * allow-net Sandbox enabled, network allowed. Project dir + /tmp writable.
19
20
  * readonly Sandbox enabled, network blocked, no writable paths.
20
21
  *
21
22
  * ## Escalation
@@ -45,6 +46,7 @@
45
46
  * /bwrap Show current mode and paths
46
47
  * /bwrap-allow-all Full access, sandbox off
47
48
  * /bwrap-workspace-write Sandbox on, workspace writable
49
+ * /bwrap-allow-net Sandbox on, network on, workspace writable
48
50
  * /bwrap-readonly Sandbox on, no writes
49
51
  *
50
52
  * Usage:
@@ -73,8 +75,9 @@ Three sandbox modes exist:
73
75
  - allow-all: sandbox off, network on, full access
74
76
  - readonly: sandbox on, network off, nothing writable
75
77
  - workspace-write: sandbox on, network off, only workspace and /tmp writable
78
+ - allow-net: sandbox on, network on, only workspace and /tmp writable
76
79
 
77
- In workspace-write and readonly modes, the bash tool has a
80
+ In workspace-write, allow-net and readonly modes, the bash tool has a
78
81
  \`request_full_access\` boolean parameter.
79
82
  Set it to true to request execution outside the sandbox.
80
83
  The user must approve.
@@ -92,7 +95,8 @@ require request_full_access: true.
92
95
 
93
96
  the \`request_full_access\` is only needed for:
94
97
  - Writing to paths outside the configured writable directories,
95
- - Operations requiring network access (curl, npm install, git push, etc.).
98
+ - Operations requiring network access when the current mode blocks it
99
+ (workspace-write or readonly; allow-all and allow-net already have network).
96
100
  Writing inside the workspace or /tmp, or reading any file, does not require escalation,
97
101
  for example, the simple \`ls\`, \`cat\`, \`find\` or \`grep\` and git command that only read from .git directory but not change .git directory and other read only commands.
98
102
  **If the command is readonly operator, do not use \`request_full_access\`**
@@ -146,7 +150,7 @@ function findBwrap(override?: string): string {
146
150
  return override ?? bwrapPath;
147
151
  }
148
152
 
149
- type BwrapMode = "allow-all" | "workspace-write" | "readonly";
153
+ type BwrapMode = "allow-all" | "workspace-write" | "allow-net" | "readonly";
150
154
 
151
155
  export interface BwrapConfig {
152
156
  mode: BwrapMode;
@@ -168,7 +172,7 @@ export interface ResolvedBwrap {
168
172
  extraArgs: string[];
169
173
  }
170
174
 
171
- function resolveBwrap(config: BwrapConfig): ResolvedBwrap {
175
+ export function resolveBwrap(config: BwrapConfig): ResolvedBwrap {
172
176
  const base = {
173
177
  mode: config.mode,
174
178
  bwrapPath: config.bwrapPath,
@@ -184,6 +188,9 @@ function resolveBwrap(config: BwrapConfig): ResolvedBwrap {
184
188
  case "workspace-write": {
185
189
  return { ...base, bwrapEnabled: true, network: false };
186
190
  }
191
+ case "allow-net": {
192
+ return { ...base, bwrapEnabled: true, network: true };
193
+ }
187
194
  case "readonly": {
188
195
  return { ...base, bwrapEnabled: true, network: false, writablePaths: [] };
189
196
  }
@@ -508,6 +515,7 @@ function notifyMode(
508
515
  const labels: Record<BwrapMode, string> = {
509
516
  "allow-all": "allow-all: sandbox off, network on",
510
517
  "workspace-write": "workspace-write: sandbox on, network off",
518
+ "allow-net": "allow-net: sandbox on, network on, workspace writable",
511
519
  readonly: "readonly: sandbox on, network off, read-only fs",
512
520
  };
513
521
  ctx.ui.notify(labels[mode], "info");
@@ -768,6 +776,11 @@ export default function bwrapExtension(pi: ExtensionAPI) {
768
776
  handler: (_args, ctx) => Promise.resolve(switchMode("workspace-write", ctx)),
769
777
  });
770
778
 
779
+ pi.registerCommand("bwrap-allow-net", {
780
+ description: "Sandbox on, network on, workspace writable",
781
+ handler: (_args, ctx) => Promise.resolve(switchMode("allow-net", ctx)),
782
+ });
783
+
771
784
  pi.registerCommand("bwrap-readonly", {
772
785
  description: "Sandbox on, network off, no writes",
773
786
  handler: (_args, ctx) => Promise.resolve(switchMode("readonly", ctx)),