Hey, cool workflow. The DbC approach for AI agents is a nice angle.
What you’re describing with CONTRACT.md as invariants lines up well with Cursor’s Project Rules system Rules | Cursor Docs. You can create .cursor/rules/ files with the Always Apply type. These get injected at the start of every agent session. So you could put your invariants directly into an always-applied rule file instead of relying on the agent to read CONTRACT.md.
Quick setup:
Cmd+Shift+PorCtrl+Shift+P, then Cursor Settings > Rules- Click + Add Rule or use
/create-rulein chat - Set the rule type to Always Apply
- Put your invariants there
That said, the rule drift problem in long sessions is real and known. Rules can get pushed out of context as the conversation grows. A few related discussions:
- Session-Pinned Rules: Attach specific rules to keep them active throughout a session
- Mandatory Pre-Action Rules Gate
Current workarounds for long sessions are starting a new chat when rules stop working, using models with longer context, or reminding critical rules inline in the prompt.
As for first-class support for prioritizing an invariants file before edits, the team is aware this is a common pain point. Your report helps with visibility on this.