{
 "meta": {
  "title": "Annotations — The Crush Language Guide",
  "description": "Generated from crush/annotations.md of The Crush Language Guide (https://docs.crushlang.org/crush/annotations.html). Edit the guide, not this file: it is regenerated on every build.",
  "frontends": [
   "crush"
  ],
  "author": "The Crush Language Guide",
  "tags": {
   "source": "crush/annotations.md",
   "guide_url": "https://docs.crushlang.org/crush/annotations.html",
   "generator": "scripts/build-notebooks.py"
  }
 },
 "cells": [
  {
   "id": "crush-annotations-md-1",
   "kind": {
    "type": "markdown"
   },
   "source": "# Annotations\n\n> Verified against crush-ast `v0.13.0` (`dc0d0278`, 2026-12-03).\n\nAn annotation is an `@name` form written before a declaration (or at the top of\na file). Three kinds exist:\n\n| Annotation | Effect |\n|---|---|\n| `@capabilities [ ... ]` | **enforced**: the program may use only these capabilities (plus the ambient ones). See [Capability System](https://docs.crushlang.org/crush/capabilities.html#declaring-what-a-program-uses-capabilities). |\n| `@kind( ... )` | **semantics**: chooses the object model of the `struct` that follows. See [Structs, Methods and Kinds](https://docs.crushlang.org/crush/structs.html#kind-choosing-object-semantics). |\n| `@module`, `@decision`, `@invariant`, `@wip`, `@temporary`, `@errors` | **metadata**: recorded in the program's CAST for tools and agents; they do not change what the program does. |\n\n(`@python { ... }` and the other `@lang` blocks look similar but are code, not\nannotations: see [Polyglot Programming](https://docs.crushlang.org/crush/polyglot.html).)\n\n## Manifest annotations\n\nThese describe a module and its decisions in a form an agent can query instead\nof parsing comments. Each takes a `{ key: value }` body; `@decision` and\n`@invariant` also take a name string.\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  },
  {
   "id": "crush-annotations-1",
   "kind": {
    "type": "crush"
   },
   "source": "@module {\n    purpose: \"Show the manifest annotations\"\n    exports: [area]\n}\n\n@decision \"ints-not-floats\" {\n    chose: \"integer sides\"\n    over: [\"float sides\"]\n    because: \"exact output in the docs\"\n    revisit-if: [\"we need fractional sizes\"]\n}\n\n@invariant \"area-non-negative\" {\n    description: \"area never returns a negative number\"\n    applies_to: [area]\n}\n\n@errors {\n    Overflow: rare\n}\nfn area(w, h) {\n    return w * h\n}\n\n@temporary {\n    reason: \"demo\"\n    expires-when: \"never\"\n    added: \"2026-10-16\"\n}\nfn helper() { return 1 }\n\nprint(area(3, 4))\nprint(helper())\n",
   "state": {
    "status": "pending"
   },
   "meta": {
    "tags": [
     "guide",
     "runnable"
    ],
    "extra": {
     "guide": {
      "src": "crush/annotations.md:23",
      "browser": "run",
      "expect_output": "12\n1\n"
     }
    }
   },
   "outputs": []
  },
  {
   "id": "crush-annotations-md-3",
   "kind": {
    "type": "markdown"
   },
   "source": "| Annotation | Fields |\n|---|---|\n| `@module` | `purpose`, `exports`, `invariants`, `related` |\n| `@decision \"name\"` | `chose`, `over`, `because`, `revisit-if` |\n| `@invariant \"name\"` | `description`, `applies_to`, `check` |\n| `@wip` | `intent`, `done`, `todo`, `unresolved` |\n| `@temporary` | `reason`, `expires-when`, `added` |\n| `@errors` | `Variant: likely` / `possible` / `rare` |\n\n`@wip` marks unfinished work on the next declaration:\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  },
  {
   "id": "crush-annotations-2",
   "kind": {
    "type": "crush"
   },
   "source": "@wip {\n    intent: \"parse the config\"\n    done: [\"read the file\"]\n    todo: [\"validate keys\"]\n    unresolved: []\n}\nfn parse() { return \"partial\" }\nprint(parse())\n",
   "state": {
    "status": "pending"
   },
   "meta": {
    "tags": [
     "guide",
     "runnable"
    ],
    "extra": {
     "guide": {
      "src": "crush/annotations.md:76",
      "browser": "run",
      "expect_output": "partial\n"
     }
    }
   },
   "outputs": []
  },
  {
   "id": "crush-annotations-md-5",
   "kind": {
    "type": "markdown"
   },
   "source": "Hyphenated keys such as `revisit-if` and `expires-when` parse (an old `crushc`\nhang on `revisit-if`, crush-ast #38, is fixed). An `@invariant`'s `check` is\nstored, not executed. (`crushc --invariant-runtime` emits calls to an\n`invariant.evaluate` capability at the top of each targeted function, but\n`crush-run` does not provide one, so such a program is refused: `not available in\nthis host: invariant.evaluate`.)\n\n## The AI-native statements\n\nCAST has AI nodes (queries, tool chains, agent delegation, goals, …) for programs\nthat agents emit as JSON; they are described in [AI-Native CAST](https://docs.crushlang.org/cast/ai-native.html).\nTwo of them also have Crush built-ins, `ai_semantic_match(text, target,\nthreshold)` and `ai_synthesize(prompt)`, which compile to the same\ncapability-gated call as the CAST `SemanticMatch` / `Synthesize` nodes. `crush-run`\nhas no AI backend, so such a program is refused before it runs; a host that\nprovides `ai_native.semantic_match` can run it:\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  },
  {
   "id": "crush-annotations-3",
   "kind": {
    "type": "crush"
   },
   "source": "fn main() {\n    let m = ai_semantic_match(\"refund\", \"billing\", 0.8)\n    print(m)\n}\n",
   "state": {
    "status": "pending"
   },
   "meta": {
    "tags": [
     "guide",
     "expected-failure"
    ],
    "extra": {
     "guide": {
      "src": "crush/annotations.md:110",
      "browser": "fail",
      "why": "this example shows a run-time error",
      "expect_error": "not available in this host: ai_native.semantic_match"
     }
    }
   },
   "outputs": []
  },
  {
   "id": "crush-annotations-md-7",
   "kind": {
    "type": "markdown"
   },
   "source": "```text\n[capabilities] … needs capabilities this run does not grant; nothing was run:\n  not available in this host: ai_native.semantic_match\n```\n\nThe one AI statement with Crush syntax, `semantic_switch`, parses but is refused\nat compile time, because it would have compiled to a silent no-op (crush-ast\nCRUSH-265):\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  },
  {
   "id": "crush-annotations-4",
   "kind": {
    "type": "crush"
   },
   "source": "fn route(text) {\n    semantic_switch text {\n        case \"billing question\":\n            return \"billing\"\n        fallback:\n            return \"human\"\n    }\n}\n\nfn main() {\n    print(route(\"refund please\"))\n}\n",
   "state": {
    "status": "pending"
   },
   "meta": {
    "tags": [
     "guide",
     "expected-failure"
    ],
    "extra": {
     "guide": {
      "src": "crush/annotations.md:125",
      "browser": "fail",
      "why": "this example shows a run-time error",
      "expect_error": "`semantic_switch` isn't supported yet (CRUSH-265)"
     }
    }
   },
   "outputs": []
  },
  {
   "id": "crush-annotations-md-9",
   "kind": {
    "type": "markdown"
   },
   "source": "```text\n[compile] `semantic_switch` isn't supported yet (CRUSH-265): it would compile to a no-op\n```\n\n## Next Steps\n\n- **[Capability System](https://docs.crushlang.org/crush/capabilities.html)**\n- **[AI-Native CAST](https://docs.crushlang.org/cast/ai-native.html)**\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  }
 ]
}
