fix(cli): preserve snapshot metadata in agent listings (#11423)

This commit is contained in:
KiritoXDone
2026-11-30 12:42:54 +00:00
committed by GitHub
parent d2d4105366
commit 23934841f0
2 changed files with 26 additions and 7 deletions
+16 -5
View File
@@ -14,11 +14,12 @@ function createPagingClient() {
archivedAt: null,
cwd: "/tmp/project",
createdAt: `2026-10-0${n}T00:00:00.000Z`,
updatedAt: `2026-10-0${n}T00:00:00.000Z`,
updatedAt: `2026-10-0${n}T02:00:00.000Z`,
labels: n === 3 ? { bot: "worker", issue: "42" } : {},
workspaceId: n === 3 ? "workspace-3" : undefined,
model: null,
lastUserMessageAt: null,
lastUserMessageAt: n === 3 ? "2026-10-03T01:00:00.000Z" : null,
backgroundWork: n === 3 ? { count: 2, runningCount: 1 } : undefined,
currentModeId: null,
availableModes: [],
pendingPermissions: [],
@@ -125,17 +126,27 @@ describe("buildAgentLsFetchOptions", () => {
});
describe("runLsCommand", () => {
it("includes labels and workspace IDs in JSON listings", async () => {
it("includes agent snapshot metadata in JSON listings", async () => {
const result = await listAgents({ daemonTarget, global: true }, async () =>
createPagingClient(),
);
const rows = JSON.parse(render(result, { format: "json" }));
expect(rows).toMatchObject([
{ name: "agent 3", labels: { bot: "worker", issue: "42" }, workspaceId: "workspace-3" },
{ name: "agent 2", labels: {}, workspaceId: null },
{
name: "agent 3",
labels: { bot: "worker", issue: "42" },
workspaceId: "workspace-3",
createdAt: "2026-10-03T00:00:00.000Z",
updatedAt: "2026-10-03T02:00:00.000Z",
lastUserMessageAt: "2026-10-03T01:00:00.000Z",
archivedAt: null,
backgroundWork: { count: 2, runningCount: 1 },
},
{ name: "agent 2", labels: {}, workspaceId: null, lastUserMessageAt: null },
{ name: "agent 1", labels: {}, workspaceId: null },
]);
expect(rows[1]).not.toHaveProperty("backgroundWork");
});
it("lists agents on every page, including one updated during the listing", async () => {
+10 -2
View File
@@ -25,8 +25,11 @@ export function addLsOptions(cmd: Command): Command {
.option("--thinking <id>", "Filter by thinking option ID");
}
/** Agent list item for display */
export interface AgentListItem {
/** Agent list item for structured output and table display. */
export interface AgentListItem extends Pick<
AgentSnapshotPayload,
"createdAt" | "updatedAt" | "lastUserMessageAt" | "archivedAt" | "backgroundWork"
> {
id: string;
shortId: string;
name: string;
@@ -113,6 +116,11 @@ function toListItem(agent: AgentSnapshotPayload): AgentListItem {
status: agent.status,
cwd: shortenPath(agent.cwd),
created: relativeTime(agent.createdAt),
createdAt: agent.createdAt,
updatedAt: agent.updatedAt,
lastUserMessageAt: agent.lastUserMessageAt,
archivedAt: agent.archivedAt,
backgroundWork: agent.backgroundWork,
background: agent.background === true,
labels: agent.labels,
workspaceId: agent.workspaceId ?? null,