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
51 changes: 51 additions & 0 deletions apps/server/src/lazurio/agentCli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
24 changes: 24 additions & 0 deletions apps/server/src/lazurio/agentCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
mergeThreadLists,
type PendingRequest,
pendingRequestsOf,
questionHistoryOf,
} from "./agentCliViews.ts";
import { readModelRecommendationRecord } from "./modelRecommendation.ts";

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions apps/server/src/lazurio/agentCliViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,33 @@ export interface PendingRequest {
readonly questions?: ReadonlyArray<unknown>;
}

/** 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
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/lazurio/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/lazurio/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ const capabilitiesCommand = Command.make("capabilities").pipe(
providerRefresh: true,
operatorPairing: true,
agentCli: true,
requestHistory: true,
threadSendIdempotency: true,
threadSendOutcome: true,
buddyThread: true,
Expand Down
9 changes: 9 additions & 0 deletions docs/user/agent-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <id> --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
Expand Down
Loading