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.
Files changed (57) hide show
  1. package/README.md +20 -3
  2. package/dist/application/session-service.d.ts +5 -2
  3. package/dist/application/session-service.js +23 -0
  4. package/dist/application/subagent-service.d.ts +4 -2
  5. package/dist/application/subagent-service.js +4 -0
  6. package/dist/cli/interactive.d.ts +6 -3
  7. package/dist/cli/interactive.js +650 -59
  8. package/dist/cli/tui/claude-command-inventory.d.ts +368 -0
  9. package/dist/cli/tui/claude-command-inventory.js +220 -0
  10. package/dist/cli/tui/mcp-elicitation.d.ts +75 -0
  11. package/dist/cli/tui/mcp-elicitation.js +497 -0
  12. package/dist/cli/tui/open-url.d.ts +2 -0
  13. package/dist/cli/tui/open-url.js +13 -0
  14. package/dist/cli/tui/permission-settings.d.ts +6 -0
  15. package/dist/cli/tui/permission-settings.js +84 -0
  16. package/dist/cli/tui/sandbox-dashboard.d.ts +10 -0
  17. package/dist/cli/tui/sandbox-dashboard.js +78 -0
  18. package/dist/cli/tui/sandbox-settings.d.ts +32 -0
  19. package/dist/cli/tui/sandbox-settings.js +146 -0
  20. package/dist/cli/tui/slash-commands.js +8 -28
  21. package/dist/cli/tui/tool-permission.d.ts +36 -0
  22. package/dist/cli/tui/tool-permission.js +386 -0
  23. package/dist/cli.d.ts +3 -2
  24. package/dist/cli.js +53 -14
  25. package/dist/core/runtime.d.ts +50 -2
  26. package/dist/core/runtime.js +30 -3
  27. package/dist/extensions/claude-extension-tools.d.ts +3 -2
  28. package/dist/extensions/claude-extension-tools.js +15 -5
  29. package/dist/extensions/claude-extensions.d.ts +1 -0
  30. package/dist/extensions/claude-extensions.js +10 -0
  31. package/dist/hooks/claude-hook-tools.js +1 -1
  32. package/dist/mcp/claude-mcp-tools.js +12 -6
  33. package/dist/permissions/bash-ast.d.ts +39 -0
  34. package/dist/permissions/bash-ast.js +1046 -0
  35. package/dist/permissions/bash-normalization.d.ts +5 -0
  36. package/dist/permissions/bash-normalization.js +241 -0
  37. package/dist/permissions/bash-path-safety.d.ts +30 -0
  38. package/dist/permissions/bash-path-safety.js +582 -0
  39. package/dist/permissions/claude-permission-resolver.d.ts +18 -0
  40. package/dist/permissions/claude-permission-resolver.js +366 -40
  41. package/dist/permissions/claude-shell-permission.d.ts +4 -0
  42. package/dist/permissions/claude-shell-permission.js +108 -0
  43. package/dist/permissions/permission-updates.d.ts +16 -0
  44. package/dist/permissions/permission-updates.js +320 -0
  45. package/dist/permissions/sed-safety.d.ts +9 -0
  46. package/dist/permissions/sed-safety.js +172 -0
  47. package/dist/permissions/shell-rule-matching.d.ts +14 -0
  48. package/dist/permissions/shell-rule-matching.js +76 -0
  49. package/dist/sandbox/claude-sandbox-runtime.d.ts +54 -0
  50. package/dist/sandbox/claude-sandbox-runtime.js +175 -0
  51. package/dist/sandbox/claude-sandbox-settings.d.ts +23 -0
  52. package/dist/sandbox/claude-sandbox-settings.js +286 -0
  53. package/dist/tools/claude-interactive-tools.d.ts +10 -1
  54. package/dist/tools/claude-interactive-tools.js +10 -4
  55. package/dist/tools/local-tools.d.ts +18 -0
  56. package/dist/tools/local-tools.js +69 -10
  57. package/package.json +4 -1
