Skip to content
Walk definitions

Walk definitions and selectors

A walk definition is a JSON file of kind codegraph.walk/1: the question codegraph walk asks of the code, bottom-up — which units it asks, what it asks them, and the fields each answer must carry. It is data, like a language profile: codegraph walk --walk FILE reads it, checks it, and compiles it before any model is read. The same file format, restricted, customizes codegraph explain (below).

This page is derived from packages/insights/src/definition.ts (the file format), packages/insights/src/selection.ts (what a selection means for the walk) and packages/analyzer/src/selectors.ts (the selector grammar). Every example on it is checked by packages/cli/test/docs-walk-definitions.test.ts, which parses each codegraph.walk/1 block of the documentation through the same schema the command uses.

A complete example

On the Java fixture: the two operations annotated @Audited, and the types above them.

{
  "kind": "codegraph.walk/1",
  "name": "audit",
  "version": "1",
  "levels": ["operation", "type"],
  "select": { "edge": { "kind": "annotationUse", "to": { "name": "Audited" } } },
  "closure": "containers",
  "prompt": {
    "task": {
      "operation": "@Audited marks a method whose calls must reach the audit log. Say what a call of this operation would record, and whether anything in its source or its callees sends it to a log at all.",
      "type": "Say which of this type's operations are audited, and whether its state can change outside them."
    },
    "instructions": "Answer in English. Quote the annotation's value when it matters.",
    "entities": [
      { "select": { "name": "Reporting" }, "instructions": "Reporting runs monthly: say what max returns on an empty list." }
    ]
  },
  "answer": {
    "label": "logged",
    "fields": {
      "operation": { "logged": { "enum": ["yes", "no", "unclear"] }, "recorded": "string[]" },
      "type": { "unaudited": { "list": { "operation": "string", "why": "string" } } }
    }
  }
}
$ codegraph walk fixtures/java/expected/model.jsonl --src fixtures/java/src --walk audit.json --dry-run
walk plan (audit): 77 units in 8 layers
  operation     57 units      2 calls ~1250 prompt tokens
  type          17 units      2 calls ~1792 prompt tokens
  module         3 units      0 calls ~0 prompt tokens
  statuses: llm 4, template 0, reuse 0, skip-scope 73, skip-budget 0
  selection: 13 dependencies of the selection are not walked (12 unselected, 1 trivial, skipped); without a record, shown as NOT EXPLAINED
  --closure all adds 24 units (operation 19, type 5, module 0)
  models: openai/gpt-5.6-luna (operations), openai/gpt-5.6-luna (types, modules); depth 1
  total: 4 calls, ~3042 prompt tokens in, ~2240 completion tokens out

(The cache line and the per-unit lines are trimmed. The four llm units are Reporting.max(List), Order.discount(int), Reporting and Order.)

Every key

Every key but kind is optional. Every object is strict: an unknown key, at any depth, is refused with its path and the valid keys.

KeyTypeDefaultRules
kind"codegraph.walk/1"requiredthe only kind this build reads
namestring"adhoc"matches [a-z][a-z0-9-]*; explain and insights are reserved. The walk’s store is <model>.NAME.walk.db
versionstring"1"trimmed, not empty. Hashed into every unit’s fingerprint: bump it to ask every unit again
levelsarray of operation, type, moduleall threenot empty, no level twice; a set (its order is not read)
selecta selectoreverythingwhich units are asked (rule 1)
excludea selectornothingwhich units are never asked; wins over select
rootsa selector, "entries" or "sources"nonewhere reach is measured from: the entities a selector selects by rule 1, the classified entry points (the entry term, with --boundaries), or the units nothing of their level depends on
reach.maxDepthinteger ≥ 0, or nullnull (the whole reach)with roots: a unit is asked only when it is at most this many breadth-first steps from a root. reach without roots is refused
reach.viafacts, candidates, dispatchfactsthe inferences a step may take, each adding to the one before (reach)
directionup, downupdown asks each unit after the operations in reach that call it, and shows it what reaches it; it needs roots, levels: ["operation"] and closure: "none". Absent from the canonical form of an up walk
layeringnearest, all-callersnearesta down walk’s order; refused on an up walk
closurenone, dependencies, containers, allnonewhat the selection adds of what it leans on (rule 4)
trivialskip, askskipwhether a trivial member (a getter, a setter, equals/hashCode/toString/compareTo, a field-assigning constructor) is asked; skipped, it is shown to its dependents as NOT EXPLAINED
context.depthinteger ≥ 11how many levels of dependency answers a prompt carries (--depth)
context.maxLinesinteger ≥ 1200source lines shown per member before the middle is elided (--max-lines)
context.sourcetruetruefalse is refused, “not supported yet”: the engine always shows source
context.memberstrue, falsefalsetrue: a call or a field access into a stub names the member it reaches, each one its own line (members); false is the default spelled, absent from the canonical form. Refused by explain --walk
context.maxDependentsinteger ≥ 120a down walk’s: a unit called by more operations in reach is a hub and quotes none of them; refused on an up walk
context.quotesa walk name, or explainnoneanother walk whose store the prompts quote, read only: its description of each unit and of the unit’s callees (quoting). Not this walk’s own name
prompt.taskstring, or { operation?, type?, module? } of stringsa neutral task per levela string is every level’s task; a level the object leaves out keeps its default. Trimmed, not empty
prompt.instructionsstring"" (none)appended to every unit’s system message, under ## Instructions
prompt.entitiesarray of { select, instructions }[]select is required, instructions not empty; kept in file order. Each closes the section of every member its selector selects by rule 1, under Instructions for this member:
answer.labelstringnonenames a scalar or enum field declared at one level at least; a dependent is shown label: value beside the description
answer.fields.operation, .type, .module{ name: field type }{}the field grammar; a level with no fields answers answer, description, confidence only
answer.builtinstringnonerefused in a walk file: the one built-in answer is explain’s (specy.domain/3), which the grammar does not spell

