cognitive-core 0.1.2 → 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.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 +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -5
- 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 +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/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/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/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 +6 -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 +109 -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 +65 -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 +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/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/runner.ts +3 -3
- 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/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/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/reflexion-generator.test.ts +411 -0
- package/tests/learning/trajectory-sources.test.ts +12 -4
- 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/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/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/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/partitioned-store.test.ts +230 -0
- package/tests/workspace/full-flow.test.ts +10 -4
- package/tests/workspace/runner.test.ts +10 -4
- 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
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
|
|
3
|
-
// ───
|
|
4
|
-
// Low-level git plumbing for reading from
|
|
5
|
-
// without checking
|
|
3
|
+
// ─── CheckpointGitReader ────────────────────────────────────────────
|
|
4
|
+
// Low-level git plumbing for reading from SessionLog checkpoint orphan
|
|
5
|
+
// branches without checking them out.
|
|
6
|
+
// Uses only git commands, no fs access.
|
|
6
7
|
// ─────────────────────────────────────────────────────────────────────
|
|
7
8
|
|
|
8
9
|
export interface GitReaderOptions {
|
|
9
10
|
repoPath: string;
|
|
10
11
|
branch?: string;
|
|
12
|
+
/** Trailer keys to search for checkpoint IDs in commit messages.
|
|
13
|
+
* Defaults to ['Sessionlog-Checkpoint']. */
|
|
14
|
+
trailerKeys?: string[];
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
export class
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
export class CheckpointGitReader {
|
|
18
|
+
readonly repoPath: string;
|
|
19
|
+
readonly branch: string;
|
|
20
|
+
private trailerKeys: string[];
|
|
16
21
|
|
|
17
22
|
constructor(options: GitReaderOptions) {
|
|
18
23
|
this.repoPath = options.repoPath;
|
|
19
|
-
this.branch = options.branch ?? '
|
|
24
|
+
this.branch = options.branch ?? 'sessionlog/checkpoints/v1';
|
|
25
|
+
this.trailerKeys = options.trailerKeys ?? ['Sessionlog-Checkpoint'];
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
/** Check if the orphan branch exists in this repo */
|
|
@@ -151,22 +157,26 @@ export class EntireGitReader {
|
|
|
151
157
|
}
|
|
152
158
|
|
|
153
159
|
/**
|
|
154
|
-
* Find
|
|
160
|
+
* Find a checkpoint trailer value for a given commit.
|
|
161
|
+
* Tries each configured trailer key in order.
|
|
155
162
|
* Returns the checkpoint ID or null.
|
|
156
163
|
*/
|
|
157
164
|
async getCheckpointTrailer(commitSha: string): Promise<string | null> {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
for (const key of this.trailerKeys) {
|
|
166
|
+
try {
|
|
167
|
+
const output = await this.git([
|
|
168
|
+
'log',
|
|
169
|
+
`--format=%(trailers:key=${key},valueonly)`,
|
|
170
|
+
commitSha,
|
|
171
|
+
'-1',
|
|
172
|
+
]);
|
|
173
|
+
const value = output.trim();
|
|
174
|
+
if (value) return value;
|
|
175
|
+
} catch {
|
|
176
|
+
// Try next key
|
|
177
|
+
}
|
|
169
178
|
}
|
|
179
|
+
return null;
|
|
170
180
|
}
|
|
171
181
|
|
|
172
182
|
// ── Private ──────────────────────────────────────────────────
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { SessionBank } from './session-bank.js';
|
|
2
|
-
export {
|
|
2
|
+
export { CheckpointGitReader, type GitReaderOptions } from './git-reader.js';
|
|
3
3
|
export {
|
|
4
|
-
|
|
4
|
+
CheckpointParser,
|
|
5
|
+
detectFormat,
|
|
6
|
+
type CheckpointFormat,
|
|
5
7
|
type ParsedMetadata,
|
|
6
8
|
} from './parser.js';
|
|
7
9
|
export type {
|
|
@@ -9,9 +9,22 @@ import type {
|
|
|
9
9
|
CheckpointRef,
|
|
10
10
|
} from './types.js';
|
|
11
11
|
|
|
12
|
+
// ─── Format Detection ──────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
export type CheckpointFormat = 'entire' | 'sessionlog' | 'unknown';
|
|
15
|
+
|
|
16
|
+
/** Auto-detect whether raw metadata JSON is Entire CLI or SessionLog format. */
|
|
17
|
+
export function detectFormat(raw: Record<string, unknown>): CheckpointFormat {
|
|
18
|
+
if ('checkpointID' in raw) return 'sessionlog';
|
|
19
|
+
if ('checkpoint_id' in raw) return 'entire';
|
|
20
|
+
if (raw.cliVersion === 'opentasks-sessionlog') return 'sessionlog';
|
|
21
|
+
if (typeof raw.cli_version === 'string') return 'entire';
|
|
22
|
+
return 'unknown';
|
|
23
|
+
}
|
|
24
|
+
|
|
12
25
|
// ─── Raw Entire JSON shapes (snake_case, matching Go structs) ───────
|
|
13
26
|
|
|
14
|
-
interface
|
|
27
|
+
interface RawEntireMetadata {
|
|
15
28
|
cli_version?: string;
|
|
16
29
|
checkpoint_id?: string;
|
|
17
30
|
session_id?: string;
|
|
@@ -23,21 +36,21 @@ interface RawMetadata {
|
|
|
23
36
|
is_task?: boolean;
|
|
24
37
|
tool_use_id?: string;
|
|
25
38
|
checkpoint_transcript_start?: number;
|
|
26
|
-
token_usage?:
|
|
27
|
-
summary?:
|
|
28
|
-
initial_attribution?:
|
|
39
|
+
token_usage?: RawEntireTokenUsage;
|
|
40
|
+
summary?: RawEntireSummary;
|
|
41
|
+
initial_attribution?: RawEntireAttribution;
|
|
29
42
|
}
|
|
30
43
|
|
|
31
|
-
interface
|
|
44
|
+
interface RawEntireTokenUsage {
|
|
32
45
|
input_tokens?: number;
|
|
33
46
|
cache_creation_tokens?: number;
|
|
34
47
|
cache_read_tokens?: number;
|
|
35
48
|
output_tokens?: number;
|
|
36
49
|
api_call_count?: number;
|
|
37
|
-
subagent_usage?:
|
|
50
|
+
subagent_usage?: RawEntireTokenUsage[];
|
|
38
51
|
}
|
|
39
52
|
|
|
40
|
-
interface
|
|
53
|
+
interface RawEntireSummary {
|
|
41
54
|
intent?: string;
|
|
42
55
|
outcome?: string;
|
|
43
56
|
learnings?: {
|
|
@@ -49,7 +62,7 @@ interface RawSummary {
|
|
|
49
62
|
open_items?: string[];
|
|
50
63
|
}
|
|
51
64
|
|
|
52
|
-
interface
|
|
65
|
+
interface RawEntireAttribution {
|
|
53
66
|
agent_lines_added?: number;
|
|
54
67
|
human_additions?: number;
|
|
55
68
|
human_modifications?: number;
|
|
@@ -58,6 +71,62 @@ interface RawAttribution {
|
|
|
58
71
|
agent_contribution?: number;
|
|
59
72
|
}
|
|
60
73
|
|
|
74
|
+
// ─── Raw SessionLog JSON shapes (camelCase) ─────────────────────────
|
|
75
|
+
|
|
76
|
+
interface RawSessionLogMetadata {
|
|
77
|
+
cliVersion?: string;
|
|
78
|
+
checkpointID?: string;
|
|
79
|
+
sessionID?: string;
|
|
80
|
+
strategy?: string;
|
|
81
|
+
createdAt?: string;
|
|
82
|
+
branch?: string;
|
|
83
|
+
filesTouched?: string[];
|
|
84
|
+
agent?: string;
|
|
85
|
+
turnID?: string;
|
|
86
|
+
isTask?: boolean;
|
|
87
|
+
toolUseID?: string;
|
|
88
|
+
checkpointTranscriptStart?: number;
|
|
89
|
+
tokenUsage?: RawSessionLogTokenUsage;
|
|
90
|
+
summary?: RawSessionLogSummary;
|
|
91
|
+
initialAttribution?: RawSessionLogAttribution;
|
|
92
|
+
tasks?: Record<string, unknown>;
|
|
93
|
+
planEntries?: unknown[];
|
|
94
|
+
skillsUsed?: unknown[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface RawSessionLogTokenUsage {
|
|
98
|
+
inputTokens?: number;
|
|
99
|
+
cacheCreationTokens?: number;
|
|
100
|
+
cacheReadTokens?: number;
|
|
101
|
+
outputTokens?: number;
|
|
102
|
+
apiCallCount?: number;
|
|
103
|
+
subagentTokens?: RawSessionLogTokenUsage;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface RawSessionLogSummary {
|
|
107
|
+
intent?: string;
|
|
108
|
+
outcome?: string;
|
|
109
|
+
learnings?: {
|
|
110
|
+
repo?: string[];
|
|
111
|
+
code?: Array<{ path: string; line?: number; endLine?: number; finding: string }>;
|
|
112
|
+
workflow?: string[];
|
|
113
|
+
};
|
|
114
|
+
friction?: string[];
|
|
115
|
+
openItems?: string[];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface RawSessionLogAttribution {
|
|
119
|
+
calculatedAt?: string;
|
|
120
|
+
agentLines?: number;
|
|
121
|
+
humanAdded?: number;
|
|
122
|
+
humanModified?: number;
|
|
123
|
+
humanRemoved?: number;
|
|
124
|
+
totalCommitted?: number;
|
|
125
|
+
agentPercentage?: number;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ─── Shared raw types for transcript parsing ────────────────────────
|
|
129
|
+
|
|
61
130
|
interface RawTranscriptLine {
|
|
62
131
|
type?: string;
|
|
63
132
|
uuid?: string;
|
|
@@ -65,7 +134,7 @@ interface RawTranscriptLine {
|
|
|
65
134
|
role?: string;
|
|
66
135
|
content?: string | RawContentBlock[];
|
|
67
136
|
};
|
|
68
|
-
//
|
|
137
|
+
// Entire CLI uses these for top-level tool_result lines
|
|
69
138
|
tool_use_id?: string;
|
|
70
139
|
content?: string | RawContentBlock[];
|
|
71
140
|
is_error?: boolean;
|
|
@@ -84,6 +153,7 @@ interface RawContentBlock {
|
|
|
84
153
|
}
|
|
85
154
|
|
|
86
155
|
interface RawCheckpointSummary {
|
|
156
|
+
// Entire format (snake_case)
|
|
87
157
|
sessions?: Array<{
|
|
88
158
|
metadata?: string;
|
|
89
159
|
transcript?: string;
|
|
@@ -91,6 +161,9 @@ interface RawCheckpointSummary {
|
|
|
91
161
|
content_hash?: string;
|
|
92
162
|
prompt?: string;
|
|
93
163
|
}>;
|
|
164
|
+
// SessionLog format may also use camelCase — same structure
|
|
165
|
+
checkpointID?: string;
|
|
166
|
+
checkpointsCount?: number;
|
|
94
167
|
}
|
|
95
168
|
|
|
96
169
|
// ─── Parser ─────────────────────────────────────────────────────────
|
|
@@ -102,9 +175,10 @@ export interface ParsedMetadata {
|
|
|
102
175
|
summary?: SessionSummary;
|
|
103
176
|
tokenUsage: TokenUsage;
|
|
104
177
|
attribution?: Attribution;
|
|
178
|
+
format: CheckpointFormat;
|
|
105
179
|
}
|
|
106
180
|
|
|
107
|
-
export class
|
|
181
|
+
export class CheckpointParser {
|
|
108
182
|
/**
|
|
109
183
|
* Parse a full session from its component files.
|
|
110
184
|
*/
|
|
@@ -113,6 +187,7 @@ export class EntireTranscriptParser {
|
|
|
113
187
|
transcriptJsonl: string,
|
|
114
188
|
checkpointPath: string,
|
|
115
189
|
sessionIndex: string,
|
|
190
|
+
sourceBranch?: string,
|
|
116
191
|
): SessionRecord {
|
|
117
192
|
const parsed = this.parseMetadata(metadataJson);
|
|
118
193
|
const transcript = this.parseTranscript(transcriptJsonl);
|
|
@@ -126,7 +201,7 @@ export class EntireTranscriptParser {
|
|
|
126
201
|
tokenUsage: parsed.tokenUsage,
|
|
127
202
|
attribution: parsed.attribution,
|
|
128
203
|
source: {
|
|
129
|
-
branch: '
|
|
204
|
+
branch: sourceBranch ?? 'sessionlog/checkpoints/v1',
|
|
130
205
|
checkpointPath,
|
|
131
206
|
sessionIndex,
|
|
132
207
|
},
|
|
@@ -135,39 +210,22 @@ export class EntireTranscriptParser {
|
|
|
135
210
|
|
|
136
211
|
/**
|
|
137
212
|
* Parse per-session metadata.json (fast path — no transcript).
|
|
213
|
+
* Auto-detects Entire (snake_case) vs SessionLog (camelCase) format.
|
|
138
214
|
*/
|
|
139
215
|
parseMetadata(metadataJson: string): ParsedMetadata {
|
|
140
|
-
const raw
|
|
141
|
-
|
|
142
|
-
const tokenUsage = this.parseTokenUsage(raw.token_usage);
|
|
143
|
-
const summary = raw.summary ? this.parseSummary(raw.summary) : undefined;
|
|
144
|
-
const attribution = raw.initial_attribution
|
|
145
|
-
? this.parseAttribution(raw.initial_attribution)
|
|
146
|
-
: undefined;
|
|
216
|
+
const raw = JSON.parse(metadataJson) as Record<string, unknown>;
|
|
217
|
+
const format = detectFormat(raw);
|
|
147
218
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
cliVersion: raw.cli_version ?? '',
|
|
153
|
-
strategy: raw.strategy === 'auto-commit' ? 'auto-commit' : 'manual-commit',
|
|
154
|
-
createdAt: raw.created_at ? new Date(raw.created_at) : new Date(0),
|
|
155
|
-
branch: raw.branch ?? '',
|
|
156
|
-
agent: raw.agent ?? '',
|
|
157
|
-
filesTouched: raw.files_touched ?? [],
|
|
158
|
-
isTask: raw.is_task ?? false,
|
|
159
|
-
toolUseId: raw.tool_use_id,
|
|
160
|
-
checkpointTranscriptStart: raw.checkpoint_transcript_start ?? 0,
|
|
161
|
-
},
|
|
162
|
-
summary,
|
|
163
|
-
tokenUsage,
|
|
164
|
-
attribution,
|
|
165
|
-
};
|
|
219
|
+
if (format === 'sessionlog') {
|
|
220
|
+
return this.parseSessionLogMetadata(raw as unknown as RawSessionLogMetadata);
|
|
221
|
+
}
|
|
222
|
+
return this.parseEntireMetadata(raw as unknown as RawEntireMetadata);
|
|
166
223
|
}
|
|
167
224
|
|
|
168
225
|
/**
|
|
169
226
|
* Parse a JSONL transcript into structured messages.
|
|
170
227
|
* Tolerant of malformed lines — skips them silently.
|
|
228
|
+
* Handles both Entire ("human") and SessionLog ("user") role types.
|
|
171
229
|
*/
|
|
172
230
|
parseTranscript(jsonlContent: string): TranscriptMessage[] {
|
|
173
231
|
const messages: TranscriptMessage[] = [];
|
|
@@ -216,21 +274,204 @@ export class EntireTranscriptParser {
|
|
|
216
274
|
};
|
|
217
275
|
}
|
|
218
276
|
|
|
219
|
-
// ──
|
|
277
|
+
// ── Entire format parsing (snake_case) ────────────────────────
|
|
278
|
+
|
|
279
|
+
private parseEntireMetadata(raw: RawEntireMetadata): ParsedMetadata {
|
|
280
|
+
const tokenUsage = this.parseEntireTokenUsage(raw.token_usage);
|
|
281
|
+
const summary = raw.summary ? this.parseEntireSummary(raw.summary) : undefined;
|
|
282
|
+
const attribution = raw.initial_attribution
|
|
283
|
+
? this.parseEntireAttribution(raw.initial_attribution)
|
|
284
|
+
: undefined;
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
sessionId: raw.session_id ?? '',
|
|
288
|
+
checkpointId: raw.checkpoint_id ?? '',
|
|
289
|
+
metadata: {
|
|
290
|
+
cliVersion: raw.cli_version ?? '',
|
|
291
|
+
strategy: raw.strategy === 'auto-commit' ? 'auto-commit' : 'manual-commit',
|
|
292
|
+
createdAt: raw.created_at ? new Date(raw.created_at) : new Date(0),
|
|
293
|
+
branch: raw.branch ?? '',
|
|
294
|
+
agent: raw.agent ?? '',
|
|
295
|
+
filesTouched: raw.files_touched ?? [],
|
|
296
|
+
isTask: raw.is_task ?? false,
|
|
297
|
+
toolUseId: raw.tool_use_id,
|
|
298
|
+
checkpointTranscriptStart: raw.checkpoint_transcript_start ?? 0,
|
|
299
|
+
},
|
|
300
|
+
summary,
|
|
301
|
+
tokenUsage,
|
|
302
|
+
attribution,
|
|
303
|
+
format: 'entire',
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
private parseEntireTokenUsage(raw?: RawEntireTokenUsage): TokenUsage {
|
|
308
|
+
if (!raw) {
|
|
309
|
+
return {
|
|
310
|
+
inputTokens: 0,
|
|
311
|
+
cacheCreationTokens: 0,
|
|
312
|
+
cacheReadTokens: 0,
|
|
313
|
+
outputTokens: 0,
|
|
314
|
+
apiCallCount: 0,
|
|
315
|
+
total: 0,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const inputTokens = raw.input_tokens ?? 0;
|
|
320
|
+
const cacheCreationTokens = raw.cache_creation_tokens ?? 0;
|
|
321
|
+
const cacheReadTokens = raw.cache_read_tokens ?? 0;
|
|
322
|
+
const outputTokens = raw.output_tokens ?? 0;
|
|
323
|
+
const apiCallCount = raw.api_call_count ?? 0;
|
|
324
|
+
|
|
325
|
+
const subagentUsage = raw.subagent_usage?.map((s) =>
|
|
326
|
+
this.parseEntireTokenUsage(s),
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
inputTokens,
|
|
331
|
+
cacheCreationTokens,
|
|
332
|
+
cacheReadTokens,
|
|
333
|
+
outputTokens,
|
|
334
|
+
apiCallCount,
|
|
335
|
+
subagentUsage,
|
|
336
|
+
total: inputTokens + cacheCreationTokens + cacheReadTokens + outputTokens,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
private parseEntireSummary(raw: RawEntireSummary): SessionSummary {
|
|
341
|
+
return {
|
|
342
|
+
intent: raw.intent ?? '',
|
|
343
|
+
outcome: raw.outcome ?? '',
|
|
344
|
+
learnings: {
|
|
345
|
+
repoPatterns: raw.learnings?.repo_patterns ?? [],
|
|
346
|
+
codeFindings: raw.learnings?.code_findings ?? [],
|
|
347
|
+
workflowPractices: raw.learnings?.workflow_practices ?? [],
|
|
348
|
+
},
|
|
349
|
+
frictionPoints: raw.friction_points ?? [],
|
|
350
|
+
openItems: raw.open_items ?? [],
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
private parseEntireAttribution(raw: RawEntireAttribution): Attribution {
|
|
355
|
+
return {
|
|
356
|
+
agentLinesAdded: raw.agent_lines_added ?? 0,
|
|
357
|
+
humanAdditions: raw.human_additions ?? 0,
|
|
358
|
+
humanModifications: raw.human_modifications ?? 0,
|
|
359
|
+
humanRemovals: raw.human_removals ?? 0,
|
|
360
|
+
totalCommittedLines: raw.total_committed_lines ?? 0,
|
|
361
|
+
agentContribution: raw.agent_contribution ?? 0,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// ── SessionLog format parsing (camelCase) ─────────────────────
|
|
366
|
+
|
|
367
|
+
private parseSessionLogMetadata(raw: RawSessionLogMetadata): ParsedMetadata {
|
|
368
|
+
const tokenUsage = this.parseSessionLogTokenUsage(raw.tokenUsage);
|
|
369
|
+
const summary = raw.summary ? this.parseSessionLogSummary(raw.summary) : undefined;
|
|
370
|
+
const attribution = raw.initialAttribution
|
|
371
|
+
? this.parseSessionLogAttribution(raw.initialAttribution)
|
|
372
|
+
: undefined;
|
|
373
|
+
|
|
374
|
+
return {
|
|
375
|
+
sessionId: raw.sessionID ?? '',
|
|
376
|
+
checkpointId: raw.checkpointID ?? '',
|
|
377
|
+
metadata: {
|
|
378
|
+
cliVersion: raw.cliVersion ?? '',
|
|
379
|
+
strategy: raw.strategy === 'auto-commit' ? 'auto-commit' : 'manual-commit',
|
|
380
|
+
createdAt: raw.createdAt ? new Date(raw.createdAt) : new Date(0),
|
|
381
|
+
branch: raw.branch ?? '',
|
|
382
|
+
agent: raw.agent ?? '',
|
|
383
|
+
filesTouched: raw.filesTouched ?? [],
|
|
384
|
+
isTask: raw.isTask ?? false,
|
|
385
|
+
toolUseId: raw.toolUseID,
|
|
386
|
+
checkpointTranscriptStart: raw.checkpointTranscriptStart ?? 0,
|
|
387
|
+
},
|
|
388
|
+
summary,
|
|
389
|
+
tokenUsage,
|
|
390
|
+
attribution,
|
|
391
|
+
format: 'sessionlog',
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
private parseSessionLogTokenUsage(raw?: RawSessionLogTokenUsage): TokenUsage {
|
|
396
|
+
if (!raw) {
|
|
397
|
+
return {
|
|
398
|
+
inputTokens: 0,
|
|
399
|
+
cacheCreationTokens: 0,
|
|
400
|
+
cacheReadTokens: 0,
|
|
401
|
+
outputTokens: 0,
|
|
402
|
+
apiCallCount: 0,
|
|
403
|
+
total: 0,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const inputTokens = raw.inputTokens ?? 0;
|
|
408
|
+
const cacheCreationTokens = raw.cacheCreationTokens ?? 0;
|
|
409
|
+
const cacheReadTokens = raw.cacheReadTokens ?? 0;
|
|
410
|
+
const outputTokens = raw.outputTokens ?? 0;
|
|
411
|
+
const apiCallCount = raw.apiCallCount ?? 0;
|
|
412
|
+
|
|
413
|
+
// SessionLog uses single subagentTokens object; wrap in array for compatibility
|
|
414
|
+
const subagentUsage = raw.subagentTokens
|
|
415
|
+
? [this.parseSessionLogTokenUsage(raw.subagentTokens)]
|
|
416
|
+
: undefined;
|
|
417
|
+
|
|
418
|
+
return {
|
|
419
|
+
inputTokens,
|
|
420
|
+
cacheCreationTokens,
|
|
421
|
+
cacheReadTokens,
|
|
422
|
+
outputTokens,
|
|
423
|
+
apiCallCount,
|
|
424
|
+
subagentUsage,
|
|
425
|
+
total: inputTokens + cacheCreationTokens + cacheReadTokens + outputTokens,
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
private parseSessionLogSummary(raw: RawSessionLogSummary): SessionSummary {
|
|
430
|
+
// SessionLog uses learnings.code as CodeLearning[] — normalize to string[]
|
|
431
|
+
const codeFindings = (raw.learnings?.code ?? []).map((cl) => {
|
|
432
|
+
const loc = cl.line ? `${cl.path}:${cl.line}` : cl.path;
|
|
433
|
+
return `${loc} - ${cl.finding}`;
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
return {
|
|
437
|
+
intent: raw.intent ?? '',
|
|
438
|
+
outcome: raw.outcome ?? '',
|
|
439
|
+
learnings: {
|
|
440
|
+
repoPatterns: raw.learnings?.repo ?? [],
|
|
441
|
+
codeFindings,
|
|
442
|
+
workflowPractices: raw.learnings?.workflow ?? [],
|
|
443
|
+
},
|
|
444
|
+
frictionPoints: raw.friction ?? [],
|
|
445
|
+
openItems: raw.openItems ?? [],
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
private parseSessionLogAttribution(raw: RawSessionLogAttribution): Attribution {
|
|
450
|
+
return {
|
|
451
|
+
agentLinesAdded: raw.agentLines ?? 0,
|
|
452
|
+
humanAdditions: raw.humanAdded ?? 0,
|
|
453
|
+
humanModifications: raw.humanModified ?? 0,
|
|
454
|
+
humanRemovals: raw.humanRemoved ?? 0,
|
|
455
|
+
totalCommittedLines: raw.totalCommitted ?? 0,
|
|
456
|
+
agentContribution: raw.agentPercentage ?? 0,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// ── Transcript parsing (shared — works for both formats) ──────
|
|
220
461
|
|
|
221
462
|
private parseTranscriptLine(
|
|
222
463
|
raw: RawTranscriptLine,
|
|
223
464
|
lineIndex: number,
|
|
224
465
|
): TranscriptMessage | null {
|
|
225
466
|
// Map Entire CLI's "human" → "user", keep "assistant" as-is.
|
|
226
|
-
//
|
|
467
|
+
// SessionLog always uses "user". Both handled here.
|
|
227
468
|
let role: 'user' | 'assistant';
|
|
228
469
|
if (raw.type === 'user' || raw.type === 'human') {
|
|
229
470
|
role = 'user';
|
|
230
471
|
} else if (raw.type === 'assistant') {
|
|
231
472
|
role = 'assistant';
|
|
232
473
|
} else if (raw.type === 'tool_result') {
|
|
233
|
-
//
|
|
474
|
+
// Entire CLI emits tool_result as a top-level JSONL line.
|
|
234
475
|
// Wrap it as a user message containing a tool_result block.
|
|
235
476
|
const toolResultBlock: ContentBlock = {
|
|
236
477
|
type: 'tool_result',
|
|
@@ -255,7 +496,6 @@ export class EntireTranscriptParser {
|
|
|
255
496
|
return null;
|
|
256
497
|
}
|
|
257
498
|
|
|
258
|
-
// UUID may not be present in real Entire CLI output
|
|
259
499
|
const uuid = raw.uuid ?? `line-${lineIndex}`;
|
|
260
500
|
|
|
261
501
|
const rawContent = raw.message?.content;
|
|
@@ -297,64 +537,6 @@ export class EntireTranscriptParser {
|
|
|
297
537
|
}
|
|
298
538
|
}
|
|
299
539
|
|
|
300
|
-
private parseTokenUsage(raw?: RawTokenUsage): TokenUsage {
|
|
301
|
-
if (!raw) {
|
|
302
|
-
return {
|
|
303
|
-
inputTokens: 0,
|
|
304
|
-
cacheCreationTokens: 0,
|
|
305
|
-
cacheReadTokens: 0,
|
|
306
|
-
outputTokens: 0,
|
|
307
|
-
apiCallCount: 0,
|
|
308
|
-
total: 0,
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const inputTokens = raw.input_tokens ?? 0;
|
|
313
|
-
const cacheCreationTokens = raw.cache_creation_tokens ?? 0;
|
|
314
|
-
const cacheReadTokens = raw.cache_read_tokens ?? 0;
|
|
315
|
-
const outputTokens = raw.output_tokens ?? 0;
|
|
316
|
-
const apiCallCount = raw.api_call_count ?? 0;
|
|
317
|
-
|
|
318
|
-
const subagentUsage = raw.subagent_usage?.map((s) =>
|
|
319
|
-
this.parseTokenUsage(s),
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
return {
|
|
323
|
-
inputTokens,
|
|
324
|
-
cacheCreationTokens,
|
|
325
|
-
cacheReadTokens,
|
|
326
|
-
outputTokens,
|
|
327
|
-
apiCallCount,
|
|
328
|
-
subagentUsage,
|
|
329
|
-
total: inputTokens + cacheCreationTokens + cacheReadTokens + outputTokens,
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
private parseSummary(raw: RawSummary): SessionSummary {
|
|
334
|
-
return {
|
|
335
|
-
intent: raw.intent ?? '',
|
|
336
|
-
outcome: raw.outcome ?? '',
|
|
337
|
-
learnings: {
|
|
338
|
-
repoPatterns: raw.learnings?.repo_patterns ?? [],
|
|
339
|
-
codeFindings: raw.learnings?.code_findings ?? [],
|
|
340
|
-
workflowPractices: raw.learnings?.workflow_practices ?? [],
|
|
341
|
-
},
|
|
342
|
-
frictionPoints: raw.friction_points ?? [],
|
|
343
|
-
openItems: raw.open_items ?? [],
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
private parseAttribution(raw: RawAttribution): Attribution {
|
|
348
|
-
return {
|
|
349
|
-
agentLinesAdded: raw.agent_lines_added ?? 0,
|
|
350
|
-
humanAdditions: raw.human_additions ?? 0,
|
|
351
|
-
humanModifications: raw.human_modifications ?? 0,
|
|
352
|
-
humanRemovals: raw.human_removals ?? 0,
|
|
353
|
-
totalCommittedLines: raw.total_committed_lines ?? 0,
|
|
354
|
-
agentContribution: raw.agent_contribution ?? 0,
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
|
|
358
540
|
private checkpointIdFromPath(path: string): string {
|
|
359
541
|
// Path is "<shard>/<rest>" → checkpoint ID is shard + rest
|
|
360
542
|
const parts = path.split('/');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { CheckpointGitReader } from './git-reader.js';
|
|
4
|
+
import { CheckpointParser } from './parser.js';
|
|
5
5
|
import type {
|
|
6
6
|
SessionRecord,
|
|
7
7
|
CheckpointRef,
|
|
@@ -12,10 +12,12 @@ import type {
|
|
|
12
12
|
} from './types.js';
|
|
13
13
|
|
|
14
14
|
// ─── SessionBank ────────────────────────────────────────────────────
|
|
15
|
-
// Main facade for reading
|
|
16
|
-
//
|
|
15
|
+
// Main facade for reading SessionLog checkpoint data from orphan
|
|
16
|
+
// branches. Read-only.
|
|
17
17
|
// ─────────────────────────────────────────────────────────────────────
|
|
18
18
|
|
|
19
|
+
const DEFAULT_BRANCH = 'sessionlog/checkpoints/v1';
|
|
20
|
+
|
|
19
21
|
interface CachedSession {
|
|
20
22
|
record: SessionRecord;
|
|
21
23
|
hasTranscript: boolean;
|
|
@@ -27,13 +29,16 @@ interface ProcessingState {
|
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
export class SessionBank {
|
|
30
|
-
private reader:
|
|
31
|
-
private parser:
|
|
32
|
+
private reader: CheckpointGitReader;
|
|
33
|
+
private parser: CheckpointParser;
|
|
32
34
|
private stateDir: string;
|
|
33
35
|
private cacheEnabled: boolean;
|
|
36
|
+
private repoPath: string;
|
|
37
|
+
private explicitBranch: string | undefined;
|
|
34
38
|
|
|
35
39
|
private available = false;
|
|
36
40
|
private initialized = false;
|
|
41
|
+
private detectedBranch: string = '';
|
|
37
42
|
|
|
38
43
|
// Cache
|
|
39
44
|
private cachedBranchHead: string | null = null;
|
|
@@ -47,19 +52,29 @@ export class SessionBank {
|
|
|
47
52
|
};
|
|
48
53
|
|
|
49
54
|
constructor(options?: SessionBankOptions) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.stateDir = options?.stateDir ?? join(repoPath, '.atlas', 'session-bank');
|
|
55
|
+
this.repoPath = options?.repoPath ?? process.cwd();
|
|
56
|
+
this.explicitBranch = options?.branch;
|
|
57
|
+
this.stateDir = options?.stateDir ?? join(this.repoPath, '.atlas', 'session-bank');
|
|
53
58
|
this.cacheEnabled = options?.cache ?? true;
|
|
54
59
|
|
|
55
|
-
|
|
56
|
-
this.
|
|
60
|
+
// Initial reader with explicit or default branch
|
|
61
|
+
const branch = this.explicitBranch ?? DEFAULT_BRANCH;
|
|
62
|
+
this.reader = new CheckpointGitReader({
|
|
63
|
+
repoPath: this.repoPath,
|
|
64
|
+
branch,
|
|
65
|
+
trailerKeys: options?.trailerKeys,
|
|
66
|
+
});
|
|
67
|
+
this.parser = new CheckpointParser();
|
|
57
68
|
}
|
|
58
69
|
|
|
59
70
|
// ── Lifecycle ──────────────────────────────────────────────────
|
|
60
71
|
|
|
61
72
|
async init(): Promise<void> {
|
|
62
73
|
this.available = await this.reader.branchExists();
|
|
74
|
+
if (this.available) {
|
|
75
|
+
this.detectedBranch = this.reader.branch;
|
|
76
|
+
}
|
|
77
|
+
|
|
63
78
|
await this.loadProcessingState();
|
|
64
79
|
if (this.available) {
|
|
65
80
|
this.cachedBranchHead = await this.reader.getBranchHead();
|
|
@@ -71,6 +86,11 @@ export class SessionBank {
|
|
|
71
86
|
return this.available;
|
|
72
87
|
}
|
|
73
88
|
|
|
89
|
+
/** The orphan branch name that was detected or configured. */
|
|
90
|
+
getBranch(): string {
|
|
91
|
+
return this.detectedBranch;
|
|
92
|
+
}
|
|
93
|
+
|
|
74
94
|
async close(): Promise<void> {
|
|
75
95
|
await this.saveProcessingState();
|
|
76
96
|
}
|
|
@@ -140,7 +160,7 @@ export class SessionBank {
|
|
|
140
160
|
tokenUsage: parsed.tokenUsage,
|
|
141
161
|
attribution: parsed.attribution,
|
|
142
162
|
source: {
|
|
143
|
-
branch:
|
|
163
|
+
branch: this.detectedBranch,
|
|
144
164
|
checkpointPath: ref.path,
|
|
145
165
|
sessionIndex: idx,
|
|
146
166
|
},
|
|
@@ -245,6 +265,7 @@ export class SessionBank {
|
|
|
245
265
|
transcriptJsonl ?? '',
|
|
246
266
|
path,
|
|
247
267
|
idx,
|
|
268
|
+
this.detectedBranch,
|
|
248
269
|
);
|
|
249
270
|
sessions.push(record);
|
|
250
271
|
} catch {
|