autosnippet 3.3.0 → 3.3.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 (245) hide show
  1. package/dashboard/dist/assets/icons-BJ2mUBi8.js +1 -0
  2. package/dashboard/dist/assets/index-B659K9t5.js +128 -0
  3. package/dashboard/dist/assets/index-NCm40PMD.css +1 -0
  4. package/dashboard/dist/index.html +3 -3
  5. package/dist/bin/cli.d.ts +1 -0
  6. package/dist/bin/cli.js +284 -142
  7. package/dist/lib/agent/context/ExplorationTracker.d.ts +2 -0
  8. package/dist/lib/agent/context/ExplorationTracker.js +21 -3
  9. package/dist/lib/agent/core/ToolExecutionPipeline.d.ts +3 -1
  10. package/dist/lib/agent/core/ToolExecutionPipeline.js +8 -1
  11. package/dist/lib/agent/forge/DynamicComposer.d.ts +58 -0
  12. package/dist/lib/agent/forge/DynamicComposer.js +99 -0
  13. package/dist/lib/agent/forge/SandboxRunner.d.ts +60 -0
  14. package/dist/lib/agent/forge/SandboxRunner.js +251 -0
  15. package/dist/lib/agent/forge/TemporaryToolRegistry.d.ts +76 -0
  16. package/dist/lib/agent/forge/TemporaryToolRegistry.js +154 -0
  17. package/dist/lib/agent/forge/ToolForge.d.ts +92 -0
  18. package/dist/lib/agent/forge/ToolForge.js +239 -0
  19. package/dist/lib/agent/forge/ToolRequirementAnalyzer.d.ts +44 -0
  20. package/dist/lib/agent/forge/ToolRequirementAnalyzer.js +119 -0
  21. package/dist/lib/agent/tools/ToolRegistry.d.ts +2 -0
  22. package/dist/lib/agent/tools/ToolRegistry.js +4 -0
  23. package/dist/lib/agent/tools/composite.js +0 -1
  24. package/dist/lib/agent/tools/index.d.ts +2 -50
  25. package/dist/lib/agent/tools/index.js +2 -3
  26. package/dist/lib/agent/tools/lifecycle.d.ts +1 -58
  27. package/dist/lib/agent/tools/lifecycle.js +2 -75
  28. package/dist/lib/cli/KnowledgeSyncService.d.ts +26 -0
  29. package/dist/lib/cli/KnowledgeSyncService.js +33 -1
  30. package/dist/lib/cli/deploy/FileManifest.d.ts +0 -21
  31. package/dist/lib/cli/deploy/FileManifest.js +0 -11
  32. package/dist/lib/domain/knowledge/KnowledgeEntry.d.ts +10 -0
  33. package/dist/lib/domain/knowledge/KnowledgeEntry.js +2 -0
  34. package/dist/lib/domain/knowledge/Lifecycle.d.ts +19 -2
  35. package/dist/lib/domain/knowledge/Lifecycle.js +32 -6
  36. package/dist/lib/domain/knowledge/UnifiedValidator.d.ts +1 -5
  37. package/dist/lib/domain/knowledge/UnifiedValidator.js +7 -44
  38. package/dist/lib/domain/knowledge/values/Stats.d.ts +29 -0
  39. package/dist/lib/domain/knowledge/values/Stats.js +41 -0
  40. package/dist/lib/external/mcp/McpServer.d.ts +19 -38
  41. package/dist/lib/external/mcp/McpServer.js +145 -117
  42. package/dist/lib/external/mcp/autoApproveInjector.js +0 -2
  43. package/dist/lib/external/mcp/handlers/bootstrap/MissionBriefingBuilder.d.ts +26 -1
  44. package/dist/lib/external/mcp/handlers/bootstrap/MissionBriefingBuilder.js +41 -0
  45. package/dist/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +49 -0
  46. package/dist/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.d.ts +3 -0
  47. package/dist/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.js +27 -0
  48. package/dist/lib/external/mcp/handlers/bootstrap/skills.js +1 -1
  49. package/dist/lib/external/mcp/handlers/bootstrap-external.js +1 -0
  50. package/dist/lib/external/mcp/handlers/bootstrap-internal.js +2 -0
  51. package/dist/lib/external/mcp/handlers/browse.d.ts +1 -0
  52. package/dist/lib/external/mcp/handlers/browse.js +2 -1
  53. package/dist/lib/external/mcp/handlers/consolidated.d.ts +117 -6
  54. package/dist/lib/external/mcp/handlers/consolidated.js +251 -71
  55. package/dist/lib/external/mcp/handlers/guard.d.ts +150 -0
  56. package/dist/lib/external/mcp/handlers/guard.js +239 -5
  57. package/dist/lib/external/mcp/handlers/knowledge.d.ts +0 -29
  58. package/dist/lib/external/mcp/handlers/knowledge.js +1 -76
  59. package/dist/lib/external/mcp/handlers/panorama.d.ts +36 -0
  60. package/dist/lib/external/mcp/handlers/panorama.js +156 -0
  61. package/dist/lib/external/mcp/handlers/system.d.ts +2 -54
  62. package/dist/lib/external/mcp/handlers/system.js +3 -113
  63. package/dist/lib/external/mcp/handlers/task.d.ts +13 -24
  64. package/dist/lib/external/mcp/handlers/task.js +218 -557
  65. package/dist/lib/external/mcp/handlers/types.d.ts +91 -8
  66. package/dist/lib/external/mcp/handlers/types.js +18 -1
  67. package/dist/lib/external/mcp/handlers/wiki-external.d.ts +18 -1
  68. package/dist/lib/external/mcp/handlers/wiki-external.js +16 -1
  69. package/dist/lib/external/mcp/tools.d.ts +18 -24
  70. package/dist/lib/external/mcp/tools.js +132 -159
  71. package/dist/lib/http/HttpServer.js +52 -0
  72. package/dist/lib/http/middleware/validate.js +7 -3
  73. package/dist/lib/http/routes/audit.d.ts +8 -0
  74. package/dist/lib/http/routes/audit.js +51 -0
  75. package/dist/lib/http/routes/guardReport.d.ts +10 -0
  76. package/dist/lib/http/routes/guardReport.js +143 -0
  77. package/dist/lib/http/routes/knowledge.js +32 -1
  78. package/dist/lib/http/routes/panorama.d.ts +11 -0
  79. package/dist/lib/http/routes/panorama.js +322 -0
  80. package/dist/lib/http/routes/signals.d.ts +10 -0
  81. package/dist/lib/http/routes/signals.js +104 -0
  82. package/dist/lib/http/routes/task.d.ts +2 -3
  83. package/dist/lib/http/routes/task.js +17 -347
  84. package/dist/lib/http/routes/violations.js +1 -1
  85. package/dist/lib/infrastructure/audit/AuditLogger.d.ts +6 -1
  86. package/dist/lib/infrastructure/audit/AuditLogger.js +14 -1
  87. package/dist/lib/infrastructure/database/drizzle/schema.d.ts +202 -504
  88. package/dist/lib/infrastructure/database/drizzle/schema.js +38 -69
  89. package/dist/lib/infrastructure/database/migrations/004_evolution_proposals.d.ts +8 -0
  90. package/dist/lib/infrastructure/database/migrations/004_evolution_proposals.js +43 -0
  91. package/dist/lib/infrastructure/database/migrations/005_recipe_source_refs.d.ts +9 -0
  92. package/dist/lib/infrastructure/database/migrations/005_recipe_source_refs.js +24 -0
  93. package/dist/lib/infrastructure/logging/Logger.d.ts +2 -0
  94. package/dist/lib/infrastructure/logging/Logger.js +34 -7
  95. package/dist/lib/infrastructure/monitoring/ErrorTracker.js +3 -1
  96. package/dist/lib/infrastructure/monitoring/PerformanceMonitor.d.ts +2 -2
  97. package/dist/lib/infrastructure/monitoring/PerformanceMonitor.js +12 -10
  98. package/dist/lib/infrastructure/notification/LarkNotifier.d.ts +24 -0
  99. package/dist/lib/infrastructure/notification/LarkNotifier.js +97 -0
  100. package/dist/lib/infrastructure/report/ReportStore.d.ts +45 -0
  101. package/dist/lib/infrastructure/report/ReportStore.js +133 -0
  102. package/dist/lib/infrastructure/signal/SignalAggregator.d.ts +18 -0
  103. package/dist/lib/infrastructure/signal/SignalAggregator.js +84 -0
  104. package/dist/lib/infrastructure/signal/SignalBridge.d.ts +13 -0
  105. package/dist/lib/infrastructure/signal/SignalBridge.js +20 -0
  106. package/dist/lib/infrastructure/signal/SignalBus.d.ts +63 -0
  107. package/dist/lib/infrastructure/signal/SignalBus.js +106 -0
  108. package/dist/lib/infrastructure/signal/SignalTraceWriter.d.ts +36 -0
  109. package/dist/lib/infrastructure/signal/SignalTraceWriter.js +130 -0
  110. package/dist/lib/infrastructure/vector/HnswVectorAdapter.js +18 -2
  111. package/dist/lib/injection/ServiceContainer.js +8 -0
  112. package/dist/lib/injection/ServiceMap.d.ts +16 -10
  113. package/dist/lib/injection/modules/AgentModule.d.ts +1 -1
  114. package/dist/lib/injection/modules/AgentModule.js +7 -1
  115. package/dist/lib/injection/modules/AppModule.d.ts +1 -1
  116. package/dist/lib/injection/modules/AppModule.js +4 -13
  117. package/dist/lib/injection/modules/GuardModule.js +27 -2
  118. package/dist/lib/injection/modules/InfraModule.d.ts +0 -1
  119. package/dist/lib/injection/modules/InfraModule.js +9 -7
  120. package/dist/lib/injection/modules/KnowledgeModule.d.ts +5 -0
  121. package/dist/lib/injection/modules/KnowledgeModule.js +131 -0
  122. package/dist/lib/injection/modules/PanoramaModule.d.ts +18 -0
  123. package/dist/lib/injection/modules/PanoramaModule.js +76 -0
  124. package/dist/lib/injection/modules/SignalModule.d.ts +10 -0
  125. package/dist/lib/injection/modules/SignalModule.js +84 -0
  126. package/dist/lib/repository/knowledge/KnowledgeRepository.impl.d.ts +1 -0
  127. package/dist/lib/repository/knowledge/KnowledgeRepository.impl.js +6 -0
  128. package/dist/lib/service/bootstrap/BootstrapTaskManager.d.ts +3 -1
  129. package/dist/lib/service/bootstrap/BootstrapTaskManager.js +20 -1
  130. package/dist/lib/service/bootstrap/UiStartupTasks.d.ts +45 -0
  131. package/dist/lib/service/bootstrap/UiStartupTasks.js +101 -0
  132. package/dist/lib/service/delivery/AgentInstructionsGenerator.js +4 -5
  133. package/dist/lib/service/delivery/CursorDeliveryPipeline.d.ts +3 -1
  134. package/dist/lib/service/delivery/CursorDeliveryPipeline.js +13 -10
  135. package/dist/lib/service/delivery/RulesGenerator.js +3 -2
  136. package/dist/lib/service/evolution/ConsolidationAdvisor.d.ts +114 -0
  137. package/dist/lib/service/evolution/ConsolidationAdvisor.js +542 -0
  138. package/dist/lib/service/evolution/ContradictionDetector.d.ts +54 -0
  139. package/dist/lib/service/evolution/ContradictionDetector.js +253 -0
  140. package/dist/lib/service/evolution/DecayDetector.d.ts +71 -0
  141. package/dist/lib/service/evolution/DecayDetector.js +244 -0
  142. package/dist/lib/service/evolution/EnhancementSuggester.d.ts +38 -0
  143. package/dist/lib/service/evolution/EnhancementSuggester.js +220 -0
  144. package/dist/lib/service/evolution/KnowledgeMetabolism.d.ts +82 -0
  145. package/dist/lib/service/evolution/KnowledgeMetabolism.js +167 -0
  146. package/dist/lib/service/evolution/RedundancyAnalyzer.d.ts +53 -0
  147. package/dist/lib/service/evolution/RedundancyAnalyzer.js +210 -0
  148. package/dist/lib/service/evolution/StagingManager.d.ts +57 -0
  149. package/dist/lib/service/evolution/StagingManager.js +201 -0
  150. package/dist/lib/service/guard/ComplianceReporter.d.ts +42 -2
  151. package/dist/lib/service/guard/ComplianceReporter.js +43 -5
  152. package/dist/lib/service/guard/CoverageAnalyzer.d.ts +54 -0
  153. package/dist/lib/service/guard/CoverageAnalyzer.js +149 -0
  154. package/dist/lib/service/guard/GuardCheckEngine.d.ts +42 -0
  155. package/dist/lib/service/guard/GuardCheckEngine.js +465 -14
  156. package/dist/lib/service/guard/GuardFeedbackLoop.d.ts +3 -0
  157. package/dist/lib/service/guard/GuardFeedbackLoop.js +9 -0
  158. package/dist/lib/service/guard/ReverseGuard.d.ts +73 -0
  159. package/dist/lib/service/guard/ReverseGuard.js +256 -0
  160. package/dist/lib/service/guard/RuleLearner.d.ts +12 -0
  161. package/dist/lib/service/guard/RuleLearner.js +38 -0
  162. package/dist/lib/service/guard/UncertaintyCollector.d.ts +83 -0
  163. package/dist/lib/service/guard/UncertaintyCollector.js +149 -0
  164. package/dist/lib/service/guard/ViolationsStore.d.ts +1 -0
  165. package/dist/lib/service/guard/ViolationsStore.js +33 -3
  166. package/dist/lib/service/knowledge/ConfidenceRouter.d.ts +13 -0
  167. package/dist/lib/service/knowledge/ConfidenceRouter.js +14 -0
  168. package/dist/lib/service/knowledge/KnowledgeService.js +22 -4
  169. package/dist/lib/service/knowledge/SourceRefReconciler.d.ts +68 -0
  170. package/dist/lib/service/knowledge/SourceRefReconciler.js +309 -0
  171. package/dist/lib/service/panorama/CouplingAnalyzer.d.ts +27 -0
  172. package/dist/lib/service/panorama/CouplingAnalyzer.js +192 -0
  173. package/dist/lib/service/panorama/DimensionAnalyzer.d.ts +28 -0
  174. package/dist/lib/service/panorama/DimensionAnalyzer.js +320 -0
  175. package/dist/lib/service/panorama/LayerInferrer.d.ts +19 -0
  176. package/dist/lib/service/panorama/LayerInferrer.js +182 -0
  177. package/dist/lib/service/panorama/ModuleDiscoverer.d.ts +24 -0
  178. package/dist/lib/service/panorama/ModuleDiscoverer.js +185 -0
  179. package/dist/lib/service/panorama/PanoramaAggregator.d.ts +29 -0
  180. package/dist/lib/service/panorama/PanoramaAggregator.js +228 -0
  181. package/dist/lib/service/panorama/PanoramaScanner.d.ts +52 -0
  182. package/dist/lib/service/panorama/PanoramaScanner.js +188 -0
  183. package/dist/lib/service/panorama/PanoramaService.d.ts +125 -0
  184. package/dist/lib/service/panorama/PanoramaService.js +363 -0
  185. package/dist/lib/service/panorama/PanoramaTypes.d.ts +134 -0
  186. package/dist/lib/service/panorama/PanoramaTypes.js +6 -0
  187. package/dist/lib/service/panorama/RoleRefiner.d.ts +48 -0
  188. package/dist/lib/service/panorama/RoleRefiner.js +535 -0
  189. package/dist/lib/service/search/BM25Scorer.d.ts +2 -2
  190. package/dist/lib/service/search/CoarseRanker.d.ts +7 -6
  191. package/dist/lib/service/search/CoarseRanker.js +11 -10
  192. package/dist/lib/service/search/FieldWeightedScorer.d.ts +81 -0
  193. package/dist/lib/service/search/FieldWeightedScorer.js +318 -0
  194. package/dist/lib/service/search/MultiSignalRanker.d.ts +3 -2
  195. package/dist/lib/service/search/MultiSignalRanker.js +17 -1
  196. package/dist/lib/service/search/SearchEngine.d.ts +9 -7
  197. package/dist/lib/service/search/SearchEngine.js +67 -10
  198. package/dist/lib/service/search/SearchTypes.d.ts +25 -3
  199. package/dist/lib/service/search/SearchTypes.js +6 -1
  200. package/dist/lib/service/signal/HitRecorder.d.ts +68 -0
  201. package/dist/lib/service/signal/HitRecorder.js +173 -0
  202. package/dist/lib/service/skills/SignalCollector.d.ts +3 -1
  203. package/dist/lib/service/skills/SignalCollector.js +31 -1
  204. package/dist/lib/service/task/IntentExtractor.d.ts +66 -0
  205. package/dist/lib/service/task/IntentExtractor.js +256 -0
  206. package/dist/lib/service/task/PrimeSearchPipeline.d.ts +54 -0
  207. package/dist/lib/service/task/PrimeSearchPipeline.js +113 -0
  208. package/dist/lib/service/vector/VectorService.d.ts +3 -0
  209. package/dist/lib/service/vector/VectorService.js +38 -4
  210. package/dist/lib/shared/schemas/mcp-tools.d.ts +41 -96
  211. package/dist/lib/shared/schemas/mcp-tools.js +59 -119
  212. package/dist/scripts/analyze-signals.d.ts +20 -0
  213. package/dist/scripts/analyze-signals.js +155 -0
  214. package/dist/scripts/diagnose-mcp.js +1 -1
  215. package/package.json +1 -1
  216. package/skills/autosnippet-create/SKILL.md +98 -89
  217. package/skills/autosnippet-devdocs/SKILL.md +55 -57
  218. package/templates/claude-code/hooks/autosnippet-session.sh +10 -15
  219. package/templates/cursor-hooks/hooks/session-start.sh +1 -1
  220. package/templates/guard-ci.yml +2 -2
  221. package/templates/instructions/agent-static.md +2 -1
  222. package/templates/instructions/conventions.md +5 -6
  223. package/templates/recipes-setup/README.md +1 -2
  224. package/templates/recipes-setup/_template.md +39 -39
  225. package/dashboard/dist/assets/icons-BofcEZ3f.js +0 -1
  226. package/dashboard/dist/assets/index-D0whuycy.css +0 -1
  227. package/dashboard/dist/assets/index-SiN1GChm.js +0 -128
  228. package/dist/lib/domain/task/Task.d.ts +0 -140
  229. package/dist/lib/domain/task/Task.js +0 -254
  230. package/dist/lib/domain/task/TaskDependency.d.ts +0 -23
  231. package/dist/lib/domain/task/TaskDependency.js +0 -34
  232. package/dist/lib/domain/task/TaskIdGenerator.d.ts +0 -40
  233. package/dist/lib/domain/task/TaskIdGenerator.js +0 -75
  234. package/dist/lib/domain/task/index.d.ts +0 -4
  235. package/dist/lib/domain/task/index.js +0 -4
  236. package/dist/lib/infrastructure/database/migrations/002_add_tasks.d.ts +0 -11
  237. package/dist/lib/infrastructure/database/migrations/002_add_tasks.js +0 -86
  238. package/dist/lib/repository/task/TaskRepository.impl.d.ts +0 -171
  239. package/dist/lib/repository/task/TaskRepository.impl.js +0 -347
  240. package/dist/lib/service/task/TaskGraphService.d.ts +0 -222
  241. package/dist/lib/service/task/TaskGraphService.js +0 -597
  242. package/dist/lib/service/task/TaskKnowledgeBridge.d.ts +0 -95
  243. package/dist/lib/service/task/TaskKnowledgeBridge.js +0 -298
  244. package/dist/lib/service/task/TaskReadyEngine.d.ts +0 -84
  245. package/dist/lib/service/task/TaskReadyEngine.js +0 -115
