sensorium-mcp 3.0.103 → 3.1.0-board.0
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/Install-Sensorium.ps1 +113 -20
- package/README.md +25 -0
- package/dist/config/agent-settings.d.ts +82 -0
- package/dist/config/agent-settings.d.ts.map +1 -0
- package/dist/config/agent-settings.js +261 -0
- package/dist/config/agent-settings.js.map +1 -0
- package/dist/config/agent-templates.d.ts +39 -0
- package/dist/config/agent-templates.d.ts.map +1 -0
- package/dist/config/agent-templates.js +105 -0
- package/dist/config/agent-templates.js.map +1 -0
- package/dist/config/detail-grant.d.ts +39 -0
- package/dist/config/detail-grant.d.ts.map +1 -0
- package/dist/config/detail-grant.js +61 -0
- package/dist/config/detail-grant.js.map +1 -0
- package/dist/config/index.d.ts +17 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +59 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/keep-alive-settings.d.ts +29 -0
- package/dist/config/keep-alive-settings.d.ts.map +1 -0
- package/dist/config/keep-alive-settings.js +100 -0
- package/dist/config/keep-alive-settings.js.map +1 -0
- package/dist/config/mcp-settings.d.ts +59 -0
- package/dist/config/mcp-settings.d.ts.map +1 -0
- package/dist/config/mcp-settings.js +196 -0
- package/dist/config/mcp-settings.js.map +1 -0
- package/dist/config/misc-settings.d.ts +48 -0
- package/dist/config/misc-settings.d.ts.map +1 -0
- package/dist/config/misc-settings.js +168 -0
- package/dist/config/misc-settings.js.map +1 -0
- package/dist/config/settings-store.d.ts +49 -0
- package/dist/config/settings-store.d.ts.map +1 -0
- package/dist/config/settings-store.js +203 -0
- package/dist/config/settings-store.js.map +1 -0
- package/dist/dashboard/log-parser.d.ts +3 -0
- package/dist/dashboard/log-parser.d.ts.map +1 -1
- package/dist/dashboard/log-parser.js +49 -5
- package/dist/dashboard/log-parser.js.map +1 -1
- package/dist/dashboard/presets.d.ts +1 -1
- package/dist/dashboard/presets.d.ts.map +1 -1
- package/dist/dashboard/presets.js +1 -1
- package/dist/dashboard/presets.js.map +1 -1
- package/dist/dashboard/routes/agent-templates.d.ts.map +1 -1
- package/dist/dashboard/routes/agent-templates.js +13 -8
- package/dist/dashboard/routes/agent-templates.js.map +1 -1
- package/dist/dashboard/routes/board.d.ts +67 -0
- package/dist/dashboard/routes/board.d.ts.map +1 -0
- package/dist/dashboard/routes/board.js +612 -0
- package/dist/dashboard/routes/board.js.map +1 -0
- package/dist/dashboard/routes/claude.d.ts.map +1 -1
- package/dist/dashboard/routes/claude.js +14 -3
- package/dist/dashboard/routes/claude.js.map +1 -1
- package/dist/dashboard/routes/copilot.d.ts.map +1 -1
- package/dist/dashboard/routes/copilot.js +32 -7
- package/dist/dashboard/routes/copilot.js.map +1 -1
- package/dist/dashboard/routes/data.d.ts.map +1 -1
- package/dist/dashboard/routes/data.js +43 -15
- package/dist/dashboard/routes/data.js.map +1 -1
- package/dist/dashboard/routes/env-vars.d.ts.map +1 -1
- package/dist/dashboard/routes/env-vars.js.map +1 -1
- package/dist/dashboard/routes/mcp-servers.d.ts.map +1 -1
- package/dist/dashboard/routes/mcp-servers.js +11 -5
- package/dist/dashboard/routes/mcp-servers.js.map +1 -1
- package/dist/dashboard/routes/prompts.d.ts.map +1 -1
- package/dist/dashboard/routes/prompts.js +2 -2
- package/dist/dashboard/routes/prompts.js.map +1 -1
- package/dist/dashboard/routes/settings.d.ts +2 -0
- package/dist/dashboard/routes/settings.d.ts.map +1 -1
- package/dist/dashboard/routes/settings.js +29 -3
- package/dist/dashboard/routes/settings.js.map +1 -1
- package/dist/dashboard/routes/skills.d.ts.map +1 -1
- package/dist/dashboard/routes/skills.js +4 -4
- package/dist/dashboard/routes/skills.js.map +1 -1
- package/dist/dashboard/routes/snapshots.d.ts.map +1 -1
- package/dist/dashboard/routes/snapshots.js +18 -11
- package/dist/dashboard/routes/snapshots.js.map +1 -1
- package/dist/dashboard/routes/templates.d.ts.map +1 -1
- package/dist/dashboard/routes/templates.js +6 -3
- package/dist/dashboard/routes/templates.js.map +1 -1
- package/dist/dashboard/routes/threads-create.d.ts +22 -0
- package/dist/dashboard/routes/threads-create.d.ts.map +1 -0
- package/dist/dashboard/routes/threads-create.js +225 -0
- package/dist/dashboard/routes/threads-create.js.map +1 -0
- package/dist/dashboard/routes/threads-helpers.d.ts +28 -0
- package/dist/dashboard/routes/threads-helpers.d.ts.map +1 -0
- package/dist/dashboard/routes/threads-helpers.js +138 -0
- package/dist/dashboard/routes/threads-helpers.js.map +1 -0
- package/dist/dashboard/routes/threads-read.d.ts +26 -0
- package/dist/dashboard/routes/threads-read.d.ts.map +1 -0
- package/dist/dashboard/routes/threads-read.js +125 -0
- package/dist/dashboard/routes/threads-read.js.map +1 -0
- package/dist/dashboard/routes/threads.d.ts +5 -44
- package/dist/dashboard/routes/threads.d.ts.map +1 -1
- package/dist/dashboard/routes/threads.js +44 -500
- package/dist/dashboard/routes/threads.js.map +1 -1
- package/dist/dashboard/routes/types.d.ts +6 -0
- package/dist/dashboard/routes/types.d.ts.map +1 -1
- package/dist/dashboard/routes/types.js.map +1 -1
- package/dist/dashboard/routes.d.ts.map +1 -1
- package/dist/dashboard/routes.js +55 -10
- package/dist/dashboard/routes.js.map +1 -1
- package/dist/dashboard/spa.html +12 -12
- package/dist/data/board/board-schema.d.ts +22 -0
- package/dist/data/board/board-schema.d.ts.map +1 -0
- package/dist/data/board/board-schema.js +103 -0
- package/dist/data/board/board-schema.js.map +1 -0
- package/dist/data/board/board-types.d.ts +117 -0
- package/dist/data/board/board-types.d.ts.map +1 -0
- package/dist/data/board/board-types.js +9 -0
- package/dist/data/board/board-types.js.map +1 -0
- package/dist/data/board/card.repository.d.ts +64 -0
- package/dist/data/board/card.repository.d.ts.map +1 -0
- package/dist/data/board/card.repository.js +272 -0
- package/dist/data/board/card.repository.js.map +1 -0
- package/dist/data/board/comment.repository.d.ts +12 -0
- package/dist/data/board/comment.repository.d.ts.map +1 -0
- package/dist/data/board/comment.repository.js +31 -0
- package/dist/data/board/comment.repository.js.map +1 -0
- package/dist/data/board/lane.repository.d.ts +18 -0
- package/dist/data/board/lane.repository.d.ts.map +1 -0
- package/dist/data/board/lane.repository.js +44 -0
- package/dist/data/board/lane.repository.js.map +1 -0
- package/dist/data/board/profile-defaults.d.ts +19 -0
- package/dist/data/board/profile-defaults.d.ts.map +1 -0
- package/dist/data/board/profile-defaults.js +118 -0
- package/dist/data/board/profile-defaults.js.map +1 -0
- package/dist/data/daily-marker.d.ts.map +1 -1
- package/dist/data/daily-marker.js +1 -1
- package/dist/data/daily-marker.js.map +1 -1
- package/dist/data/file-storage.d.ts.map +1 -1
- package/dist/data/file-storage.js +40 -16
- package/dist/data/file-storage.js.map +1 -1
- package/dist/data/interfaces.d.ts +23 -2
- package/dist/data/interfaces.d.ts.map +1 -1
- package/dist/data/memory/bootstrap.d.ts +8 -1
- package/dist/data/memory/bootstrap.d.ts.map +1 -1
- package/dist/data/memory/bootstrap.js +76 -28
- package/dist/data/memory/bootstrap.js.map +1 -1
- package/dist/data/memory/consolidation.d.ts +9 -4
- package/dist/data/memory/consolidation.d.ts.map +1 -1
- package/dist/data/memory/consolidation.js +38 -17
- package/dist/data/memory/consolidation.js.map +1 -1
- package/dist/data/memory/db-types.d.ts +4 -0
- package/dist/data/memory/db-types.d.ts.map +1 -0
- package/dist/data/memory/db-types.js +2 -0
- package/dist/data/memory/db-types.js.map +1 -0
- package/dist/data/memory/episodes.d.ts.map +1 -1
- package/dist/data/memory/episodes.js +3 -5
- package/dist/data/memory/episodes.js.map +1 -1
- package/dist/data/memory/index.d.ts +27 -14
- package/dist/data/memory/index.d.ts.map +1 -1
- package/dist/data/memory/index.js +27 -14
- package/dist/data/memory/index.js.map +1 -1
- package/dist/data/memory/migration-runner.d.ts +25 -2
- package/dist/data/memory/migration-runner.d.ts.map +1 -1
- package/dist/data/memory/migration-runner.js +110 -16
- package/dist/data/memory/migration-runner.js.map +1 -1
- package/dist/data/memory/narrative-lint.d.ts +12 -0
- package/dist/data/memory/narrative-lint.d.ts.map +1 -0
- package/dist/data/memory/narrative-lint.js +117 -0
- package/dist/data/memory/narrative-lint.js.map +1 -0
- package/dist/data/memory/narrative-resolutions.d.ts +26 -0
- package/dist/data/memory/narrative-resolutions.d.ts.map +1 -0
- package/dist/data/memory/narrative-resolutions.js +81 -0
- package/dist/data/memory/narrative-resolutions.js.map +1 -0
- package/dist/data/memory/narrative-sources.d.ts +19 -0
- package/dist/data/memory/narrative-sources.d.ts.map +1 -0
- package/dist/data/memory/narrative-sources.js +150 -0
- package/dist/data/memory/narrative-sources.js.map +1 -0
- package/dist/data/memory/narrative-store.d.ts +11 -0
- package/dist/data/memory/narrative-store.d.ts.map +1 -0
- package/dist/data/memory/narrative-store.js +80 -0
- package/dist/data/memory/narrative-store.js.map +1 -0
- package/dist/data/memory/narrative-types.d.ts +15 -0
- package/dist/data/memory/narrative-types.d.ts.map +1 -0
- package/dist/data/memory/narrative-types.js +3 -0
- package/dist/data/memory/narrative-types.js.map +1 -0
- package/dist/data/memory/narrative.d.ts +5 -2
- package/dist/data/memory/narrative.d.ts.map +1 -1
- package/dist/data/memory/narrative.js +35 -521
- package/dist/data/memory/narrative.js.map +1 -1
- package/dist/data/memory/note-archival.d.ts +42 -0
- package/dist/data/memory/note-archival.d.ts.map +1 -0
- package/dist/data/memory/note-archival.js +77 -0
- package/dist/data/memory/note-archival.js.map +1 -0
- package/dist/data/memory/note-embeddings.d.ts +27 -0
- package/dist/data/memory/note-embeddings.d.ts.map +1 -0
- package/dist/data/memory/note-embeddings.js +98 -0
- package/dist/data/memory/note-embeddings.js.map +1 -0
- package/dist/data/memory/reflection-dedup.d.ts +17 -0
- package/dist/data/memory/reflection-dedup.d.ts.map +1 -0
- package/dist/data/memory/reflection-dedup.js +55 -0
- package/dist/data/memory/reflection-dedup.js.map +1 -0
- package/dist/data/memory/reflection-gates.d.ts +40 -0
- package/dist/data/memory/reflection-gates.d.ts.map +1 -0
- package/dist/data/memory/reflection-gates.js +220 -0
- package/dist/data/memory/reflection-gates.js.map +1 -0
- package/dist/data/memory/reflection-sources.d.ts +13 -0
- package/dist/data/memory/reflection-sources.d.ts.map +1 -0
- package/dist/data/memory/reflection-sources.js +115 -0
- package/dist/data/memory/reflection-sources.js.map +1 -0
- package/dist/data/memory/reflection.d.ts +5 -35
- package/dist/data/memory/reflection.d.ts.map +1 -1
- package/dist/data/memory/reflection.js +32 -332
- package/dist/data/memory/reflection.js.map +1 -1
- package/dist/data/memory/schema-ddl.d.ts +2 -2
- package/dist/data/memory/schema-ddl.d.ts.map +1 -1
- package/dist/data/memory/schema-ddl.js +13 -11
- package/dist/data/memory/schema-ddl.js.map +1 -1
- package/dist/data/memory/schema-guard.d.ts +1 -1
- package/dist/data/memory/schema-guard.d.ts.map +1 -1
- package/dist/data/memory/schema-guard.js +5 -4
- package/dist/data/memory/schema-guard.js.map +1 -1
- package/dist/data/memory/schema.d.ts +2 -2
- package/dist/data/memory/schema.d.ts.map +1 -1
- package/dist/data/memory/schema.js +8 -2
- package/dist/data/memory/schema.js.map +1 -1
- package/dist/data/memory/semantic-notes.d.ts +120 -0
- package/dist/data/memory/semantic-notes.d.ts.map +1 -0
- package/dist/data/memory/semantic-notes.js +330 -0
- package/dist/data/memory/semantic-notes.js.map +1 -0
- package/dist/data/memory/semantic-search.d.ts +29 -0
- package/dist/data/memory/semantic-search.d.ts.map +1 -0
- package/dist/data/memory/semantic-search.js +158 -0
- package/dist/data/memory/semantic-search.js.map +1 -0
- package/dist/data/memory/synthesis.d.ts.map +1 -1
- package/dist/data/memory/synthesis.js +15 -7
- package/dist/data/memory/synthesis.js.map +1 -1
- package/dist/data/memory/thread-registry.d.ts +2 -2
- package/dist/data/memory/thread-registry.d.ts.map +1 -1
- package/dist/data/memory/thread-registry.js +91 -37
- package/dist/data/memory/thread-registry.js.map +1 -1
- package/dist/data/memory/topic-shift.js +3 -3
- package/dist/data/memory/topic-shift.js.map +1 -1
- package/dist/data/memory/utils.d.ts +0 -5
- package/dist/data/memory/utils.d.ts.map +1 -1
- package/dist/data/memory/utils.js +0 -94
- package/dist/data/memory/utils.js.map +1 -1
- package/dist/data/sent-message.repository.js +2 -2
- package/dist/data/sent-message.repository.js.map +1 -1
- package/dist/data/templates.js +2 -2
- package/dist/data/templates.js.map +1 -1
- package/dist/index.js +135 -38
- package/dist/index.js.map +1 -1
- package/dist/integrations/openai/chat.d.ts +7 -1
- package/dist/integrations/openai/chat.d.ts.map +1 -1
- package/dist/integrations/openai/chat.js +24 -7
- package/dist/integrations/openai/chat.js.map +1 -1
- package/dist/integrations/openai/speech.d.ts +5 -2
- package/dist/integrations/openai/speech.d.ts.map +1 -1
- package/dist/integrations/openai/speech.js +7 -4
- package/dist/integrations/openai/speech.js.map +1 -1
- package/dist/integrations/openai/video.d.ts.map +1 -1
- package/dist/integrations/openai/video.js +21 -10
- package/dist/integrations/openai/video.js.map +1 -1
- package/dist/integrations/openai/vision.d.ts.map +1 -1
- package/dist/integrations/openai/vision.js.map +1 -1
- package/dist/integrations/openai/voice-emotion.d.ts.map +1 -1
- package/dist/integrations/openai/voice-emotion.js +2 -2
- package/dist/integrations/openai/voice-emotion.js.map +1 -1
- package/dist/integrations/telegram/types.d.ts +9 -0
- package/dist/integrations/telegram/types.d.ts.map +1 -1
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/{logger.js → lib/logger.js} +98 -52
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/markdown.d.ts +13 -0
- package/dist/lib/markdown.d.ts.map +1 -0
- package/dist/{markdown.js → lib/markdown.js} +58 -5
- package/dist/lib/markdown.js.map +1 -0
- package/dist/{types.d.ts → lib/types.d.ts} +0 -1
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/usage-metering/index.d.ts +13 -0
- package/dist/lib/usage-metering/index.d.ts.map +1 -0
- package/dist/lib/usage-metering/index.js +10 -0
- package/dist/lib/usage-metering/index.js.map +1 -0
- package/dist/lib/usage-metering/meter.d.ts +34 -0
- package/dist/lib/usage-metering/meter.d.ts.map +1 -0
- package/dist/lib/usage-metering/meter.js +28 -0
- package/dist/lib/usage-metering/meter.js.map +1 -0
- package/dist/lib/usage-metering/pricing.d.ts +39 -0
- package/dist/lib/usage-metering/pricing.d.ts.map +1 -0
- package/dist/lib/usage-metering/pricing.js +49 -0
- package/dist/lib/usage-metering/pricing.js.map +1 -0
- package/dist/lib/usage-metering/sink.d.ts +24 -0
- package/dist/lib/usage-metering/sink.d.ts.map +1 -0
- package/dist/lib/usage-metering/sink.js +56 -0
- package/dist/lib/usage-metering/sink.js.map +1 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/{utils.js → lib/utils.js} +29 -9
- package/dist/lib/utils.js.map +1 -0
- package/dist/llm/json.d.ts +14 -0
- package/dist/llm/json.d.ts.map +1 -0
- package/dist/llm/json.js +112 -0
- package/dist/llm/json.js.map +1 -0
- package/dist/llm/prompts/narrative.d.ts +7 -0
- package/dist/llm/prompts/narrative.d.ts.map +1 -0
- package/dist/llm/prompts/narrative.js +124 -0
- package/dist/llm/prompts/narrative.js.map +1 -0
- package/dist/llm/prompts/reflection.d.ts +6 -0
- package/dist/llm/prompts/reflection.d.ts.map +1 -0
- package/dist/llm/prompts/reflection.js +77 -0
- package/dist/llm/prompts/reflection.js.map +1 -0
- package/dist/server/factory.d.ts +2 -2
- package/dist/server/factory.d.ts.map +1 -1
- package/dist/server/factory.js +176 -84
- package/dist/server/factory.js.map +1 -1
- package/dist/{http-server.d.ts → server/http-server.d.ts} +6 -3
- package/dist/server/http-server.d.ts.map +1 -0
- package/dist/{http-server.js → server/http-server.js} +92 -24
- package/dist/server/http-server.js.map +1 -0
- package/dist/{stdio-server.d.ts → server/stdio-server.d.ts} +1 -1
- package/dist/server/stdio-server.d.ts.map +1 -0
- package/dist/{stdio-server.js → server/stdio-server.js} +25 -11
- package/dist/server/stdio-server.js.map +1 -0
- package/dist/services/agent-spawn.service.d.ts +4 -4
- package/dist/services/agent-spawn.service.d.ts.map +1 -1
- package/dist/services/agent-spawn.service.js +30 -14
- package/dist/services/agent-spawn.service.js.map +1 -1
- package/dist/services/background-runner.d.ts +2 -2
- package/dist/services/background-runner.d.ts.map +1 -1
- package/dist/services/background-runner.js +13 -4
- package/dist/services/background-runner.js.map +1 -1
- package/dist/services/board/board-signals.d.ts +25 -0
- package/dist/services/board/board-signals.d.ts.map +1 -0
- package/dist/services/board/board-signals.js +83 -0
- package/dist/services/board/board-signals.js.map +1 -0
- package/dist/services/board/card-briefing.d.ts +17 -0
- package/dist/services/board/card-briefing.d.ts.map +1 -0
- package/dist/services/board/card-briefing.js +84 -0
- package/dist/services/board/card-briefing.js.map +1 -0
- package/dist/services/board/orchestrator.service.d.ts +55 -0
- package/dist/services/board/orchestrator.service.d.ts.map +1 -0
- package/dist/services/board/orchestrator.service.js +193 -0
- package/dist/services/board/orchestrator.service.js.map +1 -0
- package/dist/services/board/release-worker.d.ts +32 -0
- package/dist/services/board/release-worker.d.ts.map +1 -0
- package/dist/services/board/release-worker.js +49 -0
- package/dist/services/board/release-worker.js.map +1 -0
- package/dist/services/board/report-capture.d.ts +48 -0
- package/dist/services/board/report-capture.d.ts.map +1 -0
- package/dist/services/board/report-capture.js +172 -0
- package/dist/services/board/report-capture.js.map +1 -0
- package/dist/services/board/worker-spawn.d.ts +30 -0
- package/dist/services/board/worker-spawn.d.ts.map +1 -0
- package/dist/services/board/worker-spawn.js +90 -0
- package/dist/services/board/worker-spawn.js.map +1 -0
- package/dist/services/broker-client.d.ts +181 -0
- package/dist/services/broker-client.d.ts.map +1 -0
- package/dist/services/broker-client.js +323 -0
- package/dist/services/broker-client.js.map +1 -0
- package/dist/services/claude-spawn.service.d.ts +1 -1
- package/dist/services/claude-spawn.service.d.ts.map +1 -1
- package/dist/services/claude-spawn.service.js +138 -55
- package/dist/services/claude-spawn.service.js.map +1 -1
- package/dist/services/codex-spawn.service.d.ts +1 -1
- package/dist/services/codex-spawn.service.d.ts.map +1 -1
- package/dist/services/codex-spawn.service.js +54 -47
- package/dist/services/codex-spawn.service.js.map +1 -1
- package/dist/services/consolidation-prompts.d.ts +26 -0
- package/dist/services/consolidation-prompts.d.ts.map +1 -0
- package/dist/services/consolidation-prompts.js +144 -0
- package/dist/services/consolidation-prompts.js.map +1 -0
- package/dist/services/consolidation.service.d.ts +1 -5
- package/dist/services/consolidation.service.d.ts.map +1 -1
- package/dist/services/consolidation.service.js +99 -352
- package/dist/services/consolidation.service.js.map +1 -1
- package/dist/services/copilot-spawn.service.d.ts +1 -1
- package/dist/services/copilot-spawn.service.d.ts.map +1 -1
- package/dist/services/copilot-spawn.service.js +105 -59
- package/dist/services/copilot-spawn.service.js.map +1 -1
- package/dist/{daily-session.d.ts → services/daily-session.d.ts} +1 -1
- package/dist/services/daily-session.d.ts.map +1 -0
- package/dist/{daily-session.js → services/daily-session.js} +15 -14
- package/dist/services/daily-session.js.map +1 -0
- package/dist/services/dispatcher/broker.d.ts +10 -9
- package/dist/services/dispatcher/broker.d.ts.map +1 -1
- package/dist/services/dispatcher/broker.js +67 -47
- package/dist/services/dispatcher/broker.js.map +1 -1
- package/dist/services/dispatcher/index.d.ts +1 -1
- package/dist/services/dispatcher/index.d.ts.map +1 -1
- package/dist/services/dispatcher/index.js +1 -1
- package/dist/services/dispatcher/index.js.map +1 -1
- package/dist/services/dispatcher/lock.d.ts.map +1 -1
- package/dist/services/dispatcher/lock.js +24 -9
- package/dist/services/dispatcher/lock.js.map +1 -1
- package/dist/services/dispatcher/poller.d.ts +1 -1
- package/dist/services/dispatcher/poller.d.ts.map +1 -1
- package/dist/services/dispatcher/poller.js +112 -53
- package/dist/services/dispatcher/poller.js.map +1 -1
- package/dist/services/drive.d.ts.map +1 -0
- package/dist/{drive.js → services/drive.js} +1 -1
- package/dist/services/drive.js.map +1 -0
- package/dist/services/flight-recorder.service.d.ts +37 -0
- package/dist/services/flight-recorder.service.d.ts.map +1 -0
- package/dist/services/flight-recorder.service.js +211 -0
- package/dist/services/flight-recorder.service.js.map +1 -0
- package/dist/services/intent.d.ts.map +1 -0
- package/dist/{intent.js → services/intent.js} +78 -23
- package/dist/services/intent.js.map +1 -0
- package/dist/services/keep-alive-sync.service.d.ts +11 -0
- package/dist/services/keep-alive-sync.service.d.ts.map +1 -0
- package/dist/services/keep-alive-sync.service.js +47 -0
- package/dist/services/keep-alive-sync.service.js.map +1 -0
- package/dist/services/keeper.service.d.ts +10 -1
- package/dist/services/keeper.service.d.ts.map +1 -1
- package/dist/services/keeper.service.js +303 -43
- package/dist/services/keeper.service.js.map +1 -1
- package/dist/services/maintenance-signal.js +1 -1
- package/dist/services/maintenance-signal.js.map +1 -1
- package/dist/services/mcp-config.service.d.ts.map +1 -1
- package/dist/services/mcp-config.service.js +19 -6
- package/dist/services/mcp-config.service.js.map +1 -1
- package/dist/services/memory-briefing.service.d.ts.map +1 -1
- package/dist/services/memory-briefing.service.js +13 -7
- package/dist/services/memory-briefing.service.js.map +1 -1
- package/dist/services/memory-pruning.service.d.ts +12 -0
- package/dist/services/memory-pruning.service.d.ts.map +1 -0
- package/dist/services/memory-pruning.service.js +179 -0
- package/dist/services/memory-pruning.service.js.map +1 -0
- package/dist/services/passive-notice.service.d.ts +39 -0
- package/dist/services/passive-notice.service.d.ts.map +1 -0
- package/dist/services/passive-notice.service.js +274 -0
- package/dist/services/passive-notice.service.js.map +1 -0
- package/dist/services/process.service.d.ts +43 -9
- package/dist/services/process.service.d.ts.map +1 -1
- package/dist/services/process.service.js +184 -309
- package/dist/services/process.service.js.map +1 -1
- package/dist/services/reconnect-snapshot.service.d.ts.map +1 -1
- package/dist/services/reconnect-snapshot.service.js +3 -3
- package/dist/services/reconnect-snapshot.service.js.map +1 -1
- package/dist/{scheduler.d.ts → services/scheduler.d.ts} +2 -23
- package/dist/services/scheduler.d.ts.map +1 -0
- package/dist/{scheduler.js → services/scheduler.js} +72 -19
- package/dist/services/scheduler.js.map +1 -0
- package/dist/services/self-update.service.d.ts +26 -5
- package/dist/services/self-update.service.d.ts.map +1 -1
- package/dist/services/self-update.service.js +208 -95
- package/dist/services/self-update.service.js.map +1 -1
- package/dist/services/spawn-common.d.ts +67 -17
- package/dist/services/spawn-common.d.ts.map +1 -1
- package/dist/services/spawn-common.js +401 -50
- package/dist/services/spawn-common.js.map +1 -1
- package/dist/services/spawn-exit-watcher.d.ts +32 -0
- package/dist/services/spawn-exit-watcher.d.ts.map +1 -0
- package/dist/services/spawn-exit-watcher.js +102 -0
- package/dist/services/spawn-exit-watcher.js.map +1 -0
- package/dist/{telegram.d.ts → services/telegram.d.ts} +3 -3
- package/dist/services/telegram.d.ts.map +1 -0
- package/dist/{telegram.js → services/telegram.js} +16 -8
- package/dist/services/telegram.js.map +1 -0
- package/dist/services/thread-config.service.d.ts +25 -0
- package/dist/services/thread-config.service.d.ts.map +1 -0
- package/dist/services/thread-config.service.js +73 -0
- package/dist/services/thread-config.service.js.map +1 -0
- package/dist/services/thread-health.service.d.ts +19 -1
- package/dist/services/thread-health.service.d.ts.map +1 -1
- package/dist/services/thread-health.service.js +101 -17
- package/dist/services/thread-health.service.js.map +1 -1
- package/dist/services/thread-lifecycle.service.d.ts.map +1 -1
- package/dist/services/thread-lifecycle.service.js +26 -7
- package/dist/services/thread-lifecycle.service.js.map +1 -1
- package/dist/services/topic.service.d.ts.map +1 -1
- package/dist/services/topic.service.js +17 -6
- package/dist/services/topic.service.js.map +1 -1
- package/dist/services/worker-cleanup.service.d.ts +21 -3
- package/dist/services/worker-cleanup.service.d.ts.map +1 -1
- package/dist/services/worker-cleanup.service.js +348 -90
- package/dist/services/worker-cleanup.service.js.map +1 -1
- package/dist/sessions/dashboard-registry.d.ts +38 -0
- package/dist/sessions/dashboard-registry.d.ts.map +1 -0
- package/dist/sessions/dashboard-registry.js +84 -0
- package/dist/sessions/dashboard-registry.js.map +1 -0
- package/dist/{sessions.d.ts → sessions/mcp-registry.d.ts} +9 -60
- package/dist/sessions/mcp-registry.d.ts.map +1 -0
- package/dist/{sessions.js → sessions/mcp-registry.js} +13 -214
- package/dist/sessions/mcp-registry.js.map +1 -0
- package/dist/sessions/session-store.d.ts +17 -0
- package/dist/sessions/session-store.d.ts.map +1 -0
- package/dist/sessions/session-store.js +69 -0
- package/dist/sessions/session-store.js.map +1 -0
- package/dist/sessions/topic-registry.d.ts +14 -0
- package/dist/sessions/topic-registry.d.ts.map +1 -0
- package/dist/sessions/topic-registry.js +67 -0
- package/dist/sessions/topic-registry.js.map +1 -0
- package/dist/tools/definitions.d.ts +1 -9
- package/dist/tools/definitions.d.ts.map +1 -1
- package/dist/tools/definitions.js.map +1 -1
- package/dist/tools/defs/memory-defs.d.ts +1 -1
- package/dist/tools/defs/memory-defs.d.ts.map +1 -1
- package/dist/tools/defs/memory-defs.js +1 -1
- package/dist/tools/defs/memory-defs.js.map +1 -1
- package/dist/tools/defs/session-defs.d.ts +1 -1
- package/dist/tools/defs/session-defs.d.ts.map +1 -1
- package/dist/tools/defs/session-defs.js +24 -17
- package/dist/tools/defs/session-defs.js.map +1 -1
- package/dist/tools/defs/skill-defs.d.ts +1 -1
- package/dist/tools/defs/skill-defs.d.ts.map +1 -1
- package/dist/tools/defs/types.d.ts +11 -0
- package/dist/tools/defs/types.d.ts.map +1 -0
- package/dist/{chat-ui/src → tools/defs}/types.js.map +1 -1
- package/dist/tools/defs/utility-defs.d.ts +1 -1
- package/dist/tools/defs/utility-defs.d.ts.map +1 -1
- package/dist/tools/defs/utility-defs.js +4 -3
- package/dist/tools/defs/utility-defs.js.map +1 -1
- package/dist/tools/defs/wait-defs.d.ts +1 -1
- package/dist/tools/defs/wait-defs.d.ts.map +1 -1
- package/dist/tools/delegate-tool.d.ts +3 -3
- package/dist/tools/delegate-tool.d.ts.map +1 -1
- package/dist/tools/delegate-tool.js +177 -45
- package/dist/tools/delegate-tool.js.map +1 -1
- package/dist/tools/memory-tools.d.ts +3 -3
- package/dist/tools/memory-tools.d.ts.map +1 -1
- package/dist/tools/memory-tools.js +111 -40
- package/dist/tools/memory-tools.js.map +1 -1
- package/dist/{response-builders.d.ts → tools/response-builders.d.ts} +2 -2
- package/dist/tools/response-builders.d.ts.map +1 -0
- package/dist/{response-builders.js → tools/response-builders.js} +151 -30
- package/dist/tools/response-builders.js.map +1 -0
- package/dist/tools/session-tools.d.ts +5 -14
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js +51 -32
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/tools/shared-agent-utils.d.ts +1 -1
- package/dist/tools/shared-agent-utils.d.ts.map +1 -1
- package/dist/tools/shared-agent-utils.js +2 -4
- package/dist/tools/shared-agent-utils.js.map +1 -1
- package/dist/tools/skill-tools.d.ts +1 -1
- package/dist/tools/skill-tools.d.ts.map +1 -1
- package/dist/tools/skill-tools.js +12 -7
- package/dist/tools/skill-tools.js.map +1 -1
- package/dist/tools/start-session-tool.d.ts +3 -3
- package/dist/tools/start-session-tool.d.ts.map +1 -1
- package/dist/tools/start-session-tool.js +35 -25
- package/dist/tools/start-session-tool.js.map +1 -1
- package/dist/tools/utility-tools.d.ts +3 -3
- package/dist/tools/utility-tools.d.ts.map +1 -1
- package/dist/tools/utility-tools.js +47 -29
- package/dist/tools/utility-tools.js.map +1 -1
- package/dist/tools/wait/auto-forward.d.ts +1 -1
- package/dist/tools/wait/auto-forward.d.ts.map +1 -1
- package/dist/tools/wait/auto-forward.js +6 -4
- package/dist/tools/wait/auto-forward.js.map +1 -1
- package/dist/tools/wait/context.d.ts +58 -0
- package/dist/tools/wait/context.d.ts.map +1 -0
- package/dist/tools/wait/context.js +5 -0
- package/dist/tools/wait/context.js.map +1 -0
- package/dist/tools/wait/drive-handler.d.ts +2 -2
- package/dist/tools/wait/drive-handler.d.ts.map +1 -1
- package/dist/tools/wait/drive-handler.js +25 -13
- package/dist/tools/wait/drive-handler.js.map +1 -1
- package/dist/tools/wait/index.d.ts +2 -1
- package/dist/tools/wait/index.d.ts.map +1 -1
- package/dist/tools/wait/index.js.map +1 -1
- package/dist/tools/wait/media-processor.d.ts +4 -4
- package/dist/tools/wait/media-processor.d.ts.map +1 -1
- package/dist/tools/wait/media-processor.js +18 -9
- package/dist/tools/wait/media-processor.js.map +1 -1
- package/dist/tools/wait/message-delivery.d.ts +15 -5
- package/dist/tools/wait/message-delivery.d.ts.map +1 -1
- package/dist/tools/wait/message-delivery.js +139 -38
- package/dist/tools/wait/message-delivery.js.map +1 -1
- package/dist/tools/wait/message-processing.d.ts +2 -2
- package/dist/tools/wait/message-processing.d.ts.map +1 -1
- package/dist/tools/wait/message-processing.js +95 -37
- package/dist/tools/wait/message-processing.js.map +1 -1
- package/dist/tools/wait/poll-loop.d.ts +2 -41
- package/dist/tools/wait/poll-loop.d.ts.map +1 -1
- package/dist/tools/wait/poll-loop.js +101 -24
- package/dist/tools/wait/poll-loop.js.map +1 -1
- package/dist/tools/wait/reaction-handler.d.ts +3 -3
- package/dist/tools/wait/reaction-handler.d.ts.map +1 -1
- package/dist/tools/wait/reaction-handler.js +6 -6
- package/dist/tools/wait/reaction-handler.js.map +1 -1
- package/dist/tools/wait/task-handler.d.ts +1 -1
- package/dist/tools/wait/task-handler.d.ts.map +1 -1
- package/dist/tools/wait/task-handler.js +5 -4
- package/dist/tools/wait/task-handler.js.map +1 -1
- package/package.json +12 -2
- package/templates/code-review.default.md +1 -1
- package/templates/fire-and-forget.default.md +1 -1
- package/templates/handoff.default.md +1 -1
- package/templates/sensorium-repair.default.md +1 -1
- package/templates/sleep.default.md +1 -1
- package/templates/swarm.default.md +4 -1
- package/dist/chat-ui/src/main.d.ts +0 -2
- package/dist/chat-ui/src/main.d.ts.map +0 -1
- package/dist/chat-ui/src/main.js +0 -4
- package/dist/chat-ui/src/main.js.map +0 -1
- package/dist/chat-ui/src/markdown.d.ts +0 -2
- package/dist/chat-ui/src/markdown.d.ts.map +0 -1
- package/dist/chat-ui/src/markdown.js +0 -39
- package/dist/chat-ui/src/markdown.js.map +0 -1
- package/dist/chat-ui/src/mock-data.d.ts +0 -4
- package/dist/chat-ui/src/mock-data.d.ts.map +0 -1
- package/dist/chat-ui/src/mock-data.js +0 -230
- package/dist/chat-ui/src/mock-data.js.map +0 -1
- package/dist/chat-ui/src/types.d.ts +0 -47
- package/dist/chat-ui/src/types.d.ts.map +0 -1
- package/dist/chat-ui/vite.config.d.ts +0 -3
- package/dist/chat-ui/vite.config.d.ts.map +0 -1
- package/dist/chat-ui/vite.config.js +0 -14
- package/dist/chat-ui/vite.config.js.map +0 -1
- package/dist/config.d.ts +0 -228
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -841
- package/dist/config.js.map +0 -1
- package/dist/daily-session.d.ts.map +0 -1
- package/dist/daily-session.js.map +0 -1
- package/dist/dashboard.d.ts +0 -10
- package/dist/dashboard.d.ts.map +0 -1
- package/dist/dashboard.js +0 -10
- package/dist/dashboard.js.map +0 -1
- package/dist/data/memory/semantic.d.ts +0 -158
- package/dist/data/memory/semantic.d.ts.map +0 -1
- package/dist/data/memory/semantic.js +0 -588
- package/dist/data/memory/semantic.js.map +0 -1
- package/dist/dispatcher.d.ts +0 -9
- package/dist/dispatcher.d.ts.map +0 -1
- package/dist/dispatcher.js +0 -9
- package/dist/dispatcher.js.map +0 -1
- package/dist/drive.d.ts.map +0 -1
- package/dist/drive.js.map +0 -1
- package/dist/http-server.d.ts.map +0 -1
- package/dist/http-server.js.map +0 -1
- package/dist/intent.d.ts.map +0 -1
- package/dist/intent.js.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js.map +0 -1
- package/dist/markdown.d.ts +0 -26
- package/dist/markdown.d.ts.map +0 -1
- package/dist/markdown.js.map +0 -1
- package/dist/memory.d.ts +0 -9
- package/dist/memory.d.ts.map +0 -1
- package/dist/memory.js +0 -9
- package/dist/memory.js.map +0 -1
- package/dist/openai.d.ts +0 -13
- package/dist/openai.d.ts.map +0 -1
- package/dist/openai.js +0 -17
- package/dist/openai.js.map +0 -1
- package/dist/response-builders.d.ts.map +0 -1
- package/dist/response-builders.js.map +0 -1
- package/dist/scheduler.d.ts.map +0 -1
- package/dist/scheduler.js.map +0 -1
- package/dist/sessions.d.ts.map +0 -1
- package/dist/sessions.js.map +0 -1
- package/dist/stdio-server.d.ts.map +0 -1
- package/dist/stdio-server.js.map +0 -1
- package/dist/telegram.d.ts.map +0 -1
- package/dist/telegram.js.map +0 -1
- package/dist/tool-definitions.d.ts +0 -2
- package/dist/tool-definitions.d.ts.map +0 -1
- package/dist/tool-definitions.js +0 -2
- package/dist/tool-definitions.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
- /package/dist/{logger.d.ts → lib/logger.d.ts} +0 -0
- /package/dist/{types.js → lib/types.js} +0 -0
- /package/dist/{utils.d.ts → lib/utils.d.ts} +0 -0
- /package/dist/{drive.d.ts → services/drive.d.ts} +0 -0
- /package/dist/{intent.d.ts → services/intent.d.ts} +0 -0
- /package/dist/{chat-ui/src → tools/defs}/types.js +0 -0
|
@@ -1,154 +1,24 @@
|
|
|
1
1
|
import { getUnconsolidatedEpisodes, markConsolidated } from "../data/memory/episodes.js";
|
|
2
|
-
import { saveSemanticNote,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { saveSemanticNote, supersedeNote, updateSemanticNote, } from "../data/memory/semantic-notes.js";
|
|
3
|
+
import { searchByEmbedding, saveNoteEmbedding } from "../data/memory/note-embeddings.js";
|
|
4
|
+
import { cleanupConsolidationHousekeeping, getUnconsolidatedThreadIds, hasActiveNote, expireNote, logConsolidation, sweepOrphanedNotes, sweepOrphanedEmbeddings, } from "../data/memory/consolidation.js";
|
|
5
|
+
import { passesStructuralGate, passesQualityGate, parseReflectionFields, } from "../data/memory/reflection-gates.js";
|
|
6
|
+
import { buildExtractionPrompt, buildSupersedePrompt, buildLinkingPrompt, } from "./consolidation-prompts.js";
|
|
7
|
+
import { runMemoryPruning } from "./memory-pruning.service.js";
|
|
5
8
|
import { getThread } from "../data/memory/thread-registry.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
9
|
+
import { generateEmbedding } from "../integrations/openai/chat.js";
|
|
10
|
+
import { chatCompletionJson } from "../llm/json.js";
|
|
11
|
+
import { log } from "../lib/logger.js";
|
|
12
|
+
import { nowISO } from "../data/memory/utils.js";
|
|
13
|
+
import { errorMessage } from "../lib/utils.js";
|
|
10
14
|
const CONSOLIDATION_DEDUP_THRESHOLD = 0.88;
|
|
11
15
|
/** Higher similarity floor required before an obsolescence (non-contradiction) supersede is honored. */
|
|
12
|
-
const OBSOLESCENCE_SIM_THRESHOLD = 0.
|
|
16
|
+
const OBSOLESCENCE_SIM_THRESHOLD = 0.6;
|
|
13
17
|
const VALID_NOTE_TYPES = ["fact", "preference", "pattern", "entity", "relationship"];
|
|
14
18
|
let consolidationInProgress = false;
|
|
15
|
-
function extractEpisodeText(episodes) {
|
|
16
|
-
return episodes
|
|
17
|
-
.map((episode, index) => {
|
|
18
|
-
const contentRecord = episode.content;
|
|
19
|
-
let content;
|
|
20
|
-
if (contentRecord && typeof contentRecord === "object") {
|
|
21
|
-
content = contentRecord.text ?? contentRecord.caption ?? JSON.stringify(contentRecord);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
content = JSON.stringify(episode.content);
|
|
25
|
-
}
|
|
26
|
-
return `[${index + 1}] (${episode.type}/${episode.modality}, ${episode.timestamp}) ${content}`;
|
|
27
|
-
})
|
|
28
|
-
.join("\n");
|
|
29
|
-
}
|
|
30
|
-
function buildExtractionPrompt(episodes) {
|
|
31
|
-
const episodesText = extractEpisodeText(episodes);
|
|
32
|
-
return `You are a memory consolidation agent. Extract ONLY actionable, durable knowledge from these episodes. Quality over quantity — fewer, better notes.
|
|
33
|
-
|
|
34
|
-
Episodes:
|
|
35
|
-
${episodesText}
|
|
36
|
-
|
|
37
|
-
Output a JSON object with:
|
|
38
|
-
{
|
|
39
|
-
"notes": [
|
|
40
|
-
{
|
|
41
|
-
"type": "fact" | "preference" | "pattern" | "entity",
|
|
42
|
-
"content": "One clear, actionable sentence",
|
|
43
|
-
"keywords": ["keyword1", "keyword2", "keyword3"],
|
|
44
|
-
"confidence": 0.0-1.0,
|
|
45
|
-
"priority": 0 | 1 | 2,
|
|
46
|
-
"quality_score": 1-5
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
ACTIONABILITY TEST — apply to every note before including it:
|
|
52
|
-
- Facts must answer: "What should the agent DO with this information?" If a fact is just "X was discussed" or "Y happened" with no implication for future behavior, do NOT extract it.
|
|
53
|
-
- Preferences must be testable: "Given situation X, the operator wants Y." Vague preferences like "prefers quality" are useless — specify the concrete behavior.
|
|
54
|
-
- If a note doesn't change how the agent acts in a future session, it's not worth saving. Prefer zero notes over low-quality notes.
|
|
55
|
-
|
|
56
|
-
BANNED content — do NOT extract:
|
|
57
|
-
- Notes about the memory system, consolidation, audits, reflection quality, or memory management
|
|
58
|
-
- Self-assessments or meta-observations about the agent's own behavior ("I tend to...", "I regularly...")
|
|
59
|
-
- Passive observations that don't inform decisions ("a discussion occurred", "code was reviewed")
|
|
60
|
-
- Transient status ("currently working on X", "PR is open", "tests passing")
|
|
61
|
-
- Point-in-time state / counters / metrics: "audio ingested with 789 transcriptions", "monthly cost ~$33", "42 files processed", any note whose value is a snapshot number that will be different next week. If the number is a live counter or balance rather than a fixed decision/threshold, do NOT extract it.
|
|
62
|
-
- Future-tense plans / intentions: "will implement", "plans to", "going to", "intends to", "is about to". Plans belong in tasks, not durable memory. Only extract an action after it happened and had an outcome.
|
|
63
|
-
- Reconstructable git history: commit hashes, "commit df10c39 added…", "the fix was implemented in <sha>", "PR #123 merged". Git log/blame is authoritative — never store what a commit hash would tell you. Store the durable decision or constraint, not the commit event.
|
|
64
|
-
|
|
65
|
-
EXCEPTION: If the operator explicitly corrected the agent's behavior, extract that correction as a preference.
|
|
66
|
-
|
|
67
|
-
TYPE RULES:
|
|
68
|
-
- fact: Durable knowledge about the project, codebase, architecture, people, or external world
|
|
69
|
-
- preference: Operator's explicit or strongly implied preference for how things should be done
|
|
70
|
-
- pattern: Recurring behavior or decision pattern that predicts future situations
|
|
71
|
-
- entity: Named entity (person, project, service) with identifying attributes
|
|
72
|
-
|
|
73
|
-
PRIORITY DETECTION:
|
|
74
|
-
- priority 2: operator says "important", "crucial", "don't forget", shows strong emotional investment
|
|
75
|
-
- priority 1: operator says "would be nice", "should", mentions something repeatedly
|
|
76
|
-
- priority 0: default for routine facts
|
|
77
|
-
|
|
78
|
-
QUALITY SCORE (quality_score):
|
|
79
|
-
- 1: Vague or useless — generic statement with no actionable implication
|
|
80
|
-
- 2: Weak — some value but missing context or specificity
|
|
81
|
-
- 3: Acceptable — actionable but not particularly memorable
|
|
82
|
-
- 4: Good — specific, actionable, with context or motivation
|
|
83
|
-
- 5: Highly actionable — captures a decision, constraint, or pattern with full context and clear behavioral implication
|
|
84
|
-
Assign honestly. A score below 3 flags the note for monitoring — do NOT use this to suppress extraction; assign a low score and let the system decide.
|
|
85
|
-
|
|
86
|
-
CONTENT QUALITY:
|
|
87
|
-
- Name specific components, features, versions, or decisions — never "a bug fix was completed"
|
|
88
|
-
- Capture WHY (motivation/context), not just WHAT. Include outcome if known
|
|
89
|
-
- If neither WHY nor outcome is available, the note is probably not worth extracting
|
|
90
|
-
- Include dates when they pin a decision (e.g. "On April 15 the operator chose X"). Dates that anchor a durable decision stay; dates that merely log that an event happened do not.
|
|
91
|
-
- Return {"notes": []} if nothing actionable
|
|
92
|
-
|
|
93
|
-
SPECIFICITY GATE — apply to every note before including it:
|
|
94
|
-
- Every note MUST contain at least one specific anchor: a file name, component, person name, config key, or fixed threshold value. A commit hash does NOT count as specificity. If you cannot name something specific, do not create the note.
|
|
95
|
-
- Do NOT create notes that merely say "X was completed" or "Y was done." If something was completed, state WHAT specifically was done — which files changed, what bug was fixed, what the outcome was. Headlines without substance are useless.`;
|
|
96
|
-
}
|
|
97
|
-
function buildSupersedePrompt(batch) {
|
|
98
|
-
const notesSection = batch
|
|
99
|
-
.map((item) => `[${item.noteIndex}] New: "${item.content}"\n` +
|
|
100
|
-
(item.candidates.length > 0
|
|
101
|
-
? ` Candidates:\n${item.candidates.map((c) => ` [${c.noteId}] (${c.type}, conf: ${c.confidence}) ${c.content}`).join("\n")}`
|
|
102
|
-
: ` Candidates: none`))
|
|
103
|
-
.join("\n\n");
|
|
104
|
-
return `You are a memory-freshness detector. For each new note, decide whether it makes any of its candidate existing notes stale.
|
|
105
|
-
|
|
106
|
-
${notesSection}
|
|
107
|
-
|
|
108
|
-
Output a JSON object:
|
|
109
|
-
{
|
|
110
|
-
"results": [
|
|
111
|
-
{ "noteIndex": 0, "verdict": "contradict", "targetNoteId": "sn_xxx", "reason": "Why the candidate is now outdated" },
|
|
112
|
-
{ "noteIndex": 1, "verdict": "obsolete", "targetNoteId": "sn_yyy", "reason": "Same subject, but the new note reflects a later reality" },
|
|
113
|
-
{ "noteIndex": 2, "verdict": "keep" }
|
|
114
|
-
]
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
Verdicts (choose exactly one per note index):
|
|
118
|
-
- "contradict": the new note explicitly contradicts, updates, or replaces a candidate (e.g., newer value, completed/abandoned project, changed preference, updated version). The new note is MORE RECENT than the candidate.
|
|
119
|
-
- "obsolete": the new note does not directly contradict a candidate, but makes it OUTDATED — same subject, and the new note reflects a later reality that supersedes the candidate's still-true-sounding claim.
|
|
120
|
-
- "keep": the new note adds different information without invalidating any candidate, OR no candidates are listed.
|
|
121
|
-
|
|
122
|
-
Rules:
|
|
123
|
-
- Output exactly one result per note index, in ascending order.
|
|
124
|
-
- For "contradict" and "obsolete" you MUST include targetNoteId and reason.
|
|
125
|
-
- Only one candidate can be targeted per new note (the most directly affected one).
|
|
126
|
-
- When unsure, prefer "keep".`;
|
|
127
|
-
}
|
|
128
|
-
function buildLinkingPrompt(newNote, neighbors) {
|
|
129
|
-
const neighborsSection = neighbors.map((n) => `[${n.noteId}] (${n.type}) ${n.content}`).join("\n");
|
|
130
|
-
return `You are a causal link detector for a memory system. Determine if any of these existing notes are causally related to the new note.
|
|
131
|
-
|
|
132
|
-
New note: "${newNote.content}"
|
|
133
|
-
|
|
134
|
-
Existing notes to compare:
|
|
135
|
-
${neighborsSection}
|
|
136
|
-
|
|
137
|
-
Output a JSON object:
|
|
138
|
-
{
|
|
139
|
-
"links": [
|
|
140
|
-
{ "noteId": "sn_xxx", "reason": "Brief causal relationship — one caused the other, or they are part of the same chain" }
|
|
141
|
-
]
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
Rules:
|
|
145
|
-
- Only include notes where there is a CLEAR causal or sequential relationship (one caused the other, one is a consequence of the other, or they are part of the same decision chain)
|
|
146
|
-
- Do NOT link notes that are merely on the same topic or share keywords — the relationship must be directional and causal
|
|
147
|
-
- If no causal relationships exist, output { "links": [] }`;
|
|
148
|
-
}
|
|
149
19
|
async function checkConsolidationDuplicate(db, content, apiKey, threadId) {
|
|
150
20
|
try {
|
|
151
|
-
const embedding = await generateEmbedding(content, apiKey);
|
|
21
|
+
const embedding = await generateEmbedding(content, apiKey, threadId);
|
|
152
22
|
const matches = searchByEmbedding(db, embedding, {
|
|
153
23
|
maxResults: 1,
|
|
154
24
|
minSimilarity: CONSOLIDATION_DEDUP_THRESHOLD,
|
|
@@ -226,13 +96,6 @@ export async function runConsolidationAllThreads(db, options) {
|
|
|
226
96
|
catch (err) {
|
|
227
97
|
log.warn(`[memory] Orphan embeddings sweep failed: ${errorMessage(err)}`);
|
|
228
98
|
}
|
|
229
|
-
try {
|
|
230
|
-
const topicCount = rebuildTopicIndex(db);
|
|
231
|
-
allDetails.push(`Topic index rebuilt: ${topicCount} topics`);
|
|
232
|
-
}
|
|
233
|
-
catch (err) {
|
|
234
|
-
log.warn(`[memory] Topic index rebuild failed: ${errorMessage(err)}`);
|
|
235
|
-
}
|
|
236
99
|
return {
|
|
237
100
|
episodesProcessed: totalProcessed,
|
|
238
101
|
notesCreated: totalNotes,
|
|
@@ -257,7 +120,12 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
257
120
|
const threadEntry = getThread(db, threadId);
|
|
258
121
|
if (threadEntry?.type === "worker") {
|
|
259
122
|
log.info(`[consolidation] Skipping — thread ${threadId} is a worker thread`);
|
|
260
|
-
return {
|
|
123
|
+
return {
|
|
124
|
+
episodesProcessed: 0,
|
|
125
|
+
notesCreated: 0,
|
|
126
|
+
durationMs: 0,
|
|
127
|
+
details: ["Skipped — worker thread."],
|
|
128
|
+
};
|
|
261
129
|
}
|
|
262
130
|
const skipLock = options?._skipLock ?? false;
|
|
263
131
|
if (!skipLock && consolidationInProgress) {
|
|
@@ -277,12 +145,25 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
277
145
|
const dryRun = options?.dryRun ?? false;
|
|
278
146
|
// Recency-aware (obsolescence) supersede gate. Contradiction supersede is unaffected by this flag.
|
|
279
147
|
// off — obsolescence verdicts ignored entirely (legacy behavior).
|
|
280
|
-
// shadow — evaluate + log what WOULD be superseded, but do NOT mutate
|
|
281
|
-
// active — actually supersede obsolete notes via the soft supersedeNote path.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
148
|
+
// shadow — evaluate + log what WOULD be superseded, but do NOT mutate.
|
|
149
|
+
// active — actually supersede obsolete notes via the soft supersedeNote path (default).
|
|
150
|
+
// The two-key gate below (similarity floor AND facts-only) plus the guardrail/pinned
|
|
151
|
+
// exclusion is what keeps "active" safe; an unrecognized value falls back to the
|
|
152
|
+
// non-mutating "shadow" rather than silently writing on a typo'd config.
|
|
153
|
+
const supersedeObsolescenceRaw = process.env.SUPERSEDE_OBSOLESCENCE?.trim().toLowerCase();
|
|
154
|
+
let supersedeObsolescenceMode;
|
|
155
|
+
if (!supersedeObsolescenceRaw) {
|
|
156
|
+
supersedeObsolescenceMode = "active";
|
|
157
|
+
}
|
|
158
|
+
else if (supersedeObsolescenceRaw === "off" ||
|
|
159
|
+
supersedeObsolescenceRaw === "shadow" ||
|
|
160
|
+
supersedeObsolescenceRaw === "active") {
|
|
161
|
+
supersedeObsolescenceMode = supersedeObsolescenceRaw;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
log.warn(`[consolidation] Unrecognized SUPERSEDE_OBSOLESCENCE="${supersedeObsolescenceRaw}" — falling back to shadow (no mutation)`);
|
|
165
|
+
supersedeObsolescenceMode = "shadow";
|
|
166
|
+
}
|
|
286
167
|
const episodes = getUnconsolidatedEpisodes(db, threadId, maxEpisodes);
|
|
287
168
|
if (episodes.length === 0) {
|
|
288
169
|
return {
|
|
@@ -304,23 +185,30 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
304
185
|
{ role: "system", content: buildExtractionPrompt(episodes) },
|
|
305
186
|
{ role: "user", content: "Extract knowledge from the episodes above." },
|
|
306
187
|
];
|
|
307
|
-
const
|
|
188
|
+
const extractParsed = (await chatCompletionJson(extractMessages, apiKey, {
|
|
308
189
|
model: process.env.CONSOLIDATION_MODEL ?? "gpt-4o",
|
|
190
|
+
category: "consolidation",
|
|
191
|
+
threadId,
|
|
309
192
|
maxTokens: 4096,
|
|
310
193
|
responseFormat: { type: "json_object" },
|
|
311
194
|
timeoutMs: 60_000,
|
|
312
|
-
});
|
|
313
|
-
const extractParsed = repairAndParseJSON(extractRaw);
|
|
195
|
+
}));
|
|
314
196
|
const extractedNotes = extractParsed.notes ?? [];
|
|
315
197
|
const episodeIds = episodes.map((episode) => episode.episodeId);
|
|
316
198
|
if (!dryRun) {
|
|
317
199
|
const noteWrites = [];
|
|
318
200
|
for (const note of extractedNotes) {
|
|
319
|
-
if (typeof note.content !== "string" ||
|
|
201
|
+
if (typeof note.content !== "string" ||
|
|
202
|
+
note.content.length === 0 ||
|
|
203
|
+
note.content.length >= 2000) {
|
|
320
204
|
log.warn(`[consolidation] Skipping note with invalid content (type=${typeof note.content}, len=${typeof note.content === "string" ? note.content.length : "N/A"})`);
|
|
321
205
|
continue;
|
|
322
206
|
}
|
|
323
|
-
const
|
|
207
|
+
const typeDeclared = VALID_NOTE_TYPES.includes(note.type);
|
|
208
|
+
const noteType = (typeDeclared ? note.type : "fact");
|
|
209
|
+
if (!typeDeclared) {
|
|
210
|
+
log.warn(`[consolidation] Extracted note has unrecognized type "${note.type}" — saving as "fact", not eligible for obsolescence supersede`);
|
|
211
|
+
}
|
|
324
212
|
const dedup = await checkConsolidationDuplicate(db, note.content, apiKey, knowledgeThreadId);
|
|
325
213
|
if (dedup.isDuplicate) {
|
|
326
214
|
log.debug(`[consolidation] Dedup: skipping note similar to ${dedup.matchId} at ${dedup.similarity?.toFixed(3)}`);
|
|
@@ -334,6 +222,7 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
334
222
|
priority: Math.max(0, Math.min(2, note.priority ?? 0)),
|
|
335
223
|
qualityScore: typeof note.quality_score === "number" ? note.quality_score : null,
|
|
336
224
|
embedding: dedup.embedding,
|
|
225
|
+
typeDeclared,
|
|
337
226
|
});
|
|
338
227
|
}
|
|
339
228
|
// ── Step 2: Supersede check (batched LLM calls) ───────────────────
|
|
@@ -363,20 +252,23 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
363
252
|
})),
|
|
364
253
|
}));
|
|
365
254
|
try {
|
|
366
|
-
const
|
|
255
|
+
const supersedeParsed = (await chatCompletionJson([
|
|
367
256
|
{ role: "system", content: buildSupersedePrompt(batch) },
|
|
368
257
|
{ role: "user", content: "Check for contradictions." },
|
|
369
258
|
], apiKey, {
|
|
370
259
|
model: process.env.CONSOLIDATION_MODEL ?? "gpt-4o",
|
|
260
|
+
category: "consolidation",
|
|
261
|
+
threadId,
|
|
371
262
|
maxTokens: 1024,
|
|
372
263
|
responseFormat: { type: "json_object" },
|
|
373
264
|
timeoutMs: 30_000,
|
|
374
|
-
});
|
|
375
|
-
const supersedeParsed = repairAndParseJSON(supersedeRaw);
|
|
265
|
+
}));
|
|
376
266
|
for (const result of supersedeParsed.results ?? []) {
|
|
377
267
|
// Back-compat: a legacy {supersede:true} is a contradiction verdict.
|
|
378
268
|
const verdict = result.verdict ?? (result.supersede ? "contradict" : "keep");
|
|
379
|
-
if ((verdict !== "contradict" && verdict !== "obsolete") ||
|
|
269
|
+
if ((verdict !== "contradict" && verdict !== "obsolete") ||
|
|
270
|
+
!result.targetNoteId ||
|
|
271
|
+
typeof result.noteIndex !== "number") {
|
|
380
272
|
continue;
|
|
381
273
|
}
|
|
382
274
|
const item = chunk[result.noteIndex];
|
|
@@ -402,15 +294,27 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
402
294
|
log.debug(`[consolidation] Obsolescence rejected: sim ${candidate.similarity.toFixed(3)} < ${OBSOLESCENCE_SIM_THRESHOLD}`);
|
|
403
295
|
continue;
|
|
404
296
|
}
|
|
405
|
-
|
|
406
|
-
|
|
297
|
+
// Facts-only, and only when the extractor *declared* the type — a
|
|
298
|
+
// coerced "fact" is an unknown, not a fact.
|
|
299
|
+
if (!item.nw.typeDeclared || item.nw.type !== "fact" || candidate.type !== "fact") {
|
|
300
|
+
log.debug(`[consolidation] Obsolescence rejected: non-fact (new=${item.nw.type}${item.nw.typeDeclared ? "" : " [coerced]"}, candidate=${candidate.type})`);
|
|
407
301
|
continue;
|
|
408
302
|
}
|
|
409
|
-
item.nw.supersede = {
|
|
303
|
+
item.nw.supersede = {
|
|
304
|
+
targetNoteId: candidate.noteId,
|
|
305
|
+
reason: result.reason ?? "",
|
|
306
|
+
verdict: "obsolete",
|
|
307
|
+
similarity: candidate.similarity,
|
|
308
|
+
};
|
|
410
309
|
}
|
|
411
310
|
else {
|
|
412
311
|
// Contradiction path — unchanged behavior for any non-guardrail/pinned candidate.
|
|
413
|
-
item.nw.supersede = {
|
|
312
|
+
item.nw.supersede = {
|
|
313
|
+
targetNoteId: candidate.noteId,
|
|
314
|
+
reason: result.reason ?? "",
|
|
315
|
+
verdict: "contradict",
|
|
316
|
+
similarity: candidate.similarity,
|
|
317
|
+
};
|
|
414
318
|
}
|
|
415
319
|
}
|
|
416
320
|
}
|
|
@@ -421,6 +325,7 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
421
325
|
// ── Transaction: all DB writes ────────────────────────────────────
|
|
422
326
|
const savedNotes = [];
|
|
423
327
|
let supersededCount = 0;
|
|
328
|
+
let obsoleteSupersededCount = 0;
|
|
424
329
|
db.transaction(() => {
|
|
425
330
|
for (const { nw } of notesWithCandidates) {
|
|
426
331
|
let noteId;
|
|
@@ -438,7 +343,14 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
438
343
|
sourceEpisodes: episodeIds,
|
|
439
344
|
});
|
|
440
345
|
supersededCount++;
|
|
441
|
-
|
|
346
|
+
if (sup.verdict === "obsolete")
|
|
347
|
+
obsoleteSupersededCount++;
|
|
348
|
+
const supersedeMsg = `[supersede:${sup.verdict}] ${sup.targetNoteId} → ${noteId} (sim=${sup.similarity.toFixed(3)}, reason=${sup.reason})`;
|
|
349
|
+
// Log the pair, not just the count: this is the only durable record of
|
|
350
|
+
// which note expired and what replaced it. Shadow mode logs its proposed
|
|
351
|
+
// pairs, so the mutating path must not log less than the dry one.
|
|
352
|
+
log.info(`[memory] ${supersedeMsg}`);
|
|
353
|
+
details.push(supersedeMsg);
|
|
442
354
|
}
|
|
443
355
|
else {
|
|
444
356
|
noteId = saveSemanticNote(db, {
|
|
@@ -474,7 +386,10 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
474
386
|
});
|
|
475
387
|
})();
|
|
476
388
|
if (supersededCount > 0) {
|
|
477
|
-
|
|
389
|
+
// Obsolescence supersedes are counted separately: they are the ones the
|
|
390
|
+
// SUPERSEDE_OBSOLESCENCE flag turned on, and the ones to look at first if
|
|
391
|
+
// memory goes missing.
|
|
392
|
+
log.info(`[memory] Superseded ${supersededCount} outdated note(s) — ${supersededCount - obsoleteSupersededCount} contradiction, ${obsoleteSupersededCount} obsolescence`);
|
|
478
393
|
}
|
|
479
394
|
// ── Step 3: Linking enrichment (post-save, optional) ──────────────
|
|
480
395
|
for (const saved of savedNotes) {
|
|
@@ -486,10 +401,12 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
486
401
|
minSimilarity: 0.4,
|
|
487
402
|
skipAccessTracking: true,
|
|
488
403
|
threadId: knowledgeThreadId,
|
|
489
|
-
})
|
|
404
|
+
})
|
|
405
|
+
.filter((n) => n.noteId !== saved.noteId)
|
|
406
|
+
.slice(0, 5);
|
|
490
407
|
if (neighbors.length === 0)
|
|
491
408
|
continue;
|
|
492
|
-
const
|
|
409
|
+
const linkParsed = (await chatCompletionJson([
|
|
493
410
|
{
|
|
494
411
|
role: "system",
|
|
495
412
|
content: buildLinkingPrompt({ noteId: saved.noteId, content: saved.content }, neighbors.map((n) => ({ noteId: n.noteId, type: n.type, content: n.content }))),
|
|
@@ -497,13 +414,16 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
497
414
|
{ role: "user", content: "Identify causal links." },
|
|
498
415
|
], apiKey, {
|
|
499
416
|
model: process.env.CONSOLIDATION_MODEL ?? "gpt-4o",
|
|
417
|
+
category: "consolidation",
|
|
418
|
+
threadId,
|
|
500
419
|
maxTokens: 512,
|
|
501
420
|
responseFormat: { type: "json_object" },
|
|
502
421
|
timeoutMs: 20_000,
|
|
503
|
-
});
|
|
504
|
-
const linkParsed = repairAndParseJSON(linkRaw);
|
|
422
|
+
}));
|
|
505
423
|
const neighborIds = new Set(neighbors.map((n) => n.noteId));
|
|
506
|
-
const links = (linkParsed.links ?? []).filter((l) => typeof l.noteId === "string" &&
|
|
424
|
+
const links = (linkParsed.links ?? []).filter((l) => typeof l.noteId === "string" &&
|
|
425
|
+
typeof l.reason === "string" &&
|
|
426
|
+
neighborIds.has(l.noteId));
|
|
507
427
|
if (links.length > 0) {
|
|
508
428
|
const linkedNotes = links.map((l) => l.noteId);
|
|
509
429
|
const linkReasons = {};
|
|
@@ -552,13 +472,13 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
552
472
|
// expiring historical notes is a separate, backed-up cleanup step, not this sweep.
|
|
553
473
|
const structural = passesStructuralGate(fields, { requireAnchor: false });
|
|
554
474
|
if (!structural.pass) {
|
|
555
|
-
expireNote(db, row.note_id, nowStr);
|
|
475
|
+
expireNote(db, row.note_id, nowStr, "quality-gate");
|
|
556
476
|
expiredReflections++;
|
|
557
477
|
continue;
|
|
558
478
|
}
|
|
559
479
|
const quality = passesQualityGate(row.content, row.confidence);
|
|
560
480
|
if (!quality.pass) {
|
|
561
|
-
expireNote(db, row.note_id, nowStr);
|
|
481
|
+
expireNote(db, row.note_id, nowStr, "quality-gate");
|
|
562
482
|
expiredReflections++;
|
|
563
483
|
}
|
|
564
484
|
}
|
|
@@ -570,17 +490,6 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
570
490
|
log.warn(`[consolidation] Reflection quality gate cleanup failed: ${errorMessage(err)}`);
|
|
571
491
|
}
|
|
572
492
|
}
|
|
573
|
-
// Keep meta_topic_index accurate on the hot path (drive-handler / daily-session).
|
|
574
|
-
// Skipped when running inside runConsolidationAllThreads (_skipLock), which rebuilds
|
|
575
|
-
// once after its pruning/sweep phase to avoid N redundant per-thread rebuilds.
|
|
576
|
-
if (!skipLock && !dryRun) {
|
|
577
|
-
try {
|
|
578
|
-
rebuildTopicIndex(db);
|
|
579
|
-
}
|
|
580
|
-
catch (err) {
|
|
581
|
-
log.warn(`[memory] Topic index rebuild failed: ${errorMessage(err)}`);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
493
|
return {
|
|
585
494
|
episodesProcessed: episodes.length,
|
|
586
495
|
notesCreated,
|
|
@@ -593,166 +502,4 @@ export async function runIntelligentConsolidation(db, threadId, options) {
|
|
|
593
502
|
consolidationInProgress = false;
|
|
594
503
|
}
|
|
595
504
|
}
|
|
596
|
-
export async function runMemoryPruning(db, options) {
|
|
597
|
-
const pruningEnabled = process.env.PRUNING_ENABLED;
|
|
598
|
-
if (pruningEnabled === "false" || pruningEnabled === "0") {
|
|
599
|
-
return {
|
|
600
|
-
notesScanned: 0,
|
|
601
|
-
notesExpired: 0,
|
|
602
|
-
notesMerged: 0,
|
|
603
|
-
durationMs: 0,
|
|
604
|
-
details: ["Pruning disabled via PRUNING_ENABLED env var."],
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
const apiKey = process.env.OPENAI_API_KEY;
|
|
608
|
-
if (!apiKey) {
|
|
609
|
-
return {
|
|
610
|
-
notesScanned: 0,
|
|
611
|
-
notesExpired: 0,
|
|
612
|
-
notesMerged: 0,
|
|
613
|
-
durationMs: 0,
|
|
614
|
-
details: ["Pruning skipped — OPENAI_API_KEY not set."],
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
const startMs = Date.now();
|
|
618
|
-
const envSampleSize = parseInt(process.env.PRUNING_SAMPLE_SIZE ?? "", 10);
|
|
619
|
-
const maxNotes = options?.maxNotes ?? (Number.isFinite(envSampleSize) && envSampleSize > 0 ? envSampleSize : 60);
|
|
620
|
-
const dryRun = options?.dryRun ?? false;
|
|
621
|
-
const details = [];
|
|
622
|
-
const candidates = getCandidateNotesForPruning(db, maxNotes);
|
|
623
|
-
if (candidates.length < 5) {
|
|
624
|
-
return {
|
|
625
|
-
notesScanned: 0,
|
|
626
|
-
notesExpired: 0,
|
|
627
|
-
notesMerged: 0,
|
|
628
|
-
durationMs: Date.now() - startMs,
|
|
629
|
-
details: ["Too few candidate notes for pruning (< 5)."],
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
const now = new Date();
|
|
633
|
-
const notesText = candidates
|
|
634
|
-
.map((row) => {
|
|
635
|
-
const ageMs = now.getTime() - new Date(row.created_at).getTime();
|
|
636
|
-
const ageDays = Math.round(ageMs / (1000 * 60 * 60 * 24));
|
|
637
|
-
return `[${row.note_id}] (${row.type}, conf: ${row.confidence}, accesses: ${row.access_count}, age: ${ageDays}d) ${row.content}`;
|
|
638
|
-
})
|
|
639
|
-
.join("\n");
|
|
640
|
-
const systemPrompt = `You are a memory quality manager. Review these semantic notes and identify problems.
|
|
641
|
-
|
|
642
|
-
Notes to review:
|
|
643
|
-
${notesText}
|
|
644
|
-
|
|
645
|
-
Output a JSON object:
|
|
646
|
-
{
|
|
647
|
-
"expire": [
|
|
648
|
-
{ "noteId": "sn_xxx", "reason": "Brief explanation" }
|
|
649
|
-
],
|
|
650
|
-
"merge": [
|
|
651
|
-
{ "keepId": "sn_xxx", "expireId": "sn_yyy", "mergedContent": "Best combined version", "reason": "Brief explanation" }
|
|
652
|
-
]
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
Decision criteria:
|
|
656
|
-
- EXPIRE if: the note is vague/non-actionable ("the system has issues"), trivially obvious, or clearly outdated (references old versions, completed tasks still marked pending)
|
|
657
|
-
- MERGE if: two or more notes convey the same information — keep the more specific/accurate one. Provide mergedContent combining the best of both when useful.
|
|
658
|
-
- KEEP (omit from output) if: the note contains unique, specific, actionable information
|
|
659
|
-
|
|
660
|
-
Be conservative — when in doubt, keep the note. Only expire notes you are confident are low-value.
|
|
661
|
-
Do NOT expire preferences or guardrails unless they clearly contradict each other.
|
|
662
|
-
Return {"expire": [], "merge": []} if nothing needs pruning.`;
|
|
663
|
-
try {
|
|
664
|
-
const messages = [
|
|
665
|
-
{ role: "system", content: systemPrompt },
|
|
666
|
-
{ role: "user", content: "Review the notes above and identify any that should be expired or merged." },
|
|
667
|
-
];
|
|
668
|
-
const raw = await chatCompletion(messages, apiKey, {
|
|
669
|
-
model: process.env.CONSOLIDATION_MODEL ?? "gpt-4o",
|
|
670
|
-
maxTokens: 4096,
|
|
671
|
-
responseFormat: { type: "json_object" },
|
|
672
|
-
timeoutMs: 60_000,
|
|
673
|
-
});
|
|
674
|
-
const parsed = repairAndParseJSON(raw);
|
|
675
|
-
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
676
|
-
throw new Error(`LLM returned non-object response: ${typeof parsed}`);
|
|
677
|
-
}
|
|
678
|
-
const result = parsed;
|
|
679
|
-
const expireActions = (Array.isArray(result.expire) ? result.expire : []);
|
|
680
|
-
const mergeActions = (Array.isArray(result.merge) ? result.merge : []);
|
|
681
|
-
const candidateIds = new Set(candidates.map((candidate) => candidate.note_id));
|
|
682
|
-
let expired = 0;
|
|
683
|
-
let merged = 0;
|
|
684
|
-
const nowStr = nowISO();
|
|
685
|
-
if (!dryRun) {
|
|
686
|
-
db.transaction(() => {
|
|
687
|
-
for (const action of expireActions) {
|
|
688
|
-
if (!action.noteId)
|
|
689
|
-
continue;
|
|
690
|
-
if (!candidateIds.has(action.noteId)) {
|
|
691
|
-
details.push(`[skip-expire] ${action.noteId} not in candidate set`);
|
|
692
|
-
continue;
|
|
693
|
-
}
|
|
694
|
-
if (!hasActiveNote(db, action.noteId)) {
|
|
695
|
-
details.push(`[skip-expire] ${action.noteId} not found or already expired`);
|
|
696
|
-
continue;
|
|
697
|
-
}
|
|
698
|
-
expireNote(db, action.noteId, nowStr);
|
|
699
|
-
expired++;
|
|
700
|
-
details.push(`[pruned] ${action.noteId}: ${action.reason}`);
|
|
701
|
-
}
|
|
702
|
-
for (const action of mergeActions) {
|
|
703
|
-
if (!action.keepId || !action.expireId)
|
|
704
|
-
continue;
|
|
705
|
-
if (action.keepId === action.expireId) {
|
|
706
|
-
details.push(`[skip-merge] ${action.keepId}: keepId === expireId`);
|
|
707
|
-
continue;
|
|
708
|
-
}
|
|
709
|
-
if (!candidateIds.has(action.keepId) || !candidateIds.has(action.expireId)) {
|
|
710
|
-
details.push(`[skip-merge] ${action.keepId}/${action.expireId} not in candidate set`);
|
|
711
|
-
continue;
|
|
712
|
-
}
|
|
713
|
-
const keepNote = getActiveNoteContent(db, action.keepId);
|
|
714
|
-
const expireNoteRow = getActiveNoteContent(db, action.expireId);
|
|
715
|
-
if (!keepNote || !expireNoteRow) {
|
|
716
|
-
details.push(`[skip-merge] ${action.keepId}/${action.expireId} not found`);
|
|
717
|
-
continue;
|
|
718
|
-
}
|
|
719
|
-
mergeDuplicateNote(db, keepNote.noteId, expireNoteRow.noteId, nowStr, action.mergedContent && action.mergedContent !== keepNote.content ? action.mergedContent : undefined);
|
|
720
|
-
merged++;
|
|
721
|
-
details.push(`[merged] ${action.expireId} → ${action.keepId}: ${action.reason}`);
|
|
722
|
-
}
|
|
723
|
-
})();
|
|
724
|
-
}
|
|
725
|
-
else {
|
|
726
|
-
for (const action of expireActions) {
|
|
727
|
-
details.push(`[dry-run] [prune] ${action.noteId}: ${action.reason}`);
|
|
728
|
-
expired++;
|
|
729
|
-
}
|
|
730
|
-
for (const action of mergeActions) {
|
|
731
|
-
details.push(`[dry-run] [merge] ${action.expireId} → ${action.keepId}: ${action.reason}`);
|
|
732
|
-
merged++;
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
if (expired + merged > 0) {
|
|
736
|
-
log.info(`[memory] Pruning: expired ${expired}, merged ${merged} note(s)`);
|
|
737
|
-
}
|
|
738
|
-
return {
|
|
739
|
-
notesScanned: candidates.length,
|
|
740
|
-
notesExpired: expired,
|
|
741
|
-
notesMerged: merged,
|
|
742
|
-
durationMs: Date.now() - startMs,
|
|
743
|
-
details,
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
catch (err) {
|
|
747
|
-
const msg = errorMessage(err);
|
|
748
|
-
log.error(`[memory] Pruning failed: ${msg}`);
|
|
749
|
-
return {
|
|
750
|
-
notesScanned: candidates.length,
|
|
751
|
-
notesExpired: 0,
|
|
752
|
-
notesMerged: 0,
|
|
753
|
-
durationMs: Date.now() - startMs,
|
|
754
|
-
details: [`Pruning failed: ${msg}`],
|
|
755
|
-
};
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
505
|
//# sourceMappingURL=consolidation.service.js.map
|