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.
- package/extensions/guard.ts +210 -364
- package/extensions/permission-mode.ts +112 -73
- package/extensions/sandbox.ts +228 -138
- package/package.json +1 -1
- package/skills/auto-permission-system/SKILL.md +1 -1
- package/src/core/grep-filter.ts +33 -32
- package/src/core/index.ts +16 -20
- package/src/core/policy/classify.ts +27 -20
- package/src/core/policy/commands.ts +47 -30
- package/src/core/policy/fence.ts +101 -80
- package/src/core/policy/overrides.ts +31 -35
- package/src/core/policy/patterns.ts +39 -0
- package/src/core/policy/policy-file.ts +20 -36
- package/src/core/trust.ts +217 -142
- package/src/core/user-named.ts +88 -63
- package/src/detect/filename-gate/classify.ts +2 -2
- package/src/detect/filename-gate/index.ts +4 -4
- package/src/detect/index.ts +4 -4
- package/src/detect/mcp-gate/evaluate.ts +4 -4
- package/src/detect/mcp-gate/index.ts +3 -3
- package/src/detect/mcp-gate/signals.ts +3 -3
- package/src/detect/mcp-gate/verbs.ts +1 -1
- package/src/detect/sensitive-file-scanner/assignment.ts +2 -2
- package/src/detect/sensitive-file-scanner/content-scan.ts +10 -10
- package/src/detect/sensitive-file-scanner/file-scan.ts +8 -8
- package/src/detect/sensitive-file-scanner/index.ts +7 -7
- package/src/detect/sensitive-file-scanner/patterns.ts +1 -1
- package/src/detect/sensitive-file-scanner/redaction.ts +6 -6
- package/src/detect/sensitive-file-scanner/scoring.ts +3 -3
- package/src/detect/sensitive-file-scanner/value-analysis.ts +3 -3
- package/src/detect/tool-output-scanner/evaluate.ts +5 -5
- package/src/detect/tool-output-scanner/index.ts +3 -3
- package/src/detect/tool-output-scanner/scan.ts +6 -5
- package/src/detect/tool-output-scanner/size.ts +2 -2
- package/src/detect/tool-output-scanner/types.ts +1 -1
- package/src/l1-sandbox/bash-artifacts.ts +79 -0
- package/src/l1-sandbox/bash-ops.ts +133 -438
- package/src/l1-sandbox/bash-preflight.ts +292 -0
- package/src/l1-sandbox/bash-recovery.ts +566 -0
- package/src/l1-sandbox/manager.ts +0 -14
- package/src/l2-guard/detection.ts +140 -0
- package/src/l2-guard/output-gates.ts +191 -0
- package/src/l2-guard/report.ts +158 -0
- package/src/l2-guard/tool-gates.ts +189 -0
- package/src/shared/audit.ts +13 -8
- package/src/shared/canonicalize.ts +23 -20
- package/src/shared/network-grants.ts +12 -19
- package/src/shared/yolo.ts +24 -50
- package/src/ui/ask-flow.ts +1 -1
- 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
|
|
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
|
-
|
|
13
|
+
interface ModeDefinition {
|
|
23
14
|
value: PermissionMode;
|
|
24
15
|
icon: string;
|
|
25
16
|
name: string;
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
37
|
+
description: "Turns off all file sandboxing and leak protections",
|
|
45
38
|
},
|
|
46
39
|
];
|
|
47
40
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
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
|
-
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
|
|
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")
|
|
71
|
-
|
|
72
|
-
|
|
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(
|
|
76
|
-
|
|
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
|
-
|
|
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
|
|
100
|
+
const pickedOption = await context.ui.select(
|
|
86
101
|
"Select permission mode:",
|
|
87
102
|
options,
|
|
88
|
-
{ timeout:
|
|
103
|
+
{ timeout: SELECTION_TIMEOUT_MILLISECONDS },
|
|
89
104
|
);
|
|
90
|
-
if (picked === undefined) return;
|
|
91
105
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
130
|
+
|
|
131
|
+
context.ui.notify(`Permission mode is already ${modeLabel(nextMode)}.`, "info");
|
|
104
132
|
return;
|
|
105
133
|
}
|
|
106
134
|
|
|
107
135
|
try {
|
|
108
|
-
setPolicyMode(
|
|
109
|
-
} catch (
|
|
110
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
|
160
|
+
const yoloState = { active: false };
|
|
161
|
+
|
|
123
162
|
onYolo(pi.events, (enabled) => {
|
|
124
|
-
|
|
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,
|
|
168
|
+
handler: async (_args, context) => pickMode(pi, context, yoloState),
|
|
130
169
|
});
|
|
131
170
|
}
|