squish-memory 1.2.0 → 1.2.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/bin/squish-mcp.mjs +40 -42
- package/core/scheduler/cron-scheduler.ts +10 -1
- package/core/worker.ts +10 -1
- package/package.json +119 -119
- package/packages/mcp/src/index.ts +99 -36
- package/dist/config.d.ts +0 -106
- package/dist/config.js +0 -194
- package/dist/core/adapters/config/claude-code.d.ts +0 -45
- package/dist/core/adapters/config/claude-code.js +0 -113
- package/dist/core/adapters/config/cursor.d.ts +0 -26
- package/dist/core/adapters/config/cursor.js +0 -74
- package/dist/core/adapters/config/opencode.d.ts +0 -23
- package/dist/core/adapters/config/opencode.js +0 -73
- package/dist/core/adapters/config/windsurf.d.ts +0 -26
- package/dist/core/adapters/config/windsurf.js +0 -74
- package/dist/core/adapters/index.d.ts +0 -45
- package/dist/core/adapters/index.js +0 -84
- package/dist/core/adapters/scripts/install-adapter.d.ts +0 -19
- package/dist/core/adapters/scripts/install-adapter.js +0 -149
- package/dist/core/adapters/timeline.d.ts +0 -23
- package/dist/core/adapters/timeline.js +0 -88
- package/dist/core/adapters/types.d.ts +0 -137
- package/dist/core/adapters/types.js +0 -50
- package/dist/core/agent-preferences.d.ts +0 -16
- package/dist/core/agent-preferences.js +0 -124
- package/dist/core/algorithms/analytics/token-estimator.d.ts +0 -50
- package/dist/core/algorithms/analytics/token-estimator.js +0 -154
- package/dist/core/algorithms/detection/hash-filters.d.ts +0 -47
- package/dist/core/algorithms/detection/hash-filters.js +0 -190
- package/dist/core/algorithms/detection/semantic-ranker.d.ts +0 -32
- package/dist/core/algorithms/detection/semantic-ranker.js +0 -118
- package/dist/core/algorithms/detection/two-stage-detector.d.ts +0 -52
- package/dist/core/algorithms/detection/two-stage-detector.js +0 -299
- package/dist/core/algorithms/handlers/approve-merge.d.ts +0 -22
- package/dist/core/algorithms/handlers/approve-merge.js +0 -179
- package/dist/core/algorithms/handlers/detect-duplicates.d.ts +0 -47
- package/dist/core/algorithms/handlers/detect-duplicates.js +0 -145
- package/dist/core/algorithms/handlers/get-stats.d.ts +0 -39
- package/dist/core/algorithms/handlers/get-stats.js +0 -88
- package/dist/core/algorithms/handlers/list-proposals.d.ts +0 -45
- package/dist/core/algorithms/handlers/list-proposals.js +0 -83
- package/dist/core/algorithms/handlers/preview-merge.d.ts +0 -39
- package/dist/core/algorithms/handlers/preview-merge.js +0 -93
- package/dist/core/algorithms/handlers/reject-merge.d.ts +0 -28
- package/dist/core/algorithms/handlers/reject-merge.js +0 -69
- package/dist/core/algorithms/handlers/reverse-merge.d.ts +0 -21
- package/dist/core/algorithms/handlers/reverse-merge.js +0 -121
- package/dist/core/algorithms/index.d.ts +0 -21
- package/dist/core/algorithms/index.js +0 -26
- package/dist/core/algorithms/operations/cache-maintenance.d.ts +0 -12
- package/dist/core/algorithms/operations/cache-maintenance.js +0 -157
- package/dist/core/algorithms/safety/safety-checks.d.ts +0 -18
- package/dist/core/algorithms/safety/safety-checks.js +0 -179
- package/dist/core/algorithms/strategies/merge-strategies.d.ts +0 -50
- package/dist/core/algorithms/strategies/merge-strategies.js +0 -288
- package/dist/core/algorithms/types.d.ts +0 -125
- package/dist/core/algorithms/types.js +0 -5
- package/dist/core/algorithms/utils/response-builder.d.ts +0 -28
- package/dist/core/algorithms/utils/response-builder.js +0 -37
- package/dist/core/associations.d.ts +0 -33
- package/dist/core/associations.js +0 -284
- package/dist/core/autosave.d.ts +0 -19
- package/dist/core/autosave.js +0 -16
- package/dist/core/beliefs/decay.d.ts +0 -27
- package/dist/core/beliefs/decay.js +0 -217
- package/dist/core/beliefs/extractor.d.ts +0 -9
- package/dist/core/beliefs/extractor.js +0 -113
- package/dist/core/beliefs/store.d.ts +0 -46
- package/dist/core/beliefs/store.js +0 -466
- package/dist/core/beliefs/types.d.ts +0 -28
- package/dist/core/beliefs/types.js +0 -2
- package/dist/core/commands/mcp-server.d.ts +0 -2
- package/dist/core/commands/mcp-server.js +0 -6
- package/dist/core/commands/remember.d.ts +0 -24
- package/dist/core/commands/remember.js +0 -144
- package/dist/core/compression.d.ts +0 -45
- package/dist/core/compression.js +0 -160
- package/dist/core/consolidation.d.ts +0 -37
- package/dist/core/consolidation.js +0 -248
- package/dist/core/context/agent-context.d.ts +0 -106
- package/dist/core/context/agent-context.js +0 -274
- package/dist/core/context/context-paging.d.ts +0 -80
- package/dist/core/context/context-paging.js +0 -328
- package/dist/core/context/context-window.d.ts +0 -40
- package/dist/core/context/context-window.js +0 -177
- package/dist/core/context/context.d.ts +0 -7
- package/dist/core/context/context.js +0 -22
- package/dist/core/embeddings/embeddings.d.ts +0 -29
- package/dist/core/embeddings/embeddings.js +0 -546
- package/dist/core/embeddings/google-multimodal.d.ts +0 -14
- package/dist/core/embeddings/google-multimodal.js +0 -146
- package/dist/core/embeddings/local-embeddings.d.ts +0 -11
- package/dist/core/embeddings/local-embeddings.js +0 -11
- package/dist/core/embeddings/qmd-client.d.ts +0 -136
- package/dist/core/embeddings/qmd-client.js +0 -403
- package/dist/core/embeddings/transformers-local.d.ts +0 -64
- package/dist/core/embeddings/transformers-local.js +0 -213
- package/dist/core/embeddings.d.ts +0 -2
- package/dist/core/embeddings.js +0 -3
- package/dist/core/error-handling.d.ts +0 -63
- package/dist/core/error-handling.js +0 -173
- package/dist/core/graph/entity-deduplicator.d.ts +0 -24
- package/dist/core/graph/entity-deduplicator.js +0 -183
- package/dist/core/graph/graph-builder.d.ts +0 -46
- package/dist/core/graph/graph-builder.js +0 -174
- package/dist/core/graph/graph-traversal.d.ts +0 -80
- package/dist/core/graph/graph-traversal.js +0 -315
- package/dist/core/graph/index.d.ts +0 -19
- package/dist/core/graph/index.js +0 -13
- package/dist/core/graph/llm-entity-extractor.d.ts +0 -49
- package/dist/core/graph/llm-entity-extractor.js +0 -313
- package/dist/core/graph/multi-hop-retrieval.d.ts +0 -48
- package/dist/core/graph/multi-hop-retrieval.js +0 -215
- package/dist/core/graph/relationship-extractor.d.ts +0 -48
- package/dist/core/graph/relationship-extractor.js +0 -351
- package/dist/core/hooks/agent-hooks.d.ts +0 -83
- package/dist/core/hooks/agent-hooks.js +0 -521
- package/dist/core/hooks/auto-tagger.d.ts +0 -19
- package/dist/core/hooks/auto-tagger.js +0 -155
- package/dist/core/hooks/capture-filter.d.ts +0 -41
- package/dist/core/hooks/capture-filter.js +0 -128
- package/dist/core/hot-cache.d.ts +0 -86
- package/dist/core/hot-cache.js +0 -285
- package/dist/core/index.d.ts +0 -10
- package/dist/core/index.js +0 -11
- package/dist/core/ingestion/agent-memory.d.ts +0 -22
- package/dist/core/ingestion/agent-memory.js +0 -109
- package/dist/core/ingestion/core-memory.d.ts +0 -78
- package/dist/core/ingestion/core-memory.js +0 -226
- package/dist/core/ingestion/learnings.d.ts +0 -57
- package/dist/core/ingestion/learnings.js +0 -205
- package/dist/core/ingestion/signal-engine.d.ts +0 -41
- package/dist/core/ingestion/signal-engine.js +0 -201
- package/dist/core/integrations/obsidian-vault.d.ts +0 -31
- package/dist/core/integrations/obsidian-vault.js +0 -156
- package/dist/core/layers/generator.d.ts +0 -25
- package/dist/core/layers/generator.js +0 -76
- package/dist/core/lib/db-client.d.ts +0 -114
- package/dist/core/lib/db-client.js +0 -130
- package/dist/core/lib/parse-embedding.d.ts +0 -9
- package/dist/core/lib/parse-embedding.js +0 -58
- package/dist/core/lib/schemas.d.ts +0 -132
- package/dist/core/lib/schemas.js +0 -87
- package/dist/core/lib/types.d.ts +0 -45
- package/dist/core/lib/types.js +0 -6
- package/dist/core/lib/utils.d.ts +0 -18
- package/dist/core/lib/utils.js +0 -145
- package/dist/core/lib/validation.d.ts +0 -38
- package/dist/core/lib/validation.js +0 -151
- package/dist/core/lifecycle.d.ts +0 -25
- package/dist/core/lifecycle.js +0 -292
- package/dist/core/logger.d.ts +0 -17
- package/dist/core/logger.js +0 -46
- package/dist/core/mcp/client.d.ts +0 -17
- package/dist/core/mcp/client.js +0 -101
- package/dist/core/mcp/index.d.ts +0 -6
- package/dist/core/mcp/index.js +0 -6
- package/dist/core/mcp/server.d.ts +0 -18
- package/dist/core/mcp/server.js +0 -157
- package/dist/core/mcp/standalone-server.d.ts +0 -13
- package/dist/core/mcp/standalone-server.js +0 -46
- package/dist/core/mcp/tools.d.ts +0 -7
- package/dist/core/mcp/tools.js +0 -278
- package/dist/core/mcp/types.d.ts +0 -87
- package/dist/core/mcp/types.js +0 -48
- package/dist/core/memory/bridge-discovery.d.ts +0 -50
- package/dist/core/memory/bridge-discovery.js +0 -291
- package/dist/core/memory/categorizer.d.ts +0 -27
- package/dist/core/memory/categorizer.js +0 -306
- package/dist/core/memory/conflict-detector.d.ts +0 -7
- package/dist/core/memory/conflict-detector.js +0 -43
- package/dist/core/memory/consolidation.d.ts +0 -42
- package/dist/core/memory/consolidation.js +0 -277
- package/dist/core/memory/context-collector.d.ts +0 -10
- package/dist/core/memory/context-collector.js +0 -56
- package/dist/core/memory/contradiction-resolver.d.ts +0 -40
- package/dist/core/memory/contradiction-resolver.js +0 -368
- package/dist/core/memory/edit-workflow.d.ts +0 -19
- package/dist/core/memory/edit-workflow.js +0 -120
- package/dist/core/memory/entity-extractor.d.ts +0 -37
- package/dist/core/memory/entity-extractor.js +0 -350
- package/dist/core/memory/entity-resolver.d.ts +0 -23
- package/dist/core/memory/entity-resolver.js +0 -64
- package/dist/core/memory/explain.d.ts +0 -18
- package/dist/core/memory/explain.js +0 -92
- package/dist/core/memory/fact-deriver.d.ts +0 -31
- package/dist/core/memory/fact-deriver.js +0 -236
- package/dist/core/memory/fact-extractor.d.ts +0 -24
- package/dist/core/memory/fact-extractor.js +0 -89
- package/dist/core/memory/feedback-tracker.d.ts +0 -12
- package/dist/core/memory/feedback-tracker.js +0 -155
- package/dist/core/memory/hooks.d.ts +0 -88
- package/dist/core/memory/hooks.js +0 -174
- package/dist/core/memory/hybrid-retrieval.d.ts +0 -27
- package/dist/core/memory/hybrid-retrieval.js +0 -37
- package/dist/core/memory/hybrid-scorer.d.ts +0 -40
- package/dist/core/memory/hybrid-scorer.js +0 -267
- package/dist/core/memory/hybrid-search.d.ts +0 -23
- package/dist/core/memory/hybrid-search.js +0 -596
- package/dist/core/memory/importance.d.ts +0 -46
- package/dist/core/memory/importance.js +0 -241
- package/dist/core/memory/index.d.ts +0 -9
- package/dist/core/memory/index.js +0 -11
- package/dist/core/memory/loader.d.ts +0 -31
- package/dist/core/memory/loader.js +0 -141
- package/dist/core/memory/markdown/markdown-storage.d.ts +0 -72
- package/dist/core/memory/markdown/markdown-storage.js +0 -243
- package/dist/core/memory/memories.d.ts +0 -43
- package/dist/core/memory/memories.js +0 -452
- package/dist/core/memory/memory-lifecycle.d.ts +0 -8
- package/dist/core/memory/memory-lifecycle.js +0 -47
- package/dist/core/memory/memory-manager.d.ts +0 -15
- package/dist/core/memory/memory-manager.js +0 -46
- package/dist/core/memory/migrate.d.ts +0 -21
- package/dist/core/memory/migrate.js +0 -134
- package/dist/core/memory/normalization.d.ts +0 -7
- package/dist/core/memory/normalization.js +0 -26
- package/dist/core/memory/path-strengthener.d.ts +0 -39
- package/dist/core/memory/path-strengthener.js +0 -150
- package/dist/core/memory/progressive-disclosure.d.ts +0 -43
- package/dist/core/memory/progressive-disclosure.js +0 -280
- package/dist/core/memory/query-processor.d.ts +0 -21
- package/dist/core/memory/query-processor.js +0 -106
- package/dist/core/memory/query-rewriter.d.ts +0 -13
- package/dist/core/memory/query-rewriter.js +0 -118
- package/dist/core/memory/response-analyzer.d.ts +0 -9
- package/dist/core/memory/response-analyzer.js +0 -61
- package/dist/core/memory/retrieval-feedback.d.ts +0 -70
- package/dist/core/memory/retrieval-feedback.js +0 -213
- package/dist/core/memory/serialization.d.ts +0 -10
- package/dist/core/memory/serialization.js +0 -84
- package/dist/core/memory/stale-cleaner.d.ts +0 -26
- package/dist/core/memory/stale-cleaner.js +0 -97
- package/dist/core/memory/stats.d.ts +0 -32
- package/dist/core/memory/stats.js +0 -143
- package/dist/core/memory/telemetry.d.ts +0 -69
- package/dist/core/memory/telemetry.js +0 -313
- package/dist/core/memory/temporal-facts.d.ts +0 -41
- package/dist/core/memory/temporal-facts.js +0 -283
- package/dist/core/memory/temporal-parser.d.ts +0 -32
- package/dist/core/memory/temporal-parser.js +0 -385
- package/dist/core/memory/trigger-detector.d.ts +0 -21
- package/dist/core/memory/trigger-detector.js +0 -79
- package/dist/core/memory/write-gate.d.ts +0 -54
- package/dist/core/memory/write-gate.js +0 -210
- package/dist/core/places/index.d.ts +0 -14
- package/dist/core/places/index.js +0 -14
- package/dist/core/places/memory-places.d.ts +0 -68
- package/dist/core/places/memory-places.js +0 -261
- package/dist/core/places/places.d.ts +0 -88
- package/dist/core/places/places.js +0 -314
- package/dist/core/places/rules.d.ts +0 -74
- package/dist/core/places/rules.js +0 -240
- package/dist/core/places/walking.d.ts +0 -56
- package/dist/core/places/walking.js +0 -121
- package/dist/core/projects.d.ts +0 -17
- package/dist/core/projects.js +0 -116
- package/dist/core/redis.d.ts +0 -11
- package/dist/core/redis.js +0 -69
- package/dist/core/responses.d.ts +0 -96
- package/dist/core/responses.js +0 -122
- package/dist/core/runtime/trust-report.d.ts +0 -102
- package/dist/core/runtime/trust-report.js +0 -107
- package/dist/core/runtime/trust-state.d.ts +0 -12
- package/dist/core/runtime/trust-state.js +0 -309
- package/dist/core/scheduler/cron-scheduler.d.ts +0 -32
- package/dist/core/scheduler/cron-scheduler.js +0 -493
- package/dist/core/scheduler/heartbeat.d.ts +0 -11
- package/dist/core/scheduler/heartbeat.js +0 -73
- package/dist/core/scheduler/index.d.ts +0 -8
- package/dist/core/scheduler/index.js +0 -8
- package/dist/core/scheduler/job-runner.d.ts +0 -11
- package/dist/core/scheduler/job-runner.js +0 -164
- package/dist/core/search/conversations.d.ts +0 -25
- package/dist/core/search/conversations.js +0 -110
- package/dist/core/search/entities.d.ts +0 -12
- package/dist/core/search/entities.js +0 -31
- package/dist/core/search/folder-context.d.ts +0 -25
- package/dist/core/search/folder-context.js +0 -119
- package/dist/core/search/graph-boost.d.ts +0 -7
- package/dist/core/search/graph-boost.js +0 -23
- package/dist/core/search/index.d.ts +0 -4
- package/dist/core/search/index.js +0 -5
- package/dist/core/search/qmd-wrapper.d.ts +0 -36
- package/dist/core/search/qmd-wrapper.js +0 -58
- package/dist/core/security/encrypt.d.ts +0 -6
- package/dist/core/security/encrypt.js +0 -47
- package/dist/core/security/governance.d.ts +0 -26
- package/dist/core/security/governance.js +0 -79
- package/dist/core/security/privacy.d.ts +0 -23
- package/dist/core/security/privacy.js +0 -82
- package/dist/core/security/secret-detector.d.ts +0 -32
- package/dist/core/security/secret-detector.js +0 -88
- package/dist/core/session/auto-load.d.ts +0 -6
- package/dist/core/session/auto-load.js +0 -144
- package/dist/core/session/entity-tracker.d.ts +0 -62
- package/dist/core/session/entity-tracker.js +0 -287
- package/dist/core/session/index.d.ts +0 -7
- package/dist/core/session/index.js +0 -7
- package/dist/core/session/reference-resolver.d.ts +0 -26
- package/dist/core/session/reference-resolver.js +0 -121
- package/dist/core/session/self-iteration-job.d.ts +0 -35
- package/dist/core/session/self-iteration-job.js +0 -387
- package/dist/core/session/session-hooks.d.ts +0 -18
- package/dist/core/session/session-hooks.js +0 -58
- package/dist/core/session/types.d.ts +0 -26
- package/dist/core/session/types.js +0 -10
- package/dist/core/session/working-set.d.ts +0 -50
- package/dist/core/session/working-set.js +0 -212
- package/dist/core/snapshots/cleanup.d.ts +0 -9
- package/dist/core/snapshots/cleanup.js +0 -12
- package/dist/core/snapshots/comparison.d.ts +0 -19
- package/dist/core/snapshots/comparison.js +0 -43
- package/dist/core/snapshots/creation.d.ts +0 -13
- package/dist/core/snapshots/creation.js +0 -117
- package/dist/core/snapshots/retrieval.d.ts +0 -7
- package/dist/core/snapshots/retrieval.js +0 -41
- package/dist/core/snapshots/stats.d.ts +0 -11
- package/dist/core/snapshots/stats.js +0 -52
- package/dist/core/storage/cache.d.ts +0 -13
- package/dist/core/storage/cache.js +0 -202
- package/dist/core/storage/database.d.ts +0 -12
- package/dist/core/storage/database.js +0 -12
- package/dist/core/summarization/cleanup.d.ts +0 -9
- package/dist/core/summarization/cleanup.js +0 -12
- package/dist/core/summarization/queries.d.ts +0 -9
- package/dist/core/summarization/queries.js +0 -28
- package/dist/core/summarization/stats.d.ts +0 -14
- package/dist/core/summarization/stats.js +0 -52
- package/dist/core/summarization/strategies.d.ts +0 -24
- package/dist/core/summarization/strategies.js +0 -28
- package/dist/core/summarization.d.ts +0 -37
- package/dist/core/summarization.js +0 -188
- package/dist/core/temporal-facts.d.ts +0 -54
- package/dist/core/temporal-facts.js +0 -193
- package/dist/core/tracing/collector.d.ts +0 -111
- package/dist/core/tracing/collector.js +0 -350
- package/dist/core/tracing/visualizer.d.ts +0 -32
- package/dist/core/tracing/visualizer.js +0 -165
- package/dist/core/utils/cleanup-operations.d.ts +0 -13
- package/dist/core/utils/cleanup-operations.js +0 -44
- package/dist/core/utils/content-extraction.d.ts +0 -19
- package/dist/core/utils/content-extraction.js +0 -75
- package/dist/core/utils/filter-builder.d.ts +0 -13
- package/dist/core/utils/filter-builder.js +0 -44
- package/dist/core/utils/history-traversal.d.ts +0 -13
- package/dist/core/utils/history-traversal.js +0 -50
- package/dist/core/utils/memory-operations.d.ts +0 -17
- package/dist/core/utils/memory-operations.js +0 -43
- package/dist/core/utils/query-operations.d.ts +0 -18
- package/dist/core/utils/query-operations.js +0 -65
- package/dist/core/utils/summarization-helpers.d.ts +0 -17
- package/dist/core/utils/summarization-helpers.js +0 -33
- package/dist/core/utils/temporal-queries.d.ts +0 -13
- package/dist/core/utils/temporal-queries.js +0 -27
- package/dist/core/utils/vector-operations.d.ts +0 -71
- package/dist/core/utils/vector-operations.js +0 -129
- package/dist/core/utils/version-management.d.ts +0 -9
- package/dist/core/utils/version-management.js +0 -61
- package/dist/core/worker.d.ts +0 -82
- package/dist/core/worker.js +0 -272
- package/dist/db/adapter.d.ts +0 -7
- package/dist/db/adapter.js +0 -175
- package/dist/db/bootstrap.d.ts +0 -11
- package/dist/db/bootstrap.js +0 -1034
- package/dist/db/drizzle/schema-sqlite.d.ts +0 -5538
- package/dist/db/drizzle/schema-sqlite.js +0 -763
- package/dist/db/drizzle/schema.d.ts +0 -4734
- package/dist/db/drizzle/schema.js +0 -859
- package/dist/db/drizzle.config.d.ts +0 -3
- package/dist/db/drizzle.config.js +0 -12
- package/dist/db/index.d.ts +0 -7
- package/dist/db/index.js +0 -89
- package/dist/db/migrations/associations.d.ts +0 -6
- package/dist/db/migrations/associations.js +0 -29
- package/dist/db/migrations/beliefs.d.ts +0 -10
- package/dist/db/migrations/beliefs.js +0 -76
- package/dist/db/migrations/core-memory.d.ts +0 -6
- package/dist/db/migrations/core-memory.js +0 -29
- package/dist/db/migrations/fts.d.ts +0 -6
- package/dist/db/migrations/fts.js +0 -52
- package/dist/db/migrations/index.d.ts +0 -25
- package/dist/db/migrations/index.js +0 -51
- package/dist/db/migrations/indexes.d.ts +0 -6
- package/dist/db/migrations/indexes.js +0 -30
- package/dist/db/migrations/learnings.d.ts +0 -7
- package/dist/db/migrations/learnings.js +0 -26
- package/dist/db/migrations/maintenance.d.ts +0 -6
- package/dist/db/migrations/maintenance.js +0 -61
- package/dist/db/migrations/memories.d.ts +0 -7
- package/dist/db/migrations/memories.js +0 -16
- package/dist/db/migrations/memory-places.d.ts +0 -6
- package/dist/db/migrations/memory-places.js +0 -29
- package/dist/db/migrations/places.d.ts +0 -6
- package/dist/db/migrations/places.js +0 -43
- package/dist/db/migrations/projects.d.ts +0 -3
- package/dist/db/migrations/projects.js +0 -13
- package/dist/db/migrations/tier-conversion.d.ts +0 -7
- package/dist/db/migrations/tier-conversion.js +0 -20
- package/dist/db/neon.d.ts +0 -8
- package/dist/db/neon.js +0 -20
- package/dist/db/schema/beliefs.d.ts +0 -9
- package/dist/db/schema/beliefs.js +0 -46
- package/dist/db/schema/generator.d.ts +0 -38
- package/dist/db/schema/generator.js +0 -108
- package/dist/db/schema/index.d.ts +0 -39
- package/dist/db/schema/index.js +0 -51
- package/dist/db/schema/learnings.d.ts +0 -7
- package/dist/db/schema/learnings.js +0 -30
- package/dist/db/schema/memories.d.ts +0 -7
- package/dist/db/schema/memories.js +0 -81
- package/dist/db/schema/projects.d.ts +0 -4
- package/dist/db/schema/projects.js +0 -31
- package/dist/db/schema/tables/context-sessions.d.ts +0 -9
- package/dist/db/schema/tables/context-sessions.js +0 -37
- package/dist/db/schema/tables/conversations.d.ts +0 -9
- package/dist/db/schema/tables/conversations.js +0 -47
- package/dist/db/schema/tables/core-memory.d.ts +0 -9
- package/dist/db/schema/tables/core-memory.js +0 -41
- package/dist/db/schema/tables/entities.d.ts +0 -9
- package/dist/db/schema/tables/entities.js +0 -39
- package/dist/db/schema/tables/entity-relations.d.ts +0 -9
- package/dist/db/schema/tables/entity-relations.js +0 -31
- package/dist/db/schema/tables/learnings.d.ts +0 -9
- package/dist/db/schema/tables/learnings.js +0 -66
- package/dist/db/schema/tables/memories.d.ts +0 -9
- package/dist/db/schema/tables/memories.js +0 -161
- package/dist/db/schema/tables/memory-associations.d.ts +0 -9
- package/dist/db/schema/tables/memory-associations.js +0 -39
- package/dist/db/schema/tables/memory-hash-cache.d.ts +0 -9
- package/dist/db/schema/tables/memory-hash-cache.js +0 -29
- package/dist/db/schema/tables/memory-merge-history.d.ts +0 -9
- package/dist/db/schema/tables/memory-merge-history.js +0 -33
- package/dist/db/schema/tables/memory-merge-proposals.d.ts +0 -9
- package/dist/db/schema/tables/memory-merge-proposals.js +0 -39
- package/dist/db/schema/tables/messages.d.ts +0 -9
- package/dist/db/schema/tables/messages.js +0 -41
- package/dist/db/schema/tables/namespaces.d.ts +0 -9
- package/dist/db/schema/tables/namespaces.js +0 -37
- package/dist/db/schema/tables/projects.d.ts +0 -9
- package/dist/db/schema/tables/projects.js +0 -31
- package/dist/db/schema/tables/users.d.ts +0 -9
- package/dist/db/schema/tables/users.js +0 -27
- package/dist/db/schema.d.ts +0 -3
- package/dist/db/schema.js +0 -11
- package/dist/db/supabase.d.ts +0 -9
- package/dist/db/supabase.js +0 -24
- package/dist/packages/mcp/src/index.d.ts +0 -3
- package/dist/packages/mcp/src/index.js +0 -733
|
@@ -1,521 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Hooks - Core Logic
|
|
3
|
-
*
|
|
4
|
-
* Universal hooks for auto-capturing agent activities.
|
|
5
|
-
* Works with Claude Code, OpenCode, Cursor, Windsurf.
|
|
6
|
-
*
|
|
7
|
-
* Hook events:
|
|
8
|
-
* - sessionStart: Inject relevant memories on session start
|
|
9
|
-
* - postToolUse: Record observations after tool execution
|
|
10
|
-
* - sessionEnd: Save snapshot and sync learnings
|
|
11
|
-
* - preCompact: Save state before context compaction
|
|
12
|
-
*/
|
|
13
|
-
import { randomUUID } from 'crypto';
|
|
14
|
-
import { createLearning } from '../ingestion/learnings.js';
|
|
15
|
-
import { getRecent, rememberMemory } from '../memory/memories.js';
|
|
16
|
-
import { logger } from '../logger.js';
|
|
17
|
-
import { shouldCaptureTool, categorizeTool } from './capture-filter.js';
|
|
18
|
-
import { inferTags } from './auto-tagger.js';
|
|
19
|
-
import { ensureProject, getProjectByPath } from '../projects.js';
|
|
20
|
-
import { autoAssignMemory, initializeDefaultPlaces } from '../places/index.js';
|
|
21
|
-
import { compressForContext } from '../compression.js';
|
|
22
|
-
import { getAgentPreferences } from '../agent-preferences.js';
|
|
23
|
-
import { classifySignalEvent, distillSignalEvent } from '../ingestion/signal-engine.js';
|
|
24
|
-
import { compactSessionWorkingSet, recordSessionSignal } from '../session/working-set.js';
|
|
25
|
-
import { getDbClient } from '../lib/db-client.js';
|
|
26
|
-
import { eq } from 'drizzle-orm';
|
|
27
|
-
import { serializeMetadata, deserializeMetadata } from '../memory/serialization.js';
|
|
28
|
-
import { addMemoryToGraph } from '../graph/graph-builder.js';
|
|
29
|
-
import { addSessionContextToHotCache } from '../hot-cache.js';
|
|
30
|
-
import { extractBeliefsFromMemory } from '../beliefs/extractor.js';
|
|
31
|
-
import { upsertBeliefsForMemory, getRecentFailures, getActiveConstraints, getActiveDecisions } from '../beliefs/store.js';
|
|
32
|
-
/** Session ID for tracking across agents */
|
|
33
|
-
let currentSessionId = null;
|
|
34
|
-
/**
|
|
35
|
-
* Generate a new session ID (universal across agents)
|
|
36
|
-
*/
|
|
37
|
-
export function generateSessionId() {
|
|
38
|
-
currentSessionId = randomUUID();
|
|
39
|
-
return currentSessionId;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Get current session ID
|
|
43
|
-
*/
|
|
44
|
-
export function getCurrentSessionId() {
|
|
45
|
-
return currentSessionId;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Set session ID (for resume/continue)
|
|
49
|
-
*/
|
|
50
|
-
export function setSessionId(sessionId) {
|
|
51
|
-
currentSessionId = sessionId;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Session start hook - inject relevant context
|
|
55
|
-
*/
|
|
56
|
-
export async function handleSessionStart(params) {
|
|
57
|
-
const { projectPath, mode, agentType } = params;
|
|
58
|
-
// Ensure project exists
|
|
59
|
-
await ensureProject(projectPath);
|
|
60
|
-
// Generate or get session ID
|
|
61
|
-
if (!currentSessionId) {
|
|
62
|
-
currentSessionId = generateSessionId();
|
|
63
|
-
}
|
|
64
|
-
logger.info(`[Hooks] Session start: ${mode} (agent: ${agentType}, session: ${currentSessionId})`);
|
|
65
|
-
// Get recent memories based on mode
|
|
66
|
-
const limit = mode === 'compact' ? 3 : 5;
|
|
67
|
-
const memories = await getRecent(projectPath, limit);
|
|
68
|
-
const compactedWorkingSet = await compactSessionWorkingSet(currentSessionId, projectPath);
|
|
69
|
-
// Get spatial memory context (places) for context injection
|
|
70
|
-
let placesContext = '';
|
|
71
|
-
try {
|
|
72
|
-
const { initializeDefaultPlaces, getProjectPlaces } = await import('../places/index.js');
|
|
73
|
-
const { getProjectByPath } = await import('../projects.js');
|
|
74
|
-
const project = await getProjectByPath(projectPath);
|
|
75
|
-
if (project) {
|
|
76
|
-
await initializeDefaultPlaces(project.id);
|
|
77
|
-
const places = await getProjectPlaces(project.id);
|
|
78
|
-
if (places.length > 0) {
|
|
79
|
-
const populatedPlaces = places.filter(p => p.memoryCount > 0).slice(0, 3);
|
|
80
|
-
if (populatedPlaces.length > 0) {
|
|
81
|
-
placesContext = '\n\nActive places: ' + populatedPlaces.map(p => `${p.name} (${p.memoryCount})`).join(', ');
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
// Don't fail if places not available
|
|
88
|
-
logger.debug(`[Hooks] Places context not available: ${e}`);
|
|
89
|
-
}
|
|
90
|
-
// Format for injection with compression
|
|
91
|
-
const formatted = memories.map((m, i) => {
|
|
92
|
-
const compressed = compressForContext(m.content || '');
|
|
93
|
-
return `${i + 1}. [${m.type}] ${compressed}`;
|
|
94
|
-
}).join('\n');
|
|
95
|
-
const workingSetContext = compactedWorkingSet.summary ? `Session working set:\n${compactedWorkingSet.summary}\n\n` : '';
|
|
96
|
-
const allContent = workingSetContext + formatted + placesContext;
|
|
97
|
-
// Get agent preferences for context injection
|
|
98
|
-
let preferences = [];
|
|
99
|
-
try {
|
|
100
|
-
const project = await getProjectByPath(projectPath);
|
|
101
|
-
if (project) {
|
|
102
|
-
preferences = await getAgentPreferences(project.id);
|
|
103
|
-
// Get beliefs for state reconstruction on session boot
|
|
104
|
-
// This is the "state reconstruction" - active beliefs shape next actions
|
|
105
|
-
const [failures, constraints, decisions] = await Promise.all([
|
|
106
|
-
getRecentFailures(project.id, 5),
|
|
107
|
-
getActiveConstraints(project.id, 10),
|
|
108
|
-
getActiveDecisions(project.id, 10),
|
|
109
|
-
]);
|
|
110
|
-
// Format beliefs into context
|
|
111
|
-
const beliefsSection = formatBeliefsForContext(failures, constraints, decisions);
|
|
112
|
-
// Add beliefs to injected context
|
|
113
|
-
if (beliefsSection) {
|
|
114
|
-
allContent = beliefsSection + '\n\n' + allContent;
|
|
115
|
-
}
|
|
116
|
-
logger.info(`[Hooks] Injected ${failures.length} failures, ${constraints.length} constraints, ${decisions.length} decisions`);
|
|
117
|
-
return {
|
|
118
|
-
memories: allContent ? allContent.split('\n') : [],
|
|
119
|
-
sessionId: currentSessionId,
|
|
120
|
-
count: memories.length,
|
|
121
|
-
preferences: preferences.length > 0 ? preferences : undefined,
|
|
122
|
-
beliefs: {
|
|
123
|
-
failures: failures.map(f => f.statement),
|
|
124
|
-
constraints: constraints.map(c => c.statement),
|
|
125
|
-
decisions: decisions.map(d => d.statement),
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
logger.debug(`[Hooks] Agent preferences not available: ${e}`);
|
|
132
|
-
}
|
|
133
|
-
logger.info(`[Hooks] Injected ${memories.length} memories for session start`);
|
|
134
|
-
return {
|
|
135
|
-
memories: allContent ? allContent.split('\n') : [],
|
|
136
|
-
sessionId: currentSessionId,
|
|
137
|
-
count: memories.length,
|
|
138
|
-
preferences: preferences.length > 0 ? preferences : undefined,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Format beliefs into context section for session boot
|
|
143
|
-
* This drives "state reconstruction" - agent sees active constraints/failures/decisions
|
|
144
|
-
*/
|
|
145
|
-
function formatBeliefsForContext(failures, constraints, decisions) {
|
|
146
|
-
const sections = [];
|
|
147
|
-
if (failures.length > 0) {
|
|
148
|
-
sections.push('AVOID:\n' + failures.map((f, i) => ` ${i + 1}. ${f.statement}${f.context ? ` (${f.context})` : ''}`).join('\n'));
|
|
149
|
-
}
|
|
150
|
-
if (constraints.length > 0) {
|
|
151
|
-
sections.push('CONSTRAINTS:\n' + constraints.map((c, i) => ` ${i + 1}. ${c.statement}${c.context ? ` (${c.context})` : ''}`).join('\n'));
|
|
152
|
-
}
|
|
153
|
-
if (decisions.length > 0) {
|
|
154
|
-
sections.push('DECISIONS:\n' + decisions.map((d, i) => ` ${i + 1}. ${d.statement}${d.context ? ` (${d.context})` : ''}`).join('\n'));
|
|
155
|
-
}
|
|
156
|
-
if (sections.length === 0)
|
|
157
|
-
return '';
|
|
158
|
-
return sections.join('\n\n');
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Post-tool-use hook - record observations
|
|
162
|
-
*/
|
|
163
|
-
export async function handlePostToolUse(params) {
|
|
164
|
-
const { toolName, toolInput, toolResult, projectPath, agentType } = params;
|
|
165
|
-
// Ensure project exists
|
|
166
|
-
await ensureProject(projectPath);
|
|
167
|
-
// Ensure session ID exists
|
|
168
|
-
if (!currentSessionId) {
|
|
169
|
-
currentSessionId = generateSessionId();
|
|
170
|
-
}
|
|
171
|
-
// Check if we should capture this tool
|
|
172
|
-
if (!shouldCaptureTool(toolName)) {
|
|
173
|
-
await recordSessionSignal({
|
|
174
|
-
sessionId: currentSessionId,
|
|
175
|
-
projectPath,
|
|
176
|
-
classification: 'discard',
|
|
177
|
-
distilledContent: `Filtered tool: ${toolName}`,
|
|
178
|
-
toolName,
|
|
179
|
-
target: extractTarget(toolName, toolInput),
|
|
180
|
-
});
|
|
181
|
-
return { captured: false, reason: `Tool ${toolName} filtered out` };
|
|
182
|
-
}
|
|
183
|
-
// Extract relevant information
|
|
184
|
-
const category = categorizeTool(toolName);
|
|
185
|
-
const target = extractTarget(toolName, toolInput);
|
|
186
|
-
const content = extractContent(toolName, toolInput, toolResult);
|
|
187
|
-
const signalDecision = classifySignalEvent({
|
|
188
|
-
toolName,
|
|
189
|
-
toolInput,
|
|
190
|
-
toolResult,
|
|
191
|
-
sessionId: currentSessionId,
|
|
192
|
-
});
|
|
193
|
-
const distilledContent = distillSignalEvent({
|
|
194
|
-
toolName,
|
|
195
|
-
command: String(toolInput.command || toolInput.cmd || ''),
|
|
196
|
-
content: signalDecision.content || content,
|
|
197
|
-
classification: signalDecision.classification,
|
|
198
|
-
});
|
|
199
|
-
// Infer tags from context
|
|
200
|
-
const tags = inferTags(toolName, toolInput, distilledContent || content);
|
|
201
|
-
await recordSessionSignal({
|
|
202
|
-
sessionId: currentSessionId,
|
|
203
|
-
projectPath,
|
|
204
|
-
classification: signalDecision.classification,
|
|
205
|
-
distilledContent,
|
|
206
|
-
toolName,
|
|
207
|
-
target,
|
|
208
|
-
metadata: {
|
|
209
|
-
activeFiles: extractActiveFiles(toolName, toolInput),
|
|
210
|
-
command: String(toolInput.command || toolInput.cmd || ''),
|
|
211
|
-
outcome: inferOutcome(signalDecision, toolResult),
|
|
212
|
-
contentHash: signalDecision.contentHash,
|
|
213
|
-
tokensSaved: signalDecision.estimatedSavings,
|
|
214
|
-
activePlaces: signalDecision.placeHint.placeType ? [signalDecision.placeHint.placeType] : [],
|
|
215
|
-
graphEntities: signalDecision.graphHint.entityTerms,
|
|
216
|
-
placeRouted: Boolean(signalDecision.placeHint.placeType),
|
|
217
|
-
graphEnriched: signalDecision.graphHint.shouldEnrich,
|
|
218
|
-
},
|
|
219
|
-
});
|
|
220
|
-
if (signalDecision.classification === 'discard') {
|
|
221
|
-
return { captured: false, reason: signalDecision.reasons.join(', ') };
|
|
222
|
-
}
|
|
223
|
-
if (signalDecision.classification === 'session-only') {
|
|
224
|
-
return { captured: false, reason: 'Stored in session working set only' };
|
|
225
|
-
}
|
|
226
|
-
try {
|
|
227
|
-
const memory = await rememberMemory({
|
|
228
|
-
content: `[${category}] ${distilledContent || content}`,
|
|
229
|
-
project: projectPath,
|
|
230
|
-
type: category === 'modification' ? 'decision' : category === 'planning' ? 'context' : 'observation',
|
|
231
|
-
source: 'auto-capture',
|
|
232
|
-
metadata: {
|
|
233
|
-
signal: {
|
|
234
|
-
classification: signalDecision.classification,
|
|
235
|
-
reasons: signalDecision.reasons,
|
|
236
|
-
nuanceSuppressed: signalDecision.classification === 'durable-raw+distilled',
|
|
237
|
-
wakeUpPriority: signalDecision.wakeUpPriority,
|
|
238
|
-
},
|
|
239
|
-
placeHint: signalDecision.placeHint,
|
|
240
|
-
graphHint: signalDecision.graphHint,
|
|
241
|
-
target,
|
|
242
|
-
toolName,
|
|
243
|
-
},
|
|
244
|
-
});
|
|
245
|
-
logger.info(`[Hooks] Captured ${toolName} → ${memory.id} (session: ${currentSessionId})`);
|
|
246
|
-
let placeAssignment;
|
|
247
|
-
try {
|
|
248
|
-
const project = await getProjectByPath(projectPath);
|
|
249
|
-
if (project) {
|
|
250
|
-
await initializeDefaultPlaces(project.id);
|
|
251
|
-
placeAssignment = await autoAssignMemory({
|
|
252
|
-
memoryId: memory.id,
|
|
253
|
-
projectId: project.id,
|
|
254
|
-
toolName,
|
|
255
|
-
content: memory.content,
|
|
256
|
-
tags,
|
|
257
|
-
memoryType: memory.type,
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
catch (placeError) {
|
|
262
|
-
logger.warn(`[Hooks] Place assignment failed: ${placeError}`);
|
|
263
|
-
}
|
|
264
|
-
let graphStatus = {
|
|
265
|
-
enriched: false,
|
|
266
|
-
entitiesCreated: 0,
|
|
267
|
-
relationsCreated: 0,
|
|
268
|
-
source: 'none',
|
|
269
|
-
entityTerms: signalDecision.graphHint.entityTerms,
|
|
270
|
-
};
|
|
271
|
-
if (signalDecision.graphHint.shouldEnrich) {
|
|
272
|
-
try {
|
|
273
|
-
const graphResult = await addMemoryToGraph(memory.id, { preferLLM: true });
|
|
274
|
-
graphStatus = {
|
|
275
|
-
enriched: graphResult.entitiesCreated > 0 || graphResult.relationsCreated > 0,
|
|
276
|
-
entitiesCreated: graphResult.entitiesCreated,
|
|
277
|
-
relationsCreated: graphResult.relationsCreated,
|
|
278
|
-
source: graphResult.source,
|
|
279
|
-
entityTerms: signalDecision.graphHint.entityTerms,
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
catch (graphError) {
|
|
283
|
-
logger.warn(`[Hooks] Graph enrichment failed: ${graphError}`);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
let rawFallbackSnapshotId;
|
|
287
|
-
if (signalDecision.classification === 'durable-raw+distilled') {
|
|
288
|
-
rawFallbackSnapshotId = await attachRawFallbackSnapshot(memory.id, signalDecision.content, signalDecision.reasons);
|
|
289
|
-
}
|
|
290
|
-
await attachInspectionMetadata(memory.id, {
|
|
291
|
-
classification: signalDecision.classification,
|
|
292
|
-
reasons: signalDecision.reasons,
|
|
293
|
-
rawFallbackSnapshotId,
|
|
294
|
-
nuanceSuppressed: signalDecision.classification === 'durable-raw+distilled',
|
|
295
|
-
placeId: placeAssignment?.placeId,
|
|
296
|
-
placeType: placeAssignment?.placeType,
|
|
297
|
-
graph: graphStatus,
|
|
298
|
-
});
|
|
299
|
-
try {
|
|
300
|
-
const project = await getProjectByPath(projectPath);
|
|
301
|
-
if (project) {
|
|
302
|
-
const beliefs = extractBeliefsFromMemory({
|
|
303
|
-
memoryId: memory.id,
|
|
304
|
-
content: memory.content,
|
|
305
|
-
type: memory.type,
|
|
306
|
-
metadata: memory.metadata ?? null,
|
|
307
|
-
});
|
|
308
|
-
if (beliefs.length > 0) {
|
|
309
|
-
const storedBeliefs = await upsertBeliefsForMemory({
|
|
310
|
-
projectId: project.id,
|
|
311
|
-
memoryId: memory.id,
|
|
312
|
-
beliefs,
|
|
313
|
-
});
|
|
314
|
-
await attachBeliefInspectionMetadata(memory.id, storedBeliefs);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
catch (beliefError) {
|
|
319
|
-
logger.warn(`[Hooks] Belief extraction failed: ${beliefError}`);
|
|
320
|
-
}
|
|
321
|
-
return {
|
|
322
|
-
captured: true,
|
|
323
|
-
memoryId: memory.id,
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
catch (error) {
|
|
327
|
-
logger.error(`[Hooks] Failed to capture:`, error);
|
|
328
|
-
return { captured: false, reason: 'Failed to create learning' };
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
async function attachRawFallbackSnapshot(memoryId, rawContent, reasons) {
|
|
332
|
-
const { db, schema } = await getDbClient();
|
|
333
|
-
const snapshotId = randomUUID();
|
|
334
|
-
await db.insert(schema.memorySnapshots).values({
|
|
335
|
-
id: snapshotId,
|
|
336
|
-
memoryId,
|
|
337
|
-
snapshotType: 'periodic',
|
|
338
|
-
content: rawContent,
|
|
339
|
-
metadata: serializeMetadata({
|
|
340
|
-
role: 'raw-fallback',
|
|
341
|
-
reasons,
|
|
342
|
-
createdBy: 'signal-engine',
|
|
343
|
-
}),
|
|
344
|
-
createdAt: new Date(),
|
|
345
|
-
});
|
|
346
|
-
return snapshotId;
|
|
347
|
-
}
|
|
348
|
-
async function attachInspectionMetadata(memoryId, signal) {
|
|
349
|
-
const { db, schema } = await getDbClient();
|
|
350
|
-
const rows = await db.select().from(schema.memories).where(eq(schema.memories.id, memoryId)).limit(1);
|
|
351
|
-
const row = rows[0];
|
|
352
|
-
if (!row)
|
|
353
|
-
return;
|
|
354
|
-
const details = deserializeMetadata(row.metadata ?? null) ?? {};
|
|
355
|
-
const next = {
|
|
356
|
-
...details,
|
|
357
|
-
signal,
|
|
358
|
-
classification: signal.classification,
|
|
359
|
-
reasons: signal.reasons,
|
|
360
|
-
rawFallbackSnapshotId: signal.rawFallbackSnapshotId,
|
|
361
|
-
nuanceSuppressed: signal.nuanceSuppressed,
|
|
362
|
-
placeId: signal.placeId,
|
|
363
|
-
placeType: signal.placeType,
|
|
364
|
-
graph: signal.graph,
|
|
365
|
-
graphStatus: signal.graph
|
|
366
|
-
? `${signal.graph.enriched ? 'enriched' : 'skipped'} (${signal.graph.entitiesCreated} entities, ${signal.graph.relationsCreated} relations)`
|
|
367
|
-
: 'none',
|
|
368
|
-
};
|
|
369
|
-
await db.update(schema.memories)
|
|
370
|
-
.set({ metadata: serializeMetadata(next), updatedAt: new Date() })
|
|
371
|
-
.where(eq(schema.memories.id, memoryId));
|
|
372
|
-
}
|
|
373
|
-
async function attachBeliefInspectionMetadata(memoryId, beliefs) {
|
|
374
|
-
const { db, schema } = await getDbClient();
|
|
375
|
-
const rows = await db.select().from(schema.memories).where(eq(schema.memories.id, memoryId)).limit(1);
|
|
376
|
-
const row = rows[0];
|
|
377
|
-
if (!row)
|
|
378
|
-
return;
|
|
379
|
-
const details = deserializeMetadata(row.metadata ?? null) ?? {};
|
|
380
|
-
const next = {
|
|
381
|
-
...details,
|
|
382
|
-
beliefs: beliefs.map((belief) => ({
|
|
383
|
-
id: belief.id,
|
|
384
|
-
type: belief.type,
|
|
385
|
-
statement: belief.statement,
|
|
386
|
-
status: belief.status,
|
|
387
|
-
confidence: belief.confidence,
|
|
388
|
-
sourceMemoryIds: belief.sourceMemoryIds,
|
|
389
|
-
reason: belief.reason,
|
|
390
|
-
})),
|
|
391
|
-
};
|
|
392
|
-
await db.update(schema.memories)
|
|
393
|
-
.set({ metadata: serializeMetadata(next), updatedAt: new Date() })
|
|
394
|
-
.where(eq(schema.memories.id, memoryId));
|
|
395
|
-
}
|
|
396
|
-
function extractActiveFiles(toolName, toolInput) {
|
|
397
|
-
const path = String(toolInput.filePath || toolInput.path || '');
|
|
398
|
-
if (['Write', 'Edit', 'MultiEdit'].includes(toolName) && path) {
|
|
399
|
-
return [path];
|
|
400
|
-
}
|
|
401
|
-
return [];
|
|
402
|
-
}
|
|
403
|
-
function inferOutcome(signalDecision, toolResult) {
|
|
404
|
-
const content = typeof toolResult === 'string' ? toolResult.toLowerCase() : String(toolResult ?? '').toLowerCase();
|
|
405
|
-
if (signalDecision.classification === 'discard')
|
|
406
|
-
return 'suppressed';
|
|
407
|
-
if (/\bfail|error|exception|traceback\b/.test(content))
|
|
408
|
-
return 'failure';
|
|
409
|
-
if (/\bpass|success|completed\b/.test(content))
|
|
410
|
-
return 'success';
|
|
411
|
-
return undefined;
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Session end hook - save snapshot and sync to persistent hot cache
|
|
415
|
-
*/
|
|
416
|
-
export async function handleSessionEnd(params) {
|
|
417
|
-
const { projectPath, agentType, workInProgress } = params;
|
|
418
|
-
// Ensure project exists
|
|
419
|
-
await ensureProject(projectPath);
|
|
420
|
-
logger.info(`[Hooks] Session end (agent: ${agentType}, session: ${currentSessionId})`);
|
|
421
|
-
// Save session snapshot as a learning
|
|
422
|
-
if (workInProgress) {
|
|
423
|
-
const snapshot = await createLearning({
|
|
424
|
-
type: 'insight',
|
|
425
|
-
content: `[SESSION SNAPSHOT] ${workInProgress}`,
|
|
426
|
-
action: 'session-end',
|
|
427
|
-
project: projectPath,
|
|
428
|
-
autoLink: false,
|
|
429
|
-
});
|
|
430
|
-
logger.info(`[Hooks] Saved session snapshot: ${snapshot.id}`);
|
|
431
|
-
// NEW: Also save to persistent hot cache (survives restart)
|
|
432
|
-
try {
|
|
433
|
-
const workingSet = await compactSessionWorkingSet(projectPath);
|
|
434
|
-
await addSessionContextToHotCache({
|
|
435
|
-
activeFiles: workingSet?.activeFiles || [],
|
|
436
|
-
commands: workingSet?.recentCommands?.slice(-3).map(c => c.command) || [],
|
|
437
|
-
failures: workingSet?.recentFailures?.slice(-2) || [],
|
|
438
|
-
decisions: [], // Could extract from recent signals
|
|
439
|
-
hypotheses: workingSet?.currentHypotheses?.slice(-2) || [],
|
|
440
|
-
}, projectPath);
|
|
441
|
-
logger.info('[Hooks] Saved session context to hot cache');
|
|
442
|
-
}
|
|
443
|
-
catch (error) {
|
|
444
|
-
logger.warn('[Hooks] Failed to save hot cache', error);
|
|
445
|
-
}
|
|
446
|
-
currentSessionId = null; // Clear session
|
|
447
|
-
return {
|
|
448
|
-
snapshotId: snapshot.id,
|
|
449
|
-
memoriesSaved: 1,
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
currentSessionId = null;
|
|
453
|
-
return {
|
|
454
|
-
memoriesSaved: 0,
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* Pre-compact hook - save state for recovery
|
|
459
|
-
*/
|
|
460
|
-
export async function handlePreCompact(params) {
|
|
461
|
-
const { projectPath, agentType } = params;
|
|
462
|
-
// Ensure project exists
|
|
463
|
-
await ensureProject(projectPath);
|
|
464
|
-
logger.info(`[Hooks] Pre-compact (agent: ${agentType})`);
|
|
465
|
-
// Get recent work for recovery
|
|
466
|
-
const recent = await getRecent(projectPath, 3);
|
|
467
|
-
// Save state
|
|
468
|
-
const state = await createLearning({
|
|
469
|
-
type: 'insight',
|
|
470
|
-
content: `[PRE-COMPACT] State saved for recovery. Recent: ${recent.map(r => r.content?.substring(0, 50)).join(' | ')}`,
|
|
471
|
-
action: 'pre-compact',
|
|
472
|
-
project: projectPath,
|
|
473
|
-
autoLink: false,
|
|
474
|
-
});
|
|
475
|
-
return {
|
|
476
|
-
stateSaved: true,
|
|
477
|
-
stateId: state.id,
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* Extract target from tool input
|
|
482
|
-
*/
|
|
483
|
-
function extractTarget(toolName, toolInput) {
|
|
484
|
-
switch (toolName) {
|
|
485
|
-
case 'Write':
|
|
486
|
-
case 'Edit':
|
|
487
|
-
return String(toolInput.filePath || toolInput.path || 'unknown');
|
|
488
|
-
case 'Bash':
|
|
489
|
-
return String(toolInput.command || toolInput.cmd || 'unknown');
|
|
490
|
-
case 'Task':
|
|
491
|
-
return String(toolInput.description || toolInput.name || 'unknown');
|
|
492
|
-
default:
|
|
493
|
-
return 'unknown';
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* Extract content summary from tool result
|
|
498
|
-
*/
|
|
499
|
-
function extractContent(toolName, toolInput, toolResult) {
|
|
500
|
-
switch (toolName) {
|
|
501
|
-
case 'Write':
|
|
502
|
-
return `Wrote: ${toolInput.filePath || toolInput.path}`;
|
|
503
|
-
case 'Edit':
|
|
504
|
-
return `Edited: ${toolInput.filePath || toolInput.path}`;
|
|
505
|
-
case 'Bash':
|
|
506
|
-
const cmd = String(toolInput.command || toolInput.cmd || '');
|
|
507
|
-
if (cmd.includes('commit'))
|
|
508
|
-
return `Git commit executed`;
|
|
509
|
-
if (cmd.includes('test'))
|
|
510
|
-
return `Tests run`;
|
|
511
|
-
return `Command: ${cmd.substring(0, 50)}`;
|
|
512
|
-
case 'Task':
|
|
513
|
-
return `Task: ${toolInput.description || toolInput.name || 'unknown'}`;
|
|
514
|
-
default:
|
|
515
|
-
return `Used: ${toolName}`;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
// Re-export for convenience
|
|
519
|
-
export { shouldCaptureTool, categorizeTool } from './capture-filter.js';
|
|
520
|
-
export { inferTags } from './auto-tagger.js';
|
|
521
|
-
//# sourceMappingURL=agent-hooks.js.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-Tagger - Infer tags from context
|
|
3
|
-
*
|
|
4
|
-
* Analyzes tool input/output to automatically infer relevant tags.
|
|
5
|
-
* Uses pattern matching to classify actions.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Infer tags based on tool, input, and content
|
|
9
|
-
*/
|
|
10
|
-
export declare function inferTags(toolName: string, toolInput: Record<string, unknown>, content: string): string[];
|
|
11
|
-
/**
|
|
12
|
-
* Extract tags from commit message
|
|
13
|
-
*/
|
|
14
|
-
export declare function extractCommitTags(commitMessage: string): string[];
|
|
15
|
-
/**
|
|
16
|
-
* Extract tags from file path
|
|
17
|
-
*/
|
|
18
|
-
export declare function extractFileTags(filePath: string): string[];
|
|
19
|
-
//# sourceMappingURL=auto-tagger.d.ts.map
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-Tagger - Infer tags from context
|
|
3
|
-
*
|
|
4
|
-
* Analyzes tool input/output to automatically infer relevant tags.
|
|
5
|
-
* Uses pattern matching to classify actions.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Infer tags based on tool, input, and content
|
|
9
|
-
*/
|
|
10
|
-
export function inferTags(toolName, toolInput, content) {
|
|
11
|
-
const tags = ['hook', 'autocapture']; // Always add these
|
|
12
|
-
const tool = toolName.toLowerCase();
|
|
13
|
-
const inputStr = JSON.stringify(toolInput).toLowerCase();
|
|
14
|
-
const contentLower = content.toLowerCase();
|
|
15
|
-
// File type tags
|
|
16
|
-
if (tool === 'write' || tool === 'edit') {
|
|
17
|
-
const filePath = String(toolInput.filePath || toolInput.path || '');
|
|
18
|
-
if (filePath.endsWith('.ts') || filePath.endsWith('.tsx')) {
|
|
19
|
-
tags.push('typescript');
|
|
20
|
-
}
|
|
21
|
-
else if (filePath.endsWith('.js') || filePath.endsWith('.jsx')) {
|
|
22
|
-
tags.push('javascript');
|
|
23
|
-
}
|
|
24
|
-
else if (filePath.endsWith('.json')) {
|
|
25
|
-
tags.push('config');
|
|
26
|
-
}
|
|
27
|
-
else if (filePath.endsWith('.md')) {
|
|
28
|
-
tags.push('documentation');
|
|
29
|
-
}
|
|
30
|
-
else if (filePath.endsWith('.test.ts') || filePath.endsWith('.spec.ts')) {
|
|
31
|
-
tags.push('test');
|
|
32
|
-
}
|
|
33
|
-
// Feature/fix detection
|
|
34
|
-
if (contentLower.includes('fix') || contentLower.includes('bug')) {
|
|
35
|
-
tags.push('bugfix');
|
|
36
|
-
}
|
|
37
|
-
else if (contentLower.includes('refactor')) {
|
|
38
|
-
tags.push('refactor');
|
|
39
|
-
}
|
|
40
|
-
else if (contentLower.includes('feature') || contentLower.includes('add')) {
|
|
41
|
-
tags.push('feature');
|
|
42
|
-
}
|
|
43
|
-
else if (contentLower.includes('test')) {
|
|
44
|
-
tags.push('testing');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
// Bash command tags
|
|
48
|
-
if (tool === 'bash') {
|
|
49
|
-
const cmd = String(toolInput.command || toolInput.cmd || '');
|
|
50
|
-
if (cmd.includes('git commit')) {
|
|
51
|
-
tags.push('commit', 'version-control');
|
|
52
|
-
}
|
|
53
|
-
else if (cmd.includes('test') || cmd.includes('jest') || cmd.includes('vitest')) {
|
|
54
|
-
tags.push('testing', 'test');
|
|
55
|
-
}
|
|
56
|
-
else if (cmd.includes('build') || cmd.includes('compile')) {
|
|
57
|
-
tags.push('build');
|
|
58
|
-
}
|
|
59
|
-
else if (cmd.includes('install')) {
|
|
60
|
-
tags.push('dependencies');
|
|
61
|
-
}
|
|
62
|
-
else if (cmd.includes('lint') || cmd.includes('format')) {
|
|
63
|
-
tags.push('linting');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// Task tags
|
|
67
|
-
if (tool === 'task' || tool === 'todowrite') {
|
|
68
|
-
tags.push('task', 'planning');
|
|
69
|
-
if (contentLower.includes('fix') || contentLower.includes('bug')) {
|
|
70
|
-
tags.push('bugfix');
|
|
71
|
-
}
|
|
72
|
-
else if (contentLower.includes('feature')) {
|
|
73
|
-
tags.push('feature');
|
|
74
|
-
}
|
|
75
|
-
else if (contentLower.includes('refactor')) {
|
|
76
|
-
tags.push('refactor');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// Deduplicate
|
|
80
|
-
return [...new Set(tags)];
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Extract tags from commit message
|
|
84
|
-
*/
|
|
85
|
-
export function extractCommitTags(commitMessage) {
|
|
86
|
-
const tags = ['commit'];
|
|
87
|
-
const msg = commitMessage.toLowerCase();
|
|
88
|
-
// Conventional commits
|
|
89
|
-
if (msg.startsWith('feat:') || msg.includes('feature')) {
|
|
90
|
-
tags.push('feature', 'conventional-commit');
|
|
91
|
-
}
|
|
92
|
-
else if (msg.startsWith('fix:') || msg.includes('bugfix')) {
|
|
93
|
-
tags.push('bugfix', 'conventional-commit');
|
|
94
|
-
}
|
|
95
|
-
else if (msg.startsWith('refactor:')) {
|
|
96
|
-
tags.push('refactor', 'conventional-commit');
|
|
97
|
-
}
|
|
98
|
-
else if (msg.startsWith('docs:')) {
|
|
99
|
-
tags.push('documentation', 'conventional-commit');
|
|
100
|
-
}
|
|
101
|
-
else if (msg.startsWith('test:')) {
|
|
102
|
-
tags.push('testing', 'conventional-commit');
|
|
103
|
-
}
|
|
104
|
-
else if (msg.startsWith('chore:')) {
|
|
105
|
-
tags.push('chore', 'conventional-commit');
|
|
106
|
-
}
|
|
107
|
-
return tags;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Extract tags from file path
|
|
111
|
-
*/
|
|
112
|
-
export function extractFileTags(filePath) {
|
|
113
|
-
const tags = [];
|
|
114
|
-
const path = filePath.toLowerCase();
|
|
115
|
-
// By extension
|
|
116
|
-
if (path.endsWith('.ts') || path.endsWith('.tsx')) {
|
|
117
|
-
tags.push('typescript');
|
|
118
|
-
}
|
|
119
|
-
else if (path.endsWith('.js') || path.endsWith('.jsx')) {
|
|
120
|
-
tags.push('javascript');
|
|
121
|
-
}
|
|
122
|
-
else if (path.endsWith('.py')) {
|
|
123
|
-
tags.push('python');
|
|
124
|
-
}
|
|
125
|
-
else if (path.endsWith('.go')) {
|
|
126
|
-
tags.push('golang');
|
|
127
|
-
}
|
|
128
|
-
else if (path.endsWith('.rs')) {
|
|
129
|
-
tags.push('rust');
|
|
130
|
-
}
|
|
131
|
-
else if (path.endsWith('.java')) {
|
|
132
|
-
tags.push('java');
|
|
133
|
-
}
|
|
134
|
-
else if (path.endsWith('.json')) {
|
|
135
|
-
tags.push('config');
|
|
136
|
-
}
|
|
137
|
-
else if (path.endsWith('.md')) {
|
|
138
|
-
tags.push('documentation');
|
|
139
|
-
}
|
|
140
|
-
// By directory pattern
|
|
141
|
-
if (path.includes('/test') || path.includes('/tests') || path.includes('__tests__')) {
|
|
142
|
-
tags.push('test');
|
|
143
|
-
}
|
|
144
|
-
else if (path.includes('/src/')) {
|
|
145
|
-
tags.push('source');
|
|
146
|
-
}
|
|
147
|
-
else if (path.includes('/lib/') || path.includes('/utils/')) {
|
|
148
|
-
tags.push('library');
|
|
149
|
-
}
|
|
150
|
-
else if (path.includes('/config/') || path.includes('/scripts/')) {
|
|
151
|
-
tags.push('config');
|
|
152
|
-
}
|
|
153
|
-
return tags;
|
|
154
|
-
}
|
|
155
|
-
//# sourceMappingURL=auto-tagger.js.map
|