git-session-atomic-commits
Session-scoped git commit orchestrator with hard scope enforcement: commits ONLY files with evidence of belonging to the current agent session and leaves every other dirty worktree change untouched. B
SKILL.mdskills/git-session-atomic-commits/SKILL.md
GitHubSession-Scoped Atomic Commits
The Invariant
Commit exactly the current session's changes — and nothing else.
Any changed file not proven to belong to this session is OUT OF SCOPE and must be left completely untouched (not staged, not committed, not stashed, not reverted). The default classification of every changed file is out of scope until evidence places it in scope. When in doubt, stop and ask — never guess.
Inherited Skills
Load and delegate to these; do not re-implement their rules here:
- git-atomic-commit — atomic partitioning, staging, commit execution, type/scope format
- git-commit-scope-constitution — scope inventory and validation
Phase 0 — Establish the Session Boundary (Evidence, Not Inference)
Collect evidence, in order of reliability:
- Explicit user scope: argument text, stated intent, linked issue/PR or branch.
- Session tool history: files this agent created or edited in THIS session
(its own
create_file/ edit calls, and terminal commands that wrote files). - Session log (when available, e.g.
VSCODE_TARGET_SESSION_LOGin VS Code): file write/edit events recorded for the current session. - Full worktree inventory:
git status --short,git diff --name-only,git diff --cached --name-only, plus untracked files (git status --porcelain).
Then:
- Allowlist = every changed path backed by evidence (1)–(3). Record the evidence for each path.
- Ignore list = every changed path in the inventory (4) that is NOT on the allowlist.
- If any changed path cannot be classified with confidence → STOP and ask the user. Do not proceed on a guess.
Phase 1 — Pre-Flight Inventory and Index Audit
- Run
git status --shortand record the complete change set. - Index audit: run
git diff --cached --name-only. If ANY pre-staged file is not on the allowlist → STOP and ask how to handle it (unstage, commit separately, or exclude). Never commit on top of pre-staged unrelated files. - Untracked trap check: enumerate untracked files explicitly. Never use
git add .,git add -A, orgit add <dir>— these are the primary cause of accidental out-of-scope commits.
Phase 2 — Verify Allowlist Completeness
For each allowlist path, confirm it shows a worktree change (git status / git diff).
If an allowlist path has no change, drop it (nothing to commit) and note it in the report.
If the user expects a change there but git shows none, report it rather than forcing it.
Phase 3 — Constrained Delegation to git-atomic-commit
Pass only the allowlist to git-atomic-commit. State the constraint explicitly:
Scope is limited to these files only: [list]. All other worktree changes are out of scope; do not analyze, stage, or commit them.
git-atomic-commit handles type/scope assignment, grouping, and message generation for the allowlist. This skill retains final responsibility for scope enforcement: if the delegated agent stages anything outside the allowlist, stop and unstage it.
Phase 4 — Pre-Commit Verification Gate (MANDATORY, Blocking)
Before ANY git commit, verify all of the following. Any failure blocks the commit:
- Staged set == allowlist:
git diff --cached --name-onlymatches the allowlist exactly — no more, no fewer. - Zero ignore-list paths staged: intersection of
git diff --cached --name-onlywith the ignore list is empty. - No pre-existing unrelated staged files remain in the index.
- No broad staging was used (
git add .,git add -A,git add <dir>,git commit -a/-am). - Scopes validated via git-commit-scope-constitution.
If any check fails: unstage the offending paths (git restore --staged <path>),
re-verify, and only then proceed.
Phase 5 — Commit and Post-Commit Verification
- Execute commits via git-atomic-commit (interactive or autonomous per its rules).
- After each commit, run
git status --shortand confirm every ignore-list file is still present and unstaged. - Only report completion after the post-commit check passes.
Hard Rules (Non-Negotiable)
- Never stage or commit a file not on the allowlist. Default classification of any changed file is OUT OF SCOPE until evidence says otherwise.
- Never use broad staging:
git add .,git add -A,git add <dir>,git commit -a/-am. - Never commit over pre-staged unrelated files — stop and ask.
- Never stash, checkout, reset, or delete unrelated changes to "clean up" the worktree. Leave them exactly as-is.
- Never guess a file into the session. Insufficient evidence → stop and ask.
- Never amend existing commits unless explicitly requested.
- If the session boundary cannot be established confidently, stop and report. Do not proceed, do not "do your best".
- Scope expansion is explicit: if the user asks to include an ignore-list file, add it to the allowlist with the user's confirmation, then re-run Phase 4.
- Prefer non-destructive git commands at all times.
Output
Return in order:
- Session scope identified, with an evidence summary for each allowlist file.
- Commits created (type/scope/message).
- Files included per commit.
- Unrelated changes intentionally left untouched (the ignore list).
- Any ambiguities and how they were resolved.