33 */
44import type {
55 AgentHarness ,
6+ AgentHarnessCompactParams ,
7+ AgentHarnessCompactResult ,
68 ContextEngineHostCapability ,
79} from "openclaw/plugin-sdk/agent-harness-runtime" ;
810import type {
@@ -25,6 +27,12 @@ const CODEX_APP_SERVER_CONTEXT_ENGINE_HOST_CAPABILITIES = [
2527/** Public model-listing types exposed for Codex app-server catalog callers. */
2628export type { CodexAppServerListModelsOptions , CodexAppServerModel , CodexAppServerModelListResult } ;
2729
30+ type CodexAppServerAgentHarness = AgentHarness & {
31+ compactAfterContextEngine ?(
32+ params : AgentHarnessCompactParams ,
33+ ) : Promise < AgentHarnessCompactResult | undefined > ;
34+ } ;
35+
2836/**
2937 * Creates the Codex app-server harness used for attempts, side questions,
3038 * compaction, reset, and disposal.
@@ -41,7 +49,7 @@ export function createCodexAppServerAgentHarness(options?: {
4149 id . trim ( ) . toLowerCase ( ) ,
4250 ) ,
4351 ) ;
44- return {
52+ const harness : CodexAppServerAgentHarness = {
4553 id : options ?. id ?? "codex" ,
4654 label : options ?. label ?? "Codex agent harness" ,
4755 contextEngineHostCapabilities : CODEX_APP_SERVER_CONTEXT_ENGINE_HOST_CAPABILITIES ,
@@ -80,6 +88,13 @@ export function createCodexAppServerAgentHarness(options?: {
8088 pluginConfig : options ?. resolvePluginConfig ?.( ) ?? options ?. pluginConfig ,
8189 } ) ;
8290 } ,
91+ compactAfterContextEngine : async ( params ) => {
92+ const { maybeCompactCodexAppServerSession } = await import ( "./src/app-server/compact.js" ) ;
93+ return maybeCompactCodexAppServerSession ( params , {
94+ pluginConfig : options ?. resolvePluginConfig ?.( ) ?? options ?. pluginConfig ,
95+ allowNonManualNativeRequest : true ,
96+ } ) ;
97+ } ,
8398 reset : async ( params ) => {
8499 if ( params . sessionFile ) {
85100 const { clearCodexAppServerBinding } = await import ( "./src/app-server/session-binding.js" ) ;
@@ -92,4 +107,5 @@ export function createCodexAppServerAgentHarness(options?: {
92107 await clearSharedCodexAppServerClientAndWait ( ) ;
93108 } ,
94109 } ;
110+ return harness ;
95111}
0 commit comments