fix(webui): stop the UI contradicting itself, and clear the AA failures

Four P1 findings from the audit.

Workflows claimed "No workflow runs yet" directly above stage tables listing
those runs (archie-core-rcbf). The rows were built from the definition list
alone, so a workflow with statistics but no definition produced no row at all.
workflow-rows.js now merges both sides: a run is evidence the workflow exists.
The producer is also at fault -- /api/workflows returns definitions: [] from
the archie-ui composition while the daemon logs a registry of seven -- which
also means "Start work" never renders there. Filed as archie-core-3tij.

The logs page said "Durable history unavailable" twice and promised live logs
from a stream that had stopped (archie-core-c5bz). EventSource fires onerror
both for a retry and for a give-up; readyState tells them apart, so a dead
stream now reports "unavailable" in red instead of "reconnecting" in amber
forever. The toolbar says "Live only" and the empty state carries the
explanation, each once. An unconfigured update check (501) now says so on
Configuration rather than rendering nothing at all.

Contrast (archie-core-umdn). --fg-subtle was 3.37:1 dark and 2.72:1 light,
used for every KPI caption and column header; both move to values clearing
4.5:1 on every surface they actually land on, down to surface-hover at 4.51.
White on the dark accent was 3.2:1 on the active nav item and every primary
button: --accent-fg becomes near-black at 5.96:1 and the accent itself is
untouched, since it is also the link colour and reads correctly on the canvas.
Swept four routes in both themes: no remaining failures outside elements
painted on a gradient, which a compositing check cannot judge and which are
white on blue-purple anyway.

The HEALTH cards take their own height again
(archie-core-1786637500926-421-7c63bcd3). Equalising them was right when both
held a checklist; once setup completes, that card is a title and one line
while Gate pulse carries a gauge and four rows, so matching heights left a
~400px empty box in the first screen.
This commit is contained in:
sam committed 2026-09-20 16:50:28 +10:00
1 parent 25086a66a2
commit 7d7e900e47
14 files changed
+240 -43

No files matched your search

