🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@illodev/workfile

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@illodev/workfile - npm Package Compare versions

Comparing version
0.8.0
to
0.8.1
+1
dist/ui/static/Boards-DBZ9bjm8.js
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{Et as r,Tt as i,pt as a}from"./ui-primitives-DRENhlck.js";import{i as o,n as s,o as c,s as l,u}from"./theme-CcOVK72d.js";import{A as d,D as f,H as p,I as m,L as h,M as g,V as _,et as v,j as y,k as b,n as x,nt as S,r as C,t as w,w as T}from"./index-BcEUSS3r.js";var E=e(t(),1),D=n(),O=[];function k(e,t){let[n,r]=(0,E.useState)(t);(0,E.useEffect)(()=>{r(t)},[e.length,t]);let i=(0,E.useCallback)(()=>r(n=>Math.min(n+t,e.length)),[e.length,t]);return[n>=e.length?e:e.slice(0,n),n<e.length,i]}function A({onVisible:e,remaining:t}){let n=(0,E.useRef)(null);return(0,E.useEffect)(()=>{let t=n.current;if(!t)return;let r=new IntersectionObserver(t=>{t.some(e=>e.isIntersecting)&&e()},{rootMargin:`600px 0px`});return r.observe(t),()=>r.disconnect()},[e,t]),(0,D.jsxs)(`span`,{ref:n,className:`px-0.5 py-1 font-mono text-[11px] text-muted-foreground`,children:[`+`,t,` more`]})}function j({task:e,epicId:t,onOpen:n,onDragStart:r,onCarry:i,carrying:a}){let o=e.claimed_at?Date.parse(e.claimed_at.includes(`T`)?e.claimed_at:`${e.claimed_at}T00:00:00`):NaN,l=Number.isNaN(o)?null:Math.max(0,Math.floor((Date.now()-o)/864e5)),d=[t&&t!==e.id?`epic ${t}`:``,e.effort?`effort ${e.effort}`:``,e.claimed_by?`claimed by ${e.claimed_by}${l==null?``:` · ${l}d`}`:``].filter(Boolean);return(0,D.jsxs)(`article`,{className:u(`flex cursor-pointer flex-col gap-1.5 rounded-lg border bg-background px-3 py-2.5 shadow-xs outline-none transition-[color,border-color,box-shadow] hover:border-ring focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,a&&`border-ring ring-2 ring-ring`),tabIndex:0,draggable:!!r,"aria-grabbed":i?!!a:void 0,title:d.length?d.join(` · `):void 0,onClick:()=>n(e.id),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),n(e.id)):t.key===` `&&i?(t.preventDefault(),i()):t.key===` `&&(t.preventDefault(),n(e.id))},onDragStart:r,children:[(0,D.jsxs)(`span`,{className:`flex items-center`,children:[(0,D.jsx)(`span`,{className:`font-mono text-[11px] text-foreground/70`,children:e.id}),(0,D.jsx)(`span`,{className:`flex-1`}),(0,D.jsx)(`span`,{className:`font-mono text-[10px] font-medium`,style:{color:s(e.priority)},children:e.priority})]}),(0,D.jsx)(`span`,{className:`text-[12.5px] leading-snug font-medium`,role:`heading`,"aria-level":3,children:e.title}),(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 font-mono text-[10px] text-muted-foreground`,children:[(0,D.jsx)(`span`,{children:e.area}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsx)(`span`,{children:e.type}),e.claimed_by?(0,D.jsxs)(`span`,{className:`ml-auto inline-flex min-w-0 items-center gap-[5px]`,style:{color:c(`doing`)},children:[(0,D.jsx)(`span`,{className:`size-[5px] flex-none rounded-full bg-current`,"aria-hidden":`true`}),(0,D.jsx)(`span`,{className:`max-w-[90px] truncate`,children:e.claimed_by})]}):null]}),Array.isArray(e.scope)&&e.scope.length?(0,D.jsxs)(`span`,{className:`mt-0.5 truncate border-t border-dashed pt-1.5 font-mono text-[10.5px] text-muted-foreground`,children:[`scope `,e.scope.join(` · `)]}):null]})}function M({status:e,cards:t,epicIds:n,collapsed:o,onToggleCollapsed:s,onOpen:m,onMove:h,onCarry:v,carryingId:x,isDropTarget:C,onDragEnterColumn:w,onDragLeaveColumn:E}){let O=T(),[M,N,P]=k(t,25),F=c(e),I={onDragOver:t=>{t.preventDefault(),t.dataTransfer.dropEffect=`move`,w?.(e)},onDragLeave:t=>{t.currentTarget.contains(t.relatedTarget)||E?.(e)},onDrop:t=>{t.preventDefault(),E?.(e);let n=t.dataTransfer.getData(`text/plain`);n&&h(n,e).catch(()=>void 0)}};return o?(0,D.jsxs)(p,{role:`region`,"aria-label":`${e}, ${t.length} cards, collapsed`,className:u(`relative w-11 flex-none gap-0 overflow-hidden rounded-lg py-0 shadow-xs`,C&&`border-primary`),...I,children:[(0,D.jsx)(_,{edge:`top`,color:F}),(0,D.jsxs)(`button`,{type:`button`,"aria-expanded":!1,"aria-label":`Expand the ${e} column`,title:`${e} · ${t.length}`,className:u(`flex h-full w-full cursor-pointer flex-col items-center gap-2.5 px-1 pt-4 pb-3 transition-colors hover:bg-accent/50`,C&&`bg-accent/50`),onClick:s,children:[(0,D.jsx)(r,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-muted-foreground`}),(0,D.jsx)(`span`,{className:`min-h-0 flex-1 truncate font-mono text-[11px] uppercase tracking-[0.06em] [writing-mode:vertical-rl]`,style:{color:F},children:e}),(0,D.jsx)(S,{variant:`secondary`,className:`h-5 shrink-0 rounded-md px-[7px] font-mono text-[11px] font-normal`,children:t.length})]})]}):(0,D.jsxs)(p,{role:`region`,"aria-label":`${e}, ${t.length} cards`,className:u(`relative w-[268px] flex-none gap-0 overflow-hidden rounded-lg py-0 shadow-xs`,C&&`border-primary`),...I,children:[(0,D.jsx)(_,{edge:`top`,color:F}),(0,D.jsxs)(`header`,{className:`flex flex-none items-center gap-2 px-3 pb-2.5 pt-4`,children:[(0,D.jsx)(`span`,{className:`flex-1 font-mono text-[11px] uppercase tracking-[0.06em]`,style:{color:F},children:e}),(0,D.jsx)(S,{variant:`secondary`,className:`h-5 rounded-md px-[7px] font-mono text-[11px] font-normal`,children:t.length}),s?(0,D.jsx)(l,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-expanded":!0,"aria-label":`Collapse the ${e} column`,title:`Collapse column`,className:`-mr-1 text-muted-foreground`,onClick:s,children:(0,D.jsx)(i,{"aria-hidden":`true`})}):null]}),(0,D.jsxs)(`div`,{className:u(`scroll-fade flex flex-1 flex-col gap-2 overflow-y-auto p-2.5`,C&&`bg-accent/50`),children:[t.length===0?(0,D.jsx)(f,{className:`flex-1 gap-2 rounded-lg border border-dashed p-4`,children:(0,D.jsxs)(d,{className:`gap-1`,children:[(0,D.jsx)(y,{variant:`icon`,className:`mb-0 size-8 [&_svg:not([class*='size-'])]:size-4`,children:(0,D.jsx)(a,{"aria-hidden":`true`})}),(0,D.jsx)(g,{className:`text-[12.5px] font-medium`,children:`No cards`}),(0,D.jsx)(b,{className:`text-[11.5px]`,children:`Nothing in this state.`})]})}):M.map(e=>(0,D.jsx)(j,{task:e,epicId:n.get(e.id),onOpen:m,onCarry:v&&!O?()=>v(e):void 0,carrying:x===e.id,onDragStart:O?void 0:t=>{t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,e.id)}},e.id)),N&&(0,D.jsx)(A,{onVisible:P,remaining:t.length-M.length})]})]})}function N({tasks:e,epicIds:t,showClosed:n,onOpen:r,onMove:i}){let[a,o]=(0,E.useState)(null),[s,c]=(0,E.useState)(null),[l,u]=(0,E.useState)(``),[d,f]=(0,E.useState)(()=>{try{let e=localStorage.getItem(`workfile-flow-collapsed`);return new Set(e?JSON.parse(e):[])}catch{return new Set}}),p=(0,E.useCallback)(e=>{f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),localStorage.setItem(`workfile-flow-collapsed`,JSON.stringify([...n])),n})},[]),m=(0,E.useMemo)(()=>[`backlog`,`next`,`doing`,`review`,`blocked`,`deferred`,...n?[`done`,`discarded`]:[]],[n]),h=(0,E.useMemo)(()=>{let t=new Map;for(let n of e){let e=t.get(n.status);e?e.push(n):t.set(n.status,[n])}return t},[e]),g=e=>{o({id:e.id,status:e.status}),u(`${e.id} picked up from ${e.status}. Use the arrow keys to choose a column, space to drop, escape to cancel.`)},_=e=>{if(!a)return;let t=m.indexOf(a.status),n=m[Math.min(m.length-1,Math.max(0,t+e))];!n||n===a.status||(o({...a,status:n}),u(`${a.id} over ${n}.`))},v=async()=>{if(!a)return;let t=a;o(null);let n=e.find(e=>e.id===t.id);n&&n.status!==t.status?(await i(t.id,t.status),u(`${t.id} moved to ${t.status}.`)):u(`${t.id} put back.`)};return(0,D.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-3 overflow-x-auto p-3.5`,onDragEnd:()=>c(null),onKeyDown:e=>{a&&(e.key===`Escape`?(e.preventDefault(),o(null),u(`Move cancelled.`)):e.key===`ArrowRight`?(e.preventDefault(),_(1)):e.key===`ArrowLeft`?(e.preventDefault(),_(-1)):(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),v()))},children:[(0,D.jsx)(`p`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:l}),m.map(e=>(0,D.jsx)(M,{status:e,cards:h.get(e)??O,epicIds:t,collapsed:d.has(e),onToggleCollapsed:()=>p(e),onOpen:r,onMove:i,onCarry:g,carryingId:a?.id??null,isDropTarget:a?.status===e||s===e,onDragEnterColumn:c,onDragLeaveColumn:e=>c(t=>t===e?null:t)},e))]})}function P({tasks:e,allTasks:t,epicIds:n,onOpen:r}){let i=(0,E.useMemo)(()=>new Map(t.map(e=>[e.id,e])),[t]),a=(0,E.useMemo)(()=>{let t=new Map;for(let r of e){let e=n.get(r.id)||(r.type===`epic`?r.id:`__none`);t.has(e)||t.set(e,[]),r.id!==e&&t.get(e)?.push(r)}return[...t].sort(([e],[t])=>e===`__none`?1:t===`__none`?-1:e.localeCompare(t,void 0,{numeric:!0}))},[n,e]);return a.length?(0,D.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3.5`,children:(0,D.jsx)(`div`,{className:`flex flex-col gap-2.5`,children:a.map(([e,t])=>{let n=i.get(e),a=t.length,o=t.filter(e=>e.status===`done`||e.status===`discarded`).length,s=t.filter(e=>e.status===`doing`).length,l=a-o-s,d=e=>a?`${e/a*100}%`:`0%`,f=[{label:`${o} done`,color:c(`done`)},{label:`${s} doing`,color:c(`doing`)},{label:`${l} open`,color:null}],m=(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,D.jsx)(`span`,{className:`font-mono text-[11.5px] text-foreground/70`,children:e===`__none`?`—`:e}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 text-sm font-semibold tracking-[-0.01em] text-pretty`,children:n?.title||`Without epic`}),n?(0,D.jsx)(`span`,{className:`font-mono text-[11px]`,style:{color:c(n.status)},children:n.status}):null,(0,D.jsxs)(`span`,{className:`font-mono text-[11.5px] text-muted-foreground`,children:[o,`/`,a]})]}),(0,D.jsx)(`span`,{className:`flex h-2 w-full overflow-hidden rounded-full bg-muted`,"aria-hidden":`true`,children:a>0?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{className:`h-full`,style:{width:d(o),background:c(`done`)}}),(0,D.jsx)(`span`,{className:`h-full`,style:{width:d(s),background:c(`doing`)}})]}):null}),(0,D.jsxs)(`span`,{className:`flex flex-wrap items-center gap-3.5 font-mono text-[10.5px] text-muted-foreground`,children:[f.map(e=>(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-[5px]`,children:[(0,D.jsx)(`span`,{className:u(`size-1.5 rounded-[2px]`,!e.color&&`bg-muted-foreground`),style:e.color?{background:e.color}:void 0,"aria-hidden":`true`}),e.label]},e.label)),(0,D.jsx)(`span`,{className:`ml-auto`,children:n?.area??``})]})]});return n?(0,D.jsx)(`button`,{type:`button`,className:`flex w-full cursor-pointer flex-col gap-2.5 rounded-xl border bg-card px-4 py-3.5 text-left text-card-foreground shadow-xs outline-none transition-[color,border-color,box-shadow] hover:border-ring focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,onClick:()=>r(e),children:m},e):(0,D.jsx)(p,{className:`gap-2.5 rounded-xl px-4 py-3.5 shadow-xs`,children:m},e)})})}):(0,D.jsx)(f,{className:`flex-1 p-6`,children:(0,D.jsxs)(d,{children:[(0,D.jsx)(g,{className:`text-sm`,children:`No epics`}),(0,D.jsx)(b,{className:`text-[11.5px]`,children:`No cards match the current filters.`})]})})}var F=300,I=30;function L({task:e,span:t,mode:n,epicId:r,pct:i,labelWidth:a,onOpen:o}){let s=c(e.status);return(0,D.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),title:`${C(e,n,t)} · ${e.status}${r&&r!==e.id?` · epic ${r}`:``}`,className:`flex w-full cursor-pointer items-center border-b bg-transparent p-0 text-left transition-colors hover:bg-muted`,children:[(0,D.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 border-r px-3.5`,style:{width:a,flex:`0 0 ${a}px`,height:`var(--row-h)`},children:[(0,D.jsx)(`span`,{className:`flex-none whitespace-nowrap font-mono text-[11px] text-foreground/70`,children:e.id}),(0,D.jsx)(`span`,{className:`min-w-0 truncate text-[12.5px]`,children:e.title})]}),(0,D.jsx)(`span`,{className:`relative block flex-1`,style:{height:`var(--row-h)`},children:t.point?(0,D.jsx)(`span`,{style:{position:`absolute`,top:`50%`,width:9,height:9,transform:`translate(-50%, -50%) rotate(45deg)`,borderRadius:2,background:s,display:`block`,left:`${i(t.from)}%`}}):(0,D.jsx)(`span`,{style:{position:`absolute`,top:`50%`,transform:`translateY(-50%)`,height:12,minWidth:6,borderRadius:3,background:s,display:`block`,left:`${i(t.from)}%`,width:`${Math.max(i(t.to)-i(t.from),.8)}%`}})})]})}function R({tasks:e,epicIds:t,axes:n={},mode:r,counts:i,onModeChange:a,onOpen:s}){let c=v()?168:F,u=c+460,[p,_]=(0,E.useState)(()=>{try{return localStorage.getItem(`workfile-timeline-group`)||`none`}catch{return`none`}}),y=(0,E.useCallback)(e=>{_(e);try{localStorage.setItem(`workfile-timeline-group`,e)}catch{}},[]),S=(0,E.useMemo)(()=>[`none`,`epic`,`area`,...Object.keys(n)],[n]),C=S.includes(p)?p:`none`,T=(0,E.useCallback)(e=>{if(C===`epic`)return t.get(e.id)||``;if(C===`area`)return e.area||``;let n=e[C];return typeof n==`string`?n:``},[t,C]),O=(0,E.useMemo)(()=>{let t=new Map;for(let n of e){let e=x(n,r);e&&t.set(n.id,e)}return t},[r,e]),k=(0,E.useMemo)(()=>{let t=(e,t)=>O.get(e.id).from-O.get(t.id).from||e.id.localeCompare(t.id),n=e.filter(e=>O.has(e.id)).sort(t);return C===`none`?n:[...n].sort((e,n)=>{let r=T(e),i=T(n);return!r==!i?r.localeCompare(i)||t(e,n):r?-1:1})},[T,C,O,e]),A=(0,E.useMemo)(()=>{if(C===`none`)return k.map(e=>({task:e,label:null}));let e=[],t=null;for(let n of k){let r=T(n);r!==t&&(t=r,e.push({task:null,label:r||`no ${C}`})),e.push({task:n,label:null})}return e},[T,C,k]),j=(0,E.useMemo)(()=>new Map(A.flatMap((e,t)=>e.task?[[e.task.id,t]]:[])),[A]),M=(0,E.useMemo)(()=>{let e=[];for(let t of k)for(let n of t.depends||[])j.has(n)&&e.push({from:n,to:t.id});return e},[j,k]),N=(0,E.useMemo)(()=>w(k.map(e=>O.get(e.id)),Date.now()),[k,O]),P=i[r===`plan`?`actual`:`plan`];return!k.length||!N?(0,D.jsx)(f,{className:`flex-1 p-6`,children:(0,D.jsxs)(d,{children:[(0,D.jsx)(g,{className:`text-sm`,children:r===`plan`?`Nothing scheduled`:`Nothing recorded`}),(0,D.jsx)(b,{className:`text-[11.5px]`,children:r===`plan`?`Add a start or due date to a card.`:`Cards record a trail as they are claimed and moved.`}),P>0?(0,D.jsx)(b,{className:`text-[11.5px]`,children:(0,D.jsx)(l,{variant:`outline`,size:`sm`,className:`mt-2 text-[12.5px] font-medium`,onClick:()=>a(r===`plan`?`actual`:`plan`),children:r===`plan`?`show what actually happened · ${P} cards`:`show the schedule · ${P} cards`})}):null]})}):(0,D.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,D.jsxs)(m,{gutter:`3.5`,className:`shrink-0 border-b bg-card py-2`,children:[(0,D.jsxs)(`span`,{className:`shrink-0 font-mono text-[11px] whitespace-nowrap text-muted-foreground`,children:[k.length,` `,r===`actual`?`recorded`:`scheduled`,` ·`,` `,M.length,` dependenc`,M.length===1?`y`:`ies`]}),(0,D.jsxs)(`span`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[(0,D.jsx)(h,{label:`dates`,value:r,allLabel:null,align:`end`,options:[{value:`plan`},{value:`actual`}],onChange:e=>a(e)}),(0,D.jsx)(h,{label:`group`,value:C,allLabel:null,align:`end`,options:S.map(e=>({value:e})),onChange:y})]})]}),(0,D.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,D.jsxs)(`div`,{className:`relative min-h-full`,style:{minWidth:u},children:[(0,D.jsxs)(`div`,{"aria-hidden":`true`,className:`sticky top-0 z-[2] flex items-stretch border-b bg-card`,style:{height:I},children:[(0,D.jsx)(`span`,{className:`flex items-center border-r px-3.5 text-[10px] uppercase tracking-[0.08em] text-muted-foreground`,style:{width:c,flex:`0 0 ${c}px`},children:`card`}),(0,D.jsx)(`span`,{className:`relative flex-1`,children:N.ticks.map((e,t)=>(0,D.jsx)(`span`,{className:`text-[10px] uppercase tracking-[0.08em] text-muted-foreground`,style:{position:`absolute`,top:`50%`,transform:`translateY(-50%)`,left:`${e.left}%`,width:`${(N.ticks[t+1]?.left??100)-e.left}%`,overflow:`hidden`,paddingLeft:8,whiteSpace:`nowrap`},children:e.label},e.key))})]}),(0,D.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute`,style:{top:I,bottom:0,left:c,right:0},children:[N.ticks.map(e=>(0,D.jsx)(`span`,{className:`absolute inset-y-0 w-px bg-border`,style:{left:`${e.left}%`}},e.key)),N.today!=null&&(0,D.jsx)(`span`,{className:`absolute inset-y-0 w-px`,style:{background:o(`error`),opacity:.55,left:`${N.today}%`}})]}),(0,D.jsxs)(`div`,{className:`relative`,children:[M.length>0&&(0,D.jsx)(`svg`,{"aria-hidden":`true`,preserveAspectRatio:`none`,viewBox:`0 0 100 ${A.length}`,className:`pointer-events-none absolute top-0 h-full`,style:{left:c,width:`calc(100% - ${c}px)`},children:M.map(e=>{let t=O.get(e.from),n=O.get(e.to);if(!t||!n)return null;let r=N.pct(t.to),i=N.pct(n.from),a=j.get(e.from)+.5,s=j.get(e.to)+.5;return(0,D.jsx)(`path`,{d:`M ${r} ${a} C ${(r+i)/2} ${a}, ${(r+i)/2} ${s}, ${i} ${s}`,vectorEffect:`non-scaling-stroke`,style:i<r?{fill:`none`,stroke:o(`error`),strokeWidth:1.5,strokeDasharray:`3 2`}:{fill:`none`,stroke:`var(--muted-foreground)`,strokeWidth:1.5,opacity:.4}},`${e.from}-${e.to}`)})}),A.map((e,n)=>e.task?(0,D.jsx)(L,{task:e.task,span:O.get(e.task.id),mode:r,epicId:t.get(e.task.id),pct:N.pct,labelWidth:c,onOpen:s},e.task.id):(0,D.jsx)(`div`,{className:`border-b bg-muted/40`,children:(0,D.jsx)(`span`,{className:`flex items-center px-3.5 text-[10px] uppercase tracking-[0.08em] text-muted-foreground`,style:{height:`var(--row-h)`},children:e.label})},`group-${n}-${e.label}`))]})]})})]})}export{P as EpicsView,N as FlowBoard,R as TimelineView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{U as r,_t as i,kt as a,nt as o,q as s,vt as c}from"./ui-primitives-DRENhlck.js";import{r as l,s as u,u as d}from"./theme-CcOVK72d.js";import{$ as f,A as ee,B as te,C as p,D as ne,E as m,I as re,M as ie,P as ae,R as oe,S as se,T as h,_ as g,b as _,c as ce,d as le,et as ue,f as de,g as v,h as y,it as b,k as fe,l as pe,m as x,nt as S,p as me,q as C,rt as w,v as he,w as ge,x as _e,y as T,z as ve}from"./index-BcEUSS3r.js";import{t as ye}from"./layout-QiuZ_k5v.js";var E=e(t(),1),D=n(),O=`doc-h`,be=[`current`,`draft`,`superseded`,`archived`],k=`text-[10px] font-medium tracking-[0.07em] uppercase text-muted-foreground`;function xe({document:e,selected:t,onSelect:n}){return(0,D.jsx)(m,{asChild:!0,size:`sm`,className:d(`w-full cursor-pointer flex-col items-start gap-0.5 px-2 py-1.5 text-left hover:bg-accent`,t&&`bg-accent`),children:(0,D.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,children:[(0,D.jsxs)(`span`,{className:`flex w-full items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`flex-1 truncate text-xs font-medium`,children:e.title}),(0,D.jsx)(`span`,{className:d(`font-mono text-[10px]`,!e.managed&&`text-muted-foreground`),style:e.managed?{color:l(e.status)}:void 0,children:e.managed?e.status:`indexed`})]}),(0,D.jsx)(`span`,{className:`w-full truncate font-mono text-[10px] text-muted-foreground`,children:e.path})]})})}function Se({entries:e,activeId:t,onJump:n}){let r=Math.min(...e.map(e=>e.level));return(0,D.jsxs)(`aside`,{"aria-label":`Document outline`,className:`hidden w-[228px] shrink-0 overflow-y-auto border-l px-3 py-6.5 xl:block`,children:[(0,D.jsx)(`span`,{className:d(k,`px-2`),children:`on this page`}),(0,D.jsx)(`nav`,{className:`mt-2 flex flex-col gap-px`,children:e.map(e=>{let i=e.id===t;return(0,D.jsx)(`button`,{type:`button`,"aria-current":i?`true`:void 0,className:d(`cursor-pointer rounded-md px-2 py-1 text-left text-xs leading-snug transition-colors hover:bg-accent`,i?`bg-accent font-medium text-foreground`:`text-muted-foreground`),style:{paddingLeft:`${8+Math.min(e.level-r,3)*12}px`},onClick:()=>n(e.id),children:e.text},e.id)})})]})}function A({label:e,value:t}){return(0,D.jsxs)(g,{className:`w-auto min-w-[120px] gap-0.5 rounded-lg border bg-card px-3 py-2 shadow-xs`,children:[(0,D.jsx)(`span`,{className:k,children:e}),(0,D.jsx)(`span`,{className:`text-[13px] font-medium`,children:t})]})}function j({label:e,links:t,onOpen:n}){return t.length?(0,D.jsxs)(`section`,{className:`flex flex-col gap-1.5`,children:[(0,D.jsx)(`span`,{className:k,children:e}),t.map((e,t)=>{let r=!e.exists&&!e.title;return(0,D.jsx)(m,{asChild:!0,variant:`outline`,size:`sm`,className:d(`w-full cursor-pointer gap-2 px-2.5 py-2 text-left hover:bg-accent`,r&&`cursor-default opacity-55 hover:bg-transparent`),children:(0,D.jsxs)(`button`,{type:`button`,disabled:r,onClick:()=>n(e.id),children:[(0,D.jsx)(`span`,{className:`min-w-[78px] shrink-0 font-mono text-[11px] font-medium`,children:e.id}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-muted-foreground`,children:e.title||(e.exists===!1?`Missing record`:e.id)}),(e.relations??[e.relation]).filter(Boolean).map(e=>(0,D.jsx)(S,{variant:`secondary`,className:`font-mono text-[10px]`,children:e},e))]})},`${e.id}-${t}`)})]}):null}var M=(0,D.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted-foreground`,children:`·`});function N({id:e,onSelect:t,onOpen:n}){let[r,i]=(0,E.useState)(null),[a,o]=(0,E.useState)(``),s=(0,E.useRef)(null),d=(0,E.useMemo)(()=>r?_e(r.body||``,O):[],[r]);return(0,E.useEffect)(()=>{let t=!0;return i(null),o(``),C.record(e).then(e=>{t&&i(e.record)}).catch(e=>{t&&o(e.message)}),()=>{t=!1}},[e]),a?(0,D.jsx)(`div`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:a}):r?(0,D.jsxs)(`div`,{ref:s,className:`flex min-h-0 flex-1 flex-col overflow-y-auto px-4 py-3`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 font-mono text-[11px] text-muted-foreground`,children:[(0,D.jsx)(`span`,{children:r.id}),M,(0,D.jsx)(`span`,{children:r.documentKind}),M,(0,D.jsx)(`span`,{style:{color:l(r.status)},children:r.status}),M,(0,D.jsx)(`span`,{children:r.managed?`managed`:`indexed`}),(0,D.jsxs)(u,{type:`button`,variant:`ghost`,size:`sm`,className:`ml-auto px-2`,onClick:()=>n(e),children:[(0,D.jsx)(c,{"aria-hidden":`true`,className:`size-3`}),`Open in Docs`]})]}),(0,D.jsx)(`h2`,{className:`mt-1 text-sm font-medium`,children:r.title}),(0,D.jsx)(`p`,{className:`font-mono text-[11px] text-muted-foreground`,children:r.path}),r.freshness?.length?(0,D.jsx)(w,{className:`mt-3`,children:(0,D.jsx)(b,{children:r.freshness.map(e=>e.message).join(` `)})}):null,(0,D.jsxs)(`div`,{className:`mt-3 flex min-w-0 items-start gap-1`,children:[(0,D.jsx)(`div`,{className:`min-w-0 flex-1 [&>.typeset]:[--typeset-leading:1.6] [&>.typeset]:[--typeset-size:0.8125rem] [&>.typeset>:not(.typeset-scroll)]:max-w-[72ch]`,children:(0,D.jsx)(_,{source:r.body||`_This document is empty._`,onOpen:t,headingPrefix:O})}),(0,D.jsx)(x,{entries:d,container:s})]})]}):(0,D.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground`,children:[(0,D.jsx)(h,{}),` Reading `,e,`…`]})}function P({selectedId:e,onSelect:t,onOpenCard:n,search:c,onSearchChange:m}){let x=ge(),[S,N]=(0,E.useState)([]),[P,F]=(0,E.useState)(!0),[I,L]=(0,E.useState)(``),[R,Ce]=(0,E.useState)(!1),[z,we]=(0,E.useState)(!1),[B,V]=(0,E.useState)(null),[H,U]=(0,E.useState)(!1),[W,G]=(0,E.useState)(``),[K,Te]=(0,E.useState)(null),[Ee,q]=(0,E.useState)(0);te(e=>{ve(e,`/docs/`,`docs/`)&&q(e=>e+1)}),(0,E.useEffect)(()=>{let e=!1;F(!0);let t=window.setTimeout(()=>{C.docs(c.trim()).then(t=>{e||(N(t.records),L(``))}).catch(t=>{e||L(t instanceof Error?t.message:String(t))}).finally(()=>{e||F(!1)})},c?180:0);return()=>{e=!0,window.clearTimeout(t)}},[c,Ee]),(0,E.useEffect)(()=>{if(!B||K)return;let e=!1;return C.tasks().then(t=>{e||Te(t.schema.docs)}).catch(()=>{}),()=>{e=!0}},[B,K]);let J=(0,E.useMemo)(()=>R?S.filter(e=>e.managed):S,[S,R]),De=(0,E.useMemo)(()=>{let e=J.filter(e=>e.managed),t=J.filter(e=>!e.managed);return[{key:`managed`,label:`.project/docs · managed`,docs:e},{key:`indexed`,label:`indexed · read only`,docs:t}].filter(e=>e.docs.length>0)},[J]),Oe=ue(),Y=J.find(t=>t.id===e)||(Oe?void 0:J[0]),ke=(0,E.useRef)(null),[Ae,X]=(0,E.useState)(``),Z=(0,E.useMemo)(()=>Y&&!z?_e(Y.body,O):[],[Y,z]),Q=Z.length>1;(0,E.useEffect)(()=>{X(``);let e=ke.current;if(!e||!Q)return;let t=new Map,n=new IntersectionObserver(e=>{for(let n of e)t.set(n.target.id,n.isIntersecting);let n=Z.find(e=>t.get(e.id));n&&X(n.id)},{root:e,rootMargin:`0px 0px -66% 0px`,threshold:0});for(let e of Z){let t=document.getElementById(e.id);t&&n.observe(t)}return()=>n.disconnect()},[Z,Q]);let je=e=>{document.getElementById(e)?.scrollIntoView({block:`start`,behavior:`smooth`}),X(e)},$=e=>{let r=S.find(t=>t.id===e);r?t(r.id):n(e)},Me=(0,E.useMemo)(()=>{let e=new Set(K?.kinds??[]);for(let t of S)t.managed&&e.add(t.documentKind);return B&&e.add(B.kind),[...e].sort()},[K,S,B]),Ne=(0,E.useMemo)(()=>{let e=new Set(K?.statuses??be);for(let t of S)t.managed&&e.add(t.status);return B&&e.add(B.status),[...e].sort()},[K,S,B]);function Pe(e){G(``),V({id:e.id,title:e.title,kind:e.documentKind,status:e.status,owners:(e.owners??[]).join(`, `),reviewed:e.reviewed??``})}async function Fe(){if(!B)return;let e=S.find(e=>e.id===B.id);if(!e){G(`This document no longer exists in the workspace.`);return}let t=B.owners.split(`,`).map(e=>e.trim()).filter(Boolean),n={},r=B.title.trim();if(r&&r!==e.title&&(n.title=r),B.kind!==e.documentKind&&(n.kind=B.kind),B.status!==e.status&&(n.status=B.status),t.join(`
`)!==(e.owners??[]).join(`
`)&&(n.owners=t),(B.reviewed||``)!==(e.reviewed??``)&&(n.reviewed=B.reviewed||null),!Object.keys(n).length){V(null);return}U(!0),G(``);try{let t=await C.patchDocument(e.id,n,e.revision);N(n=>n.map(n=>n.id===e.id?t.record:n)),V(null)}catch(e){let t=e;t.code?.endsWith(`WRITE_CONFLICT`)?(q(e=>e+1),G(`The document changed on disk; the list was refreshed. Save again to apply your changes to the latest revision.`)):G(t.message||String(e))}finally{U(!1)}}return(0,D.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,D.jsxs)(`aside`,{"aria-label":`Documents`,className:d(`min-h-0 w-full shrink-0 flex-col border-r px-2 py-3 lg:flex lg:w-[290px]`,Y?`hidden`:`flex`),children:[(0,D.jsx)(re,{className:`pb-2.5`,before:(0,D.jsx)(ae,{scope:`records`,value:c,label:`Search documentation`,onChange:m}),children:(0,D.jsx)(oe,{label:`managed`,on:R,onLabel:`only`,offLabel:`all`,onChange:Ce})}),(0,D.jsx)(`div`,{"aria-busy":P||void 0,className:`min-h-0 flex-1 overflow-y-auto`,children:P?(0,D.jsxs)(`span`,{className:`flex items-center gap-2 px-2 py-1.5 font-mono text-[10.5px] text-muted-foreground`,children:[(0,D.jsx)(h,{className:`size-3`}),`Loading documents…`]}):I?(0,D.jsx)(w,{variant:`destructive`,className:`mt-1.5`,children:(0,D.jsx)(b,{children:I})}):De.length?De.map(e=>(0,D.jsxs)(`div`,{className:`flex flex-col gap-px pb-3.5`,children:[(0,D.jsxs)(`span`,{className:`flex items-center gap-2 px-2 py-1.5 font-mono text-[10.5px] text-muted-foreground`,children:[(0,D.jsx)(`span`,{className:`text-foreground/80`,children:e.label}),(0,D.jsx)(`span`,{children:e.docs.length})]}),e.docs.map(e=>(0,D.jsx)(xe,{document:e,selected:Y?.id===e.id,onSelect:()=>t(e.id)},e.id))]},e.key)):(0,D.jsx)(ne,{className:`gap-2 p-4 md:p-4`,children:(0,D.jsxs)(ee,{children:[(0,D.jsx)(ie,{className:`text-sm`,children:`No documents found.`}),(0,D.jsx)(fe,{className:`text-xs`,children:R?`Try another search, or include indexed files.`:`Try another search.`})]})})})]}),(0,D.jsx)(`section`,{ref:ke,className:d(`min-w-0 flex-1 overflow-y-auto px-6 py-6.5 sm:px-8.5`,Y?`block`:`hidden lg:block`),children:(0,D.jsx)(`div`,{className:ye,children:Y?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(u,{type:`button`,variant:`ghost`,size:`sm`,className:`-ml-2 mb-2 lg:hidden`,onClick:()=>t(null),children:[(0,D.jsx)(a,{"aria-hidden":`true`}),`All documents`]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 font-mono text-[11px] text-muted-foreground`,children:[(0,D.jsx)(`span`,{children:Y.id}),M,(0,D.jsx)(`span`,{children:Y.documentKind}),M,(0,D.jsx)(`span`,{style:{color:l(Y.status)},children:Y.status}),M,(0,D.jsx)(`span`,{children:Y.managed?`managed`:`indexed`}),(0,D.jsx)(`span`,{className:`flex-1`}),Y.managed?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(u,{type:`button`,variant:`outline`,size:`sm`,disabled:x,title:x?p:void 0,onClick:()=>we(e=>!e),children:[z?(0,D.jsx)(i,{"aria-hidden":`true`}):(0,D.jsx)(o,{"aria-hidden":`true`}),z?`Preview`:`Edit`]}),(0,D.jsxs)(u,{type:`button`,variant:`outline`,size:`sm`,disabled:x,title:x?p:void 0,onClick:()=>Pe(Y),children:[(0,D.jsx)(s,{"aria-hidden":`true`}),`Metadata`]})]}):null]}),(0,D.jsx)(`h2`,{className:`mt-3 mb-1.5 text-2xl font-semibold tracking-tight`,children:Y.title}),(0,D.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground [overflow-wrap:anywhere]`,children:Y.path}),(0,D.jsxs)(`div`,{className:`mt-4.5 flex flex-wrap gap-2`,children:[(0,D.jsx)(A,{label:`kind`,value:Y.documentKind}),(0,D.jsx)(A,{label:`status`,value:Y.status}),(0,D.jsx)(A,{label:`reviewed`,value:Y.reviewed||`—`}),(0,D.jsx)(A,{label:`owners`,value:Y.owners?.join(`, `)||`—`}),(0,D.jsx)(A,{label:`backlinks`,value:String(Y.incomingTotal??Y.incoming.length)}),Y.updated?(0,D.jsx)(A,{label:`updated`,value:Y.updated}):null]}),Y.freshness.length>0?(0,D.jsxs)(w,{role:`status`,className:`mt-4.5 max-w-2xl`,children:[(0,D.jsx)(r,{"aria-hidden":`true`,className:`text-sev-warning`}),(0,D.jsx)(b,{children:Y.freshness.map(e=>(0,D.jsx)(`span`,{children:e.message},`${e.code}-${e.message}`))})]}):null,(0,D.jsx)(`div`,{className:`mt-6.5`,children:z&&Y.managed?(0,D.jsx)(se,{value:Y.body,revision:Y.revision,onSave:async(e,t)=>{let n=await C.patchDocument(Y.id,{body:e},t);N(e=>e.map(e=>e.id===Y.id?n.record:e))}},Y.id):Y.body.trim()?(0,D.jsx)(_,{source:Y.body,headingPrefix:O,onOpen:$}):(0,D.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Y.managed?`This document is empty. Use Edit to write its first version.`:`This file has no body to render.`})}),Y.outgoing.length||Y.incoming.length||Y.scope?.length?(0,D.jsxs)(`div`,{className:`mt-7 flex max-w-[70ch] flex-col gap-4.5`,children:[(0,D.jsx)(j,{label:`links to`,links:Y.outgoing,onOpen:$}),(0,D.jsx)(j,{label:(Y.incomingTotal??Y.incoming.length)>Y.incoming.length?`backlinks (${Y.incoming.length} of ${Y.incomingTotal})`:`backlinks`,links:Y.incoming,onOpen:$}),Y.scope?.length?(0,D.jsxs)(`section`,{className:`flex flex-col gap-1.5`,children:[(0,D.jsx)(`span`,{className:k,children:`scope`}),Y.scope.map(e=>(0,D.jsx)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground [overflow-wrap:anywhere]`,children:e},e))]}):null]}):null]}):(0,D.jsx)(`div`,{className:`flex h-full items-center justify-center text-xs text-muted-foreground`,children:P?`Loading documents…`:`Select a document from the list to read it.`})})}),Q?(0,D.jsx)(Se,{entries:Z,activeId:Ae,onJump:je}):null,(0,D.jsx)(ce,{open:B!==null,onOpenChange:e=>{!e&&!H&&V(null)},children:(0,D.jsxs)(pe,{"aria-describedby":void 0,children:[(0,D.jsx)(de,{children:(0,D.jsx)(me,{children:`Edit metadata${B?` — ${B.id}`:``}`})}),B?(0,D.jsxs)(he,{className:`gap-4`,children:[(0,D.jsxs)(g,{children:[(0,D.jsx)(T,{htmlFor:`docs-meta-title`,children:`title`}),(0,D.jsx)(f,{id:`docs-meta-title`,value:B.title,onChange:e=>V({...B,title:e.target.value})})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,D.jsxs)(g,{className:`[&_[data-slot=native-select-wrapper]]:w-full`,children:[(0,D.jsx)(T,{htmlFor:`docs-meta-kind`,children:`kind`}),(0,D.jsx)(y,{id:`docs-meta-kind`,value:B.kind,onChange:e=>V({...B,kind:e.target.value}),children:Me.map(e=>(0,D.jsx)(v,{value:e,children:e},e))})]}),(0,D.jsxs)(g,{className:`[&_[data-slot=native-select-wrapper]]:w-full`,children:[(0,D.jsx)(T,{htmlFor:`docs-meta-status`,children:`status`}),(0,D.jsx)(y,{id:`docs-meta-status`,value:B.status,onChange:e=>V({...B,status:e.target.value}),children:Ne.map(e=>(0,D.jsx)(v,{value:e,children:e},e))})]})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,D.jsxs)(g,{children:[(0,D.jsx)(T,{htmlFor:`docs-meta-owners`,children:`owners`}),(0,D.jsx)(f,{id:`docs-meta-owners`,value:B.owners,placeholder:`comma-separated`,onChange:e=>V({...B,owners:e.target.value})})]}),(0,D.jsxs)(g,{children:[(0,D.jsx)(T,{htmlFor:`docs-meta-reviewed`,children:`reviewed`}),(0,D.jsx)(f,{id:`docs-meta-reviewed`,type:`date`,value:B.reviewed,onChange:e=>V({...B,reviewed:e.target.value})})]})]}),W?(0,D.jsx)(w,{variant:`destructive`,children:(0,D.jsx)(b,{children:W})}):null]}):null,(0,D.jsxs)(le,{children:[(0,D.jsx)(u,{type:`button`,variant:`outline`,disabled:H,onClick:()=>V(null),children:`Cancel`}),(0,D.jsx)(u,{type:`button`,disabled:H,onClick:()=>void Fe(),children:H?`Saving…`:`Save`})]})]})})]})}export{N as DocPanel,P as DocsView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{D as r,E as i,Ft as a,It as o,jt as s,q as ee,wt as te}from"./ui-primitives-DRENhlck.js";import{n as c,o as l,s as u,u as d}from"./theme-CcOVK72d.js";import{A as ne,D as f,J as re,M as ie,N as ae,Q as oe,X as se,Y as ce,Z as le,a as p,g as m,h,i as ue,k as de,o as g,s as fe}from"./index-BcEUSS3r.js";import{t as _}from"./progress-CzHcd1lF.js";var v=e(t(),1),y=n();function b({className:e,...t}){return(0,y.jsx)(i,{"data-slot":`checkbox`,className:d(`peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary`,e),...t,children:(0,y.jsx)(r,{"data-slot":`checkbox-indicator`,className:`grid place-content-center text-current transition-none`,children:(0,y.jsx)(s,{className:`size-3.5`})})})}function pe({className:e,...t}){return(0,y.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,y.jsx)(`table`,{"data-slot":`table`,className:d(`w-full caption-bottom text-sm`,e),...t})})}function me({className:e,...t}){return(0,y.jsx)(`thead`,{"data-slot":`table-header`,className:d(`[&_tr]:border-b`,e),...t})}function he({className:e,...t}){return(0,y.jsx)(`tbody`,{"data-slot":`table-body`,className:d(`[&_tr:last-child]:border-0`,e),...t})}function x({className:e,...t}){return(0,y.jsx)(`tr`,{"data-slot":`table-row`,className:d(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,e),...t})}function S({className:e,...t}){return(0,y.jsx)(`th`,{"data-slot":`table-head`,className:d(`h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function C({className:e,...t}){return(0,y.jsx)(`td`,{"data-slot":`table-cell`,className:d(`p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}var w=[[`id`,`id`],[`title`,`title · claim`],[`status`,`status`],[`priority`,`prio`],[`type`,`type`],[`area`,`area`],[`epic`,`links`],[`updated`,`updated`]],T=new Map(p.map((e,t)=>[e,t])),E=new Map(g.map((e,t)=>[e,t])),D=w.length+1;function O(e,t){let n=new Map;for(let r of e){let e=r[t];typeof e==`string`&&n.set(e,(n.get(e)||0)+1)}return n}function k({title:e,values:t,counts:n,selected:r,color:i,onSelect:a}){let o=t.filter(e=>n.has(e));if(!o.length)return null;let s=Math.max(...o.map(e=>n.get(e)||0));return(0,y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,y.jsx)(`span`,{className:`px-1.5 font-mono text-[10px] tracking-widest uppercase text-muted-foreground`,children:e}),o.map(e=>{let t=n.get(e)||0,o=r===e;return(0,y.jsxs)(`button`,{type:`button`,"aria-pressed":o,onClick:()=>a(o?``:e),className:d(`flex w-full cursor-pointer flex-col gap-1 rounded-md px-1.5 py-1 text-left transition-colors hover:bg-accent/50`,o&&`bg-accent`),children:[(0,y.jsxs)(`span`,{className:`flex w-full items-center gap-1.5`,children:[(0,y.jsx)(`span`,{className:d(`min-w-0 flex-1 truncate text-xs`,o?`font-medium text-foreground`:`text-muted-foreground`),children:e}),(0,y.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:t})]}),(0,y.jsx)(_,{value:s?Math.round(t/s*100):0,className:d(`h-[5px] bg-muted [&>div]:bg-current`,!i&&`text-primary`),style:i?{color:i(e)}:void 0})]},e)})]})}function A({label:e,value:t,options:n,color:r,withDot:i,onChange:a}){return(0,y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,style:{color:r},children:[i?(0,y.jsx)(`span`,{className:`size-1.5 shrink-0 rounded-full bg-current`,"aria-hidden":`true`}):null,(0,y.jsx)(h,{"aria-label":e,value:t,onChange:e=>a(e.target.value),className:`h-[22px] cursor-pointer border-transparent bg-transparent px-1 py-0 pr-8 font-mono text-[11px] text-inherit shadow-none dark:bg-transparent dark:hover:bg-transparent`,children:n.map(e=>(0,y.jsx)(m,{value:e,children:e},e))})]})}var ge=(0,v.memo)(function({task:e,epicId:t,checked:n,isOpen:r,onToggle:i,onOpen:a,onPatch:o}){let s=(e.depends?.length??0)+ +!!e.parent;return(0,y.jsxs)(x,{className:`h-[var(--row-h)] cursor-pointer`,"data-state":r?`selected`:void 0,tabIndex:0,onClick:()=>a(e.id),onKeyDown:t=>{t.key===`Enter`&&a(e.id)},children:[(0,y.jsx)(C,{className:d(`w-7 border-l-2 border-l-transparent`,r&&`border-l-primary`),onClick:e=>e.stopPropagation(),children:(0,y.jsx)(b,{"aria-label":`Select ${e.id}`,checked:n,onCheckedChange:()=>i(e.id)})}),(0,y.jsx)(C,{className:`font-mono text-xs text-muted-foreground`,children:e.id}),(0,y.jsx)(C,{className:`max-w-[520px]`,children:(0,y.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,y.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:e.title}),e.claimed_by?(0,y.jsxs)(`span`,{className:`font-mono text-[10px] whitespace-nowrap text-muted-foreground/60`,children:[`· `,e.claimed_by]}):null]})}),(0,y.jsx)(C,{onClick:e=>e.stopPropagation(),children:(0,y.jsx)(A,{label:`Status for ${e.id}`,value:e.status,options:g,color:l(e.status),withDot:!0,onChange:t=>void o(e.id,{status:t}).catch(()=>void 0)})}),(0,y.jsx)(C,{onClick:e=>e.stopPropagation(),children:(0,y.jsx)(A,{label:`Priority for ${e.id}`,value:e.priority,options:p,color:c(e.priority),onChange:t=>void o(e.id,{priority:t}).catch(()=>void 0)})}),(0,y.jsx)(C,{className:`font-mono text-[11px] text-muted-foreground`,children:e.type}),(0,y.jsx)(C,{className:`font-mono text-[11px] text-muted-foreground`,children:e.area}),(0,y.jsxs)(C,{className:`font-mono text-[11px] text-muted-foreground/60`,children:[t?(0,y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a(t)},className:d(`cursor-pointer text-primary hover:underline`,s>0&&`mr-1.5`),children:t}):null,s>0?`${s} ↔`:t?null:`—`]}),(0,y.jsx)(C,{className:`font-mono text-[11px] text-muted-foreground/60`,children:e.updated||`—`})]})});function j({tasks:e,allTasks:t,areas:n,filters:r,setFilters:i,epicIds:s,onOpen:d,onPatch:_,onBulkPatch:C}){let[A,j]=(0,v.useState)(()=>new Set),[_e,ve]=(0,v.useState)(null),[M,ye]=(0,v.useState)(`id`),[N,P]=(0,v.useState)(`desc`),[F,I]=(0,v.useState)(``),[L,R]=(0,v.useState)(``),[z,B]=(0,v.useState)(``),V=(0,v.useRef)(null),[H,be]=(0,v.useState)({start:0,end:40}),[U,xe]=(0,v.useState)(40),W=(0,v.useDeferredValue)(r),G=(0,v.useMemo)(()=>{let e=e=>ue(t,{...W,...e});return{status:O(e({status:``}),`status`),type:O(e({type:``,showIdeas:!0}),`type`),priority:O(e({priority:``}),`priority`),area:O(e({area:``}),`area`)}},[t,W]),K=(0,v.useMemo)(()=>{let t=[...e];return t.sort((e,t)=>{let n=0;return n=M===`priority`?(T.get(e.priority)||0)-(T.get(t.priority)||0):M===`status`?(E.get(e.status)||0)-(E.get(t.status)||0):M===`epic`?(s.get(e.id)||``).localeCompare(s.get(t.id)||``):String(e[M]||``).localeCompare(String(t[M]||``),void 0,{numeric:!0}),N===`asc`?n:-n}),t},[s,N,M,e]),q=(0,v.useRef)(0),Se=K.length>0,J=(0,v.useCallback)(()=>{let e=V.current;if(!e)return;let t=parseFloat(getComputedStyle(document.documentElement).getPropertyValue(`--row-h`))||40;xe(t);let n=Math.max(0,Math.floor(e.scrollTop/t)-10),r=Math.ceil(e.clientHeight/t);be({start:n,end:Math.min(q.current,n+r+20)})},[]);(0,v.useEffect)(()=>{let e=V.current;if(!e)return;e.addEventListener(`scroll`,J,{passive:!0}),window.addEventListener(`resize`,J);let t=new MutationObserver(J);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-density`]}),()=>{e.removeEventListener(`scroll`,J),window.removeEventListener(`resize`,J),t.disconnect()}},[J,Se]),(0,v.useEffect)(()=>{q.current=K.length,J()},[J,K.length]);let Ce=[r.search,r.status,r.area,r.type,r.priority,r.milestone,r.showIdeas,r.showClosed,M,N].join(`|`);(0,v.useEffect)(()=>{V.current&&(V.current.scrollTop=0),J()},[Ce,J]);let we=(0,v.useCallback)(e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Te=(0,v.useCallback)(e=>{ve(e),d(e)},[d]),Y=(0,v.useMemo)(()=>K.map(e=>e.id),[K]),X=Y.length>0&&Y.every(e=>A.has(e)),Ee=Y.some(e=>A.has(e)),De=K.slice(H.start,H.end),Z=!!(F||L||z);function Oe(e){M===e?P(e=>e===`asc`?`desc`:`asc`):(ye(e),P(e===`id`?`desc`:`asc`))}async function ke(){let e={};if(F&&(e.status=F),L&&(e.priority=L),z&&(e.area=z),!(!Z||A.size===0))try{await C([...A],e),j(new Set),I(``),R(``),B(``)}catch{}}let Q=(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(k,{title:`status`,values:g,counts:G.status,selected:r.status,color:l,onSelect:e=>i(t=>({...t,status:e}))}),(0,y.jsx)(k,{title:`priority`,values:p,counts:G.priority,selected:r.priority,color:c,onSelect:e=>i(t=>({...t,priority:e}))}),(0,y.jsx)(k,{title:`area`,values:n,counts:G.area,selected:r.area,onSelect:e=>i(t=>({...t,area:e}))}),(0,y.jsx)(k,{title:`type`,values:fe,counts:G.type,selected:r.type,onSelect:e=>i(t=>({...t,type:e}))})]}),$=[r.status,r.priority,r.area,r.type].filter(Boolean).length;return(0,y.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,y.jsx)(`aside`,{"aria-label":`Backlog facets`,className:`hidden w-[204px] flex-none flex-col gap-5 overflow-y-auto border-r px-3.5 py-4 lg:flex`,children:Q}),(0,y.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,y.jsxs)(`div`,{className:`flex flex-none items-center gap-2 px-3.5 pt-2.5 lg:hidden`,children:[(0,y.jsxs)(re,{children:[(0,y.jsx)(oe,{asChild:!0,children:(0,y.jsxs)(u,{variant:`outline`,size:`sm`,children:[(0,y.jsx)(ee,{className:`size-3.5`}),`Facets`,$?(0,y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:$}):null]})}),(0,y.jsxs)(ce,{side:`left`,className:`w-[280px] gap-0 sm:max-w-[280px]`,children:[(0,y.jsx)(se,{className:`pb-2`,children:(0,y.jsx)(le,{className:`font-mono text-[11px] tracking-wide uppercase`,children:`Facets`})}),(0,y.jsx)(`div`,{className:`flex flex-col gap-5 overflow-y-auto px-4 pb-4`,children:Q})]})]}),(0,y.jsxs)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground/70`,children:[K.length.toLocaleString(),` row`,K.length===1?``:`s`,` · scroll sideways for every column`]})]}),A.size>0&&(0,y.jsxs)(`div`,{role:`region`,"aria-label":`Bulk actions`,className:`mx-3.5 mt-2.5 mb-2.5 flex flex-none flex-wrap items-center gap-2 rounded-md border bg-muted/50 px-3 py-2`,children:[(0,y.jsxs)(`span`,{className:`font-mono text-[11px]`,children:[A.size,` selected`]}),(0,y.jsxs)(h,{"aria-label":`Set status`,value:F,onChange:e=>I(e.target.value),size:`sm`,children:[(0,y.jsx)(m,{value:``,children:`status…`}),g.map(e=>(0,y.jsx)(m,{value:e,children:e},e))]}),(0,y.jsxs)(h,{"aria-label":`Set priority`,value:L,onChange:e=>R(e.target.value),size:`sm`,children:[(0,y.jsx)(m,{value:``,children:`priority…`}),p.map(e=>(0,y.jsx)(m,{value:e,children:e},e))]}),(0,y.jsxs)(h,{"aria-label":`Set area`,value:z,onChange:e=>B(e.target.value),size:`sm`,children:[(0,y.jsx)(m,{value:``,children:`area…`}),n.map(e=>(0,y.jsx)(m,{value:e,children:e},e))]}),(0,y.jsxs)(ae,{children:[(0,y.jsx)(u,{size:`sm`,disabled:!Z,onClick:()=>void ke(),children:`Apply`}),(0,y.jsx)(u,{size:`sm`,variant:`outline`,onClick:()=>j(new Set),children:`Clear`})]})]}),K.length===0?(0,y.jsx)(f,{children:(0,y.jsxs)(ne,{children:[(0,y.jsx)(ie,{children:`No cards match`}),(0,y.jsx)(de,{children:`Adjust filters or clear the search`})]})}):(0,y.jsx)(`div`,{ref:V,className:`min-w-0 flex-1 overflow-auto [&>[data-slot=table-container]]:overflow-visible`,children:(0,y.jsxs)(pe,{className:`text-[13px]`,children:[(0,y.jsx)(me,{children:(0,y.jsxs)(x,{className:`hover:bg-transparent`,children:[(0,y.jsx)(S,{className:`sticky top-0 z-10 w-7 bg-background`,children:(0,y.jsx)(b,{"aria-label":`Select all matching cards`,checked:X?!0:Ee?`indeterminate`:!1,onCheckedChange:()=>j(e=>{let t=new Set(e);return X?Y.forEach(e=>t.delete(e)):Y.forEach(e=>t.add(e)),t})})}),w.map(([e,t])=>(0,y.jsx)(S,{"aria-sort":M===e?N===`asc`?`ascending`:`descending`:`none`,className:`sticky top-0 z-10 bg-background`,children:(0,y.jsxs)(u,{variant:`ghost`,size:`sm`,onClick:()=>Oe(e),className:`-ml-2 px-2 text-muted-foreground`,children:[t,M===e?N===`asc`?(0,y.jsx)(a,{className:`size-3`}):(0,y.jsx)(o,{className:`size-3`}):(0,y.jsx)(te,{className:`size-3 opacity-50`})]})},e))]})}),(0,y.jsxs)(he,{children:[H.start>0&&(0,y.jsx)(`tr`,{"aria-hidden":`true`,children:(0,y.jsx)(`td`,{colSpan:D,style:{height:H.start*U}})}),De.map(e=>(0,y.jsx)(ge,{task:e,epicId:s.get(e.id)||``,checked:A.has(e.id),isOpen:_e===e.id,onToggle:we,onOpen:Te,onPatch:_},e.id)),H.end<K.length&&(0,y.jsx)(`tr`,{"aria-hidden":`true`,children:(0,y.jsx)(`td`,{colSpan:D,style:{height:(K.length-H.end)*U}})})]})]})})]})]})}export{j as Explorer};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{Ct as r}from"./ui-primitives-DRENhlck.js";import{i,o as a,s as o}from"./theme-CcOVK72d.js";import{A as s,B as c,D as l,H as u,M as d,T as f,V as p,it as m,j as h,k as g,nt as _,q as v,rt as y}from"./index-BcEUSS3r.js";var b=e(t(),1),x=n(),S=[{level:`error`,label:`errors`,hint:`must be fixed for a consistent workspace`,zeroHint:`the doctor does not block the release`},{level:`warning`,label:`warnings`,hint:`worth a look, nothing is broken yet`,zeroHint:`nothing worth flagging`},{level:`info`,label:`infos`,hint:`informational, no action required`,zeroHint:`no notices from the doctor`}];function C(e){return e.replace(/[-_.]+/g,` `)}var w={error:0,warning:1,info:2};function T({onOpen:e}){let[t,n]=(0,b.useState)(null),[T,E]=(0,b.useState)(``),[D,O]=(0,b.useState)(``),[k,A]=(0,b.useState)(0);c(()=>A(e=>e+1)),(0,b.useEffect)(()=>{let e=!0;return v.health().then(t=>{e&&n(t)}).catch(t=>{e&&E(t instanceof Error?t.message:String(t))}),()=>{e=!1}},[k]);let j=(0,b.useMemo)(()=>{if(!t)return[];let e=D?t.issues.filter(e=>e.severity===D):t.issues,n=new Map;for(let t of e){let e=n.get(t.code);e?e.push(t):n.set(t.code,[t])}return[...n.entries()].sort(([e,[t]],[n,[r]])=>{let i=w[t.severity]-w[r.severity];return i===0?e.localeCompare(n):i})},[t,D]);if(T)return(0,x.jsx)(`div`,{className:`p-3.5`,children:(0,x.jsx)(y,{variant:`destructive`,children:(0,x.jsx)(m,{children:T})})});if(!t)return(0,x.jsxs)(`div`,{className:`flex items-center gap-2 p-3.5`,"aria-busy":`true`,children:[(0,x.jsx)(f,{className:`size-3 text-muted-foreground`}),(0,x.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:`running workfile doctor…`})]});let M=[[`cards`,t.modules?.cards??t.cards],[`docs`,t.modules?.docs],[`memory`,t.modules?.memory],[`changelog`,t.modules?.changelog]].filter(([,e])=>e!=null).map(([e,t])=>`${t.toLocaleString()} ${e}`).join(`, `),N=new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(t.generatedAt));return(0,x.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-3.5`,children:[(0,x.jsx)(`div`,{className:`mb-2.5 flex gap-1.5`,children:S.map(({level:e,label:n})=>(0,x.jsxs)(o,{type:`button`,variant:`outline`,size:`sm`,"aria-pressed":D===e,className:`aria-pressed:border-ring aria-pressed:bg-accent`,onClick:()=>O(t=>t===e?``:e),children:[n,(0,x.jsx)(_,{variant:`secondary`,className:`px-1.5 font-mono text-[10.5px]`,children:t.counts[e]})]},e))}),(0,x.jsx)(`div`,{className:`flex flex-wrap gap-2.5`,children:S.map(({level:e,label:n,hint:r,zeroHint:o})=>{let s=t.counts[e],c=e===`error`&&s===0?a(`done`):i(e);return(0,x.jsxs)(u,{className:`relative min-w-[13rem] flex-1 gap-1 py-3 pl-5 pr-3.5`,children:[(0,x.jsx)(p,{edge:`left`,color:c}),(0,x.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,x.jsx)(`span`,{className:`text-[26px] font-semibold tracking-tight`,style:{color:c},children:s}),(0,x.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:n})]}),(0,x.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:s===0?o:r})]},e)})}),(0,x.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-1 px-0.5 pt-4 pb-2`,children:[(0,x.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:[`grouped by code · `,M,` · checked `,N]}),(0,x.jsx)(`span`,{className:`ml-auto font-mono text-[10.5px] text-muted-foreground/70`,children:`workfile doctor --json`})]}),j.length===0?(0,x.jsx)(l,{className:`gap-2 p-10`,children:(0,x.jsxs)(s,{children:[(0,x.jsx)(h,{children:(0,x.jsx)(r,{"aria-hidden":`true`,size:20,style:{color:a(`done`)}})}),(0,x.jsx)(d,{className:`text-sm`,children:`All clear`}),(0,x.jsxs)(g,{className:`text-[12.5px]`,children:[`No `,D||`integrity`,` issues found.`]})]})}):(0,x.jsx)(`div`,{className:`flex flex-col gap-2`,children:j.map(([t,n])=>(0,x.jsxs)(u,{className:`gap-0 overflow-hidden py-0`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,x.jsx)(`span`,{"aria-hidden":`true`,className:`size-[7px] rounded-full bg-current`,style:{color:i(n[0].severity)}}),(0,x.jsx)(`span`,{className:`font-mono text-[11.5px]`,children:t}),(0,x.jsx)(`span`,{className:`flex-1 text-[12.5px] text-muted-foreground`,children:C(t)}),(0,x.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground/70`,children:n.length})]}),n.map((t,n)=>(0,x.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-1 border-b px-3 py-[7px] last:border-0`,children:[t.id?(0,x.jsx)(o,{type:`button`,variant:`link`,className:`h-auto w-[82px] flex-[0_0_82px] justify-start p-0 font-mono text-[11px] font-normal`,onClick:()=>e(t.id),children:t.id}):(0,x.jsx)(`span`,{className:`w-[82px] flex-[0_0_82px] font-mono text-[11px] text-muted-foreground/70`,children:`—`}),(0,x.jsx)(`span`,{className:`min-w-[12rem] flex-1 text-[12.5px] text-muted-foreground`,children:t.message}),t.file?(0,x.jsx)(`span`,{className:`max-w-full truncate font-mono text-[10.5px] text-muted-foreground/70 sm:max-w-80`,title:t.file,children:t.file}):null]},`${t.id||t.file}-${n}`))]},t))})]})}export{T as HealthView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{B as r,kt as i,tt as a}from"./ui-primitives-DRENhlck.js";import{i as o,o as s,r as c,s as l,u}from"./theme-CcOVK72d.js";import{$ as d,B as f,C as p,D as m,E as h,F as g,G as _,H as ee,I as v,K as y,L as te,N as ne,P as re,U as b,W as x,_ as S,b as ie,c as C,d as w,f as T,g as E,h as D,it as O,k as ae,l as k,nt as A,p as j,q as M,rt as N,u as P,w as oe,y as F,z as se}from"./index-BcEUSS3r.js";import{t as ce}from"./layout-QiuZ_k5v.js";var I=e(t(),1),L=n(),R=`text-[10px] font-medium tracking-widest uppercase text-muted-foreground`;function z(e){switch(e){case`added`:return s(`done`);case`changed`:return s(`doing`);case`fixed`:return s(`review`);case`removed`:return s(`blocked`);case`security`:return o(`error`);default:return s(`backlog`)}}function le(e,t){let n=null;for(let t of e){let e=/^v?(\d+)\.(\d+)\.(\d+)/.exec(t.version);if(!e)continue;let r=[Number(e[1]),Number(e[2]),Number(e[3])];(n?r[0]-n[0]||r[1]-n[1]||r[2]-n[2]:1)>0&&(n=r)}return n?t.some(e=>[`added`,`removed`,`deprecated`].includes(e.type))?`${n[0]}.${n[1]+1}.0`:`${n[0]}.${n[1]}.${n[2]+1}`:`0.1.0`}function B(e){return e instanceof Error?e.message:String(e)}function V({record:e,selected:t,onSelect:n}){let r=e.kind===`release`?`release`:e.type,i=e.kind===`release`?`var(--primary)`:z(e.type),a=e.kind===`release`?`${e.fragments.length} fragment${e.fragments.length===1?``:`s`} · ${e.date}`:e.area;return(0,L.jsx)(h,{asChild:!0,variant:`outline`,size:`sm`,children:(0,L.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,className:u(`flex-col flex-nowrap items-stretch gap-1 px-2.5 py-2 text-left shadow-xs`,t?`border-ring bg-accent`:`bg-card hover:border-ring`),children:[(0,L.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,L.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,L.jsx)(`span`,{className:`font-mono text-[10px]`,style:{color:i},children:r}),(0,L.jsx)(`span`,{className:`flex-1`}),(0,L.jsx)(`span`,{className:`max-w-[170px] truncate font-mono text-[10px] text-muted-foreground/70`,children:a})]}),(0,L.jsx)(`span`,{className:`text-sm leading-snug font-normal`,children:e.title})]})})}function H({label:e,records:t,selectedId:n,onSelect:r}){return t.length?(0,L.jsxs)(`div`,{role:`group`,"aria-label":e,className:`flex flex-col gap-1.5 pt-4`,children:[(0,L.jsxs)(`span`,{className:R,children:[e,` · `,t.length]}),t.map(e=>(0,L.jsx)(V,{record:e,selected:e.id===n,onSelect:()=>r(e.id)},e.id))]}):null}function U({id:e,title:t,relation:n,disabled:r,onOpen:i}){return(0,L.jsx)(h,{asChild:!0,variant:`outline`,size:`sm`,children:(0,L.jsxs)(`button`,{type:`button`,disabled:r,onClick:i,className:`flex-nowrap gap-2 bg-card px-2.5 py-1.5 text-left shadow-xs hover:border-ring disabled:pointer-events-none disabled:opacity-55`,children:[(0,L.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-muted-foreground`,children:e}),(0,L.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[12.5px]`,children:t}),n?(0,L.jsx)(A,{variant:`outline`,className:`shrink-0 font-mono text-[10px] font-normal text-muted-foreground`,children:n}):null]})})}function W({label:e,links:t,onOpen:n}){return t.length?(0,L.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,L.jsx)(`span`,{className:R,children:e}),t.map(t=>(0,L.jsx)(U,{id:t.id,title:t.title,relation:t.relation,disabled:t.disabled,onOpen:()=>n(t.id)},`${e}-${t.id}`))]}):null}function ue(e){return e.map(e=>({id:e.id,title:e.title||`Missing record`,relation:e.relation,disabled:!e.exists&&!e.title}))}function de({schema:e,areas:t,onClose:n,onCreated:r}){let[i,a]=(0,I.useState)({title:``,type:e.defaults.type,area:t[0]||`general`,visibility:e.defaults.visibility,body:``}),[o,s]=(0,I.useState)(!1),[c,u]=(0,I.useState)(``),f=(e,t)=>a(n=>({...n,[e]:t})),p=async()=>{s(!0);try{r((await M.createChange(i)).record)}catch(e){u(B(e))}finally{s(!1)}};return(0,L.jsx)(C,{open:!0,onOpenChange:e=>{e||n()},children:(0,L.jsxs)(k,{onOpenAutoFocus:e=>e.preventDefault(),children:[(0,L.jsxs)(T,{children:[(0,L.jsx)(j,{children:`New change fragment`}),(0,L.jsx)(P,{children:`Record one user- or operator-meaningful change.`})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`new-fragment-title`,children:`Title`}),(0,L.jsx)(d,{id:`new-fragment-title`,autoFocus:!0,required:!0,maxLength:120,value:i.title,onChange:e=>f(`title`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-3 gap-2.5`,children:[(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`new-fragment-type`,children:`Type`}),(0,L.jsx)(D,{id:`new-fragment-type`,value:i.type,onChange:e=>f(`type`,e.target.value),children:e.types.map(e=>(0,L.jsx)(E,{value:e,children:e},e))})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`new-fragment-area`,children:`Area`}),(0,L.jsx)(D,{id:`new-fragment-area`,value:i.area,onChange:e=>f(`area`,e.target.value),children:t.map(e=>(0,L.jsx)(E,{value:e,children:e},e))})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`new-fragment-visibility`,children:`Visibility`}),(0,L.jsx)(D,{id:`new-fragment-visibility`,value:i.visibility,onChange:e=>f(`visibility`,e.target.value),children:e.visibilities.map(e=>(0,L.jsx)(E,{value:e,children:e},e))})]})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`new-fragment-details`,children:`Details`}),(0,L.jsx)(g,{id:`new-fragment-details`,rows:5,value:i.body,onChange:e=>f(`body`,e.target.value)})]}),c?(0,L.jsx)(N,{variant:`destructive`,"aria-live":`polite`,children:(0,L.jsx)(O,{children:c})}):null,(0,L.jsxs)(w,{children:[(0,L.jsx)(l,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,L.jsx)(l,{type:`button`,disabled:o||!i.title.trim(),onClick:()=>void p(),children:o?`Saving…`:`Create fragment`})]})]})})}function fe({preview:e,suggestedVersion:t,onClose:n,onReleased:r}){let[i,a]=(0,I.useState)(t),[o,s]=(0,I.useState)(``),[c,u]=(0,I.useState)(!1),[f,p]=(0,I.useState)(``),m=async()=>{u(!0);try{await M.createRelease({version:i,title:o||void 0,fragmentIds:e.fragments.map(e=>e.id)}),r()}catch(e){p(B(e))}finally{u(!1)}};return(0,L.jsx)(C,{open:!0,onOpenChange:e=>{e||n()},children:(0,L.jsxs)(k,{className:`flex max-h-[85vh] flex-col sm:max-w-[640px]`,children:[(0,L.jsxs)(T,{children:[(0,L.jsx)(j,{children:`Release preparation`}),(0,L.jsxs)(P,{children:[e.fragments.length,` unreleased fragment`,e.fragments.length===1?``:`s`,` selected.`]})]}),(0,L.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-[150px_1fr] gap-2.5`,children:[(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`release-version`,children:`Version`}),(0,L.jsx)(d,{id:`release-version`,className:`font-mono`,placeholder:`2.4.0`,value:i,onChange:e=>a(e.target.value)})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`release-title`,children:`Release title`}),(0,L.jsx)(d,{id:`release-title`,placeholder:`Optional curated title`,value:o,onChange:e=>s(e.target.value)})]})]}),e.groups.map(e=>(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsxs)(`span`,{className:R,style:{color:z(e.type)},children:[e.type,` · `,e.fragments.length]}),e.fragments.map(e=>(0,L.jsxs)(`span`,{className:`flex items-baseline gap-2 text-[12.5px]`,children:[(0,L.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,L.jsx)(`span`,{className:`min-w-0 truncate`,children:e.title}),(0,L.jsx)(`span`,{className:`flex-1`}),(0,L.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground/70`,children:e.area})]},e.id))]},e.type)),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(`span`,{className:R,children:`release notes preview`}),(0,L.jsx)(`div`,{className:`max-h-[220px] overflow-y-auto rounded-md border bg-background px-3 py-1`,children:(0,L.jsx)(ie,{source:e.markdown||`No release notes to render.`})})]}),f?(0,L.jsx)(N,{variant:`destructive`,"aria-live":`polite`,children:(0,L.jsx)(O,{children:f})}):null]}),(0,L.jsxs)(w,{children:[(0,L.jsx)(l,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,L.jsx)(l,{type:`button`,disabled:c||!i.trim()||!e.fragments.length,onClick:()=>void m(),children:c?`Releasing…`:`Create release`})]})]})})}function pe({record:e,schema:t,areas:n,onSaved:r}){let[i,a]=(0,I.useState)({title:e.title,type:e.type,area:e.area,visibility:e.visibility}),[s,c]=(0,I.useState)(!1),[u,f]=(0,I.useState)(``),p=(e,t)=>a(n=>({...n,[e]:t})),m={};for(let t of[`title`,`type`,`area`,`visibility`])i[t]!==e[t]&&(m[t]=i[t]);let h=Object.keys(m).length>0,g=n.includes(e.area)?n:[e.area,...n],v=async()=>{c(!0);try{let t=await M.patchChange(e.id,m,e.revision);f(``),r(t.record)}catch(e){f(B(e))}finally{c(!1)}};return(0,L.jsxs)(ee,{className:`gap-2.5 rounded-lg py-3 shadow-xs`,children:[(0,L.jsx)(_,{className:`px-3`,children:(0,L.jsx)(y,{className:R,children:`edit fragment`})}),(0,L.jsxs)(b,{className:`flex flex-col gap-2.5 px-3`,children:[(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`edit-fragment-title`,children:`Title`}),(0,L.jsx)(d,{id:`edit-fragment-title`,maxLength:120,value:i.title,onChange:e=>p(`title`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-3 gap-2.5`,children:[(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`edit-fragment-type`,children:`Type`}),(0,L.jsx)(D,{id:`edit-fragment-type`,value:i.type,onChange:e=>p(`type`,e.target.value),children:t.types.map(e=>(0,L.jsx)(E,{value:e,children:e},e))})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`edit-fragment-area`,children:`Area`}),(0,L.jsx)(D,{id:`edit-fragment-area`,value:i.area,onChange:e=>p(`area`,e.target.value),children:g.map(e=>(0,L.jsx)(E,{value:e,children:e},e))})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`edit-fragment-visibility`,children:`Visibility`}),(0,L.jsx)(D,{id:`edit-fragment-visibility`,value:i.visibility,onChange:e=>p(`visibility`,e.target.value),children:t.visibilities.map(e=>(0,L.jsx)(E,{value:e,children:e},e))})]})]})]}),(0,L.jsxs)(x,{className:`gap-2.5 px-3`,children:[u?(0,L.jsx)(`span`,{className:`flex-1 text-xs`,style:{color:o(`error`)},"aria-live":`polite`,children:u}):(0,L.jsx)(`span`,{className:`flex-1`}),(0,L.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:s||!h||!i.title.trim(),onClick:()=>void v(),children:s?`Saving…`:`Save changes`})]})]})}function G({selectedId:e,onSelect:t,onOpenRecord:n,schema:s,areas:d,search:h,onSearchChange:g}){let _=oe(),[y,b]=(0,I.useState)([]),[x,S]=(0,I.useState)(``),[C,w]=(0,I.useState)(``),[T,E]=(0,I.useState)(!0),[D,k]=(0,I.useState)(``),[j,P]=(0,I.useState)(``),[F,R]=(0,I.useState)(!1),[V,U]=(0,I.useState)(null),[G,me]=(0,I.useState)(`public`),[K,q]=(0,I.useState)({content:``,error:``,loading:!0}),[he,ge]=(0,I.useState)(0),_e=()=>ge(e=>e+1);f(e=>{se(e,`/changelog/`)&&_e()}),(0,I.useEffect)(()=>{let e=!1,t=async()=>{E(!0);try{let t=await M.changelog(h.trim(),{state:x||void 0,visibility:C||void 0});if(e)return;b(t.records),k(``)}catch(t){e||k(B(t))}finally{e||E(!1)}},n=window.setTimeout(()=>void t(),h?180:0);return()=>{e=!0,window.clearTimeout(n)}},[h,x,C,he]),(0,I.useEffect)(()=>{let e=!1;return q(e=>({...e,loading:!0})),M.renderedChangelog(G).then(t=>{e||q({content:t.content,error:``,loading:!1})}).catch(t=>{e||q({content:``,error:B(t),loading:!1})}),()=>{e=!0}},[G,he]);let J=(0,I.useMemo)(()=>[...y].sort((e,t)=>{if(e.kind!==t.kind)return e.kind===`change`?-1:1;if(e.kind===`release`&&t.kind===`release`){let n=t.date.localeCompare(e.date);return n===0?t.id.localeCompare(e.id):n}return String(t.updated||``).localeCompare(String(e.updated||``))}),[y]),Y=(0,I.useMemo)(()=>new Map(y.map(e=>[e.id,e])),[y]),X=(0,I.useMemo)(()=>J.filter(e=>e.kind===`change`&&!e.released),[J]),ve=(0,I.useMemo)(()=>J.filter(e=>e.kind===`change`&&e.released),[J]),Z=(0,I.useMemo)(()=>J.filter(e=>e.kind===`release`),[J]),ye=(0,I.useMemo)(()=>le(Z,X),[Z,X]),Q=e?Y.get(e):void 0,$=e=>{if(Y.has(e)){t(e);return}if(/^(CHG|REL)-/.test(e)){S(``),w(``),t(e);return}n(e)},be=()=>{P(``),M.releasePreview().then(U).catch(e=>P(B(e)))},xe=Q?.issues.some(e=>e.severity===`error`)?`destructive`:`default`,Se=(0,L.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:_,title:_?p:void 0,onClick:()=>R(!0),children:[(0,L.jsx)(a,{"aria-hidden":`true`}),`New fragment`]});return(0,L.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:u(`w-full shrink-0 flex-col border-r lg:flex lg:w-[400px]`,Q?`hidden`:`flex`),children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-2.5 p-3.5 pb-0`,children:[(0,L.jsxs)(ee,{className:`flex-row items-center gap-2.5 border-primary bg-primary/10 p-3`,children:[(0,L.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,L.jsxs)(`span`,{className:`text-[13px] font-semibold`,children:[X.length,` unpublished fragment`,X.length===1?``:`s`]}),(0,L.jsxs)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground`,children:[`next: `,ye,` ·`,` `,s.releaseStrategy]})]}),(0,L.jsx)(l,{type:`button`,size:`sm`,className:`whitespace-nowrap`,disabled:_,title:_?p:void 0,onClick:be,children:`Prepare release`})]}),j?(0,L.jsx)(N,{variant:`destructive`,"aria-live":`polite`,children:(0,L.jsx)(O,{children:j})}):null,(0,L.jsxs)(v,{before:(0,L.jsx)(re,{scope:`records`,value:h,label:`Search history`,onChange:g}),children:[(0,L.jsx)(te,{label:`state`,value:x,options:[{value:`unreleased`},{value:`released`}],onChange:S}),(0,L.jsx)(te,{label:`visibility`,value:C,options:s.visibilities.map(e=>({value:e})),onChange:w})]})]}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3.5 pb-6 [mask-image:linear-gradient(to_bottom,black_calc(100%-24px),transparent)]`,children:T?(0,L.jsx)(`div`,{"aria-busy":`true`,className:`flex flex-col gap-2 pt-4`,children:Array.from({length:6},(e,t)=>(0,L.jsx)(`div`,{className:`h-[52px] animate-pulse rounded-md bg-muted`},t))}):D?(0,L.jsx)(N,{variant:`destructive`,className:`mt-4`,"aria-live":`polite`,children:(0,L.jsx)(O,{children:D})}):J.length?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(H,{label:`unpublished`,records:X,selectedId:e,onSelect:t}),(0,L.jsx)(H,{label:`releases`,records:Z,selectedId:e,onSelect:t}),(0,L.jsx)(H,{label:`published fragments`,records:ve,selectedId:e,onSelect:t})]}):(0,L.jsx)(m,{className:`mt-4 gap-1 p-4 md:p-4`,children:(0,L.jsx)(ae,{className:`text-xs`,children:`No history records match the filters.`})})})]}),(0,L.jsx)(`div`,{className:u(`min-w-0 flex-1 overflow-y-auto px-6 py-5 sm:px-8.5`,Q?`block`:`hidden lg:block`),children:(0,L.jsx)(`div`,{className:ce,children:Q?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(l,{type:`button`,variant:`ghost`,size:`sm`,className:`-ml-2 mb-2 lg:hidden`,onClick:()=>t(``),children:[(0,L.jsx)(i,{"aria-hidden":`true`}),`All history`]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 font-mono text-[11px]`,children:[(0,L.jsx)(`span`,{className:`whitespace-nowrap text-primary`,children:Q.id}),(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{className:`text-muted-foreground/70`,children:Q.kind}),(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),Q.kind===`change`?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{style:{color:z(Q.type)},children:Q.type}),(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:Q.area}),(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:Q.visibility}),(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{style:{color:c(Q.released?`released`:`unreleased`)},children:Q.released?`released`:`unreleased`}),Q.updated?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{className:`text-muted-foreground/70`,children:Q.updated})]}):null]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`text-primary`,children:Q.version}),(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:Q.date}),Q.commit?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{className:`text-muted-foreground/70`,children:Q.commit})]}):null,(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[Q.fragments.length,` fragment`,Q.fragments.length===1?``:`s`]})]}),(0,L.jsxs)(`span`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[Se,(0,L.jsx)(l,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Close record`,title:`Back to the derived changelog`,onClick:()=>t(``),children:(0,L.jsx)(r,{"aria-hidden":`true`})})]})]}),(0,L.jsx)(`h2`,{className:`mt-2.5 mb-1 text-[26px] leading-tight font-semibold tracking-tight [text-wrap:pretty]`,children:Q.title}),(0,L.jsx)(`div`,{className:`font-mono text-[10.5px] break-all text-muted-foreground/70`,children:Q.path}),Q.issues.length>0?(0,L.jsx)(N,{variant:xe,className:`mt-3.5`,children:(0,L.jsx)(O,{className:`w-full gap-1`,children:Q.issues.map(e=>(0,L.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,L.jsx)(`span`,{className:`shrink-0 font-mono text-[10.5px]`,style:{color:o(e.severity)},children:e.severity}),(0,L.jsx)(`span`,{children:e.message})]},`${e.code}-${e.message}`))})}):null,(0,L.jsx)(`div`,{className:`mt-4.5`,children:(0,L.jsx)(ie,{source:Q.body||`No additional notes.`,onOpen:$})}),(0,L.jsxs)(`div`,{className:`mt-5.5 flex flex-col gap-3.5`,children:[Q.kind===`change`?(0,L.jsx)(W,{label:`shipped in`,links:(Q.releaseIds||[]).map(e=>({id:e,title:Y.get(e)?.title||`Open release`,relation:`release`})),onOpen:$}):(0,L.jsx)(W,{label:`fragments · ${Q.fragments.length}`,links:Q.fragments.map(e=>{let t=Y.get(e);return{id:e,title:t?.title||`Open fragment`,relation:t?.kind===`change`?t.type:void 0}}),onOpen:$}),(0,L.jsx)(W,{label:`links to`,links:ue(Q.outgoing),onOpen:$}),(0,L.jsx)(W,{label:`backlinks`,links:ue(Q.incoming),onOpen:$})]}),Q.kind===`change`&&!_?(0,L.jsx)(`div`,{className:`mt-5.5`,children:(0,L.jsx)(pe,{record:Q,schema:s,areas:d,onSaved:e=>b(t=>t.map(t=>t.id===e.id?e:t))},`${Q.id}:${Q.revision}`)}):null]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-2 border-b pb-3`,children:[(0,L.jsx)(`span`,{className:`text-[13px] font-semibold`,children:`Derived changelog`}),(0,L.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:[`visibility `,G,` · CHANGELOG.md`]}),(0,L.jsxs)(`span`,{className:`ml-auto flex flex-wrap items-center gap-2.5`,children:[(0,L.jsx)(ne,{children:s.visibilities.map(e=>(0,L.jsx)(l,{type:`button`,size:`sm`,variant:G===e?`default`:`outline`,"aria-pressed":G===e,onClick:()=>me(e),children:e},e))}),(0,L.jsx)(A,{variant:`outline`,className:`rounded-md font-mono text-[10.5px] font-normal whitespace-nowrap text-muted-foreground`,children:`render --write`}),Se]})]}),K.error?(0,L.jsx)(N,{variant:`destructive`,className:`mt-4`,"aria-live":`polite`,children:(0,L.jsx)(O,{children:K.error})}):(0,L.jsx)(`pre`,{className:`mt-4 font-mono text-xs leading-[1.75] whitespace-pre-wrap text-muted-foreground`,"aria-busy":K.loading||void 0,children:K.loading&&!K.content?`Rendering…`:K.content||`Nothing to render yet — create the first change fragment.`})]})})}),F?(0,L.jsx)(de,{schema:s,areas:d,onClose:()=>R(!1),onCreated:e=>{R(!1),b(t=>[e,...t]),t(e.id)}}):null,V?(0,L.jsx)(fe,{preview:V,suggestedVersion:ye,onClose:()=>U(null),onReleased:()=>{U(null),_e()}}):null]})}export{G as HistoryView};

