Skip to content

fix(dev-tooling): match hook commands exactly and read config like servers - #199

Merged
Martin Bens (SpiGAndromeda) merged 4 commits into
mainfrom
fix/dev-tooling-hook-command-matching
Oct 27, 2026
Merged

Martin Bens (SpiGAndromeda) merged 4 commits into
mainfrom
fix/dev-tooling-hook-command-matching

Conversation

@SpiGAndromeda

@SpiGAndromeda Martin Bens (SpiGAndromeda) commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

The PreToolUse hooks now read the MCP config the way the servers do, and match command names exactly in the forms the tools actually run. Commands that ran a tool through node, through composer run or behind a NAME=value prefix are now blocked, and a longer script name is no longer read as a shorter one. No tool or parameter was removed.

This PR carries no version bump.

  • The hooks read the config the way the servers do: the file named by MCP_PHP_TOOLING_CONFIG or MCP_JS_TOOLING_CONFIG, else every location deep-merged.
  • Before, the hooks read only .claude/.mcp-*.json or .mcp-*.json, whichever they found first.
  • A missing override file, or a discovered file that is empty or does not hold a JSON object, reads as no config, so enforcement stays on.
  • npm script names match exactly, also behind NAME=value prefixes, through npm run-script, and past npm flags that take no value or --prefix <dir> before run.
  • A tool binary run as node node_modules/.bin/<tool> is matched.
  • The PHP hook blocks composer cs, composer cs-fix and composer rector-fix. composer cs and composer ecs name only ecs_check, composer cs-fix and composer ecs-fix only ecs_fix, and composer rector-fix only rector_fix.
  • The PHP and Storefront hooks share one Composer pattern. It matches a script with or without run or run-script and after global options such as -d <dir> or --working-dir=<dir>.
  • A views/components path marks a command as Storefront in both JS hooks. npm exec --no -c "cd ../.. && eslint views/components" is now blocked by the Storefront hook with eslint_check instead of by the Administration hook.
  • The Storefront npm run lint and npm run lint-fix blocks name both the ESLint and the Stylelint tools.
  • The detector rows for stylelint:base, prettier:base, jest:base, eslint:app, eslint:components and stylelint:app are removed.
  • The Storefront rows for lint:js:app, lint:js:components, their :fix variants and lint:fix are removed.
  • The Shopware Administration and Storefront package.json files define none of the six names dropped from the shared rows, and the Storefront package defines none of its removed lint:js:* or lint:fix rows.
  • session-start.sh decides enforcement per language and leaves out the directive lines of a language that sets enforce_mcp_tools: false. The scopes section of that language stays.

Docs: plugins/dev-tooling/docs/mcp-enforcement.md documents the config reading, JS context detection and the matched command forms.

`parse_hook_input` strips heredoc bodies before any detector sees the command, so a line inside a script body such as `vendor/bin/phpunit` no longer reads as a command the hook must block, and an unterminated heredoc removes the rest of the input. The hooks read the MCP config the way the servers do, through `read_mcp_config` (the file named by `MCP_PHP_TOOLING_CONFIG` or `MCP_JS_TOOLING_CONFIG` when set, otherwise every location in the servers' order, deep-merged). A missing override file, or a file that does not hold a JSON object, reads as no config, so enforcement stays on. `lib/js_binary.sh` adds `runs_npm_script` and the shared `COMMAND_POSITION` and `NAME_END` patterns, so a script name matches exactly behind `NAME=value` assignments, npm flags before the script name and `run-script`, and a node_modules binary matches through `node`. The detectors follow the tools. `composer cs` and `cs-fix` replace the deprecated `ecs` alias, `composer rector-fix` is blocked, `npm run unit` replaces `jest:base`, and the Storefront `lint` and `lint-fix` scripts name both linters. The script names the tools no longer use (`stylelint:base`, `prettier:base`, `jest:base`, `eslint:app`, `eslint:components`, `stylelint:app`) are dropped from the detectors. `session-start.sh` decides enforcement per language and leaves out the directive lines and scopes section of an opted-out language. The prompts put each routing statement on its own line and name `js-storefront-tooling` for the ludtwig refusal.

Co-Authored-By: Claude <noreply@anthropic.com>
A Vitest run without a Storefront path, such as `npx vitest run` or `npm exec -- vitest run`, passed both JS hooks: the Storefront hook found no Storefront marker, and the Admin hook has no Vitest row. The Storefront hook now treats a Vitest binary run as Storefront context unless the command names `Administration`. Both hooks treat a `views/components` path as Storefront, so the Storefront hook blocks `npm exec --no -c "cd ../.. && eslint views/components"` with `eslint_check` and the Admin hook lets it pass.

The PHP hook matches a Composer script after global options, so `composer -d <dir> phpstan` and `composer --working-dir=<dir> run phpunit` are blocked.

Co-Authored-By: Claude <noreply@anthropic.com>
`mcp-enforcement.md` drops the script rows the hooks no longer match (`stylelint:base`, `prettier:base`, `jest:base`, `eslint:app`, `eslint:components`, `stylelint:app`) and lists `composer cs`, `cs-fix` and `rector-fix` with the one tool each routes to. It states how each JS hook claims a command, including `views/components` and Vitest runs, that heredoc bodies are not matched, how the hooks read the config, and which forms of Composer and npm script runs match.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

`parse_hook_input` no longer removes heredoc bodies. The stripping let commands run unblocked: a heredoc piped into `bash`, a delimiter with a `-` or `.` that cut off the rest of the command, a `<<` inside quotes, and an opener line continued with `\`. Every line of a command is matched again.

`read_mcp_config` checks each discovered file before the merge, so an empty file, or one that is not a JSON object, makes the hook read no config and keep enforcement on. Before, `jq -s` dropped an empty file and a lower-priority `enforce_mcp_tools: false` decided.

The Storefront hook no longer claims every Vitest run without a Storefront marker, because it routed a plugin's own Vitest suite to `vitest_run`, which refuses plugin scopes. `COMPOSER_RUN` in `lib/js_binary.sh` is the one Composer pattern for the PHP and Storefront hooks, so the Storefront hook now matches Composer scripts after global options such as `-d <dir>`. `composer ecs` names only `ecs_check` and `composer ecs-fix` only `ecs_fix`. `session-start.sh` reports a config's scopes even when its language sets `enforce_mcp_tools: false`.

Co-Authored-By: Claude <noreply@anthropic.com>
@SpiGAndromeda Martin Bens (SpiGAndromeda) changed the title fix(dev-tooling): match hook commands exactly and strip heredoc bodies fix(dev-tooling): match hook commands exactly and read config like servers Oct 27, 2026
@SpiGAndromeda
Martin Bens (SpiGAndromeda) merged commit a276558 into main Oct 27, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant