pmx-canvas 0.9.3 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/extensions/pmx-canvas/runtime.json +1 -1
- package/.github/extensions/pmx-canvas/tools.json +9278 -2014
- package/CHANGELOG.md +22 -1
- package/dist/canvas/index.js +1 -1
- package/dist/canvas/mcp-app.html +1 -1
- package/dist/types/mcp/canvas-access.d.ts +1 -12
- package/dist/types/mcp/resource-subscriptions.d.ts +7 -0
- package/dist/types/mcp/server.d.ts +2 -0
- package/dist/types/server/ax-wait.d.ts +1 -0
- package/dist/types/server/canvas-operations.d.ts +1 -0
- package/dist/types/server/index.d.ts +3 -3
- package/dist/types/server/operations/http.d.ts +10 -0
- package/dist/types/server/operations/index.d.ts +2 -2
- package/dist/types/server/operations/invoker.d.ts +4 -3
- package/dist/types/server/operations/mcp-contracts.d.ts +20 -0
- package/dist/types/server/operations/mcp.d.ts +2 -0
- package/dist/types/server/operations/ops/batch.d.ts +1 -0
- package/dist/types/server/operations/registry.d.ts +2 -2
- package/dist/types/server/operations/types.d.ts +12 -2
- package/dist/types/server/server.d.ts +2 -0
- package/dist/types/server/webpage-node.d.ts +1 -0
- package/docs/api-reference.md +2 -2
- package/docs/cli.md +1 -1
- package/docs/http-api.md +31 -0
- package/docs/mcp.md +93 -21
- package/docs/plans/plan-019-post-0.9-roadmap.md +123 -6
- package/docs/sdk.md +5 -2
- package/package.json +1 -1
- package/plugins/pmx-canvas/com.github.copilot/extensions/pmx-canvas/runtime.json +1 -1
- package/plugins/pmx-canvas/plugin.json +1 -1
- package/plugins/pmx-canvas/runtime.json +1 -1
- package/plugins/pmx-canvas/tools.json +9278 -2014
- package/skills/pmx-canvas/SKILL.md +9 -4
- package/skills/pmx-canvas/references/full-reference.md +35 -2
- package/skills/pmx-canvas/references/installing-pmx-canvas.md +7 -7
- package/src/client/canvas/ToolRail.tsx +2 -0
- package/src/mcp/canvas-access.ts +6 -47
- package/src/mcp/resource-subscriptions.ts +181 -0
- package/src/mcp/server.ts +185 -219
- package/src/server/ax-wait.ts +21 -6
- package/src/server/canvas-operations.ts +6 -2
- package/src/server/index.ts +12 -4
- package/src/server/operations/http.ts +69 -21
- package/src/server/operations/index.ts +8 -1
- package/src/server/operations/invoker.ts +53 -5
- package/src/server/operations/mcp-contracts.ts +339 -0
- package/src/server/operations/mcp.ts +153 -18
- package/src/server/operations/ops/ax-await.ts +18 -10
- package/src/server/operations/ops/ax-read.ts +2 -0
- package/src/server/operations/ops/ax-timeline.ts +2 -2
- package/src/server/operations/ops/batch.ts +27 -8
- package/src/server/operations/ops/nodes.ts +18 -3
- package/src/server/operations/registry.ts +24 -4
- package/src/server/operations/types.ts +16 -2
- package/src/server/server.ts +10 -0
- package/src/server/webpage-node.ts +9 -4
package/dist/canvas/mcp-app.html
CHANGED
|
@@ -10173,5 +10173,5 @@ Input: ${JSON.stringify(ee.recipe.input??null)}
|
|
|
10173
10173
|
Prompt: ${ee.recipe.prompt}
|
|
10174
10174
|
Regeneration is not validation. Preserve source observations and report evidence separately.`);b(!1),C(R?"Recipe request sent. No tool was executed by Canvas.":"Could not send the request. No tool was executed.")},children:"Ask agent to refresh this board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("section",{children:[r("h3",{children:"Review history"},void 0,!1,void 0,this),i.records.length===0&&r("p",{children:"No reviews recorded."},void 0,!1,void 0,this),[...i.records].reverse().map((R)=>r("div",{class:"lifecycle-history",children:[r("strong",{children:[R.outcome,!R.applied?" · not applied":""]},void 0,!0,void 0,this),r("span",{children:[he(R.when)," · ",R.who.actor," · ",R.who.source]},void 0,!0,void 0,this),r("p",{children:R.evidence||"No evidence"},void 0,!1,void 0,this)]},R.id,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function AT(){let[e,t]=E(null),n=oe((a,l)=>{a.preventDefault(),a.stopPropagation(),t({kind:"node",x:a.clientX,y:a.clientY,nodeId:l})},[]),o=oe((a,l,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"canvas",x:a.clientX,y:a.clientY,canvasX:l,canvasY:c})},[]),i=oe((a,l)=>{a.preventDefault(),a.stopPropagation(),t({kind:"edge",x:a.clientX,y:a.clientY,edgeId:l})},[]),s=oe(()=>t(null),[]);return $e(()=>{if(!e)return;let a=()=>t(null),l=(c)=>{if(c.key==="Escape")t(null)};return document.addEventListener("click",a),document.addEventListener("keydown",l),()=>{document.removeEventListener("click",a),document.removeEventListener("keydown",l)}},[e]),{menu:e,openNodeMenu:n,openCanvasMenu:o,openEdgeMenu:i,closeMenu:s}}var FL="#4bbcFF",jL=[{label:"Blue",value:"#3b82f6"},{label:"Green",value:"#22c55e"},{label:"Yellow",value:"#eab308"},{label:"Red",value:"#ef4444"},{label:"Gray",value:"#6b7280"},{label:"Purple",value:"#a855f7"}];function RT({menu:e,onClose:t}){let n;if(e.kind==="node"){let l=Z.value.get(e.nodeId);if(!l)return null;n=KL(l)}else if(e.kind==="edge"){let l=e.edgeId,c=tt.value.get(l),u=St;n=[{label:"Relation kind…",render:()=>r("label",{class:"relation-kind-control",children:["Kind"," ",r("select",{"aria-label":"Relation kind",value:c?Kn(c):"",onChange:(d)=>{let p=d.currentTarget.value;if(p==="__custom__")t(),On("Relation kind","An open kind, such as supports").then((m)=>{if(m?.trim()&&u===St)qi(l,{kind:m.trim()})});else qi(l,{kind:p})},children:[[...new Set([...(Qn()?.relationVocabulary??ac).map((d)=>d.kind),...c?[Kn(c)]:[]])].map((d)=>r("option",{value:d,children:d},d,!1,void 0,this)),r("option",{value:"__custom__",children:"Custom kind…"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},{label:c?.reason?"Edit why…":"Add why…",action:()=>{On("Why this relation exists","One sentence explaining the link",{initial:c?.reason??"",allowEmpty:!0,confirm:"Save"}).then((d)=>{if(d!==null&&u===St)qi(l,{reason:d})})}},{label:c?.label?`Edit label “${c.label.slice(0,18)}${c.label.length>18?"…":""}”`:"Add label…",action:()=>{On("Edge label (empty clears it)","label text",{initial:c?.label??"",allowEmpty:!0,confirm:"Save"}).then((d)=>{if(d===null||u!==St)return;qi(l,{label:d})})}},{separator:!0},...["flow","depends-on","relation","references"].map((d)=>({label:`${c?.type===d?"✓":" "} ${d}`,action:()=>void qi(l,{type:d})})),{separator:!0},...["solid","dashed","dotted"].map((d)=>({label:`${(c?.style??"solid")===d?"✓":" "} ${d}`,action:()=>void qi(l,{style:d})})),{separator:!0},{label:"Delete edge",danger:!0,action:()=>void Xu(l)}]}else n=GL(e.canvasX,e.canvasY);let o=new Map,i=n.some((l)=>l.render)?n.length*32+168:n.length*32+8,s=Math.min(e.x,Math.max(12,window.innerWidth-240)),a=Math.min(e.y,Math.max(12,window.innerHeight-i));return r("div",{class:"context-menu",style:{position:"fixed",left:`${s}px`,top:`${a}px`,zIndex:1e4},onPointerDown:(l)=>l.stopPropagation(),onClick:(l)=>l.stopPropagation(),children:n.map((l)=>{let c=l.separator?"separator":l.render?"custom":`${l.label??"item"}:${l.shortcut??""}`,u=(o.get(c)??0)+1;o.set(c,u);let d=`${c}:${u}`;if(l.separator)return r("div",{class:"context-menu-separator"},d,!1,void 0,this);if(l.render)return r("div",{class:"context-menu-custom",children:l.render(t)},d,!1,void 0,this);return r("button",{type:"button",class:`context-menu-item${l.danger?" is-danger":""}`,onClick:()=>{l.action?.(),t()},children:[r("span",{class:"context-menu-label",children:l.label},void 0,!1,void 0,this),l.shortcut&&r("span",{class:"context-menu-shortcut",children:l.shortcut},void 0,!1,void 0,this)]},d,!0,void 0,this)})},void 0,!1,void 0,this)}function UL(e){return(typeof e.data.path==="string"?e.data.path.trim():"")||null}function fp(e){let t=e.trim().toLowerCase(),n=t.match(/^#([0-9a-f]{3})$/);if(n){let[o,i,s]=n[1].split("");return`#${o}${o}${i}${i}${s}${s}`}return t}function PT(e){if(typeof e.data.color!=="string"||!e.data.color.trim())return null;return fp(e.data.color)}function ZL(e){let t=PT(e);return t&&/^#[0-9a-f]{6}$/.test(t)?t:fp(FL)}function zg(e,t){let n=t?fp(t):null;dn(e.id,{data:{...e.data,color:n}}),cn(e.id,{data:{color:n}})}function WL(e,t){let n=PT(e);return r("div",{class:"context-menu-section",children:[r("div",{class:"context-menu-section-header",children:[r("span",{class:"context-menu-section-label",children:"Group color"},void 0,!1,void 0,this),r("button",{type:"button",class:"context-menu-reset",onClick:()=>{zg(e,null),t()},children:"Theme default"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"context-menu-color-grid",children:jL.map((o)=>{let i=fp(o.value);return r("button",{type:"button",class:`context-menu-color-swatch${n===i?" active":""}`,"aria-label":`Set group color to ${o.label}`,style:{"--swatch-color":o.value},onClick:()=>{zg(e,o.value),t()},children:[r("span",{class:"context-menu-color-dot",style:{"--swatch-color":o.value}},void 0,!1,void 0,this),r("span",{children:o.label},void 0,!1,void 0,this)]},o.value,!0,void 0,this)})},void 0,!1,void 0,this),r("label",{class:"context-menu-color-custom",children:[r("span",{children:"Custom"},void 0,!1,void 0,this),r("input",{type:"color",class:"context-menu-color-input","aria-label":"Custom group color",value:ZL(e),onClick:(o)=>o.stopPropagation(),onInput:(o)=>{zg(e,o.currentTarget.value),t()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Lg(e,t,n,o){return{x:e-n/2,y:t-o/2}}function qL(e,t){return e.trim().replace(/[?#].*$/,"").split("/").filter(Boolean).at(-1)||t}async function $g(e){let t=await On(e.promptLabel,e.placeholder??"");if(!t)return;let n=t.trim();if(!n)return;let o=Lg(e.canvasX,e.canvasY,e.width,e.height);if(!(await zo({type:e.type,...e.type!=="webpage"?{title:qL(n,e.titleFallback)}:{},content:n,x:o.x,y:o.y,width:e.width,height:e.height})).ok)console.error(`[canvas-menu] ${e.errorMessage}`)}function GL(e,t){return[{label:"New note",action:()=>{let i=Lg(e,t,520,360);zo({type:"markdown",title:"New note",x:i.x,y:i.y,width:520,height:360})}},{label:"Open webpage...",action:()=>{$g({promptLabel:"Webpage URL:",type:"webpage",canvasX:e,canvasY:t,width:520,height:420,placeholder:"https://example.com",titleFallback:"Webpage",errorMessage:"Could not create webpage node. Enter a valid http(s) URL."})}},{label:"Open file...",action:()=>{$g({promptLabel:"Workspace path or absolute file path:",type:"file",canvasX:e,canvasY:t,width:720,height:500,placeholder:"src/server/server.ts",titleFallback:"File",errorMessage:"Could not create file node. Check the path and try again."})}},{label:"Open image...",action:()=>{$g({promptLabel:"Image path, URL, or data URI:",type:"image",canvasX:e,canvasY:t,width:480,height:360,placeholder:"artifacts/architecture.png",titleFallback:"Image",errorMessage:"Could not create image node. Check the image source and try again."})}},{label:"Link to board…",action:()=>window.dispatchEvent(new CustomEvent("pmx-open-board-link"))},{separator:!0},{label:"New group",action:()=>{let i=Lg(e,t,600,400);qs({title:"Group",x:i.x,y:i.y,width:600,height:400})}}]}function KL(e){let t=[],n=UL(e);if(Be.value)t.push({label:"Review",action:()=>js(e.id)});if(t.push({label:"Focus",action:()=>$t(e.id)}),t.push({label:"Rename…",action:()=>{On("Rename node","Node title",{initial:typeof e.data.title==="string"?e.data.title:"",confirm:"Save"}).then((c)=>{if(!c?.trim())return;cn(e.id,{title:c.trim()})})}}),gl.has(e.type))t.push({label:"Expand",shortcut:"⤢",action:()=>So(e.id)});if(t.push({label:e.collapsed?"Expand":"Collapse",action:()=>Gi(e.id)}),Nd(e))t.push({label:"Open in new tab",action:()=>void Md(e)});let o=ht.value.has(e.id);t.push({label:o?"Unpin from context":"Pin as context",action:()=>uo(e.id)}),t.push({label:e.pinned?"Unlock position":"Lock position (no auto-arrange)",action:()=>{let c=!e.pinned;dn(e.id,{pinned:c}),cn(e.id,{pinned:c}),pn()}});let i=Ml.value;if(i&&i.from!==e.id){let c=Z.value.get(i.from),u=c?(c.data.title||c.id).slice(0,20):i.from;t.push({label:`Connect from "${u}"`,action:()=>{kr(i.from,e.id,"relation"),Ml.value=null}})}t.push({label:i?"Connect from here (replace)":"Connect from here",action:()=>{Ml.value={from:e.id}}}),t.push({label:"Connect to a card on another board…",action:()=>window.dispatchEvent(new CustomEvent("pmx-open-board-link",{detail:{sourceNodeId:e.id}}))});let s=Array.from(tt.value.values()).filter((c)=>c.from===e.id||!c.toBoardId&&c.to===e.id).length;if(s>0)t.push({label:`${s} edge${s!==1?"s":""} connected`});if(t.push({separator:!0}),(e.type==="markdown"||e.type==="file"||e.type==="image")&&n)t.push({label:"Open in browser",action:()=>{window.open(`/artifact?path=${encodeURIComponent(n)}`,"_blank","noopener")}}),t.push({label:"Copy path",action:()=>{navigator.clipboard.writeText(n)}});if(e.type==="mcp-app"||e.type==="json-render"||e.type==="graph")if(e.data.chartConfig){let c=e.data.chartConfig.title||"chart";t.push({label:"Copy chart data",action:()=>{navigator.clipboard.writeText(JSON.stringify(e.data.chartConfig,null,2))}})}else{let c=e.data.url;if(t.push({label:"Open in browser",action:()=>{if(c)window.open(c,"_blank")}}),t.push({label:"Focus in TUI",action:()=>Fk("mcp-app-focus",{url:c})}),e.type==="json-render"||e.type==="graph")t.push({label:"Copy spec",action:()=>{navigator.clipboard.writeText(JSON.stringify(e.data.spec??e.data.graphConfig??{},null,2))}})}if(e.type==="webpage"){let c=typeof e.data.url==="string"?e.data.url:"";t.push({label:"Refresh webpage",action:()=>{qu(e.id)}}),t.push({label:"Open in browser",action:()=>{if(c)window.open(c,"_blank","noopener")}}),t.push({label:"Copy URL",action:()=>{if(c)navigator.clipboard.writeText(c)}})}if(e.type==="group"){let c=e.data.children??[];if(t.push({separator:!0}),t.push({render:(u)=>WL(e,u)}),c.length>0)t.push({label:`Ungroup (${c.length} node${c.length!==1?"s":""})`,action:()=>{li(e.id),Gs(e.id)}})}let a=typeof e.data.parentGroup==="string"?e.data.parentGroup:null,l=a?Z.value.get(a):void 0;if(l&&l.type==="group"){let c=typeof l.data.title==="string"&&l.data.title?l.data.title:"frame",u=Array.isArray(l.data.children)?l.data.children.filter((d)=>d!==e.id):[];t.push({label:`Remove from “${c}”`,action:()=>{Vu(l.id,u)}})}return t.push({separator:!0}),t.push({label:e.type==="group"?"Delete frame (children stay)":"Delete",danger:!0,action:()=>{ri(e.id)}}),t}function NT({onClose:e}){let t=F(null),[n,o]=E("Bug report"),[i,s]=E(""),[a,l]=E("");return bn(t,!0),r("div",{class:"text-prompt-backdrop feedback-backdrop",onPointerDown:e,children:r("form",{ref:t,class:"text-prompt feedback-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"feedback-title","aria-describedby":"feedback-privacy",action:"https://github.com/pskoett/pmx-canvas/issues/new",method:"get",target:"_blank",rel:"noopener noreferrer",onPointerDown:(c)=>c.stopPropagation(),onKeyDown:(c)=>{if(c.stopPropagation(),c.key==="Escape")c.preventDefault(),e()},children:[r("div",{id:"feedback-title",class:"text-prompt-title",children:"Bug and feedback"},void 0,!1,void 0,this),r("p",{id:"feedback-privacy",class:"feedback-note",children:"Opens a draft issue in pskoett/pmx-canvas. Review and submit it on GitHub using your account. Issues are public. Only what you enter below is included; no board contents, workspace paths, screenshots, or logs are attached."},void 0,!1,void 0,this),r("div",{class:"feedback-field",children:[r("span",{children:"Feedback type"},void 0,!1,void 0,this),r(Or,{label:"Feedback type",value:n,onChange:o,options:["Bug report","Feature request","General feedback"].map((c)=>({value:c,label:c}))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("label",{children:["Title",r("input",{class:"text-prompt-input",name:"title",required:!0,maxLength:120,value:i,onInput:(c)=>s(c.currentTarget.value),placeholder:"A short summary"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("label",{children:["Description",r("textarea",{class:"text-prompt-input",required:!0,maxLength:1200,rows:6,value:a,onInput:(c)=>l(c.currentTarget.value),placeholder:"What happened, what you expected, and steps to reproduce — or describe your idea."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("input",{type:"hidden",name:"body",value:`## ${n}
|
|
10175
10175
|
|
|
10176
|
-
${a.trim()}`},void 0,!1,void 0,this),r("div",{class:"text-prompt-actions",children:[r("button",{type:"button",class:"text-prompt-cancel",onClick:e,children:"Cancel"},void 0,!1,void 0,this),r("button",{type:"submit",class:"text-prompt-confirm",disabled:!i.trim()||!a.trim(),children:["Continue on GitHub ",r(pi,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function mc(e,t){console.error(`[tool-rail] ${e} failed`,t)}function ps(e){let t={image:{message:"Image URL (https://… or data:image/…)",placeholder:"https://example.com/diagram.png"},file:{message:"Workspace file path",placeholder:"src/server/server.ts"},webpage:{message:"Page URL",placeholder:"https://example.com"}};On(t[e].message,t[e].placeholder).then((n)=>{if(!n)return;Ao({type:e,content:n}).catch((o)=>mc(`create ${e}`,o))})}function no({label:e,shortcut:t,detail:n,ariaLabel:o,active:i,menuOpen:s,onClick:a,btnRef:l,children:c}){let[u,d]=E(null),p=(h)=>{let g=h.currentTarget.getBoundingClientRect();d({left:g.right+10,top:g.top+g.height/2})},m=()=>d(null),f=o??(t?`${e} (${t})`:n?`${e} (${n})`:e);return r(be,{children:[r("button",{ref:l,type:"button",class:`rail-btn${i?" active":""}`,"aria-label":f,"aria-pressed":i===void 0?void 0:i,onClick:(h)=>{m(),a(h)},onPointerEnter:p,onPointerLeave:m,onFocus:p,onBlur:m,children:c},void 0,!1,void 0,this),u&&!s&&r("span",{class:"toolbar-tooltip rail-tooltip",role:"tooltip","data-testid":"rail-tooltip",style:{left:`${u.left}px`,top:`${u.top}px`},children:[r("span",{class:"toolbar-tooltip-label",children:e},void 0,!1,void 0,this),(t||n)&&r("span",{class:"toolbar-tooltip-meta",children:[t&&r("kbd",{class:"toolbar-tooltip-shortcut",children:t},void 0,!1,void 0,this),n&&r("span",{children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function sr({label:e,description:t,hint:n,beta:o,toggle:i=o,checked:s,disabled:a,onClick:l}){let c=Uw(),[u,d]=E(null),p=(f)=>d(f.currentTarget.getBoundingClientRect()),m=()=>d(null);return r(be,{children:[r("button",{type:"button",role:s===void 0?"menuitem":"menuitemcheckbox","aria-label":o?`${e} (Beta)`:e,"aria-checked":s,"aria-describedby":u?c:void 0,class:"toolbar-menu-item","aria-disabled":a||void 0,onPointerEnter:p,onPointerLeave:m,onFocus:p,onBlur:m,onClick:()=>{if(a)return;m(),l()},children:[r("span",{class:"settings-item-label",children:[e," ",o&&r("span",{class:"beta-tag",children:"Beta"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i?r("span",{class:`settings-switch${s?" is-on":""}`,"aria-hidden":"true"},void 0,!1,void 0,this):n?r("span",{class:"toolbar-menu-hint",children:n},void 0,!1,void 0,this):null]},void 0,!0,void 0,this),u&&r(ia,{children:r("span",{id:c,class:"toolbar-tooltip settings-tooltip",role:"tooltip",ref:(f)=>{if(!f)return;let h=window.innerWidth-u.right>=f.offsetWidth+20;f.style.left=`${h?u.right+10:Math.max(12,Math.min(u.left,window.innerWidth-f.offsetWidth-12))}px`,f.style.top=`${Math.max(12,Math.min(h?u.top:u.top-f.offsetHeight-8,window.innerHeight-f.offsetHeight-12))}px`},children:[r("span",{class:"toolbar-tooltip-label",children:[e,o?" (Beta)":""]},void 0,!0,void 0,this),r("span",{class:"toolbar-tooltip-body",children:t},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function MT({minimapVisible:e,onToggleMinimap:t,snapshotOpen:n,onToggleSnapshot:o,snapshotBtnRef:i,onOpenPalette:s,onOpenShortcuts:a,annotationTool:l,onSetAnnotationTool:c}){let u=qn.value,d=Ys.value,p=Array.from(Z.value.values()).filter((V)=>V.type==="trace").length,m=tt.value.size,[f,h]=E(!1),[g,v]=E(!1),[b,x]=E(!1),C=async(V)=>{if(g||!Qr.value)return;v(!0),x(!1);try{let ee=await pe("saveWorkspaceSettings","/api/canvas/settings",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({[V]:!Qr.value[V]})});x(ee.ok!==!0)}finally{v(!1)}},[y,k]=E(null),[_,A]=E(null),w=F(null),M=F(null),B=(V)=>{if(y){k(null);return}let ee=V.currentTarget.getBoundingClientRect();A({bottom:ee.bottom,right:ee.right}),k("settings")},L=(V)=>()=>{k(null),i.current?.focus(),V()},Y=_?{position:"fixed",left:`${_.right+8}px`,bottom:`${Math.max(10,window.innerHeight-_.bottom)}px`,top:"auto",right:"auto"}:void 0;$e(()=>{if(!y)return;let V=(he)=>{if(w.current&&he.target instanceof Node&&!w.current.contains(he.target))k(null)},ee=(he)=>{if(he.key==="Escape")he.preventDefault(),he.stopPropagation(),k(null),i.current?.focus({preventScroll:!0})};return document.addEventListener("pointerdown",V),document.addEventListener("keydown",ee,!0),()=>{document.removeEventListener("pointerdown",V),document.removeEventListener("keydown",ee,!0)}},[y]);let j=(V)=>{mp(),document.documentElement.setAttribute("data-theme",V),va(),Qt.value=V,Zu(V),k(null)},J=qh(Qt.value),X=(V,ee={})=>{Gt(`/api/workbench/intent?_ts=${Date.now()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:V,payload:ee})}).catch((he)=>mc("sendIntent",he))};return r(be,{children:[r("div",{class:"tool-rail",ref:w,role:"toolbar","aria-label":"Canvas tools","aria-orientation":"vertical",children:[r(no,{label:"Home",ariaLabel:"PMX Canvas — Home",onClick:()=>{k(null),Mn(null).catch((V)=>mc("openHome",V))},children:r("span",{class:"rail-brand",children:r(cd,{size:22},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),!pt.value&&r(be,{children:[r("div",{class:"rail-divider"},void 0,!1,void 0,this),r(no,{label:"Select",shortcut:"V",active:u==="select",onClick:()=>qn.value="select",children:r(GS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Pan",shortcut:"Space",active:u==="pan",onClick:()=>qn.value="pan",children:r(KS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Connect",shortcut:"C",active:u==="connect",onClick:()=>qn.value="connect",children:r("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[r("circle",{cx:"4",cy:"4",r:"2"},void 0,!1,void 0,this),r("circle",{cx:"12",cy:"12",r:"2"},void 0,!1,void 0,this),r("path",{d:"M5.5 5.5 C 8 8, 8 8, 10.5 10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),r("div",{class:"rail-divider"},void 0,!1,void 0,this),r(no,{label:"Markdown note",shortcut:"M",onClick:()=>void Ao({type:"markdown",title:"New note",width:520,height:360}).catch((V)=>mc("create markdown",V)),children:r(ui,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Attach files",ariaLabel:"Attach files",detail:"Images (PNG, JPEG, SVG…), Markdown and text/code files. PDF, Word, Excel, PowerPoint and OpenDocument use agent import with review.",onClick:()=>M.current?.click(),children:r(BS,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("input",{ref:M,type:"file",hidden:!0,multiple:!0,"aria-label":"Attach files",onChange:(V)=>{let ee=Jt(),he=Ae.value;xa(Array.from(V.currentTarget.files??[]),(ee.width/2-he.x)/he.scale,(ee.height/2-he.y)/he.scale),V.currentTarget.value=""}},void 0,!1,void 0,this),r(no,{label:"Webpage",shortcut:"W",onClick:()=>ps("webpage"),children:r(na,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Group",shortcut:"G",onClick:()=>void Ao({type:"group",title:"Group"}).catch((V)=>mc("create group",V)),children:r(nh,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Draw",shortcut:"A",active:l==="pen",onClick:()=>c(l==="pen"?null:"pen"),children:r(ZS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Text note",active:l==="text",onClick:()=>c(l==="text"?null:"text"),children:r(qS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Eraser",active:l==="eraser",onClick:()=>c(l==="eraser"?null:"eraser"),children:r(WS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("div",{class:"rail-divider"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!pt.value&&r(no,{label:"Search & commands",shortcut:Ht("K"),onClick:s,children:r(ld,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),!pt.value&&r(no,{label:"Arrange",detail:m>0?"graph-aware":"grid",onClick:()=>m>0?od():nd(),children:r(Pr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("div",{class:"rail-spacer"},void 0,!1,void 0,this),r("span",{class:"toolbar-menu-anchor",children:[r(no,{label:"Settings",detail:"Appearance, board tools, beta features, and feedback",ariaLabel:"Settings",menuOpen:y!==null,active:y!==null||n,onClick:B,btnRef:i,children:r("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:r("path",{d:"M4 7h9M17 7h3M4 17h3M11 17h9M13 7a2 2 0 1 0 4 0a2 2 0 1 0-4 0M7 17a2 2 0 1 0 4 0a2 2 0 1 0-4 0"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),y==="settings"&&r("div",{class:"toolbar-menu rail-settings-menu",style:Y,role:"menu","aria-label":"Settings",children:[r(sr,{label:"Theme",description:"Choose the canvas appearance. Your choice is saved with the board.",hint:`${fa[J].label} ›`,onClick:()=>k("theme")},void 0,!1,void 0,this),!pt.value&&r(be,{children:[r(sr,{label:"Snapshots",description:"Save a board checkpoint, compare changes, or restore an earlier version.",onClick:L(o)},void 0,!1,void 0,this),r(sr,{label:"Minimap",description:"Show a small overview of the board. Drag its viewport to move around the canvas.",checked:e,hint:e?"On":"Off",onClick:L(t)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(sr,{label:"Keyboard shortcuts",description:"See shortcuts for creating cards, selecting, navigating, and editing the canvas.",hint:"?",onClick:L(a)},void 0,!1,void 0,this),r("div",{class:"toolbar-menu-divider",role:"separator"},void 0,!1,void 0,this),r("span",{class:"settings-caption",children:"Beta features · workspace-wide · off by default"},void 0,!1,void 0,this),r(sr,{label:"Agent sessions",beta:!0,checked:kt.value,disabled:!Qr.value||g,description:"Show session chips, tasks, timeline, steering composer, and receipts. Turning off hides these without ending attached agents. Approvals and edit protections remain available. Saved for this workspace.",onClick:()=>void C("agentSessions")},void 0,!1,void 0,this),r(sr,{label:"Knowledge lifecycle",beta:!0,checked:Be.value,disabled:!Qr.value||g,description:"This turns on context lifecycle, where boards and cards decay over time as their relevance fades. Includes Review, review policies, categories, and due or retired indicators. Turning off hides lifecycle tools without deleting their data or drafts. Saved for this workspace.",onClick:()=>void C("knowledgeLifecycle")},void 0,!1,void 0,this),b&&r("p",{class:"settings-error",role:"alert",children:"Could not save settings. Try again."},void 0,!1,void 0,this),!kt.value&&(Sa.value.length>0||To.value.length>0||ls.value.length>0||Io.value)&&r(sr,{label:"Agent controls",description:"Review pending approvals, inspect or clear the write scope, or end an existing attachment without enabling the session beta.",onClick:L(()=>to.value=!0)},void 0,!1,void 0,this),r("div",{class:"toolbar-menu-divider",role:"separator"},void 0,!1,void 0,this),!nt()&&!pt.value&&r(be,{children:[r(sr,{label:"Trace",description:"Show execution traces sent by connected tools. Turning off keeps existing traces. This does not start an agent.",toggle:!0,checked:d,onClick:()=>X("trace-toggle",{enabled:!d})},void 0,!1,void 0,this),(d||p>0)&&r(sr,{label:"Clear trace",description:"Remove recorded execution traces from this board without changing whether trace capture is enabled.",onClick:L(()=>X("trace-clear"))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(sr,{label:"Send feedback",description:"Report a problem or suggestion. Review the feedback before sending.",onClick:L(()=>h(!0))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y==="theme"&&r("div",{class:"toolbar-menu",style:Y,role:"menu","aria-label":"Theme",children:[r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>k("settings"),children:r("span",{children:"‹ Settings"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Wh.map((V)=>r("button",{type:"button",role:"menuitemradio","aria-checked":J===V,class:`toolbar-menu-item${J===V?" active":""}`,onClick:()=>j(V),children:[r("span",{class:"theme-swatch",style:{background:fa[V].swatchBg},children:r("span",{class:"theme-swatch-dot",style:{background:fa[V].swatchAccent}},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{children:fa[V].label},void 0,!1,void 0,this),J===V&&r("span",{class:"toolbar-menu-check","aria-hidden":"true",children:"✓"},void 0,!1,void 0,this)]},V,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),f&&r(NT,{onClose:()=>h(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function zT({onOpenPalette:e}){let t=F(null),n=()=>{Ao({type:"markdown",title:"New note",width:520,height:360}).catch(()=>{})},o=async(i)=>{if(!i||i.length===0)return;let s=Yr(),a=Ae.value;await xa(Array.from(i),(s.x-a.x)/a.scale,(s.y-a.y)/a.scale)};return r("div",{class:"empty-state","data-testid":"empty-state",children:[r("svg",{class:"empty-state-mark",width:"52",height:"52",viewBox:"0 0 64 64",fill:"none","aria-hidden":"true",children:[r("rect",{x:"8",y:"8",width:"48",height:"48",rx:"7"},void 0,!1,void 0,this),r("rect",{x:"20",y:"20",width:"24",height:"24",rx:"4","stroke-dasharray":"4 4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"empty-state-title",children:"What would you like to work on?"},void 0,!1,void 0,this),r("div",{class:"empty-state-grid",children:[r("button",{type:"button",class:"empty-state-action",onClick:()=>t.current?.click(),children:[r("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round",class:"tone-warn","aria-hidden":"true",children:[r("path",{d:"M8 10 V2 M8 2 L5 5 M8 2 L11 5"},void 0,!1,void 0,this),r("path",{d:"M2 10 V13 H14 V10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"empty-state-action-label",children:["Drop files here",r("span",{class:"empty-state-action-description",children:"Bring in the material you want to work with."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"empty-state-action-hint",children:"or pick"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",class:"empty-state-action",onClick:()=>ps("webpage"),children:[r(na,{size:16,class:"tone-ok"},void 0,!1,void 0,this),r("span",{class:"empty-state-action-label",children:["Paste a link",r("span",{class:"empty-state-action-description",children:"Add a source, reference, or inspiration."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("kbd",{children:Ht("V")},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",class:"empty-state-action",onClick:n,children:[r(ui,{size:16,class:"tone-accent"},void 0,!1,void 0,this),r("span",{class:"empty-state-action-label",children:["Start a note",r("span",{class:"empty-state-action-description",children:"Write down an idea, then ask your agent to help you develop it."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("kbd",{children:"M"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"empty-state-agent",children:[r("div",{class:"empty-state-agent-title",children:"Or start with your agent"},void 0,!1,void 0,this),r("div",{class:"empty-state-sub",children:"Give your agent a task and ask it to work on this board."},void 0,!1,void 0,this),kt.value&&r("button",{type:"button",class:"empty-state-action is-agent",onClick:()=>void _i(),children:[r(ra,{size:16,class:"tone-purple"},void 0,!1,void 0,this),r("span",{class:"empty-state-action-label",children:"Start agent session"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",class:"empty-state-hint",onClick:e,children:["? shortcuts · ",Ht("K")," palette"]},void 0,!0,void 0,this),r("input",{ref:t,type:"file",multiple:!0,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:(i)=>{let s=i.currentTarget;o(s.files).finally(()=>{s.value=""})}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ar(e){let t=e.target instanceof HTMLElement?e.target:null;return e.key==="Escape"&&!e.defaultPrevented&&!t?.closest('input, textarea, [contenteditable="true"]')&&!document.querySelector('[role="dialog"], [role="menu"], .context-menu, .shortcut-overlay-backdrop')}var $T="From old snapshots";function hp(e){if(!e?.trim())return null;let t=e.split("/").map((n)=>n.trim());if(t.length>8)throw Error("Folders can be nested up to 8 levels.");if(t.some((n)=>!n||n==="."||n===".."||n.length>60))throw Error('Each folder name must be 1–60 characters, and cannot be "." or "..".');return t.join("/")}function fc(e){return e.split("/").map((t,n,o)=>o.slice(0,n+1).join("/"))}function LT({board:e,folders:t,onClose:n}){let o=F(null),[i,s]=E(e.folder??""),[a,l]=E(""),[c,u]=E(!1),[d,p]=E("");bn(o,!0),G(()=>{let h=(g)=>{if(g.key!=="Escape")return;if(g.preventDefault(),g.stopPropagation(),!c)n()};return window.addEventListener("keydown",h,!0),()=>window.removeEventListener("keydown",h,!0)},[c,n]);let m=a.trim()?[i,a.trim()].filter(Boolean).join("/"):i,f=async()=>{let h;try{if(a.includes("/"))throw Error("Use one folder name; choose its parent above.");h=hp(m)}catch(g){p(g instanceof Error?g.message:String(g));return}if(u(!0),p(""),await Sr(e.id,{folder:h}),Ge.value.find((g)=>g.id===e.id)?.folder===h)n();else p("Could not move this board. Try again.");u(!1)};return r("div",{class:"text-prompt-backdrop",onPointerDown:()=>!c&&n(),children:r("div",{ref:o,class:"text-prompt home-folder-dialog",role:"dialog","aria-modal":"true","aria-label":`Move ${e.name}`,onPointerDown:(h)=>h.stopPropagation(),children:[r("div",{class:"text-prompt-title",children:["Move “",e.name,"”"]},void 0,!0,void 0,this),r("p",{class:"home-folder-hint",children:"Choose a folder, or create one inside it. The board keeps its content and links."},void 0,!1,void 0,this),r("fieldset",{class:"home-folder-options",disabled:c,children:[r("legend",{children:"Destination folder"},void 0,!1,void 0,this),["",...t].map((h)=>r("label",{class:"home-folder-option",style:{paddingLeft:`${8+Math.min(h.split("/").length-1,5)*14}px`},children:[r("input",{type:"radio",name:"folder-destination",value:h,checked:i===h,onChange:()=>{s(h),p("")}},void 0,!1,void 0,this),r("span",{children:h||"Home (no folder)"},void 0,!1,void 0,this)]},h,!0,void 0,this))]},void 0,!0,void 0,this),r("label",{class:"home-folder-new",children:["New folder inside ",i||"Home"," ",r("span",{class:"home-folder-hint",children:"(optional)"},void 0,!1,void 0,this),r("input",{class:"text-prompt-input","aria-label":"New folder name",placeholder:"e.g. Decisions",maxLength:60,value:a,disabled:c,onInput:(h)=>{l(h.currentTarget.value),p("")}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-folder-hint",children:["Move to: ",r("strong",{children:m||"Home"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d&&r("p",{role:"alert",children:d},void 0,!1,void 0,this),r("div",{class:"text-prompt-actions",children:[r("button",{type:"button",class:"text-prompt-cancel",disabled:c,onClick:n,children:"Cancel"},void 0,!1,void 0,this),r("button",{type:"button",class:"text-prompt-confirm",disabled:c||m===(e.folder??""),onClick:()=>void f(),children:c?"Moving…":"Move board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function OT({board:e,onClose:t}){let n=F(null),o=F(null),[i,s]=E(null),[a,l]=E(new Set),[c,u]=E(`${e.name} copy`),[d,p]=E(!0),[m,f]=E(!0),[h,g]=E(!1),[v,b]=E(""),[x,C]=E(!1);return bn(n,!0,{initial:o}),G(()=>{let k=!0;return oS(e.id).then((_)=>{if(!k)return;if(!_||!Array.isArray(_.cards))return b("Could not load reusable cards. Try again.");s(_),l(new Set(_.cards.filter((A)=>A.reusable).map((A)=>A.id)))}),()=>{k=!1}},[e.id]),r("div",{class:"text-prompt-backdrop",onMouseDown:t,children:r("div",{ref:n,class:"text-prompt board-copy-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"board-copy-title",onMouseDown:(k)=>k.stopPropagation(),children:r("form",{onClick:jo,onSubmit:async(k)=>{if(k.preventDefault(),!c.trim()||!i)return;C(!0),b("");let _=await rS({sourceBoardId:e.id,name:c.trim(),...e.folder?{folder:e.folder}:{},nodeIds:[...a],includeReadme:d,includeStructure:m});if(C(!1),!_)return b("Could not create the board. Try a different name.");if(h)await Mn(_.id);t()},children:[r("h2",{id:"board-copy-title",children:["Create from ",e.name]},void 0,!0,void 0,this),r("label",{class:"board-copy-field",children:["Board name",r("input",{ref:o,class:"text-prompt-input",value:c,onInput:(k)=>u(k.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!i&&!v&&r("div",{class:"board-copy-status",role:"status",children:"Loading reusable cards…"},void 0,!1,void 0,this),v&&r("div",{class:"board-copy-error",role:"alert",children:v},void 0,!1,void 0,this),i&&r("fieldset",{class:"board-copy-cards",children:[r("legend",{children:"Cards to copy"},void 0,!1,void 0,this),i.cards.filter((k)=>k.reusable).length===0?r("div",{class:"board-copy-status",children:"No reusable cards on this board."},void 0,!1,void 0,this):i.cards.filter((k)=>k.reusable).map((k)=>r("label",{class:"board-copy-card",children:[r("input",{type:"checkbox",checked:a.has(k.id),onChange:(_)=>{let A=new Set(a);_.currentTarget.checked?A.add(k.id):A.delete(k.id),l(A)}},void 0,!1,void 0,this),r("span",{children:[r("strong",{children:k.title||"Untitled card"},void 0,!1,void 0,this),r("small",{children:k.type},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},k.id,!0,void 0,this))]},void 0,!0,void 0,this),r("div",{class:"board-copy-options",children:[r("label",{children:[r("input",{type:"checkbox",checked:m,onChange:(k)=>f(k.currentTarget.checked)},void 0,!1,void 0,this)," ","Preserve groups and connections"]},void 0,!0,void 0,this),r("label",{children:[r("input",{type:"checkbox",checked:d,disabled:!i?.readmeNodeId,onChange:(k)=>p(k.currentTarget.checked)},void 0,!1,void 0,this)," ","Include README"]},void 0,!0,void 0,this),r("label",{children:[r("input",{type:"checkbox",checked:h,onChange:(k)=>g(k.currentTarget.checked)},void 0,!1,void 0,this)," Open the new board after creating"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("p",{class:"board-copy-note",children:"Only selected cards and structure are copied. Asks, history, and context pins start clear."},void 0,!1,void 0,this),r("div",{class:"text-prompt-actions",children:[r("button",{type:"button",onClick:t,children:"Cancel"},void 0,!1,void 0,this),r("button",{type:"submit",disabled:!i||!c.trim()||x,children:x?"Creating…":"Create board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function gp({children:e,initiallyCollapsed:t=!1,reveal:n=0}){let o=F(null),[i,s]=E(280),[a,l]=E(400),[c,u]=E(t),d=F(null);return $e(()=>{if(n)u(!1)},[n]),$e(()=>{let p=o.current.closest(".home-memory"),m=p.querySelector(".home-memory-stage"),f=p.closest(".canvas-region"),h=p.querySelector(".home-memory-toolbar"),g=p.querySelector(".home-memory-legend"),v=()=>{f?.style.setProperty("--home-memory-content-top",`${m.getBoundingClientRect().top-(f?.getBoundingClientRect().top??0)}px`),l(Math.max(120,p.clientHeight-h.offsetHeight-g.offsetHeight-160))},b=new ResizeObserver(v);for(let x of[p,m,h,g])b.observe(x);return v(),()=>{b.disconnect(),f?.style.removeProperty("--home-memory-content-top")}},[]),r("div",{ref:o,class:`home-memory-inspector${c?" is-collapsed":""}`,style:c?void 0:{height:Math.min(i,a)},children:[!c&&r("div",{class:"home-memory-inspector-resize",role:"separator",tabIndex:0,"aria-label":"Resize relation details","aria-orientation":"horizontal","aria-controls":"home-memory-details","aria-valuemin":120,"aria-valuemax":a,"aria-valuenow":Math.min(i,a),onKeyDown:(p)=>{if(!["ArrowUp","ArrowDown","Home","End"].includes(p.key))return;p.preventDefault(),s(p.key==="Home"?120:p.key==="End"?a:Math.max(120,Math.min(a,Math.min(i,a)+(p.key==="ArrowUp"?32:-32))))},onPointerDown:(p)=>{if(p.button!==0)return;p.preventDefault(),d.current={id:p.pointerId,y:p.clientY,height:Math.min(i,a)},p.currentTarget.focus({preventScroll:!0}),p.currentTarget.setPointerCapture(p.pointerId)},onPointerMove:(p)=>{let m=d.current;if(m?.id===p.pointerId)s(Math.max(120,Math.min(a,m.height+m.y-p.clientY)))},onPointerUp:()=>{d.current=null},onPointerCancel:()=>{if(d.current)s(d.current.height);d.current=null}},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button home-memory-inspector-toggle","aria-expanded":!c,"aria-controls":"home-memory-details",onClick:()=>u(!c),children:c?"Expand details":"Collapse details"},void 0,!1,void 0,this),r("div",{id:"home-memory-details",children:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var yo={width:220,height:92};function DT(e,t){let n=e.filter((m)=>m.kind==="board"),o=new Map,i=[],s=new Set,a=new Set;for(let m of n){let f=(m.folder??"").split("/");f.forEach((h,g)=>{a.add(f.slice(0,g+1).join("/"))})}let l=(m,f)=>(m.folder??"")===f||!!f&&!!m.folder?.startsWith(`${f}/`),c=(m,f,h,g)=>{let v=n.filter((j)=>l(j,m)),b=t.has(m),x={path:m,x:f,y:h,width:280,height:72,count:v.length,depth:g,collapsed:b};if(i.push(x),b){for(let j of v)s.add(j.key);return x}let C=v.filter((j)=>(j.folder??"")===m).sort((j,J)=>j.title.localeCompare(J.title)),y=Math.min(3,Math.max(1,Math.ceil(Math.sqrt(C.length))));C.forEach((j,J)=>{let X=j.position??{x:f+24+J%y*(yo.width+28),y:h+52+Math.floor(J/y)*(yo.height+28)};o.set(j.key,{x:X.x+yo.width/2,y:X.y+yo.height/2})});let k=h+52+Math.ceil(C.length/y)*(yo.height+28),_=C.length?y*(yo.width+28)+20:280,A=[...a].filter((j)=>j&&j.slice(0,j.lastIndexOf("/"))===m&&j.includes("/")).sort(),w=20,M=0;for(let j of A){if(w>650)w=20,k+=M+24,M=0;let J=c(j,f+w,k,g+1);w+=J.width+24,M=Math.max(M,J.height),_=Math.max(_,w)}k+=M+(A.length?20:0),x.width=_,x.height=Math.max(100,k-h+4);let B=v.flatMap((j)=>{let J=o.get(j.key);return J?[J]:[]}),L=Math.max(f+x.width,...B.map((j)=>j.x+yo.width/2+20)),Y=Math.max(h+x.height,...B.map((j)=>j.y+yo.height/2+20));return x.x=Math.min(f,...B.map((j)=>j.x-yo.width/2-20)),x.y=Math.min(h,...B.map((j)=>j.y-yo.height/2-48)),x.width=L-x.x,x.height=Y-x.y,x},u=32,d=32,p=0;for(let m of[...a].filter((f)=>!f.includes("/")).sort()){if(u>1100)u=32,d+=p+36,p=0;let f=c(m,u,d,0);u+=f.width+36,p=Math.max(p,f.height)}return{positions:o,regions:i,hidden:s}}function yp(e){let t=Ge.value,n=ko.value,[o,i]=E(null),[s,a]=E(!0),[l,c]=E(!1),u=F(()=>{});return G(()=>{let d=!1,p=!1,m=!1,f,h=()=>{if(m=!0,!p&&f===void 0)f=window.setTimeout(g,120)},g=async()=>{f=void 0,m=!1,p=!0,a(!0);let v=In,b=ko.peek(),x=Ge.peek(),C=await pe("memoryGraph",`/api/canvas/memory-graph?projection=${e}`,null);if(d)return;if(p=!1,v!==In||b!==ko.peek()||x!==Ge.peek()){h();return}if(C&&Array.isArray(C.nodes)&&Array.isArray(C.edges))i(C),c(!1);else c(!0);if(a(!1),m)h()};return u.current=h,h(),()=>{d=!0,window.clearTimeout(f)}},[e]),G(()=>u.current(),[n,t]),{graph:o,loading:s,error:l,retry:()=>u.current()}}var BT={portal:"Portals",wiki:"Wiki links",card:"Card relations",previous:"Previous boards"};function HT(){let e=Ge.value,t=ko.value,{graph:n,loading:o,error:i,retry:s}=yp("boards"),[a,l]=E(""),[c,u]=E(!0),[d,p]=E(!1),[m,f]=E(!0),[h,g]=E(new Set),[v,b]=E(new Set),[x,C]=E(new Set),[y,k]=E(null),[_,A]=E(null),[w,M]=E(null),[B,L]=E({x:0,y:0}),[Y,j]=E(1),[J,X]=E({}),[V,ee]=E(!1),he=F(null),R=F(!0),te=F(!1),O=F(null);$e(()=>{pt.value=!0},[]),$e(()=>{if(!y)return;let N=(ne)=>{if(ar(ne))ne.preventDefault(),k(null)};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[y]),G(()=>{if(!y)return;let N=!1;M(null);let ne=In,Ce=ko.peek(),Te=new URLSearchParams({focus:y,depth:"2"});return pe("memoryGraph",`/api/canvas/memory-graph?${Te}`,null).then((me)=>{if(!N&&ne===In&&Ce===ko.peek())M({key:y,graph:me&&Array.isArray(me.nodes)&&Array.isArray(me.edges)?me:null})}),()=>{N=!0}},[y,n,t]);let H=Ve(()=>(n?.nodes??[]).filter((N)=>N.kind==="board").map((N)=>{let ne=e.find((Ce)=>Ce.id===N.boardId);return ne?{...N,title:ne.name,folder:ne.folder,inContext:!!ne.pin,nodeCount:ne.nodeCount,position:ne.mapPosition??void 0}:N}),[n,e]),Me=Ve(()=>DT(H,x),[H,x]),je=new Map;for(let N of H){let ne=N.folder?.split("/")[0]??"";je.set(ne,(je.get(ne)??0)+1)}let He=H.filter((N)=>c&&(!d||N.inContext)&&(m||!!N.folder)&&!h.has(N.folder?.split("/")[0]??"")&&!Me.hidden.has(N.key)&&`${N.title} ${N.summary} ${N.folder??""}`.toLocaleLowerCase().includes(a.trim().toLocaleLowerCase())),Re=new Set(He.map((N)=>N.key)),ve=(N)=>J[N]??Me.positions.get(N),D=H.find((N)=>N.key===y),re=H.find((N)=>N.key===(_??y)),ze=new Map;for(let N of n?.edges??[]){if(N.kind==="member"||v.has(N.kind))continue;let ne=Mt({boardId:N.source.boardId}),Ce=Mt({boardId:N.target.boardId});if(!Re.has(ne)||!N.missing&&(!Re.has(Ce)||ne===Ce))continue;let Te=JSON.stringify([ne,Ce,N.kind,N.relationKind,N.missing]),me=ze.get(Te);if(me)me.edges.push(N);else ze.set(Te,{from:ne,to:Ce,edges:[N]})}let ke=new Set(re?[re.key]:[]);for(let{from:N,to:ne}of ze.values())if(re&&(N===re.key||ne===re.key))ke.add(N),ke.add(ne);let ae=(N)=>new Set((n?.edges??[]).filter((ne)=>ne.kind!=="member"&&(ne.source.boardId===N.boardId||ne.target.boardId===N.boardId)).map((ne)=>ne.source.boardId===N.boardId?ne.target.boardId:ne.source.boardId).filter((ne)=>ne!==N.boardId)).size,Se=()=>{let N=he.current;if(!N?.clientWidth||!N.clientHeight)return;let ne=He.flatMap((Qe)=>{let Lt=ve(Qe.key);return Lt?[{x:Lt.x-110,y:Lt.y-46},{x:Lt.x+110,y:Lt.y+46}]:[]});for(let Qe of Me.regions){if(h.has(Qe.path.split("/")[0]??"")||!m&&!Qe.path)continue;ne.push({x:Qe.x,y:Qe.y},{x:Qe.x+Qe.width,y:Qe.y+Qe.height})}if(!ne.length)return;let Ce=Math.min(...ne.map((Qe)=>Qe.x)),Te=Math.min(...ne.map((Qe)=>Qe.y)),me=Math.max(...ne.map((Qe)=>Qe.x))-Ce,at=Math.max(...ne.map((Qe)=>Qe.y))-Te,Ft=Math.min(1.25,Math.max(0.08,Math.min((N.clientWidth-64)/Math.max(1,me),(N.clientHeight-100)/Math.max(1,at))));j(Ft),L({x:(N.clientWidth-me*Ft)/2-Ce*Ft,y:(N.clientHeight-at*Ft)/2-Te*Ft-12})};G(()=>{R.current=!0},[x]),G(()=>{if(R.current&&n&&(He.length||Me.regions.length)&&!O.current)R.current=!1,Se()},[n,x]);let de=(N,ne)=>{let Ce=he.current;if(!Ce)return;let Te=ne??{x:Ce.clientWidth/2,y:Ce.clientHeight/2},me=Math.min(3,Math.max(0.08,N));L({x:Te.x-(Te.x-B.x)*me/Y,y:Te.y-(Te.y-B.y)*me/Y}),j(me)},Ze=(N,ne=!1)=>{k(N.key);let Ce=ve(N.key),Te=he.current;if(ne&&Ce&&Te)L({x:Te.clientWidth/2-Ce.x*Y,y:Te.clientHeight/2-Ce.y*Y})},xe=(N)=>{let ne=O.current;if(O.current=null,!ne)return;if(te.current=ne.moved,!ne.key)return;let Ce=ne.key,Te=()=>X((me)=>{let at={...me};return delete at[Ce],at});if(ne.boardId&&ne.moved&&!N){let me=ne.current??ne.origin;Sr(ne.boardId,{mapPosition:{x:me.x-yo.width/2,y:me.y-yo.height/2}}).finally(Te)}else Te()},Ke=w?.key===y?w.graph:null,q=(Ke?.edges??[]).filter((N)=>D&&N.kind!=="member"&&(N.source.boardId===D.boardId||N.target.boardId===D.boardId)),ye=e.find((N)=>N.id===D?.boardId),Ue=(N,ne,Ce,Te)=>r("label",{class:"home-memory-check",children:[r("input",{type:"checkbox","aria-label":N,checked:Ce,onChange:Te},void 0,!1,void 0,this),r("span",{children:N},void 0,!1,void 0,this),r("small",{children:ne},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return r("main",{class:`home-memory is-map${V?" sidebar-open":""}`,"aria-label":"Library Map",children:[r("div",{class:"home-memory-toolbar",children:[r("span",{children:[H.length," boards · ",e.reduce((N,ne)=>N+ne.nodeCount,0)," cards ·"," ",n?.edges.filter((N)=>N.kind!=="member").length??0," links"]},void 0,!0,void 0,this),r("span",{class:`home-memory-live${i?" is-error":""}`,role:"status",children:i?"Update failed":o?"Updating…":"Live"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button home-memory-sidebar-toggle","aria-expanded":V,onClick:()=>ee(!V),children:"Filters"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-body",children:[r("div",{class:"home-memory-stage",ref:he,"aria-label":"Pan the memory view",onWheel:(N)=>{N.preventDefault();let ne=N.currentTarget.getBoundingClientRect();de(Y*Math.exp(-N.deltaY*0.0015),{x:N.clientX-ne.left,y:N.clientY-ne.top})},onPointerDown:(N)=>{if(N.button!==0||N.target.closest("button"))return;te.current=!1,O.current={id:N.pointerId,start:{x:N.clientX,y:N.clientY},origin:B,moved:!1},N.currentTarget.setPointerCapture(N.pointerId)},onPointerMove:(N)=>{let ne=O.current;if(!ne||ne.id!==N.pointerId)return;let Ce=N.clientX-ne.start.x,Te=N.clientY-ne.start.y;if(Math.abs(Ce)+Math.abs(Te)>4)ne.moved=!0;if(!ne.moved)return;let me={x:ne.origin.x+Ce/(ne.key?Y:1),y:ne.origin.y+Te/(ne.key?Y:1)};if(ne.current=me,ne.key)X((at)=>({...at,[ne.key]:me}));else L(me)},onPointerUp:()=>xe(!1),onPointerCancel:()=>xe(!0),children:[r("div",{class:"home-memory-world",style:{transform:`translate(${B.x}px, ${B.y}px) scale(${Y})`,"--memory-zoom":Y},children:[Me.regions.filter((N)=>!h.has(N.path.split("/")[0]??"")&&(m||N.path)).map((N)=>r("div",{class:`home-memory-region${N.depth?" is-nested":""}`,style:{left:N.x,top:N.y,width:N.width,height:N.height},children:r("button",{type:"button","aria-expanded":!N.collapsed,onClick:()=>C((ne)=>{let Ce=new Set(ne);if(Ce.has(N.path))Ce.delete(N.path);else Ce.add(N.path);return Ce}),children:[N.collapsed?"▸":"▾"," ",N.path.split("/").at(-1)||"Unfiled"," ",r("small",{children:[N.count," boards"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},N.path,!1,void 0,this)),r("svg",{class:"home-memory-links","aria-hidden":"true",children:[...ze].map(([N,{from:ne,to:Ce,edges:Te}])=>{let me=Te[0],at=ve(ne),Ft=ve(Ce);if(!at)return null;let Qe=Ft??{x:at.x+100,y:at.y-70},Lt=at.y+(Qe.y>at.y?46:-46),U=Ft?Qe.y+(Qe.y>at.y?-46:46):Qe.y,Ie=re&&(me.source.boardId===re.boardId||me.target.boardId===re.boardId),S=ho({kind:me.relationKind,type:me.type},e.find((ue)=>ue.id===me.source.boardId)?.relationVocabulary),K=me.missing?"var(--c-warn)":me.kind==="card"?`var(--c-rel-${S.ink})`:void 0;return r("g",{"data-from":ne,"data-to":Ce,"data-count":Te.length,style:K?{stroke:K}:void 0,class:`memory-edge edge-${me.kind}${me.missing?" is-missing":""}${Ie?" is-emphasized":re?" is-dimmed":""}`,children:[r("path",{d:`M ${at.x} ${Lt} C ${at.x} ${(Lt+U)/2}, ${Qe.x} ${(Lt+U)/2}, ${Qe.x} ${U}`},void 0,!1,void 0,this),Te.length>1&&r("text",{x:(at.x+Qe.x)/2,y:(at.y+Qe.y)/2-6,children:[Te.length," links"]},void 0,!0,void 0,this),me.missing&&r("text",{x:Qe.x,y:Qe.y-5,children:["⚠ Missing ",me.kind," link"]},void 0,!0,void 0,this)]},N,!0,void 0,this)})},void 0,!1,void 0,this),He.map((N,ne)=>{let Ce=ve(N.key);if(!Ce)return null;let Te=e.find((me)=>me.id===N.boardId);return r("article",{"data-key":N.key,class:`home-memory-node is-board${N.inContext?" in-context":""}${y===N.key?" is-selected":""}${ke.has(N.key)?" is-emphasized":re?" is-dimmed":""}`,style:{left:Ce.x,top:Ce.y},onPointerEnter:()=>{if(!O.current)A(N.key)},onPointerLeave:()=>A(null),children:[r("button",{type:"button",class:"home-memory-select","aria-label":`board: ${N.title}`,"aria-pressed":y===N.key,onFocus:(me)=>{if(!O.current&&me.currentTarget.matches(":focus-visible"))Ze(N,!0)},onClick:()=>{if(!te.current)Ze(N);te.current=!1},onDblClick:()=>void zt(N),onPointerDown:(me)=>{if(me.button!==0)return;me.stopPropagation(),te.current=!1,O.current={id:me.pointerId,start:{x:me.clientX,y:me.clientY},origin:Ce,key:N.key,boardId:N.boardId,moved:!1},me.currentTarget.setPointerCapture(me.pointerId)},onKeyDown:(me)=>{if(me.key==="Enter")me.preventDefault(),zt(N);if(me.key.startsWith("Arrow")){me.preventDefault();let at=(ne+(me.key==="ArrowLeft"||me.key==="ArrowUp"?-1:1)+He.length)%He.length,Ft=He[at];if(Ft)Ze(Ft,!0),he.current?.querySelectorAll(".home-memory-select")[at]?.focus({preventScroll:!0})}},children:[r("strong",{children:N.title},void 0,!1,void 0,this),r("span",{children:[N.nodeCount??0," cards · ",ae(N)," connected boards"]},void 0,!0,void 0,this),r("span",{class:"home-memory-summary",children:N.summary||"No summary yet"},void 0,!1,void 0,this),N.inContext&&r("span",{class:"home-memory-context",children:"⌖ In context"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Te&&r(go,{board:Te},void 0,!1,void 0,this)]},N.key,!0,void 0,this)})]},void 0,!0,void 0,this),r("div",{class:"home-memory-zoom",children:[r("button",{type:"button",class:"home-button","aria-label":"Zoom out",onClick:()=>de(Y/1.2),children:"−"},void 0,!1,void 0,this),r("span",{children:[Math.round(Y*100),"%"]},void 0,!0,void 0,this),r("button",{type:"button",class:"home-button","aria-label":"Zoom in",onClick:()=>de(Y*1.2),children:"+"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button",onClick:Se,children:"Fit view"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(!n||!He.length||i)&&r("div",{class:"home-memory-status",role:"status",children:i?r(be,{children:["Memory update failed."," ",r("button",{type:"button",class:"home-button",onClick:s,children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):!n?"Loading memory…":Me.hidden.size?"Folders collapsed. Expand a folder to see its boards.":"No matching nodes."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("aside",{class:"home-memory-sidebar","aria-label":"Map settings",children:[r("section",{children:[r("h2",{children:"Filters"},void 0,!1,void 0,this),r("label",{class:"home-memory-search",children:[r("span",{children:"Find boards and cards"},void 0,!1,void 0,this),r("input",{type:"search",value:a,placeholder:"Search boards and cards…",onInput:(N)=>l(N.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ue("Boards",H.length,c,()=>u(!c)),Ue("Only in context",H.filter((N)=>N.inContext).length,d,()=>p(!d)),Ue("Include unfiled",H.filter((N)=>!N.folder).length,m,()=>f(!m))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Groups · by folder"},void 0,!1,void 0,this),[...je].sort(([N],[ne])=>N.localeCompare(ne)).map(([N,ne])=>r("div",{children:Ue(N||"Unfiled",ne,!h.has(N),()=>g((Ce)=>{let Te=new Set(Ce);if(Te.has(N))Te.delete(N);else Te.add(N);return Te}))},N,!1,void 0,this))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Links"},void 0,!1,void 0,this),Object.keys(BT).map((N)=>r("div",{class:`memory-legend-${N}`,children:Ue(BT[N],n?.edges.filter((ne)=>ne.kind===N).length??0,!v.has(N),()=>b((ne)=>{let Ce=new Set(ne);if(Ce.has(N))Ce.delete(N);else Ce.add(N);return Ce}))},N,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-legend","aria-label":"Legend",children:[r("span",{children:"▣ Board"},void 0,!1,void 0,this),r("span",{class:"memory-context-legend",children:"⌖ In context"},void 0,!1,void 0,this),r("span",{class:"memory-legend-portal",children:"━ Portal"},void 0,!1,void 0,this),r("span",{class:"memory-legend-wiki",children:"┄ Wiki"},void 0,!1,void 0,this),r("span",{class:"memory-legend-card",children:"━ Relation"},void 0,!1,void 0,this),r("span",{children:"Drag boards to save positions · drag background to pan · scroll to zoom"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(gp,{children:D?r("section",{class:"home-memory-details",role:"complementary","aria-label":"Selection details",children:[r("button",{type:"button",class:"home-memory-clear","aria-label":"Close details",onClick:()=>k(null),children:"×"},void 0,!1,void 0,this),r("div",{class:"home-memory-detail-header",children:[r("div",{class:"home-memory-selection-title",children:[r("h3",{children:[D.title," · ",q.length," connections"]},void 0,!0,void 0,this),r("p",{children:[D.folder||"Unfiled"," · board"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-actions",children:[r("button",{type:"button",class:"home-button is-primary",onClick:()=>void zt(D),children:"Open board"},void 0,!1,void 0,this),ye&&r(go,{board:ye},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button",onClick:()=>void Sr(D.boardId,{mapPosition:null}),children:"Reset position"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-detail-body",children:[r("p",{children:[D.nodeCount??0," cards · ",ae(D)," connected boards"]},void 0,!0,void 0,this),r("p",{children:D.summary||"No summary yet."},void 0,!1,void 0,this),r("p",{class:D.inContext?"memory-context-legend":"",children:D.inContext?"⌖ In context":"Not in context"},void 0,!1,void 0,this),r("details",{class:"home-memory-connections",open:!0,children:[r("summary",{children:"Connections"},void 0,!1,void 0,this),!Ke&&r("p",{role:"status",children:w?.key===y?"Connections could not be loaded.":"Loading connections…"},void 0,!1,void 0,this),r("ul",{children:[q.map((N)=>{let ne=N.source.boardId===D.boardId,Ce=ne?N.target:N.source,Te=Ke?.nodes.find((me)=>me.key===Mt(Ce));return r("li",{children:[r("span",{children:[ne?"→":"←"," ",N.kind==="card"?Ca({...N,kind:N.relationKind}):`${N.kind}${N.label?` · ${N.label}`:""}`]},void 0,!0,void 0,this),N.missing?r("span",{class:"home-memory-missing",children:["⚠ Missing target: ",Ce.boardId,Ce.cardId?` / ${Ce.cardId}`:""]},void 0,!0,void 0,this):r("button",{type:"button",class:"home-button",onClick:()=>void zt(Ce),children:Te?.title??Ce.boardId},void 0,!1,void 0,this)]},N.id,!0,void 0,this)}),(Ke?.unresolvedLinks??[]).filter((N)=>N.source.boardId===D.boardId).map((N)=>r("li",{class:"home-memory-missing",children:["⚠ Unresolved wiki: [[",N.ref,"]]"]},`${Mt(N.source)}:${N.ref}`,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):r("div",{class:"home-memory-empty-details",children:[r("h3",{children:"Relations"},void 0,!1,void 0,this),r("p",{class:"home-memory-help",children:"Overview groups links between boards. Select a board to inspect connections. Double-click to open."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Ye={width:220,height:96,gap:64},hc=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),VL=(e,t)=>e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom;function XL(e,t,n){let o=0,i=1;for(let[s,a,l,c]of[[e.x,t.x-e.x,n.left,n.right],[e.y,t.y-e.y,n.top,n.bottom]])if(!a){if(s<=l||s>=c)return!1}else{let u=(l-s)/a,d=(c-s)/a;o=Math.max(o,Math.min(u,d)),i=Math.min(i,Math.max(u,d))}return o<i&&i>0&&o<1}function FT(e,t){let o=[...e].map(([m,f])=>({key:m,left:f.x-Ye.width/2-8,right:f.x+Ye.width/2+8,top:f.y-Ye.height/2-8,bottom:f.y+Ye.height/2+8})),i=(m,f)=>!o.some((h)=>XL(m,f,h)),s=o.flatMap((m)=>[{x:m.left,y:m.top},{x:m.right,y:m.top},{x:m.right,y:m.bottom},{x:m.left,y:m.bottom}]).filter((m)=>!o.some((f)=>VL(m,f))),a=new Map,l=(m,f)=>[{x:m.x-Ye.width/2,y:m.y+f*Ye.height},{x:m.x+Ye.width/2,y:m.y+f*Ye.height},{x:m.x+f*Ye.width,y:m.y-Ye.height/2},{x:m.x+f*Ye.width,y:m.y+Ye.height/2}].map((h,g)=>({port:h,stub:{x:h.x+(g===0?-8:g===1?8:0),y:h.y+(g===2?-8:g===3?8:0)}})),c=new Map,u=[],d=new Map,p=new Map;for(let m of t){let f=JSON.stringify([m.from,m.to].sort());p.set(f,(p.get(f)??0)+1)}for(let m of t){let f=e.get(m.from),h=e.get(m.to),g=JSON.stringify([m.from,m.to].sort()),v=d.get(g)??0;d.set(g,v+1);let b=((v+1)/(p.get(g)+1)-0.5)*0.8,x=l(f,b),C=l(h,b),y,k=1/0;for(let M of x)for(let B of C){let L=hc(M.stub,B.stub);if(L&&L<k&&i(M.stub,B.stub))k=L,y=[M.port,M.stub,B.stub,B.port]}if(!y){let M=s.map(()=>1/0),B=s.map(()=>-1),L=s.map(()=>0),Y=new Set;for(let X=0;X<s.length;X++)for(let V=0;V<x.length;V++){let ee=hc(x[V].stub,s[X]);if(ee<M[X]&&i(x[V].stub,s[X]))M[X]=ee,L[X]=V}let j=-1,J=0;while(Y.size<s.length){let X=-1;for(let ee=0;ee<s.length;ee++)if(!Y.has(ee)&&(X<0||M[ee]<M[X]))X=ee;if(X<0||M[X]>=k||!Number.isFinite(M[X]))break;Y.add(X);for(let ee=0;ee<C.length;ee++){let he=M[X]+hc(s[X],C[ee].stub);if(he<k&&i(s[X],C[ee].stub))k=he,j=X,J=ee}let V=a.get(X);if(!V)V=s.flatMap((ee,he)=>he!==X&&i(s[X],ee)?[{index:he,length:hc(s[X],ee)}]:[]),a.set(X,V);for(let ee of V)if(M[X]+ee.length<M[ee.index])M[ee.index]=M[X]+ee.length,B[ee.index]=X,L[ee.index]=L[X]}if(j>=0){let X=[];for(let he=j;he>=0;he=B[he])X.unshift(s[he]);let V=x[L[j]],ee=C[J];y=[V.port,V.stub,...X,ee.stub,ee.port]}}if(!y)continue;let _=Math.max(24,m.label.length*3.6+6),A=y.slice(1).map((M,B)=>({first:y[B],point:M,length:hc(y[B],M)})).filter((M)=>M.length>0).sort((M,B)=>B.length-M.length),w;for(let M=16;m.label&&!w;M+=20)w=A.flatMap(({first:L,point:Y,length:j})=>[0.5,0.25,0.75].flatMap((J)=>[-M,M].map((X)=>{let V=L.x+(Y.x-L.x)*J-(Y.y-L.y)*X/j,ee=L.y+(Y.y-L.y)*J+(Y.x-L.x)*X/j;return{x:V,y:ee,left:V-_,right:V+_,top:ee-16,bottom:ee+8}}))).find((L)=>![...o,...u].some((Y)=>L.left<Y.right&&L.right>Y.left&&L.top<Y.bottom&&L.bottom>Y.top));if(w)u.push(w);c.set(m.id,{points:y,path:y.map((M,B)=>`${B?"L":"M"} ${M.x} ${M.y}`).join(" "),label:w})}return c}var ms=(e)=>e.kind==="overview"?"overview":JSON.stringify(e),JL=(e,t)=>JSON.stringify([e,t].sort());function jT(e){let t=new Map,n=new Map,o=[],i=e.filter((s)=>s.kind!=="member");for(let s of i){if(s.missing){o.push(s);continue}if(s.source.boardId===s.target.boardId){n.set(s.source.boardId,(n.get(s.source.boardId)??0)+1);continue}let a=JL(s.source.boardId,s.target.boardId),l=t.get(a);if(l)l.edges.push(s);else t.set(a,{boardId:s.source.boardId,peerId:s.target.boardId,edges:[s]})}return{evidence:i,pairs:t,internal:n,missing:o}}function vp(e){let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return(t>>>0)/4294967296}function UT(e,t){let n=new Map(e.map((i)=>[i,new Map])),o=t.filter((i)=>i.from!==i.to&&n.has(i.from)&&n.has(i.to)).map((i)=>({ends:[i.from,i.to].sort(),weight:Math.max(0.1,i.weight??1)})).sort((i,s)=>i.ends[0].localeCompare(s.ends[0])||i.ends[1].localeCompare(s.ends[1])||i.weight-s.weight);for(let{ends:[i,s],weight:a}of o)n.get(i).set(s,(n.get(i).get(s)??0)+a),n.get(s).set(i,(n.get(s).get(i)??0)+a);return n}function ZT(e,t,n,o){let i=t.get(e),s=[...o.values()].reduce((c,u)=>c+Math.sqrt(u),0),a=0,l=0;for(let c of n){if(c===e)continue;let u=t.get(c),d=i.x-u.x||(vp(e)-0.5)*0.01,p=i.y-u.y||(vp(`${e}:y`)-0.5)*0.01,m=Math.max(1,Math.hypot(d,p)),f=14000/(m*m),h=o.get(c)??0,g=h?(m-290)*0.006*Math.sqrt(h)/s:0;a+=d/m*(f-g),l+=p/m*(f-g);let v=Ye.width+Ye.gap,b=(Ye.height+Ye.gap)*Ye.width/Ye.height;if(Math.abs(d)<v&&Math.abs(p)<b)if(v-Math.abs(d)<b-Math.abs(p))a+=Math.sign(d)*(v-Math.abs(d))*0.2;else l+=Math.sign(p)*(b-Math.abs(p))*0.2}return{x:a,y:l}}function WT(e,t,n,o){let i=[...e.keys()].sort(),s=UT(i,t),a=Ye.width/Ye.height,l=new Map([...e].map(([u,d])=>[u,{x:d.x,y:d.y*a}])),c=0;for(let u of i){if(u===n)continue;let d=l.get(u),p=ZT(u,l,i,s.get(u)),m=Math.min(1,24/Math.max(1,Math.hypot(p.x,p.y)))*o,f=p.x*m,h=p.y*m/a;e.set(u,{x:d.x+f,y:d.y/a+h}),c=Math.max(c,Math.hypot(f,h))}for(let[u,d]of i.entries())for(let p of i.slice(u+1)){let m=e.get(d),f=e.get(p),h=m.x-f.x,g=m.y-f.y,v=Ye.width+Ye.gap-Math.abs(h),b=Ye.height+Ye.gap-Math.abs(g);if(v<=0||b<=0)continue;let x=v<b?{x:(Math.sign(h)||-1)*v,y:0}:{x:0,y:(Math.sign(g)||-1)*b},C=p===n?1:0.5,y=d===n?1:0.5;if(d!==n)e.set(d,{x:m.x+x.x*C,y:m.y+x.y*C});if(p!==n)e.set(p,{x:f.x-x.x*y,y:f.y-x.y*y});c=Math.max(c,Math.hypot(x.x,x.y))}return c}function qT(e,t,n){let o=[...new Set(e.map((y)=>y.key))].sort();if(o.every((y)=>n.has(y)))return new Map(o.map((y)=>[y,n.get(y)]));let i=UT(o,t),s=[],a=new Set;for(let y of o){if(a.has(y))continue;let k=[y];a.add(y);for(let _ of k)for(let A of i.get(_).keys()){if(a.has(A))continue;a.add(A),k.push(A)}s.push(k.sort())}let l=new Map,c=Ye.width/Ye.height;for(let y of o){let k=n.get(y);if(k)l.set(y,{x:k.x,y:k.y*c})}for(let y of s){if(!y.some((k)=>l.has(k)))l.set(y[0],{x:0,y:0});while(y.some((k)=>!l.has(k)))for(let k of y){if(l.has(k))continue;let _=[...i.get(k).keys()].filter((A)=>l.has(A));if(!_.length)continue;l.set(k,{x:_.reduce((A,w)=>A+l.get(w).x,0)/_.length+(vp(k)-0.5)*240,y:_.reduce((A,w)=>A+l.get(w).y,0)/_.length+(vp(`${k}:y`)-0.5)*240})}for(let k=0;k<180;k++){let _=new Map;for(let A of y){if(n.has(A))continue;let w=l.get(A),{x:M,y:B}=ZT(A,l,y,i.get(A)),L=Math.min(1,24/Math.max(1,Math.hypot(M,B)))*(1-k/200);_.set(A,{x:w.x+M*L,y:w.y+B*L})}for(let[A,w]of _)l.set(A,w)}}for(let[y,k]of l)l.set(y,n.get(y)??{x:k.x,y:k.y/c});let u=o.filter((y)=>n.has(y)).map((y)=>l.get(y)),d=Ye.width+Ye.gap,p=Ye.height+Ye.gap,m=(y,k)=>Math.abs(y.x-k.x)<d&&Math.abs(y.y-k.y)<p,f=0,h=0,g=0,v=0,b=Math.sqrt(o.length)*380,x=(y)=>y.some((k)=>n.has(k));s.sort((y,k)=>Number(x(k))-Number(x(y)));let C=!1;for(let y of s){let k=x(y);if(!k&&!C)f=u.length?Math.max(...u.map((w)=>w.x))+340:0,h=f,C=!0;let _=k?u:[],A=[];for(let w of y){if(n.has(w))continue;let M=l.get(w),B=M;if(_.some((L)=>m(B,L)))B=_.flatMap((Y)=>[{x:Y.x-d,y:M.y},{x:Y.x+d,y:M.y},{x:M.x,y:Y.y-p},{x:M.x,y:Y.y+p}]).filter((Y)=>!_.some((j)=>m(Y,j))).sort((Y,j)=>Math.hypot(Y.x-M.x,Y.y-M.y)-Math.hypot(j.x-M.x,j.y-M.y))[0];l.set(w,B),_.push(B),A.push(B)}if(!k&&A.length){let w=Math.min(...A.map((B)=>B.x)),M=Math.min(...A.map((B)=>B.y));for(let B of A)B.x+=h-w,B.y+=g-M;if(u.push(...A),h=Math.max(...A.map((B)=>B.x))+340,v=Math.max(v,Math.max(...A.map((B)=>B.y))-g+200),h-f>b)h=f,g+=v,v=0}}for(let[y,k]of l)if(!n.has(y))n.set(y,k);return l}var GT={portal:"Portals",wiki:"Wiki links",card:"Card relations",previous:"Previous boards"},Og=(e)=>({scene:e,camera:null,query:"",context:!1,folders:new Set,hiddenLinks:new Set,inspection:null,limit:80});function KT(){let e=Ge.value,{graph:t,loading:n,error:o,retry:i}=yp("full"),[s,a]=E([Og({kind:"overview"})]),l=s.at(-1),c=l.scene,u=ms(c),[d,p]=E(!1),[m,f]=E(0),[h,g]=E(0),[v,b]=E(null),[x,C]=E(""),[y,k]=E({width:0,height:0}),_=F(new Map),A=F(null),w=F(null),M=F(null),B=F(null),L=()=>{if(M.current!==null)cancelAnimationFrame(M.current);M.current=null,B.current=null},Y=F(!1),j=(S)=>a((K)=>[...K.slice(0,-1),{...K.at(-1),...S}]),J=()=>{a((S)=>S.length>1?S.slice(0,-1):S),p(!1),b(null),C("")},X=(S)=>{if(ms(S)===u){f((K)=>K+1);return}a((K)=>[...K,Og(S)]),p(!1),b(null),C("")},V=(S)=>{let K=s.map((ue)=>ms(ue.scene)).lastIndexOf(ms(S));if(K>=0)a((ue)=>ue.slice(0,K+1));else X(S);p(!1)};$e(()=>{pt.value=!0},[]),$e(()=>{let S=A.current,K=()=>k({width:S.clientWidth,height:S.clientHeight}),ue=new ResizeObserver(K);return ue.observe(S),K(),()=>ue.disconnect()},[]),$e(()=>{let S=(K)=>{if(!ar(K))return;if(l.inspection||s.length>1)if(K.preventDefault(),l.inspection)j({inspection:null});else J()};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[l.inspection,s.length]);let ee=Ve(()=>(t?.nodes??[]).map((S)=>{let K=e.find((ue)=>ue.id===S.boardId);return K?{...S,folder:K.folder,...S.kind==="board"?{title:K.name,nodeCount:K.nodeCount,inContext:!!K.pin}:{}}:S}),[t,e]),he=Ve(()=>new Map(ee.map((S)=>[S.key,S])),[ee]),R=Ve(()=>jT(t?.edges??[]),[t]),te=c.kind==="overview"?null:Mt(c),O=te?he.get(te):void 0,H=(S)=>e.find((K)=>K.id===S)?.name??S,Me=(S)=>c.kind!=="overview"&&S.boardId===c.boardId,je=c.kind==="overview"?R.evidence:R.evidence.filter((S)=>c.kind==="board"?S.source.boardId===c.boardId||S.target.boardId===c.boardId:S.from===te||S.to===te),He=Ve(()=>{if(c.kind==="overview")return{nodes:ee.filter((ue)=>ue.kind==="board"),links:[...R.pairs].map(([ue,Oe])=>({id:ue,from:Mt({boardId:Oe.boardId}),to:Mt({boardId:Oe.peerId}),edges:Oe.edges,bundle:!0}))};let S=new Set;if(c.kind==="board"){for(let ue of ee)if(Me(ue)&&ue.kind==="card")S.add(ue.key)}else if(te&&he.has(te))S.add(te);let K=new Map;for(let ue of je){if(ue.missing||!he.has(ue.from)||!he.has(ue.to))continue;let Oe=c.kind==="board"&&ue.source.boardId!==c.boardId?Mt({boardId:ue.source.boardId}):ue.from,We=c.kind==="board"&&ue.target.boardId!==c.boardId?Mt({boardId:ue.target.boardId}):ue.to;S.add(Oe),S.add(We);let le=c.kind==="card"?ue.id:JSON.stringify([Oe,We].sort()),we=K.get(le);if(we)we.edges.push(ue),we.bundle=!0;else K.set(le,{id:le,from:Oe,to:We,edges:[ue],bundle:Oe!==ue.from||We!==ue.to})}return{nodes:ee.filter((ue)=>S.has(ue.key)),links:[...K.values()]}},[ee,t,u]),Re=new Map;for(let S of He.links)for(let K of[S.from,S.to])Re.set(K,(Re.get(K)??0)+S.edges.length);let ve=He.nodes.filter((S)=>Re.has(S.key)||S.key===te),D=He.nodes.filter((S)=>!Re.has(S.key)&&S.key!==te),re=(S)=>S.key===te||(!l.context||S.inContext)&&!l.folders.has(S.folder?.split("/")[0]??"")&&`${S.title} ${S.summary} ${H(S.boardId)} ${S.folder??""}`.toLocaleLowerCase().includes(l.query.trim().toLocaleLowerCase()),ze=ve.filter(re).sort((S,K)=>Number(K.key===te)-Number(S.key===te)||(Re.get(K.key)??0)-(Re.get(S.key)??0)||S.key.localeCompare(K.key)),ke=ze.slice(0,l.limit),ae=new Set(ke.map((S)=>S.key)),Se=D.filter(re),de=He.links.map((S)=>({...S,edges:S.edges.filter((K)=>!l.hiddenLinks.has(K.kind))})).filter((S)=>S.edges.length&&ae.has(S.from)&&ae.has(S.to));G(()=>()=>{L(),Y.current||=!!w.current?.moved,w.current=null},[He,l.limit,l.query,l.context,l.folders,l.hiddenLinks]);let Ze=(S)=>{if(M.current!==null)return;let K=180,ue=()=>{let Oe=w.current?.key===S,We=_.current.get(u);if(B.current)We.set(S,B.current);B.current=null;let le=new Map(ke.map((ge)=>[ge.key,We.get(ge.key)])),we=WT(le,de.map((ge)=>({...ge,weight:ge.edges.length})),S,Oe?1:K/180);for(let[ge,De]of le)We.set(ge,De);if(g((ge)=>ge+1),Oe||--K>0&&we>0.02)M.current=requestAnimationFrame(ue);else M.current=null};M.current=requestAnimationFrame(ue)},xe=Ve(()=>{let S=_.current.get(u);if(!S)S=new Map,_.current.set(u,S);if(c.kind!=="card")return qT(ve,He.links.map((ge)=>({...ge,weight:ge.edges.length})),S);if(!S.has(te))S.set(te,{x:0,y:0});let K=je.filter((ge)=>ge.kind!=="card"||ho({kind:ge.relationKind,type:ge.type},e.find((De)=>De.id===ge.source.boardId)?.relationVocabulary).directed),ue=new Set(K.filter((ge)=>ge.to===te).map((ge)=>ge.from)),Oe=new Set(K.filter((ge)=>ge.from===te).map((ge)=>ge.to)),We=ve.filter((ge)=>ge.key!==te).sort((ge,De)=>ge.key.localeCompare(De.key)),le=Ye.width+Ye.gap,we=Ye.height+Ye.gap;for(let ge of["incoming","outgoing","mutual"]){let De=We.filter((on)=>(ue.has(on.key)&&!Oe.has(on.key)?"incoming":Oe.has(on.key)&&!ue.has(on.key)?"outgoing":"mutual")===ge),Rt=De.filter((on)=>S.has(on.key)).map((on)=>S.get(on.key)),gt=S.get(te).y+we,mn=0;for(let[on,vs]of De.entries())if(!S.has(vs.key)){let Pn=Rt.length?Math.max(...Rt.map((fn)=>ge==="mutual"?fn.x:fn.y))+(mn+1)*(ge==="mutual"?le:we):(on-(De.length-1)/2)*(ge==="mutual"?le:we),xn=ge==="mutual"?{x:Pn,y:gt}:{x:ge==="incoming"?-360:360,y:Pn};while([...S.values()].some((fn)=>Math.abs(fn.x-xn.x)<le&&Math.abs(fn.y-xn.y)<we))xn.y+=we;S.set(vs.key,xn),mn++}}return new Map(S)},[He,u,h]),Ke=(S)=>S.bundle?`${S.edges.length} links`:S.edges[0].kind==="card"?ho({kind:S.edges[0].relationKind,type:S.edges[0].type},e.find((K)=>K.id===S.edges[0].source.boardId)?.relationVocabulary).kind:S.edges[0].kind,q=Ve(()=>FT(new Map(ke.map((S)=>[S.key,xe.get(S.key)])),de.map((S)=>({...S,label:S.edges.length>1||c.kind==="card"?Ke(S):""})).sort((S,K)=>S.id.localeCompare(K.id))),[xe,He,l.limit,l.query,l.context,l.folders,l.hiddenLinks]),ye=l.camera??{x:0,y:0,scale:1},Ue=ke.filter((S)=>{let K=xe.get(S.key);return(K.x-Ye.width/2)*ye.scale+ye.x<8||(K.x+Ye.width/2)*ye.scale+ye.x>y.width-8||(K.y-Ye.height/2)*ye.scale+ye.y<(c.kind==="card"?40:8)||(K.y+Ye.height/2)*ye.scale+ye.y>y.height-64}).length,N=(S=!1)=>{let K=A.current;if(!K||!ke.length)return;let ue=c.kind==="card"?40:16,Oe=K.clientHeight-ue-64-8,We=ke.flatMap((gt)=>{let mn=xe.get(gt.key);return[{x:mn.x-Ye.width/2,y:mn.y-Ye.height/2},{x:mn.x+Ye.width/2,y:mn.y+Ye.height/2}]});for(let gt of q.values())if(We.push(...gt.points),gt.label)We.push({x:gt.label.left,y:gt.label.top},{x:gt.label.right,y:gt.label.bottom});let le=Math.min(...We.map((gt)=>gt.x)),we=Math.min(...We.map((gt)=>gt.y)),ge=Math.max(...We.map((gt)=>gt.x))-le,De=Math.max(...We.map((gt)=>gt.y))-we,Rt=Math.min(1,Math.max(S?1:0.005,Math.min((K.clientWidth-64)/ge,Oe/De)));j({camera:S&&c.kind==="card"?{x:K.clientWidth/2-xe.get(te).x,y:ue+Oe/2-xe.get(te).y,scale:1}:{x:(K.clientWidth-ge*Rt)/2-le*Rt,y:ue+(Oe-De*Rt)/2-we*Rt,scale:Rt}})};$e(()=>{if(t&&!l.camera&&ke.length)N(!0)},[t,u,l.camera]),G(()=>{if(!t||c.kind==="overview"||O)return;let S=he.has(Mt({boardId:c.boardId}));a((K)=>{let ue=K.filter((We)=>We.scene.kind==="overview"||he.has(Mt(We.scene))),Oe=c.kind==="card"&&S?{kind:"board",boardId:c.boardId}:{kind:"overview"};return ms(ue.at(-1).scene)===ms(Oe)?ue:[...ue,Og(Oe)]}),C("The focused endpoint was removed. Returned to its nearest available level.")},[t,te,O]);let ne=(S)=>{let K=xe.get(S.key),ue=A.current;if(!K||!ue)return;let Oe=Math.max(1,ye.scale);j({camera:{x:ue.clientWidth/2-K.x*Oe,y:ue.clientHeight/2-K.y*Oe-20,scale:Oe},limit:Math.max(l.limit,ze.indexOf(S)+1)}),p(!1)},Ce=(S)=>{if(S.kind==="card"&&S.cardId)X({kind:"card",boardId:S.boardId,cardId:S.cardId});else X({kind:"board",boardId:S.boardId})},Te=(S,K)=>{let ue=A.current;if(!ue)return;let Oe=K??{x:ue.clientWidth/2,y:ue.clientHeight/2},We=Math.max(0.005,Math.min(3,S));j({camera:{x:Oe.x-(Oe.x-ye.x)*We/ye.scale,y:Oe.y-(Oe.y-ye.y)*We/ye.scale,scale:We}})},me=He.links.find((S)=>S.id===l.inspection),at=me?.edges??je,Ft=O?e.find((S)=>S.id===O.boardId):void 0,Qe=(S)=>{j({inspection:S.id}),f((K)=>K+1)},Lt=(S,K,ue)=>r("label",{class:"home-memory-check",children:[r("input",{type:"checkbox","aria-label":S,checked:K,onChange:ue},void 0,!1,void 0,this),r("span",{children:S},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U=c.kind!=="overview"&&!O,Ie=c.kind==="overview"?"Library":c.kind==="board"?H(c.boardId):O?.title??"Missing card";return r("main",{class:`home-memory graph-view${d?" sidebar-open":""}`,"aria-label":"Library Graph",style:{"--graph-node-width":`${Ye.width}px`,"--graph-node-height":`${Ye.height}px`},children:[r("div",{class:"home-memory-toolbar",children:[s.length>1&&r("button",{type:"button",class:"home-button",onClick:J,children:"Back"},void 0,!1,void 0,this),r("nav",{class:"graph-breadcrumb","aria-label":"Graph path",children:[r("button",{type:"button",class:"home-button",onClick:()=>V({kind:"overview"}),children:"Library"},void 0,!1,void 0,this),c.kind!=="overview"&&r(be,{children:[r("span",{children:"›"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button",onClick:()=>V({kind:"board",boardId:c.boardId}),children:H(c.boardId)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c.kind==="card"&&r(be,{children:[r("span",{children:"›"},void 0,!1,void 0,this),r("strong",{children:Ie},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("span",{children:[ke.length," of ",ve.length," connected drawn · ",Ue," partly/outside view ·"," ",ve.length-ze.length," filtered · ",Math.max(0,ze.length-ke.length)," hidden ·"," ",D.length," without links"]},void 0,!0,void 0,this),ze.length>l.limit&&r("button",{type:"button",class:"home-button",onClick:()=>j({limit:l.limit+80}),children:"Show more connections"},void 0,!1,void 0,this),r("span",{class:`home-memory-live${o?" is-error":""}`,role:"status",children:o?"Update failed":n?"Updating…":"Live"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button home-memory-sidebar-toggle","aria-expanded":d,onClick:()=>p(!d),children:"Filters"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-body",children:[r("div",{class:"home-memory-stage",ref:A,"aria-label":"Pan the memory view",onWheel:(S)=>{S.preventDefault();let K=S.currentTarget.getBoundingClientRect();Te(ye.scale*Math.exp(-S.deltaY*0.0015),{x:S.clientX-K.left,y:S.clientY-K.top})},onPointerDown:(S)=>{if(S.button!==0||S.target.closest('button, [role="button"]'))return;L(),Y.current=!1,w.current={id:S.pointerId,start:{x:S.clientX,y:S.clientY},origin:ye,moved:!1},S.currentTarget.setPointerCapture(S.pointerId)},onPointerMove:(S)=>{let K=w.current;if(!K||K.id!==S.pointerId||!(S.buttons&1))return;let ue=S.clientX-K.start.x,Oe=S.clientY-K.start.y;if(Math.abs(ue)+Math.abs(Oe)>4)K.moved=!0;if(!K.moved)return;let We={x:K.origin.x+ue/(K.key?ye.scale:1),y:K.origin.y+Oe/(K.key?ye.scale:1)};if(K.key)B.current=We,Ze(K.key);else j({camera:{...We,scale:ye.scale}})},onPointerUp:()=>{if(!w.current)return;Y.current=w.current.moved,w.current=null},onPointerCancel:()=>{let S=w.current;if(L(),S?.layout)_.current.set(u,S.layout),g((K)=>K+1);else if(S)j({camera:{...S.origin,scale:ye.scale}});Y.current=!!S?.moved,w.current=null},children:[c.kind==="card"&&r("div",{class:"graph-direction-caption",children:"Incoming starts left · outgoing starts right · drag to rearrange"},void 0,!1,void 0,this),r("div",{class:"home-memory-world",style:{transform:`translate(${ye.x}px, ${ye.y}px) scale(${ye.scale})`},children:[r("svg",{class:"home-memory-links graph-links","aria-label":"Graph connections",children:de.map((S,K)=>{let ue=q.get(S.id);if(!ue)return null;let Oe=S.edges[0],We=ho({kind:Oe.relationKind,type:Oe.type},e.find((De)=>De.id===Oe.source.boardId)?.relationVocabulary),le=!S.bundle&&(Oe.kind!=="card"||We.directed),we=S.bundle?"var(--c-muted)":Oe.kind==="card"?`var(--c-rel-${We.ink})`:Oe.kind==="wiki"?"var(--c-rel-cites)":"var(--c-rel-derived)",ge=`${S.edges.length} ${S.bundle?"links":"link"} between ${he.get(S.from)?.title} and ${he.get(S.to)?.title}`;return r("g",{class:`graph-link${S.bundle?" is-bundle":" is-exact"}${S.from===v||S.to===v?" is-highlighted":""}${l.inspection===S.id?" is-selected":""}`,"data-from":S.from,"data-to":S.to,"data-count":S.edges.length,"data-link-id":S.id,role:"button",tabindex:0,"aria-label":`Inspect ${ge}`,style:{stroke:we},onClick:()=>Qe(S),onKeyDown:(De)=>{if(De.key==="Enter"||De.key===" ")De.preventDefault(),Qe(S)},children:[r("defs",{children:r("marker",{id:`graph-arrow-${K}`,viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto",children:r("path",{d:"M 0 0 L 10 5 L 0 10 z",style:{fill:we,stroke:"none"}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("path",{class:"graph-link-hit",d:ue.path},void 0,!1,void 0,this),r("path",{class:"graph-link-line",d:ue.path,"marker-end":le?`url(#graph-arrow-${K})`:void 0},void 0,!1,void 0,this),ue.label&&(S.edges.length>1||c.kind==="card")&&r("text",{x:ue.label.x,y:ue.label.y,children:Ke(S)},void 0,!1,void 0,this)]},S.id,!0,void 0,this)})},void 0,!1,void 0,this),ke.map((S,K)=>{let ue=xe.get(S.key),Oe=e.find((le)=>le.id===S.boardId),We=S.kind==="board"?S.inContext:!!Oe?.pinnedTitles?.some((le)=>le.nodeId===S.cardId)||S.inContext&&!Oe?.pin;return r("article",{"data-key":S.key,class:`graph-node is-${S.kind}${te===S.key?" is-selected":""}${We?" in-context":""}${c.kind!=="overview"&&!Me(S)?" is-external":""}`,style:{left:ue.x,top:ue.y},onPointerEnter:()=>b(S.key),onPointerLeave:()=>b(null),children:r("button",{type:"button",class:"home-memory-select","aria-label":`${S.kind}: ${S.title}`,"aria-pressed":te===S.key,onClick:()=>{if(!Y.current)Ce(S);Y.current=!1},onPointerDown:(le)=>{if(le.button!==0)return;le.stopPropagation(),L(),Y.current=!1,w.current={id:le.pointerId,start:{x:le.clientX,y:le.clientY},origin:ue,key:S.key,layout:new Map(_.current.get(u)),moved:!1},le.currentTarget.setPointerCapture(le.pointerId)},onKeyDown:(le)=>{if(!le.key.startsWith("Arrow"))return;le.preventDefault();let we=(K+(le.key==="ArrowLeft"||le.key==="ArrowUp"?-1:1)+ke.length)%ke.length,ge=ke[we];if(ge)ne(ge),A.current?.querySelectorAll(".home-memory-select")[we]?.focus({preventScroll:!0})},children:[r("span",{class:"graph-glyph","aria-hidden":"true"},void 0,!1,void 0,this),r("strong",{children:S.title},void 0,!1,void 0,this),r("span",{children:S.kind==="board"?`${S.nodeCount??0} cards · ${R.internal.get(S.boardId)??0} internal`:`${H(S.boardId)} · ${S.type??"card"}`},void 0,!1,void 0,this),r("span",{class:We?"memory-context-legend":"",children:We?"⌖ In context":S.folder||"Unfiled"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},S.key,!1,void 0,this)})]},void 0,!0,void 0,this),r("div",{class:"home-memory-zoom",children:[r("button",{type:"button",class:"home-button","aria-label":"Zoom out",onClick:()=>Te(ye.scale/1.2),children:"−"},void 0,!1,void 0,this),r("span",{children:[Math.round(ye.scale*100),"%"]},void 0,!0,void 0,this),r("button",{type:"button",class:"home-button","aria-label":"Zoom in",onClick:()=>Te(ye.scale*1.2),children:"+"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button",onClick:()=>N(),children:"Fit view"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(x||U||!t||!ke.length||o)&&r("div",{class:"home-memory-status",role:"status",children:x||(U?"This endpoint is no longer available. Use Back to return.":o?r(be,{children:["Memory update failed."," ",r("button",{type:"button",class:"home-button",onClick:i,children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):!t?"Loading memory…":Se.length?"No linked nodes in this view. Choose a node in No connections below.":"No matching nodes.")},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("aside",{class:"home-memory-sidebar","aria-label":"Graph settings",children:[r("section",{children:[r("h2",{children:c.kind==="overview"?"Find boards":"Find cards and neighbors"},void 0,!1,void 0,this),r("label",{class:"home-memory-search",children:[r("span",{children:"Search graph"},void 0,!1,void 0,this),r("input",{type:"search",value:l.query,placeholder:"Search this graph…",onInput:(S)=>j({query:S.currentTarget.value})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l.query&&r("ul",{class:"graph-search-results",children:[...ve,...D].filter(re).slice(0,30).map((S)=>r("li",{children:r("button",{type:"button",class:"home-button",onClick:()=>{if(Re.has(S.key)||S.key===te)ne(S);else Ce(S)},children:S.title},void 0,!1,void 0,this)},S.key,!1,void 0,this))},void 0,!1,void 0,this),Lt("Only in context",l.context,()=>j({context:!l.context}))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Folders"},void 0,!1,void 0,this),[...new Set(He.nodes.map((S)=>S.folder?.split("/")[0]??""))].sort().map((S)=>r("div",{children:Lt(S||"Unfiled",!l.folders.has(S),()=>{let K=new Set(l.folders);if(K.has(S))K.delete(S);else K.add(S);j({folders:K})})},S,!1,void 0,this))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Links"},void 0,!1,void 0,this),Object.keys(GT).map((S)=>r("div",{children:Lt(GT[S],!l.hiddenLinks.has(S),()=>{let K=new Set(l.hiddenLinks);if(K.has(S))K.delete(S);else K.add(S);j({hiddenLinks:K})})},S,!1,void 0,this))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Library evidence"},void 0,!1,void 0,this),r("p",{class:"graph-accounting",children:[R.evidence.length," links ·"," ",[...R.pairs.values()].reduce((S,K)=>S+K.edges.length,0)," between boards ·"," ",[...R.internal.values()].reduce((S,K)=>S+K,0)," inside boards ·"," ",R.missing.length," missing"]},void 0,!0,void 0,this),r("p",{class:"home-memory-help",children:"Counts retain original evidence. Folder membership is not a relation. Filters change the drawing, not the totals."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Se.length>0&&r("details",{class:"graph-unlinked",open:!0,children:[r("summary",{children:["No connections (",Se.length,")"]},void 0,!0,void 0,this),r("div",{children:Se.map((S)=>r("button",{type:"button",class:"home-button graph-tray-node","aria-label":`${S.kind}: ${S.title}`,onClick:()=>Ce(S),children:[S.title,r("small",{children:S.kind==="board"?`${S.nodeCount??0} cards`:H(S.boardId)},void 0,!1,void 0,this)]},S.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-legend","aria-label":"Legend",children:[r("span",{children:"Click nodes to drill · drag nodes to rearrange · lines for evidence · drag background to pan · scroll to zoom · Fit shows extent · search reveals at readable size"},void 0,!1,void 0,this),r("span",{class:"memory-context-legend",children:"⌖ In context"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(gp,{initiallyCollapsed:!0,reveal:m,children:O||me?r("section",{class:"home-memory-details",role:"complementary","aria-label":"Selection details",children:[me&&r("button",{type:"button",class:"home-memory-clear","aria-label":"Close details",onClick:()=>j({inspection:null}),children:"×"},void 0,!1,void 0,this),r("div",{class:"home-memory-detail-header",children:[r("div",{class:"home-memory-selection-title",children:[r("h3",{children:[me?`${he.get(me.from)?.title} ↔ ${he.get(me.to)?.title}`:Ie," ·"," ",at.length," connections"]},void 0,!0,void 0,this),r("p",{children:me?"Original evidence, not a new aggregate relation":`${O?.folder||"Unfiled"} / ${H(O.boardId)}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-actions",children:O&&r(be,{children:[r("button",{type:"button",class:"home-button is-primary",onClick:()=>void zt(O),children:["Open ",O.kind]},void 0,!0,void 0,this),Ft&&r(go,{board:Ft},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-detail-body",children:[O&&r("p",{class:O.inContext?"memory-context-legend":"",children:[O.inContext?"⌖ In context":"Not in context",O.linksComplete===!1?" · Partial discovery":""]},void 0,!0,void 0,this),r("details",{class:"home-memory-connections",open:!0,children:[r("summary",{children:["Connections",me?" within this pair":""]},void 0,!0,void 0,this),r("ul",{children:[at.map((S)=>{let K=c.kind==="card"?S.from===te:c.kind==="board"?S.source.boardId===c.boardId:!0,ue=K?S.target:S.source,Oe=he.get(Mt(ue)),We=ho({kind:S.relationKind,type:S.type},e.find((we)=>we.id===S.source.boardId)?.relationVocabulary),le=S.kind!=="card"||We.directed;return r("li",{children:[r("span",{children:[le?K?"→":"←":"↔"," ",S.kind==="card"?Ca({...S,kind:S.relationKind}):`${S.kind}${S.label?` · ${S.label}`:""}`]},void 0,!0,void 0,this),r("small",{children:[he.get(S.from)?.title??S.source.cardId??H(S.source.boardId)," ",le?"→":"↔"," ",he.get(S.to)?.title??S.target.cardId??H(S.target.boardId)," ·"," ",H(ue.boardId)]},void 0,!0,void 0,this),!Oe||S.missing?r("span",{class:"home-memory-missing",children:["⚠ Missing target: ",ue.boardId,ue.cardId?` / ${ue.cardId}`:""]},void 0,!0,void 0,this):r("button",{type:"button",class:"home-button",onClick:()=>Ce(Oe),children:["Follow ",Oe.title]},void 0,!0,void 0,this)]},S.id,!0,void 0,this)}),(t?.unresolvedLinks??[]).filter((S)=>c.kind==="board"?S.source.boardId===c.boardId:Mt(S.source)===te).map((S)=>r("li",{class:"home-memory-missing",children:["⚠ Unresolved wiki: [[",S.ref,"]]"]},`${Mt(S.source)}:${S.ref}`,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):r("div",{class:"home-memory-empty-details",children:[r("h3",{children:"Connections"},void 0,!1,void 0,this),r("p",{class:"home-memory-help",children:"Click a board to explore, then a card to see its exact neighbors. Click a connection line to read the original evidence. Open content is always separate."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},"inspector",!1,void 0,this)]},void 0,!0,void 0,this)}function VT({folder:e,folders:t,onScopeChange:n}){let[o,i]=E(""),[s,a]=E(!1),[l,c]=E(null),[u,d]=E(""),p=Be.value;G(()=>{if(p)Kt()},[p]),$e(()=>{let C=(y)=>{if(!Be.value)return;if(!ar(y))return;y.preventDefault(),i(""),a(!1)};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[]);let m=Jn.value,f=(C)=>!e||C===e||!!C?.startsWith(`${e}/`),h=(m?.reviewCards??[]).filter((C)=>f(C.folder)),g=o.trim().toLocaleLowerCase(),v=h.filter((C)=>{let y=m?.cards[Mt(C)];return y&&(!s||y.sources.length>0)&&(!g||`${C.title} ${C.boardTitle} ${y.reasons.join(" ")} ${y.sources.map((k)=>k.title).join(" ")}`.toLocaleLowerCase().includes(g))}),b=new Set(Ge.value.filter((C)=>f(C.folder)).map((C)=>C.id)),x=Object.entries(m?.cards??{}).filter(([C,y])=>!y.retired&&y.unknown&&b.has(JSON.parse(C)[0])).length;if(!p)return null;return r("section",{class:"home-review-view","aria-label":"Card review queue",children:[r("div",{class:"home-main-head",children:[r("div",{class:"home-main-title",children:[r("h1",{class:"home-view-title",children:"Knowledge review"},void 0,!1,void 0,this),r("p",{children:e?`${e} and descendants`:"Whole library"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("label",{children:["Review scope",r("select",{value:e,onChange:(C)=>n(C.currentTarget.value),children:[r("option",{value:"",children:"Whole library"},void 0,!1,void 0,this),t.map((C)=>r("option",{value:C,children:[C," and descendants"]},C,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-review-controls",children:[r("label",{children:["Find review cards",r("input",{type:"search",value:o,onInput:(C)=>i(C.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("label",{children:[r("input",{type:"checkbox",checked:s,onChange:(C)=>a(C.currentTarget.checked)},void 0,!1,void 0,this),"Source warnings only"]},void 0,!0,void 0,this),r("button",{type:"button",class:"home-button",onClick:()=>void Kt(),children:"Refresh queue"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ui.value&&r("p",{role:"status",children:"Queue unavailable. Retained results may be out of date. Refresh to retry."},void 0,!1,void 0,this),u&&r("p",{role:"alert",children:u},void 0,!1,void 0,this),!m?r("p",{children:"Loading review cards…"},void 0,!1,void 0,this):r(be,{children:[r("p",{class:"home-review-count",children:["Review needed: ",h.length," ",h.length===1?"card":"cards"," · Showing ",v.length]},void 0,!0,void 0,this),r("table",{class:"home-review-table",children:[r("thead",{children:r("tr",{children:[r("th",{children:"Card"},void 0,!1,void 0,this),r("th",{children:"Board"},void 0,!1,void 0,this),r("th",{children:"Why review"},void 0,!1,void 0,this),r("th",{children:"Last checked"},void 0,!1,void 0,this),r("th",{children:"Open"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),r("tbody",{children:v.map((C)=>{let y=Mt(C),k=m.cards[y],_=[...k.reasons,...k.sources.map((A)=>`${A.title}: ${A.reasons.join(" ")||"Source needs review."}`)];return r("tr",{children:[r("td",{"data-label":"Card",children:C.title},void 0,!1,void 0,this),r("td",{"data-label":"Board",children:C.boardTitle},void 0,!1,void 0,this),r("td",{"data-label":"Why review",children:_.join(" ")||"A source needs review."},void 0,!1,void 0,this),r("td",{"data-label":"Last checked",children:k.lastValidatedAt?new Date(k.lastValidatedAt).toLocaleString():"Never checked"},void 0,!1,void 0,this),r("td",{children:r("button",{type:"button",class:"home-button",disabled:l===y,"aria-label":`Open review: ${C.title} on ${C.boardTitle}`,onClick:async()=>{if(!Be.value)return;c(y),d("");let A=await zt(C,{review:!0});if(c(null),!A)d("Review did not open. The card may have moved or navigation was cancelled. Refresh and try again.")},children:"Open review"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},y,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v.length===0&&r("p",{children:"No actionable cards in these filters."},void 0,!1,void 0,this),r("p",{class:"home-review-neutral",children:["No review policy: ",x," ",x===1?"card":"cards",". Missing policy is neutral, not overdue. Explicit content or source warnings still enter the queue."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var YL=Li({decayType:rn(["reality","decision","dependency","relevance"]),rate:rn(["fast","medium","slow","durable"]),triggers:Pe(z().trim().min(1)),revalidationMethod:z().trim().min(1),cadenceDays:Ee().int().min(1).max(36500).optional()}).refine((e)=>e.rate!=="medium"||e.cadenceDays!==void 0,{path:["cadenceDays"],message:"Medium lifecycle requires a cadence in days."}),XT=YL.safeExtend({id:z().trim().min(1),name:z().trim().min(1),glyph:z().trim().min(1)});var lr=(e,t,n,o,i,s)=>({id:e,name:t,glyph:n,decayType:o,rate:i,revalidationMethod:s,triggers:[],...i==="medium"?{cadenceDays:90}:{}}),JT=lr("research","Research","⌕","reality","medium","Check the sources and conflicting evidence."),YT=lr("metric","Metric","▥","reality","fast","Re-read the source dashboard and compare."),QT=lr("decision","Decision","⚑","decision","durable","Check for a superseding decision and changed dependencies."),eI=lr("notes","Notes","✎","relevance","slow","Check relevance to the resumed task."),bp={"Org · team · personal":{categories:[lr("strategy","Strategy","◎","relevance","slow","Check the current goals and decisions."),lr("policy","Policy","◇","decision","slow","Check with the policy owner."),QT,JT,YT,eI],folders:{Org:"strategy","Org/Policies":"policy",Team:"research","Team/Decisions":"decision","Team/Metrics":"metric",Personal:"notes"}},"Solo research":{categories:[lr("question","Question","?","relevance","slow","Check whether this question still matters."),lr("source","Source","▤","reality","medium","Re-read the original source."),lr("finding","Finding","◉","dependency","durable","Compare the supporting and contradicting evidence."),lr("note","Note","✎","relevance","slow","Check relevance to the resumed task.")],folders:{Projects:"question","Projects/Findings":"finding",Sources:"source",Notes:"note"}},"Product team":{categories:[JT,YT,QT,eI],folders:{Discovery:"research","Discovery/Metrics":"metric",Delivery:"notes",Decisions:"decision"}},Empty:{categories:[],folders:{}}};function tI({folder:e,onClose:t}){let n=Be.value,o=F(null),i=Jn.value,s=i?.folders.find((O)=>O.path===e),a=e?i?.resolvedFolders[e]:null,[l,c]=E(s?.categoryId??""),[u,d]=E(!!s?.lifecycleOverride),[p,m]=E(s?.lifecycleOverride??a?.lifecycle??Ra),[f,h]=E(()=>i?.categories[0]?structuredClone(i.categories[0]):null),[g,v]=E(null),b=i?.categories.find((O)=>O.id===f?.id),x=i?.folders.filter((O)=>O.categoryId===f?.id)??[],[C,y]=E(!1),[k,_]=E(""),[A,w]=E(()=>JSON.stringify(f)),[M,B]=E("Basics"),[L,Y]=E(""),[j,J]=E(null),X=!e&&JSON.stringify(f)!==A,V=(O)=>{if(!Be.value||C||j)return;if(X)J(()=>O);else O()},ee=()=>{if(!Be.value)return;if(j)J(null);else if(g)v(null);else V(t)};bn(o,n,{onEscape:ee}),$e(()=>{if(!n&&o.current?.contains(document.activeElement))document.querySelector('button[aria-label="Settings"]')?.focus({preventScroll:!0})},[n]),G(()=>{if(n)Kt()},[n]);let he=(O)=>{let H=structuredClone(O);h(H),w(JSON.stringify(H)),B("Basics"),v(null),_("")},R=async(O,H)=>{if(!Be.value)return!1;return(await pe("knowledgeWrite",`/api/canvas/knowledge/${O}`,null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(H)}))?.ok===!0},te=async(O)=>{if(!Be.value||C||!i)return;let H=tn;y(!0),_("");let Me=!0,je=bp[O];for(let He of je.categories){if(!Be.value||H!==tn){Me=!1;break}if(!i.categories.some((Re)=>Re.id===He.id))Me=await R("category",{category:He});if(!Me)break}if(Me)for(let[He,Re]of Object.entries(je.folders)){if(!Be.value||H!==tn){Me=!1;break}if(!i.folders.some((ve)=>ve.path===He))Me=await R("folder",{path:He,categoryId:Re,lifecycleOverride:null});if(!Me)break}await Kt(),y(!1),_(Me?O==="Empty"?"No starter data added. Existing data is unchanged.":"Starter data added. Existing categories and folder settings were preserved.":"Template stopped at a failed save. Saved entries remain; retry adds only missing entries.")};return r("div",{class:"knowledge-backdrop",hidden:!n,style:n?void 0:{display:"none"},onKeyDown:(O)=>{if(O.key==="Escape")O.stopPropagation(),O.preventDefault(),ee()},children:r("div",{ref:o,class:`knowledge-dialog${e?"":" is-category-editor"}`,role:"dialog","aria-modal":"true","aria-label":e?"Folder settings":"Categories",children:[r("header",{children:[r("div",{class:"knowledge-dialog-title",children:[r("h2",{children:e?`${e.split("/").at(-1)} · Folder settings`:"Workspace categories"},void 0,!1,void 0,this),e&&r("span",{class:"knowledge-folder-path",children:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button","aria-label":"Close settings",disabled:C,onClick:()=>V(t),children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k&&r("p",{role:"status",children:k},void 0,!1,void 0,this),j&&r("div",{role:"group","aria-label":"Discard category changes",class:"category-discard",children:[r("p",{children:"Discard unsaved category changes?"},void 0,!1,void 0,this),r("button",{type:"button",onClick:()=>J(null),children:"Keep editing"},void 0,!1,void 0,this),r("button",{type:"button",onClick:()=>{if(!Be.value)return;let O=j;J(null),w(JSON.stringify(f)),O()},children:"Discard changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!i?r("p",{children:"Knowledge settings unavailable. Close and retry."},void 0,!1,void 0,this):e?r("form",{onClick:jo,onSubmit:async(O)=>{if(O.preventDefault(),!Be.value||C)return;let H=tn;y(!0);let Me=await R("folder",{path:e,categoryId:l||null,lifecycleOverride:u?pc(p):null});if(await Kt(),y(!1),Me&&Be.value&&H===tn)t();else if(!Me)_("Folder settings were not saved. Retry.")},children:[r("div",{class:"knowledge-field",children:[r("span",{children:"Category"},void 0,!1,void 0,this),r(Or,{label:"Category",value:l,onChange:c,options:[{value:"",label:"Use the parent’s"},...i.categories.map((O)=>({value:O.id,label:`${O.glyph} ${O.name}`}))]},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("p",{children:["Currently"," ",a?.category?`${a.category.glyph} ${a.category.name} · ${a.categorySourceFolder===e?"set here":`inherited from ${a.categorySourceFolder}`}`:"unknown",". Cards inherit their category; only lifecycle can be overridden."]},void 0,!0,void 0,this),r("label",{children:[r("input",{type:"checkbox",checked:u,onChange:(O)=>d(O.currentTarget.checked)},void 0,!1,void 0,this)," ","Override lifecycle for this folder"]},void 0,!0,void 0,this),u?r(dc,{value:p,onChange:m},void 0,!1,void 0,this):r("p",{children:"Lifecycle comes from the selected category or parent. Unknown has no passive expiry."},void 0,!1,void 0,this),r("button",{type:"submit",disabled:C,children:"Save folder settings"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r(be,{children:[r("details",{class:"category-templates",children:[r("summary",{children:"Add from template"},void 0,!1,void 0,this),r("div",{class:"knowledge-presets",children:Object.entries(bp).map(([O,H])=>r("button",{type:"button",disabled:C||!!j,onClick:()=>V(()=>{if(X)h(b?structuredClone(b):null),w(JSON.stringify(b??null));te(O)}),children:[r("strong",{children:O},void 0,!1,void 0,this),r("span",{children:Object.keys(H.folders).join(" / ")||"No folders or categories"},void 0,!1,void 0,this)]},O,!0,void 0,this))},void 0,!1,void 0,this),r("p",{children:"Templates add missing data. They never replace your existing settings. Rename any category below."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"category-editor-columns",children:[r("section",{class:"category-list-panel",children:[r("h3",{children:[i.categories.length," categories"]},void 0,!0,void 0,this),r("label",{children:["Search categories",r("input",{type:"search",value:L,onInput:(O)=>Y(O.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",disabled:C,onClick:()=>V(()=>he({...Ra,id:crypto.randomUUID(),name:"",glyph:"◇"})),children:"Add category"},void 0,!1,void 0,this),r("div",{class:"category-library",role:"group","aria-label":"Workspace categories",children:i.categories.filter((O)=>O.name.toLocaleLowerCase().includes(L.toLocaleLowerCase())).map((O)=>r("button",{type:"button",class:"category-choice",disabled:C,"aria-pressed":f?.id===O.id,onClick:()=>{if(f?.id!==O.id)V(()=>he(O))},children:[r("strong",{children:[O.glyph," ",O.name]},void 0,!0,void 0,this),r("span",{children:[O.decayType," · ",O.rate,O.rate==="medium"&&O.cadenceDays?` · ${O.cadenceDays} days`:""]},void 0,!0,void 0,this)]},O.id,!0,void 0,this))},void 0,!1,void 0,this),r("p",{children:"Folders with no category above them stay unknown. Categories carry no colour."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f&&r("form",{class:"category-inspector",noValidate:!0,onClick:jo,onSubmit:async(O)=>{if(O.preventDefault(),!Be.value||C)return;let H=tn,Me=XT.safeParse({...f,...pc(f)});if(!Me.success){let Re=String(Me.error.issues[0].path[0]);B(["name","glyph","id"].includes(Re)?"Basics":"Review policy"),_(Me.error.issues[0].message),setTimeout(()=>{if(!Be.value||H!==tn)return;let ve=Re==="name"?"Name":Re==="glyph"?"Glyph":Re==="cadenceDays"?"Cadence in days":"How to check",D=o.current?.querySelectorAll("label");Array.from(D??[]).find((re)=>re.textContent?.trim().startsWith(ve))?.querySelector("input")?.focus()},0);return}y(!0);let je=await pe("knowledgeWrite","/api/canvas/knowledge/category",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({category:Me.data})}),He=je?.ok===!0;if(await Kt(),y(!1),!Be.value||H!==tn)return;if(He){let Re=je?.category??Me.data;h(Re),w(JSON.stringify(Re))}_(He?"Category saved. Inheriting folders now use these defaults.":"Category was not saved. Retry.")},children:[r("h3",{children:b?"Edit category defaults":"New category"},void 0,!1,void 0,this),r("div",{role:"tablist","aria-label":"Category settings",class:"category-tabs",children:["Basics","Review policy","Usage"].map((O)=>r("button",{type:"button",role:"tab",id:`category-tab-${O.replace(" ","-")}`,"aria-controls":"category-tab-panel","aria-selected":M===O,onClick:()=>B(O),children:O},O,!1,void 0,this))},void 0,!1,void 0,this),r("fieldset",{disabled:C||!!j,id:"category-tab-panel",role:"tabpanel","aria-labelledby":`category-tab-${M.replace(" ","-")}`,class:"category-tab-content",children:[M==="Basics"&&r(be,{children:[r("label",{children:["Name",r("input",{required:!0,value:f.name,onInput:(O)=>h({...f,name:O.currentTarget.value})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("label",{children:["Glyph",r("input",{required:!0,value:f.glyph,onInput:(O)=>h({...f,glyph:O.currentTarget.value})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"category-glyph-choices",role:"group","aria-label":"Glyph choices",children:[...new Set(Object.values(bp).flatMap((O)=>O.categories.map((H)=>H.glyph)))].map((O)=>r("button",{type:"button","aria-label":`Choose glyph ${O}`,"aria-pressed":f.glyph===O,onClick:()=>h({...f,glyph:O}),children:O},O,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M==="Review policy"&&r(dc,{value:f,onChange:(O)=>h({...f,...O})},void 0,!1,void 0,this),M==="Usage"&&r(be,{children:[r("p",{children:"Folders inherit these defaults. Folder settings and card lifecycle overrides remain unchanged. Unknown has no passive expiry."},void 0,!1,void 0,this),x.length===0&&r("p",{children:"No folders assigned."},void 0,!1,void 0,this),b&&(x.length>0?r("p",{children:["Cannot delete: assigned to ",x.map((O)=>O.path).join(", "),". Reassign or clear those folder categories first. Empty folders also count."]},void 0,!0,void 0,this):g===b.id?r("div",{role:"group","aria-label":"Confirm category deletion",children:[r("p",{children:["Delete ",b.name,"? This removes the category from this workspace."]},void 0,!0,void 0,this),r("button",{type:"button",disabled:C,onClick:()=>v(null),children:"Cancel deletion"},void 0,!1,void 0,this),r("button",{type:"button",class:"is-danger",disabled:C,onClick:async()=>{if(!Be.value||C)return;let O=tn;y(!0);let H=await pe("knowledgeRemove",`/api/canvas/knowledge/category/${encodeURIComponent(b.id)}`,null,{method:"DELETE"});if(await Kt(),y(!1),!Be.value||O!==tn)return;if(v(null),H?.ok===!0)h(null),w("null");_(H?.ok===!0?"Category deleted.":H?.error??"Category was not deleted. Retry.")},children:"Confirm deletion"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r("button",{type:"button",class:"is-danger",disabled:C,onClick:()=>v(b.id),children:"Delete category"},void 0,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("footer",{class:"category-editor-footer",children:[r("button",{type:"button",disabled:C||!!j,onClick:()=>V(t),children:"Cancel"},void 0,!1,void 0,this),r("button",{type:"submit",disabled:C||!!j,children:"Save category"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function nI({onClose:e}){let t=F(null),n=Jn.value?.relationPresets,[o,i]=E(),s=o===void 0?n?.[0]??null:o,[a,l]=E(null),[c,u]=E(null),[d,p]=E(null),[m,f]=E(""),[h,g]=E(!1),[v,b]=E(""),[x,C]=E(!1),y=F(null);G(()=>{if(!d)return;let L=document.activeElement;return y.current?.querySelector("button")?.focus(),()=>{if(L instanceof HTMLElement&&L.isConnected)L.focus()}},[d]);let k=s,_=a!==null&&JSON.stringify(a)!==JSON.stringify(c),A=(L)=>{if(h)return;if(_)p(()=>L);else L()},w=()=>{if(d)p(null);else if(x)C(!1);else A(e)};bn(t,!0,{onEscape:w});let M=(L)=>{i(L?structuredClone(L):null),l(null),u(null),C(!1),b("")},B=(L,Y)=>{if(a)l({...a,vocabulary:a.vocabulary.map((j,J)=>J===L?{...j,...Y}:j)})};return r("div",{class:"knowledge-backdrop",onKeyDown:(L)=>{if(L.key==="Escape")L.preventDefault(),L.stopPropagation(),w()},children:r("div",{ref:t,class:"knowledge-dialog is-category-editor relation-presets-dialog",role:"dialog","aria-modal":"true","aria-label":"Workspace relation presets",children:[r("header",{children:[r("h2",{children:"Workspace relation presets"},void 0,!1,void 0,this),r("button",{type:"button",disabled:h||!!d,"aria-label":"Close relation presets",onClick:()=>A(e),children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("p",{children:"Saved templates are shared across the workspace. Saving does not apply a preset to any board."},void 0,!1,void 0,this),v&&r("p",{role:"status",children:v},void 0,!1,void 0,this),d&&r("div",{ref:y,role:"alertdialog","aria-label":"Discard preset changes","aria-modal":"true",class:"relation-dirty-guard",children:[r("p",{children:"Discard unsaved preset changes?"},void 0,!1,void 0,this),r("button",{type:"button",onClick:()=>p(null),children:"Keep editing"},void 0,!1,void 0,this),r("button",{type:"button",onClick:()=>{let L=d;p(null),L()},children:"Discard changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{inert:d?!0:void 0,children:!n?r("p",{children:"Relation presets unavailable. Close and retry."},void 0,!1,void 0,this):r("div",{class:"category-editor-columns",children:[r("section",{children:[r("h3",{children:[n.length," presets"]},void 0,!0,void 0,this),r("button",{type:"button",disabled:h,onClick:()=>A(()=>{M(null);let L={id:crypto.randomUUID(),name:"",vocabulary:[]};u(structuredClone(L)),l(L)}),children:"Add preset"},void 0,!1,void 0,this),r("div",{class:"category-library",role:"group","aria-label":"Workspace relation presets",children:n.map((L)=>r("button",{type:"button",class:"category-choice",disabled:h,"aria-pressed":(a?.id??s?.id)===L.id,onClick:()=>A(()=>M(L)),children:[r("strong",{children:L.name},void 0,!1,void 0,this),r("span",{children:L.vocabulary.map((Y)=>Y.kind).join(" · ")||"No relation kinds"},void 0,!1,void 0,this)]},L.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("section",{class:"relation-preset-detail",children:a?r("form",{class:"relation-vocabulary",onClick:jo,onSubmit:async(L)=>{if(L.preventDefault(),h)return;if(new Set(a.vocabulary.map((j)=>j.kind.trim())).size!==a.vocabulary.length){b("Give each relation kind a unique name.");return}g(!0);let Y=await pe("relationPresetWrite","/api/canvas/knowledge/relation-preset",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({preset:a})});if(await Kt(),g(!1),Y?.ok)M(Y.preset);b(Y?.ok?"Preset saved for the workspace. Existing boards are unchanged.":"Preset was not saved. Retry.")},children:[r("h3",{children:s?"Customize shared preset":"New shared preset"},void 0,!1,void 0,this),r("label",{children:["Name",r("input",{required:!0,pattern:".*\\S.*",maxLength:80,disabled:h,value:a.name,onInput:(L)=>l({...a,name:L.currentTarget.value})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("p",{children:"Kinds stay open. Choose meaning ink and direction, not pin, agent or warning colours."},void 0,!1,void 0,this),a.vocabulary.map((L,Y)=>r("div",{class:"vocabulary-row",children:[r("input",{required:!0,pattern:".*\\S.*","aria-label":`Kind ${Y+1}`,maxLength:80,disabled:h,value:L.kind,onInput:(j)=>B(Y,{kind:j.currentTarget.value})},void 0,!1,void 0,this),r("select",{"aria-label":`Ink ${Y+1}`,disabled:h,value:L.ink,onChange:(j)=>B(Y,{ink:j.currentTarget.value}),children:["supports","contradicts","cites","derived","informs","related"].map((j)=>r("option",{children:j},j,!1,void 0,this))},void 0,!1,void 0,this),r("label",{children:[r("input",{type:"checkbox",disabled:h,checked:L.directed,onChange:(j)=>B(Y,{directed:j.currentTarget.checked})},void 0,!1,void 0,this),"Arrow"]},void 0,!0,void 0,this),r("button",{type:"button","aria-label":`Remove kind ${Y+1}`,disabled:h,onClick:()=>l({...a,vocabulary:a.vocabulary.filter((j,J)=>J!==Y)}),children:"×"},void 0,!1,void 0,this)]},Y,!0,void 0,this)),r("button",{type:"button",disabled:h||a.vocabulary.length>=64,onClick:()=>l({...a,vocabulary:[...a.vocabulary,{kind:"",ink:"related",directed:!0}]}),children:"Add kind"},void 0,!1,void 0,this),r("div",{class:"relation-preset-footer",children:[r("button",{type:"submit",disabled:h,children:"Save preset"},void 0,!1,void 0,this),r("button",{type:"button",disabled:h,onClick:()=>A(()=>M(s)),children:"Cancel customization"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):k?r(be,{children:[r("h3",{children:k.name},void 0,!1,void 0,this),r("p",{children:"Saved relations · read-only example"},void 0,!1,void 0,this),r("p",{children:"Use on board replaces only the chosen board’s vocabulary. Matching connections use its ink and direction; connection records are not rewritten."},void 0,!1,void 0,this),r("ul",{class:"relation-preset-preview","aria-label":"Saved relation preview",children:k.vocabulary.map((L)=>r("li",{style:{"--relation-ink":`var(--c-rel-${L.ink})`},children:[r("strong",{children:L.kind},void 0,!1,void 0,this),r("div",{class:"relation-preset-example",children:[r("span",{children:"Example A"},void 0,!1,void 0,this),r("svg",{viewBox:"0 0 120 24","aria-hidden":"true",children:[r("line",{x1:"8",y1:"12",x2:"112",y2:"12",stroke:"currentColor","stroke-width":"2","stroke-dasharray":L.ink==="related"?"3 5":void 0},void 0,!1,void 0,this),L.directed&&r("path",{d:"M 102 6 L 112 12 L 102 18",fill:"none",stroke:"currentColor","stroke-width":"2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{children:"Example B"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{children:[L.ink," · ",L.directed?"Directed: A → B":"Undirected: A — B"]},void 0,!0,void 0,this)]},L.kind,!0,void 0,this))},void 0,!1,void 0,this),!k.vocabulary.length&&r("p",{children:"No relation kinds. This empty preset can still be used on a board."},void 0,!1,void 0,this),r("div",{class:"relation-preset-footer",children:k&&r(be,{children:[r("label",{children:["Apply saved preset to board",r("select",{"aria-label":"Apply saved preset to board",disabled:h,value:m,onChange:(L)=>f(L.currentTarget.value),children:[r("option",{value:"",children:"Choose a board"},void 0,!1,void 0,this),Ge.value.map((L)=>r("option",{value:L.id,children:L.name},L.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",class:"relation-preset-use",disabled:h||!m,onClick:async()=>{if(h||!m)return;g(!0);let L=await Sr(m,{relationVocabulary:k.vocabulary});g(!1),b(L?"Preset applied. Connection records and other boards are unchanged.":"Preset was not applied. Retry.")},children:"Use on board"},void 0,!1,void 0,this),r("button",{type:"button",disabled:h,onClick:()=>{u(structuredClone(k)),l(structuredClone(k)),C(!1),b("")},children:"Customize preset"},void 0,!1,void 0,this),x?r("div",{role:"group","aria-label":"Confirm preset deletion",children:[r("p",{children:["Delete ",k.name,"? Boards that used it keep their existing vocabulary."]},void 0,!0,void 0,this),r("button",{type:"button",disabled:h,onClick:()=>C(!1),children:"Cancel deletion"},void 0,!1,void 0,this),r("button",{type:"button",class:"is-danger",disabled:h,onClick:async()=>{if(h)return;g(!0);let L=await pe("relationPresetRemove",`/api/canvas/knowledge/relation-preset/${encodeURIComponent(k.id)}`,null,{method:"DELETE"});if(await Kt(),g(!1),C(!1),L?.ok)M(null);b(L?.ok?"Preset deleted. Existing boards are unchanged.":"Preset was not deleted. Retry.")},children:"Confirm deletion"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r("button",{type:"button",class:"is-danger",disabled:h,onClick:()=>C(!0),children:"Delete preset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r("p",{children:"Choose a saved preset or add a new one."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function oI(e){if(!e)return"never opened";if((Date.now()-new Date(e).getTime())/86400000>=30)return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});return cp(e)}var cr=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function rI(e){return(e.links?.length??0)+(e.backlinks?.length??0)}async function Dg(e){let t=await On("New board","Board name",{confirm:"Create"});if(t)await nS(t,e)}var iI="pmx-canvas-home-collapsed";function QL(){try{let e=localStorage.getItem(iI);if(e)return new Set(JSON.parse(e))}catch{}return new Set([$T])}function eO(e){try{localStorage.setItem(iI,JSON.stringify([...e]))}catch{}}var gc=(e,t)=>e.folder===t||!!e.folder?.startsWith(`${t}/`),ur=(e)=>e.split("/").at(-1)??e;function tO({board:e}){return r("div",{class:"home-thumb","aria-hidden":"true",children:r("div",{class:"home-thumb-inner",children:(e.preview??[]).map((t,n)=>r("span",{class:`home-thumb-card${t.pinned?" is-pinned":""}`,style:{left:`${t.x*100}%`,top:`${t.y*100}%`,width:`${t.w*100}%`,height:`${t.h*100}%`}},n,!1,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function sI(){let e=Ge.value,t=Be.value,[n,o]=E("Folders"),i=!t&&n==="Review"?"Folders":n,[s,a]=E(()=>[...Ge.value].sort((Ie,S)=>(S.lastOpenedAt??"").localeCompare(Ie.lastOpenedAt??""))[0]?.folder??""),[l,c]=E([]),[u,d]=E(null),[p,m]=E(!1),[f,h]=E(null),[g,v]=E(!1),[b,x]=E(!1),[C,y]=E(null),[k,_]=E(null),[A,w]=E(""),[M,B]=E([]),[L,Y]=E(QL),[j,J]=E(!1),[X,V]=E(!1),ee=F(null),he=F(null),R=[...new Set([...e.flatMap((U)=>U.folder?fc(U.folder):[]),...(Jn.value?.folders??[]).flatMap((U)=>fc(U.path)),...l.flatMap(fc)])].sort((U,Ie)=>U.localeCompare(Ie)),te=(U)=>R.filter((Ie)=>U?Ie.startsWith(`${U}/`)&&!Ie.slice(U.length+1).includes("/"):!Ie.includes("/")),O=A.trim().toLocaleLowerCase(),H=e.filter((U)=>U.pin),Me=H.reduce((U,Ie)=>U+(Ie.mapChars??0),0),je=te(s),He=e.filter((U)=>(U.folder??"")===s).sort((U,Ie)=>(Ie.lastOpenedAt??"").localeCompare(U.lastOpenedAt??"")),Re=O?e.filter((U)=>`${U.name} ${U.folder??""}`.toLocaleLowerCase().includes(O)):[],ve=e.find((U)=>U.id===f)??null,D=e.find((U)=>U.id===C),re=e.find((U)=>U.id===k),ze=new Set(e.filter((U)=>!s||gc(U,s)).map((U)=>U.id)),ke=Object.entries(Jn.value?.cards??{}).filter(([U])=>ze.has(JSON.parse(U)[0])).map(([,U])=>U),ae=ke.filter((U)=>!U.retired&&(U.due||U.sources.length)).length,Se=ke.filter((U)=>U.unknown).length,de=Jn.value?.resolvedFolders[s]?.category,Ze=new Map;for(let[U,Ie]of Object.entries(Jn.value?.cards??{})){if(Ie.retired||!(Ie.due||Ie.sources.length))continue;let[S,K]=JSON.parse(U),ue=Ze.get(S)??[];ue.push(K),Ze.set(S,ue)}let xe=O?Re:He,Ke=async(U)=>{if(!Be.value)return;let Ie=tn,S=Ze.get(U)?.[0];if(!S)return;if(await zt({boardId:U,cardId:S})&&Be.value&&Ie===tn&&ie.value===U)No.value="To review"};G(()=>{let U=A.trim();if(!U){B([]);return}let Ie=!1,S=window.setTimeout(()=>{pe("searchLibrary",`/api/canvas/search?q=${encodeURIComponent(U)}&scope=library&limit=30`,null).then((K)=>{if(!Ie)B(K?.results??[])})},150);return()=>{Ie=!0,window.clearTimeout(S)}},[A]),G(()=>{if(g)he.current?.querySelector('[role="menuitem"]')?.focus()},[g]),G(()=>{if(f&&!e.some((U)=>U.id===f))h(null)},[e,f]),$e(()=>{if(i!=="Folders"||!f)return;let U=(Ie)=>{if(!ar(Ie))return;Ie.preventDefault(),h(null),x(!1)};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[i,f]);let q=(U)=>zt(U),ye=(U)=>{let Ie=new Set(L);if(Ie.has(U))Ie.delete(U);else Ie.add(U);Y(Ie),eO(Ie)},Ue=(U)=>{a(U),w(""),h(null),J(!1)},N=(U)=>{h(U),v(!1),x(!1)},ne=async()=>{let U=await On("New folder","Folder name",{confirm:"Create"});if(!U)return;let Ie;try{Ie=hp(s?`${s}/${U}`:U)}catch{return}if(!Ie)return;c((S)=>[...S,Ie]),Ue(Ie)},Ce=async(U)=>{let Ie=await On("Rename board","Board name",{initial:U.name,confirm:"Rename"});if(Ie&&Ie!==U.name)await Sr(U.id,{name:Ie})},Te=(U,Ie)=>{let S=te(U),K=!L.has(U),ue=e.filter((We)=>gc(We,U)).length,Oe=e.some((We)=>We.pin&&gc(We,U));return r("li",{children:[r("div",{class:`home-tree-row${s===U&&!O?" is-selected":""}`,"data-folder":U,children:[r("span",{class:"home-tree-indent",style:{width:`${Ie*16}px`}},void 0,!1,void 0,this),S.length>0?r("button",{type:"button",class:"home-tree-chevron","aria-label":K?`Fold ${ur(U)}`:`Unfold ${ur(U)}`,"aria-expanded":K,onClick:()=>ye(U),children:K?r(oa,{},void 0,!1,void 0,this):r(di,{},void 0,!1,void 0,this)},void 0,!1,void 0,this):r("span",{class:"home-tree-chevron"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-tree-name",onClick:()=>Ue(U),children:ur(U)},void 0,!1,void 0,this),Oe&&r("span",{class:"home-tree-pin","aria-label":"Has a board in the agent's context"},void 0,!1,void 0,this),r("span",{class:"home-tree-count",children:ue},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K&&S.length>0&&r("ul",{class:"home-tree",children:S.map((We)=>Te(We,Ie+1))},void 0,!1,void 0,this)]},U,!0,void 0,this)},me=r("ul",{class:"home-tree","aria-label":"Folders",children:[te("").map((U)=>Te(U,0)),r("li",{children:r("div",{class:`home-tree-row is-unfiled${s===""&&!O?" is-selected":""}`,children:[r("span",{class:"home-tree-chevron"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-tree-name",onClick:()=>Ue(""),children:"Unfiled"},void 0,!1,void 0,this),r("span",{class:"home-tree-count",children:e.filter((U)=>!U.folder).length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),at=r("ul",{class:"home-pinned","aria-label":"Pinned boards",children:H.map((U)=>r("li",{children:r("button",{type:"button",class:"home-pinned-row",onClick:()=>Ue(U.folder??""),children:[r("span",{class:"home-pin-dot","aria-hidden":"true",children:r(mo,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"home-pinned-name",children:U.name},void 0,!1,void 0,this),r("span",{class:"home-tree-count",children:U.folder?ur(U.folder):"Unfiled"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},U.id,!1,void 0,this))},void 0,!1,void 0,this),Ft=r("label",{class:"home-search",children:[r(ld,{},void 0,!1,void 0,this),r("span",{class:"sr-only",children:"Find boards, cards and folders"},void 0,!1,void 0,this),r("input",{type:"search",placeholder:"Boards, cards, folders…",value:A,onInput:(U)=>w(U.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Qe=(U)=>r("li",{children:r("article",{class:`home-card${U.pin?" is-pinned":""}${f===U.id?" is-selected":""}`,"data-testid":"home-board","data-board-id":U.id,children:[r("button",{type:"button",class:"home-card-select","aria-label":U.name,"aria-pressed":f===U.id,onClick:()=>N(U.id),onDblClick:()=>void Mn(U.id),children:[r(tO,{board:U},void 0,!1,void 0,this),r("span",{class:"home-card-body",children:[r("span",{class:"home-card-name",children:U.name},void 0,!1,void 0,this),r("span",{class:"home-card-readme",children:U.summary??"No README yet."},void 0,!1,void 0,this),r("span",{class:"home-card-meta",children:[r("span",{children:cr(U.nodeCount,"card")},void 0,!1,void 0,this),rI(U)>0&&r("span",{children:["↔ ",cr(rI(U),"link")]},void 0,!0,void 0,this),r("span",{class:"home-card-when",children:oI(U.lastOpenedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),t&&Ze.has(U.id)&&r("button",{type:"button",class:"home-card-review","aria-label":`Review ${U.name}`,onClick:()=>void Ke(U.id),children:["⧗ Review ",cr(Ze.get(U.id).length,"card")]},void 0,!0,void 0,this),r(go,{board:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},U.id,!1,void 0,this),Lt=ve&&r("aside",{class:"home-details","aria-label":"Board details","data-testid":"home-details",children:[r("button",{type:"button",class:"home-details-grip","aria-label":"Close details",onClick:()=>N(null)},void 0,!1,void 0,this),r("div",{class:"home-details-head",children:[r("span",{class:"home-details-folder",children:ve.folder?ur(ve.folder):"Unfiled"},void 0,!1,void 0,this),r("span",{class:"home-details-name",children:ve.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:`home-details-context${ve.pin?" is-on":""}`,children:[r("span",{class:"home-details-context-text",children:r("span",{class:"home-details-context-label",children:ve.pin?"In the agent's context":"Not in the agent's context"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("button",{type:"button",role:"switch","aria-checked":!!ve.pin,"aria-label":"In the agent's context",class:"home-switch",onClick:()=>void Vs(ve.id,!ve.pin),children:r("span",{class:"home-switch-knob"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b?r("div",{class:"home-details-confirm",role:"alert",children:[r("span",{children:["Delete ",r("strong",{children:ve.name},void 0,!1,void 0,this)," and its ",cr(ve.nodeCount,"card")," and snapshots? This can't be undone."]},void 0,!0,void 0,this),r("span",{class:"home-details-actions",children:[r("button",{type:"button",class:"home-button",onClick:()=>x(!1),children:"Cancel"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button is-danger",onClick:()=>{x(!1),sS(ve.id)},children:"Delete board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):r("div",{class:"home-details-actions",children:[r("button",{type:"button",class:"home-button is-primary",onClick:()=>void Mn(ve.id),children:"Open board"},void 0,!1,void 0,this),t&&Ze.has(ve.id)&&r("button",{type:"button",class:"home-button",onClick:()=>void Ke(ve.id),children:"Review cards"},void 0,!1,void 0,this),r("span",{class:"home-more",children:[r("button",{ref:ee,type:"button",class:"home-button is-icon","aria-label":"More: move, rename, create from, delete","aria-haspopup":"menu","aria-expanded":g,onClick:()=>v(!g),children:r(Ol,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),g&&r("span",{ref:he,class:"home-more-menu",role:"menu",onKeyDown:(U)=>{let Ie=[...he.current?.querySelectorAll('[role="menuitem"]')??[]],S=Ie.indexOf(document.activeElement);if(U.key==="Escape")U.preventDefault(),v(!1),ee.current?.focus();else if(U.key==="ArrowDown"||U.key==="ArrowUp"){U.preventDefault();let K=U.key==="ArrowDown"?1:-1;Ie[(S+K+Ie.length)%Ie.length]?.focus()}},children:[["Move…",()=>y(ve.id)],["Rename…",()=>void Ce(ve)],["Create from…",()=>_(ve.id)],["Delete…",()=>x(!0)]].map(([U,Ie])=>r("button",{type:"button",role:"menuitem",class:"home-more-item",onClick:()=>{v(!1),Ie()},children:U},U,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return r("div",{class:"home-shell",children:[u!==null&&r(tI,{folder:u||void 0,onClose:()=>d(null)},u,!1,void 0,this),p&&r(nI,{onClose:()=>m(!1)},void 0,!1,void 0,this),r("nav",{class:"home-view-tabs","aria-label":"Library view",children:[["Folders","Map","Graph","Review"].filter((U)=>t||U!=="Review").map((U)=>r("button",{type:"button",class:"home-button","aria-pressed":i===U,onClick:()=>o(U),children:U},U,!1,void 0,this)),r("button",{type:"button",class:"home-button",onClick:()=>m(!0),children:"Relation presets"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i==="Map"||i==="Graph"?i==="Map"?r(HT,{},void 0,!1,void 0,this):r(KT,{},void 0,!1,void 0,this):r("div",{class:`home-view${ve&&i==="Folders"?" has-details":""}`,"data-testid":"home-view",children:[r("aside",{class:`home-library${j?" is-open":""}`,"aria-label":"Library",children:[r("div",{class:"home-library-head",children:[r("span",{class:"home-library-title",children:"Library"},void 0,!1,void 0,this),r("span",{class:"home-tree-count",children:cr(e.length,"board")},void 0,!1,void 0,this),t&&r("button",{type:"button",class:"home-button",onClick:()=>{if(Be.value)d("")},children:"Categories"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ft,H.length>0&&r("section",{class:"home-library-section",children:[r("span",{class:"home-section-label",children:"Pinned boards"},void 0,!1,void 0,this),at,r("span",{class:"home-pinned-cost",children:["≈ ",uc(Me)," tokens · ",cr(H.length,"board")]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("section",{class:"home-library-section is-folders",children:[r("span",{class:"home-section-label",children:"Folders"},void 0,!1,void 0,this),me,r("button",{type:"button",class:"home-tree-new",onClick:()=>void ne(),children:"+ New folder"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("main",{class:"home-main",children:[r("div",{class:"home-narrow",children:[Ft,H.length>0&&r(be,{children:[r("button",{type:"button",class:"home-narrow-context","aria-expanded":X,onClick:()=>V(!X),children:[r("span",{class:"home-pin-dot","aria-hidden":"true",children:r(mo,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"home-narrow-context-label",children:["In context: ",cr(H.length,"board")]},void 0,!0,void 0,this),r("span",{class:"home-narrow-context-cost",children:["≈ ",uc(Me)," tokens"]},void 0,!0,void 0,this),r("span",{children:X?"Hide ▴":"Show ▾"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&at]},void 0,!0,void 0,this),r("button",{type:"button",class:"home-narrow-picker","aria-expanded":j,onClick:()=>J(!j),children:[s?ur(s):"Library",r("span",{class:"home-tree-count",children:["· ",s?e.filter((U)=>gc(U,s)).length:He.length," ▾"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i==="Review"?r(VT,{folder:s,folders:R,onScopeChange:Ue},void 0,!1,void 0,this):r(be,{children:[r("div",{class:"home-main-head",children:[r("div",{class:"home-main-title",children:[r("nav",{class:"home-crumbs","aria-label":"Folder path",children:[r("button",{type:"button",onClick:()=>Ue(""),children:"Library"},void 0,!1,void 0,this),s&&fc(s).map((U)=>r("span",{children:[r("span",{class:"home-crumb-sep",children:"/"},void 0,!1,void 0,this),r("button",{type:"button",onClick:()=>Ue(U),children:ur(U)},void 0,!1,void 0,this)]},U,!0,void 0,this))]},void 0,!0,void 0,this),r("h1",{class:"home-view-title",children:O?`Results for “${A.trim()}”`:s?ur(s):"Library"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&r("button",{type:"button",class:"home-button",onClick:()=>{if(Be.value)d(s)},children:[" ",s?"Folder settings":"Categories"]},void 0,!0,void 0,this),r("button",{type:"button",class:"home-button is-primary",onClick:()=>void Dg(s||null),children:s?"New board here":"New board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&Jn.value&&!O&&r("section",{class:"home-main-section","aria-label":"Folder review summary",children:[r("span",{class:"home-section-label",children:["Card review · ",s?"In this folder and subfolders":"Across the library"]},void 0,!0,void 0,this),r("div",{class:"home-card-meta",children:[de&&r("span",{children:["Category: ",de.glyph," ",de.name]},void 0,!0,void 0,this),r("button",{type:"button",class:`home-review-link${ae?" has-review":""}`,onClick:()=>{o("Review"),h(null)},children:["Review needed: ",cr(ae,"card")]},void 0,!0,void 0,this),r("span",{children:["No review policy: ",cr(Se,"card")]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),e.length===0?r("div",{class:"home-view-empty",children:"No boards yet. Create one, or let an agent start writing — it opens one."},void 0,!1,void 0,this):O?r(be,{children:[M.length>0&&r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:["Cards · ",M.length]},void 0,!0,void 0,this),r("ul",{class:"home-hits","aria-label":"Library search results",children:M.map((U)=>r("li",{children:r("button",{type:"button",class:"home-hit",onClick:()=>void q(U),children:[r("span",{class:"home-card-name",children:U.title||U.boardTitle},void 0,!1,void 0,this),t&&U.qualification?.retired&&r("span",{class:"category-tag",children:"Retired"},void 0,!1,void 0,this),r("span",{class:"home-card-meta",children:[U.boardTitle," · ",U.snippet]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},`${U.boardId}:${U.cardId}`,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Re.length>0?r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:["Boards · ",Re.length]},void 0,!0,void 0,this),r("ul",{class:"home-cards",children:Re.map(Qe)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):M.length===0&&r("div",{class:"home-view-empty",role:"status",children:["No boards match “",A.trim(),"”."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):r(be,{children:[je.length>0&&r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:["Folders · ",je.length]},void 0,!0,void 0,this),r("ul",{class:"home-folders",children:je.map((U)=>{let Ie=e.filter((ue)=>gc(ue,U)),S=Ie.map((ue)=>ue.lastOpenedAt??"").sort().at(-1),K=Ie.filter((ue)=>ue.pin).length;return r("li",{children:r("button",{type:"button",class:"home-folder","data-testid":"home-section","data-folder":U,onClick:()=>Ue(U),children:[r("span",{class:"home-folder-stack","aria-hidden":"true",children:[r("span",{},void 0,!1,void 0,this),r("span",{},void 0,!1,void 0,this),r("span",{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K>0&&r("span",{class:"home-folder-context",children:[K," in context"]},void 0,!0,void 0,this),r("span",{class:"home-folder-name",children:ur(U)},void 0,!1,void 0,this),r("span",{class:"home-folder-meta",children:[cr(Ie.length,"board"),S?` · opened ${oI(S)}`:""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},U,!1,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:[s?`Boards in ${ur(s)}`:"Unfiled boards"," · ",xe.length]},void 0,!0,void 0,this),xe.length>0?r("ul",{class:"home-cards","aria-label":s?`Boards in ${s}`:"Unfiled boards",children:xe.map(Qe)},void 0,!1,void 0,this):r("div",{class:"home-view-empty",children:"No boards here yet."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i==="Folders"&&Lt,D&&r(LT,{board:D,folders:R,onClose:()=>y(null)},D.id,!1,void 0,this),re&&r(OT,{board:re,onClose:()=>_(null)},re.id,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var fs=se(!1);function nO(e){return e>=1048576?`${(e/1024/1024).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}function aI(){let[e,t]=E(!1),[n,o]=E(!1),[i,s]=E(null),[a,l]=E(null),[c,u]=E(!1),[d,p]=E(""),m=fs.value,f=ie.value;if(G(()=>{if(!m||!f)return;let g=!0;return l(null),p(""),s(null),pe("exportPreview",`/api/canvas/export/preview?board=${encodeURIComponent(f)}&includeFiles=${e}&includeDerivedText=${n}`,null).then((v)=>{if(g)s(v?.manifest??null)}),()=>{g=!1}},[m,e,n,f]),G(()=>{o(!1)},[m,f]),G(()=>{if(!m)return;let g=(v)=>{if(v.key!=="Escape")return;v.stopPropagation(),fs.value=!1};return window.addEventListener("keydown",g,{capture:!0}),()=>window.removeEventListener("keydown",g,{capture:!0})},[m]),!m)return null;let h=async()=>{if(!i||i.boardId!==ie.value)return;u(!0);let g=await pe("exportBoard","/api/canvas/export",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({board:i.boardId,includeFiles:e,includeDerivedText:n})});if(u(!1),g?.path&&ie.value===i.boardId)l(g)};return r("div",{class:"text-prompt-backdrop",onPointerDown:()=>fs.value=!1,children:r("div",{class:"text-prompt export-dialog",role:"dialog","aria-label":"Export board","data-testid":"export-dialog",onPointerDown:(g)=>g.stopPropagation(),children:[r("div",{class:"text-prompt-title",children:["Export ",i?`“${i.boardName}”`:"board"]},void 0,!0,void 0,this),!i?r("div",{class:"export-dialog-note",children:"Reading the board…"},void 0,!1,void 0,this):r(be,{children:[r("div",{class:"export-dialog-note",children:"One HTML file anyone can open without installing anything. It will contain:"},void 0,!1,void 0,this),r("ul",{class:"export-dialog-list",children:[r("li",{children:[i.cards," card",i.cards!==1?"s":""," and ",i.connections," connection",i.connections!==1?"s":""]},void 0,!0,void 0,this),i.frames>0&&r("li",{children:[i.frames," embedded pages, charts or diagrams, with the code that draws them"]},void 0,!0,void 0,this),i.embeddedImages>0&&r("li",{children:[i.embeddedImages," local images"]},void 0,!0,void 0,this),i.placeholders.length>0&&r("li",{children:["Shown as placeholders:"," ",i.placeholders.map((g)=>`${g.title} (${g.reason})`).join(", ")]},void 0,!0,void 0,this),i.remoteImages.length>0&&r("li",{children:["Web images loaded when opened: ",i.remoteImages.join(", ")]},void 0,!0,void 0,this),i.links.length>0&&r("li",{children:["Links included in cards: ",i.links.join(", ")]},void 0,!0,void 0,this),i.frameNetworkDestinations.length>0&&r("li",{children:["Network destinations referenced by embedded pages: ",i.frameNetworkDestinations.join(", ")]},void 0,!0,void 0,this),i.embeddedCodeCanAccessNetwork&&r("li",{children:"Warning: embedded code can access the network. Scripts may contact destinations that cannot be listed in advance."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(i.attachments?.length??0)>0&&r("p",{children:"Original attachments are excluded. Their filenames remain visible."},void 0,!1,void 0,this),(i.sourceDerivedCards?.length??0)>0&&r("label",{class:"export-dialog-files",children:[r("input",{type:"checkbox",checked:n,onChange:(g)=>o(g.currentTarget.checked)},void 0,!1,void 0,this),r("span",{children:["Include imported document text (",i.sourceDerivedCards.length," cards)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i.files.length>0&&r("label",{class:"export-dialog-files",children:[r("input",{type:"checkbox",checked:e,onChange:(g)=>t(g.target.checked)},void 0,!1,void 0,this),r("span",{children:["Include the contents of ",i.files.length," local file",i.files.length!==1?"s":"",": ",i.files.map((g)=>g.path).join(", ")]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a&&r("div",{class:"export-dialog-result","data-testid":"export-result",children:[r("div",{children:["Saved (",nO(a.bytes),"): ",r("code",{children:a.path},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"export-dialog-links",children:nt()?r("button",{type:"button",disabled:c,onClick:async()=>{u(!0),p("");try{await wk(a.url)}catch(g){p(g instanceof Error?g.message:"Download failed. Try again.")}finally{u(!1)}},children:c?"Downloading…":"Download"},void 0,!1,void 0,this):r(be,{children:[r("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",children:"Open"},void 0,!1,void 0,this),r("a",{class:"is-primary",href:`${a.url}?download=1`,children:"Download"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),nt()&&r("p",{children:"Download the HTML file to open it outside ChatGPT."},void 0,!1,void 0,this),d&&r("p",{role:"alert",children:d},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"text-prompt-actions",children:[r("button",{type:"button",class:"text-prompt-cancel",onClick:()=>fs.value=!1,children:a?"Done":"Cancel"},void 0,!1,void 0,this),!a&&r("button",{type:"button",class:"text-prompt-confirm",disabled:!i||c,onClick:()=>void h(),children:c?"Exporting…":"Export"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Bg({presence:e,size:t=18}){return r("span",{class:"writer-avatar",style:{background:_o(e.sessionId),width:`${t}px`,height:`${t}px`},"aria-hidden":"true",children:Ud(e.label)},void 0,!1,void 0,this)}function lI(){let e=Wd.value;if(or.value||e.length===0)return null;let t=e.reduce((i,s)=>i+s.opCount,0),n=e.length===1?e[0].label:`${e.length} writers`,o=ss.value;return r(_e,{label:`${e.length} external writer${e.length===1?"":"s"} on this board`,body:"Click for their activity.",align:"end",children:r("button",{type:"button",class:"external-indicator","data-testid":"external-indicator","aria-label":`${n} external activity, ${t} operation${t===1?"":"s"}`,"aria-expanded":o,onClick:()=>{ss.value=!o},children:[r("span",{class:"external-indicator-avatars",children:e.slice(0,3).map((i)=>r(Bg,{presence:i},i.sessionId,!1,void 0,this))},void 0,!1,void 0,this),r("span",{class:"external-indicator-label",children:n},void 0,!1,void 0,this),r("span",{class:"external-indicator-ops hud-collapsible-text",children:[t," op",t===1?"":"s"]},void 0,!0,void 0,this),r("span",{class:"external-indicator-dot","aria-hidden":"true"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function oO(e){if(e==="node.add"||e==="jsonrender.add"||e==="graph.add"||e==="group.create")return{glyph:"+",tone:"ok"};if(e==="node.remove"||e==="edge.remove"||e==="canvas.clear")return{glyph:"×",tone:"danger"};if(e==="edge.add")return{glyph:"⟶",tone:"accent"};if(e.startsWith("ax."))return{glyph:"◆",tone:"purple"};return{glyph:"✎",tone:"accent"}}function rO(e){return e.reduce((t,n)=>n.lastSeenAt>t?n.lastSeenAt:t,"")}function iO(){return[...qt.value.values()].filter((e)=>!e.auto&&e.phase==="forming")}function cI(){let e=ss.value,t=Wd.value,n=rr(e?1e4:0);if($e(()=>{if(!e)return;let l=(c)=>{if(c.key!=="Escape"||c.defaultPrevented)return;if(c.preventDefault(),ka.value)ka.value=!1;else ss.value=!1};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e]),!e||or.value||t.length===0)return null;let o=sg.value,i=iO().filter((l)=>!o||(l.source??"")===o),s=bi.value.filter((l)=>!o||l.sessionId===o),a=(l,c)=>r("button",{type:"button",class:`activity-filter${o===l?" is-active":""}`,style:l?{"--writer":_o(l)}:void 0,"aria-pressed":o===l,onClick:()=>{sg.value=l},children:c},void 0,!1,void 0,this);return r("div",{class:"activity-feed","data-testid":"activity-feed",role:"dialog","aria-label":"External activity",children:[r("div",{class:"activity-feed-head",children:[r("span",{class:"external-indicator-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("div",{class:"activity-feed-titles",children:[r("div",{class:"activity-feed-title",children:["External activity — ",t.length," writer",t.length===1?"":"s"]},void 0,!0,void 0,this),r("div",{class:"activity-feed-sub",children:[t.reduce((l,c)=>l+c.opCount,0)," writes · last"," ",Zd(rO(t),n)," · live writers"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",class:"activity-feed-close","aria-label":"Close activity feed",onClick:()=>{ss.value=!1},children:r(Tt,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"activity-filters",children:[a(null,"All"),t.map((l)=>a(l.sessionId,l.label))]},void 0,!0,void 0,this),r("div",{class:"activity-rows",children:[i.map((l)=>r("div",{class:"activity-row is-pending","data-testid":"activity-proposal",children:[r("span",{class:"activity-glyph tone-purple","aria-hidden":"true",children:"▢"},void 0,!1,void 0,this),r("div",{class:"activity-main",children:[r("div",{class:"activity-text",children:["Proposing: ",r("b",{children:l.label?.trim()||`${l.kind} intent`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"activity-meta",children:[l.reason?.trim()||"Intent signalled — a real veto window before the mutation",l.source?` · ${l.source}`:""]},void 0,!0,void 0,this),r("div",{class:"activity-actions",children:[r("button",{type:"button",class:"activity-veto",onClick:()=>{ji(l).then((c)=>{if(c)Hi(l.id)})},children:"Veto"},void 0,!1,void 0,this),r("span",{class:"activity-hint",children:"or hover ghost + Esc"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"activity-age",children:"now"},void 0,!1,void 0,this)]},l.id,!0,void 0,this)),s.length===0&&i.length===0&&r("div",{class:"activity-empty",children:"No writes yet."},void 0,!1,void 0,this),s.map((l)=>{let{glyph:c,tone:u}=oO(l.op);return r("div",{class:"activity-row","data-testid":"activity-row","data-op":l.op,children:[r("span",{class:`activity-glyph tone-${u}`,"aria-hidden":"true",children:c},void 0,!1,void 0,this),r("div",{class:"activity-main",children:[r("div",{class:"activity-text",children:l.summary},void 0,!1,void 0,this),r("div",{class:"activity-writer",style:{color:_o(l.sessionId)},children:l.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"activity-age",children:Zd(l.at,n)},void 0,!1,void 0,this)]},l.id,!0,void 0,this)})]},void 0,!0,void 0,this),r("div",{class:"activity-feed-foot",children:[r("span",{class:"activity-feed-note",children:"All writes ghost first · Esc vetoes"},void 0,!1,void 0,this),r("button",{type:"button",class:"activity-feed-link",onClick:()=>{ka.value=!0},children:"Writers"},void 0,!1,void 0,this),kt.value&&r("button",{type:"button",class:"activity-feed-link is-accent",onClick:()=>{ss.value=!1,_i()},children:["Start session ",r(pi,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function sO(){let e=[];if(Io.value)e.push("scoped");if(To.value.length>0)e.push("gated");return e.length>0?e.join(" + "):"open"}function uI(){let e=ka.value,t=rr(e?1e4:0),n=F(null);if(bn(n,e),!e)return null;let o=kt.value?en.value.filter((a)=>a.attached):[],i=Wd.value,s=()=>{ka.value=!1};return r(be,{children:[r("div",{class:"writers-scrim",onClick:s,"aria-hidden":"true"},void 0,!1,void 0,this),r("div",{ref:n,class:"writers-sheet","data-testid":"writers-sheet",role:"dialog","aria-modal":"true","aria-label":"Connected writers",children:[r("div",{class:"writers-head",children:[r("span",{class:"writers-title",children:"Connected writers"},void 0,!1,void 0,this),r("span",{class:"writers-board",children:Cr.value.slice(0,12)},void 0,!1,void 0,this),r("button",{type:"button",class:"activity-feed-close","aria-label":"Close writers",onClick:s,children:r(Tt,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"writers-body",children:[kt.value&&r(be,{children:[r("div",{class:"writers-section",children:"Agent sessions"},void 0,!1,void 0,this),o.length===0&&r("div",{class:"writers-empty",children:"None attached — start one from the top bar."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o.map((a)=>r("div",{class:"writers-row",children:[r(Bg,{presence:a,size:20},void 0,!1,void 0,this),r("span",{class:"writers-name",children:a.label},void 0,!1,void 0,this),r("span",{class:"writers-config",children:sO()},void 0,!1,void 0,this)]},a.sessionId,!0,void 0,this)),r("div",{class:"writers-section",children:kt.value?"External writers · MCP":"Live writers"},void 0,!1,void 0,this),i.length===0&&r("div",{class:"writers-empty",children:"No external writers right now."},void 0,!1,void 0,this),i.map((a)=>r("div",{class:"writers-row",children:[r(Bg,{presence:a,size:20},void 0,!1,void 0,this),r("span",{class:"writers-name is-mono",children:a.label},void 0,!1,void 0,this),r("span",{class:"writers-meta",children:[a.source!==a.label?`${a.source} · `:"","wrote"," ",Zd(a.lastSeenAt,t)," ago"]},void 0,!0,void 0,this)]},a.sessionId,!0,void 0,this))]},void 0,!0,void 0,this),r("div",{class:"writers-foot",children:[r("span",{class:"writers-note",children:"Local-first: any process on this machine can connect and write. Every write ghosts first — veto is the control, not permissions."},void 0,!1,void 0,this),r("button",{type:"button",class:"writers-done",onClick:s,children:"Done"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function dI({nodeId:e}){let t=ie.value,[n,o]=E(null),[i,s]=E(!1),a=tt.value,l=Z.value,c=Ge.value;G(()=>{let f=!1;if(o(null),s(!1),t)pe("relations",`/api/canvas/memory-graph?focus=${encodeURIComponent(Mt({boardId:t,cardId:e}))}&depth=1`,null).then((h)=>{if(!f)o(h),s(!h)});return()=>{f=!0}},[t,e,a,l,c]);let u=t?Mt({boardId:t,cardId:e}):"",d=n?.edges.filter((f)=>f.kind!=="member"&&(f.from===u||f.to===u))??[],p=(f)=>{let h=f.to===u;if(h&&f.relationKind==="supports")return"Evidence for";if(h&&f.relationKind==="contradicts")return"Evidence against";let g=Qd({kind:f.relationKind,type:f.type});if(g)return(g==="from"?!h:h)?"Used by":"Sources";if(f.relationKind==="cites"||f.type==="references")return h?"Used by":"Sources";if(!h&&f.relationKind==="supports")return"Used by";return"Connections"},m=["Evidence for","Evidence against","Sources","Used by","Connections"];return d.sort((f,h)=>m.indexOf(p(f))-m.indexOf(p(h))),r("aside",{class:"relations-panel","aria-label":"Relations",children:[r("h3",{children:"Relations"},void 0,!1,void 0,this),!n&&r("p",{role:"status",children:i?"Relations unavailable. Reopen to retry.":"Loading relations…"},void 0,!1,void 0,this),n&&d.length===0&&r("p",{children:"No connections yet."},void 0,!1,void 0,this),d.map((f,h)=>{let g=f.from===u,v=g?f.target:f.source,b=n?.nodes.find((y)=>y.key===Mt(v)),x=c.find((y)=>y.id===f.source.boardId),C=ho({kind:f.relationKind,type:f.type},x?.relationVocabulary);return r("div",{class:"relation-row",children:[(h===0||p(d[h-1])!==p(f))&&r("h4",{children:p(f)},void 0,!1,void 0,this),r("span",{class:"relation-kind",style:{color:`var(--c-rel-${C.ink})`},children:[g?"→":"←"," ",f.relationKind??f.type??f.kind]},void 0,!0,void 0,this),f.missing?r("span",{children:"Missing target"},void 0,!1,void 0,this):r("button",{type:"button",class:"relation-target",onClick:()=>void zt(v),children:b?.title??v.boardId},void 0,!1,void 0,this),f.label&&r("span",{children:f.label},void 0,!1,void 0,this),r("p",{children:f.reason??"No reason recorded."},void 0,!1,void 0,this)]},f.id,!0,void 0,this)}),r("p",{children:"Manage shared relation presets in Home."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function pI(e,t){switch(e.type){case"markdown":return r(Ed,{node:e,expanded:t},void 0,!1,void 0,this);case"mcp-app":return r(yi,{node:e,expanded:t},void 0,!1,void 0,this);case"webpage":return r(Bd,{node:e,expanded:t},void 0,!1,void 0,this);case"json-render":return r(yi,{node:e,expanded:t},void 0,!1,void 0,this);case"graph":return r(yi,{node:e,expanded:t},void 0,!1,void 0,this);case"board":return r(rp,{node:e},void 0,!1,void 0,this);case"prompt":return r(Hd,{node:e},void 0,!1,void 0,this);case"response":return r(Fd,{node:e,expanded:t},void 0,!1,void 0,this);case"status":return r(Od,{node:e},void 0,!1,void 0,this);case"context":return r(ud,{node:e,expanded:t},void 0,!1,void 0,this);case"ledger":return r(fd,{node:e},void 0,!1,void 0,this);case"trace":return r(jd,{node:e},void 0,!1,void 0,this);case"file":return r(md,{node:e,expanded:t},void 0,!1,void 0,this);case"diff":return r(dd,{node:e},void 0,!1,void 0,this);case"mermaid":return r(Ld,{node:e,expanded:t},void 0,!1,void 0,this);case"image":return r(Dd,{node:e,expanded:t},void 0,!1,void 0,this);case"html":return r(ec,{node:e,expanded:t},void 0,!1,void 0,this);default:return r("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function mI(e){switch(e.type){case"markdown":return e.data.content||"";case"diff":return e.data.content||"";case"mermaid":return e.data.content||"";case"file":return e.data.fileContent||"";case"webpage":return e.data.content||"";case"html":return e.data.html||e.data.content||"";case"json-render":case"graph":return JSON.stringify(e.data.spec??e.data.graphConfig??{},null,2);default:return""}}function aO(e){if(!e)return 0;return e.split(/\s+/).filter(Boolean).length}function lO(e,t){return e!==null&&typeof e==="object"&&e.source===eo&&e.type==="presentation-exit"&&e.token===t}function cO(e){return e==="ArrowRight"||e==="PageDown"||e===" "||e==="ArrowLeft"||e==="PageUp"||e==="Home"||e==="End"}function fI(e){return e instanceof HTMLElement&&Boolean(e.closest(".html-presentation-exit"))}function hI(){let e=Bt.value,t=e?Z.value.get(e):void 0,[n,o]=E(!1),[i,s]=E(null),[a,l]=E(!1),[c,u]=E(""),d=F(null),p=F(null),m=oe(()=>{l(!1),Rr()},[]),f=oe(()=>{u(`presentation-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`),l(!0)},[]),h=oe((R)=>{document.querySelector(".html-presentation-overlay iframe.html-node-frame-presentation")?.contentWindow?.postMessage({source:eo,token:c,...R},"*")},[c]),g=oe(()=>{l(!1)},[]),v=oe((R)=>{if(R.key==="Escape"){R.preventDefault(),R.stopPropagation(),l(!1);return}if(R.key==="Tab"&&!fI(R.target)){R.preventDefault(),R.stopPropagation(),p.current?.focus();return}if((R.key===" "||R.key==="Enter")&&fI(R.target))return;if(!cO(R.key))return;R.preventDefault(),R.stopPropagation(),h({type:"presentation-key",key:R.key})},[h]),b=oe((R)=>{if(R.target.classList.contains("expanded-overlay-backdrop"))Rr()},[]),x=oe(()=>{if(!t)return;let R=mI(t);if(!R)return;navigator.clipboard.writeText(R).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})},[t]),C=oe(()=>{if(!e)return;uo(e)},[e]);G(()=>{l(!1)},[e]),$e(()=>{if(!a)return;let R=()=>{let H=d.current;if(!H||H.contains(document.activeElement))return;H.focus()},te=[0,50,150].map((H)=>window.setTimeout(R,H)),O=(H)=>{if(!lO(H.data,c))return;l(!1)};return document.addEventListener("keydown",v,!0),window.addEventListener("message",O),()=>{te.forEach((H)=>{window.clearTimeout(H)}),document.removeEventListener("keydown",v,!0),window.removeEventListener("message",O)}},[v,c,a]);let y=F(null),k=oe(()=>e?document.querySelector(`.canvas-node[data-node-id="${CSS.escape(e)}"]`):null,[e]),_=Be.value&&Ct.value?.nodeId===e,A=!Be.value&&Ct.value?.nodeId===e&&!!document.activeElement?.closest(".lifecycle-dialog");if(bn(y,t!==void 0&&!_,{restoreTo:k}),$e(()=>{if(A)document.querySelector('button[aria-label="Settings"]')?.focus({preventScroll:!0})},[_]),!t)return null;let w=t.data.title||t.data.path?.split("/").pop()||ln[t.type],M=mI(t),B=aO(M),L=e?ht.value.has(e):!1,Y=M.length>0,j=Lo.value===e,J=t.type==="mcp-app"||t.type==="webpage"||t.type==="json-render"||t.type==="graph",X=nC(t),V=Bo(t.type),ee=t.data.provenance&&typeof t.data.provenance==="object"?t.data.provenance:null,he=ee?[ee.sourceKind,ee.sourceUri,ee.syncedAt?`synced ${ee.syncedAt.slice(11,16)}`:null].filter((R)=>typeof R==="string"&&R.length>0).join(" · "):null;return r("div",{class:"expanded-overlay-backdrop",onPointerDown:b,style:{pointerEvents:j?"none":"auto"},children:r("div",{ref:y,class:`expanded-overlay-panel${L?" is-pinned":""}`,role:"dialog","aria-modal":_?void 0:"true","aria-label":w,"data-testid":"expanded-node",children:[r("div",{class:"expanded-header",children:[r("span",{class:"expanded-kind-icon","aria-hidden":"true",children:r(V,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"expanded-title",children:w},void 0,!1,void 0,this),r("span",{class:"expanded-kind-pill",children:ln[t.type]},void 0,!1,void 0,this),r(_e,{label:L?"In agent context — click to unpin":"Pin as agent context",children:r("button",{type:"button",class:`expanded-pin${L?" is-on":""}`,onClick:C,"aria-label":L?"In agent context — click to unpin":"Pin as agent context","aria-pressed":L,children:"✦"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"expanded-spacer"},void 0,!1,void 0,this),r("div",{class:"expanded-actions",children:[Be.value&&r("button",{type:"button",class:"expanded-action-btn",onClick:()=>js(t.id),children:"Review"},void 0,!1,void 0,this),r("button",{type:"button",class:"expanded-action-btn","aria-pressed":i===e,onClick:()=>s(i===e?null:e),children:"Relations"},void 0,!1,void 0,this),Y&&r(_e,{label:"Copy content to clipboard",children:r("button",{type:"button",class:"expanded-action-btn",onClick:x,children:n?"Copied!":"Copy"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Nd(t)&&r(_e,{label:"Open as a full-page site in the system browser",children:r("button",{type:"button",class:"expanded-action-btn",onClick:()=>void Md(t),children:["Open in tab ",r(pi,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),X&&r(_e,{label:"Present this HTML node fullscreen",children:r("button",{type:"button",class:"expanded-action-btn expanded-action-primary",onClick:f,children:"Present"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(_e,{label:"Close",shortcut:"Esc",align:"end",children:r("button",{type:"button",class:"expanded-close",onClick:m,"aria-label":"Close",children:r(Tt,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"expanded-content-row",children:[r("div",{class:`expanded-body${J?" is-embedded":""}`,children:J?r("div",{style:{flex:1,minHeight:0,display:"flex"},children:pI(t,!0)},void 0,!1,void 0,this):pI(t,!0)},void 0,!1,void 0,this),i===e&&r(dI,{nodeId:t.id},e,!1,void 0,this)]},void 0,!0,void 0,this),r(tp,{node:t},void 0,!1,void 0,this),r("div",{style:{"--ax-dock-bleed":"0px","--ax-dock-pad":"16px"},children:r(op,{node:t},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("div",{class:"expanded-footer",children:[r("span",{class:"expanded-footer-meta",children:[he,B>0?`${B.toLocaleString()} word${B!==1?"s":""}`:null].filter(Boolean).join(" · ")||ln[t.type].toLowerCase()},void 0,!1,void 0,this),r("span",{class:"expanded-spacer"},void 0,!1,void 0,this),r("span",{class:`expanded-footer-hint${j?" is-saving":""}`,children:j?"Saving edits…":"esc or click outside to close"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&a&&r("div",{ref:d,class:"html-presentation-overlay",role:"dialog","aria-modal":"true","aria-label":`Present ${w}`,tabIndex:-1,onKeyDownCapture:v,children:[r("button",{ref:p,type:"button",class:"html-presentation-exit",onClick:g,"aria-label":"Exit presentation",children:"Exit presentation"},void 0,!1,void 0,this),r("div",{class:"html-presentation-stage",children:r(ec,{node:t,expanded:!0,presentation:!0,presentationExitToken:c},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var yI=168,vI=112,xp=20;function gI(e,t,n,o){let i=Array.from(e.values()),s=0,a=0,l=1000,c=800;if(i.length>0){s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,l=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;for(let v of i)s=Math.min(s,v.position.x),a=Math.min(a,v.position.y),l=Math.max(l,v.position.x+v.size.width),c=Math.max(c,v.position.y+v.size.height)}let u=-t.x/t.scale,d=-t.y/t.scale,p=u+n/t.scale,m=d+o/t.scale,f={minX:Math.min(s,u)-xp,minY:Math.min(a,d)-xp,maxX:Math.max(l,p)+xp,maxY:Math.max(c,m)+xp},h=f.maxX-f.minX||1,g=f.maxY-f.minY||1;return{bounds:f,scale:Math.min(yI/h,vI/g)}}function bI({viewport:e,nodes:t,onNavigate:n,containerWidth:o,containerHeight:i}){let s=F(null),a=F(!1),l=t.value,c=e.value,u=gI(l,c,o,i),{bounds:d,scale:p}=u,m=(w)=>(w-d.minX)*p,f=(w)=>(w-d.minY)*p,h=oe((w)=>{let M=s.current;if(!M)return;let B=M.getBoundingClientRect(),L=(w.clientX-B.left)/B.width*yI,Y=(w.clientY-B.top)/B.height*vI,j=gI(t.value,e.value,o,i),J=e.value,X=o/J.scale,V=i/J.scale,ee=L/j.scale+j.bounds.minX,he=Y/j.scale+j.bounds.minY;n(-(ee-X/2)*J.scale,-(he-V/2)*J.scale)},[t,e,o,i,n]),g=oe((w)=>{w.stopPropagation(),w.preventDefault(),a.current=!0,h(w);let M=(L)=>{if(a.current)h(L)},B=()=>{a.current=!1,document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",B)};document.addEventListener("pointermove",M),document.addEventListener("pointerup",B)},[h]),v=rt.value,b=ht.value,x=or.value?qd.value:new Set,C=Io.value,y=C?Xd(C.nodeIds.map((w)=>l.get(w)).filter((w)=>w!==void 0),C.padding):null,k=en.value.map((w)=>({id:w.sessionId,phase:w.phase,worker:w.parentAgentId!=null,external:!w.attached,at:Gd(w,(M)=>l.get(M))})).filter((w)=>w.at!==null),_=-c.x/c.scale,A=-c.y/c.scale;return r("div",{ref:s,class:"minimap","data-testid":"minimap","aria-label":"Minimap — click to jump, drag the frame to pan",onPointerDown:g,children:[Array.from(l.values()).map((w)=>{let M=w.type==="group";return r("span",{class:`minimap-node${M?" is-group":""}${v.has(w.id)?" is-selected":""}${b.has(w.id)?" is-pinned":""}${x.has(w.id)?" is-agent":""}`,"data-kind":w.type,style:{left:`${m(w.position.x)}px`,top:`${f(w.position.y)}px`,width:`${Math.max(M?6:4,w.size.width*p)}px`,height:`${Math.max(M?5:3,w.size.height*p)}px`}},w.id,!1,void 0,this)}),y&&r("span",{class:"minimap-fence",style:{left:`${m(y.x)}px`,top:`${f(y.y)}px`,width:`${y.width*p}px`,height:`${y.height*p}px`}},void 0,!1,void 0,this),k.map((w)=>r("span",{class:`minimap-presence phase-${w.phase}${w.worker?" is-worker":""}${w.external?" is-external":""}`,style:{left:`${m(w.at.x)-4}px`,top:`${f(w.at.y)-4}px`,"--identity-color":_o(w.id)}},w.id,!1,void 0,this)),r("span",{class:"minimap-frame",style:{left:`${m(_)}px`,top:`${f(A)}px`,width:`${o/c.scale*p}px`,height:`${i/c.scale*p}px`}},void 0,!1,void 0,this),r("span",{class:"minimap-zoom",children:[Math.round(c.scale*100),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function xI(){let e=rt.value.size,t=lp("--selection-bar-height"),n=oe(()=>{let l=Array.from(rt.value);if(l.length===0)return;Qu(l),$n()},[]),o=oe(()=>{let l=Array.from(rt.value);if(l.length===0)return;qs({title:"Group",childIds:l}),$n()},[]),i=oe(()=>{let l=Array.from(rt.value);for(let c=0;c<l.length;c++)for(let u=c+1;u<l.length;u++)kr(l[c],l[u],"relation");$n()},[]),s=oe(()=>{let l=Array.from(rt.value);for(let c of l)ri(c);$n()},[]);if(e===0)return null;let a=e>=2;return r("div",{class:"selection-bar",role:"toolbar","aria-label":"Selection",ref:t,children:[r("span",{class:"selection-bar-count",children:[e," node",e!==1?"s":""," selected"]},void 0,!0,void 0,this),a&&r(be,{children:[r("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),r(_e,{label:"Align left",side:"up",children:r("button",{type:"button",class:"selection-bar-icon","aria-label":"Align left",onClick:()=>Hf("left"),children:r("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[r("line",{x1:"2.5",y1:"2",x2:"2.5",y2:"14"},void 0,!1,void 0,this),r("rect",{x:"5",y:"3.5",width:"8",height:"3.5",rx:"1"},void 0,!1,void 0,this),r("rect",{x:"5",y:"9",width:"5",height:"3.5",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Align top",side:"up",children:r("button",{type:"button",class:"selection-bar-icon","aria-label":"Align top",onClick:()=>Hf("top"),children:r("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[r("line",{x1:"2",y1:"2.5",x2:"14",y2:"2.5"},void 0,!1,void 0,this),r("rect",{x:"3.5",y:"5",width:"3.5",height:"8",rx:"1"},void 0,!1,void 0,this),r("rect",{x:"9",y:"5",width:"3.5",height:"5",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Distribute horizontally",body:"Evens the gaps. A selection that cannot fit flows into a clean row instead of overlapping.",side:"up",children:r("button",{type:"button",class:"selection-bar-icon","aria-label":"Distribute",disabled:e<3,onClick:()=>xS(),children:r("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","aria-hidden":"true",children:[r("rect",{x:"1.5",y:"5",width:"3.5",height:"6",rx:"1"},void 0,!1,void 0,this),r("rect",{x:"6.25",y:"5",width:"3.5",height:"6",rx:"1"},void 0,!1,void 0,this),r("rect",{x:"11",y:"5",width:"3.5",height:"6",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Auto-arrange selection",side:"up",children:r("button",{type:"button",class:"selection-bar-icon","aria-label":"Auto-arrange",onClick:()=>wS(),children:r(Pr,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),r(_e,{label:"Group the selection",shortcut:"G",side:"up",children:r("button",{type:"button",class:"selection-bar-action",onClick:o,children:[r("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-dasharray":"3 2.5","aria-hidden":"true",children:r("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"2"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Group"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Connect every pair",side:"up",children:r("button",{type:"button",class:"selection-bar-action",onClick:i,children:"Connect"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(_e,{label:"Pin to agent context",side:"up",children:r("button",{type:"button",class:"selection-bar-action is-pin",onClick:n,children:[r("span",{"aria-hidden":"true",children:"✦"},void 0,!1,void 0,this),"Pin as context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),r("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),r(_e,{label:"Delete selection",side:"up",children:r("button",{type:"button",class:"selection-bar-icon is-danger","aria-label":"Delete selection",onClick:s,children:r("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[r("path",{d:"M2.5 4 H13.5"},void 0,!1,void 0,this),r("path",{d:"M5.5 4 V2.5 H10.5 V4"},void 0,!1,void 0,this),r("path",{d:"M4 4 L4.8 13.5 H11.2 L12 4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Clear selection",shortcut:"Esc",side:"up",children:r("button",{type:"button",class:"selection-bar-icon",onClick:$n,"aria-label":"Clear selection",children:r(Tt,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function wp(e,t=Date.now()){if(!e.expiresAt)return null;let n=Date.parse(e.expiresAt);if(!Number.isFinite(n))return null;return Math.max(0,n-t)}function kp(e){let t=Math.max(0,Math.ceil(e/1000)),n=Math.floor(t/60),o=t%60;return`${n}:${String(o).padStart(2,"0")}`}var uO={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"vetoed"},dO={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"cancelled"},wI=[{id:"all",label:"All",hint:"Everything below in one feed, newest first"},{id:"update",label:"Updates",hint:"Board edits agents made — nodes, edges, pins, work items"},{id:"steer",label:"Steer",hint:"Instructions sent to agents — by you from the composer, or agent-to-agent"},{id:"assistant",label:"Assistant",hint:"Messages agents posted for you to read"},{id:"event",label:"Events",hint:"Run telemetry — tool runs, approvals, failures, policy notes"},{id:"evidence",label:"Evidence",hint:"Proof agents recorded — test results, artifacts, links"}],pO=Object.fromEntries(wI.map((e)=>[e.id,e.hint])),mO={policy:"warn",prompt:"accent","assistant-message":"muted","tool-start":"accent","tool-result":"ok",failure:"danger",approval:"warn",steering:"purple",command:"accent",note:"muted",evidence:"ok",steer:"purple",update:"purple",yield:"warn"};function Hg(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function fO({item:e}){let t=uO[e.status]??"queued",n=e.nodeIds[0];return r("li",{class:`session-item status-${t}`,"data-work-item-id":e.id,children:[r("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),r("div",{class:"session-item-main",children:[r("button",{type:"button",class:"session-item-title",disabled:!n,onClick:()=>n&&$t(n),children:e.title},void 0,!1,void 0,this),e.detail&&r("div",{class:"session-item-detail",children:e.detail},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"session-item-status",children:dO[e.status]??t},void 0,!1,void 0,this),r("span",{class:"session-item-time",children:Hg(e.updatedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function kI({gate:e,now:t}){let[n,o]=E(null),i=async(l)=>{o(l),await DC(e,l),o(null)},s=e.nodeIds[0],a=wp(e,t);return r("li",{class:"session-item status-awaiting session-gate","data-gate-id":e.id,children:[r("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),r("div",{class:"session-item-main",children:[r("button",{type:"button",class:"session-item-title",disabled:!s,onClick:()=>s&&$t(s),children:e.title},void 0,!1,void 0,this),e.detail&&r("div",{class:"session-item-detail",children:e.detail},void 0,!1,void 0,this),a!==null&&r("div",{class:"session-gate-ttl","data-testid":"gate-countdown",children:["auto-holds in ",kp(a)," if unanswered"]},void 0,!0,void 0,this),r("div",{class:"session-gate-actions",children:[r("button",{type:"button",class:"session-gate-approve",disabled:n!==null,onClick:()=>void i("approved"),children:n==="approved"?"Approving…":"Approve"},void 0,!1,void 0,this),r("button",{type:"button",class:"session-gate-reject",disabled:n!==null,onClick:()=>void i("rejected"),children:n==="rejected"?"Rejecting…":"Reject"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"session-item-time",children:Hg(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function SI({gate:e}){let[t,n]=E(!1);return r("li",{class:"session-item status-vetoed session-gate-held","data-gate-id":e.id,children:[r("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),r("div",{class:"session-item-main",children:[r("span",{class:"session-item-title",children:e.title},void 0,!1,void 0,this),r("div",{class:"session-item-detail",children:"Auto-held — no answer in time, the action did not proceed."},void 0,!1,void 0,this),r("div",{class:"session-gate-actions",children:r("button",{type:"button",class:"session-gate-reject",disabled:t,onClick:()=>{n(!0),BC(e).finally(()=>n(!1))},children:t?"Reopening…":"Reopen"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"session-item-status",children:"held"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function hO(e){let t=e.resolvedBy;if(!t)return e.status;let n=e.status==="approved"?"Approved":"Rejected";if(t.actor==="human")return`${n} by you`;if(t.actor==="system")return`${n} by system`;let o=t.agentId||t.source||"agent";return`${e.selfAnswer?"Self-":""}${n.toLowerCase()} by ${o}`}function _I({gate:e}){return r("li",{class:`session-item status-${e.status}`,"data-gate-id":e.id,children:[r("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),r("div",{class:"session-item-main",children:[r("span",{class:"session-item-title",children:e.title},void 0,!1,void 0,this),r("div",{class:"session-item-detail",children:hO(e)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function CI(){let e=Io.value,t=rt.value.size,[n,o]=E(!1),i=(s)=>{o(!0),zC(s).finally(()=>o(!1))};return r("div",{class:`session-scope${e?" is-fenced":""}`,"data-testid":"session-scope",children:[r("span",{class:"session-scope-dot","aria-hidden":"true"},void 0,!1,void 0,this),e?r(be,{children:[r("span",{class:"session-scope-text",children:["Scoped to ",r("strong",{children:e.nodeIds.length},void 0,!1,void 0,this)," node",e.nodeIds.length===1?"":"s"," · writes outside are blocked"]},void 0,!0,void 0,this),r("button",{type:"button",class:"session-scope-action",disabled:n,onClick:()=>i(null),children:"Clear"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r(be,{children:[r("span",{class:"session-scope-text",children:"Unscoped — the agent may write anywhere"},void 0,!1,void 0,this),r(_e,{label:t===0?"Select nodes on the canvas first":"Fence the agent to the selected nodes",align:"end",children:r("button",{type:"button",class:"session-scope-action",disabled:n||t===0,onClick:()=>i([...rt.value]),children:["Fence to selection",t>0?` (${t})`:""]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function gO(e){if(e==="browser")return"you";return en.value.find((n)=>n.sessionId===e||n.source===e)?.label??e}function yO({entry:e}){let t=rc.value.has(e.id);return r("li",{class:`session-timeline-row tone-${mO[e.kind]??"muted"}`,children:[r("span",{class:"session-timeline-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("div",{class:"session-timeline-main",children:[r("div",{class:"session-timeline-head",children:[r("span",{class:"session-timeline-label",children:e.label},void 0,!1,void 0,this),e.who&&r("span",{class:"session-timeline-who",style:{"--identity-color":_o(e.who)},children:gO(e.who)},void 0,!1,void 0,this),r("span",{class:"session-item-time",children:Hg(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"session-timeline-body",children:e.body},void 0,!1,void 0,this),e.undoable&&!t&&r("button",{type:"button",class:"session-timeline-undo","data-testid":"timeline-undo",onClick:()=>void hg(e),children:[r(th,{size:14},void 0,!1,void 0,this)," undo this edit"]},void 0,!0,void 0,this),t&&r("div",{class:"session-timeline-undone",children:"undone · steering sent"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function TI(){let e=To.value,t=rr();if(!to.value&&e.length===0)return null;return r("aside",{class:"session-panel","aria-label":"Agent controls",children:[r("header",{class:"session-panel-header",children:[r("span",{class:"session-panel-title",children:"Agent controls"},void 0,!1,void 0,this),r("span",{class:"top-bar-spacer"},void 0,!1,void 0,this),r("button",{type:"button",class:"session-collapse","aria-label":"Collapse agent controls",onClick:()=>to.value=!1,disabled:e.length>0,children:r(di,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(CI,{},void 0,!1,void 0,this),r("div",{class:"session-panel-scroll",children:[r("ul",{class:"session-list","aria-label":"Approvals",children:[e.map((n)=>r(kI,{gate:n,now:t},n.id,!1,void 0,this)),ls.value.map((n)=>r(SI,{gate:n},n.id,!1,void 0,this)),fg.value.map((n)=>r(_I,{gate:n},n.id,!1,void 0,this))]},void 0,!0,void 0,this),Sa.value.map((n)=>r("div",{class:"session-item",children:[r("span",{class:"session-item-main",children:n.label},void 0,!1,void 0,this),r("button",{type:"button",class:"session-end",onClick:()=>void ic(n),children:"End attachment"},void 0,!1,void 0,this)]},n.sessionId,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function II(){G(()=>()=>{to.value=!1},[]);let e=xi.value,t=MC.value,n=To.value,o=ls.value,i=fg.value,s=OC.value,[a,l]=E(!1),[c,u]=E(null),d=rr();if(G(()=>{Si()},[]),!(to.value||n.length>0))return r("aside",{class:"session-panel is-collapsed","aria-label":"Session (collapsed)",children:[r("button",{type:"button",class:"session-collapse",onClick:()=>{to.value=!0},"aria-label":"Expand session panel",children:"‹"},void 0,!1,void 0,this),e&&r("span",{class:`session-collapsed-live phase-${e.phase}`,"aria-label":`Session live: ${vi(e)}`,children:[r("span",{class:"session-live-dot","aria-hidden":"true"},void 0,!1,void 0,this),"live"]},void 0,!0,void 0,this),r("span",{class:"session-collapsed-label",children:"Session"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return r("aside",{class:"session-panel","aria-label":"Session",children:[r("header",{class:"session-panel-header",children:[r("span",{class:"session-panel-title",children:"Session"},void 0,!1,void 0,this),e&&r(_e,{label:vi(e),tapToOpen:!0,children:r("span",{class:`session-live phase-${e.phase}`,children:[r("span",{class:"session-live-dot","aria-hidden":"true"},void 0,!1,void 0,this),"live"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),r("span",{class:"top-bar-spacer"},void 0,!1,void 0,this),e&&r(_e,{label:"End this session",body:"A receipt and a snapshot of the board follow.",align:"end",children:r("button",{type:"button",class:"session-end",onClick:()=>void ic(e),children:"End"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("button",{type:"button",class:"session-collapse",onClick:()=>{to.value=!1},"aria-label":"Collapse session panel",children:r(di,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(CI,{},void 0,!1,void 0,this),(()=>{let m=s.find((f)=>f.undoable&&!rc.value.has(f.id));if(!m)return null;return r("div",{class:"session-undo-row","data-testid":"session-undo-row",children:[r("span",{class:"session-undo-text",children:["Agent edit on top: ",m.body]},void 0,!0,void 0,this),r("button",{type:"button",class:"session-undo-btn",onClick:()=>void hg(m),children:[r(th,{size:14},void 0,!1,void 0,this)," Undo"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)})(),r("div",{class:"session-panel-body",children:[r("section",{class:"session-section",children:(()=>{let m=t.filter((C)=>C.status==="in-progress"||C.status==="todo").length,f=t.filter((C)=>C.status!=="cancelled"),h=f.filter((C)=>C.status==="done").length,g=t.length-f.length,v=n.length>0,b=a||v,x=m>0?`${m} running`:f.length>0?`${h}/${f.length} done${g>0?` · ${g} cancelled`:""}`:t.length>0?`${t.length} cancelled`:"none yet";return r(be,{children:[r("button",{type:"button",class:"session-section-toggle","aria-expanded":b,"data-testid":"work-items-toggle",onClick:()=>l((C)=>!C),children:[r("span",{class:"session-section-title",children:"Work items"},void 0,!1,void 0,this),r("span",{class:"session-work-summary",children:[m>0&&r("span",{class:"session-work-dot","aria-hidden":"true"},void 0,!1,void 0,this),x]},void 0,!0,void 0,this),r("span",{class:`session-section-chevron${b?" is-open":""}`,"aria-hidden":"true",children:r(di,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b&&(n.length===0&&o.length===0&&i.length===0&&t.length===0?r("div",{class:"session-empty",children:"No work items yet — the agent's tasks and gates appear here."},void 0,!1,void 0,this):r("ul",{class:"session-list","aria-live":"polite","aria-label":"Work items and gates",children:[n.map((C)=>r(kI,{gate:C,now:d},C.id,!1,void 0,this)),o.map((C)=>r(SI,{gate:C},C.id,!1,void 0,this)),i.map((C)=>r(_I,{gate:C},C.id,!1,void 0,this)),t.map((C)=>r(fO,{item:C},C.id,!1,void 0,this))]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)})()},void 0,!1,void 0,this),r("section",{class:"session-section",children:[r("h3",{class:"session-section-title",children:"Timeline"},void 0,!1,void 0,this),r("div",{class:"session-timeline-filters",role:"group","aria-label":"Filter timeline",children:wI.map((m)=>r("button",{type:"button",class:`activity-filter${cs.value===m.id?" is-active":""}`,"aria-pressed":cs.value===m.id,onMouseEnter:()=>u(m.id),onMouseLeave:()=>u((f)=>f===m.id?null:f),onFocus:()=>u(m.id),onBlur:()=>u((f)=>f===m.id?null:f),onClick:()=>{cs.value=m.id},children:m.label},m.id,!1,void 0,this))},void 0,!1,void 0,this),r("div",{class:"session-timeline-hint","data-testid":"timeline-filter-hint",children:pO[c??cs.value]},void 0,!1,void 0,this),s.length===0?r("div",{class:"session-empty",children:cs.value==="all"?"Nothing recorded yet.":"Nothing of this kind yet."},void 0,!1,void 0,this):r("ul",{class:"session-list session-timeline","aria-live":"polite","aria-label":"Timeline",children:s.map((m)=>r(yO,{entry:m},m.id,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Fg(e){if(!e||typeof e!=="object")return null;let t=e,n=(o)=>Array.isArray(o)?o.length:0;return{added:n(t.addedNodes)+n(t.addedEdges),removed:n(t.removedNodes)+n(t.removedEdges),modified:n(t.modifiedNodes)}}var EI=(e)=>e.map((t)=>t.title).join(", ");function AI(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function vO({context:e,label:t,snapshotId:n}){let[o,i]=E(!1),[s,a]=E([]),[l,c]=E(!1),[u,d]=E(null),[p,m]=E(!1),f=e.edited.length>0&&e.edited.every((x)=>s.includes(x.id))?"undone":l?"kept":null;G(()=>{a([]),c(!1),d(null)},[e]);let h=async(x)=>{if(!n||p)return;m(!0);try{let C=await jC(n,x.filter((y)=>!s.includes(y.id)));return a((y)=>[...y,...C.restored]),C}finally{m(!1)}},v=[{key:"read",name:"Read",glyph:"eye"},{key:"pinned",name:"Pinned",glyph:"pin"},{key:"created",name:"Created",glyph:"spark"},{key:"edited",name:"Edited",glyph:"pen"}].filter((x)=>e[x.key].length>0);if(v.length===0&&e.changedSinceRead.length===0)return null;let b=Hn.value?.kind==="receipt";return r("div",{class:"session-receipt-context","data-testid":"session-receipt-context",children:[e.changedSinceRead.length>0&&r("div",{class:"session-receipt-warn",children:[r("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:r("path",{d:ki.warn},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{children:[EI(e.changedSinceRead)," changed after ",t," read"," ",e.changedSinceRead.length===1?"it":"them","."]},void 0,!0,void 0,this),r("button",{type:"button",class:"session-receipt-mini",disabled:o,onClick:()=>{let x=e.changedSinceRead.length===1?"it":"them";_a(`${e.changedSinceRead.map((C)=>`“${C.title}”`).join(", ")} changed after you read ${x} — read ${x} again before relying on ${x}.`).then((C)=>i(C))},children:o?"Told":`Tell ${t}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v.map((x)=>r("div",{class:"session-receipt-context-row","data-row":x.key,children:[r("div",{class:"session-receipt-context-head",children:[x.glyph==="pin"?r(mo,{},void 0,!1,void 0,this):r("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:r("path",{d:ki[x.glyph]},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"session-receipt-context-name",children:x.name},void 0,!1,void 0,this),r("span",{class:"session-receipt-context-count",children:e[x.key].length},void 0,!1,void 0,this),x.key==="pinned"&&r("button",{type:"button",class:"session-receipt-mini",disabled:e.pinned.some((C)=>C.boardId&&C.boardId!==ie.value),onClick:()=>kS(e.pinned.map((C)=>C.id)),children:"Unpin"},void 0,!1,void 0,this),x.key==="edited"&&n&&r("button",{type:"button",class:"session-receipt-mini",disabled:f!==null||p||e.edited.some((C)=>C.boardId&&C.boardId!==ie.value),onClick:()=>{h(e.edited).then((C)=>{if(C?.ok)c(!0)})},children:f==="undone"?"✓ Undone":f==="kept"?"Kept your edits":"Undo"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x.key==="edited"&&f&&r("div",{class:"session-receipt-context-items",children:f==="undone"?"every card restored":"cards you edited since were left alone"},void 0,!1,void 0,this),x.key==="edited"?r("ul",{class:"session-receipt-edits",children:e.edited.map((C)=>r(xO,{node:C,canUndo:n!==null,undoing:p,open:u===ir(C),onToggle:()=>d(u===ir(C)?null:ir(C)),undone:s.includes(C.id),onUndo:()=>void h([C])},ir(C),!1,void 0,this))},void 0,!1,void 0,this):r("div",{class:"session-receipt-context-items",children:x.key==="pinned"?e.pinned.map((C)=>C.reason?`${C.title} — “${C.reason}”`:C.title).join("; "):EI(e[x.key])},void 0,!1,void 0,this)]},x.key,!0,void 0,this)),r("button",{type:"button",role:"switch","aria-checked":b,class:`session-receipt-lens${b?" is-on":""}`,onClick:()=>sc(!b),children:[r("span",{class:"session-receipt-lens-track","aria-hidden":"true",children:r("span",{class:"session-receipt-lens-knob"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Dim untouched nodes"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function bO(e,t){let n=(d)=>d.match(/\s+|[\p{L}\p{N}_]+|[^\s\p{L}\p{N}_]/gu)??[],o=n(e),i=n(t),s=Array.from({length:o.length+1},()=>new Uint16Array(i.length+1));for(let d=o.length-1;d>=0;d--)for(let p=i.length-1;p>=0;p--)s[d][p]=o[d]===i[p]?s[d+1][p+1]+1:Math.max(s[d+1][p],s[d][p+1]);let a=[],l=[],c=0,u=0;while(c<o.length||u<i.length)if(c<o.length&&u<i.length&&o[c]===i[u])a.push({text:o[c++],changed:!1}),l.push({text:i[u++],changed:!1});else if(c<o.length&&(u===i.length||s[c+1][u]>=s[c][u+1]))a.push({text:o[c++],changed:!0});else l.push({text:i[u++],changed:!0});return[a,l]}function xO({node:e,canUndo:t,undoing:n,open:o,onToggle:i,undone:s,onUndo:a}){let l=!e.boardId||e.boardId===ie.value,c=l?Z.value.get(e.id):void 0,u=Ge.value.find((f)=>f.id===e.boardId),d=Ve(()=>o?bO(e.before??"",e.after??""):[],[o,e.before,e.after]),p=F(null);$e(()=>{for(let f of p.current?.querySelectorAll(".session-receipt-diff-text")??[]){let h=f.querySelector("del, ins");if(h)f.scrollTop=h.getBoundingClientRect().top-f.getBoundingClientRect().top-24}},[d]);let m=c?.lastEditedBy?.actor==="human";return r("li",{class:"session-receipt-edit",children:[r("span",{class:"session-receipt-edit-line",children:[r("span",{children:[e.title,e.change?r("span",{class:"session-receipt-edit-change",children:[" — ",e.change]},void 0,!0,void 0,this):null]},void 0,!0,void 0,this),e.before!==void 0&&r("button",{type:"button",class:"session-receipt-link","aria-expanded":o,onClick:i,children:o?"Hide change":"See change"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o&&r("span",{ref:p,class:"session-receipt-diff-pair",children:[d.map((f,h)=>r("span",{class:"session-receipt-diff-side",children:[r("span",{class:"session-receipt-diff-label",children:h===0?"Before":"After"},void 0,!1,void 0,this),r("span",{class:"session-receipt-diff-text",children:f.length?f.map(({text:g,changed:v},b)=>g==="…"&&(b===0||b===f.length-1)?r("span",{class:"session-receipt-diff-cut",children:g},b,!1,void 0,this):v?h===0?r("del",{children:g},b,!1,void 0,this):r("ins",{children:g},b,!1,void 0,this):g):"Empty"},void 0,!1,void 0,this)]},h,!0,void 0,this)),t&&r("span",{class:"session-receipt-undo",children:[c?r("button",{type:"button",class:"session-receipt-mini",disabled:s||m||n,onClick:a,children:s?"✓ Undone":m?"You edited it since":"Undo this card"},void 0,!1,void 0,this):u&&!l?r("button",{type:"button",class:"session-receipt-mini",onClick:()=>void Mn(u.id),children:["Open ",u.name," to undo"]},void 0,!0,void 0,this):r("span",{class:"session-receipt-edit-change",children:"Card no longer on this board"},void 0,!1,void 0,this),r("span",{class:"session-receipt-edit-change",children:c?s?"the card shows Before again":m?"undo would lose your edit":e.before?.includes("…")||e.after?.includes("…")?"undoes the whole card":"puts back the text from before":u&&!l?`it is on ${u.name}`:""},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function RI({onOpenSnapshots:e}){let t=as.value,[n,o]=E(null),[i,s]=E(!1);if(G(()=>o(null),[t]),!kt.value||!t)return null;let a=t.snapshot?.boardId===ie.value,l=Ge.value.find((m)=>m.id===t.snapshot?.boardId),c=async()=>{if(!t.snapshot||!a)return;s(!0);try{let m=await Gt(`/api/canvas/snapshots/${encodeURIComponent(t.snapshot.id)}/diff`,{headers:{"x-pmx-workbench":"1"}});if(m.ok){let f=await m.json();o(Fg(f.diff)??{added:0,removed:0,modified:0})}}finally{s(!1)}},u=AI(t.endedAt),d=t.startedAt?AI(t.startedAt):"",p=t.endedBy==="human"?"ended by you":t.endedBy==="idle-timeout"?"ended on idle timeout":t.endedBy==="agent"?"ended by the agent":"";return r("div",{class:"session-receipt","data-testid":"session-receipt",role:"status",children:[r("div",{class:"session-receipt-head",children:[r("span",{class:"session-receipt-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("span",{class:"session-receipt-title",children:t.sessions>1?`${t.sessions} sessions ended${u?` · ${u}`:""}`:`What ${t.labels[0]} did`},void 0,!1,void 0,this),r("button",{type:"button",class:"session-receipt-close",onClick:Yd,"aria-label":"Dismiss receipt",children:r(Tt,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.sessions>1?r("div",{class:"session-receipt-who",children:t.labels.join(", ")},void 0,!1,void 0,this):r("div",{class:"session-receipt-who","data-testid":"session-receipt-span",children:[`This session · ${d?`${d}–`:""}${u}`,t.snapshot?"saved as a snapshot":"",p].filter(Boolean).join(" · ")},void 0,!1,void 0,this),r("div",{class:"session-receipt-tiles",children:[r("div",{class:"session-receipt-tile",children:[r("span",{class:"session-receipt-tile-label",children:"Items"},void 0,!1,void 0,this),r("span",{class:"session-receipt-tile-value",children:t.counts.items},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"session-receipt-tile",children:[r("span",{class:"session-receipt-tile-label",children:"Done"},void 0,!1,void 0,this),r("span",{class:"session-receipt-tile-value tone-ok",children:t.counts.done},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.cancelled>0&&r("div",{class:"session-receipt-tile",children:[r("span",{class:"session-receipt-tile-label",children:"Cancelled"},void 0,!1,void 0,this),r("span",{class:"session-receipt-tile-value tone-muted",children:t.counts.cancelled},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.rejected>0&&r("div",{class:"session-receipt-tile",children:[r("span",{class:"session-receipt-tile-label",children:"Rejected"},void 0,!1,void 0,this),r("span",{class:"session-receipt-tile-value tone-danger",children:t.counts.rejected},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.held>0&&r("div",{class:"session-receipt-tile",children:[r("span",{class:"session-receipt-tile-label",children:"Held"},void 0,!1,void 0,this),r("span",{class:"session-receipt-tile-value tone-warn",children:t.counts.held},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r(vO,{context:t.context,label:t.labels.join(", "),snapshotId:t.sessions===1?t.snapshot?.id??null:null},void 0,!1,void 0,this),r("div",{class:"session-receipt-note",children:t.sessions>1?"History has each session’s diff and the snapshot from before it.":t.snapshot?"A snapshot of the board from before this session is saved — restore it to undo the session.":t.context.created.length===0&&t.context.edited.length===0?"The board itself did not change — nothing to restore.":"The board was empty when the session started — nothing to restore."},void 0,!1,void 0,this),n&&r("div",{class:"session-receipt-diff","data-testid":"session-receipt-diff",children:["This session: ",n.added," added · ",n.removed," removed · ",n.modified," modified"]},void 0,!0,void 0,this),r("div",{class:"session-receipt-actions",children:[t.snapshot&&r("button",{type:"button",class:"session-receipt-primary",disabled:i||!a&&!l,onClick:()=>a?void c():l&&void Mn(l.id),children:!a&&l?`Open ${l.name} to compare`:i?"Comparing…":"View diff"},void 0,!1,void 0,this),r(_e,{label:"Open the History drawer",body:"Saved boards and past sessions.",side:"up",align:"end",children:r("button",{type:"button",class:"session-receipt-secondary",onClick:e,children:"History"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var wO=[{title:"Tools",shortcuts:[{keys:"V",desc:"Select tool — drag empty space to lasso"},{keys:"Space (hold)",desc:"Pan — drag anywhere moves the board"},{keys:"A",desc:"Annotate — draw on the canvas"}]},{title:"Navigation",shortcuts:[{keys:Ht("K"),desc:"Command palette — search nodes & actions"},{keys:"Tab / Shift+Tab",desc:"Cycle through nodes"},{keys:"← ↑ → ↓",desc:"Walk graph along edges (when node focused)"},{keys:"F",desc:"Fit all nodes on screen"},{keys:Ht("0"),desc:"Reset viewport to origin"},{keys:`${Ht("+")} / ${Ht("−")}`,desc:"Zoom in / out"}]},{title:"Creation",shortcuts:[{keys:"M",desc:"New markdown note"},{keys:"I / W / H",desc:"New image / webpage / HTML surface"},{keys:"Shift+F",desc:"New file node (workspace path)"},{keys:"G / Shift+G",desc:"Group the selection (new frame when empty) / ungroup"},{keys:"Double-click",desc:"Open actions on a node or create menu on canvas"},{keys:"Drag port → node",desc:"Connect two nodes (hover to reveal ports)"}]},{title:"Selection",shortcuts:[{keys:"Click",desc:"Focus node (highlights neighbors & edges)"},{keys:"Shift+Click",desc:"Toggle node in multi-selection"},{keys:"Drag empty space",desc:"Lasso select multiple nodes"},{keys:Zl?"Delete / ⌫":"Delete / Backspace",desc:"Delete the selection (or the focused node)"},{keys:Zl?"⌘Z / ⇧⌘Z":"Ctrl+Z / Ctrl+Y",desc:"Undo / redo — agent edits included"},{keys:"Esc",desc:"Close overlay first, then clear selection and view filters"}]},{title:"View",shortcuts:[{keys:"?",desc:"Toggle this shortcut overlay"},{keys:"Minimap",desc:"Click/drag to navigate (toggle in the rail)"},{keys:"Right-drag",desc:"Pan the board from anywhere"}]}];function PI({onClose:e}){return r("div",{class:"shortcut-overlay-backdrop",onMouseDown:e,children:r("div",{class:"shortcut-overlay",onMouseDown:(t)=>t.stopPropagation(),children:[r("div",{class:"shortcut-overlay-header",children:[r("span",{class:"shortcut-overlay-title",children:"Keyboard Shortcuts"},void 0,!1,void 0,this),r("span",{class:"shortcut-overlay-hint",children:["Press ",r("kbd",{children:"?"},void 0,!1,void 0,this)," or ",r("kbd",{children:"Esc"},void 0,!1,void 0,this)," to close"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"shortcut-overlay-body",children:wO.map((t)=>r("div",{class:"shortcut-group",children:[r("div",{class:"shortcut-group-title",children:t.title},void 0,!1,void 0,this),t.shortcuts.map((n)=>r("div",{class:"shortcut-row",children:[r("kbd",{class:"shortcut-keys",children:n.keys},void 0,!1,void 0,this),r("span",{class:"shortcut-desc",children:nt()&&n.desc.startsWith("Undo / redo")?"Undo / redo — available in the local workbench only":n.desc},void 0,!1,void 0,this)]},n.keys,!0,void 0,this))]},t.title,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var NI="Before session · ";function MI(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function Sp(e){if(!e.startsWith(NI))return null;let t=e.slice(NI.length),n=t.lastIndexOf(" · ");return n>0?t.slice(0,n):t}function zI({open:e,onClose:t,anchorRef:n}){let[o,i]=E([]),[s,a]=E(!1),[l,c]=E(!1),[u,d]=E(null),[p,m]=E(""),[f,h]=E(null),[g,v]=E({}),b=F(null),x=F(null);G(()=>{if(!e)return;a(!0),Kk().then((w)=>{i(w),a(!1)})},[e]),G(()=>{if(e)setTimeout(()=>x.current?.focus(),50)},[e]),G(()=>{if(!e)return;let w=(M)=>{let B=b.current,L=n.current;if(B&&!B.contains(M.target)&&L&&!L.contains(M.target))t()};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[e,t]),G(()=>{if(!e)return;let w=(M)=>{if(M.key==="Escape")t()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[e,t]);let C=oe(async()=>{let w=p.trim();if(!w)return;c(!0);let M=await Vk(w);if(c(!1),M.ok&&M.snapshot)i((B)=>[M.snapshot,...B]),m("")},[p]),y=oe(async(w)=>{h(null),d(w);let M=await Xk(w);if(d(null),M.ok)t()},[t]),k=oe(async(w)=>{if((await Jk(w)).ok)i((B)=>B.filter((L)=>L.id!==w));h(null)},[]),_=oe(async(w)=>{v((B)=>({...B,[w]:"loading"}));let M=await pe("snapshotDiff",`/api/canvas/snapshots/${encodeURIComponent(w)}/diff`,{});v((B)=>({...B,[w]:Fg(M.diff)??{added:0,removed:0,modified:0}}))},[]);if(!e)return null;let A=(w,M)=>f?.id===w.id?r(be,{children:[r("button",{type:"button",class:`snapshot-action-btn ${f.action==="delete"?"snapshot-action-confirm":"snapshot-action-restore"}`,onClick:()=>f.action==="delete"?k(w.id):y(w.id),disabled:u!==null,children:f.action==="delete"?"Delete":u===w.id?"Restoring…":"Confirm"},void 0,!1,void 0,this),r("button",{type:"button",class:"snapshot-action-btn",onClick:()=>h(null),disabled:u!==null,children:"Cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r(be,{children:[r(_e,{label:"Restore this snapshot",body:nt()?"Replaces the current canvas.":"Replaces the current canvas (undoable).",align:"end",children:r("button",{type:"button",class:"snapshot-action-btn snapshot-action-restore",onClick:()=>h({id:w.id,action:"restore"}),disabled:u!==null,children:u===w.id?"Restoring…":M},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Delete this snapshot",align:"end",children:r("button",{type:"button",class:"snapshot-action-btn snapshot-action-delete",onClick:()=>h({id:w.id,action:"delete"}),"aria-label":"Delete snapshot",disabled:u!==null,children:r(Tt,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return r("div",{ref:b,class:"snapshot-panel","data-testid":"history-drawer",role:"dialog","aria-label":"History",children:[r("div",{class:"snapshot-panel-header",children:[r("span",{class:"snapshot-panel-title",children:"History"},void 0,!1,void 0,this),r("span",{class:"snapshot-panel-sub",children:"snapshots + sessions"},void 0,!1,void 0,this),r("span",{class:"snapshot-panel-spacer"},void 0,!1,void 0,this),r("button",{type:"button",class:"snapshot-panel-close",onClick:t,"aria-label":"Close history",children:r(Tt,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"snapshot-save-form",children:[r("input",{ref:x,type:"text",class:"snapshot-name-input",value:p,onInput:(w)=>m(w.target.value),onKeyDown:(w)=>{if(w.key==="Enter")C()},placeholder:"Save a snapshot as…","aria-label":"Snapshot name",maxLength:80,disabled:l},void 0,!1,void 0,this),r("button",{type:"button",class:"snapshot-save-btn",onClick:C,disabled:!p.trim()||l,children:l?"…":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"snapshot-restore-note",children:nt()?"Restoring replaces the current canvas. Save a snapshot first to keep your current state.":"Restoring replaces the current canvas. You can undo it if needed."},void 0,!1,void 0,this),r("div",{class:"snapshot-list",children:[s&&r("div",{class:"snapshot-empty",children:"Loading…"},void 0,!1,void 0,this),!s&&o.length===0&&r("div",{class:"snapshot-empty",children:"No history yet. Save a snapshot, or start an agent session — it snapshots for you."},void 0,!1,void 0,this),!s&&[...o.filter((w)=>Sp(w.name)===null),...o.some((w)=>Sp(w.name)!==null)?[{id:"__sessions-header__"}]:[],...o.filter((w)=>Sp(w.name)!==null)].map((w)=>{if(w.id==="__sessions-header__")return r("div",{class:"snapshot-section-header","data-testid":"history-sessions-header",children:"Sessions"},w.id,!1,void 0,this);let M=Sp(w.name),B=g[w.id];if(M!==null)return r("div",{class:"snapshot-item is-session","data-testid":"history-session",children:[r("div",{class:"snapshot-item-head",children:[r("span",{class:"snapshot-session-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("span",{class:"snapshot-item-name",children:["Agent session — ",M]},void 0,!0,void 0,this),r("span",{class:"snapshot-item-time",children:MI(w.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"snapshot-item-meta",children:["snapshot at session start · ",w.nodeCount," node",w.nodeCount!==1?"s":"",B&&B!=="loading"&&r("span",{class:"snapshot-item-diff",children:[" ","· since: ",B.added," added · ",B.removed," removed · ",B.modified," modified"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"snapshot-item-actions is-session",children:[r("button",{type:"button",class:"snapshot-action-btn snapshot-action-diff",disabled:B==="loading",onClick:()=>void _(w.id),children:B==="loading"?"Comparing…":"View diff"},void 0,!1,void 0,this),A(w,"Restore pre-state")]},void 0,!0,void 0,this)]},w.id,!0,void 0,this);return r("div",{class:"snapshot-item","data-testid":"history-snapshot",children:[r("div",{class:"snapshot-item-head",children:[r("span",{class:"snapshot-item-glyph","aria-hidden":"true",children:"◫"},void 0,!1,void 0,this),r("span",{class:"snapshot-item-name",children:w.name},void 0,!1,void 0,this),r("span",{class:"snapshot-item-time",children:MI(w.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"snapshot-item-meta",children:[w.nodeCount," node",w.nodeCount!==1?"s":"",w.edgeCount>0?` · ${w.edgeCount} edge${w.edgeCount!==1?"s":""}`:""," · ",cp(w.createdAt)]},void 0,!0,void 0,this),r("div",{class:"snapshot-item-actions",children:A(w,"Restore")},void 0,!1,void 0,this)]},w.id,!0,void 0,this)})]},void 0,!0,void 0,this),r("div",{class:"snapshot-panel-foot",children:"Every agent session start writes a snapshot automatically."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var kO=8;function $I({fallbackName:e}){let[t,n]=E(!1),o=F(null),i=F(null),s=F(null);$e(()=>{if(!t)return;let p=(f)=>{if(f.target instanceof Node&&!o.current?.contains(f.target)&&!s.current?.contains(f.target))n(!1)},m=(f)=>{if(f.key==="Escape")f.stopPropagation(),n(!1),i.current?.focus()};return document.addEventListener("pointerdown",p,!0),document.addEventListener("keydown",m,!0),()=>{document.removeEventListener("pointerdown",p,!0),document.removeEventListener("keydown",m,!0)}},[t]);let a=Qn(),l=!Wn.value?e:a&&!pt.value?a.name:"Home",c=Ge.value.filter((p)=>pt.value||p.id!==ie.value).slice(0,kO),u=i.current?.getBoundingClientRect(),d=(p)=>{n(!1),Mn(p)};return r("span",{class:"board-switcher",ref:o,children:[r("button",{ref:i,type:"button",class:"top-bar-title board-switcher-button","aria-haspopup":"menu","aria-expanded":t,"aria-label":`Board: ${l}. Switch board`,onClick:()=>n((p)=>!p),children:[r("span",{class:"board-switcher-name",children:l},void 0,!1,void 0,this),r("span",{class:"board-switcher-caret","aria-hidden":"true",children:r(oa,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&u&&r(ia,{children:r("div",{ref:s,class:"toolbar-menu board-switcher-menu",role:"menu","aria-label":"Boards",style:{position:"fixed",left:`min(${u.left}px, max(12px, calc(100vw - 352px)))`,top:`${u.bottom+8}px`,right:"auto",maxHeight:`min(70vh, calc(100dvh - ${u.bottom+20}px))`},children:[c.length>0&&r("div",{class:"board-switcher-heading",children:"Recent boards"},void 0,!1,void 0,this),r("div",{class:"board-switcher-recents",children:c.map((p)=>r("div",{class:"board-switcher-row",children:[r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>d(p.id),children:[r("span",{class:"board-switcher-icon","aria-hidden":"true",children:r(cd,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"board-switcher-item-copy",children:[r("span",{class:"board-switcher-item-name",children:p.name},void 0,!1,void 0,this),r("span",{class:"board-switcher-item-folder",children:p.folder?.split("/").join(" / ")||"Unfiled"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"board-switcher-item-meta",children:[p.nodeCount," ",p.nodeCount===1?"node":"nodes"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r(go,{board:p},void 0,!1,void 0,this)]},p.id,!0,void 0,this))},void 0,!1,void 0,this),r("div",{class:"board-switcher-actions",children:[r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>{n(!1),Dg()},children:[r("span",{class:"board-switcher-icon","aria-hidden":"true",children:r($S,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),"New board…"]},void 0,!0,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>d(null),children:[r("span",{class:"board-switcher-icon","aria-hidden":"true",children:r(Pr,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),"All boards (Home)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var LI=3,OI={"waiting-approval":0,thinking:1,tooling:2,idle:3};function SO(){let[e,t]=E(null),n=F(null);$e(()=>{if(!e)return;let d=(f)=>{if(!n.current?.contains(f.target)&&!e.button.contains(f.target))t(null)},p=(f)=>{if(f.key==="Escape"&&!f.defaultPrevented)f.preventDefault(),t(null),e.button.focus({preventScroll:!0})},m=()=>t(null);return document.addEventListener("pointerdown",d,!0),document.addEventListener("keydown",p),window.addEventListener("resize",m),()=>{document.removeEventListener("pointerdown",d,!0),document.removeEventListener("keydown",p),window.removeEventListener("resize",m)}},[e]);let o=Sa.value;if(G(()=>{if(e&&!e.button.isConnected)t(null)},[o,e]),!kt.value||o.length===0)return null;let i=o.filter((d)=>!d.parentAgentId||!o.some((p)=>p.sessionId!==d.sessionId&&!p.parentAgentId&&(p.sessionId===d.parentAgentId||p.source===d.parentAgentId))),s=[...i].sort((d,p)=>(OI[d.phase]??4)-(OI[p.phase]??4)),a=s.slice(0,LI),l=s.slice(LI),c=i.reduce((d,p)=>(d[p.phase]=(d[p.phase]??0)+1,d),{}),u=[c["waiting-approval"]&&`${c["waiting-approval"]} waiting on approval`,c.thinking&&`${c.thinking} thinking`,c.tooling&&`${c.tooling} running tools`,c.idle&&`${c.idle} idle`].filter(Boolean).join(", ");return r(be,{children:[r("span",{class:"agent-chips",children:a.map((d)=>{let p=d.parentAgentId?0:en.value.filter((m)=>m.parentAgentId!=null&&(m.parentAgentId===d.sessionId||m.parentAgentId===d.source)).length;return r(_e,{label:`Agent session — ${d.label}`,tapToOpen:!0,body:"What this attached agent is doing right now: idle, thinking, running a tool, or waiting on your approval. Steer it from the composer below.",children:r("span",{class:`agent-chip phase-${d.phase}`,"data-phase":d.phase,style:{"--identity-color":_o(d.sessionId)},children:[r("button",{type:"button",class:"agent-chip-initial","aria-label":`${d.label} session details`,"aria-expanded":e?.id===d.sessionId,"aria-haspopup":"dialog",onClick:(m)=>{m.stopPropagation(),t(e?.id===d.sessionId?null:{id:d.sessionId,button:m.currentTarget})},children:[Ud(d.label),r("span",{class:"agent-chip-dot","aria-hidden":"true"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"agent-chip-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("span",{class:"agent-chip-label",children:vi(d)},void 0,!1,void 0,this),r("span",{class:"agent-chip-who hud-collapsible-text",children:d.label},void 0,!1,void 0,this),r(DI,{session:d},void 0,!1,void 0,this),p>0&&r("span",{class:"agent-chip-workers",children:["+",p," worker",p===1?"":"s"]},void 0,!0,void 0,this),r("button",{type:"button",class:"agent-chip-end","aria-label":`End ${d.label} session`,onClick:(m)=>{m.stopPropagation(),ic({source:d.source,agentId:d.agentId})},children:r(Tt,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},d.sessionId,!1,void 0,this)})},void 0,!1,void 0,this),l.length>0&&r(_e,{label:`${i.length} agent sessions attached`,tapToOpen:!0,body:`${i.length} agents on this board — ${u}. The most active wear their own chips; the rest are here, and idle agents' cursors leave the board until they work again.`,children:r("span",{class:"agent-chip agent-chip-more","data-testid":"agent-chip-more",children:["+",l.length," · ",i.length," agents"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),e&&a.filter((d)=>d.sessionId===e.id).map((d)=>r(ia,{children:r("div",{ref:n,class:`agent-session-popover phase-${d.phase}`,role:"dialog","aria-label":`${d.label} session details`,style:{right:`${Math.max(12,window.innerWidth-e.button.getBoundingClientRect().right)}px`,top:`${e.button.getBoundingClientRect().bottom+8}px`},children:[r("div",{class:"agent-session-popover-head",children:[r("span",{class:"agent-chip-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("strong",{children:[d.label," · ",vi(d)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r(DI,{session:d,popover:!0},void 0,!1,void 0,this),r("button",{type:"button",class:"session-receipt-link",onClick:()=>{to.value=!0,t(null)},children:"Open session panel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},d.sessionId,!1,void 0,this))]},void 0,!0,void 0,this)}function DI({session:e,popover:t=!1}){let n=e.session,o=n?[["read",n.read.length],["created",n.created.length],["edited",n.edited.length],["pinned",n.pinned.length]].filter(([,l])=>l>0):[],i=Hn.value,s=i?.kind==="live"&&i.sessionId===e.sessionId;if(o.length===0&&!s&&!t)return null;let a=o.map(([l,c])=>`${c} ${l}`).join(" · ")||"nothing yet";if(t)return r(be,{children:[r("span",{class:"agent-session-counts",children:a},void 0,!1,void 0,this),r("button",{type:"button",role:"switch","aria-checked":s,class:`session-receipt-lens${s?" is-on":""}`,onClick:()=>sc(!s,{sessionId:e.sessionId}),children:[r("span",{class:"session-receipt-lens-track","aria-hidden":"true",children:r("span",{class:"session-receipt-lens-knob"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Dim untouched nodes"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return r("button",{type:"button",class:`agent-chip-touches${s?" is-on":""}`,"aria-pressed":s,"aria-label":`This session: ${o.map(([l,c])=>`${c} ${l}`).join(", ")||"nothing yet"}. ${s?"Show all cards":"Dim untouched cards"}`,onClick:(l)=>{l.stopPropagation(),sc(!s,{sessionId:e.sessionId})},children:a},void 0,!1,void 0,this)}function _O(){let e=To.value.length,t=e>0,n=rr(t?1000:0);if(!t)return null;let o=To.value.map((i)=>wp(i,n)).filter((i)=>i!==null).sort((i,s)=>i-s)[0];return r(_e,{label:"Approval gates waiting on you",body:"Open agent controls to approve or reject. Unanswered gates auto-hold when the countdown runs out, even with the session beta off.",children:r("button",{type:"button",class:"gate-badge",onClick:()=>to.value=!0,children:[e," gate",e===1?"":"s",o!==void 0&&` · ${kp(o)}`]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function CO(){let[e,t]=E(!1);if(!kt.value||xi.value)return null;return r(_e,{label:"Start an agent session",body:"Attaches a session to this board: the next agent that writes here is adopted into it, and you get the panel, composer, and receipt.",children:r("button",{type:"button",class:"start-session-btn","aria-label":"Start agent session beta",disabled:e,onClick:()=>{t(!0),_i().finally(()=>t(!1))},children:[r("span",{class:"start-session-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("span",{class:"start-session-label",children:"Start agent session"},void 0,!1,void 0,this),r("span",{class:"beta-tag",children:"beta"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function BI(){let e=F(null);$e(()=>{let g=e.current,v=g?.querySelector(".top-bar-right");if(!g||!v)return;let b=()=>{let y=g.querySelector('.top-bar-more [aria-expanded="true"]');g.classList.remove("is-folded","is-compact");let k=()=>v.getBoundingClientRect().right>g.getBoundingClientRect().right-14;if(y||k())g.classList.add("is-folded");if(k())g.classList.add("is-compact")},x=new ResizeObserver(b);x.observe(g);let C=new MutationObserver(b);return C.observe(g,{childList:!0,characterData:!0,subtree:!0}),b(),()=>{x.disconnect(),C.disconnect()}},[]);let t=lo.value,n=un.value,o=Ae.value,i=Z.value.size,s=tt.value.size,a=Ys.value,l=Array.from(Z.value.values()).filter((g)=>g.type==="trace").length,[c,u]=E("");G(()=>{let g=!1;return Gt("/health").then((v)=>v.ok?v.json():null).then((v)=>{if(g||typeof v?.workspace!=="string"||!v.workspace)return;let b=v.workspace.replace(/[\\/]+$/,"").split(/[\\/]/).pop();if(b)u(b)}).catch(()=>{}),()=>{g=!0}},[]);let d=Pg.value,p=d??(t==="connected"&&!n?"syncing":t),m=Qn(),f=n?[`${i} node${i!==1?"s":""}`,...s>0?[`${s} edge${s!==1?"s":""}`]:[],...l>0?[`${l} trace${l!==1?"s":""}`]:a?["trace armed"]:[]].join(" · "):"Syncing canvas…",h=()=>{let g=Jt();ta(g.width,g.height)};return r("div",{class:"top-bar",ref:e,children:[r(_e,{label:`Canvas status: ${p}`,tapToOpen:!0,body:"Live updates stream in over SSE; amber means reconnecting.",align:"start",children:r("span",{class:`connection-dot ${d??t}`,"aria-label":`Canvas status: ${p}`},void 0,!1,void 0,this)},void 0,!1,void 0,this),r($I,{fallbackName:c||"PMX Canvas"},void 0,!1,void 0,this),m&&!pt.value&&r(go,{board:m},void 0,!1,void 0,this),r("span",{class:"top-bar-meta hud-collapsible-text",children:Cr.value?Cr.value.slice(0,12):"…"},void 0,!1,void 0,this),!pt.value&&r("span",{class:"top-bar-meta hud-collapsible-text",children:f},void 0,!1,void 0,this),r("span",{class:"top-bar-spacer"},void 0,!1,void 0,this),r("div",{class:"top-bar-right",children:[r(SO,{},void 0,!1,void 0,this),r(_O,{},void 0,!1,void 0,this),r(wT,{},void 0,!1,void 0,this),r(lI,{},void 0,!1,void 0,this),!nt()&&r(CO,{},void 0,!1,void 0,this),!pt.value&&r(be,{children:[r("div",{class:"top-bar-sep"},void 0,!1,void 0,this),r("div",{class:"top-bar-actions",children:[ie.value&&r(_e,{label:"Export board",body:"One HTML file of this board that anyone can open, no install needed.",children:r("button",{type:"button",class:"present-button",onClick:()=>{fs.value=!0},children:"Export"},void 0,!1,void 0,this)},void 0,!1,void 0,this),ie.value&&r(_e,{label:"Present board",body:"Arrow keys or Space step through stops; Esc exits. Without a saved tour, groups are read top-to-bottom, left-to-right.",children:r("button",{type:"button",class:"present-button",onClick:()=>{Ll()},children:"Present"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Zoom out",shortcut:Ht("−"),children:r("button",{type:"button",class:"top-bar-btn",onClick:()=>ci(0.8),"aria-label":"Zoom out",children:r(FS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Reset zoom",shortcut:Ht("0"),children:r("button",{type:"button",class:"top-bar-zoom-label",onClick:()=>Ar({x:0,y:0,scale:1},250),"aria-label":"Reset view",children:[Math.round(o.scale*100),"%"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Zoom in",shortcut:Ht("+"),children:r("button",{type:"button",class:"top-bar-btn",onClick:()=>ci(1.25),"aria-label":"Zoom in",children:r(HS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Fit all",shortcut:"F",align:"end",children:r("button",{type:"button",class:"top-bar-btn",onClick:h,"aria-label":"Fit canvas",children:r(ad,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(TO,{boardOpen:!!ie.value,onFit:h},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function TO({boardOpen:e,onFit:t}){let[n,o]=E(!1),i=F(null),s=F(null);$e(()=>{if(!n)return;let l=()=>[...i.current?.querySelectorAll('[role="menuitem"]')??[]];l()[0]?.focus();let c=(d)=>{if(d.key==="Escape")o(!1),s.current?.focus();else if(d.key==="ArrowDown"||d.key==="ArrowUp"){d.preventDefault();let p=l(),m=p.indexOf(document.activeElement),f=d.key==="ArrowDown"?m+1:m-1;p[(f+p.length)%p.length]?.focus()}},u=(d)=>{if(i.current&&!i.current.contains(d.target))o(!1)};return window.addEventListener("keydown",c),window.addEventListener("pointerdown",u),()=>{window.removeEventListener("keydown",c),window.removeEventListener("pointerdown",u)}},[n]);let a=(l)=>()=>{o(!1),l()};return r("div",{class:"top-bar-more",ref:i,children:[r("button",{ref:s,type:"button",class:"top-bar-btn","aria-label":"More: export, present, zoom, fit","aria-haspopup":"menu","aria-expanded":n,onClick:()=>o(!n),children:"⋯"},void 0,!1,void 0,this),n&&r("div",{class:"toolbar-menu top-bar-more-menu",role:"menu",children:[e&&r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>{fs.value=!0}),children:"Export board"},void 0,!1,void 0,this),e&&r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>void Ll()),children:"Present board"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>ci(1.25)),children:"Zoom in"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>ci(0.8)),children:"Zoom out"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>Ar({x:0,y:0,scale:1},250)),children:"Reset zoom"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(t),children:"Fit all"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Ci={status:{x:40,y:80,w:300,h:120},markdown:{x:380,y:80,w:720,h:600},context:{x:1130,y:80,w:320,h:400},"mcp-app":{x:380,y:720,w:960,h:600},webpage:{x:380,y:80,w:520,h:420},"json-render":{x:380,y:720,w:840,h:620},graph:{x:380,y:720,w:760,h:520},board:{x:380,y:80,w:360,h:160},ledger:{x:1130,y:520,w:320,h:280},trace:{x:40,y:900,w:200,h:56},file:{x:380,y:80,w:720,h:600},diff:{x:380,y:80,w:640,h:420},mermaid:{x:380,y:80,w:640,h:460},image:{x:380,y:80,w:720,h:520},html:{x:380,y:80,w:720,h:640},group:{x:220,y:60,w:840,h:560},prompt:{x:380,y:1260,w:520,h:400},response:{x:380,y:1480,w:720,h:400}};function yc(e,t,n,o={}){let i=Ci[t];return{id:e,type:t,position:o.position??{x:i.x,y:i.y},size:o.size??{width:i.w,height:i.h},zIndex:t==="status"?0:1,collapsed:!1,pinned:!1,data:n}}var Ti=null,bc=null,_p=0,Ii=null,IO=3000,EO=2000,AO=1000,RO=80,HI=5000,PO=1e4,vc=!1,Br=null,Na=null,Pa=null,hs=0,Ei=null;function NO(){if(nt())return"poll";if(typeof location>"u"||typeof window>"u")return null;let e=new URLSearchParams(location.search).get("transport");if(e==="poll"||e==="sse")return e;if(window.__PMX_AMP_ORB===!0)return"poll";return null}var Ma=new Map;function xc(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t).toString(36)}function Ep(e){if(!bc)return e;let t=bc.get(e.id);if(!t)return e;return{...e,position:t.position??e.position,size:t.size??e.size,collapsed:t.collapsed??e.collapsed,pinned:t.pinned??e.pinned}}function wc(e,t,n){return Ep(yc(e,t,n))}function MO(){return $d([...Z.value.values()],Ci.markdown.w,Ci.markdown.h)}function $a(){if(!Z.value.has("status-main"))Ir(wc("status-main","status",{phase:"idle",message:"",elapsed:0}))}function zO(e,t){let n=`md-${xc(e)}`;if(Z.value.get(n))Je(n,{path:e,title:t}),xt.value=n;else{let i=MO(),s=wc(n,"markdown",{path:e,title:t,content:"",rendered:""});s.position=i,Ir(s),$t(n)}}function $O(e){if(Z.value.get("context-main"))Je("context-main",{cards:e});else if(e.length>0){let o=wc("context-main","context",{cards:e});Ir(o)}}function LO(e){let t=e.url,n=`mcp-${xc(t)}`;if(Z.value.get(n))Je(n,e);else Ir(wc(n,"mcp-app",e)),$t(n)}function OO(e){let t=e.toolCallId,o=(typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null)??(t.startsWith("ext-app-")?t:`ext-app-${t}`);if(Z.value.get(o)){Je(o,e);return}let{serverName:s,toolName:a}=e;if(s&&a){for(let[v,b]of Z.value.entries())if(b.type==="mcp-app"&&b.data.mode==="ext-app"&&b.data.serverName===s&&b.data.toolName===a&&!b.data.toolResult){Je(v,{...e});return}}let{_x:l,_y:c,_width:u,_height:d}=e,p=Ci["mcp-app"],m=u??p.w,f=d??p.h,h=l===void 0||c===void 0?$d([...Z.value.values()],m,f):null,g=Ep(yc(o,"mcp-app",{mode:"ext-app",...e},{position:{x:l??h?.x??p.x,y:c??h?.y??p.y},size:{width:m,height:f}}));Ir(g),$t(o,{recordHistory:!1})}function DO(e){let t=e.startsWith("ext-app-")?e:`ext-app-${e}`;if(Z.value.has(t))return t;let n=`ext-app-${e}`;if(n!==t&&Z.value.has(n))return n;for(let[o,i]of Z.value.entries())if(i.type==="mcp-app"&&i.data.mode==="ext-app"&&i.data.toolCallId===e)return o;return null}function ZI(e){let t=typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null;if(t&&Z.value.has(t))return t;if(typeof e.toolCallId!=="string"||!e.toolCallId)return null;return DO(e.toolCallId)}function WI(e,t){if(typeof e!=="string"||!e)return null;if(typeof t!=="string"||!t)return null;let n=null;for(let[o,i]of Z.value.entries())if(i.type==="mcp-app"&&i.data.mode==="ext-app"&&i.data.serverName===e&&i.data.toolName===t&&!i.data.toolResult){if(n)return null;n=o}return n}function qI(e){if(Z.value.get("ledger-main"))Je("ledger-main",e);else{let o=wc("ledger-main","ledger",e);o.collapsed=!0,Ir(o)}}function Zg(e){if(!Jl(e))return;if(document.documentElement.setAttribute("data-theme",e),va(),Qt.value!==e)Qt.value=e}function BO(e){return e==="markdown"||e==="mcp-app"||e==="webpage"||e==="json-render"||e==="graph"||e==="board"||e==="prompt"||e==="response"||e==="status"||e==="context"||e==="ledger"||e==="trace"||e==="file"||e==="diff"||e==="mermaid"||e==="image"||e==="html"||e==="group"}function HO(e){return e==="relation"||e==="depends-on"||e==="flow"||e==="references"}function Wg(e){if(!e||typeof e!=="object")return null;let t=e;if(typeof t.x!=="number"||typeof t.y!=="number")return null;return{x:t.x,y:t.y}}function GI(e){if(!e||typeof e!=="object")return null;let t=e;if(typeof t.width!=="number"||typeof t.height!=="number")return null;return{width:t.width,height:t.height}}function FO(e){let t=Wg(e),n=GI(e);return t&&n?{...t,...n}:null}function jO(e){if(typeof e.id!=="string"||!e.id)return null;if(!BO(e.type))return null;let t=Wg(e.position),n=GI(e.size);if(!t||!n)return null;let o=e.data&&typeof e.data==="object"?Object.fromEntries(Object.entries(e.data)):{};return{id:e.id,type:e.type,position:t,size:n,zIndex:typeof e.zIndex==="number"?e.zIndex:1,collapsed:e.collapsed===!0,pinned:e.pinned===!0,contentRevision:typeof e.contentRevision==="number"?e.contentRevision:0,linksRevision:typeof e.linksRevision==="number"?e.linksRevision:0,...Ip(e.createdBy)?{createdBy:e.createdBy}:{},...Ip(e.lastEditedBy)?{lastEditedBy:e.lastEditedBy}:{},data:o}}function Ip(e){if(!e||typeof e!=="object")return!1;let t=e;return typeof t.actor==="string"&&typeof t.source==="string"}function UO(e){if(typeof e.id!=="string"||!e.id)return null;if(typeof e.from!=="string"||!e.from)return null;if(typeof e.to!=="string"||!e.to)return null;if(!HO(e.type))return null;return{id:e.id,from:e.from,to:e.to,...typeof e.toBoardId==="string"?{toBoardId:e.toBoardId}:{},type:e.type,...typeof e.kind==="string"?{kind:e.kind}:{},...typeof e.reason==="string"?{reason:e.reason}:{},...typeof e.label==="string"?{label:e.label}:{},...e.style==="solid"||e.style==="dashed"||e.style==="dotted"?{style:e.style}:{},...e.animated===!0?{animated:!0}:{},...typeof e.revision==="number"?{revision:e.revision}:{},...Ip(e.changedBy)?{changedBy:e.changedBy}:{},...typeof e.changedAt==="string"?{changedAt:e.changedAt}:{},...Ip(e.createdBy)?{createdBy:e.createdBy}:{},...typeof e.createdAt==="string"?{createdAt:e.createdAt}:{}}}function ZO(e){if(typeof e.id!=="string"||!e.id)return null;if(e.type!=="freehand"&&e.type!=="text")return null;if(!Array.isArray(e.points))return null;let t=e.points.map((o)=>Wg(o)).filter((o)=>o!==null),n=FO(e.bounds);if(t.length<(e.type==="text"?1:2)||!n)return null;return{id:e.id,type:e.type,points:t,bounds:n,color:typeof e.color==="string"?e.color:"#f97316",width:typeof e.width==="number"?e.width:4,...typeof e.text==="string"?{text:e.text}:{},...typeof e.label==="string"?{label:e.label}:{},createdAt:typeof e.createdAt==="string"?e.createdAt:""}}var FI="pmx-canvas-version-reload";function WO(e,t){if(typeof window>"u")return;let n=window,o=(s,a)=>typeof s==="string"&&s!==""&&s!=="unknown"&&typeof a==="string"&&a!==""&&a!=="unknown"&&s!==a;if(!o(e,n.__PMX_BOOT_SERVER_VERSION)&&!o(t,n.__PMX_BOOT_BUNDLE_STAMP))return;let i=`${String(e)}::${String(t)}`;try{if(window.sessionStorage.getItem(FI)===i)return;window.sessionStorage.setItem(FI,i)}catch{return}window.location.reload()}function qO(e){let t=bi.value[0]?.id;if(yC(e),Co.value&&bi.value[0]?.id!==t)Si()}function GO(e){FC(e)}var gs=0,jg=0,za=null;function KO(e){wf(e)}function VO(e){let t=za;if(za=null,e){if(t?.boardId===ie.value)Tp(t);return}let n=ie.value,o=++gs;if(bc=null,un.value=!1,zu(),hS(),Fu(),Kf({nodes:[],edges:[]}),t?.boardId===ie.value)Tp(t);if(ie.value===null)Yd();if(Hn.value?.kind==="receipt")Hn.value=null;lg({}),co.value=null,qg();let i=jg,s=Oo;jk(n).then((a)=>{if(o===gs&&i===jg)Tp({layout:a,boardId:n})}),pe("fetchPinnedContext","/api/canvas/pinned-context",{}).then((a)=>{if(o===gs&&s===Oo)KI({nodeIds:a.nodeIds})})}eS(VO);function XO(e){if(ko.value++,gs++,za=null,un.value=!1,typeof e.catalogEpoch==="string")Qk(e.catalogEpoch);if(!nt()&&typeof e.workbenchToken==="string")window.__PMX_WORKBENCH_TOKEN=e.workbenchToken;if(Cr.value=e.sessionId||"",uf(e.workspaceSettings),lo.value="connected",Al().then(ii),Xi.value+=1,WO(e.version,e.bundleStamp),nc(),Dr(),kl(),!ju&&!nt())Ik();if(pe("fetchHumanPresence","/api/canvas/human-presence",null).then(wf),qg().then(()=>{if(Co.value)Si()}),typeof e.theme==="string"&&!Ng())Zg(e.theme);if(e.ledgerSummary)qI(e.ledgerSummary)}function JO(e){if(typeof e.path!=="string"||!e.path)return;let t=e.path,n=(typeof e.title==="string"?e.title:"")||t.split("/").pop()||"Untitled";if(zO(t,n),e.ledgerSummary)qI(e.ledgerSummary)}function YO(e){$a(),Je("status-main",{message:typeof e.message==="string"?e.message:String(e.message??""),level:e.level??"ok",source:e.source})}function QO(e){$a(),Je("status-main",{phase:e.phase,detail:e.detail})}function eD(e){let t=e.cards??[];$O(t)}function tD(e){if(typeof e.url==="string"&&e.url)LO({url:e.url,sourceServer:e.sourceServer,sourceTool:e.sourceTool,inferredType:e.inferredType,trustedDomain:e.trustedDomain,hostMode:e.hostMode??"hosted"})}function nD(e){let t=e.sessions??[];for(let n of t){let o=n.url;if(!o)continue;let i=`mcp-${xc(o)}`;if(Z.value.has(i))Je(i,{sessionState:n.state,lastSeenAt:n.lastSeenAt})}}function oD(e){if(typeof e.url==="string"&&e.url){let t=`mcp-${xc(e.url)}`;if(Z.value.has(t))Je(t,{hostMode:"fallback",fallbackReason:e.reasonCode})}}function rD(e){let n=Z.value.get("context-main");if(!n)return;let o=(n.data.auxTabs??[]).concat(e);Je("context-main",{auxTabs:o})}function iD(e){if(Z.value.has("context-main"))if(e.mode==="all")Je("context-main",{auxTabs:[]});else{let o=Z.value.get("context-main");if(!o)return;let i=(o.data.auxTabs??[]).filter((s)=>s.id!==e.id);Je("context-main",{auxTabs:i})}}function sD(e){$a(),Je("status-main",{phase:"idle",lastCompletion:{tokenCount:e.tokenCount,artifactCount:e.artifactCount}})}function aD(e){$a(),Je("status-main",{phase:"tooling",detail:`${e.name}`,activeTool:e.name})}function lD(e){$a(),Je("status-main",{activeTool:null})}function cD(e){if(e.state==="active"&&e.path){let n=`md-${xc(e.path)}`;if(Z.value.has(n))Je(n,{reviewActive:!0})}}function uD(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;OO({toolCallId:e.toolCallId,...typeof e.nodeId==="string"&&e.nodeId.length>0?{nodeId:e.nodeId}:{},title:e.title,html:e.html,toolInput:e.toolInput,serverName:e.serverName,toolName:e.toolName,appSessionId:e.appSessionId,resourceUri:e.resourceUri,toolDefinition:e.toolDefinition,resourceMeta:e.resourceMeta,hostMode:"hosted",trustedDomain:!0,...e.chartConfig?{chartConfig:e.chartConfig}:{},...typeof e.x==="number"&&{_x:e.x},...typeof e.y==="number"&&{_y:e.y},...typeof e.width==="number"&&{_width:e.width},...typeof e.height==="number"&&{_height:e.height}})}function dD(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=ZI(e)??WI(e.serverName,e.toolName);if(!t)return;if(Z.value.has(t))Je(t,{html:e.html})}function pD(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=ZI(e)??WI(e.serverName,e.toolName);if(!t)return;if(Z.value.has(t)){if(e.success===!1){li(t);return}Je(t,{toolResult:Yh({result:e.result,success:typeof e.success==="boolean"?e.success:void 0,error:typeof e.error==="string"?e.error:void 0,content:typeof e.content==="string"?e.content:void 0,detailedContent:typeof e.detailedContent==="string"?e.detailedContent:void 0})})}}function mD(e){$a(),Je("status-main",{subagent:{state:e.state,name:e.agentDisplayName??e.agentName}})}function fD(e){let t=e.nodeId;if(!t)return;let n=e.text||"",{position:o,parentNodeId:i,contextNodeIds:s}=e;if(e.threadNodeId&&Z.value.has(e.threadNodeId)){let a=e.threadNodeId,l=Z.value.get(a);if(!l)return;let c=Array.isArray(l.data.turns)?[...l.data.turns]:[],u=c[c.length-1];if(!u||u.role!=="user"||u.text!==n)c.push({role:"user",text:n,status:"pending"});Je(a,{turns:c,threadStatus:"pending"});return}if(!Z.value.has(t)){let a=o??Ci.prompt;Ir(Ep(yc(t,"prompt",{text:n,turns:n?[{role:"user",text:n,status:"pending"}]:[],threadStatus:n?"pending":"draft",status:n?"pending":"draft",parentNodeId:i,contextNodeIds:s},{position:{x:a.x,y:a.y}}))),$t(t)}if(i&&Z.value.has(i))Ks({id:`edge-${i}-${t}`,from:i,to:t,type:"flow",style:"dashed"})}function hD(e){let{nodeId:t,status:n}=e;if(t&&Z.value.has(t))Je(t,{status:n})}function gD(e){let{responseNodeId:t,promptNodeId:n}=e;if(!t)return;let o=n?Z.value.get(n):void 0;if(o&&Array.isArray(o.data.turns)){Ma.set(t,n);let s=[...o.data.turns];s.push({role:"assistant",text:"",status:"streaming"}),Je(n,{turns:s,threadStatus:"streaming",_activeResponseId:t}),$t(n);return}let i=o?{x:o.position.x,y:o.position.y+o.size.height+24}:{x:Ci.response.x,y:Ci.response.y};if(!Z.value.has(t))Ir(Ep(yc(t,"response",{content:"",status:"streaming",promptNodeId:n},{position:i})));if(n)Ks({id:`edge-${n}-${t}`,from:n,to:t,type:"flow",animated:!0});$t(t)}function yD(e){let t=e.responseNodeId;if(!t)return;let n=Ma.get(t);if(n){let o=Z.value.get(n);if(o&&Array.isArray(o.data.turns)){let i=[...o.data.turns],s=i[i.length-1];if(s&&s.role==="assistant")s.text=e.content,s.status="streaming";Je(n,{turns:i,threadStatus:"streaming"})}return}if(!Z.value.has(t))return;Je(t,{content:e.content,status:"streaming"})}function vD(e){let t=e.responseNodeId;if(!t)return;let n=Ma.get(t);if(n){let s=Z.value.get(n);if(s&&Array.isArray(s.data.turns)){let a=[...s.data.turns],l=a[a.length-1];if(l&&l.role==="assistant")l.text=e.content,l.status="complete";Je(n,{turns:a,threadStatus:"answered",_activeResponseId:void 0})}Ma.delete(t);return}if(!Z.value.has(t))return;Je(t,{content:e.content,status:"complete"});let i=Z.value.get(t)?.data.promptNodeId;if(i){let s=`edge-${i}-${t}`,a=tt.value.get(s);if(a)SS(s),Ks({...a,animated:!1})}}function Tp(e){ko.value++;let t=e.layout;if(!t?.nodes)return;if(typeof e.boardGeneration==="number"){if(e.catalogEpoch!==In||$o!==null&&e.boardGeneration<$o)return;if($o===null||e.boardGeneration>$o){za=e;return}}if(e.boardId!==void 0&&e.boardId!==ie.value){za=e;return}jg+=1;let n=!un.value;un.value=!0;let o=t.nodes.map(jO).filter((l)=>l!==null),i=Array.isArray(t.edges)?t.edges.map(UO).filter((l)=>l!==null):Array.from(tt.value.values()),s=Array.isArray(t.annotations)?t.annotations.map(ZO).filter((l)=>l!==null):void 0,a=t.viewport?{x:typeof t.viewport.x==="number"?t.viewport.x:0,y:typeof t.viewport.y==="number"?t.viewport.y:0,scale:typeof t.viewport.scale==="number"?t.viewport.scale:1}:void 0;if(n)po();Kf({...a?{viewport:a}:{},nodes:o,edges:i,...s?{annotations:s}:{}},{applyViewport:n}),Cl({event:"canvas-layout-update",data:e}),Dr(1000)}function bD(e){if(e<=1)return 500;if(e===2)return 1000;return Math.min(2500,1500+(e-3)*500)}function xD(e){if(Jf())return;let t=e.nodeId;if(t&&Z.value.has(t)){if(e.noPan===!0){Er(t);return}$t(t)}}function wD(e){if(Jf()||e.clientId===ni)return;let t=e.viewport;if(!t)return;let n=typeof t.x==="number"?t.x:0,o=typeof t.y==="number"?t.y:0,i=typeof t.scale==="number"?t.scale:1;po(),qf({x:n,y:o,scale:i})}function kD(e){if(Do.value)return;if(!Ln.value&&e.present!==!0)return;let t=Su.safeParse(e.stop);if(t.success)RS(t.data)}function SD(){if(Do.value)return;Ln.value=!1,Qo.value=""}function _D(e){if(Do.value)return;let t=Su.safeParse(e.stop);if(!t.success)return;try{Yf(t.data,Ln.value?void 0:(n)=>{Ku(n,{recordHistory:!1})})}catch{let n=fl.safeParse(e.viewport);if(!n.success)return;po(),qf(n.data)}}function CD(e){if(Z.value.get("context-main"))Je("context-main",{currentTokens:e.currentTokens,tokenLimit:e.tokenLimit,messagesLength:e.messagesLength,utilization:e.utilization,nearLimit:e.nearLimit})}function TD(e){Ys.value=e.enabled===!0}function ID(e){if(typeof e.theme==="string"&&!Ng())Zg(e.theme)}function KI(e){ko.value++;let t=Array.isArray(e.nodeIds)?e.nodeIds.filter((n)=>typeof n==="string"):[];if(Vi===0)Uf(t);Cl({event:"context-pins-changed",data:e}),nc(),Dr()}function ED(){nc(),Dr()}var Cp=null,Ug=0;async function qg(){let e=++Ug,t=gs,n=await Wk();if(e===Ug&&t===gs)co.value=n}function jI(){if(Cp)clearTimeout(Cp);Ug+=1,Cp=setTimeout(()=>{if(Cp=null,qg(),Co.value)Si()},150)}function AD(e){let t=e.intent;if(!t||typeof t.id!=="string"||typeof t.kind!=="string"||typeof t.expiresAt!=="number")return;gk(t)}function RD(e){let t=typeof e.id==="string"?e.id:"";if(!t)return;if(e.settled===!0)vk(t,typeof e.nodeId==="string"?e.nodeId:void 0);else bf(t)}var VI={connected:XO,"workbench-open":JO,"canvas-status":YO,"execution-phase":QO,"context-cards":eD,"mcp-app-candidate":tD,"mcp-app-host-snapshot":nD,"mcp-app-host-fallback":oD,"aux-open":rD,"aux-close":iD,"assistant-complete":sD,"tool-start":aD,"tool-complete":lD,"review-state":cD,"subagent-status":mD,"ext-app-open":uD,"ext-app-update":dD,"ext-app-result":pD,"context-pins-changed":KI,"context-status-changed":ED,"knowledge-changed":()=>void Kt(),"lifecycle-changed":()=>void Kt(),"boards-changed":(e)=>{ai(e),Dr()},"canvas-layout-update":Tp,"canvas-focus-node":xD,"canvas-viewport-update":wD,"canvas-tour-step":kD,"canvas-tour-exit":SD,"canvas-camera-move":_D,"context-usage":CD,"trace-state":TD,"theme-changed":ID,"settings-changed":(e)=>uf(e.workspaceSettings),"canvas-prompt-created":fD,"canvas-prompt-status":hD,"canvas-response-start":gD,"canvas-response-delta":yD,"canvas-response-complete":vD,"ax-state-changed":jI,"ax-event-created":jI,"ax-intent":AD,"ax-intent-clear":RD,"agent-presence":qO,"human-presence":KO,"agent-session-ended":GO};function XI(e,t){let n=VI[e];if(!n)return;let o=n;try{o(t)}catch(i){console.warn(`[sse-bridge] Handler for "${e}" failed:`,i)}}function UI(){vc=!0,hs+=1;let e=hs;Na?.abort();let t=new AbortController;Na=t;let n=!nt();lo.value="connecting";let o=null,i=!1,s=async()=>{if(e!==hs)return;let a=new AbortController,l;try{let c=new URLSearchParams;if(Pa!==null){if(c.set("since",String(Pa)),n)c.set("waitMs",String(AO))}let u=Cr.value;if(u)c.set("session",u);let d=c.toString(),p=Oo,m=await Promise.race([(async()=>{let b=await Gt(`/api/workbench/poll${d?`?${d}`:""}`,{signal:AbortSignal.any([t.signal,a.signal])});if(!b.ok)throw Error(`poll failed with HTTP ${b.status}`);return await b.json()})(),new Promise((b,x)=>{l=setTimeout(()=>{a.abort(),x(Error("poll request timed out"))},PO)})]);if(e!==hs)return;if(!m.ok)throw Error("poll returned ok: false");let f=o;if(o=m.sessionId??null,f!==null&&m.sessionId&&f!==m.sessionId&&!m.snapshot){Pa=null,Br=setTimeout(()=>void s(),0);return}if(m.snapshot&&i)bc=Xf(),un.value=!1,Fu(),zu(),Ma.clear();let h=p===Oo&&Vi===0,g=!1,v=new Set;if(!m.snapshot&&un.value){let b;for(let x of m.events){let C=x.payload,y=C.catalogEpoch===In&&C.boardGeneration===$o&&(x.event==="boards-changed"?C.activeBoardId:C.boardId)===ie.value;if(x.event==="canvas-layout-update"&&y){if(b)v.add(b);b=x}else if(!(x.event==="boards-changed"&&y)&&!["agent-presence","human-presence","ax-intent","ax-intent-clear"].includes(x.event))b=void 0}}for(let b of m.events){if(v.has(b))continue;if(b.event==="context-pins-changed"&&!h){g=!0;continue}XI(b.event,b.payload)}if(g)Zf(),nc(),Dr();i=!0,Pa=m.seq,Ji.value=0,Yi.value=0,lo.value="connected",Br=setTimeout(()=>void s(),n?RO:EO)}catch(c){if(e!==hs)return;console.warn("[sse-bridge] poll transport error:",c),lo.value="disconnected",Ji.value+=1,Yi.value=HI,Br=setTimeout(()=>void s(),HI)}finally{clearTimeout(l)}};return s(),()=>{if(kl(),hs+=1,vc=!1,Pa=null,t.abort(),Na===t)Na=null;if(Br)clearTimeout(Br),Br=null}}function Gg(){if(gs++,za=null,CT(Zg),bc=Xf(),un.value=!1,Fu(),zu(),Ma.clear(),Ii)clearTimeout(Ii),Ii=null;let e=NO();if(e==="poll"||vc)return UI();let t=Cr.value,n=t?`/api/workbench/events?session=${t}`:"/api/workbench/events";lo.value="connecting";let o=new EventSource(n);Ti=o;let i=!1;if(Ei)clearTimeout(Ei);if(Ei=null,e!=="sse")Ei=setTimeout(()=>{if(Ei=null,i||Ti!==o)return;console.warn("[sse-bridge] No SSE event within watchdog window — switching to polling transport."),window.dispatchEvent(new Event("pmx-canvas-boot-extend")),o.close(),Ti=null,UI()},IO);for(let[s]of Object.entries(VI))o.addEventListener(s,(a)=>{if(Ti!==o)return;i=!0;try{XI(s,JSON.parse(a.data))}catch(l){console.warn(`[sse-bridge] Failed to parse "${s}" event:`,l)}});return o.onopen=()=>{if(Ti!==o)return;_p=0,Ji.value=0,Yi.value=0,lo.value="connected"},o.onerror=()=>{if(Ti!==o)return;lo.value="disconnected",o.close(),Ti=null,_p+=1;let s=bD(_p);Ji.value=_p,Yi.value=s,Ii=setTimeout(()=>{Ii=null,Gg()},s)},()=>{if(kl(),Ii)clearTimeout(Ii),Ii=null;if(Ei)clearTimeout(Ei),Ei=null;if(vc){if(hs+=1,vc=!1,Pa=null,Na?.abort(),Na=null,Br)clearTimeout(Br),Br=null}o.close(),Ti=null}}function ys(e,t){console.error(`[app] ${e} failed`,t)}var PD=Xe(()=>Z.value.size===0),JI=Xe(()=>{let e=Ct.value;return!!e&&!pt.value&&ie.value===e.boardId&&St===e.incarnation&&Z.value.has(e.nodeId)}),Kg=Xe(()=>Be.value&&JI.value);function YI(){let[e,t]=E(()=>window.innerWidth>=700),[n,o]=E(!1),[i,s]=E(!1),[a,l]=E(!1),[c,u]=E({}),[d,p]=E(!1),[m,f]=E(null),h=F(null),g=F(null),[v,b]=E(Jt),{menu:x,openNodeMenu:C,openCanvasMenu:y,openEdgeMenu:k,closeMenu:_}=AT(),A=un.value,w=Wn.value&&(ie.value===null||pt.value),M=or.value,B=kt.value,L=Co.value||To.value.length>0||ls.value.length>0||!!Io.value,Y=Kg.value;$e(()=>{if(!B){if(Hn.value=null,to.value=!1,document.activeElement?.closest(".command-bar, .session-panel, .agent-popover"))h.current?.focus({preventScroll:!0})}},[B]);let j=oe(()=>t((R)=>!R),[]),J=oe(()=>o((R)=>!R),[]),X=oe(()=>o(!1),[]),V=oe((R)=>f(R),[]),ee=oe((R)=>{rk(R),g.current=R},[]),he=oe((R,te)=>{Ar({x:R,y:te,scale:Ae.value.scale},200)},[]);return G(()=>Gg(),[]),G(()=>{let R=(te)=>{let O=te.detail;u(O??{}),l(!0)};return window.addEventListener("pmx-open-board-link",R),()=>window.removeEventListener("pmx-open-board-link",R)},[]),G(()=>{let R=null,te=()=>{if(R!==null)window.clearTimeout(R);R=window.setTimeout(()=>{R=null,ii()},400)};return window.addEventListener("resize",te),()=>{if(R!==null)window.clearTimeout(R);window.removeEventListener("resize",te)}},[]),$e(()=>{let R=(H)=>{let Me=(H.metaKey||H.ctrlKey)&&!H.altKey;if(d&&(H.key==="Escape"||H.key==="?"||H.key==="/"&&H.shiftKey)){H.preventDefault(),p(!1);return}if(pt.value||ie.value===null)return;if(H.defaultPrevented)return;if(Me&&H.key==="k"){H.preventDefault(),s((ve)=>!ve);return}if(H.key==="Escape"&&m){H.preventDefault(),f(null);return}if(H.key==="Escape"&&Kg.value){if(H.target?.closest('[role="menu"], [role="alertdialog"]'))return;H.preventDefault(),Ct.value=null;return}if(H.key==="Escape"&&Bt.value&&!Lo.value){H.preventDefault(),Rr();return}if(H.key==="Escape"&&i){H.preventDefault(),s(!1);return}let je=H.target,He=je?.tagName;if(He==="INPUT"||He==="TEXTAREA"||je?.isContentEditable)return;if(je?.closest('[role="menu"]'))return;let Re=je?.closest('[role="dialog"]');if((H.key==="Tab"||H.key.startsWith("Arrow"))&&je?.closest(".tool-rail, .top-bar"))return;if(H.key===" "&&!H.repeat&&!Me&&!Re){H.preventDefault(),zl.value=!0;return}if(H.key==="?"||H.key==="/"&&H.shiftKey){H.preventDefault(),p((ve)=>!ve);return}if(Me&&(H.key==="z"||H.key==="Z"))H.preventDefault(),gg(H.shiftKey);else if(Me&&(H.key==="y"||H.key==="Y"))H.preventDefault(),gg(!0);else if(Me&&H.key==="0")H.preventDefault(),Ar({x:0,y:0,scale:1},250);else if(Me&&(H.key==="="||H.key==="+"))H.preventDefault(),ci(1.25);else if(Me&&H.key==="-")H.preventDefault(),ci(0.8);else if(Re)return;else if(H.key==="Escape"){if(!ar(H))return;if(H.preventDefault(),Eo.value?.boardId===ie.value)Eo.value=null;No.value="All",$n(),xt.value=null,_()}else if(H.key==="Tab")H.preventDefault(),IS(H.shiftKey?-1:1);else if(H.key==="Delete"||H.key==="Backspace"){if(_r.value!==null){let D=_r.value;H.preventDefault(),_r.value=null,Xu(D).catch((re)=>ys("delete-edge",re));return}let ve=rt.value.size>0?[...rt.value]:xt.value?[xt.value]:[];if(ve.length===0)return;H.preventDefault();for(let D of ve)ri(D).catch((re)=>ys("delete",re));$n(),xt.value=null}else if(xt.value&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(H.key)){H.preventDefault();let ve=H.key.replace("Arrow","").toLowerCase();ES(ve)}else if(!Me&&!H.altKey){let ve=H.key.toLowerCase();if(ve==="v"&&!H.shiftKey)qn.value="select";else if(ve==="c"&&!H.shiftKey&&!Me)H.preventDefault(),qn.value=qn.value==="connect"?"select":"connect";else if(ve==="m"&&!H.shiftKey)H.preventDefault(),Ao({type:"markdown",title:"New note",width:520,height:360}).catch((D)=>ys("create markdown",D));else if(ve==="a"&&!H.shiftKey)H.preventDefault(),f((D)=>D==="pen"?null:"pen");else if(ve==="g"&&!H.shiftKey){H.preventDefault();let D=Array.from(rt.value);if(D.length>=2)qs({title:"Group",childIds:D}).catch((re)=>ys("group selection",re)),$n();else Ao({type:"group",title:"Group"}).catch((re)=>ys("create group",re))}else if(ve==="g"&&H.shiftKey){H.preventDefault();for(let D of bS())li(D),Gs(D).catch((re)=>ys("ungroup",re));$n()}else if(ve==="i"&&!H.shiftKey)H.preventDefault(),ps("image");else if(ve==="w"&&!H.shiftKey)H.preventDefault(),ps("webpage");else if(ve==="h"&&!H.shiftKey)H.preventDefault(),Ao({type:"html",title:"HTML surface"}).catch((D)=>ys("create html",D));else if(ve==="f"&&H.shiftKey)H.preventDefault(),ps("file");else if(ve==="f"&&!H.shiftKey){H.preventDefault();let D=Jt();ta(D.width,D.height)}}},te=(H)=>{if(H.key===" ")zl.value=!1},O=()=>{zl.value=!1};return document.addEventListener("keydown",R),document.addEventListener("keyup",te),window.addEventListener("blur",O),()=>{document.removeEventListener("keydown",R),document.removeEventListener("keyup",te),window.removeEventListener("blur",O)}},[m,_,i,d]),G(()=>{let R=window.setTimeout(()=>void ii(),250);return()=>window.clearTimeout(R)},[M]),$e(()=>{let R=g.current;if(!R)return;let te=new ResizeObserver(()=>{b(Jt()),ii();let O=Ct.value;if(O&&Kg.value)$t(O.nodeId,{recordHistory:!1})});return te.observe(R),()=>te.disconnect()},[]),G(()=>{if(!A)return;let R=window.__pmxCanvasBootstrapReady;if(typeof R==="function")R()},[A]),r("div",{class:`app-shell${Ln.value?" is-presenting":""}`,"data-session-active":M?"true":"false",children:[r(MS,{},void 0,!1,void 0,this),r(dT,{},void 0,!1,void 0,this),r(MT,{minimapVisible:e,onToggleMinimap:j,snapshotOpen:n,onToggleSnapshot:J,snapshotBtnRef:h,onOpenPalette:()=>s(!0),onOpenShortcuts:()=>p((R)=>!R),annotationTool:m,onSetAnnotationTool:V},void 0,!1,void 0,this),r("div",{class:"app-main",children:[r(BI,{},void 0,!1,void 0,this),r(kT,{},void 0,!1,void 0,this),r("div",{class:`workspace${Y?" is-reviewing":""}`,children:[r("div",{class:"canvas-region",ref:ee,children:[!pt.value&&r(gT,{onNodeContextMenu:C,onCanvasContextMenu:y,onEdgeContextMenu:k,annotationMode:m!==null,annotationTool:m},void 0,!1,void 0,this),r(XS,{},void 0,!1,void 0,this),r(WC,{},void 0,!1,void 0,this),!w&&r(qC,{},void 0,!1,void 0,this),!w&&r(cT,{},void 0,!1,void 0,this),r(VS,{},void 0,!1,void 0,this),r(cI,{},void 0,!1,void 0,this),r(uI,{},void 0,!1,void 0,this),w?r(sI,{},void 0,!1,void 0,this):A&&PD.value&&qt.value.size===0&&r(zT,{onOpenPalette:()=>s(!0)},void 0,!1,void 0,this),!w&&rt.value.size>0&&r(xI,{},void 0,!1,void 0,this),!w&&!B&&r(xT,{},void 0,!1,void 0,this),!w&&Co.value&&!nt()&&r(yT,{},void 0,!1,void 0,this),!w&&r(RI,{onOpenSnapshots:()=>o(!0)},void 0,!1,void 0,this),r(YS,{},void 0,!1,void 0,this),!pt.value&&r(aI,{},void 0,!1,void 0,this),!w&&Bt.value&&r(hI,{},void 0,!1,void 0,this),r(zI,{open:n&&!pt.value,onClose:X,anchorRef:h},void 0,!1,void 0,this),e&&!w&&r(bI,{viewport:Ae,nodes:Z,edges:tt,onNavigate:he,containerWidth:v.width,containerHeight:v.height},void 0,!1,void 0,this)]},void 0,!0,void 0,this),JI.value&&r(ET,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),M&&r(II,{},void 0,!1,void 0,this),!M&&L&&r(TI,{},void 0,!1,void 0,this),!pt.value&&x&&r(RT,{menu:x,onClose:_},void 0,!1,void 0,this),!pt.value&&i&&r(TT,{onClose:()=>s(!1),onToggleMinimap:j},void 0,!1,void 0,this),!pt.value&&a&&r(IT,{...c,onClose:()=>l(!1)},void 0,!1,void 0,this),d&&r(PI,{onClose:()=>p(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var ND=P({x:Ee(),y:Ee()}),mne=P({boardId:z().nullable(),boardName:z(),boards:Pe(P({id:z(),name:z()})),revision:z(),nodes:Pe(P({id:z(),type:z(),title:z(),text:z(),contentRevision:Ee().int().nonnegative(),editableContent:z().optional(),position:ND,size:P({width:Ee(),height:Ee()}),image:z().optional()})),edges:Pe(P({id:z(),from:z(),to:z(),label:z()})),pinnedNodeIds:Pe(z())});function QI(e,t,n=[]){let o=new Set(e.nodes.map((l)=>l.id)),i=new Set(t.filter((l)=>o.has(l)).slice(0,20)),s=new Set(e.pinnedNodeIds.filter((l)=>o.has(l)).slice(0,20)),a=new Set(n.filter((l)=>o.has(l)).slice(0,20));return{boardId:e.boardId,boardName:e.boardName,selectedNodeIds:[...i],focusedNodeIds:[...a],pinnedNodeIds:[...s],nodes:e.nodes.filter((l)=>i.has(l.id)||s.has(l.id)||a.has(l.id)).map((l)=>({id:l.id,type:l.type,title:l.title,contentRevision:l.contentRevision,text:l.text.slice(0,700)}))}}var Ai=new Zm({name:"PMX Canvas",version:"1.0.0"},{availableDisplayModes:["inline","fullscreen"]}),MD=P({status:Ee(),body:z(),contentType:z(),encoding:rn(["text","base64"])});bk(async(e,t)=>{let n=typeof e==="string"?e:e instanceof URL?e.toString():e.url,o=(t?.method??(e instanceof Request?e.method:"GET")).toUpperCase();if(t?.body!==void 0&&typeof t.body!=="string")return Response.json({ok:!1,error:"Document uploads require the local PMX workbench."},{status:403});t?.signal?.throwIfAborted();let i=await Ai.callServerTool({name:"pmx_workbench_request",arguments:{path:n,method:o,...t?.body===void 0?{}:{body:t.body},expectedBoardId:ie.value}});t?.signal?.throwIfAborted();let s=MD.parse(i._meta?.response),a=s.encoding==="base64"?Uint8Array.from(atob(s.body),(l)=>l.charCodeAt(0)):s.body;return new Response(o==="HEAD"||s.status===204?null:a,{status:s.status,headers:{"Content-Type":s.contentType}})});var zD=P({focus:Pe(z())});function $D(){let e=zD.safeParse(co.value);return QI({boardId:ie.value,boardName:Ge.value.find((t)=>t.id===ie.value)?.name??"Home",pinnedNodeIds:[...ht.value],nodes:[...Z.value.values()].map((t)=>({id:t.id,type:t.type,title:typeof t.data.title==="string"?t.data.title:t.type,contentRevision:t.contentRevision??0,text:_u(t)}))},[...rt.value],e.success?e.data.focus:[])}function LD(){let[e,t]=E(""),[n,o]=E(0),i=F(Promise.resolve()),s=$D(),a=JSON.stringify(s),l=F(a);l.current=a;let c=Ai.getHostCapabilities(),u=Wn.value;return G(()=>{if(!u||!c?.updateModelContext||e===a)return;let d=!1,p;return i.current=i.current.then(async()=>{if(d||l.current!==a)return;if(t(""),await Ai.updateModelContext({structuredContent:s}),d||l.current!==a)return;t(a)}).catch(()=>{if(!d&&l.current===a)p=setTimeout(()=>o((m)=>m+1),2000)}),()=>{d=!0,clearTimeout(p)}},[a,u,n]),r("div",{class:"pmx-host-app",children:r(YI,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)}Ai.ontoolresult=()=>{};Ai.connect().then(async()=>{if(!Ai.getHostCapabilities()?.serverTools)throw Error("This host does not support app tool calls.");if(Ai.getHostCapabilities()?.downloadFile)xk((e)=>Ai.downloadFile({contents:[{type:"resource",resource:{uri:`file:///${encodeURIComponent(e.name)}`,mimeType:e.mimeType,text:e.text}}]}));await i_(),ul(r(LD,{},void 0,!1,void 0,this),document.getElementById("app"))}).catch((e)=>{document.getElementById("app").textContent=`Could not connect PMX: ${String(e)}`});})();
|
|
10176
|
+
${a.trim()}`},void 0,!1,void 0,this),r("div",{class:"text-prompt-actions",children:[r("button",{type:"button",class:"text-prompt-cancel",onClick:e,children:"Cancel"},void 0,!1,void 0,this),r("button",{type:"submit",class:"text-prompt-confirm",disabled:!i.trim()||!a.trim(),children:["Continue on GitHub ",r(pi,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function mc(e,t){console.error(`[tool-rail] ${e} failed`,t)}function ps(e){let t={image:{message:"Image URL (https://… or data:image/…)",placeholder:"https://example.com/diagram.png"},file:{message:"Workspace file path",placeholder:"src/server/server.ts"},webpage:{message:"Page URL",placeholder:"https://example.com"}};On(t[e].message,t[e].placeholder).then((n)=>{if(!n)return;Ao({type:e,content:n}).catch((o)=>mc(`create ${e}`,o))})}function no({label:e,shortcut:t,detail:n,ariaLabel:o,active:i,menuOpen:s,onClick:a,btnRef:l,children:c}){let[u,d]=E(null),p=(h)=>{if(s)return;let g=h.currentTarget.getBoundingClientRect();d({left:g.right+10,top:g.top+g.height/2})},m=()=>d(null),f=o??(t?`${e} (${t})`:n?`${e} (${n})`:e);return r(be,{children:[r("button",{ref:l,type:"button",class:`rail-btn${i?" active":""}`,"aria-label":f,"aria-pressed":i===void 0?void 0:i,onClick:(h)=>{m(),a(h)},onPointerEnter:p,onPointerLeave:m,onFocus:p,onBlur:m,children:c},void 0,!1,void 0,this),u&&!s&&r("span",{class:"toolbar-tooltip rail-tooltip",role:"tooltip","data-testid":"rail-tooltip",style:{left:`${u.left}px`,top:`${u.top}px`},children:[r("span",{class:"toolbar-tooltip-label",children:e},void 0,!1,void 0,this),(t||n)&&r("span",{class:"toolbar-tooltip-meta",children:[t&&r("kbd",{class:"toolbar-tooltip-shortcut",children:t},void 0,!1,void 0,this),n&&r("span",{children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function sr({label:e,description:t,hint:n,beta:o,toggle:i=o,checked:s,disabled:a,onClick:l}){let c=Uw(),[u,d]=E(null),p=(f)=>d(f.currentTarget.getBoundingClientRect()),m=()=>d(null);return r(be,{children:[r("button",{type:"button",role:s===void 0?"menuitem":"menuitemcheckbox","aria-label":o?`${e} (Beta)`:e,"aria-checked":s,"aria-describedby":u?c:void 0,class:"toolbar-menu-item","aria-disabled":a||void 0,onPointerEnter:p,onPointerLeave:m,onFocus:p,onBlur:m,onClick:()=>{if(a)return;m(),l()},children:[r("span",{class:"settings-item-label",children:[e," ",o&&r("span",{class:"beta-tag",children:"Beta"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i?r("span",{class:`settings-switch${s?" is-on":""}`,"aria-hidden":"true"},void 0,!1,void 0,this):n?r("span",{class:"toolbar-menu-hint",children:n},void 0,!1,void 0,this):null]},void 0,!0,void 0,this),u&&r(ia,{children:r("span",{id:c,class:"toolbar-tooltip settings-tooltip",role:"tooltip",ref:(f)=>{if(!f)return;let h=window.innerWidth-u.right>=f.offsetWidth+20;f.style.left=`${h?u.right+10:Math.max(12,Math.min(u.left,window.innerWidth-f.offsetWidth-12))}px`,f.style.top=`${Math.max(12,Math.min(h?u.top:u.top-f.offsetHeight-8,window.innerHeight-f.offsetHeight-12))}px`},children:[r("span",{class:"toolbar-tooltip-label",children:[e,o?" (Beta)":""]},void 0,!0,void 0,this),r("span",{class:"toolbar-tooltip-body",children:t},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function MT({minimapVisible:e,onToggleMinimap:t,snapshotOpen:n,onToggleSnapshot:o,snapshotBtnRef:i,onOpenPalette:s,onOpenShortcuts:a,annotationTool:l,onSetAnnotationTool:c}){let u=qn.value,d=Ys.value,p=Array.from(Z.value.values()).filter((V)=>V.type==="trace").length,m=tt.value.size,[f,h]=E(!1),[g,v]=E(!1),[b,x]=E(!1),C=async(V)=>{if(g||!Qr.value)return;v(!0),x(!1);try{let ee=await pe("saveWorkspaceSettings","/api/canvas/settings",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({[V]:!Qr.value[V]})});x(ee.ok!==!0)}finally{v(!1)}},[y,k]=E(null),[_,A]=E(null),w=F(null),M=F(null),B=(V)=>{if(y){k(null);return}let ee=V.currentTarget.getBoundingClientRect();A({bottom:ee.bottom,right:ee.right}),k("settings")},L=(V)=>()=>{k(null),i.current?.focus(),V()},Y=_?{position:"fixed",left:`${_.right+8}px`,bottom:`${Math.max(10,window.innerHeight-_.bottom)}px`,top:"auto",right:"auto"}:void 0;$e(()=>{if(!y)return;let V=(he)=>{if(w.current&&he.target instanceof Node&&!w.current.contains(he.target))k(null)},ee=(he)=>{if(he.key==="Escape")he.preventDefault(),he.stopPropagation(),k(null),i.current?.focus({preventScroll:!0})};return document.addEventListener("pointerdown",V),document.addEventListener("keydown",ee,!0),()=>{document.removeEventListener("pointerdown",V),document.removeEventListener("keydown",ee,!0)}},[y]);let j=(V)=>{mp(),document.documentElement.setAttribute("data-theme",V),va(),Qt.value=V,Zu(V),k(null)},J=qh(Qt.value),X=(V,ee={})=>{Gt(`/api/workbench/intent?_ts=${Date.now()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:V,payload:ee})}).catch((he)=>mc("sendIntent",he))};return r(be,{children:[r("div",{class:"tool-rail",ref:w,role:"toolbar","aria-label":"Canvas tools","aria-orientation":"vertical",children:[r(no,{label:"Home",ariaLabel:"PMX Canvas — Home",onClick:()=>{k(null),Mn(null).catch((V)=>mc("openHome",V))},children:r("span",{class:"rail-brand",children:r(cd,{size:22},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),!pt.value&&r(be,{children:[r("div",{class:"rail-divider"},void 0,!1,void 0,this),r(no,{label:"Select",shortcut:"V",active:u==="select",onClick:()=>qn.value="select",children:r(GS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Pan",shortcut:"Space",active:u==="pan",onClick:()=>qn.value="pan",children:r(KS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Connect",shortcut:"C",active:u==="connect",onClick:()=>qn.value="connect",children:r("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[r("circle",{cx:"4",cy:"4",r:"2"},void 0,!1,void 0,this),r("circle",{cx:"12",cy:"12",r:"2"},void 0,!1,void 0,this),r("path",{d:"M5.5 5.5 C 8 8, 8 8, 10.5 10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),r("div",{class:"rail-divider"},void 0,!1,void 0,this),r(no,{label:"Markdown note",shortcut:"M",onClick:()=>void Ao({type:"markdown",title:"New note",width:520,height:360}).catch((V)=>mc("create markdown",V)),children:r(ui,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Attach files",ariaLabel:"Attach files",detail:"Images (PNG, JPEG, SVG…), Markdown and text/code files. PDF, Word, Excel, PowerPoint and OpenDocument use agent import with review.",onClick:()=>M.current?.click(),children:r(BS,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("input",{ref:M,type:"file",hidden:!0,multiple:!0,"aria-label":"Attach files",onChange:(V)=>{let ee=Jt(),he=Ae.value;xa(Array.from(V.currentTarget.files??[]),(ee.width/2-he.x)/he.scale,(ee.height/2-he.y)/he.scale),V.currentTarget.value=""}},void 0,!1,void 0,this),r(no,{label:"Webpage",shortcut:"W",onClick:()=>ps("webpage"),children:r(na,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Group",shortcut:"G",onClick:()=>void Ao({type:"group",title:"Group"}).catch((V)=>mc("create group",V)),children:r(nh,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Draw",shortcut:"A",active:l==="pen",onClick:()=>c(l==="pen"?null:"pen"),children:r(ZS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Text note",active:l==="text",onClick:()=>c(l==="text"?null:"text"),children:r(qS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(no,{label:"Eraser",active:l==="eraser",onClick:()=>c(l==="eraser"?null:"eraser"),children:r(WS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("div",{class:"rail-divider"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!pt.value&&r(no,{label:"Search & commands",shortcut:Ht("K"),onClick:s,children:r(ld,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),!pt.value&&r(no,{label:"Arrange",detail:m>0?"graph-aware":"grid",onClick:()=>m>0?od():nd(),children:r(Pr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("div",{class:"rail-spacer"},void 0,!1,void 0,this),r("span",{class:"toolbar-menu-anchor",children:[r(no,{label:"Settings",detail:"Appearance, board tools, beta features, and feedback",ariaLabel:"Settings",menuOpen:y!==null,active:y!==null||n,onClick:B,btnRef:i,children:r("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:r("path",{d:"M4 7h9M17 7h3M4 17h3M11 17h9M13 7a2 2 0 1 0 4 0a2 2 0 1 0-4 0M7 17a2 2 0 1 0 4 0a2 2 0 1 0-4 0"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),y==="settings"&&r("div",{class:"toolbar-menu rail-settings-menu",style:Y,role:"menu","aria-label":"Settings",children:[r(sr,{label:"Theme",description:"Choose the canvas appearance. Your choice is saved with the board.",hint:`${fa[J].label} ›`,onClick:()=>k("theme")},void 0,!1,void 0,this),!pt.value&&r(be,{children:[r(sr,{label:"Snapshots",description:"Save a board checkpoint, compare changes, or restore an earlier version.",onClick:L(o)},void 0,!1,void 0,this),r(sr,{label:"Minimap",description:"Show a small overview of the board. Drag its viewport to move around the canvas.",checked:e,hint:e?"On":"Off",onClick:L(t)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(sr,{label:"Keyboard shortcuts",description:"See shortcuts for creating cards, selecting, navigating, and editing the canvas.",hint:"?",onClick:L(a)},void 0,!1,void 0,this),r("div",{class:"toolbar-menu-divider",role:"separator"},void 0,!1,void 0,this),r("span",{class:"settings-caption",children:"Beta features · workspace-wide · off by default"},void 0,!1,void 0,this),r(sr,{label:"Agent sessions",beta:!0,checked:kt.value,disabled:!Qr.value||g,description:"Show session chips, tasks, timeline, steering composer, and receipts. Turning off hides these without ending attached agents. Approvals and edit protections remain available. Saved for this workspace.",onClick:()=>void C("agentSessions")},void 0,!1,void 0,this),r(sr,{label:"Knowledge lifecycle",beta:!0,checked:Be.value,disabled:!Qr.value||g,description:"This turns on context lifecycle, where boards and cards decay over time as their relevance fades. Includes Review, review policies, categories, and due or retired indicators. Turning off hides lifecycle tools without deleting their data or drafts. Saved for this workspace.",onClick:()=>void C("knowledgeLifecycle")},void 0,!1,void 0,this),b&&r("p",{class:"settings-error",role:"alert",children:"Could not save settings. Try again."},void 0,!1,void 0,this),!kt.value&&(Sa.value.length>0||To.value.length>0||ls.value.length>0||Io.value)&&r(sr,{label:"Agent controls",description:"Review pending approvals, inspect or clear the write scope, or end an existing attachment without enabling the session beta.",onClick:L(()=>to.value=!0)},void 0,!1,void 0,this),r("div",{class:"toolbar-menu-divider",role:"separator"},void 0,!1,void 0,this),!nt()&&!pt.value&&r(be,{children:[r(sr,{label:"Trace",description:"Show execution traces sent by connected tools. Turning off keeps existing traces. This does not start an agent.",toggle:!0,checked:d,onClick:()=>X("trace-toggle",{enabled:!d})},void 0,!1,void 0,this),(d||p>0)&&r(sr,{label:"Clear trace",description:"Remove recorded execution traces from this board without changing whether trace capture is enabled.",onClick:L(()=>X("trace-clear"))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(sr,{label:"Send feedback",description:"Report a problem or suggestion. Review the feedback before sending.",onClick:L(()=>h(!0))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y==="theme"&&r("div",{class:"toolbar-menu",style:Y,role:"menu","aria-label":"Theme",children:[r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>k("settings"),children:r("span",{children:"‹ Settings"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Wh.map((V)=>r("button",{type:"button",role:"menuitemradio","aria-checked":J===V,class:`toolbar-menu-item${J===V?" active":""}`,onClick:()=>j(V),children:[r("span",{class:"theme-swatch",style:{background:fa[V].swatchBg},children:r("span",{class:"theme-swatch-dot",style:{background:fa[V].swatchAccent}},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{children:fa[V].label},void 0,!1,void 0,this),J===V&&r("span",{class:"toolbar-menu-check","aria-hidden":"true",children:"✓"},void 0,!1,void 0,this)]},V,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),f&&r(NT,{onClose:()=>h(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function zT({onOpenPalette:e}){let t=F(null),n=()=>{Ao({type:"markdown",title:"New note",width:520,height:360}).catch(()=>{})},o=async(i)=>{if(!i||i.length===0)return;let s=Yr(),a=Ae.value;await xa(Array.from(i),(s.x-a.x)/a.scale,(s.y-a.y)/a.scale)};return r("div",{class:"empty-state","data-testid":"empty-state",children:[r("svg",{class:"empty-state-mark",width:"52",height:"52",viewBox:"0 0 64 64",fill:"none","aria-hidden":"true",children:[r("rect",{x:"8",y:"8",width:"48",height:"48",rx:"7"},void 0,!1,void 0,this),r("rect",{x:"20",y:"20",width:"24",height:"24",rx:"4","stroke-dasharray":"4 4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"empty-state-title",children:"What would you like to work on?"},void 0,!1,void 0,this),r("div",{class:"empty-state-grid",children:[r("button",{type:"button",class:"empty-state-action",onClick:()=>t.current?.click(),children:[r("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round",class:"tone-warn","aria-hidden":"true",children:[r("path",{d:"M8 10 V2 M8 2 L5 5 M8 2 L11 5"},void 0,!1,void 0,this),r("path",{d:"M2 10 V13 H14 V10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"empty-state-action-label",children:["Drop files here",r("span",{class:"empty-state-action-description",children:"Bring in the material you want to work with."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"empty-state-action-hint",children:"or pick"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",class:"empty-state-action",onClick:()=>ps("webpage"),children:[r(na,{size:16,class:"tone-ok"},void 0,!1,void 0,this),r("span",{class:"empty-state-action-label",children:["Paste a link",r("span",{class:"empty-state-action-description",children:"Add a source, reference, or inspiration."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("kbd",{children:Ht("V")},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",class:"empty-state-action",onClick:n,children:[r(ui,{size:16,class:"tone-accent"},void 0,!1,void 0,this),r("span",{class:"empty-state-action-label",children:["Start a note",r("span",{class:"empty-state-action-description",children:"Write down an idea, then ask your agent to help you develop it."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("kbd",{children:"M"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"empty-state-agent",children:[r("div",{class:"empty-state-agent-title",children:"Or start with your agent"},void 0,!1,void 0,this),r("div",{class:"empty-state-sub",children:"Give your agent a task and ask it to work on this board."},void 0,!1,void 0,this),kt.value&&r("button",{type:"button",class:"empty-state-action is-agent",onClick:()=>void _i(),children:[r(ra,{size:16,class:"tone-purple"},void 0,!1,void 0,this),r("span",{class:"empty-state-action-label",children:"Start agent session"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",class:"empty-state-hint",onClick:e,children:["? shortcuts · ",Ht("K")," palette"]},void 0,!0,void 0,this),r("input",{ref:t,type:"file",multiple:!0,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:(i)=>{let s=i.currentTarget;o(s.files).finally(()=>{s.value=""})}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ar(e){let t=e.target instanceof HTMLElement?e.target:null;return e.key==="Escape"&&!e.defaultPrevented&&!t?.closest('input, textarea, [contenteditable="true"]')&&!document.querySelector('[role="dialog"], [role="menu"], .context-menu, .shortcut-overlay-backdrop')}var $T="From old snapshots";function hp(e){if(!e?.trim())return null;let t=e.split("/").map((n)=>n.trim());if(t.length>8)throw Error("Folders can be nested up to 8 levels.");if(t.some((n)=>!n||n==="."||n===".."||n.length>60))throw Error('Each folder name must be 1–60 characters, and cannot be "." or "..".');return t.join("/")}function fc(e){return e.split("/").map((t,n,o)=>o.slice(0,n+1).join("/"))}function LT({board:e,folders:t,onClose:n}){let o=F(null),[i,s]=E(e.folder??""),[a,l]=E(""),[c,u]=E(!1),[d,p]=E("");bn(o,!0),G(()=>{let h=(g)=>{if(g.key!=="Escape")return;if(g.preventDefault(),g.stopPropagation(),!c)n()};return window.addEventListener("keydown",h,!0),()=>window.removeEventListener("keydown",h,!0)},[c,n]);let m=a.trim()?[i,a.trim()].filter(Boolean).join("/"):i,f=async()=>{let h;try{if(a.includes("/"))throw Error("Use one folder name; choose its parent above.");h=hp(m)}catch(g){p(g instanceof Error?g.message:String(g));return}if(u(!0),p(""),await Sr(e.id,{folder:h}),Ge.value.find((g)=>g.id===e.id)?.folder===h)n();else p("Could not move this board. Try again.");u(!1)};return r("div",{class:"text-prompt-backdrop",onPointerDown:()=>!c&&n(),children:r("div",{ref:o,class:"text-prompt home-folder-dialog",role:"dialog","aria-modal":"true","aria-label":`Move ${e.name}`,onPointerDown:(h)=>h.stopPropagation(),children:[r("div",{class:"text-prompt-title",children:["Move “",e.name,"”"]},void 0,!0,void 0,this),r("p",{class:"home-folder-hint",children:"Choose a folder, or create one inside it. The board keeps its content and links."},void 0,!1,void 0,this),r("fieldset",{class:"home-folder-options",disabled:c,children:[r("legend",{children:"Destination folder"},void 0,!1,void 0,this),["",...t].map((h)=>r("label",{class:"home-folder-option",style:{paddingLeft:`${8+Math.min(h.split("/").length-1,5)*14}px`},children:[r("input",{type:"radio",name:"folder-destination",value:h,checked:i===h,onChange:()=>{s(h),p("")}},void 0,!1,void 0,this),r("span",{children:h||"Home (no folder)"},void 0,!1,void 0,this)]},h,!0,void 0,this))]},void 0,!0,void 0,this),r("label",{class:"home-folder-new",children:["New folder inside ",i||"Home"," ",r("span",{class:"home-folder-hint",children:"(optional)"},void 0,!1,void 0,this),r("input",{class:"text-prompt-input","aria-label":"New folder name",placeholder:"e.g. Decisions",maxLength:60,value:a,disabled:c,onInput:(h)=>{l(h.currentTarget.value),p("")}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-folder-hint",children:["Move to: ",r("strong",{children:m||"Home"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d&&r("p",{role:"alert",children:d},void 0,!1,void 0,this),r("div",{class:"text-prompt-actions",children:[r("button",{type:"button",class:"text-prompt-cancel",disabled:c,onClick:n,children:"Cancel"},void 0,!1,void 0,this),r("button",{type:"button",class:"text-prompt-confirm",disabled:c||m===(e.folder??""),onClick:()=>void f(),children:c?"Moving…":"Move board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function OT({board:e,onClose:t}){let n=F(null),o=F(null),[i,s]=E(null),[a,l]=E(new Set),[c,u]=E(`${e.name} copy`),[d,p]=E(!0),[m,f]=E(!0),[h,g]=E(!1),[v,b]=E(""),[x,C]=E(!1);return bn(n,!0,{initial:o}),G(()=>{let k=!0;return oS(e.id).then((_)=>{if(!k)return;if(!_||!Array.isArray(_.cards))return b("Could not load reusable cards. Try again.");s(_),l(new Set(_.cards.filter((A)=>A.reusable).map((A)=>A.id)))}),()=>{k=!1}},[e.id]),r("div",{class:"text-prompt-backdrop",onMouseDown:t,children:r("div",{ref:n,class:"text-prompt board-copy-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"board-copy-title",onMouseDown:(k)=>k.stopPropagation(),children:r("form",{onClick:jo,onSubmit:async(k)=>{if(k.preventDefault(),!c.trim()||!i)return;C(!0),b("");let _=await rS({sourceBoardId:e.id,name:c.trim(),...e.folder?{folder:e.folder}:{},nodeIds:[...a],includeReadme:d,includeStructure:m});if(C(!1),!_)return b("Could not create the board. Try a different name.");if(h)await Mn(_.id);t()},children:[r("h2",{id:"board-copy-title",children:["Create from ",e.name]},void 0,!0,void 0,this),r("label",{class:"board-copy-field",children:["Board name",r("input",{ref:o,class:"text-prompt-input",value:c,onInput:(k)=>u(k.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!i&&!v&&r("div",{class:"board-copy-status",role:"status",children:"Loading reusable cards…"},void 0,!1,void 0,this),v&&r("div",{class:"board-copy-error",role:"alert",children:v},void 0,!1,void 0,this),i&&r("fieldset",{class:"board-copy-cards",children:[r("legend",{children:"Cards to copy"},void 0,!1,void 0,this),i.cards.filter((k)=>k.reusable).length===0?r("div",{class:"board-copy-status",children:"No reusable cards on this board."},void 0,!1,void 0,this):i.cards.filter((k)=>k.reusable).map((k)=>r("label",{class:"board-copy-card",children:[r("input",{type:"checkbox",checked:a.has(k.id),onChange:(_)=>{let A=new Set(a);_.currentTarget.checked?A.add(k.id):A.delete(k.id),l(A)}},void 0,!1,void 0,this),r("span",{children:[r("strong",{children:k.title||"Untitled card"},void 0,!1,void 0,this),r("small",{children:k.type},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},k.id,!0,void 0,this))]},void 0,!0,void 0,this),r("div",{class:"board-copy-options",children:[r("label",{children:[r("input",{type:"checkbox",checked:m,onChange:(k)=>f(k.currentTarget.checked)},void 0,!1,void 0,this)," ","Preserve groups and connections"]},void 0,!0,void 0,this),r("label",{children:[r("input",{type:"checkbox",checked:d,disabled:!i?.readmeNodeId,onChange:(k)=>p(k.currentTarget.checked)},void 0,!1,void 0,this)," ","Include README"]},void 0,!0,void 0,this),r("label",{children:[r("input",{type:"checkbox",checked:h,onChange:(k)=>g(k.currentTarget.checked)},void 0,!1,void 0,this)," Open the new board after creating"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("p",{class:"board-copy-note",children:"Only selected cards and structure are copied. Asks, history, and context pins start clear."},void 0,!1,void 0,this),r("div",{class:"text-prompt-actions",children:[r("button",{type:"button",onClick:t,children:"Cancel"},void 0,!1,void 0,this),r("button",{type:"submit",disabled:!i||!c.trim()||x,children:x?"Creating…":"Create board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function gp({children:e,initiallyCollapsed:t=!1,reveal:n=0}){let o=F(null),[i,s]=E(280),[a,l]=E(400),[c,u]=E(t),d=F(null);return $e(()=>{if(n)u(!1)},[n]),$e(()=>{let p=o.current.closest(".home-memory"),m=p.querySelector(".home-memory-stage"),f=p.closest(".canvas-region"),h=p.querySelector(".home-memory-toolbar"),g=p.querySelector(".home-memory-legend"),v=()=>{f?.style.setProperty("--home-memory-content-top",`${m.getBoundingClientRect().top-(f?.getBoundingClientRect().top??0)}px`),l(Math.max(120,p.clientHeight-h.offsetHeight-g.offsetHeight-160))},b=new ResizeObserver(v);for(let x of[p,m,h,g])b.observe(x);return v(),()=>{b.disconnect(),f?.style.removeProperty("--home-memory-content-top")}},[]),r("div",{ref:o,class:`home-memory-inspector${c?" is-collapsed":""}`,style:c?void 0:{height:Math.min(i,a)},children:[!c&&r("div",{class:"home-memory-inspector-resize",role:"separator",tabIndex:0,"aria-label":"Resize relation details","aria-orientation":"horizontal","aria-controls":"home-memory-details","aria-valuemin":120,"aria-valuemax":a,"aria-valuenow":Math.min(i,a),onKeyDown:(p)=>{if(!["ArrowUp","ArrowDown","Home","End"].includes(p.key))return;p.preventDefault(),s(p.key==="Home"?120:p.key==="End"?a:Math.max(120,Math.min(a,Math.min(i,a)+(p.key==="ArrowUp"?32:-32))))},onPointerDown:(p)=>{if(p.button!==0)return;p.preventDefault(),d.current={id:p.pointerId,y:p.clientY,height:Math.min(i,a)},p.currentTarget.focus({preventScroll:!0}),p.currentTarget.setPointerCapture(p.pointerId)},onPointerMove:(p)=>{let m=d.current;if(m?.id===p.pointerId)s(Math.max(120,Math.min(a,m.height+m.y-p.clientY)))},onPointerUp:()=>{d.current=null},onPointerCancel:()=>{if(d.current)s(d.current.height);d.current=null}},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button home-memory-inspector-toggle","aria-expanded":!c,"aria-controls":"home-memory-details",onClick:()=>u(!c),children:c?"Expand details":"Collapse details"},void 0,!1,void 0,this),r("div",{id:"home-memory-details",children:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var yo={width:220,height:92};function DT(e,t){let n=e.filter((m)=>m.kind==="board"),o=new Map,i=[],s=new Set,a=new Set;for(let m of n){let f=(m.folder??"").split("/");f.forEach((h,g)=>{a.add(f.slice(0,g+1).join("/"))})}let l=(m,f)=>(m.folder??"")===f||!!f&&!!m.folder?.startsWith(`${f}/`),c=(m,f,h,g)=>{let v=n.filter((j)=>l(j,m)),b=t.has(m),x={path:m,x:f,y:h,width:280,height:72,count:v.length,depth:g,collapsed:b};if(i.push(x),b){for(let j of v)s.add(j.key);return x}let C=v.filter((j)=>(j.folder??"")===m).sort((j,J)=>j.title.localeCompare(J.title)),y=Math.min(3,Math.max(1,Math.ceil(Math.sqrt(C.length))));C.forEach((j,J)=>{let X=j.position??{x:f+24+J%y*(yo.width+28),y:h+52+Math.floor(J/y)*(yo.height+28)};o.set(j.key,{x:X.x+yo.width/2,y:X.y+yo.height/2})});let k=h+52+Math.ceil(C.length/y)*(yo.height+28),_=C.length?y*(yo.width+28)+20:280,A=[...a].filter((j)=>j&&j.slice(0,j.lastIndexOf("/"))===m&&j.includes("/")).sort(),w=20,M=0;for(let j of A){if(w>650)w=20,k+=M+24,M=0;let J=c(j,f+w,k,g+1);w+=J.width+24,M=Math.max(M,J.height),_=Math.max(_,w)}k+=M+(A.length?20:0),x.width=_,x.height=Math.max(100,k-h+4);let B=v.flatMap((j)=>{let J=o.get(j.key);return J?[J]:[]}),L=Math.max(f+x.width,...B.map((j)=>j.x+yo.width/2+20)),Y=Math.max(h+x.height,...B.map((j)=>j.y+yo.height/2+20));return x.x=Math.min(f,...B.map((j)=>j.x-yo.width/2-20)),x.y=Math.min(h,...B.map((j)=>j.y-yo.height/2-48)),x.width=L-x.x,x.height=Y-x.y,x},u=32,d=32,p=0;for(let m of[...a].filter((f)=>!f.includes("/")).sort()){if(u>1100)u=32,d+=p+36,p=0;let f=c(m,u,d,0);u+=f.width+36,p=Math.max(p,f.height)}return{positions:o,regions:i,hidden:s}}function yp(e){let t=Ge.value,n=ko.value,[o,i]=E(null),[s,a]=E(!0),[l,c]=E(!1),u=F(()=>{});return G(()=>{let d=!1,p=!1,m=!1,f,h=()=>{if(m=!0,!p&&f===void 0)f=window.setTimeout(g,120)},g=async()=>{f=void 0,m=!1,p=!0,a(!0);let v=In,b=ko.peek(),x=Ge.peek(),C=await pe("memoryGraph",`/api/canvas/memory-graph?projection=${e}`,null);if(d)return;if(p=!1,v!==In||b!==ko.peek()||x!==Ge.peek()){h();return}if(C&&Array.isArray(C.nodes)&&Array.isArray(C.edges))i(C),c(!1);else c(!0);if(a(!1),m)h()};return u.current=h,h(),()=>{d=!0,window.clearTimeout(f)}},[e]),G(()=>u.current(),[n,t]),{graph:o,loading:s,error:l,retry:()=>u.current()}}var BT={portal:"Portals",wiki:"Wiki links",card:"Card relations",previous:"Previous boards"};function HT(){let e=Ge.value,t=ko.value,{graph:n,loading:o,error:i,retry:s}=yp("boards"),[a,l]=E(""),[c,u]=E(!0),[d,p]=E(!1),[m,f]=E(!0),[h,g]=E(new Set),[v,b]=E(new Set),[x,C]=E(new Set),[y,k]=E(null),[_,A]=E(null),[w,M]=E(null),[B,L]=E({x:0,y:0}),[Y,j]=E(1),[J,X]=E({}),[V,ee]=E(!1),he=F(null),R=F(!0),te=F(!1),O=F(null);$e(()=>{pt.value=!0},[]),$e(()=>{if(!y)return;let N=(ne)=>{if(ar(ne))ne.preventDefault(),k(null)};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[y]),G(()=>{if(!y)return;let N=!1;M(null);let ne=In,Ce=ko.peek(),Te=new URLSearchParams({focus:y,depth:"2"});return pe("memoryGraph",`/api/canvas/memory-graph?${Te}`,null).then((me)=>{if(!N&&ne===In&&Ce===ko.peek())M({key:y,graph:me&&Array.isArray(me.nodes)&&Array.isArray(me.edges)?me:null})}),()=>{N=!0}},[y,n,t]);let H=Ve(()=>(n?.nodes??[]).filter((N)=>N.kind==="board").map((N)=>{let ne=e.find((Ce)=>Ce.id===N.boardId);return ne?{...N,title:ne.name,folder:ne.folder,inContext:!!ne.pin,nodeCount:ne.nodeCount,position:ne.mapPosition??void 0}:N}),[n,e]),Me=Ve(()=>DT(H,x),[H,x]),je=new Map;for(let N of H){let ne=N.folder?.split("/")[0]??"";je.set(ne,(je.get(ne)??0)+1)}let He=H.filter((N)=>c&&(!d||N.inContext)&&(m||!!N.folder)&&!h.has(N.folder?.split("/")[0]??"")&&!Me.hidden.has(N.key)&&`${N.title} ${N.summary} ${N.folder??""}`.toLocaleLowerCase().includes(a.trim().toLocaleLowerCase())),Re=new Set(He.map((N)=>N.key)),ve=(N)=>J[N]??Me.positions.get(N),D=H.find((N)=>N.key===y),re=H.find((N)=>N.key===(_??y)),ze=new Map;for(let N of n?.edges??[]){if(N.kind==="member"||v.has(N.kind))continue;let ne=Mt({boardId:N.source.boardId}),Ce=Mt({boardId:N.target.boardId});if(!Re.has(ne)||!N.missing&&(!Re.has(Ce)||ne===Ce))continue;let Te=JSON.stringify([ne,Ce,N.kind,N.relationKind,N.missing]),me=ze.get(Te);if(me)me.edges.push(N);else ze.set(Te,{from:ne,to:Ce,edges:[N]})}let ke=new Set(re?[re.key]:[]);for(let{from:N,to:ne}of ze.values())if(re&&(N===re.key||ne===re.key))ke.add(N),ke.add(ne);let ae=(N)=>new Set((n?.edges??[]).filter((ne)=>ne.kind!=="member"&&(ne.source.boardId===N.boardId||ne.target.boardId===N.boardId)).map((ne)=>ne.source.boardId===N.boardId?ne.target.boardId:ne.source.boardId).filter((ne)=>ne!==N.boardId)).size,Se=()=>{let N=he.current;if(!N?.clientWidth||!N.clientHeight)return;let ne=He.flatMap((Qe)=>{let Lt=ve(Qe.key);return Lt?[{x:Lt.x-110,y:Lt.y-46},{x:Lt.x+110,y:Lt.y+46}]:[]});for(let Qe of Me.regions){if(h.has(Qe.path.split("/")[0]??"")||!m&&!Qe.path)continue;ne.push({x:Qe.x,y:Qe.y},{x:Qe.x+Qe.width,y:Qe.y+Qe.height})}if(!ne.length)return;let Ce=Math.min(...ne.map((Qe)=>Qe.x)),Te=Math.min(...ne.map((Qe)=>Qe.y)),me=Math.max(...ne.map((Qe)=>Qe.x))-Ce,at=Math.max(...ne.map((Qe)=>Qe.y))-Te,Ft=Math.min(1.25,Math.max(0.08,Math.min((N.clientWidth-64)/Math.max(1,me),(N.clientHeight-100)/Math.max(1,at))));j(Ft),L({x:(N.clientWidth-me*Ft)/2-Ce*Ft,y:(N.clientHeight-at*Ft)/2-Te*Ft-12})};G(()=>{R.current=!0},[x]),G(()=>{if(R.current&&n&&(He.length||Me.regions.length)&&!O.current)R.current=!1,Se()},[n,x]);let de=(N,ne)=>{let Ce=he.current;if(!Ce)return;let Te=ne??{x:Ce.clientWidth/2,y:Ce.clientHeight/2},me=Math.min(3,Math.max(0.08,N));L({x:Te.x-(Te.x-B.x)*me/Y,y:Te.y-(Te.y-B.y)*me/Y}),j(me)},Ze=(N,ne=!1)=>{k(N.key);let Ce=ve(N.key),Te=he.current;if(ne&&Ce&&Te)L({x:Te.clientWidth/2-Ce.x*Y,y:Te.clientHeight/2-Ce.y*Y})},xe=(N)=>{let ne=O.current;if(O.current=null,!ne)return;if(te.current=ne.moved,!ne.key)return;let Ce=ne.key,Te=()=>X((me)=>{let at={...me};return delete at[Ce],at});if(ne.boardId&&ne.moved&&!N){let me=ne.current??ne.origin;Sr(ne.boardId,{mapPosition:{x:me.x-yo.width/2,y:me.y-yo.height/2}}).finally(Te)}else Te()},Ke=w?.key===y?w.graph:null,q=(Ke?.edges??[]).filter((N)=>D&&N.kind!=="member"&&(N.source.boardId===D.boardId||N.target.boardId===D.boardId)),ye=e.find((N)=>N.id===D?.boardId),Ue=(N,ne,Ce,Te)=>r("label",{class:"home-memory-check",children:[r("input",{type:"checkbox","aria-label":N,checked:Ce,onChange:Te},void 0,!1,void 0,this),r("span",{children:N},void 0,!1,void 0,this),r("small",{children:ne},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return r("main",{class:`home-memory is-map${V?" sidebar-open":""}`,"aria-label":"Library Map",children:[r("div",{class:"home-memory-toolbar",children:[r("span",{children:[H.length," boards · ",e.reduce((N,ne)=>N+ne.nodeCount,0)," cards ·"," ",n?.edges.filter((N)=>N.kind!=="member").length??0," links"]},void 0,!0,void 0,this),r("span",{class:`home-memory-live${i?" is-error":""}`,role:"status",children:i?"Update failed":o?"Updating…":"Live"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button home-memory-sidebar-toggle","aria-expanded":V,onClick:()=>ee(!V),children:"Filters"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-body",children:[r("div",{class:"home-memory-stage",ref:he,"aria-label":"Pan the memory view",onWheel:(N)=>{N.preventDefault();let ne=N.currentTarget.getBoundingClientRect();de(Y*Math.exp(-N.deltaY*0.0015),{x:N.clientX-ne.left,y:N.clientY-ne.top})},onPointerDown:(N)=>{if(N.button!==0||N.target.closest("button"))return;te.current=!1,O.current={id:N.pointerId,start:{x:N.clientX,y:N.clientY},origin:B,moved:!1},N.currentTarget.setPointerCapture(N.pointerId)},onPointerMove:(N)=>{let ne=O.current;if(!ne||ne.id!==N.pointerId)return;let Ce=N.clientX-ne.start.x,Te=N.clientY-ne.start.y;if(Math.abs(Ce)+Math.abs(Te)>4)ne.moved=!0;if(!ne.moved)return;let me={x:ne.origin.x+Ce/(ne.key?Y:1),y:ne.origin.y+Te/(ne.key?Y:1)};if(ne.current=me,ne.key)X((at)=>({...at,[ne.key]:me}));else L(me)},onPointerUp:()=>xe(!1),onPointerCancel:()=>xe(!0),children:[r("div",{class:"home-memory-world",style:{transform:`translate(${B.x}px, ${B.y}px) scale(${Y})`,"--memory-zoom":Y},children:[Me.regions.filter((N)=>!h.has(N.path.split("/")[0]??"")&&(m||N.path)).map((N)=>r("div",{class:`home-memory-region${N.depth?" is-nested":""}`,style:{left:N.x,top:N.y,width:N.width,height:N.height},children:r("button",{type:"button","aria-expanded":!N.collapsed,onClick:()=>C((ne)=>{let Ce=new Set(ne);if(Ce.has(N.path))Ce.delete(N.path);else Ce.add(N.path);return Ce}),children:[N.collapsed?"▸":"▾"," ",N.path.split("/").at(-1)||"Unfiled"," ",r("small",{children:[N.count," boards"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},N.path,!1,void 0,this)),r("svg",{class:"home-memory-links","aria-hidden":"true",children:[...ze].map(([N,{from:ne,to:Ce,edges:Te}])=>{let me=Te[0],at=ve(ne),Ft=ve(Ce);if(!at)return null;let Qe=Ft??{x:at.x+100,y:at.y-70},Lt=at.y+(Qe.y>at.y?46:-46),U=Ft?Qe.y+(Qe.y>at.y?-46:46):Qe.y,Ie=re&&(me.source.boardId===re.boardId||me.target.boardId===re.boardId),S=ho({kind:me.relationKind,type:me.type},e.find((ue)=>ue.id===me.source.boardId)?.relationVocabulary),K=me.missing?"var(--c-warn)":me.kind==="card"?`var(--c-rel-${S.ink})`:void 0;return r("g",{"data-from":ne,"data-to":Ce,"data-count":Te.length,style:K?{stroke:K}:void 0,class:`memory-edge edge-${me.kind}${me.missing?" is-missing":""}${Ie?" is-emphasized":re?" is-dimmed":""}`,children:[r("path",{d:`M ${at.x} ${Lt} C ${at.x} ${(Lt+U)/2}, ${Qe.x} ${(Lt+U)/2}, ${Qe.x} ${U}`},void 0,!1,void 0,this),Te.length>1&&r("text",{x:(at.x+Qe.x)/2,y:(at.y+Qe.y)/2-6,children:[Te.length," links"]},void 0,!0,void 0,this),me.missing&&r("text",{x:Qe.x,y:Qe.y-5,children:["⚠ Missing ",me.kind," link"]},void 0,!0,void 0,this)]},N,!0,void 0,this)})},void 0,!1,void 0,this),He.map((N,ne)=>{let Ce=ve(N.key);if(!Ce)return null;let Te=e.find((me)=>me.id===N.boardId);return r("article",{"data-key":N.key,class:`home-memory-node is-board${N.inContext?" in-context":""}${y===N.key?" is-selected":""}${ke.has(N.key)?" is-emphasized":re?" is-dimmed":""}`,style:{left:Ce.x,top:Ce.y},onPointerEnter:()=>{if(!O.current)A(N.key)},onPointerLeave:()=>A(null),children:[r("button",{type:"button",class:"home-memory-select","aria-label":`board: ${N.title}`,"aria-pressed":y===N.key,onFocus:(me)=>{if(!O.current&&me.currentTarget.matches(":focus-visible"))Ze(N,!0)},onClick:()=>{if(!te.current)Ze(N);te.current=!1},onDblClick:()=>void zt(N),onPointerDown:(me)=>{if(me.button!==0)return;me.stopPropagation(),te.current=!1,O.current={id:me.pointerId,start:{x:me.clientX,y:me.clientY},origin:Ce,key:N.key,boardId:N.boardId,moved:!1},me.currentTarget.setPointerCapture(me.pointerId)},onKeyDown:(me)=>{if(me.key==="Enter")me.preventDefault(),zt(N);if(me.key.startsWith("Arrow")){me.preventDefault();let at=(ne+(me.key==="ArrowLeft"||me.key==="ArrowUp"?-1:1)+He.length)%He.length,Ft=He[at];if(Ft)Ze(Ft,!0),he.current?.querySelectorAll(".home-memory-select")[at]?.focus({preventScroll:!0})}},children:[r("strong",{children:N.title},void 0,!1,void 0,this),r("span",{children:[N.nodeCount??0," cards · ",ae(N)," connected boards"]},void 0,!0,void 0,this),r("span",{class:"home-memory-summary",children:N.summary||"No summary yet"},void 0,!1,void 0,this),N.inContext&&r("span",{class:"home-memory-context",children:"⌖ In context"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Te&&r(go,{board:Te},void 0,!1,void 0,this)]},N.key,!0,void 0,this)})]},void 0,!0,void 0,this),r("div",{class:"home-memory-zoom",children:[r("button",{type:"button",class:"home-button","aria-label":"Zoom out",onClick:()=>de(Y/1.2),children:"−"},void 0,!1,void 0,this),r("span",{children:[Math.round(Y*100),"%"]},void 0,!0,void 0,this),r("button",{type:"button",class:"home-button","aria-label":"Zoom in",onClick:()=>de(Y*1.2),children:"+"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button",onClick:Se,children:"Fit view"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(!n||!He.length||i)&&r("div",{class:"home-memory-status",role:"status",children:i?r(be,{children:["Memory update failed."," ",r("button",{type:"button",class:"home-button",onClick:s,children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):!n?"Loading memory…":Me.hidden.size?"Folders collapsed. Expand a folder to see its boards.":"No matching nodes."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("aside",{class:"home-memory-sidebar","aria-label":"Map settings",children:[r("section",{children:[r("h2",{children:"Filters"},void 0,!1,void 0,this),r("label",{class:"home-memory-search",children:[r("span",{children:"Find boards and cards"},void 0,!1,void 0,this),r("input",{type:"search",value:a,placeholder:"Search boards and cards…",onInput:(N)=>l(N.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ue("Boards",H.length,c,()=>u(!c)),Ue("Only in context",H.filter((N)=>N.inContext).length,d,()=>p(!d)),Ue("Include unfiled",H.filter((N)=>!N.folder).length,m,()=>f(!m))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Groups · by folder"},void 0,!1,void 0,this),[...je].sort(([N],[ne])=>N.localeCompare(ne)).map(([N,ne])=>r("div",{children:Ue(N||"Unfiled",ne,!h.has(N),()=>g((Ce)=>{let Te=new Set(Ce);if(Te.has(N))Te.delete(N);else Te.add(N);return Te}))},N,!1,void 0,this))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Links"},void 0,!1,void 0,this),Object.keys(BT).map((N)=>r("div",{class:`memory-legend-${N}`,children:Ue(BT[N],n?.edges.filter((ne)=>ne.kind===N).length??0,!v.has(N),()=>b((ne)=>{let Ce=new Set(ne);if(Ce.has(N))Ce.delete(N);else Ce.add(N);return Ce}))},N,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-legend","aria-label":"Legend",children:[r("span",{children:"▣ Board"},void 0,!1,void 0,this),r("span",{class:"memory-context-legend",children:"⌖ In context"},void 0,!1,void 0,this),r("span",{class:"memory-legend-portal",children:"━ Portal"},void 0,!1,void 0,this),r("span",{class:"memory-legend-wiki",children:"┄ Wiki"},void 0,!1,void 0,this),r("span",{class:"memory-legend-card",children:"━ Relation"},void 0,!1,void 0,this),r("span",{children:"Drag boards to save positions · drag background to pan · scroll to zoom"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(gp,{children:D?r("section",{class:"home-memory-details",role:"complementary","aria-label":"Selection details",children:[r("button",{type:"button",class:"home-memory-clear","aria-label":"Close details",onClick:()=>k(null),children:"×"},void 0,!1,void 0,this),r("div",{class:"home-memory-detail-header",children:[r("div",{class:"home-memory-selection-title",children:[r("h3",{children:[D.title," · ",q.length," connections"]},void 0,!0,void 0,this),r("p",{children:[D.folder||"Unfiled"," · board"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-actions",children:[r("button",{type:"button",class:"home-button is-primary",onClick:()=>void zt(D),children:"Open board"},void 0,!1,void 0,this),ye&&r(go,{board:ye},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button",onClick:()=>void Sr(D.boardId,{mapPosition:null}),children:"Reset position"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-detail-body",children:[r("p",{children:[D.nodeCount??0," cards · ",ae(D)," connected boards"]},void 0,!0,void 0,this),r("p",{children:D.summary||"No summary yet."},void 0,!1,void 0,this),r("p",{class:D.inContext?"memory-context-legend":"",children:D.inContext?"⌖ In context":"Not in context"},void 0,!1,void 0,this),r("details",{class:"home-memory-connections",open:!0,children:[r("summary",{children:"Connections"},void 0,!1,void 0,this),!Ke&&r("p",{role:"status",children:w?.key===y?"Connections could not be loaded.":"Loading connections…"},void 0,!1,void 0,this),r("ul",{children:[q.map((N)=>{let ne=N.source.boardId===D.boardId,Ce=ne?N.target:N.source,Te=Ke?.nodes.find((me)=>me.key===Mt(Ce));return r("li",{children:[r("span",{children:[ne?"→":"←"," ",N.kind==="card"?Ca({...N,kind:N.relationKind}):`${N.kind}${N.label?` · ${N.label}`:""}`]},void 0,!0,void 0,this),N.missing?r("span",{class:"home-memory-missing",children:["⚠ Missing target: ",Ce.boardId,Ce.cardId?` / ${Ce.cardId}`:""]},void 0,!0,void 0,this):r("button",{type:"button",class:"home-button",onClick:()=>void zt(Ce),children:Te?.title??Ce.boardId},void 0,!1,void 0,this)]},N.id,!0,void 0,this)}),(Ke?.unresolvedLinks??[]).filter((N)=>N.source.boardId===D.boardId).map((N)=>r("li",{class:"home-memory-missing",children:["⚠ Unresolved wiki: [[",N.ref,"]]"]},`${Mt(N.source)}:${N.ref}`,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):r("div",{class:"home-memory-empty-details",children:[r("h3",{children:"Relations"},void 0,!1,void 0,this),r("p",{class:"home-memory-help",children:"Overview groups links between boards. Select a board to inspect connections. Double-click to open."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Ye={width:220,height:96,gap:64},hc=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),VL=(e,t)=>e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom;function XL(e,t,n){let o=0,i=1;for(let[s,a,l,c]of[[e.x,t.x-e.x,n.left,n.right],[e.y,t.y-e.y,n.top,n.bottom]])if(!a){if(s<=l||s>=c)return!1}else{let u=(l-s)/a,d=(c-s)/a;o=Math.max(o,Math.min(u,d)),i=Math.min(i,Math.max(u,d))}return o<i&&i>0&&o<1}function FT(e,t){let o=[...e].map(([m,f])=>({key:m,left:f.x-Ye.width/2-8,right:f.x+Ye.width/2+8,top:f.y-Ye.height/2-8,bottom:f.y+Ye.height/2+8})),i=(m,f)=>!o.some((h)=>XL(m,f,h)),s=o.flatMap((m)=>[{x:m.left,y:m.top},{x:m.right,y:m.top},{x:m.right,y:m.bottom},{x:m.left,y:m.bottom}]).filter((m)=>!o.some((f)=>VL(m,f))),a=new Map,l=(m,f)=>[{x:m.x-Ye.width/2,y:m.y+f*Ye.height},{x:m.x+Ye.width/2,y:m.y+f*Ye.height},{x:m.x+f*Ye.width,y:m.y-Ye.height/2},{x:m.x+f*Ye.width,y:m.y+Ye.height/2}].map((h,g)=>({port:h,stub:{x:h.x+(g===0?-8:g===1?8:0),y:h.y+(g===2?-8:g===3?8:0)}})),c=new Map,u=[],d=new Map,p=new Map;for(let m of t){let f=JSON.stringify([m.from,m.to].sort());p.set(f,(p.get(f)??0)+1)}for(let m of t){let f=e.get(m.from),h=e.get(m.to),g=JSON.stringify([m.from,m.to].sort()),v=d.get(g)??0;d.set(g,v+1);let b=((v+1)/(p.get(g)+1)-0.5)*0.8,x=l(f,b),C=l(h,b),y,k=1/0;for(let M of x)for(let B of C){let L=hc(M.stub,B.stub);if(L&&L<k&&i(M.stub,B.stub))k=L,y=[M.port,M.stub,B.stub,B.port]}if(!y){let M=s.map(()=>1/0),B=s.map(()=>-1),L=s.map(()=>0),Y=new Set;for(let X=0;X<s.length;X++)for(let V=0;V<x.length;V++){let ee=hc(x[V].stub,s[X]);if(ee<M[X]&&i(x[V].stub,s[X]))M[X]=ee,L[X]=V}let j=-1,J=0;while(Y.size<s.length){let X=-1;for(let ee=0;ee<s.length;ee++)if(!Y.has(ee)&&(X<0||M[ee]<M[X]))X=ee;if(X<0||M[X]>=k||!Number.isFinite(M[X]))break;Y.add(X);for(let ee=0;ee<C.length;ee++){let he=M[X]+hc(s[X],C[ee].stub);if(he<k&&i(s[X],C[ee].stub))k=he,j=X,J=ee}let V=a.get(X);if(!V)V=s.flatMap((ee,he)=>he!==X&&i(s[X],ee)?[{index:he,length:hc(s[X],ee)}]:[]),a.set(X,V);for(let ee of V)if(M[X]+ee.length<M[ee.index])M[ee.index]=M[X]+ee.length,B[ee.index]=X,L[ee.index]=L[X]}if(j>=0){let X=[];for(let he=j;he>=0;he=B[he])X.unshift(s[he]);let V=x[L[j]],ee=C[J];y=[V.port,V.stub,...X,ee.stub,ee.port]}}if(!y)continue;let _=Math.max(24,m.label.length*3.6+6),A=y.slice(1).map((M,B)=>({first:y[B],point:M,length:hc(y[B],M)})).filter((M)=>M.length>0).sort((M,B)=>B.length-M.length),w;for(let M=16;m.label&&!w;M+=20)w=A.flatMap(({first:L,point:Y,length:j})=>[0.5,0.25,0.75].flatMap((J)=>[-M,M].map((X)=>{let V=L.x+(Y.x-L.x)*J-(Y.y-L.y)*X/j,ee=L.y+(Y.y-L.y)*J+(Y.x-L.x)*X/j;return{x:V,y:ee,left:V-_,right:V+_,top:ee-16,bottom:ee+8}}))).find((L)=>![...o,...u].some((Y)=>L.left<Y.right&&L.right>Y.left&&L.top<Y.bottom&&L.bottom>Y.top));if(w)u.push(w);c.set(m.id,{points:y,path:y.map((M,B)=>`${B?"L":"M"} ${M.x} ${M.y}`).join(" "),label:w})}return c}var ms=(e)=>e.kind==="overview"?"overview":JSON.stringify(e),JL=(e,t)=>JSON.stringify([e,t].sort());function jT(e){let t=new Map,n=new Map,o=[],i=e.filter((s)=>s.kind!=="member");for(let s of i){if(s.missing){o.push(s);continue}if(s.source.boardId===s.target.boardId){n.set(s.source.boardId,(n.get(s.source.boardId)??0)+1);continue}let a=JL(s.source.boardId,s.target.boardId),l=t.get(a);if(l)l.edges.push(s);else t.set(a,{boardId:s.source.boardId,peerId:s.target.boardId,edges:[s]})}return{evidence:i,pairs:t,internal:n,missing:o}}function vp(e){let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return(t>>>0)/4294967296}function UT(e,t){let n=new Map(e.map((i)=>[i,new Map])),o=t.filter((i)=>i.from!==i.to&&n.has(i.from)&&n.has(i.to)).map((i)=>({ends:[i.from,i.to].sort(),weight:Math.max(0.1,i.weight??1)})).sort((i,s)=>i.ends[0].localeCompare(s.ends[0])||i.ends[1].localeCompare(s.ends[1])||i.weight-s.weight);for(let{ends:[i,s],weight:a}of o)n.get(i).set(s,(n.get(i).get(s)??0)+a),n.get(s).set(i,(n.get(s).get(i)??0)+a);return n}function ZT(e,t,n,o){let i=t.get(e),s=[...o.values()].reduce((c,u)=>c+Math.sqrt(u),0),a=0,l=0;for(let c of n){if(c===e)continue;let u=t.get(c),d=i.x-u.x||(vp(e)-0.5)*0.01,p=i.y-u.y||(vp(`${e}:y`)-0.5)*0.01,m=Math.max(1,Math.hypot(d,p)),f=14000/(m*m),h=o.get(c)??0,g=h?(m-290)*0.006*Math.sqrt(h)/s:0;a+=d/m*(f-g),l+=p/m*(f-g);let v=Ye.width+Ye.gap,b=(Ye.height+Ye.gap)*Ye.width/Ye.height;if(Math.abs(d)<v&&Math.abs(p)<b)if(v-Math.abs(d)<b-Math.abs(p))a+=Math.sign(d)*(v-Math.abs(d))*0.2;else l+=Math.sign(p)*(b-Math.abs(p))*0.2}return{x:a,y:l}}function WT(e,t,n,o){let i=[...e.keys()].sort(),s=UT(i,t),a=Ye.width/Ye.height,l=new Map([...e].map(([u,d])=>[u,{x:d.x,y:d.y*a}])),c=0;for(let u of i){if(u===n)continue;let d=l.get(u),p=ZT(u,l,i,s.get(u)),m=Math.min(1,24/Math.max(1,Math.hypot(p.x,p.y)))*o,f=p.x*m,h=p.y*m/a;e.set(u,{x:d.x+f,y:d.y/a+h}),c=Math.max(c,Math.hypot(f,h))}for(let[u,d]of i.entries())for(let p of i.slice(u+1)){let m=e.get(d),f=e.get(p),h=m.x-f.x,g=m.y-f.y,v=Ye.width+Ye.gap-Math.abs(h),b=Ye.height+Ye.gap-Math.abs(g);if(v<=0||b<=0)continue;let x=v<b?{x:(Math.sign(h)||-1)*v,y:0}:{x:0,y:(Math.sign(g)||-1)*b},C=p===n?1:0.5,y=d===n?1:0.5;if(d!==n)e.set(d,{x:m.x+x.x*C,y:m.y+x.y*C});if(p!==n)e.set(p,{x:f.x-x.x*y,y:f.y-x.y*y});c=Math.max(c,Math.hypot(x.x,x.y))}return c}function qT(e,t,n){let o=[...new Set(e.map((y)=>y.key))].sort();if(o.every((y)=>n.has(y)))return new Map(o.map((y)=>[y,n.get(y)]));let i=UT(o,t),s=[],a=new Set;for(let y of o){if(a.has(y))continue;let k=[y];a.add(y);for(let _ of k)for(let A of i.get(_).keys()){if(a.has(A))continue;a.add(A),k.push(A)}s.push(k.sort())}let l=new Map,c=Ye.width/Ye.height;for(let y of o){let k=n.get(y);if(k)l.set(y,{x:k.x,y:k.y*c})}for(let y of s){if(!y.some((k)=>l.has(k)))l.set(y[0],{x:0,y:0});while(y.some((k)=>!l.has(k)))for(let k of y){if(l.has(k))continue;let _=[...i.get(k).keys()].filter((A)=>l.has(A));if(!_.length)continue;l.set(k,{x:_.reduce((A,w)=>A+l.get(w).x,0)/_.length+(vp(k)-0.5)*240,y:_.reduce((A,w)=>A+l.get(w).y,0)/_.length+(vp(`${k}:y`)-0.5)*240})}for(let k=0;k<180;k++){let _=new Map;for(let A of y){if(n.has(A))continue;let w=l.get(A),{x:M,y:B}=ZT(A,l,y,i.get(A)),L=Math.min(1,24/Math.max(1,Math.hypot(M,B)))*(1-k/200);_.set(A,{x:w.x+M*L,y:w.y+B*L})}for(let[A,w]of _)l.set(A,w)}}for(let[y,k]of l)l.set(y,n.get(y)??{x:k.x,y:k.y/c});let u=o.filter((y)=>n.has(y)).map((y)=>l.get(y)),d=Ye.width+Ye.gap,p=Ye.height+Ye.gap,m=(y,k)=>Math.abs(y.x-k.x)<d&&Math.abs(y.y-k.y)<p,f=0,h=0,g=0,v=0,b=Math.sqrt(o.length)*380,x=(y)=>y.some((k)=>n.has(k));s.sort((y,k)=>Number(x(k))-Number(x(y)));let C=!1;for(let y of s){let k=x(y);if(!k&&!C)f=u.length?Math.max(...u.map((w)=>w.x))+340:0,h=f,C=!0;let _=k?u:[],A=[];for(let w of y){if(n.has(w))continue;let M=l.get(w),B=M;if(_.some((L)=>m(B,L)))B=_.flatMap((Y)=>[{x:Y.x-d,y:M.y},{x:Y.x+d,y:M.y},{x:M.x,y:Y.y-p},{x:M.x,y:Y.y+p}]).filter((Y)=>!_.some((j)=>m(Y,j))).sort((Y,j)=>Math.hypot(Y.x-M.x,Y.y-M.y)-Math.hypot(j.x-M.x,j.y-M.y))[0];l.set(w,B),_.push(B),A.push(B)}if(!k&&A.length){let w=Math.min(...A.map((B)=>B.x)),M=Math.min(...A.map((B)=>B.y));for(let B of A)B.x+=h-w,B.y+=g-M;if(u.push(...A),h=Math.max(...A.map((B)=>B.x))+340,v=Math.max(v,Math.max(...A.map((B)=>B.y))-g+200),h-f>b)h=f,g+=v,v=0}}for(let[y,k]of l)if(!n.has(y))n.set(y,k);return l}var GT={portal:"Portals",wiki:"Wiki links",card:"Card relations",previous:"Previous boards"},Og=(e)=>({scene:e,camera:null,query:"",context:!1,folders:new Set,hiddenLinks:new Set,inspection:null,limit:80});function KT(){let e=Ge.value,{graph:t,loading:n,error:o,retry:i}=yp("full"),[s,a]=E([Og({kind:"overview"})]),l=s.at(-1),c=l.scene,u=ms(c),[d,p]=E(!1),[m,f]=E(0),[h,g]=E(0),[v,b]=E(null),[x,C]=E(""),[y,k]=E({width:0,height:0}),_=F(new Map),A=F(null),w=F(null),M=F(null),B=F(null),L=()=>{if(M.current!==null)cancelAnimationFrame(M.current);M.current=null,B.current=null},Y=F(!1),j=(S)=>a((K)=>[...K.slice(0,-1),{...K.at(-1),...S}]),J=()=>{a((S)=>S.length>1?S.slice(0,-1):S),p(!1),b(null),C("")},X=(S)=>{if(ms(S)===u){f((K)=>K+1);return}a((K)=>[...K,Og(S)]),p(!1),b(null),C("")},V=(S)=>{let K=s.map((ue)=>ms(ue.scene)).lastIndexOf(ms(S));if(K>=0)a((ue)=>ue.slice(0,K+1));else X(S);p(!1)};$e(()=>{pt.value=!0},[]),$e(()=>{let S=A.current,K=()=>k({width:S.clientWidth,height:S.clientHeight}),ue=new ResizeObserver(K);return ue.observe(S),K(),()=>ue.disconnect()},[]),$e(()=>{let S=(K)=>{if(!ar(K))return;if(l.inspection||s.length>1)if(K.preventDefault(),l.inspection)j({inspection:null});else J()};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[l.inspection,s.length]);let ee=Ve(()=>(t?.nodes??[]).map((S)=>{let K=e.find((ue)=>ue.id===S.boardId);return K?{...S,folder:K.folder,...S.kind==="board"?{title:K.name,nodeCount:K.nodeCount,inContext:!!K.pin}:{}}:S}),[t,e]),he=Ve(()=>new Map(ee.map((S)=>[S.key,S])),[ee]),R=Ve(()=>jT(t?.edges??[]),[t]),te=c.kind==="overview"?null:Mt(c),O=te?he.get(te):void 0,H=(S)=>e.find((K)=>K.id===S)?.name??S,Me=(S)=>c.kind!=="overview"&&S.boardId===c.boardId,je=c.kind==="overview"?R.evidence:R.evidence.filter((S)=>c.kind==="board"?S.source.boardId===c.boardId||S.target.boardId===c.boardId:S.from===te||S.to===te),He=Ve(()=>{if(c.kind==="overview")return{nodes:ee.filter((ue)=>ue.kind==="board"),links:[...R.pairs].map(([ue,Oe])=>({id:ue,from:Mt({boardId:Oe.boardId}),to:Mt({boardId:Oe.peerId}),edges:Oe.edges,bundle:!0}))};let S=new Set;if(c.kind==="board"){for(let ue of ee)if(Me(ue)&&ue.kind==="card")S.add(ue.key)}else if(te&&he.has(te))S.add(te);let K=new Map;for(let ue of je){if(ue.missing||!he.has(ue.from)||!he.has(ue.to))continue;let Oe=c.kind==="board"&&ue.source.boardId!==c.boardId?Mt({boardId:ue.source.boardId}):ue.from,We=c.kind==="board"&&ue.target.boardId!==c.boardId?Mt({boardId:ue.target.boardId}):ue.to;S.add(Oe),S.add(We);let le=c.kind==="card"?ue.id:JSON.stringify([Oe,We].sort()),we=K.get(le);if(we)we.edges.push(ue),we.bundle=!0;else K.set(le,{id:le,from:Oe,to:We,edges:[ue],bundle:Oe!==ue.from||We!==ue.to})}return{nodes:ee.filter((ue)=>S.has(ue.key)),links:[...K.values()]}},[ee,t,u]),Re=new Map;for(let S of He.links)for(let K of[S.from,S.to])Re.set(K,(Re.get(K)??0)+S.edges.length);let ve=He.nodes.filter((S)=>Re.has(S.key)||S.key===te),D=He.nodes.filter((S)=>!Re.has(S.key)&&S.key!==te),re=(S)=>S.key===te||(!l.context||S.inContext)&&!l.folders.has(S.folder?.split("/")[0]??"")&&`${S.title} ${S.summary} ${H(S.boardId)} ${S.folder??""}`.toLocaleLowerCase().includes(l.query.trim().toLocaleLowerCase()),ze=ve.filter(re).sort((S,K)=>Number(K.key===te)-Number(S.key===te)||(Re.get(K.key)??0)-(Re.get(S.key)??0)||S.key.localeCompare(K.key)),ke=ze.slice(0,l.limit),ae=new Set(ke.map((S)=>S.key)),Se=D.filter(re),de=He.links.map((S)=>({...S,edges:S.edges.filter((K)=>!l.hiddenLinks.has(K.kind))})).filter((S)=>S.edges.length&&ae.has(S.from)&&ae.has(S.to));G(()=>()=>{L(),Y.current||=!!w.current?.moved,w.current=null},[He,l.limit,l.query,l.context,l.folders,l.hiddenLinks]);let Ze=(S)=>{if(M.current!==null)return;let K=180,ue=()=>{let Oe=w.current?.key===S,We=_.current.get(u);if(B.current)We.set(S,B.current);B.current=null;let le=new Map(ke.map((ge)=>[ge.key,We.get(ge.key)])),we=WT(le,de.map((ge)=>({...ge,weight:ge.edges.length})),S,Oe?1:K/180);for(let[ge,De]of le)We.set(ge,De);if(g((ge)=>ge+1),Oe||--K>0&&we>0.02)M.current=requestAnimationFrame(ue);else M.current=null};M.current=requestAnimationFrame(ue)},xe=Ve(()=>{let S=_.current.get(u);if(!S)S=new Map,_.current.set(u,S);if(c.kind!=="card")return qT(ve,He.links.map((ge)=>({...ge,weight:ge.edges.length})),S);if(!S.has(te))S.set(te,{x:0,y:0});let K=je.filter((ge)=>ge.kind!=="card"||ho({kind:ge.relationKind,type:ge.type},e.find((De)=>De.id===ge.source.boardId)?.relationVocabulary).directed),ue=new Set(K.filter((ge)=>ge.to===te).map((ge)=>ge.from)),Oe=new Set(K.filter((ge)=>ge.from===te).map((ge)=>ge.to)),We=ve.filter((ge)=>ge.key!==te).sort((ge,De)=>ge.key.localeCompare(De.key)),le=Ye.width+Ye.gap,we=Ye.height+Ye.gap;for(let ge of["incoming","outgoing","mutual"]){let De=We.filter((on)=>(ue.has(on.key)&&!Oe.has(on.key)?"incoming":Oe.has(on.key)&&!ue.has(on.key)?"outgoing":"mutual")===ge),Rt=De.filter((on)=>S.has(on.key)).map((on)=>S.get(on.key)),gt=S.get(te).y+we,mn=0;for(let[on,vs]of De.entries())if(!S.has(vs.key)){let Pn=Rt.length?Math.max(...Rt.map((fn)=>ge==="mutual"?fn.x:fn.y))+(mn+1)*(ge==="mutual"?le:we):(on-(De.length-1)/2)*(ge==="mutual"?le:we),xn=ge==="mutual"?{x:Pn,y:gt}:{x:ge==="incoming"?-360:360,y:Pn};while([...S.values()].some((fn)=>Math.abs(fn.x-xn.x)<le&&Math.abs(fn.y-xn.y)<we))xn.y+=we;S.set(vs.key,xn),mn++}}return new Map(S)},[He,u,h]),Ke=(S)=>S.bundle?`${S.edges.length} links`:S.edges[0].kind==="card"?ho({kind:S.edges[0].relationKind,type:S.edges[0].type},e.find((K)=>K.id===S.edges[0].source.boardId)?.relationVocabulary).kind:S.edges[0].kind,q=Ve(()=>FT(new Map(ke.map((S)=>[S.key,xe.get(S.key)])),de.map((S)=>({...S,label:S.edges.length>1||c.kind==="card"?Ke(S):""})).sort((S,K)=>S.id.localeCompare(K.id))),[xe,He,l.limit,l.query,l.context,l.folders,l.hiddenLinks]),ye=l.camera??{x:0,y:0,scale:1},Ue=ke.filter((S)=>{let K=xe.get(S.key);return(K.x-Ye.width/2)*ye.scale+ye.x<8||(K.x+Ye.width/2)*ye.scale+ye.x>y.width-8||(K.y-Ye.height/2)*ye.scale+ye.y<(c.kind==="card"?40:8)||(K.y+Ye.height/2)*ye.scale+ye.y>y.height-64}).length,N=(S=!1)=>{let K=A.current;if(!K||!ke.length)return;let ue=c.kind==="card"?40:16,Oe=K.clientHeight-ue-64-8,We=ke.flatMap((gt)=>{let mn=xe.get(gt.key);return[{x:mn.x-Ye.width/2,y:mn.y-Ye.height/2},{x:mn.x+Ye.width/2,y:mn.y+Ye.height/2}]});for(let gt of q.values())if(We.push(...gt.points),gt.label)We.push({x:gt.label.left,y:gt.label.top},{x:gt.label.right,y:gt.label.bottom});let le=Math.min(...We.map((gt)=>gt.x)),we=Math.min(...We.map((gt)=>gt.y)),ge=Math.max(...We.map((gt)=>gt.x))-le,De=Math.max(...We.map((gt)=>gt.y))-we,Rt=Math.min(1,Math.max(S?1:0.005,Math.min((K.clientWidth-64)/ge,Oe/De)));j({camera:S&&c.kind==="card"?{x:K.clientWidth/2-xe.get(te).x,y:ue+Oe/2-xe.get(te).y,scale:1}:{x:(K.clientWidth-ge*Rt)/2-le*Rt,y:ue+(Oe-De*Rt)/2-we*Rt,scale:Rt}})};$e(()=>{if(t&&!l.camera&&ke.length)N(!0)},[t,u,l.camera]),G(()=>{if(!t||c.kind==="overview"||O)return;let S=he.has(Mt({boardId:c.boardId}));a((K)=>{let ue=K.filter((We)=>We.scene.kind==="overview"||he.has(Mt(We.scene))),Oe=c.kind==="card"&&S?{kind:"board",boardId:c.boardId}:{kind:"overview"};return ms(ue.at(-1).scene)===ms(Oe)?ue:[...ue,Og(Oe)]}),C("The focused endpoint was removed. Returned to its nearest available level.")},[t,te,O]);let ne=(S)=>{let K=xe.get(S.key),ue=A.current;if(!K||!ue)return;let Oe=Math.max(1,ye.scale);j({camera:{x:ue.clientWidth/2-K.x*Oe,y:ue.clientHeight/2-K.y*Oe-20,scale:Oe},limit:Math.max(l.limit,ze.indexOf(S)+1)}),p(!1)},Ce=(S)=>{if(S.kind==="card"&&S.cardId)X({kind:"card",boardId:S.boardId,cardId:S.cardId});else X({kind:"board",boardId:S.boardId})},Te=(S,K)=>{let ue=A.current;if(!ue)return;let Oe=K??{x:ue.clientWidth/2,y:ue.clientHeight/2},We=Math.max(0.005,Math.min(3,S));j({camera:{x:Oe.x-(Oe.x-ye.x)*We/ye.scale,y:Oe.y-(Oe.y-ye.y)*We/ye.scale,scale:We}})},me=He.links.find((S)=>S.id===l.inspection),at=me?.edges??je,Ft=O?e.find((S)=>S.id===O.boardId):void 0,Qe=(S)=>{j({inspection:S.id}),f((K)=>K+1)},Lt=(S,K,ue)=>r("label",{class:"home-memory-check",children:[r("input",{type:"checkbox","aria-label":S,checked:K,onChange:ue},void 0,!1,void 0,this),r("span",{children:S},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U=c.kind!=="overview"&&!O,Ie=c.kind==="overview"?"Library":c.kind==="board"?H(c.boardId):O?.title??"Missing card";return r("main",{class:`home-memory graph-view${d?" sidebar-open":""}`,"aria-label":"Library Graph",style:{"--graph-node-width":`${Ye.width}px`,"--graph-node-height":`${Ye.height}px`},children:[r("div",{class:"home-memory-toolbar",children:[s.length>1&&r("button",{type:"button",class:"home-button",onClick:J,children:"Back"},void 0,!1,void 0,this),r("nav",{class:"graph-breadcrumb","aria-label":"Graph path",children:[r("button",{type:"button",class:"home-button",onClick:()=>V({kind:"overview"}),children:"Library"},void 0,!1,void 0,this),c.kind!=="overview"&&r(be,{children:[r("span",{children:"›"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button",onClick:()=>V({kind:"board",boardId:c.boardId}),children:H(c.boardId)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c.kind==="card"&&r(be,{children:[r("span",{children:"›"},void 0,!1,void 0,this),r("strong",{children:Ie},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("span",{children:[ke.length," of ",ve.length," connected drawn · ",Ue," partly/outside view ·"," ",ve.length-ze.length," filtered · ",Math.max(0,ze.length-ke.length)," hidden ·"," ",D.length," without links"]},void 0,!0,void 0,this),ze.length>l.limit&&r("button",{type:"button",class:"home-button",onClick:()=>j({limit:l.limit+80}),children:"Show more connections"},void 0,!1,void 0,this),r("span",{class:`home-memory-live${o?" is-error":""}`,role:"status",children:o?"Update failed":n?"Updating…":"Live"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button home-memory-sidebar-toggle","aria-expanded":d,onClick:()=>p(!d),children:"Filters"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-body",children:[r("div",{class:"home-memory-stage",ref:A,"aria-label":"Pan the memory view",onWheel:(S)=>{S.preventDefault();let K=S.currentTarget.getBoundingClientRect();Te(ye.scale*Math.exp(-S.deltaY*0.0015),{x:S.clientX-K.left,y:S.clientY-K.top})},onPointerDown:(S)=>{if(S.button!==0||S.target.closest('button, [role="button"]'))return;L(),Y.current=!1,w.current={id:S.pointerId,start:{x:S.clientX,y:S.clientY},origin:ye,moved:!1},S.currentTarget.setPointerCapture(S.pointerId)},onPointerMove:(S)=>{let K=w.current;if(!K||K.id!==S.pointerId||!(S.buttons&1))return;let ue=S.clientX-K.start.x,Oe=S.clientY-K.start.y;if(Math.abs(ue)+Math.abs(Oe)>4)K.moved=!0;if(!K.moved)return;let We={x:K.origin.x+ue/(K.key?ye.scale:1),y:K.origin.y+Oe/(K.key?ye.scale:1)};if(K.key)B.current=We,Ze(K.key);else j({camera:{...We,scale:ye.scale}})},onPointerUp:()=>{if(!w.current)return;Y.current=w.current.moved,w.current=null},onPointerCancel:()=>{let S=w.current;if(L(),S?.layout)_.current.set(u,S.layout),g((K)=>K+1);else if(S)j({camera:{...S.origin,scale:ye.scale}});Y.current=!!S?.moved,w.current=null},children:[c.kind==="card"&&r("div",{class:"graph-direction-caption",children:"Incoming starts left · outgoing starts right · drag to rearrange"},void 0,!1,void 0,this),r("div",{class:"home-memory-world",style:{transform:`translate(${ye.x}px, ${ye.y}px) scale(${ye.scale})`},children:[r("svg",{class:"home-memory-links graph-links","aria-label":"Graph connections",children:de.map((S,K)=>{let ue=q.get(S.id);if(!ue)return null;let Oe=S.edges[0],We=ho({kind:Oe.relationKind,type:Oe.type},e.find((De)=>De.id===Oe.source.boardId)?.relationVocabulary),le=!S.bundle&&(Oe.kind!=="card"||We.directed),we=S.bundle?"var(--c-muted)":Oe.kind==="card"?`var(--c-rel-${We.ink})`:Oe.kind==="wiki"?"var(--c-rel-cites)":"var(--c-rel-derived)",ge=`${S.edges.length} ${S.bundle?"links":"link"} between ${he.get(S.from)?.title} and ${he.get(S.to)?.title}`;return r("g",{class:`graph-link${S.bundle?" is-bundle":" is-exact"}${S.from===v||S.to===v?" is-highlighted":""}${l.inspection===S.id?" is-selected":""}`,"data-from":S.from,"data-to":S.to,"data-count":S.edges.length,"data-link-id":S.id,role:"button",tabindex:0,"aria-label":`Inspect ${ge}`,style:{stroke:we},onClick:()=>Qe(S),onKeyDown:(De)=>{if(De.key==="Enter"||De.key===" ")De.preventDefault(),Qe(S)},children:[r("defs",{children:r("marker",{id:`graph-arrow-${K}`,viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto",children:r("path",{d:"M 0 0 L 10 5 L 0 10 z",style:{fill:we,stroke:"none"}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("path",{class:"graph-link-hit",d:ue.path},void 0,!1,void 0,this),r("path",{class:"graph-link-line",d:ue.path,"marker-end":le?`url(#graph-arrow-${K})`:void 0},void 0,!1,void 0,this),ue.label&&(S.edges.length>1||c.kind==="card")&&r("text",{x:ue.label.x,y:ue.label.y,children:Ke(S)},void 0,!1,void 0,this)]},S.id,!0,void 0,this)})},void 0,!1,void 0,this),ke.map((S,K)=>{let ue=xe.get(S.key),Oe=e.find((le)=>le.id===S.boardId),We=S.kind==="board"?S.inContext:!!Oe?.pinnedTitles?.some((le)=>le.nodeId===S.cardId)||S.inContext&&!Oe?.pin;return r("article",{"data-key":S.key,class:`graph-node is-${S.kind}${te===S.key?" is-selected":""}${We?" in-context":""}${c.kind!=="overview"&&!Me(S)?" is-external":""}`,style:{left:ue.x,top:ue.y},onPointerEnter:()=>b(S.key),onPointerLeave:()=>b(null),children:r("button",{type:"button",class:"home-memory-select","aria-label":`${S.kind}: ${S.title}`,"aria-pressed":te===S.key,onClick:()=>{if(!Y.current)Ce(S);Y.current=!1},onPointerDown:(le)=>{if(le.button!==0)return;le.stopPropagation(),L(),Y.current=!1,w.current={id:le.pointerId,start:{x:le.clientX,y:le.clientY},origin:ue,key:S.key,layout:new Map(_.current.get(u)),moved:!1},le.currentTarget.setPointerCapture(le.pointerId)},onKeyDown:(le)=>{if(!le.key.startsWith("Arrow"))return;le.preventDefault();let we=(K+(le.key==="ArrowLeft"||le.key==="ArrowUp"?-1:1)+ke.length)%ke.length,ge=ke[we];if(ge)ne(ge),A.current?.querySelectorAll(".home-memory-select")[we]?.focus({preventScroll:!0})},children:[r("span",{class:"graph-glyph","aria-hidden":"true"},void 0,!1,void 0,this),r("strong",{children:S.title},void 0,!1,void 0,this),r("span",{children:S.kind==="board"?`${S.nodeCount??0} cards · ${R.internal.get(S.boardId)??0} internal`:`${H(S.boardId)} · ${S.type??"card"}`},void 0,!1,void 0,this),r("span",{class:We?"memory-context-legend":"",children:We?"⌖ In context":S.folder||"Unfiled"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},S.key,!1,void 0,this)})]},void 0,!0,void 0,this),r("div",{class:"home-memory-zoom",children:[r("button",{type:"button",class:"home-button","aria-label":"Zoom out",onClick:()=>Te(ye.scale/1.2),children:"−"},void 0,!1,void 0,this),r("span",{children:[Math.round(ye.scale*100),"%"]},void 0,!0,void 0,this),r("button",{type:"button",class:"home-button","aria-label":"Zoom in",onClick:()=>Te(ye.scale*1.2),children:"+"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button",onClick:()=>N(),children:"Fit view"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(x||U||!t||!ke.length||o)&&r("div",{class:"home-memory-status",role:"status",children:x||(U?"This endpoint is no longer available. Use Back to return.":o?r(be,{children:["Memory update failed."," ",r("button",{type:"button",class:"home-button",onClick:i,children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):!t?"Loading memory…":Se.length?"No linked nodes in this view. Choose a node in No connections below.":"No matching nodes.")},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("aside",{class:"home-memory-sidebar","aria-label":"Graph settings",children:[r("section",{children:[r("h2",{children:c.kind==="overview"?"Find boards":"Find cards and neighbors"},void 0,!1,void 0,this),r("label",{class:"home-memory-search",children:[r("span",{children:"Search graph"},void 0,!1,void 0,this),r("input",{type:"search",value:l.query,placeholder:"Search this graph…",onInput:(S)=>j({query:S.currentTarget.value})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l.query&&r("ul",{class:"graph-search-results",children:[...ve,...D].filter(re).slice(0,30).map((S)=>r("li",{children:r("button",{type:"button",class:"home-button",onClick:()=>{if(Re.has(S.key)||S.key===te)ne(S);else Ce(S)},children:S.title},void 0,!1,void 0,this)},S.key,!1,void 0,this))},void 0,!1,void 0,this),Lt("Only in context",l.context,()=>j({context:!l.context}))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Folders"},void 0,!1,void 0,this),[...new Set(He.nodes.map((S)=>S.folder?.split("/")[0]??""))].sort().map((S)=>r("div",{children:Lt(S||"Unfiled",!l.folders.has(S),()=>{let K=new Set(l.folders);if(K.has(S))K.delete(S);else K.add(S);j({folders:K})})},S,!1,void 0,this))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Links"},void 0,!1,void 0,this),Object.keys(GT).map((S)=>r("div",{children:Lt(GT[S],!l.hiddenLinks.has(S),()=>{let K=new Set(l.hiddenLinks);if(K.has(S))K.delete(S);else K.add(S);j({hiddenLinks:K})})},S,!1,void 0,this))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Library evidence"},void 0,!1,void 0,this),r("p",{class:"graph-accounting",children:[R.evidence.length," links ·"," ",[...R.pairs.values()].reduce((S,K)=>S+K.edges.length,0)," between boards ·"," ",[...R.internal.values()].reduce((S,K)=>S+K,0)," inside boards ·"," ",R.missing.length," missing"]},void 0,!0,void 0,this),r("p",{class:"home-memory-help",children:"Counts retain original evidence. Folder membership is not a relation. Filters change the drawing, not the totals."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Se.length>0&&r("details",{class:"graph-unlinked",open:!0,children:[r("summary",{children:["No connections (",Se.length,")"]},void 0,!0,void 0,this),r("div",{children:Se.map((S)=>r("button",{type:"button",class:"home-button graph-tray-node","aria-label":`${S.kind}: ${S.title}`,onClick:()=>Ce(S),children:[S.title,r("small",{children:S.kind==="board"?`${S.nodeCount??0} cards`:H(S.boardId)},void 0,!1,void 0,this)]},S.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-legend","aria-label":"Legend",children:[r("span",{children:"Click nodes to drill · drag nodes to rearrange · lines for evidence · drag background to pan · scroll to zoom · Fit shows extent · search reveals at readable size"},void 0,!1,void 0,this),r("span",{class:"memory-context-legend",children:"⌖ In context"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(gp,{initiallyCollapsed:!0,reveal:m,children:O||me?r("section",{class:"home-memory-details",role:"complementary","aria-label":"Selection details",children:[me&&r("button",{type:"button",class:"home-memory-clear","aria-label":"Close details",onClick:()=>j({inspection:null}),children:"×"},void 0,!1,void 0,this),r("div",{class:"home-memory-detail-header",children:[r("div",{class:"home-memory-selection-title",children:[r("h3",{children:[me?`${he.get(me.from)?.title} ↔ ${he.get(me.to)?.title}`:Ie," ·"," ",at.length," connections"]},void 0,!0,void 0,this),r("p",{children:me?"Original evidence, not a new aggregate relation":`${O?.folder||"Unfiled"} / ${H(O.boardId)}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-actions",children:O&&r(be,{children:[r("button",{type:"button",class:"home-button is-primary",onClick:()=>void zt(O),children:["Open ",O.kind]},void 0,!0,void 0,this),Ft&&r(go,{board:Ft},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-detail-body",children:[O&&r("p",{class:O.inContext?"memory-context-legend":"",children:[O.inContext?"⌖ In context":"Not in context",O.linksComplete===!1?" · Partial discovery":""]},void 0,!0,void 0,this),r("details",{class:"home-memory-connections",open:!0,children:[r("summary",{children:["Connections",me?" within this pair":""]},void 0,!0,void 0,this),r("ul",{children:[at.map((S)=>{let K=c.kind==="card"?S.from===te:c.kind==="board"?S.source.boardId===c.boardId:!0,ue=K?S.target:S.source,Oe=he.get(Mt(ue)),We=ho({kind:S.relationKind,type:S.type},e.find((we)=>we.id===S.source.boardId)?.relationVocabulary),le=S.kind!=="card"||We.directed;return r("li",{children:[r("span",{children:[le?K?"→":"←":"↔"," ",S.kind==="card"?Ca({...S,kind:S.relationKind}):`${S.kind}${S.label?` · ${S.label}`:""}`]},void 0,!0,void 0,this),r("small",{children:[he.get(S.from)?.title??S.source.cardId??H(S.source.boardId)," ",le?"→":"↔"," ",he.get(S.to)?.title??S.target.cardId??H(S.target.boardId)," ·"," ",H(ue.boardId)]},void 0,!0,void 0,this),!Oe||S.missing?r("span",{class:"home-memory-missing",children:["⚠ Missing target: ",ue.boardId,ue.cardId?` / ${ue.cardId}`:""]},void 0,!0,void 0,this):r("button",{type:"button",class:"home-button",onClick:()=>Ce(Oe),children:["Follow ",Oe.title]},void 0,!0,void 0,this)]},S.id,!0,void 0,this)}),(t?.unresolvedLinks??[]).filter((S)=>c.kind==="board"?S.source.boardId===c.boardId:Mt(S.source)===te).map((S)=>r("li",{class:"home-memory-missing",children:["⚠ Unresolved wiki: [[",S.ref,"]]"]},`${Mt(S.source)}:${S.ref}`,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):r("div",{class:"home-memory-empty-details",children:[r("h3",{children:"Connections"},void 0,!1,void 0,this),r("p",{class:"home-memory-help",children:"Click a board to explore, then a card to see its exact neighbors. Click a connection line to read the original evidence. Open content is always separate."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},"inspector",!1,void 0,this)]},void 0,!0,void 0,this)}function VT({folder:e,folders:t,onScopeChange:n}){let[o,i]=E(""),[s,a]=E(!1),[l,c]=E(null),[u,d]=E(""),p=Be.value;G(()=>{if(p)Kt()},[p]),$e(()=>{let C=(y)=>{if(!Be.value)return;if(!ar(y))return;y.preventDefault(),i(""),a(!1)};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[]);let m=Jn.value,f=(C)=>!e||C===e||!!C?.startsWith(`${e}/`),h=(m?.reviewCards??[]).filter((C)=>f(C.folder)),g=o.trim().toLocaleLowerCase(),v=h.filter((C)=>{let y=m?.cards[Mt(C)];return y&&(!s||y.sources.length>0)&&(!g||`${C.title} ${C.boardTitle} ${y.reasons.join(" ")} ${y.sources.map((k)=>k.title).join(" ")}`.toLocaleLowerCase().includes(g))}),b=new Set(Ge.value.filter((C)=>f(C.folder)).map((C)=>C.id)),x=Object.entries(m?.cards??{}).filter(([C,y])=>!y.retired&&y.unknown&&b.has(JSON.parse(C)[0])).length;if(!p)return null;return r("section",{class:"home-review-view","aria-label":"Card review queue",children:[r("div",{class:"home-main-head",children:[r("div",{class:"home-main-title",children:[r("h1",{class:"home-view-title",children:"Knowledge review"},void 0,!1,void 0,this),r("p",{children:e?`${e} and descendants`:"Whole library"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("label",{children:["Review scope",r("select",{value:e,onChange:(C)=>n(C.currentTarget.value),children:[r("option",{value:"",children:"Whole library"},void 0,!1,void 0,this),t.map((C)=>r("option",{value:C,children:[C," and descendants"]},C,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-review-controls",children:[r("label",{children:["Find review cards",r("input",{type:"search",value:o,onInput:(C)=>i(C.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("label",{children:[r("input",{type:"checkbox",checked:s,onChange:(C)=>a(C.currentTarget.checked)},void 0,!1,void 0,this),"Source warnings only"]},void 0,!0,void 0,this),r("button",{type:"button",class:"home-button",onClick:()=>void Kt(),children:"Refresh queue"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ui.value&&r("p",{role:"status",children:"Queue unavailable. Retained results may be out of date. Refresh to retry."},void 0,!1,void 0,this),u&&r("p",{role:"alert",children:u},void 0,!1,void 0,this),!m?r("p",{children:"Loading review cards…"},void 0,!1,void 0,this):r(be,{children:[r("p",{class:"home-review-count",children:["Review needed: ",h.length," ",h.length===1?"card":"cards"," · Showing ",v.length]},void 0,!0,void 0,this),r("table",{class:"home-review-table",children:[r("thead",{children:r("tr",{children:[r("th",{children:"Card"},void 0,!1,void 0,this),r("th",{children:"Board"},void 0,!1,void 0,this),r("th",{children:"Why review"},void 0,!1,void 0,this),r("th",{children:"Last checked"},void 0,!1,void 0,this),r("th",{children:"Open"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),r("tbody",{children:v.map((C)=>{let y=Mt(C),k=m.cards[y],_=[...k.reasons,...k.sources.map((A)=>`${A.title}: ${A.reasons.join(" ")||"Source needs review."}`)];return r("tr",{children:[r("td",{"data-label":"Card",children:C.title},void 0,!1,void 0,this),r("td",{"data-label":"Board",children:C.boardTitle},void 0,!1,void 0,this),r("td",{"data-label":"Why review",children:_.join(" ")||"A source needs review."},void 0,!1,void 0,this),r("td",{"data-label":"Last checked",children:k.lastValidatedAt?new Date(k.lastValidatedAt).toLocaleString():"Never checked"},void 0,!1,void 0,this),r("td",{children:r("button",{type:"button",class:"home-button",disabled:l===y,"aria-label":`Open review: ${C.title} on ${C.boardTitle}`,onClick:async()=>{if(!Be.value)return;c(y),d("");let A=await zt(C,{review:!0});if(c(null),!A)d("Review did not open. The card may have moved or navigation was cancelled. Refresh and try again.")},children:"Open review"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},y,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v.length===0&&r("p",{children:"No actionable cards in these filters."},void 0,!1,void 0,this),r("p",{class:"home-review-neutral",children:["No review policy: ",x," ",x===1?"card":"cards",". Missing policy is neutral, not overdue. Explicit content or source warnings still enter the queue."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var YL=Li({decayType:rn(["reality","decision","dependency","relevance"]),rate:rn(["fast","medium","slow","durable"]),triggers:Pe(z().trim().min(1)),revalidationMethod:z().trim().min(1),cadenceDays:Ee().int().min(1).max(36500).optional()}).refine((e)=>e.rate!=="medium"||e.cadenceDays!==void 0,{path:["cadenceDays"],message:"Medium lifecycle requires a cadence in days."}),XT=YL.safeExtend({id:z().trim().min(1),name:z().trim().min(1),glyph:z().trim().min(1)});var lr=(e,t,n,o,i,s)=>({id:e,name:t,glyph:n,decayType:o,rate:i,revalidationMethod:s,triggers:[],...i==="medium"?{cadenceDays:90}:{}}),JT=lr("research","Research","⌕","reality","medium","Check the sources and conflicting evidence."),YT=lr("metric","Metric","▥","reality","fast","Re-read the source dashboard and compare."),QT=lr("decision","Decision","⚑","decision","durable","Check for a superseding decision and changed dependencies."),eI=lr("notes","Notes","✎","relevance","slow","Check relevance to the resumed task."),bp={"Org · team · personal":{categories:[lr("strategy","Strategy","◎","relevance","slow","Check the current goals and decisions."),lr("policy","Policy","◇","decision","slow","Check with the policy owner."),QT,JT,YT,eI],folders:{Org:"strategy","Org/Policies":"policy",Team:"research","Team/Decisions":"decision","Team/Metrics":"metric",Personal:"notes"}},"Solo research":{categories:[lr("question","Question","?","relevance","slow","Check whether this question still matters."),lr("source","Source","▤","reality","medium","Re-read the original source."),lr("finding","Finding","◉","dependency","durable","Compare the supporting and contradicting evidence."),lr("note","Note","✎","relevance","slow","Check relevance to the resumed task.")],folders:{Projects:"question","Projects/Findings":"finding",Sources:"source",Notes:"note"}},"Product team":{categories:[JT,YT,QT,eI],folders:{Discovery:"research","Discovery/Metrics":"metric",Delivery:"notes",Decisions:"decision"}},Empty:{categories:[],folders:{}}};function tI({folder:e,onClose:t}){let n=Be.value,o=F(null),i=Jn.value,s=i?.folders.find((O)=>O.path===e),a=e?i?.resolvedFolders[e]:null,[l,c]=E(s?.categoryId??""),[u,d]=E(!!s?.lifecycleOverride),[p,m]=E(s?.lifecycleOverride??a?.lifecycle??Ra),[f,h]=E(()=>i?.categories[0]?structuredClone(i.categories[0]):null),[g,v]=E(null),b=i?.categories.find((O)=>O.id===f?.id),x=i?.folders.filter((O)=>O.categoryId===f?.id)??[],[C,y]=E(!1),[k,_]=E(""),[A,w]=E(()=>JSON.stringify(f)),[M,B]=E("Basics"),[L,Y]=E(""),[j,J]=E(null),X=!e&&JSON.stringify(f)!==A,V=(O)=>{if(!Be.value||C||j)return;if(X)J(()=>O);else O()},ee=()=>{if(!Be.value)return;if(j)J(null);else if(g)v(null);else V(t)};bn(o,n,{onEscape:ee}),$e(()=>{if(!n&&o.current?.contains(document.activeElement))document.querySelector('button[aria-label="Settings"]')?.focus({preventScroll:!0})},[n]),G(()=>{if(n)Kt()},[n]);let he=(O)=>{let H=structuredClone(O);h(H),w(JSON.stringify(H)),B("Basics"),v(null),_("")},R=async(O,H)=>{if(!Be.value)return!1;return(await pe("knowledgeWrite",`/api/canvas/knowledge/${O}`,null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(H)}))?.ok===!0},te=async(O)=>{if(!Be.value||C||!i)return;let H=tn;y(!0),_("");let Me=!0,je=bp[O];for(let He of je.categories){if(!Be.value||H!==tn){Me=!1;break}if(!i.categories.some((Re)=>Re.id===He.id))Me=await R("category",{category:He});if(!Me)break}if(Me)for(let[He,Re]of Object.entries(je.folders)){if(!Be.value||H!==tn){Me=!1;break}if(!i.folders.some((ve)=>ve.path===He))Me=await R("folder",{path:He,categoryId:Re,lifecycleOverride:null});if(!Me)break}await Kt(),y(!1),_(Me?O==="Empty"?"No starter data added. Existing data is unchanged.":"Starter data added. Existing categories and folder settings were preserved.":"Template stopped at a failed save. Saved entries remain; retry adds only missing entries.")};return r("div",{class:"knowledge-backdrop",hidden:!n,style:n?void 0:{display:"none"},onKeyDown:(O)=>{if(O.key==="Escape")O.stopPropagation(),O.preventDefault(),ee()},children:r("div",{ref:o,class:`knowledge-dialog${e?"":" is-category-editor"}`,role:"dialog","aria-modal":"true","aria-label":e?"Folder settings":"Categories",children:[r("header",{children:[r("div",{class:"knowledge-dialog-title",children:[r("h2",{children:e?`${e.split("/").at(-1)} · Folder settings`:"Workspace categories"},void 0,!1,void 0,this),e&&r("span",{class:"knowledge-folder-path",children:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button","aria-label":"Close settings",disabled:C,onClick:()=>V(t),children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k&&r("p",{role:"status",children:k},void 0,!1,void 0,this),j&&r("div",{role:"group","aria-label":"Discard category changes",class:"category-discard",children:[r("p",{children:"Discard unsaved category changes?"},void 0,!1,void 0,this),r("button",{type:"button",onClick:()=>J(null),children:"Keep editing"},void 0,!1,void 0,this),r("button",{type:"button",onClick:()=>{if(!Be.value)return;let O=j;J(null),w(JSON.stringify(f)),O()},children:"Discard changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!i?r("p",{children:"Knowledge settings unavailable. Close and retry."},void 0,!1,void 0,this):e?r("form",{onClick:jo,onSubmit:async(O)=>{if(O.preventDefault(),!Be.value||C)return;let H=tn;y(!0);let Me=await R("folder",{path:e,categoryId:l||null,lifecycleOverride:u?pc(p):null});if(await Kt(),y(!1),Me&&Be.value&&H===tn)t();else if(!Me)_("Folder settings were not saved. Retry.")},children:[r("div",{class:"knowledge-field",children:[r("span",{children:"Category"},void 0,!1,void 0,this),r(Or,{label:"Category",value:l,onChange:c,options:[{value:"",label:"Use the parent’s"},...i.categories.map((O)=>({value:O.id,label:`${O.glyph} ${O.name}`}))]},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("p",{children:["Currently"," ",a?.category?`${a.category.glyph} ${a.category.name} · ${a.categorySourceFolder===e?"set here":`inherited from ${a.categorySourceFolder}`}`:"unknown",". Cards inherit their category; only lifecycle can be overridden."]},void 0,!0,void 0,this),r("label",{children:[r("input",{type:"checkbox",checked:u,onChange:(O)=>d(O.currentTarget.checked)},void 0,!1,void 0,this)," ","Override lifecycle for this folder"]},void 0,!0,void 0,this),u?r(dc,{value:p,onChange:m},void 0,!1,void 0,this):r("p",{children:"Lifecycle comes from the selected category or parent. Unknown has no passive expiry."},void 0,!1,void 0,this),r("button",{type:"submit",disabled:C,children:"Save folder settings"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r(be,{children:[r("details",{class:"category-templates",children:[r("summary",{children:"Add from template"},void 0,!1,void 0,this),r("div",{class:"knowledge-presets",children:Object.entries(bp).map(([O,H])=>r("button",{type:"button",disabled:C||!!j,onClick:()=>V(()=>{if(X)h(b?structuredClone(b):null),w(JSON.stringify(b??null));te(O)}),children:[r("strong",{children:O},void 0,!1,void 0,this),r("span",{children:Object.keys(H.folders).join(" / ")||"No folders or categories"},void 0,!1,void 0,this)]},O,!0,void 0,this))},void 0,!1,void 0,this),r("p",{children:"Templates add missing data. They never replace your existing settings. Rename any category below."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"category-editor-columns",children:[r("section",{class:"category-list-panel",children:[r("h3",{children:[i.categories.length," categories"]},void 0,!0,void 0,this),r("label",{children:["Search categories",r("input",{type:"search",value:L,onInput:(O)=>Y(O.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",disabled:C,onClick:()=>V(()=>he({...Ra,id:crypto.randomUUID(),name:"",glyph:"◇"})),children:"Add category"},void 0,!1,void 0,this),r("div",{class:"category-library",role:"group","aria-label":"Workspace categories",children:i.categories.filter((O)=>O.name.toLocaleLowerCase().includes(L.toLocaleLowerCase())).map((O)=>r("button",{type:"button",class:"category-choice",disabled:C,"aria-pressed":f?.id===O.id,onClick:()=>{if(f?.id!==O.id)V(()=>he(O))},children:[r("strong",{children:[O.glyph," ",O.name]},void 0,!0,void 0,this),r("span",{children:[O.decayType," · ",O.rate,O.rate==="medium"&&O.cadenceDays?` · ${O.cadenceDays} days`:""]},void 0,!0,void 0,this)]},O.id,!0,void 0,this))},void 0,!1,void 0,this),r("p",{children:"Folders with no category above them stay unknown. Categories carry no colour."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f&&r("form",{class:"category-inspector",noValidate:!0,onClick:jo,onSubmit:async(O)=>{if(O.preventDefault(),!Be.value||C)return;let H=tn,Me=XT.safeParse({...f,...pc(f)});if(!Me.success){let Re=String(Me.error.issues[0].path[0]);B(["name","glyph","id"].includes(Re)?"Basics":"Review policy"),_(Me.error.issues[0].message),setTimeout(()=>{if(!Be.value||H!==tn)return;let ve=Re==="name"?"Name":Re==="glyph"?"Glyph":Re==="cadenceDays"?"Cadence in days":"How to check",D=o.current?.querySelectorAll("label");Array.from(D??[]).find((re)=>re.textContent?.trim().startsWith(ve))?.querySelector("input")?.focus()},0);return}y(!0);let je=await pe("knowledgeWrite","/api/canvas/knowledge/category",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({category:Me.data})}),He=je?.ok===!0;if(await Kt(),y(!1),!Be.value||H!==tn)return;if(He){let Re=je?.category??Me.data;h(Re),w(JSON.stringify(Re))}_(He?"Category saved. Inheriting folders now use these defaults.":"Category was not saved. Retry.")},children:[r("h3",{children:b?"Edit category defaults":"New category"},void 0,!1,void 0,this),r("div",{role:"tablist","aria-label":"Category settings",class:"category-tabs",children:["Basics","Review policy","Usage"].map((O)=>r("button",{type:"button",role:"tab",id:`category-tab-${O.replace(" ","-")}`,"aria-controls":"category-tab-panel","aria-selected":M===O,onClick:()=>B(O),children:O},O,!1,void 0,this))},void 0,!1,void 0,this),r("fieldset",{disabled:C||!!j,id:"category-tab-panel",role:"tabpanel","aria-labelledby":`category-tab-${M.replace(" ","-")}`,class:"category-tab-content",children:[M==="Basics"&&r(be,{children:[r("label",{children:["Name",r("input",{required:!0,value:f.name,onInput:(O)=>h({...f,name:O.currentTarget.value})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("label",{children:["Glyph",r("input",{required:!0,value:f.glyph,onInput:(O)=>h({...f,glyph:O.currentTarget.value})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"category-glyph-choices",role:"group","aria-label":"Glyph choices",children:[...new Set(Object.values(bp).flatMap((O)=>O.categories.map((H)=>H.glyph)))].map((O)=>r("button",{type:"button","aria-label":`Choose glyph ${O}`,"aria-pressed":f.glyph===O,onClick:()=>h({...f,glyph:O}),children:O},O,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M==="Review policy"&&r(dc,{value:f,onChange:(O)=>h({...f,...O})},void 0,!1,void 0,this),M==="Usage"&&r(be,{children:[r("p",{children:"Folders inherit these defaults. Folder settings and card lifecycle overrides remain unchanged. Unknown has no passive expiry."},void 0,!1,void 0,this),x.length===0&&r("p",{children:"No folders assigned."},void 0,!1,void 0,this),b&&(x.length>0?r("p",{children:["Cannot delete: assigned to ",x.map((O)=>O.path).join(", "),". Reassign or clear those folder categories first. Empty folders also count."]},void 0,!0,void 0,this):g===b.id?r("div",{role:"group","aria-label":"Confirm category deletion",children:[r("p",{children:["Delete ",b.name,"? This removes the category from this workspace."]},void 0,!0,void 0,this),r("button",{type:"button",disabled:C,onClick:()=>v(null),children:"Cancel deletion"},void 0,!1,void 0,this),r("button",{type:"button",class:"is-danger",disabled:C,onClick:async()=>{if(!Be.value||C)return;let O=tn;y(!0);let H=await pe("knowledgeRemove",`/api/canvas/knowledge/category/${encodeURIComponent(b.id)}`,null,{method:"DELETE"});if(await Kt(),y(!1),!Be.value||O!==tn)return;if(v(null),H?.ok===!0)h(null),w("null");_(H?.ok===!0?"Category deleted.":H?.error??"Category was not deleted. Retry.")},children:"Confirm deletion"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r("button",{type:"button",class:"is-danger",disabled:C,onClick:()=>v(b.id),children:"Delete category"},void 0,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("footer",{class:"category-editor-footer",children:[r("button",{type:"button",disabled:C||!!j,onClick:()=>V(t),children:"Cancel"},void 0,!1,void 0,this),r("button",{type:"submit",disabled:C||!!j,children:"Save category"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function nI({onClose:e}){let t=F(null),n=Jn.value?.relationPresets,[o,i]=E(),s=o===void 0?n?.[0]??null:o,[a,l]=E(null),[c,u]=E(null),[d,p]=E(null),[m,f]=E(""),[h,g]=E(!1),[v,b]=E(""),[x,C]=E(!1),y=F(null);G(()=>{if(!d)return;let L=document.activeElement;return y.current?.querySelector("button")?.focus(),()=>{if(L instanceof HTMLElement&&L.isConnected)L.focus()}},[d]);let k=s,_=a!==null&&JSON.stringify(a)!==JSON.stringify(c),A=(L)=>{if(h)return;if(_)p(()=>L);else L()},w=()=>{if(d)p(null);else if(x)C(!1);else A(e)};bn(t,!0,{onEscape:w});let M=(L)=>{i(L?structuredClone(L):null),l(null),u(null),C(!1),b("")},B=(L,Y)=>{if(a)l({...a,vocabulary:a.vocabulary.map((j,J)=>J===L?{...j,...Y}:j)})};return r("div",{class:"knowledge-backdrop",onKeyDown:(L)=>{if(L.key==="Escape")L.preventDefault(),L.stopPropagation(),w()},children:r("div",{ref:t,class:"knowledge-dialog is-category-editor relation-presets-dialog",role:"dialog","aria-modal":"true","aria-label":"Workspace relation presets",children:[r("header",{children:[r("h2",{children:"Workspace relation presets"},void 0,!1,void 0,this),r("button",{type:"button",disabled:h||!!d,"aria-label":"Close relation presets",onClick:()=>A(e),children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("p",{children:"Saved templates are shared across the workspace. Saving does not apply a preset to any board."},void 0,!1,void 0,this),v&&r("p",{role:"status",children:v},void 0,!1,void 0,this),d&&r("div",{ref:y,role:"alertdialog","aria-label":"Discard preset changes","aria-modal":"true",class:"relation-dirty-guard",children:[r("p",{children:"Discard unsaved preset changes?"},void 0,!1,void 0,this),r("button",{type:"button",onClick:()=>p(null),children:"Keep editing"},void 0,!1,void 0,this),r("button",{type:"button",onClick:()=>{let L=d;p(null),L()},children:"Discard changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{inert:d?!0:void 0,children:!n?r("p",{children:"Relation presets unavailable. Close and retry."},void 0,!1,void 0,this):r("div",{class:"category-editor-columns",children:[r("section",{children:[r("h3",{children:[n.length," presets"]},void 0,!0,void 0,this),r("button",{type:"button",disabled:h,onClick:()=>A(()=>{M(null);let L={id:crypto.randomUUID(),name:"",vocabulary:[]};u(structuredClone(L)),l(L)}),children:"Add preset"},void 0,!1,void 0,this),r("div",{class:"category-library",role:"group","aria-label":"Workspace relation presets",children:n.map((L)=>r("button",{type:"button",class:"category-choice",disabled:h,"aria-pressed":(a?.id??s?.id)===L.id,onClick:()=>A(()=>M(L)),children:[r("strong",{children:L.name},void 0,!1,void 0,this),r("span",{children:L.vocabulary.map((Y)=>Y.kind).join(" · ")||"No relation kinds"},void 0,!1,void 0,this)]},L.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("section",{class:"relation-preset-detail",children:a?r("form",{class:"relation-vocabulary",onClick:jo,onSubmit:async(L)=>{if(L.preventDefault(),h)return;if(new Set(a.vocabulary.map((j)=>j.kind.trim())).size!==a.vocabulary.length){b("Give each relation kind a unique name.");return}g(!0);let Y=await pe("relationPresetWrite","/api/canvas/knowledge/relation-preset",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({preset:a})});if(await Kt(),g(!1),Y?.ok)M(Y.preset);b(Y?.ok?"Preset saved for the workspace. Existing boards are unchanged.":"Preset was not saved. Retry.")},children:[r("h3",{children:s?"Customize shared preset":"New shared preset"},void 0,!1,void 0,this),r("label",{children:["Name",r("input",{required:!0,pattern:".*\\S.*",maxLength:80,disabled:h,value:a.name,onInput:(L)=>l({...a,name:L.currentTarget.value})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("p",{children:"Kinds stay open. Choose meaning ink and direction, not pin, agent or warning colours."},void 0,!1,void 0,this),a.vocabulary.map((L,Y)=>r("div",{class:"vocabulary-row",children:[r("input",{required:!0,pattern:".*\\S.*","aria-label":`Kind ${Y+1}`,maxLength:80,disabled:h,value:L.kind,onInput:(j)=>B(Y,{kind:j.currentTarget.value})},void 0,!1,void 0,this),r("select",{"aria-label":`Ink ${Y+1}`,disabled:h,value:L.ink,onChange:(j)=>B(Y,{ink:j.currentTarget.value}),children:["supports","contradicts","cites","derived","informs","related"].map((j)=>r("option",{children:j},j,!1,void 0,this))},void 0,!1,void 0,this),r("label",{children:[r("input",{type:"checkbox",disabled:h,checked:L.directed,onChange:(j)=>B(Y,{directed:j.currentTarget.checked})},void 0,!1,void 0,this),"Arrow"]},void 0,!0,void 0,this),r("button",{type:"button","aria-label":`Remove kind ${Y+1}`,disabled:h,onClick:()=>l({...a,vocabulary:a.vocabulary.filter((j,J)=>J!==Y)}),children:"×"},void 0,!1,void 0,this)]},Y,!0,void 0,this)),r("button",{type:"button",disabled:h||a.vocabulary.length>=64,onClick:()=>l({...a,vocabulary:[...a.vocabulary,{kind:"",ink:"related",directed:!0}]}),children:"Add kind"},void 0,!1,void 0,this),r("div",{class:"relation-preset-footer",children:[r("button",{type:"submit",disabled:h,children:"Save preset"},void 0,!1,void 0,this),r("button",{type:"button",disabled:h,onClick:()=>A(()=>M(s)),children:"Cancel customization"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):k?r(be,{children:[r("h3",{children:k.name},void 0,!1,void 0,this),r("p",{children:"Saved relations · read-only example"},void 0,!1,void 0,this),r("p",{children:"Use on board replaces only the chosen board’s vocabulary. Matching connections use its ink and direction; connection records are not rewritten."},void 0,!1,void 0,this),r("ul",{class:"relation-preset-preview","aria-label":"Saved relation preview",children:k.vocabulary.map((L)=>r("li",{style:{"--relation-ink":`var(--c-rel-${L.ink})`},children:[r("strong",{children:L.kind},void 0,!1,void 0,this),r("div",{class:"relation-preset-example",children:[r("span",{children:"Example A"},void 0,!1,void 0,this),r("svg",{viewBox:"0 0 120 24","aria-hidden":"true",children:[r("line",{x1:"8",y1:"12",x2:"112",y2:"12",stroke:"currentColor","stroke-width":"2","stroke-dasharray":L.ink==="related"?"3 5":void 0},void 0,!1,void 0,this),L.directed&&r("path",{d:"M 102 6 L 112 12 L 102 18",fill:"none",stroke:"currentColor","stroke-width":"2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{children:"Example B"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{children:[L.ink," · ",L.directed?"Directed: A → B":"Undirected: A — B"]},void 0,!0,void 0,this)]},L.kind,!0,void 0,this))},void 0,!1,void 0,this),!k.vocabulary.length&&r("p",{children:"No relation kinds. This empty preset can still be used on a board."},void 0,!1,void 0,this),r("div",{class:"relation-preset-footer",children:k&&r(be,{children:[r("label",{children:["Apply saved preset to board",r("select",{"aria-label":"Apply saved preset to board",disabled:h,value:m,onChange:(L)=>f(L.currentTarget.value),children:[r("option",{value:"",children:"Choose a board"},void 0,!1,void 0,this),Ge.value.map((L)=>r("option",{value:L.id,children:L.name},L.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",class:"relation-preset-use",disabled:h||!m,onClick:async()=>{if(h||!m)return;g(!0);let L=await Sr(m,{relationVocabulary:k.vocabulary});g(!1),b(L?"Preset applied. Connection records and other boards are unchanged.":"Preset was not applied. Retry.")},children:"Use on board"},void 0,!1,void 0,this),r("button",{type:"button",disabled:h,onClick:()=>{u(structuredClone(k)),l(structuredClone(k)),C(!1),b("")},children:"Customize preset"},void 0,!1,void 0,this),x?r("div",{role:"group","aria-label":"Confirm preset deletion",children:[r("p",{children:["Delete ",k.name,"? Boards that used it keep their existing vocabulary."]},void 0,!0,void 0,this),r("button",{type:"button",disabled:h,onClick:()=>C(!1),children:"Cancel deletion"},void 0,!1,void 0,this),r("button",{type:"button",class:"is-danger",disabled:h,onClick:async()=>{if(h)return;g(!0);let L=await pe("relationPresetRemove",`/api/canvas/knowledge/relation-preset/${encodeURIComponent(k.id)}`,null,{method:"DELETE"});if(await Kt(),g(!1),C(!1),L?.ok)M(null);b(L?.ok?"Preset deleted. Existing boards are unchanged.":"Preset was not deleted. Retry.")},children:"Confirm deletion"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r("button",{type:"button",class:"is-danger",disabled:h,onClick:()=>C(!0),children:"Delete preset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r("p",{children:"Choose a saved preset or add a new one."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function oI(e){if(!e)return"never opened";if((Date.now()-new Date(e).getTime())/86400000>=30)return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});return cp(e)}var cr=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function rI(e){return(e.links?.length??0)+(e.backlinks?.length??0)}async function Dg(e){let t=await On("New board","Board name",{confirm:"Create"});if(t)await nS(t,e)}var iI="pmx-canvas-home-collapsed";function QL(){try{let e=localStorage.getItem(iI);if(e)return new Set(JSON.parse(e))}catch{}return new Set([$T])}function eO(e){try{localStorage.setItem(iI,JSON.stringify([...e]))}catch{}}var gc=(e,t)=>e.folder===t||!!e.folder?.startsWith(`${t}/`),ur=(e)=>e.split("/").at(-1)??e;function tO({board:e}){return r("div",{class:"home-thumb","aria-hidden":"true",children:r("div",{class:"home-thumb-inner",children:(e.preview??[]).map((t,n)=>r("span",{class:`home-thumb-card${t.pinned?" is-pinned":""}`,style:{left:`${t.x*100}%`,top:`${t.y*100}%`,width:`${t.w*100}%`,height:`${t.h*100}%`}},n,!1,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function sI(){let e=Ge.value,t=Be.value,[n,o]=E("Folders"),i=!t&&n==="Review"?"Folders":n,[s,a]=E(()=>[...Ge.value].sort((Ie,S)=>(S.lastOpenedAt??"").localeCompare(Ie.lastOpenedAt??""))[0]?.folder??""),[l,c]=E([]),[u,d]=E(null),[p,m]=E(!1),[f,h]=E(null),[g,v]=E(!1),[b,x]=E(!1),[C,y]=E(null),[k,_]=E(null),[A,w]=E(""),[M,B]=E([]),[L,Y]=E(QL),[j,J]=E(!1),[X,V]=E(!1),ee=F(null),he=F(null),R=[...new Set([...e.flatMap((U)=>U.folder?fc(U.folder):[]),...(Jn.value?.folders??[]).flatMap((U)=>fc(U.path)),...l.flatMap(fc)])].sort((U,Ie)=>U.localeCompare(Ie)),te=(U)=>R.filter((Ie)=>U?Ie.startsWith(`${U}/`)&&!Ie.slice(U.length+1).includes("/"):!Ie.includes("/")),O=A.trim().toLocaleLowerCase(),H=e.filter((U)=>U.pin),Me=H.reduce((U,Ie)=>U+(Ie.mapChars??0),0),je=te(s),He=e.filter((U)=>(U.folder??"")===s).sort((U,Ie)=>(Ie.lastOpenedAt??"").localeCompare(U.lastOpenedAt??"")),Re=O?e.filter((U)=>`${U.name} ${U.folder??""}`.toLocaleLowerCase().includes(O)):[],ve=e.find((U)=>U.id===f)??null,D=e.find((U)=>U.id===C),re=e.find((U)=>U.id===k),ze=new Set(e.filter((U)=>!s||gc(U,s)).map((U)=>U.id)),ke=Object.entries(Jn.value?.cards??{}).filter(([U])=>ze.has(JSON.parse(U)[0])).map(([,U])=>U),ae=ke.filter((U)=>!U.retired&&(U.due||U.sources.length)).length,Se=ke.filter((U)=>U.unknown).length,de=Jn.value?.resolvedFolders[s]?.category,Ze=new Map;for(let[U,Ie]of Object.entries(Jn.value?.cards??{})){if(Ie.retired||!(Ie.due||Ie.sources.length))continue;let[S,K]=JSON.parse(U),ue=Ze.get(S)??[];ue.push(K),Ze.set(S,ue)}let xe=O?Re:He,Ke=async(U)=>{if(!Be.value)return;let Ie=tn,S=Ze.get(U)?.[0];if(!S)return;if(await zt({boardId:U,cardId:S})&&Be.value&&Ie===tn&&ie.value===U)No.value="To review"};G(()=>{let U=A.trim();if(!U){B([]);return}let Ie=!1,S=window.setTimeout(()=>{pe("searchLibrary",`/api/canvas/search?q=${encodeURIComponent(U)}&scope=library&limit=30`,null).then((K)=>{if(!Ie)B(K?.results??[])})},150);return()=>{Ie=!0,window.clearTimeout(S)}},[A]),G(()=>{if(g)he.current?.querySelector('[role="menuitem"]')?.focus()},[g]),G(()=>{if(f&&!e.some((U)=>U.id===f))h(null)},[e,f]),$e(()=>{if(i!=="Folders"||!f)return;let U=(Ie)=>{if(!ar(Ie))return;Ie.preventDefault(),h(null),x(!1)};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[i,f]);let q=(U)=>zt(U),ye=(U)=>{let Ie=new Set(L);if(Ie.has(U))Ie.delete(U);else Ie.add(U);Y(Ie),eO(Ie)},Ue=(U)=>{a(U),w(""),h(null),J(!1)},N=(U)=>{h(U),v(!1),x(!1)},ne=async()=>{let U=await On("New folder","Folder name",{confirm:"Create"});if(!U)return;let Ie;try{Ie=hp(s?`${s}/${U}`:U)}catch{return}if(!Ie)return;c((S)=>[...S,Ie]),Ue(Ie)},Ce=async(U)=>{let Ie=await On("Rename board","Board name",{initial:U.name,confirm:"Rename"});if(Ie&&Ie!==U.name)await Sr(U.id,{name:Ie})},Te=(U,Ie)=>{let S=te(U),K=!L.has(U),ue=e.filter((We)=>gc(We,U)).length,Oe=e.some((We)=>We.pin&&gc(We,U));return r("li",{children:[r("div",{class:`home-tree-row${s===U&&!O?" is-selected":""}`,"data-folder":U,children:[r("span",{class:"home-tree-indent",style:{width:`${Ie*16}px`}},void 0,!1,void 0,this),S.length>0?r("button",{type:"button",class:"home-tree-chevron","aria-label":K?`Fold ${ur(U)}`:`Unfold ${ur(U)}`,"aria-expanded":K,onClick:()=>ye(U),children:K?r(oa,{},void 0,!1,void 0,this):r(di,{},void 0,!1,void 0,this)},void 0,!1,void 0,this):r("span",{class:"home-tree-chevron"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-tree-name",onClick:()=>Ue(U),children:ur(U)},void 0,!1,void 0,this),Oe&&r("span",{class:"home-tree-pin","aria-label":"Has a board in the agent's context"},void 0,!1,void 0,this),r("span",{class:"home-tree-count",children:ue},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K&&S.length>0&&r("ul",{class:"home-tree",children:S.map((We)=>Te(We,Ie+1))},void 0,!1,void 0,this)]},U,!0,void 0,this)},me=r("ul",{class:"home-tree","aria-label":"Folders",children:[te("").map((U)=>Te(U,0)),r("li",{children:r("div",{class:`home-tree-row is-unfiled${s===""&&!O?" is-selected":""}`,children:[r("span",{class:"home-tree-chevron"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-tree-name",onClick:()=>Ue(""),children:"Unfiled"},void 0,!1,void 0,this),r("span",{class:"home-tree-count",children:e.filter((U)=>!U.folder).length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),at=r("ul",{class:"home-pinned","aria-label":"Pinned boards",children:H.map((U)=>r("li",{children:r("button",{type:"button",class:"home-pinned-row",onClick:()=>Ue(U.folder??""),children:[r("span",{class:"home-pin-dot","aria-hidden":"true",children:r(mo,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"home-pinned-name",children:U.name},void 0,!1,void 0,this),r("span",{class:"home-tree-count",children:U.folder?ur(U.folder):"Unfiled"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},U.id,!1,void 0,this))},void 0,!1,void 0,this),Ft=r("label",{class:"home-search",children:[r(ld,{},void 0,!1,void 0,this),r("span",{class:"sr-only",children:"Find boards, cards and folders"},void 0,!1,void 0,this),r("input",{type:"search",placeholder:"Boards, cards, folders…",value:A,onInput:(U)=>w(U.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Qe=(U)=>r("li",{children:r("article",{class:`home-card${U.pin?" is-pinned":""}${f===U.id?" is-selected":""}`,"data-testid":"home-board","data-board-id":U.id,children:[r("button",{type:"button",class:"home-card-select","aria-label":U.name,"aria-pressed":f===U.id,onClick:()=>N(U.id),onDblClick:()=>void Mn(U.id),children:[r(tO,{board:U},void 0,!1,void 0,this),r("span",{class:"home-card-body",children:[r("span",{class:"home-card-name",children:U.name},void 0,!1,void 0,this),r("span",{class:"home-card-readme",children:U.summary??"No README yet."},void 0,!1,void 0,this),r("span",{class:"home-card-meta",children:[r("span",{children:cr(U.nodeCount,"card")},void 0,!1,void 0,this),rI(U)>0&&r("span",{children:["↔ ",cr(rI(U),"link")]},void 0,!0,void 0,this),r("span",{class:"home-card-when",children:oI(U.lastOpenedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),t&&Ze.has(U.id)&&r("button",{type:"button",class:"home-card-review","aria-label":`Review ${U.name}`,onClick:()=>void Ke(U.id),children:["⧗ Review ",cr(Ze.get(U.id).length,"card")]},void 0,!0,void 0,this),r(go,{board:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},U.id,!1,void 0,this),Lt=ve&&r("aside",{class:"home-details","aria-label":"Board details","data-testid":"home-details",children:[r("button",{type:"button",class:"home-details-grip","aria-label":"Close details",onClick:()=>N(null)},void 0,!1,void 0,this),r("div",{class:"home-details-head",children:[r("span",{class:"home-details-folder",children:ve.folder?ur(ve.folder):"Unfiled"},void 0,!1,void 0,this),r("span",{class:"home-details-name",children:ve.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:`home-details-context${ve.pin?" is-on":""}`,children:[r("span",{class:"home-details-context-text",children:r("span",{class:"home-details-context-label",children:ve.pin?"In the agent's context":"Not in the agent's context"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("button",{type:"button",role:"switch","aria-checked":!!ve.pin,"aria-label":"In the agent's context",class:"home-switch",onClick:()=>void Vs(ve.id,!ve.pin),children:r("span",{class:"home-switch-knob"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b?r("div",{class:"home-details-confirm",role:"alert",children:[r("span",{children:["Delete ",r("strong",{children:ve.name},void 0,!1,void 0,this)," and its ",cr(ve.nodeCount,"card")," and snapshots? This can't be undone."]},void 0,!0,void 0,this),r("span",{class:"home-details-actions",children:[r("button",{type:"button",class:"home-button",onClick:()=>x(!1),children:"Cancel"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button is-danger",onClick:()=>{x(!1),sS(ve.id)},children:"Delete board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):r("div",{class:"home-details-actions",children:[r("button",{type:"button",class:"home-button is-primary",onClick:()=>void Mn(ve.id),children:"Open board"},void 0,!1,void 0,this),t&&Ze.has(ve.id)&&r("button",{type:"button",class:"home-button",onClick:()=>void Ke(ve.id),children:"Review cards"},void 0,!1,void 0,this),r("span",{class:"home-more",children:[r("button",{ref:ee,type:"button",class:"home-button is-icon","aria-label":"More: move, rename, create from, delete","aria-haspopup":"menu","aria-expanded":g,onClick:()=>v(!g),children:r(Ol,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),g&&r("span",{ref:he,class:"home-more-menu",role:"menu",onKeyDown:(U)=>{let Ie=[...he.current?.querySelectorAll('[role="menuitem"]')??[]],S=Ie.indexOf(document.activeElement);if(U.key==="Escape")U.preventDefault(),v(!1),ee.current?.focus();else if(U.key==="ArrowDown"||U.key==="ArrowUp"){U.preventDefault();let K=U.key==="ArrowDown"?1:-1;Ie[(S+K+Ie.length)%Ie.length]?.focus()}},children:[["Move…",()=>y(ve.id)],["Rename…",()=>void Ce(ve)],["Create from…",()=>_(ve.id)],["Delete…",()=>x(!0)]].map(([U,Ie])=>r("button",{type:"button",role:"menuitem",class:"home-more-item",onClick:()=>{v(!1),Ie()},children:U},U,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return r("div",{class:"home-shell",children:[u!==null&&r(tI,{folder:u||void 0,onClose:()=>d(null)},u,!1,void 0,this),p&&r(nI,{onClose:()=>m(!1)},void 0,!1,void 0,this),r("nav",{class:"home-view-tabs","aria-label":"Library view",children:[["Folders","Map","Graph","Review"].filter((U)=>t||U!=="Review").map((U)=>r("button",{type:"button",class:"home-button","aria-pressed":i===U,onClick:()=>o(U),children:U},U,!1,void 0,this)),r("button",{type:"button",class:"home-button",onClick:()=>m(!0),children:"Relation presets"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i==="Map"||i==="Graph"?i==="Map"?r(HT,{},void 0,!1,void 0,this):r(KT,{},void 0,!1,void 0,this):r("div",{class:`home-view${ve&&i==="Folders"?" has-details":""}`,"data-testid":"home-view",children:[r("aside",{class:`home-library${j?" is-open":""}`,"aria-label":"Library",children:[r("div",{class:"home-library-head",children:[r("span",{class:"home-library-title",children:"Library"},void 0,!1,void 0,this),r("span",{class:"home-tree-count",children:cr(e.length,"board")},void 0,!1,void 0,this),t&&r("button",{type:"button",class:"home-button",onClick:()=>{if(Be.value)d("")},children:"Categories"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ft,H.length>0&&r("section",{class:"home-library-section",children:[r("span",{class:"home-section-label",children:"Pinned boards"},void 0,!1,void 0,this),at,r("span",{class:"home-pinned-cost",children:["≈ ",uc(Me)," tokens · ",cr(H.length,"board")]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("section",{class:"home-library-section is-folders",children:[r("span",{class:"home-section-label",children:"Folders"},void 0,!1,void 0,this),me,r("button",{type:"button",class:"home-tree-new",onClick:()=>void ne(),children:"+ New folder"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("main",{class:"home-main",children:[r("div",{class:"home-narrow",children:[Ft,H.length>0&&r(be,{children:[r("button",{type:"button",class:"home-narrow-context","aria-expanded":X,onClick:()=>V(!X),children:[r("span",{class:"home-pin-dot","aria-hidden":"true",children:r(mo,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"home-narrow-context-label",children:["In context: ",cr(H.length,"board")]},void 0,!0,void 0,this),r("span",{class:"home-narrow-context-cost",children:["≈ ",uc(Me)," tokens"]},void 0,!0,void 0,this),r("span",{children:X?"Hide ▴":"Show ▾"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&at]},void 0,!0,void 0,this),r("button",{type:"button",class:"home-narrow-picker","aria-expanded":j,onClick:()=>J(!j),children:[s?ur(s):"Library",r("span",{class:"home-tree-count",children:["· ",s?e.filter((U)=>gc(U,s)).length:He.length," ▾"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i==="Review"?r(VT,{folder:s,folders:R,onScopeChange:Ue},void 0,!1,void 0,this):r(be,{children:[r("div",{class:"home-main-head",children:[r("div",{class:"home-main-title",children:[r("nav",{class:"home-crumbs","aria-label":"Folder path",children:[r("button",{type:"button",onClick:()=>Ue(""),children:"Library"},void 0,!1,void 0,this),s&&fc(s).map((U)=>r("span",{children:[r("span",{class:"home-crumb-sep",children:"/"},void 0,!1,void 0,this),r("button",{type:"button",onClick:()=>Ue(U),children:ur(U)},void 0,!1,void 0,this)]},U,!0,void 0,this))]},void 0,!0,void 0,this),r("h1",{class:"home-view-title",children:O?`Results for “${A.trim()}”`:s?ur(s):"Library"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&r("button",{type:"button",class:"home-button",onClick:()=>{if(Be.value)d(s)},children:[" ",s?"Folder settings":"Categories"]},void 0,!0,void 0,this),r("button",{type:"button",class:"home-button is-primary",onClick:()=>void Dg(s||null),children:s?"New board here":"New board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&Jn.value&&!O&&r("section",{class:"home-main-section","aria-label":"Folder review summary",children:[r("span",{class:"home-section-label",children:["Card review · ",s?"In this folder and subfolders":"Across the library"]},void 0,!0,void 0,this),r("div",{class:"home-card-meta",children:[de&&r("span",{children:["Category: ",de.glyph," ",de.name]},void 0,!0,void 0,this),r("button",{type:"button",class:`home-review-link${ae?" has-review":""}`,onClick:()=>{o("Review"),h(null)},children:["Review needed: ",cr(ae,"card")]},void 0,!0,void 0,this),r("span",{children:["No review policy: ",cr(Se,"card")]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),e.length===0?r("div",{class:"home-view-empty",children:"No boards yet. Create one, or let an agent start writing — it opens one."},void 0,!1,void 0,this):O?r(be,{children:[M.length>0&&r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:["Cards · ",M.length]},void 0,!0,void 0,this),r("ul",{class:"home-hits","aria-label":"Library search results",children:M.map((U)=>r("li",{children:r("button",{type:"button",class:"home-hit",onClick:()=>void q(U),children:[r("span",{class:"home-card-name",children:U.title||U.boardTitle},void 0,!1,void 0,this),t&&U.qualification?.retired&&r("span",{class:"category-tag",children:"Retired"},void 0,!1,void 0,this),r("span",{class:"home-card-meta",children:[U.boardTitle," · ",U.snippet]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},`${U.boardId}:${U.cardId}`,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Re.length>0?r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:["Boards · ",Re.length]},void 0,!0,void 0,this),r("ul",{class:"home-cards",children:Re.map(Qe)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):M.length===0&&r("div",{class:"home-view-empty",role:"status",children:["No boards match “",A.trim(),"”."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):r(be,{children:[je.length>0&&r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:["Folders · ",je.length]},void 0,!0,void 0,this),r("ul",{class:"home-folders",children:je.map((U)=>{let Ie=e.filter((ue)=>gc(ue,U)),S=Ie.map((ue)=>ue.lastOpenedAt??"").sort().at(-1),K=Ie.filter((ue)=>ue.pin).length;return r("li",{children:r("button",{type:"button",class:"home-folder","data-testid":"home-section","data-folder":U,onClick:()=>Ue(U),children:[r("span",{class:"home-folder-stack","aria-hidden":"true",children:[r("span",{},void 0,!1,void 0,this),r("span",{},void 0,!1,void 0,this),r("span",{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K>0&&r("span",{class:"home-folder-context",children:[K," in context"]},void 0,!0,void 0,this),r("span",{class:"home-folder-name",children:ur(U)},void 0,!1,void 0,this),r("span",{class:"home-folder-meta",children:[cr(Ie.length,"board"),S?` · opened ${oI(S)}`:""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},U,!1,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:[s?`Boards in ${ur(s)}`:"Unfiled boards"," · ",xe.length]},void 0,!0,void 0,this),xe.length>0?r("ul",{class:"home-cards","aria-label":s?`Boards in ${s}`:"Unfiled boards",children:xe.map(Qe)},void 0,!1,void 0,this):r("div",{class:"home-view-empty",children:"No boards here yet."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i==="Folders"&&Lt,D&&r(LT,{board:D,folders:R,onClose:()=>y(null)},D.id,!1,void 0,this),re&&r(OT,{board:re,onClose:()=>_(null)},re.id,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var fs=se(!1);function nO(e){return e>=1048576?`${(e/1024/1024).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}function aI(){let[e,t]=E(!1),[n,o]=E(!1),[i,s]=E(null),[a,l]=E(null),[c,u]=E(!1),[d,p]=E(""),m=fs.value,f=ie.value;if(G(()=>{if(!m||!f)return;let g=!0;return l(null),p(""),s(null),pe("exportPreview",`/api/canvas/export/preview?board=${encodeURIComponent(f)}&includeFiles=${e}&includeDerivedText=${n}`,null).then((v)=>{if(g)s(v?.manifest??null)}),()=>{g=!1}},[m,e,n,f]),G(()=>{o(!1)},[m,f]),G(()=>{if(!m)return;let g=(v)=>{if(v.key!=="Escape")return;v.stopPropagation(),fs.value=!1};return window.addEventListener("keydown",g,{capture:!0}),()=>window.removeEventListener("keydown",g,{capture:!0})},[m]),!m)return null;let h=async()=>{if(!i||i.boardId!==ie.value)return;u(!0);let g=await pe("exportBoard","/api/canvas/export",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({board:i.boardId,includeFiles:e,includeDerivedText:n})});if(u(!1),g?.path&&ie.value===i.boardId)l(g)};return r("div",{class:"text-prompt-backdrop",onPointerDown:()=>fs.value=!1,children:r("div",{class:"text-prompt export-dialog",role:"dialog","aria-label":"Export board","data-testid":"export-dialog",onPointerDown:(g)=>g.stopPropagation(),children:[r("div",{class:"text-prompt-title",children:["Export ",i?`“${i.boardName}”`:"board"]},void 0,!0,void 0,this),!i?r("div",{class:"export-dialog-note",children:"Reading the board…"},void 0,!1,void 0,this):r(be,{children:[r("div",{class:"export-dialog-note",children:"One HTML file anyone can open without installing anything. It will contain:"},void 0,!1,void 0,this),r("ul",{class:"export-dialog-list",children:[r("li",{children:[i.cards," card",i.cards!==1?"s":""," and ",i.connections," connection",i.connections!==1?"s":""]},void 0,!0,void 0,this),i.frames>0&&r("li",{children:[i.frames," embedded pages, charts or diagrams, with the code that draws them"]},void 0,!0,void 0,this),i.embeddedImages>0&&r("li",{children:[i.embeddedImages," local images"]},void 0,!0,void 0,this),i.placeholders.length>0&&r("li",{children:["Shown as placeholders:"," ",i.placeholders.map((g)=>`${g.title} (${g.reason})`).join(", ")]},void 0,!0,void 0,this),i.remoteImages.length>0&&r("li",{children:["Web images loaded when opened: ",i.remoteImages.join(", ")]},void 0,!0,void 0,this),i.links.length>0&&r("li",{children:["Links included in cards: ",i.links.join(", ")]},void 0,!0,void 0,this),i.frameNetworkDestinations.length>0&&r("li",{children:["Network destinations referenced by embedded pages: ",i.frameNetworkDestinations.join(", ")]},void 0,!0,void 0,this),i.embeddedCodeCanAccessNetwork&&r("li",{children:"Warning: embedded code can access the network. Scripts may contact destinations that cannot be listed in advance."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(i.attachments?.length??0)>0&&r("p",{children:"Original attachments are excluded. Their filenames remain visible."},void 0,!1,void 0,this),(i.sourceDerivedCards?.length??0)>0&&r("label",{class:"export-dialog-files",children:[r("input",{type:"checkbox",checked:n,onChange:(g)=>o(g.currentTarget.checked)},void 0,!1,void 0,this),r("span",{children:["Include imported document text (",i.sourceDerivedCards.length," cards)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i.files.length>0&&r("label",{class:"export-dialog-files",children:[r("input",{type:"checkbox",checked:e,onChange:(g)=>t(g.target.checked)},void 0,!1,void 0,this),r("span",{children:["Include the contents of ",i.files.length," local file",i.files.length!==1?"s":"",": ",i.files.map((g)=>g.path).join(", ")]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a&&r("div",{class:"export-dialog-result","data-testid":"export-result",children:[r("div",{children:["Saved (",nO(a.bytes),"): ",r("code",{children:a.path},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"export-dialog-links",children:nt()?r("button",{type:"button",disabled:c,onClick:async()=>{u(!0),p("");try{await wk(a.url)}catch(g){p(g instanceof Error?g.message:"Download failed. Try again.")}finally{u(!1)}},children:c?"Downloading…":"Download"},void 0,!1,void 0,this):r(be,{children:[r("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",children:"Open"},void 0,!1,void 0,this),r("a",{class:"is-primary",href:`${a.url}?download=1`,children:"Download"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),nt()&&r("p",{children:"Download the HTML file to open it outside ChatGPT."},void 0,!1,void 0,this),d&&r("p",{role:"alert",children:d},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"text-prompt-actions",children:[r("button",{type:"button",class:"text-prompt-cancel",onClick:()=>fs.value=!1,children:a?"Done":"Cancel"},void 0,!1,void 0,this),!a&&r("button",{type:"button",class:"text-prompt-confirm",disabled:!i||c,onClick:()=>void h(),children:c?"Exporting…":"Export"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Bg({presence:e,size:t=18}){return r("span",{class:"writer-avatar",style:{background:_o(e.sessionId),width:`${t}px`,height:`${t}px`},"aria-hidden":"true",children:Ud(e.label)},void 0,!1,void 0,this)}function lI(){let e=Wd.value;if(or.value||e.length===0)return null;let t=e.reduce((i,s)=>i+s.opCount,0),n=e.length===1?e[0].label:`${e.length} writers`,o=ss.value;return r(_e,{label:`${e.length} external writer${e.length===1?"":"s"} on this board`,body:"Click for their activity.",align:"end",children:r("button",{type:"button",class:"external-indicator","data-testid":"external-indicator","aria-label":`${n} external activity, ${t} operation${t===1?"":"s"}`,"aria-expanded":o,onClick:()=>{ss.value=!o},children:[r("span",{class:"external-indicator-avatars",children:e.slice(0,3).map((i)=>r(Bg,{presence:i},i.sessionId,!1,void 0,this))},void 0,!1,void 0,this),r("span",{class:"external-indicator-label",children:n},void 0,!1,void 0,this),r("span",{class:"external-indicator-ops hud-collapsible-text",children:[t," op",t===1?"":"s"]},void 0,!0,void 0,this),r("span",{class:"external-indicator-dot","aria-hidden":"true"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function oO(e){if(e==="node.add"||e==="jsonrender.add"||e==="graph.add"||e==="group.create")return{glyph:"+",tone:"ok"};if(e==="node.remove"||e==="edge.remove"||e==="canvas.clear")return{glyph:"×",tone:"danger"};if(e==="edge.add")return{glyph:"⟶",tone:"accent"};if(e.startsWith("ax."))return{glyph:"◆",tone:"purple"};return{glyph:"✎",tone:"accent"}}function rO(e){return e.reduce((t,n)=>n.lastSeenAt>t?n.lastSeenAt:t,"")}function iO(){return[...qt.value.values()].filter((e)=>!e.auto&&e.phase==="forming")}function cI(){let e=ss.value,t=Wd.value,n=rr(e?1e4:0);if($e(()=>{if(!e)return;let l=(c)=>{if(c.key!=="Escape"||c.defaultPrevented)return;if(c.preventDefault(),ka.value)ka.value=!1;else ss.value=!1};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e]),!e||or.value||t.length===0)return null;let o=sg.value,i=iO().filter((l)=>!o||(l.source??"")===o),s=bi.value.filter((l)=>!o||l.sessionId===o),a=(l,c)=>r("button",{type:"button",class:`activity-filter${o===l?" is-active":""}`,style:l?{"--writer":_o(l)}:void 0,"aria-pressed":o===l,onClick:()=>{sg.value=l},children:c},void 0,!1,void 0,this);return r("div",{class:"activity-feed","data-testid":"activity-feed",role:"dialog","aria-label":"External activity",children:[r("div",{class:"activity-feed-head",children:[r("span",{class:"external-indicator-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("div",{class:"activity-feed-titles",children:[r("div",{class:"activity-feed-title",children:["External activity — ",t.length," writer",t.length===1?"":"s"]},void 0,!0,void 0,this),r("div",{class:"activity-feed-sub",children:[t.reduce((l,c)=>l+c.opCount,0)," writes · last"," ",Zd(rO(t),n)," · live writers"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",class:"activity-feed-close","aria-label":"Close activity feed",onClick:()=>{ss.value=!1},children:r(Tt,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"activity-filters",children:[a(null,"All"),t.map((l)=>a(l.sessionId,l.label))]},void 0,!0,void 0,this),r("div",{class:"activity-rows",children:[i.map((l)=>r("div",{class:"activity-row is-pending","data-testid":"activity-proposal",children:[r("span",{class:"activity-glyph tone-purple","aria-hidden":"true",children:"▢"},void 0,!1,void 0,this),r("div",{class:"activity-main",children:[r("div",{class:"activity-text",children:["Proposing: ",r("b",{children:l.label?.trim()||`${l.kind} intent`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"activity-meta",children:[l.reason?.trim()||"Intent signalled — a real veto window before the mutation",l.source?` · ${l.source}`:""]},void 0,!0,void 0,this),r("div",{class:"activity-actions",children:[r("button",{type:"button",class:"activity-veto",onClick:()=>{ji(l).then((c)=>{if(c)Hi(l.id)})},children:"Veto"},void 0,!1,void 0,this),r("span",{class:"activity-hint",children:"or hover ghost + Esc"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"activity-age",children:"now"},void 0,!1,void 0,this)]},l.id,!0,void 0,this)),s.length===0&&i.length===0&&r("div",{class:"activity-empty",children:"No writes yet."},void 0,!1,void 0,this),s.map((l)=>{let{glyph:c,tone:u}=oO(l.op);return r("div",{class:"activity-row","data-testid":"activity-row","data-op":l.op,children:[r("span",{class:`activity-glyph tone-${u}`,"aria-hidden":"true",children:c},void 0,!1,void 0,this),r("div",{class:"activity-main",children:[r("div",{class:"activity-text",children:l.summary},void 0,!1,void 0,this),r("div",{class:"activity-writer",style:{color:_o(l.sessionId)},children:l.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"activity-age",children:Zd(l.at,n)},void 0,!1,void 0,this)]},l.id,!0,void 0,this)})]},void 0,!0,void 0,this),r("div",{class:"activity-feed-foot",children:[r("span",{class:"activity-feed-note",children:"All writes ghost first · Esc vetoes"},void 0,!1,void 0,this),r("button",{type:"button",class:"activity-feed-link",onClick:()=>{ka.value=!0},children:"Writers"},void 0,!1,void 0,this),kt.value&&r("button",{type:"button",class:"activity-feed-link is-accent",onClick:()=>{ss.value=!1,_i()},children:["Start session ",r(pi,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function sO(){let e=[];if(Io.value)e.push("scoped");if(To.value.length>0)e.push("gated");return e.length>0?e.join(" + "):"open"}function uI(){let e=ka.value,t=rr(e?1e4:0),n=F(null);if(bn(n,e),!e)return null;let o=kt.value?en.value.filter((a)=>a.attached):[],i=Wd.value,s=()=>{ka.value=!1};return r(be,{children:[r("div",{class:"writers-scrim",onClick:s,"aria-hidden":"true"},void 0,!1,void 0,this),r("div",{ref:n,class:"writers-sheet","data-testid":"writers-sheet",role:"dialog","aria-modal":"true","aria-label":"Connected writers",children:[r("div",{class:"writers-head",children:[r("span",{class:"writers-title",children:"Connected writers"},void 0,!1,void 0,this),r("span",{class:"writers-board",children:Cr.value.slice(0,12)},void 0,!1,void 0,this),r("button",{type:"button",class:"activity-feed-close","aria-label":"Close writers",onClick:s,children:r(Tt,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"writers-body",children:[kt.value&&r(be,{children:[r("div",{class:"writers-section",children:"Agent sessions"},void 0,!1,void 0,this),o.length===0&&r("div",{class:"writers-empty",children:"None attached — start one from the top bar."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o.map((a)=>r("div",{class:"writers-row",children:[r(Bg,{presence:a,size:20},void 0,!1,void 0,this),r("span",{class:"writers-name",children:a.label},void 0,!1,void 0,this),r("span",{class:"writers-config",children:sO()},void 0,!1,void 0,this)]},a.sessionId,!0,void 0,this)),r("div",{class:"writers-section",children:kt.value?"External writers · MCP":"Live writers"},void 0,!1,void 0,this),i.length===0&&r("div",{class:"writers-empty",children:"No external writers right now."},void 0,!1,void 0,this),i.map((a)=>r("div",{class:"writers-row",children:[r(Bg,{presence:a,size:20},void 0,!1,void 0,this),r("span",{class:"writers-name is-mono",children:a.label},void 0,!1,void 0,this),r("span",{class:"writers-meta",children:[a.source!==a.label?`${a.source} · `:"","wrote"," ",Zd(a.lastSeenAt,t)," ago"]},void 0,!0,void 0,this)]},a.sessionId,!0,void 0,this))]},void 0,!0,void 0,this),r("div",{class:"writers-foot",children:[r("span",{class:"writers-note",children:"Local-first: any process on this machine can connect and write. Every write ghosts first — veto is the control, not permissions."},void 0,!1,void 0,this),r("button",{type:"button",class:"writers-done",onClick:s,children:"Done"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function dI({nodeId:e}){let t=ie.value,[n,o]=E(null),[i,s]=E(!1),a=tt.value,l=Z.value,c=Ge.value;G(()=>{let f=!1;if(o(null),s(!1),t)pe("relations",`/api/canvas/memory-graph?focus=${encodeURIComponent(Mt({boardId:t,cardId:e}))}&depth=1`,null).then((h)=>{if(!f)o(h),s(!h)});return()=>{f=!0}},[t,e,a,l,c]);let u=t?Mt({boardId:t,cardId:e}):"",d=n?.edges.filter((f)=>f.kind!=="member"&&(f.from===u||f.to===u))??[],p=(f)=>{let h=f.to===u;if(h&&f.relationKind==="supports")return"Evidence for";if(h&&f.relationKind==="contradicts")return"Evidence against";let g=Qd({kind:f.relationKind,type:f.type});if(g)return(g==="from"?!h:h)?"Used by":"Sources";if(f.relationKind==="cites"||f.type==="references")return h?"Used by":"Sources";if(!h&&f.relationKind==="supports")return"Used by";return"Connections"},m=["Evidence for","Evidence against","Sources","Used by","Connections"];return d.sort((f,h)=>m.indexOf(p(f))-m.indexOf(p(h))),r("aside",{class:"relations-panel","aria-label":"Relations",children:[r("h3",{children:"Relations"},void 0,!1,void 0,this),!n&&r("p",{role:"status",children:i?"Relations unavailable. Reopen to retry.":"Loading relations…"},void 0,!1,void 0,this),n&&d.length===0&&r("p",{children:"No connections yet."},void 0,!1,void 0,this),d.map((f,h)=>{let g=f.from===u,v=g?f.target:f.source,b=n?.nodes.find((y)=>y.key===Mt(v)),x=c.find((y)=>y.id===f.source.boardId),C=ho({kind:f.relationKind,type:f.type},x?.relationVocabulary);return r("div",{class:"relation-row",children:[(h===0||p(d[h-1])!==p(f))&&r("h4",{children:p(f)},void 0,!1,void 0,this),r("span",{class:"relation-kind",style:{color:`var(--c-rel-${C.ink})`},children:[g?"→":"←"," ",f.relationKind??f.type??f.kind]},void 0,!0,void 0,this),f.missing?r("span",{children:"Missing target"},void 0,!1,void 0,this):r("button",{type:"button",class:"relation-target",onClick:()=>void zt(v),children:b?.title??v.boardId},void 0,!1,void 0,this),f.label&&r("span",{children:f.label},void 0,!1,void 0,this),r("p",{children:f.reason??"No reason recorded."},void 0,!1,void 0,this)]},f.id,!0,void 0,this)}),r("p",{children:"Manage shared relation presets in Home."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function pI(e,t){switch(e.type){case"markdown":return r(Ed,{node:e,expanded:t},void 0,!1,void 0,this);case"mcp-app":return r(yi,{node:e,expanded:t},void 0,!1,void 0,this);case"webpage":return r(Bd,{node:e,expanded:t},void 0,!1,void 0,this);case"json-render":return r(yi,{node:e,expanded:t},void 0,!1,void 0,this);case"graph":return r(yi,{node:e,expanded:t},void 0,!1,void 0,this);case"board":return r(rp,{node:e},void 0,!1,void 0,this);case"prompt":return r(Hd,{node:e},void 0,!1,void 0,this);case"response":return r(Fd,{node:e,expanded:t},void 0,!1,void 0,this);case"status":return r(Od,{node:e},void 0,!1,void 0,this);case"context":return r(ud,{node:e,expanded:t},void 0,!1,void 0,this);case"ledger":return r(fd,{node:e},void 0,!1,void 0,this);case"trace":return r(jd,{node:e},void 0,!1,void 0,this);case"file":return r(md,{node:e,expanded:t},void 0,!1,void 0,this);case"diff":return r(dd,{node:e},void 0,!1,void 0,this);case"mermaid":return r(Ld,{node:e,expanded:t},void 0,!1,void 0,this);case"image":return r(Dd,{node:e,expanded:t},void 0,!1,void 0,this);case"html":return r(ec,{node:e,expanded:t},void 0,!1,void 0,this);default:return r("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function mI(e){switch(e.type){case"markdown":return e.data.content||"";case"diff":return e.data.content||"";case"mermaid":return e.data.content||"";case"file":return e.data.fileContent||"";case"webpage":return e.data.content||"";case"html":return e.data.html||e.data.content||"";case"json-render":case"graph":return JSON.stringify(e.data.spec??e.data.graphConfig??{},null,2);default:return""}}function aO(e){if(!e)return 0;return e.split(/\s+/).filter(Boolean).length}function lO(e,t){return e!==null&&typeof e==="object"&&e.source===eo&&e.type==="presentation-exit"&&e.token===t}function cO(e){return e==="ArrowRight"||e==="PageDown"||e===" "||e==="ArrowLeft"||e==="PageUp"||e==="Home"||e==="End"}function fI(e){return e instanceof HTMLElement&&Boolean(e.closest(".html-presentation-exit"))}function hI(){let e=Bt.value,t=e?Z.value.get(e):void 0,[n,o]=E(!1),[i,s]=E(null),[a,l]=E(!1),[c,u]=E(""),d=F(null),p=F(null),m=oe(()=>{l(!1),Rr()},[]),f=oe(()=>{u(`presentation-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`),l(!0)},[]),h=oe((R)=>{document.querySelector(".html-presentation-overlay iframe.html-node-frame-presentation")?.contentWindow?.postMessage({source:eo,token:c,...R},"*")},[c]),g=oe(()=>{l(!1)},[]),v=oe((R)=>{if(R.key==="Escape"){R.preventDefault(),R.stopPropagation(),l(!1);return}if(R.key==="Tab"&&!fI(R.target)){R.preventDefault(),R.stopPropagation(),p.current?.focus();return}if((R.key===" "||R.key==="Enter")&&fI(R.target))return;if(!cO(R.key))return;R.preventDefault(),R.stopPropagation(),h({type:"presentation-key",key:R.key})},[h]),b=oe((R)=>{if(R.target.classList.contains("expanded-overlay-backdrop"))Rr()},[]),x=oe(()=>{if(!t)return;let R=mI(t);if(!R)return;navigator.clipboard.writeText(R).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})},[t]),C=oe(()=>{if(!e)return;uo(e)},[e]);G(()=>{l(!1)},[e]),$e(()=>{if(!a)return;let R=()=>{let H=d.current;if(!H||H.contains(document.activeElement))return;H.focus()},te=[0,50,150].map((H)=>window.setTimeout(R,H)),O=(H)=>{if(!lO(H.data,c))return;l(!1)};return document.addEventListener("keydown",v,!0),window.addEventListener("message",O),()=>{te.forEach((H)=>{window.clearTimeout(H)}),document.removeEventListener("keydown",v,!0),window.removeEventListener("message",O)}},[v,c,a]);let y=F(null),k=oe(()=>e?document.querySelector(`.canvas-node[data-node-id="${CSS.escape(e)}"]`):null,[e]),_=Be.value&&Ct.value?.nodeId===e,A=!Be.value&&Ct.value?.nodeId===e&&!!document.activeElement?.closest(".lifecycle-dialog");if(bn(y,t!==void 0&&!_,{restoreTo:k}),$e(()=>{if(A)document.querySelector('button[aria-label="Settings"]')?.focus({preventScroll:!0})},[_]),!t)return null;let w=t.data.title||t.data.path?.split("/").pop()||ln[t.type],M=mI(t),B=aO(M),L=e?ht.value.has(e):!1,Y=M.length>0,j=Lo.value===e,J=t.type==="mcp-app"||t.type==="webpage"||t.type==="json-render"||t.type==="graph",X=nC(t),V=Bo(t.type),ee=t.data.provenance&&typeof t.data.provenance==="object"?t.data.provenance:null,he=ee?[ee.sourceKind,ee.sourceUri,ee.syncedAt?`synced ${ee.syncedAt.slice(11,16)}`:null].filter((R)=>typeof R==="string"&&R.length>0).join(" · "):null;return r("div",{class:"expanded-overlay-backdrop",onPointerDown:b,style:{pointerEvents:j?"none":"auto"},children:r("div",{ref:y,class:`expanded-overlay-panel${L?" is-pinned":""}`,role:"dialog","aria-modal":_?void 0:"true","aria-label":w,"data-testid":"expanded-node",children:[r("div",{class:"expanded-header",children:[r("span",{class:"expanded-kind-icon","aria-hidden":"true",children:r(V,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"expanded-title",children:w},void 0,!1,void 0,this),r("span",{class:"expanded-kind-pill",children:ln[t.type]},void 0,!1,void 0,this),r(_e,{label:L?"In agent context — click to unpin":"Pin as agent context",children:r("button",{type:"button",class:`expanded-pin${L?" is-on":""}`,onClick:C,"aria-label":L?"In agent context — click to unpin":"Pin as agent context","aria-pressed":L,children:"✦"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"expanded-spacer"},void 0,!1,void 0,this),r("div",{class:"expanded-actions",children:[Be.value&&r("button",{type:"button",class:"expanded-action-btn",onClick:()=>js(t.id),children:"Review"},void 0,!1,void 0,this),r("button",{type:"button",class:"expanded-action-btn","aria-pressed":i===e,onClick:()=>s(i===e?null:e),children:"Relations"},void 0,!1,void 0,this),Y&&r(_e,{label:"Copy content to clipboard",children:r("button",{type:"button",class:"expanded-action-btn",onClick:x,children:n?"Copied!":"Copy"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Nd(t)&&r(_e,{label:"Open as a full-page site in the system browser",children:r("button",{type:"button",class:"expanded-action-btn",onClick:()=>void Md(t),children:["Open in tab ",r(pi,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),X&&r(_e,{label:"Present this HTML node fullscreen",children:r("button",{type:"button",class:"expanded-action-btn expanded-action-primary",onClick:f,children:"Present"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(_e,{label:"Close",shortcut:"Esc",align:"end",children:r("button",{type:"button",class:"expanded-close",onClick:m,"aria-label":"Close",children:r(Tt,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"expanded-content-row",children:[r("div",{class:`expanded-body${J?" is-embedded":""}`,children:J?r("div",{style:{flex:1,minHeight:0,display:"flex"},children:pI(t,!0)},void 0,!1,void 0,this):pI(t,!0)},void 0,!1,void 0,this),i===e&&r(dI,{nodeId:t.id},e,!1,void 0,this)]},void 0,!0,void 0,this),r(tp,{node:t},void 0,!1,void 0,this),r("div",{style:{"--ax-dock-bleed":"0px","--ax-dock-pad":"16px"},children:r(op,{node:t},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("div",{class:"expanded-footer",children:[r("span",{class:"expanded-footer-meta",children:[he,B>0?`${B.toLocaleString()} word${B!==1?"s":""}`:null].filter(Boolean).join(" · ")||ln[t.type].toLowerCase()},void 0,!1,void 0,this),r("span",{class:"expanded-spacer"},void 0,!1,void 0,this),r("span",{class:`expanded-footer-hint${j?" is-saving":""}`,children:j?"Saving edits…":"esc or click outside to close"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&a&&r("div",{ref:d,class:"html-presentation-overlay",role:"dialog","aria-modal":"true","aria-label":`Present ${w}`,tabIndex:-1,onKeyDownCapture:v,children:[r("button",{ref:p,type:"button",class:"html-presentation-exit",onClick:g,"aria-label":"Exit presentation",children:"Exit presentation"},void 0,!1,void 0,this),r("div",{class:"html-presentation-stage",children:r(ec,{node:t,expanded:!0,presentation:!0,presentationExitToken:c},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var yI=168,vI=112,xp=20;function gI(e,t,n,o){let i=Array.from(e.values()),s=0,a=0,l=1000,c=800;if(i.length>0){s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,l=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;for(let v of i)s=Math.min(s,v.position.x),a=Math.min(a,v.position.y),l=Math.max(l,v.position.x+v.size.width),c=Math.max(c,v.position.y+v.size.height)}let u=-t.x/t.scale,d=-t.y/t.scale,p=u+n/t.scale,m=d+o/t.scale,f={minX:Math.min(s,u)-xp,minY:Math.min(a,d)-xp,maxX:Math.max(l,p)+xp,maxY:Math.max(c,m)+xp},h=f.maxX-f.minX||1,g=f.maxY-f.minY||1;return{bounds:f,scale:Math.min(yI/h,vI/g)}}function bI({viewport:e,nodes:t,onNavigate:n,containerWidth:o,containerHeight:i}){let s=F(null),a=F(!1),l=t.value,c=e.value,u=gI(l,c,o,i),{bounds:d,scale:p}=u,m=(w)=>(w-d.minX)*p,f=(w)=>(w-d.minY)*p,h=oe((w)=>{let M=s.current;if(!M)return;let B=M.getBoundingClientRect(),L=(w.clientX-B.left)/B.width*yI,Y=(w.clientY-B.top)/B.height*vI,j=gI(t.value,e.value,o,i),J=e.value,X=o/J.scale,V=i/J.scale,ee=L/j.scale+j.bounds.minX,he=Y/j.scale+j.bounds.minY;n(-(ee-X/2)*J.scale,-(he-V/2)*J.scale)},[t,e,o,i,n]),g=oe((w)=>{w.stopPropagation(),w.preventDefault(),a.current=!0,h(w);let M=(L)=>{if(a.current)h(L)},B=()=>{a.current=!1,document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",B)};document.addEventListener("pointermove",M),document.addEventListener("pointerup",B)},[h]),v=rt.value,b=ht.value,x=or.value?qd.value:new Set,C=Io.value,y=C?Xd(C.nodeIds.map((w)=>l.get(w)).filter((w)=>w!==void 0),C.padding):null,k=en.value.map((w)=>({id:w.sessionId,phase:w.phase,worker:w.parentAgentId!=null,external:!w.attached,at:Gd(w,(M)=>l.get(M))})).filter((w)=>w.at!==null),_=-c.x/c.scale,A=-c.y/c.scale;return r("div",{ref:s,class:"minimap","data-testid":"minimap","aria-label":"Minimap — click to jump, drag the frame to pan",onPointerDown:g,children:[Array.from(l.values()).map((w)=>{let M=w.type==="group";return r("span",{class:`minimap-node${M?" is-group":""}${v.has(w.id)?" is-selected":""}${b.has(w.id)?" is-pinned":""}${x.has(w.id)?" is-agent":""}`,"data-kind":w.type,style:{left:`${m(w.position.x)}px`,top:`${f(w.position.y)}px`,width:`${Math.max(M?6:4,w.size.width*p)}px`,height:`${Math.max(M?5:3,w.size.height*p)}px`}},w.id,!1,void 0,this)}),y&&r("span",{class:"minimap-fence",style:{left:`${m(y.x)}px`,top:`${f(y.y)}px`,width:`${y.width*p}px`,height:`${y.height*p}px`}},void 0,!1,void 0,this),k.map((w)=>r("span",{class:`minimap-presence phase-${w.phase}${w.worker?" is-worker":""}${w.external?" is-external":""}`,style:{left:`${m(w.at.x)-4}px`,top:`${f(w.at.y)-4}px`,"--identity-color":_o(w.id)}},w.id,!1,void 0,this)),r("span",{class:"minimap-frame",style:{left:`${m(_)}px`,top:`${f(A)}px`,width:`${o/c.scale*p}px`,height:`${i/c.scale*p}px`}},void 0,!1,void 0,this),r("span",{class:"minimap-zoom",children:[Math.round(c.scale*100),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function xI(){let e=rt.value.size,t=lp("--selection-bar-height"),n=oe(()=>{let l=Array.from(rt.value);if(l.length===0)return;Qu(l),$n()},[]),o=oe(()=>{let l=Array.from(rt.value);if(l.length===0)return;qs({title:"Group",childIds:l}),$n()},[]),i=oe(()=>{let l=Array.from(rt.value);for(let c=0;c<l.length;c++)for(let u=c+1;u<l.length;u++)kr(l[c],l[u],"relation");$n()},[]),s=oe(()=>{let l=Array.from(rt.value);for(let c of l)ri(c);$n()},[]);if(e===0)return null;let a=e>=2;return r("div",{class:"selection-bar",role:"toolbar","aria-label":"Selection",ref:t,children:[r("span",{class:"selection-bar-count",children:[e," node",e!==1?"s":""," selected"]},void 0,!0,void 0,this),a&&r(be,{children:[r("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),r(_e,{label:"Align left",side:"up",children:r("button",{type:"button",class:"selection-bar-icon","aria-label":"Align left",onClick:()=>Hf("left"),children:r("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[r("line",{x1:"2.5",y1:"2",x2:"2.5",y2:"14"},void 0,!1,void 0,this),r("rect",{x:"5",y:"3.5",width:"8",height:"3.5",rx:"1"},void 0,!1,void 0,this),r("rect",{x:"5",y:"9",width:"5",height:"3.5",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Align top",side:"up",children:r("button",{type:"button",class:"selection-bar-icon","aria-label":"Align top",onClick:()=>Hf("top"),children:r("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[r("line",{x1:"2",y1:"2.5",x2:"14",y2:"2.5"},void 0,!1,void 0,this),r("rect",{x:"3.5",y:"5",width:"3.5",height:"8",rx:"1"},void 0,!1,void 0,this),r("rect",{x:"9",y:"5",width:"3.5",height:"5",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Distribute horizontally",body:"Evens the gaps. A selection that cannot fit flows into a clean row instead of overlapping.",side:"up",children:r("button",{type:"button",class:"selection-bar-icon","aria-label":"Distribute",disabled:e<3,onClick:()=>xS(),children:r("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","aria-hidden":"true",children:[r("rect",{x:"1.5",y:"5",width:"3.5",height:"6",rx:"1"},void 0,!1,void 0,this),r("rect",{x:"6.25",y:"5",width:"3.5",height:"6",rx:"1"},void 0,!1,void 0,this),r("rect",{x:"11",y:"5",width:"3.5",height:"6",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Auto-arrange selection",side:"up",children:r("button",{type:"button",class:"selection-bar-icon","aria-label":"Auto-arrange",onClick:()=>wS(),children:r(Pr,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),r(_e,{label:"Group the selection",shortcut:"G",side:"up",children:r("button",{type:"button",class:"selection-bar-action",onClick:o,children:[r("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-dasharray":"3 2.5","aria-hidden":"true",children:r("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"2"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Group"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Connect every pair",side:"up",children:r("button",{type:"button",class:"selection-bar-action",onClick:i,children:"Connect"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(_e,{label:"Pin to agent context",side:"up",children:r("button",{type:"button",class:"selection-bar-action is-pin",onClick:n,children:[r("span",{"aria-hidden":"true",children:"✦"},void 0,!1,void 0,this),"Pin as context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),r("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),r(_e,{label:"Delete selection",side:"up",children:r("button",{type:"button",class:"selection-bar-icon is-danger","aria-label":"Delete selection",onClick:s,children:r("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[r("path",{d:"M2.5 4 H13.5"},void 0,!1,void 0,this),r("path",{d:"M5.5 4 V2.5 H10.5 V4"},void 0,!1,void 0,this),r("path",{d:"M4 4 L4.8 13.5 H11.2 L12 4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Clear selection",shortcut:"Esc",side:"up",children:r("button",{type:"button",class:"selection-bar-icon",onClick:$n,"aria-label":"Clear selection",children:r(Tt,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function wp(e,t=Date.now()){if(!e.expiresAt)return null;let n=Date.parse(e.expiresAt);if(!Number.isFinite(n))return null;return Math.max(0,n-t)}function kp(e){let t=Math.max(0,Math.ceil(e/1000)),n=Math.floor(t/60),o=t%60;return`${n}:${String(o).padStart(2,"0")}`}var uO={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"vetoed"},dO={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"cancelled"},wI=[{id:"all",label:"All",hint:"Everything below in one feed, newest first"},{id:"update",label:"Updates",hint:"Board edits agents made — nodes, edges, pins, work items"},{id:"steer",label:"Steer",hint:"Instructions sent to agents — by you from the composer, or agent-to-agent"},{id:"assistant",label:"Assistant",hint:"Messages agents posted for you to read"},{id:"event",label:"Events",hint:"Run telemetry — tool runs, approvals, failures, policy notes"},{id:"evidence",label:"Evidence",hint:"Proof agents recorded — test results, artifacts, links"}],pO=Object.fromEntries(wI.map((e)=>[e.id,e.hint])),mO={policy:"warn",prompt:"accent","assistant-message":"muted","tool-start":"accent","tool-result":"ok",failure:"danger",approval:"warn",steering:"purple",command:"accent",note:"muted",evidence:"ok",steer:"purple",update:"purple",yield:"warn"};function Hg(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function fO({item:e}){let t=uO[e.status]??"queued",n=e.nodeIds[0];return r("li",{class:`session-item status-${t}`,"data-work-item-id":e.id,children:[r("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),r("div",{class:"session-item-main",children:[r("button",{type:"button",class:"session-item-title",disabled:!n,onClick:()=>n&&$t(n),children:e.title},void 0,!1,void 0,this),e.detail&&r("div",{class:"session-item-detail",children:e.detail},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"session-item-status",children:dO[e.status]??t},void 0,!1,void 0,this),r("span",{class:"session-item-time",children:Hg(e.updatedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function kI({gate:e,now:t}){let[n,o]=E(null),i=async(l)=>{o(l),await DC(e,l),o(null)},s=e.nodeIds[0],a=wp(e,t);return r("li",{class:"session-item status-awaiting session-gate","data-gate-id":e.id,children:[r("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),r("div",{class:"session-item-main",children:[r("button",{type:"button",class:"session-item-title",disabled:!s,onClick:()=>s&&$t(s),children:e.title},void 0,!1,void 0,this),e.detail&&r("div",{class:"session-item-detail",children:e.detail},void 0,!1,void 0,this),a!==null&&r("div",{class:"session-gate-ttl","data-testid":"gate-countdown",children:["auto-holds in ",kp(a)," if unanswered"]},void 0,!0,void 0,this),r("div",{class:"session-gate-actions",children:[r("button",{type:"button",class:"session-gate-approve",disabled:n!==null,onClick:()=>void i("approved"),children:n==="approved"?"Approving…":"Approve"},void 0,!1,void 0,this),r("button",{type:"button",class:"session-gate-reject",disabled:n!==null,onClick:()=>void i("rejected"),children:n==="rejected"?"Rejecting…":"Reject"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"session-item-time",children:Hg(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function SI({gate:e}){let[t,n]=E(!1);return r("li",{class:"session-item status-vetoed session-gate-held","data-gate-id":e.id,children:[r("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),r("div",{class:"session-item-main",children:[r("span",{class:"session-item-title",children:e.title},void 0,!1,void 0,this),r("div",{class:"session-item-detail",children:"Auto-held — no answer in time, the action did not proceed."},void 0,!1,void 0,this),r("div",{class:"session-gate-actions",children:r("button",{type:"button",class:"session-gate-reject",disabled:t,onClick:()=>{n(!0),BC(e).finally(()=>n(!1))},children:t?"Reopening…":"Reopen"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"session-item-status",children:"held"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function hO(e){let t=e.resolvedBy;if(!t)return e.status;let n=e.status==="approved"?"Approved":"Rejected";if(t.actor==="human")return`${n} by you`;if(t.actor==="system")return`${n} by system`;let o=t.agentId||t.source||"agent";return`${e.selfAnswer?"Self-":""}${n.toLowerCase()} by ${o}`}function _I({gate:e}){return r("li",{class:`session-item status-${e.status}`,"data-gate-id":e.id,children:[r("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),r("div",{class:"session-item-main",children:[r("span",{class:"session-item-title",children:e.title},void 0,!1,void 0,this),r("div",{class:"session-item-detail",children:hO(e)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function CI(){let e=Io.value,t=rt.value.size,[n,o]=E(!1),i=(s)=>{o(!0),zC(s).finally(()=>o(!1))};return r("div",{class:`session-scope${e?" is-fenced":""}`,"data-testid":"session-scope",children:[r("span",{class:"session-scope-dot","aria-hidden":"true"},void 0,!1,void 0,this),e?r(be,{children:[r("span",{class:"session-scope-text",children:["Scoped to ",r("strong",{children:e.nodeIds.length},void 0,!1,void 0,this)," node",e.nodeIds.length===1?"":"s"," · writes outside are blocked"]},void 0,!0,void 0,this),r("button",{type:"button",class:"session-scope-action",disabled:n,onClick:()=>i(null),children:"Clear"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r(be,{children:[r("span",{class:"session-scope-text",children:"Unscoped — the agent may write anywhere"},void 0,!1,void 0,this),r(_e,{label:t===0?"Select nodes on the canvas first":"Fence the agent to the selected nodes",align:"end",children:r("button",{type:"button",class:"session-scope-action",disabled:n||t===0,onClick:()=>i([...rt.value]),children:["Fence to selection",t>0?` (${t})`:""]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function gO(e){if(e==="browser")return"you";return en.value.find((n)=>n.sessionId===e||n.source===e)?.label??e}function yO({entry:e}){let t=rc.value.has(e.id);return r("li",{class:`session-timeline-row tone-${mO[e.kind]??"muted"}`,children:[r("span",{class:"session-timeline-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("div",{class:"session-timeline-main",children:[r("div",{class:"session-timeline-head",children:[r("span",{class:"session-timeline-label",children:e.label},void 0,!1,void 0,this),e.who&&r("span",{class:"session-timeline-who",style:{"--identity-color":_o(e.who)},children:gO(e.who)},void 0,!1,void 0,this),r("span",{class:"session-item-time",children:Hg(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"session-timeline-body",children:e.body},void 0,!1,void 0,this),e.undoable&&!t&&r("button",{type:"button",class:"session-timeline-undo","data-testid":"timeline-undo",onClick:()=>void hg(e),children:[r(th,{size:14},void 0,!1,void 0,this)," undo this edit"]},void 0,!0,void 0,this),t&&r("div",{class:"session-timeline-undone",children:"undone · steering sent"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function TI(){let e=To.value,t=rr();if(!to.value&&e.length===0)return null;return r("aside",{class:"session-panel","aria-label":"Agent controls",children:[r("header",{class:"session-panel-header",children:[r("span",{class:"session-panel-title",children:"Agent controls"},void 0,!1,void 0,this),r("span",{class:"top-bar-spacer"},void 0,!1,void 0,this),r("button",{type:"button",class:"session-collapse","aria-label":"Collapse agent controls",onClick:()=>to.value=!1,disabled:e.length>0,children:r(di,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(CI,{},void 0,!1,void 0,this),r("div",{class:"session-panel-scroll",children:[r("ul",{class:"session-list","aria-label":"Approvals",children:[e.map((n)=>r(kI,{gate:n,now:t},n.id,!1,void 0,this)),ls.value.map((n)=>r(SI,{gate:n},n.id,!1,void 0,this)),fg.value.map((n)=>r(_I,{gate:n},n.id,!1,void 0,this))]},void 0,!0,void 0,this),Sa.value.map((n)=>r("div",{class:"session-item",children:[r("span",{class:"session-item-main",children:n.label},void 0,!1,void 0,this),r("button",{type:"button",class:"session-end",onClick:()=>void ic(n),children:"End attachment"},void 0,!1,void 0,this)]},n.sessionId,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function II(){G(()=>()=>{to.value=!1},[]);let e=xi.value,t=MC.value,n=To.value,o=ls.value,i=fg.value,s=OC.value,[a,l]=E(!1),[c,u]=E(null),d=rr();if(G(()=>{Si()},[]),!(to.value||n.length>0))return r("aside",{class:"session-panel is-collapsed","aria-label":"Session (collapsed)",children:[r("button",{type:"button",class:"session-collapse",onClick:()=>{to.value=!0},"aria-label":"Expand session panel",children:"‹"},void 0,!1,void 0,this),e&&r("span",{class:`session-collapsed-live phase-${e.phase}`,"aria-label":`Session live: ${vi(e)}`,children:[r("span",{class:"session-live-dot","aria-hidden":"true"},void 0,!1,void 0,this),"live"]},void 0,!0,void 0,this),r("span",{class:"session-collapsed-label",children:"Session"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return r("aside",{class:"session-panel","aria-label":"Session",children:[r("header",{class:"session-panel-header",children:[r("span",{class:"session-panel-title",children:"Session"},void 0,!1,void 0,this),e&&r(_e,{label:vi(e),tapToOpen:!0,children:r("span",{class:`session-live phase-${e.phase}`,children:[r("span",{class:"session-live-dot","aria-hidden":"true"},void 0,!1,void 0,this),"live"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),r("span",{class:"top-bar-spacer"},void 0,!1,void 0,this),e&&r(_e,{label:"End this session",body:"A receipt and a snapshot of the board follow.",align:"end",children:r("button",{type:"button",class:"session-end",onClick:()=>void ic(e),children:"End"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("button",{type:"button",class:"session-collapse",onClick:()=>{to.value=!1},"aria-label":"Collapse session panel",children:r(di,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(CI,{},void 0,!1,void 0,this),(()=>{let m=s.find((f)=>f.undoable&&!rc.value.has(f.id));if(!m)return null;return r("div",{class:"session-undo-row","data-testid":"session-undo-row",children:[r("span",{class:"session-undo-text",children:["Agent edit on top: ",m.body]},void 0,!0,void 0,this),r("button",{type:"button",class:"session-undo-btn",onClick:()=>void hg(m),children:[r(th,{size:14},void 0,!1,void 0,this)," Undo"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)})(),r("div",{class:"session-panel-body",children:[r("section",{class:"session-section",children:(()=>{let m=t.filter((C)=>C.status==="in-progress"||C.status==="todo").length,f=t.filter((C)=>C.status!=="cancelled"),h=f.filter((C)=>C.status==="done").length,g=t.length-f.length,v=n.length>0,b=a||v,x=m>0?`${m} running`:f.length>0?`${h}/${f.length} done${g>0?` · ${g} cancelled`:""}`:t.length>0?`${t.length} cancelled`:"none yet";return r(be,{children:[r("button",{type:"button",class:"session-section-toggle","aria-expanded":b,"data-testid":"work-items-toggle",onClick:()=>l((C)=>!C),children:[r("span",{class:"session-section-title",children:"Work items"},void 0,!1,void 0,this),r("span",{class:"session-work-summary",children:[m>0&&r("span",{class:"session-work-dot","aria-hidden":"true"},void 0,!1,void 0,this),x]},void 0,!0,void 0,this),r("span",{class:`session-section-chevron${b?" is-open":""}`,"aria-hidden":"true",children:r(di,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b&&(n.length===0&&o.length===0&&i.length===0&&t.length===0?r("div",{class:"session-empty",children:"No work items yet — the agent's tasks and gates appear here."},void 0,!1,void 0,this):r("ul",{class:"session-list","aria-live":"polite","aria-label":"Work items and gates",children:[n.map((C)=>r(kI,{gate:C,now:d},C.id,!1,void 0,this)),o.map((C)=>r(SI,{gate:C},C.id,!1,void 0,this)),i.map((C)=>r(_I,{gate:C},C.id,!1,void 0,this)),t.map((C)=>r(fO,{item:C},C.id,!1,void 0,this))]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)})()},void 0,!1,void 0,this),r("section",{class:"session-section",children:[r("h3",{class:"session-section-title",children:"Timeline"},void 0,!1,void 0,this),r("div",{class:"session-timeline-filters",role:"group","aria-label":"Filter timeline",children:wI.map((m)=>r("button",{type:"button",class:`activity-filter${cs.value===m.id?" is-active":""}`,"aria-pressed":cs.value===m.id,onMouseEnter:()=>u(m.id),onMouseLeave:()=>u((f)=>f===m.id?null:f),onFocus:()=>u(m.id),onBlur:()=>u((f)=>f===m.id?null:f),onClick:()=>{cs.value=m.id},children:m.label},m.id,!1,void 0,this))},void 0,!1,void 0,this),r("div",{class:"session-timeline-hint","data-testid":"timeline-filter-hint",children:pO[c??cs.value]},void 0,!1,void 0,this),s.length===0?r("div",{class:"session-empty",children:cs.value==="all"?"Nothing recorded yet.":"Nothing of this kind yet."},void 0,!1,void 0,this):r("ul",{class:"session-list session-timeline","aria-live":"polite","aria-label":"Timeline",children:s.map((m)=>r(yO,{entry:m},m.id,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Fg(e){if(!e||typeof e!=="object")return null;let t=e,n=(o)=>Array.isArray(o)?o.length:0;return{added:n(t.addedNodes)+n(t.addedEdges),removed:n(t.removedNodes)+n(t.removedEdges),modified:n(t.modifiedNodes)}}var EI=(e)=>e.map((t)=>t.title).join(", ");function AI(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function vO({context:e,label:t,snapshotId:n}){let[o,i]=E(!1),[s,a]=E([]),[l,c]=E(!1),[u,d]=E(null),[p,m]=E(!1),f=e.edited.length>0&&e.edited.every((x)=>s.includes(x.id))?"undone":l?"kept":null;G(()=>{a([]),c(!1),d(null)},[e]);let h=async(x)=>{if(!n||p)return;m(!0);try{let C=await jC(n,x.filter((y)=>!s.includes(y.id)));return a((y)=>[...y,...C.restored]),C}finally{m(!1)}},v=[{key:"read",name:"Read",glyph:"eye"},{key:"pinned",name:"Pinned",glyph:"pin"},{key:"created",name:"Created",glyph:"spark"},{key:"edited",name:"Edited",glyph:"pen"}].filter((x)=>e[x.key].length>0);if(v.length===0&&e.changedSinceRead.length===0)return null;let b=Hn.value?.kind==="receipt";return r("div",{class:"session-receipt-context","data-testid":"session-receipt-context",children:[e.changedSinceRead.length>0&&r("div",{class:"session-receipt-warn",children:[r("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:r("path",{d:ki.warn},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{children:[EI(e.changedSinceRead)," changed after ",t," read"," ",e.changedSinceRead.length===1?"it":"them","."]},void 0,!0,void 0,this),r("button",{type:"button",class:"session-receipt-mini",disabled:o,onClick:()=>{let x=e.changedSinceRead.length===1?"it":"them";_a(`${e.changedSinceRead.map((C)=>`“${C.title}”`).join(", ")} changed after you read ${x} — read ${x} again before relying on ${x}.`).then((C)=>i(C))},children:o?"Told":`Tell ${t}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v.map((x)=>r("div",{class:"session-receipt-context-row","data-row":x.key,children:[r("div",{class:"session-receipt-context-head",children:[x.glyph==="pin"?r(mo,{},void 0,!1,void 0,this):r("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:r("path",{d:ki[x.glyph]},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"session-receipt-context-name",children:x.name},void 0,!1,void 0,this),r("span",{class:"session-receipt-context-count",children:e[x.key].length},void 0,!1,void 0,this),x.key==="pinned"&&r("button",{type:"button",class:"session-receipt-mini",disabled:e.pinned.some((C)=>C.boardId&&C.boardId!==ie.value),onClick:()=>kS(e.pinned.map((C)=>C.id)),children:"Unpin"},void 0,!1,void 0,this),x.key==="edited"&&n&&r("button",{type:"button",class:"session-receipt-mini",disabled:f!==null||p||e.edited.some((C)=>C.boardId&&C.boardId!==ie.value),onClick:()=>{h(e.edited).then((C)=>{if(C?.ok)c(!0)})},children:f==="undone"?"✓ Undone":f==="kept"?"Kept your edits":"Undo"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x.key==="edited"&&f&&r("div",{class:"session-receipt-context-items",children:f==="undone"?"every card restored":"cards you edited since were left alone"},void 0,!1,void 0,this),x.key==="edited"?r("ul",{class:"session-receipt-edits",children:e.edited.map((C)=>r(xO,{node:C,canUndo:n!==null,undoing:p,open:u===ir(C),onToggle:()=>d(u===ir(C)?null:ir(C)),undone:s.includes(C.id),onUndo:()=>void h([C])},ir(C),!1,void 0,this))},void 0,!1,void 0,this):r("div",{class:"session-receipt-context-items",children:x.key==="pinned"?e.pinned.map((C)=>C.reason?`${C.title} — “${C.reason}”`:C.title).join("; "):EI(e[x.key])},void 0,!1,void 0,this)]},x.key,!0,void 0,this)),r("button",{type:"button",role:"switch","aria-checked":b,class:`session-receipt-lens${b?" is-on":""}`,onClick:()=>sc(!b),children:[r("span",{class:"session-receipt-lens-track","aria-hidden":"true",children:r("span",{class:"session-receipt-lens-knob"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Dim untouched nodes"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function bO(e,t){let n=(d)=>d.match(/\s+|[\p{L}\p{N}_]+|[^\s\p{L}\p{N}_]/gu)??[],o=n(e),i=n(t),s=Array.from({length:o.length+1},()=>new Uint16Array(i.length+1));for(let d=o.length-1;d>=0;d--)for(let p=i.length-1;p>=0;p--)s[d][p]=o[d]===i[p]?s[d+1][p+1]+1:Math.max(s[d+1][p],s[d][p+1]);let a=[],l=[],c=0,u=0;while(c<o.length||u<i.length)if(c<o.length&&u<i.length&&o[c]===i[u])a.push({text:o[c++],changed:!1}),l.push({text:i[u++],changed:!1});else if(c<o.length&&(u===i.length||s[c+1][u]>=s[c][u+1]))a.push({text:o[c++],changed:!0});else l.push({text:i[u++],changed:!0});return[a,l]}function xO({node:e,canUndo:t,undoing:n,open:o,onToggle:i,undone:s,onUndo:a}){let l=!e.boardId||e.boardId===ie.value,c=l?Z.value.get(e.id):void 0,u=Ge.value.find((f)=>f.id===e.boardId),d=Ve(()=>o?bO(e.before??"",e.after??""):[],[o,e.before,e.after]),p=F(null);$e(()=>{for(let f of p.current?.querySelectorAll(".session-receipt-diff-text")??[]){let h=f.querySelector("del, ins");if(h)f.scrollTop=h.getBoundingClientRect().top-f.getBoundingClientRect().top-24}},[d]);let m=c?.lastEditedBy?.actor==="human";return r("li",{class:"session-receipt-edit",children:[r("span",{class:"session-receipt-edit-line",children:[r("span",{children:[e.title,e.change?r("span",{class:"session-receipt-edit-change",children:[" — ",e.change]},void 0,!0,void 0,this):null]},void 0,!0,void 0,this),e.before!==void 0&&r("button",{type:"button",class:"session-receipt-link","aria-expanded":o,onClick:i,children:o?"Hide change":"See change"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o&&r("span",{ref:p,class:"session-receipt-diff-pair",children:[d.map((f,h)=>r("span",{class:"session-receipt-diff-side",children:[r("span",{class:"session-receipt-diff-label",children:h===0?"Before":"After"},void 0,!1,void 0,this),r("span",{class:"session-receipt-diff-text",children:f.length?f.map(({text:g,changed:v},b)=>g==="…"&&(b===0||b===f.length-1)?r("span",{class:"session-receipt-diff-cut",children:g},b,!1,void 0,this):v?h===0?r("del",{children:g},b,!1,void 0,this):r("ins",{children:g},b,!1,void 0,this):g):"Empty"},void 0,!1,void 0,this)]},h,!0,void 0,this)),t&&r("span",{class:"session-receipt-undo",children:[c?r("button",{type:"button",class:"session-receipt-mini",disabled:s||m||n,onClick:a,children:s?"✓ Undone":m?"You edited it since":"Undo this card"},void 0,!1,void 0,this):u&&!l?r("button",{type:"button",class:"session-receipt-mini",onClick:()=>void Mn(u.id),children:["Open ",u.name," to undo"]},void 0,!0,void 0,this):r("span",{class:"session-receipt-edit-change",children:"Card no longer on this board"},void 0,!1,void 0,this),r("span",{class:"session-receipt-edit-change",children:c?s?"the card shows Before again":m?"undo would lose your edit":e.before?.includes("…")||e.after?.includes("…")?"undoes the whole card":"puts back the text from before":u&&!l?`it is on ${u.name}`:""},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function RI({onOpenSnapshots:e}){let t=as.value,[n,o]=E(null),[i,s]=E(!1);if(G(()=>o(null),[t]),!kt.value||!t)return null;let a=t.snapshot?.boardId===ie.value,l=Ge.value.find((m)=>m.id===t.snapshot?.boardId),c=async()=>{if(!t.snapshot||!a)return;s(!0);try{let m=await Gt(`/api/canvas/snapshots/${encodeURIComponent(t.snapshot.id)}/diff`,{headers:{"x-pmx-workbench":"1"}});if(m.ok){let f=await m.json();o(Fg(f.diff)??{added:0,removed:0,modified:0})}}finally{s(!1)}},u=AI(t.endedAt),d=t.startedAt?AI(t.startedAt):"",p=t.endedBy==="human"?"ended by you":t.endedBy==="idle-timeout"?"ended on idle timeout":t.endedBy==="agent"?"ended by the agent":"";return r("div",{class:"session-receipt","data-testid":"session-receipt",role:"status",children:[r("div",{class:"session-receipt-head",children:[r("span",{class:"session-receipt-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("span",{class:"session-receipt-title",children:t.sessions>1?`${t.sessions} sessions ended${u?` · ${u}`:""}`:`What ${t.labels[0]} did`},void 0,!1,void 0,this),r("button",{type:"button",class:"session-receipt-close",onClick:Yd,"aria-label":"Dismiss receipt",children:r(Tt,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.sessions>1?r("div",{class:"session-receipt-who",children:t.labels.join(", ")},void 0,!1,void 0,this):r("div",{class:"session-receipt-who","data-testid":"session-receipt-span",children:[`This session · ${d?`${d}–`:""}${u}`,t.snapshot?"saved as a snapshot":"",p].filter(Boolean).join(" · ")},void 0,!1,void 0,this),r("div",{class:"session-receipt-tiles",children:[r("div",{class:"session-receipt-tile",children:[r("span",{class:"session-receipt-tile-label",children:"Items"},void 0,!1,void 0,this),r("span",{class:"session-receipt-tile-value",children:t.counts.items},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"session-receipt-tile",children:[r("span",{class:"session-receipt-tile-label",children:"Done"},void 0,!1,void 0,this),r("span",{class:"session-receipt-tile-value tone-ok",children:t.counts.done},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.cancelled>0&&r("div",{class:"session-receipt-tile",children:[r("span",{class:"session-receipt-tile-label",children:"Cancelled"},void 0,!1,void 0,this),r("span",{class:"session-receipt-tile-value tone-muted",children:t.counts.cancelled},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.rejected>0&&r("div",{class:"session-receipt-tile",children:[r("span",{class:"session-receipt-tile-label",children:"Rejected"},void 0,!1,void 0,this),r("span",{class:"session-receipt-tile-value tone-danger",children:t.counts.rejected},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.held>0&&r("div",{class:"session-receipt-tile",children:[r("span",{class:"session-receipt-tile-label",children:"Held"},void 0,!1,void 0,this),r("span",{class:"session-receipt-tile-value tone-warn",children:t.counts.held},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r(vO,{context:t.context,label:t.labels.join(", "),snapshotId:t.sessions===1?t.snapshot?.id??null:null},void 0,!1,void 0,this),r("div",{class:"session-receipt-note",children:t.sessions>1?"History has each session’s diff and the snapshot from before it.":t.snapshot?"A snapshot of the board from before this session is saved — restore it to undo the session.":t.context.created.length===0&&t.context.edited.length===0?"The board itself did not change — nothing to restore.":"The board was empty when the session started — nothing to restore."},void 0,!1,void 0,this),n&&r("div",{class:"session-receipt-diff","data-testid":"session-receipt-diff",children:["This session: ",n.added," added · ",n.removed," removed · ",n.modified," modified"]},void 0,!0,void 0,this),r("div",{class:"session-receipt-actions",children:[t.snapshot&&r("button",{type:"button",class:"session-receipt-primary",disabled:i||!a&&!l,onClick:()=>a?void c():l&&void Mn(l.id),children:!a&&l?`Open ${l.name} to compare`:i?"Comparing…":"View diff"},void 0,!1,void 0,this),r(_e,{label:"Open the History drawer",body:"Saved boards and past sessions.",side:"up",align:"end",children:r("button",{type:"button",class:"session-receipt-secondary",onClick:e,children:"History"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var wO=[{title:"Tools",shortcuts:[{keys:"V",desc:"Select tool — drag empty space to lasso"},{keys:"Space (hold)",desc:"Pan — drag anywhere moves the board"},{keys:"A",desc:"Annotate — draw on the canvas"}]},{title:"Navigation",shortcuts:[{keys:Ht("K"),desc:"Command palette — search nodes & actions"},{keys:"Tab / Shift+Tab",desc:"Cycle through nodes"},{keys:"← ↑ → ↓",desc:"Walk graph along edges (when node focused)"},{keys:"F",desc:"Fit all nodes on screen"},{keys:Ht("0"),desc:"Reset viewport to origin"},{keys:`${Ht("+")} / ${Ht("−")}`,desc:"Zoom in / out"}]},{title:"Creation",shortcuts:[{keys:"M",desc:"New markdown note"},{keys:"I / W / H",desc:"New image / webpage / HTML surface"},{keys:"Shift+F",desc:"New file node (workspace path)"},{keys:"G / Shift+G",desc:"Group the selection (new frame when empty) / ungroup"},{keys:"Double-click",desc:"Open actions on a node or create menu on canvas"},{keys:"Drag port → node",desc:"Connect two nodes (hover to reveal ports)"}]},{title:"Selection",shortcuts:[{keys:"Click",desc:"Focus node (highlights neighbors & edges)"},{keys:"Shift+Click",desc:"Toggle node in multi-selection"},{keys:"Drag empty space",desc:"Lasso select multiple nodes"},{keys:Zl?"Delete / ⌫":"Delete / Backspace",desc:"Delete the selection (or the focused node)"},{keys:Zl?"⌘Z / ⇧⌘Z":"Ctrl+Z / Ctrl+Y",desc:"Undo / redo — agent edits included"},{keys:"Esc",desc:"Close overlay first, then clear selection and view filters"}]},{title:"View",shortcuts:[{keys:"?",desc:"Toggle this shortcut overlay"},{keys:"Minimap",desc:"Click/drag to navigate (toggle in the rail)"},{keys:"Right-drag",desc:"Pan the board from anywhere"}]}];function PI({onClose:e}){return r("div",{class:"shortcut-overlay-backdrop",onMouseDown:e,children:r("div",{class:"shortcut-overlay",onMouseDown:(t)=>t.stopPropagation(),children:[r("div",{class:"shortcut-overlay-header",children:[r("span",{class:"shortcut-overlay-title",children:"Keyboard Shortcuts"},void 0,!1,void 0,this),r("span",{class:"shortcut-overlay-hint",children:["Press ",r("kbd",{children:"?"},void 0,!1,void 0,this)," or ",r("kbd",{children:"Esc"},void 0,!1,void 0,this)," to close"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"shortcut-overlay-body",children:wO.map((t)=>r("div",{class:"shortcut-group",children:[r("div",{class:"shortcut-group-title",children:t.title},void 0,!1,void 0,this),t.shortcuts.map((n)=>r("div",{class:"shortcut-row",children:[r("kbd",{class:"shortcut-keys",children:n.keys},void 0,!1,void 0,this),r("span",{class:"shortcut-desc",children:nt()&&n.desc.startsWith("Undo / redo")?"Undo / redo — available in the local workbench only":n.desc},void 0,!1,void 0,this)]},n.keys,!0,void 0,this))]},t.title,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var NI="Before session · ";function MI(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function Sp(e){if(!e.startsWith(NI))return null;let t=e.slice(NI.length),n=t.lastIndexOf(" · ");return n>0?t.slice(0,n):t}function zI({open:e,onClose:t,anchorRef:n}){let[o,i]=E([]),[s,a]=E(!1),[l,c]=E(!1),[u,d]=E(null),[p,m]=E(""),[f,h]=E(null),[g,v]=E({}),b=F(null),x=F(null);G(()=>{if(!e)return;a(!0),Kk().then((w)=>{i(w),a(!1)})},[e]),G(()=>{if(e)setTimeout(()=>x.current?.focus(),50)},[e]),G(()=>{if(!e)return;let w=(M)=>{let B=b.current,L=n.current;if(B&&!B.contains(M.target)&&L&&!L.contains(M.target))t()};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[e,t]),G(()=>{if(!e)return;let w=(M)=>{if(M.key==="Escape")t()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[e,t]);let C=oe(async()=>{let w=p.trim();if(!w)return;c(!0);let M=await Vk(w);if(c(!1),M.ok&&M.snapshot)i((B)=>[M.snapshot,...B]),m("")},[p]),y=oe(async(w)=>{h(null),d(w);let M=await Xk(w);if(d(null),M.ok)t()},[t]),k=oe(async(w)=>{if((await Jk(w)).ok)i((B)=>B.filter((L)=>L.id!==w));h(null)},[]),_=oe(async(w)=>{v((B)=>({...B,[w]:"loading"}));let M=await pe("snapshotDiff",`/api/canvas/snapshots/${encodeURIComponent(w)}/diff`,{});v((B)=>({...B,[w]:Fg(M.diff)??{added:0,removed:0,modified:0}}))},[]);if(!e)return null;let A=(w,M)=>f?.id===w.id?r(be,{children:[r("button",{type:"button",class:`snapshot-action-btn ${f.action==="delete"?"snapshot-action-confirm":"snapshot-action-restore"}`,onClick:()=>f.action==="delete"?k(w.id):y(w.id),disabled:u!==null,children:f.action==="delete"?"Delete":u===w.id?"Restoring…":"Confirm"},void 0,!1,void 0,this),r("button",{type:"button",class:"snapshot-action-btn",onClick:()=>h(null),disabled:u!==null,children:"Cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r(be,{children:[r(_e,{label:"Restore this snapshot",body:nt()?"Replaces the current canvas.":"Replaces the current canvas (undoable).",align:"end",children:r("button",{type:"button",class:"snapshot-action-btn snapshot-action-restore",onClick:()=>h({id:w.id,action:"restore"}),disabled:u!==null,children:u===w.id?"Restoring…":M},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Delete this snapshot",align:"end",children:r("button",{type:"button",class:"snapshot-action-btn snapshot-action-delete",onClick:()=>h({id:w.id,action:"delete"}),"aria-label":"Delete snapshot",disabled:u!==null,children:r(Tt,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return r("div",{ref:b,class:"snapshot-panel","data-testid":"history-drawer",role:"dialog","aria-label":"History",children:[r("div",{class:"snapshot-panel-header",children:[r("span",{class:"snapshot-panel-title",children:"History"},void 0,!1,void 0,this),r("span",{class:"snapshot-panel-sub",children:"snapshots + sessions"},void 0,!1,void 0,this),r("span",{class:"snapshot-panel-spacer"},void 0,!1,void 0,this),r("button",{type:"button",class:"snapshot-panel-close",onClick:t,"aria-label":"Close history",children:r(Tt,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"snapshot-save-form",children:[r("input",{ref:x,type:"text",class:"snapshot-name-input",value:p,onInput:(w)=>m(w.target.value),onKeyDown:(w)=>{if(w.key==="Enter")C()},placeholder:"Save a snapshot as…","aria-label":"Snapshot name",maxLength:80,disabled:l},void 0,!1,void 0,this),r("button",{type:"button",class:"snapshot-save-btn",onClick:C,disabled:!p.trim()||l,children:l?"…":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"snapshot-restore-note",children:nt()?"Restoring replaces the current canvas. Save a snapshot first to keep your current state.":"Restoring replaces the current canvas. You can undo it if needed."},void 0,!1,void 0,this),r("div",{class:"snapshot-list",children:[s&&r("div",{class:"snapshot-empty",children:"Loading…"},void 0,!1,void 0,this),!s&&o.length===0&&r("div",{class:"snapshot-empty",children:"No history yet. Save a snapshot, or start an agent session — it snapshots for you."},void 0,!1,void 0,this),!s&&[...o.filter((w)=>Sp(w.name)===null),...o.some((w)=>Sp(w.name)!==null)?[{id:"__sessions-header__"}]:[],...o.filter((w)=>Sp(w.name)!==null)].map((w)=>{if(w.id==="__sessions-header__")return r("div",{class:"snapshot-section-header","data-testid":"history-sessions-header",children:"Sessions"},w.id,!1,void 0,this);let M=Sp(w.name),B=g[w.id];if(M!==null)return r("div",{class:"snapshot-item is-session","data-testid":"history-session",children:[r("div",{class:"snapshot-item-head",children:[r("span",{class:"snapshot-session-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("span",{class:"snapshot-item-name",children:["Agent session — ",M]},void 0,!0,void 0,this),r("span",{class:"snapshot-item-time",children:MI(w.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"snapshot-item-meta",children:["snapshot at session start · ",w.nodeCount," node",w.nodeCount!==1?"s":"",B&&B!=="loading"&&r("span",{class:"snapshot-item-diff",children:[" ","· since: ",B.added," added · ",B.removed," removed · ",B.modified," modified"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"snapshot-item-actions is-session",children:[r("button",{type:"button",class:"snapshot-action-btn snapshot-action-diff",disabled:B==="loading",onClick:()=>void _(w.id),children:B==="loading"?"Comparing…":"View diff"},void 0,!1,void 0,this),A(w,"Restore pre-state")]},void 0,!0,void 0,this)]},w.id,!0,void 0,this);return r("div",{class:"snapshot-item","data-testid":"history-snapshot",children:[r("div",{class:"snapshot-item-head",children:[r("span",{class:"snapshot-item-glyph","aria-hidden":"true",children:"◫"},void 0,!1,void 0,this),r("span",{class:"snapshot-item-name",children:w.name},void 0,!1,void 0,this),r("span",{class:"snapshot-item-time",children:MI(w.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"snapshot-item-meta",children:[w.nodeCount," node",w.nodeCount!==1?"s":"",w.edgeCount>0?` · ${w.edgeCount} edge${w.edgeCount!==1?"s":""}`:""," · ",cp(w.createdAt)]},void 0,!0,void 0,this),r("div",{class:"snapshot-item-actions",children:A(w,"Restore")},void 0,!1,void 0,this)]},w.id,!0,void 0,this)})]},void 0,!0,void 0,this),r("div",{class:"snapshot-panel-foot",children:"Every agent session start writes a snapshot automatically."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var kO=8;function $I({fallbackName:e}){let[t,n]=E(!1),o=F(null),i=F(null),s=F(null);$e(()=>{if(!t)return;let p=(f)=>{if(f.target instanceof Node&&!o.current?.contains(f.target)&&!s.current?.contains(f.target))n(!1)},m=(f)=>{if(f.key==="Escape")f.stopPropagation(),n(!1),i.current?.focus()};return document.addEventListener("pointerdown",p,!0),document.addEventListener("keydown",m,!0),()=>{document.removeEventListener("pointerdown",p,!0),document.removeEventListener("keydown",m,!0)}},[t]);let a=Qn(),l=!Wn.value?e:a&&!pt.value?a.name:"Home",c=Ge.value.filter((p)=>pt.value||p.id!==ie.value).slice(0,kO),u=i.current?.getBoundingClientRect(),d=(p)=>{n(!1),Mn(p)};return r("span",{class:"board-switcher",ref:o,children:[r("button",{ref:i,type:"button",class:"top-bar-title board-switcher-button","aria-haspopup":"menu","aria-expanded":t,"aria-label":`Board: ${l}. Switch board`,onClick:()=>n((p)=>!p),children:[r("span",{class:"board-switcher-name",children:l},void 0,!1,void 0,this),r("span",{class:"board-switcher-caret","aria-hidden":"true",children:r(oa,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&u&&r(ia,{children:r("div",{ref:s,class:"toolbar-menu board-switcher-menu",role:"menu","aria-label":"Boards",style:{position:"fixed",left:`min(${u.left}px, max(12px, calc(100vw - 352px)))`,top:`${u.bottom+8}px`,right:"auto",maxHeight:`min(70vh, calc(100dvh - ${u.bottom+20}px))`},children:[c.length>0&&r("div",{class:"board-switcher-heading",children:"Recent boards"},void 0,!1,void 0,this),r("div",{class:"board-switcher-recents",children:c.map((p)=>r("div",{class:"board-switcher-row",children:[r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>d(p.id),children:[r("span",{class:"board-switcher-icon","aria-hidden":"true",children:r(cd,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"board-switcher-item-copy",children:[r("span",{class:"board-switcher-item-name",children:p.name},void 0,!1,void 0,this),r("span",{class:"board-switcher-item-folder",children:p.folder?.split("/").join(" / ")||"Unfiled"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"board-switcher-item-meta",children:[p.nodeCount," ",p.nodeCount===1?"node":"nodes"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r(go,{board:p},void 0,!1,void 0,this)]},p.id,!0,void 0,this))},void 0,!1,void 0,this),r("div",{class:"board-switcher-actions",children:[r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>{n(!1),Dg()},children:[r("span",{class:"board-switcher-icon","aria-hidden":"true",children:r($S,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),"New board…"]},void 0,!0,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>d(null),children:[r("span",{class:"board-switcher-icon","aria-hidden":"true",children:r(Pr,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),"All boards (Home)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var LI=3,OI={"waiting-approval":0,thinking:1,tooling:2,idle:3};function SO(){let[e,t]=E(null),n=F(null);$e(()=>{if(!e)return;let d=(f)=>{if(!n.current?.contains(f.target)&&!e.button.contains(f.target))t(null)},p=(f)=>{if(f.key==="Escape"&&!f.defaultPrevented)f.preventDefault(),t(null),e.button.focus({preventScroll:!0})},m=()=>t(null);return document.addEventListener("pointerdown",d,!0),document.addEventListener("keydown",p),window.addEventListener("resize",m),()=>{document.removeEventListener("pointerdown",d,!0),document.removeEventListener("keydown",p),window.removeEventListener("resize",m)}},[e]);let o=Sa.value;if(G(()=>{if(e&&!e.button.isConnected)t(null)},[o,e]),!kt.value||o.length===0)return null;let i=o.filter((d)=>!d.parentAgentId||!o.some((p)=>p.sessionId!==d.sessionId&&!p.parentAgentId&&(p.sessionId===d.parentAgentId||p.source===d.parentAgentId))),s=[...i].sort((d,p)=>(OI[d.phase]??4)-(OI[p.phase]??4)),a=s.slice(0,LI),l=s.slice(LI),c=i.reduce((d,p)=>(d[p.phase]=(d[p.phase]??0)+1,d),{}),u=[c["waiting-approval"]&&`${c["waiting-approval"]} waiting on approval`,c.thinking&&`${c.thinking} thinking`,c.tooling&&`${c.tooling} running tools`,c.idle&&`${c.idle} idle`].filter(Boolean).join(", ");return r(be,{children:[r("span",{class:"agent-chips",children:a.map((d)=>{let p=d.parentAgentId?0:en.value.filter((m)=>m.parentAgentId!=null&&(m.parentAgentId===d.sessionId||m.parentAgentId===d.source)).length;return r(_e,{label:`Agent session — ${d.label}`,tapToOpen:!0,body:"What this attached agent is doing right now: idle, thinking, running a tool, or waiting on your approval. Steer it from the composer below.",children:r("span",{class:`agent-chip phase-${d.phase}`,"data-phase":d.phase,style:{"--identity-color":_o(d.sessionId)},children:[r("button",{type:"button",class:"agent-chip-initial","aria-label":`${d.label} session details`,"aria-expanded":e?.id===d.sessionId,"aria-haspopup":"dialog",onClick:(m)=>{m.stopPropagation(),t(e?.id===d.sessionId?null:{id:d.sessionId,button:m.currentTarget})},children:[Ud(d.label),r("span",{class:"agent-chip-dot","aria-hidden":"true"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("span",{class:"agent-chip-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("span",{class:"agent-chip-label",children:vi(d)},void 0,!1,void 0,this),r("span",{class:"agent-chip-who hud-collapsible-text",children:d.label},void 0,!1,void 0,this),r(DI,{session:d},void 0,!1,void 0,this),p>0&&r("span",{class:"agent-chip-workers",children:["+",p," worker",p===1?"":"s"]},void 0,!0,void 0,this),r("button",{type:"button",class:"agent-chip-end","aria-label":`End ${d.label} session`,onClick:(m)=>{m.stopPropagation(),ic({source:d.source,agentId:d.agentId})},children:r(Tt,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},d.sessionId,!1,void 0,this)})},void 0,!1,void 0,this),l.length>0&&r(_e,{label:`${i.length} agent sessions attached`,tapToOpen:!0,body:`${i.length} agents on this board — ${u}. The most active wear their own chips; the rest are here, and idle agents' cursors leave the board until they work again.`,children:r("span",{class:"agent-chip agent-chip-more","data-testid":"agent-chip-more",children:["+",l.length," · ",i.length," agents"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),e&&a.filter((d)=>d.sessionId===e.id).map((d)=>r(ia,{children:r("div",{ref:n,class:`agent-session-popover phase-${d.phase}`,role:"dialog","aria-label":`${d.label} session details`,style:{right:`${Math.max(12,window.innerWidth-e.button.getBoundingClientRect().right)}px`,top:`${e.button.getBoundingClientRect().bottom+8}px`},children:[r("div",{class:"agent-session-popover-head",children:[r("span",{class:"agent-chip-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("strong",{children:[d.label," · ",vi(d)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r(DI,{session:d,popover:!0},void 0,!1,void 0,this),r("button",{type:"button",class:"session-receipt-link",onClick:()=>{to.value=!0,t(null)},children:"Open session panel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},d.sessionId,!1,void 0,this))]},void 0,!0,void 0,this)}function DI({session:e,popover:t=!1}){let n=e.session,o=n?[["read",n.read.length],["created",n.created.length],["edited",n.edited.length],["pinned",n.pinned.length]].filter(([,l])=>l>0):[],i=Hn.value,s=i?.kind==="live"&&i.sessionId===e.sessionId;if(o.length===0&&!s&&!t)return null;let a=o.map(([l,c])=>`${c} ${l}`).join(" · ")||"nothing yet";if(t)return r(be,{children:[r("span",{class:"agent-session-counts",children:a},void 0,!1,void 0,this),r("button",{type:"button",role:"switch","aria-checked":s,class:`session-receipt-lens${s?" is-on":""}`,onClick:()=>sc(!s,{sessionId:e.sessionId}),children:[r("span",{class:"session-receipt-lens-track","aria-hidden":"true",children:r("span",{class:"session-receipt-lens-knob"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Dim untouched nodes"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return r("button",{type:"button",class:`agent-chip-touches${s?" is-on":""}`,"aria-pressed":s,"aria-label":`This session: ${o.map(([l,c])=>`${c} ${l}`).join(", ")||"nothing yet"}. ${s?"Show all cards":"Dim untouched cards"}`,onClick:(l)=>{l.stopPropagation(),sc(!s,{sessionId:e.sessionId})},children:a},void 0,!1,void 0,this)}function _O(){let e=To.value.length,t=e>0,n=rr(t?1000:0);if(!t)return null;let o=To.value.map((i)=>wp(i,n)).filter((i)=>i!==null).sort((i,s)=>i-s)[0];return r(_e,{label:"Approval gates waiting on you",body:"Open agent controls to approve or reject. Unanswered gates auto-hold when the countdown runs out, even with the session beta off.",children:r("button",{type:"button",class:"gate-badge",onClick:()=>to.value=!0,children:[e," gate",e===1?"":"s",o!==void 0&&` · ${kp(o)}`]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function CO(){let[e,t]=E(!1);if(!kt.value||xi.value)return null;return r(_e,{label:"Start an agent session",body:"Attaches a session to this board: the next agent that writes here is adopted into it, and you get the panel, composer, and receipt.",children:r("button",{type:"button",class:"start-session-btn","aria-label":"Start agent session beta",disabled:e,onClick:()=>{t(!0),_i().finally(()=>t(!1))},children:[r("span",{class:"start-session-dot","aria-hidden":"true"},void 0,!1,void 0,this),r("span",{class:"start-session-label",children:"Start agent session"},void 0,!1,void 0,this),r("span",{class:"beta-tag",children:"beta"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function BI(){let e=F(null);$e(()=>{let g=e.current,v=g?.querySelector(".top-bar-right");if(!g||!v)return;let b=()=>{let y=g.querySelector('.top-bar-more [aria-expanded="true"]');g.classList.remove("is-folded","is-compact");let k=()=>v.getBoundingClientRect().right>g.getBoundingClientRect().right-14;if(y||k())g.classList.add("is-folded");if(k())g.classList.add("is-compact")},x=new ResizeObserver(b);x.observe(g);let C=new MutationObserver(b);return C.observe(g,{childList:!0,characterData:!0,subtree:!0}),b(),()=>{x.disconnect(),C.disconnect()}},[]);let t=lo.value,n=un.value,o=Ae.value,i=Z.value.size,s=tt.value.size,a=Ys.value,l=Array.from(Z.value.values()).filter((g)=>g.type==="trace").length,[c,u]=E("");G(()=>{let g=!1;return Gt("/health").then((v)=>v.ok?v.json():null).then((v)=>{if(g||typeof v?.workspace!=="string"||!v.workspace)return;let b=v.workspace.replace(/[\\/]+$/,"").split(/[\\/]/).pop();if(b)u(b)}).catch(()=>{}),()=>{g=!0}},[]);let d=Pg.value,p=d??(t==="connected"&&!n?"syncing":t),m=Qn(),f=n?[`${i} node${i!==1?"s":""}`,...s>0?[`${s} edge${s!==1?"s":""}`]:[],...l>0?[`${l} trace${l!==1?"s":""}`]:a?["trace armed"]:[]].join(" · "):"Syncing canvas…",h=()=>{let g=Jt();ta(g.width,g.height)};return r("div",{class:"top-bar",ref:e,children:[r(_e,{label:`Canvas status: ${p}`,tapToOpen:!0,body:"Live updates stream in over SSE; amber means reconnecting.",align:"start",children:r("span",{class:`connection-dot ${d??t}`,"aria-label":`Canvas status: ${p}`},void 0,!1,void 0,this)},void 0,!1,void 0,this),r($I,{fallbackName:c||"PMX Canvas"},void 0,!1,void 0,this),m&&!pt.value&&r(go,{board:m},void 0,!1,void 0,this),r("span",{class:"top-bar-meta hud-collapsible-text",children:Cr.value?Cr.value.slice(0,12):"…"},void 0,!1,void 0,this),!pt.value&&r("span",{class:"top-bar-meta hud-collapsible-text",children:f},void 0,!1,void 0,this),r("span",{class:"top-bar-spacer"},void 0,!1,void 0,this),r("div",{class:"top-bar-right",children:[r(SO,{},void 0,!1,void 0,this),r(_O,{},void 0,!1,void 0,this),r(wT,{},void 0,!1,void 0,this),r(lI,{},void 0,!1,void 0,this),!nt()&&r(CO,{},void 0,!1,void 0,this),!pt.value&&r(be,{children:[r("div",{class:"top-bar-sep"},void 0,!1,void 0,this),r("div",{class:"top-bar-actions",children:[ie.value&&r(_e,{label:"Export board",body:"One HTML file of this board that anyone can open, no install needed.",children:r("button",{type:"button",class:"present-button",onClick:()=>{fs.value=!0},children:"Export"},void 0,!1,void 0,this)},void 0,!1,void 0,this),ie.value&&r(_e,{label:"Present board",body:"Arrow keys or Space step through stops; Esc exits. Without a saved tour, groups are read top-to-bottom, left-to-right.",children:r("button",{type:"button",class:"present-button",onClick:()=>{Ll()},children:"Present"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Zoom out",shortcut:Ht("−"),children:r("button",{type:"button",class:"top-bar-btn",onClick:()=>ci(0.8),"aria-label":"Zoom out",children:r(FS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Reset zoom",shortcut:Ht("0"),children:r("button",{type:"button",class:"top-bar-zoom-label",onClick:()=>Ar({x:0,y:0,scale:1},250),"aria-label":"Reset view",children:[Math.round(o.scale*100),"%"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Zoom in",shortcut:Ht("+"),children:r("button",{type:"button",class:"top-bar-btn",onClick:()=>ci(1.25),"aria-label":"Zoom in",children:r(HS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Fit all",shortcut:"F",align:"end",children:r("button",{type:"button",class:"top-bar-btn",onClick:h,"aria-label":"Fit canvas",children:r(ad,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(TO,{boardOpen:!!ie.value,onFit:h},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function TO({boardOpen:e,onFit:t}){let[n,o]=E(!1),i=F(null),s=F(null);$e(()=>{if(!n)return;let l=()=>[...i.current?.querySelectorAll('[role="menuitem"]')??[]];l()[0]?.focus();let c=(d)=>{if(d.key==="Escape")o(!1),s.current?.focus();else if(d.key==="ArrowDown"||d.key==="ArrowUp"){d.preventDefault();let p=l(),m=p.indexOf(document.activeElement),f=d.key==="ArrowDown"?m+1:m-1;p[(f+p.length)%p.length]?.focus()}},u=(d)=>{if(i.current&&!i.current.contains(d.target))o(!1)};return window.addEventListener("keydown",c),window.addEventListener("pointerdown",u),()=>{window.removeEventListener("keydown",c),window.removeEventListener("pointerdown",u)}},[n]);let a=(l)=>()=>{o(!1),l()};return r("div",{class:"top-bar-more",ref:i,children:[r("button",{ref:s,type:"button",class:"top-bar-btn","aria-label":"More: export, present, zoom, fit","aria-haspopup":"menu","aria-expanded":n,onClick:()=>o(!n),children:"⋯"},void 0,!1,void 0,this),n&&r("div",{class:"toolbar-menu top-bar-more-menu",role:"menu",children:[e&&r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>{fs.value=!0}),children:"Export board"},void 0,!1,void 0,this),e&&r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>void Ll()),children:"Present board"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>ci(1.25)),children:"Zoom in"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>ci(0.8)),children:"Zoom out"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>Ar({x:0,y:0,scale:1},250)),children:"Reset zoom"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(t),children:"Fit all"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Ci={status:{x:40,y:80,w:300,h:120},markdown:{x:380,y:80,w:720,h:600},context:{x:1130,y:80,w:320,h:400},"mcp-app":{x:380,y:720,w:960,h:600},webpage:{x:380,y:80,w:520,h:420},"json-render":{x:380,y:720,w:840,h:620},graph:{x:380,y:720,w:760,h:520},board:{x:380,y:80,w:360,h:160},ledger:{x:1130,y:520,w:320,h:280},trace:{x:40,y:900,w:200,h:56},file:{x:380,y:80,w:720,h:600},diff:{x:380,y:80,w:640,h:420},mermaid:{x:380,y:80,w:640,h:460},image:{x:380,y:80,w:720,h:520},html:{x:380,y:80,w:720,h:640},group:{x:220,y:60,w:840,h:560},prompt:{x:380,y:1260,w:520,h:400},response:{x:380,y:1480,w:720,h:400}};function yc(e,t,n,o={}){let i=Ci[t];return{id:e,type:t,position:o.position??{x:i.x,y:i.y},size:o.size??{width:i.w,height:i.h},zIndex:t==="status"?0:1,collapsed:!1,pinned:!1,data:n}}var Ti=null,bc=null,_p=0,Ii=null,IO=3000,EO=2000,AO=1000,RO=80,HI=5000,PO=1e4,vc=!1,Br=null,Na=null,Pa=null,hs=0,Ei=null;function NO(){if(nt())return"poll";if(typeof location>"u"||typeof window>"u")return null;let e=new URLSearchParams(location.search).get("transport");if(e==="poll"||e==="sse")return e;if(window.__PMX_AMP_ORB===!0)return"poll";return null}var Ma=new Map;function xc(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t).toString(36)}function Ep(e){if(!bc)return e;let t=bc.get(e.id);if(!t)return e;return{...e,position:t.position??e.position,size:t.size??e.size,collapsed:t.collapsed??e.collapsed,pinned:t.pinned??e.pinned}}function wc(e,t,n){return Ep(yc(e,t,n))}function MO(){return $d([...Z.value.values()],Ci.markdown.w,Ci.markdown.h)}function $a(){if(!Z.value.has("status-main"))Ir(wc("status-main","status",{phase:"idle",message:"",elapsed:0}))}function zO(e,t){let n=`md-${xc(e)}`;if(Z.value.get(n))Je(n,{path:e,title:t}),xt.value=n;else{let i=MO(),s=wc(n,"markdown",{path:e,title:t,content:"",rendered:""});s.position=i,Ir(s),$t(n)}}function $O(e){if(Z.value.get("context-main"))Je("context-main",{cards:e});else if(e.length>0){let o=wc("context-main","context",{cards:e});Ir(o)}}function LO(e){let t=e.url,n=`mcp-${xc(t)}`;if(Z.value.get(n))Je(n,e);else Ir(wc(n,"mcp-app",e)),$t(n)}function OO(e){let t=e.toolCallId,o=(typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null)??(t.startsWith("ext-app-")?t:`ext-app-${t}`);if(Z.value.get(o)){Je(o,e);return}let{serverName:s,toolName:a}=e;if(s&&a){for(let[v,b]of Z.value.entries())if(b.type==="mcp-app"&&b.data.mode==="ext-app"&&b.data.serverName===s&&b.data.toolName===a&&!b.data.toolResult){Je(v,{...e});return}}let{_x:l,_y:c,_width:u,_height:d}=e,p=Ci["mcp-app"],m=u??p.w,f=d??p.h,h=l===void 0||c===void 0?$d([...Z.value.values()],m,f):null,g=Ep(yc(o,"mcp-app",{mode:"ext-app",...e},{position:{x:l??h?.x??p.x,y:c??h?.y??p.y},size:{width:m,height:f}}));Ir(g),$t(o,{recordHistory:!1})}function DO(e){let t=e.startsWith("ext-app-")?e:`ext-app-${e}`;if(Z.value.has(t))return t;let n=`ext-app-${e}`;if(n!==t&&Z.value.has(n))return n;for(let[o,i]of Z.value.entries())if(i.type==="mcp-app"&&i.data.mode==="ext-app"&&i.data.toolCallId===e)return o;return null}function ZI(e){let t=typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null;if(t&&Z.value.has(t))return t;if(typeof e.toolCallId!=="string"||!e.toolCallId)return null;return DO(e.toolCallId)}function WI(e,t){if(typeof e!=="string"||!e)return null;if(typeof t!=="string"||!t)return null;let n=null;for(let[o,i]of Z.value.entries())if(i.type==="mcp-app"&&i.data.mode==="ext-app"&&i.data.serverName===e&&i.data.toolName===t&&!i.data.toolResult){if(n)return null;n=o}return n}function qI(e){if(Z.value.get("ledger-main"))Je("ledger-main",e);else{let o=wc("ledger-main","ledger",e);o.collapsed=!0,Ir(o)}}function Zg(e){if(!Jl(e))return;if(document.documentElement.setAttribute("data-theme",e),va(),Qt.value!==e)Qt.value=e}function BO(e){return e==="markdown"||e==="mcp-app"||e==="webpage"||e==="json-render"||e==="graph"||e==="board"||e==="prompt"||e==="response"||e==="status"||e==="context"||e==="ledger"||e==="trace"||e==="file"||e==="diff"||e==="mermaid"||e==="image"||e==="html"||e==="group"}function HO(e){return e==="relation"||e==="depends-on"||e==="flow"||e==="references"}function Wg(e){if(!e||typeof e!=="object")return null;let t=e;if(typeof t.x!=="number"||typeof t.y!=="number")return null;return{x:t.x,y:t.y}}function GI(e){if(!e||typeof e!=="object")return null;let t=e;if(typeof t.width!=="number"||typeof t.height!=="number")return null;return{width:t.width,height:t.height}}function FO(e){let t=Wg(e),n=GI(e);return t&&n?{...t,...n}:null}function jO(e){if(typeof e.id!=="string"||!e.id)return null;if(!BO(e.type))return null;let t=Wg(e.position),n=GI(e.size);if(!t||!n)return null;let o=e.data&&typeof e.data==="object"?Object.fromEntries(Object.entries(e.data)):{};return{id:e.id,type:e.type,position:t,size:n,zIndex:typeof e.zIndex==="number"?e.zIndex:1,collapsed:e.collapsed===!0,pinned:e.pinned===!0,contentRevision:typeof e.contentRevision==="number"?e.contentRevision:0,linksRevision:typeof e.linksRevision==="number"?e.linksRevision:0,...Ip(e.createdBy)?{createdBy:e.createdBy}:{},...Ip(e.lastEditedBy)?{lastEditedBy:e.lastEditedBy}:{},data:o}}function Ip(e){if(!e||typeof e!=="object")return!1;let t=e;return typeof t.actor==="string"&&typeof t.source==="string"}function UO(e){if(typeof e.id!=="string"||!e.id)return null;if(typeof e.from!=="string"||!e.from)return null;if(typeof e.to!=="string"||!e.to)return null;if(!HO(e.type))return null;return{id:e.id,from:e.from,to:e.to,...typeof e.toBoardId==="string"?{toBoardId:e.toBoardId}:{},type:e.type,...typeof e.kind==="string"?{kind:e.kind}:{},...typeof e.reason==="string"?{reason:e.reason}:{},...typeof e.label==="string"?{label:e.label}:{},...e.style==="solid"||e.style==="dashed"||e.style==="dotted"?{style:e.style}:{},...e.animated===!0?{animated:!0}:{},...typeof e.revision==="number"?{revision:e.revision}:{},...Ip(e.changedBy)?{changedBy:e.changedBy}:{},...typeof e.changedAt==="string"?{changedAt:e.changedAt}:{},...Ip(e.createdBy)?{createdBy:e.createdBy}:{},...typeof e.createdAt==="string"?{createdAt:e.createdAt}:{}}}function ZO(e){if(typeof e.id!=="string"||!e.id)return null;if(e.type!=="freehand"&&e.type!=="text")return null;if(!Array.isArray(e.points))return null;let t=e.points.map((o)=>Wg(o)).filter((o)=>o!==null),n=FO(e.bounds);if(t.length<(e.type==="text"?1:2)||!n)return null;return{id:e.id,type:e.type,points:t,bounds:n,color:typeof e.color==="string"?e.color:"#f97316",width:typeof e.width==="number"?e.width:4,...typeof e.text==="string"?{text:e.text}:{},...typeof e.label==="string"?{label:e.label}:{},createdAt:typeof e.createdAt==="string"?e.createdAt:""}}var FI="pmx-canvas-version-reload";function WO(e,t){if(typeof window>"u")return;let n=window,o=(s,a)=>typeof s==="string"&&s!==""&&s!=="unknown"&&typeof a==="string"&&a!==""&&a!=="unknown"&&s!==a;if(!o(e,n.__PMX_BOOT_SERVER_VERSION)&&!o(t,n.__PMX_BOOT_BUNDLE_STAMP))return;let i=`${String(e)}::${String(t)}`;try{if(window.sessionStorage.getItem(FI)===i)return;window.sessionStorage.setItem(FI,i)}catch{return}window.location.reload()}function qO(e){let t=bi.value[0]?.id;if(yC(e),Co.value&&bi.value[0]?.id!==t)Si()}function GO(e){FC(e)}var gs=0,jg=0,za=null;function KO(e){wf(e)}function VO(e){let t=za;if(za=null,e){if(t?.boardId===ie.value)Tp(t);return}let n=ie.value,o=++gs;if(bc=null,un.value=!1,zu(),hS(),Fu(),Kf({nodes:[],edges:[]}),t?.boardId===ie.value)Tp(t);if(ie.value===null)Yd();if(Hn.value?.kind==="receipt")Hn.value=null;lg({}),co.value=null,qg();let i=jg,s=Oo;jk(n).then((a)=>{if(o===gs&&i===jg)Tp({layout:a,boardId:n})}),pe("fetchPinnedContext","/api/canvas/pinned-context",{}).then((a)=>{if(o===gs&&s===Oo)KI({nodeIds:a.nodeIds})})}eS(VO);function XO(e){if(ko.value++,gs++,za=null,un.value=!1,typeof e.catalogEpoch==="string")Qk(e.catalogEpoch);if(!nt()&&typeof e.workbenchToken==="string")window.__PMX_WORKBENCH_TOKEN=e.workbenchToken;if(Cr.value=e.sessionId||"",uf(e.workspaceSettings),lo.value="connected",Al().then(ii),Xi.value+=1,WO(e.version,e.bundleStamp),nc(),Dr(),kl(),!ju&&!nt())Ik();if(pe("fetchHumanPresence","/api/canvas/human-presence",null).then(wf),qg().then(()=>{if(Co.value)Si()}),typeof e.theme==="string"&&!Ng())Zg(e.theme);if(e.ledgerSummary)qI(e.ledgerSummary)}function JO(e){if(typeof e.path!=="string"||!e.path)return;let t=e.path,n=(typeof e.title==="string"?e.title:"")||t.split("/").pop()||"Untitled";if(zO(t,n),e.ledgerSummary)qI(e.ledgerSummary)}function YO(e){$a(),Je("status-main",{message:typeof e.message==="string"?e.message:String(e.message??""),level:e.level??"ok",source:e.source})}function QO(e){$a(),Je("status-main",{phase:e.phase,detail:e.detail})}function eD(e){let t=e.cards??[];$O(t)}function tD(e){if(typeof e.url==="string"&&e.url)LO({url:e.url,sourceServer:e.sourceServer,sourceTool:e.sourceTool,inferredType:e.inferredType,trustedDomain:e.trustedDomain,hostMode:e.hostMode??"hosted"})}function nD(e){let t=e.sessions??[];for(let n of t){let o=n.url;if(!o)continue;let i=`mcp-${xc(o)}`;if(Z.value.has(i))Je(i,{sessionState:n.state,lastSeenAt:n.lastSeenAt})}}function oD(e){if(typeof e.url==="string"&&e.url){let t=`mcp-${xc(e.url)}`;if(Z.value.has(t))Je(t,{hostMode:"fallback",fallbackReason:e.reasonCode})}}function rD(e){let n=Z.value.get("context-main");if(!n)return;let o=(n.data.auxTabs??[]).concat(e);Je("context-main",{auxTabs:o})}function iD(e){if(Z.value.has("context-main"))if(e.mode==="all")Je("context-main",{auxTabs:[]});else{let o=Z.value.get("context-main");if(!o)return;let i=(o.data.auxTabs??[]).filter((s)=>s.id!==e.id);Je("context-main",{auxTabs:i})}}function sD(e){$a(),Je("status-main",{phase:"idle",lastCompletion:{tokenCount:e.tokenCount,artifactCount:e.artifactCount}})}function aD(e){$a(),Je("status-main",{phase:"tooling",detail:`${e.name}`,activeTool:e.name})}function lD(e){$a(),Je("status-main",{activeTool:null})}function cD(e){if(e.state==="active"&&e.path){let n=`md-${xc(e.path)}`;if(Z.value.has(n))Je(n,{reviewActive:!0})}}function uD(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;OO({toolCallId:e.toolCallId,...typeof e.nodeId==="string"&&e.nodeId.length>0?{nodeId:e.nodeId}:{},title:e.title,html:e.html,toolInput:e.toolInput,serverName:e.serverName,toolName:e.toolName,appSessionId:e.appSessionId,resourceUri:e.resourceUri,toolDefinition:e.toolDefinition,resourceMeta:e.resourceMeta,hostMode:"hosted",trustedDomain:!0,...e.chartConfig?{chartConfig:e.chartConfig}:{},...typeof e.x==="number"&&{_x:e.x},...typeof e.y==="number"&&{_y:e.y},...typeof e.width==="number"&&{_width:e.width},...typeof e.height==="number"&&{_height:e.height}})}function dD(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=ZI(e)??WI(e.serverName,e.toolName);if(!t)return;if(Z.value.has(t))Je(t,{html:e.html})}function pD(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=ZI(e)??WI(e.serverName,e.toolName);if(!t)return;if(Z.value.has(t)){if(e.success===!1){li(t);return}Je(t,{toolResult:Yh({result:e.result,success:typeof e.success==="boolean"?e.success:void 0,error:typeof e.error==="string"?e.error:void 0,content:typeof e.content==="string"?e.content:void 0,detailedContent:typeof e.detailedContent==="string"?e.detailedContent:void 0})})}}function mD(e){$a(),Je("status-main",{subagent:{state:e.state,name:e.agentDisplayName??e.agentName}})}function fD(e){let t=e.nodeId;if(!t)return;let n=e.text||"",{position:o,parentNodeId:i,contextNodeIds:s}=e;if(e.threadNodeId&&Z.value.has(e.threadNodeId)){let a=e.threadNodeId,l=Z.value.get(a);if(!l)return;let c=Array.isArray(l.data.turns)?[...l.data.turns]:[],u=c[c.length-1];if(!u||u.role!=="user"||u.text!==n)c.push({role:"user",text:n,status:"pending"});Je(a,{turns:c,threadStatus:"pending"});return}if(!Z.value.has(t)){let a=o??Ci.prompt;Ir(Ep(yc(t,"prompt",{text:n,turns:n?[{role:"user",text:n,status:"pending"}]:[],threadStatus:n?"pending":"draft",status:n?"pending":"draft",parentNodeId:i,contextNodeIds:s},{position:{x:a.x,y:a.y}}))),$t(t)}if(i&&Z.value.has(i))Ks({id:`edge-${i}-${t}`,from:i,to:t,type:"flow",style:"dashed"})}function hD(e){let{nodeId:t,status:n}=e;if(t&&Z.value.has(t))Je(t,{status:n})}function gD(e){let{responseNodeId:t,promptNodeId:n}=e;if(!t)return;let o=n?Z.value.get(n):void 0;if(o&&Array.isArray(o.data.turns)){Ma.set(t,n);let s=[...o.data.turns];s.push({role:"assistant",text:"",status:"streaming"}),Je(n,{turns:s,threadStatus:"streaming",_activeResponseId:t}),$t(n);return}let i=o?{x:o.position.x,y:o.position.y+o.size.height+24}:{x:Ci.response.x,y:Ci.response.y};if(!Z.value.has(t))Ir(Ep(yc(t,"response",{content:"",status:"streaming",promptNodeId:n},{position:i})));if(n)Ks({id:`edge-${n}-${t}`,from:n,to:t,type:"flow",animated:!0});$t(t)}function yD(e){let t=e.responseNodeId;if(!t)return;let n=Ma.get(t);if(n){let o=Z.value.get(n);if(o&&Array.isArray(o.data.turns)){let i=[...o.data.turns],s=i[i.length-1];if(s&&s.role==="assistant")s.text=e.content,s.status="streaming";Je(n,{turns:i,threadStatus:"streaming"})}return}if(!Z.value.has(t))return;Je(t,{content:e.content,status:"streaming"})}function vD(e){let t=e.responseNodeId;if(!t)return;let n=Ma.get(t);if(n){let s=Z.value.get(n);if(s&&Array.isArray(s.data.turns)){let a=[...s.data.turns],l=a[a.length-1];if(l&&l.role==="assistant")l.text=e.content,l.status="complete";Je(n,{turns:a,threadStatus:"answered",_activeResponseId:void 0})}Ma.delete(t);return}if(!Z.value.has(t))return;Je(t,{content:e.content,status:"complete"});let i=Z.value.get(t)?.data.promptNodeId;if(i){let s=`edge-${i}-${t}`,a=tt.value.get(s);if(a)SS(s),Ks({...a,animated:!1})}}function Tp(e){ko.value++;let t=e.layout;if(!t?.nodes)return;if(typeof e.boardGeneration==="number"){if(e.catalogEpoch!==In||$o!==null&&e.boardGeneration<$o)return;if($o===null||e.boardGeneration>$o){za=e;return}}if(e.boardId!==void 0&&e.boardId!==ie.value){za=e;return}jg+=1;let n=!un.value;un.value=!0;let o=t.nodes.map(jO).filter((l)=>l!==null),i=Array.isArray(t.edges)?t.edges.map(UO).filter((l)=>l!==null):Array.from(tt.value.values()),s=Array.isArray(t.annotations)?t.annotations.map(ZO).filter((l)=>l!==null):void 0,a=t.viewport?{x:typeof t.viewport.x==="number"?t.viewport.x:0,y:typeof t.viewport.y==="number"?t.viewport.y:0,scale:typeof t.viewport.scale==="number"?t.viewport.scale:1}:void 0;if(n)po();Kf({...a?{viewport:a}:{},nodes:o,edges:i,...s?{annotations:s}:{}},{applyViewport:n}),Cl({event:"canvas-layout-update",data:e}),Dr(1000)}function bD(e){if(e<=1)return 500;if(e===2)return 1000;return Math.min(2500,1500+(e-3)*500)}function xD(e){if(Jf())return;let t=e.nodeId;if(t&&Z.value.has(t)){if(e.noPan===!0){Er(t);return}$t(t)}}function wD(e){if(Jf()||e.clientId===ni)return;let t=e.viewport;if(!t)return;let n=typeof t.x==="number"?t.x:0,o=typeof t.y==="number"?t.y:0,i=typeof t.scale==="number"?t.scale:1;po(),qf({x:n,y:o,scale:i})}function kD(e){if(Do.value)return;if(!Ln.value&&e.present!==!0)return;let t=Su.safeParse(e.stop);if(t.success)RS(t.data)}function SD(){if(Do.value)return;Ln.value=!1,Qo.value=""}function _D(e){if(Do.value)return;let t=Su.safeParse(e.stop);if(!t.success)return;try{Yf(t.data,Ln.value?void 0:(n)=>{Ku(n,{recordHistory:!1})})}catch{let n=fl.safeParse(e.viewport);if(!n.success)return;po(),qf(n.data)}}function CD(e){if(Z.value.get("context-main"))Je("context-main",{currentTokens:e.currentTokens,tokenLimit:e.tokenLimit,messagesLength:e.messagesLength,utilization:e.utilization,nearLimit:e.nearLimit})}function TD(e){Ys.value=e.enabled===!0}function ID(e){if(typeof e.theme==="string"&&!Ng())Zg(e.theme)}function KI(e){ko.value++;let t=Array.isArray(e.nodeIds)?e.nodeIds.filter((n)=>typeof n==="string"):[];if(Vi===0)Uf(t);Cl({event:"context-pins-changed",data:e}),nc(),Dr()}function ED(){nc(),Dr()}var Cp=null,Ug=0;async function qg(){let e=++Ug,t=gs,n=await Wk();if(e===Ug&&t===gs)co.value=n}function jI(){if(Cp)clearTimeout(Cp);Ug+=1,Cp=setTimeout(()=>{if(Cp=null,qg(),Co.value)Si()},150)}function AD(e){let t=e.intent;if(!t||typeof t.id!=="string"||typeof t.kind!=="string"||typeof t.expiresAt!=="number")return;gk(t)}function RD(e){let t=typeof e.id==="string"?e.id:"";if(!t)return;if(e.settled===!0)vk(t,typeof e.nodeId==="string"?e.nodeId:void 0);else bf(t)}var VI={connected:XO,"workbench-open":JO,"canvas-status":YO,"execution-phase":QO,"context-cards":eD,"mcp-app-candidate":tD,"mcp-app-host-snapshot":nD,"mcp-app-host-fallback":oD,"aux-open":rD,"aux-close":iD,"assistant-complete":sD,"tool-start":aD,"tool-complete":lD,"review-state":cD,"subagent-status":mD,"ext-app-open":uD,"ext-app-update":dD,"ext-app-result":pD,"context-pins-changed":KI,"context-status-changed":ED,"knowledge-changed":()=>void Kt(),"lifecycle-changed":()=>void Kt(),"boards-changed":(e)=>{ai(e),Dr()},"canvas-layout-update":Tp,"canvas-focus-node":xD,"canvas-viewport-update":wD,"canvas-tour-step":kD,"canvas-tour-exit":SD,"canvas-camera-move":_D,"context-usage":CD,"trace-state":TD,"theme-changed":ID,"settings-changed":(e)=>uf(e.workspaceSettings),"canvas-prompt-created":fD,"canvas-prompt-status":hD,"canvas-response-start":gD,"canvas-response-delta":yD,"canvas-response-complete":vD,"ax-state-changed":jI,"ax-event-created":jI,"ax-intent":AD,"ax-intent-clear":RD,"agent-presence":qO,"human-presence":KO,"agent-session-ended":GO};function XI(e,t){let n=VI[e];if(!n)return;let o=n;try{o(t)}catch(i){console.warn(`[sse-bridge] Handler for "${e}" failed:`,i)}}function UI(){vc=!0,hs+=1;let e=hs;Na?.abort();let t=new AbortController;Na=t;let n=!nt();lo.value="connecting";let o=null,i=!1,s=async()=>{if(e!==hs)return;let a=new AbortController,l;try{let c=new URLSearchParams;if(Pa!==null){if(c.set("since",String(Pa)),n)c.set("waitMs",String(AO))}let u=Cr.value;if(u)c.set("session",u);let d=c.toString(),p=Oo,m=await Promise.race([(async()=>{let b=await Gt(`/api/workbench/poll${d?`?${d}`:""}`,{signal:AbortSignal.any([t.signal,a.signal])});if(!b.ok)throw Error(`poll failed with HTTP ${b.status}`);return await b.json()})(),new Promise((b,x)=>{l=setTimeout(()=>{a.abort(),x(Error("poll request timed out"))},PO)})]);if(e!==hs)return;if(!m.ok)throw Error("poll returned ok: false");let f=o;if(o=m.sessionId??null,f!==null&&m.sessionId&&f!==m.sessionId&&!m.snapshot){Pa=null,Br=setTimeout(()=>void s(),0);return}if(m.snapshot&&i)bc=Xf(),un.value=!1,Fu(),zu(),Ma.clear();let h=p===Oo&&Vi===0,g=!1,v=new Set;if(!m.snapshot&&un.value){let b;for(let x of m.events){let C=x.payload,y=C.catalogEpoch===In&&C.boardGeneration===$o&&(x.event==="boards-changed"?C.activeBoardId:C.boardId)===ie.value;if(x.event==="canvas-layout-update"&&y){if(b)v.add(b);b=x}else if(!(x.event==="boards-changed"&&y)&&!["agent-presence","human-presence","ax-intent","ax-intent-clear"].includes(x.event))b=void 0}}for(let b of m.events){if(v.has(b))continue;if(b.event==="context-pins-changed"&&!h){g=!0;continue}XI(b.event,b.payload)}if(g)Zf(),nc(),Dr();i=!0,Pa=m.seq,Ji.value=0,Yi.value=0,lo.value="connected",Br=setTimeout(()=>void s(),n?RO:EO)}catch(c){if(e!==hs)return;console.warn("[sse-bridge] poll transport error:",c),lo.value="disconnected",Ji.value+=1,Yi.value=HI,Br=setTimeout(()=>void s(),HI)}finally{clearTimeout(l)}};return s(),()=>{if(kl(),hs+=1,vc=!1,Pa=null,t.abort(),Na===t)Na=null;if(Br)clearTimeout(Br),Br=null}}function Gg(){if(gs++,za=null,CT(Zg),bc=Xf(),un.value=!1,Fu(),zu(),Ma.clear(),Ii)clearTimeout(Ii),Ii=null;let e=NO();if(e==="poll"||vc)return UI();let t=Cr.value,n=t?`/api/workbench/events?session=${t}`:"/api/workbench/events";lo.value="connecting";let o=new EventSource(n);Ti=o;let i=!1;if(Ei)clearTimeout(Ei);if(Ei=null,e!=="sse")Ei=setTimeout(()=>{if(Ei=null,i||Ti!==o)return;console.warn("[sse-bridge] No SSE event within watchdog window — switching to polling transport."),window.dispatchEvent(new Event("pmx-canvas-boot-extend")),o.close(),Ti=null,UI()},IO);for(let[s]of Object.entries(VI))o.addEventListener(s,(a)=>{if(Ti!==o)return;i=!0;try{XI(s,JSON.parse(a.data))}catch(l){console.warn(`[sse-bridge] Failed to parse "${s}" event:`,l)}});return o.onopen=()=>{if(Ti!==o)return;_p=0,Ji.value=0,Yi.value=0,lo.value="connected"},o.onerror=()=>{if(Ti!==o)return;lo.value="disconnected",o.close(),Ti=null,_p+=1;let s=bD(_p);Ji.value=_p,Yi.value=s,Ii=setTimeout(()=>{Ii=null,Gg()},s)},()=>{if(kl(),Ii)clearTimeout(Ii),Ii=null;if(Ei)clearTimeout(Ei),Ei=null;if(vc){if(hs+=1,vc=!1,Pa=null,Na?.abort(),Na=null,Br)clearTimeout(Br),Br=null}o.close(),Ti=null}}function ys(e,t){console.error(`[app] ${e} failed`,t)}var PD=Xe(()=>Z.value.size===0),JI=Xe(()=>{let e=Ct.value;return!!e&&!pt.value&&ie.value===e.boardId&&St===e.incarnation&&Z.value.has(e.nodeId)}),Kg=Xe(()=>Be.value&&JI.value);function YI(){let[e,t]=E(()=>window.innerWidth>=700),[n,o]=E(!1),[i,s]=E(!1),[a,l]=E(!1),[c,u]=E({}),[d,p]=E(!1),[m,f]=E(null),h=F(null),g=F(null),[v,b]=E(Jt),{menu:x,openNodeMenu:C,openCanvasMenu:y,openEdgeMenu:k,closeMenu:_}=AT(),A=un.value,w=Wn.value&&(ie.value===null||pt.value),M=or.value,B=kt.value,L=Co.value||To.value.length>0||ls.value.length>0||!!Io.value,Y=Kg.value;$e(()=>{if(!B){if(Hn.value=null,to.value=!1,document.activeElement?.closest(".command-bar, .session-panel, .agent-popover"))h.current?.focus({preventScroll:!0})}},[B]);let j=oe(()=>t((R)=>!R),[]),J=oe(()=>o((R)=>!R),[]),X=oe(()=>o(!1),[]),V=oe((R)=>f(R),[]),ee=oe((R)=>{rk(R),g.current=R},[]),he=oe((R,te)=>{Ar({x:R,y:te,scale:Ae.value.scale},200)},[]);return G(()=>Gg(),[]),G(()=>{let R=(te)=>{let O=te.detail;u(O??{}),l(!0)};return window.addEventListener("pmx-open-board-link",R),()=>window.removeEventListener("pmx-open-board-link",R)},[]),G(()=>{let R=null,te=()=>{if(R!==null)window.clearTimeout(R);R=window.setTimeout(()=>{R=null,ii()},400)};return window.addEventListener("resize",te),()=>{if(R!==null)window.clearTimeout(R);window.removeEventListener("resize",te)}},[]),$e(()=>{let R=(H)=>{let Me=(H.metaKey||H.ctrlKey)&&!H.altKey;if(d&&(H.key==="Escape"||H.key==="?"||H.key==="/"&&H.shiftKey)){H.preventDefault(),p(!1);return}if(pt.value||ie.value===null)return;if(H.defaultPrevented)return;if(Me&&H.key==="k"){H.preventDefault(),s((ve)=>!ve);return}if(H.key==="Escape"&&m){H.preventDefault(),f(null);return}if(H.key==="Escape"&&Kg.value){if(H.target?.closest('[role="menu"], [role="alertdialog"]'))return;H.preventDefault(),Ct.value=null;return}if(H.key==="Escape"&&Bt.value&&!Lo.value){H.preventDefault(),Rr();return}if(H.key==="Escape"&&i){H.preventDefault(),s(!1);return}let je=H.target,He=je?.tagName;if(He==="INPUT"||He==="TEXTAREA"||je?.isContentEditable)return;if(je?.closest('[role="menu"]'))return;let Re=je?.closest('[role="dialog"]');if((H.key==="Tab"||H.key.startsWith("Arrow"))&&je?.closest(".tool-rail, .top-bar"))return;if(H.key===" "&&!H.repeat&&!Me&&!Re){H.preventDefault(),zl.value=!0;return}if(H.key==="?"||H.key==="/"&&H.shiftKey){H.preventDefault(),p((ve)=>!ve);return}if(Me&&(H.key==="z"||H.key==="Z"))H.preventDefault(),gg(H.shiftKey);else if(Me&&(H.key==="y"||H.key==="Y"))H.preventDefault(),gg(!0);else if(Me&&H.key==="0")H.preventDefault(),Ar({x:0,y:0,scale:1},250);else if(Me&&(H.key==="="||H.key==="+"))H.preventDefault(),ci(1.25);else if(Me&&H.key==="-")H.preventDefault(),ci(0.8);else if(Re)return;else if(H.key==="Escape"){if(!ar(H))return;if(H.preventDefault(),Eo.value?.boardId===ie.value)Eo.value=null;No.value="All",$n(),xt.value=null,_()}else if(H.key==="Tab")H.preventDefault(),IS(H.shiftKey?-1:1);else if(H.key==="Delete"||H.key==="Backspace"){if(_r.value!==null){let D=_r.value;H.preventDefault(),_r.value=null,Xu(D).catch((re)=>ys("delete-edge",re));return}let ve=rt.value.size>0?[...rt.value]:xt.value?[xt.value]:[];if(ve.length===0)return;H.preventDefault();for(let D of ve)ri(D).catch((re)=>ys("delete",re));$n(),xt.value=null}else if(xt.value&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(H.key)){H.preventDefault();let ve=H.key.replace("Arrow","").toLowerCase();ES(ve)}else if(!Me&&!H.altKey){let ve=H.key.toLowerCase();if(ve==="v"&&!H.shiftKey)qn.value="select";else if(ve==="c"&&!H.shiftKey&&!Me)H.preventDefault(),qn.value=qn.value==="connect"?"select":"connect";else if(ve==="m"&&!H.shiftKey)H.preventDefault(),Ao({type:"markdown",title:"New note",width:520,height:360}).catch((D)=>ys("create markdown",D));else if(ve==="a"&&!H.shiftKey)H.preventDefault(),f((D)=>D==="pen"?null:"pen");else if(ve==="g"&&!H.shiftKey){H.preventDefault();let D=Array.from(rt.value);if(D.length>=2)qs({title:"Group",childIds:D}).catch((re)=>ys("group selection",re)),$n();else Ao({type:"group",title:"Group"}).catch((re)=>ys("create group",re))}else if(ve==="g"&&H.shiftKey){H.preventDefault();for(let D of bS())li(D),Gs(D).catch((re)=>ys("ungroup",re));$n()}else if(ve==="i"&&!H.shiftKey)H.preventDefault(),ps("image");else if(ve==="w"&&!H.shiftKey)H.preventDefault(),ps("webpage");else if(ve==="h"&&!H.shiftKey)H.preventDefault(),Ao({type:"html",title:"HTML surface"}).catch((D)=>ys("create html",D));else if(ve==="f"&&H.shiftKey)H.preventDefault(),ps("file");else if(ve==="f"&&!H.shiftKey){H.preventDefault();let D=Jt();ta(D.width,D.height)}}},te=(H)=>{if(H.key===" ")zl.value=!1},O=()=>{zl.value=!1};return document.addEventListener("keydown",R),document.addEventListener("keyup",te),window.addEventListener("blur",O),()=>{document.removeEventListener("keydown",R),document.removeEventListener("keyup",te),window.removeEventListener("blur",O)}},[m,_,i,d]),G(()=>{let R=window.setTimeout(()=>void ii(),250);return()=>window.clearTimeout(R)},[M]),$e(()=>{let R=g.current;if(!R)return;let te=new ResizeObserver(()=>{b(Jt()),ii();let O=Ct.value;if(O&&Kg.value)$t(O.nodeId,{recordHistory:!1})});return te.observe(R),()=>te.disconnect()},[]),G(()=>{if(!A)return;let R=window.__pmxCanvasBootstrapReady;if(typeof R==="function")R()},[A]),r("div",{class:`app-shell${Ln.value?" is-presenting":""}`,"data-session-active":M?"true":"false",children:[r(MS,{},void 0,!1,void 0,this),r(dT,{},void 0,!1,void 0,this),r(MT,{minimapVisible:e,onToggleMinimap:j,snapshotOpen:n,onToggleSnapshot:J,snapshotBtnRef:h,onOpenPalette:()=>s(!0),onOpenShortcuts:()=>p((R)=>!R),annotationTool:m,onSetAnnotationTool:V},void 0,!1,void 0,this),r("div",{class:"app-main",children:[r(BI,{},void 0,!1,void 0,this),r(kT,{},void 0,!1,void 0,this),r("div",{class:`workspace${Y?" is-reviewing":""}`,children:[r("div",{class:"canvas-region",ref:ee,children:[!pt.value&&r(gT,{onNodeContextMenu:C,onCanvasContextMenu:y,onEdgeContextMenu:k,annotationMode:m!==null,annotationTool:m},void 0,!1,void 0,this),r(XS,{},void 0,!1,void 0,this),r(WC,{},void 0,!1,void 0,this),!w&&r(qC,{},void 0,!1,void 0,this),!w&&r(cT,{},void 0,!1,void 0,this),r(VS,{},void 0,!1,void 0,this),r(cI,{},void 0,!1,void 0,this),r(uI,{},void 0,!1,void 0,this),w?r(sI,{},void 0,!1,void 0,this):A&&PD.value&&qt.value.size===0&&r(zT,{onOpenPalette:()=>s(!0)},void 0,!1,void 0,this),!w&&rt.value.size>0&&r(xI,{},void 0,!1,void 0,this),!w&&!B&&r(xT,{},void 0,!1,void 0,this),!w&&Co.value&&!nt()&&r(yT,{},void 0,!1,void 0,this),!w&&r(RI,{onOpenSnapshots:()=>o(!0)},void 0,!1,void 0,this),r(YS,{},void 0,!1,void 0,this),!pt.value&&r(aI,{},void 0,!1,void 0,this),!w&&Bt.value&&r(hI,{},void 0,!1,void 0,this),r(zI,{open:n&&!pt.value,onClose:X,anchorRef:h},void 0,!1,void 0,this),e&&!w&&r(bI,{viewport:Ae,nodes:Z,edges:tt,onNavigate:he,containerWidth:v.width,containerHeight:v.height},void 0,!1,void 0,this)]},void 0,!0,void 0,this),JI.value&&r(ET,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),M&&r(II,{},void 0,!1,void 0,this),!M&&L&&r(TI,{},void 0,!1,void 0,this),!pt.value&&x&&r(RT,{menu:x,onClose:_},void 0,!1,void 0,this),!pt.value&&i&&r(TT,{onClose:()=>s(!1),onToggleMinimap:j},void 0,!1,void 0,this),!pt.value&&a&&r(IT,{...c,onClose:()=>l(!1)},void 0,!1,void 0,this),d&&r(PI,{onClose:()=>p(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var ND=P({x:Ee(),y:Ee()}),mne=P({boardId:z().nullable(),boardName:z(),boards:Pe(P({id:z(),name:z()})),revision:z(),nodes:Pe(P({id:z(),type:z(),title:z(),text:z(),contentRevision:Ee().int().nonnegative(),editableContent:z().optional(),position:ND,size:P({width:Ee(),height:Ee()}),image:z().optional()})),edges:Pe(P({id:z(),from:z(),to:z(),label:z()})),pinnedNodeIds:Pe(z())});function QI(e,t,n=[]){let o=new Set(e.nodes.map((l)=>l.id)),i=new Set(t.filter((l)=>o.has(l)).slice(0,20)),s=new Set(e.pinnedNodeIds.filter((l)=>o.has(l)).slice(0,20)),a=new Set(n.filter((l)=>o.has(l)).slice(0,20));return{boardId:e.boardId,boardName:e.boardName,selectedNodeIds:[...i],focusedNodeIds:[...a],pinnedNodeIds:[...s],nodes:e.nodes.filter((l)=>i.has(l.id)||s.has(l.id)||a.has(l.id)).map((l)=>({id:l.id,type:l.type,title:l.title,contentRevision:l.contentRevision,text:l.text.slice(0,700)}))}}var Ai=new Zm({name:"PMX Canvas",version:"1.0.0"},{availableDisplayModes:["inline","fullscreen"]}),MD=P({status:Ee(),body:z(),contentType:z(),encoding:rn(["text","base64"])});bk(async(e,t)=>{let n=typeof e==="string"?e:e instanceof URL?e.toString():e.url,o=(t?.method??(e instanceof Request?e.method:"GET")).toUpperCase();if(t?.body!==void 0&&typeof t.body!=="string")return Response.json({ok:!1,error:"Document uploads require the local PMX workbench."},{status:403});t?.signal?.throwIfAborted();let i=await Ai.callServerTool({name:"pmx_workbench_request",arguments:{path:n,method:o,...t?.body===void 0?{}:{body:t.body},expectedBoardId:ie.value}});t?.signal?.throwIfAborted();let s=MD.parse(i._meta?.response),a=s.encoding==="base64"?Uint8Array.from(atob(s.body),(l)=>l.charCodeAt(0)):s.body;return new Response(o==="HEAD"||s.status===204?null:a,{status:s.status,headers:{"Content-Type":s.contentType}})});var zD=P({focus:Pe(z())});function $D(){let e=zD.safeParse(co.value);return QI({boardId:ie.value,boardName:Ge.value.find((t)=>t.id===ie.value)?.name??"Home",pinnedNodeIds:[...ht.value],nodes:[...Z.value.values()].map((t)=>({id:t.id,type:t.type,title:typeof t.data.title==="string"?t.data.title:t.type,contentRevision:t.contentRevision??0,text:_u(t)}))},[...rt.value],e.success?e.data.focus:[])}function LD(){let[e,t]=E(""),[n,o]=E(0),i=F(Promise.resolve()),s=$D(),a=JSON.stringify(s),l=F(a);l.current=a;let c=Ai.getHostCapabilities(),u=Wn.value;return G(()=>{if(!u||!c?.updateModelContext||e===a)return;let d=!1,p;return i.current=i.current.then(async()=>{if(d||l.current!==a)return;if(t(""),await Ai.updateModelContext({structuredContent:s}),d||l.current!==a)return;t(a)}).catch(()=>{if(!d&&l.current===a)p=setTimeout(()=>o((m)=>m+1),2000)}),()=>{d=!0,clearTimeout(p)}},[a,u,n]),r("div",{class:"pmx-host-app",children:r(YI,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)}Ai.ontoolresult=()=>{};Ai.connect().then(async()=>{if(!Ai.getHostCapabilities()?.serverTools)throw Error("This host does not support app tool calls.");if(Ai.getHostCapabilities()?.downloadFile)xk((e)=>Ai.downloadFile({contents:[{type:"resource",resource:{uri:`file:///${encodeURIComponent(e.name)}`,mimeType:e.mimeType,text:e.text}}]}));await i_(),ul(r(LD,{},void 0,!1,void 0,this),document.getElementById("app"))}).catch((e)=>{document.getElementById("app").textContent=`Could not connect PMX: ${String(e)}`});})();
|
|
10177
10177
|
</script></body></html>
|