📖 Situational Tutorial: Securing Legacy Codebases in 60 Seconds
📌 1. The Target Problem
Legacy codebases often accumulate custom rules files (.cursorrules, .clinerules, .windsurfrules) scattered across directories, written by different developers. When onboarding autonomous agents, these conflicting files cause context pollution and waste token budgets.
🚀 2. Step-by-Step Walkthrough
Step 1: Stitch DNA onto the Project (Graft)
Navigate to your legacy repository root and run the graft operation. This automatically detects, harvests, and prunes any messy legacy rules files on disk:
cd ~/Development/legacy-service
sprawl graft
This moves legacy files to .agents/rules/ under names like local_cursorrules.md, cleans up project root clutter, and generates a default sprawl_manifest.yml referencing them.
Step 2: Synchronize the Workspace
Verify the manifest and compile your legacy overrides along with global DNA security baselines into a single, unified rules context:
sprawl sync
This provisions a clean virtual environment, updates .agentignore, and compiles your rule sets.
Step 3: Verify Workspace Boundaries
Run the status check to ensure your legacy codebase is registered and that build folders are excluded from agent context via .agentignore:
sprawl status
Step 4: Compile IDE Adapter Targets
Link the newly structured governance configs into your IDE workspace bindings:
sprawl bind
This links the compiled context to your active editors (Cursor, VS Code, RooCode, Claude Code).
Step 5: Call Your Agent and Test MCP Boundaries
Open the legacy directory in Cursor or VS Code:
code .
Verify the sprawl-workspace-fs MCP directory boundary by testing an out-of-scope MCP path traversal (../../). The MCP server rejects out-of-scope queries with JSON-RPC -32602, confirming that MCP workspace access is scoped to the repository root.
🩺 Troubleshooting
- Graft command fails to identify rules files
- Cause: The files are named differently, or directory permissions prevent read/write access.
- Resolution: Verify that rules files are in the repository root and are readable by your user account.
🔗 Related Resources & Tutorials
- [[00_COMMAND_INDEX|Command Index Reference]]
- [[graft|Graft Command Reference]]
- [[SCN-004_mount_context|Sharing Directory Context Scenario]]