Skip to content

Commit 9de2dfe

Browse files
t3dotggclaude
andcommitted
feat(cli): add t3 thread list, show, and send
Scripts and agents can now list threads, read their latest messages, and send a message to a thread on the local running server. send --wait blocks until the turn ends and prints the agent's reply. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 7b84431 commit 9de2dfe

4 files changed

Lines changed: 644 additions & 0 deletions

File tree

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,69 @@ it.layer(NodeServices.layer)("bin cli parsing", (it) => {
841841
}),
842842
);
843843

844+
it.effect("lists, messages, and reads threads through a running server", () =>
845+
Effect.gen(function* () {
846+
const baseDir = NodeFS.mkdtempSync(
847+
NodePath.join(NodeOS.tmpdir(), "t3-cli-threads-live-test-"),
848+
);
849+
const workspaceRoot = NodeFS.mkdtempSync(
850+
NodePath.join(NodeOS.tmpdir(), "t3-cli-threads-live-workspace-"),
851+
);
852+
853+
yield* withLiveProjectCliServer(baseDir, () =>
854+
Effect.gen(function* () {
855+
yield* runCliWithRuntime([
856+
"project",
857+
"add",
858+
workspaceRoot,
859+
"--title",
860+
"Live Project",
861+
"--base-dir",
862+
baseDir,
863+
]);
864+
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery.ProjectionSnapshotQuery;
865+
const project = (yield* projectionSnapshotQuery.getSnapshot()).projects.find(
866+
(candidate) => candidate.workspaceRoot === workspaceRoot,
867+
)!;
868+
const engine = yield* OrchestrationEngine.OrchestrationEngineService;
869+
yield* engine.dispatch({
870+
type: "thread.create",
871+
commandId: CommandId.make("cmd-cli-live-thread"),
872+
threadId: ThreadId.make("thread-cli-live"),
873+
projectId: project.id,
874+
title: "Live thread",
875+
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5-codex" },
876+
interactionMode: "default",
877+
runtimeMode: "full-access",
878+
branch: null,
879+
worktreePath: null,
880+
createdAt: DateTime.formatIso(yield* DateTime.now),
881+
});
882+
883+
const listed = yield* captureStdout(
884+
runCli(["thread", "list", "--project", workspaceRoot, "--base-dir", baseDir]),
885+
);
886+
assert.equal(listed.output, "thread-cli-live idle Live Project Live thread");
887+
888+
yield* captureStdout(
889+
runCli([
890+
"thread",
891+
"send",
892+
"thread-cli-live",
893+
"Hello from the CLI",
894+
"--base-dir",
895+
baseDir,
896+
]),
897+
);
898+
const shown = yield* captureStdout(
899+
runCli(["thread", "show", "thread-cli-live", "--base-dir", baseDir]),
900+
);
901+
assert.equal(shown.output, "Live thread (idle)\n\n[user]\nHello from the CLI");
902+
}),
903+
);
904+
}),
905+
);
906+
844907
it.effect("rejects dev-url on project commands", () =>
845908
Effect.gen(function* () {
846909
const workspaceRoot = NodeFS.mkdtempSync(

‎apps/server/src/bin.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { serviceLauncherCommand } from "./cli/serviceLauncher.ts";
2424
import { servicePreflightCommand } from "./cli/servicePreflight.ts";
2525
import { sshHelperCommand } from "./cli/sshHelper.ts";
2626
import { themeCommand } from "./cli/theme.ts";
27+
import { threadCommand } from "./cli/thread.ts";
2728
import { triageCommand } from "./cli/triage.ts";
2829

2930
const CliRuntimeLayer = Layer.mergeAll(NodeServices.layer, NetService.layer);
@@ -63,6 +64,7 @@ export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
6364
pairCommand,
6465
authCommand,
6566
projectCommand,
67+
threadCommand,
6668
serviceCommand,
6769
updateCommand,
6870
uninstallCommand,

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

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import {
2+
type OrchestrationThreadShell,
3+
ProjectId,
4+
ProviderInstanceId,
5+
ThreadId,
6+
TurnId,
7+
} from "@t3tools/contracts";
8+
import { assert, describe, it } from "@effect/vitest";
9+
10+
import { turnOutcome } from "./thread.ts";
11+
12+
const SENT_AT = "2026-09-24T12:00:00.000Z";
13+
const EARLIER = "2026-09-24T11:00:00.000Z";
14+
15+
const makeThread = (
16+
overrides: Partial<OrchestrationThreadShell> = {},
17+
): OrchestrationThreadShell => ({
18+
id: ThreadId.make("thread-1"),
19+
projectId: ProjectId.make("project-1"),
20+
title: "Thread",
21+
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5-codex" },
22+
runtimeMode: "full-access",
23+
interactionMode: "default",
24+
branch: null,
25+
worktreePath: null,
26+
pullRequests: [],
27+
latestTurn: null,
28+
createdAt: EARLIER,
29+
updatedAt: EARLIER,
30+
archivedAt: null,
31+
settledOverride: null,
32+
settledAt: null,
33+
session: null,
34+
latestUserMessageAt: null,
35+
hasPendingApprovals: false,
36+
hasPendingUserInput: false,
37+
hasActionableProposedPlan: false,
38+
...overrides,
39+
});
40+
41+
const makeTurn = (
42+
requestedAt: string,
43+
state: NonNullable<OrchestrationThreadShell["latestTurn"]>["state"],
44+
) => ({
45+
turnId: TurnId.make(`turn-${requestedAt}`),
46+
state,
47+
requestedAt,
48+
startedAt: requestedAt,
49+
completedAt: state === "running" ? null : requestedAt,
50+
assistantMessageId: null,
51+
});
52+
53+
const makeSession = (
54+
status: NonNullable<OrchestrationThreadShell["session"]>["status"],
55+
updatedAt: string,
56+
) => ({
57+
threadId: ThreadId.make("thread-1"),
58+
status,
59+
providerName: "codex",
60+
runtimeMode: "full-access" as const,
61+
activeTurnId: null,
62+
lastError: status === "error" ? "provider crashed" : null,
63+
updatedAt,
64+
});
65+
66+
describe("turnOutcome", () => {
67+
it("keeps waiting while the previous turn is still the latest turn", () => {
68+
assert.equal(
69+
turnOutcome(makeThread({ latestTurn: makeTurn(EARLIER, "completed") }), SENT_AT),
70+
undefined,
71+
);
72+
});
73+
74+
it("keeps waiting while the requested turn runs", () => {
75+
assert.equal(
76+
turnOutcome(makeThread({ latestTurn: makeTurn(SENT_AT, "running") }), SENT_AT),
77+
undefined,
78+
);
79+
});
80+
81+
it("reports how the requested turn ended", () => {
82+
assert.equal(
83+
turnOutcome(makeThread({ latestTurn: makeTurn(SENT_AT, "completed") }), SENT_AT),
84+
"completed",
85+
);
86+
assert.equal(
87+
turnOutcome(makeThread({ latestTurn: makeTurn(SENT_AT, "interrupted") }), SENT_AT),
88+
"interrupted",
89+
);
90+
});
91+
92+
it("reports a turn that failed to start", () => {
93+
const thread = makeThread({
94+
latestTurn: makeTurn(EARLIER, "completed"),
95+
session: makeSession("error", SENT_AT),
96+
});
97+
assert.equal(turnOutcome(thread, SENT_AT), "error");
98+
});
99+
100+
it("ignores a session error from before the message was sent", () => {
101+
const thread = makeThread({ session: makeSession("error", EARLIER) });
102+
assert.equal(turnOutcome(thread, SENT_AT), undefined);
103+
});
104+
105+
it("stops when the turn needs an approval or an answer", () => {
106+
const running = makeTurn(SENT_AT, "running");
107+
assert.equal(
108+
turnOutcome(makeThread({ latestTurn: running, hasPendingApprovals: true }), SENT_AT),
109+
"needs-input",
110+
);
111+
assert.equal(
112+
turnOutcome(makeThread({ latestTurn: running, hasPendingUserInput: true }), SENT_AT),
113+
"needs-input",
114+
);
115+
});
116+
});

0 commit comments

Comments
 (0)