File Context, Notes & Multi-Agent Activity
Before an agent reads a 1,500-line file — or runs five grep queries to figure out what calls it — Kompile's file_context tool gives a compact, character-bounded structural dossier for that file in a single read-only call. Paired with file_note (durable per-file warnings/rationales) and file_activity (cross-agent read/write tracking), it turns individual source files into rich, shared context nodes.
What file_context returns
file_context never reads the raw file text, never builds an index, and never launches an LLM. Instead, FileContextService assembles four live signals into one bounded summary (default 6,000 chars, configurable via max_chars from 512 to 16,000):
- Open project incidents (
IncidentStore): Matching open warnings/invariants tied to that file path (up to half ofmax_chars, max2,000chars) so agents don't repeat known traps. - Durable per-file notes (
file-notes.json): Every pinned note attached to the file viafile_note, newest first, with note IDs, authors, and summaries. - Indexed symbol declarations (
index.db): Up to24top declarations (classes, interfaces, methods, functions, fields — omitting noisyFILE/PACKAGE/IMPORTboilerplate) with line numbers (@line) and compact signatures. - Structural & projected-KGraph edges: Up to
32merged outgoing and incoming relations from both the SQLite code index and the bounded neighborhood of.kompile/graph.kgraph(capped at64graph nodes and96edges).
Example output shape
--- File context (not file contents) ---
Identity: kompile:kompile-cli/.../LspTool.java
Index: AVAILABLE (entities 42, returned relations 18)
KGraph: FRESH [.kompile/graph.kgraph]
Note ids (newest first):
- 7b2c1a... — agy
Note summaries:
- [7b2c1a...] Check call_hierarchy ranges use 0-based UTF-16 exclusive ends.
Indexed symbols:
- CLASS ai.kompile.cli.main.chat.tools.LspTool @76 — public class LspTool implements CliTool
- METHOD LspTool.execute @230 — public ToolResult execute(JsonNode params, ToolContext context)
Related graph edges:
- [index] LspTool -CALLS-> LspCheckRunner
- [kgraph] McpStdioCommand -USES-> LspToolHow it works under the hood (FileContextService)
- Non-blocking WAL snapshot: Opens
~/.kompile/code-index/<projectId>/index.dbread-only inside an explicit SQLite WAL transaction, reading the file's entity/relation graph andindexGenerationatomically. Because it uses WAL instead of a JVM write lock,file_contextnever stalls behind an active background indexing pass. - Generation-checked KGraph lookup: Cross-checks the SQLite
indexGenerationagainst the projected.kompile/graph.kgraphmetadata so callers immediately see whether the KGraph slice isFRESHor stale. - Hard bounding: Enforces strict caps on notes (
12/file,4,000chars/note,2 MBstore limit), symbols (24), relations (32), graph nodes (64), graph edges (96), and final rendered characters (max_chars) — guaranteeing a single call can never blow up your prompt budget. - Zero-config project resolution: Auto-resolves the owning code project from your working directory (no
project_idargument required) and marks the project recently used inBackgroundIndexService.
Two ways the harness uses file_context
1. Standalone triage (before opening a large file)
When triaging search hits or checking who depends on a file before paying the token cost to read it, ask the agent:
"Check
file_contextforLspTool.javafirst so we can see its open incidents, pinned notes, symbols, and callers before reading it."
The harness returns the bounded structural dossier (default 6,000 chars, tunable via max_chars) without reading the raw file body.
2. Inline while reading (include_context=true)
When the agent already intends to open a file, it can request include_context=true on read so the bounded file_context block appears right beneath the line-numbered file contents — saving an extra round-trip tool call.
Durable per-file notes (file_note)
file_note attaches persistent notes directly to an indexed source file (file-notes.json, schema kompile-file-notes/v1). Notes survive code reindexing and KGraph replacement and surface automatically whenever any future session calls file_context or read(include_context=true) on that file.
| Action | Parameters | Effect |
|---|---|---|
add | file_path, content (max 4,000 chars) | Appends a timestamped note tagged with author and sessionId (up to 12 notes per file) |
delete | file_path, note_id | Removes an obsolete note using the exact note_id returned by file_context |
When to use file_note vs persistent memory
- Use
file_notefor file-local invariants and traps: "Do not add asynchronizedblock here — called underLspServerManagerlock", "Must stay compatible withnative-imagereflection config", or "TouchPersonaBoundaryTestwhen changing this pom". Any agent touching that file sees it automatically without having to remember to query memory. - Use
memoryfor project-wide conventions, user preferences, cross-cutting architecture decisions, and session handoffs that aren't tied to one file.
Multi-agent file awareness (file_activity)
When parallel subagents or peer sessions work in the same repository, file_activity (FileWatcherService) tracks who read and modified which files so agents notice concurrent changes before overwriting each other:
| Action | What It Does |
|---|---|
status | Reports file-watcher status for the workspace |
recent | Lists recent file changes (optional limit, default 20) |
notifications | Returns pending notifications for files this agent has read that were modified by another agent |
track_read | Records that this agent read file_path (registers for change notifications) |
track_write | Records that this agent intends to write file_path |
clear | Clears consumed change notifications |
Pair with edit_coordinator & diff_index:
- Before multi-agent edits, lock target files with
edit_coordinator(register_edits→ edit →release_edits). - To audit historical edits made by coding agents across sessions, query
diff_index(see Diff Index (diff_index) and Auditing & Provenance).
Next steps
- Coding Tools Overview
- Local Code Index & Code Graph — powers the indexed symbols and KGraph projection behind
file_context - LSP: Language-Server Intelligence & Edit Gate — compiler-grade navigation and fail-closed verification