Skip to content

Consolidate duplicated git helpers into shared git-context - #867

Merged
selfcontained merged 1 commit into
mainfrom
agt_415cf9dc38c4/job-debt-collector-e16dda35
Aug 2, 2026
Merged

Consolidate duplicated git helpers into shared git-context#867
selfcontained merged 1 commit into
mainfrom
agt_415cf9dc38c4/job-debt-collector-e16dda35

Conversation

@selfcontained

Copy link
Copy Markdown
Owner

What

Consolidates three drifted helper duplications in apps/server/src/shared/ (top backlog item from the 2026-07-21 tech-debt audit):

  • resolveRepoRoot had 3 implementations: the robust worktree-aware one in git-context.ts, plus plain --show-toplevel copies in git/worktree.ts and github/pr.ts that differed only in error class (and pr.ts skipped path normalization). git-context.ts now exports a canonical resolveCheckoutRoot (--show-toplevel semantics, injectable command runner, optional timeout); worktree.ts and pr.ts keep 6-line wrappers that rewrap failures in GitWorktreeError/GitHubPrError with the exact same messages and status codes.
  • resolveCurrentBranch was byte-identical in worktree.ts and pr.ts — now exported once from git-context.ts, and probeGitContext reuses it too.
  • normalizePath existed in git-context.ts (with a root-path guard) and worktree.ts (without) — the guarded version is now exported and shared.
  • CommandRunner — the identical injectable-runner type was declared locally in 5 files (worktree.ts, pr.ts, base-ref.ts, agent-diff.ts, diff-stats.ts); it now lives once in shared/lib/run-command.ts next to RunCommandResult.

Net −35 lines. No git command lines, options, error messages, or status codes changed; the only observable delta is that pr.ts's repo root is now trailing-slash-normalized like every other caller (a no-op for real --show-toplevel output).

Why it's tech debt

Three copies of the same git plumbing had already drifted (different error classes, inconsistent normalization) and sat directly on the worktree-creation path, where the #794 concurrency fix showed how sensitive this code is to subtle divergence.

Validation

  • pnpm run check
  • pnpm run test — 2390 server / 541 web / 60 misc ✅
  • pnpm run test:e2e — 175 passed, 12 skipped ✅

Queued next

Top of the tech-debt backlog: deduplicating the ~90-line AgentTypeCombobox/AgentTypeSelect pair in the web app.

🤖 Generated with Claude Code

resolveRepoRoot (--show-toplevel flavor), resolveCurrentBranch, and
normalizePath each had drifted copies across worktree.ts, github/pr.ts,
and git-context.ts. git-context.ts now owns the canonical helpers
(resolveCheckoutRoot, resolveCurrentBranch, exported normalizePath);
worktree.ts and pr.ts keep thin wrappers that rewrap failures in their
own error classes with the exact same messages and status codes. The
identical CommandRunner type declared in five files now lives once in
shared/lib/run-command.ts.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@selfcontained
selfcontained merged commit c4759d8 into mainAug 2, 2026
1 check passed
@selfcontained
selfcontained deleted the agt_415cf9dc38c4/job-debt-collector-e16dda35 branch August 2, 2026 09:16
Sign up for freeto 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

@selfcontained