uisandbox-mcp 0.2.0 → 0.3.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/README.md CHANGED
@@ -31,6 +31,16 @@ npx tsx mcp/smoke.ts fixtures/x.zip # load → set → export → verify
31
31
 
32
32
  The conversation this is built for: *"Can I look at this app in a sandbox and change the design a bit?"* → the agent builds, `load`s, `open`s; you play in the real sandbox; *"export what I did"* → `state` → `export`.
33
33
 
34
+ ## Without an agent
35
+
36
+ ```bash
37
+ npx uisandbox-mcp open ./dist # a folder or a zip: the sandbox opens in your browser, served from 127.0.0.1
38
+ ```
39
+
40
+ ## Slash commands
41
+
42
+ Where the client shows MCP prompts (Claude Desktop, Claude Code): `/uisandbox:open` (build the current repo, load, open the sandbox) and `/uisandbox:try <change>` (apply, verify 1:1, screenshot, patch). The server also sends `instructions` to the client, so the model knows when to offer the sandbox on its own.
43
+
34
44
  ## Claude Desktop / Claude Code / Cursor
35
45
 
36
46
  ```json
@@ -313,4 +313,4 @@ ${i(n).join(`
313
313
  `)||`/* Turn a knob first — then your CSS/HTML appear here with the new values written in place. */`},{id:`sheet-css`,group:`Your values`,label:`CSS variables`,file:`sandbox-values.css`,make:()=>El(t,n)},{id:`sheet-changed`,group:`Your values`,label:`CSS — changed only`,file:`sandbox-changes.css`,make:()=>El(t,n,{changedOnly:!0})},{id:`sheet-patch`,group:`Your values`,label:`Patch list (find → replace)`,file:`sandbox-patch.txt`,make:()=>Ol(t,n)},{id:`sheet-json`,group:`Your values`,label:`JSON`,file:`sandbox-values.json`,make:()=>Dl(t,n)},{id:`tokens-css`,group:`The tokens`,label:`tokens.css`,file:`tokens.css`,make:()=>X(e)},{id:`tokens-json`,group:`The tokens`,label:`tokens.json`,file:`tokens.json`,make:()=>Bl(e)},{id:`tokens-tw`,group:`The tokens`,label:`Tailwind`,file:`tailwind.tokens.js`,make:()=>Vl(e)},{id:`tokens-shadcn`,group:`The tokens`,label:`shadcn`,file:`shadcn.css`,make:()=>Gl(e)},{id:`ios-swift`,group:`iOS`,label:`DesignTokens.swift`,file:`DesignTokens.swift`,make:()=>Ql(e)},{id:`ios-assets`,group:`iOS`,label:`Asset catalog (colour sets)`,file:`DesignTokens.xcassets.txt`,make:()=>$l(e).map(e=>`// ${e.path}\n${e.content}`).join(`
314
314
  `)},{id:`android-xml`,group:`Android`,label:`colors.xml (+ night)`,file:`colors.xml`,make:()=>ru(e)+`
315
315
  `+ru(e,`dark`)},{id:`android-kt`,group:`Android`,label:`DesignTokens.kt (Compose)`,file:`DesignTokens.kt`,make:()=>iu(e)}],[e,t,n,s]),[u,d]=(0,C.useState)(l[0].id),[f,p]=(0,C.useState)(!1),m=l.find(e=>e.id===u)??l[0],h=(0,C.useMemo)(()=>m.make(),[m]),g=[...new Set(l.map(e=>e.group))],_=(e,t)=>{Rs(`export`,{format:e.replace(/^.*\./,``)});let n=document.createElement(`a`);n.href=URL.createObjectURL(t),n.download=e,n.click(),setTimeout(()=>URL.revokeObjectURL(n.href),2e3)};return(0,F.jsx)(`div`,{className:`dialog__backdrop`,onClick:o,children:(0,F.jsxs)(`div`,{className:`card dialog`,role:`dialog`,"aria-label":`Export`,onClick:e=>e.stopPropagation(),children:[(0,F.jsxs)(`div`,{className:`dialog__head`,children:[(0,F.jsx)(`h2`,{children:`Export — exactly what is in the sandbox`}),(0,F.jsx)(`span`,{className:`stage__spacer`,style:{flex:1}}),(0,F.jsxs)(`button`,{type:`button`,className:`btn btn--secondary btn--sm`,onClick:()=>{let t=l.filter(e=>e.id!==`files`).map(e=>({name:e.file,data:e.make()}));for(let n of $l(e))t.push({name:n.path,data:n.content});for(let e of s??[])t.push({name:`patched/${e.path}`,data:e.text});_(`${r.replace(/[^\w.-]+/g,`-`)}-uisandbox.zip`,su(t.map(e=>({name:e.name,text:e.data}))))},children:[(0,F.jsx)(ie,{size:13,strokeWidth:2}),` Everything (.zip)`]}),(0,F.jsx)(`button`,{type:`button`,className:`btn btn--ghost btn--icon`,onClick:o,"aria-label":`Close`,children:(0,F.jsx)(ye,{size:15})})]}),(0,F.jsxs)(`div`,{className:`dialog__body`,children:[(0,F.jsx)(`nav`,{className:`dialog__nav`,children:g.map(e=>(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`div`,{className:`menu__label`,children:e}),l.filter(t=>t.group===e).map(e=>(0,F.jsx)(`button`,{type:`button`,className:`menu__item ${e.id===u?`menu__item--on`:``}`,onClick:()=>{d(e.id),p(!1)},children:e.label},e.id))]},e))}),(0,F.jsxs)(`div`,{className:`dialog__pane`,children:[(0,F.jsx)(`pre`,{children:h}),(0,F.jsxs)(`div`,{className:`dialog__tools`,children:[(0,F.jsxs)(`span`,{children:[m.file,` · `,h.length.toLocaleString(),` chars`]}),(0,F.jsx)(`span`,{className:`stage__spacer`}),(0,F.jsxs)(`button`,{type:`button`,className:`btn btn--ghost btn--sm`,onClick:async()=>{await navigator.clipboard.writeText(h),p(!0),setTimeout(()=>p(!1),1500)},children:[f?(0,F.jsx)(D,{size:13,strokeWidth:2}):(0,F.jsx)(re,{size:13,strokeWidth:2}),` `,f?`Copied`:`Copy`]}),(0,F.jsxs)(`button`,{type:`button`,className:`btn btn--secondary btn--sm`,onClick:()=>_(m.file,new Blob([h],{type:`text/plain`})),children:[(0,F.jsx)(ie,{size:13,strokeWidth:2}),` Download`]})]})]})]})]})})}function lu(){let{cfg:e,tokens:t,dispatch:n,undo:r,redo:i,reset:a,canUndo:o,canRedo:s}=rr(),[c,l]=(0,C.useState)(null),[u,d]=(0,C.useState)(null),f=(0,C.useRef)(!1),p=e=>d(e?{...e,fromUrl:f.current}:null),[m,h]=(0,C.useState)(null),[g,_]=(0,C.useState)(!0),[v,y]=(0,C.useState)(!1),[b,x]=(0,C.useState)(!1),[S,w]=(0,C.useState)(()=>Ms()),T=(0,C.useRef)(null),ee=(0,C.useRef)(e);ee.current=e;let E=(0,C.useRef)(c);E.current=c;let[D,te]=(0,C.useState)(0),ne=(0,C.useRef)(null),O=(0,C.useMemo)(()=>c?mc(c.project.table,c.report.baseline,e,t):{},[c,e,t,D]),re=(0,C.useRef)(O);re.current=O;let ae=(0,C.useMemo)(()=>{if(!c)return``;let t=c.report.baseline.cfg,n=[e.fontDisplay,e.fontBody].filter((e,n)=>e!==(n===0?t.fontDisplay:t.fontBody)&&e!==`System`);if(!n.length)return``;let r=n.filter(e=>!we(e)),i=n.filter(we),a=[];r.length&&a.push(Be(r[0],r[1]??r[0]));for(let e of i){let t=Tt(e);t&&a.push(`@font-face{font-family:'${Te(e)}';src:url(${t});font-weight:100 900;font-display:swap}`)}if(e.fontDisplay!==t.fontDisplay){let t=String(Rn(e).vars[`--k-font-display`]);a.push(`h1,h2,h3,h4,h5,h6,[class*="title"],[class*="heading"],[class*="hero"],[class*="display"]{font-family:${t} !important}`)}return a.join(`
