@dommaker/harness 0.19.0 → 1.1.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 (398) hide show
  1. package/CHANGELOG.md +22 -9
  2. package/bin/harness.js +136 -557
  3. package/dist/cli/commands/check.d.ts.map +1 -1
  4. package/dist/cli/commands/check.js +2 -13
  5. package/dist/cli/commands/check.js.map +1 -1
  6. package/dist/cli/commands/definitions.d.ts +90 -0
  7. package/dist/cli/commands/definitions.d.ts.map +1 -0
  8. package/dist/cli/commands/definitions.js +519 -0
  9. package/dist/cli/commands/definitions.js.map +1 -0
  10. package/dist/cli/commands/knowledge.js.map +1 -1
  11. package/dist/cli/commands/sync-docs/agents-syncer.d.ts.map +1 -1
  12. package/dist/cli/commands/sync-docs/agents-syncer.js +25 -4
  13. package/dist/cli/commands/sync-docs/agents-syncer.js.map +1 -1
  14. package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts +3 -25
  15. package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts.map +1 -1
  16. package/dist/cli/commands/sync-docs/capabilities-syncer.js +3 -93
  17. package/dist/cli/commands/sync-docs/capabilities-syncer.js.map +1 -1
  18. package/dist/cli/commands/sync-docs/index.d.ts +1 -1
  19. package/dist/cli/commands/sync-docs/index.d.ts.map +1 -1
  20. package/dist/cli/commands/sync-docs/index.js +4 -4
  21. package/dist/cli/commands/sync-docs/index.js.map +1 -1
  22. package/dist/completion-checkers/classify.d.ts +23 -0
  23. package/dist/completion-checkers/classify.d.ts.map +1 -0
  24. package/dist/completion-checkers/classify.js +37 -0
  25. package/dist/completion-checkers/classify.js.map +1 -0
  26. package/dist/completion-checkers/contract-presence.d.ts +12 -0
  27. package/dist/completion-checkers/contract-presence.d.ts.map +1 -0
  28. package/dist/completion-checkers/contract-presence.js +36 -0
  29. package/dist/completion-checkers/contract-presence.js.map +1 -0
  30. package/dist/completion-checkers/glob-match.d.ts +13 -0
  31. package/dist/completion-checkers/glob-match.d.ts.map +1 -0
  32. package/dist/completion-checkers/glob-match.js +58 -0
  33. package/dist/completion-checkers/glob-match.js.map +1 -0
  34. package/dist/completion-checkers/index.d.ts +19 -0
  35. package/dist/completion-checkers/index.d.ts.map +1 -0
  36. package/dist/completion-checkers/index.js +47 -0
  37. package/dist/completion-checkers/index.js.map +1 -0
  38. package/dist/completion-checkers/phase-format.d.ts +15 -0
  39. package/dist/completion-checkers/phase-format.d.ts.map +1 -0
  40. package/dist/completion-checkers/phase-format.js +42 -0
  41. package/dist/completion-checkers/phase-format.js.map +1 -0
  42. package/dist/completion-checkers/tdd-chain.d.ts +16 -0
  43. package/dist/completion-checkers/tdd-chain.d.ts.map +1 -0
  44. package/dist/completion-checkers/tdd-chain.js +57 -0
  45. package/dist/completion-checkers/tdd-chain.js.map +1 -0
  46. package/dist/completion-checkers/types.d.ts +77 -0
  47. package/dist/completion-checkers/types.d.ts.map +1 -0
  48. package/dist/completion-checkers/types.js +10 -0
  49. package/dist/completion-checkers/types.js.map +1 -0
  50. package/dist/context/index.d.ts +1 -5
  51. package/dist/context/index.d.ts.map +1 -1
  52. package/dist/context/index.js +1 -5
  53. package/dist/context/index.js.map +1 -1
  54. package/dist/context/knowledge-injector.d.ts +3 -3
  55. package/dist/context/knowledge-injector.d.ts.map +1 -1
  56. package/dist/context/knowledge-injector.js +1 -1
  57. package/dist/context/session-manager.d.ts +1 -12
  58. package/dist/context/session-manager.d.ts.map +1 -1
  59. package/dist/context/session-manager.js +0 -63
  60. package/dist/context/session-manager.js.map +1 -1
  61. package/dist/context/types.d.ts +1 -39
  62. package/dist/context/types.d.ts.map +1 -1
  63. package/dist/context/types.js +2 -15
  64. package/dist/context/types.js.map +1 -1
  65. package/dist/core/constraints/agent-prompt-renderer.d.ts +1 -1
  66. package/dist/core/constraints/agent-prompt-renderer.js +1 -1
  67. package/dist/core/constraints/capabilities-parser.d.ts +17 -2
  68. package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
  69. package/dist/core/constraints/capabilities-parser.js +84 -2
  70. package/dist/core/constraints/capabilities-parser.js.map +1 -1
  71. package/dist/core/constraints/checker.d.ts +3 -17
  72. package/dist/core/constraints/checker.d.ts.map +1 -1
  73. package/dist/core/constraints/checker.js +7 -47
  74. package/dist/core/constraints/checker.js.map +1 -1
  75. package/dist/core/constraints/definitions.d.ts +0 -7
  76. package/dist/core/constraints/definitions.d.ts.map +1 -1
  77. package/dist/core/constraints/definitions.js +1 -8
  78. package/dist/core/constraints/definitions.js.map +1 -1
  79. package/dist/core/constraints/doc-freshness/runner.d.ts +0 -2
  80. package/dist/core/constraints/doc-freshness/runner.d.ts.map +1 -1
  81. package/dist/core/constraints/doc-freshness/runner.js.map +1 -1
  82. package/dist/core/constraints/index.d.ts +1 -1
  83. package/dist/core/constraints/index.d.ts.map +1 -1
  84. package/dist/core/constraints/index.js +2 -3
  85. package/dist/core/constraints/index.js.map +1 -1
  86. package/dist/core/constraints/interceptor.d.ts.map +1 -1
  87. package/dist/core/constraints/interceptor.js +1 -5
  88. package/dist/core/constraints/interceptor.js.map +1 -1
  89. package/dist/core/effective-constraints.d.ts.map +1 -1
  90. package/dist/core/effective-constraints.js +0 -1
  91. package/dist/core/effective-constraints.js.map +1 -1
  92. package/dist/core/project-config-loader.d.ts.map +1 -1
  93. package/dist/core/project-config-loader.js +1 -8
  94. package/dist/core/project-config-loader.js.map +1 -1
  95. package/dist/dashboard/stats.d.ts.map +1 -1
  96. package/dist/dashboard/stats.js.map +1 -1
  97. package/dist/dashboard/types.d.ts +2 -2
  98. package/dist/dashboard/types.d.ts.map +1 -1
  99. package/dist/failure/constraint-handler.d.ts.map +1 -1
  100. package/dist/failure/constraint-handler.js +0 -2
  101. package/dist/failure/constraint-handler.js.map +1 -1
  102. package/dist/gates/acceptance.d.ts +9 -1
  103. package/dist/gates/acceptance.d.ts.map +1 -1
  104. package/dist/gates/acceptance.js +21 -0
  105. package/dist/gates/acceptance.js.map +1 -1
  106. package/dist/gates/checker-gate.d.ts +23 -0
  107. package/dist/gates/checker-gate.d.ts.map +1 -0
  108. package/dist/gates/checker-gate.js +53 -0
  109. package/dist/gates/checker-gate.js.map +1 -0
  110. package/dist/gates/command.d.ts +9 -2
  111. package/dist/gates/command.d.ts.map +1 -1
  112. package/dist/gates/command.js +10 -0
  113. package/dist/gates/command.js.map +1 -1
  114. package/dist/gates/contract.d.ts +8 -2
  115. package/dist/gates/contract.d.ts.map +1 -1
  116. package/dist/gates/contract.js +9 -0
  117. package/dist/gates/contract.js.map +1 -1
  118. package/dist/gates/decision.d.ts +17 -0
  119. package/dist/gates/decision.d.ts.map +1 -0
  120. package/dist/gates/decision.js +25 -0
  121. package/dist/gates/decision.js.map +1 -0
  122. package/dist/gates/definitions.d.ts +63 -0
  123. package/dist/gates/definitions.d.ts.map +1 -0
  124. package/dist/gates/definitions.js +160 -0
  125. package/dist/gates/definitions.js.map +1 -0
  126. package/dist/gates/effective-gates.d.ts +30 -0
  127. package/dist/gates/effective-gates.d.ts.map +1 -0
  128. package/dist/gates/effective-gates.js +85 -0
  129. package/dist/gates/effective-gates.js.map +1 -0
  130. package/dist/gates/index.d.ts +25 -1
  131. package/dist/gates/index.d.ts.map +1 -1
  132. package/dist/gates/index.js +37 -1
  133. package/dist/gates/index.js.map +1 -1
  134. package/dist/gates/performance.d.ts +8 -2
  135. package/dist/gates/performance.d.ts.map +1 -1
  136. package/dist/gates/performance.js +9 -0
  137. package/dist/gates/performance.js.map +1 -1
  138. package/dist/gates/registry.d.ts +32 -0
  139. package/dist/gates/registry.d.ts.map +1 -0
  140. package/dist/gates/registry.js +90 -0
  141. package/dist/gates/registry.js.map +1 -0
  142. package/dist/gates/review.d.ts +8 -2
  143. package/dist/gates/review.d.ts.map +1 -1
  144. package/dist/gates/review.js +9 -0
  145. package/dist/gates/review.js.map +1 -1
  146. package/dist/gates/runner.d.ts +30 -0
  147. package/dist/gates/runner.d.ts.map +1 -0
  148. package/dist/gates/runner.js +38 -0
  149. package/dist/gates/runner.js.map +1 -0
  150. package/dist/gates/security.d.ts +8 -2
  151. package/dist/gates/security.d.ts.map +1 -1
  152. package/dist/gates/security.js +9 -0
  153. package/dist/gates/security.js.map +1 -1
  154. package/dist/gates/types.d.ts +41 -1
  155. package/dist/gates/types.d.ts.map +1 -1
  156. package/dist/hooks/bootstrap.d.ts.map +1 -1
  157. package/dist/hooks/bootstrap.js +0 -2
  158. package/dist/hooks/bootstrap.js.map +1 -1
  159. package/dist/hooks/config.d.ts +26 -0
  160. package/dist/hooks/config.d.ts.map +1 -0
  161. package/dist/hooks/config.js +30 -0
  162. package/dist/hooks/config.js.map +1 -0
  163. package/dist/hooks/index.d.ts +2 -1
  164. package/dist/hooks/index.d.ts.map +1 -1
  165. package/dist/hooks/index.js +4 -1
  166. package/dist/hooks/index.js.map +1 -1
  167. package/dist/hooks/registry.d.ts +18 -1
  168. package/dist/hooks/registry.d.ts.map +1 -1
  169. package/dist/hooks/registry.js +45 -0
  170. package/dist/hooks/registry.js.map +1 -1
  171. package/dist/hooks/types.d.ts +20 -0
  172. package/dist/hooks/types.d.ts.map +1 -1
  173. package/dist/index.d.ts +5 -8
  174. package/dist/index.d.ts.map +1 -1
  175. package/dist/index.js +11 -20
  176. package/dist/index.js.map +1 -1
  177. package/dist/knowledge/import.d.ts +2 -2
  178. package/dist/knowledge/import.d.ts.map +1 -1
  179. package/dist/knowledge/ingest.js.map +1 -1
  180. package/dist/knowledge/lifecycle-hooks.d.ts +2 -2
  181. package/dist/knowledge/lifecycle-hooks.d.ts.map +1 -1
  182. package/dist/knowledge/types.d.ts +5 -7
  183. package/dist/knowledge/types.d.ts.map +1 -1
  184. package/dist/knowledge/types.js +1 -1
  185. package/dist/knowledge/types.js.map +1 -1
  186. package/dist/monitoring/constraint-doctor.d.ts +4 -22
  187. package/dist/monitoring/constraint-doctor.d.ts.map +1 -1
  188. package/dist/monitoring/constraint-doctor.js +7 -94
  189. package/dist/monitoring/constraint-doctor.js.map +1 -1
  190. package/dist/presets/standard.d.ts +1 -1
  191. package/dist/presets/standard.d.ts.map +1 -1
  192. package/dist/presets/standard.js +1 -2
  193. package/dist/presets/standard.js.map +1 -1
  194. package/dist/pretool-use-hook.d.ts +16 -0
  195. package/dist/pretool-use-hook.d.ts.map +1 -0
  196. package/dist/pretool-use-hook.js +68 -0
  197. package/dist/pretool-use-hook.js.map +1 -0
  198. package/dist/spec/annotation-checker.d.ts.map +1 -1
  199. package/dist/spec/annotation-checker.js +6 -26
  200. package/dist/spec/annotation-checker.js.map +1 -1
  201. package/dist/tools/index.d.ts +0 -4
  202. package/dist/tools/index.d.ts.map +1 -1
  203. package/dist/tools/index.js +0 -4
  204. package/dist/tools/index.js.map +1 -1
  205. package/dist/types/constraint.d.ts +1 -12
  206. package/dist/types/constraint.d.ts.map +1 -1
  207. package/dist/types/constraint.js +0 -3
  208. package/dist/types/constraint.js.map +1 -1
  209. package/dist/types/project-config.d.ts +0 -2
  210. package/dist/types/project-config.d.ts.map +1 -1
  211. package/dist/utils/file-walk.d.ts +2 -2
  212. package/dist/utils/file-walk.js +2 -2
  213. package/package.json +6 -1
  214. package/src/CONTEXT.md +15 -0
  215. package/src/__tests__/checker-extra.test.ts +2 -59
  216. package/src/__tests__/constraint-doctor.test.ts +1 -140
  217. package/src/__tests__/constraint-handler.test.ts +0 -4
  218. package/src/__tests__/pretool-use-hook.test.ts +82 -0
  219. package/src/__tests__/project-config-loader-extra.test.ts +0 -20
  220. package/src/__tests__/project-config-loader.test.ts +0 -1
  221. package/src/cli/commands/CONTEXT.md +15 -7
  222. package/src/cli/commands/__tests__/check-drift.test.ts +0 -3
  223. package/src/cli/commands/__tests__/check-skip-output.test.ts +0 -5
  224. package/src/cli/commands/__tests__/check.test.ts +7 -75
  225. package/src/cli/commands/__tests__/registry.test.ts +201 -0
  226. package/src/cli/commands/__tests__/sync-docs-agents.test.ts +55 -0
  227. package/src/cli/commands/check.ts +2 -14
  228. package/src/cli/commands/definitions.ts +593 -0
  229. package/src/cli/commands/knowledge.ts +3 -3
  230. package/src/cli/commands/sync-docs/agents-syncer.ts +26 -6
  231. package/src/cli/commands/sync-docs/capabilities-syncer.ts +4 -110
  232. package/src/cli/commands/sync-docs/index.ts +8 -5
  233. package/src/completion-checkers/CONTEXT.md +25 -0
  234. package/src/completion-checkers/__tests__/contract-presence.test.ts +44 -0
  235. package/src/completion-checkers/__tests__/phase-format.test.ts +60 -0
  236. package/src/completion-checkers/__tests__/tdd-chain.test.ts +99 -0
  237. package/src/completion-checkers/classify.ts +47 -0
  238. package/src/completion-checkers/contract-presence.ts +40 -0
  239. package/src/completion-checkers/glob-match.ts +54 -0
  240. package/src/completion-checkers/index.ts +19 -0
  241. package/src/completion-checkers/phase-format.ts +48 -0
  242. package/src/completion-checkers/tdd-chain.ts +63 -0
  243. package/src/completion-checkers/types.ts +84 -0
  244. package/src/context/CONTEXT.md +2 -7
  245. package/src/context/__tests__/session-manager.test.ts +0 -91
  246. package/src/context/index.ts +1 -5
  247. package/src/context/knowledge-injector.ts +3 -3
  248. package/src/context/session-manager.ts +0 -74
  249. package/src/context/types.ts +2 -63
  250. package/src/core/constraints/__tests__/interceptor.test.ts +0 -2
  251. package/src/core/constraints/agent-prompt-renderer.ts +1 -1
  252. package/src/core/constraints/capabilities-parser.ts +95 -2
  253. package/src/core/constraints/checker.ts +8 -53
  254. package/src/core/constraints/definitions.ts +0 -8
  255. package/src/core/constraints/doc-freshness/runner.ts +1 -2
  256. package/src/core/constraints/index.ts +1 -2
  257. package/src/core/constraints/interceptor.ts +1 -6
  258. package/src/core/effective-constraints.ts +0 -1
  259. package/src/core/project-config-loader.ts +1 -7
  260. package/src/dashboard/stats.ts +2 -2
  261. package/src/dashboard/types.ts +2 -2
  262. package/src/failure/constraint-handler.ts +0 -2
  263. package/src/gates/CONTEXT.md +16 -13
  264. package/src/gates/__tests__/checker-gate.test.ts +45 -0
  265. package/src/gates/__tests__/contract.test.ts +73 -0
  266. package/src/gates/__tests__/effective-gates.test.ts +82 -0
  267. package/src/gates/__tests__/gate-interface.test.ts +202 -0
  268. package/src/gates/__tests__/registry.test.ts +87 -0
  269. package/src/gates/__tests__/runner.test.ts +81 -0
  270. package/src/gates/acceptance.ts +24 -1
  271. package/src/gates/checker-gate.ts +54 -0
  272. package/src/gates/command.ts +13 -2
  273. package/src/gates/contract.ts +12 -2
  274. package/src/gates/decision.ts +27 -0
  275. package/src/gates/definitions.ts +207 -0
  276. package/src/gates/effective-gates.ts +106 -0
  277. package/src/gates/index.ts +38 -0
  278. package/src/gates/performance.ts +12 -2
  279. package/src/gates/registry.ts +107 -0
  280. package/src/gates/review.ts +12 -2
  281. package/src/gates/runner.ts +57 -0
  282. package/src/gates/security.ts +12 -2
  283. package/src/gates/types.ts +48 -1
  284. package/src/hooks/CONTEXT.md +12 -2
  285. package/src/hooks/__tests__/bootstrap.test.ts +0 -1
  286. package/src/hooks/__tests__/config.test.ts +19 -0
  287. package/src/hooks/__tests__/pipeline.test.ts +79 -0
  288. package/src/hooks/__tests__/registry.test.ts +67 -0
  289. package/src/hooks/bootstrap.ts +0 -2
  290. package/src/hooks/config.ts +29 -0
  291. package/src/hooks/index.ts +2 -1
  292. package/src/hooks/registry.ts +60 -1
  293. package/src/hooks/types.ts +21 -0
  294. package/src/index.ts +11 -21
  295. package/src/knowledge/import.ts +3 -3
  296. package/src/knowledge/ingest.ts +4 -4
  297. package/src/knowledge/lifecycle-hooks.ts +3 -3
  298. package/src/knowledge/types.ts +5 -8
  299. package/src/monitoring/constraint-doctor.ts +7 -106
  300. package/src/presets/__tests__/standard.test.ts +0 -2
  301. package/src/presets/standard.ts +1 -2
  302. package/src/pretool-use-hook.ts +68 -0
  303. package/src/spec/__tests__/annotation-checker.test.ts +9 -3
  304. package/src/spec/annotation-checker.ts +7 -29
  305. package/src/tools/CONTEXT.md +7 -14
  306. package/src/tools/index.ts +0 -4
  307. package/src/types/constraint.ts +1 -14
  308. package/src/types/project-config.ts +0 -3
  309. package/src/utils/file-walk.ts +2 -2
  310. package/dist/architecture/constraint-engine.d.ts +0 -67
  311. package/dist/architecture/constraint-engine.d.ts.map +0 -1
  312. package/dist/architecture/constraint-engine.js +0 -295
  313. package/dist/architecture/constraint-engine.js.map +0 -1
  314. package/dist/architecture/cross-project-checker.d.ts +0 -54
  315. package/dist/architecture/cross-project-checker.d.ts.map +0 -1
  316. package/dist/architecture/cross-project-checker.js +0 -467
  317. package/dist/architecture/cross-project-checker.js.map +0 -1
  318. package/dist/cli/commands/index.d.ts +0 -30
  319. package/dist/cli/commands/index.d.ts.map +0 -1
  320. package/dist/cli/commands/index.js +0 -91
  321. package/dist/cli/commands/index.js.map +0 -1
  322. package/dist/context/file-budget.d.ts +0 -40
  323. package/dist/context/file-budget.d.ts.map +0 -1
  324. package/dist/context/file-budget.js +0 -147
  325. package/dist/context/file-budget.js.map +0 -1
  326. package/dist/context/progressive-loader.d.ts +0 -109
  327. package/dist/context/progressive-loader.d.ts.map +0 -1
  328. package/dist/context/progressive-loader.js +0 -166
  329. package/dist/context/progressive-loader.js.map +0 -1
  330. package/dist/context/token-pipeline.d.ts +0 -55
  331. package/dist/context/token-pipeline.d.ts.map +0 -1
  332. package/dist/context/token-pipeline.js +0 -220
  333. package/dist/context/token-pipeline.js.map +0 -1
  334. package/dist/context/tool-output-budget.d.ts +0 -59
  335. package/dist/context/tool-output-budget.d.ts.map +0 -1
  336. package/dist/context/tool-output-budget.js +0 -177
  337. package/dist/context/tool-output-budget.js.map +0 -1
  338. package/dist/core/constraints/default-executors.d.ts +0 -10
  339. package/dist/core/constraints/default-executors.d.ts.map +0 -1
  340. package/dist/core/constraints/default-executors.js +0 -120
  341. package/dist/core/constraints/default-executors.js.map +0 -1
  342. package/dist/llm/adapter.d.ts +0 -36
  343. package/dist/llm/adapter.d.ts.map +0 -1
  344. package/dist/llm/adapter.js +0 -118
  345. package/dist/llm/adapter.js.map +0 -1
  346. package/dist/llm/index.d.ts +0 -3
  347. package/dist/llm/index.d.ts.map +0 -1
  348. package/dist/llm/index.js +0 -19
  349. package/dist/llm/index.js.map +0 -1
  350. package/dist/llm/types.d.ts +0 -62
  351. package/dist/llm/types.d.ts.map +0 -1
  352. package/dist/llm/types.js +0 -8
  353. package/dist/llm/types.js.map +0 -1
  354. package/dist/tools/core/index.d.ts +0 -13
  355. package/dist/tools/core/index.d.ts.map +0 -1
  356. package/dist/tools/core/index.js +0 -198
  357. package/dist/tools/core/index.js.map +0 -1
  358. package/dist/tools/loader.d.ts +0 -21
  359. package/dist/tools/loader.d.ts.map +0 -1
  360. package/dist/tools/loader.js +0 -199
  361. package/dist/tools/loader.js.map +0 -1
  362. package/dist/tools/registry.d.ts +0 -59
  363. package/dist/tools/registry.d.ts.map +0 -1
  364. package/dist/tools/registry.js +0 -115
  365. package/dist/tools/registry.js.map +0 -1
  366. package/dist/tools/types.d.ts +0 -38
  367. package/dist/tools/types.d.ts.map +0 -1
  368. package/dist/tools/types.js +0 -6
  369. package/dist/tools/types.js.map +0 -1
  370. package/src/__tests__/architecture-engine.test.ts +0 -619
  371. package/src/__tests__/context/progressive-loader.test.ts +0 -131
  372. package/src/__tests__/cross-project-checker.test.ts +0 -318
  373. package/src/architecture/CONTEXT.md +0 -22
  374. package/src/architecture/constraint-engine.ts +0 -351
  375. package/src/architecture/cross-project-checker.ts +0 -545
  376. package/src/cli/commands/index.ts +0 -30
  377. package/src/context/__tests__/file-budget.test.ts +0 -142
  378. package/src/context/__tests__/progressive-loader.test.ts +0 -264
  379. package/src/context/__tests__/token-pipeline.test.ts +0 -178
  380. package/src/context/__tests__/tool-output-budget.test.ts +0 -95
  381. package/src/context/file-budget.ts +0 -142
  382. package/src/context/progressive-loader.ts +0 -260
  383. package/src/context/token-pipeline.ts +0 -265
  384. package/src/context/tool-output-budget.ts +0 -178
  385. package/src/core/constraints/__tests__/default-executors.test.ts +0 -57
  386. package/src/core/constraints/default-executors.ts +0 -92
  387. package/src/llm/CONTEXT.md +0 -21
  388. package/src/llm/__tests__/adapter.test.ts +0 -172
  389. package/src/llm/adapter.ts +0 -149
  390. package/src/llm/index.ts +0 -2
  391. package/src/llm/types.ts +0 -81
  392. package/src/tools/__tests__/loader.test.ts +0 -252
  393. package/src/tools/__tests__/registry.test.ts +0 -157
  394. package/src/tools/core/__tests__/core.test.ts +0 -122
  395. package/src/tools/core/index.ts +0 -201
  396. package/src/tools/loader.ts +0 -216
  397. package/src/tools/registry.ts +0 -128
  398. package/src/tools/types.ts +0 -46
@@ -0,0 +1,593 @@
1
+ /**
2
+ * CLI 命令定义表(H5:命令定义即注册的单一来源,R6 消灭 commands/index.ts
3
+ * 与 bin/harness.js 两处手工同步)
4
+ *
5
+ * - bin/harness.js 遍历本表注册表驱动生成全部 commander 命令块,
6
+ * 不再手写命令注册;新增命令 = 命令实现文件 + 本表一条定义 + 测试。
7
+ * - 每个实现引用(CommandImplRef)标注实现文件与导出名;bin 按需
8
+ * per-command 懒加载(O2):只在 action 执行时 require 对应命令模块,
9
+ * 不再经单一 barrel 加载全部命令实现。
10
+ * - 本模块是纯数据模块:禁止 import 任何命令实现(含运行时依赖),
11
+ * 保证 --help/--version 懒加载不被破坏;注册表完整性断言(引用实现
12
+ * 可解析)在 __tests__/registry.test.ts 构建/测试期校验。
13
+ */
14
+
15
+ /**
16
+ * 命令 CLI 选项元数据(直接映射 commander `.option()`)
17
+ */
18
+ export interface CommandCliOption {
19
+ /** commander option flags,如 '-p, --project-path <path>' */
20
+ flags: string;
21
+ /** 选项描述 */
22
+ description: string;
23
+ /** commander 缺省值;negated option(如 --no-strict)不设,由 commander 默认 true */
24
+ defaultValue?: string | boolean;
25
+ }
26
+
27
+ /**
28
+ * 命令实现引用(per-command 懒加载路径)
29
+ */
30
+ export interface CommandImplRef {
31
+ /** 实现模块名(相对 src/cli/commands,如 'check' / 'sync-docs') */
32
+ module: string;
33
+ /** 模块内导出函数名 */
34
+ export: string;
35
+ }
36
+
37
+ /**
38
+ * 子命令条目:别名 → 实现 + 实参构造
39
+ */
40
+ export interface CommandSubcommand {
41
+ /** 实现引用 */
42
+ impl: CommandImplRef;
43
+ /** 实参构造:positionals = 子命令名之后的位置参数(无则 []) */
44
+ args?: (positionals: (string | undefined)[], options: Record<string, unknown>) => unknown[];
45
+ }
46
+
47
+ /**
48
+ * 选项条件路由(如 check --list):选项值匹配时以路由替代默认 action;
49
+ * 同一选项可挂多条路由(按声明顺序执行,如 passes-gate --coverage)
50
+ */
51
+ export interface CommandOptionRoute {
52
+ /** 触发选项键(commander options 对象键名,如 'list') */
53
+ flag: string;
54
+ /** 触发值 */
55
+ when: unknown;
56
+ /** 实现引用 */
57
+ impl: CommandImplRef;
58
+ /** 实参构造(缺省为 [options]) */
59
+ args?: (positionals: (string | undefined)[], options: Record<string, unknown>) => unknown[];
60
+ }
61
+
62
+ /**
63
+ * 命令定义
64
+ */
65
+ export interface CommandDefinition {
66
+ /** 命令名(commander 注册字符串,可含位置参数,如 'retire [id]') */
67
+ command: string;
68
+ /** 命令描述 */
69
+ description: string;
70
+ /** 命令别名 */
71
+ alias?: string;
72
+ /** 位置参数声明(如 '[subcommand]' / '[subcommand] [arg]' / '<planPath>') */
73
+ argument?: string;
74
+ /** 命令选项 */
75
+ options: CommandCliOption[];
76
+ /** 子命令(commander 嵌套命令,如 constraints report / retire) */
77
+ children?: CommandDefinition[];
78
+ /** 默认 action 实现引用;缺省时裸调用显示帮助(subcommand 命令) */
79
+ action?: CommandImplRef;
80
+ /** 子命令路由:位置参数首值 → 条目;未知值报错退出(strict) */
81
+ subcommands?: Record<string, CommandSubcommand>;
82
+ /** false = 未知位置参数不报错、落回默认 action(spec 的文件参数用法) */
83
+ subcommandStrict?: boolean;
84
+ /** 选项条件路由(匹配时替代默认 action 执行) */
85
+ optionRoutes?: CommandOptionRoute[];
86
+ /** 默认 action 实参构造(缺省为 [options]) */
87
+ mapActionArgs?: (positionals: (string | undefined)[], options: Record<string, unknown>) => unknown[];
88
+ /** action 完成后处理(接收返回值,如 sync-docs --check 失败 exit(1)) */
89
+ afterRun?: (result: unknown, options: Record<string, unknown>) => void;
90
+ }
91
+
92
+ /**
93
+ * 全部非门禁 CLI 命令定义(门禁命令由 GATE_DEFINITIONS 生成,见 src/gates/definitions.ts)
94
+ */
95
+ export const COMMAND_DEFINITIONS: CommandDefinition[] = [
96
+ {
97
+ command: 'check',
98
+ description: '检查铁律是否满足',
99
+ options: [
100
+ { flags: '-p, --preset <preset>', description: '预设名称', defaultValue: 'standard' },
101
+ { flags: '-s, --staged', description: '只检查暂存文件', defaultValue: false },
102
+ { flags: '-t, --trigger <trigger>', description: '触发条件' },
103
+ { flags: '--project-path <path>', description: '项目路径' },
104
+ { flags: '--list', description: '列出所有铁律' },
105
+ ],
106
+ action: { module: 'check', export: 'check' },
107
+ optionRoutes: [
108
+ { flag: 'list', when: true, impl: { module: 'check', export: 'listLaws' }, args: () => [] },
109
+ ],
110
+ },
111
+ {
112
+ command: 'validate',
113
+ description: '验证检查点是否满足',
114
+ options: [
115
+ { flags: '-f, --file <path>', description: '检查点文件路径' },
116
+ { flags: '-p, --project-path <path>', description: '项目路径' },
117
+ { flags: '--strict', description: '严格模式(任何失败都退出)', defaultValue: false },
118
+ ],
119
+ action: { module: 'validate', export: 'validate' },
120
+ },
121
+ {
122
+ command: 'passes-gate',
123
+ alias: 'pg',
124
+ description: '运行测试门控,确保测试通过',
125
+ options: [
126
+ { flags: '-t, --test-command <command>', description: '测试命令' },
127
+ { flags: '-p, --project-path <path>', description: '项目路径' },
128
+ { flags: '--allow-partial', description: '允许部分测试通过', defaultValue: false },
129
+ { flags: '--max-retries <n>', description: '最大重试次数', defaultValue: '2' },
130
+ { flags: '--coverage', description: '检查测试覆盖率' },
131
+ { flags: '--coverage-threshold <n>', description: '覆盖率阈值', defaultValue: '80' },
132
+ ],
133
+ action: { module: 'passes-gate', export: 'runPassesGate' },
134
+ optionRoutes: [
135
+ { flag: 'coverage', when: true, impl: { module: 'passes-gate', export: 'runPassesGate' } },
136
+ {
137
+ flag: 'coverage',
138
+ when: true,
139
+ impl: { module: 'passes-gate', export: 'checkCoverage' },
140
+ args: (_pos, options) => [
141
+ options.projectPath || process.cwd(),
142
+ parseInt(String(options.coverageThreshold), 10),
143
+ ],
144
+ },
145
+ ],
146
+ },
147
+ {
148
+ command: 'init',
149
+ description: '初始化项目的 harness 配置',
150
+ options: [
151
+ { flags: '-p, --preset <preset>', description: '预设名称 (strict/standard/relaxed)', defaultValue: 'standard' },
152
+ { flags: '-g, --governance <level>', description: '治理级别 (minimal/standard/strict)' },
153
+ { flags: '-t, --type <type>', description: '项目类型 (node-api/nextjs-app/python-api/custom)' },
154
+ { flags: '--project-path <path>', description: '项目路径' },
155
+ { flags: '--no-git-hooks', description: '不创建 Git hooks' },
156
+ { flags: '--no-github-actions', description: '不创建 GitHub Actions' },
157
+ { flags: '--print-snippets', description: '只输出代码片段,不创建文件' },
158
+ ],
159
+ action: { module: 'init', export: 'init' },
160
+ },
161
+ {
162
+ command: 'report',
163
+ description: '生成检查报告',
164
+ options: [
165
+ { flags: '-o, --output <path>', description: '输出文件路径' },
166
+ { flags: '-f, --format <format>', description: '输出格式 (json/markdown/html)', defaultValue: 'markdown' },
167
+ { flags: '-p, --project-path <path>', description: '项目路径' },
168
+ ],
169
+ action: { module: 'report', export: 'report' },
170
+ },
171
+ {
172
+ command: 'status',
173
+ description: '显示 Harness 状态、统计、异常检测',
174
+ options: [
175
+ { flags: '-p, --project-path <path>', description: '项目路径' },
176
+ { flags: '-d, --detail', description: '显示详细信息', defaultValue: false },
177
+ { flags: '-a, --anomalies', description: '只显示异常', defaultValue: false },
178
+ { flags: '--hours <n>', description: '分析最近 N 小时', defaultValue: '24' },
179
+ ],
180
+ action: { module: 'status', export: 'status' },
181
+ mapActionArgs: (_pos, options) => [
182
+ {
183
+ projectPath: options.projectPath,
184
+ detail: options.detail,
185
+ anomalies: options.anomalies,
186
+ hours: parseInt(String(options.hours), 10),
187
+ },
188
+ ],
189
+ },
190
+ {
191
+ command: 'spec',
192
+ argument: '[subcommand]',
193
+ description: 'Spec 验证命令',
194
+ options: [
195
+ { flags: '-s, --schema <path>', description: 'Schema 路径(项目定义)' },
196
+ { flags: '--staged', description: '只验证暂存文件', defaultValue: false },
197
+ { flags: '-f, --file <path>', description: '验证指定文件' },
198
+ { flags: '-p, --project-path <path>', description: '项目路径' },
199
+ { flags: '-v, --verbose', description: '详细输出', defaultValue: false },
200
+ ],
201
+ action: { module: 'spec', export: 'specValidate' },
202
+ subcommands: {
203
+ list: { impl: { module: 'spec', export: 'listSpecTypes' }, args: () => [] },
204
+ },
205
+ // 未知位置参数按文件路径落回默认 action(spec foo.yaml 合法用法)
206
+ subcommandStrict: false,
207
+ mapActionArgs: (positionals, options) => [
208
+ {
209
+ schema: options.schema,
210
+ staged: options.staged,
211
+ file: options.file ||
212
+ (positionals[0] && !String(positionals[0]).startsWith('-') ? positionals[0] : undefined),
213
+ projectPath: options.projectPath,
214
+ verbose: options.verbose,
215
+ },
216
+ ],
217
+ },
218
+ {
219
+ command: 'sync-docs',
220
+ description: '同步项目文档(CAPABILITIES.md、CONTEXT.md、AGENTS.md)',
221
+ options: [
222
+ { flags: '-p, --project-path <path>', description: '项目路径' },
223
+ { flags: '-c, --check', description: '只检查不修改(CI 模式)', defaultValue: false },
224
+ { flags: '--json', description: '输出 JSON 格式(供 LLM 消费)', defaultValue: false },
225
+ { flags: '--agents', description: '同步 AGENTS.md(agent 导读;PRESERVE 标记段重新生成时保留)', defaultValue: false },
226
+ { flags: '--compact', description: '一次性迁移:将 CAPABILITIES.md 文件表格折叠为目录条目', defaultValue: false },
227
+ ],
228
+ action: { module: 'sync-docs', export: 'syncDocs' },
229
+ afterRun: (ok, options) => {
230
+ if (!ok && options.check) {
231
+ process.exit(1);
232
+ }
233
+ },
234
+ },
235
+ {
236
+ command: 'knowledge',
237
+ argument: '[subcommand] [arg]',
238
+ alias: 'kb',
239
+ description: '知识库管理(list/search/import/decay/stats/audit)',
240
+ options: [
241
+ { flags: '-p, --project-path <path>', description: '项目路径' },
242
+ { flags: '--type <types>', description: '按类型过滤(逗号分隔)' },
243
+ { flags: '--maturity <levels>', description: '按成熟度过滤(逗号分隔)' },
244
+ { flags: '--tag <tags>', description: '按标签过滤(逗号分隔)' },
245
+ { flags: '--sources <sources>', description: '导入源(逗号分隔: code,git,docs)' },
246
+ { flags: '--limit <n>', description: '结果数量限制', defaultValue: '20' },
247
+ { flags: '--reset', description: '重置导入状态', defaultValue: false },
248
+ { flags: '--scope <scope>', description: '知识范围(用于 upsert 去重)' },
249
+ { flags: '--title <title>', description: '知识标题(用于 upsert)' },
250
+ { flags: '--content <content>', description: '知识内容 Markdown(用于 upsert)' },
251
+ { flags: '--file <path>', description: '从文件读取内容(用于 upsert)' },
252
+ { flags: '--source <source>', description: '知识来源 (analyst/cli/design)', defaultValue: 'cli' },
253
+ { flags: '--fix', description: '自动修复(用于 audit)', defaultValue: false },
254
+ { flags: '--dry-run', description: '只输出报告不修改(用于 audit)', defaultValue: false },
255
+ { flags: '--threshold <n>', description: '短内容阈值(字符数,用于 audit)', defaultValue: '50' },
256
+ { flags: '--dir <path>', description: '知识库目录(覆盖默认路径)' },
257
+ { flags: '--json', description: 'JSON 格式输出', defaultValue: false },
258
+ ],
259
+ subcommands: {
260
+ list: {
261
+ impl: { module: 'knowledge', export: 'knowledgeList' },
262
+ args: (_pos, options) => [{
263
+ projectPath: options.projectPath, json: options.json,
264
+ type: options.type, maturity: options.maturity, tag: options.tag,
265
+ }],
266
+ },
267
+ ls: {
268
+ impl: { module: 'knowledge', export: 'knowledgeList' },
269
+ args: (_pos, options) => [{
270
+ projectPath: options.projectPath, json: options.json,
271
+ type: options.type, maturity: options.maturity, tag: options.tag,
272
+ }],
273
+ },
274
+ search: {
275
+ impl: { module: 'knowledge', export: 'knowledgeSearch' },
276
+ args: (positionals, options) => {
277
+ if (!positionals[0]) {
278
+ console.error('请提供搜索关键词');
279
+ process.exit(1);
280
+ }
281
+ return [positionals[0], {
282
+ projectPath: options.projectPath, json: options.json,
283
+ limit: parseInt(String(options.limit), 10),
284
+ }];
285
+ },
286
+ },
287
+ s: {
288
+ impl: { module: 'knowledge', export: 'knowledgeSearch' },
289
+ args: (positionals, options) => {
290
+ if (!positionals[0]) {
291
+ console.error('请提供搜索关键词');
292
+ process.exit(1);
293
+ }
294
+ return [positionals[0], {
295
+ projectPath: options.projectPath, json: options.json,
296
+ limit: parseInt(String(options.limit), 10),
297
+ }];
298
+ },
299
+ },
300
+ import: {
301
+ impl: { module: 'knowledge', export: 'knowledgeImport' },
302
+ args: (_pos, options) => [{
303
+ projectPath: options.projectPath, json: options.json,
304
+ sources: options.sources, reset: options.reset,
305
+ }],
306
+ },
307
+ i: {
308
+ impl: { module: 'knowledge', export: 'knowledgeImport' },
309
+ args: (_pos, options) => [{
310
+ projectPath: options.projectPath, json: options.json,
311
+ sources: options.sources, reset: options.reset,
312
+ }],
313
+ },
314
+ decay: {
315
+ impl: { module: 'knowledge', export: 'knowledgeDecay' },
316
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json }],
317
+ },
318
+ d: {
319
+ impl: { module: 'knowledge', export: 'knowledgeDecay' },
320
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json }],
321
+ },
322
+ stats: {
323
+ impl: { module: 'knowledge', export: 'knowledgeStats' },
324
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json }],
325
+ },
326
+ st: {
327
+ impl: { module: 'knowledge', export: 'knowledgeStats' },
328
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json }],
329
+ },
330
+ 'sync-rag': {
331
+ impl: { module: 'knowledge', export: 'knowledgeSyncRag' },
332
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json }],
333
+ },
334
+ 'sync-status': {
335
+ impl: { module: 'knowledge', export: 'knowledgeSyncStatus' },
336
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json }],
337
+ },
338
+ sync: {
339
+ impl: { module: 'knowledge', export: 'knowledgeSyncStatus' },
340
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json }],
341
+ },
342
+ upsert: {
343
+ impl: { module: 'knowledge', export: 'knowledgeUpsert' },
344
+ args: (_pos, options) => [{
345
+ scope: options.scope || '',
346
+ title: options.title || '',
347
+ content: options.content || '',
348
+ file: options.file || '',
349
+ type: options.type || 'architecture',
350
+ source: options.source || 'cli',
351
+ }],
352
+ },
353
+ up: {
354
+ impl: { module: 'knowledge', export: 'knowledgeUpsert' },
355
+ args: (_pos, options) => [{
356
+ scope: options.scope || '',
357
+ title: options.title || '',
358
+ content: options.content || '',
359
+ file: options.file || '',
360
+ type: options.type || 'architecture',
361
+ source: options.source || 'cli',
362
+ }],
363
+ },
364
+ audit: {
365
+ impl: { module: 'knowledge', export: 'knowledgeAudit' },
366
+ args: (_pos, options) => [{
367
+ projectPath: options.projectPath, json: options.json,
368
+ fix: options.fix, dryRun: options.dryRun,
369
+ threshold: options.threshold, dir: options.dir,
370
+ }],
371
+ },
372
+ a: {
373
+ impl: { module: 'knowledge', export: 'knowledgeAudit' },
374
+ args: (_pos, options) => [{
375
+ projectPath: options.projectPath, json: options.json,
376
+ fix: options.fix, dryRun: options.dryRun,
377
+ threshold: options.threshold, dir: options.dir,
378
+ }],
379
+ },
380
+ snapshot: {
381
+ impl: { module: 'knowledge', export: 'knowledgeSnapshot' },
382
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json, dir: options.dir }],
383
+ },
384
+ migrate: {
385
+ impl: { module: 'knowledge', export: 'knowledgeMigrate' },
386
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json, dir: options.dir }],
387
+ },
388
+ index: {
389
+ impl: { module: 'knowledge', export: 'knowledgeIndex' },
390
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json, dir: options.dir }],
391
+ },
392
+ idx: {
393
+ impl: { module: 'knowledge', export: 'knowledgeIndex' },
394
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json, dir: options.dir }],
395
+ },
396
+ health: {
397
+ impl: { module: 'knowledge', export: 'knowledgeHealth' },
398
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json, dir: options.dir }],
399
+ },
400
+ h: {
401
+ impl: { module: 'knowledge', export: 'knowledgeHealth' },
402
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json, dir: options.dir }],
403
+ },
404
+ },
405
+ },
406
+ {
407
+ command: 'sdd',
408
+ argument: '[subcommand]',
409
+ description: 'SDD 管理(index)',
410
+ options: [
411
+ { flags: '-p, --project-path <path>', description: '项目路径' },
412
+ { flags: '--dir <dir>', description: '指定基础目录' },
413
+ { flags: '--json', description: 'JSON 输出' },
414
+ ],
415
+ subcommands: {
416
+ index: {
417
+ impl: { module: 'sdd', export: 'sddIndex' },
418
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json, dir: options.dir }],
419
+ },
420
+ idx: {
421
+ impl: { module: 'sdd', export: 'sddIndex' },
422
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json, dir: options.dir }],
423
+ },
424
+ },
425
+ },
426
+ {
427
+ command: 'failure',
428
+ argument: '[subcommand]',
429
+ description: '失败记录管理(list/stats/clear)',
430
+ options: [
431
+ { flags: '-p, --project-path <path>', description: '项目路径' },
432
+ { flags: '--type <type>', description: '按错误类型过滤' },
433
+ { flags: '--level <level>', description: '按失败等级过滤 (L1/L2/L3/L4)' },
434
+ { flags: '--limit <n>', description: '结果数量限制', defaultValue: '20' },
435
+ { flags: '--json', description: 'JSON 格式输出', defaultValue: false },
436
+ ],
437
+ subcommands: {
438
+ list: {
439
+ impl: { module: 'failure', export: 'failureList' },
440
+ args: (_pos, options) => [{
441
+ projectPath: options.projectPath, json: options.json,
442
+ limit: parseInt(String(options.limit), 10),
443
+ type: options.type, level: options.level,
444
+ }],
445
+ },
446
+ ls: {
447
+ impl: { module: 'failure', export: 'failureList' },
448
+ args: (_pos, options) => [{
449
+ projectPath: options.projectPath, json: options.json,
450
+ limit: parseInt(String(options.limit), 10),
451
+ type: options.type, level: options.level,
452
+ }],
453
+ },
454
+ stats: {
455
+ impl: { module: 'failure', export: 'failureStats' },
456
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json }],
457
+ },
458
+ st: {
459
+ impl: { module: 'failure', export: 'failureStats' },
460
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json }],
461
+ },
462
+ clear: {
463
+ impl: { module: 'failure', export: 'failureClear' },
464
+ args: (_pos, options) => [{ projectPath: options.projectPath, json: options.json }],
465
+ },
466
+ },
467
+ },
468
+ {
469
+ command: 'posteval-plan',
470
+ argument: '<planPath>',
471
+ description: '验证 plan 文件的 checklist items 是否都有对应的 staged diff',
472
+ options: [],
473
+ action: { module: 'posteval-plan', export: 'postevalPlan' },
474
+ mapActionArgs: (positionals) => [{ planPath: positionals[0] }],
475
+ },
476
+ {
477
+ command: 'update-user-model',
478
+ alias: 'uum',
479
+ description: '从新对话中提取信号,更新用户思维模型(增量演化)',
480
+ options: [
481
+ { flags: '--json', description: 'JSON 格式输出', defaultValue: false },
482
+ { flags: '--dry-run', description: '只显示变化,不更新状态', defaultValue: false },
483
+ { flags: '--days <n>', description: '只处理最近 N 天的会话(自然日,含今天)' },
484
+ ],
485
+ action: { module: 'update-user-model', export: 'updateUserModel' },
486
+ mapActionArgs: (_pos, options) => [{
487
+ days: options.days !== undefined ? parseInt(String(options.days), 10) : undefined,
488
+ json: options.json,
489
+ dryRun: options.dryRun,
490
+ }],
491
+ },
492
+ {
493
+ command: 'release',
494
+ description: 'npm 发布流水线:tsc → dist 验证 → npm version → git push → npm publish → gh release。不依赖 Studio API。',
495
+ options: [
496
+ { flags: '--bump <type>', description: '版本递增类型', defaultValue: 'patch' },
497
+ { flags: '--dry-run <bool>', description: '仅模拟执行', defaultValue: 'false' },
498
+ ],
499
+ action: { module: 'release', export: 'release' },
500
+ mapActionArgs: (_pos, options) => [{ bumpType: options.bump, dryRun: options.dryRun }],
501
+ },
502
+ {
503
+ command: 'analyze-sessions',
504
+ alias: 'analyze',
505
+ description: '分析 Claude Code 对话,挖掘纠正模式和高频概念,生成规则候选',
506
+ options: [
507
+ { flags: '-d, --days <n>', description: '分析最近 N 天的会话', defaultValue: '7' },
508
+ { flags: '--json', description: 'JSON 格式输出', defaultValue: false },
509
+ ],
510
+ action: { module: 'analyze-sessions', export: 'analyzeSessions' },
511
+ mapActionArgs: (_pos, options) => [{
512
+ days: parseInt(String(options.days), 10),
513
+ json: options.json,
514
+ }],
515
+ },
516
+ {
517
+ command: 'constraints',
518
+ description: '输出约束集合元数据(版本、hash、计数、文本大小)',
519
+ options: [
520
+ { flags: '--json', description: '输出 JSON 格式', defaultValue: false },
521
+ ],
522
+ action: { module: 'constraints', export: 'constraints' },
523
+ children: [
524
+ {
525
+ command: 'report',
526
+ description: '约束使用报告:check 层统计表、退役候选诊断、prompt 注入清单、配置健康(只读)',
527
+ options: [
528
+ { flags: '-p, --project-path <path>', description: '项目路径' },
529
+ { flags: '--export [file]', description: '导出脱敏 markdown 摘要(缺省 .harness/reports/constraints-<YYYYMMDD>.md)' },
530
+ { flags: '--json', description: '输出 JSON 格式', defaultValue: false },
531
+ { flags: '--zero-intercept-min <n>', description: '零拦截候选的最小评估样本数', defaultValue: '50' },
532
+ { flags: '--noise-fail-rate <rate>', description: '高噪候选 fail 率阈值', defaultValue: '0.8' },
533
+ { flags: '--noise-min-total <n>', description: '高噪候选最小评估样本数', defaultValue: '20' },
534
+ ],
535
+ action: { module: 'constraints-report', export: 'constraintsReport' },
536
+ mapActionArgs: (_pos, options) => [{
537
+ projectPath: options.projectPath,
538
+ export: options.export,
539
+ json: options.json,
540
+ zeroInterceptMin: parseInt(String(options.zeroInterceptMin), 10),
541
+ noiseFailRate: parseFloat(String(options.noiseFailRate)),
542
+ noiseMinTotal: parseInt(String(options.noiseMinTotal), 10),
543
+ }],
544
+ },
545
+ {
546
+ command: 'retire',
547
+ argument: '[id]',
548
+ description: '退役约束:无 id 进入交互式候选选择(人确认);带 id 直达退役需显式 --yes(写 config.yml + KnowledgeStore + 同步 CLAUDE.md 注入段)',
549
+ options: [
550
+ { flags: '-p, --project-path <path>', description: '项目路径' },
551
+ { flags: '--reason <text>', description: '退役原因' },
552
+ { flags: '-y, --yes', description: '显式确认直达退役(人确认闸门;无此 flag 直达报错并提示改走交互模式)', defaultValue: false },
553
+ ],
554
+ action: { module: 'constraints-retire', export: 'constraintsRetire' },
555
+ mapActionArgs: (positionals, options) => [positionals[0], {
556
+ projectPath: options.projectPath,
557
+ reason: options.reason,
558
+ yes: options.yes,
559
+ }],
560
+ },
561
+ ],
562
+ },
563
+ {
564
+ command: 'doc-freshness-check',
565
+ argument: '<docPath>',
566
+ description: '检查文档声明的新鲜度:提取可验证声明,与代码对照',
567
+ options: [
568
+ { flags: '--changed-files <list>', description: '变更文件列表(逗号分隔)' },
569
+ { flags: '--format <format>', description: '输出格式 (table/json)', defaultValue: 'table' },
570
+ { flags: '-p, --project-path <path>', description: '项目路径' },
571
+ ],
572
+ action: { module: 'doc-freshness-check', export: 'docFreshnessCheck' },
573
+ mapActionArgs: (positionals, options) => [positionals[0], {
574
+ changedFiles: options.changedFiles,
575
+ format: options.format,
576
+ projectPath: options.projectPath,
577
+ }],
578
+ },
579
+ {
580
+ command: 'spec-baseline-check',
581
+ argument: '<specPath>',
582
+ description: '验证 spec 文件的前置条件是否满足',
583
+ options: [
584
+ { flags: '-p, --project-path <path>', description: '项目路径' },
585
+ { flags: '--json', description: '输出 JSON 格式', defaultValue: false },
586
+ ],
587
+ action: { module: 'spec-baseline-check', export: 'specBaselineCheck' },
588
+ mapActionArgs: (positionals, options) => [positionals[0], {
589
+ projectPath: options.projectPath,
590
+ json: options.json,
591
+ }],
592
+ },
593
+ ];
@@ -15,7 +15,7 @@ import { ColdStartImporter } from '../../knowledge/import';
15
15
  import { KnowledgeAudit } from '../../knowledge/audit';
16
16
  import { migrateKnowledgeEntries } from '../../knowledge/migration';
17
17
  import { KnowledgeIndexGenerator } from '../../knowledge/index-generator';
18
- import type { KnowledgeType, MaturityLevel, QueryFilter } from '../../knowledge/types';
18
+ import type { KnowledgeSubsystem, MaturityLevel, QueryFilter } from '../../knowledge/types';
19
19
 
20
20
  export interface KnowledgeOptions {
21
21
  /** 项目路径 */
@@ -36,7 +36,7 @@ export async function knowledgeList(options: KnowledgeOptions & {
36
36
 
37
37
  const filter: QueryFilter = { excludeArchived: false };
38
38
  if (options.type) {
39
- filter.types = options.type.split(',') as KnowledgeType[];
39
+ filter.types = options.type.split(',') as KnowledgeSubsystem[];
40
40
  }
41
41
  if (options.maturity) {
42
42
  filter.maturity = options.maturity.split(',') as MaturityLevel[];
@@ -85,7 +85,7 @@ export async function knowledgeSearch(
85
85
  phase: 'cli',
86
86
  maxTokens: 10000,
87
87
  maxEntries: options.limit || 20,
88
- focusTypes: [] as KnowledgeType[],
88
+ focusTypes: [] as KnowledgeSubsystem[],
89
89
  };
90
90
 
91
91
  const result = queryEngine.query(budget);
@@ -60,10 +60,11 @@ export interface GovernanceInfo {
60
60
  */
61
61
  export async function buildAgentsMd(projectPath: string, srcDirs: string[]): Promise<string> {
62
62
  const pkg = await readPackageJsonLite(projectPath);
63
- const [dirs, governance, hasKnowledge, contextDocCount] = await Promise.all([
63
+ const [dirs, governance, hasKnowledge, hasStudioContext, contextDocCount] = await Promise.all([
64
64
  getTopLevelDirEntries(projectPath, srcDirs),
65
65
  getGovernanceInfo(projectPath),
66
66
  hasKnowledgeDir(projectPath),
67
+ hasStudioContextDoc(projectPath),
67
68
  countContextDocs(projectPath, srcDirs),
68
69
  ]);
69
70
 
@@ -127,11 +128,17 @@ export async function buildAgentsMd(projectPath: string, srcDirs: string[]): Pro
127
128
  // 写进受 --check 漂移比对的文档会制造「必然过期」竞态(任何知识写入都使已提交文档过期)
128
129
  lines.push('- `.harness/knowledge/`:项目知识库,用 `harness knowledge` 查询');
129
130
  }
130
- lines.push(
131
- contextDocCount > 0
132
- ? `- 各源码目录的 \`CONTEXT.md\` 是权威模块文档(现有 ${contextDocCount} 个),改动代码时同步更新`
133
- : '- 各源码目录的 `CONTEXT.md` 是权威模块文档,缺失目录可由 `harness sync-docs` 生成模板'
134
- );
131
+ if (hasStudioContext) {
132
+ // 正本模型(studio #152/T12):模块上下文沉淀归并到业务仓 .studio/CONTEXT.md,
133
+ // 散置 CONTEXT.md 指引与该裁决矛盾,正本在场时整行替代
134
+ lines.push('- 模块上下文正本:`.studio/CONTEXT.md`(模块锚点组织),改动代码时同步更新');
135
+ } else {
136
+ lines.push(
137
+ contextDocCount > 0
138
+ ? `- 各源码目录的 \`CONTEXT.md\` 是权威模块文档(现有 ${contextDocCount} 个),改动代码时同步更新`
139
+ : '- 各源码目录的 `CONTEXT.md` 是权威模块文档,缺失目录可由 `harness sync-docs` 生成模板'
140
+ );
141
+ }
135
142
  lines.push('');
136
143
 
137
144
  return lines.join('\n');
@@ -247,6 +254,19 @@ async function hasKnowledgeDir(projectPath: string): Promise<boolean> {
247
254
  }
248
255
  }
249
256
 
257
+ /**
258
+ * 判断 .studio/CONTEXT.md 是否存在(正本模型标记,studio #152/T12):
259
+ * 模块上下文沉淀归并到业务仓单一正本(模块锚点组织)时,知识入口行改指正本,
260
+ * 不再输出散置 CONTEXT.md 指引。只判存在性,不解析内容。
261
+ */
262
+ async function hasStudioContextDoc(projectPath: string): Promise<boolean> {
263
+ try {
264
+ return (await fs.stat(path.join(projectPath, '.studio', 'CONTEXT.md'))).isFile();
265
+ } catch {
266
+ return false;
267
+ }
268
+ }
269
+
250
270
  /** 统计源码根内的 CONTEXT.md 数量(含源码根本身,跨根去重) */
251
271
  async function countContextDocs(projectPath: string, srcDirs: string[]): Promise<number> {
252
272
  const found = new Set<string>();