mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 14:01:18 +00:00
fix(coding-agent): persist thinking level defaults
This commit is contained in:
parent
8a7a761deb
commit
e1e4e593c0
2 changed files with 22 additions and 3 deletions
|
|
@ -40,6 +40,7 @@ import {
|
||||||
prepareCompaction,
|
prepareCompaction,
|
||||||
shouldCompact,
|
shouldCompact,
|
||||||
} from "./compaction/index.js";
|
} from "./compaction/index.js";
|
||||||
|
import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
|
||||||
import { exportSessionToHtml, type ToolHtmlRenderer } from "./export-html/index.js";
|
import { exportSessionToHtml, type ToolHtmlRenderer } from "./export-html/index.js";
|
||||||
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
||||||
import {
|
import {
|
||||||
|
|
@ -1094,6 +1095,8 @@ export class AgentSession {
|
||||||
this._followUpMessages = [];
|
this._followUpMessages = [];
|
||||||
this._pendingNextTurnMessages = [];
|
this._pendingNextTurnMessages = [];
|
||||||
|
|
||||||
|
this.sessionManager.appendThinkingLevelChange(this.thinkingLevel);
|
||||||
|
|
||||||
// Run setup callback if provided (e.g., to append initial messages)
|
// Run setup callback if provided (e.g., to append initial messages)
|
||||||
if (options?.setup) {
|
if (options?.setup) {
|
||||||
await options.setup(this.sessionManager);
|
await options.setup(this.sessionManager);
|
||||||
|
|
@ -2303,9 +2306,19 @@ export class AgentSession {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore thinking level if saved (setThinkingLevel clamps to model capabilities)
|
const hasThinkingEntry = this.sessionManager.getBranch().some((entry) => entry.type === "thinking_level_change");
|
||||||
if (sessionContext.thinkingLevel) {
|
const defaultThinkingLevel = this.settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL;
|
||||||
|
|
||||||
|
if (hasThinkingEntry) {
|
||||||
|
// Restore thinking level if saved (setThinkingLevel clamps to model capabilities)
|
||||||
this.setThinkingLevel(sessionContext.thinkingLevel as ThinkingLevel);
|
this.setThinkingLevel(sessionContext.thinkingLevel as ThinkingLevel);
|
||||||
|
} else {
|
||||||
|
const availableLevels = this.getAvailableThinkingLevels();
|
||||||
|
const effectiveLevel = availableLevels.includes(defaultThinkingLevel)
|
||||||
|
? defaultThinkingLevel
|
||||||
|
: this._clampThinkingLevel(defaultThinkingLevel, availableLevels);
|
||||||
|
this.agent.setThinkingLevel(effectiveLevel);
|
||||||
|
this.sessionManager.appendThinkingLevelChange(effectiveLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._reconnectToAgent();
|
this._reconnectToAgent();
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
||||||
// Check if session has existing data to restore
|
// Check if session has existing data to restore
|
||||||
const existingSession = sessionManager.buildSessionContext();
|
const existingSession = sessionManager.buildSessionContext();
|
||||||
const hasExistingSession = existingSession.messages.length > 0;
|
const hasExistingSession = existingSession.messages.length > 0;
|
||||||
|
const hasThinkingEntry = sessionManager.getBranch().some((entry) => entry.type === "thinking_level_change");
|
||||||
|
|
||||||
let model = options.model;
|
let model = options.model;
|
||||||
let modelFallbackMessage: string | undefined;
|
let modelFallbackMessage: string | undefined;
|
||||||
|
|
@ -222,7 +223,9 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
||||||
|
|
||||||
// If session has data, restore thinking level from it
|
// If session has data, restore thinking level from it
|
||||||
if (thinkingLevel === undefined && hasExistingSession) {
|
if (thinkingLevel === undefined && hasExistingSession) {
|
||||||
thinkingLevel = existingSession.thinkingLevel as ThinkingLevel;
|
thinkingLevel = hasThinkingEntry
|
||||||
|
? (existingSession.thinkingLevel as ThinkingLevel)
|
||||||
|
: (settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to settings default
|
// Fall back to settings default
|
||||||
|
|
@ -329,6 +332,9 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
||||||
// Restore messages if session has existing data
|
// Restore messages if session has existing data
|
||||||
if (hasExistingSession) {
|
if (hasExistingSession) {
|
||||||
agent.replaceMessages(existingSession.messages);
|
agent.replaceMessages(existingSession.messages);
|
||||||
|
if (!hasThinkingEntry) {
|
||||||
|
sessionManager.appendThinkingLevelChange(thinkingLevel);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Save initial model and thinking level for new sessions so they can be restored on resume
|
// Save initial model and thinking level for new sessions so they can be restored on resume
|
||||||
if (model) {
|
if (model) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue