Skip to content

fix: turns counter + hard safety enforcement (PreToolUse)#2

Merged
George-iam merged 5 commits intomainfrom
feat/fix-turns-counter-20260404
Apr 4, 2026
Merged

fix: turns counter + hard safety enforcement (PreToolUse)#2
George-iam merged 5 commits intomainfrom
feat/fix-turns-counter-20260404

Conversation

@George-iam
Copy link
Copy Markdown
Contributor

Summary

  • Turns counter: incrementTurns() existed but was never called - turns was always 0. Added debounced bumpTurn() in MCP server (10s threshold) across all 11 tool handlers.

  • Hard safety enforcement: New PreToolUse hook blocks dangerous tool calls BEFORE execution using existing checkBash()/checkGit()/checkFilePath(). Registered in settings.json for Bash/Read/Write/Edit/NotebookEdit/Glob/Grep.

  • stripQuoted(): Safety checks now strip quoted content before matching, preventing false positives on commit messages, PR bodies, and echo arguments containing denied patterns as text.

  • matchesPattern() fix: Basename matching for patterns like .env now correctly blocks /any/path/.env.

Changed files

File Change
src/server.ts bumpTurn() debounce + call in all 11 tool handlers
src/hooks/pre-tool-use.ts New - hard safety enforcement hook
src/cli.ts Register PreToolUse hook + CLI routing
src/storage/safety.ts stripQuoted() + matchesPattern() basename fix

Test plan

  • ls -la allowed (empty output)
  • npm publish blocked
  • Write .env blocked
  • Read ~/.ssh/id_rsa blocked
  • Write *.key blocked
  • Real git push --force blocked (live hook)
  • git commit -m "text with denied pattern" allowed (no false positive)
  • gh pr create --body "text with denied pattern" allowed
  • echo test && git push origin main blocked (chained command)
  • Build passes

…se hook)

- Fix turns counter: incrementTurns() existed but was never called.
  Added debounced bumpTurn() in MCP server - counts conversation turns
  via 10s debounce across all 11 tool handlers.

- Add PreToolUse hook: hard safety enforcement that blocks dangerous
  tool calls BEFORE execution. Uses existing checkBash/checkGit/
  checkFilePath from storage/safety.ts. Registered in settings.json
  for Bash/Read/Write/Edit/NotebookEdit/Glob/Grep tools.

- Fix matchesPattern: basename matching for patterns like ".env"
  now correctly blocks "/any/path/.env", not just literal ".env".
splitCommandSegments() parser respects quotes so denied patterns
inside a PR body or echo argument are not treated as commands.
Only actual command segments starting with git trigger checkGit().
checkBash() and checkGit() now strip quoted content before matching
denied patterns. Commit messages, PR bodies, and echo arguments
containing denied patterns as text are no longer falsely blocked.
Add denied prefixes from v1 Essential Safety + AI Agent Guardrails:
- git push --force, git checkout -- ., git clean -f
- gh workflow run deploy-prod, gh release create
- npm publish, twine upload, docker push

Add denied filesystem paths:
- ~/.gnupg/*, .env, *.pem, *.key
Session auditor LLM now extracts handoff data (stopped_at, in_progress,
blockers, next, dirty_branches) from session worklog. SessionEnd hook
writes handoff.md via writeHandoff() so next session can read it via
handoffContext(). Closes the read-infrastructure/write-gap.
@George-iam George-iam merged commit 6ef07f9 into main Apr 4, 2026
@George-iam George-iam deleted the feat/fix-turns-counter-20260404 branch April 4, 2026 21:55
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