feat(core): add clap CLI with migrate subcommand to agentd-core binary#1132
feat(core): add clap CLI with migrate subcommand to agentd-core binary#1132geoffjay wants to merge 2 commits intoissue-1124from
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
Restructures main.rs to use clap with two top-level subcommands: - serve (default when no args given) — starts the HTTP server - migrate status / up / down [--all] [--yes] [--db-path <path>] The --db-path flag lets tests point the binary at an isolated temp database without relying on AGENTD_ENV side effects. migrate down requires --yes or interactive TTY confirmation; exits non-zero with a clear error when stdin is not a TTY and --yes is absent. Adds clap 4 (derive) and atty 0.2 dependencies. Closes #1125
geoffjay
left a comment
There was a problem hiding this comment.
Review: feat(core): add clap CLI with migrate subcommand to agentd-core binary
Two blocking issues before this can merge. The overall structure and logic are solid — the subcommand design, TTY guard, output strings, and --db-path override are all correct and well-implemented. Cannot self-approve/request-changes; marking needs-rework via label.
Blocking: replace atty with std::io::IsTerminal
atty = "0.2" carries RUSTSEC-2021-0145 (soundness advisory — unsound use of from_raw_fd). It is also unmaintained. More importantly, the project already uses the stdlib alternative: crates/cli/src/picker.rs imports std::io::IsTerminal. Adding a known-unsound crate when the codebase already has the correct pattern is not acceptable.
Fix — remove atty from Cargo.toml entirely, then in run_migrate_down:
// Before
let is_tty = atty::is(atty::Stream::Stdin);
// After
use std::io::IsTerminal;
let is_tty = std::io::stdin().is_terminal();No other changes needed — the call-site logic is correct as written.
Blocking: use the workspace clap instead of a local version spec
The workspace already declares clap = { version = "4.5", features = ["derive"] } in [workspace.dependencies]. This PR adds its own clap = { version = "4", features = ["derive"] } — a different version spec that bypasses the workspace pin.
Fix in crates/core/Cargo.toml:
# Before
clap = { version = "4", features = ["derive"] }
# After
clap = { workspace = true }The workspace entry already includes the derive feature, so no local feature declaration is needed.
Non-blocking: init_tracing() runs for all subcommands
agentd_common::server::init_tracing() is called unconditionally in main before dispatch. For migrate status/up/down this initialises the full tracing stack when the user likely only wants clean line-oriented output. Won't cause bugs (tracing goes to stderr; integration test stdout assertions still pass), but it's slightly heavy for a CLI utility path. Consider moving the call inside run_serve() only. Non-blocking, can be a follow-up.
Stack note
This branch (issue-1125) is stacked on PR #1131 (issue-1124), which is LGTM and can merge first. The integration tests in #1133 depend on this PR's CLI shape (subcommand names, --db-path flag, output strings) — those all remain correct and will not need changes once the two blocking issues above are fixed.
Restructures
main.rsto use clap withserve(default) andmigrate status|up|downsubcommands. Adds--db-pathoverride for isolated testing, TTY/--yesguard ondown, and human-friendly output. Addsclap 4andatty 0.2dependencies.Closes #1125