Skip to content

Commit 35cb4dd

Browse files
fix(server): T3's fast mode choice wins over launch --settings in text generation
Reuse the Claude adapter's --settings reader so text generation parses inline JSON and relative files the same way chat turns do, and send an explicit fastMode like the adapter, so a launch fastMode:true no longer survives a T3 fastMode:false selection. AI-assisted; verified with the tests and tools listed above.
1 parent 216a747 commit 35cb4dd

3 files changed

Lines changed: 21 additions & 48 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,7 @@ const decodeClaudeLaunchArgSettings = Schema.decodeUnknownEffect(
19591959
* JSON, anything else is a file path relative to the cwd. makeClaudeQueryOptions
19601960
* merges the result beneath T3's own settings.
19611961
*/
1962-
const readClaudeLaunchArgSettings = Effect.fn("ClaudeAdapterV2.readLaunchArgSettings")(
1962+
export const readClaudeLaunchArgSettings = Effect.fn("ClaudeAdapterV2.readLaunchArgSettings")(
19631963
function* (input: {
19641964
readonly settings: ClaudeSettings | undefined;
19651965
readonly cwd: string | null;

‎apps/server/src/textGeneration/ClaudeTextGeneration.test.ts‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import * as TextGeneration from "./TextGeneration.ts";
2222
import { sanitizeThreadTitle } from "@t3tools/provider-core/server/textGenerationUtils";
2323
import { makeClaudeTextGeneration } from "./ClaudeTextGeneration.ts";
24+
import { ClaudeSettingsLaunchArgError } from "../orchestration-v2/Adapters/ClaudeAdapterV2.ts";
2425
import { writeFakeCli } from "@t3tools/provider-testing/fakeCli";
2526
const decodeClaudeSettings = Schema.decodeSync(ClaudeSettings);
2627

@@ -208,7 +209,7 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
208209

209210
const launchSettings = {
210211
disableAllHooks: false,
211-
fastMode: false,
212+
fastMode: true,
212213
env: { ANTHROPIC_VERTEX_PROJECT_ID: "issue-25017-marker" },
213214
};
214215
it.effect.each([
@@ -226,7 +227,7 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
226227
return yield* withFakeClaudeEnv(
227228
{
228229
output: JSON.stringify({ structured_output: { title: "Use launch settings" } }),
229-
settingsMustEqual: { ...launchSettings, disableAllHooks: true, fastMode: true },
230+
settingsMustEqual: { ...launchSettings, disableAllHooks: true, fastMode: false },
230231
claudeConfig: {
231232
launchArgs: `--settings '${inline ? JSON.stringify(launchSettings) : "launch-settings.json"}'`,
232233
},
@@ -238,25 +239,18 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
238239
modelSelection: createModelSelection(
239240
ProviderInstanceId.make("claudeAgent"),
240241
SYNTHETIC_CLAUDE_CAPABLE_MODEL,
241-
[{ id: "fastMode", value: true }],
242+
[{ id: "fastMode", value: false }],
242243
),
243244
}),
244245
);
245246
}).pipe(Effect.scoped),
246247
);
247248

248-
it.effect.each([
249-
[
250-
"malformed JSON",
251-
`--settings '{"env":'`,
252-
"The --settings launch argument is not a JSON object.",
253-
],
254-
["no value", "--settings", "The --settings launch argument needs a JSON object or file path."],
255-
] as const)("rejects a --settings launch arg with %s", ([, launchArgs, detail]) =>
249+
it.effect("reports an unreadable --settings launch arg as a text generation error", () =>
256250
withFakeClaudeEnv(
257251
{
258252
output: JSON.stringify({ structured_output: { title: "Unused" } }),
259-
claudeConfig: { launchArgs },
253+
claudeConfig: { launchArgs: `--settings '{"env":'` },
260254
},
261255
(textGeneration) =>
262256
Effect.gen(function* () {
@@ -271,7 +265,7 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
271265
}),
272266
);
273267

274-
expect(error.detail).toBe(detail);
268+
expect(error.detail).toBe(new ClaudeSettingsLaunchArgError({}).message);
275269
}),
276270
),
277271
);

‎apps/server/src/textGeneration/ClaudeTextGeneration.ts‎

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as Stream from "effect/Stream";
77
import { ChildProcess, ChildProcessSpawner } from "effect/process";
88

99
import { type ClaudeSettings, TextGenerationError } from "@t3tools/contracts";
10-
import { parseCliArgs } from "@t3tools/shared/cliArgs";
1110
import { resolveSpawnCommand } from "@t3tools/shared/shell";
1211

1312
import * 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

3838
const 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
});
7878
const isClaudeErrorResult = Schema.is(ClaudeErrorResult);
79-
const decodeLaunchSettings = Schema.decodeEffect(
80-
Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown)),
81-
);
8279
const 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

Comments
 (0)