No task or instruction text may hold four backticks (the prompt’s corpus fence), so an instruction can never open or close the fence that marks source as material. Three backticks are allowed.

A task or fields given for a level outside levels are kept, not refused: they say what that level would be asked, and --levels can then narrow a file without making it invalid or moving a fingerprint.

The smallest useful file names the walk and its task:

{
  "kind": "codegraph.walk/1",
  "name": "state-changes",
  "prompt": { "task": "Say which state this code changes, and who can observe the change." }
}

codegraph walk --print-definition prints the default definition with every key spelled — a file to start from. On this build:

{
  "kind": "codegraph.walk/1",
  "name": "adhoc",
  "version": "1",
  "levels": [
    "operation",
    "type",
    "module"
  ],
  "closure": "none",
  "trivial": "skip",
  "context": {
    "depth": 1,
    "maxLines": 200,
    "source": true
  },
  "prompt": {
    "task": {
      "operation": "Answer this walk's instructions about this operation, the general ones and any given for it in the prompt, from its source, its facts and what its callees are said to do. Where none applies, say what it does.",
      "type": "Answer this walk's instructions about this type, the general ones and any given for it in the prompt, from its source, its fields and what its members and the types it uses are said to do. Where none applies, say what it is for.",
      "module": "Answer this walk's instructions about this module, the general ones and any given for it in the prompt, from what its types are said to do and what it imports. Where none applies, say what it is about."
    },
    "instructions": "",
    "entities": []
  },
  "answer": {
    "fields": {
      "operation": {},
      "type": {},
      "module": {}
    }
  }
}

The field grammar

Every block a walk writes is answer, then the declared fields by name, then description and confidence:

  • answer is the response to the task, in full;
  • description summarizes it in at most 60 words for a reader who sees only that line. It is what flows upward: the units that depend on this one are shown its description (and the label, if any), never the rest;
  • confidence is the model’s own claim, 0 to 1, clamped on receipt.

A field type is one of:

FormJSON
a string, a number, a boolean"string", "number", "boolean"
a list of strings"string[]"
one of fixed values, in this order{ "enum": ["low", "medium", "high"] }
a list of objects{ "list": { "field": ITEM, … } }, where ITEM is a scalar, an enum, an anchor or an entity
evidence the prompt showed"anchor", { "anchor": { "mentions": "field" } }, "entity" — checked fields
any object form, nullableadd "nullable": true — so a nullable scalar is { "type": "string", "nullable": true }

The grammar is closed: a list does not nest and holds no string[], an enum needs at least one value and no value twice, a list item needs one field at least. Field names match [A-Za-z][A-Za-z0-9_]*. description, answer, confidence, words, glossary and concept are refused as a block’s field names (the first three are every block’s own; words, glossary and concept are explain’s, and the store indexes concept from every block); a list item may use them.

Every field is required in the answer — strict structured output allows nothing else — so “this may not apply” is spelled nullable, and the model answers null. Fields are ordered by name, so reordering them in the file moves nothing.

{
  "kind": "codegraph.walk/1",
  "name": "error-handling",
  "levels": ["operation"],
  "prompt": { "task": "Say how this operation reports a failure to its caller." },
  "answer": {
    "label": "reports",
    "fields": {
      "operation": {
        "reports": { "enum": ["throws", "returns-null", "returns-flag", "logs", "silent"] },
        "exceptions": "string[]",
        "retried": "boolean",
        "branches": "number",
        "owner": { "type": "string", "nullable": true },
        "paths": { "list": { "condition": "string", "outcome": { "enum": ["caller", "swallowed"] }, "line": { "type": "number", "nullable": true } } }
      }
    }
  }
}

