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
@@ -6,8 +6,9 @@ import { homedir, tmpdir } from 'node:os';
6
6
  import { join, resolve } from 'node:path';
7
7
  import { useEffect, useMemo, useRef, useState } from 'react';
8
8
  import { Box, Text, render, useApp, useInput } from 'ink';
9
+ import { permissionRuleValueToString } from '../permissions/permission-updates.js';
9
10
  import { AgentRunCancelledError } from '../core/runtime.js';
10
- import { claudePermissionActionKey, } from '../permissions/claude-permission-resolver.js';
11
+ import { claudePermissionActionKey, claudePermissionRuleMatches, } from '../permissions/claude-permission-resolver.js';
11
12
  import { redactSensitiveText, sensitiveEnvironmentValues, } from '../platform/sensitive-data.js';
12
13
  import { CommandPalette, BtwPanel, Composer, DiffDashboard, DialogFrame, ExternalEditorWait, HelpMenu, HookDashboard, ListDashboard, MemoryDashboard, MentionPicker, ModelMenu, PermissionDashboard, SelectionMenu, SessionPicker, ThemePicker, CustomThemeEditor, Transcript, WelcomePanel, useTerminalWidth, } from './tui/claude-style.js';
13
14
  import { loadTuiMemoryFiles, openTuiMemoryFolder, } from './tui/memory-files.js';
@@ -15,7 +16,7 @@ import { loadGitDiff, visiblePatchLines, } from './tui/git-diff.js';
15
16
  import { addTuiPermissionRule, loadTuiPermissionRules, removeTuiPermissionRule, } from './tui/permission-settings.js';
16
17
  import { createRecentlyDeniedStore, } from './tui/recently-denied.js';
17
18
  import { filterTuiSlashCommands, mergeTuiSlashCommands, slashCommandQuery, } from './tui/slash-commands.js';
18
- import { createComposerEditor, deleteComposerToEnd, deleteComposerToStart, deleteComposerWordBackward, insertComposerText, moveComposerCursorByWord, } from './tui/composer-editor.js';
19
+ import { createComposerEditor, deleteComposerBackward, deleteComposerForward, deleteComposerToEnd, deleteComposerToStart, deleteComposerWordBackward, insertComposerText, moveComposerCursor, moveComposerCursorByWord, } from './tui/composer-editor.js';
19
20
  import { applyMentionReference, fileReferenceAtCursor, filterTuiMentionEntries, loadTuiFileEntries, } from './tui/file-picker.js';
20
21
  import { editTuiPrompt, openTuiEditorFile, } from './tui/external-editor.js';
21
22
  import { suspendTuiProcess } from './tui/terminal-suspend.js';
@@ -28,7 +29,12 @@ import { loadTuiThemeSettings, saveTuiThemeSettings, themeSettingsWithCustomThem
28
29
  import { DEFAULT_TUI_THEME_SETTINGS, TUI_THEMES, TuiThemeProvider, tuiPalette, } from './tui/theme.js';
29
30
  import { CUSTOM_THEME_TOKENS, createTuiCustomTheme, deleteTuiCustomTheme, loadTuiCustomThemes, updateTuiCustomTheme, } from './tui/custom-themes.js';
30
31
  import { setupTuiTerminal, terminalSetupTuiSlashCommand, } from './tui/terminal-setup.js';
32
+ import { commitElicitationText, createTuiElicitationForm, elicitationFormIsValid, elicitationTextValue, expandElicitationOptions, focusedElicitationField, McpElicitationForm, McpElicitationUrl, moveElicitationFocus, moveElicitationOption, selectElicitationOption, toggleElicitationBoolean, typeaheadElicitationOption, unsetElicitationField, validateTuiElicitationForm, } from './tui/mcp-elicitation.js';
33
+ import { openTuiUrl } from './tui/open-url.js';
34
+ import { projectTuiToolPermission, ToolPermissionDialog, } from './tui/tool-permission.js';
31
35
  import { ConfigDashboard, projectConfigRows } from './tui/config-dashboard.js';
36
+ import { SandboxDashboard, tuiSandboxTabs } from './tui/sandbox-dashboard.js';
37
+ import { createTuiSandboxStore, } from './tui/sandbox-settings.js';
32
38
  import { loadConfigSettings, saveConfigSetting, configSettingDefinition, resolveConfigSettingsLocation, } from './tui/config-settings.js';
33
39
  import { projectRuntimeSettings, loadRuntimeSettings, } from './tui/runtime-settings.js';
34
40
  import { autoUpdateTarget, copyCandidates, externalEditorInitialContent, formatTurnDuration, questionTimeoutMilliseconds, sessionRecap, spinnerTip, shouldShowCopyPicker, } from './tui/runtime-interactions.js';
@@ -228,7 +234,18 @@ function ordinal(value) {
228
234
  return `${value}th`;
229
235
  }
230
236
  }
231
- export function InteractiveApp({ factory, initialSessions, initialPrompt, initialHistory = [], signal, onCancel, onTurnChange, onCleanup, onRendererChange, onBackground, axScreenReader = false, allowNewSession = true, resume, display = { version: 'dev', cwd: process.cwd() }, terminalWidth, slashCommands = EMPTY_SLASH_COMMANDS, agents = EMPTY_AGENTS, allowDangerouslySkipPermissions = false, additionalDirectories = [], diffLoader, fileLoader, externalEditor = editTuiPrompt, keybindingsConfigRoot, keybindingsFile = ensureTuiKeybindingsFile, keybindingsLoader = loadTuiKeybindings, keybindingsEditor = openTuiEditorFile, memoryFilesLoader = (configRoot, cwd) => loadTuiMemoryFiles({ configRoot, cwd }), memoryEditor = openTuiEditorFile, memoryFolderOpener = openTuiMemoryFolder, suspendProcess = suspendTuiProcess, clipboardReader = readTuiClipboard, clipboardWriter = writeTuiClipboard, sideQuestionClipboardWriter = writeTuiOsc52Clipboard, exportWriter = writeConversationExport, permissionRuleStore, recentlyDeniedStore: suppliedRecentlyDeniedStore, terminalSetup: terminalSetupOverride, themeStore, initialThemeSettings, initialThemeLoadError, workspaceDirectoryResolver = resolveTuiWorkspaceDirectory, workspaceDirectoryCompleter = completeTuiWorkspaceDirectory, runtimeSettings: suppliedRuntimeSettings, runtimeSettingsTarget, notificationWriter, }) {
237
+ const HIDDEN_TUI_SLASH_COMMANDS = new Set([
238
+ 'background',
239
+ 'new',
240
+ 'output-style',
241
+ 'reload-skills',
242
+ 'sessions',
243
+ 'skill',
244
+ 'terminal-setup',
245
+ 'update',
246
+ 'usage',
247
+ ]);
248
+ export function InteractiveApp({ factory, initialSessions, initialPrompt, initialHistory = [], signal, onCancel, onTurnChange, onCleanup, onRendererChange, onBackground, axScreenReader = false, allowNewSession = true, resume, display = { version: 'dev', cwd: process.cwd() }, terminalWidth, slashCommands = EMPTY_SLASH_COMMANDS, agents = EMPTY_AGENTS, allowDangerouslySkipPermissions = false, additionalDirectories = [], diffLoader, fileLoader, externalEditor = editTuiPrompt, keybindingsConfigRoot, keybindingsFile = ensureTuiKeybindingsFile, keybindingsLoader = loadTuiKeybindings, keybindingsEditor = openTuiEditorFile, memoryFilesLoader = (configRoot, cwd) => loadTuiMemoryFiles({ configRoot, cwd }), memoryEditor = openTuiEditorFile, memoryFolderOpener = openTuiMemoryFolder, suspendProcess = suspendTuiProcess, clipboardReader = readTuiClipboard, clipboardWriter = writeTuiClipboard, sideQuestionClipboardWriter = writeTuiOsc52Clipboard, exportWriter = writeConversationExport, permissionRuleStore, sandboxStore: suppliedSandboxStore, recentlyDeniedStore: suppliedRecentlyDeniedStore, terminalSetup: terminalSetupOverride, themeStore, initialThemeSettings, initialThemeLoadError, workspaceDirectoryResolver = resolveTuiWorkspaceDirectory, workspaceDirectoryCompleter = completeTuiWorkspaceDirectory, runtimeSettings: suppliedRuntimeSettings, runtimeSettingsTarget, notificationWriter, elicitationUrlOpener = openTuiUrl, }) {
232
249
  const { exit, suspendTerminal, waitUntilRenderFlush } = useApp();
233
250
  const width = useTerminalWidth(terminalWidth);
234
251
  const keybindingsRoot = useMemo(() => resolve(keybindingsConfigRoot ??
@@ -365,17 +382,41 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
365
382
  permissionMode: permissionMode(display.permissionMode),
366
383
  additionalDirectories: [...new Set(additionalDirectories)],
367
384
  }));
385
+ const sandboxStore = useMemo(() => suppliedSandboxStore ??
386
+ createTuiSandboxStore({
387
+ configRoot: keybindingsRoot,
388
+ cwd: runtimeCwd,
389
+ homeDirectory: homedir(),
390
+ additionalDirectories: runtimePreferences.additionalDirectories,
391
+ }), [
392
+ keybindingsRoot,
393
+ runtimeCwd,
394
+ runtimePreferences.additionalDirectories,
395
+ suppliedSandboxStore,
396
+ ]);
368
397
  const runtimePreferencesRef = useRef(runtimePreferences);
369
398
  const [permission, setPermission] = useState(null);
370
399
  const permissionRef = useRef(null);
400
+ const [permissionSelection, setPermissionSelection] = useState(0);
401
+ const [permissionFeedbackMode, setPermissionFeedbackMode] = useState(false);
402
+ const [permissionRuleEditor, setPermissionRuleEditor] = useState(null);
403
+ const immediatePermissionRulesRef = useRef([]);
404
+ const toolPermissionModel = useMemo(() => permission?.kind === 'tool'
405
+ ? projectTuiToolPermission(permission.call, runtimeCwd, sensitiveValues, permission.decision)
406
+ : null, [permission, runtimeCwd, sensitiveValues]);
371
407
  const [elicitation, setElicitation] = useState(null);
372
408
  const elicitationRef = useRef(null);
409
+ const [elicitationForm, setElicitationForm] = useState(null);
410
+ const [elicitationUrlWaiting, setElicitationUrlWaiting] = useState(false);
411
+ const elicitationUrlWaitingRef = useRef(null);
373
412
  const [question, setQuestion] = useState(null);
374
413
  const questionRef = useRef(null);
375
414
  const questionTimeoutRef = useRef(null);
376
415
  const recapShownRef = useRef(false);
377
416
  const [planApproval, setPlanApproval] = useState(null);
378
417
  const planApprovalRef = useRef(null);
418
+ const [planApprovalSelection, setPlanApprovalSelection] = useState(0);
419
+ const [planApprovalFeedbackMode, setPlanApprovalFeedbackMode] = useState(false);
379
420
  const serviceRef = useRef(null);
380
421
  const serviceCreationRef = useRef(undefined);
381
422
  const onCleanupRef = useRef(onCleanup);
@@ -545,7 +586,7 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
545
586
  permissionRef.current?.resolve(false);
546
587
  elicitationRef.current?.resolve({ action: 'cancel' });
547
588
  questionRef.current?.resolve(null);
548
- planApprovalRef.current?.resolve(false);
589
+ planApprovalRef.current?.resolve({ behavior: 'deny' });
549
590
  exit();
550
591
  };
