(path: string, remember = false)
| 68 | |
| 69 | // Helper to handle adding a directory (shared by both with-path and no-path cases) |
| 70 | const handleAddDirectory = async (path: string, remember = false) => { |
| 71 | const destination: PermissionUpdateDestination = remember ? 'localSettings' : 'session'; |
| 72 | const permissionUpdate = { |
| 73 | type: 'addDirectories' as const, |
| 74 | directories: [path], |
| 75 | destination |
| 76 | }; |
| 77 | |
| 78 | // Apply to session context |
| 79 | const latestAppState = context.getAppState(); |
| 80 | const updatedContext = applyPermissionUpdate(latestAppState.toolPermissionContext, permissionUpdate); |
| 81 | context.setAppState(prev => ({ |
| 82 | ...prev, |
| 83 | toolPermissionContext: updatedContext |
| 84 | })); |
| 85 | |
| 86 | // Update sandbox config so Bash commands can access the new directory. |
| 87 | // Bootstrap state is the source of truth for session-only dirs; persisted |
| 88 | // dirs are picked up via the settings subscription, but we refresh |
| 89 | // eagerly here to avoid a race when the user acts immediately. |
| 90 | const currentDirs = getAdditionalDirectoriesForClaudeMd(); |
| 91 | if (!currentDirs.includes(path)) { |
| 92 | setAdditionalDirectoriesForClaudeMd([...currentDirs, path]); |
| 93 | } |
| 94 | SandboxManager.refreshConfig(); |
| 95 | let message: string; |
| 96 | if (remember) { |
| 97 | try { |
| 98 | persistPermissionUpdate(permissionUpdate); |
| 99 | message = `Added ${chalk.bold(path)} as a working directory and saved to local settings`; |
| 100 | } catch (error) { |
| 101 | message = `Added ${chalk.bold(path)} as a working directory. Failed to save to local settings: ${error instanceof Error ? error.message : 'Unknown error'}`; |
| 102 | } |
| 103 | } else { |
| 104 | message = `Added ${chalk.bold(path)} as a working directory for this session`; |
| 105 | } |
| 106 | const messageWithHint = `${message} ${chalk.dim('· /permissions to manage')}`; |
| 107 | onDone(messageWithHint); |
| 108 | }; |
| 109 | |
| 110 | // When no path is provided, show AddWorkspaceDirectory input form directly |
| 111 | // and return to REPL after confirmation |
nothing calls this directly
no test coverage detected