@dommaker/harness 1.16.0 → 2.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 (504) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/agents/lifecycle.d.ts.map +1 -1
  3. package/dist/agents/lifecycle.js +3 -6
  4. package/dist/agents/lifecycle.js.map +1 -1
  5. package/dist/cli/command-contract.d.ts +6 -9
  6. package/dist/cli/command-contract.d.ts.map +1 -1
  7. package/dist/cli/command-contract.js +6 -0
  8. package/dist/cli/command-contract.js.map +1 -1
  9. package/dist/cli/commands/acceptance.d.ts.map +1 -1
  10. package/dist/cli/commands/acceptance.js +8 -7
  11. package/dist/cli/commands/acceptance.js.map +1 -1
  12. package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
  13. package/dist/cli/commands/constraints-retire.js +2 -1
  14. package/dist/cli/commands/constraints-retire.js.map +1 -1
  15. package/dist/cli/commands/contract.d.ts.map +1 -1
  16. package/dist/cli/commands/contract.js +20 -10
  17. package/dist/cli/commands/contract.js.map +1 -1
  18. package/dist/cli/commands/definitions.d.ts.map +1 -1
  19. package/dist/cli/commands/definitions.js +13 -12
  20. package/dist/cli/commands/definitions.js.map +1 -1
  21. package/dist/cli/commands/init/ci-platform.d.ts +35 -0
  22. package/dist/cli/commands/init/ci-platform.d.ts.map +1 -0
  23. package/dist/cli/commands/init/ci-platform.js +59 -0
  24. package/dist/cli/commands/init/ci-platform.js.map +1 -0
  25. package/dist/cli/commands/init/ci-wiring.d.ts +20 -0
  26. package/dist/cli/commands/init/ci-wiring.d.ts.map +1 -0
  27. package/dist/cli/commands/init/ci-wiring.js +72 -0
  28. package/dist/cli/commands/init/ci-wiring.js.map +1 -0
  29. package/dist/cli/commands/init/git-hooks.d.ts +15 -0
  30. package/dist/cli/commands/init/git-hooks.d.ts.map +1 -0
  31. package/dist/cli/commands/init/git-hooks.js +64 -0
  32. package/dist/cli/commands/init/git-hooks.js.map +1 -0
  33. package/dist/cli/commands/init/governance.d.ts +14 -0
  34. package/dist/cli/commands/init/governance.d.ts.map +1 -0
  35. package/dist/cli/commands/init/governance.js +132 -0
  36. package/dist/cli/commands/init/governance.js.map +1 -0
  37. package/dist/cli/commands/{init.d.ts → init/index.d.ts} +13 -14
  38. package/dist/cli/commands/init/index.d.ts.map +1 -0
  39. package/dist/cli/commands/init/index.js +148 -0
  40. package/dist/cli/commands/init/index.js.map +1 -0
  41. package/dist/cli/commands/init/output-style.d.ts +19 -0
  42. package/dist/cli/commands/init/output-style.d.ts.map +1 -0
  43. package/dist/cli/commands/init/output-style.js +110 -0
  44. package/dist/cli/commands/init/output-style.js.map +1 -0
  45. package/dist/cli/commands/init/presets.d.ts +26 -0
  46. package/dist/cli/commands/init/presets.d.ts.map +1 -0
  47. package/dist/cli/commands/init/presets.js +104 -0
  48. package/dist/cli/commands/init/presets.js.map +1 -0
  49. package/dist/cli/commands/init/snippets.d.ts +18 -0
  50. package/dist/cli/commands/init/snippets.d.ts.map +1 -0
  51. package/dist/cli/commands/init/snippets.js +49 -0
  52. package/dist/cli/commands/init/snippets.js.map +1 -0
  53. package/dist/cli/commands/knowledge/audit.d.ts +30 -0
  54. package/dist/cli/commands/knowledge/audit.d.ts.map +1 -0
  55. package/dist/cli/commands/knowledge/audit.js +114 -0
  56. package/dist/cli/commands/knowledge/audit.js.map +1 -0
  57. package/dist/cli/commands/knowledge/decay.d.ts +19 -0
  58. package/dist/cli/commands/knowledge/decay.d.ts.map +1 -0
  59. package/dist/cli/commands/knowledge/decay.js +48 -0
  60. package/dist/cli/commands/knowledge/decay.js.map +1 -0
  61. package/dist/cli/commands/knowledge/health.d.ts +36 -0
  62. package/dist/cli/commands/knowledge/health.d.ts.map +1 -0
  63. package/dist/cli/commands/knowledge/health.js +172 -0
  64. package/dist/cli/commands/knowledge/health.js.map +1 -0
  65. package/dist/cli/commands/knowledge/import.d.ts +26 -0
  66. package/dist/cli/commands/knowledge/import.d.ts.map +1 -0
  67. package/dist/cli/commands/knowledge/import.js +63 -0
  68. package/dist/cli/commands/knowledge/import.js.map +1 -0
  69. package/dist/cli/commands/knowledge/index.d.ts +25 -0
  70. package/dist/cli/commands/knowledge/index.d.ts.map +1 -0
  71. package/dist/cli/commands/knowledge/index.js +84 -0
  72. package/dist/cli/commands/knowledge/index.js.map +1 -0
  73. package/dist/cli/commands/knowledge/list.d.ts +25 -0
  74. package/dist/cli/commands/knowledge/list.d.ts.map +1 -0
  75. package/dist/cli/commands/knowledge/list.js +60 -0
  76. package/dist/cli/commands/knowledge/list.js.map +1 -0
  77. package/dist/cli/commands/knowledge/migrate.d.ts +21 -0
  78. package/dist/cli/commands/knowledge/migrate.d.ts.map +1 -0
  79. package/dist/cli/commands/knowledge/migrate.js +48 -0
  80. package/dist/cli/commands/knowledge/migrate.js.map +1 -0
  81. package/dist/cli/commands/knowledge/search.d.ts +32 -0
  82. package/dist/cli/commands/knowledge/search.d.ts.map +1 -0
  83. package/dist/cli/commands/knowledge/search.js +73 -0
  84. package/dist/cli/commands/knowledge/search.js.map +1 -0
  85. package/dist/cli/commands/knowledge/shared.d.ts +14 -0
  86. package/dist/cli/commands/knowledge/shared.d.ts.map +1 -0
  87. package/dist/cli/commands/knowledge/shared.js +6 -0
  88. package/dist/cli/commands/knowledge/shared.js.map +1 -0
  89. package/dist/cli/commands/knowledge/snapshot.d.ts +18 -0
  90. package/dist/cli/commands/knowledge/snapshot.d.ts.map +1 -0
  91. package/dist/cli/commands/knowledge/snapshot.js +34 -0
  92. package/dist/cli/commands/knowledge/snapshot.js.map +1 -0
  93. package/dist/cli/commands/knowledge/stats.d.ts +26 -0
  94. package/dist/cli/commands/knowledge/stats.d.ts.map +1 -0
  95. package/dist/cli/commands/knowledge/stats.js +132 -0
  96. package/dist/cli/commands/knowledge/stats.js.map +1 -0
  97. package/dist/cli/commands/knowledge/sync-rag.d.ts +19 -0
  98. package/dist/cli/commands/knowledge/sync-rag.d.ts.map +1 -0
  99. package/dist/cli/commands/knowledge/sync-rag.js +77 -0
  100. package/dist/cli/commands/knowledge/sync-rag.js.map +1 -0
  101. package/dist/cli/commands/knowledge-view.d.ts +2 -1
  102. package/dist/cli/commands/knowledge-view.d.ts.map +1 -1
  103. package/dist/cli/commands/knowledge-view.js +2 -2
  104. package/dist/cli/commands/knowledge-view.js.map +1 -1
  105. package/dist/cli/commands/passes-gate.d.ts.map +1 -1
  106. package/dist/cli/commands/passes-gate.js +12 -2
  107. package/dist/cli/commands/passes-gate.js.map +1 -1
  108. package/dist/cli/commands/performance.js.map +1 -1
  109. package/dist/cli/commands/release.d.ts.map +1 -1
  110. package/dist/cli/commands/release.js +13 -41
  111. package/dist/cli/commands/release.js.map +1 -1
  112. package/dist/cli/commands/review.d.ts.map +1 -1
  113. package/dist/cli/commands/review.js +3 -2
  114. package/dist/cli/commands/review.js.map +1 -1
  115. package/dist/cli/commands/security.d.ts.map +1 -1
  116. package/dist/cli/commands/security.js +7 -8
  117. package/dist/cli/commands/security.js.map +1 -1
  118. package/dist/cli/commands/spec-baseline-check.d.ts.map +1 -1
  119. package/dist/cli/commands/spec-baseline-check.js +6 -5
  120. package/dist/cli/commands/spec-baseline-check.js.map +1 -1
  121. package/dist/cli/commands/status.js +2 -2
  122. package/dist/cli/commands/status.js.map +1 -1
  123. package/dist/cli/commands/sync-docs/agents-syncer.js +31 -55
  124. package/dist/cli/commands/sync-docs/agents-syncer.js.map +1 -1
  125. package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts.map +1 -1
  126. package/dist/cli/commands/sync-docs/capabilities-syncer.js +18 -12
  127. package/dist/cli/commands/sync-docs/capabilities-syncer.js.map +1 -1
  128. package/dist/cli/commands/sync-docs/compact.d.ts +9 -0
  129. package/dist/cli/commands/sync-docs/compact.d.ts.map +1 -0
  130. package/dist/cli/commands/sync-docs/compact.js +73 -0
  131. package/dist/cli/commands/sync-docs/compact.js.map +1 -0
  132. package/dist/cli/commands/sync-docs/context-syncer.d.ts.map +1 -1
  133. package/dist/cli/commands/sync-docs/context-syncer.js +17 -36
  134. package/dist/cli/commands/sync-docs/context-syncer.js.map +1 -1
  135. package/dist/cli/commands/sync-docs/gate.d.ts +27 -0
  136. package/dist/cli/commands/sync-docs/gate.d.ts.map +1 -0
  137. package/dist/cli/commands/sync-docs/gate.js +72 -0
  138. package/dist/cli/commands/sync-docs/gate.js.map +1 -0
  139. package/dist/cli/commands/sync-docs/index.d.ts +13 -27
  140. package/dist/cli/commands/sync-docs/index.d.ts.map +1 -1
  141. package/dist/cli/commands/sync-docs/index.js +19 -529
  142. package/dist/cli/commands/sync-docs/index.js.map +1 -1
  143. package/dist/cli/commands/sync-docs/main-flow.d.ts +37 -0
  144. package/dist/cli/commands/sync-docs/main-flow.d.ts.map +1 -0
  145. package/dist/cli/commands/sync-docs/main-flow.js +485 -0
  146. package/dist/cli/commands/sync-docs/main-flow.js.map +1 -0
  147. package/dist/cli/commands/sync-docs/project-reader.d.ts +1 -1
  148. package/dist/cli/commands/sync-docs/project-reader.d.ts.map +1 -1
  149. package/dist/cli/commands/sync-docs/project-reader.js +16 -25
  150. package/dist/cli/commands/sync-docs/project-reader.js.map +1 -1
  151. package/dist/cli/gate-command.d.ts +1 -1
  152. package/dist/cli/gate-command.d.ts.map +1 -1
  153. package/dist/context/index.d.ts +1 -3
  154. package/dist/context/index.d.ts.map +1 -1
  155. package/dist/context/index.js +2 -5
  156. package/dist/context/index.js.map +1 -1
  157. package/dist/context/session-manager.d.ts +2 -2
  158. package/dist/context/session-manager.d.ts.map +1 -1
  159. package/dist/context/session-manager.js +31 -52
  160. package/dist/context/session-manager.js.map +1 -1
  161. package/dist/context/types.d.ts +2 -2
  162. package/dist/context/types.d.ts.map +1 -1
  163. package/dist/core/constraint-lifecycle.d.ts +1 -1
  164. package/dist/core/constraint-lifecycle.d.ts.map +1 -1
  165. package/dist/core/constraint-lifecycle.js +1 -1
  166. package/dist/core/constraint-lifecycle.js.map +1 -1
  167. package/dist/core/constraints/capabilities-parser.d.ts +2 -1
  168. package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
  169. package/dist/core/constraints/capabilities-parser.js +4 -6
  170. package/dist/core/constraints/capabilities-parser.js.map +1 -1
  171. package/dist/core/constraints/checkers/templated/exec.d.ts.map +1 -1
  172. package/dist/core/constraints/checkers/templated/exec.js +1 -0
  173. package/dist/core/constraints/checkers/templated/exec.js.map +1 -1
  174. package/dist/core/constraints/checkers/templated/file-exists.js +1 -1
  175. package/dist/core/constraints/checkers/templated/file-exists.js.map +1 -1
  176. package/dist/core/constraints/context-builder.d.ts.map +1 -1
  177. package/dist/core/constraints/context-builder.js +13 -34
  178. package/dist/core/constraints/context-builder.js.map +1 -1
  179. package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
  180. package/dist/core/constraints/definitions/guidelines.js +18 -0
  181. package/dist/core/constraints/definitions/guidelines.js.map +1 -1
  182. package/dist/core/constraints/definitions/iron-laws.d.ts.map +1 -1
  183. package/dist/core/constraints/definitions/iron-laws.js +0 -16
  184. package/dist/core/constraints/definitions/iron-laws.js.map +1 -1
  185. package/dist/core/constraints/doc-freshness/runner.d.ts.map +1 -1
  186. package/dist/core/constraints/doc-freshness/runner.js +192 -223
  187. package/dist/core/constraints/doc-freshness/runner.js.map +1 -1
  188. package/dist/core/constraints/git-evidence.d.ts.map +1 -1
  189. package/dist/core/constraints/git-evidence.js +2 -0
  190. package/dist/core/constraints/git-evidence.js.map +1 -1
  191. package/dist/core/constraints/injection-writer.d.ts +1 -0
  192. package/dist/core/constraints/injection-writer.d.ts.map +1 -1
  193. package/dist/core/constraints/injection-writer.js +3 -6
  194. package/dist/core/constraints/injection-writer.js.map +1 -1
  195. package/dist/core/project-config-loader.d.ts +3 -1
  196. package/dist/core/project-config-loader.d.ts.map +1 -1
  197. package/dist/core/project-config-loader.js +6 -6
  198. package/dist/core/project-config-loader.js.map +1 -1
  199. package/dist/core/spec/validator.d.ts +1 -1
  200. package/dist/core/spec/validator.d.ts.map +1 -1
  201. package/dist/core/spec/validator.js +41 -36
  202. package/dist/core/spec/validator.js.map +1 -1
  203. package/dist/core/validators/check-handlers/command.d.ts.map +1 -1
  204. package/dist/core/validators/check-handlers/command.js +7 -4
  205. package/dist/core/validators/check-handlers/command.js.map +1 -1
  206. package/dist/core/validators/check-handlers/http.d.ts.map +1 -1
  207. package/dist/core/validators/check-handlers/http.js +6 -4
  208. package/dist/core/validators/check-handlers/http.js.map +1 -1
  209. package/dist/core/validators/check-handlers/output.d.ts +1 -1
  210. package/dist/core/validators/check-handlers/output.d.ts.map +1 -1
  211. package/dist/core/validators/check-handlers/output.js +2 -1
  212. package/dist/core/validators/check-handlers/output.js.map +1 -1
  213. package/dist/core/validators/passes-gate.d.ts +2 -1
  214. package/dist/core/validators/passes-gate.d.ts.map +1 -1
  215. package/dist/core/validators/passes-gate.js +25 -30
  216. package/dist/core/validators/passes-gate.js.map +1 -1
  217. package/dist/gates/acceptance.d.ts +37 -18
  218. package/dist/gates/acceptance.d.ts.map +1 -1
  219. package/dist/gates/acceptance.js +129 -97
  220. package/dist/gates/acceptance.js.map +1 -1
  221. package/dist/gates/command.d.ts +1 -1
  222. package/dist/gates/contract.d.ts +11 -2
  223. package/dist/gates/contract.d.ts.map +1 -1
  224. package/dist/gates/contract.js +57 -62
  225. package/dist/gates/contract.js.map +1 -1
  226. package/dist/gates/performance.d.ts +1 -1
  227. package/dist/gates/performance.d.ts.map +1 -1
  228. package/dist/gates/performance.js +18 -8
  229. package/dist/gates/performance.js.map +1 -1
  230. package/dist/gates/registry.d.ts.map +1 -1
  231. package/dist/gates/registry.js +6 -2
  232. package/dist/gates/registry.js.map +1 -1
  233. package/dist/gates/review.d.ts.map +1 -1
  234. package/dist/gates/review.js +16 -2
  235. package/dist/gates/review.js.map +1 -1
  236. package/dist/gates/security.d.ts +5 -1
  237. package/dist/gates/security.d.ts.map +1 -1
  238. package/dist/gates/security.js +57 -63
  239. package/dist/gates/security.js.map +1 -1
  240. package/dist/gates/types.d.ts +11 -78
  241. package/dist/gates/types.d.ts.map +1 -1
  242. package/dist/gates/types.js +5 -1
  243. package/dist/gates/types.js.map +1 -1
  244. package/dist/index.d.ts +9 -2
  245. package/dist/index.d.ts.map +1 -1
  246. package/dist/index.js +10 -3
  247. package/dist/index.js.map +1 -1
  248. package/dist/knowledge/audit-dimensions.d.ts +45 -0
  249. package/dist/knowledge/audit-dimensions.d.ts.map +1 -0
  250. package/dist/knowledge/audit-dimensions.js +144 -0
  251. package/dist/knowledge/audit-dimensions.js.map +1 -0
  252. package/dist/knowledge/audit-rules.d.ts +41 -0
  253. package/dist/knowledge/audit-rules.d.ts.map +1 -0
  254. package/dist/knowledge/audit-rules.js +269 -0
  255. package/dist/knowledge/audit-rules.js.map +1 -0
  256. package/dist/knowledge/audit-scoring.d.ts +6 -60
  257. package/dist/knowledge/audit-scoring.d.ts.map +1 -1
  258. package/dist/knowledge/audit-scoring.js +8 -391
  259. package/dist/knowledge/audit-scoring.js.map +1 -1
  260. package/dist/knowledge/audit.d.ts +6 -3
  261. package/dist/knowledge/audit.d.ts.map +1 -1
  262. package/dist/knowledge/audit.js +9 -6
  263. package/dist/knowledge/audit.js.map +1 -1
  264. package/dist/knowledge/import.d.ts.map +1 -1
  265. package/dist/knowledge/import.js +5 -4
  266. package/dist/knowledge/import.js.map +1 -1
  267. package/dist/knowledge/index-generator.d.ts +2 -0
  268. package/dist/knowledge/index-generator.d.ts.map +1 -1
  269. package/dist/knowledge/index-generator.js +43 -50
  270. package/dist/knowledge/index-generator.js.map +1 -1
  271. package/dist/knowledge/index.d.ts +4 -2
  272. package/dist/knowledge/index.d.ts.map +1 -1
  273. package/dist/knowledge/index.js +2 -1
  274. package/dist/knowledge/index.js.map +1 -1
  275. package/dist/knowledge/ingest.d.ts +21 -5
  276. package/dist/knowledge/ingest.d.ts.map +1 -1
  277. package/dist/knowledge/ingest.js +12 -9
  278. package/dist/knowledge/ingest.js.map +1 -1
  279. package/dist/knowledge/lifecycle.d.ts.map +1 -1
  280. package/dist/knowledge/lifecycle.js +17 -22
  281. package/dist/knowledge/lifecycle.js.map +1 -1
  282. package/dist/knowledge/query.d.ts +1 -1
  283. package/dist/knowledge/query.d.ts.map +1 -1
  284. package/dist/knowledge/query.js +7 -7
  285. package/dist/knowledge/query.js.map +1 -1
  286. package/dist/knowledge/reference-tracker.d.ts.map +1 -1
  287. package/dist/knowledge/reference-tracker.js +14 -17
  288. package/dist/knowledge/reference-tracker.js.map +1 -1
  289. package/dist/knowledge/store.d.ts.map +1 -1
  290. package/dist/knowledge/store.js +17 -36
  291. package/dist/knowledge/store.js.map +1 -1
  292. package/dist/monitoring/trace-analyzer.d.ts +2 -2
  293. package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
  294. package/dist/monitoring/trace-analyzer.js +9 -7
  295. package/dist/monitoring/trace-analyzer.js.map +1 -1
  296. package/dist/monitoring/traces.d.ts.map +1 -1
  297. package/dist/monitoring/traces.js +6 -4
  298. package/dist/monitoring/traces.js.map +1 -1
  299. package/dist/pretool-use-hook.d.ts +1 -1
  300. package/dist/pretool-use-hook.d.ts.map +1 -1
  301. package/dist/pretool-use-hook.js +12 -19
  302. package/dist/pretool-use-hook.js.map +1 -1
  303. package/dist/release/integrity.d.ts.map +1 -1
  304. package/dist/release/integrity.js +8 -8
  305. package/dist/release/integrity.js.map +1 -1
  306. package/dist/sdd/index-generator.d.ts.map +1 -1
  307. package/dist/sdd/index-generator.js +4 -0
  308. package/dist/sdd/index-generator.js.map +1 -1
  309. package/dist/types/checkpoint.d.ts +8 -8
  310. package/dist/types/checkpoint.d.ts.map +1 -1
  311. package/dist/types/command-io.d.ts +19 -0
  312. package/dist/types/command-io.d.ts.map +1 -0
  313. package/dist/types/command-io.js +3 -0
  314. package/dist/types/command-io.js.map +1 -0
  315. package/dist/types/gate.d.ts +72 -0
  316. package/dist/types/gate.d.ts.map +1 -0
  317. package/dist/types/gate.js +13 -0
  318. package/dist/types/gate.js.map +1 -0
  319. package/dist/utils/attempt.d.ts +22 -0
  320. package/dist/utils/attempt.d.ts.map +1 -0
  321. package/dist/utils/attempt.js +40 -0
  322. package/dist/utils/attempt.js.map +1 -0
  323. package/dist/utils/detect-source-roots.d.ts.map +1 -1
  324. package/dist/utils/detect-source-roots.js +42 -51
  325. package/dist/utils/detect-source-roots.js.map +1 -1
  326. package/dist/utils/file-walk.d.ts +2 -1
  327. package/dist/utils/file-walk.d.ts.map +1 -1
  328. package/dist/utils/file-walk.js +3 -8
  329. package/dist/utils/file-walk.js.map +1 -1
  330. package/dist/utils/package-json.d.ts +49 -0
  331. package/dist/utils/package-json.d.ts.map +1 -0
  332. package/dist/utils/package-json.js +78 -0
  333. package/dist/utils/package-json.js.map +1 -0
  334. package/dist/utils/package-version.d.ts +5 -2
  335. package/dist/utils/package-version.d.ts.map +1 -1
  336. package/dist/utils/package-version.js +8 -11
  337. package/dist/utils/package-version.js.map +1 -1
  338. package/package.json +1 -6
  339. package/src/CONTEXT.md +5 -4
  340. package/src/__tests__/acceptance-gate.test.ts +23 -51
  341. package/src/__tests__/contract-gate.test.ts +1 -1
  342. package/src/__tests__/install-precommit-hook.test.ts +61 -0
  343. package/src/__tests__/iron-laws.test.ts +5 -5
  344. package/src/__tests__/layering.test.ts +1 -1
  345. package/src/__tests__/public-exports.test.ts +1 -1
  346. package/src/__tests__/public-type-surface.test.ts +9 -19
  347. package/src/__tests__/public-value-surface.test.ts +9 -17
  348. package/src/__tests__/skip-semantics.test.ts +5 -4
  349. package/src/agents/lifecycle.ts +3 -5
  350. package/src/cli/__tests__/command-contract.test.ts +18 -0
  351. package/src/cli/command-contract.ts +8 -5
  352. package/src/cli/commands/CONTEXT.md +10 -10
  353. package/src/cli/commands/__tests__/check.test.ts +1 -1
  354. package/src/cli/commands/__tests__/constraints-retire.test.ts +5 -3
  355. package/src/cli/commands/__tests__/init-governance-io.test.ts +7 -2
  356. package/src/cli/commands/__tests__/init.test.ts +1 -1
  357. package/src/cli/commands/__tests__/knowledge-audit-threshold.test.ts +14 -8
  358. package/src/cli/commands/__tests__/knowledge-flywheel-consistency.test.ts +2 -1
  359. package/src/cli/commands/__tests__/knowledge-view.test.ts +28 -18
  360. package/src/cli/commands/__tests__/knowledge.test.ts +6 -2
  361. package/src/cli/commands/__tests__/numeric-flag-assembly.test.ts +1 -1
  362. package/src/cli/commands/__tests__/passes-gate.test.ts +100 -24
  363. package/src/cli/commands/__tests__/project-path-anchoring.test.ts +3 -6
  364. package/src/cli/commands/__tests__/registry.test.ts +3 -2
  365. package/src/cli/commands/__tests__/release.test.ts +24 -2
  366. package/src/cli/commands/__tests__/report-false-green.test.ts +10 -6
  367. package/src/cli/commands/acceptance.ts +10 -9
  368. package/src/cli/commands/command.ts +1 -1
  369. package/src/cli/commands/constraints-retire.ts +3 -2
  370. package/src/cli/commands/contract.ts +29 -14
  371. package/src/cli/commands/definitions.ts +13 -12
  372. package/src/cli/commands/init/ci-platform.ts +66 -0
  373. package/src/cli/commands/init/ci-wiring.ts +48 -0
  374. package/src/cli/commands/init/git-hooks.ts +31 -0
  375. package/src/cli/commands/init/governance.ts +127 -0
  376. package/src/cli/commands/init/index.ts +156 -0
  377. package/src/cli/commands/init/output-style.ts +82 -0
  378. package/src/cli/commands/init/presets.ts +105 -0
  379. package/src/cli/commands/init/snippets.ts +57 -0
  380. package/src/cli/commands/knowledge/audit.ts +155 -0
  381. package/src/cli/commands/knowledge/decay.ts +57 -0
  382. package/src/cli/commands/knowledge/health.ts +176 -0
  383. package/src/cli/commands/knowledge/import.ts +82 -0
  384. package/src/cli/commands/knowledge/index.ts +60 -0
  385. package/src/cli/commands/knowledge/list.ts +73 -0
  386. package/src/cli/commands/knowledge/migrate.ts +61 -0
  387. package/src/cli/commands/knowledge/search.ts +93 -0
  388. package/src/cli/commands/knowledge/shared.ts +13 -0
  389. package/src/cli/commands/knowledge/snapshot.ts +38 -0
  390. package/src/cli/commands/knowledge/stats.ts +112 -0
  391. package/src/cli/commands/knowledge/sync-rag.ts +48 -0
  392. package/src/cli/commands/knowledge-view.ts +3 -2
  393. package/src/cli/commands/passes-gate.ts +14 -2
  394. package/src/cli/commands/performance.ts +2 -2
  395. package/src/cli/commands/release.ts +14 -9
  396. package/src/cli/commands/review.ts +5 -4
  397. package/src/cli/commands/security.ts +10 -11
  398. package/src/cli/commands/spec-baseline-check.ts +6 -7
  399. package/src/cli/commands/status.ts +2 -2
  400. package/src/cli/commands/sync-docs/agents-syncer.ts +28 -47
  401. package/src/cli/commands/sync-docs/capabilities-syncer.ts +18 -11
  402. package/src/cli/commands/sync-docs/compact.ts +35 -0
  403. package/src/cli/commands/sync-docs/context-syncer.ts +15 -31
  404. package/src/cli/commands/sync-docs/gate.ts +78 -0
  405. package/src/cli/commands/sync-docs/index.ts +21 -585
  406. package/src/cli/commands/sync-docs/main-flow.ts +549 -0
  407. package/src/cli/commands/sync-docs/project-reader.ts +21 -24
  408. package/src/cli/gate-command.ts +1 -1
  409. package/src/context/CONTEXT.md +4 -4
  410. package/src/context/__tests__/session-manager.test.ts +18 -0
  411. package/src/context/index.ts +1 -5
  412. package/src/context/session-manager.ts +34 -50
  413. package/src/context/types.ts +2 -2
  414. package/src/core/CONTEXT.md +2 -2
  415. package/src/core/constraint-lifecycle.ts +2 -2
  416. package/src/core/constraints/capabilities-parser.ts +4 -6
  417. package/src/core/constraints/checkers/templated/exec.ts +1 -0
  418. package/src/core/constraints/checkers/templated/file-exists.ts +1 -1
  419. package/src/core/constraints/context-builder.ts +11 -28
  420. package/src/core/constraints/definitions/guidelines.ts +19 -0
  421. package/src/core/constraints/definitions/iron-laws.ts +0 -17
  422. package/src/core/constraints/doc-freshness/runner.ts +220 -244
  423. package/src/core/constraints/git-evidence.ts +2 -0
  424. package/src/core/constraints/injection-writer.ts +3 -6
  425. package/src/core/project-config-loader.ts +6 -5
  426. package/src/core/spec/__tests__/validator.test.ts +65 -13
  427. package/src/core/spec/validator.ts +50 -40
  428. package/src/core/validators/__tests__/passes-gate-counts.test.ts +52 -0
  429. package/src/core/validators/check-handlers/command.ts +9 -6
  430. package/src/core/validators/check-handlers/http.ts +8 -6
  431. package/src/core/validators/check-handlers/output.ts +7 -6
  432. package/src/core/validators/passes-gate.ts +31 -32
  433. package/src/gates/CONTEXT.md +7 -6
  434. package/src/gates/__tests__/acceptance-types-single-source.test.ts +16 -14
  435. package/src/gates/__tests__/acceptance.test.ts +69 -94
  436. package/src/gates/__tests__/command-single-predicate.test.ts +1 -1
  437. package/src/gates/__tests__/command.test.ts +23 -12
  438. package/src/gates/__tests__/gate-interface.test.ts +2 -5
  439. package/src/gates/__tests__/performance.test.ts +3 -3
  440. package/src/gates/__tests__/security.test.ts +7 -19
  441. package/src/gates/acceptance.ts +176 -131
  442. package/src/gates/command.ts +1 -1
  443. package/src/gates/contract.ts +86 -79
  444. package/src/gates/performance.ts +35 -19
  445. package/src/gates/registry.ts +6 -3
  446. package/src/gates/review.ts +38 -10
  447. package/src/gates/security.ts +94 -81
  448. package/src/gates/types.ts +22 -84
  449. package/src/index.ts +8 -4
  450. package/src/knowledge/CONTEXT.md +9 -7
  451. package/src/knowledge/__tests__/audit-labels.test.ts +3 -3
  452. package/src/knowledge/__tests__/audit-scoring.test.ts +9 -7
  453. package/src/knowledge/__tests__/ingest.test.ts +17 -17
  454. package/src/knowledge/__tests__/store.test.ts +4 -6
  455. package/src/knowledge/audit-dimensions.ts +190 -0
  456. package/src/knowledge/audit-rules.ts +335 -0
  457. package/src/knowledge/audit-scoring.ts +7 -495
  458. package/src/knowledge/audit.ts +9 -11
  459. package/src/knowledge/import.ts +7 -6
  460. package/src/knowledge/index-generator.ts +48 -53
  461. package/src/knowledge/index.ts +4 -2
  462. package/src/knowledge/ingest.ts +27 -12
  463. package/src/knowledge/lifecycle.ts +17 -19
  464. package/src/knowledge/query.ts +7 -6
  465. package/src/knowledge/reference-tracker.ts +14 -16
  466. package/src/knowledge/store.ts +17 -32
  467. package/src/monitoring/trace-analyzer.ts +12 -9
  468. package/src/monitoring/traces.ts +8 -6
  469. package/src/pretool-use-hook.ts +26 -21
  470. package/src/release/CONTEXT.md +1 -1
  471. package/src/release/__tests__/integrity.test.ts +0 -2
  472. package/src/release/integrity.ts +8 -9
  473. package/src/sdd/index-generator.ts +4 -0
  474. package/src/types/checkpoint.ts +8 -8
  475. package/src/types/command-io.ts +14 -0
  476. package/src/types/gate.ts +77 -0
  477. package/src/utils/__tests__/attempt.test.ts +94 -0
  478. package/src/utils/__tests__/package-json.test.ts +58 -0
  479. package/src/utils/__tests__/package-version.test.ts +21 -2
  480. package/src/utils/attempt.ts +35 -0
  481. package/src/utils/detect-source-roots.ts +38 -44
  482. package/src/utils/file-walk.ts +3 -7
  483. package/src/utils/package-json.ts +61 -0
  484. package/src/utils/package-version.ts +8 -10
  485. package/dist/cli/commands/init.d.ts.map +0 -1
  486. package/dist/cli/commands/init.js +0 -502
  487. package/dist/cli/commands/init.js.map +0 -1
  488. package/dist/cli/commands/knowledge.d.ts +0 -169
  489. package/dist/cli/commands/knowledge.d.ts.map +0 -1
  490. package/dist/cli/commands/knowledge.js +0 -700
  491. package/dist/cli/commands/knowledge.js.map +0 -1
  492. package/dist/context/knowledge-injector.d.ts +0 -51
  493. package/dist/context/knowledge-injector.d.ts.map +0 -1
  494. package/dist/context/knowledge-injector.js +0 -128
  495. package/dist/context/knowledge-injector.js.map +0 -1
  496. package/dist/gates/index.d.ts +0 -10
  497. package/dist/gates/index.d.ts.map +0 -1
  498. package/dist/gates/index.js +0 -11
  499. package/dist/gates/index.js.map +0 -1
  500. package/src/cli/commands/init.ts +0 -590
  501. package/src/cli/commands/knowledge.ts +0 -820
  502. package/src/context/__tests__/knowledge-injector.test.ts +0 -197
  503. package/src/context/knowledge-injector.ts +0 -174
  504. package/src/gates/index.ts +0 -11
