diff --git a/apps/server/src/lazurio/agentCli.test.ts b/apps/server/src/lazurio/agentCli.test.ts index 564c7c3550226..70acb4e44fe55 100644 --- a/apps/server/src/lazurio/agentCli.test.ts +++ b/apps/server/src/lazurio/agentCli.test.ts @@ -1431,6 +1431,57 @@ const withPendingRequests = (world: World) => { }; describe("t3 request", () => { + it.effect( + "reads persisted answers without responding, including a resolved question outside the bounded timeline", + () => + Effect.gen(function* () { + const baseDir = makeBaseDir(); + const world = makeWorld(); + withPendingRequests(world); + const projection = world.projections.get("thread-question")!; + world.projections.set("thread-question", { + ...projection, + runtimeRequests: projection.runtimeRequests.map((request) => ({ + ...request, + status: "resolved" as const, + resolvedAt: at("2026-10-20T11:00:00.000Z"), + answers: { q1: "Wait\nverbatim" }, + })), + }); + world.boundedWithoutItems.add("thread-question"); + yield* withLiveServer(baseDir, world, () => + Effect.gen(function* () { + const history = yield* printedJson( + run([ + "request", + "history", + "--thread", + "thread-question", + "--base-dir", + baseDir, + "--json", + ]), + ); + assert.deepStrictEqual(history.output, { + requests: [ + { + requestId: "request-question", + threadId: "thread-question", + status: "resolved", + createdAt: "2026-10-20T09:00:00.000Z", + resolvedAt: "2026-10-20T11:00:00.000Z", + questions: [{ id: "q1", header: "Deploy", question: "Deploy now?", options: [] }], + answers: { q1: "Wait\nverbatim" }, + }, + ], + }); + assert.deepStrictEqual(world.fullReads, ["thread-question"]); + assert.deepStrictEqual(world.ownerDispatched, []); + }), + ); + }), + ); + it.effect("lists, answers and decides the requests threads wait on, as their user", () => Effect.gen(function* () { const baseDir = makeBaseDir(); diff --git a/apps/server/src/lazurio/agentCli.ts b/apps/server/src/lazurio/agentCli.ts index 376ca734f146b..9656e7ede92b6 100644 --- a/apps/server/src/lazurio/agentCli.ts +++ b/apps/server/src/lazurio/agentCli.ts @@ -52,6 +52,7 @@ import { mergeThreadLists, type PendingRequest, pendingRequestsOf, + questionHistoryOf, } from "./agentCliViews.ts"; import { readModelRecommendationRecord } from "./modelRecommendation.ts"; @@ -1141,6 +1142,28 @@ const requestListCommand = Command.make("list", { ...common, thread: requestThre ), ); +const requestHistoryCommand = Command.make("history", { + ...common, + thread: Flag.String("thread").pipe( + Flag.withDescription("The exact thread whose question history to read."), + ), +}).pipe( + Command.withDescription( + "Read a thread's persisted questions and answers, including resolved, cancelled and expired requests.", + ), + Command.withHandler((flags) => + run( + flags, + (connection) => + connection + .threadSnapshot(ThreadId.make(flags.thread), { full: true }) + .pipe(Effect.map(({ projection }) => ({ requests: questionHistoryOf(projection) }))), + ({ requests }) => + requests.map((request) => `${request.requestId} ${request.status}`).join("\n"), + ), + ), +); + const requestReadCommand = Command.make("read", { ...common, requestId: requestIdArgument, @@ -1325,6 +1348,7 @@ const requestCommand = Command.make("request").pipe( Command.withDescription("Answer the questions and permission requests threads wait on."), Command.withSubcommands([ requestListCommand, + requestHistoryCommand, requestReadCommand, requestRespondCommand, requestApproveCommand, diff --git a/apps/server/src/lazurio/agentCliViews.ts b/apps/server/src/lazurio/agentCliViews.ts index 07da8deb7eed5..83e4d4be429ee 100644 --- a/apps/server/src/lazurio/agentCliViews.ts +++ b/apps/server/src/lazurio/agentCliViews.ts @@ -77,6 +77,33 @@ export interface PendingRequest { readonly questions?: ReadonlyArray; } +/** Authoritative question state, including answers after a request stops being pending. */ +export const questionHistoryOf = (projection: OrchestrationV2ThreadProjection) => { + const questions = new Map( + projection.turnItems.flatMap((item) => + item.type === "user_input_request" ? [[item.requestId, item.questions] as const] : [], + ), + ); + return projection.runtimeRequests + .filter((request) => request.kind === "user_input") + .map((request) => ({ + requestId: request.id, + threadId: projection.thread.id, + status: request.status, + createdAt: DateTime.formatIso(request.createdAt), + resolvedAt: request.resolvedAt === null ? null : DateTime.formatIso(request.resolvedAt), + questions: questions.get(request.id) ?? [], + ...(request.status === "resolved" && request.answers !== undefined + ? { answers: request.answers } + : {}), + })) + .toSorted( + (left, right) => + left.createdAt.localeCompare(right.createdAt) || + left.requestId.localeCompare(right.requestId), + ); +}; + /** * The pending questions and approvals of one thread, from its control state. `complete` is false * when the details of a request lie outside the projection's timeline window, so the caller reads diff --git a/apps/server/src/lazurio/cli.test.ts b/apps/server/src/lazurio/cli.test.ts index d75de42d4dd61..1cca117be9407 100644 --- a/apps/server/src/lazurio/cli.test.ts +++ b/apps/server/src/lazurio/cli.test.ts @@ -188,7 +188,7 @@ describe("t3 lazurio", () => { Effect.gen(function* () { yield* run(["lazurio", "capabilities"]); assert.deepStrictEqual(yield* printed, [ - '{"version":1,"managedFolder":true,"modelRecommendation":true,"providerRefresh":true,"operatorPairing":true,"agentCli":true,"threadSendIdempotency":true,"threadSendOutcome":true,"buddyThread":true,"actingSender":true}', + '{"version":1,"managedFolder":true,"modelRecommendation":true,"providerRefresh":true,"operatorPairing":true,"agentCli":true,"requestHistory":true,"threadSendIdempotency":true,"threadSendOutcome":true,"buddyThread":true,"actingSender":true}', ]); }).pipe(Effect.provide(TestConsole.layer)), ); diff --git a/apps/server/src/lazurio/cli.ts b/apps/server/src/lazurio/cli.ts index 6d3c5f1a14575..9f21f3aed1026 100644 --- a/apps/server/src/lazurio/cli.ts +++ b/apps/server/src/lazurio/cli.ts @@ -282,6 +282,7 @@ const capabilitiesCommand = Command.make("capabilities").pipe( providerRefresh: true, operatorPairing: true, agentCli: true, + requestHistory: true, threadSendIdempotency: true, threadSendOutcome: true, buddyThread: true, diff --git a/docs/user/agent-cli.md b/docs/user/agent-cli.md index a0f7809c9e588..a6ce529e740b7 100644 --- a/docs/user/agent-cli.md +++ b/docs/user/agent-cli.md @@ -155,6 +155,15 @@ Approving and declining decide a request as its buttons in the app do. `--for-session` allows it for the rest of the agent's session where the agent offers that, and `t3 request deny --cancel` also stops the agent's turn. +### Read an answer after it arrives + +`t3 request history --thread --json` reads the stored questions of that +thread, oldest first, including their status and the answers T3 accepted. It +never answers or reopens a request. Use the returned request id to keep an +automation bound to its original question when a person continues the chat. +`requestHistory` in `t3 lazurio capabilities` declares this CLI support; the +command uses the running server's existing thread snapshot API. + ## Follow changes `t3 events` prints one JSON line for each thread in the sidebar, then a