@@ -0,0 +1,16 @@
1
+ import type { PermissionMode, PermissionRuleValue, PermissionUpdate } from '../core/runtime.js';
2
+ export declare function permissionRuleValueToString(rule: PermissionRuleValue): string;
3
+ export declare function permissionRuleValueFromString(value: string): PermissionRuleValue;
4
+ export declare function parsePermissionUpdates(value: unknown): readonly PermissionUpdate[] | undefined;
5
+ export declare function extractPermissionRules(updates: readonly PermissionUpdate[] | undefined): readonly PermissionRuleValue[];
6
+ export declare function effectivePermissionMode(updates: readonly PermissionUpdate[] | undefined): PermissionMode | undefined;
7
+ export declare function effectiveAdditionalDirectories(updates: readonly PermissionUpdate[] | undefined, initial?: readonly string[]): readonly string[];
8
+ export declare function readDirectoryPermissionUpdate(path: string, cwd: string, targetIsDirectory?: boolean): Extract<PermissionUpdate, {
9
+ type: 'addRules';
10
+ }> | undefined;
11
+ export declare function filePermissionSuggestions(path: string, cwd: string, operation: 'read' | 'write', mode: PermissionMode, outsideWorkingDirectory: boolean, pathsToCheck?: readonly string[], targetIsDirectory?: boolean): readonly PermissionUpdate[];
12
+ export declare function shellSubcommands(command: string, shell?: 'bash' | 'powershell'): readonly string[];
13
+ export declare function shellCommandIsReadOnly(command: string): boolean;
14
+ export declare function shellPermissionSuggestions(toolName: 'Bash' | 'PowerShell', command: string, include?: (subcommand: string) => boolean): readonly PermissionUpdate[];
15
+ export declare function skillPermissionSuggestions(skill: string): readonly PermissionUpdate[];
16
+ //# sourceMappingURL=permission-updates.d.ts.map
@@ -0,0 +1,320 @@
1
+ import { dirname, isAbsolute, resolve } from 'node:path';
2
+ import { claudeBashPermissionSuggestionContent } from './claude-shell-permission.js';
3
+ import { analyzeBashCommands } from './bash-ast.js';
4
+ export function permissionRuleValueToString(rule) {
5
+ if (!rule.ruleContent)
6
+ return rule.toolName;
7
+ const content = rule.ruleContent
8
+ .replaceAll('\\', '\\\\')
9
+ .replaceAll('(', '\\(')
10
+ .replaceAll(')', '\\)');
11
+ return `${rule.toolName}(${content})`;
12
+ }
13
+ function unescapedIndex(value, character, fromEnd = false) {
14
+ const start = fromEnd ? value.length - 1 : 0;
15
+ const end = fromEnd ? -1 : value.length;
16
+ const step = fromEnd ? -1 : 1;
17
+ for (let index = start; index !== end; index += step) {
18
+ if (value[index] !== character)
19
+ continue;
20
+ let escapes = 0;
21
+ for (let cursor = index - 1; cursor >= 0 && value[cursor] === '\\'; cursor -= 1) {
22
+ escapes += 1;
23
+ }
24
+ if (escapes % 2 === 0)
25
+ return index;
26
+ }
27
+ return -1;
28
+ }
29
+ export function permissionRuleValueFromString(value) {
30
+ const opening = unescapedIndex(value, '(');
31
+ if (opening < 1)
32
+ return { toolName: value };
33
+ const closing = unescapedIndex(value, ')', true);
34
+ if (closing !== value.length - 1 || closing <= opening) {
35
+ return { toolName: value };
36
+ }
37
+ const toolName = value.slice(0, opening);
38
+ const raw = value.slice(opening + 1, closing);
39
+ if (!raw || raw === '*')
40
+ return { toolName };
41
+ return {
42
+ toolName,
43
+ ruleContent: raw
44
+ .replaceAll('\\(', '(')
45
+ .replaceAll('\\)', ')')
46
+ .replaceAll('\\\\', '\\'),
47
+ };
48
+ }
49
+ function isRecord(value) {
50
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
51
+ }
52
+ export function parsePermissionUpdates(value) {
53
+ if (!Array.isArray(value))
54
+ return undefined;
55
+ const updates = [];
56
+ for (const item of value) {
57
+ if (!isRecord(item) || typeof item.destination !== 'string')
58
+ return undefined;
59
+ if (![
60
+ 'userSettings',
61
+ 'projectSettings',
62
+ 'localSettings',
63
+ 'session',
64
+ 'cliArg',
65
+ ].includes(item.destination)) {
66
+ return undefined;
67
+ }
68
+ const destination = item.destination;
69
+ if (item.type === 'addRules' ||
70
+ item.type === 'replaceRules' ||
71
+ item.type === 'removeRules') {
72
+ if (!['allow', 'ask', 'deny'].includes(String(item.behavior)) ||
73
+ !Array.isArray(item.rules)) {
74
+ return undefined;
75
+ }
76
+ const rules = [];
77
+ for (const rule of item.rules) {
78
+ if (!isRecord(rule) ||
79
+ typeof rule.toolName !== 'string' ||
80
+ (rule.ruleContent !== undefined &&
81
+ typeof rule.ruleContent !== 'string')) {
82
+ return undefined;
83
+ }
84
+ rules.push({
85
+ toolName: rule.toolName,
86
+ ...(typeof rule.ruleContent === 'string'
87
+ ? { ruleContent: rule.ruleContent }
88
+ : {}),
89
+ });
90
+ }
91
+ updates.push({
92
+ type: item.type,
93
+ rules,
94
+ behavior: item.behavior,
95
+ destination,
96
+ });
97
+ continue;
98
+ }
99
+ if (item.type === 'setMode') {
100
+ if (![
101
+ 'acceptEdits',
102
+ 'bypassPermissions',
103
+ 'dontAsk',
104
+ 'plan',
105
+ 'default',
106
+ ].includes(String(item.mode))) {
107
+ return undefined;
108
+ }
109
+ updates.push({
110
+ type: 'setMode',
111
+ mode: item.mode,
112
+ destination,
113
+ });
114
+ continue;
115
+ }
116
+ if (item.type === 'addDirectories' || item.type === 'removeDirectories') {
117
+ if (!Array.isArray(item.directories) ||
118
+ item.directories.some((directory) => typeof directory !== 'string')) {
119
+ return undefined;
120
+ }
121
+ updates.push({
122
+ type: item.type,
123
+ directories: item.directories,
124
+ destination,
125
+ });
126
+ continue;
127
+ }
128
+ return undefined;
129
+ }
130
+ return updates;
131
+ }
132
+ export function extractPermissionRules(updates) {
133
+ return (updates ?? []).flatMap((update) => update.type === 'addRules' ? [...update.rules] : []);
134
+ }
135
+ export function effectivePermissionMode(updates) {
136
+ return (updates ?? []).findLast((update) => update.type === 'setMode')?.mode;
137
+ }
138
+ export function effectiveAdditionalDirectories(updates, initial = []) {
139
+ const directories = new Set(initial);
140
+ for (const update of updates ?? []) {
141
+ if (update.type === 'addDirectories') {
142
+ for (const directory of update.directories)
143
+ directories.add(directory);
144
+ }
145
+ else if (update.type === 'removeDirectories') {
146
+ for (const directory of update.directories)
147
+ directories.delete(directory);
148
+ }
149
+ }
150
+ return [...directories];
151
+ }
152
+ export function readDirectoryPermissionUpdate(path, cwd, targetIsDirectory = false) {
153
+ const absolute = resolve(cwd, path);
154
+ const directory = targetIsDirectory ? absolute : dirname(absolute);
155
+ if (directory === dirname(directory))
156
+ return undefined;
157
+ const normalized = directory.replaceAll('\\', '/');
158
+ return {
159
+ type: 'addRules',
160
+ rules: [
161
+ {
162
+ toolName: 'Read',
163
+ ruleContent: isAbsolute(normalized)
164
+ ? `/${normalized}/**`
165
+ : `${normalized}/**`,
166
+ },
167
+ ],
168
+ behavior: 'allow',
169
+ destination: 'session',
170
+ };
171
+ }
172
+ export function filePermissionSuggestions(path, cwd, operation, mode, outsideWorkingDirectory, pathsToCheck = [path], targetIsDirectory = false) {
173
+ if (operation === 'read' && outsideWorkingDirectory) {
174
+ const updates = pathsToCheck.flatMap((candidate) => {
175
+ const update = readDirectoryPermissionUpdate(candidate, cwd, targetIsDirectory);
176
+ return update ? [update] : [];
177
+ });
178
+ const seen = new Set();
179
+ return updates.filter((update) => {
180
+ const rule = update.rules[0];
181
+ if (!rule)
182
+ return false;
183
+ const key = permissionRuleValueToString(rule);
184
+ if (seen.has(key))
185
+ return false;
186
+ seen.add(key);
187
+ return true;
188
+ });
189
+ }
190
+ const updates = [];
191
+ if (mode === 'default' || mode === 'plan') {
192
+ updates.push({
193
+ type: 'setMode',
194
+ mode: 'acceptEdits',
195
+ destination: 'session',
196
+ });
197
+ }
198
+ if (operation === 'write' && outsideWorkingDirectory) {
199
+ const directories = [
200
+ ...new Set(pathsToCheck.map((candidate) => dirname(resolve(cwd, candidate)))),
201
+ ];
202
+ updates.push({
203
+ type: 'addDirectories',
204
+ directories,
205
+ destination: 'session',
206
+ });
207
+ }
208
+ return updates;
209
+ }
210
+ function legacyShellSubcommands(command) {
211
+ const commands = [];
212
+ let start = 0;
213
+ let quote = null;
214
+ let escaped = false;
215
+ let depth = 0;
216
+ const push = (end, width) => {
217
+ const part = command.slice(start, end).trim();
218
+ if (part)
219
+ commands.push(part);
220
+ start = end + width;
221
+ };
222
+ for (let index = 0; index < command.length; index += 1) {
223
+ const character = command[index];
224
+ if (escaped) {
225
+ escaped = false;
226
+ continue;
227
+ }
228
+ if (character === '\\' && quote !== "'") {
229
+ escaped = true;
230
+ continue;
231
+ }
232
+ if (quote) {
233
+ if (character === quote)
234
+ quote = null;
235
+ continue;
236
+ }
237
+ if (character === "'" || character === '"' || character === '`') {
238
+ quote = character;
239
+ continue;
240
+ }
241
+ if (character === '(' || character === '{' || character === '[') {
242
+ depth += 1;
243
+ continue;
244
+ }
245
+ if (character === ')' || character === '}' || character === ']') {
246
+ depth = Math.max(0, depth - 1);
247
+ continue;
248
+ }
249
+ if (depth > 0)
250
+ continue;
251
+ const pair = command.slice(index, index + 2);
252
+ if (pair === '&&' || pair === '||') {
253
+ push(index, 2);
254
+ index += 1;
255
+ }
256
+ else if (character === ';' || character === '|' || character === '\n') {
257
+ push(index, 1);
258
+ }
259
+ }
260
+ push(command.length, 0);
261
+ return commands;
262
+ }
263
+ export function shellSubcommands(command, shell = 'bash') {
264
+ return shell === 'bash'
265
+ ? analyzeBashCommands(command).commands
266
+ : legacyShellSubcommands(command);
267
+ }
268
+ const READ_ONLY_SHELL_COMMANDS = new Set([
269
+ 'cd',
270
+ 'echo',
271
+ 'head',
272
+ 'ls',
273
+ 'pwd',
274
+ 'printf',
275
+ 'tail',
276
+ 'test',
277
+ 'true',
278
+ 'wc',
279
+ 'which',
280
+ ]);
281
+ function commandName(command) {
282
+ return command.trim().split(/\s+/u)[0] ?? '';
283
+ }
284
+ export function shellCommandIsReadOnly(command) {
285
+ if (/[<>`]|$\(|\|\||&&|[;|\n\r]/u.test(command))
286
+ return false;
287
+ return READ_ONLY_SHELL_COMMANDS.has(commandName(command));
288
+ }
289
+ export function shellPermissionSuggestions(toolName, command, include = () => true) {
290
+ const parts = shellSubcommands(command, toolName === 'Bash' ? 'bash' : 'powershell');
291
+ const candidates = (parts.length > 0 ? parts : [command]).filter((part) => !shellCommandIsReadOnly(part) && include(part));
292
+ const values = candidates
293
+ .map((part) => toolName === 'Bash'
294
+ ? claudeBashPermissionSuggestionContent(part)
295
+ : part.trim())
296
+ .filter(Boolean);
297
+ const unique = [...new Set(values)].slice(0, 5);
298
+ return unique.length === 0
299
+ ? []
300
+ : [
301
+ {
302
+ type: 'addRules',
303
+ rules: unique.map((ruleContent) => ({ toolName, ruleContent })),
304
+ behavior: 'allow',
305
+ destination: 'localSettings',
306
+ },
307
+ ];
308
+ }
309
+ export function skillPermissionSuggestions(skill) {
310
+ const normalized = skill.trim().replace(/^\//u, '');
311
+ if (!normalized)
312
+ return [];
313
+ return [normalized, `${normalized}:*`].map((ruleContent) => ({
314
+ type: 'addRules',
315
+ rules: [{ toolName: 'Skill', ruleContent }],
316
+ behavior: 'allow',
317
+ destination: 'localSettings',
318
+ }));
319
+ }
320
+ //# sourceMappingURL=permission-updates.js.map
@@ -0,0 +1,9 @@
1
+ export type SedSafetyResult = {
2
+ safe: true;
3
+ } | {
4
+ safe: false;
5
+ reason: string;
6
+ };
7
+ export declare function sedArgvIsReadOnly(argv: readonly string[]): boolean;
8
+ export declare function validateSedSafety(source: string, allowFileWrites: boolean): SedSafetyResult;
9
+ //# sourceMappingURL=sed-safety.d.ts.map
@@ -0,0 +1,172 @@
1
+ import { analyzeBashStructure, normalizeBashWrapperArgv } from './bash-ast.js';
2
+ function parseSedInvocation(args) {
3
+ const expressions = [];
4
+ const files = [];
5
+ const flags = [];
6
+ let standaloneExpression = false;
7
+ let optionsEnded = false;
8
+ let unsupported = false;
9
+ for (let index = 0; index < args.length; index += 1) {
10
+ const argument = args[index] ?? '';
11
+ if (!optionsEnded && argument === '--') {
12
+ optionsEnded = true;
13
+ continue;
14
+ }
15
+ if (!optionsEnded && (argument === '-e' || argument === '--expression')) {
16
+ flags.push(argument);
17
+ const expression = args[index + 1];
18
+ if (expression === undefined)
19
+ unsupported = true;
20
+ else
21
+ expressions.push(expression);
22
+ index += 1;
23
+ continue;
24
+ }
25
+ if (!optionsEnded && argument.startsWith('--expression=')) {
26
+ flags.push('--expression');
27
+ expressions.push(argument.slice('--expression='.length));
28
+ continue;
29
+ }
30
+ if (!optionsEnded && (argument === '-f' || argument === '--file')) {
31
+ unsupported = true;
32
+ index += 1;
33
+ continue;
34
+ }
35
+ if (!optionsEnded && argument.startsWith('-')) {
36
+ flags.push(argument);
37
+ continue;
38
+ }
39
+ if (expressions.length === 0 && !standaloneExpression) {
40
+ expressions.push(argument);
41
+ standaloneExpression = true;
42
+ }
43
+ else {
44
+ files.push(argument);
45
+ }
46
+ }
47
+ return { expressions, files, flags, unsupported };
48
+ }
49
+ function shortFlagsAllowed(flag, allowed) {
50
+ if (!flag.startsWith('-') || flag.startsWith('--'))
51
+ return false;
52
+ return [...flag.slice(1)].every((character) => allowed.has(character));
53
+ }
54
+ function linePrintIsSafe(invocation) {
55
+ const short = new Set(['n', 'E', 'r', 'z']);
56
+ const long = new Set([
57
+ '--quiet',
58
+ '--silent',
59
+ '--regexp-extended',
60
+ '--zero-terminated',
61
+ '--posix',
62
+ ]);
63
+ if (invocation.flags.some((flag) => !long.has(flag) && !shortFlagsAllowed(flag, short))) {
64
+ return false;
65
+ }
66
+ const hasQuiet = invocation.flags.some((flag) => flag === '--quiet' ||
67
+ flag === '--silent' ||
68
+ (!flag.startsWith('--') && flag.slice(1).includes('n')));
69
+ return (hasQuiet &&
70
+ invocation.expressions.length > 0 &&
71
+ invocation.expressions.every((expression) => expression
72
+ .split(';')
73
+ .every((part) => /^(?:\d+|\d+,\d+)?p$/u.test(part.trim()))));
74
+ }
75
+ function substitutionFlags(expression) {
76
+ if (!expression.startsWith('s/'))
77
+ return undefined;
78
+ const delimiters = [];
79
+ let escaped = false;
80
+ for (let index = 0; index < expression.length; index += 1) {
81
+ const character = expression[index] ?? '';
82
+ if (escaped) {
83
+ escaped = false;
84
+ }
85
+ else if (character === '\\') {
86
+ escaped = true;
87
+ }
88
+ else if (character === '/') {
89
+ delimiters.push(index);
90
+ }
91
+ }
92
+ if (delimiters.length !== 3 || delimiters[0] !== 1)
93
+ return undefined;
94
+ const lastDelimiter = delimiters.at(-1);
95
+ return lastDelimiter === undefined
96
+ ? undefined
97
+ : expression.slice(lastDelimiter + 1);
98
+ }
99
+ function expressionHasDangerousSyntax(expression) {
100
+ if (expression.includes('\n') ||
101
+ expression.includes('{') ||
102
+ expression.includes('}') ||
103
+ [...expression].some((character) => {
104
+ const codePoint = character.codePointAt(0) ?? 0;
105
+ return codePoint < 1 || codePoint > 127;
106
+ })) {
107
+ return true;
108
+ }
109
+ const hashIndex = expression.indexOf('#');
110
+ if (hashIndex >= 0 && !(hashIndex > 0 && expression[hashIndex - 1] === 's')) {
111
+ return true;
112
+ }
113
+ return (/^!/u.test(expression) ||
114
+ /[/\d$]!/u.test(expression) ||
115
+ /\d\s*~\s*\d|,\s*~\s*\d|\$\s*~\s*\d/u.test(expression) ||
116
+ /^,/u.test(expression) ||
117
+ /,\s*[+-]/u.test(expression) ||
118
+ /s\\|\\[|#%@]/u.test(expression) ||
119
+ /\\\/.*[wW]/u.test(expression) ||
120
+ /\/[^/]*\s+[wWeE]/u.test(expression));
121
+ }
122
+ function substitutionIsSafe(invocation, allowFileWrites) {
123
+ const short = new Set(['E', 'r', ...(allowFileWrites ? ['i'] : [])]);
124
+ const long = new Set([
125
+ '--regexp-extended',
126
+ '--posix',
127
+ ...(allowFileWrites ? ['--in-place'] : []),
128
+ ]);
129
+ if (invocation.flags.some((flag) => !long.has(flag) && !shortFlagsAllowed(flag, short))) {
130
+ return false;
131
+ }
132
+ if (!allowFileWrites && invocation.files.length > 0)
133
+ return false;
134
+ if (invocation.expressions.length !== 1)
135
+ return false;
136
+ const expression = (invocation.expressions[0] ?? '').trim();
137
+ if (expression.includes(';') || expressionHasDangerousSyntax(expression))
138
+ return false;
139
+ const flags = substitutionFlags(expression);
140
+ return flags !== undefined && /^[gpimIM]*[1-9]?[gpimIM]*$/u.test(flags);
141
+ }
142
+ export function sedArgvIsReadOnly(argv) {
143
+ if (argv[0] !== 'sed')
144
+ return false;
145
+ const invocation = parseSedInvocation(argv.slice(1));
146
+ return (!invocation.unsupported &&
147
+ (linePrintIsSafe(invocation) || substitutionIsSafe(invocation, false)));
148
+ }
149
+ export function validateSedSafety(source, allowFileWrites) {
150
+ const analysis = analyzeBashStructure(source);
151
+ if (!analysis.parsed)
152
+ return { safe: false, reason: analysis.reason };
153
+ for (const command of analysis.commands) {
154
+ const normalized = normalizeBashWrapperArgv(command.argv);
155
+ if (!normalized.ok)
156
+ return { safe: false, reason: normalized.reason };
157
+ if (normalized.argv[0] !== 'sed')
158
+ continue;
159
+ const invocation = parseSedInvocation(normalized.argv.slice(1));
160
+ const allowed = allowFileWrites
161
+ ? substitutionIsSafe(invocation, true)
162
+ : linePrintIsSafe(invocation) || substitutionIsSafe(invocation, false);
163
+ if (invocation.unsupported || !allowed) {
164
+ return {
165
+ safe: false,
166
+ reason: 'sed command requires explicit approval for potentially dangerous operations',
167
+ };
168
+ }
169
+ }
170
+ return { safe: true };
171
+ }
172
+ //# sourceMappingURL=sed-safety.js.map
@@ -0,0 +1,14 @@
1
+ export type ShellRule = {
2
+ type: 'exact';
3
+ command: string;
4
+ } | {
5
+ type: 'prefix';
6
+ prefix: string;
7
+ } | {
8
+ type: 'wildcard';
9
+ pattern: string;
10
+ };
11
+ export declare function parseShellRule(value: string): ShellRule;
12
+ export declare function shellWildcardMatches(pattern: string, command: string, caseInsensitive?: boolean): boolean;
13
+ export declare function shellRuleMatches(rule: ShellRule, command: string, caseInsensitive?: boolean): boolean;
14
+ //# sourceMappingURL=shell-rule-matching.d.ts.map
@@ -0,0 +1,76 @@
1
+ function prefixRule(value) {
2
+ const match = /^(.+):\*$/u.exec(value);
3
+ return match?.[1];
4
+ }
5
+ function unescapedStars(value) {
6
+ const indices = [];
7
+ for (let index = 0; index < value.length; index += 1) {
8
+ if (value[index] !== '*')
9
+ continue;
10
+ let slashes = 0;
11
+ for (let cursor = index - 1; cursor >= 0 && value[cursor] === '\\'; cursor -= 1) {
12
+ slashes += 1;
13
+ }
14
+ if (slashes % 2 === 0)
15
+ indices.push(index);
16
+ }
17
+ return indices;
18
+ }
19
+ export function parseShellRule(value) {
20
+ const prefix = prefixRule(value);
21
+ if (prefix !== undefined)
22
+ return { type: 'prefix', prefix };
23
+ return unescapedStars(value).length > 0
24
+ ? { type: 'wildcard', pattern: value }
25
+ : { type: 'exact', command: value };
26
+ }
27
+ function escapeRegex(value) {
28
+ return value.replace(/[|\\{}()[\]^$+?.]/gu, '\\$&');
29
+ }
30
+ export function shellWildcardMatches(pattern, command, caseInsensitive = false) {
31
+ const value = pattern.trim();
32
+ let expression = '';
33
+ let wildcardCount = 0;
34
+ for (let index = 0; index < value.length; index += 1) {
35
+ const character = value[index] ?? '';
36
+ if (character === '\\' && index + 1 < value.length) {
37
+ const next = value[index + 1];
38
+ if (next === '*' || next === '\\') {
39
+ expression += escapeRegex(next);
40
+ index += 1;
41
+ continue;
42
+ }
43
+ }
44
+ if (character === '*') {
45
+ expression += '.*';
46
+ wildcardCount += 1;
47
+ }
48
+ else {
49
+ expression += escapeRegex(character);
50
+ }
51
+ }
52
+ if (wildcardCount === 1 && expression.endsWith(' .*')) {
53
+ expression = `${expression.slice(0, -3)}(?: .*)?`;
54
+ }
55
+ return new RegExp(`^${expression}$`, caseInsensitive ? 'isu' : 'su').test(command);
56
+ }
57
+ function equal(left, right, caseInsensitive) {
58
+ return caseInsensitive
59
+ ? left.toLocaleLowerCase() === right.toLocaleLowerCase()
60
+ : left === right;
61
+ }
62
+ export function shellRuleMatches(rule, command, caseInsensitive = false) {
63
+ if (rule.type === 'exact') {
64
+ return equal(rule.command, command, caseInsensitive);
65
+ }
66
+ if (rule.type === 'wildcard') {
67
+ return shellWildcardMatches(rule.pattern, command, caseInsensitive);
68
+ }
69
+ if (equal(rule.prefix, command, caseInsensitive))
70
+ return true;
71
+ const prefix = `${rule.prefix} `;
72
+ return caseInsensitive
73
+ ? command.toLocaleLowerCase().startsWith(prefix.toLocaleLowerCase())
74
+ : command.startsWith(prefix);
75
+ }
76
+ //# sourceMappingURL=shell-rule-matching.js.map
@@ -0,0 +1,54 @@
1
+ import { type FsWriteRestrictionConfig, type SandboxDependencyCheck, type SandboxRuntimeConfig } from '@anthropic-ai/sandbox-runtime';
2
+ import type { ClaudeSandboxSettings } from './claude-sandbox-settings.js';
3
+ export type ClaudeSandboxPlatform = 'macos' | 'linux' | 'windows' | 'wsl';
4
+ export interface SandboxBackend {
5
+ initialize(config: SandboxRuntimeConfig): Promise<void>;
6
+ isSupportedPlatform(): boolean;
7
+ checkDependencies(ripgrep?: {
8
+ command: string;
9
+ args?: string[];
10
+ }): SandboxDependencyCheck;
11
+ wrapWithSandbox(command: string, shell?: string, config?: Partial<SandboxRuntimeConfig>, signal?: AbortSignal, options?: {
12
+ commandId?: string;
13
+ commandText?: string;
14
+ }): Promise<string>;
15
+ getFsWriteConfig(): FsWriteRestrictionConfig;
16
+ updateConfig(config: SandboxRuntimeConfig): void;
17
+ cleanupAfterCommand(): void;
18
+ annotateStderrWithSandboxFailures(commandId: string, stderr: string): string;
19
+ reset(): Promise<void>;
20
+ }
21
+ export interface SandboxCommandInput {
22
+ command: string;
23
+ dangerouslyDisableSandbox?: boolean;
24
+ }
25
+ export declare class ClaudeSandboxRuntime {
26
+ private readonly backend;
27
+ private readonly platform;
28
+ private active;
29
+ private initialized;
30
+ private initializationError;
31
+ private settings;
32
+ constructor(backend?: SandboxBackend, platform?: () => ClaudeSandboxPlatform);
33
+ initialize(settings: ClaudeSandboxSettings): Promise<void>;
34
+ isActive(): boolean;
35
+ isEnabledInSettings(): boolean;
36
+ isSupportedPlatform(): boolean;
37
+ platformName(): ClaudeSandboxPlatform;
38
+ dependencyCheck(settings?: ClaudeSandboxSettings): SandboxDependencyCheck;
39
+ autoAllowsBash(): boolean;
40
+ unavailableReason(settings?: ClaudeSandboxSettings): string | undefined;
41
+ shouldUseSandbox(input: SandboxCommandInput): boolean;
42
+ wrapCommand(input: SandboxCommandInput, options?: {
43
+ shell?: string;
44
+ signal?: AbortSignal;
45
+ commandId?: string;
46
+ }): Promise<string>;
47
+ annotateStderr(commandId: string, stderr: string): string;
48
+ cleanupAfterCommand(): void;
49
+ getFsWriteConfig(): FsWriteRestrictionConfig | undefined;
50
+ reset(): Promise<void>;
51
+ private requireSettings;
52
+ }
53
+ export declare const claudeSandboxRuntime: ClaudeSandboxRuntime;
54
+ //# sourceMappingURL=claude-sandbox-runtime.d.ts.map