With answer.label set to reports, the prompt of a caller lists this operation as - NAME [operation, reports: throws] (ID): DESCRIPTION. A level that does not declare the label, or an answer whose label is null or empty, shows [operation] and the description alone.

Checked fields: anchor and entity

Two more types ask for evidence and refuse an answer that has none. Both are legal as a block field and as a list item.

FormJSONAnswered asKept only when
an anchor"anchor", { "type": "anchor" }{ "file": "…", "line": 12 }the line is one the prompt showed: in a Source (file:first-last) slice of a member it showed in full, not in an elided middle
an anchor that mentions a field{ "anchor": { "mentions": "key" } }the sameas above, and that line contains the text of the sibling field key (a string or an enum of the same level, or of the same list item) — the check against an invented name
an entity"entity", { "type": "entity" }an entity idthe id is one the prompt wrote: a member’s, a part’s, a dependency’s

The checks run when the answer is received. A list item that fails is dropped; a block field that fails is set to null. So a checked block field is always nullable — "nullable": false on one is refused — while a checked item field is nullable only when it says so (null claims nothing and passes). The record’s metadata counts what was lost (checks.dropped, checks.nulled, and per field checks.field.NAME with the kinds checked and checks.field.NAME.lost), and a level that declares a checked field states each check in an ## Evidence section of its system message. In the prompts of a level that declares an anchor, every shown source line carries its file line number ( 9 | public int total() {; an elided middle keeps its marker, unnumbered), and an anchor’s line is that number; a mentions check reads the line’s own text, never its number. A level with no anchor shows its source unnumbered, exactly as before. A checked field cannot be the answer.label.

A passed check proves that the line was shown and holds the name — never that the line means what the answer says. What a checked walk writes is still a judgement: codegraph insights --claims prints it as a claim.

{
  "kind": "codegraph.walk/1",
  "name": "process-state",
  "levels": ["type"],
  "prompt": { "task": "Say which keys this process keeps in its state, each with the line that names it, and whether the state is a record or a dictionary." },
  "answer": {
    "fields": {
      "type": {
        "shape": { "enum": ["record", "dictionary", "unclear"] },
        "keys": { "list": { "key": "string", "at": { "anchor": { "mentions": "key" } } } },
        "owner": "entity"
      }
    }
  }
}

A definition that declares no checked field digests, prompts and fingerprints exactly as before these types existed; one that does has another answer digest, so it is another walk with its own store.

Members of a stub: context.members

