@dommaker/harness 1.16.0 → 3.0.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 (884) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +7 -7
  3. package/dist/agents/index.d.ts +1 -2
  4. package/dist/agents/index.d.ts.map +1 -1
  5. package/dist/agents/index.js.map +1 -1
  6. package/dist/agents/lifecycle.d.ts +2 -34
  7. package/dist/agents/lifecycle.d.ts.map +1 -1
  8. package/dist/agents/lifecycle.js +1 -103
  9. package/dist/agents/lifecycle.js.map +1 -1
  10. package/dist/agents/types.d.ts +1 -19
  11. package/dist/agents/types.d.ts.map +1 -1
  12. package/dist/{hooks → bootstrap}/bootstrap.d.ts +9 -3
  13. package/dist/bootstrap/bootstrap.d.ts.map +1 -0
  14. package/dist/{hooks → bootstrap}/bootstrap.js +26 -30
  15. package/dist/bootstrap/bootstrap.js.map +1 -0
  16. package/dist/{hooks → bootstrap}/index.d.ts +3 -2
  17. package/dist/bootstrap/index.d.ts.map +1 -0
  18. package/dist/{hooks → bootstrap}/index.js +3 -2
  19. package/dist/bootstrap/index.js.map +1 -0
  20. package/dist/cli/command-contract.d.ts +6 -9
  21. package/dist/cli/command-contract.d.ts.map +1 -1
  22. package/dist/cli/command-contract.js +6 -0
  23. package/dist/cli/command-contract.js.map +1 -1
  24. package/dist/cli/commands/acceptance.d.ts.map +1 -1
  25. package/dist/cli/commands/acceptance.js +9 -8
  26. package/dist/cli/commands/acceptance.js.map +1 -1
  27. package/dist/cli/commands/check.d.ts +1 -1
  28. package/dist/cli/commands/check.d.ts.map +1 -1
  29. package/dist/cli/commands/check.js +12 -5
  30. package/dist/cli/commands/check.js.map +1 -1
  31. package/dist/cli/commands/command.d.ts.map +1 -1
  32. package/dist/cli/commands/command.js +9 -5
  33. package/dist/cli/commands/command.js.map +1 -1
  34. package/dist/cli/commands/constraints-pack-proposal.d.ts.map +1 -1
  35. package/dist/cli/commands/constraints-pack-proposal.js +11 -8
  36. package/dist/cli/commands/constraints-pack-proposal.js.map +1 -1
  37. package/dist/cli/commands/constraints-reactivate.d.ts +10 -2
  38. package/dist/cli/commands/constraints-reactivate.d.ts.map +1 -1
  39. package/dist/cli/commands/constraints-reactivate.js +2 -6
  40. package/dist/cli/commands/constraints-reactivate.js.map +1 -1
  41. package/dist/cli/commands/constraints-retire.d.ts +23 -5
  42. package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
  43. package/dist/cli/commands/constraints-retire.js +19 -9
  44. package/dist/cli/commands/constraints-retire.js.map +1 -1
  45. package/dist/cli/commands/contract.d.ts.map +1 -1
  46. package/dist/cli/commands/contract.js +24 -16
  47. package/dist/cli/commands/contract.js.map +1 -1
  48. package/dist/cli/commands/definitions.d.ts +2 -73
  49. package/dist/cli/commands/definitions.d.ts.map +1 -1
  50. package/dist/cli/commands/definitions.js +13 -17
  51. package/dist/cli/commands/definitions.js.map +1 -1
  52. package/dist/cli/commands/failure.d.ts.map +1 -1
  53. package/dist/cli/commands/failure.js +5 -6
  54. package/dist/cli/commands/failure.js.map +1 -1
  55. package/dist/cli/commands/init/ci-platform.d.ts +35 -0
  56. package/dist/cli/commands/init/ci-platform.d.ts.map +1 -0
  57. package/dist/cli/commands/init/ci-platform.js +59 -0
  58. package/dist/cli/commands/init/ci-platform.js.map +1 -0
  59. package/dist/cli/commands/init/ci-wiring.d.ts +20 -0
  60. package/dist/cli/commands/init/ci-wiring.d.ts.map +1 -0
  61. package/dist/cli/commands/init/ci-wiring.js +72 -0
  62. package/dist/cli/commands/init/ci-wiring.js.map +1 -0
  63. package/dist/cli/commands/init/git-hooks.d.ts +15 -0
  64. package/dist/cli/commands/init/git-hooks.d.ts.map +1 -0
  65. package/dist/cli/commands/init/git-hooks.js +64 -0
  66. package/dist/cli/commands/init/git-hooks.js.map +1 -0
  67. package/dist/cli/commands/init/governance.d.ts +14 -0
  68. package/dist/cli/commands/init/governance.d.ts.map +1 -0
  69. package/dist/cli/commands/init/governance.js +132 -0
  70. package/dist/cli/commands/init/governance.js.map +1 -0
  71. package/dist/cli/commands/{init.d.ts → init/index.d.ts} +13 -14
  72. package/dist/cli/commands/init/index.d.ts.map +1 -0
  73. package/dist/cli/commands/init/index.js +148 -0
  74. package/dist/cli/commands/init/index.js.map +1 -0
  75. package/dist/cli/commands/init/output-style.d.ts +19 -0
  76. package/dist/cli/commands/init/output-style.d.ts.map +1 -0
  77. package/dist/cli/commands/init/output-style.js +110 -0
  78. package/dist/cli/commands/init/output-style.js.map +1 -0
  79. package/dist/cli/commands/init/presets.d.ts +26 -0
  80. package/dist/cli/commands/init/presets.d.ts.map +1 -0
  81. package/dist/cli/commands/init/presets.js +104 -0
  82. package/dist/cli/commands/init/presets.js.map +1 -0
  83. package/dist/cli/commands/init/snippets.d.ts +18 -0
  84. package/dist/cli/commands/init/snippets.d.ts.map +1 -0
  85. package/dist/cli/commands/init/snippets.js +49 -0
  86. package/dist/cli/commands/init/snippets.js.map +1 -0
  87. package/dist/cli/commands/knowledge/audit.d.ts +30 -0
  88. package/dist/cli/commands/knowledge/audit.d.ts.map +1 -0
  89. package/dist/cli/commands/knowledge/audit.js +114 -0
  90. package/dist/cli/commands/knowledge/audit.js.map +1 -0
  91. package/dist/cli/commands/knowledge/decay.d.ts +19 -0
  92. package/dist/cli/commands/knowledge/decay.d.ts.map +1 -0
  93. package/dist/cli/commands/knowledge/decay.js +48 -0
  94. package/dist/cli/commands/knowledge/decay.js.map +1 -0
  95. package/dist/cli/commands/knowledge/health.d.ts +38 -0
  96. package/dist/cli/commands/knowledge/health.d.ts.map +1 -0
  97. package/dist/cli/commands/knowledge/health.js +178 -0
  98. package/dist/cli/commands/knowledge/health.js.map +1 -0
  99. package/dist/cli/commands/knowledge/import.d.ts +26 -0
  100. package/dist/cli/commands/knowledge/import.d.ts.map +1 -0
  101. package/dist/cli/commands/knowledge/import.js +63 -0
  102. package/dist/cli/commands/knowledge/import.js.map +1 -0
  103. package/dist/cli/commands/knowledge/index.d.ts +25 -0
  104. package/dist/cli/commands/knowledge/index.d.ts.map +1 -0
  105. package/dist/cli/commands/knowledge/index.js +84 -0
  106. package/dist/cli/commands/knowledge/index.js.map +1 -0
  107. package/dist/cli/commands/knowledge/list.d.ts +25 -0
  108. package/dist/cli/commands/knowledge/list.d.ts.map +1 -0
  109. package/dist/cli/commands/knowledge/list.js +60 -0
  110. package/dist/cli/commands/knowledge/list.js.map +1 -0
  111. package/dist/cli/commands/knowledge/search.d.ts +32 -0
  112. package/dist/cli/commands/knowledge/search.d.ts.map +1 -0
  113. package/dist/cli/commands/knowledge/search.js +72 -0
  114. package/dist/cli/commands/knowledge/search.js.map +1 -0
  115. package/dist/cli/commands/knowledge/shared.d.ts +14 -0
  116. package/dist/cli/commands/knowledge/shared.d.ts.map +1 -0
  117. package/dist/cli/commands/knowledge/shared.js +6 -0
  118. package/dist/cli/commands/knowledge/shared.js.map +1 -0
  119. package/dist/cli/commands/knowledge/snapshot.d.ts +18 -0
  120. package/dist/cli/commands/knowledge/snapshot.d.ts.map +1 -0
  121. package/dist/cli/commands/knowledge/snapshot.js +34 -0
  122. package/dist/cli/commands/knowledge/snapshot.js.map +1 -0
  123. package/dist/cli/commands/knowledge/stats.d.ts +26 -0
  124. package/dist/cli/commands/knowledge/stats.d.ts.map +1 -0
  125. package/dist/cli/commands/knowledge/stats.js +132 -0
  126. package/dist/cli/commands/knowledge/stats.js.map +1 -0
  127. package/dist/cli/commands/knowledge/store-access.d.ts +25 -0
  128. package/dist/cli/commands/knowledge/store-access.d.ts.map +1 -0
  129. package/dist/cli/commands/knowledge/store-access.js +69 -0
  130. package/dist/cli/commands/knowledge/store-access.js.map +1 -0
  131. package/dist/cli/commands/knowledge-view.d.ts +8 -19
  132. package/dist/cli/commands/knowledge-view.d.ts.map +1 -1
  133. package/dist/cli/commands/knowledge-view.js +12 -63
  134. package/dist/cli/commands/knowledge-view.js.map +1 -1
  135. package/dist/cli/commands/passes-gate.d.ts.map +1 -1
  136. package/dist/cli/commands/passes-gate.js +19 -8
  137. package/dist/cli/commands/passes-gate.js.map +1 -1
  138. package/dist/cli/commands/performance.js.map +1 -1
  139. package/dist/cli/commands/release.d.ts +1 -1
  140. package/dist/cli/commands/release.d.ts.map +1 -1
  141. package/dist/cli/commands/release.js +25 -59
  142. package/dist/cli/commands/release.js.map +1 -1
  143. package/dist/cli/commands/review.d.ts.map +1 -1
  144. package/dist/cli/commands/review.js +17 -5
  145. package/dist/cli/commands/review.js.map +1 -1
  146. package/dist/cli/commands/security.d.ts.map +1 -1
  147. package/dist/cli/commands/security.js +13 -8
  148. package/dist/cli/commands/security.js.map +1 -1
  149. package/dist/{core → cli/commands}/spec/validator.d.ts +10 -19
  150. package/dist/cli/commands/spec/validator.d.ts.map +1 -0
  151. package/dist/{core → cli/commands}/spec/validator.js +52 -78
  152. package/dist/cli/commands/spec/validator.js.map +1 -0
  153. package/dist/cli/commands/spec-baseline-check.d.ts +8 -41
  154. package/dist/cli/commands/spec-baseline-check.d.ts.map +1 -1
  155. package/dist/cli/commands/spec-baseline-check.js +32 -238
  156. package/dist/cli/commands/spec-baseline-check.js.map +1 -1
  157. package/dist/cli/commands/spec.d.ts +1 -1
  158. package/dist/cli/commands/spec.d.ts.map +1 -1
  159. package/dist/cli/commands/spec.js +14 -11
  160. package/dist/cli/commands/spec.js.map +1 -1
  161. package/dist/cli/commands/status.d.ts +0 -2
  162. package/dist/cli/commands/status.d.ts.map +1 -1
  163. package/dist/cli/commands/status.js +2 -2
  164. package/dist/cli/commands/status.js.map +1 -1
  165. package/dist/cli/commands/sync-docs/agents-syncer.js +31 -55
  166. package/dist/cli/commands/sync-docs/agents-syncer.js.map +1 -1
  167. package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts +1 -1
  168. package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts.map +1 -1
  169. package/dist/cli/commands/sync-docs/capabilities-syncer.js +13 -13
  170. package/dist/cli/commands/sync-docs/capabilities-syncer.js.map +1 -1
  171. package/dist/cli/commands/sync-docs/compact.d.ts +9 -0
  172. package/dist/cli/commands/sync-docs/compact.d.ts.map +1 -0
  173. package/dist/cli/commands/sync-docs/compact.js +73 -0
  174. package/dist/cli/commands/sync-docs/compact.js.map +1 -0
  175. package/dist/cli/commands/sync-docs/context-syncer.d.ts.map +1 -1
  176. package/dist/cli/commands/sync-docs/context-syncer.js +17 -36
  177. package/dist/cli/commands/sync-docs/context-syncer.js.map +1 -1
  178. package/dist/cli/commands/sync-docs/gate.d.ts +27 -0
  179. package/dist/cli/commands/sync-docs/gate.d.ts.map +1 -0
  180. package/dist/cli/commands/sync-docs/gate.js +72 -0
  181. package/dist/cli/commands/sync-docs/gate.js.map +1 -0
  182. package/dist/cli/commands/sync-docs/index.d.ts +13 -27
  183. package/dist/cli/commands/sync-docs/index.d.ts.map +1 -1
  184. package/dist/cli/commands/sync-docs/index.js +19 -529
  185. package/dist/cli/commands/sync-docs/index.js.map +1 -1
  186. package/dist/cli/commands/sync-docs/main-flow.d.ts +21 -0
  187. package/dist/cli/commands/sync-docs/main-flow.d.ts.map +1 -0
  188. package/dist/cli/commands/sync-docs/main-flow.js +93 -0
  189. package/dist/cli/commands/sync-docs/main-flow.js.map +1 -0
  190. package/dist/cli/commands/sync-docs/project-reader.d.ts +1 -1
  191. package/dist/cli/commands/sync-docs/project-reader.d.ts.map +1 -1
  192. package/dist/cli/commands/sync-docs/project-reader.js +18 -26
  193. package/dist/cli/commands/sync-docs/project-reader.js.map +1 -1
  194. package/dist/cli/commands/sync-docs/sync-output.d.ts +15 -0
  195. package/dist/cli/commands/sync-docs/sync-output.d.ts.map +1 -0
  196. package/dist/cli/commands/sync-docs/sync-output.js +217 -0
  197. package/dist/cli/commands/sync-docs/sync-output.js.map +1 -0
  198. package/dist/cli/commands/sync-docs/sync-state.d.ts +71 -0
  199. package/dist/cli/commands/sync-docs/sync-state.d.ts.map +1 -0
  200. package/dist/cli/commands/sync-docs/sync-state.js +274 -0
  201. package/dist/cli/commands/sync-docs/sync-state.js.map +1 -0
  202. package/dist/cli/commands/sync-docs/sync-writes.d.ts +12 -0
  203. package/dist/cli/commands/sync-docs/sync-writes.d.ts.map +1 -0
  204. package/dist/cli/commands/sync-docs/sync-writes.js +72 -0
  205. package/dist/cli/commands/sync-docs/sync-writes.js.map +1 -0
  206. package/dist/cli/commands/validate.d.ts +0 -2
  207. package/dist/cli/commands/validate.d.ts.map +1 -1
  208. package/dist/cli/commands/validate.js +13 -6
  209. package/dist/cli/commands/validate.js.map +1 -1
  210. package/dist/cli/gate-command.d.ts +1 -1
  211. package/dist/cli/gate-command.d.ts.map +1 -1
  212. package/dist/context/index.d.ts +2 -4
  213. package/dist/context/index.d.ts.map +1 -1
  214. package/dist/context/index.js +2 -5
  215. package/dist/context/index.js.map +1 -1
  216. package/dist/context/session-manager.d.ts +2 -6
  217. package/dist/context/session-manager.d.ts.map +1 -1
  218. package/dist/context/session-manager.js +27 -84
  219. package/dist/context/session-manager.js.map +1 -1
  220. package/dist/context/types.d.ts +3 -25
  221. package/dist/context/types.d.ts.map +1 -1
  222. package/dist/context/types.js +2 -1
  223. package/dist/context/types.js.map +1 -1
  224. package/dist/core/app-constraints-loader.d.ts +1 -1
  225. package/dist/core/app-constraints-loader.d.ts.map +1 -1
  226. package/dist/core/app-constraints-loader.js +6 -23
  227. package/dist/core/app-constraints-loader.js.map +1 -1
  228. package/dist/core/constraint-lifecycle.d.ts +3 -8
  229. package/dist/core/constraint-lifecycle.d.ts.map +1 -1
  230. package/dist/core/constraint-lifecycle.js +27 -31
  231. package/dist/core/constraint-lifecycle.js.map +1 -1
  232. package/dist/core/constraints/capabilities-parser.d.ts +2 -1
  233. package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
  234. package/dist/core/constraints/capabilities-parser.js +4 -6
  235. package/dist/core/constraints/capabilities-parser.js.map +1 -1
  236. package/dist/core/constraints/check-cache.d.ts +4 -43
  237. package/dist/core/constraints/check-cache.d.ts.map +1 -1
  238. package/dist/core/constraints/check-cache.js +6 -51
  239. package/dist/core/constraints/check-cache.js.map +1 -1
  240. package/dist/core/constraints/checker.d.ts +0 -16
  241. package/dist/core/constraints/checker.d.ts.map +1 -1
  242. package/dist/core/constraints/checker.js +23 -64
  243. package/dist/core/constraints/checker.js.map +1 -1
  244. package/dist/core/constraints/checkers/capability-sync.js +3 -3
  245. package/dist/core/constraints/checkers/capability-sync.js.map +1 -1
  246. package/dist/core/constraints/checkers/context-doc-sync.js +2 -2
  247. package/dist/core/constraints/checkers/context-doc-sync.js.map +1 -1
  248. package/dist/core/constraints/checkers/docs-freshness.js +5 -5
  249. package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
  250. package/dist/core/constraints/checkers/index.d.ts +17 -3
  251. package/dist/core/constraints/checkers/index.d.ts.map +1 -1
  252. package/dist/core/constraints/checkers/index.js +22 -10
  253. package/dist/core/constraints/checkers/index.js.map +1 -1
  254. package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts.map +1 -1
  255. package/dist/core/constraints/checkers/no-hardcoded-credentials.js +5 -34
  256. package/dist/core/constraints/checkers/no-hardcoded-credentials.js.map +1 -1
  257. package/dist/core/constraints/checkers/no-test-simplification.d.ts.map +1 -1
  258. package/dist/core/constraints/checkers/no-test-simplification.js +11 -33
  259. package/dist/core/constraints/checkers/no-test-simplification.js.map +1 -1
  260. package/dist/core/constraints/checkers/templated/exec.d.ts.map +1 -1
  261. package/dist/core/constraints/checkers/templated/exec.js +4 -8
  262. package/dist/core/constraints/checkers/templated/exec.js.map +1 -1
  263. package/dist/core/constraints/checkers/templated/file-exists.js +1 -1
  264. package/dist/core/constraints/checkers/templated/file-exists.js.map +1 -1
  265. package/dist/core/constraints/checkers/templated/regex-scan.d.ts.map +1 -1
  266. package/dist/core/constraints/checkers/templated/regex-scan.js +8 -26
  267. package/dist/core/constraints/checkers/templated/regex-scan.js.map +1 -1
  268. package/dist/core/constraints/checkers/types.d.ts +10 -33
  269. package/dist/core/constraints/checkers/types.d.ts.map +1 -1
  270. package/dist/core/constraints/checkers/types.js +6 -46
  271. package/dist/core/constraints/checkers/types.js.map +1 -1
  272. package/dist/core/constraints/context-builder.d.ts +8 -26
  273. package/dist/core/constraints/context-builder.d.ts.map +1 -1
  274. package/dist/core/constraints/context-builder.js +9 -102
  275. package/dist/core/constraints/context-builder.js.map +1 -1
  276. package/dist/core/constraints/definitions/{iron-laws.d.ts → errors.d.ts} +1 -2
  277. package/dist/core/constraints/definitions/errors.d.ts.map +1 -0
  278. package/dist/core/constraints/definitions/{iron-laws.js → errors.js} +1 -21
  279. package/dist/core/constraints/definitions/errors.js.map +1 -0
  280. package/dist/core/constraints/definitions/{guidelines.d.ts → warnings.d.ts} +1 -2
  281. package/dist/core/constraints/definitions/warnings.d.ts.map +1 -0
  282. package/dist/core/constraints/definitions/{guidelines.js → warnings.js} +18 -5
  283. package/dist/core/constraints/definitions/warnings.js.map +1 -0
  284. package/dist/core/constraints/definitions.d.ts +2 -1
  285. package/dist/core/constraints/definitions.d.ts.map +1 -1
  286. package/dist/core/constraints/definitions.js +6 -5
  287. package/dist/core/constraints/definitions.js.map +1 -1
  288. package/dist/core/constraints/doc-freshness/runner.d.ts +0 -9
  289. package/dist/core/constraints/doc-freshness/runner.d.ts.map +1 -1
  290. package/dist/core/constraints/doc-freshness/runner.js +192 -224
  291. package/dist/core/constraints/doc-freshness/runner.js.map +1 -1
  292. package/dist/core/constraints/find-constraint.d.ts +14 -0
  293. package/dist/core/constraints/find-constraint.d.ts.map +1 -0
  294. package/dist/core/constraints/find-constraint.js +25 -0
  295. package/dist/core/constraints/find-constraint.js.map +1 -0
  296. package/dist/core/constraints/git-evidence.d.ts.map +1 -1
  297. package/dist/core/constraints/git-evidence.js +2 -0
  298. package/dist/core/constraints/git-evidence.js.map +1 -1
  299. package/dist/core/constraints/governance-accessors.d.ts +54 -0
  300. package/dist/core/constraints/governance-accessors.d.ts.map +1 -0
  301. package/dist/core/constraints/governance-accessors.js +62 -0
  302. package/dist/core/constraints/governance-accessors.js.map +1 -0
  303. package/dist/core/constraints/index.d.ts +4 -4
  304. package/dist/core/constraints/index.d.ts.map +1 -1
  305. package/dist/core/constraints/index.js +1 -4
  306. package/dist/core/constraints/index.js.map +1 -1
  307. package/dist/core/constraints/injection-writer.d.ts +1 -0
  308. package/dist/core/constraints/injection-writer.d.ts.map +1 -1
  309. package/dist/core/constraints/injection-writer.js +3 -6
  310. package/dist/core/constraints/injection-writer.js.map +1 -1
  311. package/dist/core/constraints/pack-proposal.d.ts.map +1 -1
  312. package/dist/core/constraints/pack-proposal.js +3 -14
  313. package/dist/core/constraints/pack-proposal.js.map +1 -1
  314. package/dist/core/constraints/run-env.d.ts +1 -13
  315. package/dist/core/constraints/run-env.d.ts.map +1 -1
  316. package/dist/core/constraints/run-env.js +2 -23
  317. package/dist/core/constraints/run-env.js.map +1 -1
  318. package/dist/core/constraints/triggers.d.ts +10 -6
  319. package/dist/core/constraints/triggers.d.ts.map +1 -1
  320. package/dist/core/constraints/triggers.js +11 -5
  321. package/dist/core/constraints/triggers.js.map +1 -1
  322. package/dist/core/constraints/usage-report.d.ts +0 -6
  323. package/dist/core/constraints/usage-report.d.ts.map +1 -1
  324. package/dist/core/constraints/usage-report.js +0 -9
  325. package/dist/core/constraints/usage-report.js.map +1 -1
  326. package/dist/core/index.d.ts +5 -4
  327. package/dist/core/index.d.ts.map +1 -1
  328. package/dist/core/index.js +7 -8
  329. package/dist/core/index.js.map +1 -1
  330. package/dist/core/project-config-loader.d.ts +5 -41
  331. package/dist/core/project-config-loader.d.ts.map +1 -1
  332. package/dist/core/project-config-loader.js +4 -49
  333. package/dist/core/project-config-loader.js.map +1 -1
  334. package/dist/core/spec/baseline-check.d.ts +54 -0
  335. package/dist/core/spec/baseline-check.d.ts.map +1 -0
  336. package/dist/core/spec/baseline-check.js +261 -0
  337. package/dist/core/spec/baseline-check.js.map +1 -0
  338. package/dist/core/validators/check-handlers/command.d.ts.map +1 -1
  339. package/dist/core/validators/check-handlers/command.js +7 -4
  340. package/dist/core/validators/check-handlers/command.js.map +1 -1
  341. package/dist/core/validators/check-handlers/file.d.ts.map +1 -1
  342. package/dist/core/validators/check-handlers/file.js +49 -5
  343. package/dist/core/validators/check-handlers/file.js.map +1 -1
  344. package/dist/core/validators/check-handlers/http.d.ts.map +1 -1
  345. package/dist/core/validators/check-handlers/http.js +6 -4
  346. package/dist/core/validators/check-handlers/http.js.map +1 -1
  347. package/dist/core/validators/check-handlers/output.d.ts +1 -1
  348. package/dist/core/validators/check-handlers/output.d.ts.map +1 -1
  349. package/dist/core/validators/check-handlers/output.js +2 -1
  350. package/dist/core/validators/check-handlers/output.js.map +1 -1
  351. package/dist/core/validators/checkpoint.d.ts +5 -13
  352. package/dist/core/validators/checkpoint.d.ts.map +1 -1
  353. package/dist/core/validators/checkpoint.js +53 -80
  354. package/dist/core/validators/checkpoint.js.map +1 -1
  355. package/dist/core/validators/cso.d.ts +1 -4
  356. package/dist/core/validators/cso.d.ts.map +1 -1
  357. package/dist/core/validators/cso.js +1 -9
  358. package/dist/core/validators/cso.js.map +1 -1
  359. package/dist/core/validators/passes-gate.d.ts +2 -5
  360. package/dist/core/validators/passes-gate.d.ts.map +1 -1
  361. package/dist/core/validators/passes-gate.js +21 -35
  362. package/dist/core/validators/passes-gate.js.map +1 -1
  363. package/dist/failure/classifier.d.ts +2 -21
  364. package/dist/failure/classifier.d.ts.map +1 -1
  365. package/dist/failure/classifier.js +7 -42
  366. package/dist/failure/classifier.js.map +1 -1
  367. package/dist/failure/error-types.d.ts +48 -0
  368. package/dist/failure/error-types.d.ts.map +1 -0
  369. package/dist/failure/error-types.js +122 -0
  370. package/dist/failure/error-types.js.map +1 -0
  371. package/dist/failure/index.d.ts +4 -3
  372. package/dist/failure/index.d.ts.map +1 -1
  373. package/dist/failure/index.js +8 -10
  374. package/dist/failure/index.js.map +1 -1
  375. package/dist/failure/recorder.d.ts +7 -27
  376. package/dist/failure/recorder.d.ts.map +1 -1
  377. package/dist/failure/recorder.js +11 -64
  378. package/dist/failure/recorder.js.map +1 -1
  379. package/dist/gates/acceptance.d.ts +43 -19
  380. package/dist/gates/acceptance.d.ts.map +1 -1
  381. package/dist/gates/acceptance.js +148 -122
  382. package/dist/gates/acceptance.js.map +1 -1
  383. package/dist/gates/command.d.ts +1 -17
  384. package/dist/gates/command.d.ts.map +1 -1
  385. package/dist/gates/command.js +0 -29
  386. package/dist/gates/command.js.map +1 -1
  387. package/dist/gates/contract.d.ts +11 -10
  388. package/dist/gates/contract.d.ts.map +1 -1
  389. package/dist/gates/contract.js +55 -74
  390. package/dist/gates/contract.js.map +1 -1
  391. package/dist/gates/definitions.d.ts +1 -1
  392. package/dist/gates/performance.d.ts +2 -16
  393. package/dist/gates/performance.d.ts.map +1 -1
  394. package/dist/gates/performance.js +18 -27
  395. package/dist/gates/performance.js.map +1 -1
  396. package/dist/gates/registry.d.ts.map +1 -1
  397. package/dist/gates/registry.js +3 -2
  398. package/dist/gates/registry.js.map +1 -1
  399. package/dist/gates/review.d.ts +1 -9
  400. package/dist/gates/review.d.ts.map +1 -1
  401. package/dist/gates/review.js +38 -21
  402. package/dist/gates/review.js.map +1 -1
  403. package/dist/gates/security.d.ts +6 -9
  404. package/dist/gates/security.d.ts.map +1 -1
  405. package/dist/gates/security.js +42 -76
  406. package/dist/gates/security.js.map +1 -1
  407. package/dist/gates/types.d.ts +11 -78
  408. package/dist/gates/types.d.ts.map +1 -1
  409. package/dist/gates/types.js +5 -1
  410. package/dist/gates/types.js.map +1 -1
  411. package/dist/index.d.ts +20 -13
  412. package/dist/index.d.ts.map +1 -1
  413. package/dist/index.js +14 -18
  414. package/dist/index.js.map +1 -1
  415. package/dist/knowledge/audit-dimensions.d.ts +45 -0
  416. package/dist/knowledge/audit-dimensions.d.ts.map +1 -0
  417. package/dist/knowledge/audit-dimensions.js +144 -0
  418. package/dist/knowledge/audit-dimensions.js.map +1 -0
  419. package/dist/knowledge/audit-rules.d.ts +43 -0
  420. package/dist/knowledge/audit-rules.d.ts.map +1 -0
  421. package/dist/knowledge/audit-rules.js +272 -0
  422. package/dist/knowledge/audit-rules.js.map +1 -0
  423. package/dist/knowledge/audit-scoring.d.ts +6 -60
  424. package/dist/knowledge/audit-scoring.d.ts.map +1 -1
  425. package/dist/knowledge/audit-scoring.js +8 -391
  426. package/dist/knowledge/audit-scoring.js.map +1 -1
  427. package/dist/knowledge/audit.d.ts +6 -3
  428. package/dist/knowledge/audit.d.ts.map +1 -1
  429. package/dist/knowledge/audit.js +12 -7
  430. package/dist/knowledge/audit.js.map +1 -1
  431. package/dist/knowledge/{import.d.ts → cold-start.d.ts} +2 -3
  432. package/dist/knowledge/cold-start.d.ts.map +1 -0
  433. package/dist/knowledge/{import.js → cold-start.js} +136 -182
  434. package/dist/knowledge/cold-start.js.map +1 -0
  435. package/dist/knowledge/index-generator.d.ts +2 -0
  436. package/dist/knowledge/index-generator.d.ts.map +1 -1
  437. package/dist/knowledge/index-generator.js +43 -50
  438. package/dist/knowledge/index-generator.js.map +1 -1
  439. package/dist/knowledge/index.d.ts +7 -7
  440. package/dist/knowledge/index.d.ts.map +1 -1
  441. package/dist/knowledge/index.js +4 -9
  442. package/dist/knowledge/index.js.map +1 -1
  443. package/dist/knowledge/ingest.d.ts +50 -6
  444. package/dist/knowledge/ingest.d.ts.map +1 -1
  445. package/dist/knowledge/ingest.js +109 -16
  446. package/dist/knowledge/ingest.js.map +1 -1
  447. package/dist/knowledge/lifecycle.d.ts +0 -5
  448. package/dist/knowledge/lifecycle.d.ts.map +1 -1
  449. package/dist/knowledge/lifecycle.js +29 -41
  450. package/dist/knowledge/lifecycle.js.map +1 -1
  451. package/dist/knowledge/query.d.ts +1 -1
  452. package/dist/knowledge/query.d.ts.map +1 -1
  453. package/dist/knowledge/query.js +8 -8
  454. package/dist/knowledge/query.js.map +1 -1
  455. package/dist/knowledge/store.d.ts +4 -7
  456. package/dist/knowledge/store.d.ts.map +1 -1
  457. package/dist/knowledge/store.js +26 -63
  458. package/dist/knowledge/store.js.map +1 -1
  459. package/dist/knowledge/types.d.ts +2 -36
  460. package/dist/knowledge/types.d.ts.map +1 -1
  461. package/dist/knowledge/types.js +2 -3
  462. package/dist/knowledge/types.js.map +1 -1
  463. package/dist/monitoring/analyzer-base.d.ts +1 -10
  464. package/dist/monitoring/analyzer-base.d.ts.map +1 -1
  465. package/dist/monitoring/analyzer-base.js +1 -58
  466. package/dist/monitoring/analyzer-base.js.map +1 -1
  467. package/dist/monitoring/trace-analyzer.d.ts +3 -54
  468. package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
  469. package/dist/monitoring/trace-analyzer.js +9 -136
  470. package/dist/monitoring/trace-analyzer.js.map +1 -1
  471. package/dist/monitoring/traces.d.ts +1 -14
  472. package/dist/monitoring/traces.d.ts.map +1 -1
  473. package/dist/monitoring/traces.js +9 -29
  474. package/dist/monitoring/traces.js.map +1 -1
  475. package/dist/pretool-use-hook.d.ts +1 -1
  476. package/dist/pretool-use-hook.d.ts.map +1 -1
  477. package/dist/pretool-use-hook.js +12 -19
  478. package/dist/pretool-use-hook.js.map +1 -1
  479. package/dist/release/integrity.d.ts.map +1 -1
  480. package/dist/release/integrity.js +8 -8
  481. package/dist/release/integrity.js.map +1 -1
  482. package/dist/sdd/index-generator.d.ts.map +1 -1
  483. package/dist/sdd/index-generator.js +4 -0
  484. package/dist/sdd/index-generator.js.map +1 -1
  485. package/dist/types/checkpoint.d.ts +8 -8
  486. package/dist/types/checkpoint.d.ts.map +1 -1
  487. package/dist/types/command-definition.d.ts +81 -0
  488. package/dist/types/command-definition.d.ts.map +1 -0
  489. package/dist/types/command-definition.js +10 -0
  490. package/dist/types/command-definition.js.map +1 -0
  491. package/dist/types/command-io.d.ts +19 -0
  492. package/dist/types/command-io.d.ts.map +1 -0
  493. package/dist/types/command-io.js +3 -0
  494. package/dist/types/command-io.js.map +1 -0
  495. package/dist/types/constraint.d.ts +3 -24
  496. package/dist/types/constraint.d.ts.map +1 -1
  497. package/dist/types/constraint.js.map +1 -1
  498. package/dist/types/failure.d.ts +6 -39
  499. package/dist/types/failure.d.ts.map +1 -1
  500. package/dist/types/failure.js +6 -112
  501. package/dist/types/failure.js.map +1 -1
  502. package/dist/types/gate.d.ts +72 -0
  503. package/dist/types/gate.d.ts.map +1 -0
  504. package/dist/types/gate.js +13 -0
  505. package/dist/types/gate.js.map +1 -0
  506. package/dist/types/spec.d.ts +0 -4
  507. package/dist/types/spec.d.ts.map +1 -1
  508. package/dist/types/trace.d.ts +0 -4
  509. package/dist/types/trace.d.ts.map +1 -1
  510. package/dist/utils/attempt.d.ts +22 -0
  511. package/dist/utils/attempt.d.ts.map +1 -0
  512. package/dist/utils/attempt.js +40 -0
  513. package/dist/utils/attempt.js.map +1 -0
  514. package/dist/utils/clip.d.ts +8 -0
  515. package/dist/utils/clip.d.ts.map +1 -0
  516. package/dist/utils/clip.js +15 -0
  517. package/dist/utils/clip.js.map +1 -0
  518. package/dist/utils/detect-source-roots.d.ts.map +1 -1
  519. package/dist/utils/detect-source-roots.js +42 -51
  520. package/dist/utils/detect-source-roots.js.map +1 -1
  521. package/dist/utils/diff-parse.d.ts +31 -0
  522. package/dist/utils/diff-parse.d.ts.map +1 -0
  523. package/dist/utils/diff-parse.js +72 -0
  524. package/dist/utils/diff-parse.js.map +1 -0
  525. package/dist/utils/file-walk.d.ts +2 -1
  526. package/dist/utils/file-walk.d.ts.map +1 -1
  527. package/dist/utils/file-walk.js +3 -8
  528. package/dist/utils/file-walk.js.map +1 -1
  529. package/dist/utils/guards.d.ts +6 -0
  530. package/dist/utils/guards.d.ts.map +1 -0
  531. package/dist/utils/guards.js +11 -0
  532. package/dist/utils/guards.js.map +1 -0
  533. package/dist/utils/jsonl.d.ts +0 -12
  534. package/dist/utils/jsonl.d.ts.map +1 -1
  535. package/dist/utils/jsonl.js +0 -12
  536. package/dist/utils/jsonl.js.map +1 -1
  537. package/dist/utils/log-rotate.d.ts +14 -0
  538. package/dist/utils/log-rotate.d.ts.map +1 -0
  539. package/dist/utils/log-rotate.js +74 -0
  540. package/dist/utils/log-rotate.js.map +1 -0
  541. package/dist/utils/numeric-flag.d.ts +10 -2
  542. package/dist/utils/numeric-flag.d.ts.map +1 -1
  543. package/dist/utils/numeric-flag.js +17 -2
  544. package/dist/utils/numeric-flag.js.map +1 -1
  545. package/dist/utils/package-json.d.ts +49 -0
  546. package/dist/utils/package-json.d.ts.map +1 -0
  547. package/dist/utils/package-json.js +78 -0
  548. package/dist/utils/package-json.js.map +1 -0
  549. package/dist/utils/package-version.d.ts +5 -2
  550. package/dist/utils/package-version.d.ts.map +1 -1
  551. package/dist/utils/package-version.js +8 -11
  552. package/dist/utils/package-version.js.map +1 -1
  553. package/package.json +1 -6
  554. package/src/CONTEXT.md +12 -11
  555. package/src/__tests__/acceptance-gate.test.ts +23 -51
  556. package/src/__tests__/app-constraints-loader.test.ts +5 -7
  557. package/src/__tests__/checker-extra.test.ts +12 -80
  558. package/src/__tests__/checker-primitives-sdk.test.ts +3 -18
  559. package/src/__tests__/checker.test.ts +5 -7
  560. package/src/__tests__/checkpoint.test.ts +45 -59
  561. package/src/__tests__/context-files-resolution.test.ts +3 -2
  562. package/src/__tests__/contract-gate.test.ts +1 -33
  563. package/src/__tests__/cso-validator.test.ts +1 -9
  564. package/src/__tests__/effective-constraints.test.ts +1 -3
  565. package/src/__tests__/error-classifier.test.ts +1 -42
  566. package/src/__tests__/failure-recorder.test.ts +45 -114
  567. package/src/__tests__/install-precommit-hook.test.ts +61 -0
  568. package/src/__tests__/iron-laws.test.ts +14 -21
  569. package/src/__tests__/layering.test.ts +4 -4
  570. package/src/__tests__/project-config-loader.test.ts +2 -1
  571. package/src/__tests__/public-exports.test.ts +5 -16
  572. package/src/__tests__/public-type-surface.test.ts +10 -41
  573. package/src/__tests__/public-value-surface.test.ts +9 -20
  574. package/src/__tests__/review-gate.test.ts +0 -17
  575. package/src/__tests__/security-gate.test.ts +0 -18
  576. package/src/__tests__/skip-semantics.test.ts +9 -11
  577. package/src/__tests__/trace-analyzer-extra.test.ts +13 -129
  578. package/src/__tests__/trace-analyzer.test.ts +7 -7
  579. package/src/__tests__/trace-collector.test.ts +0 -43
  580. package/src/__tests__/traces.test.ts +7 -39
  581. package/src/agents/CONTEXT.md +2 -4
  582. package/src/agents/__tests__/lifecycle.test.ts +4 -155
  583. package/src/agents/index.ts +0 -3
  584. package/src/agents/lifecycle.ts +1 -116
  585. package/src/agents/types.ts +1 -21
  586. package/src/{hooks → bootstrap}/CONTEXT.md +5 -5
  587. package/src/{hooks → bootstrap}/bootstrap.ts +32 -39
  588. package/src/{hooks → bootstrap}/index.ts +3 -2
  589. package/src/cli/__tests__/command-contract.test.ts +18 -0
  590. package/src/cli/command-contract.ts +8 -5
  591. package/src/cli/commands/CONTEXT.md +21 -21
  592. package/src/cli/commands/__tests__/check-read-count.test.ts +4 -7
  593. package/src/cli/commands/__tests__/check-skip-output.test.ts +0 -1
  594. package/src/cli/commands/__tests__/check.test.ts +1 -1
  595. package/src/cli/commands/__tests__/command-gate-dead-options.test.ts +7 -5
  596. package/src/cli/commands/__tests__/constraints-pack-proposal.test.ts +0 -1
  597. package/src/cli/commands/__tests__/constraints-report.test.ts +2 -2
  598. package/src/cli/commands/__tests__/constraints-retire.test.ts +5 -3
  599. package/src/cli/commands/__tests__/contract.test.ts +11 -4
  600. package/src/cli/commands/__tests__/failure.test.ts +9 -9
  601. package/src/cli/commands/__tests__/init-governance-io.test.ts +7 -2
  602. package/src/cli/commands/__tests__/init.test.ts +1 -1
  603. package/src/cli/commands/__tests__/knowledge-audit-threshold.test.ts +14 -8
  604. package/src/cli/commands/__tests__/knowledge-flywheel-consistency.test.ts +2 -1
  605. package/src/cli/commands/__tests__/knowledge-view.test.ts +52 -172
  606. package/src/cli/commands/__tests__/knowledge.test.ts +30 -6
  607. package/src/cli/commands/__tests__/numeric-flag-assembly.test.ts +3 -2
  608. package/src/cli/commands/__tests__/passes-gate.test.ts +105 -29
  609. package/src/cli/commands/__tests__/project-path-anchoring.test.ts +3 -6
  610. package/src/cli/commands/__tests__/project-path-convention.test.ts +4 -21
  611. package/src/cli/commands/__tests__/registry.test.ts +5 -2
  612. package/src/cli/commands/__tests__/release.test.ts +25 -3
  613. package/src/cli/commands/__tests__/report-false-green.test.ts +10 -6
  614. package/src/cli/commands/__tests__/review.test.ts +20 -6
  615. package/src/cli/commands/__tests__/security.test.ts +14 -0
  616. package/src/cli/commands/__tests__/spec-baseline-read-count.test.ts +2 -2
  617. package/src/cli/commands/__tests__/spec.test.ts +33 -23
  618. package/src/cli/commands/__tests__/validate.test.ts +32 -15
  619. package/src/cli/commands/acceptance.ts +11 -10
  620. package/src/cli/commands/check.ts +12 -6
  621. package/src/cli/commands/command.ts +8 -7
  622. package/src/cli/commands/constraints-pack-proposal.ts +10 -8
  623. package/src/cli/commands/constraints-reactivate.ts +13 -9
  624. package/src/cli/commands/constraints-retire.ts +33 -12
  625. package/src/cli/commands/contract.ts +33 -20
  626. package/src/cli/commands/definitions.ts +23 -94
  627. package/src/cli/commands/failure.ts +7 -8
  628. package/src/cli/commands/init/ci-platform.ts +66 -0
  629. package/src/cli/commands/init/ci-wiring.ts +48 -0
  630. package/src/cli/commands/init/git-hooks.ts +31 -0
  631. package/src/cli/commands/init/governance.ts +127 -0
  632. package/src/cli/commands/init/index.ts +156 -0
  633. package/src/cli/commands/init/output-style.ts +82 -0
  634. package/src/cli/commands/init/presets.ts +105 -0
  635. package/src/cli/commands/init/snippets.ts +57 -0
  636. package/src/cli/commands/knowledge/audit.ts +155 -0
  637. package/src/cli/commands/knowledge/decay.ts +57 -0
  638. package/src/cli/commands/knowledge/health.ts +180 -0
  639. package/src/cli/commands/knowledge/import.ts +82 -0
  640. package/src/cli/commands/knowledge/index.ts +60 -0
  641. package/src/cli/commands/knowledge/list.ts +73 -0
  642. package/src/cli/commands/knowledge/search.ts +92 -0
  643. package/src/cli/commands/knowledge/shared.ts +13 -0
  644. package/src/cli/commands/knowledge/snapshot.ts +38 -0
  645. package/src/cli/commands/knowledge/stats.ts +112 -0
  646. package/src/cli/commands/knowledge/store-access.ts +40 -0
  647. package/src/cli/commands/knowledge-view.ts +11 -34
  648. package/src/cli/commands/passes-gate.ts +23 -10
  649. package/src/cli/commands/performance.ts +2 -2
  650. package/src/cli/commands/release.ts +26 -22
  651. package/src/cli/commands/review.ts +19 -7
  652. package/src/cli/commands/security.ts +17 -11
  653. package/src/{core → cli/commands}/spec/__tests__/validator.test.ts +75 -61
  654. package/src/{core → cli/commands}/spec/validator.ts +65 -94
  655. package/src/cli/commands/spec-baseline-check.ts +37 -315
  656. package/src/cli/commands/spec.ts +15 -11
  657. package/src/cli/commands/status.ts +2 -4
  658. package/src/cli/commands/sync-docs/agents-syncer.ts +28 -47
  659. package/src/cli/commands/sync-docs/capabilities-syncer.ts +14 -13
  660. package/src/cli/commands/sync-docs/compact.ts +36 -0
  661. package/src/cli/commands/sync-docs/context-syncer.ts +15 -31
  662. package/src/cli/commands/sync-docs/gate.ts +78 -0
  663. package/src/cli/commands/sync-docs/index.ts +21 -585
  664. package/src/cli/commands/sync-docs/main-flow.ts +109 -0
  665. package/src/cli/commands/sync-docs/project-reader.ts +23 -25
  666. package/src/cli/commands/sync-docs/sync-output.ts +218 -0
  667. package/src/cli/commands/sync-docs/sync-state.ts +327 -0
  668. package/src/cli/commands/sync-docs/sync-writes.ts +49 -0
  669. package/src/cli/commands/validate.ts +13 -8
  670. package/src/cli/gate-command.ts +1 -1
  671. package/src/context/CONTEXT.md +6 -6
  672. package/src/context/__tests__/session-manager.test.ts +1 -41
  673. package/src/context/index.ts +1 -10
  674. package/src/context/session-manager.ts +30 -90
  675. package/src/context/types.ts +3 -38
  676. package/src/core/CONTEXT.md +11 -11
  677. package/src/core/app-constraints-loader.ts +5 -23
  678. package/src/core/constraint-lifecycle.ts +31 -40
  679. package/src/core/constraints/__tests__/check-cache.test.ts +2 -124
  680. package/src/core/constraints/__tests__/collect-constraints.test.ts +0 -6
  681. package/src/core/constraints/__tests__/run-env.test.ts +26 -114
  682. package/src/core/constraints/__tests__/triggers.test.ts +3 -2
  683. package/src/core/constraints/__tests__/usage-report.test.ts +3 -6
  684. package/src/core/constraints/capabilities-parser.ts +4 -6
  685. package/src/core/constraints/check-cache.ts +4 -70
  686. package/src/core/constraints/checker.ts +25 -75
  687. package/src/core/constraints/checkers/__tests__/capability-sync.test.ts +1 -0
  688. package/src/core/constraints/checkers/__tests__/check-outcome.test.ts +0 -1
  689. package/src/core/constraints/checkers/__tests__/docs-freshness-degraded.test.ts +2 -0
  690. package/src/core/constraints/checkers/__tests__/docs-freshness.test.ts +1 -0
  691. package/src/core/constraints/checkers/__tests__/governance-presence.test.ts +1 -0
  692. package/src/core/constraints/checkers/__tests__/input-contract.test.ts +1 -25
  693. package/src/core/constraints/checkers/__tests__/no-completion-without-verification.test.ts +3 -2
  694. package/src/core/constraints/checkers/__tests__/no-hardcoded-credentials.test.ts +3 -0
  695. package/src/core/constraints/checkers/__tests__/no-test-simplification.test.ts +1 -0
  696. package/src/core/constraints/checkers/__tests__/templated-checkers.test.ts +1 -0
  697. package/src/core/constraints/checkers/__tests__/templates-registry.test.ts +0 -2
  698. package/src/core/constraints/checkers/__tests__/three-state-consistency.test.ts +1 -0
  699. package/src/core/constraints/checkers/capability-sync.ts +2 -2
  700. package/src/core/constraints/checkers/context-doc-sync.ts +1 -1
  701. package/src/core/constraints/checkers/docs-freshness.ts +1 -1
  702. package/src/core/constraints/checkers/index.ts +21 -8
  703. package/src/core/constraints/checkers/no-hardcoded-credentials.ts +5 -32
  704. package/src/core/constraints/checkers/no-test-simplification.ts +10 -32
  705. package/src/core/constraints/checkers/templated/exec.ts +2 -7
  706. package/src/core/constraints/checkers/templated/file-exists.ts +1 -1
  707. package/src/core/constraints/checkers/templated/regex-scan.ts +6 -25
  708. package/src/core/constraints/checkers/types.ts +12 -65
  709. package/src/core/constraints/context-builder.ts +11 -102
  710. package/src/core/constraints/definitions/{iron-laws.ts → errors.ts} +0 -21
  711. package/src/core/constraints/definitions/{guidelines.ts → warnings.ts} +18 -4
  712. package/src/core/constraints/definitions.ts +4 -3
  713. package/src/core/constraints/doc-freshness/runner.ts +201 -232
  714. package/src/core/constraints/find-constraint.ts +24 -0
  715. package/src/core/constraints/git-evidence.ts +2 -0
  716. package/src/core/constraints/governance-accessors.ts +74 -0
  717. package/src/core/constraints/index.ts +0 -5
  718. package/src/core/constraints/injection-writer.ts +3 -6
  719. package/src/core/constraints/pack-proposal.ts +4 -15
  720. package/src/core/constraints/run-env.ts +1 -26
  721. package/src/core/constraints/triggers.ts +11 -6
  722. package/src/core/constraints/usage-report.ts +0 -9
  723. package/src/core/index.ts +5 -10
  724. package/src/core/project-config-loader.ts +5 -67
  725. package/src/core/spec/baseline-check.ts +300 -0
  726. package/src/core/validators/__tests__/http-retry-sleep.test.ts +1 -1
  727. package/src/core/validators/__tests__/passes-gate-counts.test.ts +52 -0
  728. package/src/core/validators/check-handlers/command.ts +9 -6
  729. package/src/core/validators/check-handlers/file.ts +48 -5
  730. package/src/core/validators/check-handlers/http.ts +8 -6
  731. package/src/core/validators/check-handlers/output.ts +7 -6
  732. package/src/core/validators/checkpoint.ts +52 -85
  733. package/src/core/validators/cso.ts +1 -12
  734. package/src/core/validators/passes-gate.ts +27 -38
  735. package/src/failure/CONTEXT.md +1 -1
  736. package/src/failure/__tests__/recorder.test.ts +2 -1
  737. package/src/failure/classifier.ts +2 -42
  738. package/src/failure/error-types.ts +122 -0
  739. package/src/failure/index.ts +9 -9
  740. package/src/failure/recorder.ts +12 -77
  741. package/src/gates/CONTEXT.md +9 -10
  742. package/src/gates/__tests__/acceptance-types-single-source.test.ts +16 -14
  743. package/src/gates/__tests__/acceptance.test.ts +69 -94
  744. package/src/gates/__tests__/command-single-predicate.test.ts +16 -61
  745. package/src/gates/__tests__/command.test.ts +23 -25
  746. package/src/gates/__tests__/gate-interface.test.ts +5 -10
  747. package/src/gates/__tests__/performance.test.ts +8 -54
  748. package/src/gates/__tests__/review.test.ts +27 -50
  749. package/src/gates/__tests__/security-default-scan.test.ts +6 -3
  750. package/src/gates/__tests__/security.test.ts +30 -61
  751. package/src/gates/acceptance.ts +199 -156
  752. package/src/gates/command.ts +1 -34
  753. package/src/gates/contract.ts +83 -93
  754. package/src/gates/definitions.ts +1 -1
  755. package/src/gates/performance.ts +36 -43
  756. package/src/gates/registry.ts +4 -3
  757. package/src/gates/review.ts +68 -31
  758. package/src/gates/security.ts +69 -96
  759. package/src/gates/types.ts +22 -84
  760. package/src/index.ts +11 -32
  761. package/src/knowledge/CONTEXT.md +21 -25
  762. package/src/knowledge/__tests__/audit-labels.test.ts +3 -3
  763. package/src/knowledge/__tests__/audit-scoring.test.ts +9 -7
  764. package/src/knowledge/__tests__/audit.test.ts +1 -1
  765. package/src/knowledge/__tests__/import.test.ts +1 -1
  766. package/src/knowledge/__tests__/ingest-validate-entry.test.ts +235 -0
  767. package/src/knowledge/__tests__/ingest.test.ts +19 -20
  768. package/src/knowledge/__tests__/store.test.ts +6 -10
  769. package/src/knowledge/__tests__/tree-walker.test.ts +5 -13
  770. package/src/knowledge/audit-dimensions.ts +190 -0
  771. package/src/knowledge/audit-rules.ts +339 -0
  772. package/src/knowledge/audit-scoring.ts +7 -495
  773. package/src/knowledge/audit.ts +12 -12
  774. package/src/knowledge/{import.ts → cold-start.ts} +150 -192
  775. package/src/knowledge/index-generator.ts +48 -53
  776. package/src/knowledge/index.ts +6 -11
  777. package/src/knowledge/ingest.ts +137 -19
  778. package/src/knowledge/lifecycle.ts +28 -38
  779. package/src/knowledge/query.ts +8 -7
  780. package/src/knowledge/store.ts +29 -66
  781. package/src/knowledge/types.ts +2 -48
  782. package/src/monitoring/CONTEXT.md +3 -3
  783. package/src/monitoring/__tests__/skipped-lines-report.test.ts +3 -16
  784. package/src/monitoring/__tests__/traces.test.ts +1 -27
  785. package/src/monitoring/analyzer-base.ts +1 -28
  786. package/src/monitoring/trace-analyzer.ts +12 -168
  787. package/src/monitoring/traces.ts +11 -35
  788. package/src/pretool-use-hook.ts +26 -21
  789. package/src/release/CONTEXT.md +1 -1
  790. package/src/release/__tests__/integrity.test.ts +0 -2
  791. package/src/release/integrity.ts +8 -9
  792. package/src/sdd/index-generator.ts +4 -0
  793. package/src/types/checkpoint.ts +8 -8
  794. package/src/types/command-definition.ts +85 -0
  795. package/src/types/command-io.ts +14 -0
  796. package/src/types/constraint.ts +3 -32
  797. package/src/types/failure.ts +7 -113
  798. package/src/types/gate.ts +77 -0
  799. package/src/types/spec.ts +0 -4
  800. package/src/types/trace.ts +0 -6
  801. package/src/utils/__tests__/attempt.test.ts +94 -0
  802. package/src/utils/__tests__/jsonl-skip-disposition.test.ts +4 -7
  803. package/src/utils/__tests__/package-json.test.ts +58 -0
  804. package/src/utils/__tests__/package-version.test.ts +21 -2
  805. package/src/utils/attempt.ts +35 -0
  806. package/src/utils/clip.ts +12 -0
  807. package/src/utils/detect-source-roots.ts +38 -44
  808. package/src/utils/diff-parse.ts +80 -0
  809. package/src/utils/file-walk.ts +3 -7
  810. package/src/utils/guards.ts +8 -0
  811. package/src/utils/jsonl.ts +0 -30
  812. package/src/utils/log-rotate.ts +43 -0
  813. package/src/utils/numeric-flag.ts +24 -2
  814. package/src/utils/package-json.ts +61 -0
  815. package/src/utils/package-version.ts +8 -10
  816. package/dist/cli/commands/init.d.ts.map +0 -1
  817. package/dist/cli/commands/init.js +0 -502
  818. package/dist/cli/commands/init.js.map +0 -1
  819. package/dist/cli/commands/knowledge.d.ts +0 -169
  820. package/dist/cli/commands/knowledge.d.ts.map +0 -1
  821. package/dist/cli/commands/knowledge.js +0 -700
  822. package/dist/cli/commands/knowledge.js.map +0 -1
  823. package/dist/context/knowledge-injector.d.ts +0 -51
  824. package/dist/context/knowledge-injector.d.ts.map +0 -1
  825. package/dist/context/knowledge-injector.js +0 -128
  826. package/dist/context/knowledge-injector.js.map +0 -1
  827. package/dist/core/constraints/checkers/templates-registry.d.ts +0 -18
  828. package/dist/core/constraints/checkers/templates-registry.d.ts.map +0 -1
  829. package/dist/core/constraints/checkers/templates-registry.js +0 -25
  830. package/dist/core/constraints/checkers/templates-registry.js.map +0 -1
  831. package/dist/core/constraints/definitions/guidelines.d.ts.map +0 -1
  832. package/dist/core/constraints/definitions/guidelines.js.map +0 -1
  833. package/dist/core/constraints/definitions/iron-laws.d.ts.map +0 -1
  834. package/dist/core/constraints/definitions/iron-laws.js.map +0 -1
  835. package/dist/core/spec/validator.d.ts.map +0 -1
  836. package/dist/core/spec/validator.js.map +0 -1
  837. package/dist/gates/checker-gate.d.ts +0 -27
  838. package/dist/gates/checker-gate.d.ts.map +0 -1
  839. package/dist/gates/checker-gate.js +0 -52
  840. package/dist/gates/checker-gate.js.map +0 -1
  841. package/dist/gates/index.d.ts +0 -10
  842. package/dist/gates/index.d.ts.map +0 -1
  843. package/dist/gates/index.js +0 -11
  844. package/dist/gates/index.js.map +0 -1
  845. package/dist/hooks/bootstrap.d.ts.map +0 -1
  846. package/dist/hooks/bootstrap.js.map +0 -1
  847. package/dist/hooks/index.d.ts.map +0 -1
  848. package/dist/hooks/index.js.map +0 -1
  849. package/dist/knowledge/doctor.d.ts +0 -37
  850. package/dist/knowledge/doctor.d.ts.map +0 -1
  851. package/dist/knowledge/doctor.js +0 -81
  852. package/dist/knowledge/doctor.js.map +0 -1
  853. package/dist/knowledge/import.d.ts.map +0 -1
  854. package/dist/knowledge/import.js.map +0 -1
  855. package/dist/knowledge/lint.d.ts +0 -90
  856. package/dist/knowledge/lint.d.ts.map +0 -1
  857. package/dist/knowledge/lint.js +0 -412
  858. package/dist/knowledge/lint.js.map +0 -1
  859. package/dist/knowledge/migration.d.ts +0 -28
  860. package/dist/knowledge/migration.d.ts.map +0 -1
  861. package/dist/knowledge/migration.js +0 -105
  862. package/dist/knowledge/migration.js.map +0 -1
  863. package/dist/knowledge/reference-tracker.d.ts +0 -31
  864. package/dist/knowledge/reference-tracker.d.ts.map +0 -1
  865. package/dist/knowledge/reference-tracker.js +0 -125
  866. package/dist/knowledge/reference-tracker.js.map +0 -1
  867. package/src/__tests__/spec-validator.test.ts +0 -58
  868. package/src/cli/commands/init.ts +0 -590
  869. package/src/cli/commands/knowledge.ts +0 -820
  870. package/src/context/__tests__/knowledge-injector.test.ts +0 -197
  871. package/src/context/knowledge-injector.ts +0 -174
  872. package/src/core/constraints/checkers/templates-registry.ts +0 -24
  873. package/src/gates/__tests__/checker-gate.test.ts +0 -86
  874. package/src/gates/checker-gate.ts +0 -52
  875. package/src/gates/index.ts +0 -11
  876. package/src/knowledge/__tests__/doctor.test.ts +0 -300
  877. package/src/knowledge/__tests__/lint.test.ts +0 -536
  878. package/src/knowledge/__tests__/migration.test.ts +0 -185
  879. package/src/knowledge/__tests__/reference-tracker.test.ts +0 -169
  880. package/src/knowledge/doctor.ts +0 -103
  881. package/src/knowledge/lint.ts +0 -460
  882. package/src/knowledge/migration.ts +0 -82
  883. package/src/knowledge/reference-tracker.ts +0 -101
  884. /package/src/{hooks → bootstrap}/__tests__/bootstrap.test.ts +0 -0
@@ -1,460 +0,0 @@
1
- /**
2
- * 知识库 Lint(健康检查)
3
- *
4
- * 检查项:
5
- * - 索引不一致(自动修复)
6
- * - 孤儿条目(无引用、无验证)
7
- * - 矛盾检测(同主题相反结论)
8
- * - 过时检测(6 月未引用的 draft)
9
- * - 重复/相似条目
10
- * - 成熟度衰减
11
- */
12
-
13
- import type { KnowledgeStore } from './store';
14
- import { ReferenceTracker } from './reference-tracker';
15
- import type { KnowledgeEntry, LintIssue, LintIssueType, MaturityLevel } from './types';
16
- import { MATURITY_LEVELS, STORAGE_LAYERS } from './types';
17
-
18
- const MAX_SOURCE_REFS = 20;
19
-
20
- export interface LintReport {
21
- timestamp: string;
22
- totalEntries: number;
23
- issues: LintIssue[];
24
- fixed: number;
25
- summary: Record<LintIssueType, number>;
26
- }
27
-
28
- export class KnowledgeLinter {
29
- private store: KnowledgeStore;
30
- private tracker: ReferenceTracker;
31
-
32
- constructor(store: KnowledgeStore, tracker: ReferenceTracker) {
33
- this.store = store;
34
- this.tracker = tracker;
35
- }
36
-
37
- /**
38
- * 执行完整 Lint 检查
39
- */
40
- run(autoFix: boolean = false): LintReport {
41
- const entries = this.store.list({ excludeArchived: false });
42
- const issues: LintIssue[] = [];
43
-
44
- // 各项检查
45
- issues.push(...this.checkIndexConsistency(entries));
46
- issues.push(...this.checkOrphans(entries));
47
- issues.push(...this.checkOutdated(entries));
48
- issues.push(...this.checkDuplicates(entries));
49
- issues.push(...this.checkContradictions(entries));
50
- issues.push(...this.checkInvalidEnums(entries));
51
-
52
- // 自动修复
53
- let fixed = 0;
54
- if (autoFix) {
55
- fixed = this.autoFix(issues);
56
- }
57
-
58
- // 统计
59
- const summary: Record<LintIssueType, number> = {
60
- orphan: 0,
61
- contradiction: 0,
62
- outdated: 0,
63
- duplicate: 0,
64
- index_inconsistent: 0,
65
- invalid_enum: 0,
66
- };
67
- for (const issue of issues) {
68
- summary[issue.type]++;
69
- }
70
-
71
- return {
72
- timestamp: new Date().toISOString(),
73
- totalEntries: entries.length,
74
- issues,
75
- fixed,
76
- summary,
77
- };
78
- }
79
-
80
- /**
81
- * 检查索引一致性
82
- */
83
- checkIndexConsistency(_entries: KnowledgeEntry[]): LintIssue[] {
84
- const issues: LintIssue[] = [];
85
- const index = this.store.readIndex();
86
-
87
- // 检查索引中的条目是否都有对应文件
88
- for (const indexEntry of index) {
89
- const fileEntry = this.store.get(indexEntry.id);
90
- if (!fileEntry) {
91
- issues.push({
92
- type: 'index_inconsistent',
93
- entryId: indexEntry.id,
94
- severity: 'medium',
95
- description: `索引条目 ${indexEntry.id} 无对应文件`,
96
- suggestion: '从索引中移除或重建索引',
97
- });
98
- }
99
- }
100
-
101
- // 检查磁盘上的文件是否都在索引中
102
- const indexIds = new Set(index.map(e => e.id));
103
- const diskEntries = this.store['readEntriesFromDisk']();
104
- for (const entry of diskEntries) {
105
- if (!indexIds.has(entry.id)) {
106
- issues.push({
107
- type: 'index_inconsistent',
108
- entryId: entry.id,
109
- severity: 'medium',
110
- description: `条目 ${entry.id} 不在索引中`,
111
- suggestion: '重建索引',
112
- });
113
- }
114
- }
115
-
116
- return issues;
117
- }
118
-
119
- /**
120
- * 检查孤儿条目(无引用、无验证)
121
- */
122
- checkOrphans(entries: KnowledgeEntry[]): LintIssue[] {
123
- const issues: LintIssue[] = [];
124
-
125
- for (const entry of entries) {
126
- if (entry.maturity === 'archived') continue;
127
-
128
- const refs = this.tracker.getReferencesForEntry(entry.id);
129
- const hasReferences = refs.length > 0;
130
- const hasContributors = entry.contributors.length > 0;
131
- const hasProjects = entry.projects.length > 0;
132
-
133
- if (!hasReferences && !hasContributors && !hasProjects && entry.maturity === 'draft') {
134
- issues.push({
135
- type: 'orphan',
136
- entryId: entry.id,
137
- severity: 'low',
138
- description: `条目 ${entry.id} (${entry.title}) 无引用、无贡献者、无项目验证`,
139
- suggestion: '考虑归档或标记为需要验证',
140
- });
141
- }
142
- }
143
-
144
- return issues;
145
- }
146
-
147
- /**
148
- * 检查过时条目(6 月未引用的 draft)
149
- */
150
- checkOutdated(entries: KnowledgeEntry[]): LintIssue[] {
151
- const issues: LintIssue[] = [];
152
- const sixMonthsAgo = new Date();
153
- sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);
154
-
155
- for (const entry of entries) {
156
- if (entry.maturity === 'archived') continue;
157
-
158
- const lastRef = entry.lastReferenced ? new Date(entry.lastReferenced) : null;
159
- const created = new Date(entry.created);
160
- const relevantDate = lastRef || created;
161
-
162
- if (relevantDate < sixMonthsAgo && entry.maturity === 'draft') {
163
- issues.push({
164
- type: 'outdated',
165
- entryId: entry.id,
166
- severity: 'medium',
167
- description: `条目 ${entry.id} (${entry.title}) 超过 6 个月未引用且为 draft`,
168
- suggestion: '考虑归档或提升成熟度',
169
- });
170
- }
171
- }
172
-
173
- return issues;
174
- }
175
-
176
- /**
177
- * 检查重复/相似条目
178
- */
179
- checkDuplicates(entries: KnowledgeEntry[]): LintIssue[] {
180
- const issues: LintIssue[] = [];
181
- const seen = new Map<string, KnowledgeEntry[]>();
182
-
183
- for (const entry of entries) {
184
- if (entry.maturity === 'archived') continue;
185
-
186
- // 基于 title + type 去重(大小写不敏感)
187
- const key = `${entry.type}:${(entry.title || '').toLowerCase().trim()}`;
188
- const existing = seen.get(key) || [];
189
- existing.push(entry);
190
- seen.set(key, existing);
191
- }
192
-
193
- for (const [, group] of seen) {
194
- if (group.length > 1) {
195
- for (const entry of group) {
196
- issues.push({
197
- type: 'duplicate',
198
- entryId: entry.id,
199
- severity: 'low',
200
- description: `条目 ${entry.id} (${entry.title}) 与同类型同标题的其他条目重复`,
201
- suggestion: `考虑合并: ${group.map(e => e.id).join(', ')}`,
202
- });
203
- }
204
- }
205
- }
206
-
207
- return issues;
208
- }
209
-
210
- /**
211
- * 检查存量条目的 maturity/layer 枚举值域(E1 复盘修正 M1 收口:
212
- * 写入闸只挡新写,存量脏值由本检查进 lint 报告;缺字段在存量侧算脏值)。
213
- * 与 validateEntry 共用同一判定正本(invalidEnumIssues),autoFix 不动此类
214
- * issue——枚举映射需人工裁定,不自动改。
215
- */
216
- checkInvalidEnums(entries: KnowledgeEntry[]): LintIssue[] {
217
- const issues: LintIssue[] = [];
218
- for (const entry of entries) {
219
- issues.push(...this.invalidEnumIssues(entry, true, entry.id));
220
- }
221
- return issues;
222
- }
223
-
224
- /**
225
- * maturity/layer 枚举判定正本。missingIsDirty=false 时字段缺省跳过
226
- * (pre-ingest 调用方只传四字段的兼容面);存量扫描传 true(缺字段即脏)。
227
- */
228
- private invalidEnumIssues(
229
- fields: { maturity?: string; layer?: string },
230
- missingIsDirty: boolean,
231
- entryId?: string
232
- ): LintIssue[] {
233
- const issues: LintIssue[] = [];
234
- if ((missingIsDirty || fields.maturity !== undefined) && !(MATURITY_LEVELS as readonly string[]).includes(fields.maturity as string)) {
235
- issues.push({
236
- type: 'invalid_enum',
237
- entryId,
238
- severity: 'high',
239
- description: fields.maturity === undefined
240
- ? `maturity is missing (declared values: ${MATURITY_LEVELS.join(' | ')}).`
241
- : `maturity "${fields.maturity}" is not a declared value (${MATURITY_LEVELS.join(' | ')}).`,
242
- suggestion: 'Map to a declared maturity (e.g. pending → draft) before writing; the store write gate rejects undeclared values.',
243
- });
244
- }
245
- if ((missingIsDirty || fields.layer !== undefined) && !(STORAGE_LAYERS as readonly string[]).includes(fields.layer as string)) {
246
- issues.push({
247
- type: 'invalid_enum',
248
- entryId,
249
- severity: 'high',
250
- description: fields.layer === undefined
251
- ? `layer is missing (declared values: ${STORAGE_LAYERS.join(' | ')}).`
252
- : `layer "${fields.layer}" is not a declared value (${STORAGE_LAYERS.join(' | ')}).`,
253
- suggestion: 'Map to a declared layer or drop the field; the store write gate rejects undeclared values.',
254
- });
255
- }
256
- return issues;
257
- }
258
-
259
- /**
260
- * 检查矛盾(同主题相反结论)
261
- *
262
- * 简单实现:同 tag 组合下成熟度冲突
263
- */
264
- checkContradictions(entries: KnowledgeEntry[]): LintIssue[] {
265
- const issues: LintIssue[] = [];
266
- const byTagGroup = new Map<string, KnowledgeEntry[]>();
267
-
268
- // 按 tag 组合分组
269
- for (const entry of entries) {
270
- if (entry.maturity === 'archived') continue;
271
- if (!entry.tags || entry.tags.length === 0) continue;
272
-
273
- const tagKey = entry.tags.sort().join(',');
274
- const existing = byTagGroup.get(tagKey) || [];
275
- existing.push(entry);
276
- byTagGroup.set(tagKey, existing);
277
- }
278
-
279
- // 检查同 tag 组合内是否有成熟度差异大的条目
280
- for (const [tagKey, group] of byTagGroup) {
281
- if (group.length < 2) continue;
282
-
283
- const maturityOrder: MaturityLevel[] = ['draft', 'verified', 'proven'];
284
- const levels = group.map(e => maturityOrder.indexOf(e.maturity));
285
- const maxLevel = Math.max(...levels);
286
- const minLevel = Math.min(...levels);
287
-
288
- // 成熟度差异 >= 2 级(如 proven vs draft)
289
- if (maxLevel - minLevel >= 2) {
290
- const lowEntries = group.filter((_, i) => levels[i] === minLevel);
291
- for (const entry of lowEntries) {
292
- issues.push({
293
- type: 'contradiction',
294
- entryId: entry.id,
295
- severity: 'high',
296
- description: `条目 ${entry.id} (${entry.title}) 与同标签的高成熟度条目存在潜在矛盾`,
297
- suggestion: `审查标签 [${tagKey}] 下的所有条目,确认或更新`,
298
- });
299
- }
300
- }
301
- }
302
-
303
- return issues;
304
- }
305
-
306
- /**
307
- * P2.5: Validate a single entry before ingestion.
308
- * Returns a list of issues (empty = valid, ready to ingest).
309
- *
310
- * Checks:
311
- * - Content too short (< 20 chars) → reject
312
- * - Title too vague (common stop words only) → flag
313
- * - Contradicts a proven entry with same tags → reject
314
- * - Near-duplicate of existing entry (title similarity > 80%) → flag merge
315
- * - maturity/layer 未声明枚举值 → reject(E1 复盘修正 M1;字段缺省则跳过,
316
- * 兼容只传 title/content/tags/type 的 pre-ingest 调用方;存量报告由调用方
317
- * 把条目字段显式传入触发)
318
- */
319
- validateEntry(entry: { title: string; content: string; tags: string[]; type: string; maturity?: string; layer?: string }): LintIssue[] {
320
- const issues: LintIssue[] = [];
321
-
322
- // Undeclared maturity/layer enum values(判定正本 = invalidEnumIssues;字段缺省跳过,
323
- // 兼容只传四字段的 pre-ingest 调用方;存量扫描走 run() → checkInvalidEnums)
324
- issues.push(...this.invalidEnumIssues(entry, false));
325
-
326
- // Content too short
327
- if ((entry.content || '').length < 20) {
328
- issues.push({
329
- type: 'orphan',
330
- severity: 'high',
331
- description: `Content too short (${entry.content.length} chars). LLM may have hallucinated.`,
332
- suggestion: 'Reject — re-extract with better prompt or discard.',
333
- });
334
- }
335
-
336
- // Title too vague
337
- const vaguePatterns = /^(错误|失败|问题|异常|bug|error|fail|issue|problem|unknown|untitled)$/i;
338
- if (vaguePatterns.test(entry.title.trim())) {
339
- issues.push({
340
- type: 'contradiction',
341
- severity: 'medium',
342
- description: `Title "${entry.title}" is too vague to be useful.`,
343
- suggestion: 'Re-extract with root cause in title, not symptom.',
344
- });
345
- }
346
-
347
- // Contradicts proven entry with same tags
348
- if (entry.tags && entry.tags.length > 0) {
349
- const allEntries = this.store.list({ excludeArchived: false });
350
- for (const existing of allEntries) {
351
- if (existing.maturity !== 'proven') continue;
352
- if (existing.type !== entry.type) continue;
353
- const sharedTags = entry.tags.filter(t => existing.tags.includes(t));
354
- if (sharedTags.length >= 2) {
355
- issues.push({
356
- type: 'contradiction',
357
- entryId: existing.id,
358
- severity: 'high',
359
- description: `New entry "${entry.title}" shares tags [${sharedTags.join(', ')}] with proven entry "${existing.title}" (${existing.id}). Contradiction risk.`,
360
- suggestion: `Review against ${existing.id}. If aligned, merge. If contradictory, flag for human review.`,
361
- });
362
- }
363
- }
364
- }
365
-
366
- // Near-duplicate title check (simple: case-insensitive substring match)
367
- if (entry.title.length > 10) {
368
- const allEntries = this.store.list({ excludeArchived: false });
369
- for (const existing of allEntries) {
370
- if (existing.id === entry.title) continue; // not same entry (entry doesn't have id yet)
371
- const existingTitle = (existing.title || '').toLowerCase();
372
- const newTitle = (entry.title || '').toLowerCase();
373
- if (existingTitle === newTitle) {
374
- issues.push({
375
- type: 'duplicate',
376
- entryId: existing.id,
377
- severity: 'medium',
378
- description: `Exact title match with existing entry "${existing.title}" (${existing.id}).`,
379
- suggestion: `Merge into ${existing.id} instead of creating duplicate.`,
380
- });
381
- break;
382
- }
383
- // Check high similarity (either title contains the other)
384
- if (existingTitle.includes(newTitle) || newTitle.includes(existingTitle)) {
385
- issues.push({
386
- type: 'duplicate',
387
- entryId: existing.id,
388
- severity: 'low',
389
- description: `Title similarity with existing "${existing.title}" (${existing.id}).`,
390
- suggestion: `Consider merging with ${existing.id}.`,
391
- });
392
- break;
393
- }
394
- }
395
- }
396
-
397
- return issues;
398
- }
399
-
400
- /**
401
- * 自动修复可修复的问题
402
- */
403
- private autoFix(issues: LintIssue[]): number {
404
- let fixed = 0;
405
-
406
- // A3: Deduplicate — group by entryId, keep newest, archive rest
407
- const duplicateIssues = issues.filter(i => i.type === 'duplicate' && i.entryId);
408
- const processedGroups = new Set<string>();
409
- for (const issue of duplicateIssues) {
410
- // Extract group from suggestion field: "考虑合并: GUI-003, GUI-004"
411
- const match = issue.suggestion?.match(/: (.+)$/);
412
- if (!match) continue;
413
- const groupKey = match[1];
414
- if (processedGroups.has(groupKey)) continue;
415
- processedGroups.add(groupKey);
416
-
417
- const ids = groupKey.split(', ').map(s => s.trim());
418
- const entries = ids.map(id => this.store.get(id)).filter(Boolean) as KnowledgeEntry[];
419
- if (entries.length <= 1) continue;
420
-
421
- // Keep the one with most recent lastReferenced
422
- entries.sort((a, b) => (b.lastReferenced || '').localeCompare(a.lastReferenced || ''));
423
- const keep = entries[0];
424
- for (let i = 1; i < entries.length; i++) {
425
- this.store.update(entries[i].id, { maturity: 'archived' });
426
- fixed++;
427
- }
428
- // Merge sourceReferences from archived entries into kept entry
429
- const allRefs = entries.flatMap(e => e.sourceReferences || []);
430
- if (allRefs.length > 0) {
431
- const existing = keep.sourceReferences || [];
432
- const merged = [...existing, ...allRefs];
433
- // Deduplicate by workflow+timestamp
434
- const seen = new Set<string>();
435
- const deduped = merged.filter(ref => {
436
- const key = `${ref.workflow}:${ref.timestamp}`;
437
- if (seen.has(key)) return false;
438
- seen.add(key);
439
- return true;
440
- }).slice(-MAX_SOURCE_REFS);
441
- this.store.update(keep.id, { sourceReferences: deduped });
442
- }
443
- }
444
-
445
- for (const issue of issues) {
446
- if (issue.type === 'index_inconsistent') {
447
- this.store.rebuildIndex();
448
- fixed++;
449
- break; // rebuildIndex 修复所有索引问题
450
- }
451
-
452
- if (issue.type === 'outdated' && issue.entryId) {
453
- this.store.update(issue.entryId, { maturity: 'archived' });
454
- fixed++;
455
- }
456
- }
457
-
458
- return fixed;
459
- }
460
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * Knowledge Migration Utilities
3
- *
4
- * Migrates existing knowledge entries to add new fields
5
- * introduced in AS-021 (consumptionMode, origin, fullContentPath, skillId).
6
- */
7
-
8
- import * as fs from 'fs';
9
- import * as path from 'path';
10
- import { splitFrontmatter, joinFrontmatter } from '../utils/frontmatter';
11
- import { isEntryFile } from './tree-walker';
12
-
13
- interface MigrationResult {
14
- total: number;
15
- migrated: number;
16
- skipped: number;
17
- errors: string[];
18
- }
19
-
20
- /**
21
- * Migrate all knowledge .md files in a directory to include
22
- * consumptionMode and origin fields if missing.
23
- *
24
- * 条目人口按 `tree-walker` 的排除口径判定(harness#134):`_index.md` 这类树生成物
25
- * 既不是迁移对象,也不再计入 `total`/`errors`(此前被报成「no frontmatter found」假阳性)。
26
- *
27
- * Existing files without these fields get defaults:
28
- * - consumptionMode: 'reference'
29
- * - origin: 'agent'
30
- *
31
- * This is idempotent — running it multiple times is safe.
32
- */
33
- export function migrateKnowledgeEntries(baseDir: string): MigrationResult {
34
- const result: MigrationResult = { total: 0, migrated: 0, skipped: 0, errors: [] };
35
-
36
- if (!fs.existsSync(baseDir)) {
37
- return result;
38
- }
39
-
40
- const files = fs.readdirSync(baseDir).filter(isEntryFile);
41
- result.total = files.length;
42
-
43
- for (const file of files) {
44
- const filePath = path.join(baseDir, file);
45
- try {
46
- const raw = fs.readFileSync(filePath, 'utf-8');
47
- const fm = splitFrontmatter(raw);
48
- if (fm.state === 'absent') {
49
- // 统一口径(harness#89 裁决 2 / harness#161):'absent' 是合法输入、不上报——
50
- // 按非条目语义静默跳过,计入 skipped(非损坏、非迁移对象,仅保证 total 计数闭环)
51
- result.skipped++;
52
- continue;
53
- }
54
- if (fm.state === 'malformed') {
55
- // 统一口径(harness#89):损坏的 frontmatter 落 errors,不静默丢
56
- result.errors.push(`${file}: frontmatter ${fm.reason} (${fm.detail})`);
57
- continue;
58
- }
59
-
60
- const meta = fm.meta;
61
- const content = fm.body;
62
-
63
- // Check if migration needed
64
- if (meta.consumptionMode && meta.origin) {
65
- result.skipped++;
66
- continue;
67
- }
68
-
69
- // Add missing fields with defaults
70
- if (!meta.consumptionMode) meta.consumptionMode = 'reference';
71
- if (!meta.origin) meta.origin = 'agent';
72
-
73
- // Write back
74
- fs.writeFileSync(filePath, joinFrontmatter(meta, content), 'utf-8');
75
- result.migrated++;
76
- } catch (err) {
77
- result.errors.push(`${file}: ${err instanceof Error ? err.message : String(err)}`);
78
- }
79
- }
80
-
81
- return result;
82
- }
@@ -1,101 +0,0 @@
1
- /**
2
- * Reference Tracker
3
- *
4
- * Tracks which decisions reference which knowledge entries.
5
- * Storage: append-only JSONL at .harness/knowledge/references.jsonl
6
- */
7
-
8
- import * as path from 'path';
9
- import { appendJsonl, readJsonl } from '../utils/jsonl';
10
- import type { ReferenceRecord, StoreUpdate } from './types';
11
- import type { KnowledgeStore } from './store';
12
-
13
- const REFERENCES_FILE = 'references.jsonl';
14
-
15
- // ── Reference Tracker ──────────────────────────────────────
16
-
17
- export class ReferenceTracker {
18
- private filePath: string;
19
- private store: KnowledgeStore;
20
-
21
- constructor(store: KnowledgeStore, baseDir?: string) {
22
- const dir = baseDir || '.harness/knowledge';
23
- this.filePath = path.join(dir, REFERENCES_FILE);
24
- this.store = store;
25
- }
26
-
27
- /**
28
- * Record that a decision referenced a set of knowledge entries.
29
- */
30
- record(decisionId: string, entryIds: string[]): void {
31
- const record: ReferenceRecord = {
32
- decisionId,
33
- entryIds,
34
- timestamp: new Date().toISOString(),
35
- };
36
- // 写链收口:ensureDir + append(harness#82;原实现不 ensureDir,依赖 store 建目录)
37
- appendJsonl(this.filePath, record);
38
- }
39
-
40
- /**
41
- * Get all decision IDs that referenced a given entry.
42
- */
43
- getReferencesForEntry(entryId: string): string[] {
44
- const records = this.readAll();
45
- return records
46
- .filter(r => r.entryIds.includes(entryId))
47
- .map(r => r.decisionId);
48
- }
49
-
50
- /**
51
- * Get all entry IDs referenced by a given decision.
52
- */
53
- getReferencesForDecision(decisionId: string): string[] {
54
- const records = this.readAll();
55
- const record = records.find(r => r.decisionId === decisionId);
56
- return record ? record.entryIds : [];
57
- }
58
-
59
- /**
60
- * Batch-update referencedBy fields on all knowledge entries.
61
- * Scans all reference records and populates entry.referencedBy.
62
- */
63
- updateReferencedBy(): void {
64
- const records = this.readAll();
65
- const entryToDecisions = new Map<string, Set<string>>();
66
- const updates: StoreUpdate[] = [];
67
-
68
- for (const record of records) {
69
- for (const entryId of record.entryIds) {
70
- if (!entryToDecisions.has(entryId)) {
71
- entryToDecisions.set(entryId, new Set());
72
- }
73
- entryToDecisions.get(entryId)!.add(record.decisionId);
74
- }
75
- }
76
-
77
- for (const [entryId, decisions] of entryToDecisions) {
78
- updates.push({ id: entryId, partial: { referencedBy: [...decisions] } });
79
- }
80
- // 未知 id 由 applyAll 逐条跳过(与原先的 store.get 存在性判定同语义)
81
- this.store.applyAll(updates);
82
- }
83
-
84
- // ── Internal ───────────────────────────────────────────────
85
-
86
- private readAll(): ReferenceRecord[] {
87
- try {
88
- // 坏行策略:skip(harness#82:原「逐行 map 会抛 + 外层 catch 吞成整文件 []」
89
- // ——坏一行丢全部记录——不可接受,改为单行损坏只丢该行);
90
- // 外层 catch 仅兜 IO 读取错误,沿用原吞掉语义
91
- // 计数去向:豁免(harness#100)——三个消费点 getReferencesForEntry /
92
- // getReferencesForDecision / updateReferencedBy 只按合法记录取引用关系。
93
- // 代价如实记录:checkOrphans(knowledge/lint.ts)以 refs.length>0 判孤儿,
94
- // 坏行会让它给出假孤儿判定,不只是少报;透传需要给 LintIssue / `knowledge health`
95
- // 报告加计数位,属 knowledge 域输出形状变更,另票收口
96
- return readJsonl<ReferenceRecord>(this.filePath, 'skip').records;
97
- } catch {
98
- return [];
99
- }
100
- }
101
- }