mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Merge branch 'main' into feat/subagents
This commit is contained in:
@@ -1664,9 +1664,9 @@ describe('loadCliConfig tool exclusions', () => {
|
||||
process.argv = ['node', 'script.js'];
|
||||
const argv = await parseArguments();
|
||||
const config = await loadCliConfig({}, [], 'test-session', argv);
|
||||
expect(config.getExcludeTools()).not.toContain('run_shell_command');
|
||||
expect(config.getExcludeTools()).not.toContain('replace');
|
||||
expect(config.getExcludeTools()).not.toContain('write_file');
|
||||
expect(config.getExcludeTools()).not.toContain(ShellTool.Name);
|
||||
expect(config.getExcludeTools()).not.toContain(EditTool.Name);
|
||||
expect(config.getExcludeTools()).not.toContain(WriteFileTool.Name);
|
||||
});
|
||||
|
||||
it('should not exclude interactive tools in interactive mode with YOLO', async () => {
|
||||
@@ -1674,9 +1674,9 @@ describe('loadCliConfig tool exclusions', () => {
|
||||
process.argv = ['node', 'script.js', '--yolo'];
|
||||
const argv = await parseArguments();
|
||||
const config = await loadCliConfig({}, [], 'test-session', argv);
|
||||
expect(config.getExcludeTools()).not.toContain('run_shell_command');
|
||||
expect(config.getExcludeTools()).not.toContain('replace');
|
||||
expect(config.getExcludeTools()).not.toContain('write_file');
|
||||
expect(config.getExcludeTools()).not.toContain(ShellTool.Name);
|
||||
expect(config.getExcludeTools()).not.toContain(EditTool.Name);
|
||||
expect(config.getExcludeTools()).not.toContain(WriteFileTool.Name);
|
||||
});
|
||||
|
||||
it('should exclude interactive tools in non-interactive mode without YOLO', async () => {
|
||||
@@ -1684,9 +1684,9 @@ describe('loadCliConfig tool exclusions', () => {
|
||||
process.argv = ['node', 'script.js', '-p', 'test'];
|
||||
const argv = await parseArguments();
|
||||
const config = await loadCliConfig({}, [], 'test-session', argv);
|
||||
expect(config.getExcludeTools()).toContain('run_shell_command');
|
||||
expect(config.getExcludeTools()).toContain('replace');
|
||||
expect(config.getExcludeTools()).toContain('write_file');
|
||||
expect(config.getExcludeTools()).toContain(ShellTool.Name);
|
||||
expect(config.getExcludeTools()).toContain(EditTool.Name);
|
||||
expect(config.getExcludeTools()).toContain(WriteFileTool.Name);
|
||||
});
|
||||
|
||||
it('should not exclude interactive tools in non-interactive mode with YOLO', async () => {
|
||||
@@ -1694,9 +1694,9 @@ describe('loadCliConfig tool exclusions', () => {
|
||||
process.argv = ['node', 'script.js', '-p', 'test', '--yolo'];
|
||||
const argv = await parseArguments();
|
||||
const config = await loadCliConfig({}, [], 'test-session', argv);
|
||||
expect(config.getExcludeTools()).not.toContain('run_shell_command');
|
||||
expect(config.getExcludeTools()).not.toContain('replace');
|
||||
expect(config.getExcludeTools()).not.toContain('write_file');
|
||||
expect(config.getExcludeTools()).not.toContain(ShellTool.Name);
|
||||
expect(config.getExcludeTools()).not.toContain(EditTool.Name);
|
||||
expect(config.getExcludeTools()).not.toContain(WriteFileTool.Name);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ describe('SettingsSchema', () => {
|
||||
'model',
|
||||
'hasSeenIdeIntegrationNudge',
|
||||
'folderTrustFeature',
|
||||
'enableWelcomeBack',
|
||||
];
|
||||
|
||||
expectedSettings.forEach((setting) => {
|
||||
|
||||
@@ -604,6 +604,16 @@ export const SETTINGS_SCHEMA = {
|
||||
description: 'Skip the next speaker check.',
|
||||
showInDialog: true,
|
||||
},
|
||||
enableWelcomeBack: {
|
||||
type: 'boolean',
|
||||
label: 'Enable Welcome Back',
|
||||
category: 'UI',
|
||||
requiresRestart: false,
|
||||
default: true,
|
||||
description:
|
||||
'Show welcome back dialog when returning to a project with conversation history.',
|
||||
showInDialog: true,
|
||||
},
|
||||
} as const;
|
||||
|
||||
type InferSettings<T extends SettingsSchema> = {
|
||||
|
||||
@@ -42,7 +42,10 @@ vi.mock('../ui/commands/extensionsCommand.js', () => ({
|
||||
vi.mock('../ui/commands/helpCommand.js', () => ({ helpCommand: {} }));
|
||||
vi.mock('../ui/commands/memoryCommand.js', () => ({ memoryCommand: {} }));
|
||||
vi.mock('../ui/commands/privacyCommand.js', () => ({ privacyCommand: {} }));
|
||||
vi.mock('../ui/commands/quitCommand.js', () => ({ quitCommand: {} }));
|
||||
vi.mock('../ui/commands/quitCommand.js', () => ({
|
||||
quitCommand: {},
|
||||
quitConfirmCommand: {},
|
||||
}));
|
||||
vi.mock('../ui/commands/statsCommand.js', () => ({ statsCommand: {} }));
|
||||
vi.mock('../ui/commands/themeCommand.js', () => ({ themeCommand: {} }));
|
||||
vi.mock('../ui/commands/toolsCommand.js', () => ({ toolsCommand: {} }));
|
||||
|
||||
@@ -25,9 +25,10 @@ import { initCommand } from '../ui/commands/initCommand.js';
|
||||
import { mcpCommand } from '../ui/commands/mcpCommand.js';
|
||||
import { memoryCommand } from '../ui/commands/memoryCommand.js';
|
||||
import { privacyCommand } from '../ui/commands/privacyCommand.js';
|
||||
import { quitCommand } from '../ui/commands/quitCommand.js';
|
||||
import { quitCommand, quitConfirmCommand } from '../ui/commands/quitCommand.js';
|
||||
import { restoreCommand } from '../ui/commands/restoreCommand.js';
|
||||
import { statsCommand } from '../ui/commands/statsCommand.js';
|
||||
import { summaryCommand } from '../ui/commands/summaryCommand.js';
|
||||
import { themeCommand } from '../ui/commands/themeCommand.js';
|
||||
import { toolsCommand } from '../ui/commands/toolsCommand.js';
|
||||
import { settingsCommand } from '../ui/commands/settingsCommand.js';
|
||||
@@ -72,8 +73,10 @@ export class BuiltinCommandLoader implements ICommandLoader {
|
||||
memoryCommand,
|
||||
privacyCommand,
|
||||
quitCommand,
|
||||
quitConfirmCommand,
|
||||
restoreCommand(this.config),
|
||||
statsCommand,
|
||||
summaryCommand,
|
||||
themeCommand,
|
||||
toolsCommand,
|
||||
settingsCommand,
|
||||
|
||||
@@ -23,6 +23,9 @@ import { useAuthCommand } from './hooks/useAuthCommand.js';
|
||||
import { useQwenAuth } from './hooks/useQwenAuth.js';
|
||||
import { useFolderTrust } from './hooks/useFolderTrust.js';
|
||||
import { useEditorSettings } from './hooks/useEditorSettings.js';
|
||||
import { useQuitConfirmation } from './hooks/useQuitConfirmation.js';
|
||||
import { useWelcomeBack } from './hooks/useWelcomeBack.js';
|
||||
import { useDialogClose } from './hooks/useDialogClose.js';
|
||||
import { useSlashCommandProcessor } from './hooks/slashCommandProcessor.js';
|
||||
import { useSubagentCreateDialog } from './hooks/useSubagentCreateDialog.js';
|
||||
import { useAgentsManagerDialog } from './hooks/useAgentsManagerDialog.js';
|
||||
@@ -42,6 +45,7 @@ import { QwenOAuthProgress } from './components/QwenOAuthProgress.js';
|
||||
import { EditorSettingsDialog } from './components/EditorSettingsDialog.js';
|
||||
import { FolderTrustDialog } from './components/FolderTrustDialog.js';
|
||||
import { ShellConfirmationDialog } from './components/ShellConfirmationDialog.js';
|
||||
import { QuitConfirmationDialog } from './components/QuitConfirmationDialog.js';
|
||||
import { RadioButtonSelect } from './components/shared/RadioButtonSelect.js';
|
||||
import {
|
||||
AgentCreationWizard,
|
||||
@@ -109,8 +113,8 @@ import { SettingsDialog } from './components/SettingsDialog.js';
|
||||
import { setUpdateHandler } from '../utils/handleAutoUpdate.js';
|
||||
import { appEvents, AppEvent } from '../utils/events.js';
|
||||
import { isNarrowWidth } from './utils/isNarrowWidth.js';
|
||||
import { WelcomeBackDialog } from './components/WelcomeBackDialog.js';
|
||||
|
||||
const CTRL_EXIT_PROMPT_DURATION_MS = 1000;
|
||||
// Maximum number of queued messages to display in UI to prevent performance issues
|
||||
const MAX_DISPLAYED_QUEUED_MESSAGES = 3;
|
||||
|
||||
@@ -292,6 +296,9 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
setIsTrustedFolder,
|
||||
);
|
||||
|
||||
const { showQuitConfirmation, handleQuitConfirmationSelect } =
|
||||
useQuitConfirmation();
|
||||
|
||||
const {
|
||||
isAuthDialogOpen,
|
||||
openAuthDialog,
|
||||
@@ -568,6 +575,7 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
commandContext,
|
||||
shellConfirmationRequest,
|
||||
confirmationRequest,
|
||||
quitConfirmationRequest,
|
||||
} = useSlashCommandProcessor(
|
||||
config,
|
||||
settings,
|
||||
@@ -588,6 +596,7 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
toggleVimEnabled,
|
||||
setIsProcessing,
|
||||
setGeminiMdFileCount,
|
||||
showQuitConfirmation,
|
||||
);
|
||||
|
||||
const buffer = useTextBuffer({
|
||||
@@ -628,6 +637,34 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
() => cancelHandlerRef.current(),
|
||||
);
|
||||
|
||||
// Welcome back functionality
|
||||
const {
|
||||
welcomeBackInfo,
|
||||
showWelcomeBackDialog,
|
||||
welcomeBackChoice,
|
||||
handleWelcomeBackSelection,
|
||||
handleWelcomeBackClose,
|
||||
} = useWelcomeBack(config, submitQuery, buffer, settings.merged);
|
||||
|
||||
// Dialog close functionality
|
||||
const { closeAnyOpenDialog } = useDialogClose({
|
||||
isThemeDialogOpen,
|
||||
handleThemeSelect,
|
||||
isAuthDialogOpen,
|
||||
handleAuthSelect,
|
||||
selectedAuthType: settings.merged.selectedAuthType,
|
||||
isEditorDialogOpen,
|
||||
exitEditorDialog,
|
||||
isSettingsDialogOpen,
|
||||
closeSettingsDialog,
|
||||
isFolderTrustDialogOpen,
|
||||
showPrivacyNotice,
|
||||
setShowPrivacyNotice,
|
||||
showWelcomeBackDialog,
|
||||
handleWelcomeBackClose,
|
||||
quitConfirmationRequest,
|
||||
});
|
||||
|
||||
// Message queue for handling input during streaming
|
||||
const { messageQueue, addMessage, clearQueue, getQueuedMessagesText } =
|
||||
useMessageQueue({
|
||||
@@ -699,21 +736,52 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
setPressedOnce: (value: boolean) => void,
|
||||
timerRef: ReturnType<typeof useRef<NodeJS.Timeout | null>>,
|
||||
) => {
|
||||
// Fast double-press: Direct quit (preserve user habit)
|
||||
if (pressedOnce) {
|
||||
if (timerRef.current) {
|
||||
clearTimeout(timerRef.current);
|
||||
}
|
||||
// Directly invoke the central command handler.
|
||||
// Exit directly without showing confirmation dialog
|
||||
handleSlashCommand('/quit');
|
||||
} else {
|
||||
setPressedOnce(true);
|
||||
timerRef.current = setTimeout(() => {
|
||||
setPressedOnce(false);
|
||||
timerRef.current = null;
|
||||
}, CTRL_EXIT_PROMPT_DURATION_MS);
|
||||
return;
|
||||
}
|
||||
|
||||
// First press: Prioritize cleanup tasks
|
||||
|
||||
// Special case: If quit-confirm dialog is open, Ctrl+C means "quit immediately"
|
||||
if (quitConfirmationRequest) {
|
||||
handleSlashCommand('/quit');
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. Close other dialogs (highest priority)
|
||||
if (closeAnyOpenDialog()) {
|
||||
return; // Dialog closed, end processing
|
||||
}
|
||||
|
||||
// 2. Cancel ongoing requests
|
||||
if (streamingState === StreamingState.Responding) {
|
||||
cancelOngoingRequest?.();
|
||||
return; // Request cancelled, end processing
|
||||
}
|
||||
|
||||
// 3. Clear input buffer (if has content)
|
||||
if (buffer.text.length > 0) {
|
||||
buffer.setText('');
|
||||
return; // Input cleared, end processing
|
||||
}
|
||||
|
||||
// All cleanup tasks completed, show quit confirmation dialog
|
||||
handleSlashCommand('/quit-confirm');
|
||||
},
|
||||
[handleSlashCommand],
|
||||
[
|
||||
handleSlashCommand,
|
||||
quitConfirmationRequest,
|
||||
closeAnyOpenDialog,
|
||||
streamingState,
|
||||
cancelOngoingRequest,
|
||||
buffer,
|
||||
],
|
||||
);
|
||||
|
||||
const handleGlobalKeypress = useCallback(
|
||||
@@ -746,9 +814,6 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
if (isAuthenticating) {
|
||||
return;
|
||||
}
|
||||
if (!ctrlCPressedOnce) {
|
||||
cancelOngoingRequest?.();
|
||||
}
|
||||
handleExit(ctrlCPressedOnce, setCtrlCPressedOnce, ctrlCTimerRef);
|
||||
} else if (keyMatchers[Command.EXIT](key)) {
|
||||
if (buffer.text.length > 0) {
|
||||
@@ -780,7 +845,6 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
ctrlDTimerRef,
|
||||
handleSlashCommand,
|
||||
isAuthenticating,
|
||||
cancelOngoingRequest,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -836,7 +900,8 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
(streamingState === StreamingState.Idle ||
|
||||
streamingState === StreamingState.Responding) &&
|
||||
!initError &&
|
||||
!isProcessing;
|
||||
!isProcessing &&
|
||||
!showWelcomeBackDialog;
|
||||
|
||||
const handleClearScreen = useCallback(() => {
|
||||
clearItems();
|
||||
@@ -916,6 +981,8 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
!isEditorDialogOpen &&
|
||||
!isSubagentCreateDialogOpen &&
|
||||
!showPrivacyNotice &&
|
||||
!showWelcomeBackDialog &&
|
||||
welcomeBackChoice !== 'restart' &&
|
||||
geminiClient?.isInitialized?.()
|
||||
) {
|
||||
submitQuery(initialPrompt);
|
||||
@@ -930,6 +997,8 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
isEditorDialogOpen,
|
||||
isSubagentCreateDialogOpen,
|
||||
showPrivacyNotice,
|
||||
showWelcomeBackDialog,
|
||||
welcomeBackChoice,
|
||||
geminiClient,
|
||||
]);
|
||||
|
||||
@@ -1038,6 +1107,13 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
))}
|
||||
</Box>
|
||||
)}
|
||||
{showWelcomeBackDialog && welcomeBackInfo?.hasHistory && (
|
||||
<WelcomeBackDialog
|
||||
welcomeBackInfo={welcomeBackInfo}
|
||||
onSelect={handleWelcomeBackSelection}
|
||||
onClose={handleWelcomeBackClose}
|
||||
/>
|
||||
)}
|
||||
|
||||
{shouldShowIdePrompt && currentIDE ? (
|
||||
<IdeIntegrationNudge
|
||||
@@ -1046,6 +1122,17 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
/>
|
||||
) : isFolderTrustDialogOpen ? (
|
||||
<FolderTrustDialog onSelect={handleFolderTrustSelect} />
|
||||
) : quitConfirmationRequest ? (
|
||||
<QuitConfirmationDialog
|
||||
onSelect={(choice) => {
|
||||
const result = handleQuitConfirmationSelect(choice);
|
||||
if (result?.shouldQuit) {
|
||||
quitConfirmationRequest.onConfirm(true, result.action);
|
||||
} else {
|
||||
quitConfirmationRequest.onConfirm(false);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
) : shellConfirmationRequest ? (
|
||||
<ShellConfirmationDialog request={shellConfirmationRequest} />
|
||||
) : confirmationRequest ? (
|
||||
@@ -1240,7 +1327,7 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||
)}
|
||||
{ctrlCPressedOnce ? (
|
||||
<Text color={Colors.AccentYellow}>
|
||||
Press Ctrl+C again to exit.
|
||||
Press Ctrl+C again to confirm exit.
|
||||
</Text>
|
||||
) : ctrlDPressedOnce ? (
|
||||
<Text color={Colors.AccentYellow}>
|
||||
|
||||
@@ -7,6 +7,33 @@
|
||||
import { formatDuration } from '../utils/formatters.js';
|
||||
import { CommandKind, type SlashCommand } from './types.js';
|
||||
|
||||
export const quitConfirmCommand: SlashCommand = {
|
||||
name: 'quit-confirm',
|
||||
description: 'Show quit confirmation dialog',
|
||||
kind: CommandKind.BUILT_IN,
|
||||
action: (context) => {
|
||||
const now = Date.now();
|
||||
const { sessionStartTime } = context.session.stats;
|
||||
const wallDuration = now - sessionStartTime.getTime();
|
||||
|
||||
return {
|
||||
type: 'quit_confirmation',
|
||||
messages: [
|
||||
{
|
||||
type: 'user',
|
||||
text: `/quit-confirm`,
|
||||
id: now - 1,
|
||||
},
|
||||
{
|
||||
type: 'quit_confirmation',
|
||||
duration: formatDuration(wallDuration),
|
||||
id: now,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export const quitCommand: SlashCommand = {
|
||||
name: 'quit',
|
||||
altNames: ['exit'],
|
||||
|
||||
189
packages/cli/src/ui/commands/summaryCommand.ts
Normal file
189
packages/cli/src/ui/commands/summaryCommand.ts
Normal file
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Qwen
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import * as fsPromises from 'fs/promises';
|
||||
import path from 'path';
|
||||
import {
|
||||
SlashCommand,
|
||||
CommandKind,
|
||||
SlashCommandActionReturn,
|
||||
} from './types.js';
|
||||
import { getProjectSummaryPrompt } from '@qwen-code/qwen-code-core';
|
||||
import { HistoryItemSummary } from '../types.js';
|
||||
|
||||
export const summaryCommand: SlashCommand = {
|
||||
name: 'summary',
|
||||
description:
|
||||
'Generate a project summary and save it to .qwen/PROJECT_SUMMARY.md',
|
||||
kind: CommandKind.BUILT_IN,
|
||||
action: async (context): Promise<SlashCommandActionReturn> => {
|
||||
const { config } = context.services;
|
||||
const { ui } = context;
|
||||
if (!config) {
|
||||
return {
|
||||
type: 'message',
|
||||
messageType: 'error',
|
||||
content: 'Config not loaded.',
|
||||
};
|
||||
}
|
||||
|
||||
const geminiClient = config.getGeminiClient();
|
||||
if (!geminiClient) {
|
||||
return {
|
||||
type: 'message',
|
||||
messageType: 'error',
|
||||
content: 'No chat client available to generate summary.',
|
||||
};
|
||||
}
|
||||
|
||||
// Check if already generating summary
|
||||
if (ui.pendingItem) {
|
||||
ui.addItem(
|
||||
{
|
||||
type: 'error' as const,
|
||||
text: 'Already generating summary, wait for previous request to complete',
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
return {
|
||||
type: 'message',
|
||||
messageType: 'error',
|
||||
content:
|
||||
'Already generating summary, wait for previous request to complete',
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
// Get the current chat history
|
||||
const chat = geminiClient.getChat();
|
||||
const history = chat.getHistory();
|
||||
|
||||
if (history.length <= 2) {
|
||||
return {
|
||||
type: 'message',
|
||||
messageType: 'info',
|
||||
content: 'No conversation found to summarize.',
|
||||
};
|
||||
}
|
||||
|
||||
// Show loading state
|
||||
const pendingMessage: HistoryItemSummary = {
|
||||
type: 'summary',
|
||||
summary: {
|
||||
isPending: true,
|
||||
stage: 'generating',
|
||||
},
|
||||
};
|
||||
ui.setPendingItem(pendingMessage);
|
||||
|
||||
// Build the conversation context for summary generation
|
||||
const conversationContext = history.map((message) => ({
|
||||
role: message.role,
|
||||
parts: message.parts,
|
||||
}));
|
||||
|
||||
// Use generateContent with chat history as context
|
||||
const response = await geminiClient.generateContent(
|
||||
[
|
||||
...conversationContext,
|
||||
{
|
||||
role: 'user',
|
||||
parts: [
|
||||
{
|
||||
text: getProjectSummaryPrompt(),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
{},
|
||||
new AbortController().signal,
|
||||
);
|
||||
|
||||
// Extract text from response
|
||||
const parts = response.candidates?.[0]?.content?.parts;
|
||||
|
||||
const markdownSummary =
|
||||
parts
|
||||
?.map((part) => part.text)
|
||||
.filter((text): text is string => typeof text === 'string')
|
||||
.join('') || '';
|
||||
|
||||
if (!markdownSummary) {
|
||||
throw new Error(
|
||||
'Failed to generate summary - no text content received from LLM response',
|
||||
);
|
||||
}
|
||||
|
||||
// Update loading message to show saving progress
|
||||
ui.setPendingItem({
|
||||
type: 'summary',
|
||||
summary: {
|
||||
isPending: true,
|
||||
stage: 'saving',
|
||||
},
|
||||
});
|
||||
|
||||
// Ensure .qwen directory exists
|
||||
const projectRoot = config.getProjectRoot();
|
||||
const qwenDir = path.join(projectRoot, '.qwen');
|
||||
try {
|
||||
await fsPromises.mkdir(qwenDir, { recursive: true });
|
||||
} catch (_err) {
|
||||
// Directory might already exist, ignore error
|
||||
}
|
||||
|
||||
// Save the summary to PROJECT_SUMMARY.md
|
||||
const summaryPath = path.join(qwenDir, 'PROJECT_SUMMARY.md');
|
||||
const summaryContent = `${markdownSummary}
|
||||
|
||||
---
|
||||
|
||||
## Summary Metadata
|
||||
**Update time**: ${new Date().toISOString()}
|
||||
`;
|
||||
|
||||
await fsPromises.writeFile(summaryPath, summaryContent, 'utf8');
|
||||
|
||||
// Clear pending item and show success message
|
||||
ui.setPendingItem(null);
|
||||
const completedSummaryItem: HistoryItemSummary = {
|
||||
type: 'summary',
|
||||
summary: {
|
||||
isPending: false,
|
||||
stage: 'completed',
|
||||
filePath: '.qwen/PROJECT_SUMMARY.md',
|
||||
},
|
||||
};
|
||||
ui.addItem(completedSummaryItem, Date.now());
|
||||
|
||||
return {
|
||||
type: 'message',
|
||||
messageType: 'info',
|
||||
content: '', // Empty content since we show the message in UI component
|
||||
};
|
||||
} catch (error) {
|
||||
// Clear pending item on error
|
||||
ui.setPendingItem(null);
|
||||
ui.addItem(
|
||||
{
|
||||
type: 'error' as const,
|
||||
text: `❌ Failed to generate project context summary: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
|
||||
return {
|
||||
type: 'message',
|
||||
messageType: 'error',
|
||||
content: `Failed to generate project context summary: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -88,6 +88,12 @@ export interface QuitActionReturn {
|
||||
messages: HistoryItem[];
|
||||
}
|
||||
|
||||
/** The return type for a command action that requests quit confirmation. */
|
||||
export interface QuitConfirmationActionReturn {
|
||||
type: 'quit_confirmation';
|
||||
messages: HistoryItem[];
|
||||
}
|
||||
|
||||
/**
|
||||
* The return type for a command action that results in a simple message
|
||||
* being displayed to the user.
|
||||
@@ -162,6 +168,7 @@ export type SlashCommandActionReturn =
|
||||
| ToolActionReturn
|
||||
| MessageActionReturn
|
||||
| QuitActionReturn
|
||||
| QuitConfirmationActionReturn
|
||||
| OpenDialogActionReturn
|
||||
| LoadHistoryActionReturn
|
||||
| SubmitPromptActionReturn
|
||||
|
||||
@@ -123,7 +123,7 @@ export function AuthDialog({
|
||||
if (settings.merged.selectedAuthType === undefined) {
|
||||
// Prevent exiting if no auth method is set
|
||||
setErrorMessage(
|
||||
'You must select an auth method to proceed. Press Ctrl+C twice to exit.',
|
||||
'You must select an auth method to proceed. Press Ctrl+C again to exit.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ export const Help: React.FC<Help> = ({ commands }) => (
|
||||
<Text bold color={Colors.AccentPurple}>
|
||||
Ctrl+C
|
||||
</Text>{' '}
|
||||
- Quit application
|
||||
- Close dialogs, cancel requests, or quit application
|
||||
</Text>
|
||||
<Text color={Colors.Foreground}>
|
||||
<Text bold color={Colors.AccentPurple}>
|
||||
|
||||
@@ -14,6 +14,7 @@ import { ErrorMessage } from './messages/ErrorMessage.js';
|
||||
import { ToolGroupMessage } from './messages/ToolGroupMessage.js';
|
||||
import { GeminiMessageContent } from './messages/GeminiMessageContent.js';
|
||||
import { CompressionMessage } from './messages/CompressionMessage.js';
|
||||
import { SummaryMessage } from './messages/SummaryMessage.js';
|
||||
import { Box } from 'ink';
|
||||
import { AboutBox } from './AboutBox.js';
|
||||
import { StatsDisplay } from './StatsDisplay.js';
|
||||
@@ -81,6 +82,9 @@ export const HistoryItemDisplay: React.FC<HistoryItemDisplayProps> = ({
|
||||
{item.type === 'model_stats' && <ModelStatsDisplay />}
|
||||
{item.type === 'tool_stats' && <ToolStatsDisplay />}
|
||||
{item.type === 'quit' && <SessionSummaryDisplay duration={item.duration} />}
|
||||
{item.type === 'quit_confirmation' && (
|
||||
<SessionSummaryDisplay duration={item.duration} />
|
||||
)}
|
||||
{item.type === 'tool_group' && (
|
||||
<ToolGroupMessage
|
||||
toolCalls={item.tools}
|
||||
@@ -94,5 +98,6 @@ export const HistoryItemDisplay: React.FC<HistoryItemDisplayProps> = ({
|
||||
{item.type === 'compression' && (
|
||||
<CompressionMessage compression={item.compression} />
|
||||
)}
|
||||
{item.type === 'summary' && <SummaryMessage summary={item.summary} />}
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -18,7 +18,9 @@ describe('OpenAIKeyPrompt', () => {
|
||||
);
|
||||
|
||||
expect(lastFrame()).toContain('OpenAI Configuration Required');
|
||||
expect(lastFrame()).toContain('https://platform.openai.com/api-keys');
|
||||
expect(lastFrame()).toContain(
|
||||
'https://bailian.console.aliyun.com/?tab=model#/api-key',
|
||||
);
|
||||
expect(lastFrame()).toContain(
|
||||
'Press Enter to continue, Tab/↑↓ to navigate, Esc to cancel',
|
||||
);
|
||||
|
||||
@@ -138,7 +138,7 @@ export function OpenAIKeyPrompt({
|
||||
<Text>
|
||||
Please enter your OpenAI configuration. You can get an API key from{' '}
|
||||
<Text color={Colors.AccentBlue}>
|
||||
https://platform.openai.com/api-keys
|
||||
https://bailian.console.aliyun.com/?tab=model#/api-key
|
||||
</Text>
|
||||
</Text>
|
||||
</Box>
|
||||
|
||||
74
packages/cli/src/ui/components/QuitConfirmationDialog.tsx
Normal file
74
packages/cli/src/ui/components/QuitConfirmationDialog.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Qwen
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { Box, Text } from 'ink';
|
||||
import React from 'react';
|
||||
import { Colors } from '../colors.js';
|
||||
import {
|
||||
RadioButtonSelect,
|
||||
RadioSelectItem,
|
||||
} from './shared/RadioButtonSelect.js';
|
||||
import { useKeypress } from '../hooks/useKeypress.js';
|
||||
|
||||
export enum QuitChoice {
|
||||
CANCEL = 'cancel',
|
||||
QUIT = 'quit',
|
||||
SAVE_AND_QUIT = 'save_and_quit',
|
||||
SUMMARY_AND_QUIT = 'summary_and_quit',
|
||||
}
|
||||
|
||||
interface QuitConfirmationDialogProps {
|
||||
onSelect: (choice: QuitChoice) => void;
|
||||
}
|
||||
|
||||
export const QuitConfirmationDialog: React.FC<QuitConfirmationDialogProps> = ({
|
||||
onSelect,
|
||||
}) => {
|
||||
useKeypress(
|
||||
(key) => {
|
||||
if (key.name === 'escape') {
|
||||
onSelect(QuitChoice.CANCEL);
|
||||
}
|
||||
},
|
||||
{ isActive: true },
|
||||
);
|
||||
|
||||
const options: Array<RadioSelectItem<QuitChoice>> = [
|
||||
{
|
||||
label: 'Quit immediately (/quit)',
|
||||
value: QuitChoice.QUIT,
|
||||
},
|
||||
{
|
||||
label: 'Generate summary and quit (/summary)',
|
||||
value: QuitChoice.SUMMARY_AND_QUIT,
|
||||
},
|
||||
{
|
||||
label: 'Save conversation and quit (/chat save)',
|
||||
value: QuitChoice.SAVE_AND_QUIT,
|
||||
},
|
||||
{
|
||||
label: 'Cancel (stay in application)',
|
||||
value: QuitChoice.CANCEL,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Box
|
||||
flexDirection="column"
|
||||
borderStyle="round"
|
||||
borderColor={Colors.AccentYellow}
|
||||
padding={1}
|
||||
width="100%"
|
||||
marginLeft={1}
|
||||
>
|
||||
<Box flexDirection="column" marginBottom={1}>
|
||||
<Text>What would you like to do before exiting?</Text>
|
||||
</Box>
|
||||
|
||||
<RadioButtonSelect items={options} onSelect={onSelect} isFocused />
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
123
packages/cli/src/ui/components/WelcomeBackDialog.tsx
Normal file
123
packages/cli/src/ui/components/WelcomeBackDialog.tsx
Normal file
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { Box, Text } from 'ink';
|
||||
import { Colors } from '../colors.js';
|
||||
import { ProjectSummaryInfo } from '@qwen-code/qwen-code-core';
|
||||
import {
|
||||
RadioButtonSelect,
|
||||
RadioSelectItem,
|
||||
} from './shared/RadioButtonSelect.js';
|
||||
import { useKeypress } from '../hooks/useKeypress.js';
|
||||
|
||||
interface WelcomeBackDialogProps {
|
||||
welcomeBackInfo: ProjectSummaryInfo;
|
||||
onSelect: (choice: 'restart' | 'continue') => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export function WelcomeBackDialog({
|
||||
welcomeBackInfo,
|
||||
onSelect,
|
||||
onClose,
|
||||
}: WelcomeBackDialogProps) {
|
||||
useKeypress(
|
||||
(key) => {
|
||||
if (key.name === 'escape') {
|
||||
onClose();
|
||||
}
|
||||
},
|
||||
{ isActive: true },
|
||||
);
|
||||
|
||||
const options: Array<RadioSelectItem<'restart' | 'continue'>> = [
|
||||
{
|
||||
label: 'Start new chat session',
|
||||
value: 'restart',
|
||||
},
|
||||
{
|
||||
label: 'Continue previous conversation',
|
||||
value: 'continue',
|
||||
},
|
||||
];
|
||||
|
||||
// Extract data from welcomeBackInfo
|
||||
const {
|
||||
timeAgo,
|
||||
goalContent,
|
||||
totalTasks = 0,
|
||||
doneCount = 0,
|
||||
inProgressCount = 0,
|
||||
pendingTasks = [],
|
||||
} = welcomeBackInfo;
|
||||
|
||||
return (
|
||||
<Box
|
||||
flexDirection="column"
|
||||
borderStyle="round"
|
||||
borderColor={Colors.AccentBlue}
|
||||
padding={1}
|
||||
width="100%"
|
||||
marginLeft={1}
|
||||
>
|
||||
<Box flexDirection="column" marginBottom={1}>
|
||||
<Text color={Colors.AccentBlue} bold>
|
||||
👋 Welcome back! (Last updated: {timeAgo})
|
||||
</Text>
|
||||
</Box>
|
||||
|
||||
{/* Overall Goal Section */}
|
||||
{goalContent && (
|
||||
<Box flexDirection="column" marginBottom={1}>
|
||||
<Text color={Colors.Foreground} bold>
|
||||
🎯 Overall Goal:
|
||||
</Text>
|
||||
<Box marginTop={1} paddingLeft={2}>
|
||||
<Text color={Colors.Gray}>{goalContent}</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{/* Current Plan Section */}
|
||||
{totalTasks > 0 && (
|
||||
<Box flexDirection="column" marginBottom={1}>
|
||||
<Text color={Colors.Foreground} bold>
|
||||
📋 Current Plan:
|
||||
</Text>
|
||||
<Box marginTop={1} paddingLeft={2}>
|
||||
<Text color={Colors.Gray}>
|
||||
Progress: {doneCount}/{totalTasks} tasks completed
|
||||
{inProgressCount > 0 && `, ${inProgressCount} in progress`}
|
||||
</Text>
|
||||
</Box>
|
||||
|
||||
{pendingTasks.length > 0 && (
|
||||
<Box flexDirection="column" marginTop={1} paddingLeft={2}>
|
||||
<Text color={Colors.Foreground} bold>
|
||||
Pending Tasks:
|
||||
</Text>
|
||||
{pendingTasks.map((task: string, index: number) => (
|
||||
<Text key={index} color={Colors.Gray}>
|
||||
• {task}
|
||||
</Text>
|
||||
))}
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{/* Action Selection */}
|
||||
<Box flexDirection="column" marginTop={1}>
|
||||
<Text bold>What would you like to do?</Text>
|
||||
<Text>Choose how to proceed with your session:</Text>
|
||||
</Box>
|
||||
|
||||
<Box marginTop={1}>
|
||||
<RadioButtonSelect items={options} onSelect={onSelect} isFocused />
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -14,6 +14,11 @@ interface InfoMessageProps {
|
||||
}
|
||||
|
||||
export const InfoMessage: React.FC<InfoMessageProps> = ({ text }) => {
|
||||
// Don't render anything if text is empty
|
||||
if (!text || text.trim() === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const prefix = 'ℹ ';
|
||||
const prefixWidth = prefix.length;
|
||||
|
||||
|
||||
59
packages/cli/src/ui/components/messages/SummaryMessage.tsx
Normal file
59
packages/cli/src/ui/components/messages/SummaryMessage.tsx
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Qwen
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Box, Text } from 'ink';
|
||||
import { SummaryProps } from '../../types.js';
|
||||
import Spinner from 'ink-spinner';
|
||||
import { Colors } from '../../colors.js';
|
||||
|
||||
export interface SummaryDisplayProps {
|
||||
summary: SummaryProps;
|
||||
}
|
||||
|
||||
/*
|
||||
* Summary messages appear when the /chat summary command is run, and show a loading spinner
|
||||
* while summary generation is in progress, followed up by success confirmation.
|
||||
*/
|
||||
export const SummaryMessage: React.FC<SummaryDisplayProps> = ({ summary }) => {
|
||||
const getText = () => {
|
||||
if (summary.isPending) {
|
||||
switch (summary.stage) {
|
||||
case 'generating':
|
||||
return 'Generating project summary...';
|
||||
case 'saving':
|
||||
return 'Saving project summary...';
|
||||
default:
|
||||
return 'Processing summary...';
|
||||
}
|
||||
}
|
||||
const baseMessage = 'Project summary generated and saved successfully!';
|
||||
if (summary.filePath) {
|
||||
return `${baseMessage} Saved to: ${summary.filePath}`;
|
||||
}
|
||||
return baseMessage;
|
||||
};
|
||||
|
||||
const getIcon = () => {
|
||||
if (summary.isPending) {
|
||||
return <Spinner type="dots" />;
|
||||
}
|
||||
return <Text color={Colors.AccentGreen}>✅</Text>;
|
||||
};
|
||||
|
||||
return (
|
||||
<Box flexDirection="row">
|
||||
<Box marginRight={1}>{getIcon()}</Box>
|
||||
<Box>
|
||||
<Text
|
||||
color={summary.isPending ? Colors.AccentPurple : Colors.AccentGreen}
|
||||
>
|
||||
{getText()}
|
||||
</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -437,7 +437,7 @@ describe('useSlashCommandProcessor', () => {
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(200);
|
||||
await vi.advanceTimersByTimeAsync(1000); // Advance by 1000ms to trigger the setTimeout callback
|
||||
});
|
||||
|
||||
expect(mockSetQuittingMessages).toHaveBeenCalledWith([]);
|
||||
@@ -469,7 +469,7 @@ describe('useSlashCommandProcessor', () => {
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(200);
|
||||
await vi.advanceTimersByTimeAsync(1000); // Advance by 1000ms to trigger the setTimeout callback
|
||||
});
|
||||
|
||||
expect(mockRunExitCleanup).toHaveBeenCalledTimes(1);
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
ToolConfirmationOutcome,
|
||||
} from '@qwen-code/qwen-code-core';
|
||||
import { useSessionStats } from '../contexts/SessionContext.js';
|
||||
import { formatDuration } from '../utils/formatters.js';
|
||||
import { runExitCleanup } from '../../utils/cleanup.js';
|
||||
import {
|
||||
Message,
|
||||
@@ -56,6 +57,7 @@ export const useSlashCommandProcessor = (
|
||||
toggleVimEnabled: () => Promise<boolean>,
|
||||
setIsProcessing: (isProcessing: boolean) => void,
|
||||
setGeminiMdFileCount: (count: number) => void,
|
||||
_showQuitConfirmation: () => void,
|
||||
) => {
|
||||
const session = useSessionStats();
|
||||
const [commands, setCommands] = useState<readonly SlashCommand[]>([]);
|
||||
@@ -76,6 +78,10 @@ export const useSlashCommandProcessor = (
|
||||
prompt: React.ReactNode;
|
||||
onConfirm: (confirmed: boolean) => void;
|
||||
}>(null);
|
||||
const [quitConfirmationRequest, setQuitConfirmationRequest] =
|
||||
useState<null | {
|
||||
onConfirm: (shouldQuit: boolean, action?: string) => void;
|
||||
}>(null);
|
||||
|
||||
const [sessionShellAllowlist, setSessionShellAllowlist] = useState(
|
||||
new Set<string>(),
|
||||
@@ -143,11 +149,21 @@ export const useSlashCommandProcessor = (
|
||||
type: 'quit',
|
||||
duration: message.duration,
|
||||
};
|
||||
} else if (message.type === MessageType.QUIT_CONFIRMATION) {
|
||||
historyItemContent = {
|
||||
type: 'quit_confirmation',
|
||||
duration: message.duration,
|
||||
};
|
||||
} else if (message.type === MessageType.COMPRESSION) {
|
||||
historyItemContent = {
|
||||
type: 'compression',
|
||||
compression: message.compression,
|
||||
};
|
||||
} else if (message.type === MessageType.SUMMARY) {
|
||||
historyItemContent = {
|
||||
type: 'summary',
|
||||
summary: message.summary,
|
||||
};
|
||||
} else {
|
||||
historyItemContent = {
|
||||
type: message.type,
|
||||
@@ -409,12 +425,85 @@ export const useSlashCommandProcessor = (
|
||||
});
|
||||
return { type: 'handled' };
|
||||
}
|
||||
case 'quit_confirmation':
|
||||
// Show quit confirmation dialog instead of immediately quitting
|
||||
setQuitConfirmationRequest({
|
||||
onConfirm: (shouldQuit: boolean, action?: string) => {
|
||||
setQuitConfirmationRequest(null);
|
||||
if (!shouldQuit) {
|
||||
// User cancelled the quit operation - do nothing
|
||||
return;
|
||||
}
|
||||
if (shouldQuit) {
|
||||
if (action === 'save_and_quit') {
|
||||
// First save conversation with auto-generated tag, then quit
|
||||
const timestamp = new Date()
|
||||
.toISOString()
|
||||
.replace(/[:.]/g, '-');
|
||||
const autoSaveTag = `auto-save chat ${timestamp}`;
|
||||
handleSlashCommand(`/chat save "${autoSaveTag}"`);
|
||||
setTimeout(() => handleSlashCommand('/quit'), 100);
|
||||
} else if (action === 'summary_and_quit') {
|
||||
// Generate summary and then quit
|
||||
handleSlashCommand('/summary')
|
||||
.then(() => {
|
||||
// Wait for user to see the summary result
|
||||
setTimeout(() => {
|
||||
handleSlashCommand('/quit');
|
||||
}, 1200);
|
||||
})
|
||||
.catch((error) => {
|
||||
// If summary fails, still quit but show error
|
||||
addItem(
|
||||
{
|
||||
type: 'error',
|
||||
text: `Failed to generate summary before quit: ${
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: String(error)
|
||||
}`,
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
// Give user time to see the error message
|
||||
setTimeout(() => {
|
||||
handleSlashCommand('/quit');
|
||||
}, 1000);
|
||||
});
|
||||
} else {
|
||||
// Just quit immediately - trigger the actual quit action
|
||||
const now = Date.now();
|
||||
const { sessionStartTime } = session.stats;
|
||||
const wallDuration = now - sessionStartTime.getTime();
|
||||
|
||||
setQuittingMessages([
|
||||
{
|
||||
type: 'user',
|
||||
text: `/quit`,
|
||||
id: now - 1,
|
||||
},
|
||||
{
|
||||
type: 'quit',
|
||||
duration: formatDuration(wallDuration),
|
||||
id: now,
|
||||
},
|
||||
]);
|
||||
setTimeout(async () => {
|
||||
await runExitCleanup();
|
||||
process.exit(0);
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
return { type: 'handled' };
|
||||
|
||||
case 'quit':
|
||||
setQuittingMessages(result.messages);
|
||||
setTimeout(async () => {
|
||||
await runExitCleanup();
|
||||
process.exit(0);
|
||||
}, 100);
|
||||
}, 1000);
|
||||
return { type: 'handled' };
|
||||
|
||||
case 'submit_prompt':
|
||||
@@ -570,6 +659,7 @@ export const useSlashCommandProcessor = (
|
||||
setSessionShellAllowlist,
|
||||
setIsProcessing,
|
||||
setConfirmationRequest,
|
||||
session.stats,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -580,5 +670,6 @@ export const useSlashCommandProcessor = (
|
||||
commandContext,
|
||||
shellConfirmationRequest,
|
||||
confirmationRequest,
|
||||
quitConfirmationRequest,
|
||||
};
|
||||
};
|
||||
|
||||
112
packages/cli/src/ui/hooks/useDialogClose.ts
Normal file
112
packages/cli/src/ui/hooks/useDialogClose.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { useCallback } from 'react';
|
||||
import { SettingScope } from '../../config/settings.js';
|
||||
import { AuthType } from '@qwen-code/qwen-code-core';
|
||||
|
||||
export interface DialogCloseOptions {
|
||||
// Theme dialog
|
||||
isThemeDialogOpen: boolean;
|
||||
handleThemeSelect: (theme: string | undefined, scope: SettingScope) => void;
|
||||
|
||||
// Auth dialog
|
||||
isAuthDialogOpen: boolean;
|
||||
handleAuthSelect: (
|
||||
authType: AuthType | undefined,
|
||||
scope: SettingScope,
|
||||
) => Promise<void>;
|
||||
selectedAuthType: AuthType | undefined;
|
||||
|
||||
// Editor dialog
|
||||
isEditorDialogOpen: boolean;
|
||||
exitEditorDialog: () => void;
|
||||
|
||||
// Settings dialog
|
||||
isSettingsDialogOpen: boolean;
|
||||
closeSettingsDialog: () => void;
|
||||
|
||||
// Folder trust dialog
|
||||
isFolderTrustDialogOpen: boolean;
|
||||
|
||||
// Privacy notice
|
||||
showPrivacyNotice: boolean;
|
||||
setShowPrivacyNotice: (show: boolean) => void;
|
||||
|
||||
// Welcome back dialog
|
||||
showWelcomeBackDialog: boolean;
|
||||
handleWelcomeBackClose: () => void;
|
||||
|
||||
// Quit confirmation dialog
|
||||
quitConfirmationRequest: {
|
||||
onConfirm: (shouldQuit: boolean, action?: string) => void;
|
||||
} | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook that handles closing dialogs when Ctrl+C is pressed.
|
||||
* This mimics the ESC key behavior by calling the same handlers that ESC uses.
|
||||
* Returns true if a dialog was closed, false if no dialogs were open.
|
||||
*/
|
||||
export function useDialogClose(options: DialogCloseOptions) {
|
||||
const closeAnyOpenDialog = useCallback((): boolean => {
|
||||
// Check each dialog in priority order and close using the same logic as ESC key
|
||||
|
||||
if (options.isThemeDialogOpen) {
|
||||
// Mimic ESC behavior: onSelect(undefined, selectedScope) - keeps current theme
|
||||
options.handleThemeSelect(undefined, SettingScope.User);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.isAuthDialogOpen) {
|
||||
// Mimic ESC behavior: only close if already authenticated (same as AuthDialog ESC logic)
|
||||
if (options.selectedAuthType !== undefined) {
|
||||
// Note: We don't await this since we want non-blocking behavior like ESC
|
||||
void options.handleAuthSelect(undefined, SettingScope.User);
|
||||
}
|
||||
// Note: AuthDialog prevents ESC exit if not authenticated, we follow same logic
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.isEditorDialogOpen) {
|
||||
// Mimic ESC behavior: call onExit() directly
|
||||
options.exitEditorDialog();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.isSettingsDialogOpen) {
|
||||
// Mimic ESC behavior: onSelect(undefined, selectedScope)
|
||||
options.closeSettingsDialog();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.isFolderTrustDialogOpen) {
|
||||
// FolderTrustDialog doesn't expose close function, but ESC would prevent exit
|
||||
// We follow the same pattern - prevent exit behavior
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.showPrivacyNotice) {
|
||||
// PrivacyNotice uses onExit callback
|
||||
options.setShowPrivacyNotice(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.showWelcomeBackDialog) {
|
||||
// WelcomeBack has its own close handler
|
||||
options.handleWelcomeBackClose();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Note: quitConfirmationRequest is NOT handled here anymore
|
||||
// It's handled specially in handleExit - ctrl+c in quit-confirm should exit immediately
|
||||
|
||||
// No dialog was open
|
||||
return false;
|
||||
}, [options]);
|
||||
|
||||
return { closeAnyOpenDialog };
|
||||
}
|
||||
@@ -913,7 +913,7 @@ export const useGeminiStream = (
|
||||
}
|
||||
const restorableToolCalls = toolCalls.filter(
|
||||
(toolCall) =>
|
||||
(toolCall.request.name === 'replace' ||
|
||||
(toolCall.request.name === 'edit' ||
|
||||
toolCall.request.name === 'write_file') &&
|
||||
toolCall.status === 'awaiting_approval',
|
||||
);
|
||||
|
||||
39
packages/cli/src/ui/hooks/useQuitConfirmation.ts
Normal file
39
packages/cli/src/ui/hooks/useQuitConfirmation.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { useState, useCallback } from 'react';
|
||||
import { QuitChoice } from '../components/QuitConfirmationDialog.js';
|
||||
|
||||
export const useQuitConfirmation = () => {
|
||||
const [isQuitConfirmationOpen, setIsQuitConfirmationOpen] = useState(false);
|
||||
|
||||
const showQuitConfirmation = useCallback(() => {
|
||||
setIsQuitConfirmationOpen(true);
|
||||
}, []);
|
||||
|
||||
const handleQuitConfirmationSelect = useCallback((choice: QuitChoice) => {
|
||||
setIsQuitConfirmationOpen(false);
|
||||
|
||||
if (choice === QuitChoice.CANCEL) {
|
||||
return { shouldQuit: false, action: 'cancel' };
|
||||
} else if (choice === QuitChoice.QUIT) {
|
||||
return { shouldQuit: true, action: 'quit' };
|
||||
} else if (choice === QuitChoice.SAVE_AND_QUIT) {
|
||||
return { shouldQuit: true, action: 'save_and_quit' };
|
||||
} else if (choice === QuitChoice.SUMMARY_AND_QUIT) {
|
||||
return { shouldQuit: true, action: 'summary_and_quit' };
|
||||
}
|
||||
|
||||
// Default to cancel if unknown choice
|
||||
return { shouldQuit: false, action: 'cancel' };
|
||||
}, []);
|
||||
|
||||
return {
|
||||
isQuitConfirmationOpen,
|
||||
showQuitConfirmation,
|
||||
handleQuitConfirmationSelect,
|
||||
};
|
||||
};
|
||||
119
packages/cli/src/ui/hooks/useWelcomeBack.ts
Normal file
119
packages/cli/src/ui/hooks/useWelcomeBack.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import {
|
||||
getProjectSummaryInfo,
|
||||
type ProjectSummaryInfo,
|
||||
type Config,
|
||||
} from '@qwen-code/qwen-code-core';
|
||||
import { type Settings } from '../../config/settingsSchema.js';
|
||||
|
||||
export interface WelcomeBackState {
|
||||
welcomeBackInfo: ProjectSummaryInfo | null;
|
||||
showWelcomeBackDialog: boolean;
|
||||
welcomeBackChoice: 'restart' | 'continue' | null;
|
||||
shouldFillInput: boolean;
|
||||
inputFillText: string | null;
|
||||
}
|
||||
|
||||
export interface WelcomeBackActions {
|
||||
handleWelcomeBackSelection: (choice: 'restart' | 'continue') => void;
|
||||
handleWelcomeBackClose: () => void;
|
||||
checkWelcomeBack: () => Promise<void>;
|
||||
clearInputFill: () => void;
|
||||
}
|
||||
|
||||
export function useWelcomeBack(
|
||||
config: Config,
|
||||
submitQuery: (query: string) => void,
|
||||
buffer: { setText: (text: string) => void },
|
||||
settings: Settings,
|
||||
): WelcomeBackState & WelcomeBackActions {
|
||||
const [welcomeBackInfo, setWelcomeBackInfo] =
|
||||
useState<ProjectSummaryInfo | null>(null);
|
||||
const [showWelcomeBackDialog, setShowWelcomeBackDialog] = useState(false);
|
||||
const [welcomeBackChoice, setWelcomeBackChoice] = useState<
|
||||
'restart' | 'continue' | null
|
||||
>(null);
|
||||
const [shouldFillInput, setShouldFillInput] = useState(false);
|
||||
const [inputFillText, setInputFillText] = useState<string | null>(null);
|
||||
|
||||
// Check for conversation history on startup
|
||||
const checkWelcomeBack = useCallback(async () => {
|
||||
// Check if welcome back is enabled in settings
|
||||
if (settings.enableWelcomeBack === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const info = await getProjectSummaryInfo();
|
||||
if (info.hasHistory) {
|
||||
setWelcomeBackInfo(info);
|
||||
setShowWelcomeBackDialog(true);
|
||||
}
|
||||
} catch (error) {
|
||||
// Silently ignore errors - welcome back is not critical
|
||||
console.debug('Welcome back check failed:', error);
|
||||
}
|
||||
}, [settings.enableWelcomeBack]);
|
||||
|
||||
// Handle welcome back dialog selection
|
||||
const handleWelcomeBackSelection = useCallback(
|
||||
(choice: 'restart' | 'continue') => {
|
||||
setWelcomeBackChoice(choice);
|
||||
setShowWelcomeBackDialog(false);
|
||||
|
||||
if (choice === 'continue' && welcomeBackInfo?.content) {
|
||||
// Create the context message to fill in the input box
|
||||
const contextMessage = `@.qwen/PROJECT_SUMMARY.md, Based on our previous conversation,Let's continue?`;
|
||||
|
||||
// Set the input fill state instead of directly submitting
|
||||
setInputFillText(contextMessage);
|
||||
setShouldFillInput(true);
|
||||
}
|
||||
// If choice is 'restart', just close the dialog and continue normally
|
||||
},
|
||||
[welcomeBackInfo],
|
||||
);
|
||||
|
||||
const handleWelcomeBackClose = useCallback(() => {
|
||||
setWelcomeBackChoice('restart'); // Default to restart when closed
|
||||
setShowWelcomeBackDialog(false);
|
||||
}, []);
|
||||
|
||||
const clearInputFill = useCallback(() => {
|
||||
setShouldFillInput(false);
|
||||
setInputFillText(null);
|
||||
}, []);
|
||||
|
||||
// Handle input filling from welcome back
|
||||
useEffect(() => {
|
||||
if (shouldFillInput && inputFillText) {
|
||||
buffer.setText(inputFillText);
|
||||
clearInputFill();
|
||||
}
|
||||
}, [shouldFillInput, inputFillText, buffer, clearInputFill]);
|
||||
|
||||
// Check for welcome back on mount
|
||||
useEffect(() => {
|
||||
checkWelcomeBack();
|
||||
}, [checkWelcomeBack]);
|
||||
|
||||
return {
|
||||
// State
|
||||
welcomeBackInfo,
|
||||
showWelcomeBackDialog,
|
||||
welcomeBackChoice,
|
||||
shouldFillInput,
|
||||
inputFillText,
|
||||
// Actions
|
||||
handleWelcomeBackSelection,
|
||||
handleWelcomeBackClose,
|
||||
checkWelcomeBack,
|
||||
clearInputFill,
|
||||
};
|
||||
}
|
||||
@@ -58,6 +58,12 @@ export interface CompressionProps {
|
||||
newTokenCount: number | null;
|
||||
}
|
||||
|
||||
export interface SummaryProps {
|
||||
isPending: boolean;
|
||||
stage: 'generating' | 'saving' | 'completed';
|
||||
filePath?: string; // Path to the saved summary file
|
||||
}
|
||||
|
||||
export interface HistoryItemBase {
|
||||
text?: string; // Text content for user/gemini/info/error messages
|
||||
}
|
||||
@@ -121,6 +127,11 @@ export type HistoryItemQuit = HistoryItemBase & {
|
||||
duration: string;
|
||||
};
|
||||
|
||||
export type HistoryItemQuitConfirmation = HistoryItemBase & {
|
||||
type: 'quit_confirmation';
|
||||
duration: string;
|
||||
};
|
||||
|
||||
export type HistoryItemToolGroup = HistoryItemBase & {
|
||||
type: 'tool_group';
|
||||
tools: IndividualToolCallDisplay[];
|
||||
@@ -136,6 +147,11 @@ export type HistoryItemCompression = HistoryItemBase & {
|
||||
compression: CompressionProps;
|
||||
};
|
||||
|
||||
export type HistoryItemSummary = HistoryItemBase & {
|
||||
type: 'summary';
|
||||
summary: SummaryProps;
|
||||
};
|
||||
|
||||
// Using Omit<HistoryItem, 'id'> seems to have some issues with typescript's
|
||||
// type inference e.g. historyItem.type === 'tool_group' isn't auto-inferring that
|
||||
// 'tools' in historyItem.
|
||||
@@ -154,7 +170,9 @@ export type HistoryItemWithoutId =
|
||||
| HistoryItemModelStats
|
||||
| HistoryItemToolStats
|
||||
| HistoryItemQuit
|
||||
| HistoryItemCompression;
|
||||
| HistoryItemQuitConfirmation
|
||||
| HistoryItemCompression
|
||||
| HistoryItemSummary;
|
||||
|
||||
export type HistoryItem = HistoryItemWithoutId & { id: number };
|
||||
|
||||
@@ -169,8 +187,10 @@ export enum MessageType {
|
||||
MODEL_STATS = 'model_stats',
|
||||
TOOL_STATS = 'tool_stats',
|
||||
QUIT = 'quit',
|
||||
QUIT_CONFIRMATION = 'quit_confirmation',
|
||||
GEMINI = 'gemini',
|
||||
COMPRESSION = 'compression',
|
||||
SUMMARY = 'summary',
|
||||
}
|
||||
|
||||
// Simplified message structure for internal feedback
|
||||
@@ -219,10 +239,21 @@ export type Message =
|
||||
duration: string;
|
||||
content?: string;
|
||||
}
|
||||
| {
|
||||
type: MessageType.QUIT_CONFIRMATION;
|
||||
timestamp: Date;
|
||||
duration: string;
|
||||
content?: string;
|
||||
}
|
||||
| {
|
||||
type: MessageType.COMPRESSION;
|
||||
compression: CompressionProps;
|
||||
timestamp: Date;
|
||||
}
|
||||
| {
|
||||
type: MessageType.SUMMARY;
|
||||
summary: SummaryProps;
|
||||
timestamp: Date;
|
||||
};
|
||||
|
||||
export interface ConsoleMessageItem {
|
||||
|
||||
Reference in New Issue
Block a user