Skip to content

FE-877: Brownfield promotion — commit the cook result onto cook/<runId>#221

Open
kostandinang wants to merge 1 commit into
ka/fe-876-integration-oraclefrom
ka/fe-877-brownfield-promotion
Open

FE-877: Brownfield promotion — commit the cook result onto cook/<runId>#221
kostandinang wants to merge 1 commit into
ka/fe-876-integration-oraclefrom
ka/fe-877-brownfield-promotion

Conversation

@kostandinang

@kostandinang kostandinang commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Stack Context

Stacks on FE-876 (#220). Seventh Arc-1 frontier -- extends FE-827's greenfield promotion (promote-run.ts) to brownfield, closing the cook-codebase-mode follow-on: a completed brownfield result used to sit uncommitted in the worktree with no path back into the user's checkout.

What?

Commit a completed brownfield cook result onto the repo's own cook/<runId> branch as one reviewable commit.

  • Promotion (promoteBrownfieldRun, promote-run.ts): the brownfield sandbox was created with git worktree add -b cook/<runId> ... HEAD, so the branch already exists at the base. This lands the composed tree on top of it via plumbing -- seed a throwaway index from the base (read-tree), stage the composed tree against an external work-tree (add -A), write-tree -> commit-tree -p <base> -> compare-and-swap update-ref. Reuses promotionSourceDir to compose across slice layouts (shared / per-slice + __epic__ merge, conflicts reported).
  • CLI wiring (runCook, cook-cli.ts): brownfield promotion now runs automatically on a completed run (the old "greenfield-only" block is gone); greenfield stays opt-in via --out.

Why?

git plumbing is the whole point: the user's active branch, working tree, and index are never touched -- only one commit and one ref move. Merging cook/<runId> into the working branch stays the user's call (the orchestrator-arcs guardrail: promotion must not freelance into their branch). Gitignored deps (node_modules/) don't land, because add -A honors the worktree's .gitignore. Unblocks FE-872's deferred brownfield dep-delta capture over the CoW baseline.

Tests

Against throwaway git repos: composed tree lands on cook/<runId> (parent = base, app.ts modified + feature.ts added present, node_modules/ absent) while main/HEAD/working-tree/index stay untouched and no stray branches appear; a missing cook/<runId> branch throws.

Review fixes (this revision)

  • Real linked-worktree test. The original test created cook/<runId> via git branch, not the production git worktree add -b cook/<runId> topology -- exactly where "update-ref a checked-out branch" could fail. Added a test that promotes from the main repo while the branch is checked out in a linked worktree (verified out-of-band that update-ref succeeds there): only the ref moves, main checkout untouched.
  • Tracked-deletion test. Pinned the deletion claim -- a file dropped from the composed tree is removed in the cook commit (the read-tree base + add -A captures deletions, not just adds/mods).
  • Brownfield --out warning. Brownfield auto-promotes, so --out no longer silently no-ops -- it warns that the result lands on cook/<runId>.
  • Dropped a misleading CAS test that couldn't actually interleave the race from outside the function; CAS correctness is visible in the code (parent is update-ref's expected old-value).

Co-authored-by: Amp amp@ampcode.com

@kostandinang kostandinang force-pushed the ka/fe-877-brownfield-promotion branch from 56b7014 to e9a6f5e Compare June 16, 2026 11:23
@kostandinang kostandinang force-pushed the ka/fe-877-brownfield-promotion branch from e9a6f5e to cd5ef22 Compare June 16, 2026 12:49
@kostandinang kostandinang force-pushed the ka/fe-876-integration-oracle branch 2 times, most recently from 4b2ab45 to decc14d Compare June 16, 2026 12:53
@kostandinang kostandinang force-pushed the ka/fe-877-brownfield-promotion branch from cd5ef22 to e7a2007 Compare June 16, 2026 12:53
@kostandinang kostandinang force-pushed the ka/fe-876-integration-oracle branch from decc14d to 92af4c7 Compare June 16, 2026 13:24
@kostandinang kostandinang force-pushed the ka/fe-877-brownfield-promotion branch from e7a2007 to b59e71f Compare June 16, 2026 13:24
@kostandinang kostandinang force-pushed the ka/fe-876-integration-oracle branch from 92af4c7 to 6a7e6c1 Compare June 16, 2026 13:38
@kostandinang kostandinang force-pushed the ka/fe-877-brownfield-promotion branch from b59e71f to 58d7775 Compare June 16, 2026 13:38
@kostandinang kostandinang marked this pull request as ready for review June 16, 2026 14:18
@cursor

cursor Bot commented Jun 16, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Promotion mutates git refs in the user's repo (CAS on cook/<runId> only), but plumbing is designed to avoid touching the active branch or working tree; failures surface as CLI errors with non-zero exit.

Overview
Brownfield cook results now land as a single reviewable commit on cook/<runId> when a run completes successfully, extending FE-827's greenfield promotion story. New promoteBrownfieldRun in promote-run.ts uses read-treeadd -Awrite-treecommit-tree → CAS update-ref with a throwaway index and external work-tree pointed at the composed tree from promotionSourceDir, so only that ref moves—the user's active branch, working tree, and index stay untouched.

CLI (runCook) flips the old greenfield-only --out block: brownfield promotion runs automatically on success; --out is ignored with a warning. Incomplete runs still promote nothing. Greenfield behavior is unchanged (opt-in --out / --force).

Tests cover happy path, missing branch, real linked-worktree topology, and tracked deletions. memory/PLAN.md marks brownfield-promotion landed (FE-877).

Reviewed by Cursor Bugbot for commit 843025d. Bugbot is set up for automated code reviews on this repo. Configure here.

@kostandinang kostandinang force-pushed the ka/fe-877-brownfield-promotion branch from 58d7775 to d8ee639 Compare June 16, 2026 18:05
@kostandinang kostandinang force-pushed the ka/fe-876-integration-oracle branch 2 times, most recently from cae46da to 8b72f34 Compare June 16, 2026 23:45
@kostandinang kostandinang force-pushed the ka/fe-877-brownfield-promotion branch from d8ee639 to a0ebbda Compare June 16, 2026 23:45
@kostandinang kostandinang force-pushed the ka/fe-876-integration-oracle branch from 8b72f34 to eb1c494 Compare June 16, 2026 23:55
@kostandinang kostandinang force-pushed the ka/fe-877-brownfield-promotion branch from a0ebbda to 17ae900 Compare June 16, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant