Files
archie/ui/dist/assets/index.js
T
sam 68ba3456ee feat(webui): chat from the dashboard
Brings the chat surface to the Web UI: /api/chat with its own handlers
and tests, a self-contained ui/src/chat feature folder, and the shared
plumbing to reach the same router Telegram uses.

Includes a dangerous-command approval path (internal/gateway/dangerous.go,
internal/webui/dangerous.go, and the Telegram counterpart) so /rollback
and /stop are gated the same way on both surfaces, persona handling for
web sessions, and release-update formatting split out of the Telegram
service so both can render it.

web_parity_test.go pins that the two surfaces expose the same commands.

Authored in a parallel session; committed here so it lands with the rest
rather than sitting uncommitted while other work builds on top of it.
task check passes with it in place.

Screenshots used while building are gitignored (*.png) rather than
committed, matching the call made on the earlier design reference.
2026-08-05 10:48:51 +10:00

15 lines
52 KiB
JavaScript

(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();function e(e,n,...r){let[i,...a]=e.split(`.`),o=document.createElement(i||`div`);a.length&&(o.className=a.join(` `)),n!==void 0&&(typeof n!=`object`||n instanceof Node)&&(r.unshift(n),n=null);for(let[e,t]of Object.entries(n||{}))t!=null&&t!==!1&&(e.startsWith(`on`)&&typeof t==`function`?o.addEventListener(e.slice(2).toLowerCase(),t):e===`class`?o.className=[o.className,t].filter(Boolean).join(` `):e===`html`?o.innerHTML=t:o.setAttribute(e,t===!0?``:String(t)));return t(o,r),o}function t(e,t){for(let n of t.flat(1/0))n!=null&&n!==!1&&e.append(n instanceof Node?n:document.createTextNode(String(n)))}function n(e,...n){return e.replaceChildren(),t(e,n),e}function r(t,n=`idle`){return e(`span.pill.pill-${n}`,t)}function i(e){switch(e){case`running`:return`info`;case`merged`:case`pr_open`:return`ok`;case`parked`:case`waiting_human`:return`warn`;case`dead`:case`rejected`:return`danger`;default:return`idle`}}function a(e){if(!e)return`—`;let t=e instanceof Date?e:new Date(e),n=Math.floor((Date.now()-t.getTime())/1e3);if(!Number.isFinite(n))return`—`;if(n<45)return`just now`;let r=[[`min`,60],[`hr`,3600],[`day`,86400],[`wk`,604800]],i=`min`,a=60;for(let[e,t]of r)n>=t&&([i,a]=[e,t]);let o=Math.floor(n/a);return`${o} ${i}${o===1?``:`s`} ago`}function o(e){return e==null||Number.isNaN(e)?`—`:new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1}).format(e)}function s(t,n){return e(`div.empty`,e(`div.empty-title`,t),n&&e(`div`,n))}var c={dashboard:`<rect x="3" y="3" width="7" height="9" rx="1.5"/><rect x="14" y="3" width="7" height="5" rx="1.5"/><rect x="14" y="12" width="7" height="9" rx="1.5"/><rect x="3" y="16" width="7" height="5" rx="1.5"/>`,chat:`<path d="M4 5.5A2.5 2.5 0 0 1 6.5 3h11A2.5 2.5 0 0 1 20 5.5v7a2.5 2.5 0 0 1-2.5 2.5H11l-4.5 4v-4.1A2.5 2.5 0 0 1 4 12.5z"/><path d="M8 8h8M8 11h5"/>`,tasks:`<path d="M9 6h11M9 12h11M9 18h11"/><path d="M4 6l1 1 2-2M4 12l1 1 2-2M4 18l1 1 2-2"/>`,logs:`<path d="M4 5h16M4 10h16M4 15h10M4 20h7"/>`,skills:`<path d="M12 3l2.6 5.6 6.1.8-4.5 4.2 1.2 6-5.4-3-5.4 3 1.2-6L3.3 9.4l6.1-.8z"/>`,workflows:`<path d="M4 7h6a3 3 0 0 1 3 3v4a3 3 0 0 0 3 3h4"/><path d="M17 4l3 3-3 3"/><path d="M7 21l-3-3 3-3"/>`,memory:`<circle cx="12" cy="12" r="3.2"/><path d="M12 3v3.4M12 17.6V21M3 12h3.4M17.6 12H21M5.6 5.6l2.4 2.4M16 16l2.4 2.4M18.4 5.6L16 8M8 16l-2.4 2.4"/>`,channels:`<rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3.5 7l8.5 6 8.5-6"/>`,settings:`<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.9l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-2.9 1.2V21a2 2 0 1 1-4 0v-.1A1.7 1.7 0 0 0 7 19.4a1.7 1.7 0 0 0-1.9.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1A1.7 1.7 0 0 0 3 15H3a2 2 0 1 1 0-4h.1A1.7 1.7 0 0 0 4.6 7a1.7 1.7 0 0 0-.3-1.9l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1A1.7 1.7 0 0 0 9 3.6V3a2 2 0 1 1 4 0v.1A1.7 1.7 0 0 0 15 4.6h.1a1.7 1.7 0 0 0 1.9-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.9V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z"/>`,search:`<circle cx="11" cy="11" r="7"/><path d="M20 20l-3.6-3.6"/>`,moon:`<path d="M20 14.5A8.5 8.5 0 0 1 9.5 4a8.5 8.5 0 1 0 10.5 10.5z"/>`,sun:`<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M2 12h2M20 12h2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M19.1 4.9l-1.4 1.4M6.3 17.7l-1.4 1.4"/>`,refresh:`<path d="M20 11a8 8 0 1 0-1.2 5.2"/><path d="M20 4v7h-7"/>`,bell:`<path d="M18 9a6 6 0 1 0-12 0c0 6-2 7-2 7h16s-2-1-2-7"/><path d="M13.7 20a2 2 0 0 1-3.4 0"/>`,trendUp:`<path d="M4 17L10 11l4 4 6-6"/><path d="M14 7h6v6"/>`,trendDown:`<path d="M4 7l6 6 4-4 6 6"/><path d="M14 17h6v-6"/>`,check:`<path d="M4.5 12.5l5 5 10-11"/>`,help:`<circle cx="12" cy="12" r="9"/><path d="M9.6 9.4a2.5 2.5 0 1 1 3.3 2.4c-.6.2-.9.8-.9 1.4v.4"/><path d="M12 17.2h.01"/>`};function l(e,{size:t=18,className:n=``}={}){let r=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);return r.setAttribute(`viewBox`,`0 0 24 24`),r.setAttribute(`width`,String(t)),r.setAttribute(`height`,String(t)),r.setAttribute(`fill`,`none`),r.setAttribute(`stroke`,`currentColor`),r.setAttribute(`stroke-width`,`1.6`),r.setAttribute(`stroke-linecap`,`round`),r.setAttribute(`stroke-linejoin`,`round`),r.setAttribute(`aria-hidden`,`true`),r.setAttribute(`class`,`ico ${n}`.trim()),r.innerHTML=c[e]||c.dashboard,r}async function u(e){let t=await fetch(e,{headers:{Accept:`application/json`},signal:AbortSignal.timeout(15e3)});if(t.status===401)throw new p(`unauthorised`,401);if(!t.ok)throw new p(`${t.status} ${t.statusText}`,t.status);return t.json()}function d(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e||{}))r!==``&&r!=null&&t.set(n,r);let n=t.toString();return n?`?${n}`:``}async function f(e){try{let t=(await e.text()).trim();if(t)return t.split(`
`)[0].slice(0,200)}catch{}return`${e.status} ${e.statusText}`}var p=class extends Error{constructor(e,t){super(e),this.status=t}},m={summary:()=>u(`/api/summary`),tasks:()=>u(`/api/tasks`),task:e=>u(`/api/tasks/${e}`),taskAction:async(e,t)=>{let n=await fetch(`/api/tasks/${e}/action`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({action:t}),signal:AbortSignal.timeout(15e3)});if(!n.ok)throw new p(await f(n),n.status);return n.json()},setup:()=>u(`/api/setup`),workflows:()=>u(`/api/workflows`),skills:()=>u(`/api/skills`),channels:()=>u(`/api/channels`),config:()=>u(`/api/config`),logs:e=>u(`/api/logs`+d(e)),memory:()=>u(`/api/memory`),chatSessions:()=>u(`/api/chat/sessions`),chatMessages:e=>u(`/api/chat/sessions/${encodeURIComponent(e)}/messages`),chatCancel:async e=>{let t=await fetch(`/api/chat/cancel`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({session_id:e}),signal:AbortSignal.timeout(15e3)});if(!t.ok)throw new p(await f(t),t.status);return t.json()},chatMessage:async(e,t)=>{let n=await fetch(`/api/chat/message`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({channel_id:e,source_id:crypto.randomUUID(),text:t}),signal:AbortSignal.timeout(15e3)});if(!n.ok)throw new p(await f(n),n.status);return n.json()},chatPersona:async(e,t)=>{let n=await fetch(`/api/chat/persona`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({session_id:e,name:t}),signal:AbortSignal.timeout(15e3)});if(!n.ok)throw new p(await f(n),n.status);return n.json()},chatUpdate:()=>u(`/api/chat/update`),chatUpdateDefer:async e=>{let t=await fetch(`/api/chat/update/defer`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({snapshot:e}),signal:AbortSignal.timeout(15e3)});if(!t.ok)throw new p(await f(t),t.status);return t.json()},chatUpdateInstall:async e=>{let t=await fetch(`/api/chat/update/install`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({snapshot:e}),signal:AbortSignal.timeout(12e4)});if(!t.ok)throw new p(await f(t),t.status);return t.json()},chatDangerous:()=>u(`/api/chat/dangerous`),chatDangerousRequest:async(e,t)=>{let n=await fetch(`/api/chat/dangerous/${encodeURIComponent(e)}`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({spec:t}),signal:AbortSignal.timeout(15e3)});if(!n.ok)throw new p(await f(n),n.status);return n.json()},chatDangerousDecision:async(e,t)=>{let n=await fetch(`/api/chat/dangerous/${encodeURIComponent(e)}/decision`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({decision:t}),signal:AbortSignal.timeout(15e3)});if(!n.ok)throw new p(await f(n),n.status);return n.json()}};function h(e,t){let n=new EventSource(`/events`);return n.onopen=()=>t?.(`live`),n.onerror=()=>t?.(`reconnecting`),n.onmessage=t=>{try{e(JSON.parse(t.data))}catch{}},()=>n.close()}function g({label:t,value:n,unit:r,trend:i,compare:a,series:o=[],goodDirection:s=`up`}){let c=i==null?null:i>=0?`up`:`down`,u=c==null?null:c===s;return e(`div.card.stat`,e(`div.stat-head`,e(`span.stat-label`,t),c&&e(`span.stat-trend.${u?`up`:`down`}`,l(c===`up`?`trendUp`:`trendDown`,{size:13}),`${Math.abs(i).toFixed(1)}%`)),e(`div.stat-value`,n,r&&e(`span.stat-unit`,r)),a&&e(`div.stat-compare`,a),o.length>1&&_(o,u===!1?`var(--danger)`:`var(--ok)`))}function _(t,n=`var(--ok)`,{width:r=220,height:i=34}={}){let a=Math.max(...t,1),o=Math.min(...t,0),s=a-o||1,c=t.length>1?r/(t.length-1):r,l=t.map((e,t)=>`${(t*c).toFixed(1)},${(i-(e-o)/s*i).toFixed(1)}`).join(` `),u=e(`svg.spark`,{viewBox:`0 0 ${r} ${i}`,preserveAspectRatio:`none`,"aria-hidden":`true`});return u.innerHTML=`<polyline points="${l}" fill="none" stroke="${n}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" vector-effect="non-scaling-stroke"/>`,u}function v({value:t,label:n,size:r=168}){let i=Math.max(0,Math.min(100,Number(t)||0)),a=i>=90?`var(--ok)`:i>=70?`var(--warn)`:`var(--danger)`,o=r/2,s=r/2,c=2*Math.PI*62*(240/360),l=(e,t)=>{let n=e*Math.PI/180,r=(e+t)*Math.PI/180,i=+(t>180);return[`M ${o+62*Math.cos(n)} ${s+62*Math.sin(n)}`,`A 62 62 0 ${i} 1 ${o+62*Math.cos(r)} ${s+62*Math.sin(r)}`].join(` `)},u=e(`svg.gauge`,{viewBox:`0 0 ${r} ${r*.78}`,role:`img`,"aria-label":`${n}: ${i}%`});return u.innerHTML=`
<path d="${l(150,240)}" fill="none" stroke="var(--border)"
stroke-width="12" stroke-linecap="round"/>
<path d="${l(150,240)}" fill="none" stroke="${a}"
stroke-width="12" stroke-linecap="round"
stroke-dasharray="${c}"
stroke-dashoffset="${c*(1-i/100)}"
class="gauge-value"/>`,e(`div.gauge-wrap`,u,e(`div.gauge-center`,e(`div.gauge-pct`,`${Math.round(i)}%`),e(`div.gauge-label`,n)))}function y(t){let n=t.reduce((e,t)=>e+(t.value||0),0)||1;return e(`div`,e(`div.segbar`,...t.filter(e=>e.value>0).map(t=>e(`span`,{class:`segbar-part segbar-${t.kind||`idle`}`,style:`width:${(t.value/n*100).toFixed(1)}%`,title:`${t.label}: ${t.value}`}))),e(`div.segbar-legend`,...t.map(t=>e(`span.segbar-key`,e(`span`,{class:`segbar-dot segbar-${t.kind||`idle`}`}),t.label))))}function b(){let t=e(`div`),i=e(`tbody`),a=e(`div.grid.grid-4`),c=e(`div`),u=e(`div`),d=e(`div.dash-top`,c,u),f=e(`div`),p=e(`div.hero-actions-inner`),_=e(`h1.hero-title`,C()),v=r(`connecting`,`idle`),y=[],b=new Map;D(),k();let S=h(e=>{y.unshift(e),y.splice(50),O()},e=>{v.className=`pill pill-${e===`live`?`ok`:`warn`}`,v.textContent=e});t.addEventListener(`archie:teardown`,S);function D(){n(t,e(`div.hero`,e(`div`,_,e(`p.hero-sub`,`Your agent's control room — what it is working on, what needs you, and what it is spending.`)),e(`div.hero-actions`,p)),e(`div.dash-section`,e(`div.dash-section-head`,e(`h2.dash-section-title`,`Health`)),d),e(`div.dash-section`,e(`div.dash-section-head`,e(`h2.dash-section-title`,`Throughput`),e(`span.dash-section-note`,`Across all repositories`)),a),e(`div.dash-section`,e(`div.dash-section-head`,e(`h2.dash-section-title`,`Right now`)),e(`div.dash-split`,f,e(`div.card`,e(`div.card-head`,e(`div`,e(`h2.card-title`,`Live activity`),e(`p.card-sub`,`Last 50, newest first`)),v),e(`div.table-scroll`,e(`table.table`,e(`thead`,e(`tr`,...[`Event`,`Task`,`Detail`,`When`].map(t=>e(`th`,t)))),i)))))),O()}function O(){if(!y.length){n(i,e(`tr`,e(`td`,{colspan:4},s(`Waiting for activity`,`Events appear here as Archie works.`))));return}n(i,...y.map(e=>x(e,b)))}async function k(){try{let[e,t,n,r]=await Promise.all([m.summary(),m.setup().catch(()=>null),m.workflows().catch(()=>null),m.tasks().catch(()=>[])]);b.clear();for(let e of r)e.owner&&e.repo&&e.issue_number&&b.set(`${e.owner}/${e.repo}#${e.issue_number}`,e.id);O(),A(e),_.textContent=t?.operator?`${C()}, ${t.operator}`:C(),j(e),M(t),N(e,n),P(e)}catch(t){n(a,e(`div.card`,s(`Cannot reach archied`,String(t.message||t)))),n(p,e(`button.btn.btn-primary`,{onclick:k},l(`refresh`,{size:15}),`Retry`))}}function A(t){let r=t?.statuses||{},i=(r.parked||0)+(r.waiting_human||0),a=r.running||0;n(p,i>0&&e(`a.btn.btn-attention`,{href:`#/tasks`},l(`tasks`,{size:15}),`${i} need${i===1?`s`:``} you`),a>0&&e(`a.btn`,{href:`#/tasks`},l(`workflows`,{size:15}),`${a} running`),e(`a.btn`,{href:`#/logs`},l(`logs`,{size:15}),`Logs`),e(`button.btn.btn-primary`,{onclick:k},l(`refresh`,{size:15}),`Refresh`))}function j(e){let t=e?.statuses||{},r=(t.merged||0)+(t.pr_open||0),i=(t.parked||0)+(t.waiting_human||0),s=Object.values(t).reduce((e,t)=>e+t,0),c=e?.tokens_by_day||[];n(a,g({label:`Working now`,value:t.running||0,compare:`${t.queued||0} waiting to start`,series:c.map(e=>e.tokens||0)}),g({label:`Needs you`,value:i,compare:i?`Parked or awaiting a reply`:`Nothing is blocked`,goodDirection:`down`}),g({label:`Delivered`,value:r,compare:s?`${Math.round(r/s*100)}% of all tasks`:`No tasks yet`}),g({label:`Tokens used`,value:o(c.reduce((e,t)=>e+(t.tokens||0),0)),compare:`Across ${c.length||0} days`,trend:E(c.map(e=>e.tokens||0)),goodDirection:`down`,series:c.map(e=>e.tokens||0)}))}function M(t){let r=!t?.steps?.length;if(d.classList.toggle(`dash-top-standalone`,r),r)return n(c);let i=t.steps.filter(e=>!e.done);if(i.length){let r=Math.round((t.steps.length-i.length)/t.steps.length*100);n(c,e(`div.card.setup`,e(`div.card-head`,e(`div`,e(`h2.card-title`,`Finish setting up`),e(`p.card-sub`,`Archie needs these before it can work on its own.`)),e(`span.setup-pct`,`${r}%`)),e(`div.setup-bar`,e(`div.setup-bar-fill`,{style:`width:${r}%`})),e(`ul.setup-list`,...t.steps.map(F))));return}n(c,e(`div.card.setup.setup-done`,e(`div.card-head`,e(`div`,e(`h2.card-title`,`Setup complete`),e(`p.card-sub`,`Archie is configured and ready to work.`)),e(`span.setup-pct`,l(`check`,{size:16})))))}function N(e,t){w(u,e,t)}function P(e){T(f,e)}function F(t){return e(`li.setup-step${t.done?`.done`:``}`,e(`span.setup-check`,t.done?l(`check`,{size:12}):``),e(`div`,e(`div.setup-step-title`,t.title),t.detail&&e(`div.setup-step-detail`,t.detail)))}return t}function x(t,n){let r=S(t,n),i=r>0,o=()=>{i&&(location.hash=`#/tasks?task=${encodeURIComponent(r)}`)};return e(`tr${i?`.activity-row`:``}`,i?{role:`link`,tabindex:`0`,title:`Open task details`,onclick:o,onkeydown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())}}:void 0,e(`td.strong`,e(`span`,t.kind||t.type||`event`)),e(`td.mono`,i?`#${r}`:`—`),e(`td`,t.detail||t.message||``),e(`td`,a(t.at||Date.now())))}function S(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 C(){let e=new Date().getHours();return e<5?`Still up?`:e<12?`Good morning`:e<18?`Good afternoon`:`Good evening`}function w(t,i,a){let o=a?.workflows||[],c=o.reduce((e,t)=>e+(t.runs||0),0),l=o.reduce((e,t)=>e+(t.merged||0)+(t.pr_open||0),0),u=o.reduce((e,t)=>e+(t.parked||0),0);if(!c){n(t,e(`div.card`,e(`div.card-head`,e(`h2.card-title`,`Gate pulse`)),s(`No completed runs yet`,`Once Archie finishes a task, its gate pass rate appears here.`)));return}let d=l/c*100;n(t,e(`div.card`,e(`div.card-head`,e(`div`,e(`h2.card-title`,`Gate pulse`),e(`p.card-sub`,`Work that passed its quality gates`))),v({value:d,label:`pass rate`}),e(`ul.pulse-list`,...o.slice(0,3).map(t=>e(`li.pulse-item`,e(`span.pulse-name`,t.workflow||`workflow`),r(`${t.merged||0}/${t.runs||0}`,(t.merged||0)===(t.runs||0)?`ok`:(t.parked||0)>0?`warn`:`info`))),u>0&&e(`li.pulse-item`,e(`span.pulse-name`,`Parked, awaiting you`),r(String(u),`warn`)))))}function T(t,r){let i=r?.tokens_by_day||[],a=i.reduce((e,t)=>e+(t.tokens||0),0);if(!i.length){n(t,e(`div.card`,e(`div.card-head`,e(`h2.card-title`,`Token outlook`)),s(`Nothing spent yet`,`Usage appears here once Archie runs its first task.`)));return}let c=a/i.length,l=Math.round(c*30),u=i.slice(-7).reduce((e,t)=>e+(t.tokens||0),0);n(t,e(`div.card`,e(`div.card-head`,e(`div`,e(`h2.card-title`,`Token outlook`),e(`p.card-sub`,`Next 30 days at the current rate`))),e(`div.forecast-value`,o(l)),e(`div.forecast-note`,`Based on ${o(Math.round(c))} per day over ${i.length} days`),y([{label:`Last 7 days (${o(u)})`,value:u,kind:`info`},{label:`Earlier (${o(a-u)})`,value:Math.max(a-u,0),kind:`idle`}])))}function E(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}var D={queued:`Queued`,running:`Working`,waiting_human:`Waiting for you`,pr_open:`In review`,merged:`Merged`,parked:`Parked`,dead:`Stopped (too many retries)`,rejected:`Rejected`,closed_wont_do:`Won't do`};function O(e){return D[e]||e||`Unknown`}function k(t=new URLSearchParams){let o=e(`div`),c=e(`div.grid.grid-4.task-summary`),l=e(`tbody`),u=e(`input.task-search`,{type:`search`,placeholder:`Search by title or repo…`,oninput:e=>{h=e.target.value.trim().toLowerCase(),k()}}),d=e(`select.task-filter`,{onchange:e=>{p=e.target.value,k()}},e(`option`,{value:``},`All statuses`),...Object.entries(D).map(([t,n])=>e(`option`,{value:t},n))),f=[],p=``,h=``,_=Number(t.get(`task`)),v=Number.isFinite(_)&&_>0?_:null,y=``,b=new Map,x=new Map,S=new Set;C(),w();function C(){n(o,e(`div.page-head`,e(`div`,e(`h1.page-title`,`Tasks`),e(`p.page-sub`,`Every issue archied has picked up, and where it stands.`)),e(`div.page-actions`,e(`button.btn`,{onclick:w},`Refresh`))),c,e(`div.card`,e(`div.card-head`,e(`div`,e(`h2.card-title`,`All tasks`),e(`p.card-sub`,`Click a row for its timeline`)),e(`div.task-filters`,u,d)),e(`div.table-scroll`,e(`table.table`,e(`thead`,e(`tr`,...[`Repo`,`Issue`,`Title`,`Status`,`Workflow`,`Stage`,`Last activity`,`Action`].map(t=>e(`th`,t)))),l))))}async function w(){try{[f,y]=await Promise.all([m.tasks(),m.config().then(e=>e?.identity?.forge_host||``).catch(()=>``)]),T(),k(),v&&f.some(e=>String(e.id)===String(v))&&R(v)}catch(t){n(c,e(`div.card`,s(`Cannot reach archied`,String(t.message||t)))),n(l,e(`tr`,e(`td`,{colspan:8},s(`Cannot reach archied`,String(t.message||t)))))}}function T(){let e=f.length,t={};for(let e of f)t[e.status]=(t[e.status]||0)+1;let r=t.running||0,i=(t.waiting_human||0)+(t.parked||0),a=(t.merged||0)+(t.pr_open||0);n(c,g({label:`Total tasks`,value:e,compare:e?`Everything archied has ever picked up`:`No tasks yet`}),g({label:`Working now`,value:r,compare:e?`${r} of ${e} in progress`:`Nothing running`}),g({label:`Needs you`,value:i,compare:i?`Parked or awaiting a reply`:`Nothing is blocked`,goodDirection:`down`}),g({label:`Delivered`,value:a,compare:e?`${Math.round(a/e*100)}% of all tasks`:`No tasks yet`}))}function E(){return f.filter(e=>p&&e.status!==p?!1:!h||`${e.title} ${e.repo}`.toLowerCase().includes(h))}function k(){let t=E();if(!f.length){n(l,e(`tr`,e(`td`,{colspan:8},s(`No tasks yet`,`Tasks appear here once archied picks up an issue to work.`))));return}if(!t.length){n(l,e(`tr`,e(`td`,{colspan:8},s(`No matching tasks`,`Try a different search or status filter.`))));return}l.replaceChildren();for(let e of t)l.append(A(e)),v===e.id&&l.append(I(e))}function A(t){return e(`tr.task-row`,{onclick:()=>{v=v===t.id?null:t.id,k(),v===t.id&&R(t.id)}},e(`td.mono`,P(t)??`${t.owner}/${t.repo}`),e(`td.mono`,F(t)??`#${t.issue_number}`),e(`td.strong`,t.title||`(untitled)`),e(`td`,r(O(t.status),i(t.status))),e(`td`,t.workflow||`—`),e(`td`,t.stage||`—`),e(`td`,{title:t.created_at?`Created ${a(t.created_at)}`:``},a(t.updated_at)),e(`td`,j(t)))}function j(t){let n=x.get(t.id),r=n?e(`span.task-action-error`,n):null,i=S.has(t.id),a=(n,r,a,o)=>e(n,{type:`button`,disabled:i,onclick:e=>{e.stopPropagation(),!(o&&!window.confirm(o))&&M(t.id,r)}},a);return t.status===`waiting_human`?e(`div.task-actions`,r,a(`button.btn.btn-small`,`approve`,`Approve`),a(`button.btn.btn-small.btn-quiet`,`reject`,`Reject`,`Reject "${t.title||`this task`}"? This closes the forge issue and cannot be undone from here.`)):t.status===`parked`?e(`div.task-actions`,r,a(`button.btn.btn-small`,`retry`,`Retry`)):r||`—`}async function M(e,t){x.delete(e),S.add(e),k();try{await m.taskAction(e,t),S.delete(e),await w()}catch(t){S.delete(e),x.set(e,t.message||`Action failed`),k()}}function N(e){return!y||!e.owner||!e.repo?null:`${y.replace(/\/+$/,``)}/${encodeURIComponent(e.owner)}/${encodeURIComponent(e.repo)}`}function P(t){let n=N(t);return n?e(`a.task-source-link`,{href:n,target:`_blank`,rel:`noreferrer`,title:`Open ${t.owner}/${t.repo} on the forge`,onclick:e=>e.stopPropagation()},`${t.owner}/${t.repo}`):null}function F(t){let n=N(t);return t.source===`chat`||!n||!t.issue_number?null:e(`a.task-source-link`,{href:`${n}/issues/${t.issue_number}`,target:`_blank`,rel:`noreferrer`,title:`Open issue #${t.issue_number} on the forge`,onclick:e=>e.stopPropagation()},`#${t.issue_number}`)}function I(t){let n=b.get(t.id);return e(`tr.task-timeline-row`,e(`td`,{colspan:8},t.status===`waiting_human`&&t.plan?e(`div.task-decision`,e(`div.task-decision-title`,`Decision required`),e(`div.task-decision-plan`,t.plan)):t.status===`parked`&&t.park_reason?e(`div.task-decision`,e(`div.task-decision-title`,`Park reason`),e(`div.task-decision-plan`,t.park_reason)):null,n===void 0?e(`div.task-timeline-loading`,`Loading timeline…`):n===null?e(`div.task-timeline-error`,e(`div.task-timeline-title`,`Could not load timeline`),e(`div.task-timeline-detail`,`archied did not answer for this task's events. It may be restarting — retry, or check the daemon.`),e(`button.btn`,{onclick:()=>R(t.id)},`Retry`)):n.length?e(`ul.task-timeline`,...n.map(L)):s(`No events yet`,`This task has not recorded any transitions.`)))}function L(t){return e(`li.task-timeline-entry`,e(`span.task-timeline-dot`),e(`div`,e(`div.task-timeline-kind`,t.kind||t.type||`event`),t.detail&&e(`div.task-timeline-detail`,t.detail),e(`div.task-timeline-when`,a(t.at))))}async function R(e){try{let t=await m.task(e);b.set(e,t||[])}catch{b.set(e,null)}k()}return o}function A(){let t=e(`div`),r=e(`div.grid.grid-2`),i=e(`input.skill-search`,{type:`search`,placeholder:`Search skills…`,oninput:e=>{o=e.target.value.trim().toLowerCase(),d()}}),a=[],o=``,c=null;l(),u();function l(){n(t,e(`div.page-head`,e(`div`,e(`h1.page-title`,`Skills`),e(`p.page-sub`,`What Archie can do, in plain language.`)),e(`div.page-actions`,e(`button.btn`,{onclick:u},`Refresh`))),e(`div.card`,e(`div.card-head`,e(`div`,e(`h2.card-title`,`Catalogue`),e(`p.card-sub`,`Project, shared, and user-global skills`)),i),r)),d()}async function u(){try{a=(await m.skills())?.skills||[],c=null}catch(e){a=[],c=String(e.message||e)}d()}function d(){if(c)return n(r,s(`Cannot reach archied`,c));if(!a.length)return n(r,s(`No skills discovered yet`,`Skills live as SKILL.md files under project, shared, or user-global .agents/skills/<name>/ directories. Add one and refresh to make it available.`));let e=a.filter(e=>f(e,o));if(!e.length)return n(r,s(`No skills match`,`Nothing found for "${o}".`));n(r,...e.map(p))}function f(e,t){return!t||`${e.name} ${e.description}`.toLowerCase().includes(t)}function p(t){return e(`div.card.skill-card`,e(`div.card-head`,e(`h3.card-title`,t.name||`Untitled skill`),t.workflow&&e(`span.pill.pill-info`,t.workflow)),e(`p.skill-desc`,t.description||`No description provided.`),e(`div.skill-source`,t.source||`Unknown source`))}return t}var j={bootstrap:`Bootstrap`,implement:`Implement`,tdd:`TDD`,feasibility:`Feasibility check`};function M(e){return j[e]?j[e]:e?e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g,` `):`Unknown`}function N(e,t){return t?Math.round(e/t*100):0}function P(t,n=`ok`){return e(`div.wf-bar`,e(`div.wf-bar-fill.wf-bar-${n}`,{style:`width:${Math.min(100,Math.max(0,t))}%`}))}function F(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 I(){let t=e(`div`),r=e(`div`),i=e(`div`);a(),o();function a(){n(t,e(`div.page-head`,e(`div`,e(`h1.page-title`,`Workflows`),e(`p.page-sub`,`Run outcomes and spend per workflow, and where stages get stuck.`)),e(`div.page-actions`,e(`button.btn`,{onclick:o},`Refresh`))),r,i)}async function o(){try{let e=await m.workflows();c(e?.workflows||[]),l(e?.stages||[])}catch(t){n(r,e(`div.card`,s(`Cannot reach archied`,String(t.message||t)))),n(i)}}function c(t){if(!t.length){n(r,e(`div.card`,e(`div.card-head`,e(`div`,e(`h2.card-title`,`Per workflow`))),s(`No workflow runs yet`,`Stats appear here once a task has run through a workflow.`)));return}n(r,e(`div.card`,e(`div.card-head`,e(`div`,e(`h2.card-title`,`Per workflow`),e(`p.card-sub`,`Success rate is merged tasks over all runs`))),e(`div.table-scroll`,e(`table.table`,e(`thead`,e(`tr`,...[`Workflow`,`Runs`,`Success rate`,`Avg tokens`,`Avg steps`].map(t=>e(`th`,t)))),e(`tbody`,...t.map(t=>{let n=N(t.merged,t.runs);return e(`tr`,e(`td.strong`,M(t.workflow)),e(`td`,`${t.runs} run${t.runs===1?``:`s`}`),e(`td`,e(`div.wf-rate`,`${n}%`,e(`span.wf-rate-sub`,`${t.merged} of ${t.runs} merged`)),P(n,n>=50?`ok`:`warn`)),e(`td.mono`,t.avg_tokens?t.avg_tokens.toLocaleString():`—`),e(`td.mono`,t.avg_steps?t.avg_steps.toFixed(1):`—`))}))))))}function l(t){if(!t.length){n(i,e(`div.card.wf-stage-card`,e(`div.card-head`,e(`div`,e(`h2.card-title`,`Per stage`))),s(`No stage data yet`,`Stage timing and failures appear here once workflows have run.`)));return}let r=Math.max(...t.map(e=>e.avg_ms||0),1),a=[...t].sort((e,t)=>(t.avg_ms||0)-(e.avg_ms||0)),o=[...t].filter(e=>e.errors>0).sort((e,t)=>t.errors-e.errors);n(i,e(`div.grid.grid-2.wf-stage-card`,e(`div.card`,e(`div.card-head`,e(`div`,e(`h2.card-title`,`Slowest stages`),e(`p.card-sub`,`Average duration, this workflow's stages`))),e(`div.table-scroll`,e(`table.table`,e(`thead`,e(`tr`,...[`Workflow`,`Stage`,`Runs`,`Avg duration`].map(t=>e(`th`,t)))),e(`tbody`,...a.map(t=>e(`tr`,e(`td`,M(t.workflow)),e(`td.strong`,t.stage),e(`td`,`${t.runs}`),e(`td`,e(`div.wf-rate`,F(t.avg_ms)),P(N(t.avg_ms,r),`info`)))))))),e(`div.card`,e(`div.card-head`,e(`div`,e(`h2.card-title`,`Most failures`),e(`p.card-sub`,`Stages that error out, over their runs`))),o.length?e(`div.table-scroll`,e(`table.table`,e(`thead`,e(`tr`,...[`Workflow`,`Stage`,`Failures`].map(t=>e(`th`,t)))),e(`tbody`,...o.map(t=>e(`tr`,e(`td`,M(t.workflow)),e(`td.strong`,t.stage),e(`td`,e(`div.wf-rate`,`${t.errors} of ${t.runs}`),P(N(t.errors,t.runs),`danger`))))))):s(`No failures recorded`,`Every stage has completed cleanly so far.`))))}return t}function L(){let t=e(`div`),i=e(`div.grid.grid-2`);a(),o();function a(){n(t,e(`div.page-head`,e(`div`,e(`h1.page-title`,`Channels`),e(`p.page-sub`,`The conversational front-ends Archie can be reached through.`)),e(`div.page-actions`,e(`button.btn`,{onclick:o},`Refresh`))),i)}async function o(){try{c((await m.channels())?.channels||[])}catch(e){n(i,s(`Cannot reach archied`,String(e.message||e)))}}function c(e){if(!e.length){n(i,s(`No channels configured`,`Configure [chat.telegram] or [chat.webhook_addr] in config.toml to talk to Archie outside the dashboard.`));return}n(i,...e.map(l))}function l(t){return e(`div.card.channel-card`,e(`div.card-head`,e(`h3.card-title`,t.name),t.configured?r(`connected`,`ok`):r(`not configured`,`idle`)),e(`p.channel-desc`,t.description),e(`p.channel-detail`,t.detail))}return t}function R(){let t=e(`div`),r=e(`div`);i(),a();function i(){n(t,e(`div.page-head`,e(`div`,e(`h1.page-title`,`Configuration`),e(`p.page-sub`,`What archied is actually running with right now.`)),e(`div.page-actions`,e(`button.btn`,{onclick:a},`Refresh`))),r)}async function a(){try{o(await m.config())}catch(t){n(r,e(`div.card`,s(`Cannot reach archied`,String(t.message||t))))}}function o(t){if(!t||Object.keys(t).length===0){n(r,e(`div.card`,s(`No configuration loaded`,`archied is running without a config file wired into the dashboard, so there is nothing to show.`)));return}n(r,V(t.identity),H(t.repositories),W(t.models,t.providers),K(t.budgets),q(t.agent),ee(t.storage,t.containers),ne(t.web))}return t}function z(t,n,...r){return e(`div.card.cfg-section`,e(`div.card-head`,e(`div`,e(`h2.card-title`,t),e(`p.card-sub`,n))),...r)}function B(t,n){return e(`div.cfg-row`,e(`span.cfg-label`,t),e(`span.cfg-value.mono`,n??`—`))}function V(t){return t?z(`Identity`,`Who Archie is on the forge, and how it addresses commits and comments.`,e(`div.cfg-rows`,B(`Bot account`,t.bot_user),B(`Commit author email`,t.bot_email),B(`Pickup label`,t.label),B(`Forge type`,t.forge_type),B(`Forge host`,t.forge_host),B(`Max diff size (lines)`,t.diff_cap_lines))):z(`Identity`,`Who Archie is on the forge.`,s(`Not available`))}function H(t){return t?.length?z(`Repositories`,`Each repository Archie polls, and the quality gate a change must pass before it opens a pull request.`,e(`div.table-scroll`,e(`table.table`,e(`thead`,e(`tr`,...[`Repository`,`Base branch`,`Ecosystem`,`Quality gate`,`Protected paths`].map(t=>e(`th`,t)))),e(`tbody`,...t.map(t=>e(`tr`,e(`td.strong`,`${t.owner}/${t.name}`),e(`td.mono`,t.base),e(`td`,t.ecosystem||`go`),e(`td.mono`,U(t.gate)),e(`td.mono`,t.protect?.length?t.protect.join(`, `):`—`))))))):z(`Repositories`,`The repositories Archie polls for work.`,s(`No repositories configured`,`Add a [[repos]] entry in config.toml so Archie has somewhere to work.`))}function U(e){return e?.length?e.map(e=>e.join(` `)).join(` → `):`—`}function W(t,n){let i=Object.entries(t||{}),a=Object.entries(n||{}),o=i.length?e(`div.cfg-rows`,...i.map(([e,t])=>B(G(e),t))):s(`No model roles configured`,`Assign a model to at least one role (e.g. "builder") in [models].`),c=a.length?e(`div.table-scroll`,e(`table.table`,e(`thead`,e(`tr`,...[`Provider`,`Class`,`Base URL`,`API key env var`,`Status`].map(t=>e(`th`,t)))),e(`tbody`,...a.map(([t,n])=>e(`tr`,e(`td.strong`,t),e(`td`,n.class),e(`td.mono`,n.base_url||`default`),e(`td.mono`,n.api_key_env||`—`),e(`td`,n.configured?r(`configured`,`ok`):r(`missing credentials`,`warn`))))))):s(`No providers configured`,`Add a [providers.<name>] entry so a model role above has something to run on.`);return z(`Models & providers`,`Which model handles each stage of work, and which LLM providers are wired up. Only the environment variable NAME is shown, never its value.`,e(`h3.cfg-subhead`,`Model roles`),o,e(`h3.cfg-subhead`,`Providers`),c)}function G(e){return e?e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g,` `):`Unknown role`}function K(t){return t?z(`Budgets`,`The limits every autonomous stage runs under, so a stuck task cannot run forever.`,e(`div.cfg-rows`,B(`Max steps`,t.max_steps||`Unlimited`),B(`Max tokens`,t.max_tokens||`Unlimited`),B(`Wall clock`,t.wall_clock),B(`Max gate failures before parking`,t.gate_max_failures||`Unlimited`))):z(`Budgets`,`Limits on every agent stage.`,s(`Not available`))}function q(t){return t?z(`Agent execution`,`How archied actually runs a stage of work.`,e(`div.cfg-rows`,B(`Execution mode`,J(t.mode)),B(`Worker command`,t.command),B(`Extra environment variables passed through`,t.env?.length?t.env.join(`, `):`None`))):z(`Agent execution`,`How Archie runs autonomous stages.`,s(`Not available`))}function J(e){switch(e){case`inprocess`:return`In-process (same binary as the daemon)`;case`subprocess`:return`Subprocess (separate archie-agent process)`;case`nats`:return`NATS (dispatched to a worker over the message bus)`;default:return e||`Not set`}}function ee(t,n){let r=[];return t&&r.push(e(`h3.cfg-subhead`,`Paths`),e(`div.cfg-rows`,B(`Work directory`,t.work_dir),B(`Task database`,t.db_path),B(`Shared skills directory`,t.skills_dir||`None (uses the work directory)`),B(`Daemon plugin directory`,t.plugin_dir||`None`),B(`Secret engine plugin directory`,t.secret_engine_dir||`None (built-in engines only)`))),n&&r.push(e(`h3.cfg-subhead`,`Sandboxed containers`),e(`div.cfg-rows`,B(`Sandboxing enabled`,n.enabled?`Yes`:`No`),B(`Agent image`,n.image||`Not set`),B(`Max concurrent tasks`,n.max_concurrency||`Unlimited`),B(`Container max lifetime`,n.max_uptime),B(`Persistent volume retention`,n.volume_ttl),B(`How images are refreshed`,te(n.pull_policy)),B(`Docker network`,n.network||`Auto-detected`))),r.length||r.push(s(`Not available`)),z(`Storage & sandboxing`,`Where archied keeps its state, and how it isolates task execution.`,...r)}function te(e){return e===`always`?`Always pull the latest image before running`:`Only pull when the image is missing locally`}function ne(t){return t?z(`Dashboard`,`This dashboard's own listen address.`,e(`div.cfg-rows`,B(`Listen address`,t.listen===`off`?`Disabled`:t.listen))):z(`Dashboard`,`This dashboard's own listen address.`,s(`Not available`))}var re=[{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 ie(e){switch((e||``).toUpperCase()){case`ERROR`:return`danger`;case`WARN`:return`warn`;case`DEBUG`:return`idle`;default:return`info`}}function ae(){let t=e(`div`),i=e(`div.log-list`),a=r(`connecting`,`idle`),o=e(`span.log-meta`),c={level:``,component:``,q:``},l=!1,u=[],d=e(`select.log-select`,{onchange:e=>v({level:e.target.value})},...re.map(t=>e(`option`,{value:t.value},t.label))),f=e(`select.log-select`,{onchange:e=>v({component:e.target.value})}),p=e(`input.log-search`,{type:`search`,placeholder:`Search messages and fields…`,oninput:ue(e=>v({q:e.target.value}),250)}),g=e(`button.btn`,{onclick:y},`Pause`);b(),x();let _=h(e=>C(e),e=>{a.className=`pill pill-${e===`live`?`ok`:`warn`}`,a.textContent=e});t.addEventListener(`archie:teardown`,_);function v(e){c={...c,...e},x()}function y(){l=!l,g.textContent=l?`Resume`:`Pause`,g.classList.toggle(`btn-primary`,l)}function b(){n(t,e(`div.page-head`,e(`div`,e(`h1.page-title`,`Logs`),e(`p.page-sub`,`What Archie has been doing, newest last.`)),e(`div.page-actions`,g,e(`button.btn`,{onclick:x},`Refresh`))),e(`div.card`,e(`div.card-head`,e(`div.log-filters`,d,f,p),e(`div.log-status`,o,a)),i))}async function x(){n(i,e(`div.log-loading`,`Loading…`));try{let e=await m.logs({level:c.level,component:c.component,q:c.q,limit:500});if(e.disabled){n(i,s(`File logging is off`,`Set [log] file in your config to keep a durable record. Live lines below still stream while this page is open.`)),o.textContent=``;return}S(e.components||[]),o.textContent=e.truncated?`showing the most recent matches from ${e.file}`:e.file||``;let t=e.entries||[];if(!t.length){n(i,s(`Nothing matches`,`Try a wider level or clear the search.`));return}n(i,...t.map(oe)),i.scrollTop=i.scrollHeight}catch(e){n(i,s(`Cannot read logs`,String(e.message||e)))}}function S(t){if(le(t,u))return;u=t;let r=c.component;n(f,e(`option`,{value:``},`All components`),...t.map(t=>e(`option`,{value:t},t))),f.value=r}function C(e){if(l)return;let t={time:e.at||new Date().toISOString(),level:e.level||`INFO`,msg:e.detail||e.message||e.kind||`event`,fields:e.task_id?{task:e.task_id}:null};if(!w(t))return;let n=i.scrollHeight-i.scrollTop-i.clientHeight<40;for(i.querySelector(`.empty, .log-loading`)&&i.replaceChildren(),i.append(oe({...t,message:t.msg}));i.children.length>1e3;)i.firstElementChild.remove();n&&(i.scrollTop=i.scrollHeight)}function w(e){if(c.level&&!c.level.split(`,`).includes((e.level||``).toUpperCase())||c.component&&e.fields?.component!==c.component)return!1;if(c.q){let t=c.q.toLowerCase();if(!`${e.msg} ${JSON.stringify(e.fields||{})}`.toLowerCase().includes(t))return!1}return!0}return t}function oe(t){let n=t.fields||{};return e(`div.log-row.log-${ie(t.level)}`,e(`span.log-time.mono`,ce(t.time)),e(`span.log-level`,(t.level||`info`).toUpperCase()),e(`span.log-body`,e(`span.log-msg`,t.message||t.msg||``),...Object.entries(n).map(([t,n])=>e(`span.log-field`,e(`span.log-field-key`,t),String(se(n))))))}function se(e){return e==null?``:typeof e==`object`?JSON.stringify(e):e}function ce(e){let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?`--:--:--`:t.toTimeString().slice(0,8)}function le(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function ue(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)}}function de(){let t=e(`div`),r=e(`div`);i(),a();function i(){n(t,e(`div.page-head`,e(`div`,e(`h1.page-title`,`Memory`),e(`p.page-sub`,`What Archie can recall between conversations, and the tools it uses to do it.`)),e(`div.page-actions`,e(`button.btn`,{onclick:a},l(`refresh`,{size:15}),`Refresh`))),r)}async function a(){n(r,e(`div.card`,e(`div.mem-loading`,`Loading…`)));try{let t=await m.memory();if(!t.enabled||!t.providers?.length){n(r,e(`div.card`,s(`Memory is not configured`,`Without a provider, Archie starts every conversation with no recollection of earlier ones.`)));return}n(r,e(`div.grid.grid-2`,...t.providers.map(fe)))}catch(t){n(r,e(`div.card`,s(`Cannot read memory providers`,String(t.message||t))))}}return t}function fe(t){let n=t.tools||[];return e(`div.card`,e(`div.card-head`,e(`div`,e(`h2.card-title`,t.name||`provider`),e(`p.card-sub`,pe(t.role))),t.available?r(`ready`,`ok`):r(`unavailable`,`danger`)),!t.available&&e(`p.mem-warning`,`Configured but not usable right now — a required binary or connection may be missing.`),n.length?e(`ul.mem-tools`,...n.map(t=>e(`li.mem-tool`,e(`div.mem-tool-name.mono`,t.name),t.description&&e(`div.mem-tool-desc`,t.description)))):e(`p.mem-warning`,`This provider exposes no tools, so the agent cannot use it.`))}function pe(e){return e===`external`?`Added by you — an external store Archie was given`:`Built in — always available to Archie`}var me=`archie.web.chat.channel`;function Y(){let e=localStorage.getItem(me);return e||(e=crypto.randomUUID(),localStorage.setItem(me,e)),e}function he(e){return e.title||e.branch_name||`Conversation ${e.session_id.slice(0,8)}`}function X(t){let n=document.createDocumentFragment(),r=/(~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|\*[^*]+\*|_[^_]+_)/g,i=0;for(let a of t.matchAll(r)){a.index>i&&n.append(document.createTextNode(t.slice(i,a.index)));let r=a[0];if(r.startsWith(`~~`))n.append(e(`del`,r.slice(2,-2)));else if(r.startsWith(`**`)||r.startsWith(`__`))n.append(e(`strong`,r.slice(2,-2)));else if(r.startsWith("`"))n.append(e(`code`,r.slice(1,-1)));else if(r.startsWith(`[`)){let t=r.match(/^\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)$/);n.append(e(`a`,{href:t[2],target:`_blank`,rel:`noreferrer`},t[1]))}else n.append(e(`em`,r.slice(1,-1)));i=a.index+r.length}return i<t.length&&n.append(document.createTextNode(t.slice(i))),n}function ge(t){let n=e(`div.chat-bubble-text`),r=String(t||``).split(`
`),i=[],a=null,o=null,s=()=>{i.length&&(n.append(e(`p`,X(i.join(` `)))),i=[])},c=()=>{a&&n.append(a),a=null};for(let t=0;t<r.length;t++){let l=r[t];if(l.startsWith("```")){s(),c(),o?(n.append(e(`pre`,e(`code`,o.join(`
`)))),o=null):o=[];continue}if(o){o.push(l);continue}let u=Z(l),d=t+1<r.length?Z(r[t+1]):null;if(u&&d&&_e(d)&&u.length===d.length){s(),c();let i=[];for(t+=2;t<r.length;t++){let e=Z(r[t]);if(!e||e.length!==u.length){t--;break}i.push(e)}let a=e(`tbody`);for(let t of i)a.append(e(`tr`,...t.map(t=>e(`td`,X(t)))));n.append(e(`table`,e(`thead`,e(`tr`,...u.map(t=>e(`th`,X(t))))),a));continue}if(!l.trim()){s(),c();continue}let f=l.match(/^(#{1,3})\s+(.+)$/);if(f){s(),c(),n.append(e(`h${f[1].length}`,X(f[2])));continue}let p=l.match(/^\s*[-*]\s+(.+)$/),m=l.match(/^\s*\d+[.)]\s+(.+)$/);if(p||m){s();let t=m?`ol`:`ul`;(!a||a.tagName.toLowerCase()!==t)&&(c(),a=e(t)),a.append(e(`li`,X((p||m)[1])));continue}if(l.startsWith(`>`)){s(),c(),n.append(e(`blockquote`,X(l.replace(/^>\s?/,``))));continue}i.push(l)}return s(),c(),o&&n.append(e(`pre`,e(`code`,o.join(`
`)))),n}function Z(e){let t=String(e||``).trim();if(!t.includes(`|`))return null;let n=t.replace(/^\|/,``).replace(/\|$/,``).split(`|`).map(e=>e.trim());return n.length>1&&n.every(e=>e!==``)?n:null}function _e(e){return e.every(e=>/^:?-{3,}:?$/.test(e))}function ve(t){let n=t.from??t.From??``,r=t.text??t.Text??``,i=n!==`web`;return e(`div.chat-bubble-row.${i?`assistant`:`user`}`,e(`div.chat-bubble`,e(`div.chat-bubble-meta`,i?`Archie`:`You`),i?ge(r):e(`div.chat-bubble-text`,r)))}function ye(){let t=e(`div.chat-page`),r=e(`div.chat-session-list`),i=e(`div.chat-transcript`),a=e(`textarea.chat-composer`,{rows:3,placeholder:`Message Archie… (commands like /status and /new work here)`,"aria-label":`Message Archie`}),o=e(`button.btn.btn-primary`,`Send`),s=e(`button.btn`,{disabled:!0},`Stop`),c=e(`span.chat-status`,`Ready`),l=e(`select.chat-select`,{"aria-label":`Personality`}),u=e(`select.chat-select`,{"aria-label":`Provider`,hidden:!0}),d=e(`select.chat-select`,{"aria-label":`Model`}),f=e(`button.btn`,{hidden:!0,onclick:()=>{window.confirm(`Reload the Telegram chat adapter?`)&&(a.value=`/restart`,K())}},`Reload Telegram`),p=``,h=[],g=!1,_=null,v=null,y={},b=[],x=[],S=0,C=e(`div.chat-empty-state`,e(`span.chat-empty-mark`,`A`),e(`h2`,`What are we working on?`),e(`p`,`Ask Archie anything, or start with one of these prompts.`),e(`div.chat-prompt-grid`,...[`Summarise active tasks`,`Show running agents`,`Check system status`].map(t=>e(`button.chat-prompt`,{onclick:()=>{a.value=t,a.focus()}},t))));function w(e){C.remove(),i.append(ve(e)),i.scrollTop=i.scrollHeight}function T(){if(r.replaceChildren(),M.hidden=!p,!h.length){r.append(e(`div.chat-empty`,`Your conversations will appear here.`));return}for(let t of h){let n=e(`button.chat-session`,{class:p===t.session_id?`active`:``,onclick:()=>G(t.session_id)},e(`strong`,he(t)),e(`span`,new Date(t.last_active_at).toLocaleString()));r.append(n)}}function E(t){y=t,l.replaceChildren(e(`option`,{value:``},`Personality`));for(let n of t.personas||[])l.append(e(`option`,{value:n},n));l.value=t.active_persona||``;let n=t.providers||[];u.hidden=n.length===0,u.replaceChildren(e(`option`,{value:``},`Provider`));for(let t of n)u.append(e(`option`,{value:t},t));u.value=t.active_provider||n[0]||``,D(u.value),f.hidden=!t.restart_available,A.hidden=!t.dangerous_available,t.dangerous_available&&V()}function D(t){let n=y.models_by_provider||{},r=t&&n[t]?n[t]:y.models||[];d.replaceChildren(e(`option`,{value:``},`Model`));for(let t of r)d.append(e(`option`,{value:t},t));d.value=y.active_model||``}function O(t){let n=t.commands||[];b=n.map(e=>typeof e==`string`?{command:e,usage:e,description:``}:e);let r=e(`div.chat-command-list`);n.length||r.append(e(`span`,`Send a message to begin.`));for(let t of n){let n=typeof t==`string`?{command:t,usage:t,description:``}:t;r.append(e(`div.chat-command-item`,e(`code`,n.usage||n.command),e(`span`,n.description||``)))}J.replaceChildren(e(`summary`,`Available commands (${n.length})`),r)}let k=e(`div.chat-update-panel`),A=e(`div.chat-dangerous-panel`,{hidden:!0}),j=e(`div.chat-command-menu`,{hidden:!0,role:`listbox`,"aria-label":`Commands`}),M=e(`details.chat-session-tools`,{hidden:!0});function N(){let e=a.value.slice(0,a.selectionStart).match(/(?:^|\s)\/([^\s]*)$/);return e?e[1].toLowerCase():null}function P(){j.hidden=!0,x=[],S=0}function F(){let t=N();if(t===null){P();return}if(x=b.filter(e=>`${e.command} ${e.description}`.toLowerCase().includes(t)).slice(0,8),!x.length){P();return}S=Math.min(S,x.length-1),j.replaceChildren(...x.map((t,n)=>e(`button.chat-command-option`,{type:`button`,role:`option`,"aria-selected":n===S,onmousedown:e=>e.preventDefault(),onclick:()=>I(n)},e(`code`,t.command),e(`span`,t.description||t.usage||``)))),j.hidden=!1}function I(e){let t=x[e];if(!t)return;let n=a.value.slice(0,a.selectionStart),r=a.value.slice(a.selectionStart),i=n.search(/(?:^|\s)\/[^\s]*$/),o=i<0?n.length:i+ +(n[i]===` `);a.value=`${n.slice(0,o)}${t.command} ${r}`;let s=o+t.command.length+1;a.setSelectionRange(s,s),P(),a.focus()}function L(t){k.replaceChildren(),v=t?.snapshot||null;let n=t?.available||[];if(!n.length){k.append(e(`span`,t?.snapshot?.deferred?`Update deferred.`:`Archie is up to date.`));return}k.append(e(`div`,e(`strong`,`Update available`),e(`span`,n.map(e=>`${e.Label||e.label}: ${e.Available||e.available}`).join(` · `))),e(`div.chat-update-actions`,e(`button.btn`,{onclick:async()=>{await m.chatUpdateDefer(v),L({snapshot:{deferred:!0},available:[]}),c.textContent=`Update deferred`}},`Defer`),t.can_install?e(`button.btn.btn-primary`,{onclick:async()=>{c.textContent=`Installing…`,await m.chatUpdateInstall(v),c.textContent=`Update started`,R()}},`Install update`):null))}async function R(){try{L(await m.chatUpdate())}catch(t){k.replaceChildren(e(`span`,t.message||`Updates unavailable`))}}function z(t,n,r){return e(`button.btn`,{onclick:async()=>{try{await m.chatDangerousDecision(t,n),c.textContent=n===`deny`?`Action denied`:`Action approved`,await V()}catch(e){c.textContent=e.message||`Approval failed`}}},r)}function B(t){A.replaceChildren();let n=t?.checkpoints||[],r=t?.pending||[],i=e(`select.chat-select`,{"aria-label":`Checkpoint`},e(`option`,{value:``},`Select checkpoint`),...n.map(t=>e(`option`,{value:t.Number??t.number},`${t.Number??t.number} — ${t.Label??t.label??`checkpoint`}`))),a=e(`input.chat-dangerous-input`,{placeholder:`Process name or id`,"aria-label":`Process name or id`}),o=(e,t)=>async()=>{if(String(t.value||t).trim())try{await m.chatDangerousRequest(e,String(t.value||t).trim()),c.textContent=`Approval requested`,await V()}catch(e){c.textContent=e.message||`Could not request action`}},s=r.length?r.map(t=>e(`div.chat-dangerous-pending`,e(`span`,t.description),e(`div.chat-update-actions`,z(t.id,`approve`,`Approve`),z(t.id,`permanent`,`Approve for 24h`),z(t.id,`deny`,`Deny`)))):[e(`span.chat-hint`,`No pending dangerous actions.`)];A.append(e(`div.chat-dangerous-head`,e(`strong`,`Dangerous actions`),e(`span.chat-hint`,`Every action requires approval.`)),e(`div.chat-dangerous-controls`,e(`div`,i,e(`button.btn`,{onclick:o(`rollback`,i)},`Request rollback`)),e(`div`,a,e(`button.btn`,{onclick:o(`stop`,a)},`Request stop`))),e(`div.chat-dangerous-pending-list`,...s))}async function V(){try{B(await m.chatDangerous())}catch(t){A.replaceChildren(e(`span.chat-hint`,t.message||`Dangerous actions unavailable`))}}async function H(){let e=await m.chatSessions();h=e.sessions||[],E(e),O(e),T(),!p&&h[0]&&await G(h[0].session_id)}async function U(e){if(p)try{c.textContent=`Working…`;let t=await m.chatMessage(Y(),e);t.session_id&&(p=t.session_id),c.textContent=t.reply||`Session updated`,await H(),p&&await G(p),M.open=!1}catch(e){c.textContent=e.message||`Session action failed`}}function W(e,t){let n=window.prompt(t);n?.trim()&&U(`${e} ${n.trim()}`)}async function G(e){p=e,T(),i.replaceChildren(),await m.chatMessage(Y(),`/resume ${e}`),l.value=y.active_personas?.[e]||y.active_persona||``;let t=await m.chatMessages(e);for(let e of t)w(e);i.children.length||i.append(C)}async function K(){let t=a.value.trim();if(!t||g)return;P(),g=!0,o.disabled=!0,s.disabled=!1,a.disabled=!0,c.textContent=`Thinking…`,w({from:`web`,text:t}),a.value=``;let n=e(`div.chat-bubble-row.assistant`,e(`div.chat-bubble`,e(`div.chat-bubble-meta`,`Archie`),e(`div.chat-bubble-text`)));i.append(n);let r=n.querySelector(`.chat-bubble-text`),l;try{_=new AbortController,l=setTimeout(()=>_.abort(),12e4);let e=await fetch(`/api/chat/stream`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`text/event-stream`},body:JSON.stringify({channel_id:Y(),source_id:crypto.randomUUID(),text:t}),signal:_.signal});if(!e.ok)throw Error(await e.text()||`${e.status} ${e.statusText}`);let n=e.body.getReader(),i=new TextDecoder,a=``;for(;;){let{value:e,done:t}=await n.read();a+=i.decode(e||new Uint8Array,{stream:!t});let o=a.split(`
`);a=o.pop()||``;for(let e of o){let t=e.split(`
`).find(e=>e.startsWith(`data: `));if(!t)continue;let n=JSON.parse(t.slice(6));if(n.session_id&&(p=n.session_id),n.type===`delta`&&(r.textContent+=n.text),n.type===`done`&&!r.textContent&&(r.textContent=n.text),n.type===`error`)throw Error(n.text)}if(t)break}r.isConnected&&r.replaceWith(ge(r.textContent)),c.textContent=`Ready`,await H(),p&&await G(p)}catch(e){e.name===`AbortError`?(r.textContent=`Turn stopped.`,c.textContent=`Stopped`):(r.textContent=`Unable to complete that turn: ${e.message||e}`,c.textContent=`Error`)}finally{clearTimeout(l),_=null,g=!1,o.disabled=!1,s.disabled=!0,a.disabled=!1,a.focus()}}o.onclick=K,s.onclick=()=>{let e=p;c.textContent=`Stopping…`,e&&m.chatCancel(e).catch(()=>{}),_?.abort()},a.oninput=F,a.onkeydown=e=>{if(!j.hidden&&x.length){if(e.key===`ArrowDown`){e.preventDefault(),S=(S+1)%x.length,F();return}if(e.key===`ArrowUp`){e.preventDefault(),S=(S+x.length-1)%x.length,F();return}if(e.key===`Enter`&&!e.ctrlKey&&!e.metaKey){e.preventDefault(),I(S);return}if(e.key===`Escape`){e.preventDefault(),P();return}}e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),K())},l.onchange=async()=>{!p||!l.value||(await m.chatPersona(p,l.value),y.active_personas={...y.active_personas||{},[p]:l.value},c.textContent=`Personality: ${l.value}`)},u.onchange=async()=>{D(u.value),u.value&&await q(`/model --provider ${u.value}`)},d.onchange=async()=>{d.value&&await q(`/model ${d.value}`)};async function q(e){try{let t=await m.chatMessage(Y(),e);c.textContent=t.reply||`Model updated`,await H()}catch(e){c.textContent=`Model update failed: ${e.message||e}`}}let J=e(`details.chat-command-help`),ee=e(`button.btn`,{onclick:R},`Check updates`),te=e(`div.chat-session-tool-list`,e(`button.btn`,{type:`button`,onclick:()=>U(`/retry`)},`Retry`),e(`button.btn`,{type:`button`,onclick:()=>U(`/undo`)},`Undo`),e(`button.btn`,{type:`button`,onclick:()=>W(`/title`,`Session title`)},`Rename`),e(`button.btn`,{type:`button`,onclick:()=>W(`/branch`,`Branch name (optional)`)},`Branch`),e(`button.btn`,{type:`button`,onclick:()=>U(`/compress --preview`)},`Preview compression`));return M.append(e(`summary`,`Session actions`),te),n(t,e(`div.chat-page-content`,e(`div.chat-topbar`,e(`div`,e(`span.chat-kicker`,`ARCHIE WORKSPACE`),e(`h1.page-title`,`Chat`)),e(`div.chat-topbar-actions`,e(`span.chat-status`,c),f,ee,l,u,d)),k,A,e(`div.chat-layout`,e(`aside.chat-sidebar`,e(`div.chat-sidebar-head`,e(`strong`,`Conversations`),e(`button.btn.btn-primary`,{onclick:()=>{a.value=`/new`,K()}},`+ New chat`)),r),e(`section.chat-workspace`,e(`div.chat-workspace-head`,e(`span.chat-workspace-label`,`PERSONAL ASSISTANT`),J,M),i,e(`div.chat-compose`,e(`div.chat-composer-shell`,a,j,e(`div.chat-compose-actions`,e(`span.chat-hint`,`⌘/Ctrl + Enter to send`),s,o))))))),i.append(C),H().catch(e=>{c.textContent=e.message||`Chat unavailable`}),R(),t}var Q=[{path:`/`,label:`Dashboard`,icon:`dashboard`,view:b},{path:`/chat`,label:`Chat`,icon:`chat`,view:ye},{path:`/tasks`,label:`Tasks`,icon:`tasks`,view:k},{path:`/logs`,label:`Logs`,icon:`logs`,view:ae},{path:`/skills`,label:`Skills`,icon:`skills`,view:A},{path:`/workflows`,label:`Workflows`,icon:`workflows`,view:I},{path:`/memory`,label:`Memory`,icon:`memory`,view:de},{path:`/channels`,label:`Channels`,icon:`channels`,view:L},{path:`/settings`,label:`Configuration`,icon:`settings`,view:R}],be=`archie.theme`;function xe(e){document.documentElement.dataset.theme=e,localStorage.setItem(be,e)}function $(){return localStorage.getItem(be)||`dark`}function Se(t){let r=new Map,i=e(`nav.nav`,...[null].flatMap(()=>[...Q.map(n=>{let i=e(`a.nav-item`,{href:`#${n.path}`,onclick:e=>{n.soon?e.preventDefault():t(n.path)},"aria-disabled":n.soon||void 0,title:n.soon?`Coming soon`:void 0},l(n.icon),e(`span.nav-label`,n.label),n.soon&&e(`span.nav-soon`,`soon`));return r.set(n.path,i),i})])),a=e(`button.icon-btn`,{title:`Toggle light and dark`,"aria-label":`Toggle light and dark`,onclick:()=>{xe($()===`dark`?`light`:`dark`),n(a,l($()===`dark`?`moon`:`sun`))}});n(a,l($()===`dark`?`moon`:`sun`));let o=e(`input`,{type:`search`,placeholder:`Jump to…`,"aria-label":`Jump to a section`,onkeydown:e=>{if(e.key!==`Enter`)return;let n=e.target.value.trim().toLowerCase(),r=Q.find(e=>!e.soon&&e.label.toLowerCase().startsWith(n));r&&(t(r.path),e.target.value=``,e.target.blur())}});return{node:e(`header.topbar`,e(`div.brand`,e(`span.brand-mark`,`A`),`Archie`),i,e(`div.topbar-end`,e(`div.topbar-search`,l(`search`,{size:15}),o),e(`button.icon-btn`,{title:`Documentation`,"aria-label":`Documentation`},l(`help`)),a,e(`div.avatar`,{title:`Signed in locally`},`A`))),highlight(e){for(let[t,n]of r)t===e?n.setAttribute(`aria-current`,`page`):n.removeAttribute(`aria-current`)}}}function Ce(){xe($());let t=e(`main.main`),r=Se(i);n(document.getElementById(`app`),e(`div.shell`,r.node,t));function i(e){location.hash===`#${e}`?a(e):location.hash=e}function a(e){t.firstElementChild?.dispatchEvent(new CustomEvent(`archie:teardown`));let[i,a=``]=e.split(`?`,2),o=Q.find(e=>e.path===i)||Q[0];r.highlight(o.path),n(t,o.view?o.view(new URLSearchParams(a)):we(o))}window.addEventListener(`hashchange`,()=>a(location.hash.slice(1)||`/`)),a(location.hash.slice(1)||`/`)}function we(t){return e(`div`,e(`div.page-head`,e(`div`,e(`h1.page-title`,t.label))),e(`div.card`,e(`div.empty`,e(`div.empty-title`,`${t.label} is not built yet`),e(`div`,`This section is next up. Nothing is broken.`))))}Ce();