让代码自带可执行验证,提升AI编程代理的可靠性与准确性。
Executable Code Knowledge: Code as a Native, Validation-Carrying Knowledge Representation for AI Coding Agents
- 将代码封装为可执行知识单元,内含验证证据和上下文状态。
- 在26个补丁任务中实现100%精确匹配,验证证据隐藏后准确率降至9%。
- 适合需要高可信度代码生成与审查的开发场景。
AI编程代理不仅需要代码片段,还需业务语义、验证证据、关系链及上下文时效性保障。现有系统多通过检索、摘要、图谱或规则外化知识。本文提出可执行代码知识(ECK),定义可执行代码知识单元(ECKU)为具备稳定身份、语义、可执行行为、契约、证据、关联、溯源、验证状态及查询接口的源码绑定对象。基于Python的原型支持本地编写、声明导出、证据执行、精确变更影响分析、新鲜度检查及面向代理的投影。在三个真实Python仓库与26个受控补丁任务中,直接使用ECK使11个带证据任务获得可执行测试覆盖,精确选择器恢复率达9/11;隐藏声明证据后精确恢复降至1/11(配对精确McNemar p=0.0078)。ECK衍生规则成功恢复全部11个精确选择器,表明规则是有效交付载体,而ECK提供源绑定、验证状态、影响范围与新鲜度。精确变更行影响与独立标注完全一致(26个补丁,12个单元链接;精度、召回率、F1均为1.000)。基于AST的指纹正确识别50个正例与17个同文件无关控制,静态规则快照未能检出任一过时案例。模型驱动的补丁评审与跨层研究仅衡量投影保真度,而非独立影响发现。结果支持混合架构:检索用于覆盖率,ECK用于源码与证据治理,投影用于交付。
原文摘要 · Abstract (English)
AI coding agents need more than relevant snippets: they need business semantics, validation evidence, relations, and assurance that their context is current. Existing systems usually infer or externalize this knowledge through retrieval, summaries, graphs, rules, or reverse specifications. We investigate a complementary representation in which selected code units directly carry agent-usable knowledge. We introduce Executable Code Knowledge (ECK) and define an Executable Code Knowledge Unit (ECKU) as a source-bound object combining stable identity, semantics, executable behavior, contracts, evidence, relations, provenance, validation state, and a query interface. Our Python prototype supports code-local authoring, manifest export, evidence execution, exact changed-line impact, freshness checking, and agent-facing projections. Across three real Python repositories and 26 controlled patch tasks, direct ECK provides executable test coverage for 11/11 evidence-bearing tasks and exact selectors for 9/11; hiding declared evidence reduces exact recovery to 1/11 (paired exact McNemar p=0.0078). ECK-derived rules recover 11/11 exact selectors, showing that rules are effective delivery artifacts while ECK supplies source binding, validation state, impact, and freshness. Exact changed-line impact matches independently authored labels on all 26 patches (12 unit links; precision, recall, and F1 all 1.000). AST-bounded fingerprints classify 50 positive changes and 17 unrelated same-file controls correctly, whereas static rules snapshots detect none of the 50 stale cases. Model-backed patch-review and cross-layer studies measure projection fidelity rather than independent impact discovery. These results support a hybrid architecture: retrieval for coverage, ECK for source and evidence governance, and projections for delivery.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。