+1 -1
View File
@@ -1 +1 @@
:root{--font-sans:ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;--font-mono:ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;--text-xs:.6875rem;--text-sm:.8125rem;--text-base:.875rem;--text-lg:1.0625rem;--text-xl:1.375rem;--text-2xl:1.875rem;--text-3xl:2.5rem;--sp-1:.25rem;--sp-2:.5rem;--sp-3:.75rem;--sp-4:1rem;--sp-5:1.5rem;--sp-6:2rem;--sp-7:3rem;--radius-sm:6px;--radius-md:10px;--radius-lg:14px;--radius-xl:20px;--radius-pill:999px;--transition:.14s cubic-bezier(.4, 0, .2, 1)}[data-theme=dark]{--lightningcss-light: ;--lightningcss-dark:initial;color-scheme:dark;--bg:#0d1014;--bg-raised:#141920;--surface:#171d25;--surface-hover:#1d242e;--border:#232b36;--border-strong:#303a48;--fg:#e8edf4;--fg-muted:#8b97a8;--fg-subtle:#5d6878;--accent:#4c8dff;--accent-fg:#fff;--accent-soft:#4c8dff24;--ok:#3fbf7f;--ok-soft:#3fbf7f24;--warn:#e8a33d;--warn-soft:#e8a33d24;--danger:#f0616d;--danger-soft:#f0616d24;--info:#4c8dff;--info-soft:#4c8dff24;--idle:#6b7688;--idle-soft:#6b768824;--accent-2:#7b5cff;--bg-blur:#1419208c;--surface-glass:#171d259e;--surface-glass-strong:#141920c7;--workspace:#11151b8c;--hairline:#ffffff0f;--wash-a:#4c8dff1a;--wash-b:#7b5cff1f;--wash-c:#3fbf7f0f;--shadow-workspace:0 24px 70px #00000080;--shadow-sm:0 1px 2px #0006;--shadow-md:0 8px 28px #0000006b}[data-theme=light]{--lightningcss-light:initial;--lightningcss-dark: ;color-scheme:light;--bg:#f6f8fb;--bg-raised:#fff;--surface:#fff;--surface-hover:#f1f4f9;--border:#e2e8f0;--border-strong:#cbd5e1;--fg:#16202e;--fg-muted:#5a6779;--fg-subtle:#8c99ab;--accent:#2563eb;--accent-fg:#fff;--accent-soft:#2563eb1a;--ok:#10935c;--ok-soft:#10935c1f;--warn:#b87514;--warn-soft:#b875141f;--danger:#d4344a;--danger-soft:#d4344a1f;--info:#2563eb;--info-soft:#2563eb1a;--idle:#64748b;--idle-soft:#64748b1f;--accent-2:#7c3aed;--bg-blur:#fff9;--surface-glass:#ffffffb8;--surface-glass-strong:#ffffffe0;--workspace:#ffffff8c;--hairline:#0f172a0f;--wash-a:#2563eb1a;--wash-b:#7c3aed1f;--wash-c:#10935c12;--shadow-workspace:0 24px 70px #0f172a24;--shadow-sm:0 1px 2px #0f172a0f;--shadow-md:0 8px 28px #0f172a1a}*,:before,:after{box-sizing:border-box}html,body{height:100%;margin:0}body{color:var(--fg);font-family:var(--font-sans);font-size:var(--text-base);-webkit-font-smoothing:antialiased;line-height:1.5}a{color:inherit;text-decoration:none}:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.visually-hidden,.sr-only{clip-path:inset(50%);white-space:nowrap;border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}body{background:radial-gradient(70rem 40rem at 8% -10%, var(--wash-a), transparent 62%), radial-gradient(56rem 34rem at 92% 4%, var(--wash-b), transparent 58%), radial-gradient(48rem 30rem at 50% 108%, var(--wash-c), transparent 60%), var(--bg);padding:var(--sp-4);background-attachment:fixed}.shell{min-height:calc(100vh - var(--sp-4) * 2);border-radius:var(--radius-xl);border:1px solid var(--hairline);background:var(--workspace);-webkit-backdrop-filter:blur(28px)saturate(120%);backdrop-filter:blur(28px)saturate(120%);box-shadow:var(--shadow-workspace);flex-direction:column;display:flex;overflow:hidden}.topbar{align-items:center;gap:var(--sp-4);padding:var(--sp-3) var(--sp-4);border-bottom:1px solid var(--hairline);background:var(--bg-blur);z-index:10;display:flex;position:sticky;top:0}.brand{align-items:center;gap:var(--sp-2);font-weight:600;font-size:var(--text-sm);letter-spacing:-.01em;flex:none;display:flex}.brand-mark{background:linear-gradient(135deg, var(--accent), var(--accent-2));color:#fff;width:26px;height:26px;font-size:var(--text-xs);border-radius:8px;place-items:center;font-weight:700;display:grid}.nav{scrollbar-width:none;border-radius:var(--radius-pill);background:var(--surface-glass-strong);border:1px solid var(--hairline);flex:0 auto;align-items:center;gap:2px;min-width:0;margin:0 auto;padding:3px;display:flex;overflow-x:auto}.nav::-webkit-scrollbar{display:none}.nav-item{align-items:center;gap:var(--sp-2);padding:var(--sp-2) var(--sp-3);border-radius:var(--radius-pill);color:var(--fg-muted);font-size:var(--text-sm);white-space:nowrap;cursor:pointer;transition:background var(--transition), color var(--transition);flex:none;display:inline-flex}.nav-item:hover{color:var(--fg);background:var(--surface-hover)}.nav-item[aria-current=page]{background:var(--accent);color:var(--accent-fg);font-weight:500}.nav-item .nav-label{display:inline}.topbar-end{align-items:center;gap:var(--sp-2);flex:none;display:flex}.topbar-search{align-items:center;gap:var(--sp-2);padding:var(--sp-2) var(--sp-3);border-radius:var(--radius-pill);background:var(--surface-glass-strong);border:1px solid var(--hairline);color:var(--fg-subtle);display:flex}.topbar-search input{color:var(--fg);font:inherit;font-size:var(--text-sm);background:0 0;border:0;outline:none;width:8rem}.topbar-search input::placeholder{color:var(--fg-subtle)}.mobile-search-toggle{display:none}.icon-btn{border-Line truncated
:root{--font-sans:ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;--font-mono:ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;--text-xs:.6875rem;--text-sm:.8125rem;--text-base:.875rem;--text-lg:1.0625rem;--text-xl:1.375rem;--text-2xl:1.875rem;--text-3xl:2.5rem;--sp-1:.25rem;--sp-2:.5rem;--sp-3:.75rem;--sp-4:1rem;--sp-5:1.5rem;--sp-6:2rem;--sp-7:3rem;--radius-sm:6px;--radius-md:10px;--radius-lg:14px;--radius-xl:20px;--radius-pill:999px;--transition:.14s cubic-bezier(.4, 0, .2, 1)}[data-theme=dark]{--lightningcss-light: ;--lightningcss-dark:initial;color-scheme:dark;--bg:#0d1014;--bg-raised:#141920;--surface:#171d25;--surface-hover:#1d242e;--border:#232b36;--border-strong:#303a48;--fg:#e8edf4;--fg-muted:#8b97a8;--fg-subtle:#7d8b9e;--accent:#4c8dff;--accent-fg:#0d1014;--accent-soft:#4c8dff24;--ok:#3fbf7f;--ok-soft:#3fbf7f24;--warn:#e8a33d;--warn-soft:#e8a33d24;--danger:#f0616d;--danger-soft:#f0616d24;--info:#4c8dff;--info-soft:#4c8dff24;--idle:#6b7688;--idle-soft:#6b768824;--accent-2:#7b5cff;--bg-blur:#1419208c;--surface-glass:#171d259e;--surface-glass-strong:#141920c7;--workspace:#11151b8c;--hairline:#ffffff0f;--wash-a:#4c8dff1a;--wash-b:#7b5cff1f;--wash-c:#3fbf7f0f;--shadow-workspace:0 24px 70px #00000080;--shadow-sm:0 1px 2px #0006;--shadow-md:0 8px 28px #0000006b}[data-theme=light]{--lightningcss-light:initial;--lightningcss-dark: ;color-scheme:light;--bg:#f6f8fb;--bg-raised:#fff;--surface:#fff;--surface-hover:#f1f4f9;--border:#e2e8f0;--border-strong:#cbd5e1;--fg:#16202e;--fg-muted:#5a6779;--fg-subtle:#636f82;--accent:#2563eb;--accent-fg:#fff;--accent-soft:#2563eb1a;--ok:#10935c;--ok-soft:#10935c1f;--warn:#b87514;--warn-soft:#b875141f;--danger:#d4344a;--danger-soft:#d4344a1f;--info:#2563eb;--info-soft:#2563eb1a;--idle:#64748b;--idle-soft:#64748b1f;--accent-2:#7c3aed;--bg-blur:#fff9;--surface-glass:#ffffffb8;--surface-glass-strong:#ffffffe0;--workspace:#ffffff8c;--hairline:#0f172a0f;--wash-a:#2563eb1a;--wash-b:#7c3aed1f;--wash-c:#10935c12;--shadow-workspace:0 24px 70px #0f172a24;--shadow-sm:0 1px 2px #0f172a0f;--shadow-md:0 8px 28px #0f172a1a}*,:before,:after{box-sizing:border-box}html,body{height:100%;margin:0}body{color:var(--fg);font-family:var(--font-sans);font-size:var(--text-base);-webkit-font-smoothing:antialiased;line-height:1.5}a{color:inherit;text-decoration:none}:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.visually-hidden,.sr-only{clip-path:inset(50%);white-space:nowrap;border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}body{background:radial-gradient(70rem 40rem at 8% -10%, var(--wash-a), transparent 62%), radial-gradient(56rem 34rem at 92% 4%, var(--wash-b), transparent 58%), radial-gradient(48rem 30rem at 50% 108%, var(--wash-c), transparent 60%), var(--bg);padding:var(--sp-4);background-attachment:fixed}.shell{min-height:calc(100vh - var(--sp-4) * 2);border-radius:var(--radius-xl);border:1px solid var(--hairline);background:var(--workspace);-webkit-backdrop-filter:blur(28px)saturate(120%);backdrop-filter:blur(28px)saturate(120%);box-shadow:var(--shadow-workspace);flex-direction:column;display:flex;overflow:hidden}.topbar{align-items:center;gap:var(--sp-4);padding:var(--sp-3) var(--sp-4);border-bottom:1px solid var(--hairline);background:var(--bg-blur);z-index:10;display:flex;position:sticky;top:0}.brand{align-items:center;gap:var(--sp-2);font-weight:600;font-size:var(--text-sm);letter-spacing:-.01em;flex:none;display:flex}.brand-mark{background:linear-gradient(135deg, var(--accent), var(--accent-2));color:#fff;width:26px;height:26px;font-size:var(--text-xs);border-radius:8px;place-items:center;font-weight:700;display:grid}.nav{scrollbar-width:none;border-radius:var(--radius-pill);background:var(--surface-glass-strong);border:1px solid var(--hairline);flex:0 auto;align-items:center;gap:2px;min-width:0;margin:0 auto;padding:3px;display:flex;overflow-x:auto}.nav::-webkit-scrollbar{display:none}.nav-item{align-items:center;gap:var(--sp-2);padding:var(--sp-2) var(--sp-3);border-radius:var(--radius-pill);color:var(--fg-muted);font-size:var(--text-sm);white-space:nowrap;cursor:pointer;transition:background var(--transition), color var(--transition);flex:none;display:inline-flex}.nav-item:hover{color:var(--fg);background:var(--surface-hover)}.nav-item[aria-current=page]{background:var(--accent);color:var(--accent-fg);font-weight:500}.nav-item .nav-label{display:inline}.topbar-end{align-items:center;gap:var(--sp-2);flex:none;display:flex}.topbar-search{align-items:center;gap:var(--sp-2);padding:var(--sp-2) var(--sp-3);border-radius:var(--radius-pill);background:var(--surface-glass-strong);border:1px solid var(--hairline);color:var(--fg-subtle);display:flex}.topbar-search input{color:var(--fg);font:inherit;font-size:var(--text-sm);background:0 0;border:0;outline:none;width:8rem}.topbar-search input::placeholder{color:var(--fg-subtle)}.mobile-search-toggle{display:none}.icon-btn{bordLine truncated
+8 -8
View File
@@ -1,10 +1,10 @@
(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)}})();var e,t,n,r,i,a,o,s,c,l,u,d,f,p,m={},h=[],g=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,_=Array.isArray;function v(e,t){for(var n in t)e[n]=t[n];return e}function y(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function b(t,n,r){var i,a,o,s={};for(o in n)o==`key`?i=n[o]:o==`ref`?a=n[o]:s[o]=n[o];if(arguments.length>2&&(s.children=arguments.length>3?e.call(arguments,2):r),typeof t==`function`&&t.defaultProps!=null)for(o in t.defaultProps)s[o]===void 0&&(s[o]=t.defaultProps[o]);return x(t,s,i,a,null)}function x(e,r,i,a,o){var s={type:e,props:r,key:i,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++n,__i:-1,__u:0};return o==null&&t.vnode!=null&&t.vnode(s),s}function S(e){return e.children}function C(e,t){this.props=e,this.context=t}function w(e,t){if(t==null)return e.__?w(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type==`function`?w(e):null}function T(e){if(e.__P&&e.__d){var n=e.__v,r=n.__e,i=[],a=[],o=v({},n);o.__v=n.__v+1,t.vnode&&t.vnode(o),I(e.__P,o,n,e.__n,e.__P.namespaceURI,32&n.__u?[r]:null,i,r??w(n),!!(32&n.__u),a),o.__v=n.__v,o.__.__k[o.__i]=o,ee(i,o,a),n.__e=n.__=null,o.__e!=r&&E(o)}}function E(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),E(e)}function D(e){(!e.__d&&(e.__d=!0)&&r.push(e)&&!O.__r++||i!=t.debounceRendering)&&((i=t.debounceRendering)||a)(O)}function O(){try{for(var e,t=1;r.length;)r.length>t&&r.sort(o),e=r.shift(),t=r.length,T(e)}finally{r.length=O.__r=0}}function k(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,g,_,v,y=r&&r.__k||h,b=t.length;for(c=A(n,t,y,c,b),d=0;d<b;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&y[p.__i]||m,p.__i=d,v=I(e,p,f,i,a,o,s,c,l,u),g=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&z(f.ref,null,p),u.push(p.ref,p.__c||g,p)),_==null&&g!=null&&(_=g),4&p.__u?(c=j(p,c,e),f.__e&&(f.__e=null)):typeof p.type==`function`&&v!==void 0?c=v:g&&(c=g.nextSibling),p.__u&=-7);return n.__e=_,c}function A(e,t,n,r,i){var a,o,s,c,l,u=n.length,d=u,f=0;for(e.__k=Array(i),a=0;a<i;a++)(o=t[a])!=null&&typeof o!=`boolean`&&typeof o!=`function`?(typeof o==`string`||typeof o==`number`||typeof o==`bigint`||o.constructor==String?o=e.__k[a]=x(null,o,null,null,null):_(o)?o=e.__k[a]=x(S,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=e.__k[a]=x(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):e.__k[a]=o,c=a+f,o.__=e,o.__b=e.__b+1,s=null,(l=o.__i=M(o,n,c,d))!=-1&&(d--,(s=n[l])&&(s.__u|=2)),s==null||s.__v==null?(l==-1&&(i>u?f--:i<u&&f++),typeof o.type!=`function`&&(o.__u|=4)):l!=c&&(l==c-1?f--:l==c+1?f++:(l>c?f--:f++,o.__u|=4))):e.__k[a]=null;if(d)for(a=0;a<u;a++)(s=n[a])!=null&&!(2&s.__u)&&(s.__e==r&&(r=w(s)),ne(s,s));return r}function j(e,t,n){var r,i;if(typeof e.type==`function`){for(r=e.__k,i=0;r&&i<r.length;i++)r[i]&&(r[i].__=e,t=j(r[i],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=w(e)),t=n.insertBefore(e.__e,t||null));do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function M(e,t,n,r){var i,a,o,s=e.key,c=e.type,l=t[n],u=l!=null&&!(2&l.__u);if(l===null&&s==null||u&&s==l.key&&c==l.type)return n;if(r>+!!u){for(i=n-1,a=n+1;i>=0||a<t.length;)if((l=t[o=i>=0?i--:a++])!=null&&!(2&l.__u)&&s==l.key&&c==l.type)return o}return-1}function N(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||g.test(t)?n:n+`px`}function P(e,t,n,r,i){var a,o;n:if(t==`style`)if(typeof n==`string`)e.style.cssText=n;else{if(typeof r==`string`&&(e.style.cssText=r=``),r)for(t in r)n&&t in n||N(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||N(e.style,t,n[t])}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(u,`$1`)),o=t.toLowerCase(),t=o in e||t==`onFocusOut`||t==`onFocusIn`?o.slice(2):t.slice(2),e.l||={},e.l[t+a]=n,n?r?n[l]=r[l]:(n[l]=d,e.addEventListener(t,a?p:f,a)):e.removeEventListener(t,a?p:f,a);else{if(i==`http://www.w3.org/2000/svg`)t=t.replace(/xlink(H|:h)/,`h`).replace(/sName$/,`s`);else if(t!=`width`&&t!=`height`&&t!=`href`&&t!=`list`&&t!=`form`&&t!=`tabIndex`&&t!=`download`&&t!=`rowSpan`&&t!=`colSpan`&&t!=`role`&&t!=`popover`&&t in e)try{e[t]=n??``;break n}catch{}typeof n==`function`||(n==null||!1===n&&t[4]!=`-`?e.removeAttribute(t):e.setAttribute(t,t==`popover`&&n==1?``:n))}}function F(e){return function(n){if(this.l){var r=thiLine truncated
`)[0].slice(0,200)}catch{}return`${e.status} ${e.statusText}`}var Ae=class extends Error{constructor(e,t){super(e),this.status=t}};function je(e){let t=e instanceof Ae?e.status:void 0,n=e?.message||`Action failed`;return t===401?{kind:`session-expired`,message:n}:t>=400&&t<500?{kind:`refused`,message:n}:{kind:`broken`,message:n}}async function Me(e,t){let n=await fetch(e,t);if(!n.ok)throw new Ae(await ke(n),n.status);return n}async function K(e,{method:t=`GET`,body:n,timeoutMs:r=De,parse:i=!0}={}){let a={Accept:`application/json`},o={method:t,headers:a,signal:AbortSignal.timeout(r)};t!==`GET`&&(a[`Content-Type`]=`application/json`,a[`X-Archie-CSRF`]=`1`),n!==void 0&&(o.body=JSON.stringify(n));let s=await Me(e,o);return i?s.json():void 0}var q={summary:()=>K(`/api/summary`),tasks:()=>K(`/api/tasks`),taskMeta:()=>K(`/api/task-meta`),task:e=>K(`/api/tasks/${e}`),taskAttempts:e=>K(`/api/tasks/${e}/attempts`),taskChanges:(e,t)=>K(`/api/tasks/${e}/changes`+Oe(t)),taskDebug:(e,t)=>K(`/api/tasks/${e}/debug`+Oe(t)),taskAction:(e,t)=>K(`/api/tasks/${e}/action`,{method:`POST`,body:{action:t}}),setup:()=>K(`/api/setup`),capabilities:()=>K(`/api/capabilities`),workflows:()=>K(`/api/workflows`),workRequest:e=>K(`/api/work-requests`,{method:`POST`,body:e}),skills:()=>K(`/api/skills`),channels:()=>K(`/api/channels`),curators:()=>K(`/api/curators`),channelReload:e=>K(`/api/channels/${encodeURIComponent(e)}/reload`,{method:`POST`,body:{}}),config:()=>K(`/api/config`),version:()=>K(`/api/version`),configUpdate:e=>K(`/api/config`,{method:`PATCH`,body:{updates:e}}),configRepoUpdate:(e,t,n,r)=>K(`/api/config/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`PATCH`,body:{field:n,value:r}}),configReset:e=>K(`/api/config/reset`,{method:`POST`,body:{key:e}}),logs:e=>K(`/api/logs`+Oe(e)),taskLogs:(e,t)=>K(`/api/tasks/${e}/logs`+Oe(t)),taskLogDownloadURL:(e,t)=>`/api/tasks/${e}/logs/download`+(t==null?``:`?attempt=${t}`),captures:e=>K(`/api/captures`+Oe({limit:e})),mappings:()=>K(`/api/mappings`),mappingCreate:e=>K(`/api/mappings`,{method:`POST`,body:e}),mappingUpdate:(e,t)=>K(`/api/mappings/${e}`,{method:`PATCH`,body:t}),mappingDelete:e=>K(`/api/mappings/${e}`,{method:`DELETE`,parse:!1}),mappingPreview:(e,t)=>K(`/api/mappings/preview`,{method:`POST`,body:{capture_id:e,fields:t}}),bindings:()=>K(`/api/bindings`),bindingCreate:e=>K(`/api/bindings`,{method:`POST`,body:e}),bindingUpdate:(e,t)=>K(`/api/bindings/${e}`,{method:`PATCH`,body:t}),bindingDelete:e=>K(`/api/bindings/${e}`,{method:`DELETE`,parse:!1}),bindingApprove:e=>K(`/api/bindings/${e}/approve`,{method:`POST`}),chatSessions:()=>K(`/api/chat/sessions`),chatMessages:e=>K(`/api/chat/sessions/${encodeURIComponent(e)}/messages`),chatTurns:e=>K(`/api/chat/sessions/${encodeURIComponent(e)}/turns`),chatCancel:e=>K(`/api/chat/cancel`,{method:`POST`,body:{session_id:e}}),chatMessage:(e,t)=>K(`/api/chat/message`,{method:`POST`,body:{channel_id:e,source_id:Ee(),text:t,page:location.hash.slice(1)||`/`}}),chatPersona:(e,t)=>K(`/api/chat/persona`,{method:`POST`,body:{session_id:e,name:t}}),chatUpdate:()=>K(`/api/chat/update`),chatUpdateDefer:e=>K(`/api/chat/update/defer`,{method:`POST`,body:{snapshot:e}}),chatUpdateInstall:e=>K(`/api/chat/update/install`,{method:`POST`,body:{snapshot:e},timeoutMs:12e4}),chatDangerous:()=>K(`/api/chat/dangerous`),chatDangerousRequest:(e,t)=>K(`/api/chat/dangerous/${encodeURIComponent(e)}`,{method:`POST`,body:{spec:t}}),chatDangerousDecision:(e,t)=>K(`/api/chat/dangerous/${encodeURIComponent(e)}/decision`,{method:`POST`,body:{decision:t}}),chatStream:(e,{signal:t}={})=>Me(`/api/chat/stream`,{method:`POST`,headers:{Accept:`text/event-stream`,"Content-Type":`application/json`,"X-Archie-CSRF":`1`},body:JSON.stringify(e),signal:t})};function Ne(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 Pe(e,t){let n=new EventSource(`/api/logs/stream`);return n.onopen=()=>t?.(`live`),n.onerror=()=>t?.(`reconnecting`),n.onmessage=t=>{try{e(JSON.parse(t.data))}catch{}},()=>n.close()}function Fe(e,t){return e?t.filter(t=>t.section&&e[t.section]===!1).map(e=>e.path):[]}var Ie=[{id:`queued`,label:`Queued`,kind:`idle`},{id:`running`,label:`Working`,kind:`info`},{id:`waiting_human`,label:`Waiting for you`,kind:`warn`,needs_you:!0},{id:`pr_open`,label:`In review`,kind:`ok`},{id:`merged`,label:`Merged`,kind:`ok`},{id:`parked`,label:`Parked`,kind:`warn`,needs_you:!0},{id:`dead`,label:`Stopped (too many retries)`,kind:`danger`},{id:`rejected`,label:`Rejected`,kind:`danger`},{id:`closed_wont_do`,label:`Won't do`,kind:`idle`}],Le=[{id:`cancel`,label:`Cancel`,kind:`quiet`,confirm:`Cancel "{title}"? This closes the forge issue.`},{id:`stop`,label:`Stop`,kind:`primary`,confirm:`Stop "{title}"? Recoverable work will remain parked.`},{id:`approve`,label:`Approve`,kind:`primary`},{id:`reject`,label:`Reject`,kind:`quiet`,confirm:`Reject "{title}"? ThiLine truncated
`).map(e=>e.trim()).find(Boolean)||``,r=n.length>tt?`${n.slice(0,tt).trimEnd()}…`:n;return{text:r,full:t,truncated:r!==t}}function Q({text:e,kind:t=`idle`}){return J(`span`,{className:`pill pill-${t}`,children:e})}var rt=`archie.setup-complete.dismissed.v1`;function it(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?.(rt),{kind:`incomplete`,remaining:n}):t?.getItem?.(`archie.setup-complete.dismissed.v1`)===`1`?{kind:`dismissed`,remaining:[]}:{kind:`complete`,remaining:[]}}function at(e=globalThis.localStorage){e?.setItem?.(rt,`1`)}var ot=new Set([`waiting_human`,`parked`]);function st(e=[]){let t=e.filter(e=>ot.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 ct({title:e,detail:t}){return J(`div`,{className:`empty`,children:[J(`div`,{className:`empty-title`,children:e}),t&&J(`div`,{children:t})]})}function lt(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 ut(){let e=new Date().getHours();return e<5?`Still up?`:e<12?`Good morning`:e<18?`Good afternoon`:`Good evening`}function dt(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 ft(){let[e,t]=U([]),[n,r]=U(`connecting`),[i,a]=U(`idle`),[o,s]=U(new Map),[c,l]=U(null),[u,d]=U(null),[f,p]=U(null),[m,h]=U(null),[g,_]=U(null),[,v]=U(!1),y=async()=>{_(null);try{let[e,t,n,r]=await Promise.all([q.summary(),q.setup().catch(()=>null),q.workflows().catch(()=>null),q.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))}};W(()=>(y(),Ne(e=>{t(t=>{let n=[e,...t];return n.splice(50),n})},e=>{r(e),a(e===`live`?`ok`:`warn`)})),[]);let b=()=>{at(),v(e=>!e)},x=u?.operator?`${ut()}, ${u.operator}`:ut(),C=null;if(g)C=J(`button`,{className:`btn btn-primary`,onClick:y,children:[J(Y,{name:`refresh`,size:15}),` Retry`]});else if(m!==null){let e=st(m),t=e.attention.count,n=e.running.count;C=J(S,{children:[t>0&&J(`a`,{className:`btn btn-attention`,href:e.attention.href,children:[J(Y,{name:`tasks`,size:15}),` `,t,` need`,t===1?`s`:``,` you`]}),n>0&&J(`a`,{className:`btn`,href:e.running.href,children:[J(Y,{name:`workflows`,size:15}),` `,n,` running`]}),J(`a`,{className:`btn`,href:`#/logs`,children:[J(Y,{name:`logs`,size:15}),` Logs`]}),J(`button`,{className:`btn btn-primary`,onClick:y,children:[J(Y,{name:`refresh`,size:15}),` Refresh`]})]})}let w=null;if(g)w=J(`div`,{className:`card`,children:J(ct,{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=J(S,{children:[J(Z,{label:`Working now`,value:e.running||0,compare:`${e.queued||0} waiting to start`,series:i.map(e=>e.tokens||0)}),J(Z,{label:`Needs you`,value:n,compare:n?`Parked or awaiting a reply`:`Nothing is blocked`,goodDirection:`down`}),J(Z,{label:`Delivered`,value:t,compare:r?`${Math.round(t/r*100)}% of all tasks`:`No tasks yet`}),J(Z,{label:`Tokens used`,value:Ze(i.reduce((e,t)=>e+(t.tokens||0),0)),compare:`Across ${i.length||0} days`,trend:dt(i.map(e=>e.tokens||0)),goodDirection:`down`,series:i.map(e=>e.tokens||0)})]})}let T=null,E=it(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=J(`div`,{className:`card setup`,children:[J(`div`,{className:`card-head`,children:[J(`div`,{children:[J(`h2`,{className:`card-title`,children:`Finish setting up`}),J(`p`,{className:`card-sub`,children:`Archie needs these before it can work on its own.`})]}),J(`span`,{className:`setup-pct`,children:[t,`%`]})]}),J(`div`,{className:`setup-bar`,children:J(`div`,{className:`setup-bar-fill`,style:{width:`${t}%`}})}),J(`ul`,{className:`setup-list`,children:u.steps.map((e,t)=>J(`li`,{className:`setup-step ${e.done?`done`:``}`,children:[J(`span`,{className:`setup-check`,children:e.done?J(Y,{name:`check`,size:12}):``}),J(`div`,{children:[J(`div`,{className:`setup-step-title`,children:e.title}),e.detail&&J(`div`,{className:`setup-step-detail`,children:e.detail})]})]},t))})]})}else T=J(`div`,{className:`card setup setup-done`,children:J(`div`,{className:`card-head`,children:[J(`div`,{children:[J(`h2`,{className:`card-title`,children:`Setup complete`}),J(`p`,{className:`card-sub`,children:`Archie is configured and ready to work.`})]}),J(`div`,{className:`setup-complete-actions`,children:[J(`span`,{className:`setup-pct`,children:J(Y,{name:`check`,size:16})}),J(`button`,{className:`icon-btn setup-dismiss`,type:`Line truncated
`),children:[J(`td`,{className:`strong`,children:e.label||e.id}),J(`td`,{className:`mono`,children:e.install_type||`—`}),J(`td`,{className:`mono`,children:e.running_version||`—`}),J(`td`,{className:`mono`,children:e.latest_available||`—`}),J(`td`,{children:J(Q,{text:Zn[e.status]||e.status,kind:Qn[e.status]||`idle`})})]},e.id||e.label))})]})})})}function er({title:e,sub:t,children:n}){return J(`div`,{className:`card cfg-section`,children:[J(`div`,{className:`card-head`,children:J(`div`,{children:[J(`h2`,{className:`card-title`,children:e}),J(`p`,{className:`card-sub`,children:t})]})}),n]})}function tr(e){return e?.error?e.error:e?.snapshot?.deferred?`Update deferred.`:`Archie is up to date.`}function nr({data:e,onDefer:t,onInstall:n}){let r=e?.available||[];return r.length?J(er,{title:`Updates`,sub:`Whether a newer release is available, and what to do about it.`,children:[J(`p`,{className:`cfg-note`,children:r.map(e=>`${e.Label||e.label}: ${e.Available||e.available}`).join(` · `)}),J(`div`,{className:`cfg-actions`,children:[J(`button`,{className:`btn`,type:`button`,onClick:()=>t?.(e.snapshot),children:`Defer`}),e.can_install&&J(`button`,{className:`btn btn-primary`,type:`button`,onClick:()=>n?.(e.snapshot),children:`Install update`})]})]}):J(er,{title:`Updates`,sub:`Whether a newer release is available, and what to do about it.`,children:J(`p`,{className:`cfg-note`,children:tr(e)})})}var rr=e=>e.Number??e.number,ir=e=>e.Label??e.label??`checkpoint`;function ar({data:e,onRequest:t,onDecide:n}){let[r,i]=U(``),[a,o]=U(``);if(e?.error)return J(er,{title:`Dangerous actions`,sub:`Actions that need explicit approval before they run.`,children:J(`p`,{className:`cfg-note`,children:e.error})});let s=e?.pending||[];return J(er,{title:`Dangerous actions`,sub:`Actions that need explicit approval before they run. Requesting one only queues it.`,children:[J(`div`,{className:`cfg-request-row`,children:[J(`select`,{"aria-label":`Checkpoint`,value:r,onChange:e=>i(e.target.value),children:[J(`option`,{value:``,children:`Select checkpoint`}),(e?.checkpoints||[]).map(e=>J(`option`,{value:String(rr(e)),children:[rr(e),` — `,ir(e)]},rr(e)))]}),J(`button`,{className:`btn`,type:`button`,disabled:!r,onClick:()=>t?.(`rollback`,r),children:`Request rollback`})]}),J(`div`,{className:`cfg-request-row`,children:[J(`input`,{placeholder:`Process name or id`,"aria-label":`Process name or id`,value:a,onInput:e=>o(e.target.value)}),J(`button`,{className:`btn`,type:`button`,disabled:!a.trim(),onClick:()=>t?.(`stop`,a),children:`Request stop`})]}),s.length?J(S,{children:s.map(e=>J(`div`,{className:`cfg-pending`,children:[J(`span`,{children:e.description}),J(`div`,{className:`cfg-actions`,children:[J(`button`,{className:`btn`,type:`button`,onClick:()=>n?.(e.id,`approve`),children:`Approve`}),J(`button`,{className:`btn`,type:`button`,onClick:()=>n?.(e.id,`permanent`),children:`Approve for 24h`}),J(`button`,{className:`btn`,type:`button`,onClick:()=>n?.(e.id,`deny`),children:`Deny`})]})]},e.id))}):J(`p`,{className:`cfg-note`,children:`No pending dangerous actions.`})]})}function $({title:e,detail:t}){return J(`div`,{className:`empty`,children:[J(`div`,{className:`empty-title`,children:e}),t&&J(`div`,{children:t})]})}function or({title:e,sub:t,children:n}){return J(`div`,{className:`card cfg-section`,children:[J(`div`,{className:`card-head`,children:J(`div`,{children:[J(`h2`,{className:`card-title`,children:e}),J(`p`,{className:`card-sub`,children:t})]})}),n]})}function sr({origins:e}){return e?.length?J(or,{title:`Configuration sources`,sub:`Applied from top to bottom; later entries take precedence over earlier ones.`,children:J(`div`,{className:`kv-list`,children:e.map((e,t)=>J(qn,{label:`${e.layer} ${e.role}${e.feature?` (${e.feature})`:``}`,value:e.path},t))})}):J(or,{title:`Configuration sources`,sub:`The files that supplied the running configuration.`,children:J($,{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 J(or,{title:`Work lifecycle`,sub:`The task statuses and operator actions archied ships.`,children:J($,{title:`Lifecycle unavailable`,detail:t})});let n=e?.statuses||[],r=e?.actions||[];return J(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:[J(`h3`,{className:`cfg-subhead`,children:`Statuses`}),n.length?J(`div`,{className:`kv-list`,children:n.map(e=>{let t=e.label??We(e.id),n=e.kind??Ge(e.id);return J(`div`,{className:`kv`,children:[J(`span`,{className:`kv-label`,children:e.id}),J(`span`,{className:`kv-value`,children:J(Q,{text:t,kind:n})})]},e.id)})}):J($,{title:`No statuses reported`,detail:`The server did not return any lifecycle statuses.`}),J(`h3`,{className:`cfg-subhead`,children:`Actions`}),r.length?J(`div`,{className:`kv-list`,children:r.map(e=>{let t=e.label??e.id,n=cr(e.kind);return J(`Line truncated
`),i=[],a=null,o=null,s=0,c=()=>{i.length&&(n.push(J(`p`,{children:Jr(i.join(` `))},s++)),i=[])},l=()=>{if(!a)return;let e=a.items.map((e,t)=>J(`li`,{children:Jr(e)},t));n.push(a.tag===`ol`?J(`ol`,{children:e},s++):J(`ul`,{children:e},s++)),a=null};for(let e=0;e<r.length;e++){let t=r[e];if(t.startsWith("```")){c(),l(),o?(n.push(J(`pre`,{children:J(`code`,{children:o.join(`
`)})},s++)),o=null):o=[];continue}if(o){o.push(t);continue}let u=Xr(t),d=e+1<r.length?Xr(r[e+1]):null;if(u&&d&&Zr(d)&&u.length===d.length){c(),l();let t=[];for(e+=2;e<r.length;e++){let n=Xr(r[e]);if(!n||n.length!==u.length){e--;break}t.push(n)}n.push(J(`table`,{children:[J(`thead`,{children:J(`tr`,{children:u.map((e,t)=>J(`th`,{children:Jr(e)},t))})}),J(`tbody`,{children:t.map((e,t)=>J(`tr`,{children:e.map((e,t)=>J(`td`,{children:Jr(e)},t))},t))})]},s++));continue}if(!t.trim()){c(),l();continue}let f=t.match(/^(#{1,3})\s+(.+)$/);if(f){c(),l();let e=`h${f[1].length}`;n.push(J(e,{children:Jr(f[2])},s++));continue}let p=t.match(/^\s*[-*]\s+(.+)$/),m=t.match(/^\s*\d+[.)]\s+(.+)$/);if(p||m){c();let e=m?`ol`:`ul`;(!a||a.tag!==e)&&(l(),a={tag:e,items:[]}),a.items.push((p||m)[1]);continue}if(t.startsWith(`>`)){c(),l(),n.push(J(`blockquote`,{children:Jr(t.replace(/^>\s?/,``))},s++));continue}i.push(t)}return c(),l(),o&&n.push(J(`pre`,{children:J(`code`,{children:o.join(`
`)})},s++)),J(`div`,{className:t,children:n})}function Xr(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 Zr(e){return e.every(e=>/^:?-{3,}:?$/.test(e))}var Qr=`archie.web.chat.channel`;function $r(){let e=localStorage.getItem(Qr);return e||(e=Ee(),localStorage.setItem(Qr,e)),e}function ei(e){return{text:e,sourceID:Ee()}}function ti(e){return{...e}}function ni(e,t){let n=!!(e&&typeof e==`object`&&e.turn&&typeof e.turn.text==`string`),r=n?e.turn.text:t.trim();return{text:r,turn:n?ti(e.turn):ei(r),isRetry:n}}function ri({scrollTop:e,viewportHeight:t,optionTop:n,optionHeight:r}){if(r>=t||n<e)return n;let i=n+r;return i>e+t?i-t:e}function ii(e){return e.title||e.branch_name||`Conversation ${e.session_id.slice(0,8)}`}function ai(e,t){if(!t)return`Archie`;let n=(e||[]).find(e=>e.session_id===t);return n?ii(n):`Archie`}function oi(){return location.hash.slice(1)||`/`}function si({open:e=!0}){let[t,n]=U([]),[r,i]=U(``),[a,o]=U([]),[s,c]=U(``),[l,u]=U(`Ready`),[d,f]=U(!1),[p,m]=U({}),[h,g]=U(``),[_,v]=U(``),[y,b]=U(``),[x,C]=U([]),[w,T]=U([]),[E,D]=U(0),[O,k]=U(!1),[A,j]=U(null),M=G(null),N=G(null),P=G(null),F=G(null),I=G(null),L=G(null),ee=G(d);ee.current=d,W(()=>{let e=e=>{let t=L.current;t?.open&&(e.target instanceof Node&&t.contains(e.target)||(t.open=!1))};return document.addEventListener(`pointerdown`,e),document.addEventListener(`focusin`,e),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`focusin`,e)}},[]),W(()=>{e&&N.current?.focus()},[e]),W(()=>{if(!O)return;let e=I.current,t=e?.children?.[E];!e||!t||(e.scrollTop=ri({scrollTop:e.scrollTop,viewportHeight:e.clientHeight,optionTop:t.offsetTop,optionHeight:t.offsetHeight}))},[E,O]),W(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},[a,A]),W(()=>{R().catch(e=>{u(e.message||`Chat unavailable`)});let e=()=>{P.current?.abort()};return window.addEventListener(`archie:teardown`,e),()=>{window.removeEventListener(`archie:teardown`,e),P.current?.abort()}},[]);async function R(){let e=await q.chatSessions(),t=e.sessions||[];n(t),m(e),g(e.active_persona||``);let i=e.providers||[],a=e.active_provider||i[0]||``;v(a),b(e.active_model||``);let o=(e.commands||[]).map(e=>typeof e==`string`?{command:e,usage:e,description:``}:e);C(o),!r&&t[0]&&await te(t[0].session_id,e,t)}async function te(e,t,n){let r=t||p;i(e),o([]),j(null);let a=r.active_personas?.[e]||r.active_persona||``;g(a);try{await q.chatMessage($r(),`/resume ${e}`);let[t,n]=await Promise.all([q.chatMessages(e),q.chatTurns(e)]),r=new Map;for(let e of n||[]){let t=e.assistant_message_id||e.AssistantMessageID;t&&r.set(t,e)}let i=(t||[]).map(e=>{let t=e.message_id||e.MessageID,n=r.get(t);return n?{...e,tool_calls:n.tool_calls||n.ToolCalls||[]}:e});o(i)}catch(e){u(e.message||`Could not load session messages`)}}async function z(e){if(r)try{u(`Working…`);let t=await q.chatMessage($r(),e);t.session_id&&i(t.session_id),u(t.reply||`Session updated`),await R(),(t.session_id||r)&&await te(t.session_id||r),F.current&&(F.current.open=!1)}catch(e){u(e.message||`Session action failed`)}}function ne(e,t){let n=window.prompt(t);n?.trim()&&z(`${e} ${n.trim()}`)}function re(e){let t=e.target.value;g(t),!(!r||!t)&&q.chatPersona(r,t).then(()=>{m(e=>({...e,active_personas:{...e.active_personas||{},[r]:t}})),u(`Personality: ${t}`)}).catch(e=>{u(e.message||`Failed to set personality`)})}async function ie(e){let t=e.target.value;if(v(t),t)try{let e=await q.chatMessage($r(),`/model --provider ${t}`);u(e.reply||`Provider updated`),await R()}catch(e){u(`Provider update failed: ${e.message||e}`)}}async function B(e){let t=e.target.value;if(b(t),t)try{let e=await q.chatMessage($r(),`/model ${t}`);u(e.reply||`Model updated`),await R()}catch(e){u(`Model update failed: ${e.message||e}`)}}function V(){c(`/new`),ce({textOverride:`/new`})}function ae(e){let t=e.target.value;c(t);let n=t.slice(0,e.target.selectionStart).match(/(?:^|\s)\/([^\s]*)$/);if(n){let e=n[1].toLowerCase(),t=x.filter(t=>`${t.command} ${t.description}`.toLowerCase().includes(e)).slice(0,8);if(t.length){T(t),D(0),k(!0);return}}k(!1),T([])}function oe(e){let t=w[e];if(!t||!N.current)return;let n=N.current,r=n.value.slice(0,n.selectionStart),i=n.value.slice(n.selectionStart),a=r.search(/(?:^|\s)\/[^\s]*$/),o=a<0?r.length:a+ +(r[a]===` `),s=`${r.slice(0,o)}${t.command} ${i}`;c(s),k(!1);let l=o+t.command.length+1;setTimeout(()=>{n.focus(),n.setSelectionRange(l,l)},0)}function se(e){if(O&&w.length){if(e.key===`Enter`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&w.some(e=>e.command===s.trim())){e.preventDefault(),k(!1),ce();return}if(e.key===`ArrowDown`){e.preventDefault(),D(e=>(e+1)%w.length);return}if(e.key===`ArrowUp`){e.preventDefault(),D(e=>(e+w.length-1)%w.length);return}if(e.key===`Enter`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey){e.preventDefault(),oe(E);return}if(e.key===`Escape`){e.preventDefault(),k(!1);re Line truncated
(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)}})();var e,t,n,r,i,a,o,s,c,l,u,d,f,p,m={},h=[],g=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,_=Array.isArray;function v(e,t){for(var n in t)e[n]=t[n];return e}function y(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function b(t,n,r){var i,a,o,s={};for(o in n)o==`key`?i=n[o]:o==`ref`?a=n[o]:s[o]=n[o];if(arguments.length>2&&(s.children=arguments.length>3?e.call(arguments,2):r),typeof t==`function`&&t.defaultProps!=null)for(o in t.defaultProps)s[o]===void 0&&(s[o]=t.defaultProps[o]);return x(t,s,i,a,null)}function x(e,r,i,a,o){var s={type:e,props:r,key:i,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++n,__i:-1,__u:0};return o==null&&t.vnode!=null&&t.vnode(s),s}function S(e){return e.children}function C(e,t){this.props=e,this.context=t}function w(e,t){if(t==null)return e.__?w(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type==`function`?w(e):null}function T(e){if(e.__P&&e.__d){var n=e.__v,r=n.__e,i=[],a=[],o=v({},n);o.__v=n.__v+1,t.vnode&&t.vnode(o),I(e.__P,o,n,e.__n,e.__P.namespaceURI,32&n.__u?[r]:null,i,r??w(n),!!(32&n.__u),a),o.__v=n.__v,o.__.__k[o.__i]=o,ee(i,o,a),n.__e=n.__=null,o.__e!=r&&E(o)}}function E(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),E(e)}function D(e){(!e.__d&&(e.__d=!0)&&r.push(e)&&!O.__r++||i!=t.debounceRendering)&&((i=t.debounceRendering)||a)(O)}function O(){try{for(var e,t=1;r.length;)r.length>t&&r.sort(o),e=r.shift(),t=r.length,T(e)}finally{r.length=O.__r=0}}function k(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,g,_,v,y=r&&r.__k||h,b=t.length;for(c=A(n,t,y,c,b),d=0;d<b;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&y[p.__i]||m,p.__i=d,v=I(e,p,f,i,a,o,s,c,l,u),g=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&ne(f.ref,null,p),u.push(p.ref,p.__c||g,p)),_==null&&g!=null&&(_=g),4&p.__u?(c=j(p,c,e),f.__e&&(f.__e=null)):typeof p.type==`function`&&v!==void 0?c=v:g&&(c=g.nextSibling),p.__u&=-7);return n.__e=_,c}function A(e,t,n,r,i){var a,o,s,c,l,u=n.length,d=u,f=0;for(e.__k=Array(i),a=0;a<i;a++)(o=t[a])!=null&&typeof o!=`boolean`&&typeof o!=`function`?(typeof o==`string`||typeof o==`number`||typeof o==`bigint`||o.constructor==String?o=e.__k[a]=x(null,o,null,null,null):_(o)?o=e.__k[a]=x(S,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=e.__k[a]=x(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):e.__k[a]=o,c=a+f,o.__=e,o.__b=e.__b+1,s=null,(l=o.__i=M(o,n,c,d))!=-1&&(d--,(s=n[l])&&(s.__u|=2)),s==null||s.__v==null?(l==-1&&(i>u?f--:i<u&&f++),typeof o.type!=`function`&&(o.__u|=4)):l!=c&&(l==c-1?f--:l==c+1?f++:(l>c?f--:f++,o.__u|=4))):e.__k[a]=null;if(d)for(a=0;a<u;a++)(s=n[a])!=null&&!(2&s.__u)&&(s.__e==r&&(r=w(s)),re(s,s));return r}function j(e,t,n){var r,i;if(typeof e.type==`function`){for(r=e.__k,i=0;r&&i<r.length;i++)r[i]&&(r[i].__=e,t=j(r[i],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=w(e)),t=n.insertBefore(e.__e,t||null));do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function M(e,t,n,r){var i,a,o,s=e.key,c=e.type,l=t[n],u=l!=null&&!(2&l.__u);if(l===null&&s==null||u&&s==l.key&&c==l.type)return n;if(r>+!!u){for(i=n-1,a=n+1;i>=0||a<t.length;)if((l=t[o=i>=0?i--:a++])!=null&&!(2&l.__u)&&s==l.key&&c==l.type)return o}return-1}function N(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||g.test(t)?n:n+`px`}function P(e,t,n,r,i){var a,o;n:if(t==`style`)if(typeof n==`string`)e.style.cssText=n;else{if(typeof r==`string`&&(e.style.cssText=r=``),r)for(t in r)n&&t in n||N(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||N(e.style,t,n[t])}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(u,`$1`)),o=t.toLowerCase(),t=o in e||t==`onFocusOut`||t==`onFocusIn`?o.slice(2):t.slice(2),e.l||={},e.l[t+a]=n,n?r?n[l]=r[l]:(n[l]=d,e.addEventListener(t,a?p:f,a)):e.removeEventListener(t,a?p:f,a);else{if(i==`http://www.w3.org/2000/svg`)t=t.replace(/xlink(H|:h)/,`h`).replace(/sName$/,`s`);else if(t!=`width`&&t!=`height`&&t!=`href`&&t!=`list`&&t!=`form`&&t!=`tabIndex`&&t!=`download`&&t!=`rowSpan`&&t!=`colSpan`&&t!=`role`&&t!=`popover`&&t in e)try{e[t]=n??``;break n}catch{}typeof n==`function`||(n==null||!1===n&&t[4]!=`-`?e.removeAttribute(t):e.setAttribute(t,t==`popover`&&n==1?``:n))}}function F(e){return function(n){if(this.l){var r=thLine truncated
`)[0].slice(0,200)}catch{}return`${e.status} ${e.statusText}`}var Me=class extends Error{constructor(e,t){super(e),this.status=t}};function Ne(e){let t=e instanceof Me?e.status:void 0,n=e?.message||`Action failed`;return t===401?{kind:`session-expired`,message:n}:t>=400&&t<500?{kind:`refused`,message:n}:{kind:`broken`,message:n}}async function Pe(e,t){let n=await fetch(e,t);if(!n.ok)throw new Me(await je(n),n.status);return n}async function G(e,{method:t=`GET`,body:n,timeoutMs:r=ke,parse:i=!0}={}){let a={Accept:`application/json`},o={method:t,headers:a,signal:AbortSignal.timeout(r)};t!==`GET`&&(a[`Content-Type`]=`application/json`,a[`X-Archie-CSRF`]=`1`),n!==void 0&&(o.body=JSON.stringify(n));let s=await Pe(e,o);return i?s.json():void 0}var K={summary:()=>G(`/api/summary`),tasks:()=>G(`/api/tasks`),taskMeta:()=>G(`/api/task-meta`),task:e=>G(`/api/tasks/${e}`),taskAttempts:e=>G(`/api/tasks/${e}/attempts`),taskChanges:(e,t)=>G(`/api/tasks/${e}/changes`+Ae(t)),taskDebug:(e,t)=>G(`/api/tasks/${e}/debug`+Ae(t)),taskAction:(e,t)=>G(`/api/tasks/${e}/action`,{method:`POST`,body:{action:t}}),setup:()=>G(`/api/setup`),capabilities:()=>G(`/api/capabilities`),workflows:()=>G(`/api/workflows`),workRequest:e=>G(`/api/work-requests`,{method:`POST`,body:e}),skills:()=>G(`/api/skills`),channels:()=>G(`/api/channels`),curators:()=>G(`/api/curators`),channelReload:e=>G(`/api/channels/${encodeURIComponent(e)}/reload`,{method:`POST`,body:{}}),config:()=>G(`/api/config`),version:()=>G(`/api/version`),configUpdate:e=>G(`/api/config`,{method:`PATCH`,body:{updates:e}}),configRepoUpdate:(e,t,n,r)=>G(`/api/config/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`PATCH`,body:{field:n,value:r}}),configReset:e=>G(`/api/config/reset`,{method:`POST`,body:{key:e}}),logs:e=>G(`/api/logs`+Ae(e)),taskLogs:(e,t)=>G(`/api/tasks/${e}/logs`+Ae(t)),taskLogDownloadURL:(e,t)=>`/api/tasks/${e}/logs/download`+(t==null?``:`?attempt=${t}`),captures:e=>G(`/api/captures`+Ae({limit:e})),mappings:()=>G(`/api/mappings`),mappingCreate:e=>G(`/api/mappings`,{method:`POST`,body:e}),mappingUpdate:(e,t)=>G(`/api/mappings/${e}`,{method:`PATCH`,body:t}),mappingDelete:e=>G(`/api/mappings/${e}`,{method:`DELETE`,parse:!1}),mappingPreview:(e,t)=>G(`/api/mappings/preview`,{method:`POST`,body:{capture_id:e,fields:t}}),bindings:()=>G(`/api/bindings`),bindingCreate:e=>G(`/api/bindings`,{method:`POST`,body:e}),bindingUpdate:(e,t)=>G(`/api/bindings/${e}`,{method:`PATCH`,body:t}),bindingDelete:e=>G(`/api/bindings/${e}`,{method:`DELETE`,parse:!1}),bindingApprove:e=>G(`/api/bindings/${e}/approve`,{method:`POST`}),chatSessions:()=>G(`/api/chat/sessions`),chatMessages:e=>G(`/api/chat/sessions/${encodeURIComponent(e)}/messages`),chatTurns:e=>G(`/api/chat/sessions/${encodeURIComponent(e)}/turns`),chatCancel:e=>G(`/api/chat/cancel`,{method:`POST`,body:{session_id:e}}),chatMessage:(e,t)=>G(`/api/chat/message`,{method:`POST`,body:{channel_id:e,source_id:De(),text:t,page:location.hash.slice(1)||`/`}}),chatPersona:(e,t)=>G(`/api/chat/persona`,{method:`POST`,body:{session_id:e,name:t}}),chatUpdate:()=>G(`/api/chat/update`),chatUpdateDefer:e=>G(`/api/chat/update/defer`,{method:`POST`,body:{snapshot:e}}),chatUpdateInstall:e=>G(`/api/chat/update/install`,{method:`POST`,body:{snapshot:e},timeoutMs:12e4}),chatDangerous:()=>G(`/api/chat/dangerous`),chatDangerousRequest:(e,t)=>G(`/api/chat/dangerous/${encodeURIComponent(e)}`,{method:`POST`,body:{spec:t}}),chatDangerousDecision:(e,t)=>G(`/api/chat/dangerous/${encodeURIComponent(e)}/decision`,{method:`POST`,body:{decision:t}}),chatStream:(e,{signal:t}={})=>Pe(`/api/chat/stream`,{method:`POST`,headers:{Accept:`text/event-stream`,"Content-Type":`application/json`,"X-Archie-CSRF":`1`},body:JSON.stringify(e),signal:t})};function Fe(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 Ie(e,t){let n=new EventSource(`/api/logs/stream`);return n.onopen=()=>t?.(`live`),n.onerror=()=>t?.(Oe(n.readyState)),n.onmessage=t=>{try{e(JSON.parse(t.data))}catch{}},()=>n.close()}function Le(e,t){return e?t.filter(t=>t.section&&e[t.section]===!1).map(e=>e.path):[]}var Re=[{id:`queued`,label:`Queued`,kind:`idle`},{id:`running`,label:`Working`,kind:`info`},{id:`waiting_human`,label:`Waiting for you`,kind:`warn`,needs_you:!0},{id:`pr_open`,label:`In review`,kind:`ok`},{id:`merged`,label:`Merged`,kind:`ok`},{id:`parked`,label:`Parked`,kind:`warn`,needs_you:!0},{id:`dead`,label:`Stopped (too many retries)`,kind:`danger`},{id:`rejected`,label:`Rejected`,kind:`danger`},{id:`closed_wont_do`,label:`Won't do`,kind:`idle`}],ze=[{id:`cancel`,label:`Cancel`,kind:`quiet`,confirm:`Cancel "{title}"? This closes the forge issue.`},{id:`stop`,label:`Stop`,kind:`primary`,confirm:`Stop "{title}"? Recoverable work will remain parked.`},{id:`approve`,label:`Approve`,kind:`primary`},{id:`reject`,label:`Reject`,kind:`quiet`,confirm:`Reject "{title}"? TLine truncated
`).map(e=>e.trim()).find(Boolean)||``,r=n.length>rt?`${n.slice(0,rt).trimEnd()}…`:n;return{text:r,full:t,truncated:r!==t}}function Z({text:e,kind:t=`idle`}){return q(`span`,{className:`pill pill-${t}`,children:e})}var at=`archie.setup-complete.dismissed.v1`;function ot(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?.(at),{kind:`incomplete`,remaining:n}):t?.getItem?.(`archie.setup-complete.dismissed.v1`)===`1`?{kind:`dismissed`,remaining:[]}:{kind:`complete`,remaining:[]}}function st(e=globalThis.localStorage){e?.setItem?.(at,`1`)}var ct=new Set([`waiting_human`,`parked`]);function lt(e=[]){let t=e.filter(e=>ct.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 ut({title:e,detail:t}){return q(`div`,{className:`empty`,children:[q(`div`,{className:`empty-title`,children:e}),t&&q(`div`,{children:t})]})}function dt(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 ft(){let e=new Date().getHours();return e<5?`Still up?`:e<12?`Good morning`:e<18?`Good afternoon`:`Good evening`}function pt(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 mt(){let[e,t]=H([]),[n,r]=H(`connecting`),[i,a]=H(`idle`),[o,s]=H(new Map),[c,l]=H(null),[u,d]=H(null),[f,p]=H(null),[m,h]=H(null),[g,_]=H(null),[,v]=H(!1),y=async()=>{_(null);try{let[e,t,n,r]=await Promise.all([K.summary(),K.setup().catch(()=>null),K.workflows().catch(()=>null),K.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))}};U(()=>(y(),Fe(e=>{t(t=>{let n=[e,...t];return n.splice(50),n})},e=>{r(e),a(e===`live`?`ok`:`warn`)})),[]);let b=()=>{st(),v(e=>!e)},x=u?.operator?`${ft()}, ${u.operator}`:ft(),C=null;if(g)C=q(`button`,{className:`btn btn-primary`,onClick:y,children:[q(J,{name:`refresh`,size:15}),` Retry`]});else if(m!==null){let e=lt(m),t=e.attention.count,n=e.running.count;C=q(S,{children:[t>0&&q(`a`,{className:`btn btn-attention`,href:e.attention.href,children:[q(J,{name:`tasks`,size:15}),` `,t,` need`,t===1?`s`:``,` you`]}),n>0&&q(`a`,{className:`btn`,href:e.running.href,children:[q(J,{name:`workflows`,size:15}),` `,n,` running`]}),q(`a`,{className:`btn`,href:`#/logs`,children:[q(J,{name:`logs`,size:15}),` Logs`]}),q(`button`,{className:`btn btn-primary`,onClick:y,children:[q(J,{name:`refresh`,size:15}),` Refresh`]})]})}let w=null;if(g)w=q(`div`,{className:`card`,children:q(ut,{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=q(S,{children:[q(X,{label:`Working now`,value:e.running||0,compare:`${e.queued||0} waiting to start`,series:i.map(e=>e.tokens||0)}),q(X,{label:`Needs you`,value:n,compare:n?`Parked or awaiting a reply`:`Nothing is blocked`,goodDirection:`down`}),q(X,{label:`Delivered`,value:t,compare:r?`${Math.round(t/r*100)}% of all tasks`:`No tasks yet`}),q(X,{label:`Tokens used`,value:$e(i.reduce((e,t)=>e+(t.tokens||0),0)),compare:`Across ${i.length||0} days`,trend:pt(i.map(e=>e.tokens||0)),goodDirection:`down`,series:i.map(e=>e.tokens||0)})]})}let T=null,E=ot(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=q(`div`,{className:`card setup`,children:[q(`div`,{className:`card-head`,children:[q(`div`,{children:[q(`h2`,{className:`card-title`,children:`Finish setting up`}),q(`p`,{className:`card-sub`,children:`Archie needs these before it can work on its own.`})]}),q(`span`,{className:`setup-pct`,children:[t,`%`]})]}),q(`div`,{className:`setup-bar`,children:q(`div`,{className:`setup-bar-fill`,style:{width:`${t}%`}})}),q(`ul`,{className:`setup-list`,children:u.steps.map((e,t)=>q(`li`,{className:`setup-step ${e.done?`done`:``}`,children:[q(`span`,{className:`setup-check`,children:e.done?q(J,{name:`check`,size:12}):``}),q(`div`,{children:[q(`div`,{className:`setup-step-title`,children:e.title}),e.detail&&q(`div`,{className:`setup-step-detail`,children:e.detail})]})]},t))})]})}else T=q(`div`,{className:`card setup setup-done`,children:q(`div`,{className:`card-head`,children:[q(`div`,{children:[q(`h2`,{className:`card-title`,children:`Setup complete`}),q(`p`,{className:`card-sub`,children:`Archie is configured and ready to work.`})]}),q(`div`,{className:`setup-complete-actions`,children:[q(`span`,{className:`setup-pct`,children:q(J,{name:`check`,size:16})}),q(`button`,{className:`icon-btn setup-dismiss`,type:`Line truncated
`),children:[q(`td`,{className:`strong`,children:e.label||e.id}),q(`td`,{className:`mono`,children:e.install_type||`—`}),q(`td`,{className:`mono`,children:e.running_version||`—`}),q(`td`,{className:`mono`,children:e.latest_available||`—`}),q(`td`,{children:q(Z,{text:er[e.status]||e.status,kind:tr[e.status]||`idle`})})]},e.id||e.label))})]})})})}function rr({title:e,sub:t,children:n}){return q(`div`,{className:`card cfg-section`,children:[q(`div`,{className:`card-head`,children:q(`div`,{children:[q(`h2`,{className:`card-title`,children:e}),q(`p`,{className:`card-sub`,children:t})]})}),n]})}function ir(e){return e?.error?e.error:e?.snapshot?.deferred?`Update deferred.`:`Archie is up to date.`}function ar({data:e,onDefer:t,onInstall:n}){let r=e?.available||[];return r.length?q(rr,{title:`Updates`,sub:`Whether a newer release is available, and what to do about it.`,children:[q(`p`,{className:`cfg-note`,children:r.map(e=>`${e.Label||e.label}: ${e.Available||e.available}`).join(` · `)}),q(`div`,{className:`cfg-actions`,children:[q(`button`,{className:`btn`,type:`button`,onClick:()=>t?.(e.snapshot),children:`Defer`}),e.can_install&&q(`button`,{className:`btn btn-primary`,type:`button`,onClick:()=>n?.(e.snapshot),children:`Install update`})]})]}):q(rr,{title:`Updates`,sub:`Whether a newer release is available, and what to do about it.`,children:q(`p`,{className:`cfg-note`,children:ir(e)})})}var or=e=>e.Number??e.number,sr=e=>e.Label??e.label??`checkpoint`;function cr({data:e,onRequest:t,onDecide:n}){let[r,i]=H(``),[a,o]=H(``);if(e?.error)return q(rr,{title:`Dangerous actions`,sub:`Actions that need explicit approval before they run.`,children:q(`p`,{className:`cfg-note`,children:e.error})});let s=e?.pending||[];return q(rr,{title:`Dangerous actions`,sub:`Actions that need explicit approval before they run. Requesting one only queues it.`,children:[q(`div`,{className:`cfg-request-row`,children:[q(`select`,{"aria-label":`Checkpoint`,value:r,onChange:e=>i(e.target.value),children:[q(`option`,{value:``,children:`Select checkpoint`}),(e?.checkpoints||[]).map(e=>q(`option`,{value:String(or(e)),children:[or(e),` — `,sr(e)]},or(e)))]}),q(`button`,{className:`btn`,type:`button`,disabled:!r,onClick:()=>t?.(`rollback`,r),children:`Request rollback`})]}),q(`div`,{className:`cfg-request-row`,children:[q(`input`,{placeholder:`Process name or id`,"aria-label":`Process name or id`,value:a,onInput:e=>o(e.target.value)}),q(`button`,{className:`btn`,type:`button`,disabled:!a.trim(),onClick:()=>t?.(`stop`,a),children:`Request stop`})]}),s.length?q(S,{children:s.map(e=>q(`div`,{className:`cfg-pending`,children:[q(`span`,{children:e.description}),q(`div`,{className:`cfg-actions`,children:[q(`button`,{className:`btn`,type:`button`,onClick:()=>n?.(e.id,`approve`),children:`Approve`}),q(`button`,{className:`btn`,type:`button`,onClick:()=>n?.(e.id,`permanent`),children:`Approve for 24h`}),q(`button`,{className:`btn`,type:`button`,onClick:()=>n?.(e.id,`deny`),children:`Deny`})]})]},e.id))}):q(`p`,{className:`cfg-note`,children:`No pending dangerous actions.`})]})}function Q({title:e,detail:t}){return q(`div`,{className:`empty`,children:[q(`div`,{className:`empty-title`,children:e}),t&&q(`div`,{children:t})]})}function $({title:e,sub:t,children:n}){return q(`div`,{className:`card cfg-section`,children:[q(`div`,{className:`card-head`,children:q(`div`,{children:[q(`h2`,{className:`card-title`,children:e}),q(`p`,{className:`card-sub`,children:t})]})}),n]})}function lr({origins:e}){return e?.length?q($,{title:`Configuration sources`,sub:`Applied from top to bottom; later entries take precedence over earlier ones.`,children:q(`div`,{className:`kv-list`,children:e.map((e,t)=>q(Xn,{label:`${e.layer} ${e.role}${e.feature?` (${e.feature})`:``}`,value:e.path},t))})}):q($,{title:`Configuration sources`,sub:`The files that supplied the running configuration.`,children:q(Q,{title:`Source provenance is unavailable.`})})}function ur(e){return e===`quiet`?`btn-quiet`:e===`danger`?`btn-danger`:``}function dr({data:e,error:t}){if(t)return q($,{title:`Work lifecycle`,sub:`The task statuses and operator actions archied ships.`,children:q(Q,{title:`Lifecycle unavailable`,detail:t})});let n=e?.statuses||[],r=e?.actions||[];return q($,{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:[q(`h3`,{className:`cfg-subhead`,children:`Statuses`}),n.length?q(`div`,{className:`kv-list`,children:n.map(e=>{let t=e.label??Ke(e.id),n=e.kind??qe(e.id);return q(`div`,{className:`kv`,children:[q(`span`,{className:`kv-label`,children:e.id}),q(`span`,{className:`kv-value`,children:q(Z,{text:t,kind:n})})]},e.id)})}):q(Q,{title:`No statuses reported`,detail:`The server did not return any lifecycle statuses.`}),q(`h3`,{className:`cfg-subhead`,children:`Actions`}),r.length?q(`div`,{className:`kv-list`,children:r.map(e=>{let t=e.label??e.id,n=ur(e.kind);return q(`div`, Line truncated
`),i=[],a=null,o=null,s=0,c=()=>{i.length&&(n.push(q(`p`,{children:Qr(i.join(` `))},s++)),i=[])},l=()=>{if(!a)return;let e=a.items.map((e,t)=>q(`li`,{children:Qr(e)},t));n.push(a.tag===`ol`?q(`ol`,{children:e},s++):q(`ul`,{children:e},s++)),a=null};for(let e=0;e<r.length;e++){let t=r[e];if(t.startsWith("```")){c(),l(),o?(n.push(q(`pre`,{children:q(`code`,{children:o.join(`
`)})},s++)),o=null):o=[];continue}if(o){o.push(t);continue}let u=ei(t),d=e+1<r.length?ei(r[e+1]):null;if(u&&d&&ti(d)&&u.length===d.length){c(),l();let t=[];for(e+=2;e<r.length;e++){let n=ei(r[e]);if(!n||n.length!==u.length){e--;break}t.push(n)}n.push(q(`table`,{children:[q(`thead`,{children:q(`tr`,{children:u.map((e,t)=>q(`th`,{children:Qr(e)},t))})}),q(`tbody`,{children:t.map((e,t)=>q(`tr`,{children:e.map((e,t)=>q(`td`,{children:Qr(e)},t))},t))})]},s++));continue}if(!t.trim()){c(),l();continue}let f=t.match(/^(#{1,3})\s+(.+)$/);if(f){c(),l();let e=`h${f[1].length}`;n.push(q(e,{children:Qr(f[2])},s++));continue}let p=t.match(/^\s*[-*]\s+(.+)$/),m=t.match(/^\s*\d+[.)]\s+(.+)$/);if(p||m){c();let e=m?`ol`:`ul`;(!a||a.tag!==e)&&(l(),a={tag:e,items:[]}),a.items.push((p||m)[1]);continue}if(t.startsWith(`>`)){c(),l(),n.push(q(`blockquote`,{children:Qr(t.replace(/^>\s?/,``))},s++));continue}i.push(t)}return c(),l(),o&&n.push(q(`pre`,{children:q(`code`,{children:o.join(`
`)})},s++)),q(`div`,{className:t,children:n})}function ei(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 ti(e){return e.every(e=>/^:?-{3,}:?$/.test(e))}var ni=`archie.web.chat.channel`;function ri(){let e=localStorage.getItem(ni);return e||(e=De(),localStorage.setItem(ni,e)),e}function ii(e){return{text:e,sourceID:De()}}function ai(e){return{...e}}function oi(e,t){let n=!!(e&&typeof e==`object`&&e.turn&&typeof e.turn.text==`string`),r=n?e.turn.text:t.trim();return{text:r,turn:n?ai(e.turn):ii(r),isRetry:n}}function si({scrollTop:e,viewportHeight:t,optionTop:n,optionHeight:r}){if(r>=t||n<e)return n;let i=n+r;return i>e+t?i-t:e}function ci(e){return e.title||e.branch_name||`Conversation ${e.session_id.slice(0,8)}`}function li(e,t){if(!t)return`Archie`;let n=(e||[]).find(e=>e.session_id===t);return n?ci(n):`Archie`}function ui(){return location.hash.slice(1)||`/`}function di({open:e=!0}){let[t,n]=H([]),[r,i]=H(``),[a,o]=H([]),[s,c]=H(``),[l,u]=H(`Ready`),[d,f]=H(!1),[p,m]=H({}),[h,g]=H(``),[_,v]=H(``),[y,b]=H(``),[x,C]=H([]),[w,T]=H([]),[E,D]=H(0),[O,k]=H(!1),[A,j]=H(null),M=W(null),N=W(null),P=W(null),F=W(null),I=W(null),L=W(null),ee=W(d);ee.current=d,U(()=>{let e=e=>{let t=L.current;t?.open&&(e.target instanceof Node&&t.contains(e.target)||(t.open=!1))};return document.addEventListener(`pointerdown`,e),document.addEventListener(`focusin`,e),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`focusin`,e)}},[]),U(()=>{e&&N.current?.focus()},[e]),U(()=>{if(!O)return;let e=I.current,t=e?.children?.[E];!e||!t||(e.scrollTop=si({scrollTop:e.scrollTop,viewportHeight:e.clientHeight,optionTop:t.offsetTop,optionHeight:t.offsetHeight}))},[E,O]),U(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},[a,A]),U(()=>{R().catch(e=>{u(e.message||`Chat unavailable`)});let e=()=>{P.current?.abort()};return window.addEventListener(`archie:teardown`,e),()=>{window.removeEventListener(`archie:teardown`,e),P.current?.abort()}},[]);async function R(){let e=await K.chatSessions(),t=e.sessions||[];n(t),m(e),g(e.active_persona||``);let i=e.providers||[],a=e.active_provider||i[0]||``;v(a),b(e.active_model||``);let o=(e.commands||[]).map(e=>typeof e==`string`?{command:e,usage:e,description:``}:e);C(o),!r&&t[0]&&await te(t[0].session_id,e,t)}async function te(e,t,n){let r=t||p;i(e),o([]),j(null);let a=r.active_personas?.[e]||r.active_persona||``;g(a);try{await K.chatMessage(ri(),`/resume ${e}`);let[t,n]=await Promise.all([K.chatMessages(e),K.chatTurns(e)]),r=new Map;for(let e of n||[]){let t=e.assistant_message_id||e.AssistantMessageID;t&&r.set(t,e)}let i=(t||[]).map(e=>{let t=e.message_id||e.MessageID,n=r.get(t);return n?{...e,tool_calls:n.tool_calls||n.ToolCalls||[]}:e});o(i)}catch(e){u(e.message||`Could not load session messages`)}}async function ne(e){if(r)try{u(`Working…`);let t=await K.chatMessage(ri(),e);t.session_id&&i(t.session_id),u(t.reply||`Session updated`),await R(),(t.session_id||r)&&await te(t.session_id||r),F.current&&(F.current.open=!1)}catch(e){u(e.message||`Session action failed`)}}function re(e,t){let n=window.prompt(t);n?.trim()&&ne(`${e} ${n.trim()}`)}function ie(e){let t=e.target.value;g(t),!(!r||!t)&&K.chatPersona(r,t).then(()=>{m(e=>({...e,active_personas:{...e.active_personas||{},[r]:t}})),u(`Personality: ${t}`)}).catch(e=>{u(e.message||`Failed to set personality`)})}async function ae(e){let t=e.target.value;if(v(t),t)try{let e=await K.chatMessage(ri(),`/model --provider ${t}`);u(e.reply||`Provider updated`),await R()}catch(e){u(`Provider update failed: ${e.message||e}`)}}async function z(e){let t=e.target.value;if(b(t),t)try{let e=await K.chatMessage(ri(),`/model ${t}`);u(e.reply||`Model updated`),await R()}catch(e){u(`Model update failed: ${e.message||e}`)}}function B(){c(`/new`),le({textOverride:`/new`})}function oe(e){let t=e.target.value;c(t);let n=t.slice(0,e.target.selectionStart).match(/(?:^|\s)\/([^\s]*)$/);if(n){let e=n[1].toLowerCase(),t=x.filter(t=>`${t.command} ${t.description}`.toLowerCase().includes(e)).slice(0,8);if(t.length){T(t),D(0),k(!0);return}}k(!1),T([])}function se(e){let t=w[e];if(!t||!N.current)return;let n=N.current,r=n.value.slice(0,n.selectionStart),i=n.value.slice(n.selectionStart),a=r.search(/(?:^|\s)\/[^\s]*$/),o=a<0?r.length:a+ +(r[a]===` `),s=`${r.slice(0,o)}${t.command} ${i}`;c(s),k(!1);let l=o+t.command.length+1;setTimeout(()=>{n.focus(),n.setSelectionRange(l,l)},0)}function ce(e){if(O&&w.length){if(e.key===`Enter`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&w.some(e=>e.command===s.trim())){e.preventDefault(),k(!1),le();return}if(e.key===`ArrowDown`){e.preventDefault(),D(e=>(e+1)%w.length);return}if(e.key===`ArrowUp`){e.preventDefault(),D(e=>(e+w.length-1)%w.length);return}if(e.key===`Enter`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey){e.preventDefault(),se(E);return}if(e.key===`Escape`){e.preventDefault(),k(!1); Line truncated
`);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&&i(n.session_id),n.type===`delta`&&(d+=n.text,j(e=>e?{...e,text:d}:null)),n.type===`tool`&&(l=[...l,n],j(e=>e?{...e,tools:l}:null)),n.type===`navigate`&&(l=[...l,n],j(e=>e?{...e,tools:l}:null)),n.type===`done`&&(p=!0,d||=n.text),n.type===`error`)throw Error(n.text)}if(r)break}if(!p)throw Error(`chat stream ended before completion`);o(e=>[...e,{from:`assistant`,text:d,tool_calls:l}]),j(null),u(`Ready`),await R()}catch(e){if(e.name===`AbortError`&&!m)j({text:`Turn stopped.`,tools:l,isError:!1,turn:r,isRetry:a}),u(`Stopped`);else{let t=`Unable to complete that turn: ${e.message||e}`;j({text:t,tools:l,isError:!0,turn:ti(r),isRetry:a}),u(`Error — retry available`)}}finally{clearTimeout(h),P.current=null,f(!1),N.current&&N.current.focus()}}function H(){u(`Stopping…`),r&&q.chatCancel(r).catch(()=>{}),P.current?.abort()}let le=p.models_by_provider||{},ue=_&&le[_]?le[_]:p.models||[];return J(`div`,{className:`chat-panel-content`,children:[J(`div`,{className:`chat-drawer-head`,children:[J(`strong`,{className:`chat-panel-title`,children:ai(t,r)}),J(`div`,{className:`chat-head-actions`,children:J(`button`,{className:`icon-btn chat-new`,type:`button`,title:`New chat`,"aria-label":`New chat`,onClick:V,children:J(Y,{name:`message-circle-plus`})})})]}),J(`div`,{className:`chat-bar`,children:[J(`label`,{className:`chat-session-switch`,children:[J(`span`,{className:`sr-only`,children:`Conversation`}),J(`select`,{value:r,onChange:e=>te(e.target.value),disabled:!t.length,children:t.length?t.map(e=>J(`option`,{value:e.session_id,children:ii(e)},e.session_id)):J(`option`,{value:``,children:`No conversations yet`})})]}),J(`details`,{className:`chat-settings`,ref:L,children:[J(`summary`,{"aria-label":`Chat settings`,title:`Chat settings`,children:J(`span`,{"aria-hidden":`true`,children:`⚙`})}),J(`div`,{className:`chat-settings-body`,children:[J(`span`,{className:`chat-status`,children:l}),J(`label`,{children:[`Personality`,J(`select`,{className:`chat-select`,"aria-label":`Personality`,value:h,onChange:re,children:[J(`option`,{value:``,children:`Default`}),(p.personas||[]).map(e=>J(`option`,{value:e,children:e},e))]})]}),(p.providers||[]).length>0&&J(`label`,{children:[`Provider`,J(`select`,{className:`chat-select`,"aria-label":`Provider`,value:_,onChange:ie,children:[J(`option`,{value:``,children:`Default`}),(p.providers||[]).map(e=>J(`option`,{value:e,children:e},e))]})]}),J(`label`,{children:[`Model`,J(`select`,{className:`chat-select`,"aria-label":`Model`,value:y,onChange:B,children:[J(`option`,{value:``,children:`Default`}),ue.map(e=>J(`option`,{value:e,children:e},e))]})]})]})]})]}),J(`div`,{className:`chat-layout`,children:J(`section`,{className:`chat-workspace`,children:[J(`div`,{className:`chat-workspace-head`,children:J(`details`,{className:`chat-session-tools`,ref:F,hidden:!r,children:[J(`summary`,{children:`Session actions`}),J(`div`,{className:`chat-session-tool-list`,children:[J(`button`,{className:`btn`,type:`button`,onClick:()=>z(`/retry`),children:`Retry`}),J(`button`,{className:`btn`,type:`button`,onClick:()=>z(`/undo`),children:`Undo`}),J(`button`,{className:`btn`,type:`button`,onClick:()=>ne(`/title`,`Session title`),children:`Rename`}),J(`button`,{className:`btn`,type:`button`,onClick:()=>ne(`/branch`,`Branch name (optional)`),children:`Branch`}),J(`button`,{className:`btn`,type:`button`,onClick:()=>z(`/compress --preview`),children:`Preview compression`})]})]})}),J(`div`,{className:`chat-transcript`,ref:M,children:!a.length&&!A?J(`div`,{className:`chat-empty-state`,children:[J(`span`,{className:`chat-empty-mark`,children:`A`}),J(`h2`,{children:`What are we working on?`}),J(`p`,{children:`Ask Archie anything, or start with one of these prompts.`}),J(`div`,{className:`chat-prompt-grid`,children:[J(`button`,{className:`chat-prompt`,type:`button`,onClick:()=>{c(`Summarise active tasks`),N.current?.focus()},children:`Summarise active tasks`}),J(`button`,{className:`chat-prompt`,type:`button`,onClick:()=>{c(`Show running agents`),N.current?.focus()},children:`Show running agents`}),J(`button`,{className:`chat-prompt`,type:`button`,onClick:()=>{c(`Check system status`),N.current?.focus()},children:`Check system status`})]})]}):J(S,{children:[a.map((e,t)=>{let n=e.from??e.From??``,r=e.text??e.Text??``,i=n!==`web`,a=e.tool_calls||e.ToolCalls||[];return J(`div`,{className:`chat-bubble-row ${i?`assistant`:`user`}`,children:J(`div`,{className:`chat-bubble`,children:i?J(S,{children:[a.length>0&&J(`div`,{className:`chat-tools`,children:a.map((e,t)=>{if(e.path)return J(`a`,{className:`chat-nav-chip`,href:`#${e.path}`,title:`Go to ${e.label||e.path}`,children:[J(`span`,{className:`chat-nav-chip-icon`,"aria-hidden":`true`,children:`↗`}),J(`span`,{className:`chat-nav-chip-label`,children:e.label||e.path})]},t);let n=e.name||e.Name||e.tool||`tool`,r=e.parameters||e.Parameters||``,i=e.summary||e.Summary||e.text||e.err||e.Err||`Line truncated
`).find(e=>e.startsWith(`data: `));if(!t)continue;let n=JSON.parse(t.slice(6));if(n.session_id&&i(n.session_id),n.type===`delta`&&(d+=n.text,j(e=>e?{...e,text:d}:null)),n.type===`tool`&&(l=[...l,n],j(e=>e?{...e,tools:l}:null)),n.type===`navigate`&&(l=[...l,n],j(e=>e?{...e,tools:l}:null)),n.type===`done`&&(p=!0,d||=n.text),n.type===`error`)throw Error(n.text)}if(r)break}if(!p)throw Error(`chat stream ended before completion`);o(e=>[...e,{from:`assistant`,text:d,tool_calls:l}]),j(null),u(`Ready`),await R()}catch(e){if(e.name===`AbortError`&&!m)j({text:`Turn stopped.`,tools:l,isError:!1,turn:r,isRetry:a}),u(`Stopped`);else{let t=`Unable to complete that turn: ${e.message||e}`;j({text:t,tools:l,isError:!0,turn:ai(r),isRetry:a}),u(`Error — retry available`)}}finally{clearTimeout(h),P.current=null,f(!1),N.current&&N.current.focus()}}function V(){u(`Stopping…`),r&&K.chatCancel(r).catch(()=>{}),P.current?.abort()}let ue=p.models_by_provider||{},de=_&&ue[_]?ue[_]:p.models||[];return q(`div`,{className:`chat-panel-content`,children:[q(`div`,{className:`chat-drawer-head`,children:[q(`strong`,{className:`chat-panel-title`,children:li(t,r)}),q(`div`,{className:`chat-head-actions`,children:q(`button`,{className:`icon-btn chat-new`,type:`button`,title:`New chat`,"aria-label":`New chat`,onClick:B,children:q(J,{name:`message-circle-plus`})})})]}),q(`div`,{className:`chat-bar`,children:[q(`label`,{className:`chat-session-switch`,children:[q(`span`,{className:`sr-only`,children:`Conversation`}),q(`select`,{value:r,onChange:e=>te(e.target.value),disabled:!t.length,children:t.length?t.map(e=>q(`option`,{value:e.session_id,children:ci(e)},e.session_id)):q(`option`,{value:``,children:`No conversations yet`})})]}),q(`details`,{className:`chat-settings`,ref:L,children:[q(`summary`,{"aria-label":`Chat settings`,title:`Chat settings`,children:q(`span`,{"aria-hidden":`true`,children:`⚙`})}),q(`div`,{className:`chat-settings-body`,children:[q(`span`,{className:`chat-status`,children:l}),q(`label`,{children:[`Personality`,q(`select`,{className:`chat-select`,"aria-label":`Personality`,value:h,onChange:ie,children:[q(`option`,{value:``,children:`Default`}),(p.personas||[]).map(e=>q(`option`,{value:e,children:e},e))]})]}),(p.providers||[]).length>0&&q(`label`,{children:[`Provider`,q(`select`,{className:`chat-select`,"aria-label":`Provider`,value:_,onChange:ae,children:[q(`option`,{value:``,children:`Default`}),(p.providers||[]).map(e=>q(`option`,{value:e,children:e},e))]})]}),q(`label`,{children:[`Model`,q(`select`,{className:`chat-select`,"aria-label":`Model`,value:y,onChange:z,children:[q(`option`,{value:``,children:`Default`}),de.map(e=>q(`option`,{value:e,children:e},e))]})]})]})]})]}),q(`div`,{className:`chat-layout`,children:q(`section`,{className:`chat-workspace`,children:[q(`div`,{className:`chat-workspace-head`,children:q(`details`,{className:`chat-session-tools`,ref:F,hidden:!r,children:[q(`summary`,{children:`Session actions`}),q(`div`,{className:`chat-session-tool-list`,children:[q(`button`,{className:`btn`,type:`button`,onClick:()=>ne(`/retry`),children:`Retry`}),q(`button`,{className:`btn`,type:`button`,onClick:()=>ne(`/undo`),children:`Undo`}),q(`button`,{className:`btn`,type:`button`,onClick:()=>re(`/title`,`Session title`),children:`Rename`}),q(`button`,{className:`btn`,type:`button`,onClick:()=>re(`/branch`,`Branch name (optional)`),children:`Branch`}),q(`button`,{className:`btn`,type:`button`,onClick:()=>ne(`/compress --preview`),children:`Preview compression`})]})]})}),q(`div`,{className:`chat-transcript`,ref:M,children:!a.length&&!A?q(`div`,{className:`chat-empty-state`,children:[q(`span`,{className:`chat-empty-mark`,children:`A`}),q(`h2`,{children:`What are we working on?`}),q(`p`,{children:`Ask Archie anything, or start with one of these prompts.`}),q(`div`,{className:`chat-prompt-grid`,children:[q(`button`,{className:`chat-prompt`,type:`button`,onClick:()=>{c(`Summarise active tasks`),N.current?.focus()},children:`Summarise active tasks`}),q(`button`,{className:`chat-prompt`,type:`button`,onClick:()=>{c(`Show running agents`),N.current?.focus()},children:`Show running agents`}),q(`button`,{className:`chat-prompt`,type:`button`,onClick:()=>{c(`Check system status`),N.current?.focus()},children:`Check system status`})]})]}):q(S,{children:[a.map((e,t)=>{let n=e.from??e.From??``,r=e.text??e.Text??``,i=n!==`web`,a=e.tool_calls||e.ToolCalls||[];return q(`div`,{className:`chat-bubble-row ${i?`assistant`:`user`}`,children:q(`div`,{className:`chat-bubble`,children:i?q(S,{children:[a.length>0&&q(`div`,{className:`chat-tools`,children:a.map((e,t)=>{if(e.path)return q(`a`,{className:`chat-nav-chip`,href:`#${e.path}`,title:`Go to ${e.label||e.path}`,children:[q(`span`,{className:`chat-nav-chip-icon`,"aria-hidden":`true`,children:`↗`}),q(`span`,{className:`chat-nav-chip-label`,children:e.label||e.path})]},t);let n=e.name||e.Name||e.tool||`tool`,r=e.parameters||e.Parameters||``,i=e.summary||e.Summary||e.text||e.err||e.Err Line truncated
+4 -1
View File
@@ -5,6 +5,7 @@
// fetch() call appears here, and it fails if any method omits a header the
// server requires.
import { randomUUID } from "./uuid.jsx";
import { streamStateFor } from "./stream-state.js";
// DEFAULT_TIMEOUT_MS bounds a request so a daemon that accepts the connection
// but never answers cannot leave the UI in a loading state with no way back.
@@ -186,7 +187,9 @@ export function subscribeEvents(onEvent, onStateChange) {
export function subscribeLogs(onEntry, onStateChange) {
const src = new EventSource("/api/logs/stream");
src.onopen = () => onStateChange?.("live");
src.onerror = () => onStateChange?.("reconnecting");
// onerror fires both for a drop the browser will retry and for one it has
// given up on; readyState is what tells them apart.
src.onerror = () => onStateChange?.(streamStateFor(src.readyState));
src.onmessage = (event) => {
try { onEntry(JSON.parse(event.data)); } catch { /* malformed log frame */ }
};
+24
View File
@@ -0,0 +1,24 @@
// What an EventSource error actually means.
//
// In base/ rather than logs/ because this is EventSource semantics, not a
// logs concept, and base must not import a feature folder.
//
// EventSource fires onerror both for a dropped connection it will retry and
// for one it has given up on. Reporting "reconnecting" for both left the logs
// page showing a permanent amber "reconnecting" pill against a stream that had
// stopped for good, next to text claiming live logs were still arriving
// (archie-core-c5bz).
//
// readyState is the difference: CONNECTING means a retry is scheduled, CLOSED
// means the browser will not try again.
/**
* streamStateFor maps an EventSource readyState to the state the UI reports:
* "live", "reconnecting", or "unavailable".
*/
export function streamStateFor(readyState) {
// Numeric literals rather than EventSource.* so this is testable without one.
if (readyState === 0) return "reconnecting";
if (readyState === 1) return "live";
return "unavailable";
}
+6 -3
View File
@@ -52,10 +52,13 @@
--fg: #e8edf4;
--fg-muted: #8b97a8;
--fg-subtle: #5d6878;
--fg-subtle: #7d8b9e;
--accent: #4c8dff;
--accent-fg: #ffffff;
/* Near-black, not white: white on this blue is 3.2:1 and fails AA on the
active nav item and every primary button. The accent stays as-is because
it is also the link colour, where it reads correctly on the dark canvas. */
--accent-fg: #0d1014;
--accent-soft: rgba(76, 141, 255, 0.14);
/* Status. Used for task state, gate results and trend direction alike, so
@@ -101,7 +104,7 @@
--fg: #16202e;
--fg-muted: #5a6779;
--fg-subtle: #8c99ab;
--fg-subtle: #636f82;
--accent: #2563eb;
--accent-fg: #ffffff;
+8 -13
View File
@@ -197,19 +197,14 @@
min-width: 0;
}
/* The grid row stretches each column wrapper to the taller card's height by
default, but a block-level .card child doesn't fill that stretched height
on its own -- it shrinks to its own content, leaving the shorter card
(typically Gate pulse's empty state) sitting flush at the top with dead
space below it instead of matching its sibling. Flexing the wrapper and
growing the card to fill it makes both HEALTH cards the same height while
each card's own content still flows from the top. */
.dash-top > div {
display: flex;
}
.dash-top > div > .card {
flex: 1;
/* Each HEALTH card takes its own content height. Equalising them (the earlier
fix for this row) was right when both held a checklist, but once setup is
complete that card is a title and one line while Gate pulse carries a gauge
and four rows, so matching heights left a ~400px empty box taking a quarter
of the first screen. A ragged bottom edge is the lesser cost.
(archie-core-1786637500926-421-7c63bcd3) */
.dash-top {
align-items: start;
}
/* No setup panel to show: the gate pulse spans the whole row instead of
+29
View File
@@ -0,0 +1,29 @@
// What the logs list says when it has nothing to show.
//
// Three different situations produced one message, which is how the page ended
// up promising that "live daemon logs will appear here" while the stream that
// would deliver them had already given up (archie-core-c5bz).
/**
* logsEmptyTitle names the situation: a dead stream, a deployment with no
* durable history, or filters that match nothing.
*/
export function logsEmptyTitle(durableUnavailable, streamState) {
if (streamState === "unavailable") return "Log stream unavailable";
if (durableUnavailable) return "No logs yet";
return "Nothing matches";
}
/**
* logsEmptyDetail says what to expect next, and never promises live logs from
* a stream that has stopped.
*/
export function logsEmptyDetail(durableUnavailable, streamState) {
if (streamState === "unavailable") {
return "The daemon is not serving /api/logs/stream. Reload once it is reachable.";
}
if (durableUnavailable) {
return "This deployment keeps no durable history. Live daemon logs appear here while the page is open.";
}
return "Try a wider level or clear the search.";
}
+9 -5
View File
@@ -4,6 +4,7 @@ import "./logs.css";
import { api, subscribeLogs } from "../base/api.jsx";
import { LOG_LEVELS, LogRow } from "../base/log-row.jsx";
import { Pill } from "../base/pill.jsx";
import { logsEmptyTitle, logsEmptyDetail } from "./logs-empty.js";
function Empty({ title, detail }) {
return (
@@ -48,7 +49,7 @@ function LogsApp() {
});
setDurableUnavailable(!!res.disabled);
const newMeta = res.disabled ? "Durable history unavailable; live daemon logs continue." : res.truncated
const newMeta = res.disabled ? "Live only" : res.truncated
? `showing the most recent matches from ${res.file}`
: res.file || "";
setMeta(newMeta);
@@ -170,7 +171,10 @@ function LogsApp() {
</div>
<div className="log-status">
<span className="log-meta">{meta}</span>
<Pill text={streamState} kind={streamState === "live" ? "ok" : "warn"} />
<Pill
text={streamState}
kind={streamState === "live" ? "ok" : streamState === "unavailable" ? "danger" : "warn"}
/>
</div>
</div>
@@ -178,9 +182,9 @@ function LogsApp() {
{meta === "Cannot read logs" ? (
<Empty title="Cannot read logs" />
) : !entriesToRender.length ? (
<Empty
title={durableUnavailable ? "Durable history unavailable" : "Nothing matches"}
detail={durableUnavailable ? "Live daemon logs will appear here while this page is open." : "Try a wider level or clear the search."}
<Empty
title={logsEmptyTitle(durableUnavailable, streamState)}
detail={logsEmptyDetail(durableUnavailable, streamState)}
/>
) : (
entriesToRender.map(entry => <LogRow key={entryKey(entry)} entry={entry} />)
+17 -7
View File
@@ -399,13 +399,23 @@ function SettingsApp() {
</div>
<div>
{!versionMissing && (
versionError ? (
<div className="card"><Empty title="Update status unavailable" detail={versionError} /></div>
) : versionData ? (
<UpdateStatusCard components={versionData} />
) : null
)}
{/* A 501 is a deployment that did not wire update checking, which is a
legitimate state and a different thing from a broken one. Saying so
once here covers the absent UpdateActionsCard below too. */}
{versionMissing ? (
<div className="card cfg-section">
<div className="card-head">
<div>
<h2 className="card-title">Update status</h2>
<p className="card-sub">Not configured on this deployment, so there is nothing to check against.</p>
</div>
</div>
</div>
) : versionError ? (
<div className="card"><Empty title="Update status unavailable" detail={versionError} /></div>
) : versionData ? (
<UpdateStatusCard components={versionData} />
) : null}
</div>
{updateData && (
+36
View File
@@ -0,0 +1,36 @@
// Merging workflow definitions with their run statistics.
//
// The rows used to come from the definition list alone, so a workflow that had
// run but was no longer in that list (or a definitions fetch that came back
// empty while the stats fetch succeeded) produced no rows at all. The page then
// showed "No workflow runs yet" directly above the stage tables listing those
// very runs (archie-core-rcbf).
//
// A run is evidence the workflow exists. Anything with either a definition or
// statistics gets a row.
/**
* workflowRows returns one row per known workflow, definitions first and in
* their declared order, then any workflow seen only in the statistics.
*/
export function workflowRows(workflows, definitions) {
const stats = new Map((workflows || []).map((w) => [w.workflow, w]));
const rows = [];
const claimed = new Set();
for (const definition of definitions || []) {
claimed.add(definition.id);
rows.push({
...definition,
...(stats.get(definition.id) || { workflow: definition.id, runs: 0, merged: 0 }),
});
}
for (const workflow of workflows || []) {
if (claimed.has(workflow.workflow)) continue;
// No definition to describe it, so the id is the only name it has.
rows.push({ id: workflow.workflow, name: workflow.workflow, ...workflow });
}
return rows;
}
+2 -5
View File
@@ -2,6 +2,7 @@ import { h, Fragment } from "preact";
import { useState, useEffect } from "preact/hooks";
import "./workflows.css";
import { api } from "../base/api.jsx";
import { workflowRows } from "./workflow-rows.js";
const WORKFLOW_LABELS = {
bootstrap: "Bootstrap",
@@ -162,11 +163,7 @@ function StartWork({ definitions }) {
}
function Workflows({ workflows, definitions }) {
const byID = new Map(workflows.map((workflow) => [workflow.workflow, workflow]));
const rows = definitions.map((definition) => ({
...definition,
...(byID.get(definition.id) || { workflow: definition.id, runs: 0, merged: 0 }),
}));
const rows = workflowRows(workflows, definitions);
if (!rows.length) {
return (
+30
View File
@@ -0,0 +1,30 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { logsEmptyTitle, logsEmptyDetail } from "../src/logs/logs-empty.js";
test("filters that match nothing say so", () => {
assert.equal(logsEmptyTitle(false, "live"), "Nothing matches");
assert.match(logsEmptyDetail(false, "live"), /wider level/);
});
test("a deployment without durable history explains live-only", () => {
assert.equal(logsEmptyTitle(true, "live"), "No logs yet");
assert.match(logsEmptyDetail(true, "live"), /no durable history/i);
});
// The bug: a dead stream still promised that live logs were on their way.
test("a dead stream does not promise live logs", () => {
assert.equal(logsEmptyTitle(true, "unavailable"), "Log stream unavailable");
const detail = logsEmptyDetail(true, "unavailable");
assert.ok(!/appear here while the page is open/.test(detail), `still promising live logs: ${detail}`);
assert.match(detail, /not serving/);
});
test("a dead stream outranks the durable-history message either way", () => {
assert.equal(logsEmptyTitle(false, "unavailable"), "Log stream unavailable");
assert.equal(logsEmptyTitle(true, "unavailable"), "Log stream unavailable");
});
test("a reconnecting stream still reads as a filter miss, not a failure", () => {
assert.equal(logsEmptyTitle(false, "reconnecting"), "Nothing matches");
});
+22
View File
@@ -0,0 +1,22 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { streamStateFor } from "../src/base/stream-state.js";
test("a retrying connection reports reconnecting", () => {
assert.equal(streamStateFor(0), "reconnecting");
});
test("an open connection reports live", () => {
assert.equal(streamStateFor(1), "live");
});
// The bug: a 503 closes the stream for good, and the page claimed it was
// reconnecting forever.
test("a closed connection reports unavailable, not reconnecting", () => {
assert.equal(streamStateFor(2), "unavailable");
});
test("an unexpected readyState is treated as unavailable rather than live", () => {
assert.equal(streamStateFor(undefined), "unavailable");
assert.equal(streamStateFor(99), "unavailable");
});
+44
View File
@@ -0,0 +1,44 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { workflowRows } from "../src/workflows/workflow-rows.js";
test("a defined workflow with no runs still gets a row at zero", () => {
const rows = workflowRows([], [{ id: "tdd", name: "TDD", enabled: true }]);
assert.equal(rows.length, 1);
assert.equal(rows[0].id, "tdd");
assert.equal(rows[0].runs, 0);
});
test("statistics are merged onto their definition", () => {
const rows = workflowRows(
[{ workflow: "tdd", runs: 3, merged: 1 }],
[{ id: "tdd", name: "TDD", enabled: true }],
);
assert.equal(rows.length, 1);
assert.equal(rows[0].name, "TDD");
assert.equal(rows[0].runs, 3);
assert.equal(rows[0].merged, 1);
});
// The regression: stats arrived, definitions did not, and the page claimed
// there were no runs while the stage tables below listed them.
test("a workflow with runs but no definition still gets a row", () => {
const rows = workflowRows([{ workflow: "implement", runs: 6, merged: 3 }], []);
assert.equal(rows.length, 1);
assert.equal(rows[0].id, "implement");
assert.equal(rows[0].runs, 6);
});
test("definitions keep their order and stats-only workflows follow", () => {
const rows = workflowRows(
[{ workflow: "ghost", runs: 2 }, { workflow: "tdd", runs: 1 }],
[{ id: "tdd" }, { id: "implement" }],
);
assert.deepEqual(rows.map((r) => r.id), ["tdd", "implement", "ghost"]);
});
test("only genuinely empty input produces no rows", () => {
assert.deepEqual(workflowRows([], []), []);
assert.deepEqual(workflowRows(undefined, undefined), []);
assert.deepEqual(workflowRows(null, null), []);
});