@@ -1,700 +0,0 @@
1
- "use strict";
2
- /**
3
- * harness knowledge 命令
4
- *
5
- * 知识库管理 11 子操作(list/search/import/decay/stats/sync-rag/audit/snapshot/migrate/index/health)。
6
- * 本文件只做「取数 + 声明两投影」:json 面正本在 `data`,人读排版在 `human()` 的
7
- * display model。上色、label 映射、json/人读分派、退出码、路径解析与 store 构造
8
- * 统一在 knowledge-view.ts(harness#133,架构评审候选4)。
9
- */
10
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- var desc = Object.getOwnPropertyDescriptor(m, k);
13
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
- desc = { enumerable: true, get: function() { return m[k]; } };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }) : (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- o[k2] = m[k];
20
- }));
21
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
- Object.defineProperty(o, "default", { enumerable: true, value: v });
23
- }) : function(o, v) {
24
- o["default"] = v;
25
- });
26
- var __importStar = (this && this.__importStar) || (function () {
27
- var ownKeys = function(o) {
28
- ownKeys = Object.getOwnPropertyNames || function (o) {
29
- var ar = [];
30
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
- return ar;
32
- };
33
- return ownKeys(o);
34
- };
35
- return function (mod) {
36
- if (mod && mod.__esModule) return mod;
37
- var result = {};
38
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
- __setModuleDefault(result, mod);
40
- return result;
41
- };
42
- })();
43
- Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.knowledgeListView = knowledgeListView;
45
- exports.knowledgeList = knowledgeList;
46
- exports.knowledgeSearchView = knowledgeSearchView;
47
- exports.knowledgeSearch = knowledgeSearch;
48
- exports.knowledgeSearchCommand = knowledgeSearchCommand;
49
- exports.knowledgeImportView = knowledgeImportView;
50
- exports.knowledgeImport = knowledgeImport;
51
- exports.knowledgeDecayView = knowledgeDecayView;
52
- exports.knowledgeDecay = knowledgeDecay;
53
- exports.knowledgeStatsView = knowledgeStatsView;
54
- exports.knowledgeStats = knowledgeStats;
55
- exports.knowledgeSyncRagView = knowledgeSyncRagView;
56
- exports.knowledgeSyncRag = knowledgeSyncRag;
57
- exports.knowledgeAuditView = knowledgeAuditView;
58
- exports.knowledgeAudit = knowledgeAudit;
59
- exports.knowledgeSnapshotView = knowledgeSnapshotView;
60
- exports.knowledgeSnapshot = knowledgeSnapshot;
61
- exports.knowledgeMigrateView = knowledgeMigrateView;
62
- exports.knowledgeMigrate = knowledgeMigrate;
63
- exports.knowledgeIndexView = knowledgeIndexView;
64
- exports.knowledgeIndex = knowledgeIndex;
65
- exports.knowledgeHealthView = knowledgeHealthView;
66
- exports.knowledgeHealth = knowledgeHealth;
67
- const fs = __importStar(require("fs"));
68
- const path = __importStar(require("path"));
69
- const query_1 = require("../../knowledge/query");
70
- const lifecycle_1 = require("../../knowledge/lifecycle");
71
- const import_1 = require("../../knowledge/import");
72
- const audit_1 = require("../../knowledge/audit");
73
- const flywheel_metrics_1 = require("../../knowledge/flywheel-metrics");
74
- const migration_1 = require("../../knowledge/migration");
75
- const index_generator_1 = require("../../knowledge/index-generator");
76
- const command_contract_1 = require("../command-contract");
77
- const numeric_flag_1 = require("../../utils/numeric-flag");
78
- const knowledge_view_1 = require("./knowledge-view");
79
- // ========================================
80
- // list
81
- // ========================================
82
- function listFilter(options) {
83
- const filter = { excludeArchived: false };
84
- if (options.type)
85
- filter.types = options.type.split(',');
86
- if (options.maturity)
87
- filter.maturity = options.maturity.split(',');
88
- if (options.tag)
89
- filter.tags = options.tag.split(',');
90
- return filter;
91
- }
92
- function knowledgeListView(options, io) {
93
- const entries = (0, knowledge_view_1.openKnowledgeStore)(options, io).list(listFilter(options));
94
- const data = { total: entries.length, entries };
95
- return { data, human: () => ({ sections: [{ rows: listRows(entries) }] }) };
96
- }
97
- function listRows(entries) {
98
- if (entries.length === 0) {
99
- return [{ cells: [{ label: '知识库为空', tone: 'warn' }] }];
100
- }
101
- const rows = [
102
- { cells: [
103
- { label: '📚 知识库 (', tone: 'heading' },
104
- { field: 'total', text: String(entries.length), tone: 'heading' },
105
- { label: ' 条)', tone: 'heading' },
106
- ] },
107
- (0, knowledge_view_1.blankLine)(),
108
- ];
109
- entries.forEach((entry, i) => {
110
- rows.push({ cells: [
111
- { field: `entries.${i}.maturity`, text: ` [${entry.maturity}]`, tone: (0, knowledge_view_1.toneForMaturity)(entry.maturity) },
112
- { field: `entries.${i}.title`, text: ` ${entry.title}`, tone: 'emph' },
113
- ] });
114
- rows.push({ cells: [
115
- { field: `entries.${i}.id`, text: ` id: ${entry.id}`, tone: 'muted' },
116
- { field: `entries.${i}.type`, text: ` | type: ${entry.type}`, tone: 'muted' },
117
- { field: `entries.${i}.layer`, text: ` | layer: ${entry.layer}`, tone: 'muted' },
118
- ] });
119
- if (entry.tags.length > 0) {
120
- rows.push({ cells: [{ field: `entries.${i}.tags`, text: ` tags: ${entry.tags.join(', ')}`, tone: 'muted' }] });
121
- }
122
- });
123
- return rows;
124
- }
125
- async function knowledgeList(options, io = command_contract_1.processIO) {
126
- return (0, knowledge_view_1.emitKnowledgeView)(io, options, knowledgeListView(options, io));
127
- }
128
- // ========================================
129
- // search
130
- // ========================================
131
- function knowledgeSearchView(query, options, io) {
132
- const store = (0, knowledge_view_1.openKnowledgeStore)(options, io);
133
- const matched = new query_1.KnowledgeQuery(store).search(query, { limit: options.limit ?? 20 });
134
- const data = { query, total: matched.length, entries: matched };
135
- return { data, human: () => ({ sections: [{ rows: searchRows(query, matched) }] }) };
136
- }
137
- function searchRows(query, matched) {
138
- if (matched.length === 0) {
139
- return [{ cells: [{ label: `未找到匹配 "${query}" 的知识条目`, tone: 'warn' }] }];
140
- }
141
- const rows = [
142
- { cells: [
143
- { label: '🔍 搜索 "', tone: 'heading' },
144
- { field: 'query', text: query, tone: 'heading' },
145
- { label: '" (', tone: 'heading' },
146
- { field: 'total', text: String(matched.length), tone: 'heading' },
147
- { label: ' 条结果)', tone: 'heading' },
148
- ] },
149
- (0, knowledge_view_1.blankLine)(),
150
- ];
151
- matched.forEach((entry, i) => {
152
- const preview = entry.content.slice(0, 100).replace(/\n/g, ' ') + (entry.content.length > 100 ? '...' : '');
153
- rows.push({ cells: [
154
- { field: `entries.${i}.title`, text: ` ${entry.title}`, tone: 'emph' },
155
- { field: `entries.${i}.maturity`, text: ` [${entry.maturity}]`, tone: 'muted' },
156
- ] });
157
- rows.push({ cells: [{ field: `entries.${i}.content`, text: ` ${preview}`, tone: 'muted' }] });
158
- });
159
- return rows;
160
- }
161
- async function knowledgeSearch(query, options, io = command_contract_1.processIO) {
162
- return (0, knowledge_view_1.emitKnowledgeView)(io, options, knowledgeSearchView(query, options, io));
163
- }
164
- /**
165
- * knowledge search 子命令入口(候选7):缺参闸门 + limit 装配窄化,
166
- * 自 definitions.ts 的 args 复印块移回命令模块(interface/测试面所在)。
167
- * `--limit` 给到的恒是字符串(缺省 '20' 也是),脏输入 fail-loud(harness#154,
168
- * 原先 parseInt 出 NaN 被下游 `|| 20` 静默兜成缺省量)。
169
- */
170
- async function knowledgeSearchCommand(positionals, options, io = command_contract_1.processIO) {
171
- const query = positionals[0];
172
- if (!query) {
173
- (0, command_contract_1.logError)(io, '请提供搜索关键词');
174
- return { kind: 'usage-error', reason: 'knowledge search 缺少关键词位置参数' };
175
- }
176
- const limit = (0, numeric_flag_1.parseNumericFlag)(options.limit, 'int');
177
- if (!limit.ok) {
178
- (0, command_contract_1.logError)(io, (0, numeric_flag_1.numericFlagMessage)('--limit', limit.raw, 'int'));
179
- return { kind: 'usage-error', reason: `knowledge search --limit 非法限制: "${limit.raw}"` };
180
- }
181
- return knowledgeSearch(String(query), {
182
- projectPath: options.projectPath,
183
- json: options.json,
184
- limit: limit.value,
185
- }, io);
186
- }
187
- // ========================================
188
- // import(冷启动)
189
- // ========================================
190
- async function knowledgeImportView(options, io) {
191
- const projectPath = options.projectPath || process.cwd();
192
- const store = (0, knowledge_view_1.openKnowledgeStore)(options, io);
193
- const sources = options.sources
194
- ? options.sources.split(',')
195
- : ['code', 'git', 'docs'];
196
- const importer = new import_1.ColdStartImporter({ projectRoot: projectPath, store, sources });
197
- if (options.reset) {
198
- importer.resetState();
199
- (0, knowledge_view_1.announce)(io, options.json, '🔄 已重置导入状态', 'warn');
200
- }
201
- (0, knowledge_view_1.announce)(io, options.json, `📥 开始导入知识 (源: ${sources.join(', ')})...`);
202
- const results = await importer.importAll();
203
- const data = {
204
- totalImported: results.reduce((sum, r) => sum + r.entries.length, 0),
205
- totalErrors: results.reduce((sum, r) => sum + r.errors.length, 0),
206
- results,
207
- };
208
- return { data, human: () => ({ sections: [{ rows: importRows(data) }] }) };
209
- }
210
- function importRows(data) {
211
- const rows = [];
212
- data.results.forEach((result, i) => {
213
- if (result.entries.length > 0) {
214
- rows.push({ cells: [
215
- { field: `results.${i}.source.type`, text: ` ✅ ${result.source.type}: `, tone: 'ok' },
216
- { field: `results.${i}.entries.length`, text: `${result.entries.length} 条`, tone: 'ok' },
217
- ] });
218
- }
219
- result.errors.forEach((err, j) => {
220
- rows.push({ cells: [
221
- { field: `results.${i}.source.type`, text: ` ❌ ${result.source.type}: `, tone: 'error' },
222
- { field: `results.${i}.errors.${j}.message`, text: err.message, tone: 'error' },
223
- ] });
224
- });
225
- });
226
- rows.push((0, knowledge_view_1.blankLine)(), { cells: [
227
- { label: '✅ 导入完成: ', tone: 'ok' },
228
- { field: 'totalImported', text: String(data.totalImported), tone: 'ok' },
229
- { label: ' 条,', tone: 'ok' },
230
- { field: 'totalErrors', text: String(data.totalErrors), tone: 'ok' },
231
- { label: ' 个错误', tone: 'ok' },
232
- ] });
233
- return rows;
234
- }
235
- async function knowledgeImport(options, io = command_contract_1.processIO) {
236
- return (0, knowledge_view_1.emitKnowledgeView)(io, options, await knowledgeImportView(options, io));
237
- }
238
- // ========================================
239
- // decay
240
- // ========================================
241
- function knowledgeDecayView(options, io) {
242
- const lifecycle = new lifecycle_1.KnowledgeLifecycle((0, knowledge_view_1.openKnowledgeStore)(options, io));
243
- (0, knowledge_view_1.announce)(io, options.json, '🔄 运行衰减周期...');
244
- const changes = lifecycle.runDecayCycle();
245
- const data = { changes };
246
- return { data, human: () => ({ sections: [{ rows: decayRows(changes) }] }) };
247
- }
248
- function decayRows(changes) {
249
- if (changes.length === 0) {
250
- return [{ cells: [{ label: '✅ 没有需要衰减的知识条目', tone: 'ok' }] }];
251
- }
252
- const rows = [
253
- { cells: [
254
- { label: '📉 ', tone: 'warn' },
255
- { field: 'changes.length', text: String(changes.length), tone: 'warn' },
256
- { label: ' 条知识发生衰减:', tone: 'warn' },
257
- ] },
258
- (0, knowledge_view_1.blankLine)(),
259
- ];
260
- changes.forEach((change, i) => {
261
- rows.push({ cells: [
262
- { field: `changes.${i}.entryId`, text: ` ${change.entryId}: ` },
263
- { field: `changes.${i}.from`, text: change.from, tone: 'error' },
264
- { label: ' → ' },
265
- { field: `changes.${i}.to`, text: change.to, tone: 'ok' },
266
- ] });
267
- rows.push({ cells: [{ field: `changes.${i}.reason`, text: ` ${change.reason}`, tone: 'muted' }] });
268
- });
269
- return rows;
270
- }
271
- async function knowledgeDecay(options, io = command_contract_1.processIO) {
272
- return (0, knowledge_view_1.emitKnowledgeView)(io, options, knowledgeDecayView(options, io));
273
- }
274
- // ========================================
275
- // stats
276
- // ========================================
277
- function knowledgeStatsView(options, io) {
278
- const store = (0, knowledge_view_1.openKnowledgeStore)(options, io);
279
- const entries = store.list({ excludeArchived: false });
280
- const active = entries.filter(e => e.maturity !== 'archived');
281
- const byType = {};
282
- const byMaturity = {};
283
- const byLayer = {};
284
- for (const entry of entries) {
285
- byType[entry.type] = (byType[entry.type] || 0) + 1;
286
- byMaturity[entry.maturity] = (byMaturity[entry.maturity] || 0) + 1;
287
- byLayer[entry.layer] = (byLayer[entry.layer] || 0) + 1;
288
- }
289
- // 飞轮指标:计算唯一实现在 knowledge/flywheel-metrics,此处只做 fs 读取 + 展示层单位映射
290
- let dailyConsumptionEvents = 0;
291
- try {
292
- const statsPath = path.join(store.getBaseDir(), '.consumption-stats.json');
293
- if (fs.existsSync(statsPath)) {
294
- const stats = JSON.parse(fs.readFileSync(statsPath, 'utf-8'));
295
- dailyConsumptionEvents = stats.dailyEvents || 0;
296
- }
297
- }
298
- catch { /* best-effort */ }
299
- const metrics = (0, flywheel_metrics_1.evaluateFlywheel)({ entries: active, dailyConsumptionEvents });
300
- const flywheel = {
301
- refCoverage: Math.round(metrics.refCoverage * 100),
302
- avgRefs: Math.round(metrics.avgRefs * 10) / 10,
303
- consumptionHitRate: Math.round(metrics.consumptionHitRate * 100),
304
- };
305
- const data = { total: entries.length, byType, byMaturity, byLayer, flywheel };
306
- const activeCount = active.length;
307
- return {
308
- data,
309
- human: () => ({
310
- sections: [
311
- {
312
- rows: [
313
- { cells: [{ label: '📊 知识库统计', tone: 'heading' }] },
314
- (0, knowledge_view_1.blankLine)(),
315
- {
316
- cells: [
317
- { label: ' 总计: ', tone: 'emph' },
318
- { field: 'total', text: String(data.total), tone: 'emph' },
319
- { label: ' 条 (活跃: ', tone: 'emph' },
320
- { derived: 'activeCount', text: String(activeCount), tone: 'emph' },
321
- { label: ')', tone: 'emph' },
322
- ],
323
- },
324
- (0, knowledge_view_1.blankLine)(),
325
- ],
326
- },
327
- { title: ' 按类型:', rows: [...countRows('byType', byType), (0, knowledge_view_1.blankLine)()] },
328
- {
329
- title: ' 按成熟度:',
330
- rows: [...Object.entries(byMaturity).map(([maturity, count]) => ({
331
- cells: [
332
- { field: `byMaturity.${maturity}`, text: ` ${maturity}`, tone: (0, knowledge_view_1.toneForMaturity)(maturity) },
333
- { field: `byMaturity.${maturity}`, text: `: ${count}` },
334
- ],
335
- })), (0, knowledge_view_1.blankLine)()],
336
- },
337
- { title: ' 按层级:', rows: [...countRows('byLayer', byLayer), (0, knowledge_view_1.blankLine)()] },
338
- {
339
- title: ' 飞轮指标:',
340
- rows: [
341
- { cells: [{ label: ' 引用覆盖: ' }, { field: 'flywheel.refCoverage', text: `${flywheel.refCoverage}%` }] },
342
- { cells: [{ label: ' 平均引用: ' }, { field: 'flywheel.avgRefs', text: String(flywheel.avgRefs) }] },
343
- { cells: [{ label: ' 消费命中率: ' }, { field: 'flywheel.consumptionHitRate', text: `${flywheel.consumptionHitRate}%` }] },
344
- ],
345
- },
346
- ],
347
- }),
348
- };
349
- }
350
- function countRows(field, counts) {
351
- return Object.entries(counts).map(([key, count]) => ({
352
- cells: [
353
- { label: ' ' },
354
- { field: `${field}.${key}`, text: `${key}: ${count}` },
355
- ],
356
- }));
357
- }
358
- async function knowledgeStats(options, io = command_contract_1.processIO) {
359
- return (0, knowledge_view_1.emitKnowledgeView)(io, options, knowledgeStatsView(options, io));
360
- }
361
- // ========================================
362
- // sync-rag
363
- // ========================================
364
- function knowledgeSyncRagView(options) {
365
- const projectPath = options.projectPath || process.cwd();
366
- const docsDir = `${projectPath}/.harness/knowledge-docs`;
367
- const docsPresent = fs.existsSync(docsDir);
368
- const files = docsPresent ? fs.readdirSync(docsDir).filter(f => f.endsWith('.md')) : [];
369
- const data = { directory: docsDir, files };
370
- return { data, human: () => ({ sections: [{ rows: syncRagRows(docsPresent, docsDir, files) }] }) };
371
- }
372
- function syncRagRows(docsPresent, docsDir, files) {
373
- if (!docsPresent)
374
- return [{ cells: [{ label: 'No .harness/knowledge-docs/ directory', tone: 'warn' }] }];
375
- if (files.length === 0)
376
- return [{ cells: [{ label: 'No knowledge docs found', tone: 'muted' }] }];
377
- return [
378
- { cells: [
379
- { label: '📄 RAG sync candidates: ', tone: 'heading' },
380
- { field: 'files.length', text: String(files.length), tone: 'heading' },
381
- { label: ' files in ', tone: 'heading' },
382
- { field: 'directory', text: docsDir, tone: 'heading' },
383
- ] },
384
- (0, knowledge_view_1.blankLine)(),
385
- ...files.map((file, i) => ({ cells: [{ field: `files.${i}`, text: ` ${file}`, tone: 'accent' }] })),
386
- (0, knowledge_view_1.blankLine)(),
387
- { cells: [{ label: 'Ingest each file into your own knowledge-base backend to sync to RAG', tone: 'muted' }] },
388
- ];
389
- }
390
- async function knowledgeSyncRag(options, io = command_contract_1.processIO) {
391
- return (0, knowledge_view_1.emitKnowledgeView)(io, options, knowledgeSyncRagView(options));
392
- }
393
- /**
394
- * `--threshold` 的装配点窄化(harness#152):非负整数字符串 → 数值,转不出来即脏输入。
395
- * `undefined` = 未传,落引擎缺省(50);`'0'` 是显式零值,不当「未传」兜掉。
396
- * 判定规则正本是 `parseNumericFlag`(harness#154 统一解析器),此处保留 #152 的
397
- * 函数面与报错文案(冻结测试钉死),只做委派。
398
- */
399
- function assembleShortContentThreshold(raw) {
400
- return (0, numeric_flag_1.parseNumericFlag)(raw, 'int');
401
- }
402
- function knowledgeAuditView(options, io) {
403
- const audit = new audit_1.KnowledgeAudit((0, knowledge_view_1.openKnowledgeStore)(options, io), {
404
- shortContentThreshold: options.threshold,
405
- });
406
- const isDryRun = options.dryRun && !options.fix;
407
- if (!isDryRun)
408
- (0, knowledge_view_1.announce)(io, options.json, '🔍 知识库质量审计...\n');
409
- const report = audit.run({ autoFix: options.fix && !isDryRun });
410
- const showFixHint = !options.fix && report.issues.length > 0;
411
- return {
412
- data: report,
413
- human: () => ({ sections: auditSections(report, showFixHint) }),
414
- };
415
- }
416
- function auditSections(report, showFixHint) {
417
- const sections = [{
418
- rows: [
419
- { cells: [{ label: ' 总条目: ', tone: 'emph' }, { field: 'totalEntries', text: String(report.totalEntries), tone: 'emph' }] },
420
- { cells: [{ label: ' 健康分: ', tone: 'emph' }, { field: 'healthScore.before', text: `${report.healthScore.before}/100`, tone: 'emph' }] },
421
- ],
422
- }];
423
- if (report.autoFixed > 0) {
424
- sections[0].rows.push({ cells: [{ label: ' 自动修复: ', tone: 'ok' }, { field: 'autoFixed', text: String(report.autoFixed), tone: 'ok' }] }, { cells: [{ label: ' 修复后: ', tone: 'emph' }, { field: 'healthScore.after', text: `${report.healthScore.after}/100`, tone: 'emph' }] });
425
- }
426
- sections[0].rows.push((0, knowledge_view_1.blankLine)());
427
- const dimensions = [];
428
- for (const [key, dim] of Object.entries(report.dimensions)) {
429
- dimensions.push({ cells: [
430
- { field: `dimensions.${key}`, text: ` ${(0, knowledge_view_1.dimensionLabel)(key)}: ` },
431
- { field: `dimensions.${key}.score`, text: `${dim.score}/100`, tone: (0, knowledge_view_1.toneForScore)(dim.score) },
432
- { field: `dimensions.${key}.issues`, text: ` (${dim.issues} 问题)` },
433
- ] });
434
- }
435
- dimensions.push((0, knowledge_view_1.blankLine)());
436
- sections.push({ title: ' 维度评分:', rows: dimensions });
437
- // 规则 label 正本在 audit.ts 的规则定义上(#109 编译期闭环经 ruleLabel 转发)
438
- const rules = [];
439
- for (const [rule, count] of Object.entries(report.summary)) {
440
- if (count === 0)
441
- continue;
442
- rules.push({ cells: [{ field: `summary.${rule}`, text: ` ${(0, knowledge_view_1.ruleLabel)(rule)}: ${count}`, tone: 'error' }] });
443
- }
444
- if (report.issues.length > 0) {
445
- rules.push((0, knowledge_view_1.blankLine)()); // 「问题详情」标题前的空行(原排版是 `\n` 前缀)
446
- }
447
- sections.push({ rows: rules });
448
- if (report.issues.length > 0) {
449
- const issues = [(0, knowledge_view_1.blankLine)()];
450
- for (const [i, issue] of report.issues.slice(0, 20).entries()) {
451
- issues.push({ cells: [
452
- { field: `issues.${i}.severity`, text: ` [${issue.severity}]`, tone: (0, knowledge_view_1.toneForSeverity)(issue.severity) },
453
- { field: `issues.${i}.entryId`, text: ` ${issue.entryId}: ` },
454
- { field: `issues.${i}.title`, text: issue.title },
455
- ] });
456
- issues.push({ cells: [
457
- { field: `issues.${i}.detail`, text: ` ${issue.detail}`, tone: 'muted' },
458
- { label: ' → ' },
459
- { field: `issues.${i}.action`, text: issue.action },
460
- ] });
461
- }
462
- if (report.issues.length > 20) {
463
- issues.push((0, knowledge_view_1.blankLine)(), { cells: [
464
- { label: ' ... 还有 ', tone: 'muted' },
465
- { field: 'issues.length', text: String(report.issues.length - 20), tone: 'muted' },
466
- { label: ' 条', tone: 'muted' },
467
- ] });
468
- }
469
- sections.push({ title: ' 问题详情 (前 20 条):', rows: issues });
470
- }
471
- if (showFixHint) {
472
- sections.push({ rows: [(0, knowledge_view_1.blankLine)(), { cells: [{ label: ' 使用 --fix 自动修复', tone: 'warn' }] }] });
473
- }
474
- return sections;
475
- }
476
- async function knowledgeAudit(options, io = command_contract_1.processIO) {
477
- const threshold = assembleShortContentThreshold(options.threshold);
478
- if (!threshold.ok) {
479
- (0, command_contract_1.logError)(io, `错误:--threshold 需要非负整数阈值(字符数),收到 "${threshold.raw}";短内容判定未执行`);
480
- return { kind: 'usage-error', reason: `knowledge audit --threshold 非法阈值: "${threshold.raw}"` };
481
- }
482
- const result = (0, knowledge_view_1.emitKnowledgeView)(io, options, knowledgeAuditView({ ...options, threshold: threshold.value }, io));
483
- // 审计可能改文件,人读路径收尾重建索引;--json 保持不写盘(现状冻结,#133 不动这条策略)
484
- if (!options.json) {
485
- new index_generator_1.KnowledgeIndexGenerator((0, knowledge_view_1.resolveKnowledgeBaseDir)(options, io)).regenerate();
486
- (0, knowledge_view_1.announce)(io, options.json, ' 📇 索引已重建', 'muted');
487
- }
488
- return result;
489
- }
490
- // ========================================
491
- // snapshot(KR4 存活率追踪)
492
- // ========================================
493
- function knowledgeSnapshotView(options, io) {
494
- const snapshotPath = (0, knowledge_view_1.openKnowledgeStore)(options, io).snapshot();
495
- const data = { snapshotPath };
496
- return {
497
- data,
498
- human: () => ({
499
- sections: [{
500
- rows: [{
501
- cells: [
502
- { label: '✅ 快照已保存: ', tone: 'ok' },
503
- { field: 'snapshotPath', text: snapshotPath, tone: 'ok' },
504
- ],
505
- }],
506
- }],
507
- }),
508
- };
509
- }
510
- function knowledgeSnapshot(options, io = command_contract_1.processIO) {
511
- return (0, knowledge_view_1.emitKnowledgeView)(io, options, knowledgeSnapshotView(options, io));
512
- }
513
- function knowledgeMigrateView(options, io) {
514
- const result = (0, migration_1.migrateKnowledgeEntries)((0, knowledge_view_1.resolveKnowledgeBaseDir)(options, io));
515
- return {
516
- data: result,
517
- human: () => ({ sections: [{ rows: migrateRows(result) }] }),
518
- };
519
- }
520
- function migrateRows(result) {
521
- const rows = [
522
- { cells: [{ label: '🔄 迁移知识条目(添加 consumptionMode/origin 字段)', tone: 'heading' }] },
523
- (0, knowledge_view_1.blankLine)(),
524
- { cells: [{ label: ' 总计: ', tone: 'ok' }, { field: 'total', text: String(result.total), tone: 'ok' }, { label: ' 条', tone: 'ok' }] },
525
- { cells: [{ label: ' 已迁移: ', tone: 'ok' }, { field: 'migrated', text: String(result.migrated), tone: 'ok' }, { label: ' 条', tone: 'ok' }] },
526
- { cells: [{ label: ' 已跳过: ', tone: 'muted' }, { field: 'skipped', text: String(result.skipped), tone: 'muted' }, { label: ' 条', tone: 'muted' }] },
527
- ];
528
- if (result.errors.length > 0) {
529
- rows.push((0, knowledge_view_1.blankLine)(), { cells: [{ label: ' 错误: ', tone: 'error' }, { field: 'errors.length', text: String(result.errors.length), tone: 'error' }, { label: ' 条', tone: 'error' }] });
530
- result.errors.slice(0, 5).forEach((err, i) => {
531
- rows.push({ cells: [{ label: ' ' }, { field: `errors.${i}`, text: err, tone: 'error' }] });
532
- });
533
- }
534
- // 两种收尾语各自带一个前导空行;migrated=0 且有错误时历史上两句都不打
535
- if (result.migrated === 0 && result.errors.length === 0) {
536
- rows.push((0, knowledge_view_1.blankLine)(), { cells: [{ label: '✅ 所有条目已是最新,无需迁移', tone: 'ok' }] });
537
- }
538
- else if (result.migrated > 0) {
539
- rows.push((0, knowledge_view_1.blankLine)(), { cells: [{ label: '✅ 迁移完成', tone: 'ok' }] });
540
- }
541
- return rows;
542
- }
543
- function knowledgeMigrate(options, io = command_contract_1.processIO) {
544
- return (0, knowledge_view_1.emitKnowledgeView)(io, options, knowledgeMigrateView(options, io));
545
- }
546
- // ========================================
547
- // index(重建 _index.md 供 Agent grep,并同步 index.json)
548
- // ========================================
549
- function knowledgeIndexView(options, io) {
550
- const baseDir = (0, knowledge_view_1.resolveKnowledgeBaseDir)(options, io);
551
- const indexPath = path.join(baseDir, '_index.md');
552
- const beforeSize = fs.existsSync(indexPath) ? fs.statSync(indexPath).size : 0;
553
- const output = new index_generator_1.KnowledgeIndexGenerator(baseDir).regenerate();
554
- // Sync index.json from disk files (removes ghost entries from manual mv/rm)
555
- (0, knowledge_view_1.openKnowledgeStore)({ dir: baseDir }, io).rebuildIndex();
556
- const afterSize = Buffer.byteLength(output, 'utf-8');
557
- const lineCount = output.split('\n').filter(l => !l.startsWith('#')).length;
558
- const data = { path: indexPath, entries: lineCount, size: afterSize, previousSize: beforeSize };
559
- return {
560
- data,
561
- human: () => ({ sections: [{ rows: indexRows({ indexPath, afterSize, lineCount, beforeSize }) }] }),
562
- };
563
- }
564
- function indexRows(shape) {
565
- const rows = [
566
- { cells: [{ label: '📇 索引已重建', tone: 'heading' }] },
567
- { cells: [{ label: ' 路径: ', tone: 'muted' }, { field: 'path', text: shape.indexPath, tone: 'muted' }] },
568
- { cells: [{ label: ' 条目: ', tone: 'ok' }, { field: 'entries', text: String(shape.lineCount), tone: 'ok' }] },
569
- { cells: [{ label: ' 大小: ', tone: 'ok' }, { field: 'size', text: `${(shape.afterSize / 1024).toFixed(1)} KB`, tone: 'ok' }] },
570
- ];
571
- if (shape.beforeSize > 0) {
572
- rows.push({ cells: [{ label: ' 旧大小: ', tone: 'muted' }, { field: 'previousSize', text: `${(shape.beforeSize / 1024).toFixed(1)} KB`, tone: 'muted' }] });
573
- }
574
- return rows;
575
- }
576
- function knowledgeIndex(options, io = command_contract_1.processIO) {
577
- return (0, knowledge_view_1.emitKnowledgeView)(io, options, knowledgeIndexView(options, io));
578
- }
579
- function knowledgeHealthView(options, io) {
580
- const store = (0, knowledge_view_1.openKnowledgeStore)(options, io);
581
- const baseDir = store.getBaseDir();
582
- const entries = store.list({ excludeArchived: true });
583
- const issues = [];
584
- // D1: 引用密度检查(低引用 = 可能孤立)
585
- let lowRefEntries = 0;
586
- for (const entry of entries) {
587
- if (entry.referencedBy.length === 0 && entry.maturity === 'verified') {
588
- lowRefEntries++;
589
- issues.push({ severity: 'info', entry: entry.id, detail: `verified 条目零引用(可能孤立)` });
590
- }
591
- }
592
- // D2: 新鲜度检查
593
- const now = Date.now();
594
- const staleThreshold = 90 * 24 * 60 * 60 * 1000; // 90 days
595
- let staleEntries = 0;
596
- for (const entry of entries) {
597
- const created = new Date(entry.created).getTime();
598
- if (now - created > staleThreshold && entry.maturity === 'draft') {
599
- staleEntries++;
600
- issues.push({ severity: 'warn', entry: entry.id, detail: `draft 超过 90 天未推进` });
601
- }
602
- }
603
- // D3: 消费数据检查
604
- const statsPath = path.join(baseDir, '.consumption-stats.json');
605
- const consumptionData = fs.existsSync(statsPath);
606
- if (!consumptionData) {
607
- issues.push({ severity: 'info', entry: '-', detail: `消费追踪数据不存在(${statsPath})` });
608
- }
609
- // D4: 飞轮指标(计算唯一实现在 knowledge/flywheel-metrics;人口为本命令的 excludeArchived 切片)
610
- const metrics = (0, flywheel_metrics_1.evaluateFlywheel)({ entries });
611
- const refCoverage = Math.round(metrics.refCoverage * 100);
612
- const avgRefs = Math.round(metrics.avgRefs * 10) / 10;
613
- const totalIssues = issues.filter(i => i.severity === 'error').length * 3
614
- + issues.filter(i => i.severity === 'warn').length * 1;
615
- const healthScore = Math.max(0, 100 - totalIssues);
616
- const data = {
617
- healthScore,
618
- summary: { total: entries.length, lowRefEntries, staleEntries, consumptionData, refCoverage, avgRefs },
619
- issues: issues.slice(0, 50),
620
- };
621
- return { data, human: () => ({ sections: healthSections(data) }) };
622
- }
623
- function healthSections(data) {
624
- const { healthScore, summary, issues } = data;
625
- const scoreTone = (0, knowledge_view_1.toneForScore)(healthScore);
626
- return [
627
- {
628
- rows: [
629
- { cells: [{ label: '🏥 飞轮健康检查', tone: 'heading' }] },
630
- (0, knowledge_view_1.blankLine)(),
631
- { cells: [
632
- { label: ' 健康分: ', tone: 'emph' },
633
- { field: 'healthScore', text: String(healthScore), tone: scoreTone },
634
- { label: '/100', tone: 'emph' },
635
- ] },
636
- { cells: [
637
- { label: ' 活跃条目: ', tone: 'emph' },
638
- { field: 'summary.total', text: String(summary.total), tone: 'emph' },
639
- ] },
640
- (0, knowledge_view_1.blankLine)(),
641
- ],
642
- },
643
- {
644
- title: ' 数据流状态:',
645
- rows: [
646
- densityRow(' 引用密度: ', 'summary.lowRefEntries', summary.lowRefEntries, ' 个零引用 verified'),
647
- densityRow(' 新鲜度: ', 'summary.staleEntries', summary.staleEntries, ' 个过期 draft'),
648
- { cells: [
649
- { label: ' 消费追踪: ' },
650
- summary.consumptionData
651
- ? { label: '✓', tone: 'ok' }
652
- : { field: 'summary.consumptionData', text: '○ 未启用', tone: 'muted' },
653
- ] },
654
- (0, knowledge_view_1.blankLine)(),
655
- ],
656
- },
657
- {
658
- title: ' 飞轮指标:',
659
- rows: [
660
- { cells: [{ label: ' 引用覆盖: ' }, { field: 'summary.refCoverage', text: `${summary.refCoverage}%` }] },
661
- { cells: [{ label: ' 平均引用: ' }, { field: 'summary.avgRefs', text: String(summary.avgRefs) }] },
662
- (0, knowledge_view_1.blankLine)(),
663
- ],
664
- },
665
- {
666
- title: ' 问题 (前 20):',
667
- rows: issues.length === 0
668
- ? [{ cells: [{ label: ' ✓ 无问题', tone: 'ok' }] }]
669
- : [
670
- ...issues.slice(0, 20).map((issue, i) => ({
671
- cells: [
672
- { field: `issues.${i}.severity`, text: ` [${issue.severity}]`, tone: (0, knowledge_view_1.toneForSeverity)(issue.severity) },
673
- { field: `issues.${i}.entry`, text: ` ${issue.entry}: ` },
674
- { field: `issues.${i}.detail`, text: issue.detail },
675
- ],
676
- })),
677
- // 溢出计数取全量数组,而 json 面的 issues 已截 50 条 → 无字段可锚,登记派生量
678
- ...(issues.length > 20
679
- ? [{ cells: [{ derived: 'healthIssuesOverflow', text: ` ... 还有 ${issues.length - 20} 条`, tone: 'muted' }] }]
680
- : []),
681
- ],
682
- },
683
- ];
684
- }
685
- function densityRow(prefix, field, count, suffix) {
686
- if (count === 0)
687
- return { cells: [{ label: prefix }, { label: '✓', tone: 'ok' }] };
688
- return {
689
- cells: [
690
- { label: prefix },
691
- { label: '⚠ ', tone: 'warn' },
692
- { field, text: String(count), tone: 'warn' },
693
- { label: suffix, tone: 'warn' },
694
- ],
695
- };
696
- }
697
- async function knowledgeHealth(options, io = command_contract_1.processIO) {
698
- return (0, knowledge_view_1.emitKnowledgeView)(io, options, knowledgeHealthView(options, io));
699
- }
700
- //# sourceMappingURL=knowledge.js.map