auto-permission-system 3.18.0 → 3.20.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.
Files changed (50) hide show
  1. package/extensions/guard.ts +210 -364
  2. package/extensions/permission-mode.ts +112 -73
  3. package/extensions/sandbox.ts +228 -138
  4. package/package.json +1 -1
  5. package/skills/auto-permission-system/SKILL.md +1 -1
  6. package/src/core/grep-filter.ts +33 -32
  7. package/src/core/index.ts +16 -20
  8. package/src/core/policy/classify.ts +27 -20
  9. package/src/core/policy/commands.ts +47 -30
  10. package/src/core/policy/fence.ts +101 -80
  11. package/src/core/policy/overrides.ts +31 -35
  12. package/src/core/policy/patterns.ts +39 -0
  13. package/src/core/policy/policy-file.ts +20 -36
  14. package/src/core/trust.ts +217 -142
  15. package/src/core/user-named.ts +88 -63
  16. package/src/detect/filename-gate/classify.ts +2 -2
  17. package/src/detect/filename-gate/index.ts +4 -4
  18. package/src/detect/index.ts +4 -4
  19. package/src/detect/mcp-gate/evaluate.ts +4 -4
  20. package/src/detect/mcp-gate/index.ts +3 -3
  21. package/src/detect/mcp-gate/signals.ts +3 -3
  22. package/src/detect/mcp-gate/verbs.ts +1 -1
  23. package/src/detect/sensitive-file-scanner/assignment.ts +2 -2
  24. package/src/detect/sensitive-file-scanner/content-scan.ts +10 -10
  25. package/src/detect/sensitive-file-scanner/file-scan.ts +8 -8
  26. package/src/detect/sensitive-file-scanner/index.ts +7 -7
  27. package/src/detect/sensitive-file-scanner/patterns.ts +1 -1
  28. package/src/detect/sensitive-file-scanner/redaction.ts +6 -6
  29. package/src/detect/sensitive-file-scanner/scoring.ts +3 -3
  30. package/src/detect/sensitive-file-scanner/value-analysis.ts +3 -3
  31. package/src/detect/tool-output-scanner/evaluate.ts +5 -5
  32. package/src/detect/tool-output-scanner/index.ts +3 -3
  33. package/src/detect/tool-output-scanner/scan.ts +6 -5
  34. package/src/detect/tool-output-scanner/size.ts +2 -2
  35. package/src/detect/tool-output-scanner/types.ts +1 -1
  36. package/src/l1-sandbox/bash-artifacts.ts +79 -0
  37. package/src/l1-sandbox/bash-ops.ts +133 -438
  38. package/src/l1-sandbox/bash-preflight.ts +292 -0
  39. package/src/l1-sandbox/bash-recovery.ts +566 -0
  40. package/src/l1-sandbox/manager.ts +0 -14
  41. package/src/l2-guard/detection.ts +140 -0
  42. package/src/l2-guard/output-gates.ts +191 -0
  43. package/src/l2-guard/report.ts +158 -0
  44. package/src/l2-guard/tool-gates.ts +189 -0
  45. package/src/shared/audit.ts +13 -8
  46. package/src/shared/canonicalize.ts +23 -20
  47. package/src/shared/network-grants.ts +12 -19
  48. package/src/shared/yolo.ts +24 -50
  49. package/src/ui/ask-flow.ts +1 -1
  50. package/src/ui/ask.ts +403 -225
@@ -1,131 +1,170 @@
1
- /**
2
- * Permission-mode UI (ADR-018, ADR-020): `/permission-mode` and the persisted mode.
3
- * Enforces nothing; persists `mode` to the global sandbox.json. The mode is
4
- * reflected in the single sandbox footer chip as an icon: `🧠`
5
- * advanced-secure, `🔒` default, `⚠️` YOLO.
6
- *
7
- * All three modes are persisted the same way and are one menu pick. YOLO is the
8
- * weakest tier: every layer is off. It travels to the layers over pi's event bus
9
- * (`src/shared/yolo.ts`) so the switch takes effect without a restart.
10
- */
11
-
12
1
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
13
2
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
14
- import { modeLabel, normalizeMode, setPolicyMode, type PermissionMode } from "../src/core/index";
15
- import { loadConfig } from "../src/l1-sandbox/config";
16
- import { loadPolicy } from "../src/l2-guard/policy";
17
- import { audit } from "../src/shared/audit";
18
- import { emitYolo, onYolo, YOLO_STATUS } from "../src/shared/yolo";
3
+ import { modeLabel, normalizeMode, setPolicyMode, type PermissionMode } from "../src/core/index.ts";
4
+ import { loadConfig } from "../src/l1-sandbox/config.ts";
5
+ import { loadPolicy } from "../src/l2-guard/policy.ts";
6
+ import { audit } from "../src/shared/audit.ts";
7
+ import { emitYolo, onYolo, YOLO_STATUS } from "../src/shared/yolo.ts";
19
8
 
20
- const GLOBAL_POLICY = `${getAgentDir()}/extensions/sandbox.json`;
9
+ const GLOBAL_POLICY_PATH = `${getAgentDir()}/extensions/sandbox.json`;
10
+ const SELECTION_TIMEOUT_MILLISECONDS = 120_000;
11
+ const MODE_LABEL_COLUMN_WIDTH = 26;
21
12
 
