cognitive-core 0.1.0 → 0.2.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/.claude/settings.json +88 -0
- package/.claude/settings.local.json +11 -0
- package/.entire/settings.json +4 -0
- package/CLAUDE.md +233 -0
- package/README.md +841 -255
- package/dist/atlas.d.ts +150 -12
- package/dist/atlas.d.ts.map +1 -1
- package/dist/atlas.js +391 -31
- package/dist/atlas.js.map +1 -1
- package/dist/bin/cli-utils.d.ts +37 -0
- package/dist/bin/cli-utils.d.ts.map +1 -0
- package/dist/bin/cli-utils.js +176 -0
- package/dist/bin/cli-utils.js.map +1 -0
- package/dist/bin/cognitive-core.d.ts +2 -12
- package/dist/bin/cognitive-core.d.ts.map +1 -1
- package/dist/bin/cognitive-core.js +76 -351
- package/dist/bin/cognitive-core.js.map +1 -1
- package/dist/bin/commands/kb.d.ts +6 -0
- package/dist/bin/commands/kb.d.ts.map +1 -0
- package/dist/bin/commands/kb.js +240 -0
- package/dist/bin/commands/kb.js.map +1 -0
- package/dist/bin/commands/learn.d.ts +6 -0
- package/dist/bin/commands/learn.d.ts.map +1 -0
- package/dist/bin/commands/learn.js +91 -0
- package/dist/bin/commands/learn.js.map +1 -0
- package/dist/bin/commands/legacy.d.ts +12 -0
- package/dist/bin/commands/legacy.d.ts.map +1 -0
- package/dist/bin/commands/legacy.js +142 -0
- package/dist/bin/commands/legacy.js.map +1 -0
- package/dist/bin/commands/run.d.ts +3 -0
- package/dist/bin/commands/run.d.ts.map +1 -0
- package/dist/bin/commands/run.js +99 -0
- package/dist/bin/commands/run.js.map +1 -0
- package/dist/bin/commands/sessions.d.ts +9 -0
- package/dist/bin/commands/sessions.d.ts.map +1 -0
- package/dist/bin/commands/sessions.js +183 -0
- package/dist/bin/commands/sessions.js.map +1 -0
- package/dist/bin/commands/skills.d.ts +6 -0
- package/dist/bin/commands/skills.d.ts.map +1 -0
- package/dist/bin/commands/skills.js +135 -0
- package/dist/bin/commands/skills.js.map +1 -0
- package/dist/embeddings/index.d.ts +1 -0
- package/dist/embeddings/index.d.ts.map +1 -1
- package/dist/embeddings/index.js +2 -0
- package/dist/embeddings/index.js.map +1 -1
- package/dist/embeddings/inverted-index.d.ts +47 -0
- package/dist/embeddings/inverted-index.d.ts.map +1 -0
- package/dist/embeddings/inverted-index.js +122 -0
- package/dist/embeddings/inverted-index.js.map +1 -0
- package/dist/embeddings/manager.d.ts +3 -1
- package/dist/embeddings/manager.d.ts.map +1 -1
- package/dist/embeddings/manager.js +12 -7
- package/dist/embeddings/manager.js.map +1 -1
- package/dist/embeddings/provider.d.ts.map +1 -1
- package/dist/embeddings/provider.js +6 -3
- package/dist/embeddings/provider.js.map +1 -1
- package/dist/embeddings/vector-store.d.ts +7 -3
- package/dist/embeddings/vector-store.d.ts.map +1 -1
- package/dist/embeddings/vector-store.js +22 -6
- package/dist/embeddings/vector-store.js.map +1 -1
- package/dist/factory.d.ts +11 -12
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +20 -7
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +11 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +71 -8
- package/dist/index.js.map +1 -1
- package/dist/learning/analyzer.d.ts.map +1 -1
- package/dist/learning/analyzer.js +17 -35
- package/dist/learning/analyzer.js.map +1 -1
- package/dist/learning/energy-evaluator.d.ts +128 -0
- package/dist/learning/energy-evaluator.d.ts.map +1 -0
- package/dist/learning/energy-evaluator.js +175 -0
- package/dist/learning/energy-evaluator.js.map +1 -0
- package/dist/learning/healing-orchestrator.d.ts +182 -0
- package/dist/learning/healing-orchestrator.d.ts.map +1 -0
- package/dist/learning/healing-orchestrator.js +250 -0
- package/dist/learning/healing-orchestrator.js.map +1 -0
- package/dist/learning/index.d.ts +11 -2
- package/dist/learning/index.d.ts.map +1 -1
- package/dist/learning/index.js +20 -3
- package/dist/learning/index.js.map +1 -1
- package/dist/learning/instant-loop.d.ts +87 -0
- package/dist/learning/instant-loop.d.ts.map +1 -0
- package/dist/learning/instant-loop.js +264 -0
- package/dist/learning/instant-loop.js.map +1 -0
- package/dist/learning/knowledge-extractor.d.ts +56 -0
- package/dist/learning/knowledge-extractor.d.ts.map +1 -0
- package/dist/learning/knowledge-extractor.js +336 -0
- package/dist/learning/knowledge-extractor.js.map +1 -0
- package/dist/learning/loop-coordinator.d.ts +61 -0
- package/dist/learning/loop-coordinator.d.ts.map +1 -0
- package/dist/learning/loop-coordinator.js +96 -0
- package/dist/learning/loop-coordinator.js.map +1 -0
- package/dist/learning/maintenance-scheduler.d.ts +141 -0
- package/dist/learning/maintenance-scheduler.d.ts.map +1 -0
- package/dist/learning/maintenance-scheduler.js +186 -0
- package/dist/learning/maintenance-scheduler.js.map +1 -0
- package/dist/learning/meta-learner.d.ts +7 -0
- package/dist/learning/meta-learner.d.ts.map +1 -1
- package/dist/learning/meta-learner.js +47 -21
- package/dist/learning/meta-learner.js.map +1 -1
- package/dist/learning/pipeline.d.ts +55 -4
- package/dist/learning/pipeline.d.ts.map +1 -1
- package/dist/learning/pipeline.js +134 -16
- package/dist/learning/pipeline.js.map +1 -1
- package/dist/learning/reflexion-generator.d.ts +64 -0
- package/dist/learning/reflexion-generator.d.ts.map +1 -0
- package/dist/learning/reflexion-generator.js +194 -0
- package/dist/learning/reflexion-generator.js.map +1 -0
- package/dist/learning/team-ingester.d.ts +152 -0
- package/dist/learning/team-ingester.d.ts.map +1 -0
- package/dist/learning/team-ingester.js +333 -0
- package/dist/learning/team-ingester.js.map +1 -0
- package/dist/learning/team-meta-learner.d.ts +50 -0
- package/dist/learning/team-meta-learner.d.ts.map +1 -0
- package/dist/learning/team-meta-learner.js +417 -0
- package/dist/learning/team-meta-learner.js.map +1 -0
- package/dist/learning/team-pipeline.d.ts +76 -0
- package/dist/learning/team-pipeline.d.ts.map +1 -0
- package/dist/learning/team-pipeline.js +266 -0
- package/dist/learning/team-pipeline.js.map +1 -0
- package/dist/learning/trajectory-sources/dataclaw.d.ts +41 -0
- package/dist/learning/trajectory-sources/dataclaw.d.ts.map +1 -0
- package/dist/learning/trajectory-sources/dataclaw.js +330 -0
- package/dist/learning/trajectory-sources/dataclaw.js.map +1 -0
- package/dist/learning/trajectory-sources/entire.d.ts +31 -0
- package/dist/learning/trajectory-sources/entire.d.ts.map +1 -0
- package/dist/learning/trajectory-sources/entire.js +189 -0
- package/dist/learning/trajectory-sources/entire.js.map +1 -0
- package/dist/learning/trajectory-sources/file.d.ts +23 -0
- package/dist/learning/trajectory-sources/file.d.ts.map +1 -0
- package/dist/learning/trajectory-sources/file.js +101 -0
- package/dist/learning/trajectory-sources/file.js.map +1 -0
- package/dist/learning/trajectory-sources/huggingface.d.ts +36 -0
- package/dist/learning/trajectory-sources/huggingface.d.ts.map +1 -0
- package/dist/learning/trajectory-sources/huggingface.js +157 -0
- package/dist/learning/trajectory-sources/huggingface.js.map +1 -0
- package/dist/learning/trajectory-sources/in-memory.d.ts +21 -0
- package/dist/learning/trajectory-sources/in-memory.d.ts.map +1 -0
- package/dist/learning/trajectory-sources/in-memory.js +43 -0
- package/dist/learning/trajectory-sources/in-memory.js.map +1 -0
- package/dist/learning/trajectory-sources/index.d.ts +7 -0
- package/dist/learning/trajectory-sources/index.d.ts.map +1 -0
- package/dist/learning/trajectory-sources/index.js +7 -0
- package/dist/learning/trajectory-sources/index.js.map +1 -0
- package/dist/learning/trajectory-sources/pipeline.d.ts +24 -0
- package/dist/learning/trajectory-sources/pipeline.d.ts.map +1 -0
- package/dist/learning/trajectory-sources/pipeline.js +47 -0
- package/dist/learning/trajectory-sources/pipeline.js.map +1 -0
- package/dist/learning/unified-pipeline.d.ts +281 -0
- package/dist/learning/unified-pipeline.d.ts.map +1 -0
- package/dist/learning/unified-pipeline.js +637 -0
- package/dist/learning/unified-pipeline.js.map +1 -0
- package/dist/memory/candidate-retrieval.d.ts +43 -0
- package/dist/memory/candidate-retrieval.d.ts.map +1 -0
- package/dist/memory/candidate-retrieval.js +41 -0
- package/dist/memory/candidate-retrieval.js.map +1 -0
- package/dist/memory/causal-store.d.ts +97 -0
- package/dist/memory/causal-store.d.ts.map +1 -0
- package/dist/memory/causal-store.js +209 -0
- package/dist/memory/causal-store.js.map +1 -0
- package/dist/memory/coherence.d.ts +71 -0
- package/dist/memory/coherence.d.ts.map +1 -0
- package/dist/memory/coherence.js +176 -0
- package/dist/memory/coherence.js.map +1 -0
- package/dist/memory/experience.d.ts +39 -6
- package/dist/memory/experience.d.ts.map +1 -1
- package/dist/memory/experience.js +193 -49
- package/dist/memory/experience.js.map +1 -1
- package/dist/memory/graph-layers/base.d.ts +29 -0
- package/dist/memory/graph-layers/base.d.ts.map +1 -0
- package/dist/memory/graph-layers/base.js +143 -0
- package/dist/memory/graph-layers/base.js.map +1 -0
- package/dist/memory/graph-layers/causal.d.ts +14 -0
- package/dist/memory/graph-layers/causal.d.ts.map +1 -0
- package/dist/memory/graph-layers/causal.js +14 -0
- package/dist/memory/graph-layers/causal.js.map +1 -0
- package/dist/memory/graph-layers/entity.d.ts +14 -0
- package/dist/memory/graph-layers/entity.d.ts.map +1 -0
- package/dist/memory/graph-layers/entity.js +14 -0
- package/dist/memory/graph-layers/entity.js.map +1 -0
- package/dist/memory/graph-layers/index.d.ts +6 -0
- package/dist/memory/graph-layers/index.d.ts.map +1 -0
- package/dist/memory/graph-layers/index.js +6 -0
- package/dist/memory/graph-layers/index.js.map +1 -0
- package/dist/memory/graph-layers/semantic.d.ts +14 -0
- package/dist/memory/graph-layers/semantic.d.ts.map +1 -0
- package/dist/memory/graph-layers/semantic.js +14 -0
- package/dist/memory/graph-layers/semantic.js.map +1 -0
- package/dist/memory/graph-layers/temporal.d.ts +14 -0
- package/dist/memory/graph-layers/temporal.d.ts.map +1 -0
- package/dist/memory/graph-layers/temporal.js +14 -0
- package/dist/memory/graph-layers/temporal.js.map +1 -0
- package/dist/memory/index.d.ts +15 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +22 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/knowledge-bank.d.ts +234 -0
- package/dist/memory/knowledge-bank.d.ts.map +1 -0
- package/dist/memory/knowledge-bank.js +1048 -0
- package/dist/memory/knowledge-bank.js.map +1 -0
- package/dist/memory/knowledge-defrag.d.ts +49 -0
- package/dist/memory/knowledge-defrag.d.ts.map +1 -0
- package/dist/memory/knowledge-defrag.js +257 -0
- package/dist/memory/knowledge-defrag.js.map +1 -0
- package/dist/memory/knowledge-graph.d.ts +41 -0
- package/dist/memory/knowledge-graph.d.ts.map +1 -0
- package/dist/memory/knowledge-graph.js +273 -0
- package/dist/memory/knowledge-graph.js.map +1 -0
- package/dist/memory/meta.d.ts +7 -8
- package/dist/memory/meta.d.ts.map +1 -1
- package/dist/memory/meta.js +73 -79
- package/dist/memory/meta.js.map +1 -1
- package/dist/memory/playbook.d.ts +26 -9
- package/dist/memory/playbook.d.ts.map +1 -1
- package/dist/memory/playbook.js +198 -74
- package/dist/memory/playbook.js.map +1 -1
- package/dist/memory/reasoning-bank.d.ts +130 -0
- package/dist/memory/reasoning-bank.d.ts.map +1 -0
- package/dist/memory/reasoning-bank.js +342 -0
- package/dist/memory/reasoning-bank.js.map +1 -0
- package/dist/memory/reflexion.d.ts +59 -0
- package/dist/memory/reflexion.d.ts.map +1 -0
- package/dist/memory/reflexion.js +96 -0
- package/dist/memory/reflexion.js.map +1 -0
- package/dist/memory/search-provider.d.ts +31 -0
- package/dist/memory/search-provider.d.ts.map +1 -0
- package/dist/memory/search-provider.js +2 -0
- package/dist/memory/search-provider.js.map +1 -0
- package/dist/memory/search-providers/index.d.ts +3 -0
- package/dist/memory/search-providers/index.d.ts.map +1 -0
- package/dist/memory/search-providers/index.js +3 -0
- package/dist/memory/search-providers/index.js.map +1 -0
- package/dist/memory/search-providers/minimem.d.ts +43 -0
- package/dist/memory/search-providers/minimem.d.ts.map +1 -0
- package/dist/memory/search-providers/minimem.js +56 -0
- package/dist/memory/search-providers/minimem.js.map +1 -0
- package/dist/memory/search-providers/text-similarity.d.ts +15 -0
- package/dist/memory/search-providers/text-similarity.d.ts.map +1 -0
- package/dist/memory/search-providers/text-similarity.js +21 -0
- package/dist/memory/search-providers/text-similarity.js.map +1 -0
- package/dist/memory/skill-exporter.d.ts +75 -0
- package/dist/memory/skill-exporter.d.ts.map +1 -0
- package/dist/memory/skill-exporter.js +248 -0
- package/dist/memory/skill-exporter.js.map +1 -0
- package/dist/memory/system.d.ts +20 -3
- package/dist/memory/system.d.ts.map +1 -1
- package/dist/memory/system.js +61 -11
- package/dist/memory/system.js.map +1 -1
- package/dist/memory/team-experience.d.ts +298 -0
- package/dist/memory/team-experience.d.ts.map +1 -0
- package/dist/memory/team-experience.js +355 -0
- package/dist/memory/team-experience.js.map +1 -0
- package/dist/memory/temporal-compressor.d.ts +126 -0
- package/dist/memory/temporal-compressor.d.ts.map +1 -0
- package/dist/memory/temporal-compressor.js +335 -0
- package/dist/memory/temporal-compressor.js.map +1 -0
- package/dist/persistence/index.d.ts +11 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +11 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/migrator.d.ts +40 -0
- package/dist/persistence/migrator.d.ts.map +1 -0
- package/dist/persistence/migrator.js +238 -0
- package/dist/persistence/migrator.js.map +1 -0
- package/dist/persistence/serializers.d.ts +45 -0
- package/dist/persistence/serializers.d.ts.map +1 -0
- package/dist/persistence/serializers.js +80 -0
- package/dist/persistence/serializers.js.map +1 -0
- package/dist/persistence/sqlite-persistence.d.ts +228 -0
- package/dist/persistence/sqlite-persistence.d.ts.map +1 -0
- package/dist/persistence/sqlite-persistence.js +588 -0
- package/dist/persistence/sqlite-persistence.js.map +1 -0
- package/dist/runtime/backends/acp-protocol.d.ts +49 -0
- package/dist/runtime/backends/acp-protocol.d.ts.map +1 -0
- package/dist/runtime/backends/acp-protocol.js +166 -0
- package/dist/runtime/backends/acp-protocol.js.map +1 -0
- package/dist/runtime/backends/acp.d.ts +26 -26
- package/dist/runtime/backends/acp.d.ts.map +1 -1
- package/dist/runtime/backends/acp.js +32 -156
- package/dist/runtime/backends/acp.js.map +1 -1
- package/dist/runtime/backends/index.d.ts +3 -1
- package/dist/runtime/backends/index.d.ts.map +1 -1
- package/dist/runtime/backends/index.js +3 -1
- package/dist/runtime/backends/index.js.map +1 -1
- package/dist/runtime/backends/macro-agent.d.ts +104 -0
- package/dist/runtime/backends/macro-agent.d.ts.map +1 -0
- package/dist/runtime/backends/macro-agent.js +107 -0
- package/dist/runtime/backends/macro-agent.js.map +1 -0
- package/dist/runtime/compute-provider.d.ts +87 -0
- package/dist/runtime/compute-provider.d.ts.map +1 -0
- package/dist/runtime/compute-provider.js +87 -0
- package/dist/runtime/compute-provider.js.map +1 -0
- package/dist/runtime/flows/learning.d.ts +10 -12
- package/dist/runtime/flows/learning.d.ts.map +1 -1
- package/dist/runtime/flows/learning.js +10 -23
- package/dist/runtime/flows/learning.js.map +1 -1
- package/dist/runtime/index.d.ts +3 -2
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +3 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/manager.d.ts +37 -4
- package/dist/runtime/manager.d.ts.map +1 -1
- package/dist/runtime/manager.js +139 -20
- package/dist/runtime/manager.js.map +1 -1
- package/dist/runtime/types.d.ts +38 -0
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/search/evaluator.d.ts +7 -0
- package/dist/search/evaluator.d.ts.map +1 -1
- package/dist/search/evaluator.js +24 -4
- package/dist/search/evaluator.js.map +1 -1
- package/dist/search/index.d.ts +2 -0
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +4 -0
- package/dist/search/index.js.map +1 -1
- package/dist/search/moe-gate.d.ts +124 -0
- package/dist/search/moe-gate.d.ts.map +1 -0
- package/dist/search/moe-gate.js +234 -0
- package/dist/search/moe-gate.js.map +1 -0
- package/dist/search/refinement-loop.d.ts +17 -0
- package/dist/search/refinement-loop.d.ts.map +1 -1
- package/dist/search/refinement-loop.js +77 -6
- package/dist/search/refinement-loop.js.map +1 -1
- package/dist/search/refinement-types.d.ts +2 -2
- package/dist/search/router.d.ts +32 -2
- package/dist/search/router.d.ts.map +1 -1
- package/dist/search/router.js +87 -4
- package/dist/search/router.js.map +1 -1
- package/dist/search/team-router.d.ts +91 -0
- package/dist/search/team-router.d.ts.map +1 -0
- package/dist/search/team-router.js +315 -0
- package/dist/search/team-router.js.map +1 -0
- package/dist/session-bank/git-reader.d.ts +44 -0
- package/dist/session-bank/git-reader.d.ts.map +1 -0
- package/dist/session-bank/git-reader.js +172 -0
- package/dist/session-bank/git-reader.js.map +1 -0
- package/dist/session-bank/index.d.ts +5 -0
- package/dist/session-bank/index.d.ts.map +1 -0
- package/dist/session-bank/index.js +4 -0
- package/dist/session-bank/index.js.map +1 -0
- package/dist/session-bank/parser.d.ts +50 -0
- package/dist/session-bank/parser.d.ts.map +1 -0
- package/dist/session-bank/parser.js +338 -0
- package/dist/session-bank/parser.js.map +1 -0
- package/dist/session-bank/session-bank.d.ts +40 -0
- package/dist/session-bank/session-bank.d.ts.map +1 -0
- package/dist/session-bank/session-bank.js +347 -0
- package/dist/session-bank/session-bank.js.map +1 -0
- package/dist/session-bank/types.d.ts +132 -0
- package/dist/session-bank/types.d.ts.map +1 -0
- package/dist/session-bank/types.js +7 -0
- package/dist/session-bank/types.js.map +1 -0
- package/dist/surfacing/index.d.ts +4 -0
- package/dist/surfacing/index.d.ts.map +1 -1
- package/dist/surfacing/index.js +3 -0
- package/dist/surfacing/index.js.map +1 -1
- package/dist/surfacing/publisher.d.ts +22 -0
- package/dist/surfacing/publisher.d.ts.map +1 -0
- package/dist/surfacing/publisher.js +9 -0
- package/dist/surfacing/publisher.js.map +1 -0
- package/dist/surfacing/skill-library.d.ts +12 -0
- package/dist/surfacing/skill-library.d.ts.map +1 -1
- package/dist/surfacing/skill-library.js +26 -0
- package/dist/surfacing/skill-library.js.map +1 -1
- package/dist/surfacing/skill-publisher.d.ts +43 -0
- package/dist/surfacing/skill-publisher.d.ts.map +1 -0
- package/dist/surfacing/skill-publisher.js +169 -0
- package/dist/surfacing/skill-publisher.js.map +1 -0
- package/dist/surfacing/sqlite-storage-adapter.d.ts +42 -0
- package/dist/surfacing/sqlite-storage-adapter.d.ts.map +1 -0
- package/dist/surfacing/sqlite-storage-adapter.js +199 -0
- package/dist/surfacing/sqlite-storage-adapter.js.map +1 -0
- package/dist/surfacing/team-skill-library.d.ts +180 -0
- package/dist/surfacing/team-skill-library.d.ts.map +1 -0
- package/dist/surfacing/team-skill-library.js +384 -0
- package/dist/surfacing/team-skill-library.js.map +1 -0
- package/dist/types/config.d.ts +1318 -44
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +243 -0
- package/dist/types/config.js.map +1 -1
- package/dist/types/dataclaw.d.ts +286 -0
- package/dist/types/dataclaw.d.ts.map +1 -0
- package/dist/types/dataclaw.js +84 -0
- package/dist/types/dataclaw.js.map +1 -0
- package/dist/types/index.d.ts +9 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +13 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/knowledge-graph.d.ts +148 -0
- package/dist/types/knowledge-graph.d.ts.map +1 -0
- package/dist/types/knowledge-graph.js +40 -0
- package/dist/types/knowledge-graph.js.map +1 -0
- package/dist/types/knowledge.d.ts +280 -0
- package/dist/types/knowledge.d.ts.map +1 -0
- package/dist/types/knowledge.js +191 -0
- package/dist/types/knowledge.js.map +1 -0
- package/dist/types/memory.d.ts +52 -0
- package/dist/types/memory.d.ts.map +1 -1
- package/dist/types/memory.js +13 -0
- package/dist/types/memory.js.map +1 -1
- package/dist/types/playbook.d.ts +4 -0
- package/dist/types/playbook.d.ts.map +1 -1
- package/dist/types/playbook.js.map +1 -1
- package/dist/types/team-meta.d.ts +160 -0
- package/dist/types/team-meta.d.ts.map +1 -0
- package/dist/types/team-meta.js +42 -0
- package/dist/types/team-meta.js.map +1 -0
- package/dist/types/team-playbook.d.ts +276 -0
- package/dist/types/team-playbook.d.ts.map +1 -0
- package/dist/types/team-playbook.js +85 -0
- package/dist/types/team-playbook.js.map +1 -0
- package/dist/types/team-trajectory.d.ts +305 -0
- package/dist/types/team-trajectory.d.ts.map +1 -0
- package/dist/types/team-trajectory.js +304 -0
- package/dist/types/team-trajectory.js.map +1 -0
- package/dist/types/trajectory-source.d.ts +39 -0
- package/dist/types/trajectory-source.d.ts.map +1 -0
- package/dist/types/trajectory-source.js +2 -0
- package/dist/types/trajectory-source.js.map +1 -0
- package/dist/utils/error-classifier.d.ts +30 -0
- package/dist/utils/error-classifier.d.ts.map +1 -0
- package/dist/utils/error-classifier.js +85 -0
- package/dist/utils/error-classifier.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +34 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +93 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/partitioned-store.d.ts +93 -0
- package/dist/utils/partitioned-store.d.ts.map +1 -0
- package/dist/utils/partitioned-store.js +251 -0
- package/dist/utils/partitioned-store.js.map +1 -0
- package/dist/utils/trajectory-helpers.d.ts +39 -0
- package/dist/utils/trajectory-helpers.d.ts.map +1 -0
- package/dist/utils/trajectory-helpers.js +57 -0
- package/dist/utils/trajectory-helpers.js.map +1 -0
- package/dist/workspace/index.d.ts +6 -0
- package/dist/workspace/index.d.ts.map +1 -0
- package/dist/workspace/index.js +11 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/runner.d.ts +49 -0
- package/dist/workspace/runner.d.ts.map +1 -0
- package/dist/workspace/runner.js +219 -0
- package/dist/workspace/runner.js.map +1 -0
- package/dist/workspace/skill-converter.d.ts +18 -0
- package/dist/workspace/skill-converter.d.ts.map +1 -0
- package/dist/workspace/skill-converter.js +257 -0
- package/dist/workspace/skill-converter.js.map +1 -0
- package/dist/workspace/templates/index.d.ts +11 -0
- package/dist/workspace/templates/index.d.ts.map +1 -0
- package/dist/workspace/templates/index.js +21 -0
- package/dist/workspace/templates/index.js.map +1 -0
- package/dist/workspace/templates/knowledge-defrag.d.ts +25 -0
- package/dist/workspace/templates/knowledge-defrag.d.ts.map +1 -0
- package/dist/workspace/templates/knowledge-defrag.js +154 -0
- package/dist/workspace/templates/knowledge-defrag.js.map +1 -0
- package/dist/workspace/templates/knowledge-extraction.d.ts +25 -0
- package/dist/workspace/templates/knowledge-extraction.d.ts.map +1 -0
- package/dist/workspace/templates/knowledge-extraction.js +246 -0
- package/dist/workspace/templates/knowledge-extraction.js.map +1 -0
- package/dist/workspace/templates/meta-reflection.d.ts +47 -0
- package/dist/workspace/templates/meta-reflection.d.ts.map +1 -0
- package/dist/workspace/templates/meta-reflection.js +135 -0
- package/dist/workspace/templates/meta-reflection.js.map +1 -0
- package/dist/workspace/templates/playbook-extraction.d.ts +20 -0
- package/dist/workspace/templates/playbook-extraction.d.ts.map +1 -0
- package/dist/workspace/templates/playbook-extraction.js +189 -0
- package/dist/workspace/templates/playbook-extraction.js.map +1 -0
- package/dist/workspace/templates/refinement-analysis.d.ts +31 -0
- package/dist/workspace/templates/refinement-analysis.d.ts.map +1 -0
- package/dist/workspace/templates/refinement-analysis.js +107 -0
- package/dist/workspace/templates/refinement-analysis.js.map +1 -0
- package/dist/workspace/templates/solution-evaluation.d.ts +21 -0
- package/dist/workspace/templates/solution-evaluation.d.ts.map +1 -0
- package/dist/workspace/templates/solution-evaluation.js +131 -0
- package/dist/workspace/templates/solution-evaluation.js.map +1 -0
- package/dist/workspace/templates/team-playbook-extraction.d.ts +44 -0
- package/dist/workspace/templates/team-playbook-extraction.d.ts.map +1 -0
- package/dist/workspace/templates/team-playbook-extraction.js +497 -0
- package/dist/workspace/templates/team-playbook-extraction.js.map +1 -0
- package/dist/workspace/templates/team-trajectory-analysis.d.ts +19 -0
- package/dist/workspace/templates/team-trajectory-analysis.d.ts.map +1 -0
- package/dist/workspace/templates/team-trajectory-analysis.js +442 -0
- package/dist/workspace/templates/team-trajectory-analysis.js.map +1 -0
- package/dist/workspace/templates/trajectory-analysis.d.ts +19 -0
- package/dist/workspace/templates/trajectory-analysis.d.ts.map +1 -0
- package/dist/workspace/templates/trajectory-analysis.js +170 -0
- package/dist/workspace/templates/trajectory-analysis.js.map +1 -0
- package/dist/workspace/templates/usage-inference.d.ts +19 -0
- package/dist/workspace/templates/usage-inference.d.ts.map +1 -0
- package/dist/workspace/templates/usage-inference.js +125 -0
- package/dist/workspace/templates/usage-inference.js.map +1 -0
- package/dist/workspace/types.d.ts +152 -0
- package/dist/workspace/types.d.ts.map +1 -0
- package/dist/workspace/types.js +17 -0
- package/dist/workspace/types.js.map +1 -0
- package/docs/DESIGN-agentic-workspace.md +2057 -0
- package/docs/DESIGN-semantic-memory-knowledge-bank.md +1789 -0
- package/docs/DESIGN-session-bank.md +1134 -0
- package/docs/DESIGN-team-extraction-pipeline.md +1369 -0
- package/docs/PROPOSAL-team-aware-learning.md +1080 -0
- package/docs/RESEARCH-semantic-memory-knowledge-structures.md +517 -0
- package/docs/RESEARCH-team-trajectory-learning.md +553 -0
- package/gaps.md +204 -0
- package/package.json +27 -7
- package/references/agent-workspace/CLAUDE.md +74 -0
- package/references/agent-workspace/README.md +587 -0
- package/references/agent-workspace/media/banner.png +0 -0
- package/references/agent-workspace/package-lock.json +2061 -0
- package/references/agent-workspace/package.json +54 -0
- package/references/agent-workspace/src/handle.ts +122 -0
- package/references/agent-workspace/src/index.ts +32 -0
- package/references/agent-workspace/src/manager.ts +102 -0
- package/references/agent-workspace/src/readers/json.ts +71 -0
- package/references/agent-workspace/src/readers/markdown.ts +37 -0
- package/references/agent-workspace/src/readers/raw.ts +27 -0
- package/references/agent-workspace/src/types.ts +68 -0
- package/references/agent-workspace/src/validation.ts +93 -0
- package/references/agent-workspace/src/writers/json.ts +17 -0
- package/references/agent-workspace/src/writers/markdown.ts +27 -0
- package/references/agent-workspace/src/writers/raw.ts +22 -0
- package/references/agent-workspace/tests/errors.test.ts +652 -0
- package/references/agent-workspace/tests/handle.test.ts +144 -0
- package/references/agent-workspace/tests/manager.test.ts +124 -0
- package/references/agent-workspace/tests/readers.test.ts +205 -0
- package/references/agent-workspace/tests/validation.test.ts +196 -0
- package/references/agent-workspace/tests/writers.test.ts +108 -0
- package/references/agent-workspace/tsconfig.json +20 -0
- package/references/agent-workspace/tsup.config.ts +9 -0
- package/references/minimem/.claude/settings.json +7 -0
- package/references/minimem/.sudocode/issues.jsonl +18 -0
- package/references/minimem/.sudocode/specs.jsonl +1 -0
- package/references/minimem/CLAUDE.md +310 -0
- package/references/minimem/README.md +556 -0
- package/references/minimem/claude-plugin/.claude-plugin/plugin.json +10 -0
- package/references/minimem/claude-plugin/.mcp.json +7 -0
- package/references/minimem/claude-plugin/README.md +158 -0
- package/references/minimem/claude-plugin/commands/recall.md +47 -0
- package/references/minimem/claude-plugin/commands/remember.md +41 -0
- package/references/minimem/claude-plugin/hooks/__tests__/hooks.test.ts +272 -0
- package/references/minimem/claude-plugin/hooks/hooks.json +27 -0
- package/references/minimem/claude-plugin/hooks/session-end.sh +86 -0
- package/references/minimem/claude-plugin/hooks/session-start.sh +85 -0
- package/references/minimem/claude-plugin/skills/memory/SKILL.md +108 -0
- package/references/minimem/package-lock.json +5373 -0
- package/references/minimem/package.json +60 -0
- package/references/minimem/scripts/postbuild.js +35 -0
- package/references/minimem/src/__tests__/edge-cases.test.ts +371 -0
- package/references/minimem/src/__tests__/errors.test.ts +265 -0
- package/references/minimem/src/__tests__/helpers.ts +199 -0
- package/references/minimem/src/__tests__/internal.test.ts +407 -0
- package/references/minimem/src/__tests__/knowledge.test.ts +287 -0
- package/references/minimem/src/__tests__/minimem.integration.test.ts +1127 -0
- package/references/minimem/src/__tests__/session.test.ts +190 -0
- package/references/minimem/src/cli/__tests__/commands.test.ts +759 -0
- package/references/minimem/src/cli/commands/__tests__/conflicts.test.ts +141 -0
- package/references/minimem/src/cli/commands/append.ts +76 -0
- package/references/minimem/src/cli/commands/config.ts +262 -0
- package/references/minimem/src/cli/commands/conflicts.ts +413 -0
- package/references/minimem/src/cli/commands/daemon.ts +169 -0
- package/references/minimem/src/cli/commands/index.ts +12 -0
- package/references/minimem/src/cli/commands/init.ts +88 -0
- package/references/minimem/src/cli/commands/mcp.ts +177 -0
- package/references/minimem/src/cli/commands/push-pull.ts +213 -0
- package/references/minimem/src/cli/commands/search.ts +158 -0
- package/references/minimem/src/cli/commands/status.ts +84 -0
- package/references/minimem/src/cli/commands/sync-init.ts +290 -0
- package/references/minimem/src/cli/commands/sync.ts +70 -0
- package/references/minimem/src/cli/commands/upsert.ts +197 -0
- package/references/minimem/src/cli/config.ts +584 -0
- package/references/minimem/src/cli/index.ts +264 -0
- package/references/minimem/src/cli/shared.ts +161 -0
- package/references/minimem/src/cli/sync/__tests__/central.test.ts +152 -0
- package/references/minimem/src/cli/sync/__tests__/conflicts.test.ts +209 -0
- package/references/minimem/src/cli/sync/__tests__/daemon.test.ts +118 -0
- package/references/minimem/src/cli/sync/__tests__/detection.test.ts +207 -0
- package/references/minimem/src/cli/sync/__tests__/integration.test.ts +476 -0
- package/references/minimem/src/cli/sync/__tests__/registry.test.ts +363 -0
- package/references/minimem/src/cli/sync/__tests__/state.test.ts +255 -0
- package/references/minimem/src/cli/sync/__tests__/validation.test.ts +193 -0
- package/references/minimem/src/cli/sync/__tests__/watcher.test.ts +178 -0
- package/references/minimem/src/cli/sync/central.ts +292 -0
- package/references/minimem/src/cli/sync/conflicts.ts +204 -0
- package/references/minimem/src/cli/sync/daemon.ts +407 -0
- package/references/minimem/src/cli/sync/detection.ts +138 -0
- package/references/minimem/src/cli/sync/index.ts +107 -0
- package/references/minimem/src/cli/sync/operations.ts +373 -0
- package/references/minimem/src/cli/sync/registry.ts +279 -0
- package/references/minimem/src/cli/sync/state.ts +355 -0
- package/references/minimem/src/cli/sync/validation.ts +206 -0
- package/references/minimem/src/cli/sync/watcher.ts +234 -0
- package/references/minimem/src/cli/version.ts +34 -0
- package/references/minimem/src/core/index.ts +9 -0
- package/references/minimem/src/core/indexer.ts +628 -0
- package/references/minimem/src/core/searcher.ts +221 -0
- package/references/minimem/src/db/schema.ts +183 -0
- package/references/minimem/src/db/sqlite-vec.ts +24 -0
- package/references/minimem/src/embeddings/__tests__/embeddings.test.ts +431 -0
- package/references/minimem/src/embeddings/batch-gemini.ts +392 -0
- package/references/minimem/src/embeddings/batch-openai.ts +409 -0
- package/references/minimem/src/embeddings/embeddings.ts +434 -0
- package/references/minimem/src/index.ts +109 -0
- package/references/minimem/src/internal.ts +299 -0
- package/references/minimem/src/minimem.ts +1276 -0
- package/references/minimem/src/search/__tests__/hybrid.test.ts +247 -0
- package/references/minimem/src/search/graph.ts +234 -0
- package/references/minimem/src/search/hybrid.ts +151 -0
- package/references/minimem/src/search/search.ts +256 -0
- package/references/minimem/src/server/__tests__/mcp.test.ts +341 -0
- package/references/minimem/src/server/__tests__/tools.test.ts +364 -0
- package/references/minimem/src/server/mcp.ts +326 -0
- package/references/minimem/src/server/tools.ts +720 -0
- package/references/minimem/src/session.ts +460 -0
- package/references/minimem/tsconfig.json +19 -0
- package/references/minimem/tsup.config.ts +26 -0
- package/references/minimem/vitest.config.ts +24 -0
- package/references/sessionlog/.husky/pre-commit +1 -0
- package/references/sessionlog/.lintstagedrc.json +4 -0
- package/references/sessionlog/.prettierignore +4 -0
- package/references/sessionlog/.prettierrc.json +11 -0
- package/references/sessionlog/LICENSE +21 -0
- package/references/sessionlog/README.md +453 -0
- package/references/sessionlog/eslint.config.js +58 -0
- package/references/sessionlog/package-lock.json +3672 -0
- package/references/sessionlog/package.json +65 -0
- package/references/sessionlog/src/__tests__/agent-hooks.test.ts +570 -0
- package/references/sessionlog/src/__tests__/agent-registry.test.ts +127 -0
- package/references/sessionlog/src/__tests__/claude-code-hooks.test.ts +225 -0
- package/references/sessionlog/src/__tests__/claude-generator.test.ts +46 -0
- package/references/sessionlog/src/__tests__/commit-msg.test.ts +86 -0
- package/references/sessionlog/src/__tests__/cursor-agent.test.ts +224 -0
- package/references/sessionlog/src/__tests__/e2e-live.test.ts +890 -0
- package/references/sessionlog/src/__tests__/event-log.test.ts +183 -0
- package/references/sessionlog/src/__tests__/flush-sentinel.test.ts +105 -0
- package/references/sessionlog/src/__tests__/gemini-agent.test.ts +375 -0
- package/references/sessionlog/src/__tests__/git-hooks.test.ts +78 -0
- package/references/sessionlog/src/__tests__/hook-managers.test.ts +121 -0
- package/references/sessionlog/src/__tests__/lifecycle-tasks.test.ts +759 -0
- package/references/sessionlog/src/__tests__/opencode-agent.test.ts +338 -0
- package/references/sessionlog/src/__tests__/redaction.test.ts +136 -0
- package/references/sessionlog/src/__tests__/session-repo.test.ts +353 -0
- package/references/sessionlog/src/__tests__/session-store.test.ts +166 -0
- package/references/sessionlog/src/__tests__/setup-ccweb.test.ts +466 -0
- package/references/sessionlog/src/__tests__/skill-live.test.ts +461 -0
- package/references/sessionlog/src/__tests__/summarize.test.ts +348 -0
- package/references/sessionlog/src/__tests__/task-plan-e2e.test.ts +610 -0
- package/references/sessionlog/src/__tests__/task-plan-live.test.ts +632 -0
- package/references/sessionlog/src/__tests__/transcript-timestamp.test.ts +121 -0
- package/references/sessionlog/src/__tests__/types.test.ts +166 -0
- package/references/sessionlog/src/__tests__/utils.test.ts +333 -0
- package/references/sessionlog/src/__tests__/validation.test.ts +103 -0
- package/references/sessionlog/src/__tests__/worktree.test.ts +57 -0
- package/references/sessionlog/src/agent/agents/claude-code.ts +1089 -0
- package/references/sessionlog/src/agent/agents/cursor.ts +361 -0
- package/references/sessionlog/src/agent/agents/gemini-cli.ts +632 -0
- package/references/sessionlog/src/agent/agents/opencode.ts +540 -0
- package/references/sessionlog/src/agent/registry.ts +143 -0
- package/references/sessionlog/src/agent/session-types.ts +113 -0
- package/references/sessionlog/src/agent/types.ts +220 -0
- package/references/sessionlog/src/cli.ts +597 -0
- package/references/sessionlog/src/commands/clean.ts +133 -0
- package/references/sessionlog/src/commands/disable.ts +84 -0
- package/references/sessionlog/src/commands/doctor.ts +145 -0
- package/references/sessionlog/src/commands/enable.ts +202 -0
- package/references/sessionlog/src/commands/explain.ts +261 -0
- package/references/sessionlog/src/commands/reset.ts +105 -0
- package/references/sessionlog/src/commands/resume.ts +180 -0
- package/references/sessionlog/src/commands/rewind.ts +195 -0
- package/references/sessionlog/src/commands/setup-ccweb.ts +275 -0
- package/references/sessionlog/src/commands/status.ts +172 -0
- package/references/sessionlog/src/config.ts +165 -0
- package/references/sessionlog/src/events/event-log.ts +126 -0
- package/references/sessionlog/src/git-operations.ts +558 -0
- package/references/sessionlog/src/hooks/git-hooks.ts +165 -0
- package/references/sessionlog/src/hooks/lifecycle.ts +391 -0
- package/references/sessionlog/src/index.ts +650 -0
- package/references/sessionlog/src/security/redaction.ts +283 -0
- package/references/sessionlog/src/session/state-machine.ts +452 -0
- package/references/sessionlog/src/store/checkpoint-store.ts +509 -0
- package/references/sessionlog/src/store/native-store.ts +173 -0
- package/references/sessionlog/src/store/provider-types.ts +99 -0
- package/references/sessionlog/src/store/session-store.ts +266 -0
- package/references/sessionlog/src/strategy/attribution.ts +296 -0
- package/references/sessionlog/src/strategy/common.ts +207 -0
- package/references/sessionlog/src/strategy/content-overlap.ts +228 -0
- package/references/sessionlog/src/strategy/manual-commit.ts +988 -0
- package/references/sessionlog/src/strategy/types.ts +279 -0
- package/references/sessionlog/src/summarize/claude-generator.ts +115 -0
- package/references/sessionlog/src/summarize/summarize.ts +432 -0
- package/references/sessionlog/src/types.ts +508 -0
- package/references/sessionlog/src/utils/chunk-files.ts +49 -0
- package/references/sessionlog/src/utils/commit-message.ts +65 -0
- package/references/sessionlog/src/utils/detect-agent.ts +36 -0
- package/references/sessionlog/src/utils/hook-managers.ts +125 -0
- package/references/sessionlog/src/utils/ide-tags.ts +32 -0
- package/references/sessionlog/src/utils/paths.ts +79 -0
- package/references/sessionlog/src/utils/preview-rewind.ts +80 -0
- package/references/sessionlog/src/utils/rewind-conflict.ts +121 -0
- package/references/sessionlog/src/utils/shadow-branch.ts +109 -0
- package/references/sessionlog/src/utils/string-utils.ts +46 -0
- package/references/sessionlog/src/utils/todo-extract.ts +188 -0
- package/references/sessionlog/src/utils/trailers.ts +187 -0
- package/references/sessionlog/src/utils/transcript-parse.ts +177 -0
- package/references/sessionlog/src/utils/transcript-timestamp.ts +59 -0
- package/references/sessionlog/src/utils/tree-ops.ts +219 -0
- package/references/sessionlog/src/utils/tty.ts +72 -0
- package/references/sessionlog/src/utils/validation.ts +65 -0
- package/references/sessionlog/src/utils/worktree.ts +58 -0
- package/references/sessionlog/src/wire-types.ts +59 -0
- package/references/sessionlog/templates/setup-env.sh +153 -0
- package/references/sessionlog/tsconfig.json +18 -0
- package/references/sessionlog/vitest.config.ts +12 -0
- package/references/skill-tree/.claude/settings.json +6 -0
- package/references/skill-tree/.sudocode/issues.jsonl +19 -0
- package/references/skill-tree/.sudocode/specs.jsonl +3 -0
- package/references/skill-tree/CLAUDE.md +126 -0
- package/references/skill-tree/README.md +372 -0
- package/references/skill-tree/docs/GAPS_v1.md +221 -0
- package/references/skill-tree/docs/INTEGRATION_PLAN.md +467 -0
- package/references/skill-tree/docs/TODOS.md +91 -0
- package/references/skill-tree/docs/anthropic_skill_guide.md +1364 -0
- package/references/skill-tree/docs/design/federated-skill-trees.md +524 -0
- package/references/skill-tree/docs/design/multi-agent-sync.md +759 -0
- package/references/skill-tree/docs/scraper/BRAINSTORM.md +583 -0
- package/references/skill-tree/docs/scraper/POC_PLAN.md +420 -0
- package/references/skill-tree/docs/scraper/README.md +170 -0
- package/references/skill-tree/examples/basic-usage.ts +164 -0
- package/references/skill-tree/package-lock.json +1852 -0
- package/references/skill-tree/package.json +66 -0
- package/references/skill-tree/scraper/README.md +123 -0
- package/references/skill-tree/scraper/docs/DESIGN.md +683 -0
- package/references/skill-tree/scraper/docs/PLAN.md +336 -0
- package/references/skill-tree/scraper/drizzle.config.ts +10 -0
- package/references/skill-tree/scraper/package-lock.json +6329 -0
- package/references/skill-tree/scraper/package.json +68 -0
- package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-description.md +7 -0
- package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-name.md +7 -0
- package/references/skill-tree/scraper/test/fixtures/minimal-skill/SKILL.md +27 -0
- package/references/skill-tree/scraper/test/fixtures/skill-json/SKILL.json +21 -0
- package/references/skill-tree/scraper/test/fixtures/skill-with-meta/SKILL.md +54 -0
- package/references/skill-tree/scraper/test/fixtures/skill-with-meta/_meta.json +24 -0
- package/references/skill-tree/scraper/test/fixtures/valid-skill/SKILL.md +93 -0
- package/references/skill-tree/scraper/test/fixtures/valid-skill/_meta.json +22 -0
- package/references/skill-tree/scraper/tsup.config.ts +14 -0
- package/references/skill-tree/scraper/vitest.config.ts +17 -0
- package/references/skill-tree/scripts/convert-to-vitest.ts +166 -0
- package/references/skill-tree/skills/skill-writer/SKILL.md +339 -0
- package/references/skill-tree/skills/skill-writer/references/examples.md +326 -0
- package/references/skill-tree/skills/skill-writer/references/patterns.md +210 -0
- package/references/skill-tree/skills/skill-writer/references/quality-checklist.md +123 -0
- package/references/skill-tree/test/run-all.ts +106 -0
- package/references/skill-tree/test/utils.ts +128 -0
- package/references/skill-tree/vitest.config.ts +16 -0
- package/src/atlas.ts +583 -41
- package/src/bin/cli-utils.ts +220 -0
- package/src/bin/cognitive-core.ts +84 -392
- package/src/bin/commands/kb.ts +266 -0
- package/src/bin/commands/learn.ts +100 -0
- package/src/bin/commands/legacy.ts +182 -0
- package/src/bin/commands/run.ts +113 -0
- package/src/bin/commands/sessions.ts +221 -0
- package/src/bin/commands/skills.ts +146 -0
- package/src/embeddings/index.ts +3 -0
- package/src/embeddings/inverted-index.ts +134 -0
- package/src/embeddings/manager.ts +13 -8
- package/src/embeddings/provider.ts +10 -3
- package/src/embeddings/vector-store.ts +21 -9
- package/src/factory.ts +33 -16
- package/src/index.ts +231 -9
- package/src/learning/analyzer.ts +21 -37
- package/src/learning/energy-evaluator.ts +282 -0
- package/src/learning/healing-orchestrator.ts +383 -0
- package/src/learning/index.ts +104 -13
- package/src/learning/instant-loop.ts +357 -0
- package/src/learning/knowledge-extractor.ts +470 -0
- package/src/learning/maintenance-scheduler.ts +271 -0
- package/src/learning/meta-learner.ts +59 -23
- package/src/learning/reflexion-generator.ts +273 -0
- package/src/learning/team-ingester.ts +499 -0
- package/src/learning/team-meta-learner.ts +558 -0
- package/src/learning/team-pipeline.ts +364 -0
- package/src/learning/trajectory-sources/dataclaw.ts +403 -0
- package/src/learning/trajectory-sources/entire.ts +251 -0
- package/src/learning/trajectory-sources/file.ts +136 -0
- package/src/learning/trajectory-sources/huggingface.ts +248 -0
- package/src/learning/trajectory-sources/in-memory.ts +61 -0
- package/src/learning/trajectory-sources/index.ts +15 -0
- package/src/learning/trajectory-sources/pipeline.ts +69 -0
- package/src/learning/unified-pipeline.ts +921 -0
- package/src/memory/candidate-retrieval.ts +71 -0
- package/src/memory/causal-store.ts +273 -0
- package/src/memory/coherence.ts +252 -0
- package/src/memory/experience.ts +217 -50
- package/src/memory/graph-layers/base.ts +184 -0
- package/src/memory/graph-layers/causal.ts +16 -0
- package/src/memory/graph-layers/entity.ts +16 -0
- package/src/memory/graph-layers/index.ts +5 -0
- package/src/memory/graph-layers/semantic.ts +16 -0
- package/src/memory/graph-layers/temporal.ts +16 -0
- package/src/memory/index.ts +88 -0
- package/src/memory/knowledge-bank.ts +1317 -0
- package/src/memory/knowledge-defrag.ts +329 -0
- package/src/memory/knowledge-graph.ts +361 -0
- package/src/memory/meta.ts +78 -96
- package/src/memory/playbook.ts +239 -75
- package/src/memory/reasoning-bank.ts +458 -0
- package/src/memory/reflexion.ts +122 -0
- package/src/memory/search-provider.ts +35 -0
- package/src/memory/search-providers/index.ts +3 -0
- package/src/memory/search-providers/minimem.ts +84 -0
- package/src/memory/search-providers/text-similarity.ts +35 -0
- package/src/memory/skill-exporter.ts +357 -0
- package/src/memory/system.ts +80 -11
- package/src/memory/team-experience.ts +604 -0
- package/src/memory/temporal-compressor.ts +409 -0
- package/src/persistence/index.ts +37 -0
- package/src/persistence/migrator.ts +298 -0
- package/src/persistence/serializers.ts +79 -0
- package/src/persistence/sqlite-persistence.ts +925 -0
- package/src/runtime/backends/acp-protocol.ts +231 -0
- package/src/runtime/backends/acp.ts +57 -196
- package/src/runtime/backends/index.ts +14 -0
- package/src/runtime/backends/macro-agent.ts +177 -0
- package/src/runtime/compute-provider.ts +206 -0
- package/src/runtime/flows/learning.ts +25 -42
- package/src/runtime/index.ts +22 -0
- package/src/runtime/manager.ts +167 -23
- package/src/runtime/types.ts +41 -0
- package/src/search/evaluator.ts +29 -4
- package/src/search/index.ts +19 -0
- package/src/search/moe-gate.ts +304 -0
- package/src/search/refinement-loop.ts +106 -12
- package/src/search/router.ts +111 -4
- package/src/search/team-router.ts +459 -0
- package/src/session-bank/git-reader.ts +200 -0
- package/src/session-bank/index.ts +26 -0
- package/src/session-bank/parser.ts +548 -0
- package/src/session-bank/session-bank.ts +485 -0
- package/src/session-bank/types.ts +176 -0
- package/src/surfacing/index.ts +23 -0
- package/src/surfacing/publisher.ts +23 -0
- package/src/surfacing/skill-library.ts +31 -0
- package/src/surfacing/skill-publisher.ts +191 -0
- package/src/surfacing/sqlite-storage-adapter.ts +285 -0
- package/src/surfacing/team-skill-library.ts +610 -0
- package/src/types/config.ts +282 -0
- package/src/types/dataclaw.ts +99 -0
- package/src/types/huggingface-transformers.d.ts +12 -0
- package/src/types/index.ts +159 -0
- package/src/types/knowledge-graph.ts +246 -0
- package/src/types/knowledge.ts +388 -0
- package/src/types/memory.ts +30 -0
- package/src/types/playbook.ts +4 -0
- package/src/types/team-meta.ts +212 -0
- package/src/types/team-playbook.ts +384 -0
- package/src/types/team-trajectory.ts +673 -0
- package/src/types/trajectory-source.ts +47 -0
- package/src/utils/error-classifier.ts +113 -0
- package/src/utils/frontmatter.ts +118 -0
- package/src/utils/index.ts +25 -0
- package/src/utils/partitioned-store.ts +299 -0
- package/src/utils/trajectory-helpers.ts +79 -0
- package/src/workspace/index.ts +48 -0
- package/src/workspace/runner.ts +281 -0
- package/src/workspace/skill-converter.ts +288 -0
- package/src/workspace/templates/index.ts +64 -0
- package/src/workspace/templates/knowledge-defrag.ts +223 -0
- package/src/workspace/templates/knowledge-extraction.ts +337 -0
- package/src/workspace/templates/meta-reflection.ts +208 -0
- package/src/workspace/templates/playbook-extraction.ts +240 -0
- package/src/workspace/templates/refinement-analysis.ts +162 -0
- package/src/workspace/templates/solution-evaluation.ts +199 -0
- package/src/workspace/templates/team-playbook-extraction.ts +631 -0
- package/src/workspace/templates/team-trajectory-analysis.ts +564 -0
- package/src/workspace/templates/trajectory-analysis.ts +234 -0
- package/src/workspace/templates/usage-inference.ts +163 -0
- package/src/workspace/types.ts +241 -0
- package/tests/atlas-knowledge.test.ts +165 -0
- package/tests/embeddings/inverted-index.test.ts +138 -0
- package/tests/feature-toggles.test.ts +275 -0
- package/tests/gap-fixes.test.ts +1116 -0
- package/tests/integration/cli-e2e.test.ts +621 -0
- package/tests/integration/dataclaw-e2e.test.ts +559 -0
- package/tests/integration/e2e.test.ts +412 -4
- package/tests/integration/entire-e2e.test.ts +376 -0
- package/tests/integration/huggingface-e2e.test.ts +627 -0
- package/tests/integration/persistence-e2e.test.ts +741 -0
- package/tests/integration/phase-e2e.test.ts +1143 -0
- package/tests/integration/session-bank.test.ts +231 -0
- package/tests/integration/sessionlog-e2e.test.ts +329 -0
- package/tests/integration/skill-tree-wiring.test.ts +152 -0
- package/tests/integration/unified-pipeline-e2e.test.ts +634 -0
- package/tests/learning/analyzer.test.ts +1 -1
- package/tests/learning/dataclaw-trajectory-source.test.ts +642 -0
- package/tests/learning/energy-evaluator.test.ts +180 -0
- package/tests/learning/entire-trajectory-source.test.ts +380 -0
- package/tests/learning/healing-orchestrator.test.ts +269 -0
- package/tests/learning/huggingface-trajectory-source.test.ts +817 -0
- package/tests/learning/instant-loop.test.ts +243 -0
- package/tests/learning/knowledge-extractor.test.ts +491 -0
- package/tests/learning/maintenance-scheduler.test.ts +191 -0
- package/tests/learning/reflexion-generator.test.ts +411 -0
- package/tests/learning/team-ingester.test.ts +349 -0
- package/tests/learning/team-meta-learner.test.ts +618 -0
- package/tests/learning/team-pipeline.test.ts +334 -0
- package/tests/learning/trajectory-sources.test.ts +320 -0
- package/tests/learning/unified-pipeline.test.ts +322 -0
- package/tests/mcp/playbook-server.test.ts +6 -1
- package/tests/memory/causal-store.test.ts +276 -0
- package/tests/memory/coherence.test.ts +232 -0
- package/tests/memory/experience.test.ts +8 -3
- package/tests/memory/graph-layers/semantic.test.ts +219 -0
- package/tests/memory/knowledge-bank-extraction.test.ts +558 -0
- package/tests/memory/knowledge-bank.test.ts +705 -0
- package/tests/memory/knowledge-defrag.test.ts +366 -0
- package/tests/memory/knowledge-evolution.test.ts +563 -0
- package/tests/memory/knowledge-graph.test.ts +492 -0
- package/tests/memory/knowledge-inbox.test.ts +258 -0
- package/tests/memory/knowledge-minimem.test.ts +251 -0
- package/tests/memory/playbook.test.ts +307 -1
- package/tests/memory/provenance.test.ts +11 -2
- package/tests/memory/reasoning-bank.test.ts +239 -0
- package/tests/memory/reflexion.test.ts +166 -0
- package/tests/memory/skill-exporter.test.ts +475 -0
- package/tests/memory/system.test.ts +6 -1
- package/tests/memory/team-experience.test.ts +411 -0
- package/tests/memory/temporal-compressor.test.ts +318 -0
- package/tests/persistence/migrator.test.ts +1009 -0
- package/tests/persistence/sqlite-persistence.test.ts +635 -0
- package/tests/runtime/agent-manager.test.ts +7 -2
- package/tests/runtime/compute-provider.test.ts +288 -0
- package/tests/runtime/delegate.test.ts +354 -0
- package/tests/runtime/macro-agent-backend.test.ts +266 -0
- package/tests/search/moe-gate.test.ts +250 -0
- package/tests/search/refinement-loop.test.ts +11 -2
- package/tests/search/router.test.ts +81 -2
- package/tests/search/team-router.test.ts +376 -0
- package/tests/session-bank/fixtures/multi-tool-session/full.jsonl +12 -0
- package/tests/session-bank/fixtures/multi-tool-session/metadata.json +28 -0
- package/tests/session-bank/fixtures/root-metadata.json +18 -0
- package/tests/session-bank/fixtures/sessionlog-root-metadata.json +16 -0
- package/tests/session-bank/fixtures/sessionlog-session/full.jsonl +6 -0
- package/tests/session-bank/fixtures/sessionlog-session/metadata.json +55 -0
- package/tests/session-bank/fixtures/simple-session/full.jsonl +6 -0
- package/tests/session-bank/fixtures/simple-session/metadata.json +38 -0
- package/tests/session-bank/git-reader.test.ts +232 -0
- package/tests/session-bank/parser.test.ts +453 -0
- package/tests/session-bank/session-bank.test.ts +546 -0
- package/tests/surfacing/skill-library.test.ts +6 -1
- package/tests/surfacing/skill-publisher.test.ts +364 -0
- package/tests/surfacing/sqlite-storage-adapter.test.ts +206 -0
- package/tests/surfacing/team-skill-library.test.ts +444 -0
- package/tests/types/team-meta.test.ts +147 -0
- package/tests/types/team-playbook.test.ts +246 -0
- package/tests/types/team-trajectory.test.ts +557 -0
- package/tests/utils/frontmatter.test.ts +208 -0
- package/tests/utils/partitioned-store.test.ts +230 -0
- package/tests/workspace/full-flow.test.ts +845 -0
- package/tests/workspace/manager.test.ts +215 -0
- package/tests/workspace/runner.test.ts +336 -0
- package/tests/workspace/skill-converter.test.ts +205 -0
- package/tests/workspace/templates/knowledge-extraction.test.ts +235 -0
- package/tests/workspace/templates/team-playbook-extraction.test.ts +341 -0
- package/tests/workspace/templates/team-trajectory-analysis.test.ts +417 -0
- package/src/learning/llm-extractor.ts +0 -542
- package/src/learning/pipeline.ts +0 -244
- package/tests/learning/pipeline.test.ts +0 -176
|
@@ -0,0 +1,1048 @@
|
|
|
1
|
+
import { readFile, writeFile, readdir, mkdir, unlink, access } from 'node:fs/promises';
|
|
2
|
+
import { join, relative } from 'node:path';
|
|
3
|
+
import { inferLayerFromRelation, createObservation } from '../types/knowledge.js';
|
|
4
|
+
import { KnowledgeGraphManager } from './knowledge-graph.js';
|
|
5
|
+
import { CoherenceChecker } from './coherence.js';
|
|
6
|
+
import { parseKnowledgeNote, serializeKnowledgeNote, } from '../utils/frontmatter.js';
|
|
7
|
+
import { TextSimilaritySearchProvider } from './search-providers/text-similarity.js';
|
|
8
|
+
/**
|
|
9
|
+
* KnowledgeBank — Semantic memory store for facts, concepts, and relationships.
|
|
10
|
+
*
|
|
11
|
+
* Uses the filesystem as the universal primary index (minimem-compatible).
|
|
12
|
+
* Maintains a multi-layer graph overlay as a derived index for relationship queries.
|
|
13
|
+
*
|
|
14
|
+
* Directory structure:
|
|
15
|
+
* {memoryDir}/
|
|
16
|
+
* knowledge/
|
|
17
|
+
* observations/ — atomic facts (k-*.md)
|
|
18
|
+
* entities/ — living entity docs ({entity}.md)
|
|
19
|
+
* domains/ — domain summaries ({domain}.md)
|
|
20
|
+
* inbox/ — unorganized agent-authored notes
|
|
21
|
+
* .knowledge/ — derived index files (graph, manifest)
|
|
22
|
+
*/
|
|
23
|
+
export class KnowledgeBank {
|
|
24
|
+
graph;
|
|
25
|
+
memoryDir;
|
|
26
|
+
bankConfig;
|
|
27
|
+
initialized = false;
|
|
28
|
+
searchProvider = new TextSimilaritySearchProvider();
|
|
29
|
+
coherenceChecker = new CoherenceChecker();
|
|
30
|
+
// Directory paths (resolved on init)
|
|
31
|
+
observationsDir = '';
|
|
32
|
+
entitiesDir = '';
|
|
33
|
+
domainsDir = '';
|
|
34
|
+
inboxDir = '';
|
|
35
|
+
indexDir = '';
|
|
36
|
+
constructor(memoryDir, config) {
|
|
37
|
+
this.memoryDir = memoryDir;
|
|
38
|
+
this.bankConfig = config;
|
|
39
|
+
this.graph = new KnowledgeGraphManager(this.bankConfig.graph);
|
|
40
|
+
}
|
|
41
|
+
// =========================================================================
|
|
42
|
+
// Lifecycle
|
|
43
|
+
// =========================================================================
|
|
44
|
+
async init() {
|
|
45
|
+
if (this.initialized)
|
|
46
|
+
return;
|
|
47
|
+
// Resolve directory paths.
|
|
48
|
+
// When minimemAware, nest under memory/knowledge/ so paths align with
|
|
49
|
+
// minimem's directory layout; otherwise use the original knowledge/ root.
|
|
50
|
+
const knowledgeBase = this.bankConfig.minimemAware
|
|
51
|
+
? join(this.memoryDir, 'memory', 'knowledge')
|
|
52
|
+
: join(this.memoryDir, 'knowledge');
|
|
53
|
+
this.observationsDir = join(knowledgeBase, 'observations');
|
|
54
|
+
this.entitiesDir = join(knowledgeBase, 'entities');
|
|
55
|
+
this.domainsDir = join(knowledgeBase, 'domains');
|
|
56
|
+
this.inboxDir = join(this.memoryDir, 'inbox');
|
|
57
|
+
this.indexDir = join(this.memoryDir, '.knowledge');
|
|
58
|
+
// Create directory structure
|
|
59
|
+
await Promise.all([
|
|
60
|
+
mkdir(this.observationsDir, { recursive: true }),
|
|
61
|
+
mkdir(this.entitiesDir, { recursive: true }),
|
|
62
|
+
mkdir(this.domainsDir, { recursive: true }),
|
|
63
|
+
mkdir(this.inboxDir, { recursive: true }),
|
|
64
|
+
mkdir(this.indexDir, { recursive: true }),
|
|
65
|
+
]);
|
|
66
|
+
// Load graph from disk
|
|
67
|
+
await this.graph.loadFromDisk(this.indexDir);
|
|
68
|
+
// Detect minimem and swap search provider if available
|
|
69
|
+
if (this.bankConfig.minimemAware) {
|
|
70
|
+
await this.detectMinimem();
|
|
71
|
+
}
|
|
72
|
+
this.initialized = true;
|
|
73
|
+
}
|
|
74
|
+
async close() {
|
|
75
|
+
if (!this.initialized)
|
|
76
|
+
return;
|
|
77
|
+
await this.graph.saveToDisk(this.indexDir);
|
|
78
|
+
}
|
|
79
|
+
// =========================================================================
|
|
80
|
+
// Write Operations
|
|
81
|
+
// =========================================================================
|
|
82
|
+
/**
|
|
83
|
+
* Create a new knowledge note and write it to disk.
|
|
84
|
+
* Runs coherence checking against existing notes — contradictions are flagged
|
|
85
|
+
* via metadata but the note is still stored.
|
|
86
|
+
* Updates the graph overlay in memory.
|
|
87
|
+
*/
|
|
88
|
+
async addObservation(note) {
|
|
89
|
+
await this.init();
|
|
90
|
+
// Run coherence check against related existing notes (if enabled)
|
|
91
|
+
if (this.bankConfig.coherenceChecking !== false) {
|
|
92
|
+
try {
|
|
93
|
+
const existing = await this.getRelatedNotes(note);
|
|
94
|
+
const coherence = await this.coherenceChecker.check(note, existing);
|
|
95
|
+
if (!coherence.isCoherent) {
|
|
96
|
+
// Flag contradictions in metadata but still store the note
|
|
97
|
+
const meta = note.frontmatter;
|
|
98
|
+
meta['contradictions'] = coherence.contradictions.map((c) => c.existingNoteId);
|
|
99
|
+
meta['coherenceEnergy'] = coherence.globalEnergy;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Coherence check is non-critical — don't block insertion
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
await this.writeNote(note);
|
|
107
|
+
this.graph.addNode(this.noteToGraphNode(note));
|
|
108
|
+
return note.frontmatter.id;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get the last coherence result from the most recent addObservation call.
|
|
112
|
+
* Useful for downstream consumers to react to contradictions.
|
|
113
|
+
*/
|
|
114
|
+
getCoherenceChecker() {
|
|
115
|
+
return this.coherenceChecker;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Update an existing entity note by appending a section.
|
|
119
|
+
*/
|
|
120
|
+
async updateEntity(entityId, update) {
|
|
121
|
+
await this.init();
|
|
122
|
+
const note = await this.getNote(entityId);
|
|
123
|
+
if (!note) {
|
|
124
|
+
throw new Error(`Entity note not found: ${entityId}`);
|
|
125
|
+
}
|
|
126
|
+
// Append the new section
|
|
127
|
+
const separator = '\n\n---\n\n';
|
|
128
|
+
const evidence = `*Source: trajectory ${update.trajectoryId}*`;
|
|
129
|
+
note.body = `${note.body}${separator}${update.section}\n\n${evidence}`;
|
|
130
|
+
// Update timestamp
|
|
131
|
+
note.frontmatter.updated = new Date().toISOString();
|
|
132
|
+
// Add trajectory to sources if not already present
|
|
133
|
+
if (!note.frontmatter.source.trajectories) {
|
|
134
|
+
note.frontmatter.source.trajectories = [];
|
|
135
|
+
}
|
|
136
|
+
if (!note.frontmatter.source.trajectories.includes(update.trajectoryId)) {
|
|
137
|
+
note.frontmatter.source.trajectories.push(update.trajectoryId);
|
|
138
|
+
}
|
|
139
|
+
await this.writeNote(note);
|
|
140
|
+
// Update graph node
|
|
141
|
+
this.graph.addNode(this.noteToGraphNode(note));
|
|
142
|
+
}
|
|
143
|
+
// =========================================================================
|
|
144
|
+
// Read Operations
|
|
145
|
+
// =========================================================================
|
|
146
|
+
/**
|
|
147
|
+
* Get a note by ID. Scans all directories.
|
|
148
|
+
*/
|
|
149
|
+
async getNote(id) {
|
|
150
|
+
await this.init();
|
|
151
|
+
// Try each directory
|
|
152
|
+
for (const dir of [
|
|
153
|
+
this.observationsDir,
|
|
154
|
+
this.entitiesDir,
|
|
155
|
+
this.domainsDir,
|
|
156
|
+
]) {
|
|
157
|
+
const notes = await this.scanDirectory(dir);
|
|
158
|
+
const found = notes.find((n) => n.frontmatter.id === id);
|
|
159
|
+
if (found)
|
|
160
|
+
return found;
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get an entity note by entity name.
|
|
166
|
+
*/
|
|
167
|
+
async getEntity(entityName) {
|
|
168
|
+
await this.init();
|
|
169
|
+
const slug = entityName.toLowerCase().replace(/[^a-z0-9]+/g, '-');
|
|
170
|
+
const filePath = join(this.entitiesDir, `${slug}.md`);
|
|
171
|
+
try {
|
|
172
|
+
const content = await readFile(filePath, 'utf-8');
|
|
173
|
+
const relativePath = relative(this.memoryDir, filePath);
|
|
174
|
+
return parseKnowledgeNote(content, relativePath);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Get a domain summary by domain name.
|
|
182
|
+
*/
|
|
183
|
+
async getDomainSummary(domain) {
|
|
184
|
+
await this.init();
|
|
185
|
+
const slug = domain.toLowerCase().replace(/[^a-z0-9]+/g, '-');
|
|
186
|
+
const filePath = join(this.domainsDir, `${slug}.md`);
|
|
187
|
+
try {
|
|
188
|
+
const content = await readFile(filePath, 'utf-8');
|
|
189
|
+
const relativePath = relative(this.memoryDir, filePath);
|
|
190
|
+
return parseKnowledgeNote(content, relativePath);
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* List all known entity names (from entity note filenames).
|
|
198
|
+
*/
|
|
199
|
+
async listEntities() {
|
|
200
|
+
await this.init();
|
|
201
|
+
try {
|
|
202
|
+
const files = await readdir(this.entitiesDir);
|
|
203
|
+
return files
|
|
204
|
+
.filter((f) => f.endsWith('.md'))
|
|
205
|
+
.map((f) => f.replace('.md', ''));
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* List all known domain names (from domain summary filenames).
|
|
213
|
+
*/
|
|
214
|
+
async listDomains() {
|
|
215
|
+
await this.init();
|
|
216
|
+
try {
|
|
217
|
+
const files = await readdir(this.domainsDir);
|
|
218
|
+
return files
|
|
219
|
+
.filter((f) => f.endsWith('.md'))
|
|
220
|
+
.map((f) => f.replace('.md', ''));
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
return [];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Get all notes across all directories.
|
|
228
|
+
*/
|
|
229
|
+
async getAllNotes() {
|
|
230
|
+
await this.init();
|
|
231
|
+
const [observations, entities, domains] = await Promise.all([
|
|
232
|
+
this.scanDirectory(this.observationsDir),
|
|
233
|
+
this.scanDirectory(this.entitiesDir),
|
|
234
|
+
this.scanDirectory(this.domainsDir),
|
|
235
|
+
]);
|
|
236
|
+
return [...observations, ...entities, ...domains];
|
|
237
|
+
}
|
|
238
|
+
// =========================================================================
|
|
239
|
+
// Graph Delegation
|
|
240
|
+
// =========================================================================
|
|
241
|
+
/**
|
|
242
|
+
* Get related notes via multi-layer graph traversal.
|
|
243
|
+
*/
|
|
244
|
+
async getRelated(noteId, options) {
|
|
245
|
+
await this.init();
|
|
246
|
+
const neighborNodes = this.graph.neighbors(noteId, options);
|
|
247
|
+
const matches = [];
|
|
248
|
+
for (const graphNode of neighborNodes) {
|
|
249
|
+
const note = await this.getNote(graphNode.id);
|
|
250
|
+
if (note) {
|
|
251
|
+
matches.push({
|
|
252
|
+
note,
|
|
253
|
+
score: graphNode.confidence,
|
|
254
|
+
matchType: 'graph',
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return matches.sort((a, b) => b.score - a.score);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Get cross-system links to playbooks.
|
|
262
|
+
*/
|
|
263
|
+
async getPlaybookLinks(noteId) {
|
|
264
|
+
await this.init();
|
|
265
|
+
const edges = this.graph.crossSystemLinks(noteId);
|
|
266
|
+
return edges
|
|
267
|
+
.filter((e) => e.crossSystem === 'playbook')
|
|
268
|
+
.map((e) => ({
|
|
269
|
+
noteId: e.from,
|
|
270
|
+
playbookId: e.to,
|
|
271
|
+
relation: 'supports',
|
|
272
|
+
}));
|
|
273
|
+
}
|
|
274
|
+
// =========================================================================
|
|
275
|
+
// Stats
|
|
276
|
+
// =========================================================================
|
|
277
|
+
async getStats() {
|
|
278
|
+
await this.init();
|
|
279
|
+
const [observations, entities, domains, inbox] = await Promise.all([
|
|
280
|
+
this.countFiles(this.observationsDir),
|
|
281
|
+
this.countFiles(this.entitiesDir),
|
|
282
|
+
this.countFiles(this.domainsDir),
|
|
283
|
+
this.countFiles(this.inboxDir),
|
|
284
|
+
]);
|
|
285
|
+
const graphStats = this.graph.getStats();
|
|
286
|
+
// Compute average confidence and domain breakdown
|
|
287
|
+
const allNotes = await this.getAllNotes();
|
|
288
|
+
let totalConfidence = 0;
|
|
289
|
+
let staleCount = 0;
|
|
290
|
+
const domainBreakdown = {};
|
|
291
|
+
for (const note of allNotes) {
|
|
292
|
+
totalConfidence += note.frontmatter.confidence;
|
|
293
|
+
if (note.frontmatter.tags.includes('stale'))
|
|
294
|
+
staleCount++;
|
|
295
|
+
for (const domain of note.frontmatter.domain) {
|
|
296
|
+
domainBreakdown[domain] = (domainBreakdown[domain] ?? 0) + 1;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
observationCount: observations,
|
|
301
|
+
entityCount: entities,
|
|
302
|
+
domainCount: domains,
|
|
303
|
+
inboxCount: inbox,
|
|
304
|
+
graph: graphStats,
|
|
305
|
+
avgConfidence: allNotes.length > 0 ? totalConfidence / allNotes.length : 0,
|
|
306
|
+
staleCount,
|
|
307
|
+
domainBreakdown,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
// =========================================================================
|
|
311
|
+
// Search & Retrieval
|
|
312
|
+
// =========================================================================
|
|
313
|
+
/**
|
|
314
|
+
* Search knowledge notes by text similarity.
|
|
315
|
+
* Scores against note ID + body using Jaccard + n-gram similarity.
|
|
316
|
+
*/
|
|
317
|
+
async search(query, options) {
|
|
318
|
+
await this.init();
|
|
319
|
+
const allNotes = await this.getAllNotes();
|
|
320
|
+
const maxResults = options?.maxResults ?? 10;
|
|
321
|
+
// Filter by domains if specified
|
|
322
|
+
let candidates = allNotes;
|
|
323
|
+
if (options?.domains && options.domains.length > 0) {
|
|
324
|
+
candidates = allNotes.filter((note) => note.frontmatter.domain.some((d) => options.domains.includes(d)));
|
|
325
|
+
}
|
|
326
|
+
// Exclude stale notes
|
|
327
|
+
candidates = candidates.filter((note) => !note.frontmatter.tags.includes('stale'));
|
|
328
|
+
// Delegate scoring to the search provider
|
|
329
|
+
const results = await this.searchProvider.search(query, candidates, { maxResults });
|
|
330
|
+
// Build a lookup for fast note retrieval by ID
|
|
331
|
+
const noteById = new Map(candidates.map((n) => [n.frontmatter.id, n]));
|
|
332
|
+
const matches = [];
|
|
333
|
+
for (const r of results) {
|
|
334
|
+
const note = noteById.get(r.noteId);
|
|
335
|
+
if (note) {
|
|
336
|
+
matches.push({
|
|
337
|
+
note,
|
|
338
|
+
score: r.score,
|
|
339
|
+
matchType: 'semantic',
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return matches;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Get relevant knowledge for a task using 3-tier retrieval:
|
|
347
|
+
* 1. Domain summary match
|
|
348
|
+
* 2. Entity name match in task description
|
|
349
|
+
* 3. Semantic text similarity search
|
|
350
|
+
*/
|
|
351
|
+
async getRelevantKnowledge(task, options) {
|
|
352
|
+
await this.init();
|
|
353
|
+
const surfacingConfig = this.bankConfig.surfacing;
|
|
354
|
+
const maxNotes = options?.maxNotes ?? surfacingConfig.maxNotesPerTask;
|
|
355
|
+
const maxTokens = options?.maxTokens ?? surfacingConfig.maxTokensForKnowledge;
|
|
356
|
+
const matches = [];
|
|
357
|
+
const seenIds = new Set();
|
|
358
|
+
// Tier 1: Domain match
|
|
359
|
+
if (surfacingConfig.includeDomainSummaries && task.domain) {
|
|
360
|
+
const domainSummary = await this.getDomainSummary(task.domain);
|
|
361
|
+
if (domainSummary && !seenIds.has(domainSummary.frontmatter.id)) {
|
|
362
|
+
seenIds.add(domainSummary.frontmatter.id);
|
|
363
|
+
matches.push({
|
|
364
|
+
note: domainSummary,
|
|
365
|
+
score: 1.0,
|
|
366
|
+
matchType: 'domain',
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// Tier 2: Entity match
|
|
371
|
+
if (surfacingConfig.includeEntityNotes) {
|
|
372
|
+
const entityNames = await this.listEntities();
|
|
373
|
+
const taskLower = task.description.toLowerCase();
|
|
374
|
+
for (const entitySlug of entityNames) {
|
|
375
|
+
const entityWords = entitySlug.replace(/-/g, ' ');
|
|
376
|
+
if (taskLower.includes(entitySlug) || taskLower.includes(entityWords)) {
|
|
377
|
+
if (seenIds.has(entitySlug))
|
|
378
|
+
continue;
|
|
379
|
+
const entityNote = await this.getEntity(entitySlug);
|
|
380
|
+
if (entityNote) {
|
|
381
|
+
seenIds.add(entityNote.frontmatter.id);
|
|
382
|
+
matches.push({
|
|
383
|
+
note: entityNote,
|
|
384
|
+
score: 0.9,
|
|
385
|
+
matchType: 'entity',
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
// Tier 3: Semantic match
|
|
392
|
+
const remainingSlots = maxNotes - matches.length;
|
|
393
|
+
if (remainingSlots > 0) {
|
|
394
|
+
const searchResults = await this.search(task.description, {
|
|
395
|
+
domains: task.domain ? [task.domain] : undefined,
|
|
396
|
+
maxResults: remainingSlots + matches.length,
|
|
397
|
+
});
|
|
398
|
+
for (const result of searchResults) {
|
|
399
|
+
if (seenIds.has(result.note.frontmatter.id))
|
|
400
|
+
continue;
|
|
401
|
+
seenIds.add(result.note.frontmatter.id);
|
|
402
|
+
matches.push(result);
|
|
403
|
+
if (matches.length >= maxNotes)
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
// Sort: domain > entity > semantic, then by score
|
|
408
|
+
matches.sort((a, b) => {
|
|
409
|
+
const typeOrder = { domain: 0, entity: 1, semantic: 2, graph: 3 };
|
|
410
|
+
const typeA = typeOrder[a.matchType ?? 'semantic'];
|
|
411
|
+
const typeB = typeOrder[b.matchType ?? 'semantic'];
|
|
412
|
+
if (typeA !== typeB)
|
|
413
|
+
return typeA - typeB;
|
|
414
|
+
return b.score - a.score;
|
|
415
|
+
});
|
|
416
|
+
// Enforce limits
|
|
417
|
+
const limited = matches.slice(0, maxNotes);
|
|
418
|
+
return this.enforceTokenBudget(limited, maxTokens);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Process inbox files: classify, move to correct directory, add to graph.
|
|
422
|
+
* Files with valid frontmatter are classified by type field.
|
|
423
|
+
* Files without valid frontmatter get heuristic classification as observations.
|
|
424
|
+
*/
|
|
425
|
+
async processInbox() {
|
|
426
|
+
await this.init();
|
|
427
|
+
let processed = 0;
|
|
428
|
+
let failed = 0;
|
|
429
|
+
let movedToObservations = 0;
|
|
430
|
+
let movedToEntities = 0;
|
|
431
|
+
let movedToDomains = 0;
|
|
432
|
+
let files;
|
|
433
|
+
try {
|
|
434
|
+
files = (await readdir(this.inboxDir)).filter((f) => f.endsWith('.md'));
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
return { processed, failed, movedToObservations, movedToEntities, movedToDomains };
|
|
438
|
+
}
|
|
439
|
+
for (const file of files) {
|
|
440
|
+
const absPath = join(this.inboxDir, file);
|
|
441
|
+
try {
|
|
442
|
+
const content = await readFile(absPath, 'utf-8');
|
|
443
|
+
const relativePath = `inbox/${file}`;
|
|
444
|
+
const parsed = parseKnowledgeNote(content, relativePath);
|
|
445
|
+
let note;
|
|
446
|
+
if (parsed && parsed.frontmatter.type) {
|
|
447
|
+
// Valid frontmatter — use its type
|
|
448
|
+
note = parsed;
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
// No valid frontmatter — apply heuristic classification
|
|
452
|
+
note = this.processRawInboxFile(content, file);
|
|
453
|
+
}
|
|
454
|
+
// Move to correct directory based on type
|
|
455
|
+
const result = await this.moveInboxNote(note);
|
|
456
|
+
if (result === 'observation')
|
|
457
|
+
movedToObservations++;
|
|
458
|
+
else if (result === 'entity')
|
|
459
|
+
movedToEntities++;
|
|
460
|
+
else if (result === 'domain-summary')
|
|
461
|
+
movedToDomains++;
|
|
462
|
+
// Add to graph
|
|
463
|
+
this.graph.addNode(this.noteToGraphNode(note));
|
|
464
|
+
// Remove from inbox
|
|
465
|
+
await unlink(absPath);
|
|
466
|
+
processed++;
|
|
467
|
+
}
|
|
468
|
+
catch {
|
|
469
|
+
failed++;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return { processed, failed, movedToObservations, movedToEntities, movedToDomains };
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Run the full 7-step defragmentation cycle via KnowledgeDefragmenter.
|
|
476
|
+
*/
|
|
477
|
+
async defragment() {
|
|
478
|
+
await this.init();
|
|
479
|
+
const { KnowledgeDefragmenter } = await import('./knowledge-defrag.js');
|
|
480
|
+
const defragmenter = new KnowledgeDefragmenter(this, this.bankConfig.defrag);
|
|
481
|
+
return defragmenter.defragment();
|
|
482
|
+
}
|
|
483
|
+
async applyExtraction(extraction) {
|
|
484
|
+
await this.init();
|
|
485
|
+
// 1. Add new observations
|
|
486
|
+
for (const obs of extraction.observations) {
|
|
487
|
+
await this.addObservation(obs);
|
|
488
|
+
}
|
|
489
|
+
// 2. Apply entity updates (skip if entity doesn't exist)
|
|
490
|
+
for (const update of extraction.entityUpdates) {
|
|
491
|
+
try {
|
|
492
|
+
await this.updateEntity(update.entityId, update);
|
|
493
|
+
}
|
|
494
|
+
catch {
|
|
495
|
+
// Entity doesn't exist yet — skip
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
// 3. Record contradictions
|
|
499
|
+
for (const contradiction of extraction.contradictions) {
|
|
500
|
+
await this.recordContradiction(contradiction);
|
|
501
|
+
}
|
|
502
|
+
// 4. Add graph edges for new links
|
|
503
|
+
for (const link of extraction.links) {
|
|
504
|
+
const layer = inferLayerFromRelation(link.relation);
|
|
505
|
+
const graphLayer = this.graph.getLayer(layer);
|
|
506
|
+
if (!graphLayer)
|
|
507
|
+
continue;
|
|
508
|
+
graphLayer.addEdge({
|
|
509
|
+
from: link.from,
|
|
510
|
+
to: link.to,
|
|
511
|
+
relation: link.relation,
|
|
512
|
+
weight: link.weight ?? 0.5,
|
|
513
|
+
created: new Date().toISOString(),
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
// 5. Add playbook cross-system links
|
|
517
|
+
for (const pbLink of extraction.playbookLinks) {
|
|
518
|
+
const semanticLayer = this.graph.getLayer('semantic');
|
|
519
|
+
if (!semanticLayer)
|
|
520
|
+
continue;
|
|
521
|
+
semanticLayer.addEdge({
|
|
522
|
+
from: pbLink.noteId,
|
|
523
|
+
to: pbLink.playbookId,
|
|
524
|
+
relation: pbLink.relation,
|
|
525
|
+
weight: 0.5,
|
|
526
|
+
created: new Date().toISOString(),
|
|
527
|
+
crossSystem: 'playbook',
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Reinforce a knowledge note with new evidence from a trajectory.
|
|
533
|
+
* Uses EMA to increase confidence: newConf = (1 - alpha) * oldConf + alpha * 1.0
|
|
534
|
+
*/
|
|
535
|
+
async reinforce(noteId, trajectoryId) {
|
|
536
|
+
await this.init();
|
|
537
|
+
const note = await this.getNote(noteId);
|
|
538
|
+
if (!note) {
|
|
539
|
+
throw new Error(`Cannot reinforce: note not found: ${noteId}`);
|
|
540
|
+
}
|
|
541
|
+
const alpha = this.bankConfig.confidence.reinforcementAlpha;
|
|
542
|
+
note.frontmatter.confidence =
|
|
543
|
+
(1 - alpha) * note.frontmatter.confidence + alpha * 1.0;
|
|
544
|
+
// Add trajectory to source (no duplicates)
|
|
545
|
+
if (!note.frontmatter.source.trajectories) {
|
|
546
|
+
note.frontmatter.source.trajectories = [];
|
|
547
|
+
}
|
|
548
|
+
if (!note.frontmatter.source.trajectories.includes(trajectoryId)) {
|
|
549
|
+
note.frontmatter.source.trajectories.push(trajectoryId);
|
|
550
|
+
}
|
|
551
|
+
// Update timestamp
|
|
552
|
+
note.frontmatter.updated = new Date().toISOString();
|
|
553
|
+
await this.writeNote(note);
|
|
554
|
+
this.graph.addNode(this.noteToGraphNode(note));
|
|
555
|
+
}
|
|
556
|
+
async recordContradiction(contradiction) {
|
|
557
|
+
await this.init();
|
|
558
|
+
const penalty = this.bankConfig.confidence.contradictionPenalty;
|
|
559
|
+
// Add the new observation if it hasn't been added already
|
|
560
|
+
const existingNew = await this.getNote(contradiction.newObservation.frontmatter.id);
|
|
561
|
+
if (!existingNew) {
|
|
562
|
+
await this.addObservation(contradiction.newObservation);
|
|
563
|
+
}
|
|
564
|
+
// Add a 'contradicts' edge in the entity layer
|
|
565
|
+
const entityLayer = this.graph.getLayer('entity');
|
|
566
|
+
if (entityLayer) {
|
|
567
|
+
entityLayer.addEdge({
|
|
568
|
+
from: contradiction.newObservation.frontmatter.id,
|
|
569
|
+
to: contradiction.existingNoteId,
|
|
570
|
+
relation: 'contradicts',
|
|
571
|
+
weight: 0.8,
|
|
572
|
+
created: new Date().toISOString(),
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
// Load the existing note for confidence updates
|
|
576
|
+
const existingNote = await this.getNote(contradiction.existingNoteId);
|
|
577
|
+
if (contradiction.resolution === 'supersede') {
|
|
578
|
+
// Old note gets full penalty, new note supersedes
|
|
579
|
+
if (existingNote) {
|
|
580
|
+
existingNote.frontmatter.confidence = Math.max(0, existingNote.frontmatter.confidence - penalty);
|
|
581
|
+
await this.writeNote(existingNote);
|
|
582
|
+
this.graph.addNode(this.noteToGraphNode(existingNote));
|
|
583
|
+
}
|
|
584
|
+
contradiction.newObservation.frontmatter.supersedes = contradiction.existingNoteId;
|
|
585
|
+
await this.writeNote(contradiction.newObservation);
|
|
586
|
+
// Add temporal 'supersedes' edge
|
|
587
|
+
const temporalLayer = this.graph.getLayer('temporal');
|
|
588
|
+
if (temporalLayer) {
|
|
589
|
+
temporalLayer.addEdge({
|
|
590
|
+
from: contradiction.newObservation.frontmatter.id,
|
|
591
|
+
to: contradiction.existingNoteId,
|
|
592
|
+
relation: 'supersedes',
|
|
593
|
+
weight: 1.0,
|
|
594
|
+
created: new Date().toISOString(),
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
else if (contradiction.resolution === 'coexist') {
|
|
599
|
+
// Both notes get half penalty
|
|
600
|
+
const halfPenalty = penalty / 2;
|
|
601
|
+
if (existingNote) {
|
|
602
|
+
existingNote.frontmatter.confidence = Math.max(0, existingNote.frontmatter.confidence - halfPenalty);
|
|
603
|
+
await this.writeNote(existingNote);
|
|
604
|
+
this.graph.addNode(this.noteToGraphNode(existingNote));
|
|
605
|
+
}
|
|
606
|
+
const newNote = await this.getNote(contradiction.newObservation.frontmatter.id);
|
|
607
|
+
if (newNote) {
|
|
608
|
+
newNote.frontmatter.confidence = Math.max(0, newNote.frontmatter.confidence - halfPenalty);
|
|
609
|
+
await this.writeNote(newNote);
|
|
610
|
+
this.graph.addNode(this.noteToGraphNode(newNote));
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
else if (contradiction.resolution === 'review') {
|
|
614
|
+
// No confidence change, tag both for review
|
|
615
|
+
if (existingNote) {
|
|
616
|
+
if (!existingNote.frontmatter.tags.includes('needs-review')) {
|
|
617
|
+
existingNote.frontmatter.tags.push('needs-review');
|
|
618
|
+
await this.writeNote(existingNote);
|
|
619
|
+
this.graph.addNode(this.noteToGraphNode(existingNote));
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
const newNote = await this.getNote(contradiction.newObservation.frontmatter.id);
|
|
623
|
+
if (newNote && !newNote.frontmatter.tags.includes('needs-review')) {
|
|
624
|
+
newNote.frontmatter.tags.push('needs-review');
|
|
625
|
+
await this.writeNote(newNote);
|
|
626
|
+
this.graph.addNode(this.noteToGraphNode(newNote));
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Apply time-based confidence decay to all knowledge notes.
|
|
632
|
+
* Skips domain summaries, notes already tagged stale, and notes within the grace period.
|
|
633
|
+
*/
|
|
634
|
+
async applyDecay() {
|
|
635
|
+
await this.init();
|
|
636
|
+
const { dailyDecayRate, staleThreshold, decayGracePeriodDays } = this.bankConfig.confidence;
|
|
637
|
+
const now = Date.now();
|
|
638
|
+
const msPerDay = 1000 * 60 * 60 * 24;
|
|
639
|
+
let decayed = 0;
|
|
640
|
+
let newlyStale = 0;
|
|
641
|
+
let alreadyStale = 0;
|
|
642
|
+
// Scan observations and entities (skip domain summaries)
|
|
643
|
+
const [observations, entities] = await Promise.all([
|
|
644
|
+
this.scanDirectory(this.observationsDir),
|
|
645
|
+
this.scanDirectory(this.entitiesDir),
|
|
646
|
+
]);
|
|
647
|
+
for (const note of [...observations, ...entities]) {
|
|
648
|
+
// Skip already stale notes
|
|
649
|
+
if (note.frontmatter.tags.includes('stale')) {
|
|
650
|
+
alreadyStale++;
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
// Compute days since last update
|
|
654
|
+
const updatedMs = new Date(note.frontmatter.updated).getTime();
|
|
655
|
+
const daysSinceUpdated = (now - updatedMs) / msPerDay;
|
|
656
|
+
// Skip notes within grace period
|
|
657
|
+
if (daysSinceUpdated <= decayGracePeriodDays) {
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
// Apply exponential decay: newConf = oldConf * (1 - rate)^(days - grace)
|
|
661
|
+
const decayDays = daysSinceUpdated - decayGracePeriodDays;
|
|
662
|
+
const newConfidence = note.frontmatter.confidence * Math.pow(1 - dailyDecayRate, decayDays);
|
|
663
|
+
note.frontmatter.confidence = Math.max(0, newConfidence);
|
|
664
|
+
// Mark as stale if below threshold
|
|
665
|
+
if (note.frontmatter.confidence < staleThreshold) {
|
|
666
|
+
if (!note.frontmatter.tags.includes('stale')) {
|
|
667
|
+
note.frontmatter.tags.push('stale');
|
|
668
|
+
newlyStale++;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
// Write to disk without updating the 'updated' timestamp
|
|
672
|
+
await this.writeNote(note);
|
|
673
|
+
this.graph.addNode(this.noteToGraphNode(note));
|
|
674
|
+
decayed++;
|
|
675
|
+
}
|
|
676
|
+
return { decayed, newlyStale, alreadyStale };
|
|
677
|
+
}
|
|
678
|
+
// =========================================================================
|
|
679
|
+
// Extraction (Phase 2)
|
|
680
|
+
// =========================================================================
|
|
681
|
+
/**
|
|
682
|
+
* Extract knowledge from a trajectory source.
|
|
683
|
+
* Iterates all trajectories, runs extraction (agent or heuristic), and applies results.
|
|
684
|
+
*/
|
|
685
|
+
async extractFrom(source, options) {
|
|
686
|
+
await this.init();
|
|
687
|
+
const items = await source.load();
|
|
688
|
+
const results = [];
|
|
689
|
+
for (const item of items) {
|
|
690
|
+
let analysis = item.analysis;
|
|
691
|
+
if (!analysis && options?.analyzer) {
|
|
692
|
+
analysis = await options.analyzer.analyze(item.trajectory);
|
|
693
|
+
}
|
|
694
|
+
const extraction = await this.extractFromTrajectory(item.trajectory, analysis, options?.taskRunner);
|
|
695
|
+
results.push(extraction);
|
|
696
|
+
}
|
|
697
|
+
return results;
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Extract knowledge from a single trajectory.
|
|
701
|
+
* Uses the workspace template if a taskRunner is provided, otherwise falls back to heuristic.
|
|
702
|
+
* Applies the extraction to the knowledge bank.
|
|
703
|
+
*/
|
|
704
|
+
async extractFromTrajectory(trajectory, analysis, taskRunner) {
|
|
705
|
+
await this.init();
|
|
706
|
+
// Compute analysis if not provided
|
|
707
|
+
const { createAnalyzer } = await import('../learning/analyzer.js');
|
|
708
|
+
const resolvedAnalysis = analysis ?? await createAnalyzer('simple').analyze(trajectory);
|
|
709
|
+
// Gather context for extraction
|
|
710
|
+
const existingEntities = await this.listEntities();
|
|
711
|
+
const relatedNotes = await this.getAllNotes();
|
|
712
|
+
// Try workspace-based extraction if taskRunner is available
|
|
713
|
+
if (taskRunner) {
|
|
714
|
+
try {
|
|
715
|
+
const { knowledgeExtractionTemplate } = await import('../workspace/templates/knowledge-extraction.js');
|
|
716
|
+
const result = await taskRunner.run(knowledgeExtractionTemplate, {
|
|
717
|
+
trajectory,
|
|
718
|
+
analysis: resolvedAnalysis,
|
|
719
|
+
existingEntities,
|
|
720
|
+
relatedNotes: relatedNotes.slice(0, 20),
|
|
721
|
+
});
|
|
722
|
+
const extraction = result.output;
|
|
723
|
+
await this.applyExtraction(extraction);
|
|
724
|
+
return extraction;
|
|
725
|
+
}
|
|
726
|
+
catch (error) {
|
|
727
|
+
console.error('Workspace-based knowledge extraction failed, falling back to heuristic:', error instanceof Error ? error.message : error);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
// Heuristic fallback
|
|
731
|
+
const { KnowledgeExtractor } = await import('../learning/knowledge-extractor.js');
|
|
732
|
+
const extractor = new KnowledgeExtractor();
|
|
733
|
+
const extraction = extractor.extract(trajectory, resolvedAnalysis, {
|
|
734
|
+
existingEntities,
|
|
735
|
+
});
|
|
736
|
+
await this.applyExtraction(extraction);
|
|
737
|
+
return extraction;
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Format knowledge notes as a markdown section for agent prompt injection.
|
|
741
|
+
* Groups by type: domain summaries → entities → observations.
|
|
742
|
+
*/
|
|
743
|
+
formatKnowledgeForPrompt(notes, options) {
|
|
744
|
+
if (notes.length === 0)
|
|
745
|
+
return '';
|
|
746
|
+
const includeEvidence = options?.includeEvidence ?? this.bankConfig.surfacing.includeEvidence;
|
|
747
|
+
const includeLinks = options?.includeLinks ?? this.bankConfig.surfacing.includeLinks;
|
|
748
|
+
const maxTokens = options?.maxTokens ?? this.bankConfig.surfacing.maxTokensForKnowledge;
|
|
749
|
+
const sections = [];
|
|
750
|
+
sections.push('## Relevant Knowledge\n');
|
|
751
|
+
// Group by type
|
|
752
|
+
const domainSummaries = notes.filter((m) => m.note.frontmatter.type === 'domain-summary');
|
|
753
|
+
const entities = notes.filter((m) => m.note.frontmatter.type === 'entity');
|
|
754
|
+
const observations = notes.filter((m) => m.note.frontmatter.type === 'observation');
|
|
755
|
+
let tokenCount = 0;
|
|
756
|
+
for (const group of [domainSummaries, entities, observations]) {
|
|
757
|
+
for (const match of group) {
|
|
758
|
+
const noteSection = this.formatSingleNote(match, includeEvidence, includeLinks);
|
|
759
|
+
const sectionTokens = Math.ceil(noteSection.length / 4);
|
|
760
|
+
if (tokenCount + sectionTokens > maxTokens && sections.length > 1) {
|
|
761
|
+
break;
|
|
762
|
+
}
|
|
763
|
+
sections.push(noteSection);
|
|
764
|
+
tokenCount += sectionTokens;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
return sections.join('\n');
|
|
768
|
+
}
|
|
769
|
+
// =========================================================================
|
|
770
|
+
// Search Provider
|
|
771
|
+
// =========================================================================
|
|
772
|
+
/**
|
|
773
|
+
* Get the name of the active search provider.
|
|
774
|
+
*/
|
|
775
|
+
getSearchProviderName() {
|
|
776
|
+
return this.searchProvider.name;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Replace the active search provider (strategy pattern).
|
|
780
|
+
*/
|
|
781
|
+
setSearchProvider(provider) {
|
|
782
|
+
this.searchProvider = provider;
|
|
783
|
+
}
|
|
784
|
+
// =========================================================================
|
|
785
|
+
// Internal Helpers
|
|
786
|
+
// =========================================================================
|
|
787
|
+
/**
|
|
788
|
+
* Detect whether minimem is available and set up the MinimemSearchProvider.
|
|
789
|
+
*
|
|
790
|
+
* Detection checks (in order):
|
|
791
|
+
* 1. Look for a `.minimem/` directory under memoryDir
|
|
792
|
+
* 2. Look for a `MEMORY.md` file under memoryDir
|
|
793
|
+
* 3. Create a Minimem instance and wire MinimemSearchProvider
|
|
794
|
+
*
|
|
795
|
+
* Falls back to TextSimilaritySearchProvider on any failure.
|
|
796
|
+
*/
|
|
797
|
+
async detectMinimem() {
|
|
798
|
+
try {
|
|
799
|
+
// Check for minimem markers
|
|
800
|
+
const minimemDir = join(this.memoryDir, '.minimem');
|
|
801
|
+
const memoryMd = join(this.memoryDir, 'MEMORY.md');
|
|
802
|
+
let hasMinimemMarker = false;
|
|
803
|
+
try {
|
|
804
|
+
await access(minimemDir);
|
|
805
|
+
hasMinimemMarker = true;
|
|
806
|
+
}
|
|
807
|
+
catch {
|
|
808
|
+
try {
|
|
809
|
+
await access(memoryMd);
|
|
810
|
+
hasMinimemMarker = true;
|
|
811
|
+
}
|
|
812
|
+
catch {
|
|
813
|
+
// No minimem markers found
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (!hasMinimemMarker)
|
|
817
|
+
return;
|
|
818
|
+
// minimem is a direct dependency — use normal dynamic import
|
|
819
|
+
try {
|
|
820
|
+
const { Minimem } = await import('minimem');
|
|
821
|
+
const minimemInstance = await Minimem.create({
|
|
822
|
+
memoryDir: this.memoryDir,
|
|
823
|
+
embedding: { provider: 'auto' },
|
|
824
|
+
});
|
|
825
|
+
const { MinimemSearchProvider } = await import('./search-providers/minimem.js');
|
|
826
|
+
this.searchProvider = new MinimemSearchProvider(minimemInstance);
|
|
827
|
+
}
|
|
828
|
+
catch {
|
|
829
|
+
// minimem initialization failed — keep text-similarity fallback
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
catch {
|
|
833
|
+
// Detection failed — keep text-similarity fallback
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Get the index directory path (for defragmenter).
|
|
838
|
+
*/
|
|
839
|
+
getIndexDir() {
|
|
840
|
+
return this.indexDir;
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Check if defragmentation should be triggered.
|
|
844
|
+
*/
|
|
845
|
+
async shouldDefragment() {
|
|
846
|
+
await this.init();
|
|
847
|
+
const inboxCount = await this.countFiles(this.inboxDir);
|
|
848
|
+
return inboxCount >= this.bankConfig.defrag.minInboxItems;
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Resolve a note's file path and write it to disk.
|
|
852
|
+
*/
|
|
853
|
+
async writeNote(note) {
|
|
854
|
+
// Resolve the file path: when minimemAware, remap knowledge/ → memory/knowledge/
|
|
855
|
+
if (this.bankConfig.minimemAware &&
|
|
856
|
+
note.filePath.startsWith('knowledge/') &&
|
|
857
|
+
!note.filePath.startsWith('memory/knowledge/')) {
|
|
858
|
+
note.filePath = `memory/${note.filePath}`;
|
|
859
|
+
}
|
|
860
|
+
const absPath = join(this.memoryDir, note.filePath);
|
|
861
|
+
const dir = absPath.substring(0, absPath.lastIndexOf('/'));
|
|
862
|
+
await mkdir(dir, { recursive: true });
|
|
863
|
+
const content = serializeKnowledgeNote(note);
|
|
864
|
+
await writeFile(absPath, content, 'utf-8');
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Scan a directory for .md files and parse them as KnowledgeNotes.
|
|
868
|
+
* Skips files with invalid/missing frontmatter.
|
|
869
|
+
*/
|
|
870
|
+
async scanDirectory(dir) {
|
|
871
|
+
const notes = [];
|
|
872
|
+
try {
|
|
873
|
+
const files = await readdir(dir);
|
|
874
|
+
for (const file of files) {
|
|
875
|
+
if (!file.endsWith('.md'))
|
|
876
|
+
continue;
|
|
877
|
+
try {
|
|
878
|
+
const absPath = join(dir, file);
|
|
879
|
+
const content = await readFile(absPath, 'utf-8');
|
|
880
|
+
const relativePath = relative(this.memoryDir, absPath);
|
|
881
|
+
const note = parseKnowledgeNote(content, relativePath);
|
|
882
|
+
if (note)
|
|
883
|
+
notes.push(note);
|
|
884
|
+
}
|
|
885
|
+
catch {
|
|
886
|
+
// Skip files that can't be read
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
catch {
|
|
891
|
+
// Directory doesn't exist yet
|
|
892
|
+
}
|
|
893
|
+
return notes;
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Count .md files in a directory.
|
|
897
|
+
*/
|
|
898
|
+
async countFiles(dir) {
|
|
899
|
+
try {
|
|
900
|
+
const files = await readdir(dir);
|
|
901
|
+
return files.filter((f) => f.endsWith('.md')).length;
|
|
902
|
+
}
|
|
903
|
+
catch {
|
|
904
|
+
return 0;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Resolve the relative path for a note based on its type and filename.
|
|
909
|
+
* When minimemAware, paths are nested under memory/knowledge/ instead of knowledge/.
|
|
910
|
+
*/
|
|
911
|
+
resolveNotePath(type, filename) {
|
|
912
|
+
const knowledgePrefix = this.bankConfig.minimemAware
|
|
913
|
+
? 'memory/knowledge'
|
|
914
|
+
: 'knowledge';
|
|
915
|
+
if (type === 'entity') {
|
|
916
|
+
return `${knowledgePrefix}/entities/${filename}`;
|
|
917
|
+
}
|
|
918
|
+
else if (type === 'domain-summary') {
|
|
919
|
+
return `${knowledgePrefix}/domains/${filename}`;
|
|
920
|
+
}
|
|
921
|
+
return `${knowledgePrefix}/observations/${filename}`;
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Move an inbox note to the correct directory based on its type.
|
|
925
|
+
* Updates the note's filePath accordingly.
|
|
926
|
+
*/
|
|
927
|
+
async moveInboxNote(note) {
|
|
928
|
+
const type = note.frontmatter.type;
|
|
929
|
+
const noteType = type === 'entity' ? 'entity' : type === 'domain-summary' ? 'domain-summary' : 'observation';
|
|
930
|
+
const filename = `${note.frontmatter.id}.md`;
|
|
931
|
+
note.filePath = this.resolveNotePath(noteType, filename);
|
|
932
|
+
await this.writeNote(note);
|
|
933
|
+
return noteType;
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Create a KnowledgeNote from a raw inbox file with no valid frontmatter.
|
|
937
|
+
* Applies heuristic: observation type, agent-authored origin, agentAuthoredInitial confidence.
|
|
938
|
+
*/
|
|
939
|
+
processRawInboxFile(content, filename) {
|
|
940
|
+
const id = filename.replace('.md', '');
|
|
941
|
+
const title = id.replace(/[-_]/g, ' ');
|
|
942
|
+
return createObservation({
|
|
943
|
+
id,
|
|
944
|
+
title,
|
|
945
|
+
body: content,
|
|
946
|
+
domain: [],
|
|
947
|
+
entities: [],
|
|
948
|
+
tags: ['inbox-processed'],
|
|
949
|
+
confidence: this.bankConfig.confidence.agentAuthoredInitial,
|
|
950
|
+
source: { origin: 'agent-authored' },
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Convert a KnowledgeNote to a GraphNode.
|
|
955
|
+
*/
|
|
956
|
+
/**
|
|
957
|
+
* Enforce a token budget on a list of matches.
|
|
958
|
+
* Always includes at least one match.
|
|
959
|
+
*/
|
|
960
|
+
enforceTokenBudget(matches, maxTokens) {
|
|
961
|
+
const result = [];
|
|
962
|
+
let usedTokens = 0;
|
|
963
|
+
for (const match of matches) {
|
|
964
|
+
const noteTokens = Math.ceil(match.note.body.length / 4);
|
|
965
|
+
if (usedTokens + noteTokens > maxTokens && result.length > 0) {
|
|
966
|
+
break;
|
|
967
|
+
}
|
|
968
|
+
result.push(match);
|
|
969
|
+
usedTokens += noteTokens;
|
|
970
|
+
}
|
|
971
|
+
return result;
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Format a single knowledge note for prompt injection.
|
|
975
|
+
*/
|
|
976
|
+
formatSingleNote(match, includeEvidence, includeLinks) {
|
|
977
|
+
const { note } = match;
|
|
978
|
+
const confidencePercent = Math.round(note.frontmatter.confidence * 100);
|
|
979
|
+
const lines = [];
|
|
980
|
+
// Title line with type-appropriate heading
|
|
981
|
+
if (note.frontmatter.type === 'domain-summary') {
|
|
982
|
+
lines.push(`### ${note.frontmatter.domain[0] ?? 'General'} Overview (${confidencePercent}% confidence)`);
|
|
983
|
+
}
|
|
984
|
+
else if (note.frontmatter.type === 'entity') {
|
|
985
|
+
const entityName = note.frontmatter.entities[0] ?? note.frontmatter.id;
|
|
986
|
+
lines.push(`### About ${entityName} (${confidencePercent}% confidence)`);
|
|
987
|
+
}
|
|
988
|
+
else {
|
|
989
|
+
lines.push(`### ${note.frontmatter.id} (${confidencePercent}% confidence)`);
|
|
990
|
+
}
|
|
991
|
+
// Body content — skip leading markdown heading
|
|
992
|
+
let bodyContent = note.body;
|
|
993
|
+
const firstLine = bodyContent.split('\n')[0];
|
|
994
|
+
if (firstLine.startsWith('#')) {
|
|
995
|
+
bodyContent = bodyContent.slice(firstLine.length).trim();
|
|
996
|
+
}
|
|
997
|
+
if (bodyContent.length > 500) {
|
|
998
|
+
bodyContent = bodyContent.slice(0, 497) + '...';
|
|
999
|
+
}
|
|
1000
|
+
lines.push(bodyContent);
|
|
1001
|
+
// Evidence citations
|
|
1002
|
+
if (includeEvidence && note.frontmatter.source.trajectories?.length) {
|
|
1003
|
+
const trajectoryIds = note.frontmatter.source.trajectories.slice(0, 3);
|
|
1004
|
+
lines.push(`\n*Evidence: ${trajectoryIds.join(', ')}*`);
|
|
1005
|
+
}
|
|
1006
|
+
// Graph links
|
|
1007
|
+
if (includeLinks && note.frontmatter.links.length > 0) {
|
|
1008
|
+
const linkSummary = note.frontmatter.links
|
|
1009
|
+
.slice(0, 3)
|
|
1010
|
+
.map((l) => `${l.relation} ${l.target}`)
|
|
1011
|
+
.join(', ');
|
|
1012
|
+
lines.push(`*Related: ${linkSummary}*`);
|
|
1013
|
+
}
|
|
1014
|
+
lines.push('');
|
|
1015
|
+
return lines.join('\n');
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Get notes related to the given note by entity or domain overlap.
|
|
1019
|
+
* Used for coherence checking before insertion.
|
|
1020
|
+
*/
|
|
1021
|
+
async getRelatedNotes(note) {
|
|
1022
|
+
const allNotes = await this.getAllNotes();
|
|
1023
|
+
const noteEntities = new Set(note.frontmatter.entities);
|
|
1024
|
+
const noteDomains = new Set(note.frontmatter.domain);
|
|
1025
|
+
return allNotes.filter((existing) => {
|
|
1026
|
+
if (existing.frontmatter.id === note.frontmatter.id)
|
|
1027
|
+
return false;
|
|
1028
|
+
const hasEntityOverlap = existing.frontmatter.entities.some((e) => noteEntities.has(e));
|
|
1029
|
+
if (hasEntityOverlap)
|
|
1030
|
+
return true;
|
|
1031
|
+
const hasDomainOverlap = existing.frontmatter.domain.some((d) => noteDomains.has(d));
|
|
1032
|
+
return hasDomainOverlap;
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
noteToGraphNode(note) {
|
|
1036
|
+
return {
|
|
1037
|
+
id: note.frontmatter.id,
|
|
1038
|
+
file: note.filePath,
|
|
1039
|
+
type: note.frontmatter.type,
|
|
1040
|
+
domains: note.frontmatter.domain,
|
|
1041
|
+
entities: note.frontmatter.entities,
|
|
1042
|
+
tags: note.frontmatter.tags,
|
|
1043
|
+
confidence: note.frontmatter.confidence,
|
|
1044
|
+
updated: note.frontmatter.updated,
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
//# sourceMappingURL=knowledge-bank.js.map
|