[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6MQWWM5P7FVQSF7EWHJ70C6":3,"skill-same:01M6MQWWM5P7FVQSF7EWHJ70C6":78},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":40,"linkOnly":41,"markdownContent":42,"markdownBody":43,"frontMatter":44,"refName":47,"commitSha":48,"skillDirectory":49,"forksCount":50,"repositoryHtmlUrl":51,"repositoryHomepageUrl":6,"ownerHtmlUrl":52,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":53,"install":54,"resources":67},"01M6MQWWM5P7FVQSF7EWHJ70C6","stack-plan",null,"Use when you need to plan commits, restructure a stack, or commit uncommitted work as organized atomic commits. Builds a stack from a description, uncommitted work, or existing commits INSTEAD of dumping everything into one monolithic commit with git add -A && git commit, or manual git rebase -i, git reset --soft, or ad-hoc git move sequences. Prevents: wrong commit ordering, forward references, git move -F panics, untested intermediates.","higherorderfunctor\u002Fnix-agentic-tools","higherorderfunctor","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F34926636?v=4","01M6MQT3TQS16N1CBRZJYR2EMB","Christopher Aubut","01M6MQT419AF9ERC87M87NRXQV",2,"Unlicense","https:\u002F\u002Fgithub.com\u002Fhigherorderfunctor\u002Fnix-agentic-tools\u002Fblob\u002Fmain\u002Fpackages\u002Fstacked-workflows\u002Fskills\u002Fstack-plan\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39],"stack plan","plan","stack","as","when","Existing","for","tree","manual","you","with","move","false","commit","reset","references","use","git move","atomic commits","commits","git commit","2026-11-10 10:12:30",false,"---\nname: stack-plan\ndescription: >-\n  Use when you need to plan commits, restructure a stack, or commit uncommitted\n  work as organized atomic commits. Builds a stack from a description,\n  uncommitted work, or existing commits INSTEAD of dumping everything into one\n  monolithic commit with git add -A && git commit, or manual git rebase -i, git\n  reset --soft, or ad-hoc git move sequences. Prevents: wrong commit ordering,\n  forward references, git move -F panics, untested intermediates.\nargument-hint: \"\u003Cplan | range | (none for working tree)>\"\ndisable-model-invocation: false\ncompatibility: \"Requires git-branchless\"\n---\n\nPlan and execute a commit stack. Determines mode automatically based on input:\n\n- **From a plan\u002Fdescription** — user describes what needs to be built; skill\n  produces the commit ordering and executes it\n- **From uncommitted work** — working tree has changes; skill classifies and\n  commits them as an atomic stack\n- **From existing commits** — range like `main..HEAD`; skill restructures into a\n  clean atomic stack\n\n## Pre-flight\n\n1. **Load references** — read `references\u002Fphilosophy.md` and\n   `references\u002Fgit-branchless.md` (relative to this skill's directory) before\n   proceeding.\n\n2. **Confirm repository initialization.** A devenv project with\n   `git.branchless.enable` runs `git branchless init` on every shell entry.\n   Anywhere else, check and stop if it is missing:\n\n   ```bash\n   git config --get branchless.core.mainBranch >\u002Fdev\u002Fnull ||\n     echo \"not initialized: ask the user to run git branchless init\"\n   ```\n\n   Do not run `git branchless init` yourself: it rewrites the repository's\n   shared configuration and hooks for every worktree.\n\n3. **Check for stale rebase state**:\n\n   ```bash\n   ls -d \"$(git rev-parse --git-path rebase-merge)\" \\\n     \"$(git rev-parse --git-path rebase-apply)\" 2>\u002Fdev\u002Fnull\n   ```\n\n   If either exists, run `git rebase --abort` before proceeding. In a linked\n   worktree `.git` is a file, so ask Git for the paths.\n\n4. **Select this worktree's own stack** as `$STACK`, and use it wherever this\n   skill needs the stack or its base:\n\n   ```bash\n   main_branch=\"$(git config branchless.core.mainBranch || echo main)\"\n   remote=\"$(git config \"branch.${main_branch}.remote\" || echo origin)\"\n   base=\"$(git rev-parse --abbrev-ref \"${main_branch}@{upstream}\" 2>\u002Fdev\u002Fnull \\\n     || echo \"${remote}\u002F${main_branch}\")\"\n   git rev-parse --verify -q \"${base}^{commit}\" >\u002Fdev\u002Fnull || base=\"$main_branch\"\n   STACK=\"descendants(roots((stack() & ::HEAD) - ::$base)) - ::$base\"\n   ```\n\n   `$base` is main's upstream ref (the last fetched one), or local `main` when\n   there is none. Plain `stack()` is not your stack while local `main` is behind\n   its upstream, the normal state when worktrees branch from `origin\u002Fmain`: it\n   also holds the upstream commits and every stack another worktree branched\n   from them. See **Selecting your own stack** in\n   `references\u002Fgit-branchless.md`.\n\n## Determine Mode\n\nExamine `$ARGUMENTS` and repo state to select the mode:\n\n- If `$ARGUMENTS` contains `--tip-only` or requests tip-only redistribution →\n  **Restructure mode (tip-only redistribution)**\n- If `$ARGUMENTS` contains `--root` or requests a from-root restructure →\n  **Restructure mode (from-root)**\n- If `$ARGUMENTS` looks like a commit range (`main..HEAD`, `hash1..hash2`,\n  branch name) → **Restructure mode**\n- If `$ARGUMENTS` is a natural-language description of work to do → **Plan\n  mode**\n- If `$ARGUMENTS` is empty and the working tree has uncommitted changes →\n  **Working tree mode**\n- If `$ARGUMENTS` is empty and the working tree is clean → ask the user what\n  they want to do\n\n## Plan Mode\n\nThe user describes work to be done. Build the stack from scratch.\n\n1. **Understand the task** from `$ARGUMENTS`. If the description is vague, ask\n   clarifying questions.\n\n2. **Design the commit stack** following the ordering in\n   `references\u002Fphilosophy.md`:\n   1. Refactoring \u002F cleanup (separate from feature work, always first)\n   2. Dependencies \u002F build config changes\n   3. Scaffolding \u002F types \u002F interfaces \u002F schemas\n   4. Core business logic\n   5. Edge cases \u002F error handling\n   6. Tests\n\n   For each commit, note:\n   - One-sentence commit message (Conventional Commits format)\n   - Which files will be created or modified\n   - Estimated line count (target 50-200 per commit)\n   - Dependencies on prior commits (no forward references)\n\n3. **Verify no forward references**: each commit must only reference files,\n   imports, and config that exist in it or earlier commits. Documentation goes\n   WITH the feature it documents. Dependencies arrive in the commit that first\n   uses them.\n\n4. **Present the plan** to the user:\n\n   ```\n   Proposed stack (N commits):\n\n   1. type(scope): description — files X, Y (~80 lines)\n   2. type(scope): description — files A, B (~120 lines)\n   3. type(scope): description — files C, D, E (~150 lines)\n   ...\n   ```\n\n   **Wait for user approval.** Adjust if they have feedback.\n\n5. **Execute the plan** — implement each commit in order:\n\n   ```bash\n   # Write the code for commit 1\n   git add \u003Cfiles>\n   git commit -m \"type(scope): description\"\n\n   # Write the code for commit 2\n   git add \u003Cfiles>\n   git commit -m \"type(scope): description\"\n   ```\n\n   After each commit, verify the codebase is in a working state.\n\n## Working Tree Mode\n\nUncommitted changes exist. Classify and commit them as a stack.\n\n1. **Survey the changes**:\n\n   ```bash\n   git status --short\n   git diff --stat\n   git diff\n   ```\n\n   Read the full diff. Count total lines changed.\n\n2. **Classify every change** into logical groups following the ordering in\n   `references\u002Fphilosophy.md`. For each group, note:\n   - Which files and hunks belong to it\n   - A one-sentence commit message\n   - Estimated line count (target 50-200 per commit)\n\n   If a file has changes spanning multiple groups, it will need `git add -p` to\n   split hunks across commits.\n\n3. **Present the plan** to the user (same format as Plan mode step 4). **Wait\n   for user approval.**\n\n4. **Commit each group** in plan order:\n\n   ```bash\n   # For file-level grouping:\n   git add \u003Cfile1> \u003Cfile2>\n   git commit -m \"type(scope): description\"\n\n   # For hunk-level splitting within a file:\n   git add -p \u003Cfile>\n   git commit -m \"type(scope): description\"\n   ```\n\n   After each commit, verify nothing was missed or double-counted:\n\n   ```bash\n   git diff --stat   # remaining uncommitted changes\n   ```\n\n## Restructure Mode\n\nExisting commits need to be reorganized into a clean atomic stack.\n\n1. **Parse the range** from `$ARGUMENTS`. Resolve to a `\u003Cbase>` and `\u003Ctip>`:\n\n   ```bash\n   # For range syntax (base..tip):\n   BASE=\u003Cresolved base>\n   TIP=\u003Cresolved tip>\n\n   # For a branch name, find the merge-base with the upstream, not local main:\n   BASE=$(git merge-base \"$base\" \u003Cbranch>)\n   TIP=\u003Cbranch>\n\n   # For --root (entire history):\n   BASE=\u003Cempty tree>\n   TIP=HEAD\n   ```\n\n2. **Understand the current state**:\n\n   ```bash\n   git sl\n   git log --oneline --reverse $BASE..$TIP   # or --root for from-root\n   git log --reverse --stat --format=\"=== %h %s ===\" $BASE..$TIP\n   git diff --stat $BASE..$TIP\n\n   # From-root (no base commit):\n   git log --oneline --reverse --root\n   git log --reverse --stat --format=\"=== %h %s ===\" --root\n   git diff --stat $(git hash-object -t tree \u002Fdev\u002Fnull) HEAD\n   ```\n\n   Read the full diff and per-commit stats. Count total lines changed.\n\n   A range written against local `main` (`main..HEAD`) also holds the upstream\n   commits while `main` is stale, and using the upstream tip itself as the base\n   stages upstream-only commits as deletions. For this worktree's stack, use\n   `$(git merge-base \"$base\" HEAD)..HEAD`.\n\n3. **Classify every change** into logical groups (same as Working Tree mode step\n   2).\n\n4. **Identify files with intermediate states**: before planning the commit\n   sequence, list every file that will have DIFFERENT content across multiple\n   commits (e.g. README.md, CLAUDE.md, flake.nix growing incrementally). For\n   each, write out EXACTLY what content it should have at each commit boundary.\n   Plan ALL intermediate states BEFORE flattening — discovering them as you go\n   leads to fixups and tree hash mismatches. This is the #1 source of rework\n   during restructure.\n\n5. **Present the plan** (same format as Plan mode step 4). **Wait for user\n   approval.**\n\n6. **Check for uncommitted work** before flattening:\n\n   ```bash\n   git status --short\n   ```\n\n   If there are uncommitted changes, warn the user and ask whether to stash or\n   commit them first.\n\n7. **Confirm the recovery point.** Record the current commit ID in the task\n   report. Do not create or delete a generic repository-global backup branch; it\n   may belong to another worktree or session.\n\n8. **Save the tree hash** for post-verification:\n\n   ```bash\n   FINAL_TREE=$(git rev-parse HEAD^{tree})\n   ```\n\n9. **Extract intermediate file states** before flattening. For every file\n   identified in step 4 as having multiple states, save each version to a temp\n   directory using `git show`. After flattening, the working tree only contains\n   the final state — earlier versions are gone.\n\n   ```bash\n   STATES_DIR=$(mktemp -d \u002Ftmp\u002Frestructure-states.XXXXXX)\n   # For each (file, commit) pair from step 4:\n   git show \"${HASH}\":path\u002Fto\u002Ffile > \"${STATES_DIR}\u002Ffilename.${HASH}\"\n   ```\n\n   Include stub files (placeholder modules, `.gitkeep` files) that scaffold\n   commits create before later commits replace them with real content. Restore\n   these with `cp` or `touch` before staging each intermediate commit.\n\n10. **Flatten the range** into the working tree:\n\n```bash\n# Standard range (has a base commit):\ngit reset --soft $BASE\ngit restore --staged .\n\n# From-root (no base commit):\ngit checkout --orphan restructure-wip\ngit reset\n# Note: git-branchless hook will panic on orphan branches — this is\n# harmless. The checkout succeeds. Suppress noise with:\n#   2>&1 | grep -v \"^branchless:\"\n```\n\nVerify the working tree matches the original diff:\n\n```bash\n# Standard range (files are unstaged):\ngit diff --stat   # should match step 2's total diff\n\n# From-root (all files are untracked after orphan+reset):\ngit status --short | wc -l   # should match step 2's file count\n```\n\n11. **Commit each group** in plan order (same as Working Tree mode step 4). For\n    files with intermediate states (identified in step 4), restore the correct\n    version from `$STATES_DIR` BEFORE staging for each commit. Do not rely on\n    the final working tree content — it represents the end state, not\n    intermediate states.\n\n    After staging each commit, check for common mistakes:\n    - **Orphaned deletions**: when staging renamed\u002Fmoved files, the old paths\n      remain as unstaged deletions. Check `git status` and stage them in the\n      same commit.\n    - **`git add -u` during multi-commit rebuild**: stages ALL modified tracked\n      files, not just the ones for this commit. Always use explicit\n      `git add \u003Cfile>` paths.\n    - **Verify staged content**: run `git diff --cached --stat` to confirm only\n      intended files are staged.\n\n### Tip-Only Redistribution\n\nA variant of restructure mode for branches where the commit history is noise and\nonly the final tree state matters.\n\n**When to use:**\n\n- More than 50% of commits are pivots, experiments, or failed approaches\n- The stack has been restacked 3+ times\n- Failed approaches were tried and abandoned in the history\n- Commit messages are mostly \"fix\", \"WIP\", \"try again\", or no longer match their\n  diffs\n\n**Approach:**\n\n1. **Analyze the final tree, not the history.** Run `\u002Fstack-summary --root` or\n   diff the tip against the base to understand what FILES exist at HEAD:\n\n   ```bash\n   git diff --stat $BASE..HEAD\n   git diff $BASE..HEAD\n   ```\n\n   Ignore the commit log entirely — don't try to preserve or reorder existing\n   commits. The history is discarded.\n\n2. **Classify every file in the total diff** into logical groups following the\n   ordering in `references\u002Fphilosophy.md`. For each group, note:\n   - Which files belong to it\n   - A one-sentence commit message\n   - Estimated line count (target 50-200 per commit)\n\n3. **Apply dependency timing audit** to determine ordering. Each planned commit\n   must only reference files, imports, and config that exist in it or earlier\n   commits. Documentation goes WITH the feature it documents.\n\n4. **Present the plan** to the user (same format as Plan mode step 4). **Wait\n   for user approval.**\n\n5. **Flatten to base and recommit from scratch** using Restructure mode steps\n   6-11 (check for uncommitted work, create backup, save tree hash, flatten,\n   commit each group).\n\n6. The resulting stack should tell a clean incremental story for reviewers — not\n   the story of how development actually happened.\n\n**Key differences from standard restructure:**\n\n- Standard restructure preserves and reorders existing commits\n- Tip-only redistribution ignores history and plans from the final tree\n- No need to identify intermediate file states (step 4 of standard restructure)\n  because the history is not a meaningful input — only the final diff against\n  the base matters\n- No need to extract intermediate file states (step 9 of standard restructure) —\n  intermediate content is authored fresh from the plan\n\n## Post-execution\n\n1. **Choose the destination for a from-root rebuild.** Stop and ask the user\n   which new branch should own the orphan history. Never replace local `main`;\n   the primary checkout may hold it.\n\n2. **Verify the result**:\n\n   ```bash\n   git sl\n   git log --oneline --reverse\n   ```\n\n   Show the user the new stack.\n\n3. **REQUIRED: Confirm total diff is identical** (Restructure mode only):\n\n   ```bash\n   # Tree hash comparison (catches ALL content differences):\n   test \"$(git rev-parse HEAD^{tree})\" = \"$FINAL_TREE\" && echo \"trees match\"\n\n   ```\n\n   Do NOT proceed if trees don't match. Fix the diverging files first using\n   fixup commits (`git commit --fixup \u003Chash>` + autosquash rebase). Common\n   causes: intermediate file state written incorrectly, orphaned deletions\n   missed, or `git add -u` pulling unrelated changes.\n\n4. **Clean up stale artifacts**: check for self-referencing symlinks or other\n   working tree debris:\n\n   ```bash\n   git status --short   # should be clean\n   ```\n\n   Remove any untracked artifacts that weren't in the original tree.\n\n5. **Run tests** if a test command is identifiable:\n\n   ```bash\n   git test run -x '\u003Ctest-command>' --jobs \u003CN> '\u003Crevset>'\n   ```\n\n   Pick `\u003Crevset>` per **Choosing the test revset** in\n   `references\u002Fgit-branchless.md`, reading `stack()` there as `$STACK`.\n   Restructuring is one of the cases that argues for `$STACK` even inside a\n   single PR — the intermediate commits are newly built and untested — but say\n   so rather than widening silently, and size `\u003CN>` by memory, not cores.\n\n   Report any commits that break the build.\n\n## Tips\n\n- **Don't lose changes.** After flattening, double-check `git diff --stat`\n  matches the original range diff. If anything is missing, stop and investigate.\n- Prefer `git add \u003Cfiles>` over `git add -p` when the changeset groups by file\n  without needing hunk splitting.\n- Respect user-requested commit boundaries — not every restructure needs to\n  flatten everything.\n- **From-root restructures** flatten the entire history. Use\n  `git checkout --orphan` + `git reset` (not `git reset --soft` which needs a\n  parent commit). The branchless hook will panic — ignore it.\n- **Intermediate file states are the #1 source of rework.** Files like README.md\n  and CLAUDE.md that grow across many commits must be written with partial\n  content at each step. Plan these states BEFORE flattening.\n- For files with complex structure (nested sections, cross-references), a full\n  rewrite at the appropriate commit is often cleaner than incremental Edit\n  operations that can cause structural nesting errors.\n- **Expect hook failures during restructure.** PostToolUse hooks (agnix linting,\n  treefmt formatting, etc.) fire when using Write\u002FEdit during a restructure. The\n  working tree is intentionally inconsistent between commits — hook errors are\n  harmless and will pass once all files are committed. Use `--no-verify` on\n  intermediate commits if needed.\n- For corrections discovered after rebuilding, stop and use `\u002Fstack-fix` with a\n  known target. Do not improvise a rebase, move, revise, or restack repair.\n","Plan and execute a commit stack. Determines mode automatically based on input:\n\n- **From a plan\u002Fdescription** — user describes what needs to be built; skill\n  produces the commit ordering and executes it\n- **From uncommitted work** — working tree has changes; skill classifies and\n  commits them as an atomic stack\n- **From existing commits** — range like `main..HEAD`; skill restructures into a\n  clean atomic stack\n\n## Pre-flight\n\n1. **Load references** — read `references\u002Fphilosophy.md` and\n   `references\u002Fgit-branchless.md` (relative to this skill's directory) before\n   proceeding.\n\n2. **Confirm repository initialization.** A devenv project with\n   `git.branchless.enable` runs `git branchless init` on every shell entry.\n   Anywhere else, check and stop if it is missing:\n\n   ```bash\n   git config --get branchless.core.mainBranch >\u002Fdev\u002Fnull ||\n     echo \"not initialized: ask the user to run git branchless init\"\n   ```\n\n   Do not run `git branchless init` yourself: it rewrites the repository's\n   shared configuration and hooks for every worktree.\n\n3. **Check for stale rebase state**:\n\n   ```bash\n   ls -d \"$(git rev-parse --git-path rebase-merge)\" \\\n     \"$(git rev-parse --git-path rebase-apply)\" 2>\u002Fdev\u002Fnull\n   ```\n\n   If either exists, run `git rebase --abort` before proceeding. In a linked\n   worktree `.git` is a file, so ask Git for the paths.\n\n4. **Select this worktree's own stack** as `$STACK`, and use it wherever this\n   skill needs the stack or its base:\n\n   ```bash\n   main_branch=\"$(git config branchless.core.mainBranch || echo main)\"\n   remote=\"$(git config \"branch.${main_branch}.remote\" || echo origin)\"\n   base=\"$(git rev-parse --abbrev-ref \"${main_branch}@{upstream}\" 2>\u002Fdev\u002Fnull \\\n     || echo \"${remote}\u002F${main_branch}\")\"\n   git rev-parse --verify -q \"${base}^{commit}\" >\u002Fdev\u002Fnull || base=\"$main_branch\"\n   STACK=\"descendants(roots((stack() & ::HEAD) - ::$base)) - ::$base\"\n   ```\n\n   `$base` is main's upstream ref (the last fetched one), or local `main` when\n   there is none. Plain `stack()` is not your stack while local `main` is behind\n   its upstream, the normal state when worktrees branch from `origin\u002Fmain`: it\n   also holds the upstream commits and every stack another worktree branched\n   from them. See **Selecting your own stack** in\n   `references\u002Fgit-branchless.md`.\n\n## Determine Mode\n\nExamine `$ARGUMENTS` and repo state to select the mode:\n\n- If `$ARGUMENTS` contains `--tip-only` or requests tip-only redistribution →\n  **Restructure mode (tip-only redistribution)**\n- If `$ARGUMENTS` contains `--root` or requests a from-root restructure →\n  **Restructure mode (from-root)**\n- If `$ARGUMENTS` looks like a commit range (`main..HEAD`, `hash1..hash2`,\n  branch name) → **Restructure mode**\n- If `$ARGUMENTS` is a natural-language description of work to do → **Plan\n  mode**\n- If `$ARGUMENTS` is empty and the working tree has uncommitted changes →\n  **Working tree mode**\n- If `$ARGUMENTS` is empty and the working tree is clean → ask the user what\n  they want to do\n\n## Plan Mode\n\nThe user describes work to be done. Build the stack from scratch.\n\n1. **Understand the task** from `$ARGUMENTS`. If the description is vague, ask\n   clarifying questions.\n\n2. **Design the commit stack** following the ordering in\n   `references\u002Fphilosophy.md`:\n   1. Refactoring \u002F cleanup (separate from feature work, always first)\n   2. Dependencies \u002F build config changes\n   3. Scaffolding \u002F types \u002F interfaces \u002F schemas\n   4. Core business logic\n   5. Edge cases \u002F error handling\n   6. Tests\n\n   For each commit, note:\n   - One-sentence commit message (Conventional Commits format)\n   - Which files will be created or modified\n   - Estimated line count (target 50-200 per commit)\n   - Dependencies on prior commits (no forward references)\n\n3. **Verify no forward references**: each commit must only reference files,\n   imports, and config that exist in it or earlier commits. Documentation goes\n   WITH the feature it documents. Dependencies arrive in the commit that first\n   uses them.\n\n4. **Present the plan** to the user:\n\n   ```\n   Proposed stack (N commits):\n\n   1. type(scope): description — files X, Y (~80 lines)\n   2. type(scope): description — files A, B (~120 lines)\n   3. type(scope): description — files C, D, E (~150 lines)\n   ...\n   ```\n\n   **Wait for user approval.** Adjust if they have feedback.\n\n5. **Execute the plan** — implement each commit in order:\n\n   ```bash\n   # Write the code for commit 1\n   git add \u003Cfiles>\n   git commit -m \"type(scope): description\"\n\n   # Write the code for commit 2\n   git add \u003Cfiles>\n   git commit -m \"type(scope): description\"\n   ```\n\n   After each commit, verify the codebase is in a working state.\n\n## Working Tree Mode\n\nUncommitted changes exist. Classify and commit them as a stack.\n\n1. **Survey the changes**:\n\n   ```bash\n   git status --short\n   git diff --stat\n   git diff\n   ```\n\n   Read the full diff. Count total lines changed.\n\n2. **Classify every change** into logical groups following the ordering in\n   `references\u002Fphilosophy.md`. For each group, note:\n   - Which files and hunks belong to it\n   - A one-sentence commit message\n   - Estimated line count (target 50-200 per commit)\n\n   If a file has changes spanning multiple groups, it will need `git add -p` to\n   split hunks across commits.\n\n3. **Present the plan** to the user (same format as Plan mode step 4). **Wait\n   for user approval.**\n\n4. **Commit each group** in plan order:\n\n   ```bash\n   # For file-level grouping:\n   git add \u003Cfile1> \u003Cfile2>\n   git commit -m \"type(scope): description\"\n\n   # For hunk-level splitting within a file:\n   git add -p \u003Cfile>\n   git commit -m \"type(scope): description\"\n   ```\n\n   After each commit, verify nothing was missed or double-counted:\n\n   ```bash\n   git diff --stat   # remaining uncommitted changes\n   ```\n\n## Restructure Mode\n\nExisting commits need to be reorganized into a clean atomic stack.\n\n1. **Parse the range** from `$ARGUMENTS`. Resolve to a `\u003Cbase>` and `\u003Ctip>`:\n\n   ```bash\n   # For range syntax (base..tip):\n   BASE=\u003Cresolved base>\n   TIP=\u003Cresolved tip>\n\n   # For a branch name, find the merge-base with the upstream, not local main:\n   BASE=$(git merge-base \"$base\" \u003Cbranch>)\n   TIP=\u003Cbranch>\n\n   # For --root (entire history):\n   BASE=\u003Cempty tree>\n   TIP=HEAD\n   ```\n\n2. **Understand the current state**:\n\n   ```bash\n   git sl\n   git log --oneline --reverse $BASE..$TIP   # or --root for from-root\n   git log --reverse --stat --format=\"=== %h %s ===\" $BASE..$TIP\n   git diff --stat $BASE..$TIP\n\n   # From-root (no base commit):\n   git log --oneline --reverse --root\n   git log --reverse --stat --format=\"=== %h %s ===\" --root\n   git diff --stat $(git hash-object -t tree \u002Fdev\u002Fnull) HEAD\n   ```\n\n   Read the full diff and per-commit stats. Count total lines changed.\n\n   A range written against local `main` (`main..HEAD`) also holds the upstream\n   commits while `main` is stale, and using the upstream tip itself as the base\n   stages upstream-only commits as deletions. For this worktree's stack, use\n   `$(git merge-base \"$base\" HEAD)..HEAD`.\n\n3. **Classify every change** into logical groups (same as Working Tree mode step\n   2).\n\n4. **Identify files with intermediate states**: before planning the commit\n   sequence, list every file that will have DIFFERENT content across multiple\n   commits (e.g. README.md, CLAUDE.md, flake.nix growing incrementally). For\n   each, write out EXACTLY what content it should have at each commit boundary.\n   Plan ALL intermediate states BEFORE flattening — discovering them as you go\n   leads to fixups and tree hash mismatches. This is the #1 source of rework\n   during restructure.\n\n5. **Present the plan** (same format as Plan mode step 4). **Wait for user\n   approval.**\n\n6. **Check for uncommitted work** before flattening:\n\n   ```bash\n   git status --short\n   ```\n\n   If there are uncommitted changes, warn the user and ask whether to stash or\n   commit them first.\n\n7. **Confirm the recovery point.** Record the current commit ID in the task\n   report. Do not create or delete a generic repository-global backup branch; it\n   may belong to another worktree or session.\n\n8. **Save the tree hash** for post-verification:\n\n   ```bash\n   FINAL_TREE=$(git rev-parse HEAD^{tree})\n   ```\n\n9. **Extract intermediate file states** before flattening. For every file\n   identified in step 4 as having multiple states, save each version to a temp\n   directory using `git show`. After flattening, the working tree only contains\n   the final state — earlier versions are gone.\n\n   ```bash\n   STATES_DIR=$(mktemp -d \u002Ftmp\u002Frestructure-states.XXXXXX)\n   # For each (file, commit) pair from step 4:\n   git show \"${HASH}\":path\u002Fto\u002Ffile > \"${STATES_DIR}\u002Ffilename.${HASH}\"\n   ```\n\n   Include stub files (placeholder modules, `.gitkeep` files) that scaffold\n   commits create before later commits replace them with real content. Restore\n   these with `cp` or `touch` before staging each intermediate commit.\n\n10. **Flatten the range** into the working tree:\n\n```bash\n# Standard range (has a base commit):\ngit reset --soft $BASE\ngit restore --staged .\n\n# From-root (no base commit):\ngit checkout --orphan restructure-wip\ngit reset\n# Note: git-branchless hook will panic on orphan branches — this is\n# harmless. The checkout succeeds. Suppress noise with:\n#   2>&1 | grep -v \"^branchless:\"\n```\n\nVerify the working tree matches the original diff:\n\n```bash\n# Standard range (files are unstaged):\ngit diff --stat   # should match step 2's total diff\n\n# From-root (all files are untracked after orphan+reset):\ngit status --short | wc -l   # should match step 2's file count\n```\n\n11. **Commit each group** in plan order (same as Working Tree mode step 4). For\n    files with intermediate states (identified in step 4), restore the correct\n    version from `$STATES_DIR` BEFORE staging for each commit. Do not rely on\n    the final working tree content — it represents the end state, not\n    intermediate states.\n\n    After staging each commit, check for common mistakes:\n    - **Orphaned deletions**: when staging renamed\u002Fmoved files, the old paths\n      remain as unstaged deletions. Check `git status` and stage them in the\n      same commit.\n    - **`git add -u` during multi-commit rebuild**: stages ALL modified tracked\n      files, not just the ones for this commit. Always use explicit\n      `git add \u003Cfile>` paths.\n    - **Verify staged content**: run `git diff --cached --stat` to confirm only\n      intended files are staged.\n\n### Tip-Only Redistribution\n\nA variant of restructure mode for branches where the commit history is noise and\nonly the final tree state matters.\n\n**When to use:**\n\n- More than 50% of commits are pivots, experiments, or failed approaches\n- The stack has been restacked 3+ times\n- Failed approaches were tried and abandoned in the history\n- Commit messages are mostly \"fix\", \"WIP\", \"try again\", or no longer match their\n  diffs\n\n**Approach:**\n\n1. **Analyze the final tree, not the history.** Run `\u002Fstack-summary --root` or\n   diff the tip against the base to understand what FILES exist at HEAD:\n\n   ```bash\n   git diff --stat $BASE..HEAD\n   git diff $BASE..HEAD\n   ```\n\n   Ignore the commit log entirely — don't try to preserve or reorder existing\n   commits. The history is discarded.\n\n2. **Classify every file in the total diff** into logical groups following the\n   ordering in `references\u002Fphilosophy.md`. For each group, note:\n   - Which files belong to it\n   - A one-sentence commit message\n   - Estimated line count (target 50-200 per commit)\n\n3. **Apply dependency timing audit** to determine ordering. Each planned commit\n   must only reference files, imports, and config that exist in it or earlier\n   commits. Documentation goes WITH the feature it documents.\n\n4. **Present the plan** to the user (same format as Plan mode step 4). **Wait\n   for user approval.**\n\n5. **Flatten to base and recommit from scratch** using Restructure mode steps\n   6-11 (check for uncommitted work, create backup, save tree hash, flatten,\n   commit each group).\n\n6. The resulting stack should tell a clean incremental story for reviewers — not\n   the story of how development actually happened.\n\n**Key differences from standard restructure:**\n\n- Standard restructure preserves and reorders existing commits\n- Tip-only redistribution ignores history and plans from the final tree\n- No need to identify intermediate file states (step 4 of standard restructure)\n  because the history is not a meaningful input — only the final diff against\n  the base matters\n- No need to extract intermediate file states (step 9 of standard restructure) —\n  intermediate content is authored fresh from the plan\n\n## Post-execution\n\n1. **Choose the destination for a from-root rebuild.** Stop and ask the user\n   which new branch should own the orphan history. Never replace local `main`;\n   the primary checkout may hold it.\n\n2. **Verify the result**:\n\n   ```bash\n   git sl\n   git log --oneline --reverse\n   ```\n\n   Show the user the new stack.\n\n3. **REQUIRED: Confirm total diff is identical** (Restructure mode only):\n\n   ```bash\n   # Tree hash comparison (catches ALL content differences):\n   test \"$(git rev-parse HEAD^{tree})\" = \"$FINAL_TREE\" && echo \"trees match\"\n\n   ```\n\n   Do NOT proceed if trees don't match. Fix the diverging files first using\n   fixup commits (`git commit --fixup \u003Chash>` + autosquash rebase). Common\n   causes: intermediate file state written incorrectly, orphaned deletions\n   missed, or `git add -u` pulling unrelated changes.\n\n4. **Clean up stale artifacts**: check for self-referencing symlinks or other\n   working tree debris:\n\n   ```bash\n   git status --short   # should be clean\n   ```\n\n   Remove any untracked artifacts that weren't in the original tree.\n\n5. **Run tests** if a test command is identifiable:\n\n   ```bash\n   git test run -x '\u003Ctest-command>' --jobs \u003CN> '\u003Crevset>'\n   ```\n\n   Pick `\u003Crevset>` per **Choosing the test revset** in\n   `references\u002Fgit-branchless.md`, reading `stack()` there as `$STACK`.\n   Restructuring is one of the cases that argues for `$STACK` even inside a\n   single PR — the intermediate commits are newly built and untested — but say\n   so rather than widening silently, and size `\u003CN>` by memory, not cores.\n\n   Report any commits that break the build.\n\n## Tips\n\n- **Don't lose changes.** After flattening, double-check `git diff --stat`\n  matches the original range diff. If anything is missing, stop and investigate.\n- Prefer `git add \u003Cfiles>` over `git add -p` when the changeset groups by file\n  without needing hunk splitting.\n- Respect user-requested commit boundaries — not every restructure needs to\n  flatten everything.\n- **From-root restructures** flatten the entire history. Use\n  `git checkout --orphan` + `git reset` (not `git reset --soft` which needs a\n  parent commit). The branchless hook will panic — ignore it.\n- **Intermediate file states are the #1 source of rework.** Files like README.md\n  and CLAUDE.md that grow across many commits must be written with partial\n  content at each step. Plan these states BEFORE flattening.\n- For files with complex structure (nested sections, cross-references), a full\n  rewrite at the appropriate commit is often cleaner than incremental Edit\n  operations that can cause structural nesting errors.\n- **Expect hook failures during restructure.** PostToolUse hooks (agnix linting,\n  treefmt formatting, etc.) fire when using Write\u002FEdit during a restructure. The\n  working tree is intentionally inconsistent between commits — hook errors are\n  harmless and will pass once all files are committed. Use `--no-verify` on\n  intermediate commits if needed.\n- For corrections discovered after rebuilding, stop and use `\u002Fstack-fix` with a\n  known target. Do not improvise a rebase, move, revise, or restack repair.\n",{"name":5,"description":7,"argument-hint":45,"compatibility":46,"disable-model-invocation":41},"\u003Cplan | range | (none for working tree)>","Requires git-branchless","main","a33b4e70efef03fe75378fad9c847b73ea142c46","packages\u002Fstacked-workflows\u002Fskills\u002Fstack-plan",0,"https:\u002F\u002Fgithub.com\u002Fhigherorderfunctor\u002Fnix-agentic-tools","https:\u002F\u002Fgithub.com\u002Fhigherorderfunctor","2026-11-15 04:06:13",{"source":8,"skillName":5,"commands":55,"prompt":65,"zipAvailable":66},[56,59,62],{"tool":57,"command":58},"npx","npx skills add higherorderfunctor\u002Fnix-agentic-tools --skill stack-plan",{"tool":60,"command":61},"bunx","bunx skills add higherorderfunctor\u002Fnix-agentic-tools --skill stack-plan",{"tool":63,"command":64},"pnpm","pnpm dlx skills add higherorderfunctor\u002Fnix-agentic-tools --skill stack-plan","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fhigherorderfunctor\u002Fnix-agentic-tools\u002Fblob\u002Fmain\u002Fpackages\u002Fstacked-workflows\u002Fskills\u002Fstack-plan\u002FSKILL.md",true,[68,74],{"path":69,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":72,"sourceHtmlUrl":73},"references\u002Fgit-branchless.md","REFERENCE","参考文档",37,"https:\u002F\u002Fgithub.com\u002Fhigherorderfunctor\u002Fnix-agentic-tools\u002Fblob\u002Fmain\u002Fpackages\u002Fstacked-workflows\u002Fskills\u002Fstack-plan\u002Freferences\u002Fgit-branchless.md",{"path":75,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":76,"sourceHtmlUrl":77},"references\u002Fphilosophy.md",33,"https:\u002F\u002Fgithub.com\u002Fhigherorderfunctor\u002Fnix-agentic-tools\u002Fblob\u002Fmain\u002Fpackages\u002Fstacked-workflows\u002Fskills\u002Fstack-plan\u002Freferences\u002Fphilosophy.md",[79,99,123,142,159,175],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":40},"01M6MQXHSDNFXSN7TT5FFWPF3X","stack-test","Use when you need to run tests or formatters across commits in a stack. Use INSTEAD of manual git test run or looping git checkout + test. Prevents: testing every commit when only the tip has to pass, unbounded parallel jobs exhausting memory, cache misunderstandings.","https:\u002F\u002Fgithub.com\u002Fhigherorderfunctor\u002Fnix-agentic-tools\u002Fblob\u002Fmain\u002Fpackages\u002Fstacked-workflows\u002Fskills\u002Fstack-test\u002FSKILL.md",[],[86,21,87,88,89,90,38,91,27,92,93,94,95,35,31,28,96,32,97,98,23],"test","stack test","parallel","TIP","checkout","memory","testing","fix","tests","only","cache","across","command",{"skillNo":100,"name":101,"nameZh":6,"description":102,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":40},"01M6MQXAXVWG1RY9H2116G4SVX","stack-summary","Use when you need to audit, analyze, or review stack quality before restructuring. Produces a structured summary with per-commit classification, philosophy audit, and violation flags. Output feeds directly into \u002Fstack-plan restructure mode. Use INSTEAD of manual git log inspection.","https:\u002F\u002Fgithub.com\u002Fhigherorderfunctor\u002Fnix-agentic-tools\u002Fblob\u002Fmain\u002Fpackages\u002Fstacked-workflows\u002Fskills\u002Fstack-summary\u002FSKILL.md",[],[21,106,107,108,109,25,27,110,111,35,31,28,112,32,113,114,115,116,29,117,118,23,20,119,120,121,122],"stack summary","summary","feeds","review stack","mode","classification","git log","log","review","output","analyze","philosophy","inspection","worktree","audit","flags","git",{"skillNo":124,"name":125,"nameZh":6,"description":126,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":127,"categories":128,"keywords":129,"publishedAt":40},"01M6MQX62HMQR5CSN4FSC95ZJC","stack-submit","Use when you need to push, submit, or create pull requests for a commit stack. Rebases only the current stack onto upstream main, validates, and pushes INSTEAD of manual git sync + git submit + PR\u002FMR creation. Handles branch creation, stacked PR\u002FMR creation with correct base branches.","https:\u002F\u002Fgithub.com\u002Fhigherorderfunctor\u002Fnix-agentic-tools\u002Fblob\u002Fmain\u002Fpackages\u002Fstacked-workflows\u002Fskills\u002Fstack-submit\u002FSKILL.md",[],[130,21,131,132,133,134,135,136,25,27,137,138,139,95,47,35,31,140,141,23],"submit","stack submit","pull","branch","push","pr","creation","correct","upstream","branches","git sync","mr",{"skillNo":143,"name":144,"nameZh":6,"description":145,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":146,"categories":147,"keywords":148,"publishedAt":40},"01M6MQX2BNQ4MAV9KCV0RZ734G","stack-split","Use when you need to break up, split, or decompose a large commit into smaller atomic commits. Use INSTEAD of manual git rebase -i + edit or git reset HEAD^. Prevents: non-working intermediate commits, wrong split ordering, missed downstream restack.","https:\u002F\u002Fgithub.com\u002Fhigherorderfunctor\u002Fnix-agentic-tools\u002Fblob\u002Fmain\u002Fpackages\u002Fstacked-workflows\u002Fskills\u002Fstack-split\u002FSKILL.md",[],[149,21,150,151,38,27,152,35,31,37,28,32,33,153,154,155,156,157,122,158,23],"split","stack split","decompose","up","head","missed","break","atomic","edit","rebase",{"skillNo":160,"name":161,"nameZh":6,"description":162,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":163,"categories":164,"keywords":165,"publishedAt":40},"01M6MQWP7CKTM5NF72MED1H8NS","stack-fix","Use when you need to fix, correct, or update content in an earlier commit — line-level edits, content moves, or structural changes. Absorbs staged changes into correct stack commits INSTEAD of running git absorb or git commit --fixup via Bash, or hand-running git prev + edit + git amend + git restack --merge. Prevents: missed dry-run preview, leftover staged changes going unnoticed, forgetting to restack. Falls back to guided manual amend when absorb cannot route hunks.","https:\u002F\u002Fgithub.com\u002Fhigherorderfunctor\u002Fnix-agentic-tools\u002Fblob\u002Fmain\u002Fpackages\u002Fstacked-workflows\u002Fskills\u002Fstack-fix\u002FSKILL.md",[],[93,21,166,167,38,27,137,168,39,35,31,28,169,170,32,171,172,173,174,23],"stack fix","back","structural","Bash","preview","hand","dry","route","running",{"skillNo":176,"name":177,"nameZh":6,"description":178,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":179,"categories":180,"keywords":181,"publishedAt":40},"01M6MQWJS10XBJT1C1JW4QF1X9","peer-communication","How to write replies a person reads: answer first, plain words, easy to scan. Load before your first reply in an interactive session.","https:\u002F\u002Fgithub.com\u002Fhigherorderfunctor\u002Fnix-agentic-tools\u002Fblob\u002Fmain\u002Fpackages\u002Fpeer-communication\u002Fskills\u002Fpeer-communication\u002FSKILL.md",[],[182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198],"peer","communication","peer communication","scan","answer","session","how to","load","interactive","replies","first","how","write","person","easy","reply","plain"]