nexusos-gate 1.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.
- nexusos_gate-1.2.0/LICENSE +21 -0
- nexusos_gate-1.2.0/PKG-INFO +124 -0
- nexusos_gate-1.2.0/README.md +101 -0
- nexusos_gate-1.2.0/pyproject.toml +50 -0
- nexusos_gate-1.2.0/setup.cfg +4 -0
- nexusos_gate-1.2.0/src/nexusos_gate/__init__.py +25 -0
- nexusos_gate-1.2.0/src/nexusos_gate/doc_symbol_refs.py +236 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/__init__.py +0 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/checks/__init__.py +0 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/checks/examples/README.md +44 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/checks/examples/__init__.py +0 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/checks/examples/config_key_refs.yaml +19 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/checks/examples/doc_consistency.yaml +15 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/checks/examples/e2e-paths.yaml +26 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/checks/examples/persist_pool_ledger.yaml +14 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/__init__.py +0 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/__init__.py +0 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/_gitcmd.py +53 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/_vault_root.py +31 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/_workspace_root.py +55 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/adversarial_review.py +70 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/branch_merged_main.py +63 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/codegraph_wrapper.py +277 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/command.py +40 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/comment_out_detection.py +94 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/commit_file_cap.py +27 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/complexity_aware.py +114 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/concurrency_declared.py +76 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/config_key_refs.py +344 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/deletion_mentioned.py +88 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/doc_consistency.py +257 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/done_ack.py +79 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/external_change_traced.py +69 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/field_check.py +28 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/file_exists.py +54 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/file_size.py +132 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/files_exist.py +175 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/git_diff_scope.py +114 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/grep_in_diff.py +142 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/line_count.py +90 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/md_updated_today.py +114 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/outcome_backfill.py +57 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/pool_rows_flipped.py +152 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/pool_write_via_wrapper.py +38 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/session_log_selfcheck.py +46 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/step_completeness.py +130 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/test_readme_synced_p4.py +118 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/tests/conftest.py +30 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/tests/test_2611111773_g1_annotation.py +124 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/tests/test_2611172040_g1_candidate_retry.py +101 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/tests/test_2611172043_b3_gate_semantics.py +209 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/tests/test_2611172046_b5_inline_strip.py +69 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/tests/test_2611172047_b7_window.py +90 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/tests/test_adversarial_review.py +107 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/tests/test_concurrency_declared.py +46 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/tests/test_files_exist.py +170 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/tests/test_git_diff_parsers.py +140 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/tests/test_oss_checks.py +201 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/tests/test_verification_evidence.py +177 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/verification_evidence.py +293 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/verification_evidence_anchor.py +115 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/verification_level_marked.py +62 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/workspace_residue.py +114 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/_checks/worktree_contract.py +51 -0
- nexusos_gate-1.2.0/src/nexusos_gate/etc/gates/launchd_registry_verify.py +58 -0
- nexusos_gate-1.2.0/src/nexusos_gate/gate_engine.py +925 -0
- nexusos_gate-1.2.0/src/nexusos_gate/persist_pool_ledger.py +241 -0
- nexusos_gate-1.2.0/src/nexusos_gate/pool_write_channel.py +201 -0
- nexusos_gate-1.2.0/src/nexusos_gate/predone.py +218 -0
- nexusos_gate-1.2.0/src/nexusos_gate/scripts/staged_tests_grouped.py +81 -0
- nexusos_gate-1.2.0/src/nexusos_gate.egg-info/PKG-INFO +124 -0
- nexusos_gate-1.2.0/src/nexusos_gate.egg-info/SOURCES.txt +74 -0
- nexusos_gate-1.2.0/src/nexusos_gate.egg-info/dependency_links.txt +1 -0
- nexusos_gate-1.2.0/src/nexusos_gate.egg-info/entry_points.txt +6 -0
- nexusos_gate-1.2.0/src/nexusos_gate.egg-info/requires.txt +2 -0
- nexusos_gate-1.2.0/src/nexusos_gate.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wangyong
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nexusos-gate
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: nexusos-gate — NEXUS declarative quality-gate engine (scenario YAML + pluggable check pool)
|
|
5
|
+
Author: NEXUS Contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/wangshuyongyhm/nexusos-gate
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: pyyaml>=5.4
|
|
21
|
+
Requires-Dist: nexusos-common<2,>=1.0
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
title: NEXUS Gate 引擎
|
|
26
|
+
description: 声明式门禁:场景YAML+checks插件池
|
|
27
|
+
updated: 2026-11-27
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
# nexusos-gate
|
|
31
|
+
|
|
32
|
+
**NEXUS Gate — 声明式门禁引擎(场景 YAML + checks 插件池)**
|
|
33
|
+
|
|
34
|
+
在多 Agent 体系里,"规则存在 ≠ 规则执行"。nexusos-gate 把「执行关键动作前该检查什么」从自觉变成强制:Agent 在关键动作前调用 `gate_check`,引擎按场景 YAML 定义跑检查插件池,返回 REJECT(硬拦)/ WARN(软警告)分级结果。
|
|
35
|
+
|
|
36
|
+
## 核心特性
|
|
37
|
+
|
|
38
|
+
- **声明式场景定义**:每个门禁场景一个 YAML(示例见随包的 etc/checks/examples/),含 required_context 校验 + 检查项列表
|
|
39
|
+
- **插件池自动发现**:`etc/gates/_checks/` 下 46 个检查插件按文件名自动装载,覆盖对抗式审查、README 同步、MEM 查询留痕、验证证据等维度
|
|
40
|
+
- **分级语义**:REJECT(产出缺失,硬拦截)/ WARN(附属质量,记录后放行)
|
|
41
|
+
- **CLI + Python API 双入口**:脚本可 `python3 -m nexusos_gate.gate_engine <scenario> <json> [--agent <name>]`(CLI 落流身份,见下),代码可 `from nexusos_gate import gate_check`
|
|
42
|
+
- **Fail-open 告警写 PG**:psycopg2 为可选依赖,缺失时门禁仍可用,仅失去告警落库能力
|
|
43
|
+
|
|
44
|
+
## 安装
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# 发布至 PyPI 前:本地路径安装(仓库根目录执行;三包目录并列时同命令安装三件套)
|
|
48
|
+
pip install ./nexusos-gate
|
|
49
|
+
pip install ./nexusos-gate ./nexusos-mem ./nexusos-xdr # 三件套一条命令(1597 干净 venv 实证口径)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
要求 Python >= 3.10。运行时唯一硬依赖是 `pyyaml>=5.4`。
|
|
53
|
+
|
|
54
|
+
PyPI 发布后可用 `pip install nexusos-gate`(当前包未发布,请勿直接照抄该命令)。
|
|
55
|
+
|
|
56
|
+
本包**没有** `[full]` extras(extras 是 nexusos-mem 的 BGE 向量能力,见 nexusos-mem README)。
|
|
57
|
+
|
|
58
|
+
## 快速上手
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from nexusos_gate import gate_check
|
|
62
|
+
|
|
63
|
+
result = gate_check(scenario="minimal", context={
|
|
64
|
+
"report_path": "output/report.md",
|
|
65
|
+
})
|
|
66
|
+
# result = {"passed": bool, "failures": [...], "hard_fails": [...], "warns": [...]}
|
|
67
|
+
if not result["passed"]:
|
|
68
|
+
... # 补齐 REJECT 项后重过;WARN 项记录继续
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
安装后导入首验(1597 实证命令):
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
python -c "import nexusos_gate; print('ok')"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
CLI 方式(shell / pre-commit hook 适用):
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
NEXUS_GATES_DIR=$(python3 -c 'import nexusos_gate,os;print(os.path.join(os.path.dirname(nexusos_gate.__file__),"etc/checks/examples"))') \
|
|
81
|
+
python3 -m nexusos_gate.gate_engine doc_consistency '{}' --agent your-agent
|
|
82
|
+
|
|
83
|
+
# 身份落流:CLI 直跑时用 --agent / NEXUS_AGENT 指明真实 Agent 名(2611172047 B6)
|
|
84
|
+
# 优先级:显式 NEXUS_AGENT > --agent <name> > 兜底 "cli"(cli 未注册→事件不落流但判定不变)
|
|
85
|
+
NEXUS_AGENT=zcode python3 -m nexusos_gate.gate_engine state_transition '{"from_state":"S4","to_state":"S5","session_id":"s1"}'
|
|
86
|
+
python3 -m nexusos_gate.gate_engine state_transition '{"from_state":"S4","to_state":"S5","session_id":"s1"}' --agent zcode
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
环境变量(常用):
|
|
90
|
+
|
|
91
|
+
| 变量 | 默认值 | 作用 |
|
|
92
|
+
|------|--------|------|
|
|
93
|
+
| `NEXUS_GATES_DIR` | (无,必需时显式指定) | 场景 YAML 目录(随包的 etc/checks/examples/ 可作模板) |
|
|
94
|
+
| `NEXUS_VAULT_ROOT` | env > 包位置哨兵推导 > 空串 | Vault 根目录(vault 类检查插件用,干净环境可缺省) |
|
|
95
|
+
| `NEXUS_AGENT` | (无 → 兜底 `cli`) | CLI 落流身份(写成真实 Agent 名才写进事件流/参与 GATE_GRACE 配对);优先级 显式 env > `--agent` > `cli`(2611172047 B6) |
|
|
96
|
+
|
|
97
|
+
## 通用示例场景(examples/)
|
|
98
|
+
|
|
99
|
+
包内不绑定任何具体业务流程——随包的 `etc/checks/examples/` 提供 4 个通用示例(`config_key_refs` / `doc_consistency` / `e2e-paths` / `persist_pool_ledger`),用 `NEXUS_GATES_DIR` 指向安装目录下的该路径即可运行。写你自己的门禁 = 在任意目录加一个场景 YAML(场景名 + required_context + 检查项),可选地往 `_checks/` 放检查插件(引擎自动发现),无需改引擎代码:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
export NEXUS_GATES_DIR=/path/to/your/gates # 场景目录(随包的 etc/checks/examples/ 可作模板)
|
|
103
|
+
gate_check(scenario="your_scenario", context={...})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## 依赖分层
|
|
107
|
+
|
|
108
|
+
| 层 | 内容 |
|
|
109
|
+
|----|------|
|
|
110
|
+
| 硬依赖 | `pyyaml>=5.4`(gate_engine 顶部 import,缺失即退出) |
|
|
111
|
+
| 可选依赖 | `psycopg2-binary`(仅检查插件告警写 PostgreSQL 用,fail-open) |
|
|
112
|
+
| 包结构 | `gate_engine.py` 调度核心 + `_checks/` 通用插件池(场景 YAML 不随包,examples/ 提供模板) |
|
|
113
|
+
|
|
114
|
+
## 与另两件的关系
|
|
115
|
+
|
|
116
|
+
nexusos-gate 是三件套中**最独立**的一个:只依赖 pyyaml,可单独 pip 安装使用。nexusos-xdr 在 dispatch/callback 等关键链路上调用本包做门禁校验;nexusos-mem 与本包无直接依赖(仅检查插件可选地查询 MEM 知识库留痕)。
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
MIT License。详见仓库根目录 [LICENSE](./LICENSE)。
|
|
121
|
+
|
|
122
|
+
## 2026-11-19 变更(2611190910 / task 2611191111)
|
|
123
|
+
|
|
124
|
+
- **CLI 身份链第四档**:`显式 NEXUS_AGENT > --agent > context.agent(新增)> cli 兜底`——裸调(无 env/flag)时若 context JSON 带 agent 字段则以其落流,gate 事件不再因 'cli' 未注册而丢失。仅在兜底档生效,不改变既有三态优先级。
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: NEXUS Gate 引擎
|
|
3
|
+
description: 声明式门禁:场景YAML+checks插件池
|
|
4
|
+
updated: 2026-11-27
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# nexusos-gate
|
|
8
|
+
|
|
9
|
+
**NEXUS Gate — 声明式门禁引擎(场景 YAML + checks 插件池)**
|
|
10
|
+
|
|
11
|
+
在多 Agent 体系里,"规则存在 ≠ 规则执行"。nexusos-gate 把「执行关键动作前该检查什么」从自觉变成强制:Agent 在关键动作前调用 `gate_check`,引擎按场景 YAML 定义跑检查插件池,返回 REJECT(硬拦)/ WARN(软警告)分级结果。
|
|
12
|
+
|
|
13
|
+
## 核心特性
|
|
14
|
+
|
|
15
|
+
- **声明式场景定义**:每个门禁场景一个 YAML(示例见随包的 etc/checks/examples/),含 required_context 校验 + 检查项列表
|
|
16
|
+
- **插件池自动发现**:`etc/gates/_checks/` 下 46 个检查插件按文件名自动装载,覆盖对抗式审查、README 同步、MEM 查询留痕、验证证据等维度
|
|
17
|
+
- **分级语义**:REJECT(产出缺失,硬拦截)/ WARN(附属质量,记录后放行)
|
|
18
|
+
- **CLI + Python API 双入口**:脚本可 `python3 -m nexusos_gate.gate_engine <scenario> <json> [--agent <name>]`(CLI 落流身份,见下),代码可 `from nexusos_gate import gate_check`
|
|
19
|
+
- **Fail-open 告警写 PG**:psycopg2 为可选依赖,缺失时门禁仍可用,仅失去告警落库能力
|
|
20
|
+
|
|
21
|
+
## 安装
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# 发布至 PyPI 前:本地路径安装(仓库根目录执行;三包目录并列时同命令安装三件套)
|
|
25
|
+
pip install ./nexusos-gate
|
|
26
|
+
pip install ./nexusos-gate ./nexusos-mem ./nexusos-xdr # 三件套一条命令(1597 干净 venv 实证口径)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
要求 Python >= 3.10。运行时唯一硬依赖是 `pyyaml>=5.4`。
|
|
30
|
+
|
|
31
|
+
PyPI 发布后可用 `pip install nexusos-gate`(当前包未发布,请勿直接照抄该命令)。
|
|
32
|
+
|
|
33
|
+
本包**没有** `[full]` extras(extras 是 nexusos-mem 的 BGE 向量能力,见 nexusos-mem README)。
|
|
34
|
+
|
|
35
|
+
## 快速上手
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from nexusos_gate import gate_check
|
|
39
|
+
|
|
40
|
+
result = gate_check(scenario="minimal", context={
|
|
41
|
+
"report_path": "output/report.md",
|
|
42
|
+
})
|
|
43
|
+
# result = {"passed": bool, "failures": [...], "hard_fails": [...], "warns": [...]}
|
|
44
|
+
if not result["passed"]:
|
|
45
|
+
... # 补齐 REJECT 项后重过;WARN 项记录继续
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
安装后导入首验(1597 实证命令):
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
python -c "import nexusos_gate; print('ok')"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
CLI 方式(shell / pre-commit hook 适用):
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
NEXUS_GATES_DIR=$(python3 -c 'import nexusos_gate,os;print(os.path.join(os.path.dirname(nexusos_gate.__file__),"etc/checks/examples"))') \
|
|
58
|
+
python3 -m nexusos_gate.gate_engine doc_consistency '{}' --agent your-agent
|
|
59
|
+
|
|
60
|
+
# 身份落流:CLI 直跑时用 --agent / NEXUS_AGENT 指明真实 Agent 名(2611172047 B6)
|
|
61
|
+
# 优先级:显式 NEXUS_AGENT > --agent <name> > 兜底 "cli"(cli 未注册→事件不落流但判定不变)
|
|
62
|
+
NEXUS_AGENT=zcode python3 -m nexusos_gate.gate_engine state_transition '{"from_state":"S4","to_state":"S5","session_id":"s1"}'
|
|
63
|
+
python3 -m nexusos_gate.gate_engine state_transition '{"from_state":"S4","to_state":"S5","session_id":"s1"}' --agent zcode
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
环境变量(常用):
|
|
67
|
+
|
|
68
|
+
| 变量 | 默认值 | 作用 |
|
|
69
|
+
|------|--------|------|
|
|
70
|
+
| `NEXUS_GATES_DIR` | (无,必需时显式指定) | 场景 YAML 目录(随包的 etc/checks/examples/ 可作模板) |
|
|
71
|
+
| `NEXUS_VAULT_ROOT` | env > 包位置哨兵推导 > 空串 | Vault 根目录(vault 类检查插件用,干净环境可缺省) |
|
|
72
|
+
| `NEXUS_AGENT` | (无 → 兜底 `cli`) | CLI 落流身份(写成真实 Agent 名才写进事件流/参与 GATE_GRACE 配对);优先级 显式 env > `--agent` > `cli`(2611172047 B6) |
|
|
73
|
+
|
|
74
|
+
## 通用示例场景(examples/)
|
|
75
|
+
|
|
76
|
+
包内不绑定任何具体业务流程——随包的 `etc/checks/examples/` 提供 4 个通用示例(`config_key_refs` / `doc_consistency` / `e2e-paths` / `persist_pool_ledger`),用 `NEXUS_GATES_DIR` 指向安装目录下的该路径即可运行。写你自己的门禁 = 在任意目录加一个场景 YAML(场景名 + required_context + 检查项),可选地往 `_checks/` 放检查插件(引擎自动发现),无需改引擎代码:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
export NEXUS_GATES_DIR=/path/to/your/gates # 场景目录(随包的 etc/checks/examples/ 可作模板)
|
|
80
|
+
gate_check(scenario="your_scenario", context={...})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 依赖分层
|
|
84
|
+
|
|
85
|
+
| 层 | 内容 |
|
|
86
|
+
|----|------|
|
|
87
|
+
| 硬依赖 | `pyyaml>=5.4`(gate_engine 顶部 import,缺失即退出) |
|
|
88
|
+
| 可选依赖 | `psycopg2-binary`(仅检查插件告警写 PostgreSQL 用,fail-open) |
|
|
89
|
+
| 包结构 | `gate_engine.py` 调度核心 + `_checks/` 通用插件池(场景 YAML 不随包,examples/ 提供模板) |
|
|
90
|
+
|
|
91
|
+
## 与另两件的关系
|
|
92
|
+
|
|
93
|
+
nexusos-gate 是三件套中**最独立**的一个:只依赖 pyyaml,可单独 pip 安装使用。nexusos-xdr 在 dispatch/callback 等关键链路上调用本包做门禁校验;nexusos-mem 与本包无直接依赖(仅检查插件可选地查询 MEM 知识库留痕)。
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT License。详见仓库根目录 [LICENSE](./LICENSE)。
|
|
98
|
+
|
|
99
|
+
## 2026-11-19 变更(2611190910 / task 2611191111)
|
|
100
|
+
|
|
101
|
+
- **CLI 身份链第四档**:`显式 NEXUS_AGENT > --agent > context.agent(新增)> cli 兜底`——裸调(无 env/flag)时若 context JSON 带 agent 字段则以其落流,gate 事件不再因 'cli' 未注册而丢失。仅在兜底档生效,不改变既有三态优先级。
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "nexusos-gate"
|
|
7
|
+
version = "1.2.0"
|
|
8
|
+
description = "nexusos-gate — NEXUS declarative quality-gate engine (scenario YAML + pluggable check pool)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
# PEP 621 旧式 text 表(非 SPDX 表达式)——保留 License classifier 不被新版
|
|
12
|
+
# setuptools(≥77, PEP639) 拒绝:license="MIT" 字符串形态会与 classifier 冲突致
|
|
13
|
+
# 干净 venv 安装失败(1609 实测 InvalidConfigError)。
|
|
14
|
+
license = {text = "MIT"}
|
|
15
|
+
authors = [{name = "NEXUS Contributors"}]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Operating System :: MacOS",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
]
|
|
27
|
+
# 池#72 定调"gate/xdr 零重依赖"。pyyaml 是 gate_engine 顶部硬依赖
|
|
28
|
+
# (缺失即 sys.exit),如实声明(Task630 决策,详见 report);psycopg2
|
|
29
|
+
# 仅插件告警写 PG 用、fail-open 可选,不进运行时依赖。
|
|
30
|
+
dependencies = ["pyyaml>=5.4", "nexusos-common>=1.0,<2"] # 1957 锚点单源(design §3.2 钉 <2)
|
|
31
|
+
|
|
32
|
+
# nexusos.gate.checks 插件协议(1959 单3,design §5):entry_points 组注入,
|
|
33
|
+
# 外部包可同协议注册 check;engine 端 sorted(name) 稳定序加载。
|
|
34
|
+
# 首批=原五私人 check(插件化×2/示例化×2/剥离×1 改造后的 OSS 化形态)。
|
|
35
|
+
[project.entry-points."nexusos.gate.checks"]
|
|
36
|
+
config_key_refs = "nexusos_gate.etc.gates._checks.config_key_refs"
|
|
37
|
+
codegraph_wrapper = "nexusos_gate.etc.gates._checks.codegraph_wrapper"
|
|
38
|
+
complexity_aware = "nexusos_gate.etc.gates._checks.complexity_aware"
|
|
39
|
+
doc_consistency = "nexusos_gate.etc.gates._checks.doc_consistency"
|
|
40
|
+
persist_pool_ledger = "nexusos_gate.persist_pool_ledger"
|
|
41
|
+
|
|
42
|
+
# 开源仓库落位(M1 脱敏建仓)后更新为真实主页;切片器不再补注(单一真源)
|
|
43
|
+
[project.urls]
|
|
44
|
+
Homepage = "https://github.com/wangshuyongyhm/nexusos-gate"
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.packages.find]
|
|
47
|
+
where = ["src"]
|
|
48
|
+
|
|
49
|
+
[tool.setuptools.package-data]
|
|
50
|
+
"nexusos_gate.etc.checks.examples" = ["*.yaml", "*.md"]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""nexusos-gate — NEXUS 声明式门禁引擎(Task630 三件套首包)。
|
|
4
|
+
|
|
5
|
+
组成:
|
|
6
|
+
- gate_engine: 场景 YAML 加载 + required_context 校验 + checks 插件分发
|
|
7
|
+
- etc/gates/*.yaml: 场景定义(done/init/dispatch/persist/code/...)
|
|
8
|
+
- etc/gates/_checks/*.py: 检查插件池(启动时按文件名自动发现)
|
|
9
|
+
|
|
10
|
+
依赖: 仅 pyyaml(硬依赖)。psycopg2 为可选(插件告警写 PG, fail-open)。
|
|
11
|
+
|
|
12
|
+
旧路径兼容: nexusos_xdr.gate_engine / etc.gates._checks.* 经
|
|
13
|
+
nexusos_xdr/ 下的 re-export shim + symlink 继续可用(零破坏)。
|
|
14
|
+
"""
|
|
15
|
+
__version__ = "1.2.0"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def gate_check(scenario: str, context: dict, agent: str = "") -> dict:
|
|
19
|
+
"""过场景门禁(便捷导出,写法对齐 nexusos_xdr.gate_check)。
|
|
20
|
+
|
|
21
|
+
延迟 import(函数内)——避免 `import nexusos_gate` 触发插件池全量扫描。
|
|
22
|
+
返回 {passed, failures, hard_fails, warns}。
|
|
23
|
+
"""
|
|
24
|
+
from nexusos_gate.gate_engine import check
|
|
25
|
+
return check(scenario, context, agent=agent)
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""doc_symbol_refs.py — Task448 L3 核心:文档符号引用扫描。
|
|
4
|
+
|
|
5
|
+
封装 obsidian-cli + ripgrep 正则,提供三类文档符号的反向引用查询:
|
|
6
|
+
- wikilink 引用([[target_doc]])
|
|
7
|
+
- 章节锚点引用(§2.6 / §核心禁令)
|
|
8
|
+
- MEM# 编号引用
|
|
9
|
+
|
|
10
|
+
设计原则:
|
|
11
|
+
- obsidian-cli 主路径,rg fallback(obsidian 不可用或粒度不够时)
|
|
12
|
+
- 全部 fail-open,工具异常不抛
|
|
13
|
+
- 路径参数化(从 __file__ 推导 vault_dir,不硬编码绝对路径)
|
|
14
|
+
"""
|
|
15
|
+
import json
|
|
16
|
+
import os
|
|
17
|
+
import re
|
|
18
|
+
import shutil
|
|
19
|
+
import subprocess
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import Optional
|
|
22
|
+
|
|
23
|
+
# Vault 根(1410 移到包根后重数 6 层上溯):
|
|
24
|
+
# nexusos_gate→src→nexusos-gate→pypi→自动化脚本→05-System→Vault 根
|
|
25
|
+
_DEFAULT_VAULT_DIR = str(Path(__file__).resolve().parents[6])
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _obsidian_cli_disabled() -> bool:
|
|
29
|
+
"""停用开关文件存在时视为没有 obsidian 命令(CLI 桥会挂死不返回,改走 rg 兜底)。"""
|
|
30
|
+
raw = (os.environ.get("NEXUS_OBSIDIAN_CLI_SWITCH") or "").strip()
|
|
31
|
+
switch = Path(raw).expanduser() if raw else Path.home() / ".nexus/xdr/obsidian-cli.disabled"
|
|
32
|
+
return switch.exists()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _run_cmd(cmd: list, cwd: Optional[str] = None, timeout: int = 15) -> tuple:
|
|
36
|
+
"""运行命令,返回 (rc, stdout, stderr)。失败返 (-1, '', '')。"""
|
|
37
|
+
try:
|
|
38
|
+
r = subprocess.run(
|
|
39
|
+
cmd, capture_output=True, text=True,
|
|
40
|
+
timeout=timeout, check=False, cwd=cwd,
|
|
41
|
+
)
|
|
42
|
+
return r.returncode, r.stdout, r.stderr
|
|
43
|
+
except (subprocess.TimeoutExpired, FileNotFoundError, OSError):
|
|
44
|
+
return -1, "", ""
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _rg_search(pattern: str, vault_dir: str, file_glob: str = "*.md") -> list:
|
|
48
|
+
"""ripgrep 递归搜索,返回 [{"file":, "line":, "text":}, ...]。"""
|
|
49
|
+
if not shutil.which("rg"):
|
|
50
|
+
return []
|
|
51
|
+
rc, out, _ = _run_cmd(
|
|
52
|
+
["rg", "-n", "--with-filename", "--no-heading", "-t", "markdown", pattern, vault_dir],
|
|
53
|
+
timeout=30,
|
|
54
|
+
)
|
|
55
|
+
if rc != 0:
|
|
56
|
+
return []
|
|
57
|
+
results = []
|
|
58
|
+
for line in out.splitlines():
|
|
59
|
+
# rg -n --with-filename 输出格式:path:line:text
|
|
60
|
+
m = re.match(r"^(.+?):(\d+):(.*)$", line)
|
|
61
|
+
if m:
|
|
62
|
+
results.append({"file": m.group(1), "line": int(m.group(2)), "text": m.group(3)})
|
|
63
|
+
return results
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def scan_wikilink_refs(target_doc: str, vault_dir: Optional[str] = None) -> list:
|
|
67
|
+
"""查 target_doc 被哪些文件的 wikilink 引用。
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
target_doc: 文档名(不带 .md,如 "init" 或 "init.md")
|
|
71
|
+
vault_dir: Vault 根目录
|
|
72
|
+
Returns:
|
|
73
|
+
[{"source_file":..., "link_text":..., "line":...}, ...]
|
|
74
|
+
obsidian-cli 优先,自动用 rg 补 line/link_text;不可用则 rg 全局兜底
|
|
75
|
+
"""
|
|
76
|
+
vd = vault_dir or _DEFAULT_VAULT_DIR
|
|
77
|
+
# 规整 target:去掉 .md 后缀(obsidian backlinks file= 用裸名)
|
|
78
|
+
target_bare = target_doc[:-3] if target_doc.endswith(".md") else target_doc
|
|
79
|
+
|
|
80
|
+
source_files = []
|
|
81
|
+
# obsidian_bin = shutil.which("obsidian")
|
|
82
|
+
obsidian_bin = None if _obsidian_cli_disabled() else shutil.which("obsidian")
|
|
83
|
+
if obsidian_bin:
|
|
84
|
+
rc, out, _ = _run_cmd(
|
|
85
|
+
[obsidian_bin, "backlinks", f"file={target_bare}", "format=json"],
|
|
86
|
+
cwd=vd, timeout=15,
|
|
87
|
+
)
|
|
88
|
+
if rc == 0 and out.strip():
|
|
89
|
+
try:
|
|
90
|
+
data = json.loads(out)
|
|
91
|
+
if isinstance(data, list):
|
|
92
|
+
source_files = [item.get("file", "") for item in data if isinstance(item, dict)]
|
|
93
|
+
except json.JSONDecodeError:
|
|
94
|
+
pass
|
|
95
|
+
|
|
96
|
+
# 对每个 source_file 用 rg 补 line + link_text(obsidian backlinks 只给 file)
|
|
97
|
+
results = []
|
|
98
|
+
if source_files:
|
|
99
|
+
# 构造 wikilink 匹配:[[target_bare]] / [[target_bare.md]] / [[target_bare|...]] / [[target_bare#...]]
|
|
100
|
+
# 接受可选 .md 后缀(用户写 [[init.md|init]] 也算引用 init)
|
|
101
|
+
link_pattern = (
|
|
102
|
+
r"\[\[" + re.escape(target_bare) + r"(\.md)?(\|[^\]]*)?(#[^\]]*)?\]\]"
|
|
103
|
+
)
|
|
104
|
+
for sf in source_files:
|
|
105
|
+
if not sf:
|
|
106
|
+
continue
|
|
107
|
+
sf_path = Path(vd) / (sf if sf.endswith(".md") else f"{sf}.md")
|
|
108
|
+
if not sf_path.exists():
|
|
109
|
+
# 可能是路径形式(folder/note)
|
|
110
|
+
sf_path = Path(vd) / sf
|
|
111
|
+
if not sf_path.exists():
|
|
112
|
+
results.append({"source_file": sf, "link_text": f"[[{target_bare}]]", "line": -1})
|
|
113
|
+
continue
|
|
114
|
+
rc, out, _ = _run_cmd(
|
|
115
|
+
["rg", "-n", "--with-filename", "--no-heading", link_pattern, str(sf_path)],
|
|
116
|
+
timeout=10,
|
|
117
|
+
)
|
|
118
|
+
if rc == 0 and out.strip():
|
|
119
|
+
for line in out.splitlines()[:5]: # 每文件最多 5 个引用
|
|
120
|
+
m = re.match(r"^(.+?):(\d+):(.*)$", line)
|
|
121
|
+
if m:
|
|
122
|
+
# 提匹配到的 wikilink 文本
|
|
123
|
+
link_match = re.search(link_pattern, m.group(3))
|
|
124
|
+
link_text = link_match.group(0) if link_match else f"[[{target_bare}]]"
|
|
125
|
+
results.append({
|
|
126
|
+
"source_file": sf,
|
|
127
|
+
"link_text": link_text,
|
|
128
|
+
"line": int(m.group(2)),
|
|
129
|
+
})
|
|
130
|
+
else:
|
|
131
|
+
results.append({"source_file": sf, "link_text": f"[[{target_bare}]]", "line": -1})
|
|
132
|
+
return results
|
|
133
|
+
|
|
134
|
+
# Fallback: obsidian 不可用,全局 rg
|
|
135
|
+
link_pattern = (
|
|
136
|
+
r"\[\[" + re.escape(target_bare) + r"(\.md)?(\|[^\]]*)?(#[^\]]*)?\]\]"
|
|
137
|
+
)
|
|
138
|
+
raw = _rg_search(link_pattern, vd)
|
|
139
|
+
for r in raw:
|
|
140
|
+
rel = str(Path(r["file"]).relative_to(vd)) if r["file"].startswith(vd) else r["file"]
|
|
141
|
+
link_match = re.search(link_pattern, r["text"])
|
|
142
|
+
results.append({
|
|
143
|
+
"source_file": rel,
|
|
144
|
+
"link_text": link_match.group(0) if link_match else f"[[{target_bare}]]",
|
|
145
|
+
"line": r["line"],
|
|
146
|
+
})
|
|
147
|
+
return results
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def scan_section_refs(section_anchor: str, scope_files: Optional[list] = None, vault_dir: Optional[str] = None) -> list:
|
|
151
|
+
"""查 §section_anchor(如 "§2.6" 或 "§核心禁令")被哪些文件引用。
|
|
152
|
+
|
|
153
|
+
Args:
|
|
154
|
+
section_anchor: 含 § 前缀("§2.6")或不含("2.6"),都接受
|
|
155
|
+
scope_files: 限定扫描的文件清单(相对 vault 路径),None=全 vault
|
|
156
|
+
vault_dir: Vault 根目录
|
|
157
|
+
Returns:
|
|
158
|
+
[{"file":, "line":, "text":}, ...]
|
|
159
|
+
"""
|
|
160
|
+
vd = vault_dir or _DEFAULT_VAULT_DIR
|
|
161
|
+
anchor = section_anchor.lstrip("§").strip()
|
|
162
|
+
# 匹配 §2.6 / § 2.6 / §核心禁令
|
|
163
|
+
pattern = r"§\s*" + re.escape(anchor)
|
|
164
|
+
results = []
|
|
165
|
+
if scope_files:
|
|
166
|
+
for sf in scope_files:
|
|
167
|
+
sf_path = Path(vd) / sf if not Path(sf).is_absolute() else Path(sf)
|
|
168
|
+
if not sf_path.exists():
|
|
169
|
+
continue
|
|
170
|
+
rc, out, _ = _run_cmd(["rg", "-n", "--no-heading", pattern, str(sf_path)], timeout=10)
|
|
171
|
+
if rc == 0:
|
|
172
|
+
for line in out.splitlines():
|
|
173
|
+
m = re.match(r"^(.+?):(\d+):(.*)$", line)
|
|
174
|
+
if m:
|
|
175
|
+
results.append({"file": sf, "line": int(m.group(2)), "text": m.group(3)})
|
|
176
|
+
else:
|
|
177
|
+
raw = _rg_search(pattern, vd)
|
|
178
|
+
for r in raw:
|
|
179
|
+
rel = str(Path(r["file"]).relative_to(vd)) if r["file"].startswith(vd) else r["file"]
|
|
180
|
+
results.append({"file": rel, "line": r["line"], "text": r["text"]})
|
|
181
|
+
return results
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def scan_mem_refs(mem_id: str, vault_dir: Optional[str] = None) -> list:
|
|
185
|
+
"""查 MEM#xxxx 编号被哪些文件引用。
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
mem_id: 数字 ID("38940")或 "MEM#38940" 形式
|
|
189
|
+
Returns:
|
|
190
|
+
[{"file":, "line":, "text":, "mem_id":}, ...]
|
|
191
|
+
"""
|
|
192
|
+
vd = vault_dir or _DEFAULT_VAULT_DIR
|
|
193
|
+
mid = mem_id.replace("MEM#", "").replace("#", "").strip()
|
|
194
|
+
if not mid.isdigit():
|
|
195
|
+
return []
|
|
196
|
+
pattern = r"MEM#" + mid + r"\b"
|
|
197
|
+
raw = _rg_search(pattern, vd)
|
|
198
|
+
results = []
|
|
199
|
+
for r in raw:
|
|
200
|
+
rel = str(Path(r["file"]).relative_to(vd)) if r["file"].startswith(vd) else r["file"]
|
|
201
|
+
results.append({"file": rel, "line": r["line"], "text": r["text"], "mem_id": int(mid)})
|
|
202
|
+
return results
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def scan_unresolved_links(vault_dir: Optional[str] = None, limit: int = 50) -> list:
|
|
206
|
+
"""查 Vault 断链(unresolved wikilinks),调 obsidian unresolved。
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
[{"link": "..."}, ...] 断链目标清单(前 limit 个)
|
|
210
|
+
"""
|
|
211
|
+
vd = vault_dir or _DEFAULT_VAULT_DIR
|
|
212
|
+
# obsidian_bin = shutil.which("obsidian")
|
|
213
|
+
obsidian_bin = None if _obsidian_cli_disabled() else shutil.which("obsidian")
|
|
214
|
+
if not obsidian_bin:
|
|
215
|
+
return []
|
|
216
|
+
rc, out, _ = _run_cmd(
|
|
217
|
+
[obsidian_bin, "unresolved", "format=json"],
|
|
218
|
+
cwd=vd, timeout=30,
|
|
219
|
+
)
|
|
220
|
+
if rc != 0 or not out.strip():
|
|
221
|
+
return []
|
|
222
|
+
try:
|
|
223
|
+
data = json.loads(out)
|
|
224
|
+
if isinstance(data, list):
|
|
225
|
+
return data[:limit]
|
|
226
|
+
except json.JSONDecodeError:
|
|
227
|
+
pass
|
|
228
|
+
return []
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
if __name__ == "__main__":
|
|
232
|
+
import sys
|
|
233
|
+
target = sys.argv[1] if len(sys.argv) > 1 else "init"
|
|
234
|
+
print(f"=== wikilink refs to '{target}' ===")
|
|
235
|
+
for r in scan_wikilink_refs(target)[:10]:
|
|
236
|
+
print(f" {r['source_file']}:{r['line']} {r['link_text']}")
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# nexusos.gate.checks · 自定义 check 接入指南(1959 单3,design §5)
|
|
2
|
+
|
|
3
|
+
nexusos-gate 的 check 注册分三层,按需组合:
|
|
4
|
+
|
|
5
|
+
| 层 | 位置 | 适用 |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| 包内声明(内置) | `etc/gates/_checks/*.py` + 场景 yaml `type:` 引用 | 通用检查(command/file_exists/...) |
|
|
8
|
+
| 用户声明式启用 | `$NEXUS_HOME/gate/checks.d/*.yaml` | 把 check(含内置/插件)以自定义参数挂进场景 |
|
|
9
|
+
| entry_points 协议 | 包 pyproject `[project.entry-points."nexusos.gate.checks"]` | 外部包注入新 check(sorted(name) 稳定序) |
|
|
10
|
+
|
|
11
|
+
## 挂一个 check 进场景(checks.d)
|
|
12
|
+
|
|
13
|
+
```yaml
|
|
14
|
+
# $NEXUS_HOME/gate/checks.d/<任意名>.yaml
|
|
15
|
+
scenario: code # 追加到哪个场景(init/dispatch/persist/done/code)
|
|
16
|
+
items:
|
|
17
|
+
- id: MY1
|
|
18
|
+
name: 我的检查
|
|
19
|
+
auto: true
|
|
20
|
+
severity: WARN # WARN / REJECT
|
|
21
|
+
check:
|
|
22
|
+
type: config_key_refs # 任意已注册 check 类型名
|
|
23
|
+
scope: ["/abs/your/config/dir"] # 该 check 支持的参数
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
items 结构与场景 yaml 内置项完全同构(追加不改内置)。
|
|
27
|
+
|
|
28
|
+
## 本目录示例
|
|
29
|
+
|
|
30
|
+
- `e2e-paths.yaml` — e2e_suite_evidence 的用户配置样本(放 `$NEXUS_HOME/gate/e2e-paths.yaml`,支持 `${NEXUS_VAULT_ROOT}`/`${NEXUS_HOME}` 占位;无配置=该 check WARN skip)
|
|
31
|
+
- `config_key_refs.yaml` — 扫描目标声明样本(私配置不随包,示例用占位路径)
|
|
32
|
+
- `persist_pool_ledger.yaml` — 取号脚本路径参数化样本(env `NEXUS_POOL_NEXT_ID_SCRIPT` 同效)
|
|
33
|
+
- `doc_consistency.yaml` — 文档一致性检查目标样本
|
|
34
|
+
|
|
35
|
+
## 外部包注入 check(entry_points)
|
|
36
|
+
|
|
37
|
+
在你的包 pyproject 里:
|
|
38
|
+
|
|
39
|
+
```toml
|
|
40
|
+
[project.entry-points."nexusos.gate.checks"]
|
|
41
|
+
my_check = "my_pkg.gate_checks:my_check_fn" # 模块或 "mod:attr",须可调用 check(params, context, agent) -> (bool, str)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
安装后 `nexus gate` 引擎自动发现(与内置五 check 同协议同待遇)。
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# config_key_refs.yaml 样本 — 扫描目标声明式启用(1959 插件化)
|
|
2
|
+
#
|
|
3
|
+
# 部署位:$NEXUS_HOME/gate/checks.d/config_key_refs.yaml(示例参数,按需改)
|
|
4
|
+
# 语义:dispatch 前配置键关联检查(代码改了漏挂 config 防护)——扫描范围
|
|
5
|
+
# 全部显式声明;无 scope 且无 NEXUS_AGENT_CFG_DIRS env 且 vault 不可得
|
|
6
|
+
# = WARN skip(不扫别人机器的私人配置目录)。
|
|
7
|
+
scenario: dispatch
|
|
8
|
+
items:
|
|
9
|
+
- id: D7C
|
|
10
|
+
name: 配置键关联(私配置声明式启用)
|
|
11
|
+
auto: true
|
|
12
|
+
severity: WARN
|
|
13
|
+
check:
|
|
14
|
+
type: config_key_refs
|
|
15
|
+
max_uncovered: 0
|
|
16
|
+
# 扫描范围:你的配置文件/目录(绝对路径;也可用 env NEXUS_AGENT_CFG_DIRS 冒号分隔清单)
|
|
17
|
+
scope:
|
|
18
|
+
- ${NEXUS_VAULT_ROOT}/your/configs/
|
|
19
|
+
- ${NEXUS_HOME}/providers.json
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# doc_consistency.yaml 样本 — 文档一致性检查目标声明(1959 示例化配套)
|
|
2
|
+
#
|
|
3
|
+
# 部署位:$NEXUS_HOME/gate/checks.d/doc_consistency.yaml(可选——C9 已内置
|
|
4
|
+
# 于 code 场景,本样本演示如何对你的文档目录单独启用/调参)
|
|
5
|
+
# 语义:改 md 时验证文中引用的路径/脚本实际存在(fail-soft WARN)。
|
|
6
|
+
scenario: code
|
|
7
|
+
items:
|
|
8
|
+
- id: C9X
|
|
9
|
+
name: 文档一致性(自定义目标)
|
|
10
|
+
auto: true
|
|
11
|
+
severity: WARN
|
|
12
|
+
check:
|
|
13
|
+
type: doc_consistency
|
|
14
|
+
files: "{changed_files}"
|
|
15
|
+
project_root: "{project_root}"
|