From c1bfd62b0c734484efcff09d6cd521acdbab2640 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Mon, 22 Jun 2026 00:36:52 +0900 Subject: feat: conversation compacting (manual + automatic) Implement roadmap item 10: conversation compaction to reclaim context window without losing the thread. Wire (0.11.0): - Add CompactionResult type - Add ConversationCompactedMessage WS event Transport-contract (0.15.0): - Add CompactResponse, CompactThresholdResponse, SetCompactThresholdRequest - Add ConversationCompactedMessage to WsServerMessage union - Re-export CompactionResult Conversation-store: - replaceHistory: delete all chunks, reset seq, append new messages - getCompactThreshold / setCompactThreshold (per-conversation setting) - compactThresholdKey added to keys.ts Session-orchestrator: - CompactionService interface + compactionHandle - conversationCompacted hook descriptor - createCompactionService: load history, split old/recent, call provider to summarize, replaceHistory with [system: summary] + recent N - Auto-trigger: resolveCompaction lazy dep, fires after turn settles (checks threshold, non-blocking) - Hook declared in manifest contributes.hooks + services Transport-http: - POST /conversations/:id/compact (manual trigger) - GET /conversations/:id/compact-threshold (read setting) - PUT /conversations/:id/compact-threshold (set setting) Transport-ws: - Subscribe to conversationCompacted hook - Broadcast conversation.compacted WS message CLI: - dispatch compact command FE handoff: frontend-compaction-handoff.md --- packages/cli/src/args.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'packages/cli/src/args.ts') diff --git a/packages/cli/src/args.ts b/packages/cli/src/args.ts index 30fa309..ecf6e2e 100644 --- a/packages/cli/src/args.ts +++ b/packages/cli/src/args.ts @@ -34,6 +34,7 @@ export type ParsedCommand = readonly status?: string; readonly all: boolean; } + | { readonly kind: "compact"; readonly server: string; readonly conversationId: string } | { readonly kind: "open"; readonly server: string; readonly conversationId: string } | { readonly kind: "read"; readonly server: string; readonly conversationId: string } | { @@ -108,6 +109,28 @@ export function parseArgs(argv: readonly string[], opts: ParseOpts): ParsedComma }; } + if (first === "compact") { + let server = opts.defaultServer; + let conversationId: string | undefined; + for (let i = 1; i < argv.length; i++) { + const arg = argv[i] as string; + if (arg === "--server") { + if (i + 1 >= argv.length) return { kind: "error", message: "--server requires a value" }; + server = argv[++i] as string; + } else if (arg.startsWith("--")) { + return { kind: "error", message: `Unknown flag: ${arg}` }; + } else if (conversationId !== undefined) { + return { kind: "error", message: `Unexpected argument for 'compact': ${arg}` }; + } else { + conversationId = arg; + } + } + if (conversationId === undefined) { + return { kind: "error", message: "'compact' requires a conversation id" }; + } + return { kind: "compact", server, conversationId }; + } + if (first === "read") { let server = opts.defaultServer; let conversationId: string | undefined; -- cgit v1.2.3