Skip to content

Diff Index (diff_index) ​

diff_index is Kompile's searchable, filterable, sortable index of historical file edits and unified diffs made by coding agents across sessions — plus version-controlled draft revisions, applies, and reverts (kompile-draft).

Unlike grep (which only sees current files on disk) or file_activity (which only tracks path-level change notifications), diff_index queries the actual oldString, newString, and unifiedDiff payloads mined from coding-agent transcripts and draft commits — including edits to untracked files that Git never saw.

What diff_index is (and is not)

diff_index is transcript- and draft-derived edit history, not Git history or a filesystem undo log:

  • It covers untracked files whenever an agent edit or draft recorded them.
  • Confirmed error results are excluded where extractors can correlate tool outcomes, though an invocation record alone is not proof that a disk write survived later manual edits.
  • Deleted or unavailable provider transcripts cannot be recovered once removed from disk.

Choosing between diff_index, /diffs, and sibling tools ​

NeedBest ToolWhy
Search historical old/new text or unified diffs across sessions, agents, or draftsdiff_index (action=search, action=get)Structured edit payloads with path globs, agent/source/session/time filters, and sorting
Glance at the latest edits in this active chat session/diffs [count]Reads the tail of the current session's live tool-call journal directly (instant, zero index scan; default 20, range 1–100)
Search current file contents on diskgrep / grep_batchLive workspace text/regex search
See if another parallel agent just touched a file you readfile_activityLive path-level read/write notifications
Search raw conversation prose or non-edit tool callstranscript_search / tool_call_catalogFull transcript text or general tool-call catalog
Stage, rebase, apply, or revert uncommitted editsdraft / draft_batchJGit-backed .kompile/drafts.git commits (automatically mirrored into diff_index)

What gets indexed & where it lives ​

Storage scopes ​

In local CLI / MCP mode (default), diff_index is strictly project-scoped unless you opt into global cross-project lookup:

ScopeParameterStorage Path
Project (default)scope="project"<project>/.kompile/agent-state/diff-index/
Global (cross-project)scope="global"~/.kompile/agent-state/diff-index/

DiffIndexService keeps only lightweight entry metadata in memory and hydrates full oldString/newString/unifiedDiff payloads on demand through a bounded LRU content cache (up to 64 entries / 8 MiB), so large edit histories stay fast and memory-safe.

Mined sources & edit tools ​

DiffIndexService automatically extracts file-edit tool calls across major coding-agent transcripts and Kompile's own draft store:

  • Transcript sources: Claude Code (including durable <session>/subagents/*.jsonl worker transcripts and legacy task outputs, retaining worker provenance without double-counting duplicate tool IDs), Codex, OpenCode, Qwen, Cline, Cursor, Continue, Aider, Gemini, Pi, and Kompile structured journals.
  • Mined edit tools: edit, write, edit_batch, edit_patch, patch, apply_patch, apply_diff, edit_file, write_file, write_to_file, replace_in_file, insert_code_block, create_file, str_replace_editor, file_editor, notebookedit (plus extractable shell file writes). Multi-file calls (edit_batch, edit_patch, and pathless multi-file patches) are expanded and deduplicated per individual edit.
  • Draft revisions, applies & reverts (DraftDiffIndexFeed): Every draft create, revise, rebase, apply, and revert writes deterministic entries (source="kompile-draft", toolName="draft", diffType="draft" | "draft-apply" | "draft-revert") carrying model, draftId, and commitId into both the project and global diff indexes.

MCP tool reference (diff_index) ​

diff_index is a read-only tool in the code MCP tool group (permissionKey="read").

Actions ​

ActionRequired paramsWhat it returns
search(all optional)Filtered, sorted, paged list of edit entries (metadata + matching snippets by default; pass include_content=true for full payloads)
getidFull DiffIndexEntry for one entry (oldString, newString, unifiedDiff, agent, source, sessionId, transcriptId, model, draftId, commitId, timestamp, line counts)
sessionsession_idPaged edits belonging to a single parent session or worker transcriptId
sessions—Per-session aggregate counts across indexed transcripts
projects—Indexed project directories with entry counts
agents—Indexed coding agents with entry counts
stats—Total entries, indexing status (indexing: true/false), and scope metadata
refresh—Requests a rescan of growing local transcripts (in remote mode, use POST /api/diff-index/reindex)

Parameters ​

ParameterTypeApplies toDescription
actionstringAll (required)search, get, projects, agents, sessions, session, stats, or refresh
scopestringAll (local mode)project (default — current project directory) or global (cross-project user index)
querystringsearch, sessionCase-insensitive substring matched across file path, old text, new text, and unified diff
file_pathstringsearch, sessionFile path substring or glob pattern (e.g. src/**/*.java, JitGraphBackendCommon.cu)
projectstringsearchProject directory path or project-name substring
agentstringsearch, sessionExact coding-agent name (e.g. claude-code, codex, opencode)
sourcestringsearch, sessionExact transcript source name, or kompile-draft for draft revisions/applies/reverts
session_idstringsession (required), searchParent session ID or worker transcriptId
sincestringsearch, sessionInclusive ISO-8601 timestamp/date lower bound (explicit offsets supported, e.g. 2026-10-25T16:30:00+09:00)
untilstringsearch, sessionInclusive ISO-8601 timestamp/date upper bound
sort_bystringsearch, sessiontimestamp (default), file_path, project, agent, source, lines_added, lines_removed, or total_changes
sort_dirstringsearch, sessiondesc (default) or asc
limitintegersearch, sessionPage size from 1 to 100 (default 20) — page size only, not a total history cap
offsetintegersearch, sessionZero-based entry offset (default 0); pass returned metadata.next_offset to continue paging
include_contentbooleansearch, sessionInclude full oldString, newString, and unifiedDiff inline (default false; 600-char matching snippets are still shown)
idstringget (required)Diff entry ID to fetch in full

Practical workflows (ask in chat or run /diffs) ​

You never need to write query JSON by hand — ask your agent in plain English and it calls diff_index with the exact filters and paging automatically:

1. Trace every edit to a file across a time window ​

Ask in chat: "Use diff_index to show every edit made to AgenticChatLoop.java between Dec 1 and Dec 4, oldest first."

The agent searches file_path="src/**/AgenticChatLoop.java" with since/until bounds and sort_by="timestamp", sort_dir="asc", automatically paging with next_offset whenever has_more is true.

2. Find who removed or changed a specific symbol ​

Ask in chat: "Search diff_index for CliToolGatewayInterceptor, newest first, and show me the full unified diff for the commit where it was modified."

The agent searches matching snippets first (keeping context small), then pulls only the target entry's full before/after diff via diff_index (action="get").

3. Inspect draft revisions, applies, and reverts ​

Ask in chat: "List recent draft revisions, applies, and reverts from diff_index (source=kompile-draft)."

Returned entries show diffType (draft, draft-apply, or draft-revert), model, draftId, and commitId.

4. Find the largest edits in a session ​

Ask in chat: "Show the 25 largest file edits from session <session-id> sorted by total changed lines."

The agent queries diff_index (action="session", sort_by="total_changes", sort_dir="desc") across either a parent chat session or a specific worker transcriptId.


Pagination, refresh, and timestamp semantics ​

  • Paging beyond 100 results: limit (1–100) is a page size, not a history cap. Follow metadata.next_offset while has_more=true. Offset pages are not frozen snapshots — when investigating an active session, pass explicit since/until bounds to prevent shifting pages.
  • Background vs. explicit refresh: Local mode throttles automatic background rescans (30-second cooldown after each scan). Call diff_index(action="refresh") when you need edits from a session that is actively growing, then poll diff_index(action="stats") until indexing is false before paging.
  • Timestamps & legacy sources: Claude, Codex, and Kompile structured journals preserve per-call invocation timestamps and call IDs. Legacy extractors that lack per-call timestamps fall back to session file modification time (never reindex time).
  • Reindexing stability: Re-reading growing sessions deduplicates individual edits and upgrades matching legacy entries in place while retaining their IDs; distinct repeated edits remain distinct.

Interactive /diffs & Server REST API ​

Quick session view in chat (/diffs) ​

Inside kompile chat and the Web Harness, /diffs [count] (default 20, range 1–100) prints recent edit tool calls for the current session newest-first directly from the session's live tool-call journal — without building or querying the cross-session diff index.

text
/diffs          # Newest 20 edit calls in this session
/diffs 50       # Newest 50 edit calls in this session

Server REST API (kompile-app-main :8080) ​

When running the distributed admin server (kompile-app-main on :8080, or when diff_index is configured with a remote server --url), the same DiffIndexService is exposed via /api/diff-index:

MethodEndpointPurpose
GET/api/diff-index/searchQuery by agent, projectDirectory, filePath, contentQuery, source, since, until, sessionId, sortBy, sortDir, limit, offset
GET/api/diff-index/entries/{id}Retrieve one full DiffIndexEntry
GET/api/diff-index/projectsList indexed projects
GET/api/diff-index/agentsList indexed agents
GET/api/diff-index/sessionsList indexed sessions with aggregates
GET/api/diff-index/sessions/{sessionId}List all diff entries in one session
GET/api/diff-index/statsIndex totals and active indexing status
POST/api/diff-index/reindexTrigger an asynchronous server-side reindex

Released under the Apache-2.0 License.