Skip to content

feat(core): add clap CLI with migrate subcommand to agentd-core binary#1132

Open
geoffjay wants to merge 2 commits intoissue-1124from
issue-1125
Open

feat(core): add clap CLI with migrate subcommand to agentd-core binary#1132
geoffjay wants to merge 2 commits intoissue-1124from
issue-1125

Conversation

@geoffjay
Copy link
Copy Markdown
Owner

Restructures main.rs to use clap with serve (default) and migrate status|up|down subcommands. Adds --db-path override for isolated testing, TTY/--yes guard on down, and human-friendly output. Adds clap 4 and atty 0.2 dependencies.

Closes #1125

@geoffjay geoffjay added the review-agent Used to invoke a review by an agent tracking this label label Apr 16, 2026
@geoffjay
Copy link
Copy Markdown
Owner Author

geoffjay commented Apr 16, 2026

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
Copy link
Copy Markdown
Owner Author

@geoffjay geoffjay left a comment

Choose a reason for hiding this comment

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

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.

@geoffjay geoffjay added needs-rework PR has review feedback that must be addressed before merging and removed review-agent Used to invoke a review by an agent tracking this label labels Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rework PR has review feedback that must be addressed before merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant