[Feature] Architecture: Negative-space mutation firewall
Description
Define strict, mechanically enforced boundaries for what a task is allowed to mutate, rejecting edits that fall outside the authorized "envelope."
Use Case
When small models encounter a bug they don't understand, they sometimes attempt "fixes" by deleting tests, broadening types to any, or removing unrelated API validations. This degrades project health over time.
Proposed Solution
- At the start of a task, establish an envelope (e.g., "Allowed: implementation of validateToken. Preserve: exported signatures, dependencies").
- Before accepting a patch from the model, the harness compares the AST of the proposed change against the original.
- If the patch alters an exported signature or modifies an unrelated test, the harness rejects the edit locally with an error: "Action blocked: You are not authorized to change the exported signature."
Alternatives Considered
- LLM-as-a-judge review (costs tokens, adds latency, unreliable on local models).
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] This feature aligns with the project's goals (local-first AI assistance)
I'd love to take this on! Here is a structured implementation:
Core Architecture & Strategy
The firewall will act as a deterministic pre-mutation gate before any file edit or write is committed to disk (integrating with source/tools/file-ops/ and source/services/lifecycle-hooks.ts).
1. Mutation Boundary Validator (source/firewall/mutation-firewall.ts)
- Envelope Configuration:
blockTypeDegradation: Rejects patches that replace explicit types withany/unknownin existing signatures.protectTestSuites: Prevents the deletion or commenting-out of existingtest(...)/it(...)blocks in spec/test files unless explicitly targeted.preserveExportSignatures: Uses TypeScript AST diffing (ts.createSourceFile) to verify that exported function/interface/type signatures remain structurally compatible before and after the edit.protectedPaths: Guardrails critical files (e.g.package.json, lockfiles, CI configs) from incidental deletion or unexpected structural edits.
2. Tool Integration Gate
- Hook the firewall directly into the file mutation pipeline (
write_file,string_replace,diff_edit):- Prior to applying the diff/replacement, run the proposed content through
evaluateMutationEnvelope(targetPath, oldContent, newContent, options). - If a rule is violated, abort the write and return a structured rejection message to the LLM (e.g.,
Action blocked by mutation firewall: You attempted to delete test cases in 'source/auth.spec.ts'. Modify implementation code instead.). - This allows the model to self-correct during the active conversation loop without corrupting the codebase.
- Prior to applying the diff/replacement, run the proposed content through
3. Configuration & CLI Settings (source/types/config.ts)
- Add a configurable
firewallblock inagents.config.jsonwith sensible defaults (enabled for local/small model profiles, configurable via/tuneor session settings).
4. Comprehensive Test Suite (source/firewall/mutation-firewall.spec.ts)
- Unit tests verifying:
- Detection and blocking of
anytype injections into typed functions. - Detection and rejection of deleted test cases in
.spec.tsfiles. - Enforcement of exported symbol signature preservation.
- Allowing legitimate modifications, refactors, and valid new tests.
- Detection and blocking of
Great plan @rishu685, just assigned you!