Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/CodexToolCallMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
createTerminalOutputMeta,
type TerminalOutputMode,
} from "./TerminalOutputMode";
import {createContextCompactionMeta} from "./ContextCompactionMeta";

type CodexItemStatus = CommandExecutionStatus | PatchApplyStatus | McpToolCallStatus | DynamicToolCallStatus | CollabAgentToolCallStatus;
type AcpToolCallStatus = "pending" | "in_progress" | "completed" | "failed";
Expand All @@ -45,7 +46,7 @@ type CommandExecutionItem = ThreadItem & { type: "commandExecution" };
type ContextCompactionItem = ThreadItem & { type: "contextCompaction" };
type AcpToolCallEvent = Extract<UpdateSessionEvent, { sessionUpdate: "tool_call" }>;

const CONTEXT_COMPACTION_META = { contextCompaction: true };
const CONTEXT_COMPACTION_META = createContextCompactionMeta();

function toAcpStatus(status: CodexItemStatus): AcpToolCallStatus {
switch (status) {
Expand Down Expand Up @@ -230,8 +231,8 @@ export function createContextCompactionStartUpdate(
return {
sessionUpdate: "tool_call",
toolCallId: item.id,
kind: "other",
title: "Context compacting",
kind: "think",
title: "Compact conversation",
status: "in_progress",
_meta: CONTEXT_COMPACTION_META,
};
Expand All @@ -243,7 +244,7 @@ export function createContextCompactionCompleteUpdate(
return {
sessionUpdate: "tool_call_update",
toolCallId: item.id,
title: "Context compacted",
title: "Compact conversation",
status: "completed",
_meta: CONTEXT_COMPACTION_META,
};
Expand All @@ -255,8 +256,8 @@ export function createCompletedContextCompactionUpdate(
return {
sessionUpdate: "tool_call",
toolCallId: item.id,
kind: "other",
title: "Context compacted",
kind: "think",
title: "Compact conversation",
status: "completed",
_meta: CONTEXT_COMPACTION_META,
};
Expand Down
29 changes: 29 additions & 0 deletions src/ContextCompactionMeta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const CONTEXT_COMPACTION_META_KEY = "contextCompaction";
export const CONTEXT_COMPACTION_META_VERSION = 1;

export type ContextCompactionTrigger = "manual" | "automatic";

export interface ContextCompactionMetadata {
version: typeof CONTEXT_COMPACTION_META_VERSION;
trigger?: ContextCompactionTrigger;
preTokens?: number;
postTokens?: number;
durationMs?: number;
error?: string;
}

/**
* Provider-neutral metadata for a synthetic ACP context-compaction tool call.
* The standard toolCallId and status fields own lifecycle identity and phase;
* this extension carries only compaction-specific facts.
*/
export function createContextCompactionMeta(
metadata: Omit<ContextCompactionMetadata, "version"> = {},
): Record<typeof CONTEXT_COMPACTION_META_KEY, ContextCompactionMetadata> {
return {
[CONTEXT_COMPACTION_META_KEY]: {
version: CONTEXT_COMPACTION_META_VERSION,
...metadata,
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
"update": {
"sessionUpdate": "tool_call",
"toolCallId": "context-compaction-id",
"kind": "other",
"title": "Context compacting",
"kind": "think",
"title": "Compact conversation",
"status": "in_progress",
"_meta": {
"contextCompaction": true
"contextCompaction": {
"version": 1
}
}
}
}
Expand All @@ -24,10 +26,12 @@
"update": {
"sessionUpdate": "tool_call_update",
"toolCallId": "context-compaction-id",
"title": "Context compacted",
"title": "Compact conversation",
"status": "completed",
"_meta": {
"contextCompaction": true
"contextCompaction": {
"version": 1
}
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/__tests__/CodexACPAgent/data/load-session-history.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,13 @@
"update": {
"sessionUpdate": "tool_call",
"toolCallId": "item-context-compaction-1",
"kind": "other",
"title": "Context compacted",
"kind": "think",
"title": "Compact conversation",
"status": "completed",
"_meta": {
"contextCompaction": true
"contextCompaction": {
"version": 1
}
}
}
}
Expand Down