diff --git a/apps/server/src/cli/thread.test.ts b/apps/server/src/cli/thread.test.ts index 5252d81b2a22f..a20331ee17d92 100644 --- a/apps/server/src/cli/thread.test.ts +++ b/apps/server/src/cli/thread.test.ts @@ -10,6 +10,7 @@ import * as Effect from "effect/Effect"; import * as Fiber from "effect/Fiber"; import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; +import * as Option from "effect/Option"; import * as Path from "effect/Path"; import { ChildProcess, ChildProcessSpawner } from "effect/process"; import * as TestClock from "effect/testing/TestClock"; @@ -23,6 +24,7 @@ import { persistServerRuntimeState, } from "../serverRuntimeState.ts"; import { + launchModelSelection, readLatestMessages, resolveProject, threadCommand, @@ -371,6 +373,50 @@ it.effect("--wait reports its run's result when a later run is the one waiting", }), ); +it.effect("start sends each --option as a typed model option", () => + Effect.gen(function* () { + const selection = yield* launchModelSelection({ + provider: Option.some("codex"), + model: Option.some("gpt-6.1-sol"), + option: ["reasoningEffort=high", " fastMode = false ", "note=a=b"], + }); + + assert.deepStrictEqual(selection, { + instanceId: "codex", + model: "gpt-6.1-sol", + options: [ + { id: "reasoningEffort", value: "high" }, + { id: "fastMode", value: false }, + { id: "note", value: "a=b" }, + ], + }); + }), +); + +it.effect("start rejects a repeated --option before reaching the server", () => + Effect.gen(function* () { + const error = yield* Command.runWith(threadCommand, { version: "0.0.0" })([ + "start", + ".", + "hi", + "--provider", + "codex", + "--model", + "gpt-6.1-sol", + "--option", + "reasoningEffort=high", + "--option", + "reasoningEffort=low", + ]).pipe(Effect.flip); + + assert.strictEqual(error.message, "--option reasoningEffort is given more than once."); + }).pipe( + Effect.provide( + Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer, TestConsole.layer), + ), + ), +); + /** Serves t3_thread_read pages the way the server does: positions count every item. */ const timelineTools = (types: ReadonlyArray) => { const items = types.map((type, position) => ({ position, itemId: `item-${position}`, type })); diff --git a/apps/server/src/cli/thread.ts b/apps/server/src/cli/thread.ts index 98d18a6c9d240..3566b75e20773 100644 --- a/apps/server/src/cli/thread.ts +++ b/apps/server/src/cli/thread.ts @@ -717,6 +717,45 @@ const launchWorkspaceStrategy = (input: { }), }); +/** + * Options are model specific, so they need an explicit model. `true` and + * `false` become booleans because boolean options such as fastMode only match + * a boolean. + */ +export const launchModelSelection = Effect.fn("cli.thread.launchModelSelection")(function* (input: { + readonly provider: Option.Option; + readonly model: Option.Option; + readonly option: ReadonlyArray; +}) { + if (Option.isSome(input.provider) !== Option.isSome(input.model)) { + return yield* new ThreadUsageError({ detail: "--provider and --model go together." }); + } + if (Option.isNone(input.provider) || Option.isNone(input.model)) { + if (input.option.length > 0) { + return yield* new ThreadUsageError({ detail: "--option needs --provider and --model." }); + } + return undefined; + } + const options: Array<{ readonly id: string; readonly value: string | boolean }> = []; + for (const entry of input.option) { + const separator = entry.indexOf("="); + const id = separator < 0 ? "" : entry.slice(0, separator).trim(); + const value = separator < 0 ? "" : entry.slice(separator + 1).trim(); + if (id.length === 0 || value.length === 0) { + return yield* new ThreadUsageError({ detail: `--option '${entry}' is not id=value.` }); + } + if (options.some((option) => option.id === id)) { + return yield* new ThreadUsageError({ detail: `--option ${id} is given more than once.` }); + } + options.push({ id, value: value === "true" ? true : value === "false" ? false : value }); + } + return { + instanceId: input.provider.value, + model: input.model.value, + ...(options.length === 0 ? {} : { options }), + }; +}); + const jsonFlag = Flag.Boolean("json").pipe( Flag.withDescription("Print JSON instead of text."), Flag.withDefault(false), @@ -793,6 +832,12 @@ const threadStartCommand = Command.make("start", { Flag.withDescription("Model slug. Defaults to the project's default model."), Flag.optional, ), + option: Flag.String("option").pipe( + Flag.withDescription( + "Model option as id=value, such as effort=high. Repeat for more. Needs --provider and --model.", + ), + Flag.atLeast(0), + ), worktree: Flag.String("worktree").pipe( Flag.withDescription( "Run in a new git worktree based on this branch, tag, or commit, instead of the project folder.", @@ -811,9 +856,7 @@ const threadStartCommand = Command.make("start", { Effect.gen(function* () { const message = yield* readMessageArgument(flags.message); const workspaceStrategy = yield* launchWorkspaceStrategy(flags); - if (Option.isSome(flags.provider) !== Option.isSome(flags.model)) { - return yield* new ThreadUsageError({ detail: "--provider and --model go together." }); - } + const modelSelection = yield* launchModelSelection(flags); const title = yield* decodeTitle( Option.getOrElse(flags.title, () => titleFromMessage(message)), ).pipe(Effect.mapError(() => new ThreadUsageError({ detail: "The title is empty." }))); @@ -828,14 +871,7 @@ const threadStartCommand = Command.make("start", { title, message, ...(workspaceStrategy === undefined ? {} : { workspaceStrategy }), - ...(Option.isSome(flags.provider) && Option.isSome(flags.model) - ? { - modelSelection: { - instanceId: flags.provider.value, - model: flags.model.value, - }, - } - : {}), + ...(modelSelection === undefined ? {} : { modelSelection }), }, ThreadLaunchResult, ); diff --git a/docs/user/outside-agents.md b/docs/user/outside-agents.md index 84d00cc98b16c..97bc0d385a3d7 100644 --- a/docs/user/outside-agents.md +++ b/docs/user/outside-agents.md @@ -153,6 +153,11 @@ default model and permission mode, and runs in the project folder unless you pass `--worktree `. `send` never interrupts: a busy thread gets the message as its next turn. Pass `-` as the message to read it from stdin. +To choose the model, pass `--provider --model `. Add +`--option id=value` for each model option, such as `--option effort=high`. +Option ids and values depend on the model; `true` and `false` set on/off +options. + `--wait` prints the agent's reply. It exits 1 when the run fails or stops, and 2 when the agent waits for an answer you give in the app. Add `--json` for a result that always includes the thread id.