551
592
  if (signal.aborted)
@@ -559,7 +600,7 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
559
600
  permissionRef.current?.resolve(false);
560
601
  elicitationRef.current?.resolve({ action: 'cancel' });
561
602
  questionRef.current?.resolve(null);
562
- planApprovalRef.current?.resolve(false);
603
+ planApprovalRef.current?.resolve({ behavior: 'deny' });
563
604
  if (exitConfirmationTimerRef.current)
564
605
  clearTimeout(exitConfirmationTimerRef.current);
565
606
  if (btwCopiedTimerRef.current)
@@ -950,7 +991,7 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
950
991
  permissionRef.current?.resolve(false);
951
992
  elicitationRef.current?.resolve({ action: 'cancel' });
952
993
  questionRef.current?.resolve(null);
953
- planApprovalRef.current?.resolve(false);
994
+ planApprovalRef.current?.resolve({ behavior: 'deny' });
954
995
  onCancel?.();
955
996
  exit();
956
997
  return;
@@ -1099,6 +1140,16 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
1099
1140
  kind: 'notice',
1100
1141
  text: `MCP elicitation completed · ${event.mcpServerName}`,
1101
1142
  });
1143
+ if (elicitationUrlWaitingRef.current?.request.serverName ===
1144
+ event.mcpServerName &&
1145
+ elicitationUrlWaitingRef.current.request.elicitationId ===
1146
+ event.elicitationId) {
1147
+ elicitationUrlWaitingRef.current = null;
1148
+ setElicitationUrlWaiting(false);
1149
+ setElicitation(null);
1150
+ setElicitationForm(null);
1151
+ clearComposerInput();
1152
+ }
1102
1153
  break;
1103
1154
  case 'tool-use-summary':
1104
1155
  append({ kind: 'notice', text: event.summary });
@@ -1128,11 +1179,16 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
1128
1179
  }
1129
1180
  }
1130
1181
  };
1131
- const requestApproval = (call, kind) => new Promise((resolveApproval) => {
1182
+ const requestApproval = (call, kind, decision) => new Promise((resolveApproval) => {
1183
+ const projected = kind === 'tool'
1184
+ ? projectTuiToolPermission(call, runtimeCwdRef.current, sensitiveValues, decision)
1185
+ : null;
1186
+ const editableRule = projected?.options.find((option) => option.editableRule)?.editableRule;
1132
1187
  let settled = false;
1133
1188
  const pending = {
1134
1189
  kind,
1135
1190
  call,
1191
+ ...(decision ? { decision } : {}),
1136
1192
  resolve: (approved) => {
1137
1193
  if (settled)
1138
1194
  return;
@@ -1143,28 +1199,44 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
1143
1199
  resolveApproval(approved);
1144
1200
  },
1145
1201
  };
1202
+ clearComposerInput();
1203
+ setPermissionSelection(0);
1204
+ setPermissionFeedbackMode(false);
1205
+ setPermissionRuleEditor(editableRule ? createComposerEditor(editableRule.initialValue) : null);
1146
1206
  permissionRef.current = pending;
1147
1207
  setPermission(pending);
1148
1208
  });
1149
- const approveTool = (call) => requestApproval(call, 'tool');
1209
+ const approveTool = (call, _originalCall, decision) => requestApproval(call, 'tool', decision);
1150
1210
  const requestElicitation = (request) => new Promise((resolveResult) => {
1151
1211
  let settled = false;
1152
1212
  const pending = {
1153
1213
  request,
1154
- resolve: (result) => {
1214
+ resolve: (result, options) => {
1155
1215
  if (settled)
1156
1216
  return;
1157
1217
  settled = true;
1158
1218
  if (elicitationRef.current === pending)
1159
1219
  elicitationRef.current = null;
1160
- setElicitation((current) => (current === pending ? null : current));
1220
+ if (!options?.keepUrlDialog) {
1221
+ setElicitation((current) => (current === pending ? null : current));
1222
+ setElicitationForm(null);
1223
+ clearComposerInput();
1224
+ }
1161
1225
  resolveResult(result);
1162
1226
  },
1163
1227
  };
1228
+ const form = createTuiElicitationForm(request.requestedSchema);
1229
+ setElicitationForm(form);
1230
+ setElicitationUrlWaiting(false);
1231
+ elicitationUrlWaitingRef.current = null;
1232
+ updateComposerInput(elicitationTextValue(form));
1164
1233
  elicitationRef.current = pending;
1165
1234
  setElicitation(pending);
1166
1235
  });
1167
- const approveRecovery = (call) => resume?.retryInterruptedTools ? true : requestApproval(call, 'recovery');
1236
+ const approveRecovery = (call) => resume?.retryInterruptedTools
1237
+ ? true
1238
+ : requestApproval(call, 'recovery').then((approval) => approval === true ||
1239
+ (typeof approval === 'object' && approval.behavior === 'allow'));
1168
1240
  const askUser = (questions, signal) => new Promise((resolveResult) => {
1169
1241
  let settled = false;
1170
1242
  const abort = () => pending.resolve(null);
@@ -1205,7 +1277,7 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
1205
1277
  });
1206
1278
  const approvePlan = (request, signal) => new Promise((resolveApproval) => {
1207
1279
  let settled = false;
1208
- const abort = () => pending.resolve(false);
1280
+ const abort = () => pending.resolve({ behavior: 'deny' });
1209
1281
  const pending = {
1210
1282
  request,
1211
1283
  resolve: (approved) => {
@@ -1220,10 +1292,13 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
1220
1292
  },
1221
1293
  };
1222
1294
  if (signal?.aborted) {
1223
- pending.resolve(false);
1295
+ pending.resolve({ behavior: 'deny' });
1224
1296
  return;
1225
1297
  }
1226
1298
  signal?.addEventListener('abort', abort, { once: true });
1299
+ clearComposerInput();
1300
+ setPlanApprovalSelection(0);
1301
+ setPlanApprovalFeedbackMode(false);
1227
1302
  planApprovalRef.current = pending;
1228
1303
  setPlanApproval(pending);
1229
1304
  });
@@ -1255,6 +1330,8 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
1255
1330
  return next;
1256
1331
  };
1257
1332
  const isSessionActionApproved = (call) => {
1333
+ if (immediatePermissionRulesRef.current.some((rule) => claudePermissionRuleMatches(rule, call, runtimeCwdRef.current)))
1334
+ return true;
1258
1335
  const activeSessionId = sessionIdRef.current;
1259
1336
  return activeSessionId
1260
1337
  ? (approvedSessionActionsRef.current
@@ -2494,20 +2571,270 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
2494
2571
  }
2495
2572
  }
2496
2573
  if (permission) {
2497
- if (lower === 'y' || value === '1') {
2498
- permission.resolve(true);
2499
- }
2500
- else if (lower === 'n' || value === '2' || key.return || key.escape) {
2574
+ const options = permission.kind === 'tool' && toolPermissionModel
2575
+ ? toolPermissionModel.options
2576
+ : [
2577
+ { action: 'allow-once', label: 'Yes' },
2578
+ { action: 'deny', label: 'No' },
2579
+ ];
2580
+ const optionCount = options.length;
2581
+ const resolvePermission = (selectedIndex) => {
2582
+ const feedback = inputRef.current.trim();
2583
+ clearComposerInput();
2584
+ setPermissionFeedbackMode(false);
2585
+ const selected = options[selectedIndex];
2586
+ if (!selected)
2587
+ return;
2588
+ if (selected.action === 'allow-once') {
2589
+ permission.resolve(feedback ? { behavior: 'allow', feedback } : { behavior: 'allow' });
2590
+ return;
2591
+ }
2592
+ if (permission.kind === 'tool' &&
2593
+ selected.action === 'persist-rule' &&
2594
+ (selected.rule || selected.editableRule || selected.updates?.length)) {
2595
+ const editedRule = permissionRuleEditor?.text.trim();
2596
+ const rule = selected.editableRule
2597
+ ? editedRule
2598
+ ? `${selected.editableRule.toolName}(${editedRule})`
2599
+ : undefined
2600
+ : selected.rule;
2601
+ const updates = selected.editableRule
2602
+ ? rule
2603
+ ? [
2604
+ {
2605
+ type: 'addRules',
2606
+ rules: [
2607
+ {
2608
+ toolName: selected.editableRule.toolName,
2609
+ ruleContent: editedRule ?? '',
2610
+ },
2611
+ ],
2612
+ behavior: 'allow',
2613
+ destination: 'localSettings',
2614
+ },
2615
+ ]
2616
+ : []
2617
+ : (selected.updates ??
2618
+ (rule
2619
+ ? [
2620
+ {
2621
+ type: 'addRules',
2622
+ rules: [
2623
+ /^([A-Za-z][\w-]*)(?:\((.*)\))?$/u.exec(rule),
2624
+ ].flatMap((match) => match?.[1]
2625
+ ? [
2626
+ {
2627
+ toolName: match[1],
2628
+ ...(match[2] === undefined
2629
+ ? {}
2630
+ : { ruleContent: match[2] }),
2631
+ },
2632
+ ]
2633
+ : []),
2634
+ behavior: 'allow',
2635
+ destination: 'localSettings',
2636
+ },
2637
+ ]
2638
+ : []));
2639
+ if (!rule && updates.length === 0) {
2640
+ permission.resolve({ behavior: 'allow' });
2641
+ return;
2642
+ }
2643
+ const saving = (async () => {
2644
+ try {
2645
+ for (const update of updates) {
2646
+ if (update.type !== 'addRules' ||
2647
+ update.destination !== 'localSettings') {
2648
+ continue;
2649
+ }
2650
+ for (const value of update.rules) {
2651
+ const savedRule = permissionRuleValueToString(value);
2652
+ await permissionStore.add({
2653
+ behavior: update.behavior,
2654
+ rule: savedRule,
2655
+ scope: 'local',
2656
+ });
2657
+ immediatePermissionRulesRef.current.push(savedRule);
2658
+ }
2659
+ }
2660
+ permission.resolve({
2661
+ behavior: 'allow',
2662
+ updatedPermissions: updates,
2663
+ });
2664
+ }
2665
+ catch (error) {
2666
+ warn(error);
2667
+ }
2668
+ })();
2669
+ onTurnChange?.(saving);
2670
+ void saving.finally(() => onTurnChange?.(null));
2671
+ return;
2672
+ }
2673
+ if (permission.kind === 'tool' &&
2674
+ selected.action === 'allow-session-action' &&
2675
+ (selected.rule || selected.updates?.length)) {
2676
+ if (selected.rule)
2677
+ immediatePermissionRulesRef.current.push(selected.rule);
2678
+ permission.resolve({
2679
+ behavior: 'allow',
2680
+ updatedPermissions: selected.updates ?? [],
2681
+ });
2682
+ return;
2683
+ }
2684
+ if (permission.kind === 'tool' &&
2685
+ selected.action === 'allow-session-edits') {
2686
+ for (const rule of ['Write', 'Edit', 'NotebookEdit']) {
2687
+ if (!immediatePermissionRulesRef.current.includes(rule))
2688
+ immediatePermissionRulesRef.current.push(rule);
2689
+ }
2690
+ updateRuntimePreferences((current) => ({
2691
+ ...current,
2692
+ permissionMode: 'acceptEdits',
2693
+ }));
2694
+ permission.resolve({
2695
+ behavior: 'allow',
2696
+ updatedPermissions: selected.updates?.length
2697
+ ? selected.updates
2698
+ : [
2699
+ {
2700
+ type: 'setMode',
2701
+ mode: 'acceptEdits',
2702
+ destination: 'session',
2703
+ },
2704
+ ],
2705
+ });
2706
+ const activeSessionId = sessionIdRef.current;
2707
+ if (activeSessionId && serviceRef.current?.setPermissionMode) {
2708
+ const saving = serviceRef.current
2709
+ .setPermissionMode(activeSessionId, 'acceptEdits')
2710
+ .catch((error) => warn(error));
2711
+ onTurnChange?.(saving);
2712
+ void saving.finally(() => onTurnChange?.(null));
2713
+ }
2714
+ return;
2715
+ }
2716
+ permission.resolve(feedback ? { behavior: 'deny', message: feedback } : false);
2717
+ };
2718
+ if (key.escape) {
2501
2719
  permission.resolve(false);
2502
2720
  }
2721
+ else if (permissionFeedbackMode) {
2722
+ if (key.tab) {
2723
+ clearComposerInput();
2724
+ setPermissionFeedbackMode(false);
2725
+ }
2726
+ else if (key.return) {
2727
+ resolvePermission(permissionSelection);
2728
+ }
2729
+ else {
2730
+ editComposer();
2731
+ }
2732
+ }
2733
+ else if (key.upArrow) {
2734
+ setPermissionSelection((current) => current === 0 ? optionCount - 1 : current - 1);
2735
+ }
2736
+ else if (key.downArrow) {
2737
+ setPermissionSelection((current) => (current + 1) % optionCount);
2738
+ }
2739
+ else if (key.tab &&
2740
+ (options[permissionSelection]?.action === 'allow-once' ||
2741
+ options[permissionSelection]?.action === 'deny')) {
2742
+ clearComposerInput();
2743
+ setPermissionFeedbackMode(true);
2744
+ }
2745
+ else if (options[permissionSelection]?.editableRule && !key.return) {
2746
+ if (key.leftArrow) {
2747
+ setPermissionRuleEditor((current) => moveComposerCursor(current ?? createComposerEditor(), -1));
2748
+ }
2749
+ else if (key.rightArrow) {
2750
+ setPermissionRuleEditor((current) => moveComposerCursor(current ?? createComposerEditor(), 1));
2751
+ }
2752
+ else if (key.backspace) {
2753
+ setPermissionRuleEditor((current) => deleteComposerBackward(current ?? createComposerEditor()));
2754
+ }
2755
+ else if (key.delete) {
2756
+ setPermissionRuleEditor((current) => deleteComposerForward(current ?? createComposerEditor()));
2757
+ }
2758
+ else if (value && !key.ctrl && !key.meta) {
2759
+ setPermissionRuleEditor((current) => insertComposerText(current ?? createComposerEditor(), value));
2760
+ }
2761
+ }
2762
+ else if (lower === 'y') {
2763
+ resolvePermission(0);
2764
+ }
2765
+ else if (lower === 'n') {
2766
+ resolvePermission(optionCount - 1);
2767
+ }
2768
+ else if (/^[1-9]$/u.test(value)) {
2769
+ const selectedIndex = Number(value) - 1;
2770
+ if (selectedIndex < optionCount)
2771
+ resolvePermission(selectedIndex);
2772
+ }
2773
+ else if (key.return) {
2774
+ resolvePermission(permissionSelection);
2775
+ }
2503
2776
  return;
2504
2777
  }
2505
2778
  if (planApproval) {
2506
- if (lower === 'y' || value === '1') {
2507
- planApproval.resolve(true);
2779
+ const elevatedMode = runtimeSettingsRef.current
2780
+ .useAutoModeDuringPlan
2781
+ ? 'auto'
2782
+ : allowDangerouslySkipPermissions
2783
+ ? 'bypassPermissions'
2784
+ : 'acceptEdits';
2785
+ const resolvePlanApproval = (selectedIndex) => {
2786
+ const feedback = inputRef.current.trim() || undefined;
2787
+ clearComposerInput();
2788
+ setPlanApprovalFeedbackMode(false);
2789
+ if (selectedIndex === 2) {
2790
+ planApproval.resolve({
2791
+ behavior: 'deny',
2792
+ ...(feedback ? { feedback } : {}),
2793
+ });
2794
+ return;
2795
+ }
2796
+ planApproval.resolve({
2797
+ behavior: 'allow',
2798
+ permissionMode: selectedIndex === 0 ? elevatedMode : 'default',
2799
+ ...(feedback ? { feedback } : {}),
2800
+ });
2801
+ };
2802
+ if (key.escape) {
2803
+ planApproval.resolve({ behavior: 'deny' });
2508
2804
  }
2509
- else if (lower === 'n' || value === '2' || key.return || key.escape) {
2510
- planApproval.resolve(false);
2805
+ else if (planApprovalFeedbackMode) {
2806
+ if (key.tab) {
2807
+ clearComposerInput();
2808
+ setPlanApprovalFeedbackMode(false);
2809
+ }
2810
+ else if (key.return) {
2811
+ resolvePlanApproval(planApprovalSelection);
2812
+ }
2813
+ else {
2814
+ editComposer();
2815
+ }
2816
+ }
2817
+ else if (key.upArrow) {
2818
+ setPlanApprovalSelection((current) => (current === 0 ? 2 : current - 1));
2819
+ }
2820
+ else if (key.downArrow) {
2821
+ setPlanApprovalSelection((current) => (current + 1) % 3);
2822
+ }
2823
+ else if (key.tab) {
2824
+ clearComposerInput();
2825
+ setPlanApprovalFeedbackMode(true);
2826
+ }
2827
+ else if (lower === 'y') {
2828
+ resolvePlanApproval(0);
2829
+ }
2830
+ else if (lower === 'n') {
2831
+ resolvePlanApproval(2);
2832
+ }
2833
+ else if (/^[1-3]$/u.test(value)) {
2834
+ resolvePlanApproval(Number(value) - 1);
2835
+ }
2836
+ else if (key.return) {
2837
+ resolvePlanApproval(planApprovalSelection);
2511
2838
  }
2512
2839
  return;
2513
2840
  }
@@ -2545,43 +2872,151 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
2545
2872
  return;
2546
2873
  }
2547
2874
  if (elicitation) {
2548
- if (key.escape) {
2549
- elicitation.resolve({ action: 'cancel' });
2875
+ const form = elicitationForm ??
2876
+ createTuiElicitationForm(elicitation.request.requestedSchema);
2877
+ const currentField = focusedElicitationField(form);
2878
+ const textField = currentField &&
2879
+ ['text', 'number', 'integer'].includes(currentField.kind);
2880
+ const commitCurrent = () => textField ? commitElicitationText(form, inputRef.current) : form;
2881
+ const showForm = (next) => {
2882
+ setElicitationForm(next);
2883
+ updateComposerInput(elicitationTextValue(next));
2884
+ };
2885
+ const move = (direction) => showForm(moveElicitationFocus(commitCurrent(), direction));
2886
+ if (elicitation.request.mode === 'url') {
2887
+ const openUrl = () => {
2888
+ void Promise.resolve()
2889
+ .then(() => elicitationUrlOpener(elicitation.request.url ?? ''))
2890
+ .catch(() => undefined);
2891
+ };
2892
+ const dismissUrlDialog = () => {
2893
+ elicitationUrlWaitingRef.current = null;
2894
+ setElicitationUrlWaiting(false);
2895
+ setElicitation(null);
2896
+ setElicitationForm(null);
2897
+ clearComposerInput();
2898
+ };
2899
+ if (key.escape) {
2900
+ if (elicitationUrlWaiting)
2901
+ dismissUrlDialog();
2902
+ else
2903
+ elicitation.resolve({ action: 'cancel' });
2904
+ }
2905
+ else if (key.leftArrow || key.rightArrow) {
2906
+ setElicitationForm({
2907
+ ...form,
2908
+ focusIndex: form.focusIndex === 0 ? 1 : 0,
2909
+ });
2910
+ }
2911
+ else if (key.return && form.focusIndex === 0) {
2912
+ if (elicitationUrlWaiting) {
2913
+ openUrl();
2914
+ }
2915
+ else {
2916
+ openUrl();
2917
+ elicitationUrlWaitingRef.current = elicitation;
2918
+ setElicitationUrlWaiting(true);
2919
+ elicitation.resolve({ action: 'accept' }, { keepUrlDialog: true });
2920
+ }
2921
+ }
2922
+ else if (key.return && form.focusIndex === 1) {
2923
+ if (elicitationUrlWaiting)
2924
+ dismissUrlDialog();
2925
+ else
2926
+ elicitation.resolve({ action: 'decline' });
2927
+ }
2928
+ return;
2550
2929
  }
2551
- else if (key.return) {
2552
- const answer = inputRef.current.trim();
2553
- clearComposerInput();
2554
- if (!answer || answer.toLowerCase() === 'decline') {
2555
- elicitation.resolve({ action: 'decline' });
2930
+ if (form.expandedField && currentField) {
2931
+ if (key.escape || key.leftArrow) {
2932
+ setElicitationForm({ ...form, expandedField: undefined });
2933
+ }
2934
+ else if (key.upArrow) {
2935
+ showForm(moveElicitationOption(form, -1));
2556
2936
  }
2557
- else if (answer.toLowerCase() === 'cancel') {
2558
- elicitation.resolve({ action: 'cancel' });
2937
+ else if (key.downArrow) {
2938
+ showForm(moveElicitationOption(form, 1));
2559
2939
  }
2560
- else if (answer.toLowerCase() === 'accept') {
2561
- elicitation.resolve({ action: 'accept' });
2940
+ else if (value === ' ') {
2941
+ setElicitationForm(selectElicitationOption(form, currentField.kind === 'enum'));
2942
+ }
2943
+ else if (key.return) {
2944
+ showForm(moveElicitationFocus(selectElicitationOption(form, true, true), 1));
2945
+ }
2946
+ else if (printable && value) {
2947
+ setElicitationForm(typeaheadElicitationOption(form, value));
2948
+ }
2949
+ }
2950
+ else if (key.escape) {
2951
+ elicitation.resolve({ action: 'cancel' });
2952
+ }
2953
+ else if (key.upArrow) {
2954
+ move(-1);
2955
+ }
2956
+ else if (key.downArrow) {
2957
+ move(1);
2958
+ }
2959
+ else if (!currentField && (key.leftArrow || key.rightArrow)) {
2960
+ setElicitationForm({
2961
+ ...form,
2962
+ focusIndex: form.focusIndex === form.fields.length
2963
+ ? form.fields.length + 1
2964
+ : form.fields.length,
2965
+ });
2966
+ }
2967
+ else if (form.focusIndex === form.fields.length && key.return) {
2968
+ const validated = validateTuiElicitationForm(form);
2969
+ if (elicitationFormIsValid(validated)) {
2970
+ elicitation.resolve({
2971
+ action: 'accept',
2972
+ ...(Object.keys(validated.values).length > 0
2973
+ ? { content: { ...validated.values } }
2974
+ : {}),
2975
+ });
2562
2976
  }
2563
2977
  else {
2564
- try {
2565
- const content = JSON.parse(answer);
2566
- if (!content ||
2567
- typeof content !== 'object' ||
2568
- Array.isArray(content))
2569
- throw new Error('elicitation content must be a JSON object');
2570
- elicitation.resolve({
2571
- action: 'accept',
2572
- content: content,
2573
- });
2574
- }
2575
- catch {
2576
- append({
2577
- kind: 'warning',
2578
- text: 'Elicitation response must be accept, decline, cancel, or a JSON object.',
2579
- });
2580
- }
2978
+ showForm(validated);
2581
2979
  }
2582
2980
  }
2583
- else {
2584
- editComposer();
2981
+ else if (form.focusIndex === form.fields.length + 1 && key.return) {
2982
+ elicitation.resolve({ action: 'decline' });
2983
+ }
2984
+ else if (currentField?.kind === 'boolean') {
2985
+ if (value === ' ' || lower === 'y' || lower === 'n') {
2986
+ let next = toggleElicitationBoolean(form);
2987
+ if (lower === 'n' && next.values[currentField.name] === true)
2988
+ next = toggleElicitationBoolean(next);
2989
+ if (lower === 'y' && next.values[currentField.name] === false)
2990
+ next = toggleElicitationBoolean(next);
2991
+ setElicitationForm(next);
2992
+ }
2993
+ else if (key.backspace) {
2994
+ setElicitationForm(unsetElicitationField(form));
2995
+ }
2996
+ else if (key.return) {
2997
+ move(1);
2998
+ }
2999
+ }
3000
+ else if (currentField &&
3001
+ ['enum', 'multi-enum'].includes(currentField.kind)) {
3002
+ if (key.rightArrow) {
3003
+ setElicitationForm(expandElicitationOptions(form));
3004
+ }
3005
+ else if (key.backspace) {
3006
+ setElicitationForm(unsetElicitationField(form));
3007
+ }
3008
+ else if (key.return) {
3009
+ move(1);
3010
+ }
3011
+ else if (printable && value) {
3012
+ setElicitationForm(typeaheadElicitationOption(form, value));
3013
+ }
3014
+ }
3015
+ else if (textField) {
3016
+ if (key.return)
3017
+ move(1);
3018
+ else
3019
+ editComposer();
2585
3020
  }
2586
3021
  return;
2587
3022
  }
@@ -2747,6 +3182,62 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
2747
3182
  }
2748
3183
  return;
2749
3184
  }
3185
+ if (earlyMenu?.kind === 'sandbox') {
3186
+ if (key.escape || value === '\u001B') {
3187
+ updateMenu(null);
3188
+ return;
3189
+ }
3190
+ const tabs = tuiSandboxTabs(earlyMenu.snapshot);
3191
+ if (key.leftArrow || key.rightArrow || key.tab) {
3192
+ const index = tabs.indexOf(earlyMenu.tab);
3193
+ const direction = key.leftArrow || (key.tab && key.shift) ? -1 : 1;
3194
+ const tab = tabs[Math.max(0, Math.min(tabs.length - 1, index + direction))] ??
3195
+ earlyMenu.tab;
3196
+ updateMenu({ ...earlyMenu, tab, selectedIndex: 0 });
3197
+ return;
3198
+ }
3199
+ const rowCount = earlyMenu.tab === 'mode'
3200
+ ? 3
3201
+ : earlyMenu.tab === 'overrides' && earlyMenu.snapshot.settings.enabled
3202
+ ? 2
3203
+ : 0;
3204
+ if (rowCount > 0 && (key.upArrow || key.downArrow)) {
3205
+ updateMenu({
3206
+ ...earlyMenu,
3207
+ selectedIndex: Math.max(0, Math.min(rowCount - 1, earlyMenu.selectedIndex + (key.upArrow ? -1 : 1))),
3208
+ });
3209
+ return;
3210
+ }
3211
+ if (rowCount > 0 && key.return) {
3212
+ const saving = (async () => {
3213
+ setBusy(true);
3214
+ try {
3215
+ const snapshot = earlyMenu.tab === 'mode'
3216
+ ? await sandboxStore.setMode(['auto-allow', 'regular', 'disabled'][earlyMenu.selectedIndex] ?? 'auto-allow')
3217
+ : await sandboxStore.setAllowUnsandboxedCommands(earlyMenu.selectedIndex === 0);
3218
+ await retireService();
3219
+ const tabs = tuiSandboxTabs(snapshot);
3220
+ updateMenu({
3221
+ kind: 'sandbox',
3222
+ tab: tabs.includes(earlyMenu.tab)
3223
+ ? earlyMenu.tab
3224
+ : (tabs[0] ?? 'dependencies'),
3225
+ selectedIndex: earlyMenu.selectedIndex,
3226
+ snapshot,
3227
+ });
3228
+ }
3229
+ catch (error) {
3230
+ warn(error);
3231
+ }
3232
+ finally {
3233
+ setBusy(false);
3234
+ }
3235
+ })();
3236
+ onTurnChange?.(saving);
3237
+ void saving.finally(() => onTurnChange?.(null));
3238
+ }
3239
+ return;
3240
+ }
2750
3241
  if (earlyMenu?.kind === 'config') {
2751
3242
  if (key.escape || value === '\u001B') {
2752
3243
  if (earlyMenu.searchFocused && earlyMenu.query) {
@@ -4258,11 +4749,18 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
4258
4749
  return;
4259
4750
  }
4260
4751
  const selectedCommand = matchingSlashCommands[selectedSlashCommandIndex];
4752
+ const commandNameQuery = inputRef.current.slice(1).toLocaleLowerCase();
4261
4753
  const exactSelectedCommand = selectedCommand !== undefined &&
4262
- inputRef.current.toLocaleLowerCase() ===
4263
- `/${selectedCommand.name}`.toLocaleLowerCase();
4754
+ commandNameQuery === selectedCommand.name.toLocaleLowerCase();
4755
+ const selectedCommandMatchesName = selectedCommand !== undefined &&
4756
+ selectedCommand.name.toLocaleLowerCase().startsWith(commandNameQuery);
4757
+ const exactHiddenCommand = HIDDEN_TUI_SLASH_COMMANDS.has(commandNameQuery);
4264
4758
  if (selectedCommand &&
4265
- (key.tab || (key.return && !exactSelectedCommand))) {
4759
+ (key.tab ||
4760
+ (key.return &&
4761
+ !exactSelectedCommand &&
4762
+ !exactHiddenCommand &&
4763
+ selectedCommandMatchesName))) {
4266
4764
  updateComposerInput(`/${selectedCommand.name} `);
4267
4765
  setCommandPaletteOpen(false);
4268
4766
  return;
@@ -4289,6 +4787,7 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
4289
4787
  if (!prompt || prompt === '!')
4290
4788
  return;
4291
4789
  const copyCommand = /^\/copy(?:\s+(\d+))?$/u.exec(prompt);
4790
+ const sandboxCommand = /^\/sandbox(?:\s+([\s\S]+))?$/u.exec(prompt);
4292
4791
  const tuiCommand = /^\/tui(?:\s+(default|fullscreen))?$/u.exec(prompt);
4293
4792
  const renameCommand = /^\/rename(?:\s+(.+))?$/u.exec(prompt);
4294
4793
  const cdCommand = /^\/cd(?:\s+(.+))?$/u.exec(prompt);
@@ -4336,6 +4835,37 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
4336
4835
  : TUI_THEMES.indexOf(themeSettings.theme)),
4337
4836
  });
4338
4837
  }
4838
+ else if (prompt === '/vim') {
4839
+ const saving = (async () => {
4840
+ setBusy(true);
4841
+ try {
4842
+ const mode = runtimeSettingsRef.current.editor === 'vim' ? 'normal' : 'vim';
4843
+ const snapshot = await saveConfigSetting('editor', mode, configTarget);
4844
+ await reloadRuntimeSettings(snapshot);
4845
+ setVimInsertMode(true);
4846
+ append({
4847
+ kind: 'local-result',
4848
+ text: `Editor mode set to ${mode}. ${mode === 'vim'
4849
+ ? 'Use Escape key to toggle between INSERT and NORMAL modes.'
4850
+ : 'Using standard (readline) keyboard bindings.'}`,
4851
+ });
4852
+ }
4853
+ catch (error) {
4854
+ warn(error);
4855
+ }
4856
+ finally {
4857
+ setBusy(false);
4858
+ }
4859
+ })();
4860
+ onTurnChange?.(saving);
4861
+ void saving.finally(() => onTurnChange?.(null));
4862
+ }
4863
+ else if (prompt === '/output-style') {
4864
+ append({
4865
+ kind: 'local-result',
4866
+ text: '/output-style has been deprecated. Use /config to change your output style, or set it in your settings file. Changes take effect on the next session.',
4867
+ });
4868
+ }
4339
4869
  else if (prompt === '/terminal-setup') {
4340
4870
  const setup = (async () => {
4341
4871
  setBusy(true);
@@ -4439,6 +4969,52 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
4439
4969
  append({ kind: 'user', text: prompt });
4440
4970
  updateMenu({ kind: 'export', selectedIndex: 0 });
4441
4971
  }
4972
+ else if (sandboxCommand) {
4973
+ const operation = (async () => {
4974
+ setBusy(true);
4975
+ try {
4976
+ const args = sandboxCommand[1]?.trim();
4977
+ if (args) {
4978
+ const exclude = /^exclude(?:\s+([\s\S]+))?$/u.exec(args);
4979
+ if (!exclude) {
4980
+ throw new Error(`Unknown subcommand "${args.split(/\s+/u)[0] ?? args}". Available subcommand: exclude`);
4981
+ }
4982
+ if (!exclude[1]?.trim()) {
4983
+ throw new Error('Please provide a command pattern to exclude (e.g. /sandbox exclude "npm run test:*")');
4984
+ }
4985
+ const result = await sandboxStore.exclude(exclude[1]);
4986
+ await retireService();
4987
+ append({
4988
+ kind: 'local-result',
4989
+ text: `Added "${result.pattern}" to excluded commands in ${result.settingsPath}`,
4990
+ });
4991
+ return;
4992
+ }
4993
+ const snapshot = await sandboxStore.load();
4994
+ if (!snapshot.supported) {
4995
+ throw new Error('Sandboxing is currently only supported on macOS, Linux, and WSL2.');
4996
+ }
4997
+ if (snapshot.unavailableReason?.includes('not in sandbox.enabledPlatforms')) {
4998
+ throw new Error(snapshot.unavailableReason);
4999
+ }
5000
+ const tabs = tuiSandboxTabs(snapshot);
5001
+ updateMenu({
5002
+ kind: 'sandbox',
5003
+ tab: tabs[0] ?? 'dependencies',
5004
+ selectedIndex: 0,
5005
+ snapshot,
5006
+ });
5007
+ }
5008
+ catch (error) {
5009
+ warn(error);
5010
+ }
5011
+ finally {
5012
+ setBusy(false);
5013
+ }
5014
+ })();
5015
+ onTurnChange?.(operation);
5016
+ void operation.finally(() => onTurnChange?.(null));
5017
+ }
4442
5018
  else if (prompt === '/permissions') {
4443
5019
  const loading = (async () => {
4444
5020
  setBusy(true);
@@ -4712,11 +5288,26 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
4712
5288
  });
4713
5289
  return (_jsx(TuiThemeProvider, { settings: themeSettings, children: _jsx(Box, { flexDirection: "column", children: selectingSession ? (_jsx(SessionPicker, { sessions: filteredPickerChoices, selectedIndex: selectedIndex, screenReader: axScreenReader, query: sessionSearch })) : (_jsxs(_Fragment, { children: [!axScreenReader && history.length === 0 && !sessionId ? (_jsx(WelcomePanel, { display: runtimeDisplay, width: width })) : null, sessionId ? (_jsxs(Text, { dimColor: true, children: ["Session ", sessionId.slice(0, 8)] })) : null, _jsx(Transcript, { items: history, activeText: activeText, activeThinking: activeThinking, thinkingExpanded: thinkingExpanded, detailedTranscript: thinkingExpanded || runtimeSettings.verbose, screenReader: axScreenReader }), externalEditorRequest !== null ||
4714
5290
  keybindingsEditing ||
4715
- memoryEditorRequest !== null ? (_jsx(ExternalEditorWait, { screenReader: axScreenReader })) : permission ? (_jsxs(DialogFrame, { title: permission.kind === 'recovery'
4716
- ? `Retry interrupted ${permission.call.name}?`
4717
- : `Allow ${permission.call.name}?`, screenReader: axScreenReader, children: [_jsx(Text, { bold: true, children: describeTool(permission.call, sensitiveValues) }), _jsxs(Text, { children: [selectionPrefix(true, axScreenReader), "1. Yes"] }), _jsx(Text, { children: " 2. No" }), _jsx(Text, { dimColor: true, children: "Enter/Esc declines \u00B7 y/n quick response" })] })) : planApproval ? (_jsxs(DialogFrame, { title: "Approve this plan and begin implementation?", screenReader: axScreenReader, children: [_jsx(Text, { dimColor: true, children: planApproval.request.planPath }), planApproval.request.plan ? (_jsx(Box, { marginY: 1, children: _jsx(Text, { children: planApproval.request.plan }) })) : null, _jsxs(Text, { children: [selectionPrefix(true, axScreenReader), "1. Yes, implement the plan"] }), _jsx(Text, { children: " 2. No, keep planning" })] })) : question ? (_jsxs(DialogFrame, { title: `${question.questions[question.index]?.header}: ${question.questions[question.index]?.question}`, screenReader: axScreenReader, children: [question.questions[question.index]?.options.map((option, index) => (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: [index + 1, ". ", option.label, " \u2014 ", option.description] }), option.preview ? (_jsx(Text, { dimColor: true, children: option.preview })) : null] }, `${index}-${option.label}`))), _jsxs(Text, { children: [axScreenReader ? 'Current answer: ' : '› ', input || (axScreenReader ? '(empty)' : '')] }), _jsx(Text, { dimColor: true, children: question.questions[question.index]?.multiSelect
5291
+ memoryEditorRequest !== null ? (_jsx(ExternalEditorWait, { screenReader: axScreenReader })) : permission ? (permission.kind === 'tool' && toolPermissionModel ? (_jsx(ToolPermissionDialog, { model: toolPermissionModel, selection: permissionSelection, feedbackMode: permissionFeedbackMode, feedback: input, ruleEditor: permissionRuleEditor, screenReader: axScreenReader })) : (_jsxs(DialogFrame, { title: `Retry interrupted ${permission.call.name}?`, screenReader: axScreenReader, children: [_jsx(Box, { flexDirection: "column", paddingX: 1, paddingY: 1, children: _jsx(Text, { bold: true, children: describeTool(permission.call, sensitiveValues) }) }), _jsx(Text, { children: "Do you want to proceed?" }), _jsxs(Text, { inverse: !axScreenReader && permissionSelection === 0, children: [selectionPrefix(permissionSelection === 0, axScreenReader), "1. Yes"] }), _jsxs(Text, { inverse: !axScreenReader && permissionSelection === 1, children: [selectionPrefix(permissionSelection === 1, axScreenReader), "2. No"] }), permissionFeedbackMode ? (_jsxs(Text, { children: ["\u203A", ' ', input ||
5292
+ (permissionSelection === 0
5293
+ ? 'tell Praxis what to do next'
5294
+ : 'tell Praxis what to do differently')] })) : null, _jsx(Text, { dimColor: true, children: permissionFeedbackMode
5295
+ ? 'Enter to submit · Tab to collapse · Esc to cancel'
5296
+ : 'Enter to confirm · Tab to add feedback · Esc to cancel' })] }))) : planApproval ? (_jsxs(DialogFrame, { title: "Ready to code?", screenReader: axScreenReader, children: [_jsx(Text, { children: "Here is Praxis's plan:" }), planApproval.request.plan ? (_jsx(Box, { borderStyle: axScreenReader ? undefined : 'classic', borderLeft: false, borderRight: false, paddingX: axScreenReader ? 0 : 1, marginY: 1, children: _jsx(Text, { children: planApproval.request.plan }) })) : null, _jsx(Text, { dimColor: true, children: "Praxis has written up a plan and is ready to execute. Would you like to proceed?" }), _jsxs(Text, { inverse: !axScreenReader && planApprovalSelection === 0, children: [selectionPrefix(planApprovalSelection === 0, axScreenReader), "1.", ' ', runtimeSettings.useAutoModeDuringPlan
5297
+ ? 'Yes, and use auto mode'
5298
+ : allowDangerouslySkipPermissions
5299
+ ? 'Yes, and bypass permissions'
5300
+ : 'Yes, auto-accept edits'] }), _jsxs(Text, { inverse: !axScreenReader && planApprovalSelection === 1, children: [selectionPrefix(planApprovalSelection === 1, axScreenReader), "2. Yes, manually approve edits"] }), _jsxs(Text, { inverse: !axScreenReader && planApprovalSelection === 2, children: [selectionPrefix(planApprovalSelection === 2, axScreenReader), "3. No, keep planning"] }), planApprovalFeedbackMode ? (_jsxs(Text, { children: ["\u203A", ' ', input ||
5301
+ (planApprovalSelection === 2
5302
+ ? 'Tell Praxis what to change'
5303
+ : 'Add feedback for implementation')] })) : null, _jsx(Text, { dimColor: true, children: planApproval.request.planPath }), _jsx(Text, { dimColor: true, children: planApprovalFeedbackMode
5304
+ ? 'Enter to submit · Tab to collapse · Esc to cancel'
5305
+ : 'Enter to confirm · Tab to add feedback · Esc to cancel' })] })) : question ? (_jsxs(DialogFrame, { title: `${question.questions[question.index]?.header}: ${question.questions[question.index]?.question}`, screenReader: axScreenReader, children: [question.questions[question.index]?.options.map((option, index) => (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: [index + 1, ". ", option.label, " \u2014 ", option.description] }), option.preview ? (_jsx(Text, { dimColor: true, children: option.preview })) : null] }, `${index}-${option.label}`))), _jsxs(Text, { children: [axScreenReader ? 'Current answer: ' : '› ', input || (axScreenReader ? '(empty)' : '')] }), _jsx(Text, { dimColor: true, children: question.questions[question.index]?.multiSelect
4718
5306
  ? 'Enter comma-separated option numbers or custom text · Esc cancels'
4719
- : 'Enter one option number or custom text · Esc cancels' })] })) : elicitation ? (_jsxs(DialogFrame, { title: `MCP elicitation (${elicitation.request.serverName})`, screenReader: axScreenReader, children: [_jsx(Text, { children: elicitation.request.message }), elicitation.request.url ? (_jsx(Text, { children: elicitation.request.url })) : null, elicitation.request.requestedSchema ? (_jsx(Text, { dimColor: true, children: JSON.stringify(elicitation.request.requestedSchema) })) : null, _jsxs(Text, { children: ["\u203A ", input] }), _jsx(Text, { dimColor: true, children: "Enter JSON object to accept \u00B7 Esc to cancel" })] })) : menu?.kind === 'model-input' ? (_jsxs(DialogFrame, { title: "Enter model ID", screenReader: axScreenReader, children: [_jsx(Text, { dimColor: true, children: "Enter a model ID supported by the configured provider." }), _jsxs(Text, { children: ["\u203A ", input] }), _jsx(Text, { dimColor: true, children: "Enter confirms \u00B7 Esc cancels" })] })) : menu?.kind === 'export-filename' ? (_jsxs(DialogFrame, { title: "Enter filename:", screenReader: axScreenReader, children: [_jsxs(Text, { children: ["> ", input] }), _jsx(Text, { dimColor: true, children: "Enter to save \u00B7 Esc to go back" })] })) : menu?.kind === 'compact-progress' ? (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "\u273B Compacting conversation\u2026" }), _jsxs(Text, { children: ['▰'.repeat(Math.floor(compactProgress / 2)), '▱'.repeat(50 - Math.floor(compactProgress / 2)), ' ', compactProgress, "%"] })] })) : menu?.kind === 'btw' ? (_jsx(BtwPanel, { entries: btwHistory, selectedIndex: menu.selectedIndex, scrollOffset: menu.scrollOffset, copied: btwCopied, width: width, screenReader: axScreenReader })) : menu?.kind === 'rewind' ? (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: " Rewind" }), _jsx(Text, { children: " " }), _jsxs(Text, { children: [' ', "Restore the code and/or conversation to the point before\u2026"] }), _jsx(Text, { children: " " }), (() => {
5307
+ : 'Enter one option number or custom text · Esc cancels' })] })) : elicitation ? (elicitation.request.mode === 'url' ? (_jsx(McpElicitationUrl, { serverName: elicitation.request.serverName, message: elicitation.request.message, url: elicitation.request.url ?? '', waiting: elicitationUrlWaiting, actionLabel: elicitation.request.elicitationId
5308
+ ? 'Skip confirmation'
5309
+ : 'Continue without waiting', selection: elicitationForm?.focusIndex ?? 0, screenReader: axScreenReader })) : (_jsx(McpElicitationForm, { serverName: elicitation.request.serverName, message: elicitation.request.message, state: elicitationForm ??
5310
+ createTuiElicitationForm(elicitation.request.requestedSchema), input: input, screenReader: axScreenReader }))) : menu?.kind === 'model-input' ? (_jsxs(DialogFrame, { title: "Enter model ID", screenReader: axScreenReader, children: [_jsx(Text, { dimColor: true, children: "Enter a model ID supported by the configured provider." }), _jsxs(Text, { children: ["\u203A ", input] }), _jsx(Text, { dimColor: true, children: "Enter confirms \u00B7 Esc cancels" })] })) : menu?.kind === 'export-filename' ? (_jsxs(DialogFrame, { title: "Enter filename:", screenReader: axScreenReader, children: [_jsxs(Text, { children: ["> ", input] }), _jsx(Text, { dimColor: true, children: "Enter to save \u00B7 Esc to go back" })] })) : menu?.kind === 'compact-progress' ? (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "\u273B Compacting conversation\u2026" }), _jsxs(Text, { children: ['▰'.repeat(Math.floor(compactProgress / 2)), '▱'.repeat(50 - Math.floor(compactProgress / 2)), ' ', compactProgress, "%"] })] })) : menu?.kind === 'btw' ? (_jsx(BtwPanel, { entries: btwHistory, selectedIndex: menu.selectedIndex, scrollOffset: menu.scrollOffset, copied: btwCopied, width: width, screenReader: axScreenReader })) : menu?.kind === 'rewind' ? (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: " Rewind" }), _jsx(Text, { children: " " }), _jsxs(Text, { children: [' ', "Restore the code and/or conversation to the point before\u2026"] }), _jsx(Text, { children: " " }), (() => {
4720
5311
  const window = rewindPointWindow(menu.points, menu.selectedIndex);
4721
5312
  return (_jsxs(_Fragment, { children: [window.start > 0 ? (_jsxs(Text, { dimColor: true, children: [" \u2191 ", window.start, " more above"] })) : null, menu.points
4722
5313
  .slice(window.start, window.end)
@@ -4738,7 +5329,7 @@ export function InteractiveApp({ factory, initialSessions, initialPrompt, initia
4738
5329
  ? `restore ${menu.point.fileChanges.join(', ')}.`
4739
5330
  : 'be unchanged.'] }), _jsx(Text, { children: " " }), rewindActions(menu.point).map((option, index) => (_jsxs(Text, { inverse: menu.selectedIndex === index, children: [menu.selectedIndex === index ? '❯ ' : ' ', index + 1, ". ", option.label] }, option.action))), _jsx(Text, { children: " " }), _jsx(Text, { color: activePalette.warning, children: "\u26A0 Rewinding does not affect files edited manually or via bash." })] })) : menu?.kind === 'rewind-context' ? (_jsxs(DialogFrame, { title: `Summarize ${menu.direction === 'from' ? 'from' : 'up to'} here`, screenReader: axScreenReader, children: [_jsx(Text, { children: menu.direction === 'from'
4740
5331
  ? 'Messages after this point will be summarized.'
4741
- : 'Messages up to this point will be summarized.' }), _jsx(Text, { children: " " }), _jsxs(Text, { children: ["add context (optional): ", input] }), _jsx(Text, { dimColor: true, children: "Enter to summarize \u00B7 Esc to go back" })] })) : menu?.kind === 'permission-rule-input' ? (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: ["Add ", menu.behavior, " permission rule"] }), _jsx(Text, { children: "Permission rules are a tool name, optionally followed by a specifier in parentheses." }), _jsx(Text, { children: "e.g., WebFetch or Bash(ls *)" }), _jsx(Text, { children: " " }), _jsx(Box, { borderStyle: axScreenReader ? undefined : 'round', paddingX: axScreenReader ? 0 : 1, children: _jsx(Text, { ...(input ? {} : { dimColor: true }), children: input || 'Enter permission rule…' }) }), _jsx(Text, { dimColor: true, children: "Enter to submit \u00B7 Esc to cancel" })] })) : menu?.kind === 'workspace-directory-input' ? (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "Add directory to workspace" }), _jsx(Text, { children: "Praxis Code will be able to read files in this directory and make edits when auto-accept edits is on." }), _jsx(Text, { children: " " }), _jsx(Text, { children: "Enter the path to the directory:" }), _jsx(Box, { borderStyle: axScreenReader ? undefined : 'round', paddingX: axScreenReader ? 0 : 1, children: _jsx(Text, { ...(input ? {} : { dimColor: true }), children: input || 'Directory path…' }) }), _jsx(Text, { dimColor: true, children: "Tab to complete \u00B7 Enter to add \u00B7 Esc to cancel" })] })) : menu?.kind === 'permission-delete' ? (_jsxs(DialogFrame, { title: permissionDeleteTitle(menu.rule.behavior), screenReader: axScreenReader, children: [_jsx(Text, { children: menu.rule.rule }), permissionRuleDescription(menu.rule.rule) ? (_jsx(Text, { dimColor: true, children: permissionRuleDescription(menu.rule.rule) })) : null, _jsx(Text, { dimColor: true, children: permissionScopeLabel(menu.rule.scope) }), _jsx(Text, { children: " " }), _jsx(Text, { children: "Are you sure you want to delete this permission rule?" }), _jsx(Text, { children: " " }), _jsxs(Text, { inverse: !axScreenReader && menu.selectedIndex === 0, children: [selectionPrefix(menu.selectedIndex === 0, axScreenReader), "1. Yes"] }), _jsxs(Text, { inverse: !axScreenReader && menu.selectedIndex === 1, children: [selectionPrefix(menu.selectedIndex === 1, axScreenReader), "2. No"] }), _jsx(Text, { dimColor: true, children: "Esc to cancel" })] })) : menu?.kind === 'workspace-directory-delete' ? (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "Remove directory from workspace?" }), _jsxs(Text, { children: [" ", menu.path] }), _jsx(Text, { children: " " }), _jsx(Text, { children: "Praxis Code will no longer have access to files in this directory." }), _jsx(Text, { children: " " }), _jsxs(Text, { inverse: !axScreenReader && menu.selectedIndex === 0, children: [selectionPrefix(menu.selectedIndex === 0, axScreenReader), "1. Yes"] }), _jsxs(Text, { inverse: !axScreenReader && menu.selectedIndex === 1, children: [selectionPrefix(menu.selectedIndex === 1, axScreenReader), "2. No"] }), _jsx(Text, { dimColor: true, children: "Enter to confirm \u00B7 Esc to cancel" })] })) : menu ? (menu.kind === 'help' ? (_jsx(HelpMenu, { tabIndex: menu.tabIndex, selectedIndex: menu.selectedIndex, builtinCommands: builtinSlashCommands, customCommands: customSlashCommands, width: width, screenReader: axScreenReader })) : menu.kind === 'diff' ? (_jsx(DiffDashboard, { snapshots: menu.snapshots, sourceIndex: menu.sourceIndex, selectedIndex: menu.selectedIndex, viewingFile: menu.viewingFile, scrollOffset: menu.scrollOffset, width: width, screenReader: axScreenReader })) : menu.kind === 'permission-dashboard' ? (_jsx(PermissionDashboard, { tabIndex: menu.tabIndex, selectedIndex: menu.selectedIndex, query: menu.query, rules: menu.rules, recentDenied: recentDenied, retryingDeniedId: retryingDeniedId, workspaceDirectories: workspaceDirectories, width: width, screenReader: axScreenReader })) : menu.kind === 'permission-scope' ? (_jsx(SelectionMenu, { title: "Where should this rule be saved?", description: `${menu.rule}${permissionRuleDescription(menu.rule)
5332
+ : 'Messages up to this point will be summarized.' }), _jsx(Text, { children: " " }), _jsxs(Text, { children: ["add context (optional): ", input] }), _jsx(Text, { dimColor: true, children: "Enter to summarize \u00B7 Esc to go back" })] })) : menu?.kind === 'permission-rule-input' ? (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: ["Add ", menu.behavior, " permission rule"] }), _jsx(Text, { children: "Permission rules are a tool name, optionally followed by a specifier in parentheses." }), _jsx(Text, { children: "e.g., WebFetch or Bash(ls *)" }), _jsx(Text, { children: " " }), _jsx(Box, { borderStyle: axScreenReader ? undefined : 'round', paddingX: axScreenReader ? 0 : 1, children: _jsx(Text, { ...(input ? {} : { dimColor: true }), children: input || 'Enter permission rule…' }) }), _jsx(Text, { dimColor: true, children: "Enter to submit \u00B7 Esc to cancel" })] })) : menu?.kind === 'workspace-directory-input' ? (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "Add directory to workspace" }), _jsx(Text, { children: "Praxis Code will be able to read files in this directory and make edits when auto-accept edits is on." }), _jsx(Text, { children: " " }), _jsx(Text, { children: "Enter the path to the directory:" }), _jsx(Box, { borderStyle: axScreenReader ? undefined : 'round', paddingX: axScreenReader ? 0 : 1, children: _jsx(Text, { ...(input ? {} : { dimColor: true }), children: input || 'Directory path…' }) }), _jsx(Text, { dimColor: true, children: "Tab to complete \u00B7 Enter to add \u00B7 Esc to cancel" })] })) : menu?.kind === 'permission-delete' ? (_jsxs(DialogFrame, { title: permissionDeleteTitle(menu.rule.behavior), screenReader: axScreenReader, children: [_jsx(Text, { children: menu.rule.rule }), permissionRuleDescription(menu.rule.rule) ? (_jsx(Text, { dimColor: true, children: permissionRuleDescription(menu.rule.rule) })) : null, _jsx(Text, { dimColor: true, children: permissionScopeLabel(menu.rule.scope) }), _jsx(Text, { children: " " }), _jsx(Text, { children: "Are you sure you want to delete this permission rule?" }), _jsx(Text, { children: " " }), _jsxs(Text, { inverse: !axScreenReader && menu.selectedIndex === 0, children: [selectionPrefix(menu.selectedIndex === 0, axScreenReader), "1. Yes"] }), _jsxs(Text, { inverse: !axScreenReader && menu.selectedIndex === 1, children: [selectionPrefix(menu.selectedIndex === 1, axScreenReader), "2. No"] }), _jsx(Text, { dimColor: true, children: "Esc to cancel" })] })) : menu?.kind === 'workspace-directory-delete' ? (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "Remove directory from workspace?" }), _jsxs(Text, { children: [" ", menu.path] }), _jsx(Text, { children: " " }), _jsx(Text, { children: "Praxis Code will no longer have access to files in this directory." }), _jsx(Text, { children: " " }), _jsxs(Text, { inverse: !axScreenReader && menu.selectedIndex === 0, children: [selectionPrefix(menu.selectedIndex === 0, axScreenReader), "1. Yes"] }), _jsxs(Text, { inverse: !axScreenReader && menu.selectedIndex === 1, children: [selectionPrefix(menu.selectedIndex === 1, axScreenReader), "2. No"] }), _jsx(Text, { dimColor: true, children: "Enter to confirm \u00B7 Esc to cancel" })] })) : menu ? (menu.kind === 'help' ? (_jsx(HelpMenu, { tabIndex: menu.tabIndex, selectedIndex: menu.selectedIndex, builtinCommands: builtinSlashCommands, customCommands: customSlashCommands, width: width, screenReader: axScreenReader })) : menu.kind === 'diff' ? (_jsx(DiffDashboard, { snapshots: menu.snapshots, sourceIndex: menu.sourceIndex, selectedIndex: menu.selectedIndex, viewingFile: menu.viewingFile, scrollOffset: menu.scrollOffset, width: width, screenReader: axScreenReader })) : menu.kind === 'permission-dashboard' ? (_jsx(PermissionDashboard, { tabIndex: menu.tabIndex, selectedIndex: menu.selectedIndex, query: menu.query, rules: menu.rules, recentDenied: recentDenied, retryingDeniedId: retryingDeniedId, workspaceDirectories: workspaceDirectories, width: width, screenReader: axScreenReader })) : menu.kind === 'sandbox' ? (_jsx(SandboxDashboard, { snapshot: menu.snapshot, tab: menu.tab, selectedIndex: menu.selectedIndex, width: width, screenReader: axScreenReader })) : menu.kind === 'permission-scope' ? (_jsx(SelectionMenu, { title: "Where should this rule be saved?", description: `${menu.rule}${permissionRuleDescription(menu.rule)
4742
5333
  ? ` · ${permissionRuleDescription(menu.rule)}`
4743
5334
  : ''}`, options: [
4744
5335
  {