Merge branch 'main' into 1179-add-resume-cmd

This commit is contained in:
tanzhenxin
2025-12-16 15:29:58 +08:00
180 changed files with 6068 additions and 5534 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@qwen-code/qwen-code",
"version": "0.5.0",
"version": "0.5.1",
"description": "Qwen Code",
"repository": {
"type": "git",
@@ -33,7 +33,7 @@
"dist"
],
"config": {
"sandboxImageUri": "ghcr.io/qwenlm/qwen-code:0.5.0"
"sandboxImageUri": "ghcr.io/qwenlm/qwen-code:0.5.1"
},
"dependencies": {
"@google/genai": "1.16.0",

View File

@@ -292,7 +292,7 @@ class GeminiAgent {
private async ensureAuthenticated(config: Config): Promise<void> {
const selectedType = this.settings.merged.security?.auth?.selectedType;
if (!selectedType) {
throw acp.RequestError.authRequired();
throw acp.RequestError.authRequired('No Selected Type');
}
try {
@@ -300,7 +300,9 @@ class GeminiAgent {
await config.refreshAuth(selectedType, true);
} catch (e) {
console.error(`Authentication failed: ${e}`);
throw acp.RequestError.authRequired();
throw acp.RequestError.authRequired(
'Authentication failed: ' + (e as Error).message,
);
}
}

View File

@@ -130,6 +130,11 @@ export interface CliArgs {
inputFormat?: string | undefined;
outputFormat: string | undefined;
includePartialMessages?: boolean;
/**
* If chat recording is disabled, the chat history would not be recorded,
* so --continue and --resume would not take effect.
*/
chatRecording: boolean | undefined;
/** Resume the most recent session for the current project */
continue: boolean | undefined;
/** Resume a specific session by its ID */
@@ -233,6 +238,11 @@ export async function parseArguments(settings: Settings): Promise<CliArgs> {
'proxy',
'Use the "proxy" setting in settings.json instead. This flag will be removed in a future version.',
)
.option('chat-recording', {
type: 'boolean',
description:
'Enable chat recording to disk. If false, chat history is not saved and --continue/--resume will not work.',
})
.command('$0 [query..]', 'Launch Qwen Code CLI', (yargsInstance: Argv) =>
yargsInstance
.positional('query', {
@@ -992,10 +1002,16 @@ export async function loadCliConfig(
enableToolOutputTruncation: settings.tools?.enableToolOutputTruncation,
eventEmitter: appEvents,
useSmartEdit: argv.useSmartEdit ?? settings.useSmartEdit,
gitCoAuthor: settings.general?.gitCoAuthor,
output: {
format: outputSettingsFormat,
},
channel: argv.channel,
// Precedence: explicit CLI flag > settings file > default(true).
// NOTE: do NOT set a yargs default for `chat-recording`, otherwise argv will
// always be true and the settings file can never disable recording.
chatRecording:
argv.chatRecording ?? settings.general?.chatRecording ?? true,
});
}

View File

@@ -581,7 +581,7 @@ function extensionConsentString(extensionConfig: ExtensionConfig): string {
}
if (extensionConfig.contextFileName) {
output.push(
`This extension will append info to your gemini.md context using ${extensionConfig.contextFileName}`,
`This extension will append info to your QWEN.md context using ${extensionConfig.contextFileName}`,
);
}
if (extensionConfig.excludeTools) {

View File

@@ -147,6 +147,16 @@ const SETTINGS_SCHEMA = {
description: 'Disable update notification prompts.',
showInDialog: false,
},
gitCoAuthor: {
type: 'boolean',
label: 'Git Co-Author',
category: 'General',
requiresRestart: false,
default: true,
description:
'Automatically add a Co-authored-by trailer to git commit messages when commits are made through Qwen Code.',
showInDialog: false,
},
checkpointing: {
type: 'object',
label: 'Checkpointing',
@@ -204,6 +214,16 @@ const SETTINGS_SCHEMA = {
'Play terminal bell sound when response completes or needs approval.',
showInDialog: true,
},
chatRecording: {
type: 'boolean',
label: 'Chat Recording',
category: 'General',
requiresRestart: true,
default: true,
description:
'Enable saving chat history to disk. Disabling this will also prevent --continue and --resume from working.',
showInDialog: false,
},
},
},
output: {
@@ -274,7 +294,7 @@ const SETTINGS_SCHEMA = {
requiresRestart: false,
default: false,
description:
'Show Gemini CLI status and thoughts in the terminal window title',
'Show Qwen Code status and thoughts in the terminal window title',
showInDialog: true,
},
hideTips: {
@@ -302,7 +322,7 @@ const SETTINGS_SCHEMA = {
requiresRestart: false,
default: false,
description:
'Hide the context summary (GEMINI.md, MCP servers) above the input.',
'Hide the context summary (QWEN.md, MCP servers) above the input.',
showInDialog: true,
},
footer: {
@@ -508,7 +528,7 @@ const SETTINGS_SCHEMA = {
category: 'Model',
requiresRestart: false,
default: undefined as string | undefined,
description: 'The Gemini model to use for conversations.',
description: 'The model to use for conversations.',
showInDialog: false,
},
maxSessionTurns: {

View File

@@ -379,8 +379,8 @@ describe('gemini.tsx main function kitty protocol', () => {
beforeEach(() => {
// Set no relaunch in tests since process spawning causing issues in tests
originalEnvNoRelaunch = process.env['GEMINI_CLI_NO_RELAUNCH'];
process.env['GEMINI_CLI_NO_RELAUNCH'] = 'true';
originalEnvNoRelaunch = process.env['QWEN_CODE_NO_RELAUNCH'];
process.env['QWEN_CODE_NO_RELAUNCH'] = 'true';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (!(process.stdin as any).setRawMode) {
@@ -402,9 +402,9 @@ describe('gemini.tsx main function kitty protocol', () => {
afterEach(() => {
// Restore original env variables
if (originalEnvNoRelaunch !== undefined) {
process.env['GEMINI_CLI_NO_RELAUNCH'] = originalEnvNoRelaunch;
process.env['QWEN_CODE_NO_RELAUNCH'] = originalEnvNoRelaunch;
} else {
delete process.env['GEMINI_CLI_NO_RELAUNCH'];
delete process.env['QWEN_CODE_NO_RELAUNCH'];
}
});
@@ -486,6 +486,7 @@ describe('gemini.tsx main function kitty protocol', () => {
authType: undefined,
maxSessionTurns: undefined,
channel: undefined,
chatRecording: undefined,
});
await main();

View File

@@ -92,7 +92,7 @@ function getNodeMemoryArgs(isDebugMode: boolean): string[] {
);
}
if (process.env['GEMINI_CLI_NO_RELAUNCH']) {
if (process.env['QWEN_CODE_NO_RELAUNCH']) {
return [];
}

View File

@@ -635,8 +635,8 @@ export default {
'The /directory add command is not supported in restrictive sandbox profiles. Please use --include-directories when starting the session instead.':
'The /directory add command is not supported in restrictive sandbox profiles. Please use --include-directories when starting the session instead.',
"Error adding '{{path}}': {{error}}": "Error adding '{{path}}': {{error}}",
'Successfully added GEMINI.md files from the following directories if there are:\n- {{directories}}':
'Successfully added GEMINI.md files from the following directories if there are:\n- {{directories}}',
'Successfully added QWEN.md files from the following directories if there are:\n- {{directories}}':
'Successfully added QWEN.md files from the following directories if there are:\n- {{directories}}',
'Error refreshing memory: {{error}}': 'Error refreshing memory: {{error}}',
'Successfully added directories:\n- {{directories}}':
'Successfully added directories:\n- {{directories}}',

View File

@@ -601,8 +601,8 @@ export default {
'The /directory add command is not supported in restrictive sandbox profiles. Please use --include-directories when starting the session instead.':
'/directory add 命令在限制性沙箱配置文件中不受支持。请改为在启动会话时使用 --include-directories。',
"Error adding '{{path}}': {{error}}": "添加 '{{path}}' 时出错:{{error}}",
'Successfully added GEMINI.md files from the following directories if there are:\n- {{directories}}':
'如果存在,已成功从以下目录添加 GEMINI.md 文件:\n- {{directories}}',
'Successfully added QWEN.md files from the following directories if there are:\n- {{directories}}':
'如果存在,已成功从以下目录添加 QWEN.md 文件:\n- {{directories}}',
'Error refreshing memory: {{error}}': '刷新内存时出错:{{error}}',
'Successfully added directories:\n- {{directories}}':
'成功添加目录:\n- {{directories}}',

View File

@@ -130,7 +130,7 @@ export const directoryCommand: SlashCommand = {
{
type: MessageType.INFO,
text: t(
'Successfully added GEMINI.md files from the following directories if there are:\n- {{directories}}',
'Successfully added QWEN.md files from the following directories if there are:\n- {{directories}}',
{
directories: added.join('\n- '),
},

View File

@@ -46,12 +46,15 @@ vi.mock('node:fs', async (importOriginal) => {
// Mock Storage from core
vi.mock('@qwen-code/qwen-code-core', async (importOriginal) => {
const actual = await importOriginal<typeof import('@qwen-code/qwen-code-core')>();
const actual =
await importOriginal<typeof import('@qwen-code/qwen-code-core')>();
return {
...actual,
Storage: {
getGlobalQwenDir: vi.fn().mockReturnValue('/mock/.qwen'),
getGlobalSettingsPath: vi.fn().mockReturnValue('/mock/.qwen/settings.json'),
getGlobalSettingsPath: vi
.fn()
.mockReturnValue('/mock/.qwen/settings.json'),
},
};
});
@@ -360,7 +363,10 @@ describe('languageCommand', () => {
throw new Error('The language command must have an action.');
}
const result = await languageCommand.action(mockContext, 'output Chinese');
const result = await languageCommand.action(
mockContext,
'output Chinese',
);
expect(fs.mkdirSync).toHaveBeenCalled();
expect(fs.writeFileSync).toHaveBeenCalledWith(
@@ -371,7 +377,9 @@ describe('languageCommand', () => {
expect(result).toEqual({
type: 'message',
messageType: 'info',
content: expect.stringContaining('LLM output language rule file generated'),
content: expect.stringContaining(
'LLM output language rule file generated',
),
});
});
@@ -380,7 +388,10 @@ describe('languageCommand', () => {
throw new Error('The language command must have an action.');
}
const result = await languageCommand.action(mockContext, 'output Japanese');
const result = await languageCommand.action(
mockContext,
'output Japanese',
);
expect(result).toEqual({
type: 'message',
@@ -514,7 +525,9 @@ describe('languageCommand', () => {
expect(result).toEqual({
type: 'message',
messageType: 'info',
content: expect.stringContaining('LLM output language rule file generated'),
content: expect.stringContaining(
'LLM output language rule file generated',
),
});
});
});

View File

@@ -89,7 +89,7 @@ describe('restoreCommand', () => {
).toEqual({
type: 'message',
messageType: 'error',
content: 'Could not determine the .gemini directory path.',
content: 'Could not determine the .qwen directory path.',
});
});

View File

@@ -28,7 +28,7 @@ async function restoreAction(
return {
type: 'message',
messageType: 'error',
content: 'Could not determine the .gemini directory path.',
content: 'Could not determine the .qwen directory path.',
};
}

View File

@@ -15,6 +15,7 @@ import type {
} from '@qwen-code/qwen-code-core';
import { ToolGroupMessage } from './messages/ToolGroupMessage.js';
import { renderWithProviders } from '../../test-utils/render.js';
import { ConfigContext } from '../contexts/ConfigContext.js';
// Mock child components
vi.mock('./messages/ToolGroupMessage.js', () => ({
@@ -22,7 +23,9 @@ vi.mock('./messages/ToolGroupMessage.js', () => ({
}));
describe('<HistoryItemDisplay />', () => {
const mockConfig = {} as unknown as Config;
const mockConfig = {
getChatRecordingService: () => undefined,
} as unknown as Config;
const baseItem = {
id: 1,
timestamp: 12345,
@@ -133,9 +136,11 @@ describe('<HistoryItemDisplay />', () => {
duration: '1s',
};
const { lastFrame } = renderWithProviders(
<SessionStatsProvider>
<HistoryItemDisplay {...baseItem} item={item} />
</SessionStatsProvider>,
<ConfigContext.Provider value={mockConfig as never}>
<SessionStatsProvider>
<HistoryItemDisplay {...baseItem} item={item} />
</SessionStatsProvider>
</ConfigContext.Provider>,
);
expect(lastFrame()).toContain('Agent powering down. Goodbye!');
});

View File

@@ -115,7 +115,7 @@ export function PermissionsModifyTrustDialog({
{needsRestart && (
<Box marginLeft={1} marginTop={1}>
<Text color={theme.status.warning}>
To apply the trust changes, Gemini CLI must be restarted. Press
To apply the trust changes, Qwen Code must be restarted. Press
&apos;r&apos; to restart CLI now.
</Text>
</Box>

View File

@@ -9,6 +9,7 @@ import { describe, it, expect, vi } from 'vitest';
import { SessionSummaryDisplay } from './SessionSummaryDisplay.js';
import * as SessionContext from '../contexts/SessionContext.js';
import type { SessionMetrics } from '../contexts/SessionContext.js';
import { ConfigContext } from '../contexts/ConfigContext.js';
vi.mock('../contexts/SessionContext.js', async (importOriginal) => {
const actual = await importOriginal<typeof SessionContext>();
@@ -24,6 +25,7 @@ const renderWithMockedStats = (
metrics: SessionMetrics,
sessionId: string = 'test-session-id-12345',
promptCount: number = 5,
chatRecordingEnabled: boolean = true,
) => {
useSessionStatsMock.mockReturnValue({
stats: {
@@ -38,7 +40,17 @@ const renderWithMockedStats = (
startNewPrompt: vi.fn(),
});
return render(<SessionSummaryDisplay duration="1h 23m 45s" />);
const mockConfig = {
getChatRecordingService: vi.fn(() =>
chatRecordingEnabled ? ({} as never) : undefined,
),
};
return render(
<ConfigContext.Provider value={mockConfig as never}>
<SessionSummaryDisplay duration="1h 23m 45s" />
</ConfigContext.Provider>,
);
};
describe('<SessionSummaryDisplay />', () => {
@@ -109,4 +121,34 @@ describe('<SessionSummaryDisplay />', () => {
expect(output).not.toContain('To continue this session, run');
expect(output).not.toContain('qwen --resume');
});
it('does not show resume message when chat recording is disabled', () => {
const metrics: SessionMetrics = {
models: {},
tools: {
totalCalls: 0,
totalSuccess: 0,
totalFail: 0,
totalDurationMs: 0,
totalDecisions: { accept: 0, reject: 0, modify: 0 },
byName: {},
},
files: {
totalLinesAdded: 0,
totalLinesRemoved: 0,
},
};
const { lastFrame } = renderWithMockedStats(
metrics,
'test-session-id-12345',
5,
false,
);
const output = lastFrame();
expect(output).toContain('Agent powering down. Goodbye!');
expect(output).not.toContain('To continue this session, run');
expect(output).not.toContain('qwen --resume');
});
});

View File

@@ -8,6 +8,7 @@ import type React from 'react';
import { Box, Text } from 'ink';
import { StatsDisplay } from './StatsDisplay.js';
import { useSessionStats } from '../contexts/SessionContext.js';
import { useConfig } from '../contexts/ConfigContext.js';
import { theme } from '../semantic-colors.js';
import { t } from '../../i18n/index.js';
@@ -18,10 +19,13 @@ interface SessionSummaryDisplayProps {
export const SessionSummaryDisplay: React.FC<SessionSummaryDisplayProps> = ({
duration,
}) => {
const config = useConfig();
const { stats } = useSessionStats();
// Only show the resume message if there were messages in the session
// Only show the resume message if there were messages in the session AND
// chat recording is enabled (otherwise there is nothing to resume).
const hasMessages = stats.promptCount > 0;
const canResume = !!config.getChatRecordingService();
return (
<>
@@ -29,7 +33,7 @@ export const SessionSummaryDisplay: React.FC<SessionSummaryDisplayProps> = ({
title={t('Agent powering down. Goodbye!')}
duration={duration}
/>
{hasMessages && (
{hasMessages && canResume && (
<Box marginTop={1}>
<Text color={theme.text.secondary}>
{t('To continue this session, run')}{' '}

View File

@@ -1461,7 +1461,7 @@ describe('SettingsDialog', () => {
context: {
fileFiltering: {
respectGitIgnore: false,
respectQwemIgnore: true,
respectQwenIgnore: true,
enableRecursiveFileSearch: false,
disableFuzzySearch: true,
},
@@ -1535,7 +1535,7 @@ describe('SettingsDialog', () => {
loadMemoryFromIncludeDirectories: false,
fileFiltering: {
respectGitIgnore: false,
respectQwemIgnore: false,
respectQwenIgnore: false,
enableRecursiveFileSearch: false,
disableFuzzySearch: false,
},

View File

@@ -115,7 +115,7 @@ describe('relaunchAppInChildProcess', () => {
vi.clearAllMocks();
process.env = { ...originalEnv };
delete process.env['GEMINI_CLI_NO_RELAUNCH'];
delete process.env['QWEN_CODE_NO_RELAUNCH'];
process.execArgv = [...originalExecArgv];
process.argv = [...originalArgv];
@@ -145,9 +145,9 @@ describe('relaunchAppInChildProcess', () => {
stdinResumeSpy.mockRestore();
});
describe('when GEMINI_CLI_NO_RELAUNCH is set', () => {
describe('when QWEN_CODE_NO_RELAUNCH is set', () => {
it('should return early without spawning a child process', async () => {
process.env['GEMINI_CLI_NO_RELAUNCH'] = 'true';
process.env['QWEN_CODE_NO_RELAUNCH'] = 'true';
await relaunchAppInChildProcess(['--test'], ['--verbose']);
@@ -156,9 +156,9 @@ describe('relaunchAppInChildProcess', () => {
});
});
describe('when GEMINI_CLI_NO_RELAUNCH is not set', () => {
describe('when QWEN_CODE_NO_RELAUNCH is not set', () => {
beforeEach(() => {
delete process.env['GEMINI_CLI_NO_RELAUNCH'];
delete process.env['QWEN_CODE_NO_RELAUNCH'];
});
it('should construct correct node arguments from execArgv, additionalNodeArgs, script, additionalScriptArgs, and argv', () => {

View File

@@ -27,7 +27,7 @@ export async function relaunchAppInChildProcess(
additionalNodeArgs: string[],
additionalScriptArgs: string[],
) {
if (process.env['GEMINI_CLI_NO_RELAUNCH']) {
if (process.env['QWEN_CODE_NO_RELAUNCH']) {
return;
}
@@ -44,7 +44,7 @@ export async function relaunchAppInChildProcess(
...additionalScriptArgs,
...scriptArgs,
];
const newEnv = { ...process.env, GEMINI_CLI_NO_RELAUNCH: 'true' };
const newEnv = { ...process.env, QWEN_CODE_NO_RELAUNCH: 'true' };
// The parent process should not be reading from stdin while the child is running.
process.stdin.pause();