mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 09:17:53 +00:00
fix: emit subagent user message and correct systemMessage properties
This commit is contained in:
@@ -11,7 +11,11 @@ import type {
|
||||
TaskResultDisplay,
|
||||
ToolCallResponseInfo,
|
||||
} from '@qwen-code/qwen-code-core';
|
||||
import { ToolErrorType } from '@qwen-code/qwen-code-core';
|
||||
import {
|
||||
ToolErrorType,
|
||||
MCPServerStatus,
|
||||
getMCPServerStatus,
|
||||
} from '@qwen-code/qwen-code-core';
|
||||
import type { Part } from '@google/genai';
|
||||
import type {
|
||||
CLIUserMessage,
|
||||
@@ -55,6 +59,15 @@ vi.mock('../ui/utils/computeStats.js', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('@qwen-code/qwen-code-core', async (importOriginal) => {
|
||||
const actual =
|
||||
await importOriginal<typeof import('@qwen-code/qwen-code-core')>();
|
||||
return {
|
||||
...actual,
|
||||
getMCPServerStatus: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('normalizePartList', () => {
|
||||
it('should return empty array for null input', () => {
|
||||
expect(normalizePartList(null)).toEqual([]);
|
||||
@@ -477,6 +490,10 @@ describe('buildSystemMessage', () => {
|
||||
let mockConfig: Config;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
// Mock getMCPServerStatus to return CONNECTED by default
|
||||
vi.mocked(getMCPServerStatus).mockReturnValue(MCPServerStatus.CONNECTED);
|
||||
|
||||
mockConfig = {
|
||||
getToolRegistry: vi.fn().mockReturnValue({
|
||||
getAllToolNames: vi.fn().mockReturnValue(['tool1', 'tool2']),
|
||||
|
||||
@@ -13,7 +13,11 @@ import type {
|
||||
ToolCallResponseInfo,
|
||||
SessionMetrics,
|
||||
} from '@qwen-code/qwen-code-core';
|
||||
import { ToolErrorType } from '@qwen-code/qwen-code-core';
|
||||
import {
|
||||
OutputFormat,
|
||||
ToolErrorType,
|
||||
getMCPServerStatus,
|
||||
} from '@qwen-code/qwen-code-core';
|
||||
import type { Part, PartListUnion } from '@google/genai';
|
||||
import type {
|
||||
CLIUserMessage,
|
||||
@@ -243,13 +247,25 @@ export async function buildSystemMessage(
|
||||
const mcpServerList = mcpServers
|
||||
? Object.keys(mcpServers).map((name) => ({
|
||||
name,
|
||||
status: 'connected',
|
||||
status: getMCPServerStatus(name),
|
||||
}))
|
||||
: [];
|
||||
|
||||
// Load slash commands
|
||||
const slashCommands = await loadSlashCommandNames(config);
|
||||
|
||||
// Load subagent names from config
|
||||
let agentNames: string[] = [];
|
||||
try {
|
||||
const subagentManager = config.getSubagentManager();
|
||||
const subagents = await subagentManager.listSubagents();
|
||||
agentNames = subagents.map((subagent) => subagent.name);
|
||||
} catch (error) {
|
||||
if (config.getDebugMode()) {
|
||||
console.error('[buildSystemMessage] Failed to load subagents:', error);
|
||||
}
|
||||
}
|
||||
|
||||
const systemMessage: CLISystemMessage = {
|
||||
type: 'system',
|
||||
subtype: 'init',
|
||||
@@ -261,13 +277,8 @@ export async function buildSystemMessage(
|
||||
model: config.getModel(),
|
||||
permissionMode,
|
||||
slash_commands: slashCommands,
|
||||
apiKeySource: 'none',
|
||||
qwen_code_version: config.getCliVersion() || 'unknown',
|
||||
output_style: 'default',
|
||||
agents: [],
|
||||
skills: [],
|
||||
// Note: capabilities are NOT included in system messages
|
||||
// They are only in the initialize control response
|
||||
agents: agentNames,
|
||||
};
|
||||
|
||||
return systemMessage;
|
||||
@@ -536,11 +547,29 @@ export function createTaskToolProgressHandler(
|
||||
}
|
||||
}
|
||||
|
||||
// Handle subagent initial message (prompt) in non-interactive mode with json/stream-json output
|
||||
// Emit when this is the first update (previous is undefined) and task starts
|
||||
if (
|
||||
!previous &&
|
||||
taskDisplay.taskPrompt &&
|
||||
!config.isInteractive() &&
|
||||
(config.getOutputFormat() === OutputFormat.JSON ||
|
||||
config.getOutputFormat() === OutputFormat.STREAM_JSON)
|
||||
) {
|
||||
// Emit the user message with the correct parent_tool_use_id
|
||||
adapter.emitUserMessage(
|
||||
[{ text: taskDisplay.taskPrompt }],
|
||||
taskToolCallId,
|
||||
);
|
||||
}
|
||||
|
||||
// Update previous state
|
||||
previousTaskStates.set(callId, taskDisplay);
|
||||
}
|
||||
};
|
||||
|
||||
// No longer need to attach adapter to handler - task.ts uses TaskResultDisplay.message instead
|
||||
|
||||
return {
|
||||
handler: outputUpdateHandler,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user