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,386 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { basename, dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
5
|
+
import { Box, Text } from 'ink';
|
|
6
|
+
import { claudeBashPermissionRuleContent } from '../../permissions/claude-shell-permission.js';
|
|
7
|
+
import { extractPermissionRules, permissionRuleValueToString, shellPermissionSuggestions, } from '../../permissions/permission-updates.js';
|
|
8
|
+
import { redactSensitiveText } from '../../platform/sensitive-data.js';
|
|
9
|
+
import { composerEditorSegments, } from './composer-editor.js';
|
|
10
|
+
function stringInput(call, name) {
|
|
11
|
+
const value = call.input[name];
|
|
12
|
+
return typeof value === 'string' ? value : undefined;
|
|
13
|
+
}
|
|
14
|
+
function redact(value, sensitiveValues) {
|
|
15
|
+
return redactSensitiveText(value, sensitiveValues);
|
|
16
|
+
}
|
|
17
|
+
function visibleLines(value, limit = 20) {
|
|
18
|
+
const lines = value.split('\n');
|
|
19
|
+
if (lines.length <= limit)
|
|
20
|
+
return lines;
|
|
21
|
+
return [...lines.slice(0, limit), `… ${lines.length - limit} more lines`];
|
|
22
|
+
}
|
|
23
|
+
function pathIsWithin(root, path) {
|
|
24
|
+
const child = relative(resolve(root), resolve(path));
|
|
25
|
+
return child === '' || (!child.startsWith('..') && !isAbsolute(child));
|
|
26
|
+
}
|
|
27
|
+
function claudeFolderSessionOption(path, cwd) {
|
|
28
|
+
const projectClaude = resolve(cwd, '.claude');
|
|
29
|
+
const globalClaude = resolve(homedir(), '.claude');
|
|
30
|
+
const pattern = pathIsWithin(globalClaude, path)
|
|
31
|
+
? '~/.claude/**'
|
|
32
|
+
: pathIsWithin(projectClaude, path)
|
|
33
|
+
? '/.claude/**'
|
|
34
|
+
: undefined;
|
|
35
|
+
if (!pattern)
|
|
36
|
+
return undefined;
|
|
37
|
+
return {
|
|
38
|
+
action: 'allow-session-action',
|
|
39
|
+
label: 'Yes, and allow Claude to edit its own settings for this session',
|
|
40
|
+
rule: `Edit(${pattern})`,
|
|
41
|
+
updates: [
|
|
42
|
+
{
|
|
43
|
+
type: 'addRules',
|
|
44
|
+
rules: [{ toolName: 'Edit', ruleContent: pattern }],
|
|
45
|
+
behavior: 'allow',
|
|
46
|
+
destination: 'session',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function fileSessionLabel(path, cwd, readOnly) {
|
|
52
|
+
const pathRelativeToCwd = relative(cwd, path);
|
|
53
|
+
if (!pathRelativeToCwd.startsWith('..')) {
|
|
54
|
+
return readOnly
|
|
55
|
+
? 'Yes, during this session'
|
|
56
|
+
: 'Yes, allow all edits during this session (shift+tab)';
|
|
57
|
+
}
|
|
58
|
+
const directory = basename(dirname(path)) || 'this directory';
|
|
59
|
+
return readOnly
|
|
60
|
+
? `Yes, allow reading from ${directory}/ during this session`
|
|
61
|
+
: `Yes, allow all edits in ${directory}/ during this session (shift+tab)`;
|
|
62
|
+
}
|
|
63
|
+
function readSessionRule(path, cwd) {
|
|
64
|
+
const absolutePath = resolve(cwd, path);
|
|
65
|
+
const target = pathIsWithin(cwd, absolutePath)
|
|
66
|
+
? absolutePath
|
|
67
|
+
: `${dirname(absolutePath)}/**`;
|
|
68
|
+
return `Read(/${target})`;
|
|
69
|
+
}
|
|
70
|
+
function fileOptions(path, cwd, readOnly, suggestions = []) {
|
|
71
|
+
const claudeFolderOption = readOnly
|
|
72
|
+
? undefined
|
|
73
|
+
: claudeFolderSessionOption(path, cwd);
|
|
74
|
+
return [
|
|
75
|
+
{ action: 'allow-once', label: 'Yes' },
|
|
76
|
+
claudeFolderOption ?? {
|
|
77
|
+
action: readOnly ? 'allow-session-action' : 'allow-session-edits',
|
|
78
|
+
label: fileSessionLabel(path, cwd, readOnly),
|
|
79
|
+
...(readOnly ? { rule: readSessionRule(path, cwd) } : {}),
|
|
80
|
+
...(suggestions.length ? { updates: suggestions } : {}),
|
|
81
|
+
},
|
|
82
|
+
{ action: 'deny', label: 'No' },
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
function fileModel(call, cwd, sensitiveValues, decision) {
|
|
86
|
+
const path = stringInput(call, 'file_path');
|
|
87
|
+
if (!path)
|
|
88
|
+
return undefined;
|
|
89
|
+
const displayPath = redact(path, sensitiveValues);
|
|
90
|
+
const displayRelativePath = redact(relative(cwd, path), sensitiveValues);
|
|
91
|
+
if (call.name === 'Edit') {
|
|
92
|
+
const oldString = redact(stringInput(call, 'old_string') ?? '', sensitiveValues);
|
|
93
|
+
const newString = redact(stringInput(call, 'new_string') ?? '', sensitiveValues);
|
|
94
|
+
return {
|
|
95
|
+
kind: 'file',
|
|
96
|
+
title: 'Edit file',
|
|
97
|
+
subtitle: displayRelativePath,
|
|
98
|
+
question: `Do you want to make this edit to ${basename(displayPath)}?`,
|
|
99
|
+
detail: [
|
|
100
|
+
...visibleLines(oldString).map((text) => ({
|
|
101
|
+
prefix: '-',
|
|
102
|
+
text,
|
|
103
|
+
})),
|
|
104
|
+
...visibleLines(newString).map((text) => ({
|
|
105
|
+
prefix: '+',
|
|
106
|
+
text,
|
|
107
|
+
})),
|
|
108
|
+
],
|
|
109
|
+
options: fileOptions(path, cwd, false, decision?.behavior === 'ask' ? decision.suggestions : []),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (call.name === 'Write') {
|
|
113
|
+
const fileExists = existsSync(path);
|
|
114
|
+
const content = redact(stringInput(call, 'content') ?? '', sensitiveValues);
|
|
115
|
+
let oldContent = '';
|
|
116
|
+
if (fileExists) {
|
|
117
|
+
try {
|
|
118
|
+
oldContent = redact(readFileSync(path, 'utf8'), sensitiveValues);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
oldContent = '';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
kind: 'file',
|
|
126
|
+
title: fileExists ? 'Overwrite file' : 'Create file',
|
|
127
|
+
subtitle: displayRelativePath,
|
|
128
|
+
question: `Do you want to ${fileExists ? 'overwrite' : 'create'} ${basename(displayPath)}?`,
|
|
129
|
+
detail: [
|
|
130
|
+
...(fileExists
|
|
131
|
+
? visibleLines(oldContent).map((text) => ({
|
|
132
|
+
prefix: '-',
|
|
133
|
+
text,
|
|
134
|
+
}))
|
|
135
|
+
: []),
|
|
136
|
+
...visibleLines(content).map((text) => ({
|
|
137
|
+
prefix: '+',
|
|
138
|
+
text,
|
|
139
|
+
})),
|
|
140
|
+
],
|
|
141
|
+
options: fileOptions(path, cwd, false, decision?.behavior === 'ask' ? decision.suggestions : []),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
function notebookModel(call, cwd, sensitiveValues, decision) {
|
|
147
|
+
if (call.name !== 'NotebookEdit')
|
|
148
|
+
return undefined;
|
|
149
|
+
const path = stringInput(call, 'notebook_path');
|
|
150
|
+
if (!path)
|
|
151
|
+
return undefined;
|
|
152
|
+
const mode = stringInput(call, 'edit_mode') ?? 'replace';
|
|
153
|
+
const action = mode === 'insert'
|
|
154
|
+
? 'insert this cell into'
|
|
155
|
+
: mode === 'delete'
|
|
156
|
+
? 'delete this cell from'
|
|
157
|
+
: 'make this edit to';
|
|
158
|
+
const source = redact(stringInput(call, 'new_source') ?? '', sensitiveValues);
|
|
159
|
+
return {
|
|
160
|
+
kind: 'notebook',
|
|
161
|
+
title: 'Edit notebook',
|
|
162
|
+
subtitle: redact(relative(cwd, path), sensitiveValues),
|
|
163
|
+
question: `Do you want to ${action} ${basename(path)}?`,
|
|
164
|
+
detail: visibleLines(source).map((text) => ({
|
|
165
|
+
prefix: mode === 'delete' ? '-' : '+',
|
|
166
|
+
text,
|
|
167
|
+
})),
|
|
168
|
+
options: fileOptions(path, cwd, false, decision?.behavior === 'ask' ? decision.suggestions : []),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function filesystemModel(call, cwd, sensitiveValues, decision) {
|
|
172
|
+
if (!['Read', 'Glob', 'Grep'].includes(call.name))
|
|
173
|
+
return undefined;
|
|
174
|
+
const path = stringInput(call, 'file_path') ?? stringInput(call, 'path') ?? cwd;
|
|
175
|
+
const display = redact(path, sensitiveValues);
|
|
176
|
+
const argument = call.name === 'Glob'
|
|
177
|
+
? (stringInput(call, 'pattern') ?? '')
|
|
178
|
+
: call.name === 'Grep'
|
|
179
|
+
? (stringInput(call, 'pattern') ?? '')
|
|
180
|
+
: display;
|
|
181
|
+
return {
|
|
182
|
+
kind: 'filesystem',
|
|
183
|
+
title: 'Read file',
|
|
184
|
+
question: 'Do you want to proceed?',
|
|
185
|
+
detail: [{ text: `${call.name}(${redact(argument, sensitiveValues)})` }],
|
|
186
|
+
options: fileOptions(path, cwd, true, decision?.behavior === 'ask' ? decision.suggestions : []),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function webFetchModel(call, sensitiveValues) {
|
|
190
|
+
if (call.name !== 'WebFetch')
|
|
191
|
+
return undefined;
|
|
192
|
+
const rawUrl = stringInput(call, 'url') ?? '';
|
|
193
|
+
let hostname = rawUrl;
|
|
194
|
+
try {
|
|
195
|
+
hostname = new URL(rawUrl).hostname;
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
// The runtime will report malformed tool input after permission handling.
|
|
199
|
+
}
|
|
200
|
+
const prompt = stringInput(call, 'prompt');
|
|
201
|
+
const description = stringInput(call, 'description');
|
|
202
|
+
return {
|
|
203
|
+
kind: 'web-fetch',
|
|
204
|
+
title: 'Fetch',
|
|
205
|
+
...(description ? { description } : {}),
|
|
206
|
+
question: 'Do you want to allow Claude to fetch this content?',
|
|
207
|
+
detail: [
|
|
208
|
+
{ text: redact(rawUrl, sensitiveValues) },
|
|
209
|
+
...(prompt ? [{ text: redact(prompt, sensitiveValues) }] : []),
|
|
210
|
+
],
|
|
211
|
+
options: [
|
|
212
|
+
{ action: 'allow-once', label: 'Yes' },
|
|
213
|
+
{
|
|
214
|
+
action: 'persist-rule',
|
|
215
|
+
label: `Yes, and don't ask again for ${hostname}`,
|
|
216
|
+
rule: `WebFetch(domain:${hostname})`,
|
|
217
|
+
},
|
|
218
|
+
{ action: 'deny', label: 'No, and tell Claude what to do differently' },
|
|
219
|
+
],
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function bashModel(call, sensitiveValues, decision) {
|
|
223
|
+
if (call.name !== 'Bash' && call.name !== 'PowerShell')
|
|
224
|
+
return undefined;
|
|
225
|
+
const command = stringInput(call, 'command') ?? '';
|
|
226
|
+
const description = stringInput(call, 'description');
|
|
227
|
+
const displayCommand = redact(command, sensitiveValues);
|
|
228
|
+
const fallbackRuleContent = call.name === 'Bash' ? claudeBashPermissionRuleContent(command) : command;
|
|
229
|
+
const suggestions = decision?.behavior === 'ask' && decision.suggestions?.length
|
|
230
|
+
? decision.suggestions
|
|
231
|
+
: shellPermissionSuggestions(call.name, command);
|
|
232
|
+
const suggestedRules = extractPermissionRules(suggestions);
|
|
233
|
+
const shellRules = suggestedRules.filter((rule) => rule.toolName === call.name);
|
|
234
|
+
const hasNonShellSuggestions = suggestions.some((update) => update.type === 'addDirectories' ||
|
|
235
|
+
(update.type === 'addRules' &&
|
|
236
|
+
update.rules.some((rule) => rule.toolName !== call.name)));
|
|
237
|
+
const editableRuleContent = !hasNonShellSuggestions && shellRules.length === 1
|
|
238
|
+
? shellRules[0]?.ruleContent
|
|
239
|
+
: undefined;
|
|
240
|
+
const ruleContent = editableRuleContent ?? fallbackRuleContent;
|
|
241
|
+
const rule = `${call.name}(${ruleContent})`;
|
|
242
|
+
const persistentOption = call.name === 'PowerShell' && command.includes('\n')
|
|
243
|
+
? undefined
|
|
244
|
+
: {
|
|
245
|
+
action: 'persist-rule',
|
|
246
|
+
label: shellRules.length > 1
|
|
247
|
+
? `Yes, and don’t ask again for ${shellRules
|
|
248
|
+
.map(permissionRuleValueToString)
|
|
249
|
+
.join(', ')}`
|
|
250
|
+
: 'Yes, and don’t ask again for',
|
|
251
|
+
...(shellRules.length === 1 ? { rule } : {}),
|
|
252
|
+
updates: suggestions,
|
|
253
|
+
...(editableRuleContent === undefined
|
|
254
|
+
? {}
|
|
255
|
+
: {
|
|
256
|
+
editableRule: {
|
|
257
|
+
toolName: call.name,
|
|
258
|
+
initialValue: editableRuleContent,
|
|
259
|
+
},
|
|
260
|
+
}),
|
|
261
|
+
};
|
|
262
|
+
return {
|
|
263
|
+
kind: 'bash',
|
|
264
|
+
title: call.name === 'Bash' ? 'Bash command' : 'PowerShell command',
|
|
265
|
+
...(description
|
|
266
|
+
? { description: redact(description, sensitiveValues) }
|
|
267
|
+
: {}),
|
|
268
|
+
question: 'Do you want to proceed?',
|
|
269
|
+
detail: visibleLines(displayCommand).map((text) => ({ text })),
|
|
270
|
+
options: [
|
|
271
|
+
{ action: 'allow-once', label: 'Yes' },
|
|
272
|
+
...(persistentOption ? [persistentOption] : []),
|
|
273
|
+
{ action: 'deny', label: 'No' },
|
|
274
|
+
],
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
export function projectTuiToolPermission(call, cwd, sensitiveValues, decision) {
|
|
278
|
+
const explain = (model) => decision?.behavior === 'ask' && decision.reason
|
|
279
|
+
? {
|
|
280
|
+
...model,
|
|
281
|
+
explanation: redact(decision.reason, sensitiveValues),
|
|
282
|
+
}
|
|
283
|
+
: model;
|
|
284
|
+
const specialized = bashModel(call, sensitiveValues, decision) ??
|
|
285
|
+
fileModel(call, cwd, sensitiveValues, decision) ??
|
|
286
|
+
notebookModel(call, cwd, sensitiveValues, decision) ??
|
|
287
|
+
filesystemModel(call, cwd, sensitiveValues, decision) ??
|
|
288
|
+
webFetchModel(call, sensitiveValues);
|
|
289
|
+
if (specialized)
|
|
290
|
+
return explain(specialized);
|
|
291
|
+
const skill = stringInput(call, 'skill') ?? stringInput(call, 'name');
|
|
292
|
+
if (call.name === 'Skill' && skill) {
|
|
293
|
+
const suggestions = decision?.behavior === 'ask' ? (decision.suggestions ?? []) : [];
|
|
294
|
+
const suggestedOptions = suggestions.flatMap((update) => {
|
|
295
|
+
if (update.type !== 'addRules')
|
|
296
|
+
return [];
|
|
297
|
+
return update.rules.flatMap((value) => {
|
|
298
|
+
if (value.toolName !== 'Skill')
|
|
299
|
+
return [];
|
|
300
|
+
const rule = permissionRuleValueToString(value);
|
|
301
|
+
const prefix = value.ruleContent?.endsWith(':*') === true;
|
|
302
|
+
return [
|
|
303
|
+
{
|
|
304
|
+
action: 'persist-rule',
|
|
305
|
+
label: prefix
|
|
306
|
+
? `Yes, and don't ask again for ${value.ruleContent} commands in ${cwd}`
|
|
307
|
+
: `Yes, and don't ask again for ${skill} in ${cwd}`,
|
|
308
|
+
rule,
|
|
309
|
+
updates: [
|
|
310
|
+
{
|
|
311
|
+
...update,
|
|
312
|
+
rules: [value],
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
},
|
|
316
|
+
];
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
return explain({
|
|
320
|
+
kind: 'skill',
|
|
321
|
+
title: `Use skill "${redact(skill, sensitiveValues)}"?`,
|
|
322
|
+
question: 'Claude may use instructions, code, or files from this Skill.',
|
|
323
|
+
detail: [],
|
|
324
|
+
options: [
|
|
325
|
+
{ action: 'allow-once', label: 'Yes' },
|
|
326
|
+
...(suggestedOptions.length
|
|
327
|
+
? suggestedOptions
|
|
328
|
+
: [
|
|
329
|
+
{
|
|
330
|
+
action: 'persist-rule',
|
|
331
|
+
label: `Yes, and don't ask again for ${skill} in ${cwd}`,
|
|
332
|
+
rule: `Skill(${skill})`,
|
|
333
|
+
},
|
|
334
|
+
...(skill.includes(' ')
|
|
335
|
+
? [
|
|
336
|
+
{
|
|
337
|
+
action: 'persist-rule',
|
|
338
|
+
label: `Yes, and don't ask again for ${skill.split(' ', 1)[0]}:* commands in ${cwd}`,
|
|
339
|
+
rule: `Skill(${skill.split(' ', 1)[0]}:*)`,
|
|
340
|
+
},
|
|
341
|
+
]
|
|
342
|
+
: []),
|
|
343
|
+
]),
|
|
344
|
+
{ action: 'deny', label: 'No' },
|
|
345
|
+
],
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
const serialized = redact(JSON.stringify(call.input), sensitiveValues);
|
|
349
|
+
return explain({
|
|
350
|
+
kind: 'generic',
|
|
351
|
+
title: 'Tool use',
|
|
352
|
+
question: 'Do you want to proceed?',
|
|
353
|
+
detail: [{ text: `${redact(call.name, sensitiveValues)}(${serialized})` }],
|
|
354
|
+
options: [
|
|
355
|
+
{ action: 'allow-once', label: 'Yes' },
|
|
356
|
+
{
|
|
357
|
+
action: 'persist-rule',
|
|
358
|
+
label: `Yes, and don't ask again for ${call.name} commands in ${cwd}`,
|
|
359
|
+
rule: call.name,
|
|
360
|
+
},
|
|
361
|
+
{ action: 'deny', label: 'No' },
|
|
362
|
+
],
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
export function ToolPermissionDialog({ model, selection, feedbackMode, feedback, ruleEditor, screenReader, }) {
|
|
366
|
+
return (_jsxs(Box, { flexDirection: "column", borderStyle: screenReader ? undefined : 'round', borderColor: "yellow", paddingX: screenReader ? 0 : 1, marginTop: 1, children: [_jsx(Text, { bold: true, children: model.title }), model.subtitle ? _jsx(Text, { dimColor: true, children: model.subtitle }) : null, _jsxs(Box, { flexDirection: "column", paddingX: 1, paddingY: 1, children: [model.detail.map((line, index) => {
|
|
367
|
+
const content = `${line.prefix ? `${line.prefix} ` : ''}${line.text}`;
|
|
368
|
+
return line.prefix ? (_jsx(Text, { color: line.prefix === '+' ? 'green' : 'red', children: content }, `${index}-${line.prefix}`)) : (_jsx(Text, { children: content }, `${index}-`));
|
|
369
|
+
}), model.description ? _jsx(Text, { dimColor: true, children: model.description }) : null] }), model.explanation ? _jsx(Text, { dimColor: true, children: model.explanation }) : null, _jsx(Text, { children: model.question }), model.options.map((option, index) => {
|
|
370
|
+
const selected = selection === index;
|
|
371
|
+
const editor = option.editableRule
|
|
372
|
+
? (ruleEditor ?? {
|
|
373
|
+
text: option.editableRule.initialValue,
|
|
374
|
+
cursor: Array.from(option.editableRule.initialValue).length,
|
|
375
|
+
})
|
|
376
|
+
: null;
|
|
377
|
+
const segments = editor ? composerEditorSegments(editor) : null;
|
|
378
|
+
return (_jsxs(Text, { bold: selected, children: [selected ? (screenReader ? 'Selected: ' : '❯ ') : ' ', index + 1, ". ", option.label, segments ? (screenReader || !selected ? (`: ${editor?.text ?? ''}`) : (_jsxs(Text, { children: [": ", segments.before, _jsx(Text, { inverse: true, children: segments.current ?? ' ' }), segments.after] }))) : null] }, `${option.action}-${index}`));
|
|
379
|
+
}), feedbackMode ? (_jsxs(Text, { children: ["\u203A", ' ', feedback ||
|
|
380
|
+
(model.options[selection]?.action === 'deny'
|
|
381
|
+
? 'tell Praxis what to do differently'
|
|
382
|
+
: 'tell Praxis what to do next')] })) : null, _jsx(Text, { dimColor: true, children: feedbackMode
|
|
383
|
+
? 'Enter to submit · Tab to collapse · Esc to cancel'
|
|
384
|
+
: 'Esc to cancel · Tab to amend' })] }));
|
|
385
|
+
}
|
|
386
|
+
//# sourceMappingURL=tool-permission.js.map
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { type ForkResult, type ManualCompactResult, type ManualCompactSelection, type RewindPoint, type SessionForkCheckpoint, type SessionInspection, type SessionRunResult, type SessionSummary, type SideQuestionForkResult, type SideQuestionResult } from './application/session-service.js';
|
|
3
3
|
import type { ClaudeDisplayTranscriptItem } from './compatibility/claude/projection.js';
|
|
4
|
-
import { type ModelDocument, type ModelImage, type ModelProvider, type ModelToolCall, type PermissionApproval, type ToolRegistry, type RuntimeEventSink } from './core/runtime.js';
|
|
4
|
+
import { type ModelDocument, type ModelImage, type ModelProvider, type ModelToolCall, type PermissionApproval, type PermissionDecision, type ToolRegistry, type RuntimeEventSink } from './core/runtime.js';
|
|
5
5
|
import type { InteractiveResumeOptions, InteractiveServiceFactory } from './cli/interactive.js';
|
|
6
6
|
import type { TuiSlashCommand } from './cli/tui/slash-commands.js';
|
|
7
7
|
import { type TuiHookConfiguration } from './cli/tui/hook-settings.js';
|
|
@@ -101,7 +101,7 @@ export interface CliDependencies extends InteractiveServiceFactory {
|
|
|
101
101
|
requireProvider: boolean;
|
|
102
102
|
hooksOnly?: boolean;
|
|
103
103
|
approveRecovery?: (call: ModelToolCall) => boolean | Promise<boolean>;
|
|
104
|
-
approveTool?: (call: ModelToolCall, originalCall?: ModelToolCall) => PermissionApproval | Promise<PermissionApproval>;
|
|
104
|
+
approveTool?: (call: ModelToolCall, originalCall?: ModelToolCall, decision?: PermissionDecision) => PermissionApproval | Promise<PermissionApproval>;
|
|
105
105
|
agent?: string;
|
|
106
106
|
model?: string;
|
|
107
107
|
effort?: CliControls['effort'];
|
|
@@ -114,6 +114,7 @@ export interface CliDependencies extends InteractiveServiceFactory {
|
|
|
114
114
|
exposeToolRegistry?: boolean;
|
|
115
115
|
emitToolUseSummaries?: boolean;
|
|
116
116
|
cwd?: string;
|
|
117
|
+
sandboxOriginalCwd?: string;
|
|
117
118
|
configRoot?: string;
|
|
118
119
|
environment?: Readonly<Record<string, string>>;
|
|
119
120
|
providerEnvironment?: NodeJS.ProcessEnv;
|
package/dist/cli.js
CHANGED
|
@@ -13,6 +13,7 @@ import { createClaudePrSessionFilter, filterClaudePrLinkedSessions, } from './co
|
|
|
13
13
|
import { isClaudeSessionId, resolveClaudePaths, } from './compatibility/claude/paths.js';
|
|
14
14
|
import { loadClaudeContextResources, loadClaudeSettings, loadClaudeSharedResources, resolveClaudeProjectMemoryDirectory, } from './compatibility/claude/shared-resources.js';
|
|
15
15
|
import { AgentRunCancelledError, } from './core/runtime.js';
|
|
16
|
+
import { persistTuiPermissionUpdates } from './cli/tui/permission-settings.js';
|
|
16
17
|
import { projectTuiHooks, } from './cli/tui/hook-settings.js';
|
|
17
18
|
import { DEFAULT_CLI_CONTROLS, resolveCliControls } from './cli/controls.js';
|
|
18
19
|
import { applyRuntimeSettingDefaults, loadRuntimeSettings, runtimeSettingsSystemPrompt, } from './cli/tui/runtime-settings.js';
|
|
@@ -42,6 +43,8 @@ import { FilteredToolRegistry } from './tools/filtered-tool-registry.js';
|
|
|
42
43
|
import { WebToolRegistry } from './tools/web.js';
|
|
43
44
|
import { WorkspaceContext } from './application/session-worktree.js';
|
|
44
45
|
import { launchTmuxWorktree } from './platform/tmux-worktree.js';
|
|
46
|
+
import { claudeSandboxRuntime } from './sandbox/claude-sandbox-runtime.js';
|
|
47
|
+
import { claudeSandboxTempDirectory, loadClaudeSandboxSettings, } from './sandbox/claude-sandbox-settings.js';
|
|
45
48
|
import { createErrorResult, createSuccessResult, parseCliInvocation, readStreamJsonMessages, StreamJsonOutput, } from './cli/protocol.js';
|
|
46
49
|
import { describeClaudePlugin, initClaudePlugin, installClaudePlugin, loadClaudePlugins, readPluginRegistry, setClaudePluginEnabled, uninstallClaudePlugin, updateClaudePlugin, validateClaudePlugin, } from './plugins/claude-plugin-runtime.js';
|
|
47
50
|
import { addClaudeMarketplace, disableAllNativePlugins, installClaudeMarketplacePlugin, listClaudeMarketplaceAvailablePlugins, listNativePluginRecords, readClaudeKnownMarketplaces, removeClaudeMarketplace, setNativePluginEnabled, saveClaudePluginConfig, uninstallNativePlugin, updateClaudeMarketplace, updateNativePlugin, validateClaudeMarketplace, } from './plugins/claude-plugin-marketplace.js';
|
|
@@ -687,8 +690,9 @@ const consoleIO = {
|
|
|
687
690
|
isTTY: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
688
691
|
readStdinLines: () => process.stdin,
|
|
689
692
|
};
|
|
690
|
-
const createDefaultService = async ({ eventSink, requireProvider, hooksOnly = false, approveRecovery, approveTool, agent, model: interactiveModel, effort: interactiveEffort, permissionMode: interactivePermissionMode, isSessionActionApproved, controls = DEFAULT_CLI_CONTROLS, interactive = false, sessionKind, signal, exposeToolRegistry = false, onElicitation, askUser, approvePlan, emitToolUseSummaries = false, cwd: requestedCwd, configRoot: requestedConfigRoot, environment, providerEnvironment: requestedProviderEnvironment, }) => {
|
|
693
|
+
const createDefaultService = async ({ eventSink, requireProvider, hooksOnly = false, approveRecovery, approveTool, agent, model: interactiveModel, effort: interactiveEffort, permissionMode: interactivePermissionMode, isSessionActionApproved, controls = DEFAULT_CLI_CONTROLS, interactive = false, sessionKind, signal, exposeToolRegistry = false, onElicitation, askUser, approvePlan, emitToolUseSummaries = false, cwd: requestedCwd, sandboxOriginalCwd, configRoot: requestedConfigRoot, environment, providerEnvironment: requestedProviderEnvironment, }) => {
|
|
691
694
|
const runtimeEnvironment = requestedProviderEnvironment ?? process.env;
|
|
695
|
+
const sandboxEnvironment = { ...runtimeEnvironment, ...environment };
|
|
692
696
|
const claudeVersion = await detectInstalledClaudeVersion();
|
|
693
697
|
const cwd = requestedCwd ?? process.cwd();
|
|
694
698
|
const workspace = new WorkspaceContext(cwd);
|
|
@@ -936,12 +940,49 @@ const createDefaultService = async ({ eventSink, requireProvider, hooksOnly = fa
|
|
|
936
940
|
? {}
|
|
937
941
|
: { settingSources: automaticSettingSources }),
|
|
938
942
|
});
|
|
943
|
+
const exposePlanDirectory = interactive &&
|
|
944
|
+
askUser !== undefined &&
|
|
945
|
+
approvePlan !== undefined &&
|
|
946
|
+
['EnterPlanMode', 'ExitPlanMode'].some((name) => (cli.tools === undefined ||
|
|
947
|
+
cli.tools.includes('default') ||
|
|
948
|
+
cli.tools.includes(name)) &&
|
|
949
|
+
!cli.disallowedTools.includes(name));
|
|
950
|
+
const initialAdditionalDirectories = [
|
|
951
|
+
...cli.additionalDirectories,
|
|
952
|
+
...(exposePlanDirectory ? [resolve(configRoot, 'plans')] : []),
|
|
953
|
+
];
|
|
954
|
+
const sandboxSettings = loadClaudeSandboxSettings({
|
|
955
|
+
resources: settings.filter((resource) => resource.plugin !== true),
|
|
956
|
+
cwd: workspace.cwd(),
|
|
957
|
+
originalCwd: sandboxOriginalCwd ?? workspace.cwd(),
|
|
958
|
+
configRoot,
|
|
959
|
+
homeDirectory: sandboxEnvironment.HOME ?? sandboxEnvironment.USERPROFILE ?? homedir(),
|
|
960
|
+
additionalDirectories: initialAdditionalDirectories,
|
|
961
|
+
tempDirectory: claudeSandboxTempDirectory(sandboxEnvironment),
|
|
962
|
+
});
|
|
963
|
+
await claudeSandboxRuntime.initialize(sandboxSettings);
|
|
964
|
+
const sandboxUnavailableReason = claudeSandboxRuntime.unavailableReason();
|
|
965
|
+
if (sandboxUnavailableReason && !sandboxSettings.failIfUnavailable) {
|
|
966
|
+
runtimeEventSink({ type: 'warning', message: sandboxUnavailableReason });
|
|
967
|
+
}
|
|
968
|
+
const permissionAdditionalDirectories = [
|
|
969
|
+
...new Set([
|
|
970
|
+
...initialAdditionalDirectories,
|
|
971
|
+
...controls.addDirectories.map((directory) => resolve(cwd, directory)),
|
|
972
|
+
...(memoryDirectory ? [memoryDirectory] : []),
|
|
973
|
+
]),
|
|
974
|
+
];
|
|
975
|
+
const initialAdditionalReadDirectories = [claudeBackgroundTaskParent(cwd)];
|
|
939
976
|
const permissionResolverForMode = (permissionMode) => new ClaudeExtensionPermissionResolver(new ClaudePermissionResolver({
|
|
940
977
|
cwd,
|
|
941
978
|
cwdProvider: () => workspace.cwd(),
|
|
979
|
+
configRoot,
|
|
942
980
|
settings,
|
|
943
981
|
allowedTools: cli.allowedTools,
|
|
944
982
|
disallowedTools: cli.disallowedTools,
|
|
983
|
+
additionalDirectories: permissionAdditionalDirectories,
|
|
984
|
+
additionalReadDirectories: initialAdditionalReadDirectories,
|
|
985
|
+
sandbox: claudeSandboxRuntime,
|
|
945
986
|
permissionMode,
|
|
946
987
|
...(isSessionActionApproved ? { isSessionActionApproved } : {}),
|
|
947
988
|
...(permissionMode === 'auto'
|
|
@@ -949,25 +990,16 @@ const createDefaultService = async ({ eventSink, requireProvider, hooksOnly = fa
|
|
|
949
990
|
autoClassifier: createClaudeModelAutoClassifier(hostedToolProvider),
|
|
950
991
|
}
|
|
951
992
|
: {}),
|
|
952
|
-
}));
|
|
993
|
+
}), extensions);
|
|
953
994
|
const permissions = permissionResolverForMode(cli.dangerouslySkipPermissions ? 'bypassPermissions' : cli.permissionMode);
|
|
954
|
-
const exposePlanDirectory = interactive &&
|
|
955
|
-
askUser !== undefined &&
|
|
956
|
-
approvePlan !== undefined &&
|
|
957
|
-
['EnterPlanMode', 'ExitPlanMode'].some((name) => (cli.tools === undefined ||
|
|
958
|
-
cli.tools.includes('default') ||
|
|
959
|
-
cli.tools.includes(name)) &&
|
|
960
|
-
!cli.disallowedTools.includes(name));
|
|
961
995
|
const localTools = new LocalToolRegistry({
|
|
962
996
|
cwd,
|
|
963
997
|
cwdProvider: () => workspace.cwd(),
|
|
964
998
|
enableReportFindings: exposeToolRegistry,
|
|
965
999
|
...(memoryDirectory ? { sharedMemoryDirectory: memoryDirectory } : {}),
|
|
966
|
-
additionalDirectories:
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
],
|
|
970
|
-
additionalReadDirectories: [claudeBackgroundTaskParent(cwd)],
|
|
1000
|
+
additionalDirectories: initialAdditionalDirectories,
|
|
1001
|
+
additionalReadDirectories: initialAdditionalReadDirectories,
|
|
1002
|
+
sandbox: claudeSandboxRuntime,
|
|
971
1003
|
...(environment ? { environment } : {}),
|
|
972
1004
|
});
|
|
973
1005
|
const runtimeMcpResources = async (candidates) => {
|
|
@@ -1167,6 +1199,11 @@ const createDefaultService = async ({ eventSink, requireProvider, hooksOnly = fa
|
|
|
1167
1199
|
mcp: mcpTools,
|
|
1168
1200
|
permissions,
|
|
1169
1201
|
permissionResolverForMode,
|
|
1202
|
+
persistPermissionUpdates: (updates) => persistTuiPermissionUpdates({
|
|
1203
|
+
cwd: workspace.cwd(),
|
|
1204
|
+
configRoot,
|
|
1205
|
+
updates,
|
|
1206
|
+
}),
|
|
1170
1207
|
extensions,
|
|
1171
1208
|
enableSubagents,
|
|
1172
1209
|
subagentToolNames: routedSubagentTools,
|
|
@@ -1448,6 +1485,7 @@ const defaultPluginEvalRuntimeFactory = {
|
|
|
1448
1485
|
USERPROFILE: options.home,
|
|
1449
1486
|
},
|
|
1450
1487
|
providerEnvironment: process.env,
|
|
1488
|
+
isSessionActionApproved: (call) => options.allowedTools.includes(call.name),
|
|
1451
1489
|
controls: {
|
|
1452
1490
|
...DEFAULT_CLI_CONTROLS,
|
|
1453
1491
|
sessionPersistence: false,
|
|
@@ -1553,6 +1591,7 @@ const defaultDependencies = {
|
|
|
1553
1591
|
createService: ({ additionalDirectories, cwd, ...options }) => createDefaultService({
|
|
1554
1592
|
...options,
|
|
1555
1593
|
...(cwd === undefined ? {} : { cwd }),
|
|
1594
|
+
sandboxOriginalCwd: process.cwd(),
|
|
1556
1595
|
...(agent === undefined ? {} : { agent }),
|
|
1557
1596
|
controls: {
|
|
1558
1597
|
...interactiveControls,
|
package/dist/core/runtime.d.ts
CHANGED
|
@@ -293,6 +293,10 @@ export interface ToolExecutionContext {
|
|
|
293
293
|
messages?: readonly ModelMessage[];
|
|
294
294
|
signal?: AbortSignal;
|
|
295
295
|
toolResultDirectory?: string;
|
|
296
|
+
originalCall?: ModelToolCall;
|
|
297
|
+
permissionUpdates?: readonly PermissionUpdate[];
|
|
298
|
+
permissionPhase?: 'request' | 'execute';
|
|
299
|
+
permissionApproved?: boolean;
|
|
296
300
|
}
|
|
297
301
|
export interface ToolRegistry {
|
|
298
302
|
definitions(): readonly ModelToolDefinition[];
|
|
@@ -300,9 +304,46 @@ export interface ToolRegistry {
|
|
|
300
304
|
execute(call: ModelToolCall, context: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
301
305
|
}
|
|
302
306
|
export type PermissionBehavior = 'allow' | 'ask' | 'deny';
|
|
307
|
+
export type PermissionMode = 'acceptEdits' | 'auto' | 'bypassPermissions' | 'manual' | 'dontAsk' | 'plan' | 'default';
|
|
308
|
+
export type PermissionUpdateDestination = 'userSettings' | 'projectSettings' | 'localSettings' | 'session' | 'cliArg';
|
|
309
|
+
export type PermissionUpdateMode = Exclude<PermissionMode, 'auto' | 'manual'>;
|
|
310
|
+
export interface PermissionRuleValue {
|
|
311
|
+
toolName: string;
|
|
312
|
+
ruleContent?: string;
|
|
313
|
+
}
|
|
314
|
+
export type PermissionUpdate = {
|
|
315
|
+
type: 'addRules';
|
|
316
|
+
rules: readonly PermissionRuleValue[];
|
|
317
|
+
behavior: PermissionBehavior;
|
|
318
|
+
destination: PermissionUpdateDestination;
|
|
319
|
+
} | {
|
|
320
|
+
type: 'replaceRules';
|
|
321
|
+
rules: readonly PermissionRuleValue[];
|
|
322
|
+
behavior: PermissionBehavior;
|
|
323
|
+
destination: PermissionUpdateDestination;
|
|
324
|
+
} | {
|
|
325
|
+
type: 'removeRules';
|
|
326
|
+
rules: readonly PermissionRuleValue[];
|
|
327
|
+
behavior: PermissionBehavior;
|
|
328
|
+
destination: PermissionUpdateDestination;
|
|
329
|
+
} | {
|
|
330
|
+
type: 'setMode';
|
|
331
|
+
mode: PermissionUpdateMode;
|
|
332
|
+
destination: PermissionUpdateDestination;
|
|
333
|
+
} | {
|
|
334
|
+
type: 'addDirectories';
|
|
335
|
+
directories: readonly string[];
|
|
336
|
+
destination: PermissionUpdateDestination;
|
|
337
|
+
} | {
|
|
338
|
+
type: 'removeDirectories';
|
|
339
|
+
directories: readonly string[];
|
|
340
|
+
destination: PermissionUpdateDestination;
|
|
341
|
+
};
|
|
303
342
|
export type PermissionApproval = boolean | {
|
|
304
343
|
behavior: 'allow';
|
|
305
344
|
updatedInput?: Record<string, unknown>;
|
|
345
|
+
updatedPermissions?: readonly PermissionUpdate[];
|
|
346
|
+
feedback?: string;
|
|
306
347
|
} | {
|
|
307
348
|
behavior: 'deny';
|
|
308
349
|
message: string;
|
|
@@ -312,6 +353,9 @@ export interface PermissionResolutionContext {
|
|
|
312
353
|
cwd: string;
|
|
313
354
|
messages?: readonly ModelMessage[];
|
|
314
355
|
signal?: AbortSignal;
|
|
356
|
+
toolResultDirectory?: string;
|
|
357
|
+
originalCall?: ModelToolCall;
|
|
358
|
+
permissionUpdates?: readonly PermissionUpdate[];
|
|
315
359
|
}
|
|
316
360
|
export type PermissionDecisionSource = 'auto-classifier' | 'rule' | 'mode' | 'default';
|
|
317
361
|
export type AutoModePermissionOutcome = 'blocked' | 'unavailable';
|
|
@@ -321,6 +365,8 @@ export type PermissionDecision = {
|
|
|
321
365
|
} | {
|
|
322
366
|
behavior: 'ask';
|
|
323
367
|
reason?: string;
|
|
368
|
+
suggestions?: readonly PermissionUpdate[];
|
|
369
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
324
370
|
source?: PermissionDecisionSource;
|
|
325
371
|
} | {
|
|
326
372
|
behavior: 'deny';
|
|
@@ -369,7 +415,9 @@ export interface AgentRunRequest {
|
|
|
369
415
|
toolResultDirectory?: string;
|
|
370
416
|
observer?: AgentRunObserver;
|
|
371
417
|
reloadMessages?: () => Promise<readonly ModelMessage[]>;
|
|
372
|
-
approveTool?: (call: ModelToolCall, originalCall?: ModelToolCall) => PermissionApproval | Promise<PermissionApproval>;
|
|
418
|
+
approveTool?: (call: ModelToolCall, originalCall?: ModelToolCall, decision?: PermissionDecision) => PermissionApproval | Promise<PermissionApproval>;
|
|
419
|
+
permissionUpdates?: readonly PermissionUpdate[];
|
|
420
|
+
onPermissionUpdates?: (updates: readonly PermissionUpdate[]) => void | Promise<void>;
|
|
373
421
|
onStop?: (text: string) => Promise<readonly string[] | {
|
|
374
422
|
messages: readonly string[];
|
|
375
423
|
usage?: ModelUsage;
|
|
@@ -381,7 +429,7 @@ export interface AgentRunRequest {
|
|
|
381
429
|
maxModelTurns?: number;
|
|
382
430
|
betas?: readonly string[];
|
|
383
431
|
}
|
|
384
|
-
export interface AgentToolRecoveryRequest extends Pick<AgentRunRequest, 'approveTool' | 'cwd' | 'observer' | 'signal' | 'toolResultDirectory'> {
|
|
432
|
+
export interface AgentToolRecoveryRequest extends Pick<AgentRunRequest, 'approveTool' | 'cwd' | 'observer' | 'onPermissionUpdates' | 'permissionUpdates' | 'signal' | 'toolResultDirectory'> {
|
|
385
433
|
approveRecovery?: (call: ModelToolCall) => boolean | Promise<boolean>;
|
|
386
434
|
messages?: readonly ModelMessage[];
|
|
387
435
|
}
|