Read the agent connection ceremony as data with --json
Builds the machine-readable connection ceremony that the "Bring your agents to Basecamp" cards keep waiting on. CLI additions every GUI path needs lists it ("basecamp auth agent connect refuses --json today"), and the one-click Connect on My > Agent (D6) depends on it. The Distribution doc gives the shape: "Emit the verification URL, the code and the expiry as a first line, then the result."
Problem
auth agent connect refuses every machine output mode, because the link, the code and the wait line all go to stdout. Anything that drives the ceremony for a person has to scrape prose to find the link and the code. That covers a Connect button, the agent sandbox's install, or a coding agent relaying the ceremony.
Change
Under --json, stdout carries two JSON values.
- One line, written as soon as Basecamp answers the intake, while the ceremony is still waiting on the person:
{"type":"verification","verification_uri":"https://…/oauth/agent_connection_verification?user_code=WDJB-MJHT","user_code":"WDJB-MJHT","expires_at":"2026-10-06T18:10:00Z","expires_in":600} - The result envelope every command prints:
Or the error, if the person declined, the code expired, or nothing could be stored.{"ok":true,"data":{"profile":"agent","account_id":"999","base_url":"…","source":"agent_connection","oauth_type":"agent","scope":"full","client_id":"bc-agent-42","profile_created":true,"default":true},"summary":"Connected profile \"agent\" to a Basecamp agent"}
Other behavior:
- stderr gets the person's half: the link, the code, the phishing warning and the wait line. The browser opens or doesn't exactly as it would without
--json. - Never on either stream: the client secret or the device code (the poll's bearer). The line carries the validated link (the one the browser would be sent to) and the code with control sequences stripped.
--agentis accepted the same way. It prints the result's data alone, after the same line.- Still refused:
--jq(it filters one envelope, and this writes two values), and--quiet,--ids-onlyand--count, which would throw the verification line away. - Unchanged:
BASECAMP_NONINTERACTIVEstill refuses the ceremony, because approval still needs a person.connect setup's use of the ceremony is untouched.
The ceremony gets an OnIntake hook in auth.AgentConnectOptions. It is called once, after the intake has been validated and before the browser opens, with only the link, the code and the expiry.
Who uses it
- The agent sandbox's install. It runs
basecamp auth agent connect -P agent --software-name agent-sandbox --json, shows the link and code, and reads the result without scraping. - A future one-click Connect. The card's own requirement still applies to whatever launches it: a fixed operation, validated parameters, and no credential ever handed back to the browser.
Tests
TestAuthAgentConnectJSONWritesTheVerificationThenTheResult. The mock server snapshots stdout at the poll, which proves the verification line is out, newline-terminated, before approval. The test also checks the result envelope, that stderr carries the code, and that neither stream carries the secret or the device code.TestAuthAgentConnectJSONOnADeclineWritesOnlyTheVerification: a decline leaves only the verification line, mints nothing and stores nothing.TestAuthAgentConnectRefusesOutputModesThatCannotCarryIt:--jq,--quiet,--ids-onlyand--count. This replaces the old blanket refusal test. It is a regression guard and passes on main too.
The first two fail on main. bin/ci is green on linux.
Summary by cubic
basecamp auth agent connect now reads the connection ceremony as data under --json (or --agent), so a Connect button, the agent sandbox, or a coding agent can drive it without scraping prose.
- stdout carries two JSON values written in order: a verification line (link, user code, expiry) as soon as Basecamp answers the intake, then the result envelope (or error). The operator's half — link, code, warning, wait line — moves to stderr; the browser opens exactly as it would without
--json. - The verification line carries the stripped link the terminal shows, and a single fixed deadline governs the published expiry, the operator's copy, and the poll. A failed write of that line stops the ceremony before anything waits or is stored; a callback that outlives the code ends it as expired.
- Neither stream ever carries the client secret or the device code.
--agentprints the result's data alone after the same verification line;--jq,--quiet,--ids-only, and--countare still refused.BASECAMP_NONINTERACTIVEandconnect setupare unchanged. - The basecamp-connect skill now runs the ceremony with
--jsonand relays the verification line's link, code, and expiry. If an older CLI refuses--json, the skill upgrades it and reruns rather than following the refusal's hint toward a pasted token.auth loginandprofile createstill refuse--jsonand are run plainly.