@dommaker/harness 1.1.0 → 1.2.0

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.
Files changed (349) hide show
  1. package/CHANGELOG.md +19 -2
  2. package/README.md +2 -4
  3. package/bin/harness.js +12 -37
  4. package/dist/cli/commands/check.d.ts +2 -2
  5. package/dist/cli/commands/check.d.ts.map +1 -1
  6. package/dist/cli/commands/check.js +7 -32
  7. package/dist/cli/commands/check.js.map +1 -1
  8. package/dist/cli/commands/definitions.d.ts +2 -0
  9. package/dist/cli/commands/definitions.d.ts.map +1 -1
  10. package/dist/cli/commands/definitions.js.map +1 -1
  11. package/dist/cli/commands/init.d.ts.map +1 -1
  12. package/dist/cli/commands/init.js +6 -37
  13. package/dist/cli/commands/init.js.map +1 -1
  14. package/dist/cli/commands/knowledge.d.ts.map +1 -1
  15. package/dist/cli/commands/knowledge.js +1 -12
  16. package/dist/cli/commands/knowledge.js.map +1 -1
  17. package/dist/cli/commands/report.d.ts.map +1 -1
  18. package/dist/cli/commands/report.js +0 -2
  19. package/dist/cli/commands/report.js.map +1 -1
  20. package/dist/cli/commands/status.d.ts.map +1 -1
  21. package/dist/cli/commands/status.js +2 -11
  22. package/dist/cli/commands/status.js.map +1 -1
  23. package/dist/context/index.d.ts +9 -6
  24. package/dist/context/index.d.ts.map +1 -1
  25. package/dist/context/index.js +18 -20
  26. package/dist/context/index.js.map +1 -1
  27. package/dist/core/constraints/capabilities-parser.d.ts +3 -2
  28. package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
  29. package/dist/core/constraints/capabilities-parser.js +25 -47
  30. package/dist/core/constraints/capabilities-parser.js.map +1 -1
  31. package/dist/core/constraints/checker.d.ts +32 -33
  32. package/dist/core/constraints/checker.d.ts.map +1 -1
  33. package/dist/core/constraints/checker.js +38 -128
  34. package/dist/core/constraints/checker.js.map +1 -1
  35. package/dist/core/constraints/checkers/index.d.ts +2 -1
  36. package/dist/core/constraints/checkers/index.d.ts.map +1 -1
  37. package/dist/core/constraints/checkers/index.js +3 -0
  38. package/dist/core/constraints/checkers/index.js.map +1 -1
  39. package/dist/core/constraints/checkers/types.d.ts +25 -0
  40. package/dist/core/constraints/checkers/types.d.ts.map +1 -1
  41. package/dist/core/constraints/checkers/types.js +24 -0
  42. package/dist/core/constraints/checkers/types.js.map +1 -1
  43. package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
  44. package/dist/core/constraints/definitions/guidelines.js +0 -2
  45. package/dist/core/constraints/definitions/guidelines.js.map +1 -1
  46. package/dist/core/constraints/definitions/prompts.d.ts.map +1 -1
  47. package/dist/core/constraints/definitions/prompts.js +0 -5
  48. package/dist/core/constraints/definitions/prompts.js.map +1 -1
  49. package/dist/core/constraints/index.d.ts +1 -2
  50. package/dist/core/constraints/index.d.ts.map +1 -1
  51. package/dist/core/constraints/index.js +1 -7
  52. package/dist/core/constraints/index.js.map +1 -1
  53. package/dist/core/constraints/usage-report.d.ts +1 -2
  54. package/dist/core/constraints/usage-report.d.ts.map +1 -1
  55. package/dist/core/constraints/usage-report.js +2 -5
  56. package/dist/core/constraints/usage-report.js.map +1 -1
  57. package/dist/core/effective-constraints.d.ts +24 -4
  58. package/dist/core/effective-constraints.d.ts.map +1 -1
  59. package/dist/core/effective-constraints.js +28 -7
  60. package/dist/core/effective-constraints.js.map +1 -1
  61. package/dist/core/effective-set.d.ts +30 -0
  62. package/dist/core/effective-set.d.ts.map +1 -0
  63. package/dist/core/effective-set.js +35 -0
  64. package/dist/core/effective-set.js.map +1 -0
  65. package/dist/core/index.d.ts +13 -6
  66. package/dist/core/index.d.ts.map +1 -1
  67. package/dist/core/index.js +44 -21
  68. package/dist/core/index.js.map +1 -1
  69. package/dist/core/project-config-loader.d.ts +3 -6
  70. package/dist/core/project-config-loader.d.ts.map +1 -1
  71. package/dist/core/project-config-loader.js +47 -61
  72. package/dist/core/project-config-loader.js.map +1 -1
  73. package/dist/failure/constraint-handler.d.ts +1 -1
  74. package/dist/failure/constraint-handler.js +1 -1
  75. package/dist/gates/checker-gate.d.ts +1 -4
  76. package/dist/gates/checker-gate.d.ts.map +1 -1
  77. package/dist/gates/checker-gate.js +3 -11
  78. package/dist/gates/checker-gate.js.map +1 -1
  79. package/dist/gates/definitions.d.ts +9 -38
  80. package/dist/gates/definitions.d.ts.map +1 -1
  81. package/dist/gates/definitions.js +24 -13
  82. package/dist/gates/definitions.js.map +1 -1
  83. package/dist/gates/effective-gates.d.ts.map +1 -1
  84. package/dist/gates/effective-gates.js +14 -18
  85. package/dist/gates/effective-gates.js.map +1 -1
  86. package/dist/gates/index.d.ts +1 -1
  87. package/dist/gates/index.d.ts.map +1 -1
  88. package/dist/gates/index.js.map +1 -1
  89. package/dist/hooks/bootstrap.d.ts.map +1 -1
  90. package/dist/hooks/bootstrap.js +0 -3
  91. package/dist/hooks/bootstrap.js.map +1 -1
  92. package/dist/index.d.ts +43 -53
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/index.js +180 -138
  95. package/dist/index.js.map +1 -1
  96. package/dist/knowledge/query.d.ts +15 -0
  97. package/dist/knowledge/query.d.ts.map +1 -1
  98. package/dist/knowledge/query.js +23 -0
  99. package/dist/knowledge/query.js.map +1 -1
  100. package/dist/monitoring/analyzer-base.d.ts +0 -4
  101. package/dist/monitoring/analyzer-base.d.ts.map +1 -1
  102. package/dist/monitoring/analyzer-base.js +0 -21
  103. package/dist/monitoring/analyzer-base.js.map +1 -1
  104. package/dist/monitoring/index.d.ts +6 -12
  105. package/dist/monitoring/index.d.ts.map +1 -1
  106. package/dist/monitoring/index.js +13 -29
  107. package/dist/monitoring/index.js.map +1 -1
  108. package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
  109. package/dist/monitoring/trace-analyzer.js +2 -68
  110. package/dist/monitoring/trace-analyzer.js.map +1 -1
  111. package/dist/monitoring/traces.d.ts +2 -6
  112. package/dist/monitoring/traces.d.ts.map +1 -1
  113. package/dist/monitoring/traces.js +0 -14
  114. package/dist/monitoring/traces.js.map +1 -1
  115. package/dist/presets/index.d.ts +2 -2
  116. package/dist/presets/index.d.ts.map +1 -1
  117. package/dist/presets/index.js +3 -4
  118. package/dist/presets/index.js.map +1 -1
  119. package/dist/presets/standard.d.ts +10 -22
  120. package/dist/presets/standard.d.ts.map +1 -1
  121. package/dist/presets/standard.js +15 -75
  122. package/dist/presets/standard.js.map +1 -1
  123. package/dist/types/constraint.d.ts +1 -29
  124. package/dist/types/constraint.d.ts.map +1 -1
  125. package/dist/types/constraint.js +1 -1
  126. package/dist/types/constraint.js.map +1 -1
  127. package/dist/types/index.d.ts +0 -3
  128. package/dist/types/index.d.ts.map +1 -1
  129. package/dist/types/index.js +0 -4
  130. package/dist/types/index.js.map +1 -1
  131. package/dist/types/project-config.d.ts +4 -8
  132. package/dist/types/project-config.d.ts.map +1 -1
  133. package/dist/types/trace.d.ts +9 -22
  134. package/dist/types/trace.d.ts.map +1 -1
  135. package/package.json +2 -2
  136. package/src/CONTEXT.md +5 -7
  137. package/src/__tests__/checker-extra.test.ts +80 -139
  138. package/src/__tests__/checker.test.ts +0 -376
  139. package/src/__tests__/project-config-loader-extra.test.ts +42 -29
  140. package/src/__tests__/public-exports.test.ts +138 -0
  141. package/src/__tests__/trace-analyzer-extra.test.ts +6 -86
  142. package/src/__tests__/trace-analyzer.test.ts +4 -5
  143. package/src/__tests__/trace-collector.test.ts +0 -11
  144. package/src/__tests__/traces.test.ts +3 -22
  145. package/src/cli/commands/CONTEXT.md +2 -2
  146. package/src/cli/commands/__tests__/check-skip-output.test.ts +10 -7
  147. package/src/cli/commands/__tests__/check.test.ts +29 -69
  148. package/src/cli/commands/__tests__/constraints-report.test.ts +1 -1
  149. package/src/cli/commands/__tests__/knowledge.test.ts +90 -1
  150. package/src/cli/commands/__tests__/registry.test.ts +8 -6
  151. package/src/cli/commands/__tests__/status-extra.test.ts +6 -28
  152. package/src/cli/commands/__tests__/status.test.ts +6 -21
  153. package/src/cli/commands/check.ts +8 -34
  154. package/src/cli/commands/definitions.ts +2 -0
  155. package/src/cli/commands/init.ts +6 -37
  156. package/src/cli/commands/knowledge.ts +1 -16
  157. package/src/cli/commands/report.ts +0 -2
  158. package/src/cli/commands/status.ts +2 -12
  159. package/src/context/index.ts +29 -6
  160. package/src/core/CONTEXT.md +4 -3
  161. package/src/core/__tests__/effective-set.test.ts +80 -0
  162. package/src/core/constraints/capabilities-parser.ts +43 -49
  163. package/src/core/constraints/checker.ts +56 -147
  164. package/src/core/constraints/checkers/index.ts +2 -1
  165. package/src/core/constraints/checkers/types.ts +42 -0
  166. package/src/core/constraints/definitions/guidelines.ts +0 -2
  167. package/src/core/constraints/definitions/prompts.ts +0 -5
  168. package/src/core/constraints/index.ts +2 -17
  169. package/src/core/constraints/usage-report.ts +5 -8
  170. package/src/core/effective-constraints.ts +35 -7
  171. package/src/core/effective-set.ts +56 -0
  172. package/src/core/index.ts +80 -6
  173. package/src/core/project-config-loader.ts +53 -68
  174. package/src/failure/CONTEXT.md +1 -1
  175. package/src/failure/constraint-handler.ts +1 -1
  176. package/src/gates/CONTEXT.md +3 -3
  177. package/src/gates/checker-gate.ts +4 -12
  178. package/src/gates/definitions.ts +27 -50
  179. package/src/gates/effective-gates.ts +14 -21
  180. package/src/gates/index.ts +1 -1
  181. package/src/hooks/bootstrap.ts +0 -3
  182. package/src/index.ts +384 -137
  183. package/src/knowledge/CONTEXT.md +2 -2
  184. package/src/knowledge/__tests__/query.test.ts +64 -0
  185. package/src/knowledge/query.ts +28 -0
  186. package/src/monitoring/CONTEXT.md +7 -13
  187. package/src/monitoring/__tests__/traces.test.ts +0 -10
  188. package/src/monitoring/analyzer-base.ts +0 -22
  189. package/src/monitoring/index.ts +6 -12
  190. package/src/monitoring/trace-analyzer.ts +2 -73
  191. package/src/monitoring/traces.ts +2 -22
  192. package/src/presets/__tests__/standard.test.ts +48 -69
  193. package/src/presets/index.ts +3 -5
  194. package/src/presets/standard.ts +14 -79
  195. package/src/spec/CONTEXT.md +5 -13
  196. package/src/types/constraint.ts +1 -51
  197. package/src/types/index.ts +0 -12
  198. package/src/types/project-config.ts +4 -10
  199. package/src/types/trace.ts +9 -34
  200. package/dist/core/constraints/interceptor.d.ts +0 -38
  201. package/dist/core/constraints/interceptor.d.ts.map +0 -1
  202. package/dist/core/constraints/interceptor.js +0 -166
  203. package/dist/core/constraints/interceptor.js.map +0 -1
  204. package/dist/dashboard/data.d.ts +0 -31
  205. package/dist/dashboard/data.d.ts.map +0 -1
  206. package/dist/dashboard/data.js +0 -81
  207. package/dist/dashboard/data.js.map +0 -1
  208. package/dist/dashboard/index.d.ts +0 -4
  209. package/dist/dashboard/index.d.ts.map +0 -1
  210. package/dist/dashboard/index.js +0 -20
  211. package/dist/dashboard/index.js.map +0 -1
  212. package/dist/dashboard/stats.d.ts +0 -20
  213. package/dist/dashboard/stats.d.ts.map +0 -1
  214. package/dist/dashboard/stats.js +0 -115
  215. package/dist/dashboard/stats.js.map +0 -1
  216. package/dist/dashboard/types.d.ts +0 -110
  217. package/dist/dashboard/types.d.ts.map +0 -1
  218. package/dist/dashboard/types.js +0 -8
  219. package/dist/dashboard/types.js.map +0 -1
  220. package/dist/monitoring/constraint-doctor.d.ts +0 -82
  221. package/dist/monitoring/constraint-doctor.d.ts.map +0 -1
  222. package/dist/monitoring/constraint-doctor.js +0 -191
  223. package/dist/monitoring/constraint-doctor.js.map +0 -1
  224. package/dist/monitoring/diagnosis-rules.d.ts +0 -18
  225. package/dist/monitoring/diagnosis-rules.d.ts.map +0 -1
  226. package/dist/monitoring/diagnosis-rules.js +0 -119
  227. package/dist/monitoring/diagnosis-rules.js.map +0 -1
  228. package/dist/monitoring/knowledge-doctor.d.ts +0 -78
  229. package/dist/monitoring/knowledge-doctor.d.ts.map +0 -1
  230. package/dist/monitoring/knowledge-doctor.js +0 -266
  231. package/dist/monitoring/knowledge-doctor.js.map +0 -1
  232. package/dist/monitoring/knowledge-evolver.d.ts +0 -72
  233. package/dist/monitoring/knowledge-evolver.d.ts.map +0 -1
  234. package/dist/monitoring/knowledge-evolver.js +0 -205
  235. package/dist/monitoring/knowledge-evolver.js.map +0 -1
  236. package/dist/monitoring/performance-analyzer.d.ts +0 -92
  237. package/dist/monitoring/performance-analyzer.d.ts.map +0 -1
  238. package/dist/monitoring/performance-analyzer.js +0 -343
  239. package/dist/monitoring/performance-analyzer.js.map +0 -1
  240. package/dist/monitoring/performance-collector.d.ts +0 -103
  241. package/dist/monitoring/performance-collector.d.ts.map +0 -1
  242. package/dist/monitoring/performance-collector.js +0 -298
  243. package/dist/monitoring/performance-collector.js.map +0 -1
  244. package/dist/safety/index.d.ts +0 -6
  245. package/dist/safety/index.d.ts.map +0 -1
  246. package/dist/safety/index.js +0 -22
  247. package/dist/safety/index.js.map +0 -1
  248. package/dist/safety/input-guardrail.d.ts +0 -36
  249. package/dist/safety/input-guardrail.d.ts.map +0 -1
  250. package/dist/safety/input-guardrail.js +0 -118
  251. package/dist/safety/input-guardrail.js.map +0 -1
  252. package/dist/safety/output-guardrail.d.ts +0 -39
  253. package/dist/safety/output-guardrail.d.ts.map +0 -1
  254. package/dist/safety/output-guardrail.js +0 -147
  255. package/dist/safety/output-guardrail.js.map +0 -1
  256. package/dist/safety/sandbox.d.ts +0 -45
  257. package/dist/safety/sandbox.d.ts.map +0 -1
  258. package/dist/safety/sandbox.js +0 -134
  259. package/dist/safety/sandbox.js.map +0 -1
  260. package/dist/safety/tool-guardrail.d.ts +0 -51
  261. package/dist/safety/tool-guardrail.d.ts.map +0 -1
  262. package/dist/safety/tool-guardrail.js +0 -147
  263. package/dist/safety/tool-guardrail.js.map +0 -1
  264. package/dist/safety/types.d.ts +0 -104
  265. package/dist/safety/types.d.ts.map +0 -1
  266. package/dist/safety/types.js +0 -6
  267. package/dist/safety/types.js.map +0 -1
  268. package/dist/spec/annotation-checker.d.ts +0 -47
  269. package/dist/spec/annotation-checker.d.ts.map +0 -1
  270. package/dist/spec/annotation-checker.js +0 -279
  271. package/dist/spec/annotation-checker.js.map +0 -1
  272. package/dist/types/enforcement.d.ts +0 -42
  273. package/dist/types/enforcement.d.ts.map +0 -1
  274. package/dist/types/enforcement.js +0 -6
  275. package/dist/types/enforcement.js.map +0 -1
  276. package/dist/types/monitoring-types.d.ts +0 -53
  277. package/dist/types/monitoring-types.d.ts.map +0 -1
  278. package/dist/types/monitoring-types.js +0 -10
  279. package/dist/types/monitoring-types.js.map +0 -1
  280. package/dist/types/performance.d.ts +0 -204
  281. package/dist/types/performance.d.ts.map +0 -1
  282. package/dist/types/performance.js +0 -12
  283. package/dist/types/performance.js.map +0 -1
  284. package/dist/verification/index.d.ts +0 -4
  285. package/dist/verification/index.d.ts.map +0 -1
  286. package/dist/verification/index.js +0 -20
  287. package/dist/verification/index.js.map +0 -1
  288. package/dist/verification/loop.d.ts +0 -30
  289. package/dist/verification/loop.d.ts.map +0 -1
  290. package/dist/verification/loop.js +0 -114
  291. package/dist/verification/loop.js.map +0 -1
  292. package/dist/verification/rules-based.d.ts +0 -40
  293. package/dist/verification/rules-based.d.ts.map +0 -1
  294. package/dist/verification/rules-based.js +0 -130
  295. package/dist/verification/rules-based.js.map +0 -1
  296. package/dist/verification/types.d.ts +0 -69
  297. package/dist/verification/types.d.ts.map +0 -1
  298. package/dist/verification/types.js +0 -6
  299. package/dist/verification/types.js.map +0 -1
  300. package/src/__tests__/annotation-checker.test.ts +0 -183
  301. package/src/__tests__/constraint-doctor.test.ts +0 -271
  302. package/src/__tests__/doctor-extra.test.ts +0 -155
  303. package/src/__tests__/extend-exceptions.test.ts +0 -149
  304. package/src/__tests__/interceptor.test.ts +0 -89
  305. package/src/__tests__/performance-analyzer.test.ts +0 -499
  306. package/src/__tests__/performance-collector.test.ts +0 -276
  307. package/src/__tests__/presets.test.ts +0 -65
  308. package/src/core/constraints/__tests__/interceptor.test.ts +0 -253
  309. package/src/core/constraints/interceptor.ts +0 -214
  310. package/src/dashboard/CONTEXT.md +0 -21
  311. package/src/dashboard/__tests__/data.test.ts +0 -111
  312. package/src/dashboard/__tests__/stats.test.ts +0 -159
  313. package/src/dashboard/data.ts +0 -103
  314. package/src/dashboard/index.ts +0 -3
  315. package/src/dashboard/stats.ts +0 -127
  316. package/src/dashboard/types.ts +0 -130
  317. package/src/monitoring/__tests__/knowledge-doctor.test.ts +0 -278
  318. package/src/monitoring/__tests__/knowledge-evolver.test.ts +0 -368
  319. package/src/monitoring/__tests__/performance-analyzer.test.ts +0 -137
  320. package/src/monitoring/__tests__/performance-collector.test.ts +0 -331
  321. package/src/monitoring/constraint-doctor.ts +0 -239
  322. package/src/monitoring/diagnosis-rules.ts +0 -132
  323. package/src/monitoring/knowledge-doctor.ts +0 -322
  324. package/src/monitoring/knowledge-evolver.ts +0 -289
  325. package/src/monitoring/performance-analyzer.ts +0 -400
  326. package/src/monitoring/performance-collector.ts +0 -326
  327. package/src/safety/CONTEXT.md +0 -23
  328. package/src/safety/__tests__/input-guardrail.test.ts +0 -105
  329. package/src/safety/__tests__/output-guardrail.test.ts +0 -108
  330. package/src/safety/__tests__/sandbox.test.ts +0 -158
  331. package/src/safety/__tests__/tool-guardrail.test.ts +0 -127
  332. package/src/safety/index.ts +0 -5
  333. package/src/safety/input-guardrail.ts +0 -133
  334. package/src/safety/output-guardrail.ts +0 -170
  335. package/src/safety/sandbox.ts +0 -148
  336. package/src/safety/tool-guardrail.ts +0 -176
  337. package/src/safety/types.ts +0 -124
  338. package/src/spec/__tests__/annotation-checker.test.ts +0 -294
  339. package/src/spec/annotation-checker.ts +0 -320
  340. package/src/types/enforcement.ts +0 -48
  341. package/src/types/monitoring-types.ts +0 -68
  342. package/src/types/performance.ts +0 -295
  343. package/src/verification/CONTEXT.md +0 -23
  344. package/src/verification/__tests__/loop.test.ts +0 -303
  345. package/src/verification/__tests__/rules-based.test.ts +0 -240
  346. package/src/verification/index.ts +0 -3
  347. package/src/verification/loop.ts +0 -137
  348. package/src/verification/rules-based.ts +0 -152
  349. package/src/verification/types.ts +0 -81
