Reading Code Evidence Remotely
Answering from knowledge sometimes needs the code behind it. Cloning repositories into every Agent sandbox is slow; instead, the query Skill can read both the Context knowledge workspace and the source code through a read-only code service, Source Graph, at exactly the commit the knowledge cites. The optional context-evidence plugin, a WebAssembly module that runs inside that service, attaches each knowledge section's recorded source references to the text the Agent reads.
flowchart LR
agent["Agent with<br/>context-inspect-search"] -->|read knowledge at commit| sg["Source Graph<br/>read-only MCP"]
sg --> wasm["context-evidence plugin<br/>joins sections to references"]
wasm -->|text + references| agent
agent -->|read cited code at its commit| sgSource Graph is optional. You do not need to install or configure it. Without a service, the query Skill still works well by reading code locally: it makes a shallow, sparse partial clone of the recorded commit and searches it with grep or rg. In the default
automode it prefers Source Graph only when an authorized instance is available.
Turn it on
- Connect your Agent host to a read-only Source Graph MCP service that covers the knowledge workspace and its source repositories. Endpoints and credentials belong to the host configuration, never to the Skill or the knowledge.
- Choose the access policy with
CONTEXT_QUERY_ACCESS_MODE:
| Value | Behavior |
|---|---|
auto (default) | Reuse suitable local material, otherwise prefer the remote service before any local checkout |
remote | Read knowledge and code only through the service; never clone automatically, even on failure |
local | Local retrieval only; no service required |
An explicit request to work locally or offline always wins.
What happens on a read
- The Agent reads knowledge pages from the configured knowledge workspace at one pinned commit, searching within
knowledge/**. - With the plugin enabled — it is on by default for
readandread_manywhere the service supports that — each returned file carries areferences:list: the recorded sources of the sections in that range, as commit-specific URLs where the remote supports it. The Agent reuses them instead of looking up the structure and source registries. - For code, the Agent passes the exact repository and the recorded full commit as the revision, with repository-root-relative paths, and reads only the ranges that decide the answer.
- The knowledge workspace's commit and each source's recorded commit are kept separate; neither is replaced by a default branch.
What it does not do
The plugin joins existing section markers, knowledge/structure.yaml and source registrations. It does not verify source contents, search code, restore sources or modify knowledge, and a reference is not proof that the source was reread in this query. It has no network, filesystem or process access; the host binds every read to the invocation's repository, immutable revision and readable scope.
When the service or plugin is unavailable, the Agent keeps the readable text and continues; in auto it may fall back to local retrieval, in remote it qualifies the affected claims instead of cloning.
Running the service
Deploying and connecting Source Graph itself — repositories, monorepo path groups, authentication and operations — is covered in the Source Graph guides. On the Context side, nothing else needs configuring: the evidence plugin ships compiled with the CLI.
远程读取代码证据
基于知识作答时,有时需要查看其背后的代码。把仓库克隆进每个 Agent 沙箱很慢;查询 Skill 可以改为通过只读代码服务 Source Graph,在知识所引用的那个提交上,同时读取 Context 知识工作区和源代码。可选的 context-evidence 插件是运行在该服务内部的 WebAssembly 模块,它会把每个知识章节记录的来源引用附加到 Agent 读取的文本上。
flowchart LR
agent["使用<br/>context-inspect-search 的 Agent"] -->|在指定提交读取知识| sg["Source Graph<br/>只读 MCP"]
sg --> wasm["context-evidence 插件<br/>将章节与引用关联"]
wasm -->|文本 + 引用| agent
agent -->|在对应提交读取被引用代码| sgSource Graph 是可选的。 你不必安装或配置它。没有该服务时,查询技能照样能很好地工作:它在本地读取代码,对记录的提交做浅层、稀疏的部分克隆,再用 grep 或 rg 搜索。默认的
auto模式只在有可用的已授权实例时才优先使用 Source Graph。
启用
- 将你的 Agent 宿主连接到一个只读的 Source Graph MCP 服务,该服务需覆盖知识工作区及其来源仓库。端点和凭据属于宿主配置,绝不放在 Skill 或知识中。
- 通过
CONTEXT_QUERY_ACCESS_MODE选择访问策略:
| 取值 | 行为 |
|---|---|
auto(默认) | 复用合适的本地材料,否则优先使用远程服务,再考虑本地检出 |
remote | 只通过服务读取知识和代码;即使失败也绝不自动克隆 |
local | 仅本地检索;不需要服务 |
明确要求在本地或离线工作时,始终以该要求为准。
读取时发生了什么
- Agent 从配置的知识工作区、在一个固定的提交上读取知识页面,搜索范围限定在
knowledge/**内。 - 启用插件后——在服务支持的情况下,
read和read_many默认开启——每个返回的文件都带有一个references:列表:即该范围内各章节记录的来源,远端支持时以特定提交的 URL 形式给出。Agent 直接复用这些引用,无需再查询结构和来源登记表。 - 读取代码时,Agent 传入确切的仓库,以记录的完整提交作为 revision,使用相对仓库根目录的路径,并只读取决定答案的那些行范围。
- 知识工作区的提交与每个来源记录的提交分开保存;两者都不会被默认分支替代。
它不做什么
插件只关联已有的章节标记、knowledge/structure.yaml 和来源登记信息。它不校验来源内容、不搜索代码、不恢复来源、也不修改知识;一条引用也不能证明本次查询重新读过该来源。它没有网络、文件系统或进程访问权限;宿主会把每次读取绑定到本次调用的仓库、不可变 revision 和可读范围。
当服务或插件不可用时,Agent 保留可读的文本并继续;在 auto 下它可能回退到本地检索,在 remote 下则会对受影响的结论加以限定说明,而不是克隆仓库。
运行服务
Source Graph 本身的部署和接入——仓库、monorepo 路径分组、认证与运维——见 Source Graph 相关指南。Context 这一侧无需额外配置:证据插件已编译并随 CLI 一同发布。