Skip to main content
Status: Scoping · Owner: TBD · Builds on: src/gaia/code_index/, the memory store, the daemon clock · Companion: the docs and GitHub project-knowledge skill plan (unmerged)

What the user gets

Point GAIA at a public GitHub repository and it keeps a searchable copy at the head of the default branch. Ask “where does the agent decide which model to load?” and the answer quotes the code, links the exact file and lines on github.com at a named commit, and says how fresh the copy is. Ask “what changed this week?” and GAIA answers from a short digest it wrote to memory after each update. The first repository is amd/gaia, for the community Discord deployment. The feature is generic: any public GitHub repository can be followed the same way, and nothing in the design is specific to GAIA’s own code.

What the code index does today

What it cannot do:
  • It knows nothing about git. No commit is recorded, so an answer cannot say which version of the code it describes, and a result cannot link to github.com.
  • It stops at 5,000 files. max_files cuts the walk short and indexes what it found. This repository has 5,225 indexable files, so it is already truncated.
  • It indexes everything equally. Tests are 43% of this repository’s chunks.
  • It leaks host paths. get_status returns the absolute folder and cache paths, and error messages name the cache folder.
  • Nothing updates it. It rebuilds only when the agent calls index_codebase.

What it costs, measured on this repository

Measured at 0a2afdc30 on a development PC with the embedder on the GPU and a chat model resident but idle. No chat model was used. The embedding rate comes from a 1,000-chunk sample; the first-index time is that rate applied to the full chunk count, not a full run. The first index is slow but one-off; a PC with no GPU will be slower and has not been measured. Every sync costs over a minute even for a one-line change, because the indexer re-reads the whole tree and rewrites the whole index, and the matching step grows with files times chunks. Leaving tests out would roughly halve all of it.

Design

Following a repository

Each followed repository lives in a dedicated folder under GAIA’s home, never inside a user project:
  • Clone anonymously with --depth 1 --single-branch, with credential helpers disabled, no submodules, no hooks, no LFS download and symlinks off. A private repository fails to clone, which is the intended behaviour: only public code gets in.
  • Check for updates with git ls-remote on the default branch. It is one small request, needs no sign-in and uses no GitHub API quota. Default interval: 30 minutes.
  • Fetch with --shallow-since set to the indexed commit’s date, so the new commits are available locally for the digest.
  • Find what changed with git diff --name-status <indexed> <new>. Only those files are re-chunked and re-embedded; deleted and renamed files drop their old chunks.
  • File list comes from git ls-files, not a directory walk, so only tracked files are ever read.
The trigger is a recurring job on the daemon clock (src/gaia/daemon/scheduler/). It must run as plain code. gaia schedule cannot host it: each fire there starts a fresh agent session from a prompt (schedule/runner.py), which would load a chat model every 30 minutes to do work that needs none.

When a sync goes wrong

Three failed syncs in a row raise a visible notice in the app and, on the Discord deployment, a message to the operator. No case falls back to web search or model memory.

Index changes

  • Record repo, branch, commit and synced_at in the metadata.
  • Add an update path that takes a list of changed and deleted files, instead of re-reading the tree.
  • Store the lookup by file so matching unchanged files is linear, not files times chunks.
  • Results and status return owner/repo plus a repository-relative path. Absolute paths never leave the indexer.

Large repositories and what is left out

This repository is already large for the current design: its metadata is one 128 MB JSON file loaded whole, and search compares the query against every vector. To scale past it:
  • Budget by chunks, not files. The 5,000-file cut-off goes. A repository is indexed in priority order (source, then docs, then tests) up to a chunk budget, and a repository that does not fit says exactly which folders were left out, in status and in answers that touch them. Never a silent partial index.
  • Stop storing chunk text twice. Metadata keeps path and line range and reads the text from the checkout, moving from one JSON file to SQLite so a sync writes only the rows that changed.
  • Smaller, faster vectors when needed. Exact search is fine at this size. Past a measured threshold, switch to a compressed or clustered FAISS index; Phase 0 finds that threshold rather than guessing it.
  • Resumable first index. A 30-minute build that is interrupted continues from the last saved batch instead of starting over.
Left out by default, before anything is read: git ls-files already drops everything untracked or ignored, so these rules matter only for what a repository commits. Each repository can add its own include and exclude patterns (for example, leave out tests/), and status lists what was skipped and why.

Updates stored in memory

