Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Annotations

Verified against crush-ast v0.13.0 (dc0d0278, 2026-12-03).

An annotation is an @name form written before a declaration (or at the top of a file). Three kinds exist:

AnnotationEffect
@capabilities [ ... ]enforced: the program may use only these capabilities (plus the ambient ones). See Capability System.
@kind( ... )semantics: chooses the object model of the struct that follows. See Structs, Methods and Kinds.
@module, @decision, @invariant, @wip, @temporary, @errorsmetadata: recorded in the program’s CAST for tools and agents; they do not change what the program does.

(@python { ... } and the other @lang blocks look similar but are code, not annotations: see Polyglot Programming.)

Manifest annotations

These describe a module and its decisions in a form an agent can query instead of parsing comments. Each takes a { key: value } body; @decision and @invariant also take a name string.

@module {
    purpose: "Show the manifest annotations"
    exports: [area]
}

@decision "ints-not-floats" {
    chose: "integer sides"
    over: ["float sides"]
    because: "exact output in the docs"
    revisit-if: ["we need fractional sizes"]
}

@invariant "area-non-negative" {
    description: "area never returns a negative number"
    applies_to: [area]
}

@errors {
    Overflow: rare
}
fn area(w, h) {
    return w * h
}

@temporary {
    reason: "demo"
    expires-when: "never"
    added: "2026-10-16"
}
fn helper() { return 1 }

print(area(3, 4))
print(helper())
12
1
AnnotationFields
@modulepurpose, exports, invariants, related
@decision "name"chose, over, because, revisit-if
@invariant "name"description, applies_to, check
@wipintent, done, todo, unresolved
@temporaryreason, expires-when, added
@errorsVariant: likely / possible / rare

@wip marks unfinished work on the next declaration:

@wip {
    intent: "parse the config"
    done: ["read the file"]
    todo: ["validate keys"]
    unresolved: []
}
fn parse() { return "partial" }
print(parse())
partial

Hyphenated keys such as revisit-if and expires-when parse (an old crushc hang on revisit-if, crush-ast #38, is fixed). An @invariant’s check is stored, not executed. (crushc --invariant-runtime emits calls to an invariant.evaluate capability at the top of each targeted function, but crush-run does not provide one, so such a program is refused: not available in this host: invariant.evaluate.)

The AI-native statements

CAST has AI nodes (queries, tool chains, agent delegation, goals, …) for programs that agents emit as JSON; they are described in AI-Native CAST. Two of them also have Crush built-ins, ai_semantic_match(text, target, threshold) and ai_synthesize(prompt), which compile to the same capability-gated call as the CAST SemanticMatch / Synthesize nodes. crush-run has no AI backend, so such a program is refused before it runs; a host that provides ai_native.semantic_match can run it:

let m = ai_semantic_match("refund", "billing", 0.8)
print(m)
[capabilities] … needs capabilities this run does not grant; nothing was run:
  not available in this host: ai_native.semantic_match

The one AI statement with Crush syntax, semantic_switch, parses but is refused at compile time, because it would have compiled to a silent no-op (crush-ast CRUSH-265):

fn route(text) {
    semantic_switch text {
        case "billing question":
            return "billing"
        fallback:
            return "human"
    }
}
print(route("refund please"))
[compile] `semantic_switch` isn't supported yet (CRUSH-265): it would compile to a no-op

Next Steps