@winspan/claude-forge 8.51.1 → 8.54.3

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 (409) hide show
  1. package/DEVELOPMENT.md +290 -221
  2. package/README.md +50 -8
  3. package/dist/cli/commands/skills.d.ts.map +1 -1
  4. package/dist/cli/commands/skills.js +121 -2
  5. package/dist/cli/commands/skills.js.map +1 -1
  6. package/dist/cli/init/hook-manager.d.ts +1 -1
  7. package/dist/cli/init/hook-manager.d.ts.map +1 -1
  8. package/dist/cli/init/hook-manager.js +1 -0
  9. package/dist/cli/init/hook-manager.js.map +1 -1
  10. package/dist/core/constants.d.ts +2 -0
  11. package/dist/core/constants.d.ts.map +1 -1
  12. package/dist/core/constants.js +4 -0
  13. package/dist/core/constants.js.map +1 -1
  14. package/dist/core/storage/events.d.ts.map +1 -1
  15. package/dist/core/storage/events.js +0 -1
  16. package/dist/core/storage/events.js.map +1 -1
  17. package/dist/core/storage/maintenance.d.ts +25 -3
  18. package/dist/core/storage/maintenance.d.ts.map +1 -1
  19. package/dist/core/storage/maintenance.js +33 -4
  20. package/dist/core/storage/maintenance.js.map +1 -1
  21. package/dist/core/storage/routing.d.ts +4 -0
  22. package/dist/core/storage/routing.d.ts.map +1 -1
  23. package/dist/core/storage/routing.js +10 -4
  24. package/dist/core/storage/routing.js.map +1 -1
  25. package/dist/core/storage/sessions.d.ts +17 -0
  26. package/dist/core/storage/sessions.d.ts.map +1 -1
  27. package/dist/core/storage/sessions.js +64 -0
  28. package/dist/core/storage/sessions.js.map +1 -1
  29. package/dist/core/storage/skills.d.ts +4 -0
  30. package/dist/core/storage/skills.d.ts.map +1 -1
  31. package/dist/core/storage/skills.js +10 -2
  32. package/dist/core/storage/skills.js.map +1 -1
  33. package/dist/core/storage/sqlite.d.ts +5 -0
  34. package/dist/core/storage/sqlite.d.ts.map +1 -1
  35. package/dist/core/storage/sqlite.js +6 -0
  36. package/dist/core/storage/sqlite.js.map +1 -1
  37. package/dist/core/storage/tasks.d.ts.map +1 -1
  38. package/dist/core/storage/tasks.js +2 -0
  39. package/dist/core/storage/tasks.js.map +1 -1
  40. package/dist/core/types.d.ts +7 -0
  41. package/dist/core/types.d.ts.map +1 -1
  42. package/dist/daemon/index.d.ts.map +1 -1
  43. package/dist/daemon/index.js +30 -5
  44. package/dist/daemon/index.js.map +1 -1
  45. package/dist/daemon/skill-sync.d.ts +21 -0
  46. package/dist/daemon/skill-sync.d.ts.map +1 -0
  47. package/dist/daemon/skill-sync.js +75 -0
  48. package/dist/daemon/skill-sync.js.map +1 -0
  49. package/dist/hooks/notification.sh +1 -1
  50. package/dist/hooks/post-tool-use.sh +1 -1
  51. package/dist/hooks/pre-tool-use.sh +1 -1
  52. package/dist/hooks/stop.sh +1 -1
  53. package/dist/hooks/user-prompt-submit.sh +1 -1
  54. package/dist/skills/official/code-simplifier.md +37 -1
  55. package/dist/skills/official/find-skills.md +120 -1
  56. package/dist/skills/official/official-api-design.md +14 -1
  57. package/dist/skills/official/official-architecture-decision.md +22 -1
  58. package/dist/skills/official/official-db-schema-design.md +19 -1
  59. package/dist/skills/official/official-debug.md +9 -1
  60. package/dist/skills/official/official-pr-review.md +1 -1
  61. package/dist/skills/official/official-security-hardening.md +7 -1
  62. package/dist/skills/official/planning-with-files.md +206 -2
  63. package/dist/skills/official/ui-ux-pro-max.md +88 -1
  64. package/dist/skills/official/webapp-testing.md +85 -1
  65. package/dist/skills/registry.d.ts +1 -1
  66. package/dist/skills/registry.d.ts.map +1 -1
  67. package/dist/skills/registry.js +15 -4
  68. package/dist/skills/registry.js.map +1 -1
  69. package/dist/skills/semantic-matcher.d.ts +4 -3
  70. package/dist/skills/semantic-matcher.d.ts.map +1 -1
  71. package/dist/skills/semantic-matcher.js +20 -22
  72. package/dist/skills/semantic-matcher.js.map +1 -1
  73. package/dist/skills/upgrade-engine.d.ts +93 -0
  74. package/dist/skills/upgrade-engine.d.ts.map +1 -0
  75. package/dist/skills/upgrade-engine.js +447 -0
  76. package/dist/skills/upgrade-engine.js.map +1 -0
  77. package/dist/skills/upgrade-prompt.d.ts +20 -0
  78. package/dist/skills/upgrade-prompt.d.ts.map +1 -0
  79. package/dist/skills/upgrade-prompt.js +75 -0
  80. package/dist/skills/upgrade-prompt.js.map +1 -0
  81. package/dist/web/analytics/weekly-report.d.ts.map +1 -1
  82. package/dist/web/analytics/weekly-report.js +21 -29
  83. package/dist/web/analytics/weekly-report.js.map +1 -1
  84. package/dist/web/routes/patch.d.ts.map +1 -1
  85. package/dist/web/routes/patch.js +32 -2
  86. package/dist/web/routes/patch.js.map +1 -1
  87. package/dist/web/routes/sessions.d.ts.map +1 -1
  88. package/dist/web/routes/sessions.js +9 -7
  89. package/dist/web/routes/sessions.js.map +1 -1
  90. package/dist/web/routes/trace.d.ts.map +1 -1
  91. package/dist/web/routes/trace.js +2 -3
  92. package/dist/web/routes/trace.js.map +1 -1
  93. package/dist/web/server.d.ts.map +1 -1
  94. package/dist/web/server.js +3 -2
  95. package/dist/web/server.js.map +1 -1
  96. package/package.json +12 -2
  97. package/scripts/postinstall.cjs +21 -0
  98. package/.claude/CLAUDE.md +0 -17
  99. package/.eslintrc.js +0 -23
  100. package/.prettierrc +0 -8
  101. package/ARCHITECTURE_ISSUES.md +0 -249
  102. package/CLAUDE.md +0 -265
  103. package/CLAUDE.md.backup +0 -488
  104. package/docs/concurrent-agents.md +0 -129
  105. package/docs/design/architecture-review-20260516.md +0 -232
  106. package/docs/design/fix-skills-data-and-set-leak-spec-20260516-1300.md +0 -219
  107. package/docs/design/h1-storage-aggregation-spec-20260518-1121.md +0 -299
  108. package/docs/design/h2-getdatabase-encapsulation-spec-20260518-1450.md +0 -191
  109. package/docs/design/h3-fallback-removal-spec-20260518-1245.md +0 -76
  110. package/docs/design/h4-index-dedup-spec-20260518-1230.md +0 -109
  111. package/docs/design/h6-services-migration-spec-20260518-1355.md +0 -82
  112. package/docs/design/hook-failure-queue-spec-20260516-1530.md +0 -204
  113. package/docs/design/l1-swarm-protocol-extract-spec-20260518-1605.md +0 -106
  114. package/docs/design/m10-forge-paths-spec-20260518-1320.md +0 -121
  115. package/docs/design/m2-m3-tool-input-spec-20260518-1425.md +0 -131
  116. package/docs/design/m7-routing-event-association-spec-20260518-1545.md +0 -103
  117. package/docs/design/project-path-gitroot-spec-20260518-1715.md +0 -134
  118. package/docs/design/refactor-phase1-spec-20260515-1600.md +0 -543
  119. package/docs/design/refactor-phase2-spec-20260515-1700.md +0 -424
  120. package/docs/design/task-active-gc-spec-20260518-1745.md +0 -146
  121. package/docs/design/tasks-list-filter-pagination-spec-20260518-0930.md +0 -208
  122. package/docs/implementation/fix-skills-data-and-set-leak-changelog-20260516-1300.md +0 -104
  123. package/docs/implementation/h1-storage-aggregation-changelog-20260518-1121.md +0 -82
  124. package/docs/implementation/h2-final-changelog-20260518-1530.md +0 -61
  125. package/docs/implementation/h2-phase1-safety-net-changelog-20260518-1450.md +0 -70
  126. package/docs/implementation/h2-phase2-operations-changelog-20260518-1450.md +0 -120
  127. package/docs/implementation/h2-phase3-callsites-changelog-20260518-1450.md +0 -71
  128. package/docs/implementation/h3-fallback-removal-changelog-20260518-1245.md +0 -71
  129. package/docs/implementation/h4-index-dedup-changelog-20260518-1230.md +0 -60
  130. package/docs/implementation/h6-services-migration-changelog-20260518-1355.md +0 -46
  131. package/docs/implementation/h7-m9-defaults-changelog-20260518-1300.md +0 -46
  132. package/docs/implementation/hook-failure-queue-changelog-20260516-1530.md +0 -196
  133. package/docs/implementation/hotfix-daemon-event-reject-20260516-1430.md +0 -56
  134. package/docs/implementation/l1-swarm-protocol-extract-changelog-20260518-1605.md +0 -45
  135. package/docs/implementation/l3-l4-daemon-perf-changelog-20260518-1410.md +0 -63
  136. package/docs/implementation/l6-l8-final-cleanup-changelog-20260518-1640.md +0 -38
  137. package/docs/implementation/m1-m4-m5-l7-cleanup-changelog-20260518-1310.md +0 -58
  138. package/docs/implementation/m10-forge-paths-changelog-20260518-1320.md +0 -60
  139. package/docs/implementation/m2-m3-tool-input-changelog-20260518-1425.md +0 -43
  140. package/docs/implementation/m6-m8-naming-shutdown-changelog-20260518-1340.md +0 -56
  141. package/docs/implementation/m7-routing-association-changelog-20260518-1545.md +0 -69
  142. package/docs/implementation/project-path-gitroot-changelog-20260518-1715.md +0 -63
  143. package/docs/implementation/refactor-phase1-changelog-20260515-1630.md +0 -354
  144. package/docs/implementation/refactor-phase2-changelog-20260515-1705.md +0 -421
  145. package/docs/implementation/task-active-gc-changelog-20260518-1745.md +0 -35
  146. package/docs/implementation/task-title-summary-changelog-20260518-1130.md +0 -39
  147. package/docs/implementation/tasks-detail-back-loses-filters-changelog-20260518-1100.md +0 -22
  148. package/docs/implementation/tasks-list-filter-pagination-changelog-20260518-0930.md +0 -72
  149. package/docs/implementation/tasks-page-white-screen-hotfix-changelog-20260518-1015.md +0 -56
  150. package/docs/reviews/claudemd-template-sync.md +0 -54
  151. package/docs/reviews/task-title-summary.md +0 -92
  152. package/docs/reviews/tasks-detail-back-loses-filters.md +0 -58
  153. package/docs/reviews/tasks-filter-pagination.md +0 -80
  154. package/docs/reviews/tasks-page-white-screen-hotfix.md +0 -126
  155. package/docs/ruflo-learning-strategy.md +0 -322
  156. package/docs/skills-deduplication-analysis.md +0 -83
  157. package/docs/skills-multiformat-support.md +0 -177
  158. package/docs/skills-third-party.md +0 -183
  159. package/docs/testing/tasks-filter-pagination-test-report.md +0 -86
  160. package/forge +0 -321
  161. package/playwright.config.ts +0 -40
  162. package/scripts/demo-v2.ts +0 -91
  163. package/scripts/dev-daemon.sh +0 -232
  164. package/scripts/dev-web.ts +0 -109
  165. package/scripts/e2e-mcp-link.ts +0 -423
  166. package/scripts/e2e-methodology-quality.ts +0 -253
  167. package/scripts/e2e-routing.ts +0 -456
  168. package/scripts/e2e-user-methodology.ts +0 -326
  169. package/scripts/e2e-web-workflows.ts +0 -299
  170. package/scripts/migrate-legacy-to-dynamic.sql +0 -108
  171. package/scripts/regenerate-execution-docs.ts +0 -116
  172. package/scripts/sync-agent-skills.ts +0 -193
  173. package/scripts/test-hook.sh +0 -71
  174. package/scripts/verify-skill-loading.ts +0 -62
  175. package/src/claudemd/claudemd-generator.ts +0 -568
  176. package/src/claudemd/convention-extractor.ts +0 -69
  177. package/src/claudemd/index.ts +0 -35
  178. package/src/claudemd/persona-manager.ts +0 -88
  179. package/src/claudemd/resume-manager.ts +0 -236
  180. package/src/claudemd/tech-detector.ts +0 -220
  181. package/src/claudemd/templates/swarm-protocol.md +0 -222
  182. package/src/cli/commands/claudemd.ts +0 -84
  183. package/src/cli/commands/config.ts +0 -46
  184. package/src/cli/commands/daemon.ts +0 -310
  185. package/src/cli/commands/executions.ts +0 -115
  186. package/src/cli/commands/init.ts +0 -204
  187. package/src/cli/commands/logs.ts +0 -181
  188. package/src/cli/commands/mcp.ts +0 -242
  189. package/src/cli/commands/menu.ts +0 -357
  190. package/src/cli/commands/skills.ts +0 -185
  191. package/src/cli/commands/stats.ts +0 -73
  192. package/src/cli/commands/status.ts +0 -69
  193. package/src/cli/commands/template.ts +0 -77
  194. package/src/cli/commands/trace.ts +0 -148
  195. package/src/cli/index.ts +0 -42
  196. package/src/cli/init/hook-manager.ts +0 -132
  197. package/src/core/ai/provider.ts +0 -308
  198. package/src/core/ai/types.ts +0 -51
  199. package/src/core/config.ts +0 -124
  200. package/src/core/constants.ts +0 -62
  201. package/src/core/event-fields.ts +0 -32
  202. package/src/core/queue/index.ts +0 -192
  203. package/src/core/storage/base.ts +0 -302
  204. package/src/core/storage/events.ts +0 -434
  205. package/src/core/storage/injections.ts +0 -78
  206. package/src/core/storage/maintenance.ts +0 -59
  207. package/src/core/storage/migrations/002_add_skill_tracking.sql +0 -6
  208. package/src/core/storage/migrations/003_add_skill_invocations.sql +0 -23
  209. package/src/core/storage/performance-indexes.sql +0 -23
  210. package/src/core/storage/routing.ts +0 -322
  211. package/src/core/storage/rows.ts +0 -112
  212. package/src/core/storage/schema.sql +0 -224
  213. package/src/core/storage/sessions.ts +0 -168
  214. package/src/core/storage/skills.ts +0 -233
  215. package/src/core/storage/sqlite.ts +0 -293
  216. package/src/core/storage/tasks.ts +0 -318
  217. package/src/core/storage/token-usage.ts +0 -93
  218. package/src/core/types.ts +0 -181
  219. package/src/core/utils/error-handler.ts +0 -257
  220. package/src/core/utils/forge-resume-block.ts +0 -74
  221. package/src/core/utils/format.ts +0 -69
  222. package/src/core/utils/git.ts +0 -23
  223. package/src/core/utils/logger.ts +0 -134
  224. package/src/core/utils/lru-cache.ts +0 -54
  225. package/src/core/utils/path.ts +0 -19
  226. package/src/core/utils/session.ts +0 -26
  227. package/src/core/utils/time.ts +0 -37
  228. package/src/core/utils/token-tracker.ts +0 -97
  229. package/src/daemon/event-parser.ts +0 -36
  230. package/src/daemon/handlers/history-exporter.ts +0 -117
  231. package/src/daemon/handlers/post-tool-use.ts +0 -54
  232. package/src/daemon/handlers/stop.ts +0 -208
  233. package/src/daemon/handlers/user-prompt.ts +0 -178
  234. package/src/daemon/hook-sync.ts +0 -91
  235. package/src/daemon/index.ts +0 -302
  236. package/src/daemon/launchd/com.claude-forge.daemon.plist.template +0 -47
  237. package/src/daemon/launchd-installer.ts +0 -260
  238. package/src/daemon/lifecycle.ts +0 -128
  239. package/src/daemon/router.ts +0 -40
  240. package/src/daemon/server.ts +0 -196
  241. package/src/daemon/services/task-segmenter.ts +0 -112
  242. package/src/hooks/hook-lib.sh +0 -118
  243. package/src/hooks/notification.sh +0 -35
  244. package/src/hooks/post-tool-use.sh +0 -61
  245. package/src/hooks/pre-tool-use.sh +0 -63
  246. package/src/hooks/stop.sh +0 -43
  247. package/src/hooks/user-prompt-submit.sh +0 -69
  248. package/src/mcp/server.ts +0 -322
  249. package/src/skills/index.ts +0 -2
  250. package/src/skills/invocation-guard.ts +0 -177
  251. package/src/skills/matcher.ts +0 -148
  252. package/src/skills/official/code-simplifier.md +0 -16
  253. package/src/skills/official/find-skills.md +0 -23
  254. package/src/skills/official/official-api-design.md +0 -17
  255. package/src/skills/official/official-architecture-decision.md +0 -20
  256. package/src/skills/official/official-bmad.md +0 -118
  257. package/src/skills/official/official-db-schema-design.md +0 -16
  258. package/src/skills/official/official-debug.md +0 -17
  259. package/src/skills/official/official-doc-driven.md +0 -31
  260. package/src/skills/official/official-harness-engineering.md +0 -108
  261. package/src/skills/official/official-performance-optimization.md +0 -30
  262. package/src/skills/official/official-pr-review.md +0 -35
  263. package/src/skills/official/official-release-checklist.md +0 -30
  264. package/src/skills/official/official-security-hardening.md +0 -26
  265. package/src/skills/official/official-spec-driven-design.md +0 -31
  266. package/src/skills/official/planning-with-files.md +0 -37
  267. package/src/skills/official/ui-ux-pro-max.md +0 -18
  268. package/src/skills/official/webapp-testing.md +0 -12
  269. package/src/skills/official-skills.ts +0 -89
  270. package/src/skills/registry.ts +0 -355
  271. package/src/skills/semantic-matcher.ts +0 -231
  272. package/src/skills/tools/pipeline-suggest.ts +0 -226
  273. package/src/skills/tools/skill-invoke.ts +0 -168
  274. package/src/skills/tools/skill-list.ts +0 -59
  275. package/src/templates/go.yaml +0 -53
  276. package/src/templates/python.yaml +0 -59
  277. package/src/templates/react.yaml +0 -55
  278. package/src/templates/template-manager.ts +0 -170
  279. package/src/web/analytics/anti-pattern-detector.ts +0 -367
  280. package/src/web/analytics/drift-detector.ts +0 -219
  281. package/src/web/analytics/weekly-report.ts +0 -431
  282. package/src/web/auth-middleware.ts +0 -54
  283. package/src/web/routes/_helpers.ts +0 -34
  284. package/src/web/routes/ai.ts +0 -204
  285. package/src/web/routes/auth.ts +0 -22
  286. package/src/web/routes/drift.ts +0 -25
  287. package/src/web/routes/error-handler.ts +0 -120
  288. package/src/web/routes/events.ts +0 -47
  289. package/src/web/routes/insights.ts +0 -43
  290. package/src/web/routes/patch.ts +0 -117
  291. package/src/web/routes/reports.ts +0 -34
  292. package/src/web/routes/rules.ts +0 -76
  293. package/src/web/routes/sessions.ts +0 -250
  294. package/src/web/routes/skill-stats.ts +0 -92
  295. package/src/web/routes/skills.ts +0 -350
  296. package/src/web/routes/static.ts +0 -67
  297. package/src/web/routes/stats.ts +0 -50
  298. package/src/web/routes/status.ts +0 -30
  299. package/src/web/routes/tasks.ts +0 -193
  300. package/src/web/routes/token-usage.ts +0 -20
  301. package/src/web/routes/trace.ts +0 -126
  302. package/src/web/routes/types.ts +0 -57
  303. package/src/web/server.ts +0 -134
  304. package/src/web/ssrf-guard.ts +0 -112
  305. package/src/web/static/index.html +0 -3251
  306. package/src/web/static/vendor/chart.umd.min.js +0 -20
  307. package/tests/e2e/dashboard.spec.ts +0 -205
  308. package/tests/e2e/routing-skill-e2e.test.ts +0 -39
  309. package/tests/helpers/mock-ai.ts +0 -92
  310. package/tests/helpers/mock-storage.ts +0 -159
  311. package/tests/integration/claudemd-generator.test.ts +0 -90
  312. package/tests/integration/queue-replay.integration.test.ts +0 -193
  313. package/tests/integration/tasks-filter.integration.test.ts +0 -154
  314. package/tests/integration/web-analytics.integration.test.ts +0 -133
  315. package/tests/integration/web-stats.integration.test.ts +0 -135
  316. package/tests/integration/web-trace.integration.test.ts +0 -175
  317. package/tests/performance/database.benchmark.ts +0 -161
  318. package/tests/semantic-matcher.test.ts +0 -99
  319. package/tests/skill-matcher.test.ts +0 -110
  320. package/tests/unit/ai-provider-retry.test.ts +0 -194
  321. package/tests/unit/ai-provider-vision.test.ts +0 -224
  322. package/tests/unit/claudemd-generator.test.ts +0 -68
  323. package/tests/unit/cli-mcp.test.ts +0 -141
  324. package/tests/unit/core/forge-paths.test.ts +0 -99
  325. package/tests/unit/daemon/hook-sync.test.ts +0 -71
  326. package/tests/unit/daemon/post-tool-use.test.ts +0 -121
  327. package/tests/unit/daemon/stop-handler-behavior-summary.test.ts +0 -202
  328. package/tests/unit/daemon/task-segmenter-recover.test.ts +0 -84
  329. package/tests/unit/event-fields.test.ts +0 -88
  330. package/tests/unit/event-parser.test.ts +0 -55
  331. package/tests/unit/handlers.test.ts +0 -171
  332. package/tests/unit/hooks/resolve-project-path.test.ts +0 -122
  333. package/tests/unit/invocation-guard.test.ts +0 -125
  334. package/tests/unit/queue.test.ts +0 -272
  335. package/tests/unit/router.test.ts +0 -138
  336. package/tests/unit/security.test.ts +0 -128
  337. package/tests/unit/skill-invocations-workflow.test.ts +0 -495
  338. package/tests/unit/skill-registry.test.ts +0 -94
  339. package/tests/unit/skills/invocation-guard-ttl.test.ts +0 -211
  340. package/tests/unit/skills/official-skills-loader.test.ts +0 -126
  341. package/tests/unit/skills/registry-multiformat.test.ts +0 -92
  342. package/tests/unit/socket-server.test.ts +0 -183
  343. package/tests/unit/storage/event-operations-aggregates.test.ts +0 -342
  344. package/tests/unit/storage/migration-idempotent.test.ts +0 -304
  345. package/tests/unit/storage/routing-aggregates.test.ts +0 -276
  346. package/tests/unit/storage/routing.test.ts +0 -117
  347. package/tests/unit/storage/schema-missing.test.ts +0 -81
  348. package/tests/unit/storage/session-operations-aggregates.test.ts +0 -120
  349. package/tests/unit/storage/sessions-aggregate.test.ts +0 -435
  350. package/tests/unit/storage/skill-operations-counts.test.ts +0 -106
  351. package/tests/unit/storage/skills-aggregates.test.ts +0 -104
  352. package/tests/unit/storage/sqlite-refactor-harness.test.ts +0 -314
  353. package/tests/unit/storage/task-operations-counts.test.ts +0 -46
  354. package/tests/unit/storage/tasks-getById.test.ts +0 -343
  355. package/tests/unit/storage/tasks-stale-gc.test.ts +0 -86
  356. package/tests/unit/storage.test.ts +0 -172
  357. package/tests/unit/token-usage.test.ts +0 -144
  358. package/tests/unit/type-guards.test.ts +0 -201
  359. package/tests/unit/utils/format.test.ts +0 -189
  360. package/tests/unit/utils/session.test.ts +0 -89
  361. package/tests/unit/utils/time.test.ts +0 -112
  362. package/tests/unit/web/navigation-back-contract.test.ts +0 -134
  363. package/tests/unit/web/routes-auth.test.ts +0 -93
  364. package/tests/unit/web/routes-events.test.ts +0 -101
  365. package/tests/unit/web/routes-rules.test.ts +0 -182
  366. package/tests/unit/web/routes-sessions.test.ts +0 -181
  367. package/tests/unit/web/routes-skill-stats.test.ts +0 -179
  368. package/tests/unit/web/routes-stats.test.ts +0 -92
  369. package/tests/unit/web/routes-tasks.test.ts +0 -385
  370. package/tests/unit/web/task-title-contract.test.ts +0 -210
  371. package/tests/unit/web/tasks-component-contract.test.ts +0 -179
  372. package/tsconfig.json +0 -22
  373. package/vitest.config.ts +0 -21
  374. package/vitest.integration.config.ts +0 -16
  375. package/web/CLAUDE.md +0 -20
  376. package/web/index.html +0 -13
  377. package/web/package-lock.json +0 -4854
  378. package/web/package.json +0 -35
  379. package/web/postcss.config.js +0 -6
  380. package/web/src/App.tsx +0 -110
  381. package/web/src/components/CodeBlock.tsx +0 -31
  382. package/web/src/components/Confirm.tsx +0 -96
  383. package/web/src/components/Drawer.tsx +0 -60
  384. package/web/src/components/Layout.tsx +0 -145
  385. package/web/src/components/MarkdownRenderer.tsx +0 -77
  386. package/web/src/components/SearchInput.tsx +0 -31
  387. package/web/src/components/SessionDetailContent.tsx +0 -157
  388. package/web/src/components/Toast.tsx +0 -92
  389. package/web/src/index.css +0 -19
  390. package/web/src/main.tsx +0 -31
  391. package/web/src/pages/AIConfig.tsx +0 -233
  392. package/web/src/pages/Dashboard.tsx +0 -572
  393. package/web/src/pages/Events.tsx +0 -271
  394. package/web/src/pages/Reports.tsx +0 -428
  395. package/web/src/pages/SessionDetail.tsx +0 -162
  396. package/web/src/pages/Sessions.tsx +0 -205
  397. package/web/src/pages/Skills.tsx +0 -180
  398. package/web/src/pages/TaskDetail.tsx +0 -515
  399. package/web/src/pages/Tasks.tsx +0 -415
  400. package/web/src/utils/auth.ts +0 -59
  401. package/web/src/utils/export.ts +0 -54
  402. package/web/src/utils/navigation.ts +0 -25
  403. package/web/src/utils/task-title.ts +0 -49
  404. package/web/src/utils/time.ts +0 -13
  405. package/web/tailwind.config.js +0 -11
  406. package/web/tsconfig.json +0 -21
  407. package/web/tsconfig.node.json +0 -10
  408. package/web/vite.config.ts +0 -76
  409. package/winspan-claude-forge-8.43.0.tgz +0 -0
package/DEVELOPMENT.md CHANGED
@@ -2,80 +2,128 @@
2
2
 
3
3
  面向 claude-forge 贡献者的架构与工作流说明。
4
4
 
5
+ > 高层架构 + 设计决策见 [docs/architecture/README.md](./docs/architecture/README.md)
6
+
5
7
  ---
6
8
 
7
9
  ## 仓库布局
8
10
 
9
11
  ```
10
12
  src/
11
- ├── core/
12
- │ ├── storage/ SQLite 存储(schema.sql + sqlite.ts),WAL 模式,单一 data.db
13
- │ ├── ai/ Anthropic SDK 封装(ClaudeProvider),被 classifier / planner / distiller 复用
14
- │ ├── utils/ logger / error-handler 等跨层工具
15
- └── types.ts ForgeEvent / HookResult 等核心类型契约
16
- ├── engine/
17
- │ ├── dsl/ 治理规则 DSL 编译器(types / lexer / parser / compiler)
18
- │ ├── conventions/ 打包进发布的默认 YAML 规则
19
- │ ├── rule-engine.ts 规则执行
20
- │ ├── context-builder.ts Hook 事件 → 规则上下文
21
- │ ├── evidence-store.ts 治理证据持久化
22
- │ ├── agent-router.ts Agent 路由(基于 routing.yaml)
23
- └── experiment-router.ts A/B 实验路由(基于 experiments.yaml)
24
- ├── intelligence/
25
- │ ├── classifier.ts IntentClassifier:complexity / taskType / keywords
26
- │ ├── quality-gate.ts AI 驱动的代码质量检查(PostToolUse)
27
- │ ├── distiller.ts Stop 时蒸馏会话为 decisions.md / timeline.md
28
- └── task-segmenter.ts 按 UserPromptSubmit 划分任务段
29
- ├── capability/
30
- │ ├── methodology-registry.ts 加载 src/capability/methodologies/*.yaml
31
- ├── methodology-planner.ts AI Planner 根据 intent 生成 ExecutionPlan
32
- ├── execution-manager.ts daemon 单例:前/后台路由、孤儿清理
33
- ├── executor/
34
- ├── types.ts PhaseExecutor 统一抽象
35
- ├── foreground-executor.ts 前台:directive pending 队列
36
- ├── background-executor.ts 后台:spawn claude -p 独立子进程
37
- ├── stream-parser.ts stream-json 事件解析
38
- │ └── orchestrator.ts 串行驱动 phases
39
- └── methodologies/ harness-engineering.yaml / bmad.yaml
40
- ├── daemon/
41
- │ ├── index.ts daemon 入口:socket server + hook router
42
- │ ├── router.ts 按 hook_type 分发到 handler
13
+ ├── core/ 共享核心,不反向依赖业务层
14
+ │ ├── storage/ SQLite 存储(schema.sql + sqlite.ts),WAL 模式,单一 data.db
15
+ ├── schema.sql 建表初始化
16
+ ├── migrations/ 增量 .sql 迁移
17
+ │ ├── events.ts writeEvent / queryEvents
18
+ │ │ ├── sessions.ts querySessions / upsertSession / countAllSessions
19
+ ├── tasks.ts writeTask / queryTasks / task_events
20
+ ├── injections.ts hook 注入审计
21
+ ├── routing.ts routing_events 表
22
+ ├── skills.ts skill_invocations
23
+ ├── token-usage.ts token_usage 聚合
24
+ ├── base.ts / rows.ts 连接 + 行映射工具
25
+ │ ├── maintenance.ts 清理/压缩
26
+ │ │ └── performance-indexes.sql 附加索引
27
+ │ ├── ai/ ClaudeProvider 封装(用于 classifier、distiller、skill-upgrade)
28
+ │ ├── queue/ 通用 SQLite 队列工具
29
+ │ ├── utils/ logger / git / path / time / lru-cache / forge-resume-block 等
30
+ ├── config.ts ConfigManager(~/.claude-forge/config.yaml)
31
+ ├── constants.ts FORGE_PATHS、各类阈值常量
32
+ │ ├── event-fields.ts hook 事件字段统一抽取
33
+ └── types.ts ForgeEvent / HookResult 等核心类型契约
34
+
35
+ ├── daemon/ 后台守护进程
36
+ │ ├── index.ts 入口:socket server + 生命周期 + 同步任务
37
+ │ ├── server.ts Unix socket 接收 hook payload
38
+ │ ├── router.ts hook_type 分发到 handler
39
+ │ ├── lifecycle.ts 启停 / 信号处理
40
+ ├── event-parser.ts hook 原始 JSON → ForgeEvent
41
+ ├── hook-sync.ts 启动时把 dist/hooks/ 同步到 ~/.claude/hooks/
42
+ ├── skill-sync.ts 启动时把 dist/skills/official/ 同步到 ~/.claude/skills/
43
+ │ ├── launchd-installer.ts macOS launchd 安装
44
+ │ ├── launchd/ launchd plist 模板
43
45
  │ ├── handlers/
44
- │ │ ├── user-prompt.ts UserPromptSubmit:分类 + 路由 + 方法论
45
- │ │ ├── pre-tool-use.ts PreToolUse:规则阻断
46
- │ │ ├── post-tool-use.ts PostToolUse:质量检查 + 方法论推进
47
- │ │ ├── stop.ts Stop:蒸馏 + 方法论兜底
48
- │ │ ├── methodology-formatter.ts 生成前/后台 directive 文本
46
+ │ │ ├── user-prompt.ts UserPromptSubmit:分类 + skill 推荐 + agent 路由
47
+ │ │ ├── post-tool-use.ts PostToolUse:观察,按需注入提示
48
+ │ │ ├── stop.ts Stop:写 session 摘要、distill 决策
49
49
  │ │ └── history-exporter.ts 导出完整历史到 .claude-forge/history/
50
- ├── routing-observer.ts 观察 Agent 调用 → 标注 obeyed
51
- ├── routing-state.ts 会话级路由状态(PreToolUse 强制校验用)
52
- ├── auto-disable-scheduler.ts 自动禁用频繁违规的 (taskType, agent) 组合
53
- │ └── methodology-pending-queue.ts 前台 directive 持久化兜底队列
54
- ├── hooks/ Shell 脚本:从 Claude Code 到 daemon socket 的桥
55
- ├── agents/ 内置 Agent 定义(13 个),可被 CLI 注入 ~/.claude/agents/
56
- ├── skills/ Skill registry
57
- ├── claudemd/ resume-manager / convention-extractor(CLAUDE.md 生成)
58
- ├── cli/ CLI 入口(claude-forge / cf),按命令组织在 cli/commands/
59
- ├── templates/ 新项目初始化模板
60
- └── web/ Express + SSE 服务器(react 前端产物从 web/dist 拷入)
61
-
62
- web/ React + TanStack Query + Tailwind 前端(独立 npm workspace)
63
- ├── src/pages/ 11 个页面(每个 lazy-loaded)
64
- ├── src/components/ Drawer / Toast / Confirm / SearchInput / MarkdownRenderer / CodeBlock
65
- └── vite.config.ts 手动 manualChunks 切分大库
66
-
67
- tests/unit/ Vitest 单测(vitest.config.ts include 仅覆盖此目录)
68
- scripts/ 开发/调试脚本:dev-web、demo-v2、smoke-background-executor
50
+ └── services/
51
+ └── task-segmenter.ts UserPromptSubmit 按时间窗划分任务段
52
+
53
+ ├── skills/ Skill 推荐与方法论分发
54
+ ├── registry.ts 扫描 ~/.claude/skills/ + src/skills/official/,提供 match()
55
+ ├── matcher.ts 关键词匹配
56
+ ├── semantic-matcher.ts AI 语义匹配(可选,需 API key)
57
+ ├── invocation-guard.ts 防止 agent 重复 invoke 同一 skill
58
+ ├── upgrade-engine.ts 社区 skill 升级核心:pull / match / evaluate / apply
59
+ ├── upgrade-prompt.ts AI evaluator prompt 模板
60
+ │ ├── official-skills.ts 加载内置官方 skill
61
+ │ ├── official/ 内置官方 skill .md 源(随发布打包)
62
+ │ ├── tools/ MCP 工具:skill_invoke / skill_list / pipeline_suggest
63
+ │ └── index.ts 对外导出
64
+
65
+ ├── web/ Web 管理后台
66
+ │ ├── server.ts Express 服务器 + 路由注册
67
+ │ ├── auth-middleware.ts 本地 token 校验
68
+ │ ├── ssrf-guard.ts SSRF 防护
69
+ │ ├── routes/ 每个 API 模块独立文件(sessions / events / tasks / skills / ai / patch ...)
70
+ │ ├── analytics/ 趋势/统计计算
71
+ │ └── static/ React 前端构建产物的最终落点(dist/web/static/)
72
+
73
+ ├── cli/
74
+ │ ├── index.ts CLI 入口(commander)
75
+ │ ├── init/ `cf init`:安装 hook 脚本
76
+ │ └── commands/ 子命令:daemon / config / skills / claudemd / status / logs / stats / menu / trace / mcp / executions / template
77
+
78
+ ├── claudemd/ CLAUDE.md 生成与维护
79
+ │ ├── tech-detector.ts 项目技术栈识别
80
+ │ ├── claudemd-generator.ts 生成 CLAUDE.md 正文
81
+ │ ├── convention-extractor.ts 从已有规则提取约定
82
+ │ ├── resume-manager.ts forge:resume 块续接管理
83
+ │ ├── persona-manager.ts 用户 persona 段管理
84
+ │ ├── templates/ 各类模板(含 swarm-protocol.md)
85
+ │ └── index.ts 对外导出
86
+
87
+ ├── hooks/ Shell 脚本:从 Claude Code 桥接到 daemon socket
88
+ │ ├── hook-lib.sh 共用工具(payload 拼装、容错)
89
+ │ ├── user-prompt-submit.sh
90
+ │ ├── pre-tool-use.sh
91
+ │ ├── post-tool-use.sh
92
+ │ ├── stop.sh
93
+ │ └── notification.sh
94
+
95
+ ├── mcp/ MCP server(暴露 skill_invoke / skill_list / pipeline_suggest 给 agent)
96
+ │ └── server.ts
97
+
98
+ └── templates/ 新项目初始化模板
99
+
100
+ web/ React 前端源码(独立 npm workspace)
101
+ ├── src/pages/ 各业务页面(lazy-loaded)
102
+ ├── src/components/ 通用组件
103
+ └── vite.config.ts Vite + 手动 manualChunks
104
+
105
+ tests/
106
+ └── unit/ vitest 单测(vitest.config.ts include 此目录)
107
+ ├── core/ daemon/ skills/ storage/ utils/ web/ hooks/ 各模块独立子目录
108
+ └── *.test.ts 顶层综合测试
109
+
110
+ scripts/ 辅助脚本:dev-daemon / dev-web / e2e-* / sync-agent-skills / check-spec-changelog 等
111
+ docs/
112
+ ├── design/ spec(planner 输出)
113
+ ├── implementation/ changelog(coder 输出)
114
+ └── skill-upgrade-guide.md skill 升级流程
69
115
  ```
70
116
 
71
117
  ## 目录依赖约束
72
118
 
73
119
  - `core` 不反向依赖业务层
74
- - `engine` 可依赖 `core`
75
- - `intelligence` 可依赖 `core` / `engine`
76
- - `capability` 可依赖 `core` / `engine` / `intelligence`
77
- - `daemon` 可依赖 `core` / `engine` / `intelligence` / `capability` / `agents` / `skills`
78
- - `cli` 做命令分发,不塞核心规则逻辑
120
+ - `skills` 可依赖 `core`
121
+ - `claudemd` 可依赖 `core`
122
+ - `daemon` 可依赖 `core` / `skills` / `claudemd`
123
+ - `web` 可依赖 `core` / `skills` / `claudemd`(不依赖 `daemon`)
124
+ - `mcp` 可依赖 `core` / `skills`
125
+ - `cli` 做命令分发,可依赖任意模块,但不塞核心规则逻辑
126
+ - `hooks/*.sh` 不依赖代码,只通过 socket payload 跟 daemon 通信
79
127
 
80
128
  ---
81
129
 
@@ -86,225 +134,246 @@ scripts/ 开发/调试脚本:dev-web、demo-v2、smoke-backgro
86
134
  npm install
87
135
  npm run build
88
136
 
89
- # 启动 daemon(开发模式,用 tsx 直跑 ts
90
- npm run dev:daemon
137
+ # 启动 daemon(开发模式,复用 ./scripts/dev-daemon.sh
138
+ npm run dev:daemon:start
139
+ npm run dev:daemon:restart
140
+ npm run dev:daemon:logs
141
+ npm run dev:daemon:stop
91
142
 
92
- # 启动 web dev 同步(监听 web/src 变化自动拷贝到 dist/web/static/)
93
- npm run dev:web
143
+ # 前端开发(在 web/ 目录)
144
+ cd web && npm install && npm run dev
94
145
  ```
95
146
 
96
- CLI 开发:`npm run dev -- <command>`(比如 `npm run dev -- status`)。
147
+ Daemon / CLI 都用系统 node(项目要求 Node 18+,实际跑在 24/26 上)。
97
148
 
98
149
  ---
99
150
 
100
151
  ## 构建与测试
101
152
 
102
153
  ```bash
103
- # 后端:tsc + 拷贝 hooks/schema/yaml dist/
154
+ # 后端:tsc + 拷贝 hooks / schema / templates / 前端产物到 dist/
104
155
  npm run build
105
156
 
106
- # 前端:vite 构建到 web/dist/,随后 npm run build 会把它复制进 dist/web/static/
107
- npm run build:web
108
-
109
- # 完整:先前端再后端
110
- npm run build:all
111
-
112
157
  # 测试
113
- npm test # vitest run,只跑 tests/unit/
114
- npm run test:watch # watch 模式
115
- npm run test:coverage # 覆盖率
158
+ npm test # vitest run(只跑 tests/unit/)
159
+ npm run test:watch # watch 模式
116
160
 
117
- # TS 双侧检查
161
+ # TS 类型检查
118
162
  npx tsc --noEmit
119
163
  cd web && npx tsc --noEmit
164
+
165
+ # spec / changelog 配对检查(开发流程治理)
166
+ npm run check:specs
120
167
  ```
121
168
 
122
- > 发布流程:`npm run prepublishOnly`(= `npm run build`)会自动跑一遍,之后 `npm publish` 即可。发布前记得 `bump version`(两处:`package.json` + `package-lock.json`)。
169
+ > 发布流程:用户手动 `npm publish`。AI 只做 `git commit / git push` bump version(`package.json` 一处)。
123
170
 
124
171
  ---
125
172
 
126
173
  ## 架构要点
127
174
 
128
- ### 方法论执行链路
175
+ ### Hook 事件流
129
176
 
130
177
  ```
131
- ┌───────────────────────┐ ┌──────────────────┐
132
- UserPromptSubmit │ or │ POST /api/ │
133
- │ 自动识别任务 → 创建 │ │ methodology- │
134
- │ execution (mode=fg) │ │ executions │
135
- └──────────┬────────────┘ (mode=bg) │
136
- │ └────────┬─────────┘
137
- │ │
138
- ▼ ▼
139
- ┌──────────────────────────────────────┐
140
- │ ExecutionManager.start()
141
- ├─ createMethodologyExecution() │
142
- │ ├─ seed phase 0 row │
143
- │ └─ new Orchestrator(executor).run() │
144
- └──────────┬───────────────────────────┘
145
-
146
- ┌──────────┴──────────┐
147
- mode? │
148
- └──┬───────────────┬──┘
149
- foreground │ background
150
- ▼ ▼
151
- ┌──────────────┐ ┌────────────────────────┐
152
- Foreground │ │ Background │
153
- │ Executor │ │ Executor │
154
- │ ─ enqueue │ │ ─ spawn claude -p │
155
- │ directive │ │ ─ parse stream-json │
156
- │ ─ return │ │ ─ update phase_exec │
157
- │ 'injected' │ │ ─ wait exit │
158
- └──────┬───────┘ └──────────┬─────────────┘
159
- │ │
160
- ▼ │
161
- ┌──────────────┐ │
162
- │ Pending │ │
163
- │ Queue │ │
164
- └──────┬───────┘ │
165
- │ │
166
- ▼ ▼
167
- ┌──────────────┐ ┌─────────────────┐
168
- │ Claude │ │ Orchestrator │
169
- │ 主会话 │ │ 推进到下一 phase │
170
- │ 下一次输入时 │ │ 直到完成或失败 │
171
- │ 消费队列 │ └─────────────────┘
172
- └──────────────┘
178
+ Claude Code ──hook payload(JSON via stdin)──► src/hooks/*.sh
179
+
180
+
181
+ $(socat / nc) ──► ~/.claude-forge/daemon.sock
182
+
183
+
184
+ src/daemon/server.ts (接收 + 反序列化)
185
+
186
+
187
+ src/daemon/event-parser.ts (统一 ForgeEvent)
188
+
189
+
190
+ src/daemon/router.ts ──┬──► handlers/user-prompt.ts
191
+ ├──► handlers/post-tool-use.ts
192
+ ├──► handlers/stop.ts
193
+ └──► (PreToolUse / Notification: 直接 allow)
194
+
195
+
196
+ core/storage/* 持久化 + 返回 HookResult
197
+
198
+
199
+ Claude Code 读取 HookResult.systemMessage / additionalContext / allow
173
200
  ```
174
201
 
175
- ### 存储
202
+ 要点:
203
+ - daemon 必须在 100ms 内返回,超时则 Claude Code 视为放行
204
+ - handler 抛错被 router 捕获,不会让 daemon 崩溃
205
+ - `PreToolUse` 当前不做规则阻断,统一放行
206
+ - daemon 不主动推消息:任何延后的指令必须等下一次 UserPromptSubmit 注入
176
207
 
177
- - `~/.claude-forge/data.db` —— 单一运行时数据库:events / sessions / routing_events / methodology_executions / phase_executions / tasks / injections / decisions / token_usage
178
- - Schema 由 `src/core/storage/schema.sql` 初始化,增量迁移放在 `runMigrations()`(幂等 `ALTER TABLE` + `PRAGMA table_info` 检测)
208
+ ### Skill 系统
179
209
 
180
- ### Hook 注入原则
210
+ ```
211
+ ┌─────────────────────┐
212
+ │ UserPromptSubmit │
213
+ │ handler │
214
+ └─────────┬───────────┘
215
+
216
+
217
+ ┌──────────────────────────┐ ┌──────────────────────────┐
218
+ │ SkillRegistry.match() │ ───────►│ semantic-matcher (AI) │
219
+ │ (registry.ts) │ │ 若配置了 API key 则优先 │
220
+ │ │ └────────────┬─────────────┘
221
+ │ 扫描两类来源: │ │ 失败/无 key
222
+ │ - 内置 src/skills/ │ ▼
223
+ │ official/*.md │ ┌──────────────────────────┐
224
+ │ - 用户 ~/.claude/skills/│ ───────►│ keyword matcher │
225
+ │ {name}.md │ │ (matcher.ts) │
226
+ │ or {name}/SKILL.md │ └────────────┬─────────────┘
227
+ └──────────────────────────┘ │
228
+ │ │
229
+ ▼ ▼
230
+ ┌──────────────────────────────────────────────────────┐
231
+ │ invocation-guard 防重复 → 注入 systemMessage 推荐 │
232
+ │ (skill_invocations 表落库) │
233
+ └──────────────────────────────────────────────────────┘
234
+
235
+ Agent 通过 MCP 工具:
236
+ - skill_list 列出可用 skill
237
+ - skill_invoke <id> 取完整方法论
238
+ - pipeline_suggest 根据 intent 拼工作流
239
+ ```
181
240
 
182
- - UserPromptSubmit 返回 `{ systemMessage, additionalContext, allow }`;systemMessage 优先级高于 additionalContext
183
- - PostToolUse 只能观察,不能修改工具结果;返回 systemMessage 会拼到 Claude 下一轮的系统消息
184
- - Stop 返回 systemMessage 会作为"本轮结束"的最后一条系统提示
185
- - **daemon 无法主动推送消息**。前台方法论的兜底设计正是基于这条约束(Stop → 写 pending 队列 → 下一次 UserPromptSubmit 消费)
241
+ frontmatter 必须有 `name: string`,否则 registry 静默跳过(debug 日志,不打扰用户)。`keywords` `tags` 都接受。
186
242
 
187
- ### Agent Worker 隔离
243
+ ### Skill 远程升级
188
244
 
189
- 后台 BackgroundExecutor spawn `claude -p` 时:
245
+ `cf skills upgrade` `src/skills/upgrade-engine.ts` 驱动,三阶段:
190
246
 
191
- - **不用 `--bare`**(会关闭 `~/.claude/agents/` 加载,破坏 phase.agent 语义)
192
- - 用 `--settings <worker-settings.json>`(内容 `{"hooks": {}}`)阻断 worker 递归触发 daemon hook
193
- - env 里写入 `CLAUDE_FORGE_WORKER=1`,未来 daemon 侧若需识别 worker 事件可用此标记
194
- - `--permission-mode bypassPermissions` + `--add-dir <projectRoot>` 限制只在项目目录内动手
195
- - `--disallowed-tools WebFetch,WebSearch` 默认禁用爬虫类工具
196
- - `--max-budget-usd 2` phase 预算上限
197
- - stream-json 全量落盘到 `~/.claude-forge/logs/execution-{id}-phase-{n}.jsonl`
247
+ 1. `pullCandidates(DEFAULT_SOURCES, ~/.claude-forge/skill-candidates/)`
248
+ - 默认源:`addyosmani/agent-skills` + `obra/superpowers`
249
+ - 已存在则 `git pull`,不存在则 `git clone`
250
+ 2. 对每个候选用 `matchToOfficial()` 找最相似官方 skill,再用 `evaluateWithAI()` 让 AI 给出 `upgrade / merge / skip`,AI 解析失败 → `needs_review`
251
+ 3. `generateReport()` 写到 `~/.claude-forge/skill-upgrade-report.md`,每条带 `<!-- upgrade-entry: ... -->` 标记
252
+ 4. `cf skills upgrade --apply` 读报告 备份 `~/.claude-forge/backups/skills/<ts>/` → 覆盖 `src/skills/official/`
253
+ 5. `--rollback <ts>` 反向拷回
198
254
 
199
- ---
255
+ 详见 `docs/skill-upgrade-guide.md`。
200
256
 
201
- ## 调试技巧
257
+ ### CLAUDE.md 生成与维护
202
258
 
203
- ```bash
204
- # 看 daemon 日志(启动时写在 stderr,daemon 模式写入 ~/.claude-forge/daemon.log)
205
- tail -f ~/.claude-forge/daemon.log
259
+ `src/claudemd/` 负责项目级规则文件的生成、续接与扩充:
206
260
 
207
- # 直接查 SQLite 运行时数据
208
- sqlite3 ~/.claude-forge/data.db "SELECT id, methodology_id, status, mode, current_phase_index FROM methodology_executions ORDER BY id DESC LIMIT 10"
261
+ - `tech-detector.ts` 识别项目语言/框架(读 `package.json` / `pyproject.toml` 等)
262
+ - `claudemd-generator.ts` 拼装结果到 `CLAUDE.md`
263
+ - `convention-extractor.ts` — 把已有规则段抽离合并
264
+ - `resume-manager.ts` — 维护 `<!-- forge:resume-begin -->` 续接块(daemon 在 Stop 时写入)
265
+ - `persona-manager.ts` — 用户自定义 persona 段
266
+ - 模板存放在 `src/claudemd/templates/`(build 时拷到 `dist/claudemd/templates/`)
209
267
 
210
- # 查看后台 worker 的完整 stream-json 日志
211
- ls ~/.claude-forge/logs/
268
+ 入口命令:`cf claudemd detect` / `cf claudemd init` / `cf claudemd update`(详见 `src/cli/commands/claudemd.ts`)。
212
269
 
213
- # Hook 脚本手工模拟(绕开 Claude Code)
214
- echo '{"session_id":"test","hook_type":"UserPromptSubmit","user_prompt":"重构xxx"}' | ~/.claude/hooks/user-prompt-submit.sh
270
+ ### Daemon 自动同步
215
271
 
216
- # Web 后台 SSE 实时监控(默认 3456,可在 ~/.claude-forge/config.yaml 修改 web.port)
217
- curl -N http://127.0.0.1:3456/api/methodology-executions/events
218
- ```
272
+ daemon 启动时(`src/daemon/index.ts`)执行两个一次性同步:
219
273
 
220
- ---
274
+ - `syncHooks()` — 把 `dist/hooks/*.sh` 对照 sha256 同步到 `~/.claude/hooks/`,避免用户忘了重跑 `cf init`
275
+ - `syncSkills()` — 把 `dist/skills/official/*.md` 同步到 `~/.claude/skills/`,user-owned 文件(已存在)跳过
221
276
 
222
- ## 新增方法论
223
-
224
- 1. 在 `src/capability/methodologies/` 新建 `<id>.yaml`,参考 `harness-engineering.yaml` 结构:
225
- ```yaml
226
- id: my-methodology
227
- name: "My Methodology"
228
- description: "..."
229
- trigger:
230
- taskType: [refactor, migrate]
231
- complexity: [moderate, complex]
232
- phase_templates:
233
- understand:
234
- agent: researcher
235
- description: ...
236
- prompt_template: ...
237
- artifacts:
238
- - type: file
239
- pattern: "docs/**/*behavior*.md"
240
- required: true
241
- decision_rules:
242
- - condition: "complexity == 'complex' && taskType == 'migrate'"
243
- phases: [understand, characterize, refactor, verify]
244
- description: "full workflow"
245
- ```
246
- 2. `phase_templates.<id>.agent` 必须对应 `~/.claude/agents/` 里真实存在的 agent 名(Planner 会用它生成 `phase.agent`,matcher 会严格校验)
247
- 3. 重启 daemon(Registry 启动时加载一次)
248
- 4. 在 Web UI `/methodologies` 点"新建执行"选它,或发一条符合 trigger 的 prompt
249
-
250
- ## 新增 Agent
251
-
252
- 最简方式:`~/.claude/agents/<name>.md` 按 frontmatter 规范写:
277
+ 两者都幂等,文件相同时不写盘。
253
278
 
254
- ```markdown
255
- ---
256
- name: my-agent
257
- description: "简明描述"
258
- tools: [Read, Grep, Edit]
259
- ---
279
+ ### 数据流(事件 → API → UI)
260
280
 
261
- 完整 agent 系统指令...
281
+ ```
282
+ hook event ──► writeEvent() ──┐
283
+ ──► writeTask()/task_events ─┤
284
+ ──► writeRoutingEvent() ─┼─► ~/.claude-forge/data.db
285
+ ──► writeSkillInvocation() ─┤
286
+ ──► writeInjection() ─┘
287
+
288
+
289
+ src/web/routes/*.ts (queryXxx)
290
+
291
+
292
+ GET /api/events / sessions / tasks / skill-invocations ...
293
+
294
+
295
+ web/src/pages/*.tsx (TanStack Query)
262
296
  ```
263
297
 
264
- 或通过 Web UI `/agents` 可视化编辑。daemon 启动时 AgentRegistry 会扫描并加载。
298
+ 存储:
299
+ - 主库 `~/.claude-forge/data.db`,表:`events`、`sessions`、`tasks`、`task_events`、`injections`、`routing_events`、`token_usage`、`skill_invocations`
300
+ - Schema 由 `src/core/storage/schema.sql` 初始化
301
+ - 增量改动放 `src/core/storage/migrations/*.sql`(按文件名顺序执行)
265
302
 
266
- ---
303
+ ### 长跑稳定性(v8.53.6 加)
304
+
305
+ daemon 通过三个机制保证长时间运行不膨胀:
267
306
 
268
- ## 测试规范
307
+ - **多表 GC**:`cleanOldData(30)` 定期清理 30 天前的 events / routing_events / skill_invocations / token_usage,防止数据库无限增长
308
+ - **SQLite VACUUM**:`runMaintenance(500)` 在数据库超过 500 MB 时触发 `VACUUM`,回收空间;上次 VACUUM 超 7 天也强制执行
309
+ - **Stale task 回收**:`staleTaskGcInterval` 每 5 分钟扫描并关闭异常 active 状态的 task(避免僵尸任务阻塞计数)
269
310
 
270
- - 单元测试放 `tests/unit/**/*.test.ts`,vitest include 只认这个目录
271
- - 集成测试:可以在 `tests/unit/executor/` 下用 fake 子进程的方式(参考 `background-executor.test.ts` 的 shell wrapper 手法)
272
- - E2E(真 claude -p):写进 `scripts/smoke-*.ts`,手动触发,不进 CI
273
- - 新增功能必须 at least 一个单测,关键路径需要集成测试
311
+ 相关代码:`src/core/storage/maintenance.ts`(cleanOldData / runMaintenance),daemon 在 `src/daemon/index.ts` 启动时注册定时任务。
274
312
 
275
313
  ---
276
314
 
277
- ## 发布流程
315
+ ## 添加新 Hook
278
316
 
279
- ```bash
280
- # 1. 本地全量验证
281
- npm run build:all
282
- npx tsc --noEmit && (cd web && npx tsc --noEmit)
283
- npm test
317
+ 1. 在 `src/hooks/` 加 `.sh` 脚本,复用 `hook-lib.sh` 的 payload 工具
318
+ 2. `src/daemon/event-parser.ts` 加 hook_type 解析(如有新字段)
319
+ 3. `src/daemon/router.ts` 加分发分支;如需 handler 新建 `src/daemon/handlers/<name>.ts`
320
+ 4. `src/core/types.ts` 加事件类型 + type guard
321
+ 5. 重 build 后 `cf init` 重装 hook,或重启 daemon 让 `syncHooks()` 自动覆盖
322
+ 6. 测试覆盖:hook 脚本 + handler 都要补 `tests/unit/`
323
+
324
+ > hooks/*.sh 无单元测试覆盖,改 hook 必走 Hybrid 工作流(见根 CLAUDE.md「工作流升级判定」)。
284
325
 
285
- # 2. bump version
286
- # package.json + package-lock.json 两处同步改
326
+ ## 添加新 Skill
287
327
 
288
- # 3. commit + tag
289
- git commit -am "chore: bump version to X.Y.Z"
290
- git tag vX.Y.Z
328
+ 最简方式:在 `src/skills/official/<name>.md` frontmatter:
291
329
 
292
- # 4. publish
293
- npm publish # 自动触发 prepublishOnly
330
+ ```markdown
331
+ ---
332
+ name: my-skill
333
+ description: 用一句话说明 skill 触发场景
334
+ keywords: [refactor, legacy, test]
335
+ version: 1.0.0
336
+ ---
294
337
 
295
- # 5. push
296
- git push && git push --tags
338
+ # 方法论正文
339
+
340
+ 完整的多 phase 工作流...
297
341
  ```
298
342
 
343
+ 发布后 daemon 启动会自动 sync 到用户的 `~/.claude/skills/`。如果是只面向自己的 skill,直接放 `~/.claude/skills/` 即可。
344
+
345
+ 社区 skill 升级走 `cf skills upgrade`,详见 `docs/skill-upgrade-guide.md`。
346
+
347
+ ## 添加新 CLI 子命令
348
+
349
+ 1. 在 `src/cli/commands/<name>.ts` 写 `register(program)`
350
+ 2. 在 `src/cli/index.ts` 引入并调用 `register()`
351
+ 3. 子命令测试放 `tests/unit/cli-<name>.test.ts`
352
+
299
353
  ---
300
354
 
301
- ## 排障清单
355
+ ## 故障排查
302
356
 
303
- | 现象 | 可能原因 |
357
+ | 现象 | 排查 |
304
358
  |---|---|
305
- | Hook 没触发 | `~/.claude/hooks/` 未软链到 `dist/hooks/`;跑 `cf init` 重装 |
306
- | daemon 启动报 EADDRINUSE | 上次进程没退;`cf daemon stop` 或 `lsof -i :<web.port>`(默认 3456)找 pid kill |
307
- | 方法论 execution 长期卡 0% | 前台模式需用户输入才推进;Web UI 可改用后台模式 |
308
- | BackgroundExecutor 直接报 auth 失败 | 确认 `ANTHROPIC_API_KEY` 环境变量可用,或配了 OAuth |
309
- | stream-json 行数突然变少 | claude CLI 版本升级,对齐 `stream-parser.ts` type 定义 |
310
- | Web 构建 chunk >500KB 警告 | 加新大依赖时,在 `web/vite.config.ts` `manualChunks` 追加分组 |
359
+ | Hook 没触发 | `ls -la ~/.claude/hooks/` 看是否指向 `dist/hooks/`;缺失就跑 `cf init`;或重启 daemon 让 `syncHooks()` 自动补 |
360
+ | daemon 启动报 `EADDRINUSE` | 上次进程没退;`cf daemon stop` 或 `lsof -i :3721` pid |
361
+ | Web 后台 404 | `dist/web/static/` 是否存在;`npm run build` 是否成功;Vite 前端 `cd web && npm run build` 后再 root build |
362
+ | Skill 没被推荐 | `cf skills list` 看是否加载;frontmatter 检查是否缺 `name` 字段;语义匹配需要 `cf config` 配 API key |
363
+ | `cf skills upgrade` 无候选 | `~/.claude-forge/skill-candidates/` 是否拉成功;网络问题用代理重试 |
364
+ | better-sqlite3 native binding error | Node 版本与 binding 不匹配;`npm rebuild better-sqlite3` |
365
+ | Schema 改动后查不到字段 | 手动加 `src/core/storage/migrations/<n>_<desc>.sql`,daemon 启动会自动执行 |
366
+
367
+ 调试入口:
368
+
369
+ ```bash
370
+ # daemon 日志
371
+ tail -f ~/.claude-forge/daemon.log
372
+
373
+ # 查 SQLite 运行时数据
374
+ sqlite3 ~/.claude-forge/data.db "SELECT id, hook_type, timestamp FROM events ORDER BY id DESC LIMIT 10"
375
+
376
+ # 手工模拟 hook 调用(绕开 Claude Code)
377
+ echo '{"session_id":"test","hook_type":"UserPromptSubmit","user_prompt":"重构 xxx"}' \
378
+ | ~/.claude/hooks/user-prompt-submit.sh
379
+ ```