Sorry, the diff of this file is too big to display

import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{et as r,mt as i,nt as a,tt as o}from"./ui-primitives-DRENhlck.js";import{i as s,r as c,s as l,u}from"./theme-CcOVK72d.js";import{$ as d,B as f,C as p,D as m,E as h,F as g,G as _,H as v,I as y,L as b,P as x,T as S,U as C,_ as w,b as T,c as E,d as D,f as O,g as k,h as A,it as j,k as M,l as N,nt as P,p as F,q as I,rt as L,w as R,y as z,z as B}from"./index-BcEUSS3r.js";var V=e(t(),1),H=n(),U=[`low`,`medium`,`high`],W=[`critical`,`high`,`medium`,`low`],G=`[mask-image:linear-gradient(to_bottom,black_calc(100%_-_24px),transparent)]`;function ee(e){return e&&e[0].toUpperCase()+e.slice(1)}function K(e,t){return`${e} ${t}${e===1?``:`s`}`}function q(e){return{category:e===`learnings`||e===`decisions`,confidence:e===`learnings`,severity:e===`incidents`,expires:e===`context`,review_after:e===`context`}}function J(e){let t=[];switch(e.collection){case`learnings`:t.push(e.confidence,e.category,e.occurrences==null?null:`${e.occurrences}×`);break;case`decisions`:e.superseded_by?.length?t.push(`superseded by ${e.superseded_by.join(`, `)}`):e.supersedes?.length?t.push(`supersedes ${e.supersedes.join(`, `)}`):t.push(e.category);break;case`incidents`:t.push(e.severity,e.corrective_actions?.length?K(e.corrective_actions.length,`corrective action`):null);break;case`conventions`:t.push(e.owners?.length?e.owners.join(`, `):`no owner`);break;case`context`:t.push(e.expires?`expires ${e.expires}`:null,e.review_after?`review after ${e.review_after}`:null);break;default:t.push(e.category,e.severity)}return t.filter(Boolean).join(` · `)}function Y({id:e,label:t,children:n}){return(0,H.jsxs)(w,{className:`gap-1.5 [&_[data-slot=native-select-wrapper]]:w-full`,children:[(0,H.jsx)(z,{htmlFor:e,children:t}),n]})}function te({record:e,selected:t,onSelect:n}){let r=J(e),i=e.lifecycleIssues?.length||0;return(0,H.jsx)(h,{asChild:!0,variant:`outline`,size:`sm`,className:`w-full flex-none flex-col items-stretch gap-1 rounded-lg bg-background px-2.5 py-2 text-left shadow-xs hover:border-ring aria-[current=true]:border-ring aria-[current=true]:bg-accent`,children:(0,H.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,children:[(0,H.jsxs)(`span`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,H.jsxs)(P,{variant:`outline`,className:`h-[18px] gap-1 rounded-md px-1.5 font-mono text-[10px] font-medium`,children:[(0,H.jsx)(`span`,{className:`size-[5px] shrink-0 rounded-full`,style:{backgroundColor:c(e.status)},"aria-hidden":`true`}),e.status]})]}),(0,H.jsx)(`span`,{className:`text-[13px] font-medium leading-snug`,children:e.title}),r||i?(0,H.jsxs)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground`,children:[r,r&&i?` · `:null,i?(0,H.jsx)(`span`,{style:{color:s(`warning`)},children:K(i,`lifecycle warning`)}):null]}):null]})})}function X({issues:e,kind:t}){return e.length?(0,H.jsx)(H.Fragment,{children:e.map(e=>(0,H.jsx)(L,{variant:e.severity===`error`?`destructive`:`default`,className:`px-3 py-2`,children:(0,H.jsxs)(j,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-0.5`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[10.5px]`,style:{color:s(e.severity)},children:t===`lifecycle`?`lifecycle`:e.severity}),(0,H.jsx)(`span`,{children:e.message})]})},`${t}-${e.code}-${e.message}`))}):null}function Z({label:e,links:t,onOpen:n}){return t.length?(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:e}),t.map(t=>{let r=!t.exists&&!t.title;return(0,H.jsx)(h,{asChild:!0,variant:`outline`,size:`sm`,className:`gap-2 rounded-lg px-2.5 py-2 text-left hover:border-ring disabled:pointer-events-none disabled:opacity-50`,children:(0,H.jsxs)(`button`,{type:`button`,disabled:r,onClick:()=>n(t.id),children:[(0,H.jsx)(`span`,{className:`w-[78px] shrink-0 truncate font-mono text-[11px] font-medium`,children:t.id}),(0,H.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-muted-foreground`,children:t.title||`Missing record`}),(t.relations??[t.relation||t.kind]).filter(Boolean).map(e=>(0,H.jsx)(P,{variant:`secondary`,className:`h-[18px] rounded-md px-1.5 font-mono text-[10px] font-medium`,children:e},e))]})},`${e}-${t.id}`)})]}):null}function Q({message:e}){return e?(0,H.jsx)(L,{variant:`destructive`,className:`px-3 py-2`,children:(0,H.jsx)(j,{children:e})}):null}function ne({schema:e,initialCollection:t,onClose:n,onCreated:r}){let i=e.collections.find(e=>e.id===t)||e.collections[0],[a,o]=(0,V.useState)({collection:i?.id||`learnings`,status:i?.statuses[0]||`active`,title:``,category:``,confidence:``,severity:``,expires:``,body:``}),[s,c]=(0,V.useState)(!1),[u,f]=(0,V.useState)(``),p=e.collections.find(e=>e.id===a.collection),m=q(a.collection),h=(e,t)=>o(n=>({...n,[e]:t})),_=t=>{let n=e.collections.find(e=>e.id===t);o(e=>({...e,collection:t,status:n?.statuses[0]||`active`}))},v=async()=>{c(!0);try{r((await I.createMemory({collection:a.collection,title:a.title,status:a.status,body:a.body,category:a.category||void 0,confidence:a.confidence||void 0,severity:a.severity||void 0,expires:a.expires||void 0})).record)}catch(e){f(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,H.jsx)(E,{open:!0,onOpenChange:e=>{e||n()},children:(0,H.jsxs)(N,{className:`sm:max-w-[520px]`,"aria-describedby":void 0,children:[(0,H.jsx)(O,{children:(0,H.jsxs)(F,{children:[`New `,p?.singular||`record`]})}),(0,H.jsxs)(`div`,{className:`-m-1 flex max-h-[65vh] flex-col gap-3 overflow-y-auto p-1`,children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,H.jsx)(Y,{id:`memory-create-collection`,label:`Collection`,children:(0,H.jsx)(A,{id:`memory-create-collection`,value:a.collection,onChange:e=>_(e.target.value),children:e.collections.map(e=>(0,H.jsx)(k,{value:e.id,children:e.id},e.id))})}),(0,H.jsx)(Y,{id:`memory-create-status`,label:`Status`,children:(0,H.jsx)(A,{id:`memory-create-status`,value:a.status,onChange:e=>h(`status`,e.target.value),children:(p?.statuses||[]).map(e=>(0,H.jsx)(k,{value:e,children:e},e))})})]}),(0,H.jsx)(Y,{id:`memory-create-title`,label:`Title`,children:(0,H.jsx)(d,{id:`memory-create-title`,autoFocus:!0,required:!0,maxLength:120,value:a.title,onChange:e=>h(`title`,e.target.value)})}),m.category||m.confidence||m.severity||m.expires?(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[m.category?(0,H.jsx)(Y,{id:`memory-create-category`,label:`Category`,children:(0,H.jsx)(d,{id:`memory-create-category`,value:a.category,onChange:e=>h(`category`,e.target.value)})}):null,m.confidence?(0,H.jsx)(Y,{id:`memory-create-confidence`,label:`Confidence`,children:(0,H.jsxs)(A,{id:`memory-create-confidence`,value:a.confidence,onChange:e=>h(`confidence`,e.target.value),children:[(0,H.jsx)(k,{value:``,children:`not set`}),U.map(e=>(0,H.jsx)(k,{value:e,children:e},e))]})}):null,m.severity?(0,H.jsx)(Y,{id:`memory-create-severity`,label:`Severity`,children:(0,H.jsxs)(A,{id:`memory-create-severity`,value:a.severity,onChange:e=>h(`severity`,e.target.value),children:[(0,H.jsx)(k,{value:``,children:`not set`}),W.map(e=>(0,H.jsx)(k,{value:e,children:e},e))]})}):null,m.expires?(0,H.jsx)(Y,{id:`memory-create-expires`,label:`Expires`,children:(0,H.jsx)(d,{id:`memory-create-expires`,type:`date`,value:a.expires,onChange:e=>h(`expires`,e.target.value)})}):null]}):null,(0,H.jsx)(Y,{id:`memory-create-body`,label:`Details`,children:(0,H.jsx)(g,{id:`memory-create-body`,rows:8,value:a.body,onChange:e=>h(`body`,e.target.value)})}),(0,H.jsx)(Q,{message:u})]}),(0,H.jsxs)(D,{children:[(0,H.jsx)(l,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(l,{type:`button`,disabled:s||!a.title.trim(),onClick:()=>void v(),children:s?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(S,{"aria-hidden":`true`}),`Saving…`]}):`Create record`})]})]})})}function re({record:e,statuses:t,onClose:n,onUpdated:r}){let i=q(e.collection),[a,o]=(0,V.useState)({title:e.title,status:e.status,category:e.category||``,confidence:e.confidence||``,severity:e.severity||``,expires:e.expires||``,review_after:e.review_after||``,body:e.body}),[s,c]=(0,V.useState)(!1),[u,f]=(0,V.useState)(``),p=(e,t)=>o(n=>({...n,[e]:t})),m=async()=>{let t={};a.title.trim()&&a.title!==e.title&&(t.title=a.title),a.status!==e.status&&(t.status=a.status),a.body!==e.body&&(t.body=a.body);for(let n of[`category`,`confidence`,`severity`,`expires`,`review_after`])a[n]!==(e[n]||``)&&(t[n]=a[n]||null);if(!Object.keys(t).length){n();return}c(!0);try{r((await I.patchMemory(e.id,t,e.revision)).record),n()}catch(e){f(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,H.jsx)(E,{open:!0,onOpenChange:e=>{e||n()},children:(0,H.jsxs)(N,{className:`sm:max-w-[520px]`,"aria-describedby":void 0,children:[(0,H.jsx)(O,{children:(0,H.jsxs)(F,{children:[`Edit `,e.id]})}),(0,H.jsxs)(`div`,{className:`-m-1 flex max-h-[65vh] flex-col gap-3 overflow-y-auto p-1`,children:[(0,H.jsx)(Y,{id:`memory-edit-title`,label:`Title`,children:(0,H.jsx)(d,{id:`memory-edit-title`,autoFocus:!0,required:!0,maxLength:120,value:a.title,onChange:e=>p(`title`,e.target.value)})}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,H.jsx)(Y,{id:`memory-edit-status`,label:`Status`,children:(0,H.jsx)(A,{id:`memory-edit-status`,value:a.status,onChange:e=>p(`status`,e.target.value),children:(t.includes(a.status)?t:[a.status,...t]).map(e=>(0,H.jsx)(k,{value:e,children:e},e))})}),i.category?(0,H.jsx)(Y,{id:`memory-edit-category`,label:`Category`,children:(0,H.jsx)(d,{id:`memory-edit-category`,value:a.category,onChange:e=>p(`category`,e.target.value)})}):null,i.confidence?(0,H.jsx)(Y,{id:`memory-edit-confidence`,label:`Confidence`,children:(0,H.jsxs)(A,{id:`memory-edit-confidence`,value:a.confidence,onChange:e=>p(`confidence`,e.target.value),children:[(0,H.jsx)(k,{value:``,children:`not set`}),U.map(e=>(0,H.jsx)(k,{value:e,children:e},e))]})}):null,i.severity?(0,H.jsx)(Y,{id:`memory-edit-severity`,label:`Severity`,children:(0,H.jsxs)(A,{id:`memory-edit-severity`,value:a.severity,onChange:e=>p(`severity`,e.target.value),children:[(0,H.jsx)(k,{value:``,children:`not set`}),W.map(e=>(0,H.jsx)(k,{value:e,children:e},e))]})}):null,i.expires?(0,H.jsx)(Y,{id:`memory-edit-expires`,label:`Expires`,children:(0,H.jsx)(d,{id:`memory-edit-expires`,type:`date`,value:a.expires,onChange:e=>p(`expires`,e.target.value)})}):null,i.review_after?(0,H.jsx)(Y,{id:`memory-edit-review-after`,label:`Review after`,children:(0,H.jsx)(d,{id:`memory-edit-review-after`,type:`date`,value:a.review_after,onChange:e=>p(`review_after`,e.target.value)})}):null]}),(0,H.jsx)(Y,{id:`memory-edit-body`,label:`Details`,children:(0,H.jsx)(g,{id:`memory-edit-body`,rows:10,value:a.body,onChange:e=>p(`body`,e.target.value)})}),(0,H.jsx)(Q,{message:u})]}),(0,H.jsxs)(D,{children:[(0,H.jsx)(l,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(l,{type:`button`,disabled:s||!a.title.trim(),onClick:()=>void m(),children:s?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(S,{"aria-hidden":`true`}),`Saving…`]}):`Save changes`})]})]})})}function ie({record:e,mode:t,onClose:n,onUpdated:r}){let[i,a]=(0,V.useState)(``),[o,s]=(0,V.useState)(!1),[c,u]=(0,V.useState)(``),f=async()=>{s(!0);try{r((t===`graduate`?await I.graduateMemory(e.id,i.split(`,`).map(e=>e.trim()).filter(Boolean),e.revision):await I.supersedeMemory(e.id,i.trim(),e.revision)).record),n()}catch(e){u(e instanceof Error?e.message:String(e))}finally{s(!1)}};return(0,H.jsx)(E,{open:!0,onOpenChange:e=>{e||n()},children:(0,H.jsxs)(N,{className:`sm:max-w-[420px]`,"aria-describedby":void 0,children:[(0,H.jsx)(O,{children:(0,H.jsxs)(F,{children:[t===`graduate`?`Graduate`:`Supersede`,` `,e.id]})}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,H.jsx)(Y,{id:`memory-lifecycle-target`,label:t===`graduate`?`Target IDs`:`Replacement ID`,children:(0,H.jsx)(d,{id:`memory-lifecycle-target`,autoFocus:!0,placeholder:t===`graduate`?`CONV-0001, DOC-0004`:`ADR-0009`,value:i,onChange:e=>a(e.target.value)})}),(0,H.jsx)(Q,{message:c})]}),(0,H.jsxs)(D,{children:[(0,H.jsx)(l,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(l,{type:`button`,disabled:o||!i.trim(),onClick:()=>void f(),children:o?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(S,{"aria-hidden":`true`}),`Saving…`]}):`Apply`})]})]})})}function ae({record:e,statuses:t,onOpenRelation:n,onOpenRecord:o,onUpdated:u,onDialogOpenChange:d}){let f=R(),[m,h]=(0,V.useState)(!1),[g,_]=(0,V.useState)(``),v=m||!!g;(0,V.useEffect)(()=>{d?.(v)},[v,d]);let y=e.collection===`learnings`&&e.status!==`graduated`,b=[`learnings`,`decisions`,`conventions`].includes(e.collection),x=[[`status`,e.status,c(e.status)]];return e.category&&x.push([`category`,e.category]),e.confidence&&x.push([`confidence`,e.confidence]),e.severity&&x.push([`severity`,e.severity,s(e.severity)]),e.occurrences!=null&&x.push([`occurrences`,String(e.occurrences)]),e.expires&&x.push([`expires`,e.expires]),e.review_after&&x.push([`review after`,e.review_after]),e.started_at&&x.push([`started`,e.started_at]),e.resolved_at&&x.push([`resolved`,e.resolved_at]),e.graduated_to?.length&&x.push([`graduated to`,e.graduated_to.join(`, `)]),e.superseded_by?.length&&x.push([`superseded by`,e.superseded_by.join(`, `)]),e.owners?.length&&x.push([`owners`,e.owners.join(`, `)]),x.push([`updated`,e.updated||`—`]),(0,H.jsxs)(`aside`,{"aria-label":`Memory record`,className:`flex min-h-0 flex-col overflow-hidden border-l bg-background`,children:[(0,H.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center gap-2 border-b px-3.5`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,H.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground/60`,children:`·`}),(0,H.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.collection}),(0,H.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground/60`,children:`·`}),(0,H.jsx)(`span`,{className:`font-mono text-[11px]`,style:{color:c(e.status)},children:e.status})]}),(0,H.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto p-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(`h2`,{className:`m-0 text-[17px] font-semibold leading-[1.3] tracking-[-0.01em] [text-wrap:pretty]`,children:e.title}),e.path?(0,H.jsx)(`span`,{className:`break-all font-mono text-[10.5px] text-muted-foreground`,children:e.path}):null]}),(0,H.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-2`,children:x.map(([e,t,n])=>(0,H.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,H.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:e}),(0,H.jsx)(`span`,{className:`text-sm`,style:n?{color:n}:void 0,children:t})]},e))}),(0,H.jsx)(X,{issues:e.issues,kind:`validation`}),(0,H.jsx)(X,{issues:e.lifecycleIssues||[],kind:`lifecycle`}),(0,H.jsx)(T,{className:`[--typeset-size:0.875rem]`,source:e.body||`No details recorded.`,onOpen:o}),(0,H.jsx)(Z,{label:`Links to`,links:e.outgoing,onOpen:n}),(0,H.jsx)(Z,{label:`Backlinks`,links:e.incoming,onOpen:n}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:f,title:f?p:void 0,onClick:()=>h(!0),children:[(0,H.jsx)(a,{"aria-hidden":`true`}),`Edit`]}),y?(0,H.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:f,title:f?p:void 0,onClick:()=>_(`graduate`),children:[(0,H.jsx)(i,{"aria-hidden":`true`}),`Graduate`]}):null,b?(0,H.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:f,title:f?p:void 0,onClick:()=>_(`supersede`),children:[(0,H.jsx)(r,{"aria-hidden":`true`}),`Supersede`]}):null]})]}),m?(0,H.jsx)(re,{record:e,statuses:t,onClose:()=>h(!1),onUpdated:u}):null,g?(0,H.jsx)(ie,{record:e,mode:g,onClose:()=>_(``),onUpdated:u}):null]})}function $(e,t){return e.find(e=>e.id===t)?.statuses||[]}function oe({id:e,schema:t,onSelect:n,onOpenRecord:r,onDialogOpenChange:i,onChanged:a}){let[o,s]=(0,V.useState)(null),[c,l]=(0,V.useState)(``);return(0,V.useEffect)(()=>{let t=!0;return s(null),l(``),I.record(e).then(e=>{t&&s(e.record)}).catch(e=>{t&&l(e.message)}),()=>{t=!1}},[e]),c?(0,H.jsx)(`div`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:c}):o?(0,H.jsx)(ae,{record:o,statuses:$(t.collections,o.collection),onOpenRelation:n,onOpenRecord:r,onUpdated:e=>{s(e),a?.()},onDialogOpenChange:i},o.id):(0,H.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground`,children:[(0,H.jsx)(S,{}),` Reading `,e,`…`]})}function se({selectedId:e,onSelect:t,onOpenRecord:n,schema:r,search:i,onSearchChange:a}){let s=R(),[d,h]=(0,V.useState)([]),[g,w]=(0,V.useState)(``),[T,E]=(0,V.useState)(``),[D,O]=(0,V.useState)(!0),[k,A]=(0,V.useState)(``),[N,F]=(0,V.useState)(null),z=(0,V.useRef)(0),U=(0,V.useCallback)(e=>{z.current=performance.now(),t(e)},[t]),[W,q]=(0,V.useState)(0);f(e=>{B(e,`/memory/`)&&q(e=>e+1)}),(0,V.useEffect)(()=>{let e=async()=>{O(!0);try{let e=await I.memory(i.trim(),{collection:g||void 0,status:T||void 0});h(e.records),A(``)}catch(e){A(e instanceof Error?e.message:String(e))}finally{O(!1)}},t=window.setTimeout(()=>void e(),i?180:0);return()=>window.clearTimeout(t)},[i,g,T,W]);let J=(0,V.useMemo)(()=>[...d].sort((e,t)=>String(t.updated||``).localeCompare(String(e.updated||``))||e.title.localeCompare(t.title)),[d]),Y=(0,V.useMemo)(()=>{let e=r.collections.filter(e=>!g||e.id===g).map(e=>({schema:e,records:J.filter(t=>t.collection===e.id)})),t=new Set(r.collections.map(e=>e.id)),n=J.filter(e=>!t.has(e.collection));return n.length&&e.push({schema:{id:`other`,singular:`record`,idPrefix:`?`,statuses:[]},records:n}),e},[r.collections,J,g]);J.find(t=>t.id===e);let X=g?$(r.collections,g):[...new Set(r.collections.flatMap(e=>e.statuses))];return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(y,{gutter:`3.5`,className:`pt-3.5`,before:(0,H.jsx)(x,{scope:`records`,value:i,label:`Search workfile memory`,onChange:a}),after:(0,H.jsx)(`span`,{className:`flex shrink-0 items-center gap-1.5 whitespace-nowrap font-mono text-[11px] text-muted-foreground`,children:D?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(S,{"aria-hidden":`true`,className:`size-3`}),`loading…`]}):K(d.length,`record`)}),children:[(0,H.jsx)(b,{label:`collection`,value:g,options:r.collections.map(e=>({value:e.id})),onChange:e=>{w(e),E(``)}}),(0,H.jsx)(b,{label:`status`,value:T,options:X.map(e=>({value:e,color:c(e)})),onChange:E})]}),k?(0,H.jsx)(L,{variant:`destructive`,className:`mx-3.5 mt-3 w-auto px-3 py-2`,children:(0,H.jsxs)(j,{children:[`Memory could not be loaded: `,k]})}):null,(0,H.jsx)(`div`,{className:`flex min-h-0 flex-1 gap-3 overflow-hidden p-3.5`,children:(0,H.jsx)(`div`,{className:`flex min-h-0 flex-1 gap-3 overflow-x-auto`,children:Y.map(t=>(0,H.jsxs)(v,{className:`w-[272px] flex-none gap-0 overflow-hidden rounded-xl py-0 [--card-spacing:--spacing(2)]`,children:[(0,H.jsxs)(_,{className:`flex flex-row items-center gap-2 border-b px-3 py-2`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[11px] font-medium text-primary`,children:t.schema.idPrefix}),(0,H.jsx)(`span`,{className:`flex-1 text-[12.5px] font-semibold`,children:ee(t.schema.singular)}),(0,H.jsx)(P,{variant:`secondary`,className:`h-5 px-1.5 font-mono text-[11px] font-normal`,children:t.records.length}),t.schema.id===`other`?null:(0,H.jsx)(l,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`New ${t.schema.singular}`,disabled:s,title:s?p:void 0,onClick:()=>F(t.schema.id),children:(0,H.jsx)(o,{"aria-hidden":`true`})})]}),(0,H.jsxs)(C,{className:u(`flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto p-2.5`,G),children:[t.records.map(t=>(0,H.jsx)(te,{record:t,selected:t.id===e,onSelect:()=>U(t.id)},t.id)),!t.records.length&&!D?(0,H.jsx)(m,{className:`gap-1 border border-dashed p-4 md:p-6`,children:(0,H.jsx)(M,{className:`font-mono text-xs`,children:`no records`})}):null]})]},t.schema.id))})}),N===null?null:(0,H.jsx)(ne,{schema:r,initialCollection:N,onClose:()=>F(null),onCreated:e=>{F(null),h(t=>[e,...t]),t(e.id)}})]})}export{oe as MemoryPanel,se as MemoryView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{$ as r,Mt as i,it as a,lt as o}from"./ui-primitives-DRENhlck.js";import{n as s,o as c,s as l,u}from"./theme-CcOVK72d.js";import{A as d,D as f,M as p,O as m,a as h,b as g,j as _,k as v,tt as y,w as b}from"./index-BcEUSS3r.js";import{t as x}from"./layout-QiuZ_k5v.js";import{t as S}from"./progress-CzHcd1lF.js";var C=e(t(),1),w=n(),T=[{key:`N`,label:`Move to next`,status:`next`},{key:`D`,label:`Defer`,status:`deferred`},{key:`X`,label:`Discard`,status:`discarded`}];function E({tasks:e,repoRoot:t,repoUrl:n,onPatch:E,onOpen:D}){let O=b(),[k,A]=(0,C.useState)(()=>new Set),[j,M]=(0,C.useState)(0),N=(0,C.useMemo)(()=>e.filter(e=>!k.has(e.id)),[k,e]),P=N[j]||N[0],F=e.length;(0,C.useEffect)(()=>{j>=N.length&&M(Math.max(0,N.length-1))},[j,N.length]);let I=(0,C.useCallback)(async(e,t=!0)=>{if(P){try{await E(P.id,e)}catch{return}t&&(A(e=>new Set(e).add(P.id)),M(e=>Math.min(e,Math.max(0,N.length-2))))}},[E,N.length,P]);(0,C.useEffect)(()=>{if(O)return;let e=e=>{if(e.ctrlKey||e.metaKey||e.altKey)return;let t=e.target;if([`INPUT`,`SELECT`,`TEXTAREA`].includes(t.tagName)||t.isContentEditable)return;let n=e.key.toUpperCase();if(n===`J`||e.key===`ArrowDown`)e.preventDefault(),M(e=>Math.min(N.length-1,e+1));else if(n===`K`||e.key===`ArrowUp`)e.preventDefault(),M(e=>Math.max(0,e-1));else if(/^[1-4]$/.test(n))e.preventDefault(),I({priority:h[Number(n)-1]},!1);else{let t=T.find(e=>e.key===n);t&&(e.preventDefault(),I({status:t.status}))}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[I,N.length,O]);let L=e=>n?`${n.replace(/\/+$/,``)}/blob/main/${e}`:`vscode://file${t}/${e}`;return O?(0,w.jsx)(f,{className:`gap-3 p-10`,children:(0,w.jsxs)(d,{children:[(0,w.jsx)(_,{children:(0,w.jsx)(o,{"aria-hidden":`true`,size:20})}),(0,w.jsx)(p,{className:`text-sm`,children:`Triage needs a writable workspace`}),(0,w.jsx)(v,{className:`text-[12.5px]`,children:`This board is served read-only, and every action here assigns a status or a priority.`})]})}):P?(0,w.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-2 border-b bg-card px-3.5 py-2.5`,children:[(0,w.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-64 items-center gap-2.5`,children:[(0,w.jsx)(S,{value:F?k.size/F*100:0,className:`min-w-16 max-w-[340px] flex-1`}),(0,w.jsxs)(`span`,{className:`shrink-0 font-mono text-[11px] text-muted-foreground`,children:[k.size,` of `,F,` processed`]})]}),(0,w.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2.5`,children:[(0,w.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:j===0,onClick:()=>M(e=>Math.max(0,e-1)),children:[(0,w.jsx)(y,{className:`max-sm:hidden`,children:`K`}),`Previous`]}),(0,w.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground tabular-nums`,children:[j+1,` / `,N.length]}),(0,w.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:j>=N.length-1,onClick:()=>M(e=>Math.min(N.length-1,e+1)),children:[(0,w.jsx)(y,{className:`max-sm:hidden`,children:`J`}),`Next`]}),(0,w.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,title:`Open full card`,"aria-label":`Open full card`,className:`max-sm:size-7 max-sm:px-0`,onClick:()=>D(P.id),children:[(0,w.jsx)(a,{"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`max-sm:hidden`,children:`Open full card`})]})]})]}),(0,w.jsxs)(`div`,{className:u(x,`px-6 py-7 sm:px-8`),children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2 font-mono text-[11px] text-muted-foreground`,children:[(0,w.jsx)(`span`,{children:P.id}),(0,w.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,w.jsx)(`span`,{style:{color:c(P.status)},children:P.status}),(0,w.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,w.jsx)(`span`,{children:P.area}),(0,w.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,w.jsx)(`span`,{children:P.type})]}),(0,w.jsx)(`h2`,{className:`mt-3 mb-1 text-[26px] leading-[1.2] font-semibold tracking-tight [text-wrap:pretty]`,children:P.title}),P.file?(0,w.jsx)(`a`,{className:`font-mono text-[11px] text-muted-foreground/70 underline underline-offset-[3px]`,href:L(P.file),target:n?`_blank`:void 0,rel:n?`noreferrer`:void 0,children:P.file}):null,P.source?(0,w.jsxs)(`span`,{className:`mt-[3px] block font-mono text-[11px] text-muted-foreground/70`,children:[`source`,` `,(0,w.jsx)(`a`,{className:`font-mono underline underline-offset-[3px]`,href:L(P.source),target:n?`_blank`:void 0,rel:n?`noreferrer`:void 0,children:P.source})]}):null,(0,w.jsx)(`div`,{className:`mt-[22px]`,children:(0,w.jsx)(g,{source:P.body,onOpen:D})}),(0,w.jsxs)(`div`,{className:`mt-[30px] flex flex-wrap gap-2 border-t pt-[18px]`,children:[h.map((e,t)=>(0,w.jsxs)(l,{type:`button`,variant:`outline`,size:`lg`,"aria-pressed":P.priority===e,style:P.priority===e?{borderColor:s(e)}:void 0,onClick:()=>void I({priority:e},!1),children:[(0,w.jsx)(y,{children:t+1}),(0,w.jsx)(`span`,{style:{color:s(e)},children:e})]},e)),T.map(e=>(0,w.jsxs)(l,{type:`button`,variant:`outline`,size:`lg`,onClick:()=>void I({status:e.status}),children:[(0,w.jsx)(y,{children:e.key}),(0,w.jsx)(`span`,{style:{color:c(e.status)},children:e.label})]},e.key))]}),(0,w.jsx)(`span`,{className:`mt-3.5 block text-xs text-muted-foreground`,children:`Every action writes the card's frontmatter to disk immediately. Shortcuts work while focus is outside a form.`})]})]}):(0,w.jsxs)(f,{className:`gap-3 p-10`,children:[(0,w.jsxs)(d,{children:[(0,w.jsx)(_,{children:(0,w.jsx)(i,{"aria-hidden":`true`,size:20,style:{color:c(`done`)}})}),(0,w.jsx)(p,{className:`text-sm`,children:`Queue clear`}),(0,w.jsxs)(v,{className:`text-[12.5px]`,children:[`You processed `,k.size.toLocaleString(),` cards.`]})]}),(0,w.jsx)(m,{children:(0,w.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{A(new Set),M(0)},children:[(0,w.jsx)(r,{"aria-hidden":`true`}),`Start again`]})})]})}export{E as TriageView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{bt as r,ut as i}from"./ui-primitives-DRENhlck.js";import{r as a,s as o,u as s}from"./theme-CcOVK72d.js";import{I as c,nt as l,q as u}from"./index-BcEUSS3r.js";var d=e(t(),1),f=[{id:`parent`,label:`parent`,declared:!0},{id:`depends`,label:`depends`,declared:!0},{id:`origin`,label:`origin`,declared:!0},{id:`supersedes`,label:`supersedes`,declared:!0},{id:`superseded_by`,label:`superseded by`,declared:!0},{id:`graduated_to`,label:`graduated to`,declared:!0},{id:`corrective_actions`,label:`corrective`,declared:!0},{id:`cards`,label:`cards`,declared:!0},{id:`decisions`,label:`decisions`,declared:!0},{id:`fragments`,label:`fragments`,declared:!0},{id:`related`,label:`related`,declared:!0},{id:`source`,label:`source`,declared:!0},{id:`wikilink`,label:`wiki link`,declared:!1},{id:`markdown`,label:`md link`,declared:!1},{id:`mention`,label:`mention`,declared:!1}],p=new Set(f.filter(e=>e.declared).map(e=>e.id)),m=[{id:`card`,label:`Cards`},{id:`memory`,label:`Memory`},{id:`doc`,label:`Docs`},{id:`change`,label:`Changes`},{id:`release`,label:`Releases`}],h=f.map(e=>e.id).filter(e=>e!==`mention`),g=[`card`,`memory`,`doc`];function _(e,t){return e.kind!==`card`||!(t.status&&e.status!==t.status||t.area&&e.area!==t.area||t.type&&e.recordType!==t.type||t.priority&&e.priority!==t.priority||t.milestone&&e.milestone!==t.milestone)}function ee(e,t){let n=Object.values(t.record??{}).some(Boolean),r=e.filter(e=>t.kinds.has(e.kind)&&_(e,t.record??{}));if(n){let e=new Set(r.filter(e=>e.kind===`card`).map(e=>e.id)),n=new Set;for(let i of v(r,t.relations).links)e.has(i.from)&&n.add(i.to),e.has(i.to)&&n.add(i.from);r=r.filter(e=>e.kind===`card`||n.has(e.id))}let{links:i,degree:a}=v(r,t.relations),o=t.hideIsolated?r.filter(e=>a.get(e.id)):r;return{records:o,links:i,degree:a,isolated:r.length-o.length}}function v(e,t){let n=new Set(e.map(e=>e.id)),r=[],i=new Map;for(let a of e)for(let e of a.edges){if(!n.has(e.to)||e.to===a.id)continue;let o=e.rel.filter(e=>t.has(e));o.length&&(r.push({from:a.id,to:e.to,relations:o,declared:o.some(e=>p.has(e))}),i.set(a.id,(i.get(a.id)||0)+1),i.set(e.to,(i.get(e.to)||0)+1))}return{links:r,degree:i}}function y(e,t){let n=e*2.399963,r=18*Math.sqrt(e)+(t>200?40:0);return{x:Math.cos(n)*r,y:Math.sin(n)*r}}var b=9e3,x=.012,S=130,C=6e-4,w=.82;function te(e,t,n){for(let t=0;t<e.length;t+=1){let r=e[t];for(let i=t+1;i<e.length;i+=1){let a=e[i],o=r.x-a.x,s=r.y-a.y,c=o*o+s*s;c<1&&(o=(t-i)*.5,s=.5,c=o*o+s*s);let l=Math.sqrt(c),u=b*n/c,d=o/l*u,f=s/l*u;r.vx+=d,r.vy+=f,a.vx-=d,a.vy-=f}}let r=new Map(e.map(e=>[e.id,e]));for(let e of t){let t=r.get(e.from),i=r.get(e.to);if(!t||!i)continue;let a=i.x-t.x,o=i.y-t.y,s=Math.sqrt(a*a+o*o)||1,c=(s-S)*x*n,l=a/s*c,u=o/s*c;t.vx+=l,t.vy+=u,i.vx-=l,i.vy-=u}for(let t of e)t.vx-=t.x*C*n,t.vy-=t.y*C*n,t.vx*=w,t.vy*=w,t.x+=t.vx,t.y+=t.vy}function T(e,t,n){let r=new Map(e.map(e=>[e.id,e]));return t.map((e,i)=>{let a=r.get(e.id)??y(i,t.length);return{id:e.id,x:a.x,y:a.y,vx:0,vy:0,record:e,degree:n.get(e.id)||0}})}function E(e,t,n,r){let i=n-e,a=r-t,o=Math.sqrt(i*i+a*a)||1,s=Math.min(o*.18,60);return`M ${e} ${t} Q ${(e+n)/2-a/o*s} ${(t+r)/2+i/o*s} ${n} ${r}`}var D=.08;function O(e,t,n,r){let i=Math.min(4,Math.max(D,e.k*r));return{k:i,x:t-(t-e.x)/e.k*i,y:n-(n-e.y)/e.k*i}}function k(e,t,n){return{x:t-e.x,y:n-e.y}}function A(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x),i=Math.max(i,a.y);return{minX:t,minY:n,maxX:r,maxY:i}}var j=n(),M=`workfile-workflow-filters`;function N(){let e={relations:[...h],kinds:[...g],hideIsolated:!0};try{let t=localStorage.getItem(M);if(!t)return e;let n=JSON.parse(t);return{relations:Array.isArray(n.relations)?n.relations:e.relations,kinds:Array.isArray(n.kinds)?n.kinds:e.kinds,hideIsolated:typeof n.hideIsolated==`boolean`?n.hideIsolated:e.hideIsolated}}catch{return e}}function P({on:e,onClick:t,children:n,dashed:r}){return(0,j.jsx)(`button`,{type:`button`,"aria-pressed":e,onClick:t,className:s(`shrink-0 rounded-full border px-2 py-0.5 text-[11px] whitespace-nowrap transition-colors`,e?`border-ring bg-accent text-foreground`:`border-border text-muted-foreground hover:bg-accent/50`,r&&`border-dashed`),children:n})}function F({selectedId:e,onSelect:t,filters:n}){let[p,h]=(0,d.useState)(null),[g,_]=(0,d.useState)(null),v=(0,d.useRef)(N()),[y,b]=(0,d.useState)(()=>new Set(v.current.relations)),[x,S]=(0,d.useState)(()=>new Set(v.current.kinds)),[C,w]=(0,d.useState)(v.current.hideIsolated),[D,F]=(0,d.useState)(null),I=(0,d.useRef)(0),[L,R]=(0,d.useState)({x:0,y:0,k:1}),[,z]=(0,d.useState)(0),B=(0,d.useRef)({nodes:[],links:[],alpha:0}),V=(0,d.useRef)(null),H=(0,d.useRef)(!1);(0,d.useEffect)(()=>{let e=!0;return u.graph().then(t=>{e&&h(t.records)}).catch(t=>{e&&_(t.message)}),()=>{e=!1}},[]),(0,d.useEffect)(()=>{localStorage.setItem(M,JSON.stringify({relations:[...y],kinds:[...x],hideIsolated:C}))},[y,x,C]);let U=(0,d.useMemo)(()=>ee(p??[],{relations:y,kinds:x,hideIsolated:C,record:n}),[p,x,y,C,n]),W=(0,d.useMemo)(()=>Object.entries(n).filter(([,e])=>e).map(([e,t])=>`${e} ${t}`),[n]);(0,d.useEffect)(()=>{B.current.nodes=T(B.current.nodes,U.records,U.degree),B.current.links=U.links,B.current.alpha=1,z(e=>e+1)},[U]);let G=(0,d.useCallback)(()=>{let e=B.current.nodes,t=V.current;if(!e.length||!t)return;let n=t.getBoundingClientRect(),{minX:r,minY:i,maxX:a,maxY:o}=A(e),s=Math.min(3,Math.max(.15,Math.min(n.width/(a-r+160),n.height/(o-i+160))));R({k:s,x:n.width/2-(r+a)/2*s,y:n.height/2-(i+o)/2*s})},[]);(0,d.useEffect)(()=>{let e=0,t=()=>{let n=B.current;n.alpha>.02&&n.nodes.length&&(te(n.nodes,n.links,n.alpha),n.alpha*=.97,H.current||G(),z(e=>e+1)),e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>cancelAnimationFrame(e)},[G]);let ne=e=>{e.preventDefault();let t=V.current?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left,r=e.clientY-t.top;H.current=!0;let i=e.deltaY<0?1.12:.89;R(e=>O(e,n,r,i))},K=(0,d.useRef)(null),re=e=>{H.current=!0,K.current={x:e.clientX-L.x,y:e.clientY-L.y},e.target.setPointerCapture?.(e.pointerId)},ie=e=>{let t=K.current;if(!t)return;let n=k(t,e.clientX,e.clientY);R(e=>({...e,...n}))},q=()=>{K.current=null},J=(e,t,n)=>{let r=new Set(e);r.has(n)?r.delete(n):r.add(n),t(r)},Y=B.current.nodes,X=(0,d.useMemo)(()=>new Map(Y.map(e=>[e.id,e])),[Y,L]),Z=D??e,Q=Z?X.get(Z):void 0,$=(0,d.useMemo)(()=>{if(!Z)return null;let e=new Set([Z]);for(let t of U.links)t.from===Z&&e.add(t.to),t.to===Z&&e.add(t.from);return e},[Z,U.links]);return g?(0,j.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`The graph could not be read: `,g]}):(0,j.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,j.jsxs)(c,{gutter:`3`,className:`shrink-0 border-b py-2`,after:(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`span`,{className:`hidden text-[11px] whitespace-nowrap text-muted-foreground sm:inline`,children:[U.records.length,` nodes · `,U.links.length,` `,`edges`]}),(0,j.jsxs)(o,{type:`button`,variant:`outline`,size:`sm`,className:`shrink-0 px-2`,onClick:()=>{H.current=!1,G()},children:[(0,j.jsx)(r,{"aria-hidden":`true`,className:`size-3`}),`Fit`]})]}),children:[(0,j.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:m.map(e=>(0,j.jsx)(P,{on:x.has(e.id),onClick:()=>J(x,S,e.id),children:e.label},e.id))}),(0,j.jsx)(`span`,{className:`h-4 w-px shrink-0 bg-border`,"aria-hidden":`true`}),(0,j.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:f.map(e=>(0,j.jsx)(P,{on:y.has(e.id),dashed:!e.declared,onClick:()=>J(y,b,e.id),children:e.label},e.id))}),(0,j.jsx)(`span`,{className:`h-4 w-px shrink-0 bg-border`,"aria-hidden":`true`}),(0,j.jsx)(P,{on:C,onClick:()=>w(!C),children:`hide isolated`})]}),(0,j.jsxs)(`div`,{className:`relative min-h-0 flex-1 overflow-hidden`,children:[p?null:(0,j.jsxs)(`div`,{className:`flex h-full items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,j.jsx)(i,{"aria-hidden":`true`,className:`size-4 animate-spin`}),`Reading the graph…`]}),p?.length&&!U.records.length?(0,j.jsx)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-1.5 px-6 text-center text-sm text-muted-foreground`,children:U.isolated?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`span`,{children:[U.isolated,` `,U.isolated===1?`record matches`:`records match`,`, and`,` `,U.isolated===1?`it is`:`none is`,` `,`connected to anything else here.`]}),(0,j.jsx)(o,{type:`button`,variant:`outline`,size:`sm`,className:`px-2`,onClick:()=>w(!1),children:`Show unconnected records`})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`span`,{children:`No records match these filters.`}),(0,j.jsx)(`span`,{className:`text-xs`,children:W.length?`${W.join(`, `)} above, and ${x.size} of ${m.length} kinds here.`:`${x.size} of ${m.length} kinds and ${y.size} of ${f.length} relationships.`})]})}):null,(0,j.jsxs)(`svg`,{ref:V,role:`presentation`,className:`size-full cursor-grab touch-none active:cursor-grabbing`,onWheel:ne,onPointerDown:re,onPointerMove:ie,onPointerUp:q,onPointerLeave:q,children:[(0,j.jsx)(`defs`,{children:(0,j.jsx)(`marker`,{id:`workflow-arrow`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`5`,markerHeight:`5`,orient:`auto-start-reverse`,children:(0,j.jsx)(`path`,{d:`M 0 1 L 7 4 L 0 7 z`,className:`fill-muted-foreground`})})}),(0,j.jsxs)(`g`,{transform:`translate(${L.x} ${L.y}) scale(${L.k})`,children:[U.links.map(e=>{let t=X.get(e.from),n=X.get(e.to);if(!t||!n)return null;let r=$&&!($.has(e.from)&&$.has(e.to));return(0,j.jsx)(`path`,{d:E(t.x,t.y,n.x,n.y),fill:`none`,markerEnd:`url(#workflow-arrow)`,className:s(`stroke-muted-foreground transition-opacity`,r?`opacity-10`:`opacity-45`),strokeWidth:1.2/L.k,strokeDasharray:e.declared?void 0:`${4/L.k} ${3/L.k}`,children:(0,j.jsx)(`title`,{children:`${e.from} → ${e.to}: ${e.relations.join(`, `)}`})},`${e.from}->${e.to}`)}),Y.map(n=>{let r=$&&!$.has(n.id),i=n.id===e,o=Math.min(16,6+Math.sqrt(n.degree)*2);return(0,j.jsxs)(`g`,{transform:`translate(${n.x} ${n.y})`,className:s(`cursor-pointer transition-opacity`,r&&`opacity-20`),onPointerEnter:()=>F(n.id),onPointerLeave:()=>F(null),onClick:e=>{e.stopPropagation(),I.current=performance.now(),t(n.id)},children:[(0,j.jsx)(`circle`,{r:o,style:{fill:a(n.record.status||`backlog`)},className:s(i?`stroke-foreground`:`stroke-background`),strokeWidth:(i?3:1.5)/L.k}),(0,j.jsx)(`title`,{children:`${n.id} — ${n.record.title}`}),L.k>.55||i||r===!1?(0,j.jsx)(`text`,{y:o+11/L.k,textAnchor:`middle`,className:`pointer-events-none fill-foreground`,style:{fontSize:`${11/L.k}px`},children:n.id}):null]},n.id)})]})]}),Q?(0,j.jsxs)(`div`,{className:`pointer-events-none absolute bottom-3 left-3 max-w-[min(30rem,70%)] rounded-md border bg-background/95 px-3 py-2 shadow-sm`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(`span`,{className:`font-mono text-[11px] font-medium`,children:Z}),(0,j.jsx)(l,{variant:`secondary`,className:`px-1.5 py-0 text-[10px] font-normal`,children:Q.record.recordType})]}),(0,j.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:Q.record.title})]}):null]})]})}export{F as WorkflowView};
+1
-0

@@ -163,2 +163,3 @@ export declare const SCHEMA_VERSION = 2;

exclude: string[];
routeRoots: undefined[];
idPrefix: string;

@@ -165,0 +166,0 @@ kinds: ("architecture" | "guide" | "handoff" | "product" | "reference" | "research" | "runbook" | "spec")[];

@@ -297,2 +297,6 @@ export const SCHEMA_VERSION = 2;

],
// Empty by default: a repository's Markdown is paths until someone says
// otherwise, and guessing which trees are published sites would turn a
// real broken link into silence.
routeRoots: [],
idPrefix: "DOC",

@@ -299,0 +303,0 @@ kinds: [...DOC_KINDS],

+2
-2

@@ -234,5 +234,5 @@ import { AGENT_TARGET_IDS, ARGV_CONTROL_CHARACTER_RE, AXIS_NAME_RE, CARD_RESERVED_KEYS, CI_TARGET_IDS, DOC_LAYOUTS, MEMORY_DEFINITIONS, REQUESTABLE_VERIFICATION_METHODS, SCHEMA_VERSION, VERIFY_TIMEOUT_SECONDS_MAXIMUM } from "./defaults.js";

else {
for (const key of ["sources", "exclude", "kinds", "statuses"]) {
for (const key of ["sources", "exclude", "routeRoots", "kinds", "statuses"]) {
validateStringList(issues, config.docs[key], `docs.${key}`, {
required: key !== "exclude"
required: key !== "exclude" && key !== "routeRoots"
});

@@ -239,0 +239,0 @@ }

@@ -48,2 +48,20 @@ export declare const DEFAULT_LIST_KEYS: Set<string>;

};
/**
* Swaps a record's body, leaving its frontmatter byte for byte as it was.
*
* Four call sites wrote this inline — `changelog patch`, `changelog release
* --amend`, `doc patch` and `memory patch` — and all four spliced the body
* directly onto `prefixLength`, which ends at the closing `---` newline. The
* renderers that *create* those records put a blank line there. So every
* record was born with one and lost it the first time anything patched its
* body: a diff line on a write that changed nothing else, on four surfaces,
* repeated for every record that ever went through a body patch. Twelve
* records in one consuming repository carried the mark before anyone noticed
* what was making it.
*
* The end-of-line comes from the file rather than from here, the same way
* `patchFrontmatter` reads it. A CRLF record patched with a hardcoded `\n`
* ends up mixed, and the one line that differs is the one this function adds.
*/
export declare function replaceBody(content: string, body: string): string;
/** A mapping one level deep, with at least one field. */

@@ -50,0 +68,0 @@ export declare function isFlatMapping(value: unknown): boolean;

@@ -336,2 +336,24 @@ import { ValidationError } from "./errors.js";

/**
* Swaps a record's body, leaving its frontmatter byte for byte as it was.
*
* Four call sites wrote this inline — `changelog patch`, `changelog release
* --amend`, `doc patch` and `memory patch` — and all four spliced the body
* directly onto `prefixLength`, which ends at the closing `---` newline. The
* renderers that *create* those records put a blank line there. So every
* record was born with one and lost it the first time anything patched its
* body: a diff line on a write that changed nothing else, on four surfaces,
* repeated for every record that ever went through a body patch. Twelve
* records in one consuming repository carried the mark before anyone noticed
* what was making it.
*
* The end-of-line comes from the file rather than from here, the same way
* `patchFrontmatter` reads it. A CRLF record patched with a hardcoded `\n`
* ends up mixed, and the one line that differs is the one this function adds.
*/
export function replaceBody(content, body) {
const parsed = requireFrontmatter(content);
const eol = /\r\n/.test(content.slice(0, parsed.prefixLength)) ? "\r\n" : "\n";
return `${content.slice(0, parsed.prefixLength)}${eol}${String(body).trim()}${eol}`;
}
/**
* One `key: value` line inside a nested structure.

@@ -338,0 +360,0 @@ *

@@ -8,3 +8,3 @@ import { randomUUID } from "node:crypto";

import { ConflictError, NotFoundError, ValidationError } from "../../core/errors.js";
import { DEFAULT_LIST_KEYS, parseFrontmatter, patchFrontmatter, renderFrontmatterEntry, requireFrontmatter } from "../../core/frontmatter.js";
import { DEFAULT_LIST_KEYS, parseFrontmatter, patchFrontmatter, renderFrontmatterEntry, replaceBody, requireFrontmatter } from "../../core/frontmatter.js";
import { withFileLock } from "../../core/locks.js";

@@ -426,4 +426,3 @@ import { revisionForContent } from "../../core/revision.js";

if (nextBody !== undefined) {
const parsed = requireFrontmatter(next, { listKeys: CHANGE_LIST_KEYS });
next = `${next.slice(0, parsed.prefixLength)}${String(nextBody).trim()}\n`;
next = replaceBody(next, String(nextBody));
}

@@ -590,6 +589,3 @@ await writeFileAtomic(path, next);

if (nextBody !== undefined) {
const parsed = requireFrontmatter(next, {
listKeys: CHANGE_LIST_KEYS
});
next = `${next.slice(0, parsed.prefixLength)}${String(nextBody).trim()}\n`;
next = replaceBody(next, String(nextBody));
}

@@ -596,0 +592,0 @@ // The write is the last chance to notice that an amendment removed

@@ -9,3 +9,3 @@ import { createHash } from "node:crypto";

import { ConflictError, NotFoundError, ValidationError } from "../../core/errors.js";
import { DEFAULT_LIST_KEYS, parseFrontmatter, patchFrontmatter, renderFrontmatterEntry, requireFrontmatter } from "../../core/frontmatter.js";
import { DEFAULT_LIST_KEYS, parseFrontmatter, patchFrontmatter, renderFrontmatterEntry, replaceBody } from "../../core/frontmatter.js";
import { withFileLock } from "../../core/locks.js";

@@ -445,5 +445,3 @@ import { revisionForContent } from "../../core/revision.js";

if (nextBody !== undefined) {
const parsed = requireFrontmatter(next, { listKeys: DOC_LIST_KEYS });
next = `${next.slice(0, parsed.prefixLength)}${String(nextBody).trim()}
`;
next = replaceBody(next, String(nextBody));
}

@@ -450,0 +448,0 @@ await writeFileAtomic(path, next);

@@ -0,1 +1,21 @@

/**
* Which offsets of a body are code, so a link shown as an example is not
* followed as a link.
*
* The clearest case is a template. `_TEMPLATE.md` teaches the house link style
* by printing `` `[texto](categoria/slug)` ``, and it was reported as linking
* to a category that does not exist: the document doing exactly its job, called
* broken. `parseAcceptance` has skipped fences since T-0157 for the same
* reason; the link scan never did.
*
* A mask rather than a blanked copy, and this is the part worth being careful
* about. Blanking first and matching after changes what matches: a real link
* whose *label* is code — ``[`app/(private)/page.tsx`](…)`` — has brackets
* inside that label, so the scanner never saw it, and erasing the backticks
* revealed a link the target pattern then truncated at the first `)`. Two
* managed documents turned red on links that are fine. Matching first and
* discarding what falls inside code cannot invent a match that was not already
* there; blanking can.
*/
export declare function codeMask(body: string): Uint8Array;
export declare function diagnoseDocuments({ documents, unreadable, workspace, knownRecords, now }: {

@@ -2,0 +22,0 @@ documents: any;

@@ -45,5 +45,96 @@ import { stat } from "node:fs/promises";

const LINK = /\[[^\]\n]{0,512}\]\(([^)\n]{1,1024})\)/g;
function localMarkdownPaths(document) {
const paths = [];
for (const match of String(document.body || "").matchAll(LINK)) {
/**
* Which offsets of a body are code, so a link shown as an example is not
* followed as a link.
*
* The clearest case is a template. `_TEMPLATE.md` teaches the house link style
* by printing `` `[texto](categoria/slug)` ``, and it was reported as linking
* to a category that does not exist: the document doing exactly its job, called
* broken. `parseAcceptance` has skipped fences since T-0157 for the same
* reason; the link scan never did.
*
* A mask rather than a blanked copy, and this is the part worth being careful
* about. Blanking first and matching after changes what matches: a real link
* whose *label* is code — ``[`app/(private)/page.tsx`](…)`` — has brackets
* inside that label, so the scanner never saw it, and erasing the backticks
* revealed a link the target pattern then truncated at the first `)`. Two
* managed documents turned red on links that are fine. Matching first and
* discarding what falls inside code cannot invent a match that was not already
* there; blanking can.
*/
export function codeMask(body) {
const mask = new Uint8Array(body.length);
const cover = (start, end) => mask.fill(1, start, end);
let offset = 0;
let fenceAt = -1;
let fence = "";
for (const line of body.split("\n")) {
const opener = line.match(/^[ \t]*(```+|~~~+)/);
if (fenceAt === -1) {
if (opener) {
fenceAt = offset;
fence = opener[1];
}
}
else if (opener && opener[1].startsWith(fence)) {
cover(fenceAt, offset + line.length);
fenceAt = -1;
}
offset += line.length + 1;
}
// A fence nobody closed runs to the end of the document, which is how a
// Markdown renderer reads it too.
if (fenceAt !== -1)
cover(fenceAt, body.length);
for (const span of body.matchAll(/`+[^`\n]*`+/g)) {
if (!mask[span.index])
cover(span.index, span.index + span[0].length);
}
return mask;
}
/**
* What a target might name, once the tree it lives in is taken into account.
*
* A path resolves against the file and is either there or not. A *route*
* resolves against the site root and onto whichever file backs it, so
* `guides/invoicing` is `guides/invoicing.md`, `guides/invoicing.mdx`, or an
* `index` of either inside `guides/invoicing/`. The four suffixes are what
* every generator in this family does; nothing here models redirects or
* trailing slashes, and it should not — that is the site's business.
*
* The file-relative reading is always tried, and tried first. Declaring a tree
* as routes widens what counts as resolvable inside it; it never narrows it,
* so a link that was fine before a root was declared is still fine after.
*/
const ROUTE_SUFFIXES = ["", ".md", ".mdx", "/index.md", "/index.mdx"];
function candidatesFor(document, target, routeRoots) {
const fromFile = target.startsWith("/")
? target.slice(1)
: posix.normalize(posix.join(posix.dirname(document.path), target));
const root = routeRoots.find((entry) => document.path === entry || document.path.startsWith(`${entry}/`));
if (root === undefined)
return [fromFile];
// An explicit `/` is site-absolute inside a route tree, which is the one
// spelling that does not go through the file's directory at all.
const fromRoot = posix.normalize(posix.join(root, target.startsWith("/") ? target.slice(1) : target));
return [
...new Set([
...ROUTE_SUFFIXES.map((suffix) => `${fromFile}${suffix}`),
...ROUTE_SUFFIXES.map((suffix) => `${fromRoot}${suffix}`)
])
];
}
/**
* Every local link in a body, with what each one could resolve to.
*
* A link is broken only when none of its candidates exist, so the caller has to
* see them grouped rather than flattened.
*/
function localMarkdownLinks(document, routeRoots) {
const body = String(document.body || "");
const links = new Map();
const code = codeMask(body);
for (const match of body.matchAll(LINK)) {
if (code[match.index])
continue;
let target = match[1].trim().replace(/^<|>$/g, "");

@@ -62,10 +153,16 @@ if (!target ||

}
paths.push(target.startsWith("/")
? target.slice(1)
: posix.normalize(posix.join(posix.dirname(document.path), target)));
if (!target || links.has(target))
continue;
links.set(target, candidatesFor(document, target, routeRoots));
}
return [...new Set(paths)];
return [...links].map(([target, candidates]) => ({ target, candidates }));
}
export async function diagnoseDocuments({ documents, unreadable = [], workspace, knownRecords = new Map(), now = new Date() }) {
const issues = unreadable.map((entry) => issue("error", "unreadable-document", { path: entry.file }, `Cannot read document: ${entry.reason}`));
// Trailing separators stripped once here rather than at every comparison: a
// root written `docs/help/` must behave as `docs/help`, and the prefix test
// below is a string test.
const routeRoots = (workspace.config.docs.routeRoots || [])
.map((entry) => String(entry).replace(/^\.\//, "").replace(/\/+$/, ""))
.filter(Boolean);
const ids = new Map();

@@ -114,4 +211,11 @@ for (const document of documents) {

}
for (const linkedPath of localMarkdownPaths(document)) {
if (!(await pathExistsWithinWorkspace(workspace, linkedPath))) {
for (const link of localMarkdownLinks(document, routeRoots)) {
let resolved = false;
for (const candidate of link.candidates) {
if (await pathExistsWithinWorkspace(workspace, candidate)) {
resolved = true;
break;
}
}
if (!resolved) {
issues.push(issue(

@@ -124,3 +228,9 @@ // An indexed document is read-only through the protocol,

// being read at all.
document.managed ? "error" : "warning", "doc-broken-local-link", document, `Linked path does not exist: ${linkedPath}`, { path: linkedPath }));
document.managed ? "error" : "warning", "doc-broken-local-link", document,
// The target as written. It used to be the resolved
// path, which in a route tree is the doubled one
// (`clientes/clientes/…`) — the shape that made the
// finding unreadable rather than the one that explains
// it. What was tried goes in the details.
`Linked path does not exist: ${link.target}`, { path: link.candidates[0], target: link.target, tried: link.candidates }));
}

@@ -127,0 +237,0 @@ }

@@ -8,3 +8,3 @@ import { readFile, rm } from "node:fs/promises";

import { ConflictError, NotFoundError, ValidationError } from "../../core/errors.js";
import { DEFAULT_LIST_KEYS, parseFrontmatter, patchFrontmatter, renderFrontmatterEntry, requireFrontmatter } from "../../core/frontmatter.js";
import { DEFAULT_LIST_KEYS, parseFrontmatter, patchFrontmatter, renderFrontmatterEntry, replaceBody } from "../../core/frontmatter.js";
import { withFileLock } from "../../core/locks.js";

@@ -365,4 +365,3 @@ import { revisionForContent } from "../../core/revision.js";

if (nextBody !== undefined) {
const parsed = requireFrontmatter(next, { listKeys: MEMORY_LIST_KEYS });
next = `${next.slice(0, parsed.prefixLength)}${String(nextBody).trim()}\n`;
next = replaceBody(next, String(nextBody));
}

@@ -369,0 +368,0 @@ const path = resolve(workspace.root, current.path);

@@ -63,2 +63,17 @@ export type CardStatus = "backlog" | "next" | "doing" | "review" | "blocked" | "deferred" | "done" | "discarded";

exclude: string[];
/**
* Trees whose links are site routes rather than paths on disk.
*
* A documentation site resolves `[text](guides/invoicing)` through its own
* router: from the site root, not from the file, and onto whatever file
* backs that route — `guides/invoicing.md`, `.mdx`, or an `index` inside a
* folder. Checked as a path, every one of those links is broken, and the
* doctor said so 635 times in one repository whose editorial guide
* *mandates* that spelling. Six genuinely dead links sat underneath.
*
* A root listed here says "inside this tree a bare link is a route", and
* the check resolves it as one before calling it broken. Everything else
* keeps being read as a path, which is what a README's links are.
*/
routeRoots: string[];
idPrefix: string;

@@ -65,0 +80,0 @@ kinds: string[];

@@ -13,3 +13,3 @@ <!doctype html>

/>
<script type="module" crossorigin src="/static/index-DnoD4yDd.js"></script>
<script type="module" crossorigin src="/static/index-BcEUSS3r.js"></script>
<link rel="modulepreload" crossorigin href="/static/rolldown-runtime-CbXtAM7H.js">

@@ -16,0 +16,0 @@ <link rel="modulepreload" crossorigin href="/static/react-Buq45Vzz.js">

@@ -583,2 +583,3 @@ # CLI reference

workfile doc create --title TITLE [--kind KIND] [--status STATUS] [--folder PATH]
workfile doc create --json-input FILE # recommended: body and metadata in one call
workfile doc move ID --folder PATH [--expected-revision REV]

@@ -604,2 +605,3 @@ workfile doc patch ID --json-input FILE [--expected-revision REV]

workfile changelog add --title TITLE [--type fixed] [--area AREA]
workfile changelog add --json-input FILE # recommended: body and metadata in one call
workfile changelog patch ID --json-input FILE [--expected-revision REV]

@@ -621,2 +623,3 @@ workfile changelog preview [--fragments CHG-0001,CHG-0002]

workfile memory add COLLECTION --title TITLE [--status STATUS]
workfile memory add COLLECTION --json-input FILE # recommended: body and metadata in one call
workfile memory patch ID --json-input FILE [--expected-revision REV]

@@ -623,0 +626,0 @@ workfile memory graduate ID --to CONV-0001,DOC-0001

{
"name": "@illodev/workfile",
"version": "0.8.0",
"version": "0.8.1",
"type": "module",

@@ -5,0 +5,0 @@ "mcpName": "io.github.illodev/workfile",

@@ -78,2 +78,11 @@ // A plain object on purpose, not `defineProject(...)`. That call would need

],
// Trees whose links are site routes rather than paths on disk. Inside
// one of these, `[text](guides/invoicing)` is resolved from the root
// named here — not from the linking file — and onto whatever backs that
// route: `.md`, `.mdx`, or an `index` of either. Without it every link
// in a published documentation tree reads as broken.
//
// Empty by default, and it only ever widens what resolves: outside
// these roots a link is a path, which is what a README's links are.
routeRoots: [],
kinds: [

@@ -80,0 +89,0 @@ "architecture",

import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{Et as r,Tt as i,pt as a}from"./ui-primitives-DRENhlck.js";import{i as o,n as s,o as c,s as l,u}from"./theme-CcOVK72d.js";import{A as d,D as f,H as p,I as m,L as h,M as g,V as _,et as v,j as y,k as b,n as x,nt as S,r as C,t as w,w as T}from"./index-DnoD4yDd.js";var E=e(t(),1),D=n(),O=[];function k(e,t){let[n,r]=(0,E.useState)(t);(0,E.useEffect)(()=>{r(t)},[e.length,t]);let i=(0,E.useCallback)(()=>r(n=>Math.min(n+t,e.length)),[e.length,t]);return[n>=e.length?e:e.slice(0,n),n<e.length,i]}function A({onVisible:e,remaining:t}){let n=(0,E.useRef)(null);return(0,E.useEffect)(()=>{let t=n.current;if(!t)return;let r=new IntersectionObserver(t=>{t.some(e=>e.isIntersecting)&&e()},{rootMargin:`600px 0px`});return r.observe(t),()=>r.disconnect()},[e,t]),(0,D.jsxs)(`span`,{ref:n,className:`px-0.5 py-1 font-mono text-[11px] text-muted-foreground`,children:[`+`,t,` more`]})}function j({task:e,epicId:t,onOpen:n,onDragStart:r,onCarry:i,carrying:a}){let o=e.claimed_at?Date.parse(e.claimed_at.includes(`T`)?e.claimed_at:`${e.claimed_at}T00:00:00`):NaN,l=Number.isNaN(o)?null:Math.max(0,Math.floor((Date.now()-o)/864e5)),d=[t&&t!==e.id?`epic ${t}`:``,e.effort?`effort ${e.effort}`:``,e.claimed_by?`claimed by ${e.claimed_by}${l==null?``:` · ${l}d`}`:``].filter(Boolean);return(0,D.jsxs)(`article`,{className:u(`flex cursor-pointer flex-col gap-1.5 rounded-lg border bg-background px-3 py-2.5 shadow-xs outline-none transition-[color,border-color,box-shadow] hover:border-ring focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,a&&`border-ring ring-2 ring-ring`),tabIndex:0,draggable:!!r,"aria-grabbed":i?!!a:void 0,title:d.length?d.join(` · `):void 0,onClick:()=>n(e.id),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),n(e.id)):t.key===` `&&i?(t.preventDefault(),i()):t.key===` `&&(t.preventDefault(),n(e.id))},onDragStart:r,children:[(0,D.jsxs)(`span`,{className:`flex items-center`,children:[(0,D.jsx)(`span`,{className:`font-mono text-[11px] text-foreground/70`,children:e.id}),(0,D.jsx)(`span`,{className:`flex-1`}),(0,D.jsx)(`span`,{className:`font-mono text-[10px] font-medium`,style:{color:s(e.priority)},children:e.priority})]}),(0,D.jsx)(`span`,{className:`text-[12.5px] leading-snug font-medium`,role:`heading`,"aria-level":3,children:e.title}),(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 font-mono text-[10px] text-muted-foreground`,children:[(0,D.jsx)(`span`,{children:e.area}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsx)(`span`,{children:e.type}),e.claimed_by?(0,D.jsxs)(`span`,{className:`ml-auto inline-flex min-w-0 items-center gap-[5px]`,style:{color:c(`doing`)},children:[(0,D.jsx)(`span`,{className:`size-[5px] flex-none rounded-full bg-current`,"aria-hidden":`true`}),(0,D.jsx)(`span`,{className:`max-w-[90px] truncate`,children:e.claimed_by})]}):null]}),Array.isArray(e.scope)&&e.scope.length?(0,D.jsxs)(`span`,{className:`mt-0.5 truncate border-t border-dashed pt-1.5 font-mono text-[10.5px] text-muted-foreground`,children:[`scope `,e.scope.join(` · `)]}):null]})}function M({status:e,cards:t,epicIds:n,collapsed:o,onToggleCollapsed:s,onOpen:m,onMove:h,onCarry:v,carryingId:x,isDropTarget:C,onDragEnterColumn:w,onDragLeaveColumn:E}){let O=T(),[M,N,P]=k(t,25),F=c(e),I={onDragOver:t=>{t.preventDefault(),t.dataTransfer.dropEffect=`move`,w?.(e)},onDragLeave:t=>{t.currentTarget.contains(t.relatedTarget)||E?.(e)},onDrop:t=>{t.preventDefault(),E?.(e);let n=t.dataTransfer.getData(`text/plain`);n&&h(n,e).catch(()=>void 0)}};return o?(0,D.jsxs)(p,{role:`region`,"aria-label":`${e}, ${t.length} cards, collapsed`,className:u(`relative w-11 flex-none gap-0 overflow-hidden rounded-lg py-0 shadow-xs`,C&&`border-primary`),...I,children:[(0,D.jsx)(_,{edge:`top`,color:F}),(0,D.jsxs)(`button`,{type:`button`,"aria-expanded":!1,"aria-label":`Expand the ${e} column`,title:`${e} · ${t.length}`,className:u(`flex h-full w-full cursor-pointer flex-col items-center gap-2.5 px-1 pt-4 pb-3 transition-colors hover:bg-accent/50`,C&&`bg-accent/50`),onClick:s,children:[(0,D.jsx)(r,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-muted-foreground`}),(0,D.jsx)(`span`,{className:`min-h-0 flex-1 truncate font-mono text-[11px] uppercase tracking-[0.06em] [writing-mode:vertical-rl]`,style:{color:F},children:e}),(0,D.jsx)(S,{variant:`secondary`,className:`h-5 shrink-0 rounded-md px-[7px] font-mono text-[11px] font-normal`,children:t.length})]})]}):(0,D.jsxs)(p,{role:`region`,"aria-label":`${e}, ${t.length} cards`,className:u(`relative w-[268px] flex-none gap-0 overflow-hidden rounded-lg py-0 shadow-xs`,C&&`border-primary`),...I,children:[(0,D.jsx)(_,{edge:`top`,color:F}),(0,D.jsxs)(`header`,{className:`flex flex-none items-center gap-2 px-3 pb-2.5 pt-4`,children:[(0,D.jsx)(`span`,{className:`flex-1 font-mono text-[11px] uppercase tracking-[0.06em]`,style:{color:F},children:e}),(0,D.jsx)(S,{variant:`secondary`,className:`h-5 rounded-md px-[7px] font-mono text-[11px] font-normal`,children:t.length}),s?(0,D.jsx)(l,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-expanded":!0,"aria-label":`Collapse the ${e} column`,title:`Collapse column`,className:`-mr-1 text-muted-foreground`,onClick:s,children:(0,D.jsx)(i,{"aria-hidden":`true`})}):null]}),(0,D.jsxs)(`div`,{className:u(`scroll-fade flex flex-1 flex-col gap-2 overflow-y-auto p-2.5`,C&&`bg-accent/50`),children:[t.length===0?(0,D.jsx)(f,{className:`flex-1 gap-2 rounded-lg border border-dashed p-4`,children:(0,D.jsxs)(d,{className:`gap-1`,children:[(0,D.jsx)(y,{variant:`icon`,className:`mb-0 size-8 [&_svg:not([class*='size-'])]:size-4`,children:(0,D.jsx)(a,{"aria-hidden":`true`})}),(0,D.jsx)(g,{className:`text-[12.5px] font-medium`,children:`No cards`}),(0,D.jsx)(b,{className:`text-[11.5px]`,children:`Nothing in this state.`})]})}):M.map(e=>(0,D.jsx)(j,{task:e,epicId:n.get(e.id),onOpen:m,onCarry:v&&!O?()=>v(e):void 0,carrying:x===e.id,onDragStart:O?void 0:t=>{t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,e.id)}},e.id)),N&&(0,D.jsx)(A,{onVisible:P,remaining:t.length-M.length})]})]})}function N({tasks:e,epicIds:t,showClosed:n,onOpen:r,onMove:i}){let[a,o]=(0,E.useState)(null),[s,c]=(0,E.useState)(null),[l,u]=(0,E.useState)(``),[d,f]=(0,E.useState)(()=>{try{let e=localStorage.getItem(`workfile-flow-collapsed`);return new Set(e?JSON.parse(e):[])}catch{return new Set}}),p=(0,E.useCallback)(e=>{f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),localStorage.setItem(`workfile-flow-collapsed`,JSON.stringify([...n])),n})},[]),m=(0,E.useMemo)(()=>[`backlog`,`next`,`doing`,`review`,`blocked`,`deferred`,...n?[`done`,`discarded`]:[]],[n]),h=(0,E.useMemo)(()=>{let t=new Map;for(let n of e){let e=t.get(n.status);e?e.push(n):t.set(n.status,[n])}return t},[e]),g=e=>{o({id:e.id,status:e.status}),u(`${e.id} picked up from ${e.status}. Use the arrow keys to choose a column, space to drop, escape to cancel.`)},_=e=>{if(!a)return;let t=m.indexOf(a.status),n=m[Math.min(m.length-1,Math.max(0,t+e))];!n||n===a.status||(o({...a,status:n}),u(`${a.id} over ${n}.`))},v=async()=>{if(!a)return;let t=a;o(null);let n=e.find(e=>e.id===t.id);n&&n.status!==t.status?(await i(t.id,t.status),u(`${t.id} moved to ${t.status}.`)):u(`${t.id} put back.`)};return(0,D.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-3 overflow-x-auto p-3.5`,onDragEnd:()=>c(null),onKeyDown:e=>{a&&(e.key===`Escape`?(e.preventDefault(),o(null),u(`Move cancelled.`)):e.key===`ArrowRight`?(e.preventDefault(),_(1)):e.key===`ArrowLeft`?(e.preventDefault(),_(-1)):(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),v()))},children:[(0,D.jsx)(`p`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:l}),m.map(e=>(0,D.jsx)(M,{status:e,cards:h.get(e)??O,epicIds:t,collapsed:d.has(e),onToggleCollapsed:()=>p(e),onOpen:r,onMove:i,onCarry:g,carryingId:a?.id??null,isDropTarget:a?.status===e||s===e,onDragEnterColumn:c,onDragLeaveColumn:e=>c(t=>t===e?null:t)},e))]})}function P({tasks:e,allTasks:t,epicIds:n,onOpen:r}){let i=(0,E.useMemo)(()=>new Map(t.map(e=>[e.id,e])),[t]),a=(0,E.useMemo)(()=>{let t=new Map;for(let r of e){let e=n.get(r.id)||(r.type===`epic`?r.id:`__none`);t.has(e)||t.set(e,[]),r.id!==e&&t.get(e)?.push(r)}return[...t].sort(([e],[t])=>e===`__none`?1:t===`__none`?-1:e.localeCompare(t,void 0,{numeric:!0}))},[n,e]);return a.length?(0,D.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3.5`,children:(0,D.jsx)(`div`,{className:`flex flex-col gap-2.5`,children:a.map(([e,t])=>{let n=i.get(e),a=t.length,o=t.filter(e=>e.status===`done`||e.status===`discarded`).length,s=t.filter(e=>e.status===`doing`).length,l=a-o-s,d=e=>a?`${e/a*100}%`:`0%`,f=[{label:`${o} done`,color:c(`done`)},{label:`${s} doing`,color:c(`doing`)},{label:`${l} open`,color:null}],m=(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,D.jsx)(`span`,{className:`font-mono text-[11.5px] text-foreground/70`,children:e===`__none`?`—`:e}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 text-sm font-semibold tracking-[-0.01em] text-pretty`,children:n?.title||`Without epic`}),n?(0,D.jsx)(`span`,{className:`font-mono text-[11px]`,style:{color:c(n.status)},children:n.status}):null,(0,D.jsxs)(`span`,{className:`font-mono text-[11.5px] text-muted-foreground`,children:[o,`/`,a]})]}),(0,D.jsx)(`span`,{className:`flex h-2 w-full overflow-hidden rounded-full bg-muted`,"aria-hidden":`true`,children:a>0?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{className:`h-full`,style:{width:d(o),background:c(`done`)}}),(0,D.jsx)(`span`,{className:`h-full`,style:{width:d(s),background:c(`doing`)}})]}):null}),(0,D.jsxs)(`span`,{className:`flex flex-wrap items-center gap-3.5 font-mono text-[10.5px] text-muted-foreground`,children:[f.map(e=>(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-[5px]`,children:[(0,D.jsx)(`span`,{className:u(`size-1.5 rounded-[2px]`,!e.color&&`bg-muted-foreground`),style:e.color?{background:e.color}:void 0,"aria-hidden":`true`}),e.label]},e.label)),(0,D.jsx)(`span`,{className:`ml-auto`,children:n?.area??``})]})]});return n?(0,D.jsx)(`button`,{type:`button`,className:`flex w-full cursor-pointer flex-col gap-2.5 rounded-xl border bg-card px-4 py-3.5 text-left text-card-foreground shadow-xs outline-none transition-[color,border-color,box-shadow] hover:border-ring focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,onClick:()=>r(e),children:m},e):(0,D.jsx)(p,{className:`gap-2.5 rounded-xl px-4 py-3.5 shadow-xs`,children:m},e)})})}):(0,D.jsx)(f,{className:`flex-1 p-6`,children:(0,D.jsxs)(d,{children:[(0,D.jsx)(g,{className:`text-sm`,children:`No epics`}),(0,D.jsx)(b,{className:`text-[11.5px]`,children:`No cards match the current filters.`})]})})}var F=300,I=30;function L({task:e,span:t,mode:n,epicId:r,pct:i,labelWidth:a,onOpen:o}){let s=c(e.status);return(0,D.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),title:`${C(e,n,t)} · ${e.status}${r&&r!==e.id?` · epic ${r}`:``}`,className:`flex w-full cursor-pointer items-center border-b bg-transparent p-0 text-left transition-colors hover:bg-muted`,children:[(0,D.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 border-r px-3.5`,style:{width:a,flex:`0 0 ${a}px`,height:`var(--row-h)`},children:[(0,D.jsx)(`span`,{className:`flex-none whitespace-nowrap font-mono text-[11px] text-foreground/70`,children:e.id}),(0,D.jsx)(`span`,{className:`min-w-0 truncate text-[12.5px]`,children:e.title})]}),(0,D.jsx)(`span`,{className:`relative block flex-1`,style:{height:`var(--row-h)`},children:t.point?(0,D.jsx)(`span`,{style:{position:`absolute`,top:`50%`,width:9,height:9,transform:`translate(-50%, -50%) rotate(45deg)`,borderRadius:2,background:s,display:`block`,left:`${i(t.from)}%`}}):(0,D.jsx)(`span`,{style:{position:`absolute`,top:`50%`,transform:`translateY(-50%)`,height:12,minWidth:6,borderRadius:3,background:s,display:`block`,left:`${i(t.from)}%`,width:`${Math.max(i(t.to)-i(t.from),.8)}%`}})})]})}function R({tasks:e,epicIds:t,axes:n={},mode:r,counts:i,onModeChange:a,onOpen:s}){let c=v()?168:F,u=c+460,[p,_]=(0,E.useState)(()=>{try{return localStorage.getItem(`workfile-timeline-group`)||`none`}catch{return`none`}}),y=(0,E.useCallback)(e=>{_(e);try{localStorage.setItem(`workfile-timeline-group`,e)}catch{}},[]),S=(0,E.useMemo)(()=>[`none`,`epic`,`area`,...Object.keys(n)],[n]),C=S.includes(p)?p:`none`,T=(0,E.useCallback)(e=>{if(C===`epic`)return t.get(e.id)||``;if(C===`area`)return e.area||``;let n=e[C];return typeof n==`string`?n:``},[t,C]),O=(0,E.useMemo)(()=>{let t=new Map;for(let n of e){let e=x(n,r);e&&t.set(n.id,e)}return t},[r,e]),k=(0,E.useMemo)(()=>{let t=(e,t)=>O.get(e.id).from-O.get(t.id).from||e.id.localeCompare(t.id),n=e.filter(e=>O.has(e.id)).sort(t);return C===`none`?n:[...n].sort((e,n)=>{let r=T(e),i=T(n);return!r==!i?r.localeCompare(i)||t(e,n):r?-1:1})},[T,C,O,e]),A=(0,E.useMemo)(()=>{if(C===`none`)return k.map(e=>({task:e,label:null}));let e=[],t=null;for(let n of k){let r=T(n);r!==t&&(t=r,e.push({task:null,label:r||`no ${C}`})),e.push({task:n,label:null})}return e},[T,C,k]),j=(0,E.useMemo)(()=>new Map(A.flatMap((e,t)=>e.task?[[e.task.id,t]]:[])),[A]),M=(0,E.useMemo)(()=>{let e=[];for(let t of k)for(let n of t.depends||[])j.has(n)&&e.push({from:n,to:t.id});return e},[j,k]),N=(0,E.useMemo)(()=>w(k.map(e=>O.get(e.id)),Date.now()),[k,O]),P=i[r===`plan`?`actual`:`plan`];return!k.length||!N?(0,D.jsx)(f,{className:`flex-1 p-6`,children:(0,D.jsxs)(d,{children:[(0,D.jsx)(g,{className:`text-sm`,children:r===`plan`?`Nothing scheduled`:`Nothing recorded`}),(0,D.jsx)(b,{className:`text-[11.5px]`,children:r===`plan`?`Add a start or due date to a card.`:`Cards record a trail as they are claimed and moved.`}),P>0?(0,D.jsx)(b,{className:`text-[11.5px]`,children:(0,D.jsx)(l,{variant:`outline`,size:`sm`,className:`mt-2 text-[12.5px] font-medium`,onClick:()=>a(r===`plan`?`actual`:`plan`),children:r===`plan`?`show what actually happened · ${P} cards`:`show the schedule · ${P} cards`})}):null]})}):(0,D.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,D.jsxs)(m,{gutter:`3.5`,className:`shrink-0 border-b bg-card py-2`,children:[(0,D.jsxs)(`span`,{className:`shrink-0 font-mono text-[11px] whitespace-nowrap text-muted-foreground`,children:[k.length,` `,r===`actual`?`recorded`:`scheduled`,` ·`,` `,M.length,` dependenc`,M.length===1?`y`:`ies`]}),(0,D.jsxs)(`span`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[(0,D.jsx)(h,{label:`dates`,value:r,allLabel:null,align:`end`,options:[{value:`plan`},{value:`actual`}],onChange:e=>a(e)}),(0,D.jsx)(h,{label:`group`,value:C,allLabel:null,align:`end`,options:S.map(e=>({value:e})),onChange:y})]})]}),(0,D.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,D.jsxs)(`div`,{className:`relative min-h-full`,style:{minWidth:u},children:[(0,D.jsxs)(`div`,{"aria-hidden":`true`,className:`sticky top-0 z-[2] flex items-stretch border-b bg-card`,style:{height:I},children:[(0,D.jsx)(`span`,{className:`flex items-center border-r px-3.5 text-[10px] uppercase tracking-[0.08em] text-muted-foreground`,style:{width:c,flex:`0 0 ${c}px`},children:`card`}),(0,D.jsx)(`span`,{className:`relative flex-1`,children:N.ticks.map((e,t)=>(0,D.jsx)(`span`,{className:`text-[10px] uppercase tracking-[0.08em] text-muted-foreground`,style:{position:`absolute`,top:`50%`,transform:`translateY(-50%)`,left:`${e.left}%`,width:`${(N.ticks[t+1]?.left??100)-e.left}%`,overflow:`hidden`,paddingLeft:8,whiteSpace:`nowrap`},children:e.label},e.key))})]}),(0,D.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute`,style:{top:I,bottom:0,left:c,right:0},children:[N.ticks.map(e=>(0,D.jsx)(`span`,{className:`absolute inset-y-0 w-px bg-border`,style:{left:`${e.left}%`}},e.key)),N.today!=null&&(0,D.jsx)(`span`,{className:`absolute inset-y-0 w-px`,style:{background:o(`error`),opacity:.55,left:`${N.today}%`}})]}),(0,D.jsxs)(`div`,{className:`relative`,children:[M.length>0&&(0,D.jsx)(`svg`,{"aria-hidden":`true`,preserveAspectRatio:`none`,viewBox:`0 0 100 ${A.length}`,className:`pointer-events-none absolute top-0 h-full`,style:{left:c,width:`calc(100% - ${c}px)`},children:M.map(e=>{let t=O.get(e.from),n=O.get(e.to);if(!t||!n)return null;let r=N.pct(t.to),i=N.pct(n.from),a=j.get(e.from)+.5,s=j.get(e.to)+.5;return(0,D.jsx)(`path`,{d:`M ${r} ${a} C ${(r+i)/2} ${a}, ${(r+i)/2} ${s}, ${i} ${s}`,vectorEffect:`non-scaling-stroke`,style:i<r?{fill:`none`,stroke:o(`error`),strokeWidth:1.5,strokeDasharray:`3 2`}:{fill:`none`,stroke:`var(--muted-foreground)`,strokeWidth:1.5,opacity:.4}},`${e.from}-${e.to}`)})}),A.map((e,n)=>e.task?(0,D.jsx)(L,{task:e.task,span:O.get(e.task.id),mode:r,epicId:t.get(e.task.id),pct:N.pct,labelWidth:c,onOpen:s},e.task.id):(0,D.jsx)(`div`,{className:`border-b bg-muted/40`,children:(0,D.jsx)(`span`,{className:`flex items-center px-3.5 text-[10px] uppercase tracking-[0.08em] text-muted-foreground`,style:{height:`var(--row-h)`},children:e.label})},`group-${n}-${e.label}`))]})]})})]})}export{P as EpicsView,N as FlowBoard,R as TimelineView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{U as r,_t as i,kt as a,nt as o,q as s,vt as c}from"./ui-primitives-DRENhlck.js";import{r as l,s as u,u as d}from"./theme-CcOVK72d.js";import{$ as f,A as ee,B as te,C as p,D as ne,E as m,I as re,M as ie,P as ae,R as oe,S as se,T as h,_ as g,b as _,c as ce,d as le,et as ue,f as de,g as v,h as y,it as b,k as fe,l as pe,m as x,nt as S,p as me,q as C,rt as w,v as he,w as ge,x as _e,y as T,z as ve}from"./index-DnoD4yDd.js";import{t as ye}from"./layout-QiuZ_k5v.js";var E=e(t(),1),D=n(),O=`doc-h`,be=[`current`,`draft`,`superseded`,`archived`],k=`text-[10px] font-medium tracking-[0.07em] uppercase text-muted-foreground`;function xe({document:e,selected:t,onSelect:n}){return(0,D.jsx)(m,{asChild:!0,size:`sm`,className:d(`w-full cursor-pointer flex-col items-start gap-0.5 px-2 py-1.5 text-left hover:bg-accent`,t&&`bg-accent`),children:(0,D.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,children:[(0,D.jsxs)(`span`,{className:`flex w-full items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`flex-1 truncate text-xs font-medium`,children:e.title}),(0,D.jsx)(`span`,{className:d(`font-mono text-[10px]`,!e.managed&&`text-muted-foreground`),style:e.managed?{color:l(e.status)}:void 0,children:e.managed?e.status:`indexed`})]}),(0,D.jsx)(`span`,{className:`w-full truncate font-mono text-[10px] text-muted-foreground`,children:e.path})]})})}function Se({entries:e,activeId:t,onJump:n}){let r=Math.min(...e.map(e=>e.level));return(0,D.jsxs)(`aside`,{"aria-label":`Document outline`,className:`hidden w-[228px] shrink-0 overflow-y-auto border-l px-3 py-6.5 xl:block`,children:[(0,D.jsx)(`span`,{className:d(k,`px-2`),children:`on this page`}),(0,D.jsx)(`nav`,{className:`mt-2 flex flex-col gap-px`,children:e.map(e=>{let i=e.id===t;return(0,D.jsx)(`button`,{type:`button`,"aria-current":i?`true`:void 0,className:d(`cursor-pointer rounded-md px-2 py-1 text-left text-xs leading-snug transition-colors hover:bg-accent`,i?`bg-accent font-medium text-foreground`:`text-muted-foreground`),style:{paddingLeft:`${8+Math.min(e.level-r,3)*12}px`},onClick:()=>n(e.id),children:e.text},e.id)})})]})}function A({label:e,value:t}){return(0,D.jsxs)(g,{className:`w-auto min-w-[120px] gap-0.5 rounded-lg border bg-card px-3 py-2 shadow-xs`,children:[(0,D.jsx)(`span`,{className:k,children:e}),(0,D.jsx)(`span`,{className:`text-[13px] font-medium`,children:t})]})}function j({label:e,links:t,onOpen:n}){return t.length?(0,D.jsxs)(`section`,{className:`flex flex-col gap-1.5`,children:[(0,D.jsx)(`span`,{className:k,children:e}),t.map((e,t)=>{let r=!e.exists&&!e.title;return(0,D.jsx)(m,{asChild:!0,variant:`outline`,size:`sm`,className:d(`w-full cursor-pointer gap-2 px-2.5 py-2 text-left hover:bg-accent`,r&&`cursor-default opacity-55 hover:bg-transparent`),children:(0,D.jsxs)(`button`,{type:`button`,disabled:r,onClick:()=>n(e.id),children:[(0,D.jsx)(`span`,{className:`min-w-[78px] shrink-0 font-mono text-[11px] font-medium`,children:e.id}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-muted-foreground`,children:e.title||(e.exists===!1?`Missing record`:e.id)}),(e.relations??[e.relation]).filter(Boolean).map(e=>(0,D.jsx)(S,{variant:`secondary`,className:`font-mono text-[10px]`,children:e},e))]})},`${e.id}-${t}`)})]}):null}var M=(0,D.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted-foreground`,children:`·`});function N({id:e,onSelect:t,onOpen:n}){let[r,i]=(0,E.useState)(null),[a,o]=(0,E.useState)(``),s=(0,E.useRef)(null),d=(0,E.useMemo)(()=>r?_e(r.body||``,O):[],[r]);return(0,E.useEffect)(()=>{let t=!0;return i(null),o(``),C.record(e).then(e=>{t&&i(e.record)}).catch(e=>{t&&o(e.message)}),()=>{t=!1}},[e]),a?(0,D.jsx)(`div`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:a}):r?(0,D.jsxs)(`div`,{ref:s,className:`flex min-h-0 flex-1 flex-col overflow-y-auto px-4 py-3`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 font-mono text-[11px] text-muted-foreground`,children:[(0,D.jsx)(`span`,{children:r.id}),M,(0,D.jsx)(`span`,{children:r.documentKind}),M,(0,D.jsx)(`span`,{style:{color:l(r.status)},children:r.status}),M,(0,D.jsx)(`span`,{children:r.managed?`managed`:`indexed`}),(0,D.jsxs)(u,{type:`button`,variant:`ghost`,size:`sm`,className:`ml-auto px-2`,onClick:()=>n(e),children:[(0,D.jsx)(c,{"aria-hidden":`true`,className:`size-3`}),`Open in Docs`]})]}),(0,D.jsx)(`h2`,{className:`mt-1 text-sm font-medium`,children:r.title}),(0,D.jsx)(`p`,{className:`font-mono text-[11px] text-muted-foreground`,children:r.path}),r.freshness?.length?(0,D.jsx)(w,{className:`mt-3`,children:(0,D.jsx)(b,{children:r.freshness.map(e=>e.message).join(` `)})}):null,(0,D.jsxs)(`div`,{className:`mt-3 flex min-w-0 items-start gap-1`,children:[(0,D.jsx)(`div`,{className:`min-w-0 flex-1 [&>.typeset]:[--typeset-leading:1.6] [&>.typeset]:[--typeset-size:0.8125rem] [&>.typeset>:not(.typeset-scroll)]:max-w-[72ch]`,children:(0,D.jsx)(_,{source:r.body||`_This document is empty._`,onOpen:t,headingPrefix:O})}),(0,D.jsx)(x,{entries:d,container:s})]})]}):(0,D.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground`,children:[(0,D.jsx)(h,{}),` Reading `,e,`…`]})}function P({selectedId:e,onSelect:t,onOpenCard:n,search:c,onSearchChange:m}){let x=ge(),[S,N]=(0,E.useState)([]),[P,F]=(0,E.useState)(!0),[I,L]=(0,E.useState)(``),[R,Ce]=(0,E.useState)(!1),[z,we]=(0,E.useState)(!1),[B,V]=(0,E.useState)(null),[H,U]=(0,E.useState)(!1),[W,G]=(0,E.useState)(``),[K,Te]=(0,E.useState)(null),[Ee,q]=(0,E.useState)(0);te(e=>{ve(e,`/docs/`,`docs/`)&&q(e=>e+1)}),(0,E.useEffect)(()=>{let e=!1;F(!0);let t=window.setTimeout(()=>{C.docs(c.trim()).then(t=>{e||(N(t.records),L(``))}).catch(t=>{e||L(t instanceof Error?t.message:String(t))}).finally(()=>{e||F(!1)})},c?180:0);return()=>{e=!0,window.clearTimeout(t)}},[c,Ee]),(0,E.useEffect)(()=>{if(!B||K)return;let e=!1;return C.tasks().then(t=>{e||Te(t.schema.docs)}).catch(()=>{}),()=>{e=!0}},[B,K]);let J=(0,E.useMemo)(()=>R?S.filter(e=>e.managed):S,[S,R]),De=(0,E.useMemo)(()=>{let e=J.filter(e=>e.managed),t=J.filter(e=>!e.managed);return[{key:`managed`,label:`.project/docs · managed`,docs:e},{key:`indexed`,label:`indexed · read only`,docs:t}].filter(e=>e.docs.length>0)},[J]),Oe=ue(),Y=J.find(t=>t.id===e)||(Oe?void 0:J[0]),ke=(0,E.useRef)(null),[Ae,X]=(0,E.useState)(``),Z=(0,E.useMemo)(()=>Y&&!z?_e(Y.body,O):[],[Y,z]),Q=Z.length>1;(0,E.useEffect)(()=>{X(``);let e=ke.current;if(!e||!Q)return;let t=new Map,n=new IntersectionObserver(e=>{for(let n of e)t.set(n.target.id,n.isIntersecting);let n=Z.find(e=>t.get(e.id));n&&X(n.id)},{root:e,rootMargin:`0px 0px -66% 0px`,threshold:0});for(let e of Z){let t=document.getElementById(e.id);t&&n.observe(t)}return()=>n.disconnect()},[Z,Q]);let je=e=>{document.getElementById(e)?.scrollIntoView({block:`start`,behavior:`smooth`}),X(e)},$=e=>{let r=S.find(t=>t.id===e);r?t(r.id):n(e)},Me=(0,E.useMemo)(()=>{let e=new Set(K?.kinds??[]);for(let t of S)t.managed&&e.add(t.documentKind);return B&&e.add(B.kind),[...e].sort()},[K,S,B]),Ne=(0,E.useMemo)(()=>{let e=new Set(K?.statuses??be);for(let t of S)t.managed&&e.add(t.status);return B&&e.add(B.status),[...e].sort()},[K,S,B]);function Pe(e){G(``),V({id:e.id,title:e.title,kind:e.documentKind,status:e.status,owners:(e.owners??[]).join(`, `),reviewed:e.reviewed??``})}async function Fe(){if(!B)return;let e=S.find(e=>e.id===B.id);if(!e){G(`This document no longer exists in the workspace.`);return}let t=B.owners.split(`,`).map(e=>e.trim()).filter(Boolean),n={},r=B.title.trim();if(r&&r!==e.title&&(n.title=r),B.kind!==e.documentKind&&(n.kind=B.kind),B.status!==e.status&&(n.status=B.status),t.join(`
`)!==(e.owners??[]).join(`
`)&&(n.owners=t),(B.reviewed||``)!==(e.reviewed??``)&&(n.reviewed=B.reviewed||null),!Object.keys(n).length){V(null);return}U(!0),G(``);try{let t=await C.patchDocument(e.id,n,e.revision);N(n=>n.map(n=>n.id===e.id?t.record:n)),V(null)}catch(e){let t=e;t.code?.endsWith(`WRITE_CONFLICT`)?(q(e=>e+1),G(`The document changed on disk; the list was refreshed. Save again to apply your changes to the latest revision.`)):G(t.message||String(e))}finally{U(!1)}}return(0,D.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,D.jsxs)(`aside`,{"aria-label":`Documents`,className:d(`min-h-0 w-full shrink-0 flex-col border-r px-2 py-3 lg:flex lg:w-[290px]`,Y?`hidden`:`flex`),children:[(0,D.jsx)(re,{className:`pb-2.5`,before:(0,D.jsx)(ae,{scope:`records`,value:c,label:`Search documentation`,onChange:m}),children:(0,D.jsx)(oe,{label:`managed`,on:R,onLabel:`only`,offLabel:`all`,onChange:Ce})}),(0,D.jsx)(`div`,{"aria-busy":P||void 0,className:`min-h-0 flex-1 overflow-y-auto`,children:P?(0,D.jsxs)(`span`,{className:`flex items-center gap-2 px-2 py-1.5 font-mono text-[10.5px] text-muted-foreground`,children:[(0,D.jsx)(h,{className:`size-3`}),`Loading documents…`]}):I?(0,D.jsx)(w,{variant:`destructive`,className:`mt-1.5`,children:(0,D.jsx)(b,{children:I})}):De.length?De.map(e=>(0,D.jsxs)(`div`,{className:`flex flex-col gap-px pb-3.5`,children:[(0,D.jsxs)(`span`,{className:`flex items-center gap-2 px-2 py-1.5 font-mono text-[10.5px] text-muted-foreground`,children:[(0,D.jsx)(`span`,{className:`text-foreground/80`,children:e.label}),(0,D.jsx)(`span`,{children:e.docs.length})]}),e.docs.map(e=>(0,D.jsx)(xe,{document:e,selected:Y?.id===e.id,onSelect:()=>t(e.id)},e.id))]},e.key)):(0,D.jsx)(ne,{className:`gap-2 p-4 md:p-4`,children:(0,D.jsxs)(ee,{children:[(0,D.jsx)(ie,{className:`text-sm`,children:`No documents found.`}),(0,D.jsx)(fe,{className:`text-xs`,children:R?`Try another search, or include indexed files.`:`Try another search.`})]})})})]}),(0,D.jsx)(`section`,{ref:ke,className:d(`min-w-0 flex-1 overflow-y-auto px-6 py-6.5 sm:px-8.5`,Y?`block`:`hidden lg:block`),children:(0,D.jsx)(`div`,{className:ye,children:Y?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(u,{type:`button`,variant:`ghost`,size:`sm`,className:`-ml-2 mb-2 lg:hidden`,onClick:()=>t(null),children:[(0,D.jsx)(a,{"aria-hidden":`true`}),`All documents`]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 font-mono text-[11px] text-muted-foreground`,children:[(0,D.jsx)(`span`,{children:Y.id}),M,(0,D.jsx)(`span`,{children:Y.documentKind}),M,(0,D.jsx)(`span`,{style:{color:l(Y.status)},children:Y.status}),M,(0,D.jsx)(`span`,{children:Y.managed?`managed`:`indexed`}),(0,D.jsx)(`span`,{className:`flex-1`}),Y.managed?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(u,{type:`button`,variant:`outline`,size:`sm`,disabled:x,title:x?p:void 0,onClick:()=>we(e=>!e),children:[z?(0,D.jsx)(i,{"aria-hidden":`true`}):(0,D.jsx)(o,{"aria-hidden":`true`}),z?`Preview`:`Edit`]}),(0,D.jsxs)(u,{type:`button`,variant:`outline`,size:`sm`,disabled:x,title:x?p:void 0,onClick:()=>Pe(Y),children:[(0,D.jsx)(s,{"aria-hidden":`true`}),`Metadata`]})]}):null]}),(0,D.jsx)(`h2`,{className:`mt-3 mb-1.5 text-2xl font-semibold tracking-tight`,children:Y.title}),(0,D.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground [overflow-wrap:anywhere]`,children:Y.path}),(0,D.jsxs)(`div`,{className:`mt-4.5 flex flex-wrap gap-2`,children:[(0,D.jsx)(A,{label:`kind`,value:Y.documentKind}),(0,D.jsx)(A,{label:`status`,value:Y.status}),(0,D.jsx)(A,{label:`reviewed`,value:Y.reviewed||`—`}),(0,D.jsx)(A,{label:`owners`,value:Y.owners?.join(`, `)||`—`}),(0,D.jsx)(A,{label:`backlinks`,value:String(Y.incomingTotal??Y.incoming.length)}),Y.updated?(0,D.jsx)(A,{label:`updated`,value:Y.updated}):null]}),Y.freshness.length>0?(0,D.jsxs)(w,{role:`status`,className:`mt-4.5 max-w-2xl`,children:[(0,D.jsx)(r,{"aria-hidden":`true`,className:`text-sev-warning`}),(0,D.jsx)(b,{children:Y.freshness.map(e=>(0,D.jsx)(`span`,{children:e.message},`${e.code}-${e.message}`))})]}):null,(0,D.jsx)(`div`,{className:`mt-6.5`,children:z&&Y.managed?(0,D.jsx)(se,{value:Y.body,revision:Y.revision,onSave:async(e,t)=>{let n=await C.patchDocument(Y.id,{body:e},t);N(e=>e.map(e=>e.id===Y.id?n.record:e))}},Y.id):Y.body.trim()?(0,D.jsx)(_,{source:Y.body,headingPrefix:O,onOpen:$}):(0,D.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Y.managed?`This document is empty. Use Edit to write its first version.`:`This file has no body to render.`})}),Y.outgoing.length||Y.incoming.length||Y.scope?.length?(0,D.jsxs)(`div`,{className:`mt-7 flex max-w-[70ch] flex-col gap-4.5`,children:[(0,D.jsx)(j,{label:`links to`,links:Y.outgoing,onOpen:$}),(0,D.jsx)(j,{label:(Y.incomingTotal??Y.incoming.length)>Y.incoming.length?`backlinks (${Y.incoming.length} of ${Y.incomingTotal})`:`backlinks`,links:Y.incoming,onOpen:$}),Y.scope?.length?(0,D.jsxs)(`section`,{className:`flex flex-col gap-1.5`,children:[(0,D.jsx)(`span`,{className:k,children:`scope`}),Y.scope.map(e=>(0,D.jsx)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground [overflow-wrap:anywhere]`,children:e},e))]}):null]}):null]}):(0,D.jsx)(`div`,{className:`flex h-full items-center justify-center text-xs text-muted-foreground`,children:P?`Loading documents…`:`Select a document from the list to read it.`})})}),Q?(0,D.jsx)(Se,{entries:Z,activeId:Ae,onJump:je}):null,(0,D.jsx)(ce,{open:B!==null,onOpenChange:e=>{!e&&!H&&V(null)},children:(0,D.jsxs)(pe,{"aria-describedby":void 0,children:[(0,D.jsx)(de,{children:(0,D.jsx)(me,{children:`Edit metadata${B?` — ${B.id}`:``}`})}),B?(0,D.jsxs)(he,{className:`gap-4`,children:[(0,D.jsxs)(g,{children:[(0,D.jsx)(T,{htmlFor:`docs-meta-title`,children:`title`}),(0,D.jsx)(f,{id:`docs-meta-title`,value:B.title,onChange:e=>V({...B,title:e.target.value})})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,D.jsxs)(g,{className:`[&_[data-slot=native-select-wrapper]]:w-full`,children:[(0,D.jsx)(T,{htmlFor:`docs-meta-kind`,children:`kind`}),(0,D.jsx)(y,{id:`docs-meta-kind`,value:B.kind,onChange:e=>V({...B,kind:e.target.value}),children:Me.map(e=>(0,D.jsx)(v,{value:e,children:e},e))})]}),(0,D.jsxs)(g,{className:`[&_[data-slot=native-select-wrapper]]:w-full`,children:[(0,D.jsx)(T,{htmlFor:`docs-meta-status`,children:`status`}),(0,D.jsx)(y,{id:`docs-meta-status`,value:B.status,onChange:e=>V({...B,status:e.target.value}),children:Ne.map(e=>(0,D.jsx)(v,{value:e,children:e},e))})]})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,D.jsxs)(g,{children:[(0,D.jsx)(T,{htmlFor:`docs-meta-owners`,children:`owners`}),(0,D.jsx)(f,{id:`docs-meta-owners`,value:B.owners,placeholder:`comma-separated`,onChange:e=>V({...B,owners:e.target.value})})]}),(0,D.jsxs)(g,{children:[(0,D.jsx)(T,{htmlFor:`docs-meta-reviewed`,children:`reviewed`}),(0,D.jsx)(f,{id:`docs-meta-reviewed`,type:`date`,value:B.reviewed,onChange:e=>V({...B,reviewed:e.target.value})})]})]}),W?(0,D.jsx)(w,{variant:`destructive`,children:(0,D.jsx)(b,{children:W})}):null]}):null,(0,D.jsxs)(le,{children:[(0,D.jsx)(u,{type:`button`,variant:`outline`,disabled:H,onClick:()=>V(null),children:`Cancel`}),(0,D.jsx)(u,{type:`button`,disabled:H,onClick:()=>void Fe(),children:H?`Saving…`:`Save`})]})]})})]})}export{N as DocPanel,P as DocsView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{D as r,E as i,Ft as a,It as o,jt as s,q as ee,wt as te}from"./ui-primitives-DRENhlck.js";import{n as c,o as l,s as u,u as d}from"./theme-CcOVK72d.js";import{A as ne,D as f,J as re,M as ie,N as ae,Q as oe,X as se,Y as ce,Z as le,a as p,g as m,h,i as ue,k as de,o as g,s as fe}from"./index-DnoD4yDd.js";import{t as _}from"./progress-CzHcd1lF.js";var v=e(t(),1),y=n();function b({className:e,...t}){return(0,y.jsx)(i,{"data-slot":`checkbox`,className:d(`peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary`,e),...t,children:(0,y.jsx)(r,{"data-slot":`checkbox-indicator`,className:`grid place-content-center text-current transition-none`,children:(0,y.jsx)(s,{className:`size-3.5`})})})}function pe({className:e,...t}){return(0,y.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,y.jsx)(`table`,{"data-slot":`table`,className:d(`w-full caption-bottom text-sm`,e),...t})})}function me({className:e,...t}){return(0,y.jsx)(`thead`,{"data-slot":`table-header`,className:d(`[&_tr]:border-b`,e),...t})}function he({className:e,...t}){return(0,y.jsx)(`tbody`,{"data-slot":`table-body`,className:d(`[&_tr:last-child]:border-0`,e),...t})}function x({className:e,...t}){return(0,y.jsx)(`tr`,{"data-slot":`table-row`,className:d(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,e),...t})}function S({className:e,...t}){return(0,y.jsx)(`th`,{"data-slot":`table-head`,className:d(`h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function C({className:e,...t}){return(0,y.jsx)(`td`,{"data-slot":`table-cell`,className:d(`p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}var w=[[`id`,`id`],[`title`,`title · claim`],[`status`,`status`],[`priority`,`prio`],[`type`,`type`],[`area`,`area`],[`epic`,`links`],[`updated`,`updated`]],T=new Map(p.map((e,t)=>[e,t])),E=new Map(g.map((e,t)=>[e,t])),D=w.length+1;function O(e,t){let n=new Map;for(let r of e){let e=r[t];typeof e==`string`&&n.set(e,(n.get(e)||0)+1)}return n}function k({title:e,values:t,counts:n,selected:r,color:i,onSelect:a}){let o=t.filter(e=>n.has(e));if(!o.length)return null;let s=Math.max(...o.map(e=>n.get(e)||0));return(0,y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,y.jsx)(`span`,{className:`px-1.5 font-mono text-[10px] tracking-widest uppercase text-muted-foreground`,children:e}),o.map(e=>{let t=n.get(e)||0,o=r===e;return(0,y.jsxs)(`button`,{type:`button`,"aria-pressed":o,onClick:()=>a(o?``:e),className:d(`flex w-full cursor-pointer flex-col gap-1 rounded-md px-1.5 py-1 text-left transition-colors hover:bg-accent/50`,o&&`bg-accent`),children:[(0,y.jsxs)(`span`,{className:`flex w-full items-center gap-1.5`,children:[(0,y.jsx)(`span`,{className:d(`min-w-0 flex-1 truncate text-xs`,o?`font-medium text-foreground`:`text-muted-foreground`),children:e}),(0,y.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:t})]}),(0,y.jsx)(_,{value:s?Math.round(t/s*100):0,className:d(`h-[5px] bg-muted [&>div]:bg-current`,!i&&`text-primary`),style:i?{color:i(e)}:void 0})]},e)})]})}function A({label:e,value:t,options:n,color:r,withDot:i,onChange:a}){return(0,y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,style:{color:r},children:[i?(0,y.jsx)(`span`,{className:`size-1.5 shrink-0 rounded-full bg-current`,"aria-hidden":`true`}):null,(0,y.jsx)(h,{"aria-label":e,value:t,onChange:e=>a(e.target.value),className:`h-[22px] cursor-pointer border-transparent bg-transparent px-1 py-0 pr-8 font-mono text-[11px] text-inherit shadow-none dark:bg-transparent dark:hover:bg-transparent`,children:n.map(e=>(0,y.jsx)(m,{value:e,children:e},e))})]})}var ge=(0,v.memo)(function({task:e,epicId:t,checked:n,isOpen:r,onToggle:i,onOpen:a,onPatch:o}){let s=(e.depends?.length??0)+ +!!e.parent;return(0,y.jsxs)(x,{className:`h-[var(--row-h)] cursor-pointer`,"data-state":r?`selected`:void 0,tabIndex:0,onClick:()=>a(e.id),onKeyDown:t=>{t.key===`Enter`&&a(e.id)},children:[(0,y.jsx)(C,{className:d(`w-7 border-l-2 border-l-transparent`,r&&`border-l-primary`),onClick:e=>e.stopPropagation(),children:(0,y.jsx)(b,{"aria-label":`Select ${e.id}`,checked:n,onCheckedChange:()=>i(e.id)})}),(0,y.jsx)(C,{className:`font-mono text-xs text-muted-foreground`,children:e.id}),(0,y.jsx)(C,{className:`max-w-[520px]`,children:(0,y.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,y.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:e.title}),e.claimed_by?(0,y.jsxs)(`span`,{className:`font-mono text-[10px] whitespace-nowrap text-muted-foreground/60`,children:[`· `,e.claimed_by]}):null]})}),(0,y.jsx)(C,{onClick:e=>e.stopPropagation(),children:(0,y.jsx)(A,{label:`Status for ${e.id}`,value:e.status,options:g,color:l(e.status),withDot:!0,onChange:t=>void o(e.id,{status:t}).catch(()=>void 0)})}),(0,y.jsx)(C,{onClick:e=>e.stopPropagation(),children:(0,y.jsx)(A,{label:`Priority for ${e.id}`,value:e.priority,options:p,color:c(e.priority),onChange:t=>void o(e.id,{priority:t}).catch(()=>void 0)})}),(0,y.jsx)(C,{className:`font-mono text-[11px] text-muted-foreground`,children:e.type}),(0,y.jsx)(C,{className:`font-mono text-[11px] text-muted-foreground`,children:e.area}),(0,y.jsxs)(C,{className:`font-mono text-[11px] text-muted-foreground/60`,children:[t?(0,y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a(t)},className:d(`cursor-pointer text-primary hover:underline`,s>0&&`mr-1.5`),children:t}):null,s>0?`${s} ↔`:t?null:`—`]}),(0,y.jsx)(C,{className:`font-mono text-[11px] text-muted-foreground/60`,children:e.updated||`—`})]})});function j({tasks:e,allTasks:t,areas:n,filters:r,setFilters:i,epicIds:s,onOpen:d,onPatch:_,onBulkPatch:C}){let[A,j]=(0,v.useState)(()=>new Set),[_e,ve]=(0,v.useState)(null),[M,ye]=(0,v.useState)(`id`),[N,P]=(0,v.useState)(`desc`),[F,I]=(0,v.useState)(``),[L,R]=(0,v.useState)(``),[z,B]=(0,v.useState)(``),V=(0,v.useRef)(null),[H,be]=(0,v.useState)({start:0,end:40}),[U,xe]=(0,v.useState)(40),W=(0,v.useDeferredValue)(r),G=(0,v.useMemo)(()=>{let e=e=>ue(t,{...W,...e});return{status:O(e({status:``}),`status`),type:O(e({type:``,showIdeas:!0}),`type`),priority:O(e({priority:``}),`priority`),area:O(e({area:``}),`area`)}},[t,W]),K=(0,v.useMemo)(()=>{let t=[...e];return t.sort((e,t)=>{let n=0;return n=M===`priority`?(T.get(e.priority)||0)-(T.get(t.priority)||0):M===`status`?(E.get(e.status)||0)-(E.get(t.status)||0):M===`epic`?(s.get(e.id)||``).localeCompare(s.get(t.id)||``):String(e[M]||``).localeCompare(String(t[M]||``),void 0,{numeric:!0}),N===`asc`?n:-n}),t},[s,N,M,e]),q=(0,v.useRef)(0),Se=K.length>0,J=(0,v.useCallback)(()=>{let e=V.current;if(!e)return;let t=parseFloat(getComputedStyle(document.documentElement).getPropertyValue(`--row-h`))||40;xe(t);let n=Math.max(0,Math.floor(e.scrollTop/t)-10),r=Math.ceil(e.clientHeight/t);be({start:n,end:Math.min(q.current,n+r+20)})},[]);(0,v.useEffect)(()=>{let e=V.current;if(!e)return;e.addEventListener(`scroll`,J,{passive:!0}),window.addEventListener(`resize`,J);let t=new MutationObserver(J);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-density`]}),()=>{e.removeEventListener(`scroll`,J),window.removeEventListener(`resize`,J),t.disconnect()}},[J,Se]),(0,v.useEffect)(()=>{q.current=K.length,J()},[J,K.length]);let Ce=[r.search,r.status,r.area,r.type,r.priority,r.milestone,r.showIdeas,r.showClosed,M,N].join(`|`);(0,v.useEffect)(()=>{V.current&&(V.current.scrollTop=0),J()},[Ce,J]);let we=(0,v.useCallback)(e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Te=(0,v.useCallback)(e=>{ve(e),d(e)},[d]),Y=(0,v.useMemo)(()=>K.map(e=>e.id),[K]),X=Y.length>0&&Y.every(e=>A.has(e)),Ee=Y.some(e=>A.has(e)),De=K.slice(H.start,H.end),Z=!!(F||L||z);function Oe(e){M===e?P(e=>e===`asc`?`desc`:`asc`):(ye(e),P(e===`id`?`desc`:`asc`))}async function ke(){let e={};if(F&&(e.status=F),L&&(e.priority=L),z&&(e.area=z),!(!Z||A.size===0))try{await C([...A],e),j(new Set),I(``),R(``),B(``)}catch{}}let Q=(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(k,{title:`status`,values:g,counts:G.status,selected:r.status,color:l,onSelect:e=>i(t=>({...t,status:e}))}),(0,y.jsx)(k,{title:`priority`,values:p,counts:G.priority,selected:r.priority,color:c,onSelect:e=>i(t=>({...t,priority:e}))}),(0,y.jsx)(k,{title:`area`,values:n,counts:G.area,selected:r.area,onSelect:e=>i(t=>({...t,area:e}))}),(0,y.jsx)(k,{title:`type`,values:fe,counts:G.type,selected:r.type,onSelect:e=>i(t=>({...t,type:e}))})]}),$=[r.status,r.priority,r.area,r.type].filter(Boolean).length;return(0,y.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,y.jsx)(`aside`,{"aria-label":`Backlog facets`,className:`hidden w-[204px] flex-none flex-col gap-5 overflow-y-auto border-r px-3.5 py-4 lg:flex`,children:Q}),(0,y.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,y.jsxs)(`div`,{className:`flex flex-none items-center gap-2 px-3.5 pt-2.5 lg:hidden`,children:[(0,y.jsxs)(re,{children:[(0,y.jsx)(oe,{asChild:!0,children:(0,y.jsxs)(u,{variant:`outline`,size:`sm`,children:[(0,y.jsx)(ee,{className:`size-3.5`}),`Facets`,$?(0,y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:$}):null]})}),(0,y.jsxs)(ce,{side:`left`,className:`w-[280px] gap-0 sm:max-w-[280px]`,children:[(0,y.jsx)(se,{className:`pb-2`,children:(0,y.jsx)(le,{className:`font-mono text-[11px] tracking-wide uppercase`,children:`Facets`})}),(0,y.jsx)(`div`,{className:`flex flex-col gap-5 overflow-y-auto px-4 pb-4`,children:Q})]})]}),(0,y.jsxs)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground/70`,children:[K.length.toLocaleString(),` row`,K.length===1?``:`s`,` · scroll sideways for every column`]})]}),A.size>0&&(0,y.jsxs)(`div`,{role:`region`,"aria-label":`Bulk actions`,className:`mx-3.5 mt-2.5 mb-2.5 flex flex-none flex-wrap items-center gap-2 rounded-md border bg-muted/50 px-3 py-2`,children:[(0,y.jsxs)(`span`,{className:`font-mono text-[11px]`,children:[A.size,` selected`]}),(0,y.jsxs)(h,{"aria-label":`Set status`,value:F,onChange:e=>I(e.target.value),size:`sm`,children:[(0,y.jsx)(m,{value:``,children:`status…`}),g.map(e=>(0,y.jsx)(m,{value:e,children:e},e))]}),(0,y.jsxs)(h,{"aria-label":`Set priority`,value:L,onChange:e=>R(e.target.value),size:`sm`,children:[(0,y.jsx)(m,{value:``,children:`priority…`}),p.map(e=>(0,y.jsx)(m,{value:e,children:e},e))]}),(0,y.jsxs)(h,{"aria-label":`Set area`,value:z,onChange:e=>B(e.target.value),size:`sm`,children:[(0,y.jsx)(m,{value:``,children:`area…`}),n.map(e=>(0,y.jsx)(m,{value:e,children:e},e))]}),(0,y.jsxs)(ae,{children:[(0,y.jsx)(u,{size:`sm`,disabled:!Z,onClick:()=>void ke(),children:`Apply`}),(0,y.jsx)(u,{size:`sm`,variant:`outline`,onClick:()=>j(new Set),children:`Clear`})]})]}),K.length===0?(0,y.jsx)(f,{children:(0,y.jsxs)(ne,{children:[(0,y.jsx)(ie,{children:`No cards match`}),(0,y.jsx)(de,{children:`Adjust filters or clear the search`})]})}):(0,y.jsx)(`div`,{ref:V,className:`min-w-0 flex-1 overflow-auto [&>[data-slot=table-container]]:overflow-visible`,children:(0,y.jsxs)(pe,{className:`text-[13px]`,children:[(0,y.jsx)(me,{children:(0,y.jsxs)(x,{className:`hover:bg-transparent`,children:[(0,y.jsx)(S,{className:`sticky top-0 z-10 w-7 bg-background`,children:(0,y.jsx)(b,{"aria-label":`Select all matching cards`,checked:X?!0:Ee?`indeterminate`:!1,onCheckedChange:()=>j(e=>{let t=new Set(e);return X?Y.forEach(e=>t.delete(e)):Y.forEach(e=>t.add(e)),t})})}),w.map(([e,t])=>(0,y.jsx)(S,{"aria-sort":M===e?N===`asc`?`ascending`:`descending`:`none`,className:`sticky top-0 z-10 bg-background`,children:(0,y.jsxs)(u,{variant:`ghost`,size:`sm`,onClick:()=>Oe(e),className:`-ml-2 px-2 text-muted-foreground`,children:[t,M===e?N===`asc`?(0,y.jsx)(a,{className:`size-3`}):(0,y.jsx)(o,{className:`size-3`}):(0,y.jsx)(te,{className:`size-3 opacity-50`})]})},e))]})}),(0,y.jsxs)(he,{children:[H.start>0&&(0,y.jsx)(`tr`,{"aria-hidden":`true`,children:(0,y.jsx)(`td`,{colSpan:D,style:{height:H.start*U}})}),De.map(e=>(0,y.jsx)(ge,{task:e,epicId:s.get(e.id)||``,checked:A.has(e.id),isOpen:_e===e.id,onToggle:we,onOpen:Te,onPatch:_},e.id)),H.end<K.length&&(0,y.jsx)(`tr`,{"aria-hidden":`true`,children:(0,y.jsx)(`td`,{colSpan:D,style:{height:(K.length-H.end)*U}})})]})]})})]})]})}export{j as Explorer};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{Ct as r}from"./ui-primitives-DRENhlck.js";import{i,o as a,s as o}from"./theme-CcOVK72d.js";import{A as s,B as c,D as l,H as u,M as d,T as f,V as p,it as m,j as h,k as g,nt as _,q as v,rt as y}from"./index-DnoD4yDd.js";var b=e(t(),1),x=n(),S=[{level:`error`,label:`errors`,hint:`must be fixed for a consistent workspace`,zeroHint:`the doctor does not block the release`},{level:`warning`,label:`warnings`,hint:`worth a look, nothing is broken yet`,zeroHint:`nothing worth flagging`},{level:`info`,label:`infos`,hint:`informational, no action required`,zeroHint:`no notices from the doctor`}];function C(e){return e.replace(/[-_.]+/g,` `)}var w={error:0,warning:1,info:2};function T({onOpen:e}){let[t,n]=(0,b.useState)(null),[T,E]=(0,b.useState)(``),[D,O]=(0,b.useState)(``),[k,A]=(0,b.useState)(0);c(()=>A(e=>e+1)),(0,b.useEffect)(()=>{let e=!0;return v.health().then(t=>{e&&n(t)}).catch(t=>{e&&E(t instanceof Error?t.message:String(t))}),()=>{e=!1}},[k]);let j=(0,b.useMemo)(()=>{if(!t)return[];let e=D?t.issues.filter(e=>e.severity===D):t.issues,n=new Map;for(let t of e){let e=n.get(t.code);e?e.push(t):n.set(t.code,[t])}return[...n.entries()].sort(([e,[t]],[n,[r]])=>{let i=w[t.severity]-w[r.severity];return i===0?e.localeCompare(n):i})},[t,D]);if(T)return(0,x.jsx)(`div`,{className:`p-3.5`,children:(0,x.jsx)(y,{variant:`destructive`,children:(0,x.jsx)(m,{children:T})})});if(!t)return(0,x.jsxs)(`div`,{className:`flex items-center gap-2 p-3.5`,"aria-busy":`true`,children:[(0,x.jsx)(f,{className:`size-3 text-muted-foreground`}),(0,x.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:`running workfile doctor…`})]});let M=[[`cards`,t.modules?.cards??t.cards],[`docs`,t.modules?.docs],[`memory`,t.modules?.memory],[`changelog`,t.modules?.changelog]].filter(([,e])=>e!=null).map(([e,t])=>`${t.toLocaleString()} ${e}`).join(`, `),N=new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(t.generatedAt));return(0,x.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-3.5`,children:[(0,x.jsx)(`div`,{className:`mb-2.5 flex gap-1.5`,children:S.map(({level:e,label:n})=>(0,x.jsxs)(o,{type:`button`,variant:`outline`,size:`sm`,"aria-pressed":D===e,className:`aria-pressed:border-ring aria-pressed:bg-accent`,onClick:()=>O(t=>t===e?``:e),children:[n,(0,x.jsx)(_,{variant:`secondary`,className:`px-1.5 font-mono text-[10.5px]`,children:t.counts[e]})]},e))}),(0,x.jsx)(`div`,{className:`flex flex-wrap gap-2.5`,children:S.map(({level:e,label:n,hint:r,zeroHint:o})=>{let s=t.counts[e],c=e===`error`&&s===0?a(`done`):i(e);return(0,x.jsxs)(u,{className:`relative min-w-[13rem] flex-1 gap-1 py-3 pl-5 pr-3.5`,children:[(0,x.jsx)(p,{edge:`left`,color:c}),(0,x.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,x.jsx)(`span`,{className:`text-[26px] font-semibold tracking-tight`,style:{color:c},children:s}),(0,x.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:n})]}),(0,x.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:s===0?o:r})]},e)})}),(0,x.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-1 px-0.5 pt-4 pb-2`,children:[(0,x.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:[`grouped by code · `,M,` · checked `,N]}),(0,x.jsx)(`span`,{className:`ml-auto font-mono text-[10.5px] text-muted-foreground/70`,children:`workfile doctor --json`})]}),j.length===0?(0,x.jsx)(l,{className:`gap-2 p-10`,children:(0,x.jsxs)(s,{children:[(0,x.jsx)(h,{children:(0,x.jsx)(r,{"aria-hidden":`true`,size:20,style:{color:a(`done`)}})}),(0,x.jsx)(d,{className:`text-sm`,children:`All clear`}),(0,x.jsxs)(g,{className:`text-[12.5px]`,children:[`No `,D||`integrity`,` issues found.`]})]})}):(0,x.jsx)(`div`,{className:`flex flex-col gap-2`,children:j.map(([t,n])=>(0,x.jsxs)(u,{className:`gap-0 overflow-hidden py-0`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,x.jsx)(`span`,{"aria-hidden":`true`,className:`size-[7px] rounded-full bg-current`,style:{color:i(n[0].severity)}}),(0,x.jsx)(`span`,{className:`font-mono text-[11.5px]`,children:t}),(0,x.jsx)(`span`,{className:`flex-1 text-[12.5px] text-muted-foreground`,children:C(t)}),(0,x.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground/70`,children:n.length})]}),n.map((t,n)=>(0,x.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-1 border-b px-3 py-[7px] last:border-0`,children:[t.id?(0,x.jsx)(o,{type:`button`,variant:`link`,className:`h-auto w-[82px] flex-[0_0_82px] justify-start p-0 font-mono text-[11px] font-normal`,onClick:()=>e(t.id),children:t.id}):(0,x.jsx)(`span`,{className:`w-[82px] flex-[0_0_82px] font-mono text-[11px] text-muted-foreground/70`,children:`—`}),(0,x.jsx)(`span`,{className:`min-w-[12rem] flex-1 text-[12.5px] text-muted-foreground`,children:t.message}),t.file?(0,x.jsx)(`span`,{className:`max-w-full truncate font-mono text-[10.5px] text-muted-foreground/70 sm:max-w-80`,title:t.file,children:t.file}):null]},`${t.id||t.file}-${n}`))]},t))})]})}export{T as HealthView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{B as r,kt as i,tt as a}from"./ui-primitives-DRENhlck.js";import{i as o,o as s,r as c,s as l,u}from"./theme-CcOVK72d.js";import{$ as d,B as f,C as p,D as m,E as h,F as g,G as _,H as ee,I as v,K as y,L as te,N as ne,P as re,U as b,W as x,_ as S,b as ie,c as C,d as w,f as T,g as E,h as D,it as O,k as ae,l as k,nt as A,p as j,q as M,rt as N,u as P,w as oe,y as F,z as se}from"./index-DnoD4yDd.js";import{t as ce}from"./layout-QiuZ_k5v.js";var I=e(t(),1),L=n(),R=`text-[10px] font-medium tracking-widest uppercase text-muted-foreground`;function z(e){switch(e){case`added`:return s(`done`);case`changed`:return s(`doing`);case`fixed`:return s(`review`);case`removed`:return s(`blocked`);case`security`:return o(`error`);default:return s(`backlog`)}}function le(e,t){let n=null;for(let t of e){let e=/^v?(\d+)\.(\d+)\.(\d+)/.exec(t.version);if(!e)continue;let r=[Number(e[1]),Number(e[2]),Number(e[3])];(n?r[0]-n[0]||r[1]-n[1]||r[2]-n[2]:1)>0&&(n=r)}return n?t.some(e=>[`added`,`removed`,`deprecated`].includes(e.type))?`${n[0]}.${n[1]+1}.0`:`${n[0]}.${n[1]}.${n[2]+1}`:`0.1.0`}function B(e){return e instanceof Error?e.message:String(e)}function V({record:e,selected:t,onSelect:n}){let r=e.kind===`release`?`release`:e.type,i=e.kind===`release`?`var(--primary)`:z(e.type),a=e.kind===`release`?`${e.fragments.length} fragment${e.fragments.length===1?``:`s`} · ${e.date}`:e.area;return(0,L.jsx)(h,{asChild:!0,variant:`outline`,size:`sm`,children:(0,L.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,className:u(`flex-col flex-nowrap items-stretch gap-1 px-2.5 py-2 text-left shadow-xs`,t?`border-ring bg-accent`:`bg-card hover:border-ring`),children:[(0,L.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,L.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,L.jsx)(`span`,{className:`font-mono text-[10px]`,style:{color:i},children:r}),(0,L.jsx)(`span`,{className:`flex-1`}),(0,L.jsx)(`span`,{className:`max-w-[170px] truncate font-mono text-[10px] text-muted-foreground/70`,children:a})]}),(0,L.jsx)(`span`,{className:`text-sm leading-snug font-normal`,children:e.title})]})})}function H({label:e,records:t,selectedId:n,onSelect:r}){return t.length?(0,L.jsxs)(`div`,{role:`group`,"aria-label":e,className:`flex flex-col gap-1.5 pt-4`,children:[(0,L.jsxs)(`span`,{className:R,children:[e,` · `,t.length]}),t.map(e=>(0,L.jsx)(V,{record:e,selected:e.id===n,onSelect:()=>r(e.id)},e.id))]}):null}function U({id:e,title:t,relation:n,disabled:r,onOpen:i}){return(0,L.jsx)(h,{asChild:!0,variant:`outline`,size:`sm`,children:(0,L.jsxs)(`button`,{type:`button`,disabled:r,onClick:i,className:`flex-nowrap gap-2 bg-card px-2.5 py-1.5 text-left shadow-xs hover:border-ring disabled:pointer-events-none disabled:opacity-55`,children:[(0,L.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-muted-foreground`,children:e}),(0,L.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[12.5px]`,children:t}),n?(0,L.jsx)(A,{variant:`outline`,className:`shrink-0 font-mono text-[10px] font-normal text-muted-foreground`,children:n}):null]})})}function W({label:e,links:t,onOpen:n}){return t.length?(0,L.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,L.jsx)(`span`,{className:R,children:e}),t.map(t=>(0,L.jsx)(U,{id:t.id,title:t.title,relation:t.relation,disabled:t.disabled,onOpen:()=>n(t.id)},`${e}-${t.id}`))]}):null}function ue(e){return e.map(e=>({id:e.id,title:e.title||`Missing record`,relation:e.relation,disabled:!e.exists&&!e.title}))}function de({schema:e,areas:t,onClose:n,onCreated:r}){let[i,a]=(0,I.useState)({title:``,type:e.defaults.type,area:t[0]||`general`,visibility:e.defaults.visibility,body:``}),[o,s]=(0,I.useState)(!1),[c,u]=(0,I.useState)(``),f=(e,t)=>a(n=>({...n,[e]:t})),p=async()=>{s(!0);try{r((await M.createChange(i)).record)}catch(e){u(B(e))}finally{s(!1)}};return(0,L.jsx)(C,{open:!0,onOpenChange:e=>{e||n()},children:(0,L.jsxs)(k,{onOpenAutoFocus:e=>e.preventDefault(),children:[(0,L.jsxs)(T,{children:[(0,L.jsx)(j,{children:`New change fragment`}),(0,L.jsx)(P,{children:`Record one user- or operator-meaningful change.`})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`new-fragment-title`,children:`Title`}),(0,L.jsx)(d,{id:`new-fragment-title`,autoFocus:!0,required:!0,maxLength:120,value:i.title,onChange:e=>f(`title`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-3 gap-2.5`,children:[(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`new-fragment-type`,children:`Type`}),(0,L.jsx)(D,{id:`new-fragment-type`,value:i.type,onChange:e=>f(`type`,e.target.value),children:e.types.map(e=>(0,L.jsx)(E,{value:e,children:e},e))})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`new-fragment-area`,children:`Area`}),(0,L.jsx)(D,{id:`new-fragment-area`,value:i.area,onChange:e=>f(`area`,e.target.value),children:t.map(e=>(0,L.jsx)(E,{value:e,children:e},e))})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`new-fragment-visibility`,children:`Visibility`}),(0,L.jsx)(D,{id:`new-fragment-visibility`,value:i.visibility,onChange:e=>f(`visibility`,e.target.value),children:e.visibilities.map(e=>(0,L.jsx)(E,{value:e,children:e},e))})]})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`new-fragment-details`,children:`Details`}),(0,L.jsx)(g,{id:`new-fragment-details`,rows:5,value:i.body,onChange:e=>f(`body`,e.target.value)})]}),c?(0,L.jsx)(N,{variant:`destructive`,"aria-live":`polite`,children:(0,L.jsx)(O,{children:c})}):null,(0,L.jsxs)(w,{children:[(0,L.jsx)(l,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,L.jsx)(l,{type:`button`,disabled:o||!i.title.trim(),onClick:()=>void p(),children:o?`Saving…`:`Create fragment`})]})]})})}function fe({preview:e,suggestedVersion:t,onClose:n,onReleased:r}){let[i,a]=(0,I.useState)(t),[o,s]=(0,I.useState)(``),[c,u]=(0,I.useState)(!1),[f,p]=(0,I.useState)(``),m=async()=>{u(!0);try{await M.createRelease({version:i,title:o||void 0,fragmentIds:e.fragments.map(e=>e.id)}),r()}catch(e){p(B(e))}finally{u(!1)}};return(0,L.jsx)(C,{open:!0,onOpenChange:e=>{e||n()},children:(0,L.jsxs)(k,{className:`flex max-h-[85vh] flex-col sm:max-w-[640px]`,children:[(0,L.jsxs)(T,{children:[(0,L.jsx)(j,{children:`Release preparation`}),(0,L.jsxs)(P,{children:[e.fragments.length,` unreleased fragment`,e.fragments.length===1?``:`s`,` selected.`]})]}),(0,L.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-[150px_1fr] gap-2.5`,children:[(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`release-version`,children:`Version`}),(0,L.jsx)(d,{id:`release-version`,className:`font-mono`,placeholder:`2.4.0`,value:i,onChange:e=>a(e.target.value)})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`release-title`,children:`Release title`}),(0,L.jsx)(d,{id:`release-title`,placeholder:`Optional curated title`,value:o,onChange:e=>s(e.target.value)})]})]}),e.groups.map(e=>(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsxs)(`span`,{className:R,style:{color:z(e.type)},children:[e.type,` · `,e.fragments.length]}),e.fragments.map(e=>(0,L.jsxs)(`span`,{className:`flex items-baseline gap-2 text-[12.5px]`,children:[(0,L.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,L.jsx)(`span`,{className:`min-w-0 truncate`,children:e.title}),(0,L.jsx)(`span`,{className:`flex-1`}),(0,L.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground/70`,children:e.area})]},e.id))]},e.type)),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(`span`,{className:R,children:`release notes preview`}),(0,L.jsx)(`div`,{className:`max-h-[220px] overflow-y-auto rounded-md border bg-background px-3 py-1`,children:(0,L.jsx)(ie,{source:e.markdown||`No release notes to render.`})})]}),f?(0,L.jsx)(N,{variant:`destructive`,"aria-live":`polite`,children:(0,L.jsx)(O,{children:f})}):null]}),(0,L.jsxs)(w,{children:[(0,L.jsx)(l,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,L.jsx)(l,{type:`button`,disabled:c||!i.trim()||!e.fragments.length,onClick:()=>void m(),children:c?`Releasing…`:`Create release`})]})]})})}function pe({record:e,schema:t,areas:n,onSaved:r}){let[i,a]=(0,I.useState)({title:e.title,type:e.type,area:e.area,visibility:e.visibility}),[s,c]=(0,I.useState)(!1),[u,f]=(0,I.useState)(``),p=(e,t)=>a(n=>({...n,[e]:t})),m={};for(let t of[`title`,`type`,`area`,`visibility`])i[t]!==e[t]&&(m[t]=i[t]);let h=Object.keys(m).length>0,g=n.includes(e.area)?n:[e.area,...n],v=async()=>{c(!0);try{let t=await M.patchChange(e.id,m,e.revision);f(``),r(t.record)}catch(e){f(B(e))}finally{c(!1)}};return(0,L.jsxs)(ee,{className:`gap-2.5 rounded-lg py-3 shadow-xs`,children:[(0,L.jsx)(_,{className:`px-3`,children:(0,L.jsx)(y,{className:R,children:`edit fragment`})}),(0,L.jsxs)(b,{className:`flex flex-col gap-2.5 px-3`,children:[(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`edit-fragment-title`,children:`Title`}),(0,L.jsx)(d,{id:`edit-fragment-title`,maxLength:120,value:i.title,onChange:e=>p(`title`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-3 gap-2.5`,children:[(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`edit-fragment-type`,children:`Type`}),(0,L.jsx)(D,{id:`edit-fragment-type`,value:i.type,onChange:e=>p(`type`,e.target.value),children:t.types.map(e=>(0,L.jsx)(E,{value:e,children:e},e))})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`edit-fragment-area`,children:`Area`}),(0,L.jsx)(D,{id:`edit-fragment-area`,value:i.area,onChange:e=>p(`area`,e.target.value),children:g.map(e=>(0,L.jsx)(E,{value:e,children:e},e))})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(F,{htmlFor:`edit-fragment-visibility`,children:`Visibility`}),(0,L.jsx)(D,{id:`edit-fragment-visibility`,value:i.visibility,onChange:e=>p(`visibility`,e.target.value),children:t.visibilities.map(e=>(0,L.jsx)(E,{value:e,children:e},e))})]})]})]}),(0,L.jsxs)(x,{className:`gap-2.5 px-3`,children:[u?(0,L.jsx)(`span`,{className:`flex-1 text-xs`,style:{color:o(`error`)},"aria-live":`polite`,children:u}):(0,L.jsx)(`span`,{className:`flex-1`}),(0,L.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:s||!h||!i.title.trim(),onClick:()=>void v(),children:s?`Saving…`:`Save changes`})]})]})}function G({selectedId:e,onSelect:t,onOpenRecord:n,schema:s,areas:d,search:h,onSearchChange:g}){let _=oe(),[y,b]=(0,I.useState)([]),[x,S]=(0,I.useState)(``),[C,w]=(0,I.useState)(``),[T,E]=(0,I.useState)(!0),[D,k]=(0,I.useState)(``),[j,P]=(0,I.useState)(``),[F,R]=(0,I.useState)(!1),[V,U]=(0,I.useState)(null),[G,me]=(0,I.useState)(`public`),[K,q]=(0,I.useState)({content:``,error:``,loading:!0}),[he,ge]=(0,I.useState)(0),_e=()=>ge(e=>e+1);f(e=>{se(e,`/changelog/`)&&_e()}),(0,I.useEffect)(()=>{let e=!1,t=async()=>{E(!0);try{let t=await M.changelog(h.trim(),{state:x||void 0,visibility:C||void 0});if(e)return;b(t.records),k(``)}catch(t){e||k(B(t))}finally{e||E(!1)}},n=window.setTimeout(()=>void t(),h?180:0);return()=>{e=!0,window.clearTimeout(n)}},[h,x,C,he]),(0,I.useEffect)(()=>{let e=!1;return q(e=>({...e,loading:!0})),M.renderedChangelog(G).then(t=>{e||q({content:t.content,error:``,loading:!1})}).catch(t=>{e||q({content:``,error:B(t),loading:!1})}),()=>{e=!0}},[G,he]);let J=(0,I.useMemo)(()=>[...y].sort((e,t)=>{if(e.kind!==t.kind)return e.kind===`change`?-1:1;if(e.kind===`release`&&t.kind===`release`){let n=t.date.localeCompare(e.date);return n===0?t.id.localeCompare(e.id):n}return String(t.updated||``).localeCompare(String(e.updated||``))}),[y]),Y=(0,I.useMemo)(()=>new Map(y.map(e=>[e.id,e])),[y]),X=(0,I.useMemo)(()=>J.filter(e=>e.kind===`change`&&!e.released),[J]),ve=(0,I.useMemo)(()=>J.filter(e=>e.kind===`change`&&e.released),[J]),Z=(0,I.useMemo)(()=>J.filter(e=>e.kind===`release`),[J]),ye=(0,I.useMemo)(()=>le(Z,X),[Z,X]),Q=e?Y.get(e):void 0,$=e=>{if(Y.has(e)){t(e);return}if(/^(CHG|REL)-/.test(e)){S(``),w(``),t(e);return}n(e)},be=()=>{P(``),M.releasePreview().then(U).catch(e=>P(B(e)))},xe=Q?.issues.some(e=>e.severity===`error`)?`destructive`:`default`,Se=(0,L.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:_,title:_?p:void 0,onClick:()=>R(!0),children:[(0,L.jsx)(a,{"aria-hidden":`true`}),`New fragment`]});return(0,L.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:u(`w-full shrink-0 flex-col border-r lg:flex lg:w-[400px]`,Q?`hidden`:`flex`),children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-2.5 p-3.5 pb-0`,children:[(0,L.jsxs)(ee,{className:`flex-row items-center gap-2.5 border-primary bg-primary/10 p-3`,children:[(0,L.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,L.jsxs)(`span`,{className:`text-[13px] font-semibold`,children:[X.length,` unpublished fragment`,X.length===1?``:`s`]}),(0,L.jsxs)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground`,children:[`next: `,ye,` ·`,` `,s.releaseStrategy]})]}),(0,L.jsx)(l,{type:`button`,size:`sm`,className:`whitespace-nowrap`,disabled:_,title:_?p:void 0,onClick:be,children:`Prepare release`})]}),j?(0,L.jsx)(N,{variant:`destructive`,"aria-live":`polite`,children:(0,L.jsx)(O,{children:j})}):null,(0,L.jsxs)(v,{before:(0,L.jsx)(re,{scope:`records`,value:h,label:`Search history`,onChange:g}),children:[(0,L.jsx)(te,{label:`state`,value:x,options:[{value:`unreleased`},{value:`released`}],onChange:S}),(0,L.jsx)(te,{label:`visibility`,value:C,options:s.visibilities.map(e=>({value:e})),onChange:w})]})]}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3.5 pb-6 [mask-image:linear-gradient(to_bottom,black_calc(100%-24px),transparent)]`,children:T?(0,L.jsx)(`div`,{"aria-busy":`true`,className:`flex flex-col gap-2 pt-4`,children:Array.from({length:6},(e,t)=>(0,L.jsx)(`div`,{className:`h-[52px] animate-pulse rounded-md bg-muted`},t))}):D?(0,L.jsx)(N,{variant:`destructive`,className:`mt-4`,"aria-live":`polite`,children:(0,L.jsx)(O,{children:D})}):J.length?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(H,{label:`unpublished`,records:X,selectedId:e,onSelect:t}),(0,L.jsx)(H,{label:`releases`,records:Z,selectedId:e,onSelect:t}),(0,L.jsx)(H,{label:`published fragments`,records:ve,selectedId:e,onSelect:t})]}):(0,L.jsx)(m,{className:`mt-4 gap-1 p-4 md:p-4`,children:(0,L.jsx)(ae,{className:`text-xs`,children:`No history records match the filters.`})})})]}),(0,L.jsx)(`div`,{className:u(`min-w-0 flex-1 overflow-y-auto px-6 py-5 sm:px-8.5`,Q?`block`:`hidden lg:block`),children:(0,L.jsx)(`div`,{className:ce,children:Q?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(l,{type:`button`,variant:`ghost`,size:`sm`,className:`-ml-2 mb-2 lg:hidden`,onClick:()=>t(``),children:[(0,L.jsx)(i,{"aria-hidden":`true`}),`All history`]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 font-mono text-[11px]`,children:[(0,L.jsx)(`span`,{className:`whitespace-nowrap text-primary`,children:Q.id}),(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{className:`text-muted-foreground/70`,children:Q.kind}),(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),Q.kind===`change`?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{style:{color:z(Q.type)},children:Q.type}),(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:Q.area}),(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:Q.visibility}),(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{style:{color:c(Q.released?`released`:`unreleased`)},children:Q.released?`released`:`unreleased`}),Q.updated?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{className:`text-muted-foreground/70`,children:Q.updated})]}):null]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`text-primary`,children:Q.version}),(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:Q.date}),Q.commit?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsx)(`span`,{className:`text-muted-foreground/70`,children:Q.commit})]}):null,(0,L.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,L.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[Q.fragments.length,` fragment`,Q.fragments.length===1?``:`s`]})]}),(0,L.jsxs)(`span`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[Se,(0,L.jsx)(l,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Close record`,title:`Back to the derived changelog`,onClick:()=>t(``),children:(0,L.jsx)(r,{"aria-hidden":`true`})})]})]}),(0,L.jsx)(`h2`,{className:`mt-2.5 mb-1 text-[26px] leading-tight font-semibold tracking-tight [text-wrap:pretty]`,children:Q.title}),(0,L.jsx)(`div`,{className:`font-mono text-[10.5px] break-all text-muted-foreground/70`,children:Q.path}),Q.issues.length>0?(0,L.jsx)(N,{variant:xe,className:`mt-3.5`,children:(0,L.jsx)(O,{className:`w-full gap-1`,children:Q.issues.map(e=>(0,L.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,L.jsx)(`span`,{className:`shrink-0 font-mono text-[10.5px]`,style:{color:o(e.severity)},children:e.severity}),(0,L.jsx)(`span`,{children:e.message})]},`${e.code}-${e.message}`))})}):null,(0,L.jsx)(`div`,{className:`mt-4.5`,children:(0,L.jsx)(ie,{source:Q.body||`No additional notes.`,onOpen:$})}),(0,L.jsxs)(`div`,{className:`mt-5.5 flex flex-col gap-3.5`,children:[Q.kind===`change`?(0,L.jsx)(W,{label:`shipped in`,links:(Q.releaseIds||[]).map(e=>({id:e,title:Y.get(e)?.title||`Open release`,relation:`release`})),onOpen:$}):(0,L.jsx)(W,{label:`fragments · ${Q.fragments.length}`,links:Q.fragments.map(e=>{let t=Y.get(e);return{id:e,title:t?.title||`Open fragment`,relation:t?.kind===`change`?t.type:void 0}}),onOpen:$}),(0,L.jsx)(W,{label:`links to`,links:ue(Q.outgoing),onOpen:$}),(0,L.jsx)(W,{label:`backlinks`,links:ue(Q.incoming),onOpen:$})]}),Q.kind===`change`&&!_?(0,L.jsx)(`div`,{className:`mt-5.5`,children:(0,L.jsx)(pe,{record:Q,schema:s,areas:d,onSaved:e=>b(t=>t.map(t=>t.id===e.id?e:t))},`${Q.id}:${Q.revision}`)}):null]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-2 border-b pb-3`,children:[(0,L.jsx)(`span`,{className:`text-[13px] font-semibold`,children:`Derived changelog`}),(0,L.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:[`visibility `,G,` · CHANGELOG.md`]}),(0,L.jsxs)(`span`,{className:`ml-auto flex flex-wrap items-center gap-2.5`,children:[(0,L.jsx)(ne,{children:s.visibilities.map(e=>(0,L.jsx)(l,{type:`button`,size:`sm`,variant:G===e?`default`:`outline`,"aria-pressed":G===e,onClick:()=>me(e),children:e},e))}),(0,L.jsx)(A,{variant:`outline`,className:`rounded-md font-mono text-[10.5px] font-normal whitespace-nowrap text-muted-foreground`,children:`render --write`}),Se]})]}),K.error?(0,L.jsx)(N,{variant:`destructive`,className:`mt-4`,"aria-live":`polite`,children:(0,L.jsx)(O,{children:K.error})}):(0,L.jsx)(`pre`,{className:`mt-4 font-mono text-xs leading-[1.75] whitespace-pre-wrap text-muted-foreground`,"aria-busy":K.loading||void 0,children:K.loading&&!K.content?`Rendering…`:K.content||`Nothing to render yet — create the first change fragment.`})]})})}),F?(0,L.jsx)(de,{schema:s,areas:d,onClose:()=>R(!1),onCreated:e=>{R(!1),b(t=>[e,...t]),t(e.id)}}):null,V?(0,L.jsx)(fe,{preview:V,suggestedVersion:ye,onClose:()=>U(null),onReleased:()=>{U(null),_e()}}):null]})}export{G as HistoryView};