@@ -170,382 +170,6 @@ describe('ConstraintChecker', () => {
170
170
  });
171
171
  });
172
172
 
173
- describe('Exception handling', () => {
174
- it('should apply exception for scalability_required', async () => {
175
- const context: ConstraintContext = {
176
- operation: 'code_implementation',
177
- scalabilityRequired: true,
178
- };
179
-
180
- const result = await checker.check(
181
- {
182
- id: 'simplest_solution_first',
183
- kind: 'check',
184
- level: 'guideline',
185
- rule: 'SIMPLEST FIRST',
186
- message: 'test',
187
- trigger: 'code_implementation',
188
- enforcement: 'test',
189
- exceptions: ['scalability_required'],
190
- },
191
- context
192
- );
193
-
194
- expect(result.satisfied).toBe(true);
195
- });
196
-
197
- it('should apply exception for security_required', async () => {
198
- const context: ConstraintContext = {
199
- operation: 'code_implementation',
200
- securityRequired: true,
201
- };
202
-
203
- const result = await checker.check(
204
- {
205
- id: 'simplest_solution_first',
206
- kind: 'check',
207
- level: 'guideline',
208
- rule: 'SIMPLEST FIRST',
209
- message: 'test',
210
- trigger: 'code_implementation',
211
- enforcement: 'test',
212
- exceptions: ['security_required'],
213
- },
214
- context
215
- );
216
-
217
- expect(result.satisfied).toBe(true);
218
- });
219
-
220
- it('should apply exception for performance_required', async () => {
221
- const context: ConstraintContext = {
222
- operation: 'code_implementation',
223
- performanceRequired: true,
224
- };
225
-
226
- const result = await checker.check(
227
- {
228
- id: 'simplest_solution_first',
229
- kind: 'check',
230
- level: 'guideline',
231
- rule: 'SIMPLEST FIRST',
232
- message: 'test',
233
- trigger: 'code_implementation',
234
- enforcement: 'test',
235
- exceptions: ['performance_required'],
236
- },
237
- context
238
- );
239
-
240
- expect(result.satisfied).toBe(true);
241
- });
242
-
243
- it('should apply exception for reliability_required', async () => {
244
- const context: ConstraintContext = {
245
- operation: 'code_implementation',
246
- reliabilityRequired: true,
247
- };
248
-
249
- const result = await checker.check(
250
- {
251
- id: 'simplest_solution_first',
252
- kind: 'check',
253
- level: 'guideline',
254
- rule: 'SIMPLEST FIRST',
255
- message: 'test',
256
- trigger: 'code_implementation',
257
- enforcement: 'test',
258
- exceptions: ['reliability_required'],
259
- },
260
- context
261
- );
262
-
263
- expect(result.satisfied).toBe(true);
264
- });
265
-
266
- it('should apply exception for config_value_error', async () => {
267
- const context: ConstraintContext = {
268
- operation: 'code_implementation',
269
- isConfigValueError: true,
270
- };
271
-
272
- const result = await checker.check(
273
- {
274
- id: 'no_fix_without_root_cause',
275
- kind: 'check',
276
- level: 'guideline',
277
- rule: 'NO FIX',
278
- message: 'test',
279
- trigger: 'code_implementation',
280
- enforcement: 'test',
281
- exceptions: ['config_value_error'],
282
- },
283
- context
284
- );
285
-
286
- expect(result.satisfied).toBe(true);
287
- });
288
-
289
- it('should apply exception for missing_config', async () => {
290
- const context: ConstraintContext = {
291
- operation: 'code_implementation',
292
- isMissingConfig: true,
293
- };
294
-
295
- const result = await checker.check(
296
- {
297
- id: 'no_fix_without_root_cause',
298
- kind: 'check',
299
- level: 'guideline',
300
- rule: 'NO FIX',
301
- message: 'test',
302
- trigger: 'code_implementation',
303
- enforcement: 'test',
304
- exceptions: ['missing_config'],
305
- },
306
- context
307
- );
308
-
309
- expect(result.satisfied).toBe(true);
310
- });
311
-
312
- it('should apply exception for config_file', async () => {
313
- const context: ConstraintContext = {
314
- operation: 'code_implementation',
315
- isConfigFile: true,
316
- };
317
-
318
- const result = await checker.check(
319
- {
320
- id: 'no_code_without_test',
321
- kind: 'check',
322
- level: 'guideline',
323
- rule: 'NO CODE',
324
- message: 'test',
325
- trigger: 'code_implementation',
326
- enforcement: 'test',
327
- exceptions: ['config_file'],
328
- },
329
- context
330
- );
331
-
332
- expect(result.satisfied).toBe(true);
333
- });
334
-
335
- it('should apply exception for type_definition', async () => {
336
- const context: ConstraintContext = {
337
- operation: 'code_implementation',
338
- isTypeDefinition: true,
339
- };
340
-
341
- const result = await checker.check(
342
- {
343
- id: 'no_code_without_test',
344
- kind: 'check',
345
- level: 'guideline',
346
- rule: 'NO CODE',
347
- message: 'test',
348
- trigger: 'code_implementation',
349
- enforcement: 'test',
350
- exceptions: ['type_definition'],
351
- },
352
- context
353
- );
354
-
355
- expect(result.satisfied).toBe(true);
356
- });
357
-
358
- it('should apply exception for simple_accessor', async () => {
359
- const context: ConstraintContext = {
360
- operation: 'code_implementation',
361
- isSimpleAccessor: true,
362
- };
363
-
364
- const result = await checker.check(
365
- {
366
- id: 'no_code_without_test',
367
- kind: 'check',
368
- level: 'guideline',
369
- rule: 'NO CODE',
370
- message: 'test',
371
- trigger: 'code_implementation',
372
- enforcement: 'test',
373
- exceptions: ['simple_accessor'],
374
- },
375
- context
376
- );
377
-
378
- expect(result.satisfied).toBe(true);
379
- });
380
-
381
- it('should apply exception for pure_display_component', async () => {
382
- const context: ConstraintContext = {
383
- operation: 'code_implementation',
384
- isPureDisplayComponent: true,
385
- };
386
-
387
- const result = await checker.check(
388
- {
389
- id: 'no_code_without_test',
390
- kind: 'check',
391
- level: 'guideline',
392
- rule: 'NO CODE',
393
- message: 'test',
394
- trigger: 'code_implementation',
395
- enforcement: 'test',
396
- exceptions: ['pure_display_component'],
397
- },
398
- context
399
- );
400
-
401
- expect(result.satisfied).toBe(true);
402
- });
403
-
404
- it('should apply exception for internal_refactor', async () => {
405
- const context: ConstraintContext = {
406
- operation: 'commit',
407
- projectPath: tempDir,
408
- isInternalRefactor: true,
409
- };
410
-
411
- const result = await checker.check(
412
- {
413
- id: 'capability_sync',
414
- kind: 'check',
415
- level: 'guideline',
416
- rule: 'CAPABILITY SYNC',
417
- message: 'test',
418
- trigger: 'commit',
419
- enforcement: 'test',
420
- exceptions: ['internal_refactor'],
421
- },
422
- context
423
- );
424
-
425
- expect(result.satisfied).toBe(true);
426
- });
427
-
428
- it('should apply exception for bug_fix_only', async () => {
429
- const context: ConstraintContext = {
430
- operation: 'commit',
431
- projectPath: tempDir,
432
- isBugFixOnly: true,
433
- };
434
-
435
- const result = await checker.check(
436
- {
437
- id: 'capability_sync',
438
- kind: 'check',
439
- level: 'guideline',
440
- rule: 'CAPABILITY SYNC',
441
- message: 'test',
442
- trigger: 'commit',
443
- enforcement: 'test',
444
- exceptions: ['bug_fix_only'],
445
- },
446
- context
447
- );
448
-
449
- expect(result.satisfied).toBe(true);
450
- });
451
-
452
- it('should apply exception for performance_optimization', async () => {
453
- const context: ConstraintContext = {
454
- operation: 'commit',
455
- projectPath: tempDir,
456
- isPerformanceOptimization: true,
457
- };
458
-
459
- const result = await checker.check(
460
- {
461
- id: 'capability_sync',
462
- kind: 'check',
463
- level: 'guideline',
464
- rule: 'CAPABILITY SYNC',
465
- message: 'test',
466
- trigger: 'commit',
467
- enforcement: 'test',
468
- exceptions: ['performance_optimization'],
469
- },
470
- context
471
- );
472
-
473
- expect(result.satisfied).toBe(true);
474
- });
475
-
476
- it('should apply exception for redundant_code_cleanup', async () => {
477
- const context: ConstraintContext = {
478
- operation: 'commit',
479
- projectPath: tempDir,
480
- isRedundantCodeCleanup: true,
481
- };
482
-
483
- const result = await checker.check(
484
- {
485
- id: 'no_simplification_without_approval',
486
- kind: 'check',
487
- level: 'guideline',
488
- rule: 'NO SIMPLIFICATION',
489
- message: 'test',
490
- trigger: 'commit',
491
- enforcement: 'test',
492
- exceptions: ['redundant_code_cleanup'],
493
- },
494
- context
495
- );
496
-
497
- expect(result.satisfied).toBe(true);
498
- });
499
-
500
- it('should apply exception for same_effect_refactor', async () => {
501
- const context: ConstraintContext = {
502
- operation: 'commit',
503
- projectPath: tempDir,
504
- isSameEffectRefactor: true,
505
- };
506
-
507
- const result = await checker.check(
508
- {
509
- id: 'no_simplification_without_approval',
510
- kind: 'check',
511
- level: 'guideline',
512
- rule: 'NO SIMPLIFICATION',
513
- message: 'test',
514
- trigger: 'commit',
515
- enforcement: 'test',
516
- exceptions: ['same_effect_refactor'],
517
- },
518
- context
519
- );
520
-
521
- expect(result.satisfied).toBe(true);
522
- });
523
-
524
- it('should apply exception for unused_code_removal', async () => {
525
- const context: ConstraintContext = {
526
- operation: 'commit',
527
- projectPath: tempDir,
528
- isUnusedCodeRemoval: true,
529
- };
530
-
531
- const result = await checker.check(
532
- {
533
- id: 'no_simplification_without_approval',
534
- kind: 'check',
535
- level: 'guideline',
536
- rule: 'NO SIMPLIFICATION',
537
- message: 'test',
538
- trigger: 'commit',
539
- enforcement: 'test',
540
- exceptions: ['unused_code_removal'],
541
- },
542
- context
543
- );
544
-
545
- expect(result.satisfied).toBe(true);
546
- });
547
- });
548
-
549
173
  describe('Prompt constraints(ADR-0001:不执行 checker,check() 短路 satisfied)', () => {
550
174
  it('所有内置 prompt 约束 check() 均短路通过', async () => {
551
175
  const context: ConstraintContext = { operation: 'code_implementation' };
@@ -2,7 +2,7 @@
2
2
  * ProjectConfigLoader 补充测试
3
3
  */
4
4
 
5
- import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
5
+ import { describe, it, expect, beforeAll, afterAll, jest } from '@jest/globals';
6
6
  import { ProjectConfigLoader } from '../core/project-config-loader';
7
7
  import * as fs from 'fs';
8
8
  import * as path from 'path';
@@ -123,34 +123,6 @@ custom_constraints:
123
123
  });
124
124
  });
