@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,590 +0,0 @@
1
- /**
2
- * harness init 命令
3
- *
4
- * 初始化项目的 harness 配置
5
- */
6
-
7
- import chalk from 'chalk';
8
- import * as fs from 'fs/promises';
9
- import * as path from 'path';
10
- import * as yaml from 'js-yaml';
11
- import { detectSourceRoots } from '../../utils/detect-source-roots';
12
- import { getHarnessPackageVersion } from '../../utils/package-version';
13
- import { loadRawProjectConfig } from '../../core/project-config-loader';
14
- import type { CiConfig, CiPlatform, GovernanceConfig } from '../../types/project-config';
15
- import { replaceStandaloneRange } from '../../core/constraints/injection-writer';
16
- import { log, logError, processIO, type CommandIO, type CommandResult } from '../command-contract';
17
- import {
18
- runPlan,
19
- nodeScaffoldFs,
20
- preCommitHookFile,
21
- prePushHookFile,
22
- harnessCheckCiFile,
23
- changelogFile,
24
- contextDocFile,
25
- governanceWorkflowFile,
26
- checkpointsFile,
27
- resolutionsFile,
28
- type ManagedFile,
29
- } from './scaffold';
30
- import {
31
- GITHUB_ACTIONS_SNIPPET,
32
- renderGitLabCiJobs,
33
- PRE_COMMIT_SNIPPET,
34
- PRE_PUSH_SNIPPET,
35
- OUTPUT_STYLE_START,
36
- OUTPUT_STYLE_END,
37
- renderOutputStyleSection,
38
- } from './scaffold-templates';
39
-
40
- export interface InitOptions {
41
- /** 项目路径 */
42
- projectPath?: string;
43
- /** 预设名称 */
44
- preset: 'strict' | 'standard' | 'relaxed';
45
- /** 治理级别(值域 = `GOVERNANCE_PRESETS` 键集合,非法值在命令入口判 usage-error、零落盘,harness#156) */
46
- governance?: 'minimal' | 'standard' | 'strict';
47
- /** 是否创建 Git hooks */
48
- gitHooks?: boolean;
49
- /** 是否创建 GitHub Actions(`--no-github-actions`:已废弃,`--ci none` 的别名) */
50
- githubActions?: boolean;
51
- /**
52
- * 服务端 CI 接线平台(`--ci`,harness#143)
53
- *
54
- * 值域校验在命令层(bin 把用户敲的字符串原样递进来);缺省时回落 config.yml
55
- * 的 `ci.platform`,再缺省即 `github`。
56
- */
57
- ci?: CiPlatform | 'none';
58
- /** 只输出代码片段,不创建文件 */
59
- printSnippets?: boolean;
60
- }
61
-
62
- /** `--ci` 的可取值域(`none` = 不创建任何服务端 CI 文件,治理 CI 面亦不建,即旧 `--no-github-actions`) */
63
- const CI_FLAG_VALUES: Array<CiPlatform | 'none'> = ['github', 'gitlab', 'none'];
64
-
65
- /** CI 平台解析结果(`error` 属用法错误,命令层直接非零退出,不落任何文件) */
66
- type CiResolution =
67
- | { kind: 'ok'; platform: CiPlatform | 'none'; warning?: string }
68
- | { kind: 'error'; reason: string };
69
-
70
- /**
71
- * 解析 CI 平台(harness#143 决议 ①④):flag > config.yml 的 `ci.platform` > `github`
72
- *
73
- * 不做 remote URL 自动检测:init 常跑在首次 push 之前无 remote 可测,而检测错的代价是
74
- * 静默写错文件。`--no-github-actions` 保留为 `--ci none` 的废弃别名;它与显式
75
- * `--ci <非 none>` 同时出现时不猜用户意图,判用法错误。
76
- */
77
- function resolveCiPlatform(
78
- options: InitOptions,
79
- configured: CiPlatform | 'none' | undefined,
80
- ): CiResolution {
81
- const flag = options.ci;
82
- if (flag !== undefined && !CI_FLAG_VALUES.includes(flag)) {
83
- return {
84
- kind: 'error',
85
- reason: `--ci 取值非法: ${String(flag)}(可取 ${CI_FLAG_VALUES.join(' | ')})`,
86
- };
87
- }
88
- if (options.githubActions === false) {
89
- if (flag !== undefined && flag !== 'none') {
90
- return {
91
- kind: 'error',
92
- reason: `--ci ${flag} 与 --no-github-actions(即 --ci none 的废弃别名)冲突,二选一`,
93
- };
94
- }
95
- return {
96
- kind: 'ok',
97
- platform: 'none',
98
- warning: '⚠️ --no-github-actions 已废弃,请改用 --ci none',
99
- };
100
- }
101
- return { kind: 'ok', platform: flag ?? configured ?? 'github' };
102
- }
103
-
104
- /**
105
- * 读 config.yml 已持久化的 `ci.platform`(解析链第二级)
106
- *
107
- * 缺失 / 解析失败 / 形状不符一律按未配置处理(与 `getGovernanceConfig` 同一口径:
108
- * 脏配置不替调用方做决定)。
109
- */
110
- function readConfiguredCiPlatform(projectPath: string): CiPlatform | 'none' | undefined {
111
- let raw: Record<string, unknown> | undefined;
112
- try {
113
- raw = loadRawProjectConfig(projectPath);
114
- } catch {
115
- return undefined;
116
- }
117
- const ci = raw?.ci;
118
- if (ci === null || typeof ci !== 'object') return undefined;
119
- const platform = (ci as CiConfig).platform;
120
- return platform !== undefined && CI_FLAG_VALUES.includes(platform) ? platform : undefined;
121
- }
122
-
123
- /**
124
- * 默认配置
125
- *
126
- * 只写有运行时消费者的字段:preset(ADR-0001 生效集链路由 mergeConstraints 消费)。
127
- * 历史模板里的 enabled / ironLaws.enforceErrors / ironLaws.warnWarnings /
128
- * validators.{checkpoint,passesGate,cso} 均为零消费者的死字段,不再写入;
129
- * strict/standard/relaxed 三档差异曾只存在于这些死字段上(实为两档),
130
- * 现在三档差异完全由 preset 键经生效集链路体现。
131
- */
132
- const DEFAULT_CONFIG = {
133
- preset: 'standard',
134
- };
135
-
136
- /**
137
- * 预设配置
138
- */
139
- const PRESETS = {
140
- strict: {
141
- ...DEFAULT_CONFIG,
142
- preset: 'strict',
143
- },
144
- standard: {
145
- ...DEFAULT_CONFIG,
146
- preset: 'standard',
147
- },
148
- relaxed: {
149
- ...DEFAULT_CONFIG,
150
- preset: 'relaxed',
151
- },
152
- };
153
-
154
- /**
155
- * 治理预设(形状 = 写入 config.yml 的 governance 段,直接用类型正本)
156
- */
157
- const GOVERNANCE_PRESETS: Record<string, GovernanceConfig> = {
158
- minimal: {
159
- level: 'minimal',
160
- docs: {
161
- sync_command: 'harness sync-docs',
162
- check_on_ci: false,
163
- files: ['CAPABILITIES.md'],
164
- },
165
- context_files: {
166
- enabled: false,
167
- required_dirs: [],
168
- },
169
- changelog: {
170
- format: 'keep-a-changelog',
171
- },
172
- testing: {
173
- test_first: true,
174
- coverage_threshold: 85,
175
- incremental_coverage: false,
176
- },
177
- },
178
- standard: {
179
- level: 'standard',
180
- docs: {
181
- sync_command: 'harness sync-docs',
182
- check_on_ci: true,
183
- files: ['CAPABILITIES.md', 'README.md'],
184
- },
185
- context_files: {
186
- enabled: true,
187
- required_dirs: [],
188
- },
189
- changelog: {
190
- format: 'keep-a-changelog',
191
- },
192
- testing: {
193
- test_first: true,
194
- coverage_threshold: 85,
195
- incremental_coverage: false,
196
- },
197
- },
198
- strict: {
199
- level: 'strict',
200
- docs: {
201
- sync_command: 'harness sync-docs',
202
- check_on_ci: true,
203
- files: ['CAPABILITIES.md', 'README.md', 'CHANGELOG.md'],
204
- },
205
- context_files: {
206
- enabled: true,
207
- required_dirs: [],
208
- },
209
- changelog: {
210
- format: 'keep-a-changelog',
211
- },
212
- testing: {
213
- test_first: true,
214
- coverage_threshold: 85,
215
- incremental_coverage: true,
216
- },
217
- },
218
- };
219
-
220
- /**
221
- * 初始化项目
222
- */
223
- export async function init(options: InitOptions, io: CommandIO = processIO): Promise<CommandResult> {
224
- const projectPath = options.projectPath || process.cwd();
225
-
226
- // CI 平台先解析:用法错误不落任何盘,且 `--print-snippets` 也要按解析出的平台出形
227
- const ci = resolveCiPlatform(options, readConfiguredCiPlatform(projectPath));
228
- if (ci.kind === 'error') {
229
- logError(io, chalk.red(`❌ 用法错误: ${ci.reason}`));
230
- return { kind: 'usage-error', reason: ci.reason };
231
- }
232
- if (ci.warning) log(io, chalk.yellow(ci.warning));
233
-
234
- // `-g` 值域校验在命令入口(harness#156 裁决 F2,与 #152 脏输入 fail-loud 同判据):
235
- // 非法值 usage-error、先于任何落盘;合法值域与装配共用同一份 GOVERNANCE_PRESETS 表,
236
- // github / gitlab / none 三平台同判(bin 把用户敲的字符串原样递进来)。
237
- // 用 Object.hasOwn 而非 `in`(harness#164):`in` 走原型链,`-g constructor`/`toString`
238
- // 会穿透校验、把 Object 构造函数写进 configData 并在 yaml.dump 炸成 YAMLException。
239
- if (options.governance !== undefined && !Object.hasOwn(GOVERNANCE_PRESETS, options.governance)) {
240
- const reason = `-g/--governance 取值非法: ${String(options.governance)}(可取 ${Object.keys(GOVERNANCE_PRESETS).join(' | ')})`;
241
- logError(io, chalk.red(`❌ 用法错误: ${reason}`));
242
- return { kind: 'usage-error', reason };
243
- }
244
-
245
- // 只输出代码片段
246
- if (options.printSnippets) {
247
- printSnippets(io, ci.platform, options.governance);
248
- return { kind: 'ok' };
249
- }
250
-
251
- log(io, chalk.blue('🚀 初始化 harness 配置...'));
252
-
253
- const configDir = path.join(projectPath, '.harness');
254
-
255
- // 创建配置目录
256
- await fs.mkdir(configDir, { recursive: true });
257
- log(io, chalk.gray(`配置目录: ${configDir}`));
258
-
259
- // 选择预设
260
- const preset = PRESETS[options.preset];
261
- log(io, chalk.gray(`预设: ${options.preset}`));
262
-
263
- // 合并治理配置
264
- const configData: Record<string, unknown> = { ...preset };
265
- if (options.governance) {
266
- configData.governance = GOVERNANCE_PRESETS[options.governance];
267
- log(io, chalk.gray(`治理级别: ${options.governance}`));
268
- }
269
-
270
- // 非默认平台才持久化:缺省即 github(旧配置零迁移),裸 init 重写 config.yml 时
271
- // 也因此不会丢掉已选定的平台
272
- if (ci.platform !== 'github') {
273
- configData.ci = { platform: ci.platform };
274
- log(io, chalk.gray(`CI 平台: ${ci.platform}`));
275
- }
276
-
277
- // 写入 harness 版本
278
- const pkgVersion = getHarnessPackageVersion();
279
- configData.harness = { version: pkgVersion };
280
-
281
- // 写入配置文件(harness 管理的配置,始终重新生成)
282
- const configPath = path.join(configDir, 'config.yml');
283
- const configContent = yaml.dump(configData, { indent: 2 });
284
- await fs.writeFile(configPath, configContent, 'utf-8');
285
- log(io, chalk.green(`✅ 已创建配置文件: ${configPath} (v${pkgVersion})`));
286
-
287
- // 受管示例文件:检查点 / Resolutions(RKB 狗粮)
288
- await runPlan(
289
- [checkpointsFile(projectPath), resolutionsFile(projectPath)],
290
- io,
291
- );
292
-
293
- // CAPABILITIES.md / CHANGELOG.md 由 sync-docs(AI 治理)管理,init 不创建
294
-
295
- // 创建 Git hooks
296
- if (options.gitHooks !== false) {
297
- await setupGitHooks(projectPath, io);
298
- }
299
-
300
- // 服务端 CI 门禁接线(平台维度):`none` = CI 站点干脆不进 plan
301
- if (ci.platform !== 'none') {
302
- await setupCiWiring(projectPath, ci.platform, options.governance, io);
303
- }
304
-
305
- // 治理相关文件生成
306
- if (options.governance) {
307
- await setupGovernance(projectPath, options.governance, io, ci.platform);
308
- }
309
-
310
- log(io);
311
- log(io, chalk.green('✅ harness 初始化完成!'));
312
- log(io);
313
- log(io, chalk.gray('下一步:'));
314
- log(io, chalk.gray(' 1. 编辑 .harness/config.yml 自定义配置'));
315
- log(io, chalk.gray(' 2. 正常开发:每次 git commit 查暂存的(增量快反馈),每次 git push 查整仓的(全量兜底)——重复是设计使然'));
316
- log(io, chalk.gray(' 3. 运行 harness status 查看状态'));
317
- log(io);
318
- log(io, chalk.blue('💡 提示: 使用 harness init --print-snippets 查看配置代码片段'));
319
- return { kind: 'ok' };
320
- }
321
-
322
- /**
323
- * 输出代码片段(CI 片段按解析出的平台出形,harness#143)
324
- *
325
- * gitlab 形打 `renderGitLabCiJobs(governanceLevel)`——与落盘 / 冲突分支同一个函数
326
- * 的正本(harness#157:曾打无 level 的 GITLAB_CI_SNIPPET,`-g` 档照抄的用户少拿
327
- * 治理与 docs 新鲜度两个任务)。
328
- */
329
- function printSnippets(
330
- io: CommandIO,
331
- platform: CiPlatform | 'none',
332
- governanceLevel: string | undefined,
333
- ): void {
334
- log(io, chalk.blue('📄 Harness 配置代码片段'));
335
- log(io);
336
-
337
- log(io, chalk.yellow('Git pre-commit hook:'));
338
- log(io, chalk.gray('添加到 .git/hooks/pre-commit'));
339
- log(io);
340
- log(io, chalk.cyan(PRE_COMMIT_SNIPPET));
341
-
342
- log(io, chalk.yellow('Git pre-push hook:'));
343
- log(io, chalk.gray('添加到 .git/hooks/pre-push(pre-commit 查暂存的、快反馈,这道查整仓的、全量兜底——重复是设计使然)'));
344
- log(io);
345
- log(io, chalk.cyan(PRE_PUSH_SNIPPET));
346
-
347
- if (platform === 'gitlab') {
348
- log(io, chalk.yellow('GitLab CI:'));
349
- log(io, chalk.gray('添加到 .gitlab-ci.yml'));
350
- log(io);
351
- log(io, chalk.cyan(renderGitLabCiJobs(governanceLevel)));
352
- } else {
353
- log(io, chalk.yellow('GitHub Actions:'));
354
- log(io, chalk.gray('添加到 .github/workflows/*.yml 的 jobs 下(以下正文取自 harness-check.yml 的 job 段)'));
355
- log(io);
356
- log(io, chalk.cyan(GITHUB_ACTIONS_SNIPPET));
357
- }
358
-
359
- log(io, chalk.blue('💡 提示: 运行 npx @dommaker/harness init 自动创建配置文件'));
360
- }
361
-
362
- /**
363
- * 设置 Git hooks(无 .git 即整站跳过;落盘语义在 scaffold plan)
364
- *
365
- * 两道:pre-commit 查暂存的(增量、快反馈),pre-push 查整仓的(全量、兜底,
366
- * harness#144)。跳过旗帜 `--no-git-hooks` 在命令层翻成「本站点不进 plan」。
367
- */
368
- async function setupGitHooks(projectPath: string, io: CommandIO): Promise<void> {
369
- if (!(await nodeScaffoldFs.exists(path.join(projectPath, '.git')))) {
370
- log(io, chalk.yellow('⚠️ 未检测到 Git 仓库,跳过 Git hooks'));
371
- log(io, chalk.gray('💡 初始化 Git 后可运行 npx @dommaker/harness init --print-snippets 查看配置'));
372
- return;
373
- }
374
- await runPlan([preCommitHookFile(projectPath), prePushHookFile(projectPath)], io);
375
- }
376
-
377
- /**
378
- * 设置服务端 CI 接线(站点形状与冲突面由 scaffold 按平台给)
379
- *
380
- * gitlab 只有一个 `.gitlab-ci.yml`,治理任务已在正文里(`governanceLevel` 传给工厂);
381
- * github 的冲突判定宽到整个 workflows 目录,需先扫一遍。
382
- */
383
- async function setupCiWiring(
384
- projectPath: string,
385
- platform: CiPlatform,
386
- governanceLevel: string | undefined,
387
- io: CommandIO,
388
- ): Promise<void> {
389
- if (platform === 'gitlab') {
390
- await runPlan([harnessCheckCiFile(projectPath, 'gitlab', [], governanceLevel)], io);
391
- return;
392
- }
393
- const workflowsDir = path.join(projectPath, '.github', 'workflows');
394
- await runPlan(
395
- [harnessCheckCiFile(projectPath, 'github', await findCiWorkflows(workflowsDir))],
396
- io,
397
- );
398
- }
399
-
400
- /**
401
- * 查找已存在的 CI 工作流文件
402
- */
403
- async function findCiWorkflows(workflowsDir: string): Promise<string[]> {
404
- try {
405
- await fs.access(workflowsDir);
406
- const files = await fs.readdir(workflowsDir);
407
- // 过滤出可能是 CI 配置的文件
408
- return files.filter(f =>
409
- f.endsWith('.yml') || f.endsWith('.yaml')
410
- );
411
- } catch {
412
- return [];
413
- }
414
- }
415
-
416
- /**
417
- * Output Style 段标记与正文正本在 `scaffold-templates.ts`
418
- *(ADR-0001:init 只写标记区间内,标记外只读)
419
- */
420
-
421
- /** 旧版 harness 无标记 Output Style 段的特征串(用于区分 harness 写入 vs 用户自写) */
422
- const LEGACY_OUTPUT_STYLE_FINGERPRINT = 'Terse like caveman';
423
-
424
- /**
425
- * 在 CLAUDE.md 顶部写入 Output Style 段(标记化、幂等)
426
- *
427
- * - 已有 HARNESS_OUTPUT_STYLE 标记:替换标记间内容
428
- * - 无标记但存在旧版 harness 写入的无标记段(特征串匹配):原位置换为标记版
429
- * - 无标记且 `## Output Style` 段为用户自写(特征串不匹配):跳过并提示,不重复追加
430
- * - 完全没有该段:在文件顶部插入标记版
431
- */
432
- export async function setupClaudeMdOutputStyle(projectPath: string, io: CommandIO): Promise<void> {
433
- const claudeMdPath = path.join(projectPath, 'CLAUDE.md');
434
- let content: string;
435
- try {
436
- content = await fs.readFile(claudeMdPath, 'utf-8');
437
- } catch {
438
- // CLAUDE.md 不存在——无人持有该文件,跳过 Output Style 段
439
- return;
440
- }
441
-
442
- const section = renderOutputStyleSection();
443
- const write = replaceStandaloneRange(content, OUTPUT_STYLE_START, OUTPUT_STYLE_END, section);
444
-
445
- if (write.kind === 'updated') {
446
- // 尾部换行规范化在 writer 内(幂等)。
447
- if (write.content !== content) {
448
- await fs.writeFile(claudeMdPath, write.content, 'utf-8');
449
- log(io, chalk.green('✅ 已更新 CLAUDE.md Output Style 段'));
450
- }
451
- return;
452
- }
453
- if (write.kind === 'half') {
454
- log(io, chalk.yellow('⚠️ CLAUDE.md 中 HARNESS_OUTPUT_STYLE 标记残缺(单边或乱序),跳过 Output Style 注入,请人工修复'));
455
- return;
456
- }
457
-
458
- // 检测旧版无标记 `## Output Style` 段
459
- const legacyMatch = /^## Output Style[ \t]*$/m.exec(content);
460
- if (legacyMatch) {
461
- const sectionStart = legacyMatch.index;
462
- const afterHeading = sectionStart + legacyMatch[0].length;
463
- const nextHeadingOffset = content.slice(afterHeading).search(/^#{1,6} /m);
464
- const sectionEnd = nextHeadingOffset === -1 ? content.length : afterHeading + nextHeadingOffset;
465
- const legacySection = content.slice(sectionStart, sectionEnd);
466
-
467
- if (!legacySection.includes(LEGACY_OUTPUT_STYLE_FINGERPRINT)) {
468
- // 用户自写的同名 section:不动,也不追加(避免重复)
469
- log(io, chalk.yellow('⚠️ CLAUDE.md 已存在自定义 "## Output Style" 段,跳过 harness Output Style 注入'));
470
- return;
471
- }
472
-
473
- // 旧版 harness 写入:原位置换为标记版
474
- const before = content.slice(0, sectionStart);
475
- const after = content.slice(sectionEnd);
476
- const newContent = before + section + (after.length > 0 ? '\n' + after : '');
477
- await fs.writeFile(claudeMdPath, newContent, 'utf-8');
478
- log(io, chalk.green('✅ 已将 CLAUDE.md Output Style 段迁移为标记化管理'));
479
- return;
480
- }
481
-
482
- // 完全没有该段:插入文件顶部
483
- await fs.writeFile(claudeMdPath, section + '\n' + content, 'utf-8');
484
- log(io, chalk.green('✅ 已在 CLAUDE.md 顶部写入 Output Style 段'));
485
- }
486
-
487
- /**
488
- * 设置治理相关文件
489
- */
490
- async function setupGovernance(
491
- projectPath: string,
492
- level: string,
493
- io: CommandIO,
494
- platform: CiPlatform | 'none',
495
- ): Promise<void> {
496
- const governance = GOVERNANCE_PRESETS[level];
497
- if (!governance) return;
498
-
499
- log(io);
500
- log(io, chalk.blue('📋 设置治理文件...'));
501
-
502
- // 1. 生成 CHANGELOG.md
503
- await runPlan([changelogFile(projectPath, governance.changelog?.format || 'keep-a-changelog')], io);
504
-
505
- // 2. 在 CLAUDE.md 中写入 Output Style 段(仅在不存在时创建)
506
- await setupClaudeMdOutputStyle(projectPath, io);
507
-
508
- // 3. 生成 CONTEXT.md 文件(预设形状即 GovernanceConfig,无需再 cast)
509
- await runPlan(await contextDocPlan(projectPath, governance, io), io);
510
-
511
- // 4. 生成治理 CI 面(仅 github 形;gitlab 已并入 .gitlab-ci.yml 正文,none 不建,harness#156)
512
- await setupGovernanceWorkflow(projectPath, level, io, platform);
513
- }
514
-
515
- /**
516
- * 目录 CONTEXT.md 骨架的 plan:required_dirs 缺省时按源码根探测,
517
- * 探测出来的目录不在场就不进 plan(告知由本函数负责)
518
- */
519
- async function contextDocPlan(
520
- projectPath: string,
521
- governance: GovernanceConfig,
522
- io: CommandIO,
523
- ): Promise<ManagedFile[]> {
524
- const contextConfig = governance.context_files;
525
- if (!contextConfig?.enabled) return [];
526
-
527
- let requiredDirs = contextConfig.required_dirs ?? [];
528
- if (requiredDirs.length === 0) {
529
- requiredDirs = detectSourceRoots(projectPath);
530
- }
531
-
532
- const plan: ManagedFile[] = [];
533
- for (const dir of requiredDirs) {
534
- if (!(await nodeScaffoldFs.exists(path.join(projectPath, dir)))) {
535
- log(io, chalk.yellow(`⚠️ 目录 ${dir} 不存在,跳过 CONTEXT.md`));
536
- continue;
537
- }
538
- plan.push(contextDocFile(projectPath, dir));
539
- }
540
- return plan;
541
- }
542
-
543
- /**
544
- * 检测已有 workflow 是否已覆盖 harness 治理命令
545
- * (harness check / passes-gate / sync-docs --check,含 npx、scoped 包名等调用形式)
546
- */
547
- const GOVERNANCE_COMMAND_PATTERN = /\bharness\s+(?:check\b|passes-gate\b|sync-docs\b[^\n]*--check)/;
548
-
549
- async function findGovernanceCoverage(workflowsDir: string): Promise<string | undefined> {
550
- for (const file of await findCiWorkflows(workflowsDir)) {
551
- try {
552
- const content = await fs.readFile(path.join(workflowsDir, file), 'utf-8');
553
- if (GOVERNANCE_COMMAND_PATTERN.test(content)) {
554
- return file;
555
- }
556
- } catch {
557
- // 读取失败,忽略该文件
558
- }
559
- }
560
- return undefined;
561
- }
562
-
563
- /**
564
- * 设置治理 CI workflow(目标已在场,或已有 workflow 覆盖治理命令时不新建 CI 面)
565
- *
566
- * 仅 github 形有本站点:gitlab 的治理任务已并入 `.gitlab-ci.yml` 正文(一个平台一份
567
- * CI 文件,harness#143);`none` = 不创建任何 CI 文件,治理 CI 面随之不建
568
- * (harness#156 裁决 F1;治理文档面不受影响,见 setupGovernance 1–4)。
569
- */
570
- async function setupGovernanceWorkflow(
571
- projectPath: string,
572
- level: string,
573
- io: CommandIO,
574
- platform: CiPlatform | 'none',
575
- ): Promise<void> {
576
- if (platform !== 'github') return;
577
-
578
- const workflowsDir = path.join(projectPath, '.github', 'workflows');
579
- const file = governanceWorkflowFile(projectPath, level);
580
-
581
- if (!(await nodeScaffoldFs.exists(file.target))) {
582
- const coveredBy = await findGovernanceCoverage(workflowsDir);
583
- if (coveredBy) {
584
- log(io, chalk.gray(`治理检查已由 ${coveredBy} 覆盖,跳过创建 harness-governance.yml`));
585
- return;
586
- }
587
- }
588
-
589
- await runPlan([file], io);
590
- }