feat(advisor): auto-detect repo from git remote when --repo omitted#807
Conversation
4fc736c to
b119b19
Compare
…s omitted `actual advisor <query>` now scopes to a connected repository automatically when `--repo` is omitted, instead of always querying at the organization level. It resolves the working tree's `origin` remote, parses its owner and name, and matches that against the organization's connected repositories (GET /v1/connected-repos). - An exact owner/name match scopes the query. When no owner matches but the name is unique, a fork resolves to its connected upstream by name. - The scoped repository (name and short id) is printed to stderr, so stdout stays pipeable for the answer. - Detection is best-effort and non-breaking: no origin remote, no match, an ambiguous match, or a connected-repos lookup failure all fall back to an organization-level query. An explicit `--repo` (name or id) is unchanged and still takes precedence. Per-file line coverage stays at 100%. Generated by the operator's software factory. City: factory-main · Agent: local-core.builder-1 On behalf of: @benw5483 Co-Authored-By: <operator-factory-bot> <factory-bot@<operator-domain>.invalid>
b119b19 to
e3ae442
Compare
backlineint
left a comment
There was a problem hiding this comment.
1. Name-only fork fallback can silently mis-scope to an unrelated repo sharing a name — src/cli/commands/advisor.rs (match_remote_to_repos)
The fallback matches on name alone when the owner doesn't match. The comment frames this as "a fork resolves to its connected upstream," but it fires for any coincidental name collision too: from me/utils (unrelated to anything connected), if the org has a single actual-software/utils connected, the query is silently scoped to actual-software/utils. It's printed to stderr and --repo overrides it, so impact is limited — but the scoping is a guess rather than a guarantee. Consider tightening it (e.g. only fall back to name-only when the host also matches) or sharpening the stderr/doc note so the guess is explicit.
2. (nitpick) Duplicated git remote get-url origin logic — src/cli/commands/advisor.rs (origin_remote_url)
The same bounded-subprocess pattern (piped output, kill_on_drop, timeout) already lives in src/cli/commands/sync/cache.rs (compute_repo_key_with_timeout) and src/cli/commands/sync/pipeline.rs. This is a third copy. Per the repo's own R-MTBI-001 (modular library architecture), a shared origin_remote_url(dir, timeout) helper that both the sync and advisor paths call would be cleaner.
Summary
When
actual advisor <query>runs without--repo, the CLI now auto-detects the connected repository from the working tree'soriginremote and scopes the query to it, so you no longer have to pass--repoby hand inside a connected repo.originremote, parses its owner and name, and matches it against your connected repositories (GET /v1/connected-repos).--repoby name or id is unchanged and still takes precedence.Test plan
cargo test --lib advisorcovers URL parsing, matching (exact, fork, none, ambiguous), the git-remote read, and end-to-end scoping.cargo clippy -- -D warningsis clean.cargo llvm-covreports 100% per-file line coverage on the changed files.actual advisor "..."inside a connected repo and confirm the "scoped to <owner/name>" note; run it outside one and confirm the organization-level fallback.