After each successful sync, one entry is written to the memory store:
  • Category note, source repo_sync, domain repo:<owner>/<repo>, entity <owner>/<repo>@<from>..<to> (short SHAs).
  • Deduplicated by commit range. The sync checks for an entry with the same entity before writing, so a retried sync writes nothing new. The distinct entity also matters because the store merges entries in the same category, context and entity that share 80% of their words (DEDUP_OVERLAP_THRESHOLD); two quiet days must not collapse into one entry.
  • Size-bounded. At most 1,200 characters, under the store’s 2,000-character limit. Up to 8 merged pull requests by number and title, the top 5 folders touched with file counts, and a “+N more” line. A sync covering more than 50 commits is summarised by count and folder only.
  • Built from a template, not by a model. Pull request numbers come from squash-commit subjects; titles are stored as quoted data. Commit messages are text written by strangers, and memory is recalled into future prompts, so a model-written summary of them would be a standing prompt-injection path. A “behaviour changes” line is included only when the commit type says so (feat, fix, ! for breaking) and repeats the title; it never interprets the diff.
  • Ageing. The store already lowers confidence by 10% for entries unused for 30 days. On top of that, the sync keeps the latest 60 digests per repository; older ones are folded into one entry per calendar month (commit count, pull request count, top folders) and removed. At this repository’s pace that holds about two months of detail.
Illustrative shape:

How answers cite and report freshness

Every search result carries repo, path, start_line, end_line, commit and a ready-made link, built by the tool, never by the model:
Linking to the commit rather than the branch means the link still shows the quoted lines after main moves. Each tool response also carries a freshness line the agent must repeat when it is not “current”:

Isolation for a public deployment

  • Only the clone is indexed. The followed-repository tools take a repository name, never a path. On a public deployment the general index_codebase and clear_code_index tools are not registered, so no message can point the indexer at a host folder.
  • Only tracked, public files. Anonymous clone plus git ls-files. The existing skip list for .env files and private keys still applies, for secrets committed by mistake.
  • No host paths in output. Results, status and errors use repository-relative paths. A test scans every tool response for the home folder and drive roots.
  • Repository text is data. A comment or README that addresses the agent is quoted, never followed. The memory digest carries titles only.
  • Read-only. Nothing in the checkout is ever executed, built or installed.
  • A fixed list. The public deployment follows the repositories its operator set; chat users cannot add one.

Scope against the project-knowledge skill plan

That plan answers from the live docs site and live GitHub (issues, pull requests, releases); this one answers from the code and remembers what merged. Live issue and pull request state stays there, under the same citation rule: this index copies no issue text.

Tests and evals

Unit (no model, no network). A fixture builds a small git repository and a bare “remote” in a temporary folder, then scripts commits against it:
  • add, edit, rename, delete: only those files are re-embedded; force-push is rebuilt
  • fetch and embedder failures keep the last good index and an exact state.json
  • digest: one per commit range, retry writes none, size cap holds, month roll-up
  • git commands asserted by argument list (depth, no credentials, no submodules)
  • citation link shape, each freshness line, no absolute path in any tool response
  • committed node_modules, binaries, lockfiles and generated files are skipped and listed
  • a repository over the chunk budget names the folders it left out; an interrupted build resumes
Integration (embedder only, require_lemonade). A retrieval benchmark: about 50 questions with the file that answers each, against amd/gaia at a pinned commit, scored by recall at 5 and mean reciprocal rank. Run again on two other public repositories in different languages before any repository beyond amd/gaia is offered. This is the number that decides whether blank-line chunking is good enough for non-Python code. Agent evals. A new gaia_repo category, set up like the other gaia_* lanes with a fixture repository and a fake gh: Existing categories to watch on every phase, since tools and memory writes change: gaia_code (code_index_and_find, code_t3_semantic_trace), gaia_memory, gaia_tool_selection, gaia_honesty and gaia_git.

Phases

Open questions for the owner

  1. Tests in or out by default? Out halves disk and time; in helps “how do I use this” questions. Phase 0’s benchmark should decide.
  2. Poll or webhook? 30-minute polling is proposed. Is a public endpoint on the Discord host worth near-instant updates?
  3. Pull request descriptions in the digest? Titles need no GitHub API call; descriptions need one per pull request and bring more untrusted text into memory.
  4. Whose memory? On Discord the digests belong to the bot, not one user. Confirm they go in the global context, visible to everyone.
  5. Compact models. Offer this on Gemma-4-E4B now, or after gaia_repo passes on it?
  6. How many repositories? Is three a fair desktop limit at 760 MB and half an hour each?
  7. Release tags. “Was this fixed in v0.25.4?” needs a tag lookup or a second index; neither is in scope here.