feat(headless): add --json flag to output session info on startup#130
feat(headless): add --json flag to output session info on startup#130
Conversation
Add a --json flag to `arf headless` that outputs session connection info (pid, socket_path, r_version, cwd, started_at, log_file) as JSON to stdout when the server is ready. This enables CI scripts and AI agents to programmatically discover the IPC socket path without polling session files. The output includes a `warnings` array that captures non-fatal startup issues (e.g. config parse errors) that would otherwise only appear on stderr and be easily missed in CI environments. --json implies --quiet (suppresses status messages on stderr). Output is pretty-printed when stdout is a TTY, compact when piped. Also refactors `server::start_server()` to return `SessionInfo` instead of just the socket path string. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…less Address roborev review findings: - Clarify doc comment on HeadlessInfo to note that r_version and log_file may be null - Enforce json-implies-quiet within run_headless itself rather than relying solely on the CLI layer Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Verify that --json outputs valid JSON with correct session info (pid, socket_path, cwd, started_at, warnings), that IPC still works, and that status messages are suppressed on stderr. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Address review findings: - Replace fixed 500ms sleep with bounded poll loop for stdout readiness to avoid race under CI load - Add assertions for r_version (should be string) and log_file (should be null without --log-file) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds a machine-readable startup output mode for arf headless so automation can discover IPC connection details without polling session files, and refactors IPC server startup to return richer session metadata.
Changes:
- Add
--jsontoarf headlessto emit session info as JSON on stdout (and imply--quiet). - Refactor IPC
start_server()APIs to returnSessionInfo(instead of only the socket path). - Add an integration test for
--jsonoutput and update shell completion snapshots.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/arf-console/src/cli.rs | Adds --json flag to the headless CLI with help text describing behavior. |
| crates/arf-console/src/main.rs | Implements JSON session-info output in headless mode and collects config-load warnings for JSON mode. |
| crates/arf-console/src/ipc/mod.rs | Changes start_server() to return SessionInfo. |
| crates/arf-console/src/ipc/server.rs | Changes server startup to return SessionInfo and propagate it to callers. |
| crates/arf-console/src/repl/meta_command.rs | Updates :ipc start output to use session.socket_path. |
| crates/arf-console/tests/headless_tests.rs | Treats --json like --quiet for readiness polling and adds a JSON-output integration test. |
| crates/arf-console/src/snapshots/arf__cli__tests__completions_bash.snap | Updates bash completion snapshot to include --json. |
| crates/arf-console/src/snapshots/arf__cli__tests__completions_fish.snap | Updates fish completion snapshot to include --json. |
| crates/arf-console/src/snapshots/arf__cli__tests__completions_powershell.snap | Updates PowerShell completion snapshot to include --json. |
| crates/arf-console/src/snapshots/arf__cli__tests__completions_zsh.snap | Updates zsh completion snapshot to include --json. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Accept null as valid r_version (collection can fail) - Fix comment wording: "In these cases" instead of "In all cases" Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Pass raw quiet flag to run_headless, let the function apply json-implies-quiet once (remove duplication at call site) - Explicitly flush stdout after writing JSON to ensure immediate delivery when piped (non-TTY) - Normalize empty/whitespace-only r_version to null in JSON output Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
--jsonflag toarf headlessthat outputs session connection info as JSON to stdout when the server is readywarningsarray to capture non-fatal startup issues (e.g. config parse errors) that would otherwise only appear on stderr--jsonimplies--quiet(suppresses status messages on stderr); output is pretty-printed on TTY, compact when pipedr_versionis normalized tonullOutput example
{ "pid": 12345, "socket_path": "/tmp/arf-12345.sock", "r_version": "4.4.1", "cwd": "/workspace", "started_at": "2026-03-22T10:00:00+09:00", "log_file": null, "warnings": [] }Other changes
server::start_server()to returnSessionInfoinstead of just the socket path stringTest plan
test_headless_json_output: verifies valid JSON output with all fields, IPC functionality, and stderr suppression🤖 Generated with Claude Code