22
- const MODE_DEFS: Array<{
13
+ interface ModeDefinition {
23
14
  value: PermissionMode;
24
15
  icon: string;
25
16
  name: string;
26
- desc: string;
27
- }> = [
17
+ description: string;
18
+ }
19
+
20
+ const MODE_DEFINITIONS: ModeDefinition[] = [
28
21
  {
29
22
  value: "advanced-secure",
30
23
  icon: "🧠",
31
24
  name: "Advanced Secure",
32
- desc: "Blocks sensitive data leaks from file reads, MCP tools & command outputs",
25
+ description: "Blocks sensitive data leaks from file reads, MCP tools & command outputs",
33
26
  },
34
27
  {
35
28
  value: "default",
36
29
  icon: "🔒",
37
30
  name: "Default",
38
- desc: "Restricts file paths & network access at the sandbox level",
31
+ description: "Restricts file paths & network access at the sandbox level",
39
32
  },
40
33
  {
41
34
  value: "yolo",
42
35
  icon: "🚨",
43
36
  name: "YOLO",
44
- desc: "Turns off all file sandboxing and leak protections",
37
+ description: "Turns off all file sandboxing and leak protections",
45
38
  },
46
39
  ];
47
40
 
48
- /**
49
- * The single sandbox footer chip: `Sandbox: <icon> N domains, M paths`.
50
- * `🧠` marks advanced-secure, `🔒` default; YOLO replaces it with the warning.
51
- * All three are single-code-point emoji (no U+FE0F variation selector), so
52
- * every terminal measures them as two cells and the padding stays even.
53
- * Skipped when the sandbox is off, so it never clobbers those notices.
54
- */
55
- function renderSandboxChip(ctx: ExtensionContext): void {
56
- const config = loadConfig(ctx.cwd);
41
+ function renderSandboxChip(context: ExtensionContext): void {
42
+ const config = loadConfig(context.cwd);
43
+
57
44
  if (normalizeMode(config.mode) === "yolo") {
58
- ctx.ui.setStatus("sandbox", ctx.ui.theme.fg("error", YOLO_STATUS));
45
+ context.ui.setStatus("sandbox", context.ui.theme.fg("error", YOLO_STATUS));
46
+ return;
47
+ }
48
+
49
+ if (!config.enabled) {
59
50
  return;
60
51
  }
61
- if (!config.enabled) return;
62
- const secure = config.mode === "advanced-secure";
63
- const domains = config.network?.allowedDomains?.length ?? 0;
64
- const paths = config.filesystem?.allowWrite?.length ?? 0;
65
- const text = `Sandbox: ${secure ? "🧠" : "🔒"} ${domains} domains, ${paths} paths`;
66
- ctx.ui.setStatus("sandbox", ctx.ui.theme.fg(secure ? "success" : "accent", text));
52
+
53
+ const isSecureMode = config.mode === "advanced-secure";
54
+ const allowedDomainCount = config.network?.allowedDomains?.length ?? 0;
55
+ const allowedPathCount = config.filesystem?.allowWrite?.length ?? 0;
56
+ const modeIcon = isSecureMode ? "🧠" : "🔒";
57
+ const chipText = `Sandbox: ${modeIcon} ${allowedDomainCount} domains, ${allowedPathCount} paths`;
58
+
59
+ context.ui.setStatus("sandbox", context.ui.theme.fg(isSecureMode ? "success" : "accent", chipText));
67
60
  }
68
61
 
69
62
  function modeNotice(mode: PermissionMode): { text: string; level: "info" | "warning" } {
70
- if (mode === "yolo") return { text: "🚨 YOLO — all security layers disabled. Saved; new conversations start this way too.", level: "warning" };
71
- if (mode === "advanced-secure") return { text: "🧠 Advanced Secure on. File reads, MCP calls, and tool output are checked for secrets.", level: "info" };
72
- return { text: "🛡 Default mode. Rule-based policy only.", level: "info" };
63
+ if (mode === "yolo") {
64
+ return {
65
+ text: "🚨 YOLO — all security layers disabled. Saved; new conversations start this way too.",
66
+ level: "warning",
67
+ };
68
+ }
69
+
70
+ if (mode === "advanced-secure") {
71
+ return {
72
+ text: "🧠 Advanced Secure on. File reads, MCP calls, and tool output are checked for secrets.",
73
+ level: "info",
74
+ };
75
+ }
76
+
77
+ return {
78
+ text: "🛡 Default mode. Rule-based policy only.",
79
+ level: "info",
80
+ };
73
81
  }
74
82
 
75
- async function pickMode(pi: ExtensionAPI, ctx: ExtensionContext, yolo: { active: boolean }): Promise<void> {
76
- const current: PermissionMode = yolo.active ? "yolo" : normalizeMode(loadPolicy(ctx.cwd).mode);
83
+ async function pickMode(
84
+ pi: ExtensionAPI,
85
+ context: ExtensionContext,
86
+ yoloState: { active: boolean },
87
+ ): Promise<void> {
88
+ const currentMode: PermissionMode = yoloState.active
89
+ ? "yolo"
90
+ : normalizeMode(loadPolicy(context.cwd).mode);
91
+
92
+ const options = MODE_DEFINITIONS.map((definition) => {
93
+ const isActive = definition.value === currentMode;
94
+ const nameWithStatus = isActive ? `${definition.name} (active)` : definition.name;
95
+ const labelColumn = nameWithStatus.padEnd(MODE_LABEL_COLUMN_WIDTH);
77
96
 
78
- const options = MODE_DEFS.map((m) => {
79
- const isActive = m.value === current;
80
- const nameWithStatus = isActive ? `${m.name} (active)` : m.name;
81
- const labelCol = nameWithStatus.padEnd(26);
82
- return `${m.icon} ${labelCol} — ${m.desc}`;
97
+ return `${definition.icon} ${labelColumn} — ${definition.description}`;
83
98
  });
84
99
 
85
- const picked = await ctx.ui.select(
100
+ const pickedOption = await context.ui.select(
86
101
  "Select permission mode:",
87
102
  options,
88
- { timeout: 120_000 },
103
+ { timeout: SELECTION_TIMEOUT_MILLISECONDS },
89
104
  );
90
- if (picked === undefined) return;
91
105
 
92
- const pickedIndex = options.indexOf(picked);
93
- const next = pickedIndex >= 0 ? MODE_DEFS[pickedIndex].value : current;
94
- if (next === current) {
95
- if (next === "yolo" && !yolo.active) {
96
- yolo.active = true;
106
+ if (pickedOption === undefined) {
107
+ return;
108
+ }
109
+
110
+ const pickedIndex = options.indexOf(pickedOption);
111
+ const nextMode = pickedIndex >= 0 ? MODE_DEFINITIONS[pickedIndex].value : currentMode;
112
+
113
+ if (nextMode === currentMode) {
114
+ if (nextMode === "yolo" && !yoloState.active) {
115
+ yoloState.active = true;
97
116
  emitYolo(pi.events, true);
98
- audit({ layer: 0, event: "permission-mode", mode: "yolo", cwd: ctx.cwd, note: "runtime-sync" });
99
- renderSandboxChip(ctx);
100
- ctx.ui.notify("🚨 YOLO — all security layers disabled for this conversation.", "warning");
117
+
118
+ audit({
119
+ layer: 0,
120
+ event: "permission-mode",
121
+ mode: "yolo",
122
+ cwd: context.cwd,
123
+ note: "runtime-sync",
124
+ });
125
+
126
+ renderSandboxChip(context);
127
+ context.ui.notify("🚨 YOLO — all security layers disabled for this conversation.", "warning");
101
128
  return;
102
129
  }
103
- ctx.ui.notify(`Permission mode is already ${modeLabel(next)}.`, "info");
130
+
131
+ context.ui.notify(`Permission mode is already ${modeLabel(nextMode)}.`, "info");
104
132
  return;
105
133
  }
106
134
 
107
135
  try {
108
- setPolicyMode(GLOBAL_POLICY, next);
109
- } catch (e) {
110
- ctx.ui.notify(`Could not save the permission mode: ${e instanceof Error ? e.message : e}`, "error");
136
+ setPolicyMode(GLOBAL_POLICY_PATH, nextMode);
137
+ } catch (error) {
138
+ const errorMessage = error instanceof Error ? error.message : String(error);
139
+ context.ui.notify(`Could not save the permission mode: ${errorMessage}`, "error");
111
140
  return;
112
141
  }
113
- yolo.active = next === "yolo";
114
- emitYolo(pi.events, yolo.active);
115
- audit({ layer: 0, event: "permission-mode", mode: next, cwd: ctx.cwd });
116
- renderSandboxChip(ctx);
117
- const notice = modeNotice(next);
118
- ctx.ui.notify(notice.text, notice.level);
142
+
143
+ yoloState.active = nextMode === "yolo";
144
+ emitYolo(pi.events, yoloState.active);
145
+
146
+ audit({
147
+ layer: 0,
148
+ event: "permission-mode",
149
+ mode: nextMode,
150
+ cwd: context.cwd,
151
+ });
152
+
153
+ renderSandboxChip(context);
154
+
155
+ const notice = modeNotice(nextMode);
156
+ context.ui.notify(notice.text, notice.level);
119
157
  }
120
158
 
121
159
  export default function (pi: ExtensionAPI) {
122
- const yolo = { active: false };
160
+ const yoloState = { active: false };
161
+
123
162
  onYolo(pi.events, (enabled) => {
124
- yolo.active = enabled;
163
+ yoloState.active = enabled;
125
164
  });
126
165
 
127
166
  pi.registerCommand?.("permission-mode", {
128
167
  description: "Choose the permission mode: Default (rules), Advanced Secure (detection), or YOLO (all layers off). Saved to the global sandbox.json.",
129
- handler: async (_args, ctx) => pickMode(pi, ctx, yolo),
168
+ handler: async (_args, context) => pickMode(pi, context, yoloState),
130
169
  });
131
170
  }