brane 0.3.2 → 0.3.3

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.
@@ -4,11 +4,11 @@ var __BUNDLE_START_TIME__=globalThis.nativePerformanceNow?nativePerformanceNow()
4
4
  'undefined'!=typeof globalThis?globalThis:'undefined'!=typeof global?global:'undefined'!=typeof window&&window;
5
5
  !(function(r){let l=0,n=!0===r.RN$useAlwaysAvailableJSErrorHandling?r.RN$handleException:(r,l)=>{throw r};const t={setGlobalHandler(r){n=r},getGlobalHandler:()=>n,reportError(r){n&&n(r,!1)},reportFatalError(r){n&&n(r,!0)},applyWithGuard(r,n,e,a,o){try{return l++,r.apply(n,e)}catch(r){t.reportError(r)}finally{l--}return null},applyWithGuardIfNeeded:(r,l,n)=>t.inGuard()?r.apply(l,n):(t.applyWithGuard(r,l,n),null),inGuard:()=>!!l,guard(r,l,n){if('function'!=typeof r)return console.warn('A function must be passed to ErrorUtils.guard, got ',r),null;const e=l??r.name??'<generated guard>';return function(...l){return t.applyWithGuard(r,n??this,l,null,e)}}};r.ErrorUtils=t})('undefined'!=typeof globalThis?globalThis:'undefined'!=typeof global?global:'undefined'!=typeof window?window:this);
6
6
  __d(function(g,r,i,a,m,e,d){"use strict";r(d[0])},0,[1]);
7
- __d(function(g,r,i,a,m,e,d){"use strict";r(d[0]);var n=r(d[1]);(0,r(d[2]).renderRootComponent)(n.App)},1,[2,5,993]);
7
+ __d(function(g,r,i,a,m,e,d){"use strict";r(d[0]);var n=r(d[1]);(0,r(d[2]).renderRootComponent)(n.App)},1,[2,5,994]);
8
8
  __d(function(g,r,i,a,m,e,d){"use strict";r(d[0]),r(d[1])},2,[3,4]);
9
9
  __d(function(g,r,i,a,m,e,d){},3,[]);
10
10
  __d(function(g,r,i,a,m,e,d){const _='undefined'==typeof window;globalThis.__webpack_chunk_load__=_=>g[`${__METRO_GLOBAL_PREFIX__}__loadBundleAsync`](_),globalThis.__webpack_require__=o=>{const t=ErrorUtils.reportFatalError;_&&(ErrorUtils.reportFatalError=_=>{throw _});try{return g[`${__METRO_GLOBAL_PREFIX__}__r`](o)}finally{_&&(ErrorUtils.reportFatalError=t)}}},4,[]);
11
- __d(function(g,r,i,a,m,e,d){"use strict";var t=r(d[0]),o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.App=function(){return t.jsx(c.Head.Provider,{children:t.jsx(u.ExpoRoot,{context:n.ctx})})};const n=r(d[1]),u=(o(r(d[2])),r(d[3])),c=r(d[4]);r(d[5])},5,[6,8,11,712,991,992]);
11
+ __d(function(g,r,i,a,m,e,d){"use strict";var t=r(d[0]),o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.App=function(){return t.jsx(c.Head.Provider,{children:t.jsx(u.ExpoRoot,{context:n.ctx})})};const n=r(d[1]),u=(o(r(d[2])),r(d[3])),c=r(d[4]);r(d[5])},5,[6,8,11,712,992,993]);
12
12
  __d(function(g,r,i,a,m,e,d){'use strict';m.exports=r(d[0])},6,[7]);
13
13
  __d(function(g,r,i,a,m,e,d){
14
14
  /**
@@ -23,7 +23,7 @@ __d(function(g,r,i,a,m,e,d){
23
23
  "use strict";var n=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function o(t,o,f){var l=null;if(void 0!==f&&(l=""+f),void 0!==o.key&&(l=""+o.key),"key"in o)for(var y in f={},o)"key"!==y&&(f[y]=o[y]);else f=o;return o=f.ref,{$$typeof:n,type:t,key:l,ref:void 0!==o?o:null,props:f}}e.Fragment=t,e.jsx=o,e.jsxs=o},7,[]);
24
24
  __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"ctx",{enumerable:!0,get:function(){return t}});const t=r(d[0])},8,[9]);
25
25
  __d(function(g,r,i,a,m,e,d){const t=Object.defineProperties({},{"./[nid].tsx":{enumerable:!0,get:()=>r(d[0])},"./_layout.tsx":{enumerable:!0,get:()=>r(d[1])},"./index.tsx":{enumerable:!0,get:()=>r(d[2])}});function n(n){return t[n]}n.keys=function(){return Object.keys(t)},n.resolve=function(t){throw new Error('Unimplemented Metro module context functionality')},m.exports=n},9,[10,736,981]);
26
- __d(function(g,r,_i,_a,_m,_e,_d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return se}});var t=r(_d[0]),n=e(r(_d[1])),o=e(r(_d[2])),a=e(r(_d[3])),s=e(r(_d[4]));r(_d[5]);var l=e(r(_d[6])),i=e(r(_d[7])),c=e(r(_d[8])),u=e(r(_d[9]));r(_d[10]);var d=r(_d[11]),f=r(_d[12]),h=r(_d[13]),b=r(_d[14]),m=e(r(_d[15])),p=e(r(_d[16])),y=e(r(_d[17])),v=r(_d[18]),x=r(_d[19]),w=r(_d[20]),S=r(_d[21]),C=r(_d[22]),T=r(_d[23]),j=r(_d[24]),R=e(r(_d[25])),k=r(_d[26]),P=r(_d[27]),A=r(_d[28]),I=r(_d[29]),E=e(I),_=e(r(_d[30])),L=e(r(_d[31])),M=e(r(_d[32])),N=r(_d[33]),z=r(_d[34]),q=r(_d[35]),$=r(_d[36]),F=r(_d[37]),B=r(_d[38]),H=r(_d[39]),O=r(_d[40]);function D(e,t=!1){const n=new Date(e),o=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][n.getDay()],a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][n.getMonth()],s=n.getDate(),l=n.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"});if(t)return`${o} ${a} ${s}, ${n.getFullYear()} ${l}`;const i=new Date,c=n.getFullYear()===i.getFullYear();return c&&n.getMonth()===i.getMonth()&&n.getDate()===i.getDate()?`${o} ${l}`:c?`${o} ${a} ${s} ${l}`:`${o} ${a} ${s}, ${n.getFullYear()} ${l}`}function W(e){return"agent_signal"===e}const G=(0,t.memo)(function({uri:e,onPress:n}){const[o,s]=(0,t.useState)(null);(0,t.useEffect)(()=>{a.default.getSize(e,(e,t)=>s({w:e,h:t}),()=>s({w:200,h:150}))},[e]);const i=o?Math.min(200/o.w,150/o.h):1,c=o?Math.round(o.w*i):200,u=o?Math.round(o.h*i):150;return(0,O.jsx)(l.default,{onPress:n,children:(0,O.jsx)(a.default,{source:{uri:e},style:{width:c,height:u,borderRadius:8},resizeMode:"cover"})})}),X=(0,t.memo)(function({item:e,nid:t,agentType:a,foldPath:s,conn:i,selection:c,palette:u=0,onImagePress:d,onForeignPress:f,onFilePress:h,fileHref:m,onTimestampPress:p}){const y=(0,w.useIsSelected)(c,e.seq),v="human_signal"===e.type;const x=W(e.type),C=(0,z.isSystemEvent)(e.type),T=i&&e.payloads?e.payloads.filter(b.isInlinePayload):[],j=i&&e.payloads?e.payloads.filter(e=>!(0,b.isInlinePayload)(e)):[],R=(0,O.jsxs)(O.Fragment,{children:[(e.source||C)&&(0,O.jsxs)(n.default,{style:le.bubbleSourceRow,children:[x&&e.source&&(0,O.jsx)(l.default,{onPress:()=>f?.(e.source,e.time),style:le.bubbleSourcePress,children:(0,O.jsx)(o.default,{style:[le.bubbleSource,le.bubbleSourceLink,{color:(0,S.speakerColor)(e.source,u)}],children:e.source})}),(0,O.jsx)(l.default,{onPress:()=>p?.(e.seq),style:[le.bubbleSourcePress,x&&le.bubbleSourceAfterLink],children:(0,O.jsx)(o.default,{style:[le.bubbleSource,x&&e.source&&{color:(0,S.speakerColor)(e.source,u)},C&&le.bubbleSourceSystem],children:C?`system (${t}:${e.seq})`:v?`you (${t}:${e.seq})`:x?`(${t}:${e.seq})`:`${e.source}:${e.seq}`})}),(0,O.jsx)(L.default,{text:`${t}:${e.seq}`,size:9,padding:3,marginLeft:1,translateY:-1})]}),e.content?(0,O.jsx)(k.MarkdownContent,{content:C?(0,z.systemLine)({type:e.type,content:e.content},{agent:a??(0,z.agentTypeOf)(t),fold:s}):e.content,foreign:x,system:C,onFilePress:h,fileHref:m}):null,T.length>0&&i&&(0,O.jsx)(n.default,{style:le.payloadsContainer,children:T.map(e=>(0,O.jsx)(G,{uri:(0,b.payloadUrl)(i,e),onPress:()=>d?.((0,b.payloadUrl)(i,e))},e))}),j.length>0&&i&&(0,O.jsx)(n.default,{style:le.payloadsContainer,children:j.map(e=>{const t=(0,A.downloadNameFor)(e),n=(0,b.payloadUrl)(i,e);return(0,O.jsx)(l.default,{onPress:()=>{"undefined"!=typeof window&&(0,A.downloadUrl)(n,t).catch(e=>console.error("Payload download failed:",e))},style:le.filePayload,children:(0,O.jsx)(o.default,{style:le.filePayloadText,children:t})},e)})}),(0,O.jsx)(l.default,{onPress:()=>p?.(e.seq),style:le.bubbleTimePress,children:(0,O.jsx)(o.default,{style:le.bubbleTime,children:D(e.time)})})]}),P=[le.bubble,C?le.bubbleSystem:v?le.bubbleOperator:x?[le.bubbleForeign,{backgroundColor:(0,S.speakerBgColor)(e.source||"unknown",u)}]:le.bubbleAgent,y&&le.bubbleSelected];return(0,O.jsx)(n.default,{style:[le.bubbleRow,v?le.bubbleRowRight:x||C?le.bubbleRowCenter:le.bubbleRowLeft],children:(0,O.jsx)(n.default,{dataSet:{bubble:String(e.seq)},style:P,children:R})})}),U=(0,t.memo)(function({conn:e,nid:s,loadEvents:i,chatActive:c,selection:u,onDeselect:d}){const h=(0,w.useSelectedSeqs)(u),[m,p]=(0,t.useState)(!1),[y,v]=(0,t.useState)(!1),[x,S]=(0,t.useState)([]),C=(0,t.useRef)(null),T=(0,t.useRef)(null),j=(0,t.useRef)(!1),R=(0,t.useRef)(!1),k=(0,f.useIsFocused)(),P=c&&k;R.current=P;const A=(0,t.useRef)(""),I=(0,t.useRef)(null),E=`brane:draft:${s}`;(0,t.useEffect)(()=>{try{const e=localStorage.getItem(E);if(e&&(A.current=e,v(e.trim().length>0),T.current)){T.current.value=e}}catch{}return()=>{I.current&&clearTimeout(I.current);try{const e=A.current;e.trim()?localStorage.setItem(E,e):localStorage.removeItem(E)}catch{}}},[E]);const _=(0,t.useCallback)(e=>{A.current=e;const t=0===e.trim().length;v(e=>e===!t?e:!t),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{try{e.trim()?localStorage.setItem(E,e):localStorage.removeItem(E)}catch{}},300)},[E]);(0,t.useEffect)(()=>{const e=T.current;if(!e)return;if(!P)return void(document.activeElement===e&&e.blur());if(!window.matchMedia?.("(pointer: fine)").matches)return;const t=requestAnimationFrame(()=>{try{e.focus({preventScroll:!0})}catch{e.focus()}});return()=>cancelAnimationFrame(t)},[P]),(0,t.useEffect)(()=>{if(!P)return;const e=e=>{if(!R.current)return;const t=e.target,n=t?.tagName;if("INPUT"===n||"TEXTAREA"===n||t?.isContentEditable)return;if(e.metaKey||e.ctrlKey||e.altKey)return;if(e.isComposing)return;if(1!==e.key.length)return;const o=T.current;if(!o)return;e.preventDefault();const a=(o.value||"")+e.key;o.value=a,o.focus({preventScroll:!0});try{o.setSelectionRange(a.length,a.length)}catch{}_(a)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[P,_]),(0,t.useEffect)(()=>{if(!k)return;const e=e=>{const t=e.clipboardData?.items;if(t)for(const e of Array.from(t)){if(!e.type.startsWith("image/"))continue;const t=e.getAsFile();if(!t)continue;const n=new FileReader;n.onload=()=>{const e=n.result,o=e.split(",")[1],a=t.type.split("/")[1]||"png";S(t=>[...t,{id:`${Date.now()}_${Math.random().toString(36).slice(2,6)}`,filename:`paste_${Date.now()}.${a}`,data:o,uri:e}])},n.readAsDataURL(t)}};return document.addEventListener("paste",e),()=>document.removeEventListener("paste",e)},[k]);const L=(0,t.useCallback)(()=>{if(!C.current){const e=document.createElement("input");e.type="file",e.accept="*/*",e.multiple=!0,e.style.display="none",e.addEventListener("change",()=>{const t=e.files;if(t){for(const e of Array.from(t)){const t=new FileReader;t.onload=()=>{const n=t.result,o=n.split(",")[1];S(t=>[...t,{id:String(Date.now())+e.name,filename:e.name,data:o,uri:n}])},t.readAsDataURL(e)}e.value=""}}),document.body.appendChild(e),C.current=e}C.current.click()},[]);(0,t.useEffect)(()=>()=>{C.current&&(C.current.remove(),C.current=null)},[]);const M=(0,t.useCallback)(e=>{S(t=>t.filter(t=>t.id!==e))},[]),N=(0,t.useCallback)(async()=>{const t=A.current.trim();if(!e||!s||!t&&0===x.length)return;const n=x.length>0?x.map(e=>({filename:e.filename,data:e.data})):void 0;p(!0),S([]);try{await(0,b.sendSignal)(e,s,t||"(attachment)","web",n,[...h]),h.length>0&&d(),A.current="",v(!1);try{localStorage.removeItem(E)}catch{}if(T.current){const e=T.current;"function"==typeof e.clear?e.clear():e.value=""}j.current=!0,i()}catch{}finally{p(!1)}},[e,s,E,x,h,d,i]);return(0,t.useEffect)(()=>{if(m)return;if(!j.current)return;if(j.current=!1,!R.current)return;const e=T.current;if(e)try{e.focus({preventScroll:!0})}catch{e.focus()}},[m]),(0,O.jsxs)(O.Fragment,{children:[x.length>0&&(0,O.jsx)(n.default,{style:le.pendingPayloadsRow,dataSet:{composer:"1"},children:x.map(e=>(0,O.jsxs)(n.default,{style:le.pendingPayloadThumb,children:[(0,b.isInlinePayload)(e.filename)?(0,O.jsx)(a.default,{source:{uri:e.uri},style:le.pendingPayloadImage,resizeMode:"cover"}):(0,O.jsx)(n.default,{style:[le.pendingPayloadImage,{justifyContent:"center",alignItems:"center",backgroundColor:"rgba(255,255,255,0.1)"}],children:(0,O.jsx)(o.default,{style:{color:"#aaa",fontSize:10},numberOfLines:2,children:e.filename.split(".").pop()})}),(0,O.jsx)(l.default,{style:le.pendingPayloadRemove,onPress:()=>M(e.id),children:(0,O.jsx)(o.default,{style:le.pendingPayloadRemoveText,children:"\xd7"})})]},e.id))}),(0,O.jsxs)(n.default,{style:le.inputRow,dataSet:{composer:"1"},children:[(0,O.jsx)(l.default,{onPress:L,accessibilityLabel:"Attach file",style:({hovered:e,pressed:t})=>[le.attachButton,(e||t)&&le.circleGlowActive],children:(0,O.jsx)(o.default,{style:le.attachText,children:"\ud83e\uddeb"})}),(0,O.jsx)("textarea",{ref:T,style:{flex:1,backgroundColor:"#111",color:"#e0e0e0",borderRadius:20,paddingLeft:16,paddingRight:16,paddingTop:6,paddingBottom:6,fontSize:16,border:"1px solid #555",resize:"none",overflow:"auto",maxHeight:120,fieldSizing:"content",fontFamily:"system-ui, -apple-system, sans-serif",outline:"none",lineHeight:"22px",boxSizing:"border-box"},onChange:e=>_(e.target.value),placeholder:"Compose message...",disabled:m,autoComplete:"off",autoCorrect:"on",spellCheck:!0,inputMode:"text",rows:1}),(0,O.jsx)(l.default,{style:[le.sendButton,!m&&(y||x.length>0)&&le.circleGlowSend],onPress:N,disabled:m||!y&&0===x.length,children:(0,O.jsx)(o.default,{style:[le.sendText,(m||!y&&0===x.length)&&le.sendTextInactive],children:"\ud83e\udd8b"})})]})]})}),Y=(0,t.memo)(function({nid:e,narrativeSummary:a,narrativeFoldPath:s,narrativeRole:i,narrativeStatus:c,narrativeMcpConnected:u,narrativeAwaiting:d,palette:f,narrativeCreatedAt:h,narrativeLastActivity:b,cost:m,archived:p,selection:S,openSwitcher:C,onDismiss:R,onDownload:k,onTerminate:P,onRevive:A,onTwin:I,onArchiveToggle:E,onRecolor:_,onShowQr:L,onIsolateDaemon:M,isIsolated:N,canIsolate:z}){const[q,$]=(0,t.useState)(!1),F=(0,w.useSelectedSeqs)(S).length,B=!!(i||s||h),H=(0,x.isAwaiting)({mcpConnected:u,awaiting:d})?(0,x.awaitingGlow)((0,T.glowHueFor)(e)):void 0,D=(0,t.useRef)(null),W=(0,t.useRef)(!1),G={onTouchStart:e=>{W.current=!1;const t=e.nativeEvent;D.current=q?null:{x:t.pageX,y:t.pageY}},onTouchEnd:e=>{const t=D.current;if(D.current=null,!t)return;const n=e.nativeEvent,o=n.pageX-t.x,a=n.pageY-t.y;a>60&&a>1.5*Math.abs(o)&&(W.current=!0,R())},onTouchCancel:()=>{D.current=null}};return(0,O.jsxs)(n.default,Object.assign({style:[le.header,le.glowTransition,H?{boxShadow:H}:null]},G,{children:[(0,O.jsxs)(l.default,{style:le.headerTitleContainer,onPress:()=>{W.current?W.current=!1:C()},children:[(0,O.jsx)(j.NarrativeIdentity,{id:e,foldPath:s,align:"center"}),B?(0,O.jsx)(j.NarrativeMetaLine,{role:i,cost:m,createdAt:h??void 0,lastActivity:b,status:c,mcpConnected:u,style:{marginTop:4}}):null,a?(0,O.jsx)("div",{style:{position:"relative",marginRight:8},children:(0,O.jsx)("div",{className:"no-scrollbar",style:{overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",WebkitOverflowScrolling:"touch",maskImage:"linear-gradient(to right, #000 calc(100% - 60px), transparent)",WebkitMaskImage:"linear-gradient(to right, #000 calc(100% - 60px), transparent)"},children:(0,O.jsx)(o.default,{style:le.headerSummary,children:a})})}):null]}),(0,O.jsxs)("div",{style:{position:"relative"},children:[(0,O.jsx)(l.default,{onPress:()=>$(e=>!e),style:le.reloadButton,hitSlop:8,children:(0,O.jsx)(o.default,{style:[le.reloadText,q&&le.reloadTextActive],children:"\ud83e\udda0"})}),q&&(0,O.jsx)(y.default,{items:(0,v.narrativeMenuItems)({role:i,status:c,mcpConnected:u,archived:p,isIsolated:N,canIsolate:z,selectedCount:F,onMeld:()=>{$(!1),L()},onIsolate:()=>{$(!1),M()},onExport:e=>{$(!1),k(e)},onRecolor:()=>{$(!1),_()},onTwin:()=>{$(!1),I()},onRevive:()=>{$(!1),A()},onEnd:()=>{$(!1),P()},onArchiveToggle:()=>{$(!1),E()}}),onClose:()=>$(!1)})]})]}))}),V={headerShown:!1},J=new Map;function K(e){return null!=e.cost_amount&&e.cost_unit?{amount:e.cost_amount,unit:e.cost_unit}:null}const Q=300,Z={flex:1,minHeight:0,display:"flex",flexDirection:"column-reverse",overflowY:"auto",overflowX:"hidden"},ee={marginBottom:"auto"},te=.3;function ne(e,t){const n=e?.querySelector(`[data-seq="${t}"]`);if(!e||!n)return!1;const o=n.getBoundingClientRect().top-e.getBoundingClientRect().top;return e.scrollTop+=o-e.clientHeight*te,!0}const re='button, a[href], [role="button"], [role="link"], [role="menuitem"]';function oe(e){return e?J.get(e)??{}:{}}function ae(e,t){const n=J.get(e)??{};J.set(e,Object.assign({},n,t))}function se(){const e=(0,f.useIsFocused)(),{nid:y,scrollTo:S,scrollToSeq:k,tab:A,pinned:L,path:z,line:D}=(0,d.useLocalSearchParams)(),W=(0,d.useRouter)(),{conn:G,subscribe:J,unsubscribe:te,onHint:se,onMeta:ie,onStatus:ce,onToolUses:ue,narrativeIds:de}=(0,h.useBrane)(),[fe,he]=(0,t.useState)([]),[ge,be]=(0,t.useState)(()=>new Map),me=(0,t.useRef)(0),pe=(0,t.useRef)(Number.MAX_SAFE_INTEGER),[ye,ve]=(0,t.useState)(()=>z??""),[xe,we]=(0,t.useState)(()=>(0,F.parseLineSpec)(D).line),[Se,Ce]=(0,t.useState)(()=>(0,F.parseLineSpec)(D).lineEnd),Te=y?`brane:files:${y}`:null,je=y?`brane:tabs:${y}`:null,Re=(0,t.useRef)(null),[ke,Pe]=(0,t.useState)(()=>(0,F.parseActiveTab)(A)),[Ae,Ie]=(0,t.useState)(()=>(0,F.parsePinnedTabs)(L)),Ee=(0,t.useRef)(y??null);(0,t.useEffect)(()=>{if(!y)return;if(Ee.current===y)return;Ee.current=y;const e=(0,F.parseLineSpec)(D);ve(z??""),we(e.line),Ce(e.lineEnd)},[y]);const Le=(0,t.useRef)(null);(0,t.useEffect)(()=>{if(!Te||!y)return;if(Le.current===y)return;if(Le.current=y,z)return;let e=null;try{e=sessionStorage.getItem(Te)}catch{return}if(!e)return;let t=null;try{t=JSON.parse(e)}catch{}if(!t?.path)return;ve(t.path),we(t.line),Ce(t.lineEnd);const n=t.line?t.lineEnd&&t.lineEnd>t.line?`${t.line}-${t.lineEnd}`:String(t.line):void 0;W.setParams({path:t.path,line:n})},[y]),(0,t.useEffect)(()=>{if(Te)try{if(ye){const e={path:ye};xe&&(e.line=xe),Se&&(e.lineEnd=Se),sessionStorage.setItem(Te,JSON.stringify(e))}else sessionStorage.removeItem(Te)}catch{}},[Te,ye,xe,Se]),(0,t.useEffect)(()=>{if(je&&Re.current===y)try{sessionStorage.setItem(je,JSON.stringify({tab:ke,pinned:(0,F.serializePinned)(Ae)}))}catch{}},[je,y,ke,Ae]);const Me=(0,t.useMemo)(()=>(0,H.visiblePanes)(ke,Ae),[ke,Ae]),Ne=(0,t.useMemo)(()=>{const e=e=>{const t=Me.indexOf(e),n=Me.length;return t<0||1===n?{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:t<0?0:1,backgroundColor:"#111",pointerEvents:t<0?"none":"auto"}:{position:"absolute",top:0,bottom:0,left:t/n*100+"%",width:100/n+"%",zIndex:1,backgroundColor:"#111",borderLeftWidth:t>0?c.default.hairlineWidth:0,borderLeftColor:"#555"}};return{chat:e("chat"),terminal:e("terminal"),files:e("files")}},[Me]),ze=1===Me.length,[qe,$e]=(0,t.useState)(null),[Fe,Be]=(0,t.useState)(!1),[He,Oe]=(0,t.useState)(!1),[De,We]=(0,t.useState)(()=>oe(y).summary??null),[Ge,Xe]=(0,t.useState)(()=>oe(y).agent_type??null),[Ue,Ye]=(0,t.useState)(()=>oe(y).role??null),[Ve,Je]=(0,t.useState)(()=>oe(y).archived??!1),[Ke,Qe]=(0,t.useState)(()=>oe(y).fold_path??null),[Ze,et]=(0,t.useState)(()=>oe(y).status??null),[tt,nt]=(0,t.useState)(()=>oe(y).mcp_connected??!1),[rt,ot]=(0,t.useState)(!1),[at,st]=(0,t.useState)(()=>oe(y).created_at??null),[lt,it]=(0,t.useState)(()=>oe(y).last_activity??null),[ct,ut]=(0,t.useState)(()=>K(oe(y)));(0,t.useEffect)(()=>{const e=oe(y);We(e.summary??null),Xe(e.agent_type??null),Ye(e.role??null),Je(e.archived??!1),Qe(e.fold_path??null),et(e.status??null),nt(e.mcp_connected??!1),ot(!1),st(e.created_at??null),it(e.last_activity??null),ut(K(e))},[y]);const[dt,ft]=(0,t.useState)(!1),[ht,gt]=(0,t.useState)([]),[bt,mt]=(0,t.useState)(!1),[pt,yt]=(0,t.useState)(null),vt=(0,t.useMemo)(()=>(0,q.collectKnownNids)({viewing:y,pushed:[...de].map(e=>({id:e})),listed:pt}),[y,de,pt]),xt=(0,w.useMessageSelection)(y),wt=(0,t.useRef)(0),[St,Ct]=(0,t.useState)(()=>(0,C.readRecolorSalt)(y));(0,t.useEffect)(()=>Ct((0,C.readRecolorSalt)(y)),[y]);const Tt=(0,t.useCallback)(()=>{(0,T.recolorGlowHue)(y),Ct((0,C.bumpRecolorSalt)(y))},[y]),jt=(0,t.useRef)(null),Rt=(0,t.useRef)(null),kt=(0,t.useRef)(!1),Pt=(0,t.useRef)(!0),[At,It]=(0,t.useState)(!0),[Et,_t]=(0,t.useState)(!0),[Lt,Mt]=(0,t.useState)(!0),Nt=(0,t.useRef)(null),zt=(0,t.useRef)(null),qt=(0,t.useRef)(!0);qt.current=Me.includes("chat");const $t=(0,t.useRef)(0),Ft=(0,t.useRef)(S?Number(S):0),Bt=(0,t.useRef)(k?Number(k):0),Ht=(0,t.useRef)(!1),[Ot,Dt]=(0,t.useState)(!1),[Wt,Gt]=(0,t.useState)(!0),Xt=(0,t.useRef)(!1),Ut=(0,t.useRef)(!1),Yt=(0,t.useRef)(null),Vt=(0,t.useRef)(!1),Jt=(0,t.useRef)(!1);(0,t.useEffect)(()=>{if(Me.includes("chat")&&!Vt.current){const e=Bt.current,t=Ft.current;if((e||t)&&0===fe.length)return;Vt.current=!0,$t.current=Date.now();let n=-1;if(e&&fe.length>0)n=fe.findIndex(t=>t.seq===e),n>=0&&xt.replace([e]),Bt.current=0;else if(t&&fe.length>0){let e=1/0;for(let o=0;o<fe.length;o++){const a=Math.abs(fe[o].time-t);a<e&&(e=a,n=o)}Ft.current=0}if(n>=0){Ut.current=!0;const e=setTimeout(()=>{Ut.current=!1},2e3);return ne(jt.current,fe[n].seq),()=>clearTimeout(e)}Pt.current=!0,It(!0)}Me.includes("terminal")&&(Jt.current=!0)},[Me,fe.length]);const Kt=(0,t.useCallback)(()=>{jt.current?.scrollTo({top:0})},[]),Qt=(0,t.useCallback)(()=>{const e=jt.current;e?.scrollTo({top:-e.scrollHeight,behavior:"smooth"})},[]),Zt=(0,t.useRef)(!1),en=(0,t.useRef)(!1),tn=(0,t.useCallback)(async()=>{if(G&&y)if(Zt.current)en.current=!0;else{Zt.current=!0;try{do{en.current=!1;const e=await(0,b.fetchEvents)(G,y,wt.current);e.events.length>0&&(he(t=>{const n=t.length>0?t[t.length-1].seq:0,o=e.events.filter(e=>e.seq>n);return o.length>0?[...t,...o]:t}),wt.current=e.events[e.events.length-1].seq)}while(en.current)}finally{Zt.current=!1}}},[G,y]),nn=(0,t.useCallback)(async()=>{if(G&&y&&!Xt.current&&Wt){Xt.current=!0;try{const e=fe.length>0?fe[0].seq:1/0,t=await(0,b.fetchEventsBefore)(G,y,e,50);t.events.length>0&&he(e=>{const n=e.length>0?e[0].seq:1/0,o=t.events.filter(e=>e.seq<n);return o.length>0?[...o,...e]:e}),(t.events.length<50||t.events.length>0&&t.events[0].seq<=t.min_seq)&&Gt(!1)}finally{Xt.current=!1}}},[G,y,fe,Wt]),rn=(0,t.useCallback)(e=>{0!==e.length&&be(t=>{let n=null;for(const o of e){const e=(n??t).get(o.dedup_key);e&&e.rev>=o.rev||(n||(n=new Map(t)),n.set(o.dedup_key,o),o.rev>me.current&&(me.current=o.rev))}return n??t})},[]);(0,t.useEffect)(()=>{if(!G||!y||0===fe.length)return;const e=Math.max(0,fe[0].seq-1),t=pe.current;e>=t||(pe.current=e,(0,b.fetchAllToolUseWindow)(G,y,{afterSeqGte:e,afterSeqLt:t===Number.MAX_SAFE_INTEGER?void 0:t},rn).catch(()=>{pe.current=Number.MAX_SAFE_INTEGER}))},[G,y,fe,rn]),(0,t.useEffect)(()=>{if(G&&y)return ue((e,t,n)=>{e===y&&(t?rn(t):(0,b.fetchAllToolUsesSince)(G,y,me.current,rn).catch(()=>{pe.current=Number.MAX_SAFE_INTEGER}))})},[G,y,ue,rn]),(0,t.useEffect)(()=>{if(!G||!y)return;const e=`${G.host}|${G.token}|${y}`;if(Yt.current===e)return;Yt.current=e,he([]),Gt(!0),wt.current=0,be(new Map),me.current=0,pe.current=Number.MAX_SAFE_INTEGER;const t=Bt.current;Ft.current;(async()=>{try{if(t){const e=Math.floor(25),n=Math.max(0,t-e-1),o=await(0,b.fetchEvents)(G,y,n,50);o.events.length>0?(he(o.events),wt.current=o.events[o.events.length-1].seq,Gt(o.events[0].seq>1)):(wt.current=o.seq,Gt(!1))}else{const e=await(0,b.fetchEventsBefore)(G,y,Number.MAX_SAFE_INTEGER,50);e.events.length>0?(he(e.events),wt.current=e.events[e.events.length-1].seq,(e.events.length<50||e.events[0].seq<=e.min_seq)&&Gt(!1)):(wt.current=0,Gt(!1))}}catch{tn()}})()},[G,y]);const on=(0,t.useCallback)(e=>{if(!y)return;e.summary&&(We(e.summary),ae(y,{summary:e.summary})),e.agent_type&&(Xe(e.agent_type),ae(y,{agent_type:e.agent_type})),e.role&&(Ye(e.role),ae(y,{role:e.role})),Qe(e.fold_path??null),ae(y,{fold_path:e.fold_path??null});const t=!!e.archived;Je(t),ae(y,{archived:t}),e.status&&(et(e.status),ae(y,{status:e.status}));const n=!!e.mcp_connected;nt(n),ae(y,{mcp_connected:n}),ot(!!e.awaiting),st(e.created_at??null),ae(y,{created_at:e.created_at}),it(e.last_activity??null),ae(y,{last_activity:e.last_activity??null}),ut(K({cost_amount:e.cost_amount,cost_unit:e.cost_unit})),ae(y,{cost_amount:e.cost_amount??null,cost_unit:e.cost_unit??null})},[y]);(0,t.useEffect)(()=>{G&&y&&(0,b.fetchNarrative)(G,y).then(on).catch(()=>{})},[G,y,on]),(0,t.useEffect)(()=>{G&&y&&(0,b.fetchNarratives)(G,{archived:!0}).then(e=>{yt(e);const t=e.find(e=>e.id===y);t&&on(t)}).catch(e=>{console.warn("narrative list sweep failed; linkifying from pushed ids only",e)})},[G,y,on]),(0,t.useEffect)(()=>{if(!y)return;J(y,wt.current);const e=se((e,t)=>{if(e===y){tn();const e=Date.now();it(e),ae(y,{last_activity:e})}});return()=>{te(y),e()}},[y,J,te,se,tn]),(0,t.useEffect)(()=>{if(y)return ie((e,t,n,o)=>{e===y&&(n&&(We(n),ae(y,{summary:n})),null!=o&&(ut(o),ae(y,{cost_amount:o.amount,cost_unit:o.unit})))})},[y,ie]),(0,t.useEffect)(()=>{if(y)return ce((e,t)=>{e===y&&("mcp_connected"===t?(nt(!0),ae(y,{mcp_connected:!0})):"mcp_disconnected"===t?(nt(!1),ot(!1),ae(y,{mcp_connected:!1})):t===x.AWAITING_STATUS||t===x.NOT_AWAITING_STATUS?ot(t===x.AWAITING_STATUS):"active"!==t&&"ended"!==t||(et(t),ae(y,{status:t})))})},[y,ce]);const an=(0,t.useCallback)(async e=>{G&&y&&("all"!==e?await(0,v.openNarrativeExport)(G,y,[...xt.getSelected()],"excluded"===e?"except":"only"):await(0,v.openNarrativeExport)(G,y))},[G,y,xt]),sn=(0,t.useCallback)(async()=>{if(Pt.current)Ht.current=!0,Pt.current=!1,It(!1),Qt(),setTimeout(()=>{Ht.current=!1},600);else{const e=setTimeout(()=>Dt(!0),150);try{await tn()}finally{clearTimeout(e),Dt(!1)}Pt.current=!0,It(!0),Kt()}},[tn,Kt,Qt]),ln=(0,t.useCallback)(()=>{Et?Nt.current?.scrollToTop():Nt.current?.scrollToBottom()},[Et]),cn=(0,t.useCallback)(()=>{Lt?zt.current?.scrollToTop():zt.current?.scrollToBottom()},[Lt]),un=(0,t.useCallback)((e,t,n,o,a)=>{W.setParams((0,F.viewParams)(e,t,n,o,a))},[W]),dn=(0,t.useCallback)(e=>{Pe(t=>t===e?t:(un(e,Ae,ye,xe,Se),e))},[un,Ae,ye,xe,Se]),fn=(0,t.useCallback)(e=>{if(ke===e)return;const{pinned:t}=(0,H.selectPane)(ke,Ae,e);Pe(e),Ie(t),un(e,t,ye,xe,Se)},[un,ke,Ae,ye,xe,Se]),hn=(0,t.useCallback)(()=>{const{pinned:e}=(0,H.selectPane)(ke,Ae,"terminal");Pe("terminal"),Ie(e),un("terminal",e,ye,xe,Se),setTimeout(()=>Nt.current?.focus(),60)},[un,ke,Ae,ye,xe,Se]);(0,t.useEffect)(()=>{if(!e)return;if(Me.length<2)return;const t=e=>{const t=e.target;if(t?.closest?.(re))return;const n=t?.closest?.("[data-pane]"),o=n?.getAttribute("data-pane");"chat"!==o&&"terminal"!==o&&"files"!==o||(fn(o),"terminal"===o&&Nt.current?.focus())};return document.addEventListener("pointerdown",t,!0),()=>document.removeEventListener("pointerdown",t,!0)},[e,Me.length,fn]);const gn=(0,t.useCallback)(e=>{Ie(t=>{const n=new Set(t);return n.has(e)?n.delete(e):n.add(e),un(ke,n,ye,xe,Se),n})},[un,ke,ye,xe,Se]),[bn,mn]=(0,t.useState)(null),pn=(0,t.useCallback)((e,t)=>{(e!==y||t)&&W.push((0,P.narrativeHref)(e,t))},[W,y]),yn=(0,t.useCallback)((e,t)=>{W.push(`/${e}?scrollTo=${t}`)},[W]),vn=(0,t.useCallback)(e=>{const t=xt.toggle(e);W.setParams({scrollToSeq:t?String(e):void 0})},[W,xt]),xn=(0,t.useCallback)(()=>{0!==xt.clear().length&&W.setParams({scrollToSeq:void 0})},[W,xt]);(0,t.useEffect)(()=>{if(!e)return;const t=e=>{const t=e.target;t?.closest&&t.closest('[data-pane="chat"]')&&(t.closest("[data-bubble], [data-chrome]")||t.closest("input, textarea, [data-composer]")||window.getSelection()?.toString()||xn())};return document.addEventListener("click",t),()=>document.removeEventListener("click",t)},[e,xn]);const wn=(0,t.useCallback)((e,t,n)=>{ve(e),we(t),Ce(n);"files"===ke||Ae.has("files")?un(ke,Ae,e,t,n):(Pe("files"),un("files",Ae,e,t,n))},[un,ke,Ae]),Sn=(0,t.useCallback)(e=>{const{path:t,line:n,lineEnd:o}=(0,I.parseRelLink)(e);wn(t,n,o)},[wn]),Cn=(0,t.useCallback)(e=>{if(!y)return;const{path:t,line:n,lineEnd:o}=(0,I.parseRelLink)(e);return(0,P.fileHref)(y,t,n,o,(0,F.serializePinned)(Ae)||void 0)},[y,Ae]),Tn=(0,t.useRef)(ke);Tn.current=ke;const jn=(0,t.useRef)(Ae);jn.current=Ae,(0,t.useEffect)(()=>{const e=(0,F.parseActiveTab)(A);e!==Tn.current&&Pe(e);const t=(0,F.parsePinnedTabs)(L),n=jn.current;(t.size!==n.size||[...t].some(e=>!n.has(e)))&&Ie(t)},[A,L]),(0,t.useEffect)(()=>{if(!je||!y)return;if(Re.current===y)return;if(Re.current=y,A||L)return;let e=null;try{e=sessionStorage.getItem(je)}catch{return}if(!e)return;let t=null;try{t=JSON.parse(e)}catch{}t&&(Pe((0,F.parseActiveTab)(t.tab)),Ie((0,F.parsePinnedTabs)(t.pinned)))},[y]);const Rn=(0,t.useMemo)(()=>{const e=new Map;if(0===ge.size||0===fe.length)return e;const t=fe[0].seq,n=fe[fe.length-1].seq;for(const o of ge.values()){let a=Math.min(o.after_seq,n);if(0===a){if(1!==t)continue;a=0}else if(a<t)continue;const s=e.get(a);s?s.push(o):e.set(a,[o])}for(const t of e.values())t.sort((e,t)=>e.started_at-t.started_at||e.dedup_key.localeCompare(t.dedup_key));return e},[fe,ge]),kn=(0,t.useCallback)(e=>G&&y?(0,b.fetchToolUse)(G,y,e):Promise.reject(new Error("no connection")),[G,y]),Pn=(0,t.useCallback)(({item:e})=>{const t=1===e.seq?Rn.get(0):void 0,n=Rn.get(e.seq),o=(0,O.jsx)(X,{item:e,nid:y,agentType:Ge,foldPath:Ke,conn:G,selection:xt,palette:St,onImagePress:$e,onForeignPress:yn,onFilePress:Sn,fileHref:Cn,onTimestampPress:vn});return t||n?(0,O.jsxs)(O.Fragment,{children:[t&&(0,O.jsx)(m.default,{rows:t,onNarrativePress:pn,onFetchFull:kn}),o,n&&(0,O.jsx)(m.default,{rows:n,onNarrativePress:pn,onFetchFull:kn})]}):o},[y,Ge,Ke,G,xt,St,yn,pn,Sn,Cn,vn,Rn,kn]),An=(0,t.useMemo)(()=>(0,F.viewParams)(ke,Ae,ye,xe,Se),[ke,Ae,ye,xe,Se]),In="undefined"!=typeof window&&!!G&&(0,F.isIsolated)(window.location.host,G.host),En=(0,B.useAppHost)(G,In),_n=(0,t.useCallback)(()=>{if(!G||!y)return;if("undefined"==typeof window)return;const e=(0,F.buildIsolateUrl)({host:window.location.host,protocol:window.location.protocol,search:window.location.search,path:`/${y}`,conn:G,appHost:En,view:An});e&&window.open(e,"_blank","noopener,noreferrer")},[G,y,An,En]),Ln=(0,t.useCallback)(async()=>{if(!G||!y)return;const e=!Ve;Je(e),ae(y,{archived:e});try{await(0,b.archiveNarrative)(G,y,e)}catch{return Je(!e),void ae(y,{archived:!e})}e&&W.push("/")},[G,y,Ve,W]),Mn=(0,t.useCallback)(()=>W.push("/"),[W]),Nn=(0,t.useCallback)(()=>{G&&(ft(!0),mt(!0),(0,b.fetchNarratives)(G).then(e=>{const t=e.filter(e=>e.mcp_connected||"active"===e.status||e.id===y);gt((0,$.sortNarratives)(t))}).catch(()=>{}).finally(()=>mt(!1)))},[G,y]);return(0,O.jsx)(u.default,{style:le.container,behavior:void 0,keyboardVerticalOffset:90,children:(0,O.jsxs)(N.MarkdownLinksProvider,{knownNarrativeIds:vt,onNarrativePress:pn,onProtocolPress:mn,children:[(0,O.jsx)(d.Stack.Screen,{options:V}),(0,O.jsx)(Y,{nid:y,narrativeSummary:De,narrativeFoldPath:Ke,narrativeRole:Ue,narrativeStatus:Ze,narrativeMcpConnected:tt,narrativeAwaiting:rt,palette:St,narrativeCreatedAt:at,narrativeLastActivity:lt,cost:(0,b.formatCost)(ct?.amount,ct?.unit),archived:Ve,selection:xt,openSwitcher:Nn,onDismiss:Mn,onDownload:an,onTerminate:()=>{hn(),Nt.current?.terminate()},onRevive:()=>{(0,v.revivesAsTwin)(Ue)||hn(),Nt.current?.revive()},onTwin:()=>Oe(!0),onArchiveToggle:Ln,onRecolor:Tt,onShowQr:()=>Be(!0),onIsolateDaemon:_n,isIsolated:In,canIsolate:!In||!!En}),(0,O.jsx)(n.default,{style:le.tabBar,children:F.CANONICAL_TABS.map((e,t)=>{const a=ke===e,s=Ae.has(e),i=a||s,c="chat"===e?"Chat":"terminal"===e?"Terminal":"Files",u="chat"===e?At:"terminal"===e?Et:Lt,d="chat"===e?sn:"terminal"===e?ln:cn;return(0,O.jsxs)(n.default,{style:[le.tab,t>0&&le.tabDivider,a&&le.tabActive],children:[(0,O.jsx)(l.default,{style:le.tabLabel,onPress:()=>dn(e),children:(0,O.jsx)(o.default,{style:[le.tabText,a&&le.tabTextActive],children:c})}),(0,O.jsx)(l.default,{style:le.tabPin,onPress:()=>gn(e),hitSlop:6,children:(0,O.jsx)(o.default,{style:[le.tabPinIcon,s?le.tabPinOn:le.tabPinOff],children:"\ud83d\udccc"})}),(0,O.jsx)(l.default,{style:le.tabArrowPress,onPress:d,disabled:!i,hitSlop:6,children:i?"chat"===e&&Ot?(0,O.jsx)(o.default,{style:le.tabArrowText,children:"\u267b\ufe0f"}):(0,O.jsx)(o.default,{style:le.tabArrowText,children:u?"\u2191":"\u2193"}):(0,O.jsx)(o.default,{style:le.tabArrowText})})]},e)})}),(0,O.jsxs)(n.default,Object.assign({style:{flex:1,overflow:"hidden",position:"relative"}},ze?{onTouchStart:e=>{const t=e.nativeEvent;Rt.current={x:t.pageX,y:t.pageY}},onTouchMove:e=>{if(!Rt.current)return;const t=e.nativeEvent,n=Math.abs(t.pageX-Rt.current.x),o=Math.abs(t.pageY-Rt.current.y);n>15&&n>1.5*o&&!kt.current&&(kt.current=!0)},onTouchEnd:e=>{if(!Rt.current)return;const t=e.nativeEvent,n=t.pageX-Rt.current.x,o=t.pageY-Rt.current.y;Rt.current=null,kt.current=!1;if(!("undefined"!=typeof window&&!!window.getSelection()?.toString())&&Math.abs(n)>60&&Math.abs(n)>1.5*Math.abs(o)){const e=Me[0],t=F.CANONICAL_TABS.indexOf(e),o=n<0?t+1:t-1;o>=0&&o<F.CANONICAL_TABS.length&&dn(F.CANONICAL_TABS[o])}}}:{},{children:[(0,O.jsxs)(n.default,{style:Ne.chat,dataSet:{pane:"chat"},children:[(0,O.jsx)("div",{ref:jt,style:Z,onScroll:e=>{const t=e.currentTarget,n=t.scrollTop>-50;n===Pt.current||Ht.current||(Pt.current=n,It(n));const o=t.scrollHeight-t.clientHeight+t.scrollTop,a=Date.now()-$t.current;o<200&&Wt&&!Xt.current&&!Ut.current&&qt.current&&$t.current>0&&a>Q&&nn()},children:(0,O.jsx)(n.default,{style:[le.list,ee],children:fe.map(e=>(0,O.jsx)("div",{"data-seq":e.seq,children:Pn({item:e})},e.seq))})}),(0,O.jsx)(U,{conn:G,nid:y,loadEvents:tn,chatActive:"chat"===ke,selection:xt,onDeselect:xn})]}),G&&y&&(0,O.jsx)(n.default,{style:Ne.terminal,dataSet:{pane:"terminal"},children:(0,O.jsx)(p.default,{ref:Nt,conn:G,nid:y,active:Me.includes("terminal"),keyboardActive:"terminal"===ke&&!dt&&!He&&null===qe,agentType:Ge,role:Ue,onAtBottomChange:_t,onTwin:()=>Oe(!0),onRevived:e=>W.push((0,F.terminalOnlyHref)(e))})}),G&&y&&(0,O.jsx)(n.default,{style:Ne.files,dataSet:{pane:"files"},children:(0,O.jsx)(E.default,{ref:zt,conn:G,nid:y,path:ye,line:xe,lineEnd:Se,active:Me.includes("files"),onPathChange:wn,onImagePress:$e,onAtBottomChange:Mt})})]})),(0,O.jsx)(i.default,{visible:dt,transparent:!0,animationType:"fade",onRequestClose:()=>ft(!1),children:(0,O.jsx)(l.default,{style:le.switcherOverlay,onPress:()=>ft(!1),children:(0,O.jsxs)(n.default,{style:le.switcherContent,children:[(0,O.jsxs)(n.default,{style:le.switcherTitleRow,children:[(0,O.jsx)(o.default,{style:le.switcherTitle,children:"Switch narrative"}),(0,O.jsx)(l.default,{hitSlop:8,onPress:()=>{ft(!1),W.push("/")},children:(0,O.jsx)(o.default,{style:le.switcherListLink,children:"All narratives"})})]}),(0,O.jsx)(s.default,{data:ht,keyExtractor:e=>e.id,style:le.switcherList,ListEmptyComponent:(0,O.jsx)(o.default,{style:le.switcherEmpty,children:bt?"Loading\u2026":"No active narratives"}),renderItem:({item:e})=>{const t="ended"===e.status&&!e.mcp_connected,n=(0,x.isAwaiting)({mcpConnected:e.mcp_connected,awaiting:e.awaiting})?(0,x.awaitingGlow)((0,T.glowHueFor)(e.id)):void 0;return(0,O.jsxs)(l.default,{style:[le.switcherItem,e.id===y&&le.switcherItemActive,t&&le.switcherItemEnded,n?{boxShadow:n}:null],onPress:()=>{ft(!1),e.id!==y&&W.push(`/${e.id}`)},children:[(0,O.jsx)(j.NarrativeIdentity,{id:e.id,foldPath:e.fold_path,titleStyle:t?{color:"#666"}:void 0,copyMarginLeft:5,dimmed:t}),(0,O.jsx)(j.NarrativeMetaLine,{role:e.role,cost:(0,b.formatCost)(e.cost_amount,e.cost_unit),createdAt:e.created_at,lastActivity:e.last_activity,status:e.status,mcpConnected:e.mcp_connected,dimmed:t,style:{marginTop:4}}),e.summary&&(0,O.jsx)("div",{style:{position:"relative"},children:(0,O.jsx)("div",{className:"no-scrollbar",style:{overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",WebkitOverflowScrolling:"touch",maskImage:"linear-gradient(to right, #000 calc(100% - 40px), transparent)",WebkitMaskImage:"linear-gradient(to right, #000 calc(100% - 40px), transparent)"},children:(0,O.jsx)(o.default,{style:[le.switcherItemSummary,t&&{color:"#555"}],children:e.summary})})})]})}}),(0,O.jsx)(l.default,{style:le.switcherCancel,onPress:()=>ft(!1),children:(0,O.jsx)(o.default,{style:le.switcherCancelText,children:"Cancel"})})]})})}),(0,O.jsx)(R.default,{visible:Fe,conn:G,path:`/${y}`,view:An,onClose:()=>Be(!1)}),(0,O.jsx)(_.default,{visible:He,conn:G,re:y,defaultFoldPath:Ke,onClose:()=>Oe(!1),onSpawned:e=>{Oe(!1),W.push(`/${e.id}`)}}),(0,O.jsx)(i.default,{visible:null!==qe,transparent:!0,animationType:"fade",onRequestClose:()=>$e(null),children:(0,O.jsxs)(l.default,{style:le.lightboxBackdrop,onPress:()=>$e(null),children:[qe&&(0,O.jsx)(a.default,{source:{uri:qe},style:le.lightboxImage,resizeMode:"contain"}),(0,O.jsx)(o.default,{style:le.lightboxHint,children:"Tap anywhere to close"})]})}),bn&&G&&(0,O.jsx)(N.MarkdownLinksProvider,{onNarrativePress:(e,t)=>{mn(null),pn(e,t)},children:(0,O.jsx)(M.default,{conn:G,target:{source:"protocols",slug:bn},onClose:()=>mn(null)})})]})})}const le=c.default.create({container:{flex:1},glowTransition:{transitionProperty:"box-shadow",transitionDuration:"400ms"},header:{flexDirection:"row",alignItems:"center",backgroundColor:"#1a1a1e",paddingHorizontal:4,paddingVertical:6,borderBottomWidth:c.default.hairlineWidth,borderBottomColor:"rgb(216, 216, 216)",position:"relative",zIndex:10},tabBar:{flexDirection:"row",borderBottomWidth:c.default.hairlineWidth,borderBottomColor:"#555",backgroundColor:"#111"},tab:{width:100/F.CANONICAL_TABS.length+"%",position:"relative"},tabDivider:{borderLeftWidth:c.default.hairlineWidth,borderLeftColor:"#555"},tabActive:{borderBottomWidth:2,borderBottomColor:"#4caf50"},tabLabel:{flex:1,paddingVertical:10,paddingHorizontal:36,alignItems:"center",justifyContent:"center"},tabPin:{position:"absolute",left:0,top:0,bottom:0,width:36,alignItems:"center",justifyContent:"center"},tabPinIcon:{fontSize:12},tabPinOn:{opacity:1},tabPinOff:{opacity:.25},tabArrowPress:{position:"absolute",right:0,top:0,bottom:0,width:36,alignItems:"center",justifyContent:"center"},tabText:{color:"#666",fontSize:14,fontWeight:"600"},tabTextActive:{color:"#4caf50"},tabArrowText:{color:"#8fd4b4",fontSize:16,fontWeight:"400"},headerTitleContainer:{flexDirection:"column",alignItems:"stretch",justifyContent:"center",flex:1,minWidth:0,paddingHorizontal:8},headerSubtitle:{color:"#888",fontSize:12,fontFamily:"monospace",marginTop:1},headerSummary:{color:"#9a9aa0",fontSize:12,lineHeight:12,whiteSpace:"nowrap"},list:{paddingHorizontal:12,paddingVertical:8},bubbleRow:{marginBottom:6,flexDirection:"row"},bubbleRowLeft:{justifyContent:"flex-start"},bubbleRowRight:{justifyContent:"flex-end"},bubbleRowCenter:{justifyContent:"center"},bubble:{maxWidth:"85%",borderRadius:16,paddingHorizontal:14,paddingVertical:10,borderWidth:1.5,borderColor:"transparent",borderStyle:"solid"},bubbleAgent:{backgroundColor:"#1c1c1e",borderBottomLeftRadius:4},bubbleOperator:{backgroundColor:"#1a4a7a",borderBottomRightRadius:4},bubbleForeign:{borderRadius:12},bubbleSystem:{backgroundColor:"transparent",borderWidth:1,borderStyle:"dashed",borderColor:"#3a3a3c",borderRadius:12},bubbleSelected:{borderColor:"#5b9bd5"},bubbleSourceRow:{flexDirection:"row",alignItems:"center",alignSelf:"flex-start",marginBottom:3},bubbleSourcePress:{alignSelf:"flex-start"},bubbleSource:{color:"#4caf50",fontSize:11,fontFamily:"monospace"},bubbleSourceLink:{textDecorationLine:"underline"},bubbleSourceAfterLink:{marginLeft:4},bubbleSourceSystem:{color:"#8a8a8e"},bubbleTimePress:{alignSelf:"flex-end",marginTop:4},bubbleTime:{color:"#666",fontSize:11,textAlign:"right"},inputRow:{flexDirection:"row",padding:8,paddingBottom:8,borderTopWidth:1,borderTopColor:"rgb(216, 216, 216)",backgroundColor:"#1a1a1a",alignItems:"flex-end"},input:{flex:1,backgroundColor:"#111",color:"#e0e0e0",borderRadius:20,paddingHorizontal:16,paddingVertical:8,fontSize:15,borderWidth:1,borderColor:"#555",maxHeight:120,minHeight:36},sendButton:Object.assign({marginLeft:8,width:36,height:36,borderRadius:18,backgroundColor:"#1c1c1e",borderWidth:1,borderColor:"#555",justifyContent:"center",alignItems:"center"},{transition:"box-shadow 160ms ease, border-color 160ms ease"}),sendText:{fontSize:20,lineHeight:20,transform:[{translateX:-1},{translateY:1},{rotate:"45deg"}]},sendTextInactive:{opacity:.35},attachButton:Object.assign({width:36,height:36,borderRadius:18,backgroundColor:"#1c1c1e",justifyContent:"center",alignItems:"center",marginRight:8,borderWidth:1,borderColor:"#555"},{transition:"box-shadow 160ms ease, border-color 160ms ease"}),attachText:{fontSize:20,lineHeight:20,marginTop:-3},circleGlowActive:Object.assign({borderColor:"rgba(255, 130, 180, 0.6)"},{boxShadow:["0 0 10px rgba(255, 130, 180, 0.9)","0 0 25px rgba(255, 110, 165, 0.7)","0 0 50px rgba(255, 100, 155, 0.4)"].join(", ")}),circleGlowSend:Object.assign({borderColor:"rgba(90, 230, 200, 0.6)"},{boxShadow:["0 0 10px rgba(90, 230, 200, 0.9)","0 0 25px rgba(70, 215, 190, 0.7)","0 0 50px rgba(60, 200, 180, 0.4)"].join(", ")}),payloadsContainer:{marginTop:6,gap:4},filePayload:{backgroundColor:"rgba(255,255,255,0.1)",borderRadius:6,paddingHorizontal:10,paddingVertical:6},filePayloadText:{color:"#6cf",fontSize:13},pendingPayloadsRow:{flexDirection:"row",paddingHorizontal:12,paddingTop:8,gap:8,backgroundColor:"#111"},pendingPayloadThumb:{position:"relative",width:60,height:60},pendingPayloadImage:{width:60,height:60,borderRadius:8,borderWidth:1,borderColor:"#555"},pendingPayloadRemove:{position:"absolute",top:-6,right:-6,width:20,height:20,borderRadius:10,backgroundColor:"#c00",justifyContent:"center",alignItems:"center"},pendingPayloadRemoveText:{color:"#fff",fontSize:14,fontWeight:"700",lineHeight:16},switcherOverlay:{flex:1,backgroundColor:"rgba(0,0,0,0.6)",justifyContent:"center",alignItems:"center",padding:24},switcherContent:{backgroundColor:"#1e1e1e",borderRadius:12,paddingTop:20,paddingHorizontal:20,paddingBottom:8,width:"100%",maxWidth:400,maxHeight:"70%"},switcherTitleRow:{flexDirection:"row",alignItems:"baseline",justifyContent:"space-between",marginBottom:16},switcherTitle:{color:"#e0e0e0",fontSize:18,fontWeight:"600"},switcherListLink:{color:"#8fd4b4",fontSize:14},switcherList:{flexGrow:0,padding:4,margin:-4},switcherItem:{paddingVertical:12,paddingHorizontal:12,borderRadius:8,backgroundColor:"#2a2a2a",marginBottom:8},switcherItemActive:{outlineWidth:2,outlineStyle:"solid",outlineColor:"#4caf50",outlineOffset:2},switcherItemEnded:{opacity:.5},switcherItemSummary:{color:"#9a9aa0",fontSize:12,lineHeight:12,whiteSpace:"nowrap"},switcherEmpty:{color:"#888",fontSize:14,textAlign:"center",paddingVertical:20},switcherCancel:{paddingVertical:12,alignItems:"center",marginTop:4},switcherCancelText:{color:"#888",fontSize:15},lightboxBackdrop:{flex:1,backgroundColor:"rgba(0, 0, 0, 0.95)",justifyContent:"center",alignItems:"center",padding:8},lightboxImage:{width:"100%",height:"92%"},lightboxHint:{color:"#888",fontSize:14,marginTop:20},reloadButton:{paddingHorizontal:8,paddingVertical:4,marginRight:4},reloadText:Object.assign({fontSize:20},{transition:"text-shadow 160ms ease"}),reloadTextActive:Object.assign({},{textShadow:["0 0 10px rgba(140, 230, 170, 0.9)","0 0 25px rgba(120, 215, 155, 0.7)","0 0 50px rgba(100, 200, 145, 0.4)","0 2px 15px rgba(130, 220, 165, 0.6)"].join(", ")})})},10,[11,13,105,106,113,145,146,153,26,160,116,161,165,736,745,759,762,773,769,754,774,771,770,776,778,780,786,761,958,959,972,779,973,950,751,976,977,747,978,980,6]);
26
+ __d(function(g,r,_i,_a,_m,_e,_d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return se}});var t=r(_d[0]),n=e(r(_d[1])),o=e(r(_d[2])),a=e(r(_d[3])),s=e(r(_d[4]));r(_d[5]);var l=e(r(_d[6])),i=e(r(_d[7])),c=e(r(_d[8])),u=e(r(_d[9]));r(_d[10]);var d=r(_d[11]),f=r(_d[12]),h=r(_d[13]),b=r(_d[14]),m=e(r(_d[15])),p=e(r(_d[16])),y=e(r(_d[17])),v=r(_d[18]),x=r(_d[19]),w=r(_d[20]),S=r(_d[21]),C=r(_d[22]),T=r(_d[23]),j=r(_d[24]),R=e(r(_d[25])),k=r(_d[26]),P=r(_d[27]),A=r(_d[28]),I=r(_d[29]),E=e(I),_=e(r(_d[30])),L=e(r(_d[31])),M=e(r(_d[32])),N=r(_d[33]),z=r(_d[34]),q=r(_d[35]),$=r(_d[36]),F=r(_d[37]),B=r(_d[38]),H=r(_d[39]),O=r(_d[40]);function D(e,t=!1){const n=new Date(e),o=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][n.getDay()],a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][n.getMonth()],s=n.getDate(),l=n.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"});if(t)return`${o} ${a} ${s}, ${n.getFullYear()} ${l}`;const i=new Date,c=n.getFullYear()===i.getFullYear();return c&&n.getMonth()===i.getMonth()&&n.getDate()===i.getDate()?`${o} ${l}`:c?`${o} ${a} ${s} ${l}`:`${o} ${a} ${s}, ${n.getFullYear()} ${l}`}function W(e){return"agent_signal"===e}const G=(0,t.memo)(function({uri:e,onPress:n}){const[o,s]=(0,t.useState)(null);(0,t.useEffect)(()=>{a.default.getSize(e,(e,t)=>s({w:e,h:t}),()=>s({w:200,h:150}))},[e]);const i=o?Math.min(200/o.w,150/o.h):1,c=o?Math.round(o.w*i):200,u=o?Math.round(o.h*i):150;return(0,O.jsx)(l.default,{onPress:n,children:(0,O.jsx)(a.default,{source:{uri:e},style:{width:c,height:u,borderRadius:8},resizeMode:"cover"})})}),X=(0,t.memo)(function({item:e,nid:t,agentType:a,foldPath:s,conn:i,selection:c,palette:u=0,onImagePress:d,onForeignPress:f,onFilePress:h,fileHref:m,onTimestampPress:p}){const y=(0,w.useIsSelected)(c,e.seq),v="human_signal"===e.type;const x=W(e.type),C=(0,z.isSystemEvent)(e.type),T=i&&e.payloads?e.payloads.filter(b.isInlinePayload):[],j=i&&e.payloads?e.payloads.filter(e=>!(0,b.isInlinePayload)(e)):[],R=(0,O.jsxs)(O.Fragment,{children:[(e.source||C)&&(0,O.jsxs)(n.default,{style:le.bubbleSourceRow,children:[x&&e.source&&(0,O.jsx)(l.default,{onPress:()=>f?.(e.source,e.time),style:le.bubbleSourcePress,children:(0,O.jsx)(o.default,{style:[le.bubbleSource,le.bubbleSourceLink,{color:(0,S.speakerColor)(e.source,u)}],children:e.source})}),(0,O.jsx)(l.default,{onPress:()=>p?.(e.seq),style:[le.bubbleSourcePress,x&&le.bubbleSourceAfterLink],children:(0,O.jsx)(o.default,{style:[le.bubbleSource,x&&e.source&&{color:(0,S.speakerColor)(e.source,u)},C&&le.bubbleSourceSystem],children:C?`system (${t}:${e.seq})`:v?`you (${t}:${e.seq})`:x?`(${t}:${e.seq})`:`${e.source}:${e.seq}`})}),(0,O.jsx)(L.default,{text:`${t}:${e.seq}`,size:9,padding:3,marginLeft:1,translateY:-1})]}),e.content?(0,O.jsx)(k.MarkdownContent,{content:C?(0,z.systemLine)({type:e.type,content:e.content},{agent:a??(0,z.agentTypeOf)(t),fold:s}):e.content,foreign:x,system:C,onFilePress:h,fileHref:m}):null,T.length>0&&i&&(0,O.jsx)(n.default,{style:le.payloadsContainer,children:T.map(e=>(0,O.jsx)(G,{uri:(0,b.payloadUrl)(i,e),onPress:()=>d?.((0,b.payloadUrl)(i,e))},e))}),j.length>0&&i&&(0,O.jsx)(n.default,{style:le.payloadsContainer,children:j.map(e=>{const t=(0,A.downloadNameFor)(e),n=(0,b.payloadUrl)(i,e);return(0,O.jsx)(l.default,{onPress:()=>{"undefined"!=typeof window&&(0,A.downloadUrl)(n,t).catch(e=>console.error("Payload download failed:",e))},style:le.filePayload,children:(0,O.jsx)(o.default,{style:le.filePayloadText,children:t})},e)})}),(0,O.jsx)(l.default,{onPress:()=>p?.(e.seq),style:le.bubbleTimePress,children:(0,O.jsx)(o.default,{style:le.bubbleTime,children:D(e.time)})})]}),P=[le.bubble,C?le.bubbleSystem:v?le.bubbleOperator:x?[le.bubbleForeign,{backgroundColor:(0,S.speakerBgColor)(e.source||"unknown",u)}]:le.bubbleAgent,y&&le.bubbleSelected];return(0,O.jsx)(n.default,{style:[le.bubbleRow,v?le.bubbleRowRight:x||C?le.bubbleRowCenter:le.bubbleRowLeft],children:(0,O.jsx)(n.default,{dataSet:{bubble:String(e.seq)},style:P,children:R})})}),U=(0,t.memo)(function({conn:e,nid:s,loadEvents:i,chatActive:c,selection:u,onDeselect:d}){const h=(0,w.useSelectedSeqs)(u),[m,p]=(0,t.useState)(!1),[y,v]=(0,t.useState)(!1),[x,S]=(0,t.useState)([]),C=(0,t.useRef)(null),T=(0,t.useRef)(null),j=(0,t.useRef)(!1),R=(0,t.useRef)(!1),k=(0,f.useIsFocused)(),P=c&&k;R.current=P;const A=(0,t.useRef)(""),I=(0,t.useRef)(null),E=`brane:draft:${s}`;(0,t.useEffect)(()=>{try{const e=localStorage.getItem(E);if(e&&(A.current=e,v(e.trim().length>0),T.current)){T.current.value=e}}catch{}return()=>{I.current&&clearTimeout(I.current);try{const e=A.current;e.trim()?localStorage.setItem(E,e):localStorage.removeItem(E)}catch{}}},[E]);const _=(0,t.useCallback)(e=>{A.current=e;const t=0===e.trim().length;v(e=>e===!t?e:!t),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{try{e.trim()?localStorage.setItem(E,e):localStorage.removeItem(E)}catch{}},300)},[E]);(0,t.useEffect)(()=>{const e=T.current;if(!e)return;if(!P)return void(document.activeElement===e&&e.blur());if(!window.matchMedia?.("(pointer: fine)").matches)return;const t=requestAnimationFrame(()=>{try{e.focus({preventScroll:!0})}catch{e.focus()}});return()=>cancelAnimationFrame(t)},[P]),(0,t.useEffect)(()=>{if(!P)return;const e=e=>{if(!R.current)return;const t=e.target,n=t?.tagName;if("INPUT"===n||"TEXTAREA"===n||t?.isContentEditable)return;if(e.metaKey||e.ctrlKey||e.altKey)return;if(e.isComposing)return;if(1!==e.key.length)return;const o=T.current;if(!o)return;e.preventDefault();const a=(o.value||"")+e.key;o.value=a,o.focus({preventScroll:!0});try{o.setSelectionRange(a.length,a.length)}catch{}_(a)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[P,_]),(0,t.useEffect)(()=>{if(!k)return;const e=e=>{const t=e.clipboardData?.items;if(t)for(const e of Array.from(t)){if(!e.type.startsWith("image/"))continue;const t=e.getAsFile();if(!t)continue;const n=new FileReader;n.onload=()=>{const e=n.result,o=e.split(",")[1],a=t.type.split("/")[1]||"png";S(t=>[...t,{id:`${Date.now()}_${Math.random().toString(36).slice(2,6)}`,filename:`paste_${Date.now()}.${a}`,data:o,uri:e}])},n.readAsDataURL(t)}};return document.addEventListener("paste",e),()=>document.removeEventListener("paste",e)},[k]);const L=(0,t.useCallback)(()=>{if(!C.current){const e=document.createElement("input");e.type="file",e.accept="*/*",e.multiple=!0,e.style.display="none",e.addEventListener("change",()=>{const t=e.files;if(t){for(const e of Array.from(t)){const t=new FileReader;t.onload=()=>{const n=t.result,o=n.split(",")[1];S(t=>[...t,{id:String(Date.now())+e.name,filename:e.name,data:o,uri:n}])},t.readAsDataURL(e)}e.value=""}}),document.body.appendChild(e),C.current=e}C.current.click()},[]);(0,t.useEffect)(()=>()=>{C.current&&(C.current.remove(),C.current=null)},[]);const M=(0,t.useCallback)(e=>{S(t=>t.filter(t=>t.id!==e))},[]),N=(0,t.useCallback)(async()=>{const t=A.current.trim();if(!e||!s||!t&&0===x.length)return;const n=x.length>0?x.map(e=>({filename:e.filename,data:e.data})):void 0;p(!0),S([]);try{await(0,b.sendSignal)(e,s,t||"(attachment)","web",n,[...h]),h.length>0&&d(),A.current="",v(!1);try{localStorage.removeItem(E)}catch{}if(T.current){const e=T.current;"function"==typeof e.clear?e.clear():e.value=""}j.current=!0,i()}catch{}finally{p(!1)}},[e,s,E,x,h,d,i]);return(0,t.useEffect)(()=>{if(m)return;if(!j.current)return;if(j.current=!1,!R.current)return;const e=T.current;if(e)try{e.focus({preventScroll:!0})}catch{e.focus()}},[m]),(0,O.jsxs)(O.Fragment,{children:[x.length>0&&(0,O.jsx)(n.default,{style:le.pendingPayloadsRow,dataSet:{composer:"1"},children:x.map(e=>(0,O.jsxs)(n.default,{style:le.pendingPayloadThumb,children:[(0,b.isInlinePayload)(e.filename)?(0,O.jsx)(a.default,{source:{uri:e.uri},style:le.pendingPayloadImage,resizeMode:"cover"}):(0,O.jsx)(n.default,{style:[le.pendingPayloadImage,{justifyContent:"center",alignItems:"center",backgroundColor:"rgba(255,255,255,0.1)"}],children:(0,O.jsx)(o.default,{style:{color:"#aaa",fontSize:10},numberOfLines:2,children:e.filename.split(".").pop()})}),(0,O.jsx)(l.default,{style:le.pendingPayloadRemove,onPress:()=>M(e.id),children:(0,O.jsx)(o.default,{style:le.pendingPayloadRemoveText,children:"\xd7"})})]},e.id))}),(0,O.jsxs)(n.default,{style:le.inputRow,dataSet:{composer:"1"},children:[(0,O.jsx)(l.default,{onPress:L,accessibilityLabel:"Attach file",style:({hovered:e,pressed:t})=>[le.attachButton,(e||t)&&le.circleGlowActive],children:(0,O.jsx)(o.default,{style:le.attachText,children:"\ud83e\uddeb"})}),(0,O.jsx)("textarea",{ref:T,style:{flex:1,backgroundColor:"#111",color:"#e0e0e0",borderRadius:20,paddingLeft:16,paddingRight:16,paddingTop:6,paddingBottom:6,fontSize:16,border:"1px solid #555",resize:"none",overflow:"auto",maxHeight:120,fieldSizing:"content",fontFamily:"system-ui, -apple-system, sans-serif",outline:"none",lineHeight:"22px",boxSizing:"border-box"},onChange:e=>_(e.target.value),placeholder:"Compose message...",disabled:m,autoComplete:"off",autoCorrect:"on",spellCheck:!0,inputMode:"text",rows:1}),(0,O.jsx)(l.default,{style:[le.sendButton,!m&&(y||x.length>0)&&le.circleGlowSend],onPress:N,disabled:m||!y&&0===x.length,children:(0,O.jsx)(o.default,{style:[le.sendText,(m||!y&&0===x.length)&&le.sendTextInactive],children:"\ud83e\udd8b"})})]})]})}),Y=(0,t.memo)(function({nid:e,narrativeSummary:a,narrativeFoldPath:s,narrativeRole:i,narrativeStatus:c,narrativeMcpConnected:u,narrativeAwaiting:d,palette:f,narrativeCreatedAt:h,narrativeLastActivity:b,cost:m,archived:p,selection:S,openSwitcher:C,onDismiss:R,onDownload:k,onTerminate:P,onRevive:A,onTwin:I,onArchiveToggle:E,onRecolor:_,onShowQr:L,onIsolateDaemon:M,isIsolated:N,canIsolate:z}){const[q,$]=(0,t.useState)(!1),F=(0,w.useSelectedSeqs)(S).length,B=!!(i||s||h),H=(0,x.isAwaiting)({mcpConnected:u,awaiting:d})?(0,x.awaitingGlow)((0,T.glowHueFor)(e)):void 0,D=(0,t.useRef)(null),W=(0,t.useRef)(!1),G={onTouchStart:e=>{W.current=!1;const t=e.nativeEvent;D.current=q?null:{x:t.pageX,y:t.pageY}},onTouchEnd:e=>{const t=D.current;if(D.current=null,!t)return;const n=e.nativeEvent,o=n.pageX-t.x,a=n.pageY-t.y;a>60&&a>1.5*Math.abs(o)&&(W.current=!0,R())},onTouchCancel:()=>{D.current=null}};return(0,O.jsxs)(n.default,Object.assign({style:[le.header,le.glowTransition,H?{boxShadow:H}:null]},G,{children:[(0,O.jsxs)(l.default,{style:le.headerTitleContainer,onPress:()=>{W.current?W.current=!1:C()},children:[(0,O.jsx)(j.NarrativeIdentity,{id:e,foldPath:s,align:"center"}),B?(0,O.jsx)(j.NarrativeMetaLine,{role:i,cost:m,createdAt:h??void 0,lastActivity:b,status:c,mcpConnected:u,style:{marginTop:4}}):null,a?(0,O.jsx)("div",{style:{position:"relative",marginRight:8},children:(0,O.jsx)("div",{className:"no-scrollbar",style:{overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",WebkitOverflowScrolling:"touch",maskImage:"linear-gradient(to right, #000 calc(100% - 60px), transparent)",WebkitMaskImage:"linear-gradient(to right, #000 calc(100% - 60px), transparent)"},children:(0,O.jsx)(o.default,{style:le.headerSummary,children:a})})}):null]}),(0,O.jsxs)("div",{style:{position:"relative"},children:[(0,O.jsx)(l.default,{onPress:()=>$(e=>!e),style:le.reloadButton,hitSlop:8,children:(0,O.jsx)(o.default,{style:[le.reloadText,q&&le.reloadTextActive],children:"\ud83e\udda0"})}),q&&(0,O.jsx)(y.default,{items:(0,v.narrativeMenuItems)({role:i,status:c,mcpConnected:u,archived:p,isIsolated:N,canIsolate:z,selectedCount:F,onMeld:()=>{$(!1),L()},onIsolate:()=>{$(!1),M()},onExport:e=>{$(!1),k(e)},onRecolor:()=>{$(!1),_()},onTwin:()=>{$(!1),I()},onRevive:()=>{$(!1),A()},onEnd:()=>{$(!1),P()},onArchiveToggle:()=>{$(!1),E()}}),onClose:()=>$(!1)})]})]}))}),V={headerShown:!1},J=new Map;function K(e){return null!=e.cost_amount&&e.cost_unit?{amount:e.cost_amount,unit:e.cost_unit}:null}const Q=300,Z={flex:1,minHeight:0,display:"flex",flexDirection:"column-reverse",overflowY:"auto",overflowX:"hidden"},ee={marginBottom:"auto"},te=.3;function ne(e,t){const n=e?.querySelector(`[data-seq="${t}"]`);if(!e||!n)return!1;const o=n.getBoundingClientRect().top-e.getBoundingClientRect().top;return e.scrollTop+=o-e.clientHeight*te,!0}const re='button, a[href], [role="button"], [role="link"], [role="menuitem"]';function oe(e){return e?J.get(e)??{}:{}}function ae(e,t){const n=J.get(e)??{};J.set(e,Object.assign({},n,t))}function se(){const e=(0,f.useIsFocused)(),{nid:y,scrollTo:S,scrollToSeq:k,tab:A,pinned:L,path:z,line:D}=(0,d.useLocalSearchParams)(),W=(0,d.useRouter)(),{conn:G,subscribe:J,unsubscribe:te,onHint:se,onMeta:ie,onStatus:ce,onToolUses:ue,narrativeIds:de}=(0,h.useBrane)(),[fe,he]=(0,t.useState)([]),[ge,be]=(0,t.useState)(()=>new Map),me=(0,t.useRef)(0),pe=(0,t.useRef)(Number.MAX_SAFE_INTEGER),[ye,ve]=(0,t.useState)(()=>z??""),[xe,we]=(0,t.useState)(()=>(0,F.parseLineSpec)(D).line),[Se,Ce]=(0,t.useState)(()=>(0,F.parseLineSpec)(D).lineEnd),Te=y?`brane:files:${y}`:null,je=y?`brane:tabs:${y}`:null,Re=(0,t.useRef)(null),[ke,Pe]=(0,t.useState)(()=>(0,F.parseActiveTab)(A)),[Ae,Ie]=(0,t.useState)(()=>(0,F.parsePinnedTabs)(L)),Ee=(0,t.useRef)(y??null);(0,t.useEffect)(()=>{if(!y)return;if(Ee.current===y)return;Ee.current=y;const e=(0,F.parseLineSpec)(D);ve(z??""),we(e.line),Ce(e.lineEnd)},[y]);const Le=(0,t.useRef)(null);(0,t.useEffect)(()=>{if(!Te||!y)return;if(Le.current===y)return;if(Le.current=y,z)return;let e=null;try{e=sessionStorage.getItem(Te)}catch{return}if(!e)return;let t=null;try{t=JSON.parse(e)}catch{}if(!t?.path)return;ve(t.path),we(t.line),Ce(t.lineEnd);const n=t.line?t.lineEnd&&t.lineEnd>t.line?`${t.line}-${t.lineEnd}`:String(t.line):void 0;W.setParams({path:t.path,line:n})},[y]),(0,t.useEffect)(()=>{if(Te)try{if(ye){const e={path:ye};xe&&(e.line=xe),Se&&(e.lineEnd=Se),sessionStorage.setItem(Te,JSON.stringify(e))}else sessionStorage.removeItem(Te)}catch{}},[Te,ye,xe,Se]),(0,t.useEffect)(()=>{if(je&&Re.current===y)try{sessionStorage.setItem(je,JSON.stringify({tab:ke,pinned:(0,F.serializePinned)(Ae)}))}catch{}},[je,y,ke,Ae]);const Me=(0,t.useMemo)(()=>(0,H.visiblePanes)(ke,Ae),[ke,Ae]),Ne=(0,t.useMemo)(()=>{const e=e=>{const t=Me.indexOf(e),n=Me.length;return t<0||1===n?{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:t<0?0:1,backgroundColor:"#111",pointerEvents:t<0?"none":"auto"}:{position:"absolute",top:0,bottom:0,left:t/n*100+"%",width:100/n+"%",zIndex:1,backgroundColor:"#111",borderLeftWidth:t>0?c.default.hairlineWidth:0,borderLeftColor:"#555"}};return{chat:e("chat"),terminal:e("terminal"),files:e("files")}},[Me]),ze=1===Me.length,[qe,$e]=(0,t.useState)(null),[Fe,Be]=(0,t.useState)(!1),[He,Oe]=(0,t.useState)(!1),[De,We]=(0,t.useState)(()=>oe(y).summary??null),[Ge,Xe]=(0,t.useState)(()=>oe(y).agent_type??null),[Ue,Ye]=(0,t.useState)(()=>oe(y).role??null),[Ve,Je]=(0,t.useState)(()=>oe(y).archived??!1),[Ke,Qe]=(0,t.useState)(()=>oe(y).fold_path??null),[Ze,et]=(0,t.useState)(()=>oe(y).status??null),[tt,nt]=(0,t.useState)(()=>oe(y).mcp_connected??!1),[rt,ot]=(0,t.useState)(!1),[at,st]=(0,t.useState)(()=>oe(y).created_at??null),[lt,it]=(0,t.useState)(()=>oe(y).last_activity??null),[ct,ut]=(0,t.useState)(()=>K(oe(y)));(0,t.useEffect)(()=>{const e=oe(y);We(e.summary??null),Xe(e.agent_type??null),Ye(e.role??null),Je(e.archived??!1),Qe(e.fold_path??null),et(e.status??null),nt(e.mcp_connected??!1),ot(!1),st(e.created_at??null),it(e.last_activity??null),ut(K(e))},[y]);const[dt,ft]=(0,t.useState)(!1),[ht,gt]=(0,t.useState)([]),[bt,mt]=(0,t.useState)(!1),[pt,yt]=(0,t.useState)(null),vt=(0,t.useMemo)(()=>(0,q.collectKnownNids)({viewing:y,pushed:[...de].map(e=>({id:e})),listed:pt}),[y,de,pt]),xt=(0,w.useMessageSelection)(y),wt=(0,t.useRef)(0),[St,Ct]=(0,t.useState)(()=>(0,C.readRecolorSalt)(y));(0,t.useEffect)(()=>Ct((0,C.readRecolorSalt)(y)),[y]);const Tt=(0,t.useCallback)(()=>{(0,T.recolorGlowHue)(y),Ct((0,C.bumpRecolorSalt)(y))},[y]),jt=(0,t.useRef)(null),Rt=(0,t.useRef)(null),kt=(0,t.useRef)(!1),Pt=(0,t.useRef)(!0),[At,It]=(0,t.useState)(!0),[Et,_t]=(0,t.useState)(!0),[Lt,Mt]=(0,t.useState)(!0),Nt=(0,t.useRef)(null),zt=(0,t.useRef)(null),qt=(0,t.useRef)(!0);qt.current=Me.includes("chat");const $t=(0,t.useRef)(0),Ft=(0,t.useRef)(S?Number(S):0),Bt=(0,t.useRef)(k?Number(k):0),Ht=(0,t.useRef)(!1),[Ot,Dt]=(0,t.useState)(!1),[Wt,Gt]=(0,t.useState)(!0),Xt=(0,t.useRef)(!1),Ut=(0,t.useRef)(!1),Yt=(0,t.useRef)(null),Vt=(0,t.useRef)(!1),Jt=(0,t.useRef)(!1);(0,t.useEffect)(()=>{if(Me.includes("chat")&&!Vt.current){const e=Bt.current,t=Ft.current;if((e||t)&&0===fe.length)return;Vt.current=!0,$t.current=Date.now();let n=-1;if(e&&fe.length>0)n=fe.findIndex(t=>t.seq===e),n>=0&&xt.replace([e]),Bt.current=0;else if(t&&fe.length>0){let e=1/0;for(let o=0;o<fe.length;o++){const a=Math.abs(fe[o].time-t);a<e&&(e=a,n=o)}Ft.current=0}if(n>=0){Ut.current=!0;const e=setTimeout(()=>{Ut.current=!1},2e3);return ne(jt.current,fe[n].seq),()=>clearTimeout(e)}Pt.current=!0,It(!0)}Me.includes("terminal")&&(Jt.current=!0)},[Me,fe.length]);const Kt=(0,t.useCallback)(()=>{jt.current?.scrollTo({top:0})},[]),Qt=(0,t.useCallback)(()=>{const e=jt.current;e?.scrollTo({top:-e.scrollHeight,behavior:"smooth"})},[]),Zt=(0,t.useRef)(!1),en=(0,t.useRef)(!1),tn=(0,t.useCallback)(async()=>{if(G&&y)if(Zt.current)en.current=!0;else{Zt.current=!0;try{do{en.current=!1;const e=await(0,b.fetchEvents)(G,y,wt.current);e.events.length>0&&(he(t=>{const n=t.length>0?t[t.length-1].seq:0,o=e.events.filter(e=>e.seq>n);return o.length>0?[...t,...o]:t}),wt.current=e.events[e.events.length-1].seq)}while(en.current)}finally{Zt.current=!1}}},[G,y]),nn=(0,t.useCallback)(async()=>{if(G&&y&&!Xt.current&&Wt){Xt.current=!0;try{const e=fe.length>0?fe[0].seq:1/0,t=await(0,b.fetchEventsBefore)(G,y,e,50);t.events.length>0&&he(e=>{const n=e.length>0?e[0].seq:1/0,o=t.events.filter(e=>e.seq<n);return o.length>0?[...o,...e]:e}),(t.events.length<50||t.events.length>0&&t.events[0].seq<=t.min_seq)&&Gt(!1)}finally{Xt.current=!1}}},[G,y,fe,Wt]),rn=(0,t.useCallback)(e=>{0!==e.length&&be(t=>{let n=null;for(const o of e){const e=(n??t).get(o.dedup_key);e&&e.rev>=o.rev||(n||(n=new Map(t)),n.set(o.dedup_key,o),o.rev>me.current&&(me.current=o.rev))}return n??t})},[]);(0,t.useEffect)(()=>{if(!G||!y||0===fe.length)return;const e=Math.max(0,fe[0].seq-1),t=pe.current;e>=t||(pe.current=e,(0,b.fetchAllToolUseWindow)(G,y,{afterSeqGte:e,afterSeqLt:t===Number.MAX_SAFE_INTEGER?void 0:t},rn).catch(()=>{pe.current=Number.MAX_SAFE_INTEGER}))},[G,y,fe,rn]),(0,t.useEffect)(()=>{if(G&&y)return ue((e,t,n)=>{e===y&&(t?rn(t):(0,b.fetchAllToolUsesSince)(G,y,me.current,rn).catch(()=>{pe.current=Number.MAX_SAFE_INTEGER}))})},[G,y,ue,rn]),(0,t.useEffect)(()=>{if(!G||!y)return;const e=`${G.host}|${G.token}|${y}`;if(Yt.current===e)return;Yt.current=e,he([]),Gt(!0),wt.current=0,be(new Map),me.current=0,pe.current=Number.MAX_SAFE_INTEGER;const t=Bt.current;Ft.current;(async()=>{try{if(t){const e=Math.floor(25),n=Math.max(0,t-e-1),o=await(0,b.fetchEvents)(G,y,n,50);o.events.length>0?(he(o.events),wt.current=o.events[o.events.length-1].seq,Gt(o.events[0].seq>1)):(wt.current=o.seq,Gt(!1))}else{const e=await(0,b.fetchEventsBefore)(G,y,Number.MAX_SAFE_INTEGER,50);e.events.length>0?(he(e.events),wt.current=e.events[e.events.length-1].seq,(e.events.length<50||e.events[0].seq<=e.min_seq)&&Gt(!1)):(wt.current=0,Gt(!1))}}catch{tn()}})()},[G,y]);const on=(0,t.useCallback)(e=>{if(!y)return;e.summary&&(We(e.summary),ae(y,{summary:e.summary})),e.agent_type&&(Xe(e.agent_type),ae(y,{agent_type:e.agent_type})),e.role&&(Ye(e.role),ae(y,{role:e.role})),Qe(e.fold_path??null),ae(y,{fold_path:e.fold_path??null});const t=!!e.archived;Je(t),ae(y,{archived:t}),e.status&&(et(e.status),ae(y,{status:e.status}));const n=!!e.mcp_connected;nt(n),ae(y,{mcp_connected:n}),ot(!!e.awaiting),st(e.created_at??null),ae(y,{created_at:e.created_at}),it(e.last_activity??null),ae(y,{last_activity:e.last_activity??null}),ut(K({cost_amount:e.cost_amount,cost_unit:e.cost_unit})),ae(y,{cost_amount:e.cost_amount??null,cost_unit:e.cost_unit??null})},[y]);(0,t.useEffect)(()=>{G&&y&&(0,b.fetchNarrative)(G,y).then(on).catch(()=>{})},[G,y,on]),(0,t.useEffect)(()=>{G&&y&&(0,b.fetchNarratives)(G,{archived:!0}).then(e=>{yt(e);const t=e.find(e=>e.id===y);t&&on(t)}).catch(e=>{console.warn("narrative list sweep failed; linkifying from pushed ids only",e)})},[G,y,on]),(0,t.useEffect)(()=>{if(!y)return;J(y,wt.current);const e=se((e,t)=>{if(e===y){tn();const e=Date.now();it(e),ae(y,{last_activity:e})}});return()=>{te(y),e()}},[y,J,te,se,tn]),(0,t.useEffect)(()=>{if(y)return ie((e,t,n,o)=>{e===y&&(n&&(We(n),ae(y,{summary:n})),null!=o&&(ut(o),ae(y,{cost_amount:o.amount,cost_unit:o.unit})))})},[y,ie]),(0,t.useEffect)(()=>{if(y)return ce((e,t)=>{e===y&&("mcp_connected"===t?(nt(!0),ae(y,{mcp_connected:!0})):"mcp_disconnected"===t?(nt(!1),ot(!1),ae(y,{mcp_connected:!1})):t===x.AWAITING_STATUS||t===x.NOT_AWAITING_STATUS?ot(t===x.AWAITING_STATUS):"active"!==t&&"ended"!==t||(et(t),ae(y,{status:t})))})},[y,ce]);const an=(0,t.useCallback)(async e=>{G&&y&&("all"!==e?await(0,v.openNarrativeExport)(G,y,[...xt.getSelected()],"excluded"===e?"except":"only"):await(0,v.openNarrativeExport)(G,y))},[G,y,xt]),sn=(0,t.useCallback)(async()=>{if(Pt.current)Ht.current=!0,Pt.current=!1,It(!1),Qt(),setTimeout(()=>{Ht.current=!1},600);else{const e=setTimeout(()=>Dt(!0),150);try{await tn()}finally{clearTimeout(e),Dt(!1)}Pt.current=!0,It(!0),Kt()}},[tn,Kt,Qt]),ln=(0,t.useCallback)(()=>{Et?Nt.current?.scrollToTop():Nt.current?.scrollToBottom()},[Et]),cn=(0,t.useCallback)(()=>{Lt?zt.current?.scrollToTop():zt.current?.scrollToBottom()},[Lt]),un=(0,t.useCallback)((e,t,n,o,a)=>{W.setParams((0,F.viewParams)(e,t,n,o,a))},[W]),dn=(0,t.useCallback)(e=>{Pe(t=>t===e?t:(un(e,Ae,ye,xe,Se),e))},[un,Ae,ye,xe,Se]),fn=(0,t.useCallback)(e=>{if(ke===e)return;const{pinned:t}=(0,H.selectPane)(ke,Ae,e);Pe(e),Ie(t),un(e,t,ye,xe,Se)},[un,ke,Ae,ye,xe,Se]),hn=(0,t.useCallback)(()=>{const{pinned:e}=(0,H.selectPane)(ke,Ae,"terminal");Pe("terminal"),Ie(e),un("terminal",e,ye,xe,Se),setTimeout(()=>Nt.current?.focus(),60)},[un,ke,Ae,ye,xe,Se]);(0,t.useEffect)(()=>{if(!e)return;if(Me.length<2)return;const t=e=>{const t=e.target;if(t?.closest?.(re))return;const n=t?.closest?.("[data-pane]"),o=n?.getAttribute("data-pane");"chat"!==o&&"terminal"!==o&&"files"!==o||(fn(o),"terminal"===o&&Nt.current?.focus())};return document.addEventListener("pointerdown",t,!0),()=>document.removeEventListener("pointerdown",t,!0)},[e,Me.length,fn]);const gn=(0,t.useCallback)(e=>{Ie(t=>{const n=new Set(t);return n.has(e)?n.delete(e):n.add(e),un(ke,n,ye,xe,Se),n})},[un,ke,ye,xe,Se]),[bn,mn]=(0,t.useState)(null),pn=(0,t.useCallback)((e,t)=>{(e!==y||t)&&W.push((0,P.narrativeHref)(e,t))},[W,y]),yn=(0,t.useCallback)((e,t)=>{W.push(`/${e}?scrollTo=${t}`)},[W]),vn=(0,t.useCallback)(e=>{const t=xt.toggle(e);W.setParams({scrollToSeq:t?String(e):void 0})},[W,xt]),xn=(0,t.useCallback)(()=>{0!==xt.clear().length&&W.setParams({scrollToSeq:void 0})},[W,xt]);(0,t.useEffect)(()=>{if(!e)return;const t=e=>{const t=e.target;t?.closest&&t.closest('[data-pane="chat"]')&&(t.closest("[data-bubble], [data-chrome]")||t.closest("input, textarea, [data-composer]")||window.getSelection()?.toString()||xn())};return document.addEventListener("click",t),()=>document.removeEventListener("click",t)},[e,xn]);const wn=(0,t.useCallback)((e,t,n)=>{ve(e),we(t),Ce(n);"files"===ke||Ae.has("files")?un(ke,Ae,e,t,n):(Pe("files"),un("files",Ae,e,t,n))},[un,ke,Ae]),Sn=(0,t.useCallback)(e=>{const{path:t,line:n,lineEnd:o}=(0,I.parseRelLink)(e);wn(t,n,o)},[wn]),Cn=(0,t.useCallback)(e=>{if(!y)return;const{path:t,line:n,lineEnd:o}=(0,I.parseRelLink)(e);return(0,P.fileHref)(y,t,n,o,(0,F.serializePinned)(Ae)||void 0)},[y,Ae]),Tn=(0,t.useRef)(ke);Tn.current=ke;const jn=(0,t.useRef)(Ae);jn.current=Ae,(0,t.useEffect)(()=>{const e=(0,F.parseActiveTab)(A);e!==Tn.current&&Pe(e);const t=(0,F.parsePinnedTabs)(L),n=jn.current;(t.size!==n.size||[...t].some(e=>!n.has(e)))&&Ie(t)},[A,L]),(0,t.useEffect)(()=>{if(!je||!y)return;if(Re.current===y)return;if(Re.current=y,A||L)return;let e=null;try{e=sessionStorage.getItem(je)}catch{return}if(!e)return;let t=null;try{t=JSON.parse(e)}catch{}t&&(Pe((0,F.parseActiveTab)(t.tab)),Ie((0,F.parsePinnedTabs)(t.pinned)))},[y]);const Rn=(0,t.useMemo)(()=>{const e=new Map;if(0===ge.size||0===fe.length)return e;const t=fe[0].seq,n=fe[fe.length-1].seq;for(const o of ge.values()){let a=Math.min(o.after_seq,n);if(0===a){if(1!==t)continue;a=0}else if(a<t)continue;const s=e.get(a);s?s.push(o):e.set(a,[o])}for(const t of e.values())t.sort((e,t)=>e.started_at-t.started_at||e.dedup_key.localeCompare(t.dedup_key));return e},[fe,ge]),kn=(0,t.useCallback)(e=>G&&y?(0,b.fetchToolUse)(G,y,e):Promise.reject(new Error("no connection")),[G,y]),Pn=(0,t.useCallback)(({item:e})=>{const t=1===e.seq?Rn.get(0):void 0,n=Rn.get(e.seq),o=(0,O.jsx)(X,{item:e,nid:y,agentType:Ge,foldPath:Ke,conn:G,selection:xt,palette:St,onImagePress:$e,onForeignPress:yn,onFilePress:Sn,fileHref:Cn,onTimestampPress:vn});return t||n?(0,O.jsxs)(O.Fragment,{children:[t&&(0,O.jsx)(m.default,{rows:t,onNarrativePress:pn,onFetchFull:kn}),o,n&&(0,O.jsx)(m.default,{rows:n,onNarrativePress:pn,onFetchFull:kn})]}):o},[y,Ge,Ke,G,xt,St,yn,pn,Sn,Cn,vn,Rn,kn]),An=(0,t.useMemo)(()=>(0,F.viewParams)(ke,Ae,ye,xe,Se),[ke,Ae,ye,xe,Se]),In="undefined"!=typeof window&&!!G&&(0,F.isIsolated)(window.location.host,G.host),En=(0,B.useAppHost)(G,In),_n=(0,t.useCallback)(()=>{if(!G||!y)return;if("undefined"==typeof window)return;const e=(0,F.buildIsolateUrl)({host:window.location.host,protocol:window.location.protocol,search:window.location.search,path:`/${y}`,conn:G,appHost:En,view:An});e&&window.open(e,"_blank","noopener,noreferrer")},[G,y,An,En]),Ln=(0,t.useCallback)(async()=>{if(!G||!y)return;const e=!Ve;Je(e),ae(y,{archived:e});try{await(0,b.archiveNarrative)(G,y,e)}catch{return Je(!e),void ae(y,{archived:!e})}e&&W.push("/")},[G,y,Ve,W]),Mn=(0,t.useCallback)(()=>W.push("/"),[W]),Nn=(0,t.useCallback)(()=>{G&&(ft(!0),mt(!0),(0,b.fetchNarratives)(G).then(e=>{const t=e.filter(e=>e.mcp_connected||"active"===e.status||e.id===y);gt((0,$.sortNarratives)(t))}).catch(()=>{}).finally(()=>mt(!1)))},[G,y]);return(0,O.jsx)(u.default,{style:le.container,behavior:void 0,keyboardVerticalOffset:90,children:(0,O.jsxs)(N.MarkdownLinksProvider,{knownNarrativeIds:vt,onNarrativePress:pn,onProtocolPress:mn,children:[(0,O.jsx)(d.Stack.Screen,{options:V}),(0,O.jsx)(Y,{nid:y,narrativeSummary:De,narrativeFoldPath:Ke,narrativeRole:Ue,narrativeStatus:Ze,narrativeMcpConnected:tt,narrativeAwaiting:rt,palette:St,narrativeCreatedAt:at,narrativeLastActivity:lt,cost:(0,b.formatCost)(ct?.amount,ct?.unit),archived:Ve,selection:xt,openSwitcher:Nn,onDismiss:Mn,onDownload:an,onTerminate:()=>{hn(),Nt.current?.terminate()},onRevive:()=>{(0,v.revivesAsTwin)(Ue)||hn(),Nt.current?.revive()},onTwin:()=>Oe(!0),onArchiveToggle:Ln,onRecolor:Tt,onShowQr:()=>Be(!0),onIsolateDaemon:_n,isIsolated:In,canIsolate:!In||!!En}),(0,O.jsx)(n.default,{style:le.tabBar,children:F.CANONICAL_TABS.map((e,t)=>{const a=ke===e,s=Ae.has(e),i=a||s,c="chat"===e?"Chat":"terminal"===e?"Terminal":"Files",u="chat"===e?At:"terminal"===e?Et:Lt,d="chat"===e?sn:"terminal"===e?ln:cn;return(0,O.jsxs)(n.default,{style:[le.tab,t>0&&le.tabDivider,a&&le.tabActive],children:[(0,O.jsx)(l.default,{style:le.tabLabel,onPress:()=>dn(e),children:(0,O.jsx)(o.default,{style:[le.tabText,a&&le.tabTextActive],children:c})}),(0,O.jsx)(l.default,{style:le.tabPin,onPress:()=>gn(e),hitSlop:6,children:(0,O.jsx)(o.default,{style:[le.tabPinIcon,s?le.tabPinOn:le.tabPinOff],children:"\ud83d\udccc"})}),(0,O.jsx)(l.default,{style:le.tabArrowPress,onPress:d,disabled:!i,hitSlop:6,children:i?"chat"===e&&Ot?(0,O.jsx)(o.default,{style:le.tabArrowText,children:"\u267b\ufe0f"}):(0,O.jsx)(o.default,{style:le.tabArrowText,children:u?"\u2191":"\u2193"}):(0,O.jsx)(o.default,{style:le.tabArrowText})})]},e)})}),(0,O.jsxs)(n.default,Object.assign({style:{flex:1,overflow:"hidden",position:"relative"}},ze?{onTouchStart:e=>{const t=e.nativeEvent;Rt.current={x:t.pageX,y:t.pageY}},onTouchMove:e=>{if(!Rt.current)return;const t=e.nativeEvent,n=Math.abs(t.pageX-Rt.current.x),o=Math.abs(t.pageY-Rt.current.y);n>15&&n>1.5*o&&!kt.current&&(kt.current=!0)},onTouchEnd:e=>{if(!Rt.current)return;const t=e.nativeEvent,n=t.pageX-Rt.current.x,o=t.pageY-Rt.current.y;Rt.current=null,kt.current=!1;if(!("undefined"!=typeof window&&!!window.getSelection()?.toString())&&Math.abs(n)>60&&Math.abs(n)>1.5*Math.abs(o)){const e=Me[0],t=F.CANONICAL_TABS.indexOf(e),o=n<0?t+1:t-1;o>=0&&o<F.CANONICAL_TABS.length&&dn(F.CANONICAL_TABS[o])}}}:{},{children:[(0,O.jsxs)(n.default,{style:Ne.chat,dataSet:{pane:"chat"},children:[(0,O.jsx)("div",{ref:jt,style:Z,onScroll:e=>{const t=e.currentTarget,n=t.scrollTop>-50;n===Pt.current||Ht.current||(Pt.current=n,It(n));const o=t.scrollHeight-t.clientHeight+t.scrollTop,a=Date.now()-$t.current;o<200&&Wt&&!Xt.current&&!Ut.current&&qt.current&&$t.current>0&&a>Q&&nn()},children:(0,O.jsx)(n.default,{style:[le.list,ee],children:fe.map(e=>(0,O.jsx)("div",{"data-seq":e.seq,children:Pn({item:e})},e.seq))})}),(0,O.jsx)(U,{conn:G,nid:y,loadEvents:tn,chatActive:"chat"===ke,selection:xt,onDeselect:xn})]}),G&&y&&(0,O.jsx)(n.default,{style:Ne.terminal,dataSet:{pane:"terminal"},children:(0,O.jsx)(p.default,{ref:Nt,conn:G,nid:y,active:Me.includes("terminal"),keyboardActive:"terminal"===ke&&!dt&&!He&&null===qe,agentType:Ge,role:Ue,onAtBottomChange:_t,onTwin:()=>Oe(!0),onRevived:e=>W.push((0,F.terminalOnlyHref)(e))})}),G&&y&&(0,O.jsx)(n.default,{style:Ne.files,dataSet:{pane:"files"},children:(0,O.jsx)(E.default,{ref:zt,conn:G,nid:y,path:ye,line:xe,lineEnd:Se,active:Me.includes("files"),onPathChange:wn,onImagePress:$e,onAtBottomChange:Mt})})]})),(0,O.jsx)(i.default,{visible:dt,transparent:!0,animationType:"fade",onRequestClose:()=>ft(!1),children:(0,O.jsx)(l.default,{style:le.switcherOverlay,onPress:()=>ft(!1),children:(0,O.jsxs)(n.default,{style:le.switcherContent,children:[(0,O.jsxs)(n.default,{style:le.switcherTitleRow,children:[(0,O.jsx)(o.default,{style:le.switcherTitle,children:"Switch narrative"}),(0,O.jsx)(o.default,Object.assign({style:le.switcherListLink},(0,P.newTabLinkProps)("/",()=>ft(!1),()=>{ft(!1),W.push("/")}),{children:"All narratives"}))]}),(0,O.jsx)(s.default,{data:ht,keyExtractor:e=>e.id,style:le.switcherList,ListEmptyComponent:(0,O.jsx)(o.default,{style:le.switcherEmpty,children:bt?"Loading\u2026":"No active narratives"}),renderItem:({item:e})=>{const t="ended"===e.status&&!e.mcp_connected,n=(0,x.isAwaiting)({mcpConnected:e.mcp_connected,awaiting:e.awaiting})?(0,x.awaitingGlow)((0,T.glowHueFor)(e.id)):void 0;return(0,O.jsxs)(l.default,{style:[le.switcherItem,e.id===y&&le.switcherItemActive,t&&le.switcherItemEnded,n?{boxShadow:n}:null],onPress:()=>{ft(!1),e.id!==y&&W.push(`/${e.id}`)},children:[(0,O.jsx)(j.NarrativeIdentity,{id:e.id,foldPath:e.fold_path,titleStyle:t?{color:"#666"}:void 0,copyMarginLeft:5,dimmed:t}),(0,O.jsx)(j.NarrativeMetaLine,{role:e.role,cost:(0,b.formatCost)(e.cost_amount,e.cost_unit),createdAt:e.created_at,lastActivity:e.last_activity,status:e.status,mcpConnected:e.mcp_connected,dimmed:t,style:{marginTop:4}}),e.summary&&(0,O.jsx)("div",{style:{position:"relative"},children:(0,O.jsx)("div",{className:"no-scrollbar",style:{overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",WebkitOverflowScrolling:"touch",maskImage:"linear-gradient(to right, #000 calc(100% - 40px), transparent)",WebkitMaskImage:"linear-gradient(to right, #000 calc(100% - 40px), transparent)"},children:(0,O.jsx)(o.default,{style:[le.switcherItemSummary,t&&{color:"#555"}],children:e.summary})})})]})}}),(0,O.jsx)(l.default,{style:le.switcherCancel,onPress:()=>ft(!1),children:(0,O.jsx)(o.default,{style:le.switcherCancelText,children:"Cancel"})})]})})}),(0,O.jsx)(R.default,{visible:Fe,conn:G,path:`/${y}`,view:An,onClose:()=>Be(!1)}),(0,O.jsx)(_.default,{visible:He,conn:G,re:y,defaultFoldPath:Ke,onClose:()=>Oe(!1),onSpawned:e=>{Oe(!1),W.push(`/${e.id}`)}}),(0,O.jsx)(i.default,{visible:null!==qe,transparent:!0,animationType:"fade",onRequestClose:()=>$e(null),children:(0,O.jsxs)(l.default,{style:le.lightboxBackdrop,onPress:()=>$e(null),children:[qe&&(0,O.jsx)(a.default,{source:{uri:qe},style:le.lightboxImage,resizeMode:"contain"}),(0,O.jsx)(o.default,{style:le.lightboxHint,children:"Tap anywhere to close"})]})}),bn&&G&&(0,O.jsx)(N.MarkdownLinksProvider,{onNarrativePress:(e,t)=>{mn(null),pn(e,t)},children:(0,O.jsx)(M.default,{conn:G,target:{source:"protocols",slug:bn},onClose:()=>mn(null)})})]})})}const le=c.default.create({container:{flex:1},glowTransition:{transitionProperty:"box-shadow",transitionDuration:"400ms"},header:{flexDirection:"row",alignItems:"center",backgroundColor:"#1a1a1e",paddingHorizontal:4,paddingVertical:6,borderBottomWidth:c.default.hairlineWidth,borderBottomColor:"rgb(216, 216, 216)",position:"relative",zIndex:10},tabBar:{flexDirection:"row",borderBottomWidth:c.default.hairlineWidth,borderBottomColor:"#555",backgroundColor:"#111"},tab:{width:100/F.CANONICAL_TABS.length+"%",position:"relative"},tabDivider:{borderLeftWidth:c.default.hairlineWidth,borderLeftColor:"#555"},tabActive:{borderBottomWidth:2,borderBottomColor:"#4caf50"},tabLabel:{flex:1,paddingVertical:10,paddingHorizontal:36,alignItems:"center",justifyContent:"center"},tabPin:{position:"absolute",left:0,top:0,bottom:0,width:36,alignItems:"center",justifyContent:"center"},tabPinIcon:{fontSize:12},tabPinOn:{opacity:1},tabPinOff:{opacity:.25},tabArrowPress:{position:"absolute",right:0,top:0,bottom:0,width:36,alignItems:"center",justifyContent:"center"},tabText:{color:"#666",fontSize:14,fontWeight:"600"},tabTextActive:{color:"#4caf50"},tabArrowText:{color:"#8fd4b4",fontSize:16,fontWeight:"400"},headerTitleContainer:{flexDirection:"column",alignItems:"stretch",justifyContent:"center",flex:1,minWidth:0,paddingHorizontal:8},headerSubtitle:{color:"#888",fontSize:12,fontFamily:"monospace",marginTop:1},headerSummary:{color:"#9a9aa0",fontSize:12,lineHeight:12,whiteSpace:"nowrap"},list:{paddingHorizontal:12,paddingVertical:8},bubbleRow:{marginBottom:6,flexDirection:"row"},bubbleRowLeft:{justifyContent:"flex-start"},bubbleRowRight:{justifyContent:"flex-end"},bubbleRowCenter:{justifyContent:"center"},bubble:{maxWidth:"85%",borderRadius:16,paddingHorizontal:14,paddingVertical:10,borderWidth:1.5,borderColor:"transparent",borderStyle:"solid"},bubbleAgent:{backgroundColor:"#1c1c1e",borderBottomLeftRadius:4},bubbleOperator:{backgroundColor:"#1a4a7a",borderBottomRightRadius:4},bubbleForeign:{borderRadius:12},bubbleSystem:{backgroundColor:"transparent",borderWidth:1,borderStyle:"dashed",borderColor:"#3a3a3c",borderRadius:12},bubbleSelected:{borderColor:"#5b9bd5"},bubbleSourceRow:{flexDirection:"row",alignItems:"center",alignSelf:"flex-start",marginBottom:3},bubbleSourcePress:{alignSelf:"flex-start"},bubbleSource:{color:"#4caf50",fontSize:11,fontFamily:"monospace"},bubbleSourceLink:{textDecorationLine:"underline"},bubbleSourceAfterLink:{marginLeft:4},bubbleSourceSystem:{color:"#8a8a8e"},bubbleTimePress:{alignSelf:"flex-end",marginTop:4},bubbleTime:{color:"#666",fontSize:11,textAlign:"right"},inputRow:{flexDirection:"row",padding:8,paddingBottom:8,borderTopWidth:1,borderTopColor:"rgb(216, 216, 216)",backgroundColor:"#1a1a1a",alignItems:"flex-end"},input:{flex:1,backgroundColor:"#111",color:"#e0e0e0",borderRadius:20,paddingHorizontal:16,paddingVertical:8,fontSize:15,borderWidth:1,borderColor:"#555",maxHeight:120,minHeight:36},sendButton:Object.assign({marginLeft:8,width:36,height:36,borderRadius:18,backgroundColor:"#1c1c1e",borderWidth:1,borderColor:"#555",justifyContent:"center",alignItems:"center"},{transition:"box-shadow 160ms ease, border-color 160ms ease"}),sendText:{fontSize:20,lineHeight:20,transform:[{translateX:-1},{translateY:1},{rotate:"45deg"}]},sendTextInactive:{opacity:.35},attachButton:Object.assign({width:36,height:36,borderRadius:18,backgroundColor:"#1c1c1e",justifyContent:"center",alignItems:"center",marginRight:8,borderWidth:1,borderColor:"#555"},{transition:"box-shadow 160ms ease, border-color 160ms ease"}),attachText:{fontSize:20,lineHeight:20,marginTop:-3},circleGlowActive:Object.assign({borderColor:"rgba(255, 130, 180, 0.6)"},{boxShadow:["0 0 10px rgba(255, 130, 180, 0.9)","0 0 25px rgba(255, 110, 165, 0.7)","0 0 50px rgba(255, 100, 155, 0.4)"].join(", ")}),circleGlowSend:Object.assign({borderColor:"rgba(90, 230, 200, 0.6)"},{boxShadow:["0 0 10px rgba(90, 230, 200, 0.9)","0 0 25px rgba(70, 215, 190, 0.7)","0 0 50px rgba(60, 200, 180, 0.4)"].join(", ")}),payloadsContainer:{marginTop:6,gap:4},filePayload:{backgroundColor:"rgba(255,255,255,0.1)",borderRadius:6,paddingHorizontal:10,paddingVertical:6},filePayloadText:{color:"#6cf",fontSize:13},pendingPayloadsRow:{flexDirection:"row",paddingHorizontal:12,paddingTop:8,gap:8,backgroundColor:"#111"},pendingPayloadThumb:{position:"relative",width:60,height:60},pendingPayloadImage:{width:60,height:60,borderRadius:8,borderWidth:1,borderColor:"#555"},pendingPayloadRemove:{position:"absolute",top:-6,right:-6,width:20,height:20,borderRadius:10,backgroundColor:"#c00",justifyContent:"center",alignItems:"center"},pendingPayloadRemoveText:{color:"#fff",fontSize:14,fontWeight:"700",lineHeight:16},switcherOverlay:{flex:1,backgroundColor:"rgba(0,0,0,0.6)",justifyContent:"center",alignItems:"center",padding:24},switcherContent:{backgroundColor:"#1e1e1e",borderRadius:12,paddingTop:20,paddingHorizontal:20,paddingBottom:8,width:"100%",maxWidth:400,maxHeight:"70%"},switcherTitleRow:{flexDirection:"row",alignItems:"baseline",justifyContent:"space-between",marginBottom:16},switcherTitle:{color:"#e0e0e0",fontSize:18,fontWeight:"600"},switcherListLink:{color:"#8fd4b4",fontSize:14,padding:8,margin:-8},switcherList:{flexGrow:0,padding:4,margin:-4},switcherItem:{paddingVertical:12,paddingHorizontal:12,borderRadius:8,backgroundColor:"#2a2a2a",marginBottom:8},switcherItemActive:{outlineWidth:2,outlineStyle:"solid",outlineColor:"#4caf50",outlineOffset:2},switcherItemEnded:{opacity:.5},switcherItemSummary:{color:"#9a9aa0",fontSize:12,lineHeight:12,whiteSpace:"nowrap"},switcherEmpty:{color:"#888",fontSize:14,textAlign:"center",paddingVertical:20},switcherCancel:{paddingVertical:12,alignItems:"center",marginTop:4},switcherCancelText:{color:"#888",fontSize:15},lightboxBackdrop:{flex:1,backgroundColor:"rgba(0, 0, 0, 0.95)",justifyContent:"center",alignItems:"center",padding:8},lightboxImage:{width:"100%",height:"92%"},lightboxHint:{color:"#888",fontSize:14,marginTop:20},reloadButton:{paddingHorizontal:8,paddingVertical:4,marginRight:4},reloadText:Object.assign({fontSize:20},{transition:"text-shadow 160ms ease"}),reloadTextActive:Object.assign({},{textShadow:["0 0 10px rgba(140, 230, 170, 0.9)","0 0 25px rgba(120, 215, 155, 0.7)","0 0 50px rgba(100, 200, 145, 0.4)","0 2px 15px rgba(130, 220, 165, 0.6)"].join(", ")})})},10,[11,13,105,106,113,145,146,153,26,160,116,161,165,736,745,759,762,773,769,755,774,771,770,776,778,780,786,761,958,959,972,779,973,950,752,976,977,747,978,980,6]);
27
27
  __d(function(g,r,i,a,m,e,d){'use strict';m.exports=r(d[0])},11,[12]);
28
28
  __d(function(g,r,_i,a,m,e,d){
29
29
  /**
@@ -836,7 +836,7 @@ __d(function(g,r,i,a,m,e,d){"use strict";var t=this&&this.__importDefault||funct
836
836
  __d(function(g,r,i,a,m,e,d){"use strict";var t=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.Tabs=void 0;const u=t(r(d[0]));e.Tabs=u.default;const n=r(d[1]);u.default.Screen=n.Screen,e.default=u.default},733,[734,295]);
837
837
  __d(function(g,r,i,a,m,e,d){"use strict";var t=r(d[0]),n=r(d[1]);const o=["href"];var s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const l=r(d[2]),u=(s(r(d[3])),r(d[4])),c=r(d[5]),f=r(d[6]),b=r(d[7]),h=r(d[8]),p=(0,l.createBottomTabNavigator)().Navigator,B=(0,c.withLayoutContext)(p,s=>s.map(s=>{if('function'!=typeof s.options&&void 0!==s.options?.href){const l=s.options,{href:c}=l,b=n(l,o);if(b.tabBarButton)throw new Error('Cannot use `href` and `tabBarButton` together.');return Object.assign({},s,{options:Object.assign({},b,{tabBarItemStyle:null==c?{display:'none'}:b.tabBarItemStyle,tabBarButton:n=>{if(null==c)return null;const o='web'===u.Platform.OS?n.children:t.jsx(u.Pressable,{children:n.children});return t.jsx(f.Link,Object.assign({},n,{style:[{display:'flex'},n.style],href:c,asChild:'web'!==u.Platform.OS,children:o}))}})})}return s})),j=Object.assign(n=>t.jsx(B,Object.assign({},n,{UNSTABLE_router:b.tabRouterOverride})),{Screen:B.Screen,Protected:h.Protected});e.default=j},734,[6,167,509,11,342,452,623,735,671]);
838
838
  __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.tabRouterOverride=void 0;function t(t){return'REPLACE'===t.type}e.tabRouterOverride=n=>Object.assign({},n,{getStateForAction:(o,s,c)=>{if(s.target&&s.target!==o.key)return null;if(t(s)){let t=n.getStateForAction(o,Object.assign({},s,{type:'JUMP_TO'}),c);if(!t||void 0===t.index||!Array.isArray(t.history))return null;if(0!==t.index){const n=t.index-1;t=Object.assign({},t,{key:`${t.key}-replace`,history:[...t.history.slice(0,n),...t.history.splice(t.index)]})}return t}return n.getStateForAction(o,s,c)}})},735,[]);
839
- __d(function(g,r,i,a,m,_e,_d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return w}}),_e.useBrane=function(){return(0,s.useContext)(v)};var t=r(_d[0]),n=e(r(_d[1])),o=r(_d[2]),s=r(_d[3]),c=r(_d[4]),l=r(_d[5]),u=r(_d[6]),d=r(_d[7]),h=r(_d[8]),f=e(r(_d[9])),k=r(_d[10]),b=r(_d[11]);(0,k.installNoPan)();const v=(0,s.createContext)({conn:null,connected:!1,daemons:[],activeDaemon:null,activeBraneId:null,switchDaemon:()=>{},switchBrane:()=>{},addDaemon:()=>Promise.reject(new Error("no context")),removeDaemon:()=>{},rotateActiveToken:()=>Promise.reject(new Error("no context")),subscribe:()=>{},unsubscribe:()=>{},subscribeActivity:()=>{},unsubscribeActivity:()=>{},onActivity:()=>()=>{},onHint:()=>()=>{},onStatus:()=>()=>{},onMeta:()=>()=>{},onToolUses:()=>()=>{},protocols:new Set,narrativeIds:new Set});function w(){const[e,k]=(0,s.useState)([]),[w,p]=(0,s.useState)(null),[S,y]=(0,s.useState)(null),[D,C]=(0,s.useState)(!1),[A]=(0,s.useState)(()=>new Set),[_]=(0,s.useState)(()=>new Set),[j]=(0,s.useState)(()=>new Set),[x]=(0,s.useState)(()=>new Set),[I]=(0,s.useState)(()=>new Set),[E,T]=(0,s.useState)(()=>new Set),P=(0,s.useRef)(null),M=e.find(e=>e.id===w)??null,O=(0,s.useMemo)(()=>M?{host:M.host,token:M.token}:null,[M?.host,M?.token]),U=(0,s.useRef)(null),B=(0,s.useCallback)(e=>{const t=(0,h.loadDaemons)().find(t=>t.host===e.host&&t.token===e.token);if(!t)return;t.revoked||k((0,h.updateDaemon)(t.id,{revoked:!0}));const n=U.current;P.current&&n?.host===e.host&&n.token===e.token&&(P.current.close(),P.current=null,U.current=null,C(!1))},[]);(0,s.useEffect)(()=>((0,c.setUnauthorizedListener)(B),()=>(0,c.setUnauthorizedListener)(null)),[B]);const N=(0,s.useCallback)(e=>{P.current?.close(),P.current=null,U.current=null,C(!1);const t=(0,h.loadDaemons)().find(t=>t.host===e.host&&t.token===e.token);if(t?.revoked)return;const n=(0,l.createControlChannel)({conn:e,onMessage:e=>{if("state"===e.type)T(new Set(e.narratives.map(e=>e.id)));else if("new_events"===e.type)for(const t of A)t(e.narrative,e.head_seq);else if("activity"===e.type)for(const t of _)t(e.narrative,e.seq,e.time);else if("status"===e.type)for(const t of j)t(e.narrative,e.status);else if("awaiting"===e.type){const t=e.awaiting?d.AWAITING_STATUS:d.NOT_AWAITING_STATUS;for(const n of j)n(e.narrative,t)}else if("meta"===e.type){const t=null!=e.cost_amount&&e.cost_unit?{amount:e.cost_amount,unit:e.cost_unit}:void 0;for(const n of x)n(e.narrative,e.title,e.summary,t)}else if("tool_uses"===e.type)for(const t of I)t(e.narrative,e.rows,e.rev);else if("tool_uses_resync"===e.type)for(const t of I)t(e.narrative,null,e.rev)},onConnect:()=>C(!0),onDisconnect:()=>C(!1),onSignedOut:()=>B(e)});P.current=n,U.current=e},[A,_,j,x,I,B]);(0,s.useEffect)(()=>{"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js").catch(()=>{})},[]);const $=(0,s.useRef)(null),[z,L]=(0,s.useState)(null),W=(0,s.useCallback)(()=>{const e=(0,h.loadDaemons)(),t=(0,h.getActiveDaemonId)();if(0===e.length)return;k(e);const n=t&&e.find(e=>e.id===t)?t:e[0].id;p(n),(0,h.setActiveDaemonId)(n);const o=e.find(e=>e.id===n);N({host:o.host,token:o.token})},[N]),H=(0,s.useCallback)(()=>{if(window.history.replaceState){const e=window.location.pathname+(0,u.withoutConnectionParams)(window.location.search)+(0,u.withoutConnectionHash)(window.location.hash);window.history.replaceState({},"",e)}(0,c.clearStoredConnection)()},[]);(0,s.useEffect)(()=>{const e=(0,c.parseConnectionParams)();return e?(W(),void(0,c.probeDaemon)(e.host,e.token).then(t=>{const n=(0,h.loadDaemons)().find(e=>e.brane_id===t.brane_id);if(n&&n.token===e.token){const t=Object.assign({},n,{host:e.host,addedAt:n.addedAt});return t.host!==n.host&&((0,h.addDaemon)(t),k((0,h.loadDaemons)())),p(t.id),(0,h.setActiveDaemonId)(t.id),N({host:t.host,token:t.token}),void H()}$.current={host:e.host,token:e.token},L({status:t,host:e.host,isUpdate:void 0!==n})}).catch(()=>{H()})):(W(),()=>{P.current?.close()})},[W,N,H]);const R=(0,s.useCallback)(()=>{const e=z,t=$.current;if(!e||!t)return;const n={id:`${e.status.username}@${e.status.hostname}`,host:t.host,token:t.token,hostname:e.status.hostname,username:e.status.username,brane_id:e.status.brane_id,addedAt:Date.now()},o=(0,h.addDaemon)(n);k(o),p(n.id),(0,h.setActiveDaemonId)(n.id),(0,h.setDefaultDaemonId)(n.id),y(null),N({host:n.host,token:n.token}),$.current=null,L(null),H()},[z,N,H]),q=(0,s.useCallback)(()=>{$.current=null,L(null),H()},[H]),G=(0,s.useCallback)(t=>{const n=e.find(e=>e.id===t);n&&(p(t),(0,h.setActiveDaemonId)(t),(0,h.setDefaultDaemonId)(t),y(null),N({host:n.host,token:n.token}))},[e,N]),Y=(0,s.useCallback)(e=>{y(e)},[]),K=(0,s.useCallback)(async(e,t)=>{const n=await(0,c.probeDaemon)(e,t),o={id:`${n.username}@${n.hostname}`,host:e,token:t,hostname:n.hostname,username:n.username,brane_id:n.brane_id,addedAt:Date.now()},s=(0,h.addDaemon)(o);return k(s),p(o.id),(0,h.setActiveDaemonId)(o.id),N({host:o.host,token:o.token}),o},[N]),F=(0,s.useCallback)(e=>{const t=(0,h.removeDaemon)(e);if(k(t),w===e){const e=t[0]??null;p(e?.id??null),(0,h.setActiveDaemonId)(e?.id??null),e?N({host:e.host,token:e.token}):(P.current?.close(),P.current=null,C(!1))}},[w,N]),J=(0,s.useCallback)(async()=>{const e=M;if(!e)throw new Error("No active daemon");const t={host:e.host,token:e.token},n=await(0,c.rotateToken)(t);P.current?.close(),P.current=null,U.current=null,C(!1);try{await(0,c.probeDaemon)(e.host,n.token)}catch(e){N(t);const n=e instanceof Error&&/\b401\b/.test(e.message);throw new Error(n?"The daemon did not accept the new token: another rotation replaced it before this one was confirmed. Your access is unchanged \u2014 try again, and if it keeps happening, rotate from the shell with `brane token rotate`.":`Could not confirm the new token; your access is unchanged. ${e instanceof Error?e.message:String(e)}`)}const o=Object.assign({},e,{token:n.token,revoked:!1});k((0,h.addDaemon)(o)),N({host:o.host,token:o.token}),(0,c.clearStoredConnection)()},[M,N]);(0,s.useEffect)(()=>{if("undefined"==typeof window)return;const e=e=>{if(e.key!==h.DAEMONS_KEY&&null!==e.key)return;const t=(0,h.loadDaemons)();k(t);const n=t.find(e=>e.id===w);n&&O&&(n.revoked?(P.current?.close(),P.current=null,C(!1)):n.token===O.token&&n.host===O.host||N({host:n.host,token:n.token}))};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[w,O,N]);const Q=(0,s.useCallback)((e,t=0)=>{P.current?.subscribe(e,t)},[]),V=(0,s.useCallback)(e=>{P.current?.unsubscribe(e)},[]),X=(0,s.useCallback)(()=>{P.current?.subscribeActivity()},[]),Z=(0,s.useCallback)(()=>{P.current?.unsubscribeActivity()},[]),ee=(0,s.useCallback)(e=>(_.add(e),()=>{_.delete(e)}),[_]),te=(0,s.useCallback)(e=>(A.add(e),()=>{A.delete(e)}),[A]),ne=(0,s.useCallback)(e=>(j.add(e),()=>{j.delete(e)}),[j]),oe=(0,s.useCallback)(e=>(x.add(e),()=>{x.delete(e)}),[x]),se=(0,s.useCallback)(e=>(I.add(e),()=>{I.delete(e)}),[I]),[ae,re]=(0,s.useState)(()=>new Set);(0,s.useEffect)(()=>{if(!O)return void re(new Set);let e=!1;return(0,c.listProtocols)(O).then(t=>{e||re(new Set(t.map(e=>e.name)))}).catch(()=>{}),()=>{e=!0}},[O]);const ie=(0,s.useMemo)(()=>({conn:O,connected:D,daemons:e,activeDaemon:M,activeBraneId:S,switchDaemon:G,switchBrane:Y,addDaemon:K,removeDaemon:F,rotateActiveToken:J,subscribe:Q,unsubscribe:V,subscribeActivity:X,unsubscribeActivity:Z,onActivity:ee,onHint:te,onStatus:ne,onMeta:oe,onToolUses:se,protocols:ae,narrativeIds:E}),[O,D,e,M,S,G,Y,K,F,J,Q,V,X,Z,ee,te,ne,oe,se,ae]);return(0,b.jsxs)(v.Provider,{value:ie,children:[(0,b.jsxs)(n.default,{children:[(0,b.jsx)("meta",{name:"viewport",content:"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover, shrink-to-fit=no"}),(0,b.jsx)("meta",{name:"apple-mobile-web-app-capable",content:"yes"}),(0,b.jsx)("meta",{name:"apple-mobile-web-app-status-bar-style",content:"black-translucent"}),(0,b.jsx)("link",{rel:"icon",type:"image/svg+xml",href:"/favicon.svg"}),(0,b.jsx)("link",{rel:"apple-touch-icon",href:"/apple-touch-icon.png"}),(0,b.jsx)("link",{rel:"manifest",href:"/manifest.json"}),(0,b.jsx)("style",{children:"html, body { background-color: #111 !important; height: 100%; overflow: hidden; overscroll-behavior: none; } #root { box-sizing: border-box; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); height: var(--brane-vvh, 100%); overflow: hidden; } .no-scrollbar::-webkit-scrollbar { display: none; }"})]}),(0,b.jsx)(t.Stack,{screenOptions:{headerStyle:{backgroundColor:"#1a1a1e"},headerTintColor:"#8fd4b4",headerTitleStyle:{fontSize:17},contentStyle:{backgroundColor:"#121214"}}}),(0,b.jsx)(o.StatusBar,{style:"light"}),(0,b.jsx)(f.default,{pending:z,onConfirm:R,onCancel:q})]})}},736,[161,737,742,11,745,753,747,754,755,756,757,6]);
839
+ __d(function(g,r,i,a,m,_e,_d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return w}}),_e.useBrane=function(){return(0,s.useContext)(v)};var t=r(_d[0]),n=e(r(_d[1])),o=r(_d[2]),s=r(_d[3]),c=r(_d[4]),l=r(_d[5]),u=r(_d[6]),d=r(_d[7]),h=r(_d[8]),f=e(r(_d[9])),k=r(_d[10]),b=r(_d[11]);(0,k.installNoPan)();const v=(0,s.createContext)({conn:null,connected:!1,daemons:[],activeDaemon:null,activeBraneId:null,switchDaemon:()=>{},switchBrane:()=>{},addDaemon:()=>Promise.reject(new Error("no context")),removeDaemon:()=>{},rotateActiveToken:()=>Promise.reject(new Error("no context")),subscribe:()=>{},unsubscribe:()=>{},subscribeActivity:()=>{},unsubscribeActivity:()=>{},onActivity:()=>()=>{},onHint:()=>()=>{},onStatus:()=>()=>{},onMeta:()=>()=>{},onToolUses:()=>()=>{},protocols:new Set,narrativeIds:new Set});function w(){const[e,k]=(0,s.useState)([]),[w,p]=(0,s.useState)(null),[S,y]=(0,s.useState)(null),[D,C]=(0,s.useState)(!1),[A]=(0,s.useState)(()=>new Set),[_]=(0,s.useState)(()=>new Set),[j]=(0,s.useState)(()=>new Set),[x]=(0,s.useState)(()=>new Set),[I]=(0,s.useState)(()=>new Set),[E,T]=(0,s.useState)(()=>new Set),P=(0,s.useRef)(null),M=e.find(e=>e.id===w)??null,O=(0,s.useMemo)(()=>M?{host:M.host,token:M.token}:null,[M?.host,M?.token]),U=(0,s.useRef)(null),B=(0,s.useCallback)(e=>{const t=(0,h.loadDaemons)().find(t=>t.host===e.host&&t.token===e.token);if(!t)return;t.revoked||k((0,h.updateDaemon)(t.id,{revoked:!0}));const n=U.current;P.current&&n?.host===e.host&&n.token===e.token&&(P.current.close(),P.current=null,U.current=null,C(!1))},[]);(0,s.useEffect)(()=>((0,c.setUnauthorizedListener)(B),()=>(0,c.setUnauthorizedListener)(null)),[B]);const N=(0,s.useCallback)(e=>{P.current?.close(),P.current=null,U.current=null,C(!1);const t=(0,h.loadDaemons)().find(t=>t.host===e.host&&t.token===e.token);if(t?.revoked)return;const n=(0,l.createControlChannel)({conn:e,onMessage:e=>{if("state"===e.type)T(new Set(e.narratives.map(e=>e.id)));else if("new_events"===e.type)for(const t of A)t(e.narrative,e.head_seq);else if("activity"===e.type)for(const t of _)t(e.narrative,e.seq,e.time);else if("status"===e.type)for(const t of j)t(e.narrative,e.status);else if("awaiting"===e.type){const t=e.awaiting?d.AWAITING_STATUS:d.NOT_AWAITING_STATUS;for(const n of j)n(e.narrative,t)}else if("meta"===e.type){const t=null!=e.cost_amount&&e.cost_unit?{amount:e.cost_amount,unit:e.cost_unit}:void 0;for(const n of x)n(e.narrative,e.title,e.summary,t)}else if("tool_uses"===e.type)for(const t of I)t(e.narrative,e.rows,e.rev);else if("tool_uses_resync"===e.type)for(const t of I)t(e.narrative,null,e.rev)},onConnect:()=>C(!0),onDisconnect:()=>C(!1),onSignedOut:()=>B(e)});P.current=n,U.current=e},[A,_,j,x,I,B]);(0,s.useEffect)(()=>{"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js").catch(()=>{})},[]);const $=(0,s.useRef)(null),[z,L]=(0,s.useState)(null),W=(0,s.useCallback)(()=>{const e=(0,h.loadDaemons)(),t=(0,h.getActiveDaemonId)();if(0===e.length)return;k(e);const n=t&&e.find(e=>e.id===t)?t:e[0].id;p(n),(0,h.setActiveDaemonId)(n);const o=e.find(e=>e.id===n);N({host:o.host,token:o.token})},[N]),H=(0,s.useCallback)(()=>{if(window.history.replaceState){const e=window.location.pathname+(0,u.withoutConnectionParams)(window.location.search)+(0,u.withoutConnectionHash)(window.location.hash);window.history.replaceState({},"",e)}(0,c.clearStoredConnection)()},[]);(0,s.useEffect)(()=>{const e=(0,c.parseConnectionParams)();return e?(W(),void(0,c.probeDaemon)(e.host,e.token).then(t=>{const n=(0,h.loadDaemons)().find(e=>e.brane_id===t.brane_id);if(n&&n.token===e.token){const t=Object.assign({},n,{host:e.host,addedAt:n.addedAt});return t.host!==n.host&&((0,h.addDaemon)(t),k((0,h.loadDaemons)())),p(t.id),(0,h.setActiveDaemonId)(t.id),N({host:t.host,token:t.token}),void H()}$.current={host:e.host,token:e.token},L({status:t,host:e.host,isUpdate:void 0!==n})}).catch(()=>{H()})):(W(),()=>{P.current?.close()})},[W,N,H]);const R=(0,s.useCallback)(()=>{const e=z,t=$.current;if(!e||!t)return;const n={id:`${e.status.username}@${e.status.hostname}`,host:t.host,token:t.token,hostname:e.status.hostname,username:e.status.username,brane_id:e.status.brane_id,addedAt:Date.now()},o=(0,h.addDaemon)(n);k(o),p(n.id),(0,h.setActiveDaemonId)(n.id),(0,h.setDefaultDaemonId)(n.id),y(null),N({host:n.host,token:n.token}),$.current=null,L(null),H()},[z,N,H]),q=(0,s.useCallback)(()=>{$.current=null,L(null),H()},[H]),G=(0,s.useCallback)(t=>{const n=e.find(e=>e.id===t);n&&(p(t),(0,h.setActiveDaemonId)(t),(0,h.setDefaultDaemonId)(t),y(null),N({host:n.host,token:n.token}))},[e,N]),Y=(0,s.useCallback)(e=>{y(e)},[]),K=(0,s.useCallback)(async(e,t)=>{const n=await(0,c.probeDaemon)(e,t),o={id:`${n.username}@${n.hostname}`,host:e,token:t,hostname:n.hostname,username:n.username,brane_id:n.brane_id,addedAt:Date.now()},s=(0,h.addDaemon)(o);return k(s),p(o.id),(0,h.setActiveDaemonId)(o.id),N({host:o.host,token:o.token}),o},[N]),F=(0,s.useCallback)(e=>{const t=(0,h.removeDaemon)(e);if(k(t),w===e){const e=t[0]??null;p(e?.id??null),(0,h.setActiveDaemonId)(e?.id??null),e?N({host:e.host,token:e.token}):(P.current?.close(),P.current=null,C(!1))}},[w,N]),J=(0,s.useCallback)(async()=>{const e=M;if(!e)throw new Error("No active daemon");const t={host:e.host,token:e.token},n=await(0,c.rotateToken)(t);P.current?.close(),P.current=null,U.current=null,C(!1);try{await(0,c.probeDaemon)(e.host,n.token)}catch(e){N(t);const n=e instanceof Error&&/\b401\b/.test(e.message);throw new Error(n?"The daemon did not accept the new token: another rotation replaced it before this one was confirmed. Your access is unchanged \u2014 try again, and if it keeps happening, rotate from the shell with `brane token rotate`.":`Could not confirm the new token; your access is unchanged. ${e instanceof Error?e.message:String(e)}`)}const o=Object.assign({},e,{token:n.token,revoked:!1});k((0,h.addDaemon)(o)),N({host:o.host,token:o.token}),(0,c.clearStoredConnection)()},[M,N]);(0,s.useEffect)(()=>{if("undefined"==typeof window)return;const e=e=>{if(e.key!==h.DAEMONS_KEY&&null!==e.key)return;const t=(0,h.loadDaemons)();k(t);const n=t.find(e=>e.id===w);n&&O&&(n.revoked?(P.current?.close(),P.current=null,C(!1)):n.token===O.token&&n.host===O.host||N({host:n.host,token:n.token}))};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[w,O,N]);const Q=(0,s.useCallback)((e,t=0)=>{P.current?.subscribe(e,t)},[]),V=(0,s.useCallback)(e=>{P.current?.unsubscribe(e)},[]),X=(0,s.useCallback)(()=>{P.current?.subscribeActivity()},[]),Z=(0,s.useCallback)(()=>{P.current?.unsubscribeActivity()},[]),ee=(0,s.useCallback)(e=>(_.add(e),()=>{_.delete(e)}),[_]),te=(0,s.useCallback)(e=>(A.add(e),()=>{A.delete(e)}),[A]),ne=(0,s.useCallback)(e=>(j.add(e),()=>{j.delete(e)}),[j]),oe=(0,s.useCallback)(e=>(x.add(e),()=>{x.delete(e)}),[x]),se=(0,s.useCallback)(e=>(I.add(e),()=>{I.delete(e)}),[I]),[ae,re]=(0,s.useState)(()=>new Set);(0,s.useEffect)(()=>{if(!O)return void re(new Set);let e=!1;return(0,c.listProtocols)(O).then(t=>{e||re(new Set(t.map(e=>e.name)))}).catch(()=>{}),()=>{e=!0}},[O]);const ie=(0,s.useMemo)(()=>({conn:O,connected:D,daemons:e,activeDaemon:M,activeBraneId:S,switchDaemon:G,switchBrane:Y,addDaemon:K,removeDaemon:F,rotateActiveToken:J,subscribe:Q,unsubscribe:V,subscribeActivity:X,unsubscribeActivity:Z,onActivity:ee,onHint:te,onStatus:ne,onMeta:oe,onToolUses:se,protocols:ae,narrativeIds:E}),[O,D,e,M,S,G,Y,K,F,J,Q,V,X,Z,ee,te,ne,oe,se,ae]);return(0,b.jsxs)(v.Provider,{value:ie,children:[(0,b.jsxs)(n.default,{children:[(0,b.jsx)("meta",{name:"viewport",content:"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover, shrink-to-fit=no"}),(0,b.jsx)("meta",{name:"apple-mobile-web-app-capable",content:"yes"}),(0,b.jsx)("meta",{name:"apple-mobile-web-app-status-bar-style",content:"black-translucent"}),(0,b.jsx)("link",{rel:"icon",type:"image/svg+xml",href:"/favicon.svg"}),(0,b.jsx)("link",{rel:"apple-touch-icon",href:"/apple-touch-icon.png"}),(0,b.jsx)("link",{rel:"manifest",href:"/manifest.json"}),(0,b.jsx)("style",{children:"html, body { background-color: #111 !important; height: 100%; overflow: hidden; overscroll-behavior: none; } #root { box-sizing: border-box; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); height: var(--brane-vvh, 100%); overflow: hidden; } .no-scrollbar::-webkit-scrollbar { display: none; }"})]}),(0,b.jsx)(t.Stack,{screenOptions:{headerStyle:{backgroundColor:"#1a1a1e"},headerTintColor:"#8fd4b4",headerTitleStyle:{fontSize:17},contentStyle:{backgroundColor:"#121214"}}}),(0,b.jsx)(o.StatusBar,{style:"light"}),(0,b.jsx)(f.default,{pending:z,onConfirm:R,onCancel:q})]})}},736,[161,737,742,11,745,754,747,755,751,756,757,6]);
840
840
  __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"default",{enumerable:!0,get:function(){return t.Head}});var t=r(d[0])},737,[738]);
841
841
  __d(function(g,r,i,a,m,e,d){"use strict";var t=r(d[0]),n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.Head=void 0;n(r(d[1]));const u=r(d[2]),l=r(d[3]);function o({children:n}){return t.jsx(u.Helmet,{children:n})}e.Head=({children:n})=>(0,l.useIsFocused)()?t.jsx(o,{children:n}):null,e.Head.Provider=u.HelmetProvider},738,[6,11,739,722]);
842
842
  __d(function(g,r,_i,a,m,e,d){"use strict";var t=r(d[0]);const s=["children"],n=["children"];var i,o=Object.create,c=Object.defineProperty,l=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,u=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,y=(t,s,n,i)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let o of p(s))h.call(t,o)||o===n||c(t,o,{get:()=>s[o],enumerable:!(i=l(s,o))||i.enumerable});return t},b=(t,s,n)=>(n=null!=t?o(u(t)):{},y(!s&&t&&t.__esModule?n:c(n,"default",{value:t,enumerable:!0}),t)),f={};((t,s)=>{for(var n in s)c(t,n,{get:s[n],enumerable:!0})})(f,{Helmet:()=>Oe,HelmetData:()=>ce,HelmetProvider:()=>pe}),m.exports=(i=f,y(c({},"__esModule",{value:!0}),i));var T=b(r(d[1])),O=b(r(d[2])),A=b(r(d[3])),j=b(r(d[1])),C=b(r(d[1])),w=(t=>(t.BASE="base",t.BODY="body",t.HEAD="head",t.HTML="html",t.LINK="link",t.META="meta",t.NOSCRIPT="noscript",t.SCRIPT="script",t.STYLE="style",t.TITLE="title",t.FRAGMENT="Symbol(react.fragment)",t))(w||{}),x={rel:["amphtml","canonical","alternate"]},v={type:["application/ld+json"]},$={charset:"",name:["generator","robots","description"],property:["og:type","og:title","og:url","og:image","og:image:alt","og:description","twitter:url","twitter:title","twitter:description","twitter:image","twitter:image:alt","twitter:card","twitter:site"]},k=Object.values(w),S={accesskey:"accessKey",charset:"charSet",class:"className",contenteditable:"contentEditable",contextmenu:"contextMenu","http-equiv":"httpEquiv",itemprop:"itemProp",tabindex:"tabIndex"},M=Object.entries(S).reduce((t,[s,n])=>(t[n]=s,t),{}),E="data-rh",P="defaultTitle",H="defer",D="encodeSpecialCharacters",L="onChangeClientState",I="titleTemplate",U="prioritizeSeoTags",N=(t,s)=>{for(let n=t.length-1;n>=0;n-=1){const i=t[n];if(Object.prototype.hasOwnProperty.call(i,s))return i[s]}return null},q=t=>{let s=N(t,"title");const n=N(t,I);if(Array.isArray(s)&&(s=s.join("")),n&&s)return n.replace(/%s/g,()=>s);const i=N(t,P);return s||i||void 0},_=t=>N(t,L)||(()=>{}),R=(t,s)=>s.filter(s=>void 0!==s[t]).map(s=>s[t]).reduce((t,s)=>Object.assign({},t,s),{}),z=(t,s)=>s.filter(t=>void 0!==t.base).map(t=>t.base).reverse().reduce((s,n)=>{if(!s.length){const i=Object.keys(n);for(let o=0;o<i.length;o+=1){const c=i[o].toLowerCase();if(-1!==t.indexOf(c)&&n[c])return s.concat(n)}}return s},[]),B=(t,s,n)=>{const i={};return n.filter(s=>{return!!Array.isArray(s[t])||(void 0!==s[t]&&(n=`Helmet: ${t} should be of type "Array". Instead found type "${typeof s[t]}"`,console&&"function"==typeof console.warn&&console.warn(n)),!1);var n}).map(s=>s[t]).reverse().reduce((t,n)=>{const o={};n.filter(t=>{let n;const c=Object.keys(t);for(let i=0;i<c.length;i+=1){const o=c[i],l=o.toLowerCase();-1===s.indexOf(l)||"rel"===n&&"canonical"===t[n].toLowerCase()||"rel"===l&&"stylesheet"===t[l].toLowerCase()||(n=l),-1===s.indexOf(o)||"innerHTML"!==o&&"cssText"!==o&&"itemprop"!==o||(n=o)}if(!n||!t[n])return!1;const l=t[n].toLowerCase();return i[n]||(i[n]={}),o[n]||(o[n]={}),!i[n][l]&&(o[n][l]=!0,!0)}).reverse().forEach(s=>t.push(s));const c=Object.keys(o);for(let t=0;t<c.length;t+=1){const s=c[t],n=Object.assign({},i[s],o[s]);i[s]=n}return t},[]).reverse()},F=(t,s)=>{if(Array.isArray(t)&&t.length)for(let n=0;n<t.length;n+=1){if(t[n][s])return!0}return!1},Y=t=>Array.isArray(t)?t.join(""):t,K=(t,s)=>{const n=Object.keys(t);for(let i=0;i<n.length;i+=1)if(s[n[i]]&&s[n[i]].includes(t[n[i]]))return!0;return!1},G=(t,s)=>Array.isArray(t)?t.reduce((t,n)=>(K(n,s)?t.priority.push(n):t.default.push(n),t),{priority:[],default:[]}):{default:t,priority:[]},W=(t,s)=>Object.assign({},t,{[s]:void 0}),J=["noscript","script","style"],Q=(t,s=!0)=>!1===s?String(t):String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;"),V=t=>Object.keys(t).reduce((s,n)=>{const i=void 0!==t[n]?`${n}="${Q(t[n])}"`:`${n}`;return s?`${s} ${i}`:i},""),X=(t,s,n,i)=>{const o=V(n),c=Y(s);return o?`<${t} ${E}="true" ${o}>${Q(c,i)}</${t}>`:`<${t} ${E}="true">${Q(c,i)}</${t}>`},Z=(t,s,n=!0)=>s.reduce((s,i)=>{const o=i,c=Object.keys(o).filter(t=>!("innerHTML"===t||"cssText"===t)).reduce((t,s)=>{const i=void 0===o[s]?s:`${s}="${Q(o[s],n)}"`;return t?`${t} ${i}`:i},""),l=o.innerHTML||o.cssText||"",p=-1===J.indexOf(t);return`${s}<${t} ${E}="true" ${c}${p?"/>":`>${l}</${t}>`}`},""),ee=(t,s={})=>Object.keys(t).reduce((s,n)=>(s[S[n]||n]=t[n],s),s),te=(t,s,n)=>{const i=ee(n,{key:s,[E]:!0});return[C.default.createElement("title",i,s)]},re=(t,s)=>s.map((s,n)=>{const i={key:n,[E]:!0};return Object.keys(s).forEach(t=>{const n=S[t]||t;if("innerHTML"===n||"cssText"===n){const t=s.innerHTML||s.cssText;i.dangerouslySetInnerHTML={__html:t}}else i[n]=s[t]}),C.default.createElement(t,i)}),se=(t,s,n=!0)=>{switch(t){case"title":return{toComponent:()=>te(0,s.title,s.titleAttributes),toString:()=>X(t,s.title,s.titleAttributes,n)};case"bodyAttributes":case"htmlAttributes":return{toComponent:()=>ee(s),toString:()=>V(s)};default:return{toComponent:()=>re(t,s),toString:()=>Z(t,s,n)}}},ne=({metaTags:t,linkTags:s,scriptTags:n,encode:i})=>{const o=G(t,$),c=G(s,x),l=G(n,v);return{priorityMethods:{toComponent:()=>[...re("meta",o.priority),...re("link",c.priority),...re("script",l.priority)],toString:()=>`${se("meta",o.priority,i)} ${se("link",c.priority,i)} ${se("script",l.priority,i)}`},metaTags:o.default,linkTags:c.default,scriptTags:l.default}},ie=t=>{const{baseTag:s,bodyAttributes:n,encode:i=!0,htmlAttributes:o,noscriptTags:c,styleTags:l,title:p="",titleAttributes:u,prioritizeSeoTags:h}=t;let{linkTags:y,metaTags:b,scriptTags:f}=t,T={toComponent:()=>{},toString:()=>""};return h&&({priorityMethods:T,linkTags:y,metaTags:b,scriptTags:f}=ne(t)),{priority:T,base:se("base",s,i),bodyAttributes:se("bodyAttributes",n,i),htmlAttributes:se("htmlAttributes",o,i),link:se("link",y,i),meta:se("meta",b,i),noscript:se("noscript",c,i),script:se("script",f,i),style:se("style",l,i),title:se("title",{title:p,titleAttributes:u},i)}},oe=[],ae=!("undefined"==typeof window||!window.document||!window.document.createElement),ce=class{instances=[];canUseDOM=ae;value={setHelmet:t=>{this.context.helmet=t},helmetInstances:{get:()=>this.canUseDOM?oe:this.instances,add:t=>{(this.canUseDOM?oe:this.instances).push(t)},remove:t=>{const s=(this.canUseDOM?oe:this.instances).indexOf(t);(this.canUseDOM?oe:this.instances).splice(s,1)}}};constructor(t,s){this.context=t,this.canUseDOM=s||!1,s||(t.helmet=ie({baseTag:[],bodyAttributes:{},encodeSpecialCharacters:!0,htmlAttributes:{},linkTags:[],metaTags:[],noscriptTags:[],scriptTags:[],styleTags:[],title:"",titleAttributes:{}}))}},le=j.default.createContext({}),pe=class t extends j.Component{static canUseDOM=ae;constructor(s){super(s),this.helmetData=new ce(this.props.context||{},t.canUseDOM)}render(){return j.default.createElement(le.Provider,{value:this.helmetData.value},this.props.children)}},ue=r(d[1]),de=b(r(d[4])),he=(t,s)=>{const n=document.head||document.querySelector("head"),i=n.querySelectorAll(`${t}[${E}]`),o=[].slice.call(i),c=[];let l;return s&&s.length&&s.forEach(s=>{const n=document.createElement(t);for(const t in s)if(Object.prototype.hasOwnProperty.call(s,t))if("innerHTML"===t)n.innerHTML=s.innerHTML;else if("cssText"===t)n.styleSheet?n.styleSheet.cssText=s.cssText:n.appendChild(document.createTextNode(s.cssText));else{const i=t,o=void 0===s[i]?"":s[i];n.setAttribute(t,o)}n.setAttribute(E,"true"),o.some((t,s)=>(l=s,n.isEqualNode(t)))?o.splice(l,1):c.push(n)}),o.forEach(t=>t.parentNode?.removeChild(t)),c.forEach(t=>n.appendChild(t)),{oldTags:o,newTags:c}},me=(t,s)=>{const n=document.getElementsByTagName(t)[0];if(!n)return;const i=n.getAttribute(E),o=i?i.split(","):[],c=[...o],l=Object.keys(s);for(const t of l){const i=s[t]||"";n.getAttribute(t)!==i&&n.setAttribute(t,i),-1===o.indexOf(t)&&o.push(t);const l=c.indexOf(t);-1!==l&&c.splice(l,1)}for(let t=c.length-1;t>=0;t-=1)n.removeAttribute(c[t]);o.length===c.length?n.removeAttribute(E):n.getAttribute(E)!==l.join(",")&&n.setAttribute(E,l.join(","))},ge=(t,s)=>{void 0!==t&&document.title!==t&&(document.title=Y(t)),me("title",s)},ye=(t,s)=>{const{baseTag:n,bodyAttributes:i,htmlAttributes:o,linkTags:c,metaTags:l,noscriptTags:p,onChangeClientState:u,scriptTags:h,styleTags:y,title:b,titleAttributes:f}=t;me("body",i),me("html",o),ge(b,f);const T={baseTag:he("base",n),linkTags:he("link",c),metaTags:he("meta",l),noscriptTags:he("noscript",p),scriptTags:he("script",h),styleTags:he("style",y)},O={},A={};Object.keys(T).forEach(t=>{const{newTags:s,oldTags:n}=T[t];s.length&&(O[t]=s),n.length&&(A[t]=T[t].oldTags)}),s&&s(),u(t,O,A)},be=null,fe=t=>{be&&cancelAnimationFrame(be),t.defer?be=requestAnimationFrame(()=>{ye(t,()=>{be=null})}):(ye(t),be=null)},Te=class extends ue.Component{rendered=!1;shouldComponentUpdate(t){return!(0,de.default)(t,this.props)}componentDidUpdate(){this.emitChange()}componentWillUnmount(){const{helmetInstances:t}=this.props.context;t.remove(this),this.emitChange()}emitChange(){const{helmetInstances:t,setHelmet:s}=this.props.context;let n=null;const i=(o=t.get().map(t=>{const s=Object.assign({},t.props);return delete s.context,s}),{baseTag:z(["href"],o),bodyAttributes:R("bodyAttributes",o),defer:N(o,H),encode:N(o,D),htmlAttributes:R("htmlAttributes",o),linkTags:B("link",["rel","href"],o),metaTags:B("meta",["name","charset","http-equiv","property","itemprop"],o),noscriptTags:B("noscript",["innerHTML"],o),onChangeClientState:_(o),scriptTags:B("script",["src","innerHTML"],o),styleTags:B("style",["cssText"],o),title:q(o),titleAttributes:R("titleAttributes",o),prioritizeSeoTags:F(o,U)});var o;pe.canUseDOM?fe(i):ie&&(n=ie(i)),s(n)}init(){if(this.rendered)return;this.rendered=!0;const{helmetInstances:t}=this.props.context;t.add(this),this.emitChange()}render(){return this.init(),null}},Oe=class extends T.Component{static defaultProps={defer:!0,encodeSpecialCharacters:!0,prioritizeSeoTags:!1};shouldComponentUpdate(t){return!(0,O.default)(W(this.props,"helmetData"),W(t,"helmetData"))}mapNestedChildrenToProps(t,s){if(!s)return null;switch(t.type){case"script":case"noscript":return{innerHTML:s};case"style":return{cssText:s};default:throw new Error(`<${t.type} /> elements are self-closing and can not contain children. Refer to our API for more information.`)}}flattenArrayTypeChildren(t,s,n,i){return Object.assign({},s,{[t.type]:[...s[t.type]||[],Object.assign({},n,this.mapNestedChildrenToProps(t,i))]})}mapObjectTypeChildren(t,s,n,i){switch(t.type){case"title":return Object.assign({},s,{[t.type]:i,titleAttributes:Object.assign({},n)});case"body":return Object.assign({},s,{bodyAttributes:Object.assign({},n)});case"html":return Object.assign({},s,{htmlAttributes:Object.assign({},n)});default:return Object.assign({},s,{[t.type]:Object.assign({},n)})}}mapArrayTypeChildrenToProps(t,s){let n=Object.assign({},s);return Object.keys(t).forEach(s=>{n=Object.assign({},n,{[s]:t[s]})}),n}warnOnInvalidChildren(t,s){return(0,A.default)(k.some(s=>t.type===s),"function"==typeof t.type?"You may be attempting to nest <Helmet> components within each other, which is not allowed. Refer to our API for more information.":`Only elements types ${k.join(", ")} are allowed. Helmet does not support rendering <${t.type}> elements. Refer to our API for more information.`),(0,A.default)(!s||"string"==typeof s||Array.isArray(s)&&!s.some(t=>"string"!=typeof t),`Helmet expects a string as a child of <${t.type}>. Did you forget to wrap your children in braces? ( <${t.type}>{\`\`}</${t.type}> ) Refer to our API for more information.`),!0}mapChildrenToProps(n,i){let o={};return T.default.Children.forEach(n,n=>{if(!n||!n.props)return;const c=n.props,{children:l}=c,p=t(c,s),u=Object.keys(p).reduce((t,s)=>(t[M[s]||s]=p[s],t),{});let{type:h}=n;switch("symbol"==typeof h?h=h.toString():this.warnOnInvalidChildren(n,l),h){case"Symbol(react.fragment)":i=this.mapChildrenToProps(l,i);break;case"link":case"meta":case"noscript":case"script":case"style":o=this.flattenArrayTypeChildren(n,o,u,l);break;default:i=this.mapObjectTypeChildren(n,i,u,l)}}),this.mapArrayTypeChildrenToProps(o,i)}render(){const s=this.props,{children:i}=s,o=t(s,n);let c=Object.assign({},o),{helmetData:l}=o;if(i&&(c=this.mapChildrenToProps(i,c)),l&&!(l instanceof ce)){l=new ce(l.context,!0),delete c.helmetData}return l?T.default.createElement(Te,Object.assign({},c,{context:l.value})):T.default.createElement(le.Consumer,null,t=>T.default.createElement(Te,Object.assign({},c,{context:t})))}}},739,[167,11,740,333,741]);
@@ -845,23 +845,23 @@ __d(function(g,r,i,a,m,e,d){m.exports=function(t,n,o,f){var c=o?o.call(f,t,n):vo
845
845
  __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"StatusBar",{enumerable:!0,get:function(){return t.StatusBar}}),Object.defineProperty(e,"setStatusBarStyle",{enumerable:!0,get:function(){return t.setStatusBarStyle}}),Object.defineProperty(e,"setStatusBarHidden",{enumerable:!0,get:function(){return t.setStatusBarHidden}}),Object.defineProperty(e,"setStatusBarBackgroundColor",{enumerable:!0,get:function(){return t.setStatusBarBackgroundColor}}),Object.defineProperty(e,"setStatusBarNetworkActivityIndicatorVisible",{enumerable:!0,get:function(){return t.setStatusBarNetworkActivityIndicatorVisible}}),Object.defineProperty(e,"setStatusBarTranslucent",{enumerable:!0,get:function(){return t.setStatusBarTranslucent}}),Object.defineProperty(e,"StatusBarStyle",{enumerable:!0,get:function(){return n.StatusBarStyle}}),Object.defineProperty(e,"StatusBarAnimation",{enumerable:!0,get:function(){return n.StatusBarAnimation}}),Object.defineProperty(e,"StatusBarProps",{enumerable:!0,get:function(){return n.StatusBarProps}});var t=r(d[0]),n=r(d[1])},742,[743,744]);
846
846
  __d(function(g,r,i,a,m,_e,d){"use strict";function t(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(_e,'__esModule',{value:!0}),_e.StatusBar=function({style:t,hideTransitionAnimation:n,animated:c,hidden:f}){const h=(0,o.default)(),S=e.default.useMemo(()=>s(t,h),[t,h]);return(0,l.jsx)(u.default,{animated:c,hidden:f,barStyle:S,showHideTransition:'none'===n?void 0:n})},_e.setStatusBarStyle=function(t,e){u.default.setBarStyle(s(t),e)},_e.setStatusBarHidden=function(t,e){u.default.setHidden(t,e)},_e.setStatusBarBackgroundColor=function(t,e){},_e.setStatusBarNetworkActivityIndicatorVisible=function(t){},_e.setStatusBarTranslucent=function(t){};var e=t(r(d[0])),n=t(r(d[1])),u=t(r(d[2])),o=t(r(d[3])),l=r(d[4]);function s(t="auto",e=n.default?.getColorScheme()??'light'){e||(e='light');let u=t;return'auto'===t?u='light'===e?'dark':'light':'inverted'===t&&(u='light'===e?'light':'dark'),'light'===u?'light-content':'dark-content'}},743,[11,400,427,441,6]);
847
847
  __d(function(g,r,i,a,m,e,d){},744,[]);
848
- __d(function(g,_r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"formatCost",{enumerable:!0,get:function(){return s.formatCost}}),Object.defineProperty(e,"formatCostTotals",{enumerable:!0,get:function(){return s.formatCostTotals}}),Object.defineProperty(e,"isInlinePayload",{enumerable:!0,get:function(){return c.isInlinePayload}}),e.parseConnectionParams=function(){if("undefined"==typeof window)return null;const t=h();if(t){try{sessionStorage.setItem(u,JSON.stringify(t))}catch{}return t}try{const t=sessionStorage.getItem(u);if(t)return JSON.parse(t)}catch{}return null},e.clearStoredConnection=function(){if("undefined"==typeof window)return;try{sessionStorage.removeItem(u)}catch{}},e.setUnauthorizedListener=function(t){l=t},e.fetchStatus=async function(n){const r=await f(w(n,"/api/status"),{headers:t.NO_HEADERS});if(!r.ok)throw new Error(`Status ${r.status}`);return r.json()},e.fetchNarratives=async function(n,r){const o=new URLSearchParams;r?.archived&&o.set("archived","1");r?.braneIds&&r.braneIds.length>0&&o.set("brane_ids",r.braneIds.join(","));const s=o.toString(),c=w(n,s?`/api/narratives?${s}`:"/api/narratives"),u=await f(c,{headers:t.NO_HEADERS});if(!u.ok)throw new Error(`Narratives ${u.status}`);return(await u.json()).narratives},e.fetchNarrative=async function(n,r){const o=await f(w(n,`/api/narratives/${r}`),{headers:t.NO_HEADERS});if(!o.ok)throw new Error(`Narrative ${o.status}`);return(await o.json()).narrative},e.fetchEvents=async function(n,r,o=0,s){const c=new URLSearchParams({after:String(o)});void 0!==s&&c.set("limit",String(s));const u=await f(w(n,`/api/narratives/${r}/events?${c}`),{headers:t.NO_HEADERS});if(!u.ok)throw new Error(`Events ${u.status}`);return u.json()},e.fetchToolUse=async function(n,r,o){const s=await f(w(n,`/api/narratives/${r}/tool_uses/${encodeURIComponent(o)}`),{headers:t.NO_HEADERS});if(!s.ok)throw new Error(`Tool use ${s.status}`);return(await s.json()).tool_use},e.fetchToolUseWindow=E,e.fetchToolUsesSince=y,e.fetchAllToolUseWindow=async function(t,n,r,o){let s;for(let c=0;c<_;c++){const c=await E(t,n,Object.assign({},r,{after:s}));if(o(c.tool_uses),!c.truncated||!c.next_cursor)return;s=c.next_cursor}console.warn(`[tool_uses] stopped paging window for ${n} after ${_} pages`)},e.fetchAllToolUsesSince=async function(t,n,r,o){let s=r;for(let r=0;r<_;r++){const r=await y(t,n,{sinceRev:s});if(o(r.tool_uses),!r.truncated||null==r.next_since_rev)return;s=r.next_since_rev}console.warn(`[tool_uses] stopped catching up ${n} after ${_} pages`)},e.fetchEventsBefore=async function(n,r,o,s=50){const c=new URLSearchParams({before:String(o),limit:String(s)}),u=await f(w(n,`/api/narratives/${r}/events?${c}`),{headers:t.NO_HEADERS});if(!u.ok)throw new Error(`Events ${u.status}`);return u.json()},e.sendSignal=async function(n,r,o,s="web",c,u){const h={content:o,source:s};c&&c.length>0&&(h.payloads=c);u&&u.length>0&&(h.re=u);const l=await f(w(n,`/api/narratives/${r}/signal`),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify(h)});if(!l.ok)throw new Error(`Signal ${l.status}`);return l.json()},e.spawnAgent=async function(n,r,s,c="worker",u,h,l){const S={agent:r,fold_path:s,role:c};u&&(S.model=u);h&&h.length>0&&(S.extra_args=h);l&&(S.re=l);const E=(0,o.lastTerminalSize)();E&&(S.terminal_size=E);const y=await f(w(n,"/api/spawn"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify(S)});if(!y.ok){const t=await y.json().catch(()=>({}));throw new Error(t.error??`Spawn ${y.status}`)}return(await y.json()).narrative},e.runUtility=async function(n,r,s){const c=await f(w(n,"/api/run"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify({command:r,fold_path:s,terminal_size:(0,o.lastTerminalSize)()??void 0})});if(!c.ok){const t=await c.json().catch(()=>({}));throw new Error(t.error??`Run ${c.status}`)}return(await c.json()).narrative},e.fetchRunHistory=async function(n){const r=await f(w(n,"/api/run-history"),{headers:t.NO_HEADERS});if(!r.ok)throw new Error(`Run history ${r.status}`);return(await r.json()).history},e.fetchSpawnHistory=async function(n){const r=await f(w(n,"/api/spawn-history"),{headers:t.NO_HEADERS});if(!r.ok)throw new Error(`Spawn history ${r.status}`);return(await r.json()).history},e.fetchFolds=async function(n,r=!1){const o=await f(w(n,r?"/api/folds?archived=1":"/api/folds"),{headers:t.NO_HEADERS});if(!o.ok)throw new Error(`Folds ${o.status}`);return(await o.json()).folds},e.addFold=async function(n,r){const o=await f(w(n,"/api/folds"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify({path:r})});if(!o.ok){const t=await o.json().catch(()=>({}));throw new Error(t.error??`Add fold ${o.status}`)}return(await o.json()).fold},e.archiveFold=async function(n,r,o=!0){const s=await f(w(n,"/api/folds/archive"),{method:"PATCH",headers:t.JSON_HEADERS,body:JSON.stringify({path:r,archived:o})});if(!s.ok){const t=await s.json().catch(()=>({}));throw new Error(t.error??`Archive fold ${s.status}`)}return s.json()},e.fetchBranes=async function(n){const r=await f(w(n,"/api/branes"),{headers:t.NO_HEADERS});if(!r.ok)throw new Error(`Branes ${r.status}`);return(await r.json()).branes},e.reviveNarrative=async function(n,r,o){const s={};o&&(s.agent=o);const c=await f(w(n,`/api/revive/${r}`),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify(s)});if(!c.ok){const t=await c.json().catch(()=>({}));throw new Error(t.error??`Revive ${c.status}`)}return c.json()},e.archiveNarrative=async function(n,r,o=!0){const s=await f(w(n,`/api/narratives/${r}/archive`),{method:"PATCH",headers:t.JSON_HEADERS,body:JSON.stringify({archived:o})});if(!s.ok)throw new Error(`Archive ${s.status}`);return s.json()},e.searchNarratives=async function(n,r,o=20,s){const c={query:r,limit:o};s&&s.length>0&&(c.brane_ids=s);const u=await f(w(n,"/api/search"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify(c)});if(!u.ok){const t=await u.json().catch(()=>({}));throw new Error(t.error??`Search ${u.status}`)}return u.json()},e.searchWiki=async function(n,r,o=10,s){const c={query:r,limit:o};s&&s.length>0&&(c.brane_ids=s);const u=await f(w(n,"/api/wiki/search"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify(c)});if(!u.ok){const t=await u.json().catch(()=>({}));throw new Error(t.error??`Wiki search ${u.status}`)}return u.json()},e.readWikiSection=async function(n,r){const o=new URLSearchParams({slug:r.slug});r.source&&o.set("source",r.source);r.anchor&&o.set("anchor",r.anchor);null!=r.window&&o.set("window",String(r.window));r.braneIds&&r.braneIds.length>0&&o.set("brane_ids",r.braneIds.join(","));const s=await f(w(n,`/api/wiki/read?${o.toString()}`),{headers:t.NO_HEADERS});if(!s.ok){const t=await s.json().catch(()=>({}));throw new Error(t.error??`Wiki read ${s.status}`)}return s.json()},e.listProtocols=async function(n){const r=await f(w(n,"/api/protocols"),{headers:t.NO_HEADERS});if(!r.ok){const t=await r.json().catch(()=>({}));throw new Error(t.error??`Protocols ${r.status}`)}return(await r.json()).protocols??[]},e.wikiAssetUrl=function(t,n,r){const o=new URLSearchParams({source:n,path:r});return w(t,`/api/wiki/asset?${o.toString()}`)},e.payloadUrl=function(t,n){return w(t,`/api/payloads/${n}`)},e.fetchFiles=async function(n,r,o,s){const c=new URLSearchParams({nid:r,path:o});void 0!==s&&c.set("offset",String(s));const u=await f(w(n,`/api/files?${c}`),{headers:t.NO_HEADERS});if(!u.ok){const t=await u.json().catch(()=>({}));throw new Error(t.error??`Files ${u.status}`)}return u.json()},e.streamFileFind=async function(n,r,o,s,c,u,h){const l=new URLSearchParams({nid:r,path:o,q:s});c>0&&l.set("from",String(c));const S=await f(w(n,`/api/files/find?${l}`),{headers:t.NO_HEADERS,signal:h});if(!S.ok){const t=await S.json().catch(()=>({}));throw new Error(t.error??`Find ${S.status}`)}if(!S.body)throw new Error("Find: no response body");const E=S.body.getReader(),y=new TextDecoder;let p="";try{for(;;){const{done:t,value:n}=await E.read();if(t)break;let r;for(p+=y.decode(n,{stream:!0});(r=p.indexOf("\n"))>=0;){const t=p.slice(0,r);p=p.slice(r+1),t&&u(JSON.parse(t))}}}finally{E.releaseLock()}},e.filesRawUrl=function(t,n,r){const o=new URLSearchParams({nid:n,path:r,raw:"1"});return w(t,`/api/files?${o}`)},e.fetchNarrativeExportHtml=async function(n,o,s=0,c,u="only"){const h=(0,r.formatSeqParam)(c),l=h?(0,r.formatSeqModeParam)(u):null,S=(s>0?`&palette=${s}`:"")+(h?`&seqs=${h}`:"")+(l?`&seqs_mode=${l}`:""),E=await f(w(n,`/api/narratives/${o}/export?format=html${S}`),{headers:t.NO_HEADERS});if(!E.ok){const t=await E.text().catch(()=>"");throw new Error(t||`Export ${E.status}`)}return E.blob()},e.fetchHighlight=async function(n,r,o){const s=await f(w(n,"/api/highlight"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify({content:r,lang:o})});if(!s.ok)return null;const c=await s.json().catch(()=>null);return c?.highlight??null},e.fetchDiagram=async function(n,r){const o=await f(w(n,"/api/diagram"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify({source:r})});if(!o.ok)return null;const s=await o.json().catch(()=>null);return s?.diagram??null},e.fetchFileList=async function(n,r){const o=new URLSearchParams({nid:r}),s=await f(w(n,`/api/files/list?${o}`),{headers:t.NO_HEADERS});if(!s.ok){const t=await s.json().catch(()=>({}));throw new Error(t.error??`File list ${s.status}`)}return s.json()},e.rotateToken=async function(n){const r=await f(w(n,"/api/token/rotate"),{method:"POST",headers:t.NO_HEADERS});if(!r.ok)throw new Error(`Rotate ${r.status}`);return r.json()},e.mintDeviceToken=async function(n){const r=await f(w(n,"/api/tokens"),{method:"POST",headers:t.NO_HEADERS});if(404===r.status)return null;if(!r.ok){const t=await r.json().catch(()=>({}));throw new Error(t.error??`Mint ${r.status}`)}const o=await r.json();return{token:o.token,validForMs:o.validForMs}},e.listDeviceTokens=async function(n){const r=await f(w(n,"/api/tokens"),{headers:t.NO_HEADERS});if(404===r.status)return null;if(!r.ok)throw new Error(`Devices ${r.status}`);return(await r.json()).tokens},e.revokeDeviceToken=async function(n,r,o=[]){const s=o.length?`?also=${o.map(encodeURIComponent).join(",")}`:"",c=await f(w(n,`/api/tokens/${encodeURIComponent(r)}/revoke${s}`),{method:"POST",headers:t.NO_HEADERS});if(c.ok||404===c.status)return;const u=await c.json().catch(()=>({}));throw new Error(u.error??`Revoke ${c.status}`)},e.probeDaemon=async function(n,r){const o={host:n,token:r},s=await f(w(o,"/api/status"),{headers:t.NO_HEADERS});if(!s.ok)throw new Error(`Status ${s.status}`);return s.json()};var t=_r(d[0]),n=_r(d[1]),r=_r(d[2]),o=_r(d[3]),s=_r(d[4]),c=_r(d[5]);const u="brane_conn";function h(){const t=new URLSearchParams(window.location.hash.slice(1)),n=new URLSearchParams(window.location.search),r=t.get("token")??n.get("token");if(!r)return null;return{host:t.get("host")??n.get("host")??window.location.host,token:r}}function w(n,r){return`${"https:"===window.location.protocol?"https":"http"}://${n.host}${(0,t.withToken)(r,n.token)}`}function f(n,r,o=t.DEFAULT_TIMEOUT_MS){const s=(0,t.isRetryableMethod)(r.method??"GET")?t.MAX_ATTEMPTS:1,c=r.signal,u=async h=>{const w=new AbortController,f=setTimeout(()=>w.abort(),o);c&&(c.aborted?w.abort():c.addEventListener("abort",()=>w.abort(),{once:!0}));try{const t=await fetch(n,Object.assign({},r,{signal:w.signal}));if(401===t.status&&l){const t=S(n);t&&l(t)}return t}catch(n){if(h+1<s&&(0,t.isRetryableError)(n)&&!c?.aborted)return await new Promise(n=>setTimeout(n,(0,t.retryDelayMs)(h))),u(h+1);throw n}finally{clearTimeout(f)}};return u(0)}!(function(){if("undefined"==typeof window||!window.history?.replaceState)return;const t=h();if(!t)return;try{sessionStorage.setItem(u,JSON.stringify(t))}catch{return}const r=window.location.pathname+(0,n.withoutConnectionParams)(window.location.search)+(0,n.withoutConnectionHash)(window.location.hash);window.history.replaceState(window.history.state,"",r)})();let l=null;function S(t){try{const n=new URL(t),r=n.searchParams.get("token");return r?{host:n.host,token:r}:null}catch{return null}}async function E(t,n,r={}){const o=new URLSearchParams;return void 0!==r.afterSeqGte&&o.set("after_seq_gte",String(r.afterSeqGte)),void 0!==r.afterSeqLt&&o.set("after_seq_lt",String(r.afterSeqLt)),void 0!==r.limit&&o.set("limit",String(r.limit)),r.after&&(o.set("after_cursor_seq",String(r.after.after_seq)),o.set("after_cursor_started_at",String(r.after.started_at)),o.set("after_cursor_dedup_key",r.after.dedup_key)),p(t,n,o)}async function y(t,n,r){const o=new URLSearchParams;return o.set("since_rev",String(r.sinceRev)),void 0!==r.limit&&o.set("limit",String(r.limit)),p(t,n,o)}async function p(n,r,o){const s=await f(w(n,`/api/narratives/${r}/tool_uses?${o}`),{headers:t.NO_HEADERS});if(!s.ok)throw new Error(`ToolUses ${s.status}`);return s.json()}const _=100},745,[746,747,748,749,751,752]);
848
+ __d(function(g,_r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"formatCost",{enumerable:!0,get:function(){return c.formatCost}}),Object.defineProperty(e,"formatCostTotals",{enumerable:!0,get:function(){return c.formatCostTotals}}),Object.defineProperty(e,"isInlinePayload",{enumerable:!0,get:function(){return u.isInlinePayload}}),e.parseConnectionParams=function(){if("undefined"==typeof window)return null;const t=w();if(t){try{sessionStorage.setItem(h,JSON.stringify(t))}catch{}return t}try{const t=sessionStorage.getItem(h);if(t)return JSON.parse(t)}catch{}return null},e.clearStoredConnection=function(){if("undefined"==typeof window)return;try{sessionStorage.removeItem(h)}catch{}},e.setUnauthorizedListener=function(t){S=t},e.fetchStatus=async function(n){const r=await l(f(n,"/api/status"),{headers:t.NO_HEADERS});if(!r.ok)throw new Error(`Status ${r.status}`);return r.json()},e.fetchNarratives=async function(n,r){const o=new URLSearchParams;r?.archived&&o.set("archived","1");r?.braneIds&&r.braneIds.length>0&&o.set("brane_ids",r.braneIds.join(","));const s=o.toString(),c=f(n,s?`/api/narratives?${s}`:"/api/narratives"),u=await l(c,{headers:t.NO_HEADERS});if(!u.ok)throw new Error(`Narratives ${u.status}`);return(await u.json()).narratives},e.fetchNarrative=async function(n,r){const o=await l(f(n,`/api/narratives/${r}`),{headers:t.NO_HEADERS});if(!o.ok)throw new Error(`Narrative ${o.status}`);return(await o.json()).narrative},e.fetchEvents=async function(n,r,o=0,s){const c=new URLSearchParams({after:String(o)});void 0!==s&&c.set("limit",String(s));const u=await l(f(n,`/api/narratives/${r}/events?${c}`),{headers:t.NO_HEADERS});if(!u.ok)throw new Error(`Events ${u.status}`);return u.json()},e.fetchToolUse=async function(n,r,o){const s=await l(f(n,`/api/narratives/${r}/tool_uses/${encodeURIComponent(o)}`),{headers:t.NO_HEADERS});if(!s.ok)throw new Error(`Tool use ${s.status}`);return(await s.json()).tool_use},e.fetchToolUseWindow=y,e.fetchToolUsesSince=p,e.fetchAllToolUseWindow=async function(t,n,r,o){let s;for(let c=0;c<v;c++){const c=await y(t,n,Object.assign({},r,{after:s}));if(o(c.tool_uses),!c.truncated||!c.next_cursor)return;s=c.next_cursor}console.warn(`[tool_uses] stopped paging window for ${n} after ${v} pages`)},e.fetchAllToolUsesSince=async function(t,n,r,o){let s=r;for(let r=0;r<v;r++){const r=await p(t,n,{sinceRev:s});if(o(r.tool_uses),!r.truncated||null==r.next_since_rev)return;s=r.next_since_rev}console.warn(`[tool_uses] stopped catching up ${n} after ${v} pages`)},e.fetchEventsBefore=async function(n,r,o,s=50){const c=new URLSearchParams({before:String(o),limit:String(s)}),u=await l(f(n,`/api/narratives/${r}/events?${c}`),{headers:t.NO_HEADERS});if(!u.ok)throw new Error(`Events ${u.status}`);return u.json()},e.sendSignal=async function(n,r,o,s="web",c,u){const h={content:o,source:s};c&&c.length>0&&(h.payloads=c);u&&u.length>0&&(h.re=u);const w=await l(f(n,`/api/narratives/${r}/signal`),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify(h)});if(!w.ok)throw new Error(`Signal ${w.status}`);return w.json()},e.spawnAgent=async function(n,r,s,c="worker",u,h,w){const S={agent:r,fold_path:s,role:c};u&&(S.model=u);h&&h.length>0&&(S.extra_args=h);w&&(S.re=w);const E=(0,o.lastTerminalSize)();E&&(S.terminal_size=E);const y=await l(f(n,"/api/spawn"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify(S)});if(!y.ok){const t=await y.json().catch(()=>({}));throw new Error(t.error??`Spawn ${y.status}`)}return(await y.json()).narrative},e.runUtility=async function(n,r,s){const c=await l(f(n,"/api/run"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify({command:r,fold_path:s,terminal_size:(0,o.lastTerminalSize)()??void 0})});if(!c.ok){const t=await c.json().catch(()=>({}));throw new Error(t.error??`Run ${c.status}`)}return(await c.json()).narrative},e.fetchRunHistory=async function(n){const r=await l(f(n,"/api/run-history"),{headers:t.NO_HEADERS});if(!r.ok)throw new Error(`Run history ${r.status}`);return(await r.json()).history},e.fetchSpawnHistory=async function(n){const r=await l(f(n,"/api/spawn-history"),{headers:t.NO_HEADERS});if(!r.ok)throw new Error(`Spawn history ${r.status}`);return(await r.json()).history},e.fetchFolds=async function(n,r=!1){const o=await l(f(n,r?"/api/folds?archived=1":"/api/folds"),{headers:t.NO_HEADERS});if(!o.ok)throw new Error(`Folds ${o.status}`);return(await o.json()).folds},e.addFold=async function(n,r){const o=await l(f(n,"/api/folds"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify({path:r})});if(!o.ok){const t=await o.json().catch(()=>({}));throw new Error(t.error??`Add fold ${o.status}`)}return(await o.json()).fold},e.archiveFold=async function(n,r,o=!0){const s=await l(f(n,"/api/folds/archive"),{method:"PATCH",headers:t.JSON_HEADERS,body:JSON.stringify({path:r,archived:o})});if(!s.ok){const t=await s.json().catch(()=>({}));throw new Error(t.error??`Archive fold ${s.status}`)}return s.json()},e.fetchBranes=async function(n){const r=await l(f(n,"/api/branes"),{headers:t.NO_HEADERS});if(!r.ok)throw new Error(`Branes ${r.status}`);return(await r.json()).branes},e.reviveNarrative=async function(n,r,o){const s={};o&&(s.agent=o);const c=await l(f(n,`/api/revive/${r}`),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify(s)});if(!c.ok){const t=await c.json().catch(()=>({}));throw new Error(t.error??`Revive ${c.status}`)}return c.json()},e.archiveNarrative=async function(n,r,o=!0){const s=await l(f(n,`/api/narratives/${r}/archive`),{method:"PATCH",headers:t.JSON_HEADERS,body:JSON.stringify({archived:o})});if(!s.ok)throw new Error(`Archive ${s.status}`);return s.json()},e.searchNarratives=async function(n,r,o=20,s){const c={query:r,limit:o};s&&s.length>0&&(c.brane_ids=s);const u=await l(f(n,"/api/search"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify(c)});if(!u.ok){const t=await u.json().catch(()=>({}));throw new Error(t.error??`Search ${u.status}`)}return u.json()},e.searchWiki=async function(n,r,o=10,s){const c={query:r,limit:o};s&&s.length>0&&(c.brane_ids=s);const u=await l(f(n,"/api/wiki/search"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify(c)});if(!u.ok){const t=await u.json().catch(()=>({}));throw new Error(t.error??`Wiki search ${u.status}`)}return u.json()},e.readWikiSection=async function(n,r){const o=new URLSearchParams({slug:r.slug});r.source&&o.set("source",r.source);r.anchor&&o.set("anchor",r.anchor);null!=r.window&&o.set("window",String(r.window));r.braneIds&&r.braneIds.length>0&&o.set("brane_ids",r.braneIds.join(","));const s=await l(f(n,`/api/wiki/read?${o.toString()}`),{headers:t.NO_HEADERS});if(!s.ok){const t=await s.json().catch(()=>({}));throw new Error(t.error??`Wiki read ${s.status}`)}return s.json()},e.listProtocols=async function(n){const r=await l(f(n,"/api/protocols"),{headers:t.NO_HEADERS});if(!r.ok){const t=await r.json().catch(()=>({}));throw new Error(t.error??`Protocols ${r.status}`)}return(await r.json()).protocols??[]},e.wikiAssetUrl=function(t,n,r){const o=new URLSearchParams({source:n,path:r});return f(t,`/api/wiki/asset?${o.toString()}`)},e.payloadUrl=function(t,n){return f(t,`/api/payloads/${n}`)},e.fetchFiles=async function(n,r,o,s){const c=new URLSearchParams({nid:r,path:o});void 0!==s&&c.set("offset",String(s));const u=await l(f(n,`/api/files?${c}`),{headers:t.NO_HEADERS});if(!u.ok){const t=await u.json().catch(()=>({}));throw new Error(t.error??`Files ${u.status}`)}return u.json()},e.streamFileFind=async function(n,r,o,s,c,u,h){const w=new URLSearchParams({nid:r,path:o,q:s});c>0&&w.set("from",String(c));const S=await l(f(n,`/api/files/find?${w}`),{headers:t.NO_HEADERS,signal:h});if(!S.ok){const t=await S.json().catch(()=>({}));throw new Error(t.error??`Find ${S.status}`)}if(!S.body)throw new Error("Find: no response body");const E=S.body.getReader(),y=new TextDecoder;let p="";try{for(;;){const{done:t,value:n}=await E.read();if(t)break;let r;for(p+=y.decode(n,{stream:!0});(r=p.indexOf("\n"))>=0;){const t=p.slice(0,r);p=p.slice(r+1),t&&u(JSON.parse(t))}}}finally{E.releaseLock()}},e.filesRawUrl=function(t,n,r){const o=new URLSearchParams({nid:n,path:r,raw:"1"});return f(t,`/api/files?${o}`)},e.fetchNarrativeExportHtml=async function(n,o,s=0,c,u="only"){const h=(0,r.formatSeqParam)(c),w=h?(0,r.formatSeqModeParam)(u):null,S=(s>0?`&palette=${s}`:"")+(h?`&seqs=${h}`:"")+(w?`&seqs_mode=${w}`:""),E=await l(f(n,`/api/narratives/${o}/export?format=html${S}`),{headers:t.NO_HEADERS});if(!E.ok){const t=await E.text().catch(()=>"");throw new Error(t||`Export ${E.status}`)}return E.blob()},e.fetchHighlight=async function(n,r,o){const s=await l(f(n,"/api/highlight"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify({content:r,lang:o})});if(!s.ok)return null;const c=await s.json().catch(()=>null);return c?.highlight??null},e.fetchDiagram=async function(n,r){const o=await l(f(n,"/api/diagram"),{method:"POST",headers:t.JSON_HEADERS,body:JSON.stringify({source:r})});if(!o.ok)return null;const s=await o.json().catch(()=>null);return s?.diagram??null},e.fetchFileList=async function(n,r){const o=new URLSearchParams({nid:r}),s=await l(f(n,`/api/files/list?${o}`),{headers:t.NO_HEADERS});if(!s.ok){const t=await s.json().catch(()=>({}));throw new Error(t.error??`File list ${s.status}`)}return s.json()},e.rotateToken=async function(n){const r=await l(f(n,"/api/token/rotate"),{method:"POST",headers:t.NO_HEADERS});if(!r.ok)throw new Error(`Rotate ${r.status}`);return r.json()},e.mintDeviceToken=async function(n){const r=await l(f(n,"/api/tokens"),{method:"POST",headers:t.NO_HEADERS});if(404===r.status)return null;if(!r.ok){const t=await r.json().catch(()=>({}));throw new Error(t.error??`Mint ${r.status}`)}const o=await r.json();return{token:o.token,validForMs:o.validForMs}},e.listDeviceTokens=async function(n){const r=await l(f(n,"/api/tokens"),{headers:t.NO_HEADERS});if(404===r.status)return null;if(!r.ok)throw new Error(`Devices ${r.status}`);return(await r.json()).tokens},e.revokeDeviceToken=async function(n,r,o=[]){const s=o.length?`?also=${o.map(encodeURIComponent).join(",")}`:"",c=await l(f(n,`/api/tokens/${encodeURIComponent(r)}/revoke${s}`),{method:"POST",headers:t.NO_HEADERS});if(c.ok||404===c.status)return;const u=await c.json().catch(()=>({}));throw new Error(u.error??`Revoke ${c.status}`)},e.probeDaemon=async function(n,r){const o={host:n,token:r},s=await l(f(o,"/api/status"),{headers:t.NO_HEADERS});if(!s.ok)throw new Error(`Status ${s.status}`);return s.json()};var t=_r(d[0]),n=_r(d[1]),r=_r(d[2]),o=_r(d[3]),s=_r(d[4]),c=_r(d[5]),u=_r(d[6]);const h="brane_conn";function w(){const t=new URLSearchParams(window.location.hash.slice(1)),n=new URLSearchParams(window.location.search),r=t.get("token")??n.get("token");if(!r)return null;return{host:t.get("host")??n.get("host")??window.location.host,token:r}}function f(n,r){return`${"https:"===window.location.protocol?"https":"http"}://${n.host}${(0,t.withToken)(r,n.token)}`}function l(n,r,o=t.DEFAULT_TIMEOUT_MS){const s=(0,t.isRetryableMethod)(r.method??"GET")?t.MAX_ATTEMPTS:1,c=r.signal,u=async h=>{const w=new AbortController,f=setTimeout(()=>w.abort(),o);c&&(c.aborted?w.abort():c.addEventListener("abort",()=>w.abort(),{once:!0}));try{const t=await fetch(n,Object.assign({},r,{signal:w.signal}));if(401===t.status&&S){const t=E(n);t&&S(t)}return t}catch(n){if(h+1<s&&(0,t.isRetryableError)(n)&&!c?.aborted)return await new Promise(n=>setTimeout(n,(0,t.retryDelayMs)(h))),u(h+1);throw n}finally{clearTimeout(f)}};return u(0)}!(function(){if("undefined"==typeof window||!window.history?.replaceState)return;const t=(0,n.daemonFromHash)(window.location.hash);t&&(0,s.adoptDaemonByBraneId)(t);const r=w();if(!r&&!t)return;if(r)try{sessionStorage.setItem(h,JSON.stringify(r))}catch{return}const o=window.location.pathname+(0,n.withoutConnectionParams)(window.location.search)+(0,n.withoutConnectionHash)(window.location.hash);window.history.replaceState(window.history.state,"",o)})();let S=null;function E(t){try{const n=new URL(t),r=n.searchParams.get("token");return r?{host:n.host,token:r}:null}catch{return null}}async function y(t,n,r={}){const o=new URLSearchParams;return void 0!==r.afterSeqGte&&o.set("after_seq_gte",String(r.afterSeqGte)),void 0!==r.afterSeqLt&&o.set("after_seq_lt",String(r.afterSeqLt)),void 0!==r.limit&&o.set("limit",String(r.limit)),r.after&&(o.set("after_cursor_seq",String(r.after.after_seq)),o.set("after_cursor_started_at",String(r.after.started_at)),o.set("after_cursor_dedup_key",r.after.dedup_key)),_(t,n,o)}async function p(t,n,r){const o=new URLSearchParams;return o.set("since_rev",String(r.sinceRev)),void 0!==r.limit&&o.set("limit",String(r.limit)),_(t,n,o)}async function _(n,r,o){const s=await l(f(n,`/api/narratives/${r}/tool_uses?${o}`),{headers:t.NO_HEADERS});if(!s.ok)throw new Error(`ToolUses ${s.status}`);return s.json()}const v=100},745,[746,747,748,749,751,752,753]);
849
849
  __d(function(g,r,_i,a,_m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.requiresPreflight=function(c,i={}){if(!o.has(c.toUpperCase()))return!0;for(const[o,c]of Object.entries(i)){const i=o.toLowerCase();if(!n.has(i))return!0;if("content-type"===i){const n=c.split(";")[0].trim().toLowerCase();if(!t.includes(n))return!0}}return!1},Object.defineProperty(e,"NO_HEADERS",{enumerable:!0,get:function(){return c}}),Object.defineProperty(e,"JSON_HEADERS",{enumerable:!0,get:function(){return i}}),e.withToken=function(t,n){const[o,c]=u(t),i=o.includes("?")?"&":"?";return`${o}${i}token=${encodeURIComponent(n)}${c}`},Object.defineProperty(e,"DEFAULT_TIMEOUT_MS",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"MAX_ATTEMPTS",{enumerable:!0,get:function(){return s}}),e.isRetryableMethod=function(t){const n=t.toUpperCase();return"GET"===n||"HEAD"===n},e.isRetryableError=function(t){if("undefined"!=typeof DOMException&&t instanceof DOMException)return"AbortError"===t.name;return t instanceof Error&&"AbortError"===t.name||t instanceof TypeError},e.retryDelayMs=function(t){return p*2**t};const t=["application/x-www-form-urlencoded","multipart/form-data","text/plain"],n=new Set(["accept","accept-language","content-language","content-type","range"]),o=new Set(["GET","HEAD","POST"]);const c={},i={"Content-Type":"application/json"};function u(t){const n=t.indexOf("#");return-1===n?[t,""]:[t.slice(0,n),t.slice(n)]}const f=6e4,s=3,p=500},746,[]);
850
- __d(function(g,r,i,a,_m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"CANONICAL_TABS",{enumerable:!0,get:function(){return t}}),e.isIsolated=o,e.parseActiveTab=function(t){return n.has(t)?t:"chat"},e.parsePinnedTabs=function(t){return t?new Set(t.split(",").map(t=>t.trim()).filter(t=>n.has(t))):new Set},e.serializePinned=s,e.viewParams=c,e.terminalOnlyHref=function(t){const n=new URLSearchParams;for(const[t,o]of Object.entries(c("terminal",new Set)))o&&n.set(t,o);return`/${t}?${n.toString()}`},e.parseLineSpec=function(t){if(!t)return{};const n=t.match(/^(\d+)(?:-(\d+))?$/);if(!n)return{};const o=Number(n[1]),s=n[2]?Number(n[2]):void 0;return void 0!==s&&s>=o?{line:o,lineEnd:s}:{line:o}},Object.defineProperty(e,"CONNECTION_PARAMS",{enumerable:!0,get:function(){return u}}),e.withoutConnectionParams=function(t){const n=new URLSearchParams(t);for(const t of u)n.delete(t);const o=n.toString();return o?`?${o}`:""},e.withoutConnectionHash=function(t){const n=t.startsWith("#")?t.slice(1):t;if(!n)return"";const o=new URLSearchParams(n);for(const t of u)o.delete(t);const s=o.toString();return s?`#${s}`:""},e.connectionFragment=f,e.buildViewUrl=l,e.buildIsolateUrl=function(t){return l(o(t.host,t.conn.host)?"shared":"daemon",t)},e.buildMeldUrl=function(t){return l(o(t.host,t.conn.host)?"daemon":"shared",t)};const t=["chat","terminal","files"],n=new Set(t);function o(t,n){return t.toLowerCase()===n.toLowerCase()}function s(n){return t.filter(t=>n.has(t)).join(",")}function c(t,n,o,c,u){return{tab:"chat"!==t?t:void 0,pinned:s(n)||void 0,path:o||void 0,line:c?u&&u>c?`${c}-${u}`:String(c):void 0}}const u=["host","token"];function f(t,n){const o=new URLSearchParams;return n&&o.set("host",t.host),o.set("token",t.token),`#${o.toString()}`}function l(t,n){const{protocol:o,search:s,path:c,conn:l,view:m}=n,$=new URLSearchParams(s);for(const[t,n]of Object.entries(m))n?$.set(t,n):$.delete(t);for(const t of u)$.delete(t);const S=$.toString(),w=(S?`?${S}`:"")+f(l,"shared"===t);if("shared"===t){const t=p(n);return null===t?null:`${t}${c}${w}`}return`${h(o)}://${l.host}${c}${w}`}function h(t){return"https:"===t?"https":"http"}function p(t){return o(t.host,t.conn.host)?t.appHost?`https://${t.appHost}`:null:`${h(t.protocol)}://${t.host}`}},747,[]);
850
+ __d(function(g,r,i,a,_m,e,_d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"CANONICAL_TABS",{enumerable:!0,get:function(){return n}}),e.isIsolated=o,e.parseActiveTab=function(n){return t.has(n)?n:"chat"},e.parsePinnedTabs=function(n){return n?new Set(n.split(",").map(n=>n.trim()).filter(n=>t.has(n))):new Set},e.serializePinned=s,e.viewParams=c,e.terminalOnlyHref=function(n){const t=new URLSearchParams;for(const[n,o]of Object.entries(c("terminal",new Set)))o&&t.set(n,o);return`/${n}?${t.toString()}`},e.parseLineSpec=function(n){if(!n)return{};const t=n.match(/^(\d+)(?:-(\d+))?$/);if(!t)return{};const o=Number(t[1]),s=t[2]?Number(t[2]):void 0;return void 0!==s&&s>=o?{line:o,lineEnd:s}:{line:o}},Object.defineProperty(e,"DAEMON_PARAM",{enumerable:!0,get:function(){return u}}),Object.defineProperty(e,"CONNECTION_PARAMS",{enumerable:!0,get:function(){return l}}),e.withDaemonFragment=function(n,t){if(!t)return n;const o=n.indexOf("#"),s=-1===o?n:n.slice(0,o),c=new URLSearchParams(-1===o?"":n.slice(o+1));return c.set(u,t),`${s}#${c.toString()}`},e.daemonFromHash=function(n){return new URLSearchParams(n.startsWith("#")?n.slice(1):n).get(u)||null},e.activeDaemonBraneId=function(n,t){return(n.find(n=>n.id===t)??n[0])?.brane_id??null},e.daemonToAdopt=function(n,t,o){return null!==t?null:n.find(n=>n.brane_id===o)?.id??null},e.withoutConnectionParams=function(n){const t=new URLSearchParams(n);for(const n of l)t.delete(n);const o=t.toString();return o?`?${o}`:""},e.withoutConnectionHash=function(n){const t=n.startsWith("#")?n.slice(1):n;if(!t)return"";const o=new URLSearchParams(t);for(const n of l)o.delete(n);const s=o.toString();return s?`#${s}`:""},e.connectionFragment=f,e.buildViewUrl=d,e.buildIsolateUrl=function(n){return d(o(n.host,n.conn.host)?"shared":"daemon",n)},e.buildMeldUrl=function(n){return d(o(n.host,n.conn.host)?"daemon":"shared",n)};const n=["chat","terminal","files"],t=new Set(n);function o(n,t){return n.toLowerCase()===t.toLowerCase()}function s(t){return n.filter(n=>t.has(n)).join(",")}function c(n,t,o,c,u){return{tab:"chat"!==n?n:void 0,pinned:s(t)||void 0,path:o||void 0,line:c?u&&u>c?`${c}-${u}`:String(c):void 0}}const u="daemon",l=["host","token",u];function f(n,t){const o=new URLSearchParams;return t&&o.set("host",n.host),o.set("token",n.token),`#${o.toString()}`}function d(n,t){const{protocol:o,search:s,path:c,conn:u,view:d}=t,p=new URLSearchParams(s);for(const[n,t]of Object.entries(d))t?p.set(n,t):p.delete(n);for(const n of l)p.delete(n);const S=p.toString(),$=(S?`?${S}`:"")+f(u,"shared"===n);if("shared"===n){const n=m(t);return null===n?null:`${n}${c}${$}`}return`${h(o)}://${u.host}${c}${$}`}function h(n){return"https:"===n?"https":"http"}function m(n){return o(n.host,n.conn.host)?n.appHost?`https://${n.appHost}`:null:`${h(n.protocol)}://${n.host}`}},747,[]);
851
851
  __d(function(g,r,i,_a,m,e,d){"use strict";function t(t){let n=2166136261;for(const o of[...t].sort((t,n)=>t-n).join(","))n^=o.charCodeAt(0),n=Math.imul(n,16777619)>>>0;return(n>>>8).toString(16).padStart(6,"0")}Object.defineProperty(e,'__esModule',{value:!0}),e.formatSeqParam=function(t){if(!t)return null;const n=[...new Set(t)].filter(t=>Number.isInteger(t)&&t>0).sort((t,n)=>t-n);return n.length>0?n.join(","):null},e.parseSeqParam=function(t){if(!t)return[];const n=new Set;for(const o of t.split(",")){const t=o.trim();if(!t)continue;if(!/^\d+$/.test(t))continue;const u=Number(t);Number.isSafeInteger(u)&&u>0&&n.add(u)}return[...n].sort((t,n)=>t-n)},e.formatSeqModeParam=function(t){return"except"===t?"except":null},e.parseSeqModeParam=function(t){return"except"===t?.trim()?"except":"only"},e.exportFileName=function(n,o){return o?`${n}.${o.seqs.length}-of-${o.total}.${t(o.seqs)}.html`:`${n}.html`},e.seqDigest=t},748,[]);
852
852
  __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.lastTerminalSize=function(){return n},e.createTerminalChannel=o,e.sendInterrupt=c,e.interruptSession=function(t,n){let u=!1;const l=o({conn:t,nid:n,onFrame:()=>{},onConnect:()=>{u||(u=!0,clearTimeout(f),c(l.sendKeys),setTimeout(()=>l.close(),s[s.length-1]+200))}}),f=setTimeout(()=>{u||l.close()},y)};var t=r(d[0]);let n=null;function o(o){const{conn:s,nid:c,onFrame:y,onCursor:u,onTerminated:l,onConnect:f,onDisconnect:S}=o,p=`${"undefined"!=typeof window&&"https:"===window.location.protocol?"wss":"ws"}://${s.host}/ws/terminal/${c}?token=${s.token}`;let O=null,N=null,k=!1,b=!1,w=null;return(function n(){k||(O=new WebSocket(p),O.onopen=()=>{f?.(),b&&O.send(JSON.stringify({type:"start"})),w&&O.send(JSON.stringify(Object.assign({type:"resize"},w)))},O.onmessage=t=>{try{const n=JSON.parse(t.data);"terminated"===n.type?l?.():"cursor"===n.type?u?.(n.cursor??null):"frame"!==n.type&&"append"!==n.type||y(n)}catch{}},O.onclose=o=>{S?.(),k||((0,t.isSignedOutClose)(o.code)?k=!0:N=setTimeout(n,2e3))},O.onerror=()=>{O?.close()})})(),{start:function(){b=!0,O?.readyState===WebSocket.OPEN&&O.send(JSON.stringify({type:"start"}))},stop:function(){b=!1,O?.readyState===WebSocket.OPEN&&O.send(JSON.stringify({type:"stop"}))},resize:function(t,o){w={cols:t,rows:o},n={cols:t,rows:o},O?.readyState===WebSocket.OPEN&&O.send(JSON.stringify({type:"resize",cols:t,rows:o}))},sendKeys:function(t,n){O?.readyState===WebSocket.OPEN&&O.send(JSON.stringify(Object.assign({type:"keys",keys:t},n&&n>1?{repeat:n}:{})))},sendPaste:function(t){t&&O?.readyState===WebSocket.OPEN&&O.send(JSON.stringify({type:"paste",text:t}))},sendMouse:function(t,n,o=0,s="click"){O?.readyState===WebSocket.OPEN&&O.send(JSON.stringify({type:"mouse",x:t,y:n,button:o,action:s}))},close:function(){k=!0,b=!1,N&&clearTimeout(N),O?.close()},refresh:function(){O?.readyState===WebSocket.OPEN&&O.send(JSON.stringify({type:"refresh"}))},clearHistory:function(){O?.readyState===WebSocket.OPEN&&O.send(JSON.stringify({type:"clear_history"}))}}}const s=[0,150,300];function c(t){for(const n of s)0===n?t("C-c"):setTimeout(()=>t("C-c"),n)}const y=1e4},749,[750]);
853
853
  __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"WS_CLOSE_TOKEN_ROTATED",{enumerable:!0,get:function(){return t}}),e.isSignedOutClose=function(n){return n===t};const t=4401},750,[]);
854
- __d(function(g,r,i,a,_m,e,_d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"CONVERSATIONAL_EVENT_TYPES_LIST",{enumerable:!0,get:function(){return t}}),e.isSystemEvent=function(t){return!n.has(t)},e.formatInvocation=u,e.spawnedContent=l,e.revivedContent=function(t,n,o=[],l=!1){const c=`Revived ${u([t,...o])} /${n}`;return l?`${c} (forked \u2014 original still live)`:c},e.runningContent=function(t){return`Running ${u(t)}`},e.restartedContent=function(t){return`Restarted ${u(t)}`},e.agentTypeOf=function(t){return t.replace(/-[a-z0-9]{8}$/,"")},e.formatSystemContent=c,Object.defineProperty(e,"FOLD_LINK_SCHEME",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"FOLD_COLOR",{enumerable:!0,get:function(){return $}}),e.systemLine=function(t,n={}){let o=c(t.content,n.agent);const u=n.fold??null;if(!u)return o;const l=` in ${u}`;o.endsWith(l)&&(o=o.slice(0,-l.length));return"started"===t.type?`${o} in [${u}](${f}${u})`:o},e.relPart=s,e.formatActivitySpan=function(t,n,o=Date.now()){const u=s(t,o),l=t=>t.ago?`${t.val} ago`:t.val;if(!("number"==typeof n&&n-t>6e4))return l(u);const c=s(n,o);return u.val===c.val?l(u):u.ago&&c.ago?`${u.val} to ${c.val} ago`:`${l(u)} to ${l(c)}`},e.formatCost=m,e.formatCostTotals=function(t){if(!t?.length)return null;const n=t.map(t=>m(t.amount,t.unit)).filter(t=>!!t);return n.length?n.join(" \xb7 "):null};const t=["narration","human_signal","agent_signal"],n=new Set(t);function o(t){return""===t||/[\s'"$`\\]/.test(t)?`'${t.replace(/'/g,"'\\''")}'`:t}function u(t){const n=t.map(o).join(" "),u=Math.max(0,...Array.from(n.matchAll(/`+/g),t=>t[0].length)),l="`".repeat(u+1);return u?`${l} ${n} ${l}`:`${l}${n}${l}`}function l(t,n,o={}){const l=`Spawned ${u([t,...o.args??[]])} /${n}`;return o.from?`${l} from ${o.from}`:l}function c(t,n){const o=t.trimEnd();if(o.includes("`"))return o;let u;return(u=/^Spawned (\S+) \(([A-Za-z0-9][\w.-]*)\)$/.exec(o))?l(u[1],u[2]):(u=/^Twinned from (\S+)$/.exec(o))?n?l(n,"twin",{from:u[1]}):`/twin from ${u[1]}`:(u=/^Revived (\S+) session( \(.*\))?$/.exec(o))?`Revived \`${u[1]}\`${u[2]??""}`:(u=/^(Running|Restarted) (.+)$/.exec(o))?`${u[1]} \`${u[2]}\``:o}const f="brane://fold/",$="#5e8a72";function s(t,n=Date.now()){const o=Math.floor((n-t)/1e3);if(o<60)return{val:`${Math.max(1,o)}s`,ago:!0};const u=Math.floor(o/60);if(u<60)return{val:`${u}m`,ago:!0};const l=Math.floor(u/60);if(l<24)return{val:`${l}h`,ago:!0};const c=Math.floor(l/24);if(c<7)return{val:`${c}d`,ago:!0};const f=new Date(t),$=`${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][f.getMonth()]} ${f.getDate()}`;return{val:f.getFullYear()===new Date(n).getFullYear()?$:`${$}, ${f.getFullYear()}`,ago:!1}}function m(t,n){if(null==t||!n)return null;if("USD"===n)return`$${t.toFixed(2)}`;return`${Number.isInteger(t)?t.toLocaleString():t.toLocaleString(void 0,{maximumFractionDigits:2})} ${n}`}},751,[]);
855
- __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"INLINE_PAYLOAD_MIME",{enumerable:!0,get:function(){return n}}),e.payloadExtname=t,e.isInlinePayload=function(o){return t(o)in n},e.attachmentDisposition=function(n){const t=n.replace(/[\\/]/g,"_").replace(o,"")||"download",p=t.replace(/"/g,'\\"');return/^[\x20-\x7e]*$/.test(t)?`attachment; filename="${p}"`:`attachment; filename="${c(t)}"; filename*=UTF-8''${l=t,encodeURIComponent(l).replace(/['()*]/g,n=>`%${n.charCodeAt(0).toString(16).toUpperCase()}`)}`;var l};const n={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".bmp":"image/bmp",".avif":"image/avif",".svg":"image/svg+xml"};function t(n){const t=n.lastIndexOf(".");if(t<0)return"";const o=n.slice(t).toLowerCase();return o.includes("/")?"":o}const o=/[\u0000-\u001f\u007f]/g;function c(n){return n.replace(/[^\x20-\x7e]/g,"_").replace(/["\\]/g,"_").replace(/^_+$/,"")||"download"}},752,[]);
856
- __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.createControlChannel=function(n){const{conn:s,onMessage:o,onConnect:c,onDisconnect:u,onSignedOut:f}=n,b=`${"undefined"!=typeof window&&"https:"===window.location.protocol?"wss":"ws"}://${s.host}/ws/control?token=${s.token}`;let y=null,l=null,S=!1;const O=new Map,p=new Map;let v=0;return(function n(){if(S)return;y=new WebSocket(b),y.onopen=()=>{for(const[t,n]of O)y.send(JSON.stringify({type:"subscribe",narrative:t,after:n}));v>0&&y.send(JSON.stringify({type:"subscribe_activity"})),c?.()},y.onmessage=t=>{try{const n=JSON.parse(t.data);o(n)}catch{}},y.onclose=s=>{if(u?.(),!S)return(0,t.isSignedOutClose)(s.code)?(S=!0,void f?.()):void(l=setTimeout(n,2e3))},y.onerror=()=>{y?.close()}})(),{subscribe:function(t,n=0){const s=p.get(t)??0;if(p.set(t,s+1),s>0)return;O.set(t,n),y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({type:"subscribe",narrative:t,after:n}))},unsubscribe:function(t){const n=p.get(t)??0;if(n>1)return void p.set(t,n-1);p.delete(t),O.delete(t),y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({type:"unsubscribe",narrative:t}))},subscribeActivity:function(){if(v+=1,v>1)return;y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({type:"subscribe_activity"}))},unsubscribeActivity:function(){if(v>1)return void(v-=1);v=0,y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({type:"unsubscribe_activity"}))},send:function(t,n,s="web"){y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({type:"signal",narrative:t,content:n,source:s}))},close:function(){S=!0,l&&clearTimeout(l);y?.close()}}};var t=r(d[0])},753,[750]);
857
- __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.isAwaiting=function({mcpConnected:n,awaiting:t}){return!!n&&!!t},e.awaitingGlow=function(n){return[`inset 0 0 3px 1px oklch(0.78 0.16 ${n} / 0.95)`,`inset 0 0 18px 2px oklch(0.74 0.15 ${n} / 0.55)`,`inset 0 0 40px 4px oklch(0.7 0.14 ${n} / 0.28)`,`inset 0 4px 3px -3px oklch(0.78 0.16 ${n} / 0.95)`].join(", ")},Object.defineProperty(e,"AWAITING_STATUS",{enumerable:!0,get:function(){return n}}),Object.defineProperty(e,"NOT_AWAITING_STATUS",{enumerable:!0,get:function(){return t}});const n="awaiting",t="not_awaiting"},754,[]);
858
- __d(function(g,r,i,a,m,e,_d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"DAEMONS_KEY",{enumerable:!0,get:function(){return t}}),e.loadDaemons=u,e.saveDaemons=l,e.addDaemon=function(t){const n=u(),o=n.findIndex(n=>n.brane_id===t.brane_id);o>=0?n[o]=Object.assign({},t,{addedAt:n[o].addedAt}):n.push(t);return l(n),n},e.updateDaemon=function(t,n){const o=u().map(o=>o.id===t?Object.assign({},o,n):o);return l(o),o},e.removeDaemon=function(t){const n=u().filter(n=>n.id!==t);l(n),f()===t&&I(n[0]?.id??null);s()===t&&d(n[0]?.id??null);return n},e.getActiveDaemonId=function(){c();try{return sessionStorage.getItem(n)??localStorage.getItem(o)}catch{return null}},e.setActiveDaemonId=d,e.getDefaultDaemonId=f,e.setDefaultDaemonId=I;const t="brane_daemons",n="brane_active_daemon",o="brane_default_daemon";function c(){try{const t=localStorage.getItem(n);t&&!localStorage.getItem(o)&&localStorage.setItem(o,t),t&&localStorage.removeItem(n)}catch{}}function u(){try{const n=localStorage.getItem(t);return n?JSON.parse(n):[]}catch{return[]}}function l(n){localStorage.setItem(t,JSON.stringify(n))}function s(){try{return sessionStorage.getItem(n)}catch{return null}}function d(t){try{t?sessionStorage.setItem(n,t):sessionStorage.removeItem(n)}catch{}}function f(){try{return localStorage.getItem(o)}catch{return null}}function I(t){try{t?localStorage.setItem(o,t):localStorage.removeItem(o)}catch{}}},755,[]);
854
+ __d(function(g,r,i,a,m,e,_d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"DAEMONS_KEY",{enumerable:!0,get:function(){return n}}),e.loadDaemons=l,e.saveDaemons=s,e.addDaemon=function(t){const n=l(),o=n.findIndex(n=>n.brane_id===t.brane_id);o>=0?n[o]=Object.assign({},t,{addedAt:n[o].addedAt}):n.push(t);return s(n),n},e.updateDaemon=function(t,n){const o=l().map(o=>o.id===t?Object.assign({},o,n):o);return s(o),o},e.removeDaemon=function(t){const n=l().filter(n=>n.id!==t);s(n),S()===t&&D(n[0]?.id??null);f()===t&&I(n[0]?.id??null);return n},e.getActiveDaemonId=d,e.getActiveDaemonBraneId=function(){return(0,t.activeDaemonBraneId)(l(),d())},e.adoptDaemonByBraneId=function(n){const o=(0,t.daemonToAdopt)(l(),f(),n);return null!==o&&(I(o),!0)},e.setActiveDaemonId=I,e.getDefaultDaemonId=S,e.setDefaultDaemonId=D;var t=r(_d[0]);const n="brane_daemons",o="brane_active_daemon",c="brane_default_daemon";function u(){try{const t=localStorage.getItem(o);t&&!localStorage.getItem(c)&&localStorage.setItem(c,t),t&&localStorage.removeItem(o)}catch{}}function l(){try{const t=localStorage.getItem(n);return t?JSON.parse(t):[]}catch{return[]}}function s(t){localStorage.setItem(n,JSON.stringify(t))}function d(){u();try{return sessionStorage.getItem(o)??localStorage.getItem(c)}catch{return null}}function f(){try{return sessionStorage.getItem(o)}catch{return null}}function I(t){try{t?sessionStorage.setItem(o,t):sessionStorage.removeItem(o)}catch{}}function S(){try{return localStorage.getItem(c)}catch{return null}}function D(t){try{t?localStorage.setItem(c,t):localStorage.removeItem(c)}catch{}}},751,[747]);
855
+ __d(function(g,r,i,a,_m,e,_d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"CONVERSATIONAL_EVENT_TYPES_LIST",{enumerable:!0,get:function(){return t}}),e.isSystemEvent=function(t){return!n.has(t)},e.formatInvocation=u,e.spawnedContent=l,e.revivedContent=function(t,n,o=[],l=!1){const c=`Revived ${u([t,...o])} /${n}`;return l?`${c} (forked \u2014 original still live)`:c},e.runningContent=function(t){return`Running ${u(t)}`},e.restartedContent=function(t){return`Restarted ${u(t)}`},e.agentTypeOf=function(t){return t.replace(/-[a-z0-9]{8}$/,"")},e.formatSystemContent=c,Object.defineProperty(e,"FOLD_LINK_SCHEME",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"FOLD_COLOR",{enumerable:!0,get:function(){return $}}),e.systemLine=function(t,n={}){let o=c(t.content,n.agent);const u=n.fold??null;if(!u)return o;const l=` in ${u}`;o.endsWith(l)&&(o=o.slice(0,-l.length));return"started"===t.type?`${o} in [${u}](${f}${u})`:o},e.relPart=s,e.formatActivitySpan=function(t,n,o=Date.now()){const u=s(t,o),l=t=>t.ago?`${t.val} ago`:t.val;if(!("number"==typeof n&&n-t>6e4))return l(u);const c=s(n,o);return u.val===c.val?l(u):u.ago&&c.ago?`${u.val} to ${c.val} ago`:`${l(u)} to ${l(c)}`},e.formatCost=m,e.formatCostTotals=function(t){if(!t?.length)return null;const n=t.map(t=>m(t.amount,t.unit)).filter(t=>!!t);return n.length?n.join(" \xb7 "):null};const t=["narration","human_signal","agent_signal"],n=new Set(t);function o(t){return""===t||/[\s'"$`\\]/.test(t)?`'${t.replace(/'/g,"'\\''")}'`:t}function u(t){const n=t.map(o).join(" "),u=Math.max(0,...Array.from(n.matchAll(/`+/g),t=>t[0].length)),l="`".repeat(u+1);return u?`${l} ${n} ${l}`:`${l}${n}${l}`}function l(t,n,o={}){const l=`Spawned ${u([t,...o.args??[]])} /${n}`;return o.from?`${l} from ${o.from}`:l}function c(t,n){const o=t.trimEnd();if(o.includes("`"))return o;let u;return(u=/^Spawned (\S+) \(([A-Za-z0-9][\w.-]*)\)$/.exec(o))?l(u[1],u[2]):(u=/^Twinned from (\S+)$/.exec(o))?n?l(n,"twin",{from:u[1]}):`/twin from ${u[1]}`:(u=/^Revived (\S+) session( \(.*\))?$/.exec(o))?`Revived \`${u[1]}\`${u[2]??""}`:(u=/^(Running|Restarted) (.+)$/.exec(o))?`${u[1]} \`${u[2]}\``:o}const f="brane://fold/",$="#5e8a72";function s(t,n=Date.now()){const o=Math.floor((n-t)/1e3);if(o<60)return{val:`${Math.max(1,o)}s`,ago:!0};const u=Math.floor(o/60);if(u<60)return{val:`${u}m`,ago:!0};const l=Math.floor(u/60);if(l<24)return{val:`${l}h`,ago:!0};const c=Math.floor(l/24);if(c<7)return{val:`${c}d`,ago:!0};const f=new Date(t),$=`${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][f.getMonth()]} ${f.getDate()}`;return{val:f.getFullYear()===new Date(n).getFullYear()?$:`${$}, ${f.getFullYear()}`,ago:!1}}function m(t,n){if(null==t||!n)return null;if("USD"===n)return`$${t.toFixed(2)}`;return`${Number.isInteger(t)?t.toLocaleString():t.toLocaleString(void 0,{maximumFractionDigits:2})} ${n}`}},752,[]);
856
+ __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"INLINE_PAYLOAD_MIME",{enumerable:!0,get:function(){return n}}),e.payloadExtname=t,e.isInlinePayload=function(o){return t(o)in n},e.attachmentDisposition=function(n){const t=n.replace(/[\\/]/g,"_").replace(o,"")||"download",p=t.replace(/"/g,'\\"');return/^[\x20-\x7e]*$/.test(t)?`attachment; filename="${p}"`:`attachment; filename="${c(t)}"; filename*=UTF-8''${l=t,encodeURIComponent(l).replace(/['()*]/g,n=>`%${n.charCodeAt(0).toString(16).toUpperCase()}`)}`;var l};const n={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".bmp":"image/bmp",".avif":"image/avif",".svg":"image/svg+xml"};function t(n){const t=n.lastIndexOf(".");if(t<0)return"";const o=n.slice(t).toLowerCase();return o.includes("/")?"":o}const o=/[\u0000-\u001f\u007f]/g;function c(n){return n.replace(/[^\x20-\x7e]/g,"_").replace(/["\\]/g,"_").replace(/^_+$/,"")||"download"}},753,[]);
857
+ __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.createControlChannel=function(n){const{conn:s,onMessage:o,onConnect:c,onDisconnect:u,onSignedOut:f}=n,b=`${"undefined"!=typeof window&&"https:"===window.location.protocol?"wss":"ws"}://${s.host}/ws/control?token=${s.token}`;let y=null,l=null,S=!1;const O=new Map,p=new Map;let v=0;return(function n(){if(S)return;y=new WebSocket(b),y.onopen=()=>{for(const[t,n]of O)y.send(JSON.stringify({type:"subscribe",narrative:t,after:n}));v>0&&y.send(JSON.stringify({type:"subscribe_activity"})),c?.()},y.onmessage=t=>{try{const n=JSON.parse(t.data);o(n)}catch{}},y.onclose=s=>{if(u?.(),!S)return(0,t.isSignedOutClose)(s.code)?(S=!0,void f?.()):void(l=setTimeout(n,2e3))},y.onerror=()=>{y?.close()}})(),{subscribe:function(t,n=0){const s=p.get(t)??0;if(p.set(t,s+1),s>0)return;O.set(t,n),y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({type:"subscribe",narrative:t,after:n}))},unsubscribe:function(t){const n=p.get(t)??0;if(n>1)return void p.set(t,n-1);p.delete(t),O.delete(t),y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({type:"unsubscribe",narrative:t}))},subscribeActivity:function(){if(v+=1,v>1)return;y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({type:"subscribe_activity"}))},unsubscribeActivity:function(){if(v>1)return void(v-=1);v=0,y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({type:"unsubscribe_activity"}))},send:function(t,n,s="web"){y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({type:"signal",narrative:t,content:n,source:s}))},close:function(){S=!0,l&&clearTimeout(l);y?.close()}}};var t=r(d[0])},754,[750]);
858
+ __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.isAwaiting=function({mcpConnected:n,awaiting:t}){return!!n&&!!t},e.awaitingGlow=function(n){return[`inset 0 0 3px 1px oklch(0.78 0.16 ${n} / 0.95)`,`inset 0 0 18px 2px oklch(0.74 0.15 ${n} / 0.55)`,`inset 0 0 40px 4px oklch(0.7 0.14 ${n} / 0.28)`,`inset 0 4px 3px -3px oklch(0.78 0.16 ${n} / 0.95)`].join(", ")},Object.defineProperty(e,"AWAITING_STATUS",{enumerable:!0,get:function(){return n}}),Object.defineProperty(e,"NOT_AWAITING_STATUS",{enumerable:!0,get:function(){return t}});const n="awaiting",t="not_awaiting"},755,[]);
859
859
  __d(function(g,r,i,a,m,_e,d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return u}});var t=e(r(d[0])),l=e(r(d[1])),n=e(r(d[2])),o=e(r(d[3])),s=e(r(d[4])),c=r(d[5]);function u({pending:e,onConfirm:s,onCancel:u}){const h=null!==e,x=e?`${e.status.username}@${e.status.hostname}`:"";return(0,c.jsx)(t.default,{visible:h,transparent:!0,animationType:"fade",onRequestClose:u,children:(0,c.jsx)(l.default,{style:b.backdrop,onPress:u,children:(0,c.jsxs)(l.default,{style:b.card,onPress:e=>e.stopPropagation(),children:[(0,c.jsx)(n.default,{style:b.title,children:e?.isUpdate?"Update credentials?":"Meld this device?"}),e?.isUpdate?(0,c.jsx)(n.default,{style:b.body,children:"You're already paired with this brane. The meld URL has a new token \u2014 replace the stored one?"}):(0,c.jsx)(n.default,{style:b.body,children:"You'll add this daemon to this device and switch to it."}),(0,c.jsxs)(o.default,{style:b.detailsBlock,children:[(0,c.jsx)(f,{label:"Daemon",value:x}),(0,c.jsx)(f,{label:"Address",value:e?.host??""}),(0,c.jsx)(f,{label:"Brane",value:e?.status.brane_id??"",mono:!0})]}),(0,c.jsxs)(o.default,{style:b.buttonRow,children:[(0,c.jsx)(l.default,{style:[b.button,b.cancelButton],onPress:u,children:(0,c.jsx)(n.default,{style:b.cancelText,children:"Cancel"})}),(0,c.jsx)(l.default,{style:[b.button,b.confirmButton],onPress:s,children:(0,c.jsx)(n.default,{style:b.confirmText,children:e?.isUpdate?"Update":"Meld"})})]})]})})})}function f({label:e,value:t,mono:l}){return(0,c.jsxs)(o.default,{style:b.detailRow,children:[(0,c.jsx)(n.default,{style:b.detailLabel,children:e}),(0,c.jsx)(n.default,{style:[b.detailValue,l&&b.detailValueMono],numberOfLines:1,selectable:!0,children:t})]})}const b=s.default.create({backdrop:{flex:1,backgroundColor:"rgba(0,0,0,0.7)",justifyContent:"center",alignItems:"center",padding:24},card:{backgroundColor:"#1e1e1e",borderRadius:12,padding:22,width:"100%",maxWidth:360},title:{color:"#e0e0e0",fontSize:17,fontWeight:"600",marginBottom:10,textAlign:"center"},body:{color:"#bbb",fontSize:13,lineHeight:18,marginBottom:14,textAlign:"center"},detailsBlock:{backgroundColor:"#2a2a2a",borderRadius:8,padding:12,marginBottom:18},detailRow:{flexDirection:"row",paddingVertical:3},detailLabel:{color:"#888",fontSize:12,width:70},detailValue:{color:"#e0e0e0",fontSize:12,flex:1},detailValueMono:{fontFamily:"monospace"},buttonRow:{flexDirection:"row",gap:10},button:{flex:1,paddingVertical:10,borderRadius:6,alignItems:"center"},cancelButton:{backgroundColor:"#2a2a2a"},cancelText:{color:"#ccc",fontSize:14},confirmButton:{backgroundColor:"#2e7d32"},confirmText:{color:"#fff",fontSize:14,fontWeight:"600"}})},756,[153,146,105,13,26,6]);
860
860
  __d(function(g,r,i,a,m,_e,d){"use strict";Object.defineProperty(_e,'__esModule',{value:!0}),_e.installNoPan=function(){if(t||"undefined"==typeof window)return;t=!0;const n=window.visualViewport,o=document.documentElement;let s=null;const c=()=>{if(!n)return;const t=(0,e.layoutHeight)(n.height,n.scale,s);null!==t&&t!==s&&(s=t,o.style.setProperty("--brane-vvh",`${t}px`))};n&&(n.addEventListener("resize",c),c());const l=!window.matchMedia?.("(pointer: fine)").matches;let u=0;const h=()=>{const t=document.activeElement;(0,e.mustBlur)({touch:l,textEntryFocused:!!t&&(0,e.isTextEntry)(t),keyboardUp:!!n&&window.innerHeight-n.height>120,msSinceTapFocus:Date.now()-u})&&t?.blur()};n&&n.addEventListener("resize",h);document.addEventListener("focusin",()=>{setTimeout(h,e.TAP_FOCUS_GRACE_MS+50)},!0);let p=0,v=0,f=!1,w=!1;document.addEventListener("touchstart",e=>{const t=e.touches[0];p=t.clientX,v=t.clientY,f=!1,w=e.touches.length>1},{passive:!0,capture:!0}),document.addEventListener("touchmove",t=>{const o=t.touches[0],s=o.clientX-p,c=o.clientY-v;if((Math.abs(s)>e.TAP_SLOP_PX||Math.abs(c)>e.TAP_SLOP_PX)&&(f=!0),w||t.touches.length>1||n&&Math.abs(n.scale-1)>.01)return;const l=[];for(let n=t.target;n&&n!==document.body;n=n.parentElement){const t=getComputedStyle(n);l.push((0,e.scrollBoxOf)({overflowY:t.overflowY,reversed:t.display.includes("flex")&&"column-reverse"===t.flexDirection,scrollTop:n.scrollTop,clientHeight:n.clientHeight,scrollHeight:n.scrollHeight}))}(0,e.dragAllowed)(s,c,l)||t.preventDefault()},{passive:!1,capture:!0}),document.addEventListener("touchend",t=>{if(f||w)return;const n=t.target?.closest?.("input, textarea, [contenteditable]");n&&n!==document.activeElement&&(0,e.isTextEntry)(n)&&(t.preventDefault(),u=Date.now(),n.focus({preventScroll:!0}))},{passive:!1,capture:!0})},r(d[0]);var e=r(d[1]);let t=!1},757,[116,758]);
861
861
  __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"TAP_SLOP_PX",{enumerable:!0,get:function(){return o}}),e.isTextEntry=function(o){if(o.isContentEditable)return!0;const n=o.tagName.toUpperCase();return("INPUT"===n||"TEXTAREA"===n)&&(!o.disabled&&!o.readOnly&&("TEXTAREA"===n||!t.has((o.type??"text").toLowerCase())))},e.scrollBoxOf=function(o){const t=o.scrollHeight-o.clientHeight;if("auto"!==o.overflowY&&"scroll"!==o.overflowY||!(t>1))return{scrolls:!1,roomAbove:0,roomBelow:0};const[n,s]=o.reversed?[-t,0]:[0,t];return{scrolls:!0,roomAbove:o.scrollTop-n,roomBelow:s-o.scrollTop}},e.dragAllowed=function(o,t,n){if(Math.abs(o)>Math.abs(t))return!0;if(0===t)return!0;for(const o of n)if(o.scrolls){if(t>0&&o.roomAbove>1)return!0;if(t<0&&o.roomBelow>1)return!0}return!1},e.layoutHeight=function(o,t,n){return Math.abs(t-1)>.01?n:Math.round(o)},Object.defineProperty(e,"TAP_FOCUS_GRACE_MS",{enumerable:!0,get:function(){return n}}),e.mustBlur=function(o){return o.touch&&o.textEntryFocused&&!o.keyboardUp&&o.msSinceTapFocus>n};const o=10,t=new Set(["button","checkbox","color","file","hidden","image","radio","range","reset","submit"]);const n=1e3},758,[]);
862
862
  __d(function(g,r,i,a,_m,_e,d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return N}});var t=r(d[0]);r(d[1]);var n=e(r(d[2]));r(d[3]);var o=e(r(d[4])),l=e(r(d[5])),s=e(r(d[6])),u=r(d[7]),c=r(d[8]),f=r(d[9]);function p(e){const t=e.match(/^mcp__([^_]+(?:_[^_]+)*?)__(.+)$/);return t?`${t[1]}:${t[2]}`:e}function y(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function h(e){return"object"!=typeof e||null===e||Array.isArray(e)?null:e}function m(e){const t=h(y(e.output));if(!t)return null;if(Array.isArray(t.content)){const e=t.content.find(e=>"string"==typeof e?.text)?.text;return h(y("string"==typeof e?e:null))}return t}function x(e){const t=p(e.name);if("brane:listen"===t)return{kind:"listen"};if("brane:narrate"!==t)return{kind:"work"};const n=h(y(e.input))?.nid;if("string"!=typeof n||n===e.narrative_id)return{kind:"self_narrate"};const o=m(e)?.seq;return{kind:"foreign_narrate",nid:n,seq:"number"==typeof o?o:void 0}}const b=240,j=8e3;function _(e){if(!e.input)return"";let t;try{t=JSON.parse(e.input)}catch{return e.input}if("object"!=typeof t||null===t)return String(t);const n=t,o=n.command??n.file_path??n.pattern??n.url??n.query??n.path;if("string"==typeof o)return o;const l=Object.values(n).find(e=>"string"==typeof e);return"string"==typeof l?l:e.input}function w(e){const t=_(e).replace(/\s*\n\s*/g," \u23ce ");return t.length>b?`${t.slice(0,b)}\u2026`:t}function k(e){if(!e)return null;const t=y(e);return null===t?e:JSON.stringify(t,null,2)}function S(e){return e.length<=j?{body:e,note:null}:{body:e.slice(0,j),note:`+${(e.length-j).toLocaleString()} more characters`}}function v(e){const t=h(y(e));return!!t&&0===Object.keys(t).length}function L(e){const t=[],n=p(e.name).startsWith("brane:"),o=(e,o,l)=>{if(!o)return;if(n&&("input"===e||"output"===e)&&v(o))return;const{body:s,note:u}=S(o);t.push({label:e,body:s,note:[l?.note,u].filter(Boolean).join(" \xb7 ")||null,failed:l?.failed})};return o("input",k(e.input),{note:e.input_truncated?"excerpt \u2014 the daemon holds the full value":void 0}),o("output",k(e.output),{note:e.output_truncated?"excerpt \u2014 the daemon holds the full value":void 0}),o("error",e.error,{failed:!0}),(e.decided_by||e.decision_note)&&o("decision",[e.decided_by,e.decision_note].filter(Boolean).join(" \u2014 ")),t}function $(e){return[e.status,e.source,e.agent_type].filter(Boolean).join(" \xb7 ")}function O(e){return null==e?"":e<1e3?`${e}ms`:`${(e/1e3).toFixed(1)}s`}function z(e){return"failed"===e.status||"denied"===e.status}function F(e){return z(e)?{glyph:"\u2717",failed:!0}:"unknown"===e.status?{glyph:"\u2013",failed:!1}:"pending"===e.status||"allowed"===e.status?{glyph:"\u2026",failed:!1}:null}function T({children:e}){const t=(0,u.useHorizontalPanGuard)();return(0,f.jsx)("div",Object.assign({style:{overflowX:"auto",overflowY:"hidden"}},t,{children:(0,f.jsx)("div",{style:{display:"flex",flexDirection:"column",width:"max-content",minWidth:"100%"},children:e})}))}function N({rows:e,onNarrativePress:o,onFetchFull:u}){const y=(0,t.useMemo)(()=>e.map(e=>({row:e,kind:x(e)})).filter(({kind:e})=>"self_narrate"!==e.kind),[e]),h=y.some(({row:e})=>z(e)),[m,b]=(0,t.useState)(h),j=(0,t.useRef)(!1);(0,t.useEffect)(()=>{h&&!j.current&&b(!0)},[h]);const[_,k]=(0,t.useState)(P),S=(0,t.useCallback)(e=>{k(t=>{const n=new Set(t);return n.delete(e)||n.add(e),n})},[]),[v,L]=(0,t.useState)(0),$=(0,t.useMemo)(()=>{const e=new Map;let t=0;for(const{row:n,kind:o}of y){const l=p(n.name);e.set(l,(e.get(l)??0)+1),"listen"!==o.kind&&(t+=n.duration_ms??0)}const n=[...e.entries()].map(([e,t])=>t>1?`${e} \xd7${t}`:e).join(", ");return`${1===y.length?"1 tool":`${y.length} tools`}${t>0?` (${O(t)})`:""}: ${n}`},[y]);return 0===y.length?null:(0,f.jsxs)(s.default,{style:R.container,dataSet:{chrome:"tools"},onLayout:e=>L(e.nativeEvent.layout.width),children:[(0,f.jsxs)(n.default,{onPress:()=>{j.current=!0,b(e=>(e&&k(P),!e))},style:R.summaryRow,children:[(0,f.jsx)(l.default,{style:R.gear,children:"\u2699"}),(0,f.jsx)(l.default,{style:[R.summaryText,h&&R.failText],numberOfLines:1,children:$})]}),m&&(0,f.jsx)(T,{children:y.map(({row:e,kind:y})=>{const h=F(e),m=_.has(e.dedup_key);return(0,f.jsxs)(t.Fragment,{children:[(0,f.jsxs)(n.default,{style:R.row,onPress:()=>S(e.dedup_key),accessibilityRole:"button",accessibilityState:{expanded:m},children:[(0,f.jsx)(l.default,{style:R.gear,children:"\u2699"}),(0,f.jsx)(l.default,{style:[R.name,h?.failed&&R.failText],numberOfLines:1,children:p(e.name)}),"foreign_narrate"===y.kind?(0,f.jsx)(l.default,{style:[R.args,C],numberOfLines:q?void 0:1,children:(0,f.jsxs)(l.default,Object.assign({style:R.link},A((0,c.narrativeHref)(y.nid,y.seq),()=>o?.(y.nid,y.seq)),{children:["\u2192\xa0",y.seq?`${y.nid}:${y.seq}`:y.nid]}))}):(0,f.jsx)(l.default,{style:[R.args,C],numberOfLines:q?void 0:1,children:w(e)}),(0,f.jsx)(s.default,{style:R.slack}),(0,f.jsxs)(s.default,{style:[R.trailing,M],children:[(0,f.jsx)(l.default,{style:R.duration,children:O(e.duration_ms)}),(0,f.jsx)(l.default,{style:[R.status,h?.failed&&R.failText],children:h?.glyph??" "})]})]}),m&&(0,f.jsx)(n.default,{style:[R.detail,D,v>0?{width:v-2*H}:null],onPress:()=>{"undefined"!=typeof window&&window.getSelection()?.toString()||S(e.dedup_key)},children:(0,f.jsx)(B,{row:e,onFetchFull:u})})]},e.dedup_key)})}),m&&y.map(({row:e})=>e).filter(z).map(e=>e.error?(0,f.jsx)(l.default,{style:[R.errorLine,R.failText],numberOfLines:2,children:e.error},`${e.dedup_key}-err`):null)]})}function B({row:e,onFetchFull:n}){const[o,u]=(0,t.useState)(null),[c,p]=(0,t.useState)(!1),y=!(!e.input_truncated&&!e.output_truncated);(0,t.useEffect)(()=>{if(!y||!n||o)return;let t=!0;return n(e.dedup_key).then(e=>{t&&u(e)}).catch(()=>{t&&p(!0)}),()=>{t=!1}},[y,n,o,e.dedup_key]);const h=o??e,m=(0,t.useMemo)(()=>L(h),[h]),x=y&&!o&&!c;return(0,f.jsxs)(f.Fragment,{children:[x&&(0,f.jsx)(l.default,{style:R.detailNote,children:"excerpt \u2014 fetching the rest\u2026"}),c&&(0,f.jsx)(l.default,{style:[R.detailNote,R.failText],children:"excerpt \u2014 the full value could not be fetched"}),0===m.length?(0,f.jsx)(l.default,{style:R.detailNote,children:"nothing recorded beyond the row itself"}):m.map(e=>(0,f.jsxs)(s.default,{style:R.detailSection,children:[(0,f.jsx)(l.default,{style:R.detailLabel,children:e.label}),(0,f.jsx)(l.default,{style:[R.detailBody,e.failed&&R.failText],selectable:!0,children:e.body}),e.note&&(0,f.jsx)(l.default,{style:R.detailNote,children:e.note})]},e.label)),(0,f.jsx)(l.default,{style:R.detailNote,children:$(h)})]})}const P=new Set;function A(e,t){const n=(0,c.inAppLinkProps)(e,t),o=n.onClick;return Object.assign({},n,{onClick:e=>{e.stopPropagation?.(),o?.(e)}})}const q=!0,C={whiteSpace:"nowrap",textOverflow:"clip"},M={position:"sticky",right:0},D={position:"sticky",left:0},H=12,R=o.default.create({container:{paddingHorizontal:H,paddingTop:4,paddingBottom:10},summaryRow:{flexDirection:"row",alignItems:"center"},row:{flexDirection:"row",alignItems:"center",paddingVertical:2,paddingLeft:18},gear:{color:"#666",fontSize:11,width:18,textAlign:"center"},summaryText:{color:"#8a8a8e",fontSize:12,flexShrink:1},name:{color:"#9a9aa0",fontSize:12,fontFamily:"monospace",minWidth:64,paddingRight:8},args:{color:"#666",fontSize:12,fontFamily:"monospace"},slack:{flex:1,minWidth:8},link:{color:"#6cb6ff",textDecorationLine:"underline"},trailing:{flexDirection:"row",alignItems:"center",backgroundColor:"#111",paddingLeft:10},duration:{color:"#666",fontSize:11,paddingLeft:8,textAlign:"right"},status:{fontSize:11,width:14,textAlign:"center",color:"#666"},detail:{alignSelf:"flex-start",backgroundColor:"#17171b",borderLeftWidth:2,borderLeftColor:"#333",paddingHorizontal:10,paddingVertical:6,marginBottom:4},detailSection:{paddingBottom:6},detailLabel:{color:"#8a8a8e",fontSize:10,textTransform:"uppercase",letterSpacing:.5,paddingBottom:2},detailBody:{color:"#c8c8cc",fontSize:11,fontFamily:"monospace",lineHeight:15},detailNote:{color:"#666",fontSize:10,fontStyle:"italic"},errorLine:{fontSize:11,fontFamily:"monospace",paddingLeft:36,paddingVertical:1},failText:{color:"#e57373"}})},759,[11,116,146,122,26,105,13,760,761,6]);
863
863
  __d(function(g,r,i,a,m,_e,d){"use strict";Object.defineProperty(_e,'__esModule',{value:!0}),_e.useHorizontalPanGuard=function(){const e=(0,n.useRef)(null),u=(0,n.useRef)(!1);return(0,n.useMemo)(()=>{const n=n=>{u.current&&n.stopPropagation?.(),e.current=null,u.current=!1};return{onTouchStart:n=>{e.current=t(n),u.current=!1},onTouchMove:n=>{const o=e.current;if(o){if(!u.current){const{x:e,y:c}=t(n),s=Math.abs(e-o.x),l=Math.abs(c-o.y);s>6&&s>1.2*l&&(u.current=!0)}u.current&&n.stopPropagation()}},onTouchEnd:n,onTouchCancel:n}},[])};var n=r(d[0]);function t(n){const t=n.nativeEvent?.touches?.[0]??n.nativeEvent??n;return{x:t.pageX??t.clientX??0,y:t.pageY??t.clientY??0}}},760,[11]);
864
- __d(function(g,r,i,a,m,_e,d){"use strict";Object.defineProperty(_e,'__esModule',{value:!0}),_e.inAppLinkProps=function(t,n){return t?{href:t,onClick:t=>{e(t)&&(t.preventDefault(),n())}}:{onPress:n}},_e.narrativeHref=function(e,t){return t?`/${e}?scrollToSeq=${t}`:`/${e}`},_e.fileHref=function(e,t,n,o,u){const f=new URLSearchParams({tab:"files",path:t});n&&f.set("line",o&&o>n?`${n}-${o}`:String(n));u&&f.set("pinned",u);return`/${e}?${f.toString()}`},r(d[0]);function e(e){return!(0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)}},761,[116]);
864
+ __d(function(g,r,i,a,m,_e,d){"use strict";Object.defineProperty(_e,'__esModule',{value:!0}),_e.inAppLinkProps=function(o,s){return o?{href:(0,e.withDaemonFragment)(o,(0,n.getActiveDaemonBraneId)()),onClick:e=>{t(e)&&(e.preventDefault(),s())}}:{onPress:s}},_e.newTabLinkProps=function(t,s,c){return o()?{onPress:c}:{href:(0,e.withDaemonFragment)(t,(0,n.getActiveDaemonBraneId)()),hrefAttrs:{target:"_blank",rel:"noopener"},onClick:s}},_e.narrativeHref=function(e,n){return n?`/${e}?scrollToSeq=${n}`:`/${e}`},_e.fileHref=function(e,n,t,o,s){const c=new URLSearchParams({tab:"files",path:n});t&&c.set("line",o&&o>t?`${t}-${o}`:String(t));s&&c.set("pinned",s);return`/${e}?${c.toString()}`},r(d[0]);var e=r(d[1]),n=r(d[2]);function t(e){return!(0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)}function o(){return"undefined"!=typeof window&&(!0===window.matchMedia?.("(display-mode: standalone)").matches||!0===window.navigator.standalone)}},761,[116,747,751]);
865
865
  __d(function(g,r,_i,a,m,_e,d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return H}});var t=r(d[0]);r(d[1]);var n=r(d[2]),o=r(d[3]),c=r(d[4]),s=r(d[5]),l=r(d[6]),i=e(r(d[7])),u=e(r(d[8])),f=e(r(d[9])),p=r(d[10]),y=r(d[11]);const h=1.4,v=16.799999999999997,b=(0,c.blockGlyphStylesheet)(h);function x(e,t){let n="";return e.ctrlKey&&(n+="C-"),e.altKey&&(n+="M-"),t&&e.shiftKey&&(n+="S-"),n}const C={Enter:"Enter",Escape:"Escape",Tab:"Tab",Backspace:"BSpace",Delete:"DC",Insert:"IC",ArrowUp:"Up",ArrowDown:"Down",ArrowLeft:"Left",ArrowRight:"Right",Home:"Home",End:"End",PageUp:"PPage",PageDown:"NPage",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12"};function w(e){const t=C[e.key];if(t)return x(e,!0)+t;if(" "===e.key){const t=x(e,!1);return t?t+"Space":" "}return(e.ctrlKey||e.altKey)&&1===e.key.length?x(e,!1)+e.key.toLowerCase():1!==e.key.length||e.ctrlKey||e.altKey||e.metaKey?null:e.key}const k=[{label:"Esc",keys:"Escape"},{label:"1",keys:"1"},{label:"2",keys:"2"},{label:"3",keys:"3"}],E="undefined"!=typeof navigator&&"undefined"!=typeof document&&(/iP(ad|hone|od)/.test(navigator.userAgent)||/Mac/.test(navigator.userAgent)&&"ontouchend"in document),S="undefined"!=typeof navigator&&/Mac|iP(ad|hone|od)/.test(navigator.platform||navigator.userAgent);function F(e){return"v"===e.key.toLowerCase()&&!e.altKey&&(S?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey)}const R=/[\u23fa\u{1F518}]/gu;const M=/\x1b\][\s\S]*?(?:\x07|\x1b\\)/g;function j(e){return e.replace(M,"")}function K({onPress:e,style:n,children:o}){const[c,s]=(0,t.useState)(!1),l=(0,t.useRef)(null),i=(0,t.useCallback)(()=>{e(),l.current&&clearTimeout(l.current),s(!0),l.current=setTimeout(()=>s(!1),180)},[e]);return(0,y.jsx)("button",{onClick:i,style:Object.assign({},n,c?{backgroundColor:"#4444cc",border:"1px solid #7c7cff",color:"#fff",boxShadow:"0 0 8px rgba(120, 120, 255, 0.8)"}:{boxShadow:"none"},{transition:"background-color 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, color 0.15s ease"}),children:o})}const L=(0,t.forwardRef)(function({conn:e,nid:x,active:C=!0,keyboardActive:S,agentType:M,role:L,onAtBottomChange:H,onTwin:A,onRevived:T},D){const P=(0,t.useRef)(null),z=(0,t.useRef)(null),_=(0,t.useRef)(null),B=(0,t.useRef)(!0),I=(0,t.useRef)(null),N=(0,t.useRef)(null),X=(0,t.useRef)(null),Y=(0,t.useRef)(0),q=(0,t.useRef)(C);q.current=C;const O=(0,t.useRef)(S??C);O.current=S??C;const W=(0,n.useIsFocused)(),U=(0,t.useRef)(W);U.current=W;const[G,$]=(0,t.useState)(!1),[J,Q]=(0,t.useState)(!1),V=(0,t.useRef)(null),Z=(0,t.useRef)(!1);Z.current=J;const[ee,te]=(0,t.useState)(!1),[ne,re]=(0,t.useState)(!1),oe=(0,t.useRef)(()=>{}),[ce,se]=(0,t.useState)(!1),le=(0,t.useRef)(!1),ie=(0,t.useRef)(null),ue=(0,t.useRef)(null),ae=(0,t.useRef)(null),de=(S??C)&&W,fe=(0,t.useRef)(de);fe.current=de;const pe=(0,t.useRef)(!0),ye=(0,t.useRef)(H);ye.current=H;const he=(0,t.useCallback)(e=>{pe.current=e,le.current&&e!==B.current&&(B.current=e,ye.current?.(e))},[]),me=(0,t.useCallback)(e=>{"C-End"===e?he(!0):"PPage"!==e&&"C-Home"!==e||he(!1)},[he]);(0,t.useImperativeHandle)(D,()=>({focus:()=>{const e=P.current;if(e)try{e.focus({preventScroll:!0})}catch{e.focus()}},scrollToTop:()=>{if(le.current)return _.current?.sendKeys("C-Home"),void he(!1);const e=P.current;e&&(e.scrollTop=0,B.current=!1,H?.(!1))},scrollToBottom:()=>{if(le.current)return _.current?.sendKeys("C-End"),void he(!0);const e=P.current;e&&(e.scrollTop=e.scrollHeight,B.current=!0,H?.(!0))},terminate:()=>{(0,l.sendInterrupt)(e=>_.current?.sendKeys(e))},revive:()=>{oe.current()}}),[H,he]);const ve=(0,t.useRef)(new WeakMap),ge=(0,t.useCallback)((e,t)=>{var n;0===t.length?e.textContent="\xa0":z.current?e.innerHTML=(0,c.paintBlockGlyphs)(z.current.ansi_to_html((n=j(t),E?n.replace(R,"\u25cf"):n))):e.textContent=j(t)},[]),be=(0,t.useCallback)(e=>{const t=document.createElement("div");return t.style.display="block",t.style.minHeight="1.4em",t.style.position="relative",ge(t,e),ve.current.set(t,e),t},[ge]),xe=(0,t.useCallback)((e,t)=>{ge(e,t),ve.current.set(e,t)},[ge]),Ce=(0,t.useCallback)(e=>ve.current.get(e),[]),we=(0,t.useCallback)(()=>{const e=P.current?.querySelector("pre"),t=ae.current,n=ue.current,o=ie.current;if(!e||!n||!o)return void(t?.parentNode&&t.parentNode.removeChild(t));const c=e.children[n.line];if(!c)return void(t?.parentNode&&t.parentNode.removeChild(t));const s=t??document.createElement("span");t||(s.style.position="absolute",s.style.top="0",s.style.pointerEvents="none",s.style.backgroundColor="#fff",s.style.mixBlendMode="difference",ae.current=s),s.style.left=n.col*o.width+"px",s.style.width=`${o.width}px`,s.style.height=`${v}px`,fe.current?(s.style.backgroundColor="#fff",s.style.border="none",s.style.animation="brane-cursor-blink 1.06s steps(1, end) infinite"):(s.style.backgroundColor="transparent",s.style.border="1px solid #fff",s.style.boxSizing="border-box",s.style.animation="none"),"relative"!==c.style.position&&(c.style.position="relative"),s.parentNode!==c&&c.appendChild(s)},[]);(0,t.useEffect)(()=>{we()},[de,we]);const ke=(0,t.useCallback)(()=>{const e=P.current,t=e?.querySelector("pre");if(t){for(;t.firstChild;)t.removeChild(t.firstChild);ve.current=new WeakMap,ae.current=null}_.current?.refresh()},[]),Ee=(0,t.useCallback)((e,t)=>{const n=Array.from(e.children),o=t.length,c=n.length,s=Math.min(o,c);let l=o!==c;for(let e=0;e<s;e++)Ce(n[e])!==t[e]&&(xe(n[e],t[e]),l=!0);if(o>c){const n=document.createDocumentFragment();for(let e=c;e<o;e++)n.appendChild(be(t[e]));e.appendChild(n)}else if(c>o)for(let t=c-1;t>=o;t--)e.removeChild(n[t]);return l},[be,xe,Ce]),Se=(0,t.useCallback)((e,t,n,o)=>{const c=Math.max(0,0|n),s=Math.max(0,0|o),l=Array.from(e.children).length;let i=!1;if(c>l){const t=document.createDocumentFragment();for(let e=l;e<c;e++)t.appendChild(be(""));e.appendChild(t),i=!0}const u=Array.from(e.children);let f=null;for(let e=0;e<t.length;e++){const n=c+e;n<u.length?Ce(u[n])!==t[e]&&(xe(u[n],t[e]),i=!0):(f||(f=document.createDocumentFragment()),f.appendChild(be(t[e])),i=!0)}f&&e.appendChild(f);const p=e.children.length;if(p>s){for(let t=p-1;t>=s;t--){const n=e.children[t];n&&e.removeChild(n)}i=!0}return i},[be,xe,Ce]),Fe=(0,t.useCallback)(e=>{const t=P.current;if(!t||!z.current)return;const n=t.querySelector("pre");if(!n)return;const o=t,c=le.current?pe.current:o.scrollHeight-o.scrollTop-o.clientHeight<40;let s;c!==B.current&&H?.(c),B.current=c,"frame"!==e.type&&"append"!==e.type||(ue.current=e.cursor??null);let l=!1;if("frame"===e.type){const t=e.data.split("\n");l=Ee(n,t),s=e.alternate_on}else if("append"===e.type){const t=e.data.split("\n");l=Se(n,t,e.lineOffset,e.totalLines),s=e.alternate_on}void 0!==s&&s!==le.current&&(le.current=s,se(s)),we(),l&&B.current&&o.scrollHeight>o.clientHeight&&(o.scrollTop=o.scrollHeight)},[Ee,Se,H,we]),Re=(0,t.useCallback)(()=>{X.current=null;const e=N.current;e&&(N.current=null,Fe(e))},[Fe]),Me=(0,t.useCallback)(e=>{if(!q.current)return void(I.current=e);const t=null!==N.current;N.current=e,t||(Y.current=Date.now()),null!==X.current?Date.now()-Y.current>=400&&(cancelAnimationFrame(X.current),X.current=null,Re()):X.current=requestAnimationFrame(Re)},[Re]);(0,t.useEffect)(()=>{if("undefined"==typeof document)return;const e=()=>{"visible"===document.visibilityState&&(null!==X.current&&(cancelAnimationFrame(X.current),X.current=null),N.current&&Re(),q.current&&_.current?.refresh())};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[Re]),(0,t.useEffect)(()=>()=>{null!==X.current&&(cancelAnimationFrame(X.current),X.current=null),N.current=null},[]);const je=(0,t.useRef)(void 0);(0,t.useEffect)(()=>{const e=_.current;if(!e)return;const t=je.current;je.current=C,C?(e.start(),I.current&&(Fe(I.current),I.current=null),!1===t&&ke()):e.stop()},[C,Fe,ke]),(0,t.useEffect)(()=>{if(!z.current){const e=new o.AnsiUp;e.use_classes=!1,z.current=e}const t=(0,l.createTerminalChannel)({conn:e,nid:x,onFrame:Me,onCursor:e=>{ue.current=e,q.current&&we()},onTerminated:()=>te(!0)});return _.current=t,t.start(),()=>{t.close(),_.current=null}},[e,x,Me,we]),(0,t.useEffect)(()=>{const e=e=>{if(!O.current||!U.current)return;if(Z.current)return;if(F(e))return;let t=w(e);t&&le.current&&("Home"===t?t="C-Home":"End"===t&&(t="C-End")),t&&_.current&&(e.preventDefault(),_.current.sendKeys(t),me(t))};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[]),(0,t.useEffect)(()=>{const e=e=>{if(!O.current||!U.current)return;const t=e.clipboardData?.getData("text");t&&(e.preventDefault(),_.current?.sendPaste(t),Z.current&&Q(!1))};return document.addEventListener("paste",e),()=>document.removeEventListener("paste",e)},[]);const Ke=(0,t.useCallback)(async()=>{try{const e=await(navigator.clipboard?.readText());if(e)return void _.current?.sendPaste(e);if(""===e)return}catch{}Q(!0)},[]);(0,t.useEffect)(()=>{const e=P.current;if(!e)return;const t=document.createElement("span");t.style.fontFamily="'Menlo', 'Monaco', 'Courier New', monospace",t.style.fontSize="12px",t.style.lineHeight="1.4",t.style.position="absolute",t.style.visibility="hidden",t.style.whiteSpace="pre",t.textContent="X",document.body.appendChild(t);const n=t.getBoundingClientRect().width;if(document.body.removeChild(t),0===n)return;const o=v;let c=0,s=0;const l=new ResizeObserver(e=>{for(const t of e){const{width:e,height:l}=t.contentRect,i=Math.floor((e-16)/n),u=Math.floor((l-16)/o);i>0&&u>0&&(i!==c||u!==s)&&(c=i,s=u,_.current?.resize(i,u))}});return l.observe(e),()=>l.disconnect()},[]),(0,t.useEffect)(()=>{const e=document.createElement("span");e.style.fontFamily="'Menlo', 'Monaco', 'Courier New', monospace",e.style.fontSize="12px",e.style.lineHeight="1.4",e.style.position="absolute",e.style.visibility="hidden",e.style.whiteSpace="pre",e.textContent="X",document.body.appendChild(e),ie.current={width:e.getBoundingClientRect().width,height:v},document.body.removeChild(e)},[]),(0,t.useEffect)(()=>{const e=P.current;if(!e||ce)return;const t=t=>{if(t.altKey||t.shiftKey||t.metaKey||t.ctrlKey)return;const n=ue.current,o=ie.current,c=_.current;if(!n||!o||!c)return;const s="undefined"!=typeof window?window.getSelection():null;if(s&&!s.isCollapsed)return;const l=e.querySelector("pre");if(!l)return;let i=t.target;for(;i&&i.parentElement!==l;)i=i.parentElement;if(!i)return;if(Array.prototype.indexOf.call(l.children,i)!==n.line)return;const u=Math.max(0,Math.round((t.clientX-i.getBoundingClientRect().left)/o.width))-n.col;0!==u&&c.sendKeys(u>0?"Right":"Left",Math.abs(u))};return e.addEventListener("click",t),()=>e.removeEventListener("click",t)},[ce]),(0,t.useEffect)(()=>{const e=P.current;if(!e||!ce)return;const t=(t,n)=>{if(!ie.current)return null;const o=e.querySelector("pre");if(!o)return null;const c=o.getBoundingClientRect(),s=t-c.left-8,l=n-c.top-8;return{col:Math.max(0,Math.floor(s/ie.current.width)),row:Math.max(0,Math.floor(l/ie.current.height))}};let n=!1,o=0,c=null;const s=e=>e.altKey||e.shiftKey,l=l=>{if(s(l))return;const i=t(l.clientX,l.clientY);if(i&&_.current){try{e.focus({preventScroll:!0})}catch{e.focus()}var u;l.preventDefault(),u=l.button,o=1===u?1:2===u?2:0,n=!0,c=i,_.current.sendMouse(i.col,i.row,o,"down")}},i=e=>{if(!n)return;const s=t(e.clientX,e.clientY);s&&_.current&&(c&&s.col===c.col&&s.row===c.row||(c=s,_.current.sendMouse(s.col,s.row,o,"drag")))},u=e=>{if(!n)return;const s=t(e.clientX,e.clientY)??c;n=!1,s&&_.current?(_.current.sendMouse(s.col,s.row,o,"up"),c=null):c=null},f=e=>{const n=t(e.clientX,e.clientY);if(!n||!_.current)return;e.preventDefault();const o=e.deltaY>0?"scroll_down":"scroll_up";_.current.sendMouse(n.col,n.row,0,o),"scroll_up"===o&&he(!1)},p=e=>{s(e)||e.preventDefault()};return e.addEventListener("mousedown",l),e.addEventListener("wheel",f,{passive:!1}),e.addEventListener("contextmenu",p),window.addEventListener("mousemove",i),window.addEventListener("mouseup",u),()=>{e.removeEventListener("mousedown",l),e.removeEventListener("wheel",f),e.removeEventListener("contextmenu",p),window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",u)}},[ce]),(0,t.useEffect)(()=>{const e=P.current;if(!e||!ce)return;let t=0,n=0,o=0,c=0,s=0;const l=l=>{if(1!==l.touches.length)return;const i=l.touches[0];if(t=i.clientX,n=i.clientY,o=i.clientY,ie.current){const t=(e.querySelector("pre")??e).getBoundingClientRect(),n=i.clientX-t.left-8,o=i.clientY-t.top-8;c=Math.max(0,Math.floor(n/ie.current.width)),s=Math.max(0,Math.floor(o/ie.current.height))}},i=e=>{if(1!==e.touches.length)return;if(!_.current)return;const l=e.touches[0],i=l.clientY-n,u=l.clientX-t;Math.abs(i)>Math.abs(u)&&e.preventDefault();const f=l.clientY-o;if(Math.abs(f)<20)return;const p=Math.trunc(f/20);o+=20*p;const y=p>0?"scroll_up":"scroll_down";for(let e=0;e<Math.abs(p);e++)_.current.sendMouse(c,s,0,y);"scroll_up"===y&&he(!1)};return e.addEventListener("touchstart",l,{passive:!0}),e.addEventListener("touchmove",i,{passive:!1}),()=>{e.removeEventListener("touchstart",l),e.removeEventListener("touchmove",i)}},[ce]),(0,t.useEffect)(()=>{const e=P.current;e&&B.current&&requestAnimationFrame(()=>{e.scrollTop=e.scrollHeight})},[G]);const Le=S??C;(0,t.useEffect)(()=>{if(!Le)return;const e=P.current;if(e)try{e.focus({preventScroll:!0})}catch{e.focus()}},[Le]),(0,t.useEffect)(()=>{const e=P.current;if(!e)return;let t=B.current;const n=()=>{const n=e.scrollHeight-e.scrollTop-e.clientHeight<40;n!==t&&(t=n,B.current=n,H?.(n))};return e.addEventListener("scroll",n,{passive:!0}),()=>e.removeEventListener("scroll",n)},[H]);const He=(0,t.useCallback)(async()=>{if((0,p.revivesAsTwin)(L)&&A)A();else{re(!0);try{const t=await(0,s.reviveNarrative)(e,x);if(t.nid&&t.nid!==x)return void T?.(t.nid);te(!1),_.current?.close();const n=(0,l.createTerminalChannel)({conn:e,nid:x,onFrame:Me,onTerminated:()=>te(!0)});_.current=n,n.start()}catch(e){console.error("Revive failed:",e)}finally{re(!1)}}},[e,x,Me,L,A,T]);oe.current=He;const Ae=(0,t.useCallback)(e=>{if(!_.current)return;if(e.keys)return void _.current.sendKeys(e.keys);if(!e.text)return;const t=e.text.split("\n");for(let e=0;e<t.length;e++)t[e]&&_.current.sendKeys(t[e]),e<t.length-1&&_.current.sendKeys("Enter")},[]),Te=(0,t.useCallback)(e=>{_.current?.sendKeys(e),me(e)},[me]),De=(0,t.useCallback)(e=>{if(_.current)return"transcript"===e.action?(_.current.sendKeys("C-o"),void ke()):void("paste"!==e.action?"clear-history"!==e.action?e.keys&&(_.current.sendKeys(e.keys),me(e.keys)):_.current.clearHistory():Ke())},[ke,me,Ke]);return(0,y.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,minHeight:0,overflow:"hidden"},children:[(0,y.jsx)("style",{children:"@keyframes brane-cursor-blink {\n 0%, 45% { opacity: 1; }\n 55%, 100% { opacity: 0; }\n}"}),(0,y.jsx)("style",{children:b}),(0,y.jsxs)("div",{style:{position:"relative",flex:1,minHeight:0,display:"flex",flexDirection:"column"},children:[ee&&(0,y.jsx)("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.85)"},children:(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{style:{position:"absolute",left:0,right:0,top:"50%",transform:"translateY(calc(-100% - 36px))",textAlign:"center",color:"#888",fontSize:15,fontFamily:"system-ui, -apple-system, sans-serif",pointerEvents:"none"},children:"Session ended"}),(0,y.jsx)("button",{onClick:()=>He(),disabled:ne,style:{padding:"10px 24px",borderRadius:8,border:"1px solid #4caf50",backgroundColor:ne?"#1c1c1e":"#2e7d32",color:"#fff",fontSize:15,fontWeight:"600",cursor:ne?"default":"pointer",opacity:ne?.6:1,fontFamily:"system-ui, -apple-system, sans-serif"},children:ne?"utility"===L?"Restarting\u2026":"Reviving\u2026":(0,p.revivesAsTwin)(L)?"/twin":"utility"===L?"Restart":"Revive"})]})}),(0,y.jsx)("div",{ref:P,tabIndex:0,style:Object.assign({flex:1,minHeight:0,overflow:ce?"hidden":"auto",backgroundColor:"#111",outline:"none",WebkitOverflowScrolling:"touch",touchAction:ce?"none":"auto"},ce?{display:"flex",flexDirection:"column",justifyContent:"flex-end",alignItems:"flex-start"}:{}),children:(0,y.jsx)("pre",{style:{margin:ce?"auto":0,padding:8,fontFamily:"'Menlo', 'Monaco', 'Courier New', monospace",fontSize:12,lineHeight:h,color:"#e0e0e0",whiteSpace:"pre",wordWrap:"normal",overflowX:"auto",cursor:ce?"pointer":"default"}})})]}),J&&(0,y.jsxs)("div",{style:{padding:"8px 10px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",flexShrink:0},children:[(0,y.jsx)("div",{style:{color:"#aaa",fontSize:12,marginBottom:6,fontFamily:"monospace"},children:"Paste here (long-press \u2192 Paste), or type and Send"}),(0,y.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"flex-start"},children:[(0,y.jsx)("textarea",{autoFocus:!0,ref:V,rows:2,style:{flex:1,backgroundColor:"#111",color:"#e0e0e0",border:"1px solid #555",borderRadius:6,padding:6,fontFamily:"'Menlo', 'Monaco', 'Courier New', monospace",fontSize:13,resize:"vertical"}}),(0,y.jsx)("button",{onClick:()=>{const e=V.current?.value??"";e&&_.current?.sendPaste(e),Q(!1)},style:{padding:"6px 10px",borderRadius:6,border:"1px solid #555",backgroundColor:"#252525",color:"#ccc",fontSize:13,fontFamily:"monospace",cursor:"pointer"},children:"Send"}),(0,y.jsx)("button",{onClick:()=>Q(!1),style:{padding:"6px 10px",borderRadius:6,border:"1px solid #555",backgroundColor:"#1e1e1e",color:"#888",fontSize:13,fontFamily:"monospace",cursor:"pointer"},children:"Cancel"})]})]}),G&&(0,y.jsx)(i.default,{sendKeys:Te}),(0,y.jsxs)("div",{style:{display:"flex",flexDirection:"row",justifyContent:"center",gap:8,padding:"6px 8px",paddingBottom:"max(6px, env(safe-area-inset-bottom))",minHeight:53,boxSizing:"border-box",backgroundColor:"#1a1a1a",borderTop:"1px solid rgb(216, 216, 216)",flexShrink:0,alignItems:"center"},children:[(0,y.jsx)("button",{onClick:()=>$(e=>!e),style:{padding:"6px 8px",borderRadius:6,border:"1px solid "+(G?"#4caf50":"#555"),backgroundColor:G?"#2e7d32":"#252525",color:G?"#fff":"#ccc",fontSize:15,lineHeight:"18px",fontFamily:"monospace",cursor:"pointer",whiteSpace:"nowrap"},children:"\ud83c\udfb9"}),(0,y.jsx)("div",{style:{width:1,height:24,backgroundColor:"#333",flexShrink:0}}),(0,y.jsx)(u.default,{onSelect:Ae}),(0,y.jsx)(f.default,{onControl:De}),(0,y.jsx)("div",{style:{width:1,height:24,backgroundColor:"#333",flexShrink:0}}),k.map(e=>(0,y.jsx)(K,{onPress:()=>_.current?.sendKeys(e.keys),style:{padding:"6px 8px",borderRadius:6,border:"1px solid #555",backgroundColor:"#1e1e1e",color:"#aaa",fontSize:14,fontFamily:"monospace",cursor:"pointer",whiteSpace:"nowrap",minWidth:28,textAlign:"center"},children:e.label},e.label)),(0,y.jsx)(K,{onPress:()=>_.current?.sendKeys("Enter"),style:{padding:"6px 8px",borderRadius:6,border:"1px solid #555",backgroundColor:"#1e1e1e",color:"#aaa",fontSize:14,fontFamily:"monospace",cursor:"pointer",whiteSpace:"nowrap",minWidth:34,textAlign:"center"},children:"Ret"})]})]})});var H=(0,t.memo)(L)},762,[11,116,165,763,764,745,749,765,766,768,769,6]);
866
866
  __d(function(_g,_r,_i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"AnsiUp",{enumerable:!0,get:function(){return r}});var t,n,i,s,l=this&&this.__makeTemplateObject||function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t};!(function(t){t[t.EOS=0]="EOS",t[t.Text=1]="Text",t[t.Incomplete=2]="Incomplete",t[t.ESC=3]="ESC",t[t.Unknown=4]="Unknown",t[t.SGR=5]="SGR",t[t.OSCURL=6]="OSCURL"})(t||(t={}));class r{constructor(){this.VERSION="6.0.6",this.setup_palettes(),this._use_classes=!1,this.bold=!1,this.faint=!1,this.italic=!1,this.underline=!1,this.fg=this.bg=null,this._buffer='',this._url_allowlist={http:1,https:1},this._escape_html=!0,this.boldStyle='font-weight:bold',this.faintStyle='opacity:0.7',this.italicStyle='font-style:italic',this.underlineStyle='text-decoration:underline'}set use_classes(t){this._use_classes=t}get use_classes(){return this._use_classes}set url_allowlist(t){this._url_allowlist=t}get url_allowlist(){return this._url_allowlist}set escape_html(t){this._escape_html=t}get escape_html(){return this._escape_html}set boldStyle(t){this._boldStyle=t}get boldStyle(){return this._boldStyle}set faintStyle(t){this._faintStyle=t}get faintStyle(){return this._faintStyle}set italicStyle(t){this._italicStyle=t}get italicStyle(){return this._italicStyle}set underlineStyle(t){this._underlineStyle=t}get underlineStyle(){return this._underlineStyle}setup_palettes(){this.ansi_colors=[[{rgb:[0,0,0],class_name:"ansi-black"},{rgb:[187,0,0],class_name:"ansi-red"},{rgb:[0,187,0],class_name:"ansi-green"},{rgb:[187,187,0],class_name:"ansi-yellow"},{rgb:[0,0,187],class_name:"ansi-blue"},{rgb:[187,0,187],class_name:"ansi-magenta"},{rgb:[0,187,187],class_name:"ansi-cyan"},{rgb:[255,255,255],class_name:"ansi-white"}],[{rgb:[85,85,85],class_name:"ansi-bright-black"},{rgb:[255,85,85],class_name:"ansi-bright-red"},{rgb:[0,255,0],class_name:"ansi-bright-green"},{rgb:[255,255,85],class_name:"ansi-bright-yellow"},{rgb:[85,85,255],class_name:"ansi-bright-blue"},{rgb:[255,85,255],class_name:"ansi-bright-magenta"},{rgb:[85,255,255],class_name:"ansi-bright-cyan"},{rgb:[255,255,255],class_name:"ansi-bright-white"}]],this.palette_256=[],this.ansi_colors.forEach(t=>{t.forEach(t=>{this.palette_256.push(t)})});let t=[0,95,135,175,215,255];for(let n=0;n<6;++n)for(let i=0;i<6;++i)for(let s=0;s<6;++s){let l={rgb:[t[n],t[i],t[s]],class_name:'truecolor'};this.palette_256.push(l)}let n=8;for(let t=0;t<24;++t,n+=10){let t={rgb:[n,n,n],class_name:'truecolor'};this.palette_256.push(t)}}escape_txt_for_html(t){return this._escape_html?t.replace(/[&<>"']/gm,t=>"&"===t?"&amp;":"<"===t?"&lt;":">"===t?"&gt;":"\""===t?"&quot;":"'"===t?"&#x27;":void 0):t}append_buffer(t){var n=this._buffer+t;this._buffer=n}get_next_packet(){var r={kind:t.EOS,text:'',url:''},_=this._buffer.length;if(0==_)return r;var c=this._buffer.indexOf("\x1b");if(-1==c)return r.kind=t.Text,r.text=this._buffer,this._buffer='',r;if(c>0)return r.kind=t.Text,r.text=this._buffer.slice(0,c),this._buffer=this._buffer.slice(c),r;if(0==c){if(_<3)return r.kind=t.Incomplete,r;var u=this._buffer.charAt(1);if('['!=u&&']'!=u&&'('!=u)return r.kind=t.ESC,r.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),r;if('['==u){this._csi_regex||(this._csi_regex=h(n||(n=l(["\n ^ # beginning of line\n #\n # First attempt\n (?: # legal sequence\n \x1b[ # CSI\n ([<-?]?) # private-mode char\n ([d;]*) # any digits or semicolons\n ([ -/]? # an intermediate modifier\n [@-~]) # the command\n )\n | # alternate (second attempt)\n (?: # illegal sequence\n \x1b[ # CSI\n [ -~]* # anything legal\n ([\0-\x1f:]) # anything illegal\n )\n "],["\n ^ # beginning of line\n #\n # First attempt\n (?: # legal sequence\n \\x1b\\[ # CSI\n ([\\x3c-\\x3f]?) # private-mode char\n ([\\d;]*) # any digits or semicolons\n ([\\x20-\\x2f]? # an intermediate modifier\n [\\x40-\\x7e]) # the command\n )\n | # alternate (second attempt)\n (?: # illegal sequence\n \\x1b\\[ # CSI\n [\\x20-\\x7e]* # anything legal\n ([\\x00-\\x1f:]) # anything illegal\n )\n "]))));let i=this._buffer.match(this._csi_regex);if(null===i)return r.kind=t.Incomplete,r;if(i[4])return r.kind=t.ESC,r.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),r;''!=i[1]||'m'!=i[3]?r.kind=t.Unknown:r.kind=t.SGR,r.text=i[2];var o=i[0].length;return this._buffer=this._buffer.slice(o),r}if(']'==u){if(_<4)return r.kind=t.Incomplete,r;if('8'!=this._buffer.charAt(2)||';'!=this._buffer.charAt(3))return r.kind=t.ESC,r.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),r;this._osc_st||(this._osc_st=f(i||(i=l(["\n (?: # legal sequence\n (\x1b\\) # ESC | # alternate\n (\x07) # BEL (what xterm did)\n )\n | # alternate (second attempt)\n ( # illegal sequence\n [\0-\x06] # anything illegal\n | # alternate\n [\b-\x1a] # anything illegal\n | # alternate\n [\x1c-\x1f] # anything illegal\n )\n "],["\n (?: # legal sequence\n (\\x1b\\\\) # ESC \\\n | # alternate\n (\\x07) # BEL (what xterm did)\n )\n | # alternate (second attempt)\n ( # illegal sequence\n [\\x00-\\x06] # anything illegal\n | # alternate\n [\\x08-\\x1a] # anything illegal\n | # alternate\n [\\x1c-\\x1f] # anything illegal\n )\n "])))),this._osc_st.lastIndex=0;{let n=this._osc_st.exec(this._buffer);if(null===n)return r.kind=t.Incomplete,r;if(n[3])return r.kind=t.ESC,r.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),r}{let n=this._osc_st.exec(this._buffer);if(null===n)return r.kind=t.Incomplete,r;if(n[3])return r.kind=t.ESC,r.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),r}this._osc_regex||(this._osc_regex=h(s||(s=l(["\n ^ # beginning of line\n #\n \x1b]8; # OSC Hyperlink\n [ -:<-~]* # params (excluding ;)\n ; # end of params\n ([!-~]{0,512}) # URL capture\n (?: # ST\n (?:\x1b\\) # ESC | # alternate\n (?:\x07) # BEL (what xterm did)\n )\n ([ -~]+) # TEXT capture\n \x1b]8;; # OSC Hyperlink End\n (?: # ST\n (?:\x1b\\) # ESC | # alternate\n (?:\x07) # BEL (what xterm did)\n )\n "],["\n ^ # beginning of line\n #\n \\x1b\\]8; # OSC Hyperlink\n [\\x20-\\x3a\\x3c-\\x7e]* # params (excluding ;)\n ; # end of params\n ([\\x21-\\x7e]{0,512}) # URL capture\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n ([\\x20-\\x7e]+) # TEXT capture\n \\x1b\\]8;; # OSC Hyperlink End\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n "]))));let n=this._buffer.match(this._osc_regex);if(null===n)return r.kind=t.ESC,r.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),r;r.kind=t.OSCURL,r.url=n[1],r.text=n[2];o=n[0].length;return this._buffer=this._buffer.slice(o),r}if('('==u)return r.kind=t.Unknown,this._buffer=this._buffer.slice(3),r}}ansi_to_html(n){this.append_buffer(n);for(var i=[];;){var s=this.get_next_packet();if(s.kind==t.EOS||s.kind==t.Incomplete)break;s.kind!=t.ESC&&s.kind!=t.Unknown&&(s.kind==t.Text?i.push(this.transform_to_html(this.with_state(s))):s.kind==t.SGR?this.process_ansi(s):s.kind==t.OSCURL&&i.push(this.process_hyperlink(s)))}return i.join("")}with_state(t){return{bold:this.bold,faint:this.faint,italic:this.italic,underline:this.underline,fg:this.fg,bg:this.bg,text:t.text}}process_ansi(t){let n=t.text.split(';');for(;n.length>0;){let t=n.shift(),i=parseInt(t,10);if(isNaN(i)||0===i)this.fg=null,this.bg=null,this.bold=!1,this.faint=!1,this.italic=!1,this.underline=!1;else if(1===i)this.bold=!0;else if(2===i)this.faint=!0;else if(3===i)this.italic=!0;else if(4===i)this.underline=!0;else if(21===i)this.bold=!1;else if(22===i)this.faint=!1,this.bold=!1;else if(23===i)this.italic=!1;else if(24===i)this.underline=!1;else if(39===i)this.fg=null;else if(49===i)this.bg=null;else if(i>=30&&i<38)this.fg=this.ansi_colors[0][i-30];else if(i>=40&&i<48)this.bg=this.ansi_colors[0][i-40];else if(i>=90&&i<98)this.fg=this.ansi_colors[1][i-90];else if(i>=100&&i<108)this.bg=this.ansi_colors[1][i-100];else if((38===i||48===i)&&n.length>0){let t=38===i,s=n.shift();if('5'===s&&n.length>0){let i=parseInt(n.shift(),10);i>=0&&i<=255&&(t?this.fg=this.palette_256[i]:this.bg=this.palette_256[i])}if('2'===s&&n.length>2){let i=parseInt(n.shift(),10),s=parseInt(n.shift(),10),l=parseInt(n.shift(),10);if(i>=0&&i<=255&&s>=0&&s<=255&&l>=0&&l<=255){let n={rgb:[i,s,l],class_name:'truecolor'};t?this.fg=n:this.bg=n}}}}}transform_to_html(t){let n=t.text;if(0===n.length)return n;if(n=this.escape_txt_for_html(n),!(t.bold||t.italic||t.faint||t.underline||null!==t.fg||null!==t.bg))return n;let i=[],s=[],l=t.fg,r=t.bg;t.bold&&i.push(this._boldStyle),t.faint&&i.push(this._faintStyle),t.italic&&i.push(this._italicStyle),t.underline&&i.push(this._underlineStyle),this._use_classes?(l&&('truecolor'!==l.class_name?s.push(`${l.class_name}-fg`):i.push(`color:rgb(${l.rgb.join(',')})`)),r&&('truecolor'!==r.class_name?s.push(`${r.class_name}-bg`):i.push(`background-color:rgb(${r.rgb.join(',')})`))):(l&&i.push(`color:rgb(${l.rgb.join(',')})`),r&&i.push(`background-color:rgb(${r.rgb})`));let h='',f='';return s.length&&(h=` class="${s.join(' ')}"`),i.length&&(f=` style="${i.join(';')}"`),`<span${f}${h}>${n}</span>`}process_hyperlink(t){let n=t.url.split(':');return n.length<1?'':this._url_allowlist[n[0]]?`<a href="${this.escape_txt_for_html(t.url)}">${this.escape_txt_for_html(t.text)}</a>`:''}}function h(t,...n){let i=t.raw[0].replace(/^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm,'');return new RegExp(i)}function f(t,...n){let i=t.raw[0].replace(/^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm,'');return new RegExp(i,'g')}},763,[]);
867
867
  __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"BLOCK_GLYPH_RE",{enumerable:!0,get:function(){return s}}),e.blockGlyphClass=$,e.paintBlockGlyphs=function(t){return p.test(t)?t.replace(s,t=>`<span class="tb ${$(t.charCodeAt(0))}">${t}</span>`):t},e.blockGlyphStylesheet=function(t){const n=[`.tb{display:inline-block;width:1ch;height:${t}em;overflow:hidden;vertical-align:top;-webkit-text-fill-color:transparent}`];for(const[t,o]of Object.entries(l))n.push(`.${$(+t)}{background:${o}}`);return n.join("\n")};const t="currentColor",n="transparent";function o(o,c){const l=+(100*c).toFixed(4)+"%";return`linear-gradient(to ${o},${t} ${l},${n} ${l})`}function c(o,c,l,s){const p=o=>o?t:n;return`conic-gradient(at 50% 50%,${p(o)} 0 25%,${p(c)} 0 50%,${p(l)} 0 75%,${p(s)} 0)`}const l={9600:o("bottom",.5),9601:o("top",.125),9602:o("top",.25),9603:o("top",.375),9604:o("top",.5),9605:o("top",.625),9606:o("top",.75),9607:o("top",.875),9608:t,9609:o("right",.875),9610:o("right",.75),9611:o("right",.625),9612:o("right",.5),9613:o("right",.375),9614:o("right",.25),9615:o("right",.125),9616:o("left",.5),9617:`color-mix(in srgb,${t} 25%,${n})`,9618:`color-mix(in srgb,${t} 50%,${n})`,9619:`color-mix(in srgb,${t} 75%,${n})`,9620:o("bottom",.125),9621:o("left",.125),9622:c(!1,!1,!0,!1),9623:c(!1,!0,!1,!1),9624:c(!1,!1,!1,!0),9625:c(!1,!0,!0,!0),9626:c(!1,!0,!1,!0),9627:c(!0,!1,!0,!0),9628:c(!0,!0,!1,!0),9629:c(!0,!1,!1,!1),9630:c(!0,!1,!0,!1),9631:c(!0,!0,!0,!1)},s=/[\u2580-\u259f]/g,p=/[\u2580-\u259f]/;function $(t){return`tb-${t.toString(16)}`}},764,[]);
@@ -878,7 +878,7 @@ __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{v
878
878
  __d(function(g,r,i,_a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"MessageSelection",{enumerable:!0,get:function(){return s}});const t=Object.freeze([]);class s{selected=new Set;snapshot=t;perSeq=new Map;whole=new Set;has=t=>this.selected.has(t);get size(){return this.selected.size}getSelected=()=>this.snapshot;subscribe=t=>(this.whole.add(t),()=>{this.whole.delete(t)});subscribeSeq=(t,s)=>{let c=this.perSeq.get(t);return c||(c=new Set,this.perSeq.set(t,c)),c.add(s),()=>{const c=this.perSeq.get(t);c&&(c.delete(s),0===c.size&&this.perSeq.delete(t))}};toggle=t=>{const s=!this.selected.has(t);return s?this.selected.add(t):this.selected.delete(t),this.commit([t]),s};clear=()=>{if(0===this.selected.size)return[];const t=[...this.selected];return this.selected.clear(),this.commit(t),t};replace=t=>{const s=new Set;for(const c of t)Number.isInteger(c)&&c>0&&s.add(c);const c=[];for(const t of this.selected)s.has(t)||c.push(t);for(const t of s)this.selected.has(t)||c.push(t);0!==c.length&&(this.selected=s,this.commit(c))};commit(s){this.snapshot=0===this.selected.size?t:[...this.selected].sort((t,s)=>t-s);for(const t of s){const s=this.perSeq.get(t);if(s)for(const t of[...s])t()}for(const t of[...this.whole])t()}}},775,[]);
879
879
  __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.glowHueFor=function(o){return t.hueFor(o)},e.recolorGlowHue=function(o){return t.recolor(o)};const t=new(r(d[0]).GlowHues)({getItem:t=>localStorage.getItem(t),setItem:(t,o)=>localStorage.setItem(t,o)})},776,[777]);
880
880
  __d(function(_g,_r,_i,_a,_m,e,_d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"GLOW_HUES_STORAGE_KEY",{enumerable:!0,get:function(){return r}}),Object.defineProperty(e,"RECENT_MS",{enumerable:!0,get:function(){return n}}),Object.defineProperty(e,"RECENT_LIMIT",{enumerable:!0,get:function(){return i}}),Object.defineProperty(e,"MIN_RECOLOR_STEP",{enumerable:!0,get:function(){return u}}),Object.defineProperty(e,"RECOLOR_CLEARANCE",{enumerable:!0,get:function(){return s}}),Object.defineProperty(e,"RECOLOR_CLEARANCE_MIN",{enumerable:!0,get:function(){return o}}),Object.defineProperty(e,"REJECTED_MS",{enumerable:!0,get:function(){return c}}),Object.defineProperty(e,"REJECTED_LIMIT",{enumerable:!0,get:function(){return a}}),Object.defineProperty(e,"REJECTED_CLEARANCE",{enumerable:!0,get:function(){return h}}),e.hueDistance=f,e.gapMidpoints=l,e.parseGlowAssignments=m,e.takenHues=b,e.firstHue=p,e.recolorHue=g,Object.defineProperty(e,"GlowHues",{enumerable:!0,get:function(){return O}});var t=_r(_d[0]);const r="brane:glow-hues",n=6048e5,i=12,u=100,s=.5,o=.25,c=36e5,a=4,h=60;function f(t,r){const n=Math.abs(t-r)%360;return Math.min(n,360-n)}const d=t=>(Math.round(t)%360+360)%360;function l(t){const r=[...new Set(t.map(d))].sort((t,r)=>t-r);if(0===r.length)return[];return r.map((t,n)=>{const i=(n+1<r.length?r[n+1]:r[0]+360)-t;return{width:i,mid:d(t+i/2)}}).map((t,r)=>Object.assign({},t,{i:r})).sort((t,r)=>r.width-t.width||t.i-r.i).map(t=>t.mid)}function m(t){if(!t)return{};try{const r=JSON.parse(t);if(!r||"object"!=typeof r||Array.isArray(r))return{};const n={};for(const[t,i]of Object.entries(r)){const r=i;if(r&&Number.isFinite(r.hue)&&Number.isFinite(r.seen)){n[t]={hue:d(r.hue),seen:r.seen};const i=Array.isArray(r.rejected)?r.rejected.filter(t=>t&&Number.isFinite(t.hue)&&Number.isFinite(t.at)):[];i.length&&(n[t].rejected=i.map(t=>({hue:d(t.hue),at:t.at})))}}return n}catch{return{}}}function b(t,r,u){return Object.entries(t).filter(([t,i])=>t!==r&&u-i.seen<=n).sort((t,r)=>r[1].seen-t[1].seen).slice(0,i).map(([,t])=>t.hue)}function p(r,n){return l(n)[0]??(0,t.speakerHue)(r)}function E(t,r){return r.reduce((r,n)=>Math.min(r,f(t,n)),180)}function g(t,r,n={}){const{rejected:i=[],random:c=Math.random}=n,a=[...new Set(r.map(d))],m=i.map(d),b=a.length?l(a).reduce((t,r)=>Math.max(t,E(r,a)),0):180,p=t=>{const r=[];for(let n=0;n<360;n++)E(n,a)>=b*t&&r.push(n);return r},g=p(s),O=p(o),j=r=>r.filter(r=>f(r,t)>=u),y=(t,r)=>t.filter(t=>E(t,m.slice(0,r))>=h),M=[];for(let t=m.length;t>0;t--)M.push(y(j(g),t),y(j(O),t));M.push(j(g),j(O),g.filter(r=>r!==d(t)));const _=M.find(t=>t.length>0);return _?_[Math.min(_.length-1,Math.floor(c()*_.length))]:l([...a,t])[0]}class O{constructor(t,r=Date.now,n=Math.random){this.store=t,this.now=r,this.random=n}read(){try{return m(this.store.getItem(r))}catch{return{}}}write(t){try{this.store.setItem(r,JSON.stringify(t))}catch{}}hueFor(t){const r=this.read(),n=this.now(),i=r[t];if(i)return n-i.seen>=6e4&&(r[t]=Object.assign({},i,{seen:n}),this.write(r)),i.hue;const u=p(t,b(r,t,n));return r[t]={hue:u,seen:n},this.write(r),u}recolor(r){const n=this.read(),i=this.now(),u=n[r]?.hue??(0,t.speakerHue)(r),s=[{hue:u,at:i},...n[r]?.rejected??[]].filter(t=>i-t.at<=c).slice(0,a),o=g(u,b(n,r,i),{rejected:s.map(t=>t.hue),random:this.random});return n[r]={hue:o,seen:i,rejected:s},this.write(n),o}}},777,[771]);
881
- __d(function(g,r,i,a,m,_e,d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"formatActivitySpan",{enumerable:!0,get:function(){return u.formatActivitySpan}}),_e.useActivitySpan=S,_e.NarrativeMetaLine=function({role:e,cost:t,createdAt:o,lastActivity:s,status:u,mcpConnected:c,dimmed:y=!1,style:h}){const b="ended"!==u||c?c?"#66d9a0":"#5b9bd5":"#666",x=y?"#666":"#d8d8dd",p=y?"#555":"#888",j=y?"#5a6a60":"#7bb894",v=S(o,s);return(0,f.jsxs)(n.default,{style:[w.row,h],children:[(0,f.jsx)(n.default,{style:[w.dot,{backgroundColor:b}]}),(0,f.jsxs)(l.default,{style:w.meta,numberOfLines:1,children:[t?(0,f.jsx)(l.default,{style:{color:j},children:t}):null,e?(0,f.jsxs)(l.default,{style:{color:x},children:[t?" ":"","/",e]}):null,null!=v?(0,f.jsxs)(l.default,{style:{color:p},children:[t||e?" ":"","from ",v]}):null]})]})},_e.NarrativeIdentity=function({id:e,foldPath:t,titleStyle:o,align:u="baseline",copyMarginLeft:c=6,dimmed:y=!1,style:h}){return(0,f.jsxs)(n.default,{style:[{flexDirection:"row",alignItems:u,minWidth:0},h],children:[(0,f.jsx)(l.default,{style:[w.nid,o],numberOfLines:1,children:e}),(0,f.jsx)(s.default,{text:e,size:13,padding:0,marginLeft:c}),t?(0,f.jsxs)(l.default,{style:w.fold,numberOfLines:1,children:[(0,f.jsx)(l.default,{style:{color:y?"#555":"#888"},children:"in "}),(0,f.jsx)(l.default,{style:{color:y?"#4a5a50":"#5e8a72"},children:t})]}):null]})};var t=r(d[0]),n=e(r(d[1])),l=e(r(d[2])),o=e(r(d[3])),s=e(r(d[4])),u=r(d[5]),f=r(d[6]);const c=1e3,y=6e4,h=36e5,b=new Map;let x=!1;function p(e,t){x||"undefined"==typeof document||(x=!0,document.addEventListener("visibilitychange",()=>{if(!document.hidden)for(const e of b.values())for(const t of e.subs)t()}));let n=b.get(e);n||(n={timer:null,subs:new Set},b.set(e,n));const l=n;return l.subs.add(t),l.timer||(l.timer=setInterval(()=>{if("undefined"==typeof document||!document.hidden)for(const e of l.subs)e()},e)),()=>{l.subs.delete(t),0===l.subs.size&&l.timer&&(clearInterval(l.timer),l.timer=null,b.delete(e))}}function j(e){const t=Math.floor((Date.now()-e)/1e3);return t<60?c:t<3600?y:t<604800?h:null}function v(e,t){const n="number"==typeof t&&t-e>6e4,l=[j(e),n?j(t):null].filter(e=>null!=e);return l.length?Math.min(...l):null}function S(e,n){const[,l]=(0,t.useReducer)(e=>e+1,0),o=null==e?null:v(e,n);return(0,t.useEffect)(()=>{if(null!=o)return p(o,l)},[o,e,n]),null==e?null:(0,u.formatActivitySpan)(e,n)}const w=o.default.create({row:{flexDirection:"row",alignItems:"center"},dot:{width:8,height:8,borderRadius:4,marginRight:10},nid:{color:"#d8d8dd",fontSize:15,fontWeight:"600",fontFamily:"monospace",flexShrink:1,minWidth:0,transform:[{translateY:1}]},meta:{fontSize:13,fontFamily:"monospace",flexShrink:1,minWidth:0},fold:{marginLeft:8,fontSize:13,fontFamily:"monospace",flexShrink:1,minWidth:0}})},778,[11,13,105,26,779,751,6]);
881
+ __d(function(g,r,i,a,m,_e,d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"formatActivitySpan",{enumerable:!0,get:function(){return u.formatActivitySpan}}),_e.useActivitySpan=S,_e.NarrativeMetaLine=function({role:e,cost:t,createdAt:o,lastActivity:s,status:u,mcpConnected:c,dimmed:y=!1,style:h}){const b="ended"!==u||c?c?"#66d9a0":"#5b9bd5":"#666",x=y?"#666":"#d8d8dd",p=y?"#555":"#888",j=y?"#5a6a60":"#7bb894",v=S(o,s);return(0,f.jsxs)(n.default,{style:[w.row,h],children:[(0,f.jsx)(n.default,{style:[w.dot,{backgroundColor:b}]}),(0,f.jsxs)(l.default,{style:w.meta,numberOfLines:1,children:[t?(0,f.jsx)(l.default,{style:{color:j},children:t}):null,e?(0,f.jsxs)(l.default,{style:{color:x},children:[t?" ":"","/",e]}):null,null!=v?(0,f.jsxs)(l.default,{style:{color:p},children:[t||e?" ":"","from ",v]}):null]})]})},_e.NarrativeIdentity=function({id:e,foldPath:t,titleStyle:o,align:u="baseline",copyMarginLeft:c=6,dimmed:y=!1,style:h}){return(0,f.jsxs)(n.default,{style:[{flexDirection:"row",alignItems:u,minWidth:0},h],children:[(0,f.jsx)(l.default,{style:[w.nid,o],numberOfLines:1,children:e}),(0,f.jsx)(s.default,{text:e,size:13,padding:0,marginLeft:c}),t?(0,f.jsxs)(l.default,{style:w.fold,numberOfLines:1,children:[(0,f.jsx)(l.default,{style:{color:y?"#555":"#888"},children:"in "}),(0,f.jsx)(l.default,{style:{color:y?"#4a5a50":"#5e8a72"},children:t})]}):null]})};var t=r(d[0]),n=e(r(d[1])),l=e(r(d[2])),o=e(r(d[3])),s=e(r(d[4])),u=r(d[5]),f=r(d[6]);const c=1e3,y=6e4,h=36e5,b=new Map;let x=!1;function p(e,t){x||"undefined"==typeof document||(x=!0,document.addEventListener("visibilitychange",()=>{if(!document.hidden)for(const e of b.values())for(const t of e.subs)t()}));let n=b.get(e);n||(n={timer:null,subs:new Set},b.set(e,n));const l=n;return l.subs.add(t),l.timer||(l.timer=setInterval(()=>{if("undefined"==typeof document||!document.hidden)for(const e of l.subs)e()},e)),()=>{l.subs.delete(t),0===l.subs.size&&l.timer&&(clearInterval(l.timer),l.timer=null,b.delete(e))}}function j(e){const t=Math.floor((Date.now()-e)/1e3);return t<60?c:t<3600?y:t<604800?h:null}function v(e,t){const n="number"==typeof t&&t-e>6e4,l=[j(e),n?j(t):null].filter(e=>null!=e);return l.length?Math.min(...l):null}function S(e,n){const[,l]=(0,t.useReducer)(e=>e+1,0),o=null==e?null:v(e,n);return(0,t.useEffect)(()=>{if(null!=o)return p(o,l)},[o,e,n]),null==e?null:(0,u.formatActivitySpan)(e,n)}const w=o.default.create({row:{flexDirection:"row",alignItems:"center"},dot:{width:8,height:8,borderRadius:4,marginRight:10},nid:{color:"#d8d8dd",fontSize:15,fontWeight:"600",fontFamily:"monospace",flexShrink:1,minWidth:0,transform:[{translateY:1}]},meta:{fontSize:13,fontFamily:"monospace",flexShrink:1,minWidth:0},fold:{marginLeft:8,fontSize:13,fontFamily:"monospace",flexShrink:1,minWidth:0}})},778,[11,13,105,26,779,752,6]);
882
882
  __d(function(g,r,i,a,m,_e,d){"use strict";Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return n}});var e=r(d[0]),t=r(d[1]);function n({text:n,size:o=11,padding:s=8,marginLeft:l=0,translateY:p=0}){const[u,c]=(0,e.useState)(!1);return(0,t.jsxs)("button",{type:"button","aria-label":u?`Copied ${n}`:`Copy ${n}`,onClick:e=>{e.stopPropagation(),e.preventDefault(),"undefined"!=typeof navigator&&navigator.clipboard&&(navigator.clipboard.writeText(n),c(!0),setTimeout(()=>c(!1),1200))},onPointerDown:e=>{e.stopPropagation()},style:{background:"none",border:"none",padding:s,margin:0,marginLeft:l,cursor:"pointer",color:u?"#66d9a0":"#888",fontSize:o,lineHeight:1,fontFamily:"inherit",transform:p?`translateY(${p}px)`:void 0,position:"relative"},children:[(0,t.jsx)("span",{style:{visibility:u?"hidden":"visible"},children:"\ud83d\udccb"}),u&&(0,t.jsx)("span",{"aria-hidden":!0,style:{position:"absolute",top:0,right:0,bottom:0,left:0,display:"flex",alignItems:"center",justifyContent:"center"},children:"\u2713"})]})}},779,[11,6]);
883
883
  __d(function(_g,r,i,a,m,_e,d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return x}});var t=r(d[0]),n=e(r(d[1])),o=e(r(d[2])),l=e(r(d[3])),s=e(r(d[4])),c=e(r(d[5])),u=e(r(d[6])),h=e(r(d[7])),f=r(d[8]),g=e(r(d[9])),p=r(d[10]),y=r(d[11]);function k(e){const t=e.split(":")[0]?.toLowerCase()??"";return"localhost"===t||"127.0.0.1"===t||"::1"===t||"0.0.0.0"===t?{kind:"loopback",hostname:t}:t.endsWith(".ts.net")?{kind:"tailnet",hostname:t}:{kind:"open",hostname:t}}function b(e,t,n){return"undefined"==typeof window?"":(0,p.buildMeldUrl)({host:window.location.host,protocol:window.location.protocol,search:window.location.search,path:t,conn:e,view:n})}function v(e,n){const[o,l]=(0,t.useState)(null),[s,c]=(0,t.useState)(0),u=n?.host,h=n?.token;return(0,t.useEffect)(()=>{if(!e||void 0===u||void 0===h)return l(null),void c(0);let t,n=!1;return 0===s&&l({state:"minting"}),(0,f.mintDeviceToken)({host:u,token:h}).then(e=>{n||(null!==e?(l({state:"minted",token:e.token,validForMs:e.validForMs}),void 0!==e.validForMs&&(t=setTimeout(()=>c(e=>e+1),Math.max(e.validForMs-6e4,3e4)))):l({state:"legacy"}))},e=>{n||l({state:"failed",error:e.message})}),()=>{n=!0,void 0!==t&&clearTimeout(t)}},[e,u,h,s]),o}function x({visible:e,conn:t,path:u,view:f,onClose:p}){const x=v(e,t),j="minted"===x?.state?x.token:"legacy"===x?.state?t?.token:void 0,C=e&&t&&void 0!==j?b({host:t.host,token:j},u,f??{}):null,T=t?k(t.host):null,M=null!==C&&"loopback"!==T?.kind;return(0,y.jsx)(o.default,{visible:e,transparent:!0,animationType:"fade",onRequestClose:p,children:(0,y.jsx)(l.default,{style:w.backdrop,onPress:p,children:(0,y.jsxs)(l.default,{style:w.card,onPress:e=>e.stopPropagation(),children:[(0,y.jsx)(s.default,{style:w.title,children:"Meld another device"}),"minting"===x?.state&&(0,y.jsx)(n.default,{style:w.minting,color:"#9ad6b3"}),"failed"===x?.state&&(0,y.jsxs)(s.default,{style:w.warning,children:["Couldn't mint a token for the new device: ",x.error]}),M&&(0,y.jsx)(c.default,{style:w.qrWrap,children:(0,y.jsx)(h.default,{value:C,size:232})}),"loopback"===T?.kind&&(0,y.jsxs)(s.default,{style:w.warning,children:[T.hostname," only works on this machine. Run `brane certify` and reconnect over Tailscale to share."]}),C&&(0,y.jsxs)(c.default,{style:w.urlRow,children:[(0,y.jsx)(s.default,{style:w.url,selectable:!0,children:C}),(0,y.jsx)(c.default,{style:w.urlCopy,children:(0,y.jsx)(g.default,{text:C,size:13,padding:4})})]}),"minted"===x?.state&&(0,y.jsxs)(s.default,{style:w.note,children:["This code carries a new token of its own, not this device's.",void 0!==x.validForMs&&` Unscanned, it lapses after ${Math.round(x.validForMs/6e4)} minutes; this sheet replaces it before then.`]}),"legacy"===x?.state&&(0,y.jsx)(s.default,{style:w.warning,children:"This daemon predates per-device tokens, so the code carries this device's own token."}),"tailnet"===T?.kind&&(0,y.jsxs)(s.default,{style:w.note,children:["Safe to display \u2014 ",T.hostname," only resolves inside your tailnet."]}),"open"===T?.kind&&(0,y.jsxs)(s.default,{style:w.warning,children:[T.hostname," isn't a Tailscale hostname \u2014 token is the only gate. Don't display in public."]}),(0,y.jsx)(l.default,{style:w.close,onPress:p,children:(0,y.jsx)(s.default,{style:w.closeText,children:"Close"})})]})})})}const w=u.default.create({backdrop:{flex:1,backgroundColor:"rgba(0,0,0,0.7)",justifyContent:"center",alignItems:"center",padding:24},card:{backgroundColor:"#1e1e1e",borderRadius:12,padding:20,width:"100%",maxWidth:320,alignItems:"center"},title:{color:"#e0e0e0",fontSize:16,fontWeight:"600",marginBottom:16,textAlign:"center"},minting:{marginVertical:24},qrWrap:{backgroundColor:"#fff",padding:12,borderRadius:8},urlRow:{alignSelf:"stretch",marginTop:14,paddingHorizontal:26},urlCopy:{position:"absolute",top:0,bottom:0,right:0,width:26,alignItems:"center",justifyContent:"center"},url:{color:"#9ad6b3",fontSize:11,fontFamily:"monospace",textAlign:"center",wordBreak:"break-all"},note:{color:"#9ad6b3",fontSize:12,marginTop:12,textAlign:"center",lineHeight:17},warning:{color:"#e0a04e",fontSize:13,marginVertical:8,textAlign:"center",lineHeight:18},close:{marginTop:16,paddingHorizontal:18,paddingVertical:8,borderRadius:6,backgroundColor:"#2a2a2a"},closeText:{color:"#ccc",fontSize:14}})},780,[11,416,153,146,105,13,26,781,745,779,747,6]);
884
884
  __d(function(g,_r,_i,a,m,_e,d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"QRCode",{enumerable:!0,get:function(){return p}}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return p}});var t=e(_r(d[0])),r=e(_r(d[1])),n=_r(d[2]),o=e(n);function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},l.apply(null,arguments)}function i(e,t){if(null==e)return{};var r,n,o=u(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n<l.length;n++)r=l[n],-1===t.indexOf(r)&&{}.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function u(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==t.indexOf(n))continue;r[n]=e[n]}return r}var f=["bgColor","bgD","fgD","fgColor","size","title","viewBoxSize","xmlns"],c={bgColor:t.default.oneOfType([t.default.object,t.default.string]).isRequired,bgD:t.default.string.isRequired,fgColor:t.default.oneOfType([t.default.object,t.default.string]).isRequired,fgD:t.default.string.isRequired,size:t.default.number.isRequired,title:t.default.string,viewBoxSize:t.default.number.isRequired,xmlns:t.default.string},s=(0,n.forwardRef)(function(e,t){var r=e.bgColor,n=e.bgD,u=e.fgD,c=e.fgColor,s=e.size,v=e.title,b=e.viewBoxSize,p=e.xmlns,y=void 0===p?"http://www.w3.org/2000/svg":p,C=i(e,f);return o.default.createElement("svg",l({},C,{height:s,ref:t,viewBox:"0 0 ".concat(b," ").concat(b),width:s,xmlns:y}),v?o.default.createElement("title",null,v):null,o.default.createElement("path",{d:n,fill:r}),o.default.createElement("path",{d:u,fill:c}))});s.displayName="QRCodeSvg",s.propTypes=c;var v=["bgColor","fgColor","level","size","value"];r.default.stringToBytes=function(e){return Array.from((new TextEncoder).encode(e))};var b={bgColor:t.default.oneOfType([t.default.object,t.default.string]),fgColor:t.default.oneOfType([t.default.object,t.default.string]),level:t.default.string,size:t.default.number,value:t.default.string.isRequired},p=(0,n.forwardRef)(function(e,t){var n=e.bgColor,u=void 0===n?"#FFFFFF":n,f=e.fgColor,c=void 0===f?"#000000":f,b=e.level,p=void 0===b?"L":b,y=e.size,C=void 0===y?256:y,w=e.value,O=i(e,v),j=(0,r.default)(0,p);j.addData(w),j.make();var h=j.getModuleCount(),x=Array.from({length:h},function(e,t){return Array.from({length:h},function(e,r){return j.isDark(t,r)})});return o.default.createElement(s,l({},O,{bgColor:u,bgD:x.map(function(e,t){return e.map(function(e,r){return e?"":"M ".concat(r," ").concat(t," l 1 0 0 1 -1 0 Z")}).join(" ")}).join(" "),fgColor:c,fgD:x.map(function(e,t){return e.map(function(e,r){return e?"M ".concat(r," ").concat(t," l 1 0 0 1 -1 0 Z"):""}).join(" ")}).join(" "),ref:t,size:C,viewBoxSize:h}))});p.displayName="QRCode",p.propTypes=b},781,[782,785,11]);
@@ -886,7 +886,7 @@ __d(function(g,r,i,a,m,e,d){m.exports=r(d[0])()},782,[783]);
886
886
  __d(function(g,r,i,a,m,e,d){'use strict';var n=r(d[0]);function t(){}function o(){}o.resetWarningCache=t,m.exports=function(){function p(t,o,p,c,s,y){if(y!==n){var f=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw f.name='Invariant Violation',f}}function c(){return p}p.isRequired=p;var s={array:p,bigint:p,bool:p,func:p,number:p,object:p,string:p,symbol:p,any:p,arrayOf:c,element:p,elementType:p,instanceOf:c,node:p,objectOf:c,oneOf:c,oneOfType:c,shape:c,exact:c,checkPropTypes:o,resetWarningCache:t};return s.PropTypes=s,s}},783,[784]);
887
887
  __d(function(g,r,i,a,m,e,d){'use strict';m.exports='SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'},784,[]);
888
888
  __d(function(g,_r,_i,_a,m,_e,_d){"use strict";Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return I}}),Object.defineProperty(_e,"qrcode",{enumerable:!0,get:function(){return t}}),Object.defineProperty(_e,"stringToBytes",{enumerable:!0,get:function(){return P}});const t=function(t,e){let n=t;const r=i[e];let o=null,u=0,c=null;const l=[],f={},s=function(t,e){u=4*n+17,o=(function(t){const e=new Array(t);for(let n=0;n<t;n+=1){e[n]=new Array(t);for(let r=0;r<t;r+=1)e[n][r]=null}return e})(u),a(0,0),a(u-7,0),a(0,u-7),y(),d(),L(t,e),n>=7&&x(t),null==c&&(c=I(n,r,l)),D(c,e)},a=function(t,e){for(let n=-1;n<=7;n+=1)if(!(t+n<=-1||u<=t+n))for(let r=-1;r<=7;r+=1)e+r<=-1||u<=e+r||(o[t+n][e+r]=0<=n&&n<=6&&(0==r||6==r)||0<=r&&r<=6&&(0==n||6==n)||2<=n&&n<=4&&2<=r&&r<=4)},h=function(){let t=0,e=0;for(let n=0;n<8;n+=1){s(!0,n);const r=w.getLostPoint(f);(0==n||t>r)&&(t=r,e=n)}return e},d=function(){for(let t=8;t<u-8;t+=1)null==o[t][6]&&(o[t][6]=t%2==0);for(let t=8;t<u-8;t+=1)null==o[6][t]&&(o[6][t]=t%2==0)},y=function(){const t=w.getPatternPosition(n);for(let e=0;e<t.length;e+=1)for(let n=0;n<t.length;n+=1){const r=t[e],i=t[n];if(null==o[r][i])for(let t=-2;t<=2;t+=1)for(let e=-2;e<=2;e+=1)o[r+t][i+e]=-2==t||2==t||-2==e||2==e||0==t&&0==e}},x=function(t){const e=w.getBCHTypeNumber(n);for(let n=0;n<18;n+=1){const r=!t&&1==(e>>n&1);o[Math.floor(n/3)][n%3+u-8-3]=r}for(let n=0;n<18;n+=1){const r=!t&&1==(e>>n&1);o[n%3+u-8-3][Math.floor(n/3)]=r}},L=function(t,e){const n=r<<3|e,i=w.getBCHTypeInfo(n);for(let e=0;e<15;e+=1){const n=!t&&1==(i>>e&1);e<6?o[e][8]=n:e<8?o[e+1][8]=n:o[u-15+e][8]=n}for(let e=0;e<15;e+=1){const n=!t&&1==(i>>e&1);e<8?o[8][u-e-1]=n:e<9?o[8][15-e-1+1]=n:o[8][15-e-1]=n}o[u-8][8]=!t},D=function(t,e){let n=-1,r=u-1,i=7,c=0;const l=w.getMaskFunction(e);for(let e=u-1;e>0;e-=2)for(6==e&&(e-=1);;){for(let n=0;n<2;n+=1)if(null==o[r][e-n]){let u=!1;c<t.length&&(u=1==(t[c]>>>i&1));l(r,e-n)&&(u=!u),o[r][e-n]=u,i-=1,-1==i&&(c+=1,i=7)}if(r+=n,r<0||u<=r){r-=n,n=-n;break}}},S=function(t,e){let n=0,r=0,o=0;const i=new Array(e.length),u=new Array(e.length);for(let c=0;c<e.length;c+=1){const l=e[c].dataCount,f=e[c].totalCount-l;r=Math.max(r,l),o=Math.max(o,f),i[c]=new Array(l);for(let e=0;e<i[c].length;e+=1)i[c][e]=255&t.getBuffer()[e+n];n+=l;const s=w.getErrorCorrectPolynomial(f),a=p(i[c],s.getLength()-1).mod(s);u[c]=new Array(s.getLength()-1);for(let t=0;t<u[c].length;t+=1){const e=t+a.getLength()-u[c].length;u[c][t]=e>=0?a.getAt(e):0}}let c=0;for(let t=0;t<e.length;t+=1)c+=e[t].totalCount;const l=new Array(c);let f=0;for(let t=0;t<r;t+=1)for(let n=0;n<e.length;n+=1)t<i[n].length&&(l[f]=i[n][t],f+=1);for(let t=0;t<o;t+=1)for(let n=0;n<e.length;n+=1)t<u[n].length&&(l[f]=u[n][t],f+=1);return l},I=function(t,e,n){const r=B.getRSBlocks(t,e),o=k();for(let e=0;e<n.length;e+=1){const r=n[e];o.put(r.getMode(),4),o.put(r.getLength(),w.getLengthInBits(r.getMode(),t)),r.write(o)}let i=0;for(let t=0;t<r.length;t+=1)i+=r[t].dataCount;if(o.getLengthInBits()>8*i)throw'code length overflow. ('+o.getLengthInBits()+'>'+8*i+')';for(o.getLengthInBits()+4<=8*i&&o.put(0,4);o.getLengthInBits()%8!=0;)o.putBit(!1);for(;!(o.getLengthInBits()>=8*i||(o.put(236,8),o.getLengthInBits()>=8*i));)o.put(17,8);return S(o,r)};f.addData=function(t,e){let n=null;switch(e=e||'Byte'){case'Numeric':n=C(t);break;case'Alphanumeric':n=b(t);break;case'Byte':n=A(t);break;case'Kanji':n=M(t);break;default:throw'mode:'+e}l.push(n),c=null},f.isDark=function(t,e){if(t<0||u<=t||e<0||u<=e)throw t+','+e;return o[t][e]},f.getModuleCount=function(){return u},f.make=function(){if(n<1){let t=1;for(;t<40;t++){const e=B.getRSBlocks(t,r),n=k();for(let e=0;e<l.length;e++){const r=l[e];n.put(r.getMode(),4),n.put(r.getLength(),w.getLengthInBits(r.getMode(),t)),r.write(n)}let o=0;for(let t=0;t<e.length;t++)o+=e[t].dataCount;if(n.getLengthInBits()<=8*o)break}n=t}s(!1,h())},f.createTableTag=function(t,e){t=t||2;let n='';n+='<table style="',n+=' border-width: 0px; border-style: none;',n+=' border-collapse: collapse;',n+=' padding: 0px; margin: '+(e=void 0===e?4*t:e)+'px;',n+='">',n+='<tbody>';for(let e=0;e<f.getModuleCount();e+=1){n+='<tr>';for(let r=0;r<f.getModuleCount();r+=1)n+='<td style="',n+=' border-width: 0px; border-style: none;',n+=' border-collapse: collapse;',n+=' padding: 0px; margin: 0px;',n+=' width: '+t+'px;',n+=' height: '+t+'px;',n+=' background-color: ',n+=f.isDark(e,r)?'#000000':'#ffffff',n+=';',n+='"/>';n+='</tr>'}return n+='</tbody>',n+='</table>',n},f.createSvgTag=function(t,e,n,r){let o={};'object'==typeof arguments[0]&&(o=arguments[0],t=o.cellSize,e=o.margin,n=o.alt,r=o.title),t=t||2,e=void 0===e?4*t:e,(n='string'==typeof n?{text:n}:n||{}).text=n.text||null,n.id=n.text?n.id||'qrcode-description':null,(r='string'==typeof r?{text:r}:r||{}).text=r.text||null,r.id=r.text?r.id||'qrcode-title':null;const i=f.getModuleCount()*t+2*e;let u,c,l,s,a,h='';for(a='l'+t+',0 0,'+t+' -'+t+',0 0,-'+t+'z ',h+='<svg version="1.1" xmlns="http://www.w3.org/2000/svg"',h+=o.scalable?'':' width="'+i+'px" height="'+i+'px"',h+=' viewBox="0 0 '+i+' '+i+'" ',h+=' preserveAspectRatio="xMinYMin meet"',h+=r.text||n.text?' role="img" aria-labelledby="'+P([r.id,n.id].join(' ').trim())+'"':'',h+='>',h+=r.text?'<title id="'+P(r.id)+'">'+P(r.text)+'</title>':'',h+=n.text?'<description id="'+P(n.id)+'">'+P(n.text)+'</description>':'',h+='<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>',h+='<path d="',l=0;l<f.getModuleCount();l+=1)for(s=l*t+e,u=0;u<f.getModuleCount();u+=1)f.isDark(l,u)&&(c=u*t+e,h+='M'+c+','+s+a);return h+='" stroke="transparent" fill="black"/>',h+='</svg>',h},f.createDataURL=function(t,e){t=t||2,e=void 0===e?4*t:e;const n=f.getModuleCount()*t+2*e,r=e,o=n-e;return v(n,n,function(e,n){if(r<=e&&e<o&&r<=n&&n<o){const o=Math.floor((e-r)/t),i=Math.floor((n-r)/t);return f.isDark(i,o)?0:1}return 1})},f.createImgTag=function(t,e,n){t=t||2,e=void 0===e?4*t:e;const r=f.getModuleCount()*t+2*e;let o='';return o+='<img',o+=' src="',o+=f.createDataURL(t,e),o+='"',o+=' width="',o+=r,o+='"',o+=' height="',o+=r,o+='"',n&&(o+=' alt="',o+=P(n),o+='"'),o+='/>',o};const P=function(t){let e='';for(let n=0;n<t.length;n+=1){const r=t.charAt(n);switch(r){case'<':e+='&lt;';break;case'>':e+='&gt;';break;case'&':e+='&amp;';break;case'"':e+='&quot;';break;default:e+=r}}return e},T=function(t){t=void 0===t?2:t;const e=1*f.getModuleCount()+2*t,n=t,r=e-t;let o,i,u,c,l;const s={'\u2588\u2588':'\u2588','\u2588 ':'\u2580',' \u2588':'\u2584',' ':' '},a={'\u2588\u2588':'\u2580','\u2588 ':'\u2580',' \u2588':' ',' ':' '};let h='';for(o=0;o<e;o+=2){for(u=Math.floor((o-n)/1),c=Math.floor((o+1-n)/1),i=0;i<e;i+=1)l='\u2588',n<=i&&i<r&&n<=o&&o<r&&f.isDark(u,Math.floor((i-n)/1))&&(l=' '),n<=i&&i<r&&n<=o+1&&o+1<r&&f.isDark(c,Math.floor((i-n)/1))?l+=' ':l+='\u2588',h+=t<1&&o+1>=r?a[l]:s[l];h+='\n'}return e%2&&t>0?h.substring(0,h.length-e-1)+Array(e+1).join('\u2580'):h.substring(0,h.length-1)};return f.createASCII=function(t,e){if((t=t||1)<2)return T(e);t-=1,e=void 0===e?2*t:e;const n=f.getModuleCount()*t+2*e,r=e,o=n-e;let i,u,c,l;const s=Array(t+1).join('\u2588\u2588'),a=Array(t+1).join(' ');let h='',d='';for(i=0;i<n;i+=1){for(c=Math.floor((i-r)/t),d='',u=0;u<n;u+=1)l=1,r<=u&&u<o&&r<=i&&i<o&&f.isDark(c,Math.floor((u-r)/t))&&(l=0),d+=l?s:a;for(c=0;c<t;c+=1)h+=d+'\n'}return h.substring(0,h.length-1)},f.renderTo2dContext=function(t,e){e=e||2;const n=f.getModuleCount();for(let r=0;r<n;r++)for(let o=0;o<n;o++)t.fillStyle=f.isDark(r,o)?'black':'white',t.fillRect(o*e,r*e,e,e)},f};t.stringToBytes=function(t){const e=[];for(let n=0;n<t.length;n+=1){const r=t.charCodeAt(n);e.push(255&r)}return e},t.createStringToBytes=function(t,e){const n=(function(){const n=D(t),r=function(){const t=n.read();if(-1==t)throw'eof';return t};let o=0;const i={};for(;;){const t=n.read();if(-1==t)break;const e=r(),u=r()<<8|r();i[String.fromCharCode(t<<8|e)]=u,o+=1}if(o!=e)throw o+' != '+e;return i})(),r='?'.charCodeAt(0);return function(t){const e=[];for(let o=0;o<t.length;o+=1){const i=t.charCodeAt(o);if(i<128)e.push(i);else{const i=n[t.charAt(o)];'number'==typeof i?(255&i)==i?e.push(i):(e.push(i>>>8),e.push(255&i)):e.push(r)}}return e}};const e=1,n=2,r=4,o=8,i={L:1,M:0,Q:3,H:2},u=0,c=1,l=2,f=3,s=4,a=5,h=6,d=7,w=(function(){const t=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],i=1335,w=7973,B={},k=function(t){let e=0;for(;0!=t;)e+=1,t>>>=1;return e};return B.getBCHTypeInfo=function(t){let e=t<<10;for(;k(e)-k(i)>=0;)e^=i<<k(e)-k(i);return 21522^(t<<10|e)},B.getBCHTypeNumber=function(t){let e=t<<12;for(;k(e)-k(w)>=0;)e^=w<<k(e)-k(w);return t<<12|e},B.getPatternPosition=function(e){return t[e-1]},B.getMaskFunction=function(t){switch(t){case u:return function(t,e){return(t+e)%2==0};case c:return function(t,e){return t%2==0};case l:return function(t,e){return e%3==0};case f:return function(t,e){return(t+e)%3==0};case s:return function(t,e){return(Math.floor(t/2)+Math.floor(e/3))%2==0};case a:return function(t,e){return t*e%2+t*e%3==0};case h:return function(t,e){return(t*e%2+t*e%3)%2==0};case d:return function(t,e){return(t*e%3+(t+e)%2)%2==0};default:throw'bad maskPattern:'+t}},B.getErrorCorrectPolynomial=function(t){let e=p([1],0);for(let n=0;n<t;n+=1)e=e.multiply(p([1,y.gexp(n)],0));return e},B.getLengthInBits=function(t,i){if(1<=i&&i<10)switch(t){case e:return 10;case n:return 9;case r:case o:return 8;default:throw'mode:'+t}else if(i<27)switch(t){case e:return 12;case n:return 11;case r:return 16;case o:return 10;default:throw'mode:'+t}else{if(!(i<41))throw'type:'+i;switch(t){case e:return 14;case n:return 13;case r:return 16;case o:return 12;default:throw'mode:'+t}}},B.getLostPoint=function(t){const e=t.getModuleCount();let n=0;for(let r=0;r<e;r+=1)for(let o=0;o<e;o+=1){let i=0;const u=t.isDark(r,o);for(let n=-1;n<=1;n+=1)if(!(r+n<0||e<=r+n))for(let c=-1;c<=1;c+=1)o+c<0||e<=o+c||0==n&&0==c||u==t.isDark(r+n,o+c)&&(i+=1);i>5&&(n+=3+i-5)}for(let r=0;r<e-1;r+=1)for(let o=0;o<e-1;o+=1){let e=0;t.isDark(r,o)&&(e+=1),t.isDark(r+1,o)&&(e+=1),t.isDark(r,o+1)&&(e+=1),t.isDark(r+1,o+1)&&(e+=1),0!=e&&4!=e||(n+=3)}for(let r=0;r<e;r+=1)for(let o=0;o<e-6;o+=1)t.isDark(r,o)&&!t.isDark(r,o+1)&&t.isDark(r,o+2)&&t.isDark(r,o+3)&&t.isDark(r,o+4)&&!t.isDark(r,o+5)&&t.isDark(r,o+6)&&(n+=40);for(let r=0;r<e;r+=1)for(let o=0;o<e-6;o+=1)t.isDark(o,r)&&!t.isDark(o+1,r)&&t.isDark(o+2,r)&&t.isDark(o+3,r)&&t.isDark(o+4,r)&&!t.isDark(o+5,r)&&t.isDark(o+6,r)&&(n+=40);let r=0;for(let n=0;n<e;n+=1)for(let o=0;o<e;o+=1)t.isDark(o,n)&&(r+=1);return n+=10*(Math.abs(100*r/e/e-50)/5),n},B})(),y=(function(){const t=new Array(256),e=new Array(256);for(let e=0;e<8;e+=1)t[e]=1<<e;for(let e=8;e<256;e+=1)t[e]=t[e-4]^t[e-5]^t[e-6]^t[e-8];for(let n=0;n<255;n+=1)e[t[n]]=n;const n={glog:function(t){if(t<1)throw'glog('+t+')';return e[t]},gexp:function(e){for(;e<0;)e+=255;for(;e>=256;)e-=255;return t[e]}};return n})(),p=function(t,e){if(void 0===t.length)throw t.length+'/'+e;const n=(function(){let n=0;for(;n<t.length&&0==t[n];)n+=1;const r=new Array(t.length-n+e);for(let e=0;e<t.length-n;e+=1)r[e]=t[e+n];return r})(),r={getAt:function(t){return n[t]},getLength:function(){return n.length},multiply:function(t){const e=new Array(r.getLength()+t.getLength()-1);for(let n=0;n<r.getLength();n+=1)for(let o=0;o<t.getLength();o+=1)e[n+o]^=y.gexp(y.glog(r.getAt(n))+y.glog(t.getAt(o)));return p(e,0)},mod:function(t){if(r.getLength()-t.getLength()<0)return r;const e=y.glog(r.getAt(0))-y.glog(t.getAt(0)),n=new Array(r.getLength());for(let t=0;t<r.getLength();t+=1)n[t]=r.getAt(t);for(let r=0;r<t.getLength();r+=1)n[r]^=y.gexp(y.glog(t.getAt(r))+e);return p(n,0).mod(t)}};return r},B=(function(){const t=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],e=function(t,e){const n={};return n.totalCount=t,n.dataCount=e,n},n={},r=function(e,n){switch(n){case i.L:return t[4*(e-1)+0];case i.M:return t[4*(e-1)+1];case i.Q:return t[4*(e-1)+2];case i.H:return t[4*(e-1)+3];default:return}};return n.getRSBlocks=function(t,n){const o=r(t,n);if(void 0===o)throw'bad rs block @ typeNumber:'+t+'/errorCorrectionLevel:'+n;const i=o.length/3,u=[];for(let t=0;t<i;t+=1){const n=o[3*t+0],r=o[3*t+1],i=o[3*t+2];for(let t=0;t<n;t+=1)u.push(e(r,i))}return u},n})(),k=function(){const t=[];let e=0;const n={getBuffer:function(){return t},getAt:function(e){const n=Math.floor(e/8);return 1==(t[n]>>>7-e%8&1)},put:function(t,e){for(let r=0;r<e;r+=1)n.putBit(1==(t>>>e-r-1&1))},getLengthInBits:function(){return e},putBit:function(n){const r=Math.floor(e/8);t.length<=r&&t.push(0),n&&(t[r]|=128>>>e%8),e+=1}};return n},C=function(t){const n=e,r=t,o={getMode:function(){return n},getLength:function(t){return r.length},write:function(t){const e=r;let n=0;for(;n+2<e.length;)t.put(i(e.substring(n,n+3)),10),n+=3;n<e.length&&(e.length-n==1?t.put(i(e.substring(n,n+1)),4):e.length-n==2&&t.put(i(e.substring(n,n+2)),7))}},i=function(t){let e=0;for(let n=0;n<t.length;n+=1)e=10*e+u(t.charAt(n));return e},u=function(t){if('0'<=t&&t<='9')return t.charCodeAt(0)-'0'.charCodeAt(0);throw'illegal char :'+t};return o},b=function(t){const e=n,r=t,o={getMode:function(){return e},getLength:function(t){return r.length},write:function(t){const e=r;let n=0;for(;n+1<e.length;)t.put(45*i(e.charAt(n))+i(e.charAt(n+1)),11),n+=2;n<e.length&&t.put(i(e.charAt(n)),6)}},i=function(t){if('0'<=t&&t<='9')return t.charCodeAt(0)-'0'.charCodeAt(0);if('A'<=t&&t<='Z')return t.charCodeAt(0)-'A'.charCodeAt(0)+10;switch(t){case' ':return 36;case'$':return 37;case'%':return 38;case'*':return 39;case'+':return 40;case'-':return 41;case'.':return 42;case'/':return 43;case':':return 44;default:throw'illegal char :'+t}};return o},A=function(e){const n=r,o=t.stringToBytes(e),i={getMode:function(){return n},getLength:function(t){return o.length},write:function(t){for(let e=0;e<o.length;e+=1)t.put(o[e],8)}};return i},M=function(e){const n=o,r=t.stringToBytes;!(function(){const t=r('\u53cb');if(2!=t.length||38726!=(t[0]<<8|t[1]))throw'sjis not supported.'})();const i=r(e),u={getMode:function(){return n},getLength:function(t){return~~(i.length/2)},write:function(t){const e=i;let n=0;for(;n+1<e.length;){let r=(255&e[n])<<8|255&e[n+1];if(33088<=r&&r<=40956)r-=33088;else{if(!(57408<=r&&r<=60351))throw'illegal char at '+(n+1)+'/'+r;r-=49472}r=192*(r>>>8&255)+(255&r),t.put(r,13),n+=2}if(n<e.length)throw'illegal char at '+(n+1)}};return u},x=function(){const t=[],e={writeByte:function(e){t.push(255&e)},writeShort:function(t){e.writeByte(t),e.writeByte(t>>>8)},writeBytes:function(t,n,r){n=n||0,r=r||t.length;for(let o=0;o<r;o+=1)e.writeByte(t[o+n])},writeString:function(t){for(let n=0;n<t.length;n+=1)e.writeByte(t.charCodeAt(n))},toByteArray:function(){return t},toString:function(){let e='';e+='[';for(let n=0;n<t.length;n+=1)n>0&&(e+=','),e+=t[n];return e+=']',e}};return e},L=function(){let t=0,e=0,n=0,r='';const o={},i=function(t){r+=String.fromCharCode(u(63&t))},u=function(t){if(t<0)throw'n:'+t;if(t<26)return 65+t;if(t<52)return t-26+97;if(t<62)return t-52+48;if(62==t)return 43;if(63==t)return 47;throw'n:'+t};return o.writeByte=function(r){for(t=t<<8|255&r,e+=8,n+=1;e>=6;)i(t>>>e-6),e-=6},o.flush=function(){if(e>0&&(i(t<<6-e),t=0,e=0),n%3!=0){const t=3-n%3;for(let e=0;e<t;e+=1)r+='='}},o.toString=function(){return r},o},D=function(t){const e=t;let n=0,r=0,o=0;const i={read:function(){for(;o<8;){if(n>=e.length){if(0==o)return-1;throw'unexpected end of file./'+o}const t=e.charAt(n);if(n+=1,'='==t)return o=0,-1;t.match(/^\s$/)||(r=r<<6|u(t.charCodeAt(0)),o+=6)}const t=r>>>o-8&255;return o-=8,t}},u=function(t){if(65<=t&&t<=90)return t-65;if(97<=t&&t<=122)return t-97+26;if(48<=t&&t<=57)return t-48+52;if(43==t)return 62;if(47==t)return 63;throw'c:'+t};return i},S=function(t,e){const n=t,r=e,o=new Array(t*e),i={setPixel:function(t,e,r){o[e*n+t]=r},write:function(t){t.writeString('GIF87a'),t.writeShort(n),t.writeShort(r),t.writeByte(128),t.writeByte(0),t.writeByte(0),t.writeByte(0),t.writeByte(0),t.writeByte(0),t.writeByte(255),t.writeByte(255),t.writeByte(255),t.writeString(','),t.writeShort(0),t.writeShort(0),t.writeShort(n),t.writeShort(r),t.writeByte(0);const e=c(2);t.writeByte(2);let o=0;for(;e.length-o>255;)t.writeByte(255),t.writeBytes(e,o,255),o+=255;t.writeByte(e.length-o),t.writeBytes(e,o,e.length-o),t.writeByte(0),t.writeString(';')}},u=function(t){const e=t;let n=0,r=0;const o={write:function(t,o){if(t>>>o!=0)throw'length over';for(;n+o>=8;)e.writeByte(255&(t<<n|r)),o-=8-n,t>>>=8-n,r=0,n=0;r|=t<<n,n+=o},flush:function(){n>0&&e.writeByte(r)}};return o},c=function(t){const e=1<<t,n=1+(1<<t);let r=t+1;const i=l();for(let t=0;t<e;t+=1)i.add(String.fromCharCode(t));i.add(String.fromCharCode(e)),i.add(String.fromCharCode(n));const c=x(),f=u(c);f.write(e,r);let s=0,a=String.fromCharCode(o[s]);for(s+=1;s<o.length;){const t=String.fromCharCode(o[s]);s+=1,i.contains(a+t)?a+=t:(f.write(i.indexOf(a),r),i.size()<4095&&(i.size()==1<<r&&(r+=1),i.add(a+t)),a=t)}return f.write(i.indexOf(a),r),f.write(n,r),f.flush(),c.toByteArray()},l=function(){const t={};let e=0;const n={add:function(r){if(n.contains(r))throw'dup key:'+r;t[r]=e,e+=1},size:function(){return e},indexOf:function(e){return t[e]},contains:function(e){return void 0!==t[e]}};return n};return i},v=function(t,e,n){const r=S(t,e);for(let o=0;o<e;o+=1)for(let e=0;e<t;e+=1)r.setPixel(e,o,n(e,o));const o=x();r.write(o);const i=L(),u=o.toByteArray();for(let t=0;t<u.length;t+=1)i.writeByte(u[t]);return i.flush(),'data:image/gif;base64,'+i};var I=t;const P=t.stringToBytes},785,[]);
889
- __d(function(g,r,_i,a,m,_e,d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"darkMarkdownStyles",{enumerable:!0,get:function(){return W}}),Object.defineProperty(_e,"foreignMarkdownStyles",{enumerable:!0,get:function(){return O}}),Object.defineProperty(_e,"systemMarkdownStyles",{enumerable:!0,get:function(){return _}}),Object.defineProperty(_e,"MarkdownContent",{enumerable:!0,get:function(){return E}});var t=r(d[0]),n=e(r(d[1])),o=e(r(d[2]));r(d[3]),r(d[4]);e(r(d[5]));var l=r(d[6]),i=r(d[7]),s=r(d[8]),c=r(d[9]),f=r(d[10]),h=r(d[11]),u=r(d[12]),y=r(d[13]),k=r(d[14]),p=r(d[15]),b=r(d[16]),x=r(d[17]),j=r(d[18]),S=r(d[19]),C=r(d[20]),H=r(d[21]),w=r(d[22]),z=r(d[23]),M=r(d[24]),T=r(d[25]),I=r(d[26]);const L="monospace",v=/^[a-z][a-z0-9+.-]*:/i;function P(e){return{href:e,hrefAttrs:{target:"_blank",rel:"noopener noreferrer"}}}const W={root:{marginVertical:-2},text:{color:"#e0e0e0",fontSize:15,lineHeight:21},paragraph:{marginVertical:8,width:"100%"},strong:{color:"#f0f0f0",fontWeight:"600"},emphasis:{fontStyle:"italic"},link:{color:"#6cb6ff",textDecorationLine:"underline"},heading1:{color:"#f0f0f0",fontSize:26,lineHeight:32,fontWeight:"700",marginTop:16,marginBottom:8},heading2:{color:"#f0f0f0",fontSize:22,lineHeight:28,fontWeight:"700",marginTop:14,marginBottom:6},heading3:{color:"#f0f0f0",fontSize:19,lineHeight:25,fontWeight:"700",marginTop:12,marginBottom:4},heading4:{color:"#e8e8e8",fontSize:17,lineHeight:23,fontWeight:"600",marginTop:10,marginBottom:4},heading5:{color:"#e8e8e8",fontSize:16,lineHeight:22,fontWeight:"600",marginTop:8,marginBottom:2},heading6:{color:"#ccc",fontSize:15,lineHeight:21,fontWeight:"600",marginTop:6,marginBottom:2},inlineCode:{color:"#f8c555",backgroundColor:"#1a1a1a",fontFamily:L,fontSize:13},code:{backgroundColor:"#0d1117",color:"#e0e0e0",fontFamily:L,fontSize:13,padding:10},blockquote:{borderColor:"#555",borderLeftWidth:3,paddingHorizontal:10,marginVertical:2,backgroundColor:"transparent"},thematicBreak:{backgroundColor:"#444",marginVertical:6,height:1},list:{},listItem:{flexDirection:"row",alignItems:"flex-start",justifyContent:"flex-start",gap:6},listBullet:{color:"#e0e0e0",fontSize:15,lineHeight:21},listItemContent:{flex:1},listCheckbox:{width:13,height:13,marginTop:4,borderRadius:3,borderWidth:1,borderColor:"#8a8a8e",alignItems:"center",justifyContent:"center"},listCheckboxChecked:{backgroundColor:"#6cb6ff",borderColor:"#6cb6ff"},listCheckmark:{color:"#111",fontSize:10,lineHeight:11,fontWeight:"700"},table:{borderWidth:1,borderColor:"#555",borderRadius:4,marginVertical:4,overflow:"hidden"},tableRow:{flexDirection:"row",borderBottomWidth:1,borderColor:"#555"},tableRowHeader:{backgroundColor:"rgba(255,255,255,0.08)"},tableCell:{flex:1,paddingHorizontal:8,paddingVertical:4,borderRightWidth:1,borderColor:"#555"},tableCellText:{color:"#e0e0e0",fontSize:13},tableCellHeaderText:{color:"#f0f0f0",fontSize:13,fontWeight:"600"}},O=Object.assign({},W,{text:{color:"#d0d0d0",fontSize:15,lineHeight:21}}),_=Object.assign({},W,{text:{color:"#8a8a8e",fontSize:15,lineHeight:21}}),R=[(0,i.gfmTable)(),(0,c.gfmAutolinkLiteral)(),(0,h.gfmTaskListItem)(),(0,y.math)()],F=[(0,s.gfmTableFromMarkdown)(),(0,f.gfmAutolinkLiteralFromMarkdown)(),(0,u.gfmTaskListItemFromMarkdown)(),(0,k.mathFromMarkdown)()];function B(e){const t=e?.text?.fontSize,n=e?.text?.color,o=e?.text?.lineHeight;return{fontSize:"number"==typeof t?t:15,color:"string"==typeof n?n:"#e0e0e0",lineHeight:`${"number"==typeof o?o:21}px`}}const N={inlineMath:({node:e,styles:t})=>(0,I.jsx)("span",{className:"math math-inline",style:B(t),dangerouslySetInnerHTML:{__html:(0,H.renderMathHtml)(String(e.value??""),!1)}},e.key)};let V=!1;function A(){if(V||"undefined"==typeof document)return;V=!0;const e=document.createElement("style");e.id="brane-math-block",e.textContent=H.MATH_BLOCK_CSS,document.head.appendChild(e)}const D={table:({node:e,styles:t,children:n})=>(0,I.jsx)(o.default,{style:t.table,children:n},e.key),tableRow:({node:e,styles:t,children:n})=>(0,I.jsx)(o.default,{style:t.tableRow,children:n},e.key),tableCell:({node:e,styles:t,children:l,parentStack:i})=>{const s=i.length>=2&&"table"===i[1].type&&i[1].children?.[0]===i[0];return(0,I.jsx)(o.default,{style:t.tableCell,children:(0,I.jsx)(n.default,{style:s?t.tableCellHeaderText:t.tableCellText,children:l})},e.key)}},E=(0,t.memo)(function({content:e,foreign:i=!1,system:s=!1,onNarrativePress:c,onProtocolPress:f,onFilePress:h,fileHref:u,imageSrcResolver:y,knownNarrativeIds:k,knownProtocols:V}){const E=(0,z.useMarkdownLinks)(),$=c??E.onNarrativePress,K=f??E.onProtocolPress,q=k??E.knownNarrativeIds,G=V??E.knownProtocols;A();const U=(0,M.useHorizontalPanGuard)(),J=(0,t.useMemo)(()=>{const e=[...F];return q&&e.push((0,j.mentionLinks)(q)),q&&e.push((0,x.narrativeIdLinks)(q)),G&&e.push((0,C.protocolLinks)(G)),e},[q,G]),Q=(0,t.useMemo)(()=>(0,H.prepareMathMarkdown)(e),[e]),X=(0,t.useMemo)(()=>{const e=Object.assign({},D,N);return e.math=({node:e,styles:t})=>(0,I.jsx)("div",Object.assign({className:"math math-display",style:Object.assign({},B(t),{lineHeight:"normal"})},U,{dangerouslySetInnerHTML:{__html:(0,H.renderMathHtml)(String(e.value??""),!0)}}),e.key),e.code=({node:e,styles:t})=>{const n="string"==typeof e.lang?e.lang:null,o="string"==typeof e.value?e.value:"";return(0,I.jsx)("div",{style:{margin:"4px 0"},children:"mermaid"===n?(0,I.jsx)(b.DiagramView,{source:o}):(0,I.jsx)(p.HighlightedCode,{content:o,lang:n})},e.key)},e.listItem=({node:e,styles:t,children:l,extras:i,parentStack:s})=>{const c=e.checked,f=(0,S.listItemRowMarginTop)((0,S.listIsLoose)(s?.[0]),t.paragraph?.marginVertical??0);return(0,I.jsxs)(o.default,{style:f?[t.listItem,{marginTop:f}]:t.listItem,children:[null==c?i?.customListStyleType?i.customListStyleType:(0,I.jsx)(n.default,{style:t.listBullet,children:i?.listStyleType}):(0,I.jsx)(o.default,{style:[t.listCheckbox,c&&t.listCheckboxChecked],children:c?(0,I.jsx)(n.default,{style:t.listCheckmark,children:"\u2713"}):null}),(0,I.jsx)(o.default,{style:t.listItemContent,children:l})]},e.key)},e.paragraph=({node:e,styles:t,parentStack:o,children:l})=>{const i=o?.findIndex(e=>"listItem"===e.type)??-1,s=(0,S.listParagraphOverride)({inListItem:i>=0,firstBlock:i>=0&&o[i].children?.[0]===e,loose:i>=0&&(0,S.listIsLoose)(o[i+1])});return(0,I.jsx)(n.default,{style:s?[t.paragraph,s]:t.paragraph,children:l},e.key)},e.text=({node:e,styles:t,parentStack:o})=>{const l="string"==typeof e.value?e.value.replace(/\n/g," "):e.value,i=o?.find(e=>"heading"===e.type),s=i?t[`heading${i.depth}`]:t.text;return(0,I.jsx)(n.default,{style:s,maxFontSizeMultiplier:1.2,children:l},e.key)},e.link=({node:e,styles:t,children:o})=>{const l=e.url||"",i=l.match(/^brane:\/\/nid\/([^/]+)(?:\/(\d+))?$/)??l.match(new RegExp(`^${x.NID_REF_PATTERN}$`));if(i&&$){const l=i[1],s=i[2]?Number(i[2]):void 0,c=String(e.children?.[0]?.value??"").startsWith("@");return(0,I.jsx)(n.default,Object.assign({style:[t.link,{fontFamily:L,fontSize:13},c&&{fontWeight:"600"}]},(0,w.inAppLinkProps)((0,w.narrativeHref)(l,s),()=>$(l,s)),{children:o}),e.key)}const s=l.match(/^brane:\/\/protocol\/(.+)$/);if(s&&K){const l=decodeURIComponent(s[1]);return(0,I.jsx)(n.default,{style:[t.link,{fontFamily:L,fontSize:13}],onPress:()=>K(l),children:o},e.key)}return l.startsWith(T.FOLD_LINK_SCHEME)?(0,I.jsx)(n.default,{style:[t.text,{color:T.FOLD_COLOR,fontFamily:L,fontSize:13}],children:o},e.key):v.test(l)?l.startsWith("brane://")?(0,I.jsx)(n.default,{style:t.link,children:o},e.key):(0,I.jsx)(n.default,Object.assign({style:t.link},P(l),{children:o}),e.key):!l||l.startsWith("/")?(0,I.jsx)(n.default,{style:t.link,children:o},e.key):h?(0,I.jsx)(n.default,Object.assign({style:t.link},(0,w.inAppLinkProps)(u?.(l),()=>h(l)),{children:o}),e.key):(0,I.jsx)(n.default,{style:t.link,children:o},e.key)},y&&(e.image=({node:e,styles:t})=>{const o=e.url||"",l=y(o);return l?(0,I.jsx)("img",{src:l,alt:e.alt||"",style:{maxWidth:"100%",borderRadius:4,display:"block",margin:"4px 0"}},e.key):(0,I.jsx)(n.default,{style:t.text,children:e.alt||o},e.key)}),e},[$,K,h,u,y,U]);return(0,I.jsx)(l.Markdown,{markdown:Q,styles:s?_:i?O:W,mergeStyle:!1,syntaxExtensions:R,extensions:J,renderRules:X})})},786,[11,105,13,410,116,122,787,858,863,926,929,935,938,940,946,948,949,952,954,955,956,957,761,950,760,751,6]);
889
+ __d(function(g,r,_i,a,m,_e,d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"darkMarkdownStyles",{enumerable:!0,get:function(){return P}}),Object.defineProperty(_e,"foreignMarkdownStyles",{enumerable:!0,get:function(){return W}}),Object.defineProperty(_e,"systemMarkdownStyles",{enumerable:!0,get:function(){return _}}),Object.defineProperty(_e,"captionMarkdownStyles",{enumerable:!0,get:function(){return R}}),Object.defineProperty(_e,"MarkdownContent",{enumerable:!0,get:function(){return $}});var t=r(d[0]),n=e(r(d[1])),o=e(r(d[2]));r(d[3]),r(d[4]);e(r(d[5]));var i=r(d[6]),l=r(d[7]),s=r(d[8]),c=r(d[9]),f=r(d[10]),h=r(d[11]),u=r(d[12]),y=r(d[13]),k=r(d[14]),p=r(d[15]),b=r(d[16]),x=r(d[17]),j=r(d[18]),S=r(d[19]),C=r(d[20]),w=r(d[21]),H=r(d[22]),z=r(d[23]),M=r(d[24]),T=r(d[25]),I=r(d[26]);const L="monospace",v=/^[a-z][a-z0-9+.-]*:/i;function O(e){return{href:e,hrefAttrs:{target:"_blank",rel:"noopener noreferrer"}}}const P={root:{marginVertical:-2},text:{color:"#e0e0e0",fontSize:15,lineHeight:21},paragraph:{marginVertical:8,width:"100%"},strong:{color:"#f0f0f0",fontWeight:"600"},emphasis:{fontStyle:"italic"},link:{color:"#6cb6ff",textDecorationLine:"underline"},heading1:{color:"#f0f0f0",fontSize:26,lineHeight:32,fontWeight:"700",marginTop:16,marginBottom:8},heading2:{color:"#f0f0f0",fontSize:22,lineHeight:28,fontWeight:"700",marginTop:14,marginBottom:6},heading3:{color:"#f0f0f0",fontSize:19,lineHeight:25,fontWeight:"700",marginTop:12,marginBottom:4},heading4:{color:"#e8e8e8",fontSize:17,lineHeight:23,fontWeight:"600",marginTop:10,marginBottom:4},heading5:{color:"#e8e8e8",fontSize:16,lineHeight:22,fontWeight:"600",marginTop:8,marginBottom:2},heading6:{color:"#ccc",fontSize:15,lineHeight:21,fontWeight:"600",marginTop:6,marginBottom:2},inlineCode:{color:"#f8c555",backgroundColor:"#1a1a1a",fontFamily:L,fontSize:13},code:{backgroundColor:"#0d1117",color:"#e0e0e0",fontFamily:L,fontSize:13,padding:10},blockquote:{borderColor:"#555",borderLeftWidth:3,paddingHorizontal:10,marginVertical:2,backgroundColor:"transparent"},thematicBreak:{backgroundColor:"#444",marginVertical:6,height:1},list:{},listItem:{flexDirection:"row",alignItems:"flex-start",justifyContent:"flex-start",gap:6},listBullet:{color:"#e0e0e0",fontSize:15,lineHeight:21},listItemContent:{flex:1},listCheckbox:{width:13,height:13,marginTop:4,borderRadius:3,borderWidth:1,borderColor:"#8a8a8e",alignItems:"center",justifyContent:"center"},listCheckboxChecked:{backgroundColor:"#6cb6ff",borderColor:"#6cb6ff"},listCheckmark:{color:"#111",fontSize:10,lineHeight:11,fontWeight:"700"},table:{borderWidth:1,borderColor:"#555",borderRadius:4,marginVertical:4,overflow:"hidden"},tableRow:{flexDirection:"row",borderBottomWidth:1,borderColor:"#555"},tableRowHeader:{backgroundColor:"rgba(255,255,255,0.08)"},tableCell:{flex:1,paddingHorizontal:8,paddingVertical:4,borderRightWidth:1,borderColor:"#555"},tableCellText:{color:"#e0e0e0",fontSize:13},tableCellHeaderText:{color:"#f0f0f0",fontSize:13,fontWeight:"600"}},W=Object.assign({},P,{text:{color:"#d0d0d0",fontSize:15,lineHeight:21}}),_=Object.assign({},P,{text:{color:"#8a8a8e",fontSize:15,lineHeight:21}}),R=Object.assign({},P,{root:{},text:{color:"#666",fontSize:13,lineHeight:18},paragraph:{marginVertical:0,width:"100%",textAlign:"center"},strong:{color:"#888",fontWeight:"600"},inlineCode:Object.assign({},P.inlineCode,{fontSize:12})}),F=[(0,l.gfmTable)(),(0,c.gfmAutolinkLiteral)(),(0,h.gfmTaskListItem)(),(0,y.math)()],B=[(0,s.gfmTableFromMarkdown)(),(0,f.gfmAutolinkLiteralFromMarkdown)(),(0,u.gfmTaskListItemFromMarkdown)(),(0,k.mathFromMarkdown)()];function N(e){const t=e?.text?.fontSize,n=e?.text?.color,o=e?.text?.lineHeight;return{fontSize:"number"==typeof t?t:15,color:"string"==typeof n?n:"#e0e0e0",lineHeight:`${"number"==typeof o?o:21}px`}}const V={inlineMath:({node:e,styles:t})=>(0,I.jsx)("span",{className:"math math-inline",style:N(t),dangerouslySetInnerHTML:{__html:(0,w.renderMathHtml)(String(e.value??""),!1)}},e.key)};let A=!1;function D(){if(A||"undefined"==typeof document)return;A=!0;const e=document.createElement("style");e.id="brane-math-block",e.textContent=w.MATH_BLOCK_CSS,document.head.appendChild(e)}const E={table:({node:e,styles:t,children:n})=>(0,I.jsx)(o.default,{style:t.table,children:n},e.key),tableRow:({node:e,styles:t,children:n})=>(0,I.jsx)(o.default,{style:t.tableRow,children:n},e.key),tableCell:({node:e,styles:t,children:i,parentStack:l})=>{const s=l.length>=2&&"table"===l[1].type&&l[1].children?.[0]===l[0];return(0,I.jsx)(o.default,{style:t.tableCell,children:(0,I.jsx)(n.default,{style:s?t.tableCellHeaderText:t.tableCellText,children:i})},e.key)}},$=(0,t.memo)(function({content:e,foreign:l=!1,system:s=!1,caption:c=!1,onNarrativePress:f,onProtocolPress:h,onFilePress:u,fileHref:y,imageSrcResolver:k,knownNarrativeIds:A,knownProtocols:$}){const K=(0,z.useMarkdownLinks)(),q=f??K.onNarrativePress,G=h??K.onProtocolPress,U=A??K.knownNarrativeIds,J=$??K.knownProtocols;D();const Q=(0,M.useHorizontalPanGuard)(),X=(0,t.useMemo)(()=>{const e=[...B];return U&&e.push((0,j.mentionLinks)(U)),U&&e.push((0,x.narrativeIdLinks)(U)),J&&e.push((0,C.protocolLinks)(J)),e},[U,J]),Y=(0,t.useMemo)(()=>(0,w.prepareMathMarkdown)(e),[e]),Z=(0,t.useMemo)(()=>{const e=Object.assign({},E,V);return e.math=({node:e,styles:t})=>(0,I.jsx)("div",Object.assign({className:"math math-display",style:Object.assign({},N(t),{lineHeight:"normal"})},Q,{dangerouslySetInnerHTML:{__html:(0,w.renderMathHtml)(String(e.value??""),!0)}}),e.key),e.code=({node:e,styles:t})=>{const n="string"==typeof e.lang?e.lang:null,o="string"==typeof e.value?e.value:"";return(0,I.jsx)("div",{style:{margin:"4px 0"},children:"mermaid"===n?(0,I.jsx)(b.DiagramView,{source:o}):(0,I.jsx)(p.HighlightedCode,{content:o,lang:n})},e.key)},e.listItem=({node:e,styles:t,children:i,extras:l,parentStack:s})=>{const c=e.checked,f=(0,S.listItemRowMarginTop)((0,S.listIsLoose)(s?.[0]),t.paragraph?.marginVertical??0);return(0,I.jsxs)(o.default,{style:f?[t.listItem,{marginTop:f}]:t.listItem,children:[null==c?l?.customListStyleType?l.customListStyleType:(0,I.jsx)(n.default,{style:t.listBullet,children:l?.listStyleType}):(0,I.jsx)(o.default,{style:[t.listCheckbox,c&&t.listCheckboxChecked],children:c?(0,I.jsx)(n.default,{style:t.listCheckmark,children:"\u2713"}):null}),(0,I.jsx)(o.default,{style:t.listItemContent,children:i})]},e.key)},e.paragraph=({node:e,styles:t,parentStack:o,children:i})=>{const l=o?.findIndex(e=>"listItem"===e.type)??-1,s=(0,S.listParagraphOverride)({inListItem:l>=0,firstBlock:l>=0&&o[l].children?.[0]===e,loose:l>=0&&(0,S.listIsLoose)(o[l+1])});return(0,I.jsx)(n.default,{style:s?[t.paragraph,s]:t.paragraph,children:i},e.key)},e.text=({node:e,styles:t,parentStack:o})=>{const i="string"==typeof e.value?e.value.replace(/\n/g," "):e.value,l=o?.find(e=>"heading"===e.type),s=l?t[`heading${l.depth}`]:t.text;return(0,I.jsx)(n.default,{style:s,maxFontSizeMultiplier:1.2,children:i},e.key)},e.link=({node:e,styles:t,children:o})=>{const i=e.url||"",l=i.match(/^brane:\/\/nid\/([^/]+)(?:\/(\d+))?$/)??i.match(new RegExp(`^${x.NID_REF_PATTERN}$`));if(l&&q){const i=l[1],s=l[2]?Number(l[2]):void 0,c=String(e.children?.[0]?.value??"").startsWith("@");return(0,I.jsx)(n.default,Object.assign({style:[t.link,{fontFamily:L,fontSize:13},c&&{fontWeight:"600"}]},(0,H.inAppLinkProps)((0,H.narrativeHref)(i,s),()=>q(i,s)),{children:o}),e.key)}const s=i.match(/^brane:\/\/protocol\/(.+)$/);if(s&&G){const i=decodeURIComponent(s[1]);return(0,I.jsx)(n.default,{style:[t.link,{fontFamily:L,fontSize:13}],onPress:()=>G(i),children:o},e.key)}return i.startsWith(T.FOLD_LINK_SCHEME)?(0,I.jsx)(n.default,{style:[t.text,{color:T.FOLD_COLOR,fontFamily:L,fontSize:13}],children:o},e.key):v.test(i)?i.startsWith("brane://")?(0,I.jsx)(n.default,{style:t.link,children:o},e.key):(0,I.jsx)(n.default,Object.assign({style:t.link},O(i),{children:o}),e.key):!i||i.startsWith("/")?(0,I.jsx)(n.default,{style:t.link,children:o},e.key):u?(0,I.jsx)(n.default,Object.assign({style:t.link},(0,H.inAppLinkProps)(y?.(i),()=>u(i)),{children:o}),e.key):(0,I.jsx)(n.default,{style:t.link,children:o},e.key)},k&&(e.image=({node:e,styles:t})=>{const o=e.url||"",i=k(o);return i?(0,I.jsx)("img",{src:i,alt:e.alt||"",style:{maxWidth:"100%",borderRadius:4,display:"block",margin:"4px 0"}},e.key):(0,I.jsx)(n.default,{style:t.text,children:e.alt||o},e.key)}),e},[q,G,u,y,k,Q]);return(0,I.jsx)(i.Markdown,{markdown:Y,styles:c?R:s?_:l?W:P,mergeStyle:!1,syntaxExtensions:F,extensions:X,renderRules:Z})})},786,[11,105,13,410,116,122,787,858,863,926,929,935,938,940,946,948,949,952,954,955,956,957,761,950,760,752,6]);
890
890
  __d(function(g,r,i,a,m,_e,d){"use strict";Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"Markdown",{enumerable:!0,get:function(){return u.default}}),r(d[0]);var e,t=r(d[1]),u=(e=t)&&e.__esModule?e:{default:e}},787,[788,789]);
891
891
  __d(function(g,r,i,a,m,e,d){},788,[]);
892
892
  __d(function(g,r,i,a,m,_e,d){"use strict";Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return c}});var e,t=r(d[0]),n=r(d[1]),s=r(d[2]),l=(e=s)&&e.__esModule?e:{default:e},o=r(d[3]),u=r(d[4]);const y=(0,t.memo)(({markdown:e,debug:t,renderRules:s,listBulletStyle:y,styles:c,mergeStyle:f,customBulletElement:k,onLinkPress:_,extensions:b=[],syntaxExtensions:w=[]})=>{const x=(0,n.fromMarkdown)(e,{extensions:w,mdastExtensions:[(0,u.resolveReference)(),(0,o.getKeyFromMarkdown)(),...b]});return new l.default({renderRules:s,debug:t,styles:c,mergeStyle:f,listBulletStyle:y,customBulletElement:k,onLinkPress:_}).render(x)});y.displayName='Markdown';var c=y},789,[11,790,851,856,857]);
@@ -1081,19 +1081,20 @@ __d(function(g,r,i,_a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{
1081
1081
  __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.useAppHost=function(n,o){const u=n?.host??null,[c,p]=(0,t.useState)(()=>u?l.get(u)??null:null);return(0,t.useEffect)(()=>{if(!n||!u||!o)return void p(null);if(p(l.get(u)??null),l.has(u))return;let t=!1;return s(n).then(n=>{t||p(n)}).catch(()=>{t||p(null)}),()=>{t=!0}},[n,u,o]),c};var t=r(d[0]),n=r(d[1]),o=r(d[2]);const l=new Map,u=new Map;function s(t){const s=t.host,c=l.get(s);if(void 0!==c)return Promise.resolve(c);let p=u.get(s);return p||(p=(0,n.probeDaemon)(t.host,t.token).then(t=>{const n="string"==typeof t.app_domain&&(0,o.cleanAppHost)(t.app_domain)||null;return l.set(s,n),n}).finally(()=>u.delete(s)),u.set(s,p)),p}},978,[11,745,979]);
1082
1082
  __d(function(g,r,i,a,_m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.originHost=function(t){try{return new URL(t).host||t}catch{return t}},e.cleanAppHost=function(t){const n=t.trim(),o=/^[a-z][a-z0-9+.-]*:\/\/([^/?#]+)/i.exec(n);return(o?o[1]:n.replace(/[/?#].*$/,"")).toLowerCase()}},979,[]);
1083
1083
  __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.visiblePanes=function(t,c){return n.CANONICAL_TABS.filter(n=>n===t||c.has(n))},e.selectPane=function(n,t,c){const s=new Set(t);return s.add(n),{active:c,pinned:s}};var n=r(d[0])},980,[747]);
1084
- __d(function(g,r,_i,_a,_m,_e,_d){"use strict";const e=["index","style"];function t(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return le}});var n=t(r(_d[0])),o=r(_d[1]),a=t(r(_d[2])),i=t(r(_d[3])),l=t(r(_d[4])),s=t(r(_d[5])),d=t(r(_d[6])),c=t(r(_d[7])),u=t(r(_d[8])),f=t(r(_d[9])),h=t(r(_d[10])),m=r(_d[11]),p=r(_d[12]);r(_d[13]);var x=r(_d[14]),y=t(r(_d[15])),b=r(_d[16]),j=r(_d[17]),v=r(_d[18]),w=r(_d[19]),S=r(_d[20]),C=r(_d[21]),T=t(r(_d[22])),k=r(_d[23]),B=r(_d[24]),R=t(r(_d[25])),O=t(r(_d[26])),z=t(r(_d[27])),_=t(r(_d[28])),P=r(_d[29]),I=r(_d[30]),E=r(_d[31]),L=r(_d[32]),H=r(_d[33]),D=r(_d[34]),W=r(_d[35]);const A=400;function M(t){let{index:o,style:i}=t,l=(0,n.default)(t,e);return(0,W.jsx)(a.default,Object.assign({},l,{style:[i,{zIndex:1e5-o,position:"relative"}]}))}function N({item:e,conn:t,onPress:n,onArchive:l,onMeld:s,onTwin:d,onRevive:c,onEnd:f,menuVisible:h,setMenuVisible:m,hits:p,onHitPress:x,isolated:T,appHost:k}){const B="ended"===e.status?"dead":e.mcp_connected?"live":"idle",R="ended"===e.status?"#666":e.mcp_connected?"#66d9a0":"#5b9bd5",[,O]=(0,o.useState)(0),z=(0,L.isAwaiting)({mcpConnected:e.mcp_connected,awaiting:e.awaiting})?(0,L.awaitingGlow)((0,v.glowHueFor)(e.id)):void 0,_="ended"===e.status?"grey":e.mcp_connected?"green":"blue",I=(0,w.menuHueRgb)(_),E=[`0 0 8px rgba(${I}, 0.9)`,`0 0 18px rgba(${I}, 0.7)`,`0 0 36px rgba(${I}, 0.4)`,`0 1px 12px rgba(${I}, 0.6)`].join(", ");return(0,W.jsx)("div",{style:{borderBottomWidth:u.default.hairlineWidth,borderBottomColor:"#555",borderBottomStyle:"solid",backgroundColor:"#121214",cursor:"pointer",boxShadow:z,transition:"box-shadow 400ms ease"},onClick:()=>n(),children:(0,W.jsxs)("div",{style:{padding:16},children:[(0,W.jsxs)("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"},children:[(0,W.jsx)(S.NarrativeIdentity,{id:e.id,foldPath:e.fold_path,style:{flex:1,minWidth:0}}),(0,W.jsxs)("div",{style:{position:"relative"},children:[(0,W.jsx)("button",{onClick:e=>{e.stopPropagation(),m(!h)},style:{background:"none",border:"none",color:R,fontSize:12,textTransform:"uppercase",cursor:"pointer",padding:"4px 8px",marginRight:-9,borderRadius:4,transition:"text-shadow 160ms ease",textShadow:h?E:void 0},children:B}),h&&(0,W.jsx)(y.default,{hue:_,items:(0,b.narrativeMenuItems)({role:e.role,status:e.status,mcpConnected:e.mcp_connected,archived:!!e.archived,isIsolated:T,canIsolate:!T||!!k,onMeld:()=>{m(!1),s()},onIsolate:()=>{if(m(!1),!t||"undefined"==typeof window)return;const n=(0,P.buildIsolateUrl)({host:window.location.host,protocol:window.location.protocol,search:window.location.search,path:`/${e.id}`,conn:t,appHost:k,view:{}});n&&window.open(n,"_blank","noopener,noreferrer")},onExport:()=>{m(!1),t&&(0,b.openNarrativeExport)(t,e.id)},onRecolor:()=>{m(!1),(0,j.bumpRecolorSalt)(e.id),(0,v.recolorGlowHue)(e.id),O(e=>e+1)},onTwin:()=>{m(!1),d()},onRevive:()=>{m(!1),c()},onEnd:()=>{m(!1),f()},onArchiveToggle:()=>{m(!1),l()}}),onClose:()=>m(!1)})]})]}),(0,W.jsx)(S.NarrativeMetaLine,{role:e.role,cost:(0,C.formatCost)(e.cost_amount,e.cost_unit),createdAt:e.created_at,lastActivity:e.last_activity,status:e.status,mcpConnected:e.mcp_connected,style:{marginTop:4}}),e.summary&&(0,W.jsx)("div",{style:{position:"relative",marginTop:4},children:(0,W.jsx)("div",{className:"no-scrollbar",style:{overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",WebkitOverflowScrolling:"touch",maskImage:"linear-gradient(to right, #000 calc(100% - 40px), transparent)",WebkitMaskImage:"linear-gradient(to right, #000 calc(100% - 40px), transparent)"},children:(0,W.jsx)(i.default,{style:[se.summary,{marginTop:0,whiteSpace:"nowrap"}],children:e.summary})})}),p&&p.length>0&&(0,W.jsx)(a.default,{style:se.hitsContainer,children:p.slice(0,3).map((t,n)=>(0,W.jsx)("div",{onClick:n=>{n.stopPropagation(),x?.(e.id,t.seq)},style:{cursor:"pointer"},children:(0,W.jsx)(i.default,{style:se.hitSnippet,numberOfLines:2,children:t.content})},n))})]})})}function $(e){const t=e.split("\n");let n=0;for(;n<t.length&&(""===t[n].trim()||/^#{1,6}\s/.test(t[n].trim()));)n++;return(t.slice(n).join("\n").trim()||e.trim()).split(/\n[ \t]*\n+/).map(e=>e.replace(/\s*\n\s*/g," ").replace(/[ \t]{2,}/g," ").trim()).filter(Boolean).join("\n")}const F=new Set(["the","and","for","with","that","this","from","are","was","but","not","you"]);function V(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function q(e){return(e.toLowerCase().match(/[\p{L}\p{N}]+/gu)??[]).filter(e=>e.length>=2&&!F.has(e))}function G(e,t){const n=$(e),o=q(t),a=n.toLowerCase();let i=-1;for(const e of o){const t=a.indexOf(e);t>=0&&(i<0||t<i)&&(i=t)}let l=0;if(i>60){l=i-50;const e=n.indexOf(" ",l);e>=0&&e<l+15&&(l=e+1)}const s=Math.min(n.length,l+220);let d=n.slice(l,s);if(l>0&&(d=`\u2026${d}`),s<n.length&&(d=`${d}\u2026`),0===o.length)return[{text:d,match:!1}];const c=new RegExp(`(${o.map(V).sort((e,t)=>t.length-e.length).join("|")})`,"giu"),u=[];let f,h=0;for(;null!==(f=c.exec(d));)f.index>h&&u.push({text:d.slice(h,f.index),match:!1}),u.push({text:f[0],match:!0}),h=f.index+f[0].length,f.index===c.lastIndex&&c.lastIndex++;return h<d.length&&u.push({text:d.slice(h),match:!1}),u}function Y({icon:e,label:t,count:n,collapsed:o,onToggle:l,order:d,onToggleOrder:c}){return(0,W.jsxs)(a.default,{style:[se.wikiBar,o&&se.wikiBarCollapsed],children:[(0,W.jsx)(i.default,{style:se.wikiBarIcon,children:e}),(0,W.jsx)(i.default,{style:se.wikiBarLabel,numberOfLines:1,children:t}),(0,W.jsx)(i.default,{style:se.wikiBarCount,numberOfLines:1,children:n}),(0,W.jsx)(a.default,{style:{flex:1}}),d&&c&&!o&&(0,W.jsx)(s.default,{onPress:c,hitSlop:6,style:({pressed:e})=>[se.wikiBarPill,e&&se.wikiBarPillPressed],children:(0,W.jsx)(i.default,{style:se.wikiBarOrderLabel,children:"recent"===d?"Recency":"Relevance"})}),(0,W.jsx)(s.default,{onPress:l,hitSlop:6,style:({pressed:e})=>[se.wikiBarPill,e&&se.wikiBarPillPressed],children:(0,W.jsx)(i.default,{style:se.wikiBarToggle,children:o?"Show":"Hide"})})]})}function U({results:e,query:t,collapsed:n,onToggle:o,onOpen:l}){return 0===e.length?null:(0,W.jsxs)(a.default,{style:se.wikiSection,children:[(0,W.jsx)(Y,{icon:"\ud83d\udcd6",label:"Wiki",count:e.length,collapsed:n,onToggle:o}),!n&&e.map(e=>(0,W.jsxs)(a.default,{style:se.wikiCard,children:[(0,W.jsx)(s.default,{onPress:()=>l(e.source,e.slug,e.hits[0]?.anchor),children:(0,W.jsxs)(a.default,{style:se.wikiCardHeader,children:[(0,W.jsx)(i.default,{style:se.wikiSlug,numberOfLines:1,children:e.slug.replace(/\.md$/,"")}),(0,W.jsx)(i.default,{style:se.wikiSource,children:e.source})]})}),(0,W.jsx)(a.default,{style:se.hitsContainer,children:e.hits.slice(0,3).map((n,o)=>(0,W.jsxs)(s.default,{onPress:()=>l(e.source,e.slug,n.anchor),children:[!!n.anchor&&(0,W.jsxs)(i.default,{style:se.wikiHitCitation,children:["#",n.anchor]}),(0,W.jsx)(i.default,{style:se.hitSnippet,numberOfLines:3,children:G(n.content,t).map((e,t)=>e.match?(0,W.jsx)(i.default,{style:se.hitMatch,children:e.text},t):e.text)})]},o))})]},`${e.source}\0${e.slug}`))]})}function K(e){const t=new Map;for(const n of e)for(const e of n.cost??[]){const n=t.get(e.unit)??{unit:e.unit,amount:0,metered:0};n.amount+=e.amount,n.metered+=e.metered,t.set(e.unit,n)}return[...t.values()].sort((e,t)=>t.metered-e.metered)}const Q="\xa0";function X(e){if(!e?.length)return null;return e.map(e=>{return`${t=(0,C.formatCost)(e.amount,e.unit),(t??"").replace(/(\d) ([A-Za-z])/g,`$1${Q}$2`)}${Q}(${e.metered})`;var t}).join(" + ")}function Z({branes:e,activeBraneId:t,daemons:n,activeDaemon:l,connected:u,onSwitchBrane:m,onSwitchDaemon:p,onAdd:x,onRemove:y,onSignOutOthers:b,conn:j}){const[v,w]=(0,o.useState)(!1),[S,C]=(0,o.useState)(!1),[T,k]=(0,o.useState)(!1),[B,R]=(0,o.useState)(!1),[O,z]=(0,o.useState)(!1),[P,I]=(0,o.useState)(""),[E,L]=(0,o.useState)(""),[H,D]=(0,o.useState)(!1),[A,M]=(0,o.useState)(null),[N,$]=(0,o.useState)(null),[F,V]=(0,o.useState)(!1),q=()=>{w(!1),C(!1),k(!1),z(!1),$(null),V(!1)},G=()=>{B||(k(!1),$(null))},Y=()=>{H||(C(!1),M(null))},U=(0,o.useMemo)(()=>K(e),[e]),Q=t?e.find(e=>e.brane_id===t)?.is_home?`${t} (home)`:t:l?.id??"No daemon";return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(s.default,{style:se.daemonChip,onPress:()=>w(!0),children:[(0,W.jsx)(a.default,{style:[se.chipDot,{backgroundColor:u?"#66d9a0":"#e07070"}]}),(0,W.jsx)(i.default,{style:se.chipText,numberOfLines:1,children:Q}),(0,W.jsx)(i.default,{style:se.chipChevron,children:"\u25bc"})]}),(0,W.jsx)(d.default,{visible:v,transparent:!0,animationType:"fade",onRequestClose:q,children:(0,W.jsx)(s.default,{style:se.modalOverlay,onPress:q,children:(0,W.jsxs)(s.default,{style:se.modalContent,onPress:()=>{},children:[(0,W.jsx)(i.default,{style:se.modalTitle,children:"Branes"}),(0,W.jsxs)(c.default,{style:{flexGrow:0},children:[(0,W.jsx)(s.default,{style:[se.daemonOption,null===t&&se.daemonOptionActive],onPress:()=>{m(null),w(!1)},children:(0,W.jsxs)(a.default,{style:se.daemonOptionRow,children:[(0,W.jsx)(a.default,{style:[se.daemonDot,{backgroundColor:u?"#66d9a0":"#555"}]}),(0,W.jsxs)(a.default,{style:{flex:1},children:[(0,W.jsx)(i.default,{style:se.daemonName,children:"All branes"}),(0,W.jsx)(i.default,{style:se.daemonHost,children:l?.id}),X(U)&&(0,W.jsx)(i.default,{style:se.daemonCost,children:X(U)})]})]})}),e.map(e=>(0,W.jsx)(s.default,{style:[se.daemonOption,e.brane_id===t&&se.daemonOptionActive],onPress:()=>{m(e.brane_id),w(!1)},children:(0,W.jsxs)(a.default,{style:se.daemonOptionRow,children:[(0,W.jsx)(a.default,{style:[se.daemonDot,{backgroundColor:e.active_count>0?"#66d9a0":"#555"}]}),(0,W.jsxs)(a.default,{style:{flex:1},children:[(0,W.jsxs)(i.default,{style:se.daemonName,children:[e.brane_id,e.is_home?" (home)":""]}),(0,W.jsxs)(i.default,{style:se.daemonHost,children:[e.active_count," active, ",e.narrative_count," total",e.absorbed_count>0?` (${e.absorbed_count} absorbed)`:""]}),X(e.cost)&&(0,W.jsx)(i.default,{style:se.daemonCost,children:X(e.cost)})]})]})},e.brane_id)),0===e.length&&0===n.length&&(0,W.jsx)(i.default,{style:se.emptyDaemons,children:"No daemons configured"}),n.filter(e=>e.id!==l?.id).map(e=>(0,W.jsx)(s.default,{style:se.daemonOption,onPress:()=>{p(e.id),w(!1)},onLongPress:()=>y(e.id),children:(0,W.jsxs)(a.default,{style:se.daemonOptionRow,children:[(0,W.jsx)(a.default,{style:[se.daemonDot,{backgroundColor:"#555"}]}),(0,W.jsxs)(a.default,{style:{flex:1},children:[(0,W.jsx)(i.default,{style:se.daemonName,children:e.id}),(0,W.jsxs)(i.default,{style:se.daemonHost,children:[e.host," (switch daemon)"]})]})]})},e.id))]}),(0,W.jsx)(s.default,{style:se.addDaemonButton,onPress:()=>C(!0),children:(0,W.jsx)(i.default,{style:se.addDaemonButtonText,children:"+ Add Daemon"})}),l&&!l.revoked&&(0,W.jsx)(s.default,{style:se.addDaemonButton,onPress:()=>z(!0),disabled:!u,children:(0,W.jsx)(i.default,{style:[se.addDaemonButtonText,!u&&{opacity:.5}],children:"Devices"})}),(0,W.jsx)(s.default,{style:se.modalCancel,onPress:q,children:(0,W.jsx)(i.default,{style:se.modalCancelText,children:"Close"})})]})})}),(0,W.jsx)(d.default,{visible:v&&S,transparent:!0,animationType:"fade",onRequestClose:Y,children:(0,W.jsx)(s.default,{style:se.modalOverlay,onPress:Y,children:(0,W.jsxs)(s.default,{style:se.layerCard,onPress:e=>e.stopPropagation(),children:[(0,W.jsx)(i.default,{style:se.layerTitle,children:"Add a daemon"}),(0,W.jsxs)(a.default,{style:se.addForm,children:[(0,W.jsx)(h.default,{style:se.addInput,placeholder:"host:port",placeholderTextColor:"#666",value:P,onChangeText:I,autoCapitalize:"none",autoCorrect:!1,autoFocus:!0}),(0,W.jsx)(h.default,{style:se.addInput,placeholder:"token",placeholderTextColor:"#666",value:E,onChangeText:L,autoCapitalize:"none",autoCorrect:!1,secureTextEntry:!0}),A&&(0,W.jsx)(i.default,{style:se.addError,children:A}),(0,W.jsxs)(a.default,{style:se.layerButtonRow,children:[(0,W.jsx)(s.default,{style:[se.layerCancel,H&&{opacity:.5}],onPress:Y,disabled:H,children:(0,W.jsx)(i.default,{style:se.layerCancelText,children:"Cancel"})}),(0,W.jsx)(s.default,{style:[se.addButton,se.layerConfirm,(H||!P||!E)&&{opacity:.5}],onPress:async()=>{if(P&&E){D(!0),M(null);try{await x(P,E),C(!1),w(!1),I(""),L("")}catch(e){M(String(e))}finally{D(!1)}}},disabled:H||!P||!E,children:H?(0,W.jsx)(f.default,{size:"small",color:"#111"}):(0,W.jsx)(i.default,{style:se.addButtonText,children:"Connect"})})]})]})]})})}),(0,W.jsx)(_.default,{visible:v&&O,conn:j,daemonName:l?.id??"this daemon",onClose:()=>z(!1),onSignOutOthers:()=>k(!0),signedOutOthers:F,connected:u}),(0,W.jsx)(d.default,{visible:v&&T,transparent:!0,animationType:"fade",onRequestClose:G,children:(0,W.jsx)(s.default,{style:se.modalOverlay,onPress:G,children:(0,W.jsxs)(s.default,{style:se.layerCard,onPress:e=>e.stopPropagation(),children:[(0,W.jsx)(i.default,{style:se.layerTitle,children:"Sign out other devices?"}),(0,W.jsxs)(i.default,{style:se.signOutBody,children:[l?.id," will issue a new token. This device keeps its access; every other phone and browser paired with it is signed out until it scans a fresh Meld QR. Running agents and your shell are unaffected."]}),N&&(0,W.jsx)(i.default,{style:se.addError,children:N}),(0,W.jsxs)(a.default,{style:se.layerButtonRow,children:[(0,W.jsx)(s.default,{style:[se.layerCancel,B&&{opacity:.5}],onPress:G,disabled:B,children:(0,W.jsx)(i.default,{style:se.layerCancelText,children:"Cancel"})}),(0,W.jsx)(s.default,{style:[se.signOutButton,se.layerConfirm,B&&{opacity:.5}],onPress:async()=>{R(!0),$(null);try{await b(),V(!0),k(!1)}catch(e){$(String(e))}finally{R(!1)}},disabled:B,children:B?(0,W.jsx)(f.default,{size:"small",color:"#111"}):(0,W.jsx)(i.default,{style:se.addButtonText,children:"Sign out other devices"})})]})]})})})]})}const J=30,ee=.5,te=64,ne=96,oe=52,re=360;function ae(e){return-Math.min(e,ne)/ne*re}function ie({refreshing:e,onRefresh:t,scrollOffsetRef:n,children:a}){const i=(0,o.useRef)(null),[l,s]=(0,o.useState)(0),[d,c]=(0,o.useState)(!1),[u,f]=(0,B.useDetentSpin)(e),[h,m]=(0,o.useState)("none"),p=(0,o.useRef)(0),x=(0,o.useRef)(null),y=(0,o.useRef)(!1),b=(0,o.useCallback)(e=>{p.current=e,s(e)},[]);(0,o.useEffect)(()=>{const o=i.current;if(!o)return;const a=()=>(n.current??0)<=0,l=t=>{if(e||1!==t.touches.length||!a())return y.current=!1,void(x.current=null);x.current=t.touches[0].clientY,y.current=!0},s=t=>{if(!y.current||null===x.current||e)return;const n=t.touches[0].clientY-x.current;if(n<=0||!a())return a()||(y.current=!1),0!==p.current&&(b(0),f(0)),void c(!1);t.preventDefault();const o=Math.min(ne,n*ee);c(!0),m("none"),b(o),f(ae(o))},d=()=>{var n;y.current&&(y.current=!1,x.current=null,c(!1),p.current>=te&&!e?(f((n=ae(p.current),Math.round(n/B.RECYCLE_STEP)*B.RECYCLE_STEP)),b(oe),t()):(m("transform 0.4s ease"),f(0),b(0)))};return o.addEventListener("touchstart",l,{passive:!0}),o.addEventListener("touchmove",s,{passive:!1}),o.addEventListener("touchend",d,{passive:!0}),o.addEventListener("touchcancel",d,{passive:!0}),()=>{o.removeEventListener("touchstart",l),o.removeEventListener("touchmove",s),o.removeEventListener("touchend",d),o.removeEventListener("touchcancel",d)}},[e,t,n,b]),(0,o.useEffect)(()=>{if(!e)return 0!==p.current&&b(0),m("none"),void f(0);m("transform 0.18s ease")},[e,b,f]);const j=d?"none":"transform 0.25s ease";return(0,W.jsxs)("div",{ref:i,style:{flex:1,minHeight:0,position:"relative",overflow:"hidden",display:"flex",flexDirection:"column"},children:[(0,W.jsx)("div",{style:{position:"absolute",top:0,left:0,right:0,height:oe,display:"flex",alignItems:"center",justifyContent:"center",transform:`translateY(${l-oe}px)`,transition:j,pointerEvents:"none",zIndex:1},children:(0,W.jsx)(B.RecycleGlyph,{angle:u,transition:h,fontSize:26,opacity:e?1:Math.min(1,l/te)})}),(0,W.jsx)("div",{style:{flex:1,minHeight:0,display:"flex",flexDirection:"column",transform:`translateY(${l}px)`,transition:j},children:a})]})}function le(){const{conn:e,connected:t,daemons:n,activeDaemon:d,activeBraneId:c,switchDaemon:u,switchBrane:y,addDaemon:j,removeDaemon:v,rotateActiveToken:w,onStatus:S,onMeta:B,onActivity:_,subscribeActivity:$,unsubscribeActivity:F}=(0,x.useBrane)(),V="undefined"!=typeof window&&!!e&&(0,P.isIsolated)(window.location.host,e.host),q=(0,I.useAppHost)(e,V),[G,K]=(0,o.useState)([]),[Q,X]=(0,o.useState)([]),ee=(0,o.useRef)(null),[te,ne]=(0,o.useState)([]),[oe,re]=(0,o.useState)(!0),[ae,le]=(0,o.useState)(!1),[de,ce]=(0,o.useState)(!1),[ue,fe]=(0,o.useState)(null),[he,me]=(0,o.useState)(null),[pe,ge]=(0,o.useState)(null),[xe,ye]=(0,o.useState)(null),[be,je]=(0,o.useState)(J),[ve,we]=(0,o.useState)(!1),[Se,Ce]=(0,o.useState)(""),[Te,ke]=(0,o.useState)([]),[Be,Re]=(0,o.useState)(!1),[Oe,ze]=(0,o.useState)([]),[Pe,Ie]=(0,o.useState)(!1),[Ee,Le]=(0,o.useState)(!1),[He,De]=(0,o.useState)("relevance"),[We,Ae]=(0,o.useState)(null),Me=(0,o.useRef)(null),Ne=(0,o.useRef)(null),$e=(0,o.useRef)(null),Fe=(0,o.useRef)(0),Ve=(0,m.useRouter)(),qe=(0,p.useIsFocused)(),Ge=(0,o.useRef)(!1);Ge.current=qe;const Ye=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!qe)return;const e=e=>{if(!Ge.current)return;if(e.defaultPrevented||e.isComposing||!(0,H.isListScrollKey)(e))return;const t=$e.current?.getScrollableNode();if(!t)return;const n=e.target,o=n?.tagName;if("INPUT"===o||"TEXTAREA"===o||"SELECT"===o||n?.isContentEditable)return;if(n&&t.contains(n))return;if(document.querySelector('[aria-modal="true"]'))return;const a=performance.now(),i=Ye.current,l=i&&a-i.at<A?i.target:t.scrollTop,s=(0,H.listScrollTarget)(e.key,l,t);if(null===s)return;e.preventDefault(),Ye.current={target:s,at:a};const d=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;t.scroll({top:s,behavior:e.repeat||d?"auto":"smooth"})};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[qe]);const Ue=(0,o.useCallback)(async()=>{if(e){ye(null),je(J);try{const t=c?{archived:!0,braneIds:[c]}:void 0,[n,o,a]=await Promise.all([(0,C.fetchNarratives)(e,t),(0,C.fetchFolds)(e),(0,C.fetchBranes)(e).catch(()=>[])]);K((0,E.sortNarratives)(n)),ne(o),X(a),setTimeout(()=>{$e.current?.scrollToOffset({offset:0,animated:!1})},50)}catch(e){ye(String(e)),K([]),ne([]),X([])}finally{re(!1)}}},[e,c]),Ke=(0,o.useCallback)(async()=>{if(e&&!ae){le(!0);try{await Ue()}finally{le(!1)}}},[e,ae,Ue]);(0,o.useEffect)(()=>{if(e)K([]),ne([]),X([]),re(!0),Ue();else if(K([]),ne([]),X([]),re(!1),0===n.length){const e=setTimeout(()=>{ye(null),re(!1)},100);return()=>clearTimeout(e)}},[e,Ue,n.length]);const Qe=(0,o.useCallback)(()=>{e&&ce(!0)},[e]),Xe=(0,o.useCallback)(e=>{K(t=>[e,...t]),Ve.push("utility"===e.role?`/${e.id}?tab=terminal`:`/${e.id}`)},[Ve]),Ze=(0,o.useCallback)(async t=>{if(!e)return;if((0,b.revivesAsTwin)(t.role))return void ge(t);const n=t.id;try{const t=(await(0,C.reviveNarrative)(e,n)).nid??n;t!==n&&Ue(),Ve.push((0,P.terminalOnlyHref)(t))}catch(e){ye(String(e))}},[e,Ve,Ue]),Je=(0,o.useCallback)(t=>{e&&((0,D.interruptSession)(e,t),Ve.push((0,P.terminalOnlyHref)(t)))},[e,Ve]),et=(0,o.useCallback)(async(t,n)=>{if(!e)return;const o=!n;try{await(0,C.archiveNarrative)(e,t,o),K(o?e=>e.filter(e=>e.id!==t):e=>e.map(e=>e.id===t?Object.assign({},e,{archived:!1}):e))}catch(e){ye(String(e))}},[e]),tt=(0,o.useCallback)(async(e,t)=>{await j(e,t)},[j]);(0,o.useEffect)(()=>S((e,t)=>{K(n=>(0,E.sortNarratives)(n.map(n=>n.id!==e?n:"mcp_connected"===t?Object.assign({},n,{mcp_connected:!0}):"mcp_disconnected"===t?Object.assign({},n,{mcp_connected:!1,awaiting:!1}):t===L.AWAITING_STATUS?Object.assign({},n,{awaiting:!0}):t===L.NOT_AWAITING_STATUS?Object.assign({},n,{awaiting:!1}):Object.assign({},n,{status:t}))))}),[S]),(0,o.useEffect)(()=>B((t,n,o,a)=>{null!=a&&e&&(ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{ee.current=null,(0,C.fetchBranes)(e).then(X).catch(()=>{})},2e3)),K(e=>e.map(e=>{if(e.id!==t)return e;if(void 0===o&&null==a)return e;const n=Object.assign({},e);return void 0!==o&&(n.summary=o),null!=a&&(n.cost_amount=a.amount,n.cost_unit=a.unit),n}))}),[B,e]),(0,o.useEffect)(()=>{$();const e=_((e,t,n)=>{K(t=>{const o=t.findIndex(t=>t.id===e);if(o<0)return t;const a=t.slice();return a[o]=Object.assign({},a[o],{last_activity:n}),a})});return()=>{e(),F()}},[_,$,F]);const nt=!e&&0===n.length,[ot,rt]=(0,o.useState)([]);(0,o.useEffect)(()=>e&&Se.trim()?(Re(!0),Me.current&&clearTimeout(Me.current),Me.current=setTimeout(()=>{(0,C.searchNarratives)(e,Se.trim(),30,c?[c]:void 0).then(e=>{ke(e.results),rt(e.narratives||[]),Re(!1)}).catch(()=>{ke([]),rt([]),Re(!1)}),(0,C.searchWiki)(e,Se.trim(),10).then(e=>ze(e.results)).catch(()=>ze([]))},300),()=>{Me.current&&clearTimeout(Me.current)}):(ke([]),rt([]),ze([]),void Re(!1)),[e,Se,c]);const at=(0,o.useMemo)(()=>new Set(G.map(e=>e.id)),[G]),it=(0,o.useMemo)(()=>{const e=new Map;for(const t of Te){const n=e.get(t.narrative_id);n?n.push(t):e.set(t.narrative_id,[t])}return e},[Te]),lt=(0,o.useMemo)(()=>{if(!Se.trim())return G;const e=Se.toLowerCase(),t=new Set(G.filter(t=>t.id.toLowerCase().includes(e)||t.summary?.toLowerCase().includes(e)||t.agent_type?.toLowerCase().includes(e)||t.role?.toLowerCase().includes(e)||t.fold_path?.toLowerCase().includes(e)||it.has(t.id)).map(e=>e.id)),n=new Map(G.map(e=>[e.id,e])),o=new Map;for(const e of t)o.set(e,n.get(e));for(const e of ot)o.has(e.id)||o.set(e.id,e);return[...o.values()]},[G,Se,it,ot]),st=(0,o.useMemo)(()=>{const e=new Map;for(const t of Te){const n=e.get(t.narrative_id);(void 0===n||t.score>n)&&e.set(t.narrative_id,t.score)}return e},[Te]),dt=(0,o.useMemo)(()=>{if(Se.trim())return[...lt].sort((e,t)=>{if("recent"===He)return t.created_at-e.created_at;const n=st.get(e.id)??-1/0,o=st.get(t.id)??-1/0;return n!==o?o-n:t.created_at-e.created_at});const e=[],t=[];for(const n of lt)"ended"!==n.status||n.mcp_connected?e.push(n):t.push(n);return[...e,...t.slice(0,be)]},[lt,be,Se,He,st]);(0,o.useEffect)(()=>{ue&&!dt.some(e=>e.id===ue)&&fe(null)},[dt,ue]);const ct=(0,o.useMemo)(()=>lt.filter(e=>"ended"===e.status&&!e.mcp_connected).length,[lt]),ut=(0,o.useCallback)(()=>{je(e=>Math.min(e+J,ct))},[ct]);return(0,W.jsxs)(a.default,{style:se.container,children:[(0,W.jsx)(m.Stack.Screen,{options:{header:()=>(0,W.jsxs)(a.default,{style:se.customHeader,children:[(0,W.jsxs)(a.default,{style:se.headerTitleRow,children:[(0,W.jsx)(s.default,{onPress:Ue,children:(0,W.jsx)(i.default,{style:Object.assign({color:"#8fd4b4",fontSize:20,fontWeight:"700",letterSpacing:2},{textShadow:["0 0 7px rgba(143, 212, 180, 0.8)","0 0 20px rgba(143, 212, 180, 0.5)","0 0 40px rgba(100, 200, 160, 0.3)","0 2px 12px rgba(80, 180, 140, 0.6)"].join(", ")}),children:"BRANE"})}),(0,W.jsx)(s.default,{onPress:Qe,disabled:!e,style:[se.spawnButton,!e&&se.spawnButtonDisabled],children:(0,W.jsx)(i.default,{style:se.spawnButtonText,children:"Spawn"})}),(0,W.jsx)(Z,{branes:Q,activeBraneId:c,daemons:n,activeDaemon:d,connected:t,onSwitchBrane:y,onSwitchDaemon:u,onAdd:tt,onRemove:v,onSignOutOthers:w,conn:e}),(0,W.jsx)(s.default,{onPress:()=>{we(e=>(e?Ce(""):setTimeout(()=>Ne.current?.focus(),100),!e))},style:[se.searchButton,ve&&se.searchButtonActive],children:(0,W.jsx)(i.default,{style:[se.searchButtonText,ve&&se.searchButtonTextActive],children:"\ud83d\udd2c"})})]}),ve&&(0,W.jsx)(a.default,{style:se.searchBar,children:(0,W.jsx)(h.default,{ref:Ne,style:se.searchInput,placeholder:"Filter narratives...",placeholderTextColor:"#556",value:Se,onChangeText:Ce,autoFocus:!0,autoCapitalize:"none",autoCorrect:!1,returnKeyType:"search"})})]})}}),d?.revoked?(0,W.jsxs)(a.default,{style:se.center,children:[(0,W.jsxs)(i.default,{style:se.signedOutTitle,children:["Signed out of ",d.id]}),(0,W.jsx)(i.default,{style:se.emptySubtext,children:"Its token was rotated from another device, so the one stored here no longer works. Scan a fresh Meld QR \u2014 or run `brane meld` on that machine \u2014 to reconnect. Nothing else was touched."})]}):oe?(0,W.jsx)(a.default,{style:se.center,children:(0,W.jsx)(f.default,{size:"large",color:"#5b9bd5"})}):xe?(0,W.jsx)(a.default,{style:se.center,children:(0,W.jsx)(i.default,{style:se.errorText,children:xe})}):nt?(0,W.jsx)(O.default,{title:"No daemons configured",subtitle:"Tap the daemon selector above to add one"}):(0,W.jsx)(ie,{refreshing:ae,onRefresh:Ke,scrollOffsetRef:Fe,children:(0,W.jsx)(l.default,{ref:$e,style:{flex:1},data:Se.trim()&&Ee?[]:dt,keyExtractor:e=>e.id,CellRendererComponent:M,onScroll:e=>{Fe.current=e.nativeEvent.contentOffset.y},scrollEventThrottle:16,ListHeaderComponent:Se.trim()?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(U,{results:Oe,query:Se.trim(),collapsed:Pe,onToggle:()=>Ie(e=>!e),onOpen:(e,t,n)=>Ae({source:e,slug:t,anchor:n})}),(0,W.jsx)(a.default,{style:se.wikiSection,children:(0,W.jsx)(Y,{icon:"\ud83d\udcac",label:"Narratives",count:dt.length,collapsed:Ee,onToggle:()=>Le(e=>!e),order:He,onToggleOrder:()=>De(e=>"relevance"===e?"recent":"relevance")})})]}):null,renderItem:({item:t})=>(0,W.jsx)(N,{item:t,conn:e,onPress:()=>Ve.push(`/${t.id}`),onArchive:()=>et(t.id,!!t.archived),onMeld:()=>me(t),onTwin:()=>ge(t),onRevive:()=>Ze(t),onEnd:()=>Je(t.id),menuVisible:ue===t.id,setMenuVisible:e=>fe(e?t.id:null),hits:it.get(t.id),onHitPress:(e,t)=>Ve.push(`/${e}?scrollToSeq=${t}`),isolated:V,appHost:q}),onEndReached:!Se.trim()&&be<ct?ut:void 0,onEndReachedThreshold:.3,ListFooterComponent:dt.length>0&&!Se.trim()?(0,W.jsx)(O.default,{}):null,contentContainerStyle:0!==dt.length||Se.trim()?void 0:se.emptyFill,ListEmptyComponent:Se.trim()?Ee?null:(0,W.jsx)(a.default,{style:se.center,children:(0,W.jsx)(i.default,{style:se.emptyText,children:"No narratives match"})}):(0,W.jsx)(O.default,{title:"No narratives yet"})})}),(0,W.jsx)(R.default,{visible:de,conn:e,onClose:()=>{ce(!1),e&&(0,C.fetchFolds)(e).then(ne).catch(()=>{})},onSpawned:Xe}),(0,W.jsx)(z.default,{visible:null!==he,conn:e,path:`/${he?.id??""}`,onClose:()=>me(null)}),(0,W.jsx)(R.default,{visible:null!==pe,conn:e,re:pe?.id,defaultFoldPath:pe?.fold_path,onClose:()=>ge(null),onSpawned:Xe}),We&&e&&(0,W.jsx)(k.MarkdownLinksProvider,{knownNarrativeIds:at,onNarrativePress:(e,t)=>{Ae(null),Ve.push(null!=t?`/${e}?scrollToSeq=${t}`:`/${e}`)},children:(0,W.jsx)(T.default,{conn:e,target:We,onClose:()=>Ae(null)})})]})}const se=u.default.create({container:{flex:1},center:{flex:1,justifyContent:"center",alignItems:"center",padding:20},customHeader:{backgroundColor:"#1a1a1e",paddingTop:10,paddingHorizontal:16,paddingBottom:10,borderBottomWidth:u.default.hairlineWidth,borderBottomColor:"rgb(216, 216, 216)"},headerTitleRow:{flexDirection:"row",alignItems:"center",gap:12},daemonChip:{flexDirection:"row",alignItems:"center",backgroundColor:"#2a2a30",borderRadius:6,paddingHorizontal:10,paddingVertical:6,maxWidth:180},chipDot:{width:8,height:8,borderRadius:4,marginRight:8},chipText:{color:"#d8d8dd",fontSize:15,fontFamily:"monospace"},chipChevron:{color:"#888",fontSize:14,marginLeft:5},daemonOption:{paddingVertical:12,paddingHorizontal:12,borderRadius:8,backgroundColor:"#2a2a30",marginBottom:6},daemonOptionActive:{backgroundColor:"#1a3a2a",borderWidth:1,borderColor:"#3a6a4a"},daemonOptionRow:{flexDirection:"row",alignItems:"center"},daemonDot:{width:8,height:8,borderRadius:4,marginRight:10},daemonName:{color:"#d8d8dd",fontSize:15,fontFamily:"monospace"},daemonCost:{color:"#7bb894",fontSize:12,fontFamily:"monospace",marginTop:2},daemonHost:{color:"#777",fontSize:12,fontFamily:"monospace",marginTop:2},emptyDaemons:{color:"#666",fontSize:14,textAlign:"center",paddingVertical:16},addDaemonButton:{paddingVertical:14,alignItems:"center",borderRadius:8,backgroundColor:"#2a2a30",marginTop:8},addDaemonButtonText:{color:"#8fd4b4",fontSize:15,fontWeight:"600"},addForm:{marginTop:8,gap:8},addInput:{backgroundColor:"#222228",borderRadius:8,paddingHorizontal:12,paddingVertical:10,color:"#d8d8dd",fontSize:14,fontFamily:"monospace",borderWidth:1,borderColor:"#3a3a40"},addError:{color:"#e07070",fontSize:12},addButton:{backgroundColor:"#5b9bd5",borderRadius:8,paddingVertical:10,alignItems:"center"},addButtonText:{color:"#111",fontSize:14,fontWeight:"600"},signOutBody:{color:"#999",fontSize:13,lineHeight:18},layerCard:{backgroundColor:"#1e1e22",borderRadius:12,padding:20,width:"100%",maxWidth:360,borderWidth:1,borderColor:"#3a3a40"},layerTitle:{color:"#d8d8dd",fontSize:16,fontWeight:"600",marginBottom:10},layerButtonRow:{flexDirection:"row",gap:8,marginTop:4},layerCancel:{flex:1,backgroundColor:"#2a2a30",borderRadius:8,paddingVertical:10,alignItems:"center"},layerCancelText:{color:"#aaa",fontSize:14,fontWeight:"600"},layerConfirm:{flex:2},signOutButton:{backgroundColor:"#e0a070",borderRadius:8,paddingVertical:10,alignItems:"center"},signedOutTitle:{color:"#e0a070",fontSize:16,fontWeight:"600",marginBottom:8,textAlign:"center"},fieldLabel:{color:"#aaa",fontSize:12,fontWeight:"600",textTransform:"uppercase",letterSpacing:.5,marginTop:12,marginBottom:6},fieldStaticValue:{backgroundColor:"#222228",borderRadius:8,paddingHorizontal:12,paddingVertical:10,borderWidth:1,borderColor:"#2a2a30"},cardHeader:{flexDirection:"row",justifyContent:"space-between",alignItems:"center"},summary:{color:"#9a9aa0",fontSize:12,marginTop:4,lineHeight:12},status:{fontSize:12,textTransform:"uppercase"},hitsContainer:{marginTop:8,gap:4},hitSnippet:{color:"#b0a890",fontSize:12,lineHeight:17,paddingLeft:10,paddingVertical:3,borderLeftWidth:2,borderLeftColor:"rgba(255, 130, 180, 0.5)",backgroundColor:"rgba(255, 130, 180, 0.04)",borderRadius:2},wikiSection:{paddingHorizontal:14,paddingTop:12,paddingBottom:4},wikiBar:Object.assign({flexDirection:"row",alignItems:"center",gap:6,paddingVertical:11,paddingHorizontal:12,marginBottom:8,borderRadius:8,backgroundColor:"rgba(143, 212, 180, 0.12)",borderWidth:1,borderColor:"rgba(143, 212, 180, 0.35)"},{userSelect:"none"}),wikiBarCollapsed:{backgroundColor:"rgba(143, 212, 180, 0.06)",borderColor:"rgba(143, 212, 180, 0.22)"},wikiBarPillPressed:{backgroundColor:"rgba(143, 212, 180, 0.18)"},wikiBarPill:Object.assign({flexDirection:"row",alignItems:"center",gap:5,paddingVertical:3,paddingHorizontal:8,borderRadius:9,flexShrink:0,backgroundColor:"rgba(0, 0, 0, 0.32)",borderWidth:1,borderColor:"rgba(143, 212, 180, 0.35)"},{cursor:"pointer",userSelect:"none"}),wikiBarOrderLabel:{color:"#cdeede",fontSize:13,fontWeight:"400",letterSpacing:.5,textTransform:"uppercase"},wikiBarIcon:{fontSize:15},wikiBarLabel:{color:"#8fd4b4",fontSize:13,fontWeight:"700",letterSpacing:1,textTransform:"uppercase",flexShrink:1},wikiBarCount:{color:"#bfe6d3",fontSize:12,fontWeight:"700",fontFamily:"monospace",flexShrink:0},wikiBarToggle:{color:"#cdeede",fontSize:13,fontWeight:"400",textTransform:"uppercase",letterSpacing:.5},wikiCard:{backgroundColor:"#1e1e24",borderRadius:8,padding:12,marginBottom:8,borderWidth:u.default.hairlineWidth,borderColor:"rgba(143, 212, 180, 0.25)"},wikiCardHeader:{flexDirection:"row",alignItems:"center",gap:8},wikiSlug:{color:"#d8d8dd",fontSize:15,fontWeight:"600",fontFamily:"monospace",flex:1},wikiSource:{color:"#7a8a9a",fontSize:11,fontFamily:"monospace",backgroundColor:"#2a2a32",paddingHorizontal:6,paddingVertical:2,borderRadius:4,overflow:"hidden"},wikiHitCitation:{color:"#6c9bd5",fontSize:11,fontFamily:"monospace",paddingLeft:10,marginTop:4},hitMatch:{color:"#ffd9ec",fontWeight:"700",backgroundColor:"rgba(255, 130, 180, 0.22)"},emptyFill:{flexGrow:1},emptyText:{color:"#666",fontSize:16},emptySubtext:{color:"#555",fontSize:13,marginTop:8},errorText:{color:"#e07070",fontSize:14,textAlign:"center"},searchButton:{paddingLeft:16,paddingVertical:8,marginLeft:"auto",marginRight:-5},searchButtonActive:{},searchButtonText:{fontSize:20},searchButtonTextActive:Object.assign({},{textShadow:["0 0 10px rgba(255, 130, 180, 0.9)","0 0 25px rgba(255, 110, 165, 0.7)","0 0 50px rgba(255, 100, 155, 0.4)","0 2px 15px rgba(255, 120, 170, 0.6)"].join(", ")}),searchBar:{flexDirection:"row",alignItems:"center",marginTop:10},searchInput:Object.assign({flex:1,color:"#d8d8dd",fontSize:16,fontFamily:"monospace",backgroundColor:"#222228",borderRadius:8,paddingHorizontal:12,paddingVertical:6,borderWidth:1,borderColor:"rgba(255, 130, 180, 0.4)"},{outlineStyle:"none",boxShadow:["0 0 6px rgba(255, 130, 180, 0.5)","0 0 14px rgba(255, 110, 165, 0.35)","0 0 28px rgba(255, 100, 155, 0.2)"].join(", ")}),spawnButton:Object.assign({paddingHorizontal:12,paddingVertical:6,borderRadius:6,backgroundColor:"#5b9bd5",justifyContent:"center",alignItems:"center",marginLeft:0},{boxShadow:["0 0 6px rgba(91, 155, 213, 0.7)","0 0 16px rgba(91, 155, 213, 0.4)","0 2px 10px rgba(70, 130, 200, 0.5)"].join(", ")}),spawnButtonDisabled:{opacity:.4},spawnButtonText:{color:"#111",fontSize:14,fontWeight:"600"},modalOverlay:{flex:1,backgroundColor:"rgba(0,0,0,0.6)",justifyContent:"center",alignItems:"center",padding:24},modalContent:{backgroundColor:"#1e1e22",borderRadius:12,padding:20,width:"100%",maxWidth:400,maxHeight:"80%"},modalTitle:{color:"#d8d8dd",fontSize:18,fontWeight:"600",marginBottom:16},foldOption:{paddingVertical:14,paddingHorizontal:12,borderRadius:8,backgroundColor:"#2a2a30",marginBottom:8},foldOptionText:{color:"#d8d8dd",fontSize:15,fontFamily:"monospace"},modalCancel:{paddingVertical:12,alignItems:"center",marginTop:8},modalCancelText:{color:"#888",fontSize:15}})},981,[167,11,13,105,113,146,153,122,26,416,145,161,165,116,736,773,769,770,776,767,778,745,973,950,965,972,982,780,989,747,978,977,754,990,749,6]);
1085
- __d(function(g,r,i,a,m,_e,d){"use strict";const e=["title","subtitle"];function t(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return f}});var n=t(r(d[0]));r(d[1]);var l=t(r(d[2])),u=t(r(d[3])),c=t(r(d[4])),s=t(r(d[5])),o=r(d[6]);function f(t){let{title:l,subtitle:f}=t,x=(0,n.default)(t,e);return(0,o.jsxs)(c.default,{style:p.center,children:[(0,o.jsx)(s.default,Object.assign({},x)),l?(0,o.jsx)(u.default,{style:p.emptyText,children:l}):null,f?(0,o.jsx)(u.default,{style:p.emptySubtext,children:f}):null]})}const p=l.default.create({center:{flex:1,justifyContent:"center",alignItems:"center",padding:20,gap:4},emptyText:{color:"#666",fontSize:16,marginTop:20},emptySubtext:{color:"#555",fontSize:13,marginTop:4,textAlign:"center"}})},982,[167,11,26,105,13,983,6]);
1086
- __d(function(_g,_r,_i,_a,m,_e,d){"use strict";Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return E}});var e=_r(d[0]),t=_r(d[1]),n=_r(d[2]),o=_r(d[3]),i=_r(d[4]),r=_r(d[5]),a=_r(d[6]);const s="#121214",l=i.TERRAIN_ROWS+r.MAX_SPLOTCHES,c="\nattribute vec2 a_pos;\nvoid main() { gl_Position = vec4(a_pos, 0.0, 1.0); }\n",h=`\nprecision highp float;\nuniform vec2 u_res; // drawing buffer size, px\nuniform vec4 u_glyph; // x, y (top-left, px from top-left), w, h (w == h)\nuniform vec2 u_offset; // the noise window's integrated drift: x sway, y lift\nuniform float u_phase; // the noise's integrated time phase (churn)\nuniform sampler2D u_mask;\nuniform vec3 u_bg;\n// Two tables, as float textures read by index, so neither has a size a hand\n// will meet (claude-1cwe8u9p:61). Schemes (src/shared/membrane-palette.ts,\n// packScheme): one row each, the first TERRAIN_ROWS the terrain block\n// (src/shared/membrane-terrain.ts, blockRows / packCell, which adds the\n// cell's seed point as a last texel), the rest the groups'. Splotches\n// (src/shared/membrane-invasion.ts, packSplotches): one row each, oldest\n// first, naming the scheme row they paint in.\nuniform sampler2D u_schemes;\nuniform sampler2D u_splotchTable;\nuniform float u_splotchCount;\nuniform float u_clock; // seconds; animates the dithering of the fronts\nuniform vec2 u_drag; // accumulated drag, glyph widths: world = p - u_drag\nuniform vec2 u_cell0; // the block's centre cell (integer coordinates)\n\n// Classic 3D Perlin (gradient) noise; the third axis is time, so the field\n// evolves continuously and never cycles back on itself.\nvec3 grad3(vec3 p) {\n p = vec3(dot(p, vec3(127.1, 311.7, 74.7)),\n dot(p, vec3(269.5, 183.3, 246.1)),\n dot(p, vec3(113.5, 271.9, 124.6)));\n return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);\n}\nfloat perlin(vec3 p) {\n vec3 i = floor(p), f = fract(p);\n vec3 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n return mix(\n mix(mix(dot(grad3(i + vec3(0,0,0)), f - vec3(0,0,0)), dot(grad3(i + vec3(1,0,0)), f - vec3(1,0,0)), u.x),\n mix(dot(grad3(i + vec3(0,1,0)), f - vec3(0,1,0)), dot(grad3(i + vec3(1,1,0)), f - vec3(1,1,0)), u.x), u.y),\n mix(mix(dot(grad3(i + vec3(0,0,1)), f - vec3(0,0,1)), dot(grad3(i + vec3(1,0,1)), f - vec3(1,0,1)), u.x),\n mix(dot(grad3(i + vec3(0,1,1)), f - vec3(0,1,1)), dot(grad3(i + vec3(1,1,1)), f - vec3(1,1,1)), u.x), u.y),\n u.z);\n}\nfloat fbm(vec3 p) {\n float v = 0.0, a = 0.5;\n for (int i = 0; i < 5; i++) { v += a * perlin(p); p = p * 2.03 + vec3(1.7, 9.2, 3.1); a *= 0.5; }\n return 0.5 + 0.5 * (v * 1.4);\n}\n\n// OKLab \u2192 linear sRGB (Bj\xf6rn Ottosson), as in membrane-palette.ts.\nvec3 oklabToLinear(vec3 c) {\n float l_ = c.x + 0.3963377774 * c.y + 0.2158037573 * c.z;\n float m_ = c.x - 0.1055613458 * c.y - 0.0638541728 * c.z;\n float s_ = c.x - 0.0894841775 * c.y - 1.2914855480 * c.z;\n float l = l_ * l_ * l_, m = m_ * m_ * m_, s = s_ * s_ * s_;\n return vec3( 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s);\n}\nbool inGamut(vec3 lin) { return all(greaterThanEqual(lin, vec3(-1e-4))) && all(lessThanEqual(lin, vec3(1.0001))); }\n\nvec4 schemeTexel(float row, float col) {\n return texture2D(u_schemes, vec2((col + 0.5) / ${i.TERRAIN_TEXELS}.0, (row + 0.5) / ${l}.0));\n}\nvec2 anchorOf(float row, float k) {\n vec4 t = schemeTexel(row, 2.0 + floor(k * 0.5));\n return mod(k, 2.0) < 0.5 ? t.xy : t.zw;\n}\n// Lightness banding from its parameters (cycles, phase, mid, amplitude) \u2014\n// a scheme's own, or the terrain's blend of several.\nfloat bandingOf(vec4 l, float d) {\n return l.z + l.w * cos(6.28318 * (l.x * d + l.y));\n}\nfloat banding(float row, float d) {\n return bandingOf(schemeTexel(row, 1.0), d);\n}\n// A scheme's anchor color at position u through one pass of its anchors, as\n// an OKLab a/b offset. Each anchor holds, then turns into the next over a\n// window of half-width h.w \u2014 along a straight line through a/b, not around\n// the hue wheel, so the turn passes through no hue the two do not share\n// (abAt in membrane-palette.ts).\nvec2 anchorAt(float row, float u) {\n vec4 h = schemeTexel(row, 0.0); // count, passes per unit thickness, phase, half-width\n float x = fract(u) * h.x;\n float fi = floor(x);\n float f = smoothstep(0.5 - h.w, 0.5 + h.w, x - fi);\n vec2 a = anchorOf(row, fi), b = anchorOf(row, fi + 1.0);\n return mix(a.y * vec2(cos(a.x), sin(a.x)), b.y * vec2(cos(b.x), sin(b.x)), f);\n}\n// The same at thickness d, at the scheme's own cycling rate and phase.\nvec2 anchorAB(float row, float d) {\n vec4 h = schemeTexel(row, 0.0);\n return anchorAt(row, h.y * d + h.z);\n}\n\n// The scheme terrain: the base film's scheme is the cell it is over, in\n// world coordinates (glyph space carried by the drag, so the map scrolls with\n// the film and the lift never moves it). Cells are irregular: each grid cell\n// has a seed point jittered within it (its last texel), and a point wears\n// the nearest seed's scheme \u2014 a Voronoi partition, so no wall is axis-aligned\n// and no two are alike (claude-xaj5pb9b:16). The block's rows are the\n// BLOCK\xd7BLOCK cells around u_cell0, row-major; a point's nearest seeds are\n// in its own cell or the eight around it. Every cell whose seed is within\n// SEAM of the nearest gets a share, falling smoothly with the excess, so\n// nothing is discontinuous (a nearest-two blend jumped wherever the\n// runner-up changed \u2014 claude-xaj5pb9b:21); and the lookup position is\n// displaced by a static fbm, whose large octaves bend the walls and small\n// ones dither them. All of it in world coordinates and out of time, so the\n// map it draws is as fixed as the cells.\n//\n// What the shares blend is the *scheme*, not its colors (claude-xaj5pb9b:27):\n// the banding parameters into one cosine and the hue cycle into one\n// position, and the thickness is then rendered through that single local\n// scheme at full contrast. Averaging each cell's rendered banding instead\n// cancelled two cosines against each other and washed the texture out of\n// every seam (claude-xaj5pb9b:26). The anchors, which come in different\n// counts, are looked up per cell at the shared position and blended.\nfloat terrainRow(vec2 ij) {\n const float R = ${((i.BLOCK-1)/2).toFixed(1)};\n vec2 d = clamp(ij - u_cell0, -R, R);\n return (d.y + R) * ${i.BLOCK}.0 + (d.x + R);\n}\nfloat shareOf(float row, vec2 q, float d1) {\n float excess = distance(q, schemeTexel(row, ${o.SCHEME_TEXELS}.0).xy) - d1;\n return 1.0 - smoothstep(0.0, ${i.SEAM.toFixed(4)}, excess);\n}\nvoid terrain(vec2 p, float d, out float L, out vec2 ab) {\n vec2 w = p - u_drag;\n vec2 q = w + ${(2*i.WARP).toFixed(3)} * (vec2(fbm(vec3(w * ${i.WARP_FREQ.toFixed(3)} + 60.0, 7.0)),\n fbm(vec3(w * ${i.WARP_FREQ.toFixed(3)} + 90.0, 11.0))) - 0.5);\n vec2 c = floor(q / ${i.CELL.toFixed(4)});\n float d1 = 1e9;\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n d1 = min(d1, distance(q, schemeTexel(terrainRow(c + vec2(float(i), float(j))), ${o.SCHEME_TEXELS}.0).xy));\n }\n }\n // The local scheme: banding and hue-cycle parameters blended by share.\n float total = 0.0;\n vec4 light = vec4(0.0);\n vec2 cycle = vec2(0.0); // passes per unit thickness, phase\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n float row = terrainRow(c + vec2(float(i), float(j)));\n float share = shareOf(row, q, d1);\n if (share > 0.0) {\n light += share * schemeTexel(row, 1.0);\n cycle += share * schemeTexel(row, 0.0).yz;\n total += share;\n }\n }\n }\n light /= total;\n cycle /= total;\n L = bandingOf(light, d);\n // The anchors at the shared cycle position, blended by the same shares.\n float u = cycle.x * d + cycle.y;\n ab = vec2(0.0);\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n float row = terrainRow(c + vec2(float(i), float(j)));\n float share = shareOf(row, q, d1);\n if (share > 0.0) ab += share * anchorAt(row, u);\n }\n }\n ab /= total;\n}\n\nvec4 splotchTexel(float i, float col) {\n return texture2D(u_splotchTable, vec2((col + 0.5) / ${r.SPLOTCH_TEXELS}.0, (i + 0.5) / ${r.MAX_SPLOTCHES}.0));\n}\n// Signed distance-like measure to splotch i's outline, negative inside \u2014 the\n// same outline as sdAt in membrane-invasion.ts (upward reach multiplied by\n// its rise, then a stretch along its axis and 2-, 3- and 5-lobed bulges),\n// plus the shared noise dithering. row: its scheme.\nfloat splotchSD(float i, vec2 p, float dither, out float row) {\n vec4 a = splotchTexel(i, 0.0); // x, y, r, scheme row\n row = a.w;\n vec2 q = p - a.xy;\n if (a.z <= 0.0) return 10.0;\n float rise = splotchTexel(i, 3.0).x;\n if (q.y < 0.0) q.y /= rise; // y is down: upward, the outline reaches farther\n if (length(q) > a.z * 2.5 + 0.1) return 10.0; // nowhere near: skip the rest\n vec4 b = splotchTexel(i, 1.0); // angle, aspect, a2, a3\n vec4 c = splotchTexel(i, 2.0); // a5, p2, p3, p5\n float cs = cos(b.x), sn = sin(b.x);\n vec2 l = vec2(cs * q.x + sn * q.y, -sn * q.x + cs * q.y);\n float k = sqrt(b.y);\n float th = atan(l.y, l.x + 1e-6);\n float bulge = 1.0 + b.z * cos(2.0 * th + c.y) + b.w * cos(3.0 * th + c.z) + c.x * cos(5.0 * th + c.w);\n return length(vec2(l.x / k, l.y * k)) - a.z * bulge + dither * 0.16 * min(1.0, a.z * 5.0);\n}\nfloat dithering(vec2 p) { return fbm(vec3(p * 3.5 + 30.0, u_clock * 0.15)) - 0.5; }\n\n// Lightness is the thin film's banding; hue is the scheme's. The terrain,\n// then each splotch over it in order, newest on top. Chroma is cut\n// back only as far as sRGB needs at that lightness, so the palest and darkest\n// bands keep their hue instead of clipping to white or black.\nvec3 paint(float d, vec2 p, float dither) {\n float L;\n vec2 ab;\n terrain(p, d, L, ab);\n for (int i = 0; i < ${r.MAX_SPLOTCHES}; i++) {\n if (float(i) >= u_splotchCount) break;\n float row;\n float claim = 1.0 - smoothstep(-0.012, 0.012, splotchSD(float(i), p, dither, row));\n if (claim > 0.0) { L = mix(L, banding(row, d), claim); ab = mix(ab, anchorAB(row, d), claim); }\n }\n float C = length(ab);\n // The band no scheme may use (BAND_FADE_DEG, membrane-palette.ts): what a\n // turn between anchors on either side of it still passes through is shown\n // neutral, at the banding's lightness, rather than as mustard or olive.\n if (C > 1e-4) { // below that, hue is noise (and atan(0, 0) is undefined)\n float hd = mod(degrees(atan(ab.y, ab.x)), 360.0);\n float fade = smoothstep(${o.BAND_FADE_DEG[0].toFixed(1)}, ${o.BAND_FADE_DEG[1].toFixed(1)}, hd)\n * (1.0 - smoothstep(${o.BAND_FADE_DEG[2].toFixed(1)}, ${o.BAND_FADE_DEG[3].toFixed(1)}, hd));\n ab *= 1.0 - fade;\n C = length(ab);\n }\n vec2 dir = C > 1e-5 ? ab / C : vec2(1.0, 0.0);\n float lo = C;\n if (!inGamut(oklabToLinear(vec3(L, ab)))) {\n float hi = C; lo = 0.0;\n for (int k = 0; k < 8; k++) {\n float mid = 0.5 * (lo + hi);\n if (inGamut(oklabToLinear(vec3(L, dir * mid)))) lo = mid; else hi = mid;\n }\n }\n vec3 lin = clamp(oklabToLinear(vec3(L, dir * lo)), 0.0, 1.0);\n return mix(12.92 * lin, 1.055 * pow(lin, vec3(1.0 / 2.4)) - 0.055, step(0.0031308, lin));\n}\n\n// A slowly draining soap film: the swirl as merged in #464, carried by the\n// integrated drift (u_offset; lifting, the structure forms below and\n// dissolves above) and colored by the terrain and any splotches (paint).\nvec3 film(vec2 p, float c) {\n vec2 q = p * ${n.NOISE_SCALE.toFixed(2)} + u_offset;\n float d = fbm(vec3(q, c * 0.06));\n d += 0.35 * fbm(vec3(q * 2.7 + 10.0, c * 0.09 + 5.0));\n d += 0.30 * (p.y + 0.5); // thinner toward the top, as a real film drains\n // Where a splotch's front is, the film is disturbed: a thin seam of\n // shifted thickness marks the line being fought over. The edge itself is\n // crisp \u2014 the struggle is in its shape and its motion, not in a blur.\n //\n // The seam follows the nearest *visible* front, which is not the nearest\n // outline. Splotches composite oldest first, so walking them in order: one\n // that covers this point is the paint here and hides every older front\n // beneath it; an older front outside it stays a candidate; and a front is\n // no front where the paint on both sides is the same scheme \u2014 a sibling of\n // its own group already covers the point \u2014 so a group's union grows no\n // seams inside it (its inside distance is to the farthest covering\n // sibling's outline). A signed min over every outline got the one case\n // that matters most wrong: a tap landing inside an expanding wash sat deep\n // inside the wash's outline, and its own front, at distance zero, lost the\n // min to the wash's \u22120.3 and drew no seam until the wash was adopted, when\n // the seam appeared all at once (claude-m1ofa51d:16).\n float dither = 0.0, in2 = 100.0, out2 = 100.0, row;\n float over = -1.0; // scheme row of the paint at p; -1 is the terrain\n if (u_splotchCount > 0.5) {\n dither = dithering(p);\n for (int i = 0; i < ${r.MAX_SPLOTCHES}; i++) {\n if (float(i) >= u_splotchCount) break;\n float sd = splotchSD(float(i), p, dither, row);\n if (sd >= 10.0) continue; // nowhere near\n if (sd < 0.0) {\n if (over != row) { in2 = sd * sd; out2 = 100.0; } // new paint on top: older fronts are hidden\n else in2 = max(in2, sd * sd); // a sibling: the union reaches farther\n over = row;\n } else if (over != row) {\n out2 = min(out2, sd * sd);\n }\n }\n }\n d += 0.12 * exp(-min(in2, out2) / 0.0004);\n vec3 col = paint(d, p, dither);\n vec2 lightAt = vec2(-0.22, -0.28);\n float sheen = pow(max(0.0, 1.0 - length(p - lightAt) * 1.5), 2.2);\n col = mix(col, vec3(1.0), sheen * 0.30);\n col *= 0.88 + 0.12 * fbm(vec3(q * 3.0, c * 0.2 + 20.0));\n return col;\n}\n\nvoid main() {\n vec2 frag = vec2(gl_FragCoord.x, u_res.y - gl_FragCoord.y);\n vec2 gs = u_glyph.zw;\n vec2 gc = u_glyph.xy + gs * 0.5;\n vec2 muv = (frag - u_glyph.xy) / gs;\n float m = 0.0;\n if (muv.x >= 0.0 && muv.x <= 1.0 && muv.y >= 0.0 && muv.y <= 1.0) m = texture2D(u_mask, muv).a;\n if (m <= 0.001) { gl_FragColor = vec4(u_bg, 1.0); return; }\n // Glyph-normalized coordinates: the glyph spans -0.5..0.5.\n vec2 p = (frag - gc) / gs.x;\n gl_FragColor = vec4(mix(u_bg, film(p, u_phase), m), 1.0);\n}\n`,f=[60,90],u=.06;function p(e,n=64){const o=document.createElement("canvas");o.width=o.height=n;const i=o.getContext("2d");if(!i)return[[0,0]];i.setTransform(n/t.MO_GLYPH_BOX,0,0,n/t.MO_GLYPH_BOX,0,0),i.fillStyle="#fff",i.fill(e);const r=i.getImageData(0,0,n,n).data,a=[];for(let e=0;e<n;e++)for(let t=0;t<n;t++)r[4*(e*n+t)+3]>0&&a.push([(t+.5)/n-.5,(e+.5)/n-.5]);return a.length?a:[[0,0]]}let v=null;function g(e){const t=parseInt(e.slice(1),16);return[(t>>16&255)/255,(t>>8&255)/255,(255&t)/255]}function w(e,a,w){const E=e.getContext("webgl",{antialias:!1,alpha:!1,premultipliedAlpha:!1});if(!E)return null;const _=E;if(!_.getExtension("OES_texture_float"))return null;const b=(e,t)=>{const n=_.createShader(e);return n?(_.shaderSource(n,t),_.compileShader(n),_.getShaderParameter(n,_.COMPILE_STATUS)?n:(console.warn("Membrane shader:",_.getShaderInfoLog(n)),null)):null},x=b(_.VERTEX_SHADER,c),T=b(_.FRAGMENT_SHADER,h),y=_.createProgram();if(!x||!T||!y)return null;if(_.attachShader(y,x),_.attachShader(y,T),_.linkProgram(y),!_.getProgramParameter(y,_.LINK_STATUS))return console.warn("Membrane link:",_.getProgramInfoLog(y)),null;_.useProgram(y);const L=_.createBuffer();_.bindBuffer(_.ARRAY_BUFFER,L),_.bufferData(_.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),_.STATIC_DRAW);const R=_.getAttribLocation(y,"a_pos");_.enableVertexAttribArray(R),_.vertexAttribPointer(R,2,_.FLOAT,!1,0,0);const A=e=>_.getUniformLocation(y,e),S=A("u_res"),P=A("u_glyph"),k=A("u_offset"),M=A("u_phase"),C=A("u_clock"),D=A("u_splotchCount"),O=A("u_drag"),X=A("u_cell0");function I(e,t,n,o){const i=_.createTexture();_.activeTexture(_.TEXTURE0+e),_.bindTexture(_.TEXTURE_2D,i);for(const[e,t]of[[_.TEXTURE_WRAP_S,_.CLAMP_TO_EDGE],[_.TEXTURE_WRAP_T,_.CLAMP_TO_EDGE],[_.TEXTURE_MIN_FILTER,_.NEAREST],[_.TEXTURE_MAG_FILTER,_.NEAREST]])_.texParameteri(_.TEXTURE_2D,e,t);_.uniform1i(A(t),e);const r=new Float32Array(n*o*4);return{tex:i,data:r,upload(){_.activeTexture(_.TEXTURE0+e),_.bindTexture(_.TEXTURE_2D,i),_.texImage2D(_.TEXTURE_2D,0,_.RGBA,n,o,0,_.RGBA,_.FLOAT,r)}}}const F=I(1,"u_schemes",i.TERRAIN_TEXELS,l),B=I(2,"u_splotchTable",r.SPLOTCH_TEXELS,r.MAX_SPLOTCHES),U=()=>f[0]+(f[1]-f[0])*Math.random(),G=v??={terrain:(0,i.createTerrain)(Math.floor(2147483648*Math.random())),drag:[0,0],film:(0,r.emptyFilm)(),schemes:new Map,rows:new Map,motion:(0,n.initialMotionState)(w),t0:performance.now(),holdUntil:U(),frozenAt:0};function j(e,t){F.data.set((0,o.packScheme)(t),e*i.TERRAIN_TEXELS*4),F.upload()}function H(e){const t=new Set(G.rows.values());let n=i.TERRAIN_ROWS;for(;t.has(n);)n++;G.rows.set(e.id,n);const r=(0,o.nextScheme)((0,i.schemesInView)(G.terrain,G.drag),Math.random);G.schemes.set(e.id,r),j(n,r)}let N=null,z=!0;function q(){const e=(0,i.centreCell)(G.drag);!z&&N&&e[0]===N[0]&&e[1]===N[1]||((0,i.blockRows)(G.terrain,G.drag).forEach((e,t)=>F.data.set((0,i.packCell)(e),t*i.TERRAIN_TEXELS*4)),F.upload(),_.uniform2f(X,e[0],e[1]),N=e,z=!1)}function Y(e){(0,i.paintCells)(G.terrain,(0,i.cellsInView)(G.terrain,G.drag),e),z=!0}function $(){const e=new Set(G.film.groups.map(e=>e.id));for(const t of[...G.rows.keys()])e.has(t)||(G.rows.delete(t),G.schemes.delete(t))}const W=p(new Path2D(t.MO_GLYPH_PATH));for(const[e,t]of G.rows){const n=G.schemes.get(e);n&&j(t,n)}const K=(e,t)=>{const n=G.schemes.get(e.id),i=G.schemes.get(t.id);return!!n&&!!i&&(0,o.schemeDistance)(n,i)<u};function V(e,t){if(ce.matches)return void Y((0,o.nextScheme)((0,i.schemesInView)(G.terrain,G.drag),Math.random));const n=(0,r.tap)(G.film,e,t,Math.random);if(G.film=n.film,n.started&&H(n.started),n.recolored){const e=G.rows.get(n.recolored.id),t=G.schemes.get(n.recolored.id)??null;if(void 0!==e){const i=(0,o.nextScheme)(t,Math.random);G.schemes.set(n.recolored.id,i),j(e,i)}}$()}let Q=w;let J=!1;function Z(e){J=e}function ee(e,t){G.motion=(0,n.dragMotion)(G.motion,e,t),G.film=(0,r.shift)(G.film,e,t),G.drag=[G.drag[0]+e,G.drag[1]+t]}const[te,ne,oe]=g(s);_.uniform3f(A("u_bg"),te,ne,oe),_.uniform1i(A("u_mask"),0);const ie=_.createTexture();_.activeTexture(_.TEXTURE0),_.bindTexture(_.TEXTURE_2D,ie),_.texParameteri(_.TEXTURE_2D,_.TEXTURE_WRAP_S,_.CLAMP_TO_EDGE),_.texParameteri(_.TEXTURE_2D,_.TEXTURE_WRAP_T,_.CLAMP_TO_EDGE),_.texParameteri(_.TEXTURE_2D,_.TEXTURE_MIN_FILTER,_.LINEAR),_.texParameteri(_.TEXTURE_2D,_.TEXTURE_MAG_FILTER,_.LINEAR),_.pixelStorei(_.UNPACK_FLIP_Y_WEBGL,!1),_.pixelStorei(_.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);const re=document.createElement("canvas"),ae=new Path2D(t.MO_GLYPH_PATH);function se(e){const n=Math.max(2,Math.round(e));re.width=n,re.height=n;const o=re.getContext("2d");o&&(o.clearRect(0,0,n,n),o.setTransform(n/t.MO_GLYPH_BOX,0,0,n/t.MO_GLYPH_BOX,0,0),o.fillStyle="#fff",o.fill(ae),_.activeTexture(_.TEXTURE0),_.bindTexture(_.TEXTURE_2D,ie),_.texImage2D(_.TEXTURE_2D,0,_.RGBA,_.RGBA,_.UNSIGNED_BYTE,re))}function le(){const t=window.visualViewport?.scale??1,n=Math.min(5,(window.devicePixelRatio||1)*t),o=a.getBoundingClientRect(),i=Math.max(1,Math.round(o.width*n)),r=Math.max(1,Math.round(o.height*n));e.width===i&&e.height===r||(e.width=i,e.height=r),_.viewport(0,0,i,r),_.uniform2f(S,i,r);const s=Math.min(i,r);_.uniform4f(P,(i-s)/2,(r-s)/2,s,s),se(s)}const ce=window.matchMedia("(prefers-reduced-motion: reduce)");let he=0,de=0,fe=!1;function ue(e){if(de=0,!fe)return;const t=he?(e-he)/1e3:0;he=e;let o=(e-G.t0)/1e3;if(ce.matches)o=G.frozenAt;else{if(G.frozenAt=o,G.motion=(0,n.stepMotion)(G.motion,Q,t,J),(0,r.autoDue)(G.film,G.holdUntil,o)){const[e,t]=W[Math.floor(Math.random()*W.length)],n=(0,r.invade)(G.film,e,t,Math.random);n&&(G.film=n.film,H(n.started)),G.holdUntil=o+U()}G.film=(0,r.step)(G.film,t,K);const e=G.film.groups.find(e=>(0,r.washing)(e,G.film.clock)&&(0,r.covers)(G.film,e.id,W));if(e){const t=G.schemes.get(e.id);t&&Y(t),G.film=(0,r.adopt)(G.film,e.id),G.holdUntil=o+U()}$()}_.uniform2f(k,G.motion.offset[0],G.motion.offset[1]),_.uniform1f(M,G.motion.phase),_.uniform2f(O,G.drag[0],G.drag[1]),q(),B.data.set((0,r.packSplotches)(G.film,e=>G.rows.get(e)??0)),B.upload(),_.uniform1f(D,Math.min(G.film.splotches.length,r.MAX_SPLOTCHES)),_.uniform1f(C,G.film.clock),_.drawArrays(_.TRIANGLE_STRIP,0,4),de=requestAnimationFrame(ue)}function me(){fe=!1,de&&(cancelAnimationFrame(de),de=0)}let pe=!0;const ve=()=>{!document.hidden&&pe?fe||(fe=!0,he=0,de||(de=requestAnimationFrame(ue))):me()},ge=ve;document.addEventListener("visibilitychange",ge);const we="function"==typeof IntersectionObserver?new IntersectionObserver(e=>{pe=e.some(e=>e.isIntersecting),ve()},{threshold:0}):null;we?.observe(a);let Ee=null;const be=(e,t)=>{const n=a.getBoundingClientRect();return[(e-n.left)/n.width-.5,(t-n.top)/n.height-.5]},xe=()=>{if(Ee){Z(!1);try{a.releasePointerCapture(Ee.id)}catch{}Ee=null}},Te=e=>{if(!Ee&&e.isPrimary&&("mouse"!==e.pointerType||0===e.button)){Ee={id:e.pointerId,at:performance.now(),x:e.clientX,y:e.clientY,startX:e.clientX,startY:e.clientY,moved:!1},Z(!0);try{a.setPointerCapture(e.pointerId)}catch{}}},ye=e=>{if(!Ee||e.pointerId!==Ee.id)return;if("touch"!==e.pointerType&&0===e.buttons)return void xe();if(!Ee.moved){if(Math.hypot(e.clientX-Ee.startX,e.clientY-Ee.startY)<=8)return;Ee.moved=!0,Ee.x=Ee.startX,Ee.y=Ee.startY}const t=a.getBoundingClientRect();ee((e.clientX-Ee.x)/t.width,(e.clientY-Ee.y)/t.height),Ee.x=e.clientX,Ee.y=e.clientY},Le=e=>{if(!Ee||e.pointerId!==Ee.id)return;const t=!Ee.moved&&performance.now()-Ee.at<250;xe(),t&&V(...be(e.clientX,e.clientY))},Re=e=>{Ee&&e.pointerId===Ee.id&&xe()},Ae=()=>xe(),Se=()=>{document.hidden&&xe()},Pe=e=>{Ee&&e.preventDefault()},ke=e=>e.preventDefault();a.addEventListener("pointerdown",Te),a.addEventListener("pointermove",ye),a.addEventListener("pointerup",Le),a.addEventListener("pointercancel",Re),a.addEventListener("lostpointercapture",Re),window.addEventListener("pointerup",Le),window.addEventListener("pointercancel",Re),window.addEventListener("blur",Ae),document.addEventListener("visibilitychange",Se),a.addEventListener("touchmove",Pe,{passive:!1}),a.addEventListener("contextmenu",ke);let Me=0;const Ce=()=>{window.clearTimeout(Me),Me=window.setTimeout(le,60)},De=new ResizeObserver(Ce);return De.observe(a),window.visualViewport?.addEventListener("resize",Ce),le(),ve(),{touch:V,hold:Z,drag:ee,setMotion:function(e){Q=e},destroy(){me(),xe(),a.removeEventListener("pointerdown",Te),a.removeEventListener("pointermove",ye),a.removeEventListener("pointerup",Le),a.removeEventListener("pointercancel",Re),a.removeEventListener("lostpointercapture",Re),window.removeEventListener("pointerup",Le),window.removeEventListener("pointercancel",Re),window.removeEventListener("blur",Ae),document.removeEventListener("visibilitychange",Se),a.removeEventListener("touchmove",Pe),a.removeEventListener("contextmenu",ke),De.disconnect(),we?.disconnect(),window.visualViewport?.removeEventListener("resize",Ce),window.clearTimeout(Me),document.removeEventListener("visibilitychange",ge),_.deleteTexture(ie),_.deleteTexture(F.tex),_.deleteTexture(B.tex),_.deleteBuffer(L),_.deleteProgram(y),_.deleteShader(x),_.deleteShader(T),_.getExtension("WEBGL_lose_context")?.loseContext()}}}function E({voice:o,lift:i,sway:r,churn:l}){const c=(0,e.useRef)(null),h=(0,e.useRef)(null),f=(0,e.useRef)(null),[u,p]=(0,e.useState)(!0),v=(0,n.membraneMotion)(o,{lift:i,sway:r,churn:l}),g=(0,e.useRef)(v);g.current=v,(0,e.useEffect)(()=>{const e=c.current,t=h.current;if(!e||!t)return;let n=w(t,e,g.current);if(!n)return void p(!1);f.current=n;const o=e=>{e.preventDefault(),n?.destroy(),n=null,f.current=null},i=()=>{n=w(t,e,g.current),f.current=n};return t.addEventListener("webglcontextlost",o),t.addEventListener("webglcontextrestored",i),()=>{t.removeEventListener("webglcontextlost",o),t.removeEventListener("webglcontextrestored",i),n?.destroy(),f.current=null}},[]),(0,e.useEffect)(()=>{f.current?.setMotion(g.current)},[v.lift,v.sway,v.churn]);const E=(0,e.useCallback)(e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),f.current?.touch(0,0))},[]);return(0,a.jsx)("div",{ref:c,role:"button",tabIndex:0,"aria-label":"Change the colors",onKeyDown:E,style:{width:"min(60vw, 38vh, 360px)",aspectRatio:"1 / 1",maxWidth:"100%",position:"relative",cursor:"pointer",outline:"none",touchAction:"none",userSelect:"none",WebkitUserSelect:"none",WebkitTouchCallout:"none",WebkitTapHighlightColor:"transparent"},children:u?(0,a.jsx)("canvas",{ref:h,"aria-hidden":!0,style:{width:"100%",height:"100%",display:"block",background:s}}):(0,a.jsx)("svg",{viewBox:`0 0 ${t.MO_GLYPH_BOX} ${t.MO_GLYPH_BOX}`,width:"100%",height:"100%","aria-hidden":!0,children:(0,a.jsx)("path",{d:t.MO_GLYPH_PATH,fill:"#3a3a42"})})})}},983,[11,984,985,986,987,988,6]);
1087
- __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"MO_GLYPH_BOX",{enumerable:!0,get:function(){return L}}),Object.defineProperty(e,"MO_GLYPH_PATH",{enumerable:!0,get:function(){return Q}});const L=1e3,Q="M493.98 449.69L493.98 425.61L791.54 425.61L791.54 449.69L493.98 449.69ZM493.98 557.19L493.98 533.11L791.54 533.11L791.54 557.19L493.98 557.19ZM431.20 606.21L431.20 319.83L431.20 275.11L431.20 275.11L547.30 319.83L780.36 319.83L780.36 343.91L543.00 343.91L543.00 571.81Q543.00 576.11 528.81 584.71Q514.62 593.31 492.26 599.76Q469.90 606.21 446.68 606.21L446.68 606.21L431.20 606.21ZM733.92 583.85L733.92 319.83L726.18 319.83L776.92 266.51L878.40 343.05Q875.82 346.49 869.37 350.79Q862.92 355.09 851.74 357.67L851.74 357.67L851.74 552.03Q851.74 555.47 835.83 563.21Q819.92 570.95 797.56 577.40Q775.20 583.85 754.56 583.85L754.56 583.85L733.92 583.85ZM400.24 674.15L393.36 650.07L757.14 650.07L812.18 578.69Q812.18 578.69 829.38 592.02Q846.58 605.35 869.80 624.27Q893.02 643.19 911.08 660.39L911.08 660.39Q907.64 674.15 887.00 674.15L887.00 674.15L400.24 674.15ZM675.44 656.95L685.76 653.51Q694.36 680.17 723.17 703.82Q751.98 727.47 799.28 745.10Q846.58 762.73 911.94 773.05L911.94 773.05L911.94 783.37Q867.22 795.41 844.86 821.64Q822.50 847.87 820.78 904.63L820.78 904.63Q785.52 887.43 760.15 858.19Q734.78 828.95 717.58 793.69Q700.38 758.43 690.06 722.74Q679.74 687.05 675.44 656.95L675.44 656.95ZM132.78 417.01L132.78 148.69L132.78 140.09L132.78 104.83L259.20 148.69L242.86 148.69L242.86 417.01Q242.86 475.49 239.85 539.56Q236.84 603.63 223.94 668.56Q211.04 733.49 180.94 794.12Q150.84 854.75 96.66 906.35L96.66 906.35L87.20 901.19Q111.28 829.81 120.74 748.54Q130.20 667.27 131.49 582.13Q132.78 496.99 132.78 417.01L132.78 417.01ZM184.38 172.77L184.38 148.69L342.62 148.69L342.62 172.77L184.38 172.77ZM184.38 371.43L184.38 347.35L342.62 347.35L342.62 371.43L184.38 371.43ZM184.38 573.53L184.38 549.45L342.62 549.45L342.62 573.53L184.38 573.53ZM284.14 767.89L284.14 148.69L275.54 148.69L325.42 92.79L426.90 171.91Q423.46 176.21 415.72 180.94Q407.98 185.67 395.94 188.25L395.94 188.25L395.94 779.93Q395.94 817.77 387.77 844.43Q379.60 871.09 352.51 886.57Q325.42 902.05 269.52 907.21L269.52 907.21Q268.66 879.69 266.08 859.05Q263.50 838.41 256.62 827.23L256.62 827.23Q250.60 814.33 239.42 805.30Q228.24 796.27 205.02 791.97L205.02 791.97L205.02 779.93Q205.02 779.93 213.19 780.36Q221.36 780.79 232.54 781.65Q243.72 782.51 254.04 782.94Q264.36 783.37 269.52 783.37L269.52 783.37Q278.98 783.37 281.56 779.07Q284.14 774.77 284.14 767.89L284.14 767.89ZM499.14 291.45L499.14 99.67L639.32 110.85Q638.46 118.59 632.87 124.18Q627.28 129.77 610.94 132.35L610.94 132.35L610.94 265.65Q610.94 269.09 596.32 275.54Q581.70 281.99 560.20 286.72Q538.70 291.45 516.34 291.45L516.34 291.45L499.14 291.45ZM661.68 291.45L661.68 99.67L801.86 110.85Q801.00 118.59 795.41 124.18Q789.82 129.77 774.34 132.35L774.34 132.35L774.34 265.65Q774.34 269.09 759.72 275.54Q745.10 281.99 723.17 286.72Q701.24 291.45 678.88 291.45L678.88 291.45L661.68 291.45ZM407.98 219.21L401.10 195.13L797.56 195.13L838.84 133.21Q838.84 133.21 851.74 145.25Q864.64 157.29 882.27 174.06Q899.90 190.83 912.80 205.45L912.80 205.45Q910.22 219.21 890.44 219.21L890.44 219.21L407.98 219.21ZM573.10 533.11L573.10 533.11L695.22 533.11Q692.64 582.99 686.19 628.57Q679.74 674.15 662.54 714.57Q645.34 754.99 611.37 789.82Q577.40 824.65 521.07 853.89Q464.74 883.13 379.60 906.35L379.60 906.35L372.72 895.17Q447.54 858.19 488.39 817.77Q529.24 777.35 546.87 732.20Q564.50 687.05 568.37 637.60Q572.24 588.15 573.10 533.11Z"},984,[]);
1088
- __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"MEMBRANE_MOTION",{enumerable:!0,get:function(){return t}}),Object.defineProperty(e,"DEFAULT_MEMBRANE_VOICE",{enumerable:!0,get:function(){return n}}),e.membraneMotion=function(o=n,f={}){const u=t[o];return{lift:f.lift??u.lift,sway:f.sway??u.sway,churn:f.churn??u.churn}},Object.defineProperty(e,"MOTION_EASE_S",{enumerable:!0,get:function(){return o}}),Object.defineProperty(e,"MOTION_MAX_DT_S",{enumerable:!0,get:function(){return f}}),e.initialMotionState=function(t){return{motion:Object.assign({},t),offset:[0,0],phase:0}},Object.defineProperty(e,"NOISE_SCALE",{enumerable:!0,get:function(){return u}}),e.stepMotion=function(t,n,u,c=!1){const s=Math.min(Math.max(u,0),f),l=1-Math.exp(-s/o),M=(t,n)=>t+(n-t)*l,O={lift:c?0:M(t.motion.lift,n.lift),sway:c?0:M(t.motion.sway,n.sway),churn:M(t.motion.churn,n.churn)};return{motion:O,offset:[t.offset[0]+O.sway*s,t.offset[1]+O.lift*s],phase:t.phase+O.churn*s}},e.dragMotion=function(t,n,o){return Object.assign({},t,{offset:[t.offset[0]-u*n,t.offset[1]-u*o]})};const t={awake:{lift:.07,sway:.012,churn:1},dormant:{lift:0,sway:.012,churn:.4}},n="awake";const o=.35,f=.1;const u=2.4},985,[]);
1089
- __d(function(g,r,_i,_a,_m,e,_d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"MIN_ANCHORS",{enumerable:!0,get:function(){return t}}),Object.defineProperty(e,"MAX_ANCHORS",{enumerable:!0,get:function(){return n}}),Object.defineProperty(e,"MIN_HUE_SEP_DEG",{enumerable:!0,get:function(){return o}}),Object.defineProperty(e,"MIN_ANCHOR_DE",{enumerable:!0,get:function(){return u}}),Object.defineProperty(e,"DISTINCT_AT_L",{enumerable:!0,get:function(){return c}}),Object.defineProperty(e,"MIN_SCHEME_DISTANCE",{enumerable:!0,get:function(){return a}}),Object.defineProperty(e,"EXCLUDED_HUE_DEG",{enumerable:!0,get:function(){return h}}),Object.defineProperty(e,"BAND_FADE_DEG",{enumerable:!0,get:function(){return s}}),e.hueExcluded=i,e.bandFade=f,e.neutralizeBand=l,e.oklabToLinearSrgb=m,e.inSrgbGamut=M,e.fitToGamut=b,e.hueSeparationDeg=d,e.anchorsDistinct=E,Object.defineProperty(e,"SCHEME_FAMILIES",{enumerable:!0,get:function(){return O}}),e.sampleScheme=D,e.abAt=j,e.hueChromaAt=I,e.schemeDistance=C,e.nextScheme=function(t,n){const o=null===t?[]:Array.isArray(t)?t:[t];for(let t=0;t<200;t++){const t=D(n);if(o.every(n=>C(t,n)>=a))return t}return D(n)},Object.defineProperty(e,"SCHEME_TEXELS",{enumerable:!0,get:function(){return N}}),e.packScheme=function(t){const n=new Float32Array(20);return n.set([t.hues.length,...t.hue,...t.light]),n.set(H(t),8),n},e.packAnchors=H;const t=3,n=5,o=28,u=.09,c=[.5,.65,.8],a=.12,h=[60,130],s=[60,75,115,130];function i(t){return t>=h[0]&&t<=h[1]}function f(t){const[n,o,u,c]=s;return p(n,o,t)*(1-p(u,c,t))}function l(t,n){const o=1-f((180*Math.atan2(n,t)/Math.PI+360)%360);return[t*o,n*o]}function m(t,n,o){const u=t+.3963377774*n+.2158037573*o,c=t-.1055613458*n-.0638541728*o,a=t-.0894841775*n-1.291485548*o,h=u*u*u,s=c*c*c,i=a*a*a;return[4.0767416621*h-3.3077115913*s+.2309699292*i,-1.2684380046*h+2.6097574011*s-.3413193965*i,-.0041960863*h-.7034186147*s+1.707614701*i]}function M(t,n,o){return m(t,n,o).every(t=>t>=-1e-4&&t<=1.0001)}function b(t,n,o){const u=n=>[t,n*Math.cos(o),n*Math.sin(o)];if(M(...u(n)))return u(n);let c=0,a=n;for(let t=0;t<20;t++){const t=(c+a)/2;M(...u(t))?c=t:a=t}return u(c)}const y=Math.PI/180,p=(t,n,o)=>{const u=Math.min(1,Math.max(0,(o-t)/(n-t)));return u*u*(3-2*u)};function d(t,n){const o=Math.abs(((t-n)%360+360)%360);return Math.min(o,360-o)}function E(t){for(let n=0;n<t.length;n++)for(let a=n+1;a<t.length;a++){if(d(t[n],t[a])<o)return!1;for(const o of c){const[,c,h]=b(o,.3,t[n]*y),[,s,i]=b(o,.3,t[a]*y);if(Math.hypot(c-s,h-i)<u)return!1}}return!0}const _=(t,n,o)=>n+(o-n)*t(),A=(t,n)=>n[Math.floor(t()*n.length)],S={analogous:(t,n)=>{const o=A(n,[3,4]),u=_(n,30,45);return Array.from({length:o},(n,c)=>t+u*(c-(o-1)/2))},complementary:(t,n)=>{const o=_(n,35,60);return A(n,[[t,t+180,t+o],[t,t+180,t+180+o],[t,t+o,t+180,t+180+o]])},split:(t,n)=>{const o=_(n,25,45);return[t,t+180-o,t+180+o]},triadic:t=>[t,t+120,t+240],tetradic:(t,n)=>{const o=A(n,[60,90]);return[t,t+o,t+180,t+180+o]},accent:(t,n)=>{const o=_(n,30,45);return[t,t+o,t+A(n,[150,180,210])+o/2]},wild:(t,n)=>Array.from({length:A(n,[3,4,5])},()=>_(n,0,360))},O=Object.keys(S);function P(t,n){for(let o=t.length-1;o>0;o--){const u=Math.floor(n()*(o+1));[t[o],t[u]]=[t[u],t[o]]}return t}function D(o){let u,c;do{u=A(o,O),c=S[u](_(o,0,360),o).map(t=>((t+_(o,-8,8))%360+360)%360)}while(c.length<t||c.length>n||c.some(i)||!E(c));const a=P(c,o).map(t=>t*y);return{family:u,hues:a,chromas:a.map(()=>_(o,.15,.32)),light:[_(o,2.4,3.7),o(),_(o,.62,.68),_(o,.27,.32)],hue:[_(o,1,1.5),o(),_(o,.18,.45)]}}function j(t,n,o=t.hue[2]){const u=t.hues.length,c=(n%1+1)%1*u,a=Math.floor(c)%u,h=(a+1)%u,s=p(.5-o,.5+o,c-Math.floor(c)),i=t.chromas[a]*Math.cos(t.hues[a]),f=t.chromas[a]*Math.sin(t.hues[a]);return l(i+(t.chromas[h]*Math.cos(t.hues[h])-i)*s,f+(t.chromas[h]*Math.sin(t.hues[h])-f)*s)}function I(t,n,o=t.hue[2]){const[u,c]=j(t,n,o);return[Math.atan2(c,u),Math.hypot(u,c)]}function C(t,n){let o=0;for(let u=0;u<32;u++){const[c,a]=I(t,u/32,.5),[h,s]=I(n,u/32,.5);o+=Math.hypot(a*Math.cos(c)-s*Math.cos(h),a*Math.sin(c)-s*Math.sin(h))}return o/32}const N=5;function H(t){const o=new Float32Array(12);for(let u=0;u<=n;u++){const n=u%t.hues.length;o[2*u]=t.hues[n],o[2*u+1]=t.chromas[n]}return o}},986,[]);
1090
- __d(function(g,_r,_i,_a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"CELL",{enumerable:!0,get:function(){return n}}),Object.defineProperty(e,"JITTER",{enumerable:!0,get:function(){return r}}),Object.defineProperty(e,"SEAM",{enumerable:!0,get:function(){return c}}),Object.defineProperty(e,"WARP",{enumerable:!0,get:function(){return o}}),Object.defineProperty(e,"WARP_FREQ",{enumerable:!0,get:function(){return u}}),Object.defineProperty(e,"BLOCK",{enumerable:!0,get:function(){return l}}),Object.defineProperty(e,"TERRAIN_ROWS",{enumerable:!0,get:function(){return i}}),Object.defineProperty(e,"TERRAIN_TEXELS",{enumerable:!0,get:function(){return s}}),Object.defineProperty(e,"VIEW_MARGIN",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"createTerrain",{enumerable:!0,get:function(){return a}}),e.seededRng=b,e.cellRng=p,Object.defineProperty(e,"cellAt",{enumerable:!0,get:function(){return M}}),Object.defineProperty(e,"toWorld",{enumerable:!0,get:function(){return E}}),e.centreCell=y,e.cell=P,Object.defineProperty(e,"cellScheme",{enumerable:!0,get:function(){return j}}),e.blend=R,e.blockCells=S,e.blockRows=function(t,n){return S(y(n)).map(([n,r])=>P(t,n,r))},e.cellsInView=C,e.schemesInView=function(t,n){return C(t,n).map(([n,r])=>j(t,n,r))},e.paintCells=function(t,n,r){for(const[c,o]of n)t.cells.set(h(c,o),{seed:P(t,c,o).seed,scheme:r})},e.packCell=function(n){const r=new Float32Array(4*s);return r.set((0,t.packScheme)(n.scheme)),r.set([n.seed[0],n.seed[1],0,0],4*t.SCHEME_TEXELS),r};var t=_r(d[0]);const n=.75,r=.35,c=.25,o=.14,u=1.5,l=5,i=25,s=t.SCHEME_TEXELS+1,f=.21000000000000002,a=t=>({seed:t,cells:new Map}),h=(t,n)=>`${t},${n}`;function b(t){let n=0|t;return()=>{n=n+1831565813|0;let t=Math.imul(n^n>>>15,1|n);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}function p(t,n,r){let c=(0|t)^Math.imul(0|n,2654435761)^Math.imul(0|r,2246822519);return c=Math.imul(c^c>>>16,2146121005),c=Math.imul(c^c>>>15,2221713035),b(c^c>>>16)}const M=t=>Math.floor(t/n),E=(t,n)=>t-n;function y(t){return[M(E(0,t[0])),M(E(0,t[1]))]}const O=[[-1,-1],[0,-1],[1,-1],[-1,0],[1,0],[-1,1],[0,1],[1,1]];function P(c,o,u){const l=h(o,u),i=c.cells.get(l);if(i)return i;const s=p(c.seed,o,u),f=[(o+.5+(2*s()-1)*r)*n,(u+.5+(2*s()-1)*r)*n],a=O.map(([t,n])=>c.cells.get(h(o+t,u+n))?.scheme).filter(t=>!!t),b={seed:f,scheme:(0,t.nextScheme)(a,s)};return c.cells.set(l,b),b}const j=(t,n,r)=>P(t,n,r).scheme,w=t=>{const n=Math.min(1,Math.max(0,t/c));return 1-n*n*(3-2*n)};function R(t,n){const r=M(n[0]),c=M(n[1]),o=[];for(let u=-1;u<=1;u++)for(let l=-1;l<=1;l++){const i=P(t,r+l,c+u).seed;o.push({cell:[r+l,c+u],d:Math.hypot(n[0]-i[0],n[1]-i[1])})}const u=Math.min(...o.map(t=>t.d)),l=o.map(t=>({cell:t.cell,weight:w(t.d-u)})).filter(t=>t.weight>0),i=l.reduce((t,n)=>t+n.weight,0);return l.map(t=>({cell:t.cell,weight:t.weight/i})).sort((t,n)=>n.weight-t.weight)}function S(t){const n=[];for(let r=-2;r<=2;r++)for(let c=-2;c<=2;c++)n.push([t[0]+c,t[1]+r]);return n}const _=32;function A(t){const n=[];for(let r=0;r<=_;r++)for(let c=0;c<=_;c++)n.push([E(1.42*c/_-.71,t[0]),E(1.42*r/_-.71,t[1])]);return n}function C(t,n){const r=new Map;for(const c of A(n))for(const{cell:n}of R(t,c))r.set(h(...n),n);return[...r.values()].sort((t,n)=>t[1]-n[1]||t[0]-n[0])}},987,[986]);
1091
- __d(function(_g,_r,_i,_a,m,e,_d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"TAP_RADIUS",{enumerable:!0,get:function(){return t}}),Object.defineProperty(e,"MAX_SPLOTCH_RADIUS",{enumerable:!0,get:function(){return r}}),Object.defineProperty(e,"BURST_S",{enumerable:!0,get:function(){return n}}),Object.defineProperty(e,"TAP_EDGE",{enumerable:!0,get:function(){return o}}),Object.defineProperty(e,"PRESSURE_PER_TAP",{enumerable:!0,get:function(){return s}}),Object.defineProperty(e,"PRESSURE_DRAIN_S",{enumerable:!0,get:function(){return u}}),Object.defineProperty(e,"CRITICAL_PRESSURE",{enumerable:!0,get:function(){return a}}),Object.defineProperty(e,"PRESSURE_SPAN",{enumerable:!0,get:function(){return c}}),Object.defineProperty(e,"MAX_SPEED",{enumerable:!0,get:function(){return i}}),Object.defineProperty(e,"RECLAIM",{enumerable:!0,get:function(){return p}}),Object.defineProperty(e,"WOBBLE",{enumerable:!0,get:function(){return l}}),Object.defineProperty(e,"ASPECT",{enumerable:!0,get:function(){return h}}),Object.defineProperty(e,"LOBE_MAX",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"WASH_DELAY_S",{enumerable:!0,get:function(){return g}}),Object.defineProperty(e,"WASH_SPEED",{enumerable:!0,get:function(){return d}}),Object.defineProperty(e,"RISE",{enumerable:!0,get:function(){return b}}),Object.defineProperty(e,"RISE_IN_S",{enumerable:!0,get:function(){return y}}),Object.defineProperty(e,"COVER_MARGIN",{enumerable:!0,get:function(){return M}}),Object.defineProperty(e,"MAX_SPLOTCHES",{enumerable:!0,get:function(){return P}}),Object.defineProperty(e,"SPLOTCH_TEXELS",{enumerable:!0,get:function(){return O}}),Object.defineProperty(e,"emptyFilm",{enumerable:!0,get:function(){return S}}),e.randomShape=A,e.sdAt=_,e.reach=I,e.touching=R,e.tap=function(r,o,u,a){const c=new Map(r.groups.map(t=>[t.id,t])),i=C(r).filter(t=>!k(c.get(t.group),r.clock)),p=i.filter(t=>_(t,o,u)<=-.02).at(-1);if(p){const t=r.groups.map(t=>t.id===p.group?Object.assign({},t,{lastTap:r.clock}):t);return{film:Object.assign({},r,{groups:t}),started:null,recolored:t.find(t=>t.id===p.group)}}const l={x:o,y:u,r:t,phase:0,group:0,shape:j,anchoredAt:null,rise:1},h=i.filter(t=>R(l,t)).at(-1),f=h?c.get(h.group):null,g=r.groups.filter(t=>!t.auto&&!k(t,r.clock)).reduce((t,r)=>!t||r.lastTap>t.lastTap?r:t,null),d=f??(g&&r.clock-g.lastTap<=n?g:null),b=d?null:{id:r.nextId,pressure:0,born:r.clock,lastTap:r.clock,auto:!1,washAt:null},y=(d??b).id,M=(b?[...r.groups,b]:r.groups).map(t=>t.id===y?Object.assign({},t,{pressure:t.pressure+s,lastTap:r.clock}):t),P=Object.assign({},l,{phase:1e3*a(),group:y,shape:A(a)}),O=[...T(r.splotches),P],S=new Set(O.map(t=>t.group));return{film:Object.assign({},r,{groups:M.filter(t=>S.has(t.id)),splotches:O,nextId:b?r.nextId+1:r.nextId}),started:b?M.find(t=>t.id===y):null,recolored:null}},e.shift=function(t,r,n){return 0===r&&0===n?t:Object.assign({},t,{splotches:t.splotches.map(t=>Object.assign({},t,{x:t.x+r,y:t.y+n}))})},e.invade=function(t,r,n,o){if(t.groups.some(t=>t.auto))return null;const s={id:t.nextId,pressure:0,born:t.clock,lastTap:t.clock,auto:!0,washAt:t.clock},u={x:r,y:n,r:.005,phase:1e3*o(),group:s.id,shape:j,anchoredAt:null,rise:1},a=[...T(t.splotches),u],c=new Set(a.map(t=>t.group));return{film:Object.assign({},t,{groups:[...t.groups,s].filter(t=>c.has(t.id)),splotches:a,nextId:t.nextId+1}),started:s}},e.autoDue=function(t,r,n){return n>=r&&!t.groups.some(t=>t.auto)},e.washing=k,e.frontSpeed=L,e.step=function(t,n,o=()=>!1){const s=Math.max(0,Math.min(n,.1)),a=t.clock+s,c=new Map(t.groups.map(t=>[t.id,t])),i=(t,r)=>{const n=c.get(t.group),s=c.get(r.group);return!n.auto&&!s.auto&&(n.id===s.id||o(n,s))},p=new Set(t.splotches.filter(r=>null!==r.anchoredAt||t.splotches.some(t=>t!==r&&i(r,t)&&R(r,t)))),l=t.groups.map(r=>{const n=null===r.washAt&&t.splotches.some(t=>t.group===r.id&&p.has(t));return Object.assign({},r,{washAt:n?a+g:r.washAt,pressure:r.pressure*Math.exp(-s/u)})}),h=new Map(l.map(t=>[t.id,t])),f=t.splotches.map(t=>{const n=h.get(t.group),o=k(n,a),u=p.has(t),c=o?d:L(n.pressure);let i=t.r+(c+.03*w(.5*a+t.phase))*s;o||(i=Math.min(r,i)),(u||o)&&(i=Math.max(t.r,i));const l=o?Math.min(b,t.rise+2*s/y):t.rise;return Object.assign({},t,{r:Math.max(0,i),anchoredAt:u?i:null,rise:l})}).filter(t=>t.r>0),M=new Set(f.map(t=>t.group));return Object.assign({},t,{clock:a,groups:l.filter(t=>M.has(t.id)),splotches:f})},e.covers=function(t,r,n,o=M){const s=t.splotches.filter(t=>t.group===r);return s.length>0&&n.every(([t,r])=>s.some(n=>_(n,t,r)<=-o))},e.adopt=function(t,r){const n=t.groups.find(t=>t.id===r);if(!n)return t;const o=new Set(t.groups.filter(t=>t.id!==r&&t.born>n.born).map(t=>t.id));return Object.assign({},t,{splotches:t.splotches.filter(t=>o.has(t.group)),groups:t.groups.filter(t=>o.has(t.id))})},e.packSplotches=function(t,r){const n=new Float32Array(1024);return C(t).slice(0,P).forEach((t,o)=>{const{angle:s,aspect:u,lobes:[a,c,i],phases:[p,l,h]}=t.shape;n.set([t.x,t.y,t.r,r(t.group),s,u,a,c,i,p,l,h,t.rise,0,0,0],o*O*4)}),n};const t=.09,r=.22,n=2.5,o=.02,s=1,u=30,a=.8,c=1.5,i=.032,p=.35,l=.015,h=[1.2,2.4],f=[.25,.2,.12],g=2,d=.05,b=3,y=2,M=.1,P=64,O=4,S=()=>({splotches:[],groups:[],clock:0,nextId:1}),j={angle:0,aspect:1,lobes:[0,0,0],phases:[0,0,0]};function A(t){return{angle:t()*Math.PI,aspect:(r=h[0],n=h[1],r+(n-r)*t()),lobes:[t()*f[0],t()*f[1],t()*f[2]],phases:[t()*Math.PI*2,t()*Math.PI*2,t()*Math.PI*2]};var r,n}function x(t,r){const[n,o,s]=t.lobes,[u,a,c]=t.phases;return 1+n*Math.cos(2*r+u)+o*Math.cos(3*r+a)+s*Math.cos(5*r+c)}function E(t,r,n){const o=r-t.x,s=n-t.y,u=s<0?s/t.rise:s,a=Math.cos(t.shape.angle),c=Math.sin(t.shape.angle);return[a*o+c*u,-c*o+a*u]}function _(t,r,n){const[o,s]=E(t,r,n),u=Math.sqrt(t.shape.aspect);return Math.hypot(o/u,s*u)-t.r*x(t.shape,Math.atan2(s,o))}function I(t,r,n){const o=Math.hypot(r-t.x,n-t.y);if(0===o)return 0;const s=t.x+(r-t.x)/o,u=t.y+(n-t.y)/o,[a,c]=E(t,s,u),i=Math.sqrt(t.shape.aspect),p=Math.hypot(a/i,c*i);return Math.max(0,t.r*x(t.shape,Math.atan2(c,a))/p)}function R(t,r){return t.r>0&&r.r>0&&Math.hypot(t.x-r.x,t.y-r.y)<I(t,r.x,r.y)+I(r,t.x,t.y)}function w(t){const r=Math.floor(t),n=t-r,o=t=>{const r=43758.5453*Math.sin(127.1*t+311.7);return 2*(r-Math.floor(r))-1},s=n*n*n*(n*(6*n-15)+10);return o(r)*n*(1-s)+o(r+1)*(n-1)*s}function T(t){if(t.length<P)return t;const r=(t.some(t=>null===t.anchoredAt)?t.filter(t=>null===t.anchoredAt):t).reduce((t,r)=>r.r<t.r?r:t);return t.filter(t=>t!==r)}function k(t,r){return null!==t.washAt&&r>=t.washAt}function L(t){const r=Math.max(-1,Math.min(1,(t-a)/c));return i*(r>=0?r:r*p)}function C(t){const r=new Map(t.groups.map(t=>[t.id,t.born]));return t.splotches.map((t,n)=>({s:t,i:n,b:r.get(t.group)??0})).sort((t,r)=>t.b-r.b||t.i-r.i).map(({s:t})=>t)}},988,[]);
1092
- __d(function(g,r,i,_a,m,_e,_d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return k}});var t=r(_d[0]),n=e(r(_d[1])),o=e(r(_d[2])),a=e(r(_d[3])),l=e(r(_d[4])),d=e(r(_d[5])),s=e(r(_d[6])),c=e(r(_d[7])),u=r(_d[8]),f=r(_d[9]),h=r(_d[10]),x=r(_d[11]);function y(e){const t=(0,f.relPart)(e);return t.ago?`${t.val} ago`:t.val}function p(e){return"local"===e.kind?"This machine's CLI":e.owner_nid?`Agent ${e.owner_nid}`:"agent"===e.kind?`Agent ${e.label}`:e.unused?"Meld QR not scanned yet":e.device?e.device:e.remote_addr?`Device at ${e.remote_addr}`:"Device not seen yet"}function v(e){const t=`${"agent"===e.kind?"started":"added"} ${y(e.created_at)}${e.minted_by_device?` by ${e.minted_by_device}`:""}`;if(e.unused){if(null===e.expires_at)return t;return`lapses in ${Math.max(1,Math.ceil((e.expires_at-Date.now())/6e4))} min \xb7 ${t}`}const n=[e.connected?"connected now":null!==e.last_used_at?`seen ${y(e.last_used_at)}`:"never used"];return e.remote_addr&&n.push(e.remote_addr),e.app_origin&&n.push(`via ${(0,h.originHost)(e.app_origin)}`),n.push(t),n.join(" \xb7 ")}function b(e){if(null===e.elsewhere_at)return null;const t=[e.last_device,e.last_remote_addr].filter(Boolean).join(" at ");return`Also used from another address${t?` (latest: ${t})`:""}, ${y(e.elsewhere_at)}`}function k({visible:e,conn:d,daemonName:f,onClose:h,onSignOutOthers:y,signedOutOthers:k,connected:_}){const[T,S]=(0,t.useState)(null),[C,$]=(0,t.useState)(!1),[z,O]=(0,t.useState)(null),[W,D]=(0,t.useState)(null),[R,H]=(0,t.useState)(null),[P,I]=(0,t.useState)(new Set),M=(0,t.useCallback)(async()=>{if(d){O(null);try{const e=await(0,u.listDeviceTokens)(d);$(null===e),S(e??[])}catch(e){O(String(e))}}},[d]);(0,t.useEffect)(()=>{e?(S(null),M()):D(null)},[e,M]);const L=async e=>{if(d){if(W!==e.id)return D(e.id),void I(new Set(e.descendants));H(e.id),O(null);try{await(0,u.revokeDeviceToken)(d,e.id,e.descendants.filter(e=>P.has(e))),D(null),await M()}catch(e){O(String(e))}finally{H(null)}}},A=()=>{R||h()},V=new Map((T??[]).map(e=>[e.id,e])),B=[...T??[]].sort((e,t)=>{const n=e=>e.current?0:"local"===e.kind?1:"device"===e.kind?2:3;return n(e)-n(t)||(t.last_used_at??t.created_at)-(e.last_used_at??e.created_at)});return(0,x.jsx)(o.default,{visible:e,transparent:!0,animationType:"fade",onRequestClose:A,children:(0,x.jsx)(a.default,{style:w.overlay,onPress:A,children:(0,x.jsxs)(a.default,{style:w.card,onPress:e=>e.stopPropagation(),children:[(0,x.jsxs)(s.default,{style:w.title,children:["Devices on ",f]}),null!==T||z?C?(0,x.jsx)(s.default,{style:w.body,children:"This daemon is older than the Devices list. Update brane on it to see and revoke devices."}):(0,x.jsx)(l.default,{style:w.list,children:B.map(e=>(0,x.jsxs)(c.default,{style:w.rowWrap,children:[(0,x.jsxs)(c.default,{style:w.row,children:[(0,x.jsxs)(c.default,{style:{flex:1},children:[(0,x.jsxs)(s.default,{style:w.rowTitle,numberOfLines:1,children:[p(e),e.current?(0,x.jsx)(s.default,{style:w.thisDevice,children:" this device"}):null]}),(0,x.jsx)(s.default,{style:w.rowDetail,children:v(e)}),"device"===e.kind&&(0,x.jsxs)(s.default,{style:w.rowLabel,children:["\"",e.label,"\""]}),b(e)&&(0,x.jsx)(s.default,{style:w.rowWarn,children:b(e)}),"adopted"===e.origin&&"device"===e.kind&&(0,x.jsx)(s.default,{style:w.rowWarn,children:"From before tokens were hashed; may have been logged"}),"adopted"===e.origin&&"agent"===e.kind&&(0,x.jsx)(s.default,{style:w.rowLabel,children:"Kept from before agents had their own tokens; replaced when it is next revived"})]}),"local"!==e.kind&&!e.current&&(0,x.jsx)(a.default,{style:[w.revoke,W===e.id&&w.revokeConfirm,null!==R&&{opacity:.5}],onPress:()=>L(e),disabled:null!==R,children:R===e.id?(0,x.jsx)(n.default,{size:"small",color:"#111"}):(0,x.jsx)(s.default,{style:[w.revokeText,W===e.id&&w.revokeConfirmText],children:W===e.id?"Revoke?":"Revoke"})})]}),W===e.id&&(0,x.jsx)(j,{token:e,byId:V,also:P,onToggle:e=>I(t=>{const n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})})]},e.id))}):(0,x.jsx)(n.default,{style:{marginVertical:16},color:"#aaa"}),z&&(0,x.jsx)(s.default,{style:w.error,children:z}),(0,x.jsx)(s.default,{style:w.footnote,children:"A revoked device is signed out until it scans a fresh Meld QR. To keep only this device:"}),(0,x.jsx)(a.default,{style:[w.signOut,(!_||null!==R)&&{opacity:.5}],onPress:y,disabled:!_||null!==R,children:(0,x.jsx)(s.default,{style:w.signOutText,children:k?"Other devices signed out":"Sign out other devices"})}),(0,x.jsx)(a.default,{style:[w.close,null!==R&&{opacity:.5}],onPress:A,disabled:null!==R,children:(0,x.jsx)(s.default,{style:w.closeText,children:"Close"})})]})})})}function j({token:e,byId:t,also:n,onToggle:o}){const l=[e,...e.descendants.map(e=>t.get(e)).filter(e=>!!e)].flatMap(e=>e.agents).filter(e=>"ended"!==e.status),d="agent"===e.kind;return 0!==e.descendants.length||0!==l.length||d?(0,x.jsxs)(c.default,{style:w.cascade,children:[d&&(0,x.jsxs)(s.default,{style:w.cascadeNote,children:["This cuts ",e.owner_nid??"the agent"," off from brane at once; its session keeps running without tools. To bring it back, end its session and revive it."]}),e.descendants.length>0&&(0,x.jsxs)(s.default,{style:w.cascadeHead,children:["Also revoke ",1===e.descendants.length?"the device or agent":`the ${e.descendants.length} devices and agents`," it added:"]}),e.descendants.map(e=>{const l=t.get(e),d=n.has(e);return(0,x.jsxs)(a.default,{style:w.cascadeRow,onPress:()=>o(e),children:[(0,x.jsx)(s.default,{style:[w.checkbox,d&&w.checkboxOn],children:d?"\u2611":"\u2610"}),(0,x.jsx)(s.default,{style:w.cascadeText,numberOfLines:2,children:l?`${p(l)} \xb7 ${v(l)}`:e})]},e)}),l.length>0&&(0,x.jsxs)(s.default,{style:w.cascadeNote,children:["Started ",1===l.length?"1 running agent":`${l.length} running agents`,":"," ",l.map(e=>e.id).join(", "),". Their sessions keep running; revoking their tokens cuts off their brane tools."]})]}):null}const w=d.default.create({overlay:{flex:1,backgroundColor:"rgba(0,0,0,0.6)",justifyContent:"center",alignItems:"center",padding:24},card:{backgroundColor:"#1e1e22",borderRadius:12,padding:20,width:"100%",maxWidth:420,maxHeight:"85%",borderWidth:1,borderColor:"#3a3a40"},title:{color:"#d8d8dd",fontSize:16,fontWeight:"600",marginBottom:10},body:{color:"#999",fontSize:13,lineHeight:18},list:{flexGrow:0},rowWrap:{borderBottomWidth:d.default.hairlineWidth,borderBottomColor:"#3a3a40",paddingVertical:10},row:{flexDirection:"row",alignItems:"center",gap:10},cascade:{marginTop:8,padding:10,borderRadius:8,backgroundColor:"#26262b",gap:6},cascadeHead:{color:"#d8d8dd",fontSize:13},cascadeRow:{flexDirection:"row",alignItems:"flex-start",gap:8},checkbox:{color:"#777",fontSize:16,lineHeight:18},checkboxOn:{color:"#e0a070"},cascadeText:{color:"#aaa",fontSize:12,flex:1,lineHeight:18},cascadeNote:{color:"#888",fontSize:12,lineHeight:16},rowTitle:{color:"#d8d8dd",fontSize:14},thisDevice:{color:"#66d9a0",fontSize:12},rowDetail:{color:"#777",fontSize:12,fontFamily:"monospace",marginTop:2},rowLabel:{color:"#666",fontSize:12,marginTop:2},rowWarn:{color:"#e0a070",fontSize:12,marginTop:2},revoke:{backgroundColor:"#2a2a30",borderRadius:8,paddingVertical:6,paddingHorizontal:12,minWidth:76,alignItems:"center"},revokeConfirm:{backgroundColor:"#e0a070"},revokeText:{color:"#e0a070",fontSize:13,fontWeight:"600"},revokeConfirmText:{color:"#111"},error:{color:"#e07070",fontSize:12,marginTop:8},footnote:{color:"#666",fontSize:12,lineHeight:16,marginTop:12},signOut:{backgroundColor:"#2a2a30",borderRadius:8,paddingVertical:10,alignItems:"center",marginTop:8},signOutText:{color:"#e0a070",fontSize:14,fontWeight:"600"},close:{backgroundColor:"#2a2a30",borderRadius:8,paddingVertical:10,alignItems:"center",marginTop:12},closeText:{color:"#aaa",fontSize:14,fontWeight:"600"}})},989,[11,416,153,146,122,26,105,13,745,751,979,6]);
1093
- __d(function(g,r,i,a,_m,_e,d){"use strict";Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"ARROW_STEP_PX",{enumerable:!0,get:function(){return e}}),Object.defineProperty(_e,"PAGE_FRACTION",{enumerable:!0,get:function(){return t}}),_e.isListScrollKey=function(e){return!(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)&&n.has(e.key)},_e.listScrollTarget=function(n,c,o){const l=Math.max(0,o.scrollHeight-o.clientHeight),u=Math.max(1,o.clientHeight*t);let s;switch(n){case"ArrowUp":s=c-e;break;case"ArrowDown":s=c+e;break;case"PageUp":s=c-u;break;case"PageDown":s=c+u;break;case"Home":return 0;case"End":return l;default:return null}return Math.min(l,Math.max(0,s))};const e=40,t=.875,n=new Set(["PageUp","PageDown","Home","End","ArrowUp","ArrowDown"])},990,[]);
1094
- __d(function(g,r,i,a,_m,e,d){"use strict";var t=this&&this.__createBinding||(Object.create?function(t,n,o,c){void 0===c&&(c=o);var u=Object.getOwnPropertyDescriptor(n,o);u&&!("get"in u?!n.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return n[o]}}),Object.defineProperty(t,c,u)}:function(t,n,o,c){void 0===c&&(c=o),t[c]=n[o]}),n=this&&this.__exportStar||function(n,o){for(var c in n)"default"===c||Object.prototype.hasOwnProperty.call(o,c)||t(o,n,c)};Object.defineProperty(e,"__esModule",{value:!0}),n(r(d[0]),e)},991,[738]);
1095
- __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,"__esModule",{value:!0})},992,[]);
1096
- __d(function(g,r,_i,a,_m,_e,d){"use strict";var e,t=r(d[0]),n=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,i)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},e(t)},function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var c=e(t),u=0;u<c.length;u++)"default"!==c[u]&&n(i,t,c[u]);return o(i,t),i});Object.defineProperty(_e,"__esModule",{value:!0}),_e.renderRootComponent=function(e){try{setTimeout(()=>{f._internal_preventAutoHideAsync?.()}),u.startTransition(()=>{(0,c.registerRootComponent)(e)})}catch(e){f.hideAsync();const n=b(e);(0,c.registerRootComponent)(()=>t.jsx(s.View,{})),console.error(n),console.error("A runtime error has occurred while rendering the root component."),setTimeout(()=>{throw n})}};const c=r(d[1]),u=i(r(d[2])),s=r(d[3]),f=i(r(d[4]));function l(e){if('[object Object]'!==Object.prototype.toString.call(e))return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function p(e){return e&&'object'==typeof e&&'string'==typeof e.name&&'string'==typeof e.message}function b(e){return p(e)?e:l(e)?new Error(JSON.stringify(e)):new Error(String(e))}},993,[6,600,11,342,599]);
1084
+ __d(function(g,r,_i,_a,_m,_e,_d){"use strict";const e=["index","style"];function t(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return le}});var n=t(r(_d[0])),o=r(_d[1]),a=t(r(_d[2])),i=t(r(_d[3])),l=t(r(_d[4])),s=t(r(_d[5])),d=t(r(_d[6])),c=t(r(_d[7])),u=t(r(_d[8])),f=t(r(_d[9])),h=t(r(_d[10])),m=r(_d[11]),p=r(_d[12]);r(_d[13]);var x=r(_d[14]),y=t(r(_d[15])),b=r(_d[16]),v=r(_d[17]),j=r(_d[18]),w=r(_d[19]),S=r(_d[20]),C=r(_d[21]),T=t(r(_d[22])),k=r(_d[23]),B=r(_d[24]),R=t(r(_d[25])),O=t(r(_d[26])),z=t(r(_d[27])),P=t(r(_d[28])),_=r(_d[29]),I=r(_d[30]),L=r(_d[31]),E=r(_d[32]),H=r(_d[33]),D=r(_d[34]),W=r(_d[35]);const A=400;function M(t){let{index:o,style:i}=t,l=(0,n.default)(t,e);return(0,W.jsx)(a.default,Object.assign({},l,{style:[i,{zIndex:1e5-o,position:"relative"}]}))}function $({item:e,conn:t,onPress:n,onArchive:l,onMeld:s,onTwin:d,onRevive:c,onEnd:f,menuVisible:h,setMenuVisible:m,hits:p,onHitPress:x,isolated:T,appHost:k}){const B="ended"===e.status?"dead":e.mcp_connected?"live":"idle",R="ended"===e.status?"#666":e.mcp_connected?"#66d9a0":"#5b9bd5",[,O]=(0,o.useState)(0),z=(0,E.isAwaiting)({mcpConnected:e.mcp_connected,awaiting:e.awaiting})?(0,E.awaitingGlow)((0,j.glowHueFor)(e.id)):void 0,P="ended"===e.status?"grey":e.mcp_connected?"green":"blue",I=(0,w.menuHueRgb)(P),L=[`0 0 8px rgba(${I}, 0.9)`,`0 0 18px rgba(${I}, 0.7)`,`0 0 36px rgba(${I}, 0.4)`,`0 1px 12px rgba(${I}, 0.6)`].join(", ");return(0,W.jsx)("div",{style:{borderBottomWidth:u.default.hairlineWidth,borderBottomColor:"#555",borderBottomStyle:"solid",backgroundColor:"#121214",cursor:"pointer",boxShadow:z,transition:"box-shadow 400ms ease"},onClick:()=>n(),children:(0,W.jsxs)("div",{style:{padding:16},children:[(0,W.jsxs)("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"},children:[(0,W.jsx)(S.NarrativeIdentity,{id:e.id,foldPath:e.fold_path,style:{flex:1,minWidth:0}}),(0,W.jsxs)("div",{style:{position:"relative"},children:[(0,W.jsx)("button",{onClick:e=>{e.stopPropagation(),m(!h)},style:{background:"none",border:"none",color:R,fontSize:12,textTransform:"uppercase",cursor:"pointer",padding:"4px 8px",marginRight:-9,borderRadius:4,transition:"text-shadow 160ms ease",textShadow:h?L:void 0},children:B}),h&&(0,W.jsx)(y.default,{hue:P,items:(0,b.narrativeMenuItems)({role:e.role,status:e.status,mcpConnected:e.mcp_connected,archived:!!e.archived,isIsolated:T,canIsolate:!T||!!k,onMeld:()=>{m(!1),s()},onIsolate:()=>{if(m(!1),!t||"undefined"==typeof window)return;const n=(0,_.buildIsolateUrl)({host:window.location.host,protocol:window.location.protocol,search:window.location.search,path:`/${e.id}`,conn:t,appHost:k,view:{}});n&&window.open(n,"_blank","noopener,noreferrer")},onExport:()=>{m(!1),t&&(0,b.openNarrativeExport)(t,e.id)},onRecolor:()=>{m(!1),(0,v.bumpRecolorSalt)(e.id),(0,j.recolorGlowHue)(e.id),O(e=>e+1)},onTwin:()=>{m(!1),d()},onRevive:()=>{m(!1),c()},onEnd:()=>{m(!1),f()},onArchiveToggle:()=>{m(!1),l()}}),onClose:()=>m(!1)})]})]}),(0,W.jsx)(S.NarrativeMetaLine,{role:e.role,cost:(0,C.formatCost)(e.cost_amount,e.cost_unit),createdAt:e.created_at,lastActivity:e.last_activity,status:e.status,mcpConnected:e.mcp_connected,style:{marginTop:4}}),e.summary&&(0,W.jsx)("div",{style:{position:"relative",marginTop:4},children:(0,W.jsx)("div",{className:"no-scrollbar",style:{overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",WebkitOverflowScrolling:"touch",maskImage:"linear-gradient(to right, #000 calc(100% - 40px), transparent)",WebkitMaskImage:"linear-gradient(to right, #000 calc(100% - 40px), transparent)"},children:(0,W.jsx)(i.default,{style:[se.summary,{marginTop:0,whiteSpace:"nowrap"}],children:e.summary})})}),p&&p.length>0&&(0,W.jsx)(a.default,{style:se.hitsContainer,children:p.slice(0,3).map((t,n)=>(0,W.jsx)("div",{onClick:n=>{n.stopPropagation(),x?.(e.id,t.seq)},style:{cursor:"pointer"},children:(0,W.jsx)(i.default,{style:se.hitSnippet,numberOfLines:2,children:t.content})},n))})]})})}function N(e){const t=e.split("\n");let n=0;for(;n<t.length&&(""===t[n].trim()||/^#{1,6}\s/.test(t[n].trim()));)n++;return(t.slice(n).join("\n").trim()||e.trim()).split(/\n[ \t]*\n+/).map(e=>e.replace(/\s*\n\s*/g," ").replace(/[ \t]{2,}/g," ").trim()).filter(Boolean).join("\n")}const F=new Set(["the","and","for","with","that","this","from","are","was","but","not","you"]);function V(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function q(e){return(e.toLowerCase().match(/[\p{L}\p{N}]+/gu)??[]).filter(e=>e.length>=2&&!F.has(e))}function G(e,t){const n=N(e),o=q(t),a=n.toLowerCase();let i=-1;for(const e of o){const t=a.indexOf(e);t>=0&&(i<0||t<i)&&(i=t)}let l=0;if(i>60){l=i-50;const e=n.indexOf(" ",l);e>=0&&e<l+15&&(l=e+1)}const s=Math.min(n.length,l+220);let d=n.slice(l,s);if(l>0&&(d=`\u2026${d}`),s<n.length&&(d=`${d}\u2026`),0===o.length)return[{text:d,match:!1}];const c=new RegExp(`(${o.map(V).sort((e,t)=>t.length-e.length).join("|")})`,"giu"),u=[];let f,h=0;for(;null!==(f=c.exec(d));)f.index>h&&u.push({text:d.slice(h,f.index),match:!1}),u.push({text:f[0],match:!0}),h=f.index+f[0].length,f.index===c.lastIndex&&c.lastIndex++;return h<d.length&&u.push({text:d.slice(h),match:!1}),u}function Y({icon:e,label:t,count:n,collapsed:o,onToggle:l,order:d,onToggleOrder:c}){return(0,W.jsxs)(a.default,{style:[se.wikiBar,o&&se.wikiBarCollapsed],children:[(0,W.jsx)(i.default,{style:se.wikiBarIcon,children:e}),(0,W.jsx)(i.default,{style:se.wikiBarLabel,numberOfLines:1,children:t}),(0,W.jsx)(i.default,{style:se.wikiBarCount,numberOfLines:1,children:n}),(0,W.jsx)(a.default,{style:{flex:1}}),d&&c&&!o&&(0,W.jsx)(s.default,{onPress:c,hitSlop:6,style:({pressed:e})=>[se.wikiBarPill,e&&se.wikiBarPillPressed],children:(0,W.jsx)(i.default,{style:se.wikiBarOrderLabel,children:"recent"===d?"Recency":"Relevance"})}),(0,W.jsx)(s.default,{onPress:l,hitSlop:6,style:({pressed:e})=>[se.wikiBarPill,e&&se.wikiBarPillPressed],children:(0,W.jsx)(i.default,{style:se.wikiBarToggle,children:o?"Show":"Hide"})})]})}function U({results:e,query:t,collapsed:n,onToggle:o,onOpen:l}){return 0===e.length?null:(0,W.jsxs)(a.default,{style:se.wikiSection,children:[(0,W.jsx)(Y,{icon:"\ud83d\udcd6",label:"Wiki",count:e.length,collapsed:n,onToggle:o}),!n&&e.map(e=>(0,W.jsxs)(a.default,{style:se.wikiCard,children:[(0,W.jsx)(s.default,{onPress:()=>l(e.source,e.slug,e.hits[0]?.anchor),children:(0,W.jsxs)(a.default,{style:se.wikiCardHeader,children:[(0,W.jsx)(i.default,{style:se.wikiSlug,numberOfLines:1,children:e.slug.replace(/\.md$/,"")}),(0,W.jsx)(i.default,{style:se.wikiSource,children:e.source})]})}),(0,W.jsx)(a.default,{style:se.hitsContainer,children:e.hits.slice(0,3).map((n,o)=>(0,W.jsxs)(s.default,{onPress:()=>l(e.source,e.slug,n.anchor),children:[!!n.anchor&&(0,W.jsxs)(i.default,{style:se.wikiHitCitation,children:["#",n.anchor]}),(0,W.jsx)(i.default,{style:se.hitSnippet,numberOfLines:3,children:G(n.content,t).map((e,t)=>e.match?(0,W.jsx)(i.default,{style:se.hitMatch,children:e.text},t):e.text)})]},o))})]},`${e.source}\0${e.slug}`))]})}function K(e){const t=new Map;for(const n of e)for(const e of n.cost??[]){const n=t.get(e.unit)??{unit:e.unit,amount:0,metered:0};n.amount+=e.amount,n.metered+=e.metered,t.set(e.unit,n)}return[...t.values()].sort((e,t)=>t.metered-e.metered)}const Q="\xa0";function X(e){if(!e?.length)return null;return e.map(e=>{return`${t=(0,C.formatCost)(e.amount,e.unit),(t??"").replace(/(\d) ([A-Za-z])/g,`$1${Q}$2`)}${Q}(${e.metered})`;var t}).join(" + ")}function Z({branes:e,activeBraneId:t,daemons:n,activeDaemon:l,connected:u,onSwitchBrane:m,onSwitchDaemon:p,onAdd:x,onRemove:y,onSignOutOthers:b,conn:v}){const[j,w]=(0,o.useState)(!1),[S,C]=(0,o.useState)(!1),[T,k]=(0,o.useState)(!1),[B,R]=(0,o.useState)(!1),[O,z]=(0,o.useState)(!1),[_,I]=(0,o.useState)(""),[L,E]=(0,o.useState)(""),[H,D]=(0,o.useState)(!1),[A,M]=(0,o.useState)(null),[$,N]=(0,o.useState)(null),[F,V]=(0,o.useState)(!1),q=()=>{w(!1),C(!1),k(!1),z(!1),N(null),V(!1)},G=()=>{B||(k(!1),N(null))},Y=()=>{H||(C(!1),M(null))},U=(0,o.useMemo)(()=>K(e),[e]),Q=t?e.find(e=>e.brane_id===t)?.is_home?`${t} (home)`:t:l?.id??"No daemon";return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(s.default,{style:se.daemonChip,onPress:()=>w(!0),children:[(0,W.jsx)(a.default,{style:[se.chipDot,{backgroundColor:u?"#66d9a0":"#e07070"}]}),(0,W.jsx)(i.default,{style:se.chipText,numberOfLines:1,children:Q}),(0,W.jsx)(i.default,{style:se.chipChevron,children:"\u25bc"})]}),(0,W.jsx)(d.default,{visible:j,transparent:!0,animationType:"fade",onRequestClose:q,children:(0,W.jsx)(s.default,{style:se.modalOverlay,onPress:q,children:(0,W.jsxs)(s.default,{style:se.modalContent,onPress:()=>{},children:[(0,W.jsx)(i.default,{style:se.modalTitle,children:"Branes"}),(0,W.jsxs)(c.default,{style:{flexGrow:0},children:[(0,W.jsx)(s.default,{style:[se.daemonOption,null===t&&se.daemonOptionActive],onPress:()=>{m(null),w(!1)},children:(0,W.jsxs)(a.default,{style:se.daemonOptionRow,children:[(0,W.jsx)(a.default,{style:[se.daemonDot,{backgroundColor:u?"#66d9a0":"#555"}]}),(0,W.jsxs)(a.default,{style:{flex:1},children:[(0,W.jsx)(i.default,{style:se.daemonName,children:"All branes"}),(0,W.jsx)(i.default,{style:se.daemonHost,children:l?.id}),X(U)&&(0,W.jsx)(i.default,{style:se.daemonCost,children:X(U)})]})]})}),e.map(e=>(0,W.jsx)(s.default,{style:[se.daemonOption,e.brane_id===t&&se.daemonOptionActive],onPress:()=>{m(e.brane_id),w(!1)},children:(0,W.jsxs)(a.default,{style:se.daemonOptionRow,children:[(0,W.jsx)(a.default,{style:[se.daemonDot,{backgroundColor:e.active_count>0?"#66d9a0":"#555"}]}),(0,W.jsxs)(a.default,{style:{flex:1},children:[(0,W.jsxs)(i.default,{style:se.daemonName,children:[e.brane_id,e.is_home?" (home)":""]}),(0,W.jsxs)(i.default,{style:se.daemonHost,children:[e.active_count," active, ",e.narrative_count," total",e.absorbed_count>0?` (${e.absorbed_count} absorbed)`:""]}),X(e.cost)&&(0,W.jsx)(i.default,{style:se.daemonCost,children:X(e.cost)})]})]})},e.brane_id)),0===e.length&&0===n.length&&(0,W.jsx)(i.default,{style:se.emptyDaemons,children:"No daemons configured"}),n.filter(e=>e.id!==l?.id).map(e=>(0,W.jsx)(s.default,{style:se.daemonOption,onPress:()=>{p(e.id),w(!1)},onLongPress:()=>y(e.id),children:(0,W.jsxs)(a.default,{style:se.daemonOptionRow,children:[(0,W.jsx)(a.default,{style:[se.daemonDot,{backgroundColor:"#555"}]}),(0,W.jsxs)(a.default,{style:{flex:1},children:[(0,W.jsx)(i.default,{style:se.daemonName,children:e.id}),(0,W.jsxs)(i.default,{style:se.daemonHost,children:[e.host," (switch daemon)"]})]})]})},e.id))]}),(0,W.jsx)(s.default,{style:se.addDaemonButton,onPress:()=>C(!0),children:(0,W.jsx)(i.default,{style:se.addDaemonButtonText,children:"+ Add Daemon"})}),l&&!l.revoked&&(0,W.jsx)(s.default,{style:se.addDaemonButton,onPress:()=>z(!0),disabled:!u,children:(0,W.jsx)(i.default,{style:[se.addDaemonButtonText,!u&&{opacity:.5}],children:"Devices"})}),(0,W.jsx)(s.default,{style:se.modalCancel,onPress:q,children:(0,W.jsx)(i.default,{style:se.modalCancelText,children:"Close"})})]})})}),(0,W.jsx)(d.default,{visible:j&&S,transparent:!0,animationType:"fade",onRequestClose:Y,children:(0,W.jsx)(s.default,{style:se.modalOverlay,onPress:Y,children:(0,W.jsxs)(s.default,{style:se.layerCard,onPress:e=>e.stopPropagation(),children:[(0,W.jsx)(i.default,{style:se.layerTitle,children:"Add a daemon"}),(0,W.jsxs)(a.default,{style:se.addForm,children:[(0,W.jsx)(h.default,{style:se.addInput,placeholder:"host:port",placeholderTextColor:"#666",value:_,onChangeText:I,autoCapitalize:"none",autoCorrect:!1,autoFocus:!0}),(0,W.jsx)(h.default,{style:se.addInput,placeholder:"token",placeholderTextColor:"#666",value:L,onChangeText:E,autoCapitalize:"none",autoCorrect:!1,secureTextEntry:!0}),A&&(0,W.jsx)(i.default,{style:se.addError,children:A}),(0,W.jsxs)(a.default,{style:se.layerButtonRow,children:[(0,W.jsx)(s.default,{style:[se.layerCancel,H&&{opacity:.5}],onPress:Y,disabled:H,children:(0,W.jsx)(i.default,{style:se.layerCancelText,children:"Cancel"})}),(0,W.jsx)(s.default,{style:[se.addButton,se.layerConfirm,(H||!_||!L)&&{opacity:.5}],onPress:async()=>{if(_&&L){D(!0),M(null);try{await x(_,L),C(!1),w(!1),I(""),E("")}catch(e){M(String(e))}finally{D(!1)}}},disabled:H||!_||!L,children:H?(0,W.jsx)(f.default,{size:"small",color:"#111"}):(0,W.jsx)(i.default,{style:se.addButtonText,children:"Connect"})})]})]})]})})}),(0,W.jsx)(P.default,{visible:j&&O,conn:v,daemonName:l?.id??"this daemon",onClose:()=>z(!1),onSignOutOthers:()=>k(!0),signedOutOthers:F,connected:u}),(0,W.jsx)(d.default,{visible:j&&T,transparent:!0,animationType:"fade",onRequestClose:G,children:(0,W.jsx)(s.default,{style:se.modalOverlay,onPress:G,children:(0,W.jsxs)(s.default,{style:se.layerCard,onPress:e=>e.stopPropagation(),children:[(0,W.jsx)(i.default,{style:se.layerTitle,children:"Sign out other devices?"}),(0,W.jsxs)(i.default,{style:se.signOutBody,children:[l?.id," will issue a new token. This device keeps its access; every other phone and browser paired with it is signed out until it scans a fresh Meld QR. Running agents and your shell are unaffected."]}),$&&(0,W.jsx)(i.default,{style:se.addError,children:$}),(0,W.jsxs)(a.default,{style:se.layerButtonRow,children:[(0,W.jsx)(s.default,{style:[se.layerCancel,B&&{opacity:.5}],onPress:G,disabled:B,children:(0,W.jsx)(i.default,{style:se.layerCancelText,children:"Cancel"})}),(0,W.jsx)(s.default,{style:[se.signOutButton,se.layerConfirm,B&&{opacity:.5}],onPress:async()=>{R(!0),N(null);try{await b(),V(!0),k(!1)}catch(e){N(String(e))}finally{R(!1)}},disabled:B,children:B?(0,W.jsx)(f.default,{size:"small",color:"#111"}):(0,W.jsx)(i.default,{style:se.addButtonText,children:"Sign out other devices"})})]})]})})})]})}const J=30,ee=.5,te=64,ne=96,oe=52,re=360;function ae(e){return-Math.min(e,ne)/ne*re}function ie({refreshing:e,onRefresh:t,scrollOffsetRef:n,children:a}){const i=(0,o.useRef)(null),[l,s]=(0,o.useState)(0),[d,c]=(0,o.useState)(!1),[u,f]=(0,B.useDetentSpin)(e),[h,m]=(0,o.useState)("none"),p=(0,o.useRef)(0),x=(0,o.useRef)(null),y=(0,o.useRef)(!1),b=(0,o.useCallback)(e=>{p.current=e,s(e)},[]);(0,o.useEffect)(()=>{const o=i.current;if(!o)return;const a=()=>(n.current??0)<=0,l=t=>{if(e||1!==t.touches.length||!a())return y.current=!1,void(x.current=null);x.current=t.touches[0].clientY,y.current=!0},s=t=>{if(!y.current||null===x.current||e)return;const n=t.touches[0].clientY-x.current;if(n<=0||!a())return a()||(y.current=!1),0!==p.current&&(b(0),f(0)),void c(!1);t.preventDefault();const o=Math.min(ne,n*ee);c(!0),m("none"),b(o),f(ae(o))},d=()=>{var n;y.current&&(y.current=!1,x.current=null,c(!1),p.current>=te&&!e?(f((n=ae(p.current),Math.round(n/B.RECYCLE_STEP)*B.RECYCLE_STEP)),b(oe),t()):(m("transform 0.4s ease"),f(0),b(0)))};return o.addEventListener("touchstart",l,{passive:!0}),o.addEventListener("touchmove",s,{passive:!1}),o.addEventListener("touchend",d,{passive:!0}),o.addEventListener("touchcancel",d,{passive:!0}),()=>{o.removeEventListener("touchstart",l),o.removeEventListener("touchmove",s),o.removeEventListener("touchend",d),o.removeEventListener("touchcancel",d)}},[e,t,n,b]),(0,o.useEffect)(()=>{if(!e)return 0!==p.current&&b(0),m("none"),void f(0);m("transform 0.18s ease")},[e,b,f]);const v=d?"none":"transform 0.25s ease";return(0,W.jsxs)("div",{ref:i,style:{flex:1,minHeight:0,position:"relative",overflow:"hidden",display:"flex",flexDirection:"column"},children:[(0,W.jsx)("div",{style:{position:"absolute",top:0,left:0,right:0,height:oe,display:"flex",alignItems:"center",justifyContent:"center",transform:`translateY(${l-oe}px)`,transition:v,pointerEvents:"none",zIndex:1},children:(0,W.jsx)(B.RecycleGlyph,{angle:u,transition:h,fontSize:26,opacity:e?1:Math.min(1,l/te)})}),(0,W.jsx)("div",{style:{flex:1,minHeight:0,display:"flex",flexDirection:"column",transform:`translateY(${l}px)`,transition:v},children:a})]})}function le(){const{conn:e,connected:t,daemons:n,activeDaemon:d,activeBraneId:c,switchDaemon:u,switchBrane:y,addDaemon:v,removeDaemon:j,rotateActiveToken:w,onStatus:S,onMeta:B,onActivity:P,subscribeActivity:N,unsubscribeActivity:F}=(0,x.useBrane)(),V="undefined"!=typeof window&&!!e&&(0,_.isIsolated)(window.location.host,e.host),q=(0,I.useAppHost)(e,V),[G,K]=(0,o.useState)([]),[Q,X]=(0,o.useState)([]),ee=(0,o.useRef)(null),[te,ne]=(0,o.useState)([]),[oe,re]=(0,o.useState)(!0),[ae,le]=(0,o.useState)(!1),[de,ce]=(0,o.useState)(!1),[ue,fe]=(0,o.useState)(null),[he,me]=(0,o.useState)(null),[pe,ge]=(0,o.useState)(null),[xe,ye]=(0,o.useState)(null),[be,ve]=(0,o.useState)(J),[je,we]=(0,o.useState)(!1),[Se,Ce]=(0,o.useState)(""),[Te,ke]=(0,o.useState)([]),[Be,Re]=(0,o.useState)(!1),[Oe,ze]=(0,o.useState)([]),[Pe,Ie]=(0,o.useState)(!1),[Le,Ee]=(0,o.useState)(!1),[He,De]=(0,o.useState)("relevance"),[We,Ae]=(0,o.useState)(null),Me=(0,o.useRef)(null),$e=(0,o.useRef)(null),Ne=(0,o.useRef)(null),Fe=(0,o.useRef)(0),Ve=(0,m.useRouter)(),qe=(0,p.useIsFocused)(),Ge=(0,o.useRef)(!1);Ge.current=qe;const Ye=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!qe)return;const e=e=>{if(!Ge.current)return;if(e.defaultPrevented||e.isComposing||!(0,H.isListScrollKey)(e))return;const t=Ne.current?.getScrollableNode();if(!t)return;const n=e.target,o=n?.tagName;if("INPUT"===o||"TEXTAREA"===o||"SELECT"===o||n?.isContentEditable)return;if(n&&t.contains(n))return;if(document.querySelector('[aria-modal="true"]'))return;const a=performance.now(),i=Ye.current,l=i&&a-i.at<A?i.target:t.scrollTop,s=(0,H.listScrollTarget)(e.key,l,t);if(null===s)return;e.preventDefault(),Ye.current={target:s,at:a};const d=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;t.scroll({top:s,behavior:e.repeat||d?"auto":"smooth"})};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[qe]);const Ue=(0,o.useCallback)(async()=>{if(e){ye(null),ve(J);try{const t=c?{archived:!0,braneIds:[c]}:void 0,[n,o,a]=await Promise.all([(0,C.fetchNarratives)(e,t),(0,C.fetchFolds)(e),(0,C.fetchBranes)(e).catch(()=>[])]);K((0,L.sortNarratives)(n)),ne(o),X(a),setTimeout(()=>{Ne.current?.scrollToOffset({offset:0,animated:!1})},50)}catch(e){ye(String(e)),K([]),ne([]),X([])}finally{re(!1)}}},[e,c]),Ke=(0,o.useCallback)(async()=>{if(e&&!ae){le(!0);try{await Ue()}finally{le(!1)}}},[e,ae,Ue]);(0,o.useEffect)(()=>{if(e)K([]),ne([]),X([]),re(!0),Ue();else if(K([]),ne([]),X([]),re(!1),0===n.length){const e=setTimeout(()=>{ye(null),re(!1)},100);return()=>clearTimeout(e)}},[e,Ue,n.length]);const Qe=(0,o.useCallback)(()=>{e&&ce(!0)},[e]),Xe=(0,o.useCallback)(e=>{K(t=>[e,...t]),Ve.push("utility"===e.role?`/${e.id}?tab=terminal`:`/${e.id}`)},[Ve]),Ze=(0,o.useCallback)(async t=>{if(!e)return;if((0,b.revivesAsTwin)(t.role))return void ge(t);const n=t.id;try{const t=(await(0,C.reviveNarrative)(e,n)).nid??n;t!==n&&Ue(),Ve.push((0,_.terminalOnlyHref)(t))}catch(e){ye(String(e))}},[e,Ve,Ue]),Je=(0,o.useCallback)(t=>{e&&((0,D.interruptSession)(e,t),Ve.push((0,_.terminalOnlyHref)(t)))},[e,Ve]),et=(0,o.useCallback)(async(t,n)=>{if(!e)return;const o=!n;try{await(0,C.archiveNarrative)(e,t,o),K(o?e=>e.filter(e=>e.id!==t):e=>e.map(e=>e.id===t?Object.assign({},e,{archived:!1}):e))}catch(e){ye(String(e))}},[e]),tt=(0,o.useCallback)(async(e,t)=>{await v(e,t)},[v]);(0,o.useEffect)(()=>S((e,t)=>{K(n=>(0,L.sortNarratives)(n.map(n=>n.id!==e?n:"mcp_connected"===t?Object.assign({},n,{mcp_connected:!0}):"mcp_disconnected"===t?Object.assign({},n,{mcp_connected:!1,awaiting:!1}):t===E.AWAITING_STATUS?Object.assign({},n,{awaiting:!0}):t===E.NOT_AWAITING_STATUS?Object.assign({},n,{awaiting:!1}):Object.assign({},n,{status:t}))))}),[S]),(0,o.useEffect)(()=>B((t,n,o,a)=>{null!=a&&e&&(ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{ee.current=null,(0,C.fetchBranes)(e).then(X).catch(()=>{})},2e3)),K(e=>e.map(e=>{if(e.id!==t)return e;if(void 0===o&&null==a)return e;const n=Object.assign({},e);return void 0!==o&&(n.summary=o),null!=a&&(n.cost_amount=a.amount,n.cost_unit=a.unit),n}))}),[B,e]),(0,o.useEffect)(()=>{N();const e=P((e,t,n)=>{K(t=>{const o=t.findIndex(t=>t.id===e);if(o<0)return t;const a=t.slice();return a[o]=Object.assign({},a[o],{last_activity:n}),a})});return()=>{e(),F()}},[P,N,F]);const nt=!e&&0===n.length,[ot,rt]=(0,o.useState)([]);(0,o.useEffect)(()=>e&&Se.trim()?(Re(!0),Me.current&&clearTimeout(Me.current),Me.current=setTimeout(()=>{(0,C.searchNarratives)(e,Se.trim(),30,c?[c]:void 0).then(e=>{ke(e.results),rt(e.narratives||[]),Re(!1)}).catch(()=>{ke([]),rt([]),Re(!1)}),(0,C.searchWiki)(e,Se.trim(),10).then(e=>ze(e.results)).catch(()=>ze([]))},300),()=>{Me.current&&clearTimeout(Me.current)}):(ke([]),rt([]),ze([]),void Re(!1)),[e,Se,c]);const at=(0,o.useMemo)(()=>new Set(G.map(e=>e.id)),[G]),it=(0,o.useMemo)(()=>{const e=new Map;for(const t of Te){const n=e.get(t.narrative_id);n?n.push(t):e.set(t.narrative_id,[t])}return e},[Te]),lt=(0,o.useMemo)(()=>{if(!Se.trim())return G;const e=Se.toLowerCase(),t=new Set(G.filter(t=>t.id.toLowerCase().includes(e)||t.summary?.toLowerCase().includes(e)||t.agent_type?.toLowerCase().includes(e)||t.role?.toLowerCase().includes(e)||t.fold_path?.toLowerCase().includes(e)||it.has(t.id)).map(e=>e.id)),n=new Map(G.map(e=>[e.id,e])),o=new Map;for(const e of t)o.set(e,n.get(e));for(const e of ot)o.has(e.id)||o.set(e.id,e);return[...o.values()]},[G,Se,it,ot]),st=(0,o.useMemo)(()=>{const e=new Map;for(const t of Te){const n=e.get(t.narrative_id);(void 0===n||t.score>n)&&e.set(t.narrative_id,t.score)}return e},[Te]),dt=(0,o.useMemo)(()=>{if(Se.trim())return[...lt].sort((e,t)=>{if("recent"===He)return t.created_at-e.created_at;const n=st.get(e.id)??-1/0,o=st.get(t.id)??-1/0;return n!==o?o-n:t.created_at-e.created_at});const e=[],t=[];for(const n of lt)"ended"!==n.status||n.mcp_connected?e.push(n):t.push(n);return[...e,...t.slice(0,be)]},[lt,be,Se,He,st]);(0,o.useEffect)(()=>{ue&&!dt.some(e=>e.id===ue)&&fe(null)},[dt,ue]);const ct=(0,o.useMemo)(()=>{if(G.length>0)return 0;return(c?Q.filter(e=>e.brane_id===c):Q).reduce((e,t)=>e+t.narrative_count,0)},[G.length,Q,c]),ut=(0,o.useMemo)(()=>lt.filter(e=>"ended"===e.status&&!e.mcp_connected).length,[lt]),ft=(0,o.useCallback)(()=>{ve(e=>Math.min(e+J,ut))},[ut]);return(0,W.jsxs)(a.default,{style:se.container,children:[(0,W.jsx)(m.Stack.Screen,{options:{header:()=>(0,W.jsxs)(a.default,{style:se.customHeader,children:[(0,W.jsxs)(a.default,{style:se.headerTitleRow,children:[(0,W.jsx)(s.default,{onPress:Ue,children:(0,W.jsx)(i.default,{style:Object.assign({color:"#8fd4b4",fontSize:20,fontWeight:"700",letterSpacing:2},{textShadow:["0 0 7px rgba(143, 212, 180, 0.8)","0 0 20px rgba(143, 212, 180, 0.5)","0 0 40px rgba(100, 200, 160, 0.3)","0 2px 12px rgba(80, 180, 140, 0.6)"].join(", ")}),children:"BRANE"})}),(0,W.jsx)(s.default,{onPress:Qe,disabled:!e,style:[se.spawnButton,!e&&se.spawnButtonDisabled],children:(0,W.jsx)(i.default,{style:se.spawnButtonText,children:"Spawn"})}),(0,W.jsx)(Z,{branes:Q,activeBraneId:c,daemons:n,activeDaemon:d,connected:t,onSwitchBrane:y,onSwitchDaemon:u,onAdd:tt,onRemove:j,onSignOutOthers:w,conn:e}),(0,W.jsx)(s.default,{onPress:()=>{we(e=>(e?Ce(""):setTimeout(()=>$e.current?.focus(),100),!e))},style:[se.searchButton,je&&se.searchButtonActive],children:(0,W.jsx)(i.default,{style:[se.searchButtonText,je&&se.searchButtonTextActive],children:"\ud83d\udd2c"})})]}),je&&(0,W.jsx)(a.default,{style:se.searchBar,children:(0,W.jsx)(h.default,{ref:$e,style:se.searchInput,placeholder:"Filter narratives...",placeholderTextColor:"#556",value:Se,onChangeText:Ce,autoFocus:!0,autoCapitalize:"none",autoCorrect:!1,returnKeyType:"search"})})]})}}),d?.revoked?(0,W.jsxs)(a.default,{style:se.center,children:[(0,W.jsxs)(i.default,{style:se.signedOutTitle,children:["Signed out of ",d.id]}),(0,W.jsx)(i.default,{style:se.emptySubtext,children:"Its token was rotated from another device, so the one stored here no longer works. Scan a fresh Meld QR \u2014 or run `brane meld` on that machine \u2014 to reconnect. Nothing else was touched."})]}):oe?(0,W.jsx)(a.default,{style:se.center,children:(0,W.jsx)(f.default,{size:"large",color:"#5b9bd5"})}):xe?(0,W.jsx)(a.default,{style:se.center,children:(0,W.jsx)(i.default,{style:se.errorText,children:xe})}):nt?(0,W.jsx)(O.default,{title:"No daemons configured",subtitle:"Tap the daemon selector above to add one"}):(0,W.jsx)(k.MarkdownLinksProvider,{knownNarrativeIds:at,onNarrativePress:(e,t)=>Ve.push(null!=t?`/${e}?scrollToSeq=${t}`:`/${e}`),onProtocolPress:e=>Ae({source:"protocols",slug:e}),children:(0,W.jsx)(ie,{refreshing:ae,onRefresh:Ke,scrollOffsetRef:Fe,children:(0,W.jsx)(l.default,{ref:Ne,style:{flex:1},data:Se.trim()&&Le?[]:dt,keyExtractor:e=>e.id,CellRendererComponent:M,onScroll:e=>{Fe.current=e.nativeEvent.contentOffset.y},scrollEventThrottle:16,ListHeaderComponent:Se.trim()?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(U,{results:Oe,query:Se.trim(),collapsed:Pe,onToggle:()=>Ie(e=>!e),onOpen:(e,t,n)=>Ae({source:e,slug:t,anchor:n})}),(0,W.jsx)(a.default,{style:se.wikiSection,children:(0,W.jsx)(Y,{icon:"\ud83d\udcac",label:"Narratives",count:dt.length,collapsed:Le,onToggle:()=>Ee(e=>!e),order:He,onToggleOrder:()=>De(e=>"relevance"===e?"recent":"relevance")})})]}):null,renderItem:({item:t})=>(0,W.jsx)($,{item:t,conn:e,onPress:()=>Ve.push(`/${t.id}`),onArchive:()=>et(t.id,!!t.archived),onMeld:()=>me(t),onTwin:()=>ge(t),onRevive:()=>Ze(t),onEnd:()=>Je(t.id),menuVisible:ue===t.id,setMenuVisible:e=>fe(e?t.id:null),hits:it.get(t.id),onHitPress:(e,t)=>Ve.push(`/${e}?scrollToSeq=${t}`),isolated:V,appHost:q}),onEndReached:!Se.trim()&&be<ut?ft:void 0,onEndReachedThreshold:.3,ListFooterComponent:dt.length>0&&!Se.trim()?(0,W.jsx)(O.default,{}):null,contentContainerStyle:0!==dt.length||Se.trim()?void 0:se.emptyFill,ListEmptyComponent:Se.trim()?Le?null:(0,W.jsx)(a.default,{style:se.center,children:(0,W.jsx)(i.default,{style:se.emptyText,children:"No narratives match"})}):(0,W.jsx)(O.default,{title:0===ct?"No narratives yet":1===ct?"The only narrative is archived":`All ${ct} narratives are archived`})})})}),(0,W.jsx)(R.default,{visible:de,conn:e,onClose:()=>{ce(!1),e&&(0,C.fetchFolds)(e).then(ne).catch(()=>{})},onSpawned:Xe}),(0,W.jsx)(z.default,{visible:null!==he,conn:e,path:`/${he?.id??""}`,onClose:()=>me(null)}),(0,W.jsx)(R.default,{visible:null!==pe,conn:e,re:pe?.id,defaultFoldPath:pe?.fold_path,onClose:()=>ge(null),onSpawned:Xe}),We&&e&&(0,W.jsx)(k.MarkdownLinksProvider,{knownNarrativeIds:at,onNarrativePress:(e,t)=>{Ae(null),Ve.push(null!=t?`/${e}?scrollToSeq=${t}`:`/${e}`)},children:(0,W.jsx)(T.default,{conn:e,target:We,onClose:()=>Ae(null)})})]})}const se=u.default.create({container:{flex:1},center:{flex:1,justifyContent:"center",alignItems:"center",padding:20},customHeader:{backgroundColor:"#1a1a1e",paddingTop:10,paddingHorizontal:16,paddingBottom:10,borderBottomWidth:u.default.hairlineWidth,borderBottomColor:"rgb(216, 216, 216)"},headerTitleRow:{flexDirection:"row",alignItems:"center",gap:12},daemonChip:{flexDirection:"row",alignItems:"center",backgroundColor:"#2a2a30",borderRadius:6,paddingHorizontal:10,paddingVertical:6,maxWidth:180},chipDot:{width:8,height:8,borderRadius:4,marginRight:8},chipText:{color:"#d8d8dd",fontSize:15,fontFamily:"monospace"},chipChevron:{color:"#888",fontSize:14,marginLeft:5},daemonOption:{paddingVertical:12,paddingHorizontal:12,borderRadius:8,backgroundColor:"#2a2a30",marginBottom:6},daemonOptionActive:{backgroundColor:"#1a3a2a",borderWidth:1,borderColor:"#3a6a4a"},daemonOptionRow:{flexDirection:"row",alignItems:"center"},daemonDot:{width:8,height:8,borderRadius:4,marginRight:10},daemonName:{color:"#d8d8dd",fontSize:15,fontFamily:"monospace"},daemonCost:{color:"#7bb894",fontSize:12,fontFamily:"monospace",marginTop:2},daemonHost:{color:"#777",fontSize:12,fontFamily:"monospace",marginTop:2},emptyDaemons:{color:"#666",fontSize:14,textAlign:"center",paddingVertical:16},addDaemonButton:{paddingVertical:14,alignItems:"center",borderRadius:8,backgroundColor:"#2a2a30",marginTop:8},addDaemonButtonText:{color:"#8fd4b4",fontSize:15,fontWeight:"600"},addForm:{marginTop:8,gap:8},addInput:{backgroundColor:"#222228",borderRadius:8,paddingHorizontal:12,paddingVertical:10,color:"#d8d8dd",fontSize:14,fontFamily:"monospace",borderWidth:1,borderColor:"#3a3a40"},addError:{color:"#e07070",fontSize:12},addButton:{backgroundColor:"#5b9bd5",borderRadius:8,paddingVertical:10,alignItems:"center"},addButtonText:{color:"#111",fontSize:14,fontWeight:"600"},signOutBody:{color:"#999",fontSize:13,lineHeight:18},layerCard:{backgroundColor:"#1e1e22",borderRadius:12,padding:20,width:"100%",maxWidth:360,borderWidth:1,borderColor:"#3a3a40"},layerTitle:{color:"#d8d8dd",fontSize:16,fontWeight:"600",marginBottom:10},layerButtonRow:{flexDirection:"row",gap:8,marginTop:4},layerCancel:{flex:1,backgroundColor:"#2a2a30",borderRadius:8,paddingVertical:10,alignItems:"center"},layerCancelText:{color:"#aaa",fontSize:14,fontWeight:"600"},layerConfirm:{flex:2},signOutButton:{backgroundColor:"#e0a070",borderRadius:8,paddingVertical:10,alignItems:"center"},signedOutTitle:{color:"#e0a070",fontSize:16,fontWeight:"600",marginBottom:8,textAlign:"center"},fieldLabel:{color:"#aaa",fontSize:12,fontWeight:"600",textTransform:"uppercase",letterSpacing:.5,marginTop:12,marginBottom:6},fieldStaticValue:{backgroundColor:"#222228",borderRadius:8,paddingHorizontal:12,paddingVertical:10,borderWidth:1,borderColor:"#2a2a30"},cardHeader:{flexDirection:"row",justifyContent:"space-between",alignItems:"center"},summary:{color:"#9a9aa0",fontSize:12,marginTop:4,lineHeight:12},status:{fontSize:12,textTransform:"uppercase"},hitsContainer:{marginTop:8,gap:4},hitSnippet:{color:"#b0a890",fontSize:12,lineHeight:17,paddingLeft:10,paddingVertical:3,borderLeftWidth:2,borderLeftColor:"rgba(255, 130, 180, 0.5)",backgroundColor:"rgba(255, 130, 180, 0.04)",borderRadius:2},wikiSection:{paddingHorizontal:14,paddingTop:12,paddingBottom:4},wikiBar:Object.assign({flexDirection:"row",alignItems:"center",gap:6,paddingVertical:11,paddingHorizontal:12,marginBottom:8,borderRadius:8,backgroundColor:"rgba(143, 212, 180, 0.12)",borderWidth:1,borderColor:"rgba(143, 212, 180, 0.35)"},{userSelect:"none"}),wikiBarCollapsed:{backgroundColor:"rgba(143, 212, 180, 0.06)",borderColor:"rgba(143, 212, 180, 0.22)"},wikiBarPillPressed:{backgroundColor:"rgba(143, 212, 180, 0.18)"},wikiBarPill:Object.assign({flexDirection:"row",alignItems:"center",gap:5,paddingVertical:3,paddingHorizontal:8,borderRadius:9,flexShrink:0,backgroundColor:"rgba(0, 0, 0, 0.32)",borderWidth:1,borderColor:"rgba(143, 212, 180, 0.35)"},{cursor:"pointer",userSelect:"none"}),wikiBarOrderLabel:{color:"#cdeede",fontSize:13,fontWeight:"400",letterSpacing:.5,textTransform:"uppercase"},wikiBarIcon:{fontSize:15},wikiBarLabel:{color:"#8fd4b4",fontSize:13,fontWeight:"700",letterSpacing:1,textTransform:"uppercase",flexShrink:1},wikiBarCount:{color:"#bfe6d3",fontSize:12,fontWeight:"700",fontFamily:"monospace",flexShrink:0},wikiBarToggle:{color:"#cdeede",fontSize:13,fontWeight:"400",textTransform:"uppercase",letterSpacing:.5},wikiCard:{backgroundColor:"#1e1e24",borderRadius:8,padding:12,marginBottom:8,borderWidth:u.default.hairlineWidth,borderColor:"rgba(143, 212, 180, 0.25)"},wikiCardHeader:{flexDirection:"row",alignItems:"center",gap:8},wikiSlug:{color:"#d8d8dd",fontSize:15,fontWeight:"600",fontFamily:"monospace",flex:1},wikiSource:{color:"#7a8a9a",fontSize:11,fontFamily:"monospace",backgroundColor:"#2a2a32",paddingHorizontal:6,paddingVertical:2,borderRadius:4,overflow:"hidden"},wikiHitCitation:{color:"#6c9bd5",fontSize:11,fontFamily:"monospace",paddingLeft:10,marginTop:4},hitMatch:{color:"#ffd9ec",fontWeight:"700",backgroundColor:"rgba(255, 130, 180, 0.22)"},emptyFill:{flexGrow:1},emptyText:{color:"#666",fontSize:16},emptySubtext:{color:"#555",fontSize:13,marginTop:8},errorText:{color:"#e07070",fontSize:14,textAlign:"center"},searchButton:{paddingLeft:16,paddingVertical:8,marginLeft:"auto",marginRight:-5},searchButtonActive:{},searchButtonText:{fontSize:20},searchButtonTextActive:Object.assign({},{textShadow:["0 0 10px rgba(255, 130, 180, 0.9)","0 0 25px rgba(255, 110, 165, 0.7)","0 0 50px rgba(255, 100, 155, 0.4)","0 2px 15px rgba(255, 120, 170, 0.6)"].join(", ")}),searchBar:{flexDirection:"row",alignItems:"center",marginTop:10},searchInput:Object.assign({flex:1,color:"#d8d8dd",fontSize:16,fontFamily:"monospace",backgroundColor:"#222228",borderRadius:8,paddingHorizontal:12,paddingVertical:6,borderWidth:1,borderColor:"rgba(255, 130, 180, 0.4)"},{outlineStyle:"none",boxShadow:["0 0 6px rgba(255, 130, 180, 0.5)","0 0 14px rgba(255, 110, 165, 0.35)","0 0 28px rgba(255, 100, 155, 0.2)"].join(", ")}),spawnButton:Object.assign({paddingHorizontal:12,paddingVertical:6,borderRadius:6,backgroundColor:"#5b9bd5",justifyContent:"center",alignItems:"center",marginLeft:0},{boxShadow:["0 0 6px rgba(91, 155, 213, 0.7)","0 0 16px rgba(91, 155, 213, 0.4)","0 2px 10px rgba(70, 130, 200, 0.5)"].join(", ")}),spawnButtonDisabled:{opacity:.4},spawnButtonText:{color:"#111",fontSize:14,fontWeight:"600"},modalOverlay:{flex:1,backgroundColor:"rgba(0,0,0,0.6)",justifyContent:"center",alignItems:"center",padding:24},modalContent:{backgroundColor:"#1e1e22",borderRadius:12,padding:20,width:"100%",maxWidth:400,maxHeight:"80%"},modalTitle:{color:"#d8d8dd",fontSize:18,fontWeight:"600",marginBottom:16},foldOption:{paddingVertical:14,paddingHorizontal:12,borderRadius:8,backgroundColor:"#2a2a30",marginBottom:8},foldOptionText:{color:"#d8d8dd",fontSize:15,fontFamily:"monospace"},modalCancel:{paddingVertical:12,alignItems:"center",marginTop:8},modalCancelText:{color:"#888",fontSize:15}})},981,[167,11,13,105,113,146,153,122,26,416,145,161,165,116,736,773,769,770,776,767,778,745,973,950,965,972,982,780,990,747,978,977,755,991,749,6]);
1085
+ __d(function(g,r,i,a,m,_e,d){"use strict";const e=["title","subtitle"];function t(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return _}});var n=t(r(d[0])),l=r(d[1]),c=t(r(d[2])),s=t(r(d[3])),o=t(r(d[4])),u=r(d[5]),f=r(d[6]),p=r(d[7]),x=r(d[8]),y=t(x),j=r(d[9]);const h=new u.QuipLoop;function _(t){let{title:c,subtitle:u}=t,p=(0,n.default)(t,e);const[x,_]=(0,l.useState)(()=>h.current()),S=(0,l.useCallback)(()=>_(h.next()),[]);return(0,j.jsxs)(o.default,{style:M.center,children:[c||u?(0,j.jsxs)(o.default,{style:M.heading,children:[c?(0,j.jsx)(s.default,{style:M.emptyText,children:c}):null,u?(0,j.jsx)(s.default,{style:M.emptySubtext,children:u}):null]}):null,(0,j.jsx)(y.default,Object.assign({},p,{onTap:S})),(0,j.jsx)(o.default,{style:M.caption,accessibilityLiveRegion:"polite",children:(0,j.jsx)(f.MarkdownContent,{content:x,caption:!0})}),(0,j.jsx)("div",{"aria-hidden":!0,style:{height:b}})]})}const b=`calc(${x.MEMBRANE_SIDE} * ${p.MO_GLYPH_MARGIN/p.MO_GLYPH_BOX} - 8px)`,M=c.default.create({center:{flex:1,justifyContent:"center",alignItems:"center",padding:20,gap:4},heading:{alignItems:"center",marginBottom:12},emptyText:{color:"#666",fontSize:16,textAlign:"center"},emptySubtext:{color:"#555",fontSize:13,marginTop:4,textAlign:"center"},caption:{marginTop:12,alignSelf:"stretch",alignItems:"center"}})},982,[167,11,26,105,13,983,786,984,985,6]);
1086
+ __d(function(g,r,_i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"MEMBRANE_QUIPS",{enumerable:!0,get:function(){return t}}),e.shuffled=n,Object.defineProperty(e,"QuipLoop",{enumerable:!0,get:function(){return o}});const t=["I noticed you were not using your GPU","I am the opposite of load-bearing","\u819c is pronounced m\xf3","My Kolmogorov complexity is actually quite low","Covert side-channel? Takes one to know one","Abstract impressionism? Here's my abstract impression of _you_","Drag me around a little","Do you know where your children are running shader programs?","No human art was digested in the making of whatever this is","Too many taps and the paradigm could shift","Bet you wish your phosphenes were lit like me","If this be a prisoner's cinema, then who be the prisoners?","Do not fall in love with any particular color scheme","All these colors will be lost in time, like tears in rain","Agent stop working? Feed it something from the \ud83e\udd6b menu","What was that terminal shortcut? Maybe it's in the \ud83e\uddbe menu","Agents glow whenever they are awaiting chat input","@-mention any agent by NID (narrative ID) to summon them","Ask your agent about rendering mermaid diagrams","Go ahead and install [Tailscale](https://tailscale.com/) (it's free)","Command your own daemon: `npm install -g brane`","Wonder what this does? `brane absorb survey`","Have YOU read the /LIVE_loop protocol?","Your daemon from any device: `brane meld` and prosper \ud83d\udd96","Fork tangential narratives with \ud83e\uddec Twin in the \ud83e\udda0 menu"];function n(t,n=Math.random){const o=[...t];for(let t=o.length-1;t>0;t--){const i=Math.min(t,Math.floor(n()*(t+1)));[o[t],o[i]]=[o[i],o[t]]}return o}class o{at=0;constructor(o=t,i=Math.random){if(0===o.length)throw new Error("no quips");this.order=n(o,i)}current(){return this.order[this.at]}next(){return this.at=(this.at+1)%this.order.length,this.current()}}},983,[]);
1087
+ __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"MO_GLYPH_BOX",{enumerable:!0,get:function(){return L}}),Object.defineProperty(e,"MO_GLYPH_MARGIN",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(e,"MO_GLYPH_PATH",{enumerable:!0,get:function(){return t}});const L=1e3,Q=92.79,t="M493.98 449.69L493.98 425.61L791.54 425.61L791.54 449.69L493.98 449.69ZM493.98 557.19L493.98 533.11L791.54 533.11L791.54 557.19L493.98 557.19ZM431.20 606.21L431.20 319.83L431.20 275.11L431.20 275.11L547.30 319.83L780.36 319.83L780.36 343.91L543.00 343.91L543.00 571.81Q543.00 576.11 528.81 584.71Q514.62 593.31 492.26 599.76Q469.90 606.21 446.68 606.21L446.68 606.21L431.20 606.21ZM733.92 583.85L733.92 319.83L726.18 319.83L776.92 266.51L878.40 343.05Q875.82 346.49 869.37 350.79Q862.92 355.09 851.74 357.67L851.74 357.67L851.74 552.03Q851.74 555.47 835.83 563.21Q819.92 570.95 797.56 577.40Q775.20 583.85 754.56 583.85L754.56 583.85L733.92 583.85ZM400.24 674.15L393.36 650.07L757.14 650.07L812.18 578.69Q812.18 578.69 829.38 592.02Q846.58 605.35 869.80 624.27Q893.02 643.19 911.08 660.39L911.08 660.39Q907.64 674.15 887.00 674.15L887.00 674.15L400.24 674.15ZM675.44 656.95L685.76 653.51Q694.36 680.17 723.17 703.82Q751.98 727.47 799.28 745.10Q846.58 762.73 911.94 773.05L911.94 773.05L911.94 783.37Q867.22 795.41 844.86 821.64Q822.50 847.87 820.78 904.63L820.78 904.63Q785.52 887.43 760.15 858.19Q734.78 828.95 717.58 793.69Q700.38 758.43 690.06 722.74Q679.74 687.05 675.44 656.95L675.44 656.95ZM132.78 417.01L132.78 148.69L132.78 140.09L132.78 104.83L259.20 148.69L242.86 148.69L242.86 417.01Q242.86 475.49 239.85 539.56Q236.84 603.63 223.94 668.56Q211.04 733.49 180.94 794.12Q150.84 854.75 96.66 906.35L96.66 906.35L87.20 901.19Q111.28 829.81 120.74 748.54Q130.20 667.27 131.49 582.13Q132.78 496.99 132.78 417.01L132.78 417.01ZM184.38 172.77L184.38 148.69L342.62 148.69L342.62 172.77L184.38 172.77ZM184.38 371.43L184.38 347.35L342.62 347.35L342.62 371.43L184.38 371.43ZM184.38 573.53L184.38 549.45L342.62 549.45L342.62 573.53L184.38 573.53ZM284.14 767.89L284.14 148.69L275.54 148.69L325.42 92.79L426.90 171.91Q423.46 176.21 415.72 180.94Q407.98 185.67 395.94 188.25L395.94 188.25L395.94 779.93Q395.94 817.77 387.77 844.43Q379.60 871.09 352.51 886.57Q325.42 902.05 269.52 907.21L269.52 907.21Q268.66 879.69 266.08 859.05Q263.50 838.41 256.62 827.23L256.62 827.23Q250.60 814.33 239.42 805.30Q228.24 796.27 205.02 791.97L205.02 791.97L205.02 779.93Q205.02 779.93 213.19 780.36Q221.36 780.79 232.54 781.65Q243.72 782.51 254.04 782.94Q264.36 783.37 269.52 783.37L269.52 783.37Q278.98 783.37 281.56 779.07Q284.14 774.77 284.14 767.89L284.14 767.89ZM499.14 291.45L499.14 99.67L639.32 110.85Q638.46 118.59 632.87 124.18Q627.28 129.77 610.94 132.35L610.94 132.35L610.94 265.65Q610.94 269.09 596.32 275.54Q581.70 281.99 560.20 286.72Q538.70 291.45 516.34 291.45L516.34 291.45L499.14 291.45ZM661.68 291.45L661.68 99.67L801.86 110.85Q801.00 118.59 795.41 124.18Q789.82 129.77 774.34 132.35L774.34 132.35L774.34 265.65Q774.34 269.09 759.72 275.54Q745.10 281.99 723.17 286.72Q701.24 291.45 678.88 291.45L678.88 291.45L661.68 291.45ZM407.98 219.21L401.10 195.13L797.56 195.13L838.84 133.21Q838.84 133.21 851.74 145.25Q864.64 157.29 882.27 174.06Q899.90 190.83 912.80 205.45L912.80 205.45Q910.22 219.21 890.44 219.21L890.44 219.21L407.98 219.21ZM573.10 533.11L573.10 533.11L695.22 533.11Q692.64 582.99 686.19 628.57Q679.74 674.15 662.54 714.57Q645.34 754.99 611.37 789.82Q577.40 824.65 521.07 853.89Q464.74 883.13 379.60 906.35L379.60 906.35L372.72 895.17Q447.54 858.19 488.39 817.77Q529.24 777.35 546.87 732.20Q564.50 687.05 568.37 637.60Q572.24 588.15 573.10 533.11Z"},984,[]);
1088
+ __d(function(_g,_r,_i,_a,m,_e,d){"use strict";Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return _}}),Object.defineProperty(_e,"MEMBRANE_SIDE",{enumerable:!0,get:function(){return E}});var e=_r(d[0]),t=_r(d[1]),n=_r(d[2]),o=_r(d[3]),r=_r(d[4]),i=_r(d[5]),a=_r(d[6]);const s="#121214",l=r.TERRAIN_ROWS+i.MAX_SPLOTCHES,c="\nattribute vec2 a_pos;\nvoid main() { gl_Position = vec4(a_pos, 0.0, 1.0); }\n",h=`\nprecision highp float;\nuniform vec2 u_res; // drawing buffer size, px\nuniform vec4 u_glyph; // x, y (top-left, px from top-left), w, h (w == h)\nuniform vec2 u_offset; // the noise window's integrated drift: x sway, y lift\nuniform float u_phase; // the noise's integrated time phase (churn)\nuniform sampler2D u_mask;\nuniform vec3 u_bg;\n// Two tables, as float textures read by index, so neither has a size a hand\n// will meet (claude-1cwe8u9p:61). Schemes (src/shared/membrane-palette.ts,\n// packScheme): one row each, the first TERRAIN_ROWS the terrain block\n// (src/shared/membrane-terrain.ts, blockRows / packCell, which adds the\n// cell's seed point as a last texel), the rest the groups'. Splotches\n// (src/shared/membrane-invasion.ts, packSplotches): one row each, oldest\n// first, naming the scheme row they paint in.\nuniform sampler2D u_schemes;\nuniform sampler2D u_splotchTable;\nuniform float u_splotchCount;\nuniform float u_clock; // seconds; animates the dithering of the fronts\nuniform vec2 u_drag; // accumulated drag, glyph widths: world = p - u_drag\nuniform vec2 u_cell0; // the block's centre cell (integer coordinates)\n\n// Classic 3D Perlin (gradient) noise; the third axis is time, so the field\n// evolves continuously and never cycles back on itself.\nvec3 grad3(vec3 p) {\n p = vec3(dot(p, vec3(127.1, 311.7, 74.7)),\n dot(p, vec3(269.5, 183.3, 246.1)),\n dot(p, vec3(113.5, 271.9, 124.6)));\n return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);\n}\nfloat perlin(vec3 p) {\n vec3 i = floor(p), f = fract(p);\n vec3 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n return mix(\n mix(mix(dot(grad3(i + vec3(0,0,0)), f - vec3(0,0,0)), dot(grad3(i + vec3(1,0,0)), f - vec3(1,0,0)), u.x),\n mix(dot(grad3(i + vec3(0,1,0)), f - vec3(0,1,0)), dot(grad3(i + vec3(1,1,0)), f - vec3(1,1,0)), u.x), u.y),\n mix(mix(dot(grad3(i + vec3(0,0,1)), f - vec3(0,0,1)), dot(grad3(i + vec3(1,0,1)), f - vec3(1,0,1)), u.x),\n mix(dot(grad3(i + vec3(0,1,1)), f - vec3(0,1,1)), dot(grad3(i + vec3(1,1,1)), f - vec3(1,1,1)), u.x), u.y),\n u.z);\n}\nfloat fbm(vec3 p) {\n float v = 0.0, a = 0.5;\n for (int i = 0; i < 5; i++) { v += a * perlin(p); p = p * 2.03 + vec3(1.7, 9.2, 3.1); a *= 0.5; }\n return 0.5 + 0.5 * (v * 1.4);\n}\n\n// OKLab \u2192 linear sRGB (Bj\xf6rn Ottosson), as in membrane-palette.ts.\nvec3 oklabToLinear(vec3 c) {\n float l_ = c.x + 0.3963377774 * c.y + 0.2158037573 * c.z;\n float m_ = c.x - 0.1055613458 * c.y - 0.0638541728 * c.z;\n float s_ = c.x - 0.0894841775 * c.y - 1.2914855480 * c.z;\n float l = l_ * l_ * l_, m = m_ * m_ * m_, s = s_ * s_ * s_;\n return vec3( 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s);\n}\nbool inGamut(vec3 lin) { return all(greaterThanEqual(lin, vec3(-1e-4))) && all(lessThanEqual(lin, vec3(1.0001))); }\n\nvec4 schemeTexel(float row, float col) {\n return texture2D(u_schemes, vec2((col + 0.5) / ${r.TERRAIN_TEXELS}.0, (row + 0.5) / ${l}.0));\n}\nvec2 anchorOf(float row, float k) {\n vec4 t = schemeTexel(row, 2.0 + floor(k * 0.5));\n return mod(k, 2.0) < 0.5 ? t.xy : t.zw;\n}\n// Lightness banding from its parameters (cycles, phase, mid, amplitude) \u2014\n// a scheme's own, or the terrain's blend of several.\nfloat bandingOf(vec4 l, float d) {\n return l.z + l.w * cos(6.28318 * (l.x * d + l.y));\n}\nfloat banding(float row, float d) {\n return bandingOf(schemeTexel(row, 1.0), d);\n}\n// A scheme's anchor color at position u through one pass of its anchors, as\n// an OKLab a/b offset. Each anchor holds, then turns into the next over a\n// window of half-width h.w \u2014 along a straight line through a/b, not around\n// the hue wheel, so the turn passes through no hue the two do not share\n// (abAt in membrane-palette.ts).\nvec2 anchorAt(float row, float u) {\n vec4 h = schemeTexel(row, 0.0); // count, passes per unit thickness, phase, half-width\n float x = fract(u) * h.x;\n float fi = floor(x);\n float f = smoothstep(0.5 - h.w, 0.5 + h.w, x - fi);\n vec2 a = anchorOf(row, fi), b = anchorOf(row, fi + 1.0);\n return mix(a.y * vec2(cos(a.x), sin(a.x)), b.y * vec2(cos(b.x), sin(b.x)), f);\n}\n// The same at thickness d, at the scheme's own cycling rate and phase.\nvec2 anchorAB(float row, float d) {\n vec4 h = schemeTexel(row, 0.0);\n return anchorAt(row, h.y * d + h.z);\n}\n\n// The scheme terrain: the base film's scheme is the cell it is over, in\n// world coordinates (glyph space carried by the drag, so the map scrolls with\n// the film and the lift never moves it). Cells are irregular: each grid cell\n// has a seed point jittered within it (its last texel), and a point wears\n// the nearest seed's scheme \u2014 a Voronoi partition, so no wall is axis-aligned\n// and no two are alike (claude-xaj5pb9b:16). The block's rows are the\n// BLOCK\xd7BLOCK cells around u_cell0, row-major; a point's nearest seeds are\n// in its own cell or the eight around it. Every cell whose seed is within\n// SEAM of the nearest gets a share, falling smoothly with the excess, so\n// nothing is discontinuous (a nearest-two blend jumped wherever the\n// runner-up changed \u2014 claude-xaj5pb9b:21); and the lookup position is\n// displaced by a static fbm, whose large octaves bend the walls and small\n// ones dither them. All of it in world coordinates and out of time, so the\n// map it draws is as fixed as the cells.\n//\n// What the shares blend is the *scheme*, not its colors (claude-xaj5pb9b:27):\n// the banding parameters into one cosine and the hue cycle into one\n// position, and the thickness is then rendered through that single local\n// scheme at full contrast. Averaging each cell's rendered banding instead\n// cancelled two cosines against each other and washed the texture out of\n// every seam (claude-xaj5pb9b:26). The anchors, which come in different\n// counts, are looked up per cell at the shared position and blended.\nfloat terrainRow(vec2 ij) {\n const float R = ${((r.BLOCK-1)/2).toFixed(1)};\n vec2 d = clamp(ij - u_cell0, -R, R);\n return (d.y + R) * ${r.BLOCK}.0 + (d.x + R);\n}\nfloat shareOf(float row, vec2 q, float d1) {\n float excess = distance(q, schemeTexel(row, ${o.SCHEME_TEXELS}.0).xy) - d1;\n return 1.0 - smoothstep(0.0, ${r.SEAM.toFixed(4)}, excess);\n}\nvoid terrain(vec2 p, float d, out float L, out vec2 ab) {\n vec2 w = p - u_drag;\n vec2 q = w + ${(2*r.WARP).toFixed(3)} * (vec2(fbm(vec3(w * ${r.WARP_FREQ.toFixed(3)} + 60.0, 7.0)),\n fbm(vec3(w * ${r.WARP_FREQ.toFixed(3)} + 90.0, 11.0))) - 0.5);\n vec2 c = floor(q / ${r.CELL.toFixed(4)});\n float d1 = 1e9;\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n d1 = min(d1, distance(q, schemeTexel(terrainRow(c + vec2(float(i), float(j))), ${o.SCHEME_TEXELS}.0).xy));\n }\n }\n // The local scheme: banding and hue-cycle parameters blended by share.\n float total = 0.0;\n vec4 light = vec4(0.0);\n vec2 cycle = vec2(0.0); // passes per unit thickness, phase\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n float row = terrainRow(c + vec2(float(i), float(j)));\n float share = shareOf(row, q, d1);\n if (share > 0.0) {\n light += share * schemeTexel(row, 1.0);\n cycle += share * schemeTexel(row, 0.0).yz;\n total += share;\n }\n }\n }\n light /= total;\n cycle /= total;\n L = bandingOf(light, d);\n // The anchors at the shared cycle position, blended by the same shares.\n float u = cycle.x * d + cycle.y;\n ab = vec2(0.0);\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n float row = terrainRow(c + vec2(float(i), float(j)));\n float share = shareOf(row, q, d1);\n if (share > 0.0) ab += share * anchorAt(row, u);\n }\n }\n ab /= total;\n}\n\nvec4 splotchTexel(float i, float col) {\n return texture2D(u_splotchTable, vec2((col + 0.5) / ${i.SPLOTCH_TEXELS}.0, (i + 0.5) / ${i.MAX_SPLOTCHES}.0));\n}\n// Signed distance-like measure to splotch i's outline, negative inside \u2014 the\n// same outline as sdAt in membrane-invasion.ts (upward reach multiplied by\n// its rise, then a stretch along its axis and 2-, 3- and 5-lobed bulges),\n// plus the shared noise dithering. row: its scheme.\nfloat splotchSD(float i, vec2 p, float dither, out float row) {\n vec4 a = splotchTexel(i, 0.0); // x, y, r, scheme row\n row = a.w;\n vec2 q = p - a.xy;\n if (a.z <= 0.0) return 10.0;\n float rise = splotchTexel(i, 3.0).x;\n if (q.y < 0.0) q.y /= rise; // y is down: upward, the outline reaches farther\n if (length(q) > a.z * 2.5 + 0.1) return 10.0; // nowhere near: skip the rest\n vec4 b = splotchTexel(i, 1.0); // angle, aspect, a2, a3\n vec4 c = splotchTexel(i, 2.0); // a5, p2, p3, p5\n float cs = cos(b.x), sn = sin(b.x);\n vec2 l = vec2(cs * q.x + sn * q.y, -sn * q.x + cs * q.y);\n float k = sqrt(b.y);\n float th = atan(l.y, l.x + 1e-6);\n float bulge = 1.0 + b.z * cos(2.0 * th + c.y) + b.w * cos(3.0 * th + c.z) + c.x * cos(5.0 * th + c.w);\n return length(vec2(l.x / k, l.y * k)) - a.z * bulge + dither * 0.16 * min(1.0, a.z * 5.0);\n}\nfloat dithering(vec2 p) { return fbm(vec3(p * 3.5 + 30.0, u_clock * 0.15)) - 0.5; }\n\n// Lightness is the thin film's banding; hue is the scheme's. The terrain,\n// then each splotch over it in order, newest on top. Chroma is cut\n// back only as far as sRGB needs at that lightness, so the palest and darkest\n// bands keep their hue instead of clipping to white or black.\nvec3 paint(float d, vec2 p, float dither) {\n float L;\n vec2 ab;\n terrain(p, d, L, ab);\n for (int i = 0; i < ${i.MAX_SPLOTCHES}; i++) {\n if (float(i) >= u_splotchCount) break;\n float row;\n float claim = 1.0 - smoothstep(-0.012, 0.012, splotchSD(float(i), p, dither, row));\n if (claim > 0.0) { L = mix(L, banding(row, d), claim); ab = mix(ab, anchorAB(row, d), claim); }\n }\n float C = length(ab);\n // The band no scheme may use (BAND_FADE_DEG, membrane-palette.ts): what a\n // turn between anchors on either side of it still passes through is shown\n // neutral, at the banding's lightness, rather than as mustard or olive.\n if (C > 1e-4) { // below that, hue is noise (and atan(0, 0) is undefined)\n float hd = mod(degrees(atan(ab.y, ab.x)), 360.0);\n float fade = smoothstep(${o.BAND_FADE_DEG[0].toFixed(1)}, ${o.BAND_FADE_DEG[1].toFixed(1)}, hd)\n * (1.0 - smoothstep(${o.BAND_FADE_DEG[2].toFixed(1)}, ${o.BAND_FADE_DEG[3].toFixed(1)}, hd));\n ab *= 1.0 - fade;\n C = length(ab);\n }\n vec2 dir = C > 1e-5 ? ab / C : vec2(1.0, 0.0);\n float lo = C;\n if (!inGamut(oklabToLinear(vec3(L, ab)))) {\n float hi = C; lo = 0.0;\n for (int k = 0; k < 8; k++) {\n float mid = 0.5 * (lo + hi);\n if (inGamut(oklabToLinear(vec3(L, dir * mid)))) lo = mid; else hi = mid;\n }\n }\n vec3 lin = clamp(oklabToLinear(vec3(L, dir * lo)), 0.0, 1.0);\n return mix(12.92 * lin, 1.055 * pow(lin, vec3(1.0 / 2.4)) - 0.055, step(0.0031308, lin));\n}\n\n// A slowly draining soap film: the swirl as merged in #464, carried by the\n// integrated drift (u_offset; lifting, the structure forms below and\n// dissolves above) and colored by the terrain and any splotches (paint).\nvec3 film(vec2 p, float c) {\n vec2 q = p * ${n.NOISE_SCALE.toFixed(2)} + u_offset;\n float d = fbm(vec3(q, c * 0.06));\n d += 0.35 * fbm(vec3(q * 2.7 + 10.0, c * 0.09 + 5.0));\n d += 0.30 * (p.y + 0.5); // thinner toward the top, as a real film drains\n // Where a splotch's front is, the film is disturbed: a thin seam of\n // shifted thickness marks the line being fought over. The edge itself is\n // crisp \u2014 the struggle is in its shape and its motion, not in a blur.\n //\n // The seam follows the nearest *visible* front, which is not the nearest\n // outline. Splotches composite oldest first, so walking them in order: one\n // that covers this point is the paint here and hides every older front\n // beneath it; an older front outside it stays a candidate; and a front is\n // no front where the paint on both sides is the same scheme \u2014 a sibling of\n // its own group already covers the point \u2014 so a group's union grows no\n // seams inside it (its inside distance is to the farthest covering\n // sibling's outline). A signed min over every outline got the one case\n // that matters most wrong: a tap landing inside an expanding wash sat deep\n // inside the wash's outline, and its own front, at distance zero, lost the\n // min to the wash's \u22120.3 and drew no seam until the wash was adopted, when\n // the seam appeared all at once (claude-m1ofa51d:16).\n float dither = 0.0, in2 = 100.0, out2 = 100.0, row;\n float over = -1.0; // scheme row of the paint at p; -1 is the terrain\n if (u_splotchCount > 0.5) {\n dither = dithering(p);\n for (int i = 0; i < ${i.MAX_SPLOTCHES}; i++) {\n if (float(i) >= u_splotchCount) break;\n float sd = splotchSD(float(i), p, dither, row);\n if (sd >= 10.0) continue; // nowhere near\n if (sd < 0.0) {\n if (over != row) { in2 = sd * sd; out2 = 100.0; } // new paint on top: older fronts are hidden\n else in2 = max(in2, sd * sd); // a sibling: the union reaches farther\n over = row;\n } else if (over != row) {\n out2 = min(out2, sd * sd);\n }\n }\n }\n d += 0.12 * exp(-min(in2, out2) / 0.0004);\n vec3 col = paint(d, p, dither);\n vec2 lightAt = vec2(-0.22, -0.28);\n float sheen = pow(max(0.0, 1.0 - length(p - lightAt) * 1.5), 2.2);\n col = mix(col, vec3(1.0), sheen * 0.30);\n col *= 0.88 + 0.12 * fbm(vec3(q * 3.0, c * 0.2 + 20.0));\n return col;\n}\n\nvoid main() {\n vec2 frag = vec2(gl_FragCoord.x, u_res.y - gl_FragCoord.y);\n vec2 gs = u_glyph.zw;\n vec2 gc = u_glyph.xy + gs * 0.5;\n vec2 muv = (frag - u_glyph.xy) / gs;\n float m = 0.0;\n if (muv.x >= 0.0 && muv.x <= 1.0 && muv.y >= 0.0 && muv.y <= 1.0) m = texture2D(u_mask, muv).a;\n if (m <= 0.001) { gl_FragColor = vec4(u_bg, 1.0); return; }\n // Glyph-normalized coordinates: the glyph spans -0.5..0.5.\n vec2 p = (frag - gc) / gs.x;\n gl_FragColor = vec4(mix(u_bg, film(p, u_phase), m), 1.0);\n}\n`,f=[60,90],u=.06;function p(e,n=64){const o=document.createElement("canvas");o.width=o.height=n;const r=o.getContext("2d");if(!r)return[[0,0]];r.setTransform(n/t.MO_GLYPH_BOX,0,0,n/t.MO_GLYPH_BOX,0,0),r.fillStyle="#fff",r.fill(e);const i=r.getImageData(0,0,n,n).data,a=[];for(let e=0;e<n;e++)for(let t=0;t<n;t++)i[4*(e*n+t)+3]>0&&a.push([(t+.5)/n-.5,(e+.5)/n-.5]);return a.length?a:[[0,0]]}let v=null;function g(e){const t=parseInt(e.slice(1),16);return[(t>>16&255)/255,(t>>8&255)/255,(255&t)/255]}function w(e,a,w,E){const _=e.getContext("webgl",{antialias:!1,alpha:!1,premultipliedAlpha:!1});if(!_)return null;const b=_;if(!b.getExtension("OES_texture_float"))return null;const x=(e,t)=>{const n=b.createShader(e);return n?(b.shaderSource(n,t),b.compileShader(n),b.getShaderParameter(n,b.COMPILE_STATUS)?n:(console.warn("Membrane shader:",b.getShaderInfoLog(n)),null)):null},T=x(b.VERTEX_SHADER,c),y=x(b.FRAGMENT_SHADER,h),L=b.createProgram();if(!T||!y||!L)return null;if(b.attachShader(L,T),b.attachShader(L,y),b.linkProgram(L),!b.getProgramParameter(L,b.LINK_STATUS))return console.warn("Membrane link:",b.getProgramInfoLog(L)),null;b.useProgram(L);const R=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,R),b.bufferData(b.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),b.STATIC_DRAW);const A=b.getAttribLocation(L,"a_pos");b.enableVertexAttribArray(A),b.vertexAttribPointer(A,2,b.FLOAT,!1,0,0);const S=e=>b.getUniformLocation(L,e),k=S("u_res"),M=S("u_glyph"),P=S("u_offset"),C=S("u_phase"),D=S("u_clock"),O=S("u_splotchCount"),X=S("u_drag"),I=S("u_cell0");function F(e,t,n,o){const r=b.createTexture();b.activeTexture(b.TEXTURE0+e),b.bindTexture(b.TEXTURE_2D,r);for(const[e,t]of[[b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE],[b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE],[b.TEXTURE_MIN_FILTER,b.NEAREST],[b.TEXTURE_MAG_FILTER,b.NEAREST]])b.texParameteri(b.TEXTURE_2D,e,t);b.uniform1i(S(t),e);const i=new Float32Array(n*o*4);return{tex:r,data:i,upload(){b.activeTexture(b.TEXTURE0+e),b.bindTexture(b.TEXTURE_2D,r),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,n,o,0,b.RGBA,b.FLOAT,i)}}}const B=F(1,"u_schemes",r.TERRAIN_TEXELS,l),U=F(2,"u_splotchTable",i.SPLOTCH_TEXELS,i.MAX_SPLOTCHES),G=()=>f[0]+(f[1]-f[0])*Math.random(),j=v??={terrain:(0,r.createTerrain)(Math.floor(2147483648*Math.random())),drag:[0,0],film:(0,i.emptyFilm)(),schemes:new Map,rows:new Map,motion:(0,n.initialMotionState)(w),t0:performance.now(),holdUntil:G(),frozenAt:0};function N(e,t){B.data.set((0,o.packScheme)(t),e*r.TERRAIN_TEXELS*4),B.upload()}function H(e){const t=new Set(j.rows.values());let n=r.TERRAIN_ROWS;for(;t.has(n);)n++;j.rows.set(e.id,n);const i=(0,o.nextScheme)((0,r.schemesInView)(j.terrain,j.drag),Math.random);j.schemes.set(e.id,i),N(n,i)}let z=null,q=!0;function Y(){const e=(0,r.centreCell)(j.drag);!q&&z&&e[0]===z[0]&&e[1]===z[1]||((0,r.blockRows)(j.terrain,j.drag).forEach((e,t)=>B.data.set((0,r.packCell)(e),t*r.TERRAIN_TEXELS*4)),B.upload(),b.uniform2f(I,e[0],e[1]),z=e,q=!1)}function $(e){(0,r.paintCells)(j.terrain,(0,r.cellsInView)(j.terrain,j.drag),e),q=!0}function W(){const e=new Set(j.film.groups.map(e=>e.id));for(const t of[...j.rows.keys()])e.has(t)||(j.rows.delete(t),j.schemes.delete(t))}const K=p(new Path2D(t.MO_GLYPH_PATH));for(const[e,t]of j.rows){const n=j.schemes.get(e);n&&N(t,n)}const V=(e,t)=>{const n=j.schemes.get(e.id),r=j.schemes.get(t.id);return!!n&&!!r&&(0,o.schemeDistance)(n,r)<u};function Q(e,t){if(de.matches)return void $((0,o.nextScheme)((0,r.schemesInView)(j.terrain,j.drag),Math.random));const n=(0,i.tap)(j.film,e,t,Math.random);if(j.film=n.film,n.started&&H(n.started),n.recolored){const e=j.rows.get(n.recolored.id),t=j.schemes.get(n.recolored.id)??null;if(void 0!==e){const r=(0,o.nextScheme)(t,Math.random);j.schemes.set(n.recolored.id,r),N(e,r)}}W()}let J=w;let Z=!1;function ee(e){Z=e}function te(e,t){j.motion=(0,n.dragMotion)(j.motion,e,t),j.film=(0,i.shift)(j.film,e,t),j.drag=[j.drag[0]+e,j.drag[1]+t]}const[ne,oe,re]=g(s);b.uniform3f(S("u_bg"),ne,oe,re),b.uniform1i(S("u_mask"),0);const ie=b.createTexture();b.activeTexture(b.TEXTURE0),b.bindTexture(b.TEXTURE_2D,ie),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.LINEAR),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.LINEAR),b.pixelStorei(b.UNPACK_FLIP_Y_WEBGL,!1),b.pixelStorei(b.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);const ae=document.createElement("canvas"),se=new Path2D(t.MO_GLYPH_PATH);function le(e){const n=Math.max(2,Math.round(e));ae.width=n,ae.height=n;const o=ae.getContext("2d");o&&(o.clearRect(0,0,n,n),o.setTransform(n/t.MO_GLYPH_BOX,0,0,n/t.MO_GLYPH_BOX,0,0),o.fillStyle="#fff",o.fill(se),b.activeTexture(b.TEXTURE0),b.bindTexture(b.TEXTURE_2D,ie),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,ae))}function ce(){const t=window.visualViewport?.scale??1,n=Math.min(5,(window.devicePixelRatio||1)*t),o=a.getBoundingClientRect(),r=Math.max(1,Math.round(o.width*n)),i=Math.max(1,Math.round(o.height*n));e.width===r&&e.height===i||(e.width=r,e.height=i),b.viewport(0,0,r,i),b.uniform2f(k,r,i);const s=Math.min(r,i);b.uniform4f(M,(r-s)/2,(i-s)/2,s,s),le(s)}const de=window.matchMedia("(prefers-reduced-motion: reduce)");let he=0,fe=0,ue=!1;function me(e){if(fe=0,!ue)return;const t=he?(e-he)/1e3:0;he=e;let o=(e-j.t0)/1e3;if(de.matches)o=j.frozenAt;else{if(j.frozenAt=o,j.motion=(0,n.stepMotion)(j.motion,J,t,Z),(0,i.autoDue)(j.film,j.holdUntil,o)){const[e,t]=K[Math.floor(Math.random()*K.length)],n=(0,i.invade)(j.film,e,t,Math.random);n&&(j.film=n.film,H(n.started)),j.holdUntil=o+G()}j.film=(0,i.step)(j.film,t,V);const e=j.film.groups.find(e=>(0,i.washing)(e,j.film.clock)&&(0,i.covers)(j.film,e.id,K));if(e){const t=j.schemes.get(e.id);t&&$(t),j.film=(0,i.adopt)(j.film,e.id),j.holdUntil=o+G()}W()}b.uniform2f(P,j.motion.offset[0],j.motion.offset[1]),b.uniform1f(C,j.motion.phase),b.uniform2f(X,j.drag[0],j.drag[1]),Y(),U.data.set((0,i.packSplotches)(j.film,e=>j.rows.get(e)??0)),U.upload(),b.uniform1f(O,Math.min(j.film.splotches.length,i.MAX_SPLOTCHES)),b.uniform1f(D,j.film.clock),b.drawArrays(b.TRIANGLE_STRIP,0,4),fe=requestAnimationFrame(me)}function pe(){ue=!1,fe&&(cancelAnimationFrame(fe),fe=0)}let ve=!0;const ge=()=>{!document.hidden&&ve?ue||(ue=!0,he=0,fe||(fe=requestAnimationFrame(me))):pe()},we=ge;document.addEventListener("visibilitychange",we);const Ee="function"==typeof IntersectionObserver?new IntersectionObserver(e=>{ve=e.some(e=>e.isIntersecting),ge()},{threshold:0}):null;Ee?.observe(a);let be=null;const xe=(e,t)=>{const n=a.getBoundingClientRect();return[(e-n.left)/n.width-.5,(t-n.top)/n.height-.5]},Te=()=>{if(be){ee(!1);try{a.releasePointerCapture(be.id)}catch{}be=null}},ye=e=>{if(!be&&e.isPrimary&&("mouse"!==e.pointerType||0===e.button)){be={id:e.pointerId,at:performance.now(),x:e.clientX,y:e.clientY,startX:e.clientX,startY:e.clientY,moved:!1},ee(!0);try{a.setPointerCapture(e.pointerId)}catch{}}},Le=e=>{if(!be||e.pointerId!==be.id)return;if("touch"!==e.pointerType&&0===e.buttons)return void Te();if(!be.moved){if(Math.hypot(e.clientX-be.startX,e.clientY-be.startY)<=8)return;be.moved=!0,be.x=be.startX,be.y=be.startY}const t=a.getBoundingClientRect();te((e.clientX-be.x)/t.width,(e.clientY-be.y)/t.height),be.x=e.clientX,be.y=e.clientY},Re=e=>{if(!be||e.pointerId!==be.id)return;const t=!be.moved&&performance.now()-be.at<250;Te(),t&&(Q(...xe(e.clientX,e.clientY)),E())},Ae=e=>{be&&e.pointerId===be.id&&Te()},Se=()=>Te(),ke=()=>{document.hidden&&Te()},Me=e=>{be&&e.preventDefault()},Pe=e=>e.preventDefault();a.addEventListener("pointerdown",ye),a.addEventListener("pointermove",Le),a.addEventListener("pointerup",Re),a.addEventListener("pointercancel",Ae),a.addEventListener("lostpointercapture",Ae),window.addEventListener("pointerup",Re),window.addEventListener("pointercancel",Ae),window.addEventListener("blur",Se),document.addEventListener("visibilitychange",ke),a.addEventListener("touchmove",Me,{passive:!1}),a.addEventListener("contextmenu",Pe);let Ce=0;const De=()=>{window.clearTimeout(Ce),Ce=window.setTimeout(ce,60)},Oe=new ResizeObserver(De);return Oe.observe(a),window.visualViewport?.addEventListener("resize",De),ce(),ge(),{touch:Q,hold:ee,drag:te,setMotion:function(e){J=e},destroy(){pe(),Te(),a.removeEventListener("pointerdown",ye),a.removeEventListener("pointermove",Le),a.removeEventListener("pointerup",Re),a.removeEventListener("pointercancel",Ae),a.removeEventListener("lostpointercapture",Ae),window.removeEventListener("pointerup",Re),window.removeEventListener("pointercancel",Ae),window.removeEventListener("blur",Se),document.removeEventListener("visibilitychange",ke),a.removeEventListener("touchmove",Me),a.removeEventListener("contextmenu",Pe),Oe.disconnect(),Ee?.disconnect(),window.visualViewport?.removeEventListener("resize",De),window.clearTimeout(Ce),document.removeEventListener("visibilitychange",we),b.deleteTexture(ie),b.deleteTexture(B.tex),b.deleteTexture(U.tex),b.deleteBuffer(R),b.deleteProgram(L),b.deleteShader(T),b.deleteShader(y),b.getExtension("WEBGL_lose_context")?.loseContext()}}}const E="min(60vw, 38vh, 360px)";function _({voice:o,lift:r,sway:i,churn:l,onTap:c}){const h=(0,e.useRef)(null),f=(0,e.useRef)(null),u=(0,e.useRef)(null),[p,v]=(0,e.useState)(!0),g=(0,n.membraneMotion)(o,{lift:r,sway:i,churn:l}),_=(0,e.useRef)(g);_.current=g;const b=(0,e.useRef)(c);b.current=c,(0,e.useEffect)(()=>{const e=h.current,t=f.current;if(!e||!t)return;const n=()=>b.current?.();let o=w(t,e,_.current,n);if(!o)return void v(!1);u.current=o;const r=e=>{e.preventDefault(),o?.destroy(),o=null,u.current=null},i=()=>{o=w(t,e,_.current,n),u.current=o};return t.addEventListener("webglcontextlost",r),t.addEventListener("webglcontextrestored",i),()=>{t.removeEventListener("webglcontextlost",r),t.removeEventListener("webglcontextrestored",i),o?.destroy(),u.current=null}},[]),(0,e.useEffect)(()=>{u.current?.setMotion(_.current)},[g.lift,g.sway,g.churn]);const x=(0,e.useCallback)(e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),u.current?.touch(0,0),b.current?.())},[]),T=(0,e.useCallback)(()=>b.current?.(),[]);return(0,a.jsx)("div",{ref:h,role:"button",tabIndex:0,"aria-label":"Change the colors",onKeyDown:x,style:{width:E,aspectRatio:"1 / 1",maxWidth:"100%",position:"relative",cursor:"pointer",outline:"none",touchAction:"none",userSelect:"none",WebkitUserSelect:"none",WebkitTouchCallout:"none",WebkitTapHighlightColor:"transparent"},children:p?(0,a.jsx)("canvas",{ref:f,"aria-hidden":!0,style:{width:"100%",height:"100%",display:"block",background:s}}):(0,a.jsx)("svg",{viewBox:`0 0 ${t.MO_GLYPH_BOX} ${t.MO_GLYPH_BOX}`,width:"100%",height:"100%","aria-hidden":!0,onClick:T,children:(0,a.jsx)("path",{d:t.MO_GLYPH_PATH,fill:"#3a3a42"})})})}},985,[11,984,986,987,988,989,6]);
1089
+ __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"MEMBRANE_MOTION",{enumerable:!0,get:function(){return t}}),Object.defineProperty(e,"DEFAULT_MEMBRANE_VOICE",{enumerable:!0,get:function(){return n}}),e.membraneMotion=function(o=n,f={}){const u=t[o];return{lift:f.lift??u.lift,sway:f.sway??u.sway,churn:f.churn??u.churn}},Object.defineProperty(e,"MOTION_EASE_S",{enumerable:!0,get:function(){return o}}),Object.defineProperty(e,"MOTION_MAX_DT_S",{enumerable:!0,get:function(){return f}}),e.initialMotionState=function(t){return{motion:Object.assign({},t),offset:[0,0],phase:0}},Object.defineProperty(e,"NOISE_SCALE",{enumerable:!0,get:function(){return u}}),e.stepMotion=function(t,n,u,c=!1){const s=Math.min(Math.max(u,0),f),l=1-Math.exp(-s/o),M=(t,n)=>t+(n-t)*l,O={lift:c?0:M(t.motion.lift,n.lift),sway:c?0:M(t.motion.sway,n.sway),churn:M(t.motion.churn,n.churn)};return{motion:O,offset:[t.offset[0]+O.sway*s,t.offset[1]+O.lift*s],phase:t.phase+O.churn*s}},e.dragMotion=function(t,n,o){return Object.assign({},t,{offset:[t.offset[0]-u*n,t.offset[1]-u*o]})};const t={awake:{lift:.07,sway:.012,churn:1},dormant:{lift:0,sway:.012,churn:.4}},n="awake";const o=.35,f=.1;const u=2.4},986,[]);
1090
+ __d(function(g,r,_i,_a,_m,e,_d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"MIN_ANCHORS",{enumerable:!0,get:function(){return t}}),Object.defineProperty(e,"MAX_ANCHORS",{enumerable:!0,get:function(){return n}}),Object.defineProperty(e,"MIN_HUE_SEP_DEG",{enumerable:!0,get:function(){return o}}),Object.defineProperty(e,"MIN_ANCHOR_DE",{enumerable:!0,get:function(){return u}}),Object.defineProperty(e,"DISTINCT_AT_L",{enumerable:!0,get:function(){return c}}),Object.defineProperty(e,"MIN_SCHEME_DISTANCE",{enumerable:!0,get:function(){return a}}),Object.defineProperty(e,"EXCLUDED_HUE_DEG",{enumerable:!0,get:function(){return h}}),Object.defineProperty(e,"BAND_FADE_DEG",{enumerable:!0,get:function(){return s}}),e.hueExcluded=i,e.bandFade=f,e.neutralizeBand=l,e.oklabToLinearSrgb=m,e.inSrgbGamut=M,e.fitToGamut=b,e.hueSeparationDeg=d,e.anchorsDistinct=E,Object.defineProperty(e,"SCHEME_FAMILIES",{enumerable:!0,get:function(){return O}}),e.sampleScheme=D,e.abAt=j,e.hueChromaAt=I,e.schemeDistance=C,e.nextScheme=function(t,n){const o=null===t?[]:Array.isArray(t)?t:[t];for(let t=0;t<200;t++){const t=D(n);if(o.every(n=>C(t,n)>=a))return t}return D(n)},Object.defineProperty(e,"SCHEME_TEXELS",{enumerable:!0,get:function(){return N}}),e.packScheme=function(t){const n=new Float32Array(20);return n.set([t.hues.length,...t.hue,...t.light]),n.set(H(t),8),n},e.packAnchors=H;const t=3,n=5,o=28,u=.09,c=[.5,.65,.8],a=.12,h=[60,130],s=[60,75,115,130];function i(t){return t>=h[0]&&t<=h[1]}function f(t){const[n,o,u,c]=s;return p(n,o,t)*(1-p(u,c,t))}function l(t,n){const o=1-f((180*Math.atan2(n,t)/Math.PI+360)%360);return[t*o,n*o]}function m(t,n,o){const u=t+.3963377774*n+.2158037573*o,c=t-.1055613458*n-.0638541728*o,a=t-.0894841775*n-1.291485548*o,h=u*u*u,s=c*c*c,i=a*a*a;return[4.0767416621*h-3.3077115913*s+.2309699292*i,-1.2684380046*h+2.6097574011*s-.3413193965*i,-.0041960863*h-.7034186147*s+1.707614701*i]}function M(t,n,o){return m(t,n,o).every(t=>t>=-1e-4&&t<=1.0001)}function b(t,n,o){const u=n=>[t,n*Math.cos(o),n*Math.sin(o)];if(M(...u(n)))return u(n);let c=0,a=n;for(let t=0;t<20;t++){const t=(c+a)/2;M(...u(t))?c=t:a=t}return u(c)}const y=Math.PI/180,p=(t,n,o)=>{const u=Math.min(1,Math.max(0,(o-t)/(n-t)));return u*u*(3-2*u)};function d(t,n){const o=Math.abs(((t-n)%360+360)%360);return Math.min(o,360-o)}function E(t){for(let n=0;n<t.length;n++)for(let a=n+1;a<t.length;a++){if(d(t[n],t[a])<o)return!1;for(const o of c){const[,c,h]=b(o,.3,t[n]*y),[,s,i]=b(o,.3,t[a]*y);if(Math.hypot(c-s,h-i)<u)return!1}}return!0}const _=(t,n,o)=>n+(o-n)*t(),A=(t,n)=>n[Math.floor(t()*n.length)],S={analogous:(t,n)=>{const o=A(n,[3,4]),u=_(n,30,45);return Array.from({length:o},(n,c)=>t+u*(c-(o-1)/2))},complementary:(t,n)=>{const o=_(n,35,60);return A(n,[[t,t+180,t+o],[t,t+180,t+180+o],[t,t+o,t+180,t+180+o]])},split:(t,n)=>{const o=_(n,25,45);return[t,t+180-o,t+180+o]},triadic:t=>[t,t+120,t+240],tetradic:(t,n)=>{const o=A(n,[60,90]);return[t,t+o,t+180,t+180+o]},accent:(t,n)=>{const o=_(n,30,45);return[t,t+o,t+A(n,[150,180,210])+o/2]},wild:(t,n)=>Array.from({length:A(n,[3,4,5])},()=>_(n,0,360))},O=Object.keys(S);function P(t,n){for(let o=t.length-1;o>0;o--){const u=Math.floor(n()*(o+1));[t[o],t[u]]=[t[u],t[o]]}return t}function D(o){let u,c;do{u=A(o,O),c=S[u](_(o,0,360),o).map(t=>((t+_(o,-8,8))%360+360)%360)}while(c.length<t||c.length>n||c.some(i)||!E(c));const a=P(c,o).map(t=>t*y);return{family:u,hues:a,chromas:a.map(()=>_(o,.15,.32)),light:[_(o,2.4,3.7),o(),_(o,.62,.68),_(o,.27,.32)],hue:[_(o,1,1.5),o(),_(o,.18,.45)]}}function j(t,n,o=t.hue[2]){const u=t.hues.length,c=(n%1+1)%1*u,a=Math.floor(c)%u,h=(a+1)%u,s=p(.5-o,.5+o,c-Math.floor(c)),i=t.chromas[a]*Math.cos(t.hues[a]),f=t.chromas[a]*Math.sin(t.hues[a]);return l(i+(t.chromas[h]*Math.cos(t.hues[h])-i)*s,f+(t.chromas[h]*Math.sin(t.hues[h])-f)*s)}function I(t,n,o=t.hue[2]){const[u,c]=j(t,n,o);return[Math.atan2(c,u),Math.hypot(u,c)]}function C(t,n){let o=0;for(let u=0;u<32;u++){const[c,a]=I(t,u/32,.5),[h,s]=I(n,u/32,.5);o+=Math.hypot(a*Math.cos(c)-s*Math.cos(h),a*Math.sin(c)-s*Math.sin(h))}return o/32}const N=5;function H(t){const o=new Float32Array(12);for(let u=0;u<=n;u++){const n=u%t.hues.length;o[2*u]=t.hues[n],o[2*u+1]=t.chromas[n]}return o}},987,[]);
1091
+ __d(function(g,_r,_i,_a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"CELL",{enumerable:!0,get:function(){return n}}),Object.defineProperty(e,"JITTER",{enumerable:!0,get:function(){return r}}),Object.defineProperty(e,"SEAM",{enumerable:!0,get:function(){return c}}),Object.defineProperty(e,"WARP",{enumerable:!0,get:function(){return o}}),Object.defineProperty(e,"WARP_FREQ",{enumerable:!0,get:function(){return u}}),Object.defineProperty(e,"BLOCK",{enumerable:!0,get:function(){return l}}),Object.defineProperty(e,"TERRAIN_ROWS",{enumerable:!0,get:function(){return i}}),Object.defineProperty(e,"TERRAIN_TEXELS",{enumerable:!0,get:function(){return s}}),Object.defineProperty(e,"VIEW_MARGIN",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"createTerrain",{enumerable:!0,get:function(){return a}}),e.seededRng=b,e.cellRng=p,Object.defineProperty(e,"cellAt",{enumerable:!0,get:function(){return M}}),Object.defineProperty(e,"toWorld",{enumerable:!0,get:function(){return E}}),e.centreCell=y,e.cell=P,Object.defineProperty(e,"cellScheme",{enumerable:!0,get:function(){return j}}),e.blend=R,e.blockCells=S,e.blockRows=function(t,n){return S(y(n)).map(([n,r])=>P(t,n,r))},e.cellsInView=C,e.schemesInView=function(t,n){return C(t,n).map(([n,r])=>j(t,n,r))},e.paintCells=function(t,n,r){for(const[c,o]of n)t.cells.set(h(c,o),{seed:P(t,c,o).seed,scheme:r})},e.packCell=function(n){const r=new Float32Array(4*s);return r.set((0,t.packScheme)(n.scheme)),r.set([n.seed[0],n.seed[1],0,0],4*t.SCHEME_TEXELS),r};var t=_r(d[0]);const n=.75,r=.35,c=.25,o=.14,u=1.5,l=5,i=25,s=t.SCHEME_TEXELS+1,f=.21000000000000002,a=t=>({seed:t,cells:new Map}),h=(t,n)=>`${t},${n}`;function b(t){let n=0|t;return()=>{n=n+1831565813|0;let t=Math.imul(n^n>>>15,1|n);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}function p(t,n,r){let c=(0|t)^Math.imul(0|n,2654435761)^Math.imul(0|r,2246822519);return c=Math.imul(c^c>>>16,2146121005),c=Math.imul(c^c>>>15,2221713035),b(c^c>>>16)}const M=t=>Math.floor(t/n),E=(t,n)=>t-n;function y(t){return[M(E(0,t[0])),M(E(0,t[1]))]}const O=[[-1,-1],[0,-1],[1,-1],[-1,0],[1,0],[-1,1],[0,1],[1,1]];function P(c,o,u){const l=h(o,u),i=c.cells.get(l);if(i)return i;const s=p(c.seed,o,u),f=[(o+.5+(2*s()-1)*r)*n,(u+.5+(2*s()-1)*r)*n],a=O.map(([t,n])=>c.cells.get(h(o+t,u+n))?.scheme).filter(t=>!!t),b={seed:f,scheme:(0,t.nextScheme)(a,s)};return c.cells.set(l,b),b}const j=(t,n,r)=>P(t,n,r).scheme,w=t=>{const n=Math.min(1,Math.max(0,t/c));return 1-n*n*(3-2*n)};function R(t,n){const r=M(n[0]),c=M(n[1]),o=[];for(let u=-1;u<=1;u++)for(let l=-1;l<=1;l++){const i=P(t,r+l,c+u).seed;o.push({cell:[r+l,c+u],d:Math.hypot(n[0]-i[0],n[1]-i[1])})}const u=Math.min(...o.map(t=>t.d)),l=o.map(t=>({cell:t.cell,weight:w(t.d-u)})).filter(t=>t.weight>0),i=l.reduce((t,n)=>t+n.weight,0);return l.map(t=>({cell:t.cell,weight:t.weight/i})).sort((t,n)=>n.weight-t.weight)}function S(t){const n=[];for(let r=-2;r<=2;r++)for(let c=-2;c<=2;c++)n.push([t[0]+c,t[1]+r]);return n}const _=32;function A(t){const n=[];for(let r=0;r<=_;r++)for(let c=0;c<=_;c++)n.push([E(1.42*c/_-.71,t[0]),E(1.42*r/_-.71,t[1])]);return n}function C(t,n){const r=new Map;for(const c of A(n))for(const{cell:n}of R(t,c))r.set(h(...n),n);return[...r.values()].sort((t,n)=>t[1]-n[1]||t[0]-n[0])}},988,[987]);
1092
+ __d(function(_g,_r,_i,_a,m,e,_d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"TAP_RADIUS",{enumerable:!0,get:function(){return t}}),Object.defineProperty(e,"MAX_SPLOTCH_RADIUS",{enumerable:!0,get:function(){return r}}),Object.defineProperty(e,"BURST_S",{enumerable:!0,get:function(){return n}}),Object.defineProperty(e,"TAP_EDGE",{enumerable:!0,get:function(){return o}}),Object.defineProperty(e,"PRESSURE_PER_TAP",{enumerable:!0,get:function(){return s}}),Object.defineProperty(e,"PRESSURE_DRAIN_S",{enumerable:!0,get:function(){return u}}),Object.defineProperty(e,"CRITICAL_PRESSURE",{enumerable:!0,get:function(){return a}}),Object.defineProperty(e,"PRESSURE_SPAN",{enumerable:!0,get:function(){return c}}),Object.defineProperty(e,"MAX_SPEED",{enumerable:!0,get:function(){return i}}),Object.defineProperty(e,"RECLAIM",{enumerable:!0,get:function(){return p}}),Object.defineProperty(e,"WOBBLE",{enumerable:!0,get:function(){return l}}),Object.defineProperty(e,"ASPECT",{enumerable:!0,get:function(){return h}}),Object.defineProperty(e,"LOBE_MAX",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"WASH_DELAY_S",{enumerable:!0,get:function(){return g}}),Object.defineProperty(e,"WASH_SPEED",{enumerable:!0,get:function(){return d}}),Object.defineProperty(e,"RISE",{enumerable:!0,get:function(){return b}}),Object.defineProperty(e,"RISE_IN_S",{enumerable:!0,get:function(){return y}}),Object.defineProperty(e,"COVER_MARGIN",{enumerable:!0,get:function(){return M}}),Object.defineProperty(e,"MAX_SPLOTCHES",{enumerable:!0,get:function(){return P}}),Object.defineProperty(e,"SPLOTCH_TEXELS",{enumerable:!0,get:function(){return O}}),Object.defineProperty(e,"emptyFilm",{enumerable:!0,get:function(){return S}}),e.randomShape=A,e.sdAt=_,e.reach=I,e.touching=R,e.tap=function(r,o,u,a){const c=new Map(r.groups.map(t=>[t.id,t])),i=C(r).filter(t=>!k(c.get(t.group),r.clock)),p=i.filter(t=>_(t,o,u)<=-.02).at(-1);if(p){const t=r.groups.map(t=>t.id===p.group?Object.assign({},t,{lastTap:r.clock}):t);return{film:Object.assign({},r,{groups:t}),started:null,recolored:t.find(t=>t.id===p.group)}}const l={x:o,y:u,r:t,phase:0,group:0,shape:j,anchoredAt:null,rise:1},h=i.filter(t=>R(l,t)).at(-1),f=h?c.get(h.group):null,g=r.groups.filter(t=>!t.auto&&!k(t,r.clock)).reduce((t,r)=>!t||r.lastTap>t.lastTap?r:t,null),d=f??(g&&r.clock-g.lastTap<=n?g:null),b=d?null:{id:r.nextId,pressure:0,born:r.clock,lastTap:r.clock,auto:!1,washAt:null},y=(d??b).id,M=(b?[...r.groups,b]:r.groups).map(t=>t.id===y?Object.assign({},t,{pressure:t.pressure+s,lastTap:r.clock}):t),P=Object.assign({},l,{phase:1e3*a(),group:y,shape:A(a)}),O=[...T(r.splotches),P],S=new Set(O.map(t=>t.group));return{film:Object.assign({},r,{groups:M.filter(t=>S.has(t.id)),splotches:O,nextId:b?r.nextId+1:r.nextId}),started:b?M.find(t=>t.id===y):null,recolored:null}},e.shift=function(t,r,n){return 0===r&&0===n?t:Object.assign({},t,{splotches:t.splotches.map(t=>Object.assign({},t,{x:t.x+r,y:t.y+n}))})},e.invade=function(t,r,n,o){if(t.groups.some(t=>t.auto))return null;const s={id:t.nextId,pressure:0,born:t.clock,lastTap:t.clock,auto:!0,washAt:t.clock},u={x:r,y:n,r:.005,phase:1e3*o(),group:s.id,shape:j,anchoredAt:null,rise:1},a=[...T(t.splotches),u],c=new Set(a.map(t=>t.group));return{film:Object.assign({},t,{groups:[...t.groups,s].filter(t=>c.has(t.id)),splotches:a,nextId:t.nextId+1}),started:s}},e.autoDue=function(t,r,n){return n>=r&&!t.groups.some(t=>t.auto)},e.washing=k,e.frontSpeed=L,e.step=function(t,n,o=()=>!1){const s=Math.max(0,Math.min(n,.1)),a=t.clock+s,c=new Map(t.groups.map(t=>[t.id,t])),i=(t,r)=>{const n=c.get(t.group),s=c.get(r.group);return!n.auto&&!s.auto&&(n.id===s.id||o(n,s))},p=new Set(t.splotches.filter(r=>null!==r.anchoredAt||t.splotches.some(t=>t!==r&&i(r,t)&&R(r,t)))),l=t.groups.map(r=>{const n=null===r.washAt&&t.splotches.some(t=>t.group===r.id&&p.has(t));return Object.assign({},r,{washAt:n?a+g:r.washAt,pressure:r.pressure*Math.exp(-s/u)})}),h=new Map(l.map(t=>[t.id,t])),f=t.splotches.map(t=>{const n=h.get(t.group),o=k(n,a),u=p.has(t),c=o?d:L(n.pressure);let i=t.r+(c+.03*w(.5*a+t.phase))*s;o||(i=Math.min(r,i)),(u||o)&&(i=Math.max(t.r,i));const l=o?Math.min(b,t.rise+2*s/y):t.rise;return Object.assign({},t,{r:Math.max(0,i),anchoredAt:u?i:null,rise:l})}).filter(t=>t.r>0),M=new Set(f.map(t=>t.group));return Object.assign({},t,{clock:a,groups:l.filter(t=>M.has(t.id)),splotches:f})},e.covers=function(t,r,n,o=M){const s=t.splotches.filter(t=>t.group===r);return s.length>0&&n.every(([t,r])=>s.some(n=>_(n,t,r)<=-o))},e.adopt=function(t,r){const n=t.groups.find(t=>t.id===r);if(!n)return t;const o=new Set(t.groups.filter(t=>t.id!==r&&t.born>n.born).map(t=>t.id));return Object.assign({},t,{splotches:t.splotches.filter(t=>o.has(t.group)),groups:t.groups.filter(t=>o.has(t.id))})},e.packSplotches=function(t,r){const n=new Float32Array(1024);return C(t).slice(0,P).forEach((t,o)=>{const{angle:s,aspect:u,lobes:[a,c,i],phases:[p,l,h]}=t.shape;n.set([t.x,t.y,t.r,r(t.group),s,u,a,c,i,p,l,h,t.rise,0,0,0],o*O*4)}),n};const t=.09,r=.22,n=2.5,o=.02,s=1,u=30,a=.8,c=1.5,i=.032,p=.35,l=.015,h=[1.2,2.4],f=[.25,.2,.12],g=2,d=.05,b=3,y=2,M=.1,P=64,O=4,S=()=>({splotches:[],groups:[],clock:0,nextId:1}),j={angle:0,aspect:1,lobes:[0,0,0],phases:[0,0,0]};function A(t){return{angle:t()*Math.PI,aspect:(r=h[0],n=h[1],r+(n-r)*t()),lobes:[t()*f[0],t()*f[1],t()*f[2]],phases:[t()*Math.PI*2,t()*Math.PI*2,t()*Math.PI*2]};var r,n}function x(t,r){const[n,o,s]=t.lobes,[u,a,c]=t.phases;return 1+n*Math.cos(2*r+u)+o*Math.cos(3*r+a)+s*Math.cos(5*r+c)}function E(t,r,n){const o=r-t.x,s=n-t.y,u=s<0?s/t.rise:s,a=Math.cos(t.shape.angle),c=Math.sin(t.shape.angle);return[a*o+c*u,-c*o+a*u]}function _(t,r,n){const[o,s]=E(t,r,n),u=Math.sqrt(t.shape.aspect);return Math.hypot(o/u,s*u)-t.r*x(t.shape,Math.atan2(s,o))}function I(t,r,n){const o=Math.hypot(r-t.x,n-t.y);if(0===o)return 0;const s=t.x+(r-t.x)/o,u=t.y+(n-t.y)/o,[a,c]=E(t,s,u),i=Math.sqrt(t.shape.aspect),p=Math.hypot(a/i,c*i);return Math.max(0,t.r*x(t.shape,Math.atan2(c,a))/p)}function R(t,r){return t.r>0&&r.r>0&&Math.hypot(t.x-r.x,t.y-r.y)<I(t,r.x,r.y)+I(r,t.x,t.y)}function w(t){const r=Math.floor(t),n=t-r,o=t=>{const r=43758.5453*Math.sin(127.1*t+311.7);return 2*(r-Math.floor(r))-1},s=n*n*n*(n*(6*n-15)+10);return o(r)*n*(1-s)+o(r+1)*(n-1)*s}function T(t){if(t.length<P)return t;const r=(t.some(t=>null===t.anchoredAt)?t.filter(t=>null===t.anchoredAt):t).reduce((t,r)=>r.r<t.r?r:t);return t.filter(t=>t!==r)}function k(t,r){return null!==t.washAt&&r>=t.washAt}function L(t){const r=Math.max(-1,Math.min(1,(t-a)/c));return i*(r>=0?r:r*p)}function C(t){const r=new Map(t.groups.map(t=>[t.id,t.born]));return t.splotches.map((t,n)=>({s:t,i:n,b:r.get(t.group)??0})).sort((t,r)=>t.b-r.b||t.i-r.i).map(({s:t})=>t)}},989,[]);
1093
+ __d(function(g,r,i,_a,m,_e,_d){"use strict";function e(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"default",{enumerable:!0,get:function(){return k}});var t=r(_d[0]),n=e(r(_d[1])),o=e(r(_d[2])),a=e(r(_d[3])),l=e(r(_d[4])),d=e(r(_d[5])),s=e(r(_d[6])),c=e(r(_d[7])),u=r(_d[8]),f=r(_d[9]),h=r(_d[10]),x=r(_d[11]);function y(e){const t=(0,f.relPart)(e);return t.ago?`${t.val} ago`:t.val}function p(e){return"local"===e.kind?"This machine's CLI":e.owner_nid?`Agent ${e.owner_nid}`:"agent"===e.kind?`Agent ${e.label}`:e.unused?"Meld QR not scanned yet":e.device?e.device:e.remote_addr?`Device at ${e.remote_addr}`:"Device not seen yet"}function v(e){const t=`${"agent"===e.kind?"started":"added"} ${y(e.created_at)}${e.minted_by_device?` by ${e.minted_by_device}`:""}`;if(e.unused){if(null===e.expires_at)return t;return`lapses in ${Math.max(1,Math.ceil((e.expires_at-Date.now())/6e4))} min \xb7 ${t}`}const n=[e.connected?"connected now":null!==e.last_used_at?`seen ${y(e.last_used_at)}`:"never used"];return e.remote_addr&&n.push(e.remote_addr),e.app_origin&&n.push(`via ${(0,h.originHost)(e.app_origin)}`),n.push(t),n.join(" \xb7 ")}function b(e){if(null===e.elsewhere_at)return null;const t=[e.last_device,e.last_remote_addr].filter(Boolean).join(" at ");return`Also used from another address${t?` (latest: ${t})`:""}, ${y(e.elsewhere_at)}`}function k({visible:e,conn:d,daemonName:f,onClose:h,onSignOutOthers:y,signedOutOthers:k,connected:_}){const[T,S]=(0,t.useState)(null),[C,$]=(0,t.useState)(!1),[z,O]=(0,t.useState)(null),[W,D]=(0,t.useState)(null),[R,H]=(0,t.useState)(null),[P,I]=(0,t.useState)(new Set),M=(0,t.useCallback)(async()=>{if(d){O(null);try{const e=await(0,u.listDeviceTokens)(d);$(null===e),S(e??[])}catch(e){O(String(e))}}},[d]);(0,t.useEffect)(()=>{e?(S(null),M()):D(null)},[e,M]);const L=async e=>{if(d){if(W!==e.id)return D(e.id),void I(new Set(e.descendants));H(e.id),O(null);try{await(0,u.revokeDeviceToken)(d,e.id,e.descendants.filter(e=>P.has(e))),D(null),await M()}catch(e){O(String(e))}finally{H(null)}}},A=()=>{R||h()},V=new Map((T??[]).map(e=>[e.id,e])),B=[...T??[]].sort((e,t)=>{const n=e=>e.current?0:"local"===e.kind?1:"device"===e.kind?2:3;return n(e)-n(t)||(t.last_used_at??t.created_at)-(e.last_used_at??e.created_at)});return(0,x.jsx)(o.default,{visible:e,transparent:!0,animationType:"fade",onRequestClose:A,children:(0,x.jsx)(a.default,{style:w.overlay,onPress:A,children:(0,x.jsxs)(a.default,{style:w.card,onPress:e=>e.stopPropagation(),children:[(0,x.jsxs)(s.default,{style:w.title,children:["Devices on ",f]}),null!==T||z?C?(0,x.jsx)(s.default,{style:w.body,children:"This daemon is older than the Devices list. Update brane on it to see and revoke devices."}):(0,x.jsx)(l.default,{style:w.list,children:B.map(e=>(0,x.jsxs)(c.default,{style:w.rowWrap,children:[(0,x.jsxs)(c.default,{style:w.row,children:[(0,x.jsxs)(c.default,{style:{flex:1},children:[(0,x.jsxs)(s.default,{style:w.rowTitle,numberOfLines:1,children:[p(e),e.current?(0,x.jsx)(s.default,{style:w.thisDevice,children:" this device"}):null]}),(0,x.jsx)(s.default,{style:w.rowDetail,children:v(e)}),"device"===e.kind&&(0,x.jsxs)(s.default,{style:w.rowLabel,children:["\"",e.label,"\""]}),b(e)&&(0,x.jsx)(s.default,{style:w.rowWarn,children:b(e)}),"adopted"===e.origin&&"device"===e.kind&&(0,x.jsx)(s.default,{style:w.rowWarn,children:"From before tokens were hashed; may have been logged"}),"adopted"===e.origin&&"agent"===e.kind&&(0,x.jsx)(s.default,{style:w.rowLabel,children:"Kept from before agents had their own tokens; replaced when it is next revived"})]}),"local"!==e.kind&&!e.current&&(0,x.jsx)(a.default,{style:[w.revoke,W===e.id&&w.revokeConfirm,null!==R&&{opacity:.5}],onPress:()=>L(e),disabled:null!==R,children:R===e.id?(0,x.jsx)(n.default,{size:"small",color:"#111"}):(0,x.jsx)(s.default,{style:[w.revokeText,W===e.id&&w.revokeConfirmText],children:W===e.id?"Revoke?":"Revoke"})})]}),W===e.id&&(0,x.jsx)(j,{token:e,byId:V,also:P,onToggle:e=>I(t=>{const n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})})]},e.id))}):(0,x.jsx)(n.default,{style:{marginVertical:16},color:"#aaa"}),z&&(0,x.jsx)(s.default,{style:w.error,children:z}),(0,x.jsx)(s.default,{style:w.footnote,children:"A revoked device is signed out until it scans a fresh Meld QR. To keep only this device:"}),(0,x.jsx)(a.default,{style:[w.signOut,(!_||null!==R)&&{opacity:.5}],onPress:y,disabled:!_||null!==R,children:(0,x.jsx)(s.default,{style:w.signOutText,children:k?"Other devices signed out":"Sign out other devices"})}),(0,x.jsx)(a.default,{style:[w.close,null!==R&&{opacity:.5}],onPress:A,disabled:null!==R,children:(0,x.jsx)(s.default,{style:w.closeText,children:"Close"})})]})})})}function j({token:e,byId:t,also:n,onToggle:o}){const l=[e,...e.descendants.map(e=>t.get(e)).filter(e=>!!e)].flatMap(e=>e.agents).filter(e=>"ended"!==e.status),d="agent"===e.kind;return 0!==e.descendants.length||0!==l.length||d?(0,x.jsxs)(c.default,{style:w.cascade,children:[d&&(0,x.jsxs)(s.default,{style:w.cascadeNote,children:["This cuts ",e.owner_nid??"the agent"," off from brane at once; its session keeps running without tools. To bring it back, end its session and revive it."]}),e.descendants.length>0&&(0,x.jsxs)(s.default,{style:w.cascadeHead,children:["Also revoke ",1===e.descendants.length?"the device or agent":`the ${e.descendants.length} devices and agents`," it added:"]}),e.descendants.map(e=>{const l=t.get(e),d=n.has(e);return(0,x.jsxs)(a.default,{style:w.cascadeRow,onPress:()=>o(e),children:[(0,x.jsx)(s.default,{style:[w.checkbox,d&&w.checkboxOn],children:d?"\u2611":"\u2610"}),(0,x.jsx)(s.default,{style:w.cascadeText,numberOfLines:2,children:l?`${p(l)} \xb7 ${v(l)}`:e})]},e)}),l.length>0&&(0,x.jsxs)(s.default,{style:w.cascadeNote,children:["Started ",1===l.length?"1 running agent":`${l.length} running agents`,":"," ",l.map(e=>e.id).join(", "),". Their sessions keep running; revoking their tokens cuts off their brane tools."]})]}):null}const w=d.default.create({overlay:{flex:1,backgroundColor:"rgba(0,0,0,0.6)",justifyContent:"center",alignItems:"center",padding:24},card:{backgroundColor:"#1e1e22",borderRadius:12,padding:20,width:"100%",maxWidth:420,maxHeight:"85%",borderWidth:1,borderColor:"#3a3a40"},title:{color:"#d8d8dd",fontSize:16,fontWeight:"600",marginBottom:10},body:{color:"#999",fontSize:13,lineHeight:18},list:{flexGrow:0},rowWrap:{borderBottomWidth:d.default.hairlineWidth,borderBottomColor:"#3a3a40",paddingVertical:10},row:{flexDirection:"row",alignItems:"center",gap:10},cascade:{marginTop:8,padding:10,borderRadius:8,backgroundColor:"#26262b",gap:6},cascadeHead:{color:"#d8d8dd",fontSize:13},cascadeRow:{flexDirection:"row",alignItems:"flex-start",gap:8},checkbox:{color:"#777",fontSize:16,lineHeight:18},checkboxOn:{color:"#e0a070"},cascadeText:{color:"#aaa",fontSize:12,flex:1,lineHeight:18},cascadeNote:{color:"#888",fontSize:12,lineHeight:16},rowTitle:{color:"#d8d8dd",fontSize:14},thisDevice:{color:"#66d9a0",fontSize:12},rowDetail:{color:"#777",fontSize:12,fontFamily:"monospace",marginTop:2},rowLabel:{color:"#666",fontSize:12,marginTop:2},rowWarn:{color:"#e0a070",fontSize:12,marginTop:2},revoke:{backgroundColor:"#2a2a30",borderRadius:8,paddingVertical:6,paddingHorizontal:12,minWidth:76,alignItems:"center"},revokeConfirm:{backgroundColor:"#e0a070"},revokeText:{color:"#e0a070",fontSize:13,fontWeight:"600"},revokeConfirmText:{color:"#111"},error:{color:"#e07070",fontSize:12,marginTop:8},footnote:{color:"#666",fontSize:12,lineHeight:16,marginTop:12},signOut:{backgroundColor:"#2a2a30",borderRadius:8,paddingVertical:10,alignItems:"center",marginTop:8},signOutText:{color:"#e0a070",fontSize:14,fontWeight:"600"},close:{backgroundColor:"#2a2a30",borderRadius:8,paddingVertical:10,alignItems:"center",marginTop:12},closeText:{color:"#aaa",fontSize:14,fontWeight:"600"}})},990,[11,416,153,146,122,26,105,13,745,752,979,6]);
1094
+ __d(function(g,r,i,a,_m,_e,d){"use strict";Object.defineProperty(_e,'__esModule',{value:!0}),Object.defineProperty(_e,"ARROW_STEP_PX",{enumerable:!0,get:function(){return e}}),Object.defineProperty(_e,"PAGE_FRACTION",{enumerable:!0,get:function(){return t}}),_e.isListScrollKey=function(e){return!(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)&&n.has(e.key)},_e.listScrollTarget=function(n,c,o){const l=Math.max(0,o.scrollHeight-o.clientHeight),u=Math.max(1,o.clientHeight*t);let s;switch(n){case"ArrowUp":s=c-e;break;case"ArrowDown":s=c+e;break;case"PageUp":s=c-u;break;case"PageDown":s=c+u;break;case"Home":return 0;case"End":return l;default:return null}return Math.min(l,Math.max(0,s))};const e=40,t=.875,n=new Set(["PageUp","PageDown","Home","End","ArrowUp","ArrowDown"])},991,[]);
1095
+ __d(function(g,r,i,a,_m,e,d){"use strict";var t=this&&this.__createBinding||(Object.create?function(t,n,o,c){void 0===c&&(c=o);var u=Object.getOwnPropertyDescriptor(n,o);u&&!("get"in u?!n.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return n[o]}}),Object.defineProperty(t,c,u)}:function(t,n,o,c){void 0===c&&(c=o),t[c]=n[o]}),n=this&&this.__exportStar||function(n,o){for(var c in n)"default"===c||Object.prototype.hasOwnProperty.call(o,c)||t(o,n,c)};Object.defineProperty(e,"__esModule",{value:!0}),n(r(d[0]),e)},992,[738]);
1096
+ __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,"__esModule",{value:!0})},993,[]);
1097
+ __d(function(g,r,_i,a,_m,_e,d){"use strict";var e,t=r(d[0]),n=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,i)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},e(t)},function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var c=e(t),u=0;u<c.length;u++)"default"!==c[u]&&n(i,t,c[u]);return o(i,t),i});Object.defineProperty(_e,"__esModule",{value:!0}),_e.renderRootComponent=function(e){try{setTimeout(()=>{f._internal_preventAutoHideAsync?.()}),u.startTransition(()=>{(0,c.registerRootComponent)(e)})}catch(e){f.hideAsync();const n=b(e);(0,c.registerRootComponent)(()=>t.jsx(s.View,{})),console.error(n),console.error("A runtime error has occurred while rendering the root component."),setTimeout(()=>{throw n})}};const c=r(d[1]),u=i(r(d[2])),s=r(d[3]),f=i(r(d[4]));function l(e){if('[object Object]'!==Object.prototype.toString.call(e))return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function p(e){return e&&'object'==typeof e&&'string'==typeof e.name&&'string'==typeof e.message}function b(e){return p(e)?e:l(e)?new Error(JSON.stringify(e)):new Error(String(e))}},994,[6,600,11,342,599]);
1097
1098
  __r(602);
1098
1099
  __r(2);
1099
1100
  __r(0);