Skip to content

Commit 27d1e98

Browse files
kakaponickclaude
andcommitted
feat(cli): add --now to thread send to steer a running turn
Waiting for the turn to end can take minutes on a long-running agent. `--now` sends right away, like the queue's send-now button, and the message steers the running turn. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 003a5a6 commit 27d1e98

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

‎apps/server/src/bin.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,55 @@ it.layer(NodeServices.layer)("thread send", (it) => {
11451145
),
11461146
);
11471147

1148+
it.effect("sends right away with --now while the agent is working", () =>
1149+
withThreadStartFixture(({ baseDir, workspaceRoot }) =>
1150+
Effect.gen(function* () {
1151+
yield* runCliWithRuntime([
1152+
"thread",
1153+
"start",
1154+
workspaceRoot,
1155+
"Fix the flaky test",
1156+
"--base-dir",
1157+
baseDir,
1158+
]);
1159+
const [created] = yield* readProjectThreads(workspaceRoot);
1160+
const engine = yield* OrchestrationEngine.OrchestrationEngineService;
1161+
const now = DateTime.formatIso(yield* DateTime.now);
1162+
yield* engine.dispatch({
1163+
type: "thread.session.set",
1164+
commandId: CommandId.make("cmd-cli-send-now-running"),
1165+
threadId: created!.id,
1166+
session: {
1167+
threadId: created!.id,
1168+
status: "running",
1169+
providerName: "claudeAgent",
1170+
runtimeMode: created!.runtimeMode,
1171+
activeTurnId: null,
1172+
lastError: null,
1173+
updatedAt: now,
1174+
},
1175+
createdAt: now,
1176+
});
1177+
1178+
yield* runCliWithRuntime([
1179+
"thread",
1180+
"send",
1181+
created!.id,
1182+
"Change of plan",
1183+
"--now",
1184+
"--base-dir",
1185+
baseDir,
1186+
]);
1187+
1188+
const [thread] = yield* readProjectThreads(workspaceRoot);
1189+
assert.include(
1190+
thread!.messages.map((message) => message.text),
1191+
"Change of plan",
1192+
);
1193+
}),
1194+
),
1195+
);
1196+
11481197
it.effect("refuses threads awaiting approval and unknown threads", () =>
11491198
withThreadStartFixture(({ baseDir, workspaceRoot }) =>
11501199
Effect.gen(function* () {

‎apps/server/src/cli/thread.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ const runThreadSend = Effect.fn("runThreadSend")(function* (flags: {
448448
readonly baseDir: Option.Option<string>;
449449
readonly thread: string;
450450
readonly prompt: string;
451+
readonly now: boolean;
451452
readonly json: boolean;
452453
}) {
453454
const config = yield* resolveCliAuthConfig(flags, yield* GlobalFlag.LogLevel);
@@ -456,11 +457,10 @@ const runThreadSend = Effect.fn("runThreadSend")(function* (flags: {
456457
return yield* Effect.gen(function* () {
457458
const server = yield* connectLiveServer(config, Duration.hours(24));
458459
const threadId = flags.thread.trim();
459-
const thread = yield* waitForIdleThread(
460-
server.shell.pipe(
461-
Effect.map((shell) => shell.threads.find((candidate) => candidate.id === threadId)),
462-
),
460+
const readThread = server.shell.pipe(
461+
Effect.map((shell) => shell.threads.find((candidate) => candidate.id === threadId)),
463462
);
463+
const thread = flags.now ? yield* readThread : yield* waitForIdleThread(readThread);
464464
if (thread === undefined) {
465465
return yield* new ThreadNotFoundError({ threadId });
466466
}
@@ -521,6 +521,10 @@ const threadSendCommand = Command.make("send", {
521521
...projectLocationFlags,
522522
thread: Argument.String("thread").pipe(Argument.withDescription("Thread id.")),
523523
prompt: promptArgument,
524+
now: Flag.Boolean("now").pipe(
525+
Flag.withDescription("Send now. Steers running turn."),
526+
Flag.withDefault(false),
527+
),
524528
json: jsonFlag,
525529
}).pipe(
526530
Command.withDescription("Send prompt to thread. Waits for running turn to finish."),

0 commit comments

Comments
 (0)