total-recall-brain 3.25.5 → 3.25.6
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.
|
@@ -5244,7 +5244,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
5244
5244
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function tW(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function nW(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?tW(Object(n),!0).forEach(function(t){QU(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):tW(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function rW(e){return ZU(e)||$U(e)||oW(e)||eW()}function iW(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function aW(e){var t=iW(e,`string`);return typeof t==`symbol`?t:t+``}function oW(e,t){if(e){if(typeof e==`string`)return XU(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?XU(e,t):void 0}}function sW(e,t){var n=new t;return n._destructor&&n._destructor(),{linkProp:function(t){return{default:n[t](),onChange:function(n,r){r[e][t](n)},triggerUpdate:!1}},linkMethod:function(t){return function(n){var r=n[e],i=[...arguments].slice(1),a=r[t].apply(r,i);return a===r?this:a}}}}var cW=window.THREE?window.THREE:{AmbientLight:vf,DirectionalLight:_f,REVISION:`185`},lW=170,uW=sW(`forceGraph`,pw),dW=Object.assign.apply(Object,rW(`jsonUrl.graphData.numDimensions.dagMode.dagLevelDistance.dagNodeFilter.onDagError.nodeRelSize.nodeId.nodeVal.nodeResolution.nodeColor.nodeAutoColorBy.nodeOpacity.nodeVisibility.nodeThreeObject.nodeThreeObjectExtend.nodePositionUpdate.linkSource.linkTarget.linkVisibility.linkColor.linkAutoColorBy.linkOpacity.linkWidth.linkResolution.linkCurvature.linkCurveRotation.linkMaterial.linkThreeObject.linkThreeObjectExtend.linkPositionUpdate.linkDirectionalArrowLength.linkDirectionalArrowColor.linkDirectionalArrowRelPos.linkDirectionalArrowResolution.linkDirectionalParticles.linkDirectionalParticleSpeed.linkDirectionalParticleOffset.linkDirectionalParticleWidth.linkDirectionalParticleColor.linkDirectionalParticleResolution.linkDirectionalParticleThreeObject.forceEngine.d3AlphaDecay.d3VelocityDecay.d3AlphaMin.ngraphPhysics.warmupTicks.cooldownTicks.cooldownTime.onEngineTick.onEngineStop`.split(`.`).map(function(e){return QU({},e,uW.linkProp(e))}))),fW=Object.assign.apply(Object,rW([`refresh`,`getGraphBbox`,`d3Force`,`d3ReheatSimulation`,`emitParticle`].map(function(e){return QU({},e,uW.linkMethod(e))}))),pW=sW(`renderObjs`,JU),mW=Object.assign.apply(Object,rW([`width`,`height`,`backgroundColor`,`showNavInfo`,`enablePointerInteraction`].map(function(e){return QU({},e,pW.linkProp(e))}))),hW=Object.assign.apply(Object,rW([`lights`,`cameraPosition`,`postProcessingComposer`].map(function(e){return QU({},e,pW.linkMethod(e))})).concat([{graph2ScreenCoords:pW.linkMethod(`getScreenCoords`),screen2GraphCoords:pW.linkMethod(`getSceneCoords`)}])),gW=m_({props:nW(nW({nodeLabel:{default:`name`,triggerUpdate:!1},linkLabel:{default:`name`,triggerUpdate:!1},linkHoverPrecision:{default:1,onChange:function(e,t){return t.renderObjs.lineHoverPrecision(e)},triggerUpdate:!1},enableNavigationControls:{default:!0,onChange:function(e,t){var n=t.renderObjs.controls();n&&(n.enabled=e,e&&n.domElement&&n.domElement.dispatchEvent(new PointerEvent(`pointerup`)))},triggerUpdate:!1},enableNodeDrag:{default:!0,triggerUpdate:!1},onNodeDrag:{default:function(){},triggerUpdate:!1},onNodeDragEnd:{default:function(){},triggerUpdate:!1},onNodeClick:{triggerUpdate:!1},onNodeRightClick:{triggerUpdate:!1},onNodeHover:{triggerUpdate:!1},onLinkClick:{triggerUpdate:!1},onLinkRightClick:{triggerUpdate:!1},onLinkHover:{triggerUpdate:!1},onBackgroundClick:{triggerUpdate:!1},onBackgroundRightClick:{triggerUpdate:!1},showPointerCursor:{default:!0,triggerUpdate:!1}},dW),mW),methods:nW(nW({zoomToFit:function(e,t,n){var r,i=[...arguments].slice(3);return e.renderObjs.fitToBbox((r=e.forceGraph).getGraphBbox.apply(r,i),t,n),this},pauseAnimation:function(e){return e.animationFrameRequestId!==null&&(cancelAnimationFrame(e.animationFrameRequestId),e.animationFrameRequestId=null),this},resumeAnimation:function(e){return e.animationFrameRequestId===null&&this._animationCycle(),this},_animationCycle:function(e){e.enablePointerInteraction&&(this.renderer().domElement.style.cursor=null),e.forceGraph.tickFrame(),e.renderObjs.tick(),e.animationFrameRequestId=requestAnimationFrame(this._animationCycle)},scene:function(e){return e.renderObjs.scene()},camera:function(e){return e.renderObjs.camera()},renderer:function(e){return e.renderObjs.renderer()},controls:function(e){return e.renderObjs.controls()},_destructor:function(e){var t,n;this.pauseAnimation(),this.graphData({nodes:[],links:[]}),(t=(n=e.forceGraph)._destructor)==null||t.call(n),e.renderObjs._destructor()}},fW),hW),stateInit:function(e){var t=e.controlType,n=e.rendererConfig,r=e.extraRenderers,i=new pw;return{forceGraph:i,renderObjs:JU({controlType:t,rendererConfig:n,extraRenderers:r}).objects([i]).lights([new cW.AmbientLight(13421772,Math.PI),new cW.DirectionalLight(16777215,.6*Math.PI)])}},init:function(e,t){e.innerHTML=``,e.appendChild(t.container=document.createElement(`div`)),t.container.style.position=`relative`;var n=document.createElement(`div`);t.container.appendChild(n),t.renderObjs(n);var r=t.renderObjs.camera(),i=t.renderObjs.renderer(),a=t.renderObjs.controls();a.enabled=!!t.enableNavigationControls,t.lastSetCameraZ=r.position.z;var o;t.container.appendChild(o=document.createElement(`div`)),o.className=`graph-info-msg`,o.textContent=``,t.forceGraph.onLoading(function(){o.textContent=`Loading...`}).onFinishLoading(function(){o.textContent=``}).onUpdate(function(){t.graphData=t.forceGraph.graphData(),r.position.x===0&&r.position.y===0&&r.position.z===t.lastSetCameraZ&&t.graphData.nodes.length&&(r.lookAt(t.forceGraph.position),t.lastSetCameraZ=r.position.z=Math.cbrt(t.graphData.nodes.length)*lW)}).onFinishUpdate(function(){if(t._dragControls){var e=t.graphData.nodes.find(function(e){return e.__initialFixedPos&&!e.__disposeControlsAfterDrag});e?e.__disposeControlsAfterDrag=!0:t._dragControls.dispose(),t._dragControls=void 0}if(t.enableNodeDrag&&t.enablePointerInteraction&&t.forceEngine===`d3`){var n=t._dragControls=new jh(t.graphData.nodes.map(function(e){return e.__threeObj}).filter(function(e){return e}),r,i.domElement);n.addEventListener(`dragstart`,function(e){var t=_W(e.object);if(t){a.enabled=!1,e.object.__initialPos=e.object.position.clone(),e.object.__prevPos=e.object.position.clone();var n=t.__data;!n.__initialFixedPos&&(n.__initialFixedPos={fx:n.fx,fy:n.fy,fz:n.fz}),!n.__initialPos&&(n.__initialPos={x:n.x,y:n.y,z:n.z}),[`x`,`y`,`z`].forEach(function(e){return n[`f${e}`]=n[e]}),i.domElement.classList.add(`grabbable`)}}),n.addEventListener(`drag`,function(e){var n=_W(e.object);if(n){if(!e.object.hasOwnProperty(`__graphObjType`)){var r=e.object.__initialPos,i=e.object.__prevPos,a=e.object.position;n.position.add(a.clone().sub(i)),i.copy(a),a.copy(r)}var o=n.__data,s=n.position,c={x:s.x-o.x,y:s.y-o.y,z:s.z-o.z};[`x`,`y`,`z`].forEach(function(e){return o[`f${e}`]=o[e]=s[e]}),t.forceGraph.d3AlphaTarget(.3).resetCountdown(),o.__dragged=!0,t.onNodeDrag(o,c)}}),n.addEventListener(`dragend`,function(e){var r=_W(e.object);if(r){delete e.object.__initialPos,delete e.object.__prevPos;var o=r.__data;o.__disposeControlsAfterDrag&&(n.dispose(),delete o.__disposeControlsAfterDrag);var s=o.__initialFixedPos,c=o.__initialPos,l={x:c.x-o.x,y:c.y-o.y,z:c.z-o.z};if(s&&([`x`,`y`,`z`].forEach(function(e){var t=`f${e}`;s[t]===void 0&&delete o[t]}),delete o.__initialFixedPos,delete o.__initialPos,o.__dragged&&(delete o.__dragged,t.onNodeDragEnd(o,l))),t.forceGraph.d3AlphaTarget(0).resetCountdown(),t.enableNavigationControls){var u;a.enabled=!0,a._status&&((u=a._onPointerCancel)==null||u.call(a)),a.domElement&&a.domElement.ownerDocument&&a.domElement.ownerDocument.dispatchEvent(new PointerEvent(`pointerup`,{pointerType:`touch`}))}i.domElement.classList.remove(`grabbable`)}})}}),cW.REVISION<155&&(t.renderObjs.renderer().useLegacyLights=!1),t.renderObjs.hoverOrderComparator(function(e,t){var n=_W(e);if(!n)return 1;var r=_W(t);if(!r)return-1;var i=function(e){return e.__graphObjType===`node`};return i(r)-i(n)}).tooltipContent(function(e){var n=_W(e);return n&&h_(t[`${n.__graphObjType}Label`])(n.__data)||``}).hoverDuringDrag(!1).onHover(function(e){var n=_W(e);if(n!==t.hoverObj){var r=t.hoverObj?t.hoverObj.__graphObjType:null,a=t.hoverObj?t.hoverObj.__data:null,o=n?n.__graphObjType:null,s=n?n.__data:null;if(r&&r!==o){var c=t[`on${r===`node`?`Node`:`Link`}Hover`];c&&c(null,a)}if(o){var l=t[`on${o===`node`?`Node`:`Link`}Hover`];l&&l(s,r===o?a:null)}i.domElement.classList[(n&&t[`on${o===`node`?`Node`:`Link`}Click`]||!n&&t.onBackgroundClick)&&h_(t.showPointerCursor)(s)?`add`:`remove`](`clickable`),t.hoverObj=n}}).clickAfterDrag(!1).onClick(function(e,n){var r=_W(e);if(r){var i=t[`on${r.__graphObjType===`node`?`Node`:`Link`}Click`];i&&i(r.__data,n)}else t.onBackgroundClick&&t.onBackgroundClick(n)}).onRightClick(function(e,n){var r=_W(e);if(r){var i=t[`on${r.__graphObjType===`node`?`Node`:`Link`}RightClick`];i&&i(r.__data,n)}else t.onBackgroundRightClick&&t.onBackgroundRightClick(n)}),this._animationCycle()}});function _W(e){for(var t=e;t&&!t.hasOwnProperty(`__graphObjType`);)t=t.parent;return t}var vW=o(((e,t)=>{t.exports=`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`})),yW=o(((e,t)=>{var n=vW();function r(){}function i(){}i.resetWarningCache=r,t.exports=function(){function e(e,t,r,i,a,o){if(o!==n){var s=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 s.name=`Invariant Violation`,s}}e.isRequired=e;function t(){return e}var a={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:r};return a.PropTypes=a,a}})),Q=l(o(((e,t)=>{t.exports=yW()()}))(),1),bW={width:Q.default.number,height:Q.default.number,graphData:Q.default.shape({nodes:Q.default.arrayOf(Q.default.object).isRequired,links:Q.default.arrayOf(Q.default.object).isRequired}),backgroundColor:Q.default.string,nodeRelSize:Q.default.number,nodeId:Q.default.string,nodeLabel:Q.default.oneOfType([Q.default.string,Q.default.func]),nodeVal:Q.default.oneOfType([Q.default.number,Q.default.string,Q.default.func]),nodeVisibility:Q.default.oneOfType([Q.default.bool,Q.default.string,Q.default.func]),nodeColor:Q.default.oneOfType([Q.default.string,Q.default.func]),nodeAutoColorBy:Q.default.oneOfType([Q.default.string,Q.default.func]),onNodeHover:Q.default.func,onNodeClick:Q.default.func,linkSource:Q.default.string,linkTarget:Q.default.string,linkLabel:Q.default.oneOfType([Q.default.string,Q.default.func]),linkVisibility:Q.default.oneOfType([Q.default.bool,Q.default.string,Q.default.func]),linkColor:Q.default.oneOfType([Q.default.string,Q.default.func]),linkAutoColorBy:Q.default.oneOfType([Q.default.string,Q.default.func]),linkWidth:Q.default.oneOfType([Q.default.number,Q.default.string,Q.default.func]),linkCurvature:Q.default.oneOfType([Q.default.number,Q.default.string,Q.default.func]),linkDirectionalArrowLength:Q.default.oneOfType([Q.default.number,Q.default.string,Q.default.func]),linkDirectionalArrowColor:Q.default.oneOfType([Q.default.string,Q.default.func]),linkDirectionalArrowRelPos:Q.default.oneOfType([Q.default.number,Q.default.string,Q.default.func]),linkDirectionalParticles:Q.default.oneOfType([Q.default.number,Q.default.string,Q.default.func]),linkDirectionalParticleSpeed:Q.default.oneOfType([Q.default.number,Q.default.string,Q.default.func]),linkDirectionalParticleOffset:Q.default.oneOfType([Q.default.number,Q.default.string,Q.default.func]),linkDirectionalParticleWidth:Q.default.oneOfType([Q.default.number,Q.default.string,Q.default.func]),linkDirectionalParticleColor:Q.default.oneOfType([Q.default.string,Q.default.func]),onLinkHover:Q.default.func,onLinkClick:Q.default.func,dagMode:Q.default.oneOf([`td`,`bu`,`lr`,`rl`,`zin`,`zout`,`radialin`,`radialout`]),dagLevelDistance:Q.default.number,dagNodeFilter:Q.default.func,onDagError:Q.default.func,d3AlphaMin:Q.default.number,d3AlphaDecay:Q.default.number,d3VelocityDecay:Q.default.number,warmupTicks:Q.default.number,cooldownTicks:Q.default.number,cooldownTime:Q.default.number,onEngineTick:Q.default.func,onEngineStop:Q.default.func,getGraphBbox:Q.default.func},xW={zoomToFit:Q.default.func,onNodeRightClick:Q.default.func,onNodeDrag:Q.default.func,onNodeDragEnd:Q.default.func,onLinkRightClick:Q.default.func,linkHoverPrecision:Q.default.number,onBackgroundClick:Q.default.func,onBackgroundRightClick:Q.default.func,showPointerCursor:Q.default.oneOfType([Q.default.bool,Q.default.func]),enablePointerInteraction:Q.default.bool,enableNodeDrag:Q.default.bool},SW={showNavInfo:Q.default.bool,nodeOpacity:Q.default.number,nodeResolution:Q.default.number,nodeThreeObject:Q.default.oneOfType([Q.default.object,Q.default.string,Q.default.func]),nodeThreeObjectExtend:Q.default.oneOfType([Q.default.bool,Q.default.string,Q.default.func]),nodePositionUpdate:Q.default.func,linkOpacity:Q.default.number,linkResolution:Q.default.number,linkCurveRotation:Q.default.oneOfType([Q.default.number,Q.default.string,Q.default.func]),linkMaterial:Q.default.oneOfType([Q.default.object,Q.default.string,Q.default.func]),linkThreeObject:Q.default.oneOfType([Q.default.object,Q.default.string,Q.default.func]),linkThreeObjectExtend:Q.default.oneOfType([Q.default.bool,Q.default.string,Q.default.func]),linkPositionUpdate:Q.default.func,linkDirectionalArrowResolution:Q.default.number,linkDirectionalParticleResolution:Q.default.number,linkDirectionalParticleThreeObject:Q.default.oneOfType([Q.default.object,Q.default.string,Q.default.func]),forceEngine:Q.default.oneOf([`d3`,`ngraph`]),ngraphPhysics:Q.default.object,numDimensions:Q.default.oneOf([1,2,3])};Object.assign({},bW,xW,{linkLineDash:Q.default.oneOfType([Q.default.arrayOf(Q.default.number),Q.default.string,Q.default.func]),nodeCanvasObjectMode:Q.default.oneOfType([Q.default.string,Q.default.func]),nodeCanvasObject:Q.default.func,nodePointerAreaPaint:Q.default.func,linkCanvasObjectMode:Q.default.oneOfType([Q.default.string,Q.default.func]),linkCanvasObject:Q.default.func,linkPointerAreaPaint:Q.default.func,linkDirectionalParticleCanvasObject:Q.default.func,autoPauseRedraw:Q.default.bool,minZoom:Q.default.number,maxZoom:Q.default.number,enableZoomInteraction:Q.default.oneOfType([Q.default.bool,Q.default.func]),enablePanInteraction:Q.default.oneOfType([Q.default.bool,Q.default.func]),onZoom:Q.default.func,onZoomEnd:Q.default.func,onRenderFramePre:Q.default.func,onRenderFramePost:Q.default.func});var CW=Object.assign({},bW,xW,SW,{enableNavigationControls:Q.default.bool,controlType:Q.default.oneOf([`trackball`,`orbit`,`fly`]),rendererConfig:Q.default.object,extraRenderers:Q.default.arrayOf(Q.default.shape({render:Q.default.func.isRequired}))});Object.assign({},bW,SW,{nodeDesc:Q.default.oneOfType([Q.default.string,Q.default.func]),linkDesc:Q.default.oneOfType([Q.default.string,Q.default.func])}),Object.assign({},bW,SW,{markerAttrs:Q.default.object,yOffset:Q.default.number,glScale:Q.default.number});var wW=Hi(gW,{methodNames:[`emitParticle`,`d3Force`,`d3ReheatSimulation`,`stopAnimation`,`pauseAnimation`,`resumeAnimation`,`cameraPosition`,`zoomToFit`,`getGraphBbox`,`screen2GraphCoords`,`graph2ScreenCoords`,`postProcessingComposer`,`lights`,`scene`,`camera`,`renderer`,`controls`,`refresh`],initPropNames:[`controlType`,`rendererConfig`,`extraRenderers`]});wW.displayName=`ForceGraph3D`,wW.propTypes=CW;var TW=new ad(1,16,16),EW=new od(1,.1,8,32),DW=new Map;function OW(e,t=!1){let n=`${e}-${t}`;return DW.has(n)||(t?DW.set(n,new zl({color:16777215,transparent:!0,opacity:.8})):DW.set(n,new wd({color:e,transparent:!0,opacity:.9}))),DW.get(n)}function kW({threads:e,memoryNodes:t,researchItems:n,onOpenThread:r,onGroundMemoryNode:i,selectedGroundingNodes:a,interactive:o=!0}){let s=(0,v.useRef)(null),c=(0,v.useRef)(null),[l,u]=(0,v.useState)({width:0,height:0}),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)({research:!0,observations:!0,rules:!0,threads:!1});(0,v.useEffect)(()=>{if(!c.current)return;let e=new ResizeObserver(e=>{if(e[0]){let{width:t,height:n}=e[0].contentRect;u({width:t,height:n})}});return e.observe(c.current),()=>e.disconnect()},[]);let h=(0,v.useMemo)(()=>{let r=[],i=[],a=new Map,o=new Map,s=new Map,c=new Map;p.threads&&e.forEach(e=>{let t={id:`thread-${e.id}`,type:`thread`,title:e.title||`Untitled Thread`,subtitle:`${e.turns} ${e.turns===1?`turn`:`turns`}`,originalData:e};r.push(t),a.set(t.id,t)}),t.forEach(e=>{let t=(e.category||`general`).toLowerCase();if([`invariants`,`preferences`,`patterns`,`anti-patterns`].includes(t)){if(!p.rules)return}else if(!p.observations)return;let n={id:`memory-${e.slug}`,type:`memory`,title:e.title||e.slug,subtitle:`Memory Node • ${e.category||`general`}`,category:t,originalData:e};r.push(n),a.set(n.id,n);let i=e.slug?.toLowerCase(),l=e.title?.toLowerCase();i&&o.set(i,n),l&&s.set(l,n),c.has(t)||c.set(t,[]),c.get(t).push(n)}),p.research&&n.forEach(e=>{let t={id:`research-${e.id}`,type:`research`,title:e.topic,subtitle:`Research Topic • ${e.priority} priority`,originalData:e};r.push(t),a.set(t.id,t)}),r.forEach(e=>{if(e.type===`research`){let t=e.originalData;if(t.node_slug){let n=`memory-${t.node_slug}`;a.has(n)&&i.push({source:e.id,target:n,type:`research`,colorHex:`#fbbf24`})}}if(e.type===`memory`){let t=e.originalData;[`related`,`contradicts`,`supersedes`].forEach(n=>{let r=t[n];if(Array.isArray(r)){let t=n===`contradicts`?`#ef4444`:n===`supersedes`?`#f59e0b`:`#60a5fa`;r.forEach(r=>{let o=`memory-${r}`;a.has(o)&&i.push({source:e.id,target:o,type:n,colorHex:t})})}});let n=c.get(e.category)||[],r=0;for(let t=0;t<n.length&&r<2;t++){let a=n[t];a.id!==e.id&&a.id>e.id&&(i.push({source:e.id,target:a.id,type:`implicit`,colorHex:`#475569`}),r++)}let l=t.body||t.content||``;(l.match(/\[\[(.*?)\]\]/g)||[]).forEach(t=>{let n=t.slice(2,-2).split(`|`).pop()?.trim().toLowerCase();if(n){let t=o.get(n)||s.get(n);t&&t.id!==e.id&&i.push({source:e.id,target:t.id,type:`openwiki`,colorHex:`#a78bfa`})}}),Array.from(l.matchAll(/\[([^\]]+)\]\(([^)]+)\)/g)).forEach(t=>{let n=t[2]?.trim().toLowerCase();if(n&&!n.startsWith(`http`)){let t=o.get(n);t&&t.id!==e.id&&i.push({source:e.id,target:t.id,type:`openwiki`,colorHex:`#a78bfa`})}})}});let l={};return i.forEach(e=>{l[e.source]=(l[e.source]||0)+1,l[e.target]=(l[e.target]||0)+1}),r.forEach(e=>{if(e.val=Math.max(2,Math.min(10,Math.sqrt(l[e.id]||0)+1.5)),e.neighbors=new Set,e.type===`memory`){let t={invariants:`#38bdf8`,preferences:`#818cf8`,patterns:`#34d399`,"anti-patterns":`#f87171`,facts:`#60a5fa`,concepts:`#a78bfa`,decisions:`#fbbf24`,lore:`#c084fc`,corrections:`#fb923c`};e.color=t[e.category]||`#60a5fa`,[`invariants`,`preferences`,`patterns`,`anti-patterns`].includes(e.category)&&(t[e.category]||(e.color=`#818cf8`))}else e.type===`thread`?e.color=`#22d3ee`:e.type===`research`&&(e.color=`#fbbf24`)}),i.forEach(e=>{let t=a.get(e.source),n=a.get(e.target);t&&n&&(t.neighbors.add(n.id),n.neighbors.add(t.id))}),{nodes:r,links:i}},[e,t,n,p]);(0,v.useEffect)(()=>{s.current&&l.width>0&&setTimeout(()=>{s.current.zoomToFit(600,50)},800)},[h,l]),(0,v.useEffect)(()=>{h.nodes.forEach(e=>{if(e.__threeObj&&e.__threeObj.userData.isCustomNode){let t=!d||e===d||d.neighbors&&d.neighbors.has(e.id),n=e.__threeObj.children[0];n&&(t?n.material=OW(e.color):(n.userData.dimMaterial||(n.userData.dimMaterial=new zl({color:e.color,transparent:!0,opacity:.05})),n.material=n.userData.dimMaterial))}})},[d,h]),(0,v.useEffect)(()=>{s.current&&(s.current.d3Force(`charge`).strength(-150),s.current.d3Force(`link`).distance(e=>e.type===`implicit`?40:80),s.current.d3Force(`collide`,window.d3?.forceCollide?.(e=>e.val*2+3)))},[h]);let g=(0,v.useCallback)(e=>{if(!o)return;let t=Math.hypot(e.x,e.y,e.z),n=1+90/(t<.1?.1:t);s.current?.cameraPosition({x:e.x*n,y:e.y*n,z:e.z*n},e,1500),e.type===`memory`?i(e.originalData.slug):e.type===`thread`&&r(e.originalData.id)},[o,i,r]),_=(0,v.useCallback)(e=>{let t=new gc;t.userData.isCustomNode=!0;let n=new Zl(TW,OW(e.color)),r=e.val*1.8;if(n.scale.set(r,r,r),t.add(n),a.includes(e.originalData?.slug)){let e=new Zl(EW,OW(`#ffffff`,!0)),n=r+1.2;e.scale.set(n,n,n),e.rotation.x=Math.PI/2,t.add(e)}return t},[a]),y=(0,v.useCallback)(e=>{let t=typeof e.source==`object`?e.source.id:e.source,n=typeof e.target==`object`?e.target.id:e.target,r=!d||t===d?.id||n===d?.id,i=e.colorHex||`#475569`,a=parseInt(i.slice(1,3),16)||71,o=parseInt(i.slice(3,5),16)||85,s=parseInt(i.slice(5,7),16)||105,c=e.type===`implicit`?.2:.6;return`rgba(${a}, ${o}, ${s}, ${r?c:.02})`},[d]);return(0,z.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`,background:`radial-gradient(circle at center, #0a0f1d 0%, #03050a 100%)`},children:[l.width>0&&(0,z.jsx)(wW,{ref:s,width:l.width,height:l.height,graphData:h,nodeThreeObject:_,nodeLabel:e=>`<div style="background: rgba(10, 15, 30, 0.7); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); padding: 10px 14px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.1); box-shadow: 0 8px 32px rgba(0,0,0,0.5); font-family: var(--font-sans, system-ui); max-width: 250px;">
|
|
5245
5245
|
<strong style="color: #fff; font-size: 14px; display: block; margin-bottom: 2px;">${e.title}</strong>
|
|
5246
5246
|
<span style="color: #94a3b8; font-size: 12px; display: block;">${e.subtitle}</span>
|
|
5247
|
-
</div>`,enableNodeDrag:o,enableNavigationControls:o,onNodeClick:g,onNodeHover:e=>{f(e||null),c.current&&(c.current.style.cursor=e?`pointer`:`default`)},linkColor:y,linkWidth:e=>e.type===`implicit`?.5:1.5,linkDirectionalParticles:e=>e.type===`implicit`?0:2,linkDirectionalParticleWidth:1.5,linkDirectionalParticleSpeed:.005,backgroundColor:`rgba(0,0,0,0)`,d3VelocityDecay:.3}),(0,z.jsxs)(`div`,{style:{position:`absolute`,top:20,left:20,zIndex:30,pointerEvents:`none`},children:[(0,z.jsx)(`h3`,{style:{margin:0,fontSize:20,color:`#f8fafc`,fontWeight:600,letterSpacing:`-0.02em`,textShadow:`0 2px 10px rgba(0,0,0,0.5)`},children:`Constellation`}),(0,z.jsx)(`p`,{style:{margin:`2px 0 0`,fontSize:12,color:`rgba(148,163,184,0.9)`,textShadow:`0 1px 4px rgba(0,0,0,0.5)`},children:`Interactive Knowledge Network`})]}),o&&(0,z.jsxs)(`div`,{style:{position:`absolute`,top:80,left:20,display:`flex`,flexDirection:`column`,gap:12,background:`rgba(15, 20, 35, 0.4)`,backdropFilter:`blur(24px)`,WebkitBackdropFilter:`blur(24px)`,padding:`16px 20px`,borderRadius:16,border:`1px solid rgba(255, 255, 255, 0.08)`,boxShadow:`0 12px 40px rgba(0,0,0,0.3)`,width:240,zIndex:60,pointerEvents:`auto`,transition:`all 0.3s ease`},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`},children:[(0,z.jsx)(`span`,{style:{fontSize:10,fontWeight:700,color:`#cbd5e1`,textTransform:`uppercase`,letterSpacing:1.2},children:`Filters`}),(0,z.jsxs)(`span`,{style:{fontSize:10,background:`rgba(255,255,255,0.06)`,padding:`2px 6px`,borderRadius:6,color:`#94a3b8`},children:[h.nodes.length,` items`]})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:[(0,z.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:10,fontSize:12,color:`#e2e8f0`,cursor:`pointer`,userSelect:`none`},children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:p.research,onChange:()=>m(e=>({...e,research:!e.research})),style:{accentColor:`#fbbf24`,cursor:`pointer`}}),(0,z.jsx)(`span`,{style:{display:`inline-block`,width:8,height:8,borderRadius:`50%`,background:`#fbbf24`,boxShadow:`0 0 8px rgba(251,191,36,0.6)`}}),(0,z.jsx)(`span`,{style:{flex:1},children:`Research`})]}),(0,z.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:10,fontSize:12,color:`#e2e8f0`,cursor:`pointer`,userSelect:`none`},children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:p.observations,onChange:()=>m(e=>({...e,observations:!e.observations})),style:{accentColor:`#60a5fa`,cursor:`pointer`}}),(0,z.jsx)(`span`,{style:{display:`inline-block`,width:8,height:8,borderRadius:`50%`,background:`#60a5fa`,boxShadow:`0 0 8px rgba(96,165,250,0.6)`}}),(0,z.jsx)(`span`,{style:{flex:1},children:`Memory`})]}),(0,z.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:10,fontSize:12,color:`#e2e8f0`,cursor:`pointer`,userSelect:`none`},children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:p.rules,onChange:()=>m(e=>({...e,rules:!e.rules})),style:{accentColor:`#38bdf8`,cursor:`pointer`}}),(0,z.jsx)(`span`,{style:{display:`inline-block`,width:8,height:8,borderRadius:`50%`,background:`linear-gradient(135deg,#38bdf8,#f87171)`,boxShadow:`0 0 8px rgba(56,189,248,0.5)`}}),(0,z.jsx)(`span`,{style:{flex:1},children:`Rules`})]}),(0,z.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:10,fontSize:12,color:`#e2e8f0`,cursor:`pointer`,userSelect:`none`},children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:p.threads,onChange:()=>m(e=>({...e,threads:!e.threads})),style:{accentColor:`#22d3ee`,cursor:`pointer`}}),(0,z.jsx)(`span`,{style:{display:`inline-block`,width:8,height:8,borderRadius:`50%`,background:`#22d3ee`,boxShadow:`0 0 8px rgba(34,211,238,0.6)`}}),(0,z.jsx)(`span`,{style:{flex:1},children:`Sessions`})]})]})]})]})}function AW({onTranscript:e,isRecording:t=!1}){let[n,r]=(0,v.useState)(t),i=(0,v.useRef)(null),[a,o]=(0,v.useState)(!0);return(0,v.useEffect)(()=>{if(typeof window<`u`){let t=window,n=t.SpeechRecognition||t.webkitSpeechRecognition;n?(i.current=new n,i.current.continuous=!1,i.current.interimResults=!1,i.current.onresult=t=>{let n=t.results[0][0].transcript;e(n),r(!1)},i.current.onerror=()=>{r(!1)},i.current.onend=()=>{r(!1)}):setTimeout(()=>o(!1),0)}},[e]),a?(0,z.jsx)(`button`,{onClick:()=>{a&&(n?(i.current?.stop(),r(!1)):(i.current?.start(),r(!0)))},className:`btn btn-ghost ${n?`active`:``}`,style:{width:44,height:44,padding:0,display:`flex`,justifyContent:`center`,alignItems:`center`,background:n?`var(--error-muted)`:`rgba(148, 163, 184, 0.06)`,border:n?`1px solid var(--error)`:`1px solid var(--border)`,color:n?`var(--error)`:`var(--text-tertiary)`,transition:`all var(--transition-fast)`},title:n?`Stop recording`:`Start voice input`,children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z`}),(0,z.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,z.jsx)(`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`})]})}):(0,z.jsx)(`button`,{disabled:!0,className:`btn btn-ghost`,style:{width:44,height:44,padding:0,display:`flex`,justifyContent:`center`,alignItems:`center`,background:`rgba(148, 163, 184, 0.03)`,border:`1px solid var(--border)`,color:`var(--text-tertiary)`,opacity:.5,cursor:`not-allowed`},title:`Voice input not supported`,children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z`}),(0,z.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,z.jsx)(`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`})]})})}var jW=0;function MW(){return Date.now()}function NW(e){let t=MW()-e;if(t<6e4)return`just now`;let n=Math.floor(t/6e4);if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function PW({activeBrainId:e,onBrainChange:t}){let n=dt(),[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(!1),l=(0,v.useRef)(null),u=(0,v.useRef)(null),d=(0,v.useRef)(null),f=(0,v.useRef)(null),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(null),[w,T]=(0,v.useState)(null),[E,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(()=>localStorage.getItem(`tr-ext-banner-dismissed`)===`true`),[A,j]=(0,v.useState)(()=>localStorage.getItem(`tr-update-banner-dismissed-version`)),[ee,M]=(0,v.useState)([]),[te,ne]=(0,v.useState)(void 0),[N,P]=(0,v.useState)([]),[re,ie]=(0,v.useState)([]),[ae,oe]=(0,v.useState)([]),[se,ce]=(0,v.useState)(!1),[le,ue]=(0,v.useState)(``),de=(0,v.useRef)(null),[fe,pe]=(0,v.useState)([]),[me,he]=(0,v.useState)(()=>{let e=localStorage.getItem(`selectedModel`);return e&&e!==`gemini`?e:`antigravity`}),[ge,_e]=(0,v.useState)(()=>localStorage.getItem(`selectedSubModel`)||``),[ve,ye]=(0,v.useState)([]),[be,xe]=(0,v.useState)(!1),Se=(0,v.useRef)(null),F=(0,v.useCallback)(()=>{l.current?.scrollIntoView({behavior:`smooth`})},[]);(0,v.useEffect)(F,[r,F]);let Ce=(0,v.useCallback)(()=>{Qn().then(e=>{M(e)}).catch(console.error),Gr().then(e=>oe(e.items||[])).catch(console.error)},[]);(0,v.useEffect)(()=>{Qn().then(e=>{M(e),e.length>0&&(ne(e[0].id),e[0].brainId&&t&&t(e[0].brainId))}).catch(console.error),Gr().then(e=>oe(e.items||[])).catch(console.error),Yr().then(e=>{let t=e.cli_agents&&e.cli_agents.length>0?e.cli_agents:[`antigravity`,`grok`,`claude`,`codex`];pe(t);let n=localStorage.getItem(`selectedModel`);if(n&&t.includes(n))he(n);else{let e=t.includes(`antigravity`)?`antigravity`:t.includes(`grok`)?`grok`:t[0];he(e),localStorage.setItem(`selectedModel`,e)}}).catch(()=>{let e=[`antigravity`,`grok`,`claude`,`codex`];pe(e);let t=localStorage.getItem(`selectedModel`);t&&e.includes(t)?he(t):(he(`antigravity`),localStorage.setItem(`selectedModel`,`antigravity`))}),ci().then(e=>{if(ye(e),e&&e.length>0){let t=localStorage.getItem(`selectedSubModel`),n=e.some(e=>e.id===t);t&&n?_e(t):(_e(e[0].id),localStorage.setItem(`selectedSubModel`,e[0].id))}}).catch(console.error)},[]),(0,v.useEffect)(()=>{let e=!0,t=()=>{oi().then(t=>{e&&y(t)}).catch(console.error)};t();let n=setInterval(t,36e5);return()=>{e=!1,clearInterval(n)}},[]),(0,v.useEffect)(()=>{let t=!0,n=()=>{nr(e).then(e=>{t&&(ie(e),P(t=>t.filter(t=>e.some(e=>e.slug===t))))}).catch(console.error)};n();let r=new EventSource(`http://localhost:9111/stream`);return r.onmessage=e=>{if(t)try{let t=JSON.parse(e.data);(t.sender===`conflict-detector`||t.sender===`memory-ingestion`||t.message?.includes(`Surface compilation`)||t.message?.includes(`Brain embeddings rebuilt`)||t.message?.includes(`Graph indices rebuilt`)||t.message?.includes(`deleted`))&&n()}catch{}},()=>{t=!1,r.close()}},[e]),(0,v.useEffect)(()=>{function e(e){de.current&&!de.current.contains(e.target)&&ce(!1),Se.current&&!Se.current.contains(e.target)&&xe(!1)}return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[de,Se]),(0,v.useEffect)(()=>{Zn(te).then(e=>{e?(i(e),jW=Math.max(jW,e.length+1)):i([])}).catch(e=>{console.error(e),i([])})},[te]),(0,v.useEffect)(()=>{!p||h!==null||er().then(e=>g(e.enabled)).catch(()=>g(!1))},[p,h]),(0,v.useEffect)(()=>{O||mi().then(D).catch(()=>{})},[O]);let we=e=>{if(!(`speechSynthesis`in window))return;window.speechSynthesis.cancel();let t=new SpeechSynthesisUtterance(e);t.rate=1.05,t.pitch=.95,window.speechSynthesis.speak(t)},Te=async e=>{if(!(!p||!e.trim())){if(h===!1){we(e);return}try{let t=await tr(e);if(!t){g(!1),we(e);return}let n=URL.createObjectURL(t);f.current&&(f.current.pause(),URL.revokeObjectURL(f.current.src));let r=new Audio(n);f.current=r,r.onended=()=>URL.revokeObjectURL(n),r.play().catch(()=>we(e))}catch{we(e)}}},Ee=()=>{let e=`thread-${MW()}`;ne(e),i([]),o(``),P([]),u.current&&(u.current.style.height=`44px`)},De=async(e,t)=>{if(e.stopPropagation(),confirm(`Are you sure you want to delete this conversation thread?`))try{if(await $n(t),te===t){let e=ee.filter(e=>e.id!==t);e.length>0?ne(e[0].id):(ne(void 0),i([]))}Ce()}catch(e){console.error(`Failed to delete thread:`,e)}},I=async()=>{let t=a.trim();if(!t||s)return;let n=te||`thread-${MW()}`;te||ne(n);let l={id:String(++jW),role:`user`,content:t,timestamp:MW()};i(e=>[...e,l]),o(``),c(!0),d.current=new AbortController,u.current&&(u.current.style.height=`44px`);try{if(b){i(e=>[...e,{id:String(++jW),role:`assistant`,content:`🕵️ **Deep Research Agents dispatched.** Gathering facts across parallel web streams...`,timestamp:MW()}]);let{slug:e}=await ii(`proactive-research`,t,t),n=!1;for(;!n;){await new Promise(e=>setTimeout(e,2e3));let t=(await ri()).find(t=>t.slug===e);t&&(t.status===`completed`||t.status===`failed`)&&(n=!0,i(e=>e.filter(e=>e.content!==`🕵️ **Deep Research Agents dispatched.** Gathering facts across parallel web streams...`)),i(e=>[...e,{id:String(++jW),role:`assistant`,content:t.body||``,timestamp:MW()}]),Te(t.body||``))}c(!1);return}let a=[`gemini`,`antigravity`].includes(me)&&ge?`${me}:${ge}`:me,o=await Xn([...r,l].map(e=>({role:e.role,content:e.content})),d.current.signal,n,N,a,e),s={id:String(++jW),role:`assistant`,content:o,timestamp:MW(),versions:[o],currentVersionIndex:0};i(e=>[...e,s]),Te(o),Ce()}catch(e){if(e.name===`AbortError`)i(e=>[...e,{id:String(++jW),role:`assistant`,content:`⛔ Generation stopped by user.`,timestamp:MW(),versions:[`⛔ Generation stopped by user.`],currentVersionIndex:0}]);else{let t={id:String(++jW),role:`assistant`,content:`⚠️ Error: ${e.message}`,timestamp:MW(),versions:[`⚠️ Error: ${e.message}`],currentVersionIndex:0};i(e=>[...e,t])}}finally{c(!1),d.current=null}},Oe=async t=>{if(s)return;let n=r.slice(0,t).map(e=>({role:e.role,content:e.content}));c(!0),d.current=new AbortController;try{let r=[`gemini`,`antigravity`].includes(me)&&ge?`${me}:${ge}`:me,a=await Xn(n,d.current.signal,te,void 0,r,e);i(e=>{let n=[...e],r=n[t],i=r.versions||[r.content];return i.push(a),r.versions=i,r.currentVersionIndex=i.length-1,r.content=a,n}),Te(a),Ce()}catch(e){e.name!==`AbortError`&&console.error(e)}finally{c(!1),d.current=null}},ke=e=>{navigator.clipboard.writeText(e).catch(console.error)},Ae=(e,t)=>{i(n=>{let r=[...n],i=r[e];if(!i.versions)return n;let a=Math.max(0,Math.min(i.versions.length-1,(i.currentVersionIndex||0)+t));return i.currentVersionIndex=a,i.content=i.versions[a],r})},je=()=>{d.current&&(d.current.abort(),d.current=null,c(!1))},Me=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),I())},Ne=e=>{let t=e.target.value;o(t);let n=e.target;n.style.height=`44px`,n.style.height=Math.min(n.scrollHeight,160)+`px`;let r=t.match(/https?:\/\/[^\s]+/);C(r?r[0]:null)},Pe=async e=>{if(S)try{await ai({url:S,action:e}),T(`✅ URL sent to ${e}`),C(null),setTimeout(()=>T(null),3e3)}catch(e){console.error(`Share API error:`,e),T(`⚠️ Failed to process URL`),setTimeout(()=>T(null),3e3)}},Fe=re.filter(e=>e.title.toLowerCase().includes(le.toLowerCase())||e.slug.toLowerCase().includes(le.toLowerCase())||e.category&&e.category.toLowerCase().includes(le.toLowerCase()));return(0,z.jsxs)(`div`,{className:`chat-layout`,children:[(0,z.jsxs)(`aside`,{className:`chat-threads-sidebar`,children:[(0,z.jsx)(`div`,{className:`sidebar-header`,children:(0,z.jsxs)(`button`,{className:`new-chat-btn`,onClick:Ee,children:[(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{marginRight:6},children:[(0,z.jsx)(`line`,{x1:`12`,y1:`5`,x2:`12`,y2:`19`}),(0,z.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`})]}),`New Chat`]})}),(0,z.jsx)(`div`,{className:`thread-list`,children:ee.map(e=>(0,z.jsxs)(`div`,{className:`thread-item ${te===e.id?`active`:``}`,onClick:()=>{ne(e.id),e.brainId&&t&&t(e.brainId)},children:[(0,z.jsxs)(`div`,{className:`thread-info`,children:[(0,z.jsx)(`div`,{className:`thread-title`,title:e.title,children:e.title}),(0,z.jsxs)(`div`,{className:`thread-meta`,children:[(0,z.jsxs)(`span`,{children:[e.turns,` `,e.turns===1?`turn`:`turns`]}),(0,z.jsx)(`span`,{children:`•`}),(0,z.jsx)(`span`,{children:NW(e.lastUpdated)})]})]}),(0,z.jsx)(`button`,{className:`thread-delete-btn`,onClick:t=>De(t,e.id),title:`Delete chat thread`,children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`polyline`,{points:`3 6 5 6 21 6`}),(0,z.jsx)(`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`}),(0,z.jsx)(`line`,{x1:`10`,y1:`11`,x2:`10`,y2:`17`}),(0,z.jsx)(`line`,{x1:`14`,y1:`11`,x2:`14`,y2:`17`})]})})]},e.id))})]}),(0,z.jsxs)(`div`,{className:`chat-container`,style:{position:`relative`,overflow:`hidden`},children:[(0,z.jsx)(`div`,{"aria-hidden":!0,style:{position:`absolute`,top:0,left:0,right:0,bottom:0,zIndex:0,pointerEvents:`none`,opacity:r.length>0?.22:.55,transition:`opacity 0.3s ease`},children:(0,z.jsx)(kW,{threads:ee,memoryNodes:re,researchItems:ae,onOpenThread:()=>{},onGroundMemoryNode:()=>{},selectedGroundingNodes:N,interactive:!1})}),(0,z.jsxs)(`header`,{className:`chat-header animate-fade-in`,style:{position:`relative`,zIndex:40,overflow:`visible`},children:[(0,z.jsxs)(`div`,{className:`chat-header-title`,children:[(0,z.jsx)(`h2`,{children:`Chat Session`}),te&&(0,z.jsx)(`span`,{className:`badge badge-accent`,style:{textTransform:`none`,letterSpacing:`normal`,fontSize:`11px`,padding:`2px 8px`},children:te})]}),(0,z.jsxs)(`div`,{className:`chat-header-model-selector`,ref:Se,style:{position:`relative`,zIndex:50},children:[(0,z.jsx)(`span`,{className:`selector-label`,children:`Model / provider:`}),(0,z.jsxs)(`div`,{className:`model-selector-dropdown-wrapper`,style:{position:`relative`,zIndex:50},children:[(0,z.jsxs)(`button`,{type:`button`,className:`model-selector-dropdown-btn ${be?`active`:``}`,onClick:e=>{e.stopPropagation(),xe(e=>!e)},title:`Select CLI agent / provider`,children:[(0,z.jsx)(`span`,{style:{textTransform:`capitalize`},children:me||`Select Model`}),(0,z.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,z.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})]}),be&&(0,z.jsx)(`div`,{className:`model-selector-menu glass`,style:{zIndex:200,pointerEvents:`auto`},role:`listbox`,children:fe.map(e=>(0,z.jsxs)(`div`,{role:`option`,"aria-selected":me===e,className:`model-selector-item ${me===e?`selected`:``}`,onClick:t=>{t.stopPropagation(),he(e),localStorage.setItem(`selectedModel`,e),_e(``),localStorage.removeItem(`selectedSubModel`),xe(!1)},children:[(0,z.jsxs)(`div`,{className:`model-selector-item-info`,children:[(0,z.jsx)(`span`,{className:`model-selector-item-name`,style:{textTransform:`capitalize`},children:e}),(0,z.jsxs)(`span`,{className:`model-selector-item-desc`,children:[e===`antigravity`&&`Google Antigravity`,e===`grok`&&`xAI Grok Build CLI`,e===`gemini`&&`Google Gemini CLI`,e===`claude`&&`Anthropic Claude CLI`,e===`codex`&&`Codex Coding Agent`]})]}),(0,z.jsx)(`span`,{className:`model-selector-item-badge`,children:`CLI`})]},e))})]}),[`gemini`,`antigravity`].includes(me)&&ve.length>0&&(0,z.jsxs)(`div`,{className:`chat-header-submodel-selector`,style:{display:`flex`,alignItems:`center`,gap:8,marginLeft:16},children:[(0,z.jsx)(`span`,{className:`selector-label`,style:{fontSize:`12px`,color:`var(--text-tertiary)`,fontWeight:500},children:`Base:`}),(0,z.jsx)(`select`,{value:ge,onChange:e=>{_e(e.target.value),localStorage.setItem(`selectedSubModel`,e.target.value)},className:`submodel-select`,style:{background:`rgba(255, 255, 255, 0.04)`,border:`1px solid var(--border)`,borderRadius:`var(--radius-sm)`,color:`var(--text-secondary)`,padding:`6px 12px`,fontSize:`13px`,fontWeight:500,outline:`none`,cursor:`pointer`,transition:`all var(--transition-fast)`},children:ve.map(e=>(0,z.jsx)(`option`,{value:e.id,style:{background:`#12121a`,color:`var(--text-secondary)`},children:e.displayName},e.id))})]})]})]}),_?.updateAvailable&&A!==_.latestVersion&&(0,z.jsxs)(`div`,{className:`animate-fade-in`,style:{margin:`0 16px 12px`,padding:`12px 16px`,background:`linear-gradient(135deg, rgba(63, 185, 80, 0.12), rgba(34, 197, 94, 0.12))`,border:`1px solid rgba(63, 185, 80, 0.3)`,borderRadius:10,display:`flex`,alignItems:`center`,gap:12,position:`relative`,zIndex:40},children:[(0,z.jsx)(`span`,{style:{fontSize:22,flexShrink:0},children:`🚀`}),(0,z.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,z.jsx)(`div`,{style:{fontWeight:600,fontSize:13,color:`var(--text-primary)`,marginBottom:2},children:`System Update Available`}),(0,z.jsxs)(`div`,{style:{fontSize:11,color:`var(--text-secondary)`},children:[`Version `,_.latestVersion,` is available. Upgrade to load the latest features.`]})]}),(0,z.jsx)(`button`,{onClick:()=>n(`/health`),style:{flexShrink:0,padding:`6px 14px`,background:`#3fb950`,color:`#fff`,border:`none`,borderRadius:6,fontWeight:600,fontSize:12,cursor:`pointer`,whiteSpace:`nowrap`},children:`Go to Update`}),(0,z.jsx)(`button`,{onClick:()=>{_?.latestVersion&&(localStorage.setItem(`tr-update-banner-dismissed-version`,_.latestVersion),j(_.latestVersion))},title:`Dismiss banner`,"aria-label":`Dismiss update banner`,style:{background:`transparent`,border:`none`,color:`var(--text-muted)`,fontSize:16,cursor:`pointer`,padding:`4px 6px`,lineHeight:1},children:`✕`})]}),E?.available&&!E.connected&&!O&&(0,z.jsxs)(`div`,{style:{margin:`0 16px 0`,padding:`12px 16px`,background:`linear-gradient(135deg, rgba(108, 92, 231, 0.12), rgba(99, 179, 237, 0.12))`,border:`1px solid rgba(108, 92, 231, 0.3)`,borderRadius:10,display:`flex`,alignItems:`center`,gap:12,animation:`fadeIn 0.3s ease`,position:`relative`,zIndex:40},children:[(0,z.jsx)(`span`,{style:{fontSize:22,flexShrink:0},children:`🧩`}),(0,z.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,z.jsx)(`div`,{style:{fontWeight:600,fontSize:13,color:`var(--text-primary)`,marginBottom:2},children:`Chrome Extension Available`}),(0,z.jsx)(`div`,{style:{fontSize:11,color:`var(--text-secondary)`},children:`Browse with your brain — contextual memory, quick capture, and research from any page`})]}),(0,z.jsx)(`a`,{href:`/api/extension/download`,download:!0,style:{flexShrink:0,padding:`6px 14px`,background:`linear-gradient(135deg, #3b82f6, #93c5fd)`,color:`#fff`,borderRadius:6,fontWeight:500,fontSize:12,textDecoration:`none`,whiteSpace:`nowrap`},children:`⬇ Download`}),(0,z.jsx)(`button`,{onClick:()=>{k(!0),localStorage.setItem(`tr-ext-banner-dismissed`,`true`)},style:{flexShrink:0,background:`none`,border:`none`,color:`var(--text-tertiary)`,cursor:`pointer`,fontSize:16,padding:`0 2px`,lineHeight:1},title:`Dismiss`,children:`✕`})]}),(0,z.jsx)(`div`,{className:`chat-messages`,style:{position:`relative`,zIndex:1,pointerEvents:`auto`},children:(0,z.jsxs)(`div`,{style:{position:`relative`,display:`flex`,flexDirection:`column`,gap:`16px`,width:`100%`,maxWidth:800,margin:`0 auto`,pointerEvents:`auto`},children:[r.map((e,t)=>(0,z.jsxs)(`div`,{className:`message message-${e.role}`,style:{backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,background:e.role===`user`?`rgba(108, 92, 231, 0.75)`:`rgba(18, 18, 26, 0.75)`,border:`1px solid rgba(255, 255, 255, 0.08)`},children:[(0,z.jsx)(`div`,{style:{whiteSpace:`pre-wrap`,overflowWrap:`break-word`},children:e.content}),e.role===`assistant`&&(0,z.jsxs)(`div`,{style:{display:`flex`,gap:12,marginTop:12,fontSize:13,color:`var(--text-tertiary)`,alignItems:`center`,userSelect:`none`},children:[e.versions&&e.versions.length>1&&(0,z.jsxs)(`div`,{style:{display:`flex`,gap:6,alignItems:`center`,marginRight:4},children:[(0,z.jsx)(`button`,{onClick:()=>Ae(t,-1),disabled:(e.currentVersionIndex||0)===0,style:{background:`none`,border:`none`,color:`inherit`,cursor:`pointer`,padding:2,opacity:(e.currentVersionIndex||0)===0?.3:1},children:`◄`}),(0,z.jsxs)(`span`,{children:[(e.currentVersionIndex||0)+1,` / `,e.versions.length]}),(0,z.jsx)(`button`,{onClick:()=>Ae(t,1),disabled:(e.currentVersionIndex||0)===e.versions.length-1,style:{background:`none`,border:`none`,color:`inherit`,cursor:`pointer`,padding:2,opacity:(e.currentVersionIndex||0)===e.versions.length-1?.3:1},children:`►`})]}),(0,z.jsx)(`button`,{onClick:()=>ke(e.content),title:`Copy to clipboard`,style:{background:`none`,border:`none`,color:`inherit`,cursor:`pointer`,display:`flex`,alignItems:`center`,gap:4},children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`rect`,{x:`9`,y:`9`,width:`13`,height:`13`,rx:`2`,ry:`2`}),(0,z.jsx)(`path`,{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`})]})}),(0,z.jsx)(`button`,{onClick:()=>Te(e.content),title:`Read Aloud`,style:{background:`none`,border:`none`,color:`inherit`,cursor:`pointer`,display:`flex`,alignItems:`center`,gap:4},children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`polygon`,{points:`11 5 6 9 2 9 2 15 6 15 11 19 11 5`}),(0,z.jsx)(`path`,{d:`M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07`})]})}),(0,z.jsx)(`button`,{onClick:()=>Oe(t),disabled:s,title:`Regenerate Response`,style:{background:`none`,border:`none`,color:`inherit`,cursor:s?`default`:`pointer`,display:`flex`,alignItems:`center`,gap:4,opacity:s?.3:1},children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`polyline`,{points:`1 4 1 10 7 10`}),(0,z.jsx)(`polyline`,{points:`23 20 23 14 17 14`}),(0,z.jsx)(`path`,{d:`M20.49 9A9 9 0 0 0 5.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 0 1 3.51 15`})]})})]})]},e.id)),s&&(0,z.jsx)(`div`,{className:`message message-assistant`,style:{backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,background:`rgba(18, 18, 26, 0.75)`,border:`1px solid rgba(255, 255, 255, 0.08)`},children:(0,z.jsx)(`span`,{className:`skeleton`,style:{display:`inline-block`,width:180,height:16}})}),(0,z.jsx)(`div`,{ref:l})]})}),(0,z.jsxs)(`div`,{className:`chat-input-bar`,style:{position:`relative`,zIndex:30,pointerEvents:`auto`},children:[N.length>0&&(0,z.jsx)(`div`,{className:`grounding-pills`,children:N.map(e=>{let t=re.find(t=>t.slug===e);return(0,z.jsxs)(`div`,{className:`grounding-pill animate-fade-in`,children:[(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`path`,{d:`M4 19.5A2.5 2.5 0 0 1 6.5 17H20`}),(0,z.jsx)(`path`,{d:`M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z`})]}),(0,z.jsx)(`span`,{className:`grounding-pill-title`,children:t?.title||e}),(0,z.jsx)(`button`,{className:`grounding-pill-remove`,onClick:()=>P(t=>t.filter(t=>t!==e)),title:`Remove grounding context`,children:`×`})]},e)})}),(0,z.jsxs)(`div`,{className:`chat-input-wrapper`,children:[(0,z.jsx)(`button`,{className:`btn btn-ghost ${b?`active`:``}`,style:{width:44,height:44,padding:0,display:`flex`,justifyContent:`center`,alignItems:`center`,color:b?`var(--accent)`:`var(--text-tertiary)`,borderColor:b?`var(--accent)`:`var(--border)`},onClick:()=>x(!b),title:b?`Deep Research On`:`Deep Research Off`,children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{width:18,height:18},children:[(0,z.jsx)(`path`,{d:`M12 2v20`}),(0,z.jsx)(`path`,{d:`M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6`})]})}),(0,z.jsxs)(`div`,{style:{position:`relative`,display:`flex`},ref:de,children:[(0,z.jsxs)(`button`,{className:`btn btn-ghost ${N.length>0?`active`:``}`,style:{width:44,height:44,padding:0,display:`flex`,justifyContent:`center`,alignItems:`center`,color:N.length>0?`var(--accent)`:`var(--text-tertiary)`,borderColor:N.length>0?`var(--accent)`:`var(--border)`},onClick:()=>ce(!se),title:`Ground with brain nodes`,children:[(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{width:18,height:18},children:[(0,z.jsx)(`path`,{d:`M4 19.5A2.5 2.5 0 0 1 6.5 17H20`}),(0,z.jsx)(`path`,{d:`M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z`})]}),N.length>0&&(0,z.jsx)(`span`,{className:`grounding-count-badge`,children:N.length})]}),se&&(0,z.jsxs)(`div`,{className:`node-selector-popover glass`,children:[(0,z.jsxs)(`div`,{className:`node-selector-header`,children:[(0,z.jsx)(`h4`,{children:`Ground with Brain Nodes`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`Search nodes...`,value:le,onChange:e=>ue(e.target.value),className:`node-search-input`,autoFocus:!0})]}),(0,z.jsx)(`div`,{className:`node-selector-list`,children:Fe.length===0?(0,z.jsx)(`div`,{className:`node-selector-empty`,children:`No nodes found`}):Fe.map(e=>{let t=N.includes(e.slug);return(0,z.jsxs)(`div`,{className:`node-selector-item ${t?`selected`:``}`,onClick:()=>{P(t?t=>t.filter(t=>t!==e.slug):t=>[...t,e.slug])},children:[(0,z.jsx)(`span`,{className:`node-selector-item-checkbox`,children:t?`✓`:``}),(0,z.jsxs)(`div`,{className:`node-selector-item-info`,children:[(0,z.jsx)(`span`,{className:`node-selector-item-title`,children:e.title}),(0,z.jsxs)(`span`,{className:`node-selector-item-meta`,children:[e.category,` • `,e.status||`active`]})]})]},e.slug)})})]})]}),(0,z.jsx)(AW,{onTranscript:e=>{o(t=>t+(t.endsWith(` `)||t===``?``:` `)+e),setTimeout(()=>{if(u.current){u.current.focus();let e=new Event(`input`,{bubbles:!0});u.current.dispatchEvent(e)}},10)}}),(0,z.jsxs)(`div`,{style:{position:`relative`,flex:1,display:`flex`,alignItems:`center`},children:[(0,z.jsx)(`textarea`,{ref:u,id:`chat-input`,value:a,onChange:Ne,onKeyDown:Me,placeholder:`Message your brain…`,rows:1,disabled:s,style:{paddingRight:44}}),(0,z.jsx)(`button`,{className:`btn btn-ghost ${p?`active`:``}`,style:{position:`absolute`,right:4,bottom:4,width:36,height:36,padding:0,display:`flex`,justifyContent:`center`,alignItems:`center`,color:p?`#ef4444`:`var(--text-tertiary)`,border:`none`,background:`transparent`},onClick:()=>{m(!p),p&&`speechSynthesis`in window&&window.speechSynthesis.cancel()},title:p?`Voice Mode On`:`Voice Mode Off`,children:p?(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{width:18,height:18},children:[(0,z.jsx)(`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z`}),(0,z.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,z.jsx)(`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`}),(0,z.jsx)(`line`,{x1:`8`,x2:`16`,y1:`22`,y2:`22`})]}):(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{width:18,height:18},children:[(0,z.jsx)(`line`,{x1:`1`,x2:`23`,y1:`1`,y2:`23`}),(0,z.jsx)(`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12M15 9.34V5a3 3 0 0 0-5.94-.88`}),(0,z.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-1.39 4.2M5 10v2a7 7 0 0 0 1.93 4.88`}),(0,z.jsx)(`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`}),(0,z.jsx)(`line`,{x1:`8`,x2:`16`,y1:`22`,y2:`22`})]})})]}),s?(0,z.jsx)(`button`,{className:`chat-send-btn`,onClick:je,id:`chat-stop`,style:{background:`var(--error)`,color:`#fff`},title:`Stop Generation`,children:(0,z.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`currentColor`,style:{width:20,height:20},children:(0,z.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`,ry:`2`})})}):(0,z.jsx)(`button`,{className:`chat-send-btn`,onClick:I,disabled:!a.trim(),id:`chat-send`,title:`Send Message`,children:(0,z.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,z.jsx)(`path`,{d:`M3.478 2.405a.75.75 0 00-.926.94l2.432 7.905H13.5a.75.75 0 010 1.5H4.984l-2.432 7.905a.75.75 0 00.926.94 60.519 60.519 0 0018.445-8.986.75.75 0 000-1.218A60.517 60.517 0 003.478 2.405z`})})})]}),S&&(0,z.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,padding:`8px 12px`,background:`var(--bg-secondary, #1e1e2e)`,borderRadius:`8px`,alignItems:`center`,fontSize:`0.85rem`,marginTop:4},children:[(0,z.jsx)(`span`,{style:{color:`var(--text-secondary)`},children:`🔗 URL detected`}),(0,z.jsx)(`button`,{className:`btn btn-sm`,onClick:()=>Pe(`research`),children:`🔬 Research`}),(0,z.jsx)(`button`,{className:`btn btn-sm`,onClick:()=>Pe(`remember`),children:`📌 Remember`})]}),w&&(0,z.jsx)(`div`,{style:{padding:`6px 12px`,background:`rgba(46, 204, 113, 0.1)`,border:`1px solid rgba(46, 204, 113, 0.3)`,borderRadius:`8px`,fontSize:`0.8rem`,color:`var(--success)`,marginTop:4,textAlign:`center`},children:w})]})]})]})}var FW=[`all`,`invariants`,`preferences`,`anti-patterns`,`patterns`,`decisions`,`concepts`,`facts`,`lore`];function IW(e){if(!e)return``;let t=e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`);return t=t.replace(/^### (.*$)/gim,`<h3>$1</h3>`),t=t.replace(/^## (.*$)/gim,`<h2>$1</h2>`),t=t.replace(/^# (.*$)/gim,`<h1>$1</h1>`),t=t.replace(/\*\*(.*?)\*\*/g,`<strong>$1</strong>`),t=t.replace(/\*(.*?)\*/g,`<em>$1</em>`),t=t.replace(/```([\s\S]*?)```/g,`<pre style="background:rgba(0,0,0,0.3);padding:12px;border-radius:6px;border:1px solid rgba(255,255,255,0.06);font-family:monospace;overflow-x:auto;"><code>$1</code></pre>`),t=t.replace(/`(.*?)`/g,`<code style="background:rgba(255,255,255,0.06);padding:2px 6px;border-radius:4px;font-family:monospace;">$1</code>`),t=t.replace(/^> (.*$)/gim,`<blockquote style="border-left:4px solid var(--purple-primary);padding-left:14px;color:var(--text-secondary);margin:16px 0;font-style:italic;">$1</blockquote>`),t=t.replace(/^- (.*$)/gim,`<li style="margin-left:20px;list-style-type:disc;">$1</li>`),t=t.replace(/\n/g,`<br />`),(0,z.jsx)(`div`,{dangerouslySetInnerHTML:{__html:t},className:`markdown-preview-block`})}function LW({activeBrainId:e}){let[t,n]=jn(),r=t.get(`slug`),[i,a]=(0,v.useState)(`vault`),[o,s]=(0,v.useState)([]),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(`all`),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)([]),[x,S]=(0,v.useState)(0),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)([]),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(!1),[j,ee]=(0,v.useState)(!1),[M,te]=(0,v.useState)(``),[ne,N]=(0,v.useState)(``),[P,re]=(0,v.useState)(`invariants`),[ie,ae]=(0,v.useState)(``),[oe,se]=(0,v.useState)(`active`),[ce,le]=(0,v.useState)(`low`),[ue,de]=(0,v.useState)(`should`),[fe,pe]=(0,v.useState)(1),[me,he]=(0,v.useState)(3),[ge,_e]=(0,v.useState)(``),[ve,ye]=(0,v.useState)(``),[be,xe]=(0,v.useState)(``),[Se,F]=(0,v.useState)(``),Ce=(0,v.useCallback)(async()=>{h(!0),_(``);try{if(f.trim()){let e=await rr(f,u===`all`?void 0:u);s(e)}else{let t=await nr(e,u===`all`?void 0:u);s(t)}}catch(e){_(e.message),s([])}finally{h(!1)}},[u,f,e]);(0,v.useEffect)(()=>{c&&(te(c.slug||``),N(c.title||``),re(c.category||`invariants`),ae(c.content||c.body||``),se(c.status||`active`),le(c.priority||`low`),de(c.modality||`should`),pe(c.confidence??1),he(c.importance??3),_e((c.tags||[]).join(`, `)),ye((c.related||[]).join(`, `)),xe((c.contradicts||[]).join(`, `)),F((c.supersedes||[]).join(`, `)))},[c]);let we=async()=>{if(c){h(!0),_(``);try{let t=ge.split(`,`).map(e=>e.trim()).filter(Boolean),n=ve.split(`,`).map(e=>e.trim()).filter(Boolean),r=be.split(`,`).map(e=>e.trim()).filter(Boolean),i=Se.split(`,`).map(e=>e.trim()).filter(Boolean),a=await ar(c.slug,{title:ne,category:P,content:ie,status:oe,priority:ce,modality:ue,confidence:fe,importance:me,tags:t,related:n,contradicts:r,supersedes:i},e);l(a),A(!1),Ce()}catch(e){_(e.message)}finally{h(!1)}}},Te=async()=>{if(!M.trim()||!ne.trim()||!ie.trim()){_(`Slug, Title, and Content are required fields.`);return}h(!0),_(``);try{let t=ge.split(`,`).map(e=>e.trim()).filter(Boolean),r=ve.split(`,`).map(e=>e.trim()).filter(Boolean),i=be.split(`,`).map(e=>e.trim()).filter(Boolean),a=Se.split(`,`).map(e=>e.trim()).filter(Boolean),o=await or({slug:M,title:ne,category:P,content:ie,status:oe,priority:ce,modality:ue,confidence:fe,importance:me,tags:t,related:r,contradicts:i,supersedes:a},e);ee(!1),l(o),n({slug:o.slug}),Ce()}catch(e){_(e.message)}finally{h(!1)}},Ee=async t=>{if(window.confirm(`Are you sure you want to delete memory node "${t}"?`)){h(!0),_(``);try{await sr(t,e),l(null),n({}),Ce()}catch(e){_(e.message)}finally{h(!1)}}},De=(0,v.useCallback)(async()=>{try{let e=await cr();E(e.conflicts||[])}catch(e){console.warn(`Conflicts API error (enhanced features might be disabled):`,e)}},[]);(0,v.useEffect)(()=>{let e=setTimeout(Ce,300);return()=>clearTimeout(e)},[Ce]);let I=(0,v.useCallback)(async()=>{w(!0);try{let e=await hi(100);b(e.sessions),S(e.total)}catch(e){_(e.message)}finally{w(!1)}},[]);(0,v.useEffect)(()=>{i===`conflicts`?De():i===`sessions`&&I()},[i,De,I]);let Oe=async e=>{if(window.confirm(`Delete session "${e}"?`))try{await gi(e),I()}catch(e){_(e.message)}};(0,v.useEffect)(()=>{r?(async()=>{let t=o.find(e=>e.slug===r);if(t&&(t.content||t.body)){l(t),_(``);return}h(!0),_(``);try{let n=await ir(r,e);n?l(n):t?l(t):(_(`Memory node not found: ${r}`),l(null))}catch(e){t?(l(t),_(``)):(_(`Failed to load memory node '${r}': ${e.message}`),l(null))}finally{h(!1)}})():l(null)},[r,e,o]),(0,v.useEffect)(()=>{let e=new EventSource(`http://localhost:9111/stream`);return e.onmessage=e=>{try{let t=JSON.parse(e.data);(t.subsystem===`conflict-detector`||t.subsystem===`rebuild`||t.subsystem===`session-watcher`)&&(Ce(),De())}catch{}},e.onerror=()=>{e.close()},()=>{e.close()}},[Ce,De]);let ke=e=>{l(e),_(``),n({slug:e.slug})},Ae=async(e,t,n)=>{O(e),_(``);try{await lr(e,t,n),await De(),await Ce()}catch(e){_(e.message)}finally{O(null)}},je=(e,t,n)=>(0,z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:[(0,z.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:16},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Slug (kebab-case, matches filename)`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`e.g. prefer-atomic-writes`,value:M,onChange:e=>te(e.target.value),disabled:!n,style:{width:`100%`,background:`rgba(255,255,255,0.03)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`}})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Title (One-line description)`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`e.g. Always write files atomically (write-then-rename)`,value:ne,onChange:e=>N(e.target.value),style:{width:`100%`,background:`rgba(255,255,255,0.03)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`}})]}),(0,z.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:12},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Category`}),(0,z.jsxs)(`select`,{value:P,onChange:e=>re(e.target.value),style:{width:`100%`,background:`rgba(15,23,42,0.9)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`},children:[(0,z.jsx)(`option`,{value:`invariants`,children:`invariants`}),(0,z.jsx)(`option`,{value:`patterns`,children:`patterns`}),(0,z.jsx)(`option`,{value:`anti-patterns`,children:`anti-patterns`}),(0,z.jsx)(`option`,{value:`preferences`,children:`preferences`}),(0,z.jsx)(`option`,{value:`decisions`,children:`decisions`}),(0,z.jsx)(`option`,{value:`concepts`,children:`concepts`}),(0,z.jsx)(`option`,{value:`facts`,children:`facts`}),(0,z.jsx)(`option`,{value:`lore`,children:`lore`})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Modality`}),(0,z.jsxs)(`select`,{value:ue,onChange:e=>de(e.target.value),style:{width:`100%`,background:`rgba(15,23,42,0.9)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`},children:[(0,z.jsx)(`option`,{value:`must`,children:`must`}),(0,z.jsx)(`option`,{value:`must_not`,children:`must_not`}),(0,z.jsx)(`option`,{value:`should`,children:`should`}),(0,z.jsx)(`option`,{value:`should_not`,children:`should_not`})]})]})]})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,z.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:12},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Status`}),(0,z.jsxs)(`select`,{value:oe,onChange:e=>se(e.target.value),style:{width:`100%`,background:`rgba(15,23,42,0.9)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`},children:[(0,z.jsx)(`option`,{value:`active`,children:`active`}),(0,z.jsx)(`option`,{value:`draft`,children:`draft`}),(0,z.jsx)(`option`,{value:`deprecated`,children:`deprecated`}),(0,z.jsx)(`option`,{value:`superseded`,children:`superseded`})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Importance (1-5 Stars)`}),(0,z.jsxs)(`select`,{value:me,onChange:e=>he(Number(e.target.value)),style:{width:`100%`,background:`rgba(15,23,42,0.9)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`},children:[(0,z.jsx)(`option`,{value:1,children:`★ 1/5`}),(0,z.jsx)(`option`,{value:2,children:`★★ 2/5`}),(0,z.jsx)(`option`,{value:3,children:`★★★ 3/5`}),(0,z.jsx)(`option`,{value:4,children:`★★★★ 4/5`}),(0,z.jsx)(`option`,{value:5,children:`★★★★★ 5/5`})]})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:[`Confidence: `,(0,z.jsxs)(`strong`,{children:[Math.round(fe*100),`%`]})]}),(0,z.jsx)(`input`,{type:`range`,min:`0`,max:`1`,step:`0.05`,value:fe,onChange:e=>pe(Number(e.target.value)),style:{width:`100%`,height:6,background:`rgba(255,255,255,0.1)`,borderRadius:3,outline:`none`}})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Tags (comma separated)`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`e.g. filesystem, reliability, writes`,value:ge,onChange:e=>_e(e.target.value),style:{width:`100%`,background:`rgba(255,255,255,0.03)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`}})]})]})]}),(0,z.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr 1fr`,gap:12},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Related Nodes (comma separated slugs)`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`e.g. use-atomic-writes, git-wiping`,value:ve,onChange:e=>ye(e.target.value),style:{width:`100%`,background:`rgba(255,255,255,0.03)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`}})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Contradicts Nodes (comma separated slugs)`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`e.g. write-anywhere-sync`,value:be,onChange:e=>xe(e.target.value),style:{width:`100%`,background:`rgba(255,255,255,0.03)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`}})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Supersedes Nodes (comma separated slugs)`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`e.g. prefer-atomic-writes-v1`,value:Se,onChange:e=>F(e.target.value),style:{width:`100%`,background:`rgba(255,255,255,0.03)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`}})]})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,z.jsx)(`label`,{style:{fontSize:12,color:`var(--text-secondary)`},children:`Memory Content`}),(0,z.jsx)(`textarea`,{value:ie,onChange:e=>ae(e.target.value),placeholder:`Write markdown here...`,style:{minHeight:300,padding:16,color:`#fff`,background:`#090d16`,border:`1px solid var(--border)`,borderRadius:8,outline:`none`,fontSize:14,lineHeight:1.6,resize:`vertical`,width:`100%`,boxSizing:`border-box`}})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:12,marginTop:12},children:[(0,z.jsx)(`button`,{className:`btn btn-ghost`,type:`button`,onClick:t,style:{fontSize:13},children:`Cancel`}),(0,z.jsx)(`button`,{className:`btn btn-purple`,type:`button`,onClick:e,style:{fontSize:13},children:n?`🚀 Create Memory Node`:`💾 Save Changes`})]})]}),Me=o.reduce((e,t)=>(e[t.category]=(e[t.category]||0)+1,e),{});return(0,z.jsxs)(`div`,{className:`page`,children:[(0,z.jsxs)(`div`,{className:`page-header`,style:{display:`flex`,justifyContent:`space-between`,alignItems:`flex-end`,marginBottom:20},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h1`,{children:`Memory Vault`}),(0,z.jsx)(`p`,{children:`Browse, audit, and resolve contradictions in your SSSS knowledge graph`})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,background:`rgba(255,255,255,0.03)`,padding:4,borderRadius:8,border:`1px solid var(--border)`},children:[(0,z.jsx)(`button`,{className:`btn btn-sm ${i===`vault`?`btn-purple`:`btn-ghost`}`,onClick:()=>{a(`vault`),l(null),n({})},style:{borderRadius:6,fontSize:12,padding:`6px 12px`},children:`🧠 Active Nodes`}),(0,z.jsxs)(`button`,{className:`btn btn-sm ${i===`conflicts`?`btn-cyan`:`btn-ghost`}`,onClick:()=>{a(`conflicts`),l(null),n({})},style:{borderRadius:6,fontSize:12,padding:`6px 12px`,display:`flex`,alignItems:`center`,gap:6},children:[`⚠️ Quarantined Conflicts`,T.length>0&&(0,z.jsx)(`span`,{style:{background:`#ef4444`,color:`#fff`,fontSize:9,padding:`1px 5px`,borderRadius:10,fontWeight:700},children:T.length})]}),(0,z.jsxs)(`button`,{className:`btn btn-sm ${i===`sessions`?`btn-purple`:`btn-ghost`}`,onClick:()=>{a(`sessions`),l(null),n({})},style:{borderRadius:6,fontSize:12,padding:`6px 12px`},children:[`📝 Sessions`,x>0&&(0,z.jsx)(`span`,{style:{background:`rgba(139,92,246,0.3)`,color:`#a78bfa`,fontSize:9,padding:`1px 5px`,borderRadius:10,fontWeight:700,marginLeft:4},children:x})]})]})]}),g&&(0,z.jsxs)(`div`,{className:`badge badge-error`,style:{alignSelf:`flex-start`,marginBottom:15},children:[`⚠️ `,g]}),i===`vault`?(0,z.jsxs)(`div`,{className:`memory-layout`,children:[(0,z.jsxs)(`div`,{className:`memory-sidebar`,children:[(0,z.jsx)(`h3`,{style:{margin:`0 0 12px 0`},children:`Categories`}),FW.map(e=>(0,z.jsxs)(`button`,{className:`category-btn ${u===e?`active`:``}`,onClick:()=>{d(e),n({}),ee(!1),A(!1)},children:[(0,z.jsx)(`span`,{children:e===`all`?`📋 All Nodes`:e}),e===`all`?(0,z.jsx)(`span`,{className:`category-count`,children:o.length}):Me[e]?(0,z.jsx)(`span`,{className:`category-count`,children:Me[e]}):null]},e)),(0,z.jsx)(`button`,{className:`btn btn-purple`,style:{width:`100%`,marginTop:20,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:8,fontSize:13},onClick:()=>{l(null),n({}),ee(!0),A(!1),te(``),N(``),re(`invariants`),ae(``),se(`active`),le(`low`),de(`should`),pe(1),he(3),_e(``),ye(``),xe(``),F(``)},children:`➕ Create New Node`})]}),(0,z.jsxs)(`div`,{className:`memory-main`,children:[(0,z.jsxs)(`div`,{className:`memory-search`,children:[(0,z.jsx)(`input`,{id:`memory-search`,type:`text`,placeholder:`Search memory nodes…`,value:f,onChange:e=>p(e.target.value)}),(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:Ce,children:`Refresh`})]}),m?(0,z.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[1,2,3].map(e=>(0,z.jsx)(`div`,{className:`skeleton`,style:{height:60}},e))}):j?(0,z.jsxs)(`div`,{className:`memory-detail`,style:{background:`rgba(15,23,42,0.45)`,backdropFilter:`blur(12px)`,border:`1px solid var(--border)`,borderRadius:12,padding:24},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:20},children:[(0,z.jsx)(`h2`,{style:{margin:0,color:`#fff`},children:`Create New SSSS Memory Node`}),(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>ee(!1),style:{fontSize:12},children:`← Back to List`})]}),je(Te,()=>ee(!1),!0)]}):c&&k?(0,z.jsxs)(`div`,{className:`memory-detail`,style:{background:`rgba(15,23,42,0.45)`,backdropFilter:`blur(12px)`,border:`1px solid var(--border)`,borderRadius:12,padding:24},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:20},children:[(0,z.jsx)(`h2`,{style:{margin:0,color:`#fff`},children:`Edit Memory Node`}),(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>A(!1),style:{fontSize:12},children:`← Cancel Edit`})]}),je(we,()=>A(!1),!1)]}):c?(0,z.jsxs)(`div`,{className:`memory-detail`,style:{background:`rgba(15,23,42,0.45)`,backdropFilter:`blur(12px)`,border:c.modality===`must`?`2px solid #10b981`:c.modality===`must_not`?`2px solid #ef4444`:c.modality===`should`?`1px solid #8b5cf6`:c.modality===`should_not`?`1px solid #f97316`:`1px solid var(--border)`,boxShadow:c.modality===`must`?`0 0 16px rgba(16, 185, 129, 0.1)`:c.modality===`must_not`?`0 0 16px rgba(239, 68, 68, 0.1)`:void 0,borderRadius:12,padding:24},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`flex-start`,marginBottom:16},children:[(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>n({}),style:{fontSize:12},children:`← Back to List`}),(0,z.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>{te(c.slug||``),N(c.title||``),re(c.category||`invariants`),ae(c.content||c.body||``),se(c.status||`active`),le(c.priority||`low`),de(c.modality||`should`),pe(c.confidence??1),he(c.importance??3),_e((c.tags||[]).join(`, `)),ye((c.related||[]).join(`, `)),xe((c.contradicts||[]).join(`, `)),F((c.supersedes||[]).join(`, `)),A(!0)},style:{fontSize:12,border:`1px solid var(--border)`},children:`✏️ Edit Node`}),(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>Ee(c.slug),style:{fontSize:12,borderColor:`rgba(239,68,68,0.2)`,color:`#fca5a5`},children:`🗑️ Delete`})]})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:12},children:[(0,z.jsx)(`h2`,{style:{margin:0,color:`#fff`},children:c.title}),c.modality&&(0,z.jsx)(`span`,{style:{fontSize:10,fontWeight:700,textTransform:`uppercase`,padding:`4px 10px`,borderRadius:6,background:c.modality===`must`?`rgba(16, 185, 129, 0.15)`:c.modality===`must_not`?`rgba(239, 68, 68, 0.15)`:`rgba(255, 255, 255, 0.05)`,color:c.modality===`must`?`#10b981`:c.modality===`must_not`?`#ef4444`:`var(--text-secondary)`,border:c.modality===`must`?`1px solid rgba(16, 185, 129, 0.3)`:c.modality===`must_not`?`1px solid rgba(239, 68, 68, 0.3)`:`1px solid rgba(255, 255, 255, 0.1)`},children:c.modality})]}),(0,z.jsxs)(`dl`,{className:`frontmatter`,style:{display:`grid`,gridTemplateColumns:`120px 1fr`,gap:`10px 20px`,marginBottom:24,paddingBottom:16,borderBottom:`1px solid rgba(255,255,255,0.06)`},children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Slug`}),(0,z.jsx)(`dd`,{style:{margin:0},children:(0,z.jsx)(`code`,{children:c.slug})}),(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Category`}),(0,z.jsx)(`dd`,{style:{margin:0,textTransform:`capitalize`},children:c.category}),c.status&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Status`}),(0,z.jsx)(`dd`,{style:{margin:0},children:(0,z.jsx)(`span`,{className:`badge badge-success`,style:{background:c.status===`active`?`rgba(34, 197, 94, 0.15)`:`rgba(255,255,255,0.05)`,color:c.status===`active`?`#22c55e`:`var(--text-secondary)`},children:c.status})})]}),c.confidence!==void 0&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Confidence`}),(0,z.jsxs)(`dd`,{style:{margin:0,display:`flex`,alignItems:`center`,gap:12},children:[(0,z.jsxs)(`strong`,{style:{fontSize:13},children:[Math.round(c.confidence*100),`%`]}),(0,z.jsx)(`div`,{style:{flex:1,maxWidth:150,height:6,background:`rgba(255,255,255,0.06)`,borderRadius:3,overflow:`hidden`,display:`inline-block`},children:(0,z.jsx)(`div`,{style:{width:`${Math.round(c.confidence*100)}%`,height:`100%`,background:`linear-gradient(90deg, #8b5cf6, #06b6d4)`,borderRadius:3}})})]})]}),c.importance!==void 0&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Importance`}),(0,z.jsx)(`dd`,{style:{margin:0,color:`#fbbf24`,display:`flex`,gap:2},children:Array.from({length:5}).map((e,t)=>(0,z.jsx)(`span`,{children:t<(c.importance||0)?`★`:`☆`},t))})]}),c.tags?.length?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Tags`}),(0,z.jsx)(`dd`,{style:{margin:0,display:`flex`,gap:6,flexWrap:`wrap`},children:c.tags.map(e=>(0,z.jsx)(`span`,{style:{background:`rgba(255,255,255,0.05)`,color:`var(--text-secondary)`,fontSize:10,padding:`2px 8px`,borderRadius:4,border:`1px solid rgba(255,255,255,0.03)`},children:e},e))})]}):null,c.related?.length?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Related`}),(0,z.jsx)(`dd`,{style:{margin:0},children:(0,z.jsx)(`code`,{children:c.related.join(`, `)})})]}):null,c.contradicts?.length?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Contradicts`}),(0,z.jsx)(`dd`,{style:{margin:0,color:`#fca5a5`},children:(0,z.jsx)(`code`,{children:c.contradicts.join(`, `)})})]}):null,c.supersedes?.length?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Supersedes`}),(0,z.jsx)(`dd`,{style:{margin:0,color:`#93c5fd`},children:(0,z.jsx)(`code`,{children:c.supersedes.join(`, `)})})]}):null]}),(0,z.jsxs)(`div`,{style:{marginTop:20},children:[(0,z.jsx)(`h3`,{style:{fontSize:12,textTransform:`uppercase`,color:`var(--text-tertiary)`,letterSpacing:.5,marginBottom:12},children:`Memory Content (SSSS Body)`}),(0,z.jsx)(`div`,{style:{background:`rgba(0,0,0,0.15)`,border:`1px solid rgba(255,255,255,0.04)`,borderRadius:8,padding:20},children:IW(c.body||c.content||``)})]})]}):(0,z.jsxs)(`div`,{className:`memory-list`,style:{display:`grid`,gridTemplateColumns:`1fr`,gap:12},children:[o.length===0&&!m&&(0,z.jsx)(`div`,{style:{textAlign:`center`,padding:40,color:`var(--text-tertiary)`},children:f?`No matching nodes found.`:u===`all`?`No memory nodes loaded. Is the backend running?`:`No memory nodes found in category "${u}".`}),o.map(e=>{let t=e.modality===`must`?`2px solid #10b981`:e.modality===`must_not`?`2px solid #ef4444`:e.modality===`should`?`1px solid #8b5cf6`:e.modality===`should_not`?`1px solid #f97316`:`1px solid rgba(255, 255, 255, 0.08)`,n=e.modality===`must`?`0 0 12px rgba(16, 185, 129, 0.15)`:e.modality===`must_not`?`0 0 12px rgba(239, 68, 68, 0.15)`:void 0;return(0,z.jsxs)(`div`,{className:`memory-node-card`,onClick:()=>ke(e),style:{border:t,boxShadow:n,transition:`transform 0.2s ease, box-shadow 0.2s ease`,position:`relative`},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`flex-start`,marginBottom:6},children:[(0,z.jsx)(`h4`,{style:{margin:0,color:`#fff`,fontSize:15},children:e.title}),e.modality&&(0,z.jsx)(`span`,{style:{fontSize:9,fontWeight:700,textTransform:`uppercase`,padding:`2px 6px`,borderRadius:4,background:e.modality===`must`?`rgba(16, 185, 129, 0.15)`:e.modality===`must_not`?`rgba(239, 68, 68, 0.15)`:`rgba(255, 255, 255, 0.05)`,color:e.modality===`must`?`#10b981`:e.modality===`must_not`?`#ef4444`:`var(--text-secondary)`},children:e.modality})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:16,fontSize:11,color:`var(--text-tertiary)`,marginTop:8},children:[(0,z.jsxs)(`span`,{children:[`📂 `,e.category]}),e.importance!==void 0&&(0,z.jsxs)(`span`,{style:{color:`#fbbf24`},children:[`★ `,e.importance,`/5`]}),e.confidence!==void 0&&(0,z.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:4},children:[`🧠 `,Math.round(e.confidence*100),`%`]})]})]},e.slug)})]})]})]}):(0,z.jsxs)(`div`,{style:{width:`100%`},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:16},children:[(0,z.jsx)(`h3`,{children:`Quarantined Contradiction Records`}),(0,z.jsxs)(`span`,{style:{fontSize:12,color:`var(--text-tertiary)`,display:`flex`,alignItems:`center`,gap:5},children:[(0,z.jsx)(`span`,{className:`pulse`,style:{background:`#06b6d4`}}),` SSE Real-time Agent Monitor Connected`]})]}),T.length===0?(0,z.jsxs)(`div`,{style:{textAlign:`center`,padding:60,background:`rgba(255,255,255,0.02)`,borderRadius:12,border:`1px dashed var(--border)`,color:`var(--text-tertiary)`},children:[(0,z.jsx)(`span`,{style:{fontSize:32,display:`block`,marginBottom:12},children:`🛡️`}),(0,z.jsx)(`h4`,{style:{color:`#fff`,marginBottom:6},children:`All Clear!`}),"No memory conflicts enqueued or quarantined in `.agent/memory-inbox/conflicts/`."]}):(0,z.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:T.map(e=>{let t=e.status===`pending`;return(0,z.jsxs)(`div`,{style:{background:`rgba(15,23,42,0.45)`,backdropFilter:`blur(12px)`,border:t?`1px solid rgba(239, 68, 68, 0.25)`:`1px solid rgba(34, 197, 94, 0.2)`,borderRadius:12,padding:24,boxShadow:`0 8px 32px rgba(0,0,0,0.15)`},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`flex-start`,marginBottom:16,borderBottom:`1px solid rgba(255,255,255,0.06)`,paddingBottom:12},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`h4`,{style:{margin:0,fontSize:16,color:`#fff`,display:`flex`,alignItems:`center`,gap:8},children:[`Conflict: `,(0,z.jsx)(`code`,{children:e.conflict_id}),(0,z.jsx)(`span`,{style:{fontSize:11,padding:`2px 8px`,borderRadius:10,background:t?`rgba(239,68,68,0.15)`:`rgba(34,197,94,0.15)`,color:t?`#ef4444`:`#22c55e`,textTransform:`uppercase`},children:e.status})]}),(0,z.jsxs)(`span`,{style:{fontSize:11,color:`var(--text-tertiary)`},children:[`Detected at: `,new Date(e.detected_at).toLocaleString()]})]}),(0,z.jsxs)(`div`,{style:{textAlign:`right`},children:[(0,z.jsxs)(`span`,{style:{fontSize:12,color:`#ef4444`,fontWeight:700,display:`block`},children:[`Clash Similarity: `,Math.round(e.similarity*100),`%`]}),(0,z.jsx)(`span`,{style:{fontSize:10,color:`var(--text-tertiary)`},children:`Modality polarity flip`})]})]}),(0,z.jsxs)(`p`,{style:{fontSize:13,background:`rgba(239,68,68,0.03)`,padding:`10px 14px`,borderRadius:6,borderLeft:`3px solid #ef4444`,color:`#fca5a5`,marginBottom:20},children:[(0,z.jsx)(`strong`,{children:`Reason:`}),` `,e.reason]}),(0,z.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:16,marginBottom:24},children:[(0,z.jsxs)(`div`,{style:{background:`rgba(255,255,255,0.02)`,padding:16,borderRadius:8,border:`1px solid rgba(255,255,255,0.05)`},children:[(0,z.jsx)(`h5`,{style:{margin:`0 0 10px 0`,color:`#a78bfa`,textTransform:`uppercase`,fontSize:11,letterSpacing:.5},children:`✓ Existing Node In Vault`}),(0,z.jsx)(`div`,{style:{fontSize:13,fontWeight:700,color:`#fff`,marginBottom:8},children:(0,z.jsx)(`code`,{children:e.existing_slug})}),(0,z.jsxs)(`dl`,{style:{display:`grid`,gridTemplateColumns:`80px 1fr`,gap:4,margin:`0 0 12px 0`,fontSize:11,color:`var(--text-secondary)`},children:[(0,z.jsx)(`dt`,{children:`Modality:`}),(0,z.jsx)(`dd`,{children:(0,z.jsx)(`code`,{children:e._existing_node?.modality||`must`})}),(0,z.jsx)(`dt`,{children:`Polarity:`}),(0,z.jsx)(`dd`,{children:(0,z.jsx)(`code`,{children:e._existing_node?.sentiment_polarity||`directive_must`})}),(0,z.jsx)(`dt`,{children:`Confidence:`}),(0,z.jsx)(`dd`,{children:e._existing_node?.confidence===void 0?`N/A`:`${Math.round(e._existing_node.confidence*100)}%`})]}),(0,z.jsx)(`div`,{style:{fontSize:12,fontStyle:`italic`,background:`rgba(0,0,0,0.2)`,padding:10,borderRadius:6,color:`var(--text-tertiary)`,minHeight:60,whiteSpace:`pre-wrap`},children:e._existing_node?.excerpt||e._existing_node?.body||`No preview content.`})]}),(0,z.jsxs)(`div`,{style:{background:`rgba(255,255,255,0.02)`,padding:16,borderRadius:8,border:`1px solid rgba(255,255,255,0.05)`},children:[(0,z.jsx)(`h5`,{style:{margin:`0 0 10px 0`,color:`#06b6d4`,textTransform:`uppercase`,fontSize:11,letterSpacing:.5},children:`⚠ New Ingestion Candidate`}),(0,z.jsx)(`div`,{style:{fontSize:13,fontWeight:700,color:`#fff`,marginBottom:8},children:(0,z.jsx)(`code`,{children:e.new_slug})}),(0,z.jsxs)(`dl`,{style:{display:`grid`,gridTemplateColumns:`80px 1fr`,gap:4,margin:`0 0 12px 0`,fontSize:11,color:`var(--text-secondary)`},children:[(0,z.jsx)(`dt`,{children:`Modality:`}),(0,z.jsx)(`dd`,{children:(0,z.jsx)(`code`,{children:e._new_node?.modality||`must_not`})}),(0,z.jsx)(`dt`,{children:`Polarity:`}),(0,z.jsx)(`dd`,{children:(0,z.jsx)(`code`,{children:e._new_node?.sentiment_polarity||`directive_must_not`})}),(0,z.jsx)(`dt`,{children:`Confidence:`}),(0,z.jsx)(`dd`,{children:e._new_node?.confidence===void 0?`N/A`:`${Math.round(e._new_node.confidence*100)}%`})]}),(0,z.jsx)(`div`,{style:{fontSize:12,fontStyle:`italic`,background:`rgba(0,0,0,0.2)`,padding:10,borderRadius:6,color:`var(--text-tertiary)`,minHeight:60,whiteSpace:`pre-wrap`},children:e._new_node?.excerpt||e._new_node?.body||`No preview content.`})]})]}),t?(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:12},children:[(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,disabled:D!==null,onClick:()=>Ae(e.conflict_id,`keep`,e.existing_slug),style:{borderColor:`rgba(255,255,255,0.1)`,fontSize:12},children:D===e.conflict_id?`Processing...`:`Keep Existing Node (${e.existing_slug})`}),(0,z.jsx)(`button`,{className:`btn btn-purple btn-sm`,disabled:D!==null,onClick:()=>Ae(e.conflict_id,`supersede`,e.new_slug),style:{fontSize:12},children:D===e.conflict_id?`Processing...`:`Supersede with New (${e.new_slug})`})]}):(0,z.jsxs)(`div`,{style:{fontSize:12,color:`#22c55e`,background:`rgba(34,197,94,0.06)`,padding:`10px 14px`,borderRadius:6,border:`1px solid rgba(34,197,94,0.15)`,display:`flex`,justifyContent:`space-between`,alignItems:`center`},children:[(0,z.jsxs)(`span`,{children:[`✓ Resolved successfully. Choice: `,(0,z.jsx)(`strong`,{children:e.resolution})]}),(0,z.jsxs)(`span`,{style:{fontSize:11,color:`var(--text-tertiary)`},children:[`Resolved at: `,e.resolved_at?new Date(e.resolved_at).toLocaleString():``]})]})]},e.conflict_id)})})]}),i===`sessions`&&(0,z.jsxs)(`div`,{className:`health-log`,style:{background:`rgba(15,23,42,0.45)`,backdropFilter:`blur(12px)`,border:`1px solid var(--border)`,borderRadius:12,padding:24},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:16},children:[(0,z.jsxs)(`h2`,{style:{margin:0,color:`#fff`,fontSize:16},children:[`📝 IDE Sessions (`,x,`)`]}),(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:I,style:{fontSize:12},children:`🔄 Refresh`})]}),C?(0,z.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[1,2,3].map(e=>(0,z.jsx)(`div`,{className:`skeleton`,style:{height:56}},e))}):y.length===0?(0,z.jsxs)(`div`,{style:{textAlign:`center`,padding:40,color:`var(--text-tertiary)`},children:[(0,z.jsx)(`span`,{style:{fontSize:32,display:`block`,marginBottom:8},children:`📝`}),`No sessions ingested yet. Sessions appear here when the relay ships IDE conversation data.`]}):(0,z.jsxs)(`table`,{style:{width:`100%`,textAlign:`left`,borderCollapse:`collapse`},children:[(0,z.jsx)(`thead`,{children:(0,z.jsxs)(`tr`,{children:[(0,z.jsx)(`th`,{style:{padding:`10px 12px`,borderBottom:`1px solid var(--border)`,color:`var(--text-tertiary)`,fontSize:12,fontWeight:600},children:`Title`}),(0,z.jsx)(`th`,{style:{padding:`10px 12px`,borderBottom:`1px solid var(--border)`,color:`var(--text-tertiary)`,fontSize:12,fontWeight:600},children:`Date`}),(0,z.jsx)(`th`,{style:{padding:`10px 12px`,borderBottom:`1px solid var(--border)`,color:`var(--text-tertiary)`,fontSize:12,fontWeight:600},children:`Source`}),(0,z.jsx)(`th`,{style:{padding:`10px 12px`,borderBottom:`1px solid var(--border)`,color:`var(--text-tertiary)`,fontSize:12,fontWeight:600},children:`Messages`}),(0,z.jsx)(`th`,{style:{padding:`10px 12px`,borderBottom:`1px solid var(--border)`,color:`var(--text-tertiary)`,fontSize:12,fontWeight:600,width:60}})]})}),(0,z.jsx)(`tbody`,{children:y.map(e=>{let t={antigravity:`#8b5cf6`,"claude-code":`#f59e0b`,codex:`#10b981`,vscode:`#3b82f6`,cursor:`#06b6d4`,"gemini-cli":`#ec4899`}[e.source||``]||`var(--text-secondary)`;return(0,z.jsxs)(`tr`,{style:{borderBottom:`1px solid rgba(255,255,255,0.04)`},children:[(0,z.jsx)(`td`,{style:{padding:`10px 12px`,color:`#fff`,fontSize:13,maxWidth:400,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.title||e.id}),(0,z.jsx)(`td`,{style:{padding:`10px 12px`,color:`var(--text-secondary)`,fontSize:12,whiteSpace:`nowrap`},children:e.date?new Date(e.date).toLocaleString():`-`}),(0,z.jsx)(`td`,{style:{padding:`10px 12px`},children:e.source&&(0,z.jsx)(`span`,{style:{fontSize:10,fontWeight:600,textTransform:`uppercase`,padding:`2px 8px`,borderRadius:4,background:`${t}20`,color:t,border:`1px solid ${t}40`},children:e.source})}),(0,z.jsx)(`td`,{style:{padding:`10px 12px`,color:`var(--text-secondary)`,fontSize:12},children:e.count}),(0,z.jsx)(`td`,{style:{padding:`10px 12px`},children:(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>Oe(e.id),style:{fontSize:10,padding:`2px 6px`,color:`#fca5a5`,borderColor:`rgba(239,68,68,0.2)`},children:`🗑️`})})]},e.id)})})]})]})]})}var RW=Object.defineProperty,zW=Object.getOwnPropertySymbols,BW=Object.prototype.hasOwnProperty,VW=Object.prototype.propertyIsEnumerable,HW=(e,t,n)=>t in e?RW(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,UW=(e,t)=>{for(var n in t||={})BW.call(t,n)&&HW(e,n,t[n]);if(zW)for(var n of zW(t))VW.call(t,n)&&HW(e,n,t[n]);return e},WW=(e,t)=>{var n={};for(var r in e)BW.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&zW)for(var r of zW(e))t.indexOf(r)<0&&VW.call(e,r)&&(n[r]=e[r]);return n},GW;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e<this.size;e++)o.push(!1);for(let e=0;e<this.size;e++)this.modules.push(o.slice()),this.isFunction.push(o.slice());this.drawFunctionPatterns();let s=this.addEccAndInterleave(r);if(this.drawCodewords(s),a==-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(a=t,e=n),this.applyMask(t)}}i(0<=a&&a<=7),this.mask=a,this.applyMask(a),this.drawFormatBits(a),this.isFunction=[]}static encodeText(n,r){let i=e.QrSegment.makeSegments(n);return t.encodeSegments(i,r)}static encodeBinary(n,r){let i=e.QrSegment.makeBytes(n);return t.encodeSegments([i],r)}static encodeSegments(e,r,a=1,s=40,c=-1,l=!0){if(!(t.MIN_VERSION<=a&&a<=s&&s<=t.MAX_VERSION)||c<-1||c>7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.length<p;e^=253)n(e,8,f);let m=[];for(;m.length*8<f.length;)m.push(0);return f.forEach((e,t)=>m[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0),this.setFunctionModule(e,6,e%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n==0&&r==0||n==0&&r==t-1||n==t-1&&r==0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.errorCorrectionLevel.formatBits<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let a=(t<<10|n)^21522;i(!(a>>>15));for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(!(t>>>18));for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a<this.size&&0<=o&&o<this.size&&this.setFunctionModule(a,o,i!=2&&i!=4)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!=1)}setFunctionModule(e,t,n){this.modules[t][e]=n,this.isFunction[t][e]=!0}addEccAndInterleave(e){let n=this.version,r=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(n,r))throw RangeError(`Invalid argument`);let a=t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n],o=t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n],s=Math.floor(t.getNumRawDataModules(n)/8),c=a-s%a,l=Math.floor(s/a),u=[],d=t.reedSolomonComputeDivisor(o);for(let n=0,r=0;n<a;n++){let i=e.slice(r,r+l-o+(n<c?0:1));r+=i.length;let a=t.reedSolomonComputeRemainder(i,d);n<c&&i.push(0),u.push(i.concat(a))}let f=[];for(let e=0;e<u[0].length;e++)u.forEach((t,n)=>{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i<this.size;i++)for(let a=0;a<2;a++){let o=t-a,s=t+1&2?i:this.size-1-i;!this.isFunction[s][o]&&n<e.length*8&&(this.modules[s][o]=r(e[n>>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.isFunction[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[n][o]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[o][n]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size-1;n++)for(let r=0;r<this.size-1;r++){let i=this.modules[n][r];i==this.modules[n][r+1]&&i==this.modules[n+1][r]&&i==this.modules[n+1][r+1]&&(e+=t.PENALTY_N2)}let n=0;for(let e of this.modules)n=e.reduce((e,t)=>e+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t<e-1;t++)n.push(0);n.push(1);let r=1;for(let i=0;i<e;i++){for(let e=0;e<n.length;e++)n[e]=t.reedSolomonMultiply(n[e],r),e+1<n.length&&(n[e]^=n[e+1]);r=t.reedSolomonMultiply(r,2)}return n}static reedSolomonComputeRemainder(e,n){let r=n.map(e=>0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(!(n>>>8)),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return!!(e>>>t&1)}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e<t.length;){let i=Math.min(t.length-e,3);n(parseInt(t.substring(e,e+i),10),i*3+1,r),e+=i}return new e(e.Mode.NUMERIC,t.length,r)}static makeAlphanumeric(t){if(!e.isAlphanumeric(t))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let r=[],i;for(i=0;i+2<=t.length;i+=2){let a=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i))*45;a+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i+1)),n(a,11,r)}return i<t.length&&n(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i)),6,r),new e(e.Mode.ALPHANUMERIC,t.length,r)}static makeSegments(t){return t==``?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}static makeEci(t){let r=[];if(t<0)throw RangeError(`ECI assignment value out of range`);if(t<128)n(t,8,r);else if(t<16384)n(2,2,r),n(t,14,r);else if(t<1e6)n(6,3,r),n(t,21,r);else throw RangeError(`ECI assignment value out of range`);return new e(e.Mode.ECI,0,r)}static isNumeric(t){return e.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return e.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let n=0;for(let r of e){let e=r.mode.numCharCountBits(t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)==`%`?(t.push(parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}};a.NUMERIC_REGEX=/^[0-9]*$/,a.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,a.ALPHANUMERIC_CHARSET=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`;let o=a;e.QrSegment=a})(GW||={}),(e=>{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(GW||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(GW||={});var KW=GW,qW={L:KW.QrCode.Ecc.LOW,M:KW.QrCode.Ecc.MEDIUM,Q:KW.QrCode.Ecc.QUARTILE,H:KW.QrCode.Ecc.HIGH},JW=128,YW=`L`,XW=`#FFFFFF`,ZW=`#000000`,QW=!1,$W=1,eG=4,tG=0,nG=.1;function rG(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function iG(e,t){return e.slice().map((e,n)=>n<t.y||n>=t.y+t.h?e:e.map((e,n)=>n<t.x||n>=t.x+t.w?e:!1))}function aG(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*nG),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function oG(e,t){return t==null?e?eG:tG:Math.max(Math.floor(t),0)}function sG({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=v.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...KW.QrSegment.makeSegments(t)),e),[]);return KW.QrCode.encodeSegments(r,qW[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=v.useMemo(()=>{let e=c.getModules(),t=oG(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:aG(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var cG=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),lG=v.forwardRef(function(e,t){let n=e,{value:r,size:i=JW,level:a=YW,bgColor:o=XW,fgColor:s=ZW,includeMargin:c=QW,minVersion:l=$W,boostLevel:u,marginSize:d,imageSettings:f}=n,p=WW(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=WW(p,[`style`]),g=f?.src,_=v.useRef(null),y=v.useRef(null),b=v.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[x,S]=v.useState(!1),{margin:C,cells:w,numCells:T,calculatedImageSettings:E}=sG({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});v.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=w,r=y.current,a=E!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&E.excavation!=null&&(n=iG(w,E.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/T*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,T,T),t.fillStyle=s,cG?t.fill(new Path2D(rG(n,C))):w.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+C,n+C,1,1)})}),E&&(t.globalAlpha=E.opacity),a&&t.drawImage(r,E.x+C,E.y+C,E.w,E.h)}}),v.useEffect(()=>{S(!1)},[g]);let D=UW({height:i,width:i},m),O=null;return g!=null&&(O=v.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{S(!0)},ref:y,crossOrigin:E?.crossOrigin})),v.createElement(v.Fragment,null,v.createElement(`canvas`,UW({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});lG.displayName=`QRCodeCanvas`;var uG=v.forwardRef(function(e,t){let n=e,{value:r,size:i=JW,level:a=YW,bgColor:o=XW,fgColor:s=ZW,includeMargin:c=QW,minVersion:l=$W,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=WW(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:y}=sG({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),b=g,x=null;p!=null&&y!=null&&(y.excavation!=null&&(b=iG(g,y.excavation)),x=v.createElement(`image`,{href:p.src,height:y.h,width:y.w,x:y.x+h,y:y.y+h,preserveAspectRatio:`none`,opacity:y.opacity,crossOrigin:y.crossOrigin}));let S=rG(b,h);return v.createElement(`svg`,UW({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&v.createElement(`title`,null,d),v.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),v.createElement(`path`,{fill:s,d:S,shapeRendering:`crispEdges`}),x)});uG.displayName=`QRCodeSVG`;function dG(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(!0),[c,l]=(0,v.useState)(!1),u=async()=>{s(!0),a(null);try{let e=await R(`${Ln()}/api/pairing`);if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Pairing API error: ${e.status}`)}let n=await e.json();t(n);let i=n.preferred_url||n.endpoints?.find(e=>e.recommended)?.url||n.endpoints?.[0]?.url||``;r(i)}catch(e){console.error(e),a(e instanceof Error?e.message:`Failed to load pairing endpoints`);let n=`${window.location.protocol}//${window.location.host}`;r(n),t({port:Number(window.location.port||3e3),protocol:window.location.protocol.replace(`:`,``)||`http`,preferred_url:n,endpoints:[{kind:`browser`,label:`This browser URL (may not work on phone)`,ip:window.location.hostname,url:n,recommended:!0,reachable_hint:`Fallback when pairing API is unavailable.`}],warnings:[`Could not load live network endpoints from the brain.`],listen_hosts:[]})}finally{s(!1)}};(0,v.useEffect)(()=>{setTimeout(()=>{u()},0)},[]);let d=e?.endpoints?.find(e=>e.url===n)||null,f=d?.kind===`loopback`||n.includes(`127.0.0.1`)||n.includes(`localhost`);return(0,z.jsxs)(`div`,{className:`mobile-pairing`,"data-testid":`mobile-pairing`,style:{padding:`20px`,background:`var(--bg-secondary)`,borderRadius:`12px`,border:`1px solid var(--border)`},children:[(0,z.jsx)(`h3`,{style:{margin:`0 0 8px`},children:`Mobile Device Pairing`}),(0,z.jsxs)(`p`,{style:{color:`var(--text-tertiary)`,fontSize:`13px`,marginBottom:`16px`},children:[`Scan with your phone to open this Total Recall dashboard. Prefer `,(0,z.jsx)(`strong`,{children:`LAN`}),` on the same Wi‑Fi, or `,(0,z.jsx)(`strong`,{children:`Tailscale/mesh`}),` if the phone is on your tailnet.`]}),o&&(0,z.jsx)(`div`,{"data-testid":`pairing-loading`,style:{color:`var(--text-tertiary)`,fontSize:13},children:`Detecting reachable addresses…`}),i&&(0,z.jsxs)(`div`,{role:`alert`,"data-testid":`pairing-error`,style:{marginBottom:12,padding:10,borderRadius:8,border:`1px solid #ef4444`,color:`#ef4444`,fontSize:12},children:[i,` `,(0,z.jsx)(`button`,{type:`button`,onClick:()=>u(),style:{marginLeft:8,cursor:`pointer`},children:`Retry`})]}),!o&&(0,z.jsxs)(`div`,{style:{display:`flex`,gap:20,flexWrap:`wrap`,alignItems:`flex-start`},children:[(0,z.jsx)(`div`,{style:{background:`#fff`,padding:`16px`,borderRadius:`8px`,display:`inline-block`},"data-testid":`pairing-qr`,children:n?(0,z.jsx)(uG,{value:n,size:150,level:`M`,includeMargin:!0}):(0,z.jsx)(`div`,{style:{width:150,height:150}})}),(0,z.jsxs)(`div`,{style:{flex:1,minWidth:200},children:[e&&e.endpoints.length>0&&(0,z.jsxs)(`div`,{className:`field-col`,style:{marginBottom:12},children:[(0,z.jsx)(`label`,{className:`field-label`,htmlFor:`pairing-endpoint`,children:`Pairing address`}),(0,z.jsx)(`select`,{id:`pairing-endpoint`,className:`settings-select`,"data-testid":`pairing-endpoint-select`,value:n,onChange:e=>r(e.target.value),style:{width:`100%`,marginTop:4},children:e.endpoints.map(e=>(0,z.jsxs)(`option`,{value:e.url,children:[e.label,e.recommended?` ★`:``,` — `,e.url]},e.url))})]}),(0,z.jsx)(`p`,{"data-testid":`pairing-url`,style:{margin:`0 0 8px`,fontSize:12,fontFamily:`var(--font-mono)`,wordBreak:`break-all`,color:`var(--text-primary)`},children:n||`—`}),(0,z.jsxs)(`div`,{style:{display:`flex`,gap:8,flexWrap:`wrap`,marginBottom:12},children:[(0,z.jsx)(`button`,{type:`button`,className:`btn-secondary`,onClick:async()=>{if(n)try{await navigator.clipboard.writeText(n),l(!0),setTimeout(()=>l(!1),2e3)}catch{a(`Clipboard copy failed — select the URL text manually.`)}},"data-testid":`pairing-copy`,children:c?`Copied`:`Copy URL`}),(0,z.jsx)(`button`,{type:`button`,className:`btn-ghost btn-sm`,onClick:()=>u(),children:`Refresh`})]}),d&&(0,z.jsxs)(`div`,{style:{fontSize:12,color:`var(--text-secondary)`,margin:`0 0 10px`,lineHeight:1.5,background:`rgba(255,255,255,0.03)`,padding:`8px 12px`,borderRadius:6},children:[(0,z.jsx)(`strong`,{children:`Connection Route:`}),` `,d.reachable_hint]}),f&&(0,z.jsxs)(`div`,{"data-testid":`pairing-loopback-warning`,style:{fontSize:12,color:`#f59e0b`,margin:`0 0 8px`,background:`rgba(245, 158, 11, 0.1)`,padding:`8px 12px`,borderRadius:6,border:`1px solid rgba(245, 158, 11, 0.2)`},children:[`⚠️ `,(0,z.jsx)(`strong`,{children:`Loopback Only:`}),` `,(0,z.jsx)(`code`,{children:`127.0.0.1`}),` only works on this computer. To open on your phone, select your Mesh IP (`,(0,z.jsx)(`code`,{children:`100.64.x.x`}),`) or enable `,(0,z.jsx)(`strong`,{children:`Allow Public Bind`}),` below to use local Wi-Fi.`]})]})]}),e?.warnings&&e.warnings.length>0&&(0,z.jsxs)(`div`,{"data-testid":`pairing-warnings`,style:{margin:`16px 0 0`,padding:`10px 14px`,fontSize:12,color:`#fbbf24`,background:`rgba(251, 191, 36, 0.08)`,borderRadius:8,border:`1px solid rgba(251, 191, 36, 0.2)`},children:[(0,z.jsx)(`div`,{style:{fontWeight:600,marginBottom:4},children:`Network Notice:`}),(0,z.jsx)(`ul`,{style:{margin:0,paddingLeft:18},children:e.warnings.map(e=>(0,z.jsx)(`li`,{children:e},e))})]}),(0,z.jsxs)(`div`,{style:{marginTop:16,padding:`12px 14px`,background:`rgba(59, 130, 246, 0.06)`,borderRadius:8,border:`1px solid rgba(59, 130, 246, 0.15)`,fontSize:12,color:`var(--text-secondary)`,lineHeight:1.5},children:[(0,z.jsx)(`div`,{style:{color:`var(--text-primary)`,fontWeight:600,marginBottom:4},children:`📱 How to connect your phone:`}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:`Option A (WireGuard / Mesh — Recommended):`}),` Install the standard `,(0,z.jsx)(`em`,{children:`Tailscale`}),` app on your phone (iOS App Store / Google Play). Log into your tailnet/headscale server. Scan the `,(0,z.jsx)(`code`,{children:`100.64.x.x`}),` QR code above.`]}),(0,z.jsxs)(`div`,{style:{marginTop:4},children:[(0,z.jsx)(`strong`,{children:`Option B (Local Home Wi-Fi):`}),` Check `,(0,z.jsx)(`strong`,{children:`Allow Public Bind`}),` in `,(0,z.jsx)(`em`,{children:`Network & Binding`}),` below, restart the server, and scan your local Wi-Fi LAN QR code (e.g. `,(0,z.jsx)(`code`,{children:`192.168.x.x`}),`).`]})]})]})}async function fG(){let e=await Vn(`/api/mesh/leader`);if(!e.leader)throw Error(`No online mesh leader is available`);return e.leader}async function pG(){return(await Vn(`/api/mesh/nodes`)).nodes}async function mG(){return Vn(`/api/mesh/access/proposals`)}async function hG(){return Hn(`/api/mesh/access/import`,{})}async function gG(e){return Hn(`/api/mesh/access`,e)}async function _G(){let e=await Hn(`/api/mesh/election/refresh`,{});if(!e.leader)throw Error(`No online mesh leader is available`);return e.leader}async function vG(){return(await Vn(`/api/mesh/election/history`)).events||[]}async function yG(e){return Hn(`/api/mesh/election/log`,e)}async function bG(){return Vn(`/api/mesh/latency`)}async function xG(){return Vn(`/api/mesh/interfaces`)}async function SG(e){let t=new URLSearchParams;e?.probe===!1&&t.set(`probe`,`0`),e?.limit&&t.set(`limit`,String(e.limit));let n=t.toString();return Vn(`/api/mesh/lan${n?`?${n}`:``}`)}async function CG(){return Vn(`/api/mesh/io`)}async function wG(e,t){let n=await R(`${L}/api/mesh/register-node`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({auth_id:e,...t?{user:t}:{}})}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r.message||`register failed: ${n.status}`);return r}async function TG(){return Vn(`/api/mesh/enrollment`)}async function EG(e){return Hn(`/api/mesh/enroll`,e||{})}async function DG(e){return Hn(`/api/mesh/lan/register`,{probe:e?.probe!==!1,limit:e?.limit??32})}async function OG(e){return Hn(`/api/mesh/preauthkey`,{reusable:e?.reusable===!0,ephemeral:e?.ephemeral===!0,ttlMinutes:e?.ttlMinutes})}function kG(){let[e,t]=(0,v.useState)([]),[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(null),[x,S]=(0,v.useState)(``),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(null);(0,v.useEffect)(()=>{pG().then(t).catch(e=>d(e?.message??`could not load nodes`)),TG().then(e=>b(e.login_server)).catch(()=>b(null))},[]),(0,v.useEffect)(()=>{if(!n)return;let e=()=>{let e=new Date(n.expiration).getTime()-Date.now();_(Math.max(0,Math.floor(e/1e3)))};e();let t=setInterval(e,1e3);return()=>clearInterval(t)},[n]);let D=async()=>{l(!0),d(null),p(!1);try{r(await OG({reusable:i,ephemeral:o}))}catch(e){d(e instanceof Error?e.message:`could not mint an enrollment key`)}finally{l(!1)}},O=async()=>{w(!0),d(null),E(null);try{let n=x.match(/hskey-authreq-[A-Za-z0-9._-]+/),r=await wG(n?n[0]:x.trim());E(r.message),S(``),t(await pG().catch(()=>e))}catch(e){d(e instanceof Error?e.message:`could not approve device`)}finally{w(!1)}},k=g!==null&&g<=0,A=y??n?.login_server??null,j=e.filter(e=>!e.self&&e.access_resolved?.complete!==!0);return(0,z.jsxs)(`section`,{"data-testid":`tailnet-enroll`,style:{marginTop:24},children:[(0,z.jsx)(`h3`,{style:{marginBottom:4},children:`Add a device to the tailnet`}),(0,z.jsx)(`p`,{style:{fontSize:12,opacity:.75,marginTop:0},children:`Point the device at this control server, then authenticate it with a short-lived key.`}),(0,z.jsxs)(`div`,{"data-testid":`enroll-instructions`,style:{margin:`12px 0`,padding:14,borderRadius:8,border:`1px solid var(--border)`,background:`var(--bg-secondary)`},children:[(0,z.jsxs)(`div`,{style:{fontSize:12,marginBottom:10},children:[(0,z.jsx)(`strong`,{children:`Control server`}),(0,z.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,marginTop:4},children:[(0,z.jsx)(`code`,{"data-testid":`enroll-login-server`,style:{wordBreak:`break-all`,flex:1},children:A??`not configured — set the Headscale URL in Secrets first`}),A&&(0,z.jsx)(`button`,{type:`button`,"data-testid":`enroll-copy-server`,onClick:()=>{navigator.clipboard?.writeText(A),h(!0)},children:m?`Copied`:`Copy`})]})]}),(0,z.jsxs)(`div`,{"data-testid":`enroll-approve`,style:{margin:`0 0 12px`,padding:12,borderRadius:8,border:`1px solid var(--border)`},children:[(0,z.jsx)(`strong`,{style:{fontSize:12},children:`Device waiting for approval?`}),(0,z.jsxs)(`p`,{style:{fontSize:12,opacity:.75,margin:`4px 0 8px`},children:[`If a device shows “run the command below in the headscale server”, paste that whole line (or just the `,(0,z.jsx)(`code`,{children:`hskey-authreq-…`}),` part) here.`]}),(0,z.jsxs)(`p`,{style:{fontSize:12,margin:`0 0 8px`,color:`#f59e0b`},children:[(0,z.jsx)(`strong`,{children:`If the code on the device never changes`}),` between sign-in attempts, it is a stale one replayed from the iOS keychain and no amount of retrying will register it. Follow`,` `,(0,z.jsx)(`strong`,{children:`How to clear the keychain (iOS)`}),` below — the code must come back different.`]}),(0,z.jsxs)(`div`,{style:{display:`flex`,gap:8,flexWrap:`wrap`},children:[(0,z.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`hskey-authreq-…`,"data-testid":`enroll-authid`,style:{flex:1,minWidth:220,fontFamily:`var(--font-mono)`,fontSize:12}}),(0,z.jsx)(`button`,{type:`button`,onClick:O,disabled:C||!x.trim(),"data-testid":`enroll-approve-btn`,children:C?`Approving…`:`Approve device`})]}),T&&(0,z.jsx)(`p`,{"data-testid":`enroll-approved`,style:{fontSize:12,color:`#10b981`,margin:`8px 0 0`},children:T})]}),(0,z.jsxs)(`details`,{open:!0,style:{fontSize:12},children:[(0,z.jsx)(`summary`,{style:{cursor:`pointer`,fontWeight:600},children:`On a phone (iOS)`}),(0,z.jsxs)(`ol`,{style:{paddingLeft:18,lineHeight:1.7,marginBottom:6},children:[(0,z.jsxs)(`li`,{children:[`Install `,(0,z.jsx)(`strong`,{children:`Tailscale`}),` from the App Store — `,(0,z.jsx)(`strong`,{children:`1.38.1 or newer`}),`, the first release that supports an alternate control server.`]}),(0,z.jsxs)(`li`,{children:[(0,z.jsx)(`strong`,{children:`Sign out of Tailscale first.`}),` The alternate-server setting is only read while the app is logged out.`]}),(0,z.jsxs)(`li`,{children:[`Open `,(0,z.jsx)(`strong`,{children:`iOS Settings`}),`, scroll past Game Center and TV Provider to`,` `,(0,z.jsx)(`strong`,{children:`Tailscale`}),`, and put the control server above into`,` `,(0,z.jsx)(`strong`,{children:`Alternate Coordination Server URL`}),`.`]}),(0,z.jsxs)(`li`,{children:[(0,z.jsx)(`strong`,{children:`Turn on “Reset Keychain”`}),` — same panel, just below the URL. Treat this as required, not optional: the app keeps its node key in the iOS keychain and will otherwise replay an old registration id forever. Force-quitting does not clear it, and the server rejects the stale id every time while the phone keeps showing a page that looks perfectly valid. Full steps under `,(0,z.jsx)(`em`,{children:`How to clear the keychain`}),` below.`]}),(0,z.jsx)(`li`,{children:`Force-quit Tailscale from the app switcher, then reopen it — the setting is read at launch.`}),(0,z.jsxs)(`li`,{children:[`Tap the plain `,(0,z.jsx)(`strong`,{children:`Sign in`}),` option (not SSO). It should open this control server's page.`]}),(0,z.jsxs)(`li`,{children:[`The page will say `,(0,z.jsx)(`em`,{children:`“run the command below in the headscale server”`}),`. That is expected — copy the line it shows and paste it into `,(0,z.jsx)(`strong`,{children:`Device waiting for approval?`}),` above.`,(0,z.jsx)(`strong`,{children:` Do not use the enrollment key below on an iPhone or iPad:`}),` the Tailscale iOS app does not accept pre-auth keys against a custom control server, so interactive sign-in plus approval here is the only route that works. Android and ChromeOS `,(0,z.jsx)(`em`,{children:`do`}),` accept the key — see below.`]})]}),(0,z.jsxs)(`p`,{style:{opacity:.75,margin:0},children:[`The in-app route — account icon → `,(0,z.jsx)(`strong`,{children:`Log in…`}),` → options menu →`,` `,(0,z.jsx)(`strong`,{children:`Use custom coordination server`}),` — reaches the same place when it works, but that menu has been reported unresponsive on some builds. The Settings route above is the reliable one.`]})]}),(0,z.jsxs)(`details`,{open:!0,style:{fontSize:12,marginTop:8},children:[(0,z.jsx)(`summary`,{style:{cursor:`pointer`,fontWeight:600},"data-testid":`enroll-keychain-steps`,children:`How to clear the keychain (iOS)`}),(0,z.jsxs)(`ol`,{style:{paddingLeft:18,lineHeight:1.7,margin:`4px 0 0`},children:[(0,z.jsxs)(`li`,{children:[`Open the iOS `,(0,z.jsx)(`strong`,{children:`Settings`}),` app — not Tailscale's own settings.`]}),(0,z.jsxs)(`li`,{children:[`Scroll to the bottom, `,(0,z.jsx)(`strong`,{children:`past Game Center and TV Provider`}),`, into the alphabetical list of installed apps. Tap `,(0,z.jsx)(`strong`,{children:`Tailscale`}),`.`]}),(0,z.jsxs)(`li`,{children:[`Turn `,(0,z.jsx)(`strong`,{children:`Reset Keychain`}),` on.`]}),(0,z.jsxs)(`li`,{children:[`While you are there, check `,(0,z.jsx)(`strong`,{children:`Alternate Coordination Server URL`}),` still reads`,` `,(0,z.jsx)(`code`,{children:A??`your control server`}),` — clearing the keychain can blank it, and an empty box sends the app back to Tailscale's public service.`]}),(0,z.jsxs)(`li`,{children:[`Leave Settings. Open the app switcher and `,(0,z.jsx)(`strong`,{children:`swipe Tailscale away`}),`. Backgrounding is not enough; the setting is read at launch.`]}),(0,z.jsxs)(`li`,{children:[`Reopen Tailscale and tap the plain `,(0,z.jsx)(`strong`,{children:`Sign in`}),` (not SSO).`]}),(0,z.jsxs)(`li`,{children:[(0,z.jsx)(`strong`,{children:`Check the code changed.`}),` If it is the same string as last time, the keychain did not clear — repeat from step 1.`]})]})]}),(0,z.jsxs)(`details`,{style:{fontSize:12,marginTop:8},children:[(0,z.jsx)(`summary`,{style:{cursor:`pointer`,fontWeight:600},"data-testid":`enroll-android`,children:`On Android`}),(0,z.jsxs)(`p`,{style:{margin:`4px 0 6px`,opacity:.85},children:[`Android is `,(0,z.jsx)(`strong`,{children:`not`}),` like iOS here — it accepts an enrollment key directly, so you can use the key below and skip interactive approval entirely.`]}),(0,z.jsxs)(`ol`,{style:{paddingLeft:18,lineHeight:1.7,margin:`0 0 6px`},children:[(0,z.jsx)(`li`,{children:`Install Tailscale from Google Play or F-Droid.`}),(0,z.jsxs)(`li`,{children:[`Open the app → `,(0,z.jsx)(`strong`,{children:`settings menu (upper-right)`}),` → `,(0,z.jsx)(`strong`,{children:`Accounts`}),`.`]}),(0,z.jsxs)(`li`,{children:[`Choose `,(0,z.jsx)(`strong`,{children:`Use an alternate server`}),` and enter`,` `,(0,z.jsx)(`code`,{children:A??`your control server`}),`.`]}),(0,z.jsxs)(`li`,{children:[`Back to `,(0,z.jsx)(`strong`,{children:`Accounts`}),`, choose `,(0,z.jsx)(`strong`,{children:`Use an auth key`}),`, and paste the enrollment key below. Then tap `,(0,z.jsx)(`strong`,{children:`login`}),` on the main screen.`]})]}),(0,z.jsx)(`p`,{style:{margin:0,opacity:.75},children:`Prefer the browser flow? Stop after step 3 and follow the prompts — if it shows a “run this command” page, approve it above exactly like iOS.`})]}),(0,z.jsxs)(`details`,{style:{fontSize:12,marginTop:8},children:[(0,z.jsx)(`summary`,{style:{cursor:`pointer`,fontWeight:600},"data-testid":`enroll-chromeos`,children:`On a Chromebook (ChromeOS)`}),(0,z.jsxs)(`p`,{style:{margin:`4px 0 6px`,opacity:.85},children:[`Install the `,(0,z.jsx)(`strong`,{children:`Android app from Google Play`}),` and follow the Android steps above — that is the supported route, and the enrollment key works.`]}),(0,z.jsx)(`p`,{style:{margin:0,opacity:.75},children:`Avoid installing inside the Crostini Linux container: it is known to crash the container on subsequent startups. Running the Android app also keeps the credentials out of the VM, and one install covers every VM on the machine. If managed policy blocks Play Store apps, there is currently no alternative install path.`})]})]}),u&&(0,z.jsx)(`div`,{role:`alert`,"data-testid":`tailnet-enroll-error`,style:{margin:`10px 0`,padding:10,borderRadius:8,border:`1px solid #ef4444`,color:`#ef4444`,fontSize:12},children:u}),(0,z.jsxs)(`div`,{style:{display:`flex`,gap:16,alignItems:`center`,flexWrap:`wrap`,margin:`12px 0`},children:[(0,z.jsxs)(`label`,{style:{fontSize:12,display:`flex`,gap:6,alignItems:`center`},children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),"data-testid":`enroll-reusable`}),`Reusable (enroll more than one device)`]}),(0,z.jsxs)(`label`,{style:{fontSize:12,display:`flex`,gap:6,alignItems:`center`},children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),"data-testid":`enroll-ephemeral`}),`Ephemeral (drops off the list when offline)`]}),(0,z.jsx)(`button`,{type:`button`,onClick:D,disabled:c,"data-testid":`enroll-mint`,style:{cursor:c?`wait`:`pointer`},children:c?`Minting…`:n?`Mint another key`:`Get enrollment key (computers, Android, ChromeOS)`})]}),n&&(0,z.jsxs)(`div`,{style:{display:`flex`,gap:20,flexWrap:`wrap`,alignItems:`flex-start`},children:[(0,z.jsx)(`div`,{style:{background:`#fff`,padding:16,borderRadius:8},"data-testid":`enroll-qr`,children:k?(0,z.jsx)(`div`,{style:{width:150,height:150,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#ef4444`,fontSize:12,textAlign:`center`},children:`Key expired — mint another`}):(0,z.jsx)(uG,{value:n.key,size:150,level:`M`,includeMargin:!0})}),(0,z.jsxs)(`div`,{style:{flex:1,minWidth:260},children:[(0,z.jsxs)(`div`,{style:{fontSize:12,marginBottom:6},children:[(0,z.jsx)(`strong`,{children:`Enrollment key`}),` `,(0,z.jsx)(`span`,{"data-testid":`enroll-ttl`,style:{opacity:.7},children:k?`(expired)`:`(expires in ${g}s, ${n.reusable?`reusable`:`single-use`})`}),(0,z.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,marginTop:4},children:[(0,z.jsx)(`code`,{style:{wordBreak:`break-all`,flex:1,opacity:k?.4:1},children:n.key}),(0,z.jsx)(`button`,{type:`button`,disabled:k,onClick:()=>{navigator.clipboard?.writeText(n.key),p(!0)},"data-testid":`enroll-copy`,children:f?`Copied`:`Copy`})]})]}),(0,z.jsxs)(`details`,{style:{fontSize:12,marginTop:6},children:[(0,z.jsx)(`summary`,{style:{cursor:`pointer`},children:`On a computer`}),(0,z.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,wordBreak:`break-all`},children:`tailscale up --login-server ${A??`<control-server>`} --authkey ${k?`<expired — mint another>`:n.key}`}),(0,z.jsxs)(`p`,{style:{opacity:.75},children:[`Always pass `,(0,z.jsx)(`code`,{children:`--login-server`}),` alongside any `,(0,z.jsx)(`code`,{children:`--reset`}),`, or the client silently repoints at the public Tailscale control plane.`]})]})]})]}),(0,z.jsxs)(`div`,{style:{marginTop:20},children:[(0,z.jsxs)(`h4`,{style:{marginBottom:6},children:[`Nodes (`,e.length,`)`]}),(0,z.jsx)(`ul`,{"data-testid":`enroll-node-list`,style:{listStyle:`none`,padding:0,fontSize:12,margin:0},children:e.map(e=>(0,z.jsxs)(`li`,{style:{padding:`4px 0`,display:`flex`,gap:8},children:[(0,z.jsx)(`span`,{title:e.online?`online`:`offline`,children:e.online?`🟢`:`⚪️`}),(0,z.jsx)(`strong`,{children:e.hostname}),(0,z.jsx)(`code`,{style:{opacity:.75},children:e.ip??`—`}),e.self&&(0,z.jsx)(`span`,{style:{opacity:.6},children:`(this host)`})]},`${e.hostname}-${e.ip??`noip`}`))}),j.length>0&&(0,z.jsxs)(`p`,{"data-testid":`enroll-access-warning`,style:{fontSize:12,color:`#f59e0b`,marginBottom:0},children:[j.length,` node(s) have no recorded login account — connecting to one fails as though it were unreachable. Run `,(0,z.jsx)(`code`,{children:`total-recall mesh access import`}),`.`]})]})]})}function AG(e){let t={...e};return t.security||={},t.security.dashboard||(t.security.dashboard={}),t.security.api||(t.security.api={}),t.security.network||(t.security.network={}),t.security.bind||(t.security.bind={}),t.security.rate_limits||(t.security.rate_limits={}),t.security.sandbox||(t.security.sandbox={}),t.security.privacy||(t.security.privacy={}),t.budget||={budget:{}},t.budget.budget||(t.budget.budget={}),t.brain||={},t.secrets||={},t}function jG({activeBrainId:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!0),[s,c]=(0,v.useState)(`idle`),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(null),[w,T]=(0,v.useState)(!1),[E,D]=(0,v.useState)(!1),O=async()=>{D(!0),C(null);try{let e=await ni();if(C(e.message),e.scheduled){setTimeout(function e(t=0){Yr().then(e=>{f(e),C(`Server restarted — reconnected.`),D(!1)}).catch(()=>{if(t>=20){C(`Server restarted but has not answered yet — reload in a moment.`),D(!1);return}setTimeout(()=>e(t+1),1500)})},2e3);return}}catch(e){C(`Restart error: `+e.message)}D(!1)},k=async()=>{T(!0),C(null);try{let e=await ti();C(e.message||`Daemon restarted successfully.`);let t=await Yr().catch(()=>null);t&&f(t)}catch(e){C(`Restart error: `+e.message)}finally{T(!1)}},[A,j]=(0,v.useState)(!1),ee=async()=>{o(!0),i(null);try{let e=await yi();n(AG(e))}catch(e){console.error(e),i(e instanceof Error?e.message:`Failed to load settings`),n(null)}finally{o(!1)}};(0,v.useEffect)(()=>{Yr().then(f).catch(console.error),oi().then(e=>y({updateAvailable:!!e.updateAvailable,latestVersion:e.latestVersion,currentVersion:e.currentVersion})).catch(console.error),setTimeout(()=>{ee()},0)},[e]);let M=[{id:`antigravity`,name:`Antigravity (Gemini SDK)`,desc:`Primary core developer agent`},{id:`gemini`,name:`Gemini CLI`,desc:`Direct Gemini assistant binary`},{id:`claude`,name:`Claude Code`,desc:`Anthropic developer CLI wrapper`},{id:`codex`,name:`Codex CLI`,desc:`OpenAI agent binary integration`},{id:`grok`,name:`Grok CLI`,desc:`xAI developer binary integration`}],te=Array.isArray(d?.cli_agents)?d.cli_agents:Array.isArray(d?.agents)?d.agents:[],ne=async e=>{e.preventDefault(),m(!0),g(null);try{let e=await ei();g(e.output),Yr().then(f).catch(console.error)}catch(e){g(`Error: `+e.message)}finally{m(!1)}},N=async()=>{x(!0),C(null);try{let e=await si();if(e.success){let t=e.summary,n=[t?.updated==null?null:`${t.updated} updated`,t?.up_to_date==null?null:`${t.up_to_date} current`,t?.latest?`latest ${t.latest}`:null].filter(Boolean),r=e.restart?.scheduled?` Server is restarting into the new code.`:e.restart?.required?` Server still runs the old code — ${e.restart.reason}`:``;C(n.length?`Update complete — ${n.join(` · `)}.${r}`:(e.message||`Update complete.`)+r)}else{let t=(e.summary?.results||[]).filter(e=>e.status===`failed`).map(e=>`${e.name}: ${e.error||`failed`}`).slice(0,3).join(`; `);C(`Update failed: ${e.message}${t?` (${t})`:``}`)}let t=await oi().catch(()=>null);t&&y({updateAvailable:!!t.updateAvailable,latestVersion:t.latestVersion,currentVersion:t.currentVersion})}catch(e){C(`Update error: `+e.message)}finally{x(!1)}},P=async()=>{if(t){c(`saving`);try{let e={...t};if(e.secrets){let t={};for(let[n,r]of Object.entries(e.secrets))typeof r==`string`&&r&&!r.includes(`•`)&&r!==`[redacted]`&&(t[n]=r);e.secrets=t}await bi(e),c(`saved`),setTimeout(()=>c(`idle`),2500)}catch(e){console.error(e),c(`error`),setTimeout(()=>c(`idle`),3e3)}}},re=async()=>{j(!0),u(`[Running] Rebuilding instruction surfaces…`);try{let e=await $r();u(`[Finished] Rebuilding instruction surfaces\n\n${e.message||(e.success?`Compile complete.`:`Compile finished with warnings.`)}`)}catch(e){u(`[Failed] Rebuild\n\n${e instanceof Error?e.message:String(e)}`)}finally{j(!1)}},ie=async()=>{try{let e=await R(`${Ln()}/api/extension/download`);if(!e.ok)throw Error(`Download failed: ${e.status}`);let t=await e.blob(),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`total-recall-extension.zip`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch(e){u(`[Failed] Extension download\n\n${e instanceof Error?e.message:String(e)}`)}},ae=(e,t,r)=>{n(n=>n&&{...n,security:{...n.security,[e]:{...n.security[e]||{},[t]:r}}})},oe=(e,t)=>{n(n=>n&&{...n,budget:{...n.budget,budget:{...n.budget.budget||{},[e]:t}}})},se=(e,t)=>{n(n=>n?{...n,brain:{...n.brain,[e]:t}}:null)},ce=e=>Array.isArray(e)?e.filter(Boolean).join(`, `):``,le=e=>e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0);return a&&!t?(0,z.jsx)(`div`,{style:{padding:40,color:`var(--text-secondary)`},"data-testid":`settings-loading`,children:(0,z.jsx)(`div`,{className:`glass-card`,style:{display:`inline-block`,padding:`12px 24px`},children:`Loading Settings...`})}):r&&!t?(0,z.jsx)(`div`,{style:{padding:40},"data-testid":`settings-error`,role:`alert`,children:(0,z.jsxs)(`div`,{className:`glass-card`,style:{display:`inline-block`,padding:`16px 24px`,border:`1px solid #ef4444`,color:`#ef4444`},children:[`Failed to load settings: `,r,(0,z.jsx)(`button`,{type:`button`,className:`btn-primary`,style:{marginLeft:16},onClick:()=>ee(),children:`Retry`})]})}):t?(0,z.jsxs)(`div`,{className:`settings-page-wrapper`,"data-testid":`settings-page`,children:[(0,z.jsx)(`style`,{children:`
|
|
5247
|
+
</div>`,enableNodeDrag:o,enableNavigationControls:o,onNodeClick:g,onNodeHover:e=>{f(e||null),c.current&&(c.current.style.cursor=e?`pointer`:`default`)},linkColor:y,linkWidth:e=>e.type===`implicit`?.5:1.5,linkDirectionalParticles:e=>e.type===`implicit`?0:2,linkDirectionalParticleWidth:1.5,linkDirectionalParticleSpeed:.005,backgroundColor:`rgba(0,0,0,0)`,d3VelocityDecay:.3}),(0,z.jsxs)(`div`,{style:{position:`absolute`,top:20,left:20,zIndex:30,pointerEvents:`none`},children:[(0,z.jsx)(`h3`,{style:{margin:0,fontSize:20,color:`#f8fafc`,fontWeight:600,letterSpacing:`-0.02em`,textShadow:`0 2px 10px rgba(0,0,0,0.5)`},children:`Constellation`}),(0,z.jsx)(`p`,{style:{margin:`2px 0 0`,fontSize:12,color:`rgba(148,163,184,0.9)`,textShadow:`0 1px 4px rgba(0,0,0,0.5)`},children:`Interactive Knowledge Network`})]}),o&&(0,z.jsxs)(`div`,{style:{position:`absolute`,top:80,left:20,display:`flex`,flexDirection:`column`,gap:12,background:`rgba(15, 20, 35, 0.4)`,backdropFilter:`blur(24px)`,WebkitBackdropFilter:`blur(24px)`,padding:`16px 20px`,borderRadius:16,border:`1px solid rgba(255, 255, 255, 0.08)`,boxShadow:`0 12px 40px rgba(0,0,0,0.3)`,width:240,zIndex:60,pointerEvents:`auto`,transition:`all 0.3s ease`},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`},children:[(0,z.jsx)(`span`,{style:{fontSize:10,fontWeight:700,color:`#cbd5e1`,textTransform:`uppercase`,letterSpacing:1.2},children:`Filters`}),(0,z.jsxs)(`span`,{style:{fontSize:10,background:`rgba(255,255,255,0.06)`,padding:`2px 6px`,borderRadius:6,color:`#94a3b8`},children:[h.nodes.length,` items`]})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:[(0,z.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:10,fontSize:12,color:`#e2e8f0`,cursor:`pointer`,userSelect:`none`},children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:p.research,onChange:()=>m(e=>({...e,research:!e.research})),style:{accentColor:`#fbbf24`,cursor:`pointer`}}),(0,z.jsx)(`span`,{style:{display:`inline-block`,width:8,height:8,borderRadius:`50%`,background:`#fbbf24`,boxShadow:`0 0 8px rgba(251,191,36,0.6)`}}),(0,z.jsx)(`span`,{style:{flex:1},children:`Research`})]}),(0,z.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:10,fontSize:12,color:`#e2e8f0`,cursor:`pointer`,userSelect:`none`},children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:p.observations,onChange:()=>m(e=>({...e,observations:!e.observations})),style:{accentColor:`#60a5fa`,cursor:`pointer`}}),(0,z.jsx)(`span`,{style:{display:`inline-block`,width:8,height:8,borderRadius:`50%`,background:`#60a5fa`,boxShadow:`0 0 8px rgba(96,165,250,0.6)`}}),(0,z.jsx)(`span`,{style:{flex:1},children:`Memory`})]}),(0,z.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:10,fontSize:12,color:`#e2e8f0`,cursor:`pointer`,userSelect:`none`},children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:p.rules,onChange:()=>m(e=>({...e,rules:!e.rules})),style:{accentColor:`#38bdf8`,cursor:`pointer`}}),(0,z.jsx)(`span`,{style:{display:`inline-block`,width:8,height:8,borderRadius:`50%`,background:`linear-gradient(135deg,#38bdf8,#f87171)`,boxShadow:`0 0 8px rgba(56,189,248,0.5)`}}),(0,z.jsx)(`span`,{style:{flex:1},children:`Rules`})]}),(0,z.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:10,fontSize:12,color:`#e2e8f0`,cursor:`pointer`,userSelect:`none`},children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:p.threads,onChange:()=>m(e=>({...e,threads:!e.threads})),style:{accentColor:`#22d3ee`,cursor:`pointer`}}),(0,z.jsx)(`span`,{style:{display:`inline-block`,width:8,height:8,borderRadius:`50%`,background:`#22d3ee`,boxShadow:`0 0 8px rgba(34,211,238,0.6)`}}),(0,z.jsx)(`span`,{style:{flex:1},children:`Sessions`})]})]})]})]})}function AW({onTranscript:e,isRecording:t=!1}){let[n,r]=(0,v.useState)(t),i=(0,v.useRef)(null),[a,o]=(0,v.useState)(!0);return(0,v.useEffect)(()=>{if(typeof window<`u`){let t=window,n=t.SpeechRecognition||t.webkitSpeechRecognition;n?(i.current=new n,i.current.continuous=!1,i.current.interimResults=!1,i.current.onresult=t=>{let n=t.results[0][0].transcript;e(n),r(!1)},i.current.onerror=()=>{r(!1)},i.current.onend=()=>{r(!1)}):setTimeout(()=>o(!1),0)}},[e]),a?(0,z.jsx)(`button`,{onClick:()=>{a&&(n?(i.current?.stop(),r(!1)):(i.current?.start(),r(!0)))},className:`btn btn-ghost ${n?`active`:``}`,style:{width:44,height:44,padding:0,display:`flex`,justifyContent:`center`,alignItems:`center`,background:n?`var(--error-muted)`:`rgba(148, 163, 184, 0.06)`,border:n?`1px solid var(--error)`:`1px solid var(--border)`,color:n?`var(--error)`:`var(--text-tertiary)`,transition:`all var(--transition-fast)`},title:n?`Stop recording`:`Start voice input`,children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z`}),(0,z.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,z.jsx)(`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`})]})}):(0,z.jsx)(`button`,{disabled:!0,className:`btn btn-ghost`,style:{width:44,height:44,padding:0,display:`flex`,justifyContent:`center`,alignItems:`center`,background:`rgba(148, 163, 184, 0.03)`,border:`1px solid var(--border)`,color:`var(--text-tertiary)`,opacity:.5,cursor:`not-allowed`},title:`Voice input not supported`,children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z`}),(0,z.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,z.jsx)(`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`})]})})}var jW=0;function MW(){return Date.now()}function NW(e){let t=MW()-e;if(t<6e4)return`just now`;let n=Math.floor(t/6e4);if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function PW({activeBrainId:e,onBrainChange:t}){let n=dt(),[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(!1),l=(0,v.useRef)(null),u=(0,v.useRef)(null),d=(0,v.useRef)(null),f=(0,v.useRef)(null),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(null),[w,T]=(0,v.useState)(null),[E,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(()=>localStorage.getItem(`tr-ext-banner-dismissed`)===`true`),[A,j]=(0,v.useState)(()=>localStorage.getItem(`tr-update-banner-dismissed-version`)),[ee,M]=(0,v.useState)([]),[te,ne]=(0,v.useState)(void 0),[N,P]=(0,v.useState)([]),[re,ie]=(0,v.useState)([]),[ae,oe]=(0,v.useState)([]),[se,ce]=(0,v.useState)(!1),[le,ue]=(0,v.useState)(``),de=(0,v.useRef)(null),[fe,pe]=(0,v.useState)([]),[me,he]=(0,v.useState)(()=>{let e=localStorage.getItem(`selectedModel`);return e&&e!==`gemini`?e:`antigravity`}),[ge,_e]=(0,v.useState)(()=>localStorage.getItem(`selectedSubModel`)||``),[ve,ye]=(0,v.useState)([]),[be,xe]=(0,v.useState)(!1),Se=(0,v.useRef)(null),F=(0,v.useCallback)(()=>{l.current?.scrollIntoView({behavior:`smooth`})},[]);(0,v.useEffect)(F,[r,F]);let Ce=(0,v.useCallback)(()=>{Qn().then(e=>{M(e)}).catch(console.error),Gr().then(e=>oe(e.items||[])).catch(console.error)},[]);(0,v.useEffect)(()=>{Qn().then(e=>{M(e),e.length>0&&(ne(e[0].id),e[0].brainId&&t&&t(e[0].brainId))}).catch(console.error),Gr().then(e=>oe(e.items||[])).catch(console.error),Yr().then(e=>{let t=e.cli_agents&&e.cli_agents.length>0?e.cli_agents:[`antigravity`,`grok`,`claude`,`codex`];pe(t);let n=localStorage.getItem(`selectedModel`);if(n&&t.includes(n))he(n);else{let e=t.includes(`antigravity`)?`antigravity`:t.includes(`grok`)?`grok`:t[0];he(e),localStorage.setItem(`selectedModel`,e)}}).catch(()=>{let e=[`antigravity`,`grok`,`claude`,`codex`];pe(e);let t=localStorage.getItem(`selectedModel`);t&&e.includes(t)?he(t):(he(`antigravity`),localStorage.setItem(`selectedModel`,`antigravity`))}),ci().then(e=>{if(ye(e),e&&e.length>0){let t=localStorage.getItem(`selectedSubModel`),n=e.some(e=>e.id===t);t&&n?_e(t):(_e(e[0].id),localStorage.setItem(`selectedSubModel`,e[0].id))}}).catch(console.error)},[]),(0,v.useEffect)(()=>{let e=!0,t=()=>{oi().then(t=>{e&&y(t)}).catch(console.error)};t();let n=setInterval(t,36e5);return()=>{e=!1,clearInterval(n)}},[]),(0,v.useEffect)(()=>{let t=!0,n=()=>{nr(e).then(e=>{t&&(ie(e),P(t=>t.filter(t=>e.some(e=>e.slug===t))))}).catch(console.error)};n();let r=new EventSource(`http://localhost:9111/stream`);return r.onmessage=e=>{if(t)try{let t=JSON.parse(e.data);(t.sender===`conflict-detector`||t.sender===`memory-ingestion`||t.message?.includes(`Surface compilation`)||t.message?.includes(`Brain embeddings rebuilt`)||t.message?.includes(`Graph indices rebuilt`)||t.message?.includes(`deleted`))&&n()}catch{}},()=>{t=!1,r.close()}},[e]),(0,v.useEffect)(()=>{function e(e){de.current&&!de.current.contains(e.target)&&ce(!1),Se.current&&!Se.current.contains(e.target)&&xe(!1)}return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[de,Se]),(0,v.useEffect)(()=>{Zn(te).then(e=>{e?(i(e),jW=Math.max(jW,e.length+1)):i([])}).catch(e=>{console.error(e),i([])})},[te]),(0,v.useEffect)(()=>{!p||h!==null||er().then(e=>g(e.enabled)).catch(()=>g(!1))},[p,h]),(0,v.useEffect)(()=>{O||mi().then(D).catch(()=>{})},[O]);let we=e=>{if(!(`speechSynthesis`in window))return;window.speechSynthesis.cancel();let t=new SpeechSynthesisUtterance(e);t.rate=1.05,t.pitch=.95,window.speechSynthesis.speak(t)},Te=async e=>{if(!(!p||!e.trim())){if(h===!1){we(e);return}try{let t=await tr(e);if(!t){g(!1),we(e);return}let n=URL.createObjectURL(t);f.current&&(f.current.pause(),URL.revokeObjectURL(f.current.src));let r=new Audio(n);f.current=r,r.onended=()=>URL.revokeObjectURL(n),r.play().catch(()=>we(e))}catch{we(e)}}},Ee=()=>{let e=`thread-${MW()}`;ne(e),i([]),o(``),P([]),u.current&&(u.current.style.height=`44px`)},De=async(e,t)=>{if(e.stopPropagation(),confirm(`Are you sure you want to delete this conversation thread?`))try{if(await $n(t),te===t){let e=ee.filter(e=>e.id!==t);e.length>0?ne(e[0].id):(ne(void 0),i([]))}Ce()}catch(e){console.error(`Failed to delete thread:`,e)}},I=async()=>{let t=a.trim();if(!t||s)return;let n=te||`thread-${MW()}`;te||ne(n);let l={id:String(++jW),role:`user`,content:t,timestamp:MW()};i(e=>[...e,l]),o(``),c(!0),d.current=new AbortController,u.current&&(u.current.style.height=`44px`);try{if(b){i(e=>[...e,{id:String(++jW),role:`assistant`,content:`🕵️ **Deep Research Agents dispatched.** Gathering facts across parallel web streams...`,timestamp:MW()}]);let{slug:e}=await ii(`proactive-research`,t,t),n=!1;for(;!n;){await new Promise(e=>setTimeout(e,2e3));let t=(await ri()).find(t=>t.slug===e);t&&(t.status===`completed`||t.status===`failed`)&&(n=!0,i(e=>e.filter(e=>e.content!==`🕵️ **Deep Research Agents dispatched.** Gathering facts across parallel web streams...`)),i(e=>[...e,{id:String(++jW),role:`assistant`,content:t.body||``,timestamp:MW()}]),Te(t.body||``))}c(!1);return}let a=[`gemini`,`antigravity`].includes(me)&&ge?`${me}:${ge}`:me,o=await Xn([...r,l].map(e=>({role:e.role,content:e.content})),d.current.signal,n,N,a,e),s={id:String(++jW),role:`assistant`,content:o,timestamp:MW(),versions:[o],currentVersionIndex:0};i(e=>[...e,s]),Te(o),Ce()}catch(e){if(e.name===`AbortError`)i(e=>[...e,{id:String(++jW),role:`assistant`,content:`⛔ Generation stopped by user.`,timestamp:MW(),versions:[`⛔ Generation stopped by user.`],currentVersionIndex:0}]);else{let t={id:String(++jW),role:`assistant`,content:`⚠️ Error: ${e.message}`,timestamp:MW(),versions:[`⚠️ Error: ${e.message}`],currentVersionIndex:0};i(e=>[...e,t])}}finally{c(!1),d.current=null}},Oe=async t=>{if(s)return;let n=r.slice(0,t).map(e=>({role:e.role,content:e.content}));c(!0),d.current=new AbortController;try{let r=[`gemini`,`antigravity`].includes(me)&&ge?`${me}:${ge}`:me,a=await Xn(n,d.current.signal,te,void 0,r,e);i(e=>{let n=[...e],r=n[t],i=r.versions||[r.content];return i.push(a),r.versions=i,r.currentVersionIndex=i.length-1,r.content=a,n}),Te(a),Ce()}catch(e){e.name!==`AbortError`&&console.error(e)}finally{c(!1),d.current=null}},ke=e=>{navigator.clipboard.writeText(e).catch(console.error)},Ae=(e,t)=>{i(n=>{let r=[...n],i=r[e];if(!i.versions)return n;let a=Math.max(0,Math.min(i.versions.length-1,(i.currentVersionIndex||0)+t));return i.currentVersionIndex=a,i.content=i.versions[a],r})},je=()=>{d.current&&(d.current.abort(),d.current=null,c(!1))},Me=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),I())},Ne=e=>{let t=e.target.value;o(t);let n=e.target;n.style.height=`44px`,n.style.height=Math.min(n.scrollHeight,160)+`px`;let r=t.match(/https?:\/\/[^\s]+/);C(r?r[0]:null)},Pe=async e=>{if(S)try{await ai({url:S,action:e}),T(`✅ URL sent to ${e}`),C(null),setTimeout(()=>T(null),3e3)}catch(e){console.error(`Share API error:`,e),T(`⚠️ Failed to process URL`),setTimeout(()=>T(null),3e3)}},Fe=re.filter(e=>e.title.toLowerCase().includes(le.toLowerCase())||e.slug.toLowerCase().includes(le.toLowerCase())||e.category&&e.category.toLowerCase().includes(le.toLowerCase()));return(0,z.jsxs)(`div`,{className:`chat-layout`,children:[(0,z.jsxs)(`aside`,{className:`chat-threads-sidebar`,children:[(0,z.jsx)(`div`,{className:`sidebar-header`,children:(0,z.jsxs)(`button`,{className:`new-chat-btn`,onClick:Ee,children:[(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{marginRight:6},children:[(0,z.jsx)(`line`,{x1:`12`,y1:`5`,x2:`12`,y2:`19`}),(0,z.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`})]}),`New Chat`]})}),(0,z.jsx)(`div`,{className:`thread-list`,children:ee.map(e=>(0,z.jsxs)(`div`,{className:`thread-item ${te===e.id?`active`:``}`,onClick:()=>{ne(e.id),e.brainId&&t&&t(e.brainId)},children:[(0,z.jsxs)(`div`,{className:`thread-info`,children:[(0,z.jsx)(`div`,{className:`thread-title`,title:e.title,children:e.title}),(0,z.jsxs)(`div`,{className:`thread-meta`,children:[(0,z.jsxs)(`span`,{children:[e.turns,` `,e.turns===1?`turn`:`turns`]}),(0,z.jsx)(`span`,{children:`•`}),(0,z.jsx)(`span`,{children:NW(e.lastUpdated)})]})]}),(0,z.jsx)(`button`,{className:`thread-delete-btn`,onClick:t=>De(t,e.id),title:`Delete chat thread`,children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`polyline`,{points:`3 6 5 6 21 6`}),(0,z.jsx)(`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`}),(0,z.jsx)(`line`,{x1:`10`,y1:`11`,x2:`10`,y2:`17`}),(0,z.jsx)(`line`,{x1:`14`,y1:`11`,x2:`14`,y2:`17`})]})})]},e.id))})]}),(0,z.jsxs)(`div`,{className:`chat-container`,style:{position:`relative`,overflow:`hidden`},children:[(0,z.jsx)(`div`,{"aria-hidden":!0,style:{position:`absolute`,top:0,left:0,right:0,bottom:0,zIndex:0,pointerEvents:`none`,opacity:r.length>0?.22:.55,transition:`opacity 0.3s ease`},children:(0,z.jsx)(kW,{threads:ee,memoryNodes:re,researchItems:ae,onOpenThread:()=>{},onGroundMemoryNode:()=>{},selectedGroundingNodes:N,interactive:!1})}),(0,z.jsxs)(`header`,{className:`chat-header animate-fade-in`,style:{position:`relative`,zIndex:40,overflow:`visible`},children:[(0,z.jsxs)(`div`,{className:`chat-header-title`,children:[(0,z.jsx)(`h2`,{children:`Chat Session`}),te&&(0,z.jsx)(`span`,{className:`badge badge-accent`,style:{textTransform:`none`,letterSpacing:`normal`,fontSize:`11px`,padding:`2px 8px`},children:te})]}),(0,z.jsxs)(`div`,{className:`chat-header-model-selector`,ref:Se,style:{position:`relative`,zIndex:50},children:[(0,z.jsx)(`span`,{className:`selector-label`,children:`Model / provider:`}),(0,z.jsxs)(`div`,{className:`model-selector-dropdown-wrapper`,style:{position:`relative`,zIndex:50},children:[(0,z.jsxs)(`button`,{type:`button`,className:`model-selector-dropdown-btn ${be?`active`:``}`,onClick:e=>{e.stopPropagation(),xe(e=>!e)},title:`Select CLI agent / provider`,children:[(0,z.jsx)(`span`,{style:{textTransform:`capitalize`},children:me||`Select Model`}),(0,z.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,z.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})]}),be&&(0,z.jsx)(`div`,{className:`model-selector-menu glass`,style:{zIndex:200,pointerEvents:`auto`},role:`listbox`,children:fe.map(e=>(0,z.jsxs)(`div`,{role:`option`,"aria-selected":me===e,className:`model-selector-item ${me===e?`selected`:``}`,onClick:t=>{t.stopPropagation(),he(e),localStorage.setItem(`selectedModel`,e),_e(``),localStorage.removeItem(`selectedSubModel`),xe(!1)},children:[(0,z.jsxs)(`div`,{className:`model-selector-item-info`,children:[(0,z.jsx)(`span`,{className:`model-selector-item-name`,style:{textTransform:`capitalize`},children:e}),(0,z.jsxs)(`span`,{className:`model-selector-item-desc`,children:[e===`antigravity`&&`Google Antigravity`,e===`grok`&&`xAI Grok Build CLI`,e===`gemini`&&`Google Gemini CLI`,e===`claude`&&`Anthropic Claude CLI`,e===`codex`&&`Codex Coding Agent`]})]}),(0,z.jsx)(`span`,{className:`model-selector-item-badge`,children:`CLI`})]},e))})]}),[`gemini`,`antigravity`].includes(me)&&ve.length>0&&(0,z.jsxs)(`div`,{className:`chat-header-submodel-selector`,style:{display:`flex`,alignItems:`center`,gap:8,marginLeft:16},children:[(0,z.jsx)(`span`,{className:`selector-label`,style:{fontSize:`12px`,color:`var(--text-tertiary)`,fontWeight:500},children:`Base:`}),(0,z.jsx)(`select`,{value:ge,onChange:e=>{_e(e.target.value),localStorage.setItem(`selectedSubModel`,e.target.value)},className:`submodel-select`,style:{background:`rgba(255, 255, 255, 0.04)`,border:`1px solid var(--border)`,borderRadius:`var(--radius-sm)`,color:`var(--text-secondary)`,padding:`6px 12px`,fontSize:`13px`,fontWeight:500,outline:`none`,cursor:`pointer`,transition:`all var(--transition-fast)`},children:ve.map(e=>(0,z.jsx)(`option`,{value:e.id,style:{background:`#12121a`,color:`var(--text-secondary)`},children:e.displayName},e.id))})]})]})]}),_?.updateAvailable&&A!==_.latestVersion&&(0,z.jsxs)(`div`,{className:`animate-fade-in`,style:{margin:`0 16px 12px`,padding:`12px 16px`,background:`linear-gradient(135deg, rgba(63, 185, 80, 0.12), rgba(34, 197, 94, 0.12))`,border:`1px solid rgba(63, 185, 80, 0.3)`,borderRadius:10,display:`flex`,alignItems:`center`,gap:12,position:`relative`,zIndex:40},children:[(0,z.jsx)(`span`,{style:{fontSize:22,flexShrink:0},children:`🚀`}),(0,z.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,z.jsx)(`div`,{style:{fontWeight:600,fontSize:13,color:`var(--text-primary)`,marginBottom:2},children:`System Update Available`}),(0,z.jsxs)(`div`,{style:{fontSize:11,color:`var(--text-secondary)`},children:[`Version `,_.latestVersion,` is available. Upgrade to load the latest features.`]})]}),(0,z.jsx)(`button`,{onClick:()=>n(`/health`),style:{flexShrink:0,padding:`6px 14px`,background:`#3fb950`,color:`#fff`,border:`none`,borderRadius:6,fontWeight:600,fontSize:12,cursor:`pointer`,whiteSpace:`nowrap`},children:`Go to Update`}),(0,z.jsx)(`button`,{onClick:()=>{_?.latestVersion&&(localStorage.setItem(`tr-update-banner-dismissed-version`,_.latestVersion),j(_.latestVersion))},title:`Dismiss banner`,"aria-label":`Dismiss update banner`,style:{background:`transparent`,border:`none`,color:`var(--text-muted)`,fontSize:16,cursor:`pointer`,padding:`4px 6px`,lineHeight:1},children:`✕`})]}),E?.available&&!E.connected&&!O&&(0,z.jsxs)(`div`,{style:{margin:`0 16px 0`,padding:`12px 16px`,background:`linear-gradient(135deg, rgba(108, 92, 231, 0.12), rgba(99, 179, 237, 0.12))`,border:`1px solid rgba(108, 92, 231, 0.3)`,borderRadius:10,display:`flex`,alignItems:`center`,gap:12,animation:`fadeIn 0.3s ease`,position:`relative`,zIndex:40},children:[(0,z.jsx)(`span`,{style:{fontSize:22,flexShrink:0},children:`🧩`}),(0,z.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,z.jsx)(`div`,{style:{fontWeight:600,fontSize:13,color:`var(--text-primary)`,marginBottom:2},children:`Chrome Extension Available`}),(0,z.jsx)(`div`,{style:{fontSize:11,color:`var(--text-secondary)`},children:`Browse with your brain — contextual memory, quick capture, and research from any page`})]}),(0,z.jsx)(`a`,{href:`/api/extension/download`,download:!0,style:{flexShrink:0,padding:`6px 14px`,background:`linear-gradient(135deg, #3b82f6, #93c5fd)`,color:`#fff`,borderRadius:6,fontWeight:500,fontSize:12,textDecoration:`none`,whiteSpace:`nowrap`},children:`⬇ Download`}),(0,z.jsx)(`button`,{onClick:()=>{k(!0),localStorage.setItem(`tr-ext-banner-dismissed`,`true`)},style:{flexShrink:0,background:`none`,border:`none`,color:`var(--text-tertiary)`,cursor:`pointer`,fontSize:16,padding:`0 2px`,lineHeight:1},title:`Dismiss`,children:`✕`})]}),(0,z.jsx)(`div`,{className:`chat-messages`,style:{position:`relative`,zIndex:1,pointerEvents:`auto`},children:(0,z.jsxs)(`div`,{style:{position:`relative`,display:`flex`,flexDirection:`column`,gap:`16px`,width:`100%`,maxWidth:800,margin:`0 auto`,pointerEvents:`auto`},children:[r.map((e,t)=>(0,z.jsxs)(`div`,{className:`message message-${e.role}`,style:{backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,background:e.role===`user`?`rgba(108, 92, 231, 0.75)`:`rgba(18, 18, 26, 0.75)`,border:`1px solid rgba(255, 255, 255, 0.08)`},children:[(0,z.jsx)(`div`,{style:{whiteSpace:`pre-wrap`,overflowWrap:`break-word`},children:e.content}),e.role===`assistant`&&(0,z.jsxs)(`div`,{style:{display:`flex`,gap:12,marginTop:12,fontSize:13,color:`var(--text-tertiary)`,alignItems:`center`,userSelect:`none`},children:[e.versions&&e.versions.length>1&&(0,z.jsxs)(`div`,{style:{display:`flex`,gap:6,alignItems:`center`,marginRight:4},children:[(0,z.jsx)(`button`,{onClick:()=>Ae(t,-1),disabled:(e.currentVersionIndex||0)===0,style:{background:`none`,border:`none`,color:`inherit`,cursor:`pointer`,padding:2,opacity:(e.currentVersionIndex||0)===0?.3:1},children:`◄`}),(0,z.jsxs)(`span`,{children:[(e.currentVersionIndex||0)+1,` / `,e.versions.length]}),(0,z.jsx)(`button`,{onClick:()=>Ae(t,1),disabled:(e.currentVersionIndex||0)===e.versions.length-1,style:{background:`none`,border:`none`,color:`inherit`,cursor:`pointer`,padding:2,opacity:(e.currentVersionIndex||0)===e.versions.length-1?.3:1},children:`►`})]}),(0,z.jsx)(`button`,{onClick:()=>ke(e.content),title:`Copy to clipboard`,style:{background:`none`,border:`none`,color:`inherit`,cursor:`pointer`,display:`flex`,alignItems:`center`,gap:4},children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`rect`,{x:`9`,y:`9`,width:`13`,height:`13`,rx:`2`,ry:`2`}),(0,z.jsx)(`path`,{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`})]})}),(0,z.jsx)(`button`,{onClick:()=>Te(e.content),title:`Read Aloud`,style:{background:`none`,border:`none`,color:`inherit`,cursor:`pointer`,display:`flex`,alignItems:`center`,gap:4},children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`polygon`,{points:`11 5 6 9 2 9 2 15 6 15 11 19 11 5`}),(0,z.jsx)(`path`,{d:`M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07`})]})}),(0,z.jsx)(`button`,{onClick:()=>Oe(t),disabled:s,title:`Regenerate Response`,style:{background:`none`,border:`none`,color:`inherit`,cursor:s?`default`:`pointer`,display:`flex`,alignItems:`center`,gap:4,opacity:s?.3:1},children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`polyline`,{points:`1 4 1 10 7 10`}),(0,z.jsx)(`polyline`,{points:`23 20 23 14 17 14`}),(0,z.jsx)(`path`,{d:`M20.49 9A9 9 0 0 0 5.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 0 1 3.51 15`})]})})]})]},e.id)),s&&(0,z.jsx)(`div`,{className:`message message-assistant`,style:{backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,background:`rgba(18, 18, 26, 0.75)`,border:`1px solid rgba(255, 255, 255, 0.08)`},children:(0,z.jsx)(`span`,{className:`skeleton`,style:{display:`inline-block`,width:180,height:16}})}),(0,z.jsx)(`div`,{ref:l})]})}),(0,z.jsxs)(`div`,{className:`chat-input-bar`,style:{position:`relative`,zIndex:30,pointerEvents:`auto`},children:[N.length>0&&(0,z.jsx)(`div`,{className:`grounding-pills`,children:N.map(e=>{let t=re.find(t=>t.slug===e);return(0,z.jsxs)(`div`,{className:`grounding-pill animate-fade-in`,children:[(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`path`,{d:`M4 19.5A2.5 2.5 0 0 1 6.5 17H20`}),(0,z.jsx)(`path`,{d:`M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z`})]}),(0,z.jsx)(`span`,{className:`grounding-pill-title`,children:t?.title||e}),(0,z.jsx)(`button`,{className:`grounding-pill-remove`,onClick:()=>P(t=>t.filter(t=>t!==e)),title:`Remove grounding context`,children:`×`})]},e)})}),(0,z.jsxs)(`div`,{className:`chat-input-wrapper`,children:[(0,z.jsx)(`button`,{className:`btn btn-ghost ${b?`active`:``}`,style:{width:44,height:44,padding:0,display:`flex`,justifyContent:`center`,alignItems:`center`,color:b?`var(--accent)`:`var(--text-tertiary)`,borderColor:b?`var(--accent)`:`var(--border)`},onClick:()=>x(!b),title:b?`Deep Research On`:`Deep Research Off`,children:(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{width:18,height:18},children:[(0,z.jsx)(`path`,{d:`M12 2v20`}),(0,z.jsx)(`path`,{d:`M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6`})]})}),(0,z.jsxs)(`div`,{style:{position:`relative`,display:`flex`},ref:de,children:[(0,z.jsxs)(`button`,{className:`btn btn-ghost ${N.length>0?`active`:``}`,style:{width:44,height:44,padding:0,display:`flex`,justifyContent:`center`,alignItems:`center`,color:N.length>0?`var(--accent)`:`var(--text-tertiary)`,borderColor:N.length>0?`var(--accent)`:`var(--border)`},onClick:()=>ce(!se),title:`Ground with brain nodes`,children:[(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{width:18,height:18},children:[(0,z.jsx)(`path`,{d:`M4 19.5A2.5 2.5 0 0 1 6.5 17H20`}),(0,z.jsx)(`path`,{d:`M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z`})]}),N.length>0&&(0,z.jsx)(`span`,{className:`grounding-count-badge`,children:N.length})]}),se&&(0,z.jsxs)(`div`,{className:`node-selector-popover glass`,children:[(0,z.jsxs)(`div`,{className:`node-selector-header`,children:[(0,z.jsx)(`h4`,{children:`Ground with Brain Nodes`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`Search nodes...`,value:le,onChange:e=>ue(e.target.value),className:`node-search-input`,autoFocus:!0})]}),(0,z.jsx)(`div`,{className:`node-selector-list`,children:Fe.length===0?(0,z.jsx)(`div`,{className:`node-selector-empty`,children:`No nodes found`}):Fe.map(e=>{let t=N.includes(e.slug);return(0,z.jsxs)(`div`,{className:`node-selector-item ${t?`selected`:``}`,onClick:()=>{P(t?t=>t.filter(t=>t!==e.slug):t=>[...t,e.slug])},children:[(0,z.jsx)(`span`,{className:`node-selector-item-checkbox`,children:t?`✓`:``}),(0,z.jsxs)(`div`,{className:`node-selector-item-info`,children:[(0,z.jsx)(`span`,{className:`node-selector-item-title`,children:e.title}),(0,z.jsxs)(`span`,{className:`node-selector-item-meta`,children:[e.category,` • `,e.status||`active`]})]})]},e.slug)})})]})]}),(0,z.jsx)(AW,{onTranscript:e=>{o(t=>t+(t.endsWith(` `)||t===``?``:` `)+e),setTimeout(()=>{if(u.current){u.current.focus();let e=new Event(`input`,{bubbles:!0});u.current.dispatchEvent(e)}},10)}}),(0,z.jsxs)(`div`,{style:{position:`relative`,flex:1,display:`flex`,alignItems:`center`},children:[(0,z.jsx)(`textarea`,{ref:u,id:`chat-input`,value:a,onChange:Ne,onKeyDown:Me,placeholder:`Message your brain…`,rows:1,disabled:s,style:{paddingRight:44}}),(0,z.jsx)(`button`,{className:`btn btn-ghost ${p?`active`:``}`,style:{position:`absolute`,right:4,bottom:4,width:36,height:36,padding:0,display:`flex`,justifyContent:`center`,alignItems:`center`,color:p?`#ef4444`:`var(--text-tertiary)`,border:`none`,background:`transparent`},onClick:()=>{m(!p),p&&`speechSynthesis`in window&&window.speechSynthesis.cancel()},title:p?`Voice Mode On`:`Voice Mode Off`,children:p?(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{width:18,height:18},children:[(0,z.jsx)(`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z`}),(0,z.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,z.jsx)(`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`}),(0,z.jsx)(`line`,{x1:`8`,x2:`16`,y1:`22`,y2:`22`})]}):(0,z.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{width:18,height:18},children:[(0,z.jsx)(`line`,{x1:`1`,x2:`23`,y1:`1`,y2:`23`}),(0,z.jsx)(`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12M15 9.34V5a3 3 0 0 0-5.94-.88`}),(0,z.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-1.39 4.2M5 10v2a7 7 0 0 0 1.93 4.88`}),(0,z.jsx)(`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`}),(0,z.jsx)(`line`,{x1:`8`,x2:`16`,y1:`22`,y2:`22`})]})})]}),s?(0,z.jsx)(`button`,{className:`chat-send-btn`,onClick:je,id:`chat-stop`,style:{background:`var(--error)`,color:`#fff`},title:`Stop Generation`,children:(0,z.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`currentColor`,style:{width:20,height:20},children:(0,z.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`,ry:`2`})})}):(0,z.jsx)(`button`,{className:`chat-send-btn`,onClick:I,disabled:!a.trim(),id:`chat-send`,title:`Send Message`,children:(0,z.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,z.jsx)(`path`,{d:`M3.478 2.405a.75.75 0 00-.926.94l2.432 7.905H13.5a.75.75 0 010 1.5H4.984l-2.432 7.905a.75.75 0 00.926.94 60.519 60.519 0 0018.445-8.986.75.75 0 000-1.218A60.517 60.517 0 003.478 2.405z`})})})]}),S&&(0,z.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,padding:`8px 12px`,background:`var(--bg-secondary, #1e1e2e)`,borderRadius:`8px`,alignItems:`center`,fontSize:`0.85rem`,marginTop:4},children:[(0,z.jsx)(`span`,{style:{color:`var(--text-secondary)`},children:`🔗 URL detected`}),(0,z.jsx)(`button`,{className:`btn btn-sm`,onClick:()=>Pe(`research`),children:`🔬 Research`}),(0,z.jsx)(`button`,{className:`btn btn-sm`,onClick:()=>Pe(`remember`),children:`📌 Remember`})]}),w&&(0,z.jsx)(`div`,{style:{padding:`6px 12px`,background:`rgba(46, 204, 113, 0.1)`,border:`1px solid rgba(46, 204, 113, 0.3)`,borderRadius:`8px`,fontSize:`0.8rem`,color:`var(--success)`,marginTop:4,textAlign:`center`},children:w})]})]})]})}var FW=[`all`,`invariants`,`preferences`,`anti-patterns`,`patterns`,`decisions`,`concepts`,`facts`,`lore`];function IW(e){if(!e)return``;let t=e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`);return t=t.replace(/^### (.*$)/gim,`<h3>$1</h3>`),t=t.replace(/^## (.*$)/gim,`<h2>$1</h2>`),t=t.replace(/^# (.*$)/gim,`<h1>$1</h1>`),t=t.replace(/\*\*(.*?)\*\*/g,`<strong>$1</strong>`),t=t.replace(/\*(.*?)\*/g,`<em>$1</em>`),t=t.replace(/```([\s\S]*?)```/g,`<pre style="background:rgba(0,0,0,0.3);padding:12px;border-radius:6px;border:1px solid rgba(255,255,255,0.06);font-family:monospace;overflow-x:auto;"><code>$1</code></pre>`),t=t.replace(/`(.*?)`/g,`<code style="background:rgba(255,255,255,0.06);padding:2px 6px;border-radius:4px;font-family:monospace;">$1</code>`),t=t.replace(/^> (.*$)/gim,`<blockquote style="border-left:4px solid var(--purple-primary);padding-left:14px;color:var(--text-secondary);margin:16px 0;font-style:italic;">$1</blockquote>`),t=t.replace(/^- (.*$)/gim,`<li style="margin-left:20px;list-style-type:disc;">$1</li>`),t=t.replace(/\n/g,`<br />`),(0,z.jsx)(`div`,{dangerouslySetInnerHTML:{__html:t},className:`markdown-preview-block`})}function LW({activeBrainId:e}){let[t,n]=jn(),r=t.get(`slug`),[i,a]=(0,v.useState)(`vault`),[o,s]=(0,v.useState)([]),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(`all`),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)([]),[x,S]=(0,v.useState)(0),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)([]),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(!1),[j,ee]=(0,v.useState)(!1),[M,te]=(0,v.useState)(``),[ne,N]=(0,v.useState)(``),[P,re]=(0,v.useState)(`invariants`),[ie,ae]=(0,v.useState)(``),[oe,se]=(0,v.useState)(`active`),[ce,le]=(0,v.useState)(`low`),[ue,de]=(0,v.useState)(`should`),[fe,pe]=(0,v.useState)(1),[me,he]=(0,v.useState)(3),[ge,_e]=(0,v.useState)(``),[ve,ye]=(0,v.useState)(``),[be,xe]=(0,v.useState)(``),[Se,F]=(0,v.useState)(``),Ce=(0,v.useCallback)(async()=>{h(!0),_(``);try{if(f.trim()){let e=await rr(f,u===`all`?void 0:u);s(e)}else{let t=await nr(e,u===`all`?void 0:u);s(t)}}catch(e){_(e.message),s([])}finally{h(!1)}},[u,f,e]);(0,v.useEffect)(()=>{c&&(te(c.slug||``),N(c.title||``),re(c.category||`invariants`),ae(c.content||c.body||``),se(c.status||`active`),le(c.priority||`low`),de(c.modality||`should`),pe(c.confidence??1),he(c.importance??3),_e((c.tags||[]).join(`, `)),ye((c.related||[]).join(`, `)),xe((c.contradicts||[]).join(`, `)),F((c.supersedes||[]).join(`, `)))},[c]);let we=async()=>{if(c){h(!0),_(``);try{let t=ge.split(`,`).map(e=>e.trim()).filter(Boolean),n=ve.split(`,`).map(e=>e.trim()).filter(Boolean),r=be.split(`,`).map(e=>e.trim()).filter(Boolean),i=Se.split(`,`).map(e=>e.trim()).filter(Boolean),a=await ar(c.slug,{title:ne,category:P,content:ie,status:oe,priority:ce,modality:ue,confidence:fe,importance:me,tags:t,related:n,contradicts:r,supersedes:i},e);l(a),A(!1),Ce()}catch(e){_(e.message)}finally{h(!1)}}},Te=async()=>{if(!M.trim()||!ne.trim()||!ie.trim()){_(`Slug, Title, and Content are required fields.`);return}h(!0),_(``);try{let t=ge.split(`,`).map(e=>e.trim()).filter(Boolean),r=ve.split(`,`).map(e=>e.trim()).filter(Boolean),i=be.split(`,`).map(e=>e.trim()).filter(Boolean),a=Se.split(`,`).map(e=>e.trim()).filter(Boolean),o=await or({slug:M,title:ne,category:P,content:ie,status:oe,priority:ce,modality:ue,confidence:fe,importance:me,tags:t,related:r,contradicts:i,supersedes:a},e);ee(!1),l(o),n({slug:o.slug}),Ce()}catch(e){_(e.message)}finally{h(!1)}},Ee=async t=>{if(window.confirm(`Are you sure you want to delete memory node "${t}"?`)){h(!0),_(``);try{await sr(t,e),l(null),n({}),Ce()}catch(e){_(e.message)}finally{h(!1)}}},De=(0,v.useCallback)(async()=>{try{let e=await cr();E(e.conflicts||[])}catch(e){console.warn(`Conflicts API error (enhanced features might be disabled):`,e)}},[]);(0,v.useEffect)(()=>{let e=setTimeout(Ce,300);return()=>clearTimeout(e)},[Ce]);let I=(0,v.useCallback)(async()=>{w(!0);try{let e=await hi(100);b(e.sessions),S(e.total)}catch(e){_(e.message)}finally{w(!1)}},[]);(0,v.useEffect)(()=>{i===`conflicts`?De():i===`sessions`&&I()},[i,De,I]);let Oe=async e=>{if(window.confirm(`Delete session "${e}"?`))try{await gi(e),I()}catch(e){_(e.message)}};(0,v.useEffect)(()=>{r?(async()=>{let t=o.find(e=>e.slug===r);if(t&&(t.content||t.body)){l(t),_(``);return}h(!0),_(``);try{let n=await ir(r,e);n?l(n):t?l(t):(_(`Memory node not found: ${r}`),l(null))}catch(e){t?(l(t),_(``)):(_(`Failed to load memory node '${r}': ${e.message}`),l(null))}finally{h(!1)}})():l(null)},[r,e,o]),(0,v.useEffect)(()=>{let e=new EventSource(`http://localhost:9111/stream`);return e.onmessage=e=>{try{let t=JSON.parse(e.data);(t.subsystem===`conflict-detector`||t.subsystem===`rebuild`||t.subsystem===`session-watcher`)&&(Ce(),De())}catch{}},e.onerror=()=>{e.close()},()=>{e.close()}},[Ce,De]);let ke=e=>{l(e),_(``),n({slug:e.slug})},Ae=async(e,t,n)=>{O(e),_(``);try{await lr(e,t,n),await De(),await Ce()}catch(e){_(e.message)}finally{O(null)}},je=(e,t,n)=>(0,z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:[(0,z.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:16},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Slug (kebab-case, matches filename)`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`e.g. prefer-atomic-writes`,value:M,onChange:e=>te(e.target.value),disabled:!n,style:{width:`100%`,background:`rgba(255,255,255,0.03)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`}})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Title (One-line description)`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`e.g. Always write files atomically (write-then-rename)`,value:ne,onChange:e=>N(e.target.value),style:{width:`100%`,background:`rgba(255,255,255,0.03)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`}})]}),(0,z.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:12},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Category`}),(0,z.jsxs)(`select`,{value:P,onChange:e=>re(e.target.value),style:{width:`100%`,background:`rgba(15,23,42,0.9)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`},children:[(0,z.jsx)(`option`,{value:`invariants`,children:`invariants`}),(0,z.jsx)(`option`,{value:`patterns`,children:`patterns`}),(0,z.jsx)(`option`,{value:`anti-patterns`,children:`anti-patterns`}),(0,z.jsx)(`option`,{value:`preferences`,children:`preferences`}),(0,z.jsx)(`option`,{value:`decisions`,children:`decisions`}),(0,z.jsx)(`option`,{value:`concepts`,children:`concepts`}),(0,z.jsx)(`option`,{value:`facts`,children:`facts`}),(0,z.jsx)(`option`,{value:`lore`,children:`lore`})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Modality`}),(0,z.jsxs)(`select`,{value:ue,onChange:e=>de(e.target.value),style:{width:`100%`,background:`rgba(15,23,42,0.9)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`},children:[(0,z.jsx)(`option`,{value:`must`,children:`must`}),(0,z.jsx)(`option`,{value:`must_not`,children:`must_not`}),(0,z.jsx)(`option`,{value:`should`,children:`should`}),(0,z.jsx)(`option`,{value:`should_not`,children:`should_not`})]})]})]})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,z.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:12},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Status`}),(0,z.jsxs)(`select`,{value:oe,onChange:e=>se(e.target.value),style:{width:`100%`,background:`rgba(15,23,42,0.9)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`},children:[(0,z.jsx)(`option`,{value:`active`,children:`active`}),(0,z.jsx)(`option`,{value:`draft`,children:`draft`}),(0,z.jsx)(`option`,{value:`deprecated`,children:`deprecated`}),(0,z.jsx)(`option`,{value:`superseded`,children:`superseded`})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Importance (1-5 Stars)`}),(0,z.jsxs)(`select`,{value:me,onChange:e=>he(Number(e.target.value)),style:{width:`100%`,background:`rgba(15,23,42,0.9)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`},children:[(0,z.jsx)(`option`,{value:1,children:`★ 1/5`}),(0,z.jsx)(`option`,{value:2,children:`★★ 2/5`}),(0,z.jsx)(`option`,{value:3,children:`★★★ 3/5`}),(0,z.jsx)(`option`,{value:4,children:`★★★★ 4/5`}),(0,z.jsx)(`option`,{value:5,children:`★★★★★ 5/5`})]})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:[`Confidence: `,(0,z.jsxs)(`strong`,{children:[Math.round(fe*100),`%`]})]}),(0,z.jsx)(`input`,{type:`range`,min:`0`,max:`1`,step:`0.05`,value:fe,onChange:e=>pe(Number(e.target.value)),style:{width:`100%`,height:6,background:`rgba(255,255,255,0.1)`,borderRadius:3,outline:`none`}})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Tags (comma separated)`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`e.g. filesystem, reliability, writes`,value:ge,onChange:e=>_e(e.target.value),style:{width:`100%`,background:`rgba(255,255,255,0.03)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`}})]})]})]}),(0,z.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr 1fr`,gap:12},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Related Nodes (comma separated slugs)`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`e.g. use-atomic-writes, git-wiping`,value:ve,onChange:e=>ye(e.target.value),style:{width:`100%`,background:`rgba(255,255,255,0.03)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`}})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Contradicts Nodes (comma separated slugs)`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`e.g. write-anywhere-sync`,value:be,onChange:e=>xe(e.target.value),style:{width:`100%`,background:`rgba(255,255,255,0.03)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`}})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{style:{display:`block`,fontSize:12,color:`var(--text-secondary)`,marginBottom:4},children:`Supersedes Nodes (comma separated slugs)`}),(0,z.jsx)(`input`,{type:`text`,placeholder:`e.g. prefer-atomic-writes-v1`,value:Se,onChange:e=>F(e.target.value),style:{width:`100%`,background:`rgba(255,255,255,0.03)`,border:`1px solid var(--border)`,borderRadius:6,padding:`8px 12px`,color:`#fff`}})]})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,z.jsx)(`label`,{style:{fontSize:12,color:`var(--text-secondary)`},children:`Memory Content`}),(0,z.jsx)(`textarea`,{value:ie,onChange:e=>ae(e.target.value),placeholder:`Write markdown here...`,style:{minHeight:300,padding:16,color:`#fff`,background:`#090d16`,border:`1px solid var(--border)`,borderRadius:8,outline:`none`,fontSize:14,lineHeight:1.6,resize:`vertical`,width:`100%`,boxSizing:`border-box`}})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:12,marginTop:12},children:[(0,z.jsx)(`button`,{className:`btn btn-ghost`,type:`button`,onClick:t,style:{fontSize:13},children:`Cancel`}),(0,z.jsx)(`button`,{className:`btn btn-purple`,type:`button`,onClick:e,style:{fontSize:13},children:n?`🚀 Create Memory Node`:`💾 Save Changes`})]})]}),Me=o.reduce((e,t)=>(e[t.category]=(e[t.category]||0)+1,e),{});return(0,z.jsxs)(`div`,{className:`page`,children:[(0,z.jsxs)(`div`,{className:`page-header`,style:{display:`flex`,justifyContent:`space-between`,alignItems:`flex-end`,marginBottom:20},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h1`,{children:`Memory Vault`}),(0,z.jsx)(`p`,{children:`Browse, audit, and resolve contradictions in your SSSS knowledge graph`})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,background:`rgba(255,255,255,0.03)`,padding:4,borderRadius:8,border:`1px solid var(--border)`},children:[(0,z.jsx)(`button`,{className:`btn btn-sm ${i===`vault`?`btn-purple`:`btn-ghost`}`,onClick:()=>{a(`vault`),l(null),n({})},style:{borderRadius:6,fontSize:12,padding:`6px 12px`},children:`🧠 Active Nodes`}),(0,z.jsxs)(`button`,{className:`btn btn-sm ${i===`conflicts`?`btn-cyan`:`btn-ghost`}`,onClick:()=>{a(`conflicts`),l(null),n({})},style:{borderRadius:6,fontSize:12,padding:`6px 12px`,display:`flex`,alignItems:`center`,gap:6},children:[`⚠️ Quarantined Conflicts`,T.length>0&&(0,z.jsx)(`span`,{style:{background:`#ef4444`,color:`#fff`,fontSize:9,padding:`1px 5px`,borderRadius:10,fontWeight:700},children:T.length})]}),(0,z.jsxs)(`button`,{className:`btn btn-sm ${i===`sessions`?`btn-purple`:`btn-ghost`}`,onClick:()=>{a(`sessions`),l(null),n({})},style:{borderRadius:6,fontSize:12,padding:`6px 12px`},children:[`📝 Sessions`,x>0&&(0,z.jsx)(`span`,{style:{background:`rgba(139,92,246,0.3)`,color:`#a78bfa`,fontSize:9,padding:`1px 5px`,borderRadius:10,fontWeight:700,marginLeft:4},children:x})]})]})]}),g&&(0,z.jsxs)(`div`,{className:`badge badge-error`,style:{alignSelf:`flex-start`,marginBottom:15},children:[`⚠️ `,g]}),i===`vault`?(0,z.jsxs)(`div`,{className:`memory-layout`,children:[(0,z.jsxs)(`div`,{className:`memory-sidebar`,children:[(0,z.jsx)(`h3`,{style:{margin:`0 0 12px 0`},children:`Categories`}),FW.map(e=>(0,z.jsxs)(`button`,{className:`category-btn ${u===e?`active`:``}`,onClick:()=>{d(e),n({}),ee(!1),A(!1)},children:[(0,z.jsx)(`span`,{children:e===`all`?`📋 All Nodes`:e}),e===`all`?(0,z.jsx)(`span`,{className:`category-count`,children:o.length}):Me[e]?(0,z.jsx)(`span`,{className:`category-count`,children:Me[e]}):null]},e)),(0,z.jsx)(`button`,{className:`btn btn-purple`,style:{width:`100%`,marginTop:20,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:8,fontSize:13},onClick:()=>{l(null),n({}),ee(!0),A(!1),te(``),N(``),re(`invariants`),ae(``),se(`active`),le(`low`),de(`should`),pe(1),he(3),_e(``),ye(``),xe(``),F(``)},children:`➕ Create New Node`})]}),(0,z.jsxs)(`div`,{className:`memory-main`,children:[(0,z.jsxs)(`div`,{className:`memory-search`,children:[(0,z.jsx)(`input`,{id:`memory-search`,type:`text`,placeholder:`Search memory nodes…`,value:f,onChange:e=>p(e.target.value)}),(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:Ce,children:`Refresh`})]}),m?(0,z.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[1,2,3].map(e=>(0,z.jsx)(`div`,{className:`skeleton`,style:{height:60}},e))}):j?(0,z.jsxs)(`div`,{className:`memory-detail`,style:{background:`rgba(15,23,42,0.45)`,backdropFilter:`blur(12px)`,border:`1px solid var(--border)`,borderRadius:12,padding:24},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:20},children:[(0,z.jsx)(`h2`,{style:{margin:0,color:`#fff`},children:`Create New SSSS Memory Node`}),(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>ee(!1),style:{fontSize:12},children:`← Back to List`})]}),je(Te,()=>ee(!1),!0)]}):c&&k?(0,z.jsxs)(`div`,{className:`memory-detail`,style:{background:`rgba(15,23,42,0.45)`,backdropFilter:`blur(12px)`,border:`1px solid var(--border)`,borderRadius:12,padding:24},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:20},children:[(0,z.jsx)(`h2`,{style:{margin:0,color:`#fff`},children:`Edit Memory Node`}),(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>A(!1),style:{fontSize:12},children:`← Cancel Edit`})]}),je(we,()=>A(!1),!1)]}):c?(0,z.jsxs)(`div`,{className:`memory-detail`,style:{background:`rgba(15,23,42,0.45)`,backdropFilter:`blur(12px)`,border:c.modality===`must`?`2px solid #10b981`:c.modality===`must_not`?`2px solid #ef4444`:c.modality===`should`?`1px solid #8b5cf6`:c.modality===`should_not`?`1px solid #f97316`:`1px solid var(--border)`,boxShadow:c.modality===`must`?`0 0 16px rgba(16, 185, 129, 0.1)`:c.modality===`must_not`?`0 0 16px rgba(239, 68, 68, 0.1)`:void 0,borderRadius:12,padding:24},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`flex-start`,marginBottom:16},children:[(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>n({}),style:{fontSize:12},children:`← Back to List`}),(0,z.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>{te(c.slug||``),N(c.title||``),re(c.category||`invariants`),ae(c.content||c.body||``),se(c.status||`active`),le(c.priority||`low`),de(c.modality||`should`),pe(c.confidence??1),he(c.importance??3),_e((c.tags||[]).join(`, `)),ye((c.related||[]).join(`, `)),xe((c.contradicts||[]).join(`, `)),F((c.supersedes||[]).join(`, `)),A(!0)},style:{fontSize:12,border:`1px solid var(--border)`},children:`✏️ Edit Node`}),(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>Ee(c.slug),style:{fontSize:12,borderColor:`rgba(239,68,68,0.2)`,color:`#fca5a5`},children:`🗑️ Delete`})]})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:12},children:[(0,z.jsx)(`h2`,{style:{margin:0,color:`#fff`},children:c.title}),c.modality&&(0,z.jsx)(`span`,{style:{fontSize:10,fontWeight:700,textTransform:`uppercase`,padding:`4px 10px`,borderRadius:6,background:c.modality===`must`?`rgba(16, 185, 129, 0.15)`:c.modality===`must_not`?`rgba(239, 68, 68, 0.15)`:`rgba(255, 255, 255, 0.05)`,color:c.modality===`must`?`#10b981`:c.modality===`must_not`?`#ef4444`:`var(--text-secondary)`,border:c.modality===`must`?`1px solid rgba(16, 185, 129, 0.3)`:c.modality===`must_not`?`1px solid rgba(239, 68, 68, 0.3)`:`1px solid rgba(255, 255, 255, 0.1)`},children:c.modality})]}),(0,z.jsxs)(`dl`,{className:`frontmatter`,style:{display:`grid`,gridTemplateColumns:`120px 1fr`,gap:`10px 20px`,marginBottom:24,paddingBottom:16,borderBottom:`1px solid rgba(255,255,255,0.06)`},children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Slug`}),(0,z.jsx)(`dd`,{style:{margin:0},children:(0,z.jsx)(`code`,{children:c.slug})}),(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Category`}),(0,z.jsx)(`dd`,{style:{margin:0,textTransform:`capitalize`},children:c.category}),c.status&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Status`}),(0,z.jsx)(`dd`,{style:{margin:0},children:(0,z.jsx)(`span`,{className:`badge badge-success`,style:{background:c.status===`active`?`rgba(34, 197, 94, 0.15)`:`rgba(255,255,255,0.05)`,color:c.status===`active`?`#22c55e`:`var(--text-secondary)`},children:c.status})})]}),c.confidence!==void 0&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Confidence`}),(0,z.jsxs)(`dd`,{style:{margin:0,display:`flex`,alignItems:`center`,gap:12},children:[(0,z.jsxs)(`strong`,{style:{fontSize:13},children:[Math.round(c.confidence*100),`%`]}),(0,z.jsx)(`div`,{style:{flex:1,maxWidth:150,height:6,background:`rgba(255,255,255,0.06)`,borderRadius:3,overflow:`hidden`,display:`inline-block`},children:(0,z.jsx)(`div`,{style:{width:`${Math.round(c.confidence*100)}%`,height:`100%`,background:`linear-gradient(90deg, #8b5cf6, #06b6d4)`,borderRadius:3}})})]})]}),c.importance!==void 0&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Importance`}),(0,z.jsx)(`dd`,{style:{margin:0,color:`#fbbf24`,display:`flex`,gap:2},children:Array.from({length:5}).map((e,t)=>(0,z.jsx)(`span`,{children:t<(c.importance||0)?`★`:`☆`},t))})]}),c.tags?.length?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Tags`}),(0,z.jsx)(`dd`,{style:{margin:0,display:`flex`,gap:6,flexWrap:`wrap`},children:c.tags.map(e=>(0,z.jsx)(`span`,{style:{background:`rgba(255,255,255,0.05)`,color:`var(--text-secondary)`,fontSize:10,padding:`2px 8px`,borderRadius:4,border:`1px solid rgba(255,255,255,0.03)`},children:e},e))})]}):null,c.related?.length?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Related`}),(0,z.jsx)(`dd`,{style:{margin:0},children:(0,z.jsx)(`code`,{children:c.related.join(`, `)})})]}):null,c.contradicts?.length?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Contradicts`}),(0,z.jsx)(`dd`,{style:{margin:0,color:`#fca5a5`},children:(0,z.jsx)(`code`,{children:c.contradicts.join(`, `)})})]}):null,c.supersedes?.length?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`dt`,{style:{color:`var(--text-tertiary)`,fontWeight:500},children:`Supersedes`}),(0,z.jsx)(`dd`,{style:{margin:0,color:`#93c5fd`},children:(0,z.jsx)(`code`,{children:c.supersedes.join(`, `)})})]}):null]}),(0,z.jsxs)(`div`,{style:{marginTop:20},children:[(0,z.jsx)(`h3`,{style:{fontSize:12,textTransform:`uppercase`,color:`var(--text-tertiary)`,letterSpacing:.5,marginBottom:12},children:`Memory Content (SSSS Body)`}),(0,z.jsx)(`div`,{style:{background:`rgba(0,0,0,0.15)`,border:`1px solid rgba(255,255,255,0.04)`,borderRadius:8,padding:20},children:IW(c.body||c.content||``)})]})]}):(0,z.jsxs)(`div`,{className:`memory-list`,style:{display:`grid`,gridTemplateColumns:`1fr`,gap:12},children:[o.length===0&&!m&&(0,z.jsx)(`div`,{style:{textAlign:`center`,padding:40,color:`var(--text-tertiary)`},children:f?`No matching nodes found.`:u===`all`?`No memory nodes loaded. Is the backend running?`:`No memory nodes found in category "${u}".`}),o.map(e=>{let t=e.modality===`must`?`2px solid #10b981`:e.modality===`must_not`?`2px solid #ef4444`:e.modality===`should`?`1px solid #8b5cf6`:e.modality===`should_not`?`1px solid #f97316`:`1px solid rgba(255, 255, 255, 0.08)`,n=e.modality===`must`?`0 0 12px rgba(16, 185, 129, 0.15)`:e.modality===`must_not`?`0 0 12px rgba(239, 68, 68, 0.15)`:void 0;return(0,z.jsxs)(`div`,{className:`memory-node-card`,onClick:()=>ke(e),style:{border:t,boxShadow:n,transition:`transform 0.2s ease, box-shadow 0.2s ease`,position:`relative`},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`flex-start`,marginBottom:6},children:[(0,z.jsx)(`h4`,{style:{margin:0,color:`#fff`,fontSize:15},children:e.title}),e.modality&&(0,z.jsx)(`span`,{style:{fontSize:9,fontWeight:700,textTransform:`uppercase`,padding:`2px 6px`,borderRadius:4,background:e.modality===`must`?`rgba(16, 185, 129, 0.15)`:e.modality===`must_not`?`rgba(239, 68, 68, 0.15)`:`rgba(255, 255, 255, 0.05)`,color:e.modality===`must`?`#10b981`:e.modality===`must_not`?`#ef4444`:`var(--text-secondary)`},children:e.modality})]}),(0,z.jsxs)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:16,fontSize:11,color:`var(--text-tertiary)`,marginTop:8},children:[(0,z.jsxs)(`span`,{children:[`📂 `,e.category]}),e.importance!==void 0&&(0,z.jsxs)(`span`,{style:{color:`#fbbf24`},children:[`★ `,e.importance,`/5`]}),e.confidence!==void 0&&(0,z.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:4},children:[`🧠 `,Math.round(e.confidence*100),`%`]})]})]},e.slug)})]})]})]}):(0,z.jsxs)(`div`,{style:{width:`100%`},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:16},children:[(0,z.jsx)(`h3`,{children:`Quarantined Contradiction Records`}),(0,z.jsxs)(`span`,{style:{fontSize:12,color:`var(--text-tertiary)`,display:`flex`,alignItems:`center`,gap:5},children:[(0,z.jsx)(`span`,{className:`pulse`,style:{background:`#06b6d4`}}),` SSE Real-time Agent Monitor Connected`]})]}),T.length===0?(0,z.jsxs)(`div`,{style:{textAlign:`center`,padding:60,background:`rgba(255,255,255,0.02)`,borderRadius:12,border:`1px dashed var(--border)`,color:`var(--text-tertiary)`},children:[(0,z.jsx)(`span`,{style:{fontSize:32,display:`block`,marginBottom:12},children:`🛡️`}),(0,z.jsx)(`h4`,{style:{color:`#fff`,marginBottom:6},children:`All Clear!`}),"No memory conflicts enqueued or quarantined in `.agent/memory-inbox/conflicts/`."]}):(0,z.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:T.map(e=>{let t=e.status===`pending`;return(0,z.jsxs)(`div`,{style:{background:`rgba(15,23,42,0.45)`,backdropFilter:`blur(12px)`,border:t?`1px solid rgba(239, 68, 68, 0.25)`:`1px solid rgba(34, 197, 94, 0.2)`,borderRadius:12,padding:24,boxShadow:`0 8px 32px rgba(0,0,0,0.15)`},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`flex-start`,marginBottom:16,borderBottom:`1px solid rgba(255,255,255,0.06)`,paddingBottom:12},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`h4`,{style:{margin:0,fontSize:16,color:`#fff`,display:`flex`,alignItems:`center`,gap:8},children:[`Conflict: `,(0,z.jsx)(`code`,{children:e.conflict_id}),(0,z.jsx)(`span`,{style:{fontSize:11,padding:`2px 8px`,borderRadius:10,background:t?`rgba(239,68,68,0.15)`:`rgba(34,197,94,0.15)`,color:t?`#ef4444`:`#22c55e`,textTransform:`uppercase`},children:e.status})]}),(0,z.jsxs)(`span`,{style:{fontSize:11,color:`var(--text-tertiary)`},children:[`Detected at: `,new Date(e.detected_at).toLocaleString()]})]}),(0,z.jsxs)(`div`,{style:{textAlign:`right`},children:[(0,z.jsxs)(`span`,{style:{fontSize:12,color:`#ef4444`,fontWeight:700,display:`block`},children:[`Clash Similarity: `,Math.round(e.similarity*100),`%`]}),(0,z.jsx)(`span`,{style:{fontSize:10,color:`var(--text-tertiary)`},children:`Modality polarity flip`})]})]}),(0,z.jsxs)(`p`,{style:{fontSize:13,background:`rgba(239,68,68,0.03)`,padding:`10px 14px`,borderRadius:6,borderLeft:`3px solid #ef4444`,color:`#fca5a5`,marginBottom:20},children:[(0,z.jsx)(`strong`,{children:`Reason:`}),` `,e.reason]}),(0,z.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:16,marginBottom:24},children:[(0,z.jsxs)(`div`,{style:{background:`rgba(255,255,255,0.02)`,padding:16,borderRadius:8,border:`1px solid rgba(255,255,255,0.05)`},children:[(0,z.jsx)(`h5`,{style:{margin:`0 0 10px 0`,color:`#a78bfa`,textTransform:`uppercase`,fontSize:11,letterSpacing:.5},children:`✓ Existing Node In Vault`}),(0,z.jsx)(`div`,{style:{fontSize:13,fontWeight:700,color:`#fff`,marginBottom:8},children:(0,z.jsx)(`code`,{children:e.existing_slug})}),(0,z.jsxs)(`dl`,{style:{display:`grid`,gridTemplateColumns:`80px 1fr`,gap:4,margin:`0 0 12px 0`,fontSize:11,color:`var(--text-secondary)`},children:[(0,z.jsx)(`dt`,{children:`Modality:`}),(0,z.jsx)(`dd`,{children:(0,z.jsx)(`code`,{children:e._existing_node?.modality||`must`})}),(0,z.jsx)(`dt`,{children:`Polarity:`}),(0,z.jsx)(`dd`,{children:(0,z.jsx)(`code`,{children:e._existing_node?.sentiment_polarity||`directive_must`})}),(0,z.jsx)(`dt`,{children:`Confidence:`}),(0,z.jsx)(`dd`,{children:e._existing_node?.confidence===void 0?`N/A`:`${Math.round(e._existing_node.confidence*100)}%`})]}),(0,z.jsx)(`div`,{style:{fontSize:12,fontStyle:`italic`,background:`rgba(0,0,0,0.2)`,padding:10,borderRadius:6,color:`var(--text-tertiary)`,minHeight:60,whiteSpace:`pre-wrap`},children:e._existing_node?.excerpt||e._existing_node?.body||`No preview content.`})]}),(0,z.jsxs)(`div`,{style:{background:`rgba(255,255,255,0.02)`,padding:16,borderRadius:8,border:`1px solid rgba(255,255,255,0.05)`},children:[(0,z.jsx)(`h5`,{style:{margin:`0 0 10px 0`,color:`#06b6d4`,textTransform:`uppercase`,fontSize:11,letterSpacing:.5},children:`⚠ New Ingestion Candidate`}),(0,z.jsx)(`div`,{style:{fontSize:13,fontWeight:700,color:`#fff`,marginBottom:8},children:(0,z.jsx)(`code`,{children:e.new_slug})}),(0,z.jsxs)(`dl`,{style:{display:`grid`,gridTemplateColumns:`80px 1fr`,gap:4,margin:`0 0 12px 0`,fontSize:11,color:`var(--text-secondary)`},children:[(0,z.jsx)(`dt`,{children:`Modality:`}),(0,z.jsx)(`dd`,{children:(0,z.jsx)(`code`,{children:e._new_node?.modality||`must_not`})}),(0,z.jsx)(`dt`,{children:`Polarity:`}),(0,z.jsx)(`dd`,{children:(0,z.jsx)(`code`,{children:e._new_node?.sentiment_polarity||`directive_must_not`})}),(0,z.jsx)(`dt`,{children:`Confidence:`}),(0,z.jsx)(`dd`,{children:e._new_node?.confidence===void 0?`N/A`:`${Math.round(e._new_node.confidence*100)}%`})]}),(0,z.jsx)(`div`,{style:{fontSize:12,fontStyle:`italic`,background:`rgba(0,0,0,0.2)`,padding:10,borderRadius:6,color:`var(--text-tertiary)`,minHeight:60,whiteSpace:`pre-wrap`},children:e._new_node?.excerpt||e._new_node?.body||`No preview content.`})]})]}),t?(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:12},children:[(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,disabled:D!==null,onClick:()=>Ae(e.conflict_id,`keep`,e.existing_slug),style:{borderColor:`rgba(255,255,255,0.1)`,fontSize:12},children:D===e.conflict_id?`Processing...`:`Keep Existing Node (${e.existing_slug})`}),(0,z.jsx)(`button`,{className:`btn btn-purple btn-sm`,disabled:D!==null,onClick:()=>Ae(e.conflict_id,`supersede`,e.new_slug),style:{fontSize:12},children:D===e.conflict_id?`Processing...`:`Supersede with New (${e.new_slug})`})]}):(0,z.jsxs)(`div`,{style:{fontSize:12,color:`#22c55e`,background:`rgba(34,197,94,0.06)`,padding:`10px 14px`,borderRadius:6,border:`1px solid rgba(34,197,94,0.15)`,display:`flex`,justifyContent:`space-between`,alignItems:`center`},children:[(0,z.jsxs)(`span`,{children:[`✓ Resolved successfully. Choice: `,(0,z.jsx)(`strong`,{children:e.resolution})]}),(0,z.jsxs)(`span`,{style:{fontSize:11,color:`var(--text-tertiary)`},children:[`Resolved at: `,e.resolved_at?new Date(e.resolved_at).toLocaleString():``]})]})]},e.conflict_id)})})]}),i===`sessions`&&(0,z.jsxs)(`div`,{className:`health-log`,style:{background:`rgba(15,23,42,0.45)`,backdropFilter:`blur(12px)`,border:`1px solid var(--border)`,borderRadius:12,padding:24},children:[(0,z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:16},children:[(0,z.jsxs)(`h2`,{style:{margin:0,color:`#fff`,fontSize:16},children:[`📝 IDE Sessions (`,x,`)`]}),(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:I,style:{fontSize:12},children:`🔄 Refresh`})]}),C?(0,z.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[1,2,3].map(e=>(0,z.jsx)(`div`,{className:`skeleton`,style:{height:56}},e))}):y.length===0?(0,z.jsxs)(`div`,{style:{textAlign:`center`,padding:40,color:`var(--text-tertiary)`},children:[(0,z.jsx)(`span`,{style:{fontSize:32,display:`block`,marginBottom:8},children:`📝`}),`No sessions ingested yet. Sessions appear here when the relay ships IDE conversation data.`]}):(0,z.jsxs)(`table`,{style:{width:`100%`,textAlign:`left`,borderCollapse:`collapse`},children:[(0,z.jsx)(`thead`,{children:(0,z.jsxs)(`tr`,{children:[(0,z.jsx)(`th`,{style:{padding:`10px 12px`,borderBottom:`1px solid var(--border)`,color:`var(--text-tertiary)`,fontSize:12,fontWeight:600},children:`Title`}),(0,z.jsx)(`th`,{style:{padding:`10px 12px`,borderBottom:`1px solid var(--border)`,color:`var(--text-tertiary)`,fontSize:12,fontWeight:600},children:`Date`}),(0,z.jsx)(`th`,{style:{padding:`10px 12px`,borderBottom:`1px solid var(--border)`,color:`var(--text-tertiary)`,fontSize:12,fontWeight:600},children:`Source`}),(0,z.jsx)(`th`,{style:{padding:`10px 12px`,borderBottom:`1px solid var(--border)`,color:`var(--text-tertiary)`,fontSize:12,fontWeight:600},children:`Messages`}),(0,z.jsx)(`th`,{style:{padding:`10px 12px`,borderBottom:`1px solid var(--border)`,color:`var(--text-tertiary)`,fontSize:12,fontWeight:600,width:60}})]})}),(0,z.jsx)(`tbody`,{children:y.map(e=>{let t={antigravity:`#8b5cf6`,"claude-code":`#f59e0b`,codex:`#10b981`,vscode:`#3b82f6`,cursor:`#06b6d4`,"gemini-cli":`#ec4899`}[e.source||``]||`var(--text-secondary)`;return(0,z.jsxs)(`tr`,{style:{borderBottom:`1px solid rgba(255,255,255,0.04)`},children:[(0,z.jsx)(`td`,{style:{padding:`10px 12px`,color:`#fff`,fontSize:13,maxWidth:400,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.title||e.id}),(0,z.jsx)(`td`,{style:{padding:`10px 12px`,color:`var(--text-secondary)`,fontSize:12,whiteSpace:`nowrap`},children:e.date?new Date(e.date).toLocaleString():`-`}),(0,z.jsx)(`td`,{style:{padding:`10px 12px`},children:e.source&&(0,z.jsx)(`span`,{style:{fontSize:10,fontWeight:600,textTransform:`uppercase`,padding:`2px 8px`,borderRadius:4,background:`${t}20`,color:t,border:`1px solid ${t}40`},children:e.source})}),(0,z.jsx)(`td`,{style:{padding:`10px 12px`,color:`var(--text-secondary)`,fontSize:12},children:e.count}),(0,z.jsx)(`td`,{style:{padding:`10px 12px`},children:(0,z.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>Oe(e.id),style:{fontSize:10,padding:`2px 6px`,color:`#fca5a5`,borderColor:`rgba(239,68,68,0.2)`},children:`🗑️`})})]},e.id)})})]})]})]})}var RW=Object.defineProperty,zW=Object.getOwnPropertySymbols,BW=Object.prototype.hasOwnProperty,VW=Object.prototype.propertyIsEnumerable,HW=(e,t,n)=>t in e?RW(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,UW=(e,t)=>{for(var n in t||={})BW.call(t,n)&&HW(e,n,t[n]);if(zW)for(var n of zW(t))VW.call(t,n)&&HW(e,n,t[n]);return e},WW=(e,t)=>{var n={};for(var r in e)BW.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&zW)for(var r of zW(e))t.indexOf(r)<0&&VW.call(e,r)&&(n[r]=e[r]);return n},GW;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e<this.size;e++)o.push(!1);for(let e=0;e<this.size;e++)this.modules.push(o.slice()),this.isFunction.push(o.slice());this.drawFunctionPatterns();let s=this.addEccAndInterleave(r);if(this.drawCodewords(s),a==-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(a=t,e=n),this.applyMask(t)}}i(0<=a&&a<=7),this.mask=a,this.applyMask(a),this.drawFormatBits(a),this.isFunction=[]}static encodeText(n,r){let i=e.QrSegment.makeSegments(n);return t.encodeSegments(i,r)}static encodeBinary(n,r){let i=e.QrSegment.makeBytes(n);return t.encodeSegments([i],r)}static encodeSegments(e,r,a=1,s=40,c=-1,l=!0){if(!(t.MIN_VERSION<=a&&a<=s&&s<=t.MAX_VERSION)||c<-1||c>7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.length<p;e^=253)n(e,8,f);let m=[];for(;m.length*8<f.length;)m.push(0);return f.forEach((e,t)=>m[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0),this.setFunctionModule(e,6,e%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n==0&&r==0||n==0&&r==t-1||n==t-1&&r==0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.errorCorrectionLevel.formatBits<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let a=(t<<10|n)^21522;i(!(a>>>15));for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(!(t>>>18));for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a<this.size&&0<=o&&o<this.size&&this.setFunctionModule(a,o,i!=2&&i!=4)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!=1)}setFunctionModule(e,t,n){this.modules[t][e]=n,this.isFunction[t][e]=!0}addEccAndInterleave(e){let n=this.version,r=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(n,r))throw RangeError(`Invalid argument`);let a=t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n],o=t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n],s=Math.floor(t.getNumRawDataModules(n)/8),c=a-s%a,l=Math.floor(s/a),u=[],d=t.reedSolomonComputeDivisor(o);for(let n=0,r=0;n<a;n++){let i=e.slice(r,r+l-o+(n<c?0:1));r+=i.length;let a=t.reedSolomonComputeRemainder(i,d);n<c&&i.push(0),u.push(i.concat(a))}let f=[];for(let e=0;e<u[0].length;e++)u.forEach((t,n)=>{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i<this.size;i++)for(let a=0;a<2;a++){let o=t-a,s=t+1&2?i:this.size-1-i;!this.isFunction[s][o]&&n<e.length*8&&(this.modules[s][o]=r(e[n>>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.isFunction[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[n][o]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[o][n]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size-1;n++)for(let r=0;r<this.size-1;r++){let i=this.modules[n][r];i==this.modules[n][r+1]&&i==this.modules[n+1][r]&&i==this.modules[n+1][r+1]&&(e+=t.PENALTY_N2)}let n=0;for(let e of this.modules)n=e.reduce((e,t)=>e+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t<e-1;t++)n.push(0);n.push(1);let r=1;for(let i=0;i<e;i++){for(let e=0;e<n.length;e++)n[e]=t.reedSolomonMultiply(n[e],r),e+1<n.length&&(n[e]^=n[e+1]);r=t.reedSolomonMultiply(r,2)}return n}static reedSolomonComputeRemainder(e,n){let r=n.map(e=>0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(!(n>>>8)),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return!!(e>>>t&1)}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e<t.length;){let i=Math.min(t.length-e,3);n(parseInt(t.substring(e,e+i),10),i*3+1,r),e+=i}return new e(e.Mode.NUMERIC,t.length,r)}static makeAlphanumeric(t){if(!e.isAlphanumeric(t))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let r=[],i;for(i=0;i+2<=t.length;i+=2){let a=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i))*45;a+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i+1)),n(a,11,r)}return i<t.length&&n(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i)),6,r),new e(e.Mode.ALPHANUMERIC,t.length,r)}static makeSegments(t){return t==``?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}static makeEci(t){let r=[];if(t<0)throw RangeError(`ECI assignment value out of range`);if(t<128)n(t,8,r);else if(t<16384)n(2,2,r),n(t,14,r);else if(t<1e6)n(6,3,r),n(t,21,r);else throw RangeError(`ECI assignment value out of range`);return new e(e.Mode.ECI,0,r)}static isNumeric(t){return e.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return e.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let n=0;for(let r of e){let e=r.mode.numCharCountBits(t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)==`%`?(t.push(parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}};a.NUMERIC_REGEX=/^[0-9]*$/,a.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,a.ALPHANUMERIC_CHARSET=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`;let o=a;e.QrSegment=a})(GW||={}),(e=>{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(GW||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(GW||={});var KW=GW,qW={L:KW.QrCode.Ecc.LOW,M:KW.QrCode.Ecc.MEDIUM,Q:KW.QrCode.Ecc.QUARTILE,H:KW.QrCode.Ecc.HIGH},JW=128,YW=`L`,XW=`#FFFFFF`,ZW=`#000000`,QW=!1,$W=1,eG=4,tG=0,nG=.1;function rG(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function iG(e,t){return e.slice().map((e,n)=>n<t.y||n>=t.y+t.h?e:e.map((e,n)=>n<t.x||n>=t.x+t.w?e:!1))}function aG(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*nG),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function oG(e,t){return t==null?e?eG:tG:Math.max(Math.floor(t),0)}function sG({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=v.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...KW.QrSegment.makeSegments(t)),e),[]);return KW.QrCode.encodeSegments(r,qW[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=v.useMemo(()=>{let e=c.getModules(),t=oG(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:aG(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var cG=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),lG=v.forwardRef(function(e,t){let n=e,{value:r,size:i=JW,level:a=YW,bgColor:o=XW,fgColor:s=ZW,includeMargin:c=QW,minVersion:l=$W,boostLevel:u,marginSize:d,imageSettings:f}=n,p=WW(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=WW(p,[`style`]),g=f?.src,_=v.useRef(null),y=v.useRef(null),b=v.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[x,S]=v.useState(!1),{margin:C,cells:w,numCells:T,calculatedImageSettings:E}=sG({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});v.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=w,r=y.current,a=E!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&E.excavation!=null&&(n=iG(w,E.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/T*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,T,T),t.fillStyle=s,cG?t.fill(new Path2D(rG(n,C))):w.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+C,n+C,1,1)})}),E&&(t.globalAlpha=E.opacity),a&&t.drawImage(r,E.x+C,E.y+C,E.w,E.h)}}),v.useEffect(()=>{S(!1)},[g]);let D=UW({height:i,width:i},m),O=null;return g!=null&&(O=v.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{S(!0)},ref:y,crossOrigin:E?.crossOrigin})),v.createElement(v.Fragment,null,v.createElement(`canvas`,UW({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});lG.displayName=`QRCodeCanvas`;var uG=v.forwardRef(function(e,t){let n=e,{value:r,size:i=JW,level:a=YW,bgColor:o=XW,fgColor:s=ZW,includeMargin:c=QW,minVersion:l=$W,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=WW(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:y}=sG({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),b=g,x=null;p!=null&&y!=null&&(y.excavation!=null&&(b=iG(g,y.excavation)),x=v.createElement(`image`,{href:p.src,height:y.h,width:y.w,x:y.x+h,y:y.y+h,preserveAspectRatio:`none`,opacity:y.opacity,crossOrigin:y.crossOrigin}));let S=rG(b,h);return v.createElement(`svg`,UW({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&v.createElement(`title`,null,d),v.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),v.createElement(`path`,{fill:s,d:S,shapeRendering:`crispEdges`}),x)});uG.displayName=`QRCodeSVG`;function dG(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(!0),[c,l]=(0,v.useState)(!1),u=async()=>{s(!0),a(null);try{let e=await R(`${Ln()}/api/pairing`);if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Pairing API error: ${e.status}`)}let n=await e.json();t(n);let i=n.preferred_url||n.endpoints?.find(e=>e.recommended)?.url||n.endpoints?.[0]?.url||``;r(i)}catch(e){console.error(e),a(e instanceof Error?e.message:`Failed to load pairing endpoints`);let n=`${window.location.protocol}//${window.location.host}`;r(n),t({port:Number(window.location.port||3e3),protocol:window.location.protocol.replace(`:`,``)||`http`,preferred_url:n,endpoints:[{kind:`browser`,label:`This browser URL (may not work on phone)`,ip:window.location.hostname,url:n,recommended:!0,reachable_hint:`Fallback when pairing API is unavailable.`}],warnings:[`Could not load live network endpoints from the brain.`],listen_hosts:[]})}finally{s(!1)}};(0,v.useEffect)(()=>{setTimeout(()=>{u()},0)},[]);let d=e?.endpoints?.find(e=>e.url===n)||null,f=d?.kind===`loopback`||n.includes(`127.0.0.1`)||n.includes(`localhost`);return(0,z.jsxs)(`div`,{className:`mobile-pairing`,"data-testid":`mobile-pairing`,style:{padding:`20px`,background:`var(--bg-secondary)`,borderRadius:`12px`,border:`1px solid var(--border)`},children:[(0,z.jsx)(`h3`,{style:{margin:`0 0 8px`},children:`Mobile Device Pairing`}),(0,z.jsxs)(`p`,{style:{color:`var(--text-tertiary)`,fontSize:`13px`,marginBottom:`16px`},children:[`Scan with your phone to open this Total Recall dashboard. Prefer `,(0,z.jsx)(`strong`,{children:`LAN`}),` on the same Wi‑Fi, or `,(0,z.jsx)(`strong`,{children:`Tailscale/mesh`}),` if the phone is on your tailnet.`]}),o&&(0,z.jsx)(`div`,{"data-testid":`pairing-loading`,style:{color:`var(--text-tertiary)`,fontSize:13},children:`Detecting reachable addresses…`}),i&&(0,z.jsxs)(`div`,{role:`alert`,"data-testid":`pairing-error`,style:{marginBottom:12,padding:10,borderRadius:8,border:`1px solid #ef4444`,color:`#ef4444`,fontSize:12},children:[i,` `,(0,z.jsx)(`button`,{type:`button`,onClick:()=>u(),style:{marginLeft:8,cursor:`pointer`},children:`Retry`})]}),!o&&(0,z.jsxs)(`div`,{style:{display:`flex`,gap:20,flexWrap:`wrap`,alignItems:`flex-start`},children:[(0,z.jsx)(`div`,{style:{background:`#fff`,padding:`16px`,borderRadius:`8px`,display:`inline-block`},"data-testid":`pairing-qr`,children:n?(0,z.jsx)(uG,{value:n,size:150,level:`M`,includeMargin:!0}):(0,z.jsx)(`div`,{style:{width:150,height:150}})}),(0,z.jsxs)(`div`,{style:{flex:1,minWidth:200},children:[e&&e.endpoints.length>0&&(0,z.jsxs)(`div`,{className:`field-col`,style:{marginBottom:12},children:[(0,z.jsx)(`label`,{className:`field-label`,htmlFor:`pairing-endpoint`,children:`Pairing address`}),(0,z.jsx)(`select`,{id:`pairing-endpoint`,className:`settings-select`,"data-testid":`pairing-endpoint-select`,value:n,onChange:e=>r(e.target.value),style:{width:`100%`,marginTop:4},children:e.endpoints.map(e=>(0,z.jsxs)(`option`,{value:e.url,children:[e.label,e.recommended?` ★`:``,` — `,e.url]},e.url))})]}),(0,z.jsx)(`p`,{"data-testid":`pairing-url`,style:{margin:`0 0 8px`,fontSize:12,fontFamily:`var(--font-mono)`,wordBreak:`break-all`,color:`var(--text-primary)`},children:n||`—`}),(0,z.jsxs)(`div`,{style:{display:`flex`,gap:8,flexWrap:`wrap`,marginBottom:12},children:[(0,z.jsx)(`button`,{type:`button`,className:`btn-secondary`,onClick:async()=>{if(n)try{await navigator.clipboard.writeText(n),l(!0),setTimeout(()=>l(!1),2e3)}catch{a(`Clipboard copy failed — select the URL text manually.`)}},"data-testid":`pairing-copy`,children:c?`Copied`:`Copy URL`}),(0,z.jsx)(`button`,{type:`button`,className:`btn-ghost btn-sm`,onClick:()=>u(),children:`Refresh`})]}),d&&(0,z.jsxs)(`div`,{style:{fontSize:12,color:`var(--text-secondary)`,margin:`0 0 10px`,lineHeight:1.5,background:`rgba(255,255,255,0.03)`,padding:`8px 12px`,borderRadius:6},children:[(0,z.jsx)(`strong`,{children:`Connection Route:`}),` `,d.reachable_hint]}),f&&(0,z.jsxs)(`div`,{"data-testid":`pairing-loopback-warning`,style:{fontSize:12,color:`#f59e0b`,margin:`0 0 8px`,background:`rgba(245, 158, 11, 0.1)`,padding:`8px 12px`,borderRadius:6,border:`1px solid rgba(245, 158, 11, 0.2)`},children:[`⚠️ `,(0,z.jsx)(`strong`,{children:`Loopback Only:`}),` `,(0,z.jsx)(`code`,{children:`127.0.0.1`}),` only works on this computer. To open on your phone, select your Mesh IP (`,(0,z.jsx)(`code`,{children:`100.64.x.x`}),`) or enable `,(0,z.jsx)(`strong`,{children:`Allow Public Bind`}),` below to use local Wi-Fi.`]})]})]}),e?.warnings&&e.warnings.length>0&&(0,z.jsxs)(`div`,{"data-testid":`pairing-warnings`,style:{margin:`16px 0 0`,padding:`10px 14px`,fontSize:12,color:`#fbbf24`,background:`rgba(251, 191, 36, 0.08)`,borderRadius:8,border:`1px solid rgba(251, 191, 36, 0.2)`},children:[(0,z.jsx)(`div`,{style:{fontWeight:600,marginBottom:4},children:`Network Notice:`}),(0,z.jsx)(`ul`,{style:{margin:0,paddingLeft:18},children:e.warnings.map(e=>(0,z.jsx)(`li`,{children:e},e))})]}),(0,z.jsxs)(`div`,{style:{marginTop:16,padding:`12px 14px`,background:`rgba(59, 130, 246, 0.06)`,borderRadius:8,border:`1px solid rgba(59, 130, 246, 0.15)`,fontSize:12,color:`var(--text-secondary)`,lineHeight:1.5},children:[(0,z.jsx)(`div`,{style:{color:`var(--text-primary)`,fontWeight:600,marginBottom:4},children:`📱 How to connect your phone:`}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:`Option A (WireGuard / Mesh — Recommended):`}),` The device has to be `,(0,z.jsx)(`em`,{children:`on the tailnet`}),`before a `,(0,z.jsx)(`code`,{children:`100.64.x.x`}),` address can reach anything — scanning this QR from a phone that has not joined will simply time out. Join it first in`,` `,(0,z.jsx)(`strong`,{children:`Add a device to the tailnet`}),`, directly below, which has the per-platform steps.`,(0,z.jsxs)(`div`,{style:{marginTop:4,opacity:.85},children:[`Short version: `,(0,z.jsx)(`strong`,{children:`Android / ChromeOS`}),` take an enrollment key directly. `,(0,z.jsx)(`strong`,{children:`iOS`}),` `,`cannot — it needs the alternate coordination server set in iOS Settings, `,(0,z.jsx)(`em`,{children:`Reset Keychain`}),` turned on, and then approval from that card. Once joined, come back and scan the `,(0,z.jsx)(`code`,{children:`100.64.x.x`}),` code.`]})]}),(0,z.jsxs)(`div`,{style:{marginTop:4},children:[(0,z.jsx)(`strong`,{children:`Option B (Local Home Wi-Fi):`}),` Check `,(0,z.jsx)(`strong`,{children:`Allow Public Bind`}),` in `,(0,z.jsx)(`em`,{children:`Network & Binding`}),` below, restart the server, and scan your local Wi-Fi LAN QR code (e.g. `,(0,z.jsx)(`code`,{children:`192.168.x.x`}),`).`]})]})]})}async function fG(){let e=await Vn(`/api/mesh/leader`);if(!e.leader)throw Error(`No online mesh leader is available`);return e.leader}async function pG(){return(await Vn(`/api/mesh/nodes`)).nodes}async function mG(){return Vn(`/api/mesh/access/proposals`)}async function hG(){return Hn(`/api/mesh/access/import`,{})}async function gG(e){return Hn(`/api/mesh/access`,e)}async function _G(){let e=await Hn(`/api/mesh/election/refresh`,{});if(!e.leader)throw Error(`No online mesh leader is available`);return e.leader}async function vG(){return(await Vn(`/api/mesh/election/history`)).events||[]}async function yG(e){return Hn(`/api/mesh/election/log`,e)}async function bG(){return Vn(`/api/mesh/latency`)}async function xG(){return Vn(`/api/mesh/interfaces`)}async function SG(e){let t=new URLSearchParams;e?.probe===!1&&t.set(`probe`,`0`),e?.limit&&t.set(`limit`,String(e.limit));let n=t.toString();return Vn(`/api/mesh/lan${n?`?${n}`:``}`)}async function CG(){return Vn(`/api/mesh/io`)}async function wG(e,t){let n=await R(`${L}/api/mesh/register-node`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({auth_id:e,...t?{user:t}:{}})}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r.message||`register failed: ${n.status}`);return r}async function TG(){return Vn(`/api/mesh/enrollment`)}async function EG(e){return Hn(`/api/mesh/enroll`,e||{})}async function DG(e){return Hn(`/api/mesh/lan/register`,{probe:e?.probe!==!1,limit:e?.limit??32})}async function OG(e){return Hn(`/api/mesh/preauthkey`,{reusable:e?.reusable===!0,ephemeral:e?.ephemeral===!0,ttlMinutes:e?.ttlMinutes})}function kG(){let[e,t]=(0,v.useState)([]),[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(null),[x,S]=(0,v.useState)(``),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(null);(0,v.useEffect)(()=>{pG().then(t).catch(e=>d(e?.message??`could not load nodes`)),TG().then(e=>b(e.login_server)).catch(()=>b(null))},[]),(0,v.useEffect)(()=>{if(!n)return;let e=()=>{let e=new Date(n.expiration).getTime()-Date.now();_(Math.max(0,Math.floor(e/1e3)))};e();let t=setInterval(e,1e3);return()=>clearInterval(t)},[n]);let D=async()=>{l(!0),d(null),p(!1);try{r(await OG({reusable:i,ephemeral:o}))}catch(e){d(e instanceof Error?e.message:`could not mint an enrollment key`)}finally{l(!1)}},O=async()=>{w(!0),d(null),E(null);try{let n=x.match(/hskey-authreq-[A-Za-z0-9._-]+/),r=await wG(n?n[0]:x.trim());E(r.message),S(``),t(await pG().catch(()=>e))}catch(e){d(e instanceof Error?e.message:`could not approve device`)}finally{w(!1)}},k=g!==null&&g<=0,A=y??n?.login_server??null,j=e.filter(e=>!e.self&&e.access_resolved?.complete!==!0);return(0,z.jsxs)(`section`,{"data-testid":`tailnet-enroll`,style:{marginTop:24},children:[(0,z.jsx)(`h3`,{style:{marginBottom:4},children:`Add a device to the tailnet`}),(0,z.jsx)(`p`,{style:{fontSize:12,opacity:.75,marginTop:0},children:`Point the device at this control server, then authenticate it with a short-lived key.`}),(0,z.jsxs)(`div`,{"data-testid":`enroll-instructions`,style:{margin:`12px 0`,padding:14,borderRadius:8,border:`1px solid var(--border)`,background:`var(--bg-secondary)`},children:[(0,z.jsxs)(`div`,{style:{fontSize:12,marginBottom:10},children:[(0,z.jsx)(`strong`,{children:`Control server`}),(0,z.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,marginTop:4},children:[(0,z.jsx)(`code`,{"data-testid":`enroll-login-server`,style:{wordBreak:`break-all`,flex:1},children:A??`not configured — set the Headscale URL in Secrets first`}),A&&(0,z.jsx)(`button`,{type:`button`,"data-testid":`enroll-copy-server`,onClick:()=>{navigator.clipboard?.writeText(A),h(!0)},children:m?`Copied`:`Copy`})]})]}),(0,z.jsxs)(`div`,{"data-testid":`enroll-approve`,style:{margin:`0 0 12px`,padding:12,borderRadius:8,border:`1px solid var(--border)`},children:[(0,z.jsx)(`strong`,{style:{fontSize:12},children:`Device waiting for approval?`}),(0,z.jsxs)(`p`,{style:{fontSize:12,opacity:.75,margin:`4px 0 8px`},children:[`If a device shows “run the command below in the headscale server”, paste that whole line (or just the `,(0,z.jsx)(`code`,{children:`hskey-authreq-…`}),` part) here.`]}),(0,z.jsxs)(`p`,{style:{fontSize:12,margin:`0 0 8px`,color:`#f59e0b`},children:[(0,z.jsx)(`strong`,{children:`If the code on the device never changes`}),` between sign-in attempts, it is a stale one replayed from the iOS keychain and no amount of retrying will register it. Follow`,` `,(0,z.jsx)(`strong`,{children:`How to clear the keychain (iOS)`}),` below — the code must come back different.`]}),(0,z.jsxs)(`div`,{style:{display:`flex`,gap:8,flexWrap:`wrap`},children:[(0,z.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`hskey-authreq-…`,"data-testid":`enroll-authid`,style:{flex:1,minWidth:220,fontFamily:`var(--font-mono)`,fontSize:12}}),(0,z.jsx)(`button`,{type:`button`,onClick:O,disabled:C||!x.trim(),"data-testid":`enroll-approve-btn`,children:C?`Approving…`:`Approve device`})]}),T&&(0,z.jsx)(`p`,{"data-testid":`enroll-approved`,style:{fontSize:12,color:`#10b981`,margin:`8px 0 0`},children:T})]}),(0,z.jsxs)(`details`,{open:!0,style:{fontSize:12},children:[(0,z.jsx)(`summary`,{style:{cursor:`pointer`,fontWeight:600},children:`On a phone (iOS)`}),(0,z.jsxs)(`ol`,{style:{paddingLeft:18,lineHeight:1.7,marginBottom:6},children:[(0,z.jsxs)(`li`,{children:[`Install `,(0,z.jsx)(`strong`,{children:`Tailscale`}),` from the App Store — `,(0,z.jsx)(`strong`,{children:`1.38.1 or newer`}),`, the first release that supports an alternate control server.`]}),(0,z.jsxs)(`li`,{children:[(0,z.jsx)(`strong`,{children:`Sign out of Tailscale first.`}),` The alternate-server setting is only read while the app is logged out.`]}),(0,z.jsxs)(`li`,{children:[`Open `,(0,z.jsx)(`strong`,{children:`iOS Settings`}),`, scroll past Game Center and TV Provider to`,` `,(0,z.jsx)(`strong`,{children:`Tailscale`}),`, and put the control server above into`,` `,(0,z.jsx)(`strong`,{children:`Alternate Coordination Server URL`}),`.`]}),(0,z.jsxs)(`li`,{children:[(0,z.jsx)(`strong`,{children:`Turn on “Reset Keychain”`}),` — same panel, just below the URL. Treat this as required, not optional: the app keeps its node key in the iOS keychain and will otherwise replay an old registration id forever. Force-quitting does not clear it, and the server rejects the stale id every time while the phone keeps showing a page that looks perfectly valid. Full steps under `,(0,z.jsx)(`em`,{children:`How to clear the keychain`}),` below.`]}),(0,z.jsx)(`li`,{children:`Force-quit Tailscale from the app switcher, then reopen it — the setting is read at launch.`}),(0,z.jsxs)(`li`,{children:[`Tap the plain `,(0,z.jsx)(`strong`,{children:`Sign in`}),` option (not SSO). It should open this control server's page.`]}),(0,z.jsxs)(`li`,{children:[`The page will say `,(0,z.jsx)(`em`,{children:`“run the command below in the headscale server”`}),`. That is expected — copy the line it shows and paste it into `,(0,z.jsx)(`strong`,{children:`Device waiting for approval?`}),` above.`,(0,z.jsx)(`strong`,{children:` Do not use the enrollment key below on an iPhone or iPad:`}),` the Tailscale iOS app does not accept pre-auth keys against a custom control server, so interactive sign-in plus approval here is the only route that works. Android and ChromeOS `,(0,z.jsx)(`em`,{children:`do`}),` accept the key — see below.`]})]}),(0,z.jsxs)(`p`,{style:{opacity:.75,margin:0},children:[`The in-app route — account icon → `,(0,z.jsx)(`strong`,{children:`Log in…`}),` → options menu →`,` `,(0,z.jsx)(`strong`,{children:`Use custom coordination server`}),` — reaches the same place when it works, but that menu has been reported unresponsive on some builds. The Settings route above is the reliable one.`]})]}),(0,z.jsxs)(`details`,{open:!0,style:{fontSize:12,marginTop:8},children:[(0,z.jsx)(`summary`,{style:{cursor:`pointer`,fontWeight:600},"data-testid":`enroll-keychain-steps`,children:`How to clear the keychain (iOS)`}),(0,z.jsxs)(`ol`,{style:{paddingLeft:18,lineHeight:1.7,margin:`4px 0 0`},children:[(0,z.jsxs)(`li`,{children:[`Open the iOS `,(0,z.jsx)(`strong`,{children:`Settings`}),` app — not Tailscale's own settings.`]}),(0,z.jsxs)(`li`,{children:[`Scroll to the bottom, `,(0,z.jsx)(`strong`,{children:`past Game Center and TV Provider`}),`, into the alphabetical list of installed apps. Tap `,(0,z.jsx)(`strong`,{children:`Tailscale`}),`.`]}),(0,z.jsxs)(`li`,{children:[`Turn `,(0,z.jsx)(`strong`,{children:`Reset Keychain`}),` on.`]}),(0,z.jsxs)(`li`,{children:[`While you are there, check `,(0,z.jsx)(`strong`,{children:`Alternate Coordination Server URL`}),` still reads`,` `,(0,z.jsx)(`code`,{children:A??`your control server`}),` — clearing the keychain can blank it, and an empty box sends the app back to Tailscale's public service.`]}),(0,z.jsxs)(`li`,{children:[`Leave Settings. Open the app switcher and `,(0,z.jsx)(`strong`,{children:`swipe Tailscale away`}),`. Backgrounding is not enough; the setting is read at launch.`]}),(0,z.jsxs)(`li`,{children:[`Reopen Tailscale and tap the plain `,(0,z.jsx)(`strong`,{children:`Sign in`}),` (not SSO).`]}),(0,z.jsxs)(`li`,{children:[(0,z.jsx)(`strong`,{children:`Check the code changed.`}),` If it is the same string as last time, the keychain did not clear — repeat from step 1.`]})]})]}),(0,z.jsxs)(`details`,{style:{fontSize:12,marginTop:8},children:[(0,z.jsx)(`summary`,{style:{cursor:`pointer`,fontWeight:600},"data-testid":`enroll-android`,children:`On Android`}),(0,z.jsxs)(`p`,{style:{margin:`4px 0 6px`,opacity:.85},children:[`Android is `,(0,z.jsx)(`strong`,{children:`not`}),` like iOS here — it accepts an enrollment key directly, so you can use the key below and skip interactive approval entirely.`]}),(0,z.jsxs)(`ol`,{style:{paddingLeft:18,lineHeight:1.7,margin:`0 0 6px`},children:[(0,z.jsx)(`li`,{children:`Install Tailscale from Google Play or F-Droid.`}),(0,z.jsxs)(`li`,{children:[`Open the app → `,(0,z.jsx)(`strong`,{children:`settings menu (upper-right)`}),` → `,(0,z.jsx)(`strong`,{children:`Accounts`}),`.`]}),(0,z.jsxs)(`li`,{children:[`Choose `,(0,z.jsx)(`strong`,{children:`Use an alternate server`}),` and enter`,` `,(0,z.jsx)(`code`,{children:A??`your control server`}),`.`]}),(0,z.jsxs)(`li`,{children:[`Back to `,(0,z.jsx)(`strong`,{children:`Accounts`}),`, choose `,(0,z.jsx)(`strong`,{children:`Use an auth key`}),`, and paste the enrollment key below. Then tap `,(0,z.jsx)(`strong`,{children:`login`}),` on the main screen.`]})]}),(0,z.jsx)(`p`,{style:{margin:0,opacity:.75},children:`Prefer the browser flow? Stop after step 3 and follow the prompts — if it shows a “run this command” page, approve it above exactly like iOS.`})]}),(0,z.jsxs)(`details`,{style:{fontSize:12,marginTop:8},children:[(0,z.jsx)(`summary`,{style:{cursor:`pointer`,fontWeight:600},"data-testid":`enroll-chromeos`,children:`On a Chromebook (ChromeOS)`}),(0,z.jsxs)(`p`,{style:{margin:`4px 0 6px`,opacity:.85},children:[`Install the `,(0,z.jsx)(`strong`,{children:`Android app from Google Play`}),` and follow the Android steps above — that is the supported route, and the enrollment key works.`]}),(0,z.jsx)(`p`,{style:{margin:0,opacity:.75},children:`Avoid installing inside the Crostini Linux container: it is known to crash the container on subsequent startups. Running the Android app also keeps the credentials out of the VM, and one install covers every VM on the machine. If managed policy blocks Play Store apps, there is currently no alternative install path.`})]})]}),u&&(0,z.jsx)(`div`,{role:`alert`,"data-testid":`tailnet-enroll-error`,style:{margin:`10px 0`,padding:10,borderRadius:8,border:`1px solid #ef4444`,color:`#ef4444`,fontSize:12},children:u}),(0,z.jsxs)(`div`,{style:{display:`flex`,gap:16,alignItems:`center`,flexWrap:`wrap`,margin:`12px 0`},children:[(0,z.jsxs)(`label`,{style:{fontSize:12,display:`flex`,gap:6,alignItems:`center`},children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),"data-testid":`enroll-reusable`}),`Reusable (enroll more than one device)`]}),(0,z.jsxs)(`label`,{style:{fontSize:12,display:`flex`,gap:6,alignItems:`center`},children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),"data-testid":`enroll-ephemeral`}),`Ephemeral (drops off the list when offline)`]}),(0,z.jsx)(`button`,{type:`button`,onClick:D,disabled:c,"data-testid":`enroll-mint`,style:{cursor:c?`wait`:`pointer`},children:c?`Minting…`:n?`Mint another key`:`Get enrollment key (computers, Android, ChromeOS)`})]}),n&&(0,z.jsxs)(`div`,{style:{display:`flex`,gap:20,flexWrap:`wrap`,alignItems:`flex-start`},children:[(0,z.jsx)(`div`,{style:{background:`#fff`,padding:16,borderRadius:8},"data-testid":`enroll-qr`,children:k?(0,z.jsx)(`div`,{style:{width:150,height:150,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#ef4444`,fontSize:12,textAlign:`center`},children:`Key expired — mint another`}):(0,z.jsx)(uG,{value:n.key,size:150,level:`M`,includeMargin:!0})}),(0,z.jsxs)(`div`,{style:{flex:1,minWidth:260},children:[(0,z.jsxs)(`div`,{style:{fontSize:12,marginBottom:6},children:[(0,z.jsx)(`strong`,{children:`Enrollment key`}),` `,(0,z.jsx)(`span`,{"data-testid":`enroll-ttl`,style:{opacity:.7},children:k?`(expired)`:`(expires in ${g}s, ${n.reusable?`reusable`:`single-use`})`}),(0,z.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,marginTop:4},children:[(0,z.jsx)(`code`,{style:{wordBreak:`break-all`,flex:1,opacity:k?.4:1},children:n.key}),(0,z.jsx)(`button`,{type:`button`,disabled:k,onClick:()=>{navigator.clipboard?.writeText(n.key),p(!0)},"data-testid":`enroll-copy`,children:f?`Copied`:`Copy`})]})]}),(0,z.jsxs)(`details`,{style:{fontSize:12,marginTop:6},children:[(0,z.jsx)(`summary`,{style:{cursor:`pointer`},children:`On a computer`}),(0,z.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,wordBreak:`break-all`},children:`tailscale up --login-server ${A??`<control-server>`} --authkey ${k?`<expired — mint another>`:n.key}`}),(0,z.jsxs)(`p`,{style:{opacity:.75},children:[`Always pass `,(0,z.jsx)(`code`,{children:`--login-server`}),` alongside any `,(0,z.jsx)(`code`,{children:`--reset`}),`, or the client silently repoints at the public Tailscale control plane.`]})]})]})]}),(0,z.jsxs)(`div`,{style:{marginTop:20},children:[(0,z.jsxs)(`h4`,{style:{marginBottom:6},children:[`Nodes (`,e.length,`)`]}),(0,z.jsx)(`ul`,{"data-testid":`enroll-node-list`,style:{listStyle:`none`,padding:0,fontSize:12,margin:0},children:e.map(e=>(0,z.jsxs)(`li`,{style:{padding:`4px 0`,display:`flex`,gap:8},children:[(0,z.jsx)(`span`,{title:e.online?`online`:`offline`,children:e.online?`🟢`:`⚪️`}),(0,z.jsx)(`strong`,{children:e.hostname}),(0,z.jsx)(`code`,{style:{opacity:.75},children:e.ip??`—`}),e.self&&(0,z.jsx)(`span`,{style:{opacity:.6},children:`(this host)`})]},`${e.hostname}-${e.ip??`noip`}`))}),j.length>0&&(0,z.jsxs)(`p`,{"data-testid":`enroll-access-warning`,style:{fontSize:12,color:`#f59e0b`,marginBottom:0},children:[j.length,` node(s) have no recorded login account — connecting to one fails as though it were unreachable. Run `,(0,z.jsx)(`code`,{children:`total-recall mesh access import`}),`.`]})]})]})}function AG(e){let t={...e};return t.security||={},t.security.dashboard||(t.security.dashboard={}),t.security.api||(t.security.api={}),t.security.network||(t.security.network={}),t.security.bind||(t.security.bind={}),t.security.rate_limits||(t.security.rate_limits={}),t.security.sandbox||(t.security.sandbox={}),t.security.privacy||(t.security.privacy={}),t.budget||={budget:{}},t.budget.budget||(t.budget.budget={}),t.brain||={},t.secrets||={},t}function jG({activeBrainId:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!0),[s,c]=(0,v.useState)(`idle`),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(null),[w,T]=(0,v.useState)(!1),[E,D]=(0,v.useState)(!1),O=async()=>{D(!0),C(null);try{let e=await ni();if(C(e.message),e.scheduled){setTimeout(function e(t=0){Yr().then(e=>{f(e),C(`Server restarted — reconnected.`),D(!1)}).catch(()=>{if(t>=20){C(`Server restarted but has not answered yet — reload in a moment.`),D(!1);return}setTimeout(()=>e(t+1),1500)})},2e3);return}}catch(e){C(`Restart error: `+e.message)}D(!1)},k=async()=>{T(!0),C(null);try{let e=await ti();C(e.message||`Daemon restarted successfully.`);let t=await Yr().catch(()=>null);t&&f(t)}catch(e){C(`Restart error: `+e.message)}finally{T(!1)}},[A,j]=(0,v.useState)(!1),ee=async()=>{o(!0),i(null);try{let e=await yi();n(AG(e))}catch(e){console.error(e),i(e instanceof Error?e.message:`Failed to load settings`),n(null)}finally{o(!1)}};(0,v.useEffect)(()=>{Yr().then(f).catch(console.error),oi().then(e=>y({updateAvailable:!!e.updateAvailable,latestVersion:e.latestVersion,currentVersion:e.currentVersion})).catch(console.error),setTimeout(()=>{ee()},0)},[e]);let M=[{id:`antigravity`,name:`Antigravity (Gemini SDK)`,desc:`Primary core developer agent`},{id:`gemini`,name:`Gemini CLI`,desc:`Direct Gemini assistant binary`},{id:`claude`,name:`Claude Code`,desc:`Anthropic developer CLI wrapper`},{id:`codex`,name:`Codex CLI`,desc:`OpenAI agent binary integration`},{id:`grok`,name:`Grok CLI`,desc:`xAI developer binary integration`}],te=Array.isArray(d?.cli_agents)?d.cli_agents:Array.isArray(d?.agents)?d.agents:[],ne=async e=>{e.preventDefault(),m(!0),g(null);try{let e=await ei();g(e.output),Yr().then(f).catch(console.error)}catch(e){g(`Error: `+e.message)}finally{m(!1)}},N=async()=>{x(!0),C(null);try{let e=await si();if(e.success){let t=e.summary,n=[t?.updated==null?null:`${t.updated} updated`,t?.up_to_date==null?null:`${t.up_to_date} current`,t?.latest?`latest ${t.latest}`:null].filter(Boolean),r=e.restart?.scheduled?` Server is restarting into the new code.`:e.restart?.required?` Server still runs the old code — ${e.restart.reason}`:``;C(n.length?`Update complete — ${n.join(` · `)}.${r}`:(e.message||`Update complete.`)+r)}else{let t=(e.summary?.results||[]).filter(e=>e.status===`failed`).map(e=>`${e.name}: ${e.error||`failed`}`).slice(0,3).join(`; `);C(`Update failed: ${e.message}${t?` (${t})`:``}`)}let t=await oi().catch(()=>null);t&&y({updateAvailable:!!t.updateAvailable,latestVersion:t.latestVersion,currentVersion:t.currentVersion})}catch(e){C(`Update error: `+e.message)}finally{x(!1)}},P=async()=>{if(t){c(`saving`);try{let e={...t};if(e.secrets){let t={};for(let[n,r]of Object.entries(e.secrets))typeof r==`string`&&r&&!r.includes(`•`)&&r!==`[redacted]`&&(t[n]=r);e.secrets=t}await bi(e),c(`saved`),setTimeout(()=>c(`idle`),2500)}catch(e){console.error(e),c(`error`),setTimeout(()=>c(`idle`),3e3)}}},re=async()=>{j(!0),u(`[Running] Rebuilding instruction surfaces…`);try{let e=await $r();u(`[Finished] Rebuilding instruction surfaces\n\n${e.message||(e.success?`Compile complete.`:`Compile finished with warnings.`)}`)}catch(e){u(`[Failed] Rebuild\n\n${e instanceof Error?e.message:String(e)}`)}finally{j(!1)}},ie=async()=>{try{let e=await R(`${Ln()}/api/extension/download`);if(!e.ok)throw Error(`Download failed: ${e.status}`);let t=await e.blob(),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`total-recall-extension.zip`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch(e){u(`[Failed] Extension download\n\n${e instanceof Error?e.message:String(e)}`)}},ae=(e,t,r)=>{n(n=>n&&{...n,security:{...n.security,[e]:{...n.security[e]||{},[t]:r}}})},oe=(e,t)=>{n(n=>n&&{...n,budget:{...n.budget,budget:{...n.budget.budget||{},[e]:t}}})},se=(e,t)=>{n(n=>n?{...n,brain:{...n.brain,[e]:t}}:null)},ce=e=>Array.isArray(e)?e.filter(Boolean).join(`, `):``,le=e=>e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0);return a&&!t?(0,z.jsx)(`div`,{style:{padding:40,color:`var(--text-secondary)`},"data-testid":`settings-loading`,children:(0,z.jsx)(`div`,{className:`glass-card`,style:{display:`inline-block`,padding:`12px 24px`},children:`Loading Settings...`})}):r&&!t?(0,z.jsx)(`div`,{style:{padding:40},"data-testid":`settings-error`,role:`alert`,children:(0,z.jsxs)(`div`,{className:`glass-card`,style:{display:`inline-block`,padding:`16px 24px`,border:`1px solid #ef4444`,color:`#ef4444`},children:[`Failed to load settings: `,r,(0,z.jsx)(`button`,{type:`button`,className:`btn-primary`,style:{marginLeft:16},onClick:()=>ee(),children:`Retry`})]})}):t?(0,z.jsxs)(`div`,{className:`settings-page-wrapper`,"data-testid":`settings-page`,children:[(0,z.jsx)(`style`,{children:`
|
|
5248
5248
|
.settings-page-wrapper {
|
|
5249
5249
|
padding: 32px 40px 100px;
|
|
5250
5250
|
max-width: 1200px;
|
package/frontend/dist/index.html
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
18
18
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet" />
|
|
19
19
|
<title>Total Recall — Portable Memory</title>
|
|
20
|
-
<script type="module" crossorigin src="/assets/index-
|
|
20
|
+
<script type="module" crossorigin src="/assets/index-DSxCyPAx.js"></script>
|
|
21
21
|
<link rel="stylesheet" crossorigin href="/assets/index-C7_Xpk27.css">
|
|
22
22
|
</head>
|
|
23
23
|
<body>
|
|
@@ -51,4 +51,14 @@ describe('MobilePairing', () => {
|
|
|
51
51
|
expect(screen.getByTestId('pairing-qr')).toBeTruthy();
|
|
52
52
|
expect(screen.getByTestId('pairing-warnings')).toBeTruthy();
|
|
53
53
|
});
|
|
54
|
+
it('sends you to enrol the device instead of hand-waving "log into your tailnet"', async () => {
|
|
55
|
+
// The old copy said "Log into your tailnet/headscale server" -- five words
|
|
56
|
+
// covering an iOS flow that needs the alternate coordination server, a
|
|
57
|
+
// keychain reset and server-side approval. Scanning a 100.64.x.x QR from a
|
|
58
|
+
// phone that has not joined just times out.
|
|
59
|
+
render(<MobilePairing />);
|
|
60
|
+
expect(await screen.findByText(/Add a device to the tailnet/i)).toBeTruthy();
|
|
61
|
+
expect(screen.getByText(/Reset Keychain/i)).toBeTruthy();
|
|
62
|
+
});
|
|
63
|
+
|
|
54
64
|
});
|
|
@@ -243,7 +243,17 @@ export function MobilePairing() {
|
|
|
243
243
|
|
|
244
244
|
<div style={{ marginTop: 16, padding: '12px 14px', background: 'rgba(59, 130, 246, 0.06)', borderRadius: 8, border: '1px solid rgba(59, 130, 246, 0.15)', fontSize: 12, color: 'var(--text-secondary)', lineHeight: 1.5 }}>
|
|
245
245
|
<div style={{ color: 'var(--text-primary)', fontWeight: 600, marginBottom: 4 }}>📱 How to connect your phone:</div>
|
|
246
|
-
<div
|
|
246
|
+
<div>
|
|
247
|
+
<strong>Option A (WireGuard / Mesh — Recommended):</strong> The device has to be <em>on the tailnet</em>
|
|
248
|
+
before a <code>100.64.x.x</code> address can reach anything — scanning this QR from a phone that has not
|
|
249
|
+
joined will simply time out. Join it first in{' '}
|
|
250
|
+
<strong>Add a device to the tailnet</strong>, directly below, which has the per-platform steps.
|
|
251
|
+
<div style={{ marginTop: 4, opacity: 0.85 }}>
|
|
252
|
+
Short version: <strong>Android / ChromeOS</strong> take an enrollment key directly. <strong>iOS</strong>
|
|
253
|
+
{' '}cannot — it needs the alternate coordination server set in iOS Settings, <em>Reset Keychain</em> turned
|
|
254
|
+
on, and then approval from that card. Once joined, come back and scan the <code>100.64.x.x</code> code.
|
|
255
|
+
</div>
|
|
256
|
+
</div>
|
|
247
257
|
<div style={{ marginTop: 4 }}><strong>Option B (Local Home Wi-Fi):</strong> Check <strong>Allow Public Bind</strong> in <em>Network & Binding</em> below, restart the server, and scan your local Wi-Fi LAN QR code (e.g. <code>192.168.x.x</code>).</div>
|
|
248
258
|
</div>
|
|
249
259
|
</div>
|