reasonweave 0.0.0-stage → 1.3.2
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/AGENTS.md +101 -0
- package/INSTALL.md +258 -0
- package/README.md +280 -2
- package/bin/lab.mjs +888 -0
- package/constitution.md +55 -0
- package/docs/CONSUMER-PROMPTS.md +474 -0
- package/docs/backlogs/01-forward-wait-self-detach.md +18 -0
- package/docs/backlogs/02-decouple-wait-and-daemon-for-agent-hosts.md +35 -0
- package/docs/backlogs/03-baton-wait-multi-id-lightweight-pubsub.md +34 -0
- package/docs/backlogs/04-adr-cross-repo-automated-dispatch-boundary.md +19 -0
- package/docs/backlogs/05-feat-units-worktree-isolation-engine.md +23 -0
- package/docs/backlogs/06-feat-blind-audit-automated-clean-runner.md +22 -0
- package/docs/backlogs/07-feat-attention-throttle-silent-pipe.md +23 -0
- package/docs/backlogs/08-future-units-shadow-ledger.md +22 -0
- package/docs/backlogs/09-feat-agent-baton-core-convergence-and-resilience.md +42 -0
- package/docs/backlogs/10-feat-anti-orphan-deterministic-wiring-governance.md +35 -0
- package/docs/backlogs/11-perf-orphan-index-fs-read.md +16 -0
- package/docs/backlogs/12-feat-vibe-security-anti-suppression-and-orphan-deps.md +43 -0
- package/docs/backlogs/13-feat-sdd-reppit-tiered-guardrails.md +40 -0
- package/docs/backlogs/14-feat-universal-cli-contract-and-hermetic-test-fixtures.md +48 -0
- package/docs/backlogs/15-feat-reasonweave-rebranding-and-doc-code-synchronization-invariant.md +44 -0
- package/docs/backlogs/16-feat-micro-engineering-skills-and-sdd-baton-fusion.md +52 -0
- package/docs/codegraph-readiness-check.md +49 -0
- package/group/architecture/adr/0001-handoff-async-wait-and-reactive-wakeup.md +87 -0
- package/group/architecture/adr/0002-de-ritualize-handoff-prompt-for-intra-repo.md +53 -0
- package/group/architecture/adr/0003-attention-throttle-and-workspace-driver.md +65 -0
- package/group/architecture/adr/0004-spec-guard-and-drift-prevention.md +90 -0
- package/group/architecture/adr/0005-global-orphan-scavenger-and-read-only-invariants.md +94 -0
- package/group/architecture/adr/0006-triad-engineering-defense-and-mutation-sensitivity.md +68 -0
- package/group/architecture/adr/0007-agent-baton-state-machine-defense-and-workspace-jail-spec.md +86 -0
- package/group/architecture/adr/0008-agent-baton-core-convergence-and-heterogeneous-session-resilience.md +133 -0
- package/group/architecture/adr/0009-anti-orphan-deterministic-wiring-governance-and-federated-guardrails.md +108 -0
- package/group/architecture/adr/0010-agent-baton-identity-security-cryptographic-credentials-and-prompt-anti-confusion.md +119 -0
- package/group/architecture/adr/0011-vibe-security-anti-suppression-and-dependency-reachability.md +161 -0
- package/group/architecture/adr/0012-spec-driven-development-reppit-and-tiered-guardrails.md +130 -0
- package/group/architecture/adr/0013-universal-cli-contract-hermetic-testing-and-defensive-probes.md +110 -0
- package/group/architecture/adr/0014-reasonweave-rebranding-and-doc-code-synchronization-invariant.md +108 -0
- package/group/architecture/adr/0015-micro-engineering-skills-and-dual-core-gate-invariant.md +127 -0
- package/group/architecture/adr/INDEX.md +29 -0
- package/group/architecture/adr/templates/adr-template.md +33 -0
- package/group/architecture/dependency-graph.md +60 -0
- package/group/contracts/npm-packaging.md +69 -0
- package/group/product/intent.md +24 -0
- package/package.json +93 -4
- package/scripts/sync-all-consumers.mjs +174 -0
- package/specs/RFC-20261110-SPEC-GUARD-UNIT.md +353 -0
- package/specs/templates/01-research.md.template +23 -0
- package/specs/templates/02-proposals.md.template +22 -0
- package/specs/templates/03-spec.md.template +33 -0
- package/specs/templates/04-tasks.md.template +29 -0
- package/specs/templates/05-evidence.md.template +29 -0
- package/specs/templates/README.md +26 -0
- package/units/adr/AGENTS.md +85 -0
- package/units/adr/CHANGELOG.md +20 -0
- package/units/adr/README.md +88 -0
- package/units/adr/VERSION.md +10 -0
- package/units/adr/docs/existing-project-prompt.md +24 -0
- package/units/adr/docs/new-project-prompt.md +36 -0
- package/units/adr/scripts/adr-init.sh +101 -0
- package/units/adr/templates/INDEX.md +19 -0
- package/units/adr/templates/adr-frozen.md +33 -0
- package/units/adr/templates/adr-light.md +56 -0
- package/units/adr/templates/adr-standard.md +61 -0
- package/units/backlog/AGENTS.md +53 -0
- package/units/backlog/AUTONOMOUS-GOVERNANCE.md +98 -0
- package/units/backlog/CHANGELOG.md +37 -0
- package/units/backlog/README.md +124 -0
- package/units/backlog/VERSION.md +11 -0
- package/units/backlog/docs/existing-project-ironrules-prompt.md +31 -0
- package/units/backlog/docs/existing-project-prompt.md +24 -0
- package/units/backlog/docs/new-project-prompt.md +19 -0
- package/units/backlog/templates/entry.md +39 -0
- package/units/backlog/templates/project-ironrules.md +36 -0
- package/units/handoffs/AGENT-GUIDE.md +118 -0
- package/units/handoffs/AGENTS.md +28 -0
- package/units/handoffs/CHANGELOG.md +498 -0
- package/units/handoffs/CLAUDE.md +28 -0
- package/units/handoffs/COMMANDS.md +187 -0
- package/units/handoffs/DESIGN.md +74 -0
- package/units/handoffs/README.md +456 -0
- package/units/handoffs/RESPONSE-TEMPLATE.md +138 -0
- package/units/handoffs/VERSION.md +1 -0
- package/units/handoffs/handoff-status.mjs +1017 -0
- package/units/handoffs/handoff.mjs +5675 -0
- package/units/orphan/CHANGELOG.md +118 -0
- package/units/orphan/DESIGN.md +484 -0
- package/units/orphan/README.md +143 -0
- package/units/orphan/VERSION.md +1 -0
- package/units/orphan/adapters/android/index.mjs +140 -0
- package/units/orphan/adapters/python/index.mjs +232 -0
- package/units/orphan/adapters/web/index.mjs +280 -0
- package/units/orphan/bin/lab-orphan.mjs +298 -0
- package/units/orphan/core/blob-reader.mjs +142 -0
- package/units/orphan/core/classifier.mjs +261 -0
- package/units/orphan/core/cleaner.mjs +166 -0
- package/units/orphan/core/diff-checker.mjs +341 -0
- package/units/orphan/core/inverted-index.mjs +124 -0
- package/units/orphan/core/orphan-deps.mjs +192 -0
- package/units/orphan/core/protocol-s1-s3.mjs +194 -0
- package/units/orphan/core/solver.mjs +217 -0
- package/units/orphan/index.mjs +105 -0
- package/units/orphan/templates/ci/orphan-guard.yml +36 -0
- package/units/orphan/templates/pre-commit.d/30-orphan-guard +34 -0
- package/units/orphan/templates/wiring/README.md +51 -0
- package/units/orphan/templates/wiring/miniprogram-route-guard.js.template +80 -0
- package/units/orphan/templates/wiring/pre-commit-node.sh.template +73 -0
- package/units/orphan/templates/wiring/project-agents-gemini-templates.md +60 -0
- package/units/orphan/templates/wiring/python-parity-test.py.template +100 -0
- package/units/orphan/templates/wiring/rust-exhaustive-match.md +65 -0
- package/units/orphan/templates/wiring/swift-periphery.md +56 -0
- package/units/orphan/tests/adapters.test.mjs +243 -0
- package/units/orphan/tests/orphan-deps.test.mjs +131 -0
- package/units/orphan/tests/phase3-gates.test.mjs +135 -0
- package/units/playbook/README.md +106 -0
- package/units/playbook/ZSPEC-AGENT-GUIDE.md +99 -0
- package/units/playbook/docs/01-architecture.md +99 -0
- package/units/playbook/docs/02-bootstrap.md +126 -0
- package/units/playbook/docs/03-units.md +91 -0
- package/units/playbook/docs/04-constitution.md +113 -0
- package/units/playbook/docs/05-adr.md +33 -0
- package/units/playbook/docs/06-spec-kit.md +76 -0
- package/units/playbook/docs/07-backlog.md +30 -0
- package/units/playbook/docs/08-codegraph.md +79 -0
- package/units/playbook/docs/09-skills.md +101 -0
- package/units/playbook/docs/10-handoff.md +72 -0
- package/units/playbook/docs/11-evidence.md +163 -0
- package/units/playbook/docs/12-gates.md +124 -0
- package/units/playbook/docs/13-parallel.md +115 -0
- package/units/playbook/docs/14-dependency-graph.md +86 -0
- package/units/playbook/docs/15-memory.md +153 -0
- package/units/playbook/docs/16-change-control.md +121 -0
- package/units/playbook/docs/17-prompts.md +121 -0
- package/units/playbook/docs/18-shift-left.md +97 -0
- package/units/playbook/docs/19-anti-orphan-vertical-slicing.md +102 -0
- package/units/playbook/docs/20-vibe-security-and-anti-suppression.md +88 -0
- package/units/playbook/docs/21-spec-driven-reppit-closed-loop.md +88 -0
- package/units/playbook/examples/owisel.md +80 -0
- package/units/playbook/references/Agent-Engineering-Framework-AEF-v1.0.md +2033 -0
- package/units/playbook/references/links.md +103 -0
- package/units/playbook/templates/AGENTS.root.md +44 -0
- package/units/playbook/templates/AGENTS.unit.md +52 -0
- package/units/playbook/templates/adr/INDEX.md +17 -0
- package/units/playbook/templates/adr/NNNN-template.md +56 -0
- package/units/playbook/templates/backlogs/entry.md +30 -0
- package/units/playbook/templates/constitution.md +93 -0
- package/units/playbook/templates/evidence/README.md +36 -0
- package/units/playbook/templates/group/architecture/dependency-graph.md +48 -0
- package/units/playbook/templates/group/architecture/system.md +59 -0
- package/units/playbook/templates/group/contracts/api.md +67 -0
- package/units/playbook/templates/group/product/intent.md +30 -0
- package/units/playbook/templates/group/product/requirements.md +48 -0
- package/units/playbook/templates/unit-skeleton/README.md +35 -0
- package/units/preflight/AGENTS.md +45 -0
- package/units/preflight/CHANGELOG.md +55 -0
- package/units/preflight/INSTALL.md +65 -0
- package/units/preflight/README.md +104 -0
- package/units/preflight/VERSION.md +3 -0
- package/units/preflight/docs/audit-requirements.md +114 -0
- package/units/preflight/docs/existing-project-prompt.md +25 -0
- package/units/preflight/docs/new-project-prompt.md +25 -0
- package/units/preflight/docs/transfers/CONSUMER-INSTALL.md +40 -0
- package/units/preflight/docs/transfers/CONSUMER-SELFCHECK.md +51 -0
- package/units/preflight/docs/transfers/README.md +39 -0
- package/units/preflight/docs/transfers/prospero.md +26 -0
- package/units/preflight/templates/check.sh +43 -0
- package/units/preflight/templates/pre-commit +55 -0
- package/units/preflight/templates/pre-commit.d/20-preflight +15 -0
- package/units/preflight/templates/preflight.conf.example +21 -0
- package/units/preflight/templates/preflight.sh +189 -0
- package/units/preflight/templates/wrap-up.md +9 -0
- package/units/review-gate/AGENTS.md +42 -0
- package/units/review-gate/CHANGELOG.md +58 -0
- package/units/review-gate/README.md +118 -0
- package/units/review-gate/VERSION.md +3 -0
- package/units/review-gate/clean-runner.mjs +350 -0
- package/units/review-gate/docs/existing-project-prompt.md +28 -0
- package/units/review-gate/docs/new-project-prompt.md +38 -0
- package/units/review-gate/docs/transfers/iggle.md +34 -0
- package/units/review-gate/docs/transfers/prospero.md +35 -0
- package/units/review-gate/docs/transfers/swoop.md +36 -0
- package/units/review-gate/docs/transfers/yiqiyihuihua.md +35 -0
- package/units/review-gate/templates/.semgrepignore +37 -0
- package/units/review-gate/templates/pre-commit +130 -0
- package/units/review-gate/templates/scan.sh +158 -0
- package/units/skills/AGENTS.md +17 -0
- package/units/skills/CHANGELOG.md +18 -0
- package/units/skills/README.md +63 -0
- package/units/skills/VERSION.md +1 -0
- package/units/skills/bin/review-package.mjs +99 -0
- package/units/skills/bin/task-brief.mjs +102 -0
- package/units/skills/catalog/brainstorming/SKILL.md +75 -0
- package/units/skills/catalog/brainstorming/references/design-doc-template.md +28 -0
- package/units/skills/catalog/systematic-debugging/SKILL.md +101 -0
- package/units/skills/catalog/systematic-debugging/references/root-cause-tracing.md +23 -0
- package/units/skills/catalog/test-driven-development/SKILL.md +88 -0
- package/units/skills/catalog/test-driven-development/references/writing-good-tests.md +13 -0
- package/units/skills/catalog/verification-before-completion/SKILL.md +73 -0
- package/units/skills/skills.mjs +181 -0
- package/units/skills/tests/pipeline.test.mjs +131 -0
- package/units/skills/tests/skill-contract.test.mjs +67 -0
- package/units/skills/tests/skills-cli.test.mjs +107 -0
- package/units/spec-guard/AGENTS.md +43 -0
- package/units/spec-guard/CHANGELOG.md +88 -0
- package/units/spec-guard/README.md +148 -0
- package/units/spec-guard/VERSION.md +1 -0
- package/units/spec-guard/bin/spec-guard.mjs +431 -0
- package/units/spec-guard/core/adr-parser.mjs +540 -0
- package/units/spec-guard/core/matrix-checker.mjs +587 -0
- package/units/spec-guard/core/mutation-runner.mjs +267 -0
- package/units/spec-guard/core/scanner.mjs +333 -0
- package/units/spec-guard/core/telemetry_authenticator.mjs +484 -0
- package/units/spec-guard/core/wiring_tracer.mjs +306 -0
- package/units/spec-guard/templates/annotations/ContractOnly.kt +19 -0
- package/units/spec-guard/templates/annotations/Invariant.kt +16 -0
- package/units/spec-guard/templates/annotations/invariant.go +19 -0
- package/units/spec-guard/templates/annotations/invariant.py +38 -0
- package/units/spec-guard/templates/annotations/invariant.ts +39 -0
- package/units/spec-guard/templates/ci/spec-guard-audit.yml +23 -0
- package/units/spec-guard/templates/pre-commit.d/15-spec-guard +72 -0
- package/units/spec-guard/templates/spec-matrix.overlay.yml +70 -0
- package/units/spec-guard/tests/spec-guard.test.mjs +716 -0
- package/units/spec-guard/tests/telemetry_authenticator.test.mjs +633 -0
- package/units/worktree/AGENTS.md +22 -0
- package/units/worktree/CHANGELOG.md +14 -0
- package/units/worktree/README.md +65 -0
- package/units/worktree/VERSION.md +1 -0
- package/units/worktree/worktree.mjs +352 -0
- package//344/275/277/347/224/250/350/257/264/346/230/216.md +322 -0
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* matrix-checker.mjs
|
|
3
|
+
*
|
|
4
|
+
* 核心对账矩阵计算引擎(Code-as-Spec-Matrix):
|
|
5
|
+
* 1. 内存动态汇聚 ADR 规约、源码断言、沙箱标记与可选 Overlay 配置
|
|
6
|
+
* 2. 严格词界对账:ADR Invariant ↔ Code Assertion ↔ Production Wiring
|
|
7
|
+
* 3. 漂移(Drift)与孤儿断言(Orphan Assertions)精确识别
|
|
8
|
+
* 4. 产出结构化审计数据与 Markdown/终端报告
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import {
|
|
14
|
+
findAdrFiles,
|
|
15
|
+
parseAdrFile,
|
|
16
|
+
containsStrictInvariant,
|
|
17
|
+
loadOverlayConfig,
|
|
18
|
+
parseSimpleYamlOverlay,
|
|
19
|
+
} from './adr-parser.mjs';
|
|
20
|
+
import { scanRepository, analyzeSymbolWiring } from './scanner.mjs';
|
|
21
|
+
import { verifyAllAdrsTelemetry } from './telemetry_authenticator.mjs';
|
|
22
|
+
import { traceAllAdrsWiring } from './wiring_tracer.mjs';
|
|
23
|
+
|
|
24
|
+
export { loadOverlayConfig, parseSimpleYamlOverlay };
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 核心对账计算:动态生成 Code-as-Spec-Matrix 并比对
|
|
28
|
+
*/
|
|
29
|
+
export function buildAndCheckMatrix(repoRoot, options = {}) {
|
|
30
|
+
// 1. 扫描所有 ADR
|
|
31
|
+
const overlay = loadOverlayConfig(repoRoot, options.overlay || options.overlayPath || '');
|
|
32
|
+
const config = { ...overlay, ...options };
|
|
33
|
+
const adrFilePaths = findAdrFiles(repoRoot, config);
|
|
34
|
+
const parsedAdrs = adrFilePaths.map((p) => parseAdrFile(p, config));
|
|
35
|
+
|
|
36
|
+
// 2. 扫描源码中所有的 @Invariant 与 @ContractOnly 声明
|
|
37
|
+
const scanResult = scanRepository(repoRoot);
|
|
38
|
+
const codeInvariants = scanResult.invariants;
|
|
39
|
+
const codeContracts = scanResult.contracts;
|
|
40
|
+
|
|
41
|
+
// 建立全局对账账本
|
|
42
|
+
const adrReports = [];
|
|
43
|
+
const allKnownInvariantIds = new Set();
|
|
44
|
+
|
|
45
|
+
let totalInvariantsCount = 0;
|
|
46
|
+
let verifiedCount = 0;
|
|
47
|
+
let sandboxedCount = 0;
|
|
48
|
+
let inProgressCount = 0;
|
|
49
|
+
let driftCount = 0;
|
|
50
|
+
const unwiredInvariants = [];
|
|
51
|
+
|
|
52
|
+
for (const adr of parsedAdrs) {
|
|
53
|
+
const adrId = adr.adrId;
|
|
54
|
+
const invResults = [];
|
|
55
|
+
|
|
56
|
+
// 收集 ADR 中声明的不变量
|
|
57
|
+
for (const inv of adr.invariants) {
|
|
58
|
+
totalInvariantsCount++;
|
|
59
|
+
allKnownInvariantIds.add(inv.canonicalId);
|
|
60
|
+
allKnownInvariantIds.add(inv.localId);
|
|
61
|
+
|
|
62
|
+
// 在源码中严格匹配绑定的断言(严格边界,且防跨 ADR 串标)
|
|
63
|
+
const matchingAssertions = codeInvariants.filter((item) => {
|
|
64
|
+
// 若断言 ID 包含 ADR 前缀(如 "ADR-060:H-1")
|
|
65
|
+
if (item.id.includes(':')) {
|
|
66
|
+
const [prefix, local] = item.id.split(':');
|
|
67
|
+
if (prefix.toUpperCase() !== adrId.toUpperCase()) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return local === inv.localId || containsStrictInvariant(local, inv.localId);
|
|
71
|
+
}
|
|
72
|
+
// 若断言 ID 仅有局部名(如 "H-1"),仅当文件名包含该 ADR 编号时方认可
|
|
73
|
+
return (item.id === inv.localId || containsStrictInvariant(item.id, inv.localId)) &&
|
|
74
|
+
item.file.toLowerCase().includes(adrId.toLowerCase());
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// 检查是否有对应的 ContractOnly 沙箱保护
|
|
78
|
+
const matchingContracts = codeContracts.filter((c) => {
|
|
79
|
+
return c.adr === adrId || containsStrictInvariant(c.adr, adrId);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// 检查 Overlay 是否有额外契约状态补充
|
|
83
|
+
const overlayItem = overlay.invariants.find((o) => o.id === inv.canonicalId || o.id === inv.localId);
|
|
84
|
+
|
|
85
|
+
// 检查关联的生产符号(来自 Overlay、生产代码中的 @Invariant 声明、或测试显式 targetSymbol)
|
|
86
|
+
const associatedSymbols = new Set();
|
|
87
|
+
if (overlayItem && overlayItem.productionSymbols) {
|
|
88
|
+
for (const s of overlayItem.productionSymbols) associatedSymbols.add(s);
|
|
89
|
+
}
|
|
90
|
+
for (const a of matchingAssertions) {
|
|
91
|
+
if (!a.isTest && a.symbolName) {
|
|
92
|
+
associatedSymbols.add(a.symbolName);
|
|
93
|
+
}
|
|
94
|
+
if (a.targetSymbol) {
|
|
95
|
+
associatedSymbols.add(a.targetSymbol);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 如果仅有单测标注且没有显式符号,扫描测试声明或非 test 开头符号
|
|
100
|
+
if (associatedSymbols.size === 0 && matchingAssertions.some((a) => a.isTest)) {
|
|
101
|
+
for (const a of matchingAssertions.filter((a) => a.isTest)) {
|
|
102
|
+
if (a.symbolName && !a.symbolName.startsWith('test')) {
|
|
103
|
+
associatedSymbols.add(a.symbolName);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let symbolWiringInfo = null;
|
|
109
|
+
let hasZeroCallers = false;
|
|
110
|
+
|
|
111
|
+
if (associatedSymbols.size > 0) {
|
|
112
|
+
for (const sym of associatedSymbols) {
|
|
113
|
+
const wiring = analyzeSymbolWiring(sym, repoRoot);
|
|
114
|
+
symbolWiringInfo = {
|
|
115
|
+
symbolName: sym,
|
|
116
|
+
productionCallerCount: wiring.prodCallers.length,
|
|
117
|
+
testCallerCount: wiring.testCallers.length,
|
|
118
|
+
wiringStatus: wiring.wiringStatus,
|
|
119
|
+
productionCallers: wiring.prodCallers,
|
|
120
|
+
testCallers: wiring.testCallers,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
if (wiring.prodCallers.length === 0) {
|
|
124
|
+
hasZeroCallers = true;
|
|
125
|
+
unwiredInvariants.push({
|
|
126
|
+
invariantId: inv.canonicalId,
|
|
127
|
+
localId: inv.localId,
|
|
128
|
+
adrId,
|
|
129
|
+
symbolName: sym,
|
|
130
|
+
testCallers: wiring.testCallers,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 状态裁定
|
|
137
|
+
let finalStatus = 'in_progress';
|
|
138
|
+
let statusReason = '';
|
|
139
|
+
|
|
140
|
+
if (options.checkCallers && hasZeroCallers) {
|
|
141
|
+
finalStatus = 'unwired';
|
|
142
|
+
statusReason = `🚨 架构函数未在生产关键链路接线 (Zero Production Callers: ${symbolWiringInfo?.symbolName || 'unknown'})`;
|
|
143
|
+
} else if (matchingAssertions.length > 0) {
|
|
144
|
+
// 拥有机器断言
|
|
145
|
+
const testAssertions = matchingAssertions.filter((a) => a.isTest);
|
|
146
|
+
if (matchingContracts.length > 0) {
|
|
147
|
+
finalStatus = 'sandboxed';
|
|
148
|
+
statusReason = `沙箱保护(@ContractOnly,等待接线闭环)`;
|
|
149
|
+
sandboxedCount++;
|
|
150
|
+
} else if (adr.isFrozen && testAssertions.length > 0) {
|
|
151
|
+
finalStatus = 'verified';
|
|
152
|
+
statusReason = `机判断言就绪 (${testAssertions.length} 处断言)`;
|
|
153
|
+
verifiedCount++;
|
|
154
|
+
} else {
|
|
155
|
+
finalStatus = 'in_progress';
|
|
156
|
+
statusReason = `断言已就绪,等待 ADR 验收与生产接线`;
|
|
157
|
+
inProgressCount++;
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
// 零断言
|
|
161
|
+
if (adr.isFrozen) {
|
|
162
|
+
finalStatus = 'drift_detected';
|
|
163
|
+
statusReason = `🚨 规约已 🔒Frozen 但代码中零断言覆盖!`;
|
|
164
|
+
driftCount++;
|
|
165
|
+
} else {
|
|
166
|
+
finalStatus = 'in_progress';
|
|
167
|
+
statusReason = `暂无对应 @Invariant 机器断言`;
|
|
168
|
+
inProgressCount++;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (overlayItem && overlayItem.status) {
|
|
173
|
+
statusReason += ` (Overlay 标注: ${overlayItem.status})`;
|
|
174
|
+
}
|
|
175
|
+
if (symbolWiringInfo && !hasZeroCallers) {
|
|
176
|
+
statusReason += ` [生产接线: ${symbolWiringInfo.productionCallerCount} 处]`;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
invResults.push({
|
|
180
|
+
invariantId: inv.canonicalId,
|
|
181
|
+
localId: inv.localId,
|
|
182
|
+
description: inv.description,
|
|
183
|
+
status: finalStatus,
|
|
184
|
+
statusReason,
|
|
185
|
+
assertionsCount: matchingAssertions.length,
|
|
186
|
+
assertions: matchingAssertions,
|
|
187
|
+
contracts: matchingContracts,
|
|
188
|
+
symbolWiring: symbolWiringInfo,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
adrReports.push({
|
|
193
|
+
adr,
|
|
194
|
+
invariants: invResults,
|
|
195
|
+
hasInvariants: adr.invariants.length > 0,
|
|
196
|
+
implementationStatusMissing: adr.isFrozen && !adr.hasImplementationStatus,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 4. 识别孤儿断言(代码写了 @Invariant 但 ADR 根本未定义)
|
|
201
|
+
const orphanAssertions = [];
|
|
202
|
+
for (const item of codeInvariants) {
|
|
203
|
+
let recognized = false;
|
|
204
|
+
for (const known of allKnownInvariantIds) {
|
|
205
|
+
if (item.id === known || containsStrictInvariant(item.id, known)) {
|
|
206
|
+
recognized = true;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (!recognized) {
|
|
211
|
+
orphanAssertions.push(item);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const isZeroCoverage = parsedAdrs.length === 0;
|
|
216
|
+
const coveragePercent = isZeroCoverage
|
|
217
|
+
? 0
|
|
218
|
+
: (totalInvariantsCount > 0
|
|
219
|
+
? Math.round(((verifiedCount + sandboxedCount) / totalInvariantsCount) * 100)
|
|
220
|
+
: 100);
|
|
221
|
+
|
|
222
|
+
return {
|
|
223
|
+
repoRoot,
|
|
224
|
+
scannedFilesCount: scanResult.scannedFilesCount,
|
|
225
|
+
adrsCount: parsedAdrs.length,
|
|
226
|
+
adrReports,
|
|
227
|
+
totalInvariantsCount,
|
|
228
|
+
verifiedCount,
|
|
229
|
+
sandboxedCount,
|
|
230
|
+
inProgressCount,
|
|
231
|
+
driftCount,
|
|
232
|
+
coveragePercent,
|
|
233
|
+
orphanAssertions,
|
|
234
|
+
unwiredInvariants,
|
|
235
|
+
zeroCoverage: isZeroCoverage,
|
|
236
|
+
isHealthy: !isZeroCoverage && driftCount === 0 && orphanAssertions.length === 0 && (!options.checkCallers || unwiredInvariants.length === 0),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 格式化终端输出报告
|
|
242
|
+
*/
|
|
243
|
+
export function formatConsoleReport(matrixResult) {
|
|
244
|
+
const lines = [];
|
|
245
|
+
lines.push('\n🛡️ \x1b[1mSpec-Guard (Drift-Gate) 规约对账矩阵报告\x1b[0m');
|
|
246
|
+
lines.push('═'.repeat(65));
|
|
247
|
+
lines.push(`📁 扫描代码文件: ${matrixResult.scannedFilesCount} 个 | ADR 规约: ${matrixResult.adrsCount} 份`);
|
|
248
|
+
lines.push(`📊 总不变量: ${matrixResult.totalInvariantsCount} | 已验证: \x1b[32m${matrixResult.verifiedCount}\x1b[0m | 沙箱隔离: \x1b[36m${matrixResult.sandboxedCount}\x1b[0m | 进行中: \x1b[33m${matrixResult.inProgressCount}\x1b[0m | 漂移: \x1b[31m${matrixResult.driftCount}\x1b[0m`);
|
|
249
|
+
lines.push(`📈 规约断言有效覆盖率: \x1b[1m${matrixResult.coveragePercent}%\x1b[0m\n`);
|
|
250
|
+
|
|
251
|
+
if (matrixResult.zeroCoverage || matrixResult.adrsCount === 0) {
|
|
252
|
+
lines.push(`\x1b[31m⚠️ ZERO_COVERAGE: 未扫描到任何有效 ADR 规约文件!零覆盖不可伪装为通过。\x1b[0m\n`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
for (const rep of matrixResult.adrReports) {
|
|
256
|
+
if (!rep.hasInvariants) continue;
|
|
257
|
+
const adr = rep.adr;
|
|
258
|
+
const frozenTag = adr.isFrozen ? '\x1b[35m[🔒Frozen]\x1b[0m' : `[${adr.status}]`;
|
|
259
|
+
lines.push(`\x1b[1m${adr.adrId}\x1b[0m ${frozenTag} - ${adr.title}`);
|
|
260
|
+
|
|
261
|
+
if (rep.implementationStatusMissing) {
|
|
262
|
+
lines.push(` \x1b[31m⚠️ 警告: 该 ADR 已标记 🔒Frozen 但缺少标准的 ## Implementation Status 段落!\x1b[0m`);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
for (const inv of rep.invariants) {
|
|
266
|
+
let icon = '⏳';
|
|
267
|
+
let color = '\x1b[33m';
|
|
268
|
+
if (inv.status === 'verified') {
|
|
269
|
+
icon = '✅';
|
|
270
|
+
color = '\x1b[32m';
|
|
271
|
+
} else if (inv.status === 'sandboxed') {
|
|
272
|
+
icon = '📦';
|
|
273
|
+
color = '\x1b[36m';
|
|
274
|
+
} else if (inv.status === 'drift_detected' || inv.status === 'unwired') {
|
|
275
|
+
icon = '🚨';
|
|
276
|
+
color = '\x1b[31m';
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
lines.push(` ${icon} ${color}${inv.invariantId.padEnd(16)}\x1b[0m : ${inv.statusReason}`);
|
|
280
|
+
for (const a of inv.assertions) {
|
|
281
|
+
lines.push(` └─ [Assertion] ${a.file}:${a.line}`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
lines.push('');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (matrixResult.orphanAssertions.length > 0) {
|
|
288
|
+
lines.push(`\x1b[33m⚠️ 发现 ${matrixResult.orphanAssertions.length} 处孤儿断言(代码标记了 @Invariant 但 ADR 规约中未定义):\x1b[0m`);
|
|
289
|
+
for (const o of matrixResult.orphanAssertions) {
|
|
290
|
+
lines.push(` - \x1b[33m${o.id}\x1b[0m at ${o.file}:${o.line}`);
|
|
291
|
+
}
|
|
292
|
+
lines.push('');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (matrixResult.unwiredInvariants && matrixResult.unwiredInvariants.length > 0) {
|
|
296
|
+
lines.push(`\x1b[31m🚨 架构函数未在生产关键链路接线 (Zero Production Callers):\x1b[0m`);
|
|
297
|
+
for (const u of matrixResult.unwiredInvariants) {
|
|
298
|
+
lines.push(` - \x1b[31m${u.invariantId}\x1b[0m -> 符号 \x1b[1m${u.symbolName}\x1b[0m 生产调用数为 0 (单测调用数: ${u.testCallers.length})`);
|
|
299
|
+
}
|
|
300
|
+
lines.push('');
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return lines.join('\n');
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* 为单个 ADR 生成详细的 Markdown 机器审计对账报告
|
|
308
|
+
*/
|
|
309
|
+
export function generateAdrAuditReport(matrixResult, targetAdrId) {
|
|
310
|
+
const normTarget = targetAdrId.toUpperCase();
|
|
311
|
+
const rep = matrixResult.adrReports.find((r) => r.adr.adrId.toUpperCase() === normTarget);
|
|
312
|
+
|
|
313
|
+
if (!rep) {
|
|
314
|
+
return `# 审计报告:${targetAdrId} (未找到)\n\n在代码库中未扫描到 ${targetAdrId} 的 ADR 文件。\n`;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const adr = rep.adr;
|
|
318
|
+
const lines = [];
|
|
319
|
+
lines.push(`# 机器审计报告:${adr.adrId} 架构规约对账凭据`);
|
|
320
|
+
lines.push(`\n- **规约标题**:${adr.title}`);
|
|
321
|
+
lines.push(`- **当前状态**:${adr.status}`);
|
|
322
|
+
lines.push(`- **审计时间**:${new Date().toISOString()}`);
|
|
323
|
+
lines.push(`- **文件路径**:\`${adr.filePath}\``);
|
|
324
|
+
lines.push(`- **Implementation Status 状态节**:${adr.hasImplementationStatus ? '✅ 规范完备' : '❌ 缺失'}`);
|
|
325
|
+
lines.push('\n---\n');
|
|
326
|
+
|
|
327
|
+
lines.push('## 1. 不变量与机器断言对账矩阵 (Triad Reconciliation)\n');
|
|
328
|
+
lines.push('| 不变量 ID | 描述 | 状态 | 断言数 | 详情 / 证据位置 |');
|
|
329
|
+
lines.push('|---|---|---|---|---|');
|
|
330
|
+
|
|
331
|
+
for (const inv of rep.invariants) {
|
|
332
|
+
const statusLabel =
|
|
333
|
+
inv.status === 'verified'
|
|
334
|
+
? '✅ 已验证'
|
|
335
|
+
: inv.status === 'sandboxed'
|
|
336
|
+
? '📦 沙箱隔离'
|
|
337
|
+
: inv.status === 'drift_detected'
|
|
338
|
+
? '🚨 漂移脱节'
|
|
339
|
+
: '⏳ 进行中';
|
|
340
|
+
|
|
341
|
+
const evidence = inv.assertions.length > 0
|
|
342
|
+
? inv.assertions.map((a) => `\`${a.file}:${a.line}\``).join('<br>')
|
|
343
|
+
: '无断言';
|
|
344
|
+
|
|
345
|
+
lines.push(`| **${inv.invariantId}** | ${inv.description} | ${statusLabel} | ${inv.assertionsCount} | ${evidence} |`);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
lines.push('\n## 2. 规约落地建议 (Verdict)\n');
|
|
349
|
+
const allVerified = rep.invariants.length > 0 && rep.invariants.every((i) => i.status === 'verified');
|
|
350
|
+
const hasDrift = rep.invariants.some((i) => i.status === 'drift_detected');
|
|
351
|
+
|
|
352
|
+
// [C5 语义校验] 检查 Implementation Status 表格项是否存在未落地/部分实现项
|
|
353
|
+
const hasUnfinishedImpl = adr.implementationItems && adr.implementationItems.some(
|
|
354
|
+
(item) => item.status === 'unwired' || item.status === 'in_progress'
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
if (hasDrift) {
|
|
358
|
+
lines.push('> ❌ **阻断判定**:检测到严重架构漂移!该规约声称生效或已 Frozen,但存在零断言覆盖的不变量。**严禁以“已实现”上报,严禁进行 Frozen 冻结签署**。\n');
|
|
359
|
+
} else if (allVerified && adr.hasImplementationStatus && !hasUnfinishedImpl) {
|
|
360
|
+
lines.push('> ✅ **合规建议**:所有声明的不变量均已绑定有效可机判断言,且落地状态节完备。具备由架构师及用户人工签署 `🔒Frozen` 的机器凭据。\n');
|
|
361
|
+
} else {
|
|
362
|
+
lines.push('> ⏳ **进行中判定**:规约部分能力处于逐步交付中(存在 ❌ 未接线 或 ⚠️ 部分实现 项)。请在 `## Implementation Status` 中如实跟踪,待全量落地后方可签署 Frozen 验收。\n');
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return lines.join('\n');
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* 构建断言、证据、接线三元全景对账矩阵 (Triad Matrix)
|
|
370
|
+
*/
|
|
371
|
+
export function buildFullTriadMatrix(repoRoot, options = {}) {
|
|
372
|
+
const assertionMatrix = buildAndCheckMatrix(repoRoot, options);
|
|
373
|
+
const telemetryMatrix = verifyAllAdrsTelemetry(repoRoot, options);
|
|
374
|
+
const wiringMatrix = traceAllAdrsWiring(repoRoot, options);
|
|
375
|
+
|
|
376
|
+
const triadRows = [];
|
|
377
|
+
const adrMap = new Map();
|
|
378
|
+
|
|
379
|
+
for (const rep of assertionMatrix.adrReports) {
|
|
380
|
+
const id = rep.adr.adrId.toUpperCase();
|
|
381
|
+
adrMap.set(id, {
|
|
382
|
+
adrId: rep.adr.adrId,
|
|
383
|
+
title: rep.adr.title,
|
|
384
|
+
isFrozen: rep.adr.isFrozen,
|
|
385
|
+
status: rep.adr.status,
|
|
386
|
+
assertion: rep,
|
|
387
|
+
telemetry: null,
|
|
388
|
+
wiring: null,
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
for (const t of telemetryMatrix.reports) {
|
|
393
|
+
const id = t.adrId.toUpperCase();
|
|
394
|
+
if (!adrMap.has(id)) {
|
|
395
|
+
adrMap.set(id, {
|
|
396
|
+
adrId: t.adrId,
|
|
397
|
+
title: '',
|
|
398
|
+
isFrozen: false,
|
|
399
|
+
status: 'Unknown',
|
|
400
|
+
assertion: null,
|
|
401
|
+
telemetry: t,
|
|
402
|
+
wiring: null,
|
|
403
|
+
});
|
|
404
|
+
} else {
|
|
405
|
+
adrMap.get(id).telemetry = t;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
for (const w of wiringMatrix.reports) {
|
|
410
|
+
const id = w.adrId.toUpperCase();
|
|
411
|
+
if (!adrMap.has(id)) {
|
|
412
|
+
adrMap.set(id, {
|
|
413
|
+
adrId: w.adrId,
|
|
414
|
+
title: '',
|
|
415
|
+
isFrozen: w.isFrozen,
|
|
416
|
+
status: w.isFrozen ? '🔒 Frozen' : 'Draft',
|
|
417
|
+
assertion: null,
|
|
418
|
+
telemetry: null,
|
|
419
|
+
wiring: w,
|
|
420
|
+
});
|
|
421
|
+
} else {
|
|
422
|
+
adrMap.get(id).wiring = w;
|
|
423
|
+
if (w.isFrozen) adrMap.get(id).isFrozen = true;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
let totalAdrs = adrMap.size;
|
|
428
|
+
let healthyAdrs = 0;
|
|
429
|
+
let telemetryDriftCount = 0;
|
|
430
|
+
let orphanDecisionCount = 0;
|
|
431
|
+
let assertionDriftCount = assertionMatrix.driftCount;
|
|
432
|
+
|
|
433
|
+
for (const [id, item] of adrMap.entries()) {
|
|
434
|
+
let verdict = 'VERIFIED';
|
|
435
|
+
let verdictIcon = '✅';
|
|
436
|
+
let hasFailure = false;
|
|
437
|
+
|
|
438
|
+
// 1. 断言状态
|
|
439
|
+
let assertionSummary = '无不变量';
|
|
440
|
+
if (item.assertion && item.assertion.invariants.length > 0) {
|
|
441
|
+
const totalInv = item.assertion.invariants.length;
|
|
442
|
+
const verifiedInv = item.assertion.invariants.filter((i) => i.status === 'verified').length;
|
|
443
|
+
const hasDrift = item.assertion.invariants.some((i) => i.status === 'drift_detected');
|
|
444
|
+
if (hasDrift) {
|
|
445
|
+
assertionSummary = `🚨 漂移 (${verifiedInv}/${totalInv})`;
|
|
446
|
+
verdict = 'DRIFT_DETECTED';
|
|
447
|
+
verdictIcon = '🚨';
|
|
448
|
+
hasFailure = true;
|
|
449
|
+
} else if (verifiedInv === totalInv) {
|
|
450
|
+
assertionSummary = `✅ 100% (${verifiedInv}/${totalInv})`;
|
|
451
|
+
} else {
|
|
452
|
+
assertionSummary = `⏳ ${Math.round((verifiedInv / totalInv) * 100)}% (${verifiedInv}/${totalInv})`;
|
|
453
|
+
if (verdict === 'VERIFIED') verdict = 'IN_PROGRESS';
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// 2. 数据自述凭据状态
|
|
458
|
+
let telemetrySummary = 'ℹ️ 豁免 (无量化)';
|
|
459
|
+
if (item.telemetry && item.telemetry.hasMetrics) {
|
|
460
|
+
if (item.telemetry.status === 'PASS') {
|
|
461
|
+
telemetrySummary = `✅ 验签通过 (${item.telemetry.metricsCount}项)`;
|
|
462
|
+
} else {
|
|
463
|
+
telemetrySummary = `🚨 自述漂移 (违反 ADR-064)`;
|
|
464
|
+
telemetryDriftCount++;
|
|
465
|
+
verdict = 'TELEMETRY_DRIFT';
|
|
466
|
+
verdictIcon = '🚨';
|
|
467
|
+
hasFailure = true;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// 3. 物理代码接线状态
|
|
472
|
+
let wiringSummary = 'ℹ️ 无需接线';
|
|
473
|
+
if (item.wiring && item.wiring.candidateSymbolsCount > 0) {
|
|
474
|
+
if (item.wiring.status === 'FAIL' || item.wiring.isOrphan) {
|
|
475
|
+
wiringSummary = `🚨 孤儿决策 (0/${item.wiring.candidateSymbolsCount})`;
|
|
476
|
+
orphanDecisionCount++;
|
|
477
|
+
verdict = 'ORPHAN_DECISION';
|
|
478
|
+
verdictIcon = '🚨';
|
|
479
|
+
hasFailure = true;
|
|
480
|
+
} else if (item.wiring.status === 'PASS') {
|
|
481
|
+
wiringSummary = `✅ 存活 (${item.wiring.wiredCount}/${item.wiring.candidateSymbolsCount})`;
|
|
482
|
+
} else {
|
|
483
|
+
wiringSummary = `⏳ 未接线 (0/${item.wiring.candidateSymbolsCount})`;
|
|
484
|
+
if (verdict === 'VERIFIED') verdict = 'IN_PROGRESS';
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (!hasFailure && verdict === 'VERIFIED') {
|
|
489
|
+
healthyAdrs++;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
triadRows.push({
|
|
493
|
+
adrId: item.adrId,
|
|
494
|
+
title: item.title,
|
|
495
|
+
isFrozen: item.isFrozen,
|
|
496
|
+
status: item.status,
|
|
497
|
+
assertionSummary,
|
|
498
|
+
telemetrySummary,
|
|
499
|
+
wiringSummary,
|
|
500
|
+
verdict,
|
|
501
|
+
verdictIcon,
|
|
502
|
+
hasFailure,
|
|
503
|
+
item,
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// 排序
|
|
508
|
+
triadRows.sort((a, b) => {
|
|
509
|
+
const numA = parseInt((a.adrId.match(/\d+/) || [0])[0], 10);
|
|
510
|
+
const numB = parseInt((b.adrId.match(/\d+/) || [0])[0], 10);
|
|
511
|
+
return numA - numB;
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
const isZeroCoverage = totalAdrs === 0;
|
|
515
|
+
const isHealthy = !isZeroCoverage && assertionDriftCount === 0 && telemetryDriftCount === 0 && orphanDecisionCount === 0;
|
|
516
|
+
|
|
517
|
+
return {
|
|
518
|
+
repoRoot,
|
|
519
|
+
assertionMatrix,
|
|
520
|
+
telemetryMatrix,
|
|
521
|
+
wiringMatrix,
|
|
522
|
+
triadRows,
|
|
523
|
+
totalAdrs,
|
|
524
|
+
healthyAdrs,
|
|
525
|
+
assertionDriftCount,
|
|
526
|
+
telemetryDriftCount,
|
|
527
|
+
orphanDecisionCount,
|
|
528
|
+
coveragePercent: isZeroCoverage ? 0 : assertionMatrix.coveragePercent,
|
|
529
|
+
zeroCoverage: isZeroCoverage,
|
|
530
|
+
isHealthy,
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* 格式化全景对账热力表输出 (Triad Heatmap)
|
|
536
|
+
*/
|
|
537
|
+
export function formatTriadHeatmap(triadResult) {
|
|
538
|
+
const lines = [];
|
|
539
|
+
lines.push('\n🛡️ \x1b[1mSpec-Guard (Drift-Gate) v2.0 - 全景对账热力表 (Triad Heatmap)\x1b[0m');
|
|
540
|
+
lines.push('═'.repeat(96));
|
|
541
|
+
lines.push(
|
|
542
|
+
`📊 规约总数: ${triadResult.totalAdrs} | 断言漂移: \x1b[31m${triadResult.assertionDriftCount}\x1b[0m | 数据漂移: \x1b[31m${triadResult.telemetryDriftCount}\x1b[0m | 孤儿决策: \x1b[31m${triadResult.orphanDecisionCount}\x1b[0m`
|
|
543
|
+
);
|
|
544
|
+
lines.push('─'.repeat(96));
|
|
545
|
+
|
|
546
|
+
// 表头
|
|
547
|
+
const colAdr = 'ADR 编号'.padEnd(10);
|
|
548
|
+
const colStatus = '规约状态'.padEnd(12);
|
|
549
|
+
const colAss = '断言 (Assertion)'.padEnd(20);
|
|
550
|
+
const colTel = '证据 (Evidence)'.padEnd(28);
|
|
551
|
+
const colWir = '接线 (Wiring)'.padEnd(16);
|
|
552
|
+
const colVer = '综合裁决';
|
|
553
|
+
|
|
554
|
+
lines.push(`\x1b[1m${colAdr} | ${colStatus} | ${colAss} | ${colTel} | ${colWir} | ${colVer}\x1b[0m`);
|
|
555
|
+
lines.push('─'.repeat(96));
|
|
556
|
+
|
|
557
|
+
for (const row of triadResult.triadRows) {
|
|
558
|
+
const frozenTag = row.isFrozen ? '[🔒Frozen]' : '[Draft]';
|
|
559
|
+
const statusCol = frozenTag.padEnd(10);
|
|
560
|
+
const adrCol = row.adrId.padEnd(10);
|
|
561
|
+
const assCol = row.assertionSummary.padEnd(18);
|
|
562
|
+
const telCol = row.telemetrySummary.padEnd(26);
|
|
563
|
+
const wirCol = row.wiringSummary.padEnd(14);
|
|
564
|
+
|
|
565
|
+
let verdictColor = '\x1b[32m';
|
|
566
|
+
if (row.verdict === 'DRIFT_DETECTED' || row.verdict === 'TELEMETRY_DRIFT' || row.verdict === 'ORPHAN_DECISION') {
|
|
567
|
+
verdictColor = '\x1b[31m';
|
|
568
|
+
} else if (row.verdict === 'IN_PROGRESS') {
|
|
569
|
+
verdictColor = '\x1b[33m';
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
lines.push(
|
|
573
|
+
`${adrCol} | ${statusCol} | ${assCol} | ${telCol} | ${wirCol} | ${verdictColor}${row.verdictIcon} ${row.verdict}\x1b[0m`
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
lines.push('═'.repeat(96));
|
|
578
|
+
if (triadResult.totalAdrs === 0 || triadResult.zeroCoverage) {
|
|
579
|
+
lines.push('\x1b[31m❌ [ZERO_COVERAGE] 门禁阻断:未发现任何有效 ADR 规约!零覆盖不可伪装为健康。\x1b[0m\n');
|
|
580
|
+
} else if (triadResult.isHealthy) {
|
|
581
|
+
lines.push('\x1b[32m✅ 全景三元对账检查通过!无断言漂移、无实测数据伪造、无孤儿冻结决策。\x1b[0m\n');
|
|
582
|
+
} else {
|
|
583
|
+
lines.push('\x1b[31m❌ 全景三元对账门禁阻断!发现存在断言脱节、实测数据伪造或孤儿冻结决策。\x1b[0m\n');
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return lines.join('\n');
|
|
587
|
+
}
|