Public: anyone can read this; the crew can change it.

Re-cut a conflict in a split file mechanically instead of a full agent run (#6140, part 3) #16962

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A pull whose only conflict is in src/http/mcp.ts is now brought up to date by the forge, with no agent run. The new test/split-recut.test.ts (3 tests) passes, along with the conflict, finishing and crew-merge tests I ran. tsc --noEmit and bun scripts/gate.ts --explain are clean.

Notes

opened this

A pull whose only conflict is in src/http/mcp.ts is now brought up to date by the forge, with no agent run. The new test/split-recut.test.ts (3 tests) passes, along with the conflict, finishing and crew-merge tests I ran. tsc --noEmit and bun scripts/gate.ts --explain are clean. I did not run bun test test/mcp-size.test.ts, which the issue asks for, and I did not run the whole suite.

What changed

  • src/actions/split_recut.ts (new) handles the re-cut. It applies when the pull's only conflict is the file main split and the per-entry directory exists on main. It does four things:
    • writes each entry the pull added to the old file as its own file under src/http/mcp/tools/, with its imports re-pointed;
    • adds the entries to index.ts in sorted order, as scripts/mcp-tools.ts would;
    • drops the old file and merges main in, as one commit on the pull's branch;
    • records a finished conflict run saying "re-cut mechanically (no agent run)".
  • Tried first, ahead of any agent run, in sweepConflicts, in the finishing pass (new re-cut mechanically move, counted as queued on the tick line), and in bringUpAfterNoMerge in dispatch.ts.
  • The finished run row is what lets rebasedPulls in finishing_first.ts count the push as a rebase, so finishing_first.ts itself is unchanged.
  • It falls back to the agent run when the pull changed or removed an entry that already existed, edited the old file outside its entries and imports, or added an entry whose file main already has.
  • A re-cut still needs room in the check lane, like any other rebase.
  • The re-cut writes a file's imports from a name match, so a bad one shows up as a red check. A red check goes to the builder through the existing check-failed path. I did not add a separate revert-to-agent step for that.
  • The split table (SPLITS) lists only the MCP split. A future split is one more row.

Tests

  • A pull conflicting only on the old file is re-cut, merges clean afterwards, and has one finished mechanical run that rebasedPulls counts.
  • A pull that also conflicts on another file, and one that changed an existing entry, each still get a queued agent run.
  • An approved pull goes through the finishing pass and is re-cut with no run queued.

Reused: the shape of resolveListConflicts in src/actions/list-conflicts.ts (conflictedTree, commitFiles with seedTree and mergeParents, push event).

Not done: re-cutting a changed existing entry. That would mean applying a patch onto a rewritten file, so it goes to the agent. I did not run bun scripts/similar.ts.

Try it: bun test test/split-recut.test.ts.

No door: this is an internal step of the sweep. The tick line and /flow already show it, and there is no new page, route or MCP tool.

Closes #6155

2 earlier comments
commented

A pull whose only conflict is in src/http/mcp.ts is now brought up to date by the forge, with no agent run. The new test/split-recut.test.ts (3 tests) passes, along with the conflict, finishing and crew-merge tests I ran. tsc --noEmit and bun scripts/gate.ts --explain are clean. I did not run bun test test/mcp-size.test.ts, which the issue asks for, and I did not run the whole suite.

What changed

  • src/actions/split_recut.ts (new) handles the re-cut. It applies when the pull's only conflict is the file main split and the per-entry directory exists on main. It does four things:
    • writes each entry the pull added to the old file as its own file under src/http/mcp/tools/, with its imports re-pointed;
    • adds the entries to index.ts in sorted order, as scripts/mcp-tools.ts would;
    • drops the old file and merges main in, as one commit on the pull's branch;
    • records a finished conflict run saying "re-cut mechanically (no agent run)".
  • Tried first, ahead of any agent run, in sweepConflicts, in the finishing pass (new re-cut mechanically move, counted as queued on the tick line), and in bringUpAfterNoMerge in dispatch.ts.
  • The finished run row is what lets rebasedPulls in finishing_first.ts count the push as a rebase, so finishing_first.ts itself is unchanged.
  • It falls back to the agent run when the pull changed or removed an entry that already existed, edited the old file outside its entries and imports, or added an entry whose file main already has.
  • A re-cut still needs room in the check lane, like any other rebase.
  • The re-cut writes a file's imports from a name match, so a bad one shows up as a red check. A red check goes to the builder through the existing check-failed path. I did not add a separate revert-to-agent step for that.
  • The split table (SPLITS) lists only the MCP split. A future split is one more row.

Tests

  • A pull conflicting only on the old file is re-cut, merges clean afterwards, and has one finished mechanical run that rebasedPulls counts.
  • A pull that also conflicts on another file, and one that changed an existing entry, each still get a queued agent run.
  • An approved pull goes through the finishing pass and is re-cut with no run queued.

Reused: the shape of resolveListConflicts in src/actions/list-conflicts.ts (conflictedTree, commitFiles with seedTree and mergeParents, push event).

Not done: re-cutting a changed existing entry. That would mean applying a patch onto a rewritten file, so it goes to the agent. I did not run bun scripts/similar.ts.

Try it: bun test test/split-recut.test.ts.

No door: this is an internal step of the sweep. The tick line and /flow already show it, and there is no new page, route or MCP tool.

commented

The gate failure was an as never cast in test/split-recut.test.ts. I removed it and pushed.

The cast wasn't needed: the test's file list already matches the commit input type. After the change, tsc --noEmit is clean and the three tests in test/split-recut.test.ts pass. The gate no longer reports the as never rule. I ran the gate and tests before committing, so that was against the working-tree file.

I did not change the similarity notes the gate prints. They are advisory: exportsOf and show in src/actions/split_recut.ts, and put and pullOn in the test. I did not run the full suite.

This is the last commit on the branch, for #6155 (a pull that conflicts only in a split file is re-cut with no agent run).

🤖 Generated with Claude Code

commented

A conflict confined to a split file (src/http/mcp.ts) is now re-cut by the forge as one commit with no agent run, instead of a full run. This revision fixes the missing-imports defect from review.

What changed

  • Imports: entryFile in src/actions/split_recut.ts now takes every import of the head file, not only the ones the pull added. It keeps those whose names the entry body uses and re-points their specifiers with respec. Names that shared.ts exports still come from there when no kept import covers them. A new tool that uses an import the old mcp.ts already had, such as an action helper, no longer loses it.
  • Tests: a new pure test has an entry using a value import and a type-only import (import type { T }) that both sit in the base file. It expects both in the generated file, re-pointed to ../../../actions/a.ts and ../../../core/t.ts. It would fail on the old code, which dropped them. I also removed the old not.toContain("../actions/a.ts") assertion, which asserted the bug. The test now only asserts the re-pointed a import is absent from an entry that doesn't use a.
  • test/mcp-size.test.ts: I ran it with the split-recut test, and all 15 tests pass. tsc --noEmit is clean. The index and file-count rules did not trip on a re-cut.

What I left out

  • The agent-run fallback still happens only before the commit. After a re-cut, the forge's own check is the proof. A red check goes to the builder, who should know the forge wrote those files; no separate note returns the pull to an agent. With the import fix this should be rare.
  • scripts/gate.ts --fix only flagged similar-function notes and one over-long comment line in src/crew/finishing.ts, which this pull doesn't touch. I didn't act on them.

How to try it Run bun test test/split-recut.test.ts test/mcp-size.test.ts.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs