@dommaker/harness 0.18.0 → 1.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 (366) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/bin/harness.js +136 -552
  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/capabilities-syncer.d.ts +3 -25
  12. package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts.map +1 -1
  13. package/dist/cli/commands/sync-docs/capabilities-syncer.js +3 -93
  14. package/dist/cli/commands/sync-docs/capabilities-syncer.js.map +1 -1
  15. package/dist/cli/commands/sync-docs/index.d.ts +1 -1
  16. package/dist/cli/commands/sync-docs/index.d.ts.map +1 -1
  17. package/dist/cli/commands/sync-docs/index.js +4 -4
  18. package/dist/cli/commands/sync-docs/index.js.map +1 -1
  19. package/dist/cli/commands/update-user-model.d.ts +1 -0
  20. package/dist/cli/commands/update-user-model.d.ts.map +1 -1
  21. package/dist/cli/commands/update-user-model.js +12 -5
  22. package/dist/cli/commands/update-user-model.js.map +1 -1
  23. package/dist/context/index.d.ts +1 -5
  24. package/dist/context/index.d.ts.map +1 -1
  25. package/dist/context/index.js +1 -5
  26. package/dist/context/index.js.map +1 -1
  27. package/dist/context/knowledge-injector.d.ts +3 -3
  28. package/dist/context/knowledge-injector.d.ts.map +1 -1
  29. package/dist/context/knowledge-injector.js +1 -1
  30. package/dist/context/session-manager.d.ts +1 -12
  31. package/dist/context/session-manager.d.ts.map +1 -1
  32. package/dist/context/session-manager.js +0 -63
  33. package/dist/context/session-manager.js.map +1 -1
  34. package/dist/context/types.d.ts +1 -39
  35. package/dist/context/types.d.ts.map +1 -1
  36. package/dist/context/types.js +2 -15
  37. package/dist/context/types.js.map +1 -1
  38. package/dist/core/constraints/agent-prompt-renderer.d.ts +32 -0
  39. package/dist/core/constraints/agent-prompt-renderer.d.ts.map +1 -0
  40. package/dist/core/constraints/agent-prompt-renderer.js +58 -0
  41. package/dist/core/constraints/agent-prompt-renderer.js.map +1 -0
  42. package/dist/core/constraints/capabilities-parser.d.ts +17 -2
  43. package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
  44. package/dist/core/constraints/capabilities-parser.js +84 -2
  45. package/dist/core/constraints/capabilities-parser.js.map +1 -1
  46. package/dist/core/constraints/check-cache.d.ts +48 -3
  47. package/dist/core/constraints/check-cache.d.ts.map +1 -1
  48. package/dist/core/constraints/check-cache.js +53 -5
  49. package/dist/core/constraints/check-cache.js.map +1 -1
  50. package/dist/core/constraints/checker.d.ts +3 -17
  51. package/dist/core/constraints/checker.d.ts.map +1 -1
  52. package/dist/core/constraints/checker.js +7 -47
  53. package/dist/core/constraints/checker.js.map +1 -1
  54. package/dist/core/constraints/definitions.d.ts +0 -7
  55. package/dist/core/constraints/definitions.d.ts.map +1 -1
  56. package/dist/core/constraints/definitions.js +1 -8
  57. package/dist/core/constraints/definitions.js.map +1 -1
  58. package/dist/core/constraints/doc-freshness/runner.d.ts +0 -2
  59. package/dist/core/constraints/doc-freshness/runner.d.ts.map +1 -1
  60. package/dist/core/constraints/doc-freshness/runner.js.map +1 -1
  61. package/dist/core/constraints/index.d.ts +5 -1
  62. package/dist/core/constraints/index.d.ts.map +1 -1
  63. package/dist/core/constraints/index.js +8 -3
  64. package/dist/core/constraints/index.js.map +1 -1
  65. package/dist/core/constraints/interceptor.d.ts.map +1 -1
  66. package/dist/core/constraints/interceptor.js +1 -5
  67. package/dist/core/constraints/interceptor.js.map +1 -1
  68. package/dist/core/effective-constraints.d.ts.map +1 -1
  69. package/dist/core/effective-constraints.js +0 -1
  70. package/dist/core/effective-constraints.js.map +1 -1
  71. package/dist/core/project-config-loader.d.ts.map +1 -1
  72. package/dist/core/project-config-loader.js +1 -8
  73. package/dist/core/project-config-loader.js.map +1 -1
  74. package/dist/dashboard/stats.d.ts.map +1 -1
  75. package/dist/dashboard/stats.js.map +1 -1
  76. package/dist/dashboard/types.d.ts +2 -2
  77. package/dist/dashboard/types.d.ts.map +1 -1
  78. package/dist/failure/constraint-handler.d.ts.map +1 -1
  79. package/dist/failure/constraint-handler.js +0 -2
  80. package/dist/failure/constraint-handler.js.map +1 -1
  81. package/dist/gates/acceptance.d.ts +9 -1
  82. package/dist/gates/acceptance.d.ts.map +1 -1
  83. package/dist/gates/acceptance.js +21 -0
  84. package/dist/gates/acceptance.js.map +1 -1
  85. package/dist/gates/checker-gate.d.ts +23 -0
  86. package/dist/gates/checker-gate.d.ts.map +1 -0
  87. package/dist/gates/checker-gate.js +53 -0
  88. package/dist/gates/checker-gate.js.map +1 -0
  89. package/dist/gates/command.d.ts +9 -2
  90. package/dist/gates/command.d.ts.map +1 -1
  91. package/dist/gates/command.js +10 -0
  92. package/dist/gates/command.js.map +1 -1
  93. package/dist/gates/contract.d.ts +8 -2
  94. package/dist/gates/contract.d.ts.map +1 -1
  95. package/dist/gates/contract.js +9 -0
  96. package/dist/gates/contract.js.map +1 -1
  97. package/dist/gates/decision.d.ts +17 -0
  98. package/dist/gates/decision.d.ts.map +1 -0
  99. package/dist/gates/decision.js +25 -0
  100. package/dist/gates/decision.js.map +1 -0
  101. package/dist/gates/definitions.d.ts +63 -0
  102. package/dist/gates/definitions.d.ts.map +1 -0
  103. package/dist/gates/definitions.js +160 -0
  104. package/dist/gates/definitions.js.map +1 -0
  105. package/dist/gates/effective-gates.d.ts +30 -0
  106. package/dist/gates/effective-gates.d.ts.map +1 -0
  107. package/dist/gates/effective-gates.js +85 -0
  108. package/dist/gates/effective-gates.js.map +1 -0
  109. package/dist/gates/index.d.ts +25 -1
  110. package/dist/gates/index.d.ts.map +1 -1
  111. package/dist/gates/index.js +37 -1
  112. package/dist/gates/index.js.map +1 -1
  113. package/dist/gates/performance.d.ts +8 -2
  114. package/dist/gates/performance.d.ts.map +1 -1
  115. package/dist/gates/performance.js +9 -0
  116. package/dist/gates/performance.js.map +1 -1
  117. package/dist/gates/registry.d.ts +32 -0
  118. package/dist/gates/registry.d.ts.map +1 -0
  119. package/dist/gates/registry.js +90 -0
  120. package/dist/gates/registry.js.map +1 -0
  121. package/dist/gates/review.d.ts +8 -2
  122. package/dist/gates/review.d.ts.map +1 -1
  123. package/dist/gates/review.js +9 -0
  124. package/dist/gates/review.js.map +1 -1
  125. package/dist/gates/runner.d.ts +30 -0
  126. package/dist/gates/runner.d.ts.map +1 -0
  127. package/dist/gates/runner.js +38 -0
  128. package/dist/gates/runner.js.map +1 -0
  129. package/dist/gates/security.d.ts +8 -2
  130. package/dist/gates/security.d.ts.map +1 -1
  131. package/dist/gates/security.js +9 -0
  132. package/dist/gates/security.js.map +1 -1
  133. package/dist/gates/types.d.ts +41 -1
  134. package/dist/gates/types.d.ts.map +1 -1
  135. package/dist/hooks/bootstrap.d.ts.map +1 -1
  136. package/dist/hooks/bootstrap.js +0 -2
  137. package/dist/hooks/bootstrap.js.map +1 -1
  138. package/dist/hooks/config.d.ts +26 -0
  139. package/dist/hooks/config.d.ts.map +1 -0
  140. package/dist/hooks/config.js +30 -0
  141. package/dist/hooks/config.js.map +1 -0
  142. package/dist/hooks/index.d.ts +2 -1
  143. package/dist/hooks/index.d.ts.map +1 -1
  144. package/dist/hooks/index.js +4 -1
  145. package/dist/hooks/index.js.map +1 -1
  146. package/dist/hooks/registry.d.ts +18 -1
  147. package/dist/hooks/registry.d.ts.map +1 -1
  148. package/dist/hooks/registry.js +45 -0
  149. package/dist/hooks/registry.js.map +1 -1
  150. package/dist/hooks/types.d.ts +20 -0
  151. package/dist/hooks/types.d.ts.map +1 -1
  152. package/dist/index.d.ts +8 -8
  153. package/dist/index.d.ts.map +1 -1
  154. package/dist/index.js +13 -21
  155. package/dist/index.js.map +1 -1
  156. package/dist/knowledge/import.d.ts +2 -2
  157. package/dist/knowledge/import.d.ts.map +1 -1
  158. package/dist/knowledge/ingest.js.map +1 -1
  159. package/dist/knowledge/lifecycle-hooks.d.ts +2 -2
  160. package/dist/knowledge/lifecycle-hooks.d.ts.map +1 -1
  161. package/dist/knowledge/types.d.ts +5 -7
  162. package/dist/knowledge/types.d.ts.map +1 -1
  163. package/dist/knowledge/types.js +1 -1
  164. package/dist/knowledge/types.js.map +1 -1
  165. package/dist/monitoring/constraint-doctor.d.ts +4 -22
  166. package/dist/monitoring/constraint-doctor.d.ts.map +1 -1
  167. package/dist/monitoring/constraint-doctor.js +7 -94
  168. package/dist/monitoring/constraint-doctor.js.map +1 -1
  169. package/dist/presets/standard.d.ts +1 -1
  170. package/dist/presets/standard.d.ts.map +1 -1
  171. package/dist/presets/standard.js +1 -2
  172. package/dist/presets/standard.js.map +1 -1
  173. package/dist/spec/annotation-checker.d.ts.map +1 -1
  174. package/dist/spec/annotation-checker.js +6 -26
  175. package/dist/spec/annotation-checker.js.map +1 -1
  176. package/dist/tools/index.d.ts +0 -4
  177. package/dist/tools/index.d.ts.map +1 -1
  178. package/dist/tools/index.js +0 -4
  179. package/dist/tools/index.js.map +1 -1
  180. package/dist/types/constraint.d.ts +1 -12
  181. package/dist/types/constraint.d.ts.map +1 -1
  182. package/dist/types/constraint.js +0 -3
  183. package/dist/types/constraint.js.map +1 -1
  184. package/dist/types/project-config.d.ts +0 -2
  185. package/dist/types/project-config.d.ts.map +1 -1
  186. package/dist/utils/file-walk.d.ts +2 -2
  187. package/dist/utils/file-walk.js +2 -2
  188. package/package.json +9 -4
  189. package/src/CONTEXT.md +14 -0
  190. package/src/__tests__/checker-extra.test.ts +2 -59
  191. package/src/__tests__/constraint-doctor.test.ts +1 -140
  192. package/src/__tests__/constraint-handler.test.ts +0 -4
  193. package/src/__tests__/project-config-loader-extra.test.ts +0 -20
  194. package/src/__tests__/project-config-loader.test.ts +0 -1
  195. package/src/cli/commands/CONTEXT.md +15 -7
  196. package/src/cli/commands/__tests__/analyze-sessions.test.ts +178 -0
  197. package/src/cli/commands/__tests__/check-drift.test.ts +0 -3
  198. package/src/cli/commands/__tests__/check-skip-output.test.ts +0 -5
  199. package/src/cli/commands/__tests__/check.test.ts +7 -75
  200. package/src/cli/commands/__tests__/registry.test.ts +201 -0
  201. package/src/cli/commands/__tests__/release.test.ts +162 -0
  202. package/src/cli/commands/__tests__/update-user-model.test.ts +205 -0
  203. package/src/cli/commands/check.ts +2 -14
  204. package/src/cli/commands/definitions.ts +593 -0
  205. package/src/cli/commands/knowledge.ts +3 -3
  206. package/src/cli/commands/sync-docs/capabilities-syncer.ts +4 -110
  207. package/src/cli/commands/sync-docs/index.ts +8 -5
  208. package/src/cli/commands/update-user-model.ts +15 -5
  209. package/src/context/CONTEXT.md +2 -7
  210. package/src/context/__tests__/session-manager.test.ts +0 -91
  211. package/src/context/index.ts +1 -5
  212. package/src/context/knowledge-injector.ts +3 -3
  213. package/src/context/session-manager.ts +0 -74
  214. package/src/context/types.ts +2 -63
  215. package/src/core/CONTEXT.md +1 -1
  216. package/src/core/constraints/__tests__/agent-prompt-renderer.test.ts +129 -0
  217. package/src/core/constraints/__tests__/check-cache.test.ts +227 -0
  218. package/src/core/constraints/__tests__/interceptor.test.ts +0 -2
  219. package/src/core/constraints/agent-prompt-renderer.ts +71 -0
  220. package/src/core/constraints/capabilities-parser.ts +95 -2
  221. package/src/core/constraints/check-cache.ts +75 -3
  222. package/src/core/constraints/checker.ts +8 -53
  223. package/src/core/constraints/definitions.ts +0 -8
  224. package/src/core/constraints/doc-freshness/runner.ts +1 -2
  225. package/src/core/constraints/index.ts +11 -2
  226. package/src/core/constraints/interceptor.ts +1 -6
  227. package/src/core/effective-constraints.ts +0 -1
  228. package/src/core/project-config-loader.ts +1 -7
  229. package/src/dashboard/stats.ts +2 -2
  230. package/src/dashboard/types.ts +2 -2
  231. package/src/failure/constraint-handler.ts +0 -2
  232. package/src/gates/CONTEXT.md +16 -13
  233. package/src/gates/__tests__/checker-gate.test.ts +45 -0
  234. package/src/gates/__tests__/contract.test.ts +73 -0
  235. package/src/gates/__tests__/effective-gates.test.ts +82 -0
  236. package/src/gates/__tests__/gate-interface.test.ts +202 -0
  237. package/src/gates/__tests__/registry.test.ts +87 -0
  238. package/src/gates/__tests__/runner.test.ts +81 -0
  239. package/src/gates/acceptance.ts +24 -1
  240. package/src/gates/checker-gate.ts +54 -0
  241. package/src/gates/command.ts +13 -2
  242. package/src/gates/contract.ts +12 -2
  243. package/src/gates/decision.ts +27 -0
  244. package/src/gates/definitions.ts +207 -0
  245. package/src/gates/effective-gates.ts +106 -0
  246. package/src/gates/index.ts +38 -0
  247. package/src/gates/performance.ts +12 -2
  248. package/src/gates/registry.ts +107 -0
  249. package/src/gates/review.ts +12 -2
  250. package/src/gates/runner.ts +57 -0
  251. package/src/gates/security.ts +12 -2
  252. package/src/gates/types.ts +48 -1
  253. package/src/hooks/CONTEXT.md +12 -2
  254. package/src/hooks/__tests__/bootstrap.test.ts +0 -1
  255. package/src/hooks/__tests__/config.test.ts +19 -0
  256. package/src/hooks/__tests__/pipeline.test.ts +79 -0
  257. package/src/hooks/__tests__/registry.test.ts +67 -0
  258. package/src/hooks/bootstrap.ts +0 -2
  259. package/src/hooks/config.ts +29 -0
  260. package/src/hooks/index.ts +2 -1
  261. package/src/hooks/registry.ts +60 -1
  262. package/src/hooks/types.ts +21 -0
  263. package/src/index.ts +13 -22
  264. package/src/knowledge/import.ts +3 -3
  265. package/src/knowledge/ingest.ts +4 -4
  266. package/src/knowledge/lifecycle-hooks.ts +3 -3
  267. package/src/knowledge/types.ts +5 -8
  268. package/src/monitoring/constraint-doctor.ts +7 -106
  269. package/src/presets/__tests__/standard.test.ts +0 -2
  270. package/src/presets/standard.ts +1 -2
  271. package/src/spec/__tests__/annotation-checker.test.ts +9 -3
  272. package/src/spec/annotation-checker.ts +7 -29
  273. package/src/tools/CONTEXT.md +7 -14
  274. package/src/tools/index.ts +0 -4
  275. package/src/types/constraint.ts +1 -14
  276. package/src/types/project-config.ts +0 -3
  277. package/src/utils/file-walk.ts +2 -2
  278. package/dist/architecture/constraint-engine.d.ts +0 -67
  279. package/dist/architecture/constraint-engine.d.ts.map +0 -1
  280. package/dist/architecture/constraint-engine.js +0 -295
  281. package/dist/architecture/constraint-engine.js.map +0 -1
  282. package/dist/architecture/cross-project-checker.d.ts +0 -54
  283. package/dist/architecture/cross-project-checker.d.ts.map +0 -1
  284. package/dist/architecture/cross-project-checker.js +0 -467
  285. package/dist/architecture/cross-project-checker.js.map +0 -1
  286. package/dist/cli/commands/index.d.ts +0 -30
  287. package/dist/cli/commands/index.d.ts.map +0 -1
  288. package/dist/cli/commands/index.js +0 -91
  289. package/dist/cli/commands/index.js.map +0 -1
  290. package/dist/context/file-budget.d.ts +0 -40
  291. package/dist/context/file-budget.d.ts.map +0 -1
  292. package/dist/context/file-budget.js +0 -147
  293. package/dist/context/file-budget.js.map +0 -1
  294. package/dist/context/progressive-loader.d.ts +0 -109
  295. package/dist/context/progressive-loader.d.ts.map +0 -1
  296. package/dist/context/progressive-loader.js +0 -166
  297. package/dist/context/progressive-loader.js.map +0 -1
  298. package/dist/context/token-pipeline.d.ts +0 -55
  299. package/dist/context/token-pipeline.d.ts.map +0 -1
  300. package/dist/context/token-pipeline.js +0 -220
  301. package/dist/context/token-pipeline.js.map +0 -1
  302. package/dist/context/tool-output-budget.d.ts +0 -59
  303. package/dist/context/tool-output-budget.d.ts.map +0 -1
  304. package/dist/context/tool-output-budget.js +0 -177
  305. package/dist/context/tool-output-budget.js.map +0 -1
  306. package/dist/core/constraints/default-executors.d.ts +0 -10
  307. package/dist/core/constraints/default-executors.d.ts.map +0 -1
  308. package/dist/core/constraints/default-executors.js +0 -120
  309. package/dist/core/constraints/default-executors.js.map +0 -1
  310. package/dist/llm/adapter.d.ts +0 -36
  311. package/dist/llm/adapter.d.ts.map +0 -1
  312. package/dist/llm/adapter.js +0 -118
  313. package/dist/llm/adapter.js.map +0 -1
  314. package/dist/llm/index.d.ts +0 -3
  315. package/dist/llm/index.d.ts.map +0 -1
  316. package/dist/llm/index.js +0 -19
  317. package/dist/llm/index.js.map +0 -1
  318. package/dist/llm/types.d.ts +0 -62
  319. package/dist/llm/types.d.ts.map +0 -1
  320. package/dist/llm/types.js +0 -8
  321. package/dist/llm/types.js.map +0 -1
  322. package/dist/tools/core/index.d.ts +0 -13
  323. package/dist/tools/core/index.d.ts.map +0 -1
  324. package/dist/tools/core/index.js +0 -198
  325. package/dist/tools/core/index.js.map +0 -1
  326. package/dist/tools/loader.d.ts +0 -21
  327. package/dist/tools/loader.d.ts.map +0 -1
  328. package/dist/tools/loader.js +0 -199
  329. package/dist/tools/loader.js.map +0 -1
  330. package/dist/tools/registry.d.ts +0 -59
  331. package/dist/tools/registry.d.ts.map +0 -1
  332. package/dist/tools/registry.js +0 -115
  333. package/dist/tools/registry.js.map +0 -1
  334. package/dist/tools/types.d.ts +0 -38
  335. package/dist/tools/types.d.ts.map +0 -1
  336. package/dist/tools/types.js +0 -6
  337. package/dist/tools/types.js.map +0 -1
  338. package/src/__tests__/architecture-engine.test.ts +0 -619
  339. package/src/__tests__/context/progressive-loader.test.ts +0 -131
  340. package/src/__tests__/cross-project-checker.test.ts +0 -318
  341. package/src/architecture/CONTEXT.md +0 -22
  342. package/src/architecture/constraint-engine.ts +0 -351
  343. package/src/architecture/cross-project-checker.ts +0 -545
  344. package/src/cli/commands/index.ts +0 -30
  345. package/src/context/__tests__/file-budget.test.ts +0 -142
  346. package/src/context/__tests__/progressive-loader.test.ts +0 -264
  347. package/src/context/__tests__/token-pipeline.test.ts +0 -178
  348. package/src/context/__tests__/tool-output-budget.test.ts +0 -95
  349. package/src/context/file-budget.ts +0 -142
  350. package/src/context/progressive-loader.ts +0 -260
  351. package/src/context/token-pipeline.ts +0 -265
  352. package/src/context/tool-output-budget.ts +0 -178
  353. package/src/core/constraints/__tests__/default-executors.test.ts +0 -57
  354. package/src/core/constraints/default-executors.ts +0 -92
  355. package/src/llm/CONTEXT.md +0 -21
  356. package/src/llm/__tests__/adapter.test.ts +0 -172
  357. package/src/llm/adapter.ts +0 -149
  358. package/src/llm/index.ts +0 -2
  359. package/src/llm/types.ts +0 -81
  360. package/src/tools/__tests__/loader.test.ts +0 -252
  361. package/src/tools/__tests__/registry.test.ts +0 -157
  362. package/src/tools/core/__tests__/core.test.ts +0 -122
  363. package/src/tools/core/index.ts +0 -201
  364. package/src/tools/loader.ts +0 -216
  365. package/src/tools/registry.ts +0 -128
  366. package/src/tools/types.ts +0 -46
