@soleri/core 2.12.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/flows/build.flow.yaml +128 -0
- package/data/flows/deliver.flow.yaml +110 -0
- package/data/flows/design.flow.yaml +108 -0
- package/data/flows/enhance.flow.yaml +90 -0
- package/data/flows/explore.flow.yaml +84 -0
- package/data/flows/fix.flow.yaml +90 -0
- package/data/flows/plan.flow.yaml +87 -0
- package/data/flows/review.flow.yaml +90 -0
- package/dist/agency/agency-manager.d.ts +27 -1
- package/dist/agency/agency-manager.d.ts.map +1 -1
- package/dist/agency/agency-manager.js +180 -9
- package/dist/agency/agency-manager.js.map +1 -1
- package/dist/agency/default-rules.d.ts +7 -0
- package/dist/agency/default-rules.d.ts.map +1 -0
- package/dist/agency/default-rules.js +79 -0
- package/dist/agency/default-rules.js.map +1 -0
- package/dist/agency/types.d.ts +48 -0
- package/dist/agency/types.d.ts.map +1 -1
- package/dist/brain/brain.d.ts +17 -2
- package/dist/brain/brain.d.ts.map +1 -1
- package/dist/brain/brain.js +118 -8
- package/dist/brain/brain.js.map +1 -1
- package/dist/brain/intelligence.d.ts.map +1 -1
- package/dist/brain/intelligence.js +16 -2
- package/dist/brain/intelligence.js.map +1 -1
- package/dist/brain/knowledge-synthesizer.d.ts +37 -0
- package/dist/brain/knowledge-synthesizer.d.ts.map +1 -0
- package/dist/brain/knowledge-synthesizer.js +161 -0
- package/dist/brain/knowledge-synthesizer.js.map +1 -0
- package/dist/brain/learning-radar.d.ts +96 -0
- package/dist/brain/learning-radar.d.ts.map +1 -0
- package/dist/brain/learning-radar.js +202 -0
- package/dist/brain/learning-radar.js.map +1 -0
- package/dist/brain/types.d.ts +15 -0
- package/dist/brain/types.d.ts.map +1 -1
- package/dist/capabilities/chain-mapping.d.ts +21 -0
- package/dist/capabilities/chain-mapping.d.ts.map +1 -0
- package/dist/capabilities/chain-mapping.js +86 -0
- package/dist/capabilities/chain-mapping.js.map +1 -0
- package/dist/capabilities/index.d.ts +10 -0
- package/dist/capabilities/index.d.ts.map +1 -0
- package/dist/capabilities/index.js +8 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/capabilities/registry.d.ts +95 -0
- package/dist/capabilities/registry.d.ts.map +1 -0
- package/dist/capabilities/registry.js +227 -0
- package/dist/capabilities/registry.js.map +1 -0
- package/dist/capabilities/types.d.ts +106 -0
- package/dist/capabilities/types.d.ts.map +1 -0
- package/dist/capabilities/types.js +12 -0
- package/dist/capabilities/types.js.map +1 -0
- package/dist/context/context-engine.d.ts.map +1 -1
- package/dist/context/context-engine.js +82 -17
- package/dist/context/context-engine.js.map +1 -1
- package/dist/context/types.d.ts +5 -0
- package/dist/context/types.d.ts.map +1 -1
- package/dist/control/intent-router.d.ts +12 -1
- package/dist/control/intent-router.d.ts.map +1 -1
- package/dist/control/intent-router.js +126 -2
- package/dist/control/intent-router.js.map +1 -1
- package/dist/control/types.d.ts +17 -0
- package/dist/control/types.d.ts.map +1 -1
- package/dist/curator/classifier.d.ts +18 -0
- package/dist/curator/classifier.d.ts.map +1 -0
- package/dist/curator/classifier.js +61 -0
- package/dist/curator/classifier.js.map +1 -0
- package/dist/curator/quality-gate.d.ts +29 -0
- package/dist/curator/quality-gate.d.ts.map +1 -0
- package/dist/curator/quality-gate.js +88 -0
- package/dist/curator/quality-gate.js.map +1 -0
- package/dist/domain-packs/index.d.ts +8 -0
- package/dist/domain-packs/index.d.ts.map +1 -0
- package/dist/domain-packs/index.js +8 -0
- package/dist/domain-packs/index.js.map +1 -0
- package/dist/domain-packs/inject-rules.d.ts +24 -0
- package/dist/domain-packs/inject-rules.d.ts.map +1 -0
- package/dist/domain-packs/inject-rules.js +65 -0
- package/dist/domain-packs/inject-rules.js.map +1 -0
- package/dist/domain-packs/knowledge-installer.d.ts +27 -0
- package/dist/domain-packs/knowledge-installer.d.ts.map +1 -0
- package/dist/domain-packs/knowledge-installer.js +89 -0
- package/dist/domain-packs/knowledge-installer.js.map +1 -0
- package/dist/domain-packs/loader.d.ts +28 -0
- package/dist/domain-packs/loader.d.ts.map +1 -0
- package/dist/domain-packs/loader.js +105 -0
- package/dist/domain-packs/loader.js.map +1 -0
- package/dist/domain-packs/pack-runtime.d.ts +80 -0
- package/dist/domain-packs/pack-runtime.d.ts.map +1 -0
- package/dist/domain-packs/pack-runtime.js +36 -0
- package/dist/domain-packs/pack-runtime.js.map +1 -0
- package/dist/domain-packs/skills-installer.d.ts +21 -0
- package/dist/domain-packs/skills-installer.d.ts.map +1 -0
- package/dist/domain-packs/skills-installer.js +38 -0
- package/dist/domain-packs/skills-installer.js.map +1 -0
- package/dist/domain-packs/token-resolver.d.ts +37 -0
- package/dist/domain-packs/token-resolver.d.ts.map +1 -0
- package/dist/domain-packs/token-resolver.js +109 -0
- package/dist/domain-packs/token-resolver.js.map +1 -0
- package/dist/domain-packs/types.d.ts +91 -0
- package/dist/domain-packs/types.d.ts.map +1 -0
- package/dist/domain-packs/types.js +122 -0
- package/dist/domain-packs/types.js.map +1 -0
- package/dist/engine/bin/soleri-engine.d.ts +12 -0
- package/dist/engine/bin/soleri-engine.d.ts.map +1 -0
- package/dist/engine/bin/soleri-engine.js +184 -0
- package/dist/engine/bin/soleri-engine.js.map +1 -0
- package/dist/engine/core-ops.d.ts +27 -0
- package/dist/engine/core-ops.d.ts.map +1 -0
- package/dist/engine/core-ops.js +159 -0
- package/dist/engine/core-ops.js.map +1 -0
- package/dist/engine/index.d.ts +19 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/index.js +17 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/register-engine.d.ts +54 -0
- package/dist/engine/register-engine.d.ts.map +1 -0
- package/dist/engine/register-engine.js +270 -0
- package/dist/engine/register-engine.js.map +1 -0
- package/dist/engine/test-helpers.d.ts +30 -0
- package/dist/engine/test-helpers.d.ts.map +1 -0
- package/dist/engine/test-helpers.js +59 -0
- package/dist/engine/test-helpers.js.map +1 -0
- package/dist/events/event-bus.d.ts +30 -0
- package/dist/events/event-bus.d.ts.map +1 -0
- package/dist/events/event-bus.js +51 -0
- package/dist/events/event-bus.js.map +1 -0
- package/dist/flows/chain-runner.d.ts +46 -0
- package/dist/flows/chain-runner.d.ts.map +1 -0
- package/dist/flows/chain-runner.js +271 -0
- package/dist/flows/chain-runner.js.map +1 -0
- package/dist/flows/chain-types.d.ts +103 -0
- package/dist/flows/chain-types.d.ts.map +1 -0
- package/dist/flows/chain-types.js +23 -0
- package/dist/flows/chain-types.js.map +1 -0
- package/dist/flows/context-router.d.ts +39 -0
- package/dist/flows/context-router.d.ts.map +1 -0
- package/dist/flows/context-router.js +206 -0
- package/dist/flows/context-router.js.map +1 -0
- package/dist/flows/dispatch-registry.d.ts +24 -0
- package/dist/flows/dispatch-registry.d.ts.map +1 -0
- package/dist/flows/dispatch-registry.js +70 -0
- package/dist/flows/dispatch-registry.js.map +1 -0
- package/dist/flows/epilogue.d.ts +24 -0
- package/dist/flows/epilogue.d.ts.map +1 -0
- package/dist/flows/epilogue.js +52 -0
- package/dist/flows/epilogue.js.map +1 -0
- package/dist/flows/executor.d.ts +25 -0
- package/dist/flows/executor.d.ts.map +1 -0
- package/dist/flows/executor.js +153 -0
- package/dist/flows/executor.js.map +1 -0
- package/dist/flows/gate-evaluator.d.ts +26 -0
- package/dist/flows/gate-evaluator.d.ts.map +1 -0
- package/dist/flows/gate-evaluator.js +162 -0
- package/dist/flows/gate-evaluator.js.map +1 -0
- package/dist/flows/index.d.ts +14 -0
- package/dist/flows/index.d.ts.map +1 -0
- package/dist/flows/index.js +20 -0
- package/dist/flows/index.js.map +1 -0
- package/dist/flows/loader.d.ts +17 -0
- package/dist/flows/loader.d.ts.map +1 -0
- package/dist/flows/loader.js +61 -0
- package/dist/flows/loader.js.map +1 -0
- package/dist/flows/plan-builder.d.ts +40 -0
- package/dist/flows/plan-builder.d.ts.map +1 -0
- package/dist/flows/plan-builder.js +213 -0
- package/dist/flows/plan-builder.js.map +1 -0
- package/dist/flows/probes.d.ts +11 -0
- package/dist/flows/probes.d.ts.map +1 -0
- package/dist/flows/probes.js +62 -0
- package/dist/flows/probes.js.map +1 -0
- package/dist/flows/types.d.ts +950 -0
- package/dist/flows/types.d.ts.map +1 -0
- package/dist/flows/types.js +105 -0
- package/dist/flows/types.js.map +1 -0
- package/dist/health/doctor-checks.d.ts +15 -0
- package/dist/health/doctor-checks.d.ts.map +1 -0
- package/dist/health/doctor-checks.js +98 -0
- package/dist/health/doctor-checks.js.map +1 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/intake/text-ingester.d.ts +52 -0
- package/dist/intake/text-ingester.d.ts.map +1 -0
- package/dist/intake/text-ingester.js +181 -0
- package/dist/intake/text-ingester.js.map +1 -0
- package/dist/intelligence/loader.d.ts +19 -0
- package/dist/intelligence/loader.d.ts.map +1 -1
- package/dist/intelligence/loader.js +35 -0
- package/dist/intelligence/loader.js.map +1 -1
- package/dist/intelligence/types.d.ts +1 -0
- package/dist/intelligence/types.d.ts.map +1 -1
- package/dist/llm/llm-client.d.ts.map +1 -1
- package/dist/llm/llm-client.js +37 -1
- package/dist/llm/llm-client.js.map +1 -1
- package/dist/llm/oauth-discovery.d.ts +26 -0
- package/dist/llm/oauth-discovery.d.ts.map +1 -0
- package/dist/llm/oauth-discovery.js +149 -0
- package/dist/llm/oauth-discovery.js.map +1 -0
- package/dist/packs/types.d.ts +58 -19
- package/dist/packs/types.d.ts.map +1 -1
- package/dist/packs/types.js +14 -0
- package/dist/packs/types.js.map +1 -1
- package/dist/planning/evidence-collector.d.ts +41 -0
- package/dist/planning/evidence-collector.d.ts.map +1 -0
- package/dist/planning/evidence-collector.js +194 -0
- package/dist/planning/evidence-collector.js.map +1 -0
- package/dist/planning/planner.d.ts +4 -0
- package/dist/planning/planner.d.ts.map +1 -1
- package/dist/planning/planner.js +11 -0
- package/dist/planning/planner.js.map +1 -1
- package/dist/playbooks/generic/onboarding.d.ts +9 -0
- package/dist/playbooks/generic/onboarding.d.ts.map +1 -0
- package/dist/playbooks/generic/onboarding.js +74 -0
- package/dist/playbooks/generic/onboarding.js.map +1 -0
- package/dist/playbooks/playbook-registry.d.ts.map +1 -1
- package/dist/playbooks/playbook-registry.js +2 -0
- package/dist/playbooks/playbook-registry.js.map +1 -1
- package/dist/queue/job-queue.d.ts +92 -0
- package/dist/queue/job-queue.d.ts.map +1 -0
- package/dist/queue/job-queue.js +180 -0
- package/dist/queue/job-queue.js.map +1 -0
- package/dist/queue/pipeline-runner.d.ts +62 -0
- package/dist/queue/pipeline-runner.d.ts.map +1 -0
- package/dist/queue/pipeline-runner.js +126 -0
- package/dist/queue/pipeline-runner.js.map +1 -0
- package/dist/runtime/admin-extra-ops.d.ts.map +1 -1
- package/dist/runtime/admin-extra-ops.js +15 -9
- package/dist/runtime/admin-extra-ops.js.map +1 -1
- package/dist/runtime/admin-ops.js +4 -4
- package/dist/runtime/admin-ops.js.map +1 -1
- package/dist/runtime/admin-setup-ops.d.ts +20 -0
- package/dist/runtime/admin-setup-ops.d.ts.map +1 -0
- package/dist/runtime/admin-setup-ops.js +583 -0
- package/dist/runtime/admin-setup-ops.js.map +1 -0
- package/dist/runtime/capture-ops.d.ts.map +1 -1
- package/dist/runtime/capture-ops.js +33 -1
- package/dist/runtime/capture-ops.js.map +1 -1
- package/dist/runtime/chain-ops.d.ts +9 -0
- package/dist/runtime/chain-ops.d.ts.map +1 -0
- package/dist/runtime/chain-ops.js +107 -0
- package/dist/runtime/chain-ops.js.map +1 -0
- package/dist/runtime/claude-md-helpers.d.ts +65 -0
- package/dist/runtime/claude-md-helpers.d.ts.map +1 -0
- package/dist/runtime/claude-md-helpers.js +173 -0
- package/dist/runtime/claude-md-helpers.js.map +1 -0
- package/dist/runtime/curator-extra-ops.d.ts +3 -2
- package/dist/runtime/curator-extra-ops.d.ts.map +1 -1
- package/dist/runtime/curator-extra-ops.js +81 -3
- package/dist/runtime/curator-extra-ops.js.map +1 -1
- package/dist/runtime/domain-ops.d.ts +21 -5
- package/dist/runtime/domain-ops.d.ts.map +1 -1
- package/dist/runtime/domain-ops.js +64 -6
- package/dist/runtime/domain-ops.js.map +1 -1
- package/dist/runtime/facades/admin-facade.d.ts.map +1 -1
- package/dist/runtime/facades/admin-facade.js +4 -0
- package/dist/runtime/facades/admin-facade.js.map +1 -1
- package/dist/runtime/facades/agency-facade.d.ts.map +1 -1
- package/dist/runtime/facades/agency-facade.js +64 -0
- package/dist/runtime/facades/agency-facade.js.map +1 -1
- package/dist/runtime/facades/brain-facade.d.ts.map +1 -1
- package/dist/runtime/facades/brain-facade.js +122 -1
- package/dist/runtime/facades/brain-facade.js.map +1 -1
- package/dist/runtime/facades/cognee-facade.d.ts.map +1 -1
- package/dist/runtime/facades/cognee-facade.js +3 -1
- package/dist/runtime/facades/cognee-facade.js.map +1 -1
- package/dist/runtime/facades/control-facade.d.ts.map +1 -1
- package/dist/runtime/facades/control-facade.js +42 -0
- package/dist/runtime/facades/control-facade.js.map +1 -1
- package/dist/runtime/facades/index.d.ts.map +1 -1
- package/dist/runtime/facades/index.js +10 -6
- package/dist/runtime/facades/index.js.map +1 -1
- package/dist/runtime/facades/memory-facade.d.ts.map +1 -1
- package/dist/runtime/facades/memory-facade.js +20 -2
- package/dist/runtime/facades/memory-facade.js.map +1 -1
- package/dist/runtime/facades/plan-facade.d.ts.map +1 -1
- package/dist/runtime/facades/plan-facade.js +2 -0
- package/dist/runtime/facades/plan-facade.js.map +1 -1
- package/dist/runtime/facades/vault-facade.d.ts.map +1 -1
- package/dist/runtime/facades/vault-facade.js +27 -5
- package/dist/runtime/facades/vault-facade.js.map +1 -1
- package/dist/runtime/intake-ops.d.ts +7 -5
- package/dist/runtime/intake-ops.d.ts.map +1 -1
- package/dist/runtime/intake-ops.js +98 -5
- package/dist/runtime/intake-ops.js.map +1 -1
- package/dist/runtime/memory-extra-ops.d.ts +6 -3
- package/dist/runtime/memory-extra-ops.d.ts.map +1 -1
- package/dist/runtime/memory-extra-ops.js +292 -4
- package/dist/runtime/memory-extra-ops.js.map +1 -1
- package/dist/runtime/orchestrate-ops.d.ts +8 -7
- package/dist/runtime/orchestrate-ops.d.ts.map +1 -1
- package/dist/runtime/orchestrate-ops.js +217 -61
- package/dist/runtime/orchestrate-ops.js.map +1 -1
- package/dist/runtime/planning-extra-ops.d.ts.map +1 -1
- package/dist/runtime/planning-extra-ops.js +85 -0
- package/dist/runtime/planning-extra-ops.js.map +1 -1
- package/dist/runtime/playbook-ops.js +1 -1
- package/dist/runtime/playbook-ops.js.map +1 -1
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +165 -18
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/session-briefing.d.ts +23 -0
- package/dist/runtime/session-briefing.d.ts.map +1 -0
- package/dist/runtime/session-briefing.js +140 -0
- package/dist/runtime/session-briefing.js.map +1 -0
- package/dist/runtime/types.d.ts +29 -2
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/vault-linking-ops.d.ts +13 -0
- package/dist/runtime/vault-linking-ops.d.ts.map +1 -0
- package/dist/runtime/vault-linking-ops.js +365 -0
- package/dist/runtime/vault-linking-ops.js.map +1 -0
- package/dist/vault/linking.d.ts +46 -0
- package/dist/vault/linking.d.ts.map +1 -0
- package/dist/vault/linking.js +275 -0
- package/dist/vault/linking.js.map +1 -0
- package/dist/vault/vault-types.d.ts +37 -0
- package/dist/vault/vault-types.d.ts.map +1 -1
- package/dist/vault/vault.d.ts +37 -0
- package/dist/vault/vault.d.ts.map +1 -1
- package/dist/vault/vault.js +152 -9
- package/dist/vault/vault.js.map +1 -1
- package/package.json +4 -1
- package/src/__tests__/admin-extra-ops.test.ts +1 -1
- package/src/__tests__/admin-ops.test.ts +2 -1
- package/src/__tests__/admin-setup-ops.test.ts +355 -0
- package/src/__tests__/async-infrastructure.test.ts +307 -0
- package/src/__tests__/cognee-client-gaps.test.ts +474 -0
- package/src/__tests__/cognee-hybrid-search.test.ts +492 -0
- package/src/__tests__/cognee-sync-manager-deep.test.ts +654 -0
- package/src/__tests__/cognee-sync-manager.test.ts +1 -0
- package/src/__tests__/core-ops.test.ts +9 -61
- package/src/__tests__/curator-extra-ops.test.ts +6 -2
- package/src/__tests__/curator-pipeline-e2e.test.ts +358 -0
- package/src/__tests__/domain-packs.test.ts +421 -0
- package/src/__tests__/flows.test.ts +604 -0
- package/src/__tests__/memory-extra-ops.test.ts +2 -2
- package/src/__tests__/planning-extra-ops.test.ts +2 -2
- package/src/__tests__/playbook-registry.test.ts +2 -2
- package/src/__tests__/playbook-seeder.test.ts +8 -8
- package/src/__tests__/playbook.test.ts +5 -5
- package/src/__tests__/second-brain-features.test.ts +583 -0
- package/src/__tests__/token-resolver.test.ts +79 -0
- package/src/agency/agency-manager.ts +217 -9
- package/src/agency/default-rules.ts +83 -0
- package/src/agency/types.ts +61 -0
- package/src/brain/brain.ts +110 -8
- package/src/brain/intelligence.ts +21 -2
- package/src/brain/knowledge-synthesizer.ts +218 -0
- package/src/brain/learning-radar.ts +340 -0
- package/src/brain/types.ts +16 -0
- package/src/capabilities/chain-mapping.ts +93 -0
- package/src/capabilities/index.ts +21 -0
- package/src/capabilities/registry.ts +290 -0
- package/src/capabilities/types.ts +143 -0
- package/src/context/context-engine.ts +114 -15
- package/src/context/types.ts +5 -0
- package/src/control/intent-router.ts +153 -2
- package/src/control/types.ts +10 -0
- package/src/curator/classifier.ts +88 -0
- package/src/curator/quality-gate.ts +129 -0
- package/src/domain-packs/index.ts +27 -0
- package/src/domain-packs/inject-rules.ts +74 -0
- package/src/domain-packs/knowledge-installer.ts +116 -0
- package/src/domain-packs/loader.ts +124 -0
- package/src/domain-packs/pack-runtime.ts +99 -0
- package/src/domain-packs/skills-installer.ts +56 -0
- package/src/domain-packs/token-resolver.ts +126 -0
- package/src/domain-packs/types.ts +229 -0
- package/src/engine/__tests__/register-engine.test.ts +104 -0
- package/src/engine/bin/soleri-engine.ts +218 -0
- package/src/engine/core-ops.ts +178 -0
- package/src/engine/index.ts +19 -0
- package/src/engine/register-engine.ts +385 -0
- package/src/engine/test-helpers.ts +83 -0
- package/src/events/event-bus.ts +58 -0
- package/src/flows/chain-runner.ts +369 -0
- package/src/flows/chain-types.ts +57 -0
- package/src/flows/context-router.ts +257 -0
- package/src/flows/dispatch-registry.ts +80 -0
- package/src/flows/epilogue.ts +65 -0
- package/src/flows/executor.ts +182 -0
- package/src/flows/gate-evaluator.ts +171 -0
- package/src/flows/index.ts +52 -0
- package/src/flows/loader.ts +63 -0
- package/src/flows/plan-builder.ts +250 -0
- package/src/flows/probes.ts +70 -0
- package/src/flows/types.ts +217 -0
- package/src/health/doctor-checks.ts +115 -0
- package/src/index.ts +68 -1
- package/src/intake/text-ingester.ts +234 -0
- package/src/intelligence/loader.ts +38 -0
- package/src/intelligence/types.ts +1 -0
- package/src/llm/llm-client.ts +38 -1
- package/src/llm/oauth-discovery.ts +169 -0
- package/src/packs/types.ts +19 -0
- package/src/planning/evidence-collector.ts +247 -0
- package/src/planning/planner.ts +11 -0
- package/src/playbooks/generic/onboarding.ts +79 -0
- package/src/playbooks/playbook-registry.ts +2 -0
- package/src/queue/job-queue.ts +281 -0
- package/src/queue/pipeline-runner.ts +149 -0
- package/src/runtime/admin-extra-ops.ts +14 -8
- package/src/runtime/admin-ops.ts +4 -4
- package/src/runtime/admin-setup-ops.ts +664 -0
- package/src/runtime/capture-ops.ts +40 -1
- package/src/runtime/chain-ops.ts +121 -0
- package/src/runtime/claude-md-helpers.ts +236 -0
- package/src/runtime/curator-extra-ops.ts +86 -3
- package/src/runtime/domain-ops.ts +71 -5
- package/src/runtime/facades/admin-facade.ts +4 -0
- package/src/runtime/facades/agency-facade.ts +68 -0
- package/src/runtime/facades/brain-facade.ts +142 -1
- package/src/runtime/facades/cognee-facade.ts +3 -1
- package/src/runtime/facades/control-facade.ts +45 -0
- package/src/runtime/facades/index.ts +12 -6
- package/src/runtime/facades/memory-facade.ts +20 -2
- package/src/runtime/facades/plan-facade.ts +2 -0
- package/src/runtime/facades/vault-facade.ts +30 -5
- package/src/runtime/intake-ops.ts +107 -5
- package/src/runtime/memory-extra-ops.ts +312 -4
- package/src/runtime/orchestrate-ops.ts +261 -65
- package/src/runtime/planning-extra-ops.ts +94 -0
- package/src/runtime/playbook-ops.ts +1 -1
- package/src/runtime/runtime.ts +164 -19
- package/src/runtime/session-briefing.ts +161 -0
- package/src/runtime/types.ts +29 -2
- package/src/runtime/vault-linking-ops.ts +452 -0
- package/src/vault/linking.ts +333 -0
- package/src/vault/vault-types.ts +46 -0
- package/src/vault/vault.ts +173 -11
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chain Runner — executes multi-step workflows with data flow between steps.
|
|
3
|
+
*
|
|
4
|
+
* Steps call facade ops via a dispatch function. Each step's output is stored
|
|
5
|
+
* in a context object and can be referenced by subsequent steps via $variable syntax.
|
|
6
|
+
*
|
|
7
|
+
* Gates pause execution. Resume via approve(). State persists to SQLite.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { randomUUID } from 'node:crypto';
|
|
11
|
+
import type { PersistenceProvider } from '../persistence/types.js';
|
|
12
|
+
import type { ChainDef, ChainInstance, StepOutput } from './chain-types.js';
|
|
13
|
+
|
|
14
|
+
// ─── Types ───────────────────────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
export type DispatchFn = (op: string, params: Record<string, unknown>) => Promise<unknown>;
|
|
17
|
+
|
|
18
|
+
type GateCheckFn = (
|
|
19
|
+
gate: string,
|
|
20
|
+
stepId: string,
|
|
21
|
+
stepResult: unknown,
|
|
22
|
+
) => Promise<{ passed: boolean; message?: string }>;
|
|
23
|
+
|
|
24
|
+
// ─── Class ───────────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
export class ChainRunner {
|
|
27
|
+
private provider: PersistenceProvider;
|
|
28
|
+
|
|
29
|
+
constructor(provider: PersistenceProvider) {
|
|
30
|
+
this.provider = provider;
|
|
31
|
+
this.initializeTable();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private initializeTable(): void {
|
|
35
|
+
this.provider.execSql(`
|
|
36
|
+
CREATE TABLE IF NOT EXISTS chain_instances (
|
|
37
|
+
id TEXT PRIMARY KEY,
|
|
38
|
+
chain_id TEXT NOT NULL,
|
|
39
|
+
chain_name TEXT NOT NULL DEFAULT '',
|
|
40
|
+
status TEXT NOT NULL DEFAULT 'running',
|
|
41
|
+
current_step TEXT,
|
|
42
|
+
paused_at_gate TEXT,
|
|
43
|
+
input TEXT NOT NULL DEFAULT '{}',
|
|
44
|
+
context TEXT NOT NULL DEFAULT '{}',
|
|
45
|
+
step_outputs TEXT NOT NULL DEFAULT '[]',
|
|
46
|
+
steps_completed INTEGER NOT NULL DEFAULT 0,
|
|
47
|
+
total_steps INTEGER NOT NULL DEFAULT 0,
|
|
48
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
49
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
50
|
+
);
|
|
51
|
+
`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Execute a chain from the beginning (or a specific step).
|
|
56
|
+
*/
|
|
57
|
+
async execute(
|
|
58
|
+
chainDef: ChainDef,
|
|
59
|
+
input: Record<string, unknown>,
|
|
60
|
+
dispatch: DispatchFn,
|
|
61
|
+
gateCheck?: GateCheckFn,
|
|
62
|
+
startFromStep?: string,
|
|
63
|
+
): Promise<ChainInstance> {
|
|
64
|
+
const instanceId = randomUUID().slice(0, 12);
|
|
65
|
+
const instance: ChainInstance = {
|
|
66
|
+
id: instanceId,
|
|
67
|
+
chainId: chainDef.id,
|
|
68
|
+
chainName: chainDef.name ?? chainDef.id,
|
|
69
|
+
status: 'running',
|
|
70
|
+
currentStep: null,
|
|
71
|
+
pausedAtGate: null,
|
|
72
|
+
input,
|
|
73
|
+
context: { input },
|
|
74
|
+
stepOutputs: [],
|
|
75
|
+
stepsCompleted: 0,
|
|
76
|
+
totalSteps: chainDef.steps.length,
|
|
77
|
+
createdAt: new Date().toISOString(),
|
|
78
|
+
updatedAt: new Date().toISOString(),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
this.persist(instance);
|
|
82
|
+
|
|
83
|
+
// Find start index
|
|
84
|
+
let startIdx = 0;
|
|
85
|
+
if (startFromStep) {
|
|
86
|
+
const idx = chainDef.steps.findIndex((s) => s.id === startFromStep);
|
|
87
|
+
if (idx >= 0) startIdx = idx;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return this.runSteps(chainDef, instance, dispatch, gateCheck, startIdx);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Resume a paused chain from where it left off.
|
|
95
|
+
*/
|
|
96
|
+
async resume(
|
|
97
|
+
instanceId: string,
|
|
98
|
+
chainDef: ChainDef,
|
|
99
|
+
dispatch: DispatchFn,
|
|
100
|
+
gateCheck?: GateCheckFn,
|
|
101
|
+
): Promise<ChainInstance> {
|
|
102
|
+
const instance = this.getInstance(instanceId);
|
|
103
|
+
if (!instance) throw new Error(`Chain instance not found: ${instanceId}`);
|
|
104
|
+
if (instance.status !== 'paused') throw new Error(`Chain is ${instance.status}, not paused`);
|
|
105
|
+
|
|
106
|
+
// Find the step after the paused gate
|
|
107
|
+
const pausedStep = instance.pausedAtGate;
|
|
108
|
+
if (!pausedStep) throw new Error('No paused gate to resume from');
|
|
109
|
+
|
|
110
|
+
const stepIdx = chainDef.steps.findIndex((s) => s.id === pausedStep);
|
|
111
|
+
if (stepIdx < 0) throw new Error(`Paused step ${pausedStep} not found in chain def`);
|
|
112
|
+
|
|
113
|
+
// Mark step as approved, move to next
|
|
114
|
+
instance.status = 'running';
|
|
115
|
+
instance.pausedAtGate = null;
|
|
116
|
+
this.persist(instance);
|
|
117
|
+
|
|
118
|
+
return this.runSteps(chainDef, instance, dispatch, gateCheck, stepIdx + 1);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Approve a gate-paused step and resume the chain.
|
|
123
|
+
*/
|
|
124
|
+
async approve(
|
|
125
|
+
instanceId: string,
|
|
126
|
+
chainDef: ChainDef,
|
|
127
|
+
dispatch: DispatchFn,
|
|
128
|
+
gateCheck?: GateCheckFn,
|
|
129
|
+
): Promise<ChainInstance> {
|
|
130
|
+
return this.resume(instanceId, chainDef, dispatch, gateCheck);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Get chain instance status.
|
|
135
|
+
*/
|
|
136
|
+
getInstance(instanceId: string): ChainInstance | null {
|
|
137
|
+
const row = this.provider.get<InstanceRow>('SELECT * FROM chain_instances WHERE id = ?', [
|
|
138
|
+
instanceId,
|
|
139
|
+
]);
|
|
140
|
+
return row ? rowToInstance(row) : null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* List all chain instances.
|
|
145
|
+
*/
|
|
146
|
+
list(limit: number = 20): ChainInstance[] {
|
|
147
|
+
const rows = this.provider.all<InstanceRow>(
|
|
148
|
+
'SELECT * FROM chain_instances ORDER BY updated_at DESC LIMIT ?',
|
|
149
|
+
[limit],
|
|
150
|
+
);
|
|
151
|
+
return rows.map(rowToInstance);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ─── Core Execution Loop ──────────────────────────────────────────
|
|
155
|
+
|
|
156
|
+
private async runSteps(
|
|
157
|
+
chainDef: ChainDef,
|
|
158
|
+
instance: ChainInstance,
|
|
159
|
+
dispatch: DispatchFn,
|
|
160
|
+
gateCheck: GateCheckFn | undefined,
|
|
161
|
+
startIdx: number,
|
|
162
|
+
): Promise<ChainInstance> {
|
|
163
|
+
// Steps MUST run sequentially — step N output feeds step N+1 input.
|
|
164
|
+
// Using recursive approach to satisfy no-await-in-loop lint rule.
|
|
165
|
+
return this.runStep(chainDef, instance, dispatch, gateCheck, startIdx);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private async runStep(
|
|
169
|
+
chainDef: ChainDef,
|
|
170
|
+
instance: ChainInstance,
|
|
171
|
+
dispatch: DispatchFn,
|
|
172
|
+
gateCheck: GateCheckFn | undefined,
|
|
173
|
+
idx: number,
|
|
174
|
+
): Promise<ChainInstance> {
|
|
175
|
+
if (idx >= chainDef.steps.length) {
|
|
176
|
+
instance.status = 'completed';
|
|
177
|
+
instance.currentStep = null;
|
|
178
|
+
this.persist(instance);
|
|
179
|
+
return instance;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const step = chainDef.steps[idx];
|
|
183
|
+
instance.currentStep = step.id;
|
|
184
|
+
this.persist(instance);
|
|
185
|
+
|
|
186
|
+
const resolvedParams = resolveParams(step.params ?? {}, instance.context);
|
|
187
|
+
|
|
188
|
+
const stepStart = Date.now();
|
|
189
|
+
let result: unknown;
|
|
190
|
+
let stepStatus: StepOutput['status'] = 'completed';
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
result = await dispatch(step.op, resolvedParams);
|
|
194
|
+
} catch (err) {
|
|
195
|
+
result = { error: (err as Error).message };
|
|
196
|
+
stepStatus = 'failed';
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const output: StepOutput = {
|
|
200
|
+
stepId: step.id,
|
|
201
|
+
op: step.op,
|
|
202
|
+
result,
|
|
203
|
+
status: stepStatus,
|
|
204
|
+
durationMs: Date.now() - stepStart,
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
instance.stepOutputs.push(output);
|
|
208
|
+
instance.context[step.id] = result;
|
|
209
|
+
if (step.output) instance.context[step.output] = result;
|
|
210
|
+
if (stepStatus === 'completed') instance.stepsCompleted++;
|
|
211
|
+
|
|
212
|
+
// Check gate
|
|
213
|
+
if (step.gate && step.gate !== 'none' && stepStatus === 'completed') {
|
|
214
|
+
const gateResult = await this.evaluateChainGate(step.gate, step.id, result, gateCheck);
|
|
215
|
+
if (!gateResult.passed) {
|
|
216
|
+
if (step.gate === 'user-approval') {
|
|
217
|
+
instance.status = 'paused';
|
|
218
|
+
instance.pausedAtGate = step.id;
|
|
219
|
+
this.persist(instance);
|
|
220
|
+
return instance;
|
|
221
|
+
}
|
|
222
|
+
instance.status = 'failed';
|
|
223
|
+
this.persist(instance);
|
|
224
|
+
return instance;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (stepStatus === 'failed') {
|
|
229
|
+
instance.status = 'failed';
|
|
230
|
+
this.persist(instance);
|
|
231
|
+
return instance;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
this.persist(instance);
|
|
235
|
+
return this.runStep(chainDef, instance, dispatch, gateCheck, idx + 1);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private async evaluateChainGate(
|
|
239
|
+
gate: string,
|
|
240
|
+
stepId: string,
|
|
241
|
+
stepResult: unknown,
|
|
242
|
+
gateCheck?: GateCheckFn,
|
|
243
|
+
): Promise<{ passed: boolean; message?: string }> {
|
|
244
|
+
switch (gate) {
|
|
245
|
+
case 'user-approval':
|
|
246
|
+
return { passed: false, message: 'Awaiting user approval' };
|
|
247
|
+
|
|
248
|
+
case 'auto-test': {
|
|
249
|
+
const result = stepResult as Record<string, unknown> | null;
|
|
250
|
+
if (!result) return { passed: false, message: 'Step returned no result' };
|
|
251
|
+
if (result.error) return { passed: false, message: `Step error: ${result.error}` };
|
|
252
|
+
return { passed: true };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
case 'vault-check': {
|
|
256
|
+
if (gateCheck) return gateCheck(gate, stepId, stepResult);
|
|
257
|
+
return { passed: true };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
default:
|
|
261
|
+
return { passed: true };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// ─── Persistence ──────────────────────────────────────────────────
|
|
266
|
+
|
|
267
|
+
private persist(instance: ChainInstance): void {
|
|
268
|
+
instance.updatedAt = new Date().toISOString();
|
|
269
|
+
this.provider.run(
|
|
270
|
+
`INSERT OR REPLACE INTO chain_instances
|
|
271
|
+
(id, chain_id, chain_name, status, current_step, paused_at_gate, input, context, step_outputs, steps_completed, total_steps, created_at, updated_at)
|
|
272
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
273
|
+
[
|
|
274
|
+
instance.id,
|
|
275
|
+
instance.chainId,
|
|
276
|
+
instance.chainName,
|
|
277
|
+
instance.status,
|
|
278
|
+
instance.currentStep,
|
|
279
|
+
instance.pausedAtGate,
|
|
280
|
+
JSON.stringify(instance.input),
|
|
281
|
+
JSON.stringify(instance.context),
|
|
282
|
+
JSON.stringify(instance.stepOutputs),
|
|
283
|
+
instance.stepsCompleted,
|
|
284
|
+
instance.totalSteps,
|
|
285
|
+
instance.createdAt,
|
|
286
|
+
instance.updatedAt,
|
|
287
|
+
],
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// ─── Variable Resolution ─────────────────────────────────────────────
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Resolve $variable references in params.
|
|
296
|
+
* $input.url → context.input.url
|
|
297
|
+
* $research.title → context.research.title
|
|
298
|
+
* $stepId → context.stepId (whole object)
|
|
299
|
+
*/
|
|
300
|
+
function resolveParams(
|
|
301
|
+
params: Record<string, unknown>,
|
|
302
|
+
context: Record<string, unknown>,
|
|
303
|
+
): Record<string, unknown> {
|
|
304
|
+
const resolved: Record<string, unknown> = {};
|
|
305
|
+
for (const [key, value] of Object.entries(params)) {
|
|
306
|
+
resolved[key] = resolveValue(value, context);
|
|
307
|
+
}
|
|
308
|
+
return resolved;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function resolveValue(value: unknown, context: Record<string, unknown>): unknown {
|
|
312
|
+
if (typeof value === 'string' && value.startsWith('$')) {
|
|
313
|
+
return resolveReference(value.slice(1), context);
|
|
314
|
+
}
|
|
315
|
+
if (Array.isArray(value)) {
|
|
316
|
+
return value.map((v) => resolveValue(v, context));
|
|
317
|
+
}
|
|
318
|
+
if (value !== null && typeof value === 'object') {
|
|
319
|
+
return resolveParams(value as Record<string, unknown>, context);
|
|
320
|
+
}
|
|
321
|
+
return value;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function resolveReference(path: string, context: Record<string, unknown>): unknown {
|
|
325
|
+
const parts = path.split('.');
|
|
326
|
+
let current: unknown = context;
|
|
327
|
+
for (const part of parts) {
|
|
328
|
+
if (current === null || current === undefined) return undefined;
|
|
329
|
+
if (typeof current !== 'object') return undefined;
|
|
330
|
+
current = (current as Record<string, unknown>)[part];
|
|
331
|
+
}
|
|
332
|
+
return current;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// ─── Row Types ───────────────────────────────────────────────────────
|
|
336
|
+
|
|
337
|
+
interface InstanceRow {
|
|
338
|
+
id: string;
|
|
339
|
+
chain_id: string;
|
|
340
|
+
chain_name: string;
|
|
341
|
+
status: string;
|
|
342
|
+
current_step: string | null;
|
|
343
|
+
paused_at_gate: string | null;
|
|
344
|
+
input: string;
|
|
345
|
+
context: string;
|
|
346
|
+
step_outputs: string;
|
|
347
|
+
steps_completed: number;
|
|
348
|
+
total_steps: number;
|
|
349
|
+
created_at: string;
|
|
350
|
+
updated_at: string;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function rowToInstance(row: InstanceRow): ChainInstance {
|
|
354
|
+
return {
|
|
355
|
+
id: row.id,
|
|
356
|
+
chainId: row.chain_id,
|
|
357
|
+
chainName: row.chain_name,
|
|
358
|
+
status: row.status as ChainInstance['status'],
|
|
359
|
+
currentStep: row.current_step,
|
|
360
|
+
pausedAtGate: row.paused_at_gate,
|
|
361
|
+
input: JSON.parse(row.input) as Record<string, unknown>,
|
|
362
|
+
context: JSON.parse(row.context) as Record<string, unknown>,
|
|
363
|
+
stepOutputs: JSON.parse(row.step_outputs) as StepOutput[],
|
|
364
|
+
stepsCompleted: row.steps_completed,
|
|
365
|
+
totalSteps: row.total_steps,
|
|
366
|
+
createdAt: row.created_at,
|
|
367
|
+
updatedAt: row.updated_at,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chain types — composable multi-step workflows with data flow.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
// ─── Chain Definition (YAML schema) ──────────────────────────────────
|
|
8
|
+
|
|
9
|
+
export const chainStepSchema = z.object({
|
|
10
|
+
id: z.string(),
|
|
11
|
+
op: z.string().describe('Facade op to call'),
|
|
12
|
+
params: z
|
|
13
|
+
.record(z.unknown())
|
|
14
|
+
.optional()
|
|
15
|
+
.describe('Params — use $input.x or $stepId.field for data flow'),
|
|
16
|
+
output: z.string().optional().describe('Key to store step result under'),
|
|
17
|
+
gate: z.enum(['user-approval', 'auto-test', 'vault-check', 'none']).optional(),
|
|
18
|
+
description: z.string().optional(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const chainDefSchema = z.object({
|
|
22
|
+
id: z.string(),
|
|
23
|
+
name: z.string().optional(),
|
|
24
|
+
description: z.string().optional(),
|
|
25
|
+
steps: z.array(chainStepSchema).min(1),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export type ChainDef = z.infer<typeof chainDefSchema>;
|
|
29
|
+
export type ChainStep = z.infer<typeof chainStepSchema>;
|
|
30
|
+
|
|
31
|
+
// ─── Chain Instance (runtime state) ──────────────────────────────────
|
|
32
|
+
|
|
33
|
+
export type ChainStatus = 'running' | 'paused' | 'completed' | 'failed';
|
|
34
|
+
|
|
35
|
+
export interface StepOutput {
|
|
36
|
+
stepId: string;
|
|
37
|
+
op: string;
|
|
38
|
+
result: unknown;
|
|
39
|
+
status: 'completed' | 'failed' | 'skipped';
|
|
40
|
+
durationMs: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ChainInstance {
|
|
44
|
+
id: string;
|
|
45
|
+
chainId: string;
|
|
46
|
+
chainName: string;
|
|
47
|
+
status: ChainStatus;
|
|
48
|
+
currentStep: string | null;
|
|
49
|
+
pausedAtGate: string | null;
|
|
50
|
+
input: Record<string, unknown>;
|
|
51
|
+
context: Record<string, unknown>;
|
|
52
|
+
stepOutputs: StepOutput[];
|
|
53
|
+
stepsCompleted: number;
|
|
54
|
+
totalSteps: number;
|
|
55
|
+
createdAt: string;
|
|
56
|
+
updatedAt: string;
|
|
57
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context-sensitive chain routing — the same intent routes to different chain
|
|
3
|
+
* sequences depending on what's being built/fixed/reviewed.
|
|
4
|
+
*
|
|
5
|
+
* Building a Button follows a different workflow than building a Page layout.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { PlanStep, ProbeName } from './types.js';
|
|
9
|
+
import { chainToToolName, chainToRequires } from './plan-builder.js';
|
|
10
|
+
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Types
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
export interface ContextOverride {
|
|
16
|
+
/** Pattern to match against prompt or entities */
|
|
17
|
+
match: RegExp;
|
|
18
|
+
/** Context label */
|
|
19
|
+
context: string;
|
|
20
|
+
/** Chain substitutions: original chain → replacement chain */
|
|
21
|
+
chainOverrides?: Record<string, string>;
|
|
22
|
+
/** Additional chains to inject before specific steps */
|
|
23
|
+
injectBefore?: Record<string, string[]>;
|
|
24
|
+
/** Additional chains to inject after specific steps */
|
|
25
|
+
injectAfter?: Record<string, string[]>;
|
|
26
|
+
/** Steps to skip in this context */
|
|
27
|
+
skipSteps?: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Context override definitions
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
const BUILD_OVERRIDES: ContextOverride[] = [
|
|
35
|
+
{
|
|
36
|
+
match: /\b(button|icon|badge|chip|tag|pill)\b/i,
|
|
37
|
+
context: 'small-component',
|
|
38
|
+
skipSteps: ['get-architecture'],
|
|
39
|
+
injectBefore: {
|
|
40
|
+
validate: ['button-semantics-check'],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
match: /\b(page|layout|dashboard|screen|view)\b/i,
|
|
45
|
+
context: 'large-component',
|
|
46
|
+
injectBefore: {
|
|
47
|
+
validate: ['responsive-patterns'],
|
|
48
|
+
},
|
|
49
|
+
injectAfter: {
|
|
50
|
+
validate: ['performance-check'],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
match: /\b(form|input|select|textarea|checkbox|radio|switch|dropdown)\b/i,
|
|
55
|
+
context: 'form-component',
|
|
56
|
+
injectBefore: {
|
|
57
|
+
validate: ['defensive-design', 'accessibility-precheck'],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
match: /\b(modal|dialog|sheet|drawer|popover|overlay|tooltip)\b/i,
|
|
62
|
+
context: 'container-component',
|
|
63
|
+
injectBefore: {
|
|
64
|
+
validate: ['container-pattern-check', 'dialog-patterns'],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const FIX_OVERRIDES: ContextOverride[] = [
|
|
70
|
+
{
|
|
71
|
+
match: /\b(styl(e|ing)|color|token|theme|palette|css)\b/i,
|
|
72
|
+
context: 'design-fix',
|
|
73
|
+
injectBefore: {
|
|
74
|
+
validate: ['contrast-check', 'token-validation'],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
match: /\b(accessib|a11y|aria|screen.?reader|keyboard|focus)\b/i,
|
|
79
|
+
context: 'a11y-fix',
|
|
80
|
+
injectBefore: {
|
|
81
|
+
validate: ['accessibility-audit'],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
const REVIEW_OVERRIDES: ContextOverride[] = [
|
|
87
|
+
{
|
|
88
|
+
match: /\b(pr|pull.?request|diff|merge)\b/i,
|
|
89
|
+
context: 'pr-review',
|
|
90
|
+
injectAfter: {
|
|
91
|
+
'check-rules': ['review-pr-design'],
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
match: /\b(architecture|import|dependency|structure)\b/i,
|
|
96
|
+
context: 'architecture-review',
|
|
97
|
+
injectAfter: {
|
|
98
|
+
'check-rules': ['check-architecture'],
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Registry mapping flow IDs to their context overrides.
|
|
105
|
+
*/
|
|
106
|
+
const FLOW_OVERRIDES: Record<string, ContextOverride[]> = {
|
|
107
|
+
'BUILD-flow': BUILD_OVERRIDES,
|
|
108
|
+
'FIX-flow': FIX_OVERRIDES,
|
|
109
|
+
'REVIEW-flow': REVIEW_OVERRIDES,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
// Public API
|
|
114
|
+
// ---------------------------------------------------------------------------
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Detect which contexts apply to a prompt and entity set.
|
|
118
|
+
* Returns an array of matching context labels.
|
|
119
|
+
*/
|
|
120
|
+
export function detectContext(
|
|
121
|
+
prompt: string,
|
|
122
|
+
entities: { components: string[]; actions: string[] },
|
|
123
|
+
): string[] {
|
|
124
|
+
const contexts: string[] = [];
|
|
125
|
+
const searchText = [prompt, ...entities.components, ...entities.actions].join(' ');
|
|
126
|
+
|
|
127
|
+
// Check all flow overrides — a prompt might match contexts across flows
|
|
128
|
+
for (const overrides of Object.values(FLOW_OVERRIDES)) {
|
|
129
|
+
for (const override of overrides) {
|
|
130
|
+
if (override.match.test(searchText) && !contexts.includes(override.context)) {
|
|
131
|
+
contexts.push(override.context);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return contexts;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Apply context overrides to a set of plan steps: chain substitutions,
|
|
141
|
+
* injections (before/after), and step skipping.
|
|
142
|
+
*/
|
|
143
|
+
export function applyContextOverrides(
|
|
144
|
+
steps: PlanStep[],
|
|
145
|
+
contexts: string[],
|
|
146
|
+
flowId: string,
|
|
147
|
+
agentId: string = 'agent',
|
|
148
|
+
): PlanStep[] {
|
|
149
|
+
const overrides = FLOW_OVERRIDES[flowId];
|
|
150
|
+
if (!overrides || contexts.length === 0) return steps;
|
|
151
|
+
|
|
152
|
+
// Collect active overrides for the detected contexts
|
|
153
|
+
const active = overrides.filter((o) => contexts.includes(o.context));
|
|
154
|
+
if (active.length === 0) return steps;
|
|
155
|
+
|
|
156
|
+
// Aggregate all skip, inject-before, inject-after, and chain overrides
|
|
157
|
+
const skipSet = new Set<string>();
|
|
158
|
+
const injectBefore = new Map<string, string[]>();
|
|
159
|
+
const injectAfter = new Map<string, string[]>();
|
|
160
|
+
const chainSubs = new Map<string, string>();
|
|
161
|
+
|
|
162
|
+
for (const ov of active) {
|
|
163
|
+
if (ov.skipSteps) ov.skipSteps.forEach((s) => skipSet.add(s));
|
|
164
|
+
if (ov.injectBefore) {
|
|
165
|
+
for (const [stepId, chains] of Object.entries(ov.injectBefore)) {
|
|
166
|
+
const existing = injectBefore.get(stepId) ?? [];
|
|
167
|
+
injectBefore.set(stepId, [...existing, ...chains]);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (ov.injectAfter) {
|
|
171
|
+
for (const [stepId, chains] of Object.entries(ov.injectAfter)) {
|
|
172
|
+
const existing = injectAfter.get(stepId) ?? [];
|
|
173
|
+
injectAfter.set(stepId, [...existing, ...chains]);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (ov.chainOverrides) {
|
|
177
|
+
for (const [from, to] of Object.entries(ov.chainOverrides)) {
|
|
178
|
+
chainSubs.set(from, to);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const result: PlanStep[] = [];
|
|
184
|
+
|
|
185
|
+
for (const step of steps) {
|
|
186
|
+
// 1. Skip steps
|
|
187
|
+
if (skipSet.has(step.id)) continue;
|
|
188
|
+
|
|
189
|
+
// 2. Inject before
|
|
190
|
+
const beforeChains = injectBefore.get(step.id);
|
|
191
|
+
if (beforeChains) {
|
|
192
|
+
result.push(buildInjectedStep(step.id, 'before', beforeChains, agentId));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// 3. Apply chain substitutions to existing step
|
|
196
|
+
let processed = step;
|
|
197
|
+
if (chainSubs.size > 0) {
|
|
198
|
+
const newTools = step.tools.map((tool) => {
|
|
199
|
+
for (const [from, to] of chainSubs) {
|
|
200
|
+
const fromTool = chainToToolName(from, agentId);
|
|
201
|
+
if (tool === fromTool) return chainToToolName(to, agentId);
|
|
202
|
+
}
|
|
203
|
+
return tool;
|
|
204
|
+
});
|
|
205
|
+
if (newTools.some((t, i) => t !== step.tools[i])) {
|
|
206
|
+
processed = { ...step, tools: newTools };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
result.push(processed);
|
|
211
|
+
|
|
212
|
+
// 4. Inject after
|
|
213
|
+
const afterChains = injectAfter.get(step.id);
|
|
214
|
+
if (afterChains) {
|
|
215
|
+
result.push(buildInjectedStep(step.id, 'after', afterChains, agentId));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Get all registered context overrides for a flow (useful for introspection).
|
|
224
|
+
*/
|
|
225
|
+
export function getFlowOverrides(flowId: string): ContextOverride[] {
|
|
226
|
+
return FLOW_OVERRIDES[flowId] ?? [];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ---------------------------------------------------------------------------
|
|
230
|
+
// Helpers
|
|
231
|
+
// ---------------------------------------------------------------------------
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Build a synthetic PlanStep from injected chains.
|
|
235
|
+
*/
|
|
236
|
+
function buildInjectedStep(
|
|
237
|
+
anchorStepId: string,
|
|
238
|
+
position: 'before' | 'after',
|
|
239
|
+
chains: string[],
|
|
240
|
+
agentId: string,
|
|
241
|
+
): PlanStep {
|
|
242
|
+
const tools = chains.map((c) => chainToToolName(c, agentId));
|
|
243
|
+
const requires: ProbeName[] = [];
|
|
244
|
+
for (const chain of chains) {
|
|
245
|
+
const req = chainToRequires(chain);
|
|
246
|
+
if (req && !requires.includes(req)) requires.push(req);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
id: `ctx-${position}-${anchorStepId}`,
|
|
251
|
+
name: `Context: ${chains.join(', ')} (${position} ${anchorStepId})`,
|
|
252
|
+
tools,
|
|
253
|
+
parallel: chains.length > 1,
|
|
254
|
+
requires,
|
|
255
|
+
status: 'pending',
|
|
256
|
+
};
|
|
257
|
+
}
|