Skip to content

feat(advisor): auto-detect repo from git remote when --repo omitted#807

Merged
benw5483 merged 1 commit into
mainfrom
feat/advisor-repo-autodetect
Jul 15, 2026
Merged

feat(advisor): auto-detect repo from git remote when --repo omitted#807
benw5483 merged 1 commit into
mainfrom
feat/advisor-repo-autodetect

Conversation

@benw5483

Copy link
Copy Markdown
Contributor

Summary

When actual advisor <query> runs without --repo, the CLI now auto-detects the connected repository from the working tree's origin remote and scopes the query to it, so you no longer have to pass --repo by hand inside a connected repo.

  • Resolves the origin remote, parses its owner and name, and matches it against your connected repositories (GET /v1/connected-repos).
  • An exact owner/name match scopes the query. A fork whose owner differs still resolves to its connected upstream by name.
  • Prints the scoped repository (name and short id) to stderr, keeping stdout pipeable for the answer.
  • Best-effort and non-breaking. No remote, no match, an ambiguous match, or a lookup failure all fall back to an organization-level query, exactly as before. Passing --repo by name or id is unchanged and still takes precedence.

Test plan

  • cargo test --lib advisor covers URL parsing, matching (exact, fork, none, ambiguous), the git-remote read, and end-to-end scoping.
  • cargo clippy -- -D warnings is clean.
  • cargo llvm-cov reports 100% per-file line coverage on the changed files.
  • Manual: run actual advisor "..." inside a connected repo and confirm the "scoped to <owner/name>" note; run it outside one and confirm the organization-level fallback.

Generated by the operator's software factory.
• City: factory-main · Agent: local-core.builder-1
• On behalf of: @benw5483

@benw5483 benw5483 marked this pull request as ready for review July 13, 2026 21:49
Base automatically changed from feat/advisor-repo-by-name to main July 14, 2026 20:38
@benw5483 benw5483 force-pushed the feat/advisor-repo-autodetect branch from 4fc736c to b119b19 Compare July 14, 2026 20:47
…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>
@benw5483 benw5483 force-pushed the feat/advisor-repo-autodetect branch from b119b19 to e3ae442 Compare July 14, 2026 20:50

@backlineint backlineint left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1. Name-only fork fallback can silently mis-scope to an unrelated repo sharing a namesrc/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 logicsrc/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.

@benw5483 benw5483 added this pull request to the merge queue Jul 15, 2026
Merged via the queue into main with commit 7495c95 Jul 15, 2026
10 of 11 checks passed
@benw5483 benw5483 deleted the feat/advisor-repo-autodetect branch July 15, 2026 14:31
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