- support `claudeAgent.fastMode` in shared/contracts, provider dispatch, and Claude adapter SDK settings - gate fast mode to supported Claude models and restart/forward options in orchestration - unify draft/UI fast mode state (not Codex-only) and add browser/server tests plus SDK probe
Showing the changes to scripts (2 of 19 files). Show all
Unified · Split
| @@ -0,0 +1,129 @@ | ||
| 1 | +import { query, type SDKMessage } from "@anthropic-ai/claude-agent-sdk"; | |
| 2 | + | |
| 3 | +type ProbeMode = "off" | "on"; | |
| 4 | + | |
| 5 | +async function* emptyPrompt(): AsyncGenerator<never, void, void> {} | |
| 6 | + | |
| 7 | +function parseArgs(argv: ReadonlyArray<string>): { | |
| 8 | + readonly mode: ProbeMode | "both"; | |
| 9 | + readonly model?: string; | |
| 10 | + readonly cwd?: string; | |
| 11 | + readonly prompt?: string; | |
| 12 | +} { | |
| 13 | + let mode: ProbeMode | "both" = "both"; | |
| 14 | + let model: string | undefined; | |
| 15 | + let cwd: string | undefined; | |
| 16 | + let prompt: string | undefined; | |
| 17 | + | |
| 18 | + for (let index = 0; index < argv.length; index += 1) { | |
| 19 | + const value = argv[index]; | |
| 20 | + if (!value) { | |
| 21 | + continue; | |
| 22 | + } | |
| 23 | + if (value === "--mode") { | |
| 24 | + const next = argv[index + 1]; | |
| 25 | + if (next === "off" || next === "on" || next === "both") { | |
| 26 | + mode = next; | |
| 27 | + index += 1; | |
| 28 | + } | |
| 29 | + continue; | |
| 30 | + } | |
| 31 | + if (value === "--model") { | |
| 32 | + model = argv[index + 1]; | |
| 33 | + index += 1; | |
| 34 | + continue; | |
| 35 | + } | |
| 36 | + if (value === "--cwd") { | |
| 37 | + cwd = argv[index + 1]; | |
| 38 | + index += 1; | |
| 39 | + continue; | |
| 40 | + } | |
| 41 | + if (value === "--prompt") { | |
| 42 | + prompt = argv[index + 1] ?? prompt; | |
| 43 | + index += 1; | |
| 44 | + } | |
| 45 | + } | |
| 46 | + | |
| 47 | + return { | |
| 48 | + mode, | |
| 49 | + ...(model ? { model } : {}), | |
| 50 | + ...(cwd ? { cwd } : {}), | |
| 51 | + ...(prompt ? { prompt } : {}), | |
| 52 | + }; | |
| 53 | +} | |
| 54 | + | |
| 55 | +async function runProbe(input: { | |
| 56 | + readonly mode: ProbeMode; | |
| 57 | + readonly model?: string; | |
| 58 | + readonly cwd?: string; | |
| 59 | + readonly prompt?: string; | |
| 60 | +}): Promise<void> { | |
| 61 | + const messages = query({ | |
| 62 | + prompt: input.prompt ?? emptyPrompt(), | |
| 63 | + options: { | |
| 64 | + ...(input.model ? { model: input.model } : {}), | |
| 65 | + ...(input.cwd ? { cwd: input.cwd } : {}), | |
| 66 | + persistSession: false, | |
| 67 | + tools: [], | |
| 68 | + permissionMode: "plan", | |
| 69 | + includePartialMessages: true, | |
| 70 | + ...(input.mode === "on" ? { settings: { fastMode: true } } : {}), | |
| 71 | + }, | |
| 72 | + }); | |
| 73 | + | |
| 74 | + const summary = { | |
| 75 | + mode: input.mode, | |
| 76 | + initFastModeState: null as string | null, | |
| 77 | + resultFastModeState: null as string | null, | |
| 78 | + resultSubtype: null as string | null, | |
| 79 | + resultText: null as string | null, | |
| 80 | + }; | |
| 81 | + | |
| 82 | + const initialization = await messages.initializationResult(); | |
| 83 | + summary.initFastModeState = initialization.fast_mode_state ?? null; | |
| 84 | + | |
| 85 | + if (!input.prompt) { | |
| 86 | + messages.close(); | |
| 87 | + console.log(JSON.stringify(summary, null, 2)); | |
| 88 | + return; | |
| 89 | + } | |
| 90 | + | |
| 91 | + for await (const message of messages) { | |
| 92 | + handleProbeMessage(message, summary); | |
| 93 | + } | |
| 94 | + console.log(JSON.stringify(summary, null, 2)); | |
| 95 | +} | |
| 96 | + | |
| 97 | +function handleProbeMessage( | |
| 98 | + message: SDKMessage, | |
| 99 | + summary: { | |
| 100 | + mode: ProbeMode; | |
| 101 | + initFastModeState: string | null; | |
| 102 | + resultFastModeState: string | null; | |
| 103 | + resultSubtype: string | null; | |
| 104 | + resultText: string | null; | |
| 105 | + }, | |
| 106 | +): void { | |
| 107 | + if (message.type !== "result") { | |
| 108 | + return; | |
| 109 | + } | |
| 110 | + summary.resultSubtype = message.subtype; | |
| 111 | + summary.resultFastModeState = message.fast_mode_state ?? null; | |
| 112 | + summary.resultText = message.subtype === "success" ? message.result : message.errors.join("\n"); | |
| 113 | +} | |
| 114 | + | |
| 115 | +async function main(): Promise<void> { | |
| 116 | + const args = parseArgs(process.argv.slice(2)); | |
| 117 | + const modes = args.mode === "both" ? (["off", "on"] as const) : [args.mode]; | |
| 118 | + | |
| 119 | + for (const mode of modes) { | |
| 120 | + await runProbe({ | |
| 121 | + mode, | |
| 122 | + ...(args.model ? { model: args.model } : {}), | |
| 123 | + ...(args.cwd ? { cwd: args.cwd } : {}), | |
| 124 | + ...(args.prompt ? { prompt: args.prompt } : {}), | |
| 125 | + }); | |
| 126 | + } | |
| 127 | +} | |
| 128 | + | |
| 129 | +await main(); | |
| @@ -4,10 +4,12 @@ · 3 unmodified lines | ||
| 4 | 4 | "type": "module", |
| 5 | 5 | "scripts": { |
| 6 | 6 | "prepare": "effect-language-service patch", |
| 7 | + "claude-fast-mode-probe": "bun run claude-fast-mode-probe.ts", | |
| 7 | 8 | "typecheck": "tsc --noEmit", |
| 8 | 9 | "test": "vitest run" |
| 9 | 10 | }, |
| 10 | 11 | "dependencies": { |
| 12 | + "@anthropic-ai/claude-agent-sdk": "^0.2.77", | |
| 11 | 13 | "@effect/platform-node": "catalog:", |
| 12 | 14 | "@t3tools/contracts": "workspace:*", |
| 13 | 15 | "@t3tools/shared": "workspace:*", |