cognitive-core 0.2.5 → 0.3.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/LICENSE +21 -0
- package/README.md +88 -143
- package/dist/agents/mock-provider.d.ts.map +1 -1
- package/dist/agents/mock-provider.js.map +1 -1
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/types.js +5 -4
- package/dist/agents/types.js.map +1 -1
- package/dist/atlas.d.ts +309 -97
- package/dist/atlas.d.ts.map +1 -1
- package/dist/atlas.js +743 -277
- package/dist/atlas.js.map +1 -1
- package/dist/bin/cli-utils.d.ts +25 -2
- package/dist/bin/cli-utils.d.ts.map +1 -1
- package/dist/bin/cli-utils.js +79 -9
- package/dist/bin/cli-utils.js.map +1 -1
- package/dist/bin/cognitive-core.js +32 -0
- package/dist/bin/cognitive-core.js.map +1 -1
- package/dist/bin/commands/dream.d.ts +17 -0
- package/dist/bin/commands/dream.d.ts.map +1 -0
- package/dist/bin/commands/dream.js +168 -0
- package/dist/bin/commands/dream.js.map +1 -0
- package/dist/bin/commands/eval.d.ts +181 -0
- package/dist/bin/commands/eval.d.ts.map +1 -0
- package/dist/bin/commands/eval.js +1582 -0
- package/dist/bin/commands/eval.js.map +1 -0
- package/dist/bin/commands/kb.js +0 -8
- package/dist/bin/commands/kb.js.map +1 -1
- package/dist/bin/commands/learn.js +12 -4
- package/dist/bin/commands/learn.js.map +1 -1
- package/dist/bin/commands/legacy.d.ts.map +1 -1
- package/dist/bin/commands/legacy.js +1 -1
- package/dist/bin/commands/legacy.js.map +1 -1
- package/dist/bin/commands/run.d.ts.map +1 -1
- package/dist/bin/commands/run.js +10 -9
- package/dist/bin/commands/run.js.map +1 -1
- package/dist/bin/commands/sessions.d.ts.map +1 -1
- package/dist/bin/commands/sessions.js.map +1 -1
- package/dist/bin/commands/skills.d.ts.map +1 -1
- package/dist/bin/commands/skills.js +283 -1
- package/dist/bin/commands/skills.js.map +1 -1
- package/dist/embeddings/bm25.d.ts.map +1 -1
- package/dist/embeddings/bm25.js +1 -2
- package/dist/embeddings/bm25.js.map +1 -1
- package/dist/embeddings/index.d.ts +3 -3
- package/dist/embeddings/index.d.ts.map +1 -1
- package/dist/embeddings/index.js +3 -3
- package/dist/embeddings/index.js.map +1 -1
- package/dist/embeddings/inverted-index.js +62 -7
- package/dist/embeddings/inverted-index.js.map +1 -1
- package/dist/embeddings/manager.d.ts.map +1 -1
- package/dist/embeddings/manager.js +6 -5
- package/dist/embeddings/manager.js.map +1 -1
- package/dist/embeddings/provider.d.ts +96 -5
- package/dist/embeddings/provider.d.ts.map +1 -1
- package/dist/embeddings/provider.js +171 -48
- package/dist/embeddings/provider.js.map +1 -1
- package/dist/embeddings/vector-store.d.ts.map +1 -1
- package/dist/embeddings/vector-store.js +3 -1
- package/dist/embeddings/vector-store.js.map +1 -1
- package/dist/eval/ablation-validate.d.ts +12 -0
- package/dist/eval/ablation-validate.d.ts.map +1 -0
- package/dist/eval/ablation-validate.js +78 -0
- package/dist/eval/ablation-validate.js.map +1 -0
- package/dist/eval/ablation.d.ts +94 -0
- package/dist/eval/ablation.d.ts.map +1 -0
- package/dist/eval/ablation.js +161 -0
- package/dist/eval/ablation.js.map +1 -0
- package/dist/eval/ci-smoke.d.ts +11 -0
- package/dist/eval/ci-smoke.d.ts.map +1 -0
- package/dist/eval/ci-smoke.js +49 -0
- package/dist/eval/ci-smoke.js.map +1 -0
- package/dist/eval/diagnostics.d.ts +214 -0
- package/dist/eval/diagnostics.d.ts.map +1 -0
- package/dist/eval/diagnostics.js +107 -0
- package/dist/eval/diagnostics.js.map +1 -0
- package/dist/eval/index.d.ts +27 -0
- package/dist/eval/index.d.ts.map +1 -0
- package/dist/eval/index.js +27 -0
- package/dist/eval/index.js.map +1 -0
- package/dist/eval/live/alfworld.d.ts +248 -0
- package/dist/eval/live/alfworld.d.ts.map +1 -0
- package/dist/eval/live/alfworld.js +637 -0
- package/dist/eval/live/alfworld.js.map +1 -0
- package/dist/eval/live/alfworld_h1.d.ts +16 -0
- package/dist/eval/live/alfworld_h1.d.ts.map +1 -0
- package/dist/eval/live/alfworld_h1.js +75 -0
- package/dist/eval/live/alfworld_h1.js.map +1 -0
- package/dist/eval/live/alfworld_memory.d.ts +38 -0
- package/dist/eval/live/alfworld_memory.d.ts.map +1 -0
- package/dist/eval/live/alfworld_memory.js +184 -0
- package/dist/eval/live/alfworld_memory.js.map +1 -0
- package/dist/eval/live/alfworld_strategy.d.ts +65 -0
- package/dist/eval/live/alfworld_strategy.d.ts.map +1 -0
- package/dist/eval/live/alfworld_strategy.js +89 -0
- package/dist/eval/live/alfworld_strategy.js.map +1 -0
- package/dist/eval/live/azure-openai-llm-provider.d.ts +41 -0
- package/dist/eval/live/azure-openai-llm-provider.d.ts.map +1 -0
- package/dist/eval/live/azure-openai-llm-provider.js +92 -0
- package/dist/eval/live/azure-openai-llm-provider.js.map +1 -0
- package/dist/eval/live/bridges/skillflow_e2b_bridge.d.ts +3 -0
- package/dist/eval/live/bridges/skillflow_e2b_bridge.d.ts.map +1 -0
- package/dist/eval/live/bridges/skillflow_e2b_bridge.js +12 -0
- package/dist/eval/live/bridges/skillflow_e2b_bridge.js.map +1 -0
- package/dist/eval/live/claude-cli-llm-provider.d.ts +53 -0
- package/dist/eval/live/claude-cli-llm-provider.d.ts.map +1 -0
- package/dist/eval/live/claude-cli-llm-provider.js +71 -0
- package/dist/eval/live/claude-cli-llm-provider.js.map +1 -0
- package/dist/eval/live/claude-cli.d.ts +96 -0
- package/dist/eval/live/claude-cli.d.ts.map +1 -0
- package/dist/eval/live/claude-cli.js +314 -0
- package/dist/eval/live/claude-cli.js.map +1 -0
- package/dist/eval/live/claude-delegate.d.ts +41 -0
- package/dist/eval/live/claude-delegate.d.ts.map +1 -0
- package/dist/eval/live/claude-delegate.js +59 -0
- package/dist/eval/live/claude-delegate.js.map +1 -0
- package/dist/eval/live/claude-workspace-backend.d.ts +24 -0
- package/dist/eval/live/claude-workspace-backend.d.ts.map +1 -0
- package/dist/eval/live/claude-workspace-backend.js +76 -0
- package/dist/eval/live/claude-workspace-backend.js.map +1 -0
- package/dist/eval/live/clbench.d.ts +64 -0
- package/dist/eval/live/clbench.d.ts.map +1 -0
- package/dist/eval/live/clbench.js +291 -0
- package/dist/eval/live/clbench.js.map +1 -0
- package/dist/eval/live/cold-reuse.d.ts +21 -0
- package/dist/eval/live/cold-reuse.d.ts.map +1 -0
- package/dist/eval/live/cold-reuse.js +102 -0
- package/dist/eval/live/cold-reuse.js.map +1 -0
- package/dist/eval/live/difficulty-registry.d.ts +68 -0
- package/dist/eval/live/difficulty-registry.d.ts.map +1 -0
- package/dist/eval/live/difficulty-registry.js +169 -0
- package/dist/eval/live/difficulty-registry.js.map +1 -0
- package/dist/eval/live/docker.d.ts +52 -0
- package/dist/eval/live/docker.d.ts.map +1 -0
- package/dist/eval/live/docker.js +164 -0
- package/dist/eval/live/docker.js.map +1 -0
- package/dist/eval/live/env-bridge.d.ts +68 -0
- package/dist/eval/live/env-bridge.d.ts.map +1 -0
- package/dist/eval/live/env-bridge.js +188 -0
- package/dist/eval/live/env-bridge.js.map +1 -0
- package/dist/eval/live/gsm8k.d.ts +44 -0
- package/dist/eval/live/gsm8k.d.ts.map +1 -0
- package/dist/eval/live/gsm8k.js +142 -0
- package/dist/eval/live/gsm8k.js.map +1 -0
- package/dist/eval/live/index.d.ts +38 -0
- package/dist/eval/live/index.d.ts.map +1 -0
- package/dist/eval/live/index.js +38 -0
- package/dist/eval/live/index.js.map +1 -0
- package/dist/eval/live/lifelongagent.d.ts +64 -0
- package/dist/eval/live/lifelongagent.d.ts.map +1 -0
- package/dist/eval/live/lifelongagent.js +216 -0
- package/dist/eval/live/lifelongagent.js.map +1 -0
- package/dist/eval/live/lift-registry.d.ts +128 -0
- package/dist/eval/live/lift-registry.d.ts.map +1 -0
- package/dist/eval/live/lift-registry.js +147 -0
- package/dist/eval/live/lift-registry.js.map +1 -0
- package/dist/eval/live/live-benchmark.d.ts +84 -0
- package/dist/eval/live/live-benchmark.d.ts.map +1 -0
- package/dist/eval/live/live-benchmark.js +2 -0
- package/dist/eval/live/live-benchmark.js.map +1 -0
- package/dist/eval/live/live-runner.d.ts +609 -0
- package/dist/eval/live/live-runner.d.ts.map +1 -0
- package/dist/eval/live/live-runner.js +1409 -0
- package/dist/eval/live/live-runner.js.map +1 -0
- package/dist/eval/live/refine.d.ts +88 -0
- package/dist/eval/live/refine.d.ts.map +1 -0
- package/dist/eval/live/refine.js +135 -0
- package/dist/eval/live/refine.js.map +1 -0
- package/dist/eval/live/registry-store.d.ts +109 -0
- package/dist/eval/live/registry-store.d.ts.map +1 -0
- package/dist/eval/live/registry-store.js +272 -0
- package/dist/eval/live/registry-store.js.map +1 -0
- package/dist/eval/live/run-checkpoint.d.ts +55 -0
- package/dist/eval/live/run-checkpoint.d.ts.map +1 -0
- package/dist/eval/live/run-checkpoint.js +86 -0
- package/dist/eval/live/run-checkpoint.js.map +1 -0
- package/dist/eval/live/run-resume.d.ts +22 -0
- package/dist/eval/live/run-resume.d.ts.map +1 -0
- package/dist/eval/live/run-resume.js +70 -0
- package/dist/eval/live/run-resume.js.map +1 -0
- package/dist/eval/live/skill-injector.d.ts +36 -0
- package/dist/eval/live/skill-injector.d.ts.map +1 -0
- package/dist/eval/live/skill-injector.js +81 -0
- package/dist/eval/live/skill-injector.js.map +1 -0
- package/dist/eval/live/skillflow-embedded-workbook-bundle.d.ts +3 -0
- package/dist/eval/live/skillflow-embedded-workbook-bundle.d.ts.map +1 -0
- package/dist/eval/live/skillflow-embedded-workbook-bundle.js +391 -0
- package/dist/eval/live/skillflow-embedded-workbook-bundle.js.map +1 -0
- package/dist/eval/live/skillflow.d.ts +154 -0
- package/dist/eval/live/skillflow.d.ts.map +1 -0
- package/dist/eval/live/skillflow.js +612 -0
- package/dist/eval/live/skillflow.js.map +1 -0
- package/dist/eval/live/skilllearnbench.d.ts +43 -0
- package/dist/eval/live/skilllearnbench.d.ts.map +1 -0
- package/dist/eval/live/skilllearnbench.js +154 -0
- package/dist/eval/live/skilllearnbench.js.map +1 -0
- package/dist/eval/live/skillopt_v1.d.ts +96 -0
- package/dist/eval/live/skillopt_v1.d.ts.map +1 -0
- package/dist/eval/live/skillopt_v1.js +0 -0
- package/dist/eval/live/skillopt_v1.js.map +1 -0
- package/dist/eval/live/skillopt_v1_causal.d.ts +26 -0
- package/dist/eval/live/skillopt_v1_causal.d.ts.map +1 -0
- package/dist/eval/live/skillopt_v1_causal.js +106 -0
- package/dist/eval/live/skillopt_v1_causal.js.map +1 -0
- package/dist/eval/live/skillopt_v1_memory.d.ts +53 -0
- package/dist/eval/live/skillopt_v1_memory.d.ts.map +1 -0
- package/dist/eval/live/skillopt_v1_memory.js +147 -0
- package/dist/eval/live/skillopt_v1_memory.js.map +1 -0
- package/dist/eval/live/skillopt_v1_rules.d.ts +39 -0
- package/dist/eval/live/skillopt_v1_rules.d.ts.map +1 -0
- package/dist/eval/live/skillopt_v1_rules.js +91 -0
- package/dist/eval/live/skillopt_v1_rules.js.map +1 -0
- package/dist/eval/live/skillsbench.d.ts +138 -0
- package/dist/eval/live/skillsbench.d.ts.map +1 -0
- package/dist/eval/live/skillsbench.js +626 -0
- package/dist/eval/live/skillsbench.js.map +1 -0
- package/dist/eval/live/stopping.d.ts +69 -0
- package/dist/eval/live/stopping.d.ts.map +1 -0
- package/dist/eval/live/stopping.js +213 -0
- package/dist/eval/live/stopping.js.map +1 -0
- package/dist/eval/live/trace.d.ts +20 -0
- package/dist/eval/live/trace.d.ts.map +1 -0
- package/dist/eval/live/trace.js +41 -0
- package/dist/eval/live/trace.js.map +1 -0
- package/dist/eval/mechanism-trace-adapter.d.ts +8 -0
- package/dist/eval/mechanism-trace-adapter.d.ts.map +1 -0
- package/dist/eval/mechanism-trace-adapter.js +118 -0
- package/dist/eval/mechanism-trace-adapter.js.map +1 -0
- package/dist/eval/memory-ab.d.ts +61 -0
- package/dist/eval/memory-ab.d.ts.map +1 -0
- package/dist/eval/memory-ab.js +161 -0
- package/dist/eval/memory-ab.js.map +1 -0
- package/dist/eval/memory-mock.d.ts +54 -0
- package/dist/eval/memory-mock.d.ts.map +1 -0
- package/dist/eval/memory-mock.js +129 -0
- package/dist/eval/memory-mock.js.map +1 -0
- package/dist/eval/memory-qa/index.d.ts +13 -0
- package/dist/eval/memory-qa/index.d.ts.map +1 -0
- package/dist/eval/memory-qa/index.js +13 -0
- package/dist/eval/memory-qa/index.js.map +1 -0
- package/dist/eval/memory-qa/iterative.d.ts +80 -0
- package/dist/eval/memory-qa/iterative.d.ts.map +1 -0
- package/dist/eval/memory-qa/iterative.js +107 -0
- package/dist/eval/memory-qa/iterative.js.map +1 -0
- package/dist/eval/memory-qa/loaders.d.ts +11 -0
- package/dist/eval/memory-qa/loaders.d.ts.map +1 -0
- package/dist/eval/memory-qa/loaders.js +21 -0
- package/dist/eval/memory-qa/loaders.js.map +1 -0
- package/dist/eval/memory-qa/metrics.d.ts +3 -0
- package/dist/eval/memory-qa/metrics.d.ts.map +1 -0
- package/dist/eval/memory-qa/metrics.js +2 -0
- package/dist/eval/memory-qa/metrics.js.map +1 -0
- package/dist/eval/memory-qa/qa.d.ts +186 -0
- package/dist/eval/memory-qa/qa.d.ts.map +1 -0
- package/dist/eval/memory-qa/qa.js +424 -0
- package/dist/eval/memory-qa/qa.js.map +1 -0
- package/dist/eval/memory-qa/retrieval.d.ts +33 -0
- package/dist/eval/memory-qa/retrieval.d.ts.map +1 -0
- package/dist/eval/memory-qa/retrieval.js +44 -0
- package/dist/eval/memory-qa/retrieval.js.map +1 -0
- package/dist/eval/memory-qa/serving.d.ts +60 -0
- package/dist/eval/memory-qa/serving.d.ts.map +1 -0
- package/dist/eval/memory-qa/serving.js +267 -0
- package/dist/eval/memory-qa/serving.js.map +1 -0
- package/dist/eval/memory-qa/types.d.ts +2 -0
- package/dist/eval/memory-qa/types.d.ts.map +1 -0
- package/dist/eval/memory-qa/types.js +2 -0
- package/dist/eval/memory-qa/types.js.map +1 -0
- package/dist/eval/metrics.d.ts +120 -0
- package/dist/eval/metrics.d.ts.map +1 -0
- package/dist/eval/metrics.js +361 -0
- package/dist/eval/metrics.js.map +1 -0
- package/dist/eval/oracle-smoke.d.ts +75 -0
- package/dist/eval/oracle-smoke.d.ts.map +1 -0
- package/dist/eval/oracle-smoke.js +143 -0
- package/dist/eval/oracle-smoke.js.map +1 -0
- package/dist/eval/playbook-calibration-report.d.ts +40 -0
- package/dist/eval/playbook-calibration-report.d.ts.map +1 -0
- package/dist/eval/playbook-calibration-report.js +246 -0
- package/dist/eval/playbook-calibration-report.js.map +1 -0
- package/dist/eval/playbook-candidate-decisions-report.d.ts +36 -0
- package/dist/eval/playbook-candidate-decisions-report.d.ts.map +1 -0
- package/dist/eval/playbook-candidate-decisions-report.js +201 -0
- package/dist/eval/playbook-candidate-decisions-report.js.map +1 -0
- package/dist/eval/playbook-usage-report.d.ts +7 -0
- package/dist/eval/playbook-usage-report.d.ts.map +1 -0
- package/dist/eval/playbook-usage-report.js +222 -0
- package/dist/eval/playbook-usage-report.js.map +1 -0
- package/dist/eval/report.d.ts +28 -0
- package/dist/eval/report.d.ts.map +1 -0
- package/dist/eval/report.js +567 -0
- package/dist/eval/report.js.map +1 -0
- package/dist/eval/retrieval/corpus.d.ts +41 -0
- package/dist/eval/retrieval/corpus.d.ts.map +1 -0
- package/dist/eval/retrieval/corpus.js +158 -0
- package/dist/eval/retrieval/corpus.js.map +1 -0
- package/dist/eval/retrieval/index.d.ts +12 -0
- package/dist/eval/retrieval/index.d.ts.map +1 -0
- package/dist/eval/retrieval/index.js +14 -0
- package/dist/eval/retrieval/index.js.map +1 -0
- package/dist/eval/retrieval/knowledge-corpus.d.ts +91 -0
- package/dist/eval/retrieval/knowledge-corpus.d.ts.map +1 -0
- package/dist/eval/retrieval/knowledge-corpus.js +268 -0
- package/dist/eval/retrieval/knowledge-corpus.js.map +1 -0
- package/dist/eval/retrieval/knowledge-quality.d.ts +91 -0
- package/dist/eval/retrieval/knowledge-quality.d.ts.map +1 -0
- package/dist/eval/retrieval/knowledge-quality.js +247 -0
- package/dist/eval/retrieval/knowledge-quality.js.map +1 -0
- package/dist/eval/retrieval/ladder.d.ts +69 -0
- package/dist/eval/retrieval/ladder.d.ts.map +1 -0
- package/dist/eval/retrieval/ladder.js +80 -0
- package/dist/eval/retrieval/ladder.js.map +1 -0
- package/dist/eval/retrieval/quality.d.ts +39 -0
- package/dist/eval/retrieval/quality.d.ts.map +1 -0
- package/dist/eval/retrieval/quality.js +75 -0
- package/dist/eval/retrieval/quality.js.map +1 -0
- package/dist/eval/rng.d.ts +25 -0
- package/dist/eval/rng.d.ts.map +1 -0
- package/dist/eval/rng.js +43 -0
- package/dist/eval/rng.js.map +1 -0
- package/dist/eval/runner.d.ts +65 -0
- package/dist/eval/runner.d.ts.map +1 -0
- package/dist/eval/runner.js +216 -0
- package/dist/eval/runner.js.map +1 -0
- package/dist/eval/skill-bundle.d.ts +18 -0
- package/dist/eval/skill-bundle.d.ts.map +1 -0
- package/dist/eval/skill-bundle.js +38 -0
- package/dist/eval/skill-bundle.js.map +1 -0
- package/dist/eval/swarmkit-report.d.ts +21 -0
- package/dist/eval/swarmkit-report.d.ts.map +1 -0
- package/dist/eval/swarmkit-report.js +93 -0
- package/dist/eval/swarmkit-report.js.map +1 -0
- package/dist/eval/task-stream.d.ts +22 -0
- package/dist/eval/task-stream.d.ts.map +1 -0
- package/dist/eval/task-stream.js +99 -0
- package/dist/eval/task-stream.js.map +1 -0
- package/dist/eval/types.d.ts +173 -0
- package/dist/eval/types.d.ts.map +1 -0
- package/dist/eval/types.js +11 -0
- package/dist/eval/types.js.map +1 -0
- package/dist/experimental/causal-store.d.ts +97 -0
- package/dist/experimental/causal-store.d.ts.map +1 -0
- package/dist/experimental/causal-store.js +213 -0
- package/dist/experimental/causal-store.js.map +1 -0
- package/dist/experimental/graph-layers/base.d.ts +29 -0
- package/dist/experimental/graph-layers/base.d.ts.map +1 -0
- package/dist/experimental/graph-layers/base.js +143 -0
- package/dist/experimental/graph-layers/base.js.map +1 -0
- package/dist/experimental/graph-layers/causal.d.ts +14 -0
- package/dist/experimental/graph-layers/causal.d.ts.map +1 -0
- package/dist/experimental/graph-layers/causal.js +14 -0
- package/dist/experimental/graph-layers/causal.js.map +1 -0
- package/dist/experimental/graph-layers/entity.d.ts +14 -0
- package/dist/experimental/graph-layers/entity.d.ts.map +1 -0
- package/dist/experimental/graph-layers/entity.js +14 -0
- package/dist/experimental/graph-layers/entity.js.map +1 -0
- package/dist/experimental/graph-layers/index.d.ts +6 -0
- package/dist/experimental/graph-layers/index.d.ts.map +1 -0
- package/dist/experimental/graph-layers/index.js +6 -0
- package/dist/experimental/graph-layers/index.js.map +1 -0
- package/dist/experimental/graph-layers/semantic.d.ts +14 -0
- package/dist/experimental/graph-layers/semantic.d.ts.map +1 -0
- package/dist/experimental/graph-layers/semantic.js +14 -0
- package/dist/experimental/graph-layers/semantic.js.map +1 -0
- package/dist/experimental/graph-layers/temporal.d.ts +14 -0
- package/dist/experimental/graph-layers/temporal.d.ts.map +1 -0
- package/dist/experimental/graph-layers/temporal.js +14 -0
- package/dist/experimental/graph-layers/temporal.js.map +1 -0
- package/dist/experimental/healing-orchestrator.d.ts +182 -0
- package/dist/experimental/healing-orchestrator.d.ts.map +1 -0
- package/dist/experimental/healing-orchestrator.js +250 -0
- package/dist/experimental/healing-orchestrator.js.map +1 -0
- package/dist/experimental/knowledge-graph-types.d.ts +148 -0
- package/dist/experimental/knowledge-graph-types.d.ts.map +1 -0
- package/dist/experimental/knowledge-graph-types.js +40 -0
- package/dist/experimental/knowledge-graph-types.js.map +1 -0
- package/dist/experimental/knowledge-graph.d.ts +41 -0
- package/dist/experimental/knowledge-graph.d.ts.map +1 -0
- package/dist/experimental/knowledge-graph.js +270 -0
- package/dist/experimental/knowledge-graph.js.map +1 -0
- package/dist/experimental/meta-reflection.d.ts +47 -0
- package/dist/experimental/meta-reflection.d.ts.map +1 -0
- package/dist/experimental/meta-reflection.js +143 -0
- package/dist/experimental/meta-reflection.js.map +1 -0
- package/dist/experimental/moe-gate.d.ts +134 -0
- package/dist/experimental/moe-gate.d.ts.map +1 -0
- package/dist/experimental/moe-gate.js +240 -0
- package/dist/experimental/moe-gate.js.map +1 -0
- package/dist/experimental/reasoning-bank.d.ts +130 -0
- package/dist/experimental/reasoning-bank.d.ts.map +1 -0
- package/dist/experimental/reasoning-bank.js +427 -0
- package/dist/experimental/reasoning-bank.js.map +1 -0
- package/dist/experimental/team/team-config.d.ts +127 -0
- package/dist/experimental/team/team-config.d.ts.map +1 -0
- package/dist/experimental/team/team-config.js +48 -0
- package/dist/experimental/team/team-config.js.map +1 -0
- package/dist/experimental/team/team-experience.d.ts +300 -0
- package/dist/experimental/team/team-experience.d.ts.map +1 -0
- package/dist/experimental/team/team-experience.js +355 -0
- package/dist/experimental/team/team-experience.js.map +1 -0
- package/dist/experimental/team/team-ingester.d.ts +152 -0
- package/dist/experimental/team/team-ingester.d.ts.map +1 -0
- package/dist/experimental/team/team-ingester.js +330 -0
- package/dist/experimental/team/team-ingester.js.map +1 -0
- package/dist/experimental/team/team-meta-learner.d.ts +51 -0
- package/dist/experimental/team/team-meta-learner.d.ts.map +1 -0
- package/dist/experimental/team/team-meta-learner.js +404 -0
- package/dist/experimental/team/team-meta-learner.js.map +1 -0
- package/dist/experimental/team/team-meta.d.ts +160 -0
- package/dist/experimental/team/team-meta.d.ts.map +1 -0
- package/dist/experimental/team/team-meta.js +42 -0
- package/dist/experimental/team/team-meta.js.map +1 -0
- package/dist/experimental/team/team-pipeline.d.ts +77 -0
- package/dist/experimental/team/team-pipeline.d.ts.map +1 -0
- package/dist/experimental/team/team-pipeline.js +262 -0
- package/dist/experimental/team/team-pipeline.js.map +1 -0
- package/dist/experimental/team/team-playbook-extraction.d.ts +45 -0
- package/dist/experimental/team/team-playbook-extraction.d.ts.map +1 -0
- package/dist/experimental/team/team-playbook-extraction.js +526 -0
- package/dist/experimental/team/team-playbook-extraction.js.map +1 -0
- package/dist/experimental/team/team-playbook.d.ts +276 -0
- package/dist/experimental/team/team-playbook.d.ts.map +1 -0
- package/dist/experimental/team/team-playbook.js +85 -0
- package/dist/experimental/team/team-playbook.js.map +1 -0
- package/dist/experimental/team/team-router.d.ts +98 -0
- package/dist/experimental/team/team-router.d.ts.map +1 -0
- package/dist/experimental/team/team-router.js +312 -0
- package/dist/experimental/team/team-router.js.map +1 -0
- package/dist/experimental/team/team-skill-library.d.ts +180 -0
- package/dist/experimental/team/team-skill-library.d.ts.map +1 -0
- package/dist/experimental/team/team-skill-library.js +385 -0
- package/dist/experimental/team/team-skill-library.js.map +1 -0
- package/dist/experimental/team/team-trajectory-analysis.d.ts +19 -0
- package/dist/experimental/team/team-trajectory-analysis.d.ts.map +1 -0
- package/dist/experimental/team/team-trajectory-analysis.js +442 -0
- package/dist/experimental/team/team-trajectory-analysis.js.map +1 -0
- package/dist/experimental/team/team-trajectory.d.ts +305 -0
- package/dist/experimental/team/team-trajectory.d.ts.map +1 -0
- package/dist/experimental/team/team-trajectory.js +315 -0
- package/dist/experimental/team/team-trajectory.js.map +1 -0
- package/dist/factory.d.ts +2 -3
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +12 -11
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +9 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -32
- package/dist/index.js.map +1 -1
- package/dist/learning/analyzer.d.ts +26 -36
- package/dist/learning/analyzer.d.ts.map +1 -1
- package/dist/learning/analyzer.js +50 -11
- package/dist/learning/analyzer.js.map +1 -1
- package/dist/learning/compound-bootstrap/external-acquisition.d.ts +63 -0
- package/dist/learning/compound-bootstrap/external-acquisition.d.ts.map +1 -0
- package/dist/learning/compound-bootstrap/external-acquisition.js +255 -0
- package/dist/learning/compound-bootstrap/external-acquisition.js.map +1 -0
- package/dist/learning/compound-bootstrap/index.d.ts +3 -0
- package/dist/learning/compound-bootstrap/index.d.ts.map +1 -0
- package/dist/learning/compound-bootstrap/index.js +3 -0
- package/dist/learning/compound-bootstrap/index.js.map +1 -0
- package/dist/learning/compound-bootstrap/workspace-analyzer.d.ts +33 -0
- package/dist/learning/compound-bootstrap/workspace-analyzer.d.ts.map +1 -0
- package/dist/learning/compound-bootstrap/workspace-analyzer.js +379 -0
- package/dist/learning/compound-bootstrap/workspace-analyzer.js.map +1 -0
- package/dist/learning/consolidation-coordinator.d.ts +49 -0
- package/dist/learning/consolidation-coordinator.d.ts.map +1 -0
- package/dist/learning/consolidation-coordinator.js +75 -0
- package/dist/learning/consolidation-coordinator.js.map +1 -0
- package/dist/learning/convention-distiller.d.ts +84 -0
- package/dist/learning/convention-distiller.d.ts.map +1 -0
- package/dist/learning/convention-distiller.js +268 -0
- package/dist/learning/convention-distiller.js.map +1 -0
- package/dist/learning/distiller.d.ts +82 -0
- package/dist/learning/distiller.d.ts.map +1 -0
- package/dist/learning/distiller.js +353 -0
- package/dist/learning/distiller.js.map +1 -0
- package/dist/learning/effectiveness.d.ts +12 -2
- package/dist/learning/effectiveness.d.ts.map +1 -1
- package/dist/learning/effectiveness.js +18 -14
- package/dist/learning/effectiveness.js.map +1 -1
- package/dist/learning/escalation.d.ts +89 -0
- package/dist/learning/escalation.d.ts.map +1 -0
- package/dist/learning/escalation.js +168 -0
- package/dist/learning/escalation.js.map +1 -0
- package/dist/learning/external-exposure.d.ts +57 -0
- package/dist/learning/external-exposure.d.ts.map +1 -0
- package/dist/learning/external-exposure.js +95 -0
- package/dist/learning/external-exposure.js.map +1 -0
- package/dist/learning/gepa-proposer.d.ts +116 -0
- package/dist/learning/gepa-proposer.d.ts.map +1 -0
- package/dist/learning/gepa-proposer.js +258 -0
- package/dist/learning/gepa-proposer.js.map +1 -0
- package/dist/learning/index.d.ts +21 -8
- package/dist/learning/index.d.ts.map +1 -1
- package/dist/learning/index.js +28 -10
- package/dist/learning/index.js.map +1 -1
- package/dist/learning/instant-loop.d.ts +46 -16
- package/dist/learning/instant-loop.d.ts.map +1 -1
- package/dist/learning/instant-loop.js +114 -111
- package/dist/learning/instant-loop.js.map +1 -1
- package/dist/learning/knowledge-extractor.d.ts.map +1 -1
- package/dist/learning/knowledge-extractor.js +1 -2
- package/dist/learning/knowledge-extractor.js.map +1 -1
- package/dist/learning/llm-extractor.d.ts +88 -0
- package/dist/learning/llm-extractor.d.ts.map +1 -0
- package/dist/learning/llm-extractor.js +372 -0
- package/dist/learning/llm-extractor.js.map +1 -0
- package/dist/learning/loop-coordinator.d.ts +61 -0
- package/dist/learning/loop-coordinator.d.ts.map +1 -0
- package/dist/learning/loop-coordinator.js +96 -0
- package/dist/learning/loop-coordinator.js.map +1 -0
- package/dist/learning/maintenance-scheduler.d.ts +15 -4
- package/dist/learning/maintenance-scheduler.d.ts.map +1 -1
- package/dist/learning/maintenance-scheduler.js +19 -16
- package/dist/learning/maintenance-scheduler.js.map +1 -1
- package/dist/learning/mechanism-trace.d.ts +196 -0
- package/dist/learning/mechanism-trace.d.ts.map +1 -0
- package/dist/learning/mechanism-trace.js +81 -0
- package/dist/learning/mechanism-trace.js.map +1 -0
- package/dist/learning/merge-proposer.d.ts +102 -0
- package/dist/learning/merge-proposer.d.ts.map +1 -0
- package/dist/learning/merge-proposer.js +253 -0
- package/dist/learning/merge-proposer.js.map +1 -0
- package/dist/learning/meta-learner.d.ts +9 -7
- package/dist/learning/meta-learner.d.ts.map +1 -1
- package/dist/learning/meta-learner.js +16 -45
- package/dist/learning/meta-learner.js.map +1 -1
- package/dist/learning/mutation-gate.d.ts +218 -0
- package/dist/learning/mutation-gate.d.ts.map +1 -0
- package/dist/learning/mutation-gate.js +390 -0
- package/dist/learning/mutation-gate.js.map +1 -0
- package/dist/learning/oracle-signal.d.ts +67 -0
- package/dist/learning/oracle-signal.d.ts.map +1 -0
- package/dist/learning/oracle-signal.js +94 -0
- package/dist/learning/oracle-signal.js.map +1 -0
- package/dist/learning/pipeline.d.ts +116 -0
- package/dist/learning/pipeline.d.ts.map +1 -0
- package/dist/learning/pipeline.js +288 -0
- package/dist/learning/pipeline.js.map +1 -0
- package/dist/learning/playbook-extractor.d.ts +8 -0
- package/dist/learning/playbook-extractor.d.ts.map +1 -1
- package/dist/learning/playbook-extractor.js +119 -34
- package/dist/learning/playbook-extractor.js.map +1 -1
- package/dist/learning/playbook-optimizer.d.ts +37 -0
- package/dist/learning/playbook-optimizer.d.ts.map +1 -0
- package/dist/learning/playbook-optimizer.js +125 -0
- package/dist/learning/playbook-optimizer.js.map +1 -0
- package/dist/learning/reflective-proposer.d.ts +173 -0
- package/dist/learning/reflective-proposer.d.ts.map +1 -0
- package/dist/learning/reflective-proposer.js +354 -0
- package/dist/learning/reflective-proposer.js.map +1 -0
- package/dist/learning/reflexion-generator.d.ts.map +1 -1
- package/dist/learning/reflexion-generator.js +4 -3
- package/dist/learning/reflexion-generator.js.map +1 -1
- package/dist/learning/replay-executor.d.ts +64 -0
- package/dist/learning/replay-executor.d.ts.map +1 -0
- package/dist/learning/replay-executor.js +92 -0
- package/dist/learning/replay-executor.js.map +1 -0
- package/dist/learning/replay-types.d.ts +150 -0
- package/dist/learning/replay-types.d.ts.map +1 -0
- package/dist/learning/replay-types.js +207 -0
- package/dist/learning/replay-types.js.map +1 -0
- package/dist/learning/replay.d.ts +166 -0
- package/dist/learning/replay.d.ts.map +1 -0
- package/dist/learning/replay.js +228 -0
- package/dist/learning/replay.js.map +1 -0
- package/dist/learning/seed-report.d.ts +88 -0
- package/dist/learning/seed-report.d.ts.map +1 -0
- package/dist/learning/seed-report.js +120 -0
- package/dist/learning/seed-report.js.map +1 -0
- package/dist/learning/trajectory-sources/dataclaw.d.ts.map +1 -1
- package/dist/learning/trajectory-sources/dataclaw.js +6 -18
- package/dist/learning/trajectory-sources/dataclaw.js.map +1 -1
- package/dist/learning/trajectory-sources/entire.d.ts.map +1 -1
- package/dist/learning/trajectory-sources/entire.js +30 -9
- package/dist/learning/trajectory-sources/entire.js.map +1 -1
- package/dist/learning/trajectory-sources/file.d.ts.map +1 -1
- package/dist/learning/trajectory-sources/file.js.map +1 -1
- package/dist/learning/trajectory-sources/huggingface.d.ts.map +1 -1
- package/dist/learning/trajectory-sources/huggingface.js +7 -7
- package/dist/learning/trajectory-sources/huggingface.js.map +1 -1
- package/dist/learning/trajectory-sources/in-memory.d.ts.map +1 -1
- package/dist/learning/trajectory-sources/in-memory.js.map +1 -1
- package/dist/learning/trajectory-sources/index.d.ts +3 -4
- package/dist/learning/trajectory-sources/index.d.ts.map +1 -1
- package/dist/learning/trajectory-sources/index.js +3 -4
- package/dist/learning/trajectory-sources/index.js.map +1 -1
- package/dist/learning/trajectory-sources/pipeline.d.ts +4 -3
- package/dist/learning/trajectory-sources/pipeline.d.ts.map +1 -1
- package/dist/learning/trajectory-sources/pipeline.js +4 -3
- package/dist/learning/trajectory-sources/pipeline.js.map +1 -1
- package/dist/learning/unified-pipeline.d.ts +486 -61
- package/dist/learning/unified-pipeline.d.ts.map +1 -1
- package/dist/learning/unified-pipeline.js +1501 -232
- package/dist/learning/unified-pipeline.js.map +1 -1
- package/dist/learning/usage-inference.d.ts.map +1 -1
- package/dist/learning/usage-inference.js +4 -9
- package/dist/learning/usage-inference.js.map +1 -1
- package/dist/learning/workspace-snapshot.d.ts +146 -0
- package/dist/learning/workspace-snapshot.d.ts.map +1 -0
- package/dist/learning/workspace-snapshot.js +269 -0
- package/dist/learning/workspace-snapshot.js.map +1 -0
- package/dist/mcp/playbook-server.d.ts +61 -2
- package/dist/mcp/playbook-server.d.ts.map +1 -1
- package/dist/mcp/playbook-server.js +179 -9
- package/dist/mcp/playbook-server.js.map +1 -1
- package/dist/memory/coherence.d.ts.map +1 -1
- package/dist/memory/coherence.js +5 -7
- package/dist/memory/coherence.js.map +1 -1
- package/dist/memory/curated-loader.d.ts +24 -0
- package/dist/memory/curated-loader.d.ts.map +1 -1
- package/dist/memory/curated-loader.js +22 -5
- package/dist/memory/curated-loader.js.map +1 -1
- package/dist/memory/evolution/llm-evolver.d.ts +36 -0
- package/dist/memory/evolution/llm-evolver.d.ts.map +1 -0
- package/dist/memory/evolution/llm-evolver.js +106 -0
- package/dist/memory/evolution/llm-evolver.js.map +1 -0
- package/dist/memory/experience.d.ts +34 -13
- package/dist/memory/experience.d.ts.map +1 -1
- package/dist/memory/experience.js +59 -48
- package/dist/memory/experience.js.map +1 -1
- package/dist/memory/extraction/conversation-extractor.d.ts +62 -0
- package/dist/memory/extraction/conversation-extractor.d.ts.map +1 -0
- package/dist/memory/extraction/conversation-extractor.js +169 -0
- package/dist/memory/extraction/conversation-extractor.js.map +1 -0
- package/dist/memory/filesystem-cascade.d.ts +116 -0
- package/dist/memory/filesystem-cascade.d.ts.map +1 -0
- package/dist/memory/filesystem-cascade.js +221 -0
- package/dist/memory/filesystem-cascade.js.map +1 -0
- package/dist/memory/index.d.ts +14 -10
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +15 -12
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/knowledge-bank.d.ts +145 -29
- package/dist/memory/knowledge-bank.d.ts.map +1 -1
- package/dist/memory/knowledge-bank.js +511 -200
- package/dist/memory/knowledge-bank.js.map +1 -1
- package/dist/memory/knowledge-defrag.d.ts +32 -9
- package/dist/memory/knowledge-defrag.d.ts.map +1 -1
- package/dist/memory/knowledge-defrag.js +57 -49
- package/dist/memory/knowledge-defrag.js.map +1 -1
- package/dist/memory/meta-playbook-bank.d.ts +24 -0
- package/dist/memory/meta-playbook-bank.d.ts.map +1 -0
- package/dist/memory/meta-playbook-bank.js +135 -0
- package/dist/memory/meta-playbook-bank.js.map +1 -0
- package/dist/memory/meta.d.ts.map +1 -1
- package/dist/memory/meta.js +33 -14
- package/dist/memory/meta.js.map +1 -1
- package/dist/memory/playbook-applicability.d.ts +43 -0
- package/dist/memory/playbook-applicability.d.ts.map +1 -0
- package/dist/memory/playbook-applicability.js +155 -0
- package/dist/memory/playbook-applicability.js.map +1 -0
- package/dist/memory/playbook-incorporation.d.ts +24 -0
- package/dist/memory/playbook-incorporation.d.ts.map +1 -0
- package/dist/memory/playbook-incorporation.js +41 -0
- package/dist/memory/playbook-incorporation.js.map +1 -0
- package/dist/memory/playbook.d.ts +444 -7
- package/dist/memory/playbook.d.ts.map +1 -1
- package/dist/memory/playbook.js +1231 -50
- package/dist/memory/playbook.js.map +1 -1
- package/dist/memory/procedural-skill.d.ts +142 -0
- package/dist/memory/procedural-skill.d.ts.map +1 -0
- package/dist/memory/procedural-skill.js +846 -0
- package/dist/memory/procedural-skill.js.map +1 -0
- package/dist/memory/search-provider.d.ts +8 -3
- package/dist/memory/search-provider.d.ts.map +1 -1
- package/dist/memory/search-providers/embedding.d.ts +64 -0
- package/dist/memory/search-providers/embedding.d.ts.map +1 -0
- package/dist/memory/search-providers/embedding.js +96 -0
- package/dist/memory/search-providers/embedding.js.map +1 -0
- package/dist/memory/search-providers/hybrid.d.ts +74 -0
- package/dist/memory/search-providers/hybrid.d.ts.map +1 -0
- package/dist/memory/search-providers/hybrid.js +94 -0
- package/dist/memory/search-providers/hybrid.js.map +1 -0
- package/dist/memory/search-providers/index.d.ts +3 -0
- package/dist/memory/search-providers/index.d.ts.map +1 -1
- package/dist/memory/search-providers/index.js +3 -0
- package/dist/memory/search-providers/index.js.map +1 -1
- package/dist/memory/search-providers/keyword-expanding.d.ts +22 -0
- package/dist/memory/search-providers/keyword-expanding.d.ts.map +1 -0
- package/dist/memory/search-providers/keyword-expanding.js +35 -0
- package/dist/memory/search-providers/keyword-expanding.js.map +1 -0
- package/dist/memory/search-providers/minimem.d.ts +16 -4
- package/dist/memory/search-providers/minimem.d.ts.map +1 -1
- package/dist/memory/search-providers/minimem.js +14 -3
- package/dist/memory/search-providers/minimem.js.map +1 -1
- package/dist/memory/search-providers/text-similarity.d.ts +2 -4
- package/dist/memory/search-providers/text-similarity.d.ts.map +1 -1
- package/dist/memory/search-providers/text-similarity.js.map +1 -1
- package/dist/memory/seeds/meta-playbook-seeds.d.ts +27 -0
- package/dist/memory/seeds/meta-playbook-seeds.d.ts.map +1 -0
- package/dist/memory/seeds/meta-playbook-seeds.js +560 -0
- package/dist/memory/seeds/meta-playbook-seeds.js.map +1 -0
- package/dist/memory/seeds/meta-strategy-seeds.d.ts +23 -0
- package/dist/memory/seeds/meta-strategy-seeds.d.ts.map +1 -0
- package/dist/memory/seeds/meta-strategy-seeds.js +82 -0
- package/dist/memory/seeds/meta-strategy-seeds.js.map +1 -0
- package/dist/memory/seeds/seed-loader.d.ts +34 -0
- package/dist/memory/seeds/seed-loader.d.ts.map +1 -0
- package/dist/memory/seeds/seed-loader.js +60 -0
- package/dist/memory/seeds/seed-loader.js.map +1 -0
- package/dist/memory/skill-exporter.d.ts.map +1 -1
- package/dist/memory/skill-exporter.js +1 -2
- package/dist/memory/skill-exporter.js.map +1 -1
- package/dist/memory/source-resolver.d.ts.map +1 -1
- package/dist/memory/source-resolver.js +7 -8
- package/dist/memory/source-resolver.js.map +1 -1
- package/dist/memory/system.d.ts +119 -14
- package/dist/memory/system.d.ts.map +1 -1
- package/dist/memory/system.js +416 -60
- package/dist/memory/system.js.map +1 -1
- package/dist/memory/temporal-compressor.d.ts +1 -1
- package/dist/memory/temporal-compressor.d.ts.map +1 -1
- package/dist/memory/temporal-compressor.js +26 -16
- package/dist/memory/temporal-compressor.js.map +1 -1
- package/dist/persistence/index.d.ts +2 -2
- package/dist/persistence/index.d.ts.map +1 -1
- package/dist/persistence/index.js +1 -1
- package/dist/persistence/index.js.map +1 -1
- package/dist/persistence/migrator.d.ts +34 -1
- package/dist/persistence/migrator.d.ts.map +1 -1
- package/dist/persistence/migrator.js +163 -33
- package/dist/persistence/migrator.js.map +1 -1
- package/dist/persistence/sqlite-persistence.d.ts +412 -1
- package/dist/persistence/sqlite-persistence.d.ts.map +1 -1
- package/dist/persistence/sqlite-persistence.js +1038 -47
- package/dist/persistence/sqlite-persistence.js.map +1 -1
- package/dist/runtime/backends/acp-protocol.d.ts.map +1 -1
- package/dist/runtime/backends/acp-protocol.js +2 -1
- package/dist/runtime/backends/acp-protocol.js.map +1 -1
- package/dist/runtime/backends/acp.d.ts.map +1 -1
- package/dist/runtime/backends/acp.js +5 -4
- package/dist/runtime/backends/acp.js.map +1 -1
- package/dist/runtime/backends/index.d.ts +2 -2
- package/dist/runtime/backends/index.d.ts.map +1 -1
- package/dist/runtime/backends/index.js +2 -2
- package/dist/runtime/backends/index.js.map +1 -1
- package/dist/runtime/backends/macro-agent.d.ts +17 -1
- package/dist/runtime/backends/macro-agent.d.ts.map +1 -1
- package/dist/runtime/backends/macro-agent.js +1 -1
- package/dist/runtime/backends/macro-agent.js.map +1 -1
- package/dist/runtime/backends/mock.d.ts.map +1 -1
- package/dist/runtime/backends/mock.js.map +1 -1
- package/dist/runtime/backends/subprocess.d.ts.map +1 -1
- package/dist/runtime/backends/subprocess.js +5 -4
- package/dist/runtime/backends/subprocess.js.map +1 -1
- package/dist/runtime/compute-provider.d.ts +2 -18
- package/dist/runtime/compute-provider.d.ts.map +1 -1
- package/dist/runtime/compute-provider.js +8 -8
- package/dist/runtime/compute-provider.js.map +1 -1
- package/dist/runtime/flows/learning.d.ts +2 -1
- package/dist/runtime/flows/learning.d.ts.map +1 -1
- package/dist/runtime/flows/learning.js +4 -5
- package/dist/runtime/flows/learning.js.map +1 -1
- package/dist/runtime/flows/validation.d.ts.map +1 -1
- package/dist/runtime/flows/validation.js +2 -5
- package/dist/runtime/flows/validation.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/manager.d.ts +128 -0
- package/dist/runtime/manager.d.ts.map +1 -1
- package/dist/runtime/manager.js +375 -64
- package/dist/runtime/manager.js.map +1 -1
- package/dist/runtime/types.d.ts +92 -1
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/search/evaluator.d.ts +71 -0
- package/dist/search/evaluator.d.ts.map +1 -1
- package/dist/search/evaluator.js +40 -5
- package/dist/search/evaluator.js.map +1 -1
- package/dist/search/index.d.ts +3 -5
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +4 -7
- package/dist/search/index.js.map +1 -1
- package/dist/search/moe-gate.d.ts +48 -2
- package/dist/search/moe-gate.d.ts.map +1 -1
- package/dist/search/moe-gate.js +117 -4
- package/dist/search/moe-gate.js.map +1 -1
- package/dist/search/refinement-loop.d.ts +63 -3
- package/dist/search/refinement-loop.d.ts.map +1 -1
- package/dist/search/refinement-loop.js +278 -23
- package/dist/search/refinement-loop.js.map +1 -1
- package/dist/search/refinement-types.d.ts +4 -2
- package/dist/search/refinement-types.d.ts.map +1 -1
- package/dist/search/refinement-types.js +2 -11
- package/dist/search/refinement-types.js.map +1 -1
- package/dist/search/router.d.ts +41 -34
- package/dist/search/router.d.ts.map +1 -1
- package/dist/search/router.js +156 -90
- package/dist/search/router.js.map +1 -1
- package/dist/search/solver.js +1 -1
- package/dist/search/solver.js.map +1 -1
- package/dist/search/task-difficulty.d.ts +54 -0
- package/dist/search/task-difficulty.d.ts.map +1 -0
- package/dist/search/task-difficulty.js +116 -0
- package/dist/search/task-difficulty.js.map +1 -0
- package/dist/search/tau-bench-verifier.d.ts +74 -0
- package/dist/search/tau-bench-verifier.d.ts.map +1 -0
- package/dist/search/tau-bench-verifier.js +96 -0
- package/dist/search/tau-bench-verifier.js.map +1 -0
- package/dist/search/verification-runner.d.ts.map +1 -1
- package/dist/search/verification-runner.js +6 -5
- package/dist/search/verification-runner.js.map +1 -1
- package/dist/session-bank/git-reader.d.ts.map +1 -1
- package/dist/session-bank/git-reader.js +5 -19
- package/dist/session-bank/git-reader.js.map +1 -1
- package/dist/session-bank/parser.d.ts.map +1 -1
- package/dist/session-bank/parser.js +26 -0
- package/dist/session-bank/parser.js.map +1 -1
- package/dist/session-bank/session-bank.d.ts.map +1 -1
- package/dist/session-bank/session-bank.js +2 -5
- package/dist/session-bank/session-bank.js.map +1 -1
- package/dist/session-bank/types.d.ts +24 -0
- package/dist/session-bank/types.d.ts.map +1 -1
- package/dist/surfacing/index.d.ts +3 -3
- package/dist/surfacing/index.d.ts.map +1 -1
- package/dist/surfacing/index.js +2 -2
- package/dist/surfacing/index.js.map +1 -1
- package/dist/surfacing/shared-bank.d.ts +43 -0
- package/dist/surfacing/shared-bank.d.ts.map +1 -0
- package/dist/surfacing/shared-bank.js +104 -0
- package/dist/surfacing/shared-bank.js.map +1 -0
- package/dist/surfacing/skill-library.d.ts +98 -2
- package/dist/surfacing/skill-library.d.ts.map +1 -1
- package/dist/surfacing/skill-library.js +192 -17
- package/dist/surfacing/skill-library.js.map +1 -1
- package/dist/surfacing/skill-publisher.d.ts +6 -4
- package/dist/surfacing/skill-publisher.d.ts.map +1 -1
- package/dist/surfacing/skill-publisher.js +32 -30
- 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 +12 -8
- package/dist/surfacing/sqlite-storage-adapter.js.map +1 -1
- package/dist/types/analysis.d.ts +43 -0
- package/dist/types/analysis.d.ts.map +1 -0
- package/dist/types/analysis.js +10 -0
- package/dist/types/analysis.js.map +1 -0
- package/dist/types/config.d.ts +2178 -425
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +600 -88
- package/dist/types/config.js.map +1 -1
- package/dist/types/dataclaw.d.ts +3 -3
- package/dist/types/index.d.ts +4 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -10
- package/dist/types/index.js.map +1 -1
- package/dist/types/knowledge-graph.d.ts +1 -1
- package/dist/types/knowledge-graph.d.ts.map +1 -1
- package/dist/types/knowledge.d.ts +219 -11
- package/dist/types/knowledge.d.ts.map +1 -1
- package/dist/types/knowledge.js +90 -30
- package/dist/types/knowledge.js.map +1 -1
- package/dist/types/memory.d.ts +8 -0
- package/dist/types/memory.d.ts.map +1 -1
- package/dist/types/memory.js +12 -4
- package/dist/types/memory.js.map +1 -1
- package/dist/types/outcome.d.ts +11 -0
- package/dist/types/outcome.d.ts.map +1 -1
- package/dist/types/outcome.js +9 -0
- package/dist/types/outcome.js.map +1 -1
- package/dist/types/playbook.d.ts +63 -0
- package/dist/types/playbook.d.ts.map +1 -1
- package/dist/types/playbook.js +51 -0
- package/dist/types/playbook.js.map +1 -1
- package/dist/types/trajectory-source.d.ts +1 -1
- package/dist/types/trajectory-source.d.ts.map +1 -1
- package/dist/types/trajectory.d.ts +61 -0
- package/dist/types/trajectory.d.ts.map +1 -1
- package/dist/types/trajectory.js +25 -0
- package/dist/types/trajectory.js.map +1 -1
- package/dist/utils/clock.d.ts +36 -0
- package/dist/utils/clock.d.ts.map +1 -0
- package/dist/utils/clock.js +48 -0
- package/dist/utils/clock.js.map +1 -0
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +10 -2
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/index.d.ts +4 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/logger.d.ts +31 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +50 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/objectives.d.ts +45 -0
- package/dist/utils/objectives.d.ts.map +1 -0
- package/dist/utils/objectives.js +74 -0
- package/dist/utils/objectives.js.map +1 -0
- package/dist/utils/partitioned-store.d.ts.map +1 -1
- package/dist/utils/partitioned-store.js.map +1 -1
- package/dist/utils/playbook-hash.d.ts +19 -0
- package/dist/utils/playbook-hash.d.ts.map +1 -0
- package/dist/utils/playbook-hash.js +51 -0
- package/dist/utils/playbook-hash.js.map +1 -0
- package/dist/utils/similarity.d.ts.map +1 -1
- package/dist/utils/similarity.js.map +1 -1
- package/dist/utils/solver-canonicalizer.d.ts +22 -0
- package/dist/utils/solver-canonicalizer.d.ts.map +1 -0
- package/dist/utils/solver-canonicalizer.js +41 -0
- package/dist/utils/solver-canonicalizer.js.map +1 -0
- package/dist/utils/storage.d.ts.map +1 -1
- package/dist/utils/storage.js +1 -3
- package/dist/utils/storage.js.map +1 -1
- package/dist/utils/task-signature.d.ts +34 -0
- package/dist/utils/task-signature.d.ts.map +1 -0
- package/dist/utils/task-signature.js +112 -0
- package/dist/utils/task-signature.js.map +1 -0
- package/dist/utils/trajectory-helpers.d.ts.map +1 -1
- package/dist/utils/trajectory-helpers.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js.map +1 -1
- package/dist/workspace/efficacy-toolkit.d.ts.map +1 -1
- package/dist/workspace/efficacy-toolkit.js +18 -26
- package/dist/workspace/efficacy-toolkit.js.map +1 -1
- package/dist/workspace/index.d.ts +4 -3
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +5 -3
- package/dist/workspace/index.js.map +1 -1
- package/dist/workspace/runner.d.ts.map +1 -1
- package/dist/workspace/runner.js +95 -21
- package/dist/workspace/runner.js.map +1 -1
- package/dist/workspace/skill-converter.d.ts +66 -1
- package/dist/workspace/skill-converter.d.ts.map +1 -1
- package/dist/workspace/skill-converter.js +238 -19
- package/dist/workspace/skill-converter.js.map +1 -1
- package/dist/workspace/skill-import.d.ts +43 -0
- package/dist/workspace/skill-import.d.ts.map +1 -0
- package/dist/workspace/skill-import.js +40 -0
- package/dist/workspace/skill-import.js.map +1 -0
- package/dist/workspace/templates/index.d.ts +6 -8
- package/dist/workspace/templates/index.d.ts.map +1 -1
- package/dist/workspace/templates/index.js +7 -11
- package/dist/workspace/templates/index.js.map +1 -1
- package/dist/workspace/templates/knowledge-defrag.d.ts.map +1 -1
- package/dist/workspace/templates/knowledge-defrag.js +0 -2
- package/dist/workspace/templates/knowledge-defrag.js.map +1 -1
- package/dist/workspace/templates/knowledge-extraction.d.ts +11 -0
- package/dist/workspace/templates/knowledge-extraction.d.ts.map +1 -1
- package/dist/workspace/templates/knowledge-extraction.js +11 -6
- package/dist/workspace/templates/knowledge-extraction.js.map +1 -1
- package/dist/workspace/templates/playbook-conditioning.d.ts +38 -0
- package/dist/workspace/templates/playbook-conditioning.d.ts.map +1 -0
- package/dist/workspace/templates/playbook-conditioning.js +147 -0
- package/dist/workspace/templates/playbook-conditioning.js.map +1 -0
- package/dist/workspace/templates/playbook-decay-detection.d.ts.map +1 -1
- package/dist/workspace/templates/playbook-decay-detection.js +24 -18
- package/dist/workspace/templates/playbook-decay-detection.js.map +1 -1
- package/dist/workspace/templates/playbook-efficacy-audit.d.ts.map +1 -1
- package/dist/workspace/templates/playbook-efficacy-audit.js +26 -11
- package/dist/workspace/templates/playbook-efficacy-audit.js.map +1 -1
- package/dist/workspace/templates/playbook-extraction.d.ts.map +1 -1
- package/dist/workspace/templates/playbook-extraction.js +75 -15
- package/dist/workspace/templates/playbook-extraction.js.map +1 -1
- package/dist/workspace/templates/playbook-lifecycle-review.d.ts.map +1 -1
- package/dist/workspace/templates/playbook-lifecycle-review.js +12 -8
- package/dist/workspace/templates/playbook-lifecycle-review.js.map +1 -1
- package/dist/workspace/templates/refinement-analysis.d.ts.map +1 -1
- package/dist/workspace/templates/refinement-analysis.js +11 -5
- package/dist/workspace/templates/refinement-analysis.js.map +1 -1
- package/dist/workspace/templates/skill-enrichment.d.ts.map +1 -1
- package/dist/workspace/templates/skill-enrichment.js +7 -11
- package/dist/workspace/templates/skill-enrichment.js.map +1 -1
- package/dist/workspace/templates/solution-evaluation.d.ts.map +1 -1
- package/dist/workspace/templates/solution-evaluation.js +15 -8
- package/dist/workspace/templates/solution-evaluation.js.map +1 -1
- package/dist/workspace/templates/trajectory-analysis.d.ts.map +1 -1
- package/dist/workspace/templates/trajectory-analysis.js +1 -3
- package/dist/workspace/templates/trajectory-analysis.js.map +1 -1
- package/dist/workspace/templates/usage-inference.d.ts.map +1 -1
- package/dist/workspace/templates/usage-inference.js +9 -7
- package/dist/workspace/templates/usage-inference.js.map +1 -1
- package/dist/workspace/types.d.ts +32 -2
- package/dist/workspace/types.d.ts.map +1 -1
- package/dist/workspace/types.js +29 -0
- package/dist/workspace/types.js.map +1 -1
- package/package.json +43 -19
- package/playbooks/agent-ops/long-task-checkpointing.json +54 -0
- package/playbooks/agent-ops/progressive-context-gathering.json +56 -0
- package/playbooks/agent-ops/safe-destructive-operations.json +59 -0
- package/playbooks/agent-ops/scope-discipline.json +56 -0
- package/playbooks/agent-ops/stall-detection-strategy-switch.json +55 -0
- package/playbooks/agent-ops/verification-before-completion.json +54 -0
- package/playbooks/alfworld/clean-and-place.json +35 -0
- package/playbooks/alfworld/cool-and-place.json +35 -0
- package/playbooks/alfworld/examine-in-light.json +32 -0
- package/playbooks/alfworld/heat-and-place.json +35 -0
- package/playbooks/alfworld/pick-and-place.json +37 -0
- package/playbooks/alfworld/pick-two-and-place.json +35 -0
- package/.claude/settings.json +0 -197
- package/.entire/settings.json +0 -4
- package/.sessionlog/settings.json +0 -4
- package/CLAUDE.md +0 -233
- package/SKILL.md +0 -193
- package/docs/DESIGN-agentic-workspace.md +0 -2057
- package/docs/DESIGN-semantic-memory-knowledge-bank.md +0 -1789
- package/docs/DESIGN-session-bank.md +0 -1134
- package/docs/DESIGN-team-extraction-pipeline.md +0 -1369
- package/docs/PROPOSAL-team-aware-learning.md +0 -1080
- package/docs/RESEARCH-semantic-memory-knowledge-structures.md +0 -517
- package/docs/RESEARCH-team-trajectory-learning.md +0 -553
- package/gaps.md +0 -204
- package/scripts/migrate-to-playbooks.ts +0 -307
- package/src/agents/index.ts +0 -14
- package/src/agents/mock-provider.ts +0 -93
- package/src/agents/types.ts +0 -137
- package/src/atlas.ts +0 -1198
- package/src/bin/cli-utils.ts +0 -220
- package/src/bin/cognitive-core.ts +0 -162
- package/src/bin/commands/kb.ts +0 -266
- package/src/bin/commands/learn.ts +0 -100
- package/src/bin/commands/legacy.ts +0 -182
- package/src/bin/commands/run.ts +0 -113
- package/src/bin/commands/sessions.ts +0 -221
- package/src/bin/commands/skills.ts +0 -146
- package/src/embeddings/bm25.ts +0 -337
- package/src/embeddings/index.ts +0 -42
- package/src/embeddings/inverted-index.ts +0 -134
- package/src/embeddings/manager.ts +0 -293
- package/src/embeddings/provider.ts +0 -318
- package/src/embeddings/vector-store.ts +0 -365
- package/src/factory.ts +0 -280
- package/src/index.ts +0 -495
- package/src/learning/analyzer.ts +0 -319
- package/src/learning/effectiveness.ts +0 -428
- package/src/learning/energy-evaluator.ts +0 -282
- package/src/learning/healing-orchestrator.ts +0 -383
- package/src/learning/index.ts +0 -150
- package/src/learning/instant-loop.ts +0 -357
- package/src/learning/knowledge-extractor.ts +0 -470
- package/src/learning/maintenance-scheduler.ts +0 -271
- package/src/learning/meta-learner.ts +0 -552
- package/src/learning/playbook-extractor.ts +0 -702
- package/src/learning/reflexion-generator.ts +0 -273
- package/src/learning/team-ingester.ts +0 -499
- package/src/learning/team-meta-learner.ts +0 -558
- package/src/learning/team-pipeline.ts +0 -364
- package/src/learning/trajectory-sources/dataclaw.ts +0 -403
- package/src/learning/trajectory-sources/entire.ts +0 -251
- package/src/learning/trajectory-sources/file.ts +0 -136
- package/src/learning/trajectory-sources/huggingface.ts +0 -248
- package/src/learning/trajectory-sources/in-memory.ts +0 -61
- package/src/learning/trajectory-sources/index.ts +0 -15
- package/src/learning/trajectory-sources/pipeline.ts +0 -69
- package/src/learning/unified-pipeline.ts +0 -1191
- package/src/learning/usage-inference.ts +0 -372
- package/src/mcp/index.ts +0 -12
- package/src/mcp/playbook-server.ts +0 -565
- package/src/memory/candidate-retrieval.ts +0 -72
- package/src/memory/causal-store.ts +0 -273
- package/src/memory/coherence.ts +0 -252
- package/src/memory/curated-loader.ts +0 -213
- package/src/memory/experience.ts +0 -682
- package/src/memory/graph-layers/base.ts +0 -184
- package/src/memory/graph-layers/causal.ts +0 -16
- package/src/memory/graph-layers/entity.ts +0 -16
- package/src/memory/graph-layers/index.ts +0 -5
- package/src/memory/graph-layers/semantic.ts +0 -16
- package/src/memory/graph-layers/temporal.ts +0 -16
- package/src/memory/index.ts +0 -131
- package/src/memory/knowledge-bank.ts +0 -1317
- package/src/memory/knowledge-defrag.ts +0 -329
- package/src/memory/knowledge-graph.ts +0 -361
- package/src/memory/meta.ts +0 -488
- package/src/memory/playbook.ts +0 -676
- package/src/memory/reasoning-bank.ts +0 -458
- package/src/memory/reflexion.ts +0 -122
- package/src/memory/search-provider.ts +0 -35
- package/src/memory/search-providers/index.ts +0 -3
- package/src/memory/search-providers/minimem.ts +0 -84
- package/src/memory/search-providers/text-similarity.ts +0 -35
- package/src/memory/skill-exporter.ts +0 -357
- package/src/memory/source-resolver.ts +0 -422
- package/src/memory/system.ts +0 -620
- package/src/memory/team-experience.ts +0 -604
- package/src/memory/temporal-compressor.ts +0 -409
- package/src/persistence/index.ts +0 -37
- package/src/persistence/migrator.ts +0 -298
- package/src/persistence/serializers.ts +0 -79
- package/src/persistence/sqlite-persistence.ts +0 -925
- package/src/runtime/backends/acp-protocol.ts +0 -231
- package/src/runtime/backends/acp.ts +0 -239
- package/src/runtime/backends/index.ts +0 -38
- package/src/runtime/backends/macro-agent.ts +0 -177
- package/src/runtime/backends/mock.ts +0 -218
- package/src/runtime/backends/subprocess.ts +0 -356
- package/src/runtime/compute-provider.ts +0 -206
- package/src/runtime/flows/learning.ts +0 -166
- package/src/runtime/flows/validation.ts +0 -381
- package/src/runtime/index.ts +0 -75
- package/src/runtime/manager.ts +0 -685
- package/src/runtime/types.ts +0 -198
- package/src/search/evaluator.ts +0 -499
- package/src/search/index.ts +0 -78
- package/src/search/moe-gate.ts +0 -304
- package/src/search/refinement-loop.ts +0 -457
- package/src/search/refinement-types.ts +0 -159
- package/src/search/router.ts +0 -368
- package/src/search/solver.ts +0 -303
- package/src/search/team-router.ts +0 -459
- package/src/search/verification-runner.ts +0 -570
- package/src/session-bank/git-reader.ts +0 -200
- package/src/session-bank/index.ts +0 -26
- package/src/session-bank/parser.ts +0 -548
- package/src/session-bank/session-bank.ts +0 -485
- package/src/session-bank/types.ts +0 -176
- package/src/surfacing/index.ts +0 -29
- package/src/surfacing/publisher.ts +0 -23
- package/src/surfacing/skill-library.ts +0 -625
- package/src/surfacing/skill-publisher.ts +0 -258
- package/src/surfacing/sqlite-storage-adapter.ts +0 -287
- package/src/surfacing/team-skill-library.ts +0 -610
- package/src/types/config.ts +0 -661
- package/src/types/dataclaw.ts +0 -99
- package/src/types/huggingface-transformers.d.ts +0 -12
- package/src/types/index.ts +0 -293
- package/src/types/knowledge-graph.ts +0 -246
- package/src/types/knowledge.ts +0 -388
- package/src/types/memory.ts +0 -300
- package/src/types/meta.ts +0 -218
- package/src/types/outcome.ts +0 -66
- package/src/types/playbook.ts +0 -215
- package/src/types/step.ts +0 -40
- package/src/types/task.ts +0 -52
- package/src/types/team-meta.ts +0 -212
- package/src/types/team-playbook.ts +0 -384
- package/src/types/team-trajectory.ts +0 -673
- package/src/types/trajectory-source.ts +0 -47
- package/src/types/trajectory.ts +0 -80
- package/src/utils/error-classifier.ts +0 -113
- package/src/utils/frontmatter.ts +0 -118
- package/src/utils/index.ts +0 -63
- package/src/utils/partitioned-store.ts +0 -299
- package/src/utils/similarity.ts +0 -139
- package/src/utils/storage.ts +0 -249
- package/src/utils/trajectory-helpers.ts +0 -79
- package/src/utils/validation.ts +0 -286
- package/src/workspace/efficacy-toolkit.ts +0 -496
- package/src/workspace/index.ts +0 -77
- package/src/workspace/runner.ts +0 -281
- package/src/workspace/skill-converter.ts +0 -288
- package/src/workspace/templates/index.ts +0 -95
- package/src/workspace/templates/knowledge-defrag.ts +0 -223
- package/src/workspace/templates/knowledge-extraction.ts +0 -337
- package/src/workspace/templates/meta-reflection.ts +0 -208
- package/src/workspace/templates/playbook-decay-detection.ts +0 -272
- package/src/workspace/templates/playbook-efficacy-audit.ts +0 -246
- package/src/workspace/templates/playbook-extraction.ts +0 -240
- package/src/workspace/templates/playbook-lifecycle-review.ts +0 -274
- package/src/workspace/templates/refinement-analysis.ts +0 -162
- package/src/workspace/templates/skill-enrichment.ts +0 -275
- package/src/workspace/templates/solution-evaluation.ts +0 -199
- package/src/workspace/templates/team-playbook-extraction.ts +0 -631
- package/src/workspace/templates/team-trajectory-analysis.ts +0 -564
- package/src/workspace/templates/trajectory-analysis.ts +0 -234
- package/src/workspace/templates/usage-inference.ts +0 -163
- package/src/workspace/types.ts +0 -185
- package/tests/atlas-knowledge.test.ts +0 -165
- package/tests/embeddings/bm25.test.ts +0 -130
- package/tests/embeddings/inverted-index.test.ts +0 -138
- package/tests/embeddings/manager.test.ts +0 -205
- package/tests/feature-toggles.test.ts +0 -275
- package/tests/fixtures/behavioral-trajectories.ts +0 -210
- package/tests/gap-fixes.test.ts +0 -1116
- package/tests/integration/atlas.test.ts +0 -266
- package/tests/integration/cli-e2e.test.ts +0 -621
- package/tests/integration/curated-sources-e2e.test.ts +0 -502
- package/tests/integration/dataclaw-e2e.test.ts +0 -559
- package/tests/integration/e2e.test.ts +0 -1337
- package/tests/integration/entire-e2e.test.ts +0 -376
- package/tests/integration/huggingface-e2e.test.ts +0 -627
- package/tests/integration/persistence-e2e.test.ts +0 -741
- package/tests/integration/phase-e2e.test.ts +0 -1143
- package/tests/integration/pipeline-data-correctness.test.ts +0 -794
- package/tests/integration/ranking-driven-loadout-e2e.test.ts +0 -185
- package/tests/integration/session-bank.test.ts +0 -231
- package/tests/integration/sessionlog-e2e.test.ts +0 -329
- package/tests/integration/skill-publishing-filesystem-e2e.test.ts +0 -216
- package/tests/integration/skill-tree-wiring.test.ts +0 -152
- package/tests/integration/unified-pipeline-e2e.test.ts +0 -634
- package/tests/learning/analyzer.test.ts +0 -426
- package/tests/learning/dataclaw-trajectory-source.test.ts +0 -642
- package/tests/learning/effectiveness.test.ts +0 -542
- package/tests/learning/energy-evaluator.test.ts +0 -180
- package/tests/learning/entire-trajectory-source.test.ts +0 -380
- package/tests/learning/healing-orchestrator.test.ts +0 -269
- package/tests/learning/huggingface-trajectory-source.test.ts +0 -817
- package/tests/learning/instant-loop.test.ts +0 -243
- package/tests/learning/knowledge-extractor.test.ts +0 -491
- package/tests/learning/maintenance-scheduler.test.ts +0 -191
- package/tests/learning/meta-learner.test.ts +0 -418
- package/tests/learning/pipeline-memory-updates.test.ts +0 -721
- package/tests/learning/playbook-extractor-provenance.test.ts +0 -114
- package/tests/learning/reflexion-generator.test.ts +0 -411
- package/tests/learning/team-ingester.test.ts +0 -349
- package/tests/learning/team-meta-learner.test.ts +0 -618
- package/tests/learning/team-pipeline.test.ts +0 -334
- package/tests/learning/trajectory-sources.test.ts +0 -320
- package/tests/learning/unified-pipeline-efficacy.test.ts +0 -232
- package/tests/learning/unified-pipeline.test.ts +0 -322
- package/tests/learning/usage-inference.test.ts +0 -254
- package/tests/mcp/playbook-server.test.ts +0 -257
- package/tests/memory/candidate-retrieval.test.ts +0 -167
- package/tests/memory/causal-store.test.ts +0 -276
- package/tests/memory/coherence.test.ts +0 -232
- package/tests/memory/compound-engineering-seed.test.ts +0 -338
- package/tests/memory/curated-loader-extended.test.ts +0 -225
- package/tests/memory/experience.test.ts +0 -203
- package/tests/memory/graph-layers/semantic.test.ts +0 -219
- package/tests/memory/knowledge-bank-extraction.test.ts +0 -558
- package/tests/memory/knowledge-bank.test.ts +0 -705
- package/tests/memory/knowledge-defrag.test.ts +0 -366
- package/tests/memory/knowledge-evolution.test.ts +0 -563
- package/tests/memory/knowledge-graph.test.ts +0 -492
- package/tests/memory/knowledge-inbox.test.ts +0 -258
- package/tests/memory/knowledge-minimem.test.ts +0 -251
- package/tests/memory/meta.test.ts +0 -399
- package/tests/memory/playbook-quality-validation.test.ts +0 -430
- package/tests/memory/playbook.test.ts +0 -644
- package/tests/memory/provenance.test.ts +0 -648
- package/tests/memory/reasoning-bank.test.ts +0 -239
- package/tests/memory/reflexion.test.ts +0 -166
- package/tests/memory/skill-exporter.test.ts +0 -475
- package/tests/memory/source-resolver.test.ts +0 -700
- package/tests/memory/system.test.ts +0 -330
- package/tests/memory/team-experience.test.ts +0 -411
- package/tests/memory/temporal-compressor.test.ts +0 -318
- package/tests/persistence/migrator.test.ts +0 -1009
- package/tests/persistence/sqlite-persistence.test.ts +0 -635
- package/tests/runtime/agent-manager.test.ts +0 -517
- package/tests/runtime/compute-provider.test.ts +0 -288
- package/tests/runtime/delegate.test.ts +0 -354
- package/tests/runtime/macro-agent-backend.test.ts +0 -266
- package/tests/runtime/mock-backend.test.ts +0 -248
- package/tests/search/evaluator.test.ts +0 -257
- package/tests/search/moe-gate.test.ts +0 -250
- package/tests/search/refinement-loop.test.ts +0 -477
- package/tests/search/refinement.test.ts +0 -267
- package/tests/search/router.test.ts +0 -506
- package/tests/search/team-router.test.ts +0 -376
- package/tests/search/verification-runner.test.ts +0 -357
- package/tests/session-bank/fixtures/multi-tool-session/full.jsonl +0 -12
- package/tests/session-bank/fixtures/multi-tool-session/metadata.json +0 -28
- package/tests/session-bank/fixtures/root-metadata.json +0 -18
- package/tests/session-bank/fixtures/sessionlog-root-metadata.json +0 -16
- package/tests/session-bank/fixtures/sessionlog-session/full.jsonl +0 -6
- package/tests/session-bank/fixtures/sessionlog-session/metadata.json +0 -55
- package/tests/session-bank/fixtures/simple-session/full.jsonl +0 -6
- package/tests/session-bank/fixtures/simple-session/metadata.json +0 -38
- package/tests/session-bank/git-reader.test.ts +0 -232
- package/tests/session-bank/parser.test.ts +0 -453
- package/tests/session-bank/session-bank.test.ts +0 -546
- package/tests/surfacing/skill-library.test.ts +0 -297
- package/tests/surfacing/skill-publisher.test.ts +0 -432
- package/tests/surfacing/sqlite-storage-adapter.test.ts +0 -197
- package/tests/surfacing/team-skill-library.test.ts +0 -444
- package/tests/types/outcome.test.ts +0 -147
- package/tests/types/step.test.ts +0 -133
- package/tests/types/task.test.ts +0 -158
- package/tests/types/team-meta.test.ts +0 -147
- package/tests/types/team-playbook.test.ts +0 -246
- package/tests/types/team-trajectory.test.ts +0 -557
- package/tests/types/trajectory.test.ts +0 -253
- package/tests/utils/error-classifier.test.ts +0 -149
- package/tests/utils/frontmatter.test.ts +0 -208
- package/tests/utils/partitioned-store.test.ts +0 -230
- package/tests/utils/similarity.test.ts +0 -188
- package/tests/utils/trajectory-helpers.test.ts +0 -163
- package/tests/utils/validation.test.ts +0 -252
- package/tests/workspace/efficacy-toolkit.test.ts +0 -404
- package/tests/workspace/full-flow.test.ts +0 -845
- package/tests/workspace/manager.test.ts +0 -215
- package/tests/workspace/runner.test.ts +0 -336
- package/tests/workspace/skill-converter.test.ts +0 -205
- package/tests/workspace/templates/knowledge-extraction.test.ts +0 -235
- package/tests/workspace/templates/playbook-efficacy.test.ts +0 -377
- package/tests/workspace/templates/team-playbook-extraction.test.ts +0 -341
- package/tests/workspace/templates/team-trajectory-analysis.test.ts +0 -417
- package/tsconfig.json +0 -25
- package/vitest.config.ts +0 -22
package/dist/memory/playbook.js
CHANGED
|
@@ -8,16 +8,52 @@
|
|
|
8
8
|
import { createPlaybook, bumpPlaybookVersion } from '../types/index.js';
|
|
9
9
|
import { fromJSON, blobToEmbedding, fromISO } from '../persistence/index.js';
|
|
10
10
|
import { InvertedIndex } from '../embeddings/inverted-index.js';
|
|
11
|
-
import { textSimilarity } from '../utils/similarity.js';
|
|
11
|
+
import { textSimilarity, cosineSimilarity } from '../utils/similarity.js';
|
|
12
|
+
import { playbookHash } from '../utils/playbook-hash.js';
|
|
13
|
+
import { rowToExperience } from './experience.js';
|
|
12
14
|
import { getCandidates } from './candidate-retrieval.js';
|
|
15
|
+
import { convertPlaybookToSkill } from '../surfacing/skill-publisher.js';
|
|
16
|
+
import { scoreSkillsHybrid, } from 'skill-tree';
|
|
13
17
|
/**
|
|
14
18
|
* Build the indexable text for a playbook (situations + triggers concatenated)
|
|
15
19
|
*/
|
|
16
20
|
function playbookIndexText(playbook) {
|
|
17
|
-
return [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
return [...playbook.applicability.situations, ...playbook.applicability.triggers].join(' ');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* ADDITIVE LEARNING — over-merge guard. Two playbooks are domain-compatible
|
|
25
|
+
* when they share at least one (case-insensitive) domain, OR when at least one
|
|
26
|
+
* declares no domains (so we can't gate and fall back to similarity alone).
|
|
27
|
+
* Distinct, fully-declared, non-overlapping domains are NEVER merged.
|
|
28
|
+
*/
|
|
29
|
+
function domainsCompatible(a, b) {
|
|
30
|
+
const da = a.applicability.domains.map((d) => d.toLowerCase().trim()).filter(Boolean);
|
|
31
|
+
const db = b.applicability.domains.map((d) => d.toLowerCase().trim()).filter(Boolean);
|
|
32
|
+
if (da.length === 0 || db.length === 0)
|
|
33
|
+
return true;
|
|
34
|
+
const setA = new Set(da);
|
|
35
|
+
return db.some((d) => setA.has(d));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* ADDITIVE LEARNING — embeddings-optional similarity used to decide whether a
|
|
39
|
+
* freshly distilled playbook should REFINE an existing one instead of minting a
|
|
40
|
+
* new row. Cosine over embeddings when BOTH have them (semantic); otherwise a
|
|
41
|
+
* lexical blend of 0.6 * best situation textSimilarity + 0.4 * strategy
|
|
42
|
+
* textSimilarity (mirrors PlaybookExtractor.consolidate). The lexical branch is
|
|
43
|
+
* the one the eval path exercises, since it defaults to embedProvider:'none'.
|
|
44
|
+
*/
|
|
45
|
+
function playbookRefineSimilarity(a, b) {
|
|
46
|
+
if (a.embedding && b.embedding) {
|
|
47
|
+
return cosineSimilarity(a.embedding, b.embedding);
|
|
48
|
+
}
|
|
49
|
+
let maxSituationSim = 0;
|
|
50
|
+
for (const sA of a.applicability.situations) {
|
|
51
|
+
for (const sB of b.applicability.situations) {
|
|
52
|
+
maxSituationSim = Math.max(maxSituationSim, textSimilarity(sA, sB));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const strategySim = textSimilarity(a.guidance.strategy, b.guidance.strategy);
|
|
56
|
+
return maxSituationSim * 0.6 + strategySim * 0.4;
|
|
21
57
|
}
|
|
22
58
|
/**
|
|
23
59
|
* Convert a PlaybookRow (SQLite representation) back to a Playbook (domain type).
|
|
@@ -31,7 +67,12 @@ function rowToPlaybook(row) {
|
|
|
31
67
|
confidence: row.confidence,
|
|
32
68
|
complexity: row.complexity,
|
|
33
69
|
estimatedEffort: row.estimated_effort,
|
|
34
|
-
applicability: fromJSON(row.applicability, {
|
|
70
|
+
applicability: fromJSON(row.applicability, {
|
|
71
|
+
situations: [],
|
|
72
|
+
triggers: [],
|
|
73
|
+
antiPatterns: [],
|
|
74
|
+
domains: [],
|
|
75
|
+
}),
|
|
35
76
|
guidance: fromJSON(row.guidance, { strategy: '', tactics: [] }),
|
|
36
77
|
verification: fromJSON(row.verification, { successIndicators: [], failureIndicators: [] }),
|
|
37
78
|
evolution: {
|
|
@@ -45,16 +86,41 @@ function rowToPlaybook(row) {
|
|
|
45
86
|
consolidationStrength: evolution.consolidationStrength,
|
|
46
87
|
domainBreadth: evolution.domainBreadth,
|
|
47
88
|
},
|
|
48
|
-
provenance:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
89
|
+
provenance: provenance && Object.keys(provenance).length > 0
|
|
90
|
+
? {
|
|
91
|
+
origin: (provenance.origin ?? row.origin ?? 'extracted'),
|
|
92
|
+
extractionMethod: provenance.extractionMethod,
|
|
93
|
+
fallbackReason: provenance.fallbackReason,
|
|
94
|
+
template: provenance.template,
|
|
95
|
+
templateVersion: provenance.templateVersion,
|
|
96
|
+
sourceFile: provenance.sourceFile,
|
|
97
|
+
importedFrom: provenance.importedFrom,
|
|
98
|
+
curatedBy: provenance.curatedBy,
|
|
99
|
+
recordedAt: provenance.recordedAt
|
|
100
|
+
? new Date(provenance.recordedAt)
|
|
101
|
+
: new Date(),
|
|
102
|
+
creationCostUsd: provenance.creationCostUsd,
|
|
103
|
+
}
|
|
104
|
+
: undefined,
|
|
55
105
|
embedding: blobToEmbedding(row.embedding),
|
|
56
106
|
createdAt: fromISO(row.created_at) ?? new Date(),
|
|
57
107
|
updatedAt: fromISO(row.updated_at) ?? new Date(),
|
|
108
|
+
parentPlaybookId: row.parent_playbook_id ?? undefined,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Text to embed for a playbook (situations + triggers concatenated — same as the index key).
|
|
113
|
+
*/
|
|
114
|
+
function playbookEmbedText(playbook) {
|
|
115
|
+
return [...playbook.applicability.situations, ...playbook.applicability.triggers].join(' ');
|
|
116
|
+
}
|
|
117
|
+
function skillTreeEmbedderFrom(provider) {
|
|
118
|
+
if (!provider)
|
|
119
|
+
return undefined;
|
|
120
|
+
return {
|
|
121
|
+
async embed(texts) {
|
|
122
|
+
return provider.embedBatch(texts);
|
|
123
|
+
},
|
|
58
124
|
};
|
|
59
125
|
}
|
|
60
126
|
/**
|
|
@@ -65,6 +131,40 @@ export class PlaybookLibrary {
|
|
|
65
131
|
_index = new InvertedIndex();
|
|
66
132
|
initialized = false;
|
|
67
133
|
_resolver;
|
|
134
|
+
/** Optional embedding provider — when set, findMatching scores by vector cosine
|
|
135
|
+
* (semantic) instead of lexical textSimilarity. Embed on add so the vector is
|
|
136
|
+
* stored alongside the playbook row. Pass null to revert to lexical. */
|
|
137
|
+
embedder = null;
|
|
138
|
+
/** When true, force lexical scoring even if an embedder is attached (ablation). */
|
|
139
|
+
_forceLexical = false;
|
|
140
|
+
/** Near-dup merge threshold (cosine). 0 = disabled. */
|
|
141
|
+
_mergeThreshold = 0.92;
|
|
142
|
+
/** Whether write-time curation (near-dup merge) is enabled. */
|
|
143
|
+
_curationEnabled = true;
|
|
144
|
+
/** Minimum evidence (successCount+failureCount) before prune eligibility. */
|
|
145
|
+
_pruneMinEvidence = 3;
|
|
146
|
+
/**
|
|
147
|
+
* F2: When true and an embedder is attached, anti-pattern exclusion uses
|
|
148
|
+
* embedding cosine similarity instead of lexical textSimilarity.
|
|
149
|
+
* Default true. Set false to revert to old lexical guard (ablation).
|
|
150
|
+
*/
|
|
151
|
+
_semanticAntiPatterns = true;
|
|
152
|
+
/** Optional Phase 3 writer for stable procedural-memory SKILL.md files. */
|
|
153
|
+
_structuralWriter = null;
|
|
154
|
+
/**
|
|
155
|
+
* F2: Cosine threshold above which a query is considered to match an
|
|
156
|
+
* anti-pattern (and the playbook is excluded). Default 0.6.
|
|
157
|
+
* Semantic cosine scores are denser than lexical textSimilarity scores,
|
|
158
|
+
* so the threshold is lower than the lexical 0.7 guard.
|
|
159
|
+
*/
|
|
160
|
+
_semanticAntiPatternThreshold = 0.6;
|
|
161
|
+
/**
|
|
162
|
+
* F2: In-memory cache of anti-pattern embeddings keyed by playbook id.
|
|
163
|
+
* Populated lazily on first retrieval and reused across queries.
|
|
164
|
+
* Key: `${playbookId}::${antiPatternIndex}` → embedding vector.
|
|
165
|
+
* Avoids re-embedding the same anti-pattern strings on every query.
|
|
166
|
+
*/
|
|
167
|
+
_antiPatternEmbeddingCache = new Map();
|
|
68
168
|
constructor(persistence) {
|
|
69
169
|
this.persistence = persistence;
|
|
70
170
|
this._resolver = {
|
|
@@ -75,6 +175,93 @@ export class PlaybookLibrary {
|
|
|
75
175
|
values: () => this.getAllSync(),
|
|
76
176
|
};
|
|
77
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Attach a semantic embedding provider. When set, `findMatching` scores
|
|
180
|
+
* candidates by vector cosine instead of lexical textSimilarity, and new
|
|
181
|
+
* playbooks are embedded on `add()`. Pass null to revert to lexical.
|
|
182
|
+
*/
|
|
183
|
+
setEmbeddingProvider(provider) {
|
|
184
|
+
this.embedder = provider;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* When true, force lexical scoring (Jaccard+trigram) even when an embedder
|
|
188
|
+
* is attached — corresponds to the `features.lexicalRetrieval` ablation flag.
|
|
189
|
+
*/
|
|
190
|
+
setForceLexical(force) {
|
|
191
|
+
this._forceLexical = force;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* True when retrieval scores candidates by embedding cosine (an embedder is
|
|
195
|
+
* attached and lexical scoring is not forced). Callers use this to pick the
|
|
196
|
+
* right relevance floor — semantic cosine scores are denser than lexical, so
|
|
197
|
+
* they tolerate (and require) a higher minScore. See PlaybookRetrievalConfig.
|
|
198
|
+
*/
|
|
199
|
+
isSemanticScoring() {
|
|
200
|
+
return this.embedder !== null && !this._forceLexical;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* F2: Configure semantic anti-pattern exclusion.
|
|
204
|
+
*
|
|
205
|
+
* @param enabled - When true (default), anti-pattern exclusion uses embedding
|
|
206
|
+
* cosine similarity when an embedder is attached. When false, falls back to
|
|
207
|
+
* lexical textSimilarity > 0.7 (old behavior, ablation arm).
|
|
208
|
+
* @param threshold - Cosine similarity threshold above which a query matches
|
|
209
|
+
* an anti-pattern and the playbook is excluded. Default 0.6. Lower than
|
|
210
|
+
* the lexical 0.7 guard because semantic cosine scores are denser.
|
|
211
|
+
*/
|
|
212
|
+
setSemanticAntiPatterns(enabled, threshold) {
|
|
213
|
+
this._semanticAntiPatterns = enabled;
|
|
214
|
+
if (threshold !== undefined)
|
|
215
|
+
this._semanticAntiPatternThreshold = threshold;
|
|
216
|
+
// Clear the embedding cache when settings change so stale vectors are dropped.
|
|
217
|
+
this._antiPatternEmbeddingCache.clear();
|
|
218
|
+
}
|
|
219
|
+
setStructuralWriter(writer) {
|
|
220
|
+
this._structuralWriter = writer;
|
|
221
|
+
}
|
|
222
|
+
async writeStructural(playbook) {
|
|
223
|
+
if (!this._structuralWriter)
|
|
224
|
+
return;
|
|
225
|
+
await this._structuralWriter.write(playbook);
|
|
226
|
+
await this._structuralWriter.writeState(playbook);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Persist the rebuildable operational-state sidecar after a counter/confidence
|
|
230
|
+
* mutation (recordSuccess/Failure/recordApplicationOutcome). Non-fatal: SQLite
|
|
231
|
+
* stays canonical for ops state until the next reindex. No-op outside
|
|
232
|
+
* filesystem/dual-write mode (no structural writer attached).
|
|
233
|
+
*/
|
|
234
|
+
async writeStateStructural(playbook) {
|
|
235
|
+
if (!this._structuralWriter)
|
|
236
|
+
return;
|
|
237
|
+
try {
|
|
238
|
+
await this._structuralWriter.writeState(playbook);
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
// Sidecar write failed — SQLite remains the source of truth for ops state.
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
async deleteStructural(playbook) {
|
|
245
|
+
if (!this._structuralWriter)
|
|
246
|
+
return;
|
|
247
|
+
await this._structuralWriter.delete(playbook);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Configure write-time curation (PR-D2).
|
|
251
|
+
*
|
|
252
|
+
* @param enabled - When false, add() always appends (append-only ablation).
|
|
253
|
+
* @param mergeThreshold - Cosine similarity above which two playbooks are
|
|
254
|
+
* treated as near-duplicates and merged (default 0.92).
|
|
255
|
+
* @param pruneMinEvidence - Minimum (successCount + failureCount) before a
|
|
256
|
+
* playbook is eligible for harm-pruning (default 3).
|
|
257
|
+
*/
|
|
258
|
+
setCurationConfig(opts) {
|
|
259
|
+
this._curationEnabled = opts.enabled;
|
|
260
|
+
if (opts.mergeThreshold !== undefined)
|
|
261
|
+
this._mergeThreshold = opts.mergeThreshold;
|
|
262
|
+
if (opts.pruneMinEvidence !== undefined)
|
|
263
|
+
this._pruneMinEvidence = opts.pruneMinEvidence;
|
|
264
|
+
}
|
|
78
265
|
async init() {
|
|
79
266
|
if (this.initialized)
|
|
80
267
|
return;
|
|
@@ -89,21 +276,41 @@ export class PlaybookLibrary {
|
|
|
89
276
|
}
|
|
90
277
|
// === RETRIEVAL ===
|
|
91
278
|
/**
|
|
92
|
-
* Find playbooks matching a context
|
|
93
|
-
*
|
|
94
|
-
*
|
|
279
|
+
* Find playbooks matching a context.
|
|
280
|
+
*
|
|
281
|
+
* Scoring path:
|
|
282
|
+
* - When an embedding provider is attached AND `_forceLexical` is false
|
|
283
|
+
* (the semantic path): embed the query + lazily embed any playbook that
|
|
284
|
+
* lacks a stored vector, then score by cosine similarity. The InvertedIndex
|
|
285
|
+
* is used only as a pre-filter candidate-narrowing step; when it returns
|
|
286
|
+
* nothing a full-scan fallback is used so semantic retrieval is never
|
|
287
|
+
* blocked by lexical index misses.
|
|
288
|
+
* - Otherwise (lexical path): score by Jaccard+trigram textSimilarity as
|
|
289
|
+
* before. This is the ablation path (`features.lexicalRetrieval: true`)
|
|
290
|
+
* and the no-provider fallback.
|
|
95
291
|
*/
|
|
96
292
|
async findMatching(context, options) {
|
|
97
293
|
await this.init();
|
|
98
294
|
const k = options?.k ?? 5;
|
|
99
|
-
|
|
100
|
-
|
|
295
|
+
const useEmbedding = this.embedder !== null && !this._forceLexical;
|
|
296
|
+
// Get candidate pool.
|
|
297
|
+
// Semantic path: do NOT let the lexical InvertedIndex cap candidates — we
|
|
298
|
+
// need the full set so cosine can find semantically-near items even when
|
|
299
|
+
// they share no tokens with the query. Use domain fallback or full scan.
|
|
300
|
+
const domainFallback = options?.domains && options.domains.length > 0
|
|
101
301
|
? [
|
|
102
302
|
...options.domains.flatMap((d) => this.persistence.getPlaybooksByDomain(d).map(rowToPlaybook)),
|
|
103
303
|
...this.persistence.getPlaybooksByDomain('_global').map(rowToPlaybook),
|
|
104
304
|
]
|
|
105
305
|
: undefined;
|
|
106
|
-
let playbooks
|
|
306
|
+
let playbooks;
|
|
307
|
+
if (useEmbedding) {
|
|
308
|
+
// Full scan (or domain slice) so semantic retrieval can reach any playbook.
|
|
309
|
+
playbooks = domainFallback ?? this.getAllSync();
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
playbooks = getCandidates(context, this._index, this._resolver, { k }, domainFallback);
|
|
313
|
+
}
|
|
107
314
|
// Filter by domains if specified (for cases where index returned cross-domain)
|
|
108
315
|
if (options?.domains && options.domains.length > 0) {
|
|
109
316
|
playbooks = playbooks.filter((p) => p.applicability.domains.some((d) => options.domains.includes(d)));
|
|
@@ -112,32 +319,80 @@ export class PlaybookLibrary {
|
|
|
112
319
|
if (options?.minConfidence !== undefined) {
|
|
113
320
|
playbooks = playbooks.filter((p) => p.confidence >= options.minConfidence);
|
|
114
321
|
}
|
|
322
|
+
// Embed the query once (semantic path only).
|
|
323
|
+
let queryVec;
|
|
324
|
+
if (useEmbedding && this.embedder) {
|
|
325
|
+
queryVec = await this.embedder.embed(context);
|
|
326
|
+
}
|
|
115
327
|
// Score playbooks
|
|
116
328
|
const scored = [];
|
|
117
329
|
for (const playbook of playbooks) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
330
|
+
let score;
|
|
331
|
+
let matchType = 'situation';
|
|
332
|
+
if (useEmbedding && queryVec && this.embedder) {
|
|
333
|
+
// F2: Anti-pattern exclusion via embedding cosine when semantic mode is on.
|
|
334
|
+
if (options?.excludeAntiPatterns !== false &&
|
|
335
|
+
playbook.applicability.antiPatterns.length > 0) {
|
|
336
|
+
if (this._semanticAntiPatterns && this.embedder) {
|
|
337
|
+
// Lazily embed each anti-pattern string and cache by playbook+index.
|
|
338
|
+
let excluded = false;
|
|
339
|
+
for (let apIdx = 0; apIdx < playbook.applicability.antiPatterns.length; apIdx++) {
|
|
340
|
+
const cacheKey = `${playbook.id}::${apIdx}`;
|
|
341
|
+
let apVec = this._antiPatternEmbeddingCache.get(cacheKey);
|
|
342
|
+
if (!apVec) {
|
|
343
|
+
apVec = await this.embedder.embed(playbook.applicability.antiPatterns[apIdx]);
|
|
344
|
+
this._antiPatternEmbeddingCache.set(cacheKey, apVec);
|
|
345
|
+
}
|
|
346
|
+
if (cosineSimilarity(queryVec, apVec) > this._semanticAntiPatternThreshold) {
|
|
347
|
+
excluded = true;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (excluded)
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
// Lexical fallback (old behavior / ablation when semanticAntiPatterns=false).
|
|
356
|
+
const antiPatternMatch = playbook.applicability.antiPatterns.some((ap) => textSimilarity(context, ap) > 0.7);
|
|
357
|
+
if (antiPatternMatch)
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
// Lazily embed any playbook that was stored before the provider was
|
|
362
|
+
// attached (so we don't block init, only pay on first access).
|
|
363
|
+
if (!playbook.embedding) {
|
|
364
|
+
playbook.embedding = await this.embedder.embed(playbookEmbedText(playbook));
|
|
365
|
+
// Persist the newly-computed embedding for future runs.
|
|
366
|
+
this.persistence.insertPlaybook(playbook);
|
|
367
|
+
}
|
|
368
|
+
score = playbook.embedding.length > 0 ? cosineSimilarity(queryVec, playbook.embedding) : 0;
|
|
369
|
+
if (score > 0) {
|
|
370
|
+
scored.push({ playbook, score, matchType: 'situation', retrievalMethod: 'legacy' });
|
|
371
|
+
}
|
|
123
372
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
373
|
+
else {
|
|
374
|
+
// Lexical path (original behavior).
|
|
375
|
+
// Check anti-patterns first (if enabled)
|
|
376
|
+
if (options?.excludeAntiPatterns !== false) {
|
|
377
|
+
const antiPatternMatch = playbook.applicability.antiPatterns.some((ap) => textSimilarity(context, ap) > 0.7);
|
|
378
|
+
if (antiPatternMatch)
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
// Score against situations
|
|
382
|
+
const situationScores = playbook.applicability.situations.map((s) => textSimilarity(context, s));
|
|
383
|
+
const maxSituationScore = situationScores.length > 0 ? Math.max(...situationScores) : 0;
|
|
384
|
+
// Score against triggers (weighted higher for exact matches)
|
|
385
|
+
const triggerScores = playbook.applicability.triggers.map((t) => textSimilarity(context, t));
|
|
386
|
+
const maxTriggerScore = triggerScores.length > 0 ? Math.max(...triggerScores) * 1.2 : 0;
|
|
387
|
+
score = Math.max(maxSituationScore, maxTriggerScore);
|
|
388
|
+
matchType = maxTriggerScore > maxSituationScore ? 'trigger' : 'situation';
|
|
389
|
+
if (score > 0) {
|
|
390
|
+
scored.push({ playbook, score, matchType, retrievalMethod: 'legacy' });
|
|
391
|
+
}
|
|
135
392
|
}
|
|
136
393
|
}
|
|
137
394
|
// Apply minimum score filter before ranking
|
|
138
|
-
const filtered = options?.minScore !== undefined
|
|
139
|
-
? scored.filter((r) => r.score >= options.minScore)
|
|
140
|
-
: scored;
|
|
395
|
+
const filtered = options?.minScore !== undefined ? scored.filter((r) => r.score >= options.minScore) : scored;
|
|
141
396
|
// Apply MMR diversity reranking or simple sort
|
|
142
397
|
const lambda = options?.lambda;
|
|
143
398
|
if (lambda !== undefined && lambda < 1.0) {
|
|
@@ -147,6 +402,54 @@ export class PlaybookLibrary {
|
|
|
147
402
|
filtered.sort((a, b) => b.score - a.score);
|
|
148
403
|
return filtered.slice(0, k);
|
|
149
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Find playbooks using skill-tree's tuned hybrid skill scorer.
|
|
407
|
+
*
|
|
408
|
+
* This treats playbooks as skill-tree Skills at retrieval time, without
|
|
409
|
+
* requiring playbooks to be published into skill-tree storage first. It gives
|
|
410
|
+
* the serving path access to skill-tree's body-indexed BM25 scorer, optional
|
|
411
|
+
* dense fusion, and calibrated [0,1] relevance scores.
|
|
412
|
+
*/
|
|
413
|
+
async findMatchingSkillTreeHybrid(context, options) {
|
|
414
|
+
await this.init();
|
|
415
|
+
const k = options?.k ?? 5;
|
|
416
|
+
let playbooks = options?.domains && options.domains.length > 0
|
|
417
|
+
? options.domains.flatMap((d) => this.persistence.getPlaybooksByDomain(d).map(rowToPlaybook))
|
|
418
|
+
: this.getAllSync();
|
|
419
|
+
if (options?.domains && options.domains.length > 0) {
|
|
420
|
+
playbooks = playbooks.filter((p) => p.applicability.domains.some((d) => options.domains.includes(d)));
|
|
421
|
+
}
|
|
422
|
+
if (options?.minConfidence !== undefined) {
|
|
423
|
+
playbooks = playbooks.filter((p) => p.confidence >= options.minConfidence);
|
|
424
|
+
}
|
|
425
|
+
if (options?.excludeAntiPatterns !== false) {
|
|
426
|
+
playbooks = playbooks.filter((p) => !p.applicability.antiPatterns.some((ap) => textSimilarity(context, ap) > 0.7));
|
|
427
|
+
}
|
|
428
|
+
if (playbooks.length === 0)
|
|
429
|
+
return [];
|
|
430
|
+
const playbookById = new Map(playbooks.map((p) => [p.id, p]));
|
|
431
|
+
const skills = playbooks.map(convertPlaybookToSkill);
|
|
432
|
+
const scored = await scoreSkillsHybrid(context, skills, {
|
|
433
|
+
embedder: skillTreeEmbedderFrom(this.embedder),
|
|
434
|
+
fusion: options?.fusion ?? 'rrf',
|
|
435
|
+
});
|
|
436
|
+
const filtered = options?.minScore !== undefined
|
|
437
|
+
? scored.filter((r) => r.relevanceScore >= options.minScore)
|
|
438
|
+
: scored;
|
|
439
|
+
return filtered.slice(0, k).flatMap((item) => {
|
|
440
|
+
const playbook = playbookById.get(item.skill.id);
|
|
441
|
+
if (!playbook)
|
|
442
|
+
return [];
|
|
443
|
+
return [
|
|
444
|
+
{
|
|
445
|
+
playbook,
|
|
446
|
+
score: item.relevanceScore,
|
|
447
|
+
matchType: 'situation',
|
|
448
|
+
retrievalMethod: 'skill-tree-hybrid',
|
|
449
|
+
},
|
|
450
|
+
];
|
|
451
|
+
});
|
|
452
|
+
}
|
|
150
453
|
/**
|
|
151
454
|
* Maximal Marginal Relevance reranking.
|
|
152
455
|
* Selects top-k items balancing relevance and diversity.
|
|
@@ -218,6 +521,7 @@ export class PlaybookLibrary {
|
|
|
218
521
|
}
|
|
219
522
|
playbook.updatedAt = new Date();
|
|
220
523
|
this.persistence.insertPlaybook(playbook); // Write-through (INSERT OR REPLACE)
|
|
524
|
+
await this.writeStateStructural(playbook);
|
|
221
525
|
}
|
|
222
526
|
/**
|
|
223
527
|
* Record failure and capture context
|
|
@@ -251,6 +555,72 @@ export class PlaybookLibrary {
|
|
|
251
555
|
playbook.confidence = Math.max(0.1, playbook.confidence - dampedDelta);
|
|
252
556
|
playbook.updatedAt = new Date();
|
|
253
557
|
this.persistence.insertPlaybook(playbook); // Write-through
|
|
558
|
+
await this.writeStateStructural(playbook);
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* F6: Injection-presence credit — update counters by INJECTION-PRESENCE +
|
|
562
|
+
* TASK OUTCOME, not by lexical usage detection.
|
|
563
|
+
*
|
|
564
|
+
* Instead of waiting for usage-inference to confirm a playbook was "used"
|
|
565
|
+
* (which fails for distilled playbooks whose abstract tactics never lexically
|
|
566
|
+
* match concrete actions), we attribute a fractional share of each task's
|
|
567
|
+
* outcome to every playbook that was injected, weighted by its retrieval
|
|
568
|
+
* score. Weights across all injected playbooks sum to 1 per task, so total
|
|
569
|
+
* credit per task = 1 distributed by relevance.
|
|
570
|
+
*
|
|
571
|
+
* Fractional counts interact correctly with downstream consumers:
|
|
572
|
+
* - helpfulnessPrior: (successCount+1)/(successCount+failureCount+2) —
|
|
573
|
+
* fractional inputs produce a valid probability; Laplace smoothing (+2)
|
|
574
|
+
* keeps it out of the 0/1 corners even for tiny weights.
|
|
575
|
+
* - pruneHarmful: failureCount >= successCount + minEvidence — fractional
|
|
576
|
+
* threshold means a playbook accumulates evidence gradually; a
|
|
577
|
+
* minEvidence=3 threshold needs ~3 tasks worth of failure-weight before
|
|
578
|
+
* pruning fires, which is correct (3 fractional tasks = 3 real tasks at
|
|
579
|
+
* weight 1).
|
|
580
|
+
* - Confidence grows via weight-scaled damped delta (same formula as
|
|
581
|
+
* recordSuccess / recordFailure but multiplied by weight), completing
|
|
582
|
+
* F3: distilled playbooks born at 0.6-0.7 climb past the 0.7 router
|
|
583
|
+
* gate after a few attributed successes.
|
|
584
|
+
*
|
|
585
|
+
* @param id - Playbook id
|
|
586
|
+
* @param success - Whether the task succeeded
|
|
587
|
+
* @param weight - Relevance share [0,1]; weights over all injected playbooks
|
|
588
|
+
* should sum to 1. When weight = 0 this is a no-op.
|
|
589
|
+
*/
|
|
590
|
+
async recordApplicationOutcome(id, success, weight) {
|
|
591
|
+
if (weight <= 0)
|
|
592
|
+
return;
|
|
593
|
+
await this.init();
|
|
594
|
+
const row = this.persistence.getPlaybook(id);
|
|
595
|
+
if (!row)
|
|
596
|
+
return;
|
|
597
|
+
const playbook = rowToPlaybook(row);
|
|
598
|
+
// Snapshot before mutation for version history
|
|
599
|
+
this.persistence.snapshotPlaybookVersion(id, playbook.evolution.version, success
|
|
600
|
+
? `Injection-presence credit (success, weight=${weight.toFixed(3)})`
|
|
601
|
+
: `Injection-presence credit (failure, weight=${weight.toFixed(3)})`);
|
|
602
|
+
if (success) {
|
|
603
|
+
playbook.evolution.successCount += weight;
|
|
604
|
+
// Stability-plasticity: damped confidence increase, scaled by weight
|
|
605
|
+
const cs = playbook.evolution.consolidationStrength ?? 0;
|
|
606
|
+
const rawDelta = (1 - playbook.confidence) * 0.1;
|
|
607
|
+
const dampedDelta = (rawDelta / (1 + cs * 0.1)) * weight;
|
|
608
|
+
playbook.confidence = Math.min(0.99, playbook.confidence + dampedDelta);
|
|
609
|
+
// Grow consolidation strength (weight-scaled, same direction as recordSuccess)
|
|
610
|
+
playbook.evolution.consolidationStrength = Math.min(10, cs + 0.05 * weight);
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
playbook.evolution.failureCount += weight;
|
|
614
|
+
// Stability-plasticity: damped confidence decrease, scaled by weight
|
|
615
|
+
const cs = playbook.evolution.consolidationStrength ?? 0;
|
|
616
|
+
const rawDelta = playbook.confidence * 0.15;
|
|
617
|
+
const dampedDelta = (rawDelta / (1 + cs * 0.2)) * weight;
|
|
618
|
+
playbook.confidence = Math.max(0.1, playbook.confidence - dampedDelta);
|
|
619
|
+
}
|
|
620
|
+
playbook.evolution.lastUsed = new Date();
|
|
621
|
+
playbook.updatedAt = new Date();
|
|
622
|
+
this.persistence.insertPlaybook(playbook); // Write-through (INSERT OR REPLACE)
|
|
623
|
+
await this.writeStateStructural(playbook);
|
|
254
624
|
}
|
|
255
625
|
/**
|
|
256
626
|
* Add a context-specific refinement
|
|
@@ -276,6 +646,7 @@ export class PlaybookLibrary {
|
|
|
276
646
|
playbook.evolution.version = bumpPlaybookVersion(playbook, 'patch');
|
|
277
647
|
playbook.updatedAt = new Date();
|
|
278
648
|
this.persistence.insertPlaybook(playbook); // Write-through
|
|
649
|
+
await this.writeStructural(playbook);
|
|
279
650
|
}
|
|
280
651
|
/**
|
|
281
652
|
* Evolve playbook based on accumulated failures
|
|
@@ -303,16 +674,705 @@ export class PlaybookLibrary {
|
|
|
303
674
|
this.persistence.insertPlaybook(playbook); // Write-through
|
|
304
675
|
// Update index since applicability may have changed
|
|
305
676
|
this._index.add(id, playbookIndexText(playbook));
|
|
677
|
+
await this.writeStructural(playbook);
|
|
306
678
|
return playbook;
|
|
307
679
|
}
|
|
680
|
+
// === FRONTIER (per-(signature, experience, playbook) Pareto bookkeeping) ===
|
|
681
|
+
/**
|
|
682
|
+
* Record an outcome on the Pareto frontier.
|
|
683
|
+
*
|
|
684
|
+
* For each (taskSignature, experienceId), the frontier tracks each
|
|
685
|
+
* playbook's *best* observed score. Multiple playbooks coexist on the
|
|
686
|
+
* frontier for the same (sig, exp) when they tie. The router uses this
|
|
687
|
+
* to preserve specialist playbooks that are good on a subset of work
|
|
688
|
+
* but mediocre on average.
|
|
689
|
+
*/
|
|
690
|
+
async recordOutcomeOnSignature(playbookId, taskSignature, experienceId, score) {
|
|
691
|
+
await this.init();
|
|
692
|
+
this.persistence.upsertFrontierRow(taskSignature, experienceId, playbookId, score);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Record a live outcome: stamps both the Pareto frontier AND the eval
|
|
696
|
+
* cache (as `judged_by = 'live'`). Live writes take priority over
|
|
697
|
+
* llm-judge predictions, so any prior judge guess for this
|
|
698
|
+
* (playbook, experience) pair is superseded by ground truth.
|
|
699
|
+
*
|
|
700
|
+
* Use this from the hot path (instant loop) so the cache and frontier
|
|
701
|
+
* accumulate ground-truth observations as solves happen. Phase 2's
|
|
702
|
+
* acceptance gate will read from the cache without paying for judge
|
|
703
|
+
* calls when live data already exists.
|
|
704
|
+
*
|
|
705
|
+
* If `objectives` is provided, also writes one row per objective into
|
|
706
|
+
* the cartesian frontier (multi-objective Pareto). Caller-supplied
|
|
707
|
+
* objectives must follow the higher-is-better convention.
|
|
708
|
+
*/
|
|
709
|
+
async recordLiveOutcome(playbookId, taskSignature, experienceId, score, objectives) {
|
|
710
|
+
await this.init();
|
|
711
|
+
this.persistence.upsertFrontierRow(taskSignature, experienceId, playbookId, score);
|
|
712
|
+
// Also write to the eval cache as a live observation. Needs the
|
|
713
|
+
// playbook's content hash, so we fetch and hash. Cheap (DB hit + SHA-256).
|
|
714
|
+
const row = this.persistence.getPlaybook(playbookId);
|
|
715
|
+
if (row) {
|
|
716
|
+
const hash = playbookHash(rowToPlaybook(row));
|
|
717
|
+
this.persistence.upsertEvalCache(hash, experienceId, score, 'live');
|
|
718
|
+
}
|
|
719
|
+
// Multi-objective frontier rows.
|
|
720
|
+
if (objectives) {
|
|
721
|
+
for (const [objective, objScore] of Object.entries(objectives)) {
|
|
722
|
+
this.persistence.upsertFrontierCartesianRow(taskSignature, experienceId, objective, playbookId, objScore);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Get all frontier rows for a signature.
|
|
728
|
+
*/
|
|
729
|
+
async getFrontierForSignature(taskSignature) {
|
|
730
|
+
await this.init();
|
|
731
|
+
return this.persistence.getFrontierBySignature(taskSignature);
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Get all frontier rows for a playbook, across every signature it
|
|
735
|
+
* participates in. An empty result means the playbook has no live
|
|
736
|
+
* frontier history yet (freshly-extracted or never-served) — callers
|
|
737
|
+
* that gate on dominance must treat "no frontier" as non-dominated to
|
|
738
|
+
* avoid deadlocking first-ever promotions.
|
|
739
|
+
*/
|
|
740
|
+
async getFrontierForPlaybook(playbookId) {
|
|
741
|
+
await this.init();
|
|
742
|
+
return this.persistence.getFrontierByPlaybook(playbookId);
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Get the dominator set: playbooks that survive Pareto dominance pruning
|
|
746
|
+
* across the (experience -> best playbooks) frontier for a signature.
|
|
747
|
+
*
|
|
748
|
+
* A playbook P is *dominated* if every (sig, exp) where P is on the
|
|
749
|
+
* frontier also has at least one non-dominated other playbook on the
|
|
750
|
+
* same frontier — i.e., P is never *uniquely* needed. Direct port of
|
|
751
|
+
* GEPA's `remove_dominated_programs` (gepa_utils.py:35-72), specialized
|
|
752
|
+
* to a single signature scope.
|
|
753
|
+
*
|
|
754
|
+
* Returns playbooks ranked by win frequency (descending). Used by the
|
|
755
|
+
* router to sample frontier members.
|
|
756
|
+
*/
|
|
757
|
+
async getDominatorPlaybooks(opts) {
|
|
758
|
+
await this.init();
|
|
759
|
+
if (!opts.taskSignature) {
|
|
760
|
+
return [];
|
|
761
|
+
}
|
|
762
|
+
const rows = this.persistence.getFrontierBySignature(opts.taskSignature);
|
|
763
|
+
if (rows.length === 0)
|
|
764
|
+
return [];
|
|
765
|
+
// Build per-experience frontiers: experience_id -> set of playbook_ids
|
|
766
|
+
// at the top score on that experience.
|
|
767
|
+
const frontierByExp = new Map();
|
|
768
|
+
const topScoreByExp = new Map();
|
|
769
|
+
for (const row of rows) {
|
|
770
|
+
const prev = topScoreByExp.get(row.experience_id);
|
|
771
|
+
if (prev === undefined || row.score > prev) {
|
|
772
|
+
topScoreByExp.set(row.experience_id, row.score);
|
|
773
|
+
frontierByExp.set(row.experience_id, new Set([row.playbook_id]));
|
|
774
|
+
}
|
|
775
|
+
else if (row.score === prev) {
|
|
776
|
+
frontierByExp.get(row.experience_id).add(row.playbook_id);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
const survivors = pruneDominated(frontierByExp);
|
|
780
|
+
return resolveFrontierMembers(survivors, frontierByExp, this.persistence, opts.domain);
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Multi-objective variant of `getDominatorPlaybooks`. Computes
|
|
784
|
+
* dominance over the cartesian frontier (per-(exp, objective)) for
|
|
785
|
+
* a signature, restricted to a caller-supplied set of objectives.
|
|
786
|
+
*
|
|
787
|
+
* A playbook survives if, for some (experience, objective) pair, it
|
|
788
|
+
* is uniquely on the frontier OR no other surviving playbook covers
|
|
789
|
+
* all the pairs where it dominates. Direct port of
|
|
790
|
+
* `remove_dominated_programs` applied to the cartesian key space.
|
|
791
|
+
*
|
|
792
|
+
* `objectives` defaults to all objectives present in the cartesian
|
|
793
|
+
* frontier for this signature. Passing a subset narrows the dominance
|
|
794
|
+
* computation (e.g., `['cost']` for cost-only selection).
|
|
795
|
+
*
|
|
796
|
+
* Returns playbooks ranked by total (exp, objective) wins across the
|
|
797
|
+
* requested objectives.
|
|
798
|
+
*/
|
|
799
|
+
async getDominatorPlaybooksMultiObjective(opts) {
|
|
800
|
+
await this.init();
|
|
801
|
+
const rows = this.persistence.getFrontierCartesianBySignature(opts.taskSignature);
|
|
802
|
+
if (rows.length === 0)
|
|
803
|
+
return [];
|
|
804
|
+
// Filter by requested objectives if specified.
|
|
805
|
+
const filtered = opts.objectives
|
|
806
|
+
? rows.filter((r) => opts.objectives.includes(r.objective))
|
|
807
|
+
: rows;
|
|
808
|
+
if (filtered.length === 0)
|
|
809
|
+
return [];
|
|
810
|
+
// Build per-(exp, objective) frontier: key -> set of top-scoring playbooks
|
|
811
|
+
const frontierByKey = new Map();
|
|
812
|
+
const topScoreByKey = new Map();
|
|
813
|
+
for (const row of filtered) {
|
|
814
|
+
const key = `${row.experience_id}::${row.objective}`;
|
|
815
|
+
const prev = topScoreByKey.get(key);
|
|
816
|
+
if (prev === undefined || row.score > prev) {
|
|
817
|
+
topScoreByKey.set(key, row.score);
|
|
818
|
+
frontierByKey.set(key, new Set([row.playbook_id]));
|
|
819
|
+
}
|
|
820
|
+
else if (row.score === prev) {
|
|
821
|
+
frontierByKey.get(key).add(row.playbook_id);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
const survivors = pruneDominated(frontierByKey);
|
|
825
|
+
return resolveFrontierMembers(survivors, frontierByKey, this.persistence, opts.domain);
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* How many (sig, exp) pairs does this playbook currently dominate?
|
|
829
|
+
* Deletion paths (consolidation, GC) should check this before removing
|
|
830
|
+
* a playbook — a playbook with `uniqueWins > 0` is a specialist that
|
|
831
|
+
* can't be reproduced by the surviving playbooks.
|
|
832
|
+
*/
|
|
833
|
+
async getFrontierContribution(playbookId) {
|
|
834
|
+
await this.init();
|
|
835
|
+
return this.persistence.getFrontierContribution(playbookId);
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Sample a minibatch of experiences for replay-based evaluation of
|
|
839
|
+
* a candidate mutation against this playbook.
|
|
840
|
+
*
|
|
841
|
+
* Two-stage strategy:
|
|
842
|
+
* 1. Frontier-first: take the most recent experiences where this
|
|
843
|
+
* playbook has actually been scored (from `playbook_frontier`,
|
|
844
|
+
* ranked by `recorded_at` desc). This is the GEPA-style "same
|
|
845
|
+
* minibatch as the parent" semantics — the candidate is judged
|
|
846
|
+
* on the workload the parent was already serving.
|
|
847
|
+
* 2. Fallback: if the playbook has no frontier history yet (typical
|
|
848
|
+
* for freshly-extracted playbooks), use experiences linked to
|
|
849
|
+
* its `evolution.createdFrom` trajectories.
|
|
850
|
+
*
|
|
851
|
+
* If `taskSignature` is provided, restricts stage 1 to rows on that
|
|
852
|
+
* signature only — the proper "same workload" semantics. Without it,
|
|
853
|
+
* stage 1 mixes signatures, which corrupts comparison.
|
|
854
|
+
*
|
|
855
|
+
* `poolAcrossSignatures` overrides that filter: when true, stage 1 uses
|
|
856
|
+
* the playbook's recent frontier rows ACROSS all `{domain}:{intent}`
|
|
857
|
+
* signatures even if `taskSignature` is supplied. This is the mutation
|
|
858
|
+
* GATE path (see MutationGate.propose): the frontier rows returned by
|
|
859
|
+
* `getFrontierByPlaybook` are ALREADY per-playbook, so every row is an
|
|
860
|
+
* application of THIS playbook and is inherently relevant regardless of
|
|
861
|
+
* task domain. A domain-general playbook's failure evidence otherwise
|
|
862
|
+
* shatters into ~1-per-signature buckets on real benchmarks (families
|
|
863
|
+
* like SkillFlow Cross-Format-Data-Reconciliation span retail-operations,
|
|
864
|
+
* cloud-finops, it-operations, … — many domains), which is always below
|
|
865
|
+
* `minMinibatchSize`, so the gate can never reach a real parent-vs-child
|
|
866
|
+
* comparison and always takes the sparse-minibatch auto-accept bypass.
|
|
867
|
+
* Pooling across signatures lets a playbook applied to ≥3 tasks reach a
|
|
868
|
+
* non-sparse minibatch. The recency sort keeps the newest applications,
|
|
869
|
+
* so pooling doesn't drag in stale evidence.
|
|
870
|
+
*
|
|
871
|
+
* Returns up to `k` experiences. Empty result means the caller should
|
|
872
|
+
* accept the mutation without a gate (no evidence either way).
|
|
873
|
+
*/
|
|
874
|
+
async sampleMinibatchForPlaybook(playbookId, k = 5, taskSignature, poolAcrossSignatures = false) {
|
|
875
|
+
await this.init();
|
|
876
|
+
// Stage 1: recent frontier history (signature-filtered when provided,
|
|
877
|
+
// unless the caller opts into cross-signature pooling for the gate).
|
|
878
|
+
let frontierRows = this.persistence.getFrontierByPlaybook(playbookId);
|
|
879
|
+
if (taskSignature && !poolAcrossSignatures) {
|
|
880
|
+
frontierRows = frontierRows.filter((r) => r.task_signature === taskSignature);
|
|
881
|
+
}
|
|
882
|
+
if (frontierRows.length > 0) {
|
|
883
|
+
const sortedByRecency = [...frontierRows]
|
|
884
|
+
.sort((a, b) => b.recorded_at.localeCompare(a.recorded_at))
|
|
885
|
+
.slice(0, k);
|
|
886
|
+
const seen = new Set();
|
|
887
|
+
const experiences = [];
|
|
888
|
+
for (const row of sortedByRecency) {
|
|
889
|
+
if (seen.has(row.experience_id))
|
|
890
|
+
continue;
|
|
891
|
+
seen.add(row.experience_id);
|
|
892
|
+
const expRow = this.persistence.getExperience(row.experience_id);
|
|
893
|
+
if (expRow)
|
|
894
|
+
experiences.push(rowToExperience(expRow));
|
|
895
|
+
if (experiences.length >= k)
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
if (experiences.length > 0)
|
|
899
|
+
return experiences;
|
|
900
|
+
}
|
|
901
|
+
// Stage 2: fallback to createdFrom trajectories
|
|
902
|
+
const playbookRow = this.persistence.getPlaybook(playbookId);
|
|
903
|
+
if (!playbookRow)
|
|
904
|
+
return [];
|
|
905
|
+
const playbook = rowToPlaybook(playbookRow);
|
|
906
|
+
const trajectoryIds = playbook.evolution.createdFrom ?? [];
|
|
907
|
+
if (trajectoryIds.length === 0)
|
|
908
|
+
return [];
|
|
909
|
+
const seen = new Set();
|
|
910
|
+
const experiences = [];
|
|
911
|
+
for (const trajId of trajectoryIds) {
|
|
912
|
+
const expRows = this.persistence.getExperiencesByTrajectory(trajId);
|
|
913
|
+
for (const expRow of expRows) {
|
|
914
|
+
if (seen.has(expRow.id))
|
|
915
|
+
continue;
|
|
916
|
+
seen.add(expRow.id);
|
|
917
|
+
experiences.push(rowToExperience(expRow));
|
|
918
|
+
if (experiences.length >= k)
|
|
919
|
+
return experiences;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
return experiences;
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Sample a stratified minibatch for two-parent merge acceptance.
|
|
926
|
+
*
|
|
927
|
+
* GEPA's merge acceptance (proposer/merge.py:258-288) samples from
|
|
928
|
+
* three buckets where the two parents disagreed: where A scored
|
|
929
|
+
* higher, where B scored higher, and where they tied. This tests
|
|
930
|
+
* the merged child specifically on the workloads that motivated the
|
|
931
|
+
* merge — the disjoint wins that each parent uniquely had.
|
|
932
|
+
*
|
|
933
|
+
* Stratification considers ONLY experiences where both parents have
|
|
934
|
+
* recorded scores on `taskSignature` — head-to-head pairs. Lopsided
|
|
935
|
+
* experiences (only one parent scored) are excluded; without both
|
|
936
|
+
* scores there's no comparison to bucket on.
|
|
937
|
+
*
|
|
938
|
+
* Returns the picked experiences plus the parents' scores on each
|
|
939
|
+
* (so the caller doesn't need to re-look them up — they are ground
|
|
940
|
+
* truth from the frontier, no judge call needed).
|
|
941
|
+
*/
|
|
942
|
+
async sampleMergeMinibatch(parentAId, parentBId, taskSignature, k = 6, rng = Math.random) {
|
|
943
|
+
await this.init();
|
|
944
|
+
const rows = this.persistence.getFrontierBySignature(taskSignature);
|
|
945
|
+
// Build (playbook, experience) -> score for both parents.
|
|
946
|
+
const aScores = new Map();
|
|
947
|
+
const bScores = new Map();
|
|
948
|
+
for (const r of rows) {
|
|
949
|
+
if (r.playbook_id === parentAId)
|
|
950
|
+
aScores.set(r.experience_id, r.score);
|
|
951
|
+
else if (r.playbook_id === parentBId)
|
|
952
|
+
bScores.set(r.experience_id, r.score);
|
|
953
|
+
}
|
|
954
|
+
// Bucket experiences scored by BOTH parents.
|
|
955
|
+
const aWins = [];
|
|
956
|
+
const bWins = [];
|
|
957
|
+
const tied = [];
|
|
958
|
+
for (const [expId, aScore] of aScores) {
|
|
959
|
+
const bScore = bScores.get(expId);
|
|
960
|
+
if (bScore === undefined)
|
|
961
|
+
continue;
|
|
962
|
+
if (aScore > bScore)
|
|
963
|
+
aWins.push(expId);
|
|
964
|
+
else if (bScore > aScore)
|
|
965
|
+
bWins.push(expId);
|
|
966
|
+
else
|
|
967
|
+
tied.push(expId);
|
|
968
|
+
}
|
|
969
|
+
// Shuffle each bucket so the picker doesn't deterministically take
|
|
970
|
+
// the head every cycle. Matches GEPA's random within-bucket sampling
|
|
971
|
+
// (merge.py:270-278) and gives variety to the minibatch when the
|
|
972
|
+
// merge proposer revisits the same triplet.
|
|
973
|
+
const shuffled = (xs) => fisherYatesShuffled(xs, rng);
|
|
974
|
+
const aShuf = shuffled(aWins);
|
|
975
|
+
const bShuf = shuffled(bWins);
|
|
976
|
+
const tShuf = shuffled(tied);
|
|
977
|
+
// Even share per bucket. Use ceil(k/3) to match GEPA's per-bucket
|
|
978
|
+
// count (merge.py:264-268) — the initial pick may exceed k, then
|
|
979
|
+
// the spillover loop trims excess.
|
|
980
|
+
const perBucket = Math.max(1, Math.ceil(k / 3));
|
|
981
|
+
const picked = new Set();
|
|
982
|
+
const pickFrom = (bucket, n) => {
|
|
983
|
+
for (const id of bucket.slice(0, n)) {
|
|
984
|
+
if (picked.size >= k)
|
|
985
|
+
return;
|
|
986
|
+
picked.add(id);
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
pickFrom(aShuf, perBucket);
|
|
990
|
+
pickFrom(bShuf, perBucket);
|
|
991
|
+
pickFrom(tShuf, perBucket);
|
|
992
|
+
// Spillover: if any bucket was short, top up from the others until k.
|
|
993
|
+
// Bounded iteration count handles the case where all buckets are
|
|
994
|
+
// exhausted before reaching k.
|
|
995
|
+
const allBuckets = [aShuf, bShuf, tShuf];
|
|
996
|
+
let idx = 0;
|
|
997
|
+
let lastSize = picked.size;
|
|
998
|
+
while (picked.size < k && idx < allBuckets.length * 10) {
|
|
999
|
+
const bucket = allBuckets[idx % allBuckets.length];
|
|
1000
|
+
for (const id of bucket) {
|
|
1001
|
+
if (picked.size >= k)
|
|
1002
|
+
break;
|
|
1003
|
+
picked.add(id);
|
|
1004
|
+
}
|
|
1005
|
+
idx++;
|
|
1006
|
+
if (picked.size === lastSize && idx % allBuckets.length === 0)
|
|
1007
|
+
break;
|
|
1008
|
+
lastSize = picked.size;
|
|
1009
|
+
}
|
|
1010
|
+
const experiences = [];
|
|
1011
|
+
for (const expId of picked) {
|
|
1012
|
+
const expRow = this.persistence.getExperience(expId);
|
|
1013
|
+
if (expRow)
|
|
1014
|
+
experiences.push(rowToExperience(expRow));
|
|
1015
|
+
}
|
|
1016
|
+
const pickedSet = picked;
|
|
1017
|
+
return {
|
|
1018
|
+
experiences,
|
|
1019
|
+
parentAScoreByExp: aScores,
|
|
1020
|
+
parentBScoreByExp: bScores,
|
|
1021
|
+
buckets: {
|
|
1022
|
+
aWins: aWins.filter((id) => pickedSet.has(id)),
|
|
1023
|
+
bWins: bWins.filter((id) => pickedSet.has(id)),
|
|
1024
|
+
tied: tied.filter((id) => pickedSet.has(id)),
|
|
1025
|
+
},
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Get the content hash for a playbook (used as the eval-cache key).
|
|
1030
|
+
* Convenience wrapper around `playbookHash()` for callers that don't
|
|
1031
|
+
* want to import the utility directly.
|
|
1032
|
+
*/
|
|
1033
|
+
hashOf(playbook) {
|
|
1034
|
+
return playbookHash(playbook);
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Frontier-aware variant of `findMatching`.
|
|
1038
|
+
*
|
|
1039
|
+
* When the task's signature has recorded outcomes, ranks dominator
|
|
1040
|
+
* playbooks by their per-signature win count (Pareto sampling — direct
|
|
1041
|
+
* port of GEPA's `select_program_candidate_from_pareto_front`,
|
|
1042
|
+
* gepa_utils.py:90-117). Otherwise falls back to text-similarity
|
|
1043
|
+
* matching (cold-start path).
|
|
1044
|
+
*
|
|
1045
|
+
* Returns a list of matches: the sampled dominator first, then other
|
|
1046
|
+
* dominators by descending wins, then text-similarity matches to fill
|
|
1047
|
+
* to `k`. Score is normalized so the sampled dominator gets 1.0.
|
|
1048
|
+
*/
|
|
1049
|
+
async findMatchingFrontierAware(context, taskSignature, options) {
|
|
1050
|
+
await this.init();
|
|
1051
|
+
const k = options?.k ?? 5;
|
|
1052
|
+
const prefer = options?.prefer ?? 'best';
|
|
1053
|
+
const dominators = prefer === 'best'
|
|
1054
|
+
? await this.getDominatorPlaybooks({
|
|
1055
|
+
taskSignature,
|
|
1056
|
+
domain: options?.domains?.[0],
|
|
1057
|
+
})
|
|
1058
|
+
: await this.getDominatorPlaybooksMultiObjective({
|
|
1059
|
+
taskSignature,
|
|
1060
|
+
objectives: resolvePreferenceObjectives(prefer),
|
|
1061
|
+
domain: options?.domains?.[0],
|
|
1062
|
+
});
|
|
1063
|
+
if (dominators.length === 0) {
|
|
1064
|
+
return this.findMatching(context, options);
|
|
1065
|
+
}
|
|
1066
|
+
// Weighted sample by totalWins. Mirrors gepa_utils.py:103-117:
|
|
1067
|
+
// build a multiset where each dominator appears `totalWins` times,
|
|
1068
|
+
// pick one uniformly at random. Equivalent to weighted sampling.
|
|
1069
|
+
const rng = options?.rng ?? Math.random;
|
|
1070
|
+
const totalWeight = dominators.reduce((s, m) => s + m.totalWins, 0);
|
|
1071
|
+
const target = rng() * totalWeight;
|
|
1072
|
+
let acc = 0;
|
|
1073
|
+
let sampled = dominators[0];
|
|
1074
|
+
for (const m of dominators) {
|
|
1075
|
+
acc += m.totalWins;
|
|
1076
|
+
if (acc >= target) {
|
|
1077
|
+
sampled = m;
|
|
1078
|
+
break;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
const out = [];
|
|
1082
|
+
const includedIds = new Set();
|
|
1083
|
+
// Sampled dominator gets full score.
|
|
1084
|
+
out.push({
|
|
1085
|
+
playbook: sampled.playbook,
|
|
1086
|
+
score: 1.0,
|
|
1087
|
+
matchType: 'situation',
|
|
1088
|
+
retrievalMethod: 'frontier',
|
|
1089
|
+
});
|
|
1090
|
+
includedIds.add(sampled.playbook.id);
|
|
1091
|
+
// Other dominators ranked by wins (already sorted in getDominatorPlaybooks).
|
|
1092
|
+
const sampledWins = sampled.totalWins || 1;
|
|
1093
|
+
for (const m of dominators) {
|
|
1094
|
+
if (includedIds.has(m.playbook.id))
|
|
1095
|
+
continue;
|
|
1096
|
+
if (out.length >= k)
|
|
1097
|
+
break;
|
|
1098
|
+
out.push({
|
|
1099
|
+
playbook: m.playbook,
|
|
1100
|
+
// Clamp below the sampled dominator's 1.0 — when a non-sampled
|
|
1101
|
+
// dominator has more wins than the sampled one, the raw ratio
|
|
1102
|
+
// exceeds 1.0 and corrupts downstream score-threshold checks.
|
|
1103
|
+
score: Math.min(0.95, 0.7 * (m.totalWins / sampledWins)),
|
|
1104
|
+
matchType: 'situation',
|
|
1105
|
+
retrievalMethod: 'frontier',
|
|
1106
|
+
});
|
|
1107
|
+
includedIds.add(m.playbook.id);
|
|
1108
|
+
}
|
|
1109
|
+
// Fill remaining slots with text-similarity matches not already included.
|
|
1110
|
+
if (out.length < k) {
|
|
1111
|
+
const fillerOpts = {
|
|
1112
|
+
...options,
|
|
1113
|
+
k: k + dominators.length, // overdraw to filter
|
|
1114
|
+
};
|
|
1115
|
+
const filler = await this.findMatching(context, fillerOpts);
|
|
1116
|
+
for (const m of filler) {
|
|
1117
|
+
if (includedIds.has(m.playbook.id))
|
|
1118
|
+
continue;
|
|
1119
|
+
if (out.length >= k)
|
|
1120
|
+
break;
|
|
1121
|
+
// Filler scores are lower than dominators by construction.
|
|
1122
|
+
out.push({ ...m, score: Math.min(m.score, 0.5) });
|
|
1123
|
+
includedIds.add(m.playbook.id);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
return out.slice(0, k);
|
|
1127
|
+
}
|
|
308
1128
|
// === LIFECYCLE ===
|
|
309
1129
|
/**
|
|
310
|
-
* Add a new playbook
|
|
1130
|
+
* Add a new playbook. When curation is enabled and an embedding provider is
|
|
1131
|
+
* attached, checks for a near-duplicate first (cosine > _mergeThreshold).
|
|
1132
|
+
* If found, merges the incoming playbook into the existing one (union of
|
|
1133
|
+
* triggers/tactics, higher-confidence strategy, appends createdFrom id) and
|
|
1134
|
+
* returns the existing id. Otherwise inserts as normal.
|
|
1135
|
+
*
|
|
1136
|
+
* When curation is disabled (features.curation = false), always appends.
|
|
1137
|
+
*
|
|
1138
|
+
* Returns the id of the playbook that was ultimately stored (existing or new).
|
|
311
1139
|
*/
|
|
312
1140
|
async add(playbook) {
|
|
313
1141
|
await this.init();
|
|
1142
|
+
// Embed on store when a provider is attached and no embedding exists yet.
|
|
1143
|
+
if (this.embedder && !playbook.embedding) {
|
|
1144
|
+
playbook.embedding = await this.embedder.embed(playbookEmbedText(playbook));
|
|
1145
|
+
}
|
|
1146
|
+
// Near-dup merge (curation path).
|
|
1147
|
+
if (this._curationEnabled && playbook.embedding && this.embedder) {
|
|
1148
|
+
const dupId = await this._findNearDup(playbook);
|
|
1149
|
+
if (dupId) {
|
|
1150
|
+
await this._mergeInto(dupId, playbook);
|
|
1151
|
+
return dupId;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
await this.writeStructural(playbook);
|
|
1155
|
+
this.persistence.insertPlaybook(playbook);
|
|
1156
|
+
this._index.add(playbook.id, playbookIndexText(playbook));
|
|
1157
|
+
return playbook.id;
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* Upsert a playbook parsed from a canonical procedural-memory file.
|
|
1161
|
+
*
|
|
1162
|
+
* This intentionally bypasses near-duplicate curation: reindexing from the
|
|
1163
|
+
* filesystem must reproduce the canonical files, not reinterpret them as new
|
|
1164
|
+
* learned candidates that may be merged away.
|
|
1165
|
+
*/
|
|
1166
|
+
async upsertCanonical(playbook) {
|
|
1167
|
+
await this.init();
|
|
1168
|
+
if (this.embedder && !playbook.embedding) {
|
|
1169
|
+
playbook.embedding = await this.embedder.embed(playbookEmbedText(playbook));
|
|
1170
|
+
}
|
|
314
1171
|
this.persistence.insertPlaybook(playbook);
|
|
315
1172
|
this._index.add(playbook.id, playbookIndexText(playbook));
|
|
1173
|
+
return playbook.id;
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Drop a playbook's derived rows only — the delete-side counterpart of
|
|
1177
|
+
* {@link upsertCanonical}. Unlike {@link delete}, this does NOT call the
|
|
1178
|
+
* structural writer, so it is safe to invoke from a file-event handler
|
|
1179
|
+
* reacting to a SKILL.md that was already removed on disk (the filesystem
|
|
1180
|
+
* cascade): it removes the SQLite row + inverted-index entry without trying
|
|
1181
|
+
* to re-delete the canonical file.
|
|
1182
|
+
*/
|
|
1183
|
+
async removeCanonical(id) {
|
|
1184
|
+
await this.init();
|
|
1185
|
+
this._index.remove(id);
|
|
1186
|
+
return this.persistence.deletePlaybook(id);
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Scan for an existing playbook whose embedding cosine similarity to the
|
|
1190
|
+
* candidate exceeds _mergeThreshold. Returns the best match id or null.
|
|
1191
|
+
*
|
|
1192
|
+
* Lexical fallback when no embedder: use textSimilarity on index text.
|
|
1193
|
+
* The lexical threshold is scaled down proportionally (~0.80) since
|
|
1194
|
+
* textSimilarity scores are sparser.
|
|
1195
|
+
*/
|
|
1196
|
+
async _findNearDup(candidate) {
|
|
1197
|
+
const candidateText = playbookIndexText(candidate);
|
|
1198
|
+
const all = this.getAllSync();
|
|
1199
|
+
let bestScore = 0;
|
|
1200
|
+
let bestId = null;
|
|
1201
|
+
for (const existing of all) {
|
|
1202
|
+
if (existing.id === candidate.id)
|
|
1203
|
+
continue;
|
|
1204
|
+
let score;
|
|
1205
|
+
if (candidate.embedding && existing.embedding) {
|
|
1206
|
+
score = cosineSimilarity(candidate.embedding, existing.embedding);
|
|
1207
|
+
}
|
|
1208
|
+
else {
|
|
1209
|
+
// Lexical fallback: adjust threshold to ~86% of cosine threshold
|
|
1210
|
+
const lexicalThreshold = this._mergeThreshold * 0.86;
|
|
1211
|
+
score = textSimilarity(candidateText, playbookIndexText(existing));
|
|
1212
|
+
if (score < lexicalThreshold)
|
|
1213
|
+
continue;
|
|
1214
|
+
if (score > bestScore) {
|
|
1215
|
+
bestScore = score;
|
|
1216
|
+
bestId = existing.id;
|
|
1217
|
+
}
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
1220
|
+
if (score >= this._mergeThreshold && score > bestScore) {
|
|
1221
|
+
bestScore = score;
|
|
1222
|
+
bestId = existing.id;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
return bestId;
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Merge a new playbook's content into an existing one in-place:
|
|
1229
|
+
* - Union applicability.triggers (dedup)
|
|
1230
|
+
* - Union guidance.tactics (dedup)
|
|
1231
|
+
* - Keep the higher-confidence strategy
|
|
1232
|
+
* - Append the new playbook's first createdFrom id (if any)
|
|
1233
|
+
*
|
|
1234
|
+
* Does NOT bump successCount/failureCount — those are updated via
|
|
1235
|
+
* recordSuccess/recordFailure from the usage-inference path.
|
|
1236
|
+
*/
|
|
1237
|
+
async _mergeInto(existingId, incoming) {
|
|
1238
|
+
const row = this.persistence.getPlaybook(existingId);
|
|
1239
|
+
if (!row)
|
|
1240
|
+
return;
|
|
1241
|
+
const existing = rowToPlaybook(row);
|
|
1242
|
+
// Union triggers
|
|
1243
|
+
const mergedTriggers = Array.from(new Set([...existing.applicability.triggers, ...incoming.applicability.triggers]));
|
|
1244
|
+
// Union tactics
|
|
1245
|
+
const mergedTactics = Array.from(new Set([...existing.guidance.tactics, ...incoming.guidance.tactics]));
|
|
1246
|
+
// Keep higher-confidence strategy
|
|
1247
|
+
const strategy = incoming.confidence > existing.confidence
|
|
1248
|
+
? incoming.guidance.strategy
|
|
1249
|
+
: existing.guidance.strategy;
|
|
1250
|
+
// Append createdFrom ids (dedup)
|
|
1251
|
+
const existingCreatedFrom = new Set(existing.evolution.createdFrom);
|
|
1252
|
+
for (const srcId of incoming.evolution.createdFrom) {
|
|
1253
|
+
existingCreatedFrom.add(srcId);
|
|
1254
|
+
}
|
|
1255
|
+
existing.applicability.triggers = mergedTriggers;
|
|
1256
|
+
existing.guidance.tactics = mergedTactics;
|
|
1257
|
+
existing.guidance.strategy = strategy;
|
|
1258
|
+
existing.evolution.createdFrom = Array.from(existingCreatedFrom);
|
|
1259
|
+
existing.updatedAt = new Date();
|
|
1260
|
+
this.persistence.insertPlaybook(existing);
|
|
1261
|
+
// Re-index with merged triggers
|
|
1262
|
+
this._index.add(existing.id, playbookIndexText(existing));
|
|
1263
|
+
await this.writeStructural(existing);
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* ADDITIVE LEARNING (flag-gated by callers) — find an existing playbook
|
|
1267
|
+
* similar enough to `candidate` to REFINE INTO, WITHOUT requiring an
|
|
1268
|
+
* embedding provider. Similarity is embeddings-optional (cosine when both
|
|
1269
|
+
* embeddings exist, else lexical strategy+situation blend). A non-empty
|
|
1270
|
+
* domain intersection is REQUIRED whenever both declare domains, guarding
|
|
1271
|
+
* against cross-domain over-merge. Returns the best matching existing id
|
|
1272
|
+
* with similarity ≥ `threshold`, or null.
|
|
1273
|
+
*
|
|
1274
|
+
* `opts.candidates` overrides the search pool (e.g. to also scan playbooks
|
|
1275
|
+
* distilled earlier in the same batch that aren't in the library yet);
|
|
1276
|
+
* `opts.excludeId` skips a specific id.
|
|
1277
|
+
*/
|
|
1278
|
+
async findRefineTarget(candidate, threshold, opts) {
|
|
1279
|
+
await this.init();
|
|
1280
|
+
const pool = opts?.candidates ?? this.getAllSync();
|
|
1281
|
+
let bestScore = 0;
|
|
1282
|
+
let bestId = null;
|
|
1283
|
+
for (const existing of pool) {
|
|
1284
|
+
if (existing.id === candidate.id)
|
|
1285
|
+
continue;
|
|
1286
|
+
if (opts?.excludeId && existing.id === opts.excludeId)
|
|
1287
|
+
continue;
|
|
1288
|
+
if (!domainsCompatible(candidate, existing))
|
|
1289
|
+
continue;
|
|
1290
|
+
const score = playbookRefineSimilarity(candidate, existing);
|
|
1291
|
+
if (score >= threshold && score > bestScore) {
|
|
1292
|
+
bestScore = score;
|
|
1293
|
+
bestId = existing.id;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
return bestId;
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* ADDITIVE LEARNING — refine an existing playbook IN PLACE with a freshly
|
|
1300
|
+
* distilled `incoming` one, instead of adding `incoming` as a new
|
|
1301
|
+
* `distilled-<uuid>` row. This is how evidence COMPOUNDS onto one playbook:
|
|
1302
|
+
* - union situations / triggers / anti-patterns / domains / tactics
|
|
1303
|
+
* - keep the existing strategy (stable identity) + append a refinement note
|
|
1304
|
+
* - append incoming.createdFrom (dedup) — the compounding trajectory evidence
|
|
1305
|
+
* - accumulate success/failure counters
|
|
1306
|
+
* - BOUNDED confidence nudge (fraction of remaining headroom, capped 0.95),
|
|
1307
|
+
* never a raw max() — guards runaway inflation across repeated merges
|
|
1308
|
+
* - bump minor version; snapshot the prior version for history
|
|
1309
|
+
* Returns the refined playbook, or undefined when `existingId` is unknown.
|
|
1310
|
+
*/
|
|
1311
|
+
async refineWithDistilled(existingId, incoming) {
|
|
1312
|
+
await this.init();
|
|
1313
|
+
const row = this.persistence.getPlaybook(existingId);
|
|
1314
|
+
if (!row)
|
|
1315
|
+
return undefined;
|
|
1316
|
+
const existing = rowToPlaybook(row);
|
|
1317
|
+
this.persistence.snapshotPlaybookVersion(existingId, existing.evolution.version, 'Pre-additive-refine snapshot');
|
|
1318
|
+
const union = (a, b) => Array.from(new Set([...a, ...b]));
|
|
1319
|
+
existing.applicability.situations = union(existing.applicability.situations, incoming.applicability.situations);
|
|
1320
|
+
existing.applicability.triggers = union(existing.applicability.triggers, incoming.applicability.triggers);
|
|
1321
|
+
existing.applicability.antiPatterns = union(existing.applicability.antiPatterns, incoming.applicability.antiPatterns);
|
|
1322
|
+
existing.applicability.domains = union(existing.applicability.domains, incoming.applicability.domains);
|
|
1323
|
+
existing.guidance.tactics = union(existing.guidance.tactics, incoming.guidance.tactics);
|
|
1324
|
+
existing.evolution.createdFrom = union(existing.evolution.createdFrom, incoming.evolution.createdFrom);
|
|
1325
|
+
existing.evolution.successCount += incoming.evolution.successCount;
|
|
1326
|
+
existing.evolution.failureCount += incoming.evolution.failureCount;
|
|
1327
|
+
const positive = incoming.evolution.successCount >= incoming.evolution.failureCount;
|
|
1328
|
+
existing.evolution.refinements = [
|
|
1329
|
+
...existing.evolution.refinements,
|
|
1330
|
+
{
|
|
1331
|
+
context: 'additive-consolidation',
|
|
1332
|
+
addition: `Merged distilled trajectory(s): ${incoming.evolution.createdFrom.join(', ') || '(none)'}`,
|
|
1333
|
+
source: positive ? 'success' : 'failure',
|
|
1334
|
+
addedAt: new Date(),
|
|
1335
|
+
},
|
|
1336
|
+
];
|
|
1337
|
+
// Bounded confidence update — see docstring. Positive evidence moves 5% of
|
|
1338
|
+
// the remaining headroom toward 1 (capped 0.95); failure-only nudges down.
|
|
1339
|
+
if (positive) {
|
|
1340
|
+
existing.confidence = Math.min(0.95, existing.confidence + 0.05 * (1 - existing.confidence));
|
|
1341
|
+
}
|
|
1342
|
+
else {
|
|
1343
|
+
existing.confidence = Math.max(0, existing.confidence - 0.05 * existing.confidence);
|
|
1344
|
+
}
|
|
1345
|
+
existing.evolution.version = bumpPlaybookVersion(existing, 'minor');
|
|
1346
|
+
existing.updatedAt = new Date();
|
|
1347
|
+
this.persistence.insertPlaybook(existing);
|
|
1348
|
+
this._index.add(existing.id, playbookIndexText(existing));
|
|
1349
|
+
await this.writeStructural(existing);
|
|
1350
|
+
return existing;
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Prune (delete) playbooks where failureCount >= successCount + minEvidence,
|
|
1354
|
+
* ensuring at least minEvidence observations exist so zero/low-count noise
|
|
1355
|
+
* never triggers pruning. Gated on features.curation.
|
|
1356
|
+
*
|
|
1357
|
+
* Returns the ids of pruned playbooks.
|
|
1358
|
+
*/
|
|
1359
|
+
async pruneHarmful(minEvidence) {
|
|
1360
|
+
await this.init();
|
|
1361
|
+
if (!this._curationEnabled)
|
|
1362
|
+
return [];
|
|
1363
|
+
const threshold = minEvidence ?? this._pruneMinEvidence;
|
|
1364
|
+
const pruned = [];
|
|
1365
|
+
for (const playbook of this.getAllSync()) {
|
|
1366
|
+
const { successCount, failureCount } = playbook.evolution;
|
|
1367
|
+
const total = successCount + failureCount;
|
|
1368
|
+
if (total < threshold)
|
|
1369
|
+
continue; // insufficient evidence
|
|
1370
|
+
if (failureCount >= successCount + threshold) {
|
|
1371
|
+
await this.delete(playbook.id);
|
|
1372
|
+
pruned.push(playbook.id);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
return pruned;
|
|
316
1376
|
}
|
|
317
1377
|
/**
|
|
318
1378
|
* Create and add a new playbook
|
|
@@ -372,10 +1432,8 @@ export class PlaybookLibrary {
|
|
|
372
1432
|
return this.getAllSync()
|
|
373
1433
|
.filter((p) => p.evolution.successCount + p.evolution.failureCount >= 3)
|
|
374
1434
|
.sort((a, b) => {
|
|
375
|
-
const rateA = a.evolution.successCount /
|
|
376
|
-
|
|
377
|
-
const rateB = b.evolution.successCount /
|
|
378
|
-
(b.evolution.successCount + b.evolution.failureCount);
|
|
1435
|
+
const rateA = a.evolution.successCount / (a.evolution.successCount + a.evolution.failureCount);
|
|
1436
|
+
const rateB = b.evolution.successCount / (b.evolution.successCount + b.evolution.failureCount);
|
|
379
1437
|
return rateB - rateA;
|
|
380
1438
|
})
|
|
381
1439
|
.slice(0, k);
|
|
@@ -399,8 +1457,14 @@ export class PlaybookLibrary {
|
|
|
399
1457
|
*/
|
|
400
1458
|
async delete(id) {
|
|
401
1459
|
await this.init();
|
|
1460
|
+
const row = this.persistence.getPlaybook(id);
|
|
1461
|
+
const playbook = row ? rowToPlaybook(row) : undefined;
|
|
402
1462
|
this._index.remove(id);
|
|
403
|
-
|
|
1463
|
+
const deleted = this.persistence.deletePlaybook(id);
|
|
1464
|
+
if (deleted && playbook) {
|
|
1465
|
+
await this.deleteStructural(playbook);
|
|
1466
|
+
}
|
|
1467
|
+
return deleted;
|
|
404
1468
|
}
|
|
405
1469
|
/**
|
|
406
1470
|
* Get count
|
|
@@ -437,8 +1501,7 @@ export class PlaybookLibrary {
|
|
|
437
1501
|
await this.init();
|
|
438
1502
|
const toDelete = this.getAllSync().filter((p) => p.provenance?.origin === origin);
|
|
439
1503
|
for (const playbook of toDelete) {
|
|
440
|
-
this.
|
|
441
|
-
this._index.remove(playbook.id);
|
|
1504
|
+
await this.delete(playbook.id);
|
|
442
1505
|
}
|
|
443
1506
|
return toDelete.length;
|
|
444
1507
|
}
|
|
@@ -449,11 +1512,9 @@ export class PlaybookLibrary {
|
|
|
449
1512
|
*/
|
|
450
1513
|
async deleteByCuratedSource(sourcePrefix) {
|
|
451
1514
|
await this.init();
|
|
452
|
-
const toDelete = this.getAllSync().filter((p) => p.provenance?.origin === 'curated' &&
|
|
453
|
-
p.provenance.sourceFile?.startsWith(sourcePrefix));
|
|
1515
|
+
const toDelete = this.getAllSync().filter((p) => p.provenance?.origin === 'curated' && p.provenance.sourceFile?.startsWith(sourcePrefix));
|
|
454
1516
|
for (const playbook of toDelete) {
|
|
455
|
-
this.
|
|
456
|
-
this._index.remove(playbook.id);
|
|
1517
|
+
await this.delete(playbook.id);
|
|
457
1518
|
}
|
|
458
1519
|
return toDelete.length;
|
|
459
1520
|
}
|
|
@@ -487,6 +1548,126 @@ export class PlaybookLibrary {
|
|
|
487
1548
|
return this.persistence.getAllPlaybooks().map(rowToPlaybook);
|
|
488
1549
|
}
|
|
489
1550
|
}
|
|
1551
|
+
/**
|
|
1552
|
+
* Pure Fisher-Yates shuffle returning a new array. Caller supplies an
|
|
1553
|
+
* `rng` (typically `Math.random` in production, a deterministic source
|
|
1554
|
+
* in tests).
|
|
1555
|
+
*
|
|
1556
|
+
* Robust to `rng()` returning 1.0: `Math.random()` is documented as
|
|
1557
|
+
* `[0, 1)` so production is safe, but the public `rng` type accepts any
|
|
1558
|
+
* `() => number` and tests/users could supply 1.0. Without the clamp,
|
|
1559
|
+
* `floor(1.0 * (i + 1)) = i + 1` would index out of bounds, writing
|
|
1560
|
+
* `undefined` into the array.
|
|
1561
|
+
*/
|
|
1562
|
+
/**
|
|
1563
|
+
* Shared dominance pruning + member resolution. Both `getDominatorPlaybooks`
|
|
1564
|
+
* and `getDominatorPlaybooksMultiObjective` use the same algorithm over
|
|
1565
|
+
* different frontier key spaces.
|
|
1566
|
+
*
|
|
1567
|
+
* `frontierSets`: map from an opaque key to the set of playbook IDs that
|
|
1568
|
+
* are at the top score for that key.
|
|
1569
|
+
*
|
|
1570
|
+
* Returns the surviving (non-dominated) playbook IDs.
|
|
1571
|
+
*/
|
|
1572
|
+
function pruneDominated(frontierSets) {
|
|
1573
|
+
const winCounts = new Map();
|
|
1574
|
+
for (const set of frontierSets.values()) {
|
|
1575
|
+
for (const id of set) {
|
|
1576
|
+
winCounts.set(id, (winCounts.get(id) ?? 0) + 1);
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
const candidates = Array.from(winCounts.keys());
|
|
1580
|
+
const dominated = new Set();
|
|
1581
|
+
const isDominated = (target, alive) => {
|
|
1582
|
+
for (const set of frontierSets.values()) {
|
|
1583
|
+
if (!set.has(target))
|
|
1584
|
+
continue;
|
|
1585
|
+
let other = false;
|
|
1586
|
+
for (const id of set) {
|
|
1587
|
+
if (id !== target && alive.has(id)) {
|
|
1588
|
+
other = true;
|
|
1589
|
+
break;
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
if (!other)
|
|
1593
|
+
return false;
|
|
1594
|
+
}
|
|
1595
|
+
return true;
|
|
1596
|
+
};
|
|
1597
|
+
// Sort low-win first so we drop weak dominators preferentially —
|
|
1598
|
+
// matches gepa_utils.py:47 ordering.
|
|
1599
|
+
candidates.sort((a, b) => winCounts.get(a) - winCounts.get(b));
|
|
1600
|
+
let changed = true;
|
|
1601
|
+
while (changed) {
|
|
1602
|
+
changed = false;
|
|
1603
|
+
for (const c of candidates) {
|
|
1604
|
+
if (dominated.has(c))
|
|
1605
|
+
continue;
|
|
1606
|
+
const alive = new Set(candidates.filter((x) => x !== c && !dominated.has(x)));
|
|
1607
|
+
if (isDominated(c, alive)) {
|
|
1608
|
+
dominated.add(c);
|
|
1609
|
+
changed = true;
|
|
1610
|
+
break;
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
return new Set(candidates.filter((c) => !dominated.has(c)));
|
|
1615
|
+
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Resolve surviving playbook IDs into ranked FrontierMember objects.
|
|
1618
|
+
* Shared by both single- and multi-objective dominator methods.
|
|
1619
|
+
*/
|
|
1620
|
+
function resolveFrontierMembers(survivors, frontierSets, persistence, domain) {
|
|
1621
|
+
const members = [];
|
|
1622
|
+
for (const id of survivors) {
|
|
1623
|
+
const row = persistence.getPlaybook(id);
|
|
1624
|
+
if (!row)
|
|
1625
|
+
continue;
|
|
1626
|
+
const playbook = rowToPlaybook(row);
|
|
1627
|
+
if (domain && !playbook.applicability.domains.includes(domain))
|
|
1628
|
+
continue;
|
|
1629
|
+
let total = 0;
|
|
1630
|
+
let unique = 0;
|
|
1631
|
+
for (const set of frontierSets.values()) {
|
|
1632
|
+
if (set.has(id)) {
|
|
1633
|
+
total++;
|
|
1634
|
+
if (set.size === 1)
|
|
1635
|
+
unique++;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
members.push({ playbook, totalWins: total, uniqueWins: unique });
|
|
1639
|
+
}
|
|
1640
|
+
members.sort((a, b) => {
|
|
1641
|
+
if (b.totalWins !== a.totalWins)
|
|
1642
|
+
return b.totalWins - a.totalWins;
|
|
1643
|
+
return b.playbook.confidence - a.playbook.confidence;
|
|
1644
|
+
});
|
|
1645
|
+
return members;
|
|
1646
|
+
}
|
|
1647
|
+
function fisherYatesShuffled(xs, rng) {
|
|
1648
|
+
const out = [...xs];
|
|
1649
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
1650
|
+
const j = Math.min(i, Math.floor(rng() * (i + 1)));
|
|
1651
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
1652
|
+
}
|
|
1653
|
+
return out;
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Resolve an `ObjectivePreference` into the list of objective keys that
|
|
1657
|
+
* the cartesian dominator computation should consider.
|
|
1658
|
+
*/
|
|
1659
|
+
function resolvePreferenceObjectives(prefer) {
|
|
1660
|
+
switch (prefer) {
|
|
1661
|
+
case 'best':
|
|
1662
|
+
return ['quality'];
|
|
1663
|
+
case 'cheap':
|
|
1664
|
+
return ['cost'];
|
|
1665
|
+
case 'fast':
|
|
1666
|
+
return ['latency'];
|
|
1667
|
+
default:
|
|
1668
|
+
return prefer.objectives;
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
490
1671
|
/**
|
|
491
1672
|
* Create a playbook library
|
|
492
1673
|
*/
|