@@ -1,18 +1,14 @@
1
1
  /**
2
- * CAPABILITIES.md 同步器(工单 22)
2
+ * CAPABILITIES.md 文件表格同步器(工单 22)
3
3
  *
4
- * 支持两种格式:
5
- * - 文件表格格式:模块/文件/说明三列表格,增删行维护
6
- * - 能力清单格式:计数行(CLI Commands (N) 等),FreshnessRunner 校验与刷新
4
+ * 只负责文件表格格式:模块/文件/说明三列表格,增删行维护。
5
+ * 能力清单格式(计数行)的解析与计数已收敛到 core/constraints/capabilities-parser(H2 O10-R3)。
7
6
  */
8
7
 
9
8
  import * as fs from 'fs/promises';
10
9
  import * as path from 'path';
11
- import { IRON_LAWS, GUIDELINES, TIPS } from '../../../core/constraints/definitions';
12
- import { isCapabilityListingFormat, readCapabilitiesEntries } from '../../../core/constraints/capabilities-parser';
13
- import { FreshnessRunner } from '../../../core/constraints/doc-freshness/runner';
10
+ import { readCapabilitiesEntries } from '../../../core/constraints/capabilities-parser';
14
11
  import type { CapabilitiesMode } from '../../../core/project-config-loader';
15
- import type { DocFreshnessCheck } from '../../../types/project-config';
16
12
  import type { ModuleInfo, SyncResult } from './project-reader';
17
13
 
18
14
  /**
@@ -33,108 +29,6 @@ export async function parseCapabilitiesFiles(capabilitiesPath: string): Promise<
33
29
  return files;
34
30
  }
35
31
 
36
- /**
37
- * 检测 CAPABILITIES.md 是否使用能力清单格式(计数行),而非文件表格格式
38
- *
39
- * @deprecated 实现已收敛到 core/constraints/capabilities-parser(与工单 19-B 同方向),
40
- * 此处保留 re-export 兼容现有调用方
41
- */
42
- export { isCapabilityListingFormat };
43
-
44
- /**
45
- * 构建 CAPABILITIES.md 能力清单格式的检查配置
46
- */
47
- function buildCapabilityChecks(): DocFreshnessCheck[] {
48
- return [
49
- {
50
- type: 'doc_regex_count',
51
- doc: 'CAPABILITIES.md',
52
- label: 'CLI Commands',
53
- pattern: 'CLI Commands\\s*\\((\\d+)\\)',
54
- actual: { kind: 'dir_count', path: 'src/cli/commands', extension: '.ts', exclude: ['index.ts'] },
55
- },
56
- {
57
- type: 'doc_regex_count',
58
- doc: 'CAPABILITIES.md',
59
- label: 'Quality Gates',
60
- pattern: 'Quality Gates?\\s*\\((\\d+)\\)',
61
- actual: { kind: 'dir_count', path: 'src/gates', extension: '.ts', exclude: ['index.ts', 'types.ts'] },
62
- },
63
- {
64
- type: 'doc_regex_count',
65
- doc: 'CAPABILITIES.md',
66
- label: 'Iron Laws',
67
- pattern: 'Iron Laws?\\s*\\((\\d+)\\)',
68
- actual: { kind: 'const_count', value: Object.keys(IRON_LAWS).length },
69
- },
70
- {
71
- type: 'doc_regex_count',
72
- doc: 'CAPABILITIES.md',
73
- label: 'Guidelines',
74
- pattern: 'Guidelines?\\s*\\((\\d+)\\)',
75
- actual: { kind: 'const_count', value: Object.keys(GUIDELINES).length },
76
- },
77
- {
78
- type: 'doc_regex_count',
79
- doc: 'CAPABILITIES.md',
80
- label: 'Tips',
81
- pattern: 'Tips?\\s*\\((\\d+)\\)',
82
- actual: { kind: 'const_count', value: Object.keys(TIPS).length },
83
- },
84
- ];
85
- }
86
-
87
- /**
88
- * 使用 FreshnessRunner 检查能力清单计数是否与代码一致(--check 模式)
89
- */
90
- export function checkCapabilityCounts(
91
- projectPath: string
92
- ): { match: boolean; mismatches: string[] } {
93
- const runner = new FreshnessRunner();
94
- const checks = buildCapabilityChecks();
95
- const results = runner.runAll({ checks }, projectPath);
96
-
97
- const mismatches: string[] = [];
98
- for (const r of results) {
99
- if (!r.pass && r.message) {
100
- mismatches.push(r.message);
101
- }
102
- }
103
-
104
- return { match: mismatches.length === 0, mismatches };
105
- }
106
-
107
- /**
108
- * 更新 CAPABILITIES.md 中的能力清单计数(write 模式)
109
- *
110
- * 使用 FreshnessRunner 获取实际计数,然后 regex 替换文档计数行。
111
- */
112
- export function updateCapabilityCounts(content: string, projectPath: string): string {
113
- const runner = new FreshnessRunner();
114
-
115
- const cliCount = runner.countFromDir('src/cli/commands', '.ts', ['index.ts'], projectPath);
116
- const gateCount = runner.countFromDir('src/gates', '.ts', ['index.ts', 'types.ts'], projectPath);
117
- const ironCount = Object.keys(IRON_LAWS).length;
118
- const guideCount = Object.keys(GUIDELINES).length;
119
- const tipsCount = Object.keys(TIPS).length;
120
-
121
- const replacements: [RegExp, string][] = [
122
- [/CLI Commands\s*\(\d+\)/, `CLI Commands (${cliCount})`],
123
- [/Quality Gates?\s*\(\d+\)/, `Quality Gates (${gateCount})`],
124
- [/Iron Laws?\s*\(\d+\)/, `Iron Laws (${ironCount})`],
125
- [/Guidelines?\s*\(\d+\)/, `Guidelines (${guideCount})`],
126
- [/Tips?\s*\(\d+\)/, `Tips (${tipsCount})`],
127
- ];
128
-
129
- for (const [regex, replacement] of replacements) {
130
- if (regex.test(content)) {
131
- content = content.replace(regex, replacement);
132
- }
133
- }
134
-
135
- return content;
136
- }
137
-
138
32
  /**
139
33
  * 更新 CAPABILITIES.md 文件
140
34
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * 实现拆分:
8
8
  * - project-reader.ts 项目信息读取(package.json/config.yml/源码扫描)
9
- * - capabilities-syncer.ts CAPABILITIES.md 两种格式的对比与维护
9
+ * - capabilities-syncer.ts CAPABILITIES.md 文件表格格式的对比与维护(能力清单格式解析/计数走 core/constraints/capabilities-parser)
10
10
  * - context-syncer.ts CONTEXT.md 模板生成/发现/过时判定
11
11
  * - agents-syncer.ts AGENTS.md 生成
12
12
  * - preserve-block.ts PRESERVE 标记块提取与组合
@@ -16,16 +16,19 @@ import chalk from 'chalk';
16
16
  import * as fs from 'fs/promises';
17
17
  import { existsSync } from 'fs';
18
18
  import * as path from 'path';
19
- import { aggregateToSourceSubdir, readCapabilitiesEntries } from '../../../core/constraints/capabilities-parser';
19
+ import {
20
+ aggregateToSourceSubdir,
21
+ readCapabilitiesEntries,
22
+ isCapabilityListingFormat,
23
+ checkCapabilityCounts,
24
+ updateCapabilityCounts,
25
+ } from '../../../core/constraints/capabilities-parser';
20
26
  import { detectSourceRoots } from '../../../utils/detect-source-roots';
21
27
  import { getCapabilitiesMode } from '../../../core/project-config-loader';
22
28
  import { getSourceDirs, scanSourceModules, getRequiredContextDirs } from './project-reader';
23
29
  import type { ModuleInfo, SyncResult } from './project-reader';
24
30
  import {
25
31
  parseCapabilitiesFiles,
26
- isCapabilityListingFormat,
27
- checkCapabilityCounts,
28
- updateCapabilityCounts,
29
32
  updateCapabilitiesFile,
30
33
  compactCapabilitiesContent,
31
34
  } from './capabilities-syncer';
@@ -28,6 +28,7 @@ import {
28
28
  } from '../session-mining';
29
29
 
30
30
  export interface UpdateUserModelOptions {
31
+ days?: number; // 只处理最近 N 天(自然日,含今天)的会话;缺省不过滤(向后兼容)
31
32
  json?: boolean;
32
33
  dryRun?: boolean; // don't update state, just show what would change
33
34
  }
@@ -58,7 +59,7 @@ export async function updateUserModel(options: UpdateUserModelOptions): Promise<
58
59
  const state = loadState();
59
60
 
60
61
  // 2. Scan new data
61
- const newSessions = findNewSessions(transcriptDir, state.sessionsProcessed);
62
+ const newSessions = findNewSessions(transcriptDir, state.sessionsProcessed, options.days);
62
63
  if (newSessions.length === 0) {
63
64
  console.log(chalk.gray('No new sessions to process'));
64
65
  return;
@@ -137,10 +138,19 @@ interface SimpleSession {
137
138
  toolCalls: string[]; // tool names used
138
139
  }
139
140
 
140
- function findNewSessions(dir: string, processed: string[]): SimpleSession[] {
141
- const sessions = readTranscriptSessions(dir)
142
- .filter(s => !processed.includes(s.id))
143
- .sort((a, b) => a.date.localeCompare(b.date));
141
+ function findNewSessions(dir: string, processed: string[], days?: number): SimpleSession[] {
142
+ let sessions = readTranscriptSessions(dir)
143
+ .filter(s => !processed.includes(s.id));
144
+
145
+ // 「最近 N 天」:自然日窗口(含今天)。days<=0 视为不过滤,与缺省一致。
146
+ if (days !== undefined && days > 0) {
147
+ const cutoff = new Date(Date.now() - (days - 1) * 86_400_000)
148
+ .toISOString()
149
+ .slice(0, 10);
150
+ sessions = sessions.filter(s => s.date >= cutoff);
151
+ }
152
+
153
+ sessions.sort((a, b) => a.date.localeCompare(b.date));
144
154
 
145
155
  return sessions.map(s => ({
146
156
  id: s.id,
@@ -1,15 +1,11 @@
1
1
  # context/
2
2
 
3
3
  ## 职责
4
- 上下文管理:Token 预算(多级分配)、渐进式加载(worker pool 并发)、文件/工具输出预算、会话压缩、Token 流水线、知识注入。
4
+ 上下文管理:Token 预算(多级分配)、会话压缩、会话管理、知识注入。
5
5
 
6
6
  ## 核心导出
7
7
  - `TokenBudget` — 多级 token 预算(system/user/tool/reserve)
8
- - `ProgressiveLoader` — 渐进式加载 + worker pool 并发
9
- - `FileBudget` — 文件级 token 预算
10
- - `ToolOutputBudget` — 工具输出 token 预算
11
8
  - `Compaction` — 会话压缩(摘要/截断/滑动窗口)
12
- - `TokenPipeline` — Token 流水线
13
9
  - `SessionManager` — 会话管理
14
10
  - `KnowledgeInjector` — 知识注入引擎
15
11
 
@@ -20,9 +16,8 @@
20
16
 
21
17
  ## 约定
22
18
  - Token 预算策略由配置文件控制
23
- - 渐进式加载保证输入顺序(worker pool 模式)
24
19
  - 会话压缩策略可组合
25
20
 
26
21
  ## 注意事项
27
- - Phase 2 实现的 Token 流水线 + 预算 + 压缩
28
22
  - 零 Token 成本:纯计算,不调用 LLM
23
+ - Phase 2 前瞻的渐进式加载/Token 流水线/文件与工具输出预算已随 H1(#40)删除
@@ -81,50 +81,6 @@ describe('SessionManager', () => {
81
81
  });
82
82
  });
83
83
 
84
- describe('getWindowView', () => {
85
- it('应该生成窗口视图', () => {
86
- manager.createSession('session-1');
87
- manager.appendToSession('session-1', {
88
- type: 'system',
89
- id: 'sys-1',
90
- content: 'You are helpful.',
91
- timestamp: 't1',
92
- });
93
- manager.appendToSession('session-1', {
94
- type: 'user_message',
95
- id: 'msg-1',
96
- content: 'Hello',
97
- timestamp: 't2',
98
- });
99
-
100
- const output = manager.getWindowView('session-1', {
101
- total: 8000,
102
- systemPrompt: 1000,
103
- toolDefinitions: 500,
104
- knowledge: 600,
105
- notes: 300,
106
- history: 5600,
107
- });
108
-
109
- expect(output.prompt).toContain('You are helpful.');
110
- expect(output.prompt).toContain('Hello');
111
- expect(output.snapshot).toBeDefined();
112
- });
113
-
114
- it('应该抛出当会话不存在', () => {
115
- expect(() => {
116
- manager.getWindowView('nonexistent', {
117
- total: 8000,
118
- systemPrompt: 1000,
119
- toolDefinitions: 500,
120
- knowledge: 600,
121
- notes: 300,
122
- history: 5600,
123
- });
124
- }).toThrow('不存在');
125
- });
126
- });
127
-
128
84
  describe('checkpointSession', () => {
129
85
  it('应该生成 checkpoint', () => {
130
86
  manager.createSession('session-1');
@@ -250,51 +206,4 @@ describe('SessionManager', () => {
250
206
  });
251
207
  });
252
208
 
253
- describe('getWindowView with all event types', () => {
254
- it('handles all event types through eventsToSources', () => {
255
- manager.createSession('session-event-types');
256
- manager.appendToSession('session-event-types', {
257
- type: 'system',
258
- id: 'sys-1',
259
- content: 'System prompt',
260
- timestamp: 't1',
261
- });
262
- manager.appendToSession('session-event-types', {
263
- type: 'assistant_message',
264
- id: 'asst-1',
265
- content: 'I will help',
266
- timestamp: 't2',
267
- });
268
- manager.appendToSession('session-event-types', {
269
- type: 'tool_call',
270
- id: 'tool-1',
271
- content: 'run test',
272
- timestamp: 't3',
273
- });
274
- manager.appendToSession('session-event-types', {
275
- type: 'tool_result',
276
- id: 'tool-2',
277
- content: 'test output',
278
- timestamp: 't4',
279
- });
280
- manager.appendToSession('session-event-types', {
281
- type: 'checkpoint',
282
- id: 'cp-1',
283
- content: 'session summary',
284
- timestamp: 't5',
285
- });
286
-
287
- const output = manager.getWindowView('session-event-types', {
288
- total: 8000,
289
- systemPrompt: 1000,
290
- toolDefinitions: 500,
291
- knowledge: 600,
292
- notes: 300,
293
- history: 5600,
294
- });
295
-
296
- expect(output).toBeDefined();
297
- expect(output.prompt).toBeDefined();
298
- });
299
- });
300
209
  });
@@ -1,15 +1,11 @@
1
1
  /**
2
2
  * 上下文管理模块
3
3
  *
4
- * Phase 2: Token 流水线 + 预算 + 压缩
4
+ * Token 预算 + 会话压缩 + 知识注入
5
5
  */
6
6
 
7
7
  export * from './types';
8
8
  export * from './token-budget';
9
- export * from './progressive-loader';
10
- export * from './file-budget';
11
- export * from './tool-output-budget';
12
9
  export * from './compaction';
13
- export * from './token-pipeline';
14
10
  export * from './session-manager';
15
11
  export * from './knowledge-injector';
@@ -1,20 +1,20 @@
1
1
  /**
2
2
  * 知识注入器
3
3
  *
4
- * 将知识条目转换为 ContextSource,注入到 TokenPipeline 的 P3 位置
4
+ * 将知识条目转换为 ContextSource,供上层上下文组装消费
5
5
  * 支持按阶段预算、类型过滤、去重
6
6
  */
7
7
 
8
8
  import { KnowledgeQuery } from '../knowledge/query';
9
9
  import { TokenEstimator } from './token-budget';
10
- import type { KnowledgeEntry, KnowledgeType } from '../knowledge/types';
10
+ import type { KnowledgeEntry, KnowledgeSubsystem } from '../knowledge/types';
11
11
  import type { ContextSource } from './types';
12
12
 
13
13
  export interface InjectionConfig {
14
14
  /** Token 预算(默认 800) */
15
15
  budget: number;
16
16
  /** 关注的知识类型 */
17
- focusTypes?: KnowledgeType[];
17
+ focusTypes?: KnowledgeSubsystem[];
18
18
  /** 当前阶段 */
19
19
  phase?: string;
20
20
  /** 已注入的条目 ID(去重) */
@@ -8,26 +8,20 @@
8
8
 
9
9
  import * as fs from 'fs';
10
10
  import * as path from 'path';
11
- import { TokenPipeline } from './token-pipeline';
12
11
  import { ContextTracker } from '../monitoring/context-tracker';
13
12
  import type {
14
13
  SessionEvent,
15
14
  SessionHandle,
16
15
  SessionCheckpoint,
17
- TokenBudgetAllocation,
18
- PipelineOutput,
19
- ContextSource,
20
16
  } from './types';
21
17
 
22
18
  export class SessionManager {
23
19
  private basePath: string;
24
20
  private sessions: Map<string, SessionHandle> = new Map();
25
- private pipeline: TokenPipeline;
26
21
  private tracker: ContextTracker;
27
22
 
28
23
  constructor(basePath?: string) {
29
24
  this.basePath = basePath || process.cwd();
30
- this.pipeline = new TokenPipeline();
31
25
  this.tracker = new ContextTracker(this.basePath);
32
26
  }
33
27
 
@@ -139,29 +133,6 @@ export class SessionManager {
139
133
  this.appendEvent(id, event);
140
134
  }
141
135
 
142
- /**
143
- * 获取当前轮窗口视图(自动从磁盘加载,S2)
144
- *
145
- * 将 session 事件转换为 ContextSource,通过 TokenPipeline 生成 prompt
146
- */
147
- getWindowView(id: string, budget: TokenBudgetAllocation): PipelineOutput {
148
- const handle = this.getSession(id);
149
- if (!handle) {
150
- throw new Error(`会话 ${id} 不存在`);
151
- }
152
-
153
- // 将事件转换为 ContextSource
154
- const sources = this.eventsToSources(handle.events);
155
-
156
- // 通过 pipeline 生成窗口视图
157
- const output = this.pipeline.run({ sources, budget });
158
-
159
- // 记录快照
160
- this.tracker.record(output.snapshot);
161
-
162
- return output;
163
- }
164
-
165
136
  /**
166
137
  * 生成 checkpoint(自动从磁盘加载,S2)
167
138
  */
@@ -242,51 +213,6 @@ export class SessionManager {
242
213
  return this.tracker;
243
214
  }
244
215
 
245
- /**
246
- * 将事件转换为 ContextSource
247
- */
248
- private eventsToSources(events: SessionEvent[]): ContextSource[] {
249
- return events.map(event => {
250
- let priority: number;
251
- let type: ContextSource['type'];
252
-
253
- switch (event.type) {
254
- case 'system':
255
- priority = 1;
256
- type = 'system_prompt';
257
- break;
258
- case 'user_message':
259
- priority = 6;
260
- type = 'user_message';
261
- break;
262
- case 'assistant_message':
263
- priority = 5;
264
- type = 'session_event';
265
- break;
266
- case 'tool_call':
267
- case 'tool_result':
268
- priority = 5;
269
- type = 'tool_output';
270
- break;
271
- case 'checkpoint':
272
- priority = 4;
273
- type = 'session_event';
274
- break;
275
- default:
276
- priority = 5;
277
- type = 'session_event';
278
- }
279
-
280
- return {
281
- type,
282
- id: event.id,
283
- content: event.content,
284
- priority,
285
- metadata: event.metadata,
286
- };
287
- });
288
- }
289
-
290
216
  /**
291
217
  * 生成 checkpoint 摘要
292
218
  */
@@ -1,49 +1,9 @@
1
1
  /**
2
2
  * 上下文管理类型定义
3
3
  *
4
- * Phase 2: Token 流水线 + 预算 + 压缩
4
+ * Token 预算 + 会话压缩 + 会话管理 + 知识注入
5
5
  */
6
6
 
7
- import type { QueryResult } from '../knowledge/types';
8
-
9
- // ========================================
10
- // 文件读取预算
11
- // ========================================
12
-
13
- export interface FileBudgetConfig {
14
- maxLines: number; // 默认 2000
15
- maxBytes: number; // 默认 50KB (51200)
16
- maxTokenEstimate: number; // 默认 8000
17
- continuationHint: boolean; // 默认 true
18
- }
19
-
20
- export const DEFAULT_FILE_BUDGET: FileBudgetConfig = {
21
- maxLines: 2000,
22
- maxBytes: 51200,
23
- maxTokenEstimate: 8000,
24
- continuationHint: true,
25
- };
26
-
27
- // ========================================
28
- // 工具输出预算
29
- // ========================================
30
-
31
- export interface ToolOutputBudgetConfig {
32
- maxChars: number; // 默认 16000
33
- maxTokenRatio: number; // 默认 0.3 (占总预算 30%)
34
- previewLines: number; // 默认 50
35
- overflowToDisk: boolean; // 默认 false
36
- dedup: boolean; // 默认 true
37
- }
38
-
39
- export const DEFAULT_TOOL_OUTPUT_BUDGET: ToolOutputBudgetConfig = {
40
- maxChars: 16000,
41
- maxTokenRatio: 0.3,
42
- previewLines: 50,
43
- overflowToDisk: false,
44
- dedup: true,
45
- };
46
-
47
7
  // ========================================
48
8
  // 会话压缩
49
9
  // ========================================
@@ -76,7 +36,7 @@ export interface SessionMessage {
76
36
  }
77
37
 
78
38
  // ========================================
79
- // Token Pipeline
39
+ // 上下文来源
80
40
  // ========================================
81
41
 
82
42
  export type ContextSourceType = 'session_event' | 'tool_output' | 'knowledge' | 'user_message' | 'system_prompt' | 'tool_definition';
@@ -89,27 +49,6 @@ export interface ContextSource {
89
49
  metadata?: Record<string, any>;
90
50
  }
91
51
 
92
- export interface TokenBudgetAllocation {
93
- total: number;
94
- systemPrompt: number; // 固定,不压缩
95
- toolDefinitions: number; // 按需懒加载
96
- knowledge: number; // 500-800
97
- notes: number; // 200-500
98
- history: number; // 剩余预算
99
- }
100
-
101
- export interface PipelineInput {
102
- sources: ContextSource[];
103
- budget: TokenBudgetAllocation;
104
- knowledge?: QueryResult;
105
- }
106
-
107
- export interface PipelineOutput {
108
- prompt: string;
109
- snapshot: ContextUsageSnapshot;
110
- dropped: Array<{ type: string; id: string; reason: string }>;
111
- }
112
-
113
52
  // ========================================
114
53
  // 上下文使用快照
115
54
  // ========================================
@@ -4,7 +4,7 @@
4
4
  约束引擎核心:check/prompt 二元约束系统(ADR-0001)、生效集合并(effective-constraints)、检查点验证器(CSO/passes-gate)、会话管理、Spec 验证器、项目配置加载。
5
5
 
6
6
  ## 核心导出
7
- - `constraints/` — 约束定义(IRON_LAWS/GUIDELINES/PROMPTS;TIPS 已退役为空表) + 检查引擎(ConstraintChecker) + 拦截器(ConstraintInterceptor) + 缓存(CheckCache) + 注入渲染(injection-renderer)/漂移校验(injection-drift)/使用统计(usage-report)
7
+ - `constraints/` — 约束定义(IRON_LAWS/GUIDELINES/PROMPTS;TIPS 已退役为空表) + 检查引擎(ConstraintChecker) + 拦截器(ConstraintInterceptor) + 缓存(CheckCache:TTL 缓存 + 计数采样,H6/G5 起公开导出) + 注入渲染(injection-renderer) + Agent prompt 渲染(agent-prompt-renderer:trigger 参数化分组渲染,role 路由留 studio,H6/G6)/漂移校验(injection-drift)/使用统计(usage-report)
8
8
  - `effective-constraints.ts` — `getEffectiveConstraints(projectRoot)`:全仓唯一生效集来源(内置 → preset → config.yml 禁用(内置与 custom 同效)→ custom 追加(禁用/已退役的不追加)→ scenes 过滤);`lintEffectiveConfig` 配置诊断
9
9
  - `validators/` — checkpoints、passes-gate、CSO 验证器
10
10
  - `session/` — 会话管理