From 6ae883a665332d04b63f648b70add6b37d991d20 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 19 Sep 2026 02:26:23 +1000 Subject: [PATCH] fix(webui): remount the task detail page when the task id changes Code review on this PR: navigating from one /tasks/:id route to another keeps the previous task's data. The router renders pages with Preact's own render() into one long-lived outlet (main.jsx show()), and taskDetailPage returned RunDetail with no key, so the same element was diffed in place and never remounted. Every task-scoped read lives in a useEffect with empty deps and the open tab and pinned attempt are useState initialisers, so all of them ran once for the first task and the new task was rendered against another task's reads: run history, events, open tab, pinned attempt, and the log/change/debug caches. RunDetail's own comment already asserted "the route remounts it when that changes" -- the remount it relied on never happened. Keying by id makes it happen. Keying rather than resetting is deliberate: RunDetail holds 14 pieces of task-scoped state, and a hand-rolled reset must name every one and silently regresses when a fifteenth is added. A remount is exhaustive by construction. Preact 10.29.8 wraps render() in a Fragment and diffs children by key, so a changed root key unmounts and mounts fresh; both regression tests were shown to fail without the key. Tests: component-level (two task ids rendered into one shared host, mirroring the router's outlet) and router-level through the real show() path. --- ui/dist/assets/index.js | 2 +- ui/src/tasks/task-detail.jsx | 10 +++++- ui/test/main-routing.test.js | 19 +++++++++++ ui/test/task-detail.test.js | 65 ++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 2 deletions(-) diff --git a/ui/dist/assets/index.js b/ui/dist/assets/index.js index afe30ccb6..c5e4ca6e4 100644 --- a/ui/dist/assets/index.js +++ b/ui/dist/assets/index.js @@ -6,7 +6,7 @@ stroke-width="12" stroke-linecap="round" stroke-dasharray="${s}" stroke-dashoffset="${s*(1-r/100)}" - class="gauge-value"/>`,W(`div.gauge-wrap`,l,W(`div.gauge-center`,W(`div.gauge-pct`,`${Math.round(r)}%`),W(`div.gauge-label`,t)))}function $e(e){let t=e.reduce((e,t)=>e+(t.value||0),0)||1;return W(`div`,W(`div.segbar`,...e.filter(e=>e.value>0).map(e=>W(`span`,{class:`segbar-part segbar-${e.kind||`idle`}`,style:`width:${(e.value/t*100).toFixed(1)}%`,title:`${e.label}: ${e.value}`}))),W(`div.segbar-legend`,...e.map(e=>W(`span.segbar-key`,W(`span`,{class:`segbar-dot segbar-${e.kind||`idle`}`}),e.label))))}var et=0;Array.isArray;function Z(e,n,r,i,a,o){n||={};var s,c,l=n;if(`ref`in l)for(c in l={},n)c==`ref`?s=n[c]:l[c]=n[c];var u={type:e,props:l,key:r,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--et,__i:-1,__u:0,__source:a,__self:o};if(typeof e==`function`&&(s=e.defaultProps))for(c in s)l[c]===void 0&&(l[c]=s[c]);return t.vnode&&t.vnode(u),u}function Q({text:e,kind:t=`idle`}){return Z(`span`,{className:`pill pill-${t}`,children:e})}var tt=`archie.setup-complete.dismissed.v1`;function nt(e,t=globalThis.localStorage){if(!e?.steps?.length)return{kind:`omit`,remaining:[]};let n=e.steps.filter(e=>!e.done);return n.length?(t?.removeItem?.(tt),{kind:`incomplete`,remaining:n}):t?.getItem?.(`archie.setup-complete.dismissed.v1`)===`1`?{kind:`dismissed`,remaining:[]}:{kind:`complete`,remaining:[]}}function rt(e=globalThis.localStorage){e?.setItem?.(tt,`1`)}var it=new Set([`waiting_human`,`parked`]);function at(e=[]){let t=e.filter(e=>it.has(e.status)),n=e.filter(e=>e.status===`running`);return{attention:{count:t.length,href:t.length===1?`#/tasks?task=${encodeURIComponent(t[0].id)}`:`#/tasks?status=needs_you`},running:{count:n.length,href:`#/tasks?status=running`}}}function ot({node:e}){let t=X();return Y(()=>{t.current&&e&&t.current.replaceChildren(e)},[e]),Z(`div`,{ref:t,style:{display:`contents`}})}function st(e){return Z(ot,{node:Xe(e)})}function ct(e){return Z(ot,{node:Qe(e)})}function lt({segments:e}){return Z(ot,{node:$e(e)})}function ut({name:e,opts:t}){return Z(ot,{node:G(e,t)})}function dt({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function ft(e,t){return Number(e.task_id)>0?Number(e.task_id):!e.repo||!e.issue?0:Number(t.get(`${e.repo}#${e.issue}`))||0}function pt(){let e=new Date().getHours();return e<5?`Still up?`:e<12?`Good morning`:e<18?`Good afternoon`:`Good evening`}function mt(e){if(e.length<4)return null;let t=Math.floor(e.length/2),n=e.slice(0,t).reduce((e,t)=>e+t,0),r=e.slice(t).reduce((e,t)=>e+t,0);return n?(r-n)/n*100:null}function ht(){let[e,t]=J([]),[n,r]=J(`connecting`),[i,a]=J(`idle`),[o,s]=J(new Map),[c,l]=J(null),[u,d]=J(null),[f,p]=J(null),[m,h]=J(null),[g,_]=J(null),[,v]=J(!1),y=async()=>{_(null);try{let[e,t,n,r]=await Promise.all([U.summary(),U.setup().catch(()=>null),U.workflows().catch(()=>null),U.tasks().catch(()=>[])]),i=new Map;for(let e of r)e.owner&&e.repo&&e.issue_number&&i.set(`${e.owner}/${e.repo}#${e.issue_number}`,e.id);s(i),l(e),d(t),p(n),h(r)}catch(e){_(String(e.message||e))}};Y(()=>(y(),ue(e=>{t(t=>{let n=[e,...t];return n.splice(50),n})},e=>{r(e),a(e===`live`?`ok`:`warn`)})),[]);let b=()=>{rt(),v(e=>!e)},x=u?.operator?`${pt()}, ${u.operator}`:pt(),C=null;if(g)C=Z(`button`,{className:`btn btn-primary`,onClick:y,children:[Z(ut,{name:`refresh`,opts:{size:15}}),` Retry`]});else if(m!==null){let e=at(m),t=e.attention.count,n=e.running.count;C=Z(S,{children:[t>0&&Z(`a`,{className:`btn btn-attention`,href:e.attention.href,children:[Z(ut,{name:`tasks`,opts:{size:15}}),` `,t,` need`,t===1?`s`:``,` you`]}),n>0&&Z(`a`,{className:`btn`,href:e.running.href,children:[Z(ut,{name:`workflows`,opts:{size:15}}),` `,n,` running`]}),Z(`a`,{className:`btn`,href:`#/logs`,children:[Z(ut,{name:`logs`,opts:{size:15}}),` Logs`]}),Z(`button`,{className:`btn btn-primary`,onClick:y,children:[Z(ut,{name:`refresh`,opts:{size:15}}),` Refresh`]})]})}let w=null;if(g)w=Z(`div`,{className:`card`,children:Z(dt,{title:`Cannot reach archied`,detail:g})});else if(c){let e=c?.statuses||{},t=(e.merged||0)+(e.pr_open||0),n=(e.parked||0)+(e.waiting_human||0),r=Object.values(e).reduce((e,t)=>e+t,0),i=c?.tokens_by_day||[];w=Z(S,{children:[Z(st,{label:`Working now`,value:e.running||0,compare:`${e.queued||0} waiting to start`,series:i.map(e=>e.tokens||0)}),Z(st,{label:`Needs you`,value:n,compare:n?`Parked or awaiting a reply`:`Nothing is blocked`,goodDirection:`down`}),Z(st,{label:`Delivered`,value:t,compare:r?`${Math.round(t/r*100)}% of all tasks`:`No tasks yet`}),Z(st,{label:`Tokens used`,value:De(i.reduce((e,t)=>e+(t.tokens||0),0)),compare:`Across ${i.length||0} days`,trend:mt(i.map(e=>e.tokens||0)),goodDirection:`down`,series:i.map(e=>e.tokens||0)})]})}let T=null,E=nt(u),D=E.kind===`omit`||E.kind===`dismissed`;if(!D){let e=E.remaining;if(e.length){let t=Math.round((u.steps.length-e.length)/u.steps.length*100);T=Z(`div`,{className:`card setup`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Finish setting up`}),Z(`p`,{className:`card-sub`,children:`Archie needs these before it can work on its own.`})]}),Z(`span`,{className:`setup-pct`,children:[t,`%`]})]}),Z(`div`,{className:`setup-bar`,children:Z(`div`,{className:`setup-bar-fill`,style:{width:`${t}%`}})}),Z(`ul`,{className:`setup-list`,children:u.steps.map((e,t)=>Z(`li`,{className:`setup-step ${e.done?`done`:``}`,children:[Z(`span`,{className:`setup-check`,children:e.done?Z(ut,{name:`check`,opts:{size:12}}):``}),Z(`div`,{children:[Z(`div`,{className:`setup-step-title`,children:e.title}),e.detail&&Z(`div`,{className:`setup-step-detail`,children:e.detail})]})]},t))})]})}else T=Z(`div`,{className:`card setup setup-done`,children:Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Setup complete`}),Z(`p`,{className:`card-sub`,children:`Archie is configured and ready to work.`})]}),Z(`div`,{className:`setup-complete-actions`,children:[Z(`span`,{className:`setup-pct`,children:Z(ut,{name:`check`,opts:{size:16}})}),Z(`button`,{className:`icon-btn setup-dismiss`,type:`button`,title:`Dismiss setup complete`,"aria-label":`Dismiss setup complete`,onClick:b,children:`×`})]})]})})}let O=null;if(c){let e=f?.workflows||[],t=e.reduce((e,t)=>e+(t.runs||0),0),n=e.reduce((e,t)=>e+(t.merged||0)+(t.pr_open||0),0),r=e.reduce((e,t)=>e+(t.parked||0),0);if(!t)O=Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:Z(`h2`,{className:`card-title`,children:`Gate pulse`})}),Z(dt,{title:`No completed runs yet`,detail:`Once Archie finishes a task, its gate pass rate appears here.`})]});else{let i=n/t*100;O=Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Gate pulse`}),Z(`p`,{className:`card-sub`,children:`Work that passed its quality gates`})]})}),Z(ct,{value:i,label:`pass rate`}),Z(`ul`,{className:`pulse-list`,children:[e.slice(0,3).map((e,t)=>Z(`li`,{className:`pulse-item`,children:[Z(`span`,{className:`pulse-name`,children:e.workflow||`workflow`}),Z(Q,{text:`${e.merged||0}/${e.runs||0}`,kind:(e.merged||0)===(e.runs||0)?`ok`:(e.parked||0)>0?`warn`:`info`})]},t)),r>0&&Z(`li`,{className:`pulse-item`,children:[Z(`span`,{className:`pulse-name`,children:`Parked, awaiting you`}),Z(Q,{text:String(r),kind:`warn`})]})]})]})}}let k=null;if(c){let e=c?.tokens_by_day||[],t=e.reduce((e,t)=>e+(t.tokens||0),0);if(!e.length)k=Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:Z(`h2`,{className:`card-title`,children:`Token outlook`})}),Z(dt,{title:`Nothing spent yet`,detail:`Usage appears here once Archie runs its first task.`})]});else{let n=t/e.length,r=Math.round(n*30),i=e.slice(-7).reduce((e,t)=>e+(t.tokens||0),0);k=Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Token outlook`}),Z(`p`,{className:`card-sub`,children:`Next 30 days at the current rate`})]})}),Z(`div`,{className:`forecast-value`,children:De(r)}),Z(`div`,{className:`forecast-note`,children:[`Based on `,De(Math.round(n)),` per day over `,e.length,` days`]}),Z(lt,{segments:[{label:`Last 7 days (${De(i)})`,value:i,kind:`info`},{label:`Earlier (${De(t-i)})`,value:Math.max(t-i,0),kind:`idle`}]})]})}}return Z(S,{children:[Z(`div`,{className:`hero`,children:[Z(`div`,{children:[Z(`h1`,{className:`hero-title`,children:x}),Z(`p`,{className:`hero-sub`,children:`Your agent's control room — what it is working on, what needs you, and what it is spending.`})]}),Z(`div`,{className:`hero-actions`,children:Z(`div`,{className:`hero-actions-inner`,children:C})})]}),Z(`div`,{className:`dash-section`,children:[Z(`div`,{className:`dash-section-head`,children:Z(`h2`,{className:`dash-section-title`,children:`Health`})}),Z(`div`,{className:`dash-top ${D?`dash-top-standalone`:``}`,children:[Z(`div`,{children:T}),Z(`div`,{children:O})]})]}),Z(`div`,{className:`dash-section`,children:[Z(`div`,{className:`dash-section-head`,children:[Z(`h2`,{className:`dash-section-title`,children:`Throughput`}),Z(`span`,{className:`dash-section-note`,children:`Across all repositories`})]}),Z(`div`,{className:`grid grid-4`,children:w})]}),Z(`div`,{className:`dash-section`,children:[Z(`div`,{className:`dash-section-head`,children:Z(`h2`,{className:`dash-section-title`,children:`Right now`})}),Z(`div`,{className:`dash-split`,children:[Z(`div`,{children:k}),Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Live activity`}),Z(`p`,{className:`card-sub`,children:`Last 50, newest first`})]}),Z(Q,{text:n,kind:i})]}),Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Event`}),Z(`th`,{children:`Task`}),Z(`th`,{children:`Detail`}),Z(`th`,{children:`When`})]})}),Z(`tbody`,{children:e.length?e.map((e,t)=>{let n=ft(e,o),r=n>0,i=()=>{r&&(location.hash=`#/tasks?task=${encodeURIComponent(n)}`)};return Z(`tr`,{className:r?`activity-row`:``,role:r?`link`:void 0,tabIndex:r?`0`:void 0,title:r?`Open task details`:void 0,onClick:r?i:void 0,onKeyDown:r?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),i())}:void 0,children:[Z(`td`,{className:`strong`,children:Z(`span`,{children:e.kind||e.type||`event`})}),Z(`td`,{className:`mono`,children:r?`#${n}`:`—`}),Z(`td`,{children:e.detail||e.message||``}),Z(`td`,{children:Ee(e.at||Date.now())})]},t)}):Z(`tr`,{children:Z(`td`,{colSpan:`4`,children:Z(dt,{title:`Waiting for activity`,detail:`Events appear here as Archie works.`})})})})]})})]})]})]})]})}function gt(){return Z(ht,{})}function _t(e,t){let n=e.title||`untitled task`;return{"aria-expanded":String(t),"aria-controls":`task-timeline-${e.id}`,"aria-label":`${t?`Collapse`:`Expand`} timeline for ${n}`}}var vt=Se(),yt=new Set([`needs_you`,...xe()]);function bt(e){let t=e?.get?.(`status`)||``;return yt.has(t)?t:``}function xt(e,t){return t?t===`needs_you`?vt.has(e.status):e.status===t:!0}function St(e){return String(e||`event`).replaceAll(`_`,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Ct(e){let t=Number(e);if(!Number.isFinite(t)||t<0)return``;if(t<1e3)return`${Math.round(t)} ms`;let n=t/1e3;if(n<60)return`${n.toFixed(+(n<10))} s`;let r=Math.round(n),i=Math.floor(r/60),a=r%60;if(i<60)return a===0?`${i} min`:`${i} min ${a} s`;let o=Math.floor(i/60),s=i-o*60;return s===0?`${o} h`:`${o} h ${s} min`}function wt(e){let t=Number(e);return!Number.isFinite(t)||t<=0?``:t.toLocaleString(`en-US`)}function Tt(e={}){let t=e.data||{},n=e.stage||`unknown stage`,r=e.workflow?`${e.workflow} workflow`:``;if(e.kind===`stage_start`)return{title:`Started stage: ${n}`,detail:r};if(e.kind===`stage_finish`){let e=Ct(t.duration_ms),i=[r,e&&`ran for ${e}`].filter(Boolean).join(` · `);return{title:t.interrupted?`Stage interrupted: ${n}`:t.error?`Stage failed: ${n}`:`Finished stage: ${n}`,detail:[i,t.error].filter(Boolean).join(` — `)}}if(e.kind===`task_retried`){let n=Number(t.retry_count);return{title:Number.isFinite(n)&&n>0?`Retry ${n}`:`Retry requested`,detail:[t.previous_stage&&`after ${t.previous_stage}`,t.previous_reason].filter(Boolean).join(`: `)||e.detail||``}}if(e.kind===`agent_finish`){let r=wt(t.iterations),i=wt(t.tokens),a=Number(t.cached_tokens)||0,o=wt((Number(t.prompt_tokens)||0)-a),s=wt(t.completion_tokens),c=wt(t.cached_tokens),l=[r&&`${r} iterations`,i&&`${i} tokens`,o&&`${o} fresh prompt`,s&&`${s} completion`,c&&`${c} cached`,t.model].filter(Boolean);return{title:`Agent ${t.status||`finished`}: ${n}`,detail:l.join(` · `)||e.detail||``}}if(e.kind===`config_captured`)return{title:`Configuration captured`,detail:`The effective task-runtime configuration for this run.`};if(e.kind===`changes_captured`){let e=Number(t.totals?.files);return{title:`Change capture recorded`,detail:[Number.isFinite(e)&&e>0?`${e} file${e===1?``:`s`} changed`:``,t.captured_after?`captured after ${t.captured_after}`:``].filter(Boolean).join(` · `)}}return{title:St(e.kind||e.type),detail:e.detail||``}}var Et=[{value:``,label:`All levels`},{value:`ERROR`,label:`Errors`},{value:`WARN,ERROR`,label:`Warnings and errors`},{value:`INFO,WARN,ERROR`,label:`Info and above`},{value:`DEBUG`,label:`Debug only`}];function Dt(e){switch((e||``).toUpperCase()){case`ERROR`:return`danger`;case`WARN`:return`warn`;case`DEBUG`:return`idle`;default:return`info`}}function Ot(e){let t=e.fields||{};return W(`div.log-row.log-${Dt(e.level)}`,W(`span.log-time.mono`,At(e.time)),W(`span.log-level`,(e.level||`info`).toUpperCase()),W(`span.log-body`,W(`span.log-msg`,e.message||e.msg||``),...Object.entries(t).map(([e,t])=>W(`span.log-field`,W(`span.log-field-key`,e),String(kt(t))))))}function kt(e){return e==null?``:typeof e==`object`?JSON.stringify(e):e}function At(e){let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?`--:--:--`:t.toTimeString().slice(0,8)}function jt({entry:e}){let t=X(null);return Y(()=>{t.current&&t.current.replaceChildren(Ot(e))},[e]),Z(`div`,{ref:t,style:{display:`contents`}})}function Mt(e,t){return`/api/tasks/${e}/logs/download`+(t==null?``:`?attempt=${t}`)}var Nt={level:``,stage:``};function Pt(e,t,n=Nt){let r=n||Nt;return[e,Number(t)||0,r.level||``,r.stage||``].join(`|`)}function Ft({filters:e,onFilterChange:t,stages:n,attempt:r}){let i=n=>t?.({...e,...n}),a=Number(r)||0;return Z(`div`,{className:`log-filters task-log-filters`,children:[Z(`span`,{className:`task-log-attempt`,children:a>0?`Attempt ${a}`:`Current attempt`}),t?Z(S,{children:[Z(`label`,{className:`task-log-filter`,children:[Z(`span`,{className:`task-log-filter-label`,children:`Level`}),Z(`select`,{className:`task-filter`,value:e.level,"aria-label":`Filter log entries by level`,onChange:e=>i({level:e.target.value}),children:Et.map(e=>Z(`option`,{value:e.value,children:e.label},e.value))})]}),Z(`label`,{className:`task-log-filter`,children:[Z(`span`,{className:`task-log-filter-label`,children:`Stage`}),Z(`select`,{className:`task-filter`,value:e.stage,"aria-label":`Filter log entries by stage`,onChange:e=>i({stage:e.target.value}),children:[Z(`option`,{value:``,children:`All stages`}),(n||[]).map(e=>Z(`option`,{value:e,children:e},e))]})]}),e.stage?Z(`p`,{className:`task-log-filter-note`,children:`A stage filter matches only log lines that record a stage. Agent and tool output carries none, so it is not shown while this filter is set.`}):null,!e.stage&&!(n||[]).length?Z(`p`,{className:`task-log-filter-note`,children:`This attempt recorded no stage names, so the stage filter has nothing to match.`}):null]}):null]})}function It({text:e}){return Z(`p`,{className:`visually-hidden`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:e})}function Lt({state:e,onRetry:t,taskId:n,attempt:r,filters:i=Nt,onFilterChange:a,stages:o=[]}){let s=Number(r)||Number(e?.attempt)||0,c,l;if(e===void 0)c=`Loading this attempt's log`,l=Z(`div`,{className:`task-log-loading`,children:`Loading attempt log…`});else if(e===null)c=`This attempt's log could not be loaded`,l=Z(`div`,{className:`task-log-error`,children:[Z(`div`,{className:`task-timeline-detail`,children:`Could not load this attempt's log.`}),Z(`button`,{className:`btn`,onClick:t,children:`Retry`})]});else if(e.found===!1&&!e.disabled)c=`No log recorded for this attempt`,l=Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`No log recorded for this attempt`}),Z(`div`,{children:`This attempt produced no output, or it has not started writing yet.`})]});else if(e.disabled)c=`This dashboard cannot read task logs`,l=Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`No persisted log for this attempt`}),Z(`div`,{children:`This dashboard cannot read task logs. The service that owns the log files is not reporting a log reader.`})]});else{let t=e.entries||[],r=n==null?null:Mt(n,s||null),i=r?Z(`a`,{className:`btn btn-small task-log-download`,href:r,download:!0,children:`Download log`}):null;t.length?(c=`${t.length} log entr${t.length===1?`y`:`ies`} shown`,l=Z(S,{children:[Z(`div`,{className:`log-list task-log-list`,children:t.map((e,t)=>Z(jt,{entry:e},t))}),i]})):(c=`This attempt's log has no entries matching the current filter`,l=Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`Nothing recorded`}),Z(`div`,{children:`This attempt's log file has no entries matching the current filter.`}),i]}))}return Z(S,{children:[Z(Ft,{filters:i,onFilterChange:a,stages:o,attempt:s}),Z(It,{text:c}),l]})}function Rt(){return typeof window<`u`&&window.matchMedia?.(`(prefers-reduced-motion: reduce)`)?.matches===!0}function zt(){return Rt()?`auto`:`smooth`}function Bt(e){let t=X(null);return Y(()=>{t.current&&t.current.replaceChildren(Xe(e))},[e]),Z(`div`,{ref:t,style:{display:`contents`}})}function Vt({kind:e,message:t}){return e===`session-expired`?Z(`span`,{className:`task-action-error task-action-error-session`,children:[`Your session has expired.`,` `,Z(`button`,{className:`button btn btn-small`,type:`button`,onClick:()=>window.location.reload(),children:`Reload to sign in`})]}):e===`refused`?Z(`span`,{className:`task-action-error task-action-error-refused`,children:[t,` — you can't do that.`]}):Z(`span`,{className:`task-action-error task-action-error-broken`,children:[t,` — try again, or check the daemon.`]})}function Ht({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Ut({taskId:e,attempt:t,state:n,onLoad:r,onRetry:i}){let a=X(r);return a.current=r,Y(()=>{n===void 0&&a.current()},[n]),Z(Lt,{state:n,taskId:e,attempt:t,onRetry:i})}function Wt({query:e}){let[t,n]=J(null),[r,i]=J(null),[a,o]=J(()=>bt(e)),[s,c]=J(``),l=Number(e.get(`task`)),u=Number.isFinite(l)&&l>0?l:null,[d,f]=J(u),[p,m]=J(u!==null),[h,g]=J(new Map),[_,v]=J(new Map),y=X(new Set),[b,x]=J(new Set),[C,w]=J(new Map),[T,E]=J(new Set),D=async()=>{try{i(null);let e=await U.tasks();return n(e),d&&e.some(e=>String(e.id)===String(d))&&(h.has(d)||O(d)),e}catch(e){return i(String(e.message||e)),n(null),null}};Y(()=>{D()},[]);let O=async e=>{try{let t=await U.task(e);g(n=>new Map(n).set(e,t||[]))}catch{g(t=>new Map(t).set(e,null))}},k=async(e,t,{force:n=!1}={})=>{let r=Pt(e,t);if(!(y.current.has(r)&&!n)){y.current.add(r),n&&v(e=>{let t=new Map(e);return t.delete(r),t});try{let n=await U.taskLogs(e,{attempt:t||void 0,limit:500});v(e=>new Map(e).set(r,n))}catch{v(e=>new Map(e).set(r,null))}}},A=e=>{g(t=>{let n=new Map(t);return n.delete(e),n})},j=async(e,t)=>{w(t=>{let n=new Map(t);return n.delete(e),n}),E(t=>new Set(t).add(e));try{await U.taskAction(e,t),E(t=>{let n=new Set(t);return n.delete(e),n}),t===`archive`&&f(null),A(e);let n=await D();Array.isArray(n)&&n.find(t=>String(t.id)===String(e))&&d===e&&O(e)}catch(t){E(t=>{let n=new Set(t);return n.delete(e),n}),w(n=>new Map(n).set(e,ce(t)))}};Y(()=>{p&&d&&t&&(m(!1),requestAnimationFrame(()=>{let e=document.getElementById(`task-row-${d}`);e&&(e.focus({preventScroll:!0}),e.scrollIntoView?.({block:`center`,behavior:zt()}))}))},[p,d,t]);let M=(e,t)=>{t&&t.stopPropagation();let n=d!==e;f(n?e:null),n&&O(e)},N=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=()=>{if(!t)return null;let e=t.length,n={};for(let e of t)n[e.status]=(n[e.status]||0)+1;let r=n.running||0,i=(n.waiting_human||0)+(n.parked||0),a=(n.merged||0)+(n.pr_open||0);return Z(`div`,{className:`grid grid-4 task-summary`,children:[Z(Bt,{label:`Total tasks`,value:e,compare:e?`Everything archied has ever picked up`:`No tasks yet`}),Z(Bt,{label:`Working now`,value:r,compare:e?`${r} of ${e} in progress`:`Nothing running`}),Z(Bt,{label:`Needs you`,value:i,compare:i?`Parked or awaiting a reply`:`Nothing is blocked`,goodDirection:`down`}),Z(Bt,{label:`Delivered`,value:a,compare:e?`${Math.round(a/e*100)}% of all tasks`:`No tasks yet`})]})},F=e=>{let t=C.get(e.id),n=t?Vt(t):null,r=T.has(e.id),i=e=>e===`quiet`?`btn-quiet`:e===`danger`?`btn-danger`:``,a=(e.actions||[]).map(t=>{let n=Ce(t);if(!n)return null;let a=e.title||`this task`,o=n.confirm?n.confirm.replaceAll(`{title}`,a):void 0,s=[`button`,`btn`,`btn-small`,i(n.kind)].filter(Boolean).join(` `);if(n.kind===`link`){if(t===`open_pr`)return I(e,`pull_request`,e.pr_number,n.label);if(t===`open_issue`)return I(e,`issue`,e.issue_number,n.label)}return Z(`button`,{className:s,type:`button`,disabled:r,onClick:n=>{n.stopPropagation(),!(o&&!window.confirm(o))&&j(e.id,t)},children:n.label},t)}).filter(Boolean);return!a.length&&!n?`—`:Z(`div`,{className:`task-actions`,children:[n,a]})},I=(e,t,n,r)=>{let i=t===`issue`?e.issue_url:e.pr_url;return!i||!n||t===`issue`&&e.source===`chat`?Z(`button`,{className:`btn btn-small`,type:`button`,disabled:!0,title:`${r} is unavailable`,children:r}):Z(`a`,{className:`btn btn-small`,href:i,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:r})},ee=e=>{let t=e.repo_url;return t?Z(`a`,{className:`task-source-link`,href:t,target:`_blank`,rel:`noreferrer`,title:`Open ${e.owner}/${e.repo} on the forge`,onClick:e=>e.stopPropagation(),children:[e.owner,`/`,e.repo]}):null},te=e=>{let t=e.issue_url;return e.source===`chat`||!t||!e.issue_number?null:Z(`a`,{className:`task-source-link`,href:t,target:`_blank`,rel:`noreferrer`,title:`Open issue #${e.issue_number} on the forge`,onClick:e=>e.stopPropagation(),children:[`#`,e.issue_number]})},L=e=>{let t=Pt(e.id,e.attempt),n=h.get(e.id),r=b.has(e.id);return Z(`tr`,{className:`task-timeline-row`,id:`task-timeline-${e.id}`,children:Z(`td`,{colSpan:8,children:[Z(`div`,{className:`task-detail-actions`,children:[Z(`div`,{className:`task-decision-title`,children:`Available actions`}),F(e)]}),e.status===`waiting_human`&&e.plan&&Z(`div`,{className:`task-decision`,children:[Z(`div`,{className:`task-decision-title`,children:`Decision required`}),Z(`div`,{className:`task-decision-plan`,children:e.plan})]}),e.status===`parked`&&e.park_reason&&Z(`div`,{className:`task-decision`,children:[Z(`div`,{className:`task-decision-title`,children:`Park reason`}),Z(`div`,{className:`task-decision-plan`,children:e.park_reason})]}),n===void 0?Z(`div`,{className:`task-timeline-loading`,children:`Loading timeline…`}):n===null?Z(`div`,{className:`task-timeline-error`,children:[Z(`div`,{className:`task-timeline-title`,children:`Could not load timeline`}),Z(`div`,{className:`task-timeline-detail`,children:`archied did not answer for this task's events. It may be restarting — retry, or check the daemon.`}),Z(`button`,{className:`btn`,onClick:()=>O(e.id),children:`Retry`})]}):n.length?Z(`ul`,{className:`task-timeline`,children:n.map((e,t)=>{let n=Tt(e);return Z(`li`,{className:`task-timeline-entry`,children:[Z(`span`,{className:`task-timeline-dot`}),Z(`div`,{children:[Z(`div`,{className:`task-timeline-kind`,children:n.title}),n.detail&&Z(`div`,{className:`task-timeline-detail`,children:n.detail}),Z(`div`,{className:`task-timeline-when`,children:Ee(e.at)})]})]},t)})}):Z(Ht,{title:`No events yet`,detail:`This task has not recorded any transitions.`}),Z(`div`,{className:`task-logs-section`,children:[Z(`div`,{className:`task-decision-title`,children:[`Attempt log`,Z(`button`,{className:`btn btn-small`,onClick:()=>N(e.id),style:{marginLeft:`10px`},children:r?`Hide`:`Show`})]}),r&&Z(Ut,{taskId:e.id,attempt:e.attempt,state:_.has(t)?_.get(t):void 0,onLoad:()=>k(e.id,e.attempt),onRetry:()=>k(e.id,e.attempt,{force:!0})})]})]})})};return Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Tasks`}),Z(`p`,{className:`page-sub`,children:`Every issue archied has picked up, and where it stands.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:D,children:`Refresh`})})]}),r?Z(`div`,{className:`grid grid-4 task-summary`,children:Z(`div`,{className:`card`,children:Z(Ht,{title:`Cannot reach archied`,detail:r})})}):P(),Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`All tasks`}),Z(`p`,{className:`card-sub`,children:`Click a row for its timeline`})]}),Z(`div`,{className:`task-filters`,children:[Z(`input`,{className:`task-search`,type:`search`,placeholder:`Search by title or repo…`,value:s,onInput:e=>c(e.target.value.trim().toLowerCase())}),Z(`select`,{className:`task-filter`,value:a,onChange:e=>o(e.target.value),children:[Z(`option`,{value:``,children:`All statuses`}),Z(`option`,{value:`needs_you`,children:`Needs you`}),xe().map(e=>Z(`option`,{value:e,children:ye(e)},e))]})]})]}),Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[`Repo`,`Issue`,`Title`,`Status`,`Workflow`,`Stage`,`Last activity`,`Action`].map(e=>Z(`th`,{children:e},e))})}),Z(`tbody`,{children:(()=>{if(r)return Z(`tr`,{children:Z(`td`,{colSpan:8,children:Z(Ht,{title:`Cannot reach archied`,detail:r})})});if(!t)return Z(`tr`,{children:Z(`td`,{colSpan:8,children:Z(`div`,{className:`task-timeline-loading`,children:`Loading tasks...`})})});if(!t.length)return Z(`tr`,{children:Z(`td`,{colSpan:8,children:Z(Ht,{title:`No tasks yet`,detail:`Tasks appear here once archied picks up an issue to work.`})})});let e=t.filter(e=>xt(e,a)?!s||`${e.title} ${e.repo}`.toLowerCase().includes(s):!1);return e.length?e.map(e=>{let t=d===e.id,n=`task-timeline-${e.id}`;return Z(S,{children:[Z(`tr`,{className:`task-row`,id:`task-row-${e.id}`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),M(e.id,t))},onClick:t=>M(e.id,t),..._t(e,t),children:[Z(`td`,{className:`mono`,"data-label":`Repository`,children:[Z(`button`,{className:`task-expand`,type:`button`,"aria-expanded":String(t),"aria-controls":n,"aria-label":`${t?`Collapse`:`Expand`} timeline for ${e.title||`untitled task`}`,onClick:t=>M(e.id,t),children:t?`−`:`+`}),ee(e)??`${e.owner}/${e.repo}`]}),Z(`td`,{className:`mono`,"data-label":`Issue`,children:te(e)??`#${e.issue_number}`}),Z(`td`,{className:`strong`,"data-label":`Title`,children:Z(`a`,{className:`task-detail-link`,href:`#/tasks/${e.id}`,title:`Open the run detail for this task`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:e.title||`(untitled)`})}),Z(`td`,{"data-label":`Status`,children:Z(Q,{text:ye(e.status),kind:be(e.status)})}),Z(`td`,{"data-label":`Workflow`,children:e.workflow||`—`}),Z(`td`,{"data-label":`Stage`,children:e.stage||`—`}),Z(`td`,{"data-label":`Last activity`,title:e.created_at?`Created ${Ee(e.created_at)}`:``,children:Ee(e.updated_at)}),Z(`td`,{"data-label":`Actions`,children:F(e)})]}),t&&L(e)]},e.id)}):Z(`tr`,{children:Z(`td`,{colSpan:8,children:Z(Ht,{title:`No matching tasks`,detail:`Try a different search or status filter.`})})})})()})]})})]})]})}function Gt(e){return Z(Wt,{query:e})}function Kt(e,t){return`${e}-tab-${t}`}function qt(e,t){return`${e}-panel-${t}`}function Jt({tabs:e,active:t,onSelect:n,prefix:r=`run`,label:i=`Run detail views`}){let a=X([]),o=t=>{let r=e[t];r&&(n?.(r.id),a.current[t]?.focus?.())};return Z(`div`,{className:`tab-bar`,role:`tablist`,"aria-label":i,onKeyDown:n=>{let r=e.findIndex(e=>e.id===t);if(r<0)return;let i;if(n.key===`ArrowRight`)i=(r+1)%e.length;else if(n.key===`ArrowLeft`)i=(r-1+e.length)%e.length;else if(n.key===`Home`)i=0;else if(n.key===`End`)i=e.length-1;else return;n.preventDefault(),o(i)},children:e.map((e,i)=>{let o=e.id===t;return Z(`button`,{ref:e=>{a.current[i]=e},id:Kt(r,e.id),className:`tab${o?` is-selected`:``}`,type:`button`,role:`tab`,"aria-selected":o,"aria-controls":qt(r,e.id),tabIndex:o?0:-1,onClick:()=>n?.(e.id),children:e.label},e.id)})})}var Yt={ok:{label:`ok`,kind:`ok`},failed:{label:`failed`,kind:`danger`},interrupted:{label:`interrupted`,kind:`warn`},running:{label:`running`,kind:`info`},unknown:{label:`unknown`,kind:`idle`}};function Xt(e){return Yt[e]||{label:e||`unknown`,kind:`idle`}}function Zt(e,t,n){return(e||[]).filter(e=>e&&e.kind===`agent_finish`&&Number(e.attempt)===Number(t)&&(e.stage||``)===(n||``)).map(e=>Tt(e))}function Qt(e){let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?`start time not recorded`:`started ${t.toISOString().replace(`T`,` `).slice(0,16)} UTC`}function $t({stage:e,attemptNumber:t,events:n}){let r=Xt(e.status),i=Ct(e.duration_ms),a=Zt(n,t,e.name);return Z(`li`,{className:`run-stage`,"data-status":e.status||`unknown`,children:[Z(`span`,{className:`run-stage-node`,"aria-hidden":`true`}),Z(`div`,{className:`run-stage-body`,children:[Z(`div`,{className:`run-stage-head`,children:[Z(`span`,{className:`run-stage-name mono`,children:e.name||`(unnamed stage)`}),Z(Q,{text:r.label,kind:r.kind}),Z(`span`,{className:`run-stage-duration`,children:i?`ran for ${i}`:`duration not recorded`})]}),e.error?Z(`div`,{className:`run-stage-error`,children:e.error}):null,a.map((e,t)=>Z(`div`,{className:`run-agent-report`,children:[Z(`span`,{className:`run-agent-report-label`,children:`Agent's own report, not verified by archie: `}),[e.title,e.detail].filter(Boolean).join(` · `)]},t))]})]})}function en({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function tn({count:e}){let t=Number(e)||0;return t?Z(`p`,{className:`run-rail-note`,children:[t,` event`,t===1?``:`s`,` on this task predate attempt attribution and cannot be assigned to a run.`]}):null}function nn({state:e,attemptNumber:t,events:n,onRetry:r}){if(e===void 0)return Z(`div`,{className:`run-loading`,children:`Loading this task's attempts…`});if(e===null)return Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load this task's attempts`}),Z(`div`,{className:`run-error-detail`,children:`archied did not answer for this task's run history. It may be restarting — retry, or check the daemon.`}),r?Z(`button`,{className:`btn`,type:`button`,onClick:r,children:`Retry`}):null]});let i=e?.attempts||[];if(!i.length)return Z(S,{children:[Z(en,{title:`No attempts recorded`,detail:`This task has no recorded run. An attempt is written when a stage event is emitted, and none exist here.`}),Z(tn,{count:e?.unattributed_events})]});let a=i.find(e=>Number(e.attempt)===Number(t));if(!a)return Z(S,{children:[Z(en,{title:`Attempt ${t} is not recorded for this task`,detail:`This task recorded attempt ${i.map(e=>e.attempt).join(`, `)}.`}),Z(tn,{count:e?.unattributed_events})]});let o=a.stages||[],s=Xt(a.status);return Z(`div`,{className:`run-rail`,children:[Z(`div`,{className:`run-rail-head`,children:[Z(`span`,{className:`run-rail-attempt`,children:[`Attempt `,a.attempt]}),Z(Q,{text:s.label,kind:s.kind}),Z(`span`,{className:`run-rail-when`,children:Qt(a.started_at)})]}),o.length?Z(`ol`,{className:`run-stages`,"aria-label":`Stages recorded in attempt ${a.attempt}`,children:o.map((e,t)=>Z($t,{stage:e,attemptNumber:a.attempt,events:n},`${e.seq??t}:${e.name}`))}):Z(en,{title:`No stages recorded for this attempt`,detail:`The attempt exists, but nothing recorded a stage for it.`}),Z(`p`,{className:`run-rail-legend`,children:[Z(`strong`,{children:`ok`}),` means the stage returned without error. Archie records no exit code and does not verify that the work was correct, so this is a progress status, not a check result.`]}),Z(tn,{count:e?.unattributed_events})]})}var rn={added:`Added`,modified:`Modified`,deleted:`Deleted`,renamed:`Renamed`,typechange:`Type changed`};function an(e){return rn[e]||e||`unknown`}function on(e,t){let n=e?.repo_url||t?.repo_url||``,r=t&&String(t.pr_number??``)!==``&&String(t.pr_number)===String(e?.pr_number??``);return{repo:n,pr:e?.pr_url||r&&t.pr_url||``}}function sn(e={}){let t=Number(e.files)||0,n=[`${t} file${t===1?``:`s`}`];return e.additions&&n.push(`+${e.additions}`),e.deletions&&n.push(`−${e.deletions}`),n.join(` · `)}function cn({capture:e}){let t=e.files||[],n=Number(e.totals?.files)||t.length;return t.length?Z(S,{children:[Z(`table`,{className:`table run-changes-table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Path`}),Z(`th`,{children:`Change`}),Z(`th`,{className:`run-changes-count`,children:`Added`}),Z(`th`,{className:`run-changes-count`,children:`Deleted`})]})}),Z(`tbody`,{children:t.map((e,t)=>Z(`tr`,{children:[Z(`td`,{className:`mono run-changes-path`,children:[e.old_path?Z(`span`,{className:`run-changes-old`,children:[e.old_path,` → `]}):null,e.path]}),Z(`td`,{children:[an(e.status),e.binary?Z(`span`,{className:`run-changes-hint`,children:`no textual hunks`}):null]}),Z(`td`,{className:`run-changes-count mono`,children:e.additions?`+${e.additions}`:`—`}),Z(`td`,{className:`run-changes-count mono`,children:e.deletions?`−${e.deletions}`:`—`})]},`${e.path}:${t}`))})]}),e.truncated?Z(`p`,{className:`run-changes-note`,children:[`Showing the first `,t.length,` of `,n,` files. The totals above cover every file in this capture.`]}):null]}):Z(`div`,{className:`run-changes-empty`,children:[`This capture recorded no file entries`,n?`, though its totals cover ${n} file${n===1?``:`s`}`:``,`.`]})}function ln({capture:e,task:t}){let n=on(e,t),r=e.pr_number;return Z(`section`,{className:`run-capture`,children:[Z(`div`,{className:`run-capture-head`,children:[Z(`span`,{className:`run-capture-when`,children:[e.captured_after?`Captured after ${e.captured_after}`:`Captured`,e.stage?` in stage ${e.stage}`:``]}),Z(`span`,{className:`run-capture-at`,children:e.captured_at?Ee(e.captured_at):``})]}),Z(`div`,{className:`run-capture-meta`,children:[Z(`span`,{className:`mono`,children:n.repo?Z(`a`,{className:`run-capture-link`,href:n.repo,target:`_blank`,rel:`noreferrer`,children:[e.owner,`/`,e.repo]}):`${e.owner||``}/${e.repo||``}`}),e.branch?Z(`span`,{className:`mono run-capture-branch`,children:[e.branch,e.base?` → ${e.base}`:``]}):null,e.head_sha?Z(`span`,{className:`mono run-capture-sha`,children:String(e.head_sha).slice(0,8)}):null,r?n.pr?Z(`a`,{className:`run-capture-link`,href:n.pr,target:`_blank`,rel:`noreferrer`,children:[`PR #`,r]}):Z(`span`,{className:`mono`,children:[`PR #`,r]}):null,Z(`span`,{className:`run-capture-totals`,children:sn(e.totals)})]}),Z(cn,{capture:e})]})}function un({state:e,task:t,onRetry:n}){if(e===void 0)return Z(`div`,{className:`run-loading`,children:`Loading changed files…`});if(e===null)return Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load this attempt's changed files`}),Z(`div`,{className:`run-error-detail`,children:`archied did not answer for this attempt. It may be restarting — retry, or check the daemon.`}),n?Z(`button`,{className:`btn`,type:`button`,onClick:n,children:`Retry`}):null]});let r=e.captures||[];return e.found===!0&&!r.length?Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`A change capture was recorded but could not be read`}),Z(`div`,{children:`This attempt has a change capture event, but this dashboard could not decode its payload. That is a read failure, not a statement about what the attempt changed.`})]}):!e.found||!r.length?Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`No change capture was recorded for this attempt`}),Z(`div`,{children:`Archie records what an attempt changed when it commits or pushes that work. Nothing was recorded here — the attempt may predate capture, or it produced no commit. This is not the same as "no files changed".`})]}):Z(`div`,{className:`run-changes`,children:r.map((e,n)=>Z(ln,{capture:e,task:t},`${e.captured_at||``}:${n}`))})}function dn(e,t){return(e||[]).find(e=>e&&e.kind===`config_captured`&&Number(e.attempt)===Number(t))||null}function fn({events:e,attempt:t,onRetry:n}){if(e===void 0)return Z(`div`,{className:`run-loading`,children:`Loading this task's events…`});if(e===null)return Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load this task's events`}),Z(`div`,{className:`run-error-detail`,children:`The configuration is recorded as an event on the task, so it cannot be shown while the event stream is unreadable. archied did not answer — retry, or check the daemon.`}),n?Z(`button`,{className:`btn`,type:`button`,onClick:n,children:`Retry`}):null]});let r=dn(e,t);if(!r)return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`Not captured for this run`}),Z(`div`,{children:[`Archie records the effective configuration when it dispatches an attempt. Attempt `,t,` `,`has no such record — it predates the record, or the capture did not run. Nothing here says the run used the defaults.`]})]});let i=r.data||{},a=i.schema||``,o=i.document;return Z(`div`,{className:`run-config`,children:[Z(`p`,{className:`run-config-scope`,children:[`This is attempt `,r.attempt,`'s effective task-runtime configuration: a non-secret subset covering bot identity, models, limits, budgets, dispatch, diff cap, notifications, forge host and tool policy. It is not the dashboard configuration view — providers, repositories, identities, credentials and lock state are not part of it.`]}),Z(`div`,{className:`run-config-when`,children:[`Captured `,r.at||`at an unrecorded time`,r.stage?` in stage ${r.stage}`:``]}),a===`archie/task-config@1`?Z(`pre`,{className:`run-json`,children:JSON.stringify(o??{},null,2)}):Z(S,{children:[Z(`div`,{className:`run-config-unknown`,children:[`Recorded in an unknown schema`,a?` (${a})`:``,`. The raw payload is shown verbatim; nothing here reinterprets it.`]}),Z(`pre`,{className:`run-json`,children:JSON.stringify(i,null,2)})]})]})}function pn({state:e,attempt:t,onRetry:n}){return e===void 0?Z(`div`,{className:`run-loading`,children:`Loading the stored record…`}):e===null?Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load the stored record`}),Z(`div`,{className:`run-error-detail`,children:`archied did not answer for this task's debug view. It may be restarting — retry, or check the daemon.`}),n?Z(`button`,{className:`btn`,type:`button`,onClick:n,children:`Retry`}):null]}):Z(`div`,{className:`run-debug`,children:[Z(`p`,{className:`run-debug-note`,children:[`The stored task record and its events, verbatim. Events are unfiltered on purpose: this is every event the task has, and each one carries the attempt it belongs to. Attempt `,t,` `,`is the one selected above.`]}),Z(`pre`,{className:`run-json`,children:JSON.stringify(e,null,2)})]})}var mn=[{id:`stages`,label:`Stages`},{id:`log`,label:`Log`},{id:`changes`,label:`Changed files`},{id:`config`,label:`Configuration`},{id:`debug`,label:`Debug`}],hn=`run`,gn=new Set(mn.map(e=>e.id));function _n(e){let t=String(e??``).trim();if(!/^\d+$/.test(t))return null;let n=Number(t);return Number.isSafeInteger(n)&&n>0?n:null}function vn(e){let t=e?.get?.(`tab`)||``;return gn.has(t)?t:mn[0].id}function yn(e){let t=e?.get?.(`attempt`);if(t==null||t===``)return null;let n=Number(t);return Number.isInteger(n)&&n>0?n:null}function bn(e,t,n){let r=new URLSearchParams;return r.set(`tab`,t||mn[0].id),n&&r.set(`attempt`,String(n)),`#/tasks/${e}?${r.toString()}`}function xn(e,t,n){try{window.history.replaceState(null,``,`${location.pathname}${location.search}${bn(e,t,n)}`)}catch{}}function Sn(e,t){return`${e}|${Number(t)||0}`}function Cn({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function wn({id:e}){return Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Task not found`}),Z(`p`,{className:`page-sub`,children:[`No task with id `,e,` in this deployment.`]})]}),Z(`div`,{className:`page-actions`,children:Z(`a`,{className:`btn`,href:`#/tasks`,children:`Back to tasks`})})]}),Z(`div`,{className:`card`,children:Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:[`Nothing is recorded for task `,e]}),Z(`div`,{children:`archied answered that this task does not exist, so there is no run history to show.`})]})})]})}function Tn({raw:e}){return Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Not a task id`}),Z(`p`,{className:`page-sub`,children:`The run view addresses one task by its id: #/tasks/42`})]}),Z(`div`,{className:`page-actions`,children:Z(`a`,{className:`btn`,href:`#/tasks`,children:`Back to tasks`})})]}),Z(`div`,{className:`card`,children:Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:[`“`,e,`” is not a task id`]}),Z(`div`,{children:`A task id is a positive whole number. Nothing was requested.`})]})})]})}function En({attempts:e,selected:t,onSelect:n}){let r=e?.attempts||[];return r.length?Z(`div`,{className:`run-attempts`,role:`group`,"aria-label":`Attempts of this task`,children:r.map(e=>{let r=Xt(e.status),i=Number(e.attempt)===Number(t);return Z(`button`,{type:`button`,className:`run-attempt${i?` is-selected`:``}`,"aria-pressed":i,onClick:()=>n(e.attempt),children:[Z(`span`,{className:`run-attempt-id`,children:[`Attempt `,e.attempt]}),Z(Q,{text:r.label,kind:r.kind}),Z(`span`,{className:`run-attempt-meta`,children:[(e.stages||[]).length,` stage`,(e.stages||[]).length===1?``:`s`]})]},e.attempt)})}):null}function Dn({id:e,query:t}){let[n,r]=J(()=>vn(t)),[i,a]=J(()=>yn(t)),[o,s]=J(void 0),[c,l]=J(void 0),[u,d]=J(!1),[f,p]=J(void 0),[m,h]=J(Nt),[g,_]=J(new Map),[v,y]=J(new Map),[b,x]=J(new Map),[S,C]=J(!1),[w,T]=J(null),[E,D]=J(0),O=X(new Set),k=Array.isArray(o)&&o.find(t=>String(t.id)===String(e))||null,A=Number(c?.current_attempt)>0?Number(c.current_attempt):null,j=i??A,M=(c?.attempts||[]).find(e=>Number(e.attempt)===Number(j)),N=[...new Set((M?.stages||[]).map(e=>e.name).filter(Boolean))],P=(e,t,n,{force:r=!1}={})=>{O.current.has(e)&&!r||(O.current.add(e),n(t=>new Map(t).set(e,void 0)),t().then(t=>n(n=>new Map(n).set(e,t))).catch(()=>n(t=>new Map(t).set(e,null))))},F=()=>{s(void 0),U.tasks().then(e=>s(e)).catch(()=>s(null))},I=()=>{l(void 0),d(!1),U.taskAttempts(e).then(e=>l(e)).catch(e=>{e?.status===404&&d(!0),l(null)})},ee=()=>{p(void 0),U.task(e).then(e=>p(e||[])).catch(()=>p(null))},te=(t,n)=>P(Pt(e,t,m),()=>U.taskLogs(e,{attempt:t||void 0,level:m.level,stage:m.stage,limit:500}),_,n),L=(t,n)=>P(Sn(e,t),()=>U.taskChanges(e,{attempt:t}),y,n),R=(t,n)=>P(Sn(e,t),()=>U.taskDebug(e,{attempt:t}),x,n),ne=()=>{O.current=new Set,_(new Map),y(new Map),x(new Map),F(),I(),ee(),D(e=>e+1)};Y(()=>{F(),I(),ee()},[]),Y(()=>{j!=null&&(n===`log`?te(j):n===`changes`?L(j):n===`debug`&&R(j))},[n,j,m,E]),Y(()=>{xn(e,n,j)},[e,n,j]);let z=async()=>{let t=k?.title||`task ${e}`;if(window.confirm(`Start a new run for "${t}"? This is a new attempt, and the previous attempt's commits are discarded.`)){T(null),C(!0);try{await U.taskAction(e,`retry`),O.current=new Set,_(new Map),y(new Map),x(new Map),a(null),F(),I(),ee(),D(e=>e+1)}catch(e){T(ce(e))}finally{C(!1)}}};if(u)return Z(wn,{id:e});let B=j==null?null:Pt(e,j,m),re=Sn(e,j),ie=Sn(e,j),ae=()=>{if(n===`stages`)return Z(nn,{state:c,attemptNumber:j,events:f,onRetry:I});if(c===void 0)return Z(`div`,{className:`run-loading`,children:`Loading this task's attempts…`});if(c===null)return Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load this task's attempts`}),Z(`div`,{className:`run-error-detail`,children:`This panel reads one attempt, and the task's run history could not be read.`}),Z(`button`,{className:`btn`,type:`button`,onClick:I,children:`Retry`})]});if(j==null)return Z(Cn,{title:`No attempt recorded`,detail:`This task has no recorded run, so there is nothing to read for an attempt.`});switch(n){case`log`:return Z(Lt,{state:B&&g.has(B)?g.get(B):void 0,attempt:j,stages:N,filters:m,onFilterChange:h,taskId:e,onRetry:()=>te(j,{force:!0})});case`changes`:return Z(un,{state:v.has(re)?v.get(re):void 0,task:k,onRetry:()=>L(j,{force:!0})});case`config`:return Z(fn,{events:f,attempt:j,onRetry:ee});case`debug`:return Z(pn,{state:b.has(ie)?b.get(ie):void 0,attempt:j,onRetry:()=>R(j,{force:!0})});default:return Z(nn,{state:c,attemptNumber:j,events:f,onRetry:I})}},V=Ce(`retry`),oe=!!(V&&(k?.actions||[]).includes(`retry`));return Z(`div`,{className:`run-page`,children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:k?.title||`Task #${e}`}),Z(`p`,{className:`page-sub`,children:[`One run of task `,e,k?.workflow?` · ${k.workflow} workflow`:``,k?.repo?` · ${k.owner}/${k.repo}`:``]})]}),Z(`div`,{className:`page-actions`,children:[Z(`a`,{className:`btn`,href:`#/tasks`,children:`Back to tasks`}),Z(`button`,{className:`btn`,type:`button`,onClick:ne,children:`Refresh`})]})]}),Z(`div`,{className:`run-meta`,children:[Z(`span`,{className:`run-meta-item`,children:[Z(`span`,{className:`run-meta-label`,children:`Task status`}),o===void 0?Z(`span`,{className:`run-meta-muted`,children:`loading…`}):k?Z(Q,{text:ye(k.status),kind:be(k.status)}):Z(`span`,{className:`run-meta-muted`,children:`not read`})]}),Z(`span`,{className:`run-meta-item`,children:[Z(`span`,{className:`run-meta-label`,children:`Attempt`}),Z(`span`,{className:`run-meta-value`,children:c===null?`run history unreadable`:c===void 0?`loading…`:j==null?`none recorded`:`attempt ${j} of ${A??j}`})]}),k?.repo_url?Z(`a`,{className:`run-meta-link`,href:k.repo_url,target:`_blank`,rel:`noreferrer`,children:[k.owner,`/`,k.repo]}):null,k?.issue_url&&k.issue_number?Z(`a`,{className:`run-meta-link`,href:k.issue_url,target:`_blank`,rel:`noreferrer`,children:[`Issue #`,k.issue_number]}):null,k?.pr_url&&k.pr_number?Z(`a`,{className:`run-meta-link`,href:k.pr_url,target:`_blank`,rel:`noreferrer`,children:[`PR #`,k.pr_number]}):null]}),o===null?Z(`p`,{className:`run-note`,children:`The task list could not be read, so this page cannot show the task's current status or its operator controls. The run history below comes from the task's own endpoints.`}):null,Array.isArray(o)&&!k?Z(`p`,{className:`run-note`,children:[`Task `,e,` is not among the tasks this dashboard lists (the list covers the 100 most recently updated). Its recorded attempts are shown below; the Debug tab holds the stored record verbatim.`]}):null,Z(`section`,{className:`run-restart`,"aria-label":`Start a new run`,children:[Z(`button`,{className:`btn ${V?.kind===`primary`?`btn-primary`:``}`,type:`button`,disabled:!oe||S,title:`Retry this task as a new run`,onClick:z,children:S?`Starting…`:`Start a new run`}),Z(`p`,{className:`run-restart-copy`,children:`Starts a new attempt for this task: a fresh worktree reset onto the base branch. The previous attempt's commits are discarded — they are not carried into the new run.`}),!oe&&o!==void 0?Z(`p`,{className:`run-restart-unavailable`,children:k?`A new run can only start from a parked task. This task is ${ye(k.status)}.`:`This task's operator controls could not be read, so a new run cannot be started from here.`}):null,w?Z(`p`,{className:`run-restart-error run-restart-error-${w.kind}`,children:w.kind===`session-expired`?`Your session has expired. Reload to sign in.`:w.kind===`refused`?`${w.message} — this run cannot be restarted from here.`:`${w.message} — try again, or check the daemon.`}):null]}),Z(En,{attempts:c,selected:j,onSelect:e=>a(e)}),Z(`div`,{className:`card run-card`,children:[Z(Jt,{tabs:mn,active:n,onSelect:r,prefix:hn}),Z(`div`,{className:`run-panel`,role:`tabpanel`,id:qt(hn,n),"aria-labelledby":Kt(hn,n),tabIndex:0,children:ae()})]})]})}function On(e,t){let n=t?.id,r=_n(n);return r===null?Z(Tn,{raw:n??``}):Z(Dn,{id:r,query:e})}function kn({title:e,detail:t}){return Z(`div`,{class:`empty`,children:[Z(`div`,{class:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function An(e){return Z(jn,{query:e})}function jn(){let[e,t]=J([]),[n,r]=J(``),[i,a]=J(null),o=async()=>{try{let e=await U.skills();t(e?.skills||[]),a(null)}catch(e){t([]),a(String(e.message||e))}};Y(()=>{o()},[]);let s=(e,t)=>!t||`${e.name} ${e.description}`.toLowerCase().includes(t),c=He(()=>e.filter(e=>s(e,n)),[e,n]);return Z(`div`,{children:[Z(`div`,{class:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{class:`page-title`,children:`Skills`}),Z(`p`,{class:`page-sub`,children:`What Archie can do, in plain language.`})]}),Z(`div`,{class:`page-actions`,children:Z(`button`,{class:`btn`,onClick:o,children:`Refresh`})})]}),Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Catalogue`}),Z(`p`,{class:`card-sub`,children:`Project, shared, and user-global skills`})]}),Z(`input`,{class:`skill-search`,type:`search`,placeholder:`Search skills…`,onInput:e=>r(e.target.value.trim().toLowerCase())})]}),Z(`div`,{class:`grid grid-2`,children:i?Z(kn,{title:`Cannot reach archied`,detail:i}):e.length?c.length?c.map(e=>Z(`div`,{class:`card skill-card`,children:[Z(`div`,{class:`card-head`,children:[Z(`h3`,{class:`card-title`,children:e.name||`Untitled skill`}),e.workflow&&Z(Q,{text:e.workflow,kind:`info`})]}),Z(`p`,{class:`skill-desc`,children:e.description||`No description provided.`}),Z(`div`,{class:`skill-source`,children:e.source||`Unknown source`})]},e.name)):Z(kn,{title:`No skills match`,detail:`Nothing found for "${n}".`}):Z(kn,{title:`No skills discovered yet`,detail:`Skills live as SKILL.md files under project, shared, or user-global .agents/skills// directories. Add one and refresh to make it available.`})})]})]})}var Mn={bootstrap:`Bootstrap`,implement:`Implement`,tdd:`TDD`,feasibility:`Feasibility check`};function Nn(e){return Mn[e]?Mn[e]:e?e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g,` `):`Unknown`}function Pn(e,t){return t?Math.round(e/t*100):0}function Fn(e){if(!e)return`—`;if(e<1e3)return`${e} ms`;let t=e/1e3;return t<60?`${t.toFixed(1)} s`:`${(t/60).toFixed(1)} min`}function In({title:e,detail:t}){return Z(`div`,{class:`empty`,children:[Z(`div`,{class:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Ln({fraction:e,kind:t=`ok`}){let n=Math.min(100,Math.max(0,e));return Z(`div`,{class:`wf-bar`,children:Z(`div`,{class:`wf-bar-fill wf-bar-${t}`,style:{width:`${n}%`}})})}function Rn(e){return Z(zn,{query:e})}function zn(){let[e,t]=J([]),[n,r]=J([]),[i,a]=J([]),[o,s]=J(null),c=async()=>{try{let e=await U.workflows();t(e?.definitions||[]),r(e?.workflows||[]),a(e?.stages||[]),s(null)}catch(e){s(String(e.message||e))}};return Y(()=>{c()},[]),Z(`div`,{children:[Z(`div`,{class:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{class:`page-title`,children:`Workflows`}),Z(`p`,{class:`page-sub`,children:`Run outcomes and spend per workflow, and where stages get stuck.`})]}),Z(`div`,{class:`page-actions`,children:Z(`button`,{class:`btn`,onClick:c,children:`Refresh`})})]}),Z(Bn,{definitions:e}),o?Z(`div`,{class:`card`,children:Z(In,{title:`Cannot reach archied`,detail:o})}):Z(S,{children:[Z(Vn,{workflows:n,definitions:e}),Z(Hn,{stages:i})]})]})}function Bn({definitions:e}){if(!e.length)return null;let t=e.filter(e=>e.enabled)[0]?.id||``,[n,r]=J(``),[i,a]=J(``),[o,s]=J(t),[c,l]=J(``),[u,d]=J(``),[f,p]=J(!1),[m,h]=J(``);return Y(()=>{!o&&t&&s(t)},[t,o]),Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Start work`}),Z(`p`,{class:`card-sub`,children:`This enters Archie’s normal admitted task queue.`})]})}),Z(`form`,{class:`wf-form`,onSubmit:async e=>{e.preventDefault(),p(!0),h(``);try{let e=await U.workRequest({identity:n,repository:i,workflow:o,title:c,instructions:u});h(`Queued task #${e.task_id}.`),r(``),a(``),s(t),l(``),d(``)}catch(e){h(String(e.message||e))}finally{p(!1)}},children:[Z(`input`,{placeholder:`Identity`,required:!0,value:n,onInput:e=>r(e.target.value)}),Z(`input`,{placeholder:`owner/repository`,required:!0,value:i,onInput:e=>a(e.target.value)}),Z(`select`,{required:!0,value:o,onInput:e=>s(e.target.value),children:e.filter(e=>e.enabled).map(e=>Z(`option`,{value:e.id,children:Nn(e.name||e.id)},e.id))}),Z(`input`,{placeholder:`Short task title`,required:!0,value:c,onInput:e=>l(e.target.value)}),Z(`textarea`,{placeholder:`Instructions for the work`,required:!0,rows:3,value:u,onInput:e=>d(e.target.value)}),Z(`button`,{class:`btn`,type:`submit`,disabled:f,children:`Start work`}),m&&Z(`p`,{class:`card-sub`,children:m})]})]})}function Vn({workflows:e,definitions:t}){let n=new Map(e.map(e=>[e.workflow,e])),r=t.map(e=>({...e,...n.get(e.id)||{workflow:e.id,runs:0,merged:0}}));return r.length?Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Per workflow`}),Z(`p`,{class:`card-sub`,children:`Success rate is merged tasks over all runs`})]})}),Z(`div`,{class:`table-scroll`,children:Z(`table`,{class:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Workflow`}),Z(`th`,{children:`Origin`}),Z(`th`,{children:`Runs`}),Z(`th`,{children:`Success rate`}),Z(`th`,{children:`Avg tokens`}),Z(`th`,{children:`Avg steps`})]})}),Z(`tbody`,{children:r.map(e=>{let t=Pn(e.merged,e.runs);return Z(`tr`,{children:[Z(`td`,{class:`strong`,children:Nn(e.workflow)}),Z(`td`,{class:`mono`,children:e.origin||`registry`}),Z(`td`,{children:`${e.runs} run${e.runs===1?``:`s`}`}),Z(`td`,{children:[Z(`div`,{class:`wf-rate`,children:[t,`%`,Z(`span`,{class:`wf-rate-sub`,children:[e.merged,` of `,e.runs,` merged`]})]}),Z(Ln,{fraction:t,kind:t>=50?`ok`:`warn`})]}),Z(`td`,{class:`mono`,children:e.avg_tokens?e.avg_tokens.toLocaleString():`—`}),Z(`td`,{class:`mono`,children:e.avg_steps?e.avg_steps.toFixed(1):`—`})]},e.workflow)})})]})})]}):Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:Z(`h2`,{class:`card-title`,children:`Per workflow`})})}),Z(In,{title:`No workflow runs yet`,detail:`Stats appear here once a task has run through a workflow.`})]})}function Hn({stages:e}){if(!e.length)return Z(`div`,{class:`card wf-stage-card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:Z(`h2`,{class:`card-title`,children:`Per stage`})})}),Z(In,{title:`No stage data yet`,detail:`Stage timing and failures appear here once workflows have run.`})]});let t=Math.max(...e.map(e=>e.avg_ms||0),1),n=[...e].sort((e,t)=>(t.avg_ms||0)-(e.avg_ms||0)),r=[...e].filter(e=>e.errors>0).sort((e,t)=>t.errors-e.errors);return Z(`div`,{class:`grid grid-2 wf-stage-card`,children:[Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Slowest stages`}),Z(`p`,{class:`card-sub`,children:`Average duration, this workflow's stages`})]})}),Z(`div`,{class:`table-scroll`,children:Z(`table`,{class:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Workflow`}),Z(`th`,{children:`Stage`}),Z(`th`,{children:`Runs`}),Z(`th`,{children:`Avg duration`})]})}),Z(`tbody`,{children:n.map((e,n)=>Z(`tr`,{children:[Z(`td`,{children:Nn(e.workflow)}),Z(`td`,{class:`strong`,children:e.stage}),Z(`td`,{children:e.runs}),Z(`td`,{children:[Z(`div`,{class:`wf-rate`,children:Fn(e.avg_ms)}),Z(Ln,{fraction:Pn(e.avg_ms,t),kind:`info`})]})]},n))})]})})]}),Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Most failures`}),Z(`p`,{class:`card-sub`,children:`Stages that error out, over their runs`})]})}),r.length?Z(`div`,{class:`table-scroll`,children:Z(`table`,{class:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Workflow`}),Z(`th`,{children:`Stage`}),Z(`th`,{children:`Failures`})]})}),Z(`tbody`,{children:r.map((e,t)=>Z(`tr`,{children:[Z(`td`,{children:Nn(e.workflow)}),Z(`td`,{class:`strong`,children:e.stage}),Z(`td`,{children:[Z(`div`,{class:`wf-rate`,children:[e.errors,` of `,e.runs]}),Z(Ln,{fraction:Pn(e.errors,e.runs),kind:`danger`})]})]},t))})]})}):Z(In,{title:`No failures recorded`,detail:`Every stage has completed cleanly so far.`})]})]})}function Un({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Wn(e,t){return e===`running`?`ok`:e===`failed`||e===`degraded`?`warn`:`idle`}function Gn(){let[e,t]=J([]),[n,r]=J(null),i=async()=>{try{let e=await U.channels();t(e?.channels||[]),r(null)}catch(e){r(String(e.message||e))}};return Y(()=>{i()},[]),Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Channels`}),Z(`p`,{className:`page-sub`,children:`The conversational front-ends Archie can be reached through.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:i,children:`Refresh`})})]}),Z(`div`,{className:`grid grid-2`,children:n?Z(Un,{title:`Cannot reach archied`,detail:n}):e.length===0?Z(Un,{title:`No channels configured`,detail:`Configure [chat.telegram] or [chat.webhook_addr] in config.toml to talk to Archie outside the dashboard.`}):e.map(e=>Z(`div`,{className:`card channel-card`,children:[Z(`div`,{className:`card-head`,children:[Z(`h3`,{className:`card-title`,children:e.name}),Z(Q,{text:e.state||(e.configured?`configured`:`stopped`),kind:Wn(e.state,e.configured)})]}),Z(`p`,{className:`channel-desc`,children:e.description}),Z(`p`,{className:`channel-detail`,children:e.detail}),e.reload_supported?Z(`button`,{className:`btn`,onClick:async t=>{t.currentTarget.disabled=!0;try{await U.channelReload(e.id||e.name.toLowerCase()),await i()}catch{}finally{t.currentTarget&&(t.currentTarget.disabled=!1)}},children:`Reload`}):Z(`p`,{className:`channel-detail`,children:`Reload requires a daemon restart for this adapter.`})]},e.id||e.name))})]})}function Kn(e){return Z(Gn,{query:e})}function qn({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Jn(e){return Z(Yn,{query:e})}function Yn({query:e}){let[t,n]=J([]),[r,i]=J(null),a=async()=>{try{let e=await U.curators();n(e?.curators||[]),i(null)}catch(e){i(String(e.message||e))}};return Y(()=>{a()},[]),Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Curators`}),Z(`p`,{className:`page-sub`,children:`Background agents that maintain memory and skills: what ran, and why.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:a,children:`Refresh`})})]}),Z(`div`,{className:`grid grid-2`,children:r?Z(qn,{title:`Cannot reach archied`,detail:r}):t.length?t.map(e=>Z(Zn,{curator:e},e.name)):Z(qn,{title:`No curators registered`,detail:`Curators are background agent loops that maintain memory and skills. None are registered on this daemon.`})})]})}function Xn(e){switch(e){case`healthy`:return`ok`;case`degraded`:return`warn`;case`unhealthy`:return`danger`;default:return`idle`}}function Zn({curator:e}){let t=e.recent_actions||[];return Z(`div`,{className:`card curator-card`,children:[Z(`div`,{className:`card-head`,children:[Z(`h3`,{className:`card-title`,children:e.name}),Z(Q,{text:e.health?.status||`unknown`,kind:Xn(e.health?.status)})]}),e.health?.message&&Z(`p`,{className:`curator-health-message`,children:e.health.message}),Z(`p`,{className:`curator-meta`,children:e.last_run_at?`Last ran ${Ee(e.last_run_at)} · ${e.last_run_actions} action${e.last_run_actions===1?``:`s`}`:`Has not run yet`}),t.length?Z(`ul`,{className:`curator-actions`,children:t.map((e,t)=>Z(`li`,{className:`curator-action`,children:[Z(`div`,{className:`curator-action-head`,children:[Z(`span`,{className:`curator-action-type`,children:e.type||`action`}),Z(`span`,{className:`curator-action-time`,children:Ee(e.at)})]}),e.detail&&Z(`p`,{className:`curator-action-detail`,children:e.detail}),e.reason&&Z(`p`,{className:`curator-action-reason`,children:[`Why: `,e.reason]})]},t))}):Z(`p`,{className:`curator-meta`,children:`No recorded activity yet.`})]})}function Qn(e){return e==null||e===``?`—`:String(e)}function $n({label:e,value:t,opts:n}){let r=Qn(t),[i,a]=J(!1),[o,s]=J(``),[c,l]=J(null),[u,d]=J(!1),[f,p]=J(!1),m=n?.key;if(!m)return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,title:n?.hint,children:e}),Z(`span`,{className:`kv-value mono ${r===`—`?`is-empty`:``}`,title:r,children:r})]});let h=n.locked?.[m];if(h)return Z(`div`,{className:`kv is-locked`,children:[Z(`span`,{className:`kv-label`,title:n.hint,children:e}),Z(`span`,{className:`kv-value mono ${r===`—`?`is-empty`:``}`,title:r,children:r}),Z(`span`,{className:`kv-note`,children:h})]});if(n.editable===!1)return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,title:n.hint,children:e}),Z(`span`,{className:`kv-value mono ${r===`—`?`is-empty`:``}`,title:r,children:r})]});let g=n.overridden?.includes(m),_=()=>{s(String(n.raw??``)),l(null),a(!0)},v=async()=>{p(!0),l(null);try{await U.configReset(m),n.onSaved?.()}catch(e){l(String(e.message||e))}finally{p(!1)}},y=async()=>{let e=er(n.type,o);if(e.error){l(e.error);return}d(!0),l(null);try{await(n.save||(e=>U.configUpdate({[m]:e})))(e.value),a(!1),n.onSaved?.()}catch(e){l(String(e.message||e))}finally{d(!1)}};if(i){let t=X(null);Y(()=>{t.current&&t.current.focus()},[]);let r=e=>{e.key===`Enter`&&(e.preventDefault(),y()),e.key===`Escape`&&a(!1)},i;return i=n.type===`bool`?Z(`select`,{className:`kv-input`,value:o,onChange:e=>s(e.target.value),onKeyDown:r,ref:t,children:[Z(`option`,{value:`true`,children:`true`}),Z(`option`,{value:`false`,children:`false`})]}):n.type===`enum`?Z(`select`,{className:`kv-input`,value:o,onChange:e=>s(e.target.value),onKeyDown:r,ref:t,children:(n.options||[]).map(e=>Z(`option`,{value:e,children:e},e))}):Z(`input`,{className:`kv-input`,type:`text`,value:o,onInput:e=>s(e.target.value),onKeyDown:r,ref:t}),Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,title:n.hint,children:e}),i,Z(`div`,{className:`kv-actions`,children:[Z(`button`,{className:`kv-save`,type:`button`,onClick:y,disabled:u,children:`Save`}),Z(`button`,{className:`kv-cancel`,type:`button`,onClick:()=>a(!1),disabled:u,children:`Cancel`})]}),c&&Z(`span`,{className:`kv-note is-error`,children:c})]})}return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,title:n.hint,children:e}),Z(`span`,{className:`kv-value mono ${r===`—`?`is-empty`:``}`,title:r,children:r}),Z(`div`,{className:`kv-actions`,children:[g&&Z(`span`,{className:`kv-flag`,title:`Set from the dashboard; this shadows the value in the config file`,children:`overridden`}),Z(`button`,{className:`kv-btn`,type:`button`,title:`Edit ${e}`,onClick:_,children:`Edit`}),g&&Z(`button`,{className:`kv-btn`,type:`button`,title:`Discard the dashboard value and fall back to the config file`,onClick:v,disabled:f,children:`Reset`})]}),c&&Z(`span`,{className:`kv-note is-error`,children:c})]})}function er(e,t){switch(e){case`int`:{let e=parseInt(t,10);return Number.isNaN(e)?{error:`Enter a whole number`}:{value:e}}case`bool`:return{value:t===`true`};default:return{value:t}}}function tr({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function nr({sub:e,title:t,children:n}){return Z(`div`,{className:`card cfg-section`,children:[Z(`div`,{className:`card-head`,children:Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:t||`Update status`}),Z(`p`,{className:`card-sub`,children:e})]})}),n]})}var rr={ok:`OK`,update_available:`Update available`,drift:`Drift`,unknown:`Unknown`},ir={ok:`ok`,update_available:`info`,drift:`danger`,unknown:`idle`};function ar({components:e}){return!e||!e.length?Z(nr,{sub:`How each component is deployed, and whether what's running matches what's installed.`,children:Z(tr,{title:`No components reported`,detail:`The configured update-check command returned nothing.`})}):Z(nr,{sub:`How each component is deployed, and whether what's running matches what's installed. Hover a row for the exact versions compared.`,children:Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Component`}),Z(`th`,{children:`Install type`}),Z(`th`,{children:`Running`}),Z(`th`,{children:`Latest available`}),Z(`th`,{children:`Status`})]})}),Z(`tbody`,{children:e.map(e=>Z(`tr`,{title:[`Installed claim: ${e.installed_claim||`unknown`}`,`Running: ${e.running_version||`not observed`}`,e.reference?`Reference: ${e.reference}`:null].filter(Boolean).join(` + class="gauge-value"/>`,W(`div.gauge-wrap`,l,W(`div.gauge-center`,W(`div.gauge-pct`,`${Math.round(r)}%`),W(`div.gauge-label`,t)))}function $e(e){let t=e.reduce((e,t)=>e+(t.value||0),0)||1;return W(`div`,W(`div.segbar`,...e.filter(e=>e.value>0).map(e=>W(`span`,{class:`segbar-part segbar-${e.kind||`idle`}`,style:`width:${(e.value/t*100).toFixed(1)}%`,title:`${e.label}: ${e.value}`}))),W(`div.segbar-legend`,...e.map(e=>W(`span.segbar-key`,W(`span`,{class:`segbar-dot segbar-${e.kind||`idle`}`}),e.label))))}var et=0;Array.isArray;function Z(e,n,r,i,a,o){n||={};var s,c,l=n;if(`ref`in l)for(c in l={},n)c==`ref`?s=n[c]:l[c]=n[c];var u={type:e,props:l,key:r,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--et,__i:-1,__u:0,__source:a,__self:o};if(typeof e==`function`&&(s=e.defaultProps))for(c in s)l[c]===void 0&&(l[c]=s[c]);return t.vnode&&t.vnode(u),u}function Q({text:e,kind:t=`idle`}){return Z(`span`,{className:`pill pill-${t}`,children:e})}var tt=`archie.setup-complete.dismissed.v1`;function nt(e,t=globalThis.localStorage){if(!e?.steps?.length)return{kind:`omit`,remaining:[]};let n=e.steps.filter(e=>!e.done);return n.length?(t?.removeItem?.(tt),{kind:`incomplete`,remaining:n}):t?.getItem?.(`archie.setup-complete.dismissed.v1`)===`1`?{kind:`dismissed`,remaining:[]}:{kind:`complete`,remaining:[]}}function rt(e=globalThis.localStorage){e?.setItem?.(tt,`1`)}var it=new Set([`waiting_human`,`parked`]);function at(e=[]){let t=e.filter(e=>it.has(e.status)),n=e.filter(e=>e.status===`running`);return{attention:{count:t.length,href:t.length===1?`#/tasks?task=${encodeURIComponent(t[0].id)}`:`#/tasks?status=needs_you`},running:{count:n.length,href:`#/tasks?status=running`}}}function ot({node:e}){let t=X();return Y(()=>{t.current&&e&&t.current.replaceChildren(e)},[e]),Z(`div`,{ref:t,style:{display:`contents`}})}function st(e){return Z(ot,{node:Xe(e)})}function ct(e){return Z(ot,{node:Qe(e)})}function lt({segments:e}){return Z(ot,{node:$e(e)})}function ut({name:e,opts:t}){return Z(ot,{node:G(e,t)})}function dt({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function ft(e,t){return Number(e.task_id)>0?Number(e.task_id):!e.repo||!e.issue?0:Number(t.get(`${e.repo}#${e.issue}`))||0}function pt(){let e=new Date().getHours();return e<5?`Still up?`:e<12?`Good morning`:e<18?`Good afternoon`:`Good evening`}function mt(e){if(e.length<4)return null;let t=Math.floor(e.length/2),n=e.slice(0,t).reduce((e,t)=>e+t,0),r=e.slice(t).reduce((e,t)=>e+t,0);return n?(r-n)/n*100:null}function ht(){let[e,t]=J([]),[n,r]=J(`connecting`),[i,a]=J(`idle`),[o,s]=J(new Map),[c,l]=J(null),[u,d]=J(null),[f,p]=J(null),[m,h]=J(null),[g,_]=J(null),[,v]=J(!1),y=async()=>{_(null);try{let[e,t,n,r]=await Promise.all([U.summary(),U.setup().catch(()=>null),U.workflows().catch(()=>null),U.tasks().catch(()=>[])]),i=new Map;for(let e of r)e.owner&&e.repo&&e.issue_number&&i.set(`${e.owner}/${e.repo}#${e.issue_number}`,e.id);s(i),l(e),d(t),p(n),h(r)}catch(e){_(String(e.message||e))}};Y(()=>(y(),ue(e=>{t(t=>{let n=[e,...t];return n.splice(50),n})},e=>{r(e),a(e===`live`?`ok`:`warn`)})),[]);let b=()=>{rt(),v(e=>!e)},x=u?.operator?`${pt()}, ${u.operator}`:pt(),C=null;if(g)C=Z(`button`,{className:`btn btn-primary`,onClick:y,children:[Z(ut,{name:`refresh`,opts:{size:15}}),` Retry`]});else if(m!==null){let e=at(m),t=e.attention.count,n=e.running.count;C=Z(S,{children:[t>0&&Z(`a`,{className:`btn btn-attention`,href:e.attention.href,children:[Z(ut,{name:`tasks`,opts:{size:15}}),` `,t,` need`,t===1?`s`:``,` you`]}),n>0&&Z(`a`,{className:`btn`,href:e.running.href,children:[Z(ut,{name:`workflows`,opts:{size:15}}),` `,n,` running`]}),Z(`a`,{className:`btn`,href:`#/logs`,children:[Z(ut,{name:`logs`,opts:{size:15}}),` Logs`]}),Z(`button`,{className:`btn btn-primary`,onClick:y,children:[Z(ut,{name:`refresh`,opts:{size:15}}),` Refresh`]})]})}let w=null;if(g)w=Z(`div`,{className:`card`,children:Z(dt,{title:`Cannot reach archied`,detail:g})});else if(c){let e=c?.statuses||{},t=(e.merged||0)+(e.pr_open||0),n=(e.parked||0)+(e.waiting_human||0),r=Object.values(e).reduce((e,t)=>e+t,0),i=c?.tokens_by_day||[];w=Z(S,{children:[Z(st,{label:`Working now`,value:e.running||0,compare:`${e.queued||0} waiting to start`,series:i.map(e=>e.tokens||0)}),Z(st,{label:`Needs you`,value:n,compare:n?`Parked or awaiting a reply`:`Nothing is blocked`,goodDirection:`down`}),Z(st,{label:`Delivered`,value:t,compare:r?`${Math.round(t/r*100)}% of all tasks`:`No tasks yet`}),Z(st,{label:`Tokens used`,value:De(i.reduce((e,t)=>e+(t.tokens||0),0)),compare:`Across ${i.length||0} days`,trend:mt(i.map(e=>e.tokens||0)),goodDirection:`down`,series:i.map(e=>e.tokens||0)})]})}let T=null,E=nt(u),D=E.kind===`omit`||E.kind===`dismissed`;if(!D){let e=E.remaining;if(e.length){let t=Math.round((u.steps.length-e.length)/u.steps.length*100);T=Z(`div`,{className:`card setup`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Finish setting up`}),Z(`p`,{className:`card-sub`,children:`Archie needs these before it can work on its own.`})]}),Z(`span`,{className:`setup-pct`,children:[t,`%`]})]}),Z(`div`,{className:`setup-bar`,children:Z(`div`,{className:`setup-bar-fill`,style:{width:`${t}%`}})}),Z(`ul`,{className:`setup-list`,children:u.steps.map((e,t)=>Z(`li`,{className:`setup-step ${e.done?`done`:``}`,children:[Z(`span`,{className:`setup-check`,children:e.done?Z(ut,{name:`check`,opts:{size:12}}):``}),Z(`div`,{children:[Z(`div`,{className:`setup-step-title`,children:e.title}),e.detail&&Z(`div`,{className:`setup-step-detail`,children:e.detail})]})]},t))})]})}else T=Z(`div`,{className:`card setup setup-done`,children:Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Setup complete`}),Z(`p`,{className:`card-sub`,children:`Archie is configured and ready to work.`})]}),Z(`div`,{className:`setup-complete-actions`,children:[Z(`span`,{className:`setup-pct`,children:Z(ut,{name:`check`,opts:{size:16}})}),Z(`button`,{className:`icon-btn setup-dismiss`,type:`button`,title:`Dismiss setup complete`,"aria-label":`Dismiss setup complete`,onClick:b,children:`×`})]})]})})}let O=null;if(c){let e=f?.workflows||[],t=e.reduce((e,t)=>e+(t.runs||0),0),n=e.reduce((e,t)=>e+(t.merged||0)+(t.pr_open||0),0),r=e.reduce((e,t)=>e+(t.parked||0),0);if(!t)O=Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:Z(`h2`,{className:`card-title`,children:`Gate pulse`})}),Z(dt,{title:`No completed runs yet`,detail:`Once Archie finishes a task, its gate pass rate appears here.`})]});else{let i=n/t*100;O=Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Gate pulse`}),Z(`p`,{className:`card-sub`,children:`Work that passed its quality gates`})]})}),Z(ct,{value:i,label:`pass rate`}),Z(`ul`,{className:`pulse-list`,children:[e.slice(0,3).map((e,t)=>Z(`li`,{className:`pulse-item`,children:[Z(`span`,{className:`pulse-name`,children:e.workflow||`workflow`}),Z(Q,{text:`${e.merged||0}/${e.runs||0}`,kind:(e.merged||0)===(e.runs||0)?`ok`:(e.parked||0)>0?`warn`:`info`})]},t)),r>0&&Z(`li`,{className:`pulse-item`,children:[Z(`span`,{className:`pulse-name`,children:`Parked, awaiting you`}),Z(Q,{text:String(r),kind:`warn`})]})]})]})}}let k=null;if(c){let e=c?.tokens_by_day||[],t=e.reduce((e,t)=>e+(t.tokens||0),0);if(!e.length)k=Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:Z(`h2`,{className:`card-title`,children:`Token outlook`})}),Z(dt,{title:`Nothing spent yet`,detail:`Usage appears here once Archie runs its first task.`})]});else{let n=t/e.length,r=Math.round(n*30),i=e.slice(-7).reduce((e,t)=>e+(t.tokens||0),0);k=Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Token outlook`}),Z(`p`,{className:`card-sub`,children:`Next 30 days at the current rate`})]})}),Z(`div`,{className:`forecast-value`,children:De(r)}),Z(`div`,{className:`forecast-note`,children:[`Based on `,De(Math.round(n)),` per day over `,e.length,` days`]}),Z(lt,{segments:[{label:`Last 7 days (${De(i)})`,value:i,kind:`info`},{label:`Earlier (${De(t-i)})`,value:Math.max(t-i,0),kind:`idle`}]})]})}}return Z(S,{children:[Z(`div`,{className:`hero`,children:[Z(`div`,{children:[Z(`h1`,{className:`hero-title`,children:x}),Z(`p`,{className:`hero-sub`,children:`Your agent's control room — what it is working on, what needs you, and what it is spending.`})]}),Z(`div`,{className:`hero-actions`,children:Z(`div`,{className:`hero-actions-inner`,children:C})})]}),Z(`div`,{className:`dash-section`,children:[Z(`div`,{className:`dash-section-head`,children:Z(`h2`,{className:`dash-section-title`,children:`Health`})}),Z(`div`,{className:`dash-top ${D?`dash-top-standalone`:``}`,children:[Z(`div`,{children:T}),Z(`div`,{children:O})]})]}),Z(`div`,{className:`dash-section`,children:[Z(`div`,{className:`dash-section-head`,children:[Z(`h2`,{className:`dash-section-title`,children:`Throughput`}),Z(`span`,{className:`dash-section-note`,children:`Across all repositories`})]}),Z(`div`,{className:`grid grid-4`,children:w})]}),Z(`div`,{className:`dash-section`,children:[Z(`div`,{className:`dash-section-head`,children:Z(`h2`,{className:`dash-section-title`,children:`Right now`})}),Z(`div`,{className:`dash-split`,children:[Z(`div`,{children:k}),Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Live activity`}),Z(`p`,{className:`card-sub`,children:`Last 50, newest first`})]}),Z(Q,{text:n,kind:i})]}),Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Event`}),Z(`th`,{children:`Task`}),Z(`th`,{children:`Detail`}),Z(`th`,{children:`When`})]})}),Z(`tbody`,{children:e.length?e.map((e,t)=>{let n=ft(e,o),r=n>0,i=()=>{r&&(location.hash=`#/tasks?task=${encodeURIComponent(n)}`)};return Z(`tr`,{className:r?`activity-row`:``,role:r?`link`:void 0,tabIndex:r?`0`:void 0,title:r?`Open task details`:void 0,onClick:r?i:void 0,onKeyDown:r?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),i())}:void 0,children:[Z(`td`,{className:`strong`,children:Z(`span`,{children:e.kind||e.type||`event`})}),Z(`td`,{className:`mono`,children:r?`#${n}`:`—`}),Z(`td`,{children:e.detail||e.message||``}),Z(`td`,{children:Ee(e.at||Date.now())})]},t)}):Z(`tr`,{children:Z(`td`,{colSpan:`4`,children:Z(dt,{title:`Waiting for activity`,detail:`Events appear here as Archie works.`})})})})]})})]})]})]})]})}function gt(){return Z(ht,{})}function _t(e,t){let n=e.title||`untitled task`;return{"aria-expanded":String(t),"aria-controls":`task-timeline-${e.id}`,"aria-label":`${t?`Collapse`:`Expand`} timeline for ${n}`}}var vt=Se(),yt=new Set([`needs_you`,...xe()]);function bt(e){let t=e?.get?.(`status`)||``;return yt.has(t)?t:``}function xt(e,t){return t?t===`needs_you`?vt.has(e.status):e.status===t:!0}function St(e){return String(e||`event`).replaceAll(`_`,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Ct(e){let t=Number(e);if(!Number.isFinite(t)||t<0)return``;if(t<1e3)return`${Math.round(t)} ms`;let n=t/1e3;if(n<60)return`${n.toFixed(+(n<10))} s`;let r=Math.round(n),i=Math.floor(r/60),a=r%60;if(i<60)return a===0?`${i} min`:`${i} min ${a} s`;let o=Math.floor(i/60),s=i-o*60;return s===0?`${o} h`:`${o} h ${s} min`}function wt(e){let t=Number(e);return!Number.isFinite(t)||t<=0?``:t.toLocaleString(`en-US`)}function Tt(e={}){let t=e.data||{},n=e.stage||`unknown stage`,r=e.workflow?`${e.workflow} workflow`:``;if(e.kind===`stage_start`)return{title:`Started stage: ${n}`,detail:r};if(e.kind===`stage_finish`){let e=Ct(t.duration_ms),i=[r,e&&`ran for ${e}`].filter(Boolean).join(` · `);return{title:t.interrupted?`Stage interrupted: ${n}`:t.error?`Stage failed: ${n}`:`Finished stage: ${n}`,detail:[i,t.error].filter(Boolean).join(` — `)}}if(e.kind===`task_retried`){let n=Number(t.retry_count);return{title:Number.isFinite(n)&&n>0?`Retry ${n}`:`Retry requested`,detail:[t.previous_stage&&`after ${t.previous_stage}`,t.previous_reason].filter(Boolean).join(`: `)||e.detail||``}}if(e.kind===`agent_finish`){let r=wt(t.iterations),i=wt(t.tokens),a=Number(t.cached_tokens)||0,o=wt((Number(t.prompt_tokens)||0)-a),s=wt(t.completion_tokens),c=wt(t.cached_tokens),l=[r&&`${r} iterations`,i&&`${i} tokens`,o&&`${o} fresh prompt`,s&&`${s} completion`,c&&`${c} cached`,t.model].filter(Boolean);return{title:`Agent ${t.status||`finished`}: ${n}`,detail:l.join(` · `)||e.detail||``}}if(e.kind===`config_captured`)return{title:`Configuration captured`,detail:`The effective task-runtime configuration for this run.`};if(e.kind===`changes_captured`){let e=Number(t.totals?.files);return{title:`Change capture recorded`,detail:[Number.isFinite(e)&&e>0?`${e} file${e===1?``:`s`} changed`:``,t.captured_after?`captured after ${t.captured_after}`:``].filter(Boolean).join(` · `)}}return{title:St(e.kind||e.type),detail:e.detail||``}}var Et=[{value:``,label:`All levels`},{value:`ERROR`,label:`Errors`},{value:`WARN,ERROR`,label:`Warnings and errors`},{value:`INFO,WARN,ERROR`,label:`Info and above`},{value:`DEBUG`,label:`Debug only`}];function Dt(e){switch((e||``).toUpperCase()){case`ERROR`:return`danger`;case`WARN`:return`warn`;case`DEBUG`:return`idle`;default:return`info`}}function Ot(e){let t=e.fields||{};return W(`div.log-row.log-${Dt(e.level)}`,W(`span.log-time.mono`,At(e.time)),W(`span.log-level`,(e.level||`info`).toUpperCase()),W(`span.log-body`,W(`span.log-msg`,e.message||e.msg||``),...Object.entries(t).map(([e,t])=>W(`span.log-field`,W(`span.log-field-key`,e),String(kt(t))))))}function kt(e){return e==null?``:typeof e==`object`?JSON.stringify(e):e}function At(e){let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?`--:--:--`:t.toTimeString().slice(0,8)}function jt({entry:e}){let t=X(null);return Y(()=>{t.current&&t.current.replaceChildren(Ot(e))},[e]),Z(`div`,{ref:t,style:{display:`contents`}})}function Mt(e,t){return`/api/tasks/${e}/logs/download`+(t==null?``:`?attempt=${t}`)}var Nt={level:``,stage:``};function Pt(e,t,n=Nt){let r=n||Nt;return[e,Number(t)||0,r.level||``,r.stage||``].join(`|`)}function Ft({filters:e,onFilterChange:t,stages:n,attempt:r}){let i=n=>t?.({...e,...n}),a=Number(r)||0;return Z(`div`,{className:`log-filters task-log-filters`,children:[Z(`span`,{className:`task-log-attempt`,children:a>0?`Attempt ${a}`:`Current attempt`}),t?Z(S,{children:[Z(`label`,{className:`task-log-filter`,children:[Z(`span`,{className:`task-log-filter-label`,children:`Level`}),Z(`select`,{className:`task-filter`,value:e.level,"aria-label":`Filter log entries by level`,onChange:e=>i({level:e.target.value}),children:Et.map(e=>Z(`option`,{value:e.value,children:e.label},e.value))})]}),Z(`label`,{className:`task-log-filter`,children:[Z(`span`,{className:`task-log-filter-label`,children:`Stage`}),Z(`select`,{className:`task-filter`,value:e.stage,"aria-label":`Filter log entries by stage`,onChange:e=>i({stage:e.target.value}),children:[Z(`option`,{value:``,children:`All stages`}),(n||[]).map(e=>Z(`option`,{value:e,children:e},e))]})]}),e.stage?Z(`p`,{className:`task-log-filter-note`,children:`A stage filter matches only log lines that record a stage. Agent and tool output carries none, so it is not shown while this filter is set.`}):null,!e.stage&&!(n||[]).length?Z(`p`,{className:`task-log-filter-note`,children:`This attempt recorded no stage names, so the stage filter has nothing to match.`}):null]}):null]})}function It({text:e}){return Z(`p`,{className:`visually-hidden`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:e})}function Lt({state:e,onRetry:t,taskId:n,attempt:r,filters:i=Nt,onFilterChange:a,stages:o=[]}){let s=Number(r)||Number(e?.attempt)||0,c,l;if(e===void 0)c=`Loading this attempt's log`,l=Z(`div`,{className:`task-log-loading`,children:`Loading attempt log…`});else if(e===null)c=`This attempt's log could not be loaded`,l=Z(`div`,{className:`task-log-error`,children:[Z(`div`,{className:`task-timeline-detail`,children:`Could not load this attempt's log.`}),Z(`button`,{className:`btn`,onClick:t,children:`Retry`})]});else if(e.found===!1&&!e.disabled)c=`No log recorded for this attempt`,l=Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`No log recorded for this attempt`}),Z(`div`,{children:`This attempt produced no output, or it has not started writing yet.`})]});else if(e.disabled)c=`This dashboard cannot read task logs`,l=Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`No persisted log for this attempt`}),Z(`div`,{children:`This dashboard cannot read task logs. The service that owns the log files is not reporting a log reader.`})]});else{let t=e.entries||[],r=n==null?null:Mt(n,s||null),i=r?Z(`a`,{className:`btn btn-small task-log-download`,href:r,download:!0,children:`Download log`}):null;t.length?(c=`${t.length} log entr${t.length===1?`y`:`ies`} shown`,l=Z(S,{children:[Z(`div`,{className:`log-list task-log-list`,children:t.map((e,t)=>Z(jt,{entry:e},t))}),i]})):(c=`This attempt's log has no entries matching the current filter`,l=Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`Nothing recorded`}),Z(`div`,{children:`This attempt's log file has no entries matching the current filter.`}),i]}))}return Z(S,{children:[Z(Ft,{filters:i,onFilterChange:a,stages:o,attempt:s}),Z(It,{text:c}),l]})}function Rt(){return typeof window<`u`&&window.matchMedia?.(`(prefers-reduced-motion: reduce)`)?.matches===!0}function zt(){return Rt()?`auto`:`smooth`}function Bt(e){let t=X(null);return Y(()=>{t.current&&t.current.replaceChildren(Xe(e))},[e]),Z(`div`,{ref:t,style:{display:`contents`}})}function Vt({kind:e,message:t}){return e===`session-expired`?Z(`span`,{className:`task-action-error task-action-error-session`,children:[`Your session has expired.`,` `,Z(`button`,{className:`button btn btn-small`,type:`button`,onClick:()=>window.location.reload(),children:`Reload to sign in`})]}):e===`refused`?Z(`span`,{className:`task-action-error task-action-error-refused`,children:[t,` — you can't do that.`]}):Z(`span`,{className:`task-action-error task-action-error-broken`,children:[t,` — try again, or check the daemon.`]})}function Ht({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Ut({taskId:e,attempt:t,state:n,onLoad:r,onRetry:i}){let a=X(r);return a.current=r,Y(()=>{n===void 0&&a.current()},[n]),Z(Lt,{state:n,taskId:e,attempt:t,onRetry:i})}function Wt({query:e}){let[t,n]=J(null),[r,i]=J(null),[a,o]=J(()=>bt(e)),[s,c]=J(``),l=Number(e.get(`task`)),u=Number.isFinite(l)&&l>0?l:null,[d,f]=J(u),[p,m]=J(u!==null),[h,g]=J(new Map),[_,v]=J(new Map),y=X(new Set),[b,x]=J(new Set),[C,w]=J(new Map),[T,E]=J(new Set),D=async()=>{try{i(null);let e=await U.tasks();return n(e),d&&e.some(e=>String(e.id)===String(d))&&(h.has(d)||O(d)),e}catch(e){return i(String(e.message||e)),n(null),null}};Y(()=>{D()},[]);let O=async e=>{try{let t=await U.task(e);g(n=>new Map(n).set(e,t||[]))}catch{g(t=>new Map(t).set(e,null))}},k=async(e,t,{force:n=!1}={})=>{let r=Pt(e,t);if(!(y.current.has(r)&&!n)){y.current.add(r),n&&v(e=>{let t=new Map(e);return t.delete(r),t});try{let n=await U.taskLogs(e,{attempt:t||void 0,limit:500});v(e=>new Map(e).set(r,n))}catch{v(e=>new Map(e).set(r,null))}}},A=e=>{g(t=>{let n=new Map(t);return n.delete(e),n})},j=async(e,t)=>{w(t=>{let n=new Map(t);return n.delete(e),n}),E(t=>new Set(t).add(e));try{await U.taskAction(e,t),E(t=>{let n=new Set(t);return n.delete(e),n}),t===`archive`&&f(null),A(e);let n=await D();Array.isArray(n)&&n.find(t=>String(t.id)===String(e))&&d===e&&O(e)}catch(t){E(t=>{let n=new Set(t);return n.delete(e),n}),w(n=>new Map(n).set(e,ce(t)))}};Y(()=>{p&&d&&t&&(m(!1),requestAnimationFrame(()=>{let e=document.getElementById(`task-row-${d}`);e&&(e.focus({preventScroll:!0}),e.scrollIntoView?.({block:`center`,behavior:zt()}))}))},[p,d,t]);let M=(e,t)=>{t&&t.stopPropagation();let n=d!==e;f(n?e:null),n&&O(e)},N=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=()=>{if(!t)return null;let e=t.length,n={};for(let e of t)n[e.status]=(n[e.status]||0)+1;let r=n.running||0,i=(n.waiting_human||0)+(n.parked||0),a=(n.merged||0)+(n.pr_open||0);return Z(`div`,{className:`grid grid-4 task-summary`,children:[Z(Bt,{label:`Total tasks`,value:e,compare:e?`Everything archied has ever picked up`:`No tasks yet`}),Z(Bt,{label:`Working now`,value:r,compare:e?`${r} of ${e} in progress`:`Nothing running`}),Z(Bt,{label:`Needs you`,value:i,compare:i?`Parked or awaiting a reply`:`Nothing is blocked`,goodDirection:`down`}),Z(Bt,{label:`Delivered`,value:a,compare:e?`${Math.round(a/e*100)}% of all tasks`:`No tasks yet`})]})},F=e=>{let t=C.get(e.id),n=t?Vt(t):null,r=T.has(e.id),i=e=>e===`quiet`?`btn-quiet`:e===`danger`?`btn-danger`:``,a=(e.actions||[]).map(t=>{let n=Ce(t);if(!n)return null;let a=e.title||`this task`,o=n.confirm?n.confirm.replaceAll(`{title}`,a):void 0,s=[`button`,`btn`,`btn-small`,i(n.kind)].filter(Boolean).join(` `);if(n.kind===`link`){if(t===`open_pr`)return I(e,`pull_request`,e.pr_number,n.label);if(t===`open_issue`)return I(e,`issue`,e.issue_number,n.label)}return Z(`button`,{className:s,type:`button`,disabled:r,onClick:n=>{n.stopPropagation(),!(o&&!window.confirm(o))&&j(e.id,t)},children:n.label},t)}).filter(Boolean);return!a.length&&!n?`—`:Z(`div`,{className:`task-actions`,children:[n,a]})},I=(e,t,n,r)=>{let i=t===`issue`?e.issue_url:e.pr_url;return!i||!n||t===`issue`&&e.source===`chat`?Z(`button`,{className:`btn btn-small`,type:`button`,disabled:!0,title:`${r} is unavailable`,children:r}):Z(`a`,{className:`btn btn-small`,href:i,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:r})},ee=e=>{let t=e.repo_url;return t?Z(`a`,{className:`task-source-link`,href:t,target:`_blank`,rel:`noreferrer`,title:`Open ${e.owner}/${e.repo} on the forge`,onClick:e=>e.stopPropagation(),children:[e.owner,`/`,e.repo]}):null},te=e=>{let t=e.issue_url;return e.source===`chat`||!t||!e.issue_number?null:Z(`a`,{className:`task-source-link`,href:t,target:`_blank`,rel:`noreferrer`,title:`Open issue #${e.issue_number} on the forge`,onClick:e=>e.stopPropagation(),children:[`#`,e.issue_number]})},L=e=>{let t=Pt(e.id,e.attempt),n=h.get(e.id),r=b.has(e.id);return Z(`tr`,{className:`task-timeline-row`,id:`task-timeline-${e.id}`,children:Z(`td`,{colSpan:8,children:[Z(`div`,{className:`task-detail-actions`,children:[Z(`div`,{className:`task-decision-title`,children:`Available actions`}),F(e)]}),e.status===`waiting_human`&&e.plan&&Z(`div`,{className:`task-decision`,children:[Z(`div`,{className:`task-decision-title`,children:`Decision required`}),Z(`div`,{className:`task-decision-plan`,children:e.plan})]}),e.status===`parked`&&e.park_reason&&Z(`div`,{className:`task-decision`,children:[Z(`div`,{className:`task-decision-title`,children:`Park reason`}),Z(`div`,{className:`task-decision-plan`,children:e.park_reason})]}),n===void 0?Z(`div`,{className:`task-timeline-loading`,children:`Loading timeline…`}):n===null?Z(`div`,{className:`task-timeline-error`,children:[Z(`div`,{className:`task-timeline-title`,children:`Could not load timeline`}),Z(`div`,{className:`task-timeline-detail`,children:`archied did not answer for this task's events. It may be restarting — retry, or check the daemon.`}),Z(`button`,{className:`btn`,onClick:()=>O(e.id),children:`Retry`})]}):n.length?Z(`ul`,{className:`task-timeline`,children:n.map((e,t)=>{let n=Tt(e);return Z(`li`,{className:`task-timeline-entry`,children:[Z(`span`,{className:`task-timeline-dot`}),Z(`div`,{children:[Z(`div`,{className:`task-timeline-kind`,children:n.title}),n.detail&&Z(`div`,{className:`task-timeline-detail`,children:n.detail}),Z(`div`,{className:`task-timeline-when`,children:Ee(e.at)})]})]},t)})}):Z(Ht,{title:`No events yet`,detail:`This task has not recorded any transitions.`}),Z(`div`,{className:`task-logs-section`,children:[Z(`div`,{className:`task-decision-title`,children:[`Attempt log`,Z(`button`,{className:`btn btn-small`,onClick:()=>N(e.id),style:{marginLeft:`10px`},children:r?`Hide`:`Show`})]}),r&&Z(Ut,{taskId:e.id,attempt:e.attempt,state:_.has(t)?_.get(t):void 0,onLoad:()=>k(e.id,e.attempt),onRetry:()=>k(e.id,e.attempt,{force:!0})})]})]})})};return Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Tasks`}),Z(`p`,{className:`page-sub`,children:`Every issue archied has picked up, and where it stands.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:D,children:`Refresh`})})]}),r?Z(`div`,{className:`grid grid-4 task-summary`,children:Z(`div`,{className:`card`,children:Z(Ht,{title:`Cannot reach archied`,detail:r})})}):P(),Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`All tasks`}),Z(`p`,{className:`card-sub`,children:`Click a row for its timeline`})]}),Z(`div`,{className:`task-filters`,children:[Z(`input`,{className:`task-search`,type:`search`,placeholder:`Search by title or repo…`,value:s,onInput:e=>c(e.target.value.trim().toLowerCase())}),Z(`select`,{className:`task-filter`,value:a,onChange:e=>o(e.target.value),children:[Z(`option`,{value:``,children:`All statuses`}),Z(`option`,{value:`needs_you`,children:`Needs you`}),xe().map(e=>Z(`option`,{value:e,children:ye(e)},e))]})]})]}),Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[`Repo`,`Issue`,`Title`,`Status`,`Workflow`,`Stage`,`Last activity`,`Action`].map(e=>Z(`th`,{children:e},e))})}),Z(`tbody`,{children:(()=>{if(r)return Z(`tr`,{children:Z(`td`,{colSpan:8,children:Z(Ht,{title:`Cannot reach archied`,detail:r})})});if(!t)return Z(`tr`,{children:Z(`td`,{colSpan:8,children:Z(`div`,{className:`task-timeline-loading`,children:`Loading tasks...`})})});if(!t.length)return Z(`tr`,{children:Z(`td`,{colSpan:8,children:Z(Ht,{title:`No tasks yet`,detail:`Tasks appear here once archied picks up an issue to work.`})})});let e=t.filter(e=>xt(e,a)?!s||`${e.title} ${e.repo}`.toLowerCase().includes(s):!1);return e.length?e.map(e=>{let t=d===e.id,n=`task-timeline-${e.id}`;return Z(S,{children:[Z(`tr`,{className:`task-row`,id:`task-row-${e.id}`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),M(e.id,t))},onClick:t=>M(e.id,t),..._t(e,t),children:[Z(`td`,{className:`mono`,"data-label":`Repository`,children:[Z(`button`,{className:`task-expand`,type:`button`,"aria-expanded":String(t),"aria-controls":n,"aria-label":`${t?`Collapse`:`Expand`} timeline for ${e.title||`untitled task`}`,onClick:t=>M(e.id,t),children:t?`−`:`+`}),ee(e)??`${e.owner}/${e.repo}`]}),Z(`td`,{className:`mono`,"data-label":`Issue`,children:te(e)??`#${e.issue_number}`}),Z(`td`,{className:`strong`,"data-label":`Title`,children:Z(`a`,{className:`task-detail-link`,href:`#/tasks/${e.id}`,title:`Open the run detail for this task`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:e.title||`(untitled)`})}),Z(`td`,{"data-label":`Status`,children:Z(Q,{text:ye(e.status),kind:be(e.status)})}),Z(`td`,{"data-label":`Workflow`,children:e.workflow||`—`}),Z(`td`,{"data-label":`Stage`,children:e.stage||`—`}),Z(`td`,{"data-label":`Last activity`,title:e.created_at?`Created ${Ee(e.created_at)}`:``,children:Ee(e.updated_at)}),Z(`td`,{"data-label":`Actions`,children:F(e)})]}),t&&L(e)]},e.id)}):Z(`tr`,{children:Z(`td`,{colSpan:8,children:Z(Ht,{title:`No matching tasks`,detail:`Try a different search or status filter.`})})})})()})]})})]})]})}function Gt(e){return Z(Wt,{query:e})}function Kt(e,t){return`${e}-tab-${t}`}function qt(e,t){return`${e}-panel-${t}`}function Jt({tabs:e,active:t,onSelect:n,prefix:r=`run`,label:i=`Run detail views`}){let a=X([]),o=t=>{let r=e[t];r&&(n?.(r.id),a.current[t]?.focus?.())};return Z(`div`,{className:`tab-bar`,role:`tablist`,"aria-label":i,onKeyDown:n=>{let r=e.findIndex(e=>e.id===t);if(r<0)return;let i;if(n.key===`ArrowRight`)i=(r+1)%e.length;else if(n.key===`ArrowLeft`)i=(r-1+e.length)%e.length;else if(n.key===`Home`)i=0;else if(n.key===`End`)i=e.length-1;else return;n.preventDefault(),o(i)},children:e.map((e,i)=>{let o=e.id===t;return Z(`button`,{ref:e=>{a.current[i]=e},id:Kt(r,e.id),className:`tab${o?` is-selected`:``}`,type:`button`,role:`tab`,"aria-selected":o,"aria-controls":qt(r,e.id),tabIndex:o?0:-1,onClick:()=>n?.(e.id),children:e.label},e.id)})})}var Yt={ok:{label:`ok`,kind:`ok`},failed:{label:`failed`,kind:`danger`},interrupted:{label:`interrupted`,kind:`warn`},running:{label:`running`,kind:`info`},unknown:{label:`unknown`,kind:`idle`}};function Xt(e){return Yt[e]||{label:e||`unknown`,kind:`idle`}}function Zt(e,t,n){return(e||[]).filter(e=>e&&e.kind===`agent_finish`&&Number(e.attempt)===Number(t)&&(e.stage||``)===(n||``)).map(e=>Tt(e))}function Qt(e){let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?`start time not recorded`:`started ${t.toISOString().replace(`T`,` `).slice(0,16)} UTC`}function $t({stage:e,attemptNumber:t,events:n}){let r=Xt(e.status),i=Ct(e.duration_ms),a=Zt(n,t,e.name);return Z(`li`,{className:`run-stage`,"data-status":e.status||`unknown`,children:[Z(`span`,{className:`run-stage-node`,"aria-hidden":`true`}),Z(`div`,{className:`run-stage-body`,children:[Z(`div`,{className:`run-stage-head`,children:[Z(`span`,{className:`run-stage-name mono`,children:e.name||`(unnamed stage)`}),Z(Q,{text:r.label,kind:r.kind}),Z(`span`,{className:`run-stage-duration`,children:i?`ran for ${i}`:`duration not recorded`})]}),e.error?Z(`div`,{className:`run-stage-error`,children:e.error}):null,a.map((e,t)=>Z(`div`,{className:`run-agent-report`,children:[Z(`span`,{className:`run-agent-report-label`,children:`Agent's own report, not verified by archie: `}),[e.title,e.detail].filter(Boolean).join(` · `)]},t))]})]})}function en({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function tn({count:e}){let t=Number(e)||0;return t?Z(`p`,{className:`run-rail-note`,children:[t,` event`,t===1?``:`s`,` on this task predate attempt attribution and cannot be assigned to a run.`]}):null}function nn({state:e,attemptNumber:t,events:n,onRetry:r}){if(e===void 0)return Z(`div`,{className:`run-loading`,children:`Loading this task's attempts…`});if(e===null)return Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load this task's attempts`}),Z(`div`,{className:`run-error-detail`,children:`archied did not answer for this task's run history. It may be restarting — retry, or check the daemon.`}),r?Z(`button`,{className:`btn`,type:`button`,onClick:r,children:`Retry`}):null]});let i=e?.attempts||[];if(!i.length)return Z(S,{children:[Z(en,{title:`No attempts recorded`,detail:`This task has no recorded run. An attempt is written when a stage event is emitted, and none exist here.`}),Z(tn,{count:e?.unattributed_events})]});let a=i.find(e=>Number(e.attempt)===Number(t));if(!a)return Z(S,{children:[Z(en,{title:`Attempt ${t} is not recorded for this task`,detail:`This task recorded attempt ${i.map(e=>e.attempt).join(`, `)}.`}),Z(tn,{count:e?.unattributed_events})]});let o=a.stages||[],s=Xt(a.status);return Z(`div`,{className:`run-rail`,children:[Z(`div`,{className:`run-rail-head`,children:[Z(`span`,{className:`run-rail-attempt`,children:[`Attempt `,a.attempt]}),Z(Q,{text:s.label,kind:s.kind}),Z(`span`,{className:`run-rail-when`,children:Qt(a.started_at)})]}),o.length?Z(`ol`,{className:`run-stages`,"aria-label":`Stages recorded in attempt ${a.attempt}`,children:o.map((e,t)=>Z($t,{stage:e,attemptNumber:a.attempt,events:n},`${e.seq??t}:${e.name}`))}):Z(en,{title:`No stages recorded for this attempt`,detail:`The attempt exists, but nothing recorded a stage for it.`}),Z(`p`,{className:`run-rail-legend`,children:[Z(`strong`,{children:`ok`}),` means the stage returned without error. Archie records no exit code and does not verify that the work was correct, so this is a progress status, not a check result.`]}),Z(tn,{count:e?.unattributed_events})]})}var rn={added:`Added`,modified:`Modified`,deleted:`Deleted`,renamed:`Renamed`,typechange:`Type changed`};function an(e){return rn[e]||e||`unknown`}function on(e,t){let n=e?.repo_url||t?.repo_url||``,r=t&&String(t.pr_number??``)!==``&&String(t.pr_number)===String(e?.pr_number??``);return{repo:n,pr:e?.pr_url||r&&t.pr_url||``}}function sn(e={}){let t=Number(e.files)||0,n=[`${t} file${t===1?``:`s`}`];return e.additions&&n.push(`+${e.additions}`),e.deletions&&n.push(`−${e.deletions}`),n.join(` · `)}function cn({capture:e}){let t=e.files||[],n=Number(e.totals?.files)||t.length;return t.length?Z(S,{children:[Z(`table`,{className:`table run-changes-table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Path`}),Z(`th`,{children:`Change`}),Z(`th`,{className:`run-changes-count`,children:`Added`}),Z(`th`,{className:`run-changes-count`,children:`Deleted`})]})}),Z(`tbody`,{children:t.map((e,t)=>Z(`tr`,{children:[Z(`td`,{className:`mono run-changes-path`,children:[e.old_path?Z(`span`,{className:`run-changes-old`,children:[e.old_path,` → `]}):null,e.path]}),Z(`td`,{children:[an(e.status),e.binary?Z(`span`,{className:`run-changes-hint`,children:`no textual hunks`}):null]}),Z(`td`,{className:`run-changes-count mono`,children:e.additions?`+${e.additions}`:`—`}),Z(`td`,{className:`run-changes-count mono`,children:e.deletions?`−${e.deletions}`:`—`})]},`${e.path}:${t}`))})]}),e.truncated?Z(`p`,{className:`run-changes-note`,children:[`Showing the first `,t.length,` of `,n,` files. The totals above cover every file in this capture.`]}):null]}):Z(`div`,{className:`run-changes-empty`,children:[`This capture recorded no file entries`,n?`, though its totals cover ${n} file${n===1?``:`s`}`:``,`.`]})}function ln({capture:e,task:t}){let n=on(e,t),r=e.pr_number;return Z(`section`,{className:`run-capture`,children:[Z(`div`,{className:`run-capture-head`,children:[Z(`span`,{className:`run-capture-when`,children:[e.captured_after?`Captured after ${e.captured_after}`:`Captured`,e.stage?` in stage ${e.stage}`:``]}),Z(`span`,{className:`run-capture-at`,children:e.captured_at?Ee(e.captured_at):``})]}),Z(`div`,{className:`run-capture-meta`,children:[Z(`span`,{className:`mono`,children:n.repo?Z(`a`,{className:`run-capture-link`,href:n.repo,target:`_blank`,rel:`noreferrer`,children:[e.owner,`/`,e.repo]}):`${e.owner||``}/${e.repo||``}`}),e.branch?Z(`span`,{className:`mono run-capture-branch`,children:[e.branch,e.base?` → ${e.base}`:``]}):null,e.head_sha?Z(`span`,{className:`mono run-capture-sha`,children:String(e.head_sha).slice(0,8)}):null,r?n.pr?Z(`a`,{className:`run-capture-link`,href:n.pr,target:`_blank`,rel:`noreferrer`,children:[`PR #`,r]}):Z(`span`,{className:`mono`,children:[`PR #`,r]}):null,Z(`span`,{className:`run-capture-totals`,children:sn(e.totals)})]}),Z(cn,{capture:e})]})}function un({state:e,task:t,onRetry:n}){if(e===void 0)return Z(`div`,{className:`run-loading`,children:`Loading changed files…`});if(e===null)return Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load this attempt's changed files`}),Z(`div`,{className:`run-error-detail`,children:`archied did not answer for this attempt. It may be restarting — retry, or check the daemon.`}),n?Z(`button`,{className:`btn`,type:`button`,onClick:n,children:`Retry`}):null]});let r=e.captures||[];return e.found===!0&&!r.length?Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`A change capture was recorded but could not be read`}),Z(`div`,{children:`This attempt has a change capture event, but this dashboard could not decode its payload. That is a read failure, not a statement about what the attempt changed.`})]}):!e.found||!r.length?Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`No change capture was recorded for this attempt`}),Z(`div`,{children:`Archie records what an attempt changed when it commits or pushes that work. Nothing was recorded here — the attempt may predate capture, or it produced no commit. This is not the same as "no files changed".`})]}):Z(`div`,{className:`run-changes`,children:r.map((e,n)=>Z(ln,{capture:e,task:t},`${e.captured_at||``}:${n}`))})}function dn(e,t){return(e||[]).find(e=>e&&e.kind===`config_captured`&&Number(e.attempt)===Number(t))||null}function fn({events:e,attempt:t,onRetry:n}){if(e===void 0)return Z(`div`,{className:`run-loading`,children:`Loading this task's events…`});if(e===null)return Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load this task's events`}),Z(`div`,{className:`run-error-detail`,children:`The configuration is recorded as an event on the task, so it cannot be shown while the event stream is unreadable. archied did not answer — retry, or check the daemon.`}),n?Z(`button`,{className:`btn`,type:`button`,onClick:n,children:`Retry`}):null]});let r=dn(e,t);if(!r)return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`Not captured for this run`}),Z(`div`,{children:[`Archie records the effective configuration when it dispatches an attempt. Attempt `,t,` `,`has no such record — it predates the record, or the capture did not run. Nothing here says the run used the defaults.`]})]});let i=r.data||{},a=i.schema||``,o=i.document;return Z(`div`,{className:`run-config`,children:[Z(`p`,{className:`run-config-scope`,children:[`This is attempt `,r.attempt,`'s effective task-runtime configuration: a non-secret subset covering bot identity, models, limits, budgets, dispatch, diff cap, notifications, forge host and tool policy. It is not the dashboard configuration view — providers, repositories, identities, credentials and lock state are not part of it.`]}),Z(`div`,{className:`run-config-when`,children:[`Captured `,r.at||`at an unrecorded time`,r.stage?` in stage ${r.stage}`:``]}),a===`archie/task-config@1`?Z(`pre`,{className:`run-json`,children:JSON.stringify(o??{},null,2)}):Z(S,{children:[Z(`div`,{className:`run-config-unknown`,children:[`Recorded in an unknown schema`,a?` (${a})`:``,`. The raw payload is shown verbatim; nothing here reinterprets it.`]}),Z(`pre`,{className:`run-json`,children:JSON.stringify(i,null,2)})]})]})}function pn({state:e,attempt:t,onRetry:n}){return e===void 0?Z(`div`,{className:`run-loading`,children:`Loading the stored record…`}):e===null?Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load the stored record`}),Z(`div`,{className:`run-error-detail`,children:`archied did not answer for this task's debug view. It may be restarting — retry, or check the daemon.`}),n?Z(`button`,{className:`btn`,type:`button`,onClick:n,children:`Retry`}):null]}):Z(`div`,{className:`run-debug`,children:[Z(`p`,{className:`run-debug-note`,children:[`The stored task record and its events, verbatim. Events are unfiltered on purpose: this is every event the task has, and each one carries the attempt it belongs to. Attempt `,t,` `,`is the one selected above.`]}),Z(`pre`,{className:`run-json`,children:JSON.stringify(e,null,2)})]})}var mn=[{id:`stages`,label:`Stages`},{id:`log`,label:`Log`},{id:`changes`,label:`Changed files`},{id:`config`,label:`Configuration`},{id:`debug`,label:`Debug`}],hn=`run`,gn=new Set(mn.map(e=>e.id));function _n(e){let t=String(e??``).trim();if(!/^\d+$/.test(t))return null;let n=Number(t);return Number.isSafeInteger(n)&&n>0?n:null}function vn(e){let t=e?.get?.(`tab`)||``;return gn.has(t)?t:mn[0].id}function yn(e){let t=e?.get?.(`attempt`);if(t==null||t===``)return null;let n=Number(t);return Number.isInteger(n)&&n>0?n:null}function bn(e,t,n){let r=new URLSearchParams;return r.set(`tab`,t||mn[0].id),n&&r.set(`attempt`,String(n)),`#/tasks/${e}?${r.toString()}`}function xn(e,t,n){try{window.history.replaceState(null,``,`${location.pathname}${location.search}${bn(e,t,n)}`)}catch{}}function Sn(e,t){return`${e}|${Number(t)||0}`}function Cn({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function wn({id:e}){return Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Task not found`}),Z(`p`,{className:`page-sub`,children:[`No task with id `,e,` in this deployment.`]})]}),Z(`div`,{className:`page-actions`,children:Z(`a`,{className:`btn`,href:`#/tasks`,children:`Back to tasks`})})]}),Z(`div`,{className:`card`,children:Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:[`Nothing is recorded for task `,e]}),Z(`div`,{children:`archied answered that this task does not exist, so there is no run history to show.`})]})})]})}function Tn({raw:e}){return Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Not a task id`}),Z(`p`,{className:`page-sub`,children:`The run view addresses one task by its id: #/tasks/42`})]}),Z(`div`,{className:`page-actions`,children:Z(`a`,{className:`btn`,href:`#/tasks`,children:`Back to tasks`})})]}),Z(`div`,{className:`card`,children:Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:[`“`,e,`” is not a task id`]}),Z(`div`,{children:`A task id is a positive whole number. Nothing was requested.`})]})})]})}function En({attempts:e,selected:t,onSelect:n}){let r=e?.attempts||[];return r.length?Z(`div`,{className:`run-attempts`,role:`group`,"aria-label":`Attempts of this task`,children:r.map(e=>{let r=Xt(e.status),i=Number(e.attempt)===Number(t);return Z(`button`,{type:`button`,className:`run-attempt${i?` is-selected`:``}`,"aria-pressed":i,onClick:()=>n(e.attempt),children:[Z(`span`,{className:`run-attempt-id`,children:[`Attempt `,e.attempt]}),Z(Q,{text:r.label,kind:r.kind}),Z(`span`,{className:`run-attempt-meta`,children:[(e.stages||[]).length,` stage`,(e.stages||[]).length===1?``:`s`]})]},e.attempt)})}):null}function Dn({id:e,query:t}){let[n,r]=J(()=>vn(t)),[i,a]=J(()=>yn(t)),[o,s]=J(void 0),[c,l]=J(void 0),[u,d]=J(!1),[f,p]=J(void 0),[m,h]=J(Nt),[g,_]=J(new Map),[v,y]=J(new Map),[b,x]=J(new Map),[S,C]=J(!1),[w,T]=J(null),[E,D]=J(0),O=X(new Set),k=Array.isArray(o)&&o.find(t=>String(t.id)===String(e))||null,A=Number(c?.current_attempt)>0?Number(c.current_attempt):null,j=i??A,M=(c?.attempts||[]).find(e=>Number(e.attempt)===Number(j)),N=[...new Set((M?.stages||[]).map(e=>e.name).filter(Boolean))],P=(e,t,n,{force:r=!1}={})=>{O.current.has(e)&&!r||(O.current.add(e),n(t=>new Map(t).set(e,void 0)),t().then(t=>n(n=>new Map(n).set(e,t))).catch(()=>n(t=>new Map(t).set(e,null))))},F=()=>{s(void 0),U.tasks().then(e=>s(e)).catch(()=>s(null))},I=()=>{l(void 0),d(!1),U.taskAttempts(e).then(e=>l(e)).catch(e=>{e?.status===404&&d(!0),l(null)})},ee=()=>{p(void 0),U.task(e).then(e=>p(e||[])).catch(()=>p(null))},te=(t,n)=>P(Pt(e,t,m),()=>U.taskLogs(e,{attempt:t||void 0,level:m.level,stage:m.stage,limit:500}),_,n),L=(t,n)=>P(Sn(e,t),()=>U.taskChanges(e,{attempt:t}),y,n),R=(t,n)=>P(Sn(e,t),()=>U.taskDebug(e,{attempt:t}),x,n),ne=()=>{O.current=new Set,_(new Map),y(new Map),x(new Map),F(),I(),ee(),D(e=>e+1)};Y(()=>{F(),I(),ee()},[]),Y(()=>{j!=null&&(n===`log`?te(j):n===`changes`?L(j):n===`debug`&&R(j))},[n,j,m,E]),Y(()=>{xn(e,n,j)},[e,n,j]);let z=async()=>{let t=k?.title||`task ${e}`;if(window.confirm(`Start a new run for "${t}"? This is a new attempt, and the previous attempt's commits are discarded.`)){T(null),C(!0);try{await U.taskAction(e,`retry`),O.current=new Set,_(new Map),y(new Map),x(new Map),a(null),F(),I(),ee(),D(e=>e+1)}catch(e){T(ce(e))}finally{C(!1)}}};if(u)return Z(wn,{id:e});let B=j==null?null:Pt(e,j,m),re=Sn(e,j),ie=Sn(e,j),ae=()=>{if(n===`stages`)return Z(nn,{state:c,attemptNumber:j,events:f,onRetry:I});if(c===void 0)return Z(`div`,{className:`run-loading`,children:`Loading this task's attempts…`});if(c===null)return Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load this task's attempts`}),Z(`div`,{className:`run-error-detail`,children:`This panel reads one attempt, and the task's run history could not be read.`}),Z(`button`,{className:`btn`,type:`button`,onClick:I,children:`Retry`})]});if(j==null)return Z(Cn,{title:`No attempt recorded`,detail:`This task has no recorded run, so there is nothing to read for an attempt.`});switch(n){case`log`:return Z(Lt,{state:B&&g.has(B)?g.get(B):void 0,attempt:j,stages:N,filters:m,onFilterChange:h,taskId:e,onRetry:()=>te(j,{force:!0})});case`changes`:return Z(un,{state:v.has(re)?v.get(re):void 0,task:k,onRetry:()=>L(j,{force:!0})});case`config`:return Z(fn,{events:f,attempt:j,onRetry:ee});case`debug`:return Z(pn,{state:b.has(ie)?b.get(ie):void 0,attempt:j,onRetry:()=>R(j,{force:!0})});default:return Z(nn,{state:c,attemptNumber:j,events:f,onRetry:I})}},V=Ce(`retry`),oe=!!(V&&(k?.actions||[]).includes(`retry`));return Z(`div`,{className:`run-page`,children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:k?.title||`Task #${e}`}),Z(`p`,{className:`page-sub`,children:[`One run of task `,e,k?.workflow?` · ${k.workflow} workflow`:``,k?.repo?` · ${k.owner}/${k.repo}`:``]})]}),Z(`div`,{className:`page-actions`,children:[Z(`a`,{className:`btn`,href:`#/tasks`,children:`Back to tasks`}),Z(`button`,{className:`btn`,type:`button`,onClick:ne,children:`Refresh`})]})]}),Z(`div`,{className:`run-meta`,children:[Z(`span`,{className:`run-meta-item`,children:[Z(`span`,{className:`run-meta-label`,children:`Task status`}),o===void 0?Z(`span`,{className:`run-meta-muted`,children:`loading…`}):k?Z(Q,{text:ye(k.status),kind:be(k.status)}):Z(`span`,{className:`run-meta-muted`,children:`not read`})]}),Z(`span`,{className:`run-meta-item`,children:[Z(`span`,{className:`run-meta-label`,children:`Attempt`}),Z(`span`,{className:`run-meta-value`,children:c===null?`run history unreadable`:c===void 0?`loading…`:j==null?`none recorded`:`attempt ${j} of ${A??j}`})]}),k?.repo_url?Z(`a`,{className:`run-meta-link`,href:k.repo_url,target:`_blank`,rel:`noreferrer`,children:[k.owner,`/`,k.repo]}):null,k?.issue_url&&k.issue_number?Z(`a`,{className:`run-meta-link`,href:k.issue_url,target:`_blank`,rel:`noreferrer`,children:[`Issue #`,k.issue_number]}):null,k?.pr_url&&k.pr_number?Z(`a`,{className:`run-meta-link`,href:k.pr_url,target:`_blank`,rel:`noreferrer`,children:[`PR #`,k.pr_number]}):null]}),o===null?Z(`p`,{className:`run-note`,children:`The task list could not be read, so this page cannot show the task's current status or its operator controls. The run history below comes from the task's own endpoints.`}):null,Array.isArray(o)&&!k?Z(`p`,{className:`run-note`,children:[`Task `,e,` is not among the tasks this dashboard lists (the list covers the 100 most recently updated). Its recorded attempts are shown below; the Debug tab holds the stored record verbatim.`]}):null,Z(`section`,{className:`run-restart`,"aria-label":`Start a new run`,children:[Z(`button`,{className:`btn ${V?.kind===`primary`?`btn-primary`:``}`,type:`button`,disabled:!oe||S,title:`Retry this task as a new run`,onClick:z,children:S?`Starting…`:`Start a new run`}),Z(`p`,{className:`run-restart-copy`,children:`Starts a new attempt for this task: a fresh worktree reset onto the base branch. The previous attempt's commits are discarded — they are not carried into the new run.`}),!oe&&o!==void 0?Z(`p`,{className:`run-restart-unavailable`,children:k?`A new run can only start from a parked task. This task is ${ye(k.status)}.`:`This task's operator controls could not be read, so a new run cannot be started from here.`}):null,w?Z(`p`,{className:`run-restart-error run-restart-error-${w.kind}`,children:w.kind===`session-expired`?`Your session has expired. Reload to sign in.`:w.kind===`refused`?`${w.message} — this run cannot be restarted from here.`:`${w.message} — try again, or check the daemon.`}):null]}),Z(En,{attempts:c,selected:j,onSelect:e=>a(e)}),Z(`div`,{className:`card run-card`,children:[Z(Jt,{tabs:mn,active:n,onSelect:r,prefix:hn}),Z(`div`,{className:`run-panel`,role:`tabpanel`,id:qt(hn,n),"aria-labelledby":Kt(hn,n),tabIndex:0,children:ae()})]})]})}function On(e,t){let n=t?.id,r=_n(n);return r===null?Z(Tn,{raw:n??``}):Z(Dn,{id:r,query:e},r)}function kn({title:e,detail:t}){return Z(`div`,{class:`empty`,children:[Z(`div`,{class:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function An(e){return Z(jn,{query:e})}function jn(){let[e,t]=J([]),[n,r]=J(``),[i,a]=J(null),o=async()=>{try{let e=await U.skills();t(e?.skills||[]),a(null)}catch(e){t([]),a(String(e.message||e))}};Y(()=>{o()},[]);let s=(e,t)=>!t||`${e.name} ${e.description}`.toLowerCase().includes(t),c=He(()=>e.filter(e=>s(e,n)),[e,n]);return Z(`div`,{children:[Z(`div`,{class:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{class:`page-title`,children:`Skills`}),Z(`p`,{class:`page-sub`,children:`What Archie can do, in plain language.`})]}),Z(`div`,{class:`page-actions`,children:Z(`button`,{class:`btn`,onClick:o,children:`Refresh`})})]}),Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Catalogue`}),Z(`p`,{class:`card-sub`,children:`Project, shared, and user-global skills`})]}),Z(`input`,{class:`skill-search`,type:`search`,placeholder:`Search skills…`,onInput:e=>r(e.target.value.trim().toLowerCase())})]}),Z(`div`,{class:`grid grid-2`,children:i?Z(kn,{title:`Cannot reach archied`,detail:i}):e.length?c.length?c.map(e=>Z(`div`,{class:`card skill-card`,children:[Z(`div`,{class:`card-head`,children:[Z(`h3`,{class:`card-title`,children:e.name||`Untitled skill`}),e.workflow&&Z(Q,{text:e.workflow,kind:`info`})]}),Z(`p`,{class:`skill-desc`,children:e.description||`No description provided.`}),Z(`div`,{class:`skill-source`,children:e.source||`Unknown source`})]},e.name)):Z(kn,{title:`No skills match`,detail:`Nothing found for "${n}".`}):Z(kn,{title:`No skills discovered yet`,detail:`Skills live as SKILL.md files under project, shared, or user-global .agents/skills// directories. Add one and refresh to make it available.`})})]})]})}var Mn={bootstrap:`Bootstrap`,implement:`Implement`,tdd:`TDD`,feasibility:`Feasibility check`};function Nn(e){return Mn[e]?Mn[e]:e?e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g,` `):`Unknown`}function Pn(e,t){return t?Math.round(e/t*100):0}function Fn(e){if(!e)return`—`;if(e<1e3)return`${e} ms`;let t=e/1e3;return t<60?`${t.toFixed(1)} s`:`${(t/60).toFixed(1)} min`}function In({title:e,detail:t}){return Z(`div`,{class:`empty`,children:[Z(`div`,{class:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Ln({fraction:e,kind:t=`ok`}){let n=Math.min(100,Math.max(0,e));return Z(`div`,{class:`wf-bar`,children:Z(`div`,{class:`wf-bar-fill wf-bar-${t}`,style:{width:`${n}%`}})})}function Rn(e){return Z(zn,{query:e})}function zn(){let[e,t]=J([]),[n,r]=J([]),[i,a]=J([]),[o,s]=J(null),c=async()=>{try{let e=await U.workflows();t(e?.definitions||[]),r(e?.workflows||[]),a(e?.stages||[]),s(null)}catch(e){s(String(e.message||e))}};return Y(()=>{c()},[]),Z(`div`,{children:[Z(`div`,{class:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{class:`page-title`,children:`Workflows`}),Z(`p`,{class:`page-sub`,children:`Run outcomes and spend per workflow, and where stages get stuck.`})]}),Z(`div`,{class:`page-actions`,children:Z(`button`,{class:`btn`,onClick:c,children:`Refresh`})})]}),Z(Bn,{definitions:e}),o?Z(`div`,{class:`card`,children:Z(In,{title:`Cannot reach archied`,detail:o})}):Z(S,{children:[Z(Vn,{workflows:n,definitions:e}),Z(Hn,{stages:i})]})]})}function Bn({definitions:e}){if(!e.length)return null;let t=e.filter(e=>e.enabled)[0]?.id||``,[n,r]=J(``),[i,a]=J(``),[o,s]=J(t),[c,l]=J(``),[u,d]=J(``),[f,p]=J(!1),[m,h]=J(``);return Y(()=>{!o&&t&&s(t)},[t,o]),Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Start work`}),Z(`p`,{class:`card-sub`,children:`This enters Archie’s normal admitted task queue.`})]})}),Z(`form`,{class:`wf-form`,onSubmit:async e=>{e.preventDefault(),p(!0),h(``);try{let e=await U.workRequest({identity:n,repository:i,workflow:o,title:c,instructions:u});h(`Queued task #${e.task_id}.`),r(``),a(``),s(t),l(``),d(``)}catch(e){h(String(e.message||e))}finally{p(!1)}},children:[Z(`input`,{placeholder:`Identity`,required:!0,value:n,onInput:e=>r(e.target.value)}),Z(`input`,{placeholder:`owner/repository`,required:!0,value:i,onInput:e=>a(e.target.value)}),Z(`select`,{required:!0,value:o,onInput:e=>s(e.target.value),children:e.filter(e=>e.enabled).map(e=>Z(`option`,{value:e.id,children:Nn(e.name||e.id)},e.id))}),Z(`input`,{placeholder:`Short task title`,required:!0,value:c,onInput:e=>l(e.target.value)}),Z(`textarea`,{placeholder:`Instructions for the work`,required:!0,rows:3,value:u,onInput:e=>d(e.target.value)}),Z(`button`,{class:`btn`,type:`submit`,disabled:f,children:`Start work`}),m&&Z(`p`,{class:`card-sub`,children:m})]})]})}function Vn({workflows:e,definitions:t}){let n=new Map(e.map(e=>[e.workflow,e])),r=t.map(e=>({...e,...n.get(e.id)||{workflow:e.id,runs:0,merged:0}}));return r.length?Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Per workflow`}),Z(`p`,{class:`card-sub`,children:`Success rate is merged tasks over all runs`})]})}),Z(`div`,{class:`table-scroll`,children:Z(`table`,{class:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Workflow`}),Z(`th`,{children:`Origin`}),Z(`th`,{children:`Runs`}),Z(`th`,{children:`Success rate`}),Z(`th`,{children:`Avg tokens`}),Z(`th`,{children:`Avg steps`})]})}),Z(`tbody`,{children:r.map(e=>{let t=Pn(e.merged,e.runs);return Z(`tr`,{children:[Z(`td`,{class:`strong`,children:Nn(e.workflow)}),Z(`td`,{class:`mono`,children:e.origin||`registry`}),Z(`td`,{children:`${e.runs} run${e.runs===1?``:`s`}`}),Z(`td`,{children:[Z(`div`,{class:`wf-rate`,children:[t,`%`,Z(`span`,{class:`wf-rate-sub`,children:[e.merged,` of `,e.runs,` merged`]})]}),Z(Ln,{fraction:t,kind:t>=50?`ok`:`warn`})]}),Z(`td`,{class:`mono`,children:e.avg_tokens?e.avg_tokens.toLocaleString():`—`}),Z(`td`,{class:`mono`,children:e.avg_steps?e.avg_steps.toFixed(1):`—`})]},e.workflow)})})]})})]}):Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:Z(`h2`,{class:`card-title`,children:`Per workflow`})})}),Z(In,{title:`No workflow runs yet`,detail:`Stats appear here once a task has run through a workflow.`})]})}function Hn({stages:e}){if(!e.length)return Z(`div`,{class:`card wf-stage-card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:Z(`h2`,{class:`card-title`,children:`Per stage`})})}),Z(In,{title:`No stage data yet`,detail:`Stage timing and failures appear here once workflows have run.`})]});let t=Math.max(...e.map(e=>e.avg_ms||0),1),n=[...e].sort((e,t)=>(t.avg_ms||0)-(e.avg_ms||0)),r=[...e].filter(e=>e.errors>0).sort((e,t)=>t.errors-e.errors);return Z(`div`,{class:`grid grid-2 wf-stage-card`,children:[Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Slowest stages`}),Z(`p`,{class:`card-sub`,children:`Average duration, this workflow's stages`})]})}),Z(`div`,{class:`table-scroll`,children:Z(`table`,{class:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Workflow`}),Z(`th`,{children:`Stage`}),Z(`th`,{children:`Runs`}),Z(`th`,{children:`Avg duration`})]})}),Z(`tbody`,{children:n.map((e,n)=>Z(`tr`,{children:[Z(`td`,{children:Nn(e.workflow)}),Z(`td`,{class:`strong`,children:e.stage}),Z(`td`,{children:e.runs}),Z(`td`,{children:[Z(`div`,{class:`wf-rate`,children:Fn(e.avg_ms)}),Z(Ln,{fraction:Pn(e.avg_ms,t),kind:`info`})]})]},n))})]})})]}),Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Most failures`}),Z(`p`,{class:`card-sub`,children:`Stages that error out, over their runs`})]})}),r.length?Z(`div`,{class:`table-scroll`,children:Z(`table`,{class:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Workflow`}),Z(`th`,{children:`Stage`}),Z(`th`,{children:`Failures`})]})}),Z(`tbody`,{children:r.map((e,t)=>Z(`tr`,{children:[Z(`td`,{children:Nn(e.workflow)}),Z(`td`,{class:`strong`,children:e.stage}),Z(`td`,{children:[Z(`div`,{class:`wf-rate`,children:[e.errors,` of `,e.runs]}),Z(Ln,{fraction:Pn(e.errors,e.runs),kind:`danger`})]})]},t))})]})}):Z(In,{title:`No failures recorded`,detail:`Every stage has completed cleanly so far.`})]})]})}function Un({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Wn(e,t){return e===`running`?`ok`:e===`failed`||e===`degraded`?`warn`:`idle`}function Gn(){let[e,t]=J([]),[n,r]=J(null),i=async()=>{try{let e=await U.channels();t(e?.channels||[]),r(null)}catch(e){r(String(e.message||e))}};return Y(()=>{i()},[]),Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Channels`}),Z(`p`,{className:`page-sub`,children:`The conversational front-ends Archie can be reached through.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:i,children:`Refresh`})})]}),Z(`div`,{className:`grid grid-2`,children:n?Z(Un,{title:`Cannot reach archied`,detail:n}):e.length===0?Z(Un,{title:`No channels configured`,detail:`Configure [chat.telegram] or [chat.webhook_addr] in config.toml to talk to Archie outside the dashboard.`}):e.map(e=>Z(`div`,{className:`card channel-card`,children:[Z(`div`,{className:`card-head`,children:[Z(`h3`,{className:`card-title`,children:e.name}),Z(Q,{text:e.state||(e.configured?`configured`:`stopped`),kind:Wn(e.state,e.configured)})]}),Z(`p`,{className:`channel-desc`,children:e.description}),Z(`p`,{className:`channel-detail`,children:e.detail}),e.reload_supported?Z(`button`,{className:`btn`,onClick:async t=>{t.currentTarget.disabled=!0;try{await U.channelReload(e.id||e.name.toLowerCase()),await i()}catch{}finally{t.currentTarget&&(t.currentTarget.disabled=!1)}},children:`Reload`}):Z(`p`,{className:`channel-detail`,children:`Reload requires a daemon restart for this adapter.`})]},e.id||e.name))})]})}function Kn(e){return Z(Gn,{query:e})}function qn({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Jn(e){return Z(Yn,{query:e})}function Yn({query:e}){let[t,n]=J([]),[r,i]=J(null),a=async()=>{try{let e=await U.curators();n(e?.curators||[]),i(null)}catch(e){i(String(e.message||e))}};return Y(()=>{a()},[]),Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Curators`}),Z(`p`,{className:`page-sub`,children:`Background agents that maintain memory and skills: what ran, and why.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:a,children:`Refresh`})})]}),Z(`div`,{className:`grid grid-2`,children:r?Z(qn,{title:`Cannot reach archied`,detail:r}):t.length?t.map(e=>Z(Zn,{curator:e},e.name)):Z(qn,{title:`No curators registered`,detail:`Curators are background agent loops that maintain memory and skills. None are registered on this daemon.`})})]})}function Xn(e){switch(e){case`healthy`:return`ok`;case`degraded`:return`warn`;case`unhealthy`:return`danger`;default:return`idle`}}function Zn({curator:e}){let t=e.recent_actions||[];return Z(`div`,{className:`card curator-card`,children:[Z(`div`,{className:`card-head`,children:[Z(`h3`,{className:`card-title`,children:e.name}),Z(Q,{text:e.health?.status||`unknown`,kind:Xn(e.health?.status)})]}),e.health?.message&&Z(`p`,{className:`curator-health-message`,children:e.health.message}),Z(`p`,{className:`curator-meta`,children:e.last_run_at?`Last ran ${Ee(e.last_run_at)} · ${e.last_run_actions} action${e.last_run_actions===1?``:`s`}`:`Has not run yet`}),t.length?Z(`ul`,{className:`curator-actions`,children:t.map((e,t)=>Z(`li`,{className:`curator-action`,children:[Z(`div`,{className:`curator-action-head`,children:[Z(`span`,{className:`curator-action-type`,children:e.type||`action`}),Z(`span`,{className:`curator-action-time`,children:Ee(e.at)})]}),e.detail&&Z(`p`,{className:`curator-action-detail`,children:e.detail}),e.reason&&Z(`p`,{className:`curator-action-reason`,children:[`Why: `,e.reason]})]},t))}):Z(`p`,{className:`curator-meta`,children:`No recorded activity yet.`})]})}function Qn(e){return e==null||e===``?`—`:String(e)}function $n({label:e,value:t,opts:n}){let r=Qn(t),[i,a]=J(!1),[o,s]=J(``),[c,l]=J(null),[u,d]=J(!1),[f,p]=J(!1),m=n?.key;if(!m)return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,title:n?.hint,children:e}),Z(`span`,{className:`kv-value mono ${r===`—`?`is-empty`:``}`,title:r,children:r})]});let h=n.locked?.[m];if(h)return Z(`div`,{className:`kv is-locked`,children:[Z(`span`,{className:`kv-label`,title:n.hint,children:e}),Z(`span`,{className:`kv-value mono ${r===`—`?`is-empty`:``}`,title:r,children:r}),Z(`span`,{className:`kv-note`,children:h})]});if(n.editable===!1)return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,title:n.hint,children:e}),Z(`span`,{className:`kv-value mono ${r===`—`?`is-empty`:``}`,title:r,children:r})]});let g=n.overridden?.includes(m),_=()=>{s(String(n.raw??``)),l(null),a(!0)},v=async()=>{p(!0),l(null);try{await U.configReset(m),n.onSaved?.()}catch(e){l(String(e.message||e))}finally{p(!1)}},y=async()=>{let e=er(n.type,o);if(e.error){l(e.error);return}d(!0),l(null);try{await(n.save||(e=>U.configUpdate({[m]:e})))(e.value),a(!1),n.onSaved?.()}catch(e){l(String(e.message||e))}finally{d(!1)}};if(i){let t=X(null);Y(()=>{t.current&&t.current.focus()},[]);let r=e=>{e.key===`Enter`&&(e.preventDefault(),y()),e.key===`Escape`&&a(!1)},i;return i=n.type===`bool`?Z(`select`,{className:`kv-input`,value:o,onChange:e=>s(e.target.value),onKeyDown:r,ref:t,children:[Z(`option`,{value:`true`,children:`true`}),Z(`option`,{value:`false`,children:`false`})]}):n.type===`enum`?Z(`select`,{className:`kv-input`,value:o,onChange:e=>s(e.target.value),onKeyDown:r,ref:t,children:(n.options||[]).map(e=>Z(`option`,{value:e,children:e},e))}):Z(`input`,{className:`kv-input`,type:`text`,value:o,onInput:e=>s(e.target.value),onKeyDown:r,ref:t}),Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,title:n.hint,children:e}),i,Z(`div`,{className:`kv-actions`,children:[Z(`button`,{className:`kv-save`,type:`button`,onClick:y,disabled:u,children:`Save`}),Z(`button`,{className:`kv-cancel`,type:`button`,onClick:()=>a(!1),disabled:u,children:`Cancel`})]}),c&&Z(`span`,{className:`kv-note is-error`,children:c})]})}return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,title:n.hint,children:e}),Z(`span`,{className:`kv-value mono ${r===`—`?`is-empty`:``}`,title:r,children:r}),Z(`div`,{className:`kv-actions`,children:[g&&Z(`span`,{className:`kv-flag`,title:`Set from the dashboard; this shadows the value in the config file`,children:`overridden`}),Z(`button`,{className:`kv-btn`,type:`button`,title:`Edit ${e}`,onClick:_,children:`Edit`}),g&&Z(`button`,{className:`kv-btn`,type:`button`,title:`Discard the dashboard value and fall back to the config file`,onClick:v,disabled:f,children:`Reset`})]}),c&&Z(`span`,{className:`kv-note is-error`,children:c})]})}function er(e,t){switch(e){case`int`:{let e=parseInt(t,10);return Number.isNaN(e)?{error:`Enter a whole number`}:{value:e}}case`bool`:return{value:t===`true`};default:return{value:t}}}function tr({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function nr({sub:e,title:t,children:n}){return Z(`div`,{className:`card cfg-section`,children:[Z(`div`,{className:`card-head`,children:Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:t||`Update status`}),Z(`p`,{className:`card-sub`,children:e})]})}),n]})}var rr={ok:`OK`,update_available:`Update available`,drift:`Drift`,unknown:`Unknown`},ir={ok:`ok`,update_available:`info`,drift:`danger`,unknown:`idle`};function ar({components:e}){return!e||!e.length?Z(nr,{sub:`How each component is deployed, and whether what's running matches what's installed.`,children:Z(tr,{title:`No components reported`,detail:`The configured update-check command returned nothing.`})}):Z(nr,{sub:`How each component is deployed, and whether what's running matches what's installed. Hover a row for the exact versions compared.`,children:Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Component`}),Z(`th`,{children:`Install type`}),Z(`th`,{children:`Running`}),Z(`th`,{children:`Latest available`}),Z(`th`,{children:`Status`})]})}),Z(`tbody`,{children:e.map(e=>Z(`tr`,{title:[`Installed claim: ${e.installed_claim||`unknown`}`,`Running: ${e.running_version||`not observed`}`,e.reference?`Reference: ${e.reference}`:null].filter(Boolean).join(` `),children:[Z(`td`,{className:`strong`,children:e.label||e.id}),Z(`td`,{className:`mono`,children:e.install_type||`—`}),Z(`td`,{className:`mono`,children:e.running_version||`—`}),Z(`td`,{className:`mono`,children:e.latest_available||`—`}),Z(`td`,{children:Z(Q,{text:rr[e.status]||e.status,kind:ir[e.status]||`idle`})})]},e.id||e.label))})]})})})}function $({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function or({title:e,sub:t,children:n}){return Z(`div`,{className:`card cfg-section`,children:[Z(`div`,{className:`card-head`,children:Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:e}),Z(`p`,{className:`card-sub`,children:t})]})}),n]})}function sr({origins:e}){return e?.length?Z(or,{title:`Configuration sources`,sub:`Applied from top to bottom; later entries take precedence over earlier ones.`,children:Z(`div`,{className:`kv-list`,children:e.map((e,t)=>Z($n,{label:`${e.layer} ${e.role}${e.feature?` (${e.feature})`:``}`,value:e.path},t))})}):Z(or,{title:`Configuration sources`,sub:`The files that supplied the running configuration.`,children:Z($,{title:`Source provenance is unavailable.`})})}function cr(e){return e===`quiet`?`btn-quiet`:e===`danger`?`btn-danger`:``}function lr({data:e,error:t}){if(t)return Z(or,{title:`Work lifecycle`,sub:`The task statuses and operator actions archied ships.`,children:Z($,{title:`Lifecycle unavailable`,detail:t})});let n=e?.statuses||[],r=e?.actions||[];return Z(or,{title:`Work lifecycle`,sub:`The task statuses and operator actions archied ships. Add one on the backend and it appears here without a frontend change.`,children:[Z(`h3`,{className:`cfg-subhead`,children:`Statuses`}),n.length?Z(`div`,{className:`kv-list`,children:n.map(e=>{let t=e.label??ye(e.id),n=e.kind??be(e.id);return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,children:e.id}),Z(`span`,{className:`kv-value`,children:Z(Q,{text:t,kind:n})})]},e.id)})}):Z($,{title:`No statuses reported`,detail:`The server did not return any lifecycle statuses.`}),Z(`h3`,{className:`cfg-subhead`,children:`Actions`}),r.length?Z(`div`,{className:`kv-list`,children:r.map(e=>{let t=e.label??e.id,n=cr(e.kind);return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,children:e.id}),Z(`span`,{className:`kv-value`,children:Z(`button`,{className:`btn btn-small ${n}`,type:`button`,disabled:!0,children:t})})]},e.id)})}):Z($,{title:`No actions reported`,detail:`The server did not return any operator actions.`})]})}function ur({r:e,field:t,onSaved:n,editable:r=!0}){let[i,a]=J(!1),[o,s]=J(null),[c,l]=J(!!e[t]);return r?Z(`td`,{children:[Z(`input`,{className:`repo-field-checkbox`,type:`checkbox`,checked:c,onChange:async r=>{let i=r.target.checked;l(i),a(!0),s(null);try{await U.configRepoUpdate(e.owner,e.name,t,i),n?.()}catch(e){l(!i),s(String(e.message||e))}finally{a(!1)}},disabled:i}),o&&Z(`span`,{className:`kv-note is-error`,children:o})]}):Z(`td`,{children:c?`yes`:`no`})}function dr({r:e,field:t,onSaved:n,editable:r=!0}){let[i,a]=J(String(e[t]??0)),[o,s]=J(null),[c,l]=J(!1);return r?Z(`td`,{children:[Z(`input`,{className:`kv-input`,type:`text`,value:i,onChange:e=>a(e.target.value),onBlur:async()=>{let r=parseInt(i,10);if(Number.isNaN(r)){s(`Enter a whole number`);return}l(!0),s(null);try{await U.configRepoUpdate(e.owner,e.name,t,r),n?.()}catch(e){s(String(e.message||e))}finally{l(!1)}},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.target.blur())},disabled:c}),o&&Z(`span`,{className:`kv-note is-error`,children:o})]}):Z(`td`,{className:`mono`,children:i})}function fr({repos:e,onSaved:t,editable:n=!0}){if(!e?.length)return Z(or,{title:`Repositories`,sub:`The repositories Archie polls for work.`,children:Z($,{title:`No repositories configured`,detail:`Add a [[repos]] entry in config.toml so Archie has somewhere to work.`})});let r=e=>e?.length?e.map(e=>e.join(` `)).join(` → `):`—`;return Z(or,{title:`Repositories`,sub:`Each repository Archie polls, and the quality gate a change must pass before it opens a pull request. Concurrent tasks, retries, and self-review are per-repository overrides -- PATCH /api/config/repos/{owner}/{name}, not the file config.toml directly.`,children:Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Repository`}),Z(`th`,{children:`Base branch`}),Z(`th`,{children:`Ecosystem`}),Z(`th`,{children:`Quality gate`}),Z(`th`,{children:`Protected paths`}),Z(`th`,{children:`Concurrent`}),Z(`th`,{children:`Max retries`}),Z(`th`,{children:`Self-review`})]})}),Z(`tbody`,{children:e.map((e,i)=>Z(`tr`,{children:[Z(`td`,{className:`strong`,children:[e.owner,`/`,e.name]}),Z(`td`,{className:`mono`,children:e.base}),Z(`td`,{children:e.ecosystem||`go`}),Z(`td`,{className:`mono`,children:r(e.gate)}),Z(`td`,{className:`mono`,children:e.protect?.length?e.protect.join(`, `):`—`}),Z(ur,{r:e,field:`allow_concurrent`,onSaved:t,editable:n}),Z(dr,{r:e,field:`max_retries`,onSaved:t,editable:n}),Z(ur,{r:e,field:`review_enabled`,onSaved:t,editable:n})]},i))})]})})})}function pr(e){return e?e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g,` `):`Unknown role`}function mr({models:e,providers:t}){let n=Object.entries(e||{}),r=Object.entries(t||{});return Z(or,{title:`Models & providers`,sub:`Which model handles each stage of work, and which LLM providers are wired up. Only the environment variable NAME is shown, never its value.`,children:[Z(`h3`,{className:`cfg-subhead`,children:`Model roles`}),n.length?Z(`div`,{className:`kv-list`,children:n.map(([e,t])=>Z($n,{label:pr(e),value:t},e))}):Z($,{title:`No model roles configured`,detail:`Assign a model to at least one role (e.g. "builder") in [models].`}),Z(`h3`,{className:`cfg-subhead`,children:`Providers`}),r.length?Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Provider`}),Z(`th`,{children:`Class`}),Z(`th`,{children:`Base URL`}),Z(`th`,{children:`API key env var`}),Z(`th`,{children:`Status`})]})}),Z(`tbody`,{children:r.map(([e,t])=>Z(`tr`,{children:[Z(`td`,{className:`strong`,children:e}),Z(`td`,{children:t.class}),Z(`td`,{className:`mono`,children:t.base_url||`default`}),Z(`td`,{className:`mono`,children:t.api_key_env||`—`}),Z(`td`,{children:t.configured?Z(Q,{text:`configured`,kind:`ok`}):Z(Q,{text:`missing credentials`,kind:`warn`})})]},e))})]})}):Z($,{title:`No providers configured`,detail:`Add a [providers.] entry so a model role above has something to run on.`})]})}function hr(){let[e,t]=J(null),[n,r]=J(null),[i,a]=J(null),[o,s]=J(null),[c,l]=J(!1),[u,d]=J(null),[f,p]=J(null),m=()=>{h(),g(),_()},h=async()=>{try{let e=await U.config();t(e),r(null)}catch(e){r(String(e.message||e))}},g=async()=>{try{let e=await U.version();a(e?.components||[]),s(null),l(!1)}catch(e){e?.status===501?l(!0):s(String(e.message||e))}},_=async()=>{try{let e=await U.taskMeta();d(e),p(null)}catch(e){p(String(e.message||e))}};return Y(()=>{m()},[]),Z(`div`,{className:`cfg-page`,children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Configuration`}),Z(`p`,{className:`page-sub`,children:`What archied is actually running with right now.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:m,children:`Refresh`})})]}),Z(`div`,{children:!c&&(o?Z(`div`,{className:`card`,children:Z($,{title:`Update status unavailable`,detail:o})}):i?Z(ar,{components:i}):null)}),Z(`div`,{children:Z(lr,{data:u,error:f})}),Z(`div`,{children:n?Z(`div`,{className:`card`,children:Z($,{title:`Cannot reach archied`,detail:n})}):!e||Object.keys(e).length===0?Z(`div`,{className:`card`,children:Z($,{title:`No configuration loaded`,detail:`archied is running without a config file wired into the dashboard, so there is nothing to show.`})}):Z(S,{children:[e.reload?.overlay_unavailable&&Z(`div`,{className:`card cfg-notice`,children:Z(`p`,{children:[`The runtime config overlay is not in effect: `,e.reload.overlay_unavailable]})}),e.reload?.last_error&&Z(`div`,{className:`card cfg-notice`,children:Z(`p`,{children:[`The last config reload failed; the running config is unchanged: `,e.reload.last_error]})}),(e.schema||[]).map((t,n)=>{let r=t.fields.filter(e=>e.type!==`structured`);return r.length?Z(or,{title:t.label,sub:t.description,children:Z(`div`,{className:`kv-list`,children:r.map(t=>Z($n,{label:t.label,value:t.value,opts:{key:t.key,type:t.type,options:t.options,raw:t.value,hint:t.description,editable:t.editable&&e.editable!==!1,locked:e.locked||{},overridden:e.overridden||[],onSaved:h}},t.key))})},n):null}),Z(fr,{repos:e.repositories,onSaved:h,editable:e.editable!==!1}),Z(mr,{models:e.models,providers:e.providers}),Z(sr,{origins:e.provenance})]})})]})}function gr(e){return Z(hr,{query:e})}function _r({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function vr(e){switch((e||``).toUpperCase()){case`ERROR`:return`danger`;case`WARN`:return`warn`;case`DEBUG`:return`idle`;default:return`info`}}function yr(e){return e==null?``:typeof e==`object`?JSON.stringify(e):e}function br(e){let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?`--:--:--`:t.toTimeString().slice(0,8)}function xr({entry:e}){let t=e.fields||{};return Z(`div`,{className:`log-row log-${vr(e.level)}`,children:[Z(`span`,{className:`log-time mono`,children:br(e.time)}),Z(`span`,{className:`log-level`,children:(e.level||`info`).toUpperCase()}),Z(`span`,{className:`log-body`,children:[Z(`span`,{className:`log-msg`,children:e.message||e.msg||``}),Object.entries(t).map(([e,t])=>Z(`span`,{className:`log-field`,children:[Z(`span`,{className:`log-field-key`,children:e}),String(yr(t))]},e))]})]})}function Sr(e){return`${e.time||``}|${e.level||``}|${e.message||e.msg||``}|${JSON.stringify(e.fields||{})}`}function Cr(){let[e,t]=J({level:``,component:``,q:``}),[n,r]=J(!1),[i,a]=J([]),[o,s]=J([]),c=X(new Map),[l,u]=J(0),[d,f]=J(!1),[p,m]=J(`connecting`),[h,g]=J(`Refreshing…`),_=X(null),v=X(null),y=async()=>{g(`Refreshing…`);try{let t=await U.logs({level:e.level,component:e.component,q:e.q,limit:500});a(e=>{let n=t.components||[];return e.length===n.length&&e.every((e,t)=>e===n[t])?e:n}),f(!!t.disabled);let n=t.disabled?`Durable history unavailable; live daemon logs continue.`:t.truncated?`showing the most recent matches from ${t.file}`:t.file||``;g(n),s(t.entries||[])}catch{g(`Cannot read logs`)}};Y(()=>{y()},[e]),Y(()=>{let e=de(e=>{if(b.current)return;let t=e;S.current(t)&&(c.current.set(Sr(t),t),t.fields?.component&&a(e=>e.includes(t.fields.component)?e:[...e,t.fields.component]),u(e=>e+1))},e=>{m(e)});return()=>e()},[]);let b=X(n);b.current=n;let x=t=>{if(e.level&&!e.level.split(`,`).includes((t.level||``).toUpperCase())||e.component&&t.fields?.component!==e.component)return!1;if(e.q){let n=e.q.toLowerCase();if(!`${t.message||t.msg||``} ${JSON.stringify(t.fields||{})}`.toLowerCase().includes(n))return!1}return!0},S=X(x);S.current=x;let C=He(()=>{let e=new Map;for(let t of o)e.set(Sr(t),t);for(let[t,n]of c.current)e.set(t,n);return[...e.values()].filter(x).slice(-1e3)},[o,l,e]);return Y(()=>{_.current&&(_.current.scrollTop=_.current.scrollHeight)},[C]),Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Logs`}),Z(`p`,{className:`page-sub`,children:`What Archie has been doing, newest last.`})]}),Z(`div`,{className:`page-actions`,children:[Z(`button`,{className:`btn ${n?`btn-primary`:``}`,onClick:()=>r(!n),children:n?`Resume`:`Pause`}),Z(`button`,{className:`btn`,onClick:y,children:`Refresh`})]})]}),Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{className:`log-filters`,children:[Z(`select`,{className:`log-select`,value:e.level,onChange:e=>t(t=>({...t,level:e.target.value})),children:Et.map(e=>Z(`option`,{value:e.value,children:e.label},e.value))}),Z(`select`,{className:`log-select`,value:e.component,onChange:e=>t(t=>({...t,component:e.target.value})),children:[Z(`option`,{value:``,children:`All components`}),i.map(e=>Z(`option`,{value:e,children:e},e))]}),Z(`input`,{className:`log-search`,type:`search`,placeholder:`Search messages and fields…`,onInput:e=>{let n=e.target.value;v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{t(e=>({...e,q:n}))},250)}})]}),Z(`div`,{className:`log-status`,children:[Z(`span`,{className:`log-meta`,children:h}),Z(Q,{text:p,kind:p===`live`?`ok`:`warn`})]})]}),Z(`div`,{className:`log-list`,ref:_,children:h===`Cannot read logs`?Z(_r,{title:`Cannot read logs`}):C.length?C.map(e=>Z(xr,{entry:e},Sr(e))):Z(_r,{title:d?`Durable history unavailable`:`Nothing matches`,detail:d?`Live daemon logs will appear here while this page is open.`:`Try a wider level or clear the search.`})})]})]})}function wr(e){return Z(Cr,{query:e})}function Tr({capture:e,expanded:t,onToggle:n}){return Z(S,{children:[Z(`tr`,{className:`capture-row`,tabIndex:`0`,"aria-expanded":String(t),onClick:n,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),n(e))},children:[Z(`td`,{className:`mono`,children:e.source||`(unknown)`}),Z(`td`,{title:e.received_at||``,children:Ee(e.received_at)}),Z(`td`,{children:Z(Q,{text:`Unbound`,kind:`idle`})}),Z(`td`,{className:`mono`,children:e.content_type||`—`}),Z(`td`,{children:Z(`button`,{className:`btn btn-small`,type:`button`,children:t?`Hide`:`View`})})]}),t&&Z(Er,{capture:e})]})}function Er({capture:e}){return Z(`tr`,{className:`capture-detail-row`,children:Z(`td`,{colSpan:`5`,children:Z(`div`,{className:`capture-detail`,children:[Z(`div`,{className:`capture-detail-section`,children:[Z(`div`,{className:`capture-detail-title`,children:`Payload`}),Z(Dr,{raw:e.body})]}),Z(`div`,{className:`capture-detail-section`,children:[Z(`div`,{className:`capture-detail-title`,children:`Headers`}),Z(Dr,{raw:e.headers})]})]})})})}function Dr({raw:e}){return e?Z(`pre`,{className:`capture-payload`,children:Or(e)}):Z(`div`,{className:`capture-empty`,children:`(empty)`})}function Or(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function kr({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Ar(e){return Z(jr,{query:e})}function jr({query:e}){let[t,n]=J([]),[r,i]=J(null),[a,o]=J(null),[s,c]=J(!0),[l,u]=J({text:`connecting`,kind:`idle`}),d=async()=>{try{let e=await U.captures(100);c(e.enabled!==!1),n(e.captures||[]),o(null)}catch(e){o(String(e.message||e))}};return Y(()=>{d();let e=ue(e=>{e.kind===`capture`&&d()},e=>{u({text:e,kind:e===`live`?`ok`:`warn`})});return()=>e()},[]),Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Event inspector`}),Z(`p`,{className:`page-sub`,children:`Real inbound payloads archie has captured, most recent first.`})]}),Z(`div`,{className:`page-actions`,children:[Z(Q,{text:l.text,kind:l.kind}),Z(`button`,{className:`btn`,onClick:d,children:`Refresh`})]})]}),Z(`div`,{className:`card`,children:a?Z(kr,{title:`Cannot reach archied`,detail:a}):s?t.length?Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[`Source`,`Received`,`Binding`,`Content type`,``].map((e,t)=>Z(`th`,{children:e},t))})}),Z(`tbody`,{children:t.map(e=>Z(Tr,{capture:e,expanded:r===e.id,onToggle:()=>i(r===e.id?null:e.id)},e.id))})]})}):Z(kr,{title:`No captures yet`,detail:`Point a webhook at /webhooks/capture/ and it will show up here.`}):Z(kr,{title:`Capture is not configured`,detail:`This deployment has no capture storage wired up.`})})]})}var Mr=[`string`,`number`,`bool`,`object`,`array`,`any`];function Nr(e){if(e==null)return`any`;if(Array.isArray(e))return`array`;switch(typeof e){case`string`:return`string`;case`number`:return`number`;case`boolean`:return`bool`;case`object`:return`object`;default:return`any`}}function Pr(e,t){return e?`${e}.${t}`:t}function Fr(e,t){return`${e}[${t}]`}function Ir({value:e,path:t=``,name:n=``,onPick:r}){return typeof e==`object`&&e?Z(`ul`,{className:`mapping-tree-list`,children:(Array.isArray(e)?e.map((e,n)=>[String(n),e,Fr(t,n)]):Object.entries(e).map(([e,n])=>[e,n,Pr(t,e)])).map(([e,t,n])=>Z(`li`,{className:`mapping-tree-item`,children:[Z(`span`,{className:`mapping-tree-key`,onClick:i=>{i.stopPropagation(),r&&r({path:n,type:Nr(t),name:e})},children:e}),Z(Ir,{value:t,path:n,name:e,onPick:r})]},n))}):Z(`span`,{className:`mapping-tree-value`,onClick:i=>{i.stopPropagation(),r&&r({path:t,type:Nr(e),name:n})},children:JSON.stringify(e)})}function Lr({fields:e,preview:t,onRemove:n,onNameChange:r,onTypeChange:i,onRequiredChange:a}){if(!e.length)return Z(`div`,{className:`mapping-empty-fields`,children:`Click a value in the payload to bind a field.`});let o=new Map((t?.failures||[]).map(e=>[e.field_name,e]));return Z(`table`,{className:`table mapping-fields-table`,children:[Z(`thead`,{children:Z(`tr`,{children:[`Field name`,`Path`,`Type`,`Required`,`Preview`,``].map((e,t)=>Z(`th`,{children:e},t))})}),Z(`tbody`,{children:e.map((e,s)=>Z(`tr`,{children:[Z(`td`,{children:Z(`input`,{className:`mapping-input`,value:e.name,onInput:e=>r?.(s,e.target.value)})}),Z(`td`,{className:`mono`,children:e.path}),Z(`td`,{children:Z(`select`,{className:`mapping-select`,value:e.type,onChange:e=>i?.(s,e.target.value),children:Mr.map(e=>Z(`option`,{value:e,children:e},e))})}),Z(`td`,{children:Z(`input`,{type:`checkbox`,checked:e.required,onChange:e=>a?.(s,e.target.checked)})}),Z(`td`,{children:Z(Rr,{field:e,preview:t,failureByField:o})}),Z(`td`,{children:Z(`button`,{className:`btn btn-small`,type:`button`,onClick:()=>n?.(s),children:`Remove`})})]},s))})]})}function Rr({field:e,preview:t,failureByField:n}){if(!t)return Z(Q,{text:`not previewed`,kind:`idle`});let r=n.get(e.name);return r?Z(Q,{text:r.reason,kind:`danger`}):Object.prototype.hasOwnProperty.call(t.values||{},e.name)?Z(Q,{text:JSON.stringify(t.values[e.name]),kind:`ok`}):Z(Q,{text:`skipped (optional)`,kind:`idle`})}function zr({mapping:e,onEdit:t,onDelete:n}){return Z(`tr`,{children:[Z(`td`,{children:e.name}),Z(`td`,{className:`mono`,children:e.source_hint||`—`}),Z(`td`,{children:String(e.fields?.length??0)}),Z(`td`,{children:[Z(`button`,{className:`btn btn-small`,type:`button`,onClick:()=>t?.(e),children:`Edit`}),Z(`button`,{className:`btn btn-small`,type:`button`,onClick:()=>n?.(e),children:`Delete`})]})]})}function Br({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Vr(e){return Z(Hr,{query:e})}function Hr({query:e}){let[t,n]=J([]),[r,i]=J([]),[a,o]=J(null),[s,c]=J(null),l=async()=>{try{let[e,t]=await Promise.all([U.mappings(),U.captures(100)]);n(e.mappings||[]),i(t.captures||[]),o(null)}catch(e){o(String(e.message||e))}};Y(()=>{l()},[]);let u=()=>{c({id:null,name:``,sourceHint:``,fields:[],captureId:null,payload:null,payloadError:null,preview:null,actionError:null})},d=e=>{c({id:e.id,name:e.name,sourceHint:e.source_hint||``,fields:(e.fields||[]).map(e=>({...e})),captureId:null,payload:null,payloadError:null,preview:null,actionError:null})},f=async e=>{if(window.confirm(`Delete mapping "${e.name}"?`))try{await U.mappingDelete(e.id),await l()}catch(e){o(String(e.message||e))}},p=e=>{let t=r.find(t=>String(t.id)===String(e));c(e=>{let n={...e,captureId:t?t.id:null,preview:null};if(!t)n.payload=null,n.payloadError=null;else try{n.payload=JSON.parse(t.body),n.payloadError=null}catch{n.payload=null,n.payloadError=`This capture's body is not valid JSON, so its fields cannot be mapped by path.`}return n})},m=({path:e,type:t,name:n})=>{c(r=>{let i=new Set(r.fields.map(e=>e.name)),a=n||`field`,o=1;for(;i.has(a);)a=`${n||`field`}_${++o}`;let s=[...r.fields,{name:a,path:e,type:t,required:!0}];return{...r,fields:s,preview:null}})},h=e=>{c(t=>{let n=t.fields.slice();return n.splice(e,1),{...t,fields:n,preview:null}})},g=(e,t)=>{c(n=>{let r=n.fields.slice();return r[e]={...r[e],...t},{...n,fields:r,preview:null}})};return s?Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:Z(`h1`,{className:`page-title`,children:s.id?`Edit mapping`:`New mapping`})}),Z(`div`,{className:`page-actions`,children:[Z(`button`,{className:`btn`,type:`button`,onClick:()=>{c(null)},children:`Cancel`}),Z(`button`,{className:`btn btn-primary`,type:`button`,onClick:async()=>{let e={name:s.name,source_hint:s.sourceHint,fields:s.fields};try{s.id?await U.mappingUpdate(s.id,e):await U.mappingCreate(e),c(null),await l()}catch(e){c(t=>({...t,actionError:String(e.message||e)}))}},children:`Save`})]})]}),s.actionError&&Z(`div`,{className:`mapping-error`,children:s.actionError}),Z(`div`,{className:`card mapping-form`,children:[Z(`label`,{className:`mapping-form-row`,children:[`Name`,Z(`input`,{className:`mapping-input`,value:s.name,onInput:e=>c(t=>({...t,name:e.target.value}))})]}),Z(`label`,{className:`mapping-form-row`,children:[`Source hint (organisational only)`,Z(`input`,{className:`mapping-input`,value:s.sourceHint,onInput:e=>c(t=>({...t,sourceHint:e.target.value}))})]}),Z(`label`,{className:`mapping-form-row`,children:[`Preview against captured event`,Z(`select`,{className:`mapping-select`,value:s.captureId||``,onChange:e=>p(e.target.value),children:[Z(`option`,{value:``,children:`— pick a captured event —`}),r.map(e=>Z(`option`,{value:e.id,children:[e.source||`(unknown)`,` — `,e.received_at||``]},e.id))]})]})]}),Z(`div`,{className:`card mapping-fields`,children:[Z(`div`,{className:`mapping-section-title`,children:`Bound fields`}),Z(Lr,{fields:s.fields,preview:s.preview,onRemove:h,onNameChange:(e,t)=>g(e,{name:t}),onTypeChange:(e,t)=>g(e,{type:t}),onRequiredChange:(e,t)=>g(e,{required:t})}),Z(`button`,{className:`btn`,type:`button`,onClick:async()=>{if(!s.captureId){c(e=>({...e,actionError:`Pick a captured event to preview against.`}));return}try{let e=await U.mappingPreview(s.captureId,s.fields);c(t=>({...t,preview:e,actionError:null}))}catch(e){c(t=>({...t,actionError:String(e.message||e)}))}},children:`Preview`})]}),Z(`div`,{className:`card mapping-payload`,children:[Z(`div`,{className:`mapping-section-title`,children:`Payload — click a value to bind it`}),s.payloadError?Z(`div`,{className:`mapping-error`,children:s.payloadError}):s.payload===null?Z(`div`,{className:`mapping-empty-fields`,children:`Pick a captured event above to see its payload.`}):Z(Ir,{value:s.payload,onPick:m})]})]}):Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Field mappings`}),Z(`p`,{className:`page-sub`,children:`Bind named fields to JSON paths from a real captured event, ready for a playbook binding.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn btn-primary`,type:`button`,onClick:u,children:`New mapping`})})]}),a?Z(Br,{title:`Cannot reach archied`,detail:a}):t.length?Z(`div`,{className:`card`,children:Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[`Name`,`Source hint`,`Fields`,``].map((e,t)=>Z(`th`,{children:e},t))})}),Z(`tbody`,{children:t.map(e=>Z(zr,{mapping:e,onEdit:()=>d(e),onDelete:()=>f(e)},e.id))})]})})}):Z(Br,{title:`No mappings yet`,detail:`Create one from a captured event to reuse fields in a future playbook binding.`})]})}var Ur={draft:`draft`,pending_approval:`pending approval`,armed:`armed`},Wr={draft:`idle`,pending_approval:`warn`,armed:`ok`};function Gr({status:e}){return Z(Q,{text:Ur[e]||e,kind:Wr[e]||`idle`})}function Kr({binding:e,onEdit:t,onApprove:n,onDelete:r}){let i=e.owner&&e.repo?`${e.owner}/${e.repo}`:`—`;return Z(`tr`,{children:[Z(`td`,{children:e.name}),Z(`td`,{className:`mono`,children:e.matcher?.source||`—`}),Z(`td`,{children:e.workflow}),Z(`td`,{className:`mono`,children:i}),Z(`td`,{children:Z(Gr,{status:e.status})}),Z(`td`,{children:[Z(`button`,{className:`btn btn-small`,type:`button`,onClick:()=>t?.(e),children:`Edit`}),e.status===`pending_approval`&&Z(`button`,{className:`btn btn-small btn-primary`,type:`button`,onClick:()=>n?.(e),children:`Approve`}),Z(`button`,{className:`btn btn-small`,type:`button`,onClick:()=>r?.(e),children:`Delete`})]})]})}function qr({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Jr(e){return Z(Xr,{query:e})}function Yr(){return{id:null,name:``,source:``,mappingId:``,workflow:``,owner:``,repo:``,secret:``,actionError:null}}function Xr({query:e}){let[t,n]=J([]),[r,i]=J([]),[a,o]=J([]),[s,c]=J(null),[l,u]=J(null),d=async()=>{try{let[e,t,r]=await Promise.all([U.bindings(),U.mappings(),U.workflows()]);n(e.bindings||[]),i(t.mappings||[]),o((r.definitions||[]).filter(e=>e.enabled)),c(null)}catch(e){c(String(e.message||e))}};Y(()=>{d()},[]);let f=()=>{u(Yr())},p=e=>{u({id:e.id,name:e.name,source:e.matcher?.source||``,mappingId:e.mapping_id?String(e.mapping_id):``,workflow:e.workflow||``,owner:e.owner||``,repo:e.repo||``,secret:``,actionError:null})},m=()=>u(null),h=async()=>{let e={name:l.name,matcher:{source:l.source},mapping_id:Number(l.mappingId)||0,workflow:l.workflow,owner:l.owner,repo:l.repo,secret:l.secret};try{l.id?await U.bindingUpdate(l.id,e):await U.bindingCreate(e),u(null),await d()}catch(e){u(t=>({...t,actionError:String(e.message||e)}))}},g=async e=>{try{await U.bindingApprove(e.id),await d()}catch(e){c(String(e.message||e))}},_=async e=>{if(window.confirm(`Delete binding "${e.name}"?`))try{await U.bindingDelete(e.id),await d()}catch(e){c(String(e.message||e))}};return l?Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:Z(`h1`,{className:`page-title`,children:l.id?`Edit binding`:`New binding`})}),Z(`div`,{className:`page-actions`,children:[Z(`button`,{className:`btn`,type:`button`,onClick:m,children:`Cancel`}),Z(`button`,{className:`btn btn-primary`,type:`button`,onClick:h,children:`Save`})]})]}),l.actionError&&Z(`div`,{className:`binding-error`,children:l.actionError}),Z(`div`,{className:`card binding-form`,children:[Z(`label`,{className:`binding-form-row`,children:[`Name`,Z(`input`,{className:`binding-input`,value:l.name,onInput:e=>u(t=>({...t,name:e.target.value}))})]}),Z(`label`,{className:`binding-form-row`,children:[`Source (the path segment senders POST to, e.g. "sentry")`,Z(`input`,{className:`binding-input`,value:l.source,onInput:e=>u(t=>({...t,source:e.target.value}))})]}),Z(`label`,{className:`binding-form-row`,children:[`Field mapping`,Z(`select`,{className:`binding-select`,value:l.mappingId,onChange:e=>u(t=>({...t,mappingId:e.target.value})),children:[Z(`option`,{value:``,children:`— pick a saved mapping —`}),r.map(e=>Z(`option`,{value:e.id,children:e.name},e.id))]})]}),Z(`label`,{className:`binding-form-row`,children:[`Workflow`,Z(`select`,{className:`binding-select`,value:l.workflow,onChange:e=>u(t=>({...t,workflow:e.target.value})),children:[Z(`option`,{value:``,children:`— pick a workflow —`}),a.map(e=>Z(`option`,{value:e.id,children:e.name},e.id))]})]}),Z(`label`,{className:`binding-form-row`,children:[`Repo pin -- owner (optional; leave both blank for the single-configured-repo default)`,Z(`input`,{className:`binding-input`,value:l.owner,onInput:e=>u(t=>({...t,owner:e.target.value}))})]}),Z(`label`,{className:`binding-form-row`,children:[`Repo pin -- repo`,Z(`input`,{className:`binding-input`,value:l.repo,onInput:e=>u(t=>({...t,repo:e.target.value}))})]}),Z(`label`,{className:`binding-form-row`,children:[`Shared secret (`,l.id?`leave blank to keep the current secret`:`senders sign with this via HMAC-SHA256`,`)`,Z(`input`,{className:`binding-input`,type:`password`,value:l.secret,onInput:e=>u(t=>({...t,secret:e.target.value}))})]})]})]}):Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Playbook bindings`}),Z(`p`,{className:`page-sub`,children:`Tie a matcher, a field mapping, and a workflow together. New and edited bindings need explicit approval before they can fire.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn btn-primary`,type:`button`,onClick:f,children:`New binding`})})]}),s?Z(qr,{title:`Cannot reach archied`,detail:s}):t.length?Z(`div`,{className:`card`,children:Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[`Name`,`Source`,`Workflow`,`Repo pin`,`Status`,``].map((e,t)=>Z(`th`,{children:e},t))})}),Z(`tbody`,{children:t.map(e=>Z(Kr,{binding:e,onEdit:()=>p(e),onApprove:()=>g(e),onDelete:()=>_(e)},e.id))})]})})}):Z(qr,{title:`No bindings yet`,detail:`Create one from a saved field mapping to turn a captured webhook into a workflow.`})]})}function Zr({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Qr(e){return e===`external`?`Added by you — an external store Archie was given`:`Built in — always available to Archie`}function $r({provider:e}){let t=e.tools||[];return Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:e.name||`provider`}),Z(`p`,{className:`card-sub`,children:Qr(e.role)})]}),e.available?Z(Q,{text:`ready`,kind:`ok`}):Z(Q,{text:`unavailable`,kind:`danger`})]}),!e.available&&Z(`p`,{className:`mem-warning`,children:`Configured but not usable right now — a required binary or connection may be missing.`}),t.length?Z(`ul`,{className:`mem-tools`,children:t.map((e,t)=>Z(`li`,{className:`mem-tool`,children:[Z(`div`,{className:`mem-tool-name mono`,children:e.name}),e.description&&Z(`div`,{className:`mem-tool-desc`,children:e.description})]},t))}):Z(`p`,{className:`mem-warning`,children:`This provider exposes no tools, so the agent cannot use it.`})]})}function ei(){let[e,t]=J(null),[n,r]=J(!0),[i,a]=J(null),[o,s]=J(!0),c=async()=>{s(!0),a(null);try{let e=await U.memory();r(!!e.enabled),t(e.providers||[])}catch(e){a(String(e.message||e))}finally{s(!1)}};return Y(()=>{c()},[]),Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Memory`}),Z(`p`,{className:`page-sub`,children:`What Archie can recall between conversations, and the tools it uses to do it.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:c,children:`Refresh`})})]}),Z(`div`,{children:o?Z(`div`,{className:`card`,children:Z(`div`,{className:`mem-loading`,children:`Loading…`})}):i?Z(`div`,{className:`card`,children:Z(Zr,{title:`Cannot read memory providers`,detail:i})}):!n||!e.length?Z(`div`,{className:`card`,children:Z(Zr,{title:`Memory is not configured`,detail:`Without a provider, Archie starts every conversation with no recollection of earlier ones.`})}):Z(`div`,{className:`grid grid-2`,children:e.map((e,t)=>Z($r,{provider:e},t))})})]})}function ti(e){return Z(ei,{query:e})}function ni(e){let t=document.createDocumentFragment(),n=/(!\[[^\]]*\]\((?:https?:\/\/[^\s)]+|data:image\/[^\s)]+|\/[^\s)]+)\)|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\((?:https?:\/\/[^\s)]+|\/[^\s)]+)\)|\*[^*]+\*|_[^_]+_)/g,r=0;for(let i of e.matchAll(n)){i.index>r&&t.append(document.createTextNode(e.slice(r,i.index)));let n=i[0];if(n.startsWith(`![`)){let e=n.match(/^!\[([^\]]*)\]\((.+)\)$/);e&&t.append(W(`img.chat-media-img`,{src:e[2],alt:e[1]||`Image`,loading:`lazy`}))}else if(n.startsWith(`~~`))t.append(W(`del`,n.slice(2,-2)));else if(n.startsWith(`**`)||n.startsWith(`__`))t.append(W(`strong`,n.slice(2,-2)));else if(n.startsWith("`"))t.append(W(`code`,n.slice(1,-1)));else if(n.startsWith(`[`)){let e=n.match(/^\[([^\]]+)\]\((https?:\/\/[^\s)]+|\/[^\s)]+)\)$/);t.append(W(`a`,{href:e[2],target:`_blank`,rel:`noreferrer`},e[1]))}else t.append(W(`em`,n.slice(1,-1)));r=i.index+n.length}return r{r.length&&(t.append(W(`p`,ni(r.join(` `)))),r=[])},s=()=>{i&&t.append(i),i=null};for(let e=0;eW(`td`,ni(e)))));t.append(W(`table`,W(`thead`,W(`tr`,...l.map(e=>W(`th`,ni(e))))),i));continue}if(!c.trim()){o(),s();continue}let d=c.match(/^(#{1,3})\s+(.+)$/);if(d){o(),s(),t.append(W(`h${d[1].length}`,ni(d[2])));continue}let f=c.match(/^\s*[-*]\s+(.+)$/),p=c.match(/^\s*\d+[.)]\s+(.+)$/);if(f||p){o();let e=p?`ol`:`ul`;(!i||i.tagName.toLowerCase()!==e)&&(s(),i=W(e)),i.append(W(`li`,ni((f||p)[1])));continue}if(c.startsWith(`>`)){o(),s(),t.append(W(`blockquote`,ni(c.replace(/^>\s?/,``))));continue}r.push(c)}return o(),s(),a&&t.append(W(`pre`,W(`code`,a.join(` diff --git a/ui/src/tasks/task-detail.jsx b/ui/src/tasks/task-detail.jsx index 6210ff7b8..bf31eec35 100644 --- a/ui/src/tasks/task-detail.jsx +++ b/ui/src/tasks/task-detail.jsx @@ -544,5 +544,13 @@ export function taskDetailPage(query, params) { const raw = params?.id; const id = parseTaskId(raw); if (id === null) return ; - return ; + // The key is load-bearing, not cosmetic. The router renders this page with + // Preact's own render() into one long-lived outlet (main.jsx, show()), so + // navigating from #/tasks/1 to #/tasks/2 diffs the same element in place and + // RunDetail is never remounted. Without the key every piece of task-scoped + // state -- the open tab, the pinned attempt, the run history, the events, and + // the log/change/debug caches -- stays with the task that was left, and the + // new task is rendered against another task's reads. Keying by id makes the + // remount RunDetail's own comment assumes actually happen. + return ; } diff --git a/ui/test/main-routing.test.js b/ui/test/main-routing.test.js index 367a03c96..78768f74d 100644 --- a/ui/test/main-routing.test.js +++ b/ui/test/main-routing.test.js @@ -77,6 +77,25 @@ test("the app routes deep links and keeps the navigation highlight honest", asyn assert.equal(navCurrent("/tasks"), "page"); }); + // The real router, not a reconstruction of it: show() renders the run page with + // Preact's render() into one long-lived outlet, so two task ids on the same + // matched route must still be two component instances. Without a key on the + // page element the second id diffs the first one in place and the operator's + // Log tab from task 7 is still open on task 8. + await t.test("moving to another task id does not keep the previous task's panel", async () => { + await navigate("#/tasks/8"); + await waitFor(() => assert.equal(title(), "Task #8")); + const selected = [...document.querySelectorAll('[role="tab"]')].find( + (tab) => tab.getAttribute("aria-selected") === "true", + ); + assert.equal( + selected.textContent, + "Stages", + "W11: a new task id must remount the page, not inherit the previous task's open tab", + ); + assert.equal(navCurrent("/tasks"), "page"); + }); + await t.test("the existing task deep links keep working", async () => { await navigate("#/tasks?task=7&status=needs_you"); await waitFor(() => assert.equal(title(), "Tasks")); diff --git a/ui/test/task-detail.test.js b/ui/test/task-detail.test.js index 6088b16a8..10050dec9 100644 --- a/ui/test/task-detail.test.js +++ b/ui/test/task-detail.test.js @@ -1,6 +1,7 @@ import { test } from "node:test"; import assert from "node:assert/strict"; import { render, cleanup, fireEvent, waitFor } from "@testing-library/preact"; +import { render as preactRender } from "preact"; import { api, ApiError } from "../src/base/api.jsx"; import { taskDetailPage } from "../src/tasks/task-detail.jsx"; @@ -398,4 +399,68 @@ test("a failure to load the attempts offers a retry", async () => { restore(); }); +// The router renders the run page with Preact's own render() into one long-lived +// outlet (main.jsx, show()), so moving from one task id to another diffs the same +// component in place rather than mounting a fresh one. Every piece of task-scoped +// state therefore has to be re-established when the id changes -- otherwise the +// new task is shown with the previous task's tab, pinned attempt, run history and +// events. RunDetail's own comment relies on this ("the route remounts it when +// that changes"), so navigating between two ids is the case to pin. +test("navigating to another task id re-establishes the task-scoped reads and selections", async () => { + const attemptReads = []; + const eventReads = []; + const { restore } = install({ + taskAttempts: async (id) => { + attemptReads.push(String(id)); + return ATTEMPTS; + }, + task: async (id) => { + eventReads.push(String(id)); + return EVENTS; + }, + }); + const host = document.createElement("div"); + document.body.appendChild(host); + + // Task 1, opened pinned to its earlier attempt and to the Log tab. + preactRender(taskDetailPage(new URLSearchParams("tab=log&attempt=1"), { id: "1" }), host); + await waitFor(() => assert.equal(attemptReads.length, 1)); + const selectedTab = () => + [...host.querySelectorAll('[role="tab"]')].find( + (tab) => tab.getAttribute("aria-selected") === "true", + ); + const pressedAttempt = () => + [...host.querySelectorAll(".run-attempt")].find( + (chip) => chip.getAttribute("aria-pressed") === "true", + ); + assert.equal(selectedTab().textContent, "Log"); + assert.match(pressedAttempt().textContent, /Attempt 1/); + + // The router's own navigation: the same matched route, a different captured id, + // the same outlet. Nothing unmounts, so no state is cleared for free. + preactRender(taskDetailPage(new URLSearchParams(""), { id: "2" }), host); + + await waitFor(() => + assert.equal(attemptReads.length, 2, "the new task's run history must be re-read"), + ); + assert.equal(attemptReads[1], "2", "the run history must be read for the new task's id"); + assert.equal(eventReads.length, 2, "the new task's events must be re-read"); + assert.equal(eventReads[1], "2", "the events must be read for the new task's id"); + + assert.equal( + selectedTab().textContent, + "Stages", + "the previous task's tab must not carry over to the new task", + ); + assert.match( + pressedAttempt().textContent, + /Attempt 2/, + "the previous task's pinned attempt must not carry over to the new task", + ); + + preactRender(null, host); + host.remove(); + restore(); +}); + test.after(() => cleanup());