cognitive-core 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.json +111 -2
- package/.sessionlog/settings.json +4 -0
- package/CLAUDE.md +233 -0
- package/README.md +370 -54
- package/dist/atlas.d.ts +10 -10
- package/dist/atlas.d.ts.map +1 -1
- package/dist/atlas.js +79 -48
- 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/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 +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -6
- 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 +7 -2
- package/dist/learning/index.d.ts.map +1 -1
- package/dist/learning/index.js +13 -2
- 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/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.map +1 -1
- package/dist/learning/meta-learner.js +4 -21
- package/dist/learning/meta-learner.js.map +1 -1
- package/dist/learning/pipeline.d.ts +31 -4
- package/dist/learning/pipeline.d.ts.map +1 -1
- package/dist/learning/pipeline.js +64 -12
- 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/trajectory-sources/entire.d.ts +8 -5
- package/dist/learning/trajectory-sources/entire.d.ts.map +1 -1
- package/dist/learning/trajectory-sources/entire.js +13 -6
- package/dist/learning/trajectory-sources/entire.js.map +1 -1
- package/dist/learning/trajectory-sources/index.d.ts +1 -1
- package/dist/learning/trajectory-sources/index.d.ts.map +1 -1
- package/dist/learning/trajectory-sources/index.js +1 -1
- package/dist/learning/trajectory-sources/index.js.map +1 -1
- package/dist/learning/trajectory-sources/pipeline.d.ts +4 -4
- package/dist/learning/trajectory-sources/pipeline.d.ts.map +1 -1
- package/dist/learning/trajectory-sources/pipeline.js +2 -2
- package/dist/learning/trajectory-sources/pipeline.js.map +1 -1
- package/dist/learning/unified-pipeline.d.ts +311 -0
- package/dist/learning/unified-pipeline.d.ts.map +1 -0
- package/dist/learning/unified-pipeline.js +844 -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 +43 -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/index.d.ts +7 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +12 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/knowledge-bank.d.ts +14 -0
- package/dist/memory/knowledge-bank.d.ts.map +1 -1
- package/dist/memory/knowledge-bank.js +45 -0
- package/dist/memory/knowledge-bank.js.map +1 -1
- 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/system.d.ts +7 -2
- package/dist/memory/system.d.ts.map +1 -1
- package/dist/memory/system.js +19 -7
- package/dist/memory/system.js.map +1 -1
- 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/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/search/index.d.ts +1 -0
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +2 -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/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/session-bank/git-reader.d.ts +9 -4
- package/dist/session-bank/git-reader.d.ts.map +1 -1
- package/dist/session-bank/git-reader.js +22 -15
- package/dist/session-bank/git-reader.js.map +1 -1
- package/dist/session-bank/index.d.ts +2 -2
- package/dist/session-bank/index.d.ts.map +1 -1
- package/dist/session-bank/index.js +2 -2
- package/dist/session-bank/index.js.map +1 -1
- package/dist/session-bank/parser.d.ts +16 -5
- package/dist/session-bank/parser.d.ts.map +1 -1
- package/dist/session-bank/parser.js +187 -80
- package/dist/session-bank/parser.js.map +1 -1
- package/dist/session-bank/session-bank.d.ts +5 -0
- package/dist/session-bank/session-bank.d.ts.map +1 -1
- package/dist/session-bank/session-bank.js +30 -9
- package/dist/session-bank/session-bank.js.map +1 -1
- package/dist/session-bank/types.d.ts +4 -1
- package/dist/session-bank/types.d.ts.map +1 -1
- package/dist/session-bank/types.js +3 -3
- package/dist/session-bank/types.js.map +1 -1
- package/dist/surfacing/skill-publisher.d.ts.map +1 -1
- package/dist/surfacing/skill-publisher.js +15 -43
- package/dist/surfacing/skill-publisher.js.map +1 -1
- package/dist/surfacing/sqlite-storage-adapter.d.ts.map +1 -1
- package/dist/surfacing/sqlite-storage-adapter.js +13 -21
- package/dist/surfacing/sqlite-storage-adapter.js.map +1 -1
- package/dist/types/config.d.ts +100 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +27 -0
- package/dist/types/config.js.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- 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/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/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -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/efficacy-toolkit.d.ts +164 -0
- package/dist/workspace/efficacy-toolkit.d.ts.map +1 -0
- package/dist/workspace/efficacy-toolkit.js +281 -0
- package/dist/workspace/efficacy-toolkit.js.map +1 -0
- package/dist/workspace/index.d.ts +2 -1
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +3 -1
- package/dist/workspace/index.js.map +1 -1
- package/dist/workspace/runner.d.ts +3 -4
- package/dist/workspace/runner.d.ts.map +1 -1
- package/dist/workspace/runner.js.map +1 -1
- package/dist/workspace/templates/index.d.ts +3 -0
- package/dist/workspace/templates/index.d.ts.map +1 -1
- package/dist/workspace/templates/index.js +6 -0
- package/dist/workspace/templates/index.js.map +1 -1
- package/dist/workspace/templates/playbook-decay-detection.d.ts +46 -0
- package/dist/workspace/templates/playbook-decay-detection.d.ts.map +1 -0
- package/dist/workspace/templates/playbook-decay-detection.js +197 -0
- package/dist/workspace/templates/playbook-decay-detection.js.map +1 -0
- package/dist/workspace/templates/playbook-efficacy-audit.d.ts +46 -0
- package/dist/workspace/templates/playbook-efficacy-audit.d.ts.map +1 -0
- package/dist/workspace/templates/playbook-efficacy-audit.js +160 -0
- package/dist/workspace/templates/playbook-efficacy-audit.js.map +1 -0
- package/dist/workspace/templates/playbook-lifecycle-review.d.ts +51 -0
- package/dist/workspace/templates/playbook-lifecycle-review.d.ts.map +1 -0
- package/dist/workspace/templates/playbook-lifecycle-review.js +187 -0
- package/dist/workspace/templates/playbook-lifecycle-review.js.map +1 -0
- package/dist/workspace/types.d.ts +9 -2
- package/dist/workspace/types.d.ts.map +1 -1
- package/dist/workspace/types.js.map +1 -1
- package/package.json +12 -4
- 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/.sudocode/issues.jsonl +8 -0
- package/references/skill-tree/.sudocode/specs.jsonl +2 -0
- package/references/skill-tree/CLAUDE.md +56 -80
- package/references/skill-tree/README.md +188 -140
- package/references/skill-tree/examples/basic-usage.ts +95 -121
- package/references/skill-tree/package-lock.json +369 -26
- package/references/skill-tree/package.json +1 -1
- package/src/atlas.ts +97 -67
- 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/vector-store.ts +21 -9
- package/src/factory.ts +33 -16
- package/src/index.ts +136 -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 +66 -9
- package/src/learning/instant-loop.ts +357 -0
- package/src/learning/maintenance-scheduler.ts +271 -0
- package/src/learning/meta-learner.ts +5 -23
- package/src/learning/reflexion-generator.ts +273 -0
- package/src/learning/trajectory-sources/entire.ts +24 -13
- package/src/learning/trajectory-sources/index.ts +2 -2
- package/src/learning/trajectory-sources/pipeline.ts +5 -5
- package/src/learning/unified-pipeline.ts +1191 -0
- package/src/memory/candidate-retrieval.ts +72 -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/index.ts +43 -0
- package/src/memory/knowledge-bank.ts +57 -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/system.ts +21 -5
- 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/flows/learning.ts +25 -42
- package/src/search/index.ts +10 -0
- package/src/search/moe-gate.ts +304 -0
- package/src/search/router.ts +111 -4
- package/src/session-bank/git-reader.ts +29 -19
- package/src/session-bank/index.ts +4 -2
- package/src/session-bank/parser.ts +280 -98
- package/src/session-bank/session-bank.ts +33 -12
- package/src/session-bank/types.ts +8 -5
- package/src/surfacing/skill-publisher.ts +17 -49
- package/src/surfacing/sqlite-storage-adapter.ts +16 -32
- package/src/types/config.ts +30 -0
- package/src/types/index.ts +3 -0
- package/src/types/memory.ts +30 -0
- package/src/types/playbook.ts +4 -0
- package/src/utils/error-classifier.ts +113 -0
- package/src/utils/index.ts +18 -0
- package/src/utils/partitioned-store.ts +299 -0
- package/src/utils/trajectory-helpers.ts +79 -0
- package/src/workspace/efficacy-toolkit.ts +496 -0
- package/src/workspace/index.ts +29 -0
- package/src/workspace/runner.ts +3 -3
- package/src/workspace/templates/index.ts +24 -0
- package/src/workspace/templates/playbook-decay-detection.ts +272 -0
- package/src/workspace/templates/playbook-efficacy-audit.ts +246 -0
- package/src/workspace/templates/playbook-lifecycle-review.ts +274 -0
- package/src/workspace/types.ts +10 -2
- package/tests/embeddings/inverted-index.test.ts +138 -0
- package/tests/feature-toggles.test.ts +275 -0
- package/tests/fixtures/behavioral-trajectories.ts +210 -0
- package/tests/gap-fixes.test.ts +17 -4
- package/tests/integration/cli-e2e.test.ts +621 -0
- package/tests/integration/e2e.test.ts +6 -5
- package/tests/integration/entire-e2e.test.ts +314 -125
- package/tests/integration/persistence-e2e.test.ts +741 -0
- package/tests/integration/phase-e2e.test.ts +1143 -0
- package/tests/integration/pipeline-data-correctness.test.ts +794 -0
- package/tests/integration/session-bank.test.ts +20 -14
- package/tests/integration/sessionlog-e2e.test.ts +329 -0
- package/tests/integration/unified-pipeline-e2e.test.ts +634 -0
- package/tests/learning/analyzer.test.ts +1 -1
- package/tests/learning/energy-evaluator.test.ts +180 -0
- package/tests/learning/entire-trajectory-source.test.ts +25 -25
- package/tests/learning/healing-orchestrator.test.ts +269 -0
- package/tests/learning/instant-loop.test.ts +243 -0
- package/tests/learning/maintenance-scheduler.test.ts +191 -0
- package/tests/learning/meta-learner.test.ts +418 -0
- package/tests/learning/pipeline-memory-updates.test.ts +721 -0
- package/tests/learning/reflexion-generator.test.ts +411 -0
- package/tests/learning/trajectory-sources.test.ts +12 -4
- package/tests/learning/unified-pipeline-efficacy.test.ts +232 -0
- package/tests/learning/unified-pipeline.test.ts +322 -0
- package/tests/mcp/playbook-server.test.ts +6 -1
- package/tests/memory/candidate-retrieval.test.ts +167 -0
- 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/meta.test.ts +399 -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 +6 -1
- package/tests/memory/system.test.ts +6 -1
- 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 +6 -1
- package/tests/runtime/delegate.test.ts +6 -1
- package/tests/search/evaluator.test.ts +257 -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/verification-runner.test.ts +357 -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/git-reader.test.ts +13 -13
- package/tests/session-bank/parser.test.ts +135 -3
- package/tests/session-bank/session-bank.test.ts +1 -1
- package/tests/surfacing/skill-library.test.ts +6 -1
- package/tests/surfacing/skill-publisher.test.ts +24 -58
- package/tests/surfacing/sqlite-storage-adapter.test.ts +11 -23
- package/tests/utils/error-classifier.test.ts +149 -0
- package/tests/utils/partitioned-store.test.ts +230 -0
- package/tests/utils/trajectory-helpers.test.ts +163 -0
- package/tests/workspace/efficacy-toolkit.test.ts +404 -0
- package/tests/workspace/full-flow.test.ts +10 -4
- package/tests/workspace/runner.test.ts +10 -4
- package/tests/workspace/templates/playbook-efficacy.test.ts +377 -0
- package/docs/DESIGN-workspace-migration.md +0 -1079
- package/docs/PLAN-agentic-workspace-implementation.md +0 -717
- package/docs/PLAN-graph-migration.md +0 -299
- package/docs/PLAN-session-bank-implementation.md +0 -474
- package/src/learning/pipeline.ts +0 -323
- package/tests/learning/pipeline.test.ts +0 -176
package/src/learning/pipeline.ts
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Trajectory,
|
|
3
|
-
LearningConfig,
|
|
4
|
-
} from '../types/index.js';
|
|
5
|
-
import type { TrajectoryWithAnalysis } from '../types/trajectory-source.js';
|
|
6
|
-
import type { MemorySystem } from '../memory/system.js';
|
|
7
|
-
import {
|
|
8
|
-
TrajectoryAnalyzer,
|
|
9
|
-
createAnalyzer,
|
|
10
|
-
type AnalysisResult,
|
|
11
|
-
} from './analyzer.js';
|
|
12
|
-
import {
|
|
13
|
-
PlaybookExtractor,
|
|
14
|
-
createPlaybookExtractor,
|
|
15
|
-
} from './playbook-extractor.js';
|
|
16
|
-
import type { AgenticTaskRunner } from '../workspace/runner.js';
|
|
17
|
-
import { trajectoryAnalysisTemplate } from '../workspace/templates/trajectory-analysis.js';
|
|
18
|
-
import { playbookExtractionTemplate } from '../workspace/templates/playbook-extraction.js';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Result of processing a single trajectory
|
|
22
|
-
*/
|
|
23
|
-
export interface ProcessResult {
|
|
24
|
-
trajectoryId: string;
|
|
25
|
-
stored: boolean;
|
|
26
|
-
analysis: AnalysisResult;
|
|
27
|
-
abstractable: boolean;
|
|
28
|
-
playbookExtracted: boolean;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Result of batch learning
|
|
33
|
-
*/
|
|
34
|
-
export interface BatchResult {
|
|
35
|
-
trajectoriesProcessed: number;
|
|
36
|
-
playbooksExtracted: number;
|
|
37
|
-
experiencesPruned: number;
|
|
38
|
-
successRate: number;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Learning Pipeline
|
|
43
|
-
* Orchestrates trajectory analysis, playbook extraction, and memory updates
|
|
44
|
-
*/
|
|
45
|
-
export class LearningPipeline {
|
|
46
|
-
private analyzer: TrajectoryAnalyzer;
|
|
47
|
-
private playbookExtractor: PlaybookExtractor;
|
|
48
|
-
private memory: MemorySystem;
|
|
49
|
-
private config: LearningConfig;
|
|
50
|
-
|
|
51
|
-
// Optional agentic task runner for workspace-based analysis
|
|
52
|
-
private taskRunner: AgenticTaskRunner | null = null;
|
|
53
|
-
|
|
54
|
-
// Accumulated trajectories for batch learning
|
|
55
|
-
private accumulated: Trajectory[] = [];
|
|
56
|
-
private accumulatedAnalyses: AnalysisResult[] = [];
|
|
57
|
-
private lastBatchTime: Date | null = null;
|
|
58
|
-
|
|
59
|
-
constructor(memory: MemorySystem, config?: Partial<LearningConfig>) {
|
|
60
|
-
this.memory = memory;
|
|
61
|
-
this.config = {
|
|
62
|
-
creditStrategy: config?.creditStrategy ?? 'simple',
|
|
63
|
-
patternExtractor: config?.patternExtractor ?? 'llm',
|
|
64
|
-
minTrajectories: config?.minTrajectories ?? 10,
|
|
65
|
-
minHoursSinceLast: config?.minHoursSinceLast,
|
|
66
|
-
minSuccessRate: config?.minSuccessRate,
|
|
67
|
-
deduplicationThreshold: config?.deduplicationThreshold ?? 0.9,
|
|
68
|
-
maxExperiences: config?.maxExperiences ?? 1000,
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
this.analyzer = createAnalyzer(this.config.creditStrategy);
|
|
72
|
-
this.playbookExtractor = createPlaybookExtractor({
|
|
73
|
-
minTrajectories: this.config.minTrajectories,
|
|
74
|
-
mergeThreshold: this.config.deduplicationThreshold,
|
|
75
|
-
minSuccessRate: this.config.minSuccessRate ?? 0.6,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Set the agentic task runner for workspace-based analysis.
|
|
81
|
-
* When set, analysis tasks are delegated to templates (with heuristic fallback).
|
|
82
|
-
*/
|
|
83
|
-
setTaskRunner(runner: AgenticTaskRunner): void {
|
|
84
|
-
this.taskRunner = runner;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Process a single trajectory
|
|
89
|
-
*/
|
|
90
|
-
async processTrajectory(trajectory: Trajectory): Promise<ProcessResult> {
|
|
91
|
-
// Store in experience memory
|
|
92
|
-
await this.memory.storeTrajectory(trajectory);
|
|
93
|
-
|
|
94
|
-
// Analyze: workspace-based when runner available, heuristic otherwise
|
|
95
|
-
let analysis: AnalysisResult;
|
|
96
|
-
if (this.taskRunner) {
|
|
97
|
-
analysis = await this.analyzeWithTemplate(trajectory);
|
|
98
|
-
} else {
|
|
99
|
-
analysis = await this.analyzer.analyze(trajectory);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Accumulate for batch learning
|
|
103
|
-
this.accumulated.push(trajectory);
|
|
104
|
-
this.accumulatedAnalyses.push(analysis);
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
trajectoryId: trajectory.id,
|
|
108
|
-
stored: true,
|
|
109
|
-
analysis,
|
|
110
|
-
abstractable: analysis.abstractable,
|
|
111
|
-
playbookExtracted: false, // Playbooks are extracted in batch
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Run trajectory analysis via the workspace template.
|
|
117
|
-
* The template's assessComplexity() routes simple cases to heuristicFallback()
|
|
118
|
-
* (which calls the existing TrajectoryAnalyzer), so this is safe for all inputs.
|
|
119
|
-
*/
|
|
120
|
-
private async analyzeWithTemplate(trajectory: Trajectory): Promise<AnalysisResult> {
|
|
121
|
-
try {
|
|
122
|
-
const result = await this.taskRunner!.run(trajectoryAnalysisTemplate, {
|
|
123
|
-
trajectory,
|
|
124
|
-
creditStrategy: this.config.creditStrategy,
|
|
125
|
-
});
|
|
126
|
-
return result.output;
|
|
127
|
-
} catch (error) {
|
|
128
|
-
// If workspace-based analysis fails, fall back to heuristic
|
|
129
|
-
console.error(
|
|
130
|
-
'Workspace-based trajectory analysis failed, falling back to heuristic:',
|
|
131
|
-
error instanceof Error ? error.message : error
|
|
132
|
-
);
|
|
133
|
-
return this.analyzer.analyze(trajectory);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Check if batch learning should run
|
|
139
|
-
*/
|
|
140
|
-
shouldRunBatch(): boolean {
|
|
141
|
-
// Check minimum trajectories
|
|
142
|
-
if (this.accumulated.length < this.config.minTrajectories) {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Check time since last batch
|
|
147
|
-
if (this.config.minHoursSinceLast && this.lastBatchTime) {
|
|
148
|
-
const hoursSinceLast =
|
|
149
|
-
(Date.now() - this.lastBatchTime.getTime()) / (1000 * 60 * 60);
|
|
150
|
-
if (hoursSinceLast < this.config.minHoursSinceLast) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Check success rate
|
|
156
|
-
if (this.config.minSuccessRate) {
|
|
157
|
-
const successCount = this.accumulatedAnalyses.filter(
|
|
158
|
-
(a) => a.success
|
|
159
|
-
).length;
|
|
160
|
-
const successRate = successCount / this.accumulated.length;
|
|
161
|
-
if (successRate < this.config.minSuccessRate) {
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return true;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Run batch learning on accumulated trajectories
|
|
171
|
-
*/
|
|
172
|
-
async runBatchLearning(): Promise<BatchResult> {
|
|
173
|
-
if (this.accumulated.length === 0) {
|
|
174
|
-
return {
|
|
175
|
-
trajectoriesProcessed: 0,
|
|
176
|
-
playbooksExtracted: 0,
|
|
177
|
-
experiencesPruned: 0,
|
|
178
|
-
successRate: 0,
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Extract playbooks: workspace-based when runner available, heuristic otherwise
|
|
183
|
-
let playbooksAdded = 0;
|
|
184
|
-
const existingPlaybooks = await this.memory.playbooks.getAll();
|
|
185
|
-
const playbookExtraction = await this.extractPlaybooks(existingPlaybooks);
|
|
186
|
-
|
|
187
|
-
// Add new playbooks
|
|
188
|
-
for (const playbook of playbookExtraction.new) {
|
|
189
|
-
const exists = await this.memory.playbooks.exists(
|
|
190
|
-
playbook.name,
|
|
191
|
-
this.config.deduplicationThreshold
|
|
192
|
-
);
|
|
193
|
-
if (!exists) {
|
|
194
|
-
await this.memory.playbooks.add(playbook);
|
|
195
|
-
playbooksAdded++;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Apply updates to existing playbooks
|
|
200
|
-
for (const update of playbookExtraction.updates) {
|
|
201
|
-
if (update.refinement) {
|
|
202
|
-
await this.memory.playbooks.addRefinement(
|
|
203
|
-
update.id,
|
|
204
|
-
update.refinement.context,
|
|
205
|
-
update.refinement.addition,
|
|
206
|
-
update.refinement.source
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
if (update.newTrigger) {
|
|
210
|
-
const playbook = await this.memory.playbooks.get(update.id);
|
|
211
|
-
if (playbook && !playbook.applicability.triggers.includes(update.newTrigger)) {
|
|
212
|
-
playbook.applicability.triggers.push(update.newTrigger);
|
|
213
|
-
await this.memory.playbooks.add(playbook);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (update.newAntiPattern) {
|
|
217
|
-
const playbook = await this.memory.playbooks.get(update.id);
|
|
218
|
-
if (playbook && !playbook.applicability.antiPatterns.includes(update.newAntiPattern)) {
|
|
219
|
-
playbook.applicability.antiPatterns.push(update.newAntiPattern);
|
|
220
|
-
await this.memory.playbooks.add(playbook);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Prune experiences if needed
|
|
226
|
-
const pruned = await this.memory.experiences.prune({
|
|
227
|
-
maxCount: this.config.maxExperiences,
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
// Calculate success rate
|
|
231
|
-
const successCount = this.accumulatedAnalyses.filter((a) => a.success).length;
|
|
232
|
-
const successRate = successCount / this.accumulated.length;
|
|
233
|
-
|
|
234
|
-
// Clear accumulated and update time
|
|
235
|
-
const trajectoriesProcessed = this.accumulated.length;
|
|
236
|
-
this.accumulated = [];
|
|
237
|
-
this.accumulatedAnalyses = [];
|
|
238
|
-
this.lastBatchTime = new Date();
|
|
239
|
-
|
|
240
|
-
return {
|
|
241
|
-
trajectoriesProcessed,
|
|
242
|
-
playbooksExtracted: playbooksAdded,
|
|
243
|
-
experiencesPruned: pruned.totalPruned,
|
|
244
|
-
successRate,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Run playbook extraction via the workspace template.
|
|
250
|
-
* Falls back to heuristic extractor on failure.
|
|
251
|
-
*/
|
|
252
|
-
private async extractPlaybooks(
|
|
253
|
-
existingPlaybooks: import('../types/index.js').Playbook[]
|
|
254
|
-
): Promise<import('./playbook-extractor.js').ExtractedPlaybooks> {
|
|
255
|
-
if (this.taskRunner) {
|
|
256
|
-
try {
|
|
257
|
-
const result = await this.taskRunner.run(playbookExtractionTemplate, {
|
|
258
|
-
trajectories: this.accumulated,
|
|
259
|
-
analyses: this.accumulatedAnalyses,
|
|
260
|
-
existingPlaybooks,
|
|
261
|
-
});
|
|
262
|
-
return result.output;
|
|
263
|
-
} catch (error) {
|
|
264
|
-
console.error(
|
|
265
|
-
'Workspace-based playbook extraction failed, falling back to heuristic:',
|
|
266
|
-
error instanceof Error ? error.message : error
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return this.playbookExtractor.extract(
|
|
272
|
-
this.accumulated,
|
|
273
|
-
this.accumulatedAnalyses,
|
|
274
|
-
existingPlaybooks
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Get accumulated trajectory count
|
|
280
|
-
*/
|
|
281
|
-
getAccumulatedCount(): number {
|
|
282
|
-
return this.accumulated.length;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Get accumulated trajectories with their analyses.
|
|
287
|
-
* Read-only view — does not clear the accumulator.
|
|
288
|
-
*/
|
|
289
|
-
getAccumulated(): TrajectoryWithAnalysis[] {
|
|
290
|
-
return this.accumulated.map((trajectory, i) => ({
|
|
291
|
-
trajectory,
|
|
292
|
-
analysis: this.accumulatedAnalyses[i],
|
|
293
|
-
}));
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Clear accumulated trajectories
|
|
298
|
-
*/
|
|
299
|
-
clearAccumulated(): void {
|
|
300
|
-
this.accumulated = [];
|
|
301
|
-
this.accumulatedAnalyses = [];
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Update configuration
|
|
306
|
-
*/
|
|
307
|
-
updateConfig(config: Partial<LearningConfig>): void {
|
|
308
|
-
this.config = { ...this.config, ...config };
|
|
309
|
-
if (config.creditStrategy) {
|
|
310
|
-
this.analyzer.setStrategy(config.creditStrategy);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Create a learning pipeline
|
|
317
|
-
*/
|
|
318
|
-
export function createLearningPipeline(
|
|
319
|
-
memory: MemorySystem,
|
|
320
|
-
config?: Partial<LearningConfig>
|
|
321
|
-
): LearningPipeline {
|
|
322
|
-
return new LearningPipeline(memory, config);
|
|
323
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
-
import { LearningPipeline, createLearningPipeline } from '../../src/learning/pipeline.js';
|
|
3
|
-
import { MemorySystem } from '../../src/memory/system.js';
|
|
4
|
-
import { createTrajectory, createStep, createTask, successOutcome, failureOutcome } from '../../src/types/index.js';
|
|
5
|
-
import * as fs from 'node:fs/promises';
|
|
6
|
-
import * as path from 'node:path';
|
|
7
|
-
|
|
8
|
-
describe('LearningPipeline', () => {
|
|
9
|
-
let pipeline: LearningPipeline;
|
|
10
|
-
let memory: MemorySystem;
|
|
11
|
-
let testDir: string;
|
|
12
|
-
|
|
13
|
-
beforeEach(async () => {
|
|
14
|
-
testDir = path.join(process.cwd(), '.test-pipeline-' + Date.now());
|
|
15
|
-
await fs.mkdir(testDir, { recursive: true });
|
|
16
|
-
memory = new MemorySystem(testDir);
|
|
17
|
-
await memory.init();
|
|
18
|
-
pipeline = createLearningPipeline(memory, {
|
|
19
|
-
minTrajectories: 3,
|
|
20
|
-
minSuccessRate: 0.5,
|
|
21
|
-
maxExperiences: 100,
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterEach(async () => {
|
|
26
|
-
await memory.close();
|
|
27
|
-
await fs.rm(testDir, { recursive: true, force: true });
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const createTestTrajectory = (success: boolean, description: string) => {
|
|
31
|
-
return createTrajectory({
|
|
32
|
-
task: createTask({ domain: 'test', description }),
|
|
33
|
-
steps: [
|
|
34
|
-
createStep({
|
|
35
|
-
thought: 'Analyzing task',
|
|
36
|
-
action: 'read file',
|
|
37
|
-
observation: 'file contents',
|
|
38
|
-
}),
|
|
39
|
-
createStep({
|
|
40
|
-
thought: 'Applying solution',
|
|
41
|
-
action: 'edit file',
|
|
42
|
-
observation: success ? 'success' : 'error: failed',
|
|
43
|
-
}),
|
|
44
|
-
],
|
|
45
|
-
outcome: success
|
|
46
|
-
? successOutcome({ result: 'completed' })
|
|
47
|
-
: failureOutcome('Task failed'),
|
|
48
|
-
agentId: 'test-agent',
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
describe('processTrajectory', () => {
|
|
53
|
-
it('should process and store trajectory', async () => {
|
|
54
|
-
const trajectory = createTestTrajectory(true, 'Test task 1');
|
|
55
|
-
const result = await pipeline.processTrajectory(trajectory);
|
|
56
|
-
|
|
57
|
-
expect(result.stored).toBe(true);
|
|
58
|
-
expect(result.trajectoryId).toBe(trajectory.id);
|
|
59
|
-
expect(result.analysis).toBeDefined();
|
|
60
|
-
expect(result.analysis.success).toBe(true);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should accumulate trajectories for batch learning', async () => {
|
|
64
|
-
expect(pipeline.getAccumulatedCount()).toBe(0);
|
|
65
|
-
|
|
66
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 1'));
|
|
67
|
-
expect(pipeline.getAccumulatedCount()).toBe(1);
|
|
68
|
-
|
|
69
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 2'));
|
|
70
|
-
expect(pipeline.getAccumulatedCount()).toBe(2);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should analyze trajectory for key steps', async () => {
|
|
74
|
-
const trajectory = createTestTrajectory(true, 'Test analysis');
|
|
75
|
-
const result = await pipeline.processTrajectory(trajectory);
|
|
76
|
-
|
|
77
|
-
expect(result.analysis.keySteps).toBeDefined();
|
|
78
|
-
expect(Array.isArray(result.analysis.keySteps)).toBe(true);
|
|
79
|
-
expect(result.analysis.stepAttribution).toBeDefined();
|
|
80
|
-
expect(result.analysis.stepAttribution.length).toBe(trajectory.steps.length);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
describe('shouldRunBatch', () => {
|
|
85
|
-
it('should return false when below minTrajectories', () => {
|
|
86
|
-
expect(pipeline.shouldRunBatch()).toBe(false);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should return true when above minTrajectories with sufficient success rate', async () => {
|
|
90
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 1'));
|
|
91
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 2'));
|
|
92
|
-
expect(pipeline.shouldRunBatch()).toBe(false); // Still below 3
|
|
93
|
-
|
|
94
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 3'));
|
|
95
|
-
expect(pipeline.shouldRunBatch()).toBe(true); // Now at 3
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should return false when success rate is too low', async () => {
|
|
99
|
-
await pipeline.processTrajectory(createTestTrajectory(false, 'Task 1'));
|
|
100
|
-
await pipeline.processTrajectory(createTestTrajectory(false, 'Task 2'));
|
|
101
|
-
await pipeline.processTrajectory(createTestTrajectory(false, 'Task 3'));
|
|
102
|
-
|
|
103
|
-
// 0% success rate, below 50% threshold
|
|
104
|
-
expect(pipeline.shouldRunBatch()).toBe(false);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('runBatchLearning', () => {
|
|
109
|
-
it('should return empty result when no trajectories accumulated', async () => {
|
|
110
|
-
const result = await pipeline.runBatchLearning();
|
|
111
|
-
|
|
112
|
-
expect(result.trajectoriesProcessed).toBe(0);
|
|
113
|
-
expect(result.playbooksExtracted).toBe(0);
|
|
114
|
-
expect(result.experiencesPruned).toBe(0);
|
|
115
|
-
expect(result.successRate).toBe(0);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('should process accumulated trajectories', async () => {
|
|
119
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 1'));
|
|
120
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 2'));
|
|
121
|
-
await pipeline.processTrajectory(createTestTrajectory(false, 'Task 3'));
|
|
122
|
-
|
|
123
|
-
const result = await pipeline.runBatchLearning();
|
|
124
|
-
|
|
125
|
-
expect(result.trajectoriesProcessed).toBe(3);
|
|
126
|
-
expect(result.successRate).toBeCloseTo(2/3, 2);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('should clear accumulated after batch', async () => {
|
|
130
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 1'));
|
|
131
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 2'));
|
|
132
|
-
|
|
133
|
-
expect(pipeline.getAccumulatedCount()).toBe(2);
|
|
134
|
-
await pipeline.runBatchLearning();
|
|
135
|
-
expect(pipeline.getAccumulatedCount()).toBe(0);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
describe('clearAccumulated', () => {
|
|
140
|
-
it('should clear all accumulated trajectories', async () => {
|
|
141
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 1'));
|
|
142
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 2'));
|
|
143
|
-
|
|
144
|
-
expect(pipeline.getAccumulatedCount()).toBe(2);
|
|
145
|
-
pipeline.clearAccumulated();
|
|
146
|
-
expect(pipeline.getAccumulatedCount()).toBe(0);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
describe('configuration', () => {
|
|
151
|
-
it('should use configurable maxExperiences for pruning', async () => {
|
|
152
|
-
// The pipeline was created with maxExperiences: 100
|
|
153
|
-
// This test verifies the config is passed correctly
|
|
154
|
-
const configuredPipeline = createLearningPipeline(memory, {
|
|
155
|
-
maxExperiences: 50,
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// Process a trajectory to ensure it uses the config
|
|
159
|
-
const trajectory = createTestTrajectory(true, 'Config test');
|
|
160
|
-
const result = await configuredPipeline.processTrajectory(trajectory);
|
|
161
|
-
expect(result.stored).toBe(true);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('should update configuration', async () => {
|
|
165
|
-
pipeline.updateConfig({ minTrajectories: 5 });
|
|
166
|
-
|
|
167
|
-
// Add 3 trajectories (was enough before update)
|
|
168
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 1'));
|
|
169
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 2'));
|
|
170
|
-
await pipeline.processTrajectory(createTestTrajectory(true, 'Task 3'));
|
|
171
|
-
|
|
172
|
-
// Should not run batch yet (need 5 now)
|
|
173
|
-
expect(pipeline.shouldRunBatch()).toBe(false);
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
});
|