agentleFS
eqtylabeqtylab/cupcake/CLAUDE.md

cupcake

CLAUDE.md294 starsChanged 12 months agoApache-2.0View on GitHub

- Function: A policy engine for AI coding agents (like Claude Code, Cursor, OpenCode) that intercepts tool calls, evaluates them against user-defined OPA Rego policies, and returns Allow, Block, or Warn decisions. - Core Flow: $$\text{Event Input} \rightarrow \text{Route (O(1))} \rightarrow \text{Gather Signals} \rightarrow \text{Evaluate (WASM)} \rightarrow \text{Synthesize} \rightarrow \text{Response}$$ - Hybrid Model: Rego (WASM) declares rules/aggregates verbs; Rust (Engine) handles routing, signal gathering, and final decision synthesis. - Two-Phase Evaluation: 1. Phase 1 (Global Policies): Evaluated first (early termination…

The file

We split this CLAUDE.md into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Feature Flag (MANDATORY): All Rust tests MUST be run with the --features deterministic-tests flag for stable HMAC key generation.

    line 46
  2. Distinctive:

    Harness Testing (CRITICAL): When testing a specific harness (e.g., Claude Code), use the dedicated helper function to avoid compilation …

    line 51

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

Cupcake System Overview

  • Function: A policy engine for AI coding agents (like Claude Code, Cursor, OpenCode) that intercepts tool calls, evaluates them against user-defined OPA Rego policies, and returns Allow, Block, or Warn decisions.
  • Core Flow: $$\text{Event Input} \rightarrow \text{Route (O(1))} \rightarrow \text{Gather Signals} \rightarrow \text{Evaluate (WASM)} \rightarrow \text{Synthesize} \rightarrow \text{Response}$$
  • Hybrid Model: Rego (WASM) declares rules/aggregates verbs; Rust (Engine) handles routing, signal gathering, and final decision synthesis.
  • Two-Phase Evaluation:
    1. Phase 1 (Global Policies): Evaluated first (early termination on block). Organization-wide governance from ~/.cupcake/rulebook.yml.
    2. Phase 2 (Project Policies): Evaluated only if Phase 1 allows. Project-specific rules from .cupcake/rulebook.yml.

Policy Engine (WASM/Rego) Details

1. Routing vs. Policy Execution (CRITICAL)

  • Routing is an optimization layer, not a selector.
    • Controls: Early exit if no policies match event criteria, and which signals to collect.
    • Does NOT Control: Which Rego rules execute inside WASM. All compiled policies run via the single entrypoint cupcake.system.evaluate.
  • Policy Self-Filtering (MANDATORY): Policies MUST include event and tool checks in their Rego logic.
    deny contains decision if {
        input.hook_event_name == "PreToolUse"  # REQUIRED
        input.tool_name == "Bash"               # REQUIRED
        # ... your logic
    }

2. OPA Rego v1 Migration (CRITICAL)

Cupcake uses OPA v1.71.0+ where Rego v1 is the default syntax.

AreaOld (Rego v0)New (Rego v1 / Best Practice)Notes
Object Key Membership"key" in my_object"key" in object.keys(my_object)CRITICAL: Old syntax silently fails by returning false.
Decision Verbsdeny[decision] { ... }deny contains decision if { ... }Use contains with if.
Ask DecisionN/AMust include reason and question fields.
Metadata PlacementAllowed anywherescope: package metadata MUST be the FIRST thing in the file (before package declaration).Enforced by OPA linter/compiler.

3. Decisions & Synthesis

  • Decision Priority: Halt > Deny/Block > Ask > Allow.
  • Signal Access: Signals are accessed via input.signals.*, not data.*.
  • Builtin Config Access: Builtin policy config is accessed via input.builtin_config.<builtin_name>, not through signals.

Testing Requirements

  • Feature Flag (MANDATORY): All Rust tests MUST be run with the --features deterministic-tests flag for stable HMAC key generation.
    cargo test --workspace --features cupcake-core/deterministic-tests
    # or: just test
  • Harness Testing (CRITICAL): When testing a specific harness (e.g., Claude Code), use the dedicated helper function to avoid compilation errors:
    // CORRECT
    test_helpers::create_test_project_for_harness(
        project_dir.path(),
        HarnessType::ClaudeCode
    )?;

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.