🎩 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.5.0
to
0.5.1
+1
dist/ui/static/Boards-p7YzNgZN.js
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{_t as r,mt as i,pt as a,rt as o}from"./ui-primitives-wYj92QGw.js";import{a as s,f as c,i as l,m as u,o as d,p as f,r as p,s as m,t as h,u as g}from"./empty-BHqXimMR.js";import{A as _,G as v,Q as y,U as b,X as x,Y as S,Z as C,j as w,n as T,q as E,r as D,t as O}from"./index-CSPF1W21.js";var k=e(t(),1),A=n(),j=[];function M(e,t){let[n,r]=(0,k.useState)(t);(0,k.useEffect)(()=>{r(t)},[e.length,t]);let i=(0,k.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 N({onVisible:e,remaining:t}){let n=(0,k.useRef)(null);return(0,k.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,A.jsxs)(`span`,{ref:n,className:`px-0.5 py-1 font-mono text-[11px] text-muted-foreground`,children:[`+`,t,` more`]})}function P({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,s=Number.isNaN(o)?null:Math.max(0,Math.floor((Date.now()-o)/864e5)),l=[t&&t!==e.id?`epic ${t}`:``,e.effort?`effort ${e.effort}`:``,e.claimed_by?`claimed by ${e.claimed_by}${s==null?``:` · ${s}d`}`:``].filter(Boolean);return(0,A.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:l.length?l.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,A.jsxs)(`span`,{className:`flex items-center`,children:[(0,A.jsx)(`span`,{className:`font-mono text-[11px] text-foreground/70`,children:e.id}),(0,A.jsx)(`span`,{className:`flex-1`}),(0,A.jsx)(`span`,{className:`font-mono text-[10px] font-medium`,style:{color:m(e.priority)},children:e.priority})]}),(0,A.jsx)(`span`,{className:`text-[12.5px] leading-snug font-medium`,role:`heading`,"aria-level":3,children:e.title}),(0,A.jsxs)(`span`,{className:`flex items-center gap-1.5 font-mono text-[10px] text-muted-foreground`,children:[(0,A.jsx)(`span`,{children:e.area}),(0,A.jsx)(`span`,{children:`·`}),(0,A.jsx)(`span`,{children:e.type}),e.claimed_by?(0,A.jsxs)(`span`,{className:`ml-auto inline-flex min-w-0 items-center gap-[5px]`,style:{color:c(`doing`)},children:[(0,A.jsx)(`span`,{className:`size-[5px] flex-none rounded-full bg-current`,"aria-hidden":`true`}),(0,A.jsx)(`span`,{className:`max-w-[90px] truncate`,children:e.claimed_by})]}):null]}),Array.isArray(e.scope)&&e.scope.length?(0,A.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 F({status:e,cards:t,epicIds:n,collapsed:r,onToggleCollapsed:m,onOpen:g,onMove:v,onCarry:b,carryingId:x,isDropTarget:S,onDragEnterColumn:C,onDragLeaveColumn:T}){let[E,D,O]=M(t,25),k=c(e),j={onDragOver:t=>{t.preventDefault(),t.dataTransfer.dropEffect=`move`,C?.(e)},onDragLeave:t=>{t.currentTarget.contains(t.relatedTarget)||T?.(e)},onDrop:t=>{t.preventDefault(),T?.(e);let n=t.dataTransfer.getData(`text/plain`);n&&v(n,e).catch(()=>void 0)}};return r?(0,A.jsxs)(w,{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`,S&&`border-primary`),...j,children:[(0,A.jsx)(_,{edge:`top`,color:k}),(0,A.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`,S&&`bg-accent/50`),onClick:m,children:[(0,A.jsx)(i,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-muted-foreground`}),(0,A.jsx)(`span`,{className:`min-h-0 flex-1 truncate font-mono text-[11px] uppercase tracking-[0.06em] [writing-mode:vertical-rl]`,style:{color:k},children:e}),(0,A.jsx)(y,{variant:`secondary`,className:`h-5 shrink-0 rounded-md px-[7px] font-mono text-[11px] font-normal`,children:t.length})]})]}):(0,A.jsxs)(w,{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`,S&&`border-primary`),...j,children:[(0,A.jsx)(_,{edge:`top`,color:k}),(0,A.jsxs)(`header`,{className:`flex flex-none items-center gap-2 px-3 pb-2.5 pt-4`,children:[(0,A.jsx)(`span`,{className:`flex-1 font-mono text-[11px] uppercase tracking-[0.06em]`,style:{color:k},children:e}),(0,A.jsx)(y,{variant:`secondary`,className:`h-5 rounded-md px-[7px] font-mono text-[11px] font-normal`,children:t.length}),m?(0,A.jsx)(f,{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:m,children:(0,A.jsx)(a,{"aria-hidden":`true`})}):null]}),(0,A.jsxs)(`div`,{className:u(`scroll-fade flex flex-1 flex-col gap-2 overflow-y-auto p-2.5`,S&&`bg-accent/50`),children:[t.length===0?(0,A.jsx)(h,{className:`flex-1 gap-2 rounded-lg border border-dashed p-4`,children:(0,A.jsxs)(l,{className:`gap-1`,children:[(0,A.jsx)(s,{variant:`icon`,className:`mb-0 size-8 [&_svg:not([class*='size-'])]:size-4`,children:(0,A.jsx)(o,{"aria-hidden":`true`})}),(0,A.jsx)(d,{className:`text-[12.5px] font-medium`,children:`No cards`}),(0,A.jsx)(p,{className:`text-[11.5px]`,children:`Nothing in this state.`})]})}):E.map(e=>(0,A.jsx)(P,{task:e,epicId:n.get(e.id),onOpen:g,onCarry:b?()=>b(e):void 0,carrying:x===e.id,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,e.id)}},e.id)),D&&(0,A.jsx)(N,{onVisible:O,remaining:t.length-E.length})]})]})}function I({tasks:e,epicIds:t,showClosed:n,onOpen:r,onMove:i}){let[a,o]=(0,k.useState)(null),[s,c]=(0,k.useState)(null),[l,u]=(0,k.useState)(``),[d,f]=(0,k.useState)(()=>{try{let e=localStorage.getItem(`workfile-flow-collapsed`);return new Set(e?JSON.parse(e):[])}catch{return new Set}}),p=(0,k.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,k.useMemo)(()=>[`backlog`,`next`,`doing`,`review`,`blocked`,`deferred`,...n?[`done`,`discarded`]:[]],[n]),h=(0,k.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,A.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,A.jsx)(`p`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:l}),m.map(e=>(0,A.jsx)(F,{status:e,cards:h.get(e)??j,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 L({tasks:e,allTasks:t,epicIds:n,onOpen:r}){let i=(0,k.useMemo)(()=>new Map(t.map(e=>[e.id,e])),[t]),a=(0,k.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,A.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3.5`,children:(0,A.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}],p=(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,A.jsx)(`span`,{className:`font-mono text-[11.5px] text-foreground/70`,children:e===`__none`?`—`:e}),(0,A.jsx)(`span`,{className:`min-w-0 flex-1 text-sm font-semibold tracking-[-0.01em] text-pretty`,children:n?.title||`Without epic`}),n?(0,A.jsx)(`span`,{className:`font-mono text-[11px]`,style:{color:c(n.status)},children:n.status}):null,(0,A.jsxs)(`span`,{className:`font-mono text-[11.5px] text-muted-foreground`,children:[o,`/`,a]})]}),(0,A.jsx)(`span`,{className:`flex h-2 w-full overflow-hidden rounded-full bg-muted`,"aria-hidden":`true`,children:a>0?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`span`,{className:`h-full`,style:{width:d(o),background:c(`done`)}}),(0,A.jsx)(`span`,{className:`h-full`,style:{width:d(s),background:c(`doing`)}})]}):null}),(0,A.jsxs)(`span`,{className:`flex flex-wrap items-center gap-3.5 font-mono text-[10.5px] text-muted-foreground`,children:[f.map(e=>(0,A.jsxs)(`span`,{className:`inline-flex items-center gap-[5px]`,children:[(0,A.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,A.jsx)(`span`,{className:`ml-auto`,children:n?.area??``})]})]});return n?(0,A.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:p},e):(0,A.jsx)(w,{className:`gap-2.5 rounded-xl px-4 py-3.5 shadow-xs`,children:p},e)})})}):(0,A.jsx)(h,{className:`flex-1 p-6`,children:(0,A.jsxs)(l,{children:[(0,A.jsx)(d,{className:`text-sm`,children:`No epics`}),(0,A.jsx)(p,{className:`text-[11.5px]`,children:`No cards match the current filters.`})]})})}var R=300,z=30;function B({task:e,span:t,mode:n,epicId:r,pct:i,labelWidth:a,onOpen:o}){let s=c(e.status);return(0,A.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),title:`${D(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,A.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,A.jsx)(`span`,{className:`flex-none whitespace-nowrap font-mono text-[11px] text-foreground/70`,children:e.id}),(0,A.jsx)(`span`,{className:`min-w-0 truncate text-[12.5px]`,children:e.title})]}),(0,A.jsx)(`span`,{className:`relative block flex-1`,style:{height:`var(--row-h)`},children:t.point?(0,A.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,A.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 V({tasks:e,epicIds:t,axes:n={},mode:i,counts:a,onModeChange:o,onOpen:s}){let c=b()?168:R,u=c+460,[m,_]=(0,k.useState)(()=>{try{return localStorage.getItem(`workfile-timeline-group`)||`none`}catch{return`none`}}),y=(0,k.useCallback)(e=>{_(e);try{localStorage.setItem(`workfile-timeline-group`,e)}catch{}},[]),w=(0,k.useMemo)(()=>[`none`,`epic`,`area`,...Object.keys(n)],[n]),D=w.includes(m)?m:`none`,j=(0,k.useCallback)(e=>{if(D===`epic`)return t.get(e.id)||``;if(D===`area`)return e.area||``;let n=e[D];return typeof n==`string`?n:``},[t,D]),M=(0,k.useMemo)(()=>{let t=new Map;for(let n of e){let e=T(n,i);e&&t.set(n.id,e)}return t},[i,e]),N=(0,k.useMemo)(()=>{let t=(e,t)=>M.get(e.id).from-M.get(t.id).from||e.id.localeCompare(t.id),n=e.filter(e=>M.has(e.id)).sort(t);return D===`none`?n:[...n].sort((e,n)=>{let r=j(e),i=j(n);return!r==!i?r.localeCompare(i)||t(e,n):r?-1:1})},[j,D,M,e]),P=(0,k.useMemo)(()=>{if(D===`none`)return N.map(e=>({task:e,label:null}));let e=[],t=null;for(let n of N){let r=j(n);r!==t&&(t=r,e.push({task:null,label:r||`no ${D}`})),e.push({task:n,label:null})}return e},[j,D,N]),F=(0,k.useMemo)(()=>new Map(P.flatMap((e,t)=>e.task?[[e.task.id,t]]:[])),[P]),I=(0,k.useMemo)(()=>{let e=[];for(let t of N)for(let n of t.depends||[])F.has(n)&&e.push({from:n,to:t.id});return e},[F,N]),L=(0,k.useMemo)(()=>O(N.map(e=>M.get(e.id)),Date.now()),[N,M]),V=a[i===`plan`?`actual`:`plan`];return!N.length||!L?(0,A.jsx)(h,{className:`flex-1 p-6`,children:(0,A.jsxs)(l,{children:[(0,A.jsx)(d,{className:`text-sm`,children:i===`plan`?`Nothing scheduled`:`Nothing recorded`}),(0,A.jsx)(p,{className:`text-[11.5px]`,children:i===`plan`?`Add a start or due date to a card.`:`Cards record a trail as they are claimed and moved.`}),V>0?(0,A.jsx)(p,{className:`text-[11.5px]`,children:(0,A.jsx)(f,{variant:`outline`,size:`sm`,className:`mt-2 text-[12.5px] font-medium`,onClick:()=>o(i===`plan`?`actual`:`plan`),children:i===`plan`?`show what actually happened · ${V} cards`:`show the schedule · ${V} cards`})}):null]})}):(0,A.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,A.jsxs)(`div`,{className:`no-scrollbar flex flex-none items-center gap-2.5 overflow-x-auto border-b bg-card px-3.5 py-2`,children:[(0,A.jsxs)(`span`,{className:`shrink-0 font-mono text-[11px] whitespace-nowrap text-muted-foreground`,children:[N.length,` `,i===`actual`?`recorded`:`scheduled`,` ·`,` `,I.length,` dependenc`,I.length===1?`y`:`ies`]}),(0,A.jsxs)(v,{children:[(0,A.jsx)(C,{asChild:!0,children:(0,A.jsxs)(f,{variant:`outline`,size:`sm`,"aria-label":`dates`,className:`ml-auto shrink-0 text-[12.5px] font-medium`,children:[`dates`,(0,A.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:i}),(0,A.jsx)(r,{className:`size-[13px] text-muted-foreground`})]})}),(0,A.jsx)(E,{align:`end`,children:(0,A.jsxs)(S,{value:i,onValueChange:e=>o(e),children:[(0,A.jsx)(x,{value:`plan`,children:`plan`}),(0,A.jsx)(x,{value:`actual`,children:`actual`})]})})]}),(0,A.jsxs)(v,{children:[(0,A.jsx)(C,{asChild:!0,children:(0,A.jsxs)(f,{variant:`outline`,size:`sm`,"aria-label":`group`,className:`shrink-0 text-[12.5px] font-medium`,children:[`group`,(0,A.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:D}),(0,A.jsx)(r,{className:`size-[13px] text-muted-foreground`})]})}),(0,A.jsx)(E,{align:`end`,children:(0,A.jsx)(S,{value:D,onValueChange:y,children:w.map(e=>(0,A.jsx)(x,{value:e,children:e},e))})})]})]}),(0,A.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,A.jsxs)(`div`,{className:`relative min-h-full`,style:{minWidth:u},children:[(0,A.jsxs)(`div`,{"aria-hidden":`true`,className:`sticky top-0 z-[2] flex items-stretch border-b bg-card`,style:{height:z},children:[(0,A.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,A.jsx)(`span`,{className:`relative flex-1`,children:L.ticks.map((e,t)=>(0,A.jsx)(`span`,{className:`text-[10px] uppercase tracking-[0.08em] text-muted-foreground`,style:{position:`absolute`,top:`50%`,transform:`translateY(-50%)`,left:`${e.left}%`,width:`${(L.ticks[t+1]?.left??100)-e.left}%`,overflow:`hidden`,paddingLeft:8,whiteSpace:`nowrap`},children:e.label},e.key))})]}),(0,A.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute`,style:{top:z,bottom:0,left:c,right:0},children:[L.ticks.map(e=>(0,A.jsx)(`span`,{className:`absolute inset-y-0 w-px bg-border`,style:{left:`${e.left}%`}},e.key)),L.today!=null&&(0,A.jsx)(`span`,{className:`absolute inset-y-0 w-px`,style:{background:g(`error`),opacity:.55,left:`${L.today}%`}})]}),(0,A.jsxs)(`div`,{className:`relative`,children:[I.length>0&&(0,A.jsx)(`svg`,{"aria-hidden":`true`,preserveAspectRatio:`none`,viewBox:`0 0 100 ${P.length}`,className:`pointer-events-none absolute top-0 h-full`,style:{left:c,width:`calc(100% - ${c}px)`},children:I.map(e=>{let t=M.get(e.from),n=M.get(e.to);if(!t||!n)return null;let r=L.pct(t.to),i=L.pct(n.from),a=F.get(e.from)+.5,o=F.get(e.to)+.5;return(0,A.jsx)(`path`,{d:`M ${r} ${a} C ${(r+i)/2} ${a}, ${(r+i)/2} ${o}, ${i} ${o}`,vectorEffect:`non-scaling-stroke`,style:i<r?{fill:`none`,stroke:g(`error`),strokeWidth:1.5,strokeDasharray:`3 2`}:{fill:`none`,stroke:`var(--muted-foreground)`,strokeWidth:1.5,opacity:.4}},`${e.from}-${e.to}`)})}),P.map((e,n)=>e.task?(0,A.jsx)(B,{task:e.task,span:M.get(e.task.id),mode:i,epicId:t.get(e.task.id),pct:L.pct,labelWidth:c,onOpen:s},e.task.id):(0,A.jsx)(`div`,{className:`border-b bg-muted/40`,children:(0,A.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{L as EpicsView,I as FlowBoard,V as TimelineView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{F as r,V as i,gt as ee,q as te,st as a,z as o}from"./ui-primitives-wYj92QGw.js";import{i as ne,l as s,m as c,o as re,p as l,r as ie,t as ae}from"./empty-BHqXimMR.js";import{n as u,t as d}from"./native-select-NN1SzVJL.js";import{$ as f,C as p,E as m,H as h,I as g,O as oe,Q as _,S as se,T as ce,U as le,_ as ue,b as v,c as de,d as fe,et as y,f as pe,g as me,h as he,k as ge,l as _e,p as ve,v as b,x as ye,y as x}from"./index-CSPF1W21.js";import{t as be}from"./layout-QiuZ_k5v.js";var S=e(t(),1),C=n(),w=`doc-h`,xe=[`current`,`draft`,`superseded`,`archived`],T=`text-[10px] font-medium tracking-[0.07em] uppercase text-muted-foreground`;function Se({document:e,selected:t,onSelect:n}){return(0,C.jsx)(m,{asChild:!0,size:`sm`,className:c(`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,C.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,children:[(0,C.jsxs)(`span`,{className:`flex w-full items-center gap-1.5`,children:[(0,C.jsx)(`span`,{className:`flex-1 truncate text-xs font-medium`,children:e.title}),(0,C.jsx)(`span`,{className:c(`font-mono text-[10px]`,!e.managed&&`text-muted-foreground`),style:e.managed?{color:s(e.status)}:void 0,children:e.managed?e.status:`indexed`})]}),(0,C.jsx)(`span`,{className:`w-full truncate font-mono text-[10px] text-muted-foreground`,children:e.path})]})})}function Ce({entries:e,activeId:t,onJump:n}){let r=Math.min(...e.map(e=>e.level));return(0,C.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,C.jsx)(`span`,{className:c(T,`px-2`),children:`on this page`}),(0,C.jsx)(`nav`,{className:`mt-2 flex flex-col gap-px`,children:e.map(e=>{let i=e.id===t;return(0,C.jsx)(`button`,{type:`button`,"aria-current":i?`true`:void 0,className:c(`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 E({label:e,value:t}){return(0,C.jsxs)(b,{className:`w-auto min-w-[120px] gap-0.5 rounded-lg border bg-card px-3 py-2 shadow-xs`,children:[(0,C.jsx)(`span`,{className:T,children:e}),(0,C.jsx)(`span`,{className:`text-[13px] font-medium`,children:t})]})}function D({label:e,links:t,onOpen:n}){return t.length?(0,C.jsxs)(`section`,{className:`flex flex-col gap-1.5`,children:[(0,C.jsx)(`span`,{className:T,children:e}),t.map((e,t)=>{let r=!e.exists&&!e.title;return(0,C.jsx)(m,{asChild:!0,variant:`outline`,size:`sm`,className:c(`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,C.jsxs)(`button`,{type:`button`,disabled:r,onClick:()=>n(e.id),children:[(0,C.jsx)(`span`,{className:`min-w-[78px] shrink-0 font-mono text-[11px] font-medium`,children:e.id}),(0,C.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.relation?(0,C.jsx)(_,{variant:`secondary`,className:`font-mono text-[10px]`,children:e.relation}):null]})},`${e.id}-${t}`)})]}):null}var O=(0,C.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted-foreground`,children:`·`});function k({selectedId:e,onSelect:t,onOpenCard:n}){let[m,_]=(0,S.useState)([]),[k,A]=(0,S.useState)(``),[j,M]=(0,S.useState)(!0),[N,P]=(0,S.useState)(``),[F,I]=(0,S.useState)(!1),[L,we]=(0,S.useState)(!1),[R,z]=(0,S.useState)(null),[B,V]=(0,S.useState)(!1),[H,U]=(0,S.useState)(``),[W,Te]=(0,S.useState)(null),[Ee,G]=(0,S.useState)(0);ge(e=>{oe(e,`/docs/`,`docs/`)&&G(e=>e+1)}),(0,S.useEffect)(()=>{let e=!1;M(!0);let t=window.setTimeout(()=>{g.docs(k.trim()).then(t=>{e||(_(t.records),P(``))}).catch(t=>{e||P(t instanceof Error?t.message:String(t))}).finally(()=>{e||M(!1)})},k?180:0);return()=>{e=!0,window.clearTimeout(t)}},[k,Ee]),(0,S.useEffect)(()=>{if(!R||W)return;let e=!1;return g.tasks().then(t=>{e||Te(t.schema.docs)}).catch(()=>{}),()=>{e=!0}},[R,W]);let K=(0,S.useMemo)(()=>F?m.filter(e=>e.managed):m,[m,F]),q=(0,S.useMemo)(()=>{let e=K.filter(e=>e.managed),t=K.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)},[K]),De=le(),J=K.find(t=>t.id===e)||(De?void 0:K[0]),Y=(0,S.useRef)(null),[Oe,X]=(0,S.useState)(``),Z=(0,S.useMemo)(()=>J&&!L?se(J.body,w):[],[J,L]),Q=Z.length>1;(0,S.useEffect)(()=>{X(``);let e=Y.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 ke=e=>{document.getElementById(e)?.scrollIntoView({block:`start`,behavior:`smooth`}),X(e)},$=e=>{let r=m.find(t=>t.id===e);r?t(r.id):n(e)},Ae=(0,S.useMemo)(()=>{let e=new Set(W?.kinds??[]);for(let t of m)t.managed&&e.add(t.documentKind);return R&&e.add(R.kind),[...e].sort()},[W,m,R]),je=(0,S.useMemo)(()=>{let e=new Set(W?.statuses??xe);for(let t of m)t.managed&&e.add(t.status);return R&&e.add(R.status),[...e].sort()},[W,m,R]);function Me(e){U(``),z({id:e.id,title:e.title,kind:e.documentKind,status:e.status,owners:(e.owners??[]).join(`, `),reviewed:e.reviewed??``})}async function Ne(){if(!R)return;let e=m.find(e=>e.id===R.id);if(!e){U(`This document no longer exists in the workspace.`);return}let t=R.owners.split(`,`).map(e=>e.trim()).filter(Boolean),n={},r=R.title.trim();if(r&&r!==e.title&&(n.title=r),R.kind!==e.documentKind&&(n.kind=R.kind),R.status!==e.status&&(n.status=R.status),t.join(`
`)!==(e.owners??[]).join(`
`)&&(n.owners=t),(R.reviewed||``)!==(e.reviewed??``)&&(n.reviewed=R.reviewed||null),!Object.keys(n).length){z(null);return}V(!0),U(``);try{let t=await g.patchDocument(e.id,n,e.revision);_(n=>n.map(n=>n.id===e.id?t.record:n)),z(null)}catch(e){let t=e;t.code?.endsWith(`WRITE_CONFLICT`)?(G(e=>e+1),U(`The document changed on disk; the list was refreshed. Save again to apply your changes to the latest revision.`)):U(t.message||String(e))}finally{V(!1)}}return(0,C.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,C.jsxs)(`aside`,{"aria-label":`Documents`,className:c(`min-h-0 w-full shrink-0 flex-col border-r px-2 py-3 lg:flex lg:w-[290px]`,J?`hidden`:`flex`),children:[(0,C.jsxs)(`div`,{className:`flex flex-col gap-2 pb-2.5`,children:[(0,C.jsxs)(he,{className:`h-8`,children:[(0,C.jsx)(me,{children:(0,C.jsx)(i,{"aria-hidden":`true`})}),(0,C.jsx)(ue,{className:`h-8`,type:`search`,value:k,"aria-label":`Search documentation`,placeholder:`Search documentation…`,onChange:e=>A(e.target.value)})]}),(0,C.jsx)(`div`,{className:`flex gap-1.5`,children:(0,C.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,"aria-pressed":F,className:c(`h-7 gap-1.5 px-2.5 text-xs`,F&&`border-ring bg-accent`),onClick:()=>I(!F),children:[`managed`,(0,C.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:F?`only`:`all`})]})})]}),(0,C.jsx)(`div`,{"aria-busy":j||void 0,className:`min-h-0 flex-1 overflow-y-auto`,children:j?(0,C.jsxs)(`span`,{className:`flex items-center gap-2 px-2 py-1.5 font-mono text-[10.5px] text-muted-foreground`,children:[(0,C.jsx)(ce,{className:`size-3`}),`Loading documents…`]}):N?(0,C.jsx)(f,{variant:`destructive`,className:`mt-1.5`,children:(0,C.jsx)(y,{children:N})}):q.length?q.map(e=>(0,C.jsxs)(`div`,{className:`flex flex-col gap-px pb-3.5`,children:[(0,C.jsxs)(`span`,{className:`flex items-center gap-2 px-2 py-1.5 font-mono text-[10.5px] text-muted-foreground`,children:[(0,C.jsx)(`span`,{className:`text-foreground/80`,children:e.label}),(0,C.jsx)(`span`,{children:e.docs.length})]}),e.docs.map(e=>(0,C.jsx)(Se,{document:e,selected:J?.id===e.id,onSelect:()=>t(e.id)},e.id))]},e.key)):(0,C.jsx)(ae,{className:`gap-2 p-4 md:p-4`,children:(0,C.jsxs)(ne,{children:[(0,C.jsx)(re,{className:`text-sm`,children:`No documents found.`}),(0,C.jsx)(ie,{className:`text-xs`,children:F?`Try another search, or include indexed files.`:`Try another search.`})]})})})]}),(0,C.jsx)(`section`,{ref:Y,className:c(`min-w-0 flex-1 overflow-y-auto px-6 py-6.5 sm:px-8.5`,J?`block`:`hidden lg:block`),children:(0,C.jsx)(`div`,{className:be,children:J?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(l,{type:`button`,variant:`ghost`,size:`sm`,className:`-ml-2 mb-2 lg:hidden`,onClick:()=>t(``),children:[(0,C.jsx)(ee,{"aria-hidden":`true`}),`All documents`]}),(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 font-mono text-[11px] text-muted-foreground`,children:[(0,C.jsx)(`span`,{children:J.id}),O,(0,C.jsx)(`span`,{children:J.documentKind}),O,(0,C.jsx)(`span`,{style:{color:s(J.status)},children:J.status}),O,(0,C.jsx)(`span`,{children:J.managed?`managed`:`indexed`}),(0,C.jsx)(`span`,{className:`flex-1`}),J.managed?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>we(e=>!e),children:[L?(0,C.jsx)(a,{"aria-hidden":`true`}):(0,C.jsx)(te,{"aria-hidden":`true`}),L?`Preview`:`Edit`]}),(0,C.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>Me(J),children:[(0,C.jsx)(o,{"aria-hidden":`true`}),`Metadata`]})]}):null]}),(0,C.jsx)(`h2`,{className:`mt-3 mb-1.5 text-2xl font-semibold tracking-tight`,children:J.title}),(0,C.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground [overflow-wrap:anywhere]`,children:J.path}),(0,C.jsxs)(`div`,{className:`mt-4.5 flex flex-wrap gap-2`,children:[(0,C.jsx)(E,{label:`kind`,value:J.documentKind}),(0,C.jsx)(E,{label:`status`,value:J.status}),(0,C.jsx)(E,{label:`reviewed`,value:J.reviewed||`—`}),(0,C.jsx)(E,{label:`owners`,value:J.owners?.join(`, `)||`—`}),(0,C.jsx)(E,{label:`backlinks`,value:String(J.incomingTotal??J.incoming.length)}),J.updated?(0,C.jsx)(E,{label:`updated`,value:J.updated}):null]}),J.freshness.length>0?(0,C.jsxs)(f,{role:`status`,className:`mt-4.5 max-w-2xl`,children:[(0,C.jsx)(r,{"aria-hidden":`true`,className:`text-sev-warning`}),(0,C.jsx)(y,{children:J.freshness.map(e=>(0,C.jsx)(`span`,{children:e.message},`${e.code}-${e.message}`))})]}):null,(0,C.jsx)(`div`,{className:`mt-6.5`,children:L&&J.managed?(0,C.jsx)(p,{value:J.body,revision:J.revision,onSave:async(e,t)=>{let n=await g.patchDocument(J.id,{body:e},t);_(e=>e.map(e=>e.id===J.id?n.record:e))}},J.id):J.body.trim()?(0,C.jsx)(ye,{source:J.body,headingPrefix:w,onOpen:$}):(0,C.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:J.managed?`This document is empty. Use Edit to write its first version.`:`This file has no body to render.`})}),J.outgoing.length||J.incoming.length||J.scope?.length?(0,C.jsxs)(`div`,{className:`mt-7 flex max-w-[70ch] flex-col gap-4.5`,children:[(0,C.jsx)(D,{label:`links to`,links:J.outgoing,onOpen:$}),(0,C.jsx)(D,{label:(J.incomingTotal??J.incoming.length)>J.incoming.length?`backlinks (${J.incoming.length} of ${J.incomingTotal})`:`backlinks`,links:J.incoming,onOpen:$}),J.scope?.length?(0,C.jsxs)(`section`,{className:`flex flex-col gap-1.5`,children:[(0,C.jsx)(`span`,{className:T,children:`scope`}),J.scope.map(e=>(0,C.jsx)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground [overflow-wrap:anywhere]`,children:e},e))]}):null]}):null]}):(0,C.jsx)(`div`,{className:`flex h-full items-center justify-center text-xs text-muted-foreground`,children:j?`Loading documents…`:`Select a document from the list to read it.`})})}),Q?(0,C.jsx)(Ce,{entries:Z,activeId:Oe,onJump:ke}):null,(0,C.jsx)(de,{open:R!==null,onOpenChange:e=>{!e&&!B&&z(null)},children:(0,C.jsxs)(_e,{"aria-describedby":void 0,children:[(0,C.jsx)(pe,{children:(0,C.jsx)(ve,{children:`Edit metadata${R?` — ${R.id}`:``}`})}),R?(0,C.jsxs)(x,{className:`gap-4`,children:[(0,C.jsxs)(b,{children:[(0,C.jsx)(v,{htmlFor:`docs-meta-title`,children:`title`}),(0,C.jsx)(h,{id:`docs-meta-title`,value:R.title,onChange:e=>z({...R,title:e.target.value})})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,C.jsxs)(b,{className:`[&_[data-slot=native-select-wrapper]]:w-full`,children:[(0,C.jsx)(v,{htmlFor:`docs-meta-kind`,children:`kind`}),(0,C.jsx)(d,{id:`docs-meta-kind`,value:R.kind,onChange:e=>z({...R,kind:e.target.value}),children:Ae.map(e=>(0,C.jsx)(u,{value:e,children:e},e))})]}),(0,C.jsxs)(b,{className:`[&_[data-slot=native-select-wrapper]]:w-full`,children:[(0,C.jsx)(v,{htmlFor:`docs-meta-status`,children:`status`}),(0,C.jsx)(d,{id:`docs-meta-status`,value:R.status,onChange:e=>z({...R,status:e.target.value}),children:je.map(e=>(0,C.jsx)(u,{value:e,children:e},e))})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,C.jsxs)(b,{children:[(0,C.jsx)(v,{htmlFor:`docs-meta-owners`,children:`owners`}),(0,C.jsx)(h,{id:`docs-meta-owners`,value:R.owners,placeholder:`comma-separated`,onChange:e=>z({...R,owners:e.target.value})})]}),(0,C.jsxs)(b,{children:[(0,C.jsx)(v,{htmlFor:`docs-meta-reviewed`,children:`reviewed`}),(0,C.jsx)(h,{id:`docs-meta-reviewed`,type:`date`,value:R.reviewed,onChange:e=>z({...R,reviewed:e.target.value})})]})]}),H?(0,C.jsx)(f,{variant:`destructive`,children:(0,C.jsx)(y,{children:H})}):null]}):null,(0,C.jsxs)(fe,{children:[(0,C.jsx)(l,{type:`button`,variant:`outline`,disabled:B,onClick:()=>z(null),children:`Cancel`}),(0,C.jsx)(l,{type:`button`,disabled:B,onClick:()=>void Ne(),children:B?`Saving…`:`Save`})]})]})})]})}export{k as DocsView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{Ct as r,St as i,b as a,ft as o,vt as s,y as c,z as ee}from"./ui-primitives-wYj92QGw.js";import{f as l,i as te,m as u,o as ne,p as d,r as re,s as f,t as ie}from"./empty-BHqXimMR.js";import{n as p,t as m}from"./native-select-NN1SzVJL.js";import{B as ae,D as oe,L as se,R as ce,V as le,a as h,i as ue,o as g,s as de,z as fe}from"./index-CSPF1W21.js";import{t as _}from"./progress-CKc41PRw.js";var v=e(t(),1),y=n();function b({className:e,...t}){return(0,y.jsx)(c,{"data-slot":`checkbox`,className:u(`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)(a,{"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:u(`w-full caption-bottom text-sm`,e),...t})})}function me({className:e,...t}){return(0,y.jsx)(`thead`,{"data-slot":`table-header`,className:u(`[&_tr]:border-b`,e),...t})}function he({className:e,...t}){return(0,y.jsx)(`tbody`,{"data-slot":`table-body`,className:u(`[&_tr:last-child]:border-0`,e),...t})}function x({className:e,...t}){return(0,y.jsx)(`tr`,{"data-slot":`table-row`,className:u(`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:u(`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:u(`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(h.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:u(`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:u(`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:u(`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)(m,{"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)(p,{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:u(`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:h,color:f(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:u(`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:a,setFilters:s,epicIds:c,onOpen:u,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)(a),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`?(c.get(e.id)||``).localeCompare(c.get(t.id)||``):String(e[M]||``).localeCompare(String(t[M]||``),void 0,{numeric:!0}),N===`asc`?n:-n}),t},[c,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=[a.search,a.status,a.area,a.type,a.priority,a.milestone,a.showIdeas,a.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),u(e)},[u]),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:a.status,color:l,onSelect:e=>s(t=>({...t,status:e}))}),(0,y.jsx)(k,{title:`priority`,values:h,counts:G.priority,selected:a.priority,color:f,onSelect:e=>s(t=>({...t,priority:e}))}),(0,y.jsx)(k,{title:`area`,values:n,counts:G.area,selected:a.area,onSelect:e=>s(t=>({...t,area:e}))}),(0,y.jsx)(k,{title:`type`,values:de,counts:G.type,selected:a.type,onSelect:e=>s(t=>({...t,type:e}))})]}),$=[a.status,a.priority,a.area,a.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)(se,{children:[(0,y.jsx)(le,{asChild:!0,children:(0,y.jsxs)(d,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 px-2.5 text-xs`,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)(fe,{className:`pb-2`,children:(0,y.jsx)(ae,{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)(m,{"aria-label":`Set status`,value:F,onChange:e=>I(e.target.value),className:`h-7 px-2 py-0 pr-8 text-xs`,children:[(0,y.jsx)(p,{value:``,children:`status…`}),g.map(e=>(0,y.jsx)(p,{value:e,children:e},e))]}),(0,y.jsxs)(m,{"aria-label":`Set priority`,value:L,onChange:e=>R(e.target.value),className:`h-7 px-2 py-0 pr-8 text-xs`,children:[(0,y.jsx)(p,{value:``,children:`priority…`}),h.map(e=>(0,y.jsx)(p,{value:e,children:e},e))]}),(0,y.jsxs)(m,{"aria-label":`Set area`,value:z,onChange:e=>B(e.target.value),className:`h-7 px-2 py-0 pr-8 text-xs`,children:[(0,y.jsx)(p,{value:``,children:`area…`}),n.map(e=>(0,y.jsx)(p,{value:e,children:e},e))]}),(0,y.jsxs)(oe,{children:[(0,y.jsx)(d,{size:`sm`,className:`h-7`,disabled:!Z,onClick:()=>void ke(),children:`Apply`}),(0,y.jsx)(d,{size:`sm`,variant:`outline`,className:`h-7`,onClick:()=>j(new Set),children:`Clear`})]})]}),K.length===0?(0,y.jsx)(ie,{children:(0,y.jsxs)(te,{children:[(0,y.jsx)(ne,{children:`No cards match`}),(0,y.jsx)(re,{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)(d,{variant:`ghost`,size:`sm`,onClick:()=>Oe(e),className:`-ml-2 h-7 gap-1 px-2 text-xs text-muted-foreground`,children:[t,M===e?N===`asc`?(0,y.jsx)(i,{className:`size-3`}):(0,y.jsx)(r,{className:`size-3`}):(0,y.jsx)(o,{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:c.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{dt as r}from"./ui-primitives-wYj92QGw.js";import{a as i,f as a,i as o,o as s,p as c,r as l,t as u,u as d}from"./empty-BHqXimMR.js";import{$ as f,A as p,I as m,Q as h,T as g,et as _,j as v,k as y}from"./index-CSPF1W21.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);y(()=>A(e=>e+1)),(0,b.useEffect)(()=>{let e=!0;return m.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)(f,{variant:`destructive`,children:(0,x.jsx)(_,{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)(g,{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)(c,{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)(h,{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:i})=>{let o=t.counts[e],s=e===`error`&&o===0?a(`done`):d(e);return(0,x.jsxs)(v,{className:`relative min-w-[13rem] flex-1 gap-1 py-3 pl-5 pr-3.5`,children:[(0,x.jsx)(p,{edge:`left`,color:s}),(0,x.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,x.jsx)(`span`,{className:`text-[26px] font-semibold tracking-tight`,style:{color:s},children:o}),(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:o===0?i: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)(u,{className:`gap-2 p-10`,children:(0,x.jsxs)(o,{children:[(0,x.jsx)(i,{children:(0,x.jsx)(r,{"aria-hidden":`true`,size:20,style:{color:a(`done`)}})}),(0,x.jsx)(s,{className:`text-sm`,children:`All clear`}),(0,x.jsxs)(l,{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)(v,{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:d(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)(c,{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{K as r,N as i,_t as a,gt as o}from"./ui-primitives-wYj92QGw.js";import{f as s,l as c,m as l,p as u,r as d,t as f,u as p}from"./empty-BHqXimMR.js";import{n as m,t as h}from"./native-select-NN1SzVJL.js";import{$ as g,D as _,E as v,F as ee,G as y,H as b,I as x,K as S,M as C,N as w,O as te,P as ne,Q as T,Z as E,b as D,c as O,d as k,et as A,f as j,j as re,k as ie,l as M,p as N,q as P,u as F,v as I,w as ae,x as oe}from"./index-CSPF1W21.js";import{t as se}from"./layout-QiuZ_k5v.js";var L=e(t(),1),R=n(),z=`text-[10px] font-medium tracking-widest uppercase text-muted-foreground`;function B(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 p(`error`);default:return s(`backlog`)}}function ce(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 V(e){return e instanceof Error?e.message:String(e)}function H({label:e,value:t,options:n,onChange:r}){return(0,R.jsxs)(y,{children:[(0,R.jsx)(E,{asChild:!0,children:(0,R.jsxs)(u,{type:`button`,variant:`outline`,size:`sm`,"aria-label":e,className:l(`h-7 gap-1 px-2 text-xs`,t&&`border-ring bg-accent`),children:[e,(0,R.jsx)(`span`,{className:l(`font-normal`,!t&&`text-muted-foreground`),children:t||`all`}),(0,R.jsx)(a,{"aria-hidden":`true`,className:`size-3 text-muted-foreground`})]})}),(0,R.jsxs)(P,{align:`start`,children:[(0,R.jsx)(S,{checked:!t,onSelect:()=>r(``),children:`all`}),n.map(e=>(0,R.jsx)(S,{checked:t===e,onSelect:()=>r(e),children:e},e))]})]})}function U({record:e,selected:t,onSelect:n}){let r=e.kind===`release`?`release`:e.type,i=e.kind===`release`?`var(--primary)`:B(e.type),a=e.kind===`release`?`${e.fragments.length} fragment${e.fragments.length===1?``:`s`} · ${e.date}`:e.area;return(0,R.jsx)(v,{asChild:!0,variant:`outline`,size:`sm`,children:(0,R.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,className:l(`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,R.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,R.jsx)(`span`,{className:`font-mono text-[10px]`,style:{color:i},children:r}),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsx)(`span`,{className:`max-w-[170px] truncate font-mono text-[10px] text-muted-foreground/70`,children:a})]}),(0,R.jsx)(`span`,{className:`text-sm leading-snug font-normal`,children:e.title})]})})}function W({label:e,records:t,selectedId:n,onSelect:r}){return t.length?(0,R.jsxs)(`div`,{role:`group`,"aria-label":e,className:`flex flex-col gap-1.5 pt-4`,children:[(0,R.jsxs)(`span`,{className:z,children:[e,` · `,t.length]}),t.map(e=>(0,R.jsx)(U,{record:e,selected:e.id===n,onSelect:()=>r(e.id)},e.id))]}):null}function G({id:e,title:t,relation:n,disabled:r,onOpen:i}){return(0,R.jsx)(v,{asChild:!0,variant:`outline`,size:`sm`,children:(0,R.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,R.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-muted-foreground`,children:e}),(0,R.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[12.5px]`,children:t}),n?(0,R.jsx)(T,{variant:`outline`,className:`shrink-0 font-mono text-[10px] font-normal text-muted-foreground`,children:n}):null]})})}function K({label:e,links:t,onOpen:n}){return t.length?(0,R.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,R.jsx)(`span`,{className:z,children:e}),t.map(t=>(0,R.jsx)(G,{id:t.id,title:t.title,relation:t.relation,disabled:t.disabled,onOpen:()=>n(t.id)},`${e}-${t.id}`))]}):null}function le(e){return e.map(e=>({id:e.id,title:e.title||`Missing record`,relation:e.relation,disabled:!e.exists&&!e.title}))}function ue({schema:e,areas:t,onClose:n,onCreated:r}){let[i,a]=(0,L.useState)({title:``,type:e.defaults.type,area:t[0]||`general`,visibility:e.defaults.visibility,body:``}),[o,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(``),d=(e,t)=>a(n=>({...n,[e]:t})),f=async()=>{s(!0);try{r((await x.createChange(i)).record)}catch(e){l(V(e))}finally{s(!1)}};return(0,R.jsx)(O,{open:!0,onOpenChange:e=>{e||n()},children:(0,R.jsxs)(M,{onOpenAutoFocus:e=>e.preventDefault(),children:[(0,R.jsxs)(j,{children:[(0,R.jsx)(N,{children:`New change fragment`}),(0,R.jsx)(F,{children:`Record one user- or operator-meaningful change.`})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(D,{htmlFor:`new-fragment-title`,children:`Title`}),(0,R.jsx)(b,{id:`new-fragment-title`,autoFocus:!0,required:!0,maxLength:120,value:i.title,onChange:e=>d(`title`,e.target.value)})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-3 gap-2.5`,children:[(0,R.jsxs)(I,{children:[(0,R.jsx)(D,{htmlFor:`new-fragment-type`,children:`Type`}),(0,R.jsx)(h,{id:`new-fragment-type`,value:i.type,onChange:e=>d(`type`,e.target.value),children:e.types.map(e=>(0,R.jsx)(m,{value:e,children:e},e))})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(D,{htmlFor:`new-fragment-area`,children:`Area`}),(0,R.jsx)(h,{id:`new-fragment-area`,value:i.area,onChange:e=>d(`area`,e.target.value),children:t.map(e=>(0,R.jsx)(m,{value:e,children:e},e))})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(D,{htmlFor:`new-fragment-visibility`,children:`Visibility`}),(0,R.jsx)(h,{id:`new-fragment-visibility`,value:i.visibility,onChange:e=>d(`visibility`,e.target.value),children:e.visibilities.map(e=>(0,R.jsx)(m,{value:e,children:e},e))})]})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(D,{htmlFor:`new-fragment-details`,children:`Details`}),(0,R.jsx)(ae,{id:`new-fragment-details`,rows:5,value:i.body,onChange:e=>d(`body`,e.target.value)})]}),c?(0,R.jsx)(g,{variant:`destructive`,"aria-live":`polite`,children:(0,R.jsx)(A,{children:c})}):null,(0,R.jsxs)(k,{children:[(0,R.jsx)(u,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,R.jsx)(u,{type:`button`,disabled:o||!i.title.trim(),onClick:()=>void f(),children:o?`Saving…`:`Create fragment`})]})]})})}function de({preview:e,suggestedVersion:t,onClose:n,onReleased:r}){let[i,a]=(0,L.useState)(t),[o,s]=(0,L.useState)(``),[c,l]=(0,L.useState)(!1),[d,f]=(0,L.useState)(``),p=async()=>{l(!0);try{await x.createRelease({version:i,title:o||void 0,fragmentIds:e.fragments.map(e=>e.id)}),r()}catch(e){f(V(e))}finally{l(!1)}};return(0,R.jsx)(O,{open:!0,onOpenChange:e=>{e||n()},children:(0,R.jsxs)(M,{className:`flex max-h-[85vh] flex-col sm:max-w-[640px]`,children:[(0,R.jsxs)(j,{children:[(0,R.jsx)(N,{children:`Release preparation`}),(0,R.jsxs)(F,{children:[e.fragments.length,` unreleased fragment`,e.fragments.length===1?``:`s`,` selected.`]})]}),(0,R.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto`,children:[(0,R.jsxs)(`div`,{className:`grid grid-cols-[150px_1fr] gap-2.5`,children:[(0,R.jsxs)(I,{children:[(0,R.jsx)(D,{htmlFor:`release-version`,children:`Version`}),(0,R.jsx)(b,{id:`release-version`,className:`font-mono`,placeholder:`2.4.0`,value:i,onChange:e=>a(e.target.value)})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(D,{htmlFor:`release-title`,children:`Release title`}),(0,R.jsx)(b,{id:`release-title`,placeholder:`Optional curated title`,value:o,onChange:e=>s(e.target.value)})]})]}),e.groups.map(e=>(0,R.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,R.jsxs)(`span`,{className:z,style:{color:B(e.type)},children:[e.type,` · `,e.fragments.length]}),e.fragments.map(e=>(0,R.jsxs)(`span`,{className:`flex items-baseline gap-2 text-[12.5px]`,children:[(0,R.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,R.jsx)(`span`,{className:`min-w-0 truncate`,children:e.title}),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground/70`,children:e.area})]},e.id))]},e.type)),(0,R.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,R.jsx)(`span`,{className:z,children:`release notes preview`}),(0,R.jsx)(`div`,{className:`max-h-[220px] overflow-y-auto rounded-md border bg-background px-3 py-1`,children:(0,R.jsx)(oe,{source:e.markdown||`No release notes to render.`})})]}),d?(0,R.jsx)(g,{variant:`destructive`,"aria-live":`polite`,children:(0,R.jsx)(A,{children:d})}):null]}),(0,R.jsxs)(k,{children:[(0,R.jsx)(u,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,R.jsx)(u,{type:`button`,disabled:c||!i.trim()||!e.fragments.length,onClick:()=>void p(),children:c?`Releasing…`:`Create release`})]})]})})}function fe({record:e,schema:t,areas:n,onSaved:r}){let[i,a]=(0,L.useState)({title:e.title,type:e.type,area:e.area,visibility:e.visibility}),[o,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(``),d=(e,t)=>a(n=>({...n,[e]:t})),f={};for(let t of[`title`,`type`,`area`,`visibility`])i[t]!==e[t]&&(f[t]=i[t]);let g=Object.keys(f).length>0,_=n.includes(e.area)?n:[e.area,...n],v=async()=>{s(!0);try{let t=await x.patchChange(e.id,f,e.revision);l(``),r(t.record)}catch(e){l(V(e))}finally{s(!1)}};return(0,R.jsxs)(re,{className:`gap-2.5 rounded-lg py-3 shadow-xs`,children:[(0,R.jsx)(ne,{className:`px-3`,children:(0,R.jsx)(ee,{className:z,children:`edit fragment`})}),(0,R.jsxs)(C,{className:`flex flex-col gap-2.5 px-3`,children:[(0,R.jsxs)(I,{children:[(0,R.jsx)(D,{htmlFor:`edit-fragment-title`,children:`Title`}),(0,R.jsx)(b,{id:`edit-fragment-title`,maxLength:120,value:i.title,onChange:e=>d(`title`,e.target.value)})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-3 gap-2.5`,children:[(0,R.jsxs)(I,{children:[(0,R.jsx)(D,{htmlFor:`edit-fragment-type`,children:`Type`}),(0,R.jsx)(h,{id:`edit-fragment-type`,value:i.type,onChange:e=>d(`type`,e.target.value),children:t.types.map(e=>(0,R.jsx)(m,{value:e,children:e},e))})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(D,{htmlFor:`edit-fragment-area`,children:`Area`}),(0,R.jsx)(h,{id:`edit-fragment-area`,value:i.area,onChange:e=>d(`area`,e.target.value),children:_.map(e=>(0,R.jsx)(m,{value:e,children:e},e))})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(D,{htmlFor:`edit-fragment-visibility`,children:`Visibility`}),(0,R.jsx)(h,{id:`edit-fragment-visibility`,value:i.visibility,onChange:e=>d(`visibility`,e.target.value),children:t.visibilities.map(e=>(0,R.jsx)(m,{value:e,children:e},e))})]})]})]}),(0,R.jsxs)(w,{className:`gap-2.5 px-3`,children:[c?(0,R.jsx)(`span`,{className:`flex-1 text-xs`,style:{color:p(`error`)},"aria-live":`polite`,children:c}):(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsx)(u,{type:`button`,variant:`outline`,size:`sm`,disabled:o||!g||!i.title.trim(),onClick:()=>void v(),children:o?`Saving…`:`Save changes`})]})]})}function pe({selectedId:e,onSelect:t,onOpenRecord:n,schema:a,areas:s}){let[m,h]=(0,L.useState)([]),[v,ee]=(0,L.useState)(``),[y,S]=(0,L.useState)(``),[C,w]=(0,L.useState)(``),[ne,E]=(0,L.useState)(!0),[D,O]=(0,L.useState)(``),[k,j]=(0,L.useState)(``),[M,N]=(0,L.useState)(!1),[P,F]=(0,L.useState)(null),[I,ae]=(0,L.useState)(`public`),[z,U]=(0,L.useState)({content:``,error:``,loading:!0}),[G,pe]=(0,L.useState)(0),me=()=>pe(e=>e+1);ie(e=>{te(e,`/changelog/`)&&me()}),(0,L.useEffect)(()=>{let e=!1,t=async()=>{E(!0);try{let t=await x.changelog(v.trim(),{state:y||void 0,visibility:C||void 0});if(e)return;h(t.records),O(``)}catch(t){e||O(V(t))}finally{e||E(!1)}},n=window.setTimeout(()=>void t(),v?180:0);return()=>{e=!0,window.clearTimeout(n)}},[v,y,C,G]),(0,L.useEffect)(()=>{let e=!1;return U(e=>({...e,loading:!0})),x.renderedChangelog(I).then(t=>{e||U({content:t.content,error:``,loading:!1})}).catch(t=>{e||U({content:``,error:V(t),loading:!1})}),()=>{e=!0}},[I,G]);let q=(0,L.useMemo)(()=>[...m].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||``))}),[m]),J=(0,L.useMemo)(()=>new Map(m.map(e=>[e.id,e])),[m]),Y=(0,L.useMemo)(()=>q.filter(e=>e.kind===`change`&&!e.released),[q]),he=(0,L.useMemo)(()=>q.filter(e=>e.kind===`change`&&e.released),[q]),X=(0,L.useMemo)(()=>q.filter(e=>e.kind===`release`),[q]),Z=(0,L.useMemo)(()=>ce(X,Y),[X,Y]),Q=e?J.get(e):void 0,$=e=>{if(J.has(e)){t(e);return}if(/^(CHG|REL)-/.test(e)){S(``),w(``),t(e);return}n(e)},ge=()=>{j(``),x.releasePreview().then(F).catch(e=>j(V(e)))},_e=Q?.issues.some(e=>e.severity===`error`)?`destructive`:`default`,ve=(0,R.jsxs)(u,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>N(!0),children:[(0,R.jsx)(r,{"aria-hidden":`true`}),`New fragment`]});return(0,R.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:l(`w-full shrink-0 flex-col border-r lg:flex lg:w-[400px]`,Q?`hidden`:`flex`),children:[(0,R.jsxs)(`div`,{className:`flex flex-col gap-2.5 p-3.5 pb-0`,children:[(0,R.jsxs)(re,{className:`flex-row items-center gap-2.5 border-primary bg-primary/10 p-3`,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,R.jsxs)(`span`,{className:`text-[13px] font-semibold`,children:[Y.length,` unpublished fragment`,Y.length===1?``:`s`]}),(0,R.jsxs)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground`,children:[`next: `,Z,` ·`,` `,a.releaseStrategy]})]}),(0,R.jsx)(u,{type:`button`,size:`sm`,className:`whitespace-nowrap`,onClick:ge,children:`Prepare release`})]}),k?(0,R.jsx)(g,{variant:`destructive`,"aria-live":`polite`,children:(0,R.jsx)(A,{children:k})}):null,(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(b,{type:`search`,"aria-label":`Search history`,placeholder:`Search fragments and releases…`,value:v,onChange:e=>ee(e.target.value),className:`h-7 flex-1 px-2.5 text-xs md:text-xs`}),(0,R.jsx)(H,{label:`state`,value:y,options:[`unreleased`,`released`],onChange:S}),(0,R.jsx)(H,{label:`visibility`,value:C,options:a.visibilities,onChange:w})]})]}),(0,R.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:ne?(0,R.jsx)(`div`,{"aria-busy":`true`,className:`flex flex-col gap-2 pt-4`,children:Array.from({length:6},(e,t)=>(0,R.jsx)(`div`,{className:`h-[52px] animate-pulse rounded-md bg-muted`},t))}):D?(0,R.jsx)(g,{variant:`destructive`,className:`mt-4`,"aria-live":`polite`,children:(0,R.jsx)(A,{children:D})}):q.length?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(W,{label:`unpublished`,records:Y,selectedId:e,onSelect:t}),(0,R.jsx)(W,{label:`releases`,records:X,selectedId:e,onSelect:t}),(0,R.jsx)(W,{label:`published fragments`,records:he,selectedId:e,onSelect:t})]}):(0,R.jsx)(f,{className:`mt-4 gap-1 p-4 md:p-4`,children:(0,R.jsx)(d,{className:`text-xs`,children:`No history records match the filters.`})})})]}),(0,R.jsx)(`div`,{className:l(`min-w-0 flex-1 overflow-y-auto px-6 py-5 sm:px-8.5`,Q?`block`:`hidden lg:block`),children:(0,R.jsx)(`div`,{className:se,children:Q?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(u,{type:`button`,variant:`ghost`,size:`sm`,className:`-ml-2 mb-2 lg:hidden`,onClick:()=>t(``),children:[(0,R.jsx)(o,{"aria-hidden":`true`}),`All history`]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 font-mono text-[11px]`,children:[(0,R.jsx)(`span`,{className:`whitespace-nowrap text-primary`,children:Q.id}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{className:`text-muted-foreground/70`,children:Q.kind}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),Q.kind===`change`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{style:{color:B(Q.type)},children:Q.type}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:Q.area}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:Q.visibility}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{style:{color:c(Q.released?`released`:`unreleased`)},children:Q.released?`released`:`unreleased`}),Q.updated?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{className:`text-muted-foreground/70`,children:Q.updated})]}):null]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-primary`,children:Q.version}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:Q.date}),Q.commit?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{className:`text-muted-foreground/70`,children:Q.commit})]}):null,(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[Q.fragments.length,` fragment`,Q.fragments.length===1?``:`s`]})]}),(0,R.jsxs)(`span`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[ve,(0,R.jsx)(u,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Close record`,title:`Back to the derived changelog`,onClick:()=>t(``),children:(0,R.jsx)(i,{"aria-hidden":`true`})})]})]}),(0,R.jsx)(`h2`,{className:`mt-2.5 mb-1 text-[26px] leading-tight font-semibold tracking-tight [text-wrap:pretty]`,children:Q.title}),(0,R.jsx)(`div`,{className:`font-mono text-[10.5px] break-all text-muted-foreground/70`,children:Q.path}),Q.issues.length>0?(0,R.jsx)(g,{variant:_e,className:`mt-3.5`,children:(0,R.jsx)(A,{className:`w-full gap-1`,children:Q.issues.map(e=>(0,R.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`shrink-0 font-mono text-[10.5px]`,style:{color:p(e.severity)},children:e.severity}),(0,R.jsx)(`span`,{children:e.message})]},`${e.code}-${e.message}`))})}):null,(0,R.jsx)(`div`,{className:`mt-4.5`,children:(0,R.jsx)(oe,{source:Q.body||`No additional notes.`,onOpen:$})}),(0,R.jsxs)(`div`,{className:`mt-5.5 flex flex-col gap-3.5`,children:[Q.kind===`change`?(0,R.jsx)(K,{label:`shipped in`,links:(Q.releaseIds||[]).map(e=>({id:e,title:J.get(e)?.title||`Open release`,relation:`release`})),onOpen:$}):(0,R.jsx)(K,{label:`fragments · ${Q.fragments.length}`,links:Q.fragments.map(e=>{let t=J.get(e);return{id:e,title:t?.title||`Open fragment`,relation:t?.kind===`change`?t.type:void 0}}),onOpen:$}),(0,R.jsx)(K,{label:`links to`,links:le(Q.outgoing),onOpen:$}),(0,R.jsx)(K,{label:`backlinks`,links:le(Q.incoming),onOpen:$})]}),Q.kind===`change`?(0,R.jsx)(`div`,{className:`mt-5.5`,children:(0,R.jsx)(fe,{record:Q,schema:a,areas:s,onSaved:e=>h(t=>t.map(t=>t.id===e.id?e:t))},`${Q.id}:${Q.revision}`)}):null]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-2 border-b pb-3`,children:[(0,R.jsx)(`span`,{className:`text-[13px] font-semibold`,children:`Derived changelog`}),(0,R.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:[`visibility `,I,` · CHANGELOG.md`]}),(0,R.jsxs)(`span`,{className:`ml-auto flex flex-wrap items-center gap-2.5`,children:[(0,R.jsx)(_,{children:a.visibilities.map(e=>(0,R.jsx)(u,{type:`button`,size:`sm`,variant:I===e?`default`:`outline`,"aria-pressed":I===e,className:`h-7 px-2.5 text-xs`,onClick:()=>ae(e),children:e},e))}),(0,R.jsx)(T,{variant:`outline`,className:`rounded-md font-mono text-[10.5px] font-normal whitespace-nowrap text-muted-foreground`,children:`render --write`}),ve]})]}),z.error?(0,R.jsx)(g,{variant:`destructive`,className:`mt-4`,"aria-live":`polite`,children:(0,R.jsx)(A,{children:z.error})}):(0,R.jsx)(`pre`,{className:`mt-4 font-mono text-xs leading-[1.75] whitespace-pre-wrap text-muted-foreground`,"aria-busy":z.loading||void 0,children:z.loading&&!z.content?`Rendering…`:z.content||`Nothing to render yet — create the first change fragment.`})]})})}),M?(0,R.jsx)(ue,{schema:a,areas:s,onClose:()=>N(!1),onCreated:e=>{N(!1),h(t=>[e,...t]),t(e.id)}}):null,P?(0,R.jsx)(de,{preview:P,suggestedVersion:Z,onClose:()=>F(null),onReleased:()=>{F(null),me()}}):null]})}export{pe as HistoryView};

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

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{G as r,K as i,V as a,_t as o,it as s,q as c,vt as l}from"./ui-primitives-wYj92QGw.js";import{l as u,m as d,p as f,r as p,t as m,u as h}from"./empty-BHqXimMR.js";import{n as g,t as _}from"./native-select-NN1SzVJL.js";import{$ as v,E as y,G as b,H as x,I as S,J as C,M as ee,O as te,P as ne,Q as w,T,Z as E,_ as re,b as D,c as O,d as k,et as A,f as j,g as M,h as N,j as P,k as F,l as I,m as ie,p as L,q as R,v as z,w as B,x as V}from"./index-CSPF1W21.js";var H=e(t(),1),U=n(),W=[`low`,`medium`,`high`],G=[`critical`,`high`,`medium`,`low`],ae=`[mask-image:linear-gradient(to_bottom,black_calc(100%_-_24px),transparent)]`;function oe(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 se(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 J({label:e,value:t,options:n,allLabel:r=`all`,onChange:i}){return(0,U.jsxs)(b,{children:[(0,U.jsx)(E,{asChild:!0,children:(0,U.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,"aria-label":e,className:d(`h-7 gap-1 rounded-full px-2.5 text-xs`,t&&`border-ring bg-accent`),children:[e,(0,U.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:t||r}),(0,U.jsx)(o,{"aria-hidden":`true`,className:`size-3 text-muted-foreground`})]})}),(0,U.jsxs)(R,{align:`start`,sideOffset:4,children:[(0,U.jsxs)(C,{onSelect:()=>i(``),children:[r,t?null:(0,U.jsx)(l,{"aria-hidden":`true`,className:`ml-auto`})]}),n.map(e=>(0,U.jsxs)(C,{onSelect:()=>i(e.value),children:[e.color?(0,U.jsx)(`span`,{className:`size-2 shrink-0 rounded-full`,style:{backgroundColor:e.color},"aria-hidden":`true`}):null,e.label??e.value,t===e.value?(0,U.jsx)(l,{"aria-hidden":`true`,className:`ml-auto`}):null]},e.value))]})]})}function Y({id:e,label:t,children:n}){return(0,U.jsxs)(z,{className:`gap-1.5 [&_[data-slot=native-select-wrapper]]:w-full`,children:[(0,U.jsx)(D,{htmlFor:e,children:t}),n]})}function ce({record:e,selected:t,onSelect:n}){let r=se(e),i=e.lifecycleIssues?.length||0;return(0,U.jsx)(y,{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,U.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,children:[(0,U.jsxs)(`span`,{className:`flex items-center justify-between gap-2`,children:[(0,U.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,U.jsxs)(w,{variant:`outline`,className:`h-[18px] gap-1 rounded-md px-1.5 font-mono text-[10px] font-medium`,children:[(0,U.jsx)(`span`,{className:`size-[5px] shrink-0 rounded-full`,style:{backgroundColor:u(e.status)},"aria-hidden":`true`}),e.status]})]}),(0,U.jsx)(`span`,{className:`text-[13px] font-medium leading-snug`,children:e.title}),r||i?(0,U.jsxs)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground`,children:[r,r&&i?` · `:null,i?(0,U.jsx)(`span`,{style:{color:h(`warning`)},children:K(i,`lifecycle warning`)}):null]}):null]})})}function X({issues:e,kind:t}){return e.length?(0,U.jsx)(U.Fragment,{children:e.map(e=>(0,U.jsx)(v,{variant:e.severity===`error`?`destructive`:`default`,className:`px-3 py-2`,children:(0,U.jsxs)(A,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-0.5`,children:[(0,U.jsx)(`span`,{className:`font-mono text-[10.5px]`,style:{color:h(e.severity)},children:t===`lifecycle`?`lifecycle`:e.severity}),(0,U.jsx)(`span`,{children:e.message})]})},`${t}-${e.code}-${e.message}`))}):null}function Z({label:e,links:t,onOpen:n}){return t.length?(0,U.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,U.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,U.jsx)(y,{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,U.jsxs)(`button`,{type:`button`,disabled:r,onClick:()=>n(t.id),children:[(0,U.jsx)(`span`,{className:`w-[78px] shrink-0 truncate font-mono text-[11px] font-medium`,children:t.id}),(0,U.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-muted-foreground`,children:t.title||`Missing record`}),t.relation||t.kind?(0,U.jsx)(w,{variant:`secondary`,className:`h-[18px] rounded-md px-1.5 font-mono text-[10px] font-medium`,children:t.relation||t.kind}):null]})},`${e}-${t.id}`)})]}):null}function Q({message:e}){return e?(0,U.jsx)(v,{variant:`destructive`,className:`px-3 py-2`,children:(0,U.jsx)(A,{children:e})}):null}function le({schema:e,initialCollection:t,onClose:n,onCreated:r}){let i=e.collections.find(e=>e.id===t)||e.collections[0],[a,o]=(0,H.useState)({collection:i?.id||`learnings`,status:i?.statuses[0]||`active`,title:``,category:``,confidence:``,severity:``,expires:``,body:``}),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(``),d=e.collections.find(e=>e.id===a.collection),p=q(a.collection),m=(e,t)=>o(n=>({...n,[e]:t})),h=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 S.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){u(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,U.jsx)(O,{open:!0,onOpenChange:e=>{e||n()},children:(0,U.jsxs)(I,{className:`sm:max-w-[520px]`,"aria-describedby":void 0,children:[(0,U.jsx)(j,{children:(0,U.jsxs)(L,{children:[`New `,d?.singular||`record`]})}),(0,U.jsxs)(`div`,{className:`-m-1 flex max-h-[65vh] flex-col gap-3 overflow-y-auto p-1`,children:[(0,U.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,U.jsx)(Y,{id:`memory-create-collection`,label:`Collection`,children:(0,U.jsx)(_,{id:`memory-create-collection`,value:a.collection,onChange:e=>h(e.target.value),children:e.collections.map(e=>(0,U.jsx)(g,{value:e.id,children:e.id},e.id))})}),(0,U.jsx)(Y,{id:`memory-create-status`,label:`Status`,children:(0,U.jsx)(_,{id:`memory-create-status`,value:a.status,onChange:e=>m(`status`,e.target.value),children:(d?.statuses||[]).map(e=>(0,U.jsx)(g,{value:e,children:e},e))})})]}),(0,U.jsx)(Y,{id:`memory-create-title`,label:`Title`,children:(0,U.jsx)(x,{id:`memory-create-title`,autoFocus:!0,required:!0,maxLength:120,value:a.title,onChange:e=>m(`title`,e.target.value)})}),p.category||p.confidence||p.severity||p.expires?(0,U.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[p.category?(0,U.jsx)(Y,{id:`memory-create-category`,label:`Category`,children:(0,U.jsx)(x,{id:`memory-create-category`,value:a.category,onChange:e=>m(`category`,e.target.value)})}):null,p.confidence?(0,U.jsx)(Y,{id:`memory-create-confidence`,label:`Confidence`,children:(0,U.jsxs)(_,{id:`memory-create-confidence`,value:a.confidence,onChange:e=>m(`confidence`,e.target.value),children:[(0,U.jsx)(g,{value:``,children:`not set`}),W.map(e=>(0,U.jsx)(g,{value:e,children:e},e))]})}):null,p.severity?(0,U.jsx)(Y,{id:`memory-create-severity`,label:`Severity`,children:(0,U.jsxs)(_,{id:`memory-create-severity`,value:a.severity,onChange:e=>m(`severity`,e.target.value),children:[(0,U.jsx)(g,{value:``,children:`not set`}),G.map(e=>(0,U.jsx)(g,{value:e,children:e},e))]})}):null,p.expires?(0,U.jsx)(Y,{id:`memory-create-expires`,label:`Expires`,children:(0,U.jsx)(x,{id:`memory-create-expires`,type:`date`,value:a.expires,onChange:e=>m(`expires`,e.target.value)})}):null]}):null,(0,U.jsx)(Y,{id:`memory-create-body`,label:`Details`,children:(0,U.jsx)(B,{id:`memory-create-body`,rows:8,value:a.body,onChange:e=>m(`body`,e.target.value)})}),(0,U.jsx)(Q,{message:l})]}),(0,U.jsxs)(k,{children:[(0,U.jsx)(f,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,U.jsx)(f,{type:`button`,disabled:s||!a.title.trim(),onClick:()=>void v(),children:s?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(T,{"aria-hidden":`true`}),`Saving…`]}):`Create record`})]})]})})}function ue({record:e,statuses:t,onClose:n,onUpdated:r}){let i=q(e.collection),[a,o]=(0,H.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,H.useState)(!1),[l,u]=(0,H.useState)(``),d=(e,t)=>o(n=>({...n,[e]:t})),p=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 S.patchMemory(e.id,t,e.revision)).record),n()}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,U.jsx)(O,{open:!0,onOpenChange:e=>{e||n()},children:(0,U.jsxs)(I,{className:`sm:max-w-[520px]`,"aria-describedby":void 0,children:[(0,U.jsx)(j,{children:(0,U.jsxs)(L,{children:[`Edit `,e.id]})}),(0,U.jsxs)(`div`,{className:`-m-1 flex max-h-[65vh] flex-col gap-3 overflow-y-auto p-1`,children:[(0,U.jsx)(Y,{id:`memory-edit-title`,label:`Title`,children:(0,U.jsx)(x,{id:`memory-edit-title`,autoFocus:!0,required:!0,maxLength:120,value:a.title,onChange:e=>d(`title`,e.target.value)})}),(0,U.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,U.jsx)(Y,{id:`memory-edit-status`,label:`Status`,children:(0,U.jsx)(_,{id:`memory-edit-status`,value:a.status,onChange:e=>d(`status`,e.target.value),children:(t.includes(a.status)?t:[a.status,...t]).map(e=>(0,U.jsx)(g,{value:e,children:e},e))})}),i.category?(0,U.jsx)(Y,{id:`memory-edit-category`,label:`Category`,children:(0,U.jsx)(x,{id:`memory-edit-category`,value:a.category,onChange:e=>d(`category`,e.target.value)})}):null,i.confidence?(0,U.jsx)(Y,{id:`memory-edit-confidence`,label:`Confidence`,children:(0,U.jsxs)(_,{id:`memory-edit-confidence`,value:a.confidence,onChange:e=>d(`confidence`,e.target.value),children:[(0,U.jsx)(g,{value:``,children:`not set`}),W.map(e=>(0,U.jsx)(g,{value:e,children:e},e))]})}):null,i.severity?(0,U.jsx)(Y,{id:`memory-edit-severity`,label:`Severity`,children:(0,U.jsxs)(_,{id:`memory-edit-severity`,value:a.severity,onChange:e=>d(`severity`,e.target.value),children:[(0,U.jsx)(g,{value:``,children:`not set`}),G.map(e=>(0,U.jsx)(g,{value:e,children:e},e))]})}):null,i.expires?(0,U.jsx)(Y,{id:`memory-edit-expires`,label:`Expires`,children:(0,U.jsx)(x,{id:`memory-edit-expires`,type:`date`,value:a.expires,onChange:e=>d(`expires`,e.target.value)})}):null,i.review_after?(0,U.jsx)(Y,{id:`memory-edit-review-after`,label:`Review after`,children:(0,U.jsx)(x,{id:`memory-edit-review-after`,type:`date`,value:a.review_after,onChange:e=>d(`review_after`,e.target.value)})}):null]}),(0,U.jsx)(Y,{id:`memory-edit-body`,label:`Details`,children:(0,U.jsx)(B,{id:`memory-edit-body`,rows:10,value:a.body,onChange:e=>d(`body`,e.target.value)})}),(0,U.jsx)(Q,{message:l})]}),(0,U.jsxs)(k,{children:[(0,U.jsx)(f,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,U.jsx)(f,{type:`button`,disabled:s||!a.title.trim(),onClick:()=>void p(),children:s?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(T,{"aria-hidden":`true`}),`Saving…`]}):`Save changes`})]})]})})}function de({record:e,mode:t,onClose:n,onUpdated:r}){let[i,a]=(0,H.useState)(``),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(``),u=async()=>{s(!0);try{r((t===`graduate`?await S.graduateMemory(e.id,i.split(`,`).map(e=>e.trim()).filter(Boolean),e.revision):await S.supersedeMemory(e.id,i.trim(),e.revision)).record),n()}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}};return(0,U.jsx)(O,{open:!0,onOpenChange:e=>{e||n()},children:(0,U.jsxs)(I,{className:`sm:max-w-[420px]`,"aria-describedby":void 0,children:[(0,U.jsx)(j,{children:(0,U.jsxs)(L,{children:[t===`graduate`?`Graduate`:`Supersede`,` `,e.id]})}),(0,U.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,U.jsx)(Y,{id:`memory-lifecycle-target`,label:t===`graduate`?`Target IDs`:`Replacement ID`,children:(0,U.jsx)(x,{id:`memory-lifecycle-target`,autoFocus:!0,placeholder:t===`graduate`?`CONV-0001, DOC-0004`:`ADR-0009`,value:i,onChange:e=>a(e.target.value)})}),(0,U.jsx)(Q,{message:c})]}),(0,U.jsxs)(k,{children:[(0,U.jsx)(f,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,U.jsx)(f,{type:`button`,disabled:o||!i.trim(),onClick:()=>void u(),children:o?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(T,{"aria-hidden":`true`}),`Saving…`]}):`Apply`})]})]})})}function fe({record:e,statuses:t,onOpenRelation:n,onOpenRecord:i,onUpdated:a,onDialogOpenChange:o}){let[l,d]=(0,H.useState)(!1),[p,m]=(0,H.useState)(``),g=l||!!p;(0,H.useEffect)(()=>{o?.(g)},[g,o]);let _=e.collection===`learnings`&&e.status!==`graduated`,v=[`learnings`,`decisions`,`conventions`].includes(e.collection),y=[[`status`,e.status,u(e.status)]];return e.category&&y.push([`category`,e.category]),e.confidence&&y.push([`confidence`,e.confidence]),e.severity&&y.push([`severity`,e.severity,h(e.severity)]),e.occurrences!=null&&y.push([`occurrences`,String(e.occurrences)]),e.expires&&y.push([`expires`,e.expires]),e.review_after&&y.push([`review after`,e.review_after]),e.started_at&&y.push([`started`,e.started_at]),e.resolved_at&&y.push([`resolved`,e.resolved_at]),e.graduated_to?.length&&y.push([`graduated to`,e.graduated_to.join(`, `)]),e.superseded_by?.length&&y.push([`superseded by`,e.superseded_by.join(`, `)]),e.owners?.length&&y.push([`owners`,e.owners.join(`, `)]),y.push([`updated`,e.updated||`—`]),(0,U.jsxs)(`aside`,{"aria-label":`Memory record`,className:`flex min-h-0 flex-col overflow-hidden border-l bg-background`,children:[(0,U.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center gap-2 border-b px-3.5`,children:[(0,U.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,U.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground/60`,children:`·`}),(0,U.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.collection}),(0,U.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground/60`,children:`·`}),(0,U.jsx)(`span`,{className:`font-mono text-[11px]`,style:{color:u(e.status)},children:e.status})]}),(0,U.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto p-4`,children:[(0,U.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,U.jsx)(`h2`,{className:`m-0 text-[17px] font-semibold leading-[1.3] tracking-[-0.01em] [text-wrap:pretty]`,children:e.title}),e.path?(0,U.jsx)(`span`,{className:`break-all font-mono text-[10.5px] text-muted-foreground`,children:e.path}):null]}),(0,U.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-2`,children:y.map(([e,t,n])=>(0,U.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,U.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:e}),(0,U.jsx)(`span`,{className:`text-sm`,style:n?{color:n}:void 0,children:t})]},e))}),(0,U.jsx)(X,{issues:e.issues,kind:`validation`}),(0,U.jsx)(X,{issues:e.lifecycleIssues||[],kind:`lifecycle`}),(0,U.jsx)(V,{className:`[--typeset-size:0.875rem]`,source:e.body||`No details recorded.`,onOpen:i}),(0,U.jsx)(Z,{label:`Links to`,links:e.outgoing,onOpen:n}),(0,U.jsx)(Z,{label:`Backlinks`,links:e.incoming,onOpen:n}),(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,U.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>d(!0),children:[(0,U.jsx)(c,{"aria-hidden":`true`}),`Edit`]}),_?(0,U.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>m(`graduate`),children:[(0,U.jsx)(s,{"aria-hidden":`true`}),`Graduate`]}):null,v?(0,U.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>m(`supersede`),children:[(0,U.jsx)(r,{"aria-hidden":`true`}),`Supersede`]}):null]})]}),l?(0,U.jsx)(ue,{record:e,statuses:t,onClose:()=>d(!1),onUpdated:a}):null,p?(0,U.jsx)(de,{record:e,mode:p,onClose:()=>m(``),onUpdated:a}):null]})}function $(e,t){return e.find(e=>e.id===t)?.statuses||[]}function pe({selectedId:e,onSelect:t,onOpenRecord:n,schema:r}){let[o,s]=(0,H.useState)([]),[c,l]=(0,H.useState)(``),[h,g]=(0,H.useState)(``),[_,y]=(0,H.useState)(``),[b,x]=(0,H.useState)(!0),[C,E]=(0,H.useState)(``),[D,O]=(0,H.useState)(null),[k,j]=(0,H.useState)(()=>localStorage.getItem(`workfile-memory-drawer`)===`expanded`);(0,H.useEffect)(()=>{localStorage.setItem(`workfile-memory-drawer`,k?`expanded`:`normal`)},[k]);let I=(0,H.useRef)(!1),L=(0,H.useRef)(0),R=(0,H.useCallback)(e=>{L.current=performance.now(),t(e)},[t]),[z,B]=(0,H.useState)(0);F(e=>{te(e,`/memory/`)&&B(e=>e+1)}),(0,H.useEffect)(()=>{let e=async()=>{x(!0);try{let e=await S.memory(c.trim(),{collection:h||void 0,status:_||void 0});s(e.records),E(``)}catch(e){E(e instanceof Error?e.message:String(e))}finally{x(!1)}},t=window.setTimeout(()=>void e(),c?180:0);return()=>window.clearTimeout(t)},[c,h,_,z]);let V=(0,H.useMemo)(()=>[...o].sort((e,t)=>String(t.updated||``).localeCompare(String(e.updated||``))||e.title.localeCompare(t.title)),[o]),W=(0,H.useMemo)(()=>{let e=r.collections.filter(e=>!h||e.id===h).map(e=>({schema:e,records:V.filter(t=>t.collection===e.id)})),t=new Set(r.collections.map(e=>e.id)),n=V.filter(e=>!t.has(e.collection));return n.length&&e.push({schema:{id:`other`,singular:`record`,idPrefix:`?`,statuses:[]},records:n}),e},[r.collections,V,h]),G=V.find(t=>t.id===e),q=h?$(r.collections,h):[...new Set(r.collections.flatMap(e=>e.statuses))];return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-3.5 pt-3.5`,children:[(0,U.jsxs)(N,{className:`w-full min-w-[180px] sm:w-[260px]`,children:[(0,U.jsx)(M,{children:(0,U.jsx)(a,{"aria-hidden":`true`})}),(0,U.jsx)(re,{type:`search`,"aria-label":`Search workfile memory`,placeholder:`Search decisions, incidents, learnings…`,value:c,onChange:e=>l(e.target.value)})]}),(0,U.jsx)(J,{label:`collection`,value:h,options:r.collections.map(e=>({value:e.id})),onChange:e=>{g(e),y(``)}}),(0,U.jsx)(J,{label:`status`,value:_,options:q.map(e=>({value:e,color:u(e)})),onChange:y}),(0,U.jsx)(`span`,{className:`ml-auto flex shrink-0 items-center gap-1.5 whitespace-nowrap font-mono text-[11px] text-muted-foreground`,children:b?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(T,{"aria-hidden":`true`,className:`size-3`}),`loading…`]}):K(o.length,`record`)})]}),C?(0,U.jsx)(v,{variant:`destructive`,className:`mx-3.5 mt-3 w-auto px-3 py-2`,children:(0,U.jsxs)(A,{children:[`Memory could not be loaded: `,C]})}):null,(0,U.jsx)(`div`,{className:`flex min-h-0 flex-1 gap-3 overflow-hidden p-3.5`,children:(0,U.jsx)(`div`,{className:`flex min-h-0 flex-1 gap-3 overflow-x-auto`,children:W.map(t=>(0,U.jsxs)(P,{className:`w-[272px] flex-none gap-0 overflow-hidden rounded-xl py-0 [--card-spacing:--spacing(2)]`,children:[(0,U.jsxs)(ne,{className:`flex flex-row items-center gap-2 border-b px-3 py-2`,children:[(0,U.jsx)(`span`,{className:`font-mono text-[11px] font-medium text-primary`,children:t.schema.idPrefix}),(0,U.jsx)(`span`,{className:`flex-1 text-[12.5px] font-semibold`,children:oe(t.schema.singular)}),(0,U.jsx)(w,{variant:`secondary`,className:`h-5 px-1.5 font-mono text-[11px] font-normal`,children:t.records.length}),t.schema.id===`other`?null:(0,U.jsx)(f,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`New ${t.schema.singular}`,onClick:()=>O(t.schema.id),children:(0,U.jsx)(i,{"aria-hidden":`true`})})]}),(0,U.jsxs)(ee,{className:d(`flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto p-2.5`,ae),children:[t.records.map(t=>(0,U.jsx)(ce,{record:t,selected:t.id===e,onSelect:()=>R(t.id)},t.id)),!t.records.length&&!b?(0,U.jsx)(m,{className:`gap-1 border border-dashed p-4 md:p-6`,children:(0,U.jsx)(p,{className:`font-mono text-xs`,children:`no records`})}):null]})]},t.schema.id))})}),(0,U.jsx)(ie,{open:!!G,expanded:k,label:`record`,description:`Details and lifecycle for the selected memory record.`,onOpenChange:e=>{e||t(``)},onExpandedChange:j,holdOpen:()=>I.current||performance.now()-L.current<200,children:G?(0,U.jsx)(fe,{record:G,statuses:$(r.collections,G.collection),onOpenRelation:e=>{o.some(t=>t.id===e)?R(e):n(e)},onOpenRecord:n,onUpdated:e=>s(t=>t.map(t=>t.id===e.id?e:t)),onDialogOpenChange:e=>{I.current=e}},G.id):null}),D===null?null:(0,U.jsx)(le,{schema:r,initialCollection:D,onClose:()=>O(null),onCreated:e=>{O(null),s(t=>[e,...t]),t(e.id)}})]})}export{pe as MemoryView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{W as r,Y as i,yt as a}from"./ui-primitives-wYj92QGw.js";import{a as o,f as s,i as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h}from"./empty-BHqXimMR.js";import{W as g,a as _,x as v}from"./index-CSPF1W21.js";import{t as y}from"./layout-QiuZ_k5v.js";import{t as b}from"./progress-CKc41PRw.js";var x=e(t(),1),S=n(),C=[{key:`N`,label:`Move to next`,status:`next`},{key:`D`,label:`Defer`,status:`deferred`},{key:`X`,label:`Discard`,status:`discarded`}];function w({tasks:e,repoRoot:t,repoUrl:n,onPatch:w,onOpen:T}){let[E,D]=(0,x.useState)(()=>new Set),[O,k]=(0,x.useState)(0),A=(0,x.useMemo)(()=>e.filter(e=>!E.has(e.id)),[E,e]),j=A[O]||A[0],M=e.length;(0,x.useEffect)(()=>{O>=A.length&&k(Math.max(0,A.length-1))},[O,A.length]);let N=(0,x.useCallback)(async(e,t=!0)=>{if(j){try{await w(j.id,e)}catch{return}t&&(D(e=>new Set(e).add(j.id)),k(e=>Math.min(e,Math.max(0,A.length-2))))}},[w,A.length,j]);(0,x.useEffect)(()=>{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(),k(e=>Math.min(A.length-1,e+1));else if(n===`K`||e.key===`ArrowUp`)e.preventDefault(),k(e=>Math.max(0,e-1));else if(/^[1-4]$/.test(n))e.preventDefault(),N({priority:_[Number(n)-1]},!1);else{let t=C.find(e=>e.key===n);t&&(e.preventDefault(),N({status:t.status}))}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[N,A.length]);let P=e=>n?`${n.replace(/\/+$/,``)}/blob/main/${e}`:`vscode://file${t}/${e}`;return j?(0,S.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2.5 border-b bg-card px-3.5 py-2.5`,children:[(0,S.jsx)(b,{value:M?E.size/M*100:0,className:`max-w-[340px] flex-1`}),(0,S.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:[E.size,` of `,M,` processed`]}),(0,S.jsx)(`span`,{className:`flex-1`}),(0,S.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,disabled:O===0,onClick:()=>k(e=>Math.max(0,e-1)),children:[(0,S.jsx)(g,{children:`K`}),`Previous`]}),(0,S.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground tabular-nums`,children:[O+1,` / `,A.length]}),(0,S.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,disabled:O>=A.length-1,onClick:()=>k(e=>Math.min(A.length-1,e+1)),children:[(0,S.jsx)(g,{children:`J`}),`Next`]}),(0,S.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>T(j.id),children:[(0,S.jsx)(i,{"aria-hidden":`true`}),`Open full card`]})]}),(0,S.jsxs)(`div`,{className:l(y,`px-6 py-7 sm:px-8`),children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 font-mono text-[11px] text-muted-foreground`,children:[(0,S.jsx)(`span`,{children:j.id}),(0,S.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,S.jsx)(`span`,{style:{color:s(j.status)},children:j.status}),(0,S.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,S.jsx)(`span`,{children:j.area}),(0,S.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,S.jsx)(`span`,{children:j.type})]}),(0,S.jsx)(`h2`,{className:`mt-3 mb-1 text-[26px] leading-[1.2] font-semibold tracking-tight [text-wrap:pretty]`,children:j.title}),j.file?(0,S.jsx)(`a`,{className:`font-mono text-[11px] text-muted-foreground/70 underline underline-offset-[3px]`,href:P(j.file),target:n?`_blank`:void 0,rel:n?`noreferrer`:void 0,children:j.file}):null,j.source?(0,S.jsxs)(`span`,{className:`mt-[3px] block font-mono text-[11px] text-muted-foreground/70`,children:[`source`,` `,(0,S.jsx)(`a`,{className:`font-mono underline underline-offset-[3px]`,href:P(j.source),target:n?`_blank`:void 0,rel:n?`noreferrer`:void 0,children:j.source})]}):null,(0,S.jsx)(`div`,{className:`mt-[22px]`,children:(0,S.jsx)(v,{source:j.body,onOpen:T})}),(0,S.jsxs)(`div`,{className:`mt-[30px] flex flex-wrap gap-2 border-t pt-[18px]`,children:[_.map((e,t)=>(0,S.jsxs)(f,{type:`button`,variant:`outline`,"aria-pressed":j.priority===e,style:j.priority===e?{borderColor:m(e)}:void 0,onClick:()=>void N({priority:e},!1),children:[(0,S.jsx)(g,{children:t+1}),(0,S.jsx)(`span`,{style:{color:m(e)},children:e})]},e)),C.map(e=>(0,S.jsxs)(f,{type:`button`,variant:`outline`,onClick:()=>void N({status:e.status}),children:[(0,S.jsx)(g,{children:e.key}),(0,S.jsx)(`span`,{style:{color:s(e.status)},children:e.label})]},e.key))]}),(0,S.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,S.jsxs)(h,{className:`gap-3 p-10`,children:[(0,S.jsxs)(c,{children:[(0,S.jsx)(o,{children:(0,S.jsx)(a,{"aria-hidden":`true`,size:20,style:{color:s(`done`)}})}),(0,S.jsx)(d,{className:`text-sm`,children:`Queue clear`}),(0,S.jsxs)(p,{className:`text-[12.5px]`,children:[`You processed `,E.size.toLocaleString(),` cards.`]})]}),(0,S.jsx)(u,{children:(0,S.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{D(new Set),k(0)},children:[(0,S.jsx)(r,{"aria-hidden":`true`}),`Start again`]})})]})}export{w as TriageView};
+49
-1

@@ -1,2 +0,50 @@

export declare function writeFileAtomic(path: any, content: any): Promise<void>;
/**
* Whether a rename was refused for a reason that can pass on its own.
*
* POSIX renames straight over an open file and never notices. Windows refuses
* while *anything* holds the destination, and measured on the runners, one
* `fs.open(path, "r")` from this very process is enough: every share mode
* refuses, including `ReadWrite, Delete`. So this is not about how the reader
* asked for the file. It is about the destination being open at all — by the
* index builder, the watcher, the HTTP server, the UI, an editor or a virus
* scanner, any of which reads the records the CLI writes.
*/
export declare function isRenameRefusal(error: any): boolean;
/**
* Writes a file in one step, or not at all.
*
* The rename is retried because on Windows it is refused while a reader holds
* the destination, and a reader that is reading holds it for as long as the
* read takes — milliseconds. Measured on the runners: every refusal cleared
* within 100ms of the holder letting go. The window here is an order of
* magnitude above that, and it is a window rather than a promise: a
* destination somebody keeps open forever still fails, with its own errno
* rather than with an invented one, because that is the truth about it.
*/
export declare function writeFileAtomic(path: any, content: any, { attempts, retryMs, rename: renameFile }?: any): Promise<void>;
export declare function createFileExclusive(path: any, content: any): Promise<void>;
/**
* Whether an exclusive create was refused because somebody else got there
* first, rather than because the path is unwritable.
*
* POSIX has one answer for this and it is `EEXIST`. Windows has more than one.
* A file whose last handle is still closing sits in delete-pending state: the
* directory entry is there, so the create is refused, but it is refused with
* `EPERM` — and with `EBUSY` when the refusal comes from a sharing violation
* instead. Both mean precisely what `EEXIST` means: wait, then try again.
*
* Every caller of this predicate was written against the POSIX code alone, so
* the Windows codes fell through to a rethrow and reached users as
* `INTERNAL_ERROR: EPERM: operation not permitted` — a card creation failing
* outright where it should have queued.
*
* `EACCES` is deliberately Windows-only. There it is one more way of saying
* delete-pending; on POSIX it is the ordinary "this directory is not yours to
* write in", and retrying that until a timeout would bury the real cause under
* a report about contention.
*
* The codes are a property of the filesystem, not of the kernel: a repository
* on an SMB share hits the same refusals from Linux, which is why none of this
* is gated on `process.platform` beyond the one code that genuinely differs.
*/
export declare function isCreateContention(error: any): boolean;

@@ -1,5 +0,57 @@

import { mkdir, open, rename, rm, writeFile } from "node:fs/promises";
import { constants } from "node:fs";
import { access, mkdir, open, rename, rm, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { randomUUID } from "node:crypto";
export async function writeFileAtomic(path, content) {
const RENAME_REFUSALS = new Set(["EPERM", "EACCES", "EBUSY"]);
/**
* Whether a rename was refused for a reason that can pass on its own.
*
* POSIX renames straight over an open file and never notices. Windows refuses
* while *anything* holds the destination, and measured on the runners, one
* `fs.open(path, "r")` from this very process is enough: every share mode
* refuses, including `ReadWrite, Delete`. So this is not about how the reader
* asked for the file. It is about the destination being open at all — by the
* index builder, the watcher, the HTTP server, the UI, an editor or a virus
* scanner, any of which reads the records the CLI writes.
*/
export function isRenameRefusal(error) {
return Boolean(error?.code && RENAME_REFUSALS.has(error.code));
}
/**
* Whether the refusal is one that waiting cannot fix.
*
* A read-only destination is refused with `EPERM` too — the same code, from
* the same call, for a reason that will still be true in a second. The code
* cannot tell them apart, so ask the destination instead: if it cannot be
* written to, the rename is not queued behind anybody and there is nothing to
* wait for. A destination that does not exist yet is not the reason either.
*/
async function destinationIsUnwritable(path) {
try {
await access(path, constants.W_OK);
return false;
}
catch (error) {
return error?.code !== "ENOENT";
}
}
function sleep(milliseconds) {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
}
/**
* Writes a file in one step, or not at all.
*
* The rename is retried because on Windows it is refused while a reader holds
* the destination, and a reader that is reading holds it for as long as the
* read takes — milliseconds. Measured on the runners: every refusal cleared
* within 100ms of the holder letting go. The window here is an order of
* magnitude above that, and it is a window rather than a promise: a
* destination somebody keeps open forever still fails, with its own errno
* rather than with an invented one, because that is the truth about it.
*/
export async function writeFileAtomic(path, content, { attempts = 20, retryMs = 25,
// The rename, overridable only so a refusal can be driven on a machine
// that does not produce one. See `isRenameRefusal` for why POSIX never
// will.
rename: renameFile = rename } = {}) {
await mkdir(dirname(path), { recursive: true });

@@ -9,3 +61,15 @@ const temporary = join(dirname(path), `.${randomUUID()}.tmp`);

await writeFile(temporary, content, { encoding: "utf8", flag: "wx" });
await rename(temporary, path);
for (let attempt = 1;; attempt += 1) {
try {
await renameFile(temporary, path);
return;
}
catch (error) {
if (attempt >= attempts || !isRenameRefusal(error))
throw error;
if (await destinationIsUnwritable(path))
throw error;
await sleep(retryMs);
}
}
}

@@ -26,1 +90,34 @@ finally {

}
const CONTENTION_ERRORS = new Set(["EEXIST", "EPERM", "EBUSY"]);
/**
* Whether an exclusive create was refused because somebody else got there
* first, rather than because the path is unwritable.
*
* POSIX has one answer for this and it is `EEXIST`. Windows has more than one.
* A file whose last handle is still closing sits in delete-pending state: the
* directory entry is there, so the create is refused, but it is refused with
* `EPERM` — and with `EBUSY` when the refusal comes from a sharing violation
* instead. Both mean precisely what `EEXIST` means: wait, then try again.
*
* Every caller of this predicate was written against the POSIX code alone, so
* the Windows codes fell through to a rethrow and reached users as
* `INTERNAL_ERROR: EPERM: operation not permitted` — a card creation failing
* outright where it should have queued.
*
* `EACCES` is deliberately Windows-only. There it is one more way of saying
* delete-pending; on POSIX it is the ordinary "this directory is not yours to
* write in", and retrying that until a timeout would bury the real cause under
* a report about contention.
*
* The codes are a property of the filesystem, not of the kernel: a repository
* on an SMB share hits the same refusals from Linux, which is why none of this
* is gated on `process.platform` beyond the one code that genuinely differs.
*/
export function isCreateContention(error) {
const code = error?.code;
if (!code)
return false;
if (CONTENTION_ERRORS.has(code))
return true;
return code === "EACCES" && process.platform === "win32";
}
+1
-1

@@ -11,3 +11,3 @@ export { ConfigError, ConflictError, ForbiddenError, NotFoundError, ProtocolError, UnsupportedMediaTypeError, ValidationError, normalizeError } from "./errors.js";

export { createWorkspaceWatcher } from "./watcher.js";
export { createFileExclusive, writeFileAtomic } from "./filesystem.js";
export { createFileExclusive, isCreateContention, isRenameRefusal, writeFileAtomic } from "./filesystem.js";
export { discoverFiles, globToRegExp, matchesAnyGlob, normalizeRepoPath } from "./glob.js";

@@ -14,0 +14,0 @@ export { containedPath, readMarkdownTree } from "./paths.js";

@@ -9,3 +9,3 @@ export { ConfigError, ConflictError, ForbiddenError, NotFoundError, ProtocolError, UnsupportedMediaTypeError, ValidationError, normalizeError } from "./errors.js";

export { createWorkspaceWatcher } from "./watcher.js";
export { createFileExclusive, writeFileAtomic } from "./filesystem.js";
export { createFileExclusive, isCreateContention, isRenameRefusal, writeFileAtomic } from "./filesystem.js";
export { discoverFiles, globToRegExp, matchesAnyGlob, normalizeRepoPath } from "./glob.js";

@@ -12,0 +12,0 @@ export { containedPath, readMarkdownTree } from "./paths.js";

@@ -34,2 +34,2 @@ /**

}>;
export declare function withFileLock(path: any, operation: any, { timeoutMs, retryMs, metadata, staleAfterMs, onBrokenLock }?: any): Promise<any>;
export declare function withFileLock(path: any, operation: any, { timeoutMs, retryMs, metadata, staleAfterMs, onBrokenLock, open: openLock }?: any): Promise<any>;
import { mkdir, open, readFile, rm } from "node:fs/promises";
import { dirname } from "node:path";
import { ConflictError } from "./errors.js";
import { isCreateContention } from "./filesystem.js";
function sleep(milliseconds) {

@@ -69,3 +70,7 @@ return new Promise((resolve) => setTimeout(resolve, milliseconds));

}
export async function withFileLock(path, operation, { timeoutMs = 5000, retryMs = 25, metadata = {}, staleAfterMs = 0, onBrokenLock } = {}) {
export async function withFileLock(path, operation, { timeoutMs = 5000, retryMs = 25, metadata = {}, staleAfterMs = 0, onBrokenLock,
// The opener, overridable only so a refusal can be driven on demand.
// The Windows codes below cannot be produced by racing on POSIX, and a
// runner losing the race again is not a test.
open: openLock = open } = {}) {
await mkdir(dirname(path), { recursive: true });

@@ -75,10 +80,18 @@ const deadline = Date.now() + timeoutMs;

let handle = null;
let refusal = null;
while (!handle) {
try {
handle = await open(path, "wx");
await handle.writeFile(`${JSON.stringify({ pid: process.pid, createdAt: new Date().toISOString(), ...metadata })}\n`, "utf8");
// Named, because the injected opener is untyped and assigning it
// straight into `handle` would widen the binding back to nullable.
const opened = await openLock(path, "wx");
handle = opened;
await opened.writeFile(`${JSON.stringify({ pid: process.pid, createdAt: new Date().toISOString(), ...metadata })}\n`, "utf8");
}
catch (error) {
if (error?.code !== "EEXIST")
// `EEXIST` is only how POSIX says "somebody holds it"; see
// `isCreateContention` for the codes Windows uses for the same
// thing. Anything else is a real fault and must not be waited on.
if (!isCreateContention(error))
throw error;
refusal = error;
const verdict = await lockIsStale(path, { staleAfterMs: expiry });

@@ -98,3 +111,7 @@ if (verdict.stale) {

owner: verdict.owner?.metadata ?? null,
heldForMs: verdict.owner?.ageMs ?? null
heldForMs: verdict.owner?.ageMs ?? null,
// Which refusal ran out the clock. A delete-pending
// lock leaves no owner to report, so without this the
// timeout says nothing at all about what happened.
lastError: refusal?.code ?? null
});

@@ -101,0 +118,0 @@ }

@@ -45,2 +45,10 @@ /**

code?: string;
/**
* How a reservation is written. Defaults to `createFileExclusive`, and
* exists as an option only so a refused create can be driven on demand:
* the Windows contention this guards against needed four processes and a
* 500-record corpus to fire once in sixteen rounds, and never fires at all
* on POSIX.
*/
create?: (path: string, content: string) => Promise<void>;
}

@@ -63,3 +71,3 @@ /** A held reservation. The id is unused on disk until `release` is called. */

*/
export declare function acquireRecordId({ directories, prefix, lockDirectory, maxRetries, code }: ReserveRecordIdOptions): Promise<RecordIdReservation>;
export declare function acquireRecordId({ directories, prefix, lockDirectory, maxRetries, code, create }: ReserveRecordIdOptions): Promise<RecordIdReservation>;
/**

@@ -71,3 +79,7 @@ * Runs `write` with an id nothing else can be holding.

* path collision — same id, same title — is absorbed rather than surfaced.
* Windows refuses that same write with `EPERM` while the colliding file is
* still closing, so the absorption has to recognize both; see
* `isCreateContention`. Nothing has been written when either arrives, because
* the exclusive create is the first thing every `write` does.
*/
export declare function reserveRecordId<T>(options: ReserveRecordIdOptions, write: (id: string) => Promise<T>): Promise<T>;
import { rm } from "node:fs/promises";
import { basename, join } from "node:path";
import { ConflictError } from "./errors.js";
import { createFileExclusive } from "./filesystem.js";
import { createFileExclusive, isCreateContention } from "./filesystem.js";
import { readMarkdownTree } from "./paths.js";

@@ -15,3 +15,3 @@ /**

*/
export async function acquireRecordId({ directories, prefix, lockDirectory, maxRetries = 64, code = "RECORD_ID_ALLOCATION_FAILED" }) {
export async function acquireRecordId({ directories, prefix, lockDirectory, maxRetries = 64, code = "RECORD_ID_ALLOCATION_FAILED", create = createFileExclusive }) {
const escaped = prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");

@@ -39,2 +39,3 @@ const pattern = new RegExp(`^${escaped}-(\\d+)`);

let sequence = scan.highest + 1;
let refusal = null;
for (let attempt = 0; attempt < maxRetries; attempt += 1) {

@@ -44,7 +45,12 @@ const id = `${prefix}-${String(sequence).padStart(4, "0")}`;

try {
await createFileExclusive(reservation, `${JSON.stringify({ id, pid: process.pid, createdAt: new Date().toISOString() })}\n`);
await create(reservation, `${JSON.stringify({ id, pid: process.pid, createdAt: new Date().toISOString() })}\n`);
}
catch (error) {
if (error?.code !== "EEXIST")
// `EEXIST` is the POSIX way of saying this; Windows refuses a
// delete-pending lockfile with `EPERM` instead, and that code used
// to escape here and surface as `INTERNAL_ERROR` — the create
// failing outright rather than stepping aside.
if (!isCreateContention(error))
throw error;
refusal = error;
// Somebody else is mid-flight on this id.

@@ -69,3 +75,7 @@ sequence += 1;

}
throw new ConflictError(code, `Unable to allocate an ID with prefix ${prefix} after ${maxRetries} retries.`);
throw new ConflictError(code, `Unable to allocate an ID with prefix ${prefix} after ${maxRetries} retries.`,
// Which refusal used up the attempts. Contention that never clears and
// a cache directory nobody can write to produce the same exhaustion
// here, and only the code tells them apart.
{ contention: refusal?.code ?? null });
}

@@ -78,2 +88,6 @@ /**

* path collision — same id, same title — is absorbed rather than surfaced.
* Windows refuses that same write with `EPERM` while the colliding file is
* still closing, so the absorption has to recognize both; see
* `isCreateContention`. Nothing has been written when either arrives, because
* the exclusive create is the first thing every `write` does.
*/

@@ -88,3 +102,3 @@ export async function reserveRecordId(options, write) {

catch (error) {
if (error?.code !== "EEXIST")
if (!isCreateContention(error))
throw error;

@@ -91,0 +105,0 @@ }

@@ -6,3 +6,3 @@ export type { AgentTarget, BaseProjectRecord, CardEffort, CardChanges, CardMutationOptions, CardPriority, CardRecord, CardStatus, CardType, ChangeRecord, ChangeVisibility, CiTarget, CreateCardInput, CreateChangeInput, CreateDocumentInput, CreateMemoryInput, CreateReleaseInput, DeepPartial, DocumentLayout, DoctorReport, DocumentRecord, EffectiveProjectSchema, HybridSearchOptions, MemoryCollection, MemoryRecord, ProjectAgentsConfig, ProjectCardsConfig, ProjectChangelogConfig, ProjectCiConfig, ProjectConfig, ProjectConfigInput, ProjectDiagnostic, ProjectDocsConfig, ProjectIntegration, ProjectIndex, ProjectMcpConfig, ProjectMemoryConfig, ProjectRecord, ProjectRecordLink, ProjectSearchConfig, ProjectSearchOptions, ProjectSearchResult, ProjectStorageConfig, ProjectUiConfig, ProjectWorkspace, ProjectWorkspacePaths, RecordMutationResult, ReleaseRecord, ReleaseStrategy, RevisionOptions, SemanticSearchMatch, SemanticSearchProvider, SemanticSearchRecord, WorkspaceVersion } from "./types.js";

export { DEFAULT_LIST_KEYS, parseFrontmatter, parseValue, patchFrontmatter, requireFrontmatter, serializeValue } from "./core/frontmatter.js";
export { createFileExclusive, writeFileAtomic } from "./core/filesystem.js";
export { createFileExclusive, isCreateContention, isRenameRefusal, writeFileAtomic } from "./core/filesystem.js";
export { discoverFiles, globToRegExp, matchesAnyGlob, normalizeRepoPath } from "./core/glob.js";

@@ -9,0 +9,0 @@ export { containedPath, readMarkdownTree } from "./core/paths.js";

@@ -5,3 +5,3 @@ export { defineProject } from "./config/define-project.js";

export { DEFAULT_LIST_KEYS, parseFrontmatter, parseValue, patchFrontmatter, requireFrontmatter, serializeValue } from "./core/frontmatter.js";
export { createFileExclusive, writeFileAtomic } from "./core/filesystem.js";
export { createFileExclusive, isCreateContention, isRenameRefusal, writeFileAtomic } from "./core/filesystem.js";
export { discoverFiles, globToRegExp, matchesAnyGlob, normalizeRepoPath } from "./core/glob.js";

@@ -8,0 +8,0 @@ export { containedPath, readMarkdownTree } from "./core/paths.js";

import { readFile, rm } from "node:fs/promises";
import { basename, join } from "node:path";
import { createFileExclusive, writeFileAtomic } from "../../core/filesystem.js";
import { createFileExclusive, isCreateContention, writeFileAtomic } from "../../core/filesystem.js";
import { ConflictError, NotFoundError, ValidationError } from "../../core/errors.js";

@@ -103,5 +103,14 @@ import { parseFrontmatter, patchFrontmatter } from "../../core/frontmatter.js";

const reservation = join(workspace.paths.cache, "locks", "ids", `${newId}.lock`);
await createFileExclusive(reservation, `${JSON.stringify({ id: newId, pid: process.pid, createdAt: stamp })}\n`);
// Both creates below can lose to a concurrent allocation, and neither
// failure is a fault: the ID check above ran against an index read before
// any of this. Reported as the conflict it is, rather than as the raw
// errno, which on Windows is not even `EEXIST` — see `isCreateContention`.
const contended = (error) => {
if (!isCreateContention(error))
throw error;
throw new ConflictError("CARD_ID_TAKEN", `${newId} was allocated by another process while renumbering.`, { contention: error.code });
};
await createFileExclusive(reservation, `${JSON.stringify({ id: newId, pid: process.pid, createdAt: stamp })}\n`).catch(contended);
try {
await createFileExclusive(newPath, next);
await createFileExclusive(newPath, next).catch(contended);
await rm(oldPath, { force: true });

@@ -232,3 +241,16 @@ }

: content;
await createFileExclusive(join(directory, target), trailed);
try {
await createFileExclusive(join(directory, target), trailed);
}
catch (error) {
// `taken` was read before the loop started, so the name can be
// claimed underneath us — by another process, or by an earlier
// move in this very pass. The contract above is to skip a
// collision, and it applies whichever way the collision is
// reported: this used to escape as an internal error instead.
if (!isCreateContention(error))
throw error;
skipped.push({ id: card.id, file: card.file, reason: "name-taken" });
continue;
}
await rm(join(directory, card.file), { force: true });

@@ -235,0 +257,0 @@ taken.delete(card.file);

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

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

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

<link rel="modulepreload" crossorigin href="/static/native-select-NN1SzVJL.js">
<link rel="stylesheet" crossorigin href="/static/index-BcUMy2xt.css">
<link rel="stylesheet" crossorigin href="/static/index-H5jAYVUH.css">
</head>

@@ -23,0 +23,0 @@ <body>

{
"name": "@illodev/workfile",
"version": "0.5.0",
"version": "0.5.1",
"type": "module",

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

import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{_t as r,mt as i,pt as a,rt as o}from"./ui-primitives-wYj92QGw.js";import{a as s,f as c,i as l,m as u,o as d,p as f,r as p,s as m,t as h,u as g}from"./empty-BHqXimMR.js";import{A as _,J as v,K as y,W as b,X as x,Y as S,Z as C,j as w,n as T,r as E,t as D}from"./index-hHNShan0.js";var O=e(t(),1),k=n(),A=[];function j(e,t){let[n,r]=(0,O.useState)(t);(0,O.useEffect)(()=>{r(t)},[e.length,t]);let i=(0,O.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 M({onVisible:e,remaining:t}){let n=(0,O.useRef)(null);return(0,O.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,k.jsxs)(`span`,{ref:n,className:`px-0.5 py-1 font-mono text-[11px] text-muted-foreground`,children:[`+`,t,` more`]})}function N({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,s=Number.isNaN(o)?null:Math.max(0,Math.floor((Date.now()-o)/864e5)),l=[t&&t!==e.id?`epic ${t}`:``,e.effort?`effort ${e.effort}`:``,e.claimed_by?`claimed by ${e.claimed_by}${s==null?``:` · ${s}d`}`:``].filter(Boolean);return(0,k.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:l.length?l.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,k.jsxs)(`span`,{className:`flex items-center`,children:[(0,k.jsx)(`span`,{className:`font-mono text-[11px] text-foreground/70`,children:e.id}),(0,k.jsx)(`span`,{className:`flex-1`}),(0,k.jsx)(`span`,{className:`font-mono text-[10px] font-medium`,style:{color:m(e.priority)},children:e.priority})]}),(0,k.jsx)(`span`,{className:`text-[12.5px] leading-snug font-medium`,role:`heading`,"aria-level":3,children:e.title}),(0,k.jsxs)(`span`,{className:`flex items-center gap-1.5 font-mono text-[10px] text-muted-foreground`,children:[(0,k.jsx)(`span`,{children:e.area}),(0,k.jsx)(`span`,{children:`·`}),(0,k.jsx)(`span`,{children:e.type}),e.claimed_by?(0,k.jsxs)(`span`,{className:`ml-auto inline-flex min-w-0 items-center gap-[5px]`,style:{color:c(`doing`)},children:[(0,k.jsx)(`span`,{className:`size-[5px] flex-none rounded-full bg-current`,"aria-hidden":`true`}),(0,k.jsx)(`span`,{className:`max-w-[90px] truncate`,children:e.claimed_by})]}):null]}),Array.isArray(e.scope)&&e.scope.length?(0,k.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 P({status:e,cards:t,epicIds:n,collapsed:r,onToggleCollapsed:m,onOpen:g,onMove:v,onCarry:y,carryingId:b,isDropTarget:x,onDragEnterColumn:S,onDragLeaveColumn:T}){let[E,D,O]=j(t,25),A=c(e),P={onDragOver:t=>{t.preventDefault(),t.dataTransfer.dropEffect=`move`,S?.(e)},onDragLeave:t=>{t.currentTarget.contains(t.relatedTarget)||T?.(e)},onDrop:t=>{t.preventDefault(),T?.(e);let n=t.dataTransfer.getData(`text/plain`);n&&v(n,e).catch(()=>void 0)}};return r?(0,k.jsxs)(w,{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`,x&&`border-primary`),...P,children:[(0,k.jsx)(_,{edge:`top`,color:A}),(0,k.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`,x&&`bg-accent/50`),onClick:m,children:[(0,k.jsx)(i,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-muted-foreground`}),(0,k.jsx)(`span`,{className:`min-h-0 flex-1 truncate font-mono text-[11px] uppercase tracking-[0.06em] [writing-mode:vertical-rl]`,style:{color:A},children:e}),(0,k.jsx)(C,{variant:`secondary`,className:`h-5 shrink-0 rounded-md px-[7px] font-mono text-[11px] font-normal`,children:t.length})]})]}):(0,k.jsxs)(w,{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`,x&&`border-primary`),...P,children:[(0,k.jsx)(_,{edge:`top`,color:A}),(0,k.jsxs)(`header`,{className:`flex flex-none items-center gap-2 px-3 pb-2.5 pt-4`,children:[(0,k.jsx)(`span`,{className:`flex-1 font-mono text-[11px] uppercase tracking-[0.06em]`,style:{color:A},children:e}),(0,k.jsx)(C,{variant:`secondary`,className:`h-5 rounded-md px-[7px] font-mono text-[11px] font-normal`,children:t.length}),m?(0,k.jsx)(f,{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:m,children:(0,k.jsx)(a,{"aria-hidden":`true`})}):null]}),(0,k.jsxs)(`div`,{className:u(`scroll-fade flex flex-1 flex-col gap-2 overflow-y-auto p-2.5`,x&&`bg-accent/50`),children:[t.length===0?(0,k.jsx)(h,{className:`flex-1 gap-2 rounded-lg border border-dashed p-4`,children:(0,k.jsxs)(l,{className:`gap-1`,children:[(0,k.jsx)(s,{variant:`icon`,className:`mb-0 size-8 [&_svg:not([class*='size-'])]:size-4`,children:(0,k.jsx)(o,{"aria-hidden":`true`})}),(0,k.jsx)(d,{className:`text-[12.5px] font-medium`,children:`No cards`}),(0,k.jsx)(p,{className:`text-[11.5px]`,children:`Nothing in this state.`})]})}):E.map(e=>(0,k.jsx)(N,{task:e,epicId:n.get(e.id),onOpen:g,onCarry:y?()=>y(e):void 0,carrying:b===e.id,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,e.id)}},e.id)),D&&(0,k.jsx)(M,{onVisible:O,remaining:t.length-E.length})]})]})}function F({tasks:e,epicIds:t,showClosed:n,onOpen:r,onMove:i}){let[a,o]=(0,O.useState)(null),[s,c]=(0,O.useState)(null),[l,u]=(0,O.useState)(``),[d,f]=(0,O.useState)(()=>{try{let e=localStorage.getItem(`workfile-flow-collapsed`);return new Set(e?JSON.parse(e):[])}catch{return new Set}}),p=(0,O.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,O.useMemo)(()=>[`backlog`,`next`,`doing`,`review`,`blocked`,`deferred`,...n?[`done`,`discarded`]:[]],[n]),h=(0,O.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,k.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,k.jsx)(`p`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:l}),m.map(e=>(0,k.jsx)(P,{status:e,cards:h.get(e)??A,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 I({tasks:e,allTasks:t,epicIds:n,onOpen:r}){let i=(0,O.useMemo)(()=>new Map(t.map(e=>[e.id,e])),[t]),a=(0,O.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,k.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3.5`,children:(0,k.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}],p=(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,k.jsx)(`span`,{className:`font-mono text-[11.5px] text-foreground/70`,children:e===`__none`?`—`:e}),(0,k.jsx)(`span`,{className:`min-w-0 flex-1 text-sm font-semibold tracking-[-0.01em] text-pretty`,children:n?.title||`Without epic`}),n?(0,k.jsx)(`span`,{className:`font-mono text-[11px]`,style:{color:c(n.status)},children:n.status}):null,(0,k.jsxs)(`span`,{className:`font-mono text-[11.5px] text-muted-foreground`,children:[o,`/`,a]})]}),(0,k.jsx)(`span`,{className:`flex h-2 w-full overflow-hidden rounded-full bg-muted`,"aria-hidden":`true`,children:a>0?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`span`,{className:`h-full`,style:{width:d(o),background:c(`done`)}}),(0,k.jsx)(`span`,{className:`h-full`,style:{width:d(s),background:c(`doing`)}})]}):null}),(0,k.jsxs)(`span`,{className:`flex flex-wrap items-center gap-3.5 font-mono text-[10.5px] text-muted-foreground`,children:[f.map(e=>(0,k.jsxs)(`span`,{className:`inline-flex items-center gap-[5px]`,children:[(0,k.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,k.jsx)(`span`,{className:`ml-auto`,children:n?.area??``})]})]});return n?(0,k.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:p},e):(0,k.jsx)(w,{className:`gap-2.5 rounded-xl px-4 py-3.5 shadow-xs`,children:p},e)})})}):(0,k.jsx)(h,{className:`flex-1 p-6`,children:(0,k.jsxs)(l,{children:[(0,k.jsx)(d,{className:`text-sm`,children:`No epics`}),(0,k.jsx)(p,{className:`text-[11.5px]`,children:`No cards match the current filters.`})]})})}var L=300,R=30;function z({task:e,span:t,mode:n,epicId:r,pct:i,onOpen:a}){let o=c(e.status);return(0,k.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),title:`${E(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,k.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 border-r px-3.5`,style:{width:L,flex:`0 0 ${L}px`,height:`var(--row-h)`},children:[(0,k.jsx)(`span`,{className:`flex-none whitespace-nowrap font-mono text-[11px] text-foreground/70`,children:e.id}),(0,k.jsx)(`span`,{className:`min-w-0 truncate text-[12.5px]`,children:e.title})]}),(0,k.jsx)(`span`,{className:`relative block flex-1`,style:{height:`var(--row-h)`},children:t.point?(0,k.jsx)(`span`,{style:{position:`absolute`,top:`50%`,width:9,height:9,transform:`translate(-50%, -50%) rotate(45deg)`,borderRadius:2,background:o,display:`block`,left:`${i(t.from)}%`}}):(0,k.jsx)(`span`,{style:{position:`absolute`,top:`50%`,transform:`translateY(-50%)`,height:12,minWidth:6,borderRadius:3,background:o,display:`block`,left:`${i(t.from)}%`,width:`${Math.max(i(t.to)-i(t.from),.8)}%`}})})]})}function B({tasks:e,epicIds:t,axes:n={},mode:i,counts:a,onModeChange:o,onOpen:s}){let[c,u]=(0,O.useState)(()=>{try{return localStorage.getItem(`workfile-timeline-group`)||`none`}catch{return`none`}}),m=(0,O.useCallback)(e=>{u(e);try{localStorage.setItem(`workfile-timeline-group`,e)}catch{}},[]),_=(0,O.useMemo)(()=>[`none`,`epic`,`area`,...Object.keys(n)],[n]),C=_.includes(c)?c:`none`,w=(0,O.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]),E=(0,O.useMemo)(()=>{let t=new Map;for(let n of e){let e=T(n,i);e&&t.set(n.id,e)}return t},[i,e]),A=(0,O.useMemo)(()=>{let t=(e,t)=>E.get(e.id).from-E.get(t.id).from||e.id.localeCompare(t.id),n=e.filter(e=>E.has(e.id)).sort(t);return C===`none`?n:[...n].sort((e,n)=>{let r=w(e),i=w(n);return!r==!i?r.localeCompare(i)||t(e,n):r?-1:1})},[w,C,E,e]),j=(0,O.useMemo)(()=>{if(C===`none`)return A.map(e=>({task:e,label:null}));let e=[],t=null;for(let n of A){let r=w(n);r!==t&&(t=r,e.push({task:null,label:r||`no ${C}`})),e.push({task:n,label:null})}return e},[w,C,A]),M=(0,O.useMemo)(()=>new Map(j.flatMap((e,t)=>e.task?[[e.task.id,t]]:[])),[j]),N=(0,O.useMemo)(()=>{let e=[];for(let t of A)for(let n of t.depends||[])M.has(n)&&e.push({from:n,to:t.id});return e},[M,A]),P=(0,O.useMemo)(()=>D(A.map(e=>E.get(e.id)),Date.now()),[A,E]),F=a[i===`plan`?`actual`:`plan`];return!A.length||!P?(0,k.jsx)(h,{className:`flex-1 p-6`,children:(0,k.jsxs)(l,{children:[(0,k.jsx)(d,{className:`text-sm`,children:i===`plan`?`Nothing scheduled`:`Nothing recorded`}),(0,k.jsx)(p,{className:`text-[11.5px]`,children:i===`plan`?`Add a start or due date to a card.`:`Cards record a trail as they are claimed and moved.`}),F>0?(0,k.jsx)(p,{className:`text-[11.5px]`,children:(0,k.jsx)(f,{variant:`outline`,size:`sm`,className:`mt-2 text-[12.5px] font-medium`,onClick:()=>o(i===`plan`?`actual`:`plan`),children:i===`plan`?`show what actually happened · ${F} cards`:`show the schedule · ${F} cards`})}):null]})}):(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,k.jsxs)(`div`,{className:`flex flex-none items-center gap-2.5 border-b bg-card px-3.5 py-2`,children:[(0,k.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:[A.length,` `,i===`actual`?`recorded`:`scheduled`,` ·`,` `,N.length,` dependenc`,N.length===1?`y`:`ies`]}),(0,k.jsxs)(b,{children:[(0,k.jsx)(x,{asChild:!0,children:(0,k.jsxs)(f,{variant:`outline`,size:`sm`,"aria-label":`dates`,className:`ml-auto text-[12.5px] font-medium`,children:[`dates`,(0,k.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:i}),(0,k.jsx)(r,{className:`size-[13px] text-muted-foreground`})]})}),(0,k.jsx)(y,{align:`end`,children:(0,k.jsxs)(v,{value:i,onValueChange:e=>o(e),children:[(0,k.jsx)(S,{value:`plan`,children:`plan`}),(0,k.jsx)(S,{value:`actual`,children:`actual`})]})})]}),(0,k.jsxs)(b,{children:[(0,k.jsx)(x,{asChild:!0,children:(0,k.jsxs)(f,{variant:`outline`,size:`sm`,"aria-label":`group`,className:`text-[12.5px] font-medium`,children:[`group`,(0,k.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:C}),(0,k.jsx)(r,{className:`size-[13px] text-muted-foreground`})]})}),(0,k.jsx)(y,{align:`end`,children:(0,k.jsx)(v,{value:C,onValueChange:m,children:_.map(e=>(0,k.jsx)(S,{value:e,children:e},e))})})]})]}),(0,k.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,k.jsxs)(`div`,{className:`relative min-h-full`,children:[(0,k.jsxs)(`div`,{"aria-hidden":`true`,className:`sticky top-0 z-[2] flex items-stretch border-b bg-card`,style:{height:R},children:[(0,k.jsx)(`span`,{className:`flex items-center border-r px-3.5 text-[10px] uppercase tracking-[0.08em] text-muted-foreground`,style:{width:L,flex:`0 0 ${L}px`},children:`card`}),(0,k.jsx)(`span`,{className:`relative flex-1`,children:P.ticks.map((e,t)=>(0,k.jsx)(`span`,{className:`text-[10px] uppercase tracking-[0.08em] text-muted-foreground`,style:{position:`absolute`,top:`50%`,transform:`translateY(-50%)`,left:`${e.left}%`,width:`${(P.ticks[t+1]?.left??100)-e.left}%`,overflow:`hidden`,paddingLeft:8,whiteSpace:`nowrap`},children:e.label},e.key))})]}),(0,k.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute`,style:{top:R,bottom:0,left:L,right:0},children:[P.ticks.map(e=>(0,k.jsx)(`span`,{className:`absolute inset-y-0 w-px bg-border`,style:{left:`${e.left}%`}},e.key)),P.today!=null&&(0,k.jsx)(`span`,{className:`absolute inset-y-0 w-px`,style:{background:g(`error`),opacity:.55,left:`${P.today}%`}})]}),(0,k.jsxs)(`div`,{className:`relative`,children:[N.length>0&&(0,k.jsx)(`svg`,{"aria-hidden":`true`,preserveAspectRatio:`none`,viewBox:`0 0 100 ${j.length}`,className:`pointer-events-none absolute top-0 h-full`,style:{left:L,width:`calc(100% - ${L}px)`},children:N.map(e=>{let t=E.get(e.from),n=E.get(e.to);if(!t||!n)return null;let r=P.pct(t.to),i=P.pct(n.from),a=M.get(e.from)+.5,o=M.get(e.to)+.5;return(0,k.jsx)(`path`,{d:`M ${r} ${a} C ${(r+i)/2} ${a}, ${(r+i)/2} ${o}, ${i} ${o}`,vectorEffect:`non-scaling-stroke`,style:i<r?{fill:`none`,stroke:g(`error`),strokeWidth:1.5,strokeDasharray:`3 2`}:{fill:`none`,stroke:`var(--muted-foreground)`,strokeWidth:1.5,opacity:.4}},`${e.from}-${e.to}`)})}),j.map((e,n)=>e.task?(0,k.jsx)(z,{task:e.task,span:E.get(e.task.id),mode:i,epicId:t.get(e.task.id),pct:P.pct,onOpen:s},e.task.id):(0,k.jsx)(`div`,{className:`border-b bg-muted/40`,children:(0,k.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{I as EpicsView,F as FlowBoard,B as TimelineView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{F as r,V as i,gt as ee,q as te,st as ne,z as re}from"./ui-primitives-wYj92QGw.js";import{i as ie,l as a,m as o,o as ae,p as s,r as oe,t as se}from"./empty-BHqXimMR.js";import{n as c,t as l}from"./native-select-NN1SzVJL.js";import{$ as u,C as ce,E as d,H as f,I as p,O as le,Q as m,S as ue,T as de,Z as h,_ as fe,b as g,c as pe,d as _,f as v,g as y,h as b,k as me,l as he,p as ge,v as x,x as _e,y as ve}from"./index-hHNShan0.js";import{t as ye}from"./layout-QiuZ_k5v.js";var S=e(t(),1),C=n(),w=`doc-h`,be=[`current`,`draft`,`superseded`,`archived`],T=`text-[10px] font-medium tracking-[0.07em] uppercase text-muted-foreground`;function xe({document:e,selected:t,onSelect:n}){return(0,C.jsx)(d,{asChild:!0,size:`sm`,className:o(`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,C.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,children:[(0,C.jsxs)(`span`,{className:`flex w-full items-center gap-1.5`,children:[(0,C.jsx)(`span`,{className:`flex-1 truncate text-xs font-medium`,children:e.title}),(0,C.jsx)(`span`,{className:o(`font-mono text-[10px]`,!e.managed&&`text-muted-foreground`),style:e.managed?{color:a(e.status)}:void 0,children:e.managed?e.status:`indexed`})]}),(0,C.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,C.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,C.jsx)(`span`,{className:o(T,`px-2`),children:`on this page`}),(0,C.jsx)(`nav`,{className:`mt-2 flex flex-col gap-px`,children:e.map(e=>{let i=e.id===t;return(0,C.jsx)(`button`,{type:`button`,"aria-current":i?`true`:void 0,className:o(`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 E({label:e,value:t}){return(0,C.jsxs)(x,{className:`w-auto min-w-[120px] gap-0.5 rounded-lg border bg-card px-3 py-2 shadow-xs`,children:[(0,C.jsx)(`span`,{className:T,children:e}),(0,C.jsx)(`span`,{className:`text-[13px] font-medium`,children:t})]})}function D({label:e,links:t,onOpen:n}){return t.length?(0,C.jsxs)(`section`,{className:`flex flex-col gap-1.5`,children:[(0,C.jsx)(`span`,{className:T,children:e}),t.map((e,t)=>{let r=!e.exists&&!e.title;return(0,C.jsx)(d,{asChild:!0,variant:`outline`,size:`sm`,className:o(`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,C.jsxs)(`button`,{type:`button`,disabled:r,onClick:()=>n(e.id),children:[(0,C.jsx)(`span`,{className:`min-w-[78px] shrink-0 font-mono text-[11px] font-medium`,children:e.id}),(0,C.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.relation?(0,C.jsx)(h,{variant:`secondary`,className:`font-mono text-[10px]`,children:e.relation}):null]})},`${e.id}-${t}`)})]}):null}var O=(0,C.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted-foreground`,children:`·`});function k({selectedId:e,onSelect:t,onOpenCard:n}){let[d,h]=(0,S.useState)([]),[k,A]=(0,S.useState)(``),[j,M]=(0,S.useState)(!0),[N,P]=(0,S.useState)(``),[F,Ce]=(0,S.useState)(!1),[I,we]=(0,S.useState)(!1),[L,R]=(0,S.useState)(null),[z,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)(``),[U,Te]=(0,S.useState)(null),[Ee,W]=(0,S.useState)(0);me(e=>{le(e,`/docs/`,`docs/`)&&W(e=>e+1)}),(0,S.useEffect)(()=>{let e=!1;M(!0);let t=window.setTimeout(()=>{p.docs(k.trim()).then(t=>{e||(h(t.records),P(``))}).catch(t=>{e||P(t instanceof Error?t.message:String(t))}).finally(()=>{e||M(!1)})},k?180:0);return()=>{e=!0,window.clearTimeout(t)}},[k,Ee]),(0,S.useEffect)(()=>{if(!L||U)return;let e=!1;return p.tasks().then(t=>{e||Te(t.schema.docs)}).catch(()=>{}),()=>{e=!0}},[L,U]);let G=(0,S.useMemo)(()=>F?d.filter(e=>e.managed):d,[d,F]),K=(0,S.useMemo)(()=>{let e=G.filter(e=>e.managed),t=G.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)},[G]),q=G.find(t=>t.id===e)||G[0],J=(0,S.useRef)(null),[Y,X]=(0,S.useState)(``),Z=(0,S.useMemo)(()=>q&&!I?ue(q.body,w):[],[q,I]),Q=Z.length>1;(0,S.useEffect)(()=>{X(``);let e=J.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 De=e=>{document.getElementById(e)?.scrollIntoView({block:`start`,behavior:`smooth`}),X(e)},$=e=>{let r=d.find(t=>t.id===e);r?t(r.id):n(e)},Oe=(0,S.useMemo)(()=>{let e=new Set(U?.kinds??[]);for(let t of d)t.managed&&e.add(t.documentKind);return L&&e.add(L.kind),[...e].sort()},[U,d,L]),ke=(0,S.useMemo)(()=>{let e=new Set(U?.statuses??be);for(let t of d)t.managed&&e.add(t.status);return L&&e.add(L.status),[...e].sort()},[U,d,L]);function Ae(e){H(``),R({id:e.id,title:e.title,kind:e.documentKind,status:e.status,owners:(e.owners??[]).join(`, `),reviewed:e.reviewed??``})}async function je(){if(!L)return;let e=d.find(e=>e.id===L.id);if(!e){H(`This document no longer exists in the workspace.`);return}let t=L.owners.split(`,`).map(e=>e.trim()).filter(Boolean),n={},r=L.title.trim();if(r&&r!==e.title&&(n.title=r),L.kind!==e.documentKind&&(n.kind=L.kind),L.status!==e.status&&(n.status=L.status),t.join(`
`)!==(e.owners??[]).join(`
`)&&(n.owners=t),(L.reviewed||``)!==(e.reviewed??``)&&(n.reviewed=L.reviewed||null),!Object.keys(n).length){R(null);return}B(!0),H(``);try{let t=await p.patchDocument(e.id,n,e.revision);h(n=>n.map(n=>n.id===e.id?t.record:n)),R(null)}catch(e){let t=e;t.code?.endsWith(`WRITE_CONFLICT`)?(W(e=>e+1),H(`The document changed on disk; the list was refreshed. Save again to apply your changes to the latest revision.`)):H(t.message||String(e))}finally{B(!1)}}return(0,C.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,C.jsxs)(`aside`,{"aria-label":`Documents`,className:o(`min-h-0 w-full shrink-0 flex-col border-r px-2 py-3 lg:flex lg:w-[290px]`,q?`hidden`:`flex`),children:[(0,C.jsxs)(`div`,{className:`flex flex-col gap-2 pb-2.5`,children:[(0,C.jsxs)(b,{className:`h-8`,children:[(0,C.jsx)(y,{children:(0,C.jsx)(i,{"aria-hidden":`true`})}),(0,C.jsx)(fe,{className:`h-8`,type:`search`,value:k,"aria-label":`Search documentation`,placeholder:`Search documentation…`,onChange:e=>A(e.target.value)})]}),(0,C.jsx)(`div`,{className:`flex gap-1.5`,children:(0,C.jsxs)(s,{type:`button`,variant:`outline`,size:`sm`,"aria-pressed":F,className:o(`h-7 gap-1.5 px-2.5 text-xs`,F&&`border-ring bg-accent`),onClick:()=>Ce(!F),children:[`managed`,(0,C.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:F?`only`:`all`})]})})]}),(0,C.jsx)(`div`,{"aria-busy":j||void 0,className:`min-h-0 flex-1 overflow-y-auto`,children:j?(0,C.jsxs)(`span`,{className:`flex items-center gap-2 px-2 py-1.5 font-mono text-[10.5px] text-muted-foreground`,children:[(0,C.jsx)(de,{className:`size-3`}),`Loading documents…`]}):N?(0,C.jsx)(m,{variant:`destructive`,className:`mt-1.5`,children:(0,C.jsx)(u,{children:N})}):K.length?K.map(e=>(0,C.jsxs)(`div`,{className:`flex flex-col gap-px pb-3.5`,children:[(0,C.jsxs)(`span`,{className:`flex items-center gap-2 px-2 py-1.5 font-mono text-[10.5px] text-muted-foreground`,children:[(0,C.jsx)(`span`,{className:`text-foreground/80`,children:e.label}),(0,C.jsx)(`span`,{children:e.docs.length})]}),e.docs.map(e=>(0,C.jsx)(xe,{document:e,selected:q?.id===e.id,onSelect:()=>t(e.id)},e.id))]},e.key)):(0,C.jsx)(se,{className:`gap-2 p-4 md:p-4`,children:(0,C.jsxs)(ie,{children:[(0,C.jsx)(ae,{className:`text-sm`,children:`No documents found.`}),(0,C.jsx)(oe,{className:`text-xs`,children:F?`Try another search, or include indexed files.`:`Try another search.`})]})})})]}),(0,C.jsx)(`section`,{ref:J,className:o(`min-w-0 flex-1 overflow-y-auto px-6 py-6.5 sm:px-8.5`,q?`block`:`hidden lg:block`),children:(0,C.jsx)(`div`,{className:ye,children:q?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(s,{type:`button`,variant:`ghost`,size:`sm`,className:`-ml-2 mb-2 lg:hidden`,onClick:()=>t(``),children:[(0,C.jsx)(ee,{"aria-hidden":`true`}),`All documents`]}),(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 font-mono text-[11px] text-muted-foreground`,children:[(0,C.jsx)(`span`,{children:q.id}),O,(0,C.jsx)(`span`,{children:q.documentKind}),O,(0,C.jsx)(`span`,{style:{color:a(q.status)},children:q.status}),O,(0,C.jsx)(`span`,{children:q.managed?`managed`:`indexed`}),(0,C.jsx)(`span`,{className:`flex-1`}),q.managed?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(s,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>we(e=>!e),children:[I?(0,C.jsx)(ne,{"aria-hidden":`true`}):(0,C.jsx)(te,{"aria-hidden":`true`}),I?`Preview`:`Edit`]}),(0,C.jsxs)(s,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>Ae(q),children:[(0,C.jsx)(re,{"aria-hidden":`true`}),`Metadata`]})]}):null]}),(0,C.jsx)(`h2`,{className:`mt-3 mb-1.5 text-2xl font-semibold tracking-tight`,children:q.title}),(0,C.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground [overflow-wrap:anywhere]`,children:q.path}),(0,C.jsxs)(`div`,{className:`mt-4.5 flex flex-wrap gap-2`,children:[(0,C.jsx)(E,{label:`kind`,value:q.documentKind}),(0,C.jsx)(E,{label:`status`,value:q.status}),(0,C.jsx)(E,{label:`reviewed`,value:q.reviewed||`—`}),(0,C.jsx)(E,{label:`owners`,value:q.owners?.join(`, `)||`—`}),(0,C.jsx)(E,{label:`backlinks`,value:String(q.incomingTotal??q.incoming.length)}),q.updated?(0,C.jsx)(E,{label:`updated`,value:q.updated}):null]}),q.freshness.length>0?(0,C.jsxs)(m,{role:`status`,className:`mt-4.5 max-w-2xl`,children:[(0,C.jsx)(r,{"aria-hidden":`true`,className:`text-sev-warning`}),(0,C.jsx)(u,{children:q.freshness.map(e=>(0,C.jsx)(`span`,{children:e.message},`${e.code}-${e.message}`))})]}):null,(0,C.jsx)(`div`,{className:`mt-6.5`,children:I&&q.managed?(0,C.jsx)(ce,{value:q.body,revision:q.revision,onSave:async(e,t)=>{let n=await p.patchDocument(q.id,{body:e},t);h(e=>e.map(e=>e.id===q.id?n.record:e))}},q.id):q.body.trim()?(0,C.jsx)(_e,{source:q.body,headingPrefix:w,onOpen:$}):(0,C.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:q.managed?`This document is empty. Use Edit to write its first version.`:`This file has no body to render.`})}),q.outgoing.length||q.incoming.length||q.scope?.length?(0,C.jsxs)(`div`,{className:`mt-7 flex max-w-[70ch] flex-col gap-4.5`,children:[(0,C.jsx)(D,{label:`links to`,links:q.outgoing,onOpen:$}),(0,C.jsx)(D,{label:(q.incomingTotal??q.incoming.length)>q.incoming.length?`backlinks (${q.incoming.length} of ${q.incomingTotal})`:`backlinks`,links:q.incoming,onOpen:$}),q.scope?.length?(0,C.jsxs)(`section`,{className:`flex flex-col gap-1.5`,children:[(0,C.jsx)(`span`,{className:T,children:`scope`}),q.scope.map(e=>(0,C.jsx)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground [overflow-wrap:anywhere]`,children:e},e))]}):null]}):null]}):(0,C.jsx)(`div`,{className:`flex h-full items-center justify-center text-xs text-muted-foreground`,children:j?`Loading documents…`:`Select a document from the list to read it.`})})}),Q?(0,C.jsx)(Se,{entries:Z,activeId:Y,onJump:De}):null,(0,C.jsx)(pe,{open:L!==null,onOpenChange:e=>{!e&&!z&&R(null)},children:(0,C.jsxs)(he,{"aria-describedby":void 0,children:[(0,C.jsx)(v,{children:(0,C.jsx)(ge,{children:`Edit metadata${L?` — ${L.id}`:``}`})}),L?(0,C.jsxs)(ve,{className:`gap-4`,children:[(0,C.jsxs)(x,{children:[(0,C.jsx)(g,{htmlFor:`docs-meta-title`,children:`title`}),(0,C.jsx)(f,{id:`docs-meta-title`,value:L.title,onChange:e=>R({...L,title:e.target.value})})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,C.jsxs)(x,{className:`[&_[data-slot=native-select-wrapper]]:w-full`,children:[(0,C.jsx)(g,{htmlFor:`docs-meta-kind`,children:`kind`}),(0,C.jsx)(l,{id:`docs-meta-kind`,value:L.kind,onChange:e=>R({...L,kind:e.target.value}),children:Oe.map(e=>(0,C.jsx)(c,{value:e,children:e},e))})]}),(0,C.jsxs)(x,{className:`[&_[data-slot=native-select-wrapper]]:w-full`,children:[(0,C.jsx)(g,{htmlFor:`docs-meta-status`,children:`status`}),(0,C.jsx)(l,{id:`docs-meta-status`,value:L.status,onChange:e=>R({...L,status:e.target.value}),children:ke.map(e=>(0,C.jsx)(c,{value:e,children:e},e))})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,C.jsxs)(x,{children:[(0,C.jsx)(g,{htmlFor:`docs-meta-owners`,children:`owners`}),(0,C.jsx)(f,{id:`docs-meta-owners`,value:L.owners,placeholder:`comma-separated`,onChange:e=>R({...L,owners:e.target.value})})]}),(0,C.jsxs)(x,{children:[(0,C.jsx)(g,{htmlFor:`docs-meta-reviewed`,children:`reviewed`}),(0,C.jsx)(f,{id:`docs-meta-reviewed`,type:`date`,value:L.reviewed,onChange:e=>R({...L,reviewed:e.target.value})})]})]}),V?(0,C.jsx)(m,{variant:`destructive`,children:(0,C.jsx)(u,{children:V})}):null]}):null,(0,C.jsxs)(_,{children:[(0,C.jsx)(s,{type:`button`,variant:`outline`,disabled:z,onClick:()=>R(null),children:`Cancel`}),(0,C.jsx)(s,{type:`button`,disabled:z,onClick:()=>void je(),children:z?`Saving…`:`Save`})]})]})})]})}export{k as DocsView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{Ct as r,St as i,b as a,ft as o,vt as s,y as c,z as ee}from"./ui-primitives-wYj92QGw.js";import{f as l,i as te,m as u,o as ne,p as d,r as re,s as f,t as ie}from"./empty-BHqXimMR.js";import{n as p,t as m}from"./native-select-NN1SzVJL.js";import{B as ae,D as oe,L as se,R as ce,V as le,a as h,i as ue,o as g,s as de,z as fe}from"./index-hHNShan0.js";import{t as _}from"./progress-CKc41PRw.js";var v=e(t(),1),y=n();function b({className:e,...t}){return(0,y.jsx)(c,{"data-slot":`checkbox`,className:u(`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)(a,{"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:u(`w-full caption-bottom text-sm`,e),...t})})}function me({className:e,...t}){return(0,y.jsx)(`thead`,{"data-slot":`table-header`,className:u(`[&_tr]:border-b`,e),...t})}function he({className:e,...t}){return(0,y.jsx)(`tbody`,{"data-slot":`table-body`,className:u(`[&_tr:last-child]:border-0`,e),...t})}function x({className:e,...t}){return(0,y.jsx)(`tr`,{"data-slot":`table-row`,className:u(`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:u(`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:u(`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(h.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:u(`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:u(`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:u(`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)(m,{"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)(p,{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:u(`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:h,color:f(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:u(`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:a,setFilters:s,epicIds:c,onOpen:u,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)(a),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`?(c.get(e.id)||``).localeCompare(c.get(t.id)||``):String(e[M]||``).localeCompare(String(t[M]||``),void 0,{numeric:!0}),N===`asc`?n:-n}),t},[c,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=[a.search,a.status,a.area,a.type,a.priority,a.milestone,a.showIdeas,a.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),u(e)},[u]),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:a.status,color:l,onSelect:e=>s(t=>({...t,status:e}))}),(0,y.jsx)(k,{title:`priority`,values:h,counts:G.priority,selected:a.priority,color:f,onSelect:e=>s(t=>({...t,priority:e}))}),(0,y.jsx)(k,{title:`area`,values:n,counts:G.area,selected:a.area,onSelect:e=>s(t=>({...t,area:e}))}),(0,y.jsx)(k,{title:`type`,values:de,counts:G.type,selected:a.type,onSelect:e=>s(t=>({...t,type:e}))})]}),$=[a.status,a.priority,a.area,a.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)(se,{children:[(0,y.jsx)(le,{asChild:!0,children:(0,y.jsxs)(d,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 px-2.5 text-xs`,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)(fe,{className:`pb-2`,children:(0,y.jsx)(ae,{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)(m,{"aria-label":`Set status`,value:F,onChange:e=>I(e.target.value),className:`h-7 px-2 py-0 pr-8 text-xs`,children:[(0,y.jsx)(p,{value:``,children:`status…`}),g.map(e=>(0,y.jsx)(p,{value:e,children:e},e))]}),(0,y.jsxs)(m,{"aria-label":`Set priority`,value:L,onChange:e=>R(e.target.value),className:`h-7 px-2 py-0 pr-8 text-xs`,children:[(0,y.jsx)(p,{value:``,children:`priority…`}),h.map(e=>(0,y.jsx)(p,{value:e,children:e},e))]}),(0,y.jsxs)(m,{"aria-label":`Set area`,value:z,onChange:e=>B(e.target.value),className:`h-7 px-2 py-0 pr-8 text-xs`,children:[(0,y.jsx)(p,{value:``,children:`area…`}),n.map(e=>(0,y.jsx)(p,{value:e,children:e},e))]}),(0,y.jsxs)(oe,{children:[(0,y.jsx)(d,{size:`sm`,className:`h-7`,disabled:!Z,onClick:()=>void ke(),children:`Apply`}),(0,y.jsx)(d,{size:`sm`,variant:`outline`,className:`h-7`,onClick:()=>j(new Set),children:`Clear`})]})]}),K.length===0?(0,y.jsx)(ie,{children:(0,y.jsxs)(te,{children:[(0,y.jsx)(ne,{children:`No cards match`}),(0,y.jsx)(re,{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)(d,{variant:`ghost`,size:`sm`,onClick:()=>Oe(e),className:`-ml-2 h-7 gap-1 px-2 text-xs text-muted-foreground`,children:[t,M===e?N===`asc`?(0,y.jsx)(i,{className:`size-3`}):(0,y.jsx)(r,{className:`size-3`}):(0,y.jsx)(o,{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:c.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{dt as r}from"./ui-primitives-wYj92QGw.js";import{a as i,f as a,i as o,o as s,p as c,r as l,t as u,u as d}from"./empty-BHqXimMR.js";import{$ as f,A as p,I as m,Q as h,T as g,Z as _,j as v,k as y}from"./index-hHNShan0.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);y(()=>A(e=>e+1)),(0,b.useEffect)(()=>{let e=!0;return m.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)(h,{variant:`destructive`,children:(0,x.jsx)(f,{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)(g,{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)(c,{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:i})=>{let o=t.counts[e],s=e===`error`&&o===0?a(`done`):d(e);return(0,x.jsxs)(v,{className:`relative min-w-[13rem] flex-1 gap-1 py-3 pl-5 pr-3.5`,children:[(0,x.jsx)(p,{edge:`left`,color:s}),(0,x.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,x.jsx)(`span`,{className:`text-[26px] font-semibold tracking-tight`,style:{color:s},children:o}),(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:o===0?i:r})]},e)})}),(0,x.jsxs)(`div`,{className:`flex items-center gap-2.5 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:`flex-1`}),(0,x.jsx)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground/70`,children:`workfile doctor --json`})]}),j.length===0?(0,x.jsx)(u,{className:`gap-2 p-10`,children:(0,x.jsxs)(o,{children:[(0,x.jsx)(i,{children:(0,x.jsx)(r,{"aria-hidden":`true`,size:20,style:{color:a(`done`)}})}),(0,x.jsx)(s,{className:`text-sm`,children:`All clear`}),(0,x.jsxs)(l,{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)(v,{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:d(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)(c,{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{K as r,N as i,_t as a,gt as o}from"./ui-primitives-wYj92QGw.js";import{f as s,l as c,m as l,p as u,r as d,t as f,u as p}from"./empty-BHqXimMR.js";import{n as m,t as h}from"./native-select-NN1SzVJL.js";import{$ as g,D as _,E as v,F as y,G as b,H as x,I as S,K as C,M as w,N as T,O as ee,P as te,Q as E,W as D,X as O,Z as ne,b as k,c as A,d as j,f as M,j as re,k as ie,l as N,p as P,u as F,v as I,w as ae,x as oe}from"./index-hHNShan0.js";import{t as se}from"./layout-QiuZ_k5v.js";var L=e(t(),1),R=n(),z=`text-[10px] font-medium tracking-widest uppercase text-muted-foreground`;function B(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 p(`error`);default:return s(`backlog`)}}function ce(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 V(e){return e instanceof Error?e.message:String(e)}function H({label:e,value:t,options:n,onChange:r}){return(0,R.jsxs)(D,{children:[(0,R.jsx)(O,{asChild:!0,children:(0,R.jsxs)(u,{type:`button`,variant:`outline`,size:`sm`,"aria-label":e,className:l(`h-7 gap-1 px-2 text-xs`,t&&`border-ring bg-accent`),children:[e,(0,R.jsx)(`span`,{className:l(`font-normal`,!t&&`text-muted-foreground`),children:t||`all`}),(0,R.jsx)(a,{"aria-hidden":`true`,className:`size-3 text-muted-foreground`})]})}),(0,R.jsxs)(C,{align:`start`,children:[(0,R.jsx)(b,{checked:!t,onSelect:()=>r(``),children:`all`}),n.map(e=>(0,R.jsx)(b,{checked:t===e,onSelect:()=>r(e),children:e},e))]})]})}function U({record:e,selected:t,onSelect:n}){let r=e.kind===`release`?`release`:e.type,i=e.kind===`release`?`var(--primary)`:B(e.type),a=e.kind===`release`?`${e.fragments.length} fragment${e.fragments.length===1?``:`s`} · ${e.date}`:e.area;return(0,R.jsx)(v,{asChild:!0,variant:`outline`,size:`sm`,children:(0,R.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,className:l(`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,R.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,R.jsx)(`span`,{className:`font-mono text-[10px]`,style:{color:i},children:r}),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsx)(`span`,{className:`max-w-[170px] truncate font-mono text-[10px] text-muted-foreground/70`,children:a})]}),(0,R.jsx)(`span`,{className:`text-sm leading-snug font-normal`,children:e.title})]})})}function W({label:e,records:t,selectedId:n,onSelect:r}){return t.length?(0,R.jsxs)(`div`,{role:`group`,"aria-label":e,className:`flex flex-col gap-1.5 pt-4`,children:[(0,R.jsxs)(`span`,{className:z,children:[e,` · `,t.length]}),t.map(e=>(0,R.jsx)(U,{record:e,selected:e.id===n,onSelect:()=>r(e.id)},e.id))]}):null}function G({id:e,title:t,relation:n,disabled:r,onOpen:i}){return(0,R.jsx)(v,{asChild:!0,variant:`outline`,size:`sm`,children:(0,R.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,R.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-muted-foreground`,children:e}),(0,R.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[12.5px]`,children:t}),n?(0,R.jsx)(ne,{variant:`outline`,className:`shrink-0 font-mono text-[10px] font-normal text-muted-foreground`,children:n}):null]})})}function K({label:e,links:t,onOpen:n}){return t.length?(0,R.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,R.jsx)(`span`,{className:z,children:e}),t.map(t=>(0,R.jsx)(G,{id:t.id,title:t.title,relation:t.relation,disabled:t.disabled,onOpen:()=>n(t.id)},`${e}-${t.id}`))]}):null}function le(e){return e.map(e=>({id:e.id,title:e.title||`Missing record`,relation:e.relation,disabled:!e.exists&&!e.title}))}function ue({schema:e,areas:t,onClose:n,onCreated:r}){let[i,a]=(0,L.useState)({title:``,type:e.defaults.type,area:t[0]||`general`,visibility:e.defaults.visibility,body:``}),[o,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(``),d=(e,t)=>a(n=>({...n,[e]:t})),f=async()=>{s(!0);try{r((await S.createChange(i)).record)}catch(e){l(V(e))}finally{s(!1)}};return(0,R.jsx)(A,{open:!0,onOpenChange:e=>{e||n()},children:(0,R.jsxs)(N,{onOpenAutoFocus:e=>e.preventDefault(),children:[(0,R.jsxs)(M,{children:[(0,R.jsx)(P,{children:`New change fragment`}),(0,R.jsx)(F,{children:`Record one user- or operator-meaningful change.`})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(k,{htmlFor:`new-fragment-title`,children:`Title`}),(0,R.jsx)(x,{id:`new-fragment-title`,autoFocus:!0,required:!0,maxLength:120,value:i.title,onChange:e=>d(`title`,e.target.value)})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-3 gap-2.5`,children:[(0,R.jsxs)(I,{children:[(0,R.jsx)(k,{htmlFor:`new-fragment-type`,children:`Type`}),(0,R.jsx)(h,{id:`new-fragment-type`,value:i.type,onChange:e=>d(`type`,e.target.value),children:e.types.map(e=>(0,R.jsx)(m,{value:e,children:e},e))})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(k,{htmlFor:`new-fragment-area`,children:`Area`}),(0,R.jsx)(h,{id:`new-fragment-area`,value:i.area,onChange:e=>d(`area`,e.target.value),children:t.map(e=>(0,R.jsx)(m,{value:e,children:e},e))})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(k,{htmlFor:`new-fragment-visibility`,children:`Visibility`}),(0,R.jsx)(h,{id:`new-fragment-visibility`,value:i.visibility,onChange:e=>d(`visibility`,e.target.value),children:e.visibilities.map(e=>(0,R.jsx)(m,{value:e,children:e},e))})]})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(k,{htmlFor:`new-fragment-details`,children:`Details`}),(0,R.jsx)(ae,{id:`new-fragment-details`,rows:5,value:i.body,onChange:e=>d(`body`,e.target.value)})]}),c?(0,R.jsx)(E,{variant:`destructive`,"aria-live":`polite`,children:(0,R.jsx)(g,{children:c})}):null,(0,R.jsxs)(j,{children:[(0,R.jsx)(u,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,R.jsx)(u,{type:`button`,disabled:o||!i.title.trim(),onClick:()=>void f(),children:o?`Saving…`:`Create fragment`})]})]})})}function de({preview:e,suggestedVersion:t,onClose:n,onReleased:r}){let[i,a]=(0,L.useState)(t),[o,s]=(0,L.useState)(``),[c,l]=(0,L.useState)(!1),[d,f]=(0,L.useState)(``),p=async()=>{l(!0);try{await S.createRelease({version:i,title:o||void 0,fragmentIds:e.fragments.map(e=>e.id)}),r()}catch(e){f(V(e))}finally{l(!1)}};return(0,R.jsx)(A,{open:!0,onOpenChange:e=>{e||n()},children:(0,R.jsxs)(N,{className:`flex max-h-[85vh] flex-col sm:max-w-[640px]`,children:[(0,R.jsxs)(M,{children:[(0,R.jsx)(P,{children:`Release preparation`}),(0,R.jsxs)(F,{children:[e.fragments.length,` unreleased fragment`,e.fragments.length===1?``:`s`,` selected.`]})]}),(0,R.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto`,children:[(0,R.jsxs)(`div`,{className:`grid grid-cols-[150px_1fr] gap-2.5`,children:[(0,R.jsxs)(I,{children:[(0,R.jsx)(k,{htmlFor:`release-version`,children:`Version`}),(0,R.jsx)(x,{id:`release-version`,className:`font-mono`,placeholder:`2.4.0`,value:i,onChange:e=>a(e.target.value)})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(k,{htmlFor:`release-title`,children:`Release title`}),(0,R.jsx)(x,{id:`release-title`,placeholder:`Optional curated title`,value:o,onChange:e=>s(e.target.value)})]})]}),e.groups.map(e=>(0,R.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,R.jsxs)(`span`,{className:z,style:{color:B(e.type)},children:[e.type,` · `,e.fragments.length]}),e.fragments.map(e=>(0,R.jsxs)(`span`,{className:`flex items-baseline gap-2 text-[12.5px]`,children:[(0,R.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,R.jsx)(`span`,{className:`min-w-0 truncate`,children:e.title}),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground/70`,children:e.area})]},e.id))]},e.type)),(0,R.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,R.jsx)(`span`,{className:z,children:`release notes preview`}),(0,R.jsx)(`div`,{className:`max-h-[220px] overflow-y-auto rounded-md border bg-background px-3 py-1`,children:(0,R.jsx)(oe,{source:e.markdown||`No release notes to render.`})})]}),d?(0,R.jsx)(E,{variant:`destructive`,"aria-live":`polite`,children:(0,R.jsx)(g,{children:d})}):null]}),(0,R.jsxs)(j,{children:[(0,R.jsx)(u,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,R.jsx)(u,{type:`button`,disabled:c||!i.trim()||!e.fragments.length,onClick:()=>void p(),children:c?`Releasing…`:`Create release`})]})]})})}function fe({record:e,schema:t,areas:n,onSaved:r}){let[i,a]=(0,L.useState)({title:e.title,type:e.type,area:e.area,visibility:e.visibility}),[o,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(``),d=(e,t)=>a(n=>({...n,[e]:t})),f={};for(let t of[`title`,`type`,`area`,`visibility`])i[t]!==e[t]&&(f[t]=i[t]);let g=Object.keys(f).length>0,_=n.includes(e.area)?n:[e.area,...n],v=async()=>{s(!0);try{let t=await S.patchChange(e.id,f,e.revision);l(``),r(t.record)}catch(e){l(V(e))}finally{s(!1)}};return(0,R.jsxs)(re,{className:`gap-2.5 rounded-lg py-3 shadow-xs`,children:[(0,R.jsx)(te,{className:`px-3`,children:(0,R.jsx)(y,{className:z,children:`edit fragment`})}),(0,R.jsxs)(w,{className:`flex flex-col gap-2.5 px-3`,children:[(0,R.jsxs)(I,{children:[(0,R.jsx)(k,{htmlFor:`edit-fragment-title`,children:`Title`}),(0,R.jsx)(x,{id:`edit-fragment-title`,maxLength:120,value:i.title,onChange:e=>d(`title`,e.target.value)})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-3 gap-2.5`,children:[(0,R.jsxs)(I,{children:[(0,R.jsx)(k,{htmlFor:`edit-fragment-type`,children:`Type`}),(0,R.jsx)(h,{id:`edit-fragment-type`,value:i.type,onChange:e=>d(`type`,e.target.value),children:t.types.map(e=>(0,R.jsx)(m,{value:e,children:e},e))})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(k,{htmlFor:`edit-fragment-area`,children:`Area`}),(0,R.jsx)(h,{id:`edit-fragment-area`,value:i.area,onChange:e=>d(`area`,e.target.value),children:_.map(e=>(0,R.jsx)(m,{value:e,children:e},e))})]}),(0,R.jsxs)(I,{children:[(0,R.jsx)(k,{htmlFor:`edit-fragment-visibility`,children:`Visibility`}),(0,R.jsx)(h,{id:`edit-fragment-visibility`,value:i.visibility,onChange:e=>d(`visibility`,e.target.value),children:t.visibilities.map(e=>(0,R.jsx)(m,{value:e,children:e},e))})]})]})]}),(0,R.jsxs)(T,{className:`gap-2.5 px-3`,children:[c?(0,R.jsx)(`span`,{className:`flex-1 text-xs`,style:{color:p(`error`)},"aria-live":`polite`,children:c}):(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsx)(u,{type:`button`,variant:`outline`,size:`sm`,disabled:o||!g||!i.title.trim(),onClick:()=>void v(),children:o?`Saving…`:`Save changes`})]})]})}function pe({selectedId:e,onSelect:t,onOpenRecord:n,schema:a,areas:s}){let[m,h]=(0,L.useState)([]),[v,y]=(0,L.useState)(``),[b,C]=(0,L.useState)(``),[w,T]=(0,L.useState)(``),[te,D]=(0,L.useState)(!0),[O,k]=(0,L.useState)(``),[A,j]=(0,L.useState)(``),[M,N]=(0,L.useState)(!1),[P,F]=(0,L.useState)(null),[I,ae]=(0,L.useState)(`public`),[z,U]=(0,L.useState)({content:``,error:``,loading:!0}),[G,pe]=(0,L.useState)(0),me=()=>pe(e=>e+1);ie(e=>{ee(e,`/changelog/`)&&me()}),(0,L.useEffect)(()=>{let e=!1,t=async()=>{D(!0);try{let t=await S.changelog(v.trim(),{state:b||void 0,visibility:w||void 0});if(e)return;h(t.records),k(``)}catch(t){e||k(V(t))}finally{e||D(!1)}},n=window.setTimeout(()=>void t(),v?180:0);return()=>{e=!0,window.clearTimeout(n)}},[v,b,w,G]),(0,L.useEffect)(()=>{let e=!1;return U(e=>({...e,loading:!0})),S.renderedChangelog(I).then(t=>{e||U({content:t.content,error:``,loading:!1})}).catch(t=>{e||U({content:``,error:V(t),loading:!1})}),()=>{e=!0}},[I,G]);let q=(0,L.useMemo)(()=>[...m].sort((e,t)=>e.kind===t.kind?e.kind===`release`&&t.kind===`release`?t.date.localeCompare(e.date):String(t.updated||``).localeCompare(String(e.updated||``)):e.kind===`change`?-1:1),[m]),J=(0,L.useMemo)(()=>new Map(m.map(e=>[e.id,e])),[m]),Y=(0,L.useMemo)(()=>q.filter(e=>e.kind===`change`&&!e.released),[q]),he=(0,L.useMemo)(()=>q.filter(e=>e.kind===`change`&&e.released),[q]),X=(0,L.useMemo)(()=>q.filter(e=>e.kind===`release`),[q]),Z=(0,L.useMemo)(()=>ce(X,Y),[X,Y]),Q=e?J.get(e):void 0,$=e=>{if(J.has(e)){t(e);return}if(/^(CHG|REL)-/.test(e)){C(``),T(``),t(e);return}n(e)},ge=()=>{j(``),S.releasePreview().then(F).catch(e=>j(V(e)))},_e=Q?.issues.some(e=>e.severity===`error`)?`destructive`:`default`,ve=(0,R.jsxs)(u,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>N(!0),children:[(0,R.jsx)(r,{"aria-hidden":`true`}),`New fragment`]});return(0,R.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:l(`w-full shrink-0 flex-col border-r lg:flex lg:w-[400px]`,Q?`hidden`:`flex`),children:[(0,R.jsxs)(`div`,{className:`flex flex-col gap-2.5 p-3.5 pb-0`,children:[(0,R.jsxs)(re,{className:`flex-row items-center gap-2.5 border-primary bg-primary/10 p-3`,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,R.jsxs)(`span`,{className:`text-[13px] font-semibold`,children:[Y.length,` unpublished fragment`,Y.length===1?``:`s`]}),(0,R.jsxs)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground`,children:[`next: `,Z,` ·`,` `,a.releaseStrategy]})]}),(0,R.jsx)(u,{type:`button`,size:`sm`,className:`whitespace-nowrap`,onClick:ge,children:`Prepare release`})]}),A?(0,R.jsx)(E,{variant:`destructive`,"aria-live":`polite`,children:(0,R.jsx)(g,{children:A})}):null,(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(x,{type:`search`,"aria-label":`Search history`,placeholder:`Search fragments and releases…`,value:v,onChange:e=>y(e.target.value),className:`h-7 flex-1 px-2.5 text-xs md:text-xs`}),(0,R.jsx)(H,{label:`state`,value:b,options:[`unreleased`,`released`],onChange:C}),(0,R.jsx)(H,{label:`visibility`,value:w,options:a.visibilities,onChange:T})]})]}),(0,R.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:te?(0,R.jsx)(`div`,{"aria-busy":`true`,className:`flex flex-col gap-2 pt-4`,children:Array.from({length:6},(e,t)=>(0,R.jsx)(`div`,{className:`h-[52px] animate-pulse rounded-md bg-muted`},t))}):O?(0,R.jsx)(E,{variant:`destructive`,className:`mt-4`,"aria-live":`polite`,children:(0,R.jsx)(g,{children:O})}):q.length?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(W,{label:`unpublished`,records:Y,selectedId:e,onSelect:t}),(0,R.jsx)(W,{label:`releases`,records:X,selectedId:e,onSelect:t}),(0,R.jsx)(W,{label:`published fragments`,records:he,selectedId:e,onSelect:t})]}):(0,R.jsx)(f,{className:`mt-4 gap-1 p-4 md:p-4`,children:(0,R.jsx)(d,{className:`text-xs`,children:`No history records match the filters.`})})})]}),(0,R.jsx)(`div`,{className:l(`min-w-0 flex-1 overflow-y-auto px-6 py-5 sm:px-8.5`,Q?`block`:`hidden lg:block`),children:(0,R.jsx)(`div`,{className:se,children:Q?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(u,{type:`button`,variant:`ghost`,size:`sm`,className:`-ml-2 mb-2 lg:hidden`,onClick:()=>t(``),children:[(0,R.jsx)(o,{"aria-hidden":`true`}),`All history`]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 font-mono text-[11px]`,children:[(0,R.jsx)(`span`,{className:`text-primary`,children:Q.id}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{className:`text-muted-foreground/70`,children:Q.kind}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),Q.kind===`change`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{style:{color:B(Q.type)},children:Q.type}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:Q.area}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:Q.visibility}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{style:{color:c(Q.released?`released`:`unreleased`)},children:Q.released?`released`:`unreleased`}),Q.updated?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{className:`text-muted-foreground/70`,children:Q.updated})]}):null]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-primary`,children:Q.version}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:Q.date}),Q.commit?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{className:`text-muted-foreground/70`,children:Q.commit})]}):null,(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[Q.fragments.length,` fragment`,Q.fragments.length===1?``:`s`]})]}),(0,R.jsx)(`span`,{className:`flex-1`}),ve,(0,R.jsx)(u,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Close record`,title:`Back to the derived changelog`,onClick:()=>t(``),children:(0,R.jsx)(i,{"aria-hidden":`true`})})]}),(0,R.jsx)(`h2`,{className:`mt-2.5 mb-1 text-[26px] leading-tight font-semibold tracking-tight [text-wrap:pretty]`,children:Q.title}),(0,R.jsx)(`div`,{className:`font-mono text-[10.5px] break-all text-muted-foreground/70`,children:Q.path}),Q.issues.length>0?(0,R.jsx)(E,{variant:_e,className:`mt-3.5`,children:(0,R.jsx)(g,{className:`w-full gap-1`,children:Q.issues.map(e=>(0,R.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,R.jsx)(`span`,{className:`shrink-0 font-mono text-[10.5px]`,style:{color:p(e.severity)},children:e.severity}),(0,R.jsx)(`span`,{children:e.message})]},`${e.code}-${e.message}`))})}):null,(0,R.jsx)(`div`,{className:`mt-4.5`,children:(0,R.jsx)(oe,{source:Q.body||`No additional notes.`,onOpen:$})}),(0,R.jsxs)(`div`,{className:`mt-5.5 flex flex-col gap-3.5`,children:[Q.kind===`change`?(0,R.jsx)(K,{label:`shipped in`,links:(Q.releaseIds||[]).map(e=>({id:e,title:J.get(e)?.title||`Open release`,relation:`release`})),onOpen:$}):(0,R.jsx)(K,{label:`fragments · ${Q.fragments.length}`,links:Q.fragments.map(e=>{let t=J.get(e);return{id:e,title:t?.title||`Open fragment`,relation:t?.kind===`change`?t.type:void 0}}),onOpen:$}),(0,R.jsx)(K,{label:`links to`,links:le(Q.outgoing),onOpen:$}),(0,R.jsx)(K,{label:`backlinks`,links:le(Q.incoming),onOpen:$})]}),Q.kind===`change`?(0,R.jsx)(`div`,{className:`mt-5.5`,children:(0,R.jsx)(fe,{record:Q,schema:a,areas:s,onSaved:e=>h(t=>t.map(t=>t.id===e.id?e:t))},`${Q.id}:${Q.revision}`)}):null]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2.5 border-b pb-3`,children:[(0,R.jsx)(`span`,{className:`text-[13px] font-semibold`,children:`Derived changelog`}),(0,R.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:[`visibility `,I,` · CHANGELOG.md`]}),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsx)(_,{children:a.visibilities.map(e=>(0,R.jsx)(u,{type:`button`,size:`sm`,variant:I===e?`default`:`outline`,"aria-pressed":I===e,className:`h-7 px-2.5 text-xs`,onClick:()=>ae(e),children:e},e))}),(0,R.jsx)(ne,{variant:`outline`,className:`rounded-md font-mono text-[10.5px] font-normal whitespace-nowrap text-muted-foreground`,children:`render --write`}),ve]}),z.error?(0,R.jsx)(E,{variant:`destructive`,className:`mt-4`,"aria-live":`polite`,children:(0,R.jsx)(g,{children:z.error})}):(0,R.jsx)(`pre`,{className:`mt-4 font-mono text-xs leading-[1.75] whitespace-pre-wrap text-muted-foreground`,"aria-busy":z.loading||void 0,children:z.loading&&!z.content?`Rendering…`:z.content||`Nothing to render yet — create the first change fragment.`})]})})}),M?(0,R.jsx)(ue,{schema:a,areas:s,onClose:()=>N(!1),onCreated:e=>{N(!1),h(t=>[e,...t]),t(e.id)}}):null,P?(0,R.jsx)(de,{preview:P,suggestedVersion:Z,onClose:()=>F(null),onReleased:()=>{F(null),me()}}):null]})}export{pe as HistoryView};

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

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{G as r,K as i,V as a,_t as o,it as s,q as c,vt as l}from"./ui-primitives-wYj92QGw.js";import{l as u,m as d,p as f,r as p,t as m,u as h}from"./empty-BHqXimMR.js";import{n as g,t as _}from"./native-select-NN1SzVJL.js";import{$ as v,E as y,H as b,I as x,K as S,M as ee,O as te,P as ne,Q as C,T as w,W as T,X as E,Z as D,_ as re,b as O,c as k,d as A,f as j,g as M,h as N,j as P,k as F,l as I,m as ie,p as L,q as R,v as z,w as B,x as V}from"./index-hHNShan0.js";var H=e(t(),1),U=n(),W=[`low`,`medium`,`high`],G=[`critical`,`high`,`medium`,`low`],ae=`[mask-image:linear-gradient(to_bottom,black_calc(100%_-_24px),transparent)]`;function oe(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 se(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 J({label:e,value:t,options:n,allLabel:r=`all`,onChange:i}){return(0,U.jsxs)(T,{children:[(0,U.jsx)(E,{asChild:!0,children:(0,U.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,"aria-label":e,className:d(`h-7 gap-1 rounded-full px-2.5 text-xs`,t&&`border-ring bg-accent`),children:[e,(0,U.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:t||r}),(0,U.jsx)(o,{"aria-hidden":`true`,className:`size-3 text-muted-foreground`})]})}),(0,U.jsxs)(S,{align:`start`,sideOffset:4,children:[(0,U.jsxs)(R,{onSelect:()=>i(``),children:[r,t?null:(0,U.jsx)(l,{"aria-hidden":`true`,className:`ml-auto`})]}),n.map(e=>(0,U.jsxs)(R,{onSelect:()=>i(e.value),children:[e.color?(0,U.jsx)(`span`,{className:`size-2 shrink-0 rounded-full`,style:{backgroundColor:e.color},"aria-hidden":`true`}):null,e.label??e.value,t===e.value?(0,U.jsx)(l,{"aria-hidden":`true`,className:`ml-auto`}):null]},e.value))]})]})}function Y({id:e,label:t,children:n}){return(0,U.jsxs)(z,{className:`gap-1.5 [&_[data-slot=native-select-wrapper]]:w-full`,children:[(0,U.jsx)(O,{htmlFor:e,children:t}),n]})}function ce({record:e,selected:t,onSelect:n}){let r=se(e),i=e.lifecycleIssues?.length||0;return(0,U.jsx)(y,{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,U.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,children:[(0,U.jsxs)(`span`,{className:`flex items-center justify-between gap-2`,children:[(0,U.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,U.jsxs)(D,{variant:`outline`,className:`h-[18px] gap-1 rounded-md px-1.5 font-mono text-[10px] font-medium`,children:[(0,U.jsx)(`span`,{className:`size-[5px] shrink-0 rounded-full`,style:{backgroundColor:u(e.status)},"aria-hidden":`true`}),e.status]})]}),(0,U.jsx)(`span`,{className:`text-[13px] font-medium leading-snug`,children:e.title}),r||i?(0,U.jsxs)(`span`,{className:`font-mono text-[10.5px] text-muted-foreground`,children:[r,r&&i?` · `:null,i?(0,U.jsx)(`span`,{style:{color:h(`warning`)},children:K(i,`lifecycle warning`)}):null]}):null]})})}function X({issues:e,kind:t}){return e.length?(0,U.jsx)(U.Fragment,{children:e.map(e=>(0,U.jsx)(C,{variant:e.severity===`error`?`destructive`:`default`,className:`px-3 py-2`,children:(0,U.jsxs)(v,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-0.5`,children:[(0,U.jsx)(`span`,{className:`font-mono text-[10.5px]`,style:{color:h(e.severity)},children:t===`lifecycle`?`lifecycle`:e.severity}),(0,U.jsx)(`span`,{children:e.message})]})},`${t}-${e.code}-${e.message}`))}):null}function Z({label:e,links:t,onOpen:n}){return t.length?(0,U.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,U.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,U.jsx)(y,{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,U.jsxs)(`button`,{type:`button`,disabled:r,onClick:()=>n(t.id),children:[(0,U.jsx)(`span`,{className:`w-[78px] shrink-0 truncate font-mono text-[11px] font-medium`,children:t.id}),(0,U.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-muted-foreground`,children:t.title||`Missing record`}),t.relation||t.kind?(0,U.jsx)(D,{variant:`secondary`,className:`h-[18px] rounded-md px-1.5 font-mono text-[10px] font-medium`,children:t.relation||t.kind}):null]})},`${e}-${t.id}`)})]}):null}function Q({message:e}){return e?(0,U.jsx)(C,{variant:`destructive`,className:`px-3 py-2`,children:(0,U.jsx)(v,{children:e})}):null}function le({schema:e,initialCollection:t,onClose:n,onCreated:r}){let i=e.collections.find(e=>e.id===t)||e.collections[0],[a,o]=(0,H.useState)({collection:i?.id||`learnings`,status:i?.statuses[0]||`active`,title:``,category:``,confidence:``,severity:``,expires:``,body:``}),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(``),d=e.collections.find(e=>e.id===a.collection),p=q(a.collection),m=(e,t)=>o(n=>({...n,[e]:t})),h=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 x.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){u(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,U.jsx)(k,{open:!0,onOpenChange:e=>{e||n()},children:(0,U.jsxs)(I,{className:`sm:max-w-[520px]`,"aria-describedby":void 0,children:[(0,U.jsx)(j,{children:(0,U.jsxs)(L,{children:[`New `,d?.singular||`record`]})}),(0,U.jsxs)(`div`,{className:`-m-1 flex max-h-[65vh] flex-col gap-3 overflow-y-auto p-1`,children:[(0,U.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,U.jsx)(Y,{id:`memory-create-collection`,label:`Collection`,children:(0,U.jsx)(_,{id:`memory-create-collection`,value:a.collection,onChange:e=>h(e.target.value),children:e.collections.map(e=>(0,U.jsx)(g,{value:e.id,children:e.id},e.id))})}),(0,U.jsx)(Y,{id:`memory-create-status`,label:`Status`,children:(0,U.jsx)(_,{id:`memory-create-status`,value:a.status,onChange:e=>m(`status`,e.target.value),children:(d?.statuses||[]).map(e=>(0,U.jsx)(g,{value:e,children:e},e))})})]}),(0,U.jsx)(Y,{id:`memory-create-title`,label:`Title`,children:(0,U.jsx)(b,{id:`memory-create-title`,autoFocus:!0,required:!0,maxLength:120,value:a.title,onChange:e=>m(`title`,e.target.value)})}),p.category||p.confidence||p.severity||p.expires?(0,U.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[p.category?(0,U.jsx)(Y,{id:`memory-create-category`,label:`Category`,children:(0,U.jsx)(b,{id:`memory-create-category`,value:a.category,onChange:e=>m(`category`,e.target.value)})}):null,p.confidence?(0,U.jsx)(Y,{id:`memory-create-confidence`,label:`Confidence`,children:(0,U.jsxs)(_,{id:`memory-create-confidence`,value:a.confidence,onChange:e=>m(`confidence`,e.target.value),children:[(0,U.jsx)(g,{value:``,children:`not set`}),W.map(e=>(0,U.jsx)(g,{value:e,children:e},e))]})}):null,p.severity?(0,U.jsx)(Y,{id:`memory-create-severity`,label:`Severity`,children:(0,U.jsxs)(_,{id:`memory-create-severity`,value:a.severity,onChange:e=>m(`severity`,e.target.value),children:[(0,U.jsx)(g,{value:``,children:`not set`}),G.map(e=>(0,U.jsx)(g,{value:e,children:e},e))]})}):null,p.expires?(0,U.jsx)(Y,{id:`memory-create-expires`,label:`Expires`,children:(0,U.jsx)(b,{id:`memory-create-expires`,type:`date`,value:a.expires,onChange:e=>m(`expires`,e.target.value)})}):null]}):null,(0,U.jsx)(Y,{id:`memory-create-body`,label:`Details`,children:(0,U.jsx)(B,{id:`memory-create-body`,rows:8,value:a.body,onChange:e=>m(`body`,e.target.value)})}),(0,U.jsx)(Q,{message:l})]}),(0,U.jsxs)(A,{children:[(0,U.jsx)(f,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,U.jsx)(f,{type:`button`,disabled:s||!a.title.trim(),onClick:()=>void v(),children:s?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(w,{"aria-hidden":`true`}),`Saving…`]}):`Create record`})]})]})})}function ue({record:e,statuses:t,onClose:n,onUpdated:r}){let i=q(e.collection),[a,o]=(0,H.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,H.useState)(!1),[l,u]=(0,H.useState)(``),d=(e,t)=>o(n=>({...n,[e]:t})),p=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 x.patchMemory(e.id,t,e.revision)).record),n()}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,U.jsx)(k,{open:!0,onOpenChange:e=>{e||n()},children:(0,U.jsxs)(I,{className:`sm:max-w-[520px]`,"aria-describedby":void 0,children:[(0,U.jsx)(j,{children:(0,U.jsxs)(L,{children:[`Edit `,e.id]})}),(0,U.jsxs)(`div`,{className:`-m-1 flex max-h-[65vh] flex-col gap-3 overflow-y-auto p-1`,children:[(0,U.jsx)(Y,{id:`memory-edit-title`,label:`Title`,children:(0,U.jsx)(b,{id:`memory-edit-title`,autoFocus:!0,required:!0,maxLength:120,value:a.title,onChange:e=>d(`title`,e.target.value)})}),(0,U.jsxs)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:[(0,U.jsx)(Y,{id:`memory-edit-status`,label:`Status`,children:(0,U.jsx)(_,{id:`memory-edit-status`,value:a.status,onChange:e=>d(`status`,e.target.value),children:(t.includes(a.status)?t:[a.status,...t]).map(e=>(0,U.jsx)(g,{value:e,children:e},e))})}),i.category?(0,U.jsx)(Y,{id:`memory-edit-category`,label:`Category`,children:(0,U.jsx)(b,{id:`memory-edit-category`,value:a.category,onChange:e=>d(`category`,e.target.value)})}):null,i.confidence?(0,U.jsx)(Y,{id:`memory-edit-confidence`,label:`Confidence`,children:(0,U.jsxs)(_,{id:`memory-edit-confidence`,value:a.confidence,onChange:e=>d(`confidence`,e.target.value),children:[(0,U.jsx)(g,{value:``,children:`not set`}),W.map(e=>(0,U.jsx)(g,{value:e,children:e},e))]})}):null,i.severity?(0,U.jsx)(Y,{id:`memory-edit-severity`,label:`Severity`,children:(0,U.jsxs)(_,{id:`memory-edit-severity`,value:a.severity,onChange:e=>d(`severity`,e.target.value),children:[(0,U.jsx)(g,{value:``,children:`not set`}),G.map(e=>(0,U.jsx)(g,{value:e,children:e},e))]})}):null,i.expires?(0,U.jsx)(Y,{id:`memory-edit-expires`,label:`Expires`,children:(0,U.jsx)(b,{id:`memory-edit-expires`,type:`date`,value:a.expires,onChange:e=>d(`expires`,e.target.value)})}):null,i.review_after?(0,U.jsx)(Y,{id:`memory-edit-review-after`,label:`Review after`,children:(0,U.jsx)(b,{id:`memory-edit-review-after`,type:`date`,value:a.review_after,onChange:e=>d(`review_after`,e.target.value)})}):null]}),(0,U.jsx)(Y,{id:`memory-edit-body`,label:`Details`,children:(0,U.jsx)(B,{id:`memory-edit-body`,rows:10,value:a.body,onChange:e=>d(`body`,e.target.value)})}),(0,U.jsx)(Q,{message:l})]}),(0,U.jsxs)(A,{children:[(0,U.jsx)(f,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,U.jsx)(f,{type:`button`,disabled:s||!a.title.trim(),onClick:()=>void p(),children:s?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(w,{"aria-hidden":`true`}),`Saving…`]}):`Save changes`})]})]})})}function de({record:e,mode:t,onClose:n,onUpdated:r}){let[i,a]=(0,H.useState)(``),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(``),u=async()=>{s(!0);try{r((t===`graduate`?await x.graduateMemory(e.id,i.split(`,`).map(e=>e.trim()).filter(Boolean),e.revision):await x.supersedeMemory(e.id,i.trim(),e.revision)).record),n()}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}};return(0,U.jsx)(k,{open:!0,onOpenChange:e=>{e||n()},children:(0,U.jsxs)(I,{className:`sm:max-w-[420px]`,"aria-describedby":void 0,children:[(0,U.jsx)(j,{children:(0,U.jsxs)(L,{children:[t===`graduate`?`Graduate`:`Supersede`,` `,e.id]})}),(0,U.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,U.jsx)(Y,{id:`memory-lifecycle-target`,label:t===`graduate`?`Target IDs`:`Replacement ID`,children:(0,U.jsx)(b,{id:`memory-lifecycle-target`,autoFocus:!0,placeholder:t===`graduate`?`CONV-0001, DOC-0004`:`ADR-0009`,value:i,onChange:e=>a(e.target.value)})}),(0,U.jsx)(Q,{message:c})]}),(0,U.jsxs)(A,{children:[(0,U.jsx)(f,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,U.jsx)(f,{type:`button`,disabled:o||!i.trim(),onClick:()=>void u(),children:o?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(w,{"aria-hidden":`true`}),`Saving…`]}):`Apply`})]})]})})}function fe({record:e,statuses:t,onOpenRelation:n,onOpenRecord:i,onUpdated:a,onDialogOpenChange:o}){let[l,d]=(0,H.useState)(!1),[p,m]=(0,H.useState)(``),g=l||!!p;(0,H.useEffect)(()=>{o?.(g)},[g,o]);let _=e.collection===`learnings`&&e.status!==`graduated`,v=[`learnings`,`decisions`,`conventions`].includes(e.collection),y=[[`status`,e.status,u(e.status)]];return e.category&&y.push([`category`,e.category]),e.confidence&&y.push([`confidence`,e.confidence]),e.severity&&y.push([`severity`,e.severity,h(e.severity)]),e.occurrences!=null&&y.push([`occurrences`,String(e.occurrences)]),e.expires&&y.push([`expires`,e.expires]),e.review_after&&y.push([`review after`,e.review_after]),e.started_at&&y.push([`started`,e.started_at]),e.resolved_at&&y.push([`resolved`,e.resolved_at]),e.graduated_to?.length&&y.push([`graduated to`,e.graduated_to.join(`, `)]),e.superseded_by?.length&&y.push([`superseded by`,e.superseded_by.join(`, `)]),e.owners?.length&&y.push([`owners`,e.owners.join(`, `)]),y.push([`updated`,e.updated||`—`]),(0,U.jsxs)(`aside`,{"aria-label":`Memory record`,className:`flex min-h-0 flex-col overflow-hidden border-l bg-background`,children:[(0,U.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center gap-2 border-b px-3.5`,children:[(0,U.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.id}),(0,U.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground/60`,children:`·`}),(0,U.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.collection}),(0,U.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground/60`,children:`·`}),(0,U.jsx)(`span`,{className:`font-mono text-[11px]`,style:{color:u(e.status)},children:e.status})]}),(0,U.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto p-4`,children:[(0,U.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,U.jsx)(`h2`,{className:`m-0 text-[17px] font-semibold leading-[1.3] tracking-[-0.01em] [text-wrap:pretty]`,children:e.title}),e.path?(0,U.jsx)(`span`,{className:`break-all font-mono text-[10.5px] text-muted-foreground`,children:e.path}):null]}),(0,U.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-2`,children:y.map(([e,t,n])=>(0,U.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,U.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:e}),(0,U.jsx)(`span`,{className:`text-sm`,style:n?{color:n}:void 0,children:t})]},e))}),(0,U.jsx)(X,{issues:e.issues,kind:`validation`}),(0,U.jsx)(X,{issues:e.lifecycleIssues||[],kind:`lifecycle`}),(0,U.jsx)(V,{className:`[--typeset-size:0.875rem]`,source:e.body||`No details recorded.`,onOpen:i}),(0,U.jsx)(Z,{label:`Links to`,links:e.outgoing,onOpen:n}),(0,U.jsx)(Z,{label:`Backlinks`,links:e.incoming,onOpen:n}),(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,U.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>d(!0),children:[(0,U.jsx)(c,{"aria-hidden":`true`}),`Edit`]}),_?(0,U.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>m(`graduate`),children:[(0,U.jsx)(s,{"aria-hidden":`true`}),`Graduate`]}):null,v?(0,U.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>m(`supersede`),children:[(0,U.jsx)(r,{"aria-hidden":`true`}),`Supersede`]}):null]})]}),l?(0,U.jsx)(ue,{record:e,statuses:t,onClose:()=>d(!1),onUpdated:a}):null,p?(0,U.jsx)(de,{record:e,mode:p,onClose:()=>m(``),onUpdated:a}):null]})}function $(e,t){return e.find(e=>e.id===t)?.statuses||[]}function pe({selectedId:e,onSelect:t,onOpenRecord:n,schema:r}){let[o,s]=(0,H.useState)([]),[c,l]=(0,H.useState)(``),[h,g]=(0,H.useState)(``),[_,y]=(0,H.useState)(``),[b,S]=(0,H.useState)(!0),[T,E]=(0,H.useState)(``),[O,k]=(0,H.useState)(null),[A,j]=(0,H.useState)(()=>localStorage.getItem(`workfile-memory-drawer`)===`expanded`);(0,H.useEffect)(()=>{localStorage.setItem(`workfile-memory-drawer`,A?`expanded`:`normal`)},[A]);let I=(0,H.useRef)(!1),L=(0,H.useRef)(0),R=(0,H.useCallback)(e=>{L.current=performance.now(),t(e)},[t]),[z,B]=(0,H.useState)(0);F(e=>{te(e,`/memory/`)&&B(e=>e+1)}),(0,H.useEffect)(()=>{let e=async()=>{S(!0);try{let e=await x.memory(c.trim(),{collection:h||void 0,status:_||void 0});s(e.records),E(``)}catch(e){E(e instanceof Error?e.message:String(e))}finally{S(!1)}},t=window.setTimeout(()=>void e(),c?180:0);return()=>window.clearTimeout(t)},[c,h,_,z]);let V=(0,H.useMemo)(()=>[...o].sort((e,t)=>String(t.updated||``).localeCompare(String(e.updated||``))||e.title.localeCompare(t.title)),[o]),W=(0,H.useMemo)(()=>{let e=r.collections.filter(e=>!h||e.id===h).map(e=>({schema:e,records:V.filter(t=>t.collection===e.id)})),t=new Set(r.collections.map(e=>e.id)),n=V.filter(e=>!t.has(e.collection));return n.length&&e.push({schema:{id:`other`,singular:`record`,idPrefix:`?`,statuses:[]},records:n}),e},[r.collections,V,h]),G=V.find(t=>t.id===e),q=h?$(r.collections,h):[...new Set(r.collections.flatMap(e=>e.statuses))];return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-3.5 pt-3.5`,children:[(0,U.jsxs)(N,{className:`w-full min-w-[180px] sm:w-[260px]`,children:[(0,U.jsx)(M,{children:(0,U.jsx)(a,{"aria-hidden":`true`})}),(0,U.jsx)(re,{type:`search`,"aria-label":`Search workfile memory`,placeholder:`Search decisions, incidents, learnings…`,value:c,onChange:e=>l(e.target.value)})]}),(0,U.jsx)(J,{label:`collection`,value:h,options:r.collections.map(e=>({value:e.id})),onChange:e=>{g(e),y(``)}}),(0,U.jsx)(J,{label:`status`,value:_,options:q.map(e=>({value:e,color:u(e)})),onChange:y}),(0,U.jsx)(`span`,{className:`ml-auto flex shrink-0 items-center gap-1.5 whitespace-nowrap font-mono text-[11px] text-muted-foreground`,children:b?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(w,{"aria-hidden":`true`,className:`size-3`}),`loading…`]}):K(o.length,`record`)})]}),T?(0,U.jsx)(C,{variant:`destructive`,className:`mx-3.5 mt-3 w-auto px-3 py-2`,children:(0,U.jsxs)(v,{children:[`Memory could not be loaded: `,T]})}):null,(0,U.jsx)(`div`,{className:`flex min-h-0 flex-1 gap-3 overflow-hidden p-3.5`,children:(0,U.jsx)(`div`,{className:`flex min-h-0 flex-1 gap-3 overflow-x-auto`,children:W.map(t=>(0,U.jsxs)(P,{className:`w-[272px] flex-none gap-0 overflow-hidden rounded-xl py-0 [--card-spacing:--spacing(2)]`,children:[(0,U.jsxs)(ne,{className:`flex flex-row items-center gap-2 border-b px-3 py-2`,children:[(0,U.jsx)(`span`,{className:`font-mono text-[11px] font-medium text-primary`,children:t.schema.idPrefix}),(0,U.jsx)(`span`,{className:`flex-1 text-[12.5px] font-semibold`,children:oe(t.schema.singular)}),(0,U.jsx)(D,{variant:`secondary`,className:`h-5 px-1.5 font-mono text-[11px] font-normal`,children:t.records.length}),t.schema.id===`other`?null:(0,U.jsx)(f,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`New ${t.schema.singular}`,onClick:()=>k(t.schema.id),children:(0,U.jsx)(i,{"aria-hidden":`true`})})]}),(0,U.jsxs)(ee,{className:d(`flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto p-2.5`,ae),children:[t.records.map(t=>(0,U.jsx)(ce,{record:t,selected:t.id===e,onSelect:()=>R(t.id)},t.id)),!t.records.length&&!b?(0,U.jsx)(m,{className:`gap-1 border border-dashed p-4 md:p-6`,children:(0,U.jsx)(p,{className:`font-mono text-xs`,children:`no records`})}):null]})]},t.schema.id))})}),(0,U.jsx)(ie,{open:!!G,expanded:A,label:`record`,description:`Details and lifecycle for the selected memory record.`,onOpenChange:e=>{e||t(``)},onExpandedChange:j,holdOpen:()=>I.current||performance.now()-L.current<200,children:G?(0,U.jsx)(fe,{record:G,statuses:$(r.collections,G.collection),onOpenRelation:e=>{o.some(t=>t.id===e)?R(e):n(e)},onOpenRecord:n,onUpdated:e=>s(t=>t.map(t=>t.id===e.id?e:t)),onDialogOpenChange:e=>{I.current=e}},G.id):null}),O===null?null:(0,U.jsx)(le,{schema:r,initialCollection:O,onClose:()=>k(null),onCreated:e=>{k(null),s(t=>[e,...t]),t(e.id)}})]})}export{pe as MemoryView};
import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{i as t,t as n}from"./react-Buq45Vzz.js";import{W as r,Y as i,yt as a}from"./ui-primitives-wYj92QGw.js";import{a as o,f as s,i as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h}from"./empty-BHqXimMR.js";import{U as g,a as _,x as v}from"./index-hHNShan0.js";import{t as y}from"./layout-QiuZ_k5v.js";import{t as b}from"./progress-CKc41PRw.js";var x=e(t(),1),S=n(),C=[{key:`N`,label:`Move to next`,status:`next`},{key:`D`,label:`Defer`,status:`deferred`},{key:`X`,label:`Discard`,status:`discarded`}];function w({tasks:e,repoRoot:t,repoUrl:n,onPatch:w,onOpen:T}){let[E,D]=(0,x.useState)(()=>new Set),[O,k]=(0,x.useState)(0),A=(0,x.useMemo)(()=>e.filter(e=>!E.has(e.id)),[E,e]),j=A[O]||A[0],M=e.length;(0,x.useEffect)(()=>{O>=A.length&&k(Math.max(0,A.length-1))},[O,A.length]);let N=(0,x.useCallback)(async(e,t=!0)=>{if(j){try{await w(j.id,e)}catch{return}t&&(D(e=>new Set(e).add(j.id)),k(e=>Math.min(e,Math.max(0,A.length-2))))}},[w,A.length,j]);(0,x.useEffect)(()=>{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(),k(e=>Math.min(A.length-1,e+1));else if(n===`K`||e.key===`ArrowUp`)e.preventDefault(),k(e=>Math.max(0,e-1));else if(/^[1-4]$/.test(n))e.preventDefault(),N({priority:_[Number(n)-1]},!1);else{let t=C.find(e=>e.key===n);t&&(e.preventDefault(),N({status:t.status}))}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[N,A.length]);let P=e=>n?`${n.replace(/\/+$/,``)}/blob/main/${e}`:`vscode://file${t}/${e}`;return j?(0,S.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2.5 border-b bg-card px-3.5 py-2.5`,children:[(0,S.jsx)(b,{value:M?E.size/M*100:0,className:`max-w-[340px] flex-1`}),(0,S.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:[E.size,` of `,M,` processed`]}),(0,S.jsx)(`span`,{className:`flex-1`}),(0,S.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,disabled:O===0,onClick:()=>k(e=>Math.max(0,e-1)),children:[(0,S.jsx)(g,{children:`K`}),`Previous`]}),(0,S.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground tabular-nums`,children:[O+1,` / `,A.length]}),(0,S.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,disabled:O>=A.length-1,onClick:()=>k(e=>Math.min(A.length-1,e+1)),children:[(0,S.jsx)(g,{children:`J`}),`Next`]}),(0,S.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>T(j.id),children:[(0,S.jsx)(i,{"aria-hidden":`true`}),`Open full card`]})]}),(0,S.jsxs)(`div`,{className:l(y,`px-6 py-7 sm:px-8`),children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 font-mono text-[11px] text-muted-foreground`,children:[(0,S.jsx)(`span`,{children:j.id}),(0,S.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,S.jsx)(`span`,{style:{color:s(j.status)},children:j.status}),(0,S.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,S.jsx)(`span`,{children:j.area}),(0,S.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,S.jsx)(`span`,{children:j.type})]}),(0,S.jsx)(`h2`,{className:`mt-3 mb-1 text-[26px] leading-[1.2] font-semibold tracking-tight [text-wrap:pretty]`,children:j.title}),j.file?(0,S.jsx)(`a`,{className:`font-mono text-[11px] text-muted-foreground/70 underline underline-offset-[3px]`,href:P(j.file),target:n?`_blank`:void 0,rel:n?`noreferrer`:void 0,children:j.file}):null,j.source?(0,S.jsxs)(`span`,{className:`mt-[3px] block font-mono text-[11px] text-muted-foreground/70`,children:[`source`,` `,(0,S.jsx)(`a`,{className:`font-mono underline underline-offset-[3px]`,href:P(j.source),target:n?`_blank`:void 0,rel:n?`noreferrer`:void 0,children:j.source})]}):null,(0,S.jsx)(`div`,{className:`mt-[22px]`,children:(0,S.jsx)(v,{source:j.body,onOpen:T})}),(0,S.jsxs)(`div`,{className:`mt-[30px] flex flex-wrap gap-2 border-t pt-[18px]`,children:[_.map((e,t)=>(0,S.jsxs)(f,{type:`button`,variant:`outline`,"aria-pressed":j.priority===e,style:j.priority===e?{borderColor:m(e)}:void 0,onClick:()=>void N({priority:e},!1),children:[(0,S.jsx)(g,{children:t+1}),(0,S.jsx)(`span`,{style:{color:m(e)},children:e})]},e)),C.map(e=>(0,S.jsxs)(f,{type:`button`,variant:`outline`,onClick:()=>void N({status:e.status}),children:[(0,S.jsx)(g,{children:e.key}),(0,S.jsx)(`span`,{style:{color:s(e.status)},children:e.label})]},e.key))]}),(0,S.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,S.jsxs)(h,{className:`gap-3 p-10`,children:[(0,S.jsxs)(c,{children:[(0,S.jsx)(o,{children:(0,S.jsx)(a,{"aria-hidden":`true`,size:20,style:{color:s(`done`)}})}),(0,S.jsx)(d,{className:`text-sm`,children:`Queue clear`}),(0,S.jsxs)(p,{className:`text-[12.5px]`,children:[`You processed `,E.size.toLocaleString(),` cards.`]})]}),(0,S.jsx)(u,{children:(0,S.jsxs)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{D(new Set),k(0)},children:[(0,S.jsx)(r,{"aria-hidden":`true`}),`Start again`]})})]})}export{w as TriageView};

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