Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ packages/vocabulary/ @codegraph/vocabulary — the words of the model's NAMES
and SVG; the carriers lookup (which names carry a word).
Pure computation. Its `./cloud` entry is the layout alone
and imports nothing: the one value a frontend may take.
packages/dataop/ @codegraph/dataop — the model LOWERED into a Specy Data &
Operation model (`.dataop`, `observed` level): `lower(graph)`
→ a typed DataOpModel (structs, globals, operations and their
clauses, each with its anchor), `print(model)` → the text.
States what the model holds and nothing else: `opaque`, `?`
or a finding where it holds no fact. Per-language type
tables are data. A projection, never read back. Pure
computation (PLAN §26, docs/dataop.md).
packages/insights/ @codegraph/insights — the bottom-up EXPLANATION walk: units
(operations → types → modules), SCC-condensed walk order,
context packs, prompts, Merkle fingerprints, plan/run, the
Expand Down Expand Up @@ -153,7 +161,7 @@ fixtures/ Reference corpora + expected model.jsonl snapshots.

### Hard boundaries (convenience does not override architecture)

- **`core`, `analyzer`, `city`, `navigator` and `vocabulary` never import Three.js or React**
- **`core`, `analyzer`, `city`, `navigator`, `vocabulary` and `dataop` never import Three.js or React**
— they must run in Node with no DOM. `viz` reads the city model and
`navigator-ui` the navigator model; neither mutates its model and neither
re-derives graph facts the analyzer already computes.
Expand Down Expand Up @@ -315,6 +323,10 @@ node scripts/homebrew/render.mjs --version X.Y.Z --sums SHA256SUMS [--npm-sha256
./bin/codegraph city model.jsonl --layout --out city.json # the artifacts alone
./bin/codegraph navigator model.jsonl --out navigator.json
./bin/codegraph vocabulary model.jsonl [--level module|type] [--scope ID] [--drift FILE] [--svg FILE] # the names' words
./bin/codegraph dataop model.jsonl [--out FILE] [--name NAME] [--boundaries FILE] [--scope SEL] # a Specy Data & Operation
# model (.dataop, observed): structs, globals, operations with depends on / uses / reads / writes / errors; the summary of
# what was not lowered on stderr; docs/dataop.md. Snapshot: fixtures/java/expected/model.dataop
# (CODEGRAPH_UPDATE_SNAPSHOTS=1 pnpm --filter @codegraph/dataop test fixtures)
./bin/codegraph serve model.jsonl --height vocabulary:order --height-scale sqrt # where one word lives, in the city
./bin/codegraph explain model.jsonl --src DIR --dry-run # the walk plan, no call
./bin/codegraph explain model.jsonl --src DIR --estimate --price-in 0.10 --price-out 0.60 # tokens in/out + cost, no call
Expand Down
76 changes: 70 additions & 6 deletions METAMODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ cross-validation meaningful. It is deliberately *not* the same as sorting the
rendered ids as strings, where `/` and `.` are ordinary characters.

**Relations:** every reference between concepts (edge endpoints, `parent`,
`children`, `attachedTo`, `declaredType`, `candidates`) identifies an entity by
its natural key. The v1 file format spells each of those as the rendered id
`children`, `attachedTo`, `declaredType`, `candidates`, and the ids inside a
Literal or a TypeExpr, §1.6–§1.7) identifies an entity by its natural key. The v1 file format spells each of those as the rendered id
string (`EntityId` in core); an encoding is free to spell them otherwise — M6
uses file-scoped integer surrogates — as long as they resolve to the same key.
A surrogate is **not** identity and never crosses a file boundary.
Expand Down Expand Up @@ -156,6 +156,38 @@ Two rules:
**Relations:** carried by Entities via `TWithValue` (§3.6) and by
`annotationUse` edges (§4).

### 1.7 TypeExpr

The **type a declaration writes**, as a tree: `List<OrderLine>`, `int[]`,
`String?`. `declaredType` (§3.4) keeps only the erased head, as a reference —
the raw `List`, nothing for a primitive or an array — so the written type was
not in the model before contract 1.2.0 (MM-7). A tagged union whose tags are a
closed core-owned vocabulary (MM-3), built as Literal is:

