memgate 0.0.0-stage → 0.1.1
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.
- package/LICENSE +12 -0
- package/README.md +52 -2
- package/VERSIONS.json +17 -0
- package/dist/index.js +726 -0
- package/index.ts +25 -0
- package/openclaw.plugin.json +53 -0
- package/package.json +37 -3
- package/src/admission.py +208 -0
- package/src/bridge.ts +205 -0
- package/src/bridge_cli.py +600 -0
- package/src/context-engine.ts +373 -0
- package/src/hebbian_link.py +34 -0
- package/src/kernel/activity_telemetry.py +51 -0
- package/src/kernel/admission.py +208 -0
- package/src/kernel/calldecay/__init__.py +24 -0
- package/src/kernel/calldecay/__main__.py +7 -0
- package/src/kernel/calldecay/_kernel.py +32 -0
- package/src/kernel/calldecay/adapter.py +126 -0
- package/src/kernel/calldecay/cli.py +80 -0
- package/src/kernel/calldecay/gate.py +93 -0
- package/src/kernel/calldecay/landing.py +1298 -0
- package/src/kernel/calldecay/metrics.py +37 -0
- package/src/kernel/calldecay/mock.py +68 -0
- package/src/kernel/calldecay/pipeline.py +85 -0
- package/src/kernel/calldecay/proxy.py +220 -0
- package/src/kernel/calldecay/summarize.py +401 -0
- package/src/kernel/core/LICENSE +228 -0
- package/src/kernel/core/__init__.py +0 -0
- package/src/kernel/core/accept_contract.py +67 -0
- package/src/kernel/core/chain_probe_world.py +133 -0
- package/src/kernel/core/concept_ontology.py +2401 -0
- package/src/kernel/core/concept_opposition.py +291 -0
- package/src/kernel/core/concept_phase.py +1342 -0
- package/src/kernel/core/concept_principle.py +2481 -0
- package/src/kernel/core/concept_pyramid.py +287 -0
- package/src/kernel/core/concept_space.py +45 -0
- package/src/kernel/core/concept_space_mixin.py +941 -0
- package/src/kernel/core/concept_state.py +2748 -0
- package/src/kernel/core/decision_symbolic.py +245 -0
- package/src/kernel/core/eco_math_world.py +489 -0
- package/src/kernel/core/emergence.py +362 -0
- package/src/kernel/core/events.py +93 -0
- package/src/kernel/core/hebbian.py +117 -0
- package/src/kernel/core/llm_arm.py +551 -0
- package/src/kernel/core/memory_shadow.py +158 -0
- package/src/kernel/core/mes_layer_base.py +309 -0
- package/src/kernel/core/mes_vnext.py +540 -0
- package/src/kernel/core/ontology_core.py +168 -0
- package/src/kernel/core/phase_field.py +187 -0
- package/src/kernel/core/reasoning.py +185 -0
- package/src/kernel/core/rhythm_vnext.py +777 -0
- package/src/kernel/dashboard_render.py +196 -0
- package/src/kernel/depscan_probe.py +96 -0
- package/src/kernel/health_probe.py +186 -0
- package/src/kernel/hebbian_link.py +34 -0
- package/src/kernel/knowledge_distiller/README.md +9 -0
- package/src/kernel/knowledge_distiller/__init__.py +1 -0
- package/src/kernel/knowledge_distiller/knowledge_distiller.py +196 -0
- package/src/kernel/m3_judge.py +215 -0
- package/src/kernel/mechanism_advisor.py +203 -0
- package/src/kernel/mechanism_learner.py +193 -0
- package/src/kernel/memory_core.py +81 -0
- package/src/kernel/quality_gate/README.md +9 -0
- package/src/kernel/quality_gate/__init__.py +1 -0
- package/src/kernel/quality_gate/quality_gate.py +7 -0
- package/src/kernel/registry_gate.py +57 -0
- package/src/kernel/semantic_recall.py +635 -0
- package/src/kernel/tiered_decay/README.md +9 -0
- package/src/kernel/tiered_decay/__init__.py +1 -0
- package/src/kernel/tiered_decay/tiered_decay.py +17 -0
- package/src/kernel/tokenizer/README.md +9 -0
- package/src/kernel/tokenizer/__init__.py +2 -0
- package/src/kernel/tokenizer/tokenizer.py +14 -0
- package/src/kernel/version_binding.py +131 -0
- package/src/knowledge_distiller.py +196 -0
- package/src/m3_collector.py +247 -0
- package/src/m3_judge.py +215 -0
- package/src/memory-capability.ts +44 -0
- package/src/semantic_recall.py +635 -0
- package/src/thinking_stub.ts +141 -0
- package/src/toolface_hook.ts +69 -0
- package/src/tools.ts +98 -0
- package/src/vendor/calldecay-sdk/calldecay/__init__.py +24 -0
- package/src/vendor/calldecay-sdk/calldecay/__main__.py +7 -0
- package/src/vendor/calldecay-sdk/calldecay/_kernel.py +32 -0
- package/src/vendor/calldecay-sdk/calldecay/adapter.py +126 -0
- package/src/vendor/calldecay-sdk/calldecay/cli.py +80 -0
- package/src/vendor/calldecay-sdk/calldecay/gate.py +93 -0
- package/src/vendor/calldecay-sdk/calldecay/landing.py +1298 -0
- package/src/vendor/calldecay-sdk/calldecay/metrics.py +37 -0
- package/src/vendor/calldecay-sdk/calldecay/mock.py +68 -0
- package/src/vendor/calldecay-sdk/calldecay/pipeline.py +85 -0
- package/src/vendor/calldecay-sdk/calldecay/proxy.py +220 -0
- package/src/vendor/calldecay-sdk/calldecay/summarize.py +401 -0
- package/src/vendor/core/LICENSE +228 -0
- package/src/vendor/core/__init__.py +0 -0
- package/src/vendor/core/accept_contract.py +67 -0
- package/src/vendor/core/chain_probe_world.py +133 -0
- package/src/vendor/core/concept_ontology.py +2401 -0
- package/src/vendor/core/concept_opposition.py +291 -0
- package/src/vendor/core/concept_phase.py +1342 -0
- package/src/vendor/core/concept_principle.py +2481 -0
- package/src/vendor/core/concept_pyramid.py +287 -0
- package/src/vendor/core/concept_space.py +45 -0
- package/src/vendor/core/concept_space_mixin.py +941 -0
- package/src/vendor/core/concept_state.py +2748 -0
- package/src/vendor/core/decision_symbolic.py +245 -0
- package/src/vendor/core/eco_math_world.py +489 -0
- package/src/vendor/core/emergence.py +362 -0
- package/src/vendor/core/events.py +93 -0
- package/src/vendor/core/hebbian.py +117 -0
- package/src/vendor/core/llm_arm.py +551 -0
- package/src/vendor/core/memory_shadow.py +158 -0
- package/src/vendor/core/mes_layer_base.py +309 -0
- package/src/vendor/core/mes_vnext.py +540 -0
- package/src/vendor/core/ontology_core.py +168 -0
- package/src/vendor/core/phase_field.py +187 -0
- package/src/vendor/core/reasoning.py +185 -0
- package/src/vendor/core/rhythm_vnext.py +777 -0
- package/src/vendor/pvs-sdk/pvs/__init__.py +0 -0
- package/src/vendor/pvs-sdk/pvs/adapters/__init__.py +0 -0
- package/src/vendor/pvs-sdk/pvs/adapters/llm_backends.py +69 -0
- package/src/vendor/pvs-sdk/pvs/core/__init__.py +0 -0
- package/src/vendor/pvs-sdk/pvs/core/budget.py +84 -0
- package/src/vendor/pvs-sdk/pvs/core/llm_gate.py +149 -0
- package/src/vendor/pvs-sdk/pvs/core/memory.py +143 -0
- package/src/vendor/pvs-sdk/pvs/core/pvs.py +175 -0
- package/src/vendor/pvs-sdk/pvs/core/verifier.py +77 -0
- package/src/vendor/pvs-sdk/pvs/eval/__init__.py +3 -0
- package/src/vendor/pvs-sdk/pvs/eval/coverage.py +82 -0
- package/src/vendor/pvs-sdk/pvs/gate/__init__.py +5 -0
- package/src/vendor/pvs-sdk/pvs/gate/__main__.py +3 -0
- package/src/vendor/pvs-sdk/pvs/gate/boot.py +68 -0
- package/src/vendor/pvs-sdk/pvs/gate/ledger.py +157 -0
- package/src/vendor/pvs-sdk/pvs/gate/preflight.py +342 -0
- package/src/vendor/pvs-sdk/pvs/harness/__init__.py +0 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""pvs.gate.preflight —— 开工前断言检查器 (2026-11-02 波次31 交付A)。
|
|
3
|
+
|
|
4
|
+
把台账每条教训转成可执行断言, 开工前跑一遍:
|
|
5
|
+
|
|
6
|
+
python3 -m pvs.gate preflight # 全部断言
|
|
7
|
+
python3 -m pvs.gate preflight --report <报单.md> # 带报单对账 (L08)
|
|
8
|
+
python3 -m pvs.gate preflight --json # 机器可读 (报告集成)
|
|
9
|
+
python3 -m pvs.gate preflight --strict # DECL(人工确认项) 未确认也算 FAIL
|
|
10
|
+
|
|
11
|
+
断言类型:
|
|
12
|
+
auto = 本机自动扫描 (进程/脚本/快照锚定/台账完整性/报单对账)
|
|
13
|
+
decl = 需人工确认的行为项; 输出确认口令 + 固化命令模板 (--ack L04,L05 显式确认)
|
|
14
|
+
|
|
15
|
+
退出码: 0 = 全过; 1 = 有 FAIL。preflight 自己也守 L03: 全程 && 语义, fail-fast。
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
import re
|
|
22
|
+
import subprocess
|
|
23
|
+
import sys
|
|
24
|
+
|
|
25
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
26
|
+
_ROOT = os.path.dirname(os.path.dirname(HERE)) # arc-agi-2 (L09: __file__ 锚定)
|
|
27
|
+
WS_ROOT = os.path.dirname(_ROOT)
|
|
28
|
+
|
|
29
|
+
from .ledger import LESSONS # noqa: E402
|
|
30
|
+
|
|
31
|
+
# 扫描范围: 本仓 py/sh (排除冻结区大件目录与本模块自身无须排除)
|
|
32
|
+
_SCAN_EXCL_DIR = {"__pycache__", ".git", "node_modules",
|
|
33
|
+
"submission_run_v1_out", "kaggle_kernel_shot1", "kaggle_kernel_shot2",
|
|
34
|
+
"site-packages", "openclaw-src", ".venv-nle", ".trash_ai-research_cleared_20260912"} # 2026-11-20 范围修: 第三方(venv/openclaw 上游)/实验快照/垃圾箱不属治理扫描面
|
|
35
|
+
_MAX_SCAN_FILES = 4000
|
|
36
|
+
|
|
37
|
+
_OK, _FAIL, _DECL = "PASS", "FAIL", "DECL"
|
|
38
|
+
|
|
39
|
+
_BASELINE_FILE = os.path.join(HERE, "preflight_baseline.json")
|
|
40
|
+
# L09 口径: 教训入册日之后新增/改动的脚本必须 __file__ 锚定;
|
|
41
|
+
# 入册前历史散件不计 (改到哪修到哪), 基线文件仍可显式点名复核。
|
|
42
|
+
_L09_EPOCH = 1793548800.0 # 2026-11-02 00:00 +08:00 教训入册日
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _load_baseline(lesson_id):
|
|
46
|
+
"""已复核历史基线 (L06 精神: 只保护逐条复核过的旧账, 新命中必须真修)。"""
|
|
47
|
+
try:
|
|
48
|
+
data = json.load(open(_BASELINE_FILE))
|
|
49
|
+
return set(data.get(lesson_id, []))
|
|
50
|
+
except Exception:
|
|
51
|
+
return set()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _iter_code_files():
|
|
55
|
+
"""L09 纪律: 从 __file__ 锚定的 _ROOT 走目录, 不猜 cwd。"""
|
|
56
|
+
n = 0
|
|
57
|
+
for dirpath, dirnames, filenames in os.walk(_ROOT):
|
|
58
|
+
dirnames[:] = [d for d in dirnames if d not in _SCAN_EXCL_DIR]
|
|
59
|
+
for fn in filenames:
|
|
60
|
+
if not fn.endswith((".py", ".sh")):
|
|
61
|
+
continue
|
|
62
|
+
# E2 自扫排除: 检查器家族 (gate/process) 自身的说明文字含
|
|
63
|
+
# "pkill -f"/"; 串联"等 pattern 字面量, 外部根扫描时会误伤自己。
|
|
64
|
+
if fn in ("preflight.py", "ledger.py", "boot.py") and \
|
|
65
|
+
os.path.basename(dirpath) in ("gate", "process"):
|
|
66
|
+
continue
|
|
67
|
+
yield os.path.join(dirpath, fn)
|
|
68
|
+
n += 1
|
|
69
|
+
if n >= _MAX_SCAN_FILES:
|
|
70
|
+
return
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _read(path):
|
|
74
|
+
try:
|
|
75
|
+
with open(path, "r", encoding="utf-8", errors="replace") as f:
|
|
76
|
+
return f.read()
|
|
77
|
+
except OSError:
|
|
78
|
+
return ""
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# ─────────────────────────── auto 断言实现 ───────────────────────────
|
|
82
|
+
|
|
83
|
+
def check_ledger_integrity(ctx):
|
|
84
|
+
"""L01: 台账每条必须有教训原文/触发场景/行为检查项/验证证据/固化命令模板 + 断言。"""
|
|
85
|
+
bad = []
|
|
86
|
+
for ls in LESSONS:
|
|
87
|
+
for field in ("lesson", "trigger", "check_item", "evidence", "cmd_template"):
|
|
88
|
+
if not str(ls.get(field, "")).strip():
|
|
89
|
+
bad.append(f"{ls['id']} 缺 {field}")
|
|
90
|
+
a = ls.get("assertion") or {}
|
|
91
|
+
if a.get("kind") not in ("auto", "decl"):
|
|
92
|
+
bad.append(f"{ls['id']} 断言类型非法")
|
|
93
|
+
if a.get("kind") == "auto" and a.get("fn") not in globals():
|
|
94
|
+
bad.append(f"{ls['id']} 断言函数 {a.get('fn')} 不存在")
|
|
95
|
+
if bad:
|
|
96
|
+
return _FAIL, "台账不完整: " + "; ".join(bad)
|
|
97
|
+
return _OK, f"{len(LESSONS)} 条教训六字段齐全, 断言全部注册"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def check_pid_discipline(ctx):
|
|
101
|
+
"""L02: 仓内脚本禁用 pkill -f / pgrep -f (匹配自己命令行的自杀实锤)。"""
|
|
102
|
+
hits = []
|
|
103
|
+
for path in _iter_code_files():
|
|
104
|
+
if os.path.abspath(path).startswith(os.path.abspath(HERE)):
|
|
105
|
+
continue # 本检查器自身引用 pattern 不算
|
|
106
|
+
text = _read(path)
|
|
107
|
+
for i, line in enumerate(text.splitlines(), 1):
|
|
108
|
+
if re.search(r"\bpkill\s+-f\b|\bpgrep\s+-f\b", line):
|
|
109
|
+
hits.append(f"{os.path.relpath(path, _ROOT)}:{i}")
|
|
110
|
+
if hits:
|
|
111
|
+
return _FAIL, "发现 pkill -f/pgrep -f: " + ", ".join(hits[:8])
|
|
112
|
+
return _OK, "仓内 py/sh 零 pkill -f / pgrep -f (进程一律 pid/`pgrep -x`)"
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def check_failfast_chains(ctx):
|
|
116
|
+
"""L03: 关键校验 (py_compile/pytest/回归) 不得用 `;` 串联。"""
|
|
117
|
+
pat = re.compile(r"(py_compile|pytest|run_full_regression|selftest)[^\n;&|]{0,120};(?! ?(?:then|do)\b)") # 2026-11-20 精化: 排除 if/循环控制结构的分号(真违例=check; check 串联)
|
|
118
|
+
hits = []
|
|
119
|
+
for path in _iter_code_files():
|
|
120
|
+
if os.path.abspath(path).startswith(os.path.abspath(HERE)):
|
|
121
|
+
continue # 检查器自身含 pattern 字面量, 不自扫
|
|
122
|
+
text = _read(path)
|
|
123
|
+
for i, line in enumerate(text.splitlines(), 1):
|
|
124
|
+
if pat.search(line):
|
|
125
|
+
hits.append(f"{os.path.relpath(path, _ROOT)}:{i}")
|
|
126
|
+
# 已复核基线 (L06 精神: 复核→补已复核那条→正常放行; 新增命中不受基线保护)
|
|
127
|
+
base = _load_baseline("L03")
|
|
128
|
+
new_hits = [h for h in hits if h.split(":")[0] not in base]
|
|
129
|
+
if new_hits:
|
|
130
|
+
return _FAIL, "关键校验疑似 `;` 串联: " + ", ".join(new_hits[:8])
|
|
131
|
+
n_base = len(hits) - len(new_hits)
|
|
132
|
+
return _OK, (f"未发现新增 `;` 串联 (fail-fast 链)"
|
|
133
|
+
+ (f"; 历史基线已复核 {n_base} 条" if n_base else ""))
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def check_snapshot_pin(ctx):
|
|
137
|
+
"""L09: 快照/数据路径必须从 __file__ 锚定导出; 禁裸 sys.path.insert 猜路径吃钉死快照。"""
|
|
138
|
+
suspect = []
|
|
139
|
+
for path in _iter_code_files():
|
|
140
|
+
rel = os.path.relpath(path, _ROOT)
|
|
141
|
+
if rel.startswith("arc_core" + os.sep): # 包内 __init__ 常规写法, 另有规范
|
|
142
|
+
continue
|
|
143
|
+
text = _read(path)
|
|
144
|
+
if not text:
|
|
145
|
+
continue
|
|
146
|
+
if re.search(r"\bsys\.path\.insert\(", text) and not ("__file__" in text and "abspath" in text):
|
|
147
|
+
# 教训入册 (2026-11-02) 后新增/改动的脚本才算违规; 入册前散件不计
|
|
148
|
+
if os.path.getmtime(path) < _L09_EPOCH:
|
|
149
|
+
continue
|
|
150
|
+
suspect.append(rel)
|
|
151
|
+
base = _load_baseline("L09")
|
|
152
|
+
new_hits = [s for s in suspect if s not in base]
|
|
153
|
+
if new_hits:
|
|
154
|
+
return _FAIL, "裸 sys.path 且无 __file__ 锚定 (入册后新件): " + ", ".join(new_hits[:8])
|
|
155
|
+
return _OK, (f"入册 (2026-11-02) 后新/改脚本均 __file__ 锚定; "
|
|
156
|
+
f"历史散件基线 {len(base)} 个已逐个复核入册 (改到哪修到哪)")
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def check_llm_process_count(ctx):
|
|
160
|
+
"""L12: 20B 级大模型并发计算 <=1 (管「同时计算」的卡死风险;
|
|
161
|
+
后台待命/常驻不算; 3B/4B 小模型与 embedding 不计)。判据=并发计算中的大模型数 >=2 才 FAIL。"""
|
|
162
|
+
try:
|
|
163
|
+
out = subprocess.run(["pgrep", "-x", "llama-server"], capture_output=True,
|
|
164
|
+
text=True, timeout=5)
|
|
165
|
+
pids = [p for p in out.stdout.split() if p.strip()]
|
|
166
|
+
except Exception:
|
|
167
|
+
pids = []
|
|
168
|
+
active_large, standby_large = [], []
|
|
169
|
+
for pid in pids:
|
|
170
|
+
cmdline = _read("/proc/%s/cmdline" % pid).replace(chr(0), " ")
|
|
171
|
+
if "--embedding" in cmdline:
|
|
172
|
+
continue
|
|
173
|
+
size = _model_size_b(cmdline)
|
|
174
|
+
if size is not None and size < 20:
|
|
175
|
+
continue # 3B/4B 等小/中模型不计(L12 豁免)
|
|
176
|
+
(active_large if _is_computing(pid) else standby_large).append(pid)
|
|
177
|
+
if len(active_large) >= 2:
|
|
178
|
+
return _FAIL, ("20B 级大模型并发计算 %d 个 (pid: %s) -- 同时计算卡死风险 (L12; 待命不计)"
|
|
179
|
+
% (len(active_large), active_large))
|
|
180
|
+
if active_large or standby_large:
|
|
181
|
+
return _OK, ("20B 级大模型: 计算中 %d, 待命 %d (并发计算 <=1 合规; L12 管并发计算不是管进程数)"
|
|
182
|
+
% (len(active_large), len(standby_large)))
|
|
183
|
+
return _OK, "无 20B 级大模型在跑 (L12 合规)"
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _model_size_b(cmdline):
|
|
187
|
+
"""从模型文件名提取参数规模(B); 提不出=None(按大模型保守计)。"""
|
|
188
|
+
for tok in cmdline.split():
|
|
189
|
+
if ".gguf" in tok:
|
|
190
|
+
m = re.search(r"[-_.](\d+(?:\.\d+)?)[bB][-_.]", tok)
|
|
191
|
+
if m:
|
|
192
|
+
return float(m.group(1))
|
|
193
|
+
return None
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _is_computing(pid, window=0.4):
|
|
197
|
+
"""短窗 CPU 占用判定: 计算态 >20% 算在算, 否则待命 (L12 并发计算口径)。"""
|
|
198
|
+
import time
|
|
199
|
+
try:
|
|
200
|
+
def ticks():
|
|
201
|
+
return sum(int(x) for x in _read("/proc/%s/stat" % pid).rsplit(")", 1)[1].split()[11:13])
|
|
202
|
+
t0 = ticks()
|
|
203
|
+
time.sleep(window)
|
|
204
|
+
t1 = ticks()
|
|
205
|
+
clk = os.sysconf("SC_CLK_TCK")
|
|
206
|
+
return (t1 - t0) / float(clk * window) > 0.20
|
|
207
|
+
except Exception:
|
|
208
|
+
return False
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def check_dns_pin(ctx):
|
|
212
|
+
"""L13: googleapis 死 IP 防线 —— kaggle 上传必须走 socket.getaddrinfo 钉法。
|
|
213
|
+
勘误 E1 (整合施工方案_v1 §5): 适用性门控 —— 无 kaggle 上传活动的工作区
|
|
214
|
+
=PASS(不适用); 有上传活动则必须走钉法且钉法脚本在位 (防工作区耦合误报)。"""
|
|
215
|
+
bad, pin_refs, any_upload = [], 0, False
|
|
216
|
+
for path in _iter_code_files():
|
|
217
|
+
rel = os.path.relpath(path, _ROOT)
|
|
218
|
+
if os.path.abspath(path).startswith(os.path.abspath(HERE)):
|
|
219
|
+
continue # 检查器自身不自扫
|
|
220
|
+
text = _read(path)
|
|
221
|
+
if re.search(r"\bkaggle\s+(datasets|models)\s+(create|version|upload|push)\b", text):
|
|
222
|
+
any_upload = True
|
|
223
|
+
if "getaddrinfo" in text or "upload_pinned" in text:
|
|
224
|
+
pin_refs += 1
|
|
225
|
+
else:
|
|
226
|
+
bad.append(rel)
|
|
227
|
+
if bad:
|
|
228
|
+
return _FAIL, "kaggle 上传未走钉法: " + ", ".join(bad[:6])
|
|
229
|
+
if not any_upload:
|
|
230
|
+
return _OK, "本工作区无 kaggle 上传活动 (L13 不适用); 钉法机制保留在台账"
|
|
231
|
+
pins = [p for p in _iter_code_files() if os.path.basename(p) == "upload_pinned.py"]
|
|
232
|
+
good_pins = [p for p in pins if "getaddrinfo" in _read(p)]
|
|
233
|
+
if pin_refs and not good_pins:
|
|
234
|
+
return _FAIL, "上传引用钉法但 upload_pinned.py 缺失/被改坏"
|
|
235
|
+
return _OK, f"kaggle 上传 {pin_refs} 处均走钉法; 合格钉法脚本 {len(good_pins)} 个"
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def check_report_stat_bytes(ctx):
|
|
239
|
+
"""L08: 报单与实盘逐字节对账 —— 报单里 `路径` = N B 声明逐个 stat -c%s 复核。"""
|
|
240
|
+
report = ctx.get("report_path")
|
|
241
|
+
if not report:
|
|
242
|
+
return _DECL, "未带 --report <报单.md>; 交账前请用 --report 复核 (stat -c%s 实测字节)"
|
|
243
|
+
text = _read(report)
|
|
244
|
+
if not text:
|
|
245
|
+
return _FAIL, f"报单不可读: {report}"
|
|
246
|
+
decls = re.findall(r"`([^`]+)`\s*=\s*([\d,]+)\s*B", text)
|
|
247
|
+
if not decls:
|
|
248
|
+
return _FAIL, "报单无 `路径` = N B 声明 (L08: 必须含 stat -c%s 实测字节)"
|
|
249
|
+
bad = []
|
|
250
|
+
for rel, size in decls:
|
|
251
|
+
target = rel if os.path.isabs(rel) else os.path.join(_ROOT, rel)
|
|
252
|
+
if not os.path.isfile(target):
|
|
253
|
+
bad.append(f"{rel} 不存在")
|
|
254
|
+
continue
|
|
255
|
+
actual = os.path.getsize(target)
|
|
256
|
+
if actual != int(size.replace(",", "")):
|
|
257
|
+
bad.append(f"{rel} 报 {size} 实 {actual}")
|
|
258
|
+
if bad:
|
|
259
|
+
return _FAIL, "报单对账不符: " + "; ".join(bad[:6])
|
|
260
|
+
return _OK, f"报单 {len(decls)} 项 stat -c%s 全部对上"
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
# ─────────────────────────── 运行器 ───────────────────────────
|
|
264
|
+
|
|
265
|
+
def run_preflight(report_path=None, ack=None, strict=False, root=None):
|
|
266
|
+
"""跑全部断言, 返回 (rows, ok)。rows: [{id, lesson, kind, status, detail, cmd}]。
|
|
267
|
+
root= 可选: 对任意工作区跑门禁(产品化参数, 供 boot/外部工作区调用)。
|
|
268
|
+
"""
|
|
269
|
+
global _ROOT, WS_ROOT
|
|
270
|
+
_saved = (_ROOT, WS_ROOT)
|
|
271
|
+
if root:
|
|
272
|
+
_ROOT = os.path.abspath(root)
|
|
273
|
+
WS_ROOT = os.path.dirname(_ROOT)
|
|
274
|
+
try:
|
|
275
|
+
return _run_preflight_inner(report_path=report_path, ack=ack, strict=strict)
|
|
276
|
+
finally:
|
|
277
|
+
_ROOT, WS_ROOT = _saved
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _run_preflight_inner(report_path=None, ack=None, strict=False):
|
|
281
|
+
ack = set(ack or [])
|
|
282
|
+
ctx = {"report_path": report_path}
|
|
283
|
+
rows = []
|
|
284
|
+
ok = True
|
|
285
|
+
for ls in LESSONS:
|
|
286
|
+
a = ls.get("assertion") or {}
|
|
287
|
+
kind = a.get("kind")
|
|
288
|
+
if kind == "auto":
|
|
289
|
+
fn = globals().get(a.get("fn", ""))
|
|
290
|
+
if fn is None:
|
|
291
|
+
status, detail = _FAIL, f"断言函数缺失: {a.get('fn')}"
|
|
292
|
+
else:
|
|
293
|
+
try:
|
|
294
|
+
status, detail = fn(ctx)
|
|
295
|
+
except Exception as e: # 断言自身炸了 = FAIL, 不静默
|
|
296
|
+
status, detail = _FAIL, f"断言异常: {e}"
|
|
297
|
+
else:
|
|
298
|
+
if ls["id"] in ack:
|
|
299
|
+
status, detail = _OK, "已人工确认 (--ack)"
|
|
300
|
+
else:
|
|
301
|
+
status, detail = _DECL, "待人工确认: " + ls["check_item"]
|
|
302
|
+
if status == _FAIL or (strict and status == _DECL):
|
|
303
|
+
ok = False
|
|
304
|
+
rows.append({"id": ls["id"], "lesson": ls["lesson"][:40], "kind": kind,
|
|
305
|
+
"status": status, "detail": detail,
|
|
306
|
+
"cmd": ls.get("cmd_template", "")})
|
|
307
|
+
return rows, ok
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def main(argv=None):
|
|
311
|
+
import argparse
|
|
312
|
+
ap = argparse.ArgumentParser(prog="python3 -m pvs.gate preflight",
|
|
313
|
+
description="教训台账 → 可执行断言, 开工前跑一遍")
|
|
314
|
+
ap.add_argument("--report", default=None, help="报单 md 路径 (L08 逐字节对账)")
|
|
315
|
+
ap.add_argument("--ack", default="", help="逗号分隔人工确认项, 如 L04,L05")
|
|
316
|
+
ap.add_argument("--strict", action="store_true", help="DECL 未确认也算 FAIL")
|
|
317
|
+
ap.add_argument("--json", action="store_true", help="机器可读输出")
|
|
318
|
+
args = ap.parse_args(argv)
|
|
319
|
+
|
|
320
|
+
ack = [x.strip() for x in args.ack.split(",") if x.strip()]
|
|
321
|
+
rows, ok = run_preflight(report_path=args.report, ack=ack, strict=args.strict)
|
|
322
|
+
|
|
323
|
+
if args.json:
|
|
324
|
+
print(json.dumps({"ok": ok, "rows": rows}, ensure_ascii=False, indent=1))
|
|
325
|
+
return 0 if ok else 1
|
|
326
|
+
|
|
327
|
+
print("=== preflight(教训台账 → 可执行断言) ===")
|
|
328
|
+
for r in rows:
|
|
329
|
+
mark = {_OK: "[ OK ]", _FAIL: "[FAIL]", _DECL: "[DECL]"}[r["status"]]
|
|
330
|
+
print(f"{mark} {r['id']} {r['lesson']}")
|
|
331
|
+
print(f" {r['detail']}")
|
|
332
|
+
if r["status"] != _OK and r["cmd"]:
|
|
333
|
+
print(f" 模板: {r['cmd']}")
|
|
334
|
+
n_fail = sum(1 for r in rows if r["status"] == _FAIL)
|
|
335
|
+
n_decl = sum(1 for r in rows if r["status"] == _DECL)
|
|
336
|
+
print(f"--- 结论: {len(rows)} 项, FAIL {n_fail}, DECL {n_decl} → "
|
|
337
|
+
f"{'开工放行' if ok else '先修 FAIL/补确认'}")
|
|
338
|
+
return 0 if ok else 1
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
if __name__ == "__main__":
|
|
342
|
+
sys.exit(main())
|
|
File without changes
|