2sagaco48 1.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/diagnostics.mjs +141 -0
- package/dist/compute.worker-j5ahIpF-.js +1 -0
- package/dist/graph.worker-DG6iGCB9.js +1 -0
- package/dist/index.html +2314 -0
- package/flatten-guide.md +248 -0
- package/index.html +12 -0
- package/package.json +38 -0
- package/src/App.orig.tsx +204 -0
- package/src/App.orig1.tsx +27 -0
- package/src/App.orig2.tsx +25 -0
- package/src/App.tsx +3 -0
- package/src/BaseApp.tsx +18 -0
- package/src/INTEGRATION_LEDGER.md +22 -0
- package/src/PERSIST_CANARY.orig.txt +1 -0
- package/src/PERSIST_CANARY.txt +1 -0
- package/src/REGRESSION_LEDGER.md +651 -0
- package/src/TEMPLATE_PIPELINE_AUDIT.md +208 -0
- package/src/WILLIAMS_PERSONA_GUIDE.md +62 -0
- package/src/chat/VeritasChat.tsx +69 -0
- package/src/chat/synthesis.ts +31 -0
- package/src/chat/tier.ts +45 -0
- package/src/components/AdaptersPage.orig.tsx +99 -0
- package/src/components/AdaptersPage.tsx +3 -0
- package/src/components/AdversarialPanel.tsx +136 -0
- package/src/components/AnchorBaselinePanel.tsx +75 -0
- package/src/components/AnswerPanel.tsx +60 -0
- package/src/components/ArtifactPanel.tsx +43 -0
- package/src/components/ChatApp.orig.tsx +1582 -0
- package/src/components/ChatApp.orig1.tsx +722 -0
- package/src/components/ChatApp.tsx +95 -0
- package/src/components/ChatAugmentPanels.tsx +73 -0
- package/src/components/CitationLedgerPanel.tsx +313 -0
- package/src/components/ComputeSandboxPanel.tsx +130 -0
- package/src/components/ConfigPanel.tsx +110 -0
- package/src/components/ControlPlanePage.tsx +195 -0
- package/src/components/CreativeTreeLifePage.tsx +234 -0
- package/src/components/CreativeTreeOfLifePanel.tsx +149 -0
- package/src/components/DebugTracePanel.tsx +137 -0
- package/src/components/DeepReasoningTrace.tsx +48 -0
- package/src/components/EntitySheetPanel.tsx +51 -0
- package/src/components/FailureModesPanel.tsx +104 -0
- package/src/components/GBSDashboard.tsx +239 -0
- package/src/components/GraphView.tsx +116 -0
- package/src/components/HUD.tsx +125 -0
- package/src/components/HypothesisPanel.tsx +67 -0
- package/src/components/InnovationGenomeEngine.tsx +792 -0
- package/src/components/InnovationPersonaGuide.tsx +348 -0
- package/src/components/InnovationPersonaPanel.tsx +289 -0
- package/src/components/LiveResourceHUD.tsx +109 -0
- package/src/components/LongWriterPanel.tsx +112 -0
- package/src/components/MainPipelineV10Bridge.tsx +72 -0
- package/src/components/MarkdownLite.tsx +63 -0
- package/src/components/MemoryInspector.tsx +38 -0
- package/src/components/MemoryMonitor.tsx +52 -0
- package/src/components/MemoryStressPanel.tsx +176 -0
- package/src/components/ModulesPage.tsx +171 -0
- package/src/components/PipelineDebugConsole.orig.tsx +1856 -0
- package/src/components/PipelineDebugConsole.tsx +3 -0
- package/src/components/PreFlightHUD.tsx +67 -0
- package/src/components/PrismaFetchTracePanel.tsx +87 -0
- package/src/components/ReportOSPanel.tsx +165 -0
- package/src/components/ResourceEstimatorPage.tsx +327 -0
- package/src/components/RichText.tsx +181 -0
- package/src/components/SagaOsPanel.tsx +605 -0
- package/src/components/SagaOsReference.tsx +421 -0
- package/src/components/SagaOsV2Panel.tsx +594 -0
- package/src/components/SagaStyleTab.tsx +382 -0
- package/src/components/SageBlueprintPanel.tsx +416 -0
- package/src/components/SharedChatInput.tsx +77 -0
- package/src/components/StatFinancePanel.tsx +190 -0
- package/src/components/StylePersonaPanel.tsx +128 -0
- package/src/components/TemplatesPage.tsx +300 -0
- package/src/components/TestPanel.tsx +63 -0
- package/src/components/TraceLog.tsx +89 -0
- package/src/components/V15CalibrationAugment.tsx +1134 -0
- package/src/components/V15CalibrationDialog.tsx +1871 -0
- package/src/components/V15Overlay.orig.tsx +120 -0
- package/src/components/V15Overlay.tsx +4 -0
- package/src/components/V15OverlayWrapper.tsx +362 -0
- package/src/components/V15Toggle.tsx +34 -0
- package/src/console/DiagnosticRecoveryPanel.tsx +358 -0
- package/src/console/EngineeringConsole.tsx +103 -0
- package/src/console/FictionSystemPanels.tsx +882 -0
- package/src/console/InspectorPanels.tsx +254 -0
- package/src/console/ManuscriptGraderPanel.tsx +182 -0
- package/src/console/RecursiveReviserPanel.tsx +245 -0
- package/src/console/SeedControlPanel.tsx +135 -0
- package/src/console/StoryControllerPanel.tsx +443 -0
- package/src/console/engineBridge.ts +258 -0
- package/src/console/gemini.ts +106 -0
- package/src/console/grading.ts +250 -0
- package/src/console/util.ts +45 -0
- package/src/fiction/continuity.ts +372 -0
- package/src/fiction/crash-protection.ts +111 -0
- package/src/fiction/diagnostics.ts +208 -0
- package/src/fiction/diff.ts +74 -0
- package/src/fiction/entity-state-machine.ts +214 -0
- package/src/fiction/nive-engine.ts +404 -0
- package/src/fiction/pipeline-selftest.ts +132 -0
- package/src/fiction/seed-control.ts +193 -0
- package/src/fiction/story-engine.ts +326 -0
- package/src/fiction/types.ts +68 -0
- package/src/flatten-guide.md +379 -0
- package/src/index.css +14 -0
- package/src/index.orig.css +13 -0
- package/src/lib/academic-sources.base.ts +188 -0
- package/src/lib/academic-sources.orig.ts +28 -0
- package/src/lib/academic-sources.ts +10 -0
- package/src/lib/advanced-math.ts +119 -0
- package/src/lib/adversarial-engine.base.ts +409 -0
- package/src/lib/adversarial-engine.ts +82 -0
- package/src/lib/ai-revision.ts +623 -0
- package/src/lib/app-state.tsx +426 -0
- package/src/lib/artifact-registry.ts +97 -0
- package/src/lib/artifacts.ts +180 -0
- package/src/lib/atlas-dr.ts +167 -0
- package/src/lib/browser-mtls.ts +127 -0
- package/src/lib/browser-queue.ts +221 -0
- package/src/lib/browser-search-scraper.base.ts +382 -0
- package/src/lib/browser-search-scraper.orig.ts +90 -0
- package/src/lib/browser-search-scraper.ts +10 -0
- package/src/lib/calc-interceptor.ts +82 -0
- package/src/lib/citation-lane-tap.ts +78 -0
- package/src/lib/citation-ledger-store.ts +369 -0
- package/src/lib/citation-ledger.ts +203 -0
- package/src/lib/compute-sandbox.ts +215 -0
- package/src/lib/compute.worker.ts +153 -0
- package/src/lib/connectors/gemini.ts +120 -0
- package/src/lib/connectors/jina.ts +233 -0
- package/src/lib/connectors/marketdata.ts +51 -0
- package/src/lib/connectors/prismafetch.base.ts +175 -0
- package/src/lib/connectors/prismafetch.ts +1 -0
- package/src/lib/connectors/serpapi.ts +65 -0
- package/src/lib/connectors/wikidata.ts +44 -0
- package/src/lib/constraints.ts +331 -0
- package/src/lib/continuation-detector.base.ts +153 -0
- package/src/lib/continuation-detector.ts +48 -0
- package/src/lib/contradraft.ts +168 -0
- package/src/lib/cors-proxy.ts +120 -0
- package/src/lib/coverage.ts +81 -0
- package/src/lib/debug/architecture-prescription.ts +556 -0
- package/src/lib/debug/covea-repair.ts +543 -0
- package/src/lib/debug/helios-ground.ts +319 -0
- package/src/lib/debug/intent-decomposer.ts +281 -0
- package/src/lib/debug/intent-lattice.ts +349 -0
- package/src/lib/debug/pipeline-diagnosis.ts +1149 -0
- package/src/lib/debug/pipeline-trace-bus.ts +424 -0
- package/src/lib/debug/prompt-forge.ts +678 -0
- package/src/lib/debug/repair-sites.ts +513 -0
- package/src/lib/debug/research-phase.ts +266 -0
- package/src/lib/debug/retrieval-context.ts +76 -0
- package/src/lib/debug/retrieval-hardener.ts +142 -0
- package/src/lib/debug/scraper-debug-runner.ts +576 -0
- package/src/lib/debug/scraper-forensics.ts +418 -0
- package/src/lib/debug/scraper-lane-roadmap.ts +136 -0
- package/src/lib/debug/self-test.ts +415 -0
- package/src/lib/debug/step-attribution.ts +211 -0
- package/src/lib/debug/template-rubric.ts +301 -0
- package/src/lib/debug/unified-innovation.ts +126 -0
- package/src/lib/debug/veritas-hybrid-scraper.ts +335 -0
- package/src/lib/defense-registry.ts +104 -0
- package/src/lib/defenses.ts +162 -0
- package/src/lib/deterministic-citation-ledger.ts +174 -0
- package/src/lib/elo-registry.base.ts +117 -0
- package/src/lib/elo-registry.ts +1 -0
- package/src/lib/entity-resolver.ts +291 -0
- package/src/lib/failure-modes.ts +267 -0
- package/src/lib/feature-registry.ts +69 -0
- package/src/lib/flaw-registry.ts +143 -0
- package/src/lib/flaws/_template.ts +52 -0
- package/src/lib/flaws/builtins.ts +63 -0
- package/src/lib/flaws/finance.ts +169 -0
- package/src/lib/flaws/fixers.ts +10 -0
- package/src/lib/flaws/index.ts +32 -0
- package/src/lib/flaws/legal.ts +157 -0
- package/src/lib/flaws/medical.ts +188 -0
- package/src/lib/flaws/original-defenses-pack.ts +81 -0
- package/src/lib/flaws/sample-declarative-pack.json +38 -0
- package/src/lib/flaws/selftest.ts +201 -0
- package/src/lib/flaws/software-extended.ts +125 -0
- package/src/lib/flaws/software-rn-webgl.ts +182 -0
- package/src/lib/flaws/statistics-advanced.ts +46 -0
- package/src/lib/flaws/statistics.ts +61 -0
- package/src/lib/gbse/config.ts +20 -0
- package/src/lib/gbse/engine.ts +226 -0
- package/src/lib/gbse/graph.ts +118 -0
- package/src/lib/gbse/graph.worker.ts +21 -0
- package/src/lib/gbse/tests.ts +117 -0
- package/src/lib/gbse/tiers.ts +65 -0
- package/src/lib/gbse/types.ts +94 -0
- package/src/lib/innovation-genome-engine-v2.orig.ts +1001 -0
- package/src/lib/innovation-genome-engine-v2.ts +3 -0
- package/src/lib/innovation-genome-engine.orig.ts +330 -0
- package/src/lib/innovation-genome-engine.ts +3 -0
- package/src/lib/innovation-genome-v10.orig.ts +314 -0
- package/src/lib/innovation-genome-v10.ts +2 -0
- package/src/lib/innovation-genome-v3.orig.ts +2015 -0
- package/src/lib/innovation-genome-v3.ts +2 -0
- package/src/lib/innovation-genome-v4.orig.ts +1959 -0
- package/src/lib/innovation-genome-v4.ts +2 -0
- package/src/lib/innovation-genome-v5.orig.ts +1210 -0
- package/src/lib/innovation-genome-v5.ts +2 -0
- package/src/lib/innovation-genome-v7.orig.ts +2549 -0
- package/src/lib/innovation-genome-v7.ts +2 -0
- package/src/lib/innovation-genome-v8.orig.ts +1485 -0
- package/src/lib/innovation-genome-v8.ts +2 -0
- package/src/lib/innovation-genome-v9.orig.ts +643 -0
- package/src/lib/innovation-genome-v9.ts +2 -0
- package/src/lib/jina.base.ts +293 -0
- package/src/lib/jina.ts +1 -0
- package/src/lib/live-telemetry.ts +61 -0
- package/src/lib/longwriter.ts +84 -0
- package/src/lib/manuscript-grade-v2.ts +298 -0
- package/src/lib/memory-governor.ts +173 -0
- package/src/lib/memory-stress-tests.ts +248 -0
- package/src/lib/model-intelligence.ts +48 -0
- package/src/lib/model-rotator.ts +75 -0
- package/src/lib/models.orig.ts +513 -0
- package/src/lib/models.ts +151 -0
- package/src/lib/n-deep.base.ts +592 -0
- package/src/lib/n-deep.ts +51 -0
- package/src/lib/nih-simulator.ts +56 -0
- package/src/lib/nih-vulnerability-fixes.ts +460 -0
- package/src/lib/omega-templates.base.ts +294 -0
- package/src/lib/omega-templates.ts +225 -0
- package/src/lib/omni-nexus.ts +64 -0
- package/src/lib/oracle-adapters.ts +67 -0
- package/src/lib/oracle-registry.ts +163 -0
- package/src/lib/orchestrator.ts +357 -0
- package/src/lib/output-boundary.ts +235 -0
- package/src/lib/overrides/vite-native-chaos-harness.ts +154 -0
- package/src/lib/overrides/vite-native-contract-plane.ts +245 -0
- package/src/lib/overrides/vite-native-doctor-plane.ts +208 -0
- package/src/lib/overrides/vite-native-knowledge-store.ts +267 -0
- package/src/lib/overrides/vite-native-policy-plane.ts +190 -0
- package/src/lib/overrides/vite-native-replay-plane.ts +197 -0
- package/src/lib/overrides/vite-native-runtime-plane.ts +106 -0
- package/src/lib/overrides/vite-native-scraper.ts +848 -0
- package/src/lib/overrides/vite-native-selftest-functional.ts +217 -0
- package/src/lib/overrides/vite-native-selftest.ts +183 -0
- package/src/lib/overrides/vite-native-snapshot-plane.ts +123 -0
- package/src/lib/philosophy-toolkit.ts +75 -0
- package/src/lib/pipeline.orig.ts +659 -0
- package/src/lib/pipeline.ts +42 -0
- package/src/lib/precache.ts +128 -0
- package/src/lib/py-sandbox.ts +205 -0
- package/src/lib/quality-score.ts +96 -0
- package/src/lib/quant-engine.ts +231 -0
- package/src/lib/quant-lib.ts +80 -0
- package/src/lib/reportos.ts +175 -0
- package/src/lib/research-os.ts +306 -0
- package/src/lib/resource-estimator.ts +114 -0
- package/src/lib/rpm-governor.ts +93 -0
- package/src/lib/runtime-estimator.ts +135 -0
- package/src/lib/sage/empty-space-v6.ts +560 -0
- package/src/lib/sage/empty-space-v7.ts +222 -0
- package/src/lib/sage/empty-space.ts +733 -0
- package/src/lib/sage/engine.ts +786 -0
- package/src/lib/sage/index.ts +17 -0
- package/src/lib/sage/judge.ts +246 -0
- package/src/lib/sage/prng.ts +53 -0
- package/src/lib/sage/reality-grounding.ts +380 -0
- package/src/lib/sage/repetition.ts +151 -0
- package/src/lib/sage/saga-os-v2-engines.ts +1870 -0
- package/src/lib/sage/saga-os-v2.ts +274 -0
- package/src/lib/sage/saga-os-v3-core.ts +1491 -0
- package/src/lib/sage/saga-os-v3-release.ts +739 -0
- package/src/lib/sage/saga-os-v4-aureate.ts +1161 -0
- package/src/lib/sage/saga-os-v4.ts +212 -0
- package/src/lib/sage/saga-os-v5.ts +205 -0
- package/src/lib/sage/saga-os-v6.ts +346 -0
- package/src/lib/sage/saga-os-v7.ts +314 -0
- package/src/lib/sage/saga-os-v8.ts +505 -0
- package/src/lib/sage/saga-os.ts +329 -0
- package/src/lib/sage/taxonomy.ts +403 -0
- package/src/lib/sage/unified-roll.ts +524 -0
- package/src/lib/sage/worked-sketches.ts +44 -0
- package/src/lib/sage.ts +166 -0
- package/src/lib/scraper-debug-bus.ts +53 -0
- package/src/lib/scraper-enhanced.orig.ts +153 -0
- package/src/lib/scraper-enhanced.ts +10 -0
- package/src/lib/scraper-hardener.base.orig.ts +155 -0
- package/src/lib/scraper-hardener.base.ts +317 -0
- package/src/lib/scraper-hardener.ts +1 -0
- package/src/lib/scraper-palisade/palisade-adjudicator.orig.ts +419 -0
- package/src/lib/scraper-palisade/palisade-adjudicator.ts +13 -0
- package/src/lib/scraper-vnext/arbiter-omega.orig.ts +688 -0
- package/src/lib/scraper-vnext/arbiter-omega.ts +13 -0
- package/src/lib/scraper-vnext/canonical-portfolio-augments.ts +479 -0
- package/src/lib/scraper-vnext/canonical-portfolio-orchestrator.orig.ts +1529 -0
- package/src/lib/scraper-vnext/canonical-portfolio-orchestrator.ts +13 -0
- package/src/lib/scraper-vnext/conclave-omega.ts +1830 -0
- package/src/lib/scraper-vnext/content-extractor-v2.ts +226 -0
- package/src/lib/scraper-vnext/diagnostics-suite.ts +36 -0
- package/src/lib/scraper-vnext/epistemic-packer.ts +97 -0
- package/src/lib/scraper-vnext/fusion-v2.ts +65 -0
- package/src/lib/scraper-vnext/hydra-reader.orig.ts +1216 -0
- package/src/lib/scraper-vnext/hydra-reader.ts +13 -0
- package/src/lib/scraper-vnext/native-scraper-browser-vnext.orig.ts +91 -0
- package/src/lib/scraper-vnext/native-scraper-browser-vnext.ts +13 -0
- package/src/lib/scraper-vnext/nexus-consensus.orig.ts +905 -0
- package/src/lib/scraper-vnext/nexus-consensus.ts +13 -0
- package/src/lib/scraper-vnext/portfolio-consensus-adjudicator.ts +804 -0
- package/src/lib/scraper-vnext/portfolio-consensus-memory.ts +377 -0
- package/src/lib/scraper-vnext/portfolio-terminal-governor.ts +548 -0
- package/src/lib/scraper-vnext/query-strategist.orig.ts +224 -0
- package/src/lib/scraper-vnext/query-strategist.ts +423 -0
- package/src/lib/scraper-vnext/retrieval-accelerator.ts +708 -0
- package/src/lib/scraper-vnext/retrieval-audit-augments.ts +477 -0
- package/src/lib/scraper-vnext/retrieval-control-plane.ts +904 -0
- package/src/lib/scraper-vnext/retrieval-policy-augments.ts +358 -0
- package/src/lib/scraper-vnext/safe-fetch-v2.ts +157 -0
- package/src/lib/scraper-vnext/sentinel-omega.ts +56 -0
- package/src/lib/scraper-vnext/sentinel-orchestrator.ts +69 -0
- package/src/lib/scraper-vnext/sibyl-oracle.orig.ts +413 -0
- package/src/lib/scraper-vnext/sibyl-oracle.ts +13 -0
- package/src/lib/scraper-vnext/smart-read-v2.ts +55 -0
- package/src/lib/scraper-vnext/spa-rescue-bridge.ts +608 -0
- package/src/lib/scraper-vnext/strata-engine.orig.ts +2666 -0
- package/src/lib/scraper-vnext/strata-engine.ts +13 -0
- package/src/lib/scraper-vnext/structured-source-adapter.orig.ts +369 -0
- package/src/lib/scraper-vnext/structured-source-adapter.ts +34 -0
- package/src/lib/scraper-vnext/terminal-complete.ts +224 -0
- package/src/lib/scraper-vnext/terminal-final.ts +277 -0
- package/src/lib/scraper-vnext/terminal-saturation.ts +345 -0
- package/src/lib/scraper-vnext/terminal-wire.ts +425 -0
- package/src/lib/scraper-vnext/vanguard-titanium.orig.ts +467 -0
- package/src/lib/scraper-vnext/vanguard-titanium.ts +17 -0
- package/src/lib/search-cache.ts +138 -0
- package/src/lib/sloop-runner.base.ts +223 -0
- package/src/lib/sloop-runner.ts +104 -0
- package/src/lib/sloop.ts +114 -0
- package/src/lib/small-model-adapters.ts +82 -0
- package/src/lib/sscp.ts +86 -0
- package/src/lib/system-map.ts +54 -0
- package/src/lib/uni-node.ts +86 -0
- package/src/lib/universal-rigor-guard.ts +433 -0
- package/src/lib/v15-gate-testbed.ts +274 -0
- package/src/lib/v15-gemini.base.ts +89 -0
- package/src/lib/v15-gemini.ts +1 -0
- package/src/lib/v15-grounding.orig.ts +241 -0
- package/src/lib/v15-grounding.ts +79 -0
- package/src/lib/v15-pipeline.base.ts +769 -0
- package/src/lib/v15-pipeline.orig.ts +1154 -0
- package/src/lib/v15-pipeline.ts +674 -0
- package/src/lib/v15-questions.ts +64 -0
- package/src/lib/v15-rate-limiter.orig.ts +91 -0
- package/src/lib/v15-rate-limiter.ts +48 -0
- package/src/lib/v15-state.base.ts +87 -0
- package/src/lib/v15-state.ts +28 -0
- package/src/lib/visual-table-generator.tsx +207 -0
- package/src/lib/wasm-runtime.ts +133 -0
- package/src/lib/williams-persona-guide.ts +265 -0
- package/src/lib/williams-style.base.ts +464 -0
- package/src/lib/williams-style.ts +59 -0
- package/src/lib/worker-pool.ts +96 -0
- package/src/lib/writing-tiers.ts +125 -0
- package/src/main.orig.tsx +10 -0
- package/src/main.tsx +10 -0
- package/src/utils/cn.orig.ts +6 -0
- package/src/utils/cn.ts +6 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +31 -0
- package/unify.mjs +537 -0
- package/vite.config.ts +18 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* portfolio-consensus-memory.ts
|
|
3
|
+
* ============================================================================
|
|
4
|
+
* ADDITIVE persistence layer over portfolio-consensus-adjudicator.ts.
|
|
5
|
+
* Stores advisory lane reliability by CanonicalLaneId and family-pair
|
|
6
|
+
* corroboration by sorted architectural family pair. No fabricated URLs.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
ENGINE_FAMILY,
|
|
11
|
+
familyOf,
|
|
12
|
+
groundWithPortfolioConsensus,
|
|
13
|
+
type CanonicalLaneId,
|
|
14
|
+
type ConsensusConfidence,
|
|
15
|
+
type LaneConsensus,
|
|
16
|
+
type PortfolioConsensusOptions,
|
|
17
|
+
type PortfolioConsensusResult,
|
|
18
|
+
} from "./portfolio-consensus-adjudicator";
|
|
19
|
+
|
|
20
|
+
const DB_NAME = "portfolio-consensus-memory-v1";
|
|
21
|
+
const DB_VERSION = 1;
|
|
22
|
+
const STORE_LANE = "lane-reliability";
|
|
23
|
+
const STORE_PAIR = "family-corroboration";
|
|
24
|
+
|
|
25
|
+
interface LaneReliabilityRecord {
|
|
26
|
+
laneId: CanonicalLaneId;
|
|
27
|
+
wins: number;
|
|
28
|
+
fulfilledNonWins: number;
|
|
29
|
+
failures: number;
|
|
30
|
+
totalElapsedMs: number;
|
|
31
|
+
lastSeenAt: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface FamilyPairRecord {
|
|
35
|
+
pairKey: string;
|
|
36
|
+
corroborationCount: number;
|
|
37
|
+
observationCount: number;
|
|
38
|
+
lastSeenAt: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let dbPromise: Promise<IDBDatabase | null> | null = null;
|
|
42
|
+
|
|
43
|
+
function openDb(): Promise<IDBDatabase | null> {
|
|
44
|
+
if (dbPromise) return dbPromise;
|
|
45
|
+
dbPromise = new Promise((resolve) => {
|
|
46
|
+
if (typeof indexedDB === "undefined") {
|
|
47
|
+
resolve(null);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const req = indexedDB.open(DB_NAME, DB_VERSION);
|
|
52
|
+
req.onupgradeneeded = () => {
|
|
53
|
+
const db = req.result;
|
|
54
|
+
if (!db.objectStoreNames.contains(STORE_LANE)) {
|
|
55
|
+
db.createObjectStore(STORE_LANE, { keyPath: "laneId" });
|
|
56
|
+
}
|
|
57
|
+
if (!db.objectStoreNames.contains(STORE_PAIR)) {
|
|
58
|
+
db.createObjectStore(STORE_PAIR, { keyPath: "pairKey" });
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
req.onsuccess = () => resolve(req.result);
|
|
62
|
+
req.onerror = () => resolve(null);
|
|
63
|
+
req.onblocked = () => resolve(null);
|
|
64
|
+
} catch {
|
|
65
|
+
resolve(null);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return dbPromise;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function idbGet<T>(store: string, key: string): Promise<T | null> {
|
|
72
|
+
const db = await openDb();
|
|
73
|
+
if (!db) return null;
|
|
74
|
+
return new Promise((resolve) => {
|
|
75
|
+
try {
|
|
76
|
+
const req = db.transaction(store, "readonly").objectStore(store).get(key);
|
|
77
|
+
req.onsuccess = () => resolve((req.result as T) ?? null);
|
|
78
|
+
req.onerror = () => resolve(null);
|
|
79
|
+
} catch {
|
|
80
|
+
resolve(null);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function idbPut(store: string, value: unknown): Promise<void> {
|
|
86
|
+
const db = await openDb();
|
|
87
|
+
if (!db) return;
|
|
88
|
+
return new Promise((resolve) => {
|
|
89
|
+
try {
|
|
90
|
+
const req = db.transaction(store, "readwrite").objectStore(store).put(value);
|
|
91
|
+
req.onsuccess = () => resolve();
|
|
92
|
+
req.onerror = () => resolve();
|
|
93
|
+
} catch {
|
|
94
|
+
resolve();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function idbGetAll<T>(store: string): Promise<T[]> {
|
|
100
|
+
const db = await openDb();
|
|
101
|
+
if (!db) return [];
|
|
102
|
+
return new Promise((resolve) => {
|
|
103
|
+
try {
|
|
104
|
+
const req = db.transaction(store, "readonly").objectStore(store).getAll();
|
|
105
|
+
req.onsuccess = () => resolve((req.result as T[]) ?? []);
|
|
106
|
+
req.onerror = () => resolve([]);
|
|
107
|
+
} catch {
|
|
108
|
+
resolve([]);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function sortedPairKey(a: string, b: string): string {
|
|
114
|
+
return [a, b].sort().join("↔");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function recencyDecay(lastSeenAt: number, halfLifeDays = 14): number {
|
|
118
|
+
const ageDays = Math.max(0, (Date.now() - lastSeenAt) / 86_400_000);
|
|
119
|
+
return Math.exp((-Math.LN2 / halfLifeDays) * ageDays);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface LaneReliability {
|
|
123
|
+
laneId: CanonicalLaneId;
|
|
124
|
+
winRate: number;
|
|
125
|
+
meanElapsedMs: number;
|
|
126
|
+
sampleCount: number;
|
|
127
|
+
recencyWeightedWinRate: number;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface FamilyCorroborationPrior {
|
|
131
|
+
familyA: string;
|
|
132
|
+
familyB: string;
|
|
133
|
+
corroborationRate: number;
|
|
134
|
+
sampleCount: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface PortfolioMemorySnapshot {
|
|
138
|
+
laneReliability: LaneReliability[];
|
|
139
|
+
familyPriors: FamilyCorroborationPrior[];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export async function getLaneReliability(laneId: CanonicalLaneId): Promise<LaneReliability> {
|
|
143
|
+
const rec = await idbGet<LaneReliabilityRecord>(STORE_LANE, laneId);
|
|
144
|
+
if (!rec) {
|
|
145
|
+
return { laneId, winRate: 0, meanElapsedMs: 0, sampleCount: 0, recencyWeightedWinRate: 0 };
|
|
146
|
+
}
|
|
147
|
+
const total = rec.wins + rec.fulfilledNonWins + rec.failures;
|
|
148
|
+
const winRate = total > 0 ? rec.wins / total : 0;
|
|
149
|
+
const fulfilled = rec.wins + rec.fulfilledNonWins;
|
|
150
|
+
const meanElapsedMs = fulfilled > 0 ? rec.totalElapsedMs / fulfilled : 0;
|
|
151
|
+
return {
|
|
152
|
+
laneId,
|
|
153
|
+
winRate,
|
|
154
|
+
meanElapsedMs,
|
|
155
|
+
sampleCount: total,
|
|
156
|
+
recencyWeightedWinRate: winRate * recencyDecay(rec.lastSeenAt),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export async function getFamilyCorroborationPrior(familyA: string, familyB: string): Promise<FamilyCorroborationPrior> {
|
|
161
|
+
const pairKey = sortedPairKey(familyA, familyB);
|
|
162
|
+
const rec = await idbGet<FamilyPairRecord>(STORE_PAIR, pairKey);
|
|
163
|
+
if (!rec || rec.observationCount === 0) return { familyA, familyB, corroborationRate: 0, sampleCount: 0 };
|
|
164
|
+
return {
|
|
165
|
+
familyA,
|
|
166
|
+
familyB,
|
|
167
|
+
corroborationRate: rec.corroborationCount / rec.observationCount,
|
|
168
|
+
sampleCount: rec.observationCount,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export async function getPortfolioMemorySnapshot(laneIds: CanonicalLaneId[]): Promise<PortfolioMemorySnapshot> {
|
|
173
|
+
const laneReliability = await Promise.all(laneIds.map((id) => getLaneReliability(id)));
|
|
174
|
+
const pairRecords = await idbGetAll<FamilyPairRecord>(STORE_PAIR);
|
|
175
|
+
const familyPriors = pairRecords.map((rec) => {
|
|
176
|
+
const [familyA, familyB] = rec.pairKey.split("↔");
|
|
177
|
+
return {
|
|
178
|
+
familyA,
|
|
179
|
+
familyB,
|
|
180
|
+
corroborationRate: rec.observationCount > 0 ? rec.corroborationCount / rec.observationCount : 0,
|
|
181
|
+
sampleCount: rec.observationCount,
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
return { laneReliability, familyPriors };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function recordLaneOutcome(laneId: CanonicalLaneId, outcome: "win" | "fulfilled-non-win" | "failure", elapsedMs: number): Promise<void> {
|
|
188
|
+
const existing = (await idbGet<LaneReliabilityRecord>(STORE_LANE, laneId)) ?? {
|
|
189
|
+
laneId,
|
|
190
|
+
wins: 0,
|
|
191
|
+
fulfilledNonWins: 0,
|
|
192
|
+
failures: 0,
|
|
193
|
+
totalElapsedMs: 0,
|
|
194
|
+
lastSeenAt: 0,
|
|
195
|
+
};
|
|
196
|
+
if (outcome === "win") {
|
|
197
|
+
existing.wins += 1;
|
|
198
|
+
existing.totalElapsedMs += Math.max(0, elapsedMs);
|
|
199
|
+
} else if (outcome === "fulfilled-non-win") {
|
|
200
|
+
existing.fulfilledNonWins += 1;
|
|
201
|
+
existing.totalElapsedMs += Math.max(0, elapsedMs);
|
|
202
|
+
} else {
|
|
203
|
+
existing.failures += 1;
|
|
204
|
+
}
|
|
205
|
+
existing.lastSeenAt = Date.now();
|
|
206
|
+
await idbPut(STORE_LANE, existing);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async function recordFamilyPairObservation(familyA: string, familyB: string, corroborated: boolean): Promise<void> {
|
|
210
|
+
if (familyA === familyB) return;
|
|
211
|
+
const pairKey = sortedPairKey(familyA, familyB);
|
|
212
|
+
const existing = (await idbGet<FamilyPairRecord>(STORE_PAIR, pairKey)) ?? {
|
|
213
|
+
pairKey,
|
|
214
|
+
corroborationCount: 0,
|
|
215
|
+
observationCount: 0,
|
|
216
|
+
lastSeenAt: 0,
|
|
217
|
+
};
|
|
218
|
+
existing.observationCount += 1;
|
|
219
|
+
if (corroborated) existing.corroborationCount += 1;
|
|
220
|
+
existing.lastSeenAt = Date.now();
|
|
221
|
+
await idbPut(STORE_PAIR, existing);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async function recordPortfolioOutcome(result: PortfolioConsensusResult): Promise<void> {
|
|
225
|
+
for (const lane of result.laneResults) {
|
|
226
|
+
const isWinner = lane.id === result.winnerLane;
|
|
227
|
+
if (lane.status === "fulfilled") {
|
|
228
|
+
await recordLaneOutcome(lane.id, isWinner ? "win" : "fulfilled-non-win", lane.elapsedMs);
|
|
229
|
+
} else {
|
|
230
|
+
await recordLaneOutcome(lane.id, "failure", lane.elapsedMs);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
for (let i = 0; i < result.laneConsensus.length; i += 1) {
|
|
235
|
+
for (let j = i + 1; j < result.laneConsensus.length; j += 1) {
|
|
236
|
+
const a = result.laneConsensus[i];
|
|
237
|
+
const b = result.laneConsensus[j];
|
|
238
|
+
if (a.family === b.family) continue;
|
|
239
|
+
const corroborated = a.independentFamilies.includes(b.family) || b.independentFamilies.includes(a.family);
|
|
240
|
+
await recordFamilyPairObservation(a.family, b.family, corroborated);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface AdaptivePortfolioOptions extends PortfolioConsensusOptions {
|
|
246
|
+
adaptivePruning?: boolean;
|
|
247
|
+
pruneMinSamples?: number;
|
|
248
|
+
minEnabledLanes?: number;
|
|
249
|
+
recordOutcome?: boolean;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const ALL_LANE_IDS = Object.keys(ENGINE_FAMILY) as CanonicalLaneId[];
|
|
253
|
+
|
|
254
|
+
export async function groundWithAdaptivePortfolioConsensus(
|
|
255
|
+
question: string,
|
|
256
|
+
options: AdaptivePortfolioOptions = {},
|
|
257
|
+
): Promise<PortfolioConsensusResult & { prunedLanes: CanonicalLaneId[]; memorySnapshot: PortfolioMemorySnapshot }> {
|
|
258
|
+
const recordOutcome = options.recordOutcome !== false;
|
|
259
|
+
const minEnabled = Math.max(2, Math.floor(options.minEnabledLanes ?? 2));
|
|
260
|
+
const minSamples = Math.max(1, Math.floor(options.pruneMinSamples ?? 5));
|
|
261
|
+
let effectiveOptions: PortfolioConsensusOptions = options;
|
|
262
|
+
const prunedLanes: CanonicalLaneId[] = [];
|
|
263
|
+
|
|
264
|
+
if (options.adaptivePruning === true) {
|
|
265
|
+
const requestedIds = ALL_LANE_IDS.filter((id) => options.enableLanes?.[id] !== false);
|
|
266
|
+
const reliabilities = await Promise.all(requestedIds.map((id) => getLaneReliability(id)));
|
|
267
|
+
const provenFailures = reliabilities.filter(
|
|
268
|
+
(r) => r.laneId !== "terminal-wire" && r.sampleCount >= minSamples && r.winRate === 0,
|
|
269
|
+
);
|
|
270
|
+
const enableLanes: Partial<Record<CanonicalLaneId, boolean>> = { ...(options.enableLanes ?? {}) };
|
|
271
|
+
let survivingCount = requestedIds.length;
|
|
272
|
+
for (const bad of provenFailures) {
|
|
273
|
+
if (survivingCount <= minEnabled) break;
|
|
274
|
+
enableLanes[bad.laneId] = false;
|
|
275
|
+
prunedLanes.push(bad.laneId);
|
|
276
|
+
survivingCount -= 1;
|
|
277
|
+
}
|
|
278
|
+
effectiveOptions = { ...options, enableLanes };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const result = await groundWithPortfolioConsensus(question, effectiveOptions);
|
|
282
|
+
if (recordOutcome) await recordPortfolioOutcome(result);
|
|
283
|
+
const memorySnapshot = await getPortfolioMemorySnapshot(ALL_LANE_IDS);
|
|
284
|
+
return { ...result, prunedLanes, memorySnapshot };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export async function runPortfolioConsensusMemoryDiagnostics(): Promise<{
|
|
288
|
+
ok: boolean;
|
|
289
|
+
checks: Array<{ id: string; passed: boolean; detail: string }>;
|
|
290
|
+
}> {
|
|
291
|
+
const checks: Array<{ id: string; passed: boolean; detail: string }> = [];
|
|
292
|
+
const add = (id: string, passed: boolean, detail: string) => checks.push({ id, passed, detail });
|
|
293
|
+
|
|
294
|
+
const probeLaneId = "sentinel-omega" as CanonicalLaneId;
|
|
295
|
+
await recordLaneOutcome(probeLaneId, "win", 500);
|
|
296
|
+
await recordLaneOutcome(probeLaneId, "fulfilled-non-win", 700);
|
|
297
|
+
await recordLaneOutcome(probeLaneId, "failure", 0);
|
|
298
|
+
const rel = await getLaneReliability(probeLaneId);
|
|
299
|
+
add("lane-reliability-samples", rel.sampleCount >= 3, `sampleCount=${rel.sampleCount}`);
|
|
300
|
+
add("lane-reliability-winrate", rel.winRate > 0 && rel.winRate < 1, `winRate=${rel.winRate.toFixed(4)}`);
|
|
301
|
+
|
|
302
|
+
const unseen = await getLaneReliability(`unseen-${Date.now()}` as CanonicalLaneId);
|
|
303
|
+
add("lane-reliability-unseen-zero", unseen.sampleCount === 0 && unseen.winRate === 0, "zero for unseen lane");
|
|
304
|
+
|
|
305
|
+
await recordFamilyPairObservation("omega-standalone", "omni-standalone", true);
|
|
306
|
+
await recordFamilyPairObservation("omni-standalone", "omega-standalone", false);
|
|
307
|
+
const prior = await getFamilyCorroborationPrior("omega-standalone", "omni-standalone");
|
|
308
|
+
add("family-pair-symmetric-key", prior.sampleCount >= 2, `samples=${prior.sampleCount} rate=${prior.corroborationRate}`);
|
|
309
|
+
|
|
310
|
+
await recordFamilyPairObservation("conclave-core", "conclave-core", true);
|
|
311
|
+
const sameFamilyPrior = await getFamilyCorroborationPrior("conclave-core", "conclave-core");
|
|
312
|
+
add("family-pair-rejects-same-family", sameFamilyPrior.sampleCount === 0, `samples=${sameFamilyPrior.sampleCount}`);
|
|
313
|
+
|
|
314
|
+
const fakeResult: PortfolioConsensusResult = {
|
|
315
|
+
ok: true,
|
|
316
|
+
provider: "test",
|
|
317
|
+
selection: "canonical",
|
|
318
|
+
winnerLane: "terminal-wire",
|
|
319
|
+
canonicalWinnerLane: "terminal-wire",
|
|
320
|
+
consensusWinnerLane: "terminal-wire",
|
|
321
|
+
count: 1,
|
|
322
|
+
sources: [],
|
|
323
|
+
evidenceBlock: "x".repeat(200),
|
|
324
|
+
consensusConfidence: "moderate" as ConsensusConfidence,
|
|
325
|
+
consensusCaveat: "",
|
|
326
|
+
laneConsensus: [
|
|
327
|
+
{
|
|
328
|
+
laneId: "terminal-wire" as CanonicalLaneId,
|
|
329
|
+
family: familyOf("terminal-wire"),
|
|
330
|
+
acceptable: true,
|
|
331
|
+
blockMeanJaccard: 0,
|
|
332
|
+
blockCorroborators: [],
|
|
333
|
+
independentFamilies: ["omni-standalone"],
|
|
334
|
+
independentCorroborationCount: 1,
|
|
335
|
+
augmentedQuality: [],
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
laneId: "omni-nexus" as CanonicalLaneId,
|
|
339
|
+
family: familyOf("omni-nexus"),
|
|
340
|
+
acceptable: true,
|
|
341
|
+
blockMeanJaccard: 0,
|
|
342
|
+
blockCorroborators: [],
|
|
343
|
+
independentFamilies: ["conclave-core"],
|
|
344
|
+
independentCorroborationCount: 1,
|
|
345
|
+
augmentedQuality: [],
|
|
346
|
+
},
|
|
347
|
+
] as LaneConsensus[],
|
|
348
|
+
claimCorroboration: [],
|
|
349
|
+
decisionLedger: [],
|
|
350
|
+
agreement: [],
|
|
351
|
+
laneResults: [
|
|
352
|
+
{ id: "terminal-wire" as CanonicalLaneId, priority: 100, status: "fulfilled", elapsedMs: 300 },
|
|
353
|
+
{ id: "omni-nexus" as CanonicalLaneId, priority: 60, status: "fulfilled", elapsedMs: 400 },
|
|
354
|
+
] as any,
|
|
355
|
+
};
|
|
356
|
+
await recordPortfolioOutcome(fakeResult);
|
|
357
|
+
const twRel = await getLaneReliability("terminal-wire" as CanonicalLaneId);
|
|
358
|
+
add("record-outcome-winner-recorded", twRel.sampleCount >= 1 && twRel.winRate > 0, `winRate=${twRel.winRate.toFixed(3)}`);
|
|
359
|
+
|
|
360
|
+
const adversarialLanes: CanonicalLaneId[] = ["sentinel-orchestrator", "vanguard-packer", "sentinel-omega", "omni-nexus"];
|
|
361
|
+
for (const id of adversarialLanes) for (let i = 0; i < 6; i += 1) await recordLaneOutcome(id, "failure", 0);
|
|
362
|
+
const requested = ["terminal-wire", ...adversarialLanes] as CanonicalLaneId[];
|
|
363
|
+
const rels = await Promise.all(requested.map((id) => getLaneReliability(id)));
|
|
364
|
+
const failingCount = rels.filter((r) => r.laneId !== "terminal-wire" && r.sampleCount >= 5 && r.winRate === 0).length;
|
|
365
|
+
const wouldPrune = Math.min(failingCount, requested.length - 2);
|
|
366
|
+
add("adaptive-prune-bounded", wouldPrune <= adversarialLanes.length && requested.length - wouldPrune >= 2, `wouldPrune=${wouldPrune}`);
|
|
367
|
+
add("adaptive-prune-never-drops-terminal-wire", true, "terminal-wire excluded from prune filter");
|
|
368
|
+
add("sorted-pair-key-order-independent", sortedPairKey("a", "b") === sortedPairKey("b", "a"), sortedPairKey("a", "b"));
|
|
369
|
+
add("recency-decay-fresh", Math.abs(recencyDecay(Date.now()) - 1) < 0.01, `fresh=${recencyDecay(Date.now()).toFixed(4)}`);
|
|
370
|
+
add("recency-decay-old-approaches-zero", recencyDecay(Date.now() - 365 * 86_400_000) < 0.01, `old=${recencyDecay(Date.now() - 365 * 86_400_000).toFixed(6)}`);
|
|
371
|
+
const snapshot = await getPortfolioMemorySnapshot(["terminal-wire", `never-queried-${Date.now()}` as CanonicalLaneId]);
|
|
372
|
+
add("snapshot-covers-all-requested", snapshot.laneReliability.length === 2, `n=${snapshot.laneReliability.length}`);
|
|
373
|
+
|
|
374
|
+
return { ok: checks.every((c) => c.passed), checks };
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export { groundWithPortfolioConsensus, familyOf, ENGINE_FAMILY };
|