返回资讯中心
外部精选
软件工程
#开发者实时流

Neo4j 推出 Relate 工具,让编程 Agent 读取代码库的 git 历史

来源标题:Your Coding Agent Can Read the Code. Give It the History with Relate by Neo4j

Neo4j 发布 Relate 的 git-to-graph 扩展,可将代码库的 git 历史导入图数据库并以只读方式提供给编程 Agent。测试中,仅能读取源码树的三个编程 Agent 都未发现 api_key.py 与 oauth2.py、http.py 等模块的关联,接入历史图数据后三者均找出了这些文件。这些模块虽无直接 import 关系,但历史上常在同类提交中一起改动。

Hacker News 最新johnymontana2026/11/19 · 今天30 分钟阅读

以下正文由 AI 翻译自 Hacker News 最新(原文版权归原站所有),可能存在偏差,重要内容请以原文为准。

博客首页 Developer GenAI 新闻 Agentic AI Developer 你的编码 Agent 能读代码,现在用 Relate by Neo4j 给它补上历史 William Lyon 用 Relate 的 git-to-graph 扩展把一个仓库的 git 历史加载成图数据库,以只读方式提供出去,看看编码 Agent 借助它能发现哪些在源码树里找不到的东西。

在一个流行的开源代码库里,security/api_key.py 在 28 次提交中被修改过。其中 18 次,oauth2.py 也被一起改了;http.py 被一起改了 17 次,open_id_connect_url.py 16 次。这四个模块之间没有任何一个 import 另一个,所以在 api_key.py 里没有任何显眼的线索指向另外三个文件。

历史记录把原因说得很清楚。每次有人给某一种安全方案加上一个行为,就会同时加到所有方案上:#134 里的 auto_error,#1757 里的 description,#13786 里的 401 状态码,#10147 里的 WebSocket 支持。

我们问三个编码 Agent:在给 APIKeyHeader 增加一个构造函数参数之前,还需要改动哪些地方?只给它们读源码树时,没有一个能说出那三个模块。把仓库历史加载成图之后,三个都说了出来。

本文展示如何用 Relate 的 git-to-graph 扩展构建这张图、该向它问什么,以及 Codex、OpenCode 和 Pi 能够查询它之后发生了哪些变化。

Relate 是一个为 AI Agent 直接使用而构建的开源图数据库。它是嵌入式的:单个二进制文件,无需部署服务器,无需注册,整个数据库就是你机器上的一个 .rl 文件,Agent 用 Cypher 查询它。

“Agent 原生”的意思是,Agent 需要的东西都自带。relate skill install 会给编码 Agent 装上一个 skill,它记录了 CLI、它的 Cypher 方言,还附带一份现成查询的目录。relate serve — mcp 把任意数据库暴露为 MCP 工具,而 --read-only 让它拒绝一切写入。

Relate 扩展可以用来把外部数据加载进图。本文用到其中两个:git-to-graph 用于仓库的提交历史,fs-to-graph 用于工作树。

git-to-graph 读取一个代码检出的提交历史。fs-to-graph 读取它的工作树。两者写入同一个 Relate 存储,因此一张图里既有代码现在是什么样,也有它是怎么变成这样的。

relate extension install git-to-graph relate extension install fs-to-graph git clone https://github.com/fastapi/fastapi.git relate run git-to-graph fastapi -d fastapi.rl relate run fs-to-graph fastapi --max-content-bytes 400000 -d fastapi.rlCode language: PHP (php) imported 8102 commits, 914 people, 5733 files (34551 TOUCHED, 48322 CO_CHANGED edges) into the store imported 429 folders, 3229 files (3657 CONTAINS edges) into the store

在 FastAPI 上(8,102 次提交,从 2018 年 12 月到 2026 年 11 月),历史导入耗时 4.6 秒,文件导入耗时 14 秒。存储是一个 30 MB 的文件;它来源的克隆是 101 MB。再次运行历史导入是安全的:它是合并操作,第二次运行后仍然是同样的 48,322 条 co-change 边。

CO_CHANGED 关系连接两个出现在同一次提交中的文件,它的 count 是这种模式出现的提交次数。这一条关系就能回答 Agent 在编辑一个文件之前应该问的第一个问题。

MATCH (:File {path: $path})-[r:CO_CHANGED]-(other:File) RETURN other.path AS coupled, r.count AS times ORDER BY times DESC, coupled LIMIT 5Code language: CSS (css)

对于 fastapi/fastapi/security/api_key.py:

+---------------------------------------------------+-------+ | coupled | times | +---------------------------------------------------+-------+ | "fastapi/fastapi/security/oauth2.py" | 18 | | "fastapi/fastapi/security/http.py" | 17 | | "fastapi/fastapi/security/open_id_connect_url.py" | 16 | | "fastapi/fastapi/applications.py" | 12 | | "fastapi/fastapi/routing.py" | 12 | +---------------------------------------------------+-------+Code language: JavaScript (javascript)

对于 fastapi/fastapi/routing.py——一个有 6,552 行、193 次提交的文件——榜首是 applications.py(58 次)、dependencies/utils.py(47 次)和 openapi/utils.py(39 次)。routing.py 的所有提交中,有三分之一也改动了 applications.py。

计数说明哪些文件会一起变动。更早的提交说明这类改动长什么样。这个查询找出某个文件上提交信息匹配某个词的提交,并列出每次提交还改动了什么:

MATCH (c:Commit)-[:TOUCHED]->(:File {path: $path}) WHERE toLower(c.subject) CONTAINS $term AND c.files_changed <= 50 MATCH (c)-[:TOUCHED]->(o:File) WHERE o.path <> $path WITH c, collect(o.path) AS others RETURN substring(c.sha, 0, 8) AS sha, substring(toString(c.authored_at), 0, 10) AS day, substring(c.subject, 0, 60) AS subject, [p IN others WHERE p STARTS WITH $prefix | replace(p, $prefix, '')] AS source, size([p IN others WHERE p STARTS WITH $tests]) AS tests ORDER BY c.authored_at DESC LIMIT 6Code language: PHP (php)

把 $path 设为 api_key.py、$term 设为 security,五行中有四行改动了完全相同的三个源文件:

这就是一次改动的模板:那条 description 提交是更早的一次构造函数参数改动,它显示了当时伴随了哪些文件、多少个测试。

MATCH (p:Person)-[:AUTHORED]->(c:Commit)-[:TOUCHED]->(f:File) WHERE f.path IN $paths AND NOT (p.name ENDS WITH '[bot]' OR p.name = 'github-actions') WITH p, count(DISTINCT c) AS commits, max(c.authored_at) AS last_touch RETURN p.name AS reviewer, commits, substring(toString(last_touch), 0, 10) AS last_touch ORDER BY commits DESC, reviewer LIMIT 6Code language: PHP (php)

对于 routing.py 和 applications.py:

+-----------------------+---------+--------------+ | reviewer | commits | last_touch | +-----------------------+---------+--------------+ | "Sebastián Ramírez" | 135 | "2026-10-22" | | "David Montague" | 8 | "2019-11-27" | | "Marcelo Trylesinski" | 7 | "2025-10-11" | | "Mohammed" | 7 | "2019-03-23" | | "Yurii Motov" | 5 | "2026-07-28" | | "Yurii Karabas" | 3 | "2021-01-07" | +-----------------------+---------+--------------+Code language: JavaScript (javascript)

(原文较长,此处译出前 6000 字,完整内容请点「打开原文」。)

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →