diff --git a/.claude/rules/meta-destructive-commands.md b/.claude/rules/meta-destructive-commands.md index b06f534..a326934 100644 --- a/.claude/rules/meta-destructive-commands.md +++ b/.claude/rules/meta-destructive-commands.md @@ -4,10 +4,13 @@ Multi-repo workspaces amplify the impact of destructive commands. ## Before Destructive Operations -1. **Create a snapshot first** +1. **Commit or stash first** ``` - meta git snapshot create before-refactor + meta git status + meta git add -A && meta git commit -m "wip: before refactor" ``` + Or stash it in every repo: `meta exec -- git stash push -u -m before-refactor`. + A backup branch (`git branch backup/`) keeps only commits, not uncommitted changes. 2. **Preview with --dry-run** ``` @@ -23,13 +26,18 @@ Multi-repo workspaces amplify the impact of destructive commands. These commands trigger PreToolUse denial: - `git push --force` (use `--force-with-lease` instead) -- `git reset --hard` (use `meta git snapshot` instead) +- `git reset --hard` (commit or stash first; recover commits with `git reflog`) - `git clean -fd` (dangerous file removal) - `rm -rf` on repo roots or `.meta*` paths ## Recovery -If something goes wrong: +If something goes wrong, run `git reflog` in the affected repo to find the previous commit, then restore it on a branch: ``` -meta git snapshot restore before-refactor +git switch -c recovered ``` +To look across all repos: +``` +meta exec -- git reflog -n 20 +``` +The reflog only recovers commits, not uncommitted changes. diff --git a/.claude/skills/meta-exec/SKILL.md b/.claude/skills/meta-exec/SKILL.md index 93cbc41..e53a941 100644 --- a/.claude/skills/meta-exec/SKILL.md +++ b/.claude/skills/meta-exec/SKILL.md @@ -185,7 +185,7 @@ meta exec -- rm -rf node_modules dist | Generic commands | Git operations | | Build/test commands | Commands needing special handling | | One-off scripts | Operations with meta-specific logic | -| npm/cargo/make | Clone, update, snapshot | +| npm/cargo/make | Clone, update, worktree | `meta exec -- ` always runs the command as typed, never through a plugin: `meta exec -- git status` runs plain `git status` in each repo, while `meta git status` uses the git plugin. Prefer `meta git ` for git: any git subcommand passes through it, and it runs remote commands (`fetch`, `pull`, `push`) without credential prompts that would hang parallel runs. Plugins intercept only their own subcommands (`meta git ...`, `meta cargo ...`) and provide enhanced behavior. `meta git clone` doesn't run `git clone` in each repo—it reads `.meta` and clones the entire graph. diff --git a/.claude/skills/meta-git/SKILL.md b/.claude/skills/meta-git/SKILL.md index 656fc64..ce4d3e5 100644 --- a/.claude/skills/meta-git/SKILL.md +++ b/.claude/skills/meta-git/SKILL.md @@ -1,6 +1,6 @@ --- name: meta-git -description: Git operations across multiple repositories — status, commit, push, pull, snapshots, multi-commit. +description: Git operations across multiple repositories — status, commit, push, pull, multi-commit. --- # Meta Git Skill @@ -48,30 +48,26 @@ meta git update # Clone repos listed in .meta that are missing locally `meta git update` only clones missing repos (nested meta repos included); it does not pull existing ones. `meta git pull --recursive` also pulls nested meta repos. -## Snapshots (Critical for Batch Operations) +## Before Batch Operations (Critical) -Before making sweeping changes, create a snapshot: +Before making sweeping changes, commit or stash uncommitted work in every repo: ```bash -# Save current state of every repo at this meta level (add --recursive for nested ones) -meta git snapshot create before-refactor +# See which repos have uncommitted changes +meta git status -# See what snapshots exist -meta git snapshot list +# Commit them at this meta level (add --recursive for nested ones); `meta git commit` commits only staged changes +meta git add -A +meta git commit -m "wip: before refactor" -# Preview what restore would do -meta --dry-run git snapshot restore before-refactor +# Or stash them instead (untracked files included) +meta exec -- git stash push -u -m before-refactor -# Actually restore (auto-stashes uncommitted tracked changes; asks to confirm without --force) -meta git snapshot restore before-refactor --force +# Preview a batch command before running it +meta --dry-run exec -- ``` -**What snapshots capture per repo:** -- Current SHA -- Branch name -- Dirty status - -**On restore**: Each repo's branch is reset to the snapshot's SHA (`git checkout -B `), so commits made after the snapshot drop off the branch (they stay in the reflog). If a repo has uncommitted changes to tracked files, meta stashes them first. Untracked files are not stashed and can block the checkout. +**Recovering**: `git reflog` in the affected repo lists the commits its `HEAD` pointed to; `git switch -c recovered ` brings one back. Use `meta exec -- git reflog -n 20` to look across all repos (`--include ` for one). The reflog only recovers commits, not uncommitted changes, so commit or stash first. A backup branch keeps only commits. ## Common Git Operations @@ -107,7 +103,8 @@ meta --exclude legacy git pull ### Starting Work ```bash meta git status # What's the current state? -meta git snapshot create wip # Save state before changes +meta git add -A # Stage pending work +meta git commit -m "wip" # Commit it before changes meta git pull # Get latest ``` @@ -121,11 +118,11 @@ meta git push # Push all repos ### Safe Batch Refactoring ```bash -meta git snapshot create before-changes +meta git add -A && meta git commit -m "wip: before changes" # Save pending work first # ... make changes across repos ... meta git status # Review -# If something went wrong: -meta git snapshot restore before-changes --force +# If something went wrong, in the affected repo: +git reflog # Find an earlier commit, then: git switch -c recovered ``` ## MCP Tools for Git Operations diff --git a/.claude/skills/meta-plugins/SKILL.md b/.claude/skills/meta-plugins/SKILL.md index 809fb30..4711bad 100644 --- a/.claude/skills/meta-plugins/SKILL.md +++ b/.claude/skills/meta-plugins/SKILL.md @@ -29,7 +29,6 @@ Handles all `meta git *` commands with special cases: |---------|----------| | `meta git clone ` | Clone parent, read `.meta`, clone all children | | `meta git update` | Clone missing repos (use `meta git pull` to pull existing ones) | -| `meta git snapshot *` | Create/restore workspace state | | `meta git worktree *` | Isolated multi-repo worktree sets (see the `meta-worktree` skill) | | `meta git ` | Pass through to every repo at this meta level | diff --git a/src/context.rs b/src/context.rs index 6c347e7..8a55d0a 100644 --- a/src/context.rs +++ b/src/context.rs @@ -277,10 +277,6 @@ fn key_commands() -> Vec { command: "meta git commit -m \"msg\"".to_string(), description: "commit in all dirty repos".to_string(), }, - CommandRef { - command: "meta git snapshot create ".to_string(), - description: "save state before batch changes".to_string(), - }, CommandRef { command: "meta --include X,Y exec -- ".to_string(), description: "target specific repos".to_string(), diff --git a/src/subprocess_plugins.rs b/src/subprocess_plugins.rs index 4d93761..85c4eab 100644 --- a/src/subprocess_plugins.rs +++ b/src/subprocess_plugins.rs @@ -737,7 +737,7 @@ mod tests { ("rust", vec!["cargo build", "cargo test"]), ( "git", - vec!["git status", "git snapshot", "git snapshot create"], + vec!["git status", "git worktree", "git worktree create"], ), ] { manager.plugins.insert( @@ -757,7 +757,7 @@ mod tests { // The longest claimed command wins; the rest are the plugin's args assert_eq!( - routed(&manager, &["git", "snapshot", "create", "x"]), + routed(&manager, &["git", "worktree", "create", "x"]), Some(("git".to_string(), 3)) ); assert_eq!(