diff --git a/.context/tasks/meta-snapshot.md b/.context/tasks/meta-snapshot.md index 64dab16d..0b05a443 100644 --- a/.context/tasks/meta-snapshot.md +++ b/.context/tasks/meta-snapshot.md @@ -179,7 +179,7 @@ Captured state of 25 repos Snapshot saved: .meta-snapshots/before-upgrade.json # Do batch operations -$ meta exec "git pull && npm install" +$ meta exec -- sh -c 'git pull && npm install' # ... something breaks ... # Restore diff --git a/.meta/skills/meta-exec/SKILL.md b/.meta/skills/meta-exec/SKILL.md index 586a6116..93cbc41b 100644 --- a/.meta/skills/meta-exec/SKILL.md +++ b/.meta/skills/meta-exec/SKILL.md @@ -15,13 +15,19 @@ Execute any command in the root repo and every project at this meta level (add ` # Run 'make build' in every repo meta exec -- make build -# Run any shell command +# Any program with its arguments meta exec -- ls -la - -# Commands with arguments meta exec -- npm install --save-dev typescript ``` +Each argument meta receives reaches the program unchanged: meta runs the program directly, with no shell in between. Quotes, spaces, `$()`, `;`, `|`, `&&`, globs and `%` in an argument stay literal, so text from an issue, a commit message or a file name can't run commands once meta has it. Your own shell still parses the command line before meta runs (`"$(...)"` in double quotes runs there), so pass untrusted text in single quotes or as a separate argv element (as the MCP tools take it). When you want a shell (pipes, `&&`, redirects, globs), ask for one: + +```bash +meta exec -- sh -c 'npm ci && npm test' +``` + +A `.looprc` alias for the program is expanded into words (POSIX quoting rules, nothing expanded or run). On Windows meta does not wrap commands in `cmd /c` either. Batch files such as `npm.cmd` need their extension (`meta exec -- npm.cmd install`); Windows runs those through `cmd.exe`, and Rust escapes their arguments for it and refuses any it cannot pass safely. + The `--` separates meta options from the command to execute. The `--` is optional unless your command starts with `-`. ```bash @@ -52,16 +58,17 @@ Parallel mode: ## Filtering Options -Control which repos run the command. These options come from `loop`: +Control which repos run the command: ```bash -# Only directories whose path contains one of these (substring match) +# Only these repos: each value is a repo's .meta name or its path from the workspace root meta --include api,worker git status +meta --include libs/core,. git status # `.` is the root repo -# Skip directories whose path contains one of these +# Skip these repos meta --exclude legacy-service git push -# Filter by tag (meta-specific, applied before loop filtering) +# Filter by tag (applied before --include/--exclude) meta --tag backend exec -- make deploy # Combine: tag filter + directory filter @@ -70,10 +77,10 @@ meta --tag backend --include api git status **Filter precedence:** 1. `--tag` filters projects by tag (meta level) -2. `--include` limits to specific directories (loop level) -3. `--exclude` removes directories (loop level) +2. `--include` limits to the named repos +3. `--exclude` removes the named repos -Include/exclude match substrings of directory paths, so `api` also matches `api-tests`. The meta root repo stays included even when it doesn't match a tag. +A value names a whole repo, never part of a path: `api` does not match `api-tests`. A value that names no repo is an error, so a typo never runs a command in the repo you meant to skip. Inside a worktree set, a repo is named by its alias (its path in the set). A value starting with `./` is a path only; use it when a name is ambiguous (a value that names several repos is an error too). The meta root repo stays included even when it doesn't match a tag. ## Dry Run @@ -129,8 +136,8 @@ meta --silent exec -- npm install |--------|-------------| | `--parallel` | Run commands concurrently (the default) | | `--sequential` | Run one repo at a time | -| `--include ` | Only directories whose path contains these | -| `--exclude ` | Skip directories whose path contains these | +| `--include ` | Only these repos (`.meta` name or path from the root) | +| `--exclude ` | Skip these repos (`.meta` name or path from the root) | | `--tag ` | Filter by project tag(s) | | `--dry-run` | Preview without executing | | `--json` | Structured JSON output | @@ -161,8 +168,8 @@ meta --exclude large-monorepo exec -- cargo update ### Find Files Across Repos ```bash -# Quote the whole command: meta joins its arguments with spaces for the shell -meta exec -- 'find . -name "*.rs" -type f' | head -20 +# Arguments go to find as typed: "*.rs" is find's pattern, not a shell glob +meta exec -- find . -name '*.rs' -type f | head -20 ``` ### Clean Build Artifacts @@ -175,7 +182,7 @@ meta exec -- rm -rf node_modules dist | Use `meta exec` | Use Plugin (e.g., `meta git`) | |-----------------|-------------------------------| -| Generic shell commands | Git operations | +| 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 | diff --git a/.meta/skills/meta-git/SKILL.md b/.meta/skills/meta-git/SKILL.md index 1a0098bd..656fc641 100644 --- a/.meta/skills/meta-git/SKILL.md +++ b/.meta/skills/meta-git/SKILL.md @@ -19,6 +19,8 @@ meta git status # Shows status for every repo at once meta git commit -m "feat: update" # Commits in every repo with staged changes ``` +Any other git subcommand passes through to git in each repo. Meta passes the arguments it receives to git unchanged, with no shell in between: `meta git log --format='%h %s'` and a commit message containing `$(...)` or `;` are passed as-is. Your own shell still expands `$(...)` inside double quotes before meta runs, so put untrusted text in single quotes. + ## Cloning a Meta Repo ```bash @@ -87,13 +89,13 @@ meta git log --oneline -5 ## Filtering -Target specific repos. With `--tag`, the meta root repo stays included even when it isn't tagged; `--include`/`--exclude` match substrings of directory paths and can drop the root. +Target specific repos. With `--tag`, the meta root repo stays included even when it isn't tagged; `--include`/`--exclude` take whole repos (a `.meta` name or the path from the workspace root, `.` for the root), never part of a path, and can drop the root. A value that names no repo is an error. ```bash # By tag meta --tag backend git status -# By directory (substring match: `api` also matches `api-tests`) +# By repo: .meta name or path from the root (`api` does not match `api-tests`) meta --include api,web git push # Exclude repos @@ -139,7 +141,7 @@ When the meta MCP server is available, these tools provide structured JSON outpu ## Efficiency Tips -- **Targeted commits**: `meta --include repo1,repo2 git commit -m "msg"` commits only in repos whose path matches +- **Targeted commits**: `meta --include repo1,repo2 git commit -m "msg"` commits only in the named repos - **Tag-based push**: `meta --tag backend git push` pushes tagged repos (and the root) - **Per-repo messages**: Use `meta_git_multi_commit` when changes in different repos need different commit messages - **One-call status**: `meta git status` replaces N individual `cd && git status` sequences diff --git a/.meta/skills/meta-safety/SKILL.md b/.meta/skills/meta-safety/SKILL.md index ca036710..d584efbd 100644 --- a/.meta/skills/meta-safety/SKILL.md +++ b/.meta/skills/meta-safety/SKILL.md @@ -15,7 +15,7 @@ Multi-repo workspaces are powerful but require awareness. Meta gives you precisi ## Precision Operations -Instead of cd-ing into repos one by one, use meta flags to target what you need. Include/exclude match substrings of directory paths; `--tag` keeps the meta root even when it isn't tagged: +Instead of cd-ing into repos one by one, use meta flags to target what you need. Include/exclude take whole repos (a `.meta` name or the path from the workspace root), never part of a path, and a value that names no repo is an error; `--tag` keeps the meta root even when it isn't tagged: ```bash # Target specific repos @@ -42,7 +42,7 @@ When modifying a repo that other repos depend on: ## Efficient Commits ```bash -# Commit only in repos whose path contains repo1 or repo2 (substring match) +# Commit only in repos repo1 and repo2 (.meta name or path from the root) meta --include repo1,repo2 git commit -m "feat: update shared API" # Push tagged repos (and the root) diff --git a/.meta/skills/meta-workspace/SKILL.md b/.meta/skills/meta-workspace/SKILL.md index fcb46172..859ca35c 100644 --- a/.meta/skills/meta-workspace/SKILL.md +++ b/.meta/skills/meta-workspace/SKILL.md @@ -115,7 +115,7 @@ When the meta MCP server is available, these tools provide structured JSON for p ## Efficiency Tips - **One command, all repos**: `meta git status` replaces N individual `cd && git status` calls -- **Targeted operations**: `meta --include repo1,repo2 exec -- cmd` operates on only the repos whose path matches +- **Targeted operations**: `meta --include repo1,repo2 exec -- cmd` operates on only the named repos (`.meta` name or path from the workspace root) - **Tag-based filtering**: `meta --tag backend exec -- cargo test` scopes to tagged repos - **Dependency awareness**: `meta_analyze_impact ` shows who depends on a repo before you modify it — prevents cascading fix-up commits - **Session start**: Always run `meta project list --recursive --json` first to get the workspace map diff --git a/.meta/skills/meta-worktree/SKILL.md b/.meta/skills/meta-worktree/SKILL.md index c1f9b102..bc946be5 100644 --- a/.meta/skills/meta-worktree/SKILL.md +++ b/.meta/skills/meta-worktree/SKILL.md @@ -127,9 +127,11 @@ meta git worktree exec auth-fix --exclude legacy -- npm test meta git worktree exec auth-fix --parallel -- cargo build ``` -`--include`/`--exclude` match text anywhere in each repo's absolute path, and -every path contains `.worktrees//`: pick filter text that isn't in the set -name (`--include auth` in set `auth-fix` matches every repo). +`--include`/`--exclude` name whole repos by alias, their path in the set +(`.` for the root repo), never part of a path. A value that names no repo in +the set is an error. They go after the set name: `meta --include x git +worktree ...` is refused. The command's arguments reach it as +typed, with no shell; use `-- sh -c '...'` when you want one. ## Context Detection @@ -229,7 +231,7 @@ it up with `remove`. | Option | Description | |--------|-------------| -| `--include ` | Only repos whose path contains it (comma-separated) | -| `--exclude ` | Skip repos whose path contains it (comma-separated) | +| `--include ` | Only these repos, by alias (comma-separated) | +| `--exclude ` | Skip these repos, by alias (comma-separated) | | `--parallel` | Run concurrently | | `--ephemeral` | Create, run, then remove (takes `--repo`/`--all`, `--branch`, `--from-pr`, `--meta`, a commit-ish) | diff --git a/Cargo.lock b/Cargo.lock index ae4381e8..f8de765c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -949,6 +949,7 @@ dependencies = [ "rayon", "serde", "serde_json", + "shlex", "tempfile", ] @@ -1094,7 +1095,6 @@ dependencies = [ "colored", "indexmap", "meta_plugin_protocol", - "shlex", "tempfile", ] diff --git a/README.md b/README.md index 95cd6d2f..15dfb92c 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ User runs: meta git status --tag backend Meta CLI: parse args → load .meta → filter by tags → find plugin │ ▼ -Plugin (meta-git): "here's the plan" → [{dir: "./api", cmd: "git status"}, ...] +Plugin (meta-git): "here's the plan" → [{dir: "./api", argv: ["git", "status"]}, ...] │ ▼ Loop Engine: execute plan → aggregate output → report results @@ -268,7 +268,7 @@ This enables impact analysis ("what breaks if I change shared-utils?"), topologi | Command | Description | |---------|-------------| -| `meta exec ` | Run any command across all repositories | +| `meta exec -- ` | Run any command across all repositories (no shell; `sh -c '...'` for one) | | `meta git status` | Git status for all repos | | `meta git pull` | Pull latest changes | | `meta git push` | Push commits | @@ -310,10 +310,16 @@ meta exec npm test --tag frontend,shared ### By Directory ```bash -meta git status --include api-service,web-app -meta exec npm install --exclude legacy-app +meta --include api-service,web-app git status +meta --exclude legacy-app exec -- npm install ``` +A value names a whole repo: its `.meta` name or its path from the workspace root (`.` for the root repo), never part of a path, so `api` does not select `api-legacy`. A value that names no repo is an error, so a typo never runs a command in a repo you meant to skip. Inside a worktree set, a repo is named by its alias (its path in the set). A value starting with `./` is a path only; use it when a name is ambiguous (a value that names several repos is an error too). + +### Arguments + +Meta runs every command as a program with its arguments, never through a shell. Each argument meta receives reaches the program unchanged, so quotes, spaces, `$()`, `;`, globs and `%` stay literal (`meta git log --format='%h %s'` works, and text pasted into a commit message can't run commands). Your own shell still parses the line before meta runs, so `"$(...)"` in double quotes runs there: pass untrusted text in single quotes. When you want a shell, ask for one: `meta exec -- sh -c 'npm ci && npm test'`. `meta git status`, `commit`, `clone`, `update`, `snapshot` and `worktree` are meta's own commands with their own options; for git's native behavior, `meta exec -- git ...`. Meta still reads its own `--json`, `--verbose`, `--silent`, `--recursive`, `--strict` and `--primary` after a plugin command (`meta git status --json`); put arguments that look like those after `--` (`meta git add -- --json`). + ### Recursive Processing ```bash @@ -375,7 +381,7 @@ meta-myplugin --meta-plugin-info # Meta asks: "Execute this command" echo '{"command":"myplugin run","args":[],"projects":[...]}' | meta-myplugin --meta-plugin-exec -# → {"plan": {"commands": [{"dir": "./repo1", "cmd": "..."}]}} +# → {"plan": {"commands": [{"dir": "./repo1", "argv": ["make", "lint"]}]}} ``` See [docs/plugin_development.md](docs/plugin_development.md) for the full guide. @@ -470,8 +476,8 @@ Arguments: Options: -c, --config Path to .meta config file -t, --tag Filter by tag(s), comma-separated - -i, --include Include only these directories - -e, --exclude Exclude these directories + -i, --include Only these repos (.meta name or path from the root) + -e, --exclude Skip these repos (.meta name or path from the root) -r, --recursive Process nested meta repos --depth Max recursion depth --json Output in JSON format diff --git a/claude-plugin/skills/meta-exec/SKILL.md b/claude-plugin/skills/meta-exec/SKILL.md index 586a6116..93cbc41b 100644 --- a/claude-plugin/skills/meta-exec/SKILL.md +++ b/claude-plugin/skills/meta-exec/SKILL.md @@ -15,13 +15,19 @@ Execute any command in the root repo and every project at this meta level (add ` # Run 'make build' in every repo meta exec -- make build -# Run any shell command +# Any program with its arguments meta exec -- ls -la - -# Commands with arguments meta exec -- npm install --save-dev typescript ``` +Each argument meta receives reaches the program unchanged: meta runs the program directly, with no shell in between. Quotes, spaces, `$()`, `;`, `|`, `&&`, globs and `%` in an argument stay literal, so text from an issue, a commit message or a file name can't run commands once meta has it. Your own shell still parses the command line before meta runs (`"$(...)"` in double quotes runs there), so pass untrusted text in single quotes or as a separate argv element (as the MCP tools take it). When you want a shell (pipes, `&&`, redirects, globs), ask for one: + +```bash +meta exec -- sh -c 'npm ci && npm test' +``` + +A `.looprc` alias for the program is expanded into words (POSIX quoting rules, nothing expanded or run). On Windows meta does not wrap commands in `cmd /c` either. Batch files such as `npm.cmd` need their extension (`meta exec -- npm.cmd install`); Windows runs those through `cmd.exe`, and Rust escapes their arguments for it and refuses any it cannot pass safely. + The `--` separates meta options from the command to execute. The `--` is optional unless your command starts with `-`. ```bash @@ -52,16 +58,17 @@ Parallel mode: ## Filtering Options -Control which repos run the command. These options come from `loop`: +Control which repos run the command: ```bash -# Only directories whose path contains one of these (substring match) +# Only these repos: each value is a repo's .meta name or its path from the workspace root meta --include api,worker git status +meta --include libs/core,. git status # `.` is the root repo -# Skip directories whose path contains one of these +# Skip these repos meta --exclude legacy-service git push -# Filter by tag (meta-specific, applied before loop filtering) +# Filter by tag (applied before --include/--exclude) meta --tag backend exec -- make deploy # Combine: tag filter + directory filter @@ -70,10 +77,10 @@ meta --tag backend --include api git status **Filter precedence:** 1. `--tag` filters projects by tag (meta level) -2. `--include` limits to specific directories (loop level) -3. `--exclude` removes directories (loop level) +2. `--include` limits to the named repos +3. `--exclude` removes the named repos -Include/exclude match substrings of directory paths, so `api` also matches `api-tests`. The meta root repo stays included even when it doesn't match a tag. +A value names a whole repo, never part of a path: `api` does not match `api-tests`. A value that names no repo is an error, so a typo never runs a command in the repo you meant to skip. Inside a worktree set, a repo is named by its alias (its path in the set). A value starting with `./` is a path only; use it when a name is ambiguous (a value that names several repos is an error too). The meta root repo stays included even when it doesn't match a tag. ## Dry Run @@ -129,8 +136,8 @@ meta --silent exec -- npm install |--------|-------------| | `--parallel` | Run commands concurrently (the default) | | `--sequential` | Run one repo at a time | -| `--include ` | Only directories whose path contains these | -| `--exclude ` | Skip directories whose path contains these | +| `--include ` | Only these repos (`.meta` name or path from the root) | +| `--exclude ` | Skip these repos (`.meta` name or path from the root) | | `--tag ` | Filter by project tag(s) | | `--dry-run` | Preview without executing | | `--json` | Structured JSON output | @@ -161,8 +168,8 @@ meta --exclude large-monorepo exec -- cargo update ### Find Files Across Repos ```bash -# Quote the whole command: meta joins its arguments with spaces for the shell -meta exec -- 'find . -name "*.rs" -type f' | head -20 +# Arguments go to find as typed: "*.rs" is find's pattern, not a shell glob +meta exec -- find . -name '*.rs' -type f | head -20 ``` ### Clean Build Artifacts @@ -175,7 +182,7 @@ meta exec -- rm -rf node_modules dist | Use `meta exec` | Use Plugin (e.g., `meta git`) | |-----------------|-------------------------------| -| Generic shell commands | Git operations | +| 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 | diff --git a/claude-plugin/skills/meta-git/SKILL.md b/claude-plugin/skills/meta-git/SKILL.md index 1a0098bd..656fc641 100644 --- a/claude-plugin/skills/meta-git/SKILL.md +++ b/claude-plugin/skills/meta-git/SKILL.md @@ -19,6 +19,8 @@ meta git status # Shows status for every repo at once meta git commit -m "feat: update" # Commits in every repo with staged changes ``` +Any other git subcommand passes through to git in each repo. Meta passes the arguments it receives to git unchanged, with no shell in between: `meta git log --format='%h %s'` and a commit message containing `$(...)` or `;` are passed as-is. Your own shell still expands `$(...)` inside double quotes before meta runs, so put untrusted text in single quotes. + ## Cloning a Meta Repo ```bash @@ -87,13 +89,13 @@ meta git log --oneline -5 ## Filtering -Target specific repos. With `--tag`, the meta root repo stays included even when it isn't tagged; `--include`/`--exclude` match substrings of directory paths and can drop the root. +Target specific repos. With `--tag`, the meta root repo stays included even when it isn't tagged; `--include`/`--exclude` take whole repos (a `.meta` name or the path from the workspace root, `.` for the root), never part of a path, and can drop the root. A value that names no repo is an error. ```bash # By tag meta --tag backend git status -# By directory (substring match: `api` also matches `api-tests`) +# By repo: .meta name or path from the root (`api` does not match `api-tests`) meta --include api,web git push # Exclude repos @@ -139,7 +141,7 @@ When the meta MCP server is available, these tools provide structured JSON outpu ## Efficiency Tips -- **Targeted commits**: `meta --include repo1,repo2 git commit -m "msg"` commits only in repos whose path matches +- **Targeted commits**: `meta --include repo1,repo2 git commit -m "msg"` commits only in the named repos - **Tag-based push**: `meta --tag backend git push` pushes tagged repos (and the root) - **Per-repo messages**: Use `meta_git_multi_commit` when changes in different repos need different commit messages - **One-call status**: `meta git status` replaces N individual `cd && git status` sequences diff --git a/claude-plugin/skills/meta-safety/SKILL.md b/claude-plugin/skills/meta-safety/SKILL.md index ca036710..d584efbd 100644 --- a/claude-plugin/skills/meta-safety/SKILL.md +++ b/claude-plugin/skills/meta-safety/SKILL.md @@ -15,7 +15,7 @@ Multi-repo workspaces are powerful but require awareness. Meta gives you precisi ## Precision Operations -Instead of cd-ing into repos one by one, use meta flags to target what you need. Include/exclude match substrings of directory paths; `--tag` keeps the meta root even when it isn't tagged: +Instead of cd-ing into repos one by one, use meta flags to target what you need. Include/exclude take whole repos (a `.meta` name or the path from the workspace root), never part of a path, and a value that names no repo is an error; `--tag` keeps the meta root even when it isn't tagged: ```bash # Target specific repos @@ -42,7 +42,7 @@ When modifying a repo that other repos depend on: ## Efficient Commits ```bash -# Commit only in repos whose path contains repo1 or repo2 (substring match) +# Commit only in repos repo1 and repo2 (.meta name or path from the root) meta --include repo1,repo2 git commit -m "feat: update shared API" # Push tagged repos (and the root) diff --git a/claude-plugin/skills/meta-workspace/SKILL.md b/claude-plugin/skills/meta-workspace/SKILL.md index fcb46172..859ca35c 100644 --- a/claude-plugin/skills/meta-workspace/SKILL.md +++ b/claude-plugin/skills/meta-workspace/SKILL.md @@ -115,7 +115,7 @@ When the meta MCP server is available, these tools provide structured JSON for p ## Efficiency Tips - **One command, all repos**: `meta git status` replaces N individual `cd && git status` calls -- **Targeted operations**: `meta --include repo1,repo2 exec -- cmd` operates on only the repos whose path matches +- **Targeted operations**: `meta --include repo1,repo2 exec -- cmd` operates on only the named repos (`.meta` name or path from the workspace root) - **Tag-based filtering**: `meta --tag backend exec -- cargo test` scopes to tagged repos - **Dependency awareness**: `meta_analyze_impact ` shows who depends on a repo before you modify it — prevents cascading fix-up commits - **Session start**: Always run `meta project list --recursive --json` first to get the workspace map diff --git a/claude-plugin/skills/meta-worktree/SKILL.md b/claude-plugin/skills/meta-worktree/SKILL.md index c1f9b102..bc946be5 100644 --- a/claude-plugin/skills/meta-worktree/SKILL.md +++ b/claude-plugin/skills/meta-worktree/SKILL.md @@ -127,9 +127,11 @@ meta git worktree exec auth-fix --exclude legacy -- npm test meta git worktree exec auth-fix --parallel -- cargo build ``` -`--include`/`--exclude` match text anywhere in each repo's absolute path, and -every path contains `.worktrees//`: pick filter text that isn't in the set -name (`--include auth` in set `auth-fix` matches every repo). +`--include`/`--exclude` name whole repos by alias, their path in the set +(`.` for the root repo), never part of a path. A value that names no repo in +the set is an error. They go after the set name: `meta --include x git +worktree ...` is refused. The command's arguments reach it as +typed, with no shell; use `-- sh -c '...'` when you want one. ## Context Detection @@ -229,7 +231,7 @@ it up with `remove`. | Option | Description | |--------|-------------| -| `--include ` | Only repos whose path contains it (comma-separated) | -| `--exclude ` | Skip repos whose path contains it (comma-separated) | +| `--include ` | Only these repos, by alias (comma-separated) | +| `--exclude ` | Skip these repos, by alias (comma-separated) | | `--parallel` | Run concurrently | | `--ephemeral` | Create, run, then remove (takes `--repo`/`--all`, `--branch`, `--from-pr`, `--meta`, a commit-ish) | diff --git a/docs/advanced_usage.md b/docs/advanced_usage.md index 03f32d81..83075c9b 100644 --- a/docs/advanced_usage.md +++ b/docs/advanced_usage.md @@ -210,7 +210,7 @@ Execute commands with automatic rollback on failure: ```bash # Via MCP tool -meta_batch_execute --command "npm test" --atomic true +meta_batch_execute {"command": ["npm", "test"], "atomic": true} ``` If any repo fails, all repos are rolled back to pre-execution state. @@ -232,27 +232,27 @@ meta exec --tag frontend,shared -- npm test ### By Directory ```bash -# Include only specific directories (plugin commands) -meta git status --include api-service,web-app +# Only these repos +meta --include api-service,web-app git status -# Exclude directories - use exec for non-plugin commands -meta exec --exclude legacy-app -- npm install +# Skip a repo +meta --exclude legacy-app exec -- npm install ``` +A value names a whole repo: its `.meta` name or its path from the workspace root (`.` for the root repo), never part of a path, so `api` does not select `api-legacy`. A value that names no repo is an error, so a typo never runs a command in a repo you meant to skip. Inside a worktree set, a repo is named by its alias (its path in the set). A value starting with `./` is a path only; use it when a name is ambiguous (a value that names several repos is an error too). + ### Combined Filtering ```bash -# Tag filter + directory filter -meta --tag backend git status --include api - -# For non-plugin commands, use exec -meta exec --tag backend --include api -- cargo test +# Tag filter + repo filter +meta --tag backend --include api git status +meta --tag backend --include api exec -- cargo test ``` **Filter precedence:** 1. `--tag` filters by project tags (meta level) -2. `--include` limits to specific directories (loop level) -3. `--exclude` removes directories (loop level) +2. `--include` limits to the named repos +3. `--exclude` removes the named repos --- diff --git a/docs/agent_workflows.md b/docs/agent_workflows.md index 793ef4d2..97da6ea6 100644 --- a/docs/agent_workflows.md +++ b/docs/agent_workflows.md @@ -120,7 +120,7 @@ When building projects with dependencies: // Build with dependencies {"name": "meta_batch_execute", "arguments": { - "command": "npm run build", + "command": ["npm", "run", "build"], "atomic": true }} ``` @@ -157,7 +157,7 @@ For operations that must succeed together: ```json {"name": "meta_batch_execute", "arguments": { - "command": "npm test && npm run build", + "command": ["sh", "-c", "npm test && npm run build"], "tag": "frontend", "atomic": true }} @@ -212,7 +212,7 @@ Don't operate on all repos when you mean a subset: ### 4. Use Atomic Mode for Critical Operations ```json {"name": "meta_batch_execute", "arguments": { - "command": "npm publish", + "command": ["npm", "publish"], "atomic": true }} ``` diff --git a/docs/claude_code_skills.md b/docs/claude_code_skills.md index 0cb68551..3144d6a8 100644 --- a/docs/claude_code_skills.md +++ b/docs/claude_code_skills.md @@ -119,7 +119,7 @@ The skill text lives in `meta_cli/.claude/skills/` and is embedded in the `meta` **Key concepts covered:** - Session start: `meta project list --recursive --json`, `meta git status` -- Filtering with `--include`/`--exclude` (substring matches) and `--tag` +- Filtering with `--include`/`--exclude` (whole repos: `.meta` name or path from the root) and `--tag` - Dependency order via the MCP tool `meta_execution_order` - Global and worktree `--strict` mode diff --git a/docs/faq_troubleshooting.md b/docs/faq_troubleshooting.md index 854704f1..929b88f5 100644 --- a/docs/faq_troubleshooting.md +++ b/docs/faq_troubleshooting.md @@ -123,11 +123,11 @@ projects: # By tag (plugin commands) meta --tag backend git status -# By directory name (plugin commands) -meta git status --include api,web +# By repo: its .meta name or its path from the workspace root +meta --include api,web git status -# Exclude specific repos (use exec for non-plugin commands) -meta exec --exclude legacy-service -- npm install +# Exclude specific repos +meta --exclude legacy-service exec -- npm install ``` ### Q: Commands are running slowly. How can I speed them up? diff --git a/docs/loop.md b/docs/loop.md index a3dc5baa..34d9021a 100644 --- a/docs/loop.md +++ b/docs/loop.md @@ -26,7 +26,7 @@ ## Key Features -- Run any shell command in multiple directories in parallel +- Run any command in multiple directories in parallel (as a program with arguments, never through a shell; use `sh -c '...'` when you want one) - Defaults to all child repositories, with flexible inclusion/exclusion via CLI or config - Supports `.looprc` for persistent configuration - Verbose and silent output modes diff --git a/docs/mcp_server.md b/docs/mcp_server.md index 6e4407b6..b9bba179 100644 --- a/docs/mcp_server.md +++ b/docs/mcp_server.md @@ -53,13 +53,15 @@ Lists all projects in the meta repository. #### meta_exec Execute a command across all projects. +Runs `meta exec` with the given program and arguments. + **Parameters:** -- `command` (required): Command to execute +- `command` (required): The program and its arguments, one per item. They reach the program as given, with no shell; for a shell, ask for one: `["sh", "-c", "..."]` - `tag` (optional): Filter by tag **Example:** ```json -{"name": "meta_exec", "arguments": {"command": "npm install", "tag": "frontend"}} +{"name": "meta_exec", "arguments": {"command": ["git", "log", "--format=%h %s", "-1"], "tag": "frontend"}} ``` #### meta_get_config @@ -121,7 +123,7 @@ Get branch information (current, tracking, ahead/behind). Stage files across repositories. **Parameters:** -- `files` (optional): Files to stage (default: ".") +- `files` (optional): Paths to stage, one per item, passed to git as given (default: `["."]`) - `tag` (optional): Filter by tag #### meta_git_commit @@ -331,7 +333,7 @@ Restore workspace to a previous snapshot. Execute command across repos with optional atomic mode (auto-rollback on failure). **Parameters:** -- `command` (required): Command to execute +- `command` (required): The program and its arguments to run in each project, one per item, with no shell - `tag` (optional): Filter by tag - `atomic` (optional): Enable atomic mode with rollback on failure @@ -340,7 +342,7 @@ Execute command across repos with optional atomic mode (auto-rollback on failure { "name": "meta_batch_execute", "arguments": { - "command": "npm test", + "command": ["npm", "test"], "tag": "frontend", "atomic": true } diff --git a/docs/plugin_development.md b/docs/plugin_development.md index e6da7b8a..a4dac595 100644 --- a/docs/plugin_development.md +++ b/docs/plugin_development.md @@ -144,32 +144,18 @@ echo '' | meta-docker --meta-plugin-exec } ``` -**Response Format:** +**Response Format:** a plugin prints text (meta shows it as is), or an execution plan that meta runs in each directory: ```json { - "success": true, - "results": [ - { - "project": "api", - "success": true, - "output": "Successfully built image api:latest", - "exit_code": 0 - }, - { - "project": "web", - "success": false, - "output": "", - "error": "Dockerfile not found", - "exit_code": 1 - } - ], - "summary": { - "total": 2, - "succeeded": 1, - "failed": 1 + "plan": { + "commands": [ + {"dir": "/ws/api", "argv": ["docker", "build", "-t", "api:latest", "."]} + ], + "parallel": true } } ``` +Each `argv` is a program and its arguments. Meta runs it as given, with no shell, so the plugin needs no quoting; a plugin that needs a shell plans `["sh", "-c", "..."]`. `projects` in the request lists the repos `--include`/`--exclude` selected; a plugin that finds repos itself must refuse those filters rather than ignore them. ### Error Response diff --git a/tests/exec.bats b/tests/exec.bats index 89940386..d9238f6d 100644 --- a/tests/exec.bats +++ b/tests/exec.bats @@ -14,7 +14,8 @@ setup() { cargo build --workspace --quiet fi - TEST_DIR="$(mktemp -d)" + # The physical path, as pwd prints it (macOS temp dirs sit behind a symlink) + TEST_DIR="$(cd "$(mktemp -d)" && pwd -P)" mkdir -p "$TEST_DIR/.meta/plugins" cp "$META_GIT_BIN" "$TEST_DIR/.meta/plugins/meta-git" chmod +x "$TEST_DIR/.meta/plugins/meta-git" @@ -105,11 +106,11 @@ teardown() { [[ "$output" != *"worker"* ]] } -@test "meta exec --include with nonexistent dir runs nothing" { +@test "meta exec --include with nonexistent dir is an error and runs nothing" { run "$META_BIN" --include nonexistent exec -- echo hello - [ "$status" -eq 0 ] - # Should not produce "hello" output since no dirs match - [[ "$output" != *"hello"* ]] || [[ "$output" == *"No directories"* ]] || [[ "$output" == *"0"* ]] + [ "$status" -ne 0 ] + [[ "$output" == *"--include 'nonexistent' names none of the repos"* ]] + [[ "$output" != *"hello"* ]] } # ============ --exclude ============ @@ -464,3 +465,197 @@ SCRIPT [ "$status" -eq 0 ] [[ "$output" == *"hello"* ]] } + +# ============ Arguments reach the command as typed, with no shell ============ + +@test "meta exec passes each argument as given, never through a shell" { + run "$META_BIN" --include api exec -- printf '[%s]\n' 'one arg' '$(touch PWNED)' 'a;touch PWNED' '*' "it's" + [ "$status" -eq 0 ] + [[ "$output" == *"[one arg]"* ]] + [[ "$output" == *'[$(touch PWNED)]'* ]] + [[ "$output" == *"[a;touch PWNED]"* ]] + [[ "$output" == *"[*]"* ]] + [[ "$output" == *"[it's]"* ]] + [ -z "$(find "$TEST_DIR" -name PWNED)" ] +} + +@test "meta exec runs a shell only when asked for one" { + run "$META_BIN" --include api exec -- sh -c 'echo first && echo second' + [ "$status" -eq 0 ] + [[ "$output" == *"first"* ]] + [[ "$output" == *"second"* ]] +} + +@test "meta exec --dry-run shows the command quoted as typed" { + run "$META_BIN" --dry-run --include api exec -- touch 'one arg' + [ "$status" -eq 0 ] + [[ "$output" == *"touch 'one arg'"* ]] + [ ! -e "$TEST_DIR/api/one arg" ] +} + +@test "meta exec of a missing program fails cleanly" { + run "$META_BIN" --include api exec -- meta-no-such-program + [ "$status" -ne 0 ] + [[ "$output" == *"meta-no-such-program"* ]] + [[ "$output" != *"panicked"* ]] +} + +# ============ --include / --exclude name whole repos ============ + +add_api_legacy() { + mkdir -p "$TEST_DIR/api-legacy" "$TEST_DIR/libs/core" + cat > "$TEST_DIR/.meta.json" <<'EOF' +{ + "projects": { + "api": "git@github.com:org/api.git", + "api-legacy": "git@github.com:org/api-legacy.git", + "worker": "git@github.com:org/worker.git", + "core": { "repo": "git@github.com:org/core.git", "path": "libs/core" } + } +} +EOF +} + +@test "--include api does not select api-legacy" { + add_api_legacy + run "$META_BIN" --include api exec -- pwd + [ "$status" -eq 0 ] + [[ "$output" == *"$TEST_DIR/api"* ]] + [[ "$output" != *"api-legacy"* ]] + [[ "$output" != *"worker"* ]] +} + +@test "--exclude api keeps api-legacy" { + add_api_legacy + run "$META_BIN" --exclude api exec -- pwd + [ "$status" -eq 0 ] + [[ "$output" == *"$TEST_DIR/api-legacy"* ]] + [[ "$output" == *"$TEST_DIR/worker"* ]] + [ "$(grep -c "^$TEST_DIR/api\$" <<<"$output")" -eq 0 ] +} + +@test "--include a part of a path names none of the repos" { + add_api_legacy + # every absolute path here contains "t" and "a" + for value in a t ap libs core/x; do + run "$META_BIN" --include "$value" exec -- pwd + [ "$status" -ne 0 ] || { echo "--include $value: $output"; false; } + [[ "$output" == *"names none of the repos"* ]] + done +} + +@test "--include takes a repo's .meta name or its path from the root" { + add_api_legacy + for value in core libs/core ./libs/core/; do + run "$META_BIN" --include "$value" exec -- pwd + [ "$status" -eq 0 ] + [[ "$output" == *"$TEST_DIR/libs/core"* ]] + [[ "$output" != *"api"* ]] + done + run "$META_BIN" --include . exec -- pwd + [ "$status" -eq 0 ] + [ "$(grep -c "^$TEST_DIR\$" <<<"$output")" -eq 1 ] + [[ "$output" != *"$TEST_DIR/"* ]] +} + +@test "--exclude with a typo is an error, not a no-op" { + add_api_legacy + run "$META_BIN" --exclude apii exec -- touch ran + [ "$status" -ne 0 ] + [[ "$output" == *"--exclude 'apii' names none of the repos"* ]] + [ -z "$(find "$TEST_DIR" -name ran)" ] +} + +@test "--include selects plugin commands the same way" { + add_api_legacy + run "$META_BIN" --dry-run --include api git reset --hard + [ "$status" -eq 0 ] + [ "$(grep -c "Would execute" <<<"$output")" -eq 1 ] + [[ "$output" == *"$TEST_DIR/api"* ]] + [[ "$output" != *"api-legacy"* ]] +} + +@test "--include takes names from the config chosen with --config" { + add_api_legacy + cat > "$TEST_DIR/alt.json" <<'EOF' +{ "projects": { "core-lib": { "repo": "git@github.com:org/core.git", "path": "./libs/core/" } } } +EOF + run "$META_BIN" --config alt.json --include core-lib exec -- pwd + [ "$status" -eq 0 ] + [[ "$output" == *"$TEST_DIR/libs/core"* ]] + [[ "$output" != *"api"* ]] + run "$META_BIN" --config alt.json --include core exec -- pwd + [ "$status" -ne 0 ] + [[ "$output" == *"names none of the repos"* ]] +} + +@test "--recursive with --config walks the chosen config" { + add_api_legacy + mkdir -p "$TEST_DIR/staging/api" + cat > "$TEST_DIR/alt.json" <<'EOF' +{ "projects": { "staging-api": { "repo": "git@github.com:org/api.git", "path": "staging/api" } } } +EOF + run "$META_BIN" --config alt.json --recursive --include staging-api exec -- pwd + [ "$status" -eq 0 ] + [[ "$output" == *"$TEST_DIR/staging/api"* ]] + run "$META_BIN" --config alt.json --recursive exec -- pwd + [ "$status" -eq 0 ] + [[ "$output" == *"$TEST_DIR/staging/api"* ]] + [[ "$output" != *"api-legacy"* ]] +} + +@test "a value that is one repo's path and another's name is an error" { + mkdir -p "$TEST_DIR/web" "$TEST_DIR/frontend" + cat > "$TEST_DIR/.meta.json" <<'EOF' +{ "projects": { "web": { "repo": "git@github.com:org/web.git", "path": "frontend" }, "web-app": { "repo": "git@github.com:org/web-app.git", "path": "web" } } } +EOF + run "$META_BIN" --include web exec -- touch ran + [ "$status" -ne 0 ] + [[ "$output" == *"names the repo at web by path and the repo at frontend by .meta name"* ]] + [ -z "$(find "$TEST_DIR" -name ran)" ] +} + +@test "meta git clone refuses --include" { + run "$META_BIN" --include api git clone https://example.invalid/meta.git + [ "$status" -ne 0 ] + [[ "$output" == *"does not take --include/--exclude"* ]] +} + +@test "meta-mcp meta_exec runs its argv with no shell" { + run env PATH="$(dirname "$META_BIN"):$PATH" "$BATS_TEST_DIRNAME/../target/debug/meta-mcp" <<'EOF' +{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}} +{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"meta_exec","arguments":{"command":["printf","[%s]","one arg","$(touch PWNED5)"]}}} +EOF + [[ "$output" == *'[one arg][$(touch PWNED5)]'* ]] + [ -z "$(find "$TEST_DIR" -name PWNED5)" ] +} + +@test "--recursive with --config expands each nested meta repo once" { + mkdir -p "$TEST_DIR/child" "$TEST_DIR/legacy" + cat > "$TEST_DIR/.meta.json" <<'EOF' +{ "projects": { "child": "git@github.com:org/child.git", "legacy": "git@github.com:org/legacy.git" } } +EOF + cat > "$TEST_DIR/child/.meta.json" <<'EOF' +{ "projects": { "up": { "repo": "git@github.com:org/up.git", "path": ".." } } } +EOF + # pwd prints the physical path (macOS temp dirs sit behind a symlink) + legacy="$(cd "$TEST_DIR/legacy" && pwd -P)" + run "$META_BIN" --recursive exec -- pwd + [ "$status" -eq 0 ] + default_runs="$(grep -cx "$legacy" <<<"$output" || true)" + run "$META_BIN" --config .meta.json --recursive exec -- pwd + [ "$status" -eq 0 ] + [ "$(grep -cx "$legacy" <<<"$output" || true)" -eq "$default_runs" ] + [ "$default_runs" -eq 1 ] +} + +@test "--exclude skips every spelling of the same repo" { + mkdir -p "$TEST_DIR/api" "$TEST_DIR/libs" + cat > "$TEST_DIR/.meta.json" <<'EOF' +{ "projects": { "api": "git@github.com:org/api.git", "other": { "repo": "git@github.com:org/api.git", "path": "libs/../api" } } } +EOF + run "$META_BIN" --exclude api exec -- touch ran + [ "$status" -eq 0 ] + [ ! -e "$TEST_DIR/api/ran" ] + [ -e "$TEST_DIR/ran" ] +} diff --git a/tests/git.bats b/tests/git.bats index 1958a85b..ad2f55df 100644 --- a/tests/git.bats +++ b/tests/git.bats @@ -976,3 +976,85 @@ create_meta_bare_repo() { rm -rf "$GRANDCHILD_BARE" "$CHILD_BARE" "$ROOT_BARE" "$CLONE_TARGET" } + +# ============ Arguments reach git as typed, with no shell ============ + +@test "meta git passes \$(...) to git, never runs it" { + run "$META_BIN" git log --grep='$(touch PWNED1)' -1 + [ "$status" -eq 0 ] + [ -z "$(find "$TEST_DIR" -name PWNED1)" ] +} + +@test "meta git keeps a ; inside one argument" { + run "$META_BIN" --include frontend git tag -m 'release; touch PWNED2' v1 + [ "$status" -eq 0 ] + [ -z "$(find "$TEST_DIR" -name PWNED2)" ] + [ "$(git -C "$TEST_DIR/frontend" tag -l --format='%(contents:subject)' v1)" = "release; touch PWNED2" ] +} + +@test "meta git keeps an argument with spaces whole" { + run "$META_BIN" git log --format='%h %s' -1 + [ "$status" -eq 0 ] + [[ "$output" == *" Initial commit for frontend"* ]] + [[ "$output" != *"ambiguous argument"* ]] +} + +@test "meta git commit -m keeps the message as typed" { + echo change >> "$TEST_DIR/frontend/README.md" + git -C "$TEST_DIR/frontend" add README.md + run "$META_BIN" git commit -m "it's \$(touch PWNED3); done" + [ "$status" -eq 0 ] + [ -z "$(find "$TEST_DIR" -name PWNED3)" ] + [ "$(git -C "$TEST_DIR/frontend" log -1 --format=%s)" = "it's \$(touch PWNED3); done" ] +} + +@test "meta-mcp meta_git_add stages a hostile file name as one path" { + META_MCP_BIN="$BATS_TEST_DIRNAME/../target/debug/meta-mcp" + echo x > "$TEST_DIR/frontend/my file.txt; touch PWNED4" + echo x > "$TEST_DIR/frontend/unrelated.txt" + run env PATH="$(dirname "$META_BIN"):$PATH" "$META_MCP_BIN" <<'EOF' +{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}} +{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"meta_git_add","arguments":{"files":"my file.txt; touch PWNED4"}}} +{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"meta_git_add","arguments":{"files":[]}}} +{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"meta_git_add","arguments":{"files":["my file.txt; touch PWNED4"]}}} +EOF + [ -z "$(find "$TEST_DIR" -name PWNED4)" ] + [[ "$output" == *"'files' must be a list of strings"* ]] + [[ "$output" == *"'files' is empty"* ]] + [ "$(git -C "$TEST_DIR/frontend" diff --cached --name-only)" = "my file.txt; touch PWNED4" ] +} + +@test "meta git snapshot restore refuses --include instead of restoring every repo" { + "$META_BIN" git snapshot create filtered + run "$META_BIN" --include frontend git snapshot restore filtered --force + [ "$status" -ne 0 ] + [[ "$output" == *"does not take --include/--exclude"* ]] +} + +@test "meta git update refuses --include instead of cloning every missing repo" { + run "$META_BIN" --include frontend git update + [ "$status" -ne 0 ] + [[ "$output" == *"does not take --include/--exclude"* ]] +} + +@test "arguments after -- that look like meta flags reach git" { + echo x > "$TEST_DIR/frontend/--json" + run "$META_BIN" --include frontend git add -- --json + [ "$status" -eq 0 ] + [ "$(git -C "$TEST_DIR/frontend" diff --cached --name-only)" = "--json" ] +} + +@test "--help and -h after -- reach git as file names" { + META_MCP_BIN="$BATS_TEST_DIRNAME/../target/debug/meta-mcp" + echo x > "$TEST_DIR/frontend/--help" + echo x > "$TEST_DIR/frontend/-h" + run "$META_BIN" --include frontend git add -- --help + [ "$status" -eq 0 ] + [ "$(git -C "$TEST_DIR/frontend" diff --cached --name-only)" = "--help" ] + # meta_git_add runs in every repo; only frontend has the file + run env PATH="$(dirname "$META_BIN"):$PATH" "$META_MCP_BIN" <<'EOF' +{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}} +{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"meta_git_add","arguments":{"files":["-h"]}}} +EOF + [ "$(git -C "$TEST_DIR/frontend" diff --cached --name-only | LC_ALL=C sort | tr '\n' ' ')" = "--help -h " ] +} diff --git a/tests/worktree.bats b/tests/worktree.bats index 340d12b3..fb29f992 100644 --- a/tests/worktree.bats +++ b/tests/worktree.bats @@ -357,6 +357,18 @@ assert d['totals']['files_changed'] >= 1 [[ "$output" != *"exec-excl/frontend"* ]] } +@test "worktree exec --include names whole repos, never parts of paths" { + "$META_BIN" git worktree create exec-whole --repo backend --repo frontend + run "$META_BIN" git worktree exec exec-whole --include end -- touch ran + [ "$status" -ne 0 ] + [[ "$output" == *"--include 'end' names none of the repos"* ]] + [ -z "$(find .worktrees/exec-whole -name ran)" ] + run "$META_BIN" git worktree exec exec-whole --exclude ./backend/ -- pwd + [ "$status" -eq 0 ] + [[ "$output" == *"exec-whole/frontend"* ]] + [[ "$output" != *"exec-whole/backend"* ]] +} + @test "worktree exec --parallel runs concurrently" { "$META_BIN" git worktree create exec-par --repo backend --repo frontend run "$META_BIN" git worktree exec exec-par --parallel -- echo parallel-ok @@ -743,3 +755,27 @@ EOF [ "$status" -eq 0 ] [[ "$output" == *"list-nested"* ]] } + +@test "--include before git worktree is refused, not ignored" { + "$META_BIN" git worktree create global-filter --repo backend --repo frontend + run "$META_BIN" --exclude frontend git worktree exec global-filter -- touch ran + [ "$status" -ne 0 ] + [[ "$output" == *"does not take --include/--exclude before it"* ]] + [ -z "$(find .worktrees/global-filter -name ran)" ] +} + +@test "inside a worktree set, a filter typo is an error even when --tag selects nothing" { + "$META_BIN" git worktree create tagged --repo backend --repo frontend + cd .worktrees/tagged + run "$META_BIN" --tag nonexistent --exclude typo exec -- pwd + [ "$status" -ne 0 ] + [[ "$output" == *"--exclude 'typo' names none of the repos"* ]] +} + +@test "worktree exec --include works with a relative META_WORKTREES" { + "$META_BIN" git worktree create rel-root --repo backend --repo frontend + run env META_WORKTREES=.worktrees "$META_BIN" git worktree exec rel-root --include backend -- pwd + [ "$status" -eq 0 ] + [[ "$output" == *"rel-root/backend"* ]] + [[ "$output" != *"rel-root/frontend"* ]] +}