agentleFS
TheUnchartedTheUncharted/zapcode/CLAUDE.md

zapcode

CLAUDE.md92 starsChanged 9 months agoMITView on GitHub

AI coding assistant instructions for the zapcode project. See AGENTS.md for the full architecture reference. This file adds Claude-Code-specific guidance on top of it. Do not add Co-Authored-By trailers to git commits. Before writing any code in this repository, read AGENTS.md in full. It defines: - What Zapcode is and what it must never do - The full architecture (parser → IR → bytecode → VM → snapshot) - The five sandbox invariants that must never be violated - The…

  • In this repositoryOne other file it gives its agents.

The file

Show its rules and text

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

18 rules. About 0 are common, 9 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

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

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

    Do not add Co-Authored-By trailers to git commits.

    line 11
  2. Distinctive:

    Before writing any code in this repository, read AGENTS.md in full.

    line 17
  3. Distinctive:

    Do not skip this. The sandbox invariants in particular will save you from introducing security vulnerabilities that are hard to detect and …

    line 23
  4. Distinctive:

    Start here when working on a new area:

    line 30
  5. Very specific:

    When in doubt about where something belongs: zapcode-core is pure Rust with zero I/O.

    line 48
  6. Distinctive:

    Check the supported subset table in AGENTS.md first: If the feature is explicitly listed as unsupported, do not add it without opening a …

    line 56
  7. Very specific:

    Use push_call_frame() helper for any function call setup

    line 71
  8. Distinctive:

    Write tests: before considering the feature done.

    line 73
  9. Distinctive:

    Update JS, Python, and WASM bindings: if the feature affects the public API surface.

    line 75
  10. Very specific:

    Before submitting any code to zapcode-core, verify:

    line 81
  11. Very specific:

    If you are implementing an external function bridge: the bridge must validate that the function name exists in the registered set before …

    line 90
  12. Distinctive:

    When walking the AST:

    line 115
  13. Very specific:

    Use match exhaustively — never _ wildcard on statement or expression nodes.

    line 116
  14. Very specific:

    Do not use oxc_transformer or oxc_semantic — they add weight we don't need.

    line 119
  15. Very specific:

    Run benchmarks with cargo bench.

    line 147
  16. Distinctive:

    Sandbox boundary question: if in doubt, block it.

    line 154
  17. Very specific:

    API design question: follow @pydantic/monty's API shape.

    line 155
  18. Distinctive:

    Performance vs correctness: always choose correctness.

    line 156

≈ “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

CLAUDE.md

AI coding assistant instructions for the zapcode project. See AGENTS.md for the full architecture reference. This file adds Claude-Code-specific guidance on top of it.


Git

Do not add Co-Authored-By trailers to git commits.


Read AGENTS.md first

Before writing any code in this repository, read AGENTS.md in full. It defines:

  • What Zapcode is and what it must never do
  • The full architecture (parser → IR → bytecode → VM → snapshot)
  • The five sandbox invariants that must never be violated
  • The definition of "done" for any feature

Do not skip this. The sandbox invariants in particular will save you from introducing security vulnerabilities that are hard to detect and easy to ship.


Codebase orientation

Start here when working on a new area:

AreaEntry point
Parsing TypeScriptcrates/zapcode-core/src/parser/mod.rs
IR definitioncrates/zapcode-core/src/parser/ir.rs
Bytecode instructionscrates/zapcode-core/src/compiler/instruction.rs
Compiler (IR → bytecode)crates/zapcode-core/src/compiler/mod.rs
VM main loop + dispatchcrates/zapcode-core/src/vm/mod.rs
Built-in functionscrates/zapcode-core/src/vm/builtins.rs
Value / type systemcrates/zapcode-core/src/value.rs
Snapshot / resumecrates/zapcode-core/src/snapshot.rs
Resource limitscrates/zapcode-core/src/sandbox.rs
Error typescrates/zapcode-core/src/error.rs
JS bindings APIcrates/zapcode-js/src/lib.rs
Python bindings APIcrates/zapcode-py/src/lib.rs
WASM bindings APIcrates/zapcode-wasm/src/lib.rs

When in doubt about where something belongs: zapcode-core is pure Rust with zero I/O. Bindings crates only translate types and marshal calls into zapcode-core. Never put business logic in binding crates.


