soloforge 1.2.19 → 1.2.20
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/dist/adapters/claude_code/tools.d.ts.map +1 -1
- package/dist/adapters/claude_code/tools.js +159 -1
- package/dist/adapters/claude_code/tools.js.map +1 -1
- package/dist/adapters/trae/trae_config.d.ts +1 -1
- package/dist/adapters/trae/trae_config.d.ts.map +1 -1
- package/dist/adapters/trae/trae_config.js +1 -1
- package/dist/adapters/trae/trae_config.js.map +1 -1
- package/dist/engine/audit_pool.d.ts.map +1 -1
- package/dist/engine/audit_pool.js +1 -0
- package/dist/engine/audit_pool.js.map +1 -1
- package/dist/engine/contract_registry.d.ts +113 -0
- package/dist/engine/contract_registry.d.ts.map +1 -0
- package/dist/engine/contract_registry.js +1159 -0
- package/dist/engine/contract_registry.js.map +1 -0
- package/dist/engine/contract_state_store.d.ts +67 -0
- package/dist/engine/contract_state_store.d.ts.map +1 -0
- package/dist/engine/contract_state_store.js +167 -0
- package/dist/engine/contract_state_store.js.map +1 -0
- package/dist/engine/debugger.d.ts.map +1 -1
- package/dist/engine/debugger.js +30 -1
- package/dist/engine/debugger.js.map +1 -1
- package/dist/engine/degradation.d.ts +58 -0
- package/dist/engine/degradation.d.ts.map +1 -0
- package/dist/engine/degradation.js +74 -0
- package/dist/engine/degradation.js.map +1 -0
- package/dist/engine/delivery_readiness.d.ts +66 -0
- package/dist/engine/delivery_readiness.d.ts.map +1 -0
- package/dist/engine/delivery_readiness.js +176 -0
- package/dist/engine/delivery_readiness.js.map +1 -0
- package/dist/engine/deprecated_contract.d.ts +21 -0
- package/dist/engine/deprecated_contract.d.ts.map +1 -0
- package/dist/engine/deprecated_contract.js +14 -0
- package/dist/engine/deprecated_contract.js.map +1 -0
- package/dist/engine/diagnostic_registry.d.ts +64 -0
- package/dist/engine/diagnostic_registry.d.ts.map +1 -0
- package/dist/engine/diagnostic_registry.js +176 -0
- package/dist/engine/diagnostic_registry.js.map +1 -0
- package/dist/engine/enforcement_guard.d.ts +84 -0
- package/dist/engine/enforcement_guard.d.ts.map +1 -0
- package/dist/engine/enforcement_guard.js +305 -0
- package/dist/engine/enforcement_guard.js.map +1 -0
- package/dist/engine/failure_report.d.ts +74 -0
- package/dist/engine/failure_report.d.ts.map +1 -0
- package/dist/engine/failure_report.js +143 -0
- package/dist/engine/failure_report.js.map +1 -0
- package/dist/engine/governance_report.d.ts +9 -1
- package/dist/engine/governance_report.d.ts.map +1 -1
- package/dist/engine/governance_report.js +16 -2
- package/dist/engine/governance_report.js.map +1 -1
- package/dist/engine/implementation_roadmap_registry.d.ts +1 -1
- package/dist/engine/implementation_roadmap_registry.d.ts.map +1 -1
- package/dist/engine/implementation_roadmap_registry.js +32 -24
- package/dist/engine/implementation_roadmap_registry.js.map +1 -1
- package/dist/engine/knowledge_lifecycle.d.ts +23 -0
- package/dist/engine/knowledge_lifecycle.d.ts.map +1 -0
- package/dist/engine/knowledge_lifecycle.js +13 -0
- package/dist/engine/knowledge_lifecycle.js.map +1 -0
- package/dist/engine/language_policy.d.ts +21 -0
- package/dist/engine/language_policy.d.ts.map +1 -0
- package/dist/engine/language_policy.js +18 -0
- package/dist/engine/language_policy.js.map +1 -0
- package/dist/engine/language_policy_contract.d.ts +52 -0
- package/dist/engine/language_policy_contract.d.ts.map +1 -0
- package/dist/engine/language_policy_contract.js +78 -0
- package/dist/engine/language_policy_contract.js.map +1 -0
- package/dist/engine/mechanism_family_registry.d.ts +48 -0
- package/dist/engine/mechanism_family_registry.d.ts.map +1 -0
- package/dist/engine/mechanism_family_registry.js +197 -0
- package/dist/engine/mechanism_family_registry.js.map +1 -0
- package/dist/engine/policy_drift_detector.d.ts +20 -0
- package/dist/engine/policy_drift_detector.d.ts.map +1 -1
- package/dist/engine/policy_drift_detector.js +79 -0
- package/dist/engine/policy_drift_detector.js.map +1 -1
- package/dist/engine/retention_policy.d.ts +46 -0
- package/dist/engine/retention_policy.d.ts.map +1 -0
- package/dist/engine/retention_policy.js +124 -0
- package/dist/engine/retention_policy.js.map +1 -0
- package/dist/engine/state_update_bypass.d.ts +19 -0
- package/dist/engine/state_update_bypass.d.ts.map +1 -0
- package/dist/engine/state_update_bypass.js +17 -0
- package/dist/engine/state_update_bypass.js.map +1 -0
- package/dist/engine/task_context.d.ts.map +1 -1
- package/dist/engine/task_context.js +8 -0
- package/dist/engine/task_context.js.map +1 -1
- package/dist/engine/test_strategy.d.ts +58 -0
- package/dist/engine/test_strategy.d.ts.map +1 -0
- package/dist/engine/test_strategy.js +93 -0
- package/dist/engine/test_strategy.js.map +1 -0
- package/dist/engine/tool_invocation_contract_registry.d.ts.map +1 -1
- package/dist/engine/tool_invocation_contract_registry.js +11 -1
- package/dist/engine/tool_invocation_contract_registry.js.map +1 -1
- package/dist/engine/verification_contract.d.ts +132 -0
- package/dist/engine/verification_contract.d.ts.map +1 -0
- package/dist/engine/verification_contract.js +296 -0
- package/dist/engine/verification_contract.js.map +1 -0
- package/dist/engine/workspace_lease.d.ts +69 -0
- package/dist/engine/workspace_lease.d.ts.map +1 -0
- package/dist/engine/workspace_lease.js +153 -0
- package/dist/engine/workspace_lease.js.map +1 -0
- package/dist/types.d.ts +13 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,1159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一契约注册表 — 将治理对象从 capability 扩展到多 kind contract。
|
|
3
|
+
*
|
|
4
|
+
* 问题二十 (Unified Contract Registry) 核心实现:
|
|
5
|
+
* - 统一登记 workflow、guard、verification、delivery、failure、degradation、
|
|
6
|
+
* metric、language_policy 等所有核心契约
|
|
7
|
+
* - contract_id 作为一等治理身份
|
|
8
|
+
* - policy_id 到 contract_id 的映射
|
|
9
|
+
* - 契约状态门控、漂移检测、依赖校验、证据校验
|
|
10
|
+
* - Runtime hard fail gating
|
|
11
|
+
*
|
|
12
|
+
* Capability Registry 保留为能力状态事实源,此表覆盖更广泛的契约类型。
|
|
13
|
+
*/
|
|
14
|
+
import { getCapability } from "./capability_registry.js";
|
|
15
|
+
// ── 内置契约注册表 ──
|
|
16
|
+
const BUILTIN_CONTRACTS = [
|
|
17
|
+
// ── 1. 工作流契约 ──
|
|
18
|
+
{
|
|
19
|
+
contract_id: "workflow_contract",
|
|
20
|
+
kind: "workflow",
|
|
21
|
+
name: "工作流契约",
|
|
22
|
+
state: "enforced",
|
|
23
|
+
owner_component: "engine/workflow_contract_registry",
|
|
24
|
+
owner_files: ["src/engine/workflow_contract_registry.ts"],
|
|
25
|
+
test_files: ["tests/engine/workflow_contract_registry.test.ts"],
|
|
26
|
+
lifecycle_test_files: ["tests/engine/workflow_contract_registry.test.ts"],
|
|
27
|
+
knowledge_refs: ["templates/knowledge/rules/工作流契约规则.md"],
|
|
28
|
+
prompt_refs: [],
|
|
29
|
+
depends_on: ["route_decision_contract"],
|
|
30
|
+
consumed_by: ["tool_invocation_contract", "main_path_integration_contract"],
|
|
31
|
+
hard_fail_allowed: true,
|
|
32
|
+
promotion_conditions: ["所有 workflow 有集成测试"],
|
|
33
|
+
demotion_conditions: ["workflow regression check 漏检"],
|
|
34
|
+
evidence_requirements: ["validateWorkflowContracts 无 hard_fail"],
|
|
35
|
+
policy_id: "CAP-021",
|
|
36
|
+
capability_ids: ["workflow_contract"],
|
|
37
|
+
},
|
|
38
|
+
// ── 2. 工具调用契约 ──
|
|
39
|
+
{
|
|
40
|
+
contract_id: "tool_invocation_contract",
|
|
41
|
+
kind: "guard",
|
|
42
|
+
name: "工具调用契约",
|
|
43
|
+
state: "enforced",
|
|
44
|
+
owner_component: "engine/tool_invocation_contract_registry",
|
|
45
|
+
owner_files: ["src/engine/tool_invocation_contract_registry.ts"],
|
|
46
|
+
test_files: ["tests/engine/tool_invocation_contract_registry.test.ts"],
|
|
47
|
+
lifecycle_test_files: ["tests/engine/tool_invocation_contract_registry.test.ts"],
|
|
48
|
+
knowledge_refs: ["templates/knowledge/rules/工具调用规则.md"],
|
|
49
|
+
prompt_refs: [],
|
|
50
|
+
depends_on: ["workflow_contract"],
|
|
51
|
+
consumed_by: ["main_path_integration_contract"],
|
|
52
|
+
hard_fail_allowed: true,
|
|
53
|
+
promotion_conditions: ["所有 MCP tool 有 invocation test"],
|
|
54
|
+
demotion_conditions: ["tool invocation regression 漏检"],
|
|
55
|
+
evidence_requirements: ["validateToolInvocation 无 hard_fail"],
|
|
56
|
+
policy_id: "CAP-022",
|
|
57
|
+
capability_ids: ["tool_invocation_contract"],
|
|
58
|
+
},
|
|
59
|
+
// ── 3. 机制契约 ──
|
|
60
|
+
{
|
|
61
|
+
contract_id: "mechanism_contract",
|
|
62
|
+
kind: "mechanism_family",
|
|
63
|
+
name: "机制契约",
|
|
64
|
+
state: "enforced",
|
|
65
|
+
owner_component: "engine/mechanism_contract_registry",
|
|
66
|
+
owner_files: ["src/engine/mechanism_contract_registry.ts"],
|
|
67
|
+
test_files: ["tests/engine/mechanism_contract_registry.test.ts"],
|
|
68
|
+
lifecycle_test_files: ["tests/engine/mechanism_contract_registry.test.ts"],
|
|
69
|
+
knowledge_refs: [],
|
|
70
|
+
prompt_refs: [],
|
|
71
|
+
depends_on: ["workflow_contract", "tool_invocation_contract"],
|
|
72
|
+
consumed_by: ["main_path_integration_contract"],
|
|
73
|
+
hard_fail_allowed: true,
|
|
74
|
+
promotion_conditions: ["所有 P0 机制有 lifecycle test"],
|
|
75
|
+
demotion_conditions: ["机制 regression check 漏检"],
|
|
76
|
+
evidence_requirements: ["validateMechanismContracts 无 hard_fail"],
|
|
77
|
+
},
|
|
78
|
+
// ── 4. 产物契约 ──
|
|
79
|
+
{
|
|
80
|
+
contract_id: "artifact_contract",
|
|
81
|
+
kind: "delivery",
|
|
82
|
+
name: "产物契约",
|
|
83
|
+
state: "enforced",
|
|
84
|
+
owner_component: "engine/artifact_contract_registry",
|
|
85
|
+
owner_files: ["src/engine/artifact_contract_registry.ts"],
|
|
86
|
+
test_files: ["tests/engine/artifact_contract_registry.test.ts"],
|
|
87
|
+
lifecycle_test_files: ["tests/engine/artifact_contract_registry.test.ts"],
|
|
88
|
+
knowledge_refs: [],
|
|
89
|
+
prompt_refs: [],
|
|
90
|
+
depends_on: ["workflow_contract"],
|
|
91
|
+
consumed_by: ["main_path_integration_contract"],
|
|
92
|
+
hard_fail_allowed: true,
|
|
93
|
+
promotion_conditions: ["所有 artifact kind 有测试"],
|
|
94
|
+
demotion_conditions: ["artifact regression 漏检"],
|
|
95
|
+
evidence_requirements: ["validateArtifactContracts 无 hard_fail"],
|
|
96
|
+
},
|
|
97
|
+
// ── 5. 输入物料契约 ──
|
|
98
|
+
{
|
|
99
|
+
contract_id: "input_material_contract",
|
|
100
|
+
kind: "verification",
|
|
101
|
+
name: "输入物料契约",
|
|
102
|
+
state: "enforced",
|
|
103
|
+
owner_component: "engine/input_material_contract_registry",
|
|
104
|
+
owner_files: ["src/engine/input_material_contract_registry.ts"],
|
|
105
|
+
test_files: ["tests/engine/input_material_contract_registry.test.ts"],
|
|
106
|
+
lifecycle_test_files: ["tests/engine/input_material_contract_registry.test.ts"],
|
|
107
|
+
knowledge_refs: [],
|
|
108
|
+
prompt_refs: [],
|
|
109
|
+
depends_on: ["privacy_secret_contract"],
|
|
110
|
+
consumed_by: ["workflow_contract", "main_path_integration_contract"],
|
|
111
|
+
hard_fail_allowed: true,
|
|
112
|
+
promotion_conditions: ["所有 material kind 有测试"],
|
|
113
|
+
demotion_conditions: ["material regression 漏检"],
|
|
114
|
+
evidence_requirements: ["input material contract 验证通过"],
|
|
115
|
+
},
|
|
116
|
+
// ── 6. 命令执行契约 ──
|
|
117
|
+
{
|
|
118
|
+
contract_id: "command_execution_contract",
|
|
119
|
+
kind: "guard",
|
|
120
|
+
name: "命令执行契约",
|
|
121
|
+
state: "enforced",
|
|
122
|
+
owner_component: "engine/command_execution_contract",
|
|
123
|
+
owner_files: ["src/engine/command_execution_contract.ts"],
|
|
124
|
+
test_files: ["tests/engine/command_execution_contract.test.ts"],
|
|
125
|
+
lifecycle_test_files: ["tests/engine/command_execution_contract.test.ts"],
|
|
126
|
+
knowledge_refs: ["templates/knowledge/rules/命令执行规则.md"],
|
|
127
|
+
prompt_refs: [],
|
|
128
|
+
depends_on: ["tool_invocation_contract"],
|
|
129
|
+
consumed_by: ["main_path_integration_contract"],
|
|
130
|
+
hard_fail_allowed: true,
|
|
131
|
+
promotion_conditions: ["覆盖所有 destructive 命令模式"],
|
|
132
|
+
demotion_conditions: ["destructive 命令漏检"],
|
|
133
|
+
evidence_requirements: ["命令分级测试通过"],
|
|
134
|
+
policy_id: "CAP-025",
|
|
135
|
+
capability_ids: ["command_execution"],
|
|
136
|
+
},
|
|
137
|
+
// ── 7. 隐私/敏感信息契约 ──
|
|
138
|
+
{
|
|
139
|
+
contract_id: "privacy_secret_contract",
|
|
140
|
+
kind: "guard",
|
|
141
|
+
name: "隐私/敏感信息契约",
|
|
142
|
+
state: "enforced",
|
|
143
|
+
owner_component: "engine/privacy_secret_contract",
|
|
144
|
+
owner_files: ["src/engine/privacy_secret_contract.ts"],
|
|
145
|
+
test_files: ["tests/engine/privacy_secret_contract.test.ts"],
|
|
146
|
+
lifecycle_test_files: ["tests/engine/privacy_secret_contract.test.ts"],
|
|
147
|
+
knowledge_refs: ["templates/knowledge/rules/敏感信息处理规则.md"],
|
|
148
|
+
prompt_refs: [],
|
|
149
|
+
depends_on: [],
|
|
150
|
+
consumed_by: ["input_material_contract", "main_path_integration_contract"],
|
|
151
|
+
hard_fail_allowed: true,
|
|
152
|
+
promotion_conditions: ["覆盖所有 PII 类型"],
|
|
153
|
+
demotion_conditions: ["secret scanner 产生大量误报"],
|
|
154
|
+
evidence_requirements: ["RedactionRecord 测试通过"],
|
|
155
|
+
policy_id: "CAP-024",
|
|
156
|
+
capability_ids: ["privacy_secret"],
|
|
157
|
+
},
|
|
158
|
+
// ── 8. 配置优先级契约 ──
|
|
159
|
+
{
|
|
160
|
+
contract_id: "config_precedence_contract",
|
|
161
|
+
kind: "guard",
|
|
162
|
+
name: "配置优先级契约",
|
|
163
|
+
state: "enforced",
|
|
164
|
+
owner_component: "engine/config_precedence_contract",
|
|
165
|
+
owner_files: ["src/engine/config_precedence_contract.ts"],
|
|
166
|
+
test_files: ["tests/engine/config_precedence_contract.test.ts"],
|
|
167
|
+
lifecycle_test_files: ["tests/engine/config_precedence_contract.test.ts"],
|
|
168
|
+
knowledge_refs: [],
|
|
169
|
+
prompt_refs: [],
|
|
170
|
+
depends_on: [],
|
|
171
|
+
consumed_by: ["main_path_integration_contract"],
|
|
172
|
+
hard_fail_allowed: true,
|
|
173
|
+
promotion_conditions: ["所有优先级冲突有测试"],
|
|
174
|
+
demotion_conditions: ["优先级回归漏检"],
|
|
175
|
+
evidence_requirements: ["validateConfigPrecedence 无 hard_fail"],
|
|
176
|
+
},
|
|
177
|
+
// ── 9. 用户反馈契约 ──
|
|
178
|
+
{
|
|
179
|
+
contract_id: "user_feedback_contract",
|
|
180
|
+
kind: "delivery",
|
|
181
|
+
name: "用户反馈契约",
|
|
182
|
+
state: "enforced",
|
|
183
|
+
owner_component: "engine/user_feedback_contract",
|
|
184
|
+
owner_files: ["src/engine/user_feedback_contract.ts"],
|
|
185
|
+
test_files: ["tests/engine/user_feedback_contract.test.ts"],
|
|
186
|
+
lifecycle_test_files: ["tests/engine/user_feedback_contract.test.ts"],
|
|
187
|
+
knowledge_refs: [],
|
|
188
|
+
prompt_refs: [],
|
|
189
|
+
depends_on: [],
|
|
190
|
+
consumed_by: ["main_path_integration_contract"],
|
|
191
|
+
hard_fail_allowed: true,
|
|
192
|
+
promotion_conditions: ["所有反馈类型有测试"],
|
|
193
|
+
demotion_conditions: ["反馈回归漏检"],
|
|
194
|
+
evidence_requirements: ["用户反馈契约验证通过"],
|
|
195
|
+
},
|
|
196
|
+
// ── 10. 主链路接入契约 ──
|
|
197
|
+
{
|
|
198
|
+
contract_id: "main_path_integration_contract",
|
|
199
|
+
kind: "verification",
|
|
200
|
+
name: "主链路接入防孤岛契约",
|
|
201
|
+
state: "enforced",
|
|
202
|
+
owner_component: "engine/main_path_integration_contract",
|
|
203
|
+
owner_files: ["src/engine/main_path_integration_contract.ts"],
|
|
204
|
+
test_files: ["tests/engine/main_path_integration_contract.test.ts"],
|
|
205
|
+
lifecycle_test_files: ["tests/engine/main_path_integration_contract.test.ts"],
|
|
206
|
+
knowledge_refs: ["templates/knowledge/rules/防孤岛实现规则.md"],
|
|
207
|
+
prompt_refs: [],
|
|
208
|
+
depends_on: [
|
|
209
|
+
"workflow_contract",
|
|
210
|
+
"tool_invocation_contract",
|
|
211
|
+
"mechanism_contract",
|
|
212
|
+
"artifact_contract",
|
|
213
|
+
],
|
|
214
|
+
consumed_by: ["contract_governance"],
|
|
215
|
+
hard_fail_allowed: true,
|
|
216
|
+
promotion_conditions: ["所有 enforced 模块有 entry trace"],
|
|
217
|
+
demotion_conditions: ["orphan scan 产生大量误报"],
|
|
218
|
+
evidence_requirements: ["validateMainPathIntegration 无 hard_fail"],
|
|
219
|
+
policy_id: "CAP-023",
|
|
220
|
+
capability_ids: ["main_path_integration"],
|
|
221
|
+
},
|
|
222
|
+
// ── 11. 路由决策契约 ──
|
|
223
|
+
{
|
|
224
|
+
contract_id: "route_decision_contract",
|
|
225
|
+
kind: "workflow",
|
|
226
|
+
name: "路由决策契约",
|
|
227
|
+
state: "enforced",
|
|
228
|
+
owner_component: "engine/route_decision_contract_verifier",
|
|
229
|
+
owner_files: ["src/engine/route_decision_contract_verifier.ts"],
|
|
230
|
+
test_files: ["tests/engine/route_decision_contract.test.ts"],
|
|
231
|
+
lifecycle_test_files: ["tests/engine/route_decision_contract.test.ts"],
|
|
232
|
+
knowledge_refs: [],
|
|
233
|
+
prompt_refs: [],
|
|
234
|
+
depends_on: [],
|
|
235
|
+
consumed_by: ["workflow_contract"],
|
|
236
|
+
hard_fail_allowed: true,
|
|
237
|
+
promotion_conditions: ["所有路由决策有测试"],
|
|
238
|
+
demotion_conditions: ["路由决策回归漏检"],
|
|
239
|
+
evidence_requirements: ["verifyRouteDecisionContract 无 hard_fail"],
|
|
240
|
+
},
|
|
241
|
+
// ── 12. 契约治理契约(问题二十自治理) ──
|
|
242
|
+
{
|
|
243
|
+
contract_id: "contract_governance",
|
|
244
|
+
kind: "verification",
|
|
245
|
+
name: "契约治理契约",
|
|
246
|
+
state: "enforced",
|
|
247
|
+
owner_component: "engine/contract_registry",
|
|
248
|
+
owner_files: ["src/engine/contract_registry.ts"],
|
|
249
|
+
test_files: ["tests/engine/contract_registry.test.ts"],
|
|
250
|
+
lifecycle_test_files: ["tests/engine/contract_registry.test.ts"],
|
|
251
|
+
knowledge_refs: [],
|
|
252
|
+
prompt_refs: [],
|
|
253
|
+
depends_on: [
|
|
254
|
+
"main_path_integration_contract",
|
|
255
|
+
"workflow_contract",
|
|
256
|
+
"tool_invocation_contract",
|
|
257
|
+
],
|
|
258
|
+
consumed_by: [],
|
|
259
|
+
hard_fail_allowed: true,
|
|
260
|
+
promotion_conditions: ["所有核心契约已在 Unified Contract Registry 登记"],
|
|
261
|
+
demotion_conditions: ["契约治理检查产生大量误报"],
|
|
262
|
+
evidence_requirements: [
|
|
263
|
+
"validateContractRegistry 无 hard_fail",
|
|
264
|
+
"所有核心 contract 已登记",
|
|
265
|
+
"policy_id 到 contract_id 映射完整",
|
|
266
|
+
],
|
|
267
|
+
},
|
|
268
|
+
// ── 13. 知识注入契约 ──
|
|
269
|
+
{
|
|
270
|
+
contract_id: "knowledge_injection_contract",
|
|
271
|
+
kind: "knowledge_injection",
|
|
272
|
+
name: "知识注入契约",
|
|
273
|
+
state: "advisory",
|
|
274
|
+
owner_component: "engine/knowledge_injection_boundary",
|
|
275
|
+
owner_files: ["src/engine/knowledge_injection_boundary.ts"],
|
|
276
|
+
test_files: ["tests/engine/knowledge_injection_boundary.test.ts"],
|
|
277
|
+
lifecycle_test_files: [],
|
|
278
|
+
knowledge_refs: [],
|
|
279
|
+
prompt_refs: [],
|
|
280
|
+
depends_on: ["workflow_contract"],
|
|
281
|
+
consumed_by: ["main_path_integration_contract"],
|
|
282
|
+
hard_fail_allowed: false,
|
|
283
|
+
promotion_conditions: ["知识注入边界有完整集成测试"],
|
|
284
|
+
demotion_conditions: ["知识注入产生安全逃逸"],
|
|
285
|
+
evidence_requirements: ["knowledge injection boundary 测试通过"],
|
|
286
|
+
},
|
|
287
|
+
// ── 14. 失败/恢复契约 ──
|
|
288
|
+
{
|
|
289
|
+
contract_id: "failure_recovery_contract",
|
|
290
|
+
kind: "failure",
|
|
291
|
+
name: "失败/恢复契约",
|
|
292
|
+
state: "advisory",
|
|
293
|
+
owner_component: "engine/failure_classifier",
|
|
294
|
+
owner_files: ["src/engine/failure_classifier.ts"],
|
|
295
|
+
test_files: ["tests/engine/failure_classifier.test.ts"],
|
|
296
|
+
lifecycle_test_files: [],
|
|
297
|
+
knowledge_refs: [],
|
|
298
|
+
prompt_refs: [],
|
|
299
|
+
depends_on: ["workflow_contract"],
|
|
300
|
+
consumed_by: ["main_path_integration_contract"],
|
|
301
|
+
hard_fail_allowed: false,
|
|
302
|
+
promotion_conditions: ["所有失败分类有恢复策略测试"],
|
|
303
|
+
demotion_conditions: ["失败恢复逻辑产生误判"],
|
|
304
|
+
evidence_requirements: ["failure classifier 测试通过"],
|
|
305
|
+
},
|
|
306
|
+
// ── 15. 降级契约 ──
|
|
307
|
+
{
|
|
308
|
+
contract_id: "degradation_contract",
|
|
309
|
+
kind: "degradation",
|
|
310
|
+
name: "降级契约",
|
|
311
|
+
state: "advisory",
|
|
312
|
+
owner_component: "engine/runtime_safety",
|
|
313
|
+
owner_files: ["src/engine/runtime_safety.ts"],
|
|
314
|
+
test_files: ["tests/engine/runtime_safety.test.ts"],
|
|
315
|
+
lifecycle_test_files: [],
|
|
316
|
+
knowledge_refs: [],
|
|
317
|
+
prompt_refs: [],
|
|
318
|
+
depends_on: ["failure_recovery_contract"],
|
|
319
|
+
consumed_by: ["main_path_integration_contract"],
|
|
320
|
+
hard_fail_allowed: false,
|
|
321
|
+
promotion_conditions: ["降级事件用户可见测试通过"],
|
|
322
|
+
demotion_conditions: ["降级逻辑产生误判"],
|
|
323
|
+
evidence_requirements: ["runtime safety 测试通过"],
|
|
324
|
+
},
|
|
325
|
+
// ── 16. 指标契约 ──
|
|
326
|
+
{
|
|
327
|
+
contract_id: "metric_contract",
|
|
328
|
+
kind: "metric",
|
|
329
|
+
name: "指标契约",
|
|
330
|
+
state: "advisory",
|
|
331
|
+
owner_component: "engine/observability",
|
|
332
|
+
owner_files: ["src/engine/observability.ts"],
|
|
333
|
+
test_files: ["tests/engine/observability.test.ts"],
|
|
334
|
+
lifecycle_test_files: [],
|
|
335
|
+
knowledge_refs: [],
|
|
336
|
+
prompt_refs: [],
|
|
337
|
+
depends_on: [],
|
|
338
|
+
consumed_by: ["main_path_integration_contract"],
|
|
339
|
+
hard_fail_allowed: false,
|
|
340
|
+
promotion_conditions: ["所有治理指标有采集和聚合测试"],
|
|
341
|
+
demotion_conditions: ["指标采集影响性能"],
|
|
342
|
+
evidence_requirements: ["observability 测试通过"],
|
|
343
|
+
},
|
|
344
|
+
// ── 17. 语言策略契约 ──
|
|
345
|
+
{
|
|
346
|
+
contract_id: "language_policy_contract",
|
|
347
|
+
kind: "language_policy",
|
|
348
|
+
name: "语言策略契约",
|
|
349
|
+
state: "advisory",
|
|
350
|
+
owner_component: "engine/core_engineering_principles",
|
|
351
|
+
owner_files: ["src/engine/core_engineering_principles.ts"],
|
|
352
|
+
test_files: ["tests/engine/core_engineering_principles.test.ts"],
|
|
353
|
+
lifecycle_test_files: [],
|
|
354
|
+
knowledge_refs: [],
|
|
355
|
+
prompt_refs: [],
|
|
356
|
+
depends_on: [],
|
|
357
|
+
consumed_by: ["main_path_integration_contract"],
|
|
358
|
+
hard_fail_allowed: false,
|
|
359
|
+
promotion_conditions: ["中文语义优先覆盖所有用户可见路径"],
|
|
360
|
+
demotion_conditions: ["语言策略产生误判阻断"],
|
|
361
|
+
evidence_requirements: ["core engineering principles 测试通过"],
|
|
362
|
+
},
|
|
363
|
+
// ── 18. 任务上下文契约 ──
|
|
364
|
+
{
|
|
365
|
+
contract_id: "task_context_contract",
|
|
366
|
+
kind: "task_context",
|
|
367
|
+
name: "任务上下文契约",
|
|
368
|
+
state: "enforced",
|
|
369
|
+
owner_component: "engine/task_context",
|
|
370
|
+
owner_files: ["src/engine/task_context.ts"],
|
|
371
|
+
test_files: ["tests/engine/task_context.test.ts"],
|
|
372
|
+
lifecycle_test_files: ["tests/engine/task_context.test.ts"],
|
|
373
|
+
knowledge_refs: [],
|
|
374
|
+
prompt_refs: [],
|
|
375
|
+
depends_on: [],
|
|
376
|
+
consumed_by: ["workflow_contract", "main_path_integration_contract"],
|
|
377
|
+
hard_fail_allowed: true,
|
|
378
|
+
promotion_conditions: ["TaskContext 生命周期测试覆盖所有状态转移"],
|
|
379
|
+
demotion_conditions: ["TaskContext 逃逸(绕过状态机)"],
|
|
380
|
+
evidence_requirements: ["task_context 生命周期测试通过"],
|
|
381
|
+
policy_id: "CAP-001",
|
|
382
|
+
capability_ids: ["task_context_lifecycle"],
|
|
383
|
+
},
|
|
384
|
+
// ── 19. 技术决策契约 ──
|
|
385
|
+
{
|
|
386
|
+
contract_id: "technology_decision_contract",
|
|
387
|
+
kind: "technology_decision",
|
|
388
|
+
name: "技术决策契约",
|
|
389
|
+
state: "advisory",
|
|
390
|
+
owner_component: "engine/decision_contract",
|
|
391
|
+
owner_files: ["src/engine/decision_contract.ts"],
|
|
392
|
+
test_files: ["tests/engine/decision_contract.test.ts"],
|
|
393
|
+
lifecycle_test_files: [],
|
|
394
|
+
knowledge_refs: [],
|
|
395
|
+
prompt_refs: [],
|
|
396
|
+
depends_on: [],
|
|
397
|
+
consumed_by: ["main_path_integration_contract"],
|
|
398
|
+
hard_fail_allowed: false,
|
|
399
|
+
promotion_conditions: ["技术决策字段覆盖所有关键维度"],
|
|
400
|
+
demotion_conditions: ["决策字段冗余影响可读性"],
|
|
401
|
+
evidence_requirements: ["decision contract 测试通过"],
|
|
402
|
+
},
|
|
403
|
+
// ── 20. 知识演化契约 ──
|
|
404
|
+
{
|
|
405
|
+
contract_id: "knowledge_evolution_contract",
|
|
406
|
+
kind: "knowledge_evolution",
|
|
407
|
+
name: "知识演化契约",
|
|
408
|
+
state: "advisory",
|
|
409
|
+
owner_component: "engine/knowledge_sovereignty",
|
|
410
|
+
owner_files: ["src/engine/knowledge_sovereignty.ts"],
|
|
411
|
+
test_files: ["tests/engine/knowledge_sovereignty.test.ts"],
|
|
412
|
+
lifecycle_test_files: [],
|
|
413
|
+
knowledge_refs: [],
|
|
414
|
+
prompt_refs: [],
|
|
415
|
+
depends_on: ["knowledge_injection_contract"],
|
|
416
|
+
consumed_by: ["main_path_integration_contract"],
|
|
417
|
+
hard_fail_allowed: false,
|
|
418
|
+
promotion_conditions: ["知识演化生命周期有完整测试"],
|
|
419
|
+
demotion_conditions: ["知识演化逻辑产生误判"],
|
|
420
|
+
evidence_requirements: ["knowledge sovereignty 测试通过"],
|
|
421
|
+
},
|
|
422
|
+
// ── 21. 诊断码契约 ──
|
|
423
|
+
{
|
|
424
|
+
contract_id: "diagnostic_code_contract",
|
|
425
|
+
kind: "guard",
|
|
426
|
+
name: "诊断码契约",
|
|
427
|
+
state: "enforced",
|
|
428
|
+
owner_component: "engine/diagnostic_registry",
|
|
429
|
+
owner_files: ["src/engine/diagnostic_registry.ts"],
|
|
430
|
+
test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
431
|
+
lifecycle_test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
432
|
+
knowledge_refs: [],
|
|
433
|
+
prompt_refs: [],
|
|
434
|
+
depends_on: ["contract_governance"],
|
|
435
|
+
consumed_by: ["main_path_integration_contract"],
|
|
436
|
+
hard_fail_allowed: true,
|
|
437
|
+
promotion_conditions: ["所有 blocking/critical 事件有诊断码"],
|
|
438
|
+
demotion_conditions: ["诊断码检查产生大量误报"],
|
|
439
|
+
evidence_requirements: ["diagnostic registry 测试通过"],
|
|
440
|
+
},
|
|
441
|
+
// ── 22. 强制护栏契约 ──
|
|
442
|
+
{
|
|
443
|
+
contract_id: "enforcement_guard_contract",
|
|
444
|
+
kind: "guard",
|
|
445
|
+
name: "强制护栏契约",
|
|
446
|
+
state: "enforced",
|
|
447
|
+
owner_component: "engine/enforcement_guard",
|
|
448
|
+
owner_files: ["src/engine/enforcement_guard.ts"],
|
|
449
|
+
test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
450
|
+
lifecycle_test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
451
|
+
knowledge_refs: [],
|
|
452
|
+
prompt_refs: [],
|
|
453
|
+
depends_on: ["diagnostic_code_contract", "command_execution_contract"],
|
|
454
|
+
consumed_by: ["main_path_integration_contract"],
|
|
455
|
+
hard_fail_allowed: true,
|
|
456
|
+
promotion_conditions: ["覆盖七类护栏且有 must-fail 测试"],
|
|
457
|
+
demotion_conditions: ["护栏阻断产生大量误报"],
|
|
458
|
+
evidence_requirements: ["enforcement guard 测试通过"],
|
|
459
|
+
},
|
|
460
|
+
// ── 23. 验证契约 ──
|
|
461
|
+
{
|
|
462
|
+
contract_id: "verification_contract",
|
|
463
|
+
kind: "verification",
|
|
464
|
+
name: "验证契约",
|
|
465
|
+
state: "enforced",
|
|
466
|
+
owner_component: "engine/verification_contract",
|
|
467
|
+
owner_files: ["src/engine/verification_contract.ts"],
|
|
468
|
+
test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
469
|
+
lifecycle_test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
470
|
+
knowledge_refs: [],
|
|
471
|
+
prompt_refs: [],
|
|
472
|
+
depends_on: ["main_path_integration_contract"],
|
|
473
|
+
consumed_by: ["delivery_readiness_contract"],
|
|
474
|
+
hard_fail_allowed: true,
|
|
475
|
+
promotion_conditions: ["VerificationPlan 与 VerificationEvidence 分离有测试"],
|
|
476
|
+
demotion_conditions: ["验证契约检查产生大量误报"],
|
|
477
|
+
evidence_requirements: ["verification contract 测试通过"],
|
|
478
|
+
},
|
|
479
|
+
// ── 24. 交付就绪契约 ──
|
|
480
|
+
{
|
|
481
|
+
contract_id: "delivery_readiness_contract",
|
|
482
|
+
kind: "delivery",
|
|
483
|
+
name: "交付就绪契约",
|
|
484
|
+
state: "enforced",
|
|
485
|
+
owner_component: "engine/delivery_readiness",
|
|
486
|
+
owner_files: ["src/engine/delivery_readiness.ts"],
|
|
487
|
+
test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
488
|
+
lifecycle_test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
489
|
+
knowledge_refs: [],
|
|
490
|
+
prompt_refs: [],
|
|
491
|
+
depends_on: ["verification_contract", "enforcement_guard_contract"],
|
|
492
|
+
consumed_by: ["main_path_integration_contract"],
|
|
493
|
+
hard_fail_allowed: true,
|
|
494
|
+
promotion_conditions: ["交付许可不触发交付执行有测试"],
|
|
495
|
+
demotion_conditions: ["交付门控产生大量误报"],
|
|
496
|
+
evidence_requirements: ["delivery readiness 测试通过"],
|
|
497
|
+
},
|
|
498
|
+
// ── 25. 失败报告契约 ──
|
|
499
|
+
{
|
|
500
|
+
contract_id: "failure_report_contract",
|
|
501
|
+
kind: "failure",
|
|
502
|
+
name: "失败报告契约",
|
|
503
|
+
state: "enforced",
|
|
504
|
+
owner_component: "engine/failure_report",
|
|
505
|
+
owner_files: ["src/engine/failure_report.ts"],
|
|
506
|
+
test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
507
|
+
lifecycle_test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
508
|
+
knowledge_refs: [],
|
|
509
|
+
prompt_refs: [],
|
|
510
|
+
depends_on: ["diagnostic_code_contract", "failure_recovery_contract"],
|
|
511
|
+
consumed_by: ["main_path_integration_contract"],
|
|
512
|
+
hard_fail_allowed: true,
|
|
513
|
+
promotion_conditions: ["所有 FailureClass 有恢复策略和测试"],
|
|
514
|
+
demotion_conditions: ["失败分类产生大量误判"],
|
|
515
|
+
evidence_requirements: ["failure report 测试通过"],
|
|
516
|
+
},
|
|
517
|
+
// ── 26. 降级契约 ──
|
|
518
|
+
{
|
|
519
|
+
contract_id: "degradation_event_contract",
|
|
520
|
+
kind: "degradation",
|
|
521
|
+
name: "降级事件契约",
|
|
522
|
+
state: "enforced",
|
|
523
|
+
owner_component: "engine/degradation",
|
|
524
|
+
owner_files: ["src/engine/degradation.ts"],
|
|
525
|
+
test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
526
|
+
lifecycle_test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
527
|
+
knowledge_refs: [],
|
|
528
|
+
prompt_refs: [],
|
|
529
|
+
depends_on: ["diagnostic_code_contract"],
|
|
530
|
+
consumed_by: ["main_path_integration_contract"],
|
|
531
|
+
hard_fail_allowed: true,
|
|
532
|
+
promotion_conditions: ["降级事件用户可见有测试"],
|
|
533
|
+
demotion_conditions: ["降级检查产生大量误报"],
|
|
534
|
+
evidence_requirements: ["degradation 测试通过"],
|
|
535
|
+
},
|
|
536
|
+
// ── 27. 工作区隔离契约 ──
|
|
537
|
+
{
|
|
538
|
+
contract_id: "workspace_isolation_contract",
|
|
539
|
+
kind: "guard",
|
|
540
|
+
name: "工作区隔离契约",
|
|
541
|
+
state: "enforced",
|
|
542
|
+
owner_component: "engine/workspace_lease",
|
|
543
|
+
owner_files: ["src/engine/workspace_lease.ts"],
|
|
544
|
+
test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
545
|
+
lifecycle_test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
546
|
+
knowledge_refs: [],
|
|
547
|
+
prompt_refs: [],
|
|
548
|
+
depends_on: ["diagnostic_code_contract"],
|
|
549
|
+
consumed_by: ["main_path_integration_contract"],
|
|
550
|
+
hard_fail_allowed: true,
|
|
551
|
+
promotion_conditions: ["并发冲突检测有测试"],
|
|
552
|
+
demotion_conditions: ["lease 冲突检测产生大量误报"],
|
|
553
|
+
evidence_requirements: ["workspace lease 测试通过"],
|
|
554
|
+
},
|
|
555
|
+
// ── 28. 测试策略契约 ──
|
|
556
|
+
{
|
|
557
|
+
contract_id: "test_strategy_contract",
|
|
558
|
+
kind: "verification",
|
|
559
|
+
name: "测试策略契约",
|
|
560
|
+
state: "advisory",
|
|
561
|
+
owner_component: "engine/test_strategy",
|
|
562
|
+
owner_files: ["src/engine/test_strategy.ts"],
|
|
563
|
+
test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
564
|
+
lifecycle_test_files: [],
|
|
565
|
+
knowledge_refs: [],
|
|
566
|
+
prompt_refs: [],
|
|
567
|
+
depends_on: ["contract_governance"],
|
|
568
|
+
consumed_by: ["main_path_integration_contract"],
|
|
569
|
+
hard_fail_allowed: false,
|
|
570
|
+
promotion_conditions: ["enforced contract lifecycle test 覆盖完整"],
|
|
571
|
+
demotion_conditions: ["测试策略检查产生大量误报"],
|
|
572
|
+
evidence_requirements: ["test strategy 测试通过"],
|
|
573
|
+
},
|
|
574
|
+
// ── 29. 机制族映射契约 ──
|
|
575
|
+
{
|
|
576
|
+
contract_id: "mechanism_family_contract",
|
|
577
|
+
kind: "mechanism_family",
|
|
578
|
+
name: "机制族映射契约",
|
|
579
|
+
state: "advisory",
|
|
580
|
+
owner_component: "engine/mechanism_family_registry",
|
|
581
|
+
owner_files: ["src/engine/mechanism_family_registry.ts"],
|
|
582
|
+
test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
583
|
+
lifecycle_test_files: [],
|
|
584
|
+
knowledge_refs: [],
|
|
585
|
+
prompt_refs: [],
|
|
586
|
+
depends_on: ["contract_governance"],
|
|
587
|
+
consumed_by: ["main_path_integration_contract"],
|
|
588
|
+
hard_fail_allowed: false,
|
|
589
|
+
promotion_conditions: ["所有设计机制族有 owner module 和测试"],
|
|
590
|
+
demotion_conditions: ["机制族映射产生大量误报"],
|
|
591
|
+
evidence_requirements: ["mechanism family registry 测试通过"],
|
|
592
|
+
},
|
|
593
|
+
// ── 30. 语言策略契约 ──
|
|
594
|
+
{
|
|
595
|
+
contract_id: "language_policy_contract_entry",
|
|
596
|
+
kind: "language_policy",
|
|
597
|
+
name: "语言策略契约",
|
|
598
|
+
state: "advisory",
|
|
599
|
+
owner_component: "engine/language_policy_contract",
|
|
600
|
+
owner_files: ["src/engine/language_policy_contract.ts"],
|
|
601
|
+
test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
602
|
+
lifecycle_test_files: [],
|
|
603
|
+
knowledge_refs: [],
|
|
604
|
+
prompt_refs: [],
|
|
605
|
+
depends_on: [],
|
|
606
|
+
consumed_by: ["main_path_integration_contract"],
|
|
607
|
+
hard_fail_allowed: false,
|
|
608
|
+
promotion_conditions: ["中文语义覆盖所有用户可见路径"],
|
|
609
|
+
demotion_conditions: ["语言策略产生误判阻断"],
|
|
610
|
+
evidence_requirements: ["language policy 测试通过"],
|
|
611
|
+
},
|
|
612
|
+
// ── 31. 保留策略契约 ──
|
|
613
|
+
{
|
|
614
|
+
contract_id: "retention_policy_contract",
|
|
615
|
+
kind: "knowledge_evolution",
|
|
616
|
+
name: "保留策略契约",
|
|
617
|
+
state: "advisory",
|
|
618
|
+
owner_component: "engine/retention_policy",
|
|
619
|
+
owner_files: ["src/engine/retention_policy.ts"],
|
|
620
|
+
test_files: ["tests/engine/batch2_scenario_matrix.test.ts"],
|
|
621
|
+
lifecycle_test_files: [],
|
|
622
|
+
knowledge_refs: [],
|
|
623
|
+
prompt_refs: [],
|
|
624
|
+
depends_on: [],
|
|
625
|
+
consumed_by: ["main_path_integration_contract"],
|
|
626
|
+
hard_fail_allowed: false,
|
|
627
|
+
promotion_conditions: ["所有记录类型有保留策略"],
|
|
628
|
+
demotion_conditions: ["清理策略删除仍被引用的 evidence"],
|
|
629
|
+
evidence_requirements: ["retention policy 测试通过"],
|
|
630
|
+
},
|
|
631
|
+
];
|
|
632
|
+
// ── 运行时注册表(允许动态添加,用于测试和扩展) ──
|
|
633
|
+
let runtimeEntries = null;
|
|
634
|
+
function getRegistry() {
|
|
635
|
+
if (!runtimeEntries) {
|
|
636
|
+
runtimeEntries = new Map();
|
|
637
|
+
for (const entry of BUILTIN_CONTRACTS) {
|
|
638
|
+
runtimeEntries.set(entry.contract_id, cloneEntry(entry));
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return runtimeEntries;
|
|
642
|
+
}
|
|
643
|
+
function cloneEntry(e) {
|
|
644
|
+
return {
|
|
645
|
+
...e,
|
|
646
|
+
owner_files: [...e.owner_files],
|
|
647
|
+
test_files: [...e.test_files],
|
|
648
|
+
lifecycle_test_files: [...e.lifecycle_test_files],
|
|
649
|
+
knowledge_refs: [...e.knowledge_refs],
|
|
650
|
+
prompt_refs: [...e.prompt_refs],
|
|
651
|
+
depends_on: [...e.depends_on],
|
|
652
|
+
consumed_by: [...e.consumed_by],
|
|
653
|
+
promotion_conditions: [...e.promotion_conditions],
|
|
654
|
+
demotion_conditions: [...e.demotion_conditions],
|
|
655
|
+
evidence_requirements: [...e.evidence_requirements],
|
|
656
|
+
capability_ids: e.capability_ids ? [...e.capability_ids] : undefined,
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
// ── 查询函数 ──
|
|
660
|
+
/** 获取所有契约条目 */
|
|
661
|
+
export function getAllContracts() {
|
|
662
|
+
return [...getRegistry().values()].map(cloneEntry);
|
|
663
|
+
}
|
|
664
|
+
/** 按 contract_id 获取 */
|
|
665
|
+
export function getContractById(id) {
|
|
666
|
+
const entry = getRegistry().get(id);
|
|
667
|
+
return entry ? cloneEntry(entry) : undefined;
|
|
668
|
+
}
|
|
669
|
+
/** 按 policy_id 查找对应 contract_id */
|
|
670
|
+
export function getContractByPolicyId(policyId) {
|
|
671
|
+
for (const entry of getRegistry().values()) {
|
|
672
|
+
if (entry.policy_id === policyId)
|
|
673
|
+
return cloneEntry(entry);
|
|
674
|
+
}
|
|
675
|
+
return undefined;
|
|
676
|
+
}
|
|
677
|
+
/** 按类型列出契约 */
|
|
678
|
+
export function listContractsByKind(kind) {
|
|
679
|
+
return [...getRegistry().values()]
|
|
680
|
+
.filter((e) => e.kind === kind)
|
|
681
|
+
.map(cloneEntry);
|
|
682
|
+
}
|
|
683
|
+
/** 按状态列出契约 */
|
|
684
|
+
export function listContractsByState(state) {
|
|
685
|
+
return [...getRegistry().values()]
|
|
686
|
+
.filter((e) => e.state === state)
|
|
687
|
+
.map(cloneEntry);
|
|
688
|
+
}
|
|
689
|
+
/** 列出所有契约 */
|
|
690
|
+
export function listContracts() {
|
|
691
|
+
return getAllContracts();
|
|
692
|
+
}
|
|
693
|
+
/** 注册表汇总统计 */
|
|
694
|
+
export function getContractRegistrySummary() {
|
|
695
|
+
const entries = [...getRegistry().values()];
|
|
696
|
+
const ALL_KINDS = [
|
|
697
|
+
"capability", "mechanism_family", "workflow", "guard",
|
|
698
|
+
"knowledge_injection", "verification", "delivery", "failure",
|
|
699
|
+
"degradation", "metric", "language_policy", "technology_decision",
|
|
700
|
+
"task_context", "knowledge_evolution",
|
|
701
|
+
];
|
|
702
|
+
const ALL_STATES = [
|
|
703
|
+
"draft", "advisory", "enforced", "experimental", "deprecated", "removed",
|
|
704
|
+
];
|
|
705
|
+
const by_kind = Object.fromEntries(ALL_KINDS.map((k) => [k, entries.filter((e) => e.kind === k).length]));
|
|
706
|
+
const by_state = Object.fromEntries(ALL_STATES.map((s) => [s, entries.filter((e) => e.state === s).length]));
|
|
707
|
+
const canHardFail = entries.filter((e) => e.hard_fail_allowed && e.state === "enforced");
|
|
708
|
+
const cannotHardFail = entries.filter((e) => !(e.hard_fail_allowed && e.state === "enforced"));
|
|
709
|
+
return {
|
|
710
|
+
total: entries.length,
|
|
711
|
+
by_kind,
|
|
712
|
+
by_state,
|
|
713
|
+
can_hard_fail: canHardFail.map((e) => e.contract_id),
|
|
714
|
+
cannot_hard_fail: cannotHardFail.map((e) => e.contract_id),
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
// ── Runtime hard fail gating ──
|
|
718
|
+
/**
|
|
719
|
+
* 判断契约是否允许 hard fail。
|
|
720
|
+
* 只有 state=enforced 且 hard_fail_allowed=true 的契约才能阻断。
|
|
721
|
+
*/
|
|
722
|
+
export function canContractHardFail(contractId) {
|
|
723
|
+
const entry = getRegistry().get(contractId);
|
|
724
|
+
if (!entry)
|
|
725
|
+
return false;
|
|
726
|
+
return entry.state === "enforced" && entry.hard_fail_allowed;
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Runtime hard fail gate — 未登记的契约不得 hard fail。
|
|
730
|
+
* 用于运行时检查 workflow 是否引用了合法的 guard/verification/failure 契约。
|
|
731
|
+
*/
|
|
732
|
+
export function runtimeHardFailGate(contractId, context) {
|
|
733
|
+
const entry = getRegistry().get(contractId);
|
|
734
|
+
if (!entry) {
|
|
735
|
+
return {
|
|
736
|
+
allowed: false,
|
|
737
|
+
reason: `契约 ${contractId} 未在 Unified Contract Registry 登记,不得 hard fail`,
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
if (entry.state === "removed") {
|
|
741
|
+
return {
|
|
742
|
+
allowed: false,
|
|
743
|
+
reason: `契约 ${contractId} 已移除,${context} 不得引用已移除契约`,
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
if (entry.state === "deprecated") {
|
|
747
|
+
if (entry.replacement_contract_id) {
|
|
748
|
+
return {
|
|
749
|
+
allowed: false,
|
|
750
|
+
reason: `契约 ${contractId} 已废弃,替代契约: ${entry.replacement_contract_id},请迁移到替代契约`,
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
if (entry.migration_note) {
|
|
754
|
+
return {
|
|
755
|
+
allowed: false,
|
|
756
|
+
reason: `契约 ${contractId} 已废弃,迁移说明: ${entry.migration_note}`,
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
return {
|
|
760
|
+
allowed: false,
|
|
761
|
+
reason: `契约 ${contractId} 已废弃且无替代/迁移说明,${context} 不得引用`,
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
if (entry.state === "advisory" || entry.state === "experimental" || entry.state === "draft") {
|
|
765
|
+
return {
|
|
766
|
+
allowed: false,
|
|
767
|
+
reason: `契约 ${contractId} 状态为 ${entry.state},advisory/experimental/draft 契约只能 warning/advisory,不能阻断主流程`,
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
if (entry.state === "enforced" && !entry.hard_fail_allowed) {
|
|
771
|
+
return {
|
|
772
|
+
allowed: false,
|
|
773
|
+
reason: `契约 ${contractId} enforced 但 hard_fail_allowed=false,不得阻断`,
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
if (entry.state === "enforced" && entry.hard_fail_allowed) {
|
|
777
|
+
return { allowed: true, reason: "契约已强制登记且允许 hard fail" };
|
|
778
|
+
}
|
|
779
|
+
return { allowed: false, reason: `契约 ${contractId} 状态为 ${entry.state},不允许 hard fail` };
|
|
780
|
+
}
|
|
781
|
+
// ── 契约治理内核 ──
|
|
782
|
+
/**
|
|
783
|
+
* 验证契约注册表完整性。
|
|
784
|
+
* 检查: 唯一性、字段完整性、文件存在、状态约束、依赖存在性、capability 冲突等。
|
|
785
|
+
*/
|
|
786
|
+
export function validateContractRegistry(existingFiles) {
|
|
787
|
+
const findings = [];
|
|
788
|
+
const entries = [...getRegistry().values()];
|
|
789
|
+
const idSet = new Set();
|
|
790
|
+
for (const entry of entries) {
|
|
791
|
+
// 1. contract_id 唯一且非空
|
|
792
|
+
if (!entry.contract_id || entry.contract_id.trim() === "") {
|
|
793
|
+
findings.push({
|
|
794
|
+
contract_id: entry.contract_id || "",
|
|
795
|
+
kind: entry.kind,
|
|
796
|
+
severity: "hard_fail",
|
|
797
|
+
rule: "contract_id_nonempty",
|
|
798
|
+
message_zh: "contract_id 不能为空",
|
|
799
|
+
evidence_refs: [],
|
|
800
|
+
});
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
803
|
+
if (idSet.has(entry.contract_id)) {
|
|
804
|
+
findings.push({
|
|
805
|
+
contract_id: entry.contract_id,
|
|
806
|
+
kind: entry.kind,
|
|
807
|
+
severity: "hard_fail",
|
|
808
|
+
rule: "contract_id_unique",
|
|
809
|
+
message_zh: `contract_id ${entry.contract_id} 重复`,
|
|
810
|
+
evidence_refs: [],
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
idSet.add(entry.contract_id);
|
|
814
|
+
// 2. kind/state/owner/test 字段完整
|
|
815
|
+
if (!entry.kind) {
|
|
816
|
+
findings.push({
|
|
817
|
+
contract_id: entry.contract_id,
|
|
818
|
+
kind: entry.kind,
|
|
819
|
+
severity: "hard_fail",
|
|
820
|
+
rule: "kind_required",
|
|
821
|
+
message_zh: `契约 ${entry.contract_id} 缺少 kind`,
|
|
822
|
+
evidence_refs: [],
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
if (!entry.state) {
|
|
826
|
+
findings.push({
|
|
827
|
+
contract_id: entry.contract_id,
|
|
828
|
+
kind: entry.kind,
|
|
829
|
+
severity: "hard_fail",
|
|
830
|
+
rule: "state_required",
|
|
831
|
+
message_zh: `契约 ${entry.contract_id} 缺少 state`,
|
|
832
|
+
evidence_refs: [],
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
if (!entry.owner_component) {
|
|
836
|
+
findings.push({
|
|
837
|
+
contract_id: entry.contract_id,
|
|
838
|
+
kind: entry.kind,
|
|
839
|
+
severity: "hard_fail",
|
|
840
|
+
rule: "owner_required",
|
|
841
|
+
message_zh: `契约 ${entry.contract_id} 缺少 owner_component`,
|
|
842
|
+
evidence_refs: [],
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
if (entry.test_files.length === 0) {
|
|
846
|
+
findings.push({
|
|
847
|
+
contract_id: entry.contract_id,
|
|
848
|
+
kind: entry.kind,
|
|
849
|
+
severity: "hard_fail",
|
|
850
|
+
rule: "test_files_required",
|
|
851
|
+
message_zh: `契约 ${entry.contract_id} 无测试文件,所有核心契约必须有测试`,
|
|
852
|
+
evidence_refs: [],
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
// 3. owner_files/test_files 存在性(当 existingFiles 提供时)
|
|
856
|
+
if (existingFiles) {
|
|
857
|
+
const isEnforcedOrHardFail = entry.state === "enforced" || entry.hard_fail_allowed;
|
|
858
|
+
for (const f of entry.owner_files) {
|
|
859
|
+
if (!existingFiles.has(f)) {
|
|
860
|
+
findings.push({
|
|
861
|
+
contract_id: entry.contract_id,
|
|
862
|
+
kind: entry.kind,
|
|
863
|
+
severity: isEnforcedOrHardFail ? "hard_fail" : "warning",
|
|
864
|
+
rule: "owner_file_exists",
|
|
865
|
+
message_zh: `契约 ${entry.contract_id} 的 owner_file ${f} 不存在${isEnforcedOrHardFail ? "(enforced/hard_fail 契约必须存在)" : ""}`,
|
|
866
|
+
evidence_refs: [f],
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
for (const f of entry.test_files) {
|
|
871
|
+
if (!existingFiles.has(f)) {
|
|
872
|
+
findings.push({
|
|
873
|
+
contract_id: entry.contract_id,
|
|
874
|
+
kind: entry.kind,
|
|
875
|
+
severity: isEnforcedOrHardFail ? "hard_fail" : "warning",
|
|
876
|
+
rule: "test_file_exists",
|
|
877
|
+
message_zh: `契约 ${entry.contract_id} 的 test_file ${f} 不存在${isEnforcedOrHardFail ? "(enforced/hard_fail 契约必须存在)" : ""}`,
|
|
878
|
+
evidence_refs: [f],
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
for (const f of entry.lifecycle_test_files) {
|
|
883
|
+
if (!existingFiles.has(f)) {
|
|
884
|
+
findings.push({
|
|
885
|
+
contract_id: entry.contract_id,
|
|
886
|
+
kind: entry.kind,
|
|
887
|
+
severity: "hard_fail",
|
|
888
|
+
rule: "lifecycle_test_file_exists",
|
|
889
|
+
message_zh: `契约 ${entry.contract_id} 的 lifecycle_test_file ${f} 不存在`,
|
|
890
|
+
evidence_refs: [f],
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
// 4. hard_fail_allowed=true 必须 state=enforced 且 lifecycle_test_files 非空
|
|
896
|
+
if (entry.hard_fail_allowed) {
|
|
897
|
+
if (entry.state !== "enforced") {
|
|
898
|
+
findings.push({
|
|
899
|
+
contract_id: entry.contract_id,
|
|
900
|
+
kind: entry.kind,
|
|
901
|
+
severity: "hard_fail",
|
|
902
|
+
rule: "hard_fail_requires_enforced",
|
|
903
|
+
message_zh: `契约 ${entry.contract_id} 的 hard_fail_allowed=true 但 state=${entry.state},只有 enforced 契约允许 hard fail`,
|
|
904
|
+
evidence_refs: [],
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
if (entry.lifecycle_test_files.length === 0) {
|
|
908
|
+
findings.push({
|
|
909
|
+
contract_id: entry.contract_id,
|
|
910
|
+
kind: entry.kind,
|
|
911
|
+
severity: "hard_fail",
|
|
912
|
+
rule: "hard_fail_requires_lifecycle_tests",
|
|
913
|
+
message_zh: `契约 ${entry.contract_id} 的 hard_fail_allowed=true 但无 lifecycle_test_files`,
|
|
914
|
+
evidence_refs: [],
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
// 5. advisory/experimental/draft 不得 hard_fail_allowed
|
|
919
|
+
if ((entry.state === "advisory" ||
|
|
920
|
+
entry.state === "experimental" ||
|
|
921
|
+
entry.state === "draft") &&
|
|
922
|
+
entry.hard_fail_allowed) {
|
|
923
|
+
findings.push({
|
|
924
|
+
contract_id: entry.contract_id,
|
|
925
|
+
kind: entry.kind,
|
|
926
|
+
severity: "hard_fail",
|
|
927
|
+
rule: "non_enforced_no_hard_fail",
|
|
928
|
+
message_zh: `契约 ${entry.contract_id} 的 state=${entry.state},advisory/experimental/draft 契约不得 hard_fail_allowed=true`,
|
|
929
|
+
evidence_refs: [],
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
// 6. deprecated 必须有 replacement_contract_id 或 migration_note
|
|
933
|
+
if (entry.state === "deprecated") {
|
|
934
|
+
if (!entry.replacement_contract_id && !entry.migration_note) {
|
|
935
|
+
findings.push({
|
|
936
|
+
contract_id: entry.contract_id,
|
|
937
|
+
kind: entry.kind,
|
|
938
|
+
severity: "hard_fail",
|
|
939
|
+
rule: "deprecated_requires_replacement",
|
|
940
|
+
message_zh: `契约 ${entry.contract_id} 已废弃但无 replacement_contract_id 或 migration_note`,
|
|
941
|
+
evidence_refs: [],
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
// 7. removed 不得被 workflow/prompt/consumed_by 主链路引用
|
|
946
|
+
if (entry.state === "removed") {
|
|
947
|
+
if (entry.consumed_by.length > 0) {
|
|
948
|
+
findings.push({
|
|
949
|
+
contract_id: entry.contract_id,
|
|
950
|
+
kind: entry.kind,
|
|
951
|
+
severity: "hard_fail",
|
|
952
|
+
rule: "removed_not_referenced",
|
|
953
|
+
message_zh: `已移除契约 ${entry.contract_id} 仍被 consumed_by 引用: ${entry.consumed_by.join(", ")}`,
|
|
954
|
+
evidence_refs: entry.consumed_by,
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
if (entry.prompt_refs.length > 0) {
|
|
958
|
+
findings.push({
|
|
959
|
+
contract_id: entry.contract_id,
|
|
960
|
+
kind: entry.kind,
|
|
961
|
+
severity: "hard_fail",
|
|
962
|
+
rule: "removed_no_prompt_refs",
|
|
963
|
+
message_zh: `已移除契约 ${entry.contract_id} 仍被 prompt 引用: ${entry.prompt_refs.join(", ")}`,
|
|
964
|
+
evidence_refs: entry.prompt_refs,
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
// 8. depends_on 指向的契约必须存在
|
|
969
|
+
for (const depId of entry.depends_on) {
|
|
970
|
+
if (!getRegistry().has(depId)) {
|
|
971
|
+
findings.push({
|
|
972
|
+
contract_id: entry.contract_id,
|
|
973
|
+
kind: entry.kind,
|
|
974
|
+
severity: "hard_fail",
|
|
975
|
+
rule: "dependency_exists",
|
|
976
|
+
message_zh: `契约 ${entry.contract_id} 依赖不存在的契约 ${depId}`,
|
|
977
|
+
evidence_refs: [depId],
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
else {
|
|
981
|
+
const dep = getRegistry().get(depId);
|
|
982
|
+
// 8a. 依赖不得指向 removed
|
|
983
|
+
if (dep.state === "removed") {
|
|
984
|
+
findings.push({
|
|
985
|
+
contract_id: entry.contract_id,
|
|
986
|
+
kind: entry.kind,
|
|
987
|
+
severity: "hard_fail",
|
|
988
|
+
rule: "dependency_not_removed",
|
|
989
|
+
message_zh: `契约 ${entry.contract_id} 依赖已移除的契约 ${depId}`,
|
|
990
|
+
evidence_refs: [depId],
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
// 8b. 指向 deprecated 必须有 migration note 或 replacement
|
|
994
|
+
if (dep.state === "deprecated" && !dep.replacement_contract_id && !dep.migration_note) {
|
|
995
|
+
findings.push({
|
|
996
|
+
contract_id: entry.contract_id,
|
|
997
|
+
kind: entry.kind,
|
|
998
|
+
severity: "warning",
|
|
999
|
+
rule: "dependency_deprecated_migration",
|
|
1000
|
+
message_zh: `契约 ${entry.contract_id} 依赖已废弃的契约 ${depId},该废弃契约无替代或迁移说明`,
|
|
1001
|
+
evidence_refs: [depId],
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
// 9. capability state 与 contract state 冲突检查
|
|
1007
|
+
if (entry.policy_id && entry.capability_ids && entry.capability_ids.length > 0) {
|
|
1008
|
+
for (const capId of entry.capability_ids) {
|
|
1009
|
+
const cap = getCapability(capId);
|
|
1010
|
+
if (cap) {
|
|
1011
|
+
const conflict = checkCapabilityContractConflict(cap.state, entry.state, capId, entry.contract_id);
|
|
1012
|
+
if (conflict) {
|
|
1013
|
+
findings.push(conflict);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
return findings;
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* 检查 capability state 与 contract state 冲突。
|
|
1023
|
+
* capability enforced 但对应 contract advisory/removed 必须报告。
|
|
1024
|
+
*/
|
|
1025
|
+
function checkCapabilityContractConflict(capState, contractState, capId, contractId) {
|
|
1026
|
+
// capability enforced 但 contract advisory/removed/draft — 冲突
|
|
1027
|
+
if (capState === "enforced" &&
|
|
1028
|
+
(contractState === "advisory" ||
|
|
1029
|
+
contractState === "removed" ||
|
|
1030
|
+
contractState === "draft")) {
|
|
1031
|
+
return {
|
|
1032
|
+
contract_id: contractId,
|
|
1033
|
+
kind: "capability",
|
|
1034
|
+
severity: "hard_fail",
|
|
1035
|
+
rule: "capability_contract_state_conflict",
|
|
1036
|
+
message_zh: `能力 ${capId} 状态为 enforced,但对应契约 ${contractId} 状态为 ${contractState},存在冲突`,
|
|
1037
|
+
evidence_refs: [capId, contractId],
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
// capability advisory 但 contract enforced — 冲突(反向)
|
|
1041
|
+
if (capState === "advisory" && contractState === "enforced") {
|
|
1042
|
+
return {
|
|
1043
|
+
contract_id: contractId,
|
|
1044
|
+
kind: "capability",
|
|
1045
|
+
severity: "warning",
|
|
1046
|
+
rule: "capability_contract_state_conflict",
|
|
1047
|
+
message_zh: `能力 ${capId} 状态为 advisory,但对应契约 ${contractId} 状态为 enforced,可能需要同步`,
|
|
1048
|
+
evidence_refs: [capId, contractId],
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
return null;
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* 验证 workflow 引用的契约是否合法。
|
|
1055
|
+
* workflow 引用不存在、removed 或非法 deprecated contract 必须 blocked。
|
|
1056
|
+
*/
|
|
1057
|
+
export function validateWorkflowContractRefs(workflowId, referencedContractIds) {
|
|
1058
|
+
const findings = [];
|
|
1059
|
+
for (const refId of referencedContractIds) {
|
|
1060
|
+
const entry = getRegistry().get(refId);
|
|
1061
|
+
if (!entry) {
|
|
1062
|
+
findings.push({
|
|
1063
|
+
contract_id: refId,
|
|
1064
|
+
kind: "workflow",
|
|
1065
|
+
severity: "hard_fail",
|
|
1066
|
+
rule: "workflow_ref_exists",
|
|
1067
|
+
message_zh: `工作流 ${workflowId} 引用不存在的契约 ${refId}`,
|
|
1068
|
+
evidence_refs: [workflowId, refId],
|
|
1069
|
+
});
|
|
1070
|
+
continue;
|
|
1071
|
+
}
|
|
1072
|
+
if (entry.state === "removed") {
|
|
1073
|
+
findings.push({
|
|
1074
|
+
contract_id: refId,
|
|
1075
|
+
kind: entry.kind,
|
|
1076
|
+
severity: "hard_fail",
|
|
1077
|
+
rule: "workflow_ref_not_removed",
|
|
1078
|
+
message_zh: `工作流 ${workflowId} 引用已移除的契约 ${refId}`,
|
|
1079
|
+
evidence_refs: [workflowId, refId],
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
// deprecated 一律 hard_fail/blocked;有 replacement 提示迁移
|
|
1083
|
+
if (entry.state === "deprecated") {
|
|
1084
|
+
const hint = entry.replacement_contract_id
|
|
1085
|
+
? `,替代契约: ${entry.replacement_contract_id}`
|
|
1086
|
+
: entry.migration_note
|
|
1087
|
+
? `,迁移说明: ${entry.migration_note}`
|
|
1088
|
+
: ",无替代或迁移说明";
|
|
1089
|
+
findings.push({
|
|
1090
|
+
contract_id: refId,
|
|
1091
|
+
kind: entry.kind,
|
|
1092
|
+
severity: "hard_fail",
|
|
1093
|
+
rule: "workflow_ref_deprecated_blocked",
|
|
1094
|
+
message_zh: `工作流 ${workflowId} 引用已废弃的契约 ${refId}${hint}`,
|
|
1095
|
+
evidence_refs: [workflowId, refId],
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
// advisory/experimental 只能 warning,不能阻断
|
|
1099
|
+
if (entry.state === "advisory" || entry.state === "experimental" || entry.state === "draft") {
|
|
1100
|
+
findings.push({
|
|
1101
|
+
contract_id: refId,
|
|
1102
|
+
kind: entry.kind,
|
|
1103
|
+
severity: "advisory",
|
|
1104
|
+
rule: "workflow_ref_advisory_only",
|
|
1105
|
+
message_zh: `工作流 ${workflowId} 引用的契约 ${refId} 状态为 ${entry.state},只能 advisory,不能阻断主流程`,
|
|
1106
|
+
evidence_refs: [workflowId, refId],
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
return findings;
|
|
1111
|
+
}
|
|
1112
|
+
// ── 动态注册(用于测试和扩展) ──
|
|
1113
|
+
/** 注册新契约(运行时) */
|
|
1114
|
+
export function registerContract(entry) {
|
|
1115
|
+
const registry = getRegistry();
|
|
1116
|
+
if (registry.has(entry.contract_id)) {
|
|
1117
|
+
return { success: false, error: `contract_id ${entry.contract_id} 已存在` };
|
|
1118
|
+
}
|
|
1119
|
+
registry.set(entry.contract_id, cloneEntry(entry));
|
|
1120
|
+
return { success: true };
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* 内部 helper: 只允许通过 ContractStateStore.apply 调用。
|
|
1124
|
+
* 此函数不导出。ContractStateStore 通过 createContractStateApplier 获取闭包引用。
|
|
1125
|
+
*/
|
|
1126
|
+
function applyContractStateOverride(override) {
|
|
1127
|
+
const registry = getRegistry();
|
|
1128
|
+
const entry = registry.get(override.contract_id);
|
|
1129
|
+
if (!entry)
|
|
1130
|
+
return;
|
|
1131
|
+
const updated = cloneEntry(entry);
|
|
1132
|
+
updated.state = override.new_state;
|
|
1133
|
+
if (override.replacement_contract_id) {
|
|
1134
|
+
updated.replacement_contract_id = override.replacement_contract_id;
|
|
1135
|
+
}
|
|
1136
|
+
if (override.migration_note) {
|
|
1137
|
+
updated.migration_note = override.migration_note;
|
|
1138
|
+
}
|
|
1139
|
+
registry.set(override.contract_id, updated);
|
|
1140
|
+
}
|
|
1141
|
+
/** 工厂函数: 返回 applyContractStateOverride 闭包引用,仅供 ContractStateStore 使用 */
|
|
1142
|
+
export function createContractStateApplier() {
|
|
1143
|
+
return applyContractStateOverride;
|
|
1144
|
+
}
|
|
1145
|
+
/** 重置运行时注册表为内置契约(用于测试清理) */
|
|
1146
|
+
export function resetRegistry() {
|
|
1147
|
+
runtimeEntries = null;
|
|
1148
|
+
}
|
|
1149
|
+
/** 获取所有 policy_id → contract_id 映射 */
|
|
1150
|
+
export function getPolicyToContractMapping() {
|
|
1151
|
+
const result = [];
|
|
1152
|
+
for (const entry of getRegistry().values()) {
|
|
1153
|
+
if (entry.policy_id) {
|
|
1154
|
+
result.push({ policy_id: entry.policy_id, contract_id: entry.contract_id });
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
return result;
|
|
1158
|
+
}
|
|
1159
|
+
//# sourceMappingURL=contract_registry.js.map
|