Sorry, the diff of this file is too big to display

import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{et as r,mt as i,nt as a,tt as o}from"./ui-primitives-DRENhlck.js";import{i as s,r as c,s as l,u}from"./theme-CcOVK72d.js";import{$ as d,B as f,C as p,D as m,E as h,F as g,G as _,H as v,I as y,L as b,P as x,T as S,U as C,_ as w,b as T,c as E,d as D,f as O,g as k,h as A,it as j,k as M,l as N,nt as P,p as F,q as I,rt as L,w as R,y as z,z as B}from"./index-DnoD4yDd.js";var V=e(t(),1),H=n(),U=[`low`,`medium`,`high`],W=[`critical`,`high`,`medium`,`low`],G=`[mask-image:linear-gradient(to_bottom,black_calc(100%_-_24px),transparent)]`;function ee(e){return e&&e[0].toUpperCase()+e.slice(1)}function K(e,t){return`${e} ${t}${e===1?``:`s`}`}function q(e){return{category:e===`learnings`||e===`decisions`,confidence:e===`learnings`,severity:e===`incidents`,expires:e===`context`,review_after:e===`context`}}function J(e){let t=[];switch(e.collection){case`learnings`:t.push(e.confidence,e.category,e.occurrences==null?null:`${e.occurrences}×`);break;case`decisions`:e.superseded_by?.length?t.push(`superseded by ${e.superseded_by.join(`, `)}`):e.supersedes?.length?t.push(`supersedes ${e.supersedes.join(`, `)}`):t.push(e.category);break;case`incidents`:t.push(e.severity,e.corrective_actions?.length?K(e.corrective_actions.length,`corrective action`):null);break;case`conventions`:t.push(e.owners?.length?e.owners.join(`, `):`no owner`);break;case`context`:t.push(e.expires?`expires ${e.expires}`:null,e.review_after?`review after ${e.review_after}`:null);break;default:t.push(e.category,e.severity)}return t.filter(Boolean).join(` · `)}function Y({id:e,label:t,children:n}){return(0,H.jsxs)(w,{className:`gap-1.5 [&_[data-slot=native-select-wrapper]]:w-full`,children:[(0,H.jsx)(z,{htmlFor:e,children:t}),n]})}function te({record:e,selected:t,onSelect:n}){let r=J(e),i=e.lifecycleIssues?.length||0;return(0,H.jsx)(h,{asChild:!0,variant:`outline`,size:`sm`,className:`w-full flex-none flex-col items-stretch gap-1 rounded-lg bg-background px-2.5 py-2 text-left shadow-xs hover:border-ring aria-[current=true]:border-ring aria-[current=true]:bg-accent`,children:(0,H.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,children:[(0,H.jsxs)(`span`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,H.jsxs)(P,{variant:`outline`,className:`h-[18px] gap-1 rounded-md px-1.5 font-mono text-[10px] font-medium`,children:[(0,H.jsx)(`span`,{className:`size-[5px] shrink-0 rounded-full`,style:{backgroundColor:c(e.status)},"aria-hidden":`true`}),e.status]})]}),(0,H.jsx)(`span`,{className:`text-[13px] font-medium leading-snug`,children:e.title}),r||i?(0,H.jsxs)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground`,children:[r,r&&i?` · `:null,i?(0,H.jsx)(`span`,{style:{color:s(`warning`)},children:K(i,`lifecycle warning`)}):null]}):null]})})}function X({issues:e,kind:t}){return e.length?(0,H.jsx)(H.Fragment,{children:e.map(e=>(0,H.jsx)(L,{variant:e.severity===`error`?`destructive`:`default`,className:`px-3 py-2`,children:(0,H.jsxs)(j,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-0.5`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[10.5px]`,style:{color:s(e.severity)},children:t===`lifecycle`?`lifecycle`:e.severity}),(0,H.jsx)(`span`,{children:e.message})]})},`${t}-${e.code}-${e.message}`))}):null}function Z({label:e,links:t,onOpen:n}){return t.length?(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:e}),t.map(t=>{let r=!t.exists&&!t.title;return(0,H.jsx)(h,{asChild:!0,variant:`outline`,size:`sm`,className:`gap-2 rounded-lg px-2.5 py-2 text-left hover:border-ring disabled:pointer-events-none disabled:opacity-50`,children:(0,H.jsxs)(`button`,{type:`button`,disabled:r,onClick:()=>n(t.id),children:[(0,H.jsx)(`span`,{className:`w-[78px] shrink-0 truncate font-mono text-[11px] font-medium`,children:t.id}),(0,H.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-muted-foreground`,children:t.title||`Missing record`}),(t.relations??[t.relation||t.kind]).filter(Boolean).map(e=>(0,H.jsx)(P,{variant:`secondary`,className:`h-[18px] rounded-md px-1.5 font-mono text-[10px] font-medium`,children:e},e))]})},`${e}-${t.id}`)})]}):null}function Q({message:e}){return e?(0,H.jsx)(L,{variant:`destructive`,className:`px-3 py-2`,children:(0,H.jsx)(j,{children:e})}):null}function ne({schema:e,initialCollection:t,onClose:n,onCreated:r}){let i=e.collections.find(e=>e.id===t)||e.collections[0],[a,o]=(0,V.useState)({collection:i?.id||`learnings`,status:i?.statuses[0]||`active`,title:``,category:``,confidence:``,severity:``,expires:``,body:``}),[s,c]=(0,V.useState)(!1),[u,f]=(0,V.useState)(``),p=e.collections.find(e=>e.id===a.collection),m=q(a.collection),h=(e,t)=>o(n=>({...n,[e]:t})),_=t=>{let n=e.collections.find(e=>e.id===t);o(e=>({...e,collection:t,status:n?.statuses[0]||`active`}))},v=async()=>{c(!0);try{r((await I.createMemory({collection:a.collection,title:a.title,status:a.status,body:a.body,category:a.category||void 0,confidence:a.confidence||void 0,severity:a.severity||void 0,expires:a.expires||void 0})).record)}catch(e){f(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,H.jsx)(E,{open:!0,onOpenChange:e=>{e||n()},children:(0,H.jsxs)(N,{className:`sm:max-w-[520px]`,"aria-describedby":void 0,children:[(0,H.jsx)(O,{children:(0,H.jsxs)(F,{children:[`New `,p?.singular||`record`]})}),(0,H.jsxs)(`div`,{className:`-m-1 flex max-h-[65vh] flex-col gap-3 overflow-y-auto p-1`,children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,H.jsx)(Y,{id:`memory-create-collection`,label:`Collection`,children:(0,H.jsx)(A,{id:`memory-create-collection`,value:a.collection,onChange:e=>_(e.target.value),children:e.collections.map(e=>(0,H.jsx)(k,{value:e.id,children:e.id},e.id))})}),(0,H.jsx)(Y,{id:`memory-create-status`,label:`Status`,children:(0,H.jsx)(A,{id:`memory-create-status`,value:a.status,onChange:e=>h(`status`,e.target.value),children:(p?.statuses||[]).map(e=>(0,H.jsx)(k,{value:e,children:e},e))})})]}),(0,H.jsx)(Y,{id:`memory-create-title`,label:`Title`,children:(0,H.jsx)(d,{id:`memory-create-title`,autoFocus:!0,required:!0,maxLength:120,value:a.title,onChange:e=>h(`title`,e.target.value)})}),m.category||m.confidence||m.severity||m.expires?(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[m.category?(0,H.jsx)(Y,{id:`memory-create-category`,label:`Category`,children:(0,H.jsx)(d,{id:`memory-create-category`,value:a.category,onChange:e=>h(`category`,e.target.value)})}):null,m.confidence?(0,H.jsx)(Y,{id:`memory-create-confidence`,label:`Confidence`,children:(0,H.jsxs)(A,{id:`memory-create-confidence`,value:a.confidence,onChange:e=>h(`confidence`,e.target.value),children:[(0,H.jsx)(k,{value:``,children:`not set`}),U.map(e=>(0,H.jsx)(k,{value:e,children:e},e))]})}):null,m.severity?(0,H.jsx)(Y,{id:`memory-create-severity`,label:`Severity`,children:(0,H.jsxs)(A,{id:`memory-create-severity`,value:a.severity,onChange:e=>h(`severity`,e.target.value),children:[(0,H.jsx)(k,{value:``,children:`not set`}),W.map(e=>(0,H.jsx)(k,{value:e,children:e},e))]})}):null,m.expires?(0,H.jsx)(Y,{id:`memory-create-expires`,label:`Expires`,children:(0,H.jsx)(d,{id:`memory-create-expires`,type:`date`,value:a.expires,onChange:e=>h(`expires`,e.target.value)})}):null]}):null,(0,H.jsx)(Y,{id:`memory-create-body`,label:`Details`,children:(0,H.jsx)(g,{id:`memory-create-body`,rows:8,value:a.body,onChange:e=>h(`body`,e.target.value)})}),(0,H.jsx)(Q,{message:u})]}),(0,H.jsxs)(D,{children:[(0,H.jsx)(l,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(l,{type:`button`,disabled:s||!a.title.trim(),onClick:()=>void v(),children:s?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(S,{"aria-hidden":`true`}),`Saving…`]}):`Create record`})]})]})})}function re({record:e,statuses:t,onClose:n,onUpdated:r}){let i=q(e.collection),[a,o]=(0,V.useState)({title:e.title,status:e.status,category:e.category||``,confidence:e.confidence||``,severity:e.severity||``,expires:e.expires||``,review_after:e.review_after||``,body:e.body}),[s,c]=(0,V.useState)(!1),[u,f]=(0,V.useState)(``),p=(e,t)=>o(n=>({...n,[e]:t})),m=async()=>{let t={};a.title.trim()&&a.title!==e.title&&(t.title=a.title),a.status!==e.status&&(t.status=a.status),a.body!==e.body&&(t.body=a.body);for(let n of[`category`,`confidence`,`severity`,`expires`,`review_after`])a[n]!==(e[n]||``)&&(t[n]=a[n]||null);if(!Object.keys(t).length){n();return}c(!0);try{r((await I.patchMemory(e.id,t,e.revision)).record),n()}catch(e){f(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,H.jsx)(E,{open:!0,onOpenChange:e=>{e||n()},children:(0,H.jsxs)(N,{className:`sm:max-w-[520px]`,"aria-describedby":void 0,children:[(0,H.jsx)(O,{children:(0,H.jsxs)(F,{children:[`Edit `,e.id]})}),(0,H.jsxs)(`div`,{className:`-m-1 flex max-h-[65vh] flex-col gap-3 overflow-y-auto p-1`,children:[(0,H.jsx)(Y,{id:`memory-edit-title`,label:`Title`,children:(0,H.jsx)(d,{id:`memory-edit-title`,autoFocus:!0,required:!0,maxLength:120,value:a.title,onChange:e=>p(`title`,e.target.value)})}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,H.jsx)(Y,{id:`memory-edit-status`,label:`Status`,children:(0,H.jsx)(A,{id:`memory-edit-status`,value:a.status,onChange:e=>p(`status`,e.target.value),children:(t.includes(a.status)?t:[a.status,...t]).map(e=>(0,H.jsx)(k,{value:e,children:e},e))})}),i.category?(0,H.jsx)(Y,{id:`memory-edit-category`,label:`Category`,children:(0,H.jsx)(d,{id:`memory-edit-category`,value:a.category,onChange:e=>p(`category`,e.target.value)})}):null,i.confidence?(0,H.jsx)(Y,{id:`memory-edit-confidence`,label:`Confidence`,children:(0,H.jsxs)(A,{id:`memory-edit-confidence`,value:a.confidence,onChange:e=>p(`confidence`,e.target.value),children:[(0,H.jsx)(k,{value:``,children:`not set`}),U.map(e=>(0,H.jsx)(k,{value:e,children:e},e))]})}):null,i.severity?(0,H.jsx)(Y,{id:`memory-edit-severity`,label:`Severity`,children:(0,H.jsxs)(A,{id:`memory-edit-severity`,value:a.severity,onChange:e=>p(`severity`,e.target.value),children:[(0,H.jsx)(k,{value:``,children:`not set`}),W.map(e=>(0,H.jsx)(k,{value:e,children:e},e))]})}):null,i.expires?(0,H.jsx)(Y,{id:`memory-edit-expires`,label:`Expires`,children:(0,H.jsx)(d,{id:`memory-edit-expires`,type:`date`,value:a.expires,onChange:e=>p(`expires`,e.target.value)})}):null,i.review_after?(0,H.jsx)(Y,{id:`memory-edit-review-after`,label:`Review after`,children:(0,H.jsx)(d,{id:`memory-edit-review-after`,type:`date`,value:a.review_after,onChange:e=>p(`review_after`,e.target.value)})}):null]}),(0,H.jsx)(Y,{id:`memory-edit-body`,label:`Details`,children:(0,H.jsx)(g,{id:`memory-edit-body`,rows:10,value:a.body,onChange:e=>p(`body`,e.target.value)})}),(0,H.jsx)(Q,{message:u})]}),(0,H.jsxs)(D,{children:[(0,H.jsx)(l,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(l,{type:`button`,disabled:s||!a.title.trim(),onClick:()=>void m(),children:s?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(S,{"aria-hidden":`true`}),`Saving…`]}):`Save changes`})]})]})})}function ie({record:e,mode:t,onClose:n,onUpdated:r}){let[i,a]=(0,V.useState)(``),[o,s]=(0,V.useState)(!1),[c,u]=(0,V.useState)(``),f=async()=>{s(!0);try{r((t===`graduate`?await I.graduateMemory(e.id,i.split(`,`).map(e=>e.trim()).filter(Boolean),e.revision):await I.supersedeMemory(e.id,i.trim(),e.revision)).record),n()}catch(e){u(e instanceof Error?e.message:String(e))}finally{s(!1)}};return(0,H.jsx)(E,{open:!0,onOpenChange:e=>{e||n()},children:(0,H.jsxs)(N,{className:`sm:max-w-[420px]`,"aria-describedby":void 0,children:[(0,H.jsx)(O,{children:(0,H.jsxs)(F,{children:[t===`graduate`?`Graduate`:`Supersede`,` `,e.id]})}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,H.jsx)(Y,{id:`memory-lifecycle-target`,label:t===`graduate`?`Target IDs`:`Replacement ID`,children:(0,H.jsx)(d,{id:`memory-lifecycle-target`,autoFocus:!0,placeholder:t===`graduate`?`CONV-0001, DOC-0004`:`ADR-0009`,value:i,onChange:e=>a(e.target.value)})}),(0,H.jsx)(Q,{message:c})]}),(0,H.jsxs)(D,{children:[(0,H.jsx)(l,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(l,{type:`button`,disabled:o||!i.trim(),onClick:()=>void f(),children:o?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(S,{"aria-hidden":`true`}),`Saving…`]}):`Apply`})]})]})})}function ae({record:e,statuses:t,onOpenRelation:n,onOpenRecord:o,onUpdated:u,onDialogOpenChange:d}){let f=R(),[m,h]=(0,V.useState)(!1),[g,_]=(0,V.useState)(``),v=m||!!g;(0,V.useEffect)(()=>{d?.(v)},[v,d]);let y=e.collection===`learnings`&&e.status!==`graduated`,b=[`learnings`,`decisions`,`conventions`].includes(e.collection),x=[[`status`,e.status,c(e.status)]];return e.category&&x.push([`category`,e.category]),e.confidence&&x.push([`confidence`,e.confidence]),e.severity&&x.push([`severity`,e.severity,s(e.severity)]),e.occurrences!=null&&x.push([`occurrences`,String(e.occurrences)]),e.expires&&x.push([`expires`,e.expires]),e.review_after&&x.push([`review after`,e.review_after]),e.started_at&&x.push([`started`,e.started_at]),e.resolved_at&&x.push([`resolved`,e.resolved_at]),e.graduated_to?.length&&x.push([`graduated to`,e.graduated_to.join(`, `)]),e.superseded_by?.length&&x.push([`superseded by`,e.superseded_by.join(`, `)]),e.owners?.length&&x.push([`owners`,e.owners.join(`, `)]),x.push([`updated`,e.updated||`—`]),(0,H.jsxs)(`aside`,{"aria-label":`Memory record`,className:`flex min-h-0 flex-col overflow-hidden border-l bg-background`,children:[(0,H.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center gap-2 border-b px-3.5`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,H.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground/60`,children:`·`}),(0,H.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.collection}),(0,H.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground/60`,children:`·`}),(0,H.jsx)(`span`,{className:`font-mono text-[11px]`,style:{color:c(e.status)},children:e.status})]}),(0,H.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto p-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(`h2`,{className:`m-0 text-[17px] font-semibold leading-[1.3] tracking-[-0.01em] [text-wrap:pretty]`,children:e.title}),e.path?(0,H.jsx)(`span`,{className:`break-all font-mono text-[10.5px] text-muted-foreground`,children:e.path}):null]}),(0,H.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-2`,children:x.map(([e,t,n])=>(0,H.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,H.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:e}),(0,H.jsx)(`span`,{className:`text-sm`,style:n?{color:n}:void 0,children:t})]},e))}),(0,H.jsx)(X,{issues:e.issues,kind:`validation`}),(0,H.jsx)(X,{issues:e.lifecycleIssues||[],kind:`lifecycle`}),(0,H.jsx)(T,{className:`[--typeset-size:0.875rem]`,source:e.body||`No details recorded.`,onOpen:o}),(0,H.jsx)(Z,{label:`Links to`,links:e.outgoing,onOpen:n}),(0,H.jsx)(Z,{label:`Backlinks`,links:e.incoming,onOpen:n}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:f,title:f?p:void 0,onClick:()=>h(!0),children:[(0,H.jsx)(a,{"aria-hidden":`true`}),`Edit`]}),y?(0,H.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:f,title:f?p:void 0,onClick:()=>_(`graduate`),children:[(0,H.jsx)(i,{"aria-hidden":`true`}),`Graduate`]}):null,b?(0,H.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:f,title:f?p:void 0,onClick:()=>_(`supersede`),children:[(0,H.jsx)(r,{"aria-hidden":`true`}),`Supersede`]}):null]})]}),m?(0,H.jsx)(re,{record:e,statuses:t,onClose:()=>h(!1),onUpdated:u}):null,g?(0,H.jsx)(ie,{record:e,mode:g,onClose:()=>_(``),onUpdated:u}):null]})}function $(e,t){return e.find(e=>e.id===t)?.statuses||[]}function oe({id:e,schema:t,onSelect:n,onOpenRecord:r,onDialogOpenChange:i,onChanged:a}){let[o,s]=(0,V.useState)(null),[c,l]=(0,V.useState)(``);return(0,V.useEffect)(()=>{let t=!0;return s(null),l(``),I.record(e).then(e=>{t&&s(e.record)}).catch(e=>{t&&l(e.message)}),()=>{t=!1}},[e]),c?(0,H.jsx)(`div`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:c}):o?(0,H.jsx)(ae,{record:o,statuses:$(t.collections,o.collection),onOpenRelation:n,onOpenRecord:r,onUpdated:e=>{s(e),a?.()},onDialogOpenChange:i},o.id):(0,H.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground`,children:[(0,H.jsx)(S,{}),` Reading `,e,`…`]})}function se({selectedId:e,onSelect:t,onOpenRecord:n,schema:r,search:i,onSearchChange:a}){let s=R(),[d,h]=(0,V.useState)([]),[g,w]=(0,V.useState)(``),[T,E]=(0,V.useState)(``),[D,O]=(0,V.useState)(!0),[k,A]=(0,V.useState)(``),[N,F]=(0,V.useState)(null),z=(0,V.useRef)(0),U=(0,V.useCallback)(e=>{z.current=performance.now(),t(e)},[t]),[W,q]=(0,V.useState)(0);f(e=>{B(e,`/memory/`)&&q(e=>e+1)}),(0,V.useEffect)(()=>{let e=async()=>{O(!0);try{let e=await I.memory(i.trim(),{collection:g||void 0,status:T||void 0});h(e.records),A(``)}catch(e){A(e instanceof Error?e.message:String(e))}finally{O(!1)}},t=window.setTimeout(()=>void e(),i?180:0);return()=>window.clearTimeout(t)},[i,g,T,W]);let J=(0,V.useMemo)(()=>[...d].sort((e,t)=>String(t.updated||``).localeCompare(String(e.updated||``))||e.title.localeCompare(t.title)),[d]),Y=(0,V.useMemo)(()=>{let e=r.collections.filter(e=>!g||e.id===g).map(e=>({schema:e,records:J.filter(t=>t.collection===e.id)})),t=new Set(r.collections.map(e=>e.id)),n=J.filter(e=>!t.has(e.collection));return n.length&&e.push({schema:{id:`other`,singular:`record`,idPrefix:`?`,statuses:[]},records:n}),e},[r.collections,J,g]);J.find(t=>t.id===e);let X=g?$(r.collections,g):[...new Set(r.collections.flatMap(e=>e.statuses))];return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(y,{gutter:`3.5`,className:`pt-3.5`,before:(0,H.jsx)(x,{scope:`records`,value:i,label:`Search workfile memory`,onChange:a}),after:(0,H.jsx)(`span`,{className:`flex shrink-0 items-center gap-1.5 whitespace-nowrap font-mono text-[11px] text-muted-foreground`,children:D?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(S,{"aria-hidden":`true`,className:`size-3`}),`loading…`]}):K(d.length,`record`)}),children:[(0,H.jsx)(b,{label:`collection`,value:g,options:r.collections.map(e=>({value:e.id})),onChange:e=>{w(e),E(``)}}),(0,H.jsx)(b,{label:`status`,value:T,options:X.map(e=>({value:e,color:c(e)})),onChange:E})]}),k?(0,H.jsx)(L,{variant:`destructive`,className:`mx-3.5 mt-3 w-auto px-3 py-2`,children:(0,H.jsxs)(j,{children:[`Memory could not be loaded: `,k]})}):null,(0,H.jsx)(`div`,{className:`flex min-h-0 flex-1 gap-3 overflow-hidden p-3.5`,children:(0,H.jsx)(`div`,{className:`flex min-h-0 flex-1 gap-3 overflow-x-auto`,children:Y.map(t=>(0,H.jsxs)(v,{className:`w-[272px] flex-none gap-0 overflow-hidden rounded-xl py-0 [--card-spacing:--spacing(2)]`,children:[(0,H.jsxs)(_,{className:`flex flex-row items-center gap-2 border-b px-3 py-2`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[11px] font-medium text-primary`,children:t.schema.idPrefix}),(0,H.jsx)(`span`,{className:`flex-1 text-[12.5px] font-semibold`,children:ee(t.schema.singular)}),(0,H.jsx)(P,{variant:`secondary`,className:`h-5 px-1.5 font-mono text-[11px] font-normal`,children:t.records.length}),t.schema.id===`other`?null:(0,H.jsx)(l,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`New ${t.schema.singular}`,disabled:s,title:s?p:void 0,onClick:()=>F(t.schema.id),children:(0,H.jsx)(o,{"aria-hidden":`true`})})]}),(0,H.jsxs)(C,{className:u(`flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto p-2.5`,G),children:[t.records.map(t=>(0,H.jsx)(te,{record:t,selected:t.id===e,onSelect:()=>U(t.id)},t.id)),!t.records.length&&!D?(0,H.jsx)(m,{className:`gap-1 border border-dashed p-4 md:p-6`,children:(0,H.jsx)(M,{className:`font-mono text-xs`,children:`no records`})}):null]})]},t.schema.id))})}),N===null?null:(0,H.jsx)(ne,{schema:r,initialCollection:N,onClose:()=>F(null),onCreated:e=>{F(null),h(t=>[e,...t]),t(e.id)}})]})}export{oe as MemoryPanel,se as MemoryView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{$ as r,Mt as i,it as a,lt as o}from"./ui-primitives-DRENhlck.js";import{n as s,o as c,s as l,u}from"./theme-CcOVK72d.js";import{A as d,D as f,M as p,O as m,a as h,b as g,j as _,k as v,tt as y,w as b}from"./index-DnoD4yDd.js";import{t as x}from"./layout-QiuZ_k5v.js";import{t as S}from"./progress-CzHcd1lF.js";var C=e(t(),1),w=n(),T=[{key:`N`,label:`Move to next`,status:`next`},{key:`D`,label:`Defer`,status:`deferred`},{key:`X`,label:`Discard`,status:`discarded`}];function E({tasks:e,repoRoot:t,repoUrl:n,onPatch:E,onOpen:D}){let O=b(),[k,A]=(0,C.useState)(()=>new Set),[j,M]=(0,C.useState)(0),N=(0,C.useMemo)(()=>e.filter(e=>!k.has(e.id)),[k,e]),P=N[j]||N[0],F=e.length;(0,C.useEffect)(()=>{j>=N.length&&M(Math.max(0,N.length-1))},[j,N.length]);let I=(0,C.useCallback)(async(e,t=!0)=>{if(P){try{await E(P.id,e)}catch{return}t&&(A(e=>new Set(e).add(P.id)),M(e=>Math.min(e,Math.max(0,N.length-2))))}},[E,N.length,P]);(0,C.useEffect)(()=>{if(O)return;let e=e=>{if(e.ctrlKey||e.metaKey||e.altKey)return;let t=e.target;if([`INPUT`,`SELECT`,`TEXTAREA`].includes(t.tagName)||t.isContentEditable)return;let n=e.key.toUpperCase();if(n===`J`||e.key===`ArrowDown`)e.preventDefault(),M(e=>Math.min(N.length-1,e+1));else if(n===`K`||e.key===`ArrowUp`)e.preventDefault(),M(e=>Math.max(0,e-1));else if(/^[1-4]$/.test(n))e.preventDefault(),I({priority:h[Number(n)-1]},!1);else{let t=T.find(e=>e.key===n);t&&(e.preventDefault(),I({status:t.status}))}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[I,N.length,O]);let L=e=>n?`${n.replace(/\/+$/,``)}/blob/main/${e}`:`vscode://file${t}/${e}`;return O?(0,w.jsx)(f,{className:`gap-3 p-10`,children:(0,w.jsxs)(d,{children:[(0,w.jsx)(_,{children:(0,w.jsx)(o,{"aria-hidden":`true`,size:20})}),(0,w.jsx)(p,{className:`text-sm`,children:`Triage needs a writable workspace`}),(0,w.jsx)(v,{className:`text-[12.5px]`,children:`This board is served read-only, and every action here assigns a status or a priority.`})]})}):P?(0,w.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-2 border-b bg-card px-3.5 py-2.5`,children:[(0,w.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-64 items-center gap-2.5`,children:[(0,w.jsx)(S,{value:F?k.size/F*100:0,className:`min-w-16 max-w-[340px] flex-1`}),(0,w.jsxs)(`span`,{className:`shrink-0 font-mono text-[11px] text-muted-foreground`,children:[k.size,` of `,F,` processed`]})]}),(0,w.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2.5`,children:[(0,w.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:j===0,onClick:()=>M(e=>Math.max(0,e-1)),children:[(0,w.jsx)(y,{className:`max-sm:hidden`,children:`K`}),`Previous`]}),(0,w.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground tabular-nums`,children:[j+1,` / `,N.length]}),(0,w.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:j>=N.length-1,onClick:()=>M(e=>Math.min(N.length-1,e+1)),children:[(0,w.jsx)(y,{className:`max-sm:hidden`,children:`J`}),`Next`]}),(0,w.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,title:`Open full card`,"aria-label":`Open full card`,className:`max-sm:size-7 max-sm:px-0`,onClick:()=>D(P.id),children:[(0,w.jsx)(a,{"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`max-sm:hidden`,children:`Open full card`})]})]})]}),(0,w.jsxs)(`div`,{className:u(x,`px-6 py-7 sm:px-8`),children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2 font-mono text-[11px] text-muted-foreground`,children:[(0,w.jsx)(`span`,{children:P.id}),(0,w.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,w.jsx)(`span`,{style:{color:c(P.status)},children:P.status}),(0,w.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,w.jsx)(`span`,{children:P.area}),(0,w.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,w.jsx)(`span`,{children:P.type})]}),(0,w.jsx)(`h2`,{className:`mt-3 mb-1 text-[26px] leading-[1.2] font-semibold tracking-tight [text-wrap:pretty]`,children:P.title}),P.file?(0,w.jsx)(`a`,{className:`font-mono text-[11px] text-muted-foreground/70 underline underline-offset-[3px]`,href:L(P.file),target:n?`_blank`:void 0,rel:n?`noreferrer`:void 0,children:P.file}):null,P.source?(0,w.jsxs)(`span`,{className:`mt-[3px] block font-mono text-[11px] text-muted-foreground/70`,children:[`source`,` `,(0,w.jsx)(`a`,{className:`font-mono underline underline-offset-[3px]`,href:L(P.source),target:n?`_blank`:void 0,rel:n?`noreferrer`:void 0,children:P.source})]}):null,(0,w.jsx)(`div`,{className:`mt-[22px]`,children:(0,w.jsx)(g,{source:P.body,onOpen:D})}),(0,w.jsxs)(`div`,{className:`mt-[30px] flex flex-wrap gap-2 border-t pt-[18px]`,children:[h.map((e,t)=>(0,w.jsxs)(l,{type:`button`,variant:`outline`,size:`lg`,"aria-pressed":P.priority===e,style:P.priority===e?{borderColor:s(e)}:void 0,onClick:()=>void I({priority:e},!1),children:[(0,w.jsx)(y,{children:t+1}),(0,w.jsx)(`span`,{style:{color:s(e)},children:e})]},e)),T.map(e=>(0,w.jsxs)(l,{type:`button`,variant:`outline`,size:`lg`,onClick:()=>void I({status:e.status}),children:[(0,w.jsx)(y,{children:e.key}),(0,w.jsx)(`span`,{style:{color:c(e.status)},children:e.label})]},e.key))]}),(0,w.jsx)(`span`,{className:`mt-3.5 block text-xs text-muted-foreground`,children:`Every action writes the card's frontmatter to disk immediately. Shortcuts work while focus is outside a form.`})]})]}):(0,w.jsxs)(f,{className:`gap-3 p-10`,children:[(0,w.jsxs)(d,{children:[(0,w.jsx)(_,{children:(0,w.jsx)(i,{"aria-hidden":`true`,size:20,style:{color:c(`done`)}})}),(0,w.jsx)(p,{className:`text-sm`,children:`Queue clear`}),(0,w.jsxs)(v,{className:`text-[12.5px]`,children:[`You processed `,k.size.toLocaleString(),` cards.`]})]}),(0,w.jsx)(m,{children:(0,w.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{A(new Set),M(0)},children:[(0,w.jsx)(r,{"aria-hidden":`true`}),`Start again`]})})]})}export{E as TriageView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{bt as r,ut as i}from"./ui-primitives-DRENhlck.js";import{r as a,s as o,u as s}from"./theme-CcOVK72d.js";import{I as c,nt as l,q as u}from"./index-DnoD4yDd.js";var d=e(t(),1),f=[{id:`parent`,label:`parent`,declared:!0},{id:`depends`,label:`depends`,declared:!0},{id:`origin`,label:`origin`,declared:!0},{id:`supersedes`,label:`supersedes`,declared:!0},{id:`superseded_by`,label:`superseded by`,declared:!0},{id:`graduated_to`,label:`graduated to`,declared:!0},{id:`corrective_actions`,label:`corrective`,declared:!0},{id:`cards`,label:`cards`,declared:!0},{id:`decisions`,label:`decisions`,declared:!0},{id:`fragments`,label:`fragments`,declared:!0},{id:`related`,label:`related`,declared:!0},{id:`source`,label:`source`,declared:!0},{id:`wikilink`,label:`wiki link`,declared:!1},{id:`markdown`,label:`md link`,declared:!1},{id:`mention`,label:`mention`,declared:!1}],p=new Set(f.filter(e=>e.declared).map(e=>e.id)),m=[{id:`card`,label:`Cards`},{id:`memory`,label:`Memory`},{id:`doc`,label:`Docs`},{id:`change`,label:`Changes`},{id:`release`,label:`Releases`}],h=f.map(e=>e.id).filter(e=>e!==`mention`),g=[`card`,`memory`,`doc`];function _(e,t){return e.kind!==`card`||!(t.status&&e.status!==t.status||t.area&&e.area!==t.area||t.type&&e.recordType!==t.type||t.priority&&e.priority!==t.priority||t.milestone&&e.milestone!==t.milestone)}function ee(e,t){let n=Object.values(t.record??{}).some(Boolean),r=e.filter(e=>t.kinds.has(e.kind)&&_(e,t.record??{}));if(n){let e=new Set(r.filter(e=>e.kind===`card`).map(e=>e.id)),n=new Set;for(let i of v(r,t.relations).links)e.has(i.from)&&n.add(i.to),e.has(i.to)&&n.add(i.from);r=r.filter(e=>e.kind===`card`||n.has(e.id))}let{links:i,degree:a}=v(r,t.relations),o=t.hideIsolated?r.filter(e=>a.get(e.id)):r;return{records:o,links:i,degree:a,isolated:r.length-o.length}}function v(e,t){let n=new Set(e.map(e=>e.id)),r=[],i=new Map;for(let a of e)for(let e of a.edges){if(!n.has(e.to)||e.to===a.id)continue;let o=e.rel.filter(e=>t.has(e));o.length&&(r.push({from:a.id,to:e.to,relations:o,declared:o.some(e=>p.has(e))}),i.set(a.id,(i.get(a.id)||0)+1),i.set(e.to,(i.get(e.to)||0)+1))}return{links:r,degree:i}}function y(e,t){let n=e*2.399963,r=18*Math.sqrt(e)+(t>200?40:0);return{x:Math.cos(n)*r,y:Math.sin(n)*r}}var b=9e3,x=.012,S=130,C=6e-4,w=.82;function te(e,t,n){for(let t=0;t<e.length;t+=1){let r=e[t];for(let i=t+1;i<e.length;i+=1){let a=e[i],o=r.x-a.x,s=r.y-a.y,c=o*o+s*s;c<1&&(o=(t-i)*.5,s=.5,c=o*o+s*s);let l=Math.sqrt(c),u=b*n/c,d=o/l*u,f=s/l*u;r.vx+=d,r.vy+=f,a.vx-=d,a.vy-=f}}let r=new Map(e.map(e=>[e.id,e]));for(let e of t){let t=r.get(e.from),i=r.get(e.to);if(!t||!i)continue;let a=i.x-t.x,o=i.y-t.y,s=Math.sqrt(a*a+o*o)||1,c=(s-S)*x*n,l=a/s*c,u=o/s*c;t.vx+=l,t.vy+=u,i.vx-=l,i.vy-=u}for(let t of e)t.vx-=t.x*C*n,t.vy-=t.y*C*n,t.vx*=w,t.vy*=w,t.x+=t.vx,t.y+=t.vy}function T(e,t,n){let r=new Map(e.map(e=>[e.id,e]));return t.map((e,i)=>{let a=r.get(e.id)??y(i,t.length);return{id:e.id,x:a.x,y:a.y,vx:0,vy:0,record:e,degree:n.get(e.id)||0}})}function E(e,t,n,r){let i=n-e,a=r-t,o=Math.sqrt(i*i+a*a)||1,s=Math.min(o*.18,60);return`M ${e} ${t} Q ${(e+n)/2-a/o*s} ${(t+r)/2+i/o*s} ${n} ${r}`}var D=.08;function O(e,t,n,r){let i=Math.min(4,Math.max(D,e.k*r));return{k:i,x:t-(t-e.x)/e.k*i,y:n-(n-e.y)/e.k*i}}function k(e,t,n){return{x:t-e.x,y:n-e.y}}function A(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x),i=Math.max(i,a.y);return{minX:t,minY:n,maxX:r,maxY:i}}var j=n(),M=`workfile-workflow-filters`;function N(){let e={relations:[...h],kinds:[...g],hideIsolated:!0};try{let t=localStorage.getItem(M);if(!t)return e;let n=JSON.parse(t);return{relations:Array.isArray(n.relations)?n.relations:e.relations,kinds:Array.isArray(n.kinds)?n.kinds:e.kinds,hideIsolated:typeof n.hideIsolated==`boolean`?n.hideIsolated:e.hideIsolated}}catch{return e}}function P({on:e,onClick:t,children:n,dashed:r}){return(0,j.jsx)(`button`,{type:`button`,"aria-pressed":e,onClick:t,className:s(`shrink-0 rounded-full border px-2 py-0.5 text-[11px] whitespace-nowrap transition-colors`,e?`border-ring bg-accent text-foreground`:`border-border text-muted-foreground hover:bg-accent/50`,r&&`border-dashed`),children:n})}function F({selectedId:e,onSelect:t,filters:n}){let[p,h]=(0,d.useState)(null),[g,_]=(0,d.useState)(null),v=(0,d.useRef)(N()),[y,b]=(0,d.useState)(()=>new Set(v.current.relations)),[x,S]=(0,d.useState)(()=>new Set(v.current.kinds)),[C,w]=(0,d.useState)(v.current.hideIsolated),[D,F]=(0,d.useState)(null),I=(0,d.useRef)(0),[L,R]=(0,d.useState)({x:0,y:0,k:1}),[,z]=(0,d.useState)(0),B=(0,d.useRef)({nodes:[],links:[],alpha:0}),V=(0,d.useRef)(null),H=(0,d.useRef)(!1);(0,d.useEffect)(()=>{let e=!0;return u.graph().then(t=>{e&&h(t.records)}).catch(t=>{e&&_(t.message)}),()=>{e=!1}},[]),(0,d.useEffect)(()=>{localStorage.setItem(M,JSON.stringify({relations:[...y],kinds:[...x],hideIsolated:C}))},[y,x,C]);let U=(0,d.useMemo)(()=>ee(p??[],{relations:y,kinds:x,hideIsolated:C,record:n}),[p,x,y,C,n]),W=(0,d.useMemo)(()=>Object.entries(n).filter(([,e])=>e).map(([e,t])=>`${e} ${t}`),[n]);(0,d.useEffect)(()=>{B.current.nodes=T(B.current.nodes,U.records,U.degree),B.current.links=U.links,B.current.alpha=1,z(e=>e+1)},[U]);let G=(0,d.useCallback)(()=>{let e=B.current.nodes,t=V.current;if(!e.length||!t)return;let n=t.getBoundingClientRect(),{minX:r,minY:i,maxX:a,maxY:o}=A(e),s=Math.min(3,Math.max(.15,Math.min(n.width/(a-r+160),n.height/(o-i+160))));R({k:s,x:n.width/2-(r+a)/2*s,y:n.height/2-(i+o)/2*s})},[]);(0,d.useEffect)(()=>{let e=0,t=()=>{let n=B.current;n.alpha>.02&&n.nodes.length&&(te(n.nodes,n.links,n.alpha),n.alpha*=.97,H.current||G(),z(e=>e+1)),e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>cancelAnimationFrame(e)},[G]);let ne=e=>{e.preventDefault();let t=V.current?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left,r=e.clientY-t.top;H.current=!0;let i=e.deltaY<0?1.12:.89;R(e=>O(e,n,r,i))},K=(0,d.useRef)(null),re=e=>{H.current=!0,K.current={x:e.clientX-L.x,y:e.clientY-L.y},e.target.setPointerCapture?.(e.pointerId)},ie=e=>{let t=K.current;if(!t)return;let n=k(t,e.clientX,e.clientY);R(e=>({...e,...n}))},q=()=>{K.current=null},J=(e,t,n)=>{let r=new Set(e);r.has(n)?r.delete(n):r.add(n),t(r)},Y=B.current.nodes,X=(0,d.useMemo)(()=>new Map(Y.map(e=>[e.id,e])),[Y,L]),Z=D??e,Q=Z?X.get(Z):void 0,$=(0,d.useMemo)(()=>{if(!Z)return null;let e=new Set([Z]);for(let t of U.links)t.from===Z&&e.add(t.to),t.to===Z&&e.add(t.from);return e},[Z,U.links]);return g?(0,j.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`The graph could not be read: `,g]}):(0,j.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,j.jsxs)(c,{gutter:`3`,className:`shrink-0 border-b py-2`,after:(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`span`,{className:`hidden text-[11px] whitespace-nowrap text-muted-foreground sm:inline`,children:[U.records.length,` nodes · `,U.links.length,` `,`edges`]}),(0,j.jsxs)(o,{type:`button`,variant:`outline`,size:`sm`,className:`shrink-0 px-2`,onClick:()=>{H.current=!1,G()},children:[(0,j.jsx)(r,{"aria-hidden":`true`,className:`size-3`}),`Fit`]})]}),children:[(0,j.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:m.map(e=>(0,j.jsx)(P,{on:x.has(e.id),onClick:()=>J(x,S,e.id),children:e.label},e.id))}),(0,j.jsx)(`span`,{className:`h-4 w-px shrink-0 bg-border`,"aria-hidden":`true`}),(0,j.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:f.map(e=>(0,j.jsx)(P,{on:y.has(e.id),dashed:!e.declared,onClick:()=>J(y,b,e.id),children:e.label},e.id))}),(0,j.jsx)(`span`,{className:`h-4 w-px shrink-0 bg-border`,"aria-hidden":`true`}),(0,j.jsx)(P,{on:C,onClick:()=>w(!C),children:`hide isolated`})]}),(0,j.jsxs)(`div`,{className:`relative min-h-0 flex-1 overflow-hidden`,children:[p?null:(0,j.jsxs)(`div`,{className:`flex h-full items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,j.jsx)(i,{"aria-hidden":`true`,className:`size-4 animate-spin`}),`Reading the graph…`]}),p?.length&&!U.records.length?(0,j.jsx)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-1.5 px-6 text-center text-sm text-muted-foreground`,children:U.isolated?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`span`,{children:[U.isolated,` `,U.isolated===1?`record matches`:`records match`,`, and`,` `,U.isolated===1?`it is`:`none is`,` `,`connected to anything else here.`]}),(0,j.jsx)(o,{type:`button`,variant:`outline`,size:`sm`,className:`px-2`,onClick:()=>w(!1),children:`Show unconnected records`})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`span`,{children:`No records match these filters.`}),(0,j.jsx)(`span`,{className:`text-xs`,children:W.length?`${W.join(`, `)} above, and ${x.size} of ${m.length} kinds here.`:`${x.size} of ${m.length} kinds and ${y.size} of ${f.length} relationships.`})]})}):null,(0,j.jsxs)(`svg`,{ref:V,role:`presentation`,className:`size-full cursor-grab touch-none active:cursor-grabbing`,onWheel:ne,onPointerDown:re,onPointerMove:ie,onPointerUp:q,onPointerLeave:q,children:[(0,j.jsx)(`defs`,{children:(0,j.jsx)(`marker`,{id:`workflow-arrow`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`5`,markerHeight:`5`,orient:`auto-start-reverse`,children:(0,j.jsx)(`path`,{d:`M 0 1 L 7 4 L 0 7 z`,className:`fill-muted-foreground`})})}),(0,j.jsxs)(`g`,{transform:`translate(${L.x} ${L.y}) scale(${L.k})`,children:[U.links.map(e=>{let t=X.get(e.from),n=X.get(e.to);if(!t||!n)return null;let r=$&&!($.has(e.from)&&$.has(e.to));return(0,j.jsx)(`path`,{d:E(t.x,t.y,n.x,n.y),fill:`none`,markerEnd:`url(#workflow-arrow)`,className:s(`stroke-muted-foreground transition-opacity`,r?`opacity-10`:`opacity-45`),strokeWidth:1.2/L.k,strokeDasharray:e.declared?void 0:`${4/L.k} ${3/L.k}`,children:(0,j.jsx)(`title`,{children:`${e.from} → ${e.to}: ${e.relations.join(`, `)}`})},`${e.from}->${e.to}`)}),Y.map(n=>{let r=$&&!$.has(n.id),i=n.id===e,o=Math.min(16,6+Math.sqrt(n.degree)*2);return(0,j.jsxs)(`g`,{transform:`translate(${n.x} ${n.y})`,className:s(`cursor-pointer transition-opacity`,r&&`opacity-20`),onPointerEnter:()=>F(n.id),onPointerLeave:()=>F(null),onClick:e=>{e.stopPropagation(),I.current=performance.now(),t(n.id)},children:[(0,j.jsx)(`circle`,{r:o,style:{fill:a(n.record.status||`backlog`)},className:s(i?`stroke-foreground`:`stroke-background`),strokeWidth:(i?3:1.5)/L.k}),(0,j.jsx)(`title`,{children:`${n.id} — ${n.record.title}`}),L.k>.55||i||r===!1?(0,j.jsx)(`text`,{y:o+11/L.k,textAnchor:`middle`,className:`pointer-events-none fill-foreground`,style:{fontSize:`${11/L.k}px`},children:n.id}):null]},n.id)})]})]}),Q?(0,j.jsxs)(`div`,{className:`pointer-events-none absolute bottom-3 left-3 max-w-[min(30rem,70%)] rounded-md border bg-background/95 px-3 py-2 shadow-sm`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(`span`,{className:`font-mono text-[11px] font-medium`,children:Z}),(0,j.jsx)(l,{variant:`secondary`,className:`px-1.5 py-0 text-[10px] font-normal`,children:Q.record.recordType})]}),(0,j.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:Q.record.title})]}):null]})]})}export{F as WorkflowView};

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display