Skip to content

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):

  1. Open project incidents (IncidentStore): Matching open warnings/invariants tied to that file path (up to half of max_chars, max 2,000 chars) so agents don't repeat known traps.
  2. Durable per-file notes (file-notes.json): Every pinned note attached to the file via file_note, newest first, with note IDs, authors, and summaries.
  3. Indexed symbol declarations (index.db): Up to 24 top declarations (classes, interfaces, methods, functions, fields — omitting noisy FILE/PACKAGE/IMPORT boilerplate) with line numbers (@line) and compact signatures.
  4. Structural & projected-KGraph edges: Up to 32 merged outgoing and incoming relations from both the SQLite code index and the bounded neighborhood of .kompile/graph.kgraph (capped at 64 graph nodes and 96 edges).

Example output shape ​

text
--- 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-> LspTool

How it works under the hood (FileContextService) ​

  • Non-blocking WAL snapshot: Opens ~/.kompile/code-index/<projectId>/index.db read-only inside an explicit SQLite WAL transaction, reading the file's entity/relation graph and indexGeneration atomically. Because it uses WAL instead of a JVM write lock, file_context never stalls behind an active background indexing pass.
  • Generation-checked KGraph lookup: Cross-checks the SQLite indexGeneration against the projected .kompile/graph.kgraph metadata so callers immediately see whether the KGraph slice is FRESH or stale.
  • Hard bounding: Enforces strict caps on notes (12/file, 4,000 chars/note, 2 MB store 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_id argument required) and marks the project recently used in BackgroundIndexService.

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_context for LspTool.java first 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.

ActionParametersEffect
addfile_path, content (max 4,000 chars)Appends a timestamped note tagged with author and sessionId (up to 12 notes per file)
deletefile_path, note_idRemoves an obsolete note using the exact note_id returned by file_context

When to use file_note vs persistent memory ​

  • Use file_note for file-local invariants and traps: "Do not add a synchronized block here — called under LspServerManager lock", "Must stay compatible with native-image reflection config", or "Touch PersonaBoundaryTest when changing this pom". Any agent touching that file sees it automatically without having to remember to query memory.
  • Use memory for 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:

ActionWhat It Does
statusReports file-watcher status for the workspace
recentLists recent file changes (optional limit, default 20)
notificationsReturns pending notifications for files this agent has read that were modified by another agent
track_readRecords that this agent read file_path (registers for change notifications)
track_writeRecords that this agent intends to write file_path
clearClears consumed change notifications

Pair with edit_coordinator & diff_index:

Next steps ​

Released under the Apache-2.0 License.