From c71b74918571c2edc98ecfcc02956bc3b9255ecb Mon Sep 17 00:00:00 2001 From: shrutip90 Date: Thu, 16 Oct 2025 16:04:16 -0700 Subject: [PATCH] fix: Add folder names in permissions dialog similar to the launch dialog (#11278) --- .../PermissionsModifyTrustDialog.test.tsx | 12 ++++++ .../PermissionsModifyTrustDialog.tsx | 41 +++++++++++-------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/packages/cli/src/ui/components/PermissionsModifyTrustDialog.test.tsx b/packages/cli/src/ui/components/PermissionsModifyTrustDialog.test.tsx index 15d6948d82..e3008782fa 100644 --- a/packages/cli/src/ui/components/PermissionsModifyTrustDialog.test.tsx +++ b/packages/cli/src/ui/components/PermissionsModifyTrustDialog.test.tsx @@ -46,6 +46,7 @@ describe('PermissionsModifyTrustDialog', () => { let mockCommitTrustLevelChange: Mock; beforeEach(() => { + mockedCwd.mockReturnValue('/test/dir'); mockUpdateTrustLevel = vi.fn(); mockCommitTrustLevelChange = vi.fn(); vi.mocked(usePermissionsModifyTrust).mockReturnValue({ @@ -120,6 +121,17 @@ describe('PermissionsModifyTrustDialog', () => { }); }); + it('should render the labels with folder names', async () => { + const { lastFrame } = renderWithProviders( + , + ); + + await waitFor(() => { + expect(lastFrame()).toContain('Trust this folder (dir)'); + expect(lastFrame()).toContain('Trust parent folder (test)'); + }); + }); + it('should call onExit when escape is pressed', async () => { const onExit = vi.fn(); const { stdin, lastFrame } = renderWithProviders( diff --git a/packages/cli/src/ui/components/PermissionsModifyTrustDialog.tsx b/packages/cli/src/ui/components/PermissionsModifyTrustDialog.tsx index 94da207842..78f1858a38 100644 --- a/packages/cli/src/ui/components/PermissionsModifyTrustDialog.tsx +++ b/packages/cli/src/ui/components/PermissionsModifyTrustDialog.tsx @@ -6,6 +6,8 @@ import { Box, Text } from 'ink'; import type React from 'react'; +import * as process from 'node:process'; +import * as path from 'node:path'; import { TrustLevel } from '../../config/trustedFolders.js'; import { useKeypress } from '../hooks/useKeypress.js'; import { usePermissionsModifyTrust } from '../hooks/usePermissionsModifyTrust.js'; @@ -19,28 +21,31 @@ interface PermissionsModifyTrustDialogProps { addItem: UseHistoryManagerReturn['addItem']; } -const TRUST_LEVEL_ITEMS = [ - { - label: 'Trust this folder', - value: TrustLevel.TRUST_FOLDER, - key: TrustLevel.TRUST_FOLDER, - }, - { - label: 'Trust parent folder', - value: TrustLevel.TRUST_PARENT, - key: TrustLevel.TRUST_PARENT, - }, - { - label: "Don't trust", - value: TrustLevel.DO_NOT_TRUST, - key: TrustLevel.DO_NOT_TRUST, - }, -]; - export function PermissionsModifyTrustDialog({ onExit, addItem, }: PermissionsModifyTrustDialogProps): React.JSX.Element { + const dirName = path.basename(process.cwd()); + const parentFolder = path.basename(path.dirname(process.cwd())); + + const TRUST_LEVEL_ITEMS = [ + { + label: `Trust this folder (${dirName})`, + value: TrustLevel.TRUST_FOLDER, + key: TrustLevel.TRUST_FOLDER, + }, + { + label: `Trust parent folder (${parentFolder})`, + value: TrustLevel.TRUST_PARENT, + key: TrustLevel.TRUST_PARENT, + }, + { + label: "Don't trust", + value: TrustLevel.DO_NOT_TRUST, + key: TrustLevel.DO_NOT_TRUST, + }, + ]; + const { cwd, currentTrustLevel,