@@ -1,140 +0,0 @@
1
- export interface TaskProps {
2
- id?: string | null;
3
- parentId?: string | null;
4
- childSeq?: number;
5
- title?: string;
6
- description?: string;
7
- design?: string;
8
- acceptance?: string;
9
- notes?: string;
10
- status?: string;
11
- priority?: number;
12
- taskType?: string;
13
- closeReason?: string;
14
- failCount?: number;
15
- lastFailReason?: string;
16
- contentHash?: string | null;
17
- assignee?: string;
18
- createdBy?: string;
19
- createdAt?: number;
20
- updatedAt?: number;
21
- closedAt?: number | null;
22
- knowledgeContext?: Record<string, unknown> | null;
23
- metadata?: Record<string, unknown>;
24
- [key: string]: unknown;
25
- }
26
- interface TaskRow {
27
- id?: unknown;
28
- parent_id?: unknown;
29
- child_seq?: unknown;
30
- title?: unknown;
31
- description?: unknown;
32
- design?: unknown;
33
- acceptance?: unknown;
34
- notes?: unknown;
35
- status?: unknown;
36
- priority?: unknown;
37
- task_type?: unknown;
38
- close_reason?: unknown;
39
- content_hash?: unknown;
40
- fail_count?: unknown;
41
- last_fail_reason?: unknown;
42
- assignee?: unknown;
43
- created_by?: unknown;
44
- created_at?: unknown;
45
- updated_at?: unknown;
46
- closed_at?: unknown;
47
- metadata?: unknown;
48
- parentId?: unknown;
49
- childSeq?: unknown;
50
- taskType?: unknown;
51
- closeReason?: unknown;
52
- contentHash?: unknown;
53
- failCount?: unknown;
54
- lastFailReason?: unknown;
55
- createdBy?: unknown;
56
- createdAt?: unknown;
57
- updatedAt?: unknown;
58
- closedAt?: unknown;
59
- [key: string]: unknown;
60
- }
61
- /**
62
- * Task — 任务实体
63
- *
64
- * 参考 Beads Issue 结构,裁剪为 AutoSnippet 所需的核心字段。
65
- *
66
- * 字段分组:
67
- * Core Identification → id, parentId, contentHash
68
- * Content → title, description, design, acceptance
69
- * Status & Workflow → status, priority, taskType
70
- * Assignment → assignee, claimedAt
71
- * Timestamps → createdAt, updatedAt, closedAt
72
- * Knowledge Bridge → knowledgeContext (运行时,不持久化)
73
- */
74
- export declare class Task {
75
- acceptance: string;
76
- assignee: string;
77
- childSeq: number;
78
- closeReason: string;
79
- closedAt: number | null;
80
- contentHash: string | null;
81
- createdAt: number;
82
- createdBy: string;
83
- description: string;
84
- design: string;
85
- failCount: number;
86
- id: string | null;
87
- lastFailReason: string;
88
- metadata: Record<string, unknown>;
89
- notes: string;
90
- parentId: string | null;
91
- priority: number;
92
- status: string;
93
- taskType: string;
94
- title: string;
95
- updatedAt: number;
96
- knowledgeContext: Record<string, unknown> | null;
97
- constructor(props?: TaskProps);
98
- claim(assignee?: string): void;
99
- close(reason?: string): void;
100
- reopen(): void;
101
- pin(): void;
102
- unpin(reason?: string): void;
103
- defer(reason?: string): void;
104
- fail(reason: string): void;
105
- /**
106
- * 计算内容哈希(用于去重检测)
107
- * 相同标题+描述+类型 = 重复任务
108
- */
109
- computeContentHash(): string;
110
- validate(): boolean;
111
- /** 是否有效(快捷校验) */
112
- isValid(): boolean;
113
- toJSON(): {
114
- knowledgeContext?: Record<string, unknown> | undefined;
115
- id: string | null;
116
- parentId: string | null;
117
- title: string;
118
- description: string;
119
- design: string;
120
- acceptance: string;
121
- notes: string;
122
- status: string;
123
- priority: number;
124
- taskType: string;
125
- closeReason: string;
126
- assignee: string;
127
- createdBy: string;
128
- createdAt: number;
129
- updatedAt: number;
130
- closedAt: number | null;
131
- contentHash: string | null;
132
- failCount: number;
133
- lastFailReason: string;
134
- metadata: Record<string, unknown>;
135
- };
136
- static fromJSON(data: unknown): Task;
137
- /** 从数据库行构造 Task(snake_case → camelCase) */
138
- static fromRow(row: TaskRow | null): Task | null;
139
- }
140
- export default Task;
@@ -1,254 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- /**
3
- * Task — 任务实体
4
- *
5
- * 参考 Beads Issue 结构,裁剪为 AutoSnippet 所需的核心字段。
6
- *
7
- * 字段分组:
8
- * Core Identification → id, parentId, contentHash
9
- * Content → title, description, design, acceptance
10
- * Status & Workflow → status, priority, taskType
11
- * Assignment → assignee, claimedAt
12
- * Timestamps → createdAt, updatedAt, closedAt
13
- * Knowledge Bridge → knowledgeContext (运行时,不持久化)
14
- */
15
- export class Task {
16
- acceptance;
17
- assignee;
18
- childSeq;
19
- closeReason;
20
- closedAt;
21
- contentHash;
22
- createdAt;
23
- createdBy;
24
- description;
25
- design;
26
- failCount;
27
- id;
28
- lastFailReason;
29
- metadata;
30
- notes;
31
- parentId;
32
- priority;
33
- status;
34
- taskType;
35
- title;
36
- updatedAt;
37
- knowledgeContext;
38
- constructor(props = {}) {
39
- // ── Core Identification ──
40
- this.id = props.id || null;
41
- this.parentId = props.parentId || null;
42
- this.childSeq = props.childSeq || 0;
43
- // ── Content ──
44
- this.title = props.title || '';
45
- this.description = props.description || '';
46
- this.design = props.design || '';
47
- this.acceptance = props.acceptance || '';
48
- this.notes = props.notes || '';
49
- // ── Status & Workflow ──
50
- this.status = props.status || 'open';
51
- this.priority = props.priority ?? 2;
52
- this.taskType = props.taskType || 'task';
53
- this.closeReason = props.closeReason || '';
54
- this.failCount = props.failCount || 0;
55
- this.lastFailReason = props.lastFailReason || '';
56
- // ── Content Hash (去重) ──
57
- this.contentHash = props.contentHash || null;
58
- // ── Assignment ──
59
- this.assignee = props.assignee || '';
60
- this.createdBy = props.createdBy || 'agent';
61
- // ── Timestamps ──
62
- this.createdAt = props.createdAt || Math.floor(Date.now() / 1000);
63
- this.updatedAt = props.updatedAt || Math.floor(Date.now() / 1000);
64
- this.closedAt = props.closedAt || null;
65
- // ── Knowledge Bridge (运行时填充, 不持久化) ──
66
- this.knowledgeContext = props.knowledgeContext || null;
67
- // ── Metadata (可扩展 JSON) ──
68
- this.metadata = props.metadata || {};
69
- }
70
- // ── 生命周期方法 ──
71
- claim(assignee = 'agent') {
72
- if (this.status === 'closed') {
73
- throw new Error('Cannot claim a closed task');
74
- }
75
- if (this.status === 'pinned') {
76
- throw new Error('Cannot claim a pinned decision. Use unpin_decision or revise_decision instead.');
77
- }
78
- this.status = 'in_progress';
79
- this.assignee = assignee;
80
- this.updatedAt = Math.floor(Date.now() / 1000);
81
- }
82
- close(reason = 'Completed') {
83
- if (this.status === 'pinned') {
84
- throw new Error('Cannot close a pinned decision directly. Use unpin_decision or revise_decision instead.');
85
- }
86
- this.status = 'closed';
87
- this.closeReason = reason;
88
- this.closedAt = Math.floor(Date.now() / 1000);
89
- this.updatedAt = this.closedAt;
90
- }
91
- reopen() {
92
- this.status = 'open';
93
- this.closedAt = null;
94
- this.closeReason = '';
95
- this.updatedAt = Math.floor(Date.now() / 1000);
96
- }
97
- pin() {
98
- if (this.status === 'closed') {
99
- throw new Error('Cannot pin a closed task');
100
- }
101
- this.status = 'pinned';
102
- this.updatedAt = Math.floor(Date.now() / 1000);
103
- }
104
- unpin(reason = '') {
105
- if (this.status !== 'pinned') {
106
- throw new Error('Can only unpin a pinned task');
107
- }
108
- this.status = 'closed';
109
- this.closeReason = reason || 'Unpinned by user';
110
- this.closedAt = Math.floor(Date.now() / 1000);
111
- this.updatedAt = this.closedAt;
112
- }
113
- defer(reason = '') {
114
- if (this.status === 'pinned') {
115
- throw new Error('Cannot defer a pinned decision. Use unpin_decision or revise_decision instead.');
116
- }
117
- this.status = 'deferred';
118
- if (reason) {
119
- this.notes = `[deferred] ${reason}`;
120
- }
121
- this.updatedAt = Math.floor(Date.now() / 1000);
122
- }
123
- fail(reason) {
124
- if (this.status === 'closed') {
125
- throw new Error('Cannot fail a closed task');
126
- }
127
- if (this.status === 'pinned') {
128
- throw new Error('Cannot fail a pinned decision. Use unpin_decision or revise_decision instead.');
129
- }
130
- this.status = 'open';
131
- this.failCount += 1;
132
- this.lastFailReason = reason || 'Unknown failure';
133
- this.assignee = '';
134
- this.updatedAt = Math.floor(Date.now() / 1000);
135
- }
136
- /**
137
- * 计算内容哈希(用于去重检测)
138
- * 相同标题+描述+类型 = 重复任务
139
- */
140
- computeContentHash() {
141
- const content = `${this.title}|${this.description}|${this.taskType}`;
142
- this.contentHash = createHash('sha256').update(content).digest('hex').substring(0, 12);
143
- return this.contentHash;
144
- }
145
- // ── 校验 ──
146
- validate() {
147
- if (!this.title || this.title.length === 0) {
148
- throw new Error('title is required');
149
- }
150
- if (this.title.length > 500) {
151
- throw new Error(`title must be 500 characters or less (got ${this.title.length})`);
152
- }
153
- if (typeof this.priority !== 'number' ||
154
- !Number.isInteger(this.priority) ||
155
- this.priority < 0 ||
156
- this.priority > 4) {
157
- throw new Error(`priority must be an integer between 0 and 4 (got ${this.priority})`);
158
- }
159
- const validStatuses = ['open', 'in_progress', 'deferred', 'closed', 'pinned'];
160
- if (!validStatuses.includes(this.status)) {
161
- throw new Error(`invalid status: ${this.status}`);
162
- }
163
- const validTypes = ['epic', 'task', 'bug', 'chore', 'decision'];
164
- if (!validTypes.includes(this.taskType)) {
165
- throw new Error(`invalid task type: ${this.taskType}`);
166
- }
167
- if (this.status === 'closed' && !this.closedAt) {
168
- throw new Error('closed tasks must have closedAt timestamp');
169
- }
170
- return true;
171
- }
172
- /** 是否有效(快捷校验) */
173
- isValid() {
174
- try {
175
- this.validate();
176
- return true;
177
- }
178
- catch {
179
- return false;
180
- }
181
- }
182
- toJSON() {
183
- return {
184
- id: this.id,
185
- parentId: this.parentId,
186
- title: this.title,
187
- description: this.description,
188
- design: this.design,
189
- acceptance: this.acceptance,
190
- notes: this.notes,
191
- status: this.status,
192
- priority: this.priority,
193
- taskType: this.taskType,
194
- closeReason: this.closeReason,
195
- assignee: this.assignee,
196
- createdBy: this.createdBy,
197
- createdAt: this.createdAt,
198
- updatedAt: this.updatedAt,
199
- closedAt: this.closedAt,
200
- contentHash: this.contentHash,
201
- failCount: this.failCount,
202
- lastFailReason: this.lastFailReason,
203
- metadata: this.metadata,
204
- ...(this.knowledgeContext ? { knowledgeContext: this.knowledgeContext } : {}),
205
- };
206
- }
207
- static fromJSON(data) {
208
- if (!data) {
209
- return new Task();
210
- }
211
- return new Task(data);
212
- }
213
- /** 从数据库行构造 Task(snake_case → camelCase) */
214
- static fromRow(row) {
215
- if (!row) {
216
- return null;
217
- }
218
- // 兼容 raw SQL 返回的 snake_case 和 Drizzle 返回的 camelCase
219
- return new Task({
220
- id: row.id,
221
- parentId: (row.parent_id ?? row.parentId),
222
- childSeq: (row.child_seq ?? row.childSeq),
223
- title: row.title,
224
- description: row.description,
225
- design: row.design,
226
- acceptance: row.acceptance,
227
- notes: row.notes,
228
- status: row.status,
229
- priority: row.priority,
230
- taskType: (row.task_type ?? row.taskType),
231
- closeReason: (row.close_reason ?? row.closeReason),
232
- contentHash: (row.content_hash ?? row.contentHash),
233
- failCount: (row.fail_count ?? row.failCount),
234
- lastFailReason: (row.last_fail_reason ?? row.lastFailReason),
235
- assignee: row.assignee,
236
- createdBy: (row.created_by ?? row.createdBy),
237
- createdAt: (row.created_at ?? row.createdAt),
238
- updatedAt: (row.updated_at ?? row.updatedAt),
239
- closedAt: (row.closed_at ?? row.closedAt),
240
- metadata: (() => {
241
- if (typeof row.metadata !== 'string') {
242
- return row.metadata || {};
243
- }
244
- try {
245
- return JSON.parse(row.metadata);
246
- }
247
- catch {
248
- return {};
249
- }
250
- })(),
251
- });
252
- }
253
- }
254
- export default Task;
@@ -1,23 +0,0 @@
1
- /**
2
- * 任务依赖类型
3
- *
4
- * Phase 1 引入 6 种核心依赖类型,按 "是否影响就绪" 分为两组。
5
- *
6
- * 阻塞型: blocks, waits-for → 影响 ready 计算
7
- * 结构型: parent-child → 仅层次关系
8
- * 关联型: discovered-from, related, knowledge-ref → 不影响 ready
9
- */
10
- export declare const DepType: Readonly<{
11
- BLOCKS: "blocks";
12
- WAITS_FOR: "waits-for";
13
- PARENT_CHILD: "parent-child";
14
- DISCOVERED_FROM: "discovered-from";
15
- RELATED: "related";
16
- KNOWLEDGE_REF: "knowledge-ref";
17
- SUPERSEDES: "supersedes";
18
- }>;
19
- /** 判断依赖类型是否影响就绪计算 */
20
- export declare function affectsReadyWork(depType: string): boolean;
21
- /** 判断依赖类型是否合法 */
22
- export declare function isValidDepType(depType: string): boolean;
23
- export default DepType;
@@ -1,34 +0,0 @@
1
- /**
2
- * 任务依赖类型
3
- *
4
- * Phase 1 引入 6 种核心依赖类型,按 "是否影响就绪" 分为两组。
5
- *
6
- * 阻塞型: blocks, waits-for → 影响 ready 计算
7
- * 结构型: parent-child → 仅层次关系
8
- * 关联型: discovered-from, related, knowledge-ref → 不影响 ready
9
- */
10
- export const DepType = Object.freeze({
11
- // ── 阻塞型(影响 ready 计算)──
12
- BLOCKS: 'blocks',
13
- WAITS_FOR: 'waits-for',
14
- // ── 结构型(建立层次,不影响 ready)──
15
- PARENT_CHILD: 'parent-child',
16
- // ── 关联型(不影响 ready,构建知识/因果图谱)──
17
- DISCOVERED_FROM: 'discovered-from',
18
- RELATED: 'related',
19
- KNOWLEDGE_REF: 'knowledge-ref', // AutoSnippet 独有:关联知识条目
20
- SUPERSEDES: 'supersedes', // 决策演化链:新决策取代旧决策
21
- });
22
- /** 所有合法的依赖类型值列表 */
23
- const ALL_DEP_TYPES = Object.values(DepType);
24
- /** 影响就绪计算的依赖类型集合 */
25
- const BLOCKING_TYPES = new Set([DepType.BLOCKS, DepType.WAITS_FOR]);
26
- /** 判断依赖类型是否影响就绪计算 */
27
- export function affectsReadyWork(depType) {
28
- return BLOCKING_TYPES.has(depType);
29
- }
30
- /** 判断依赖类型是否合法 */
31
- export function isValidDepType(depType) {
32
- return ALL_DEP_TYPES.includes(depType);
33
- }
34
- export default DepType;
@@ -1,40 +0,0 @@
1
- import type { DrizzleDB } from '../../infrastructure/database/drizzle/index.js';
2
- /**
3
- * TaskIdGenerator — 短 Hash ID 生成器
4
- *
5
- * 渐进式长度扩展(随任务数增长自动加长):
6
- * 0-500 tasks → 4 字符 (16^4 = 65,536 组合)
7
- * 500-1500 → 5 字符 (16^5 = 1,048,576)
8
- * 1500+ → 6 字符 (16^6 = 16,777,216)
9
- *
10
- * 前缀 'asd-',与 Beads 的 'bd-' 区分。
11
- */
12
- interface DbHandle {
13
- prepare(sql: string): {
14
- get(...params: unknown[]): Record<string, unknown> | undefined;
15
- run(...params: unknown[]): unknown;
16
- };
17
- }
18
- export declare class TaskIdGenerator {
19
- #private;
20
- _db: DbHandle;
21
- _prefix: string;
22
- /** @param db raw SQLite handle */
23
- constructor(db: DbHandle, drizzle?: DrizzleDB);
24
- /**
25
- * 生成新的短 Hash ID
26
- * @returns 如 'asd-a1b2'
27
- */
28
- generate(): string;
29
- /**
30
- * 生成子任务 ID
31
- * asd-a3f8 → asd-a3f8.1, asd-a3f8.2, ...
32
- * ★ Drizzle 类型安全 SELECT + UPDATE
33
- */
34
- generateChild(parentId: string): string;
35
- /** ★ Drizzle 类型安全 COUNT */
36
- private _getTaskCount;
37
- /** ★ Drizzle 类型安全 EXISTS */
38
- private _exists;
39
- }
40
- export default TaskIdGenerator;
@@ -1,75 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { eq, sql } from 'drizzle-orm';
3
- import { v4 as uuidv4 } from 'uuid';
4
- import { getDrizzle } from '../../infrastructure/database/drizzle/index.js';
5
- import { tasks } from '../../infrastructure/database/drizzle/schema.js';
6
- export class TaskIdGenerator {
7
- _db;
8
- _prefix;
9
- #drizzle;
10
- /** @param db raw SQLite handle */
11
- constructor(db, drizzle) {
12
- this._db = db;
13
- this._prefix = 'asd';
14
- this.#drizzle = drizzle ?? getDrizzle();
15
- }
16
- /**
17
- * 生成新的短 Hash ID
18
- * @returns 如 'asd-a1b2'
19
- */
20
- generate() {
21
- const taskCount = this._getTaskCount();
22
- const hashLen = taskCount < 500 ? 4 : taskCount < 1500 ? 5 : 6;
23
- // 尝试生成无冲突 ID(最多 10 次)
24
- for (let attempt = 0; attempt < 10; attempt++) {
25
- const uuid = uuidv4();
26
- const hash = createHash('sha256').update(uuid).digest('hex');
27
- const shortHash = hash.substring(0, hashLen);
28
- const id = `${this._prefix}-${shortHash}`;
29
- if (!this._exists(id)) {
30
- return id;
31
- }
32
- }
33
- // 回退到 6 位 + 冲突检查 + 终极 8 位兜底
34
- const uuid = uuidv4();
35
- const hash = createHash('sha256').update(uuid).digest('hex');
36
- const fallbackId = `${this._prefix}-${hash.substring(0, 6)}`;
37
- if (!this._exists(fallbackId)) {
38
- return fallbackId;
39
- }
40
- return `${this._prefix}-${hash.substring(0, 8)}`;
41
- }
42
- /**
43
- * 生成子任务 ID
44
- * asd-a3f8 → asd-a3f8.1, asd-a3f8.2, ...
45
- * ★ Drizzle 类型安全 SELECT + UPDATE
46
- */
47
- generateChild(parentId) {
48
- const parent = this.#drizzle
49
- .select({ childSeq: tasks.childSeq })
50
- .from(tasks)
51
- .where(eq(tasks.id, parentId))
52
- .get();
53
- if (!parent) {
54
- throw new Error(`Parent task not found: ${parentId}`);
55
- }
56
- const nextSeq = (parent.childSeq || 0) + 1;
57
- this.#drizzle.update(tasks).set({ childSeq: nextSeq }).where(eq(tasks.id, parentId)).run();
58
- return `${parentId}.${nextSeq}`;
59
- }
60
- /** ★ Drizzle 类型安全 COUNT */
61
- _getTaskCount() {
62
- const row = this.#drizzle.select({ cnt: sql `COUNT(*)` }).from(tasks).get();
63
- return row?.cnt || 0;
64
- }
65
- /** ★ Drizzle 类型安全 EXISTS */
66
- _exists(id) {
67
- const row = this.#drizzle
68
- .select({ x: sql `1` })
69
- .from(tasks)
70
- .where(eq(tasks.id, id))
71
- .get();
72
- return !!row;
73
- }
74
- }
75
- export default TaskIdGenerator;
@@ -1,4 +0,0 @@
1
- /** Task Domain — 统一导出 */
2
- export { Task } from './Task.js';
3
- export { affectsReadyWork, DepType, isValidDepType } from './TaskDependency.js';
4
- export { TaskIdGenerator } from './TaskIdGenerator.js';
@@ -1,4 +0,0 @@
1
- /** Task Domain — 统一导出 */
2
- export { Task } from './Task.js';
3
- export { affectsReadyWork, DepType, isValidDepType } from './TaskDependency.js';
4
- export { TaskIdGenerator } from './TaskIdGenerator.js';
@@ -1,11 +0,0 @@
1
- /**
2
- * Migration 002: TaskGraph 任务表
3
- *
4
- * 新增 tasks 表 + task_dependencies 表 + task_events 表。
5
- *
6
- * 设计决策 D1: 独立 task_dependencies 表(不复用 knowledge_edges)
7
- * - 语义不同(任务依赖 vs 知识关系)
8
- * - 需要专门的索引优化就绪检测查询
9
- * - 避免与知识图谱互相污染
10
- */
11
- export default function migrate(db: import('better-sqlite3').Database): void;
@@ -1,86 +0,0 @@
1
- /**
2
- * Migration 002: TaskGraph 任务表
3
- *
4
- * 新增 tasks 表 + task_dependencies 表 + task_events 表。
5
- *
6
- * 设计决策 D1: 独立 task_dependencies 表(不复用 knowledge_edges)
7
- * - 语义不同(任务依赖 vs 知识关系)
8
- * - 需要专门的索引优化就绪检测查询
9
- * - 避免与知识图谱互相污染
10
- */
11
- export default function migrate(db) {
12
- // ── tasks 表 ──
13
- db.exec(`
14
- CREATE TABLE IF NOT EXISTS tasks (
15
- id TEXT PRIMARY KEY,
16
- parent_id TEXT,
17
- child_seq INTEGER DEFAULT 0,
18
-
19
- title TEXT NOT NULL,
20
- description TEXT DEFAULT '',
21
- design TEXT DEFAULT '',
22
- acceptance TEXT DEFAULT '',
23
- notes TEXT DEFAULT '',
24
-
25
- status TEXT NOT NULL DEFAULT 'open',
26
- priority INTEGER NOT NULL DEFAULT 2,
27
- task_type TEXT NOT NULL DEFAULT 'task',
28
- close_reason TEXT DEFAULT '',
29
- content_hash TEXT DEFAULT '',
30
- fail_count INTEGER DEFAULT 0,
31
- last_fail_reason TEXT DEFAULT '',
32
-
33
- assignee TEXT DEFAULT '',
34
- created_by TEXT DEFAULT 'agent',
35
-
36
- created_at INTEGER NOT NULL,
37
- updated_at INTEGER NOT NULL,
38
- closed_at INTEGER,
39
-
40
- metadata TEXT DEFAULT '{}'
41
- );
42
-
43
- CREATE INDEX IF NOT EXISTS idx_tasks_status ON tasks(status);
44
- CREATE INDEX IF NOT EXISTS idx_tasks_priority ON tasks(priority);
45
- CREATE INDEX IF NOT EXISTS idx_tasks_parent ON tasks(parent_id);
46
- CREATE INDEX IF NOT EXISTS idx_tasks_type ON tasks(task_type);
47
- CREATE INDEX IF NOT EXISTS idx_tasks_assignee ON tasks(assignee);
48
- CREATE INDEX IF NOT EXISTS idx_tasks_created ON tasks(created_at);
49
- CREATE INDEX IF NOT EXISTS idx_tasks_hash ON tasks(content_hash);
50
- `);
51
- // ── task_dependencies 表 ──
52
- db.exec(`
53
- CREATE TABLE IF NOT EXISTS task_dependencies (
54
- id INTEGER PRIMARY KEY AUTOINCREMENT,
55
- task_id TEXT NOT NULL,
56
- depends_on_id TEXT NOT NULL,
57
- dep_type TEXT NOT NULL DEFAULT 'blocks',
58
- metadata TEXT DEFAULT '{}',
59
- created_at INTEGER NOT NULL,
60
- created_by TEXT DEFAULT 'agent',
61
-
62
- UNIQUE (task_id, depends_on_id, dep_type)
63
- );
64
-
65
- CREATE INDEX IF NOT EXISTS idx_td_task ON task_dependencies(task_id);
66
- CREATE INDEX IF NOT EXISTS idx_td_depends_on ON task_dependencies(depends_on_id);
67
- CREATE INDEX IF NOT EXISTS idx_td_type ON task_dependencies(dep_type);
68
- `);
69
- // ── task_events 审计表 ──
70
- db.exec(`
71
- CREATE TABLE IF NOT EXISTS task_events (
72
- id INTEGER PRIMARY KEY AUTOINCREMENT,
73
- task_id TEXT NOT NULL,
74
- event_type TEXT NOT NULL,
75
- actor TEXT DEFAULT 'agent',
76
- old_value TEXT,
77
- new_value TEXT,
78
- comment TEXT,
79
- created_at INTEGER NOT NULL
80
- );
81
-
82
- CREATE INDEX IF NOT EXISTS idx_te_task ON task_events(task_id);
83
- CREATE INDEX IF NOT EXISTS idx_te_type ON task_events(event_type);
84
- CREATE INDEX IF NOT EXISTS idx_te_created ON task_events(created_at);
85
- `);
86
- }