Skip to content

gh codecrew migrate: the one-shot 1.0 to 2.0 move #256

Closed

Description

@davison

Goal

M13-R2 in full, after the layout (#R1 task) and typed identities (#R4 task) merge — it writes both. Exempt from the pointer check as init is. Hub: pointer plus the recognised contract and extension names out of roles/, anything else left and reported; spoke: pointer plus any roles/.local.md. Rewrites codecrew "2.0", adds a missing coordinator row, types identities by resolving each login's kind through the GitHub users API. Refuses BOTH_LAYOUTS; refuses when roles/ holds an unrecognised entry. Idempotent; one pathspec commit as init makes; never pushes. Protocol 1.0 pointers only. SPEC §6 row, help text, the CHANGELOG's migration steps.

Requirements

M13-R2

Plan

The verb. A new internal/cli/migrate.go holding migrateCmd and a
testable migrate(dir string, w io.Writer, dryRun bool) error; wired in
cli.go beside init — it reads no pointer through loadPointer, so it is
exempt from the protocol check the same way, and it refuses a subdirectory
(repoRoot/sameDir, as init does) and a directory that is not a git
repository (the move is a git mv, so the history follows).

Detection, from config.LegacyLayout(root) and the presence of
.codecrew/config.yml:

1.x layout 2.0 pointer outcome
yes yes refused[BOTH_LAYOUTS], naming both
no yes "already on the 2.0 layout", exit 0, nothing written (idempotent)
no no "not a CodeCrew repo" (a plain error, as config.Load's is)
yes no migrate

A 1.x layout that is roles/ contracts with no .codecrew.yml is a plain
error too: with no pointer nothing says whether the repo is a hub or a
spoke, and migrate does not guess.

What moves. Ten recognised names — the five contracts <role>.md and
their <role>.local.md extensions — git mv'd from roles/ to
.codecrew/roles/, plus .codecrew.yml → .codecrew/config.yml. roles/
is examined only when it holds at least one of the ten: a project's own
roles/ (Ansible's) is never read, which is the collision the layout move
exists to end. When it is CodeCrew's, every entry in it must be one of the
ten or the verb refuses FOREIGN_ROLES_DIR naming the unrecognised entries
and saying to move or remove them first — R2's "refuses when roles/ holds
an unrecognised entry rather than guessing" is the operative rule (Decision
to be recorded). An emptied roles/ is removed (os.Remove, which fails
safely if anything is left).

The pointer rewrite, in place on the moved file: codecrew: "2.0"; a
coordinator: { identity: ~ } row appended when a roles: table exists
without one; each identity value typed — ~/empty and already-typed values
pass through, a value with a slash becomes team:<value>, anything else is
resolved through the GitHub users API (users/<login> → Bot →
app:<login without [bot]>, User → user:<login>; a bare App slug 404s
there, so users/<login>[bot] is probed second). A value that resolves to
neither, or to both, refuses IDENTITY_UNRESOLVED naming it. A
codecrew: that is not major 1 refuses MIGRATION_UNSUPPORTED naming the
version; a missing codecrew: is read as 1.0 with a note, as
config.Compatible already does. The file is edited as a yaml.Node
round-trip so comments survive, with blank lines carried through a sentinel
comment.

The commit. One pathspec commit of exactly the paths moved and written,
on the current branch, never pushed — commitScaffold's machinery extracted
into a shared pathspecCommit (git add -- <new> then git commit --only -- <old> <new>), so the operator's other staged and unstaged work is
untouched. --dry-run prints every step, resolves identities (a read), and
writes nothing.

Refusal codes added: BOTH_LAYOUTS, FOREIGN_ROLES_DIR,
IDENTITY_UNRESOLVED, MIGRATION_UNSUPPORTED — migrate's own family,
distinct from PROTOCOL_MISMATCH (#254, Codex 3 / Claude 3).

Tests (internal/cli/migrate_test.go, temp dirs with git init, the
users API behind an injectable resolver): hub with all ten files → all
moved, pointer rewritten and typed, coordinator row added, roles/ gone,
one commit, other work untouched; hub with four contracts and no extensions
→ moved, nothing invented; roles/ with a foreign entry → refused naming
it, nothing written; a foreign-only roles/ beside a .codecrew.yml → left
alone; both layouts → BOTH_LAYOUTS; spoke → pointer only; already 2.0 →
exit 0 writing nothing; a 0.x pointer → refused; an unresolvable identity →
refused; --dry-run writes nothing; the YAML round-trip keeping comments.

Docs. SPEC §6 gains a migrate row and §10's 2.0 paragraph names the
verb; cli.go's help; docs/introduction.md's refusal list (thirty-five →
thirty-nine, with the README's count); the CHANGELOG's 2.0 entry gains the
migration steps (upgrade the extension, gh codecrew migrate, review the
commit, push and open a PR).

Ask-the-human points

None. The one judgment the task flagged — whether an unrecognised entry in
roles/ is reported or refused — is settled by M13-R2's own text ("refuses
when roles/ holds an unrecognised entry rather than guessing") and is
recorded as a Decision rather than raised as a gate.

Activity

  1. added
    cc:task
    on Sep 6, 2026
  2. radiusred-cody commented on Sep 6, 2026

    @radiusred-cody
    Contributor

    Started by @radiusred-cody[bot].

  3. radiusred-cody commented on Sep 6, 2026

    @radiusred-cody
    Contributor

    Decision: an unrecognised entry in roles/ refuses FOREIGN_ROLES_DIR, and roles/ is read at all only when it already holds one of CodeCrew's own ten names.

    M13-R2 says two things about a hub's roles/ that read differently: "only the recognised contract and extension file names out of roles/, leaving anything else there and reporting it" and "refuses when roles/ holds an unrecognised entry rather than guessing". They describe one posture — migrate moves ten known names and never the directory — but only one of them can be the operative rule at the moment an eleventh name is found. The refusal is it: leaving a stranger behind and printing a line about it makes the operator read output they did not ask for to discover that their tree is now half moved, and it is the half-migration that is expensive, not the extra run.

    The second half of the rule is what keeps that refusal from firing on the repos 2.0 exists for. roles/ is opened only when at least one of the ten names is in it. A project's own roles/ — Ansible's, the collision that motivated the whole layout move — holds none, so it is never read, never moved and never a refusal; migrate does the pointer and leaves the directory exactly where it was. Once one of the ten is in there the directory is CodeCrew's, and then every entry in it must be one of the ten.

    Trade-off: a hub whose roles/ genuinely mixes CodeCrew's contracts with the project's own files cannot be migrated by the verb at all — the operator separates them by hand first. That repository is ambiguous by construction and no rule resolves it without guessing; the refusal names both sets (what it recognises and what it does not) so the separation is a copy-paste rather than an investigation.

    Rejected: ROLES_UNRECOGNISED as the code — it names the input rather than the diagnosis, and the diagnosis is that this directory is not (only) CodeCrew's. FOREIGN_ROLES_DIR is the name the adopted scan finding proposed (#254, Codex 3) and the one the operator's Decision adopted into R2. Also rejected: moving the recognised names and reporting the rest, per the sentence above; and a --force/--only <paths> escape hatch, which is a second way to be wrong about the same directory.

    Decision: the ten recognised names are the same in a hub and in a spoke.

    R2 describes the spoke as "the pointer plus any roles/<role>.local.md", which is what a spoke actually has — init --hub writes it no contracts. Making the recognised set narrower for a spoke would mean a spoke holding a stale roles/qa.md refuses FOREIGN_ROLES_DIR over a file that is unmistakably CodeCrew's own. One set of ten, hub and spoke alike, moves it instead; a spoke that has nothing but the pointer still migrates as R2 describes, because there is nothing else there to move.

  4. radiusred-cody commented on Sep 6, 2026

    @radiusred-cody
    Contributor

    Decision: migrate raises four codes of its own — BOTH_LAYOUTS, FOREIGN_ROLES_DIR, IDENTITY_UNRESOLVED, MIGRATION_UNSUPPORTED — and everything that is not a protocol condition stays a plain error.

    The milestone's Decision on #254 fixed the family ("migrate is conservative and has its own refusal codes, distinct from PROTOCOL_MISMATCH"); these are its members. Each names a condition an orchestrator can branch on, and none of them overlaps a code that already exists:

    • BOTH_LAYOUTS — the repo carries .codecrew/config.yml and a 1.x pointer or contracts; the detail names both sets. Given by R2 verbatim.
    • FOREIGN_ROLES_DIR — above.
    • IDENTITY_UNRESOLVED — a bare routing value could not be typed to exactly one GitHub principal: nothing answers to it, two things do, it is an organization, or the API could not be asked. One code, one meaning — migrate cannot type this row, so you must — with the detail saying which of the four it was. The fix is the same in every case, which is the test for whether a second code would say anything.
    • MIGRATION_UNSUPPORTED — the pointer's protocol major is not 1: 0.x predates the conventions the move assumes, and above 1 is not a 1.x repo whatever the files beside it look like. The detail names the version it read.

    Trade-off: four codes are four permanent promises under SPEC §10 for a verb an adopter runs once. They are worth it because the once is the first contact with 2.0 and every one of these outcomes needs a different human act — separate the layouts, tidy roles/, type a row by hand, do nothing.

    Rejected: PROTOCOL_MISMATCH for the version case — the scans' finding (#254, Claude 3) is precisely that a migration refusal must not share a code with "upgrade the extension". IDENTITY_AMBIGUOUS as a fifth code for the both-answer case — the operator's act is identical to the not-found case (write the typed value), and a code an agent cannot act on differently is a code that says nothing. Codes for the three non-protocol stops — not a git repository, run at the root, contracts with no pointer — which are plain errors: init treats the same two conditions the same way, and none of them is a gate an agent can clear by acting on the code.

  5. radiusred-cody commented on Sep 6, 2026

    @radiusred-cody
    Contributor

    Decision: a bare identity is probed at users/<value> and, when that is a 404, at users/<value>[bot] — and a value both answer to is refused rather than chosen.

    The task's rule is "gh api users/<login> → .type Bot → app:<login without [bot]>, User → user:<login>; a 404 → refuse". Applied literally it refuses on the commonest row there is. A 1.0 table wrote an App as its bare slug — identity: radiusred-cody, matched by strings.TrimSuffix(login, "[bot]") — but a GitHub App's account login is radiusred-cody[bot], so users/radiusred-cody is a 404 and every App-held seat in every 1.0 hub would have refused. This hub's own pre-#276 table is four such rows.

    So the 404 is not the answer, it is the first half of the question: probe the value, and when GitHub has nothing there probe <value>[bot]. The task's own "without [bot]" clause anticipates the suffix; this reads the same rule from the other end. Verified against the live API on a copy of this hub's 1.0 pointer: all four seats typed to app: correctly.

    The second probe also exposes a case the single probe would have got silently wrong. If a human owns the login foo and the App foo[bot] exists, the 1.0 value foo means two things — exactly the ambiguity M13-R4 exists to end — and typing it user:foo because that probe answered first would encode a coin toss in the routing table for good. Both answering is IDENTITY_UNRESOLVED naming both, and the operator writes the one they meant.

    Trade-off: two API calls per bare row instead of one (ten at most, for a five-row table), and a migration cannot be run fully offline. Migrate is a once-per-repo verb whose whole job here is asking GitHub a question nothing local can answer, so the cost is the feature.

    Rejected: guessing from the value's shape — a hyphenated slug looks exactly like a hyphenated username, which is the finding. Trying [bot] first — it would type a real human whose login collides with an App slug as the App. Accepting an Organization as a seat: an org is not a principal that holds a role under SPEC §5, so it refuses with the same code.

    Decision: the pointer is rewritten as a yaml.Node round-trip, with blank lines carried across as a sentinel comment.

    The pointer is a file a human maintains: the scaffold ships it with a paragraph explaining the identity grammar, and hubs add notes of their own (this one's names #212). Re-marshalling a struct would silently delete all of it, so the rewrite edits the parsed node tree in place, which keeps comments, key order and flow-vs-block style. yaml.v3 drops blank lines, though, and in a commented file those carry as much of the shape as the comments do — so each is replaced by a #codecrew-blank-line comment before parsing and turned back after encoding. The added coordinator row takes the style its siblings use, block or flow.

    Trade-off: a round-trip is not byte-preserving. Flow mappings lose their inner padding ({ identity: ~ } → {identity: ~}), a trailing comment can be re-indented under the last key, and indentation is normalised to two spaces. The commit is local and unpushed precisely so the operator reads the diff before it goes anywhere, and the alternative — regex surgery on lines — is fragile across the block, flow, quoted and multi-document shapes a hand-edited pointer can take.

    Rejected: rewriting the pointer from a struct and re-emitting the current scaffold's comment block — it would overwrite the project's own notes with upstream's, in the one file that is most clearly theirs.

  6. radiusred-cody commented on Sep 6, 2026

    @radiusred-cody
    Contributor

    Decision: a destination that already exists is BOTH_LAYOUTS, checked before anything is written, and the filesystem fallback is reached only after proving the source is untracked.

    Checky's finding on PR #280 is right and the bug was real: applyMoves fell back from any git mv failure to os.Rename. The fallback exists for one case only — a 1.x file git does not track, whose path cannot go in the commit's pathspec — but "destination exists" is also a git mv failure, so a repo holding .codecrew/roles/qa.md with no .codecrew/config.yml above it would have had its 2.0 file renamed over and the tracked source's deletion left outside the migration commit. That breaks both of R2's guarantees at once: one pathspec commit, and every refusal before anything is written.

    The fix is two rules rather than one. First, every destination is stat'd before the first move and any that exists refuses. Second, the fallback is guarded by git ls-files --error-unmatch: git refusing to move a file it tracks is the repository's answer to a question migrate asked, and renaming underneath it is never the right response — that failure is returned.

    The code for the preflight is BOTH_LAYOUTS, not a new one. The condition is the same fact the pointer check already catches one level up — this repo carries files from both layouts and migrate will not choose between them — and the operator's act is identical: keep whichever the project uses, remove the other, rerun. A separate code would name a different place, not a different decision, and codes are permanent under SPEC §10.

    Trade-off: BOTH_LAYOUTS now fires for two shapes, so its detail rather than its code says which. That is what the detail is for, and the alternative — DESTINATION_EXISTS beside it — would make an orchestrator branch twice to reach the same instruction.

    Rejected: moving what can be moved and reporting the clash — half a migration is the outcome R2's refuse-first rule exists to prevent. Also rejected: git mv -f, which is the overwrite the finding is about, and dropping the filesystem fallback entirely, which would refuse an uncommitted 1.x scaffold that is otherwise perfectly migratable (there is now a test for that path too).

    Decision: the two LegacyLayout tests get a repository of their own, in this PR.

    Checky's go test ./... failed on TestLoadConfigRefusesTheLegacyLayout and TestLoadRefusesTheLegacyLayout because a stray /tmp/.git on their machine made t.TempDir() an ancestor-having subdirectory, so #255's gitRoot walk judged the layout at /tmp instead. The tests are #255's, but the coordinator's instruction was to take the fix here if it is a temp-dir repository, and it is: internal/cli uses the existing gitRepo(t) helper and internal/config gets a four-line repoDir(t) that makes a .git directory, which is all gitRoot stats for — no subprocess from the config package's tests.

    Reproduced before fixing (TMPDIR set to a directory holding a .git): both tests failed with exactly the reported message, and pass under the same hostile TMPDIR after. The whole suite passes both ways.

  7. 1 remaining item

  8. radiusred-cody commented on Sep 6, 2026

    @radiusred-cody
    Contributor

    Decision: migrate writes .codecrew/AGENTS.md and reports a root entry point that does not reach it — the operator's call, 2026-09-06, adopted into this task.

    I flagged the gap on PR #280 rather than deciding it: a migrated 1.x hub ended up on the 2.0 layout with no 2.0 entry point, its root AGENTS.md still carrying the old instructions and naming roles/ and .codecrew.yml, paths that no longer exist. The operator's answer is that it rides 2.0, because the fleet migration hits it on every hub and a repo whose instructions describe a tree that is gone is not migrated, only moved.

    The scope reading that makes it R2's and not a new requirement: R2 moves a protocol 1.0 repo to the 2.0 layout, and R3 defines what the 2.0 layout's entry point is — .codecrew/AGENTS.md carrying the instructions, the root file a pointer the project owns. A migration that produces every other 2.0 file and not that one has not finished the move it names.

    The shape is init's, deliberately, and shares its code. .codecrew/AGENTS.md is written from the same agentsScaffold when absent, hub and spoke alike, and goes into the migration's own pathspec commit rather than being left for the operator's next one. The two root files go through the same reachesInstructions: one that already arrives asks for nothing, one that does not is named with the exact lines to paste, and the printed payload is entryPointLines verbatim — the same constant the scaffold writes, extracted into a shared entryPointAction so the two verbs cannot drift into printing different lines. --dry-run lists the write and prints the block.

    Trade-off: migrate now writes a file as well as moving files, which widens what a one-shot verb touches. It is bounded to one path that CodeCrew owns and that the repo does not already have — never an overwrite, and never a line the project wrote.

    Rejected: rewriting the root AGENTS.md to the 2.0 pointer scaffold. It would be the cleanest possible migration and it is exactly what #257 decided against for init: the root entry point is the adopter's file, they may have put anything in it, and a verb that rewrites prose is a verb nobody runs twice. Printing the lines is slower and correct. Also rejected: leaving .codecrew/AGENTS.md to a follow-up init run — init refuses nothing here and would work, but it makes the migration a two-command ritual whose second half is easy to skip, and the skip is silent.

    Note on the report's shape: reachesInstructions is false for a root file that is absent as well as for one that arrives nowhere, and the act asked of the operator is the same, so both are named — with (kept) or (absent) after each, since the block cannot honestly call a missing file kept. init's own wording and its Kept: line are untouched, and its test still pins them.

  9. radiusred-cody commented on Sep 6, 2026

    @radiusred-cody
    Contributor

    Decision: a 1.x spoke pointer carrying a roles: block refuses SPOKE_ROUTING before anything is written, rather than being migrated with the block dropped — dropping it would discard routing the operator wrote, and where those rows belong is theirs to say (checky's second-round finding on PR #280; #279's code reused, so the count stays at forty-two).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cc:task

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions