8000 refactor(adapters): the state directory has one map and one forgiving read by dominikwozniak · Pull Request #93 · dominikwozniak/dw-mc · GitHub
[go: up one dir, main page]

Skip to content

refactor(adapters): the state directory has one map and one forgiving read - #93

Merged
dominikwozniak merged 1 commit into
mainfrom
refactor/86-state-directory-map
Sep 18, 2026
Merged

dominikwozniak merged 1 commit into
mainfrom
refactor/86-state-directory-map

Conversation

@dominikwozniak
Copy link
Copy Markdown
Owner

src/adapters/git.ts derives the clone path, the checkout path, the session branch and the pull ref in two places: once in whereToCut, which cuts a worktree, and once in holding, which is asked before one is taken away. The second copy is not an oversight — whereToCut clones and fetches, and nothing that removes a directory may fetch first, or a machine that is offline is told its work is gone. Naming those four in src/adapters/store.ts keeps that rule and takes the copy away, and it puts them beside the walk that already reads the same layout back off the disk.

What changes

  • src/adapters/store.ts — cloneAt, cutAt, sessionBranch and pullRef are the map, and clonesOf parses it back through the same .git suffix. None of them reaches the network.
  • src/adapters/store.ts — remembered states the state-directory bargain once: a record this version cannot read is forgotten rather than fatal (ADR 0010). The seven reads that each restated it keep only what forgetting costs them.
  • src/adapters/store.ts — weigh and inventory fold a directory's entries the same way over different sets, so the fold is one function; both still walk what they walked, one recursively and one not.
  • src/adapters/git.ts — reads the map instead of joining paths of its own, and drops back under 500 lines.

Test plan

  • pnpm check — pass (51 files, 695 tests)
  • No test assertion changed. That was the contract: this moves code and decides nothing new, so a test needing a different expectation would have meant the move changed behaviour.

Risk

Nothing on disk moves — the same paths, the same branch names, the same refs, the same keys — so a state directory written before this reads the same after it. If a path were wrong, dw-mc fix would cut a second worktree beside the standing one rather than reuse it; src/adapters/git.test.ts and src/cli/uninstall.test.ts drive both sides of the map and are unchanged.

Closes #86

🤖 Generated with Claude Code

… read

`git.ts` derived the clone path, the checkout path, the session branch and the
pull ref twice: once where a worktree is cut and once where one is taken away.
The second copy exists because the first one fetches, and nothing that removes
a directory may fetch first. Naming the four in `store.ts` keeps that rule and
takes the copy away, and it puts them beside the walk that reads the same
layout back off the disk.

The forgiving read of the tool's own records was written seven times, each
under its own paragraph saying the same thing about a cache. `remembered`
states it once, and each record keeps only what forgetting it costs there.

`weigh` and `inventory` fold a directory's entries the same way over different
sets, so the fold is one function and both still walk what they walked.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@dominikwozniak
dominikwozniak merged commit 1eee807 into main Sep 18, 2026
1 check passed
@dominikwozniak
dominikwozniak deleted the refactor/86-state-directory-map branch September 18, 2026 07:04
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.

refactor(adapters): the state directory has one map and one forgiving read

1 participant

0