feat(cli): complete the link → checkout agent flow in JSON - #427
Open
philip wants to merge 1 commit into
Open
Conversation
Let an agent complete the link → checkout flow in structured JSON. link --agent now returns needs_branch instead of a false terminal "linked" when no branch is pinned, and checkout --agent pins a branch, pulls env, and reports checked_out with an env_pull status. Includes tests. Co-authored-by: Isaac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Lets an AI agent walk from a linked project to a working
DATABASE_URLentirely instructured JSON, without a human in the loop or any prose to parse.
Two changes:
checkoutgains an--agentmode: a JSON state machine that resolves the project,then either returns
needs_branch(listing the real branches to choose from, plus anext_command_templateto retry) or pins the branch, pulls its env, and returnschecked_out. It never guesses a branch and never silently creates one.link --agentno longer reportsstatus: "linked"when a project is linked but nobranch is pinned. That was a false terminal state: there's no branch and no env yet.
It now returns
needs_branchpointing atcheckout --agent, so an agent continues theflow instead of stopping one step short of a usable database.
The two commands share one response contract (
needs_branch+next_command_template),so an agent sees a consistent shape across the whole flow. The interactive paths are
untouched; agent mode is an early return.
Note for reviewers: exit code on a failed env pull
checkout --agentpins a branch (local, always succeeds) then pulls its env (remote, canfail). On a failed pull it reports
status: "checked_out",env_pull: "failed", andexits 0, since the pin genuinely succeeded and the failure lives in the
env_pullfield.The risk: an agent that checks the exit code or
status(both say "success") could missit and fail a later step with no
DATABASE_URL; onlyenv_pullflags it. We chose exit 0for consistency, since every path that pulls env (
checkout,link,config apply)treats a failed pull as a warning, not a command failure. If you'd prefer agent mode to
exit non-zero here, it's a one-line change isolated to the agent path, pinned either way
by an e2e test.
Testing
Unit suites cover the response shapes for both commands. A live e2e
(
checkout.e2e.test.ts) provisions a real project and verifies both the successful pull(connection string written to disk) and the failed pull (branch still pinned, exit 0).
This pull request and its description were written by Isaac.