Skip to content

feat(supervisor): add --json flag to supervisor status - #601

Merged
jdx merged 4 commits into
jdx:mainfrom
disintegrator:supervisor-status-json
Jul 28, 2026
Merged

feat(supervisor): add --json flag to supervisor status#601
jdx merged 4 commits into
jdx:mainfrom
disintegrator:supervisor-status-json

Conversation

@disintegrator

@disintegrator disintegrator commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a --json flag to pitchfork supervisor status:

$ pitchfork supervisor status --json
{
  "status": "up",
  "web_ui": "http://127.0.0.1:3120"
}
  • Prints {"status": "up"} or {"status": "down"} depending on whether the supervisor is reachable (exit code 0 either way, so it's pipe-friendly for jq). If the IPC connection fails while the supervisor process is still alive (e.g. permission denied on the socket), it reports {"status": "unknown", "error": "..."} instead of a misleading down.
  • Includes "web_ui": "<url>" only when the web UI server is actually running.
  • The URL is queried from the running supervisor over IPC via a new GetWebUrl request rather than read from static config, so it reflects the server's actual bound address — correct even when the port was auto-bumped or settings changed after the supervisor started. The web server records its real URL (actual port, bind address, base path) at bind time; unspecified addresses like 0.0.0.0 render as localhost.
  • Older supervisors that don't recognize GetWebUrl respond with Error, which is treated as "no web UI" instead of failing (same pattern as SyncMdns/ReloadConfig).
  • The human-readable (non-JSON) output also gains a Web UI: <url> line when the web UI is up.

Testing

  • mise run ci-dev passes (fmt, clippy, render, 275 e2e tests).
  • Manually verified: up with web UI, down, and the port-bump case (occupied port 3120 → reported http://127.0.0.1:3121).

Contributor note

This PR was completely generated by a coding agent. I don't have deep experience with Rust but I also accept if this PR doesn't clear the quality bar and gets closed.

This PR was generated by Claude Code.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added an optional --json flag to supervisor status, returning JSON with status (up, down, or unknown) and, when available, the web interface URL plus any related error details.
    • Enhanced non-JSON supervisor status to still show the web interface URL when it can be determined.
  • Documentation
    • Updated CLI documentation/usage for supervisor status to include the optional --json flag.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 449e43b3-fadc-4be8-9967-dd77c2b3ef7d

📥 Commits

Reviewing files that changed from the base of the PR and between cff301c and 66c9dcd.

📒 Files selected for processing (2)
  • src/cli/supervisor/status.rs
  • src/supervisor/log_sink.rs
💤 Files with no reviewable changes (1)
  • src/supervisor/log_sink.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cli/supervisor/status.rs

📝 Walkthrough

Walkthrough

The supervisor status command now accepts --json, reports daemon state, and includes the web UI URL when available. IPC variants and handlers expose the URL, while the web server caches its normalized bound address. CLI documentation reflects the new option.

Changes

Supervisor status reporting

Layer / File(s) Summary
Web URL publication
src/web/mod.rs, src/web/server.rs
The web server caches a normalized URL from its bound address and exposes it through web::url().
Web URL IPC flow
src/ipc/mod.rs, src/supervisor/ipc_handlers.rs, src/ipc/client.rs
IPC adds GetWebUrl and WebUrl; the supervisor returns the cached URL and the client handles supported, unsupported, and unexpected responses.
Status command and documentation
src/cli/json_output.rs, src/cli/supervisor/status.rs, pitchfork.usage.kdl, docs/cli/...
supervisor status --json emits structured status with optional URL and distinguishes running, stopped, and unknown daemon states; CLI documentation is updated.

Supervisor plumbing cleanup

Layer / File(s) Summary
Pending sink ownership handling
src/supervisor/log_sink.rs, src/supervisor/mod.rs
PendingSink replaces is_some() with take(), and the supervisor synchronization import removes the unused mpsc symbol.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant StatusCommand
  participant IpcClient
  participant Supervisor
  User->>StatusCommand: Run supervisor status [--json]
  StatusCommand->>IpcClient: Request supervisor status
  IpcClient->>Supervisor: GetWebUrl
  Supervisor-->>IpcClient: WebUrl with optional URL
  IpcClient-->>StatusCommand: Status data
  StatusCommand-->>User: Human-readable or JSON output
Loading

Possibly related PRs

  • jdx/pitchfork#661: Both changes modify the supervisor log-sink subsystem, including PendingSink behavior.

Poem

I’m a rabbit with status to share,
“Up” in JSON, with a URL there.
IPC carries news just so,
The web address starts to glow.
--json makes the report fair!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main user-facing change: adding a --json flag to supervisor status.
Docstring Coverage ✅ Passed Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a --json flag to pitchfork supervisor status, returning structured output with status (up/down/unknown), an optional web_ui URL, and an optional error field. The web UI URL is queried live over IPC from the running supervisor rather than read from static config, so it correctly reflects port-bumped or changed addresses.

  • src/web/server.rs records the actual bound URL in a WEB_URL OnceLock at startup; unspecified bind addresses (0.0.0.0) render as localhost, and IPv6 addresses are bracket-quoted correctly.
  • A new GetWebUrl IPC request/response pair lets the CLI ask the running supervisor for the URL; old supervisors that respond with Error are treated as "web UI not running" for backward compatibility.
  • When the IPC connect fails, the code falls back to checking the supervisor PID via PROCS.is_running to distinguish a genuinely stopped supervisor (\"down\") from a running-but-unreachable one (\"unknown\"), addressing a prior review concern.

Confidence Score: 5/5

Safe to merge; the changes are additive, backward-compatible, and cleanly scoped to the new --json flag and web URL reporting.

The new IPC request is handled gracefully on older supervisors, the URL derivation from the actual bound address is correct, the three-state status logic is sound, and the two dead-code removals are verified safe.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/cli/supervisor/status.rs Adds --json flag with status_json() helper; properly distinguishes "up"/"down"/"unknown" using process-level check when IPC fails.
src/ipc/client.rs Adds get_web_url() that maps IpcResponse::Error to Ok(None) for backward compat with old supervisors.
src/ipc/mod.rs Adds GetWebUrl request and WebUrl response variants; clean extension of existing IPC enum.
src/supervisor/ipc_handlers.rs Handles GetWebUrl by returning the WEB_URL OnceLock value; follows existing handler pattern correctly.
src/web/mod.rs Adds WEB_URL OnceLock and pub url() accessor; mirrors existing WEB_PORT pattern.
src/web/server.rs Derives URL from actual bound address; correctly handles unspecified IPs as localhost and IPv6 with bracket notation.
src/cli/json_output.rs Adds JsonSupervisorStatus struct with optional web_ui and error fields.
src/supervisor/log_sink.rs Removes unused PendingSink::is_some() helper method.
src/supervisor/mod.rs Removes unused mpsc import from tokio::sync.

Reviews (4): Last reviewed commit: "fix(status): report state file read erro..." | Re-trigger Greptile

Comment thread src/cli/supervisor/status.rs
Comment thread src/web/server.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
docs/cli/supervisor/status.md (1)

8-12: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the JSON fields.

Please mention that the output contains status ("up"/"down") and an optional web_ui URL, ideally with a short example. “Output in JSON format” does not define the machine-readable contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/cli/supervisor/status.md` around lines 8 - 12, Expand the `--json`
section in the Flags documentation to define the JSON contract: include the
required `status` field with `"up"` or `"down"` values and the optional `web_ui`
URL field. Add a concise example showing the expected JSON output.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@docs/cli/supervisor/status.md`:
- Around line 8-12: Expand the `--json` section in the Flags documentation to
define the JSON contract: include the required `status` field with `"up"` or
`"down"` values and the optional `web_ui` URL field. Add a concise example
showing the expected JSON output.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 9009c5c9-925a-48aa-a62b-3130c9e24b0d

📥 Commits

Reviewing files that changed from the base of the PR and between b55b0f4 and 332fc7f.

📒 Files selected for processing (12)
  • docs/cli/commands.json
  • docs/cli/index.md
  • docs/cli/supervisor.md
  • docs/cli/supervisor/status.md
  • pitchfork.usage.kdl
  • src/cli/json_output.rs
  • src/cli/supervisor/status.rs
  • src/ipc/client.rs
  • src/ipc/mod.rs
  • src/supervisor/ipc_handlers.rs
  • src/web/mod.rs
  • src/web/server.rs

@disintegrator
disintegrator force-pushed the supervisor-status-json branch from 332fc7f to 0c5856f Compare July 15, 2026 15:19
@disintegrator
disintegrator marked this pull request as ready for review July 15, 2026 17:40
@disintegrator
disintegrator marked this pull request as draft July 17, 2026 19:43
@github-actions

Copy link
Copy Markdown
Contributor

This PR currently has merge conflicts. If this continues for 7 days, it will be closed automatically.

This is warning day 1 of 7.

Please update the PR when you have a chance. Feel free to reopen or create a new PR if it is closed and you'd like to continue working on it.

This comment was generated by an automated workflow.

@github-actions

Copy link
Copy Markdown
Contributor

This PR currently has merge conflicts. If this continues for 7 days, it will be closed automatically.

This is warning day 2 of 7.

Please update the PR when you have a chance. Feel free to reopen or create a new PR if it is closed and you'd like to continue working on it.

This comment was generated by an automated workflow.

Adds a --json flag to `pitchfork supervisor status` that prints
{"status": "up"|"down"}, including "web_ui": "<url>" when the web
UI server is running.

The URL is queried from the running supervisor over IPC via a new
GetWebUrl request, so it reflects the server's actual bound address
(port bumping, settings changed since supervisor start) rather than
static config. Older supervisors that don't recognize the request are
treated as having no web UI instead of erroring. The non-JSON output
also gains a "Web UI: <url>" line when the web UI is up.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@disintegrator
disintegrator force-pushed the supervisor-status-json branch from 0c5856f to cff301c Compare July 27, 2026 16:30
@disintegrator
disintegrator marked this pull request as ready for review July 27, 2026 16:32
@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cli/supervisor/status.rs`:
- Around line 41-44: Update the status logic around existing_supervisor_pid() so
lookup errors are preserved and reported as “unknown” rather than converted to
“down.” Distinguish an error from a successful absent PID, and only classify a
confirmed missing or non-running PID as “down”; retain the existing
PROCS.is_running(pid) check for valid PIDs.
- Around line 22-23: Update the status flow around ipc.get_web_url() to
distinguish Ok(None) from Err: keep the older-supervisor compatibility result as
“no Web UI,” but propagate or report get_web_url() errors so JSON status
includes the error and human-readable mode exits unsuccessfully. Remove
unwrap_or_default() and preserve the existing Web UI logging for successful
URLs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 054e6dfe-19bb-4640-8307-2a4b631d0eaf

📥 Commits

Reviewing files that changed from the base of the PR and between 0c5856f and cff301c.

📒 Files selected for processing (13)
  • docs/cli/commands.json
  • docs/cli/index.md
  • docs/cli/supervisor.md
  • docs/cli/supervisor/status.md
  • pitchfork.usage.kdl
  • src/cli/json_output.rs
  • src/cli/supervisor/status.rs
  • src/ipc/client.rs
  • src/ipc/mod.rs
  • src/supervisor/ipc_handlers.rs
  • src/supervisor/mod.rs
  • src/web/mod.rs
  • src/web/server.rs
🚧 Files skipped from review as they are similar to previous changes (10)
  • docs/cli/index.md
  • pitchfork.usage.kdl
  • docs/cli/supervisor.md
  • docs/cli/commands.json
  • src/supervisor/ipc_handlers.rs
  • src/ipc/mod.rs
  • src/ipc/client.rs
  • src/web/mod.rs
  • src/cli/json_output.rs
  • docs/cli/supervisor/status.md

Comment thread src/cli/supervisor/status.rs Outdated
Comment thread src/cli/supervisor/status.rs Outdated
disintegrator and others added 3 commits July 27, 2026 23:31
Dead code that failed clippy with -D warnings.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
get_web_url() already maps the older-supervisor compatibility case to
Ok(None); a returned Err is a genuine transport or protocol failure.
Propagate it in human-readable mode so the command exits unsuccessfully,
and report it in the JSON output's error field instead of swallowing it
with unwrap_or_default().

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
existing_supervisor_pid() fails when the state file cannot be read or
parsed; collapsing that error with .ok().flatten() misreported it as a
confirmed-down supervisor. Only a successful lookup finding no PID, or a
PID that is not running, now classifies as "down" — a lookup error is
reported as "unknown" with the failure in the error field.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

This PR currently has failing checks. If this continues for 7 days, it will be closed automatically.

This is warning day 1 of 7.

Please update the PR when you have a chance. Feel free to reopen or create a new PR if it is closed and you'd like to continue working on it.

This comment was generated by an automated workflow.

@jdx
jdx merged commit 7081c67 into jdx:main Jul 28, 2026
12 of 14 checks passed
@jdx jdx mentioned this pull request Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants