跳到正文
Skillpedia
通用编程19k · #10506

xerj-code

它能做什么

在开源代码中找到可用的参考实现,在本地为其建立索引,并在编写新代码之前检索出确切的段落。适合使用陌生库或移植算法的开发者。

适用场景

  • ✓当你开始一项任务,而所用的 API 你不太熟悉时。
  • ✓当你在移植一个算法,需要参考版本时。
  • ✓当同一个修复方法已经尝试两次仍然失败时。

技能链接

https://github.com/xerj-org/xerj/blob/main/tools/xerj-code/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/xerj-org/xerj/blob/main/tools/xerj-code/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我使用这个库的 seal 函数时一直出错。请找到一个可用的参考实现,并使用它的确切做法。”

每周 5 个新技能,1 分钟读完。

工作原理

该技能会克隆已经包含正确实现的代码仓库,为其建立索引,并检索任务所需的段落。阅读参考资料消耗的是输入 token,而不是反复尝试编写代码所消耗的成本。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

XERJ.code — reference coding

An agent that does not know an API guesses, runs, fails, and guesses again. Each lap costs output tokens, which are the expensive kind. This skill replaces laps with a lookup: clone the repositories that already contain a correct implementation, index them with XERJ, and retrieve the passage before writing.

The trade is deliberate. Retrieval spends input tokens, which are cheaper per token and cacheable; loops spend output tokens. See COSTS.md for the arithmetic and for the conditions under which this trade loses.

Status, stated plainly: measured, and the value is real but narrow. (Full case study with real tokens and dollars: docs/case-studies/reference-coding/CASE_STUDY.md, 2026-08-05.)

The comparison that matters is against native Claude Code — the same agent with tools that would grep the source itself — not a bare model. Measured across three regimes, same agent, one objective verdict (compiles + passes hidden tests):

  • Unfamiliar code with a contract the model can't recall (a seal, a generational handle, a lazy refill, a specific hash scheme — measured across seven purpose-built libraries, 21 runs): native and xerj both solve 21/21; xerj uses 1.5× fewer output tokens and costs 1.3× less than native, because retrieval replaces the grep. Pure memory fails 1/21 and burns 6.5× the cost flailing. This is the win, and it is decisive. The compiler can leak an API name across a retry loop, but never a contract.
  • Memorised code (any popular public crate — even a 256-value table, or a protobuf-style varint): retrieval is overhead. Pure memory is cheapest; injecting a big reference can be the worst arm, because the model re-emits what it was handed.

So: use this when the reference is code the model has not memorised — your own private/proprietary code, an internal API, a post-cutoff or niche library. On public library references the model already knows, it costs more than it saves. The native-vs-xerj gap grows with corpus size (grep pulls the whole tree into context; retrieval pulls one passage).

Since #977 the whole loop is inside the xerj binary — xerj corpus add / xerj corpus index / xerj code — plus the xerj_code_search MCP tool for agents without a shell. The old wrapper scripts (xc-corpus.sh, xc-index.sh, xc.py) are gone; your existing ~/.xerj-code corpora and indexes work unchanged (see Migration below).

Standing corpora for this repository (MANDATORY since 2026-08-06)

In the xerj repo, retrieval-before-writing is required for non-trivial engine work, not optional. Each corpus below has a pinned, licence-reviewed definition in hub/ — xerj corpus add --from hub/<name>.json rebuilds it at the same commits anyone else is using:

corpus projects use it for
xerj-search lucene, tantivy, meilisearch, quickwit, sonic, elasticsearch FTS, BM25, postings, merge policy, typo tolerance, segment layout, ES wire semantics
xerj-vector qdrant, usearch, instant-distance, hnswlib HNSW build, neighbour heuristics, quantisation, filtered kNN
xerj-storage sled, fjall, redb WAL, flush epochs, crash recovery, compaction, page allocation
xerj-columnar clickhouse columnar storage, aggregation execution, compression codecs, vectorised scans

Approach-only sources: elasticsearch (AGPL-3.0 / SSPL-1.0 / Elastic-2.0) and sonic (MPL-2.0). Never copy their code into Apache-2.0 XERJ; for ES, pasting source would also falsify the project's public "shares no code with Elasticsearch" claim. meilisearch is MIT at the core but BUSL-1.1 for its Enterprise Edition parts — check the header/path first. Read the design, write our own implementation. Each manifest's review.use field says which bucket a repo is in; hub/README.md explains the three.

Hub corpus or local corpus

Two kinds of corpus sit on the same local node. Each answers a different kind of question:

hub corpus local corpus
what it holds public material at a pinned commit: a library's source, a standard, a regulation, an advisory feed files only this machine has: the project y
常见问题

它总是更省钱吗?

不是。案例研究指出了这种方法会失效的条件,因此其收益是真实的,但范围有限。

它是与什么比较的?

它是与使用自身搜索工具的同一个编码智能体进行比较,而不是与裸模型比较。

它会替我写代码吗?

由智能体编写代码,但实现会以检索到的参考段落为依据。

详情

作者的原始描述

Reference-coding with XERJ. Clone the libraries that already solved your problem, index them locally, and retrieve the exact implementation before writing code — so the agent reads passages instead of re-deriving algorithms across retry loops. Use when starting a task in an unfamiliar API, porting an algorithm, or when you have already looped twice on the same error.

repo: xerj-org/xerj

热度

GitHub 星标
19k
排名
#10506
许可证
Apache-2.0
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能