Skip to content

feat(plugin): add hooks.json, settings.json, extend validator (#447 #448 #451)#507

Open
Luis85 wants to merge 24 commits into
developfrom
feat/p1-plugin-foundations
Open

feat(plugin): add hooks.json, settings.json, extend validator (#447 #448 #451)#507
Luis85 wants to merge 24 commits into
developfrom
feat/p1-plugin-foundations

Conversation

@Luis85
Copy link
Copy Markdown
Owner

@Luis85 Luis85 commented May 13, 2026

Summary

Closes #447, #448, #451.

Three tightly-coupled P1 improvements that must land together to keep CI green.

#447 — Migrate enforcement hooks to hooks/hooks.json

Creates claude-plugin/specorator/hooks/hooks.json with both hooks from .claude/settings.json:

  • SessionStart: memory reminder (reads MEMORY.md on session start)
  • PreToolUse (Bash): branch guard — blocks commits to main/develop with sys.exit(2) (blocking semantics, not exit 1)

These are committed source files, not generated artifacts — no build-claude-plugin.ts changes needed.

#448 — Add default agent settings.json

Creates claude-plugin/specorator/settings.json with {"agent": "orchestrator"}, giving adopters an oriented first-run experience on plugin install.

#451 — Extend check:claude-plugin validator

Adds always-run structural checks for:

  • hooks/hooks.json presence and sys.exit(2) branch guard semantics
  • settings.json presence and agent field validity
  • $schema field in plugin.json (also updates buildExpectedManifest() to include it)
  • category field in .claude-plugin/marketplace.json ("category": "development")
  • Non-fatal warning for any SKILL.md missing description: frontmatter

Also updates test fixtures in tests/scripts/claude-plugin.test.ts to cover all new assertions.

Test plan

  • npm run build:claude-plugin green
  • npm run check:claude-plugin green
  • npm run verify green — all 40 checks pass, 445/445 tests passing

Generated by Claude Code

- Create claude-plugin/specorator/hooks/hooks.json with SessionStart and
  PreToolUse hooks (branch guard exits 2 for blocking — not 1)
- Create claude-plugin/specorator/settings.json with agent: orchestrator
- Add $schema to buildExpectedManifest() in build-claude-plugin.ts
- Add category: development to .claude-plugin/marketplace.json
- Extend check-claude-plugin.ts with checkPluginHooks(), checkPluginSettings(),
  $schema validation, category check, and warnMissingSkillDescriptions()
- Update test fixtures to include new required committed-source files

https://claude.ai/code/session_01PqUQc4Vg5vMB4eDpg9MmeM
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 679a919706

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread claude-plugin/specorator/hooks/hooks.json Outdated
Comment thread scripts/check-claude-plugin.ts Outdated
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ffbb3ff57

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/check-claude-plugin.ts Outdated
Comment thread claude-plugin/specorator/hooks/hooks.json Outdated
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c0f4f93a16

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/check-claude-plugin.ts Outdated
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5ce26a34fe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread claude-plugin/specorator/hooks/hooks.json Outdated
Comment thread scripts/check-claude-plugin.ts Outdated
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ada954bc97

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/scripts/claude-plugin.test.ts Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 482c22c001

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread claude-plugin/specorator/hooks/hooks.json Outdated
The previous implementation stripped quoted strings before scanning for
`git commit`, allowing `bash -c "git commit"` to bypass the guard.
Use the raw command string so all commit invocations are detected.

Addresses Codex P1 review thread on PR #507.
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be4ee51efa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/build-claude-plugin.ts Outdated
Comment thread scripts/check-claude-plugin.ts Outdated
Luis85 added 2 commits May 14, 2026 04:28
The SchemaStore slug for Claude Code plugins is
`claude-code-plugin-manifest`, not `claude-code-plugin`.
Using the wrong slug returns 404 and falls back to no-schema
validation, defeating the manifest validation check.

Fixes Codex P2 thread on PR #507.
checkPluginHooks() was stringifying the entire PreToolUse JSON and
searching for sys.exit(2) anywhere in it. This would produce a false
positive if any non-Bash hook happened to contain that string in a
non-command field.

Now extracts only the `command` strings from hooks whose `matcher`
is "Bash" and checks sys.exit(2) specifically in those. The
|| exit <N> swallowed-failure check is updated to use the same
filtered command list.

Fixes Codex P2 thread on PR #507.
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b20e94f1c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread claude-plugin/specorator/hooks/hooks.json Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 706028dff5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/check-claude-plugin.ts Outdated
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1773e6cc59

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread claude-plugin/specorator/hooks/hooks.json Outdated
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ee8fe76779

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread claude-plugin/specorator/hooks/hooks.json Outdated
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d0545803b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread claude-plugin/specorator/hooks/hooks.json Outdated
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 750c274193

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread claude-plugin/specorator/hooks/hooks.json Outdated
Comment thread claude-plugin/specorator/hooks/hooks.json Outdated
…d position

- Also check inside bash/sh -c '...' quoted args so commands like
  `bash -lc "git commit"` are caught on main/develop.
- Anchor the git-commit regex to command-position tokens (^, |, &, ;, (, {, \n)
  so benign commands like `echo git commit` no longer trigger false positives.
- quote-stripping is preserved for the direct-invocation path so
  `echo "git commit"` still produces no false positive.

https://claude.ai/code/session_011TPNgd7jBv3ySSyvaTifA1
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adc8cd577e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread claude-plugin/specorator/hooks/hooks.json Outdated
Extend the command-position anchor in is_gc so that git commit is also
detected when preceded by env-var assignments (FOO=bar) or known
passthrough wrappers (env, sudo, time, nice, nohup). The previous
pattern required git to appear immediately after ^, a pipe, semicolon,
etc., so `env FOO=1 git commit` was silently allowed on protected branches.

echo git commit (literal print) remains undetected because echo does not
match any of the allowed prefix patterns.
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…d; fix TS6 types

- Extend PreToolUse env-var bypass regex to cover lowercase env-var names
- Narrow warnMissingSkillDescriptions() scan from *.md to SKILL.md only
- Add "types":["node"] to tsconfig.scripts.json for TypeScript 6 compatibility

https://claude.ai/code/session_011TPNgd7jBv3ySSyvaTifA1
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f58c73421

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/check-claude-plugin.ts Outdated
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f58c73421

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread claude-plugin/specorator/hooks/hooks.json Outdated
…ard to catch then-clause commits

warnMissingSkillDescriptions() now warns for SKILL.md files that
have no frontmatter at all (not just files with frontmatter that
lack description:). The branch-guard is_gc regex now recognises
'then' as a command separator so 'if ...; then git commit ...; fi'
is correctly detected on protected branches.

https://claude.ai/code/session_011TPNgd7jBv3ySSyvaTifA1
Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Owner Author

Luis85 commented May 14, 2026

@codex review


Generated by Claude Code

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c6e254cc4a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"hooks": [
{
"type": "command",
"command": "python3 -c 'import sys,json,re,subprocess; d=json.load(sys.stdin); cmd=d.get(\"tool_input\",{}).get(\"command\",\"\"); dq=chr(34); sq=chr(39); strip_q=lambda s:re.sub(f\"{dq}[^{dq}]*{dq}|{sq}[^{sq}]*{sq}\",\"\",s); is_gc=lambda s:bool(re.search(r\"(?:^|[|;&({]|\\n|\\bthen\\b)\\s*(?:(?:[A-Za-z_]\\w*=[^\\s]*|env|sudo|time|nice|nohup)\\s+)*git\\b[^|&;]*\\scommit\\b\",strip_q(s))); parts=[cmd]+[m.group(1) or m.group(2) for m in re.finditer(r\"\\b(?:bash|sh)\\b[^|&;]*-[a-zA-Z]*c\\s+(?:\"+dq+r\"([^\"+dq+r\"]+)\"+dq+r\"|\"+sq+r\"([^\"+sq+r\"]+)\"+sq+r\")\",cmd)]; any(is_gc(p) for p in parts) or sys.exit(0); b=subprocess.run([\"git\",\"symbolic-ref\",\"--short\",\"HEAD\"],capture_output=True,text=True).stdout.strip(); b in(\"main\",\"develop\") and (print(\"[branch-guard] Commit on\",repr(b),\"blocked. Use a topic branch.\",file=sys.stderr) or sys.exit(2))'"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Detect commits prefixed by command in branch guard

The is_gc matcher only allows a small prefix list (env|sudo|time|nice|nohup plus assignments), so command git commit -m ... is treated as non-commit and exits 0 even on main/develop, which bypasses the protected-branch block. Fresh evidence: evaluating the committed regex against command git commit -m x returns no match, while plain git commit -m x matches. Because command is a valid shell prefix that still executes git commit, this leaves a direct path to commit on protected branches.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aaa0819f36

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"hooks": [
{
"type": "command",
"command": "python3 -c 'import sys,json,re,subprocess; d=json.load(sys.stdin); cmd=d.get(\"tool_input\",{}).get(\"command\",\"\"); dq=chr(34); sq=chr(39); strip_q=lambda s:re.sub(f\"{dq}[^{dq}]*{dq}|{sq}[^{sq}]*{sq}\",\"\",s); is_gc=lambda s:bool(re.search(r\"(?:^|[|;&({]|\\n|\\bthen\\b)\\s*(?:(?:[A-Za-z_]\\w*=[^\\s]*|env|sudo|time|nice|nohup)\\s+)*git\\b[^|&;]*\\scommit\\b\",strip_q(s))); parts=[cmd]+[m.group(1) or m.group(2) for m in re.finditer(r\"\\b(?:bash|sh)\\b[^|&;]*-[a-zA-Z]*c\\s+(?:\"+dq+r\"([^\"+dq+r\"]+)\"+dq+r\"|\"+sq+r\"([^\"+sq+r\"]+)\"+sq+r\")\",cmd)]; any(is_gc(p) for p in parts) or sys.exit(0); b=subprocess.run([\"git\",\"symbolic-ref\",\"--short\",\"HEAD\"],capture_output=True,text=True).stdout.strip(); b in(\"main\",\"develop\") and (print(\"[branch-guard] Commit on\",repr(b),\"blocked. Use a topic branch.\",file=sys.stderr) or sys.exit(2))'"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Detect option-bearing sudo/time prefixes in commit matcher

The branch-guard regex only allows bare sudo/time tokens before git commit, so valid Bash forms with flags (for example sudo -u root git commit -m x or time -p git commit -m x) are treated as non-commit commands. In this commit’s hook command, those inputs return exit 0 on a main branch, which bypasses the protected-branch commit block entirely.

Useful? React with 👍 / 👎.

"hooks": [
{
"type": "command",
"command": "python3 -c 'import sys,json,re,subprocess; d=json.load(sys.stdin); cmd=d.get(\"tool_input\",{}).get(\"command\",\"\"); dq=chr(34); sq=chr(39); strip_q=lambda s:re.sub(f\"{dq}[^{dq}]*{dq}|{sq}[^{sq}]*{sq}\",\"\",s); is_gc=lambda s:bool(re.search(r\"(?:^|[|;&({]|\\n|\\bthen\\b)\\s*(?:(?:[A-Za-z_]\\w*=[^\\s]*|env|sudo|time|nice|nohup)\\s+)*git\\b[^|&;]*\\scommit\\b\",strip_q(s))); parts=[cmd]+[m.group(1) or m.group(2) for m in re.finditer(r\"\\b(?:bash|sh)\\b[^|&;]*-[a-zA-Z]*c\\s+(?:\"+dq+r\"([^\"+dq+r\"]+)\"+dq+r\"|\"+sq+r\"([^\"+sq+r\"]+)\"+sq+r\")\",cmd)]; any(is_gc(p) for p in parts) or sys.exit(0); b=subprocess.run([\"git\",\"symbolic-ref\",\"--short\",\"HEAD\"],capture_output=True,text=True).stdout.strip(); b in(\"main\",\"develop\") and (print(\"[branch-guard] Commit on\",repr(b),\"blocked. Use a topic branch.\",file=sys.stderr) or sys.exit(2))'"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Match git commits inside do ... done shell blocks

The commit detector adds a special-case boundary for then but not for loop bodies, so constructs like for i in 1; do git commit -m x; done are not recognized as commit invocations. With the current hook command this path exits 0 on main/develop, allowing direct commits through a common shell control-flow form.

Useful? React with 👍 / 👎.

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.

improvement: migrate enforcement hooks to plugin package hooks/hooks.json

3 participants