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.
Files changed (56) hide show
  1. package/.github/extensions/pmx-canvas/runtime.json +1 -1
  2. package/.github/extensions/pmx-canvas/tools.json +9278 -2014
  3. package/CHANGELOG.md +22 -1
  4. package/dist/canvas/index.js +1 -1
  5. package/dist/canvas/mcp-app.html +1 -1
  6. package/dist/types/mcp/canvas-access.d.ts +1 -12
  7. package/dist/types/mcp/resource-subscriptions.d.ts +7 -0
  8. package/dist/types/mcp/server.d.ts +2 -0
  9. package/dist/types/server/ax-wait.d.ts +1 -0
  10. package/dist/types/server/canvas-operations.d.ts +1 -0
  11. package/dist/types/server/index.d.ts +3 -3
  12. package/dist/types/server/operations/http.d.ts +10 -0
  13. package/dist/types/server/operations/index.d.ts +2 -2
  14. package/dist/types/server/operations/invoker.d.ts +4 -3
  15. package/dist/types/server/operations/mcp-contracts.d.ts +20 -0
  16. package/dist/types/server/operations/mcp.d.ts +2 -0
  17. package/dist/types/server/operations/ops/batch.d.ts +1 -0
  18. package/dist/types/server/operations/registry.d.ts +2 -2
  19. package/dist/types/server/operations/types.d.ts +12 -2
  20. package/dist/types/server/server.d.ts +2 -0
  21. package/dist/types/server/webpage-node.d.ts +1 -0
  22. package/docs/api-reference.md +2 -2
  23. package/docs/cli.md +1 -1
  24. package/docs/http-api.md +31 -0
  25. package/docs/mcp.md +93 -21
  26. package/docs/plans/plan-019-post-0.9-roadmap.md +123 -6
  27. package/docs/sdk.md +5 -2
  28. package/package.json +1 -1
  29. package/plugins/pmx-canvas/com.github.copilot/extensions/pmx-canvas/runtime.json +1 -1
  30. package/plugins/pmx-canvas/plugin.json +1 -1
  31. package/plugins/pmx-canvas/runtime.json +1 -1
  32. package/plugins/pmx-canvas/tools.json +9278 -2014
  33. package/skills/pmx-canvas/SKILL.md +9 -4
  34. package/skills/pmx-canvas/references/full-reference.md +35 -2
  35. package/skills/pmx-canvas/references/installing-pmx-canvas.md +7 -7
  36. package/src/client/canvas/ToolRail.tsx +2 -0
  37. package/src/mcp/canvas-access.ts +6 -47
  38. package/src/mcp/resource-subscriptions.ts +181 -0
  39. package/src/mcp/server.ts +185 -219
  40. package/src/server/ax-wait.ts +21 -6
  41. package/src/server/canvas-operations.ts +6 -2
  42. package/src/server/index.ts +12 -4
  43. package/src/server/operations/http.ts +69 -21
  44. package/src/server/operations/index.ts +8 -1
  45. package/src/server/operations/invoker.ts +53 -5
  46. package/src/server/operations/mcp-contracts.ts +339 -0
  47. package/src/server/operations/mcp.ts +153 -18
  48. package/src/server/operations/ops/ax-await.ts +18 -10
  49. package/src/server/operations/ops/ax-read.ts +2 -0
  50. package/src/server/operations/ops/ax-timeline.ts +2 -2
  51. package/src/server/operations/ops/batch.ts +27 -8
  52. package/src/server/operations/ops/nodes.ts +18 -3
  53. package/src/server/operations/registry.ts +24 -4
  54. package/src/server/operations/types.ts +16 -2
  55. package/src/server/server.ts +10 -0
  56. package/src/server/webpage-node.ts +9 -4
@@ -391,4 +391,4 @@ Input: ${JSON.stringify(ee.recipe.input??null)}
391
391
  Prompt: ${ee.recipe.prompt}
