lexifina/global-law:用Git版本控制全球法律文本及MCP工具
lexifina/global-law: Git for Global Law: the law of every country as one git history, each country's record a submodule, every commit one l…
做Legal Tech或Agent的同学必看,这个开源项目用Git思维重构了全球法律数据的版本管理,并直接提供了MCP接口,让大模型能精准回溯法条历史,工程思路非常硬核且实用。
Git for Global Law: the law of every country as one git history, each country's record a submodule, every commit one law taking effect
全球法律 Git:将各国法律视为一个 git 历史,每个国家的记录是一个子模块,每次提交代表一部法律生效
GitHub repository created 2026-10-28 · 1001 stars in 2.5 days (about 398 a day) · HTML
GitHub 仓库创建于 2026-10-28 · 2.5 天内获得 1001 颗星(平均每天约 398 颗)· HTML
Git for Global Law
全球法律 Git
The world's law in one git history. Every word traced to the law that wrote it for any country and any date.
在一个 git 历史中呈现世界各国的法律。每一处文字都可追溯至为任何国家、任何日期所撰写的法律依据。
An expansion of the same for the US Code, #1 on Hacker News (28/10/26). Semantic, searchable law on a global scale.
针对美国法典的扩展版本,在 Hacker News 排名第一(2026年10月28日)。 在全球范围内实现语义化、可搜索的法律。
https://github.com/user-attachments/assets/f24f3411-24d9-416a-8c45-9cebc817c64e
Free to use: CC0. Fork it, build on it, ship it in a product: no permission or credit needed. The law text sits in each country's repository, under that repository's own terms.
免费使用:CC0。您可以分叉、在此基础上构建、或在产品中发布:无需许可或署名。法律文本位于每个国家的仓库中,受该仓库自身条款约束。
The law of many jurisdictions as one git history. Each jurisdiction's law is its own repository, where every commit is one law taking effect, written by that law. This repository arranges those repositories by jurisdiction and interleaves their histories in the order the changes took force, so a single commit here is the state of all of them on one day.
将多个司法管辖区的法律整合为一个 git 历史。每个司法管辖区的法律拥有自己的仓库,其中每次提交代表一部法律生效,并由该法律本身定义。本仓库按司法管辖区排列这些仓库,并按变更生效的时间顺序交错它们的歷史,因此这里的单次提交即代表所有仓库在某一日期的状态。
Each country's law lives in its own repository, `lexifina/-law`, which says where it belongs here in a `corpus.json` at its root. A country whose repository still holds only its sources (no law yet) has a folder with its `jurisdiction.json` and `SOURCES.md`, and no submodule: only real law is pinned. Laws adopted but not yet in force stay on each corpus's future branch; `main` here holds only what is in force by the build date.
每个国家的法律存在于其各自的仓库 `lexifina/-law` 中,该仓库在其根目录的 `corpus.json` 中标明其在此处的归属位置。若某国仓库仅包含其来源文件(尚无法律),则会有一个包含其 `jurisdiction.json` 和 `SOURCES.md` 的文件夹,且没有子模块:只有实际生效的法律才会被固定。已采纳但尚未生效的法律保留在各语料库的未来分支上;`main` 分支仅包含截至构建日期已生效的法律。
Corpora differ widely in reach. Some hold a country's whole statute book (Czechia, Spain, Switzerland, Georgia, Malta); others hold a few acts, or a sample: the US corpus is nine titles of the United States Code, and the UK corpus is the special educational needs law. `manifest.json` gives each corpus's `coverage`, and `history` says how its past is known: `in-force` (dated official versions), `replayed` (rebuilt by applying each amending act; its `verification` says which dates were checked) or `current-only` (today's text only).
语料库的范围差异很大。有些涵盖一个国家的全部成文法典(捷克、西班牙、瑞士、格鲁吉亚、马耳他);有些仅包含几部法案或样本:美国语料库包含美国法典中的九个标题,英国语料库则涵盖特殊教育需求相关法律。`manifest.json` 提供每个语料库的 `coverage`(覆盖范围),`history` 说明其历史记录如何获取:`in-force`(带日期的官方版本)、`replayed`(通过应用每项修正法案重建;其 `verification` 字段注明已验证的日期)或 `current-only`(仅限今日文本)。
Using it from an AI model (MCP)
从 AI 模型中使用(MCP)
`tools/mcp_server.py` is a Model Context Protocol server for this tree. It lets Claude or any other MCP client ask the law what it said on a date, and every answer states where its record starts and ends. It uses only Python 3.10+ and git, runs on your machine over stdio, reads the repository and changes nothing. It makes no network calls.
`tools/mcp_server.py` 是此仓库树的 Model Context Protocol (MCP) 服务器。它允许 Claude 或其他任何 MCP 客户端查询法律在特定日期的内容,且每个答案都会标明其记录的起止位置。它仅使用 Python 3.10+ 和 git,通过 stdio 在您的机器上运行,读取仓库且不进行任何修改。它不发起任何网络请求。
For other clients (Claude Desktop, Cursor and the like), add this to their MCP settings:
对于其他客户端(如 Claude Desktop、Cursor 等),请将以下内容添加到其 MCP 设置中:
Then ask in plain words, for example:
然后用通俗的语言提问,例如:
- "What did 11 U.S.C. §1182(1) say on 1 May 2022, and which law last changed it?" - "A case was commenced on 2022-05-01 under §1182. Which text applies, period by period?" - "Is the text of s. 42 Children and Families Act 2014 that the Court of Appeal applied in 2020 still in force?" - "Which provisions rely on 11 U.S.C. §1182, and which judgments does the record hold for it?" - "Check every citation in this brief against the law in force today."
- "2022年5月1日时,《美国法典》第11编§1182(1)条的内容是什么?哪部法律对其进行了最后一次修改?" - "案件于2022-05-01根据§1182条启动。各时间段分别适用哪些文本?" - "上诉法院在2020年适用的《2014年儿童与家庭法》第42条目前是否仍然有效?" - "哪些条款引用了《美国法典》第11编§1182条?记录中有哪些相关判例?" - "核对本摘要中的所有引文,对照现行法律。"
It has 18 read-only tools, three prompts and a resource template. The tools cover finding a provision, reading it on a date, who wrote each word, comparing dates, a provision's history, the laws between two dates, searching the text and the change notes, when words entered or left the law, what else a change affects, checking precedent, resolving the citations in a brief, and which text applies to a case. Old paths with ISO country codes (`us/federal/usc/...`, `de`) are still read. MCP.md has the full tool list, the protocol versions, the security measures and how it compares with other law MCP servers. The tests are `python -m unittest tests.test_mcp`.
它包含18个只读工具、三个提示词和一个资源模板。这些工具涵盖查找条款、查看特定日期的条款内容、追溯每个词的起草者、比较日期、查看条款历史、查询两个日期之间的法律、搜索文本和变更说明、了解词汇进入或退出法律的时间、分析变更的影响范围、检查先例、解决摘要中的引文冲突,以及确定适用于某案件的文本。带有ISO国家代码的旧路径(如 `us/federal/usc/...`、`de`)仍支持读取。`MCP.md` 文件列出了完整的工具列表、协议版本、安全措施以及与其他法律 MCP 服务器的对比。测试命令为 `python -m unittest tests.test_mcp`。
How it is built
构建方式
- The first commit, dated 1 January 1970, holds the jurisdiction tree and the list of corpora, and no law. - Every later commit moves exactly one corpus to its next commit. Its author is the law, as in the corpus, and its trailers name the corpus, the corpus commit, the law and the in-force date. - The order is the in-force date, keeping each corpus's own order. - The last commit adds this README, the tools and the tests. - The build is deterministic. When a corpus is rebuilt, for example after a correction, this repository is rebuilt from scratch and force-pushed.
- 第一个提交记录日期为1970年1月1日,包含了管辖权树和语料库列表,但不包含任何法律文本。 - 随后的每次提交仅将一个语料库推进到其下一个提交状态。提交的作者即为该语料库所代表的法律,与语料库一致;提交信息中的尾部字段(trailers)标明了语料库名称、语料库提交哈希、法律名称及生效日期。 - 提交顺序按生效日期排列,同时保持每个语料库内部的原有顺序。 - 最后一次提交添加了此 README 文件、工具和测试用例。 - 构建过程是确定性的。当某个语料库因修正等原因重新构建时,整个仓库将从头重建并强制推送。
Dates
日期处理
Git cannot store dates before 1970, so changes to the Grundgesetz that took effect earlier carry 1970 commit dates, one second apart, in the right order. The `In-force` trailer is authoritative and the tools use it, so `law.py show 1956-03-19 …` works.
Git 无法存储1970年之前的日期,因此对《基本法》(Grundgesetz)的早期变更虽然实际生效时间更早,但在 Git 中记录的提交日期均为1970年,且彼此间隔一秒,并按正确的时间顺序排列。`In-force`(生效)尾部字段具有权威性,工具也依赖该字段,因此执行 `law.py show 1956-03-19 …` 可以正常工作。
What it does not show
未展示的内容
- Each corpus covers only what its README says. A file missing on a date can mean the provision was not yet in force or that the corpus does not reach that far back. - A later law that reaches back to earlier dates (retroactive application) is recorded in the corpus's commit messages but does not change the text shown on those earlier dates. - `git blame` works by line, so a line changed in part is credited to the last law that touched it. `law.py words` credits each word instead, by comparing each version with the one before; text rewritten in place is credited to the law that rewrote it, even where a few of its words are the same as before.
- 每个语料库仅涵盖其 README 所述的内容。某日期缺失文件可能意味着相关规定尚未生效,或该语料库未追溯至那么早的时期。 - 追溯至更早日期的后续法律(具有溯及力)会记录在语料库的提交信息中,但不会改变那些较早日期显示的文本。 - `git blame` 按行工作,因此部分更改的行归功于最后修改它的法律。`law.py words` 则通过比较每个版本与其前一个版本来归因于每个单词;原地重写的文本归功于重写它的法律,即使其中一些单词与之前相同。
Visualisation suite
可视化套件
See all global law cohort visualisations and bridges here
在此查看所有全球法律队列可视化和桥梁
Reading it
阅读它
Dates must be written YYYY-MM-DD. When a date falls before a record starts or after it ends, the tools say so on stderr, because each country's record covers a different period (see `record_to` in `manifest.json`).
日期必须写成 YYYY-MM-DD 格式。当日期落在记录开始之前或结束之后时,工具会在 stderr 上提示,因为每个国家的记录覆盖不同的时间段(参见 `manifest.json` 中的 `record_to`)。
Plain git works too, with care:
普通的 git 也可以,但需谨慎使用:
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力