law-cn-cli 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- law_cn_cli-0.2.0/LICENSE +131 -0
- law_cn_cli-0.2.0/PKG-INFO +430 -0
- law_cn_cli-0.2.0/README.md +402 -0
- law_cn_cli-0.2.0/cnlaw/__init__.py +6 -0
- law_cn_cli-0.2.0/cnlaw/__main__.py +5 -0
- law_cn_cli-0.2.0/cnlaw/adapters/__init__.py +6 -0
- law_cn_cli-0.2.0/cnlaw/adapters/base.py +212 -0
- law_cn_cli-0.2.0/cnlaw/adapters/bse.py +232 -0
- law_cn_cli-0.2.0/cnlaw/adapters/cac.py +343 -0
- law_cn_cli-0.2.0/cnlaw/adapters/court.py +152 -0
- law_cn_cli-0.2.0/cnlaw/adapters/csrc.py +455 -0
- law_cn_cli-0.2.0/cnlaw/adapters/gov_policy.py +254 -0
- law_cn_cli-0.2.0/cnlaw/adapters/gov_rules.py +487 -0
- law_cn_cli-0.2.0/cnlaw/adapters/mee.py +177 -0
- law_cn_cli-0.2.0/cnlaw/adapters/miit.py +283 -0
- law_cn_cli-0.2.0/cnlaw/adapters/mod.py +192 -0
- law_cn_cli-0.2.0/cnlaw/adapters/moj.py +182 -0
- law_cn_cli-0.2.0/cnlaw/adapters/neeq.py +37 -0
- law_cn_cli-0.2.0/cnlaw/adapters/nfra.py +208 -0
- law_cn_cli-0.2.0/cnlaw/adapters/npc.py +859 -0
- law_cn_cli-0.2.0/cnlaw/adapters/party.py +185 -0
- law_cn_cli-0.2.0/cnlaw/adapters/samr.py +236 -0
- law_cn_cli-0.2.0/cnlaw/adapters/spp.py +292 -0
- law_cn_cli-0.2.0/cnlaw/adapters/sse.py +231 -0
- law_cn_cli-0.2.0/cnlaw/adapters/szse.py +186 -0
- law_cn_cli-0.2.0/cnlaw/adapters/tax.py +258 -0
- law_cn_cli-0.2.0/cnlaw/adapters/treaty.py +331 -0
- law_cn_cli-0.2.0/cnlaw/adapters/utils.py +36 -0
- law_cn_cli-0.2.0/cnlaw/cli.py +725 -0
- law_cn_cli-0.2.0/cnlaw/errors.py +22 -0
- law_cn_cli-0.2.0/cnlaw/federated.py +378 -0
- law_cn_cli-0.2.0/cnlaw/models.py +329 -0
- law_cn_cli-0.2.0/cnlaw/registry.py +86 -0
- law_cn_cli-0.2.0/cnlaw/skill_installer.py +250 -0
- law_cn_cli-0.2.0/cnlaw/skill_templates/cnlaw-search/SKILL.md +64 -0
- law_cn_cli-0.2.0/cnlaw/skill_templates/cnlaw-search/agents/openai.yaml +4 -0
- law_cn_cli-0.2.0/cnlaw/skill_templates/cnlaw-search/references/cli-reference.md +56 -0
- law_cn_cli-0.2.0/cnlaw/skill_templates/cnlaw-search/references/evidence-validation.md +35 -0
- law_cn_cli-0.2.0/cnlaw/skill_templates/cnlaw-search/references/output-contract.md +31 -0
- law_cn_cli-0.2.0/cnlaw/skill_templates/cnlaw-search/references/query-planning.md +50 -0
- law_cn_cli-0.2.0/cnlaw/skill_templates/cnlaw-search/references/research-workflow.md +29 -0
- law_cn_cli-0.2.0/cnlaw/skill_templates/cnlaw-search/references/source-routing.md +29 -0
- law_cn_cli-0.2.0/cnlaw/transport.py +239 -0
- law_cn_cli-0.2.0/law_cn_cli.egg-info/PKG-INFO +430 -0
- law_cn_cli-0.2.0/law_cn_cli.egg-info/SOURCES.txt +59 -0
- law_cn_cli-0.2.0/law_cn_cli.egg-info/dependency_links.txt +1 -0
- law_cn_cli-0.2.0/law_cn_cli.egg-info/entry_points.txt +2 -0
- law_cn_cli-0.2.0/law_cn_cli.egg-info/requires.txt +10 -0
- law_cn_cli-0.2.0/law_cn_cli.egg-info/top_level.txt +1 -0
- law_cn_cli-0.2.0/pyproject.toml +62 -0
- law_cn_cli-0.2.0/setup.cfg +4 -0
- law_cn_cli-0.2.0/tests/test_cli.py +523 -0
- law_cn_cli-0.2.0/tests/test_document_cache.py +48 -0
- law_cn_cli-0.2.0/tests/test_federated.py +293 -0
- law_cn_cli-0.2.0/tests/test_friendly_mappings.py +131 -0
- law_cn_cli-0.2.0/tests/test_live_patrol.py +70 -0
- law_cn_cli-0.2.0/tests/test_models.py +92 -0
- law_cn_cli-0.2.0/tests/test_pagination.py +47 -0
- law_cn_cli-0.2.0/tests/test_registry.py +40 -0
- law_cn_cli-0.2.0/tests/test_skill_installer.py +53 -0
- law_cn_cli-0.2.0/tests/test_transport.py +56 -0
law_cn_cli-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# PolyForm Noncommercial License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
In order to get any license under these terms, you must agree
|
|
8
|
+
to them as both strict obligations and conditions to all
|
|
9
|
+
your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the
|
|
14
|
+
software to do everything you might do with the software
|
|
15
|
+
that would otherwise infringe the licensor's copyright
|
|
16
|
+
in it for any permitted purpose. However, you may
|
|
17
|
+
only distribute the software according to [Distribution
|
|
18
|
+
License](#distribution-license) and make changes or new works
|
|
19
|
+
based on the software according to [Changes and New Works
|
|
20
|
+
License](#changes-and-new-works-license).
|
|
21
|
+
|
|
22
|
+
## Distribution License
|
|
23
|
+
|
|
24
|
+
The licensor grants you an additional copyright license
|
|
25
|
+
to distribute copies of the software. Your license
|
|
26
|
+
to distribute covers distributing the software with
|
|
27
|
+
changes and new works permitted by [Changes and New Works
|
|
28
|
+
License](#changes-and-new-works-license).
|
|
29
|
+
|
|
30
|
+
## Notices
|
|
31
|
+
|
|
32
|
+
You must ensure that anyone who gets a copy of any part of
|
|
33
|
+
the software from you also gets a copy of these terms or the
|
|
34
|
+
URL for them above, as well as copies of any plain-text lines
|
|
35
|
+
beginning with `Required Notice:` that the licensor provided
|
|
36
|
+
with the software. For example:
|
|
37
|
+
|
|
38
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
39
|
+
|
|
40
|
+
## Changes and New Works License
|
|
41
|
+
|
|
42
|
+
The licensor grants you an additional copyright license to
|
|
43
|
+
make changes and new works based on the software for any
|
|
44
|
+
permitted purpose.
|
|
45
|
+
|
|
46
|
+
## Patent License
|
|
47
|
+
|
|
48
|
+
The licensor grants you a patent license for the software that
|
|
49
|
+
covers patent claims the licensor can license, or becomes able
|
|
50
|
+
to license, that you would infringe by using the software.
|
|
51
|
+
|
|
52
|
+
## Noncommercial Purposes
|
|
53
|
+
|
|
54
|
+
Any noncommercial purpose is a permitted purpose.
|
|
55
|
+
|
|
56
|
+
## Personal Uses
|
|
57
|
+
|
|
58
|
+
Personal use for research, experiment, and testing for
|
|
59
|
+
the benefit of public knowledge, personal study, private
|
|
60
|
+
entertainment, hobby projects, amateur pursuits, or religious
|
|
61
|
+
observance, without any anticipated commercial application,
|
|
62
|
+
is use for a permitted purpose.
|
|
63
|
+
|
|
64
|
+
## Noncommercial Organizations
|
|
65
|
+
|
|
66
|
+
Use by any charitable organization, educational institution,
|
|
67
|
+
public research organization, public safety or health
|
|
68
|
+
organization, environmental protection organization,
|
|
69
|
+
or government institution is use for a permitted purpose
|
|
70
|
+
regardless of the source of funding or obligations resulting
|
|
71
|
+
from the funding.
|
|
72
|
+
|
|
73
|
+
## Fair Use
|
|
74
|
+
|
|
75
|
+
You may have "fair use" rights for the software under the
|
|
76
|
+
law. These terms do not limit them.
|
|
77
|
+
|
|
78
|
+
## No Other Rights
|
|
79
|
+
|
|
80
|
+
These terms do not allow you to sublicense or transfer any of
|
|
81
|
+
your licenses to anyone else, or prevent the licensor from
|
|
82
|
+
granting licenses to anyone else. These terms do not imply
|
|
83
|
+
any other licenses.
|
|
84
|
+
|
|
85
|
+
## Patent Defense
|
|
86
|
+
|
|
87
|
+
If you make any written claim that the software infringes or
|
|
88
|
+
contributes to infringement of any patent, your patent license
|
|
89
|
+
for the software granted under these terms ends immediately. If
|
|
90
|
+
your company makes such a claim, your patent license ends
|
|
91
|
+
immediately for work on behalf of your company.
|
|
92
|
+
|
|
93
|
+
## Violations
|
|
94
|
+
|
|
95
|
+
The first time you are notified in writing that you have
|
|
96
|
+
violated any of these terms, or done anything with the software
|
|
97
|
+
not covered by your licenses, your licenses can nonetheless
|
|
98
|
+
continue if you come into full compliance with these terms,
|
|
99
|
+
and take practical steps to correct past violations, within
|
|
100
|
+
32 days of receiving notice. Otherwise, all your licenses
|
|
101
|
+
end immediately.
|
|
102
|
+
|
|
103
|
+
## No Liability
|
|
104
|
+
|
|
105
|
+
***As far as the law allows, the software comes as is, without
|
|
106
|
+
any warranty or condition, and the licensor will not be liable
|
|
107
|
+
to you for any damages arising out of these terms or the use
|
|
108
|
+
or nature of the software, under any kind of legal claim.***
|
|
109
|
+
|
|
110
|
+
## Definitions
|
|
111
|
+
|
|
112
|
+
The **licensor** is the individual or entity offering these
|
|
113
|
+
terms, and the **software** is the software the licensor makes
|
|
114
|
+
available under these terms.
|
|
115
|
+
|
|
116
|
+
**You** refers to the individual or entity agreeing to these
|
|
117
|
+
terms.
|
|
118
|
+
|
|
119
|
+
**Your company** is any legal entity, sole proprietorship,
|
|
120
|
+
or other kind of organization that you work for, plus all
|
|
121
|
+
organizations that have control over, are under the control of,
|
|
122
|
+
or are under common control with that organization. **Control**
|
|
123
|
+
means ownership of substantially all the assets of an entity,
|
|
124
|
+
or the power to direct its management and policies by vote,
|
|
125
|
+
contract, or otherwise. Control can be direct or indirect.
|
|
126
|
+
|
|
127
|
+
**Your licenses** are all the licenses granted to you for the
|
|
128
|
+
software under these terms.
|
|
129
|
+
|
|
130
|
+
**Use** means anything you do with the software requiring one
|
|
131
|
+
of your licenses.
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: law-cn-cli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Unified CLI for official Chinese legal information sources
|
|
5
|
+
License-Expression: PolyForm-Noncommercial-1.0.0
|
|
6
|
+
Keywords: china-law,legal-research,regulations,cli
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Environment :: Console
|
|
9
|
+
Classifier: Intended Audience :: Legal Industry
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: beautifulsoup4>=4.12
|
|
19
|
+
Requires-Dist: cryptography>=42.0
|
|
20
|
+
Requires-Dist: httpx[socks]>=0.27
|
|
21
|
+
Requires-Dist: PyYAML>=6.0
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
25
|
+
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
26
|
+
Requires-Dist: twine>=5.0; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# law-cn-cli
|
|
30
|
+
|
|
31
|
+
`law-cn-cli` 将 20 个中国境内官方法律、法规、规章、政策和交易规则来源统一为一套命令语法。发行包名称是 `law-cn-cli`,安装后的命令仍为 `cnlaw`:
|
|
32
|
+
|
|
33
|
+
```text
|
|
34
|
+
cnlaw search <source-code> <keyword> [统一检索选项]
|
|
35
|
+
cnlaw search auto <keyword> [--sources code,...] [--view grouped|raw]
|
|
36
|
+
cnlaw search all <keyword> [--view grouped|raw]
|
|
37
|
+
cnlaw info <source-code> <document-id-or-official-url>
|
|
38
|
+
cnlaw article npc <document-id> <条号>
|
|
39
|
+
cnlaw preview npc <document-id>
|
|
40
|
+
cnlaw article-search npc <keyword> [--max-laws N]
|
|
41
|
+
cnlaw download <source-code> <document-id> --format docx|pdf
|
|
42
|
+
cnlaw skill install|update|status|path|uninstall
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
这是一个从各官网当前实际请求重新验证、独立实现的项目。项目会明确区分公开开发 API、官网前端内部 JSON 接口和 HTML 检索端点;“能被官网调用”不等于“有公开开发文档或稳定性承诺”。
|
|
46
|
+
|
|
47
|
+
20 个来源均实现了 `info`。国家法律法规数据库使用结构化详情接口;其他来源按各站当前详情接口或官方详情 HTML 解析。URL 型输入会校验来源官方域名,不允许把任意 URL 当成请求目标。
|
|
48
|
+
|
|
49
|
+
`cnlaw article npc` 会调用国家法律法规数据库的官方 DOCX 下载接口,解析后输出完整条文。可用条号(如 `第二十八条`、`第28条`、`28`)或 `--grep` 检索单篇法规内的所有命中条文。短期签名 URL 不会写入输出或缓存;原始官方文件默认进入本地持久化缓存,避免后续条文检索重复下载。
|
|
50
|
+
|
|
51
|
+
## 安装
|
|
52
|
+
|
|
53
|
+
需要 Python 3.11 或更高版本。
|
|
54
|
+
|
|
55
|
+
推荐通过 `uv` 安装为隔离的全局命令:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
uv tool install law-cn-cli
|
|
59
|
+
cnlaw --version
|
|
60
|
+
cnlaw sources
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
命令自身带完整帮助,可逐层查看:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
cnlaw --help
|
|
67
|
+
cnlaw search --help
|
|
68
|
+
cnlaw article-search --help
|
|
69
|
+
cnlaw skill --help
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
升级或卸载:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
uv tool upgrade law-cn-cli
|
|
76
|
+
uv tool uninstall law-cn-cli
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
也可以使用 `pip`:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
python3 -m pip install law-cn-cli
|
|
83
|
+
cnlaw sources
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
从源码参与开发时,在项目根目录运行:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
python3 -m venv .venv
|
|
90
|
+
.venv/bin/pip install -e '.[dev]'
|
|
91
|
+
.venv/bin/cnlaw --version
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 基本用法
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# 查看全部来源
|
|
98
|
+
cnlaw sources
|
|
99
|
+
|
|
100
|
+
# 查看单个来源原生支持的检索能力
|
|
101
|
+
cnlaw capabilities npc
|
|
102
|
+
|
|
103
|
+
# 查看该来源经官网请求核验过的额外检索字段及请求字段名
|
|
104
|
+
cnlaw parameters tax --format json
|
|
105
|
+
|
|
106
|
+
# 国家法律法规数据库:标题检索
|
|
107
|
+
cnlaw search npc '劳动合同法' --format json
|
|
108
|
+
|
|
109
|
+
# 国家法律法规数据库:读取官方详情
|
|
110
|
+
cnlaw info npc 2c909fdd678bf17901678bf74d7106b3
|
|
111
|
+
|
|
112
|
+
# 国家法律法规数据库:提取完整条文
|
|
113
|
+
cnlaw article npc 2c909fdd678bf17901678bf74d7106b3 '第二十八条'
|
|
114
|
+
cnlaw article npc 2c909fdd678bf17901678bf74d7106b3 --grep '劳动报酬'
|
|
115
|
+
|
|
116
|
+
# 返回完整目录、总条数和全部条号(不抽样)
|
|
117
|
+
cnlaw preview npc 2c909fdd678bf17901678bf74d7106b3
|
|
118
|
+
|
|
119
|
+
# 跨法规条文检索;默认处理全部候选法规
|
|
120
|
+
cnlaw article-search npc '民法典第三百一十一条'
|
|
121
|
+
|
|
122
|
+
# 只有用户明确希望截断时才设置候选法规数量
|
|
123
|
+
cnlaw article-search npc '民法典第三百一十一条' --max-laws 20
|
|
124
|
+
|
|
125
|
+
# 显式下载;格式参数决定官网实际请求的文件格式
|
|
126
|
+
cnlaw download npc 2c909fdd678bf17901678bf74d7106b3 \
|
|
127
|
+
--format pdf \
|
|
128
|
+
--output './劳动合同法.pdf'
|
|
129
|
+
|
|
130
|
+
# 检查持久化文件缓存
|
|
131
|
+
cnlaw cache stats
|
|
132
|
+
|
|
133
|
+
# 国家法律法规数据库:正文检索具体条文引用
|
|
134
|
+
cnlaw search npc '民法典第三百一十一条' \
|
|
135
|
+
--scope content \
|
|
136
|
+
--format jsonl
|
|
137
|
+
|
|
138
|
+
# 国家规章库
|
|
139
|
+
cnlaw search gov-rules '管理办法' --scope title --sort newest
|
|
140
|
+
|
|
141
|
+
# 上交所规则
|
|
142
|
+
cnlaw search sse '信息披露' --scope all
|
|
143
|
+
|
|
144
|
+
# 金融监管总局,完整写入可审计目录
|
|
145
|
+
cnlaw search nfra '善意取得' \
|
|
146
|
+
--scope all \
|
|
147
|
+
--output './runs/nfra-good-faith'
|
|
148
|
+
|
|
149
|
+
# 国家法律法规数据库:搜索建议
|
|
150
|
+
cnlaw suggest npc '劳动合同'
|
|
151
|
+
|
|
152
|
+
# 国家法律法规数据库:查看单篇文件中的关键词命中位置
|
|
153
|
+
cnlaw highlight npc 2c909fdd678bf17901678bf74d7106b3 '劳动报酬'
|
|
154
|
+
|
|
155
|
+
# 国家法律法规数据库:读取关联资料
|
|
156
|
+
cnlaw related npc 2c909fdd678bf17901678bf74d7106b3 '劳动合同'
|
|
157
|
+
|
|
158
|
+
# 国家法律法规数据库:批量下载;所有 ID 都会处理,失败项单独列出
|
|
159
|
+
cnlaw batch-download npc \
|
|
160
|
+
2c909fdd678bf17901678bf74d7106b3 \
|
|
161
|
+
ANOTHER_DOCUMENT_ID \
|
|
162
|
+
--format docx \
|
|
163
|
+
--output-dir './downloads'
|
|
164
|
+
|
|
165
|
+
# 网信办高级检索:连续关键词按官网语义作顺序敏感的短语检索
|
|
166
|
+
cnlaw search cac '生成式人工智能服务管理暂行办法' \
|
|
167
|
+
--scope title \
|
|
168
|
+
--match exact \
|
|
169
|
+
--source-param required_phrase=生成式人工智能 \
|
|
170
|
+
--source-param exclude_terms=征求意见 \
|
|
171
|
+
--source-param directory=网信政务
|
|
172
|
+
|
|
173
|
+
# 网信办法规栏目 JSON 接口:枚举该分类的全部记录并保存审计清单
|
|
174
|
+
cnlaw catalog cac \
|
|
175
|
+
--category 部门规章 \
|
|
176
|
+
--format jsonl \
|
|
177
|
+
--output './cac-department-rules'
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
如果没有指定 `--scope`,CLI 会为该来源自动选择其支持的优先范围:`title`、`all`、`content`。显式指定了来源不支持的筛选项时,命令会报错,不会悄悄忽略条件。
|
|
181
|
+
|
|
182
|
+
`suggest`、`highlight`、`related`、`article`、`preview`、`article-search` 和 `batch-download` 当前只支持 `npc`。`catalog` 当前支持 `cac`。批量下载会处理命令中给出的全部 ID;任一项目失败时仍保留其他成功结果,并以非零退出码和 `failures` 字段明确报告。
|
|
183
|
+
|
|
184
|
+
## 统一检索选项
|
|
185
|
+
|
|
186
|
+
```text
|
|
187
|
+
--scope title|content|all
|
|
188
|
+
--match fuzzy|exact
|
|
189
|
+
--status VALUE 可重复
|
|
190
|
+
--document-type VALUE 可重复
|
|
191
|
+
--authority VALUE 可重复
|
|
192
|
+
--publish-from YYYY-MM-DD
|
|
193
|
+
--publish-to YYYY-MM-DD
|
|
194
|
+
--effective-from YYYY-MM-DD
|
|
195
|
+
--effective-to YYYY-MM-DD
|
|
196
|
+
--sort relevance|newest|oldest
|
|
197
|
+
--limit N
|
|
198
|
+
--source-param KEY=VALUE 单站来源特有字段
|
|
199
|
+
--source-param SOURCE:KEY=VALUE auto/all 中按来源限定的特有字段
|
|
200
|
+
--format table|json|jsonl
|
|
201
|
+
--output DIRECTORY
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
不同官网原生能力不同。先运行 `cnlaw capabilities <source>`,即可知道某个选项是 `native`、`emulated` 还是不支持。
|
|
205
|
+
|
|
206
|
+
运行 `cnlaw parameters <source>` 可查看该站的高级字段、对应官网请求字段、类型、可重复性和已知枚举。单站检索用 `--source-param KEY=VALUE`;`auto/all` 用 `--source-param SOURCE:KEY=VALUE`,避免把一个网站的字段错误广播到其他网站。未知字段、错误枚举和不允许重复的字段会直接报错。
|
|
207
|
+
|
|
208
|
+
### 网信办接口说明
|
|
209
|
+
|
|
210
|
+
网信办适配器使用两条不同的官网数据路径,避免把栏目枚举错误包装成全文检索:
|
|
211
|
+
|
|
212
|
+
- `cnlaw search cac KEYWORD` 调用高级检索 JSP。支持 `title`、`content`、`all`,公布日期区间,相关度/最新/最早排序,以及 `required_phrase`、`exclude_terms`、`directory`。`directory` 只接受官网高级检索表单实际可用的顶层栏目:`全站`、`热点专题`、`要闻`、`网信政务`、`互动服务`。
|
|
213
|
+
- `cnlaw catalog cac --category CATEGORY` 调用 `/cms/JsonList`,支持 `全部`、`法律`、`行政法规`、`部门规章`、`司法解释`、`规范性文件`、`政策文件`、`政策解读`。该命令返回目录元数据(标题、摘要、日期和官方详情页链接),不把摘要冒充法规全文。
|
|
214
|
+
|
|
215
|
+
网信办高级检索中,连续关键词具有顺序敏感的短语效果;`--match exact` 表示这一官网“完整连续短语”语义,不表示标题必须与关键词逐字完全相等。中文逗号分隔的主关键词按官网行为表示任一短语命中。官网表单虽存在 `inpro` 字段,但在线验证中该字段未产生可靠结果,因此 CLI 不将它宣称为可用参数。法规深层分类代码也不能由高级检索接口可靠过滤,所以由 `catalog` 命令通过 JSON 栏目接口提供。
|
|
216
|
+
|
|
217
|
+
`catalog` 的内部每页数量只用于请求分批,不是输出上限。命令根据官网 `totalRec` 持续翻页,默认保留全部原始记录,不抽样、不去重;输出清单中的 `pages_fetched`、`records_written`、`total_reported` 和 `truncated` 可用于核验完整性。
|
|
218
|
+
|
|
219
|
+
维护仓库中的 20 站请求审计还记录了 CLI 自动维护、但不允许用户覆写的分页、回调、站点范围和动态鉴权字段。该维护档案不属于 wheel/sdist 的公开运行时内容;公开用户应以 `cnlaw capabilities` 和 `cnlaw parameters` 的实际输出为准。
|
|
220
|
+
|
|
221
|
+
`--limit` 没有默认值。未明确传入时,适配器会按照官网返回的总数或总页数继续翻页,不会为了方便静默截断。传入 `--limit` 是用户明确要求截断;输出清单会记录 `explicit_limit` 和 `truncated`。
|
|
222
|
+
|
|
223
|
+
## 跨来源规则路由
|
|
224
|
+
|
|
225
|
+
`cnlaw search auto KEYWORD` 使用可审计的确定性分层路由,而不是在 CLI 内调用大模型。默认双核心是国家法律法规数据库
|
|
226
|
+
`npc` 与国家规章库 `gov-rules`;规章库默认限定为“部门规章”。关键词出现明确
|
|
227
|
+
省级地域或“地方政府规章”时,规章库切换为“地方政府规章”。随后按司法、检察、
|
|
228
|
+
政策、网信、金融、市场监管、税务、生态环境、交易所、条约等主题增加对应专业
|
|
229
|
+
来源。
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# 查看路由计划,不发出搜索请求
|
|
233
|
+
cnlaw search auto '上海市生成式人工智能管理规定' --explain-routing
|
|
234
|
+
|
|
235
|
+
# 执行规则路由并按同一文件聚类展示
|
|
236
|
+
cnlaw search auto '生成式人工智能服务管理暂行办法' --format json
|
|
237
|
+
|
|
238
|
+
# 显式限定参与的来源
|
|
239
|
+
cnlaw search auto '量刑建议' --sources npc,gov-rules,spp
|
|
240
|
+
|
|
241
|
+
# 在跨来源检索中覆盖某一站的原生字段
|
|
242
|
+
cnlaw search auto '北京市人工智能' \
|
|
243
|
+
--source-param gov-rules:category=地方政府规章
|
|
244
|
+
|
|
245
|
+
# 请求全部 20 个来源
|
|
246
|
+
cnlaw search all '善意取得' --view raw --format jsonl
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
实际网络请求会按来源并发执行,结果仍按路由计划中的来源顺序稳定汇总。一个来源
|
|
250
|
+
失败不会阻塞其他来源。
|
|
251
|
+
|
|
252
|
+
`auto/all` 的默认 `grouped` 视图只用于减少视觉重复。每个聚类的 `records`
|
|
253
|
+
字段仍保留全部来源记录;`--view raw` 直接输出所有原始记录。标准化标题一致的
|
|
254
|
+
记录归入同一文件族;发布日期、文号或发布机关存在冲突时,在族内拆为 `versions`
|
|
255
|
+
并标记 `version_conflict=true`,不会把冲突版本当成同一份文本。
|
|
256
|
+
|
|
257
|
+
跨源相关度分数不直接相加。聚类选择展示记录时按文件类型优先规范文本或制定机关
|
|
258
|
+
官网,但不会删除其他官方来源。输出 `manifest.json` 记录所选来源、路由理由、
|
|
259
|
+
逐源检索清单、跳过原因、来源失败、原始记录数和聚类数。一个来源失败时保留其他
|
|
260
|
+
来源结果并以非零退出码明确报告,不静默吞掉失败。
|
|
261
|
+
|
|
262
|
+
`auto/all` 没有默认结果上限;`--limit N` 在联邦检索中明确表示“每个来源最多
|
|
263
|
+
N 条”,并写入 `explicit_limit_per_source`。来源特有参数必须写成
|
|
264
|
+
`SOURCE:KEY=VALUE`;未限定来源的写法会直接报错。
|
|
265
|
+
|
|
266
|
+
## 安装 Agent Skill
|
|
267
|
+
|
|
268
|
+
包内自带 `cnlaw-search` Skill,用于让支持 Skills 的 Agent 在运行 CLI 前进行实时
|
|
269
|
+
查询规划、全网候选发现、官方回查、效力核验和证据分级。它不会自动写入用户目录;
|
|
270
|
+
安装必须由用户显式执行:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
cnlaw skill install --agent auto
|
|
274
|
+
cnlaw skill status --agent auto
|
|
275
|
+
cnlaw skill path --agent auto
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
`auto` 会优先识别 Codex 的 Skills 目录,其次识别通用 `~/.agents/skills`。也可以
|
|
279
|
+
用 `--agent codex|agents` 或 `--target-root PATH` 明确指定位置。升级包后运行:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
cnlaw skill update --agent auto
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
安装器通过文件哈希记录自身写入的文件。若用户修改了 Skill,更新和卸载会拒绝
|
|
286
|
+
覆盖或删除;只有显式传入 `--force` 才会处理修改过的已登记文件。卸载命令为
|
|
287
|
+
`cnlaw skill uninstall`。
|
|
288
|
+
|
|
289
|
+
Skill 由一个入口 `SKILL.md`、Agent 元数据和六份按需读取的 reference 组成:
|
|
290
|
+
研究流程、实时查询规划、来源路由、CLI 命令、证据核验和输出契约。宽泛概念不会
|
|
291
|
+
依赖无法穷尽的本地同义词表;Agent 实时生成候选查询,并保留用户原始检索词。
|
|
292
|
+
网页搜索或 AI 记忆只能产生候选,最终法源仍须回到 CLI 或制定机关官网核验。
|
|
293
|
+
|
|
294
|
+
## 原文文件缓存
|
|
295
|
+
|
|
296
|
+
NPC 的 `article`、`preview`、`article-search` 和 `download` 默认复用持久化的官方 DOCX/PDF:
|
|
297
|
+
|
|
298
|
+
- 默认目录:`~/.cache/cnlaw/documents`
|
|
299
|
+
- 默认有效期:7 天,命令帮助和缓存元数据均明确记录为 `604800` 秒
|
|
300
|
+
- 缓存键:来源 + 官方 document ID + 文件格式
|
|
301
|
+
- 缓存内容:原始公开文件及哈希、大小、缓存时间;不保存短期签名 URL
|
|
302
|
+
- `--refresh`:强制重新获取并更新缓存
|
|
303
|
+
- `--no-cache`:本次既不读取也不写入缓存
|
|
304
|
+
- `--cache-dir PATH`、`--cache-max-age-days N`:显式调整位置和有效期
|
|
305
|
+
- `cnlaw cache stats`:查看条目、大小、路径和有效期
|
|
306
|
+
- `cnlaw cache clear`:仅清理由 cnlaw 标记并拥有的缓存目录
|
|
307
|
+
|
|
308
|
+
`article`、`preview` 输出 `file_cache_hit`;`article-search` 输出 `cache_hits` 和 `files_downloaded`;显式下载输出 `cache_hit`,因此是否发生重复下载可以直接审计。
|
|
309
|
+
|
|
310
|
+
## 输出与审计
|
|
311
|
+
|
|
312
|
+
### 检索输出
|
|
313
|
+
|
|
314
|
+
每条记录统一包含:
|
|
315
|
+
|
|
316
|
+
- `source`、`source_name`、`source_document_id`
|
|
317
|
+
- `title`、`official_url`
|
|
318
|
+
- `document_type`、`issuing_authority`、`document_number`
|
|
319
|
+
- `publish_date`、`effective_date`
|
|
320
|
+
- `validity_status`、`validity_explicit`
|
|
321
|
+
- `summary`、`content`、`download_urls`
|
|
322
|
+
- `retrieved_at`、`source_rank`
|
|
323
|
+
- `raw_metadata`
|
|
324
|
+
|
|
325
|
+
### 详情输出(`cnlaw info`)
|
|
326
|
+
|
|
327
|
+
结构化 JSON,至少包含:
|
|
328
|
+
|
|
329
|
+
- `official_url`、`title`、`source_document_id`
|
|
330
|
+
- `body`、`body_availability`、`body_note`、`content_outline`
|
|
331
|
+
- `document_type`、`issuing_authority`、`publish_date`、`effective_date`、`validity_status`
|
|
332
|
+
- `attachments`(官方 `ossFile` 路径及不含签名的 `download_endpoint` 模板)
|
|
333
|
+
- `retrieved_at`、`raw_metadata`
|
|
334
|
+
|
|
335
|
+
当详情接口只返回目录/条文标题而无正文时,`body_availability` 为 `outline_only`;当接口未返回正文结构、仅列出可下载附件时为 `download_only`。CLI 不会下载或解析附件内容。
|
|
336
|
+
|
|
337
|
+
### 条文输出(`cnlaw article npc`)
|
|
338
|
+
|
|
339
|
+
`article` 使用官方 DOCX 下载接口取得原文并解析。输出包含官方详情页、法规标题、检索条件、完整命中条文和 `file_cache_hit`。原始文件按上文规则进入持久化缓存,但不输出带签名的临时下载 URL。
|
|
340
|
+
|
|
341
|
+
`article-search` 的每条命中都携带所属法规 ID、标题、官方详情页、条号和条文文本;任何下载或解析失败都会进入 `failures`,不会静默丢弃。未传 `--max-laws` 时处理全部候选法规;显式设置后,输出会记录候选总数、本批偏移、明确请求的法规数、实际解析数和下一批偏移。
|
|
342
|
+
|
|
343
|
+
使用 `--output` 时生成:
|
|
344
|
+
|
|
345
|
+
```text
|
|
346
|
+
DIRECTORY/
|
|
347
|
+
├── records.jsonl
|
|
348
|
+
└── manifest.json
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
`manifest.json` 记录抓取页数、写入条数、官网报告总数、显式限制以及是否截断。已有同名文件时命令拒绝覆盖。
|
|
352
|
+
|
|
353
|
+
## 来源与能力
|
|
354
|
+
|
|
355
|
+
| code | 官方来源 | 传输方式 | 检索范围 | 其他原生筛选 |
|
|
356
|
+
|---|---|---|---|---|
|
|
357
|
+
| `npc` | 国家法律法规数据库 | JSON | title, content | exact, status, 类型, 制定机关 |
|
|
358
|
+
| `gov-rules` | 国家规章库 | JSON + 官网动态鉴权 | title, all | newest |
|
|
359
|
+
| `gov-policy` | 国务院政策文件库 | JSON | title, content, all | newest;文件库、分类、标签、文号、年份、部门、日期 |
|
|
360
|
+
| `moj` | 司法部行政法规库 | HTML | title, content | status, 公布/施行日期, newest/oldest |
|
|
361
|
+
| `court` | 最高人民法院 | HTML | all | — |
|
|
362
|
+
| `spp` | 最高人民检察院法律法规库 | 官方静态 HTML 栏目 | title | exact, 公布日期, newest/oldest;宪法、法律、司法解释、规范文件 |
|
|
363
|
+
| `party` | 党内法规库 | JSONP | title, content | newest |
|
|
364
|
+
| `treaty` | 外交部条约数据库 | HTML | title | 施行日期;条约分类、缔约国、领域、签署日期、港澳分类 |
|
|
365
|
+
| `tax` | 国家税务总局政策法规库 | JSON | title, all | exact, 公布日期, status, newest;效力级别、税种及二级分类、文号、行业、制定年份 |
|
|
366
|
+
| `mee` | 生态环境部法规标准 | HTML | title, content, all | 公布日期, newest/oldest |
|
|
367
|
+
| `csrc` | 证监会证券期货法规数据库 | JSON | title, content(可组合) | exact, authority, status, 公布日期, newest;标题/正文各三词 AND/OR、法规体系 |
|
|
368
|
+
| `samr` | 市场监管法律法规规章数据库 | JSON | title, content | 类型(可多选), status, 公布/施行日期 |
|
|
369
|
+
| `miit` | 工业和信息化部政策法规 | JSON | title, content, all, 文号 | 公布日期, newest;文件类型、部门、主题 |
|
|
370
|
+
| `nfra` | 国家金融监督管理总局 | JSON | title, content, all | 公布日期, newest/oldest;栏目、机构、相对时间 |
|
|
371
|
+
| `cac` | 国家互联网信息办公室 | HTML 高级检索 + JSON 法规栏目 | title, content, all | 连续短语, 排除词, 顶层栏目, 公布日期, newest/oldest;法规七分类全量枚举 |
|
|
372
|
+
| `mod` | 国防部法规文献 | JSON + 官网动态凭据 | title, content, author | exact;标准/模糊/二次检索 |
|
|
373
|
+
| `sse` | 上海证券交易所规则 | JSONP | title, content, all | exact, 公布日期, newest |
|
|
374
|
+
| `szse` | 深圳证券交易所规则 | JSON | title, content, all | exact, newest |
|
|
375
|
+
| `bse` | 北京证券交易所规则 | JSONP | all | 公布日期, newest |
|
|
376
|
+
| `neeq` | 全国股转系统规则 | JSONP | all | 公布日期, newest |
|
|
377
|
+
|
|
378
|
+
其中最高法、国防部官网的检索接口是全站索引,结果会保留官网返回的栏目分类;它们不应被误解为只包含司法解释或军事法规。最高检站内搜索跳转至第三方开普云服务,当前直连稳定性不足,因此 `spp` 使用最高检官方四类静态栏目全量分页并在本地执行标题匹配;不会把第三方服务宣称为最高检公开 API。网信办、司法部、最高法、最高检等 HTML 来源通常比 JSON 来源更容易受页面结构和 WAF 变化影响。
|
|
379
|
+
|
|
380
|
+
## 已知限制与在线巡检
|
|
381
|
+
|
|
382
|
+
自动化测试用于固定请求和解析契约,不能替代官网在线状态。历史巡检覆盖加入最高检之前的 18 个非 NPC 来源;最高检已于 2026-07-25 单独完成官方栏目全分页与详情在线验证。下一次全来源巡检将覆盖 19 个非 NPC 来源。此前详情严格校验中有 14 个完整通过,以下 4 个存在官网侧或文件形态限制:
|
|
383
|
+
|
|
384
|
+
- 证监会详情接口偶发超时或返回 504。
|
|
385
|
+
- 工信部部分官方详情页返回站点配置错误。
|
|
386
|
+
- 市场监管总局部分文件只提供 PDF/DOCX 附件,结构化接口中的 `content` 为 `null`。
|
|
387
|
+
- 上交所部分完整规则正文只通过官方 DOCX 附件提供。
|
|
388
|
+
|
|
389
|
+
因此,调用 `info` 后应检查 `body_availability`、`body_note` 和 `attachments`,不能只凭 HTTP 成功就认定已取得全文。官网接口、WAF 和页面结构可能随时变化;具体研究任务仍应核对 `official_url` 指向的官方页面。
|
|
390
|
+
|
|
391
|
+
## 数据保留规则
|
|
392
|
+
|
|
393
|
+
- 不设置默认条数、页数或摘要长度。
|
|
394
|
+
- 不静默去重。工信部搜索返回相似结果分组时,会逐条保留每个组成员;最高检同一文件出现在多个官方栏目时,也逐条保留并标记栏目。
|
|
395
|
+
- 不根据标题自行推定文件效力。仅在官网明确提供效力状态时设置 `validity_explicit=true`。
|
|
396
|
+
- 不把 Cookie、动态接口凭据或令牌写入源码、输出和清单。
|
|
397
|
+
- 国家规章库与国防部需要的官网前端鉴权值在运行时读取,只在内存中使用。
|
|
398
|
+
- 对官网硬性分页限制或异常字段采用显式适配,并在维护档案中记录证据和处理方式。
|
|
399
|
+
|
|
400
|
+
## 隐私与网络行为
|
|
401
|
+
|
|
402
|
+
- 安装包不包含维护者或用户的浏览器 Cookie、访问令牌、API Key、个人 IP 地址或本机路径。
|
|
403
|
+
- CLI 没有中心服务器、账户系统或遥测上报;检索请求由用户本机直接发往所选官方来源。
|
|
404
|
+
- 与任何网络访问一样,目标官网会看到请求出口的公网 IP;如果配置代理,则通常看到代理出口 IP。
|
|
405
|
+
- 少数官网会在请求过程中下发临时 Cookie 或动态鉴权值。适配器只在当前 HTTP 客户端内存中使用,不写入源码、输出、清单或持久化缓存。
|
|
406
|
+
- NPC 原始公开文件默认缓存在 `~/.cache/cnlaw/documents`;可用 `--no-cache` 禁用,或用 `cnlaw cache clear` 显式清理。
|
|
407
|
+
|
|
408
|
+
## 故障排查
|
|
409
|
+
|
|
410
|
+
- 先运行 `cnlaw --version`、`cnlaw sources`、`cnlaw capabilities <source>` 和 `cnlaw parameters <source>`,确认版本、来源代码和支持参数。
|
|
411
|
+
- PyPI 已发布但本地版本较旧时,运行 `uv tool upgrade law-cn-cli`,再用 `cnlaw --version` 核对。
|
|
412
|
+
- 官网超时、WAF 拦截或 HTML 结构变化时,CLI 会返回非零退出码。不要把失败当成“没有检索结果”,可稍后重试并核对官方页面。
|
|
413
|
+
- 搜索默认不设条数或页数上限;只有显式传入 `--limit` 才截断,输出清单会记录截断状态。
|
|
414
|
+
|
|
415
|
+
## 开发与验证
|
|
416
|
+
|
|
417
|
+
```bash
|
|
418
|
+
.venv/bin/python -m pytest
|
|
419
|
+
.venv/bin/python -m pytest --cov=cnlaw --cov-report=term-missing
|
|
420
|
+
uv build
|
|
421
|
+
uvx twine check dist/*
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
维护仓库中的来源研究档案记录官网入口、检索端点、分页字段、支持能力、验证日期及稳定性说明,但不会打入面向用户的 wheel/sdist。
|
|
425
|
+
|
|
426
|
+
## 许可证
|
|
427
|
+
|
|
428
|
+
本项目采用 [PolyForm Noncommercial License 1.0.0](https://polyformproject.org/licenses/noncommercial/1.0.0),SPDX 标识为 `PolyForm-Noncommercial-1.0.0`。
|
|
429
|
+
|
|
430
|
+
允许个人研究、学习、测试以及该许可证列明的非商业组织使用;不授权商业使用。企业内部使用、商业产品或服务集成、收费服务等商业用途应事先另行取得商业授权。完整法律条款以随安装包分发的 [`LICENSE`](LICENSE) 为准。
|