diff --git a/src/cli/App.tsx b/src/cli/App.tsx index f4c1388..d6eb9fb 100644 --- a/src/cli/App.tsx +++ b/src/cli/App.tsx @@ -1250,6 +1250,10 @@ export default function App({ llmConfigRef.current = llmConfig; }, [llmConfig]); const [currentModelId, setCurrentModelId] = useState(null); + // Full model handle for API calls (e.g., "anthropic/claude-sonnet-4-5-20251101") + const [currentModelHandle, setCurrentModelHandle] = useState( + null, + ); // Derive agentName from agentState (single source of truth) const agentName = agentState?.name ?? null; const [agentDescription, setAgentDescription] = useState(null); @@ -2605,6 +2609,8 @@ export default function App({ } else { setCurrentModelId(agentModelHandle || null); } + // Store full handle for API calls (e.g., compaction) + setCurrentModelHandle(agentModelHandle || null); // Derive toolset from agent's model (not persisted, computed on resume) if (agentModelHandle) { @@ -6423,10 +6429,28 @@ export default function App({ } // Special handling for /compact command - summarize conversation history - if (msg.trim() === "/compact") { + // Supports: /compact, /compact all, /compact sliding_window + if (msg.trim().startsWith("/compact")) { + const parts = msg.trim().split(/\s+/); + const modeArg = parts[1] as "all" | "sliding_window" | undefined; + const validModes = ["all", "sliding_window"]; + + // Validate mode if provided + if (modeArg && !validModes.includes(modeArg)) { + const cmd = commandRunner.start( + msg.trim(), + `Invalid mode "${modeArg}". Valid modes: ${validModes.join(", ")}`, + ); + cmd.fail( + `Invalid mode "${modeArg}". Valid modes: ${validModes.join(", ")}`, + ); + return { submitted: true }; + } + + const modeDisplay = modeArg ? ` (mode: ${modeArg})` : ""; const cmd = commandRunner.start( msg.trim(), - "Compacting conversation history...", + `Compacting conversation history${modeDisplay}...`, ); setCommandRunning(true); @@ -6448,18 +6472,38 @@ export default function App({ } const client = await getClient(); + + // Compute model handle from llmConfig + const modelHandle = + llmConfig?.model_endpoint_type && llmConfig?.model + ? `${llmConfig.model_endpoint_type}/${llmConfig.model}` + : llmConfig?.model || null; + + // Build compaction settings if mode was specified + // Pass mode-specific prompt to override any agent defaults + const compactParams = + modeArg && modelHandle + ? { + compaction_settings: { + mode: modeArg, + model: modelHandle, + }, + } + : undefined; + // Use agent-level compact API for "default" conversation, // otherwise use conversation-level API const result = conversationIdRef.current === "default" - ? await client.agents.messages.compact(agentId) + ? await client.agents.messages.compact(agentId, compactParams) : await client.conversations.messages.compact( conversationIdRef.current, + compactParams, ); // Format success message with before/after counts and summary const outputLines = [ - `Compaction completed. Message buffer length reduced from ${result.num_messages_before} to ${result.num_messages_after}.`, + `Compaction completed${modeDisplay}. Message buffer length reduced from ${result.num_messages_before} to ${result.num_messages_after}.`, "", `Summary: ${result.summary}`, ]; diff --git a/src/cli/commands/registry.ts b/src/cli/commands/registry.ts index c4341ab..0e34a55 100644 --- a/src/cli/commands/registry.ts +++ b/src/cli/commands/registry.ts @@ -366,7 +366,8 @@ export const commands: Record = { }, }, "/compact": { - desc: "Summarize conversation history (compaction)", + desc: "Summarize conversation history (compaction) with optional mode", + args: "[all|sliding_window]", handler: () => { // Handled specially in App.tsx to access client and agent ID return "Compacting conversation...";