claude-memory-layer 1.0.31 → 1.0.33

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 (343) hide show
  1. package/README.md +9 -2
  2. package/dist/cli/index.js +1110 -72
  3. package/dist/cli/index.js.map +4 -4
  4. package/dist/core/index.js +414 -25
  5. package/dist/core/index.js.map +2 -2
  6. package/dist/hooks/post-tool-use.js +416 -27
  7. package/dist/hooks/post-tool-use.js.map +2 -2
  8. package/dist/hooks/semantic-daemon.js +416 -27
  9. package/dist/hooks/semantic-daemon.js.map +2 -2
  10. package/dist/hooks/session-end.js +416 -27
  11. package/dist/hooks/session-end.js.map +2 -2
  12. package/dist/hooks/session-start.js +416 -27
  13. package/dist/hooks/session-start.js.map +2 -2
  14. package/dist/hooks/stop.js +416 -27
  15. package/dist/hooks/stop.js.map +2 -2
  16. package/dist/hooks/user-prompt-submit.js +504 -34
  17. package/dist/hooks/user-prompt-submit.js.map +2 -2
  18. package/dist/index.js +416 -27
  19. package/dist/index.js.map +2 -2
  20. package/dist/mcp/index.js +407 -32
  21. package/dist/mcp/index.js.map +2 -2
  22. package/dist/server/api/index.js +850 -44
  23. package/dist/server/api/index.js.map +3 -3
  24. package/dist/server/index.js +1073 -64
  25. package/dist/server/index.js.map +3 -3
  26. package/dist/services/memory-service.js +416 -27
  27. package/dist/services/memory-service.js.map +2 -2
  28. package/dist/ui/assets/js/bootstrap.js +2 -0
  29. package/dist/ui/assets/js/overview.js +166 -3
  30. package/dist/ui/assets/js/state.js +3 -0
  31. package/dist/ui/index.html +20 -0
  32. package/dist/ui/style.css +193 -0
  33. package/package.json +15 -2
  34. package/scripts/postinstall-embedding-backend.cjs +16 -12
  35. package/AGENTS.md +0 -71
  36. package/CLAUDE.md +0 -30
  37. package/HANDOFF.md +0 -92
  38. package/Memo.txt +0 -558
  39. package/benchmarks/replay/anonymized-real-sessions.json +0 -48
  40. package/config/kpi-thresholds.json +0 -7
  41. package/context.md +0 -636
  42. package/docs/ARCHITECTURE_COMPARISON_AND_RECOMMENDATIONS.md +0 -627
  43. package/docs/HERMES_MEMORY_INGESTION_ANALYSIS.md +0 -440
  44. package/docs/MCP_MEMORY_SERVICE_COMPARATIVE_REVIEW.md +0 -271
  45. package/docs/MEMORY_USEFULNESS_AUDIT.md +0 -371
  46. package/docs/MEMORY_USEFULNESS_AUDIT_RAW.json +0 -80
  47. package/docs/MEMSEARCH_PROJECT_STRUCTURE_ANALYSIS.md +0 -333
  48. package/docs/MEMU_ADOPTION.md +0 -40
  49. package/docs/OPERATIONS.md +0 -18
  50. package/docs/PRODUCT_VALIDATION_MATRIX.md +0 -82
  51. package/docs/PROJECT_STRUCTURE_ANALYSIS.md +0 -421
  52. package/docs/REFACTORING_MILESTONES_AND_ISSUES.md +0 -501
  53. package/docs/REFACTORING_PLAN_THIN_CORE.md +0 -414
  54. package/docs/REFERENCE_PROJECT_ANALYSES.md +0 -25
  55. package/docs/SUPERLOCALMEMORY_PROJECT_STRUCTURE_ANALYSIS.md +0 -452
  56. package/docs/TARGET_ARCHITECTURE_AND_FOLDER_STRUCTURE.md +0 -446
  57. package/docs/architecture/comparison-index.md +0 -47
  58. package/docs/reports/codex-real-data-validation-20260505T040447Z.md +0 -46
  59. package/plan.md +0 -1642
  60. package/scripts/build.ts +0 -159
  61. package/scripts/bump-patch-version.sh +0 -18
  62. package/scripts/delete-unknown-projects.js +0 -154
  63. package/scripts/fix-sync-gap.js +0 -32
  64. package/scripts/generate-session-qrels.ts +0 -126
  65. package/scripts/heartbeat-memory-orchestrator.sh +0 -28
  66. package/scripts/replay-retrieval-benchmark.ts +0 -69
  67. package/scripts/report-sync-gap.js +0 -26
  68. package/scripts/review-queue-auto-resolve.js +0 -21
  69. package/scripts/sync-gap-auto-heal.sh +0 -17
  70. package/spec.md +0 -624
  71. package/specs/20260207-dashboard-upgrade/context.md +0 -38
  72. package/specs/20260207-dashboard-upgrade/spec.md +0 -96
  73. package/specs/citations-system/context.md +0 -243
  74. package/specs/citations-system/plan.md +0 -495
  75. package/specs/citations-system/spec.md +0 -371
  76. package/specs/endless-mode/context.md +0 -305
  77. package/specs/endless-mode/plan.md +0 -620
  78. package/specs/endless-mode/spec.md +0 -455
  79. package/specs/entity-edge-model/context.md +0 -401
  80. package/specs/entity-edge-model/plan.md +0 -459
  81. package/specs/entity-edge-model/spec.md +0 -391
  82. package/specs/evidence-aligner-v2/context.md +0 -401
  83. package/specs/evidence-aligner-v2/plan.md +0 -303
  84. package/specs/evidence-aligner-v2/spec.md +0 -312
  85. package/specs/mcp-desktop-integration/context.md +0 -278
  86. package/specs/mcp-desktop-integration/plan.md +0 -550
  87. package/specs/mcp-desktop-integration/spec.md +0 -494
  88. package/specs/memory-utilization-improvements/context.md +0 -145
  89. package/specs/memory-utilization-improvements/plan.md +0 -361
  90. package/specs/memory-utilization-improvements/spec.md +0 -361
  91. package/specs/post-tool-use-hook/context.md +0 -319
  92. package/specs/post-tool-use-hook/plan.md +0 -469
  93. package/specs/post-tool-use-hook/spec.md +0 -364
  94. package/specs/private-tags/context.md +0 -288
  95. package/specs/private-tags/plan.md +0 -412
  96. package/specs/private-tags/spec.md +0 -345
  97. package/specs/progressive-disclosure/context.md +0 -346
  98. package/specs/progressive-disclosure/plan.md +0 -663
  99. package/specs/progressive-disclosure/spec.md +0 -415
  100. package/specs/selective-tool-observation/context.md +0 -100
  101. package/specs/selective-tool-observation/plan.md +0 -158
  102. package/specs/selective-tool-observation/spec.md +0 -127
  103. package/specs/task-entity-system/context.md +0 -297
  104. package/specs/task-entity-system/plan.md +0 -301
  105. package/specs/task-entity-system/spec.md +0 -314
  106. package/specs/thin-core-refactor/context.md +0 -275
  107. package/specs/thin-core-refactor/plan.md +0 -536
  108. package/specs/thin-core-refactor/spec.md +0 -465
  109. package/specs/vector-outbox-v2/context.md +0 -470
  110. package/specs/vector-outbox-v2/plan.md +0 -562
  111. package/specs/vector-outbox-v2/spec.md +0 -466
  112. package/specs/web-viewer-ui/context.md +0 -384
  113. package/specs/web-viewer-ui/plan.md +0 -797
  114. package/specs/web-viewer-ui/spec.md +0 -516
  115. package/src/adapters/claude/capture/index.ts +0 -3
  116. package/src/adapters/claude/context/index.ts +0 -3
  117. package/src/adapters/claude/hooks/index.ts +0 -21
  118. package/src/adapters/claude/hooks/post-tool-use.ts +0 -239
  119. package/src/adapters/claude/hooks/prompt-injection-policy.ts +0 -104
  120. package/src/adapters/claude/hooks/semantic-daemon-client.ts +0 -209
  121. package/src/adapters/claude/hooks/semantic-daemon.ts +0 -283
  122. package/src/adapters/claude/hooks/session-end.ts +0 -59
  123. package/src/adapters/claude/hooks/session-start.ts +0 -73
  124. package/src/adapters/claude/hooks/stop.ts +0 -128
  125. package/src/adapters/claude/hooks/user-prompt-submit.ts +0 -361
  126. package/src/adapters/claude/index.ts +0 -4
  127. package/src/adapters/claude/transcript/index.ts +0 -4
  128. package/src/adapters/claude/transcript/transcript-reader.ts +0 -57
  129. package/src/adapters/claude/transcript/turn-reconstructor.ts +0 -65
  130. package/src/apps/cli/claude-settings-hooks.ts +0 -138
  131. package/src/apps/cli/codex-import-runner.ts +0 -125
  132. package/src/apps/cli/codex-validation-output.ts +0 -95
  133. package/src/apps/cli/hermes-import-runner.ts +0 -130
  134. package/src/apps/cli/hermes-validation-output.ts +0 -91
  135. package/src/apps/cli/index.ts +0 -1735
  136. package/src/apps/cli/mcp-install.ts +0 -106
  137. package/src/apps/cli/retrieval-disclosure-output.ts +0 -196
  138. package/src/apps/dashboard/assets/js/bootstrap.js +0 -244
  139. package/src/apps/dashboard/assets/js/chat.js +0 -373
  140. package/src/apps/dashboard/assets/js/disclosure.js +0 -232
  141. package/src/apps/dashboard/assets/js/modals.js +0 -298
  142. package/src/apps/dashboard/assets/js/overview.js +0 -655
  143. package/src/apps/dashboard/assets/js/state.js +0 -72
  144. package/src/apps/dashboard/assets/js/views.js +0 -468
  145. package/src/apps/dashboard/index.html +0 -543
  146. package/src/apps/dashboard/index.ts +0 -3
  147. package/src/apps/dashboard/style.css +0 -1750
  148. package/src/apps/index.ts +0 -5
  149. package/src/apps/server/api/chat.ts +0 -244
  150. package/src/apps/server/api/citations.ts +0 -105
  151. package/src/apps/server/api/events.ts +0 -137
  152. package/src/apps/server/api/health.ts +0 -53
  153. package/src/apps/server/api/index.ts +0 -26
  154. package/src/apps/server/api/projects.ts +0 -74
  155. package/src/apps/server/api/search.ts +0 -184
  156. package/src/apps/server/api/sessions.ts +0 -115
  157. package/src/apps/server/api/stats.ts +0 -723
  158. package/src/apps/server/api/turns.ts +0 -143
  159. package/src/apps/server/api/utils.ts +0 -65
  160. package/src/apps/server/index.ts +0 -111
  161. package/src/cli/index.ts +0 -3
  162. package/src/cli/retrieval-disclosure-output.ts +0 -2
  163. package/src/compat/index.ts +0 -5
  164. package/src/core/canonical-key.ts +0 -186
  165. package/src/core/citation-generator.ts +0 -63
  166. package/src/core/consolidated-store.ts +0 -356
  167. package/src/core/consolidation-worker.ts +0 -493
  168. package/src/core/context-formatter.ts +0 -276
  169. package/src/core/continuity-manager.ts +0 -341
  170. package/src/core/db-wrapper.ts +0 -64
  171. package/src/core/derive/fact-deriver.ts +0 -170
  172. package/src/core/derive/index.ts +0 -2
  173. package/src/core/derive/summary-deriver.ts +0 -76
  174. package/src/core/edge-repo.ts +0 -333
  175. package/src/core/embedder.ts +0 -4
  176. package/src/core/engine/embedding-maintenance-service.ts +0 -187
  177. package/src/core/engine/endless-memory-services.ts +0 -4
  178. package/src/core/engine/index.ts +0 -19
  179. package/src/core/engine/memory-engine-services.ts +0 -170
  180. package/src/core/engine/memory-ingest-service.ts +0 -317
  181. package/src/core/engine/memory-query-service.ts +0 -173
  182. package/src/core/engine/memory-runtime-service.ts +0 -162
  183. package/src/core/engine/memory-service-composition.ts +0 -231
  184. package/src/core/engine/retrieval-analytics-service.ts +0 -181
  185. package/src/core/engine/retrieval-disclosure-service.ts +0 -420
  186. package/src/core/engine/retrieval-orchestrator.ts +0 -377
  187. package/src/core/engine/retrieval-services.ts +0 -176
  188. package/src/core/engine/shared-memory-services.ts +0 -4
  189. package/src/core/entity-repo.ts +0 -349
  190. package/src/core/event-store.ts +0 -779
  191. package/src/core/evidence-aligner.ts +0 -635
  192. package/src/core/external-market-context.ts +0 -582
  193. package/src/core/graduation-worker.ts +0 -171
  194. package/src/core/graduation.ts +0 -377
  195. package/src/core/index.ts +0 -64
  196. package/src/core/ingest-interceptor.ts +0 -80
  197. package/src/core/markdown-mirror.ts +0 -70
  198. package/src/core/matcher.ts +0 -208
  199. package/src/core/md-mirror.ts +0 -92
  200. package/src/core/metadata-extractor.ts +0 -203
  201. package/src/core/model/memory-fact.ts +0 -30
  202. package/src/core/model/memory-rule.ts +0 -14
  203. package/src/core/model/memory-summary.ts +0 -21
  204. package/src/core/model/raw-event.ts +0 -28
  205. package/src/core/model/retrieval-result.ts +0 -35
  206. package/src/core/mongo-sync-config.ts +0 -165
  207. package/src/core/mongo-sync-worker.ts +0 -381
  208. package/src/core/privacy/filter.ts +0 -190
  209. package/src/core/privacy/index.ts +0 -20
  210. package/src/core/privacy/tag-parser.ts +0 -145
  211. package/src/core/product-validation-matrix.ts +0 -314
  212. package/src/core/progressive-retriever.ts +0 -414
  213. package/src/core/registry/project-path.ts +0 -54
  214. package/src/core/registry/session-registry.ts +0 -69
  215. package/src/core/replay-evaluator.ts +0 -625
  216. package/src/core/retrieval-benchmark.ts +0 -117
  217. package/src/core/retrieval-quality.ts +0 -109
  218. package/src/core/retriever.ts +0 -800
  219. package/src/core/session-qrels.ts +0 -360
  220. package/src/core/shared-event-store.ts +0 -114
  221. package/src/core/shared-promoter.ts +0 -249
  222. package/src/core/shared-store.ts +0 -289
  223. package/src/core/shared-vector-store.ts +0 -203
  224. package/src/core/sqlite-event-store.ts +0 -1846
  225. package/src/core/sqlite-wrapper.ts +0 -116
  226. package/src/core/sync-worker.ts +0 -228
  227. package/src/core/tag-taxonomy.ts +0 -51
  228. package/src/core/task/blocker-resolver.ts +0 -333
  229. package/src/core/task/index.ts +0 -9
  230. package/src/core/task/task-matcher.ts +0 -240
  231. package/src/core/task/task-projector.ts +0 -358
  232. package/src/core/task/task-resolver.ts +0 -421
  233. package/src/core/turn-state.ts +0 -207
  234. package/src/core/types.ts +0 -952
  235. package/src/core/vector-outbox.ts +0 -299
  236. package/src/core/vector-store.ts +0 -231
  237. package/src/core/vector-worker.ts +0 -521
  238. package/src/core/working-set-store.ts +0 -257
  239. package/src/extensions/endless-memory/endless-memory-services.ts +0 -350
  240. package/src/extensions/endless-memory/index.ts +0 -1
  241. package/src/extensions/index.ts +0 -5
  242. package/src/extensions/mcp/handlers.ts +0 -960
  243. package/src/extensions/mcp/index.ts +0 -48
  244. package/src/extensions/mcp/tools.ts +0 -252
  245. package/src/extensions/shared-memory/index.ts +0 -1
  246. package/src/extensions/shared-memory/shared-memory-services.ts +0 -211
  247. package/src/extensions/vector/embedder.ts +0 -234
  248. package/src/extensions/vector/index.ts +0 -1
  249. package/src/hooks/post-tool-use.ts +0 -9
  250. package/src/hooks/semantic-daemon-client.ts +0 -1
  251. package/src/hooks/semantic-daemon.ts +0 -11
  252. package/src/hooks/session-end.ts +0 -9
  253. package/src/hooks/session-start.ts +0 -9
  254. package/src/hooks/stop.ts +0 -9
  255. package/src/hooks/user-prompt-submit.ts +0 -9
  256. package/src/index.ts +0 -13
  257. package/src/mcp/handlers.ts +0 -2
  258. package/src/mcp/index.ts +0 -4
  259. package/src/mcp/tools.ts +0 -2
  260. package/src/server/api/chat.ts +0 -2
  261. package/src/server/api/citations.ts +0 -2
  262. package/src/server/api/events.ts +0 -2
  263. package/src/server/api/health.ts +0 -2
  264. package/src/server/api/index.ts +0 -2
  265. package/src/server/api/projects.ts +0 -2
  266. package/src/server/api/search.ts +0 -2
  267. package/src/server/api/sessions.ts +0 -2
  268. package/src/server/api/stats.ts +0 -2
  269. package/src/server/api/turns.ts +0 -2
  270. package/src/server/api/utils.ts +0 -2
  271. package/src/server/index.ts +0 -2
  272. package/src/services/bootstrap-organizer.ts +0 -463
  273. package/src/services/codex-session-history-importer.ts +0 -966
  274. package/src/services/hermes-session-history-importer.ts +0 -733
  275. package/src/services/memory-service-config.ts +0 -36
  276. package/src/services/memory-service-registry.ts +0 -150
  277. package/src/services/memory-service.ts +0 -688
  278. package/src/services/session-history-importer.ts +0 -629
  279. package/tests/README.md +0 -23
  280. package/tests/adapters/claude/claude-semantic-daemon-adapter.test.ts +0 -54
  281. package/tests/adapters/claude/claude-transcript-reconstructor.test.ts +0 -98
  282. package/tests/adapters/claude-hook-prompt-injection-policy.test.ts +0 -99
  283. package/tests/apps/app-layer-boundary.test.ts +0 -48
  284. package/tests/apps/claude-settings-hooks.test.ts +0 -107
  285. package/tests/apps/cli-disclosure-output.test.ts +0 -212
  286. package/tests/apps/codex-import-runner.test.ts +0 -99
  287. package/tests/apps/codex-validation-output.test.ts +0 -100
  288. package/tests/apps/hermes-import-runner.test.ts +0 -99
  289. package/tests/apps/mcp-install-command.test.ts +0 -59
  290. package/tests/apps/package-build-entrypoints.test.ts +0 -30
  291. package/tests/apps/postinstall-embedding-backend.test.ts +0 -185
  292. package/tests/apps/search-api-disclosure.test.ts +0 -162
  293. package/tests/apps/stats-api-lightweight.test.ts +0 -67
  294. package/tests/apps/ui-disclosure-output.test.ts +0 -140
  295. package/tests/core/bootstrap-organizer.test.ts +0 -111
  296. package/tests/core/canonical-key.test.ts +0 -101
  297. package/tests/core/codex-session-history-importer-validation.test.ts +0 -185
  298. package/tests/core/consolidation-worker.test.ts +0 -75
  299. package/tests/core/embedding-maintenance-service.test.ts +0 -282
  300. package/tests/core/evidence-aligner.test.ts +0 -152
  301. package/tests/core/external-market-context.test.ts +0 -209
  302. package/tests/core/fact-deriver.test.ts +0 -79
  303. package/tests/core/hermes-session-history-importer-validation.test.ts +0 -609
  304. package/tests/core/ingest-interceptor.test.ts +0 -38
  305. package/tests/core/markdown-mirror.test.ts +0 -85
  306. package/tests/core/matcher.test.ts +0 -112
  307. package/tests/core/md-mirror.test.ts +0 -50
  308. package/tests/core/memory-engine-services.test.ts +0 -240
  309. package/tests/core/memory-ingest-service.test.ts +0 -296
  310. package/tests/core/memory-query-service.test.ts +0 -129
  311. package/tests/core/memory-runtime-service.test.ts +0 -201
  312. package/tests/core/memory-service-composition.test.ts +0 -192
  313. package/tests/core/memory-service-config.test.ts +0 -41
  314. package/tests/core/memory-service-facade.test.ts +0 -30
  315. package/tests/core/memory-service-registry.test.ts +0 -206
  316. package/tests/core/product-validation-matrix.test.ts +0 -61
  317. package/tests/core/project-registry.test.ts +0 -78
  318. package/tests/core/replay-evaluator.test.ts +0 -181
  319. package/tests/core/retrieval-analytics-service.test.ts +0 -210
  320. package/tests/core/retrieval-benchmark.test.ts +0 -93
  321. package/tests/core/retrieval-disclosure-service.test.ts +0 -264
  322. package/tests/core/retrieval-orchestrator.test.ts +0 -403
  323. package/tests/core/retrieval-quality.test.ts +0 -31
  324. package/tests/core/retrieval-services.test.ts +0 -185
  325. package/tests/core/retriever-fallback-chain.test.ts +0 -223
  326. package/tests/core/retriever-strategy-scope.test.ts +0 -164
  327. package/tests/core/retriever.memu-adoption.test.ts +0 -122
  328. package/tests/core/session-history-importer-filter.test.ts +0 -78
  329. package/tests/core/session-qrels.test.ts +0 -250
  330. package/tests/core/sqlite-event-store-replication.test.ts +0 -127
  331. package/tests/core/summary-deriver.test.ts +0 -66
  332. package/tests/extensions/embedder-warning-suppression.test.ts +0 -84
  333. package/tests/extensions/endless-memory-extension-boundary.test.ts +0 -17
  334. package/tests/extensions/endless-memory-services.test.ts +0 -325
  335. package/tests/extensions/mcp-context-tools.test.ts +0 -905
  336. package/tests/extensions/mcp-extension-boundary.test.ts +0 -21
  337. package/tests/extensions/mcp-package-build.test.ts +0 -22
  338. package/tests/extensions/mcp-project-aware-tools.test.ts +0 -102
  339. package/tests/extensions/shared-memory-extension-boundary.test.ts +0 -24
  340. package/tests/extensions/shared-memory-services.test.ts +0 -309
  341. package/tests/extensions/vector-extension-boundary.test.ts +0 -21
  342. package/tsconfig.json +0 -24
  343. package/vitest.config.ts +0 -15
@@ -1,333 +0,0 @@
1
- /**
2
- * Blocker Resolver - Resolve blocker texts to entity references
3
- * AXIOMMIND: No stub task creation, fallback to condition
4
- */
5
-
6
- import { dbRun, dbAll, type Database } from '../db-wrapper.js';
7
- import { randomUUID } from 'crypto';
8
- import type { BlockerRef, Entity } from '../types.js';
9
- import { makeEntityCanonicalKey, makeArtifactKey } from '../canonical-key.js';
10
- import { TaskMatcher } from './task-matcher.js';
11
-
12
- export interface BlockerResolverConfig {
13
- project?: string;
14
- }
15
-
16
- // Patterns for artifact detection
17
- const URL_PATTERN = /^https?:\/\/.+/;
18
- const JIRA_PATTERN = /^[A-Z]+-\d+$/;
19
- const GITHUB_ISSUE_PATTERN = /^[^\/]+\/[^#]+#\d+$/;
20
- const TASK_ID_PATTERN = /^task:[^:]+:[^:]+$/;
21
-
22
- export class BlockerResolver {
23
- private taskMatcher: TaskMatcher;
24
-
25
- constructor(
26
- private db: Database,
27
- private config: BlockerResolverConfig = {}
28
- ) {
29
- this.taskMatcher = new TaskMatcher(db);
30
- }
31
-
32
- /**
33
- * Resolve a single blocker text to entity reference
34
- * Rules:
35
- * 1. Strong ID/URL/key pattern → artifact
36
- * 2. Explicit task_id → task
37
- * 3. Task title match (strict only) → task
38
- * 4. Fallback → condition (no stub task creation)
39
- */
40
- async resolveBlocker(
41
- text: string,
42
- _sourceEntryId?: string
43
- ): Promise<BlockerRef> {
44
- const trimmedText = text.trim();
45
-
46
- // Rule 1: Check for artifact patterns
47
- const artifactRef = await this.tryResolveAsArtifact(trimmedText);
48
- if (artifactRef) {
49
- return artifactRef;
50
- }
51
-
52
- // Rule 2: Check for explicit task_id pattern
53
- if (TASK_ID_PATTERN.test(trimmedText)) {
54
- const taskRef = await this.tryResolveAsTaskId(trimmedText);
55
- if (taskRef) {
56
- return taskRef;
57
- }
58
- // Task ID not found, fall through to condition
59
- }
60
-
61
- // Rule 3: Try task title matching (strict only)
62
- const taskMatch = await this.taskMatcher.match(trimmedText, this.config.project);
63
-
64
- if (taskMatch.confidence === 'high' && taskMatch.match) {
65
- // Strict match found
66
- return {
67
- kind: 'task',
68
- entityId: taskMatch.match.entityId,
69
- rawText: trimmedText,
70
- confidence: taskMatch.score
71
- };
72
- }
73
-
74
- // Rule 4: Fallback to condition (get-or-create)
75
- // Also store candidates if any
76
- const conditionRef = await this.createConditionBlocker(
77
- trimmedText,
78
- taskMatch.candidates
79
- );
80
-
81
- return conditionRef;
82
- }
83
-
84
- /**
85
- * Resolve multiple blocker texts
86
- */
87
- async resolveBlockers(
88
- texts: string[],
89
- sourceEntryId?: string
90
- ): Promise<BlockerRef[]> {
91
- const results: BlockerRef[] = [];
92
-
93
- for (const text of texts) {
94
- const ref = await this.resolveBlocker(text, sourceEntryId);
95
- results.push(ref);
96
- }
97
-
98
- return results;
99
- }
100
-
101
- /**
102
- * Try to resolve as artifact (URL, JIRA, GitHub)
103
- */
104
- private async tryResolveAsArtifact(text: string): Promise<BlockerRef | null> {
105
- // Check patterns
106
- if (!URL_PATTERN.test(text) && !JIRA_PATTERN.test(text) && !GITHUB_ISSUE_PATTERN.test(text)) {
107
- return null;
108
- }
109
-
110
- const canonicalKey = makeArtifactKey(text);
111
-
112
- // Find or create artifact
113
- const existing = await dbAll<Record<string, unknown>>(
114
- this.db,
115
- `SELECT entity_id FROM entities
116
- WHERE entity_type = 'artifact' AND canonical_key = ?`,
117
- [canonicalKey]
118
- );
119
-
120
- let entityId: string;
121
-
122
- if (existing.length > 0) {
123
- entityId = existing[0].entity_id as string;
124
- } else {
125
- // Create artifact entity via event
126
- entityId = await this.declareArtifact(text, canonicalKey);
127
- }
128
-
129
- return {
130
- kind: 'artifact',
131
- entityId,
132
- rawText: text,
133
- confidence: 1.0
134
- };
135
- }
136
-
137
- /**
138
- * Try to resolve as explicit task ID
139
- */
140
- private async tryResolveAsTaskId(taskId: string): Promise<BlockerRef | null> {
141
- // taskId format: task:project:identifier
142
- const rows = await dbAll<Record<string, unknown>>(
143
- this.db,
144
- `SELECT entity_id FROM entities
145
- WHERE entity_type = 'task' AND canonical_key = ?
146
- AND status = 'active'`,
147
- [taskId]
148
- );
149
-
150
- if (rows.length === 0) {
151
- return null;
152
- }
153
-
154
- return {
155
- kind: 'task',
156
- entityId: rows[0].entity_id as string,
157
- rawText: taskId,
158
- confidence: 1.0
159
- };
160
- }
161
-
162
- /**
163
- * Create condition blocker (get-or-create)
164
- */
165
- private async createConditionBlocker(
166
- text: string,
167
- candidates?: Entity[]
168
- ): Promise<BlockerRef> {
169
- const canonicalKey = makeEntityCanonicalKey('condition', text, {
170
- project: this.config.project
171
- });
172
-
173
- // Find existing condition
174
- const existing = await dbAll<Record<string, unknown>>(
175
- this.db,
176
- `SELECT entity_id FROM entities
177
- WHERE entity_type = 'condition' AND canonical_key = ?`,
178
- [canonicalKey]
179
- );
180
-
181
- let entityId: string;
182
-
183
- if (existing.length > 0) {
184
- entityId = existing[0].entity_id as string;
185
- } else {
186
- // Create condition entity via event
187
- entityId = await this.declareCondition(text, canonicalKey, candidates);
188
- }
189
-
190
- return {
191
- kind: 'condition',
192
- entityId,
193
- rawText: text,
194
- confidence: 0.5,
195
- candidates: candidates?.map(c => c.entityId)
196
- };
197
- }
198
-
199
- /**
200
- * Declare a new condition entity
201
- */
202
- private async declareCondition(
203
- text: string,
204
- canonicalKey: string,
205
- candidates?: Entity[]
206
- ): Promise<string> {
207
- const entityId = randomUUID();
208
- const now = new Date().toISOString();
209
-
210
- const currentJson = {
211
- text,
212
- resolved: false,
213
- candidates: candidates?.map(c => ({
214
- entityId: c.entityId,
215
- title: c.title
216
- }))
217
- };
218
-
219
- await dbRun(
220
- this.db,
221
- `INSERT INTO entities (
222
- entity_id, entity_type, canonical_key, title, stage, status,
223
- current_json, title_norm, search_text, created_at, updated_at
224
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
225
- [
226
- entityId,
227
- 'condition',
228
- canonicalKey,
229
- text,
230
- 'raw',
231
- 'active',
232
- JSON.stringify(currentJson),
233
- text.toLowerCase().trim(),
234
- text,
235
- now,
236
- now
237
- ]
238
- );
239
-
240
- // Create alias
241
- await dbRun(
242
- this.db,
243
- `INSERT INTO entity_aliases (entity_type, canonical_key, entity_id, is_primary)
244
- VALUES (?, ?, ?, TRUE)
245
- ON CONFLICT (entity_type, canonical_key) DO NOTHING`,
246
- ['condition', canonicalKey, entityId]
247
- );
248
-
249
- return entityId;
250
- }
251
-
252
- /**
253
- * Declare a new artifact entity
254
- */
255
- private async declareArtifact(
256
- identifier: string,
257
- canonicalKey: string
258
- ): Promise<string> {
259
- const entityId = randomUUID();
260
- const now = new Date().toISOString();
261
-
262
- // Determine artifact type
263
- let artifactType = 'generic';
264
- if (URL_PATTERN.test(identifier)) {
265
- artifactType = 'url';
266
- } else if (JIRA_PATTERN.test(identifier)) {
267
- artifactType = 'jira';
268
- } else if (GITHUB_ISSUE_PATTERN.test(identifier)) {
269
- artifactType = 'github_issue';
270
- }
271
-
272
- const currentJson = {
273
- identifier,
274
- artifactType
275
- };
276
-
277
- await dbRun(
278
- this.db,
279
- `INSERT INTO entities (
280
- entity_id, entity_type, canonical_key, title, stage, status,
281
- current_json, title_norm, search_text, created_at, updated_at
282
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
283
- [
284
- entityId,
285
- 'artifact',
286
- canonicalKey,
287
- identifier,
288
- 'raw',
289
- 'active',
290
- JSON.stringify(currentJson),
291
- identifier.toLowerCase(),
292
- identifier,
293
- now,
294
- now
295
- ]
296
- );
297
-
298
- // Create alias
299
- await dbRun(
300
- this.db,
301
- `INSERT INTO entity_aliases (entity_type, canonical_key, entity_id, is_primary)
302
- VALUES (?, ?, ?, TRUE)
303
- ON CONFLICT (entity_type, canonical_key) DO NOTHING`,
304
- ['artifact', canonicalKey, entityId]
305
- );
306
-
307
- return entityId;
308
- }
309
-
310
- /**
311
- * Create unknown placeholder condition
312
- * Used when task is blocked but no blocker text provided
313
- */
314
- async createUnknownPlaceholder(taskTitle: string): Promise<BlockerRef> {
315
- const text = `Unknown blocker for: ${taskTitle}`;
316
-
317
- const ref = await this.createConditionBlocker(text);
318
-
319
- // Mark as auto placeholder
320
- await dbRun(
321
- this.db,
322
- `UPDATE entities
323
- SET current_json = json_set(current_json, '$.auto_placeholder', true)
324
- WHERE entity_id = ?`,
325
- [ref.entityId]
326
- );
327
-
328
- return {
329
- ...ref,
330
- confidence: 0.0
331
- };
332
- }
333
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Task Entity System - AXIOMMIND Principle 5
3
- * Task is Entity, state via event fold
4
- */
5
-
6
- export * from './task-matcher.js';
7
- export * from './blocker-resolver.js';
8
- export * from './task-resolver.js';
9
- export * from './task-projector.js';
@@ -1,240 +0,0 @@
1
- /**
2
- * Task Matcher - Find existing tasks by title similarity
3
- * AXIOMMIND: strict matching (≥0.92, gap≥0.03)
4
- */
5
-
6
- import { dbAll, toDate, type Database } from '../db-wrapper.js';
7
- import type { Entity, MatchConfidence } from '../types.js';
8
- import { makeEntityCanonicalKey } from '../canonical-key.js';
9
- import { MATCH_THRESHOLDS } from '../types.js';
10
-
11
- export interface TaskMatchResult {
12
- match: Entity | null;
13
- confidence: MatchConfidence;
14
- score: number;
15
- gap?: number;
16
- candidates?: Entity[];
17
- }
18
-
19
- export interface TaskMatcherConfig {
20
- minCombinedScore: number;
21
- minGap: number;
22
- suggestionThreshold: number;
23
- maxCandidates: number;
24
- }
25
-
26
- const DEFAULT_CONFIG: TaskMatcherConfig = {
27
- minCombinedScore: MATCH_THRESHOLDS.minCombinedScore,
28
- minGap: MATCH_THRESHOLDS.minGap,
29
- suggestionThreshold: MATCH_THRESHOLDS.suggestionThreshold,
30
- maxCandidates: 5
31
- };
32
-
33
- export class TaskMatcher {
34
- private readonly config: TaskMatcherConfig;
35
-
36
- constructor(
37
- private db: Database,
38
- config?: Partial<TaskMatcherConfig>
39
- ) {
40
- this.config = { ...DEFAULT_CONFIG, ...config };
41
- }
42
-
43
- /**
44
- * Find task by exact canonical key match
45
- */
46
- async findExact(title: string, project?: string): Promise<Entity | null> {
47
- const canonicalKey = makeEntityCanonicalKey('task', title, { project });
48
-
49
- const rows = await dbAll<Record<string, unknown>>(
50
- this.db,
51
- `SELECT * FROM entities
52
- WHERE entity_type = 'task' AND canonical_key = ?
53
- AND status = 'active'`,
54
- [canonicalKey]
55
- );
56
-
57
- if (rows.length === 0) return null;
58
- return this.rowToEntity(rows[0]);
59
- }
60
-
61
- /**
62
- * Find task by alias
63
- */
64
- async findByAlias(title: string, project?: string): Promise<Entity | null> {
65
- const canonicalKey = makeEntityCanonicalKey('task', title, { project });
66
-
67
- const rows = await dbAll<Record<string, unknown>>(
68
- this.db,
69
- `SELECT e.* FROM entities e
70
- JOIN entity_aliases a ON e.entity_id = a.entity_id
71
- WHERE a.entity_type = 'task' AND a.canonical_key = ?
72
- AND e.status = 'active'`,
73
- [canonicalKey]
74
- );
75
-
76
- if (rows.length === 0) return null;
77
- return this.rowToEntity(rows[0]);
78
- }
79
-
80
- /**
81
- * Search tasks by text (FTS-like)
82
- */
83
- async searchByText(query: string, project?: string): Promise<Array<{ entity: Entity; score: number }>> {
84
- const searchPattern = `%${query.toLowerCase()}%`;
85
-
86
- let sql = `
87
- SELECT *,
88
- CASE
89
- WHEN title_norm = ? THEN 1.0
90
- WHEN title_norm LIKE ? THEN 0.9
91
- ELSE 0.7
92
- END as match_score
93
- FROM entities
94
- WHERE entity_type = 'task'
95
- AND status = 'active'
96
- AND (title_norm LIKE ? OR search_text LIKE ?)
97
- `;
98
-
99
- const normalizedQuery = query.toLowerCase().trim();
100
- const params: unknown[] = [normalizedQuery, `%${normalizedQuery}%`, searchPattern, searchPattern];
101
-
102
- if (project) {
103
- sql += ` AND json_extract(current_json, '$.project') = ?`;
104
- params.push(project);
105
- }
106
-
107
- sql += ` ORDER BY match_score DESC, updated_at DESC LIMIT ?`;
108
- params.push(this.config.maxCandidates);
109
-
110
- const rows = await dbAll<Record<string, unknown>>(this.db, sql, params);
111
-
112
- return rows.map(row => ({
113
- entity: this.rowToEntity(row),
114
- score: row.match_score as number
115
- }));
116
- }
117
-
118
- /**
119
- * Match task with confidence classification
120
- * Returns high confidence only if score ≥ 0.92 AND gap ≥ 0.03
121
- */
122
- async match(title: string, project?: string): Promise<TaskMatchResult> {
123
- // Step 1: Try exact match
124
- const exactMatch = await this.findExact(title, project);
125
- if (exactMatch) {
126
- return {
127
- match: exactMatch,
128
- confidence: 'high',
129
- score: 1.0
130
- };
131
- }
132
-
133
- // Step 2: Try alias match
134
- const aliasMatch = await this.findByAlias(title, project);
135
- if (aliasMatch) {
136
- return {
137
- match: aliasMatch,
138
- confidence: 'high',
139
- score: 0.98
140
- };
141
- }
142
-
143
- // Step 3: Try text search
144
- const searchResults = await this.searchByText(title, project);
145
- if (searchResults.length === 0) {
146
- return {
147
- match: null,
148
- confidence: 'none',
149
- score: 0
150
- };
151
- }
152
-
153
- const topResult = searchResults[0];
154
- const secondScore = searchResults.length > 1 ? searchResults[1].score : null;
155
-
156
- // Calculate gap
157
- const gap = secondScore !== null ? topResult.score - secondScore : Infinity;
158
-
159
- // Classify confidence
160
- const confidence = this.classifyConfidence(topResult.score, gap);
161
-
162
- // For strict matching, only return high confidence if criteria met
163
- if (confidence === 'high') {
164
- return {
165
- match: topResult.entity,
166
- confidence: 'high',
167
- score: topResult.score,
168
- gap
169
- };
170
- }
171
-
172
- // For suggested, return candidates
173
- if (confidence === 'suggested') {
174
- return {
175
- match: null,
176
- confidence: 'suggested',
177
- score: topResult.score,
178
- gap,
179
- candidates: searchResults.slice(0, this.config.maxCandidates).map(r => r.entity)
180
- };
181
- }
182
-
183
- return {
184
- match: null,
185
- confidence: 'none',
186
- score: topResult.score
187
- };
188
- }
189
-
190
- /**
191
- * Classify confidence based on AXIOMMIND thresholds
192
- */
193
- private classifyConfidence(score: number, gap: number): MatchConfidence {
194
- const { minCombinedScore, minGap, suggestionThreshold } = this.config;
195
-
196
- // High confidence: score ≥ 0.92 AND gap ≥ 0.03
197
- if (score >= minCombinedScore && gap >= minGap) {
198
- return 'high';
199
- }
200
-
201
- // Suggested: score ≥ 0.75
202
- if (score >= suggestionThreshold) {
203
- return 'suggested';
204
- }
205
-
206
- return 'none';
207
- }
208
-
209
- /**
210
- * Get suggestion candidates (for condition fallback)
211
- */
212
- async getSuggestionCandidates(title: string, project?: string): Promise<Entity[]> {
213
- const searchResults = await this.searchByText(title, project);
214
- return searchResults
215
- .filter(r => r.score >= this.config.suggestionThreshold)
216
- .slice(0, this.config.maxCandidates)
217
- .map(r => r.entity);
218
- }
219
-
220
- /**
221
- * Convert database row to Entity
222
- */
223
- private rowToEntity(row: Record<string, unknown>): Entity {
224
- return {
225
- entityId: row.entity_id as string,
226
- entityType: row.entity_type as 'task' | 'condition' | 'artifact',
227
- canonicalKey: row.canonical_key as string,
228
- title: row.title as string,
229
- stage: row.stage as 'raw' | 'working' | 'candidate' | 'verified' | 'certified',
230
- status: row.status as 'active' | 'contested' | 'deprecated' | 'superseded',
231
- currentJson: typeof row.current_json === 'string'
232
- ? JSON.parse(row.current_json)
233
- : row.current_json as Record<string, unknown>,
234
- titleNorm: row.title_norm as string | undefined,
235
- searchText: row.search_text as string | undefined,
236
- createdAt: toDate(row.created_at),
237
- updatedAt: toDate(row.updated_at)
238
- };
239
- }
240
- }