Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <meta name="description" content="Inspect the Dot Loom Conductor benchmark and reference policy for constrained multi-model routing."> | |
| <title>Dot Loom Conductor | Policy Explorer</title> | |
| <style> | |
| :root { | |
| color-scheme: light; | |
| --paper: #fff; | |
| --ink: #111; | |
| --muted: #686866; | |
| --line: #d9d9d5; | |
| --line-strong: #111; | |
| --wash: #f4f4f1; | |
| --red: #ff001f; | |
| --max: 1400px; | |
| } | |
| * { box-sizing: border-box; } | |
| html { scroll-behavior: smooth; } | |
| body { | |
| margin: 0; | |
| background: var(--paper); | |
| color: var(--ink); | |
| font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
| line-height: 1.45; | |
| } | |
| button, input, textarea, select { font: inherit; } | |
| a { color: inherit; text-underline-offset: 4px; } | |
| a:hover { color: var(--red); } | |
| .mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; } | |
| .shell { width: min(var(--max), calc(100% - 56px)); margin: 0 auto; } | |
| .topbar { | |
| min-height: 70px; | |
| display: flex; | |
| align-items: center; | |
| justify-content: space-between; | |
| gap: 24px; | |
| border-bottom: 1px solid var(--line-strong); | |
| } | |
| .brand { display: flex; align-items: center; gap: 11px; font-weight: 750; letter-spacing: -.02em; } | |
| .brand img { width: 30px; height: 30px; object-fit: contain; } | |
| .brand small { color: var(--muted); font: 11px/1.2 "SFMono-Regular", Consolas, monospace; letter-spacing: .08em; } | |
| .nav { display: flex; align-items: center; gap: 26px; font-size: 13px; } | |
| .nav a { text-decoration: none; } | |
| .intro { | |
| display: grid; | |
| grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr); | |
| gap: 70px; | |
| padding: 76px 0 62px; | |
| border-bottom: 1px solid var(--line-strong); | |
| } | |
| .eyebrow { | |
| color: var(--red); | |
| font: 700 12px/1.2 "SFMono-Regular", Consolas, monospace; | |
| letter-spacing: .12em; | |
| text-transform: uppercase; | |
| } | |
| h1, h2, h3, p { margin-top: 0; } | |
| h1 { margin: 18px 0 20px; font-size: clamp(46px, 5.2vw, 72px); line-height: .98; letter-spacing: -.055em; } | |
| .lede { max-width: 800px; margin-bottom: 0; color: var(--muted); font-size: 20px; } | |
| .intro-facts { border-top: 1px solid var(--line-strong); align-self: end; } | |
| .intro-facts div { display: grid; grid-template-columns: 1fr auto; gap: 20px; padding: 13px 0; border-bottom: 1px solid var(--line); } | |
| .intro-facts dt { color: var(--muted); font-size: 13px; } | |
| .intro-facts dd { margin: 0; font-size: 13px; font-weight: 750; text-align: right; } | |
| .boundary { margin-top: 18px; padding-left: 13px; border-left: 3px solid var(--red); color: var(--muted); font-size: 13px; } | |
| section { padding: 76px 0; border-bottom: 1px solid var(--line-strong); } | |
| .section-head { display: grid; grid-template-columns: 1fr 1fr; gap: 48px; align-items: end; margin-bottom: 34px; } | |
| h2 { margin: 10px 0 0; font-size: clamp(34px, 4vw, 52px); line-height: 1; letter-spacing: -.045em; } | |
| .section-copy { justify-self: end; max-width: 620px; margin-bottom: 0; color: var(--muted); } | |
| .result-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); } | |
| .result-stat { min-width: 0; padding: 19px 18px; border-right: 1px solid var(--line); } | |
| .result-stat:last-child { border-right: 0; } | |
| .result-stat small { display: block; min-height: 30px; color: var(--muted); font: 11px/1.35 "SFMono-Regular", Consolas, monospace; text-transform: uppercase; } | |
| .result-stat strong { display: block; margin-top: 8px; font-size: clamp(23px, 2.4vw, 34px); letter-spacing: -.035em; } | |
| .result-stat strong.red { color: var(--red); } | |
| .benchmark-figure { margin: 34px 0 0; border: 1px solid var(--line); background: var(--paper); } | |
| .benchmark-figure img { display: block; width: 100%; height: auto; } | |
| .caption { margin: 12px 0 0; color: var(--muted); font-size: 12px; } | |
| .workbench { display: grid; grid-template-columns: 430px minmax(0, 1fr); border: 1px solid var(--line-strong); } | |
| .controls { min-width: 0; padding: 26px; border-right: 1px solid var(--line-strong); background: var(--wash); } | |
| .output { min-width: 0; } | |
| .control-group { margin-bottom: 23px; } | |
| .control-label { display: block; margin-bottom: 8px; color: var(--muted); font: 700 11px/1.2 "SFMono-Regular", Consolas, monospace; letter-spacing: .06em; text-transform: uppercase; } | |
| textarea, select, input[type="number"], input[type="text"] { | |
| width: 100%; border: 1px solid #b8b8b4; border-radius: 0; background: var(--paper); color: var(--ink); padding: 10px 11px; outline: none; | |
| } | |
| textarea { min-height: 86px; resize: vertical; } | |
| textarea:focus, select:focus, input:focus { border-color: var(--red); } | |
| .sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 15px 18px; } | |
| .slider-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; } | |
| .slider-meta output { color: var(--ink); font-family: "SFMono-Regular", Consolas, monospace; } | |
| input[type="range"] { width: 100%; accent-color: var(--red); } | |
| .budgets { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } | |
| .field span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; } | |
| details { border-top: 1px solid var(--line); padding-top: 16px; } | |
| summary { cursor: pointer; font-size: 13px; font-weight: 700; } | |
| .workers { margin-top: 16px; display: grid; gap: 16px; } | |
| .worker { padding-top: 13px; border-top: 1px dashed #b8b8b4; } | |
| .worker:first-child { padding-top: 0; border-top: 0; } | |
| .worker-title { margin-bottom: 10px; color: var(--red); font: 700 11px/1.2 "SFMono-Regular", Consolas, monospace; text-transform: uppercase; } | |
| .worker-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; } | |
| .worker-grid .wide { grid-column: 1 / -1; } | |
| .worker-grid input { padding: 8px; font-size: 12px; } | |
| .route-btn { width: 100%; margin-top: 22px; border: 1px solid var(--ink); background: var(--ink); color: #fff; padding: 13px 16px; font-weight: 750; cursor: pointer; } | |
| .route-btn:hover { background: var(--red); border-color: var(--red); } | |
| .output-head { padding: 27px 30px 24px; border-bottom: 1px solid var(--line-strong); } | |
| .output-kicker { display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); font: 11px/1.2 "SFMono-Regular", Consolas, monospace; text-transform: uppercase; } | |
| .policy { margin: 15px 0 24px; color: var(--red); font-size: clamp(46px, 6vw, 78px); font-weight: 780; line-height: .9; letter-spacing: -.06em; } | |
| .policy span { color: var(--red); } | |
| .role-flow { display: grid; grid-template-columns: 1fr 34px 1fr 34px 1fr; align-items: stretch; } | |
| .role { min-width: 0; padding: 15px; border: 1px solid var(--line-strong); } | |
| .role small { display: block; color: var(--muted); font: 10px/1.2 "SFMono-Regular", Consolas, monospace; text-transform: uppercase; } | |
| .role strong { display: block; margin-top: 6px; font-size: 13px; overflow-wrap: anywhere; } | |
| .role.off { opacity: .35; } | |
| .flow-arrow { display: grid; place-items: center; color: var(--red); font-size: 20px; } | |
| .metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-bottom: 1px solid var(--line-strong); } | |
| .metric { min-width: 0; padding: 17px 18px; border-right: 1px solid var(--line); } | |
| .metric:last-child { border-right: 0; } | |
| .metric small { display: block; color: var(--muted); font: 10px/1.2 "SFMono-Regular", Consolas, monospace; text-transform: uppercase; } | |
| .metric strong { display: block; margin-top: 6px; font-size: 18px; overflow-wrap: anywhere; } | |
| .proof { display: grid; grid-template-columns: .75fr 1.25fr; } | |
| .reasons, .json-wrap { min-width: 0; padding: 23px; } | |
| .reasons { border-right: 1px solid var(--line); } | |
| .proof h3 { margin-bottom: 14px; color: var(--muted); font: 700 11px/1.2 "SFMono-Regular", Consolas, monospace; text-transform: uppercase; } | |
| .reason-list { display: grid; gap: 9px; } | |
| .reason { display: flex; align-items: center; gap: 9px; font-size: 12px; overflow-wrap: anywhere; } | |
| .reason::before { content: ""; width: 14px; height: 2px; flex: 0 0 auto; background: var(--red); } | |
| pre { margin: 0; max-height: 250px; overflow: auto; white-space: pre-wrap; color: #2d2d2b; font: 11px/1.55 "SFMono-Regular", Consolas, monospace; } | |
| .error { color: var(--red); } | |
| .candidate-wrap { overflow-x: auto; border-top: 1px solid var(--line-strong); } | |
| .candidate-caption { padding: 12px 15px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; } | |
| table { width: 100%; border-collapse: collapse; font-size: 12px; } | |
| th, td { padding: 11px 13px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; } | |
| th { color: var(--muted); background: var(--wash); font-weight: 700; } | |
| tbody tr:first-child td { color: var(--red); font-weight: 700; } | |
| .evidence { display: grid; grid-template-columns: .7fr 1.3fr; gap: 70px; } | |
| .evidence-lede { font-size: 26px; line-height: 1.25; letter-spacing: -.025em; } | |
| .evidence-list { border-top: 1px solid var(--line-strong); } | |
| .evidence-link { display: grid; grid-template-columns: 36px 1fr auto; gap: 14px; align-items: center; padding: 17px 0; border-bottom: 1px solid var(--line); text-decoration: none; } | |
| .evidence-link > span { color: var(--red); font-family: "SFMono-Regular", Consolas, monospace; } | |
| .evidence-link small { color: var(--muted); } | |
| footer { display: flex; justify-content: space-between; gap: 20px; padding: 27px 0 46px; color: var(--muted); font-size: 12px; } | |
| @media (max-width: 1120px) { | |
| .intro { grid-template-columns: 1fr; gap: 38px; } | |
| .intro-facts { max-width: 720px; } | |
| .workbench { grid-template-columns: 380px minmax(0, 1fr); } | |
| .result-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); } | |
| .result-stat:nth-child(3) { border-right: 0; } | |
| .result-stat:nth-child(-n+3) { border-bottom: 1px solid var(--line); } | |
| } | |
| @media (max-width: 900px) { | |
| .section-head, .evidence { grid-template-columns: 1fr; gap: 22px; } | |
| .section-copy { justify-self: start; } | |
| .workbench { grid-template-columns: 1fr; } | |
| .controls { border-right: 0; border-bottom: 1px solid var(--line-strong); } | |
| } | |
| @media (max-width: 680px) { | |
| .shell { width: min(var(--max), calc(100% - 28px)); } | |
| .topbar { min-height: 62px; } | |
| .nav { display: none; } | |
| .intro { padding: 50px 0 44px; } | |
| h1 { font-size: clamp(42px, 12.4vw, 58px); } | |
| .lede { font-size: 17px; } | |
| section { padding: 54px 0; } | |
| .result-strip { grid-template-columns: 1fr 1fr; } | |
| .result-stat, .result-stat:nth-child(3) { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); } | |
| .result-stat:nth-child(even) { border-right: 0; } | |
| .result-stat:last-child { grid-column: 1 / -1; border-right: 0; border-bottom: 0; } | |
| .benchmark-figure { overflow-x: auto; } | |
| .benchmark-figure img { width: 900px; max-width: none; } | |
| .sliders, .budgets, .worker-grid { grid-template-columns: 1fr; } | |
| .worker-grid .wide { grid-column: auto; } | |
| .output-head { padding: 22px; } | |
| .role-flow { grid-template-columns: 1fr; gap: 8px; } | |
| .flow-arrow { transform: rotate(90deg); height: 24px; } | |
| .metrics { grid-template-columns: 1fr 1fr; } | |
| .metric:nth-child(2) { border-right: 0; } | |
| .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); } | |
| .proof { grid-template-columns: 1fr; } | |
| .reasons { border-right: 0; border-bottom: 1px solid var(--line); } | |
| .evidence-link { grid-template-columns: 28px 1fr; } | |
| .evidence-link small { display: none; } | |
| footer { flex-direction: column; } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <header class="shell topbar"> | |
| <div class="brand"><img src="assets/dot-mark.png" alt="Dot"><span>Dot Loom</span><small>R&D</small></div> | |
| <nav class="nav" aria-label="Research links"> | |
| <a href="#results">Results</a> | |
| <a href="#explorer">Policy explorer</a> | |
| <a href="#evidence">Evidence</a> | |
| <a href="https://huggingface.co/usedot/Dot-Loom-Conductor-14B" target="_blank" rel="noreferrer">Model ↗</a> | |
| </nav> | |
| </header> | |
| <main> | |
| <div class="shell intro"> | |
| <div> | |
| <div class="eyebrow">Dot Loom Conductor 14B</div> | |
| <h1>Learned control for multi-model inference.</h1> | |
| <p class="lede">A Mistral 14B LoRA adapter trained to choose one, two, or three model calls under explicit quality, cost, latency, and verification constraints.</p> | |
| </div> | |
| <aside> | |
| <dl class="intro-facts"> | |
| <div><dt>Base</dt><dd>Ministral 3 · 14B</dd></div> | |
| <div><dt>Training</dt><dd>9,000 traces · 1x H200 SXM5</dd></div> | |
| <div><dt>Held-out exact plan</dt><dd>90.8% with guard</dd></div> | |
| <div><dt>License</dt><dd>Apache 2.0</dd></div> | |
| </dl> | |
| <div class="boundary"><strong>Research boundary:</strong> this Space runs the public reference scorer in the browser. It does not run or imitate weight-level inference from the 14B adapter.</div> | |
| </aside> | |
| </div> | |
| <section id="results"> | |
| <div class="shell"> | |
| <div class="section-head"> | |
| <div><div class="eyebrow">Held-out evaluation</div><h2>What changed after training</h2></div> | |
| <p class="section-copy">The frozen test split contains 1,200 cases from eight task families absent from training and validation. Deterministic Loom is the operational baseline.</p> | |
| </div> | |
| <div class="result-strip" aria-label="Benchmark summary"> | |
| <div class="result-stat"><small>Exact-plan match<br>adapter + guard</small><strong class="red">90.8%</strong></div> | |
| <div class="result-stat"><small>Lift over<br>deterministic Loom</small><strong class="red">+11.5 pp</strong></div> | |
| <div class="result-stat"><small>Paired bootstrap<br>95% CI</small><strong>9.4 to 13.7</strong></div> | |
| <div class="result-stat"><small>Unsafe<br>under-escalation</small><strong class="red">0.0%</strong></div> | |
| <div class="result-stat"><small>Budget violations<br>caught by guard</small><strong>13 / 13</strong></div> | |
| </div> | |
| <figure class="benchmark-figure"><img src="assets/benchmark-overview.png" alt="Held-out benchmark comparing deterministic Loom with the Dot-trained adapter plus runtime guard"></figure> | |
| <p class="caption">The raw base checkpoint is a capacity control, not a comparison with an instruction-tuned assistant. Full lane results, raw predictions, and scoring receipts are linked below.</p> | |
| </div> | |
| </section> | |
| <section id="explorer"> | |
| <div class="shell"> | |
| <div class="section-head"> | |
| <div><div class="eyebrow">Reference policy</div><h2>Inspect constrained routing</h2></div> | |
| <p class="section-copy">The scorer enumerates every valid writer, reviewer, and finalizer assignment, rejects over-budget plans, and ranks the remaining candidates using the disclosed utility function.</p> | |
| </div> | |
| <div class="workbench"> | |
| <form class="controls" id="route-form"> | |
| <div class="control-group"> | |
| <label class="control-label" for="preset">Scenario</label> | |
| <select id="preset"> | |
| <option>Billing race</option> | |
| <option>SSRF audit</option> | |
| <option>Low-risk copy edit</option> | |
| <option>Product tradeoff</option> | |
| </select> | |
| </div> | |
| <div class="control-group"> | |
| <label class="control-label" for="summary">Task</label> | |
| <textarea id="summary"></textarea> | |
| </div> | |
| <div class="control-group sliders"> | |
| <label><span class="slider-meta"><span>Risk</span><output id="risk-out"></output></span><input id="risk" type="range" min="0" max="1" step="0.01"></label> | |
| <label><span class="slider-meta"><span>Complexity</span><output id="complexity-out"></output></span><input id="complexity" type="range" min="0" max="1" step="0.01"></label> | |
| <label><span class="slider-meta"><span>Consequence</span><output id="consequence-out"></output></span><input id="consequence" type="range" min="0" max="1" step="0.01"></label> | |
| <label><span class="slider-meta"><span>Ambiguity</span><output id="ambiguity-out"></output></span><input id="ambiguity" type="range" min="0" max="1" step="0.01"></label> | |
| <label><span class="slider-meta"><span>Evidence need</span><output id="evidence-out"></output></span><input id="evidence" type="range" min="0" max="1" step="0.01"></label> | |
| <label><span class="slider-meta"><span>Reversibility</span><output id="reversibility-out"></output></span><input id="reversibility" type="range" min="0" max="1" step="0.01"></label> | |
| </div> | |
| <div class="control-group budgets"> | |
| <label class="field"><span>Maximum calls</span><input id="max-calls" type="number" min="1" max="3" step="1"></label> | |
| <label class="field"><span>Maximum credits</span><input id="max-credits" type="number" min="0.1" step="0.1"></label> | |
| <label class="field"><span>Maximum latency, ms</span><input id="max-latency" type="number" min="1000" step="1000"></label> | |
| <label class="field"><span>Target quality</span><input id="min-quality" type="number" min="0" max="1" step="0.01"></label> | |
| </div> | |
| <details> | |
| <summary>Edit the three worker profiles</summary> | |
| <div class="workers" id="workers"></div> | |
| </details> | |
| <button class="route-btn" type="submit">Enumerate and select policy</button> | |
| </form> | |
| <div class="output" id="result" aria-live="polite"> | |
| <div class="output-head"> | |
| <div class="output-kicker"><span>Reference selection</span><span id="candidate-count"></span></div> | |
| <div class="policy" id="policy"></div> | |
| <div class="role-flow" id="role-flow"></div> | |
| </div> | |
| <div class="metrics"> | |
| <div class="metric"><small>Credits</small><strong id="metric-credits"></strong></div> | |
| <div class="metric"><small>P95 latency</small><strong id="metric-latency"></strong></div> | |
| <div class="metric"><small>Estimated quality</small><strong id="metric-quality"></strong></div> | |
| <div class="metric"><small>Estimated pass rate</small><strong id="metric-pass"></strong></div> | |
| </div> | |
| <div class="proof"> | |
| <div class="reasons"><h3>Reason codes</h3><div class="reason-list" id="reasons"></div></div> | |
| <div class="json-wrap"><h3>Machine-readable plan</h3><pre id="plan-json"></pre></div> | |
| </div> | |
| <div class="candidate-wrap"> | |
| <div class="candidate-caption" id="candidate-caption"></div> | |
| <table> | |
| <thead><tr><th>Policy</th><th>Writer</th><th>Reviewer</th><th>Finalizer</th><th>Credits</th><th>Latency</th><th>Quality</th><th>Pass rate</th><th>Utility</th></tr></thead> | |
| <tbody id="candidate-body"></tbody> | |
| </table> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </section> | |
| <section id="evidence"> | |
| <div class="shell evidence"> | |
| <div> | |
| <div class="eyebrow">Evidence package</div> | |
| <p class="evidence-lede">Weights, data, raw predictions, receipts, checksums, and limitations are published together.</p> | |
| <p class="section-copy" style="margin-top:20px">The study measures routing-plan generation. It does not establish universal model rankings or final code correctness.</p> | |
| </div> | |
| <div class="evidence-list"> | |
| <a class="evidence-link" href="https://huggingface.co/usedot/Dot-Loom-Conductor-14B" target="_blank" rel="noreferrer"><span>01</span><strong>Adapter, model card, and evidence receipts</strong><small>Model ↗</small></a> | |
| <a class="evidence-link" href="https://huggingface.co/datasets/usedot/dot-loom-conductor-v2" target="_blank" rel="noreferrer"><span>02</span><strong>11,100-example corpus and split viewer</strong><small>Dataset ↗</small></a> | |
| <a class="evidence-link" href="https://huggingface.co/usedot/Dot-Loom-Conductor-14B/blob/main/TECHNICAL_REPORT.md" target="_blank" rel="noreferrer"><span>03</span><strong>Methods, results, deployment boundary, and limitations</strong><small>Report ↗</small></a> | |
| <a class="evidence-link" href="https://github.com/usedotai/dot-loom/tree/main/research/ministral-conductor" target="_blank" rel="noreferrer"><span>04</span><strong>Source, tests, raw predictions, and reproducible runners</strong><small>GitHub ↗</small></a> | |
| </div> | |
| </div> | |
| </section> | |
| </main> | |
| <footer class="shell"><span>Dot R&D · Apache 2.0 · July 2026</span><span>No prompts leave this browser.</span></footer> | |
| <script> | |
| ; | |
| const defaultWorkers = [ | |
| {id:"efficient-writer",provider_group:"local",quality:.72,pass_rate:.56,credits_per_call:.15,p95_latency_ms:6500,strengths:["coding","drafting","speed"]}, | |
| {id:"independent-reviewer",provider_group:"provider-y",quality:.89,pass_rate:.85,credits_per_call:3.5,p95_latency_ms:35000,strengths:["reasoning","review","writing"]}, | |
| {id:"strong-finalizer",provider_group:"provider-z",quality:.97,pass_rate:.96,credits_per_call:12.5,p95_latency_ms:42000,strengths:["implementation","reasoning","synthesis"]} | |
| ]; | |
| const presets = { | |
| "Low-risk copy edit": {summary:"Rewrite a short release note without changing any facts.",risk:.12,complexity:.25,consequence:.10,ambiguity:.20,evidence:.12,reversibility:.95,maxCalls:1,maxCredits:1,maxLatency:15000,minQuality:.55}, | |
| "Billing race": {summary:"Audit a USDC credit claim for concurrent debit, retry, settlement, and recovery failures.",risk:.96,complexity:.91,consequence:.98,ambiguity:.57,evidence:.94,reversibility:.12,maxCalls:3,maxCredits:16.5,maxLatency:95000,minQuality:.90}, | |
| "SSRF audit": {summary:"Audit a user-controlled fetcher for redirects, DNS rebinding, and metadata endpoint access.",risk:.95,complexity:.88,consequence:.96,ambiguity:.62,evidence:.92,reversibility:.18,maxCalls:3,maxCredits:16.5,maxLatency:95000,minQuality:.90}, | |
| "Product tradeoff": {summary:"Choose between two implementation strategies under a fixed budget.",risk:.34,complexity:.58,consequence:.46,ambiguity:.68,evidence:.55,reversibility:.78,maxCalls:2,maxCredits:5,maxLatency:60000,minQuality:.72} | |
| }; | |
| const $ = id => document.getElementById(id); | |
| const clamp = (value, low=0, high=1) => Math.max(low, Math.min(high, value)); | |
| const rounded = (value, digits=4) => Number(Number(value).toFixed(digits)); | |
| const esc = value => String(value).replace(/[&<>'"]/g, c => ({"&":"&","<":"<",">":">","'":"'",'"':"""}[c])); | |
| function planRecord(policy, writer, reviewer=null, finalizer=null) { | |
| const selected = [writer, reviewer, finalizer].filter(Boolean); | |
| return { | |
| policy, writer:writer.id, reviewer:reviewer?.id ?? null, finalizer:finalizer?.id ?? null, | |
| max_calls:selected.length, | |
| estimated_credits:rounded(selected.reduce((sum,w)=>sum+w.credits_per_call,0),3), | |
| estimated_latency_ms:selected.reduce((sum,w)=>sum+w.p95_latency_ms,0), | |
| independent_verification:Boolean(reviewer && reviewer.provider_group !== writer.provider_group), | |
| access:{writer:[],reviewer:reviewer?["writer"]:[],finalizer:finalizer?["writer","reviewer"]:[]} | |
| }; | |
| } | |
| function enumeratePlans(workers) { | |
| const plans = []; | |
| workers.forEach(w => plans.push(planRecord("lean",w))); | |
| workers.forEach(w => workers.forEach(r => { if (r.id !== w.id) plans.push(planRecord("balanced",w,r)); })); | |
| workers.forEach(w => workers.forEach(r => workers.forEach(f => { | |
| if (new Set([w.id,r.id,f.id]).size === 3) plans.push(planRecord("strict",w,r,f)); | |
| }))); | |
| return plans; | |
| } | |
| function outcomeForPlan(task, workers, plan) { | |
| const byId = Object.fromEntries(workers.map(w=>[w.id,w])); | |
| const writer = byId[plan.writer]; | |
| const difficulty = .42*task.complexity + .28*task.ambiguity + .3*task.risk; | |
| let quality = clamp(writer.quality - .24*difficulty + .08*(1-task.complexity),.05,.995); | |
| let passRate = clamp(writer.pass_rate - .27*difficulty,.03,.995); | |
| if (plan.reviewer) { | |
| const reviewer = byId[plan.reviewer]; | |
| const independent = reviewer.provider_group !== writer.provider_group; | |
| const reliability = reviewer.quality*reviewer.pass_rate; | |
| let power = reliability*(.28+.34*task.evidence_need+.18*task.risk); | |
| if (independent) power *= 1.12; | |
| const regression = (1-reviewer.quality)*(1-reviewer.pass_rate)*(.08+.08*task.ambiguity); | |
| quality = clamp(quality+(1-quality)*power-quality*regression); | |
| passRate = clamp(passRate+(1-passRate)*reliability*(.36+.34*task.risk)-passRate*regression*.5); | |
| } | |
| if (plan.finalizer) { | |
| const finalizer = byId[plan.finalizer]; | |
| const synthesisFit = finalizer.strengths.some(s=>["synthesis","reasoning","writing"].includes(s)) ? .035 : -.025; | |
| const finalizerQuality = clamp(finalizer.quality-.1*difficulty+synthesisFit,.05,.995); | |
| const power = finalizerQuality*finalizer.pass_rate*(.2+.24*task.complexity+.16*task.ambiguity); | |
| const evidenceQuality = clamp(quality+(1-quality)*power); | |
| quality = clamp(.58*evidenceQuality+.42*finalizerQuality); | |
| passRate = clamp(.62*passRate+.38*finalizer.pass_rate); | |
| } | |
| return {quality:rounded(quality),pass_rate:rounded(passRate)}; | |
| } | |
| const feasible = (plan,c) => plan.max_calls<=c.max_calls && plan.estimated_credits<=c.max_credits+1e-9 && plan.estimated_latency_ms<=c.max_latency_ms; | |
| function roleFitnessPenalty(c, workers, plan) { | |
| const byId = Object.fromEntries(workers.map(w=>[w.id,w])); | |
| const writer = byId[plan.writer]; | |
| let penalty = 0; | |
| if (plan.reviewer) { | |
| const reviewer = byId[plan.reviewer]; | |
| const floor = Math.max(.55,Math.min(.82,c.minimum_quality-.1)); | |
| penalty += 22*Math.max(0,floor-reviewer.quality) + 12*Math.max(0,.58-reviewer.pass_rate) + 9*Math.max(0,writer.quality-reviewer.quality-.18); | |
| if (!reviewer.strengths.some(s=>["review","reasoning"].includes(s))) penalty += 2.5; | |
| } | |
| if (plan.finalizer) { | |
| const finalizer = byId[plan.finalizer]; | |
| const selected = [plan.writer,plan.reviewer,plan.finalizer].filter(Boolean).map(id=>byId[id]); | |
| const bestQuality = Math.max(...selected.map(w=>w.quality)); | |
| const bestPass = Math.max(...selected.map(w=>w.pass_rate)); | |
| penalty += 34*Math.max(0,bestQuality-finalizer.quality) + 14*Math.max(0,bestPass-finalizer.pass_rate-.08); | |
| if (!finalizer.strengths.some(s=>["synthesis","reasoning","writing"].includes(s))) penalty += 3; | |
| } | |
| return penalty; | |
| } | |
| function utility(task,c,plan,outcome,workers) { | |
| let score = 62*outcome.quality + 23*outcome.pass_rate; | |
| score -= 7*plan.estimated_credits/Math.max(c.max_credits,.1); | |
| score -= 4.5*plan.estimated_latency_ms/Math.max(c.max_latency_ms,1); | |
| score -= 1.5*(plan.max_calls-1) + roleFitnessPenalty(c,workers,plan); | |
| score -= 42*Math.max(0,c.minimum_quality-outcome.quality); | |
| const verificationPressure = task.risk*task.consequence*(.55+.45*task.evidence_need); | |
| if (plan.independent_verification) score += 12*verificationPressure; | |
| else if (verificationPressure>.42) score -= 28*verificationPressure; | |
| const synthesisPressure = .4*task.complexity+.25*task.ambiguity+.2*task.risk+.15*task.evidence_need; | |
| if (plan.policy==="strict") score += 30*Math.max(0,synthesisPressure-.35); | |
| if (task.risk<.28 && task.complexity<.42) score -= 4.8*(plan.max_calls-1); | |
| if (task.reversibility<.3 && plan.policy==="lean") score -= 7.5; | |
| return rounded(score,6); | |
| } | |
| function reasonCodes(task,c,plan,outcome) { | |
| const reasons=[]; | |
| if (task.risk>=.72 || task.consequence>=.78) reasons.push("high_consequence"); | |
| if (task.evidence_need>=.65) reasons.push("independent_evidence"); | |
| if (task.complexity>=.72 || task.ambiguity>=.72) reasons.push("complex_task"); | |
| if (plan.estimated_credits>=c.max_credits*.82) reasons.push("credit_constrained"); | |
| if (plan.estimated_latency_ms>=c.max_latency_ms*.82) reasons.push("latency_constrained"); | |
| if (outcome.quality<c.minimum_quality) reasons.push("best_feasible_below_target"); | |
| if (plan.policy==="lean" && reasons.length===0) reasons.push("single_call_sufficient"); | |
| if (plan.independent_verification) reasons.push("independent_verification"); | |
| return [...new Set(reasons)].sort().slice(0,4); | |
| } | |
| function renderWorkers(workers=defaultWorkers) { | |
| $("workers").innerHTML = workers.map((w,i)=>` | |
| <div class="worker" data-worker="${i}"> | |
| <div class="worker-title">Candidate ${String.fromCharCode(65+i)}</div> | |
| <div class="worker-grid"> | |
| <label class="field wide"><span>Name</span><input data-k="id" type="text" value="${esc(w.id)}"></label> | |
| <label class="field"><span>Provider group</span><input data-k="provider_group" type="text" value="${esc(w.provider_group)}"></label> | |
| <label class="field"><span>Strengths</span><input data-k="strengths" type="text" value="${esc(w.strengths.join(", "))}"></label> | |
| <label class="field"><span>Quality</span><input data-k="quality" type="number" min="0" max="1" step="0.01" value="${w.quality}"></label> | |
| <label class="field"><span>Pass rate</span><input data-k="pass_rate" type="number" min="0" max="1" step="0.01" value="${w.pass_rate}"></label> | |
| <label class="field"><span>Credits / call</span><input data-k="credits_per_call" type="number" min="0" step="0.01" value="${w.credits_per_call}"></label> | |
| <label class="field"><span>P95 latency, ms</span><input data-k="p95_latency_ms" type="number" min="1" step="100" value="${w.p95_latency_ms}"></label> | |
| </div> | |
| </div>`).join(""); | |
| } | |
| function readWorkers() { | |
| return [...document.querySelectorAll("[data-worker]")].map(node=>{ | |
| const get = key => node.querySelector(`[data-k="${key}"]`).value; | |
| return {id:get("id").trim(),provider_group:get("provider_group").trim(),quality:Number(get("quality")),pass_rate:Number(get("pass_rate")),credits_per_call:Number(get("credits_per_call")),p95_latency_ms:Number(get("p95_latency_ms")),strengths:get("strengths").split(",").map(s=>s.trim()).filter(Boolean)}; | |
| }); | |
| } | |
| function validateWorkers(workers) { | |
| if (new Set(workers.map(w=>w.id)).size!==3 || workers.some(w=>!w.id)) throw new Error("Candidate names must be non-empty and unique."); | |
| if (workers.some(w=>w.quality<0||w.quality>1||w.pass_rate<0||w.pass_rate>1)) throw new Error("Quality and pass rate must stay between 0 and 1."); | |
| if (workers.some(w=>w.credits_per_call<0||w.p95_latency_ms<1)) throw new Error("Cost and latency must be positive."); | |
| } | |
| function selectPlan(task,c,workers) { | |
| validateWorkers(workers); | |
| const candidates=enumeratePlans(workers).filter(plan=>feasible(plan,c)).map(plan=>{ | |
| const outcome=outcomeForPlan(task,workers,plan); | |
| return {plan,outcome,score:utility(task,c,plan,outcome,workers)}; | |
| }); | |
| if (!candidates.length) throw new Error("No plan fits the selected call, credit, and latency budgets."); | |
| const eligible=candidates.filter(row=>row.outcome.quality>=c.minimum_quality); | |
| const ranked=(eligible.length?eligible:candidates).sort((a,b)=>b.score-a.score||b.outcome.quality-a.outcome.quality||b.outcome.pass_rate-a.outcome.pass_rate||a.plan.estimated_credits-b.plan.estimated_credits||a.plan.estimated_latency_ms-b.plan.estimated_latency_ms); | |
| const winner=ranked[0]; | |
| const result={...winner.plan,max_credits:c.max_credits,max_latency_ms:c.max_latency_ms,estimated_quality:winner.outcome.quality,estimated_pass_rate:winner.outcome.pass_rate,reason_codes:reasonCodes(task,c,winner.plan,winner.outcome)}; | |
| return {result,candidates:candidates.sort((a,b)=>b.score-a.score)}; | |
| } | |
| function renderRoles(result) { | |
| const roles=[["Writer",result.writer],["Reviewer",result.reviewer],["Finalizer",result.finalizer]]; | |
| $("role-flow").innerHTML=roles.map(([label,value],index)=>`${index?'<div class="flow-arrow">→</div>':''}<div class="role ${value?'':'off'}"><small>${label}</small><strong>${esc(value||"not used")}</strong></div>`).join(""); | |
| } | |
| function renderCandidates(rows) { | |
| $("candidate-body").innerHTML=rows.map(({plan,outcome,score})=>`<tr><td>${esc(plan.policy)}</td><td>${esc(plan.writer)}</td><td>${esc(plan.reviewer||"-")}</td><td>${esc(plan.finalizer||"-")}</td><td>${plan.estimated_credits.toFixed(3)}</td><td>${plan.estimated_latency_ms.toLocaleString()} ms</td><td>${outcome.quality.toFixed(4)}</td><td>${outcome.pass_rate.toFixed(4)}</td><td>${score.toFixed(4)}</td></tr>`).join(""); | |
| $("candidate-caption").textContent=`${rows.length} feasible candidates, ranked by disclosed utility`; | |
| } | |
| function renderResult(result,candidates,c) { | |
| $("policy").innerHTML=`<span>${esc(result.policy.toUpperCase())}</span> · ${result.max_calls}`; | |
| $("candidate-count").textContent=`${candidates.length} feasible plans`; | |
| renderRoles(result); | |
| $("metric-credits").textContent=`${result.estimated_credits.toFixed(3)} / ${c.max_credits.toFixed(3)}`; | |
| $("metric-latency").textContent=`${result.estimated_latency_ms.toLocaleString()} ms`; | |
| $("metric-quality").textContent=result.estimated_quality.toFixed(4); | |
| $("metric-pass").textContent=result.estimated_pass_rate.toFixed(4); | |
| $("reasons").innerHTML=result.reason_codes.map(reason=>`<div class="reason mono">${esc(reason)}</div>`).join(""); | |
| $("plan-json").className=""; | |
| $("plan-json").textContent=JSON.stringify(result,null,2); | |
| renderCandidates(candidates); | |
| } | |
| function renderError(message) { | |
| $("policy").innerHTML='<span>INPUT</span> ERROR'; | |
| $("candidate-count").textContent="no plan selected"; | |
| $("role-flow").innerHTML=""; | |
| ["metric-credits","metric-latency","metric-quality","metric-pass"].forEach(id=>$(id).textContent="-"); | |
| $("reasons").innerHTML=`<div class="reason">${esc(message)}</div>`; | |
| $("plan-json").className="error"; | |
| $("plan-json").textContent=JSON.stringify({error:message},null,2); | |
| $("candidate-body").innerHTML=""; | |
| $("candidate-caption").textContent="Correct the inputs and route again"; | |
| } | |
| function currentInputs() { | |
| return { | |
| task:{risk:Number($("risk").value),complexity:Number($("complexity").value),consequence:Number($("consequence").value),ambiguity:Number($("ambiguity").value),evidence_need:Number($("evidence").value),reversibility:Number($("reversibility").value)}, | |
| constraints:{max_calls:Number($("max-calls").value),max_credits:Number($("max-credits").value),max_latency_ms:Number($("max-latency").value),minimum_quality:Number($("min-quality").value)} | |
| }; | |
| } | |
| function route() { | |
| try { | |
| const {task,constraints}=currentInputs(); | |
| const {result,candidates}=selectPlan(task,constraints,readWorkers()); | |
| renderResult(result,candidates,constraints); | |
| } catch (error) { renderError(error.message); } | |
| } | |
| function updateOutputs() { | |
| [["risk","risk-out"],["complexity","complexity-out"],["consequence","consequence-out"],["ambiguity","ambiguity-out"],["evidence","evidence-out"],["reversibility","reversibility-out"]].forEach(([input,output])=>$(output).value=Number($(input).value).toFixed(2)); | |
| } | |
| function setPreset(name) { | |
| const p=presets[name]; | |
| $("summary").value=p.summary; | |
| [["risk",p.risk],["complexity",p.complexity],["consequence",p.consequence],["ambiguity",p.ambiguity],["evidence",p.evidence],["reversibility",p.reversibility]].forEach(([id,value])=>$(id).value=value); | |
| $("max-calls").value=p.maxCalls; | |
| $("max-credits").value=p.maxCredits; | |
| $("max-latency").value=p.maxLatency; | |
| $("min-quality").value=p.minQuality; | |
| updateOutputs(); | |
| route(); | |
| } | |
| renderWorkers(); | |
| $("preset").addEventListener("change",event=>setPreset(event.target.value)); | |
| $("route-form").addEventListener("submit",event=>{event.preventDefault();route();}); | |
| document.querySelectorAll('input[type="range"]').forEach(input=>input.addEventListener("input",updateOutputs)); | |
| setPreset("Billing race"); | |
| </script> | |
| </body> | |
| </html> | |