nexusos-gate 1.2.0__py3-none-any.whl
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/__init__.py +25 -0
- nexusos_gate/doc_symbol_refs.py +236 -0
- nexusos_gate/etc/__init__.py +0 -0
- nexusos_gate/etc/checks/__init__.py +0 -0
- nexusos_gate/etc/checks/examples/README.md +44 -0
- nexusos_gate/etc/checks/examples/__init__.py +0 -0
- nexusos_gate/etc/checks/examples/config_key_refs.yaml +19 -0
- nexusos_gate/etc/checks/examples/doc_consistency.yaml +15 -0
- nexusos_gate/etc/checks/examples/e2e-paths.yaml +26 -0
- nexusos_gate/etc/checks/examples/persist_pool_ledger.yaml +14 -0
- nexusos_gate/etc/gates/__init__.py +0 -0
- nexusos_gate/etc/gates/_checks/__init__.py +0 -0
- nexusos_gate/etc/gates/_checks/_gitcmd.py +53 -0
- nexusos_gate/etc/gates/_checks/_vault_root.py +31 -0
- nexusos_gate/etc/gates/_checks/_workspace_root.py +55 -0
- nexusos_gate/etc/gates/_checks/adversarial_review.py +70 -0
- nexusos_gate/etc/gates/_checks/branch_merged_main.py +63 -0
- nexusos_gate/etc/gates/_checks/codegraph_wrapper.py +277 -0
- nexusos_gate/etc/gates/_checks/command.py +40 -0
- nexusos_gate/etc/gates/_checks/comment_out_detection.py +94 -0
- nexusos_gate/etc/gates/_checks/commit_file_cap.py +27 -0
- nexusos_gate/etc/gates/_checks/complexity_aware.py +114 -0
- nexusos_gate/etc/gates/_checks/concurrency_declared.py +76 -0
- nexusos_gate/etc/gates/_checks/config_key_refs.py +344 -0
- nexusos_gate/etc/gates/_checks/deletion_mentioned.py +88 -0
- nexusos_gate/etc/gates/_checks/doc_consistency.py +257 -0
- nexusos_gate/etc/gates/_checks/done_ack.py +79 -0
- nexusos_gate/etc/gates/_checks/external_change_traced.py +69 -0
- nexusos_gate/etc/gates/_checks/field_check.py +28 -0
- nexusos_gate/etc/gates/_checks/file_exists.py +54 -0
- nexusos_gate/etc/gates/_checks/file_size.py +132 -0
- nexusos_gate/etc/gates/_checks/files_exist.py +175 -0
- nexusos_gate/etc/gates/_checks/git_diff_scope.py +114 -0
- nexusos_gate/etc/gates/_checks/grep_in_diff.py +142 -0
- nexusos_gate/etc/gates/_checks/line_count.py +90 -0
- nexusos_gate/etc/gates/_checks/md_updated_today.py +114 -0
- nexusos_gate/etc/gates/_checks/outcome_backfill.py +57 -0
- nexusos_gate/etc/gates/_checks/pool_rows_flipped.py +152 -0
- nexusos_gate/etc/gates/_checks/pool_write_via_wrapper.py +38 -0
- nexusos_gate/etc/gates/_checks/session_log_selfcheck.py +46 -0
- nexusos_gate/etc/gates/_checks/step_completeness.py +130 -0
- nexusos_gate/etc/gates/_checks/test_readme_synced_p4.py +118 -0
- nexusos_gate/etc/gates/_checks/tests/conftest.py +30 -0
- nexusos_gate/etc/gates/_checks/tests/test_2611111773_g1_annotation.py +124 -0
- nexusos_gate/etc/gates/_checks/tests/test_2611172040_g1_candidate_retry.py +101 -0
- nexusos_gate/etc/gates/_checks/tests/test_2611172043_b3_gate_semantics.py +209 -0
- nexusos_gate/etc/gates/_checks/tests/test_2611172046_b5_inline_strip.py +69 -0
- nexusos_gate/etc/gates/_checks/tests/test_2611172047_b7_window.py +90 -0
- nexusos_gate/etc/gates/_checks/tests/test_adversarial_review.py +107 -0
- nexusos_gate/etc/gates/_checks/tests/test_concurrency_declared.py +46 -0
- nexusos_gate/etc/gates/_checks/tests/test_files_exist.py +170 -0
- nexusos_gate/etc/gates/_checks/tests/test_git_diff_parsers.py +140 -0
- nexusos_gate/etc/gates/_checks/tests/test_oss_checks.py +201 -0
- nexusos_gate/etc/gates/_checks/tests/test_verification_evidence.py +177 -0
- nexusos_gate/etc/gates/_checks/verification_evidence.py +293 -0
- nexusos_gate/etc/gates/_checks/verification_evidence_anchor.py +115 -0
- nexusos_gate/etc/gates/_checks/verification_level_marked.py +62 -0
- nexusos_gate/etc/gates/_checks/workspace_residue.py +114 -0
- nexusos_gate/etc/gates/_checks/worktree_contract.py +51 -0
- nexusos_gate/etc/gates/launchd_registry_verify.py +58 -0
- nexusos_gate/gate_engine.py +925 -0
- nexusos_gate/persist_pool_ledger.py +241 -0
- nexusos_gate/pool_write_channel.py +201 -0
- nexusos_gate/predone.py +218 -0
- nexusos_gate/scripts/staged_tests_grouped.py +81 -0
- nexusos_gate-1.2.0.dist-info/METADATA +124 -0
- nexusos_gate-1.2.0.dist-info/RECORD +71 -0
- nexusos_gate-1.2.0.dist-info/WHEEL +5 -0
- nexusos_gate-1.2.0.dist-info/entry_points.txt +6 -0
- nexusos_gate-1.2.0.dist-info/licenses/LICENSE +21 -0
- nexusos_gate-1.2.0.dist-info/top_level.txt +1 -0
nexusos_gate/__init__.py
ADDED
|
@@ -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}"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# e2e-paths.yaml 样本 — e2e_suite_evidence(G18)用户配置
|
|
2
|
+
#
|
|
3
|
+
# 部署位:$NEXUS_HOME/gate/e2e-paths.yaml(或 env NEXUS_GATE_E2E_PATHS 直指本文件)
|
|
4
|
+
# 语义:改动面命中 system_path_patterns 任一 = 系统改动单 → done 前须跑 e2e
|
|
5
|
+
# 套件并留证据;无本配置 = 该 check WARN skip(不 REJECT)。
|
|
6
|
+
# 占位:${NEXUS_VAULT_ROOT}/${NEXUS_HOME} 读取时展开(vault 不可得则该值
|
|
7
|
+
# 留原样——建议相对口径就不需要占位)。
|
|
8
|
+
version: 1
|
|
9
|
+
|
|
10
|
+
# e2e 套件入口(vault/workspace 相对或 ${NEXUS_VAULT_ROOT} 绝对)
|
|
11
|
+
suite_entry: ${NEXUS_VAULT_ROOT}/your/e2e-suite/run-suite.sh
|
|
12
|
+
|
|
13
|
+
# 系统改动路径模式(fnmatch 语义,* 跨 / 匹配)——按你的系统面改
|
|
14
|
+
system_path_patterns:
|
|
15
|
+
- your/system/pypi/**
|
|
16
|
+
- your/core/scripts/*.sh
|
|
17
|
+
|
|
18
|
+
# 只读复测/零改动反信号——任务书明示 → 豁免
|
|
19
|
+
read_only_markers:
|
|
20
|
+
- 只读复测
|
|
21
|
+
- 零改动
|
|
22
|
+
|
|
23
|
+
# 任务书侧系统路径字样(第二信号兜底)
|
|
24
|
+
task_md_system_markers:
|
|
25
|
+
- pypi/
|
|
26
|
+
- e2e-suite
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# persist_pool_ledger.yaml 样本 — 台账 check 声明式启用(1959 示例化)
|
|
2
|
+
#
|
|
3
|
+
# 部署位:$NEXUS_HOME/gate/checks.d/persist_pool_ledger.yaml
|
|
4
|
+
# 语义:WARN 台账健康检查(事实型恒 pass;vault/取号脚本不可得 = WARN skip)。
|
|
5
|
+
# 取号脚本默认按 vault 布局组合路径解析;他机自定义脚本用 env
|
|
6
|
+
# NEXUS_POOL_NEXT_ID_SCRIPT(支持 ${NEXUS_VAULT_ROOT}/${NEXUS_HOME} 占位)。
|
|
7
|
+
scenario: persist
|
|
8
|
+
items:
|
|
9
|
+
- id: P8
|
|
10
|
+
name: 池台账健康
|
|
11
|
+
auto: true
|
|
12
|
+
severity: WARN
|
|
13
|
+
check:
|
|
14
|
+
type: persist_pool_ledger
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""_gitcmd.py — git 调用共享层(Task1552 S2,1545 审查发现的 quotePath 家族缺陷收口)。
|
|
2
|
+
|
|
3
|
+
不做插件(下划线前缀被 gate_engine 加载器跳过,同 _vaultlink 先例),纯函数库:
|
|
4
|
+
run_git(args, cwd, timeout) -> (rc, stdout, stderr)
|
|
5
|
+
diff_b_path(plus_line) -> str — 解析 diff `+++ b/...` 头的单一真源
|
|
6
|
+
|
|
7
|
+
单一真源约定:凡 gate 检查器调 git diff 输出做路径解析,必须经本模块——
|
|
8
|
+
`-c core.quotePath=false` 统一在此注入(1545 实证:默认转义让中文路径带
|
|
9
|
+
引号+八进制,grep 后缀/前缀匹配全失配——C1 误拦 REJECT、C14/C15 漏检)。
|
|
10
|
+
"""
|
|
11
|
+
import subprocess
|
|
12
|
+
|
|
13
|
+
# 超时默认与各插件原值一致(15-20s 量级)
|
|
14
|
+
_DEFAULT_TIMEOUT = 20
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def run_git(args: list, cwd=None, timeout: int = _DEFAULT_TIMEOUT) -> tuple:
|
|
18
|
+
"""跑 git(恒带 -c core.quotePath=false,拿 UTF-8 原始路径)。
|
|
19
|
+
|
|
20
|
+
返回 (rc, stdout, stderr)。异常映射与各插件旧私有实现一致:
|
|
21
|
+
TimeoutExpired→124 / FileNotFoundError→127 / 其他→1。
|
|
22
|
+
"""
|
|
23
|
+
cmd = ["git", "-c", "core.quotePath=false"] + list(args)
|
|
24
|
+
try:
|
|
25
|
+
r = subprocess.run(
|
|
26
|
+
cmd,
|
|
27
|
+
cwd=cwd or None,
|
|
28
|
+
capture_output=True,
|
|
29
|
+
text=True,
|
|
30
|
+
timeout=timeout,
|
|
31
|
+
)
|
|
32
|
+
return r.returncode, r.stdout or "", r.stderr or ""
|
|
33
|
+
except subprocess.TimeoutExpired:
|
|
34
|
+
return 124, "", "git timeout"
|
|
35
|
+
except FileNotFoundError:
|
|
36
|
+
return 127, "", "git not found"
|
|
37
|
+
except Exception as e:
|
|
38
|
+
return 1, "", f"{type(e).__name__}: {e}"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def diff_b_path(plus_line: str) -> str:
|
|
42
|
+
"""解析 diff 文件头(`+++ b/path` 或 `+++ "b/path"`)→ 仓库相对路径。
|
|
43
|
+
|
|
44
|
+
S1 根修(1545):原 comment_out_detection 用 lstrip("b/")(字符集语义)——
|
|
45
|
+
引号形态剥不动致 b/ 前缀残留、b 开头文件名被啃。git 的引号包裹整个 "b/path"
|
|
46
|
+
(含 b/),故顺序必须是:先剥包裹引号,再 removeprefix("b/")——1545 复审
|
|
47
|
+
实证反序时引号形态的 b/ 残留(S1 同款复发,1552 单测首跑抓回)。
|
|
48
|
+
/dev/null 返回原样(调用方自判)。
|
|
49
|
+
"""
|
|
50
|
+
s = plus_line.strip()
|
|
51
|
+
if len(s) >= 2 and s.startswith('"') and s.endswith('"'):
|
|
52
|
+
s = s[1:-1]
|
|
53
|
+
return s.removeprefix("b/")
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""_vault_root — gate 插件的 vault 根参数化助手(Task1597 顺手项)。
|
|
3
|
+
|
|
4
|
+
为什么存在:此前 6+ 处插件把 vault 根硬编码成本机绝对路径
|
|
5
|
+
作缺省——换机器/开源用户拿到包后这些路径指向别人的盘,检查要么静默
|
|
6
|
+
跑错目录要么报出莫名路径。参数化铁律(PARAMETERIZATION-GUIDE):env
|
|
7
|
+
优先,仓内可相对推导(沿 parents 找含 05-System 的目录=vault 根),
|
|
8
|
+
仓外(wheel 装到陌生环境)返回空串让调用方自然报"文件不存在",
|
|
9
|
+
而不是指向一台不存在的机器。
|
|
10
|
+
|
|
11
|
+
插件加载形态兼容(同 _gitcmd/_vaultlink 先例):
|
|
12
|
+
try: import _vault_root
|
|
13
|
+
except ImportError: from . import _vault_root
|
|
14
|
+
"""
|
|
15
|
+
import os
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from nexusos_common import auto_scripts_dir
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def vault_root() -> str:
|
|
22
|
+
"""vault 根解析:NEXUS_ROOT env > 哨兵推导(nexusos-common 单源,1957)。
|
|
23
|
+
|
|
24
|
+
空串不是错误值——下游 file_exists 等检查拿它拼路径会得到不存在的
|
|
25
|
+
路径,按原逻辑报「文件不存在」,这比指向别人机器的假路径诚实。
|
|
26
|
+
"""
|
|
27
|
+
env = os.environ.get("NEXUS_ROOT")
|
|
28
|
+
if env:
|
|
29
|
+
return env
|
|
30
|
+
auto_dir = auto_scripts_dir(Path(__file__))
|
|
31
|
+
return str(auto_dir.parents[1]) if auto_dir is not None else ""
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""_workspace_root — 工作区根发现策略(1959 单3,design §5 codegraph 行)。
|
|
3
|
+
|
|
4
|
+
为什么存在:codegraph_wrapper/complexity_aware 原用 parents[7] 包位置推导
|
|
5
|
+
工作区根——安装形状假设(pip 装到陌生环境必错目录,audit §1 行13)。
|
|
6
|
+
本助手把发现策略接口化为显式链,杀 parents[N]:
|
|
7
|
+
|
|
8
|
+
explicit 参数 > env NEXUS_CODEGRAPH_PROJECT(直指项目根)
|
|
9
|
+
> env NEXUS_ROOT(vault 布局:优先 {vault}/05-System/自动化脚本
|
|
10
|
+
的 .codegraph 私人深链探测,退 {vault} 本身——均在 .codegraph 存在
|
|
11
|
+
才认)> git repo root(从 start 向上找 .git)> None
|
|
12
|
+
|
|
13
|
+
插件加载形态兼容(同 _gitcmd/_vaultlink 先例):
|
|
14
|
+
try: import _workspace_root
|
|
15
|
+
except ImportError: from . import _workspace_root
|
|
16
|
+
"""
|
|
17
|
+
import os
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _has_codegraph(root: Path) -> bool:
|
|
22
|
+
return (root / ".codegraph").is_dir()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _vault_candidate(vault: str) -> Path | None:
|
|
26
|
+
"""vault 布局下的项目根探测:私人深链(自动化脚本/.codegraph)优先,
|
|
27
|
+
退 vault 根自身;两者都无 .codegraph → None(不认)。"""
|
|
28
|
+
v = Path(vault)
|
|
29
|
+
deep = v / "05-System" / "自动化脚本"
|
|
30
|
+
if _has_codegraph(deep):
|
|
31
|
+
return deep
|
|
32
|
+
if _has_codegraph(v):
|
|
33
|
+
return v
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def resolve_workspace_root(explicit: str | None = None, start: Path | None = None) -> Path | None:
|
|
38
|
+
"""工作区根发现(显式链见模块 docstring)。返回 None=不可得(调用方 fail-open)。"""
|
|
39
|
+
if explicit:
|
|
40
|
+
p = Path(explicit).expanduser()
|
|
41
|
+
return p if p.is_dir() else None
|
|
42
|
+
env_direct = os.environ.get("NEXUS_CODEGRAPH_PROJECT", "").strip()
|
|
43
|
+
if env_direct:
|
|
44
|
+
p = Path(env_direct).expanduser()
|
|
45
|
+
return p if p.is_dir() else None
|
|
46
|
+
env_vault = os.environ.get("NEXUS_ROOT", "").strip()
|
|
47
|
+
if env_vault:
|
|
48
|
+
cand = _vault_candidate(env_vault)
|
|
49
|
+
if cand is not None:
|
|
50
|
+
return cand
|
|
51
|
+
d = (start or Path.cwd()).resolve()
|
|
52
|
+
for p in (d, *d.parents):
|
|
53
|
+
if (p / ".git").exists():
|
|
54
|
+
return p
|
|
55
|
+
return None
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""检查类型: adversarial_review — 对抗式审查(C13 用, WARN)。
|
|
2
|
+
|
|
3
|
+
thinking-methodology.md §2 的代码强制层:代码改动时提醒做过对抗式审查
|
|
4
|
+
(红队思维:找反例/漏洞/边界)。
|
|
5
|
+
|
|
6
|
+
4 条证据路径(任一满足即 pass,全不满足 → False 但 severity WARN 软提醒):
|
|
7
|
+
1. 非代码豁免: changed_files 无代码扩展名 → pass(复用 verification_evidence._has_no_code)
|
|
8
|
+
2. commit_msg 标记: 含 [adversarial:...] → pass
|
|
9
|
+
3. verify 文件含对抗式关键词: verify_*.md / adversarial-review.md 内容含"对抗式/反例/边界/失败/逆向"
|
|
10
|
+
4. test 陪跑: changed_files 含 test_*.py / *_test.py(逆向思维产物)
|
|
11
|
+
"""
|
|
12
|
+
import os
|
|
13
|
+
import re
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
from verification_evidence import _has_no_code, _coerce_files
|
|
17
|
+
except ImportError:
|
|
18
|
+
from .verification_evidence import _has_no_code, _coerce_files
|
|
19
|
+
|
|
20
|
+
_ADVERSARIAL_MSG = re.compile(r'\[adversarial:.*?\]', re.IGNORECASE)
|
|
21
|
+
_VERIFY_KEYWORDS = ('对抗式', '反例', '边界', '失败', '逆向', 'adversarial', 'edge case')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def check(params: dict, context: dict, agent: str) -> tuple:
|
|
25
|
+
"""
|
|
26
|
+
params: (无, 全从 context 取)
|
|
27
|
+
context:
|
|
28
|
+
changed_files: 改动文件列表
|
|
29
|
+
commit_msg: 提交信息
|
|
30
|
+
project_root: 项目根(读 verify 文件用)
|
|
31
|
+
返回: (passed, detail)
|
|
32
|
+
"""
|
|
33
|
+
changed = _coerce_files(context.get("changed_files"), context)
|
|
34
|
+
if not changed:
|
|
35
|
+
return True, "无改动,跳过"
|
|
36
|
+
|
|
37
|
+
# 路径1: 非代码豁免
|
|
38
|
+
if _has_no_code(changed):
|
|
39
|
+
return True, "非代码改动,豁免"
|
|
40
|
+
|
|
41
|
+
# 路径2: commit_msg 标记
|
|
42
|
+
msg = context.get("commit_msg", "") or ""
|
|
43
|
+
if _ADVERSARIAL_MSG.search(msg):
|
|
44
|
+
return True, "commit_msg 含对抗式审查标记"
|
|
45
|
+
|
|
46
|
+
# 路径3: verify 文件含对抗式关键词
|
|
47
|
+
project_root = context.get("project_root", "") or ""
|
|
48
|
+
for f in changed:
|
|
49
|
+
base = os.path.basename(f).lower()
|
|
50
|
+
if base.startswith("verify_") or base.startswith("adversarial") or base.endswith("_verify.md"):
|
|
51
|
+
full = os.path.join(project_root, f) if project_root else f
|
|
52
|
+
try:
|
|
53
|
+
content = open(full, encoding='utf-8').read().lower()
|
|
54
|
+
if any(k in content for k in _VERIFY_KEYWORDS):
|
|
55
|
+
return True, f"verify 文件 {base} 含对抗式审查内容"
|
|
56
|
+
except Exception:
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
# 路径4: test 陪跑
|
|
60
|
+
for f in changed:
|
|
61
|
+
base = os.path.basename(f).lower()
|
|
62
|
+
if base.startswith("test_") or base.endswith("_test.py"):
|
|
63
|
+
return True, "有 test 陪跑(逆向思维产物)"
|
|
64
|
+
|
|
65
|
+
# 全不满足
|
|
66
|
+
return False, (
|
|
67
|
+
"未发现对抗式审查证据。"
|
|
68
|
+
"建议: commit_msg 加 [adversarial:反例1,反例2] 或附 adversarial-review.md 或补 test。"
|
|
69
|
+
"详见 thinking-methodology.md §2"
|
|
70
|
+
)
|