316
- `)},[e.fontDisplay,e.fontBody,c]),oe=(0,C.useRef)(ae);oe.current=ae,(0,C.useEffect)(()=>{},[c,e,O,n,ae]),(0,C.useEffect)(()=>{document.title=c?`UISandbox — ${c.project.name}`:`UISandbox — Test your design on the real thing`},[c]);let k=(0,C.useMemo)(()=>{if(!c)return 0;let e=c.project.table.identityVars();return Object.keys(O).filter(t=>O[t]!==e[t]).length},[O,c]),A=(0,C.useCallback)(()=>{let e=T.current?.contentDocument;if(!e)return;for(let n of[e,...nl(e)])t(n);function t(e){let t=e.getElementById(`us-vars`);t||(t=e.createElement(`style`),t.id=`us-vars`,(e.head??e.documentElement).prepend(t));let n=ps(re.current),r=n.slice(n.indexOf(`>`)+1,n.lastIndexOf(`<`));t.textContent!==r&&(t.textContent=r);let i=e.getElementById(`us-fonts`);i||(i=e.createElement(`style`),i.id=`us-fonts`,t.after(i));let a=oe.current;i.textContent!==a&&(i.textContent=a);let o=E.current;if(o)try{ns(e,o.project.scheme,ee.current.sb.dark??null)}catch{}}},[]);(0,C.useEffect)(()=>{A()},[O,ae,e.sb.dark,A]),(0,C.useEffect)(()=>{let t=new URLSearchParams(location.search).get(`sync`);if(!t||!c||!/^(127\.0\.0\.1|localhost)$/.test(location.hostname))return;let n=setTimeout(()=>{fetch(`/__state/${encodeURIComponent(t)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({cfg:e})}).catch(()=>{})},400);return()=>clearTimeout(n)},[e,c]);let ce=(0,C.useCallback)(()=>{let e=E.current,t=T.current?.contentDocument;if(!e||!t||!t.body)return;let n=e.report.baseline.cfg;if(!Object.keys(n).every(e=>ee.current[e]===n[e]))return;let r=Fc(e.project.table,n),i={...n,...r??{}},o=!e.report.brandDeclared&&!e.brandSeen;e.brandSeen=!0;let s=Pc(t,i,{brand:o}),c;try{let e=t.defaultView,n=[e.getComputedStyle(t.body).backgroundColor,e.getComputedStyle(t.documentElement).backgroundColor].find(e=>e&&!/^rgba\(0, 0, 0, 0\)$|^transparent$/.test(e));n&&(c=n)}catch{}let u={...i,...s??{}},d=oc(e.project.table,u.cPrimary,{paintedCanvas:c}),f=d.canvasId!==e.report.baseline.families?.canvasId;!r&&!s&&!f||(e.report.baseline={cfg:u,tokens:Rn(u),families:d},r&&e.report.notes.push(`Corrected from rules your JS inserted at runtime: ${Object.entries(r).map(([e,t])=>`${e} ${t}`).join(`, `)}.`),s&&e.report.notes.push(`Corrected from the rendered page: ${Object.entries(s).map(([e,t])=>`${e} ${t}`).join(`, `)}.`),a(u),l({...e}))},[a]),ue=(0,C.useCallback)(()=>{let e=E.current,t=T.current?.contentDocument;if(!e||!t?.body)return;let n=vs(t,e.project.screens);n.length&&(e.project.screens=[...e.project.screens,...n],l({...e}))},[]),j=(0,C.useCallback)(()=>{let e=E.current,t=T.current?.contentWindow;if(!e||!t)return;let n=t.location.pathname.replace(/^\/__sb\/[^/]+\//,`/`).replace(/\/+$/,``)||`/`;e.project.base&&n.startsWith(`/`+e.project.base)&&(n=n.slice(e.project.base.length+1)||`/`),!e.project.screens.some(e=>e.label===n)&&(e.project.screens=[...e.project.screens,{path:n.replace(/^\//,``),label:n,source:`pinned`}],l({...e}))},[]),[fe,pe]=(0,C.useState)(null),[me,he]=(0,C.useState)([]);(0,C.useEffect)(()=>Bc(e=>{E.current?.project.id===e.id&&he(Vc(e))}),[]),(0,C.useEffect)(()=>{he(c?Vc(c.project):[])},[c]);let[ge,ve]=(0,C.useState)(null),be=(0,C.useRef)(null),xe=(0,C.useCallback)(()=>{be.current&&clearTimeout(be.current),be.current=setTimeout(()=>{let e=E.current,t=T.current?.contentDocument;if(!(!e||!t?.body))try{ve(dl(t,e.project.table,re.current))}catch{}},900)},[]),Se=(0,C.useCallback)(()=>{A(),ne.current?.();let e=T.current?.contentDocument;if(e?.body){let t=()=>{let t=[e,...nl(e)],n=t.reduce((e,t)=>e+t.body.querySelectorAll(`*`).length,0),r=t.reduce((e,t)=>e+Array.from(t.styleSheets).reduce((e,t)=>{try{return e+t.cssRules.length}catch{return e}},0),0),i=t.reduce((e,t)=>e+(t.body.innerText??``).trim().length,0);return{shell:t.reduce((e,t)=>e+t.body.querySelectorAll(`img, svg, canvas, video, picture`).length,0)===0&&(n<6||r<3||i<20&&n<40),els:n,rules:r,text:i}};setTimeout(()=>{if(!t().shell){pe(null);return}setTimeout(()=>{let e=t();pe(e.shell?`This screen rendered ${e.els} element${e.els===1?``:`s`}, ${e.rules} style rules and ${e.text} characters of visible text — it looks like a shell, not the app (a page the server fills in, a build that needs its API, or a folder without its CSS). What you see here is not what your users see.`:null)},2800)},1200)}e&&c&&(ne.current=$c(e,c.project.table,()=>{te(e=>e+1),ce(),xe()})),ce(),ue(),xe(),setTimeout(ue,800)},[A,c,ce,ue,xe]);(0,C.useEffect)(()=>()=>{ne.current?.()},[]),(0,C.useEffect)(()=>{let e=null;return Hc(()=>{e&&clearTimeout(e),e=setTimeout(()=>{te(e=>e+1),ce()},80)})},[ce]);let Ce=async(e,t)=>{h(null),Rs(`drop`),u||(f.current=!1);try{p({stage:`read`,done:0,total:e.entries.length,bytes:0,what:e.rootName}),await Jc();let n=0,r=await fs(e,{root:t,onProgress:(t,r,i)=>{let a=Date.now();(a-n>120||t===r)&&(n=a,p({stage:`read`,done:t,total:r,bytes:i,what:e.rootName}))}});if(!r.platform.renders||!r.screens.length)throw Error(Zo(r.platform,{files:e.entries.length}));p({stage:`derive`,total:r.table.entries.length,what:e.rootName});let i=await Mc(e,r.table);p({stage:`open`,what:e.rootName}),c&&Xc(c.project),Yc(r,()=>re.current),a(i.baseline.cfg);let o=new URLSearchParams(location.search).get(`screen`),s=o&&r.screens.find(e=>e.path===o||e.label===o)||r.screens[0];l({project:r,report:i,screen:s,archive:e}),x(!0),Rs(`loaded`,{screens:r.screens.length,values:r.table.entries.length})}catch(e){h(e.message),Rs(`refused`)}finally{p(null)}},M=(0,C.useRef)(!1),Ee=async e=>{h(null),f.current=!0;try{let t=(()=>{try{let t=new URL(e,location.href);return t.pathname.startsWith(`/__repo/`)?new URL(t.searchParams.get(`u`)??``,location.href).host||`github.com`:t.host}catch{return e}})();p({stage:`fetch`,what:t,bytes:0});let n=await fetch(e);if(!n.ok)throw Error(n.status===404?`Nothing at ${t} for that URL (${n.status}).`:`${n.status} fetching from ${t}.`);let r=Number(n.headers.get(`content-length`)||0)||void 0,i=[],a=0,o=n.body?.getReader();if(o)for(;;){let{done:e,value:n}=await o.read();if(e)break;i.push(n),a+=n.byteLength,p({stage:`fetch`,what:t,bytes:a,size:r})}let s=o?new Blob(i):await n.blob(),c=decodeURIComponent(n.headers.get(`content-disposition`)?.match(/filename="?([^";]+)"?/)?.[1]||e.split(`/`).pop()||`archive.zip`);await Ce(await no(new File([s],c.endsWith(`.zip`)?c:`${c}.zip`,{type:`application/zip`})))}catch(e){h(e.message),p(null)}};return(0,C.useEffect)(()=>{if(M.current)return;let e=new URLSearchParams(location.search).get(`load`);e&&(M.current=!0,Ee(e))},[]),(0,C.useEffect)(()=>{let e=e=>{!(e.metaKey||e.ctrlKey)||e.key.toLowerCase()!==`z`||(e.preventDefault(),e.shiftKey?i():r())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,i]),(0,F.jsxs)(`div`,{className:`app`,children:[(0,F.jsxs)(`header`,{className:`app__topbar`,children:[(0,F.jsxs)(`span`,{className:`app__brand`,children:[(0,F.jsx)(`span`,{className:`app__brand-mark`,children:(0,F.jsx)(bs,{size:16})}),`UISandbox `,(0,F.jsx)(`small`,{children:`your app, 1:1, then the knobs`})]}),(0,F.jsx)(`span`,{className:`app__spacer`}),(0,F.jsx)(Es,{}),(0,F.jsx)(`a`,{className:`btn btn--ghost btn--icon`,href:`https://github.com/AlexanderKaan/uisandbox`,target:`_blank`,rel:`noopener`,title:`Source on GitHub`,"aria-label":`Source on GitHub`,children:(0,F.jsx)(xs,{})}),c&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`button`,{type:`button`,className:`btn btn--ghost btn--icon`,onClick:r,disabled:!o,title:`Undo (⌘Z)`,children:(0,F.jsx)(_e,{size:15})}),(0,F.jsx)(`button`,{type:`button`,className:`btn btn--ghost btn--icon`,onClick:i,disabled:!s,title:`Redo (⇧⌘Z)`,children:(0,F.jsx)(de,{size:15})}),(0,F.jsxs)(`button`,{type:`button`,className:`btn btn--ghost btn--sm`,onClick:()=>x(e=>!e),title:`What we read from your code`,children:[(0,F.jsx)(se,{size:14}),` Read`]}),(0,F.jsxs)(`button`,{type:`button`,className:`btn btn--primary btn--sm`,onClick:()=>y(!0),children:[(0,F.jsx)(ie,{size:14}),` Export`]}),(0,F.jsxs)(`button`,{type:`button`,className:`btn btn--ghost btn--sm`,onClick:()=>{Xc(c.project),l(null),a(vn)},title:`Close this project`,children:[(0,F.jsx)(ye,{size:14}),` Close`]})]})]}),(0,F.jsxs)(`div`,{className:`app__body`,children:[c&&(0,F.jsxs)(F.Fragment,{children:[!g&&(0,F.jsx)(`button`,{type:`button`,className:`btn btn--ghost btn--icon`,style:{position:`absolute`,left:8,top:56,zIndex:41},onClick:()=>_(!0),title:`Show the knobs`,children:(0,F.jsx)(le,{size:16})}),g&&(0,F.jsx)(_n,{cfg:e,tokens:t,base:c.report.baseline.cfg,families:c.report.baseline.families,scheme:c.project.scheme,codeFonts:Oc(c.project.table),hasGradients:c.project.table.ofKind(`angle`).length>0,varNow:e=>O[oo(e)],dispatch:n,onCollapse:()=>_(!1),onRandomize:()=>n({type:`REPLACE`,cfg:ir(e,c.report.baseline)}),onReset:()=>n({type:`REPLACE`,cfg:c.report.baseline.cfg})}),(0,F.jsx)(bl,{project:c.project,screen:c.screen,onScreen:e=>l({...c,screen:e}),frameRef:T,onLoaded:Se,onPin:j,changedCount:k,warning:fe??(me.length?`${me.length===1?`A file`:`${me.length} files`} this page asked for ${me.length===1?`is`:`are`} not in the archive — ${me.slice(0,3).join(`, `)}${me.length>3?`…`:``}. That usually means source, not the built output: parts of the page cannot run here.`:null),coverage:ge,notes:b?(0,F.jsxs)(`div`,{className:`card popcard`,role:`dialog`,"aria-label":`What was read`,children:[(0,F.jsx)(`h3`,{children:`What we read from your code`}),(0,F.jsxs)(`ul`,{className:`notes`,children:[c.report.notes.map((e,t)=>(0,F.jsx)(`li`,{children:e},t)),(0,F.jsxs)(`li`,{children:[c.project.table.entries.length,` distinct values in `,Math.round(c.project.cssBytes/1024),` KB of CSS: `,[`color`,`radius`,`font-size`,`font-family`,`space`,`shadow`,`angle`].map(e=>`${c.project.table.ofKind(e).length} ${e===`angle`?`gradient angle`:e}`).join(` · `),`.`]}),c.project.candidates.length>1&&(0,F.jsxs)(`li`,{children:[`Other roots in the archive:`,` `,c.project.candidates.filter(e=>e!==c.project.root).slice(0,6).map(e=>(0,F.jsx)(`button`,{type:`button`,className:`btn btn--secondary btn--sm`,style:{marginRight:6,marginTop:4},onClick:()=>{let t=c.archive;Xc(c.project),l(null),Ce(t,e)},children:e||`/`},e))]})]}),(0,F.jsx)(`div`,{style:{marginTop:10},children:(0,F.jsx)(`button`,{type:`button`,className:`btn btn--ghost btn--sm`,onClick:()=>x(!1),children:`Close`})})]}):null})]}),!c&&(0,F.jsx)(gl,{onArchive:Ce,onUrl:e=>void Ee(`/__repo/?u=${encodeURIComponent(e)}`),busy:u,error:m}),S&&(0,F.jsxs)(`div`,{className:`consent`,role:`dialog`,"aria-label":`Analytics`,children:[(0,F.jsx)(`span`,{children:`We count visits with Google Analytics — no names, nothing about your files. OK?`}),(0,F.jsx)(`button`,{type:`button`,className:`btn btn--primary btn--sm`,onClick:()=>{Ls(!0),w(!1)},children:`OK`}),(0,F.jsx)(`button`,{type:`button`,className:`btn btn--ghost btn--sm`,onClick:()=>{Ls(!1),w(!1)},children:`No thanks`})]})]}),(0,F.jsx)(Ds,{}),v&&c&&(0,F.jsx)(cu,{cfg:e,table:c.project.table,vars:O,projectName:c.project.name,files:c.project.raw,fontCss:ae,onClose:()=>y(!1)})]})}var uu=document.documentElement;for(let[e,t]of Object.entries(Rn(vn).vars))uu.style.setProperty(e,String(t));Is(),(0,xe.createRoot)(document.getElementById(`root`)).render((0,F.jsx)(C.StrictMode,{children:(0,F.jsx)(lu,{})}));
316
+ `)},[e.fontDisplay,e.fontBody,c]),oe=(0,C.useRef)(ae);oe.current=ae,(0,C.useEffect)(()=>{},[c,e,O,n,ae]),(0,C.useEffect)(()=>{document.title=c?`UISandbox — ${c.project.name}`:`UISandbox — Test your design on the real thing`},[c]);let k=(0,C.useMemo)(()=>{if(!c)return 0;let e=c.project.table.identityVars();return Object.keys(O).filter(t=>O[t]!==e[t]).length},[O,c]),A=(0,C.useCallback)(()=>{let e=T.current?.contentDocument;if(!e)return;for(let n of[e,...nl(e)])t(n);function t(e){let t=e.getElementById(`us-vars`);t||(t=e.createElement(`style`),t.id=`us-vars`,(e.head??e.documentElement).prepend(t));let n=ps(re.current),r=n.slice(n.indexOf(`>`)+1,n.lastIndexOf(`<`));t.textContent!==r&&(t.textContent=r);let i=e.getElementById(`us-fonts`);i||(i=e.createElement(`style`),i.id=`us-fonts`,t.after(i));let a=oe.current;i.textContent!==a&&(i.textContent=a);let o=E.current;if(o)try{ns(e,o.project.scheme,ee.current.sb.dark??null)}catch{}}},[]);(0,C.useEffect)(()=>{A()},[O,ae,e.sb.dark,A]),(0,C.useEffect)(()=>{let t=new URLSearchParams(location.search).get(`sync`);if(!t||!c||!/^(127\.0\.0\.1|localhost)$/.test(location.hostname))return;let n=setTimeout(()=>{fetch(`/__state/${encodeURIComponent(t)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({cfg:e})}).catch(()=>{})},400);return()=>clearTimeout(n)},[e,c]);let ce=(0,C.useCallback)(()=>{let e=E.current,t=T.current?.contentDocument;if(!e||!t||!t.body)return;let n=e.report.baseline.cfg;if(!Object.keys(n).every(e=>ee.current[e]===n[e]))return;let r=Fc(e.project.table,n),i={...n,...r??{}},o=!e.report.brandDeclared&&!e.brandSeen;e.brandSeen=!0;let s=Pc(t,i,{brand:o}),c;try{let e=t.defaultView,n=[e.getComputedStyle(t.body).backgroundColor,e.getComputedStyle(t.documentElement).backgroundColor].find(e=>e&&!/^rgba\(0, 0, 0, 0\)$|^transparent$/.test(e));n&&(c=n)}catch{}let u={...i,...s??{}},d=oc(e.project.table,u.cPrimary,{paintedCanvas:c}),f=d.canvasId!==e.report.baseline.families?.canvasId;!r&&!s&&!f||(e.report.baseline={cfg:u,tokens:Rn(u),families:d},r&&e.report.notes.push(`Corrected from rules your JS inserted at runtime: ${Object.entries(r).map(([e,t])=>`${e} ${t}`).join(`, `)}.`),s&&e.report.notes.push(`Corrected from the rendered page: ${Object.entries(s).map(([e,t])=>`${e} ${t}`).join(`, `)}.`),a(u),l({...e}))},[a]),ue=(0,C.useCallback)(()=>{let e=E.current,t=T.current?.contentDocument;if(!e||!t?.body)return;let n=vs(t,e.project.screens);n.length&&(e.project.screens=[...e.project.screens,...n],l({...e}))},[]),j=(0,C.useCallback)(()=>{let e=E.current,t=T.current?.contentWindow;if(!e||!t)return;let n=t.location.pathname.replace(/^\/__sb\/[^/]+\//,`/`).replace(/\/+$/,``)||`/`;e.project.base&&n.startsWith(`/`+e.project.base)&&(n=n.slice(e.project.base.length+1)||`/`),!e.project.screens.some(e=>e.label===n)&&(e.project.screens=[...e.project.screens,{path:n.replace(/^\//,``),label:n,source:`pinned`}],l({...e}))},[]),[fe,pe]=(0,C.useState)(null),[me,he]=(0,C.useState)([]);(0,C.useEffect)(()=>Bc(e=>{E.current?.project.id===e.id&&he(Vc(e))}),[]),(0,C.useEffect)(()=>{he(c?Vc(c.project):[])},[c]);let[ge,ve]=(0,C.useState)(null),be=(0,C.useRef)(null),xe=(0,C.useCallback)(()=>{be.current&&clearTimeout(be.current),be.current=setTimeout(()=>{let e=E.current,t=T.current?.contentDocument;if(!(!e||!t?.body))try{ve(dl(t,e.project.table,re.current))}catch{}},900)},[]),Se=(0,C.useCallback)(()=>{A(),ne.current?.();let e=T.current?.contentDocument;if(e?.body){let t=()=>{let t=[e,...nl(e)],n=t.reduce((e,t)=>e+t.body.querySelectorAll(`*`).length,0),r=t.reduce((e,t)=>e+Array.from(t.styleSheets).reduce((e,t)=>{try{return e+t.cssRules.length}catch{return e}},0),0),i=t.reduce((e,t)=>e+(t.body.innerText??``).trim().length,0);return{shell:t.reduce((e,t)=>e+t.body.querySelectorAll(`img, svg, canvas, video, picture`).length,0)===0&&(n<6||r<3||i<20&&n<40),els:n,rules:r,text:i}};setTimeout(()=>{if(!t().shell){pe(null);return}setTimeout(()=>{let e=t();pe(e.shell?`This screen rendered ${e.els} element${e.els===1?``:`s`}, ${e.rules} style rules and ${e.text} characters of visible text — it looks like a shell, not the app (a page the server fills in, a build that needs its API, or a folder without its CSS). What you see here is not what your users see.`:null)},2800)},1200)}e&&c&&(ne.current=$c(e,c.project.table,()=>{te(e=>e+1),ce(),xe()})),ce(),ue(),xe(),setTimeout(ue,800)},[A,c,ce,ue,xe]);(0,C.useEffect)(()=>()=>{ne.current?.()},[]),(0,C.useEffect)(()=>{let e=null;return Hc(()=>{e&&clearTimeout(e),e=setTimeout(()=>{te(e=>e+1),ce()},80)})},[ce]);let Ce=async(e,t)=>{h(null),Rs(`drop`),u||(f.current=!1);try{p({stage:`read`,done:0,total:e.entries.length,bytes:0,what:e.rootName}),await Jc();let n=0,r=await fs(e,{root:t,onProgress:(t,r,i)=>{let a=Date.now();(a-n>120||t===r)&&(n=a,p({stage:`read`,done:t,total:r,bytes:i,what:e.rootName}))}});if(!r.platform.renders||!r.screens.length)throw Error(Zo(r.platform,{files:e.entries.length}));p({stage:`derive`,total:r.table.entries.length,what:e.rootName});let i=await Mc(e,r.table);p({stage:`open`,what:e.rootName}),c&&Xc(c.project),Yc(r,()=>re.current),a(i.baseline.cfg);let o=new URLSearchParams(location.search).get(`screen`),s=o&&r.screens.find(e=>e.path===o||e.label===o)||r.screens[0];l({project:r,report:i,screen:s,archive:e}),x(!0),Rs(`loaded`,{screens:r.screens.length,values:r.table.entries.length})}catch(e){h(e.message),Rs(`refused`)}finally{p(null)}},M=(0,C.useRef)(!1),Ee=async e=>{h(null),f.current=!0;try{let t=(()=>{try{let t=new URL(e,location.href);return t.pathname.startsWith(`/__repo/`)?new URL(t.searchParams.get(`u`)??``,location.href).host||`github.com`:t.host}catch{return e}})();p({stage:`fetch`,what:t,bytes:0});let n=await fetch(e);if(!n.ok)throw Error(n.status===404?`Nothing at ${t} for that URL (${n.status}).`:`${n.status} fetching from ${t}.`);let r=Number(n.headers.get(`content-length`)||0)||void 0,i=[],a=0,o=n.body?.getReader();if(o)for(;;){let{done:e,value:n}=await o.read();if(e)break;i.push(n),a+=n.byteLength,p({stage:`fetch`,what:t,bytes:a,size:r})}let s=o?new Blob(i):await n.blob(),c=decodeURIComponent(n.headers.get(`content-disposition`)?.match(/filename="?([^";]+)"?/)?.[1]||e.split(`/`).pop()||`archive.zip`);await Ce(await no(new File([s],c.endsWith(`.zip`)?c:`${c}.zip`,{type:`application/zip`})))}catch(e){h(e.message),p(null)}};return(0,C.useEffect)(()=>{if(M.current)return;let e=new URLSearchParams(location.search).get(`load`);if(!e)return;M.current=!0;let t=e.match(/^(?:https?:\/\/)?(?:www\.)?github\.com\/[\w.-]+\/[\w.-]+/i)&&!/\.zip($|\?)/i.test(e)&&!/\/archive\//i.test(e);Ee(t?`/__repo/?u=${encodeURIComponent(e.startsWith(`http`)?e:`https://${e}`)}`:e)},[]),(0,C.useEffect)(()=>{let e=e=>{!(e.metaKey||e.ctrlKey)||e.key.toLowerCase()!==`z`||(e.preventDefault(),e.shiftKey?i():r())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,i]),(0,F.jsxs)(`div`,{className:`app`,children:[(0,F.jsxs)(`header`,{className:`app__topbar`,children:[(0,F.jsxs)(`span`,{className:`app__brand`,children:[(0,F.jsx)(`span`,{className:`app__brand-mark`,children:(0,F.jsx)(bs,{size:16})}),`UISandbox `,(0,F.jsx)(`small`,{children:`your app, 1:1, then the knobs`})]}),(0,F.jsx)(`span`,{className:`app__spacer`}),(0,F.jsx)(Es,{}),(0,F.jsx)(`a`,{className:`btn btn--ghost btn--icon`,href:`https://github.com/AlexanderKaan/uisandbox`,target:`_blank`,rel:`noopener`,title:`Source on GitHub`,"aria-label":`Source on GitHub`,children:(0,F.jsx)(xs,{})}),c&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`button`,{type:`button`,className:`btn btn--ghost btn--icon`,onClick:r,disabled:!o,title:`Undo (⌘Z)`,children:(0,F.jsx)(_e,{size:15})}),(0,F.jsx)(`button`,{type:`button`,className:`btn btn--ghost btn--icon`,onClick:i,disabled:!s,title:`Redo (⇧⌘Z)`,children:(0,F.jsx)(de,{size:15})}),(0,F.jsxs)(`button`,{type:`button`,className:`btn btn--ghost btn--sm`,onClick:()=>x(e=>!e),title:`What we read from your code`,children:[(0,F.jsx)(se,{size:14}),` Read`]}),(0,F.jsxs)(`button`,{type:`button`,className:`btn btn--primary btn--sm`,onClick:()=>y(!0),children:[(0,F.jsx)(ie,{size:14}),` Export`]}),(0,F.jsxs)(`button`,{type:`button`,className:`btn btn--ghost btn--sm`,onClick:()=>{Xc(c.project),l(null),a(vn)},title:`Close this project`,children:[(0,F.jsx)(ye,{size:14}),` Close`]})]})]}),(0,F.jsxs)(`div`,{className:`app__body`,children:[c&&(0,F.jsxs)(F.Fragment,{children:[!g&&(0,F.jsx)(`button`,{type:`button`,className:`btn btn--ghost btn--icon`,style:{position:`absolute`,left:8,top:56,zIndex:41},onClick:()=>_(!0),title:`Show the knobs`,children:(0,F.jsx)(le,{size:16})}),g&&(0,F.jsx)(_n,{cfg:e,tokens:t,base:c.report.baseline.cfg,families:c.report.baseline.families,scheme:c.project.scheme,codeFonts:Oc(c.project.table),hasGradients:c.project.table.ofKind(`angle`).length>0,varNow:e=>O[oo(e)],dispatch:n,onCollapse:()=>_(!1),onRandomize:()=>n({type:`REPLACE`,cfg:ir(e,c.report.baseline)}),onReset:()=>n({type:`REPLACE`,cfg:c.report.baseline.cfg})}),(0,F.jsx)(bl,{project:c.project,screen:c.screen,onScreen:e=>l({...c,screen:e}),frameRef:T,onLoaded:Se,onPin:j,changedCount:k,warning:fe??(me.length?`${me.length===1?`A file`:`${me.length} files`} this page asked for ${me.length===1?`is`:`are`} not in the archive — ${me.slice(0,3).join(`, `)}${me.length>3?`…`:``}. That usually means source, not the built output: parts of the page cannot run here.`:null),coverage:ge,notes:b?(0,F.jsxs)(`div`,{className:`card popcard`,role:`dialog`,"aria-label":`What was read`,children:[(0,F.jsx)(`h3`,{children:`What we read from your code`}),(0,F.jsxs)(`ul`,{className:`notes`,children:[c.report.notes.map((e,t)=>(0,F.jsx)(`li`,{children:e},t)),(0,F.jsxs)(`li`,{children:[c.project.table.entries.length,` distinct values in `,Math.round(c.project.cssBytes/1024),` KB of CSS: `,[`color`,`radius`,`font-size`,`font-family`,`space`,`shadow`,`angle`].map(e=>`${c.project.table.ofKind(e).length} ${e===`angle`?`gradient angle`:e}`).join(` · `),`.`]}),c.project.candidates.length>1&&(0,F.jsxs)(`li`,{children:[`Other roots in the archive:`,` `,c.project.candidates.filter(e=>e!==c.project.root).slice(0,6).map(e=>(0,F.jsx)(`button`,{type:`button`,className:`btn btn--secondary btn--sm`,style:{marginRight:6,marginTop:4},onClick:()=>{let t=c.archive;Xc(c.project),l(null),Ce(t,e)},children:e||`/`},e))]})]}),(0,F.jsx)(`div`,{style:{marginTop:10},children:(0,F.jsx)(`button`,{type:`button`,className:`btn btn--ghost btn--sm`,onClick:()=>x(!1),children:`Close`})})]}):null})]}),!c&&(0,F.jsx)(gl,{onArchive:Ce,onUrl:e=>void Ee(`/__repo/?u=${encodeURIComponent(e)}`),busy:u,error:m}),S&&(0,F.jsxs)(`div`,{className:`consent`,role:`dialog`,"aria-label":`Analytics`,children:[(0,F.jsx)(`span`,{children:`We count visits with Google Analytics — no names, nothing about your files. OK?`}),(0,F.jsx)(`button`,{type:`button`,className:`btn btn--primary btn--sm`,onClick:()=>{Ls(!0),w(!1)},children:`OK`}),(0,F.jsx)(`button`,{type:`button`,className:`btn btn--ghost btn--sm`,onClick:()=>{Ls(!1),w(!1)},children:`No thanks`})]})]}),(0,F.jsx)(Ds,{}),v&&c&&(0,F.jsx)(cu,{cfg:e,table:c.project.table,vars:O,projectName:c.project.name,files:c.project.raw,fontCss:ae,onClose:()=>y(!1)})]})}var uu=document.documentElement;for(let[e,t]of Object.entries(Rn(vn).vars))uu.style.setProperty(e,String(t));Is(),(0,xe.createRoot)(document.getElementById(`root`)).render((0,F.jsx)(C.StrictMode,{children:(0,F.jsx)(lu,{})}));
@@ -58,7 +58,7 @@
58
58
  </script>
59
59
  <link rel="preconnect" href="https://fonts.googleapis.com" />
60
60
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet" />
61
- <script type="module" crossorigin src="/assets/index-BAi4QoSo.js"></script>
61
+ <script type="module" crossorigin src="/assets/index-v-2SQjGH.js"></script>
62
62
  <link rel="stylesheet" crossorigin href="/assets/index-DgIoYtvB.css">
63
63
  </head>
64
64
  <body>
@@ -25,7 +25,8 @@ Site: https://uisandbox.org/ · Source: https://github.com/AlexanderKaan/uisandb
25
25
 
26
26
  ## For agents
27
27
 
28
- - Load: `https://uisandbox.org/?load=https://example.com/build.zip` (the URL must allow CORS or be same-origin).
28
+ - Load by link — any agent can say this to a user: `https://uisandbox.org/?load=https://github.com/user/repo` (a public repo; its default branch — or `/tree/branch` — is fetched as a zip through the site's own route; the build must be inside the repo, e.g. a gh-pages branch), or `?load=<zip-url>` for a zip the browser may fetch (CORS).
29
+ - In Claude Code / Claude Desktop / Cursor with the MCP server: say "open this app in UISandbox" — the agent builds the app, loads it and opens the real sandbox in the browser (`open`), and can export what you turned afterwards (`state` → `export`). Prompts `/uisandbox:open` and `/uisandbox:try` exist where the client shows MCP prompts.
29
30
  - MCP server (stdio, same engine): tools `open` (the real sandbox in the user's browser, served locally), `state`, `load` (zip URL/path), `screens`, `set` (knobs), `export` (sheet-css, sheet-json, patch, tokens-css, tokens-json, tailwind, shadcn, swift, android-xml, android-kotlin), `verify` (the 1:1 check in headless Chromium), `screenshot`. Install: `npx -y uisandbox-mcp` (npm: https://www.npmjs.com/package/uisandbox-mcp); config and a prompt to paste: https://github.com/AlexanderKaan/uisandbox/blob/main/mcp/README.md
30
31
 
31
32
  ## More
package/dist/app/llms.txt CHANGED
@@ -25,7 +25,8 @@ Site: https://uisandbox.org/ · Source: https://github.com/AlexanderKaan/uisandb
25
25
 
26
26
  ## For agents
27
27
 
28
- - Load: `https://uisandbox.org/?load=https://example.com/build.zip` (the URL must allow CORS or be same-origin).
28
+ - Load by link — any agent can say this to a user: `https://uisandbox.org/?load=https://github.com/user/repo` (a public repo; its default branch — or `/tree/branch` — is fetched as a zip through the site's own route; the build must be inside the repo, e.g. a gh-pages branch), or `?load=<zip-url>` for a zip the browser may fetch (CORS).
29
+ - In Claude Code / Claude Desktop / Cursor with the MCP server: say "open this app in UISandbox" — the agent builds the app, loads it and opens the real sandbox in the browser (`open`), and can export what you turned afterwards (`state` → `export`). Prompts `/uisandbox:open` and `/uisandbox:try` exist where the client shows MCP prompts.
29
30
  - MCP server (stdio, same engine): tools `open` (the real sandbox in the user's browser, served locally), `state`, `load` (zip URL/path), `screens`, `set` (knobs), `export` (sheet-css, sheet-json, patch, tokens-css, tokens-json, tailwind, shadcn, swift, android-xml, android-kotlin), `verify` (the 1:1 check in headless Chromium), `screenshot`. Install: `npx -y uisandbox-mcp` (npm: https://www.npmjs.com/package/uisandbox-mcp); config and a prompt to paste: https://github.com/AlexanderKaan/uisandbox/blob/main/mcp/README.md
30
31
 
31
32
  ## More
package/dist/server.mjs CHANGED
@@ -2,8 +2,8 @@
2
2
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
4
  import { z } from "zod";
5
- import { existsSync, readFileSync, statSync } from "node:fs";
6
- import { basename, dirname, extname, join } from "node:path";
5
+ import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
6
+ import { basename, dirname, extname, join, relative } from "node:path";
7
7
  import { createServer } from "node:http";
8
8
  import { fileURLToPath } from "node:url";
9
9
  import { spawn } from "node:child_process";
@@ -23,6 +23,15 @@ var __esmMin = (fn, res, err) => () => {
23
23
  }
24
24
  };
25
25
  var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
26
+ var __exportAll = (all, no_symbols) => {
27
+ let target = {};
28
+ for (var name in all) __defProp(target, name, {
29
+ get: all[name],
30
+ enumerable: true
31
+ });
32
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
33
+ return target;
34
+ };
26
35
  var __copyProps = (to, from, except, desc) => {
27
36
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
28
37
  key = keys[i];
@@ -8924,6 +8933,96 @@ ${rows(dark).join("\n")}
8924
8933
  `;
8925
8934
  }
8926
8935
  //#endregion
8936
+ //#region mcp/zipdir.ts
8937
+ /** A folder → a zip (stored, no compression) in memory, for the CLI. */
8938
+ var zipdir_exports = /* @__PURE__ */ __exportAll({ zipFolder: () => zipFolder });
8939
+ async function zipFolder(dir) {
8940
+ const files = [];
8941
+ const walk = (d) => {
8942
+ for (const e of readdirSync(d)) {
8943
+ if (e === "node_modules" || e === ".git") continue;
8944
+ const f = join(d, e);
8945
+ if (statSync(f).isDirectory()) walk(f);
8946
+ else files.push(f);
8947
+ }
8948
+ };
8949
+ walk(dir);
8950
+ const enc = new TextEncoder();
8951
+ const locals = [], centrals = [];
8952
+ let offset = 0;
8953
+ for (const f of files) {
8954
+ const data = new Uint8Array(readFileSync(f));
8955
+ const name = enc.encode(relative(dir, f).split("\\").join("/"));
8956
+ const crc = crc32(data);
8957
+ const local = new Uint8Array(30 + name.length + data.length);
8958
+ const lv = new DataView(local.buffer);
8959
+ lv.setUint32(0, 67324752, true);
8960
+ lv.setUint16(4, 20, true);
8961
+ lv.setUint16(6, 2048, true);
8962
+ lv.setUint16(8, 0, true);
8963
+ lv.setUint32(14, crc, true);
8964
+ lv.setUint32(18, data.length, true);
8965
+ lv.setUint32(22, data.length, true);
8966
+ lv.setUint16(26, name.length, true);
8967
+ local.set(name, 30);
8968
+ local.set(data, 30 + name.length);
8969
+ const central = new Uint8Array(46 + name.length);
8970
+ const cv = new DataView(central.buffer);
8971
+ cv.setUint32(0, 33639248, true);
8972
+ cv.setUint16(4, 20, true);
8973
+ cv.setUint16(6, 20, true);
8974
+ cv.setUint16(8, 2048, true);
8975
+ cv.setUint16(10, 0, true);
8976
+ cv.setUint32(16, crc, true);
8977
+ cv.setUint32(20, data.length, true);
8978
+ cv.setUint32(24, data.length, true);
8979
+ cv.setUint16(28, name.length, true);
8980
+ cv.setUint32(42, offset, true);
8981
+ central.set(name, 46);
8982
+ locals.push(local);
8983
+ centrals.push(central);
8984
+ offset += local.length;
8985
+ }
8986
+ const cdSize = centrals.reduce((n, c) => n + c.length, 0);
8987
+ const end = /* @__PURE__ */ new Uint8Array(22);
8988
+ const ev = new DataView(end.buffer);
8989
+ ev.setUint32(0, 101010256, true);
8990
+ ev.setUint16(8, files.length, true);
8991
+ ev.setUint16(10, files.length, true);
8992
+ ev.setUint32(12, cdSize, true);
8993
+ ev.setUint32(16, offset, true);
8994
+ const total = offset + cdSize + 22;
8995
+ const out = new Uint8Array(new ArrayBuffer(total));
8996
+ let p = 0;
8997
+ for (const l of locals) {
8998
+ out.set(l, p);
8999
+ p += l.length;
9000
+ }
9001
+ for (const c of centrals) {
9002
+ out.set(c, p);
9003
+ p += c.length;
9004
+ }
9005
+ out.set(end, p);
9006
+ return out;
9007
+ }
9008
+ var crcTable, crc32;
9009
+ var init_zipdir = __esmMin((() => {
9010
+ crcTable = (() => {
9011
+ const t = /* @__PURE__ */ new Uint32Array(256);
9012
+ for (let n = 0; n < 256; n++) {
9013
+ let c = n;
9014
+ for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
9015
+ t[n] = c >>> 0;
9016
+ }
9017
+ return t;
9018
+ })();
9019
+ crc32 = (b) => {
9020
+ let c = 4294967295;
9021
+ for (let i = 0; i < b.length; i++) c = crcTable[(c ^ b[i]) & 255] ^ c >>> 8;
9022
+ return (c ^ 4294967295) >>> 0;
9023
+ };
9024
+ }));
9025
+ //#endregion
8927
9026
  //#region mcp/server.ts
8928
9027
  /**
8929
9028
  * UISandbox as an MCP server — the same engine the browser runs, no second
@@ -9005,8 +9104,15 @@ var summarise = (p) => {
9005
9104
  };
9006
9105
  var server = new McpServer({
9007
9106
  name: "uisandbox",
9008
- version: "0.1.0"
9009
- });
9107
+ version: "0.3.0"
9108
+ }, { instructions: `UISandbox renders a BUILT web app 1:1 in a sandbox and turns every CSS literal into a knob that moves the app's own value; "1:1" is measured (a computed-style diff), not promised.
9109
+
9110
+ When to use it — and offer it without being asked:
9111
+ - The user wants to LOOK at an app in a sandbox or PLAY with its design ("can I see this in a sandbox", "let me try some changes", "what would a different brand colour look like"): build the app if you are in its repo (npm run build / vite build / nuxi generate / next build with output: 'export'), zip the output folder (dist/, build/, out/ — never node_modules or source), \`load\` it, then \`open\`. The real, interactive sandbox opens in their browser from 127.0.0.1; nothing leaves the machine. Tell them it is open and that whatever they turn comes back here: when they return with "export this" / "what did I change" / "check it", call \`state\`, then \`export\` / \`verify\` / \`screenshot\`.
9112
+ - The user wants ONE change tried ("try brand #e11d48", "rounder corners"): \`load\` → \`set\` → \`verify\` → \`screenshot\` → \`export\` (patch). Offer \`open\` after.
9113
+ - The user is iterating on the look of an app you are working in: offer the sandbox proactively, once.
9114
+
9115
+ Rules: never claim more than \`verify\` and the reach meter report — quote the numbers; if a load is refused (iOS/Android/source-only), relay the reason and suggest building first; \`verify\`/\`screenshot\` need a browser (npx playwright install chromium once) — \`open\`, \`load\`, \`set\`, \`export\` do not.` });
9010
9116
  server.registerTool("load", {
9011
9117
  title: "Load a built web app",
9012
9118
  description: "Load a BUILT web app (a zip of its dist/build/out folder, or a repo zip carrying the build) by URL or local path. Returns the project id, screens, tokenised values and the baseline the knobs stand on. Refuses what cannot render (iOS/Android/source-only) with the reason.",
@@ -9381,6 +9487,67 @@ server.registerTool("screenshot", {
9381
9487
  mimeType: "image/png"
9382
9488
  }] };
9383
9489
  });
9490
+ server.registerPrompt("open", {
9491
+ title: "Open this app in UISandbox",
9492
+ description: "Build the app in the current repo (or use a zip), load it and open the real sandbox in the browser to play with the design.",
9493
+ argsSchema: { zip: z.string().optional().describe("A zip path or URL; omit to build the current repo") }
9494
+ }, ({ zip }) => ({ messages: [{
9495
+ role: "user",
9496
+ content: {
9497
+ type: "text",
9498
+ text: zip ? `Load ${zip} in UISandbox and open the sandbox so I can look at the app and change the design by hand. Tell me when it is open and what you found (screens, brand, families). When I come back, read the state and export what I changed.` : `Open this app in UISandbox: build it first (the framework's build command), zip the output folder (dist/, build/ or out/ — not source), load it and open the sandbox so I can look at it and change the design by hand. Tell me when it is open and what you found (screens, brand, families). When I come back, read the state and export what I changed.`
9499
+ }
9500
+ }] }));
9501
+ server.registerPrompt("try", {
9502
+ title: "Try a design change and verify it",
9503
+ description: "Load a build, apply knobs (brand, radius, fonts, spacing…), verify it is still 1:1, show a screenshot, give the patch.",
9504
+ argsSchema: {
9505
+ zip: z.string().optional().describe("A zip path or URL; omit to build the current repo"),
9506
+ change: z.string().describe("What to try, e.g. \"brand #e11d48 and radius ×1.5\"")
9507
+ }
9508
+ }, ({ zip, change }) => ({ messages: [{
9509
+ role: "user",
9510
+ content: {
9511
+ type: "text",
9512
+ text: `${zip ? `Load ${zip} in UISandbox` : "Build this repo, zip the output and load it in UISandbox"}. Then try: ${change}. Verify it is still 1:1 (quote the numbers and the reach), show me a screenshot, and give me the patch. Offer to open the sandbox afterwards.`
9513
+ }
9514
+ }] }));
9515
+ var argv = process.argv.slice(2);
9516
+ if (argv[0] === "open" && argv[1]) {
9517
+ const target = argv[1];
9518
+ let bytes, name;
9519
+ if (statSync(target).isDirectory()) {
9520
+ const { zipFolder } = await Promise.resolve().then(() => (init_zipdir(), zipdir_exports));
9521
+ bytes = await zipFolder(target);
9522
+ name = basename(target) + ".zip";
9523
+ } else {
9524
+ const b = readFileSync(target);
9525
+ bytes = new Uint8Array(b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength));
9526
+ name = basename(target);
9527
+ }
9528
+ const archive = await openZip(new File([bytes], name.endsWith(".zip") ? name : `${name}.zip`, { type: "application/zip" }));
9529
+ const project = await buildProject(archive);
9530
+ if (!project.platform.renders || !project.screens.length) {
9531
+ console.error(refusalFor(project.platform, { files: archive.entries.length }));
9532
+ process.exit(2);
9533
+ }
9534
+ const report = await deriveBaseline(archive, project.table);
9535
+ const id = "cli";
9536
+ projects.set(id, {
9537
+ id,
9538
+ name: archive.rootName,
9539
+ bytes,
9540
+ project,
9541
+ report,
9542
+ cfg: report.baseline.cfg,
9543
+ archive
9544
+ });
9545
+ const { port } = await localServer();
9546
+ const url = `http://127.0.0.1:${port}/?load=${encodeURIComponent(`/__archive/${id}.zip`)}&sync=${id}`;
9547
+ openInBrowser(url);
9548
+ console.log(`UISandbox is open: ${url}\n${project.screens.length} screens · ${project.table.entries.length} values · brand ${report.baseline.cfg.cPrimary}\nCtrl-C to stop.`);
9549
+ await new Promise(() => {});
9550
+ }
9384
9551
  var transport = new StdioServerTransport();
9385
9552
  await server.connect(transport);
9386
9553
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uisandbox-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "UISandbox as an MCP server: open the real sandbox in your browser with your built web app loaded, turn its own knobs, verify 1:1, export CSS/patch/tokens/Swift/Android. Test your design on the real thing.",
5
5
  "type": "module",
6
6
  "bin": {