exec((__import__('pathlib').Path(__file__).parent/'apply-shared.py').read_text().split("append('src/lib/format.ts'")[0]) p=root/'src/components/ComposerControls.tsx';s=p.read_text();s=s.replace("import { Btn, Dialog, Icon }", "import { Btn, Dialog, Icon, ErrorNotice }");s="import { formatModelName } from '../lib/format';\nimport { features } from '../lib/features';\n"+s start=s.index(' }')+s[end:] start=s.index(' {features.thinkingLevels&&} '''+s[end:] start=s.index(':null}", "{error&&!urlOpen?setError('')}/>:null}") p.write_text(s) # Usage is calculated from streaming stats or explicitly marked estimates, never a fabricated rate. p=root/'src/lib/chat-metrics.ts';s=p.read_text();s=s.replace("const speed=[...replies].reverse().find(m=>m.tps!==undefined)?.tps??null;", "const streaming=replies.find(m=>m.streaming);\n const speed=streaming?.tps??[...replies].reverse().find(m=>m.tps!==undefined)?.tps??null;") s=s.replace('total:hasUsage?session.tokensIn+session.tokensOut:messages.length?null:0,', 'total:hasUsage?session.tokensIn+session.tokensOut+(streaming?.tokens??0):replies.every(m=>m.inputTokens!==undefined&&m.tokens!==undefined)?replies.reduce((n,m)=>n+m.inputTokens!+m.tokens!,0):null,') s=s.replace('return {example:', "return {streaming:!!streaming,estimated:streaming?.usageSource==='estimated',hasReplies:replies.length>0,example:") p.write_text(s) edit('src/lib/types.ts',"usageSource?: 'reported' | 'demo' | 'unavailable';", "usageSource?: 'reported' | 'demo' | 'unavailable' | 'estimated';") edit('src/lib/store.ts',"statsAvailable: sess.statsAvailable !== false && typeof frame.tokensIn === 'number' && typeof frame.tokensOut === 'number',", "statsAvailable: typeof frame.tokensIn === 'number' && typeof frame.tokensOut === 'number' && sess.messages.filter(m=>m.role==='assistant'&&!m.streaming).every(m=>typeof m.inputTokens==='number'),") edit('src/lib/store.ts',"patchAssistant((m) => ({ ...m, content: m.content + String(frame.text ?? '') }));", "patchAssistant((m) => { const content=m.content+String(frame.text??''); const count=Math.max(1,Math.ceil(content.length/4)); const seconds=Math.max(.1,(performance.now()-started)/1000); return {...m,content,tokens:count,tps:count/seconds,usageSource:'estimated'}; });") p=root/'src/components/TelemetryPopover.tsx';s=p.read_text();s=s.replace('const note=m.example?', 'if(!m.hasReplies)return null;\n const note=m.example?');s=s.replace("`${m.speed===null?'—':Math.round(m.speed)} tokens/s`", "`${m.estimated?'≈ ':''}${m.speed===null?'—':Math.round(m.speed)} tok/s${m.streaming?'':' · last reply'}`");s=s.replace('label="LLM time"','label="Thinking & writing"');s=s.replace('title="Session statistics">{m.estimated?

Live estimate from response length and elapsed time. Final usage comes from the engine.

:null}','') p=root/'src/components/Markdown.tsx';s=p.read_text();s=s.replace(r'\*\*[^*]+\*\*|',r'\*\*[^*]+\*\*|\*[^*\n]+\*|');s=s.replace(' const link =', " if (part.startsWith('*') && part.endsWith('*')) return {part.slice(1,-1)};\n const link =");p.write_text(s) p=root/'src/screens/Chat.tsx';s=p.read_text();s=s.replace('Btn, Empty, Icon, IconBtn,','Btn, Empty, Icon, IconBtn, ErrorNotice,');s=s.replace('clockTime, cx, duration, tokens, tps','clockTime, cx, duration, tokens, tps, formatModelName');s=s.replace('const inlinePreview = splitWidth >= (selectedRun ? 720 : 900);','const inlinePreview = splitWidth >= (selectedRun ? 960 : 1120);');start=s.index(' ',start);s=s[:start]+' '+s[end:];s=s.replace('Try the two-stream UI demo · add a prompt','Try two versions and keep the better one');s=s.replace('!draft.trim() || (!loaded',"!draft.trim() || draft.trim()==='/' || (!loaded");s=s.replace(' value={draft}\n', ' rows={1}\n value={draft}\n');s=s.replace(' onChange={(e) => setDraft(e.target.value)}',' onChange={(e) => {setDraft(e.target.value);e.currentTarget.style.height="auto";e.currentTarget.style.height=`${Math.min(180,e.currentTarget.scrollHeight)}px`;}}');s=s.replace("{m.example?'Design example':'Demo response · simulated inference'}", "{m.example?'Design example':'Preview build'}");s=s.replace('More', '');s=s.replace('{t.name} · {t.state}', '{t.name}·{t.state===\'done\'&&t.scope!==\'read\'?\'Approved\':t.state===\'denied\'?\'Denied\':t.state===\'done\'?\'Done\':t.state}');s=s.replace('B selected · inspect the two passes','Version B selected · compare versions');p.write_text(s) # A failed example agent has an inspectable log; do not invent a working retry API. p=root/'src/components/SubagentRow.tsx';s=p.read_text();s="import { useState } from 'react';\n"+s;s=s.replace("import { Icon, type IconName }", "import { Btn, Dialog, Icon, type IconName }");s=s.replace(' const state=',' const [log,setLog]=useState(false);\n const state=');s=s.replace('

', '

{a.status===\'failed\'?:null}');s=s.replace(' ;',' setLog(false)} actions={setLog(false)}>Done}>

{a.description}

Status: {state.label} · {elapsed(a.durationMs)} · {compactTokens(a.tokens)} tokens

;');p.write_text(s) append('src/styles/app.css','\n.text-action { padding:0; border:0; background:none; color:var(--st-accent-text); cursor:pointer; font:inherit; font-size:12px; text-decoration:underline; }\n')