fix(agent): resolve reasoningMode from profile config and session meta

- Read reasoningMode from profile config and storedMeta when not
  explicitly set via options (matching thinkingLevel pattern)
- Skip extractThinking() call when reasoningMode is "off"
- Clean up redundant ?? undefined casts in CLI entry points

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
yushen 2026-02-04 16:00:53 +08:00
parent 953a29672a
commit 8fe2b5f010
5 changed files with 19 additions and 6 deletions

View file

@ -7,6 +7,7 @@
*/
import { Agent } from "../../runner.js";
import type { AgentOptions } from "../../types.js";
import type { ToolsConfig } from "../../tools/policy.js";
import { cyan, yellow, dim } from "../colors.js";
@ -198,7 +199,7 @@ export async function runCommand(args: string[]): Promise<void> {
baseUrl: opts.baseUrl,
systemPrompt: opts.system,
thinkingLevel: opts.thinking as any,
reasoningMode: (opts.reasoning as any) ?? undefined,
reasoningMode: opts.reasoning as AgentOptions["reasoningMode"],
cwd: opts.cwd,
sessionId: opts.session,
debug: opts.debug,

View file

@ -349,7 +349,7 @@ class InteractiveCLI {
model: this.opts.model,
systemPrompt: this.opts.system,
thinkingLevel: this.opts.thinking as AgentOptions["thinkingLevel"],
reasoningMode: (this.opts.reasoning as AgentOptions["reasoningMode"]) ?? undefined,
reasoningMode: this.opts.reasoning as AgentOptions["reasoningMode"],
cwd: this.opts.cwd,
sessionId,
});

View file

@ -177,7 +177,7 @@ async function main() {
baseUrl: opts.baseUrl,
systemPrompt: opts.system,
thinkingLevel: opts.thinking as any,
reasoningMode: (opts.reasoning as any) ?? undefined,
reasoningMode: opts.reasoning as any,
cwd: opts.cwd,
sessionId: opts.session,
debug: opts.debug,

View file

@ -249,8 +249,8 @@ export function createAgentOutput(params: {
state.streaming = false;
state.lastAssistantText = text;
// Extract and store thinking content
const thinking = extractThinking(msg);
// Extract and store thinking content (skip when off)
const thinking = reasoningMode !== "off" ? extractThinking(msg) : "";
state.lastAssistantThinking = thinking;
// Show thinking at end for "on" mode

View file

@ -70,7 +70,7 @@ export class Agent {
private readonly skillManager?: SkillManager;
private readonly contextWindowGuard: ContextWindowGuardResult;
private readonly debug: boolean;
private readonly reasoningMode: ReasoningMode;
private reasoningMode: ReasoningMode;
private toolsOptions: AgentOptions;
private readonly originalToolsConfig?: ToolsConfig;
private readonly stderr: NodeJS.WritableStream;
@ -267,6 +267,18 @@ export class Agent {
this.agent.setThinkingLevel(options.thinkingLevel);
}
// Resolve reasoningMode: options > profile config > storedMeta > default "stream"
if (!options.reasoningMode) {
const profileReasoningMode = this.profile?.getProfile()?.config?.reasoningMode;
const metaReasoningMode = storedMeta?.reasoningMode as ReasoningMode | undefined;
const resolved = profileReasoningMode ?? metaReasoningMode ?? "stream";
if (resolved !== this.reasoningMode) {
this.reasoningMode = resolved;
// Re-create output with correct reasoningMode
this.output = createAgentOutput({ stdout, stderr: this.stderr, reasoningMode: this.reasoningMode });
}
}
this.agent.setModel(model);
// Save original tools config from options (for later merging during reload)