diff --git a/CHANGELOG.md b/CHANGELOG.md index 17aa681..098e8de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- `policy.yml` accepts the agents CLI's tracked instruction files: `.agent/instructions/`, `.agent/agents.json` and `.agent/agents.resolved`. Other `.agent/` paths, including private directories nested under the units, stay private execution files. The declaration and lock may name agent IDs such as `codex` without an allowed product term. + ## 0.1.0 - Add reusable `swift-package.yml` validation for formatting, compilers with default traits, additional trait sets on the first compiler, Linux, Apple platforms, DocC, terminal demo recording, and repository commands. diff --git a/scripts/check-policy.py b/scripts/check-policy.py index 63df3fc..f1b1ebf 100755 --- a/scripts/check-policy.py +++ b/scripts/check-policy.py @@ -23,7 +23,23 @@ OWNER_EMAIL = "10173746+showxu@users.noreply.github.com" PRIVATE_PATH = re.compile(r"/(?:Users|home)/[^/\s]+/|[.]workspace/") PRODUCT = re.compile(r"\b(ChatGPT|Codex|Cursor|Claude)\b", re.I) +PRODUCT_TERMS = frozenset({"chatgpt", "codex", "cursor", "claude"}) TOOL_ATTRIBUTION = re.compile(r"Generated" r" with|cursor\.com|anthropic\.com|claude\.ai|openai\.com", re.I) +# The agents CLI's committed declaration and lock name agent IDs such as codex; +# instruction units under .agent/instructions/ are tracked repository guidance. +AGENT_STATE_FILES = {".agent/agents.json", ".agent/agents.resolved"} +AGENT_INSTRUCTIONS = ".agent/instructions/" + + +def private_execution_file(file): + name = file.as_posix() + if name in AGENT_STATE_FILES: + return False + if name.startswith(AGENT_INSTRUCTIONS): + # Private state nested under the units stays private. + file = Path(name[len(AGENT_INSTRUCTIONS):]) + return (any(part in {".agent", ".workspace"} for part in file.parts) + or file.name == "PLANS.md" or file.name.endswith(".plan.md")) def content_findings(path, number, text, allow_terms): @@ -227,7 +243,7 @@ def check(event, event_name, *, allow_terms=frozenset(), dependabot_exception=Fa comparison, head, "--").split("\0") for path in filter(None, paths): file = Path(path) - if any(part in {".agent", ".workspace"} for part in file.parts) or file.name == "PLANS.md" or file.name.endswith(".plan.md"): + if private_execution_file(file): findings.append(f"{path}: private execution file") if git("--literal-pathspecs", "ls-tree", head, "--", path).startswith("160000 "): continue @@ -242,7 +258,8 @@ def check(event, event_name, *, allow_terms=frozenset(), dependabot_exception=Fa trailing_blank_start -= 1 patch = git("--literal-pathspecs", "diff", "--text", "--no-ext-diff", "--no-textconv", "--no-color", "--no-renames", "--unified=0", comparison, head, "--", path) - findings.extend(added_findings(patch, trailing_blank_start=trailing_blank_start, allow_terms=allow_terms)) + terms = allow_terms | PRODUCT_TERMS if file.as_posix() in AGENT_STATE_FILES else allow_terms + findings.extend(added_findings(patch, trailing_blank_start=trailing_blank_start, allow_terms=terms)) return findings diff --git a/tests/test_policy.py b/tests/test_policy.py index a8f9a64..45483a9 100644 --- a/tests/test_policy.py +++ b/tests/test_policy.py @@ -387,6 +387,34 @@ def test_attributes_cannot_hide_text_or_disable_whitespace_policy(self): for reason in ('whitespace', 'conflict marker', 'attribution', 'blank line at end'): self.assertTrue(any(reason in finding for finding in findings), reason) + def test_agents_instruction_files_are_tracked_and_other_agent_files_stay_private(self): + (self.root / '.agent/instructions/shared').mkdir(parents=True) + (self.root / '.agent/instructions/shared/route.md').write_text('---\ndescription: Route changes.\n---\n## Route\n') + (self.root / '.agent/agents.json').write_text('{"instructions": {"agents": ["claude-code", "codex"]}}\n') + (self.root / '.agent/agents.resolved').write_text('{"instructions": {"chatgpt": {}}}\n') + head = self.commit('docs: declare agent instructions') + self.assertEqual(policy.check(self.event(head, 'docs: declare agent instructions'), 'pull_request'), []) + (self.root / '.agent/plans').mkdir() + (self.root / '.agent/plans/task.md').write_text('plan\n') + (self.root / '.agent/cache').mkdir() + (self.root / '.agent/cache/state').write_text('state\n') + private = ('.agent/instructions/shared/.agent/cache/state', '.agent/instructions/.work' + 'space/notes.md', + '.agent/instructions/PLANS.md', 'plugin/.agent/agents.json', '.agent/agents.json.bak') + for path in private: + (self.root / path).parent.mkdir(parents=True, exist_ok=True) + (self.root / path).write_text('state\n') + head = self.commit('docs: add private state') + findings = policy.check(self.event(head, 'docs: add private state'), 'pull_request') + for path in ('.agent/plans/task.md', '.agent/cache/state', *private): + self.assertIn(f'{path}: private execution file', findings) + + def test_instruction_units_still_need_permitted_product_terms(self): + (self.root / '.agent/instructions').mkdir(parents=True) + (self.root / '.agent/instructions/guide.md').write_text('# Guide\n\nAsk Codex.\n') + head = self.commit('docs: add guide') + findings = policy.check(self.event(head, 'docs: add guide'), 'pull_request') + self.assertTrue(any('unapproved product/tool term: Codex' in finding for finding in findings)) + def test_binary_content_is_not_interpreted_as_text(self): (self.root / 'image').write_bytes(b'\x00\n<<<<<<< bytes\nGenerated-by: bytes \n') head = self.commit('test: add binary fixture')