pi-better-background-tasks 0.2.6 → 0.2.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
@@ -27,8 +27,10 @@ the effective foreground policy at launch and runs under the platform's write
27
27
  sandbox: reads and network stay unrestricted, writes are confined to the
28
28
  canonical project directory, and denied paths stay denied.
29
29
 
30
- The policy is captured once, when the task starts. A later `/sandbox on`,
31
- `/sandbox off`, or deny-rule change reaches tasks launched after it; a task
30
+ The policy is captured once, when the task starts. The foreground sandbox is
31
+ inactive by default, so local tasks ordinarily launch unconfined. A later
32
+ `/sandbox on`, `/sandbox off`, `/sandbox default on|off`, or a deny-rule change
33
+ reaches tasks launched after it; a task
32
34
  already running — including a watcher resumed in a later Pi session — keeps the
33
35
  policy it started with.
34
36
 
@@ -45,8 +47,8 @@ process, `pi.exec` calls, and unrelated third-party extension code stay outside
45
47
  the guarantee, and confinement is per surface: a confined process on another
46
48
  first-party surface can still write this one's task registry. Installing
47
49
  [`pi-better-harness`](https://github.com/1aboveio/pi-better-harness/tree/main/packages/pi-better-harness#readme)
48
- brings the sandbox in by default, so an ordinary `pi` session confines its
49
- foreground tools and its local background tasks under one project policy.
50
+ installs the sandbox extension, but leaves foreground tools and local background
51
+ tasks inactive until a human opts in.
50
52
 
51
53
  ## Remote SSH
52
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-background-tasks",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "Pi extension for durable background shell tasks, watchers, logs, and status inspection.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/sandbox.ts CHANGED
@@ -12,10 +12,10 @@
12
12
  * argv are resolved once, when the task starts, and are what the task keeps
13
13
  * running. A later `/sandbox off` or deny-rule change therefore reaches only
14
14
  * tasks launched after it.
15
- * 2. **Fail closed.** Once the foreground state says a sandbox should apply, a
16
- * missing or unusable backend blocks the launch. The local command is never
17
- * retried unconfined behind the operator's back. The single exception is an
18
- * explicitly `disabled` state, which is a human's deliberate decision.
15
+ * 2. **Opt-in, then fail closed.** `inactive` and explicitly `disabled` states
16
+ * launch unconfined. Once foreground policy says confinement applies, a
17
+ * missing or unusable backend blocks the launch and is never retried
18
+ * unconfined behind the operator's back.
19
19
  *
20
20
  * The contract is duplicated here rather than imported: `pi-better-sandbox` is
21
21
  * an optional peer that this package must keep working without. Two channel
@@ -53,12 +53,13 @@ export const FOREGROUND_SANDBOX_POLICY_REQUEST_CHANNEL = "pi-better-sandbox:poli
53
53
  /**
54
54
  * What the foreground sandbox is doing right now.
55
55
  *
56
+ * - `inactive` - default-off foreground policy; launch tasks as before.
56
57
  * - `enabled` - confine locally launched tasks.
57
58
  * - `disabled` - a human switched protection off; launch tasks as before.
58
59
  * - `unavailable` - no backend on this platform; block protected launches.
59
60
  * - `failed` - protection cannot be applied here; block protected launches.
60
61
  */
61
- export type ForegroundSandboxState = "enabled" | "disabled" | "unavailable" | "failed";
62
+ export type ForegroundSandboxState = "inactive" | "enabled" | "disabled" | "unavailable" | "failed";
62
63
 
63
64
  /** The published snapshot, narrowed to the fields a task launch needs. */
64
65
  export interface ForegroundSandboxPolicy {
@@ -101,7 +102,7 @@ export type ForegroundSandboxPlan =
101
102
 
102
103
  const UNCONFINED: ForegroundSandboxPlan = { confined: false };
103
104
 
104
- const VALID_STATES = new Set<string>(["enabled", "disabled", "unavailable", "failed"]);
105
+ const VALID_STATES = new Set<string>(["inactive", "enabled", "disabled", "unavailable", "failed"]);
105
106
 
106
107
  /**
107
108
  * The latest snapshot per event bus.
@@ -183,8 +184,8 @@ export function currentForegroundSandboxPolicy(pi: unknown): ForegroundSandboxPo
183
184
  * Decide how a local launch must be confined, before the task has an id, a
184
185
  * directory, or a log.
185
186
  *
186
- * Throws for every state that is neither confinable nor a human's explicit
187
- * opt-out, which is what keeps a blocked launch from leaving task state behind.
187
+ * Throws for every state that is neither confinable nor intentionally
188
+ * unconfined, which keeps a blocked launch from leaving task state behind.
188
189
  */
189
190
  export function resolveForegroundSandboxPlan(pi: unknown): ForegroundSandboxPlan {
190
191
  return planFor(currentForegroundSandboxPolicy(pi));
@@ -195,7 +196,7 @@ export function planFor(policy: ForegroundSandboxPolicy | undefined): Foreground
195
196
  // No sandbox extension is publishing: this package is installed on its own and
196
197
  // keeps its historical unsandboxed behaviour.
197
198
  if (!policy) return UNCONFINED;
198
- if (policy.state === "disabled") return UNCONFINED;
199
+ if (policy.state === "inactive" || policy.state === "disabled") return UNCONFINED;
199
200
  if (policy.state !== "enabled" || !policy.writableRoot) {
200
201
  throw new ForegroundSandboxBlockedError(policy);
201
202
  }