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,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Stress Tests — deterministic in-browser workloads that mimic the
|
|
3
|
+
* heaviest research configurations (SLOOP + N-Deep + Cluster) and verify
|
|
4
|
+
* the memory governor keeps the heap within budget.
|
|
5
|
+
*
|
|
6
|
+
* No network calls. Pure in-browser allocation simulations that mirror the
|
|
7
|
+
* actual peak memory patterns of each pipeline phase, using the governor's
|
|
8
|
+
* own safe-cap helpers and draft caps to predict whether the user's chosen
|
|
9
|
+
* configuration will OOM on their device BEFORE they launch a heavy query.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
readMemoryReport,
|
|
14
|
+
safeClusterWidth,
|
|
15
|
+
safeNDeepPasses,
|
|
16
|
+
safeSloopPages,
|
|
17
|
+
safeDraftCharCap,
|
|
18
|
+
settleHeap,
|
|
19
|
+
type MemoryReport,
|
|
20
|
+
} from "./memory-governor";
|
|
21
|
+
|
|
22
|
+
// ─── Legacy minimal API (back-compat with existing MemoryStressPanel) ─────────
|
|
23
|
+
export interface StressResult {
|
|
24
|
+
passed: boolean;
|
|
25
|
+
peakMB: number;
|
|
26
|
+
durationMs: number;
|
|
27
|
+
notes: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ─── New advanced API (R2 patch integration) ─────────────────────────────────
|
|
31
|
+
export interface StressTestStep {
|
|
32
|
+
name: string;
|
|
33
|
+
ok: boolean;
|
|
34
|
+
details: string;
|
|
35
|
+
pressureBefore: number;
|
|
36
|
+
pressureAfter: number;
|
|
37
|
+
ms: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface StressTestReport {
|
|
41
|
+
config: {
|
|
42
|
+
sloopPages: number;
|
|
43
|
+
sloopSections: number;
|
|
44
|
+
clusterWidth: number;
|
|
45
|
+
nDeepPasses: number;
|
|
46
|
+
draftCharsPerSection: number;
|
|
47
|
+
};
|
|
48
|
+
steps: StressTestStep[];
|
|
49
|
+
startReport: MemoryReport;
|
|
50
|
+
endReport: MemoryReport;
|
|
51
|
+
passed: boolean;
|
|
52
|
+
peakMB: number;
|
|
53
|
+
durationMs: number;
|
|
54
|
+
recommendedConfig?: {
|
|
55
|
+
sloopPages: number;
|
|
56
|
+
clusterWidth: number;
|
|
57
|
+
nDeepPasses: number;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function repeat(s: string, n: number): string {
|
|
62
|
+
// Array.join is O(n) — avoids quadratic string concatenation.
|
|
63
|
+
return new Array(n + 1).join(s);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function timed<T>(fn: () => Promise<T> | T): Promise<{ value: T; ms: number }> {
|
|
67
|
+
const t0 = performance.now();
|
|
68
|
+
const value = await fn();
|
|
69
|
+
return { value, ms: performance.now() - t0 };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function pressure(): number {
|
|
73
|
+
return readMemoryReport().pressure;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Synthetic workload that mimics SLOOP section generation. */
|
|
77
|
+
function sloopSectionAlloc(chars: number): { digest: string; alloc: number } {
|
|
78
|
+
const block = repeat("LOREM IPSUM DOLOR SIT AMET CONSECTETUR ", Math.max(1, Math.ceil(chars / 40)));
|
|
79
|
+
const text = block.slice(0, chars);
|
|
80
|
+
const digest = text.slice(0, 240);
|
|
81
|
+
return { digest, alloc: text.length };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Synthetic workload that mimics N-Deep redraft memory pattern. */
|
|
85
|
+
function nDeepRedraftAlloc(chars: number): string {
|
|
86
|
+
const a = repeat("X", chars);
|
|
87
|
+
const b = repeat("Y", chars);
|
|
88
|
+
const c = repeat("Z", Math.min(safeDraftCharCap(), Math.round(chars * 1.05)));
|
|
89
|
+
void a.length; void b.length;
|
|
90
|
+
return c;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Synthetic workload that mimics a cluster wave: N parallel payloads. */
|
|
94
|
+
async function clusterWaveAlloc(width: number, payloadChars: number): Promise<number> {
|
|
95
|
+
const promises = new Array(width).fill(0).map((_v, i) =>
|
|
96
|
+
Promise.resolve(repeat(String.fromCharCode(65 + (i % 26)), payloadChars))
|
|
97
|
+
);
|
|
98
|
+
const arr = await Promise.all(promises);
|
|
99
|
+
const total = arr.reduce((sum, s) => sum + s.length, 0);
|
|
100
|
+
return total;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Advanced stress test — separates SLOOP, Cluster, and N-Deep phases with
|
|
105
|
+
* per-step pressure tracking and recommends a safe configuration on failure.
|
|
106
|
+
*/
|
|
107
|
+
export async function runStressTestAdvanced(opts: {
|
|
108
|
+
sloopPages: number;
|
|
109
|
+
clusterWidth: number;
|
|
110
|
+
nDeepPasses: number;
|
|
111
|
+
draftCharsPerSection?: number;
|
|
112
|
+
}): Promise<StressTestReport> {
|
|
113
|
+
const startReport = readMemoryReport();
|
|
114
|
+
const start = Date.now();
|
|
115
|
+
const sloopSections = Math.max(4, opts.sloopPages * 2);
|
|
116
|
+
const draftCharsPerSection = Math.min(
|
|
117
|
+
opts.draftCharsPerSection ?? 18_000,
|
|
118
|
+
safeDraftCharCap(),
|
|
119
|
+
);
|
|
120
|
+
const steps: StressTestStep[] = [];
|
|
121
|
+
let peakMB = startReport.usedMB;
|
|
122
|
+
|
|
123
|
+
// Step 1 — SLOOP synthetic section pass
|
|
124
|
+
{
|
|
125
|
+
const before = pressure();
|
|
126
|
+
const t = await timed(async () => {
|
|
127
|
+
let totalAlloc = 0;
|
|
128
|
+
const digests: string[] = [];
|
|
129
|
+
for (let i = 0; i < sloopSections; i++) {
|
|
130
|
+
const { digest, alloc } = sloopSectionAlloc(draftCharsPerSection);
|
|
131
|
+
digests.push(digest);
|
|
132
|
+
totalAlloc += alloc;
|
|
133
|
+
const r = readMemoryReport();
|
|
134
|
+
if (r.usedMB > peakMB) peakMB = r.usedMB;
|
|
135
|
+
await new Promise(r => setTimeout(r, 0));
|
|
136
|
+
}
|
|
137
|
+
return { digests, totalAlloc };
|
|
138
|
+
});
|
|
139
|
+
const after = pressure();
|
|
140
|
+
steps.push({
|
|
141
|
+
name: `SLOOP synthetic ${sloopSections} sections @ ${Math.round(draftCharsPerSection / 1024)}KB`,
|
|
142
|
+
ok: after < 0.92,
|
|
143
|
+
details: `Allocated ${(t.value.totalAlloc / 1048576).toFixed(1)} MB total; held ${t.value.digests.length} digests`,
|
|
144
|
+
pressureBefore: before,
|
|
145
|
+
pressureAfter: after,
|
|
146
|
+
ms: t.ms,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
await settleHeap(20);
|
|
150
|
+
|
|
151
|
+
// Step 2 — Cluster wave parallelism
|
|
152
|
+
{
|
|
153
|
+
const before = pressure();
|
|
154
|
+
const safeWidth = safeClusterWidth(opts.clusterWidth, readMemoryReport());
|
|
155
|
+
const t = await timed(() => clusterWaveAlloc(safeWidth, 12_000));
|
|
156
|
+
const after = pressure();
|
|
157
|
+
const r = readMemoryReport();
|
|
158
|
+
if (r.usedMB > peakMB) peakMB = r.usedMB;
|
|
159
|
+
steps.push({
|
|
160
|
+
name: `Cluster wave width=${opts.clusterWidth} (governor capped to ${safeWidth})`,
|
|
161
|
+
ok: after < 0.92,
|
|
162
|
+
details: `Total parallel payload ${(t.value / 1048576).toFixed(1)} MB`,
|
|
163
|
+
pressureBefore: before,
|
|
164
|
+
pressureAfter: after,
|
|
165
|
+
ms: t.ms,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
await settleHeap(20);
|
|
169
|
+
|
|
170
|
+
// Step 3 — N-Deep redraft loop
|
|
171
|
+
{
|
|
172
|
+
const before = pressure();
|
|
173
|
+
const safePasses = safeNDeepPasses(opts.nDeepPasses, draftCharsPerSection * sloopSections, readMemoryReport());
|
|
174
|
+
const t = await timed(async () => {
|
|
175
|
+
let current = repeat("S", Math.min(safeDraftCharCap(), draftCharsPerSection * 2));
|
|
176
|
+
for (let p = 0; p < safePasses; p++) {
|
|
177
|
+
current = nDeepRedraftAlloc(current.length);
|
|
178
|
+
const r = readMemoryReport();
|
|
179
|
+
if (r.usedMB > peakMB) peakMB = r.usedMB;
|
|
180
|
+
await new Promise(r => setTimeout(r, 0));
|
|
181
|
+
}
|
|
182
|
+
return current.length;
|
|
183
|
+
});
|
|
184
|
+
const after = pressure();
|
|
185
|
+
steps.push({
|
|
186
|
+
name: `N-Deep redraft passes requested=${opts.nDeepPasses} (governor capped to ${safePasses})`,
|
|
187
|
+
ok: after < 0.95,
|
|
188
|
+
details: `Final working draft chars ${t.value}`,
|
|
189
|
+
pressureBefore: before,
|
|
190
|
+
pressureAfter: after,
|
|
191
|
+
ms: t.ms,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const endReport = readMemoryReport();
|
|
196
|
+
const passed = steps.every(s => s.ok) && endReport.pressure < 0.92;
|
|
197
|
+
const durationMs = Date.now() - start;
|
|
198
|
+
|
|
199
|
+
let recommendedConfig: StressTestReport["recommendedConfig"] | undefined;
|
|
200
|
+
if (!passed) {
|
|
201
|
+
recommendedConfig = {
|
|
202
|
+
sloopPages: safeSloopPages(opts.sloopPages, endReport),
|
|
203
|
+
clusterWidth: safeClusterWidth(opts.clusterWidth, endReport),
|
|
204
|
+
nDeepPasses: safeNDeepPasses(opts.nDeepPasses, draftCharsPerSection * sloopSections, endReport),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
config: {
|
|
210
|
+
sloopPages: opts.sloopPages,
|
|
211
|
+
sloopSections,
|
|
212
|
+
clusterWidth: opts.clusterWidth,
|
|
213
|
+
nDeepPasses: opts.nDeepPasses,
|
|
214
|
+
draftCharsPerSection,
|
|
215
|
+
},
|
|
216
|
+
steps,
|
|
217
|
+
startReport,
|
|
218
|
+
endReport,
|
|
219
|
+
passed,
|
|
220
|
+
peakMB,
|
|
221
|
+
durationMs,
|
|
222
|
+
recommendedConfig,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Legacy entry point — returns minimal StressResult shape for existing callers. */
|
|
227
|
+
export async function runMemoryStressTest(opts: {
|
|
228
|
+
pages: number;
|
|
229
|
+
passes: number;
|
|
230
|
+
cluster: number;
|
|
231
|
+
onProgress?: (msg: string) => void;
|
|
232
|
+
}): Promise<StressResult> {
|
|
233
|
+
opts.onProgress?.(`start: pages=${opts.pages} passes=${opts.passes} cluster=${opts.cluster}`);
|
|
234
|
+
const report = await runStressTestAdvanced({
|
|
235
|
+
sloopPages: opts.pages,
|
|
236
|
+
clusterWidth: opts.cluster,
|
|
237
|
+
nDeepPasses: opts.passes,
|
|
238
|
+
});
|
|
239
|
+
for (const s of report.steps) {
|
|
240
|
+
opts.onProgress?.(`${s.name}: ${s.ok ? "OK" : "FAIL"} (${s.pressureBefore.toFixed(2)} → ${s.pressureAfter.toFixed(2)})`);
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
passed: report.passed,
|
|
244
|
+
peakMB: report.peakMB,
|
|
245
|
+
durationMs: report.durationMs,
|
|
246
|
+
notes: report.steps.map(s => `${s.name}: ${s.ok ? "ok" : "warn"}`),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model intelligence ratings — Arena.ai / LMSys Arena-aligned Elo-style scores.
|
|
3
|
+
* Higher = stronger. Used for tie-breaking in N-Deep accept/reject judge:
|
|
4
|
+
* when the judge cannot confidently decide between the critic's revision and
|
|
5
|
+
* the original text, the text produced by the *stronger* author model wins.
|
|
6
|
+
*
|
|
7
|
+
* Scores are normalized to the 0..100 band and reflect Arena leaderboard
|
|
8
|
+
* rankings as of early 2026. They are deliberately approximate (±3 pts) and
|
|
9
|
+
* used only as a deterministic ordering signal — never as an absolute quality
|
|
10
|
+
* claim.
|
|
11
|
+
*/
|
|
12
|
+
import type { ModelId } from "./models";
|
|
13
|
+
|
|
14
|
+
export const MODEL_INTELLIGENCE: Record<ModelId, number> = {
|
|
15
|
+
// Gemini frontier
|
|
16
|
+
"gemini-3.5-flash": 92,
|
|
17
|
+
"gemini-3-flash-preview": 90,
|
|
18
|
+
"gemini-2.5-pro": 94,
|
|
19
|
+
"gemini-2.5-flash": 88,
|
|
20
|
+
"gemini-3.1-flash-lite": 82,
|
|
21
|
+
"gemini-2.5-flash-lite": 78,
|
|
22
|
+
// Gemma open weights
|
|
23
|
+
"gemma-4-31b-it": 80,
|
|
24
|
+
"gemma-4-26b-it": 76,
|
|
25
|
+
"gemma-3-27b-it": 74,
|
|
26
|
+
// Claude
|
|
27
|
+
"claude-3-7-sonnet-latest": 93,
|
|
28
|
+
"claude-3-5-sonnet-latest": 89,
|
|
29
|
+
"claude-3-5-haiku-latest": 80,
|
|
30
|
+
// Grok
|
|
31
|
+
"grok-2-latest": 86,
|
|
32
|
+
// DeepSeek
|
|
33
|
+
"deepseek-reasoner": 91,
|
|
34
|
+
"deepseek-chat": 85,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export function intelligenceOf(model: ModelId | string): number {
|
|
38
|
+
return (MODEL_INTELLIGENCE as Record<string, number>)[model] ?? 70;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Compare two model IDs. Returns a (intelligence > b ? 1 : a === b ? 0 : -1). */
|
|
42
|
+
export function compareIntelligence(a: ModelId | string, b: ModelId | string): number {
|
|
43
|
+
const ai = intelligenceOf(a);
|
|
44
|
+
const bi = intelligenceOf(b);
|
|
45
|
+
if (ai > bi) return 1;
|
|
46
|
+
if (ai < bi) return -1;
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { geminiGenerate, type GenerateResult } from "./v15-gemini";
|
|
2
|
+
import { GEMINI_ELO_ROSTER, getModelEloInfo, type ModelEloRating } from "./elo-registry";
|
|
3
|
+
import { tryAcquire, recordResult, snapshotUsage } from "./v15-rate-limiter";
|
|
4
|
+
import { getAllowedModels } from "./v15-state";
|
|
5
|
+
|
|
6
|
+
export const ROTATION_POOL = [...GEMINI_ELO_ROSTER];
|
|
7
|
+
|
|
8
|
+
export function getActiveRotationPool(): string[] {
|
|
9
|
+
try {
|
|
10
|
+
const allowed = getAllowedModels();
|
|
11
|
+
const filtered = allowed?.length ? GEMINI_ELO_ROSTER.filter(m => allowed.includes(m)) : [];
|
|
12
|
+
return filtered.length ? filtered : ROTATION_POOL;
|
|
13
|
+
} catch { return ROTATION_POOL; }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RotationAttempt { model: string; elo: number; tier?: string; ok: boolean; latencyMs: number; error?: string }
|
|
17
|
+
export interface RotatedGenerateResult extends GenerateResult { modelUsed: string; eloInfo: ModelEloRating; attempts: RotationAttempt[] }
|
|
18
|
+
|
|
19
|
+
const usedThisRound = new Set<string>();
|
|
20
|
+
function shuffle<T>(xs: T[]): T[] { const out = [...xs]; for (let i = out.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [out[i], out[j]] = [out[j], out[i]]; } return out; }
|
|
21
|
+
|
|
22
|
+
function roundRobinOrder(pool: string[], preferred?: string) {
|
|
23
|
+
if (usedThisRound.size >= pool.length) usedThisRound.clear();
|
|
24
|
+
const unused = pool.filter(m => !usedThisRound.has(m));
|
|
25
|
+
const used = pool.filter(m => usedThisRound.has(m));
|
|
26
|
+
if (preferred && unused.includes(preferred)) return [preferred, ...shuffle(unused.filter(m => m !== preferred)), ...shuffle(used)];
|
|
27
|
+
return [...shuffle(unused), ...shuffle(used)];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function generateWithRotation(opts: { apiKey: string; prompt: string; systemInstruction?: string; preferredModel?: string; maxOutputTokens?: number; pool?: string[] }): Promise<RotatedGenerateResult> {
|
|
31
|
+
const pool = opts.pool ?? getActiveRotationPool();
|
|
32
|
+
const order = roundRobinOrder(pool, opts.preferredModel);
|
|
33
|
+
const attempts: RotationAttempt[] = [];
|
|
34
|
+
const webHint = "\n\nIf this model has native web-search/tool grounding available, use it to verify time-sensitive factual claims; otherwise rely only on provided evidence and state uncertainty.";
|
|
35
|
+
for (const model of order) {
|
|
36
|
+
const eloInfo = getModelEloInfo(model);
|
|
37
|
+
const acquired = await tryAcquire(model, true);
|
|
38
|
+
if (!acquired) {
|
|
39
|
+
const s = snapshotUsage(model);
|
|
40
|
+
attempts.push({ model, elo: eloInfo.elo, tier: eloInfo.tier, ok: false, latencyMs: 0, error: `rate-limit skip (RPM ${s.rpmUsed}/${s.rpmMax}, RPD ${s.rpdUsed}/${s.rpdMax})` });
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const res = await geminiGenerate({ apiKey: opts.apiKey, model, prompt: opts.prompt + webHint, systemInstruction: opts.systemInstruction, maxOutputTokens: opts.maxOutputTokens });
|
|
44
|
+
recordResult(model, res.ok);
|
|
45
|
+
attempts.push({ model, elo: eloInfo.elo, tier: eloInfo.tier, ok: res.ok, latencyMs: res.latencyMs, error: res.error });
|
|
46
|
+
if (res.ok && res.text.trim()) { usedThisRound.add(model); return { ...res, modelUsed: model, eloInfo, attempts }; }
|
|
47
|
+
await new Promise(r => setTimeout(r, 150));
|
|
48
|
+
}
|
|
49
|
+
const fallback = order[0] ?? "gemini-3.5-flash";
|
|
50
|
+
return { text: "", ok: false, error: `All models failed (${attempts.map(a => `${a.model}: ${a.error}`).join("; ")})`, latencyMs: attempts.reduce((a, b) => a + b.latencyMs, 0), modelUsed: fallback, eloInfo: getModelEloInfo(fallback), attempts };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface JudgeResult { model: string; score: number; note?: string }
|
|
54
|
+
export interface ParallelJudgeResult { judgments: JudgeResult[]; attempts: RotationAttempt[] }
|
|
55
|
+
|
|
56
|
+
export async function parallelJudgeRotation(opts: { apiKey: string; question: string; answer: string; judgeModels?: string[] }): Promise<ParallelJudgeResult> {
|
|
57
|
+
const models = opts.judgeModels ?? getActiveRotationPool();
|
|
58
|
+
const attempts: RotationAttempt[] = [];
|
|
59
|
+
const judgments: JudgeResult[] = [];
|
|
60
|
+
await Promise.all(models.map(async model => {
|
|
61
|
+
const prompt = `Score the answer 0-10. Penalize truncation, prompt leakage, hallucinated citations, missing scope, and missing computations. Return JSON only: {"score": number, "note": "short rationale"}\n\nQUESTION:\n${opts.question}\n\nANSWER:\n${opts.answer.slice(0, 8000)}`;
|
|
62
|
+
const res = await generateWithRotation({ apiKey: opts.apiKey, prompt, preferredModel: model, pool: [model], maxOutputTokens: 350 });
|
|
63
|
+
attempts.push(...res.attempts);
|
|
64
|
+
if (!res.ok) return;
|
|
65
|
+
try {
|
|
66
|
+
const m = res.text.match(/\{[\s\S]*\}/);
|
|
67
|
+
const j = JSON.parse(m ? m[0] : res.text);
|
|
68
|
+
judgments.push({ model: res.modelUsed, score: Math.max(0, Math.min(10, Number(j.score) || 0)), note: String(j.note ?? "") });
|
|
69
|
+
} catch {
|
|
70
|
+
const truncated = /\b(to|the|of|is|and|a|an)\s*$/i.test(opts.answer.trim()) || opts.answer.trim().length < 160;
|
|
71
|
+
judgments.push({ model: res.modelUsed, score: truncated ? 1 : 7, note: "Deterministic judge fallback; model JSON was malformed." });
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
return { judgments, attempts };
|
|
75
|
+
}
|