praxis-agent 0.10.0 → 0.12.0
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 +20 -3
- package/dist/application/session-service.d.ts +5 -2
- package/dist/application/session-service.js +23 -0
- package/dist/application/subagent-service.d.ts +4 -2
- package/dist/application/subagent-service.js +4 -0
- package/dist/cli/interactive.d.ts +6 -3
- package/dist/cli/interactive.js +650 -59
- package/dist/cli/tui/claude-command-inventory.d.ts +368 -0
- package/dist/cli/tui/claude-command-inventory.js +220 -0
- package/dist/cli/tui/mcp-elicitation.d.ts +75 -0
- package/dist/cli/tui/mcp-elicitation.js +497 -0
- package/dist/cli/tui/open-url.d.ts +2 -0
- package/dist/cli/tui/open-url.js +13 -0
- package/dist/cli/tui/permission-settings.d.ts +6 -0
- package/dist/cli/tui/permission-settings.js +84 -0
- package/dist/cli/tui/sandbox-dashboard.d.ts +10 -0
- package/dist/cli/tui/sandbox-dashboard.js +78 -0
- package/dist/cli/tui/sandbox-settings.d.ts +32 -0
- package/dist/cli/tui/sandbox-settings.js +146 -0
- package/dist/cli/tui/slash-commands.js +8 -28
- package/dist/cli/tui/tool-permission.d.ts +36 -0
- package/dist/cli/tui/tool-permission.js +386 -0
- package/dist/cli.d.ts +3 -2
- package/dist/cli.js +53 -14
- package/dist/core/runtime.d.ts +50 -2
- package/dist/core/runtime.js +30 -3
- package/dist/extensions/claude-extension-tools.d.ts +3 -2
- package/dist/extensions/claude-extension-tools.js +15 -5
- package/dist/extensions/claude-extensions.d.ts +1 -0
- package/dist/extensions/claude-extensions.js +10 -0
- package/dist/hooks/claude-hook-tools.js +1 -1
- package/dist/mcp/claude-mcp-tools.js +12 -6
- package/dist/permissions/bash-ast.d.ts +39 -0
- package/dist/permissions/bash-ast.js +1046 -0
- package/dist/permissions/bash-normalization.d.ts +5 -0
- package/dist/permissions/bash-normalization.js +241 -0
- package/dist/permissions/bash-path-safety.d.ts +30 -0
- package/dist/permissions/bash-path-safety.js +582 -0
- package/dist/permissions/claude-permission-resolver.d.ts +18 -0
- package/dist/permissions/claude-permission-resolver.js +366 -40
- package/dist/permissions/claude-shell-permission.d.ts +4 -0
- package/dist/permissions/claude-shell-permission.js +108 -0
- package/dist/permissions/permission-updates.d.ts +16 -0
- package/dist/permissions/permission-updates.js +320 -0
- package/dist/permissions/sed-safety.d.ts +9 -0
- package/dist/permissions/sed-safety.js +172 -0
- package/dist/permissions/shell-rule-matching.d.ts +14 -0
- package/dist/permissions/shell-rule-matching.js +76 -0
- package/dist/sandbox/claude-sandbox-runtime.d.ts +54 -0
- package/dist/sandbox/claude-sandbox-runtime.js +175 -0
- package/dist/sandbox/claude-sandbox-settings.d.ts +23 -0
- package/dist/sandbox/claude-sandbox-settings.js +286 -0
- package/dist/tools/claude-interactive-tools.d.ts +10 -1
- package/dist/tools/claude-interactive-tools.js +10 -4
- package/dist/tools/local-tools.d.ts +18 -0
- package/dist/tools/local-tools.js +69 -10
- package/package.json +4 -1
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import { lstatSync, readlinkSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
3
|
+
import { analyzeBashStructure, normalizeBashWrapperArgv, } from './bash-ast.js';
|
|
4
|
+
import { sedArgvIsReadOnly } from './sed-safety.js';
|
|
5
|
+
const OPERATIONS = {
|
|
6
|
+
cd: 'read',
|
|
7
|
+
ls: 'read',
|
|
8
|
+
find: 'read',
|
|
9
|
+
mkdir: 'create',
|
|
10
|
+
touch: 'create',
|
|
11
|
+
rm: 'write',
|
|
12
|
+
rmdir: 'write',
|
|
13
|
+
mv: 'write',
|
|
14
|
+
cp: 'write',
|
|
15
|
+
cat: 'read',
|
|
16
|
+
head: 'read',
|
|
17
|
+
tail: 'read',
|
|
18
|
+
sort: 'read',
|
|
19
|
+
uniq: 'read',
|
|
20
|
+
wc: 'read',
|
|
21
|
+
cut: 'read',
|
|
22
|
+
paste: 'read',
|
|
23
|
+
column: 'read',
|
|
24
|
+
tr: 'read',
|
|
25
|
+
file: 'read',
|
|
26
|
+
stat: 'read',
|
|
27
|
+
diff: 'read',
|
|
28
|
+
awk: 'read',
|
|
29
|
+
strings: 'read',
|
|
30
|
+
hexdump: 'read',
|
|
31
|
+
od: 'read',
|
|
32
|
+
base64: 'read',
|
|
33
|
+
nl: 'read',
|
|
34
|
+
grep: 'read',
|
|
35
|
+
rg: 'read',
|
|
36
|
+
sed: 'write',
|
|
37
|
+
git: 'read',
|
|
38
|
+
jq: 'read',
|
|
39
|
+
sha256sum: 'read',
|
|
40
|
+
sha1sum: 'read',
|
|
41
|
+
md5sum: 'read',
|
|
42
|
+
};
|
|
43
|
+
const PATH_COMMANDS = new Set(Object.keys(OPERATIONS));
|
|
44
|
+
const SENSITIVE_FILES = new Set([
|
|
45
|
+
'.gitconfig',
|
|
46
|
+
'.gitmodules',
|
|
47
|
+
'.bashrc',
|
|
48
|
+
'.bash_profile',
|
|
49
|
+
'.zshrc',
|
|
50
|
+
'.zprofile',
|
|
51
|
+
'.profile',
|
|
52
|
+
'.ripgreprc',
|
|
53
|
+
'.mcp.json',
|
|
54
|
+
'.claude.json',
|
|
55
|
+
]);
|
|
56
|
+
const SENSITIVE_DIRECTORIES = new Set(['.git', '.vscode', '.idea', '.claude']);
|
|
57
|
+
const GLOB = /[*?[\]{}]/u;
|
|
58
|
+
function positionalArguments(args) {
|
|
59
|
+
const result = [];
|
|
60
|
+
let optionsEnded = false;
|
|
61
|
+
for (const argument of args) {
|
|
62
|
+
if (!optionsEnded && argument === '--') {
|
|
63
|
+
optionsEnded = true;
|
|
64
|
+
}
|
|
65
|
+
else if (optionsEnded || !argument.startsWith('-')) {
|
|
66
|
+
result.push(argument);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
function patternCommandPaths(args, flagsWithValues, defaultPaths = []) {
|
|
72
|
+
const paths = [];
|
|
73
|
+
let patternSeen = false;
|
|
74
|
+
let optionsEnded = false;
|
|
75
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
76
|
+
const argument = args[index] ?? '';
|
|
77
|
+
if (!optionsEnded && argument === '--') {
|
|
78
|
+
optionsEnded = true;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (!optionsEnded && argument.startsWith('-')) {
|
|
82
|
+
const flag = argument.split('=', 1)[0] ?? argument;
|
|
83
|
+
if (['-e', '--regexp', '-f', '--file'].includes(flag))
|
|
84
|
+
patternSeen = true;
|
|
85
|
+
if (flagsWithValues.has(flag) && !argument.includes('='))
|
|
86
|
+
index += 1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (!patternSeen)
|
|
90
|
+
patternSeen = true;
|
|
91
|
+
else
|
|
92
|
+
paths.push(argument);
|
|
93
|
+
}
|
|
94
|
+
return paths.length > 0 ? paths : [...defaultPaths];
|
|
95
|
+
}
|
|
96
|
+
function sedPaths(args) {
|
|
97
|
+
const paths = [];
|
|
98
|
+
let expressionSeen = false;
|
|
99
|
+
let optionsEnded = false;
|
|
100
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
101
|
+
const argument = args[index] ?? '';
|
|
102
|
+
if (!optionsEnded && argument === '--') {
|
|
103
|
+
optionsEnded = true;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (!optionsEnded && argument.startsWith('-')) {
|
|
107
|
+
if (argument === '-f' || argument === '--file') {
|
|
108
|
+
if (args[index + 1])
|
|
109
|
+
paths.push(args[index + 1] ?? '');
|
|
110
|
+
index += 1;
|
|
111
|
+
expressionSeen = true;
|
|
112
|
+
}
|
|
113
|
+
else if (argument === '-e' || argument === '--expression') {
|
|
114
|
+
index += 1;
|
|
115
|
+
expressionSeen = true;
|
|
116
|
+
}
|
|
117
|
+
else if (/^-.*[ef]/u.test(argument)) {
|
|
118
|
+
expressionSeen = true;
|
|
119
|
+
}
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (!expressionSeen)
|
|
123
|
+
expressionSeen = true;
|
|
124
|
+
else
|
|
125
|
+
paths.push(argument);
|
|
126
|
+
}
|
|
127
|
+
return paths;
|
|
128
|
+
}
|
|
129
|
+
function findPaths(args) {
|
|
130
|
+
const paths = [];
|
|
131
|
+
const pathFlags = new Set([
|
|
132
|
+
'-newer',
|
|
133
|
+
'-anewer',
|
|
134
|
+
'-cnewer',
|
|
135
|
+
'-mnewer',
|
|
136
|
+
'-samefile',
|
|
137
|
+
'-path',
|
|
138
|
+
'-wholename',
|
|
139
|
+
'-ilname',
|
|
140
|
+
'-lname',
|
|
141
|
+
'-ipath',
|
|
142
|
+
'-iwholename',
|
|
143
|
+
]);
|
|
144
|
+
let predicateSeen = false;
|
|
145
|
+
let optionsEnded = false;
|
|
146
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
147
|
+
const argument = args[index] ?? '';
|
|
148
|
+
if (optionsEnded) {
|
|
149
|
+
paths.push(argument);
|
|
150
|
+
}
|
|
151
|
+
else if (argument === '--') {
|
|
152
|
+
optionsEnded = true;
|
|
153
|
+
}
|
|
154
|
+
else if (argument.startsWith('-')) {
|
|
155
|
+
if (!['-H', '-L', '-P'].includes(argument))
|
|
156
|
+
predicateSeen = true;
|
|
157
|
+
if (pathFlags.has(argument) || /^-newer[acmBt][acmtB]$/u.test(argument)) {
|
|
158
|
+
if (args[index + 1])
|
|
159
|
+
paths.push(args[index + 1] ?? '');
|
|
160
|
+
index += 1;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (!predicateSeen) {
|
|
164
|
+
paths.push(argument);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return paths.length > 0 ? paths : ['.'];
|
|
168
|
+
}
|
|
169
|
+
function commandPaths(command, args) {
|
|
170
|
+
if (command === 'cd')
|
|
171
|
+
return args.length > 0 ? [args.join(' ')] : ['~'];
|
|
172
|
+
if (command === 'ls') {
|
|
173
|
+
const paths = positionalArguments(args);
|
|
174
|
+
return paths.length > 0 ? paths : ['.'];
|
|
175
|
+
}
|
|
176
|
+
if (command === 'find')
|
|
177
|
+
return findPaths(args);
|
|
178
|
+
if (command === 'grep' || command === 'rg') {
|
|
179
|
+
const flags = new Set([
|
|
180
|
+
'-e',
|
|
181
|
+
'--regexp',
|
|
182
|
+
'-f',
|
|
183
|
+
'--file',
|
|
184
|
+
...(command === 'grep'
|
|
185
|
+
? ['--exclude', '--include', '--exclude-dir', '--include-dir']
|
|
186
|
+
: [
|
|
187
|
+
'-t',
|
|
188
|
+
'--type',
|
|
189
|
+
'-T',
|
|
190
|
+
'--type-not',
|
|
191
|
+
'-g',
|
|
192
|
+
'--glob',
|
|
193
|
+
'--max-depth',
|
|
194
|
+
'-r',
|
|
195
|
+
'--replace',
|
|
196
|
+
]),
|
|
197
|
+
'-m',
|
|
198
|
+
'--max-count',
|
|
199
|
+
'-A',
|
|
200
|
+
'--after-context',
|
|
201
|
+
'-B',
|
|
202
|
+
'--before-context',
|
|
203
|
+
'-C',
|
|
204
|
+
'--context',
|
|
205
|
+
]);
|
|
206
|
+
const paths = patternCommandPaths(args, flags, command === 'rg' ? ['.'] : []);
|
|
207
|
+
if (command === 'grep' &&
|
|
208
|
+
paths.length === 0 &&
|
|
209
|
+
args.some((argument) => ['-r', '-R', '--recursive'].includes(argument))) {
|
|
210
|
+
return ['.'];
|
|
211
|
+
}
|
|
212
|
+
return paths;
|
|
213
|
+
}
|
|
214
|
+
if (command === 'sed')
|
|
215
|
+
return sedPaths(args);
|
|
216
|
+
if (command === 'jq') {
|
|
217
|
+
return patternCommandPaths(args, new Set([
|
|
218
|
+
'-e',
|
|
219
|
+
'--expression',
|
|
220
|
+
'-f',
|
|
221
|
+
'--from-file',
|
|
222
|
+
'--arg',
|
|
223
|
+
'--argjson',
|
|
224
|
+
'--slurpfile',
|
|
225
|
+
'--rawfile',
|
|
226
|
+
'--args',
|
|
227
|
+
'--jsonargs',
|
|
228
|
+
'-L',
|
|
229
|
+
'--library-path',
|
|
230
|
+
'--indent',
|
|
231
|
+
'--tab',
|
|
232
|
+
]));
|
|
233
|
+
}
|
|
234
|
+
if (command === 'git') {
|
|
235
|
+
if (args[0] === 'diff' && args.includes('--no-index')) {
|
|
236
|
+
return positionalArguments(args.slice(1)).slice(0, 2);
|
|
237
|
+
}
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
if (command === 'tr') {
|
|
241
|
+
const positional = positionalArguments(args);
|
|
242
|
+
const deletes = args.some((arg) => /^-[^-]*d/u.test(arg) || arg === '--delete');
|
|
243
|
+
return positional.slice(deletes ? 1 : 2);
|
|
244
|
+
}
|
|
245
|
+
return positionalArguments(args);
|
|
246
|
+
}
|
|
247
|
+
function expandPath(path, options) {
|
|
248
|
+
if (path === '~' ||
|
|
249
|
+
path.startsWith('~/') ||
|
|
250
|
+
((options.platform ?? process.platform) === 'win32' &&
|
|
251
|
+
path.startsWith('~\\'))) {
|
|
252
|
+
return resolve(options.homeDirectory, path.slice(1).replace(/^[/\\]/u, ''));
|
|
253
|
+
}
|
|
254
|
+
return isAbsolute(path) ? resolve(path) : resolve(options.cwd, path);
|
|
255
|
+
}
|
|
256
|
+
function inside(candidate, root) {
|
|
257
|
+
const child = relative(resolve(root), resolve(candidate));
|
|
258
|
+
return child === '' || (!child.startsWith('..') && !isAbsolute(child));
|
|
259
|
+
}
|
|
260
|
+
function pathRepresentations(path) {
|
|
261
|
+
const absolute = resolve(path);
|
|
262
|
+
const representations = new Set([absolute]);
|
|
263
|
+
if (path.startsWith('//') || path.startsWith('\\\\')) {
|
|
264
|
+
return [...representations];
|
|
265
|
+
}
|
|
266
|
+
let current = absolute;
|
|
267
|
+
const visited = new Set();
|
|
268
|
+
for (let depth = 0; depth < 40 && !visited.has(current); depth += 1) {
|
|
269
|
+
visited.add(current);
|
|
270
|
+
try {
|
|
271
|
+
const stats = lstatSync(current);
|
|
272
|
+
if (stats.isFIFO() ||
|
|
273
|
+
stats.isSocket() ||
|
|
274
|
+
stats.isCharacterDevice() ||
|
|
275
|
+
stats.isBlockDevice()) {
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
if (!stats.isSymbolicLink())
|
|
279
|
+
break;
|
|
280
|
+
const target = readlinkSync(current);
|
|
281
|
+
current = isAbsolute(target) ? target : resolve(dirname(current), target);
|
|
282
|
+
representations.add(current);
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
let existing = absolute;
|
|
289
|
+
for (;;) {
|
|
290
|
+
try {
|
|
291
|
+
lstatSync(existing);
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
const parent = dirname(existing);
|
|
296
|
+
if (parent === existing)
|
|
297
|
+
return [...representations];
|
|
298
|
+
existing = parent;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
try {
|
|
302
|
+
const canonicalParent = realpathSync.native(existing);
|
|
303
|
+
representations.add(resolve(canonicalParent, relative(existing, absolute)));
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
// A disappearing or inaccessible path retains its lexical representations.
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
representations.add(realpathSync.native(absolute));
|
|
310
|
+
}
|
|
311
|
+
catch {
|
|
312
|
+
// Nonexistent targets are covered by their deepest existing ancestor.
|
|
313
|
+
}
|
|
314
|
+
return [...representations];
|
|
315
|
+
}
|
|
316
|
+
function globBasePath(path, platform) {
|
|
317
|
+
const match = GLOB.exec(path);
|
|
318
|
+
if (match?.index === undefined)
|
|
319
|
+
return path;
|
|
320
|
+
const prefix = path.slice(0, match.index);
|
|
321
|
+
const separatorIndex = platform === 'win32'
|
|
322
|
+
? Math.max(prefix.lastIndexOf('/'), prefix.lastIndexOf('\\'))
|
|
323
|
+
: prefix.lastIndexOf('/');
|
|
324
|
+
if (separatorIndex < 0)
|
|
325
|
+
return '.';
|
|
326
|
+
return prefix.slice(0, separatorIndex) || '/';
|
|
327
|
+
}
|
|
328
|
+
function containsTraversal(path) {
|
|
329
|
+
return path.split(/[\\/]+/u).includes('..');
|
|
330
|
+
}
|
|
331
|
+
function vulnerableUncPath(path, platform) {
|
|
332
|
+
if (platform !== 'win32')
|
|
333
|
+
return false;
|
|
334
|
+
return (/\\\\[^\s\\/]+(?:@(?:\d+|ssl))?(?:[\\/]|$|\s)/iu.test(path) ||
|
|
335
|
+
/(^|[^:])\/\/[^\s\\/]+(?:@(?:\d+|ssl))?(?:[\\/]|$|\s)/iu.test(path) ||
|
|
336
|
+
/\/\\{2,}[^\s\\/]/u.test(path) ||
|
|
337
|
+
/\\{2,}\/[^\s\\/]/u.test(path) ||
|
|
338
|
+
/@ssl@\d+|@\d+@ssl|davwwwroot/iu.test(path));
|
|
339
|
+
}
|
|
340
|
+
function suspiciousWritePath(path, platform) {
|
|
341
|
+
if ((platform === 'win32' || process.env.WSL_DISTRO_NAME !== undefined) &&
|
|
342
|
+
path.indexOf(':', 2) >= 0) {
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
return (/~\d/u.test(path) ||
|
|
346
|
+
path.startsWith('\\\\?\\') ||
|
|
347
|
+
path.startsWith('\\\\.\\') ||
|
|
348
|
+
path.startsWith('//?/') ||
|
|
349
|
+
path.startsWith('//./') ||
|
|
350
|
+
/[.\s]+$/u.test(path) ||
|
|
351
|
+
/\.(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/iu.test(path) ||
|
|
352
|
+
/(^|[\\/])\.{3,}(?:[\\/]|$)/u.test(path) ||
|
|
353
|
+
vulnerableUncPath(path, platform));
|
|
354
|
+
}
|
|
355
|
+
export function pathIsInsideRoots(candidate, roots) {
|
|
356
|
+
const rootRepresentations = roots.flatMap(pathRepresentations);
|
|
357
|
+
return pathRepresentations(candidate).every((path) => rootRepresentations.some((root) => inside(path, root)));
|
|
358
|
+
}
|
|
359
|
+
function sensitivePath(path) {
|
|
360
|
+
const segments = resolve(path)
|
|
361
|
+
.split(/[\\/]+/u)
|
|
362
|
+
.filter(Boolean)
|
|
363
|
+
.map((segment) => segment.toLocaleLowerCase());
|
|
364
|
+
for (let index = 0; index < segments.length; index += 1) {
|
|
365
|
+
const segment = segments[index] ?? '';
|
|
366
|
+
if (!SENSITIVE_DIRECTORIES.has(segment))
|
|
367
|
+
continue;
|
|
368
|
+
if (segment === '.claude' && segments[index + 1] === 'worktrees')
|
|
369
|
+
continue;
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
return SENSITIVE_FILES.has(segments.at(-1) ?? '');
|
|
373
|
+
}
|
|
374
|
+
function dangerousRemoval(path, homeDirectory) {
|
|
375
|
+
const normalized = path.replace(/[\\/]+/gu, '/').replace(/\/$/u, '') || '/';
|
|
376
|
+
if (normalized === '*' || normalized.endsWith('/*'))
|
|
377
|
+
return true;
|
|
378
|
+
if (normalized === '/' || normalized === resolve(homeDirectory))
|
|
379
|
+
return true;
|
|
380
|
+
return (dirname(normalized) === '/' ||
|
|
381
|
+
/^[A-Za-z]:$/u.test(normalized) ||
|
|
382
|
+
/^[A-Za-z]:\/[^/]+$/u.test(normalized));
|
|
383
|
+
}
|
|
384
|
+
function pathFailure(rawPath, operation, options, dangerous = false) {
|
|
385
|
+
const platform = options.platform ?? process.platform;
|
|
386
|
+
if (vulnerableUncPath(rawPath, platform)) {
|
|
387
|
+
return {
|
|
388
|
+
safe: false,
|
|
389
|
+
behavior: 'ask',
|
|
390
|
+
reason: 'UNC network paths require manual approval',
|
|
391
|
+
path: rawPath,
|
|
392
|
+
operation,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
if (rawPath.includes('__PRAXIS_COMMAND_SUBSTITUTION__') ||
|
|
396
|
+
rawPath.includes('$') ||
|
|
397
|
+
rawPath.includes('%') ||
|
|
398
|
+
rawPath.startsWith('=')) {
|
|
399
|
+
return {
|
|
400
|
+
safe: false,
|
|
401
|
+
behavior: 'ask',
|
|
402
|
+
reason: 'Shell expansion syntax in paths requires manual approval',
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
if (rawPath.startsWith('~') && rawPath !== '~' && !rawPath.startsWith('~/')) {
|
|
406
|
+
return {
|
|
407
|
+
safe: false,
|
|
408
|
+
behavior: 'ask',
|
|
409
|
+
reason: 'Tilde expansion variants in paths require manual approval',
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
if (GLOB.test(rawPath) && operation !== 'read') {
|
|
413
|
+
return {
|
|
414
|
+
safe: false,
|
|
415
|
+
behavior: 'ask',
|
|
416
|
+
reason: 'Glob patterns are not allowed in write operations',
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
const validationPath = operation === 'read' && GLOB.test(rawPath) && !containsTraversal(rawPath)
|
|
420
|
+
? globBasePath(rawPath, platform)
|
|
421
|
+
: rawPath;
|
|
422
|
+
const absolutePath = expandPath(validationPath, options);
|
|
423
|
+
const pathsToCheck = pathRepresentations(absolutePath);
|
|
424
|
+
const rules = pathsToCheck.map((path) => options.fileRule?.(operation, path) ?? null);
|
|
425
|
+
if (rules.includes('deny')) {
|
|
426
|
+
return {
|
|
427
|
+
safe: false,
|
|
428
|
+
behavior: 'deny',
|
|
429
|
+
reason: `Path '${absolutePath}' is denied by a file permission rule`,
|
|
430
|
+
path: absolutePath,
|
|
431
|
+
operation,
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
if (operation !== 'read' &&
|
|
435
|
+
pathIsInsideRoots(absolutePath, options.internalEditableRoots ?? [])) {
|
|
436
|
+
return { safe: true };
|
|
437
|
+
}
|
|
438
|
+
if (dangerous &&
|
|
439
|
+
[rawPath, ...pathsToCheck].some((path) => dangerousRemoval(path, options.homeDirectory))) {
|
|
440
|
+
return {
|
|
441
|
+
safe: false,
|
|
442
|
+
behavior: 'ask',
|
|
443
|
+
reason: `Dangerous removal operation on critical path: ${absolutePath}`,
|
|
444
|
+
path: absolutePath,
|
|
445
|
+
operation,
|
|
446
|
+
suggestions: [],
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
if (operation !== 'read' &&
|
|
450
|
+
[rawPath, ...pathsToCheck].some((path) => suspiciousWritePath(path, platform))) {
|
|
451
|
+
return {
|
|
452
|
+
safe: false,
|
|
453
|
+
behavior: 'ask',
|
|
454
|
+
reason: `Write to suspicious path '${absolutePath}' requires explicit approval`,
|
|
455
|
+
path: absolutePath,
|
|
456
|
+
operation,
|
|
457
|
+
suggestions: [],
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
if (operation !== 'read' &&
|
|
461
|
+
pathsToCheck.some((path) => sensitivePath(path))) {
|
|
462
|
+
return {
|
|
463
|
+
safe: false,
|
|
464
|
+
behavior: 'ask',
|
|
465
|
+
reason: `Write to sensitive file '${absolutePath}' requires explicit approval`,
|
|
466
|
+
path: absolutePath,
|
|
467
|
+
operation,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
const roots = operation === 'read' ? options.readRoots : options.writeRoots;
|
|
471
|
+
const inRoot = pathIsInsideRoots(absolutePath, roots);
|
|
472
|
+
if (inRoot &&
|
|
473
|
+
(operation === 'read' || options.permissionMode === 'acceptEdits')) {
|
|
474
|
+
return { safe: true };
|
|
475
|
+
}
|
|
476
|
+
if (operation === 'read' &&
|
|
477
|
+
pathIsInsideRoots(absolutePath, options.internalReadableRoots ?? [])) {
|
|
478
|
+
return { safe: true };
|
|
479
|
+
}
|
|
480
|
+
if (operation !== 'read' &&
|
|
481
|
+
!inRoot &&
|
|
482
|
+
options.sandboxWriteConfig &&
|
|
483
|
+
!pathIsInsideRoots(absolutePath, options.sandboxWriteConfig.denyWithinAllow) &&
|
|
484
|
+
pathIsInsideRoots(absolutePath, options.sandboxWriteConfig.allowOnly)) {
|
|
485
|
+
return { safe: true };
|
|
486
|
+
}
|
|
487
|
+
if (rules.length > 0 && rules.every((rule) => rule === 'allow')) {
|
|
488
|
+
return { safe: true };
|
|
489
|
+
}
|
|
490
|
+
return {
|
|
491
|
+
safe: false,
|
|
492
|
+
behavior: 'ask',
|
|
493
|
+
reason: operation === 'read'
|
|
494
|
+
? `Path '${absolutePath}' is outside allowed working directories`
|
|
495
|
+
: `Write to '${absolutePath}' requires explicit approval`,
|
|
496
|
+
path: absolutePath,
|
|
497
|
+
operation,
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
function outputRedirect(redirect) {
|
|
501
|
+
return ['>', '>>', '>|', '&>', '&>>', '>&'].includes(redirect.operator);
|
|
502
|
+
}
|
|
503
|
+
export function validateBashPathSafety(source, options) {
|
|
504
|
+
const analysis = analyzeBashStructure(source);
|
|
505
|
+
if (!analysis.parsed) {
|
|
506
|
+
return { safe: false, behavior: 'ask', reason: analysis.reason };
|
|
507
|
+
}
|
|
508
|
+
const normalized = analysis.commands.map((command) => ({
|
|
509
|
+
...command,
|
|
510
|
+
wrapper: normalizeBashWrapperArgv(command.argv),
|
|
511
|
+
}));
|
|
512
|
+
const hasCd = normalized.some(({ wrapper }) => wrapper.ok && wrapper.argv[0] === 'cd');
|
|
513
|
+
if (hasCd &&
|
|
514
|
+
normalized.filter(({ wrapper }) => wrapper.ok && wrapper.argv[0] === 'cd')
|
|
515
|
+
.length > 1) {
|
|
516
|
+
return {
|
|
517
|
+
safe: false,
|
|
518
|
+
behavior: 'ask',
|
|
519
|
+
reason: 'Multiple directory changes require explicit approval',
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
if (hasCd &&
|
|
523
|
+
normalized.some(({ wrapper }) => wrapper.ok && wrapper.argv[0] === 'git')) {
|
|
524
|
+
return {
|
|
525
|
+
safe: false,
|
|
526
|
+
behavior: 'ask',
|
|
527
|
+
reason: 'Compound commands with cd and git require approval to prevent bare repository attacks',
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
for (const redirect of analysis.redirects) {
|
|
531
|
+
if (!outputRedirect(redirect))
|
|
532
|
+
continue;
|
|
533
|
+
if (redirect.operator === '>&' && /^\d+$/u.test(redirect.target))
|
|
534
|
+
continue;
|
|
535
|
+
if (redirect.target === '/dev/null')
|
|
536
|
+
continue;
|
|
537
|
+
if (hasCd) {
|
|
538
|
+
return {
|
|
539
|
+
safe: false,
|
|
540
|
+
behavior: 'ask',
|
|
541
|
+
reason: 'Commands with directory changes and output redirection require explicit approval',
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
const result = pathFailure(redirect.target, 'create', options);
|
|
545
|
+
if (!result.safe)
|
|
546
|
+
return result;
|
|
547
|
+
}
|
|
548
|
+
for (const { wrapper } of normalized) {
|
|
549
|
+
if (!wrapper.ok) {
|
|
550
|
+
return { safe: false, behavior: 'ask', reason: wrapper.reason };
|
|
551
|
+
}
|
|
552
|
+
const [base, ...args] = wrapper.argv;
|
|
553
|
+
if (!base || !PATH_COMMANDS.has(base))
|
|
554
|
+
continue;
|
|
555
|
+
const command = base;
|
|
556
|
+
if ((command === 'mv' || command === 'cp') &&
|
|
557
|
+
args.some((arg) => arg.startsWith('-'))) {
|
|
558
|
+
return {
|
|
559
|
+
safe: false,
|
|
560
|
+
behavior: 'ask',
|
|
561
|
+
reason: `${command} command with flags requires manual approval`,
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
const operation = command === 'sed' && sedArgvIsReadOnly(wrapper.argv)
|
|
565
|
+
? 'read'
|
|
566
|
+
: OPERATIONS[command];
|
|
567
|
+
if (hasCd && operation !== 'read') {
|
|
568
|
+
return {
|
|
569
|
+
safe: false,
|
|
570
|
+
behavior: 'ask',
|
|
571
|
+
reason: 'Commands with directory changes and write operations require explicit approval',
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
for (const path of commandPaths(command, args)) {
|
|
575
|
+
const result = pathFailure(path, operation, options, command === 'rm' || command === 'rmdir');
|
|
576
|
+
if (!result.safe)
|
|
577
|
+
return result;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return { safe: true };
|
|
581
|
+
}
|
|
582
|
+
//# sourceMappingURL=bash-path-safety.js.map
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type { FsWriteRestrictionConfig } from '@anthropic-ai/sandbox-runtime';
|
|
1
2
|
import type { ClaudeJsonResource } from '../compatibility/claude/shared-resources.js';
|
|
2
3
|
import type { ModelToolCall, PermissionDecision, PermissionResolutionContext, PermissionResolver } from '../core/runtime.js';
|
|
3
4
|
import { type ClaudeAutoClassifier, type ClaudeAutoModeConfig } from './claude-auto-classifier.js';
|
|
4
5
|
export interface ClaudePermissionResolverOptions {
|
|
5
6
|
cwd: string;
|
|
6
7
|
cwdProvider?: () => string;
|
|
8
|
+
configRoot?: string;
|
|
7
9
|
homeDirectory?: string;
|
|
8
10
|
settings: readonly ClaudeJsonResource[];
|
|
9
11
|
allowedTools?: readonly string[];
|
|
@@ -12,19 +14,35 @@ export interface ClaudePermissionResolverOptions {
|
|
|
12
14
|
autoClassifier?: ClaudeAutoClassifier;
|
|
13
15
|
autoModeConfig?: ClaudeAutoModeConfig;
|
|
14
16
|
isSessionActionApproved?: (call: ModelToolCall) => boolean;
|
|
17
|
+
additionalDirectories?: readonly string[];
|
|
18
|
+
additionalReadDirectories?: readonly string[];
|
|
19
|
+
sandbox?: ClaudePermissionSandbox;
|
|
20
|
+
}
|
|
21
|
+
export interface ClaudePermissionSandbox {
|
|
22
|
+
autoAllowsBash(): boolean;
|
|
23
|
+
shouldUseSandbox(input: {
|
|
24
|
+
command: string;
|
|
25
|
+
dangerouslyDisableSandbox?: boolean;
|
|
26
|
+
}): boolean;
|
|
27
|
+
getFsWriteConfig(): FsWriteRestrictionConfig | undefined;
|
|
15
28
|
}
|
|
16
29
|
export type ClaudePermissionMode = 'acceptEdits' | 'auto' | 'bypassPermissions' | 'manual' | 'dontAsk' | 'plan' | 'default';
|
|
17
30
|
export declare function claudePermissionActionKey(call: ModelToolCall): string;
|
|
18
31
|
export declare function validateClaudePermissionSettings(settings: readonly ClaudeJsonResource[]): void;
|
|
32
|
+
export declare function claudePermissionRuleMatches(rule: string, call: ModelToolCall, cwd: string, homeDirectory?: string): boolean;
|
|
19
33
|
export declare class ClaudePermissionResolver implements PermissionResolver {
|
|
20
34
|
private readonly rules;
|
|
21
35
|
private readonly cwd;
|
|
22
36
|
private readonly cwdProvider;
|
|
37
|
+
private readonly configRoot;
|
|
23
38
|
private readonly homeDirectory;
|
|
24
39
|
private readonly permissionMode;
|
|
25
40
|
private readonly autoClassifier;
|
|
26
41
|
private readonly autoModeConfig;
|
|
27
42
|
private readonly isSessionActionApproved;
|
|
43
|
+
private readonly additionalDirectories;
|
|
44
|
+
private readonly additionalReadDirectories;
|
|
45
|
+
private readonly sandbox;
|
|
28
46
|
constructor(options: ClaudePermissionResolverOptions);
|
|
29
47
|
resolve(call: ModelToolCall, context?: PermissionResolutionContext): Promise<PermissionDecision>;
|
|
30
48
|
private askDecision;
|