| Form | Shape | Notes |
|---|---|---|
| `named` | `{k: "named", type: EntityId, args?: TypeExpr[]}` | a declared type or a stub, with its written type arguments in order. `args` absent when none is written, never empty |
| `primitive` | `{k: "primitive", name: string}` | the language's own word: `int`, `long`, `boolean`, `char` |
| `array` | `{k: "array", of: TypeExpr}` | |
| `nullable` | `{k: "nullable", of: TypeExpr}` | where the language writes it (`T?`, `T \| null`); never inferred from an annotation |
| `function` | `{k: "function", params: TypeExpr[], returns?: TypeExpr}` | `returns` absent = the function returns no value |
| `union` | `{k: "union", of: TypeExpr[]}` | written alternatives, in written order; at least two |
| `variable` | `{k: "variable", name: string}` | a type parameter |
| `unevaluated` | `{k: "unevaluated", source: string}` | a written type the extractor did not structure (a wildcard, an intersection). The source text is still a fact, as for a Literal |

Three rules:

- **A type expression is what is written, never what is inferred.** No
`typeExpr` on a `var`, on an untyped parameter, on a `void` return.
- **Ids inside count for closure** (§8a), exactly as a Literal's: a `named`
type resolves to a declared entity or a stub, and in the M6 encoding it is a
file-scoped surrogate, so a dangling one is unwritable. A type the extractor
cannot name is `unevaluated`, never a fabricated id.
- **A value never replaces a dependency.** The `reference` edges a written type
emits — its head, each of its arguments — are still emitted.

**Relations:** carried by Entities via `TTypedEntity.typeExpr` (§3.4).

---

## 2. Entity
Expand Down Expand Up @@ -193,7 +225,7 @@ Traits marked *(marker)* contribute **no attributes**: they declare a
capability whose data lives in `edges[]` (edges are stored once, outgoing
direction only — see §4).

![The nineteen traits around the entity that composes them, by family; a dashed box is a marker trait](website/assets/diagrams/traits-metamodel.svg)
![The twenty traits around the entity that composes them, by family; a dashed box is a marker trait](website/assets/diagrams/traits-metamodel.svg)

The whole vocabulary on one sheet: an entity composes at most one of each
trait, a dashed box is a marker, and the three red dots are the composition of
Expand Down Expand Up @@ -244,7 +276,7 @@ attachment distinction needs. Only the serialized key goes, in M6.
| `TType` | `isStub: boolean` | any type-like entity: class, interface, struct, enum, protocol, PHP/Rust trait |
| `TWithInheritances` | *(marker)* — see `Inheritance` edges | multiple inheritance = N edges (Python). Absent from Go/Rust profiles — that absence is profile information, not a gap |
| `TWithImplements` | *(marker)* — see `InterfaceImplementation` edges | |
| `TTypedEntity` | `declaredType?: EntityId` | optional even when the trait is present: absent value in JS/Python/Clojure, C# `var`, inferred Go/TS/Rust |
| `TTypedEntity` | `declaredType?: EntityId`, `typeExpr?: TypeExpr` (§1.7) | both optional even when the trait is present: absent value in JS/Python/Clojure, C# `var`, inferred Go/TS/Rust. `declaredType` is the erased head, a reference; `typeExpr` (since contract 1.2.0, MM-7) the type as written, a tree. Neither replaces the other, and neither replaces the `reference` edges the written type emits |

### 3.5 Behavior

Expand All @@ -255,13 +287,27 @@ attachment distinction needs. Only the serialized key goes, in M6.
| `TWithLocalVariables` | `localVariables: EntityId[]` | |
| `TWithInvocations` | *(marker)* — see `Invocation` edges | outgoing only; incoming is derived by the analyzer, never stored |

An invocable that needs an instance — a Java instance method, a constructor —
carries the marker `TWithReceiver` (§3.6), as an instance field does.

### 3.6 Structure