An edge into an external module or type names the member it reaches when the extractor writes it (member, MM-6): println on the call into PrintStream, lookup/2 on the call into :ets. A prompt does not show it unless the definition asks, so that explain’s paid records and every earlier walk keep their prompts. With "context": { "members": true } each call and each field access into a stub is shown with its member, and an extractor that merges equal edges (Java, C#, Ruby, Python) shows one line per member where it would show one line for the stub:

On the fixturesWithout (explain, and any definition that does not opt in)With context.members: true
Java, System.out.println(message)- PrintStream of PrintStream (external) and - read System.System (external)- println of PrintStream (external) and - read System.out (external)
Java, v.isEmpty() ? null : v.get(0)- List of List (external)- get of List (external) and - isEmpty of List (external)
Elixir, %Ecto.Changeset{valid?: true}, %Ecto.Changeset{changeset | errors: []}- read Ecto.Changeset.Ecto.Changeset (external) and - write Ecto.Changeset.Ecto.Changeset (external)- read Ecto.Changeset.valid? (external) and - write Ecto.Changeset.errors (external)
Elixir, :ets.lookup(@table, sku)- ets of ets (external)- lookup/2 of ets (external)

An edge that names no member renders as it always did. The opt-in is hashed: it is in the definition digest and in every unit’s fingerprint, so turning it on asks the walk’s units again; a definition without it digests and fingerprints as before. Trivial members are decided on the facts without members either way, so the opt-in moves no unit in or out of a trivial: "skip" walk.

Selectors

A selector names entities. It has two spellings of one grammar: a term of text, which is what --include and --exclude take (one term per flag), and JSON, which is what a file’s select, exclude and prompt.entities[].select hold, and which alone can compose.

TermJSONMatches an entity when
id:ID{ "id": "ID" }it is that entity — the id verbatim, as the model renders it, compared as an opaque token
kind:K{ "kind": "K" }its kind is K (class, method, package, module…)
trait:T{ "trait": "T" }it declares the trait T (TComment, TWithValue…)
lang:L{ "lang": "L" }the model that declares it is of language L: a profile code, java, csharp, ts, ex, rb
name:GLOB{ "name": "GLOB" }its own name matches
module:GLOB{ "module": "GLOB" }the name of its containing module (a module is its own) matches
file:GLOB{ "file": "GLOB" }its anchor’s file, relative to the model’s root, matches
edge:KIND{ "edge": { "kind": "KIND" } }it writes an edge of that kind
edge:KIND>TERM{ "edge": { "kind": "KIND", "to": SELECTOR } }it writes an edge of that kind to an entity the nested selector matches
edge-in:KIND{ "edgeIn": { "kind": "KIND" } }an edge of that kind points at it (the analyzer’s derived inverse, in memory)
edge-in:KIND<TERM{ "edgeIn": { "kind": "KIND", "from": SELECTOR } }an edge of that kind points at it from an entity the nested selector matches
—{ "edge": { "kind": "KIND", "member": "GLOB" } }, the same on edgeInthe edge also names a member of its stub target (MM-6, edges) that the glob matches; an edge that names none never matches. Combines with to/from: { "edge": { "kind": "invocation", "to": { "name": "Ecto.Repo" }, "member": "insert*" } }
entry{ "entry": {} }a boundaries file’s inventory holds it, classified by a rule
entry:KIND{ "entry": { "kind": "KIND" } }the same, of one kind of stimulus (entry:inbound request); entry:unclassified: a row no rule classifies (layer no caller)
outbound{ "outbound": {} }it writes an edge that crosses to a stub an outbound rule names (an outbound row’s from)
outbound:KIND{ "outbound": { "kind": "KIND" } }the same, to one system kind (outbound:database)
rule:NAME{ "rule": "NAME" }one rule found it: an inbound rule’s entries, an outbound or effect rule’s crossing entities (rule:inbound.types:*Controller)
—{ "all": [SELECTOR, …] }every one matches (all: [] matches everything)
—{ "any": [SELECTOR, …] }one at least matches (any: [] matches nothing)
—{ "not": SELECTOR }the selector does not match

The vocabulary is core’s. An unknown kind, trait, language or edge kind is an error that lists the valid names, never a silent empty match:

$ codegraph walk fixtures/java/expected/model.jsonl --src fixtures/java/src --prompt "What does this do?" --include edge:calls --dry-run
codegraph: --include "edge:calls": unknown edge kind "calls"; valid: import, inheritance, interfaceImplementation, invocation, access, reference, embedding, traitUsage, fileInclude, annotationUse, throws
One selector term per flag, PREFIX:VALUE: id:ID, kind:K, trait:T, lang:L, name:GLOB, module:GLOB, file:GLOB, edge:KIND or edge:KIND>TERM, edge-in:KIND or edge-in:KIND<TERM; with --boundaries FILE, entry, entry:KIND, outbound, outbound:KIND, rule:NAME (a kind with a space is one quoted word: 'entry:inbound request'). Repeat the flag for several (any of them).

kind: takes every kind some profile declares, since a term does not know its model’s language when it is parsed.

Text form. A term is split at its first :. An id: or a glob runs verbatim to the end, so an id holding :, /, # or < needs no escape. edge: splits its value at the first >, edge-in: at the first <, and the rest is parsed as a whole term, so terms nest: edge:invocation>edge:throws is “calls something that throws”. In a shell, quote a term that holds > or <.

Globs. * matches within one segment, ** across segments (and, between separators, no segment at all, as a shell globstar does). A glob must match the whole string, case-sensitively, with no escape: * is always a wildcard, and an exact name is an id:. The segment separator of file: is /. That of name: and module: is the one the language profile states for the entity’s kind — . for a Java package or a C# namespace, / for a TypeScript, Elixir or Ruby file module, :: for a Ruby constant. So on Java, module:com.acme.order* does not reach a sub-package and module:com.acme.order** does. An unnamed entity (a constructor, a lambda) matches no name:; a stub with no parent matches no module:; a package has no anchor and matches no file:.

Members. member has no text form: edge:KIND>TERM is unchanged, and a selector that names a member is written in JSON. Its glob is one segment, so * crosses the / of an Elixir arity: insert* matches insert/2. A member is spelled as the extractor writes it (the language’s reference page says which), and an extractor that names none yet makes every member selector match nothing — codegraph validate prints members named: N of M edges to stubs.

Views. A selector matches inside the view’s projection: under --internal-only a stub matches nothing, under --declared-only an edge term sees declared edges only (there is no provenance syntax of its own), and not complements within the view.

Boundary terms. entry, outbound and rule match what a boundaries file finds, so they need one: --boundaries FILE on walk and explain (a definition names no file). Without it such a term is an error that says so, never an empty match; a rule: the file does not hold is an error listing the file’s rules, while one it holds that found nothing simply selects nothing. A kind is written as the vocabulary spells it, spaces included — on a command line quote the whole term, --include 'entry:inbound request' — and entry and outbound also stand alone. rule: takes the whole rest as the rule’s name, colons, >, * and dots included, so edge:invocation>rule:outbound.effects:Ecto.Repo>insert* is “calls something that inserts”. The rules are applied to the whole model, as the analyze reports apply them; the terms then match inside the view. A definition whose selectors read a boundaries file records the file’s rules in its digest: the same text over other rules is another definition.

Nothing is folded. A term matches the entity itself: a type does not “have” its methods’ invocations. Containment enters through the walk’s rule 1, below.

On the Java fixture, counted with the analyzer: edge:annotationUse>name:Audited matches 2 entities (Order.discount(int) and Reporting.max(List)), module:com.acme.order 137, module:com.acme.order** 152, file:**/legacy/** 8, edge:invocation>module:java.io** 1 (Notifications.log(String)), edge-in:inheritance 4.

What a selection means for the walk

The walk is built over the whole model, whatever the selection: units, cycles, order and fingerprints never depend on it. A selection only decides which units are asked. So an answer bought under one filter is reused by any later run whose inputs match.

  1. The member, its nearest type, its nearest module. A unit’s member is selected when it, its NEAREST containing type, or its nearest containing module matches select (no select: everything), and none of the three matches exclude. Exclude always wins. Containment is not transitive: a sub-package’s units are not reached through its parent package, nor a nested type’s through the type around it — a sub-tree is a glob (module:com.acme.order**).
  2. Levels. A unit is asked only if its level is in levels.
  3. A cycle is one unit. A cycle is asked when one member is selected, and not asked when one member is excluded: asking it would ask the excluded member too.
  4. Closure. dependencies adds every unit the selection transitively depends on, so each asked prompt sees its callees answered; containers adds the type and the module above a selected unit; all both. Closure never adds a unit that is barred — outside levels, reached by exclude, or a trivial member under trivial: "skip" — and dependencies does not walk on through one. containers reaches the module above an operation even when the type between them is barred; a parent package is not a container.
  5. Reach, when roots is set: a unit selected by rules 1–3 that is farther than reach.maxDepth from the roots, or not reached at all, is not selected (it is counted as outside the reach). It narrows before closure, so containers still brings the type and module above a reached operation back, and dependencies still adds every callee of an asked unit, past the bound. Below.
  6. Not selected is skip-scope. Such a unit is never called. When the store holds a record with its fingerprint, the record is reused; otherwise it is shown to its dependents as NOT EXPLAINED, and that absence is part of their fingerprints — so they are asked again once it is answered.

The plan prices what a selection leaves out. On the Java fixture, the two @Audited operations:

$ codegraph walk fixtures/java/expected/model.jsonl --src fixtures/java/src --prompt "Which of these is audited, and what does the audit record?" --include 'edge:annotationUse>name:Audited' --dry-run
walk plan (adhoc): 77 units in 8 layers
  operation     57 units      2 calls ~1122 prompt tokens
  type          17 units      0 calls ~0 prompt tokens
  module         3 units      0 calls ~0 prompt tokens
  statuses: llm 2, template 0, reuse 0, skip-scope 75, skip-budget 0
  selection: 1 dependency of the selection is not walked (1 unselected); without a record, shown as NOT EXPLAINED
  --closure dependencies adds 2 units (operation 2, type 0, module 0)
  models: openai/gpt-5.6-luna (operations), openai/gpt-5.6-luna (types, modules); depth 1
  total: 2 calls, ~1122 prompt tokens in, ~1000 completion tokens out

The selection: line counts the direct dependencies of asked units that are not asked, by why; the --closure line what the next closure would add, transitively. Both are a cold plan’s figures: a dependency the store already answered is reused and quoted rather than shown as NOT EXPLAINED.

Reach: what lies near the roots

roots and reach ask only what lies within N breadth-first steps of the roots. The distance is the reach report’s, over entities, on the inference reach.via states: every member of a root unit is at 0, a step is a call or an access (declared only, under facts) or the step from an operation into a lambda written inside it. A unit takes the smallest distance of its members, so a cycle is one unit at its nearest member’s distance. A type or a module is not reached by calls: it is at a distance only as a root, and comes in through closure: "containers".

{
  "kind": "codegraph.walk/1",
  "name": "near-the-edge",
  "levels": ["operation", "type"],
  "roots": { "entry": { "kind": "unclassified" } },
  "reach": { "maxDepth": 1, "via": "facts" },
  "closure": "containers",
  "prompt": { "task": "Say which use case this code serves." }
}

Order of the rules: select/exclude per entity (rule 1), levels, cycles and trivial, then reach, then closure; exclude wins over all of them. On operations r → a → b, b ⇄ d (one unit), b → c, with r the root: maxDepth: 1 asks r and a; maxDepth: 2 adds the cycle {b, d}; no bound adds c; an exclude of d bars the cycle whatever the bound; containers adds the types and the package above r and a.

The plan prices each depth before any spend — one plan per bound, with no budget — so choosing a depth is choosing a price. On the Java fixture, from the operations nothing calls (the spring table classifies none of them there):

$ codegraph walk fixtures/java/expected/model.jsonl --src fixtures/java/src --prompt "Say what it does." --roots entry:unclassified --boundaries plugin/references/stacks/spring.json --max-depth 1 --closure containers --estimate --price-in 0.10 --price-out 0.60
  reach: from entry:unclassified (32 root units) via facts, max depth 1; the reach ends at depth 2
    depth        units   calls   input tokens  output tokens       cost
    0               49      49         29 102         28 020    $0.0197
    ≤ 1             56      56         32 697         31 640    $0.0223
    all (≤ 2)       58      58         33 728         32 640    $0.0230

The last row, under a bound the reach goes past, is the whole reach: what lifting the bound would cost. --json carries the table as reach.depths. Under --max-calls, the calls go to the nearest units first: skip-budget falls on the farthest (ties in walk order). Without roots the budget is spent in walk order, dependencies first, as before.

The walk stays the one built over the whole model: roots, reach and the boundaries file move no unit, no cycle, no layer, and no fingerprint but through a dependency they leave without a record — so what a bounded run buys, a deeper run reuses.

Rule 1 tries the whole selector on each of the three. A not inside select is therefore rarely what is meant: { "all": [{ "module": "com.acme.order**" }, { "not": { "file": "**/legacy/**" } }] } still asks everything in com.acme.order.legacy, because that package — the members’ nearest module — matches both halves (a package has no file). Say it with exclude:

{
  "kind": "codegraph.walk/1",
  "name": "order-api",
  "levels": ["operation", "type"],
  "select": { "module": "com.acme.order**" },
  "exclude": { "any": [{ "file": "**/legacy/**" }, { "edgeIn": { "kind": "inheritance" } }] },
  "prompt": { "task": "Say whether code outside this package could depend on this, and what would break if it changed." }
}

That plans 58 calls on the Java fixture: none in legacy/, none for the types something extends (AbstractOrder, Priceable) nor for their members — and none for Money, which shares a type cycle with Priceable: one excluded member leaves the whole cycle unasked (rule 3).

What moves a fingerprint. A unit hashes what explain’s units hash — the prompt version, the model slug, the level, its members’ source slices as shown (so context.maxLines counts), comments, signatures and facts, context.depth, its dependencies’ hashes and the ids of those that had no record — plus, for a defined walk, the definition’s version, its level’s system message (the task and prompt.instructions), its level’s answer schema, the label, the entity instructions that reach its members, and context.members when it is true (with the members its facts then show). A down unit hashes the callers it quotes in place of its dependencies, and direction and layering; a quoting unit, each quoted record’s fingerprint. name, select, exclude, roots, reach, levels, closure, trivial and the boundaries file are not hashed: a selection moves a fingerprint only through a dependency it leaves without a record. Editing prompt.instructions, version, a string task or the label asks every unit again; editing the operation task or an operation field asks the operations again and every unit that depends on them; an entity instruction, the units of the members it selects and their dependents. The answer text is never hashed.

Down: what reaches a unit first

"direction": "down" turns the order over. An up walk asks a unit after what it depends on and shows it its callees’ answers; a down walk asks an operation after the operations in reach that call it, and shows it their answers: the use it serves, not the parts it is made of. It walks from roots, within reach, at the operation level only (levels: ["operation"]; cross-level edges point downward, and turning them over is its own design), with no closure.

{
  "kind": "codegraph.walk/1",
  "name": "purpose",
  "direction": "down",
  "levels": ["operation"],
  "roots": { "entry": { "kind": "unclassified" } },
  "reach": { "maxDepth": 3 },
  "context": { "depth": 2 },
  "prompt": { "task": "Say which use this operation serves, from what reaches it." }
}
  • Layers. Under nearest (the default), an operation’s layer is its distance from a root, so the surface is asked first and a depth bound is a bound on the order too. It quotes the callers nearer a root than itself; a caller as near or farther is listed by its signature under Also reached from, not answered yet when this unit is asked. Under all-callers, every caller in reach is asked first and quoted (Kahn’s order on the callers): no unit is asked before a caller, but the depth no longer bounds the order.
  • The prompt gains a section ## What reaches this: the descriptions of the callers it quotes and, at context.depth 2, one line per unit farther up the chain to the nearest root, root first. What it calls is shown by its facts and as NOT EXPLAINED — this walk asks it later — or by another walk’s description when the walk quotes one. The system message says so in place of the up walk’s rule about dependencies.
  • Hubs. A unit called by more operations in reach than context.maxDependents quotes none of them: its section says Reached from K operations, under M entries: more than this walk quotes (N), so none is shown. A logger serves everything and learns nothing from 400 callers.
  • What an edit re-asks. A down unit hashes the fingerprints of the callers it quotes and, by id and signature, those it lists; a hub hashes none. So editing an operation nothing quotes re-asks it alone, and editing a root re-asks what it reaches through quotes, down to the bound and no farther than a hub. The plan and the estimate print that cone before any spend, and --json carries it as cone:
$ codegraph walk fixtures/java/expected/model.jsonl --src fixtures/java/src --prompt "Say which use this operation serves, from what reaches it." --name purpose --direction down --levels operation --roots entry:unclassified --boundaries plugin/references/stacks/spring.json --max-depth 3 --dry-run
walk plan (purpose): 77 units in 4 layers
  operation     57 units     38 calls ~22963 prompt tokens
  type          17 units      0 calls ~0 prompt tokens
  module         3 units      0 calls ~0 prompt tokens
  statuses: llm 38, template 0, reuse 0, skip-scope 39, skip-budget 0
  selection: 3 dependencies of the selection are not walked (3 trivial, skipped); without a record, shown as NOT EXPLAINED
  reach: from entry:unclassified (32 root units) via facts, max depth 3; the reach ends at depth 2
    depth        units   calls   input tokens  output tokens
    0               30      30         18 110         15 000
    ≤ 1             36      36         21 712         18 000
    ≤ 2             38      38         22 963         19 000
    each row is a plan of its own at that bound, with no budget; units are those asked (records reused are not).
  cone: an edit re-asks its unit and every unit that quotes it, transitively (43 units in reach, layering nearest)
    a root's edit: 1 to 5 units, 1.6 on average over 32 roots; largest: java:com.acme.order/Notifications.freeOf(com.acme.order.Order) (5), java:com.acme.order/Notifications.both(com.acme.order.Order) (4), java:com.acme.order/Batch.running() (3)
    a unit nothing quotes (a leaf of this order): its edit re-asks it alone

(The cache line, the totals and the per-unit lines, in layer order, are trimmed.) direction is hashed into a down unit’s fingerprint and into the definition digest, and the side-car header says "direction": "down". A down walk is another walk: the same name walking the other way is refused on its store, bytes untouched — give it a name of its own.

Quoting another walk

context.quotes names another walk — explain, or a walk whose store is <model>.NAME.walk.db — whose answers the prompts quote. The store is opened read only, never written; missing, empty or another walk’s, it is a usage error before anything is planned. A prompt then shows a section ## What the walk `NAME` says: that walk’s description of the unit and, going up, of its callees; going down, the callees themselves are shown by it under ## What the dependencies do. The quoted record’s fingerprint enters the quoting unit’s, so a unit the other walk answers anew is asked again. The sandwich this allows: explain up, then a down walk quoting it, so an operation is asked knowing both what it does and what it is for.

{
  "kind": "codegraph.walk/1",
  "name": "purpose-explained",
  "direction": "down",
  "levels": ["operation"],
  "roots": "sources",
  "reach": { "maxDepth": 2 },
  "context": { "quotes": "explain" },
  "prompt": { "task": "Say which use this operation serves: what reaches it, and what explain says it does." }
}

The shipped walks

Three definitions ship with the plugin, in plugin/walks/, each asking for checked evidence. A boundaries file is never named inside a definition: it is passed with --boundaries.

WalkAsksSelectsIts answerNeeds
entry-residuewhat calls an operation nothing calls and no rule classifies, or that nothing does{ "entry": { "kind": "unclassified" } }, operationsstimulus (a kind of stimulus, corpus dispatch, test only, dead code, unknown; the label), caller, evidence: a list of { token, at }, at an anchor that mentions tokena stack table or boundaries file with inbound rules
outbound-systemswhich system an operation that crosses the boundary reaches, whether it reads, writes, sends or receives, and what goes out or comes back{ "outbound": {} }, operations; context.members: truecrossings: a list of { system, kind, effect, what, call, at }, at an anchor that mentions calla boundaries file with an outbound half (plugin/walks/example.boundaries.json, fictional, for an Elixir application)
process-statethe keys of a process’s state and whether it is a record or a dictionaryElixir types that use GenServer or implement GenServer or :gen_server (edge selectors, no boundaries file)shape (record, dictionary, other, none; the label), keys: a list of { key, at }, at an anchor that mentions key, initializedBy an entitynothing
codegraph walk fixtures/java/expected/model.jsonl --src fixtures/java/src --walk plugin/walks/entry-residue.json --boundaries plugin/references/stacks/spring.json --estimate
codegraph walk fixtures/elixir/expected/model.jsonl --src fixtures/elixir/src --walk plugin/walks/outbound-systems.json --boundaries plugin/walks/example.boundaries.json --estimate
codegraph walk fixtures/elixir/expected/model.jsonl --src fixtures/elixir/src --walk plugin/walks/process-state.json --estimate
codegraph insights fixtures/elixir/expected/model.jsonl --claims

On the fixtures they ask 30 operations (Java, spring; 30 on Elixir with phoenix), the 4 operations of AcmeOrder.Stock that read or write its ETS table, and the one GenServer, AcmeOrder.Stock. The stack tables of plugin/references/stacks/ hold inbound rules only, so outbound-systems runs with a file written for the code at hand; the example names ETS as a cache and Ecto.Repo as the database.

Customizing explain with a file

codegraph explain --walk FILE reads the same format, restricted to what leaves explain’s answer alone: select, exclude, roots, reach, levels, closure, context (but context.members: true: explain’s prompts never name a member), prompt.instructions and prompt.entities. It may restate the built-in exactly — "name": "explain", "version": "2", "answer": { "builtin": "specy.domain/3" } — and is refused for prompt.task, answer.fields, answer.label, trivial (explain templates trivial members: they are never asked nor skipped), another name, another version or another built-in — and for "direction": "down", layering, context.maxDependents and context.quotes: explain walks up and quotes no other walk. Explain’s blocks are what its readers, the glossary and the Specy skill depend on.

{
  "kind": "codegraph.walk/1",
  "name": "explain",
  "exclude": { "module": "com.acme.order.legacy" },
  "prompt": {
    "instructions": "The team calls a Basket a cart: use both words.",
    "entities": [
      { "select": { "module": "com.acme.order.adapter" }, "instructions": "This package wraps a vendor's ledger client: name what it adapts, and to what." }
    ]
  }
}

A customized explain keeps its kind (codegraph.insights/1) and its store (<model>.insights.db); its header gains walk: { name: "explain", version: "2", digest }, the digest over the instructions alone. A unit no instruction reaches — and every templated unit, which sends no prompt — keeps explain’s fingerprint, so the records already bought for it are reused.

codegraph walk --print-definition explain prints explain as a definition: the one form the grammar cannot spell, its answer, named.

{
  "kind": "codegraph.walk/1",
  "name": "explain",
  "version": "2",
  "levels": [
    "operation",
    "type",
    "module"
  ],
  "closure": "none",
  "context": {
    "depth": 1,
    "maxLines": 200,
    "source": true
  },
  "prompt": {
    "instructions": "",
    "entities": []
  },
  "answer": {
    "builtin": "specy.domain/3"
  }
}

Handed to explain --walk, it changes nothing; handed to walk --walk, it is refused on name and answer.builtin. In this documentation a codegraph.walk/1 block whose name is explain is an explain file, and every other one a walk definition: that is how the documentation test tells them apart.

Faults

Every fault carries its path. The file is checked in two passes — its structure first (keys and JSON types), then what the values say (names, selectors, levels, tasks, the grammar, the label) — and every fault of a pass is reported at once:

$ codegraph walk fixtures/java/expected/model.jsonl --src fixtures/java/src --walk bad.json --dry-run
codegraph: bad.json is not a valid walk definition (4 faults):
  name: must match [a-z][a-z0-9-]* (a lowercase letter, then lowercase letters, digits or "-"), got "Audit"
  context.source: false is not supported yet: the engine shows every member's source (leaving it out is deferred with context.sections, PLAN.md §22.7)
  answer.fields.operation.description: "description" is reserved: every block carries description, answer and confidence, and words and glossary are explain's
  answer.fields.operation.steps.list.inner: a list item holds scalars and enums only: a list does not nest
codegraph walk --print-definition prints one to start from; codegraph walk --print-definition explain, explain's.

A flag folded over a key is named with it — name (from --name): "explain" is reserved for the built-in walk; …. The exit code is 2.

Not supported

  • context.source: false (a walk over facts alone) is read and refused until the engine can leave source out of a prompt and of its hash; context.sections (which facts a prompt shows) does not exist.
  • A different task per entity subset inside one walk: per-entity text is instructions; a different task is a second walk with its own selection.
  • An answer schema beyond the grammar, and prompt templates: the user message’s layout is the engine’s.
  • Selectors over measures (metric:), stereotypes or another walk’s answers.
  • A down walk at the type or module level, or with a closure.
  • A boundaries file named inside a definition: it is the --boundaries flag’s.
  • Selectors on analyze, city and navigator.

See also

codegraph walk · codegraph explain · Ask your own question of the code · Explaining bottom-up

Last updated on