Daily Tech Briefing
AI 科技速览

每天 5 分钟内学习 AI。获取最新的人工智能新闻,理解其重要性,并学习如何将其应用于您的工作。

AI 快讯
Dev.to AI · 2026/7/29 08:36:53

Giving my agent a map of the codebase (drawn partly from its own footsteps)

AI 中文解读
编程智能体终于有了"记忆地图":它以前每次进入一个新代码库都像实习生一样从头摸索,现在通过记录自己走过的每一步,为项目自动绘制一张动态导航图,让新手智能体一次就知道该往哪儿看。 通俗地说,程序员常用的AI辅助编码工具每次处理一个新项目时,都得重新翻遍所有文件才能理解代码结构,就像每次上班第一天都要从头学习公司地图。解决办法是让智能体自己生成一本"项目笔记":不仅记录代码谁调用了谁(结构),谁和谁经常一起修改(版本历史),还记录它自己在实际工作中最常同时打开哪些文件(行为习惯)。最关键的是第三种信号,因为静态分析工具永远看不到实际工作模式,只有亲自动手干活的智能体才知道哪几个文件总是一起变动。 这项技术最直接的影响是让AI编程工具的反应更快、答案更准。开发者在用GitHub Copilot等工具时,智能体能更快理解项目全局,减少无意义的文件搜索,进而加速代码编写。长远来看,这种"自我观察+持续学习"的模式也可能被引入其他智能助手,比如让办公软件记住你写文档时最常同时打开的参考资料,或让设计工具记住你调整UI时习惯一起修改的组件——AI不再是每次从头猜,而是越用越懂你。
<p><em>Originally published at <a href="https://olund.dev/writing/code-map/" rel="noopener noreferrer">olund.dev</a>.</em></p> <p>Watch a coding agent land in an unfamiliar repository and you will see it do<br> what a new hire does on day one: grep for names, list directories, open<br> files, and slowly assemble a mental model. Unlike the hire, the agent does<br> this <em>every session</em>. The model it builds is discarded when the context<br> window closes, and the next session pays for it again - in tokens, in<br> latency, and in the wrong turns an incomplete picture produces.</p> <p>My fix is a per-project <strong>code map</strong>: a queryable navigation layer each<br> repository carries, rebuilt incrementally, that a new session receives a<br> digest of before it reads a single file. The interesting part is not that it<br> exists - static code intelligence is a mature field - but which three<br> signals it fuses, because the third one is something most tooling cannot<br> see at all.</p> <h2> Three signals, one map </h2> <p><strong>Structure</strong> is the conventional axis: symbols, calls, and imports parsed<br> with tree-sitter across whatever languages the repo mixes. This is<br> deliberately the shallow version of static analysis. Dedicated tools do<br> deep type resolution far better than I ever will, and competing with them<br> head-on would be a losing use of my time. Syntactic edges are good enough<br> for navigation, and the edge table records where each edge came from, so a<br> deeper per-language analyzer can add resolved edges later without a redesign.</p> <p><strong>Temporal</strong> comes from git: churn, ownership, and co-change - which files<br> historically change in the same commits. Parsed from plain <code>git log</code><br> output; no library dependency, and the repo's whole history is sitting<br> there with nothing better to do.</p> <p><strong>Behavioral</strong> is the differentiator. My memory system already records<br> every tool call an agent makes - every read, edit, and write, tagged with<br> project and session. Rolled up, that log yields a co-touch matrix: which<br> files did agents actually work on <em>together, in real sessions</em>. Editing<br> weighs more than reading in the rollup, because changing two files together<br> is stronger evidence of coupling than looking at them.</p> <p>The distinction between the axes matters in practice. The call graph tells<br> you A depends on B - true, and sometimes useless, because half of a<br> codebase depends on B. The behavioral signal tells you that in the last<br> thirty sessions, every time A changed, B and C changed too. Those are A's<br> <em>de facto</em> neighbors: the set you should have open when you touch it. Static<br> tools cannot compute this because they never see the work. Git co-change<br> approximates it but only at commit granularity, after the fact, and only<br> for changes - a session that read four files to safely edit a fifth leaves<br> no trace in git at all. The agent's own footsteps are the only place this<br> signal exists.</p> <h2> Cheap at session start, deep on demand </h2> <p>The map is consumed two ways, and the split is deliberate.</p> <p>The cheap path is a small rendered digest injected into every session's<br> context at start: the subsystems, a few key files each, one line of purpose,<br> ordered by community detection over the fused graph. On my main project<br> right now that is 913 files folded into 33 communities. One refinement<br> earns its keep daily: the digest's sections are <em>reordered by relevance to<br> the branch's current task</em>, which the session-start machinery already knows<br> from the pointer file described in the previous post. A session opening a<br> branch about upload quality-control sees the QC subsystem first, not an<br> alphabetical list.</p> <p>The deep path is a set of query tools the agent calls mid-session:<br> neighborhood (structural plus behavioral ne
分享
阅读原文