Documentation

Docs / Reference

ADR 0044 - Code peek source endpoint and IDE presets

Status: Accepted (delegated review, 2026-11-03)

Context

The developer asked (2026-11-03, task T016e) to show a node's real source inside the app: the lines around its span, the exact span highlighted and an "Open in editor" button, honest about freshness. The endpoint must follow ADR 0041's loopback, Host, Sec-Fetch-Site/Origin and CSP rules, be confined to the indexed repository (no traversal, no symlink escape, no file outside the indexed files) and have size and line caps. The editor should be a one-word setting with verified URL schemes, keeping ide.link_template for anything else, and Windows paths must work. The panel will be reused by the Flow tab, trace lanes and the overview (T016-ui-decisions, "Graph views").

VISION's precision principle governs the highlight: never mark lines as the node's span unless that is proven. What the store holds decides what can be proven (T016e F1): the whole-file content hash (files.content_hash, read with Store.FileHashes), the node span (1-based lines, 0-based UTF-8 byte columns on LF-normalised source) and the node content hash, which for source nodes covers exactly the span bytes (contract v1 "Hashes", ADR 0005). No indexed source text is stored anywhere, so a changed file can be compared with its indexed version only through the span hash.

The scanner (internal/scan) never follows a symlink, reads only regular files, and does not index files with a NUL byte or invalid UTF-8 (T016e F4). Before this ADR the default IDE template was vscode://file/{abs_path}:{line}:{column}, which yields vscode://file//home/u/a.ts on Linux and macOS: VS Code turns that leading // into a UNC authority, a different resource from the workspace's file (T016e F5). Golden tests replaced the root with {ROOT}, which hid the double slash.

Editor URL schemes were read from primary sources fetched from raw.githubusercontent.com on 2026-11-03 (T016e F6, re-checked in T016e1 A1); cursor.com, docs.cursor.com, zed.dev and sublimetext.com are blocked by the environment's proxy and were not read.

Options considered and decisions

1. Source by node identity

The endpoint is generic (/api/v0/source, not under /api/v0/api/) because graph views reuse it. It uses ADR 0042's runs-before/after consistency check (one retry, then 503 index_changed) and store_error.

2. Highlight rule

The response states the result explicitly (exact, text_match, changed, span_invalid, missing, not_regular, too_large, binary, unreadable, no_location, not_indexed; docs/cli/serve.md). The presented node in the same response is built from the same bytes (query.NewPresenterWithReader), so node.ide.exact, node.file_state and source.state always agree.

3. Confinement

4. Caps

4 MiB per file (checked by Stat and by a limited read), 400 lines per window, 4,096 bytes per line (cut at a rune boundary and listed in cut_lines), context 0 to 50 with default 8. A3 of T016e1: no tracked text file of the ten corpus checkouts exceeds 4 MiB (the six files above it are images, audio or NUL-containing data the scanner does not index).

5. UTF-16 highlight columns

6. IDE presets

Verified formats (sources in internal/config/ide.go and docs/config.md):

editor template column status
vscode, vscode-insiders <scheme>://file{abs_url_path}:{line}:{column} UTF-16, 1-based verified (docs and handler)
vscodium vscodium://file{abs_url_path}:... as VS Code verified (build script; VS Code's handler)
cursor cursor://file{abs_url_path}:... as VS Code, assumed unverified (docs blocked, source not public)
jetbrains idea://open?file={abs_path}&line={line}&column={column} code points (logical column), 0-based verified from source; macOS and IntelliJ IDEA only
zed zed://file{abs_path}:{line}:{column} code points, 1-based verified from source

A1 corrected T016e F6 on one point: Zed's column is not a byte offset. navigate_to_positions (crates/recent_projects/src/remote_connections.rs) passes column - 1 to point_from_external_input (crates/text/src/text.rs), which counts characters (chars()), so the zed preset uses codepoint.

Review correction (T016e1 review): the jetbrains preset first used utf16. IntelliJ's LogicalPosition javadoc (JetBrains/intellij-community platform/editor-ui-api/src/com/intellij/openapi/editor/LogicalPosition.java) says the column counts characters with "surrogate pairs of characters ... counted as one column" and a tab occupying "up to the tab size", so the preset uses codepoint (column base 0 unchanged).

7. JetBrains

8. No Sublime Text preset

Sublime Text registers no URL scheme of its own; subl:// needs a third-party handler with differing formats, and its documentation could not be fetched. A preset that silently does nothing without extra software would mislead. docs/config.md shows a link_template and label for such a handler.

9. {abs_url_path} and the default

{abs_url_path} is {abs_path} with exactly one leading slash (/home/u/a.ts, /C:/src/a.ts; a UNC path keeps its two). The default is the vscode preset, so the default link on Linux and macOS loses the double slash; on Windows it is byte-identical. A template written with {abs_path} keeps its exact output. The golden normalisers (golden.ReplaceRoot) now treat {ROOT} as the root without its leading slash, always written after a slash, so committed links stay vscode://file/{ROOT}/... on every OS while an accidental double slash on POSIX stays visible as vscode://file//{ROOT}/....

Consequences

Known gaps

Review notes (delegated review, 2026-11-03)

Amendment (T016e2): code peek UI

Status: Accepted (delegated review, 2026-11-03)

This amendment records the panel contract of the web UI that consumes GET /api/v0/source (T016e2). It changes nothing above; the header status applies to the endpoint and presets only.

Review notes (T016e2, delegated review 2026-11-03): independent review found no blocker, major or wrong-highlight issue (highlight only from the server's exact/text_match; stale responses never shown under another row's header). Revision after review: focus returns to the opener, row keys work from the row's controls, distinct accessible names with aria-expanded/aria-controls, race tests, and the compact strip drops its Roots rows while the peek is open. Langflow browser gate: 10/10 highlights equal the API span, 0 CSP violations, light and dark. Known gaps: the open peek is not in the URL hash; the shell footer reads "unknown" until the first status answer arrives on large repositories (wording predates T016e2).

Amendment (2026-11-04, T016k): JetBrains column unit and byte order mark

Status: Accepted (delegated review, 2026-11-04)

Review correction (2026-11-04, T016k), recorded by ADR 0050 "Review fixes R2"; the text above is kept as it was decided.

Review notes (2026-11-04, T016k, delegated review 2026-11-04): the correction was verified from intellij-community and zed master (2026-11-04) and re-checked end to end through /api/v0/source?editor= for all six presets on the stacked head of 2026-11-04: "😀" before the node counts two UTF-16 units for jetbrains, a line-1 byte order mark is not counted by any preset, a jetbrains link after a tab or on a changed file names the line only. Golden change limited to the cursor and jetbrains notes in ide-builtin.golden.json. Full suite, corpora, timing and store size as recorded in ADR 0050 "Review notes (2026-11-04)"; CI: [ci windows] batch run on dd42753 green. Known gaps: see ADR 0050 (tab line-only, Cursor unit assumed).

Report a problem with this pageSource: docs/adr/0044-code-peek-and-ide-presets.md