最新资讯
techcrunch.com Airbnb 称将于 2027 年上半年推出 AI 旅行代理 theverge.com Perplexity 推出面向工作的 AI 代理 Teammates unite.ai Five9 拟以约3.25亿美元收购 Level AI,扩展客服AI分销渠道 unite.ai Serve Robotics 向物理AI公司开放车队软件与数据 wired.com 聊天机器人广告时代到来:哪些做法有效、哪些无效 techmeme.com METR:Anthropic 删减了评估报告中最具信息量的证据 unite.ai 微软借助 AI 修复更多 Windows 漏洞,但补丁部署仍滞后 bloomberg.com Cloudflare 上调年度利润预期,AI 推动网络需求 theinformation.com Anthropic 为 Claude 推出个人理财功能 theinformation.com Airbnb 披露 Chesky 隐秘 AI 初创公司的新细节 engadget.com Google 将停用 Firebase Studio,引导开发者转向 Antigravity 与 AI Studio www.youtube.com 别再给 AI Agent 发 API Key:Keycard 与 Temporal 谈 Agent 安全与可恢复执行
多元动态
登录 注册
大模型 dev.to · @sunnydachs

你的 README 代码示例正在悄悄说谎——我用纯 AST(不用 LLM)做了个检测文档漂移的 CLI

原文 我的收藏

作者发布 CLI 工具 doc-drift,通过 AST 扫描 Markdown 中的围栏代码块,提取其中定义的函数与类,检查其是否仍与真实代码库匹配,从而发现“文档漂移”,全程不使用 LLM。文章给出扫描示例输出(如 README.md:153 签名漂移),但未提供采用情况或效果数据。

AI推荐理由 作者发布 CLI 工具 doc-drift,用 AST 而非 LLM 检测 Markdown 代码示例与真实代码库之间的“文档漂移”,并给出扫描输出示例。工具思路具体、可自行验证,但为个人项目,尚无采用情况或效果数据。

60

正文

Your README code examples are silently lying — I built a CLI to detect documentation drift using only AST, no LLM "Did you know? This README example doesn't work." Have you ever had a junior engineer tell you that? Or worse — have you added a line to your code, forgot the docs, and broke it yourself? This time I want to tell you about doc-drift, a CLI I built that detects this "documentation drift" — the silent gap between code examples in your Markdown and the actual codebase — without using an LLM at all. https://github.com/sunnydachs/doc-drift What it does You point it at a repository. It scans your Markdown files for fenced code blocks, extracts the functions and classes defined there, and checks whether they still match the real codebase. # scan the repo (read-only) doc-drift # another repo, machine-readable output doc-drift /path/to/repo --json Enter fullscreen mode Exit fullscreen mode Example output: doc-drift — scanned /home/dev/myproject markdown files: 42 | python blocks checked: 87 README.md:153 ⚠️ SIGNATURE DRIFT block defines (url, retries) but repository defines (url, timeout) summary: {"signature_drift": 3, "missing": 1, "unparseable": 5} | clean blocks: 41 Enter fullscreen mode Exit fullscreen mode It reports three main findings: SIGNATURE DRIFT — the documented function exists, but its arguments have diverged from the real code. MISSING — the documented function/class no longer exists anywhere in the repo (renamed? deleted?). UNPARSEABLE — the block isn't valid Python (pseudo-code, placeholders) — informational only. A "function exists, but arguments differ" bug is one that IDEs and static analysis can never catch. Docs aren't executed — so nothing in the toolchain ever checks them. That's the hole. Why deliberately not use an LLM This was the core design decision. An AI reading the natural-language docs could grasp more "context." But I deliberately built it on nothing but Python's standard ast (Abstract Syntax Tree). Three reasons: Deterministic. Same input → same output, every time. I don't want a tool in CI whose verdict flips between runs. Read-only and safe. It never imports or executes your code — it compares at the syntax-tree level. Your files stay untouched. Zero dependencies. Python 3.11+ is enough. Install is pip install git+... This is one answer to the question I keep asking myself when automating: how much should I hand to an AI? Deterministic work deserves deterministic tools. The rule: docs may omit, but they must never invent The detail I obsessed over: code examples in docs are almost always simplified versus the real code. Omitting an argument should be fine. So the rule is: Omit arguments — allowed. Invent arguments or functions that don't exist in the code — forbidden. That single line ("省略は許す、発明は許さない" / omit is fine, inventing is not) eliminated the vast majority of false positives. Classes work the same way: every documented method must exist on the real class, but unmentioned methods are treated as omitted. Testing against real-world data Not a toy README — a real, large open-source repository: Scanned 1,692 Markdown files / 4,451 code blocks. Found one genuine drift: a function documented with 2 arguments whose implementation had since moved to 1 argument. Also surfaced our own over-eager default exclusion that caused false positives — so we fixed the configuration. The real win wasn't just "it works" — it was confirming in practice that the tool does not degrade into a noisy false-positive spammer. Honest limitations It can't tell "documentation" from "illustration." A hypothetical example in a top-level README (code never meant to exist) reports as MISSING. It shines in docs/ trees whose examples mirror the codebase. Python only (for now). Other languages are counted but not checked. Name-based comparison. Default values and type annotations are ignored — it catches renames, removals, and arity/name changes, not semantic drift. Wrap-up Docs-vs-code drift only gets more dangerous as a project grows. And these "quiet but sharp-toothed" problems are exactly where deterministic tools earn their keep. This is one in a series I'm building on the same principles (deterministic / read-only / dry-run-first). A sibling, plan-drift, applies the same approach to analytics tracking plans. https://github.com/sunnydachs/doc-drift Feedback, and especially false-positive reports from your own repos, are the most useful thing you can give me — drop them in the repo issues.

来源报道 · 1 篇 · 以下链接均前往原始媒体

← 返回精选动态 原文

更多内容