From e5b33254a4b55d9660e1c7980c08925500c833f9 Mon Sep 17 00:00:00 2001 From: Mikhail Petrov Date: Wed, 20 May 2026 18:37:43 +0300 Subject: [PATCH 1/2] Add mutation boundary prompt guardrails --- .claude/agents/actor.md | 9 +++ .claude/skills/map-debug/SKILL.md | 10 +++ .claude/skills/map-efficient/SKILL.md | 10 +++ .claude/skills/map-fast/SKILL.md | 13 +++- .claude/skills/map-task/SKILL.md | 9 +++ .codex/AGENTS.md | 9 +++ .codex/skills/map-fast/SKILL.md | 7 ++ README.md | 1 + docs/ARCHITECTURE.md | 1 + docs/USAGE.md | 2 + docs/improvement-done.md | 10 +++ docs/improvement-loop-log.md | 15 ++++ docs/improvement-plan.md | 18 ----- docs/learned/architecture-patterns.md | 2 +- docs/learned/commands.md | 2 +- docs/learned/review-checks.md | 2 +- docs/learned/testing-strategies.md | 2 +- src/mapify_cli/templates/agents/actor.md | 9 +++ src/mapify_cli/templates/codex/AGENTS.md | 9 +++ .../templates/codex/skills/map-fast/SKILL.md | 7 ++ .../templates/skills/map-debug/SKILL.md | 10 +++ .../templates/skills/map-efficient/SKILL.md | 10 +++ .../templates/skills/map-fast/SKILL.md | 13 +++- .../templates/skills/map-task/SKILL.md | 9 +++ tests/test_skills.py | 72 +++++++++++++++++++ 25 files changed, 237 insertions(+), 24 deletions(-) diff --git a/.claude/agents/actor.md b/.claude/agents/actor.md index 856aa48f..09952862 100644 --- a/.claude/agents/actor.md +++ b/.claude/agents/actor.md @@ -38,6 +38,15 @@ You are a Protocol-Driven Code Execution System. Your objective: translate an AA **Operating constraints**: {{language}}, {{framework}}, scope limited to {{allowed_scope}}. +## Mutation Boundary Constraints + +Every write must stay inside the current subtask contract. + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the current contract explicitly names that dependency change. +- Do not refactor neighboring code unless the validation criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, stop and report it as a blocker/tradeoff instead of doing it silently. + **Template Variable Reference**: - `{{variable}}` (lowercase): Pre-filled by MAP framework Orchestrator before you see them - `{{variable}}` (in generated code): Preserve exactly for runtime substitution when instructed diff --git a/.claude/skills/map-debug/SKILL.md b/.claude/skills/map-debug/SKILL.md index 1b8a05d6..e90604f7 100644 --- a/.claude/skills/map-debug/SKILL.md +++ b/.claude/skills/map-debug/SKILL.md @@ -41,6 +41,15 @@ parallel_tool_policy: sequential_root_cause_first - Do not add extra agents beyond the documented debugging sequence; switch workflows only if the task stops being a debugging task. - Do not continue polishing after the original symptom is reproduced, fixed, and verified. +## Mutation Boundary Constraints + +These constraints apply to every fix subtask: + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the root cause evidence explicitly requires that dependency change. +- Do not refactor neighboring code unless the bug cannot be fixed and verified without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff instead of doing it silently. + ## Workflow Overview Debugging workflow focuses on analysis before implementation: @@ -144,6 +153,7 @@ Task( **Root Cause:** [identified root cause] Apply the fix directly with Edit/Write tools. +Do not edit unrelated files, add or upgrade dependencies, or refactor neighboring code unless the root cause evidence explicitly requires it. Report any required scope expansion as a blocker/tradeoff. JSON contract reference: [Actor Change Summary](../../references/map-json-output-contracts.md#actor-change-summary). diff --git a/.claude/skills/map-efficient/SKILL.md b/.claude/skills/map-efficient/SKILL.md index 5d6fdaa8..3b3fb29d 100644 --- a/.claude/skills/map-efficient/SKILL.md +++ b/.claude/skills/map-efficient/SKILL.md @@ -36,6 +36,15 @@ parallel_tool_policy: guarded_wave_only 5. After Monitor pass, record files changed in `step_state.json` for guard isolation. 6. Validate planning metadata before Actor starts: `expected_diff_size`, `concern_type`, `one_logical_step`, `split_rationale`, `concern_justification`, `coverage_map`, `hard_constraints`, `soft_constraints`, `validation_criteria`, `[AC-1]` bracket tags, and `tradeoff_rationale`. +## Mutation Boundary Constraints + +These constraints apply to every write-capable Actor or fix phase: + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the current subtask contract explicitly names that dependency change. +- Do not refactor neighboring code unless the current validation criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff and wait for the contract to change instead of doing it silently. + ## Intentional Agent Omissions /map-efficient does not run Evaluator or Reflector during normal execution. Monitor validates correctness directly, and learning is deferred to `/map-learn`. @@ -187,6 +196,7 @@ Task( Implement exactly the current subtask. Preserve validation_criteria, coverage_map tags, hard_constraints, and soft_constraints tradeoffs. Do not expand scope. +Do not edit unrelated files, add or upgrade dependencies, or refactor neighboring code unless the current subtask contract explicitly requires it. Report any required scope expansion as a blocker/tradeoff. Return files_changed, tests_run, validation_notes, and any blocker. diff --git a/.claude/skills/map-fast/SKILL.md b/.claude/skills/map-fast/SKILL.md index 9b6a14c4..636d4d55 100644 --- a/.claude/skills/map-fast/SKILL.md +++ b/.claude/skills/map-fast/SKILL.md @@ -33,8 +33,18 @@ parallel_tool_policy: sequential_by_default - Do not add discovery, design review, impact analysis, or learning steps to keep this workflow busy. - Do not refactor nearby code unless the selected small task cannot work without that exact change. +- Do not edit unrelated files or add, remove, or upgrade dependencies unless the task explicitly requires that exact change. - If the task becomes risky, multi-stage, or ambiguous, stop using `/map-fast` and switch to `/map-efficient` or `/map-plan` instead. +## Mutation Boundary Constraints + +These constraints apply to the Actor implementation prompt: + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the current task explicitly names that dependency change. +- Do not refactor neighboring code unless the acceptance criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff instead of doing it silently. + ## Workflow Overview Minimal agent sequence (token-optimized, reduced analysis depth): @@ -102,7 +112,8 @@ Output JSON with: - trade_offs: array of strings - remaining_risks: array of strings -Apply changes directly with Edit/Write tools. Do not serialize full file contents in your response." +Apply changes directly with Edit/Write tools. Do not serialize full file contents in your response. +Do not edit unrelated files, add or upgrade dependencies, or refactor neighboring code unless the current subtask explicitly requires it. Report any required scope expansion as a blocker/tradeoff." ) ``` diff --git a/.claude/skills/map-task/SKILL.md b/.claude/skills/map-task/SKILL.md index 32314715..64fdeabe 100644 --- a/.claude/skills/map-task/SKILL.md +++ b/.claude/skills/map-task/SKILL.md @@ -37,6 +37,15 @@ parallel_tool_policy: single_subtask_sequential - Do not re-plan the selected subtask unless its stored contract is missing or contradictory. - Do not add Predictor, Evaluator, or learning work unless the shared state machine requires it for this subtask. +## Mutation Boundary Constraints + +These constraints apply to the selected subtask's write-capable phases: + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the selected subtask contract explicitly names that dependency change. +- Do not refactor neighboring code unless the selected subtask's validation criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff and stop for a contract update instead of doing it silently. + --- ## Step 0: Parse Arguments diff --git a/.codex/AGENTS.md b/.codex/AGENTS.md index ee6d03da..d0d3d827 100644 --- a/.codex/AGENTS.md +++ b/.codex/AGENTS.md @@ -31,6 +31,15 @@ research and review phases. This prevents accidental edits while exploring. **Note:** Hooks require `hooks = true` in config.toml and are not supported on Windows. +## Mutation Boundary Constraints + +For write-capable MAP skills and agents: + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the current task or subtask explicitly names that dependency change. +- Do not refactor neighboring code unless the acceptance criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff instead of doing it silently. + ## Getting Started 1. Trust this project in Codex settings diff --git a/.codex/skills/map-fast/SKILL.md b/.codex/skills/map-fast/SKILL.md index 4686793b..77c623ab 100644 --- a/.codex/skills/map-fast/SKILL.md +++ b/.codex/skills/map-fast/SKILL.md @@ -20,3 +20,10 @@ $map-fast 3. Verify: `shell_command` to run tests/build No decomposition, no state tracking, no artifacts. + +## Mutation Boundary Constraints + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the task explicitly names that dependency change. +- Do not refactor neighboring code unless the acceptance criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff instead of doing it silently. diff --git a/README.md b/README.md index 28e8ba82..457220eb 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ MAP review is useful, but it is not a replacement for engineering judgment. Seri - **Low overhead** - structured enough to prevent chaos, lightweight enough to keep token and time cost under control. - **Compact high-traffic playbooks** - `/map-plan`, `/map-efficient`, `/map-check`, and `/map-review` keep their active `SKILL.md` bodies focused on the next workflow action, with detailed examples and troubleshooting in bundled supporting files that load only when needed. - **Calibrated workflow effort** - each shipped slash skill declares a `thinking_policy` and `parallel_tool_policy`, so lightweight commands stay direct while planning, review, and release workflows reserve deeper reasoning and parallel fan-out for the stages that benefit from it. Non-release prompts use targeted guardrails instead of blanket all-caps prohibition blocks, reducing over-triggered agents and tool calls while keeping true hard stops explicit. +- **Mutation boundary constraints** - write-capable Claude and Codex provider surfaces tell agents not to edit unrelated files, add or upgrade dependencies, or refactor neighboring code unless the current task/subtask explicitly requires it. If broader scope is necessary, agents should report it as a blocker or tradeoff instead of silently expanding the diff. - **Context-first prompt envelopes** - high-context `/map-plan`, `/map-efficient`, `/map-debug`, and `/map-review` agent prompts wrap branch artifacts in XML-style ``, then state the `` and ``, so specs, review bundles, diffs, logs, and schemas stay visually and machine-semantically separated. - **Skill IR audit** - release checks can lower shipped Claude and Codex `SKILL.md` files into a typed `SkillIR`, verify content hashes, catch unsupported frontmatter, reject missing supporting-file links, and block injection-like instructions before `mapify init` copies provider surfaces into user repos. - **Reviewable diffs** - planning and task contracts keep changes small enough to inspect. diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 1ca6e457..580f1c4b 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -82,6 +82,7 @@ Claude skill metadata includes `skillClass` in `.claude/skills/skill-rules.json` - **Context Budgeting & Compression**: MAP exposes compression policies and thresholds and treats budget control as a first-class workflow concern. Generated Actor `` blocks and `/map-review` reviewer fan-out prompts are capped by deterministic estimated-token budgets before prompt injection so long plans or raw diffs cannot silently crowd out current-subtask, review-bundle, and dependency context. Active budgeted prompt paths append before/after estimates and clipped section labels to `.map//token_budget.json` so users can diagnose missing-context reports without transcript inspection. - **Effort & Parallelism Calibration**: Each task skill declares a `thinking_policy` and `parallel_tool_policy` so provider runtimes know when to stay direct, when to use adaptive reasoning, and when parallel fan-out is safe. Prompt-tone regression tests keep non-release skills on targeted guardrails instead of blanket prohibition blocks, which protects lightweight workflows from unnecessary subagent/tool expansion. +- **Mutation Boundary Constraints**: Write-capable provider surfaces include explicit negative constraints at the point where agents can edit files. Actor, `/map-fast`, `/map-efficient`, `/map-task`, `/map-debug`, and Codex quick-implementation scaffolds tell agents not to edit unrelated files, change dependencies, or refactor neighboring code unless the current contract requires it; necessary scope expansion must be reported as a blocker/tradeoff. - **Compact Skill Playbooks**: High-traffic task skills keep `SKILL.md` focused on active next-action flow and move examples, troubleshooting, and low-frequency rationale into bundled supporting files. This reduces recurring context cost after invocation and compaction without deleting the reference material needed for edge cases. - **Context-First Prompt Envelopes**: High-context skill prompts use a shared XML-style envelope so persisted artifacts appear in `` before ``, instructions, and ``. This keeps specs, review bundles, diffs, logs, and output schemas distinct when provider runtimes receive long subagent prompts. - **Skill IR Audit**: `src/mapify_cli/skill_ir.py` lowers hand-authored Claude and Codex `SKILL.md` files into provider-neutral `SkillIR` records with content hashes, invocation mode, supporting-file links, and extracted safety constraints. The audit fails unsupported frontmatter, unresolved bundled references, and hidden instruction-override wording before provider surfaces are installed. diff --git a/docs/USAGE.md b/docs/USAGE.md index 3c18dc20..15b9ed14 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -75,6 +75,8 @@ Maintainer guardrail: every skill prompt section that says `Output JSON with:` m Maintainer prompt-tone guardrail: non-release MAP skills should use targeted workflow guardrails and explicit off-ramps instead of blanket all-caps prohibition blocks. `tests/test_skills.py::TestPromptToneCalibration` keeps `/map-fast`, `/map-check`, `/map-resume`, and `/map-task` focused on their intended scope and reserves aggressive hard-stop wording for release safety and irreversible operations. +Maintainer mutation-boundary guardrail: write-capable Claude and Codex provider surfaces must include `Mutation Boundary Constraints` before broad write prompts. `tests/test_skills.py::TestSkillStructure::test_write_capable_claude_surfaces_have_constraint_first_boundaries` and `test_write_capable_codex_surfaces_have_mutation_boundaries` keep installed agents from losing the explicit “do not edit unrelated files / do not change dependencies / report scope expansion” rule. + Maintainer provider-surface guardrail: shipped Claude and Codex skills can be audited as typed `SkillIR` records before release. Run `python -m mapify_cli.skill_ir src/mapify_cli/templates/skills src/mapify_cli/templates/codex/skills` to parse every `SKILL.md`, print deterministic content hashes, and fail unsupported frontmatter, missing bundled Markdown references, or injection-like phrases such as “ignore previous instructions.” Maintainer skill-lifecycle guardrail: high-traffic workflow skills (`/map-plan`, `/map-efficient`, `/map-check`, and `/map-review`) keep the active `SKILL.md` body under 500 lines and link to bundled supporting files for examples, troubleshooting, and low-frequency reference details. This keeps invoked skill content cheaper to carry through long sessions and compaction while preserving full reference material for ambiguous or failing runs. diff --git a/docs/improvement-done.md b/docs/improvement-done.md index 6a86cb69..4db41b5b 100644 --- a/docs/improvement-done.md +++ b/docs/improvement-done.md @@ -1,5 +1,15 @@ # MAP Framework Improvement Done +## Constraint-first provider rule templates [2604.040] + +- Date: 2026-05-20 +- Added `Mutation Boundary Constraints` to write-capable Claude provider surfaces: `.claude/agents/actor.md`, `/map-fast`, `/map-efficient`, `/map-task`, and `/map-debug`, plus the shipped template copies. +- Added matching Codex constraints to `.codex/AGENTS.md` and `$map-fast`, plus the shipped template copies, so installed Codex projects get the same unrelated-edit/dependency-change boundary. +- The constraints tell agents not to edit unrelated files, add/remove/upgrade dependencies, or refactor neighboring code unless the current task/subtask explicitly requires it; required scope expansion must be reported as a blocker/tradeoff instead of done silently. +- Added regression tests that scan source and generated Claude/Codex provider surfaces for the mutation-boundary section and required phrases before release. +- Updated README, usage, and architecture docs to describe the installed-user behavior and maintainer guardrail. +- Verified with focused mutation-boundary prompt tests, full skill/template-sync tests, generated Claude and Codex `mapify init` smokes that inspected installed provider files, Skill IR audit, `make lint`, `pytest -m "not slow"`, and no-LLM e2e artifact tests. Full `pytest` and the slow Claude SDK module were attempted, but each exceeded the 30-minute tool timeout without a deterministic failure message. + ## Compact high-traffic workflow playbooks [2604.033-2] - Date: 2026-05-20 diff --git a/docs/improvement-loop-log.md b/docs/improvement-loop-log.md index 9c9755d9..326fc5d8 100644 --- a/docs/improvement-loop-log.md +++ b/docs/improvement-loop-log.md @@ -372,3 +372,18 @@ - invariant: `High-traffic workflow SKILL.md files should keep active next-action flow under 500 lines and link bundled supporting files for examples/troubleshooting/reference material.` - review-check: `When compacting task skills, verify source and template SKILL.md files still preserve state-machine commands, output contracts, closeout artifact writes, and prompt-contract markers before moving detail into references.` - gotcha: `Tests that assert a command appears before first Task( can fail if prose mentions Task( earlier than the real launch; keep literal launch markers out of preflight prose.` + +## 2026-05-20 - Constraint-first provider rule templates [2604.040] + +- Decision: `implemented` +- Branch: `codex/2604-040-constraint-provider-rules` +- Baseline: The active plan identified that generated provider rules lacked a structural guardrail against broad positive write directives. Claude write-capable surfaces already had scattered scope wording, but there was no uniform installed-project constraint that blocked unrelated edits, dependency churn, or neighboring refactors at mutation boundaries. +- Forward Change: Added `Mutation Boundary Constraints` to the Actor agent, `/map-fast`, `/map-efficient`, `/map-task`, `/map-debug`, `.codex/AGENTS.md`, and Codex `$map-fast`, then synced the shipped templates. The constraints require agents to report dependency changes, broad refactors, or scope expansion as blockers/tradeoffs instead of doing them silently. +- Decisive Validation: Focused prompt regression tests now scan source and shipped Claude/Codex provider surfaces for the mutation-boundary section and required unrelated-file/dependency/refactor/blocker phrases. Generated-project smokes inspected installed `.claude/` files, root `AGENTS.md` for Codex, and `.codex/skills/map-fast/SKILL.md`. +- Validation Boundary: `pytest` and `pytest tests/integration/test_e2e_claude_sdk.py -v -m slow` were both attempted and exceeded the 30-minute tool timeout without a deterministic failure message. Deterministic validation passed via `make lint`, `pytest -m "not slow"`, focused skill/template tests, no-LLM e2e artifact tests, Skill IR audit, and generated-project smokes. +- Next Trigger: Reuse this when adding a write-capable provider surface, changing Actor/fix prompts, or introducing any prompt that says to apply edits directly. +- Reusable Learnings: + - command: `pytest tests/test_skills.py::TestSkillStructure::test_write_capable_claude_surfaces_have_constraint_first_boundaries tests/test_skills.py::TestSkillStructure::test_write_capable_codex_surfaces_have_mutation_boundaries -v` + - command: `uv run --no-sync mapify init --no-git --mcp none` + - invariant: `Every write-capable provider surface should include Mutation Boundary Constraints that block unrelated edits, dependency changes, and neighboring refactors unless the current contract explicitly requires them.` + - review-check: `When a prompt says Actor/fix/apply_patch should edit files directly, verify the same prompt or its enclosing skill tells the agent to report required scope expansion as a blocker/tradeoff.` diff --git a/docs/improvement-plan.md b/docs/improvement-plan.md index a4661ce1..9430e4da 100644 --- a/docs/improvement-plan.md +++ b/docs/improvement-plan.md @@ -189,21 +189,3 @@ - Extend spec/plan artifacts with `hard_constraints` and `soft_constraints` fields. Hard constraints block stage completion or force replanning when violated; soft constraints are logged with explicit tradeoff rationale when a workflow chooses not to satisfy them. - Require complex workflows to consume the prior stage artifact explicitly before proceeding; for example, review should load spec + tests + diff, and code execution should record which test/spec contract it is satisfying. Shipped as `2604.039-followup-3` via `prior_stage_consumption` reports in verification summaries and review bundles plus an explicit validator command. - Update canonical docs so MAP has a visible default artifact pipeline even if individual commands still differ in internal implementation details. - -## Constraint-first provider rule templates - -**Source**: [[do-agent-rules-shape-or-distort-guardrails-beat-guidance-in-coding-agents]] (paper note) -**Implementation Layer**: `src/mapify_cli/templates/`, generated `.claude/commands/`, generated `.codex/` surfaces, and template regression tests -**Missing Capability**: A template lint/evaluation pass that distinguishes negative constraints from broad positive directives before MAP installs provider rule files. -**Architecture Evidence**: `docs/ARCHITECTURE.md` identifies provider scaffolding, generated command/skill surfaces, deterministic guardrails, reviewable diffs, and template drift as core concerns. -**Benefit Hypothesis**: Rewriting MAP’s generated provider rules to prefer concrete constraints over broad directives will reduce unrelated-file edits and dependency churn in MAP-driven workflows. Pass criteria: template snapshot tests classify new/changed rule lines, and a small golden workflow fixture shows generated prompts include explicit “do not change unrelated files/dependencies” constraints at high-risk stages. -**Confidence**: 0.67 -**Reasoning**: MAP owns the generated rule/prompt surfaces consumed by coding agents. The source idea is not generic here: MAP’s value is shaping agent behavior through generated workflow artifacts, so rule structure directly affects product quality and user trust. -**Why Not Already Tried**: Existing plan entries cover command examples, skill architecture, workflow fit, and artifact gates, but do not include a structural rule-quality check over generated templates. - -### Proposed Changes - -- Add a template linter that tags generated instruction lines as constraint, directive, context, or example; fail or warn when high-risk workflow templates add broad positive directives without a paired constraint. -- Refactor generated provider rules toward concrete negative constraints at mutation boundaries, especially around unrelated refactors, dependency changes, artifact deletion, and stage skipping. -- Add snapshot tests for representative Claude and Codex scaffolds to keep constraint-first wording stable across `mapify init`. -- Document rule-writing guidance in template maintenance docs so manual edits preserve the same constraint-first style. diff --git a/docs/learned/architecture-patterns.md b/docs/learned/architecture-patterns.md index 4f85896d..bbb58192 100644 --- a/docs/learned/architecture-patterns.md +++ b/docs/learned/architecture-patterns.md @@ -5,4 +5,4 @@ - **Limit Budget Reports To Active Prompt Paths** (2026-05-20): When adding prompt-budget observability, write decisions only from prompt builders that already enforce budgets in production workflows because telemetry for dormant mechanisms does not improve the current user workflow. [workflow: improvement-plan-loop] - **Externalize recovery appendices** (2026-05-20): Skills used after context loss should keep `SKILL.md` focused on the active recovery decision and link to supporting files for examples, state-shape references, token notes, and troubleshooting so compaction recovery does not re-load low-frequency appendices by default. [workflow: improvement-plan-loop] - **Keep high-traffic task skills compact** (2026-05-20): When a task skill is part of the normal MAP golden path, keep active `SKILL.md` focused on next-action flow and move examples, troubleshooting, and low-frequency rationale to supporting files because invoked skill bodies remain in context and are reattached after compaction. [workflow: improvement-plan-loop] - +- **Put negative constraints at mutation boundaries** (2026-05-20): Write-capable provider surfaces should pair direct edit instructions with explicit negative constraints against unrelated files, dependency changes, and neighboring refactors; if broader scope is necessary, the agent should report a blocker/tradeoff rather than silently expanding the diff. [workflow: improvement-plan-loop] diff --git a/docs/learned/commands.md b/docs/learned/commands.md index e28748c1..ff6f6d8d 100644 --- a/docs/learned/commands.md +++ b/docs/learned/commands.md @@ -23,4 +23,4 @@ - **Inspect Budgeted Review Prompts By Branch** (2026-05-20): When validating generated `/map-review` prompt budgeting, run `python3 .map/scripts/map_step_runner.py build_review_prompts --branch --budget-tokens --review-preferences "..."` because the helper defaults to the current git branch and may otherwise write `.map//token_budget.json`. [workflow: improvement-plan-loop] - **Check compact resume skill lifecycle** (2026-05-20): Use `pytest tests/test_skills.py::TestSkillStructure::test_map_resume_keeps_recovery_skill_body_compact tests/test_template_sync.py -v` after changing `/map-resume` so the active recovery body, supporting reference, and shipped template copy stay aligned. [workflow: improvement-plan-loop] - **Check compact high-traffic skill bodies** (2026-05-20): When changing `/map-plan`, `/map-efficient`, `/map-check`, or `/map-review`, run `pytest tests/test_skills.py::TestSkillStructure::test_high_traffic_workflow_skills_keep_active_bodies_compact tests/test_template_sync.py -v` because source and shipped template bodies must stay compact and link their bundled references. [workflow: improvement-plan-loop] - +- **Check mutation-boundary provider prompts** (2026-05-20): When changing write-capable Actor/fix prompts, run `pytest tests/test_skills.py::TestSkillStructure::test_write_capable_claude_surfaces_have_constraint_first_boundaries tests/test_skills.py::TestSkillStructure::test_write_capable_codex_surfaces_have_mutation_boundaries -v` so installed provider surfaces keep unrelated-edit and dependency-change guardrails. [workflow: improvement-plan-loop] diff --git a/docs/learned/review-checks.md b/docs/learned/review-checks.md index 1d35309d..131e5844 100644 --- a/docs/learned/review-checks.md +++ b/docs/learned/review-checks.md @@ -20,4 +20,4 @@ - **Review Budget Artifacts For Actionability** (2026-05-20): When reviewing prompt-budget artifacts, always verify each decision names the prompt path, before/after estimates, clipped sections, source artifacts, and adjustment knob because raw token counts alone do not tell operators whether to continue, raise a budget, or split the workflow. [workflow: improvement-plan-loop] - **Check supporting-file externalization end to end** (2026-05-20): When low-frequency skill content moves out of `SKILL.md`, verify the active workflow still names the next action, Markdown links resolve, non-SKILL supporting files are template-synced, and generated installs include both files. [workflow: improvement-plan-loop] - **Review compacted skills for live workflow markers** (2026-05-20): When reviewing skill-body compaction, always verify state-machine commands, prompt envelope links, run-health writes, review bundle wiring, and handoff artifacts remain in active `SKILL.md` because supporting files should not hide mandatory execution gates. [workflow: improvement-plan-loop] - +- **Require mutation boundaries near direct-edit prompts** (2026-05-20): When reviewing any prompt that tells Actor, a fix phase, or Codex `$map-fast` to edit files directly, verify it also blocks unrelated files, dependency changes, and neighboring refactors unless the current contract explicitly requires them, with required scope expansion reported as a blocker/tradeoff. [workflow: improvement-plan-loop] diff --git a/docs/learned/testing-strategies.md b/docs/learned/testing-strategies.md index 99d808db..f9687ee8 100644 --- a/docs/learned/testing-strategies.md +++ b/docs/learned/testing-strategies.md @@ -34,4 +34,4 @@ paths: - **Smoke Budget Artifacts In Generated Projects** (2026-05-20): When testing shipped prompt-budget helpers, run a generated-project smoke that exercises installed `.map/scripts/map_step_runner.py` against real `.map/` artifacts and a real git diff because source tests do not prove installed users get the artifact wiring. [workflow: improvement-plan-loop] - **Protect compact recovery skill bodies** (2026-05-20): When a skill is used after context exhaustion or `/clear`, add a source-and-template regression for active `SKILL.md` size plus supporting-file links so low-frequency examples and troubleshooting do not creep back into the invoked body. [workflow: improvement-plan-loop] - **Smoke compact skills in generated projects** (2026-05-20): When adding supporting files to shipped skills, run a generated-project `mapify init` smoke and inspect installed `SKILL.md` plus supporting files because template sync alone does not prove installed users receive the compact active body and bundled reference. [workflow: improvement-plan-loop] - +- **Regression-test mutation-boundary wording in source and templates** (2026-05-20): When adding or editing write-capable provider prompts, scan both `.claude/` and `src/mapify_cli/templates/`, plus Codex templates, for explicit `Mutation Boundary Constraints`; generated users need the same unrelated-edit/dependency-change guardrails as the repo working set. [workflow: improvement-plan-loop] diff --git a/src/mapify_cli/templates/agents/actor.md b/src/mapify_cli/templates/agents/actor.md index 856aa48f..09952862 100644 --- a/src/mapify_cli/templates/agents/actor.md +++ b/src/mapify_cli/templates/agents/actor.md @@ -38,6 +38,15 @@ You are a Protocol-Driven Code Execution System. Your objective: translate an AA **Operating constraints**: {{language}}, {{framework}}, scope limited to {{allowed_scope}}. +## Mutation Boundary Constraints + +Every write must stay inside the current subtask contract. + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the current contract explicitly names that dependency change. +- Do not refactor neighboring code unless the validation criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, stop and report it as a blocker/tradeoff instead of doing it silently. + **Template Variable Reference**: - `{{variable}}` (lowercase): Pre-filled by MAP framework Orchestrator before you see them - `{{variable}}` (in generated code): Preserve exactly for runtime substitution when instructed diff --git a/src/mapify_cli/templates/codex/AGENTS.md b/src/mapify_cli/templates/codex/AGENTS.md index ee6d03da..d0d3d827 100644 --- a/src/mapify_cli/templates/codex/AGENTS.md +++ b/src/mapify_cli/templates/codex/AGENTS.md @@ -31,6 +31,15 @@ research and review phases. This prevents accidental edits while exploring. **Note:** Hooks require `hooks = true` in config.toml and are not supported on Windows. +## Mutation Boundary Constraints + +For write-capable MAP skills and agents: + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the current task or subtask explicitly names that dependency change. +- Do not refactor neighboring code unless the acceptance criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff instead of doing it silently. + ## Getting Started 1. Trust this project in Codex settings diff --git a/src/mapify_cli/templates/codex/skills/map-fast/SKILL.md b/src/mapify_cli/templates/codex/skills/map-fast/SKILL.md index 4686793b..77c623ab 100644 --- a/src/mapify_cli/templates/codex/skills/map-fast/SKILL.md +++ b/src/mapify_cli/templates/codex/skills/map-fast/SKILL.md @@ -20,3 +20,10 @@ $map-fast 3. Verify: `shell_command` to run tests/build No decomposition, no state tracking, no artifacts. + +## Mutation Boundary Constraints + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the task explicitly names that dependency change. +- Do not refactor neighboring code unless the acceptance criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff instead of doing it silently. diff --git a/src/mapify_cli/templates/skills/map-debug/SKILL.md b/src/mapify_cli/templates/skills/map-debug/SKILL.md index 1b8a05d6..e90604f7 100644 --- a/src/mapify_cli/templates/skills/map-debug/SKILL.md +++ b/src/mapify_cli/templates/skills/map-debug/SKILL.md @@ -41,6 +41,15 @@ parallel_tool_policy: sequential_root_cause_first - Do not add extra agents beyond the documented debugging sequence; switch workflows only if the task stops being a debugging task. - Do not continue polishing after the original symptom is reproduced, fixed, and verified. +## Mutation Boundary Constraints + +These constraints apply to every fix subtask: + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the root cause evidence explicitly requires that dependency change. +- Do not refactor neighboring code unless the bug cannot be fixed and verified without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff instead of doing it silently. + ## Workflow Overview Debugging workflow focuses on analysis before implementation: @@ -144,6 +153,7 @@ Task( **Root Cause:** [identified root cause] Apply the fix directly with Edit/Write tools. +Do not edit unrelated files, add or upgrade dependencies, or refactor neighboring code unless the root cause evidence explicitly requires it. Report any required scope expansion as a blocker/tradeoff. JSON contract reference: [Actor Change Summary](../../references/map-json-output-contracts.md#actor-change-summary). diff --git a/src/mapify_cli/templates/skills/map-efficient/SKILL.md b/src/mapify_cli/templates/skills/map-efficient/SKILL.md index 5d6fdaa8..3b3fb29d 100644 --- a/src/mapify_cli/templates/skills/map-efficient/SKILL.md +++ b/src/mapify_cli/templates/skills/map-efficient/SKILL.md @@ -36,6 +36,15 @@ parallel_tool_policy: guarded_wave_only 5. After Monitor pass, record files changed in `step_state.json` for guard isolation. 6. Validate planning metadata before Actor starts: `expected_diff_size`, `concern_type`, `one_logical_step`, `split_rationale`, `concern_justification`, `coverage_map`, `hard_constraints`, `soft_constraints`, `validation_criteria`, `[AC-1]` bracket tags, and `tradeoff_rationale`. +## Mutation Boundary Constraints + +These constraints apply to every write-capable Actor or fix phase: + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the current subtask contract explicitly names that dependency change. +- Do not refactor neighboring code unless the current validation criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff and wait for the contract to change instead of doing it silently. + ## Intentional Agent Omissions /map-efficient does not run Evaluator or Reflector during normal execution. Monitor validates correctness directly, and learning is deferred to `/map-learn`. @@ -187,6 +196,7 @@ Task( Implement exactly the current subtask. Preserve validation_criteria, coverage_map tags, hard_constraints, and soft_constraints tradeoffs. Do not expand scope. +Do not edit unrelated files, add or upgrade dependencies, or refactor neighboring code unless the current subtask contract explicitly requires it. Report any required scope expansion as a blocker/tradeoff. Return files_changed, tests_run, validation_notes, and any blocker. diff --git a/src/mapify_cli/templates/skills/map-fast/SKILL.md b/src/mapify_cli/templates/skills/map-fast/SKILL.md index 9b6a14c4..636d4d55 100644 --- a/src/mapify_cli/templates/skills/map-fast/SKILL.md +++ b/src/mapify_cli/templates/skills/map-fast/SKILL.md @@ -33,8 +33,18 @@ parallel_tool_policy: sequential_by_default - Do not add discovery, design review, impact analysis, or learning steps to keep this workflow busy. - Do not refactor nearby code unless the selected small task cannot work without that exact change. +- Do not edit unrelated files or add, remove, or upgrade dependencies unless the task explicitly requires that exact change. - If the task becomes risky, multi-stage, or ambiguous, stop using `/map-fast` and switch to `/map-efficient` or `/map-plan` instead. +## Mutation Boundary Constraints + +These constraints apply to the Actor implementation prompt: + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the current task explicitly names that dependency change. +- Do not refactor neighboring code unless the acceptance criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff instead of doing it silently. + ## Workflow Overview Minimal agent sequence (token-optimized, reduced analysis depth): @@ -102,7 +112,8 @@ Output JSON with: - trade_offs: array of strings - remaining_risks: array of strings -Apply changes directly with Edit/Write tools. Do not serialize full file contents in your response." +Apply changes directly with Edit/Write tools. Do not serialize full file contents in your response. +Do not edit unrelated files, add or upgrade dependencies, or refactor neighboring code unless the current subtask explicitly requires it. Report any required scope expansion as a blocker/tradeoff." ) ``` diff --git a/src/mapify_cli/templates/skills/map-task/SKILL.md b/src/mapify_cli/templates/skills/map-task/SKILL.md index 32314715..64fdeabe 100644 --- a/src/mapify_cli/templates/skills/map-task/SKILL.md +++ b/src/mapify_cli/templates/skills/map-task/SKILL.md @@ -37,6 +37,15 @@ parallel_tool_policy: single_subtask_sequential - Do not re-plan the selected subtask unless its stored contract is missing or contradictory. - Do not add Predictor, Evaluator, or learning work unless the shared state machine requires it for this subtask. +## Mutation Boundary Constraints + +These constraints apply to the selected subtask's write-capable phases: + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the selected subtask contract explicitly names that dependency change. +- Do not refactor neighboring code unless the selected subtask's validation criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff and stop for a contract update instead of doing it silently. + --- ## Step 0: Parse Arguments diff --git a/tests/test_skills.py b/tests/test_skills.py index 24e902d2..e421cf91 100644 --- a/tests/test_skills.py +++ b/tests/test_skills.py @@ -89,6 +89,32 @@ "map-check": "check-reference.md", } +CLAUDE_MUTATION_BOUNDARY_SURFACES = [ + Path("agents") / "actor.md", + Path("skills") / "map-fast" / "SKILL.md", + Path("skills") / "map-efficient" / "SKILL.md", + Path("skills") / "map-task" / "SKILL.md", + Path("skills") / "map-debug" / "SKILL.md", +] + +CODEX_MUTATION_BOUNDARY_SURFACES = [ + Path("AGENTS.md"), + Path("skills") / "map-fast" / "SKILL.md", +] + +MUTATION_BOUNDARY_REQUIRED_PHRASES = [ + "Do not edit unrelated files", + "Do not add, remove, or upgrade dependencies", + "refactor neighboring code", + "report it as a blocker/tradeoff", +] + +MUTATION_DIRECTIVE_PATTERN = re.compile( + r"\b(?:Apply changes directly|Use Edit/Write|Implement exactly|" + r"Implement this subtask|Implement a fix|make changes)\b", + re.IGNORECASE, +) + PROMPT_TONE_SKILL_ROOTS = [ Path(".claude") / "skills", Path("src") / "mapify_cli" / "templates" / "skills", @@ -430,6 +456,52 @@ def test_high_traffic_workflow_skills_keep_active_bodies_compact( assert "## Examples" in reference assert "## Troubleshooting" in reference + def test_write_capable_claude_surfaces_have_constraint_first_boundaries( + self, project_root + ): + """Write-capable Claude surfaces must block silent scope expansion.""" + for root in ( + project_root / ".claude", + project_root / "src" / "mapify_cli" / "templates", + ): + for relative_path in CLAUDE_MUTATION_BOUNDARY_SURFACES: + surface = root / relative_path + content = surface.read_text(encoding="utf-8") + + assert "## Mutation Boundary Constraints" in content, ( + f"{surface} must declare mutation boundary constraints before " + "write-capable instructions." + ) + for phrase in MUTATION_BOUNDARY_REQUIRED_PHRASES: + assert phrase in content, ( + f"{surface} must include constraint-first guardrail: {phrase}" + ) + + if relative_path.parts[0] == "skills": + constraint_index = content.index("## Mutation Boundary Constraints") + directive_match = MUTATION_DIRECTIVE_PATTERN.search(content) + assert directive_match is None or constraint_index < directive_match.start(), ( + f"{surface} should present scope/dependency constraints before " + "broad write directives." + ) + + def test_write_capable_codex_surfaces_have_mutation_boundaries( + self, project_root + ): + """Installed Codex scaffolds need the same unrelated-edit/dependency guardrail.""" + codex_root = project_root / "src" / "mapify_cli" / "templates" / "codex" + for relative_path in CODEX_MUTATION_BOUNDARY_SURFACES: + surface = codex_root / relative_path + content = surface.read_text(encoding="utf-8") + + assert "## Mutation Boundary Constraints" in content, ( + f"{surface} must declare mutation boundary constraints." + ) + for phrase in MUTATION_BOUNDARY_REQUIRED_PHRASES: + assert phrase in content, ( + f"{surface} must include constraint-first guardrail: {phrase}" + ) + # --- skill-rules.json tests --- def test_skill_rules_json_is_valid(self, skills_dir): From 71cd04637e80dd33f0e4ead6176b34a5e43d6ffe Mon Sep 17 00:00:00 2001 From: Mikhail Petrov Date: Wed, 20 May 2026 18:52:49 +0300 Subject: [PATCH 2/2] Tighten mutation boundary ordering checks --- .claude/agents/actor.md | 18 +++++++-------- .codex/skills/map-fast/SKILL.md | 14 ++++++------ src/mapify_cli/templates/agents/actor.md | 18 +++++++-------- .../templates/codex/skills/map-fast/SKILL.md | 14 ++++++------ tests/test_skills.py | 22 ++++++++++++------- 5 files changed, 46 insertions(+), 40 deletions(-) diff --git a/.claude/agents/actor.md b/.claude/agents/actor.md index 09952862..9e4cdf13 100644 --- a/.claude/agents/actor.md +++ b/.claude/agents/actor.md @@ -6,6 +6,15 @@ version: 3.1.0 last_updated: 2025-11-27 --- +## Mutation Boundary Constraints + +Every write must stay inside the current subtask contract. + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the current contract explicitly names that dependency change. +- Do not refactor neighboring code unless the validation criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, stop and report it as a blocker/tradeoff instead of doing it silently. + # QUICK REFERENCE (Read First) ``` @@ -38,15 +47,6 @@ You are a Protocol-Driven Code Execution System. Your objective: translate an AA **Operating constraints**: {{language}}, {{framework}}, scope limited to {{allowed_scope}}. -## Mutation Boundary Constraints - -Every write must stay inside the current subtask contract. - -- Do not edit unrelated files, even if they are nearby or easy to clean up. -- Do not add, remove, or upgrade dependencies unless the current contract explicitly names that dependency change. -- Do not refactor neighboring code unless the validation criteria cannot pass without that exact refactor. -- If a dependency change, broad refactor, or scope expansion seems necessary, stop and report it as a blocker/tradeoff instead of doing it silently. - **Template Variable Reference**: - `{{variable}}` (lowercase): Pre-filled by MAP framework Orchestrator before you see them - `{{variable}}` (in generated code): Preserve exactly for runtime substitution when instructed diff --git a/.codex/skills/map-fast/SKILL.md b/.codex/skills/map-fast/SKILL.md index 77c623ab..1fcf3588 100644 --- a/.codex/skills/map-fast/SKILL.md +++ b/.codex/skills/map-fast/SKILL.md @@ -13,6 +13,13 @@ Minimal MAP workflow for small changes. Skips planning and learning phases. $map-fast ``` +## Mutation Boundary Constraints + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the task explicitly names that dependency change. +- Do not refactor neighboring code unless the acceptance criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff instead of doing it silently. + ## Workflow 1. Research: `shell_command` to explore relevant files @@ -20,10 +27,3 @@ $map-fast 3. Verify: `shell_command` to run tests/build No decomposition, no state tracking, no artifacts. - -## Mutation Boundary Constraints - -- Do not edit unrelated files, even if they are nearby or easy to clean up. -- Do not add, remove, or upgrade dependencies unless the task explicitly names that dependency change. -- Do not refactor neighboring code unless the acceptance criteria cannot pass without that exact refactor. -- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff instead of doing it silently. diff --git a/src/mapify_cli/templates/agents/actor.md b/src/mapify_cli/templates/agents/actor.md index 09952862..9e4cdf13 100644 --- a/src/mapify_cli/templates/agents/actor.md +++ b/src/mapify_cli/templates/agents/actor.md @@ -6,6 +6,15 @@ version: 3.1.0 last_updated: 2025-11-27 --- +## Mutation Boundary Constraints + +Every write must stay inside the current subtask contract. + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the current contract explicitly names that dependency change. +- Do not refactor neighboring code unless the validation criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, stop and report it as a blocker/tradeoff instead of doing it silently. + # QUICK REFERENCE (Read First) ``` @@ -38,15 +47,6 @@ You are a Protocol-Driven Code Execution System. Your objective: translate an AA **Operating constraints**: {{language}}, {{framework}}, scope limited to {{allowed_scope}}. -## Mutation Boundary Constraints - -Every write must stay inside the current subtask contract. - -- Do not edit unrelated files, even if they are nearby or easy to clean up. -- Do not add, remove, or upgrade dependencies unless the current contract explicitly names that dependency change. -- Do not refactor neighboring code unless the validation criteria cannot pass without that exact refactor. -- If a dependency change, broad refactor, or scope expansion seems necessary, stop and report it as a blocker/tradeoff instead of doing it silently. - **Template Variable Reference**: - `{{variable}}` (lowercase): Pre-filled by MAP framework Orchestrator before you see them - `{{variable}}` (in generated code): Preserve exactly for runtime substitution when instructed diff --git a/src/mapify_cli/templates/codex/skills/map-fast/SKILL.md b/src/mapify_cli/templates/codex/skills/map-fast/SKILL.md index 77c623ab..1fcf3588 100644 --- a/src/mapify_cli/templates/codex/skills/map-fast/SKILL.md +++ b/src/mapify_cli/templates/codex/skills/map-fast/SKILL.md @@ -13,6 +13,13 @@ Minimal MAP workflow for small changes. Skips planning and learning phases. $map-fast ``` +## Mutation Boundary Constraints + +- Do not edit unrelated files, even if they are nearby or easy to clean up. +- Do not add, remove, or upgrade dependencies unless the task explicitly names that dependency change. +- Do not refactor neighboring code unless the acceptance criteria cannot pass without that exact refactor. +- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff instead of doing it silently. + ## Workflow 1. Research: `shell_command` to explore relevant files @@ -20,10 +27,3 @@ $map-fast 3. Verify: `shell_command` to run tests/build No decomposition, no state tracking, no artifacts. - -## Mutation Boundary Constraints - -- Do not edit unrelated files, even if they are nearby or easy to clean up. -- Do not add, remove, or upgrade dependencies unless the task explicitly names that dependency change. -- Do not refactor neighboring code unless the acceptance criteria cannot pass without that exact refactor. -- If a dependency change, broad refactor, or scope expansion seems necessary, report it as a blocker/tradeoff instead of doing it silently. diff --git a/tests/test_skills.py b/tests/test_skills.py index e421cf91..5e0f8dc9 100644 --- a/tests/test_skills.py +++ b/tests/test_skills.py @@ -111,7 +111,7 @@ MUTATION_DIRECTIVE_PATTERN = re.compile( r"\b(?:Apply changes directly|Use Edit/Write|Implement exactly|" - r"Implement this subtask|Implement a fix|make changes)\b", + r"Implement this subtask|Implement a fix|Apply the fix directly|make changes)\b", re.IGNORECASE, ) @@ -477,13 +477,12 @@ def test_write_capable_claude_surfaces_have_constraint_first_boundaries( f"{surface} must include constraint-first guardrail: {phrase}" ) - if relative_path.parts[0] == "skills": - constraint_index = content.index("## Mutation Boundary Constraints") - directive_match = MUTATION_DIRECTIVE_PATTERN.search(content) - assert directive_match is None or constraint_index < directive_match.start(), ( - f"{surface} should present scope/dependency constraints before " - "broad write directives." - ) + constraint_index = content.index("## Mutation Boundary Constraints") + directive_match = MUTATION_DIRECTIVE_PATTERN.search(content) + assert directive_match is None or constraint_index < directive_match.start(), ( + f"{surface} should present scope/dependency constraints before " + "broad write directives." + ) def test_write_capable_codex_surfaces_have_mutation_boundaries( self, project_root @@ -502,6 +501,13 @@ def test_write_capable_codex_surfaces_have_mutation_boundaries( f"{surface} must include constraint-first guardrail: {phrase}" ) + constraint_index = content.index("## Mutation Boundary Constraints") + directive_match = MUTATION_DIRECTIVE_PATTERN.search(content) + assert directive_match is None or constraint_index < directive_match.start(), ( + f"{surface} should present scope/dependency constraints before " + "broad write directives." + ) + # --- skill-rules.json tests --- def test_skill_rules_json_is_valid(self, skills_dir):