mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-22 06:00:26 +00:00
WP16: Update main-new.ts to use InteractiveMode
This commit is contained in:
parent
0020de8518
commit
00982705f2
2 changed files with 26 additions and 42 deletions
|
|
@ -1520,9 +1520,9 @@ async function runInteractiveMode(
|
||||||
1. `npm run check` passes
|
1. `npm run check` passes
|
||||||
2. Manual test via cli-new.ts: Interactive mode works
|
2. Manual test via cli-new.ts: Interactive mode works
|
||||||
|
|
||||||
- [ ] Update `runInteractiveMode()` in main-new.ts
|
- [x] Update `runInteractiveMode()` in main-new.ts
|
||||||
- [ ] Update InteractiveMode instantiation
|
- [x] Update InteractiveMode instantiation
|
||||||
- [ ] Verify with `npm run check`
|
- [x] Verify with `npm run check`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,15 +19,14 @@ import { AgentSession } from "./core/agent-session.js";
|
||||||
import { exportFromFile } from "./export-html.js";
|
import { exportFromFile } from "./export-html.js";
|
||||||
import { messageTransformer } from "./messages.js";
|
import { messageTransformer } from "./messages.js";
|
||||||
import { findModel, getApiKeyForModel, getAvailableModels } from "./model-config.js";
|
import { findModel, getApiKeyForModel, getAvailableModels } from "./model-config.js";
|
||||||
import { runPrintMode, runRpcMode } from "./modes/index.js";
|
import { InteractiveMode, runPrintMode, runRpcMode } from "./modes/index.js";
|
||||||
import { SessionManager } from "./session-manager.js";
|
import { SessionManager } from "./session-manager.js";
|
||||||
import { SettingsManager } from "./settings-manager.js";
|
import { SettingsManager } from "./settings-manager.js";
|
||||||
import { expandSlashCommand, loadSlashCommands } from "./slash-commands.js";
|
import { loadSlashCommands } from "./slash-commands.js";
|
||||||
import { initTheme } from "./theme/theme.js";
|
import { initTheme } from "./theme/theme.js";
|
||||||
import { allTools, codingTools, type ToolName } from "./tools/index.js";
|
import { allTools, codingTools, type ToolName } from "./tools/index.js";
|
||||||
import { ensureTool } from "./tools-manager.js";
|
import { ensureTool } from "./tools-manager.js";
|
||||||
import { SessionSelectorComponent } from "./tui/session-selector.js";
|
import { SessionSelectorComponent } from "./tui/session-selector.js";
|
||||||
import { TuiRenderer } from "./tui/tui-renderer.js";
|
|
||||||
|
|
||||||
const defaultModelPerProvider: Record<KnownProvider, string> = {
|
const defaultModelPerProvider: Record<KnownProvider, string> = {
|
||||||
anthropic: "claude-sonnet-4-5",
|
anthropic: "claude-sonnet-4-5",
|
||||||
|
|
@ -727,83 +726,66 @@ async function selectSession(sessionManager: SessionManager): Promise<string | n
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runInteractiveMode(
|
async function runInteractiveMode(
|
||||||
agent: Agent,
|
session: AgentSession,
|
||||||
sessionManager: SessionManager,
|
|
||||||
settingsManager: SettingsManager,
|
|
||||||
version: string,
|
version: string,
|
||||||
changelogMarkdown: string | null = null,
|
changelogMarkdown: string | null = null,
|
||||||
collapseChangelog = false,
|
|
||||||
modelFallbackMessage: string | null = null,
|
modelFallbackMessage: string | null = null,
|
||||||
versionCheckPromise: Promise<string | null>,
|
versionCheckPromise: Promise<string | null>,
|
||||||
scopedModels: Array<{ model: Model<Api>; thinkingLevel: ThinkingLevel }> = [],
|
|
||||||
initialMessages: string[] = [],
|
initialMessages: string[] = [],
|
||||||
initialMessage?: string,
|
initialMessage?: string,
|
||||||
initialAttachments?: Attachment[],
|
initialAttachments?: Attachment[],
|
||||||
fdPath: string | null = null,
|
fdPath: string | null = null,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const renderer = new TuiRenderer(
|
const mode = new InteractiveMode(session, version, changelogMarkdown, fdPath);
|
||||||
agent,
|
|
||||||
sessionManager,
|
|
||||||
settingsManager,
|
|
||||||
version,
|
|
||||||
changelogMarkdown,
|
|
||||||
collapseChangelog,
|
|
||||||
scopedModels,
|
|
||||||
fdPath,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Initialize TUI (subscribes to agent events internally)
|
// Initialize TUI (subscribes to agent events internally)
|
||||||
await renderer.init();
|
await mode.init();
|
||||||
|
|
||||||
// Handle version check result when it completes (don't block)
|
// Handle version check result when it completes (don't block)
|
||||||
versionCheckPromise.then((newVersion) => {
|
versionCheckPromise.then((newVersion) => {
|
||||||
if (newVersion) {
|
if (newVersion) {
|
||||||
renderer.showNewVersionNotification(newVersion);
|
mode.showNewVersionNotification(newVersion);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Render any existing messages (from --continue mode)
|
// Render any existing messages (from --continue mode)
|
||||||
renderer.renderInitialMessages(agent.state);
|
mode.renderInitialMessages(session.state);
|
||||||
|
|
||||||
// Show model fallback warning at the end of the chat if applicable
|
// Show model fallback warning at the end of the chat if applicable
|
||||||
if (modelFallbackMessage) {
|
if (modelFallbackMessage) {
|
||||||
renderer.showWarning(modelFallbackMessage);
|
mode.showWarning(modelFallbackMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load file-based slash commands for expansion
|
|
||||||
const fileCommands = loadSlashCommands();
|
|
||||||
|
|
||||||
// Process initial message with attachments if provided (from @file args)
|
// Process initial message with attachments if provided (from @file args)
|
||||||
if (initialMessage) {
|
if (initialMessage) {
|
||||||
try {
|
try {
|
||||||
await agent.prompt(expandSlashCommand(initialMessage, fileCommands), initialAttachments);
|
await session.prompt(initialMessage, { attachments: initialAttachments });
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
||||||
renderer.showError(errorMessage);
|
mode.showError(errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process remaining initial messages if provided (from CLI args)
|
// Process remaining initial messages if provided (from CLI args)
|
||||||
for (const message of initialMessages) {
|
for (const message of initialMessages) {
|
||||||
try {
|
try {
|
||||||
await agent.prompt(expandSlashCommand(message, fileCommands));
|
await session.prompt(message);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
||||||
renderer.showError(errorMessage);
|
mode.showError(errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interactive loop
|
// Interactive loop
|
||||||
while (true) {
|
while (true) {
|
||||||
const userInput = await renderer.getUserInput();
|
const userInput = await mode.getUserInput();
|
||||||
|
|
||||||
// Process the message - agent.prompt will add user message and trigger state updates
|
// Process the message
|
||||||
try {
|
try {
|
||||||
await agent.prompt(userInput);
|
await session.prompt(userInput);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
// Display error in the TUI by adding an error message to the chat
|
|
||||||
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
||||||
renderer.showError(errorMessage);
|
mode.showError(errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1164,7 +1146,7 @@ export async function main(args: string[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create AgentSession for non-interactive modes
|
// Create AgentSession for non-interactive modes
|
||||||
// (Interactive mode will create its own session when we refactor TuiRenderer)
|
|
||||||
const fileCommands = loadSlashCommands();
|
const fileCommands = loadSlashCommands();
|
||||||
|
|
||||||
// Route to appropriate mode
|
// Route to appropriate mode
|
||||||
|
|
@ -1224,17 +1206,19 @@ export async function main(args: string[]) {
|
||||||
const fdPath = await ensureTool("fd");
|
const fdPath = await ensureTool("fd");
|
||||||
|
|
||||||
// Interactive mode - use TUI (may have initial messages from CLI args)
|
// Interactive mode - use TUI (may have initial messages from CLI args)
|
||||||
const collapseChangelog = settingsManager.getCollapseChangelog();
|
const session = new AgentSession({
|
||||||
await runInteractiveMode(
|
|
||||||
agent,
|
agent,
|
||||||
sessionManager,
|
sessionManager,
|
||||||
settingsManager,
|
settingsManager,
|
||||||
|
scopedModels,
|
||||||
|
fileCommands,
|
||||||
|
});
|
||||||
|
await runInteractiveMode(
|
||||||
|
session,
|
||||||
VERSION,
|
VERSION,
|
||||||
changelogMarkdown,
|
changelogMarkdown,
|
||||||
collapseChangelog,
|
|
||||||
modelFallbackMessage,
|
modelFallbackMessage,
|
||||||
versionCheckPromise,
|
versionCheckPromise,
|
||||||
scopedModels,
|
|
||||||
parsed.messages,
|
parsed.messages,
|
||||||
initialMessage,
|
initialMessage,
|
||||||
initialAttachments,
|
initialAttachments,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue