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,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SAGA OS Studio — canonical system map (NEW, additive, durable).
|
|
3
|
+
* Every entry is tiered by how it actually participates in fiction generation:
|
|
4
|
+
* automatic (runs every chapter without user action), conditional (runs when
|
|
5
|
+
* its trigger fires), manual-tool (user-invoked from a panel), new (added by
|
|
6
|
+
* the transparency/grade/revision work and additive-only).
|
|
7
|
+
*/
|
|
8
|
+
export type SystemTier = "automatic" | "conditional" | "manual-tool" | "new";
|
|
9
|
+
|
|
10
|
+
export const SYSTEM_TIER_LABEL: Record<SystemTier, string> = {
|
|
11
|
+
automatic: "AUTOMATIC — every chapter",
|
|
12
|
+
conditional: "CONDITIONAL — on trigger",
|
|
13
|
+
"manual-tool": "MANUAL TOOL — user-invoked",
|
|
14
|
+
new: "NEW — additive",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const SYSTEM_TIER_TONE: Record<SystemTier, string> = {
|
|
18
|
+
automatic: "teal",
|
|
19
|
+
conditional: "sky",
|
|
20
|
+
"manual-tool": "amber",
|
|
21
|
+
new: "violet",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export interface SystemEntry {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
tier: SystemTier;
|
|
28
|
+
description: string;
|
|
29
|
+
wiredVia: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const SAGA_SYSTEM_MAP: SystemEntry[] = [
|
|
33
|
+
{ id: "sage-blueprint", name: "SAGE blueprint", tier: "automatic", description: "Premise / theme / POV / macro-structure / chapter outline compiler.", wiredVia: "rollSage() — sage/engine.ts" },
|
|
34
|
+
{ id: "saga-v1", name: "SAGA-OS v1 directive", tier: "automatic", description: "Throughline, pacing and promise-discipline directive block.", wiredVia: "saga-os.ts directive compiler" },
|
|
35
|
+
{ id: "saga-v2", name: "SAGA-OS v2 engines", tier: "automatic", description: "Slot-class engines: cast, place, promise, plant/payoff tracking.", wiredVia: "saga-os-v2-engines.ts" },
|
|
36
|
+
{ id: "saga-v3", name: "SAGA-OS v3 pipeline", tier: "automatic", description: "Unified chapter prompt assembly: directive + persona + contract.", wiredVia: "saga-os-v3-core.ts / v3-release.ts" },
|
|
37
|
+
{ id: "saga-v4", name: "SAGA-OS v4 aureate", tier: "automatic", description: "Aureate style + reality-level layer fused into the chapter contract.", wiredVia: "saga-os-v4-aureate.ts" },
|
|
38
|
+
{ id: "saga-v5v8", name: "SAGA-OS v5–v8 layers", tier: "conditional", description: "Successive refinements (release, continuity, canon) applied when their gates pass.", wiredVia: "saga-os-v5..v8.ts" },
|
|
39
|
+
{ id: "unified-roll", name: "Unified roll", tier: "automatic", description: "Merges archetype + genre + scale into one contribution ledger per roll.", wiredVia: "unifiedRoll() — sage/unified-roll.ts" },
|
|
40
|
+
{ id: "reality", name: "Reality grounding", tier: "automatic", description: "Reality-level constraints compiled into the prompt; post-generation audits.", wiredVia: "reality-grounding.ts + getRealityAudits()" },
|
|
41
|
+
{ id: "style-judge", name: "Style judge (Kallos)", tier: "conditional", description: "Post-write style audit against the persona contract.", wiredVia: "sage/judge.ts + getStyleAudits()" },
|
|
42
|
+
{ id: "repetition", name: "Repetition guard", tier: "automatic", description: "Echo / repeated-phrase suppression compiled into the contract.", wiredVia: "sage/repetition.ts" },
|
|
43
|
+
{ id: "empty-space", name: "Empty-space engine", tier: "automatic", description: "Negative-space discipline: what is deliberately left unsaid.", wiredVia: "sage/empty-space(-v6/-v7).ts" },
|
|
44
|
+
{ id: "genome", name: "Innovation genome", tier: "conditional", description: "Novelty / discovery diagnostics feeding persona and tree panels.", wiredVia: "innovation-genome-v3..v10 + engine" },
|
|
45
|
+
{ id: "persona", name: "Williams persona", tier: "automatic", description: "Archetype voice directive prepended to every chapter call.", wiredVia: "getPersonaDirective() — williams-style.ts" },
|
|
46
|
+
{ id: "templates", name: "Omega templates", tier: "conditional", description: "Style-override + authoritative output contracts when a template is active.", wiredVia: "omega-templates.ts" },
|
|
47
|
+
{ id: "longwriter", name: "Longwriter tiers", tier: "conditional", description: "Chapter tiering for long-form coherence across the book.", wiredVia: "longwriter.ts / writing-tiers.ts" },
|
|
48
|
+
{ id: "ndeep", name: "n-Deep passes", tier: "conditional", description: "Multi-pass convergence loop when enabled in settings.", wiredVia: "n-deep.ts" },
|
|
49
|
+
{ id: "sloop", name: "SLOOP runner", tier: "conditional", description: "Paged long-output runner for book-scale synthesis.", wiredVia: "sloop-runner.ts" },
|
|
50
|
+
{ id: "legacy-grade", name: "Legacy grade (1–10)", tier: "manual-tool", description: "In-panel 12-category manuscript judge; untouched by grade v2.", wiredVia: "sage/judge.ts gradeManuscript()" },
|
|
51
|
+
{ id: "fiction-input", name: "Fiction Input ledger", tier: "new", description: "Byte-exact per-chapter prompts tapped at the model-call boundary.", wiredVia: "getModelCallLog() tag=fiction-chapter" },
|
|
52
|
+
{ id: "grade-v2", name: "Manuscript Grade v2", tier: "new", description: "Standalone weighted 100-point rubric + diagnostics + quote-grounded rewrites.", wiredVia: "manuscript-grade-v2.ts gradeManuscriptV2()" },
|
|
53
|
+
{ id: "revision-v2", name: "Recursive Revision v2", tier: "new", description: "Target-score minimal-diff loop with fresh model + fresh context per step.", wiredVia: "ai-revision.ts runRecursiveRevisionLoop()" },
|
|
54
|
+
];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UniNode Local Orchestrator (Browser-Side Sidecar)
|
|
3
|
+
* Implements the Hub/Worker orchestration logic in TypeScript.
|
|
4
|
+
* Provides mDNS-style discovery via BroadcastChannel and Task Dispatch via Web Workers.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface NodeInfo {
|
|
8
|
+
nodeId: string;
|
|
9
|
+
role: "hub" | "worker" | "hybrid";
|
|
10
|
+
capabilities: string[];
|
|
11
|
+
load: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface TaskRequest {
|
|
15
|
+
taskId: string;
|
|
16
|
+
toolName: string;
|
|
17
|
+
inputJson: string;
|
|
18
|
+
timeoutMs: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface TaskResponse {
|
|
22
|
+
taskId: string;
|
|
23
|
+
resultJson?: any;
|
|
24
|
+
errorMessage?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class UniNode {
|
|
28
|
+
private nodeId: string = crypto.randomUUID();
|
|
29
|
+
private role: "hub" | "worker" | "hybrid";
|
|
30
|
+
private discoveryChannel = new BroadcastChannel("uninode_discovery");
|
|
31
|
+
private taskChannel = new BroadcastChannel("uninode_tasks");
|
|
32
|
+
private peers = new Map<string, NodeInfo>();
|
|
33
|
+
|
|
34
|
+
constructor(role: "hub" | "worker" | "hybrid" = "hybrid") {
|
|
35
|
+
this.role = role;
|
|
36
|
+
this.initDiscovery();
|
|
37
|
+
this.initTaskHandling();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private initDiscovery() {
|
|
41
|
+
this.discoveryChannel.onmessage = (e) => {
|
|
42
|
+
const { type, node } = e.data;
|
|
43
|
+
if (type === "HEARTBEAT") {
|
|
44
|
+
this.peers.set(node.nodeId, node);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Heartbeat loop
|
|
49
|
+
setInterval(() => {
|
|
50
|
+
this.discoveryChannel.postMessage({
|
|
51
|
+
type: "HEARTBEAT",
|
|
52
|
+
node: {
|
|
53
|
+
nodeId: this.nodeId,
|
|
54
|
+
role: this.role,
|
|
55
|
+
capabilities: ["web_search", "quant_engine", "logic_gate"],
|
|
56
|
+
load: 0, // In real env, track worker pool load
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}, 5000);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private initTaskHandling() {
|
|
63
|
+
this.taskChannel.onmessage = async (e) => {
|
|
64
|
+
const { type, request, targetNodeId } = e.data;
|
|
65
|
+
if (type === "DISPATCH" && (targetNodeId === this.nodeId || this.role !== "hub")) {
|
|
66
|
+
// Execute task (delegate to WorkerPool)
|
|
67
|
+
console.log(`[UniNode] Executing task ${request.taskId}: ${request.toolName}`);
|
|
68
|
+
// Result would be posted back via response channel
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public getPeers(): NodeInfo[] {
|
|
74
|
+
return Array.from(this.peers.values());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public getIdentity() {
|
|
78
|
+
return { nodeId: this.nodeId, role: this.role };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let nodeInstance: UniNode | null = null;
|
|
83
|
+
export function getUniNode() {
|
|
84
|
+
if (!nodeInstance) nodeInstance = new UniNode();
|
|
85
|
+
return nodeInstance;
|
|
86
|
+
}
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal Rigor Guard V14 — Terminal Canonical
|
|
3
|
+
* - Registry-backed flaw scanner (delegates to pluggable flaws/ system)
|
|
4
|
+
* - Deterministic Auto-Fix loop (per-pass + final post-loop pass)
|
|
5
|
+
* - Multi-agent refinement loop (Draft → Critique → Editor) with early exit
|
|
6
|
+
* - Remediation hints injected into critique + editor prompts
|
|
7
|
+
* - Stable promotion after final auto-fix rescue
|
|
8
|
+
* - Balanced-brace JSON extraction for judge replies
|
|
9
|
+
* - Parallel Blind Judge Ensemble with optional cross-model rotation
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { GenerateParams, ModelId } from "./models";
|
|
13
|
+
import { generateSynthesizedResponse } from "./models";
|
|
14
|
+
import type { ComputeRecord } from "./compute-sandbox";
|
|
15
|
+
import type { ExtractedConstraints } from "./constraints";
|
|
16
|
+
import { throttle } from "./rpm-governor";
|
|
17
|
+
import { runFlawScan, runAutoFix, type ScanContext, type ScanSource } from "./flaw-registry";
|
|
18
|
+
import { ensureFlawsLoaded } from "./flaws";
|
|
19
|
+
|
|
20
|
+
// ─── TYPES ─────────────────────────────────────────────────────────────────
|
|
21
|
+
export interface GuardIssue {
|
|
22
|
+
severity: "info" | "warning" | "major" | "critical";
|
|
23
|
+
code: string;
|
|
24
|
+
message: string;
|
|
25
|
+
remediation?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface GuardScore {
|
|
29
|
+
errorDetectionScore: number;
|
|
30
|
+
mathRigorScore: number;
|
|
31
|
+
writingStyleScore: number;
|
|
32
|
+
hallucinationScore: number;
|
|
33
|
+
combinedScore: number;
|
|
34
|
+
shortNote: string;
|
|
35
|
+
issues: GuardIssue[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface JudgeEnsembleResult {
|
|
39
|
+
median: number;
|
|
40
|
+
min: number;
|
|
41
|
+
max: number;
|
|
42
|
+
spread?: number;
|
|
43
|
+
scores: number[];
|
|
44
|
+
notes: string[];
|
|
45
|
+
calls: number;
|
|
46
|
+
available: boolean;
|
|
47
|
+
verificationDetails?: any[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface UniversalRigorResult {
|
|
51
|
+
finalText: string;
|
|
52
|
+
guardScore: GuardScore;
|
|
53
|
+
judgeResult: JudgeEnsembleResult;
|
|
54
|
+
passes: number;
|
|
55
|
+
stable: boolean;
|
|
56
|
+
autoFixesApplied: string[];
|
|
57
|
+
debugLog: any[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ─── HELPERS ───────────────────────────────────────────────────────────────
|
|
61
|
+
function clamp(n: number, lo: number, hi: number): number {
|
|
62
|
+
if (!Number.isFinite(n)) return lo;
|
|
63
|
+
return Math.max(lo, Math.min(hi, n));
|
|
64
|
+
}
|
|
65
|
+
function round(n: number, digits = 3): number {
|
|
66
|
+
const p = 10 ** digits;
|
|
67
|
+
return Math.round(n * p) / p;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Balanced-brace JSON object extractor; prefers candidates with `requiredKey`. */
|
|
71
|
+
function parseBestJsonObject(raw: string, requiredKey?: string): any {
|
|
72
|
+
// Prefer a fenced block first
|
|
73
|
+
const fenced = raw.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
74
|
+
const src = fenced ? fenced[1] : raw;
|
|
75
|
+
|
|
76
|
+
const candidates: string[] = [];
|
|
77
|
+
let depth = 0, start = -1, inStr = false, esc = false;
|
|
78
|
+
for (let i = 0; i < src.length; i++) {
|
|
79
|
+
const ch = src[i];
|
|
80
|
+
if (inStr) {
|
|
81
|
+
if (esc) esc = false;
|
|
82
|
+
else if (ch === "\\") esc = true;
|
|
83
|
+
else if (ch === '"') inStr = false;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (ch === '"') { inStr = true; continue; }
|
|
87
|
+
if (ch === "{") { if (depth === 0) start = i; depth++; }
|
|
88
|
+
else if (ch === "}") {
|
|
89
|
+
depth--;
|
|
90
|
+
if (depth === 0 && start !== -1) { candidates.push(src.slice(start, i + 1)); start = -1; }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const ordered = requiredKey
|
|
94
|
+
? [...candidates].reverse().sort((a, b) =>
|
|
95
|
+
Number(b.includes(`"${requiredKey}"`)) - Number(a.includes(`"${requiredKey}"`)))
|
|
96
|
+
: candidates;
|
|
97
|
+
for (const c of ordered) { try { return JSON.parse(c); } catch { /* try next */ } }
|
|
98
|
+
return {};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function buildRemediationBlock(issues: GuardIssue[]): string {
|
|
102
|
+
const seen = new Set<string>();
|
|
103
|
+
const hints: string[] = [];
|
|
104
|
+
for (const i of issues) {
|
|
105
|
+
if (!i.remediation || seen.has(i.remediation)) continue;
|
|
106
|
+
seen.add(i.remediation);
|
|
107
|
+
hints.push(`- [${i.code}] ${i.remediation}`);
|
|
108
|
+
if (hints.length >= 10) break;
|
|
109
|
+
}
|
|
110
|
+
return hints.length > 0
|
|
111
|
+
? `\n\nREMEDIATION HINTS (apply where appropriate; preserve correct content):\n${hints.join("\n")}`
|
|
112
|
+
: "";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function stripMetaDiscourse(text: string): string {
|
|
116
|
+
let s = text;
|
|
117
|
+
s = s.replace(/###\s*Deterministic Audit Overlay[\s\S]*?(?=\n###|\n---|$)/gi, "");
|
|
118
|
+
s = s.replace(/based on the provided data/gi, "");
|
|
119
|
+
return s.trim();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ─── FLAW SCAN (delegates to registry) ─────────────────────────────────────
|
|
123
|
+
export function scanUniversalFlaws(
|
|
124
|
+
prompt: string,
|
|
125
|
+
answer: string,
|
|
126
|
+
computeRecords: ComputeRecord[],
|
|
127
|
+
constraints: ExtractedConstraints,
|
|
128
|
+
sources?: ScanSource[],
|
|
129
|
+
extra?: { anchorDateISO?: string; domainTags?: string[]; templateId?: string },
|
|
130
|
+
): GuardIssue[] {
|
|
131
|
+
ensureFlawsLoaded();
|
|
132
|
+
const ctx: ScanContext = {
|
|
133
|
+
prompt, answer, lowerAnswer: answer.toLowerCase(),
|
|
134
|
+
computeRecords, constraints,
|
|
135
|
+
sources,
|
|
136
|
+
anchorDateISO: extra?.anchorDateISO,
|
|
137
|
+
domainTags: extra?.domainTags,
|
|
138
|
+
templateId: extra?.templateId,
|
|
139
|
+
};
|
|
140
|
+
return runFlawScan(ctx).map((i) => {
|
|
141
|
+
const out: GuardIssue = { severity: i.severity, code: i.code, message: i.message };
|
|
142
|
+
if (i.remediation) out.remediation = i.remediation;
|
|
143
|
+
return out;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ─── OVERLAY ──────────────────────────────────────────────────────────────
|
|
148
|
+
export function generateUniversalOverlay(
|
|
149
|
+
computeRecords: ComputeRecord[],
|
|
150
|
+
constraints: ExtractedConstraints,
|
|
151
|
+
): string {
|
|
152
|
+
let overlay = `\n\n---\n\n### Deterministic Audit Overlay (Universal)\n`;
|
|
153
|
+
if (constraints.timeHorizon || constraints.explicitComparisonTargets.length > 0) {
|
|
154
|
+
overlay += `**Active Constraints:**\n`;
|
|
155
|
+
if (constraints.timeHorizon) overlay += `- Horizon: ${constraints.timeHorizon.days} days\n`;
|
|
156
|
+
if (constraints.explicitComparisonTargets.length > 0)
|
|
157
|
+
overlay += `- Targets: ${constraints.explicitComparisonTargets.join(", ")}\n`;
|
|
158
|
+
}
|
|
159
|
+
if (computeRecords.length > 0) {
|
|
160
|
+
overlay += `\n**Computed Ground Truth (MUST MATCH EXACTLY):**\n`;
|
|
161
|
+
for (const rec of computeRecords) {
|
|
162
|
+
if (rec.ok && rec.result) overlay += `- ${rec.label} [${rec.formula}]: ${JSON.stringify(rec.result)}\n`;
|
|
163
|
+
else overlay += `- ${rec.label}: FAILED (${rec.error})\n`;
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
overlay += `\n**Computed Ground Truth:** None required/generated.\n`;
|
|
167
|
+
}
|
|
168
|
+
return overlay;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ─── SCORING ──────────────────────────────────────────────────────────────
|
|
172
|
+
export function scoreUniversalGuard(
|
|
173
|
+
prompt: string, answer: string,
|
|
174
|
+
computeRecords: ComputeRecord[], constraints: ExtractedConstraints,
|
|
175
|
+
sources?: ScanSource[],
|
|
176
|
+
extra?: { anchorDateISO?: string; domainTags?: string[]; templateId?: string },
|
|
177
|
+
): GuardScore {
|
|
178
|
+
const issues = scanUniversalFlaws(prompt, answer, computeRecords, constraints, sources, extra);
|
|
179
|
+
|
|
180
|
+
let err = 10, math = 10, style = 9.5, hall = 0;
|
|
181
|
+
for (const issue of issues) {
|
|
182
|
+
if (issue.severity === "critical") { err -= 2.5; math -= 2.0; hall += 2.5; }
|
|
183
|
+
else if (issue.severity === "major") { err -= 1.2; math -= 1.5; hall += 1.2; }
|
|
184
|
+
else if (issue.severity === "warning") { err -= 0.4; math -= 0.4; hall += 0.4; }
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const wordCount = answer.split(/\s+/).filter(Boolean).length;
|
|
188
|
+
if (wordCount < 40) {
|
|
189
|
+
style -= 1.5;
|
|
190
|
+
issues.push({ severity: "warning", code: "LOW_INFORMATION_DENSITY", message: "Answer lacks contextual depth." });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
err = clamp(err, 0, 10); math = clamp(math, 0, 10); style = clamp(style, 0, 10); hall = clamp(hall, 0, 10);
|
|
194
|
+
const combinedScore = round(0.40 * err + 0.30 * math + 0.20 * style + 0.10 * (10 - hall), 2);
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
errorDetectionScore: round(err, 2),
|
|
198
|
+
mathRigorScore: round(math, 2),
|
|
199
|
+
writingStyleScore: round(style, 2),
|
|
200
|
+
hallucinationScore: round(hall, 2),
|
|
201
|
+
combinedScore,
|
|
202
|
+
shortNote: `Score: ${combinedScore}/10 | Issues: ${issues.length ? issues.map(i => `${i.code}(${i.severity})`).join(", ") : "none"}`,
|
|
203
|
+
issues,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// ─── MULTI-AGENT REFINEMENT PIPELINE ──────────────────────────────────────
|
|
208
|
+
export async function executeUniversalRigorPipeline(opts: {
|
|
209
|
+
initialDraft: string;
|
|
210
|
+
userQuery: string;
|
|
211
|
+
baseParams: GenerateParams;
|
|
212
|
+
computeRecords: ComputeRecord[];
|
|
213
|
+
constraints: ExtractedConstraints;
|
|
214
|
+
rpm?: number;
|
|
215
|
+
maxDepth?: number;
|
|
216
|
+
sources?: ScanSource[];
|
|
217
|
+
anchorDateISO?: string;
|
|
218
|
+
domainTags?: string[];
|
|
219
|
+
templateId?: string;
|
|
220
|
+
judgeModels?: ModelId[];
|
|
221
|
+
onDebug?: (msg: string) => void;
|
|
222
|
+
}): Promise<UniversalRigorResult> {
|
|
223
|
+
const maxDepth = clamp(opts.maxDepth ?? 3, 1, 5);
|
|
224
|
+
const debugLog: any[] = [];
|
|
225
|
+
let currentDraft = opts.initialDraft;
|
|
226
|
+
let stable = false;
|
|
227
|
+
let finalScore: GuardScore | null = null;
|
|
228
|
+
let actualDepth = 0;
|
|
229
|
+
const allAutoFixes: string[] = [];
|
|
230
|
+
|
|
231
|
+
const scanExtra = {
|
|
232
|
+
anchorDateISO: opts.anchorDateISO,
|
|
233
|
+
domainTags: opts.domainTags,
|
|
234
|
+
templateId: opts.templateId,
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const buildAutoFixCtx = (ans: string): ScanContext => ({
|
|
238
|
+
prompt: opts.userQuery,
|
|
239
|
+
answer: ans,
|
|
240
|
+
lowerAnswer: ans.toLowerCase(),
|
|
241
|
+
computeRecords: opts.computeRecords,
|
|
242
|
+
constraints: opts.constraints,
|
|
243
|
+
sources: opts.sources,
|
|
244
|
+
anchorDateISO: opts.anchorDateISO,
|
|
245
|
+
domainTags: opts.domainTags,
|
|
246
|
+
templateId: opts.templateId,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
const overlay = generateUniversalOverlay(opts.computeRecords, opts.constraints);
|
|
250
|
+
opts.onDebug?.(`[Universal Rigor] Starting multi-agent loop (max depth ${maxDepth})`);
|
|
251
|
+
|
|
252
|
+
for (let d = 1; d <= maxDepth; d++) {
|
|
253
|
+
actualDepth = d;
|
|
254
|
+
|
|
255
|
+
// Loop-top deterministic auto-fix
|
|
256
|
+
const af = runAutoFix(currentDraft, buildAutoFixCtx(currentDraft));
|
|
257
|
+
if (af.applied.length > 0) {
|
|
258
|
+
currentDraft = af.text;
|
|
259
|
+
allAutoFixes.push(...af.applied);
|
|
260
|
+
opts.onDebug?.(`[Universal Rigor] Deterministic auto-fix (pass ${d}): ${af.applied.join(", ")}`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const score = scoreUniversalGuard(
|
|
264
|
+
opts.userQuery, currentDraft, opts.computeRecords, opts.constraints,
|
|
265
|
+
opts.sources, scanExtra,
|
|
266
|
+
);
|
|
267
|
+
finalScore = score;
|
|
268
|
+
|
|
269
|
+
if (score.combinedScore >= 9.5 && !score.issues.some(i => i.severity === "critical")) {
|
|
270
|
+
opts.onDebug?.(`[Universal Rigor] ✓ Stable at depth ${d} (Score: ${score.combinedScore})`);
|
|
271
|
+
stable = true;
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
opts.onDebug?.(`[Universal Rigor] Depth ${d} failed (Score: ${score.combinedScore}, ${score.issues.length} issues). Running Critique → Editor.`);
|
|
276
|
+
|
|
277
|
+
// Build remediation hints for both critique + editor
|
|
278
|
+
const remediationBlock = buildRemediationBlock(score.issues);
|
|
279
|
+
|
|
280
|
+
// 1. Critique Pass
|
|
281
|
+
const critiqueSys = `You are a strict deterministic auditor. Review the DRAFT against the REFERENCE OVERLAY and the listed ISSUES. Return JSON: {"clear": boolean, "errors": string[], "corrections": string[]}.${remediationBlock}\n\nREFERENCE OVERLAY:\n${overlay}\n\nISSUES DETECTED:\n${JSON.stringify(score.issues)}\n\nDRAFT:\n${currentDraft}`;
|
|
282
|
+
|
|
283
|
+
const critique = await throttle(
|
|
284
|
+
() => generateSynthesizedResponse({ ...opts.baseParams, userMessage: critiqueSys, conversationHistory: [] }),
|
|
285
|
+
{ rpm: opts.rpm, onWait: ms => opts.onDebug?.(`[Universal Rigor] RPM wait ${ms}ms`) }
|
|
286
|
+
);
|
|
287
|
+
debugLog.push({ stage: `Critique ${d}`, content: critique });
|
|
288
|
+
|
|
289
|
+
// 2. Editor Pass
|
|
290
|
+
const editorSys = `You are the final editor. Fix the draft based on the CRITIQUE and REFERENCE OVERLAY. You MUST preserve all correct content, units, and deterministic values. Output ONLY the revised prose. Do not output JSON or commentary.${remediationBlock}\n\nREFERENCE OVERLAY:\n${overlay}\n\nCRITIQUE:\n${critique}\n\nDRAFT:\n${currentDraft}`;
|
|
291
|
+
|
|
292
|
+
const revised = await throttle(
|
|
293
|
+
() => generateSynthesizedResponse({ ...opts.baseParams, userMessage: editorSys, conversationHistory: [] }),
|
|
294
|
+
{ rpm: opts.rpm, onWait: ms => opts.onDebug?.(`[Universal Rigor] RPM wait ${ms}ms`) }
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
currentDraft = revised.trim();
|
|
298
|
+
debugLog.push({ stage: `Editor ${d}`, content: currentDraft });
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (!finalScore) {
|
|
302
|
+
finalScore = scoreUniversalGuard(
|
|
303
|
+
opts.userQuery, currentDraft, opts.computeRecords, opts.constraints,
|
|
304
|
+
opts.sources, scanExtra,
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Final post-loop auto-fix — closes the last-editor leak gap
|
|
309
|
+
const finalAf = runAutoFix(currentDraft, buildAutoFixCtx(currentDraft));
|
|
310
|
+
if (finalAf.applied.length > 0) {
|
|
311
|
+
currentDraft = finalAf.text;
|
|
312
|
+
allAutoFixes.push(...finalAf.applied);
|
|
313
|
+
opts.onDebug?.(`[Universal Rigor] Final auto-fix: ${finalAf.applied.join(", ")}`);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Always re-score the exact shipped draft
|
|
317
|
+
finalScore = scoreUniversalGuard(
|
|
318
|
+
opts.userQuery, currentDraft, opts.computeRecords, opts.constraints,
|
|
319
|
+
opts.sources, scanExtra,
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
// Promote stable if final draft qualifies
|
|
323
|
+
if (!stable && finalScore.combinedScore >= 9.5 && !finalScore.issues.some(i => i.severity === "critical")) {
|
|
324
|
+
stable = true;
|
|
325
|
+
opts.onDebug?.(`[Universal Rigor] Stabilized by final draft score ${finalScore.combinedScore}.`);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Blind Third-Party Judge (parallel)
|
|
329
|
+
opts.onDebug?.(`[Universal Rigor] Running Blind Third-Party Judge Ensemble`);
|
|
330
|
+
const judgeResult = await judgeEnsembleUniversal({
|
|
331
|
+
prompt: opts.userQuery,
|
|
332
|
+
draft: currentDraft,
|
|
333
|
+
overlay,
|
|
334
|
+
baseParams: opts.baseParams,
|
|
335
|
+
rpm: opts.rpm,
|
|
336
|
+
judgeModels: opts.judgeModels,
|
|
337
|
+
onDebug: opts.onDebug,
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
return {
|
|
341
|
+
finalText: currentDraft,
|
|
342
|
+
guardScore: finalScore,
|
|
343
|
+
judgeResult,
|
|
344
|
+
passes: actualDepth,
|
|
345
|
+
stable,
|
|
346
|
+
autoFixesApplied: allAutoFixes,
|
|
347
|
+
debugLog,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ─── BLIND JUDGE (parallel, optional cross-model) ─────────────────────────
|
|
352
|
+
async function judgeEnsembleUniversal(opts: {
|
|
353
|
+
prompt: string;
|
|
354
|
+
draft: string;
|
|
355
|
+
overlay: string;
|
|
356
|
+
baseParams: GenerateParams;
|
|
357
|
+
samples?: number;
|
|
358
|
+
rpm?: number;
|
|
359
|
+
judgeModels?: ModelId[];
|
|
360
|
+
onDebug?: (msg: string) => void;
|
|
361
|
+
}): Promise<JudgeEnsembleResult> {
|
|
362
|
+
const samples = opts.samples ?? 3;
|
|
363
|
+
const blindDraft = stripMetaDiscourse(opts.draft);
|
|
364
|
+
|
|
365
|
+
const judgeSystem = `You are an INDEPENDENT third-party grader. You did NOT write the answer. Grade skeptically.
|
|
366
|
+
|
|
367
|
+
MANDATORY VERIFICATION PROTOCOL:
|
|
368
|
+
Step 1 (TOPIC MATCH): Does the answer address the prompt? If completely off-topic, HARD CAP score at 2.0.
|
|
369
|
+
Step 2 (NUMERIC DERIVATION): Compare the answer's numbers to the REFERENCE OVERLAY. If they contradict, HARD CAP at 5.0.
|
|
370
|
+
Step 3 (LOGICAL CONSISTENCY): Are there internal contradictions? If yes, HARD CAP at 3.0.
|
|
371
|
+
Step 4 (UNITS): If numeric prompt lacks units, HARD CAP at 7.0.
|
|
372
|
+
Step 5 (OUTPUT): Return STRICT JSON ONLY:
|
|
373
|
+
{"combinedScore":<0-10>,"topicMatch":<true|false>,"numbersMatchOverlay":<true|false>,"shortNote":<string>}
|
|
374
|
+
|
|
375
|
+
REFERENCE OVERLAY:
|
|
376
|
+
${opts.overlay}
|
|
377
|
+
|
|
378
|
+
USER PROMPT:
|
|
379
|
+
${opts.prompt}
|
|
380
|
+
|
|
381
|
+
ANSWER UNDER REVIEW:
|
|
382
|
+
${blindDraft.slice(0, 15000)}`;
|
|
383
|
+
|
|
384
|
+
// Parallel execution with optional cross-model rotation
|
|
385
|
+
const judgePromises = Array.from({ length: samples }, (_, i) => {
|
|
386
|
+
const jm = (opts.judgeModels && opts.judgeModels.length)
|
|
387
|
+
? opts.judgeModels[i % opts.judgeModels.length]
|
|
388
|
+
: opts.baseParams.model;
|
|
389
|
+
return throttle(
|
|
390
|
+
() => generateSynthesizedResponse({ ...opts.baseParams, model: jm, userMessage: judgeSystem, conversationHistory: [] }),
|
|
391
|
+
{ rpm: opts.rpm, onWait: ms => opts.onDebug?.(`[Universal Judge] RPM wait ${ms}ms`) }
|
|
392
|
+
).then(txt => {
|
|
393
|
+
try {
|
|
394
|
+
const parsed = parseBestJsonObject(txt, "combinedScore");
|
|
395
|
+
let sc = Number(parsed.combinedScore);
|
|
396
|
+
if (!Number.isFinite(sc)) sc = 0;
|
|
397
|
+
sc = clamp(sc, 0, 10);
|
|
398
|
+
if (parsed.topicMatch === false) sc = Math.min(sc, 2.0);
|
|
399
|
+
if (parsed.numbersMatchOverlay === false) sc = Math.min(sc, 5.0);
|
|
400
|
+
return {
|
|
401
|
+
score: sc,
|
|
402
|
+
note: parsed.shortNote ? String(parsed.shortNote).slice(0, 200) : "",
|
|
403
|
+
detail: parsed,
|
|
404
|
+
};
|
|
405
|
+
} catch (err: any) {
|
|
406
|
+
return { score: 0, note: `judge_parse_error: ${err?.message ?? ""}`, detail: null };
|
|
407
|
+
}
|
|
408
|
+
}).catch((err: any) => ({ score: 0, note: `judge_call_error: ${err?.message ?? ""}`, detail: null }));
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
const results = await Promise.all(judgePromises);
|
|
412
|
+
const scores = results.map(r => r.score);
|
|
413
|
+
const notes = results.map(r => r.note);
|
|
414
|
+
const verificationDetails = results.map(r => r.detail);
|
|
415
|
+
|
|
416
|
+
const sorted = [...scores].sort((a, b) => a - b);
|
|
417
|
+
const median = sorted.length % 2 !== 0
|
|
418
|
+
? sorted[Math.floor(sorted.length / 2)]
|
|
419
|
+
: (sorted[sorted.length / 2 - 1] + sorted[sorted.length / 2]) / 2;
|
|
420
|
+
const spread = scores.length ? Math.max(...scores) - Math.min(...scores) : 0;
|
|
421
|
+
|
|
422
|
+
return {
|
|
423
|
+
median: round(median, 2),
|
|
424
|
+
min: Math.min(...scores),
|
|
425
|
+
max: Math.max(...scores),
|
|
426
|
+
spread: round(spread, 2),
|
|
427
|
+
scores,
|
|
428
|
+
notes,
|
|
429
|
+
calls: samples,
|
|
430
|
+
available: true,
|
|
431
|
+
verificationDetails,
|
|
432
|
+
};
|
|
433
|
+
}
|