mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 07:03:25 +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
|
|
@ -114,8 +114,8 @@ Guidelines:
|
||||||
|
|
||||||
Current directory: ${process.cwd()}`;
|
Current directory: ${process.cwd()}`;
|
||||||
|
|
||||||
async function runInteractiveMode(agent: Agent, _sessionManager: SessionManager, version: string): Promise<void> {
|
async function runInteractiveMode(agent: Agent, sessionManager: SessionManager, version: string): Promise<void> {
|
||||||
const renderer = new TuiRenderer(agent, version);
|
const renderer = new TuiRenderer(agent, sessionManager, version);
|
||||||
|
|
||||||
// Initialize TUI
|
// Initialize TUI
|
||||||
await renderer.init();
|
await renderer.init();
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,18 @@ export interface SessionEventEntry {
|
||||||
event: AgentEvent;
|
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 {
|
export class SessionManager {
|
||||||
private sessionId!: string;
|
private sessionId!: string;
|
||||||
private sessionFile!: string;
|
private sessionFile!: string;
|
||||||
|
|
@ -139,6 +151,24 @@ export class SessionManager {
|
||||||
appendFileSync(this.sessionFile, JSON.stringify(entry) + "\n");
|
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[] {
|
loadMessages(): any[] {
|
||||||
if (!existsSync(this.sessionFile)) return [];
|
if (!existsSync(this.sessionFile)) return [];
|
||||||
|
|
||||||
|
|
@ -164,13 +194,15 @@ export class SessionManager {
|
||||||
|
|
||||||
const lines = readFileSync(this.sessionFile, "utf8").trim().split("\n");
|
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";
|
let lastThinkingLevel = "off";
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
try {
|
try {
|
||||||
const entry = JSON.parse(line);
|
const entry = JSON.parse(line);
|
||||||
if (entry.type === "session" && entry.thinkingLevel) {
|
if (entry.type === "session" && entry.thinkingLevel) {
|
||||||
lastThinkingLevel = entry.thinkingLevel;
|
lastThinkingLevel = entry.thinkingLevel;
|
||||||
|
} else if (entry.type === "thinking_level_change" && entry.thinkingLevel) {
|
||||||
|
lastThinkingLevel = entry.thinkingLevel;
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Skip malformed lines
|
// Skip malformed lines
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import {
|
||||||
TUI,
|
TUI,
|
||||||
} from "@mariozechner/pi-tui";
|
} from "@mariozechner/pi-tui";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
import type { SessionManager } from "../session-manager.js";
|
||||||
import { AssistantMessageComponent } from "./assistant-message.js";
|
import { AssistantMessageComponent } from "./assistant-message.js";
|
||||||
import { CustomEditor } from "./custom-editor.js";
|
import { CustomEditor } from "./custom-editor.js";
|
||||||
import { FooterComponent } from "./footer.js";
|
import { FooterComponent } from "./footer.js";
|
||||||
|
|
@ -29,6 +30,7 @@ export class TuiRenderer {
|
||||||
private editorContainer: Container; // Container to swap between editor and selector
|
private editorContainer: Container; // Container to swap between editor and selector
|
||||||
private footer: FooterComponent;
|
private footer: FooterComponent;
|
||||||
private agent: Agent;
|
private agent: Agent;
|
||||||
|
private sessionManager: SessionManager;
|
||||||
private version: string;
|
private version: string;
|
||||||
private isInitialized = false;
|
private isInitialized = false;
|
||||||
private onInputCallback?: (text: string) => void;
|
private onInputCallback?: (text: string) => void;
|
||||||
|
|
@ -48,8 +50,9 @@ export class TuiRenderer {
|
||||||
// Track if this is the first user message (to skip spacer)
|
// Track if this is the first user message (to skip spacer)
|
||||||
private isFirstUserMessage = true;
|
private isFirstUserMessage = true;
|
||||||
|
|
||||||
constructor(agent: Agent, version: string) {
|
constructor(agent: Agent, sessionManager: SessionManager, version: string) {
|
||||||
this.agent = agent;
|
this.agent = agent;
|
||||||
|
this.sessionManager = sessionManager;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.ui = new TUI(new ProcessTerminal());
|
this.ui = new TUI(new ProcessTerminal());
|
||||||
this.chatContainer = new Container();
|
this.chatContainer = new Container();
|
||||||
|
|
@ -409,6 +412,9 @@ export class TuiRenderer {
|
||||||
// Apply the selected thinking level
|
// Apply the selected thinking level
|
||||||
this.agent.setThinkingLevel(level);
|
this.agent.setThinkingLevel(level);
|
||||||
|
|
||||||
|
// Save thinking level change to session
|
||||||
|
this.sessionManager.saveThinkingLevelChange(level);
|
||||||
|
|
||||||
// Show confirmation message with proper spacing
|
// Show confirmation message with proper spacing
|
||||||
this.chatContainer.addChild(new Spacer(1));
|
this.chatContainer.addChild(new Spacer(1));
|
||||||
const confirmText = new Text(chalk.dim(`Thinking level: ${level}`), 1, 0);
|
const confirmText = new Text(chalk.dim(`Thinking level: ${level}`), 1, 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue