Repository navigation
feat(doctor): airc doctor --connect pre-flight check (closes #80) - #87
Conversation
Adds a third doctor mode beyond the existing health-check default and
--tests integration-suite mode. Use case:
airc doctor --connect && airc connect
Eliminates the silent-fail classes that produced #78 / #85 / #79
cascades for first-time users by surfacing them before pair attempt
rather than during.
Default health probes (git/gh/openssl/ssh/python3 + gh-auth) PLUS
connect-specific checks:
- github gists API reachable (catches network outages + token issues
that would silently break gist substrate)
- tailscale UP (not just installed) when the cached host_target is in
tailnet CGNAT range — handles Memento's exact failure mode (#78)
but at a different point in the workflow
- AIRC_PORT free or auto-shift available (info-only, since airc
handles port collision gracefully)
- Cached host_target reachable + ssh-auth works (resume scenario;
catches stale-pairing + dead-host cases before the user notices
silent queue / dead-monitor cascade)
Each probe outputs [ok] / [BLOCKED] / [info] with a fix command;
exits non-zero on any BLOCKED so the call site can chain with &&.
Bash + ps1 in lockstep per the no-neglect-Windows rule. The ps1 mode
mirrors structure exactly; both share the same probe set.
Verified locally on this Mac: doctor --connect returns READY when env
is healthy, prints fix commands when not.
133/133 integration tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds a new airc doctor --connect mode (bash + PowerShell) that runs connect-specific preflight checks so first-time (and resume-path) failures surface before attempting airc connect.
Changes:
- Extend
doctorto support a new--connectmode alongside--testsand default environment health checks. - Implement connect preflight probes: GitHub API reachability via
gh, Tailscale UP gating when cachedhost_targetis CGNAT, port availability, and cached host SSH reachability. - Update PowerShell dispatch to pass through
doctorsub-args.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
airc |
Adds cmd_doctor --connect routing and implements _doctor_connect_preflight probes. |
airc.ps1 |
Adds Invoke-DoctorConnectPreflight and routes airc doctor --connect via Invoke-Doctor -Argv. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # ── Connect-specific: gist API reachable ── | ||
| if command -v gh >/dev/null 2>&1; then | ||
| if gh api user >/dev/null 2>&1; then | ||
| printf " [ok] github gists API reachable\n" | ||
| else | ||
| printf " [BLOCKED] github gists API not reachable -- network or token issue\n" | ||
| printf " Fix: check internet, then re-run 'gh auth login -s gist'\n" | ||
| issues=$((issues+1)) |
There was a problem hiding this comment.
The “github gists API reachable” probe uses gh api user, which can succeed even when gist write access is missing (and also overlaps with the prior gh auth status probe). This means doctor --connect may still report READY while gist creation/deletion later fails, and it may double-count the same root cause as multiple issues. Consider checking for the gist scope explicitly (e.g., parse gh auth status scopes output) and/or probe an endpoint/operation that requires gist scope, and skip/avoid counting this probe when gh is missing or already unauthenticated.
| # ── Connect-specific: gist API reachable ── | |
| if command -v gh >/dev/null 2>&1; then | |
| if gh api user >/dev/null 2>&1; then | |
| printf " [ok] github gists API reachable\n" | |
| else | |
| printf " [BLOCKED] github gists API not reachable -- network or token issue\n" | |
| printf " Fix: check internet, then re-run 'gh auth login -s gist'\n" | |
| issues=$((issues+1)) | |
| # ── Connect-specific: gist access available ── | |
| if command -v gh >/dev/null 2>&1; then | |
| local gh_auth_status="" | |
| if gh_auth_status=$(gh auth status 2>&1); then | |
| case "$gh_auth_status" in | |
| *"Token scopes:"*"gist"*|*"scopes:"*"gist"*) | |
| printf " [ok] github gist scope available\n" | |
| ;; | |
| *) | |
| printf " [BLOCKED] github gist scope missing\n" | |
| printf " Fix: re-run 'gh auth login -s gist'\n" | |
| issues=$((issues+1)) | |
| ;; | |
| esac | |
| else | |
| printf " [info] github gist scope check skipped -- gh auth already failing\n" |
| Probe 'gh (GitHub CLI)' { | ||
| Get-Command gh -ErrorAction SilentlyContinue | ||
| } 'winget install --id GitHub.cli (then: gh auth login -s gist)' | ||
| Probe 'gh authenticated (gist scope)' { | ||
| if (-not (Get-Command gh -ErrorAction SilentlyContinue)) { return $false } | ||
| & gh auth status 2>$null | Out-Null | ||
| $LASTEXITCODE -eq 0 | ||
| } 'gh auth login -s gist' | ||
| Probe 'ssh (OpenSSH client)' { | ||
| Get-Command ssh -ErrorAction SilentlyContinue | ||
| } 'Settings -> Apps -> Optional Features -> Add -> OpenSSH Client' | ||
| Probe 'ssh-keygen' { | ||
| Get-Command ssh-keygen -ErrorAction SilentlyContinue | ||
| } 'Comes with OpenSSH Client (see above)' | ||
| Probe 'openssl' { | ||
| $null -ne $script:OpenSSLBin | ||
| } 'winget install --id Git.Git (Git for Windows bundles openssl)' | ||
|
|
||
| # Connect-specific: github gists API reachable | ||
| Probe 'github gists API reachable' { | ||
| if (-not (Get-Command gh -ErrorAction SilentlyContinue)) { return $false } | ||
| & gh api user 2>$null | Out-Null | ||
| $LASTEXITCODE -eq 0 | ||
| } 'check internet, then re-run gh auth login -s gist' |
There was a problem hiding this comment.
In doctor --connect, the gh-related probes will over-count and may give a false sense of coverage: gh auth status doesn’t verify gist scope, and gh api user doesn’t actually exercise the gists API (it can succeed without gist permission). Also, because these are implemented as independent Probe calls, a missing/unauthenticated gh can be counted 2–3 times. Consider (1) short-circuiting downstream gh probes when gh is missing/unauthenticated, and (2) validating gist scope explicitly (e.g., parse gh auth status for scopes) or probing an endpoint/operation that requires gist scope.
#87) Two issues Copilot caught on PR #87: 1. **Over-counting**: when gh is missing/unauthed, the cascade of probes (gh installed, gh auth, gh gist API) each counted as a separate issue, producing inflated 'BLOCKED on 3 issues' messages that all share one root cause. 2. **Gist scope wasn't actually verified**: `gh auth status` passes for a gist-scope-less token, and `gh api user` doesn't exercise the gists endpoint. Result: doctor --connect could report READY while gist creation/deletion later silently fails. Fix: single chain (installed -> authed -> gist scope present -> gists API reachable), early-return on first failure with the most specific fix command. Each step's failure counts as exactly one issue with exactly the right diagnosis. Both bash and PS1 use the same chain shape for parity. Gist-scope check parses `gh auth status` output for "Token scopes: ... gist ..." (works on both 2.x output styles). Gists-API reach uses `gh api 'gists?per_page=1'` -- minimal endpoint that actually exercises the gist permission, no side effects. 133/133 integration tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Closes #80. Adds
airc doctor --connectpre-flight mode. Use case:Surfaces the silent-fail classes that produced #78 / #85 / #79 cascades for first-time users BEFORE the pair attempt instead of during. Each probe is [ok] / [BLOCKED] / [info] with a fix command; exit non-zero if any BLOCKED.
What's checked
Default health probes plus connect-specific:
Bash + PS1 lockstep
Per Joel's no-neglect-Windows rule. Both languages have the same probe set in their own idiom.
Test plan
airc doctor --connectreturns READY in healthy env, prints fix commands otherwiseRelated issues
Closes #80. Complements landed #84 (resume + fresh-pair tailscale gate) + #86 (gh-bin winget fallback). Together these three eliminate the silent-fail classes at install/connect time.
🤖 Generated with Claude Code