125
125
 
126
- describe('约束扩展', () => {
127
- it('应该扩展例外列表', () => {
128
- fs.writeFileSync(
129
- path.join(harnessDir, 'config.yml'),
130
- `
131
- custom_constraints:
132
- extended_rule:
133
- rule: EXTENDED RULE
134
- message: Extended
135
- level: guideline
136
- trigger: commit
137
- exceptions:
138
- - simple_typo
139
- extend_exceptions:
140
- - config_change
141
- `
142
- );
143
-
144
- const loader = new ProjectConfigLoader(tempDir);
145
- loader.load();
146
- const merged = loader.mergeConstraints();
147
-
148
- expect(merged.guidelines['extended_rule']?.exceptions).toBeDefined();
149
- expect(merged.guidelines['extended_rule']?.exceptions).toContain('simple_typo');
150
- expect(merged.guidelines['extended_rule']?.exceptions).toContain('config_change');
151
- });
152
- });
153
-
154
126
  describe('isConstraintEnabled', () => {
155
127
  it('启用的约束应该返回 true', () => {
156
128
  const loader = new ProjectConfigLoader(tempDir);
@@ -263,6 +235,47 @@ custom_constraints:
263
235
  });
264
236
  });
265
237
 
238
+ describe('preset 裁剪(内联自原 applyPreset)', () => {
239
+ it('options.preset 覆盖 config.yml 的 preset', () => {
240
+ fs.writeFileSync(
241
+ path.join(harnessDir, 'config.yml'),
242
+ `preset: standard`
243
+ );
244
+
245
+ const loader = new ProjectConfigLoader(tempDir);
246
+ loader.load();
247
+ const merged = loader.mergeConstraints({ preset: 'relaxed' });
248
+
249
+ // relaxed 仅启用 3 条铁律 + 2 条指导原则,禁用提示
250
+ expect(Object.keys(merged.ironLaws)).toHaveLength(3);
251
+ expect(Object.keys(merged.guidelines)).toHaveLength(2);
252
+ expect(Object.keys(merged.prompts ?? {})).toHaveLength(0);
253
+ expect(merged.disabled.length).toBeGreaterThan(0);
254
+ });
255
+
256
+ it('未知预设名回落 standard + stderr 警告', () => {
257
+ fs.writeFileSync(
258
+ path.join(harnessDir, 'config.yml'),
259
+ `preset: no_such_preset`
260
+ );
261
+
262
+ const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
263
+ try {
264
+ const loader = new ProjectConfigLoader(tempDir);
265
+ loader.load();
266
+ const merged = loader.mergeConstraints();
267
+
268
+ // 回落 standard = 全部启用
269
+ expect(merged.disabled).toEqual([]);
270
+ expect(errorSpy).toHaveBeenCalledWith(
271
+ expect.stringContaining('未知预设 "no_such_preset"')
272
+ );
273
+ } finally {
274
+ errorSpy.mockRestore();
275
+ }
276
+ });
277
+ });
278
+
266
279
  describe('getCustomConstraints', () => {
267
280
  it('应该返回自定义约束', () => {
268
281
  fs.writeFileSync(
@@ -0,0 +1,138 @@
1
+ /**
2
+ * 公共导出防回归(ADR-0003)
3
+ *
4
+ * 包根导出收敛为显式清单后,任何增删公共符号都必须显式评审:
5
+ * 改动 src/index.ts 导出清单时同步更新本文件的 EXPECTED_RUNTIME_EXPORTS,
6
+ * diff 即 PR 评审材料。
7
+ *
8
+ * 注意:Object.keys 只能看到运行时(值)导出;纯类型导出由
9
+ * src/index.ts 显式清单在编译期把关,不在本测试断言范围内。
10
+ */
11
+
12
+ const EXPECTED_RUNTIME_EXPORTS = [
13
+ 'AdaptiveTokenBudget',
14
+ 'AgentLifecycle',
15
+ 'CONSTRAINTS_END_MARKER',
16
+ 'CONSTRAINTS_START_MARKER',
17
+ 'CSOValidator',
18
+ 'CheckCache',
19
+ 'CheckpointValidator',
20
+ 'CleanStateManager',
21
+ 'ColdStartImporter',
22
+ 'CommandGate',
23
+ 'ConstraintViolationError',
24
+ 'ConstraintViolationHandler',
25
+ 'ContextTracker',
26
+ 'ContractGate',
27
+ 'DEFAULT_CLASSIFICATION_RULES',
28
+ 'DEFAULT_CODE_CHECKPOINTS',
29
+ 'DEFAULT_COMMAND_BLACKLIST',
30
+ 'DEFAULT_COMPACTION_CONFIG',
31
+ 'DEFAULT_DECAY_CONFIG',
32
+ 'DEFAULT_LEVEL_MAPPING',
33
+ 'DEFAULT_NONCODE_GLOBS',
34
+ 'DEFAULT_TEST_GLOBS',
35
+ 'DEFAULT_TRACE_FILE',
36
+ 'ErrorClassifier',
37
+ 'ErrorType',
38
+ 'FailureLevel',
39
+ 'FailureRecorder',
40
+ 'FileKnowledgeStore',
41
+ 'GATE_DEFINITIONS',
42
+ 'GUIDELINES',
43
+ 'HookPipeline',
44
+ 'HookRegistry',
45
+ 'IRON_LAWS',
46
+ 'KnowledgeAudit',
47
+ 'KnowledgeHealthScorer',
48
+ 'KnowledgeIngest',
49
+ 'KnowledgeInjector',
50
+ 'KnowledgeLifecycle',
51
+ 'KnowledgeLifecycleHooks',
52
+ 'KnowledgeLinter',
53
+ 'KnowledgeQuery',
54
+ 'MINIMAL_CHECKPOINTS',
55
+ 'PHASE_SUBJECT_RE',
56
+ 'PROMPTS',
57
+ 'PassesGate',
58
+ 'PerformanceGate',
59
+ 'ReferenceTracker',
60
+ 'ReviewGate',
61
+ 'SecurityGate',
62
+ 'SessionCompaction',
63
+ 'SessionManager',
64
+ 'SessionStartup',
65
+ 'SpecAcceptanceGate',
66
+ 'SpecValidator',
67
+ 'TESTED_BY_RE',
68
+ 'TESTS_NONE_RE',
69
+ 'TokenBudget',
70
+ 'TokenEstimator',
71
+ 'TraceAnalyzer',
72
+ 'TraceCollector',
73
+ 'assertGateRegistryClosed',
74
+ 'assertHookRegistryClosed',
75
+ 'bootstrapHarness',
76
+ 'bootstrapHarnessSync',
77
+ 'checkBeforeExecution',
78
+ 'checkConstraint',
79
+ 'checkConstraints',
80
+ 'classifyCommitFiles',
81
+ 'classifyError',
82
+ 'configureTraceCollector',
83
+ 'createAnalyzer',
84
+ 'createCheckerGate',
85
+ 'createCleanStateManager',
86
+ 'createCommandGate',
87
+ 'createContractGate',
88
+ 'createErrorClassifier',
89
+ 'createFailureRecorder',
90
+ 'createPassesGate',
91
+ 'createPerformanceGate',
92
+ 'createReviewGate',
93
+ 'createSecurityGate',
94
+ 'createSessionStartup',
95
+ 'createSpecAcceptanceGate',
96
+ 'decisionFromResult',
97
+ 'executeWithBlock',
98
+ 'executeWithCollect',
99
+ 'executeWithSafeBoolean',
100
+ 'extractCodeStructure',
101
+ 'findConstraintsByTrigger',
102
+ 'getAllConstraints',
103
+ 'getCommandGate',
104
+ 'getCommandRiskLevel',
105
+ 'getConstraint',
106
+ 'getEffectiveConstraints',
107
+ 'getEffectiveGates',
108
+ 'getFailureLevel',
109
+ 'getGate',
110
+ 'getRegistryPath',
111
+ 'getToolsDir',
112
+ 'getTraceCollector',
113
+ 'isCommandAllowed',
114
+ 'lintEffectiveConfig',
115
+ 'listRegisteredGates',
116
+ 'matchAnyGlob',
117
+ 'matchGlob',
118
+ 'migrateKnowledgeEntries',
119
+ 'registeredGateCount',
120
+ 'renderConstraintsByTrigger',
121
+ 'renderConstraintsSection',
122
+ 'resolveGlobs',
123
+ 'runGates',
124
+ 'sanitizeExternalContent',
125
+ 'toErrorStrategy',
126
+ 'validateAllSpecs',
127
+ 'validateSpec',
128
+ 'verifyContractPresence',
129
+ 'verifyPhaseFormat',
130
+ 'verifyTddChain',
131
+ ];
132
+
133
+ describe('公共导出清单(ADR-0003)', () => {
134
+ it('包根运行时导出键集合与显式清单一致', async () => {
135
+ const mod = await import('../index');
136
+ expect(Object.keys(mod).sort()).toEqual([...EXPECTED_RUNTIME_EXPORTS].sort());
137
+ });
138
+ });