Add commit split for staged multi-commit plans

Merged
RA
3mo ago
+2128-48

Motivation

No motivation was provided.

What's New

Git Pathspecs

  • listStagedPaths reads staged paths with git diff --staged --name-only -z.
  • performCommit takes optional pathspecs so one staged set can become several commits.
  • Commits run as git -C <worktree-root> so those root-relative paths work when cwd is a subdirectory.

Split Plan

  • The model returns JSON commit groups. The parser rejects empty messages, empty file lists, duplicates, and unknown paths.
  • Leftover staged paths are appended as Commit remaining staged changes.

CLI

  • commit split proposes a plan, then apply, apply and push, edit, move, reorder, regenerate, or cancel.
  • Apply walks the plan and commits each group with pathspecs.

Split Plan Flow

flowchart TB
    A["commit split"] --> B["Staged diff and paths"]
    B --> C["generateSplitPlan"]
    C --> D{"Action"}
    D -->|edit move reorder| D
    D -->|regenerate| C
    D -->|apply| E["performCommit per group"]
    D -->|apply and push| E
    E --> F["push publish or force-with-lease"]
    D -->|cancel| G["exit"]

Changed Files

FileChange TypeSummary
src/infra/git/repo.tsModifiedPathspecs, listStagedPaths, git -C root
src/domain/split/plan.tsAddedParse and validate plan JSON
src/cli/split.tsAddedInteractive apply loop
src/domain/commit/prompts.tsModifiedgetSplitPrompt
src/domain/llm/router.tsModifiedgenerateSplitPlan
src/cli/parser.tsModifiedsplit command
src/domain/alias/alias.tsModifiedAlias target split
index.tsModifiedDispatch split
README.mdModifiedDocument commit split
tests listed aboveAdded/ModifiedPlan, router, CLI apply/cancel, git pathspec

Testing & Feedback

Try commit split on a mixed staged set, including from a subdirectory. Confirm apply leaves the right files in each commit, leftover paths get the remaining-changes commit, and cancel writes nothing.

If you find any bugs or have recommendations for improvements, please open an issue and assign it to me.


[!NOTE]
Cursor Bugbot is generating a summary for commit 59297560a9bcda3fff193548e45801ffd3ce8357. Configure here.