Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions apps/server/src/cli/thread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -23,6 +24,7 @@ import {
persistServerRuntimeState,
} from "../serverRuntimeState.ts";
import {
launchModelSelection,
readLatestMessages,
resolveProject,
threadCommand,
Expand Down Expand Up @@ -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"],
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

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<string>) => {
const items = types.map((type, position) => ({ position, itemId: `item-${position}`, type }));
Expand Down
58 changes: 47 additions & 11 deletions apps/server/src/cli/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
readonly model: Option.Option<string>;
readonly option: ReadonlyArray<string>;
}) {
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),
Expand Down Expand Up @@ -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.",
Expand All @@ -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." })));
Expand All @@ -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,
);
Expand Down
5 changes: 5 additions & 0 deletions docs/user/outside-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ default model and permission mode, and runs in the project folder unless you
pass `--worktree <base-branch>`. `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 <instance-id> --model <slug>`. 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.
Expand Down
Loading