@@ -26,6 +26,7 @@ import { ServerSettingsError } from "@t3tools/contracts";
2626
2727import { createModelCapabilities } from "@t3tools/shared/model" ;
2828import { resolveSpawnCommand } from "@t3tools/shared/shell" ;
29+ import { codexAppServerArgs , resolveCodexLaunchArgs } from "./codexLaunchArgs.ts" ;
2930import {
3031 AUTH_PROBE_TIMEOUT_MS ,
3132 buildServerProvider ,
@@ -286,99 +287,6 @@ export function buildCodexInitializeParams(): CodexSchema.V1InitializeParams {
286287 } ;
287288}
288289
289- export const T3CODE_CODEX_LAUNCH_ARGS_ENV = "T3CODE_CODEX_LAUNCH_ARGS" ;
290-
291- export const resolveCodexLaunchArgs = (
292- launchArgs ?: string ,
293- environment : NodeJS . ProcessEnv = process . env ,
294- ) => environment [ T3CODE_CODEX_LAUNCH_ARGS_ENV ] ?. trim ( ) || launchArgs ?. trim ( ) || "" ;
295-
296- export const codexLaunchArgv = ( launchArgs ?: string ) : ReadonlyArray < string > => {
297- const input = launchArgs ?. trim ( ) ;
298- if ( ! input ) return [ ] ;
299-
300- const args : string [ ] = [ ] ;
301- let current = "" ;
302- let quote : "'" | '"' | undefined ;
303- let quoted = false ;
304-
305- for ( let index = 0 ; index < input . length ; index ++ ) {
306- const char = input [ index ] ;
307- if ( char === undefined ) continue ;
308-
309- if ( quote ) {
310- if ( char === quote ) {
311- quote = undefined ;
312- quoted = true ;
313- } else if ( char === "\\" && quote === '"' ) {
314- const next = input [ index + 1 ] ;
315- if ( next !== undefined && [ '"' , "\\" , "$" , "`" ] . includes ( next ) ) {
316- current += next ;
317- index ++ ;
318- } else {
319- current += char ;
320- }
321- } else {
322- current += char ;
323- }
324- continue ;
325- }
326-
327- if ( char === "'" || char === '"' ) {
328- quote = char ;
329- quoted = true ;
330- } else if ( / \s / . test ( char ) ) {
331- if ( current || quoted ) {
332- args . push ( current ) ;
333- current = "" ;
334- quoted = false ;
335- }
336- } else if ( char === "\\" ) {
337- const next = input [ index + 1 ] ;
338- if ( next !== undefined && / \s / . test ( next ) ) {
339- current += next ;
340- index ++ ;
341- } else {
342- current += char ;
343- }
344- } else {
345- current += char ;
346- }
347- }
348-
349- if ( current || quoted ) args . push ( current ) ;
350- return args ;
351- } ;
352-
353- export const codexAppServerArgs = ( launchArgs ?: string ) => [
354- "app-server" ,
355- ...codexLaunchArgv ( launchArgs ) ,
356- ] ;
357-
358- export const codexExecLaunchArgs = ( launchArgs ?: string ) => {
359- const args = codexLaunchArgv ( launchArgs ) ;
360- const execArgs : Array < string > = [ ] ;
361- for ( let index = 0 ; index < args . length ; index ++ ) {
362- const arg = args [ index ] ;
363- if ( arg === undefined ) continue ;
364- if ( arg === "--strict-config" || arg . startsWith ( "--config=" ) || arg . startsWith ( "-c=" ) ) {
365- execArgs . push ( arg ) ;
366- } else if ( arg === "--config" || arg === "-c" || arg === "--enable" || arg === "--disable" ) {
367- execArgs . push ( arg ) ;
368- const value = args [ index + 1 ] ;
369- if ( value !== undefined && ! value . startsWith ( "-" ) ) {
370- execArgs . push ( value ) ;
371- index ++ ;
372- } else {
373- execArgs . pop ( ) ;
374- }
375- } else if ( arg . startsWith ( "--enable=" ) || arg . startsWith ( "--disable=" ) ) {
376- execArgs . push ( arg ) ;
377- }
378- }
379- return execArgs ;
380- } ;
381-
382290const probeCodexAppServerProvider = Effect . fn ( "probeCodexAppServerProvider" ) ( function * ( input : {
383291 readonly binaryPath : string ;
384292 readonly homePath ?: string ;
0 commit comments