Skip to content

Commit 35fca9d

Browse files
kakaponickclaude
andcommitted
feat(cli): add t3 thread send to continue an existing thread
`t3 thread send <thread> <prompt|->` starts the next turn with the thread's own model, runtime mode, and interaction mode. If the agent is still working, it waits for the turn to finish instead of steering, because a steer interrupts the running agent on some providers. It refuses threads that wait on an approval or an answer. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 30b4f09 commit 35fca9d

3 files changed

Lines changed: 359 additions & 121 deletions

File tree

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

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
1010
import {
1111
CommandId,
1212
EnvironmentOrchestrationHttpApi,
13+
EventId,
1314
ProviderDriverKind,
1415
ProviderInstanceId,
1516
type ServerProvider,
@@ -1071,3 +1072,96 @@ it.layer(NodeServices.layer)("thread start", (it) => {
10711072
),
10721073
);
10731074
});
1075+
1076+
it.layer(NodeServices.layer)("thread send", (it) => {
1077+
it.effect("sends a prompt to an existing thread and keeps its modes", () =>
1078+
withThreadStartFixture(({ baseDir, workspaceRoot }) =>
1079+
Effect.gen(function* () {
1080+
yield* runCliWithRuntime([
1081+
"thread",
1082+
"start",
1083+
workspaceRoot,
1084+
"Fix the flaky test",
1085+
"--base-dir",
1086+
baseDir,
1087+
]);
1088+
const [created] = yield* readProjectThreads(workspaceRoot);
1089+
const engine = yield* OrchestrationEngine.OrchestrationEngineService;
1090+
yield* engine.dispatch({
1091+
type: "thread.runtime-mode.set",
1092+
commandId: CommandId.make("cmd-cli-send-runtime-mode"),
1093+
threadId: created!.id,
1094+
runtimeMode: "auto-accept-edits",
1095+
createdAt: DateTime.formatIso(yield* DateTime.now),
1096+
});
1097+
1098+
const { output } = yield* captureStdout(
1099+
runCli([
1100+
"thread",
1101+
"send",
1102+
created!.id,
1103+
"Now add a regression test",
1104+
"--json",
1105+
"--base-dir",
1106+
baseDir,
1107+
]),
1108+
);
1109+
1110+
const [thread] = yield* readProjectThreads(workspaceRoot);
1111+
assert.equal(thread!.runtimeMode, "auto-accept-edits");
1112+
assert.deepEqual(thread!.modelSelection, created!.modelSelection);
1113+
assert.sameMembers(
1114+
thread!.messages.map((message) => message.text),
1115+
["Fix the flaky test", "Now add a regression test"],
1116+
);
1117+
assert.include(output, `"threadId":"${created!.id}"`);
1118+
}),
1119+
),
1120+
);
1121+
1122+
it.effect("refuses threads awaiting approval and unknown threads", () =>
1123+
withThreadStartFixture(({ baseDir, workspaceRoot }) =>
1124+
Effect.gen(function* () {
1125+
yield* runCliWithRuntime([
1126+
"thread",
1127+
"start",
1128+
workspaceRoot,
1129+
"Fix the flaky test",
1130+
"--base-dir",
1131+
baseDir,
1132+
]);
1133+
const [created] = yield* readProjectThreads(workspaceRoot);
1134+
const engine = yield* OrchestrationEngine.OrchestrationEngineService;
1135+
const now = DateTime.formatIso(yield* DateTime.now);
1136+
yield* engine.dispatch({
1137+
type: "thread.activity.append",
1138+
commandId: CommandId.make("cmd-cli-send-approval"),
1139+
threadId: created!.id,
1140+
activity: {
1141+
id: EventId.make("activity-cli-send-approval"),
1142+
tone: "approval",
1143+
kind: "approval.requested",
1144+
summary: "Run command",
1145+
payload: { requestId: "req-cli-send" },
1146+
turnId: null,
1147+
createdAt: now,
1148+
},
1149+
createdAt: now,
1150+
});
1151+
1152+
const send = (threadId: string) =>
1153+
runCliWithRuntime(["thread", "send", threadId, "Keep going", "--base-dir", baseDir]).pipe(
1154+
Effect.flip,
1155+
);
1156+
1157+
assert.equal(
1158+
(yield* send(created!.id)).message,
1159+
"Thread awaits approval or answer. Resolve in T3 Code.",
1160+
);
1161+
assert.equal((yield* send("thread-missing")).message, "Thread 'thread-missing' not found.");
1162+
const [thread] = yield* readProjectThreads(workspaceRoot);
1163+
assert.lengthOf(thread!.messages, 1);
1164+
}),
1165+
),
1166+
);
1167+
});

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { assert, it } from "@effect/vitest";
2+
import * as Effect from "effect/Effect";
3+
import * as Fiber from "effect/Fiber";
4+
import * as TestClock from "effect/testing/TestClock";
5+
6+
import { waitForIdleThread } from "./thread.ts";
7+
8+
it.effect("waits for the running turn to finish before returning the thread", () =>
9+
Effect.gen(function* () {
10+
const statuses = ["running", "starting", "ready"];
11+
let reads = 0;
12+
const readThread = Effect.sync(() => ({ session: { status: statuses[reads++]! } }));
13+
14+
const waiting = yield* Effect.forkChild(waitForIdleThread(readThread));
15+
yield* TestClock.adjust("5 seconds");
16+
assert.equal(reads, 2);
17+
yield* TestClock.adjust("5 seconds");
18+
const thread = yield* Fiber.join(waiting);
19+
20+
assert.equal(thread?.session.status, "ready");
21+
assert.equal(reads, 3);
22+
}),
23+
);
24+
25+
it.effect("returns an idle or missing thread without waiting", () =>
26+
Effect.gen(function* () {
27+
assert.deepEqual(yield* waitForIdleThread(Effect.succeed({ session: null })), {
28+
session: null,
29+
});
30+
assert.isUndefined(yield* waitForIdleThread(Effect.succeed(undefined)));
31+
}),
32+
);

0 commit comments

Comments
 (0)