Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/session-list-daemon-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hunkdiff": patch
---

Report whether the session daemon is reachable in `hunk session list --json` so callers can tell a down daemon from an empty session set.
2 changes: 1 addition & 1 deletion src/session/agent/commands.daemon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("resolveDaemonAvailability with no daemon listening", () => {
action: "list",
output: "json",
} satisfies SessionCommandInput);
expect(JSON.parse(output)).toEqual({ sessions: [] });
expect(JSON.parse(output)).toEqual({ sessions: [], daemon: { available: false } });
});

probeTest(
Expand Down
44 changes: 44 additions & 0 deletions src/session/agent/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,50 @@ describe("session command compatibility checks", () => {
expect(output).toBe("No active Hunk sessions.\n");
});

// Intent: the JSON list value must distinguish a down daemon (available: false) from a healthy
// daemon with zero sessions (available: true). Text output stays unchanged in both states.
test("list reports daemon unavailable in JSON when no daemon is present", async () => {
setSessionCommandTestHooks({
createClient: () => {
throw new Error("list should not create a client without a daemon");
},
resolveDaemonAvailability: async () => false,
});

const output = await runSessionCommand({
kind: "session",
action: "list",
output: "json",
} satisfies SessionCommandInput);

expect(JSON.parse(output)).toEqual({
sessions: [],
daemon: { available: false },
});
});

test("list reports daemon available in JSON when a daemon is present", async () => {
setSessionCommandTestHooks({
createClient: () =>
createClient({
listSessions: async () => [createTestListedSession("session-1")],
}),
resolveDaemonAvailability: async () => true,
});

const output = await runSessionCommand({
kind: "session",
action: "list",
output: "json",
} satisfies SessionCommandInput);

const parsed = JSON.parse(output);
expect(parsed.daemon).toEqual({ available: true });
expect(parsed).toMatchObject({
sessions: [{ sessionId: "session-1" }],
});
});

// Intent: remaining command branches dispatch to the daemon and keep text output stable.
test("routes remaining session actions through the daemon and formats text output", async () => {
const selector: SessionSelectorInput = { sessionId: "session-1" };
Expand Down
10 changes: 8 additions & 2 deletions src/session/agent/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ export async function runSessionCommand(input: SessionCommandInput) {
input.action,
) ?? resolveDaemonAvailability(input.action));
if (!daemonAvailable && input.action === "list") {
return renderOutput(input.output, { sessions: [] }, () => formatListOutput([]));
// Report daemon reachability in the JSON value so callers can tell a down daemon from a
// healthy daemon with zero sessions — both otherwise render an empty session list.
return renderOutput(input.output, { sessions: [], daemon: { available: false } }, () =>
formatListOutput([]),
);
}

const normalizedSelector = "selector" in input ? normalizeSessionSelector(input.selector) : null;
Expand All @@ -188,7 +192,9 @@ export async function runSessionCommand(input: SessionCommandInput) {
switch (input.action) {
case "list": {
const sessions = await client.listSessions();
return renderOutput(input.output, { sessions }, () => formatListOutput(sessions));
return renderOutput(input.output, { sessions, daemon: { available: true } }, () =>
formatListOutput(sessions),
);
}
case "get": {
const session = await client.getSession(normalizedSelector!);
Expand Down