Logic guardian

From Rune-kit/rune · View interactive version

Logic guardian is an AI agent skill from the GitHub repository Rune-kit/rune. Protects complex business logic from accidental deletion or overwrite. Use when editing payment, trading, state-machine, or other load-bearing business logic where a single deleted line can cause silent data corruption. Maintains a logic manifest, enforces pre-edit gates, validates post-edit diffs.

How to use this skill

Skill file

logic-guardian

Purpose

Complex projects (trading bots, payment systems, game engines, state machines) contain interconnected logic that AI agents routinely destroy by accident. The pattern is always the same: new session starts, agent doesn't know existing logic, rewrites or deletes working code, project regresses. logic-guardian breaks this cycle by maintaining a machine-readable logic manifest, enforcing a pre-edit gate on logic files, and validating that edits don't silently remove existing logic. It is the "institutional memory" for business logic.

Triggers

Calls (outbound connections)

Called By (inbound connections)

Workflow

Phase 0 — Load Manifest + Invariants

  1. Use Read on .rune/logic-manifest.json
  2. If file exists:
  1. If manifest does NOT exist:
  1. Obtain invariants (seeded by onboard — see onboard Step 5.4):

Phase 1 — Validate Manifest Against Codebase

Ensure the manifest matches the actual code (detect drift):

  1. For each component in the manifest:
  1. Report:
  1. If drift detected: ask user whether to update manifest or investigate changes

Phase 2 — Pre-Edit Gate (called by fix/surgeon/cook)

Before ANY edit to a manifested file:

  1. Load the manifest (Phase 0)
  2. Display the affected component's current spec:

```

COMPONENT: [name]

STATUS: ACTIVE | TESTING | DEPRECATED

FUNCTIONS: [list with one-line descriptions]

PARAMETERS: [configurable values with current settings]

DEPENDENCIES: [what other components depend on this]

LAST_MODIFIED: [date]

```

  1. Require the agent to explicitly state:
  1. If the agent cannot list the existing functions → BLOCK the edit. Force a Read of the file first.
  2. Cross-file invariant check — for each rule loaded from .rune/INVARIANTS.md in Phase 0:

```

INVARIANT (from .rune/INVARIANTS.md):

WHAT: <rule.what>

WHY: <rule.why>

```

Phase 3 — Generate Manifest (first-time or rescan)

Scan the project and build the manifest:

  1. Use scout to find logic-heavy files:
  1. For each discovered file:
  1. Map dependencies between components:
  1. Write manifest to .rune/logic-manifest.json
  2. Save summary to neural memory via session-bridge

Phase 4 — Post-Edit Validation

After any edit to a manifested file:

  1. Re-read the edited file
  2. Compare against the manifest's function list:
  1. Run verification to execute tests
  2. If all checks pass: update the manifest with new state
  3. If function was removed unintentionally: offer to restore from git

Phase 5 — Cross-Session Handoff

Ensure the next session can pick up where this one left off:

  1. Update .rune/logic-manifest.json with:
  1. Save key decisions to journal as ADRs
  2. Save manifest summary to neural memory:

Output Format

Manifest Schema (`.rune/logic-manifest.json`)

{
  "version": "1.0",
  "project": "project-name",
  "last_validated": "2026-03-05T10:00:00Z",
  "components": [
    {
      "name": "rsi-entry-detector",
      "file_path": "src/scenarios/rsi_entry/detect.py",
      "role": "ENTRY_LOGIC",
      "status": "ACTIVE",
      "functions": [
        {
          "name": "detect_entry_signal",
          "signature": "(df: DataFrame, ticket: Ticket, config: Settings) -> Signal | None",
          "description": "3-step RSI entry detection: challenge -> zone check -> entry point",
          "critical": true
        }
      ],
      "parameters": [
        { "name": "rsi_period", "value": 7, "source": "settings.py" },
        { "name": "challenge_threshold_long", "value": 65, "source": "settings.py" }
      ],
      "dependencies": ["trend-pass-tracker", "indicator-calculator"],
      "dependents": ["production-worker", "backtest-engine"],
      "last_modified": "2026-03-01",
      "last_modifier": "human",
      "checksum": "sha256:abc123..."
    }
  ],
  "co_change_groups": [
    {
      "name": "entry-pipeline",
      "components": ["trend-pass-tracker", "rsi-entry-detector", "indicator-calculator"],
      "reason": "These components share RSI parameters and must be modified together"
    }
  ]
}

Validation Report

## Logic Guardian Report

### Manifest Status: SYNCED | DRIFT_DETECTED
- Components: N active, M testing, K deprecated
- Last validated: [timestamp]

### Pre-Edit Gate
- File: [path]
- Component: [name] (ACTIVE)
- Functions preserved: [list]
- Intended change: [description]
- Impact: [downstream effects]

### Post-Edit Validation
- Functions removed: [none | list]
- Signatures changed: [none | list]
- Parameters changed: [none | list]
- Tests: PASS | FAIL
- Manifest: UPDATED | NEEDS_REVIEW

Constraints

  1. MUST load manifest before ANY edit to a manifested file — the entire point is pre-edit awareness
  2. MUST NOT allow edits to ACTIVE logic without the agent explicitly listing what will be preserved — prevents silent overwrites
  3. MUST alert on function removal — the #1 failure mode is deleting working logic
  4. MUST run tests after editing manifested files — logic changes without test verification are blind
  5. MUST update manifest after validated edits — stale manifests provide false confidence
  6. MUST NOT auto-generate manifest for files the agent hasn't read — manifest must reflect actual understanding

Mesh Gates

| Gate | Requires | If Missing |

|------|----------|------------|

| PRE_EDIT | .rune/logic-manifest.json loaded + component spec displayed | BLOCK edit. Run Phase 0 + Phase 2 first. |

| POST_EDIT | All manifest functions still present OR removal explicitly acknowledged | ALERT + offer git restore |

| CROSS_SESSION | Manifest updated + summary saved to journal/nmem | WARN: next session will lack context |

Sharp Edges

| Failure Mode | Severity | Mitigation |

|---|---|---|

| Agent edits manifested file without loading manifest first | CRITICAL | Phase 2 gate: cook/fix MUST call logic-guardian before editing manifested files |

| Manifest drifts from actual code (manual edits not tracked) | HIGH | Phase 1 validation on every load — detect and reconcile drift |

| Agent acknowledges existing logic but still overwrites it | HIGH | Post-edit Phase 4 diff check catches removed functions regardless of agent claims |

| Manifest becomes too large (100+ components) | MEDIUM | Group related functions into composite components; track at module level not function level |

| False sense of security — manifest exists but is outdated | MEDIUM | Checksum comparison on every load; warn if file hash doesn't match manifest |

| Agent treats manifest generation as a one-time task | LOW | Phase 5 cross-session handoff ensures manifest stays alive across sessions |

Done When

Returns

| Artifact | Format | Location |

|----------|--------|----------|

| Logic manifest | JSON | .rune/logic-manifest.json |

| Validation report (SYNCED / DRIFT) | Markdown | inline |

| Pre-edit gate summary | Structured text | inline |

| ADR entries for logic changes | Markdown | via journal L3 |

Cost Profile

~1,000-2,000 tokens for manifest load + pre-edit gate. ~3,000-5,000 tokens for full project scan (Phase 3). Sonnet for code analysis; haiku for file scanning via scout.

Scope guardrail: logic-guardian protects existing logic — it does not implement new features or refactor code.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.