(host: SlashCommandHost, args: string)
| 5 | type AddDirChoice = 'session' | 'remember' | 'cancel'; |
| 6 | |
| 7 | export async function handleAddDirCommand(host: SlashCommandHost, args: string): Promise<void> { |
| 8 | const input = args.trim(); |
| 9 | const session = host.session; |
| 10 | |
| 11 | if (input.length === 0 || input.toLowerCase() === 'list') { |
| 12 | const additionalDirs = session?.summary?.additionalDirs ?? []; |
| 13 | if (additionalDirs.length === 0) { |
| 14 | host.showStatus('No additional directories configured.'); |
| 15 | return; |
| 16 | } |
| 17 | host.showStatus(formatAdditionalDirsStatus(additionalDirs)); |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | if (session === undefined) { |
| 22 | host.showError(NO_ACTIVE_SESSION_MESSAGE); |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | host.mountEditorReplacement( |
| 27 | new ChoicePickerComponent({ |
| 28 | title: `Add directory to workspace: ${input}`, |
| 29 | hint: '↑↓ navigate · Enter confirm · Esc cancel', |
| 30 | options: [ |
| 31 | { |
| 32 | value: 'session', |
| 33 | label: 'Yes, for this session', |
| 34 | }, |
| 35 | { |
| 36 | value: 'remember', |
| 37 | label: 'Yes, and remember this directory', |
| 38 | }, |
| 39 | { |
| 40 | value: 'cancel', |
| 41 | label: 'No', |
| 42 | }, |
| 43 | ], |
| 44 | onSelect: (value) => { |
| 45 | void handleAddDirChoice(host, session.id, input, value as AddDirChoice); |
| 46 | }, |
| 47 | onCancel: () => { |
| 48 | host.restoreEditor(); |
| 49 | host.showStatus(`Did not add ${input} as a working directory.`); |
| 50 | }, |
| 51 | }), |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | function formatAdditionalDirsStatus(additionalDirs: readonly string[]): string { |
| 56 | return ['Additional directories:', ...additionalDirs.map((dir) => ` ${dir}`)].join('\n'); |
no test coverage detected