feat(cli): add -f/--format to webcmd daemon status - #325
Conversation
`daemon status` fetches a fully-typed `DaemonStatus` object but only ever printed it as hand-written text lines, rejecting `-f` entirely. Agents/scripts polling daemon health had no structured way to read it (#175). Add `-f, --format` (default `table`, unchanged text output). Other formats render a `{ running, ...status }` envelope through the shared output path — `running` distinguishes the "daemon not reachable" case, which previously had no structured representation at all (`fetchDaemonStatus` returns null rather than a partial status object). Scope note: same slice-of-#175 approach as the `validate` PR — one complete, tested command rather than a partial pass across the full list in the issue. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
🟠 Maintainer review suggested — low confidenceThe automated review could not reach a fully supported conclusion. This review is advisory and does not block merging. |
There was a problem hiding this comment.
Pull request overview
Adds structured output support to the built-in webcmd daemon status command by wiring it into the shared renderer when a non-default output format is requested, enabling scripts/agents to reliably consume daemon health data.
Changes:
- Updated
daemonStatus()to accept an optional format parameter and torender()a structured{ running, ...status }envelope for non-tableformats. - Added unit tests for
-f jsonstructured output for both “running” and “not running” daemon states. - Extended CLI registration for
daemon statusto accept-f, --format <fmt>and validate/normalize the format viaresolveOutputFormat().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/commands/daemon.ts | Adds format-aware rendering for structured outputs while keeping legacy default output intact. |
| src/commands/daemon.test.ts | Adds tests for structured output behavior (currently JSON-only in the PR). |
| src/cli.ts | Registers -f/--format for daemon status and passes the validated format through. |
Suppressed comments (1)
src/commands/daemon.test.ts:133
- The new structured-output coverage for the stopped/unreachable daemon case only asserts JSON. Add a YAML variant too so
daemon status -f yamlhas test coverage for the{ running: false }envelope.
it('renders a structured envelope for -f json when not running (#175)', async () => {
fetchDaemonStatusMock.mockResolvedValue(null);
await daemonStatus('json');
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| it('renders a structured envelope for -f json when running (#175)', async () => { | ||
| fetchDaemonStatusMock.mockResolvedValue({ | ||
| ok: true, | ||
| pid: 12345, | ||
| uptime: 60, | ||
| daemonVersion: PKG_VERSION, | ||
| runtimeConnected: true, | ||
| runtimeName: 'fake', | ||
| pending: 0, | ||
| memoryMB: 64, | ||
| port: 9777, | ||
| }); | ||
|
|
||
| await daemonStatus('json'); | ||
|
|
||
| const printed = stdoutSpy.mock.calls.map((c: unknown[]) => c[0]).join('\n'); | ||
| const data = JSON.parse(printed); | ||
| expect(data).toMatchObject({ running: true, pid: 12345, port: 9777 }); | ||
| }); |
Address PR review feedback on #325: the new structured-output tests only covered -f json for both the running and not-running daemon states. Add the yaml equivalents so daemon status -f yaml is exercised too. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Subset of #365 ( |
|
Thank you @rohan911438 — |
|
Superseded by #306. |
Summary
Partial slice of #175.
daemon statusfetches a fully-typedDaemonStatusobject but onlyever printed it as hand-written text lines, rejecting
-fentirely.Agents/scripts polling daemon health had no structured way to read it.
Changes
daemonStatus()now takes an optionalfmt(defaulttable,unchanged text output).
{ running, ...status }envelope through theshared output path.
runningdistinguishes the "daemon notreachable" case, which previously had no structured representation
at all (
fetchDaemonStatusreturnsnullrather than a partialstatus object).
-f, --formattodaemon status.Scope note
Same slice-of-#175 approach as the
validatePR — one complete,tested command rather than a partial pass across the full list in the
issue.
Test plan
src/commands/daemon.test.ts:-f jsonwhenrunning and when not running.
npx tsc --noEmitclean.npx vitest run --project unit src/commands/daemon.test.ts— 16/16 pass.webcmd daemon status -f json/webcmd daemon status.