| Trait | Attributes contributed | Notes |
|---|---|---|
| `TStructural` | *(marker)* — value holder | attributes, variables, parameters, Clojure vars. Legal target of `Access` edges |
| `TWithAccesses` | *(marker)* — see `Access` edges | outgoing only |
| `TWithValue` | `value: Literal` (§1.6) | the entity's declaration-site constant value: a Java `static final` constant initializer, an annotation element's `default`, a TS enum member's value, a Clojure def'd constant. Optional wherever licensed — an attribute whose initializer is not a compile-time constant simply carries no value, and absence means "not constant", never "empty" |
| `TWithReceiver` | *(marker)* | the entity is evaluated against an instance of the type it is written in or attached to: a Java instance field, instance method, constructor. Since contract 1.2.0 (MM-8) |

**The receiver marker (MM-8).** Java's `attribute` kind has no word for
static: `Order.MAX_LINES` and `Order.channel` differ only by a constant value,
and an instance method and a static one only by what they may touch.
`TWithReceiver` says it, on the kinds a profile can decide it for, and is
licensed optional there. **In a profile that licenses it on a kind, absence
means "no receiver"** — a static member, an enum constant; in a profile that
does not, absence means nothing. A lambda never carries it: it is evaluated
against what it captures, not against an instance of its own. The `receiver`
of an `access` edge (§4) is its counterpart on the edge.

### 3.7 The composition that motivates the whole design

Expand Down Expand Up @@ -373,6 +419,20 @@ two edges, ordered by member after provenance (absent first). A consumer reads
Decision and evidence: `docs/model-metamodel.md` MM-6. Not to be confused with
the navigator's dependency `member`, which is the corpus entity a row reaches.

**The receiver of an access (MM-8).** An `access` edge may carry
`receiver: "self" | "other"`: `self` when the target is reached through the
accessor's own receiver, written (`this.lines`) or implied (`lines`); `other`
through any other expression (`other.lines`). It is absent when the target has
no receiver (a static field, a local) or when the extractor does not say. It is
legal on `access` only — core's schema refuses it elsewhere — and only when the
target is **not** a stub: a stub has no members (§6), so nothing in the model
says the field reached needs an instance; the integrity rule (`codegraph
validate`, rule `receiver`) reports one that is. Like `member`, it is part of
the edge: `this.lines = other.lines` is a `self` write and an `other` read at
one site — two facts — so it orders edges after `member`, absent first. A
consumer reads `edge.receiver`; `model.db` holds it in `edge.receiver` and the
`dep` view. Decision and evidence: `docs/model-metamodel.md` MM-8.

![The edge in the middle: its eleven kinds in four families, its four provenance values, the entities at its ends, its anchor and the profile that licenses it](website/assets/diagrams/edges-metamodel.svg)

The relation on one sheet: an edge has exactly one kind, so at most one of a
Expand Down Expand Up @@ -406,7 +466,7 @@ Eleven kinds, in four families by what an edge connects.
| Kind | From → To | Extra attributes | Notes |
|---|---|---|---|
| `invocation` | Invocable → Invocable | `candidates`, `member` (to a stub) | uncertain dispatch → `provenance: dynamic-candidate` + candidates list |
| `access` | Invocable → Structural | `isRead: bool`, `isWrite: bool`, `member` (to a stub) | field/variable reads and writes |
| `access` | Invocable → Structural | `isRead: bool`, `isWrite: bool`, `member` (to a stub), `receiver` (not to a stub) | field/variable reads and writes |
| `throws` | Invocable → Type (exception) | | a written `throw` statement whose static exception type resolved; the anchor is the throw SITE — the evidence a guard clause leaves. A declared propagation clause (Java `throws E`) is a plain `reference`, not this. Distinct from `reference` so failure exits are selectable without reading the target's kind, which a stub target cannot answer |

#### References
Expand Down Expand Up @@ -603,7 +663,11 @@ already knows the per-frame sha.
The integrity properties a model must satisfy, whatever encodes it:

- **closure** — every reference resolves to a declared entity or a stub (§4,
§6), the ids inside `Literal` values included (§1.6);
§6), the ids inside `Literal` values and `TypeExpr` trees included (§1.6,
§1.7);
- **member and receiver legality** — an edge's `member` only on an
`invocation`, `access` or `reference` to a stub, its `receiver` only on an
`access` to an entity that is not one (§4);
- **no self-reference** — `from ≠ to` on every edge;
- **provenance set** on every edge, from the closed set of §1.3;
- **profile validity** for every entity (§5);
Expand Down
Loading
Loading