-
Notifications
You must be signed in to change notification settings - Fork 4
feat: LLM-27711 Codex /compact command #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ import type { | |
| SkillsListResponse, | ||
| ThreadLoadedListParams, | ||
| ThreadLoadedListResponse, | ||
| ThreadCompactStartParams, | ||
| ThreadCompactStartResponse, | ||
| ThreadListParams, | ||
| ThreadListResponse, | ||
| ThreadReadParams, | ||
|
|
@@ -181,6 +183,21 @@ export class CodexAppServerClient { | |
| } | ||
| } | ||
|
|
||
| async runCompact(params: ThreadCompactStartParams): Promise<TurnCompletedNotification> { | ||
| let resolveTurnCompleted!: (event: TurnCompletedNotification) => void; | ||
| const turnCompleted = new Promise<TurnCompletedNotification>((resolve) => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why compact needs to wait for turn/end? Won't this be done automatically by common event handling? |
||
| resolveTurnCompleted = resolve; | ||
| }); | ||
| const releaseCapture = this.captureTurnCompletions(params.threadId, resolveTurnCompleted); | ||
|
|
||
| try { | ||
| await this.threadCompactStart(params); | ||
| return await turnCompleted; | ||
| } finally { | ||
| releaseCapture(); | ||
| } | ||
| } | ||
|
|
||
| async turnInterrupt(params: TurnInterruptParams): Promise<TurnInterruptResponse> { | ||
| return await this.sendRequest({ method: "turn/interrupt", params: params }); | ||
| } | ||
|
|
@@ -205,6 +222,10 @@ export class CodexAppServerClient { | |
| return await this.sendRequest({ method: "thread/read", params: params }); | ||
| } | ||
|
|
||
| async threadCompactStart(params: ThreadCompactStartParams): Promise<ThreadCompactStartResponse> { | ||
| return await this.sendRequest({ method: "thread/compact/start", params }); | ||
| } | ||
|
|
||
| async listMcpServerStatus(params: ListMcpServerStatusParams): Promise<ListMcpServerStatusResponse> { | ||
| return await this.sendRequest({ method: "mcpServerStatus/list", params }); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import type {AgentSideConnection, AvailableCommand} from "@agentclientprotocol/s | |
| import {ACPSessionConnection} from "./ACPSessionConnection"; | ||
| import type {CodexAcpClient} from "./CodexAcpClient"; | ||
| import type {RateLimitSnapshot, SkillsListEntry} from "./app-server/v2"; | ||
| import type {TurnCompletedNotification} from "./app-server/v2"; | ||
| import type {SessionState} from "./CodexAcpServer"; | ||
| import type {RateLimitsMap} from "./RateLimitsMap"; | ||
| import type {TokenCount} from "./TokenCount"; | ||
|
|
@@ -41,7 +42,7 @@ export class CodexCommands { | |
| } | ||
| } | ||
|
|
||
| async tryHandle(prompt: acp.ContentBlock[], sessionState: SessionState): Promise<boolean> { | ||
| async tryHandle(prompt: acp.ContentBlock[], sessionState: SessionState): Promise<CommandHandlingResult | false> { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is intention behind this return type? And why we added type |
||
| const command = this.parseCommand(prompt); | ||
| if (command) { | ||
| return this.handleCommand(command, sessionState); | ||
|
|
@@ -91,6 +92,11 @@ export class CodexCommands { | |
| description: "Display session configuration and token usage.", | ||
| input: null | ||
| }, | ||
| { | ||
| name: "compact", | ||
| description: "Summarize conversation to prevent hitting the context limit.", | ||
| input: null | ||
| }, | ||
| { | ||
| name: "logout", | ||
| description: "Sign out of Codex. This option is available when you are logged in via ChatGPT.", | ||
|
|
@@ -119,10 +125,12 @@ export class CodexCommands { | |
| }; | ||
| } | ||
|
|
||
| async handleCommand(command: ParsedCommand, sessionState: SessionState): Promise<boolean> { | ||
| async handleCommand(command: ParsedCommand, sessionState: SessionState): Promise<CommandHandlingResult> { | ||
| const sessionId = sessionState.sessionId; | ||
|
|
||
| switch (command.name) { | ||
| case "compact": | ||
| return await this.runWithProcessCheck(() => this.codexAcpClient.compactSession(sessionId)); | ||
| case "status": { | ||
| const session = new ACPSessionConnection(this.connection, sessionId); | ||
| const message = this.buildStatusMessage(sessionState); | ||
|
|
@@ -355,3 +363,4 @@ export class CodexCommands { | |
| } | ||
|
|
||
| type ParsedCommand = { name: string; input: string | null }; | ||
| type CommandHandlingResult = true | TurnCompletedNotification; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remain if (turnCompleted.turn.status === "interrupted") here and would remove "ifNeeded" from the extracted method. This would be more explicit and even more short.