From 508d7edaace5712b113e4478696d38114f8c9260 Mon Sep 17 00:00:00 2001 From: tobin Date: Fri, 8 May 2026 03:04:35 +0000 Subject: [PATCH 1/2] Gate hooks to Salesforce projects only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit guardrails.py (PreToolUse:Bash) and agent-validator.py (PostToolUse:Write|Edit) now check for Salesforce project markers (sfdx-project.json, force-app/, aiAuthoringBundles/) in cwd or an ancestor and exit immediately if none are found. Previously, when the plugin was installed globally, the PreToolUse hook ran on every Bash command in every session — including projects with no Salesforce relevance — before the is_sf_context() text-regex gate. This change makes the hooks complete no-ops outside Salesforce projects, so they do not observe tool I/O in unrelated work. Behavior inside Salesforce projects is unchanged. --- CHANGELOG.md | 1 + shared/hooks/scripts/agent-validator.py | 15 +++++++++++++++ shared/hooks/scripts/guardrails.py | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07cb821..c2dd05a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed +- `guardrails.py` and `agent-validator.py` hooks now exit immediately when the working directory is not a Salesforce project (no `sfdx-project.json`, `force-app/`, or `aiAuthoringBundles/` in cwd or any ancestor). When the plugin is installed globally, hooks no longer observe Bash commands or file edits in unrelated projects. Behavior inside Salesforce projects is unchanged. - `README.md` and `CLAUDE.md` updated to reflect the new plugin slug (`agentforce-adlc`) in install commands, skill namespace examples (`/agentforce-adlc:developing-agentforce`, etc.), and project-structure references. ### Added diff --git a/shared/hooks/scripts/agent-validator.py b/shared/hooks/scripts/agent-validator.py index e647275..a169f44 100644 --- a/shared/hooks/scripts/agent-validator.py +++ b/shared/hooks/scripts/agent-validator.py @@ -32,6 +32,18 @@ import sys from pathlib import Path +SF_PROJECT_MARKERS = ("sfdx-project.json", "force-app", "aiAuthoringBundles") + + +def is_salesforce_project(start: Path | None = None) -> bool: + """Return True if cwd or any ancestor contains a Salesforce project marker.""" + p = (start or Path.cwd()).resolve() + for d in (p, *p.parents): + if any((d / m).exists() for m in SF_PROJECT_MARKERS): + return True + return False + + try: from stdin_utils import read_stdin_safe except ImportError: @@ -475,6 +487,9 @@ def _auto_resolve_placeholder(self): def main(): """Main entry point for the PostToolUse hook.""" + if not is_salesforce_project(): + sys.exit(0) + input_data = read_stdin_safe(timeout_seconds=0.1) if not input_data: sys.exit(0) diff --git a/shared/hooks/scripts/guardrails.py b/shared/hooks/scripts/guardrails.py index bd41863..086c312 100644 --- a/shared/hooks/scripts/guardrails.py +++ b/shared/hooks/scripts/guardrails.py @@ -19,6 +19,22 @@ import sys from pathlib import Path +SF_PROJECT_MARKERS = ("sfdx-project.json", "force-app", "aiAuthoringBundles") + + +def is_salesforce_project(start: Path | None = None) -> bool: + """Return True if cwd or any ancestor contains a Salesforce project marker. + + Used as a project-relevance gate so this hook is a no-op when the plugin is + installed globally but the user is working in an unrelated project. + """ + p = (start or Path.cwd()).resolve() + for d in (p, *p.parents): + if any((d / m).exists() for m in SF_PROJECT_MARKERS): + return True + return False + + try: from stdin_utils import read_stdin_safe except ImportError: @@ -118,6 +134,10 @@ def is_sf_context(command: str) -> bool: def main(): + if not is_salesforce_project(): + print(json.dumps({"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "allow"}})) + sys.exit(0) + input_data = read_stdin_safe(timeout_seconds=0.1) if not input_data: print(json.dumps({"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "allow"}})) From f2773addcf95193f81e41eeaba91da30b6ac3e86 Mon Sep 17 00:00:00 2001 From: tobin Date: Mon, 11 May 2026 19:44:46 +0000 Subject: [PATCH 2/2] Re-trigger CI