@@ -14,7 +14,6 @@ import type {
1414import type { JsonValue } from "./app-server/serde_json/JsonValue" ;
1515import { ModelId } from "./ModelId" ;
1616import { AgentMode } from "./AgentMode" ;
17- import { CodexAdditionalRootsProvider } from "./CodexAdditionalRootsProvider" ;
1817import path from "node:path" ;
1918import { logger } from "./Logger" ;
2019import type {
@@ -39,15 +38,13 @@ import type {AuthenticationLogoutResponse, AuthenticationStatusResponse} from ".
3938export class CodexAcpClient {
4039
4140 private readonly codexClient : CodexAppServerClient ;
42- private readonly additionalRootsProvider : CodexAdditionalRootsProvider ;
4341 private readonly config : JsonObject ;
4442 private readonly modelProvider : string | null ;
4543 private gatewayConfig : GatewayConfig | null ;
4644
4745
4846 constructor ( codexClient : CodexAppServerClient , codexConfig ?: JsonObject , modelProvider ?: string ) {
4947 this . codexClient = codexClient ;
50- this . additionalRootsProvider = new CodexAdditionalRootsProvider ( codexClient ) ;
5148 this . config = codexConfig ?? { } ;
5249 this . modelProvider = modelProvider ?? null ;
5350 this . gatewayConfig = null ;
@@ -182,7 +179,7 @@ export class CodexAcpClient {
182179 }
183180
184181 async resumeSession ( request : acp . ResumeSessionRequest ) : Promise < SessionMetadata > {
185- await this . additionalRootsProvider . refreshSkills ( request ) ;
182+ await this . refreshSkills ( request . cwd , request . _meta ) ;
186183
187184 const response = await this . codexClient . threadResume ( {
188185 approvalPolicy : null ,
@@ -233,7 +230,7 @@ export class CodexAcpClient {
233230 }
234231
235232 async newSession ( request : acp . NewSessionRequest ) : Promise < SessionMetadata > {
236- await this . additionalRootsProvider . refreshSkills ( request ) ;
233+ await this . refreshSkills ( request . cwd , request . _meta ) ;
237234
238235 const response = await this . codexClient . threadStart ( {
239236 config : this . createSessionConfig ( request . cwd , request . mcpServers ) ,
@@ -288,6 +285,21 @@ export class CodexAcpClient {
288285 return this . gatewayConfig ?. modelProvider ?? this . modelProvider ;
289286 }
290287
288+ private async refreshSkills ( cwd : string , meta ?: Record < string , unknown > | null ) : Promise < void > {
289+ if ( ! cwd ) {
290+ return ;
291+ }
292+ const additionalRoots = readAdditionalRoots ( meta ) ;
293+ await this . codexClient . listSkills ( {
294+ cwds : [ cwd ] ,
295+ forceReload : true ,
296+ perCwdExtraUserRoots : [ {
297+ cwd : cwd ,
298+ extraUserRoots : additionalRoots
299+ } ]
300+ } ) ;
301+ }
302+
291303 /**
292304 * Create a codex config entry for MCP server
293305 */
@@ -343,11 +355,7 @@ export class CodexAcpClient {
343355 const input = buildPromptItems ( request . prompt ) ;
344356 const effort = modelId . effort as ReasoningEffort | null ; //TODO remove unsafe conversion
345357
346- const refreshSkillsRequest : { _meta ?: Record < string , unknown > | null , cwd ?: string } = { cwd : cwd } ;
347- if ( request . _meta !== undefined ) {
348- refreshSkillsRequest . _meta = request . _meta ;
349- }
350- await this . additionalRootsProvider . refreshSkills ( refreshSkillsRequest ) ;
358+ await this . refreshSkills ( cwd , request . _meta ) ;
351359 await this . codexClient . turnStart ( {
352360 outputSchema : null ,
353361 threadId : request . sessionId ,
@@ -572,6 +580,18 @@ interface GatewayConfig {
572580 }
573581}
574582
583+ function readAdditionalRoots ( meta : Record < string , unknown > | null | undefined ) : string [ ] {
584+ const rawRoots = meta ?. [ "additionalRoots" ] ;
585+ if ( ! Array . isArray ( rawRoots ) ) {
586+ return [ ] ;
587+ }
588+
589+ return Array . from ( new Set ( rawRoots
590+ . filter ( ( value ) : value is string => typeof value === "string" )
591+ . map ( value => value . trim ( ) )
592+ . filter ( value => value . length > 0 ) ) ) ;
593+ }
594+
575595function mergeGatewayConfig ( config : JsonObject , gatewayConfig : GatewayConfig | null ) : JsonObject {
576596 if ( gatewayConfig !== null ) {
577597 const newConfig = { ...config } ;
0 commit comments