mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 08:02:17 +00:00
Add custom session events for thinking level and model changes
Session manager changes: - Add ThinkingLevelChangeEntry and ModelChangeEntry types - Add saveThinkingLevelChange() and saveModelChange() methods - Update loadThinkingLevel() to also check for thinking_level_change events (not just session headers) TUI changes: - Pass SessionManager to TuiRenderer constructor - Call saveThinkingLevelChange() when user changes thinking level via /thinking - Store session manager as instance variable for future use This ensures thinking level changes during a session are persisted and correctly restored on --continue.
This commit is contained in:
parent
02a21dd936
commit
bf5f4b17c0
3 changed files with 42 additions and 4 deletions
|
|
@ -34,6 +34,18 @@ export interface SessionEventEntry {
|
|||
event: AgentEvent;
|
||||
}
|
||||
|
||||
export interface ThinkingLevelChangeEntry {
|
||||
type: "thinking_level_change";
|
||||
timestamp: string;
|
||||
thinkingLevel: string;
|
||||
}
|
||||
|
||||
export interface ModelChangeEntry {
|
||||
type: "model_change";
|
||||
timestamp: string;
|
||||
model: string;
|
||||
}
|
||||
|
||||
export class SessionManager {
|
||||
private sessionId!: string;
|
||||
private sessionFile!: string;
|
||||
|
|
@ -139,6 +151,24 @@ export class SessionManager {
|
|||
appendFileSync(this.sessionFile, JSON.stringify(entry) + "\n");
|
||||
}
|
||||
|
||||
saveThinkingLevelChange(thinkingLevel: string): void {
|
||||
const entry: ThinkingLevelChangeEntry = {
|
||||
type: "thinking_level_change",
|
||||
timestamp: new Date().toISOString(),
|
||||
thinkingLevel,
|
||||
};
|
||||
appendFileSync(this.sessionFile, JSON.stringify(entry) + "\n");
|
||||
}
|
||||
|
||||
saveModelChange(model: string): void {
|
||||
const entry: ModelChangeEntry = {
|
||||
type: "model_change",
|
||||
timestamp: new Date().toISOString(),
|
||||
model,
|
||||
};
|
||||
appendFileSync(this.sessionFile, JSON.stringify(entry) + "\n");
|
||||
}
|
||||
|
||||
loadMessages(): any[] {
|
||||
if (!existsSync(this.sessionFile)) return [];
|
||||
|
||||
|
|
@ -164,13 +194,15 @@ export class SessionManager {
|
|||
|
||||
const lines = readFileSync(this.sessionFile, "utf8").trim().split("\n");
|
||||
|
||||
// Find the most recent session header with thinking level
|
||||
// Find the most recent thinking level (from session header or change event)
|
||||
let lastThinkingLevel = "off";
|
||||
for (const line of lines) {
|
||||
try {
|
||||
const entry = JSON.parse(line);
|
||||
if (entry.type === "session" && entry.thinkingLevel) {
|
||||
lastThinkingLevel = entry.thinkingLevel;
|
||||
} else if (entry.type === "thinking_level_change" && entry.thinkingLevel) {
|
||||
lastThinkingLevel = entry.thinkingLevel;
|
||||
}
|
||||
} catch {
|
||||
// Skip malformed lines
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue