@winspan/claude-forge 8.50.6 → 8.51.1
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.
- package/CLAUDE.md +7 -7
- package/dist/claudemd/claudemd-generator.d.ts.map +1 -1
- package/dist/claudemd/claudemd-generator.js +27 -237
- package/dist/claudemd/claudemd-generator.js.map +1 -1
- package/dist/claudemd/resume-manager.js +1 -1
- package/dist/claudemd/resume-manager.js.map +1 -1
- package/dist/claudemd/templates/swarm-protocol.md +222 -0
- package/dist/cli/commands/daemon.js +6 -6
- package/dist/cli/commands/daemon.js.map +1 -1
- package/dist/cli/commands/executions.d.ts.map +1 -1
- package/dist/cli/commands/executions.js +4 -3
- package/dist/cli/commands/executions.js.map +1 -1
- package/dist/cli/commands/init.js +2 -2
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/logs.js.map +1 -1
- package/dist/cli/commands/mcp.d.ts.map +1 -1
- package/dist/cli/commands/mcp.js +3 -5
- package/dist/cli/commands/mcp.js.map +1 -1
- package/dist/cli/commands/menu.d.ts.map +1 -1
- package/dist/cli/commands/menu.js +4 -3
- package/dist/cli/commands/menu.js.map +1 -1
- package/dist/cli/commands/stats.d.ts.map +1 -1
- package/dist/cli/commands/stats.js +2 -3
- package/dist/cli/commands/stats.js.map +1 -1
- package/dist/cli/commands/status.js +2 -2
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/trace.d.ts.map +1 -1
- package/dist/cli/commands/trace.js +11 -23
- package/dist/cli/commands/trace.js.map +1 -1
- package/dist/cli/init/hook-manager.d.ts.map +1 -1
- package/dist/cli/init/hook-manager.js +2 -2
- package/dist/cli/init/hook-manager.js.map +1 -1
- package/dist/core/ai/provider.js +2 -2
- package/dist/core/ai/provider.js.map +1 -1
- package/dist/core/constants.d.ts +12 -1
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.js +15 -1
- package/dist/core/constants.js.map +1 -1
- package/dist/core/event-fields.d.ts +16 -0
- package/dist/core/event-fields.d.ts.map +1 -0
- package/dist/core/event-fields.js +19 -0
- package/dist/core/event-fields.js.map +1 -0
- package/dist/core/queue/index.d.ts.map +1 -1
- package/dist/core/queue/index.js +3 -4
- package/dist/core/queue/index.js.map +1 -1
- package/dist/core/storage/base.d.ts +36 -3
- package/dist/core/storage/base.d.ts.map +1 -1
- package/dist/core/storage/base.js +101 -58
- package/dist/core/storage/base.js.map +1 -1
- package/dist/core/storage/events.d.ts +92 -3
- package/dist/core/storage/events.d.ts.map +1 -1
- package/dist/core/storage/events.js +147 -0
- package/dist/core/storage/events.js.map +1 -1
- package/dist/core/storage/routing.d.ts +54 -1
- package/dist/core/storage/routing.d.ts.map +1 -1
- package/dist/core/storage/routing.js +99 -1
- package/dist/core/storage/routing.js.map +1 -1
- package/dist/core/storage/schema.sql +12 -2
- package/dist/core/storage/sessions.d.ts +20 -0
- package/dist/core/storage/sessions.d.ts.map +1 -1
- package/dist/core/storage/sessions.js +59 -0
- package/dist/core/storage/sessions.js.map +1 -1
- package/dist/core/storage/skills.d.ts +23 -0
- package/dist/core/storage/skills.d.ts.map +1 -1
- package/dist/core/storage/skills.js +47 -0
- package/dist/core/storage/skills.js.map +1 -1
- package/dist/core/storage/sqlite.d.ts +35 -2
- package/dist/core/storage/sqlite.d.ts.map +1 -1
- package/dist/core/storage/sqlite.js +93 -4
- package/dist/core/storage/sqlite.js.map +1 -1
- package/dist/core/storage/tasks.d.ts +49 -0
- package/dist/core/storage/tasks.d.ts.map +1 -1
- package/dist/core/storage/tasks.js +143 -1
- package/dist/core/storage/tasks.js.map +1 -1
- package/dist/core/storage/token-usage.d.ts +1 -1
- package/dist/core/storage/token-usage.d.ts.map +1 -1
- package/dist/core/storage/token-usage.js +1 -1
- package/dist/core/storage/token-usage.js.map +1 -1
- package/dist/core/types.d.ts +24 -3
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/core/utils/error-handler.d.ts.map +1 -1
- package/dist/core/utils/error-handler.js +3 -2
- package/dist/core/utils/error-handler.js.map +1 -1
- package/dist/core/utils/git.d.ts +10 -0
- package/dist/core/utils/git.d.ts.map +1 -0
- package/dist/core/utils/git.js +24 -0
- package/dist/core/utils/git.js.map +1 -0
- package/dist/core/utils/logger.d.ts.map +1 -1
- package/dist/core/utils/logger.js +15 -1
- package/dist/core/utils/logger.js.map +1 -1
- package/dist/core/utils/lru-cache.d.ts +1 -0
- package/dist/core/utils/lru-cache.d.ts.map +1 -1
- package/dist/core/utils/lru-cache.js +3 -0
- package/dist/core/utils/lru-cache.js.map +1 -1
- package/dist/core/utils/token-tracker.js +1 -1
- package/dist/core/utils/token-tracker.js.map +1 -1
- package/dist/daemon/event-parser.d.ts.map +1 -1
- package/dist/daemon/event-parser.js +2 -1
- package/dist/daemon/event-parser.js.map +1 -1
- package/dist/daemon/handlers/history-exporter.js.map +1 -1
- package/dist/daemon/handlers/post-tool-use.d.ts.map +1 -1
- package/dist/daemon/handlers/post-tool-use.js +7 -3
- package/dist/daemon/handlers/post-tool-use.js.map +1 -1
- package/dist/daemon/handlers/stop.d.ts +4 -0
- package/dist/daemon/handlers/stop.d.ts.map +1 -1
- package/dist/daemon/handlers/stop.js +23 -35
- package/dist/daemon/handlers/stop.js.map +1 -1
- package/dist/daemon/handlers/user-prompt.d.ts +3 -3
- package/dist/daemon/handlers/user-prompt.d.ts.map +1 -1
- package/dist/daemon/handlers/user-prompt.js +12 -22
- package/dist/daemon/handlers/user-prompt.js.map +1 -1
- package/dist/daemon/hook-sync.d.ts +17 -0
- package/dist/daemon/hook-sync.d.ts.map +1 -0
- package/dist/daemon/hook-sync.js +74 -0
- package/dist/daemon/hook-sync.js.map +1 -0
- package/dist/daemon/index.d.ts.map +1 -1
- package/dist/daemon/index.js +33 -9
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/lifecycle.js +3 -4
- package/dist/daemon/lifecycle.js.map +1 -1
- package/dist/daemon/server.d.ts +6 -4
- package/dist/daemon/server.d.ts.map +1 -1
- package/dist/daemon/server.js +76 -85
- package/dist/daemon/server.js.map +1 -1
- package/dist/daemon/services/task-segmenter.js +1 -1
- package/dist/daemon/services/task-segmenter.js.map +1 -1
- package/dist/hooks/hook-lib.sh +37 -0
- package/dist/hooks/notification.sh +2 -2
- package/dist/hooks/post-tool-use.sh +2 -2
- package/dist/hooks/pre-tool-use.sh +2 -2
- package/dist/hooks/stop.sh +9 -6
- package/dist/hooks/user-prompt-submit.sh +2 -2
- package/dist/{daemon/services → web/analytics}/anti-pattern-detector.d.ts +3 -4
- package/dist/web/analytics/anti-pattern-detector.d.ts.map +1 -0
- package/dist/{daemon/services → web/analytics}/anti-pattern-detector.js +7 -46
- package/dist/{daemon/services → web/analytics}/anti-pattern-detector.js.map +1 -1
- package/dist/web/analytics/drift-detector.d.ts.map +1 -0
- package/dist/{daemon/services → web/analytics}/drift-detector.js +10 -13
- package/dist/web/analytics/drift-detector.js.map +1 -0
- package/dist/web/analytics/weekly-report.d.ts.map +1 -0
- package/dist/{daemon/services → web/analytics}/weekly-report.js +51 -50
- package/dist/web/analytics/weekly-report.js.map +1 -0
- package/dist/web/auth-middleware.d.ts.map +1 -1
- package/dist/web/auth-middleware.js +1 -2
- package/dist/web/auth-middleware.js.map +1 -1
- package/dist/web/routes/_helpers.d.ts +16 -0
- package/dist/web/routes/_helpers.d.ts.map +1 -0
- package/dist/web/routes/_helpers.js +32 -0
- package/dist/web/routes/_helpers.js.map +1 -0
- package/dist/web/routes/drift.js +1 -1
- package/dist/web/routes/drift.js.map +1 -1
- package/dist/web/routes/insights.js +1 -1
- package/dist/web/routes/insights.js.map +1 -1
- package/dist/web/routes/reports.js +1 -1
- package/dist/web/routes/reports.js.map +1 -1
- package/dist/web/routes/rules.d.ts +3 -0
- package/dist/web/routes/rules.d.ts.map +1 -1
- package/dist/web/routes/rules.js +28 -52
- package/dist/web/routes/rules.js.map +1 -1
- package/dist/web/routes/sessions.d.ts.map +1 -1
- package/dist/web/routes/sessions.js +16 -30
- package/dist/web/routes/sessions.js.map +1 -1
- package/dist/web/routes/skill-stats.d.ts +2 -0
- package/dist/web/routes/skill-stats.d.ts.map +1 -1
- package/dist/web/routes/skill-stats.js +28 -64
- package/dist/web/routes/skill-stats.js.map +1 -1
- package/dist/web/routes/skills.d.ts.map +1 -1
- package/dist/web/routes/skills.js +5 -4
- package/dist/web/routes/skills.js.map +1 -1
- package/dist/web/routes/stats.d.ts +4 -0
- package/dist/web/routes/stats.d.ts.map +1 -1
- package/dist/web/routes/stats.js +19 -21
- package/dist/web/routes/stats.js.map +1 -1
- package/dist/web/routes/tasks.d.ts.map +1 -1
- package/dist/web/routes/tasks.js +17 -42
- package/dist/web/routes/tasks.js.map +1 -1
- package/dist/web/routes/trace.d.ts.map +1 -1
- package/dist/web/routes/trace.js +7 -17
- package/dist/web/routes/trace.js.map +1 -1
- package/dist/web/routes/types.d.ts.map +1 -1
- package/dist/web/routes/types.js +4 -3
- package/dist/web/routes/types.js.map +1 -1
- package/dist/web/static/assets/{AIConfig-BQCAQE9D.js → AIConfig-CdDWzJyO.js} +2 -2
- package/dist/web/static/assets/{AIConfig-BQCAQE9D.js.map → AIConfig-CdDWzJyO.js.map} +1 -1
- package/dist/web/static/assets/{Dashboard-D7Bo6Kan.js → Dashboard-CoEmmIDt.js} +2 -2
- package/dist/web/static/assets/{Dashboard-D7Bo6Kan.js.map → Dashboard-CoEmmIDt.js.map} +1 -1
- package/dist/web/static/assets/{Drawer-BeHRQxUS.js → Drawer-DdRTzlLB.js} +2 -2
- package/dist/web/static/assets/{Drawer-BeHRQxUS.js.map → Drawer-DdRTzlLB.js.map} +1 -1
- package/dist/web/static/assets/{Events-K_tCY2ti.js → Events-DrIq1SUS.js} +2 -2
- package/dist/web/static/assets/{Events-K_tCY2ti.js.map → Events-DrIq1SUS.js.map} +1 -1
- package/dist/web/static/assets/{Reports-BJCmBnc_.js → Reports-DFBM3MDK.js} +2 -2
- package/dist/web/static/assets/{Reports-BJCmBnc_.js.map → Reports-DFBM3MDK.js.map} +1 -1
- package/dist/web/static/assets/{SearchInput-BX2KhMkw.js → SearchInput-qCj_jAcf.js} +2 -2
- package/dist/web/static/assets/{SearchInput-BX2KhMkw.js.map → SearchInput-qCj_jAcf.js.map} +1 -1
- package/dist/web/static/assets/{SessionDetail-Bkr-kC7V.js → SessionDetail-CCzwdoT7.js} +2 -2
- package/dist/web/static/assets/{SessionDetail-Bkr-kC7V.js.map → SessionDetail-CCzwdoT7.js.map} +1 -1
- package/dist/web/static/assets/{Sessions-Chx9OCLH.js → Sessions-FfLYkAw9.js} +2 -2
- package/dist/web/static/assets/{Sessions-Chx9OCLH.js.map → Sessions-FfLYkAw9.js.map} +1 -1
- package/dist/web/static/assets/{Skills-O0GT1i7m.js → Skills-C8Gvs3Qa.js} +2 -2
- package/dist/web/static/assets/{Skills-O0GT1i7m.js.map → Skills-C8Gvs3Qa.js.map} +1 -1
- package/dist/web/static/assets/TaskDetail-BS8pYhaR.js +2 -0
- package/dist/web/static/assets/TaskDetail-BS8pYhaR.js.map +1 -0
- package/dist/web/static/assets/Tasks-CyuhizG8.js +2 -0
- package/dist/web/static/assets/Tasks-CyuhizG8.js.map +1 -0
- package/dist/web/static/assets/index-CBX47X8l.js +3 -0
- package/dist/web/static/assets/{index-DxIbmNmr.js.map → index-CBX47X8l.js.map} +1 -1
- package/dist/web/static/assets/index-DjIoMdoR.css +1 -0
- package/dist/web/static/assets/{lucide-fJlPI3H7.js → lucide-Bs_edTLa.js} +44 -39
- package/dist/web/static/assets/lucide-Bs_edTLa.js.map +1 -0
- package/dist/web/static/assets/react-router-r79dBVy4.js +20 -0
- package/dist/web/static/assets/{react-router-I-HqunH7.js.map → react-router-r79dBVy4.js.map} +1 -1
- package/dist/web/static/assets/task-title-BhOcemuR.js +2 -0
- package/dist/web/static/assets/task-title-BhOcemuR.js.map +1 -0
- package/dist/web/static/index.html +4 -4
- package/docs/design/h1-storage-aggregation-spec-20260518-1121.md +299 -0
- package/docs/design/h2-getdatabase-encapsulation-spec-20260518-1450.md +191 -0
- package/docs/design/h3-fallback-removal-spec-20260518-1245.md +76 -0
- package/docs/design/h4-index-dedup-spec-20260518-1230.md +109 -0
- package/docs/design/h6-services-migration-spec-20260518-1355.md +82 -0
- package/docs/design/l1-swarm-protocol-extract-spec-20260518-1605.md +106 -0
- package/docs/design/m10-forge-paths-spec-20260518-1320.md +121 -0
- package/docs/design/m2-m3-tool-input-spec-20260518-1425.md +131 -0
- package/docs/design/m7-routing-event-association-spec-20260518-1545.md +103 -0
- package/docs/design/project-path-gitroot-spec-20260518-1715.md +134 -0
- package/docs/design/task-active-gc-spec-20260518-1745.md +146 -0
- package/docs/implementation/h1-storage-aggregation-changelog-20260518-1121.md +82 -0
- package/docs/implementation/h2-final-changelog-20260518-1530.md +61 -0
- package/docs/implementation/h2-phase1-safety-net-changelog-20260518-1450.md +70 -0
- package/docs/implementation/h2-phase2-operations-changelog-20260518-1450.md +120 -0
- package/docs/implementation/h2-phase3-callsites-changelog-20260518-1450.md +71 -0
- package/docs/implementation/h3-fallback-removal-changelog-20260518-1245.md +71 -0
- package/docs/implementation/h4-index-dedup-changelog-20260518-1230.md +60 -0
- package/docs/implementation/h6-services-migration-changelog-20260518-1355.md +46 -0
- package/docs/implementation/h7-m9-defaults-changelog-20260518-1300.md +46 -0
- package/docs/implementation/l1-swarm-protocol-extract-changelog-20260518-1605.md +45 -0
- package/docs/implementation/l3-l4-daemon-perf-changelog-20260518-1410.md +63 -0
- package/docs/implementation/l6-l8-final-cleanup-changelog-20260518-1640.md +38 -0
- package/docs/implementation/m1-m4-m5-l7-cleanup-changelog-20260518-1310.md +58 -0
- package/docs/implementation/m10-forge-paths-changelog-20260518-1320.md +60 -0
- package/docs/implementation/m2-m3-tool-input-changelog-20260518-1425.md +43 -0
- package/docs/implementation/m6-m8-naming-shutdown-changelog-20260518-1340.md +56 -0
- package/docs/implementation/m7-routing-association-changelog-20260518-1545.md +69 -0
- package/docs/implementation/project-path-gitroot-changelog-20260518-1715.md +63 -0
- package/docs/implementation/task-active-gc-changelog-20260518-1745.md +35 -0
- package/docs/implementation/task-title-summary-changelog-20260518-1130.md +39 -0
- package/docs/implementation/tasks-detail-back-loses-filters-changelog-20260518-1100.md +22 -0
- package/docs/implementation/tasks-page-white-screen-hotfix-changelog-20260518-1015.md +56 -0
- package/docs/reviews/task-title-summary.md +92 -0
- package/docs/reviews/tasks-detail-back-loses-filters.md +58 -0
- package/docs/reviews/tasks-page-white-screen-hotfix.md +126 -0
- package/package.json +2 -2
- package/src/claudemd/claudemd-generator.ts +29 -238
- package/src/claudemd/resume-manager.ts +1 -1
- package/src/claudemd/templates/swarm-protocol.md +222 -0
- package/src/cli/commands/daemon.ts +6 -6
- package/src/cli/commands/executions.ts +4 -3
- package/src/cli/commands/init.ts +2 -2
- package/src/cli/commands/logs.ts +1 -1
- package/src/cli/commands/mcp.ts +3 -5
- package/src/cli/commands/menu.ts +4 -3
- package/src/cli/commands/stats.ts +2 -3
- package/src/cli/commands/status.ts +2 -2
- package/src/cli/commands/trace.ts +10 -26
- package/src/cli/init/hook-manager.ts +2 -2
- package/src/core/ai/provider.ts +2 -2
- package/src/core/constants.ts +18 -1
- package/src/core/event-fields.ts +32 -0
- package/src/core/queue/index.ts +3 -4
- package/src/core/storage/base.ts +132 -56
- package/src/core/storage/events.ts +183 -4
- package/src/core/storage/routing.ts +129 -1
- package/src/core/storage/schema.sql +12 -2
- package/src/core/storage/sessions.ts +64 -0
- package/src/core/storage/skills.ts +69 -0
- package/src/core/storage/sqlite.ts +103 -4
- package/src/core/storage/tasks.ts +149 -1
- package/src/core/storage/token-usage.ts +1 -1
- package/src/core/types.ts +30 -3
- package/src/core/utils/error-handler.ts +3 -2
- package/src/core/utils/git.ts +23 -0
- package/src/core/utils/logger.ts +16 -1
- package/src/core/utils/lru-cache.ts +4 -0
- package/src/core/utils/token-tracker.ts +1 -1
- package/src/daemon/event-parser.ts +4 -3
- package/src/daemon/handlers/history-exporter.ts +1 -1
- package/src/daemon/handlers/post-tool-use.ts +7 -3
- package/src/daemon/handlers/stop.ts +32 -39
- package/src/daemon/handlers/user-prompt.ts +12 -22
- package/src/daemon/hook-sync.ts +91 -0
- package/src/daemon/index.ts +34 -10
- package/src/daemon/lifecycle.ts +3 -3
- package/src/daemon/server.ts +76 -89
- package/src/daemon/services/task-segmenter.ts +1 -1
- package/src/hooks/hook-lib.sh +37 -0
- package/src/hooks/notification.sh +2 -2
- package/src/hooks/post-tool-use.sh +2 -2
- package/src/hooks/pre-tool-use.sh +2 -2
- package/src/hooks/stop.sh +9 -6
- package/src/hooks/user-prompt-submit.sh +2 -2
- package/src/{daemon/services → web/analytics}/anti-pattern-detector.ts +9 -54
- package/src/{daemon/services → web/analytics}/drift-detector.ts +10 -23
- package/src/{daemon/services → web/analytics}/weekly-report.ts +52 -75
- package/src/web/auth-middleware.ts +1 -2
- package/src/web/routes/_helpers.ts +34 -0
- package/src/web/routes/drift.ts +1 -1
- package/src/web/routes/insights.ts +1 -1
- package/src/web/routes/reports.ts +1 -1
- package/src/web/routes/rules.ts +31 -56
- package/src/web/routes/sessions.ts +18 -30
- package/src/web/routes/skill-stats.ts +29 -69
- package/src/web/routes/skills.ts +5 -4
- package/src/web/routes/stats.ts +19 -29
- package/src/web/routes/tasks.ts +17 -42
- package/src/web/routes/trace.ts +7 -19
- package/src/web/routes/types.ts +4 -3
- package/tests/integration/claudemd-generator.test.ts +90 -0
- package/tests/integration/web-analytics.integration.test.ts +133 -0
- package/tests/integration/web-stats.integration.test.ts +135 -0
- package/tests/integration/web-trace.integration.test.ts +175 -0
- package/tests/unit/core/forge-paths.test.ts +99 -0
- package/tests/unit/daemon/hook-sync.test.ts +71 -0
- package/tests/unit/daemon/post-tool-use.test.ts +121 -0
- package/tests/unit/daemon/stop-handler-behavior-summary.test.ts +202 -0
- package/tests/unit/daemon/task-segmenter-recover.test.ts +84 -0
- package/tests/unit/event-fields.test.ts +88 -0
- package/tests/unit/event-parser.test.ts +55 -0
- package/tests/unit/hooks/resolve-project-path.test.ts +122 -0
- package/tests/unit/socket-server.test.ts +183 -0
- package/tests/unit/storage/event-operations-aggregates.test.ts +342 -0
- package/tests/unit/storage/migration-idempotent.test.ts +304 -0
- package/tests/unit/storage/routing-aggregates.test.ts +276 -0
- package/tests/unit/storage/routing.test.ts +117 -0
- package/tests/unit/storage/schema-missing.test.ts +81 -0
- package/tests/unit/storage/session-operations-aggregates.test.ts +120 -0
- package/tests/unit/storage/skill-operations-counts.test.ts +106 -0
- package/tests/unit/storage/skills-aggregates.test.ts +104 -0
- package/tests/unit/storage/sqlite-refactor-harness.test.ts +3 -3
- package/tests/unit/storage/task-operations-counts.test.ts +46 -0
- package/tests/unit/storage/tasks-getById.test.ts +343 -0
- package/tests/unit/storage/tasks-stale-gc.test.ts +86 -0
- package/tests/unit/token-usage.test.ts +6 -6
- package/tests/unit/web/navigation-back-contract.test.ts +134 -0
- package/tests/unit/web/routes-rules.test.ts +182 -0
- package/tests/unit/web/routes-tasks.test.ts +34 -0
- package/tests/unit/web/task-title-contract.test.ts +210 -0
- package/tests/unit/web/tasks-component-contract.test.ts +179 -0
- package/vitest.config.ts +1 -1
- package/web/src/pages/TaskDetail.tsx +9 -5
- package/web/src/pages/Tasks.tsx +315 -50
- package/web/src/utils/navigation.ts +25 -0
- package/web/src/utils/task-title.ts +49 -0
- package/dist/daemon/services/anti-pattern-detector.d.ts.map +0 -1
- package/dist/daemon/services/drift-detector.d.ts.map +0 -1
- package/dist/daemon/services/drift-detector.js.map +0 -1
- package/dist/daemon/services/weekly-report.d.ts.map +0 -1
- package/dist/daemon/services/weekly-report.js.map +0 -1
- package/dist/web/static/assets/TaskDetail-5SR8zGzv.js +0 -2
- package/dist/web/static/assets/TaskDetail-5SR8zGzv.js.map +0 -1
- package/dist/web/static/assets/Tasks-DCgDqvOZ.js +0 -2
- package/dist/web/static/assets/Tasks-DCgDqvOZ.js.map +0 -1
- package/dist/web/static/assets/index-D8AKj26b.css +0 -1
- package/dist/web/static/assets/index-DxIbmNmr.js +0 -3
- package/dist/web/static/assets/lucide-fJlPI3H7.js.map +0 -1
- package/dist/web/static/assets/react-router-I-HqunH7.js +0 -20
- /package/dist/{daemon/services → web/analytics}/drift-detector.d.ts +0 -0
- /package/dist/{daemon/services → web/analytics}/weekly-report.d.ts +0 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for /api/rules/hit-rate.
|
|
3
|
+
*
|
|
4
|
+
* H1 baseline — establishes contract before migrating rules.ts to SQL aggregates.
|
|
5
|
+
* Response shape must remain identical after the route refactor.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
9
|
+
import express, { type Application } from 'express';
|
|
10
|
+
import request from 'supertest';
|
|
11
|
+
import { SQLiteStorage } from '../../../src/core/storage/sqlite.js';
|
|
12
|
+
import { registerRulesRoutes } from '../../../src/web/routes/rules.js';
|
|
13
|
+
import type { SkillRegistry } from '../../../src/skills/registry.js';
|
|
14
|
+
|
|
15
|
+
const SESSION = 'sess-rules';
|
|
16
|
+
const PROJECT = '/tmp/proj-rules';
|
|
17
|
+
|
|
18
|
+
/** Minimal SkillRegistry stub for the never-triggered list. */
|
|
19
|
+
function makeRegistry(ids: string[]): SkillRegistry {
|
|
20
|
+
return {
|
|
21
|
+
getAll: () => ids.map(id => ({ id })),
|
|
22
|
+
} as unknown as SkillRegistry;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function makeInv(opts: {
|
|
26
|
+
id: string;
|
|
27
|
+
skill_id: string;
|
|
28
|
+
success: 0 | 1;
|
|
29
|
+
timestamp: number;
|
|
30
|
+
}) {
|
|
31
|
+
return {
|
|
32
|
+
id: opts.id,
|
|
33
|
+
route_request_id: null,
|
|
34
|
+
session_id: SESSION,
|
|
35
|
+
agent_id: null,
|
|
36
|
+
skill_id: opts.skill_id,
|
|
37
|
+
invocation_type: 'dynamic' as const,
|
|
38
|
+
reason: null,
|
|
39
|
+
workflow: null, phase: null, feature_slug: null, artifact_path: null,
|
|
40
|
+
depth: 0,
|
|
41
|
+
success: opts.success,
|
|
42
|
+
error: opts.success === 0 ? 'boom' : null,
|
|
43
|
+
timestamp: opts.timestamp,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe('GET /api/rules/hit-rate', () => {
|
|
48
|
+
let app: Application;
|
|
49
|
+
let storage: SQLiteStorage;
|
|
50
|
+
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
storage = new SQLiteStorage(':memory:');
|
|
53
|
+
app = express();
|
|
54
|
+
app.use(express.json());
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
afterEach(() => {
|
|
58
|
+
storage.close();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('空数据:summary 全 0,skills/agents 为空,neverTriggered 列出 registry 全部', async () => {
|
|
62
|
+
registerRulesRoutes(app, { storage, skillRegistry: makeRegistry(['tdd', 'debug']) });
|
|
63
|
+
|
|
64
|
+
const res = await request(app).get('/api/rules/hit-rate').query({ days: 7 });
|
|
65
|
+
expect(res.status).toBe(200);
|
|
66
|
+
expect(res.body.period.days).toBe(7);
|
|
67
|
+
expect(typeof res.body.period.since).toBe('string');
|
|
68
|
+
expect(res.body.summary).toEqual({
|
|
69
|
+
totalPrompts: 0,
|
|
70
|
+
agentDelegations: 0,
|
|
71
|
+
agentRate: '0%',
|
|
72
|
+
skillInvocations: 0,
|
|
73
|
+
skillRate: '0%',
|
|
74
|
+
});
|
|
75
|
+
expect(res.body.skills).toEqual([]);
|
|
76
|
+
expect(res.body.agents).toEqual([]);
|
|
77
|
+
expect(res.body.neverTriggered.sort()).toEqual(['debug', 'tdd']);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('混合数据:totalPrompts、agentDelegations(obeyed=1)、agents 排序、skills 频次、neverTriggered 排除已触发', async () => {
|
|
81
|
+
registerRulesRoutes(app, { storage, skillRegistry: makeRegistry(['tdd', 'debug', 'unused-skill']) });
|
|
82
|
+
|
|
83
|
+
const now = Date.now();
|
|
84
|
+
// 5 个 routing events,3 个 obeyed (2 researcher + 1 coder)
|
|
85
|
+
storage.writeRoutingEvent({
|
|
86
|
+
session_id: SESSION, project_path: PROJECT, ts: now,
|
|
87
|
+
prompt: 'p1', intent_json: '{}',
|
|
88
|
+
routed_to_type: 'agent', routed_to_name: 'researcher', obeyed: 1,
|
|
89
|
+
});
|
|
90
|
+
storage.writeRoutingEvent({
|
|
91
|
+
session_id: SESSION, project_path: PROJECT, ts: now,
|
|
92
|
+
prompt: 'p2', intent_json: '{}',
|
|
93
|
+
routed_to_type: 'agent', routed_to_name: 'researcher', obeyed: 1,
|
|
94
|
+
});
|
|
95
|
+
storage.writeRoutingEvent({
|
|
96
|
+
session_id: SESSION, project_path: PROJECT, ts: now,
|
|
97
|
+
prompt: 'p3', intent_json: '{}',
|
|
98
|
+
routed_to_type: 'agent', routed_to_name: 'coder', obeyed: 1,
|
|
99
|
+
});
|
|
100
|
+
storage.writeRoutingEvent({
|
|
101
|
+
session_id: SESSION, project_path: PROJECT, ts: now,
|
|
102
|
+
prompt: 'p4', intent_json: '{}',
|
|
103
|
+
routed_to_type: 'agent', routed_to_name: 'tester', obeyed: 0,
|
|
104
|
+
});
|
|
105
|
+
storage.writeRoutingEvent({
|
|
106
|
+
session_id: SESSION, project_path: PROJECT, ts: now,
|
|
107
|
+
prompt: 'p5', intent_json: '{}',
|
|
108
|
+
routed_to_type: 'skill', routed_to_name: 'tdd', obeyed: null,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// 3 个 skill invocations
|
|
112
|
+
storage.writeSkillInvocation(makeInv({ id: 's1', skill_id: 'tdd', success: 1, timestamp: now }));
|
|
113
|
+
storage.writeSkillInvocation(makeInv({ id: 's2', skill_id: 'tdd', success: 0, timestamp: now }));
|
|
114
|
+
storage.writeSkillInvocation(makeInv({ id: 's3', skill_id: 'debug', success: 1, timestamp: now }));
|
|
115
|
+
|
|
116
|
+
const res = await request(app).get('/api/rules/hit-rate').query({ days: 7 });
|
|
117
|
+
expect(res.status).toBe(200);
|
|
118
|
+
|
|
119
|
+
// Summary
|
|
120
|
+
expect(res.body.summary.totalPrompts).toBe(5);
|
|
121
|
+
expect(res.body.summary.agentDelegations).toBe(3);
|
|
122
|
+
expect(res.body.summary.agentRate).toBe('60.0%');
|
|
123
|
+
expect(res.body.summary.skillInvocations).toBe(3);
|
|
124
|
+
expect(res.body.summary.skillRate).toBe('60.0%');
|
|
125
|
+
|
|
126
|
+
// Skills 排序 by total desc
|
|
127
|
+
expect(res.body.skills).toHaveLength(2);
|
|
128
|
+
expect(res.body.skills[0]).toEqual({
|
|
129
|
+
skill_id: 'tdd', total: 2, success: 1, failed: 1, rate: '40.0%',
|
|
130
|
+
});
|
|
131
|
+
expect(res.body.skills[1]).toEqual({
|
|
132
|
+
skill_id: 'debug', total: 1, success: 1, failed: 0, rate: '20.0%',
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Agents 排序 by count desc,仅 obeyed=1
|
|
136
|
+
expect(res.body.agents).toHaveLength(2);
|
|
137
|
+
expect(res.body.agents[0]).toEqual({ agent: 'researcher', count: 2, rate: '40.0%' });
|
|
138
|
+
expect(res.body.agents[1]).toEqual({ agent: 'coder', count: 1, rate: '20.0%' });
|
|
139
|
+
|
|
140
|
+
// neverTriggered = registry - skills with invocations
|
|
141
|
+
expect(res.body.neverTriggered).toEqual(['unused-skill']);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('days 默认 7、可被 query 覆盖', async () => {
|
|
145
|
+
registerRulesRoutes(app, { storage, skillRegistry: makeRegistry([]) });
|
|
146
|
+
|
|
147
|
+
const res1 = await request(app).get('/api/rules/hit-rate');
|
|
148
|
+
expect(res1.body.period.days).toBe(7);
|
|
149
|
+
|
|
150
|
+
const res2 = await request(app).get('/api/rules/hit-rate').query({ days: 30 });
|
|
151
|
+
expect(res2.body.period.days).toBe(30);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('days 窗口过滤:旧 routing/skill 数据不计入', async () => {
|
|
155
|
+
registerRulesRoutes(app, { storage, skillRegistry: makeRegistry(['tdd']) });
|
|
156
|
+
|
|
157
|
+
const old = Date.now() - 30 * 24 * 3600 * 1000;
|
|
158
|
+
storage.writeRoutingEvent({
|
|
159
|
+
session_id: SESSION, project_path: PROJECT, ts: old,
|
|
160
|
+
prompt: 'old', intent_json: '{}',
|
|
161
|
+
routed_to_type: 'agent', routed_to_name: 'researcher', obeyed: 1,
|
|
162
|
+
});
|
|
163
|
+
storage.writeSkillInvocation(makeInv({ id: 's-old', skill_id: 'tdd', success: 1, timestamp: old }));
|
|
164
|
+
|
|
165
|
+
const res = await request(app).get('/api/rules/hit-rate').query({ days: 7 });
|
|
166
|
+
expect(res.body.summary.totalPrompts).toBe(0);
|
|
167
|
+
expect(res.body.summary.skillInvocations).toBe(0);
|
|
168
|
+
expect(res.body.skills).toEqual([]);
|
|
169
|
+
expect(res.body.agents).toEqual([]);
|
|
170
|
+
// 旧数据没触发 → tdd 仍在 neverTriggered
|
|
171
|
+
expect(res.body.neverTriggered).toEqual(['tdd']);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('skillRegistry 缺失:neverTriggered 为空', async () => {
|
|
175
|
+
// 不传 skillRegistry
|
|
176
|
+
registerRulesRoutes(app, { storage });
|
|
177
|
+
|
|
178
|
+
const res = await request(app).get('/api/rules/hit-rate');
|
|
179
|
+
expect(res.status).toBe(200);
|
|
180
|
+
expect(res.body.neverTriggered).toEqual([]);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
@@ -128,6 +128,40 @@ describe('Tasks Routes', () => {
|
|
|
128
128
|
expect(task).toHaveProperty('status');
|
|
129
129
|
expect(task).toHaveProperty('event_count');
|
|
130
130
|
});
|
|
131
|
+
|
|
132
|
+
// ── safety-net:task-title-summary-real ─────────────────────────────────
|
|
133
|
+
// These tests assert the first_prompt field must be present in API items.
|
|
134
|
+
// They will be RED until the backend SQL subquery is added (Phase 2 fix).
|
|
135
|
+
|
|
136
|
+
it('safety-net: every item has first_prompt key (may be null)', async () => {
|
|
137
|
+
seedSession(storage, SESSION, PROJECT_A);
|
|
138
|
+
storage.writeTask({ id: 'fp-check', session_id: SESSION, title: '<task-notification>', start_time: ts() });
|
|
139
|
+
const res = await request(app).get('/api/tasks');
|
|
140
|
+
expect(res.status).toBe(200);
|
|
141
|
+
expect(res.body.items).toHaveLength(1);
|
|
142
|
+
// first_prompt key must exist in the response (value may be null when no event)
|
|
143
|
+
expect(res.body.items[0]).toHaveProperty('first_prompt');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('safety-net: first_prompt contains user_prompt text when event exists', async () => {
|
|
147
|
+
seedSession(storage, SESSION, PROJECT_A);
|
|
148
|
+
const taskStart = ts();
|
|
149
|
+
storage.writeTask({ id: 'fp-event', session_id: SESSION, title: '<task-notification>', start_time: taskStart });
|
|
150
|
+
// Write a UserPromptSubmit event for this session after task start
|
|
151
|
+
storage.writeEvent({
|
|
152
|
+
event_id: EV_PROMPT,
|
|
153
|
+
session_id: SESSION, project_path: PROJECT_A,
|
|
154
|
+
timestamp: ts(100),
|
|
155
|
+
hook_type: 'UserPromptSubmit',
|
|
156
|
+
user_prompt: '<task-notification>\n<summary>Fix the login bug</summary>\n</task-notification>',
|
|
157
|
+
});
|
|
158
|
+
const res = await request(app).get('/api/tasks');
|
|
159
|
+
expect(res.status).toBe(200);
|
|
160
|
+
expect(res.body.items).toHaveLength(1);
|
|
161
|
+
const fp = res.body.items[0].first_prompt as string | null;
|
|
162
|
+
expect(fp).not.toBeNull();
|
|
163
|
+
expect(fp).toContain('Fix the login bug');
|
|
164
|
+
});
|
|
131
165
|
});
|
|
132
166
|
|
|
133
167
|
// ─────────────────────────────────────────────────────────────────────────
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safety-net + TDD contract tests for normalizeTaskTitle()
|
|
3
|
+
*
|
|
4
|
+
* harness/safety-net:task-title-summary
|
|
5
|
+
*
|
|
6
|
+
* Root cause: Tasks stored with title = raw <task-notification> XML (sub-agent
|
|
7
|
+
* completion callbacks). The frontend renders the literal XML string, making
|
|
8
|
+
* task titles completely unreadable.
|
|
9
|
+
*
|
|
10
|
+
* This file locks the contract for the pure helper `normalizeTaskTitle`:
|
|
11
|
+
* - written BEFORE the implementation (TDD red phase)
|
|
12
|
+
* - no React / DOM dependency — pure function only
|
|
13
|
+
* - covers passthrough, fallback, XML extraction, edge cases
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, it, expect } from 'vitest';
|
|
17
|
+
|
|
18
|
+
// ── Import under test (will fail until task-title.ts is created) ─────────────
|
|
19
|
+
// Adjust path to match web/src/utils/task-title.ts resolved from project root.
|
|
20
|
+
// Because vitest.config.ts only includes tests/unit/**, we use a relative path
|
|
21
|
+
// from this file up to web/src/utils/.
|
|
22
|
+
import { normalizeTaskTitle } from '../../../web/src/utils/task-title';
|
|
23
|
+
|
|
24
|
+
// ── Fixtures ──────────────────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
const TASK_NOTIFICATION_FULL = `<task-notification>
|
|
27
|
+
<task-id>aefe161c3350644df</task-id>
|
|
28
|
+
<tool-use-id>toolu_01XxXxXxXx</tool-use-id>
|
|
29
|
+
<output-file>/private/tmp/something/xxx.output</output-file>
|
|
30
|
+
<status>completed</status>
|
|
31
|
+
<summary>Agent "Hotfix Tasks 返回丢筛选" completed</summary>
|
|
32
|
+
<result>Task finished successfully</result>
|
|
33
|
+
<usage><total_tokens>57809</total_tokens><tool_uses>37</tool_uses><duration_ms>289676</duration_ms></usage>
|
|
34
|
+
</task-notification>`;
|
|
35
|
+
|
|
36
|
+
const TASK_NOTIFICATION_NO_SUMMARY = `<task-notification>
|
|
37
|
+
<task-id>deadbeef</task-id>
|
|
38
|
+
<status>completed</status>
|
|
39
|
+
</task-notification>`;
|
|
40
|
+
|
|
41
|
+
const TASK_NOTIFICATION_EMOJI_SUMMARY = `<task-notification>
|
|
42
|
+
<summary>Agent "修复 Bug 🐛" completed — see /tmp/report.md</summary>
|
|
43
|
+
</task-notification>`;
|
|
44
|
+
|
|
45
|
+
const TASK_NOTIFICATION_QUOTES_SUMMARY = `<task-notification>
|
|
46
|
+
<summary>Agent "it's a 'test' with "quotes"" done</summary>
|
|
47
|
+
</task-notification>`;
|
|
48
|
+
|
|
49
|
+
const LONG_SUMMARY_NOTIFICATION = `<task-notification>
|
|
50
|
+
<summary>Agent completed a very long task description that exceeds the maximum allowed display length of eighty characters in the UI widget</summary>
|
|
51
|
+
</task-notification>`;
|
|
52
|
+
|
|
53
|
+
const INLINE_CLOSING_TAG = `<task-notification>
|
|
54
|
+
<summary>First match</summary><summary>Should not appear</summary>
|
|
55
|
+
</task-notification>`;
|
|
56
|
+
|
|
57
|
+
// ── Tests ──────────────────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
describe('normalizeTaskTitle — contract (harness/safety-net:task-title-summary)', () => {
|
|
60
|
+
|
|
61
|
+
// ── 1. Passthrough ─────────────────────────────────────────────────────────
|
|
62
|
+
describe('passthrough for regular titles', () => {
|
|
63
|
+
it('returns a normal title unchanged', () => {
|
|
64
|
+
expect(normalizeTaskTitle('批准')).toBe('批准');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('returns a regular English title unchanged', () => {
|
|
68
|
+
expect(normalizeTaskTitle('Fix login crash')).toBe('Fix login crash');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('trims leading and trailing whitespace', () => {
|
|
72
|
+
expect(normalizeTaskTitle(' hello world ')).toBe('hello world');
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// ── 2. Fallback for empty / null / undefined ────────────────────────────────
|
|
77
|
+
describe('fallback for empty / null / undefined', () => {
|
|
78
|
+
it('returns fallback for empty string', () => {
|
|
79
|
+
expect(normalizeTaskTitle('')).toBe('(无标题)');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('returns fallback for whitespace-only string', () => {
|
|
83
|
+
expect(normalizeTaskTitle(' ')).toBe('(无标题)');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('returns fallback for null', () => {
|
|
87
|
+
expect(normalizeTaskTitle(null)).toBe('(无标题)');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('returns fallback for undefined', () => {
|
|
91
|
+
expect(normalizeTaskTitle(undefined)).toBe('(无标题)');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// ── 3. task-notification XML extraction ────────────────────────────────────
|
|
96
|
+
describe('<task-notification> XML extraction', () => {
|
|
97
|
+
it('extracts <summary> content from a full notification blob', () => {
|
|
98
|
+
expect(normalizeTaskTitle(TASK_NOTIFICATION_FULL)).toBe(
|
|
99
|
+
'Agent "Hotfix Tasks 返回丢筛选" completed'
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('returns "(子任务回调)" when <summary> tag is absent', () => {
|
|
104
|
+
expect(normalizeTaskTitle(TASK_NOTIFICATION_NO_SUMMARY)).toBe('(子任务回调)');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('returns "(子任务回调)" for bare <task-notification> tag alone', () => {
|
|
108
|
+
expect(normalizeTaskTitle('<task-notification>')).toBe('(子任务回调)');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('preserves emoji and Chinese characters in summary', () => {
|
|
112
|
+
expect(normalizeTaskTitle(TASK_NOTIFICATION_EMOJI_SUMMARY)).toBe(
|
|
113
|
+
'Agent "修复 Bug 🐛" completed — see /tmp/report.md'
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('preserves single quotes and double quotes inside summary', () => {
|
|
118
|
+
expect(normalizeTaskTitle(TASK_NOTIFICATION_QUOTES_SUMMARY)).toBe(
|
|
119
|
+
`Agent "it's a 'test' with "quotes"" done`
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('takes the first <summary> match when multiple are present (defensive)', () => {
|
|
124
|
+
expect(normalizeTaskTitle(INLINE_CLOSING_TAG)).toBe('First match');
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// ── 4. Truncation ──────────────────────────────────────────────────────────
|
|
129
|
+
describe('truncation at 80 characters', () => {
|
|
130
|
+
it('truncates a summary longer than 80 chars and appends ellipsis', () => {
|
|
131
|
+
const result = normalizeTaskTitle(LONG_SUMMARY_NOTIFICATION);
|
|
132
|
+
expect(result.endsWith('…')).toBe(true);
|
|
133
|
+
// The visible text portion is exactly 80 chars (before the ellipsis)
|
|
134
|
+
expect(result.slice(0, -1).length).toBe(80);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('does not truncate a summary of exactly 80 chars', () => {
|
|
138
|
+
const exactly80 = 'A'.repeat(80);
|
|
139
|
+
const notification = `<task-notification><summary>${exactly80}</summary></task-notification>`;
|
|
140
|
+
const result = normalizeTaskTitle(notification);
|
|
141
|
+
expect(result).toBe(exactly80);
|
|
142
|
+
expect(result.endsWith('…')).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('truncates a plain title longer than 80 chars', () => {
|
|
146
|
+
const long = 'B'.repeat(90);
|
|
147
|
+
const result = normalizeTaskTitle(long);
|
|
148
|
+
expect(result.endsWith('…')).toBe(true);
|
|
149
|
+
expect(result.slice(0, -1).length).toBe(80);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('does not truncate a plain title of exactly 80 chars', () => {
|
|
153
|
+
const exactly80 = 'C'.repeat(80);
|
|
154
|
+
expect(normalizeTaskTitle(exactly80)).toBe(exactly80);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// ── 5. Summary whitespace trimming ────────────────────────────────────────
|
|
159
|
+
describe('summary whitespace trimming', () => {
|
|
160
|
+
it('trims whitespace inside <summary> tags', () => {
|
|
161
|
+
const withPad = `<task-notification><summary> trimmed </summary></task-notification>`;
|
|
162
|
+
expect(normalizeTaskTitle(withPad)).toBe('trimmed');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('falls back to "(子任务回调)" when summary is whitespace-only', () => {
|
|
166
|
+
const whitespaceSummary = `<task-notification><summary> </summary></task-notification>`;
|
|
167
|
+
expect(normalizeTaskTitle(whitespaceSummary)).toBe('(子任务回调)');
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// ── 6. safety-net:task-title-summary-real — dual-param with firstPrompt ──
|
|
172
|
+
// These tests will be RED until normalizeTaskTitle is updated to accept a
|
|
173
|
+
// second parameter (firstPrompt). Phase 2 fix turns them GREEN.
|
|
174
|
+
describe('dual-param: title=<task-notification> (19 chars) + firstPrompt', () => {
|
|
175
|
+
const BARE_NOTIFICATION = '<task-notification>';
|
|
176
|
+
|
|
177
|
+
it('extracts summary from firstPrompt when title is bare 19-char token', () => {
|
|
178
|
+
const firstPrompt = '<task-notification>\n<summary>Fix the login bug</summary>\n</task-notification>';
|
|
179
|
+
expect(normalizeTaskTitle(BARE_NOTIFICATION, firstPrompt)).toBe('Fix the login bug');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('shows head of firstPrompt when it has no summary tag', () => {
|
|
183
|
+
const firstPrompt = 'Please investigate the database performance issue and report findings.';
|
|
184
|
+
const result = normalizeTaskTitle(BARE_NOTIFICATION, firstPrompt);
|
|
185
|
+
expect(result).toMatch(/^\(子任务回调\) — /);
|
|
186
|
+
expect(result).toContain('Please investigate');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('falls back to "(子任务回调)" when firstPrompt is null', () => {
|
|
190
|
+
expect(normalizeTaskTitle(BARE_NOTIFICATION, null)).toBe('(子任务回调)');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('falls back to "(子任务回调)" when firstPrompt is undefined', () => {
|
|
194
|
+
expect(normalizeTaskTitle(BARE_NOTIFICATION, undefined)).toBe('(子任务回调)');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('plain title ignores firstPrompt entirely (no contamination)', () => {
|
|
198
|
+
const fp = '<task-notification><summary>Should be ignored</summary></task-notification>';
|
|
199
|
+
expect(normalizeTaskTitle('Fix login crash', fp)).toBe('Fix login crash');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('truncates a long summary from firstPrompt at 80 chars with ellipsis', () => {
|
|
203
|
+
const longSummary = 'A'.repeat(90);
|
|
204
|
+
const fp = `<task-notification><summary>${longSummary}</summary></task-notification>`;
|
|
205
|
+
const result = normalizeTaskTitle(BARE_NOTIFICATION, fp);
|
|
206
|
+
expect(result.endsWith('…')).toBe(true);
|
|
207
|
+
expect(result.slice(0, -1).length).toBe(80);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safety-net: Tasks component API contract test
|
|
3
|
+
*
|
|
4
|
+
* harness/safety-net:tasks-page-white-screen
|
|
5
|
+
*
|
|
6
|
+
* Root cause: Tasks.tsx called GET /api/tasks and treated the response as
|
|
7
|
+
* Task[] (bare array), but the API returns { items: Task[], total, has_more }.
|
|
8
|
+
* Iterating a plain object as an array caused a runtime error → white screen.
|
|
9
|
+
*
|
|
10
|
+
* This test locks the correct API contract so a regression is immediately
|
|
11
|
+
* visible. It also validates the TypeScript-level interface that Tasks.tsx
|
|
12
|
+
* must use when consuming the /api/tasks endpoint.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, it, expect } from 'vitest';
|
|
16
|
+
|
|
17
|
+
// ── Types mirroring the API contract ────────────────────────────────────────
|
|
18
|
+
|
|
19
|
+
interface TaskRecord {
|
|
20
|
+
id: string;
|
|
21
|
+
session_id: string;
|
|
22
|
+
title: string;
|
|
23
|
+
status: 'active' | 'completed' | 'abandoned';
|
|
24
|
+
start_time: string;
|
|
25
|
+
end_time?: string;
|
|
26
|
+
event_count: number;
|
|
27
|
+
project_path?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface TaskPage {
|
|
31
|
+
items: TaskRecord[];
|
|
32
|
+
total: number;
|
|
33
|
+
has_more: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ── Simulated fetch helpers (pure functions, no DOM needed) ──────────────────
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* BROKEN: simulates what the old Tasks.tsx code did — treated the entire
|
|
40
|
+
* response body as a Task[] and tried to .filter() on it.
|
|
41
|
+
* This is the defect we are safety-netting.
|
|
42
|
+
*/
|
|
43
|
+
function consumeTasksResponseBROKEN(responseBody: unknown): TaskRecord[] {
|
|
44
|
+
// Old code: `return res.json()` then `tasks.filter(...)` — treats body as array
|
|
45
|
+
return responseBody as TaskRecord[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* CORRECT: extracts items from the paginated wrapper that /api/tasks returns.
|
|
50
|
+
*/
|
|
51
|
+
function consumeTasksResponseCORRECT(responseBody: TaskPage): TaskRecord[] {
|
|
52
|
+
return responseBody.items;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ── Test fixtures ─────────────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
const TASK_RECORD: TaskRecord = {
|
|
58
|
+
id: 'abc-123',
|
|
59
|
+
session_id: 'sess-001',
|
|
60
|
+
title: 'Test task',
|
|
61
|
+
status: 'active',
|
|
62
|
+
start_time: '2026-05-18T00:00:00.000Z',
|
|
63
|
+
event_count: 5,
|
|
64
|
+
project_path: '/home/user/project',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const API_RESPONSE: TaskPage = {
|
|
68
|
+
items: [TASK_RECORD],
|
|
69
|
+
total: 1,
|
|
70
|
+
has_more: false,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// ── Contract: /api/tasks must return { items, total, has_more } ───────────────
|
|
74
|
+
|
|
75
|
+
describe('Tasks API contract (safety-net: tasks-page-white-screen)', () => {
|
|
76
|
+
describe('API response shape', () => {
|
|
77
|
+
it('response body is an object with items array, not a bare array', () => {
|
|
78
|
+
expect(Array.isArray(API_RESPONSE)).toBe(false);
|
|
79
|
+
expect(typeof API_RESPONSE).toBe('object');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('response.items is the array of task records', () => {
|
|
83
|
+
expect(Array.isArray(API_RESPONSE.items)).toBe(true);
|
|
84
|
+
expect(API_RESPONSE.items).toHaveLength(1);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('response.total is a number >= 0', () => {
|
|
88
|
+
expect(typeof API_RESPONSE.total).toBe('number');
|
|
89
|
+
expect(API_RESPONSE.total).toBeGreaterThanOrEqual(0);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('response.has_more is a boolean', () => {
|
|
93
|
+
expect(typeof API_RESPONSE.has_more).toBe('boolean');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('each item has required fields: id, session_id, title, status, start_time, event_count', () => {
|
|
97
|
+
const item = API_RESPONSE.items[0];
|
|
98
|
+
expect(item).toHaveProperty('id');
|
|
99
|
+
expect(item).toHaveProperty('session_id');
|
|
100
|
+
expect(item).toHaveProperty('title');
|
|
101
|
+
expect(item).toHaveProperty('status');
|
|
102
|
+
expect(item).toHaveProperty('start_time');
|
|
103
|
+
expect(item).toHaveProperty('event_count');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('[CHAR] broken consumer — documents the white-screen defect', () => {
|
|
108
|
+
it('treating response body as Task[] gives an object not an array (this was the bug)', () => {
|
|
109
|
+
// consumeTasksResponseBROKEN returns the whole { items, total, has_more } object
|
|
110
|
+
// as if it were Task[]. Calling array methods on it would throw.
|
|
111
|
+
const result = consumeTasksResponseBROKEN(API_RESPONSE);
|
|
112
|
+
// The broken code returns an object where an array is expected
|
|
113
|
+
expect(Array.isArray(result)).toBe(false);
|
|
114
|
+
// Accessing .filter would succeed (it's on Object.prototype? No — it would
|
|
115
|
+
// return undefined because plain objects don't have .filter)
|
|
116
|
+
expect(typeof (result as unknown as { filter?: unknown }).filter).toBe('undefined');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('[CHAR] calling .map on the broken result throws or returns undefined', () => {
|
|
120
|
+
const result = consumeTasksResponseBROKEN(API_RESPONSE) as unknown;
|
|
121
|
+
// When Tasks.tsx does tasks.filter(...), tasks is { items, total, has_more }
|
|
122
|
+
// which has no .filter → calling it throws TypeError
|
|
123
|
+
expect(() => {
|
|
124
|
+
(result as TaskRecord[]).filter(() => true);
|
|
125
|
+
}).toThrow(TypeError);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('correct consumer — contract the fix must satisfy', () => {
|
|
130
|
+
it('correct consumer returns an actual array', () => {
|
|
131
|
+
const result = consumeTasksResponseCORRECT(API_RESPONSE);
|
|
132
|
+
expect(Array.isArray(result)).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('correct consumer exposes task fields for rendering', () => {
|
|
136
|
+
const result = consumeTasksResponseCORRECT(API_RESPONSE);
|
|
137
|
+
expect(result[0].id).toBe('abc-123');
|
|
138
|
+
expect(result[0].title).toBe('Test task');
|
|
139
|
+
expect(result[0].status).toBe('active');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('total is preserved from response for pagination display', () => {
|
|
143
|
+
expect(API_RESPONSE.total).toBe(1);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('has_more drives next-page button state', () => {
|
|
147
|
+
expect(API_RESPONSE.has_more).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('empty page shape is valid', () => {
|
|
151
|
+
const empty: TaskPage = { items: [], total: 0, has_more: false };
|
|
152
|
+
const result = consumeTasksResponseCORRECT(empty);
|
|
153
|
+
expect(result).toEqual([]);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('pagination parameters', () => {
|
|
158
|
+
it('default limit is 50', () => {
|
|
159
|
+
// The API uses Zod default(50) — component should default to 50 items/page
|
|
160
|
+
const defaultLimit = 50;
|
|
161
|
+
expect(defaultLimit).toBeGreaterThan(0);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('supported page sizes are 20, 50, 100', () => {
|
|
165
|
+
const PAGE_SIZES = [20, 50, 100];
|
|
166
|
+
PAGE_SIZES.forEach(size => {
|
|
167
|
+
expect(size).toBeGreaterThan(0);
|
|
168
|
+
expect(size).toBeLessThanOrEqual(200); // API max is 200
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('offset is computed as (page - 1) * pageSize', () => {
|
|
173
|
+
const page = 3;
|
|
174
|
+
const pageSize = 50;
|
|
175
|
+
const offset = (page - 1) * pageSize;
|
|
176
|
+
expect(offset).toBe(100);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
package/vitest.config.ts
CHANGED
|
@@ -5,7 +5,7 @@ export default defineConfig({
|
|
|
5
5
|
test: {
|
|
6
6
|
globals: true,
|
|
7
7
|
environment: 'node',
|
|
8
|
-
include: ['tests/unit/**/*.test.ts'],
|
|
8
|
+
include: ['tests/unit/**/*.test.ts', 'tests/integration/**/*.test.ts'],
|
|
9
9
|
exclude: ['tests-old/**', 'src-old/**', 'node_modules/**'],
|
|
10
10
|
coverage: {
|
|
11
11
|
provider: 'v8',
|