How to add a new language feature

  1. Check the supported subset table in AGENTS.md first. If the feature is explicitly listed as unsupported, do not add it without opening a discussion. Features are excluded intentionally.
  2. Add parser support in crates/zapcode-core/src/parser/. The parser walks the oxc AST and emits ZapcodeIR. Unsupported nodes must emit ZapcodeError::UnsupportedSyntax with the node's span information.
  3. Add compiler support in crates/zapcode-core/src/compiler/. The compiler lowers ZapcodeIR to bytecode instructions. Add new Instruction variants only when necessary — prefer reusing existing instructions.
  4. Add VM dispatch in crates/zapcode-core/src/vm/mod.rs. The main dispatch() function matches on Instruction. Every new instruction needs:
    • Correct stack discipline (verify push/pop balance)
    • Resource limit check before any allocation
    • Use push_call_frame() helper for any function call setup
  5. Write tests before considering the feature done. See AGENTS.md testing philosophy.
  6. Update JS, Python, and WASM bindings if the feature affects the public API surface.

Sandbox invariant checklist

Before submitting any code to zapcode-core, verify:

  • No std::fs::* usage
  • No std::env::* usage
  • No std::net::* or tokio::net::* usage
  • No unsafe block without a // SAFETY: comment
  • No way for guest code to call any function not in the registered externalFunctions map
  • No way for guest code to read or write to any memory outside the VM

If you are implementing an external function bridge: the bridge must validate that the function name exists in the registered set before suspending. An unregistered name must produce ZapcodeError::UnknownExternalFunction, not a panic or a silent no-op.


oxc usage patterns

Zapcode uses oxc_parser for parsing and oxc_ast for AST traversal:

use oxc_parser::{Parser, ParserReturn};
use oxc_span::SourceType;
use oxc_allocator::Allocator;

// Always use SourceType::tsx() — it handles both TS and TSX
let allocator = Allocator::default();
let source_type = SourceType::tsx();
let ret: ParserReturn = Parser::new(&allocator, source, source_type).parse();

if !ret.errors.is_empty() {
    return Err(ZapcodeError::ParseError(format_oxc_errors(&ret.errors, source)));
}

When walking the AST:

  • Use match exhaustively — never _ wildcard on statement or expression nodes. An unhandled node should produce ZapcodeError::UnsupportedSyntax, not be silently ignored.
  • Preserve span information in IR nodes for error messages.
  • Do not use oxc_transformer or oxc_semantic — they add weight we don't need.

Async / await implementation notes

Key invariants:

The VM is single-threaded. There is no Tokio runtime inside the VM.

await on a host function suspends the VM and returns VmState::Suspended. The caller resolves the function externally and calls resume().

await on an internal Promise (e.g., Promise.resolve(42)) is handled entirely inside the VM without suspending.

Do not try to integrate tokio::spawn or async_std into the VM executor.


Performance targets

MetricTarget
First execution latency (simple expression)< 5 µs
Snapshot size (typical agent code)< 2 KB
Snapshot + resume round-trip< 2 ms

Run benchmarks with cargo bench. The benchmark suite is in crates/zapcode-core/benches/.


What to do when you're unsure

  1. Unsupported syntax: emit ZapcodeError::UnsupportedSyntax with the span. Do not silently skip.
  2. Sandbox boundary question: if in doubt, block it.
  3. API design question: follow @pydantic/monty's API shape.
  4. Performance vs correctness: always choose correctness.

Quick reference: public API

Rust

use zapcode_core::{ZapcodeRun, Value, ResourceLimits, VmState, ZapcodeSnapshot};

let runner = ZapcodeRun::new(
    code.to_string(),
    vec!["url".to_string()],
    vec!["fetch".to_string()],
    ResourceLimits::default(),
)?;

// Start — pauses at first external call
let state = runner.start(vec![
    ("url".to_string(), Value::String("https://...".into())),
])?;

match state {
    VmState::Suspended { function_name, args, snapshot } => {
        let bytes = snapshot.dump()?;
        let restored = ZapcodeSnapshot::load(&bytes)?;
        let final_state = restored.resume(Value::String("result".into()))?;
    }
    VmState::Complete(value) => println!("Result: {:?}", value),
}

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.