@@ -7,7 +7,6 @@ import * as Stream from "effect/Stream";
77import { ChildProcess , ChildProcessSpawner } from "effect/process" ;
88
99import { type ClaudeSettings , TextGenerationError } from "@t3tools/contracts" ;
10- import { parseCliArgs } from "@t3tools/shared/cliArgs" ;
1110import { resolveSpawnCommand } from "@t3tools/shared/shell" ;
1211
1312import * as TextGenerationOperations from "@t3tools/provider-core/server/textGenerationOperations" ;
@@ -34,6 +33,7 @@ import {
3433 hasClaudeManagedMcpConfig ,
3534 makeClaudeEnvironment ,
3635} from "../provider/Drivers/ClaudeHome.ts" ;
36+ import { readClaudeLaunchArgSettings } from "../orchestration-v2/Adapters/ClaudeAdapterV2.ts" ;
3737
3838const CLAUDE_TIMEOUT_MS = 180_000 ;
3939/** `--tools` takes bare names; patterns go in the allow list. */
@@ -76,9 +76,6 @@ const ClaudeErrorResult = Schema.Struct({
7676 errors : Schema . optionalKey ( Schema . Array ( Schema . String ) ) ,
7777} ) ;
7878const isClaudeErrorResult = Schema . is ( ClaudeErrorResult ) ;
79- const decodeLaunchSettings = Schema . decodeEffect (
80- Schema . fromJsonString ( Schema . Record ( Schema . String , Schema . Unknown ) ) ,
81- ) ;
8279const decodeJsonOption = Schema . decodeUnknownOption ( Schema . fromJsonString ( Schema . Unknown ) ) ;
8380
8481// Claude reports JSON errors on stdout; stderr may contain only wrapper notices.
@@ -142,34 +139,6 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
142139 ) ,
143140 ) ;
144141
145- // Claude passes one --settings flag, so ours has to carry the launch-arg settings too.
146- // Like the CLI, a value starting with "{" is JSON and anything else is a file path.
147- const readLaunchSettings = Effect . fn ( "readLaunchSettings" ) ( function * (
148- operation : TextGenerationOperations . Operation ,
149- cwd : string ,
150- ) {
151- const raw = parseCliArgs ( claudeSettings . launchArgs ) . flags . settings ;
152- if ( raw === undefined ) return { } ;
153- const value = raw ?. trim ( ) ?? "" ;
154- const fail = ( detail : string ) => ( cause : unknown ) =>
155- new TextGenerationError ( { operation, detail, cause } ) ;
156- if ( value . length === 0 ) {
157- return yield * new TextGenerationError ( {
158- operation,
159- detail : "The --settings launch argument needs a JSON object or file path." ,
160- } ) ;
161- }
162- const filePath = path . resolve ( cwd , value ) ;
163- const json = value . startsWith ( "{" )
164- ? value
165- : yield * fileSystem
166- . readFileString ( filePath )
167- . pipe ( Effect . mapError ( fail ( `Failed to read Claude settings file ${ filePath } .` ) ) ) ;
168- return yield * decodeLaunchSettings ( json ) . pipe (
169- Effect . mapError ( fail ( "The --settings launch argument is not a JSON object." ) ) ,
170- ) ;
171- } ) ;
172-
173142 const runClaudeJson = Effect . fn ( "runClaudeJson" ) ( function * < S extends Schema . Top > ( {
174143 operation,
175144 cwd,
@@ -220,10 +189,20 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
220189 const fastMode =
221190 fastModeDescriptor ?. type === "boolean" ? fastModeDescriptor . currentValue : undefined ;
222191 const settings = {
223- ...( yield * readLaunchSettings ( operation , cwd ) ) ,
192+ // Claude takes one --settings flag, so the launch-arg settings ride beneath ours.
193+ ...( yield * readClaudeLaunchArgSettings ( {
194+ settings : claudeSettings ,
195+ cwd,
196+ fileSystem,
197+ path,
198+ } ) . pipe (
199+ Effect . mapError (
200+ ( cause ) => new TextGenerationError ( { operation, detail : cause . message , cause } ) ,
201+ ) ,
202+ ) ) ,
224203 disableAllHooks : true ,
225204 ...( typeof thinking === "boolean" ? { alwaysThinkingEnabled : thinking } : { } ) ,
226- ...( fastMode ? { fastMode : true } : { } ) ,
205+ ...( typeof fastMode === "boolean" ? { fastMode } : { } ) ,
227206 ...( typeof ultracode === "boolean" ? { ultracode } : { } ) ,
228207 } ;
229208 const settingsJson = yield * encodeJsonForOperation (
0 commit comments