392
392
  Regeneration is not validation. Preserve source observations and report evidence separately.`);b(!1),C(A?"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((A)=>r("div",{class:"lifecycle-history",children:[r("strong",{children:[A.outcome,!A.applied?" · not applied":""]},void 0,!0,void 0,this),r("span",{children:[he(A.when)," · ",A.who.actor," · ",A.who.source]},void 0,!0,void 0,this),r("p",{children:A.evidence||"No evidence"},void 0,!1,void 0,this)]},A.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 bT(){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 Me(()=>{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 hL="#4bbcFF",gL=[{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 xT({menu:e,onClose:t}){let n;if(e.kind==="node"){let l=H.value.get(e.nodeId);if(!l)return null;n=kL(l)}else if(e.kind==="edge"){let l=e.edgeId,c=et.value.get(l),u=wt;n=[{label:"Relation kind…",render:()=>r("label",{class:"relation-kind-control",children:["Kind"," ",r("select",{"aria-label":"Relation kind",value:c?Gn(c):"",onChange:(d)=>{let p=d.currentTarget.value;if(p==="__custom__")t(),On("Relation kind","An open kind, such as supports").then((f)=>{if(f?.trim()&&u===wt)Fi(l,{kind:f.trim()})});else Fi(l,{kind:p})},children:[[...new Set([...(Yn()?.relationVocabulary??Kl).map((d)=>d.kind),...c?[Gn(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===wt)Fi(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!==wt)return;Fi(l,{label:d})})}},{separator:!0},...["flow","depends-on","relation","references"].map((d)=>({label:`${c?.type===d?"✓":" "} ${d}`,action:()=>void Fi(l,{type:d})})),{separator:!0},...["solid","dashed","dotted"].map((d)=>({label:`${(c?.style??"solid")===d?"✓":" "} ${d}`,action:()=>void Fi(l,{style:d})})),{separator:!0},{label:"Delete edge",danger:!0,action:()=>void wu(l)}]}else n=wL(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 yL(e){return(typeof e.data.path==="string"?e.data.path.trim():"")||null}function rp(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 wT(e){if(typeof e.data.color!=="string"||!e.data.color.trim())return null;return rp(e.data.color)}function vL(e){let t=wT(e);return t&&/^#[0-9a-f]{6}$/.test(t)?t:rp(hL)}function Cg(e,t){let n=t?rp(t):null;un(e.id,{data:{...e.data,color:n}}),ln(e.id,{data:{color:n}})}function bL(e,t){let n=wT(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:()=>{Cg(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:gL.map((o)=>{let i=rp(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:()=>{Cg(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:vL(e),onClick:(o)=>o.stopPropagation(),onInput:(o)=>{Cg(e,o.currentTarget.value),t()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Ig(e,t,n,o){return{x:e-n/2,y:t-o/2}}function xL(e,t){return e.trim().replace(/[?#].*$/,"").split("/").filter(Boolean).at(-1)||t}async function Tg(e){let t=await On(e.promptLabel,e.placeholder??"");if(!t)return;let n=t.trim();if(!n)return;let o=Ig(e.canvasX,e.canvasY,e.width,e.height);if(!(await No({type:e.type,...e.type!=="webpage"?{title:xL(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 wL(e,t){return[{label:"New note",action:()=>{let i=Ig(e,t,520,360);No({type:"markdown",title:"New note",x:i.x,y:i.y,width:520,height:360})}},{label:"Open webpage...",action:()=>{Tg({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:()=>{Tg({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:()=>{Tg({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=Ig(e,t,600,400);Ns({title:"Group",x:i.x,y:i.y,width:600,height:400})}}]}function kL(e){let t=[],n=yL(e);if(Oe.value)t.push({label:"Review",action:()=>Es(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;ln(e.id,{title:c.trim()})})}}),Ga.has(e.type))t.push({label:"Expand",shortcut:"⤢",action:()=>xo(e.id)});if(t.push({label:e.collapsed?"Expand":"Collapse",action:()=>Hi(e.id)}),od(e))t.push({label:"Open in new tab",action:()=>void rd(e)});let o=kt.value.has(e.id);t.push({label:o?"Unpin from context":"Pin as context",action:()=>lo(e.id)}),t.push({label:e.pinned?"Unlock position":"Lock position (no auto-arrange)",action:()=>{let c=!e.pinned;un(e.id,{pinned:c}),ln(e.id,{pinned:c}),dn()}});let i=ul.value;if(i&&i.from!==e.id){let c=H.value.get(i.from),u=c?(c.data.title||c.id).slice(0,20):i.from;t.push({label:`Connect from "${u}"`,action:()=>{yr(i.from,e.id,"relation"),ul.value=null}})}t.push({label:i?"Connect from here (replace)":"Connect from here",action:()=>{ul.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(et.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:()=>{yu(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)=>bL(e,u)}),c.length>0)t.push({label:`Ungroup (${c.length} node${c.length!==1?"s":""})`,action:()=>{ei(e.id),Ms(e.id)}})}let a=typeof e.data.parentGroup==="string"?e.data.parentGroup:null,l=a?H.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:()=>{xu(l.id,u)}})}return t.push({separator:!0}),t.push({label:e.type==="group"?"Delete frame (children stay)":"Delete",danger:!0,action:()=>{Xr(e.id)}}),t}function kT({onClose:e}){let t=D(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(Mr,{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}
393
393
 
394
- ${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(ri,{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 ec(e,t){console.error(`[tool-rail] ${e} failed`,t)}function as(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;Eo({type:e,content:n}).catch((o)=>ec(`create ${e}`,o))})}function to({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})},f=()=>d(null),m=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":m,"aria-pressed":i===void 0?void 0:i,onClick:(h)=>{f(),a(h)},onPointerEnter:p,onPointerLeave:f,onFocus:p,onBlur:f,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 rr({label:e,description:t,hint:n,beta:o,toggle:i=o,checked:s,disabled:a,onClick:l}){let c=wy(),[u,d]=E(null),p=(m)=>d(m.currentTarget.getBoundingClientRect()),f=()=>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:f,onFocus:p,onBlur:f,onClick:()=>{if(a)return;f(),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(Ws,{children:r("span",{id:c,class:"toolbar-tooltip settings-tooltip",role:"tooltip",ref:(m)=>{if(!m)return;let h=window.innerWidth-u.right>=m.offsetWidth+20;m.style.left=`${h?u.right+10:Math.max(12,Math.min(u.left,window.innerWidth-m.offsetWidth-12))}px`,m.style.top=`${Math.max(12,Math.min(h?u.top:u.top-m.offsetHeight-8,window.innerHeight-m.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 ST({minimapVisible:e,onToggleMinimap:t,snapshotOpen:n,onToggleSnapshot:o,snapshotBtnRef:i,onOpenPalette:s,onOpenShortcuts:a,annotationTool:l,onSetAnnotationTool:c}){let u=Wn.value,d=Ds.value,p=Array.from(H.value.values()).filter((V)=>V.type==="trace").length,f=et.value.size,[m,h]=E(!1),[g,v]=E(!1),[b,x]=E(!1),C=async(V)=>{if(g||!Wr.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]:!Wr.value[V]})});x(ee.ok!==!0)}finally{v(!1)}},[y,k]=E(null),[_,I]=E(null),w=D(null),P=D(null),L=(V)=>{if(y){k(null);return}let ee=V.currentTarget.getBoundingClientRect();I({bottom:ee.bottom,right:ee.right}),k("settings")},N=(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;Me(()=>{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 B=(V)=>{op(),document.documentElement.setAttribute("data-theme",V),la(),Qt.value=V,hu(V),k(null)},J=fh(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)=>ec("sendIntent",he))};return r(be,{children:[r("div",{class:"tool-rail",ref:w,role:"toolbar","aria-label":"Canvas tools","aria-orientation":"vertical",children:[r(to,{label:"Home",ariaLabel:"PMX Canvas — Home",onClick:()=>{k(null),Mn(null).catch((V)=>ec("openHome",V))},children:r("span",{class:"rail-brand",children:r(zu,{size:22},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),!ut.value&&r(be,{children:[r("div",{class:"rail-divider"},void 0,!1,void 0,this),r(to,{label:"Select",shortcut:"V",active:u==="select",onClick:()=>Wn.value="select",children:r(bS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{label:"Pan",shortcut:"Space",active:u==="pan",onClick:()=>Wn.value="pan",children:r(xS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{label:"Connect",shortcut:"C",active:u==="connect",onClick:()=>Wn.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(to,{label:"Markdown note",shortcut:"M",onClick:()=>void Eo({type:"markdown",title:"New note",width:520,height:360}).catch((V)=>ec("create markdown",V)),children:r(ni,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{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:()=>P.current?.click(),children:r(dS,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("input",{ref:P,type:"file",hidden:!0,multiple:!0,"aria-label":"Attach files",onChange:(V)=>{let ee=Jt(),he=Ee.value;ua(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(to,{label:"Webpage",shortcut:"W",onClick:()=>as("webpage"),children:r(Us,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{label:"Group",shortcut:"G",onClick:()=>void Eo({type:"group",title:"Group"}).catch((V)=>ec("create group",V)),children:r(Sm,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{label:"Draw",shortcut:"A",active:l==="pen",onClick:()=>c(l==="pen"?null:"pen"),children:r(gS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{label:"Text note",active:l==="text",onClick:()=>c(l==="text"?null:"text"),children:r(vS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{label:"Eraser",active:l==="eraser",onClick:()=>c(l==="eraser"?null:"eraser"),children:r(yS,{},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),!ut.value&&r(to,{label:"Search & commands",shortcut:Ft("K"),onClick:s,children:r(Mu,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),!ut.value&&r(to,{label:"Arrange",detail:f>0?"graph-aware":"grid",onClick:()=>f>0?Eu():Iu(),children:r(Tr,{},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(to,{label:"Settings",detail:"Appearance, board tools, beta features, and feedback",ariaLabel:"Settings",menuOpen:y!==null,active:y!==null||n,onClick:L,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(rr,{label:"Theme",description:"Choose the canvas appearance. Your choice is saved with the board.",hint:`${ea[J].label} ›`,onClick:()=>k("theme")},void 0,!1,void 0,this),!ut.value&&r(be,{children:[r(rr,{label:"Snapshots",description:"Save a board checkpoint, compare changes, or restore an earlier version.",onClick:N(o)},void 0,!1,void 0,this),r(rr,{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:N(t)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(rr,{label:"Keyboard shortcuts",description:"See shortcuts for creating cards, selecting, navigating, and editing the canvas.",hint:"?",onClick:N(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(rr,{label:"Agent sessions",beta:!0,checked:xt.value,disabled:!Wr.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(rr,{label:"Knowledge lifecycle",beta:!0,checked:Oe.value,disabled:!Wr.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),!xt.value&&(fa.value.length>0||Co.value.length>0||os.value.length>0||To.value)&&r(rr,{label:"Agent controls",description:"Review pending approvals, inspect or clear the write scope, or end an existing attachment without enabling the session beta.",onClick:N(()=>eo.value=!0)},void 0,!1,void 0,this),r("div",{class:"toolbar-menu-divider",role:"separator"},void 0,!1,void 0,this),!tt()&&!ut.value&&r(be,{children:[r(rr,{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(rr,{label:"Clear trace",description:"Remove recorded execution traces from this board without changing whether trace capture is enabled.",onClick:N(()=>X("trace-clear"))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(rr,{label:"Send feedback",description:"Report a problem or suggestion. Review the feedback before sending.",onClick:N(()=>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),ph.map((V)=>r("button",{type:"button",role:"menuitemradio","aria-checked":J===V,class:`toolbar-menu-item${J===V?" active":""}`,onClick:()=>B(V),children:[r("span",{class:"theme-swatch",style:{background:ea[V].swatchBg},children:r("span",{class:"theme-swatch-dot",style:{background:ea[V].swatchAccent}},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{children:ea[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),m&&r(kT,{onClose:()=>h(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function _T({onOpenPalette:e}){let t=D(null),n=()=>{Eo({type:"markdown",title:"New note",width:520,height:360}).catch(()=>{})},o=async(i)=>{if(!i||i.length===0)return;let s=Zr(),a=Ee.value;await ua(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:()=>as("webpage"),children:[r(Us,{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:Ft("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(ni,{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),xt.value&&r("button",{type:"button",class:"empty-state-action is-agent",onClick:()=>void vi(),children:[r(Zs,{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 · ",Ft("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 ir(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 CT="From old snapshots";function ip(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 tc(e){return e.split("/").map((t,n,o)=>o.slice(0,n+1).join("/"))}function TT({board:e,folders:t,onClose:n}){let o=D(null),[i,s]=E(e.folder??""),[a,l]=E(""),[c,u]=E(!1),[d,p]=E("");bn(o,!0),q(()=>{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 f=a.trim()?[i,a.trim()].filter(Boolean).join("/"):i,m=async()=>{let h;try{if(a.includes("/"))throw Error("Use one folder name; choose its parent above.");h=ip(f)}catch(g){p(g instanceof Error?g.message:String(g));return}if(u(!0),p(""),await vr(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:f||"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||f===(e.folder??""),onClick:()=>void m(),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 IT({board:e,onClose:t}){let n=D(null),o=D(null),[i,s]=E(null),[a,l]=E(new Set),[c,u]=E(`${e.name} copy`),[d,p]=E(!0),[f,m]=E(!0),[h,g]=E(!1),[v,b]=E(""),[x,C]=E(!1);return bn(n,!0,{initial:o}),q(()=>{let k=!0;return Ak(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((I)=>I.reusable).map((I)=>I.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:Ho,onSubmit:async(k)=>{if(k.preventDefault(),!c.trim()||!i)return;C(!0),b("");let _=await Rk({sourceBoardId:e.id,name:c.trim(),...e.folder?{folder:e.folder}:{},nodeIds:[...a],includeReadme:d,includeStructure:f});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 I=new Set(a);_.currentTarget.checked?I.add(k.id):I.delete(k.id),l(I)}},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:f,onChange:(k)=>m(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 sp({children:e,initiallyCollapsed:t=!1,reveal:n=0}){let o=D(null),[i,s]=E(280),[a,l]=E(400),[c,u]=E(t),d=D(null);return Me(()=>{if(n)u(!1)},[n]),Me(()=>{let p=o.current.closest(".home-memory"),f=p.querySelector(".home-memory-stage"),m=p.closest(".canvas-region"),h=p.querySelector(".home-memory-toolbar"),g=p.querySelector(".home-memory-legend"),v=()=>{m?.style.setProperty("--home-memory-content-top",`${f.getBoundingClientRect().top-(m?.getBoundingClientRect().top??0)}px`),l(Math.max(120,p.clientHeight-h.offsetHeight-g.offsetHeight-160))},b=new ResizeObserver(v);for(let x of[p,f,h,g])b.observe(x);return v(),()=>{b.disconnect(),m?.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 f=d.current;if(f?.id===p.pointerId)s(Math.max(120,Math.min(a,f.height+f.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 go={width:220,height:92};function ET(e,t){let n=e.filter((f)=>f.kind==="board"),o=new Map,i=[],s=new Set,a=new Set;for(let f of n){let m=(f.folder??"").split("/");m.forEach((h,g)=>{a.add(m.slice(0,g+1).join("/"))})}let l=(f,m)=>(f.folder??"")===m||!!m&&!!f.folder?.startsWith(`${m}/`),c=(f,m,h,g)=>{let v=n.filter((B)=>l(B,f)),b=t.has(f),x={path:f,x:m,y:h,width:280,height:72,count:v.length,depth:g,collapsed:b};if(i.push(x),b){for(let B of v)s.add(B.key);return x}let C=v.filter((B)=>(B.folder??"")===f).sort((B,J)=>B.title.localeCompare(J.title)),y=Math.min(3,Math.max(1,Math.ceil(Math.sqrt(C.length))));C.forEach((B,J)=>{let X=B.position??{x:m+24+J%y*(go.width+28),y:h+52+Math.floor(J/y)*(go.height+28)};o.set(B.key,{x:X.x+go.width/2,y:X.y+go.height/2})});let k=h+52+Math.ceil(C.length/y)*(go.height+28),_=C.length?y*(go.width+28)+20:280,I=[...a].filter((B)=>B&&B.slice(0,B.lastIndexOf("/"))===f&&B.includes("/")).sort(),w=20,P=0;for(let B of I){if(w>650)w=20,k+=P+24,P=0;let J=c(B,m+w,k,g+1);w+=J.width+24,P=Math.max(P,J.height),_=Math.max(_,w)}k+=P+(I.length?20:0),x.width=_,x.height=Math.max(100,k-h+4);let L=v.flatMap((B)=>{let J=o.get(B.key);return J?[J]:[]}),N=Math.max(m+x.width,...L.map((B)=>B.x+go.width/2+20)),Y=Math.max(h+x.height,...L.map((B)=>B.y+go.height/2+20));return x.x=Math.min(m,...L.map((B)=>B.x-go.width/2-20)),x.y=Math.min(h,...L.map((B)=>B.y-go.height/2-48)),x.width=N-x.x,x.height=Y-x.y,x},u=32,d=32,p=0;for(let f of[...a].filter((m)=>!m.includes("/")).sort()){if(u>1100)u=32,d+=p+36,p=0;let m=c(f,u,d,0);u+=m.width+36,p=Math.max(p,m.height)}return{positions:o,regions:i,hidden:s}}function ap(e){let t=Ge.value,n=bo.value,[o,i]=E(null),[s,a]=E(!0),[l,c]=E(!1),u=D(()=>{});return q(()=>{let d=!1,p=!1,f=!1,m,h=()=>{if(f=!0,!p&&m===void 0)m=window.setTimeout(g,120)},g=async()=>{m=void 0,f=!1,p=!0,a(!0);let v=Sn,b=bo.peek(),x=Ge.peek(),C=await pe("memoryGraph",`/api/canvas/memory-graph?projection=${e}`,null);if(d)return;if(p=!1,v!==Sn||b!==bo.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),f)h()};return u.current=h,h(),()=>{d=!0,window.clearTimeout(m)}},[e]),q(()=>u.current(),[n,t]),{graph:o,loading:s,error:l,retry:()=>u.current()}}var AT={portal:"Portals",wiki:"Wiki links",card:"Card relations",previous:"Previous boards"};function RT(){let e=Ge.value,t=bo.value,{graph:n,loading:o,error:i,retry:s}=ap("boards"),[a,l]=E(""),[c,u]=E(!0),[d,p]=E(!1),[f,m]=E(!0),[h,g]=E(new Set),[v,b]=E(new Set),[x,C]=E(new Set),[y,k]=E(null),[_,I]=E(null),[w,P]=E(null),[L,N]=E({x:0,y:0}),[Y,B]=E(1),[J,X]=E({}),[V,ee]=E(!1),he=D(null),A=D(!0),te=D(!1),M=D(null);Me(()=>{ut.value=!0},[]),Me(()=>{if(!y)return;let R=(ne)=>{if(ir(ne))ne.preventDefault(),k(null)};return window.addEventListener("keydown",R),()=>window.removeEventListener("keydown",R)},[y]),q(()=>{if(!y)return;let R=!1;P(null);let ne=Sn,Ce=bo.peek(),Te=new URLSearchParams({focus:y,depth:"2"});return pe("memoryGraph",`/api/canvas/memory-graph?${Te}`,null).then((fe)=>{if(!R&&ne===Sn&&Ce===bo.peek())P({key:y,graph:fe&&Array.isArray(fe.nodes)&&Array.isArray(fe.edges)?fe:null})}),()=>{R=!0}},[y,n,t]);let O=Ke(()=>(n?.nodes??[]).filter((R)=>R.kind==="board").map((R)=>{let ne=e.find((Ce)=>Ce.id===R.boardId);return ne?{...R,title:ne.name,folder:ne.folder,inContext:!!ne.pin,nodeCount:ne.nodeCount,position:ne.mapPosition??void 0}:R}),[n,e]),Pe=Ke(()=>ET(O,x),[O,x]),Fe=new Map;for(let R of O){let ne=R.folder?.split("/")[0]??"";Fe.set(ne,(Fe.get(ne)??0)+1)}let De=O.filter((R)=>c&&(!d||R.inContext)&&(f||!!R.folder)&&!h.has(R.folder?.split("/")[0]??"")&&!Pe.hidden.has(R.key)&&`${R.title} ${R.summary} ${R.folder??""}`.toLocaleLowerCase().includes(a.trim().toLocaleLowerCase())),Ae=new Set(De.map((R)=>R.key)),ve=(R)=>J[R]??Pe.positions.get(R),z=O.find((R)=>R.key===y),re=O.find((R)=>R.key===(_??y)),Ne=new Map;for(let R of n?.edges??[]){if(R.kind==="member"||v.has(R.kind))continue;let ne=Mt({boardId:R.source.boardId}),Ce=Mt({boardId:R.target.boardId});if(!Ae.has(ne)||!R.missing&&(!Ae.has(Ce)||ne===Ce))continue;let Te=JSON.stringify([ne,Ce,R.kind,R.relationKind,R.missing]),fe=Ne.get(Te);if(fe)fe.edges.push(R);else Ne.set(Te,{from:ne,to:Ce,edges:[R]})}let ke=new Set(re?[re.key]:[]);for(let{from:R,to:ne}of Ne.values())if(re&&(R===re.key||ne===re.key))ke.add(R),ke.add(ne);let ae=(R)=>new Set((n?.edges??[]).filter((ne)=>ne.kind!=="member"&&(ne.source.boardId===R.boardId||ne.target.boardId===R.boardId)).map((ne)=>ne.source.boardId===R.boardId?ne.target.boardId:ne.source.boardId).filter((ne)=>ne!==R.boardId)).size,Se=()=>{let R=he.current;if(!R?.clientWidth||!R.clientHeight)return;let ne=De.flatMap((Ye)=>{let Lt=ve(Ye.key);return Lt?[{x:Lt.x-110,y:Lt.y-46},{x:Lt.x+110,y:Lt.y+46}]:[]});for(let Ye of Pe.regions){if(h.has(Ye.path.split("/")[0]??"")||!f&&!Ye.path)continue;ne.push({x:Ye.x,y:Ye.y},{x:Ye.x+Ye.width,y:Ye.y+Ye.height})}if(!ne.length)return;let Ce=Math.min(...ne.map((Ye)=>Ye.x)),Te=Math.min(...ne.map((Ye)=>Ye.y)),fe=Math.max(...ne.map((Ye)=>Ye.x))-Ce,it=Math.max(...ne.map((Ye)=>Ye.y))-Te,Ht=Math.min(1.25,Math.max(0.08,Math.min((R.clientWidth-64)/Math.max(1,fe),(R.clientHeight-100)/Math.max(1,it))));B(Ht),N({x:(R.clientWidth-fe*Ht)/2-Ce*Ht,y:(R.clientHeight-it*Ht)/2-Te*Ht-12})};q(()=>{A.current=!0},[x]),q(()=>{if(A.current&&n&&(De.length||Pe.regions.length)&&!M.current)A.current=!1,Se()},[n,x]);let de=(R,ne)=>{let Ce=he.current;if(!Ce)return;let Te=ne??{x:Ce.clientWidth/2,y:Ce.clientHeight/2},fe=Math.min(3,Math.max(0.08,R));N({x:Te.x-(Te.x-L.x)*fe/Y,y:Te.y-(Te.y-L.y)*fe/Y}),B(fe)},Ue=(R,ne=!1)=>{k(R.key);let Ce=ve(R.key),Te=he.current;if(ne&&Ce&&Te)N({x:Te.clientWidth/2-Ce.x*Y,y:Te.clientHeight/2-Ce.y*Y})},xe=(R)=>{let ne=M.current;if(M.current=null,!ne)return;if(te.current=ne.moved,!ne.key)return;let Ce=ne.key,Te=()=>X((fe)=>{let it={...fe};return delete it[Ce],it});if(ne.boardId&&ne.moved&&!R){let fe=ne.current??ne.origin;vr(ne.boardId,{mapPosition:{x:fe.x-go.width/2,y:fe.y-go.height/2}}).finally(Te)}else Te()},qe=w?.key===y?w.graph:null,W=(qe?.edges??[]).filter((R)=>z&&R.kind!=="member"&&(R.source.boardId===z.boardId||R.target.boardId===z.boardId)),ye=e.find((R)=>R.id===z?.boardId),He=(R,ne,Ce,Te)=>r("label",{class:"home-memory-check",children:[r("input",{type:"checkbox","aria-label":R,checked:Ce,onChange:Te},void 0,!1,void 0,this),r("span",{children:R},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:[O.length," boards · ",e.reduce((R,ne)=>R+ne.nodeCount,0)," cards ·"," ",n?.edges.filter((R)=>R.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:(R)=>{R.preventDefault();let ne=R.currentTarget.getBoundingClientRect();de(Y*Math.exp(-R.deltaY*0.0015),{x:R.clientX-ne.left,y:R.clientY-ne.top})},onPointerDown:(R)=>{if(R.button!==0||R.target.closest("button"))return;te.current=!1,M.current={id:R.pointerId,start:{x:R.clientX,y:R.clientY},origin:L,moved:!1},R.currentTarget.setPointerCapture(R.pointerId)},onPointerMove:(R)=>{let ne=M.current;if(!ne||ne.id!==R.pointerId)return;let Ce=R.clientX-ne.start.x,Te=R.clientY-ne.start.y;if(Math.abs(Ce)+Math.abs(Te)>4)ne.moved=!0;if(!ne.moved)return;let fe={x:ne.origin.x+Ce/(ne.key?Y:1),y:ne.origin.y+Te/(ne.key?Y:1)};if(ne.current=fe,ne.key)X((it)=>({...it,[ne.key]:fe}));else N(fe)},onPointerUp:()=>xe(!1),onPointerCancel:()=>xe(!0),children:[r("div",{class:"home-memory-world",style:{transform:`translate(${L.x}px, ${L.y}px) scale(${Y})`,"--memory-zoom":Y},children:[Pe.regions.filter((R)=>!h.has(R.path.split("/")[0]??"")&&(f||R.path)).map((R)=>r("div",{class:`home-memory-region${R.depth?" is-nested":""}`,style:{left:R.x,top:R.y,width:R.width,height:R.height},children:r("button",{type:"button","aria-expanded":!R.collapsed,onClick:()=>C((ne)=>{let Ce=new Set(ne);if(Ce.has(R.path))Ce.delete(R.path);else Ce.add(R.path);return Ce}),children:[R.collapsed?"▸":"▾"," ",R.path.split("/").at(-1)||"Unfiled"," ",r("small",{children:[R.count," boards"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},R.path,!1,void 0,this)),r("svg",{class:"home-memory-links","aria-hidden":"true",children:[...Ne].map(([R,{from:ne,to:Ce,edges:Te}])=>{let fe=Te[0],it=ve(ne),Ht=ve(Ce);if(!it)return null;let Ye=Ht??{x:it.x+100,y:it.y-70},Lt=it.y+(Ye.y>it.y?46:-46),F=Ht?Ye.y+(Ye.y>it.y?-46:46):Ye.y,Ie=re&&(fe.source.boardId===re.boardId||fe.target.boardId===re.boardId),S=mo({kind:fe.relationKind,type:fe.type},e.find((ue)=>ue.id===fe.source.boardId)?.relationVocabulary),K=fe.missing?"var(--c-warn)":fe.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-${fe.kind}${fe.missing?" is-missing":""}${Ie?" is-emphasized":re?" is-dimmed":""}`,children:[r("path",{d:`M ${it.x} ${Lt} C ${it.x} ${(Lt+F)/2}, ${Ye.x} ${(Lt+F)/2}, ${Ye.x} ${F}`},void 0,!1,void 0,this),Te.length>1&&r("text",{x:(it.x+Ye.x)/2,y:(it.y+Ye.y)/2-6,children:[Te.length," links"]},void 0,!0,void 0,this),fe.missing&&r("text",{x:Ye.x,y:Ye.y-5,children:["⚠ Missing ",fe.kind," link"]},void 0,!0,void 0,this)]},R,!0,void 0,this)})},void 0,!1,void 0,this),De.map((R,ne)=>{let Ce=ve(R.key);if(!Ce)return null;let Te=e.find((fe)=>fe.id===R.boardId);return r("article",{"data-key":R.key,class:`home-memory-node is-board${R.inContext?" in-context":""}${y===R.key?" is-selected":""}${ke.has(R.key)?" is-emphasized":re?" is-dimmed":""}`,style:{left:Ce.x,top:Ce.y},onPointerEnter:()=>{if(!M.current)I(R.key)},onPointerLeave:()=>I(null),children:[r("button",{type:"button",class:"home-memory-select","aria-label":`board: ${R.title}`,"aria-pressed":y===R.key,onFocus:(fe)=>{if(!M.current&&fe.currentTarget.matches(":focus-visible"))Ue(R,!0)},onClick:()=>{if(!te.current)Ue(R);te.current=!1},onDblClick:()=>void zt(R),onPointerDown:(fe)=>{if(fe.button!==0)return;fe.stopPropagation(),te.current=!1,M.current={id:fe.pointerId,start:{x:fe.clientX,y:fe.clientY},origin:Ce,key:R.key,boardId:R.boardId,moved:!1},fe.currentTarget.setPointerCapture(fe.pointerId)},onKeyDown:(fe)=>{if(fe.key==="Enter")fe.preventDefault(),zt(R);if(fe.key.startsWith("Arrow")){fe.preventDefault();let it=(ne+(fe.key==="ArrowLeft"||fe.key==="ArrowUp"?-1:1)+De.length)%De.length,Ht=De[it];if(Ht)Ue(Ht,!0),he.current?.querySelectorAll(".home-memory-select")[it]?.focus({preventScroll:!0})}},children:[r("strong",{children:R.title},void 0,!1,void 0,this),r("span",{children:[R.nodeCount??0," cards · ",ae(R)," connected boards"]},void 0,!0,void 0,this),r("span",{class:"home-memory-summary",children:R.summary||"No summary yet"},void 0,!1,void 0,this),R.inContext&&r("span",{class:"home-memory-context",children:"⌖ In context"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Te&&r(ho,{board:Te},void 0,!1,void 0,this)]},R.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||!De.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…":Pe.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:(R)=>l(R.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),He("Boards",O.length,c,()=>u(!c)),He("Only in context",O.filter((R)=>R.inContext).length,d,()=>p(!d)),He("Include unfiled",O.filter((R)=>!R.folder).length,f,()=>m(!f))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Groups · by folder"},void 0,!1,void 0,this),[...Fe].sort(([R],[ne])=>R.localeCompare(ne)).map(([R,ne])=>r("div",{children:He(R||"Unfiled",ne,!h.has(R),()=>g((Ce)=>{let Te=new Set(Ce);if(Te.has(R))Te.delete(R);else Te.add(R);return Te}))},R,!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(AT).map((R)=>r("div",{class:`memory-legend-${R}`,children:He(AT[R],n?.edges.filter((ne)=>ne.kind===R).length??0,!v.has(R),()=>b((ne)=>{let Ce=new Set(ne);if(Ce.has(R))Ce.delete(R);else Ce.add(R);return Ce}))},R,!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(sp,{children:z?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:[z.title," · ",W.length," connections"]},void 0,!0,void 0,this),r("p",{children:[z.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(z),children:"Open board"},void 0,!1,void 0,this),ye&&r(ho,{board:ye},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button",onClick:()=>void vr(z.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:[z.nodeCount??0," cards · ",ae(z)," connected boards"]},void 0,!0,void 0,this),r("p",{children:z.summary||"No summary yet."},void 0,!1,void 0,this),r("p",{class:z.inContext?"memory-context-legend":"",children:z.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),!qe&&r("p",{role:"status",children:w?.key===y?"Connections could not be loaded.":"Loading connections…"},void 0,!1,void 0,this),r("ul",{children:[W.map((R)=>{let ne=R.source.boardId===z.boardId,Ce=ne?R.target:R.source,Te=qe?.nodes.find((fe)=>fe.key===Mt(Ce));return r("li",{children:[r("span",{children:[ne?"→":"←"," ",R.kind==="card"?ha({...R,kind:R.relationKind}):`${R.kind}${R.label?` · ${R.label}`:""}`]},void 0,!0,void 0,this),R.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)]},R.id,!0,void 0,this)}),(qe?.unresolvedLinks??[]).filter((R)=>R.source.boardId===z.boardId).map((R)=>r("li",{class:"home-memory-missing",children:["⚠ Unresolved wiki: [[",R.ref,"]]"]},`${Mt(R.source)}:${R.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 Je={width:220,height:96,gap:64},nc=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),SL=(e,t)=>e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom;function _L(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 PT(e,t){let o=[...e].map(([f,m])=>({key:f,left:m.x-Je.width/2-8,right:m.x+Je.width/2+8,top:m.y-Je.height/2-8,bottom:m.y+Je.height/2+8})),i=(f,m)=>!o.some((h)=>_L(f,m,h)),s=o.flatMap((f)=>[{x:f.left,y:f.top},{x:f.right,y:f.top},{x:f.right,y:f.bottom},{x:f.left,y:f.bottom}]).filter((f)=>!o.some((m)=>SL(f,m))),a=new Map,l=(f,m)=>[{x:f.x-Je.width/2,y:f.y+m*Je.height},{x:f.x+Je.width/2,y:f.y+m*Je.height},{x:f.x+m*Je.width,y:f.y-Je.height/2},{x:f.x+m*Je.width,y:f.y+Je.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 f of t){let m=JSON.stringify([f.from,f.to].sort());p.set(m,(p.get(m)??0)+1)}for(let f of t){let m=e.get(f.from),h=e.get(f.to),g=JSON.stringify([f.from,f.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(m,b),C=l(h,b),y,k=1/0;for(let P of x)for(let L of C){let N=nc(P.stub,L.stub);if(N&&N<k&&i(P.stub,L.stub))k=N,y=[P.port,P.stub,L.stub,L.port]}if(!y){let P=s.map(()=>1/0),L=s.map(()=>-1),N=s.map(()=>0),Y=new Set;for(let X=0;X<s.length;X++)for(let V=0;V<x.length;V++){let ee=nc(x[V].stub,s[X]);if(ee<P[X]&&i(x[V].stub,s[X]))P[X]=ee,N[X]=V}let B=-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||P[ee]<P[X]))X=ee;if(X<0||P[X]>=k||!Number.isFinite(P[X]))break;Y.add(X);for(let ee=0;ee<C.length;ee++){let he=P[X]+nc(s[X],C[ee].stub);if(he<k&&i(s[X],C[ee].stub))k=he,B=X,J=ee}let V=a.get(X);if(!V)V=s.flatMap((ee,he)=>he!==X&&i(s[X],ee)?[{index:he,length:nc(s[X],ee)}]:[]),a.set(X,V);for(let ee of V)if(P[X]+ee.length<P[ee.index])P[ee.index]=P[X]+ee.length,L[ee.index]=X,N[ee.index]=N[X]}if(B>=0){let X=[];for(let he=B;he>=0;he=L[he])X.unshift(s[he]);let V=x[N[B]],ee=C[J];y=[V.port,V.stub,...X,ee.stub,ee.port]}}if(!y)continue;let _=Math.max(24,f.label.length*3.6+6),I=y.slice(1).map((P,L)=>({first:y[L],point:P,length:nc(y[L],P)})).filter((P)=>P.length>0).sort((P,L)=>L.length-P.length),w;for(let P=16;f.label&&!w;P+=20)w=I.flatMap(({first:N,point:Y,length:B})=>[0.5,0.25,0.75].flatMap((J)=>[-P,P].map((X)=>{let V=N.x+(Y.x-N.x)*J-(Y.y-N.y)*X/B,ee=N.y+(Y.y-N.y)*J+(Y.x-N.x)*X/B;return{x:V,y:ee,left:V-_,right:V+_,top:ee-16,bottom:ee+8}}))).find((N)=>![...o,...u].some((Y)=>N.left<Y.right&&N.right>Y.left&&N.top<Y.bottom&&N.bottom>Y.top));if(w)u.push(w);c.set(f.id,{points:y,path:y.map((P,L)=>`${L?"L":"M"} ${P.x} ${P.y}`).join(" "),label:w})}return c}var ls=(e)=>e.kind==="overview"?"overview":JSON.stringify(e),CL=(e,t)=>JSON.stringify([e,t].sort());function NT(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=CL(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 lp(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 MT(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||(lp(e)-0.5)*0.01,p=i.y-u.y||(lp(`${e}:y`)-0.5)*0.01,f=Math.max(1,Math.hypot(d,p)),m=14000/(f*f),h=o.get(c)??0,g=h?(f-290)*0.006*Math.sqrt(h)/s:0;a+=d/f*(m-g),l+=p/f*(m-g);let v=Je.width+Je.gap,b=(Je.height+Je.gap)*Je.width/Je.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 $T(e,t,n,o){let i=[...e.keys()].sort(),s=MT(i,t),a=Je.width/Je.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)),f=Math.min(1,24/Math.max(1,Math.hypot(p.x,p.y)))*o,m=p.x*f,h=p.y*f/a;e.set(u,{x:d.x+m,y:d.y/a+h}),c=Math.max(c,Math.hypot(m,h))}for(let[u,d]of i.entries())for(let p of i.slice(u+1)){let f=e.get(d),m=e.get(p),h=f.x-m.x,g=f.y-m.y,v=Je.width+Je.gap-Math.abs(h),b=Je.height+Je.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:f.x+x.x*C,y:f.y+x.y*C});if(p!==n)e.set(p,{x:m.x-x.x*y,y:m.y-x.y*y});c=Math.max(c,Math.hypot(x.x,x.y))}return c}function LT(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=MT(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 I of i.get(_).keys()){if(a.has(I))continue;a.add(I),k.push(I)}s.push(k.sort())}let l=new Map,c=Je.width/Je.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((I)=>l.has(I));if(!_.length)continue;l.set(k,{x:_.reduce((I,w)=>I+l.get(w).x,0)/_.length+(lp(k)-0.5)*240,y:_.reduce((I,w)=>I+l.get(w).y,0)/_.length+(lp(`${k}:y`)-0.5)*240})}for(let k=0;k<180;k++){let _=new Map;for(let I of y){if(n.has(I))continue;let w=l.get(I),{x:P,y:L}=zT(I,l,y,i.get(I)),N=Math.min(1,24/Math.max(1,Math.hypot(P,L)))*(1-k/200);_.set(I,{x:w.x+P*N,y:w.y+L*N})}for(let[I,w]of _)l.set(I,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=Je.width+Je.gap,p=Je.height+Je.gap,f=(y,k)=>Math.abs(y.x-k.x)<d&&Math.abs(y.y-k.y)<p,m=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)m=u.length?Math.max(...u.map((w)=>w.x))+340:0,h=m,C=!0;let _=k?u:[],I=[];for(let w of y){if(n.has(w))continue;let P=l.get(w),L=P;if(_.some((N)=>f(L,N)))L=_.flatMap((Y)=>[{x:Y.x-d,y:P.y},{x:Y.x+d,y:P.y},{x:P.x,y:Y.y-p},{x:P.x,y:Y.y+p}]).filter((Y)=>!_.some((B)=>f(Y,B))).sort((Y,B)=>Math.hypot(Y.x-P.x,Y.y-P.y)-Math.hypot(B.x-P.x,B.y-P.y))[0];l.set(w,L),_.push(L),I.push(L)}if(!k&&I.length){let w=Math.min(...I.map((L)=>L.x)),P=Math.min(...I.map((L)=>L.y));for(let L of I)L.x+=h-w,L.y+=g-P;if(u.push(...I),h=Math.max(...I.map((L)=>L.x))+340,v=Math.max(v,Math.max(...I.map((L)=>L.y))-g+200),h-m>b)h=m,g+=v,v=0}}for(let[y,k]of l)if(!n.has(y))n.set(y,k);return l}var OT={portal:"Portals",wiki:"Wiki links",card:"Card relations",previous:"Previous boards"},Eg=(e)=>({scene:e,camera:null,query:"",context:!1,folders:new Set,hiddenLinks:new Set,inspection:null,limit:80});function DT(){let e=Ge.value,{graph:t,loading:n,error:o,retry:i}=ap("full"),[s,a]=E([Eg({kind:"overview"})]),l=s.at(-1),c=l.scene,u=ls(c),[d,p]=E(!1),[f,m]=E(0),[h,g]=E(0),[v,b]=E(null),[x,C]=E(""),[y,k]=E({width:0,height:0}),_=D(new Map),I=D(null),w=D(null),P=D(null),L=D(null),N=()=>{if(P.current!==null)cancelAnimationFrame(P.current);P.current=null,L.current=null},Y=D(!1),B=(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(ls(S)===u){m((K)=>K+1);return}a((K)=>[...K,Eg(S)]),p(!1),b(null),C("")},V=(S)=>{let K=s.map((ue)=>ls(ue.scene)).lastIndexOf(ls(S));if(K>=0)a((ue)=>ue.slice(0,K+1));else X(S);p(!1)};Me(()=>{ut.value=!0},[]),Me(()=>{let S=I.current,K=()=>k({width:S.clientWidth,height:S.clientHeight}),ue=new ResizeObserver(K);return ue.observe(S),K(),()=>ue.disconnect()},[]),Me(()=>{let S=(K)=>{if(!ir(K))return;if(l.inspection||s.length>1)if(K.preventDefault(),l.inspection)B({inspection:null});else J()};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[l.inspection,s.length]);let ee=Ke(()=>(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=Ke(()=>new Map(ee.map((S)=>[S.key,S])),[ee]),A=Ke(()=>NT(t?.edges??[]),[t]),te=c.kind==="overview"?null:Mt(c),M=te?he.get(te):void 0,O=(S)=>e.find((K)=>K.id===S)?.name??S,Pe=(S)=>c.kind!=="overview"&&S.boardId===c.boardId,Fe=c.kind==="overview"?A.evidence:A.evidence.filter((S)=>c.kind==="board"?S.source.boardId===c.boardId||S.target.boardId===c.boardId:S.from===te||S.to===te),De=Ke(()=>{if(c.kind==="overview")return{nodes:ee.filter((ue)=>ue.kind==="board"),links:[...A.pairs].map(([ue,$e])=>({id:ue,from:Mt({boardId:$e.boardId}),to:Mt({boardId:$e.peerId}),edges:$e.edges,bundle:!0}))};let S=new Set;if(c.kind==="board"){for(let ue of ee)if(Pe(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 Fe){if(ue.missing||!he.has(ue.from)||!he.has(ue.to))continue;let $e=c.kind==="board"&&ue.source.boardId!==c.boardId?Mt({boardId:ue.source.boardId}):ue.from,je=c.kind==="board"&&ue.target.boardId!==c.boardId?Mt({boardId:ue.target.boardId}):ue.to;S.add($e),S.add(je);let le=c.kind==="card"?ue.id:JSON.stringify([$e,je].sort()),we=K.get(le);if(we)we.edges.push(ue),we.bundle=!0;else K.set(le,{id:le,from:$e,to:je,edges:[ue],bundle:$e!==ue.from||je!==ue.to})}return{nodes:ee.filter((ue)=>S.has(ue.key)),links:[...K.values()]}},[ee,t,u]),Ae=new Map;for(let S of De.links)for(let K of[S.from,S.to])Ae.set(K,(Ae.get(K)??0)+S.edges.length);let ve=De.nodes.filter((S)=>Ae.has(S.key)||S.key===te),z=De.nodes.filter((S)=>!Ae.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} ${O(S.boardId)} ${S.folder??""}`.toLocaleLowerCase().includes(l.query.trim().toLocaleLowerCase()),Ne=ve.filter(re).sort((S,K)=>Number(K.key===te)-Number(S.key===te)||(Ae.get(K.key)??0)-(Ae.get(S.key)??0)||S.key.localeCompare(K.key)),ke=Ne.slice(0,l.limit),ae=new Set(ke.map((S)=>S.key)),Se=z.filter(re),de=De.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));q(()=>()=>{N(),Y.current||=!!w.current?.moved,w.current=null},[De,l.limit,l.query,l.context,l.folders,l.hiddenLinks]);let Ue=(S)=>{if(P.current!==null)return;let K=180,ue=()=>{let $e=w.current?.key===S,je=_.current.get(u);if(L.current)je.set(S,L.current);L.current=null;let le=new Map(ke.map((ge)=>[ge.key,je.get(ge.key)])),we=$T(le,de.map((ge)=>({...ge,weight:ge.edges.length})),S,$e?1:K/180);for(let[ge,Le]of le)je.set(ge,Le);if(g((ge)=>ge+1),$e||--K>0&&we>0.02)P.current=requestAnimationFrame(ue);else P.current=null};P.current=requestAnimationFrame(ue)},xe=Ke(()=>{let S=_.current.get(u);if(!S)S=new Map,_.current.set(u,S);if(c.kind!=="card")return LT(ve,De.links.map((ge)=>({...ge,weight:ge.edges.length})),S);if(!S.has(te))S.set(te,{x:0,y:0});let K=Fe.filter((ge)=>ge.kind!=="card"||mo({kind:ge.relationKind,type:ge.type},e.find((Le)=>Le.id===ge.source.boardId)?.relationVocabulary).directed),ue=new Set(K.filter((ge)=>ge.to===te).map((ge)=>ge.from)),$e=new Set(K.filter((ge)=>ge.from===te).map((ge)=>ge.to)),je=ve.filter((ge)=>ge.key!==te).sort((ge,Le)=>ge.key.localeCompare(Le.key)),le=Je.width+Je.gap,we=Je.height+Je.gap;for(let ge of["incoming","outgoing","mutual"]){let Le=je.filter((on)=>(ue.has(on.key)&&!$e.has(on.key)?"incoming":$e.has(on.key)&&!ue.has(on.key)?"outgoing":"mutual")===ge),Rt=Le.filter((on)=>S.has(on.key)).map((on)=>S.get(on.key)),pt=S.get(te).y+we,pn=0;for(let[on,fs]of Le.entries())if(!S.has(fs.key)){let Pn=Rt.length?Math.max(...Rt.map((fn)=>ge==="mutual"?fn.x:fn.y))+(pn+1)*(ge==="mutual"?le:we):(on-(Le.length-1)/2)*(ge==="mutual"?le:we),xn=ge==="mutual"?{x:Pn,y:pt}:{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(fs.key,xn),pn++}}return new Map(S)},[De,u,h]),qe=(S)=>S.bundle?`${S.edges.length} links`:S.edges[0].kind==="card"?mo({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,W=Ke(()=>PT(new Map(ke.map((S)=>[S.key,xe.get(S.key)])),de.map((S)=>({...S,label:S.edges.length>1||c.kind==="card"?qe(S):""})).sort((S,K)=>S.id.localeCompare(K.id))),[xe,De,l.limit,l.query,l.context,l.folders,l.hiddenLinks]),ye=l.camera??{x:0,y:0,scale:1},He=ke.filter((S)=>{let K=xe.get(S.key);return(K.x-Je.width/2)*ye.scale+ye.x<8||(K.x+Je.width/2)*ye.scale+ye.x>y.width-8||(K.y-Je.height/2)*ye.scale+ye.y<(c.kind==="card"?40:8)||(K.y+Je.height/2)*ye.scale+ye.y>y.height-64}).length,R=(S=!1)=>{let K=I.current;if(!K||!ke.length)return;let ue=c.kind==="card"?40:16,$e=K.clientHeight-ue-64-8,je=ke.flatMap((pt)=>{let pn=xe.get(pt.key);return[{x:pn.x-Je.width/2,y:pn.y-Je.height/2},{x:pn.x+Je.width/2,y:pn.y+Je.height/2}]});for(let pt of W.values())if(je.push(...pt.points),pt.label)je.push({x:pt.label.left,y:pt.label.top},{x:pt.label.right,y:pt.label.bottom});let le=Math.min(...je.map((pt)=>pt.x)),we=Math.min(...je.map((pt)=>pt.y)),ge=Math.max(...je.map((pt)=>pt.x))-le,Le=Math.max(...je.map((pt)=>pt.y))-we,Rt=Math.min(1,Math.max(S?1:0.005,Math.min((K.clientWidth-64)/ge,$e/Le)));B({camera:S&&c.kind==="card"?{x:K.clientWidth/2-xe.get(te).x,y:ue+$e/2-xe.get(te).y,scale:1}:{x:(K.clientWidth-ge*Rt)/2-le*Rt,y:ue+($e-Le*Rt)/2-we*Rt,scale:Rt}})};Me(()=>{if(t&&!l.camera&&ke.length)R(!0)},[t,u,l.camera]),q(()=>{if(!t||c.kind==="overview"||M)return;let S=he.has(Mt({boardId:c.boardId}));a((K)=>{let ue=K.filter((je)=>je.scene.kind==="overview"||he.has(Mt(je.scene))),$e=c.kind==="card"&&S?{kind:"board",boardId:c.boardId}:{kind:"overview"};return ls(ue.at(-1).scene)===ls($e)?ue:[...ue,Eg($e)]}),C("The focused endpoint was removed. Returned to its nearest available level.")},[t,te,M]);let ne=(S)=>{let K=xe.get(S.key),ue=I.current;if(!K||!ue)return;let $e=Math.max(1,ye.scale);B({camera:{x:ue.clientWidth/2-K.x*$e,y:ue.clientHeight/2-K.y*$e-20,scale:$e},limit:Math.max(l.limit,Ne.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=I.current;if(!ue)return;let $e=K??{x:ue.clientWidth/2,y:ue.clientHeight/2},je=Math.max(0.005,Math.min(3,S));B({camera:{x:$e.x-($e.x-ye.x)*je/ye.scale,y:$e.y-($e.y-ye.y)*je/ye.scale,scale:je}})},fe=De.links.find((S)=>S.id===l.inspection),it=fe?.edges??Fe,Ht=M?e.find((S)=>S.id===M.boardId):void 0,Ye=(S)=>{B({inspection:S.id}),m((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),F=c.kind!=="overview"&&!M,Ie=c.kind==="overview"?"Library":c.kind==="board"?O(c.boardId):M?.title??"Missing card";return r("main",{class:`home-memory graph-view${d?" sidebar-open":""}`,"aria-label":"Library Graph",style:{"--graph-node-width":`${Je.width}px`,"--graph-node-height":`${Je.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:O(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 · ",He," partly/outside view ·"," ",ve.length-Ne.length," filtered · ",Math.max(0,Ne.length-ke.length)," hidden ·"," ",z.length," without links"]},void 0,!0,void 0,this),Ne.length>l.limit&&r("button",{type:"button",class:"home-button",onClick:()=>B({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:I,"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;N(),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,$e=S.clientY-K.start.y;if(Math.abs(ue)+Math.abs($e)>4)K.moved=!0;if(!K.moved)return;let je={x:K.origin.x+ue/(K.key?ye.scale:1),y:K.origin.y+$e/(K.key?ye.scale:1)};if(K.key)L.current=je,Ue(K.key);else B({camera:{...je,scale:ye.scale}})},onPointerUp:()=>{if(!w.current)return;Y.current=w.current.moved,w.current=null},onPointerCancel:()=>{let S=w.current;if(N(),S?.layout)_.current.set(u,S.layout),g((K)=>K+1);else if(S)B({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=W.get(S.id);if(!ue)return null;let $e=S.edges[0],je=mo({kind:$e.relationKind,type:$e.type},e.find((Le)=>Le.id===$e.source.boardId)?.relationVocabulary),le=!S.bundle&&($e.kind!=="card"||je.directed),we=S.bundle?"var(--c-muted)":$e.kind==="card"?`var(--c-rel-${je.ink})`:$e.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:()=>Ye(S),onKeyDown:(Le)=>{if(Le.key==="Enter"||Le.key===" ")Le.preventDefault(),Ye(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:qe(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),$e=e.find((le)=>le.id===S.boardId),je=S.kind==="board"?S.inContext:!!$e?.pinnedTitles?.some((le)=>le.nodeId===S.cardId)||S.inContext&&!$e?.pin;return r("article",{"data-key":S.key,class:`graph-node is-${S.kind}${te===S.key?" is-selected":""}${je?" in-context":""}${c.kind!=="overview"&&!Pe(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(),N(),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),I.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 · ${A.internal.get(S.boardId)??0} internal`:`${O(S.boardId)} · ${S.type??"card"}`},void 0,!1,void 0,this),r("span",{class:je?"memory-context-legend":"",children:je?"⌖ 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:()=>R(),children:"Fit view"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(x||F||!t||!ke.length||o)&&r("div",{class:"home-memory-status",role:"status",children:x||(F?"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)=>B({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,...z].filter(re).slice(0,30).map((S)=>r("li",{children:r("button",{type:"button",class:"home-button",onClick:()=>{if(Ae.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,()=>B({context:!l.context}))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Folders"},void 0,!1,void 0,this),[...new Set(De.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);B({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(OT).map((S)=>r("div",{children:Lt(OT[S],!l.hiddenLinks.has(S),()=>{let K=new Set(l.hiddenLinks);if(K.has(S))K.delete(S);else K.add(S);B({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:[A.evidence.length," links ·"," ",[...A.pairs.values()].reduce((S,K)=>S+K.edges.length,0)," between boards ·"," ",[...A.internal.values()].reduce((S,K)=>S+K,0)," inside boards ·"," ",A.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`:O(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(sp,{initiallyCollapsed:!0,reveal:f,children:M||fe?r("section",{class:"home-memory-details",role:"complementary","aria-label":"Selection details",children:[fe&&r("button",{type:"button",class:"home-memory-clear","aria-label":"Close details",onClick:()=>B({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:[fe?`${he.get(fe.from)?.title} ↔ ${he.get(fe.to)?.title}`:Ie," ·"," ",it.length," connections"]},void 0,!0,void 0,this),r("p",{children:fe?"Original evidence, not a new aggregate relation":`${M?.folder||"Unfiled"} / ${O(M.boardId)}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-actions",children:M&&r(be,{children:[r("button",{type:"button",class:"home-button is-primary",onClick:()=>void zt(M),children:["Open ",M.kind]},void 0,!0,void 0,this),Ht&&r(ho,{board:Ht},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:[M&&r("p",{class:M.inContext?"memory-context-legend":"",children:[M.inContext?"⌖ In context":"Not in context",M.linksComplete===!1?" · Partial discovery":""]},void 0,!0,void 0,this),r("details",{class:"home-memory-connections",open:!0,children:[r("summary",{children:["Connections",fe?" within this pair":""]},void 0,!0,void 0,this),r("ul",{children:[it.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,$e=he.get(Mt(ue)),je=mo({kind:S.relationKind,type:S.type},e.find((we)=>we.id===S.source.boardId)?.relationVocabulary),le=S.kind!=="card"||je.directed;return r("li",{children:[r("span",{children:[le?K?"→":"←":"↔"," ",S.kind==="card"?ha({...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??O(S.source.boardId)," ",le?"→":"↔"," ",he.get(S.to)?.title??S.target.cardId??O(S.target.boardId)," ·"," ",O(ue.boardId)]},void 0,!0,void 0,this),!$e||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($e),children:["Follow ",$e.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 BT({folder:e,folders:t,onScopeChange:n}){let[o,i]=E(""),[s,a]=E(!1),[l,c]=E(null),[u,d]=E(""),p=Oe.value;q(()=>{if(p)Kt()},[p]),Me(()=>{let C=(y)=>{if(!Oe.value)return;if(!ir(y))return;y.preventDefault(),i(""),a(!1)};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[]);let f=Xn.value,m=(C)=>!e||C===e||!!C?.startsWith(`${e}/`),h=(f?.reviewCards??[]).filter((C)=>m(C.folder)),g=o.trim().toLocaleLowerCase(),v=h.filter((C)=>{let y=f?.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)=>m(C.folder)).map((C)=>C.id)),x=Object.entries(f?.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),Oi.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),!f?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=f.cards[y],_=[...k.reasons,...k.sources.map((I)=>`${I.title}: ${I.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(!Oe.value)return;c(y),d("");let I=await zt(C,{review:!0});if(c(null),!I)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 TL=Pi({decayType:mn(["reality","decision","dependency","relevance"]),rate:mn(["fast","medium","slow","durable"]),triggers:We(U().trim().min(1)),revalidationMethod:U().trim().min(1),cadenceDays:Ze().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."}),FT=TL.safeExtend({id:U().trim().min(1),name:U().trim().min(1),glyph:U().trim().min(1)});var sr=(e,t,n,o,i,s)=>({id:e,name:t,glyph:n,decayType:o,rate:i,revalidationMethod:s,triggers:[],...i==="medium"?{cadenceDays:90}:{}}),HT=sr("research","Research","⌕","reality","medium","Check the sources and conflicting evidence."),UT=sr("metric","Metric","▥","reality","fast","Re-read the source dashboard and compare."),jT=sr("decision","Decision","⚑","decision","durable","Check for a superseding decision and changed dependencies."),ZT=sr("notes","Notes","✎","relevance","slow","Check relevance to the resumed task."),cp={"Org · team · personal":{categories:[sr("strategy","Strategy","◎","relevance","slow","Check the current goals and decisions."),sr("policy","Policy","◇","decision","slow","Check with the policy owner."),jT,HT,UT,ZT],folders:{Org:"strategy","Org/Policies":"policy",Team:"research","Team/Decisions":"decision","Team/Metrics":"metric",Personal:"notes"}},"Solo research":{categories:[sr("question","Question","?","relevance","slow","Check whether this question still matters."),sr("source","Source","▤","reality","medium","Re-read the original source."),sr("finding","Finding","◉","dependency","durable","Compare the supporting and contradicting evidence."),sr("note","Note","✎","relevance","slow","Check relevance to the resumed task.")],folders:{Projects:"question","Projects/Findings":"finding",Sources:"source",Notes:"note"}},"Product team":{categories:[HT,UT,jT,ZT],folders:{Discovery:"research","Discovery/Metrics":"metric",Delivery:"notes",Decisions:"decision"}},Empty:{categories:[],folders:{}}};function WT({folder:e,onClose:t}){let n=Oe.value,o=D(null),i=Xn.value,s=i?.folders.find((M)=>M.path===e),a=e?i?.resolvedFolders[e]:null,[l,c]=E(s?.categoryId??""),[u,d]=E(!!s?.lifecycleOverride),[p,f]=E(s?.lifecycleOverride??a?.lifecycle??xa),[m,h]=E(()=>i?.categories[0]?structuredClone(i.categories[0]):null),[g,v]=E(null),b=i?.categories.find((M)=>M.id===m?.id),x=i?.folders.filter((M)=>M.categoryId===m?.id)??[],[C,y]=E(!1),[k,_]=E(""),[I,w]=E(()=>JSON.stringify(m)),[P,L]=E("Basics"),[N,Y]=E(""),[B,J]=E(null),X=!e&&JSON.stringify(m)!==I,V=(M)=>{if(!Oe.value||C||B)return;if(X)J(()=>M);else M()},ee=()=>{if(!Oe.value)return;if(B)J(null);else if(g)v(null);else V(t)};bn(o,n,{onEscape:ee}),Me(()=>{if(!n&&o.current?.contains(document.activeElement))document.querySelector('button[aria-label="Settings"]')?.focus({preventScroll:!0})},[n]),q(()=>{if(n)Kt()},[n]);let he=(M)=>{let O=structuredClone(M);h(O),w(JSON.stringify(O)),L("Basics"),v(null),_("")},A=async(M,O)=>{if(!Oe.value)return!1;return(await pe("knowledgeWrite",`/api/canvas/knowledge/${M}`,null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(O)}))?.ok===!0},te=async(M)=>{if(!Oe.value||C||!i)return;let O=tn;y(!0),_("");let Pe=!0,Fe=cp[M];for(let De of Fe.categories){if(!Oe.value||O!==tn){Pe=!1;break}if(!i.categories.some((Ae)=>Ae.id===De.id))Pe=await A("category",{category:De});if(!Pe)break}if(Pe)for(let[De,Ae]of Object.entries(Fe.folders)){if(!Oe.value||O!==tn){Pe=!1;break}if(!i.folders.some((ve)=>ve.path===De))Pe=await A("folder",{path:De,categoryId:Ae,lifecycleOverride:null});if(!Pe)break}await Kt(),y(!1),_(Pe?M==="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:(M)=>{if(M.key==="Escape")M.stopPropagation(),M.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),B&&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(!Oe.value)return;let M=B;J(null),w(JSON.stringify(m)),M()},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:Ho,onSubmit:async(M)=>{if(M.preventDefault(),!Oe.value||C)return;let O=tn;y(!0);let Pe=await A("folder",{path:e,categoryId:l||null,lifecycleOverride:u?Ql(p):null});if(await Kt(),y(!1),Pe&&Oe.value&&O===tn)t();else if(!Pe)_("Folder settings were not saved. Retry.")},children:[r("div",{class:"knowledge-field",children:[r("span",{children:"Category"},void 0,!1,void 0,this),r(Mr,{label:"Category",value:l,onChange:c,options:[{value:"",label:"Use the parent’s"},...i.categories.map((M)=>({value:M.id,label:`${M.glyph} ${M.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:(M)=>d(M.currentTarget.checked)},void 0,!1,void 0,this)," ","Override lifecycle for this folder"]},void 0,!0,void 0,this),u?r(Yl,{value:p,onChange:f},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(cp).map(([M,O])=>r("button",{type:"button",disabled:C||!!B,onClick:()=>V(()=>{if(X)h(b?structuredClone(b):null),w(JSON.stringify(b??null));te(M)}),children:[r("strong",{children:M},void 0,!1,void 0,this),r("span",{children:Object.keys(O.folders).join(" / ")||"No folders or categories"},void 0,!1,void 0,this)]},M,!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:N,onInput:(M)=>Y(M.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",disabled:C,onClick:()=>V(()=>he({...xa,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((M)=>M.name.toLocaleLowerCase().includes(N.toLocaleLowerCase())).map((M)=>r("button",{type:"button",class:"category-choice",disabled:C,"aria-pressed":m?.id===M.id,onClick:()=>{if(m?.id!==M.id)V(()=>he(M))},children:[r("strong",{children:[M.glyph," ",M.name]},void 0,!0,void 0,this),r("span",{children:[M.decayType," · ",M.rate,M.rate==="medium"&&M.cadenceDays?` · ${M.cadenceDays} days`:""]},void 0,!0,void 0,this)]},M.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),m&&r("form",{class:"category-inspector",noValidate:!0,onClick:Ho,onSubmit:async(M)=>{if(M.preventDefault(),!Oe.value||C)return;let O=tn,Pe=FT.safeParse({...m,...Ql(m)});if(!Pe.success){let Ae=String(Pe.error.issues[0].path[0]);L(["name","glyph","id"].includes(Ae)?"Basics":"Review policy"),_(Pe.error.issues[0].message),setTimeout(()=>{if(!Oe.value||O!==tn)return;let ve=Ae==="name"?"Name":Ae==="glyph"?"Glyph":Ae==="cadenceDays"?"Cadence in days":"How to check",z=o.current?.querySelectorAll("label");Array.from(z??[]).find((re)=>re.textContent?.trim().startsWith(ve))?.querySelector("input")?.focus()},0);return}y(!0);let Fe=await pe("knowledgeWrite","/api/canvas/knowledge/category",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({category:Pe.data})}),De=Fe?.ok===!0;if(await Kt(),y(!1),!Oe.value||O!==tn)return;if(De){let Ae=Fe?.category??Pe.data;h(Ae),w(JSON.stringify(Ae))}_(De?"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((M)=>r("button",{type:"button",role:"tab",id:`category-tab-${M.replace(" ","-")}`,"aria-controls":"category-tab-panel","aria-selected":P===M,onClick:()=>L(M),children:M},M,!1,void 0,this))},void 0,!1,void 0,this),r("fieldset",{disabled:C||!!B,id:"category-tab-panel",role:"tabpanel","aria-labelledby":`category-tab-${P.replace(" ","-")}`,class:"category-tab-content",children:[P==="Basics"&&r(be,{children:[r("label",{children:["Name",r("input",{required:!0,value:m.name,onInput:(M)=>h({...m,name:M.currentTarget.value})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("label",{children:["Glyph",r("input",{required:!0,value:m.glyph,onInput:(M)=>h({...m,glyph:M.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(cp).flatMap((M)=>M.categories.map((O)=>O.glyph)))].map((M)=>r("button",{type:"button","aria-label":`Choose glyph ${M}`,"aria-pressed":m.glyph===M,onClick:()=>h({...m,glyph:M}),children:M},M,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P==="Review policy"&&r(Yl,{value:m,onChange:(M)=>h({...m,...M})},void 0,!1,void 0,this),P==="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((M)=>M.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(!Oe.value||C)return;let M=tn;y(!0);let O=await pe("knowledgeRemove",`/api/canvas/knowledge/category/${encodeURIComponent(b.id)}`,null,{method:"DELETE"});if(await Kt(),y(!1),!Oe.value||M!==tn)return;if(v(null),O?.ok===!0)h(null),w("null");_(O?.ok===!0?"Category deleted.":O?.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||!!B,onClick:()=>V(t),children:"Cancel"},void 0,!1,void 0,this),r("button",{type:"submit",disabled:C||!!B,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 qT({onClose:e}){let t=D(null),n=Xn.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),[f,m]=E(""),[h,g]=E(!1),[v,b]=E(""),[x,C]=E(!1),y=D(null);q(()=>{if(!d)return;let N=document.activeElement;return y.current?.querySelector("button")?.focus(),()=>{if(N instanceof HTMLElement&&N.isConnected)N.focus()}},[d]);let k=s,_=a!==null&&JSON.stringify(a)!==JSON.stringify(c),I=(N)=>{if(h)return;if(_)p(()=>N);else N()},w=()=>{if(d)p(null);else if(x)C(!1);else I(e)};bn(t,!0,{onEscape:w});let P=(N)=>{i(N?structuredClone(N):null),l(null),u(null),C(!1),b("")},L=(N,Y)=>{if(a)l({...a,vocabulary:a.vocabulary.map((B,J)=>J===N?{...B,...Y}:B)})};return r("div",{class:"knowledge-backdrop",onKeyDown:(N)=>{if(N.key==="Escape")N.preventDefault(),N.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:()=>I(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 N=d;p(null),N()},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:()=>I(()=>{P(null);let N={id:crypto.randomUUID(),name:"",vocabulary:[]};u(structuredClone(N)),l(N)}),children:"Add preset"},void 0,!1,void 0,this),r("div",{class:"category-library",role:"group","aria-label":"Workspace relation presets",children:n.map((N)=>r("button",{type:"button",class:"category-choice",disabled:h,"aria-pressed":(a?.id??s?.id)===N.id,onClick:()=>I(()=>P(N)),children:[r("strong",{children:N.name},void 0,!1,void 0,this),r("span",{children:N.vocabulary.map((Y)=>Y.kind).join(" · ")||"No relation kinds"},void 0,!1,void 0,this)]},N.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:Ho,onSubmit:async(N)=>{if(N.preventDefault(),h)return;if(new Set(a.vocabulary.map((B)=>B.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)P(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:(N)=>l({...a,name:N.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((N,Y)=>r("div",{class:"vocabulary-row",children:[r("input",{required:!0,pattern:".*\\S.*","aria-label":`Kind ${Y+1}`,maxLength:80,disabled:h,value:N.kind,onInput:(B)=>L(Y,{kind:B.currentTarget.value})},void 0,!1,void 0,this),r("select",{"aria-label":`Ink ${Y+1}`,disabled:h,value:N.ink,onChange:(B)=>L(Y,{ink:B.currentTarget.value}),children:["supports","contradicts","cites","derived","informs","related"].map((B)=>r("option",{children:B},B,!1,void 0,this))},void 0,!1,void 0,this),r("label",{children:[r("input",{type:"checkbox",disabled:h,checked:N.directed,onChange:(B)=>L(Y,{directed:B.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((B,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:()=>I(()=>P(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((N)=>r("li",{style:{"--relation-ink":`var(--c-rel-${N.ink})`},children:[r("strong",{children:N.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":N.ink==="related"?"3 5":void 0},void 0,!1,void 0,this),N.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:[N.ink," · ",N.directed?"Directed: A → B":"Undirected: A — B"]},void 0,!0,void 0,this)]},N.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:f,onChange:(N)=>m(N.currentTarget.value),children:[r("option",{value:"",children:"Choose a board"},void 0,!1,void 0,this),Ge.value.map((N)=>r("option",{value:N.id,children:N.name},N.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||!f,onClick:async()=>{if(h||!f)return;g(!0);let N=await vr(f,{relationVocabulary:k.vocabulary});g(!1),b(N?"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 N=await pe("relationPresetRemove",`/api/canvas/knowledge/relation-preset/${encodeURIComponent(k.id)}`,null,{method:"DELETE"});if(await Kt(),g(!1),C(!1),N?.ok)P(null);b(N?.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 GT(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 Qd(e)}var ar=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function KT(e){return(e.links?.length??0)+(e.backlinks?.length??0)}async function Ag(e){let t=await On("New board","Board name",{confirm:"Create"});if(t)await Ek(t,e)}var VT="pmx-canvas-home-collapsed";function IL(){try{let e=localStorage.getItem(VT);if(e)return new Set(JSON.parse(e))}catch{}return new Set([CT])}function EL(e){try{localStorage.setItem(VT,JSON.stringify([...e]))}catch{}}var oc=(e,t)=>e.folder===t||!!e.folder?.startsWith(`${t}/`),lr=(e)=>e.split("/").at(-1)??e;function AL({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 XT(){let e=Ge.value,t=Oe.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,f]=E(!1),[m,h]=E(null),[g,v]=E(!1),[b,x]=E(!1),[C,y]=E(null),[k,_]=E(null),[I,w]=E(""),[P,L]=E([]),[N,Y]=E(IL),[B,J]=E(!1),[X,V]=E(!1),ee=D(null),he=D(null),A=[...new Set([...e.flatMap((F)=>F.folder?tc(F.folder):[]),...(Xn.value?.folders??[]).flatMap((F)=>tc(F.path)),...l.flatMap(tc)])].sort((F,Ie)=>F.localeCompare(Ie)),te=(F)=>A.filter((Ie)=>F?Ie.startsWith(`${F}/`)&&!Ie.slice(F.length+1).includes("/"):!Ie.includes("/")),M=I.trim().toLocaleLowerCase(),O=e.filter((F)=>F.pin),Pe=O.reduce((F,Ie)=>F+(Ie.mapChars??0),0),Fe=te(s),De=e.filter((F)=>(F.folder??"")===s).sort((F,Ie)=>(Ie.lastOpenedAt??"").localeCompare(F.lastOpenedAt??"")),Ae=M?e.filter((F)=>`${F.name} ${F.folder??""}`.toLocaleLowerCase().includes(M)):[],ve=e.find((F)=>F.id===m)??null,z=e.find((F)=>F.id===C),re=e.find((F)=>F.id===k),Ne=new Set(e.filter((F)=>!s||oc(F,s)).map((F)=>F.id)),ke=Object.entries(Xn.value?.cards??{}).filter(([F])=>Ne.has(JSON.parse(F)[0])).map(([,F])=>F),ae=ke.filter((F)=>!F.retired&&(F.due||F.sources.length)).length,Se=ke.filter((F)=>F.unknown).length,de=Xn.value?.resolvedFolders[s]?.category,Ue=new Map;for(let[F,Ie]of Object.entries(Xn.value?.cards??{})){if(Ie.retired||!(Ie.due||Ie.sources.length))continue;let[S,K]=JSON.parse(F),ue=Ue.get(S)??[];ue.push(K),Ue.set(S,ue)}let xe=M?Ae:De,qe=async(F)=>{if(!Oe.value)return;let Ie=tn,S=Ue.get(F)?.[0];if(!S)return;if(await zt({boardId:F,cardId:S})&&Oe.value&&Ie===tn&&se.value===F)Ro.value="To review"};q(()=>{let F=I.trim();if(!F){L([]);return}let Ie=!1,S=window.setTimeout(()=>{pe("searchLibrary",`/api/canvas/search?q=${encodeURIComponent(F)}&scope=library&limit=30`,null).then((K)=>{if(!Ie)L(K?.results??[])})},150);return()=>{Ie=!0,window.clearTimeout(S)}},[I]),q(()=>{if(g)he.current?.querySelector('[role="menuitem"]')?.focus()},[g]),q(()=>{if(m&&!e.some((F)=>F.id===m))h(null)},[e,m]),Me(()=>{if(i!=="Folders"||!m)return;let F=(Ie)=>{if(!ir(Ie))return;Ie.preventDefault(),h(null),x(!1)};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[i,m]);let W=(F)=>zt(F),ye=(F)=>{let Ie=new Set(N);if(Ie.has(F))Ie.delete(F);else Ie.add(F);Y(Ie),EL(Ie)},He=(F)=>{a(F),w(""),h(null),J(!1)},R=(F)=>{h(F),v(!1),x(!1)},ne=async()=>{let F=await On("New folder","Folder name",{confirm:"Create"});if(!F)return;let Ie;try{Ie=ip(s?`${s}/${F}`:F)}catch{return}if(!Ie)return;c((S)=>[...S,Ie]),He(Ie)},Ce=async(F)=>{let Ie=await On("Rename board","Board name",{initial:F.name,confirm:"Rename"});if(Ie&&Ie!==F.name)await vr(F.id,{name:Ie})},Te=(F,Ie)=>{let S=te(F),K=!N.has(F),ue=e.filter((je)=>oc(je,F)).length,$e=e.some((je)=>je.pin&&oc(je,F));return r("li",{children:[r("div",{class:`home-tree-row${s===F&&!M?" is-selected":""}`,"data-folder":F,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 ${lr(F)}`:`Unfold ${lr(F)}`,"aria-expanded":K,onClick:()=>ye(F),children:K?r(js,{},void 0,!1,void 0,this):r(oi,{},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:()=>He(F),children:lr(F)},void 0,!1,void 0,this),$e&&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((je)=>Te(je,Ie+1))},void 0,!1,void 0,this)]},F,!0,void 0,this)},fe=r("ul",{class:"home-tree","aria-label":"Folders",children:[te("").map((F)=>Te(F,0)),r("li",{children:r("div",{class:`home-tree-row is-unfiled${s===""&&!M?" is-selected":""}`,children:[r("span",{class:"home-tree-chevron"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-tree-name",onClick:()=>He(""),children:"Unfiled"},void 0,!1,void 0,this),r("span",{class:"home-tree-count",children:e.filter((F)=>!F.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),it=r("ul",{class:"home-pinned","aria-label":"Pinned boards",children:O.map((F)=>r("li",{children:r("button",{type:"button",class:"home-pinned-row",onClick:()=>He(F.folder??""),children:[r("span",{class:"home-pin-dot","aria-hidden":"true",children:r(uo,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"home-pinned-name",children:F.name},void 0,!1,void 0,this),r("span",{class:"home-tree-count",children:F.folder?lr(F.folder):"Unfiled"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},F.id,!1,void 0,this))},void 0,!1,void 0,this),Ht=r("label",{class:"home-search",children:[r(Mu,{},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:I,onInput:(F)=>w(F.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ye=(F)=>r("li",{children:r("article",{class:`home-card${F.pin?" is-pinned":""}${m===F.id?" is-selected":""}`,"data-testid":"home-board","data-board-id":F.id,children:[r("button",{type:"button",class:"home-card-select","aria-label":F.name,"aria-pressed":m===F.id,onClick:()=>R(F.id),onDblClick:()=>void Mn(F.id),children:[r(AL,{board:F},void 0,!1,void 0,this),r("span",{class:"home-card-body",children:[r("span",{class:"home-card-name",children:F.name},void 0,!1,void 0,this),r("span",{class:"home-card-readme",children:F.summary??"No README yet."},void 0,!1,void 0,this),r("span",{class:"home-card-meta",children:[r("span",{children:ar(F.nodeCount,"card")},void 0,!1,void 0,this),KT(F)>0&&r("span",{children:["↔ ",ar(KT(F),"link")]},void 0,!0,void 0,this),r("span",{class:"home-card-when",children:GT(F.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&&Ue.has(F.id)&&r("button",{type:"button",class:"home-card-review","aria-label":`Review ${F.name}`,onClick:()=>void qe(F.id),children:["⧗ Review ",ar(Ue.get(F.id).length,"card")]},void 0,!0,void 0,this),r(ho,{board:F},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},F.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:()=>R(null)},void 0,!1,void 0,this),r("div",{class:"home-details-head",children:[r("span",{class:"home-details-folder",children:ve.folder?lr(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 $s(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 ",ar(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),Nk(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&&Ue.has(ve.id)&&r("button",{type:"button",class:"home-button",onClick:()=>void qe(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(ml,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),g&&r("span",{ref:he,class:"home-more-menu",role:"menu",onKeyDown:(F)=>{let Ie=[...he.current?.querySelectorAll('[role="menuitem"]')??[]],S=Ie.indexOf(document.activeElement);if(F.key==="Escape")F.preventDefault(),v(!1),ee.current?.focus();else if(F.key==="ArrowDown"||F.key==="ArrowUp"){F.preventDefault();let K=F.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(([F,Ie])=>r("button",{type:"button",role:"menuitem",class:"home-more-item",onClick:()=>{v(!1),Ie()},children:F},F,!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(WT,{folder:u||void 0,onClose:()=>d(null)},u,!1,void 0,this),p&&r(qT,{onClose:()=>f(!1)},void 0,!1,void 0,this),r("nav",{class:"home-view-tabs","aria-label":"Library view",children:[["Folders","Map","Graph","Review"].filter((F)=>t||F!=="Review").map((F)=>r("button",{type:"button",class:"home-button","aria-pressed":i===F,onClick:()=>o(F),children:F},F,!1,void 0,this)),r("button",{type:"button",class:"home-button",onClick:()=>f(!0),children:"Relation presets"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i==="Map"||i==="Graph"?i==="Map"?r(RT,{},void 0,!1,void 0,this):r(DT,{},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${B?" 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:ar(e.length,"board")},void 0,!1,void 0,this),t&&r("button",{type:"button",class:"home-button",onClick:()=>{if(Oe.value)d("")},children:"Categories"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ht,O.length>0&&r("section",{class:"home-library-section",children:[r("span",{class:"home-section-label",children:"Pinned boards"},void 0,!1,void 0,this),it,r("span",{class:"home-pinned-cost",children:["≈ ",Jl(Pe)," tokens · ",ar(O.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),fe,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:[Ht,O.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(uo,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"home-narrow-context-label",children:["In context: ",ar(O.length,"board")]},void 0,!0,void 0,this),r("span",{class:"home-narrow-context-cost",children:["≈ ",Jl(Pe)," 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&&it]},void 0,!0,void 0,this),r("button",{type:"button",class:"home-narrow-picker","aria-expanded":B,onClick:()=>J(!B),children:[s?lr(s):"Library",r("span",{class:"home-tree-count",children:["· ",s?e.filter((F)=>oc(F,s)).length:De.length," ▾"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i==="Review"?r(BT,{folder:s,folders:A,onScopeChange:He},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:()=>He(""),children:"Library"},void 0,!1,void 0,this),s&&tc(s).map((F)=>r("span",{children:[r("span",{class:"home-crumb-sep",children:"/"},void 0,!1,void 0,this),r("button",{type:"button",onClick:()=>He(F),children:lr(F)},void 0,!1,void 0,this)]},F,!0,void 0,this))]},void 0,!0,void 0,this),r("h1",{class:"home-view-title",children:M?`Results for “${I.trim()}”`:s?lr(s):"Library"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&r("button",{type:"button",class:"home-button",onClick:()=>{if(Oe.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 Ag(s||null),children:s?"New board here":"New board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&Xn.value&&!M&&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: ",ar(ae,"card")]},void 0,!0,void 0,this),r("span",{children:["No review policy: ",ar(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):M?r(be,{children:[P.length>0&&r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:["Cards · ",P.length]},void 0,!0,void 0,this),r("ul",{class:"home-hits","aria-label":"Library search results",children:P.map((F)=>r("li",{children:r("button",{type:"button",class:"home-hit",onClick:()=>void W(F),children:[r("span",{class:"home-card-name",children:F.title||F.boardTitle},void 0,!1,void 0,this),t&&F.qualification?.retired&&r("span",{class:"category-tag",children:"Retired"},void 0,!1,void 0,this),r("span",{class:"home-card-meta",children:[F.boardTitle," · ",F.snippet]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},`${F.boardId}:${F.cardId}`,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ae.length>0?r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:["Boards · ",Ae.length]},void 0,!0,void 0,this),r("ul",{class:"home-cards",children:Ae.map(Ye)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):P.length===0&&r("div",{class:"home-view-empty",role:"status",children:["No boards match “",I.trim(),"”."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):r(be,{children:[Fe.length>0&&r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:["Folders · ",Fe.length]},void 0,!0,void 0,this),r("ul",{class:"home-folders",children:Fe.map((F)=>{let Ie=e.filter((ue)=>oc(ue,F)),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":F,onClick:()=>He(F),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:lr(F)},void 0,!1,void 0,this),r("span",{class:"home-folder-meta",children:[ar(Ie.length,"board"),S?` · opened ${GT(S)}`:""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},F,!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 ${lr(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(Ye)},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,z&&r(TT,{board:z,folders:A,onClose:()=>y(null)},z.id,!1,void 0,this),re&&r(IT,{board:re,onClose:()=>_(null)},re.id,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var cs=ie(!1);function RL(e){return e>=1048576?`${(e/1024/1024).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}function JT(){let[e,t]=E(!1),[n,o]=E(!1),[i,s]=E(null),[a,l]=E(null),[c,u]=E(!1),[d,p]=E(""),f=cs.value,m=se.value;if(q(()=>{if(!f||!m)return;let g=!0;return l(null),p(""),s(null),pe("exportPreview",`/api/canvas/export/preview?board=${encodeURIComponent(m)}&includeFiles=${e}&includeDerivedText=${n}`,null).then((v)=>{if(g)s(v?.manifest??null)}),()=>{g=!1}},[f,e,n,m]),q(()=>{o(!1)},[f,m]),q(()=>{if(!f)return;let g=(v)=>{if(v.key!=="Escape")return;v.stopPropagation(),cs.value=!1};return window.addEventListener("keydown",g,{capture:!0}),()=>window.removeEventListener("keydown",g,{capture:!0})},[f]),!f)return null;let h=async()=>{if(!i||i.boardId!==se.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&&se.value===i.boardId)l(g)};return r("div",{class:"text-prompt-backdrop",onPointerDown:()=>cs.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 (",RL(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:tt()?r("button",{type:"button",disabled:c,onClick:async()=>{u(!0),p("");try{await Gw(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),tt()&&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:()=>cs.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 Rg({presence:e,size:t=18}){return r("span",{class:"writer-avatar",style:{background:So(e.sessionId),width:`${t}px`,height:`${t}px`},"aria-hidden":"true",children:Md(e.label)},void 0,!1,void 0,this)}function YT(){let e=$d.value;if(tr.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=ts.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:()=>{ts.value=!o},children:[r("span",{class:"external-indicator-avatars",children:e.slice(0,3).map((i)=>r(Rg,{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 PL(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 NL(e){return e.reduce((t,n)=>n.lastSeenAt>t?n.lastSeenAt:t,"")}function ML(){return[...qt.value.values()].filter((e)=>!e.auto&&e.phase==="forming")}function QT(){let e=ts.value,t=$d.value,n=nr(e?1e4:0);if(Me(()=>{if(!e)return;let l=(c)=>{if(c.key!=="Escape"||c.defaultPrevented)return;if(c.preventDefault(),pa.value)pa.value=!1;else ts.value=!1};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e]),!e||tr.value||t.length===0)return null;let o=Jh.value,i=ML().filter((l)=>!o||(l.source??"")===o),s=fi.value.filter((l)=>!o||l.sessionId===o),a=(l,c)=>r("button",{type:"button",class:`activity-filter${o===l?" is-active":""}`,style:l?{"--writer":So(l)}:void 0,"aria-pressed":o===l,onClick:()=>{Jh.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(NL(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:()=>{ts.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:()=>{Li(l).then((c)=>{if(c)zi(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}=PL(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:So(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:()=>{pa.value=!0},children:"Writers"},void 0,!1,void 0,this),xt.value&&r("button",{type:"button",class:"activity-feed-link is-accent",onClick:()=>{ts.value=!1,vi()},children:["Start session ",r(ri,{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 zL(){let e=[];if(To.value)e.push("scoped");if(Co.value.length>0)e.push("gated");return e.length>0?e.join(" + "):"open"}function eI(){let e=pa.value,t=nr(e?1e4:0),n=D(null);if(bn(n,e),!e)return null;let o=xt.value?en.value.filter((a)=>a.attached):[],i=$d.value,s=()=>{pa.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:xr.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:[xt.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(Rg,{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:zL()},void 0,!1,void 0,this)]},a.sessionId,!0,void 0,this)),r("div",{class:"writers-section",children:xt.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(Rg,{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 tI({nodeId:e}){let t=se.value,[n,o]=E(null),[i,s]=E(!1),a=et.value,l=H.value,c=Ge.value;q(()=>{let m=!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(!m)o(h),s(!h)});return()=>{m=!0}},[t,e,a,l,c]);let u=t?Mt({boardId:t,cardId:e}):"",d=n?.edges.filter((m)=>m.kind!=="member"&&(m.from===u||m.to===u))??[],p=(m)=>{let h=m.to===u;if(h&&m.relationKind==="supports")return"Evidence for";if(h&&m.relationKind==="contradicts")return"Evidence against";let g=jd({kind:m.relationKind,type:m.type});if(g)return(g==="from"?!h:h)?"Used by":"Sources";if(m.relationKind==="cites"||m.type==="references")return h?"Used by":"Sources";if(!h&&m.relationKind==="supports")return"Used by";return"Connections"},f=["Evidence for","Evidence against","Sources","Used by","Connections"];return d.sort((m,h)=>f.indexOf(p(m))-f.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((m,h)=>{let g=m.from===u,v=g?m.target:m.source,b=n?.nodes.find((y)=>y.key===Mt(v)),x=c.find((y)=>y.id===m.source.boardId),C=mo({kind:m.relationKind,type:m.type},x?.relationVocabulary);return r("div",{class:"relation-row",children:[(h===0||p(d[h-1])!==p(m))&&r("h4",{children:p(m)},void 0,!1,void 0,this),r("span",{class:"relation-kind",style:{color:`var(--c-rel-${C.ink})`},children:[g?"→":"←"," ",m.relationKind??m.type??m.kind]},void 0,!0,void 0,this),m.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),m.label&&r("span",{children:m.label},void 0,!1,void 0,this),r("p",{children:m.reason??"No reason recorded."},void 0,!1,void 0,this)]},m.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 nI(e,t){switch(e.type){case"markdown":return r(Qu,{node:e,expanded:t},void 0,!1,void 0,this);case"mcp-app":return r(di,{node:e,expanded:t},void 0,!1,void 0,this);case"webpage":return r(Ad,{node:e,expanded:t},void 0,!1,void 0,this);case"json-render":return r(di,{node:e,expanded:t},void 0,!1,void 0,this);case"graph":return r(di,{node:e,expanded:t},void 0,!1,void 0,this);case"board":return r(Kd,{node:e},void 0,!1,void 0,this);case"prompt":return r(Rd,{node:e},void 0,!1,void 0,this);case"response":return r(Pd,{node:e,expanded:t},void 0,!1,void 0,this);case"status":return r(Id,{node:e},void 0,!1,void 0,this);case"context":return r($u,{node:e,expanded:t},void 0,!1,void 0,this);case"ledger":return r(Bu,{node:e},void 0,!1,void 0,this);case"trace":return r(Nd,{node:e},void 0,!1,void 0,this);case"file":return r(Du,{node:e,expanded:t},void 0,!1,void 0,this);case"diff":return r(Lu,{node:e},void 0,!1,void 0,this);case"mermaid":return r(ad,{node:e,expanded:t},void 0,!1,void 0,this);case"image":return r(Ed,{node:e,expanded:t},void 0,!1,void 0,this);case"html":return r(Hl,{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 oI(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 $L(e){if(!e)return 0;return e.split(/\s+/).filter(Boolean).length}function LL(e,t){return e!==null&&typeof e==="object"&&e.source===Qn&&e.type==="presentation-exit"&&e.token===t}function OL(e){return e==="ArrowRight"||e==="PageDown"||e===" "||e==="ArrowLeft"||e==="PageUp"||e==="Home"||e==="End"}function rI(e){return e instanceof HTMLElement&&Boolean(e.closest(".html-presentation-exit"))}function iI(){let e=Bt.value,t=e?H.value.get(e):void 0,[n,o]=E(!1),[i,s]=E(null),[a,l]=E(!1),[c,u]=E(""),d=D(null),p=D(null),f=oe(()=>{l(!1),Cr()},[]),m=oe(()=>{u(`presentation-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`),l(!0)},[]),h=oe((A)=>{document.querySelector(".html-presentation-overlay iframe.html-node-frame-presentation")?.contentWindow?.postMessage({source:Qn,token:c,...A},"*")},[c]),g=oe(()=>{l(!1)},[]),v=oe((A)=>{if(A.key==="Escape"){A.preventDefault(),A.stopPropagation(),l(!1);return}if(A.key==="Tab"&&!rI(A.target)){A.preventDefault(),A.stopPropagation(),p.current?.focus();return}if((A.key===" "||A.key==="Enter")&&rI(A.target))return;if(!OL(A.key))return;A.preventDefault(),A.stopPropagation(),h({type:"presentation-key",key:A.key})},[h]),b=oe((A)=>{if(A.target.classList.contains("expanded-overlay-backdrop"))Cr()},[]),x=oe(()=>{if(!t)return;let A=oI(t);if(!A)return;navigator.clipboard.writeText(A).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})},[t]),C=oe(()=>{if(!e)return;lo(e)},[e]);q(()=>{l(!1)},[e]),Me(()=>{if(!a)return;let A=()=>{let O=d.current;if(!O||O.contains(document.activeElement))return;O.focus()},te=[0,50,150].map((O)=>window.setTimeout(A,O)),M=(O)=>{if(!LL(O.data,c))return;l(!1)};return document.addEventListener("keydown",v,!0),window.addEventListener("message",M),()=>{te.forEach((O)=>{window.clearTimeout(O)}),document.removeEventListener("keydown",v,!0),window.removeEventListener("message",M)}},[v,c,a]);let y=D(null),k=oe(()=>e?document.querySelector(`.canvas-node[data-node-id="${CSS.escape(e)}"]`):null,[e]),_=Oe.value&&Ct.value?.nodeId===e,I=!Oe.value&&Ct.value?.nodeId===e&&!!document.activeElement?.closest(".lifecycle-dialog");if(bn(y,t!==void 0&&!_,{restoreTo:k}),Me(()=>{if(I)document.querySelector('button[aria-label="Settings"]')?.focus({preventScroll:!0})},[_]),!t)return null;let w=t.data.title||t.data.path?.split("/").pop()||an[t.type],P=oI(t),L=$L(P),N=e?kt.value.has(e):!1,Y=P.length>0,B=zo.value===e,J=t.type==="mcp-app"||t.type==="webpage"||t.type==="json-render"||t.type==="graph",X=q_(t),V=Do(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((A)=>typeof A==="string"&&A.length>0).join(" · "):null;return r("div",{class:"expanded-overlay-backdrop",onPointerDown:b,style:{pointerEvents:B?"none":"auto"},children:r("div",{ref:y,class:`expanded-overlay-panel${N?" 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:an[t.type]},void 0,!1,void 0,this),r(_e,{label:N?"In agent context — click to unpin":"Pin as agent context",children:r("button",{type:"button",class:`expanded-pin${N?" is-on":""}`,onClick:C,"aria-label":N?"In agent context — click to unpin":"Pin as agent context","aria-pressed":N,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:[Oe.value&&r("button",{type:"button",class:"expanded-action-btn",onClick:()=>Es(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),od(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 rd(t),children:["Open in tab ",r(ri,{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:m,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:f,"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:nI(t,!0)},void 0,!1,void 0,this):nI(t,!0)},void 0,!1,void 0,this),i===e&&r(tI,{nodeId:t.id},e,!1,void 0,this)]},void 0,!0,void 0,this),r(Wd,{node:t},void 0,!1,void 0,this),r("div",{style:{"--ax-dock-bleed":"0px","--ax-dock-pad":"16px"},children:r(Gd,{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,L>0?`${L.toLocaleString()} word${L!==1?"s":""}`:null].filter(Boolean).join(" · ")||an[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${B?" is-saving":""}`,children:B?"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(Hl,{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 aI=168,lI=112,up=20;function sI(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,f=d+o/t.scale,m={minX:Math.min(s,u)-up,minY:Math.min(a,d)-up,maxX:Math.max(l,p)+up,maxY:Math.max(c,f)+up},h=m.maxX-m.minX||1,g=m.maxY-m.minY||1;return{bounds:m,scale:Math.min(aI/h,lI/g)}}function cI({viewport:e,nodes:t,onNavigate:n,containerWidth:o,containerHeight:i}){let s=D(null),a=D(!1),l=t.value,c=e.value,u=sI(l,c,o,i),{bounds:d,scale:p}=u,f=(w)=>(w-d.minX)*p,m=(w)=>(w-d.minY)*p,h=oe((w)=>{let P=s.current;if(!P)return;let L=P.getBoundingClientRect(),N=(w.clientX-L.left)/L.width*aI,Y=(w.clientY-L.top)/L.height*lI,B=sI(t.value,e.value,o,i),J=e.value,X=o/J.scale,V=i/J.scale,ee=N/B.scale+B.bounds.minX,he=Y/B.scale+B.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 P=(N)=>{if(a.current)h(N)},L=()=>{a.current=!1,document.removeEventListener("pointermove",P),document.removeEventListener("pointerup",L)};document.addEventListener("pointermove",P),document.addEventListener("pointerup",L)},[h]),v=st.value,b=kt.value,x=tr.value?Ld.value:new Set,C=To.value,y=C?Fd(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:Od(w,(P)=>l.get(P))})).filter((w)=>w.at!==null),_=-c.x/c.scale,I=-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 P=w.type==="group";return r("span",{class:`minimap-node${P?" 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:`${f(w.position.x)}px`,top:`${m(w.position.y)}px`,width:`${Math.max(P?6:4,w.size.width*p)}px`,height:`${Math.max(P?5:3,w.size.height*p)}px`}},w.id,!1,void 0,this)}),y&&r("span",{class:"minimap-fence",style:{left:`${f(y.x)}px`,top:`${m(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:`${f(w.at.x)-4}px`,top:`${m(w.at.y)-4}px`,"--identity-color":So(w.id)}},w.id,!1,void 0,this)),r("span",{class:"minimap-frame",style:{left:`${f(_)}px`,top:`${m(I)}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 uI(){let e=st.value.size,t=Yd("--selection-bar-height"),n=oe(()=>{let l=Array.from(st.value);if(l.length===0)return;_u(l),$n()},[]),o=oe(()=>{let l=Array.from(st.value);if(l.length===0)return;Ns({title:"Group",childIds:l}),$n()},[]),i=oe(()=>{let l=Array.from(st.value);for(let c=0;c<l.length;c++)for(let u=c+1;u<l.length;u++)yr(l[c],l[u],"relation");$n()},[]),s=oe(()=>{let l=Array.from(st.value);for(let c of l)Xr(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:()=>am("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:()=>am("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:()=>qk(),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:()=>Gk(),children:r(Tr,{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 dp(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 pp(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 DL={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"vetoed"},BL={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"cancelled"},dI=[{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"}],FL=Object.fromEntries(dI.map((e)=>[e.id,e.hint])),HL={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 Pg(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 UL({item:e}){let t=DL[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:BL[e.status]??t},void 0,!1,void 0,this),r("span",{class:"session-item-time",children:Pg(e.updatedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function pI({gate:e,now:t}){let[n,o]=E(null),i=async(l)=>{o(l),await EC(e,l),o(null)},s=e.nodeIds[0],a=dp(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 ",pp(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:Pg(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function fI({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),AC(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 jL(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 mI({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:jL(e)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function hI(){let e=To.value,t=st.value.size,[n,o]=E(!1),i=(s)=>{o(!0),_C(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([...st.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 ZL(e){if(e==="browser")return"you";return en.value.find((n)=>n.sessionId===e||n.source===e)?.label??e}function WL({entry:e}){let t=Wl.value.has(e.id);return r("li",{class:`session-timeline-row tone-${HL[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":So(e.who)},children:ZL(e.who)},void 0,!1,void 0,this),r("span",{class:"session-item-time",children:Pg(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 sg(e),children:[r(km,{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 gI(){let e=Co.value,t=nr();if(!eo.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:()=>eo.value=!1,disabled:e.length>0,children:r(oi,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(hI,{},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(pI,{gate:n,now:t},n.id,!1,void 0,this)),os.value.map((n)=>r(fI,{gate:n},n.id,!1,void 0,this)),ig.value.map((n)=>r(mI,{gate:n},n.id,!1,void 0,this))]},void 0,!0,void 0,this),fa.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 ql(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 yI(){q(()=>()=>{eo.value=!1},[]);let e=mi.value,t=SC.value,n=Co.value,o=os.value,i=ig.value,s=IC.value,[a,l]=E(!1),[c,u]=E(null),d=nr();if(q(()=>{yi()},[]),!(eo.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:()=>{eo.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: ${pi(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:pi(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 ql(e),children:"End"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("button",{type:"button",class:"session-collapse",onClick:()=>{eo.value=!1},"aria-label":"Collapse session panel",children:r(oi,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(hI,{},void 0,!1,void 0,this),(()=>{let f=s.find((m)=>m.undoable&&!Wl.value.has(m.id));if(!f)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: ",f.body]},void 0,!0,void 0,this),r("button",{type:"button",class:"session-undo-btn",onClick:()=>void sg(f),children:[r(km,{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 f=t.filter((C)=>C.status==="in-progress"||C.status==="todo").length,m=t.filter((C)=>C.status!=="cancelled"),h=m.filter((C)=>C.status==="done").length,g=t.length-m.length,v=n.length>0,b=a||v,x=f>0?`${f} running`:m.length>0?`${h}/${m.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:[f>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(oi,{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(pI,{gate:C,now:d},C.id,!1,void 0,this)),o.map((C)=>r(fI,{gate:C},C.id,!1,void 0,this)),i.map((C)=>r(mI,{gate:C},C.id,!1,void 0,this)),t.map((C)=>r(UL,{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:dI.map((f)=>r("button",{type:"button",class:`activity-filter${rs.value===f.id?" is-active":""}`,"aria-pressed":rs.value===f.id,onMouseEnter:()=>u(f.id),onMouseLeave:()=>u((m)=>m===f.id?null:m),onFocus:()=>u(f.id),onBlur:()=>u((m)=>m===f.id?null:m),onClick:()=>{rs.value=f.id},children:f.label},f.id,!1,void 0,this))},void 0,!1,void 0,this),r("div",{class:"session-timeline-hint","data-testid":"timeline-filter-hint",children:FL[c??rs.value]},void 0,!1,void 0,this),s.length===0?r("div",{class:"session-empty",children:rs.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((f)=>r(WL,{entry:f},f.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 Ng(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 vI=(e)=>e.map((t)=>t.title).join(", ");function bI(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function qL({context:e,label:t,snapshotId:n}){let[o,i]=E(!1),[s,a]=E([]),[l,c]=E(!1),[u,d]=E(null),[p,f]=E(!1),m=e.edited.length>0&&e.edited.every((x)=>s.includes(x.id))?"undone":l?"kept":null;q(()=>{a([]),c(!1),d(null)},[e]);let h=async(x)=>{if(!n||p)return;f(!0);try{let C=await NC(n,x.filter((y)=>!s.includes(y.id)));return a((y)=>[...y,...C.restored]),C}finally{f(!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=Fn.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:gi.warn},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{children:[vI(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";ma(`${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(uo,{},void 0,!1,void 0,this):r("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:r("path",{d:gi[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!==se.value),onClick:()=>Kk(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:m!==null||p||e.edited.some((C)=>C.boardId&&C.boardId!==se.value),onClick:()=>{h(e.edited).then((C)=>{if(C?.ok)c(!0)})},children:m==="undone"?"✓ Undone":m==="kept"?"Kept your edits":"Undo"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x.key==="edited"&&m&&r("div",{class:"session-receipt-context-items",children:m==="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(KL,{node:C,canUndo:n!==null,undoing:p,open:u===or(C),onToggle:()=>d(u===or(C)?null:or(C)),undone:s.includes(C.id),onUndo:()=>void h([C])},or(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("; "):vI(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:()=>Gl(!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 GL(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 KL({node:e,canUndo:t,undoing:n,open:o,onToggle:i,undone:s,onUndo:a}){let l=!e.boardId||e.boardId===se.value,c=l?H.value.get(e.id):void 0,u=Ge.value.find((m)=>m.id===e.boardId),d=Ke(()=>o?GL(e.before??"",e.after??""):[],[o,e.before,e.after]),p=D(null);Me(()=>{for(let m of p.current?.querySelectorAll(".session-receipt-diff-text")??[]){let h=m.querySelector("del, ins");if(h)m.scrollTop=h.getBoundingClientRect().top-m.getBoundingClientRect().top-24}},[d]);let f=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((m,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:m.length?m.map(({text:g,changed:v},b)=>g==="…"&&(b===0||b===m.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||f||n,onClick:a,children:s?"✓ Undone":f?"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":f?"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 xI({onOpenSnapshots:e}){let t=ns.value,[n,o]=E(null),[i,s]=E(!1);if(q(()=>o(null),[t]),!xt.value||!t)return null;let a=t.snapshot?.boardId===se.value,l=Ge.value.find((f)=>f.id===t.snapshot?.boardId),c=async()=>{if(!t.snapshot||!a)return;s(!0);try{let f=await Gt(`/api/canvas/snapshots/${encodeURIComponent(t.snapshot.id)}/diff`,{headers:{"x-pmx-workbench":"1"}});if(f.ok){let m=await f.json();o(Ng(m.diff)??{added:0,removed:0,modified:0})}}finally{s(!1)}},u=bI(t.endedAt),d=t.startedAt?bI(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:Ud,"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(qL,{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 VL=[{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:Ft("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:Ft("0"),desc:"Reset viewport to origin"},{keys:`${Ft("+")} / ${Ft("−")}`,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:wl?"Delete / ⌫":"Delete / Backspace",desc:"Delete the selection (or the focused node)"},{keys:wl?"⌘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 wI({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:VL.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:tt()&&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 kI="Before session · ";function SI(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 fp(e){if(!e.startsWith(kI))return null;let t=e.slice(kI.length),n=t.lastIndexOf(" · ");return n>0?t.slice(0,n):t}function _I({open:e,onClose:t,anchorRef:n}){let[o,i]=E([]),[s,a]=E(!1),[l,c]=E(!1),[u,d]=E(null),[p,f]=E(""),[m,h]=E(null),[g,v]=E({}),b=D(null),x=D(null);q(()=>{if(!e)return;a(!0),xk().then((w)=>{i(w),a(!1)})},[e]),q(()=>{if(e)setTimeout(()=>x.current?.focus(),50)},[e]),q(()=>{if(!e)return;let w=(P)=>{let L=b.current,N=n.current;if(L&&!L.contains(P.target)&&N&&!N.contains(P.target))t()};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[e,t]),q(()=>{if(!e)return;let w=(P)=>{if(P.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 P=await wk(w);if(c(!1),P.ok&&P.snapshot)i((L)=>[P.snapshot,...L]),f("")},[p]),y=oe(async(w)=>{h(null),d(w);let P=await kk(w);if(d(null),P.ok)t()},[t]),k=oe(async(w)=>{if((await Sk(w)).ok)i((L)=>L.filter((N)=>N.id!==w));h(null)},[]),_=oe(async(w)=>{v((L)=>({...L,[w]:"loading"}));let P=await pe("snapshotDiff",`/api/canvas/snapshots/${encodeURIComponent(w)}/diff`,{});v((L)=>({...L,[w]:Ng(P.diff)??{added:0,removed:0,modified:0}}))},[]);if(!e)return null;let I=(w,P)=>m?.id===w.id?r(be,{children:[r("button",{type:"button",class:`snapshot-action-btn ${m.action==="delete"?"snapshot-action-confirm":"snapshot-action-restore"}`,onClick:()=>m.action==="delete"?k(w.id):y(w.id),disabled:u!==null,children:m.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:tt()?"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…":P},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)=>f(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:tt()?"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)=>fp(w.name)===null),...o.some((w)=>fp(w.name)!==null)?[{id:"__sessions-header__"}]:[],...o.filter((w)=>fp(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 P=fp(w.name),L=g[w.id];if(P!==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 — ",P]},void 0,!0,void 0,this),r("span",{class:"snapshot-item-time",children:SI(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":"",L&&L!=="loading"&&r("span",{class:"snapshot-item-diff",children:[" ","· since: ",L.added," added · ",L.removed," removed · ",L.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:L==="loading",onClick:()=>void _(w.id),children:L==="loading"?"Comparing…":"View diff"},void 0,!1,void 0,this),I(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:SI(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":""}`:""," · ",Qd(w.createdAt)]},void 0,!0,void 0,this),r("div",{class:"snapshot-item-actions",children:I(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 XL=8;function CI({fallbackName:e}){let[t,n]=E(!1),o=D(null),i=D(null),s=D(null);Me(()=>{if(!t)return;let p=(m)=>{if(m.target instanceof Node&&!o.current?.contains(m.target)&&!s.current?.contains(m.target))n(!1)},f=(m)=>{if(m.key==="Escape")m.stopPropagation(),n(!1),i.current?.focus()};return document.addEventListener("pointerdown",p,!0),document.addEventListener("keydown",f,!0),()=>{document.removeEventListener("pointerdown",p,!0),document.removeEventListener("keydown",f,!0)}},[t]);let a=Yn(),l=!io.value?e:a&&!ut.value?a.name:"Home",c=Ge.value.filter((p)=>ut.value||p.id!==se.value).slice(0,XL),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(js,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&u&&r(Ws,{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(zu,{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(ho,{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),Ag()},children:[r("span",{class:"board-switcher-icon","aria-hidden":"true",children:r(aS,{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(Tr,{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 TI=3,II={"waiting-approval":0,thinking:1,tooling:2,idle:3};function JL(){let[e,t]=E(null),n=D(null);Me(()=>{if(!e)return;let d=(m)=>{if(!n.current?.contains(m.target)&&!e.button.contains(m.target))t(null)},p=(m)=>{if(m.key==="Escape"&&!m.defaultPrevented)m.preventDefault(),t(null),e.button.focus({preventScroll:!0})},f=()=>t(null);return document.addEventListener("pointerdown",d,!0),document.addEventListener("keydown",p),window.addEventListener("resize",f),()=>{document.removeEventListener("pointerdown",d,!0),document.removeEventListener("keydown",p),window.removeEventListener("resize",f)}},[e]);let o=fa.value;if(q(()=>{if(e&&!e.button.isConnected)t(null)},[o,e]),!xt.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)=>(II[d.phase]??4)-(II[p.phase]??4)),a=s.slice(0,TI),l=s.slice(TI),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((f)=>f.parentAgentId!=null&&(f.parentAgentId===d.sessionId||f.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":So(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:(f)=>{f.stopPropagation(),t(e?.id===d.sessionId?null:{id:d.sessionId,button:f.currentTarget})},children:[Md(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:pi(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(EI,{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:(f)=>{f.stopPropagation(),ql({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(Ws,{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," · ",pi(d)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r(EI,{session:d,popover:!0},void 0,!1,void 0,this),r("button",{type:"button",class:"session-receipt-link",onClick:()=>{eo.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 EI({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=Fn.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:()=>Gl(!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(),Gl(!s,{sessionId:e.sessionId})},children:a},void 0,!1,void 0,this)}function YL(){let e=Co.value.length,t=e>0,n=nr(t?1000:0);if(!t)return null;let o=Co.value.map((i)=>dp(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:()=>eo.value=!0,children:[e," gate",e===1?"":"s",o!==void 0&&` · ${pp(o)}`]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function QL(){let[e,t]=E(!1);if(!xt.value||mi.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),vi().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 AI(){let e=D(null);Me(()=>{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=ao.value,n=cn.value,o=Ee.value,i=H.value.size,s=et.value.size,a=Ds.value,l=Array.from(H.value.values()).filter((g)=>g.type==="trace").length,[c,u]=E("");q(()=>{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=kg.value,p=d??(t==="connected"&&!n?"syncing":t),f=Yn(),m=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();Hs(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(CI,{fallbackName:c||"PMX Canvas"},void 0,!1,void 0,this),f&&!ut.value&&r(ho,{board:f},void 0,!1,void 0,this),r("span",{class:"top-bar-meta hud-collapsible-text",children:xr.value?xr.value.slice(0,12):"…"},void 0,!1,void 0,this),!ut.value&&r("span",{class:"top-bar-meta hud-collapsible-text",children:m},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(JL,{},void 0,!1,void 0,this),r(YL,{},void 0,!1,void 0,this),r(dT,{},void 0,!1,void 0,this),r(YT,{},void 0,!1,void 0,this),!tt()&&r(QL,{},void 0,!1,void 0,this),!ut.value&&r(be,{children:[r("div",{class:"top-bar-sep"},void 0,!1,void 0,this),r("div",{class:"top-bar-actions",children:[se.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:()=>{cs.value=!0},children:"Export"},void 0,!1,void 0,this)},void 0,!1,void 0,this),se.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:()=>{fl()},children:"Present"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Zoom out",shortcut:Ft("−"),children:r("button",{type:"button",class:"top-bar-btn",onClick:()=>ti(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:Ft("0"),children:r("button",{type:"button",class:"top-bar-zoom-label",onClick:()=>_r({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:Ft("+"),children:r("button",{type:"button",class:"top-bar-btn",onClick:()=>ti(1.25),"aria-label":"Zoom in",children:r(pS,{},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(Nu,{},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(eO,{boardOpen:!!se.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 eO({boardOpen:e,onFit:t}){let[n,o]=E(!1),i=D(null),s=D(null);Me(()=>{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(),f=p.indexOf(document.activeElement),m=d.key==="ArrowDown"?f+1:f-1;p[(m+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(()=>{cs.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 fl()),children:"Present board"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>ti(1.25)),children:"Zoom in"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>ti(0.8)),children:"Zoom out"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>_r({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 bi={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 rc(e,t,n,o={}){let i=bi[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 xi=null,sc=null,mp=0,wi=null,tO=3000,nO=2000,oO=1000,rO=80,RI=5000,iO=1e4,ic=!1,$r=null,ka=null,wa=null,us=0,ki=null;function sO(){if(tt())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 Sa=new Map;function ac(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 vp(e){if(!sc)return e;let t=sc.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 lc(e,t,n){return vp(rc(e,t,n))}function aO(){return sd([...H.value.values()],bi.markdown.w,bi.markdown.h)}function Ca(){if(!H.value.has("status-main"))kr(lc("status-main","status",{phase:"idle",message:"",elapsed:0}))}function lO(e,t){let n=`md-${ac(e)}`;if(H.value.get(n))Xe(n,{path:e,title:t}),gt.value=n;else{let i=aO(),s=lc(n,"markdown",{path:e,title:t,content:"",rendered:""});s.position=i,kr(s),$t(n)}}function cO(e){if(H.value.get("context-main"))Xe("context-main",{cards:e});else if(e.length>0){let o=lc("context-main","context",{cards:e});kr(o)}}function uO(e){let t=e.url,n=`mcp-${ac(t)}`;if(H.value.get(n))Xe(n,e);else kr(lc(n,"mcp-app",e)),$t(n)}function dO(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(H.value.get(o)){Xe(o,e);return}let{serverName:s,toolName:a}=e;if(s&&a){for(let[v,b]of H.value.entries())if(b.type==="mcp-app"&&b.data.mode==="ext-app"&&b.data.serverName===s&&b.data.toolName===a&&!b.data.toolResult){Xe(v,{...e});return}}let{_x:l,_y:c,_width:u,_height:d}=e,p=bi["mcp-app"],f=u??p.w,m=d??p.h,h=l===void 0||c===void 0?sd([...H.value.values()],f,m):null,g=vp(rc(o,"mcp-app",{mode:"ext-app",...e},{position:{x:l??h?.x??p.x,y:c??h?.y??p.y},size:{width:f,height:m}}));kr(g),$t(o,{recordHistory:!1})}function pO(e){let t=e.startsWith("ext-app-")?e:`ext-app-${e}`;if(H.value.has(t))return t;let n=`ext-app-${e}`;if(n!==t&&H.value.has(n))return n;for(let[o,i]of H.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&&H.value.has(t))return t;if(typeof e.toolCallId!=="string"||!e.toolCallId)return null;return pO(e.toolCallId)}function $I(e,t){if(typeof e!=="string"||!e)return null;if(typeof t!=="string"||!t)return null;let n=null;for(let[o,i]of H.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 LI(e){if(H.value.get("ledger-main"))Xe("ledger-main",e);else{let o=lc("ledger-main","ledger",e);o.collapsed=!0,kr(o)}}function $g(e){if(!El(e))return;if(document.documentElement.setAttribute("data-theme",e),la(),Qt.value!==e)Qt.value=e}function fO(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 mO(e){return e==="relation"||e==="depends-on"||e==="flow"||e==="references"}function Lg(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 OI(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 hO(e){let t=Lg(e),n=OI(e);return t&&n?{...t,...n}:null}function gO(e){if(typeof e.id!=="string"||!e.id)return null;if(!fO(e.type))return null;let t=Lg(e.position),n=OI(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,...yp(e.createdBy)?{createdBy:e.createdBy}:{},...yp(e.lastEditedBy)?{lastEditedBy:e.lastEditedBy}:{},data:o}}function yp(e){if(!e||typeof e!=="object")return!1;let t=e;return typeof t.actor==="string"&&typeof t.source==="string"}function yO(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(!mO(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}:{},...yp(e.changedBy)?{changedBy:e.changedBy}:{},...typeof e.changedAt==="string"?{changedAt:e.changedAt}:{},...yp(e.createdBy)?{createdBy:e.createdBy}:{},...typeof e.createdAt==="string"?{createdAt:e.createdAt}:{}}}function vO(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)=>Lg(o)).filter((o)=>o!==null),n=hO(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 PI="pmx-canvas-version-reload";function bO(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(PI)===i)return;window.sessionStorage.setItem(PI,i)}catch{return}window.location.reload()}function xO(e){let t=fi.value[0]?.id;if(aC(e),_o.value&&fi.value[0]?.id!==t)yi()}function wO(e){PC(e)}var ds=0,Mg=0,_a=null;function kO(e){Uf(e)}function SO(e){let t=_a;if(_a=null,e){if(t?.boardId===se.value)gp(t);return}let n=se.value,o=++ds;if(sc=null,cn.value=!1,su(),Hk(),pu(),hm({nodes:[],edges:[]}),t?.boardId===se.value)gp(t);if(se.value===null)Ud();if(Fn.value?.kind==="receipt")Fn.value=null;Qh({}),Lo.value=null,Og();let i=Mg,s=$o;mk(n).then((a)=>{if(o===ds&&i===Mg)gp({layout:a,boardId:n})}),pe("fetchPinnedContext","/api/canvas/pinned-context",{}).then((a)=>{if(o===ds&&s===$o)DI({nodeIds:a.nodeIds})})}Tk(SO);function _O(e){if(bo.value++,ds++,_a=null,cn.value=!1,typeof e.catalogEpoch==="string")Ck(e.catalogEpoch);if(!tt()&&typeof e.workbenchToken==="string")window.__PMX_WORKBENCH_TOKEN=e.workbenchToken;if(xr.value=e.sessionId||"",Pf(e.workspaceSettings),ao.value="connected",sl().then(Jr),Zi.value+=1,bO(e.version,e.bundleStamp),jl(),zr(),Qa(),!fu&&!tt())Qw();if(pe("fetchHumanPresence","/api/canvas/human-presence",null).then(Uf),Og().then(()=>{if(_o.value)yi()}),typeof e.theme==="string"&&!Sg())$g(e.theme);if(e.ledgerSummary)LI(e.ledgerSummary)}function CO(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(lO(t,n),e.ledgerSummary)LI(e.ledgerSummary)}function TO(e){Ca(),Xe("status-main",{message:typeof e.message==="string"?e.message:String(e.message??""),level:e.level??"ok",source:e.source})}function IO(e){Ca(),Xe("status-main",{phase:e.phase,detail:e.detail})}function EO(e){let t=e.cards??[];cO(t)}function AO(e){if(typeof e.url==="string"&&e.url)uO({url:e.url,sourceServer:e.sourceServer,sourceTool:e.sourceTool,inferredType:e.inferredType,trustedDomain:e.trustedDomain,hostMode:e.hostMode??"hosted"})}function RO(e){let t=e.sessions??[];for(let n of t){let o=n.url;if(!o)continue;let i=`mcp-${ac(o)}`;if(H.value.has(i))Xe(i,{sessionState:n.state,lastSeenAt:n.lastSeenAt})}}function PO(e){if(typeof e.url==="string"&&e.url){let t=`mcp-${ac(e.url)}`;if(H.value.has(t))Xe(t,{hostMode:"fallback",fallbackReason:e.reasonCode})}}function NO(e){let n=H.value.get("context-main");if(!n)return;let o=(n.data.auxTabs??[]).concat(e);Xe("context-main",{auxTabs:o})}function MO(e){if(H.value.has("context-main"))if(e.mode==="all")Xe("context-main",{auxTabs:[]});else{let o=H.value.get("context-main");if(!o)return;let i=(o.data.auxTabs??[]).filter((s)=>s.id!==e.id);Xe("context-main",{auxTabs:i})}}function zO(e){Ca(),Xe("status-main",{phase:"idle",lastCompletion:{tokenCount:e.tokenCount,artifactCount:e.artifactCount}})}function $O(e){Ca(),Xe("status-main",{phase:"tooling",detail:`${e.name}`,activeTool:e.name})}function LO(e){Ca(),Xe("status-main",{activeTool:null})}function OO(e){if(e.state==="active"&&e.path){let n=`md-${ac(e.path)}`;if(H.value.has(n))Xe(n,{reviewActive:!0})}}function DO(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;dO({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 BO(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=zI(e)??$I(e.serverName,e.toolName);if(!t)return;if(H.value.has(t))Xe(t,{html:e.html})}function FO(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=zI(e)??$I(e.serverName,e.toolName);if(!t)return;if(H.value.has(t)){if(e.success===!1){ei(t);return}Xe(t,{toolResult:jh({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 HO(e){Ca(),Xe("status-main",{subagent:{state:e.state,name:e.agentDisplayName??e.agentName}})}function UO(e){let t=e.nodeId;if(!t)return;let n=e.text||"",{position:o,parentNodeId:i,contextNodeIds:s}=e;if(e.threadNodeId&&H.value.has(e.threadNodeId)){let a=e.threadNodeId,l=H.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"});Xe(a,{turns:c,threadStatus:"pending"});return}if(!H.value.has(t)){let a=o??bi.prompt;kr(vp(rc(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&&H.value.has(i))zs({id:`edge-${i}-${t}`,from:i,to:t,type:"flow",style:"dashed"})}function jO(e){let{nodeId:t,status:n}=e;if(t&&H.value.has(t))Xe(t,{status:n})}function ZO(e){let{responseNodeId:t,promptNodeId:n}=e;if(!t)return;let o=n?H.value.get(n):void 0;if(o&&Array.isArray(o.data.turns)){Sa.set(t,n);let s=[...o.data.turns];s.push({role:"assistant",text:"",status:"streaming"}),Xe(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:bi.response.x,y:bi.response.y};if(!H.value.has(t))kr(vp(rc(t,"response",{content:"",status:"streaming",promptNodeId:n},{position:i})));if(n)zs({id:`edge-${n}-${t}`,from:n,to:t,type:"flow",animated:!0});$t(t)}function WO(e){let t=e.responseNodeId;if(!t)return;let n=Sa.get(t);if(n){let o=H.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";Xe(n,{turns:i,threadStatus:"streaming"})}return}if(!H.value.has(t))return;Xe(t,{content:e.content,status:"streaming"})}function qO(e){let t=e.responseNodeId;if(!t)return;let n=Sa.get(t);if(n){let s=H.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";Xe(n,{turns:a,threadStatus:"answered",_activeResponseId:void 0})}Sa.delete(t);return}if(!H.value.has(t))return;Xe(t,{content:e.content,status:"complete"});let i=H.value.get(t)?.data.promptNodeId;if(i){let s=`edge-${i}-${t}`,a=et.value.get(s);if(a)Vk(s),zs({...a,animated:!1})}}function gp(e){bo.value++;let t=e.layout;if(!t?.nodes)return;if(typeof e.boardGeneration==="number"){if(e.catalogEpoch!==Sn||Mo!==null&&e.boardGeneration<Mo)return;if(Mo===null||e.boardGeneration>Mo){_a=e;return}}if(e.boardId!==void 0&&e.boardId!==se.value){_a=e;return}Mg+=1;let n=!cn.value;cn.value=!0;let o=t.nodes.map(gO).filter((l)=>l!==null),i=Array.isArray(t.edges)?t.edges.map(yO).filter((l)=>l!==null):Array.from(et.value.values()),s=Array.isArray(t.annotations)?t.annotations.map(vO).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)co();hm({...a?{viewport:a}:{},nodes:o,edges:i,...s?{annotations:s}:{}},{applyViewport:n}),nl({event:"canvas-layout-update",data:e}),zr(1000)}function GO(e){if(e<=1)return 500;if(e===2)return 1000;return Math.min(2500,1500+(e-3)*500)}function KO(e){if(vm())return;let t=e.nodeId;if(t&&H.value.has(t)){if(e.noPan===!0){Sr(t);return}$t(t)}}function VO(e){if(vm()||e.clientId===Kr)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;co(),fm({x:n,y:o,scale:i})}function XO(e){if(Oo.value)return;if(!Ln.value&&e.present!==!0)return;let t=Xc.safeParse(e.stop);if(t.success)nS(t.data)}function JO(){if(Oo.value)return;Ln.value=!1,Jo.value=""}function YO(e){if(Oo.value)return;let t=Xc.safeParse(e.stop);if(!t.success)return;try{bm(t.data,Ln.value?void 0:(n)=>{bu(n,{recordHistory:!1})})}catch{let n=Wa.safeParse(e.viewport);if(!n.success)return;co(),fm(n.data)}}function QO(e){if(H.value.get("context-main"))Xe("context-main",{currentTokens:e.currentTokens,tokenLimit:e.tokenLimit,messagesLength:e.messagesLength,utilization:e.utilization,nearLimit:e.nearLimit})}function eD(e){Ds.value=e.enabled===!0}function tD(e){if(typeof e.theme==="string"&&!Sg())$g(e.theme)}function DI(e){bo.value++;let t=Array.isArray(e.nodeIds)?e.nodeIds.filter((n)=>typeof n==="string"):[];if(ji===0)um(t);nl({event:"context-pins-changed",data:e}),jl(),zr()}function nD(){jl(),zr()}var hp=null,zg=0;async function Og(){let e=++zg,t=ds,n=await yk();if(e===zg&&t===ds)Lo.value=n}function NI(){if(hp)clearTimeout(hp);zg+=1,hp=setTimeout(()=>{if(hp=null,Og(),_o.value)yi()},150)}function oD(e){let t=e.intent;if(!t||typeof t.id!=="string"||typeof t.kind!=="string"||typeof t.expiresAt!=="number")return;jw(t)}function rD(e){let t=typeof e.id==="string"?e.id:"";if(!t)return;if(e.settled===!0)Ww(t,typeof e.nodeId==="string"?e.nodeId:void 0);else Ff(t)}var BI={connected:_O,"workbench-open":CO,"canvas-status":TO,"execution-phase":IO,"context-cards":EO,"mcp-app-candidate":AO,"mcp-app-host-snapshot":RO,"mcp-app-host-fallback":PO,"aux-open":NO,"aux-close":MO,"assistant-complete":zO,"tool-start":$O,"tool-complete":LO,"review-state":OO,"subagent-status":HO,"ext-app-open":DO,"ext-app-update":BO,"ext-app-result":FO,"context-pins-changed":DI,"context-status-changed":nD,"knowledge-changed":()=>void Kt(),"lifecycle-changed":()=>void Kt(),"boards-changed":(e)=>{Qr(e),zr()},"canvas-layout-update":gp,"canvas-focus-node":KO,"canvas-viewport-update":VO,"canvas-tour-step":XO,"canvas-tour-exit":JO,"canvas-camera-move":YO,"context-usage":QO,"trace-state":eD,"theme-changed":tD,"settings-changed":(e)=>Pf(e.workspaceSettings),"canvas-prompt-created":UO,"canvas-prompt-status":jO,"canvas-response-start":ZO,"canvas-response-delta":WO,"canvas-response-complete":qO,"ax-state-changed":NI,"ax-event-created":NI,"ax-intent":oD,"ax-intent-clear":rD,"agent-presence":xO,"human-presence":kO,"agent-session-ended":wO};function FI(e,t){let n=BI[e];if(!n)return;let o=n;try{o(t)}catch(i){console.warn(`[sse-bridge] Handler for "${e}" failed:`,i)}}function MI(){ic=!0,us+=1;let e=us;ka?.abort();let t=new AbortController;ka=t;let n=!tt();ao.value="connecting";let o=null,i=!1,s=async()=>{if(e!==us)return;let a=new AbortController,l;try{let c=new URLSearchParams;if(wa!==null){if(c.set("since",String(wa)),n)c.set("waitMs",String(oO))}let u=xr.value;if(u)c.set("session",u);let d=c.toString(),p=$o,f=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"))},iO)})]);if(e!==us)return;if(!f.ok)throw Error("poll returned ok: false");let m=o;if(o=f.sessionId??null,m!==null&&f.sessionId&&m!==f.sessionId&&!f.snapshot){wa=null,$r=setTimeout(()=>void s(),0);return}if(f.snapshot&&i)sc=ym(),cn.value=!1,pu(),su(),Sa.clear();let h=p===$o&&ji===0,g=!1,v=new Set;if(!f.snapshot&&cn.value){let b;for(let x of f.events){let C=x.payload,y=C.catalogEpoch===Sn&&C.boardGeneration===Mo&&(x.event==="boards-changed"?C.activeBoardId:C.boardId)===se.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 f.events){if(v.has(b))continue;if(b.event==="context-pins-changed"&&!h){g=!0;continue}FI(b.event,b.payload)}if(g)dm(),jl(),zr();i=!0,wa=f.seq,Wi.value=0,qi.value=0,ao.value="connected",$r=setTimeout(()=>void s(),n?rO:nO)}catch(c){if(e!==us)return;console.warn("[sse-bridge] poll transport error:",c),ao.value="disconnected",Wi.value+=1,qi.value=RI,$r=setTimeout(()=>void s(),RI)}finally{clearTimeout(l)}};return s(),()=>{if(Qa(),us+=1,ic=!1,wa=null,t.abort(),ka===t)ka=null;if($r)clearTimeout($r),$r=null}}function Dg(){if(ds++,_a=null,hT($g),sc=ym(),cn.value=!1,pu(),su(),Sa.clear(),wi)clearTimeout(wi),wi=null;let e=sO();if(e==="poll"||ic)return MI();let t=xr.value,n=t?`/api/workbench/events?session=${t}`:"/api/workbench/events";ao.value="connecting";let o=new EventSource(n);xi=o;let i=!1;if(ki)clearTimeout(ki);if(ki=null,e!=="sse")ki=setTimeout(()=>{if(ki=null,i||xi!==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(),xi=null,MI()},tO);for(let[s]of Object.entries(BI))o.addEventListener(s,(a)=>{if(xi!==o)return;i=!0;try{FI(s,JSON.parse(a.data))}catch(l){console.warn(`[sse-bridge] Failed to parse "${s}" event:`,l)}});return o.onopen=()=>{if(xi!==o)return;mp=0,Wi.value=0,qi.value=0,ao.value="connected"},o.onerror=()=>{if(xi!==o)return;ao.value="disconnected",o.close(),xi=null,mp+=1;let s=GO(mp);Wi.value=mp,qi.value=s,wi=setTimeout(()=>{wi=null,Dg()},s)},()=>{if(Qa(),wi)clearTimeout(wi),wi=null;if(ki)clearTimeout(ki),ki=null;if(ic){if(us+=1,ic=!1,wa=null,ka?.abort(),ka=null,$r)clearTimeout($r),$r=null}o.close(),xi=null}}function ps(e,t){console.error(`[app] ${e} failed`,t)}var iD=Ve(()=>H.value.size===0),HI=Ve(()=>{let e=Ct.value;return!!e&&!ut.value&&se.value===e.boardId&&wt===e.incarnation&&H.value.has(e.nodeId)}),Bg=Ve(()=>Oe.value&&HI.value);function UI(){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),[f,m]=E(null),h=D(null),g=D(null),[v,b]=E(Jt),{menu:x,openNodeMenu:C,openCanvasMenu:y,openEdgeMenu:k,closeMenu:_}=bT(),I=cn.value,w=io.value&&(se.value===null||ut.value),P=tr.value,L=xt.value,N=_o.value||Co.value.length>0||os.value.length>0||!!To.value,Y=Bg.value;Me(()=>{if(!L){if(Fn.value=null,eo.value=!1,document.activeElement?.closest(".command-bar, .session-panel, .agent-popover"))h.current?.focus({preventScroll:!0})}},[L]);let B=oe(()=>t((A)=>!A),[]),J=oe(()=>o((A)=>!A),[]),X=oe(()=>o(!1),[]),V=oe((A)=>m(A),[]),ee=oe((A)=>{Rw(A),g.current=A},[]),he=oe((A,te)=>{_r({x:A,y:te,scale:Ee.value.scale},200)},[]);return q(()=>Dg(),[]),q(()=>{let A=(te)=>{let M=te.detail;u(M??{}),l(!0)};return window.addEventListener("pmx-open-board-link",A),()=>window.removeEventListener("pmx-open-board-link",A)},[]),q(()=>{let A=null,te=()=>{if(A!==null)window.clearTimeout(A);A=window.setTimeout(()=>{A=null,Jr()},400)};return window.addEventListener("resize",te),()=>{if(A!==null)window.clearTimeout(A);window.removeEventListener("resize",te)}},[]),Me(()=>{let A=(O)=>{let Pe=(O.metaKey||O.ctrlKey)&&!O.altKey;if(d&&(O.key==="Escape"||O.key==="?"||O.key==="/"&&O.shiftKey)){O.preventDefault(),p(!1);return}if(ut.value||se.value===null)return;if(O.defaultPrevented)return;if(Pe&&O.key==="k"){O.preventDefault(),s((ve)=>!ve);return}if(O.key==="Escape"&&f){O.preventDefault(),m(null);return}if(O.key==="Escape"&&Bg.value){if(O.target?.closest('[role="menu"], [role="alertdialog"]'))return;O.preventDefault(),Ct.value=null;return}if(O.key==="Escape"&&Bt.value&&!zo.value){O.preventDefault(),Cr();return}if(O.key==="Escape"&&i){O.preventDefault(),s(!1);return}let Fe=O.target,De=Fe?.tagName;if(De==="INPUT"||De==="TEXTAREA"||Fe?.isContentEditable)return;if(Fe?.closest('[role="menu"]'))return;let Ae=Fe?.closest('[role="dialog"]');if((O.key==="Tab"||O.key.startsWith("Arrow"))&&Fe?.closest(".tool-rail, .top-bar"))return;if(O.key===" "&&!O.repeat&&!Pe&&!Ae){O.preventDefault(),dl.value=!0;return}if(O.key==="?"||O.key==="/"&&O.shiftKey){O.preventDefault(),p((ve)=>!ve);return}if(Pe&&(O.key==="z"||O.key==="Z"))O.preventDefault(),ag(O.shiftKey);else if(Pe&&(O.key==="y"||O.key==="Y"))O.preventDefault(),ag(!0);else if(Pe&&O.key==="0")O.preventDefault(),_r({x:0,y:0,scale:1},250);else if(Pe&&(O.key==="="||O.key==="+"))O.preventDefault(),ti(1.25);else if(Pe&&O.key==="-")O.preventDefault(),ti(0.8);else if(Ae)return;else if(O.key==="Escape"){if(!ir(O))return;if(O.preventDefault(),Io.value?.boardId===se.value)Io.value=null;Ro.value="All",$n(),gt.value=null,_()}else if(O.key==="Tab")O.preventDefault(),Qk(O.shiftKey?-1:1);else if(O.key==="Delete"||O.key==="Backspace"){if(br.value!==null){let z=br.value;O.preventDefault(),br.value=null,wu(z).catch((re)=>ps("delete-edge",re));return}let ve=st.value.size>0?[...st.value]:gt.value?[gt.value]:[];if(ve.length===0)return;O.preventDefault();for(let z of ve)Xr(z).catch((re)=>ps("delete",re));$n(),gt.value=null}else if(gt.value&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(O.key)){O.preventDefault();let ve=O.key.replace("Arrow","").toLowerCase();eS(ve)}else if(!Pe&&!O.altKey){let ve=O.key.toLowerCase();if(ve==="v"&&!O.shiftKey)Wn.value="select";else if(ve==="c"&&!O.shiftKey&&!Pe)O.preventDefault(),Wn.value=Wn.value==="connect"?"select":"connect";else if(ve==="m"&&!O.shiftKey)O.preventDefault(),Eo({type:"markdown",title:"New note",width:520,height:360}).catch((z)=>ps("create markdown",z));else if(ve==="a"&&!O.shiftKey)O.preventDefault(),m((z)=>z==="pen"?null:"pen");else if(ve==="g"&&!O.shiftKey){O.preventDefault();let z=Array.from(st.value);if(z.length>=2)Ns({title:"Group",childIds:z}).catch((re)=>ps("group selection",re)),$n();else Eo({type:"group",title:"Group"}).catch((re)=>ps("create group",re))}else if(ve==="g"&&O.shiftKey){O.preventDefault();for(let z of Wk())ei(z),Ms(z).catch((re)=>ps("ungroup",re));$n()}else if(ve==="i"&&!O.shiftKey)O.preventDefault(),as("image");else if(ve==="w"&&!O.shiftKey)O.preventDefault(),as("webpage");else if(ve==="h"&&!O.shiftKey)O.preventDefault(),Eo({type:"html",title:"HTML surface"}).catch((z)=>ps("create html",z));else if(ve==="f"&&O.shiftKey)O.preventDefault(),as("file");else if(ve==="f"&&!O.shiftKey){O.preventDefault();let z=Jt();Hs(z.width,z.height)}}},te=(O)=>{if(O.key===" ")dl.value=!1},M=()=>{dl.value=!1};return document.addEventListener("keydown",A),document.addEventListener("keyup",te),window.addEventListener("blur",M),()=>{document.removeEventListener("keydown",A),document.removeEventListener("keyup",te),window.removeEventListener("blur",M)}},[f,_,i,d]),q(()=>{let A=window.setTimeout(()=>void Jr(),250);return()=>window.clearTimeout(A)},[P]),Me(()=>{let A=g.current;if(!A)return;let te=new ResizeObserver(()=>{b(Jt()),Jr();let M=Ct.value;if(M&&Bg.value)$t(M.nodeId,{recordHistory:!1})});return te.observe(A),()=>te.disconnect()},[]),q(()=>{if(!I)return;let A=window.__pmxCanvasBootstrapReady;if(typeof A==="function")A()},[I]),r("div",{class:`app-shell${Ln.value?" is-presenting":""}`,"data-session-active":P?"true":"false",children:[r(iS,{},void 0,!1,void 0,this),r(tT,{},void 0,!1,void 0,this),r(ST,{minimapVisible:e,onToggleMinimap:B,snapshotOpen:n,onToggleSnapshot:J,snapshotBtnRef:h,onOpenPalette:()=>s(!0),onOpenShortcuts:()=>p((A)=>!A),annotationTool:f,onSetAnnotationTool:V},void 0,!1,void 0,this),r("div",{class:"app-main",children:[r(AI,{},void 0,!1,void 0,this),r(pT,{},void 0,!1,void 0,this),r("div",{class:`workspace${Y?" is-reviewing":""}`,children:[r("div",{class:"canvas-region",ref:ee,children:[!ut.value&&r(sT,{onNodeContextMenu:C,onCanvasContextMenu:y,onEdgeContextMenu:k,annotationMode:f!==null,annotationTool:f},void 0,!1,void 0,this),r(kS,{},void 0,!1,void 0,this),r($C,{},void 0,!1,void 0,this),!w&&r(LC,{},void 0,!1,void 0,this),!w&&r(QC,{},void 0,!1,void 0,this),r(wS,{},void 0,!1,void 0,this),r(QT,{},void 0,!1,void 0,this),r(eI,{},void 0,!1,void 0,this),w?r(XT,{},void 0,!1,void 0,this):I&&iD.value&&qt.value.size===0&&r(_T,{onOpenPalette:()=>s(!0)},void 0,!1,void 0,this),!w&&st.value.size>0&&r(uI,{},void 0,!1,void 0,this),!w&&!L&&r(uT,{},void 0,!1,void 0,this),!w&&_o.value&&!tt()&&r(aT,{},void 0,!1,void 0,this),!w&&r(xI,{onOpenSnapshots:()=>o(!0)},void 0,!1,void 0,this),r(_S,{},void 0,!1,void 0,this),!ut.value&&r(JT,{},void 0,!1,void 0,this),!w&&Bt.value&&r(iI,{},void 0,!1,void 0,this),r(_I,{open:n&&!ut.value,onClose:X,anchorRef:h},void 0,!1,void 0,this),e&&!w&&r(cI,{viewport:Ee,nodes:H,edges:et,onNavigate:he,containerWidth:v.width,containerHeight:v.height},void 0,!1,void 0,this)]},void 0,!0,void 0,this),HI.value&&r(vT,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),P&&r(yI,{},void 0,!1,void 0,this),!P&&N&&r(gI,{},void 0,!1,void 0,this),!ut.value&&x&&r(xT,{menu:x,onClose:_},void 0,!1,void 0,this),!ut.value&&i&&r(gT,{onClose:()=>s(!1),onToggleMinimap:B},void 0,!1,void 0,this),!ut.value&&a&&r(yT,{...c,onClose:()=>l(!1)},void 0,!1,void 0,this),d&&r(wI,{onClose:()=>p(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}PS();var jI=document.getElementById("app");if(jI)Ra(r(UI,{},void 0,!1,void 0,this),jI);
394
+ ${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(ri,{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 ec(e,t){console.error(`[tool-rail] ${e} failed`,t)}function as(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;Eo({type:e,content:n}).catch((o)=>ec(`create ${e}`,o))})}function to({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})},f=()=>d(null),m=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":m,"aria-pressed":i===void 0?void 0:i,onClick:(h)=>{f(),a(h)},onPointerEnter:p,onPointerLeave:f,onFocus:p,onBlur:f,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 rr({label:e,description:t,hint:n,beta:o,toggle:i=o,checked:s,disabled:a,onClick:l}){let c=wy(),[u,d]=E(null),p=(m)=>d(m.currentTarget.getBoundingClientRect()),f=()=>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:f,onFocus:p,onBlur:f,onClick:()=>{if(a)return;f(),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(Ws,{children:r("span",{id:c,class:"toolbar-tooltip settings-tooltip",role:"tooltip",ref:(m)=>{if(!m)return;let h=window.innerWidth-u.right>=m.offsetWidth+20;m.style.left=`${h?u.right+10:Math.max(12,Math.min(u.left,window.innerWidth-m.offsetWidth-12))}px`,m.style.top=`${Math.max(12,Math.min(h?u.top:u.top-m.offsetHeight-8,window.innerHeight-m.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 ST({minimapVisible:e,onToggleMinimap:t,snapshotOpen:n,onToggleSnapshot:o,snapshotBtnRef:i,onOpenPalette:s,onOpenShortcuts:a,annotationTool:l,onSetAnnotationTool:c}){let u=Wn.value,d=Ds.value,p=Array.from(H.value.values()).filter((V)=>V.type==="trace").length,f=et.value.size,[m,h]=E(!1),[g,v]=E(!1),[b,x]=E(!1),C=async(V)=>{if(g||!Wr.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]:!Wr.value[V]})});x(ee.ok!==!0)}finally{v(!1)}},[y,k]=E(null),[_,I]=E(null),w=D(null),P=D(null),L=(V)=>{if(y){k(null);return}let ee=V.currentTarget.getBoundingClientRect();I({bottom:ee.bottom,right:ee.right}),k("settings")},N=(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;Me(()=>{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 B=(V)=>{op(),document.documentElement.setAttribute("data-theme",V),la(),Qt.value=V,hu(V),k(null)},J=fh(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)=>ec("sendIntent",he))};return r(be,{children:[r("div",{class:"tool-rail",ref:w,role:"toolbar","aria-label":"Canvas tools","aria-orientation":"vertical",children:[r(to,{label:"Home",ariaLabel:"PMX Canvas — Home",onClick:()=>{k(null),Mn(null).catch((V)=>ec("openHome",V))},children:r("span",{class:"rail-brand",children:r(zu,{size:22},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),!ut.value&&r(be,{children:[r("div",{class:"rail-divider"},void 0,!1,void 0,this),r(to,{label:"Select",shortcut:"V",active:u==="select",onClick:()=>Wn.value="select",children:r(bS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{label:"Pan",shortcut:"Space",active:u==="pan",onClick:()=>Wn.value="pan",children:r(xS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{label:"Connect",shortcut:"C",active:u==="connect",onClick:()=>Wn.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(to,{label:"Markdown note",shortcut:"M",onClick:()=>void Eo({type:"markdown",title:"New note",width:520,height:360}).catch((V)=>ec("create markdown",V)),children:r(ni,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{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:()=>P.current?.click(),children:r(dS,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("input",{ref:P,type:"file",hidden:!0,multiple:!0,"aria-label":"Attach files",onChange:(V)=>{let ee=Jt(),he=Ee.value;ua(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(to,{label:"Webpage",shortcut:"W",onClick:()=>as("webpage"),children:r(Us,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{label:"Group",shortcut:"G",onClick:()=>void Eo({type:"group",title:"Group"}).catch((V)=>ec("create group",V)),children:r(Sm,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{label:"Draw",shortcut:"A",active:l==="pen",onClick:()=>c(l==="pen"?null:"pen"),children:r(gS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{label:"Text note",active:l==="text",onClick:()=>c(l==="text"?null:"text"),children:r(vS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(to,{label:"Eraser",active:l==="eraser",onClick:()=>c(l==="eraser"?null:"eraser"),children:r(yS,{},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),!ut.value&&r(to,{label:"Search & commands",shortcut:Ft("K"),onClick:s,children:r(Mu,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),!ut.value&&r(to,{label:"Arrange",detail:f>0?"graph-aware":"grid",onClick:()=>f>0?Eu():Iu(),children:r(Tr,{},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(to,{label:"Settings",detail:"Appearance, board tools, beta features, and feedback",ariaLabel:"Settings",menuOpen:y!==null,active:y!==null||n,onClick:L,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(rr,{label:"Theme",description:"Choose the canvas appearance. Your choice is saved with the board.",hint:`${ea[J].label} ›`,onClick:()=>k("theme")},void 0,!1,void 0,this),!ut.value&&r(be,{children:[r(rr,{label:"Snapshots",description:"Save a board checkpoint, compare changes, or restore an earlier version.",onClick:N(o)},void 0,!1,void 0,this),r(rr,{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:N(t)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(rr,{label:"Keyboard shortcuts",description:"See shortcuts for creating cards, selecting, navigating, and editing the canvas.",hint:"?",onClick:N(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(rr,{label:"Agent sessions",beta:!0,checked:xt.value,disabled:!Wr.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(rr,{label:"Knowledge lifecycle",beta:!0,checked:Oe.value,disabled:!Wr.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),!xt.value&&(fa.value.length>0||Co.value.length>0||os.value.length>0||To.value)&&r(rr,{label:"Agent controls",description:"Review pending approvals, inspect or clear the write scope, or end an existing attachment without enabling the session beta.",onClick:N(()=>eo.value=!0)},void 0,!1,void 0,this),r("div",{class:"toolbar-menu-divider",role:"separator"},void 0,!1,void 0,this),!tt()&&!ut.value&&r(be,{children:[r(rr,{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(rr,{label:"Clear trace",description:"Remove recorded execution traces from this board without changing whether trace capture is enabled.",onClick:N(()=>X("trace-clear"))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(rr,{label:"Send feedback",description:"Report a problem or suggestion. Review the feedback before sending.",onClick:N(()=>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),ph.map((V)=>r("button",{type:"button",role:"menuitemradio","aria-checked":J===V,class:`toolbar-menu-item${J===V?" active":""}`,onClick:()=>B(V),children:[r("span",{class:"theme-swatch",style:{background:ea[V].swatchBg},children:r("span",{class:"theme-swatch-dot",style:{background:ea[V].swatchAccent}},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{children:ea[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),m&&r(kT,{onClose:()=>h(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function _T({onOpenPalette:e}){let t=D(null),n=()=>{Eo({type:"markdown",title:"New note",width:520,height:360}).catch(()=>{})},o=async(i)=>{if(!i||i.length===0)return;let s=Zr(),a=Ee.value;await ua(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:()=>as("webpage"),children:[r(Us,{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:Ft("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(ni,{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),xt.value&&r("button",{type:"button",class:"empty-state-action is-agent",onClick:()=>void vi(),children:[r(Zs,{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 · ",Ft("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 ir(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 CT="From old snapshots";function ip(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 tc(e){return e.split("/").map((t,n,o)=>o.slice(0,n+1).join("/"))}function TT({board:e,folders:t,onClose:n}){let o=D(null),[i,s]=E(e.folder??""),[a,l]=E(""),[c,u]=E(!1),[d,p]=E("");bn(o,!0),q(()=>{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 f=a.trim()?[i,a.trim()].filter(Boolean).join("/"):i,m=async()=>{let h;try{if(a.includes("/"))throw Error("Use one folder name; choose its parent above.");h=ip(f)}catch(g){p(g instanceof Error?g.message:String(g));return}if(u(!0),p(""),await vr(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:f||"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||f===(e.folder??""),onClick:()=>void m(),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 IT({board:e,onClose:t}){let n=D(null),o=D(null),[i,s]=E(null),[a,l]=E(new Set),[c,u]=E(`${e.name} copy`),[d,p]=E(!0),[f,m]=E(!0),[h,g]=E(!1),[v,b]=E(""),[x,C]=E(!1);return bn(n,!0,{initial:o}),q(()=>{let k=!0;return Ak(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((I)=>I.reusable).map((I)=>I.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:Ho,onSubmit:async(k)=>{if(k.preventDefault(),!c.trim()||!i)return;C(!0),b("");let _=await Rk({sourceBoardId:e.id,name:c.trim(),...e.folder?{folder:e.folder}:{},nodeIds:[...a],includeReadme:d,includeStructure:f});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 I=new Set(a);_.currentTarget.checked?I.add(k.id):I.delete(k.id),l(I)}},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:f,onChange:(k)=>m(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 sp({children:e,initiallyCollapsed:t=!1,reveal:n=0}){let o=D(null),[i,s]=E(280),[a,l]=E(400),[c,u]=E(t),d=D(null);return Me(()=>{if(n)u(!1)},[n]),Me(()=>{let p=o.current.closest(".home-memory"),f=p.querySelector(".home-memory-stage"),m=p.closest(".canvas-region"),h=p.querySelector(".home-memory-toolbar"),g=p.querySelector(".home-memory-legend"),v=()=>{m?.style.setProperty("--home-memory-content-top",`${f.getBoundingClientRect().top-(m?.getBoundingClientRect().top??0)}px`),l(Math.max(120,p.clientHeight-h.offsetHeight-g.offsetHeight-160))},b=new ResizeObserver(v);for(let x of[p,f,h,g])b.observe(x);return v(),()=>{b.disconnect(),m?.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 f=d.current;if(f?.id===p.pointerId)s(Math.max(120,Math.min(a,f.height+f.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 go={width:220,height:92};function ET(e,t){let n=e.filter((f)=>f.kind==="board"),o=new Map,i=[],s=new Set,a=new Set;for(let f of n){let m=(f.folder??"").split("/");m.forEach((h,g)=>{a.add(m.slice(0,g+1).join("/"))})}let l=(f,m)=>(f.folder??"")===m||!!m&&!!f.folder?.startsWith(`${m}/`),c=(f,m,h,g)=>{let v=n.filter((B)=>l(B,f)),b=t.has(f),x={path:f,x:m,y:h,width:280,height:72,count:v.length,depth:g,collapsed:b};if(i.push(x),b){for(let B of v)s.add(B.key);return x}let C=v.filter((B)=>(B.folder??"")===f).sort((B,J)=>B.title.localeCompare(J.title)),y=Math.min(3,Math.max(1,Math.ceil(Math.sqrt(C.length))));C.forEach((B,J)=>{let X=B.position??{x:m+24+J%y*(go.width+28),y:h+52+Math.floor(J/y)*(go.height+28)};o.set(B.key,{x:X.x+go.width/2,y:X.y+go.height/2})});let k=h+52+Math.ceil(C.length/y)*(go.height+28),_=C.length?y*(go.width+28)+20:280,I=[...a].filter((B)=>B&&B.slice(0,B.lastIndexOf("/"))===f&&B.includes("/")).sort(),w=20,P=0;for(let B of I){if(w>650)w=20,k+=P+24,P=0;let J=c(B,m+w,k,g+1);w+=J.width+24,P=Math.max(P,J.height),_=Math.max(_,w)}k+=P+(I.length?20:0),x.width=_,x.height=Math.max(100,k-h+4);let L=v.flatMap((B)=>{let J=o.get(B.key);return J?[J]:[]}),N=Math.max(m+x.width,...L.map((B)=>B.x+go.width/2+20)),Y=Math.max(h+x.height,...L.map((B)=>B.y+go.height/2+20));return x.x=Math.min(m,...L.map((B)=>B.x-go.width/2-20)),x.y=Math.min(h,...L.map((B)=>B.y-go.height/2-48)),x.width=N-x.x,x.height=Y-x.y,x},u=32,d=32,p=0;for(let f of[...a].filter((m)=>!m.includes("/")).sort()){if(u>1100)u=32,d+=p+36,p=0;let m=c(f,u,d,0);u+=m.width+36,p=Math.max(p,m.height)}return{positions:o,regions:i,hidden:s}}function ap(e){let t=Ge.value,n=bo.value,[o,i]=E(null),[s,a]=E(!0),[l,c]=E(!1),u=D(()=>{});return q(()=>{let d=!1,p=!1,f=!1,m,h=()=>{if(f=!0,!p&&m===void 0)m=window.setTimeout(g,120)},g=async()=>{m=void 0,f=!1,p=!0,a(!0);let v=Sn,b=bo.peek(),x=Ge.peek(),C=await pe("memoryGraph",`/api/canvas/memory-graph?projection=${e}`,null);if(d)return;if(p=!1,v!==Sn||b!==bo.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),f)h()};return u.current=h,h(),()=>{d=!0,window.clearTimeout(m)}},[e]),q(()=>u.current(),[n,t]),{graph:o,loading:s,error:l,retry:()=>u.current()}}var AT={portal:"Portals",wiki:"Wiki links",card:"Card relations",previous:"Previous boards"};function RT(){let e=Ge.value,t=bo.value,{graph:n,loading:o,error:i,retry:s}=ap("boards"),[a,l]=E(""),[c,u]=E(!0),[d,p]=E(!1),[f,m]=E(!0),[h,g]=E(new Set),[v,b]=E(new Set),[x,C]=E(new Set),[y,k]=E(null),[_,I]=E(null),[w,P]=E(null),[L,N]=E({x:0,y:0}),[Y,B]=E(1),[J,X]=E({}),[V,ee]=E(!1),he=D(null),A=D(!0),te=D(!1),M=D(null);Me(()=>{ut.value=!0},[]),Me(()=>{if(!y)return;let R=(ne)=>{if(ir(ne))ne.preventDefault(),k(null)};return window.addEventListener("keydown",R),()=>window.removeEventListener("keydown",R)},[y]),q(()=>{if(!y)return;let R=!1;P(null);let ne=Sn,Ce=bo.peek(),Te=new URLSearchParams({focus:y,depth:"2"});return pe("memoryGraph",`/api/canvas/memory-graph?${Te}`,null).then((fe)=>{if(!R&&ne===Sn&&Ce===bo.peek())P({key:y,graph:fe&&Array.isArray(fe.nodes)&&Array.isArray(fe.edges)?fe:null})}),()=>{R=!0}},[y,n,t]);let O=Ke(()=>(n?.nodes??[]).filter((R)=>R.kind==="board").map((R)=>{let ne=e.find((Ce)=>Ce.id===R.boardId);return ne?{...R,title:ne.name,folder:ne.folder,inContext:!!ne.pin,nodeCount:ne.nodeCount,position:ne.mapPosition??void 0}:R}),[n,e]),Pe=Ke(()=>ET(O,x),[O,x]),Fe=new Map;for(let R of O){let ne=R.folder?.split("/")[0]??"";Fe.set(ne,(Fe.get(ne)??0)+1)}let De=O.filter((R)=>c&&(!d||R.inContext)&&(f||!!R.folder)&&!h.has(R.folder?.split("/")[0]??"")&&!Pe.hidden.has(R.key)&&`${R.title} ${R.summary} ${R.folder??""}`.toLocaleLowerCase().includes(a.trim().toLocaleLowerCase())),Ae=new Set(De.map((R)=>R.key)),ve=(R)=>J[R]??Pe.positions.get(R),z=O.find((R)=>R.key===y),re=O.find((R)=>R.key===(_??y)),Ne=new Map;for(let R of n?.edges??[]){if(R.kind==="member"||v.has(R.kind))continue;let ne=Mt({boardId:R.source.boardId}),Ce=Mt({boardId:R.target.boardId});if(!Ae.has(ne)||!R.missing&&(!Ae.has(Ce)||ne===Ce))continue;let Te=JSON.stringify([ne,Ce,R.kind,R.relationKind,R.missing]),fe=Ne.get(Te);if(fe)fe.edges.push(R);else Ne.set(Te,{from:ne,to:Ce,edges:[R]})}let ke=new Set(re?[re.key]:[]);for(let{from:R,to:ne}of Ne.values())if(re&&(R===re.key||ne===re.key))ke.add(R),ke.add(ne);let ae=(R)=>new Set((n?.edges??[]).filter((ne)=>ne.kind!=="member"&&(ne.source.boardId===R.boardId||ne.target.boardId===R.boardId)).map((ne)=>ne.source.boardId===R.boardId?ne.target.boardId:ne.source.boardId).filter((ne)=>ne!==R.boardId)).size,Se=()=>{let R=he.current;if(!R?.clientWidth||!R.clientHeight)return;let ne=De.flatMap((Ye)=>{let Lt=ve(Ye.key);return Lt?[{x:Lt.x-110,y:Lt.y-46},{x:Lt.x+110,y:Lt.y+46}]:[]});for(let Ye of Pe.regions){if(h.has(Ye.path.split("/")[0]??"")||!f&&!Ye.path)continue;ne.push({x:Ye.x,y:Ye.y},{x:Ye.x+Ye.width,y:Ye.y+Ye.height})}if(!ne.length)return;let Ce=Math.min(...ne.map((Ye)=>Ye.x)),Te=Math.min(...ne.map((Ye)=>Ye.y)),fe=Math.max(...ne.map((Ye)=>Ye.x))-Ce,it=Math.max(...ne.map((Ye)=>Ye.y))-Te,Ht=Math.min(1.25,Math.max(0.08,Math.min((R.clientWidth-64)/Math.max(1,fe),(R.clientHeight-100)/Math.max(1,it))));B(Ht),N({x:(R.clientWidth-fe*Ht)/2-Ce*Ht,y:(R.clientHeight-it*Ht)/2-Te*Ht-12})};q(()=>{A.current=!0},[x]),q(()=>{if(A.current&&n&&(De.length||Pe.regions.length)&&!M.current)A.current=!1,Se()},[n,x]);let de=(R,ne)=>{let Ce=he.current;if(!Ce)return;let Te=ne??{x:Ce.clientWidth/2,y:Ce.clientHeight/2},fe=Math.min(3,Math.max(0.08,R));N({x:Te.x-(Te.x-L.x)*fe/Y,y:Te.y-(Te.y-L.y)*fe/Y}),B(fe)},Ue=(R,ne=!1)=>{k(R.key);let Ce=ve(R.key),Te=he.current;if(ne&&Ce&&Te)N({x:Te.clientWidth/2-Ce.x*Y,y:Te.clientHeight/2-Ce.y*Y})},xe=(R)=>{let ne=M.current;if(M.current=null,!ne)return;if(te.current=ne.moved,!ne.key)return;let Ce=ne.key,Te=()=>X((fe)=>{let it={...fe};return delete it[Ce],it});if(ne.boardId&&ne.moved&&!R){let fe=ne.current??ne.origin;vr(ne.boardId,{mapPosition:{x:fe.x-go.width/2,y:fe.y-go.height/2}}).finally(Te)}else Te()},qe=w?.key===y?w.graph:null,W=(qe?.edges??[]).filter((R)=>z&&R.kind!=="member"&&(R.source.boardId===z.boardId||R.target.boardId===z.boardId)),ye=e.find((R)=>R.id===z?.boardId),He=(R,ne,Ce,Te)=>r("label",{class:"home-memory-check",children:[r("input",{type:"checkbox","aria-label":R,checked:Ce,onChange:Te},void 0,!1,void 0,this),r("span",{children:R},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:[O.length," boards · ",e.reduce((R,ne)=>R+ne.nodeCount,0)," cards ·"," ",n?.edges.filter((R)=>R.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:(R)=>{R.preventDefault();let ne=R.currentTarget.getBoundingClientRect();de(Y*Math.exp(-R.deltaY*0.0015),{x:R.clientX-ne.left,y:R.clientY-ne.top})},onPointerDown:(R)=>{if(R.button!==0||R.target.closest("button"))return;te.current=!1,M.current={id:R.pointerId,start:{x:R.clientX,y:R.clientY},origin:L,moved:!1},R.currentTarget.setPointerCapture(R.pointerId)},onPointerMove:(R)=>{let ne=M.current;if(!ne||ne.id!==R.pointerId)return;let Ce=R.clientX-ne.start.x,Te=R.clientY-ne.start.y;if(Math.abs(Ce)+Math.abs(Te)>4)ne.moved=!0;if(!ne.moved)return;let fe={x:ne.origin.x+Ce/(ne.key?Y:1),y:ne.origin.y+Te/(ne.key?Y:1)};if(ne.current=fe,ne.key)X((it)=>({...it,[ne.key]:fe}));else N(fe)},onPointerUp:()=>xe(!1),onPointerCancel:()=>xe(!0),children:[r("div",{class:"home-memory-world",style:{transform:`translate(${L.x}px, ${L.y}px) scale(${Y})`,"--memory-zoom":Y},children:[Pe.regions.filter((R)=>!h.has(R.path.split("/")[0]??"")&&(f||R.path)).map((R)=>r("div",{class:`home-memory-region${R.depth?" is-nested":""}`,style:{left:R.x,top:R.y,width:R.width,height:R.height},children:r("button",{type:"button","aria-expanded":!R.collapsed,onClick:()=>C((ne)=>{let Ce=new Set(ne);if(Ce.has(R.path))Ce.delete(R.path);else Ce.add(R.path);return Ce}),children:[R.collapsed?"▸":"▾"," ",R.path.split("/").at(-1)||"Unfiled"," ",r("small",{children:[R.count," boards"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},R.path,!1,void 0,this)),r("svg",{class:"home-memory-links","aria-hidden":"true",children:[...Ne].map(([R,{from:ne,to:Ce,edges:Te}])=>{let fe=Te[0],it=ve(ne),Ht=ve(Ce);if(!it)return null;let Ye=Ht??{x:it.x+100,y:it.y-70},Lt=it.y+(Ye.y>it.y?46:-46),F=Ht?Ye.y+(Ye.y>it.y?-46:46):Ye.y,Ie=re&&(fe.source.boardId===re.boardId||fe.target.boardId===re.boardId),S=mo({kind:fe.relationKind,type:fe.type},e.find((ue)=>ue.id===fe.source.boardId)?.relationVocabulary),K=fe.missing?"var(--c-warn)":fe.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-${fe.kind}${fe.missing?" is-missing":""}${Ie?" is-emphasized":re?" is-dimmed":""}`,children:[r("path",{d:`M ${it.x} ${Lt} C ${it.x} ${(Lt+F)/2}, ${Ye.x} ${(Lt+F)/2}, ${Ye.x} ${F}`},void 0,!1,void 0,this),Te.length>1&&r("text",{x:(it.x+Ye.x)/2,y:(it.y+Ye.y)/2-6,children:[Te.length," links"]},void 0,!0,void 0,this),fe.missing&&r("text",{x:Ye.x,y:Ye.y-5,children:["⚠ Missing ",fe.kind," link"]},void 0,!0,void 0,this)]},R,!0,void 0,this)})},void 0,!1,void 0,this),De.map((R,ne)=>{let Ce=ve(R.key);if(!Ce)return null;let Te=e.find((fe)=>fe.id===R.boardId);return r("article",{"data-key":R.key,class:`home-memory-node is-board${R.inContext?" in-context":""}${y===R.key?" is-selected":""}${ke.has(R.key)?" is-emphasized":re?" is-dimmed":""}`,style:{left:Ce.x,top:Ce.y},onPointerEnter:()=>{if(!M.current)I(R.key)},onPointerLeave:()=>I(null),children:[r("button",{type:"button",class:"home-memory-select","aria-label":`board: ${R.title}`,"aria-pressed":y===R.key,onFocus:(fe)=>{if(!M.current&&fe.currentTarget.matches(":focus-visible"))Ue(R,!0)},onClick:()=>{if(!te.current)Ue(R);te.current=!1},onDblClick:()=>void zt(R),onPointerDown:(fe)=>{if(fe.button!==0)return;fe.stopPropagation(),te.current=!1,M.current={id:fe.pointerId,start:{x:fe.clientX,y:fe.clientY},origin:Ce,key:R.key,boardId:R.boardId,moved:!1},fe.currentTarget.setPointerCapture(fe.pointerId)},onKeyDown:(fe)=>{if(fe.key==="Enter")fe.preventDefault(),zt(R);if(fe.key.startsWith("Arrow")){fe.preventDefault();let it=(ne+(fe.key==="ArrowLeft"||fe.key==="ArrowUp"?-1:1)+De.length)%De.length,Ht=De[it];if(Ht)Ue(Ht,!0),he.current?.querySelectorAll(".home-memory-select")[it]?.focus({preventScroll:!0})}},children:[r("strong",{children:R.title},void 0,!1,void 0,this),r("span",{children:[R.nodeCount??0," cards · ",ae(R)," connected boards"]},void 0,!0,void 0,this),r("span",{class:"home-memory-summary",children:R.summary||"No summary yet"},void 0,!1,void 0,this),R.inContext&&r("span",{class:"home-memory-context",children:"⌖ In context"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Te&&r(ho,{board:Te},void 0,!1,void 0,this)]},R.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||!De.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…":Pe.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:(R)=>l(R.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),He("Boards",O.length,c,()=>u(!c)),He("Only in context",O.filter((R)=>R.inContext).length,d,()=>p(!d)),He("Include unfiled",O.filter((R)=>!R.folder).length,f,()=>m(!f))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Groups · by folder"},void 0,!1,void 0,this),[...Fe].sort(([R],[ne])=>R.localeCompare(ne)).map(([R,ne])=>r("div",{children:He(R||"Unfiled",ne,!h.has(R),()=>g((Ce)=>{let Te=new Set(Ce);if(Te.has(R))Te.delete(R);else Te.add(R);return Te}))},R,!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(AT).map((R)=>r("div",{class:`memory-legend-${R}`,children:He(AT[R],n?.edges.filter((ne)=>ne.kind===R).length??0,!v.has(R),()=>b((ne)=>{let Ce=new Set(ne);if(Ce.has(R))Ce.delete(R);else Ce.add(R);return Ce}))},R,!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(sp,{children:z?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:[z.title," · ",W.length," connections"]},void 0,!0,void 0,this),r("p",{children:[z.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(z),children:"Open board"},void 0,!1,void 0,this),ye&&r(ho,{board:ye},void 0,!1,void 0,this),r("button",{type:"button",class:"home-button",onClick:()=>void vr(z.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:[z.nodeCount??0," cards · ",ae(z)," connected boards"]},void 0,!0,void 0,this),r("p",{children:z.summary||"No summary yet."},void 0,!1,void 0,this),r("p",{class:z.inContext?"memory-context-legend":"",children:z.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),!qe&&r("p",{role:"status",children:w?.key===y?"Connections could not be loaded.":"Loading connections…"},void 0,!1,void 0,this),r("ul",{children:[W.map((R)=>{let ne=R.source.boardId===z.boardId,Ce=ne?R.target:R.source,Te=qe?.nodes.find((fe)=>fe.key===Mt(Ce));return r("li",{children:[r("span",{children:[ne?"→":"←"," ",R.kind==="card"?ha({...R,kind:R.relationKind}):`${R.kind}${R.label?` · ${R.label}`:""}`]},void 0,!0,void 0,this),R.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)]},R.id,!0,void 0,this)}),(qe?.unresolvedLinks??[]).filter((R)=>R.source.boardId===z.boardId).map((R)=>r("li",{class:"home-memory-missing",children:["⚠ Unresolved wiki: [[",R.ref,"]]"]},`${Mt(R.source)}:${R.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 Je={width:220,height:96,gap:64},nc=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),SL=(e,t)=>e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom;function _L(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 PT(e,t){let o=[...e].map(([f,m])=>({key:f,left:m.x-Je.width/2-8,right:m.x+Je.width/2+8,top:m.y-Je.height/2-8,bottom:m.y+Je.height/2+8})),i=(f,m)=>!o.some((h)=>_L(f,m,h)),s=o.flatMap((f)=>[{x:f.left,y:f.top},{x:f.right,y:f.top},{x:f.right,y:f.bottom},{x:f.left,y:f.bottom}]).filter((f)=>!o.some((m)=>SL(f,m))),a=new Map,l=(f,m)=>[{x:f.x-Je.width/2,y:f.y+m*Je.height},{x:f.x+Je.width/2,y:f.y+m*Je.height},{x:f.x+m*Je.width,y:f.y-Je.height/2},{x:f.x+m*Je.width,y:f.y+Je.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 f of t){let m=JSON.stringify([f.from,f.to].sort());p.set(m,(p.get(m)??0)+1)}for(let f of t){let m=e.get(f.from),h=e.get(f.to),g=JSON.stringify([f.from,f.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(m,b),C=l(h,b),y,k=1/0;for(let P of x)for(let L of C){let N=nc(P.stub,L.stub);if(N&&N<k&&i(P.stub,L.stub))k=N,y=[P.port,P.stub,L.stub,L.port]}if(!y){let P=s.map(()=>1/0),L=s.map(()=>-1),N=s.map(()=>0),Y=new Set;for(let X=0;X<s.length;X++)for(let V=0;V<x.length;V++){let ee=nc(x[V].stub,s[X]);if(ee<P[X]&&i(x[V].stub,s[X]))P[X]=ee,N[X]=V}let B=-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||P[ee]<P[X]))X=ee;if(X<0||P[X]>=k||!Number.isFinite(P[X]))break;Y.add(X);for(let ee=0;ee<C.length;ee++){let he=P[X]+nc(s[X],C[ee].stub);if(he<k&&i(s[X],C[ee].stub))k=he,B=X,J=ee}let V=a.get(X);if(!V)V=s.flatMap((ee,he)=>he!==X&&i(s[X],ee)?[{index:he,length:nc(s[X],ee)}]:[]),a.set(X,V);for(let ee of V)if(P[X]+ee.length<P[ee.index])P[ee.index]=P[X]+ee.length,L[ee.index]=X,N[ee.index]=N[X]}if(B>=0){let X=[];for(let he=B;he>=0;he=L[he])X.unshift(s[he]);let V=x[N[B]],ee=C[J];y=[V.port,V.stub,...X,ee.stub,ee.port]}}if(!y)continue;let _=Math.max(24,f.label.length*3.6+6),I=y.slice(1).map((P,L)=>({first:y[L],point:P,length:nc(y[L],P)})).filter((P)=>P.length>0).sort((P,L)=>L.length-P.length),w;for(let P=16;f.label&&!w;P+=20)w=I.flatMap(({first:N,point:Y,length:B})=>[0.5,0.25,0.75].flatMap((J)=>[-P,P].map((X)=>{let V=N.x+(Y.x-N.x)*J-(Y.y-N.y)*X/B,ee=N.y+(Y.y-N.y)*J+(Y.x-N.x)*X/B;return{x:V,y:ee,left:V-_,right:V+_,top:ee-16,bottom:ee+8}}))).find((N)=>![...o,...u].some((Y)=>N.left<Y.right&&N.right>Y.left&&N.top<Y.bottom&&N.bottom>Y.top));if(w)u.push(w);c.set(f.id,{points:y,path:y.map((P,L)=>`${L?"L":"M"} ${P.x} ${P.y}`).join(" "),label:w})}return c}var ls=(e)=>e.kind==="overview"?"overview":JSON.stringify(e),CL=(e,t)=>JSON.stringify([e,t].sort());function NT(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=CL(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 lp(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 MT(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||(lp(e)-0.5)*0.01,p=i.y-u.y||(lp(`${e}:y`)-0.5)*0.01,f=Math.max(1,Math.hypot(d,p)),m=14000/(f*f),h=o.get(c)??0,g=h?(f-290)*0.006*Math.sqrt(h)/s:0;a+=d/f*(m-g),l+=p/f*(m-g);let v=Je.width+Je.gap,b=(Je.height+Je.gap)*Je.width/Je.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 $T(e,t,n,o){let i=[...e.keys()].sort(),s=MT(i,t),a=Je.width/Je.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)),f=Math.min(1,24/Math.max(1,Math.hypot(p.x,p.y)))*o,m=p.x*f,h=p.y*f/a;e.set(u,{x:d.x+m,y:d.y/a+h}),c=Math.max(c,Math.hypot(m,h))}for(let[u,d]of i.entries())for(let p of i.slice(u+1)){let f=e.get(d),m=e.get(p),h=f.x-m.x,g=f.y-m.y,v=Je.width+Je.gap-Math.abs(h),b=Je.height+Je.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:f.x+x.x*C,y:f.y+x.y*C});if(p!==n)e.set(p,{x:m.x-x.x*y,y:m.y-x.y*y});c=Math.max(c,Math.hypot(x.x,x.y))}return c}function LT(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=MT(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 I of i.get(_).keys()){if(a.has(I))continue;a.add(I),k.push(I)}s.push(k.sort())}let l=new Map,c=Je.width/Je.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((I)=>l.has(I));if(!_.length)continue;l.set(k,{x:_.reduce((I,w)=>I+l.get(w).x,0)/_.length+(lp(k)-0.5)*240,y:_.reduce((I,w)=>I+l.get(w).y,0)/_.length+(lp(`${k}:y`)-0.5)*240})}for(let k=0;k<180;k++){let _=new Map;for(let I of y){if(n.has(I))continue;let w=l.get(I),{x:P,y:L}=zT(I,l,y,i.get(I)),N=Math.min(1,24/Math.max(1,Math.hypot(P,L)))*(1-k/200);_.set(I,{x:w.x+P*N,y:w.y+L*N})}for(let[I,w]of _)l.set(I,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=Je.width+Je.gap,p=Je.height+Je.gap,f=(y,k)=>Math.abs(y.x-k.x)<d&&Math.abs(y.y-k.y)<p,m=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)m=u.length?Math.max(...u.map((w)=>w.x))+340:0,h=m,C=!0;let _=k?u:[],I=[];for(let w of y){if(n.has(w))continue;let P=l.get(w),L=P;if(_.some((N)=>f(L,N)))L=_.flatMap((Y)=>[{x:Y.x-d,y:P.y},{x:Y.x+d,y:P.y},{x:P.x,y:Y.y-p},{x:P.x,y:Y.y+p}]).filter((Y)=>!_.some((B)=>f(Y,B))).sort((Y,B)=>Math.hypot(Y.x-P.x,Y.y-P.y)-Math.hypot(B.x-P.x,B.y-P.y))[0];l.set(w,L),_.push(L),I.push(L)}if(!k&&I.length){let w=Math.min(...I.map((L)=>L.x)),P=Math.min(...I.map((L)=>L.y));for(let L of I)L.x+=h-w,L.y+=g-P;if(u.push(...I),h=Math.max(...I.map((L)=>L.x))+340,v=Math.max(v,Math.max(...I.map((L)=>L.y))-g+200),h-m>b)h=m,g+=v,v=0}}for(let[y,k]of l)if(!n.has(y))n.set(y,k);return l}var OT={portal:"Portals",wiki:"Wiki links",card:"Card relations",previous:"Previous boards"},Eg=(e)=>({scene:e,camera:null,query:"",context:!1,folders:new Set,hiddenLinks:new Set,inspection:null,limit:80});function DT(){let e=Ge.value,{graph:t,loading:n,error:o,retry:i}=ap("full"),[s,a]=E([Eg({kind:"overview"})]),l=s.at(-1),c=l.scene,u=ls(c),[d,p]=E(!1),[f,m]=E(0),[h,g]=E(0),[v,b]=E(null),[x,C]=E(""),[y,k]=E({width:0,height:0}),_=D(new Map),I=D(null),w=D(null),P=D(null),L=D(null),N=()=>{if(P.current!==null)cancelAnimationFrame(P.current);P.current=null,L.current=null},Y=D(!1),B=(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(ls(S)===u){m((K)=>K+1);return}a((K)=>[...K,Eg(S)]),p(!1),b(null),C("")},V=(S)=>{let K=s.map((ue)=>ls(ue.scene)).lastIndexOf(ls(S));if(K>=0)a((ue)=>ue.slice(0,K+1));else X(S);p(!1)};Me(()=>{ut.value=!0},[]),Me(()=>{let S=I.current,K=()=>k({width:S.clientWidth,height:S.clientHeight}),ue=new ResizeObserver(K);return ue.observe(S),K(),()=>ue.disconnect()},[]),Me(()=>{let S=(K)=>{if(!ir(K))return;if(l.inspection||s.length>1)if(K.preventDefault(),l.inspection)B({inspection:null});else J()};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[l.inspection,s.length]);let ee=Ke(()=>(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=Ke(()=>new Map(ee.map((S)=>[S.key,S])),[ee]),A=Ke(()=>NT(t?.edges??[]),[t]),te=c.kind==="overview"?null:Mt(c),M=te?he.get(te):void 0,O=(S)=>e.find((K)=>K.id===S)?.name??S,Pe=(S)=>c.kind!=="overview"&&S.boardId===c.boardId,Fe=c.kind==="overview"?A.evidence:A.evidence.filter((S)=>c.kind==="board"?S.source.boardId===c.boardId||S.target.boardId===c.boardId:S.from===te||S.to===te),De=Ke(()=>{if(c.kind==="overview")return{nodes:ee.filter((ue)=>ue.kind==="board"),links:[...A.pairs].map(([ue,$e])=>({id:ue,from:Mt({boardId:$e.boardId}),to:Mt({boardId:$e.peerId}),edges:$e.edges,bundle:!0}))};let S=new Set;if(c.kind==="board"){for(let ue of ee)if(Pe(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 Fe){if(ue.missing||!he.has(ue.from)||!he.has(ue.to))continue;let $e=c.kind==="board"&&ue.source.boardId!==c.boardId?Mt({boardId:ue.source.boardId}):ue.from,je=c.kind==="board"&&ue.target.boardId!==c.boardId?Mt({boardId:ue.target.boardId}):ue.to;S.add($e),S.add(je);let le=c.kind==="card"?ue.id:JSON.stringify([$e,je].sort()),we=K.get(le);if(we)we.edges.push(ue),we.bundle=!0;else K.set(le,{id:le,from:$e,to:je,edges:[ue],bundle:$e!==ue.from||je!==ue.to})}return{nodes:ee.filter((ue)=>S.has(ue.key)),links:[...K.values()]}},[ee,t,u]),Ae=new Map;for(let S of De.links)for(let K of[S.from,S.to])Ae.set(K,(Ae.get(K)??0)+S.edges.length);let ve=De.nodes.filter((S)=>Ae.has(S.key)||S.key===te),z=De.nodes.filter((S)=>!Ae.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} ${O(S.boardId)} ${S.folder??""}`.toLocaleLowerCase().includes(l.query.trim().toLocaleLowerCase()),Ne=ve.filter(re).sort((S,K)=>Number(K.key===te)-Number(S.key===te)||(Ae.get(K.key)??0)-(Ae.get(S.key)??0)||S.key.localeCompare(K.key)),ke=Ne.slice(0,l.limit),ae=new Set(ke.map((S)=>S.key)),Se=z.filter(re),de=De.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));q(()=>()=>{N(),Y.current||=!!w.current?.moved,w.current=null},[De,l.limit,l.query,l.context,l.folders,l.hiddenLinks]);let Ue=(S)=>{if(P.current!==null)return;let K=180,ue=()=>{let $e=w.current?.key===S,je=_.current.get(u);if(L.current)je.set(S,L.current);L.current=null;let le=new Map(ke.map((ge)=>[ge.key,je.get(ge.key)])),we=$T(le,de.map((ge)=>({...ge,weight:ge.edges.length})),S,$e?1:K/180);for(let[ge,Le]of le)je.set(ge,Le);if(g((ge)=>ge+1),$e||--K>0&&we>0.02)P.current=requestAnimationFrame(ue);else P.current=null};P.current=requestAnimationFrame(ue)},xe=Ke(()=>{let S=_.current.get(u);if(!S)S=new Map,_.current.set(u,S);if(c.kind!=="card")return LT(ve,De.links.map((ge)=>({...ge,weight:ge.edges.length})),S);if(!S.has(te))S.set(te,{x:0,y:0});let K=Fe.filter((ge)=>ge.kind!=="card"||mo({kind:ge.relationKind,type:ge.type},e.find((Le)=>Le.id===ge.source.boardId)?.relationVocabulary).directed),ue=new Set(K.filter((ge)=>ge.to===te).map((ge)=>ge.from)),$e=new Set(K.filter((ge)=>ge.from===te).map((ge)=>ge.to)),je=ve.filter((ge)=>ge.key!==te).sort((ge,Le)=>ge.key.localeCompare(Le.key)),le=Je.width+Je.gap,we=Je.height+Je.gap;for(let ge of["incoming","outgoing","mutual"]){let Le=je.filter((on)=>(ue.has(on.key)&&!$e.has(on.key)?"incoming":$e.has(on.key)&&!ue.has(on.key)?"outgoing":"mutual")===ge),Rt=Le.filter((on)=>S.has(on.key)).map((on)=>S.get(on.key)),pt=S.get(te).y+we,pn=0;for(let[on,fs]of Le.entries())if(!S.has(fs.key)){let Pn=Rt.length?Math.max(...Rt.map((fn)=>ge==="mutual"?fn.x:fn.y))+(pn+1)*(ge==="mutual"?le:we):(on-(Le.length-1)/2)*(ge==="mutual"?le:we),xn=ge==="mutual"?{x:Pn,y:pt}:{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(fs.key,xn),pn++}}return new Map(S)},[De,u,h]),qe=(S)=>S.bundle?`${S.edges.length} links`:S.edges[0].kind==="card"?mo({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,W=Ke(()=>PT(new Map(ke.map((S)=>[S.key,xe.get(S.key)])),de.map((S)=>({...S,label:S.edges.length>1||c.kind==="card"?qe(S):""})).sort((S,K)=>S.id.localeCompare(K.id))),[xe,De,l.limit,l.query,l.context,l.folders,l.hiddenLinks]),ye=l.camera??{x:0,y:0,scale:1},He=ke.filter((S)=>{let K=xe.get(S.key);return(K.x-Je.width/2)*ye.scale+ye.x<8||(K.x+Je.width/2)*ye.scale+ye.x>y.width-8||(K.y-Je.height/2)*ye.scale+ye.y<(c.kind==="card"?40:8)||(K.y+Je.height/2)*ye.scale+ye.y>y.height-64}).length,R=(S=!1)=>{let K=I.current;if(!K||!ke.length)return;let ue=c.kind==="card"?40:16,$e=K.clientHeight-ue-64-8,je=ke.flatMap((pt)=>{let pn=xe.get(pt.key);return[{x:pn.x-Je.width/2,y:pn.y-Je.height/2},{x:pn.x+Je.width/2,y:pn.y+Je.height/2}]});for(let pt of W.values())if(je.push(...pt.points),pt.label)je.push({x:pt.label.left,y:pt.label.top},{x:pt.label.right,y:pt.label.bottom});let le=Math.min(...je.map((pt)=>pt.x)),we=Math.min(...je.map((pt)=>pt.y)),ge=Math.max(...je.map((pt)=>pt.x))-le,Le=Math.max(...je.map((pt)=>pt.y))-we,Rt=Math.min(1,Math.max(S?1:0.005,Math.min((K.clientWidth-64)/ge,$e/Le)));B({camera:S&&c.kind==="card"?{x:K.clientWidth/2-xe.get(te).x,y:ue+$e/2-xe.get(te).y,scale:1}:{x:(K.clientWidth-ge*Rt)/2-le*Rt,y:ue+($e-Le*Rt)/2-we*Rt,scale:Rt}})};Me(()=>{if(t&&!l.camera&&ke.length)R(!0)},[t,u,l.camera]),q(()=>{if(!t||c.kind==="overview"||M)return;let S=he.has(Mt({boardId:c.boardId}));a((K)=>{let ue=K.filter((je)=>je.scene.kind==="overview"||he.has(Mt(je.scene))),$e=c.kind==="card"&&S?{kind:"board",boardId:c.boardId}:{kind:"overview"};return ls(ue.at(-1).scene)===ls($e)?ue:[...ue,Eg($e)]}),C("The focused endpoint was removed. Returned to its nearest available level.")},[t,te,M]);let ne=(S)=>{let K=xe.get(S.key),ue=I.current;if(!K||!ue)return;let $e=Math.max(1,ye.scale);B({camera:{x:ue.clientWidth/2-K.x*$e,y:ue.clientHeight/2-K.y*$e-20,scale:$e},limit:Math.max(l.limit,Ne.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=I.current;if(!ue)return;let $e=K??{x:ue.clientWidth/2,y:ue.clientHeight/2},je=Math.max(0.005,Math.min(3,S));B({camera:{x:$e.x-($e.x-ye.x)*je/ye.scale,y:$e.y-($e.y-ye.y)*je/ye.scale,scale:je}})},fe=De.links.find((S)=>S.id===l.inspection),it=fe?.edges??Fe,Ht=M?e.find((S)=>S.id===M.boardId):void 0,Ye=(S)=>{B({inspection:S.id}),m((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),F=c.kind!=="overview"&&!M,Ie=c.kind==="overview"?"Library":c.kind==="board"?O(c.boardId):M?.title??"Missing card";return r("main",{class:`home-memory graph-view${d?" sidebar-open":""}`,"aria-label":"Library Graph",style:{"--graph-node-width":`${Je.width}px`,"--graph-node-height":`${Je.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:O(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 · ",He," partly/outside view ·"," ",ve.length-Ne.length," filtered · ",Math.max(0,Ne.length-ke.length)," hidden ·"," ",z.length," without links"]},void 0,!0,void 0,this),Ne.length>l.limit&&r("button",{type:"button",class:"home-button",onClick:()=>B({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:I,"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;N(),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,$e=S.clientY-K.start.y;if(Math.abs(ue)+Math.abs($e)>4)K.moved=!0;if(!K.moved)return;let je={x:K.origin.x+ue/(K.key?ye.scale:1),y:K.origin.y+$e/(K.key?ye.scale:1)};if(K.key)L.current=je,Ue(K.key);else B({camera:{...je,scale:ye.scale}})},onPointerUp:()=>{if(!w.current)return;Y.current=w.current.moved,w.current=null},onPointerCancel:()=>{let S=w.current;if(N(),S?.layout)_.current.set(u,S.layout),g((K)=>K+1);else if(S)B({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=W.get(S.id);if(!ue)return null;let $e=S.edges[0],je=mo({kind:$e.relationKind,type:$e.type},e.find((Le)=>Le.id===$e.source.boardId)?.relationVocabulary),le=!S.bundle&&($e.kind!=="card"||je.directed),we=S.bundle?"var(--c-muted)":$e.kind==="card"?`var(--c-rel-${je.ink})`:$e.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:()=>Ye(S),onKeyDown:(Le)=>{if(Le.key==="Enter"||Le.key===" ")Le.preventDefault(),Ye(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:qe(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),$e=e.find((le)=>le.id===S.boardId),je=S.kind==="board"?S.inContext:!!$e?.pinnedTitles?.some((le)=>le.nodeId===S.cardId)||S.inContext&&!$e?.pin;return r("article",{"data-key":S.key,class:`graph-node is-${S.kind}${te===S.key?" is-selected":""}${je?" in-context":""}${c.kind!=="overview"&&!Pe(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(),N(),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),I.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 · ${A.internal.get(S.boardId)??0} internal`:`${O(S.boardId)} · ${S.type??"card"}`},void 0,!1,void 0,this),r("span",{class:je?"memory-context-legend":"",children:je?"⌖ 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:()=>R(),children:"Fit view"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(x||F||!t||!ke.length||o)&&r("div",{class:"home-memory-status",role:"status",children:x||(F?"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)=>B({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,...z].filter(re).slice(0,30).map((S)=>r("li",{children:r("button",{type:"button",class:"home-button",onClick:()=>{if(Ae.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,()=>B({context:!l.context}))]},void 0,!0,void 0,this),r("section",{children:[r("h2",{children:"Folders"},void 0,!1,void 0,this),[...new Set(De.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);B({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(OT).map((S)=>r("div",{children:Lt(OT[S],!l.hiddenLinks.has(S),()=>{let K=new Set(l.hiddenLinks);if(K.has(S))K.delete(S);else K.add(S);B({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:[A.evidence.length," links ·"," ",[...A.pairs.values()].reduce((S,K)=>S+K.edges.length,0)," between boards ·"," ",[...A.internal.values()].reduce((S,K)=>S+K,0)," inside boards ·"," ",A.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`:O(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(sp,{initiallyCollapsed:!0,reveal:f,children:M||fe?r("section",{class:"home-memory-details",role:"complementary","aria-label":"Selection details",children:[fe&&r("button",{type:"button",class:"home-memory-clear","aria-label":"Close details",onClick:()=>B({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:[fe?`${he.get(fe.from)?.title} ↔ ${he.get(fe.to)?.title}`:Ie," ·"," ",it.length," connections"]},void 0,!0,void 0,this),r("p",{children:fe?"Original evidence, not a new aggregate relation":`${M?.folder||"Unfiled"} / ${O(M.boardId)}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{class:"home-memory-actions",children:M&&r(be,{children:[r("button",{type:"button",class:"home-button is-primary",onClick:()=>void zt(M),children:["Open ",M.kind]},void 0,!0,void 0,this),Ht&&r(ho,{board:Ht},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:[M&&r("p",{class:M.inContext?"memory-context-legend":"",children:[M.inContext?"⌖ In context":"Not in context",M.linksComplete===!1?" · Partial discovery":""]},void 0,!0,void 0,this),r("details",{class:"home-memory-connections",open:!0,children:[r("summary",{children:["Connections",fe?" within this pair":""]},void 0,!0,void 0,this),r("ul",{children:[it.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,$e=he.get(Mt(ue)),je=mo({kind:S.relationKind,type:S.type},e.find((we)=>we.id===S.source.boardId)?.relationVocabulary),le=S.kind!=="card"||je.directed;return r("li",{children:[r("span",{children:[le?K?"→":"←":"↔"," ",S.kind==="card"?ha({...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??O(S.source.boardId)," ",le?"→":"↔"," ",he.get(S.to)?.title??S.target.cardId??O(S.target.boardId)," ·"," ",O(ue.boardId)]},void 0,!0,void 0,this),!$e||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($e),children:["Follow ",$e.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 BT({folder:e,folders:t,onScopeChange:n}){let[o,i]=E(""),[s,a]=E(!1),[l,c]=E(null),[u,d]=E(""),p=Oe.value;q(()=>{if(p)Kt()},[p]),Me(()=>{let C=(y)=>{if(!Oe.value)return;if(!ir(y))return;y.preventDefault(),i(""),a(!1)};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[]);let f=Xn.value,m=(C)=>!e||C===e||!!C?.startsWith(`${e}/`),h=(f?.reviewCards??[]).filter((C)=>m(C.folder)),g=o.trim().toLocaleLowerCase(),v=h.filter((C)=>{let y=f?.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)=>m(C.folder)).map((C)=>C.id)),x=Object.entries(f?.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),Oi.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),!f?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=f.cards[y],_=[...k.reasons,...k.sources.map((I)=>`${I.title}: ${I.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(!Oe.value)return;c(y),d("");let I=await zt(C,{review:!0});if(c(null),!I)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 TL=Pi({decayType:mn(["reality","decision","dependency","relevance"]),rate:mn(["fast","medium","slow","durable"]),triggers:We(U().trim().min(1)),revalidationMethod:U().trim().min(1),cadenceDays:Ze().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."}),FT=TL.safeExtend({id:U().trim().min(1),name:U().trim().min(1),glyph:U().trim().min(1)});var sr=(e,t,n,o,i,s)=>({id:e,name:t,glyph:n,decayType:o,rate:i,revalidationMethod:s,triggers:[],...i==="medium"?{cadenceDays:90}:{}}),HT=sr("research","Research","⌕","reality","medium","Check the sources and conflicting evidence."),UT=sr("metric","Metric","▥","reality","fast","Re-read the source dashboard and compare."),jT=sr("decision","Decision","⚑","decision","durable","Check for a superseding decision and changed dependencies."),ZT=sr("notes","Notes","✎","relevance","slow","Check relevance to the resumed task."),cp={"Org · team · personal":{categories:[sr("strategy","Strategy","◎","relevance","slow","Check the current goals and decisions."),sr("policy","Policy","◇","decision","slow","Check with the policy owner."),jT,HT,UT,ZT],folders:{Org:"strategy","Org/Policies":"policy",Team:"research","Team/Decisions":"decision","Team/Metrics":"metric",Personal:"notes"}},"Solo research":{categories:[sr("question","Question","?","relevance","slow","Check whether this question still matters."),sr("source","Source","▤","reality","medium","Re-read the original source."),sr("finding","Finding","◉","dependency","durable","Compare the supporting and contradicting evidence."),sr("note","Note","✎","relevance","slow","Check relevance to the resumed task.")],folders:{Projects:"question","Projects/Findings":"finding",Sources:"source",Notes:"note"}},"Product team":{categories:[HT,UT,jT,ZT],folders:{Discovery:"research","Discovery/Metrics":"metric",Delivery:"notes",Decisions:"decision"}},Empty:{categories:[],folders:{}}};function WT({folder:e,onClose:t}){let n=Oe.value,o=D(null),i=Xn.value,s=i?.folders.find((M)=>M.path===e),a=e?i?.resolvedFolders[e]:null,[l,c]=E(s?.categoryId??""),[u,d]=E(!!s?.lifecycleOverride),[p,f]=E(s?.lifecycleOverride??a?.lifecycle??xa),[m,h]=E(()=>i?.categories[0]?structuredClone(i.categories[0]):null),[g,v]=E(null),b=i?.categories.find((M)=>M.id===m?.id),x=i?.folders.filter((M)=>M.categoryId===m?.id)??[],[C,y]=E(!1),[k,_]=E(""),[I,w]=E(()=>JSON.stringify(m)),[P,L]=E("Basics"),[N,Y]=E(""),[B,J]=E(null),X=!e&&JSON.stringify(m)!==I,V=(M)=>{if(!Oe.value||C||B)return;if(X)J(()=>M);else M()},ee=()=>{if(!Oe.value)return;if(B)J(null);else if(g)v(null);else V(t)};bn(o,n,{onEscape:ee}),Me(()=>{if(!n&&o.current?.contains(document.activeElement))document.querySelector('button[aria-label="Settings"]')?.focus({preventScroll:!0})},[n]),q(()=>{if(n)Kt()},[n]);let he=(M)=>{let O=structuredClone(M);h(O),w(JSON.stringify(O)),L("Basics"),v(null),_("")},A=async(M,O)=>{if(!Oe.value)return!1;return(await pe("knowledgeWrite",`/api/canvas/knowledge/${M}`,null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(O)}))?.ok===!0},te=async(M)=>{if(!Oe.value||C||!i)return;let O=tn;y(!0),_("");let Pe=!0,Fe=cp[M];for(let De of Fe.categories){if(!Oe.value||O!==tn){Pe=!1;break}if(!i.categories.some((Ae)=>Ae.id===De.id))Pe=await A("category",{category:De});if(!Pe)break}if(Pe)for(let[De,Ae]of Object.entries(Fe.folders)){if(!Oe.value||O!==tn){Pe=!1;break}if(!i.folders.some((ve)=>ve.path===De))Pe=await A("folder",{path:De,categoryId:Ae,lifecycleOverride:null});if(!Pe)break}await Kt(),y(!1),_(Pe?M==="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:(M)=>{if(M.key==="Escape")M.stopPropagation(),M.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),B&&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(!Oe.value)return;let M=B;J(null),w(JSON.stringify(m)),M()},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:Ho,onSubmit:async(M)=>{if(M.preventDefault(),!Oe.value||C)return;let O=tn;y(!0);let Pe=await A("folder",{path:e,categoryId:l||null,lifecycleOverride:u?Ql(p):null});if(await Kt(),y(!1),Pe&&Oe.value&&O===tn)t();else if(!Pe)_("Folder settings were not saved. Retry.")},children:[r("div",{class:"knowledge-field",children:[r("span",{children:"Category"},void 0,!1,void 0,this),r(Mr,{label:"Category",value:l,onChange:c,options:[{value:"",label:"Use the parent’s"},...i.categories.map((M)=>({value:M.id,label:`${M.glyph} ${M.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:(M)=>d(M.currentTarget.checked)},void 0,!1,void 0,this)," ","Override lifecycle for this folder"]},void 0,!0,void 0,this),u?r(Yl,{value:p,onChange:f},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(cp).map(([M,O])=>r("button",{type:"button",disabled:C||!!B,onClick:()=>V(()=>{if(X)h(b?structuredClone(b):null),w(JSON.stringify(b??null));te(M)}),children:[r("strong",{children:M},void 0,!1,void 0,this),r("span",{children:Object.keys(O.folders).join(" / ")||"No folders or categories"},void 0,!1,void 0,this)]},M,!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:N,onInput:(M)=>Y(M.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{type:"button",disabled:C,onClick:()=>V(()=>he({...xa,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((M)=>M.name.toLocaleLowerCase().includes(N.toLocaleLowerCase())).map((M)=>r("button",{type:"button",class:"category-choice",disabled:C,"aria-pressed":m?.id===M.id,onClick:()=>{if(m?.id!==M.id)V(()=>he(M))},children:[r("strong",{children:[M.glyph," ",M.name]},void 0,!0,void 0,this),r("span",{children:[M.decayType," · ",M.rate,M.rate==="medium"&&M.cadenceDays?` · ${M.cadenceDays} days`:""]},void 0,!0,void 0,this)]},M.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),m&&r("form",{class:"category-inspector",noValidate:!0,onClick:Ho,onSubmit:async(M)=>{if(M.preventDefault(),!Oe.value||C)return;let O=tn,Pe=FT.safeParse({...m,...Ql(m)});if(!Pe.success){let Ae=String(Pe.error.issues[0].path[0]);L(["name","glyph","id"].includes(Ae)?"Basics":"Review policy"),_(Pe.error.issues[0].message),setTimeout(()=>{if(!Oe.value||O!==tn)return;let ve=Ae==="name"?"Name":Ae==="glyph"?"Glyph":Ae==="cadenceDays"?"Cadence in days":"How to check",z=o.current?.querySelectorAll("label");Array.from(z??[]).find((re)=>re.textContent?.trim().startsWith(ve))?.querySelector("input")?.focus()},0);return}y(!0);let Fe=await pe("knowledgeWrite","/api/canvas/knowledge/category",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({category:Pe.data})}),De=Fe?.ok===!0;if(await Kt(),y(!1),!Oe.value||O!==tn)return;if(De){let Ae=Fe?.category??Pe.data;h(Ae),w(JSON.stringify(Ae))}_(De?"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((M)=>r("button",{type:"button",role:"tab",id:`category-tab-${M.replace(" ","-")}`,"aria-controls":"category-tab-panel","aria-selected":P===M,onClick:()=>L(M),children:M},M,!1,void 0,this))},void 0,!1,void 0,this),r("fieldset",{disabled:C||!!B,id:"category-tab-panel",role:"tabpanel","aria-labelledby":`category-tab-${P.replace(" ","-")}`,class:"category-tab-content",children:[P==="Basics"&&r(be,{children:[r("label",{children:["Name",r("input",{required:!0,value:m.name,onInput:(M)=>h({...m,name:M.currentTarget.value})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("label",{children:["Glyph",r("input",{required:!0,value:m.glyph,onInput:(M)=>h({...m,glyph:M.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(cp).flatMap((M)=>M.categories.map((O)=>O.glyph)))].map((M)=>r("button",{type:"button","aria-label":`Choose glyph ${M}`,"aria-pressed":m.glyph===M,onClick:()=>h({...m,glyph:M}),children:M},M,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P==="Review policy"&&r(Yl,{value:m,onChange:(M)=>h({...m,...M})},void 0,!1,void 0,this),P==="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((M)=>M.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(!Oe.value||C)return;let M=tn;y(!0);let O=await pe("knowledgeRemove",`/api/canvas/knowledge/category/${encodeURIComponent(b.id)}`,null,{method:"DELETE"});if(await Kt(),y(!1),!Oe.value||M!==tn)return;if(v(null),O?.ok===!0)h(null),w("null");_(O?.ok===!0?"Category deleted.":O?.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||!!B,onClick:()=>V(t),children:"Cancel"},void 0,!1,void 0,this),r("button",{type:"submit",disabled:C||!!B,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 qT({onClose:e}){let t=D(null),n=Xn.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),[f,m]=E(""),[h,g]=E(!1),[v,b]=E(""),[x,C]=E(!1),y=D(null);q(()=>{if(!d)return;let N=document.activeElement;return y.current?.querySelector("button")?.focus(),()=>{if(N instanceof HTMLElement&&N.isConnected)N.focus()}},[d]);let k=s,_=a!==null&&JSON.stringify(a)!==JSON.stringify(c),I=(N)=>{if(h)return;if(_)p(()=>N);else N()},w=()=>{if(d)p(null);else if(x)C(!1);else I(e)};bn(t,!0,{onEscape:w});let P=(N)=>{i(N?structuredClone(N):null),l(null),u(null),C(!1),b("")},L=(N,Y)=>{if(a)l({...a,vocabulary:a.vocabulary.map((B,J)=>J===N?{...B,...Y}:B)})};return r("div",{class:"knowledge-backdrop",onKeyDown:(N)=>{if(N.key==="Escape")N.preventDefault(),N.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:()=>I(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 N=d;p(null),N()},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:()=>I(()=>{P(null);let N={id:crypto.randomUUID(),name:"",vocabulary:[]};u(structuredClone(N)),l(N)}),children:"Add preset"},void 0,!1,void 0,this),r("div",{class:"category-library",role:"group","aria-label":"Workspace relation presets",children:n.map((N)=>r("button",{type:"button",class:"category-choice",disabled:h,"aria-pressed":(a?.id??s?.id)===N.id,onClick:()=>I(()=>P(N)),children:[r("strong",{children:N.name},void 0,!1,void 0,this),r("span",{children:N.vocabulary.map((Y)=>Y.kind).join(" · ")||"No relation kinds"},void 0,!1,void 0,this)]},N.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:Ho,onSubmit:async(N)=>{if(N.preventDefault(),h)return;if(new Set(a.vocabulary.map((B)=>B.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)P(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:(N)=>l({...a,name:N.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((N,Y)=>r("div",{class:"vocabulary-row",children:[r("input",{required:!0,pattern:".*\\S.*","aria-label":`Kind ${Y+1}`,maxLength:80,disabled:h,value:N.kind,onInput:(B)=>L(Y,{kind:B.currentTarget.value})},void 0,!1,void 0,this),r("select",{"aria-label":`Ink ${Y+1}`,disabled:h,value:N.ink,onChange:(B)=>L(Y,{ink:B.currentTarget.value}),children:["supports","contradicts","cites","derived","informs","related"].map((B)=>r("option",{children:B},B,!1,void 0,this))},void 0,!1,void 0,this),r("label",{children:[r("input",{type:"checkbox",disabled:h,checked:N.directed,onChange:(B)=>L(Y,{directed:B.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((B,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:()=>I(()=>P(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((N)=>r("li",{style:{"--relation-ink":`var(--c-rel-${N.ink})`},children:[r("strong",{children:N.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":N.ink==="related"?"3 5":void 0},void 0,!1,void 0,this),N.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:[N.ink," · ",N.directed?"Directed: A → B":"Undirected: A — B"]},void 0,!0,void 0,this)]},N.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:f,onChange:(N)=>m(N.currentTarget.value),children:[r("option",{value:"",children:"Choose a board"},void 0,!1,void 0,this),Ge.value.map((N)=>r("option",{value:N.id,children:N.name},N.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||!f,onClick:async()=>{if(h||!f)return;g(!0);let N=await vr(f,{relationVocabulary:k.vocabulary});g(!1),b(N?"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 N=await pe("relationPresetRemove",`/api/canvas/knowledge/relation-preset/${encodeURIComponent(k.id)}`,null,{method:"DELETE"});if(await Kt(),g(!1),C(!1),N?.ok)P(null);b(N?.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 GT(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 Qd(e)}var ar=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function KT(e){return(e.links?.length??0)+(e.backlinks?.length??0)}async function Ag(e){let t=await On("New board","Board name",{confirm:"Create"});if(t)await Ek(t,e)}var VT="pmx-canvas-home-collapsed";function IL(){try{let e=localStorage.getItem(VT);if(e)return new Set(JSON.parse(e))}catch{}return new Set([CT])}function EL(e){try{localStorage.setItem(VT,JSON.stringify([...e]))}catch{}}var oc=(e,t)=>e.folder===t||!!e.folder?.startsWith(`${t}/`),lr=(e)=>e.split("/").at(-1)??e;function AL({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 XT(){let e=Ge.value,t=Oe.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,f]=E(!1),[m,h]=E(null),[g,v]=E(!1),[b,x]=E(!1),[C,y]=E(null),[k,_]=E(null),[I,w]=E(""),[P,L]=E([]),[N,Y]=E(IL),[B,J]=E(!1),[X,V]=E(!1),ee=D(null),he=D(null),A=[...new Set([...e.flatMap((F)=>F.folder?tc(F.folder):[]),...(Xn.value?.folders??[]).flatMap((F)=>tc(F.path)),...l.flatMap(tc)])].sort((F,Ie)=>F.localeCompare(Ie)),te=(F)=>A.filter((Ie)=>F?Ie.startsWith(`${F}/`)&&!Ie.slice(F.length+1).includes("/"):!Ie.includes("/")),M=I.trim().toLocaleLowerCase(),O=e.filter((F)=>F.pin),Pe=O.reduce((F,Ie)=>F+(Ie.mapChars??0),0),Fe=te(s),De=e.filter((F)=>(F.folder??"")===s).sort((F,Ie)=>(Ie.lastOpenedAt??"").localeCompare(F.lastOpenedAt??"")),Ae=M?e.filter((F)=>`${F.name} ${F.folder??""}`.toLocaleLowerCase().includes(M)):[],ve=e.find((F)=>F.id===m)??null,z=e.find((F)=>F.id===C),re=e.find((F)=>F.id===k),Ne=new Set(e.filter((F)=>!s||oc(F,s)).map((F)=>F.id)),ke=Object.entries(Xn.value?.cards??{}).filter(([F])=>Ne.has(JSON.parse(F)[0])).map(([,F])=>F),ae=ke.filter((F)=>!F.retired&&(F.due||F.sources.length)).length,Se=ke.filter((F)=>F.unknown).length,de=Xn.value?.resolvedFolders[s]?.category,Ue=new Map;for(let[F,Ie]of Object.entries(Xn.value?.cards??{})){if(Ie.retired||!(Ie.due||Ie.sources.length))continue;let[S,K]=JSON.parse(F),ue=Ue.get(S)??[];ue.push(K),Ue.set(S,ue)}let xe=M?Ae:De,qe=async(F)=>{if(!Oe.value)return;let Ie=tn,S=Ue.get(F)?.[0];if(!S)return;if(await zt({boardId:F,cardId:S})&&Oe.value&&Ie===tn&&se.value===F)Ro.value="To review"};q(()=>{let F=I.trim();if(!F){L([]);return}let Ie=!1,S=window.setTimeout(()=>{pe("searchLibrary",`/api/canvas/search?q=${encodeURIComponent(F)}&scope=library&limit=30`,null).then((K)=>{if(!Ie)L(K?.results??[])})},150);return()=>{Ie=!0,window.clearTimeout(S)}},[I]),q(()=>{if(g)he.current?.querySelector('[role="menuitem"]')?.focus()},[g]),q(()=>{if(m&&!e.some((F)=>F.id===m))h(null)},[e,m]),Me(()=>{if(i!=="Folders"||!m)return;let F=(Ie)=>{if(!ir(Ie))return;Ie.preventDefault(),h(null),x(!1)};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[i,m]);let W=(F)=>zt(F),ye=(F)=>{let Ie=new Set(N);if(Ie.has(F))Ie.delete(F);else Ie.add(F);Y(Ie),EL(Ie)},He=(F)=>{a(F),w(""),h(null),J(!1)},R=(F)=>{h(F),v(!1),x(!1)},ne=async()=>{let F=await On("New folder","Folder name",{confirm:"Create"});if(!F)return;let Ie;try{Ie=ip(s?`${s}/${F}`:F)}catch{return}if(!Ie)return;c((S)=>[...S,Ie]),He(Ie)},Ce=async(F)=>{let Ie=await On("Rename board","Board name",{initial:F.name,confirm:"Rename"});if(Ie&&Ie!==F.name)await vr(F.id,{name:Ie})},Te=(F,Ie)=>{let S=te(F),K=!N.has(F),ue=e.filter((je)=>oc(je,F)).length,$e=e.some((je)=>je.pin&&oc(je,F));return r("li",{children:[r("div",{class:`home-tree-row${s===F&&!M?" is-selected":""}`,"data-folder":F,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 ${lr(F)}`:`Unfold ${lr(F)}`,"aria-expanded":K,onClick:()=>ye(F),children:K?r(js,{},void 0,!1,void 0,this):r(oi,{},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:()=>He(F),children:lr(F)},void 0,!1,void 0,this),$e&&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((je)=>Te(je,Ie+1))},void 0,!1,void 0,this)]},F,!0,void 0,this)},fe=r("ul",{class:"home-tree","aria-label":"Folders",children:[te("").map((F)=>Te(F,0)),r("li",{children:r("div",{class:`home-tree-row is-unfiled${s===""&&!M?" is-selected":""}`,children:[r("span",{class:"home-tree-chevron"},void 0,!1,void 0,this),r("button",{type:"button",class:"home-tree-name",onClick:()=>He(""),children:"Unfiled"},void 0,!1,void 0,this),r("span",{class:"home-tree-count",children:e.filter((F)=>!F.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),it=r("ul",{class:"home-pinned","aria-label":"Pinned boards",children:O.map((F)=>r("li",{children:r("button",{type:"button",class:"home-pinned-row",onClick:()=>He(F.folder??""),children:[r("span",{class:"home-pin-dot","aria-hidden":"true",children:r(uo,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"home-pinned-name",children:F.name},void 0,!1,void 0,this),r("span",{class:"home-tree-count",children:F.folder?lr(F.folder):"Unfiled"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},F.id,!1,void 0,this))},void 0,!1,void 0,this),Ht=r("label",{class:"home-search",children:[r(Mu,{},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:I,onInput:(F)=>w(F.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ye=(F)=>r("li",{children:r("article",{class:`home-card${F.pin?" is-pinned":""}${m===F.id?" is-selected":""}`,"data-testid":"home-board","data-board-id":F.id,children:[r("button",{type:"button",class:"home-card-select","aria-label":F.name,"aria-pressed":m===F.id,onClick:()=>R(F.id),onDblClick:()=>void Mn(F.id),children:[r(AL,{board:F},void 0,!1,void 0,this),r("span",{class:"home-card-body",children:[r("span",{class:"home-card-name",children:F.name},void 0,!1,void 0,this),r("span",{class:"home-card-readme",children:F.summary??"No README yet."},void 0,!1,void 0,this),r("span",{class:"home-card-meta",children:[r("span",{children:ar(F.nodeCount,"card")},void 0,!1,void 0,this),KT(F)>0&&r("span",{children:["↔ ",ar(KT(F),"link")]},void 0,!0,void 0,this),r("span",{class:"home-card-when",children:GT(F.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&&Ue.has(F.id)&&r("button",{type:"button",class:"home-card-review","aria-label":`Review ${F.name}`,onClick:()=>void qe(F.id),children:["⧗ Review ",ar(Ue.get(F.id).length,"card")]},void 0,!0,void 0,this),r(ho,{board:F},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},F.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:()=>R(null)},void 0,!1,void 0,this),r("div",{class:"home-details-head",children:[r("span",{class:"home-details-folder",children:ve.folder?lr(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 $s(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 ",ar(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),Nk(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&&Ue.has(ve.id)&&r("button",{type:"button",class:"home-button",onClick:()=>void qe(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(ml,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),g&&r("span",{ref:he,class:"home-more-menu",role:"menu",onKeyDown:(F)=>{let Ie=[...he.current?.querySelectorAll('[role="menuitem"]')??[]],S=Ie.indexOf(document.activeElement);if(F.key==="Escape")F.preventDefault(),v(!1),ee.current?.focus();else if(F.key==="ArrowDown"||F.key==="ArrowUp"){F.preventDefault();let K=F.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(([F,Ie])=>r("button",{type:"button",role:"menuitem",class:"home-more-item",onClick:()=>{v(!1),Ie()},children:F},F,!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(WT,{folder:u||void 0,onClose:()=>d(null)},u,!1,void 0,this),p&&r(qT,{onClose:()=>f(!1)},void 0,!1,void 0,this),r("nav",{class:"home-view-tabs","aria-label":"Library view",children:[["Folders","Map","Graph","Review"].filter((F)=>t||F!=="Review").map((F)=>r("button",{type:"button",class:"home-button","aria-pressed":i===F,onClick:()=>o(F),children:F},F,!1,void 0,this)),r("button",{type:"button",class:"home-button",onClick:()=>f(!0),children:"Relation presets"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i==="Map"||i==="Graph"?i==="Map"?r(RT,{},void 0,!1,void 0,this):r(DT,{},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${B?" 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:ar(e.length,"board")},void 0,!1,void 0,this),t&&r("button",{type:"button",class:"home-button",onClick:()=>{if(Oe.value)d("")},children:"Categories"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ht,O.length>0&&r("section",{class:"home-library-section",children:[r("span",{class:"home-section-label",children:"Pinned boards"},void 0,!1,void 0,this),it,r("span",{class:"home-pinned-cost",children:["≈ ",Jl(Pe)," tokens · ",ar(O.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),fe,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:[Ht,O.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(uo,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{class:"home-narrow-context-label",children:["In context: ",ar(O.length,"board")]},void 0,!0,void 0,this),r("span",{class:"home-narrow-context-cost",children:["≈ ",Jl(Pe)," 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&&it]},void 0,!0,void 0,this),r("button",{type:"button",class:"home-narrow-picker","aria-expanded":B,onClick:()=>J(!B),children:[s?lr(s):"Library",r("span",{class:"home-tree-count",children:["· ",s?e.filter((F)=>oc(F,s)).length:De.length," ▾"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i==="Review"?r(BT,{folder:s,folders:A,onScopeChange:He},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:()=>He(""),children:"Library"},void 0,!1,void 0,this),s&&tc(s).map((F)=>r("span",{children:[r("span",{class:"home-crumb-sep",children:"/"},void 0,!1,void 0,this),r("button",{type:"button",onClick:()=>He(F),children:lr(F)},void 0,!1,void 0,this)]},F,!0,void 0,this))]},void 0,!0,void 0,this),r("h1",{class:"home-view-title",children:M?`Results for “${I.trim()}”`:s?lr(s):"Library"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&r("button",{type:"button",class:"home-button",onClick:()=>{if(Oe.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 Ag(s||null),children:s?"New board here":"New board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&Xn.value&&!M&&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: ",ar(ae,"card")]},void 0,!0,void 0,this),r("span",{children:["No review policy: ",ar(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):M?r(be,{children:[P.length>0&&r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:["Cards · ",P.length]},void 0,!0,void 0,this),r("ul",{class:"home-hits","aria-label":"Library search results",children:P.map((F)=>r("li",{children:r("button",{type:"button",class:"home-hit",onClick:()=>void W(F),children:[r("span",{class:"home-card-name",children:F.title||F.boardTitle},void 0,!1,void 0,this),t&&F.qualification?.retired&&r("span",{class:"category-tag",children:"Retired"},void 0,!1,void 0,this),r("span",{class:"home-card-meta",children:[F.boardTitle," · ",F.snippet]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},`${F.boardId}:${F.cardId}`,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ae.length>0?r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:["Boards · ",Ae.length]},void 0,!0,void 0,this),r("ul",{class:"home-cards",children:Ae.map(Ye)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):P.length===0&&r("div",{class:"home-view-empty",role:"status",children:["No boards match “",I.trim(),"”."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):r(be,{children:[Fe.length>0&&r("section",{class:"home-main-section",children:[r("span",{class:"home-section-label",children:["Folders · ",Fe.length]},void 0,!0,void 0,this),r("ul",{class:"home-folders",children:Fe.map((F)=>{let Ie=e.filter((ue)=>oc(ue,F)),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":F,onClick:()=>He(F),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:lr(F)},void 0,!1,void 0,this),r("span",{class:"home-folder-meta",children:[ar(Ie.length,"board"),S?` · opened ${GT(S)}`:""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},F,!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 ${lr(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(Ye)},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,z&&r(TT,{board:z,folders:A,onClose:()=>y(null)},z.id,!1,void 0,this),re&&r(IT,{board:re,onClose:()=>_(null)},re.id,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var cs=ie(!1);function RL(e){return e>=1048576?`${(e/1024/1024).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}function JT(){let[e,t]=E(!1),[n,o]=E(!1),[i,s]=E(null),[a,l]=E(null),[c,u]=E(!1),[d,p]=E(""),f=cs.value,m=se.value;if(q(()=>{if(!f||!m)return;let g=!0;return l(null),p(""),s(null),pe("exportPreview",`/api/canvas/export/preview?board=${encodeURIComponent(m)}&includeFiles=${e}&includeDerivedText=${n}`,null).then((v)=>{if(g)s(v?.manifest??null)}),()=>{g=!1}},[f,e,n,m]),q(()=>{o(!1)},[f,m]),q(()=>{if(!f)return;let g=(v)=>{if(v.key!=="Escape")return;v.stopPropagation(),cs.value=!1};return window.addEventListener("keydown",g,{capture:!0}),()=>window.removeEventListener("keydown",g,{capture:!0})},[f]),!f)return null;let h=async()=>{if(!i||i.boardId!==se.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&&se.value===i.boardId)l(g)};return r("div",{class:"text-prompt-backdrop",onPointerDown:()=>cs.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 (",RL(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:tt()?r("button",{type:"button",disabled:c,onClick:async()=>{u(!0),p("");try{await Gw(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),tt()&&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:()=>cs.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 Rg({presence:e,size:t=18}){return r("span",{class:"writer-avatar",style:{background:So(e.sessionId),width:`${t}px`,height:`${t}px`},"aria-hidden":"true",children:Md(e.label)},void 0,!1,void 0,this)}function YT(){let e=$d.value;if(tr.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=ts.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:()=>{ts.value=!o},children:[r("span",{class:"external-indicator-avatars",children:e.slice(0,3).map((i)=>r(Rg,{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 PL(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 NL(e){return e.reduce((t,n)=>n.lastSeenAt>t?n.lastSeenAt:t,"")}function ML(){return[...qt.value.values()].filter((e)=>!e.auto&&e.phase==="forming")}function QT(){let e=ts.value,t=$d.value,n=nr(e?1e4:0);if(Me(()=>{if(!e)return;let l=(c)=>{if(c.key!=="Escape"||c.defaultPrevented)return;if(c.preventDefault(),pa.value)pa.value=!1;else ts.value=!1};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e]),!e||tr.value||t.length===0)return null;let o=Jh.value,i=ML().filter((l)=>!o||(l.source??"")===o),s=fi.value.filter((l)=>!o||l.sessionId===o),a=(l,c)=>r("button",{type:"button",class:`activity-filter${o===l?" is-active":""}`,style:l?{"--writer":So(l)}:void 0,"aria-pressed":o===l,onClick:()=>{Jh.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(NL(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:()=>{ts.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:()=>{Li(l).then((c)=>{if(c)zi(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}=PL(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:So(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:()=>{pa.value=!0},children:"Writers"},void 0,!1,void 0,this),xt.value&&r("button",{type:"button",class:"activity-feed-link is-accent",onClick:()=>{ts.value=!1,vi()},children:["Start session ",r(ri,{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 zL(){let e=[];if(To.value)e.push("scoped");if(Co.value.length>0)e.push("gated");return e.length>0?e.join(" + "):"open"}function eI(){let e=pa.value,t=nr(e?1e4:0),n=D(null);if(bn(n,e),!e)return null;let o=xt.value?en.value.filter((a)=>a.attached):[],i=$d.value,s=()=>{pa.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:xr.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:[xt.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(Rg,{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:zL()},void 0,!1,void 0,this)]},a.sessionId,!0,void 0,this)),r("div",{class:"writers-section",children:xt.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(Rg,{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 tI({nodeId:e}){let t=se.value,[n,o]=E(null),[i,s]=E(!1),a=et.value,l=H.value,c=Ge.value;q(()=>{let m=!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(!m)o(h),s(!h)});return()=>{m=!0}},[t,e,a,l,c]);let u=t?Mt({boardId:t,cardId:e}):"",d=n?.edges.filter((m)=>m.kind!=="member"&&(m.from===u||m.to===u))??[],p=(m)=>{let h=m.to===u;if(h&&m.relationKind==="supports")return"Evidence for";if(h&&m.relationKind==="contradicts")return"Evidence against";let g=jd({kind:m.relationKind,type:m.type});if(g)return(g==="from"?!h:h)?"Used by":"Sources";if(m.relationKind==="cites"||m.type==="references")return h?"Used by":"Sources";if(!h&&m.relationKind==="supports")return"Used by";return"Connections"},f=["Evidence for","Evidence against","Sources","Used by","Connections"];return d.sort((m,h)=>f.indexOf(p(m))-f.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((m,h)=>{let g=m.from===u,v=g?m.target:m.source,b=n?.nodes.find((y)=>y.key===Mt(v)),x=c.find((y)=>y.id===m.source.boardId),C=mo({kind:m.relationKind,type:m.type},x?.relationVocabulary);return r("div",{class:"relation-row",children:[(h===0||p(d[h-1])!==p(m))&&r("h4",{children:p(m)},void 0,!1,void 0,this),r("span",{class:"relation-kind",style:{color:`var(--c-rel-${C.ink})`},children:[g?"→":"←"," ",m.relationKind??m.type??m.kind]},void 0,!0,void 0,this),m.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),m.label&&r("span",{children:m.label},void 0,!1,void 0,this),r("p",{children:m.reason??"No reason recorded."},void 0,!1,void 0,this)]},m.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 nI(e,t){switch(e.type){case"markdown":return r(Qu,{node:e,expanded:t},void 0,!1,void 0,this);case"mcp-app":return r(di,{node:e,expanded:t},void 0,!1,void 0,this);case"webpage":return r(Ad,{node:e,expanded:t},void 0,!1,void 0,this);case"json-render":return r(di,{node:e,expanded:t},void 0,!1,void 0,this);case"graph":return r(di,{node:e,expanded:t},void 0,!1,void 0,this);case"board":return r(Kd,{node:e},void 0,!1,void 0,this);case"prompt":return r(Rd,{node:e},void 0,!1,void 0,this);case"response":return r(Pd,{node:e,expanded:t},void 0,!1,void 0,this);case"status":return r(Id,{node:e},void 0,!1,void 0,this);case"context":return r($u,{node:e,expanded:t},void 0,!1,void 0,this);case"ledger":return r(Bu,{node:e},void 0,!1,void 0,this);case"trace":return r(Nd,{node:e},void 0,!1,void 0,this);case"file":return r(Du,{node:e,expanded:t},void 0,!1,void 0,this);case"diff":return r(Lu,{node:e},void 0,!1,void 0,this);case"mermaid":return r(ad,{node:e,expanded:t},void 0,!1,void 0,this);case"image":return r(Ed,{node:e,expanded:t},void 0,!1,void 0,this);case"html":return r(Hl,{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 oI(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 $L(e){if(!e)return 0;return e.split(/\s+/).filter(Boolean).length}function LL(e,t){return e!==null&&typeof e==="object"&&e.source===Qn&&e.type==="presentation-exit"&&e.token===t}function OL(e){return e==="ArrowRight"||e==="PageDown"||e===" "||e==="ArrowLeft"||e==="PageUp"||e==="Home"||e==="End"}function rI(e){return e instanceof HTMLElement&&Boolean(e.closest(".html-presentation-exit"))}function iI(){let e=Bt.value,t=e?H.value.get(e):void 0,[n,o]=E(!1),[i,s]=E(null),[a,l]=E(!1),[c,u]=E(""),d=D(null),p=D(null),f=oe(()=>{l(!1),Cr()},[]),m=oe(()=>{u(`presentation-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`),l(!0)},[]),h=oe((A)=>{document.querySelector(".html-presentation-overlay iframe.html-node-frame-presentation")?.contentWindow?.postMessage({source:Qn,token:c,...A},"*")},[c]),g=oe(()=>{l(!1)},[]),v=oe((A)=>{if(A.key==="Escape"){A.preventDefault(),A.stopPropagation(),l(!1);return}if(A.key==="Tab"&&!rI(A.target)){A.preventDefault(),A.stopPropagation(),p.current?.focus();return}if((A.key===" "||A.key==="Enter")&&rI(A.target))return;if(!OL(A.key))return;A.preventDefault(),A.stopPropagation(),h({type:"presentation-key",key:A.key})},[h]),b=oe((A)=>{if(A.target.classList.contains("expanded-overlay-backdrop"))Cr()},[]),x=oe(()=>{if(!t)return;let A=oI(t);if(!A)return;navigator.clipboard.writeText(A).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})},[t]),C=oe(()=>{if(!e)return;lo(e)},[e]);q(()=>{l(!1)},[e]),Me(()=>{if(!a)return;let A=()=>{let O=d.current;if(!O||O.contains(document.activeElement))return;O.focus()},te=[0,50,150].map((O)=>window.setTimeout(A,O)),M=(O)=>{if(!LL(O.data,c))return;l(!1)};return document.addEventListener("keydown",v,!0),window.addEventListener("message",M),()=>{te.forEach((O)=>{window.clearTimeout(O)}),document.removeEventListener("keydown",v,!0),window.removeEventListener("message",M)}},[v,c,a]);let y=D(null),k=oe(()=>e?document.querySelector(`.canvas-node[data-node-id="${CSS.escape(e)}"]`):null,[e]),_=Oe.value&&Ct.value?.nodeId===e,I=!Oe.value&&Ct.value?.nodeId===e&&!!document.activeElement?.closest(".lifecycle-dialog");if(bn(y,t!==void 0&&!_,{restoreTo:k}),Me(()=>{if(I)document.querySelector('button[aria-label="Settings"]')?.focus({preventScroll:!0})},[_]),!t)return null;let w=t.data.title||t.data.path?.split("/").pop()||an[t.type],P=oI(t),L=$L(P),N=e?kt.value.has(e):!1,Y=P.length>0,B=zo.value===e,J=t.type==="mcp-app"||t.type==="webpage"||t.type==="json-render"||t.type==="graph",X=q_(t),V=Do(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((A)=>typeof A==="string"&&A.length>0).join(" · "):null;return r("div",{class:"expanded-overlay-backdrop",onPointerDown:b,style:{pointerEvents:B?"none":"auto"},children:r("div",{ref:y,class:`expanded-overlay-panel${N?" 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:an[t.type]},void 0,!1,void 0,this),r(_e,{label:N?"In agent context — click to unpin":"Pin as agent context",children:r("button",{type:"button",class:`expanded-pin${N?" is-on":""}`,onClick:C,"aria-label":N?"In agent context — click to unpin":"Pin as agent context","aria-pressed":N,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:[Oe.value&&r("button",{type:"button",class:"expanded-action-btn",onClick:()=>Es(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),od(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 rd(t),children:["Open in tab ",r(ri,{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:m,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:f,"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:nI(t,!0)},void 0,!1,void 0,this):nI(t,!0)},void 0,!1,void 0,this),i===e&&r(tI,{nodeId:t.id},e,!1,void 0,this)]},void 0,!0,void 0,this),r(Wd,{node:t},void 0,!1,void 0,this),r("div",{style:{"--ax-dock-bleed":"0px","--ax-dock-pad":"16px"},children:r(Gd,{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,L>0?`${L.toLocaleString()} word${L!==1?"s":""}`:null].filter(Boolean).join(" · ")||an[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${B?" is-saving":""}`,children:B?"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(Hl,{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 aI=168,lI=112,up=20;function sI(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,f=d+o/t.scale,m={minX:Math.min(s,u)-up,minY:Math.min(a,d)-up,maxX:Math.max(l,p)+up,maxY:Math.max(c,f)+up},h=m.maxX-m.minX||1,g=m.maxY-m.minY||1;return{bounds:m,scale:Math.min(aI/h,lI/g)}}function cI({viewport:e,nodes:t,onNavigate:n,containerWidth:o,containerHeight:i}){let s=D(null),a=D(!1),l=t.value,c=e.value,u=sI(l,c,o,i),{bounds:d,scale:p}=u,f=(w)=>(w-d.minX)*p,m=(w)=>(w-d.minY)*p,h=oe((w)=>{let P=s.current;if(!P)return;let L=P.getBoundingClientRect(),N=(w.clientX-L.left)/L.width*aI,Y=(w.clientY-L.top)/L.height*lI,B=sI(t.value,e.value,o,i),J=e.value,X=o/J.scale,V=i/J.scale,ee=N/B.scale+B.bounds.minX,he=Y/B.scale+B.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 P=(N)=>{if(a.current)h(N)},L=()=>{a.current=!1,document.removeEventListener("pointermove",P),document.removeEventListener("pointerup",L)};document.addEventListener("pointermove",P),document.addEventListener("pointerup",L)},[h]),v=st.value,b=kt.value,x=tr.value?Ld.value:new Set,C=To.value,y=C?Fd(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:Od(w,(P)=>l.get(P))})).filter((w)=>w.at!==null),_=-c.x/c.scale,I=-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 P=w.type==="group";return r("span",{class:`minimap-node${P?" 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:`${f(w.position.x)}px`,top:`${m(w.position.y)}px`,width:`${Math.max(P?6:4,w.size.width*p)}px`,height:`${Math.max(P?5:3,w.size.height*p)}px`}},w.id,!1,void 0,this)}),y&&r("span",{class:"minimap-fence",style:{left:`${f(y.x)}px`,top:`${m(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:`${f(w.at.x)-4}px`,top:`${m(w.at.y)-4}px`,"--identity-color":So(w.id)}},w.id,!1,void 0,this)),r("span",{class:"minimap-frame",style:{left:`${f(_)}px`,top:`${m(I)}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 uI(){let e=st.value.size,t=Yd("--selection-bar-height"),n=oe(()=>{let l=Array.from(st.value);if(l.length===0)return;_u(l),$n()},[]),o=oe(()=>{let l=Array.from(st.value);if(l.length===0)return;Ns({title:"Group",childIds:l}),$n()},[]),i=oe(()=>{let l=Array.from(st.value);for(let c=0;c<l.length;c++)for(let u=c+1;u<l.length;u++)yr(l[c],l[u],"relation");$n()},[]),s=oe(()=>{let l=Array.from(st.value);for(let c of l)Xr(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:()=>am("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:()=>am("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:()=>qk(),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:()=>Gk(),children:r(Tr,{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 dp(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 pp(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 DL={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"vetoed"},BL={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"cancelled"},dI=[{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"}],FL=Object.fromEntries(dI.map((e)=>[e.id,e.hint])),HL={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 Pg(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 UL({item:e}){let t=DL[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:BL[e.status]??t},void 0,!1,void 0,this),r("span",{class:"session-item-time",children:Pg(e.updatedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function pI({gate:e,now:t}){let[n,o]=E(null),i=async(l)=>{o(l),await EC(e,l),o(null)},s=e.nodeIds[0],a=dp(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 ",pp(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:Pg(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function fI({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),AC(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 jL(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 mI({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:jL(e)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function hI(){let e=To.value,t=st.value.size,[n,o]=E(!1),i=(s)=>{o(!0),_C(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([...st.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 ZL(e){if(e==="browser")return"you";return en.value.find((n)=>n.sessionId===e||n.source===e)?.label??e}function WL({entry:e}){let t=Wl.value.has(e.id);return r("li",{class:`session-timeline-row tone-${HL[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":So(e.who)},children:ZL(e.who)},void 0,!1,void 0,this),r("span",{class:"session-item-time",children:Pg(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 sg(e),children:[r(km,{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 gI(){let e=Co.value,t=nr();if(!eo.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:()=>eo.value=!1,disabled:e.length>0,children:r(oi,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(hI,{},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(pI,{gate:n,now:t},n.id,!1,void 0,this)),os.value.map((n)=>r(fI,{gate:n},n.id,!1,void 0,this)),ig.value.map((n)=>r(mI,{gate:n},n.id,!1,void 0,this))]},void 0,!0,void 0,this),fa.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 ql(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 yI(){q(()=>()=>{eo.value=!1},[]);let e=mi.value,t=SC.value,n=Co.value,o=os.value,i=ig.value,s=IC.value,[a,l]=E(!1),[c,u]=E(null),d=nr();if(q(()=>{yi()},[]),!(eo.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:()=>{eo.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: ${pi(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:pi(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 ql(e),children:"End"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("button",{type:"button",class:"session-collapse",onClick:()=>{eo.value=!1},"aria-label":"Collapse session panel",children:r(oi,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r(hI,{},void 0,!1,void 0,this),(()=>{let f=s.find((m)=>m.undoable&&!Wl.value.has(m.id));if(!f)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: ",f.body]},void 0,!0,void 0,this),r("button",{type:"button",class:"session-undo-btn",onClick:()=>void sg(f),children:[r(km,{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 f=t.filter((C)=>C.status==="in-progress"||C.status==="todo").length,m=t.filter((C)=>C.status!=="cancelled"),h=m.filter((C)=>C.status==="done").length,g=t.length-m.length,v=n.length>0,b=a||v,x=f>0?`${f} running`:m.length>0?`${h}/${m.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:[f>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(oi,{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(pI,{gate:C,now:d},C.id,!1,void 0,this)),o.map((C)=>r(fI,{gate:C},C.id,!1,void 0,this)),i.map((C)=>r(mI,{gate:C},C.id,!1,void 0,this)),t.map((C)=>r(UL,{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:dI.map((f)=>r("button",{type:"button",class:`activity-filter${rs.value===f.id?" is-active":""}`,"aria-pressed":rs.value===f.id,onMouseEnter:()=>u(f.id),onMouseLeave:()=>u((m)=>m===f.id?null:m),onFocus:()=>u(f.id),onBlur:()=>u((m)=>m===f.id?null:m),onClick:()=>{rs.value=f.id},children:f.label},f.id,!1,void 0,this))},void 0,!1,void 0,this),r("div",{class:"session-timeline-hint","data-testid":"timeline-filter-hint",children:FL[c??rs.value]},void 0,!1,void 0,this),s.length===0?r("div",{class:"session-empty",children:rs.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((f)=>r(WL,{entry:f},f.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 Ng(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 vI=(e)=>e.map((t)=>t.title).join(", ");function bI(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function qL({context:e,label:t,snapshotId:n}){let[o,i]=E(!1),[s,a]=E([]),[l,c]=E(!1),[u,d]=E(null),[p,f]=E(!1),m=e.edited.length>0&&e.edited.every((x)=>s.includes(x.id))?"undone":l?"kept":null;q(()=>{a([]),c(!1),d(null)},[e]);let h=async(x)=>{if(!n||p)return;f(!0);try{let C=await NC(n,x.filter((y)=>!s.includes(y.id)));return a((y)=>[...y,...C.restored]),C}finally{f(!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=Fn.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:gi.warn},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{children:[vI(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";ma(`${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(uo,{},void 0,!1,void 0,this):r("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:r("path",{d:gi[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!==se.value),onClick:()=>Kk(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:m!==null||p||e.edited.some((C)=>C.boardId&&C.boardId!==se.value),onClick:()=>{h(e.edited).then((C)=>{if(C?.ok)c(!0)})},children:m==="undone"?"✓ Undone":m==="kept"?"Kept your edits":"Undo"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x.key==="edited"&&m&&r("div",{class:"session-receipt-context-items",children:m==="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(KL,{node:C,canUndo:n!==null,undoing:p,open:u===or(C),onToggle:()=>d(u===or(C)?null:or(C)),undone:s.includes(C.id),onUndo:()=>void h([C])},or(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("; "):vI(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:()=>Gl(!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 GL(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 KL({node:e,canUndo:t,undoing:n,open:o,onToggle:i,undone:s,onUndo:a}){let l=!e.boardId||e.boardId===se.value,c=l?H.value.get(e.id):void 0,u=Ge.value.find((m)=>m.id===e.boardId),d=Ke(()=>o?GL(e.before??"",e.after??""):[],[o,e.before,e.after]),p=D(null);Me(()=>{for(let m of p.current?.querySelectorAll(".session-receipt-diff-text")??[]){let h=m.querySelector("del, ins");if(h)m.scrollTop=h.getBoundingClientRect().top-m.getBoundingClientRect().top-24}},[d]);let f=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((m,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:m.length?m.map(({text:g,changed:v},b)=>g==="…"&&(b===0||b===m.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||f||n,onClick:a,children:s?"✓ Undone":f?"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":f?"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 xI({onOpenSnapshots:e}){let t=ns.value,[n,o]=E(null),[i,s]=E(!1);if(q(()=>o(null),[t]),!xt.value||!t)return null;let a=t.snapshot?.boardId===se.value,l=Ge.value.find((f)=>f.id===t.snapshot?.boardId),c=async()=>{if(!t.snapshot||!a)return;s(!0);try{let f=await Gt(`/api/canvas/snapshots/${encodeURIComponent(t.snapshot.id)}/diff`,{headers:{"x-pmx-workbench":"1"}});if(f.ok){let m=await f.json();o(Ng(m.diff)??{added:0,removed:0,modified:0})}}finally{s(!1)}},u=bI(t.endedAt),d=t.startedAt?bI(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:Ud,"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(qL,{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 VL=[{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:Ft("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:Ft("0"),desc:"Reset viewport to origin"},{keys:`${Ft("+")} / ${Ft("−")}`,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:wl?"Delete / ⌫":"Delete / Backspace",desc:"Delete the selection (or the focused node)"},{keys:wl?"⌘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 wI({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:VL.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:tt()&&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 kI="Before session · ";function SI(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 fp(e){if(!e.startsWith(kI))return null;let t=e.slice(kI.length),n=t.lastIndexOf(" · ");return n>0?t.slice(0,n):t}function _I({open:e,onClose:t,anchorRef:n}){let[o,i]=E([]),[s,a]=E(!1),[l,c]=E(!1),[u,d]=E(null),[p,f]=E(""),[m,h]=E(null),[g,v]=E({}),b=D(null),x=D(null);q(()=>{if(!e)return;a(!0),xk().then((w)=>{i(w),a(!1)})},[e]),q(()=>{if(e)setTimeout(()=>x.current?.focus(),50)},[e]),q(()=>{if(!e)return;let w=(P)=>{let L=b.current,N=n.current;if(L&&!L.contains(P.target)&&N&&!N.contains(P.target))t()};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[e,t]),q(()=>{if(!e)return;let w=(P)=>{if(P.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 P=await wk(w);if(c(!1),P.ok&&P.snapshot)i((L)=>[P.snapshot,...L]),f("")},[p]),y=oe(async(w)=>{h(null),d(w);let P=await kk(w);if(d(null),P.ok)t()},[t]),k=oe(async(w)=>{if((await Sk(w)).ok)i((L)=>L.filter((N)=>N.id!==w));h(null)},[]),_=oe(async(w)=>{v((L)=>({...L,[w]:"loading"}));let P=await pe("snapshotDiff",`/api/canvas/snapshots/${encodeURIComponent(w)}/diff`,{});v((L)=>({...L,[w]:Ng(P.diff)??{added:0,removed:0,modified:0}}))},[]);if(!e)return null;let I=(w,P)=>m?.id===w.id?r(be,{children:[r("button",{type:"button",class:`snapshot-action-btn ${m.action==="delete"?"snapshot-action-confirm":"snapshot-action-restore"}`,onClick:()=>m.action==="delete"?k(w.id):y(w.id),disabled:u!==null,children:m.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:tt()?"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…":P},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)=>f(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:tt()?"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)=>fp(w.name)===null),...o.some((w)=>fp(w.name)!==null)?[{id:"__sessions-header__"}]:[],...o.filter((w)=>fp(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 P=fp(w.name),L=g[w.id];if(P!==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 — ",P]},void 0,!0,void 0,this),r("span",{class:"snapshot-item-time",children:SI(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":"",L&&L!=="loading"&&r("span",{class:"snapshot-item-diff",children:[" ","· since: ",L.added," added · ",L.removed," removed · ",L.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:L==="loading",onClick:()=>void _(w.id),children:L==="loading"?"Comparing…":"View diff"},void 0,!1,void 0,this),I(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:SI(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":""}`:""," · ",Qd(w.createdAt)]},void 0,!0,void 0,this),r("div",{class:"snapshot-item-actions",children:I(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 XL=8;function CI({fallbackName:e}){let[t,n]=E(!1),o=D(null),i=D(null),s=D(null);Me(()=>{if(!t)return;let p=(m)=>{if(m.target instanceof Node&&!o.current?.contains(m.target)&&!s.current?.contains(m.target))n(!1)},f=(m)=>{if(m.key==="Escape")m.stopPropagation(),n(!1),i.current?.focus()};return document.addEventListener("pointerdown",p,!0),document.addEventListener("keydown",f,!0),()=>{document.removeEventListener("pointerdown",p,!0),document.removeEventListener("keydown",f,!0)}},[t]);let a=Yn(),l=!io.value?e:a&&!ut.value?a.name:"Home",c=Ge.value.filter((p)=>ut.value||p.id!==se.value).slice(0,XL),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(js,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&u&&r(Ws,{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(zu,{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(ho,{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),Ag()},children:[r("span",{class:"board-switcher-icon","aria-hidden":"true",children:r(aS,{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(Tr,{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 TI=3,II={"waiting-approval":0,thinking:1,tooling:2,idle:3};function JL(){let[e,t]=E(null),n=D(null);Me(()=>{if(!e)return;let d=(m)=>{if(!n.current?.contains(m.target)&&!e.button.contains(m.target))t(null)},p=(m)=>{if(m.key==="Escape"&&!m.defaultPrevented)m.preventDefault(),t(null),e.button.focus({preventScroll:!0})},f=()=>t(null);return document.addEventListener("pointerdown",d,!0),document.addEventListener("keydown",p),window.addEventListener("resize",f),()=>{document.removeEventListener("pointerdown",d,!0),document.removeEventListener("keydown",p),window.removeEventListener("resize",f)}},[e]);let o=fa.value;if(q(()=>{if(e&&!e.button.isConnected)t(null)},[o,e]),!xt.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)=>(II[d.phase]??4)-(II[p.phase]??4)),a=s.slice(0,TI),l=s.slice(TI),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((f)=>f.parentAgentId!=null&&(f.parentAgentId===d.sessionId||f.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":So(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:(f)=>{f.stopPropagation(),t(e?.id===d.sessionId?null:{id:d.sessionId,button:f.currentTarget})},children:[Md(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:pi(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(EI,{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:(f)=>{f.stopPropagation(),ql({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(Ws,{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," · ",pi(d)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r(EI,{session:d,popover:!0},void 0,!1,void 0,this),r("button",{type:"button",class:"session-receipt-link",onClick:()=>{eo.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 EI({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=Fn.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:()=>Gl(!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(),Gl(!s,{sessionId:e.sessionId})},children:a},void 0,!1,void 0,this)}function YL(){let e=Co.value.length,t=e>0,n=nr(t?1000:0);if(!t)return null;let o=Co.value.map((i)=>dp(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:()=>eo.value=!0,children:[e," gate",e===1?"":"s",o!==void 0&&` · ${pp(o)}`]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function QL(){let[e,t]=E(!1);if(!xt.value||mi.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),vi().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 AI(){let e=D(null);Me(()=>{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=ao.value,n=cn.value,o=Ee.value,i=H.value.size,s=et.value.size,a=Ds.value,l=Array.from(H.value.values()).filter((g)=>g.type==="trace").length,[c,u]=E("");q(()=>{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=kg.value,p=d??(t==="connected"&&!n?"syncing":t),f=Yn(),m=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();Hs(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(CI,{fallbackName:c||"PMX Canvas"},void 0,!1,void 0,this),f&&!ut.value&&r(ho,{board:f},void 0,!1,void 0,this),r("span",{class:"top-bar-meta hud-collapsible-text",children:xr.value?xr.value.slice(0,12):"…"},void 0,!1,void 0,this),!ut.value&&r("span",{class:"top-bar-meta hud-collapsible-text",children:m},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(JL,{},void 0,!1,void 0,this),r(YL,{},void 0,!1,void 0,this),r(dT,{},void 0,!1,void 0,this),r(YT,{},void 0,!1,void 0,this),!tt()&&r(QL,{},void 0,!1,void 0,this),!ut.value&&r(be,{children:[r("div",{class:"top-bar-sep"},void 0,!1,void 0,this),r("div",{class:"top-bar-actions",children:[se.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:()=>{cs.value=!0},children:"Export"},void 0,!1,void 0,this)},void 0,!1,void 0,this),se.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:()=>{fl()},children:"Present"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r(_e,{label:"Zoom out",shortcut:Ft("−"),children:r("button",{type:"button",class:"top-bar-btn",onClick:()=>ti(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:Ft("0"),children:r("button",{type:"button",class:"top-bar-zoom-label",onClick:()=>_r({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:Ft("+"),children:r("button",{type:"button",class:"top-bar-btn",onClick:()=>ti(1.25),"aria-label":"Zoom in",children:r(pS,{},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(Nu,{},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(eO,{boardOpen:!!se.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 eO({boardOpen:e,onFit:t}){let[n,o]=E(!1),i=D(null),s=D(null);Me(()=>{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(),f=p.indexOf(document.activeElement),m=d.key==="ArrowDown"?f+1:f-1;p[(m+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(()=>{cs.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 fl()),children:"Present board"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>ti(1.25)),children:"Zoom in"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>ti(0.8)),children:"Zoom out"},void 0,!1,void 0,this),r("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:a(()=>_r({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 bi={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 rc(e,t,n,o={}){let i=bi[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 xi=null,sc=null,mp=0,wi=null,tO=3000,nO=2000,oO=1000,rO=80,RI=5000,iO=1e4,ic=!1,$r=null,ka=null,wa=null,us=0,ki=null;function sO(){if(tt())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 Sa=new Map;function ac(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 vp(e){if(!sc)return e;let t=sc.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 lc(e,t,n){return vp(rc(e,t,n))}function aO(){return sd([...H.value.values()],bi.markdown.w,bi.markdown.h)}function Ca(){if(!H.value.has("status-main"))kr(lc("status-main","status",{phase:"idle",message:"",elapsed:0}))}function lO(e,t){let n=`md-${ac(e)}`;if(H.value.get(n))Xe(n,{path:e,title:t}),gt.value=n;else{let i=aO(),s=lc(n,"markdown",{path:e,title:t,content:"",rendered:""});s.position=i,kr(s),$t(n)}}function cO(e){if(H.value.get("context-main"))Xe("context-main",{cards:e});else if(e.length>0){let o=lc("context-main","context",{cards:e});kr(o)}}function uO(e){let t=e.url,n=`mcp-${ac(t)}`;if(H.value.get(n))Xe(n,e);else kr(lc(n,"mcp-app",e)),$t(n)}function dO(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(H.value.get(o)){Xe(o,e);return}let{serverName:s,toolName:a}=e;if(s&&a){for(let[v,b]of H.value.entries())if(b.type==="mcp-app"&&b.data.mode==="ext-app"&&b.data.serverName===s&&b.data.toolName===a&&!b.data.toolResult){Xe(v,{...e});return}}let{_x:l,_y:c,_width:u,_height:d}=e,p=bi["mcp-app"],f=u??p.w,m=d??p.h,h=l===void 0||c===void 0?sd([...H.value.values()],f,m):null,g=vp(rc(o,"mcp-app",{mode:"ext-app",...e},{position:{x:l??h?.x??p.x,y:c??h?.y??p.y},size:{width:f,height:m}}));kr(g),$t(o,{recordHistory:!1})}function pO(e){let t=e.startsWith("ext-app-")?e:`ext-app-${e}`;if(H.value.has(t))return t;let n=`ext-app-${e}`;if(n!==t&&H.value.has(n))return n;for(let[o,i]of H.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&&H.value.has(t))return t;if(typeof e.toolCallId!=="string"||!e.toolCallId)return null;return pO(e.toolCallId)}function $I(e,t){if(typeof e!=="string"||!e)return null;if(typeof t!=="string"||!t)return null;let n=null;for(let[o,i]of H.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 LI(e){if(H.value.get("ledger-main"))Xe("ledger-main",e);else{let o=lc("ledger-main","ledger",e);o.collapsed=!0,kr(o)}}function $g(e){if(!El(e))return;if(document.documentElement.setAttribute("data-theme",e),la(),Qt.value!==e)Qt.value=e}function fO(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 mO(e){return e==="relation"||e==="depends-on"||e==="flow"||e==="references"}function Lg(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 OI(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 hO(e){let t=Lg(e),n=OI(e);return t&&n?{...t,...n}:null}function gO(e){if(typeof e.id!=="string"||!e.id)return null;if(!fO(e.type))return null;let t=Lg(e.position),n=OI(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,...yp(e.createdBy)?{createdBy:e.createdBy}:{},...yp(e.lastEditedBy)?{lastEditedBy:e.lastEditedBy}:{},data:o}}function yp(e){if(!e||typeof e!=="object")return!1;let t=e;return typeof t.actor==="string"&&typeof t.source==="string"}function yO(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(!mO(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}:{},...yp(e.changedBy)?{changedBy:e.changedBy}:{},...typeof e.changedAt==="string"?{changedAt:e.changedAt}:{},...yp(e.createdBy)?{createdBy:e.createdBy}:{},...typeof e.createdAt==="string"?{createdAt:e.createdAt}:{}}}function vO(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)=>Lg(o)).filter((o)=>o!==null),n=hO(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 PI="pmx-canvas-version-reload";function bO(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(PI)===i)return;window.sessionStorage.setItem(PI,i)}catch{return}window.location.reload()}function xO(e){let t=fi.value[0]?.id;if(aC(e),_o.value&&fi.value[0]?.id!==t)yi()}function wO(e){PC(e)}var ds=0,Mg=0,_a=null;function kO(e){Uf(e)}function SO(e){let t=_a;if(_a=null,e){if(t?.boardId===se.value)gp(t);return}let n=se.value,o=++ds;if(sc=null,cn.value=!1,su(),Hk(),pu(),hm({nodes:[],edges:[]}),t?.boardId===se.value)gp(t);if(se.value===null)Ud();if(Fn.value?.kind==="receipt")Fn.value=null;Qh({}),Lo.value=null,Og();let i=Mg,s=$o;mk(n).then((a)=>{if(o===ds&&i===Mg)gp({layout:a,boardId:n})}),pe("fetchPinnedContext","/api/canvas/pinned-context",{}).then((a)=>{if(o===ds&&s===$o)DI({nodeIds:a.nodeIds})})}Tk(SO);function _O(e){if(bo.value++,ds++,_a=null,cn.value=!1,typeof e.catalogEpoch==="string")Ck(e.catalogEpoch);if(!tt()&&typeof e.workbenchToken==="string")window.__PMX_WORKBENCH_TOKEN=e.workbenchToken;if(xr.value=e.sessionId||"",Pf(e.workspaceSettings),ao.value="connected",sl().then(Jr),Zi.value+=1,bO(e.version,e.bundleStamp),jl(),zr(),Qa(),!fu&&!tt())Qw();if(pe("fetchHumanPresence","/api/canvas/human-presence",null).then(Uf),Og().then(()=>{if(_o.value)yi()}),typeof e.theme==="string"&&!Sg())$g(e.theme);if(e.ledgerSummary)LI(e.ledgerSummary)}function CO(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(lO(t,n),e.ledgerSummary)LI(e.ledgerSummary)}function TO(e){Ca(),Xe("status-main",{message:typeof e.message==="string"?e.message:String(e.message??""),level:e.level??"ok",source:e.source})}function IO(e){Ca(),Xe("status-main",{phase:e.phase,detail:e.detail})}function EO(e){let t=e.cards??[];cO(t)}function AO(e){if(typeof e.url==="string"&&e.url)uO({url:e.url,sourceServer:e.sourceServer,sourceTool:e.sourceTool,inferredType:e.inferredType,trustedDomain:e.trustedDomain,hostMode:e.hostMode??"hosted"})}function RO(e){let t=e.sessions??[];for(let n of t){let o=n.url;if(!o)continue;let i=`mcp-${ac(o)}`;if(H.value.has(i))Xe(i,{sessionState:n.state,lastSeenAt:n.lastSeenAt})}}function PO(e){if(typeof e.url==="string"&&e.url){let t=`mcp-${ac(e.url)}`;if(H.value.has(t))Xe(t,{hostMode:"fallback",fallbackReason:e.reasonCode})}}function NO(e){let n=H.value.get("context-main");if(!n)return;let o=(n.data.auxTabs??[]).concat(e);Xe("context-main",{auxTabs:o})}function MO(e){if(H.value.has("context-main"))if(e.mode==="all")Xe("context-main",{auxTabs:[]});else{let o=H.value.get("context-main");if(!o)return;let i=(o.data.auxTabs??[]).filter((s)=>s.id!==e.id);Xe("context-main",{auxTabs:i})}}function zO(e){Ca(),Xe("status-main",{phase:"idle",lastCompletion:{tokenCount:e.tokenCount,artifactCount:e.artifactCount}})}function $O(e){Ca(),Xe("status-main",{phase:"tooling",detail:`${e.name}`,activeTool:e.name})}function LO(e){Ca(),Xe("status-main",{activeTool:null})}function OO(e){if(e.state==="active"&&e.path){let n=`md-${ac(e.path)}`;if(H.value.has(n))Xe(n,{reviewActive:!0})}}function DO(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;dO({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 BO(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=zI(e)??$I(e.serverName,e.toolName);if(!t)return;if(H.value.has(t))Xe(t,{html:e.html})}function FO(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=zI(e)??$I(e.serverName,e.toolName);if(!t)return;if(H.value.has(t)){if(e.success===!1){ei(t);return}Xe(t,{toolResult:jh({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 HO(e){Ca(),Xe("status-main",{subagent:{state:e.state,name:e.agentDisplayName??e.agentName}})}function UO(e){let t=e.nodeId;if(!t)return;let n=e.text||"",{position:o,parentNodeId:i,contextNodeIds:s}=e;if(e.threadNodeId&&H.value.has(e.threadNodeId)){let a=e.threadNodeId,l=H.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"});Xe(a,{turns:c,threadStatus:"pending"});return}if(!H.value.has(t)){let a=o??bi.prompt;kr(vp(rc(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&&H.value.has(i))zs({id:`edge-${i}-${t}`,from:i,to:t,type:"flow",style:"dashed"})}function jO(e){let{nodeId:t,status:n}=e;if(t&&H.value.has(t))Xe(t,{status:n})}function ZO(e){let{responseNodeId:t,promptNodeId:n}=e;if(!t)return;let o=n?H.value.get(n):void 0;if(o&&Array.isArray(o.data.turns)){Sa.set(t,n);let s=[...o.data.turns];s.push({role:"assistant",text:"",status:"streaming"}),Xe(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:bi.response.x,y:bi.response.y};if(!H.value.has(t))kr(vp(rc(t,"response",{content:"",status:"streaming",promptNodeId:n},{position:i})));if(n)zs({id:`edge-${n}-${t}`,from:n,to:t,type:"flow",animated:!0});$t(t)}function WO(e){let t=e.responseNodeId;if(!t)return;let n=Sa.get(t);if(n){let o=H.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";Xe(n,{turns:i,threadStatus:"streaming"})}return}if(!H.value.has(t))return;Xe(t,{content:e.content,status:"streaming"})}function qO(e){let t=e.responseNodeId;if(!t)return;let n=Sa.get(t);if(n){let s=H.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";Xe(n,{turns:a,threadStatus:"answered",_activeResponseId:void 0})}Sa.delete(t);return}if(!H.value.has(t))return;Xe(t,{content:e.content,status:"complete"});let i=H.value.get(t)?.data.promptNodeId;if(i){let s=`edge-${i}-${t}`,a=et.value.get(s);if(a)Vk(s),zs({...a,animated:!1})}}function gp(e){bo.value++;let t=e.layout;if(!t?.nodes)return;if(typeof e.boardGeneration==="number"){if(e.catalogEpoch!==Sn||Mo!==null&&e.boardGeneration<Mo)return;if(Mo===null||e.boardGeneration>Mo){_a=e;return}}if(e.boardId!==void 0&&e.boardId!==se.value){_a=e;return}Mg+=1;let n=!cn.value;cn.value=!0;let o=t.nodes.map(gO).filter((l)=>l!==null),i=Array.isArray(t.edges)?t.edges.map(yO).filter((l)=>l!==null):Array.from(et.value.values()),s=Array.isArray(t.annotations)?t.annotations.map(vO).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)co();hm({...a?{viewport:a}:{},nodes:o,edges:i,...s?{annotations:s}:{}},{applyViewport:n}),nl({event:"canvas-layout-update",data:e}),zr(1000)}function GO(e){if(e<=1)return 500;if(e===2)return 1000;return Math.min(2500,1500+(e-3)*500)}function KO(e){if(vm())return;let t=e.nodeId;if(t&&H.value.has(t)){if(e.noPan===!0){Sr(t);return}$t(t)}}function VO(e){if(vm()||e.clientId===Kr)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;co(),fm({x:n,y:o,scale:i})}function XO(e){if(Oo.value)return;if(!Ln.value&&e.present!==!0)return;let t=Xc.safeParse(e.stop);if(t.success)nS(t.data)}function JO(){if(Oo.value)return;Ln.value=!1,Jo.value=""}function YO(e){if(Oo.value)return;let t=Xc.safeParse(e.stop);if(!t.success)return;try{bm(t.data,Ln.value?void 0:(n)=>{bu(n,{recordHistory:!1})})}catch{let n=Wa.safeParse(e.viewport);if(!n.success)return;co(),fm(n.data)}}function QO(e){if(H.value.get("context-main"))Xe("context-main",{currentTokens:e.currentTokens,tokenLimit:e.tokenLimit,messagesLength:e.messagesLength,utilization:e.utilization,nearLimit:e.nearLimit})}function eD(e){Ds.value=e.enabled===!0}function tD(e){if(typeof e.theme==="string"&&!Sg())$g(e.theme)}function DI(e){bo.value++;let t=Array.isArray(e.nodeIds)?e.nodeIds.filter((n)=>typeof n==="string"):[];if(ji===0)um(t);nl({event:"context-pins-changed",data:e}),jl(),zr()}function nD(){jl(),zr()}var hp=null,zg=0;async function Og(){let e=++zg,t=ds,n=await yk();if(e===zg&&t===ds)Lo.value=n}function NI(){if(hp)clearTimeout(hp);zg+=1,hp=setTimeout(()=>{if(hp=null,Og(),_o.value)yi()},150)}function oD(e){let t=e.intent;if(!t||typeof t.id!=="string"||typeof t.kind!=="string"||typeof t.expiresAt!=="number")return;jw(t)}function rD(e){let t=typeof e.id==="string"?e.id:"";if(!t)return;if(e.settled===!0)Ww(t,typeof e.nodeId==="string"?e.nodeId:void 0);else Ff(t)}var BI={connected:_O,"workbench-open":CO,"canvas-status":TO,"execution-phase":IO,"context-cards":EO,"mcp-app-candidate":AO,"mcp-app-host-snapshot":RO,"mcp-app-host-fallback":PO,"aux-open":NO,"aux-close":MO,"assistant-complete":zO,"tool-start":$O,"tool-complete":LO,"review-state":OO,"subagent-status":HO,"ext-app-open":DO,"ext-app-update":BO,"ext-app-result":FO,"context-pins-changed":DI,"context-status-changed":nD,"knowledge-changed":()=>void Kt(),"lifecycle-changed":()=>void Kt(),"boards-changed":(e)=>{Qr(e),zr()},"canvas-layout-update":gp,"canvas-focus-node":KO,"canvas-viewport-update":VO,"canvas-tour-step":XO,"canvas-tour-exit":JO,"canvas-camera-move":YO,"context-usage":QO,"trace-state":eD,"theme-changed":tD,"settings-changed":(e)=>Pf(e.workspaceSettings),"canvas-prompt-created":UO,"canvas-prompt-status":jO,"canvas-response-start":ZO,"canvas-response-delta":WO,"canvas-response-complete":qO,"ax-state-changed":NI,"ax-event-created":NI,"ax-intent":oD,"ax-intent-clear":rD,"agent-presence":xO,"human-presence":kO,"agent-session-ended":wO};function FI(e,t){let n=BI[e];if(!n)return;let o=n;try{o(t)}catch(i){console.warn(`[sse-bridge] Handler for "${e}" failed:`,i)}}function MI(){ic=!0,us+=1;let e=us;ka?.abort();let t=new AbortController;ka=t;let n=!tt();ao.value="connecting";let o=null,i=!1,s=async()=>{if(e!==us)return;let a=new AbortController,l;try{let c=new URLSearchParams;if(wa!==null){if(c.set("since",String(wa)),n)c.set("waitMs",String(oO))}let u=xr.value;if(u)c.set("session",u);let d=c.toString(),p=$o,f=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"))},iO)})]);if(e!==us)return;if(!f.ok)throw Error("poll returned ok: false");let m=o;if(o=f.sessionId??null,m!==null&&f.sessionId&&m!==f.sessionId&&!f.snapshot){wa=null,$r=setTimeout(()=>void s(),0);return}if(f.snapshot&&i)sc=ym(),cn.value=!1,pu(),su(),Sa.clear();let h=p===$o&&ji===0,g=!1,v=new Set;if(!f.snapshot&&cn.value){let b;for(let x of f.events){let C=x.payload,y=C.catalogEpoch===Sn&&C.boardGeneration===Mo&&(x.event==="boards-changed"?C.activeBoardId:C.boardId)===se.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 f.events){if(v.has(b))continue;if(b.event==="context-pins-changed"&&!h){g=!0;continue}FI(b.event,b.payload)}if(g)dm(),jl(),zr();i=!0,wa=f.seq,Wi.value=0,qi.value=0,ao.value="connected",$r=setTimeout(()=>void s(),n?rO:nO)}catch(c){if(e!==us)return;console.warn("[sse-bridge] poll transport error:",c),ao.value="disconnected",Wi.value+=1,qi.value=RI,$r=setTimeout(()=>void s(),RI)}finally{clearTimeout(l)}};return s(),()=>{if(Qa(),us+=1,ic=!1,wa=null,t.abort(),ka===t)ka=null;if($r)clearTimeout($r),$r=null}}function Dg(){if(ds++,_a=null,hT($g),sc=ym(),cn.value=!1,pu(),su(),Sa.clear(),wi)clearTimeout(wi),wi=null;let e=sO();if(e==="poll"||ic)return MI();let t=xr.value,n=t?`/api/workbench/events?session=${t}`:"/api/workbench/events";ao.value="connecting";let o=new EventSource(n);xi=o;let i=!1;if(ki)clearTimeout(ki);if(ki=null,e!=="sse")ki=setTimeout(()=>{if(ki=null,i||xi!==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(),xi=null,MI()},tO);for(let[s]of Object.entries(BI))o.addEventListener(s,(a)=>{if(xi!==o)return;i=!0;try{FI(s,JSON.parse(a.data))}catch(l){console.warn(`[sse-bridge] Failed to parse "${s}" event:`,l)}});return o.onopen=()=>{if(xi!==o)return;mp=0,Wi.value=0,qi.value=0,ao.value="connected"},o.onerror=()=>{if(xi!==o)return;ao.value="disconnected",o.close(),xi=null,mp+=1;let s=GO(mp);Wi.value=mp,qi.value=s,wi=setTimeout(()=>{wi=null,Dg()},s)},()=>{if(Qa(),wi)clearTimeout(wi),wi=null;if(ki)clearTimeout(ki),ki=null;if(ic){if(us+=1,ic=!1,wa=null,ka?.abort(),ka=null,$r)clearTimeout($r),$r=null}o.close(),xi=null}}function ps(e,t){console.error(`[app] ${e} failed`,t)}var iD=Ve(()=>H.value.size===0),HI=Ve(()=>{let e=Ct.value;return!!e&&!ut.value&&se.value===e.boardId&&wt===e.incarnation&&H.value.has(e.nodeId)}),Bg=Ve(()=>Oe.value&&HI.value);function UI(){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),[f,m]=E(null),h=D(null),g=D(null),[v,b]=E(Jt),{menu:x,openNodeMenu:C,openCanvasMenu:y,openEdgeMenu:k,closeMenu:_}=bT(),I=cn.value,w=io.value&&(se.value===null||ut.value),P=tr.value,L=xt.value,N=_o.value||Co.value.length>0||os.value.length>0||!!To.value,Y=Bg.value;Me(()=>{if(!L){if(Fn.value=null,eo.value=!1,document.activeElement?.closest(".command-bar, .session-panel, .agent-popover"))h.current?.focus({preventScroll:!0})}},[L]);let B=oe(()=>t((A)=>!A),[]),J=oe(()=>o((A)=>!A),[]),X=oe(()=>o(!1),[]),V=oe((A)=>m(A),[]),ee=oe((A)=>{Rw(A),g.current=A},[]),he=oe((A,te)=>{_r({x:A,y:te,scale:Ee.value.scale},200)},[]);return q(()=>Dg(),[]),q(()=>{let A=(te)=>{let M=te.detail;u(M??{}),l(!0)};return window.addEventListener("pmx-open-board-link",A),()=>window.removeEventListener("pmx-open-board-link",A)},[]),q(()=>{let A=null,te=()=>{if(A!==null)window.clearTimeout(A);A=window.setTimeout(()=>{A=null,Jr()},400)};return window.addEventListener("resize",te),()=>{if(A!==null)window.clearTimeout(A);window.removeEventListener("resize",te)}},[]),Me(()=>{let A=(O)=>{let Pe=(O.metaKey||O.ctrlKey)&&!O.altKey;if(d&&(O.key==="Escape"||O.key==="?"||O.key==="/"&&O.shiftKey)){O.preventDefault(),p(!1);return}if(ut.value||se.value===null)return;if(O.defaultPrevented)return;if(Pe&&O.key==="k"){O.preventDefault(),s((ve)=>!ve);return}if(O.key==="Escape"&&f){O.preventDefault(),m(null);return}if(O.key==="Escape"&&Bg.value){if(O.target?.closest('[role="menu"], [role="alertdialog"]'))return;O.preventDefault(),Ct.value=null;return}if(O.key==="Escape"&&Bt.value&&!zo.value){O.preventDefault(),Cr();return}if(O.key==="Escape"&&i){O.preventDefault(),s(!1);return}let Fe=O.target,De=Fe?.tagName;if(De==="INPUT"||De==="TEXTAREA"||Fe?.isContentEditable)return;if(Fe?.closest('[role="menu"]'))return;let Ae=Fe?.closest('[role="dialog"]');if((O.key==="Tab"||O.key.startsWith("Arrow"))&&Fe?.closest(".tool-rail, .top-bar"))return;if(O.key===" "&&!O.repeat&&!Pe&&!Ae){O.preventDefault(),dl.value=!0;return}if(O.key==="?"||O.key==="/"&&O.shiftKey){O.preventDefault(),p((ve)=>!ve);return}if(Pe&&(O.key==="z"||O.key==="Z"))O.preventDefault(),ag(O.shiftKey);else if(Pe&&(O.key==="y"||O.key==="Y"))O.preventDefault(),ag(!0);else if(Pe&&O.key==="0")O.preventDefault(),_r({x:0,y:0,scale:1},250);else if(Pe&&(O.key==="="||O.key==="+"))O.preventDefault(),ti(1.25);else if(Pe&&O.key==="-")O.preventDefault(),ti(0.8);else if(Ae)return;else if(O.key==="Escape"){if(!ir(O))return;if(O.preventDefault(),Io.value?.boardId===se.value)Io.value=null;Ro.value="All",$n(),gt.value=null,_()}else if(O.key==="Tab")O.preventDefault(),Qk(O.shiftKey?-1:1);else if(O.key==="Delete"||O.key==="Backspace"){if(br.value!==null){let z=br.value;O.preventDefault(),br.value=null,wu(z).catch((re)=>ps("delete-edge",re));return}let ve=st.value.size>0?[...st.value]:gt.value?[gt.value]:[];if(ve.length===0)return;O.preventDefault();for(let z of ve)Xr(z).catch((re)=>ps("delete",re));$n(),gt.value=null}else if(gt.value&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(O.key)){O.preventDefault();let ve=O.key.replace("Arrow","").toLowerCase();eS(ve)}else if(!Pe&&!O.altKey){let ve=O.key.toLowerCase();if(ve==="v"&&!O.shiftKey)Wn.value="select";else if(ve==="c"&&!O.shiftKey&&!Pe)O.preventDefault(),Wn.value=Wn.value==="connect"?"select":"connect";else if(ve==="m"&&!O.shiftKey)O.preventDefault(),Eo({type:"markdown",title:"New note",width:520,height:360}).catch((z)=>ps("create markdown",z));else if(ve==="a"&&!O.shiftKey)O.preventDefault(),m((z)=>z==="pen"?null:"pen");else if(ve==="g"&&!O.shiftKey){O.preventDefault();let z=Array.from(st.value);if(z.length>=2)Ns({title:"Group",childIds:z}).catch((re)=>ps("group selection",re)),$n();else Eo({type:"group",title:"Group"}).catch((re)=>ps("create group",re))}else if(ve==="g"&&O.shiftKey){O.preventDefault();for(let z of Wk())ei(z),Ms(z).catch((re)=>ps("ungroup",re));$n()}else if(ve==="i"&&!O.shiftKey)O.preventDefault(),as("image");else if(ve==="w"&&!O.shiftKey)O.preventDefault(),as("webpage");else if(ve==="h"&&!O.shiftKey)O.preventDefault(),Eo({type:"html",title:"HTML surface"}).catch((z)=>ps("create html",z));else if(ve==="f"&&O.shiftKey)O.preventDefault(),as("file");else if(ve==="f"&&!O.shiftKey){O.preventDefault();let z=Jt();Hs(z.width,z.height)}}},te=(O)=>{if(O.key===" ")dl.value=!1},M=()=>{dl.value=!1};return document.addEventListener("keydown",A),document.addEventListener("keyup",te),window.addEventListener("blur",M),()=>{document.removeEventListener("keydown",A),document.removeEventListener("keyup",te),window.removeEventListener("blur",M)}},[f,_,i,d]),q(()=>{let A=window.setTimeout(()=>void Jr(),250);return()=>window.clearTimeout(A)},[P]),Me(()=>{let A=g.current;if(!A)return;let te=new ResizeObserver(()=>{b(Jt()),Jr();let M=Ct.value;if(M&&Bg.value)$t(M.nodeId,{recordHistory:!1})});return te.observe(A),()=>te.disconnect()},[]),q(()=>{if(!I)return;let A=window.__pmxCanvasBootstrapReady;if(typeof A==="function")A()},[I]),r("div",{class:`app-shell${Ln.value?" is-presenting":""}`,"data-session-active":P?"true":"false",children:[r(iS,{},void 0,!1,void 0,this),r(tT,{},void 0,!1,void 0,this),r(ST,{minimapVisible:e,onToggleMinimap:B,snapshotOpen:n,onToggleSnapshot:J,snapshotBtnRef:h,onOpenPalette:()=>s(!0),onOpenShortcuts:()=>p((A)=>!A),annotationTool:f,onSetAnnotationTool:V},void 0,!1,void 0,this),r("div",{class:"app-main",children:[r(AI,{},void 0,!1,void 0,this),r(pT,{},void 0,!1,void 0,this),r("div",{class:`workspace${Y?" is-reviewing":""}`,children:[r("div",{class:"canvas-region",ref:ee,children:[!ut.value&&r(sT,{onNodeContextMenu:C,onCanvasContextMenu:y,onEdgeContextMenu:k,annotationMode:f!==null,annotationTool:f},void 0,!1,void 0,this),r(kS,{},void 0,!1,void 0,this),r($C,{},void 0,!1,void 0,this),!w&&r(LC,{},void 0,!1,void 0,this),!w&&r(QC,{},void 0,!1,void 0,this),r(wS,{},void 0,!1,void 0,this),r(QT,{},void 0,!1,void 0,this),r(eI,{},void 0,!1,void 0,this),w?r(XT,{},void 0,!1,void 0,this):I&&iD.value&&qt.value.size===0&&r(_T,{onOpenPalette:()=>s(!0)},void 0,!1,void 0,this),!w&&st.value.size>0&&r(uI,{},void 0,!1,void 0,this),!w&&!L&&r(uT,{},void 0,!1,void 0,this),!w&&_o.value&&!tt()&&r(aT,{},void 0,!1,void 0,this),!w&&r(xI,{onOpenSnapshots:()=>o(!0)},void 0,!1,void 0,this),r(_S,{},void 0,!1,void 0,this),!ut.value&&r(JT,{},void 0,!1,void 0,this),!w&&Bt.value&&r(iI,{},void 0,!1,void 0,this),r(_I,{open:n&&!ut.value,onClose:X,anchorRef:h},void 0,!1,void 0,this),e&&!w&&r(cI,{viewport:Ee,nodes:H,edges:et,onNavigate:he,containerWidth:v.width,containerHeight:v.height},void 0,!1,void 0,this)]},void 0,!0,void 0,this),HI.value&&r(vT,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),P&&r(yI,{},void 0,!1,void 0,this),!P&&N&&r(gI,{},void 0,!1,void 0,this),!ut.value&&x&&r(xT,{menu:x,onClose:_},void 0,!1,void 0,this),!ut.value&&i&&r(gT,{onClose:()=>s(!1),onToggleMinimap:B},void 0,!1,void 0,this),!ut.value&&a&&r(yT,{...c,onClose:()=>l(!1)},void 0,!1,void 0,this),d&&r(wI,{onClose:()=>p(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}PS();var jI=document.getElementById("app");if(jI)Ra(r(UI,{},void 0,!1,void 0,this),jI);