fix: turns counter + hard safety enforcement (PreToolUse)#2
Merged
George-iam merged 5 commits intomainfrom Apr 4, 2026
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Turns counter:
incrementTurns()existed but was never called - turns was always 0. Added debouncedbumpTurn()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
.envnow correctly blocks/any/path/.env.Changed files
src/server.tsbumpTurn()debounce + call in all 11 tool handlerssrc/hooks/pre-tool-use.tssrc/cli.tssrc/storage/safety.tsstripQuoted()+matchesPattern()basename fixTest plan
ls -laallowed (empty output)npm publishblockedWrite .envblockedRead ~/.ssh/id_rsablockedWrite *.keyblockedgit push --forceblocked (live hook)git commit -m "text with denied pattern"allowed (no false positive)gh pr create --body "text with denied pattern"allowedecho test && git push origin mainblocked (chained command)