Skip to content

feat(headless): add --json flag to output session info on startup#130

Merged
eitsupi merged 6 commits intomainfrom
feat/headless-json-output
Mar 22, 2026
Merged

feat(headless): add --json flag to output session info on startup#130
eitsupi merged 6 commits intomainfrom
feat/headless-json-output

Conversation

@eitsupi
Copy link
Copy Markdown
Owner

@eitsupi eitsupi commented Mar 22, 2026

Summary

  • Add --json flag to arf headless that outputs session connection info as JSON to stdout when the server is ready
  • Enables CI scripts and AI agents to programmatically discover the IPC socket path without polling session files
  • JSON includes a warnings array to capture non-fatal startup issues (e.g. config parse errors) that would otherwise only appear on stderr
  • --json implies --quiet (suppresses status messages on stderr); output is pretty-printed on TTY, compact when piped
  • stdout is explicitly flushed after JSON output to ensure immediate delivery when piped
  • Empty/whitespace-only r_version is normalized to null

Output 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

  • Refactors server::start_server() to return SessionInfo instead of just the socket path string

Test plan

  • Integration test test_headless_json_output: verifies valid JSON output with all fields, IPC functionality, and stderr suppression
  • All existing headless tests pass
  • CLI completion snapshots updated

🤖 Generated with Claude Code

eitsupi and others added 4 commits March 22, 2026 02:54
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]>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 --json to arf headless to emit session info as JSON on stdout (and imply --quiet).
  • Refactor IPC start_server() APIs to return SessionInfo (instead of only the socket path).
  • Add an integration test for --json output 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]>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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]>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@eitsupi eitsupi merged commit e8c52e0 into main Mar 22, 2026
14 checks passed
@eitsupi eitsupi deleted the feat/headless-json-output branch March 22, 2026 03:59
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