feat(github): connect-repo picks from the repos this caller can reach
Closes #205. Pairs with insta-platform#412 and #416, both deployed to prod.
What changed
insta compute connect-repo <owner/repo> [service] used to find the repo by listing every installation the org holds and then each installation's repositories — an org-scoped view the platform has since made admin-only and caller-scoped (insta-platform#416), because it showed every member every repo a shared installation covers.
It now asks one question: POST /orgs/:orgId/github/repos with an empty body — the repositories this caller's own GitHub account can reach, answered from the identity they already authorized. Same question the connect gate asks again when the source lands, so a repo missing here would be refused there anyway.
When the platform says there is no usable identity, the terminal earns one the way the console does, without a browser callback or a client secret:
$ insta compute connect-repo acme/app web
this terminal is not authorized with GitHub yet — authorize it once:
open https://github.com/login/device and enter the code WDJB-MJHT
waiting for you to confirm… (ctrl-c to abort)
connected acme/app → compute web (nixpacks): building main now — every push to main redeploys it
The prompt goes to stderr, so --json stays one parseable document.
Eight things self-review caught in the first draft
Each is mutation-tested — the listed behaviour goes red when the guard is removed.
- A missing
expiresAtpolled forever.Date.parse(undefined)is NaN, and the loop guard had been written to tolerate that, so every comparison was false and the only exits were a return or a throw. Driving it with a start response lacking the field polled 5000+ times. It now fails loudly, asdeviceGrantinauth.tsalready does for the same field. - An interval Node cannot represent fires in ~1ms.
1e12overflows to a 1ms timer and a negative one is clamped to 1ms — both the hot poll the guard existed to prevent, and neither was caught by a finite-and-positive check. Both ends are clamped now (1s..60s), and a non-positiveintervalis read as absent (RFC 8628's 5s). - A negative
slowDownBydrove the interval down, same 1ms outcome. - The "no identity" test matched any
Errorat any status. A 502 whose prose happened to contain "no longer accepted" would have sent the person through a 15-minute authorize loop that cannot fix it. Gated onApiError400 now. (A machine-readable code from the platform would be better than matching another service's prose — worth doing when something else touches that route.) Number.isFinite(Number(x))acceptednull,'',0andfalseas an installation id, sendinginstallationId: 0to the connect; and the repo id was unvalidated. Both are whole-positive now, with a distinct message, because "listed but unbuildable" and "not in your list" have different remedies.- The prompt went to stdout, so
--jsonemitted three human lines before the document. - A 429 or a dropped link ended the flow. The login flow's identical 5s cadence tripped the platform's per-IP limiter on prod on 2026-09-10; this one backs off instead of aborting an authorization the person may be one click from finishing.
- A confirmed authorization carrying no
reposwas coerced to[], which surfaced as "the App reaches none of your repositories" right after the person authorized. It fails loudly now.
Agent mode
Agent sessions reach the three org-scoped GitHub routes through InsForge/insta-platform#423 (merged 8f9afe1, deployed). On a backend without it they get unclassified_agent_action, and the CLI says so and names what an agent cannot fix — the console, or --public.
One behaviour change worth knowing
An org member running connect-repo now gets "connecting a repository needs the org admin role" instead of the platform's bare forbidden. They could never complete a connect — all three connect doors have always been admin — but the listing they used to get through was member-gated, so the refusal arrives earlier and now says what to do.
Gate
tsc --noEmit clean, 57 files / 869 tests. The lookup's own tests cover: case-insensitive match, unreachable repo, nothing reachable, unusable installation id, unlinked → authorize → use what came back, dead authorization → same, the same words at a different status → real failure, and the member's 403.
Summary by cubic
insta compute connect-repo now finds repos through the caller's own GitHub account instead of listing every org installation, which the platform made admin-only. If there's no GitHub identity yet, it runs a device authorization flow (prints a URL and code, polls until confirmed) and continues with whatever repos come back. Closes #205.
Device flow
- Polls with backoff on rate limits and dropped connections instead of aborting.
- Fails loudly on malformed responses (missing expiry, no repos) rather than looping or coercing to empty.
- Prompt goes to stderr so
--jsonoutput stays a single parseable document. - Runs only where someone can read the code — an interactive terminal or agent mode;
--jsonand bare pipes fail fast instead of waiting.
Behavior change
- Only two 403s get rewritten — members are told connecting needs the org admin role, and agents refused by policy get directed to the console; any other 403 is rethrown as the platform sent it.
- Restores the
repoLine,watchPathsClause, andcomputeWatchPathstest coverage the first pass accidentally deleted.