Skip to content

op code

Mikhail Deynekin edited this page Nov 22, 2026 · 7 revisions

code

Symbol bodies — only on an explicit request.

Group Navigation and reading
Edition community — works without a licence
Capability search — the feature that carries this operation; the licence matrix is on 15 · Editions and licensing
MCP tool ragraf_code · read-only · idempotent
CLI ragraf -p <config> query code …

Why it exists

Bodies are returned only on an explicit request, so a search never spends context on code nobody asked for. Every change here closes a measured defect: a hit's identifiers could not be used as input, start and end were accepted and ignored, a container class was returned together with its 51 methods and doubled the sum to 1.80 times the file, the limit truncated without saying so, and text could only come from disk.

What it solves

  • Read the body of a symbol, or a window inside it, and read text from the index rather than from disk, so a file changed after indexing does not change the answer.
  • Use a hit's own identifiers (chunk_id, node_id) as the next call, instead of searching the file again.
  • See what was dropped: nested spans are counted in nested_dropped, the tail in truncated and spans_total, and the source of each text in text_source (index or disk).
  • Narrow by a real window: spans are selected by intersection with start/end, and an answer with no text at all is not reported as found.

How to use it

The call that produced the answer below, as a command line:

$ ragraf -p demo-corpus.yaml query code --path src/app/utils.py

The same call through MCP: ragraf_code().

The answer below was captured on the demo corpus, not written for the page:

{
 "op": "code",
 "index_rev": "rev-0002",
 "capability": "degraded",
 "provenance": "index",
 "found": true,
 "result": [
  {
   "index": 0,
   "path": "src/app/utils.py",
   "symbol": "src/app/utils.py:digest",
   "start_line": 6,
   "end_line": 8,
   "window": {
    "start": 6,
    "end": 8
   },
   "changed_since_index": false,
   "text_source": "index",
   "text": "def digest(text: str) -> str:\n    \"\"\"Stable digest of a text, used for cache keys.\"\"\"\n    return hashlib.sha256(text.encode(\"utf-8\")).hexdigest()"
  },
  {
   "index": 1,
   "path": "src/app/utils.py",
   "symbol": "src/app/utils.py:chunk",
   "start_line": 11,
   "end_line": 13,
   "window": {
    "start": 11,
    "end": 13
   },
   "changed_since_index": false,
   "text_source": "index",
   "text": "def chunk(items: list[str], size: int = 2) -> list[list[str]]:\n    \"\"\"Split a list into fixed-size groups.\"\"\"\n    return [items[index:index + size] for index in range(0, len(items), size)]"
  },
  "... 1 more"
 ],
 "limits_count": 1
}

The call succeeded. The answer is trimmed to two items per list and to the fields that carry no Russian prose: limits and the explanatory strings are counted in the footer below instead of being quoted.

Parameters

Name Type Default
fqn str | None None
path str | None None
style str 'compact'
limit int 5
entry_ids str | None None
start int | None None
end int | None None
source str 'auto'
include_containers bool False

What it returns

result is assembled at runtime, so the code carries no static list of its keys: the shape is whatever the sentence above describes, and the diagram below shows the steps that build it.

The body also writes these fields into the answer envelope itself (extra): gaps, nested_dropped, resolved, spans, spans_returned, spans_total, spans_with_text, suggest, truncated, unresolved, without_body.

The envelope around the result is the same for every operation; how to read it: 04 · Operations reference.

How it works

Step What happens
Reads none of the three stores directly — the answer comes through the engine the body calls, or from what the call is given
Calls util.decode_text, util.to_posix
Guarded by the index revision is read (current_rev), so every fact belongs to a named revision; a missing index is refused by name (_no_index) instead of raising
Writes gaps, nested_dropped, resolved, spans, spans_returned, spans_total, spans_with_text, suggest, truncated, unresolved, without_body into the answer envelope
Empty answer yes, and names where to go instead: search, symbol
flowchart TD
  Start[query code]
  Rev{index revision}
  NoIndex[refused: no index]
  Call0[util.decode_text]
  Call1[util.to_posix]
  Found{found}
  Empty[empty result + suggest: search symbol]
  Out[envelope with result]
  Start --> Rev
  Rev -- none --> NoIndex
  Rev -- rev-N --> Call0
  Call0 --> Call1
  Call1 --> Found
  Found -- no --> Empty
  Found -- yes --> Out
Loading

Where it stops

Every answer carries a limits field, and it is never empty when a boundary exists: that is where the limits of this particular call are named — which part of the corpus was not covered, which fact could not be confirmed, what the operation refused to guess.

The boundary of the whole Navigation and reading group is stated once, on the reference page. It is a sentence about the group, so it is not repeated here as if it were a sentence about code.

Around this group

← previous in the group: references

→ next in the group: live_read

The full table with all 87 operations · A–Z index · Navigation and reading


Where these fields come from: the parameters, their types and defaults are read from the signature op_code in src/ragraf/facade.py:4287 (line numbers as of 0.12.0); the MCP annotations from the tool registration; the edition from src/ragraf/edition_baseline.json; the guards, calls, stores, envelope fields and the diagram from the body of that same method. The example is a run of tools/build-op-examples.py on the demo corpus at revision rev-0002; fields whose value is Russian prose in this build (limits, explanatory strings) are counted, not quoted. Nothing else on this page is written by hand.

The reason and the tasks above are a translation of the docstring of op_code, src/ragraf/facade.py:4287, kept in tools/op-text.json next to the line it came from. That file is the only hand-written text in the pipeline; the gate tools/check-op-text.py checks that the line exists and that its text is English.

Clone this wiki locally