A per-task page at #/tasks/{id} with tabs for the attempt's stages and log, changed
files, configuration and a raw debug view. Reachable from the task list, deep
linkable via ?tab= and ?attempt=, and reload safe. Existing URLs (#/tasks?task=N
and #/tasks?status=...) are unchanged.
- A stage rail per attempt: name, duration, terminal status and error text, with
unattributed events surfaced and the agent's own verdict shown separately.
- No pass/fail badge and no exit code anywhere: the backend has neither, and a stage
that returned nil after producing a poor diff is a success. Status word, duration
and error text are shown instead.
- The log pane filters by attempt, stage and level, states the coverage caveat for
stage filters (agent and tool output records no stage), and keeps the three read
outcomes distinct: no log reader in this deployment, no file for this attempt, and
no entries matching the filter.
- Retry is labelled as a new run and its confirm says the previous attempt's commits
are discarded, because it hard-resets the branch onto the base.
- An absent capture reads "not captured for this run" rather than implying nothing
changed, and no elapsed-run figure is shown since only per-stage durations exist.
- The events cache is invalidated on retry (it previously kept the ended attempt's
events) and the log cache is keyed by attempt, so two attempts cannot be conflated.
- ui/dist is rebuilt and committed: the gate runs the node tests but never rebuilds
the bundle, so a stale one would otherwise ship behind a green gate.
- docs/prds/task-run-detail.md records the surface and its limits, and
docs/architecture/observability.md describes it alongside the read endpoints.
Both new vocabularies are pinned by tests on each side (config schema, change
statuses) so a one-sided rename fails a test instead of silently degrading the page.
16 lines
144 KiB
JavaScript
16 lines
144 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)}})();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,te(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)),z(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=this.l[n.type+e];if(n[c]==null)n[c]=d++;else if(n[c]<r[l])return;return r(t.event?t.event(n):n)}}}function I(e,n,r,i,a,o,s,c,l,u){var d,f,p,m,g,b,x,T,E,D,O,A,j,M,N,P,F=n.type;if(n.constructor!==void 0)return null;128&r.__u&&(l=!!(32&r.__u),o=[c=n.__e=r.__e]),(d=t.__b)&&d(n);n:if(typeof F==`function`){f=s.length;try{if(E=n.props,D=F.prototype&&F.prototype.render,O=(d=F.contextType)&&i[d.__c],A=d?O?O.props.value:d.__:i,r.__c?T=(p=n.__c=r.__c).__=p.__E:(D?n.__c=p=new F(E,A):(n.__c=p=new C(E,A),p.constructor=F,p.render=B),O&&O.sub(p),p.state||(p.state={}),p.__n=i,m=p.__d=!0,p.__h=[],p._sb=[]),D&&p.__s==null&&(p.__s=p.state),D&&F.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=v({},p.__s)),v(p.__s,F.getDerivedStateFromProps(E,p.__s))),g=p.props,b=p.state,p.__v=n,m)D&&F.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),D&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(D&&F.getDerivedStateFromProps==null&&E!==g&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(E,A),n.__v==r.__v||!p.__e&&p.shouldComponentUpdate!=null&&!1===p.shouldComponentUpdate(E,p.__s,A)){n.__v!=r.__v&&(p.props=E,p.state=p.__s,p.__d=!1),n.__e=r.__e,n.__k=r.__k,n.__k.some(function(e){e&&(e.__=n)}),h.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&s.push(p),c=w(r);break n}p.componentWillUpdate!=null&&p.componentWillUpdate(E,p.__s,A),D&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(g,b,x)})}if(p.context=A,p.props=E,p.__P=e,p.__e=!1,j=t.__r,M=0,D)p.state=p.__s,p.__d=!1,j&&j(n),d=p.render(p.props,p.state,p.context),h.push.apply(p.__h,p._sb),p._sb=[];else do p.__d=!1,j&&j(n),d=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++M<25);p.state=p.__s,p.getChildContext!=null&&(i=v(v({},i),p.getChildContext())),D&&!m&&p.getSnapshotBeforeUpdate!=null&&(x=p.getSnapshotBeforeUpdate(g,b)),N=d!=null&&d.type===S&&d.key==null?L(d.props.children):d,c=k(e,_(N)?N:[N],n,r,i,a,o,s,c,l,u),p.base=n.__e,n.__u&=-161,p.__h.length&&s.push(p),T&&(p.__E=p.__=null)}catch(e){if(s.length=f,n.__v=null,l||o!=null){if(e.then){for(n.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;o!=null&&(o[o.indexOf(c)]=null),n.__e=c}else if(o!=null)for(P=o.length;P--;)y(o[P])}else n.__e=r.__e;n.__k??=r.__k||[],e.then||ee(n),t.__e(e,n,r)}}else o==null&&n.__v==r.__v?(n.__k=r.__k,n.__e=r.__e):c=n.__e=R(r.__e,n,r,i,a,o,s,l,u);return(d=t.diffed)&&d(n),128&n.__u?void 0:c}function ee(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(ee))}function te(e,n,r){for(var i=0;i<r.length;i++)ne(r[i],r[++i],r[++i]);t.__c&&t.__c(n,e),e.some(function(n){try{e=n.__h,n.__h=[],e.some(function(e){e.call(n)})}catch(e){t.__e(e,n.__v)}})}function L(e){return typeof e!=`object`||!e||e.__b>0?e:_(e)?e.map(L):e.constructor===void 0?v({},e):null}function R(n,r,i,a,o,s,c,l,u){var d,f,p,h,g,v,b,x=i.props||m,S=r.props,C=r.type;if(C==`svg`?o=`http://www.w3.org/2000/svg`:C==`math`?o=`http://www.w3.org/1998/Math/MathML`:o||=`http://www.w3.org/1999/xhtml`,s!=null){for(d=0;d<s.length;d++)if((g=s[d])&&`setAttribute`in g==!!C&&(C?g.localName==C:g.nodeType==3)){n=g,s[d]=null;break}}if(n==null){if(C==null)return document.createTextNode(S);n=document.createElementNS(o,C,S.is&&S),l&&=(t.__m&&t.__m(r,s),!1),s=null}if(C==null)x===S||l&&n.data==S||(n.data=S);else{if(s=C==`textarea`&&S.defaultValue!=null?null:s&&e.call(n.childNodes),!l&&s!=null)for(x={},d=0;d<n.attributes.length;d++)x[(g=n.attributes[d]).name]=g.value;for(d in x)g=x[d],d==`dangerouslySetInnerHTML`?p=g:d==`children`||d in S||d==`value`&&`defaultValue`in S||d==`checked`&&`defaultChecked`in S||P(n,d,null,g,o);for(d in S)g=S[d],d==`children`?h=g:d==`dangerouslySetInnerHTML`?f=g:d==`value`?v=g:d==`checked`?b=g:l&&typeof g!=`function`||x[d]===g||P(n,d,g,x[d],o);if(f)l||p&&(f.__html==p.__html||f.__html==n.innerHTML)||(n.innerHTML=f.__html),r.__k=[];else if(p&&(n.innerHTML=``),k(r.type==`template`?n.content:n,_(h)?h:[h],r,i,a,C==`foreignObject`?`http://www.w3.org/1999/xhtml`:o,s,c,s?s[0]:i.__k&&w(i,0),l,u),s!=null)for(d=s.length;d--;)y(s[d]);l&&C!=`textarea`||(d=`value`,C==`progress`&&v==null?n.removeAttribute(`value`):v!=null&&(v!==n[d]||C==`progress`&&!v||C==`option`&&v!=x[d])&&P(n,d,v,x[d],o),d=`checked`,b!=null&&b!=n[d]&&P(n,d,b,x[d],o))}return n}function ne(e,n,r){try{if(typeof e==`function`){var i=typeof e.__u==`function`;i&&e.__u(),i&&n==null||(e.__u=e(n))}else e.current=n}catch(e){t.__e(e,r)}}function z(e,n,r){var i,a;if(t.unmount&&t.unmount(e),(i=e.ref)&&(i.current&&i.current!=e.__e||ne(i,null,n)),(i=e.__c)!=null){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(e){t.__e(e,n)}i.base=i.__P=i.__n=null}if(i=e.__k)for(a=0;a<i.length;a++)i[a]&&z(i[a],n,r||typeof e.type!=`function`);r||y(e.__e),e.__c=e.__=e.__e=void 0}function B(e,t,n){return this.constructor(e,n)}function re(n,r,i){var a,o,s,c;r==document&&(r=document.documentElement),t.__&&t.__(n,r),o=(a=typeof i==`function`)?null:i&&i.__k||r.__k,s=[],c=[],I(r,n=(!a&&i||r).__k=b(S,null,[n]),o||m,m,r.namespaceURI,!a&&i?[i]:o?null:r.firstChild?e.call(r.childNodes):null,s,!a&&i?i:o?o.__e:r.firstChild,a,c),te(s,n,c),n.props.children=null}e=h.slice,t={__e:function(e,t,n,r){for(var i,a,o;t=t.__;)if((i=t.__c)&&!i.__)try{if((a=i.constructor)&&a.getDerivedStateFromError!=null&&(i.setState(a.getDerivedStateFromError(e)),o=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,r||{}),o=i.__d),o)return i.__E=i}catch(t){e=t}throw e}},n=0,C.prototype.setState=function(e,t){var n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=v({},this.state);typeof e==`function`&&(e=e(v({},n),this.props)),e&&v(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),D(this))},C.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),D(this))},C.prototype.render=S,r=[],a=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,o=function(e,t){return e.__v.__b-t.__v.__b},O.__r=0,s=Math.random().toString(8),c=`__d`+s,l=`__a`+s,u=/(PointerCapture)$|Capture$/i,d=0,f=F(!1),p=F(!0);function ie(e=globalThis.crypto){if(typeof e?.randomUUID==`function`)return e.randomUUID();let t=new Uint8Array(16);if(typeof e?.getRandomValues==`function`)e.getRandomValues(t);else for(let e=0;e<t.length;e+=1)t[e]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;let n=Array.from(t,e=>e.toString(16).padStart(2,`0`));return`${n.slice(0,4).join(``)}-${n.slice(4,6).join(``)}-${n.slice(6,8).join(``)}-${n.slice(8,10).join(``)}-${n.slice(10).join(``)}`}var ae=15e3;function V(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 oe(e){try{let t=(await e.text()).trim();if(t)return t.split(`
|
||
`)[0].slice(0,200)}catch{}return`${e.status} ${e.statusText}`}var se=class extends Error{constructor(e,t){super(e),this.status=t}};function ce(e){let t=e instanceof se?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 le(e,t){let n=await fetch(e,t);if(!n.ok)throw new se(await oe(n),n.status);return n}async function H(e,{method:t=`GET`,body:n,timeoutMs:r=ae,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 le(e,o);return i?s.json():void 0}var U={summary:()=>H(`/api/summary`),tasks:()=>H(`/api/tasks`),taskMeta:()=>H(`/api/task-meta`),task:e=>H(`/api/tasks/${e}`),taskAttempts:e=>H(`/api/tasks/${e}/attempts`),taskChanges:(e,t)=>H(`/api/tasks/${e}/changes`+V(t)),taskDebug:(e,t)=>H(`/api/tasks/${e}/debug`+V(t)),taskAction:(e,t)=>H(`/api/tasks/${e}/action`,{method:`POST`,body:{action:t}}),setup:()=>H(`/api/setup`),capabilities:()=>H(`/api/capabilities`),workflows:()=>H(`/api/workflows`),workRequest:e=>H(`/api/work-requests`,{method:`POST`,body:e}),skills:()=>H(`/api/skills`),channels:()=>H(`/api/channels`),curators:()=>H(`/api/curators`),channelReload:e=>H(`/api/channels/${encodeURIComponent(e)}/reload`,{method:`POST`,body:{}}),config:()=>H(`/api/config`),version:()=>H(`/api/version`),configUpdate:e=>H(`/api/config`,{method:`PATCH`,body:{updates:e}}),configRepoUpdate:(e,t,n,r)=>H(`/api/config/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`PATCH`,body:{field:n,value:r}}),configReset:e=>H(`/api/config/reset`,{method:`POST`,body:{key:e}}),logs:e=>H(`/api/logs`+V(e)),taskLogs:(e,t)=>H(`/api/tasks/${e}/logs`+V(t)),taskLogDownloadURL:(e,t)=>`/api/tasks/${e}/logs/download`+(t==null?``:`?attempt=${t}`),captures:e=>H(`/api/captures`+V({limit:e})),mappings:()=>H(`/api/mappings`),mappingCreate:e=>H(`/api/mappings`,{method:`POST`,body:e}),mappingUpdate:(e,t)=>H(`/api/mappings/${e}`,{method:`PATCH`,body:t}),mappingDelete:e=>H(`/api/mappings/${e}`,{method:`DELETE`,parse:!1}),mappingPreview:(e,t)=>H(`/api/mappings/preview`,{method:`POST`,body:{capture_id:e,fields:t}}),bindings:()=>H(`/api/bindings`),bindingCreate:e=>H(`/api/bindings`,{method:`POST`,body:e}),bindingUpdate:(e,t)=>H(`/api/bindings/${e}`,{method:`PATCH`,body:t}),bindingDelete:e=>H(`/api/bindings/${e}`,{method:`DELETE`,parse:!1}),bindingApprove:e=>H(`/api/bindings/${e}/approve`,{method:`POST`}),memory:()=>H(`/api/memory`),chatSessions:()=>H(`/api/chat/sessions`),chatMessages:e=>H(`/api/chat/sessions/${encodeURIComponent(e)}/messages`),chatTurns:e=>H(`/api/chat/sessions/${encodeURIComponent(e)}/turns`),chatCancel:e=>H(`/api/chat/cancel`,{method:`POST`,body:{session_id:e}}),chatMessage:(e,t)=>H(`/api/chat/message`,{method:`POST`,body:{channel_id:e,source_id:ie(),text:t,page:location.hash.slice(1)||`/`}}),chatPersona:(e,t)=>H(`/api/chat/persona`,{method:`POST`,body:{session_id:e,name:t}}),chatUpdate:()=>H(`/api/chat/update`),chatUpdateDefer:e=>H(`/api/chat/update/defer`,{method:`POST`,body:{snapshot:e}}),chatUpdateInstall:e=>H(`/api/chat/update/install`,{method:`POST`,body:{snapshot:e},timeoutMs:12e4}),chatDangerous:()=>H(`/api/chat/dangerous`),chatDangerousRequest:(e,t)=>H(`/api/chat/dangerous/${encodeURIComponent(e)}`,{method:`POST`,body:{spec:t}}),chatDangerousDecision:(e,t)=>H(`/api/chat/dangerous/${encodeURIComponent(e)}/decision`,{method:`POST`,body:{decision:t}}),chatStream:(e,{signal:t}={})=>le(`/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 ue(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 de(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 pe=[{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`}],me=[{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}"? This closes the forge issue.`},{id:`retry`,label:`Retry`,kind:`primary`},{id:`abandon`,label:`Abandon`,kind:`quiet`,confirm:`Abandon "{title}"? This closes the forge issue.`},{id:`archive`,label:`Archive`,kind:`quiet`,confirm:`Archive the local record for "{title}"?`},{id:`open_pr`,label:`Open PR`,kind:`link`},{id:`open_issue`,label:`Open issue`,kind:`link`}],he=[...pe],ge=[...me],_e=new Map(he.map(e=>[e.id,e])),ve=new Map(ge.map(e=>[e.id,e]));function ye(e){return _e.get(e)?.label||e||`Unknown`}function be(e){return _e.get(e)?.kind||`idle`}function xe(){return he.map(e=>e.id)}function Se(){return new Set(he.filter(e=>e.needs_you).map(e=>e.id))}function Ce(e){return ve.get(e)||null}function W(e,t,...n){let[r,...i]=e.split(`.`),a=document.createElement(r||`div`);i.length&&(a.className=i.join(` `)),t!==void 0&&(typeof t!=`object`||t instanceof Node)&&(n.unshift(t),t=null);for(let[e,n]of Object.entries(t||{}))n!=null&&n!==!1&&(e.startsWith(`on`)&&typeof n==`function`?a.addEventListener(e.slice(2).toLowerCase(),n):e===`class`?a.className=[a.className,n].filter(Boolean).join(` `):e===`html`?a.innerHTML=n:a.setAttribute(e,n===!0?``:String(n)));return we(a,n),a}function we(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 Te(e,...t){return e.replaceChildren(),we(e,t),e}function Ee(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 De(e){return e==null||Number.isNaN(e)?`—`:new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1}).format(e)}var Oe={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"/>`,curators:`<circle cx="12" cy="12" r="8"/><path d="M12 8v4l3 2"/>`,captures:`<path d="M12 3v11M12 14l-4-4M12 14l4-4"/><path d="M4 14v4a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-4"/>`,mappings:`<circle cx="5" cy="7" r="2"/><circle cx="5" cy="17" r="2"/><circle cx="19" cy="12" r="2"/><path d="M7 7l10 5M7 17l10-5"/>`,bindings:`<rect x="3" y="9" width="8" height="6" rx="2.5"/><rect x="13" y="9" width="8" height="6" rx="2.5"/><path d="M9 12h6"/>`,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"/>`,close:`<path d="M6 6l12 12M18 6L6 18"/>`,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 G(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=Oe[e]||Oe.dashboard,r}var ke,K,Ae,je,Me=0,Ne=[],q=t,Pe=q.__b,Fe=q.__r,Ie=q.diffed,Le=q.__c,Re=q.unmount,ze=q.__;function Be(e,t){q.__h&&q.__h(K,e,Me||t),Me=0;var n=K.__H||(K.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function J(e){return Me=1,Ve(Ye,e)}function Ve(e,t,n){var r=Be(ke++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Ye(void 0,t),function(e){var t=r.__N?r.__N[0]:r.__[0],n=r.t(t,e);t!==n&&(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=K,!K.__f)){var i=function(e,t,n){if(!r.__c.__H)return!0;var i=!1,o=r.__c.props!==e;if(r.__c.__H.__.some(function(e){if(e.__N){i=!0;var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(o=!0)}}),a){var s=a.call(this,e,t,n);return i?s||o:s}return!i||o};K.__f=!0;var a=K.shouldComponentUpdate,o=K.componentWillUpdate;K.componentWillUpdate=function(e,t,n){if(this.__e){var r=a;a=void 0,i(e,t,n),a=r}o&&o.call(this,e,t,n)},K.shouldComponentUpdate=i}return r.__N||r.__}function Y(e,t){var n=Be(ke++,3);!q.__s&&Je(n.__H,t)&&(n.__=e,n.u=t,K.__H.__h.push(n))}function X(e){return Me=5,He(function(){return{current:e}},[])}function He(e,t){var n=Be(ke++,7);return Je(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function Ue(){for(var e;e=Ne.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Ke),t.__h.some(qe),t.__h=[]}catch(n){t.__h=[],q.__e(n,e.__v)}}}q.__b=function(e){K=null,Pe&&Pe(e)},q.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ze&&ze(e,t)},q.__r=function(e){Fe&&Fe(e),ke=0;var t=(K=e.__c).__H;t&&(Ae===K?(t.__h=[],K.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(Ke),t.__h.some(qe),t.__h=[],ke=0)),Ae=K},q.diffed=function(e){Ie&&Ie(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Ne.push(t)!==1&&je===q.requestAnimationFrame||((je=q.requestAnimationFrame)||Ge)(Ue)),t.__H.__.some(function(e){e.u&&=(e.__H=e.u,void 0)})),Ae=K=null},q.__c=function(e,t){t.some(function(e){try{e.__h.some(Ke),e.__h=e.__h.filter(function(e){return!e.__||qe(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],q.__e(n,e.__v)}}),Le&&Le(e,t)},q.unmount=function(e){Re&&Re(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{Ke(e)}catch(e){t=e}}),n.__H=void 0,t&&q.__e(t,n.__v))};var We=typeof requestAnimationFrame==`function`;function Ge(e){var t,n=function(){clearTimeout(r),We&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);We&&(t=requestAnimationFrame(n))}function Ke(e){var t=K,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),K=t}function qe(e){var t=K;e.__c=e.__(),K=t}function Je(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function Ye(e,t){return typeof t==`function`?t(e):t}function Xe({label:e,value:t,unit:n,trend:r,compare:i,series:a=[],goodDirection:o=`up`}){let s=r==null?null:r>=0?`up`:`down`,c=s==null?null:s===o;return W(`div.card.stat`,W(`div.stat-head`,W(`span.stat-label`,e),s&&W(`span.stat-trend.${c?`up`:`down`}`,G(s===`up`?`trendUp`:`trendDown`,{size:13}),`${Math.abs(r).toFixed(1)}%`)),W(`div.stat-value`,t,n&&W(`span.stat-unit`,n)),i&&W(`div.stat-compare`,i),a.length>1&&Ze(a,c===!1?`var(--danger)`:`var(--ok)`))}function Ze(e,t=`var(--ok)`,{width:n=220,height:r=34}={}){let i=Math.max(...e,1),a=Math.min(...e,0),o=i-a||1,s=e.length>1?n/(e.length-1):n,c=e.map((e,t)=>`${(t*s).toFixed(1)},${(r-(e-a)/o*r).toFixed(1)}`).join(` `),l=W(`svg.spark`,{viewBox:`0 0 ${n} ${r}`,preserveAspectRatio:`none`,"aria-hidden":`true`});return l.innerHTML=`<polyline points="${c}" fill="none" stroke="${t}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" vector-effect="non-scaling-stroke"/>`,l}function Qe({value:e,label:t,size:n=168}){let r=Math.max(0,Math.min(100,Number(e)||0)),i=r>=90?`var(--ok)`:r>=70?`var(--warn)`:`var(--danger)`,a=n/2,o=n/2,s=2*Math.PI*62*(240/360),c=(e,t)=>{let n=e*Math.PI/180,r=(e+t)*Math.PI/180,i=+(t>180);return[`M ${a+62*Math.cos(n)} ${o+62*Math.sin(n)}`,`A 62 62 0 ${i} 1 ${a+62*Math.cos(r)} ${o+62*Math.sin(r)}`].join(` `)},l=W(`svg.gauge`,{viewBox:`0 0 ${n} ${n*.78}`,role:`img`,"aria-label":`${t}: ${r}%`});return l.innerHTML=`
|
||
<path d="${c(150,240)}" fill="none" stroke="var(--border)"
|
||
stroke-width="12" stroke-linecap="round"/>
|
||
<path d="${c(150,240)}" fill="none" stroke="${i}"
|
||
stroke-width="12" stroke-linecap="round"
|
||
stroke-dasharray="${s}"
|
||
stroke-dashoffset="${s*(1-r/100)}"
|
||
class="gauge-value"/>`,W(`div.gauge-wrap`,l,W(`div.gauge-center`,W(`div.gauge-pct`,`${Math.round(r)}%`),W(`div.gauge-label`,t)))}function $e(e){let t=e.reduce((e,t)=>e+(t.value||0),0)||1;return W(`div`,W(`div.segbar`,...e.filter(e=>e.value>0).map(e=>W(`span`,{class:`segbar-part segbar-${e.kind||`idle`}`,style:`width:${(e.value/t*100).toFixed(1)}%`,title:`${e.label}: ${e.value}`}))),W(`div.segbar-legend`,...e.map(e=>W(`span.segbar-key`,W(`span`,{class:`segbar-dot segbar-${e.kind||`idle`}`}),e.label))))}var et=0;Array.isArray;function Z(e,n,r,i,a,o){n||={};var s,c,l=n;if(`ref`in l)for(c in l={},n)c==`ref`?s=n[c]:l[c]=n[c];var u={type:e,props:l,key:r,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--et,__i:-1,__u:0,__source:a,__self:o};if(typeof e==`function`&&(s=e.defaultProps))for(c in s)l[c]===void 0&&(l[c]=s[c]);return t.vnode&&t.vnode(u),u}function Q({text:e,kind:t=`idle`}){return Z(`span`,{className:`pill pill-${t}`,children:e})}var tt=`archie.setup-complete.dismissed.v1`;function nt(e,t=globalThis.localStorage){if(!e?.steps?.length)return{kind:`omit`,remaining:[]};let n=e.steps.filter(e=>!e.done);return n.length?(t?.removeItem?.(tt),{kind:`incomplete`,remaining:n}):t?.getItem?.(`archie.setup-complete.dismissed.v1`)===`1`?{kind:`dismissed`,remaining:[]}:{kind:`complete`,remaining:[]}}function rt(e=globalThis.localStorage){e?.setItem?.(tt,`1`)}var it=new Set([`waiting_human`,`parked`]);function at(e=[]){let t=e.filter(e=>it.has(e.status)),n=e.filter(e=>e.status===`running`);return{attention:{count:t.length,href:t.length===1?`#/tasks?task=${encodeURIComponent(t[0].id)}`:`#/tasks?status=needs_you`},running:{count:n.length,href:`#/tasks?status=running`}}}function ot({node:e}){let t=X();return Y(()=>{t.current&&e&&t.current.replaceChildren(e)},[e]),Z(`div`,{ref:t,style:{display:`contents`}})}function st(e){return Z(ot,{node:Xe(e)})}function ct(e){return Z(ot,{node:Qe(e)})}function lt({segments:e}){return Z(ot,{node:$e(e)})}function ut({name:e,opts:t}){return Z(ot,{node:G(e,t)})}function dt({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function ft(e,t){return Number(e.task_id)>0?Number(e.task_id):!e.repo||!e.issue?0:Number(t.get(`${e.repo}#${e.issue}`))||0}function pt(){let e=new Date().getHours();return e<5?`Still up?`:e<12?`Good morning`:e<18?`Good afternoon`:`Good evening`}function mt(e){if(e.length<4)return null;let t=Math.floor(e.length/2),n=e.slice(0,t).reduce((e,t)=>e+t,0),r=e.slice(t).reduce((e,t)=>e+t,0);return n?(r-n)/n*100:null}function ht(){let[e,t]=J([]),[n,r]=J(`connecting`),[i,a]=J(`idle`),[o,s]=J(new Map),[c,l]=J(null),[u,d]=J(null),[f,p]=J(null),[m,h]=J(null),[g,_]=J(null),[,v]=J(!1),y=async()=>{_(null);try{let[e,t,n,r]=await Promise.all([U.summary(),U.setup().catch(()=>null),U.workflows().catch(()=>null),U.tasks().catch(()=>[])]),i=new Map;for(let e of r)e.owner&&e.repo&&e.issue_number&&i.set(`${e.owner}/${e.repo}#${e.issue_number}`,e.id);s(i),l(e),d(t),p(n),h(r)}catch(e){_(String(e.message||e))}};Y(()=>(y(),ue(e=>{t(t=>{let n=[e,...t];return n.splice(50),n})},e=>{r(e),a(e===`live`?`ok`:`warn`)})),[]);let b=()=>{rt(),v(e=>!e)},x=u?.operator?`${pt()}, ${u.operator}`:pt(),C=null;if(g)C=Z(`button`,{className:`btn btn-primary`,onClick:y,children:[Z(ut,{name:`refresh`,opts:{size:15}}),` Retry`]});else if(m!==null){let e=at(m),t=e.attention.count,n=e.running.count;C=Z(S,{children:[t>0&&Z(`a`,{className:`btn btn-attention`,href:e.attention.href,children:[Z(ut,{name:`tasks`,opts:{size:15}}),` `,t,` need`,t===1?`s`:``,` you`]}),n>0&&Z(`a`,{className:`btn`,href:e.running.href,children:[Z(ut,{name:`workflows`,opts:{size:15}}),` `,n,` running`]}),Z(`a`,{className:`btn`,href:`#/logs`,children:[Z(ut,{name:`logs`,opts:{size:15}}),` Logs`]}),Z(`button`,{className:`btn btn-primary`,onClick:y,children:[Z(ut,{name:`refresh`,opts:{size:15}}),` Refresh`]})]})}let w=null;if(g)w=Z(`div`,{className:`card`,children:Z(dt,{title:`Cannot reach archied`,detail:g})});else if(c){let e=c?.statuses||{},t=(e.merged||0)+(e.pr_open||0),n=(e.parked||0)+(e.waiting_human||0),r=Object.values(e).reduce((e,t)=>e+t,0),i=c?.tokens_by_day||[];w=Z(S,{children:[Z(st,{label:`Working now`,value:e.running||0,compare:`${e.queued||0} waiting to start`,series:i.map(e=>e.tokens||0)}),Z(st,{label:`Needs you`,value:n,compare:n?`Parked or awaiting a reply`:`Nothing is blocked`,goodDirection:`down`}),Z(st,{label:`Delivered`,value:t,compare:r?`${Math.round(t/r*100)}% of all tasks`:`No tasks yet`}),Z(st,{label:`Tokens used`,value:De(i.reduce((e,t)=>e+(t.tokens||0),0)),compare:`Across ${i.length||0} days`,trend:mt(i.map(e=>e.tokens||0)),goodDirection:`down`,series:i.map(e=>e.tokens||0)})]})}let T=null,E=nt(u),D=E.kind===`omit`||E.kind===`dismissed`;if(!D){let e=E.remaining;if(e.length){let t=Math.round((u.steps.length-e.length)/u.steps.length*100);T=Z(`div`,{className:`card setup`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Finish setting up`}),Z(`p`,{className:`card-sub`,children:`Archie needs these before it can work on its own.`})]}),Z(`span`,{className:`setup-pct`,children:[t,`%`]})]}),Z(`div`,{className:`setup-bar`,children:Z(`div`,{className:`setup-bar-fill`,style:{width:`${t}%`}})}),Z(`ul`,{className:`setup-list`,children:u.steps.map((e,t)=>Z(`li`,{className:`setup-step ${e.done?`done`:``}`,children:[Z(`span`,{className:`setup-check`,children:e.done?Z(ut,{name:`check`,opts:{size:12}}):``}),Z(`div`,{children:[Z(`div`,{className:`setup-step-title`,children:e.title}),e.detail&&Z(`div`,{className:`setup-step-detail`,children:e.detail})]})]},t))})]})}else T=Z(`div`,{className:`card setup setup-done`,children:Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Setup complete`}),Z(`p`,{className:`card-sub`,children:`Archie is configured and ready to work.`})]}),Z(`div`,{className:`setup-complete-actions`,children:[Z(`span`,{className:`setup-pct`,children:Z(ut,{name:`check`,opts:{size:16}})}),Z(`button`,{className:`icon-btn setup-dismiss`,type:`button`,title:`Dismiss setup complete`,"aria-label":`Dismiss setup complete`,onClick:b,children:`×`})]})]})})}let O=null;if(c){let e=f?.workflows||[],t=e.reduce((e,t)=>e+(t.runs||0),0),n=e.reduce((e,t)=>e+(t.merged||0)+(t.pr_open||0),0),r=e.reduce((e,t)=>e+(t.parked||0),0);if(!t)O=Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:Z(`h2`,{className:`card-title`,children:`Gate pulse`})}),Z(dt,{title:`No completed runs yet`,detail:`Once Archie finishes a task, its gate pass rate appears here.`})]});else{let i=n/t*100;O=Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Gate pulse`}),Z(`p`,{className:`card-sub`,children:`Work that passed its quality gates`})]})}),Z(ct,{value:i,label:`pass rate`}),Z(`ul`,{className:`pulse-list`,children:[e.slice(0,3).map((e,t)=>Z(`li`,{className:`pulse-item`,children:[Z(`span`,{className:`pulse-name`,children:e.workflow||`workflow`}),Z(Q,{text:`${e.merged||0}/${e.runs||0}`,kind:(e.merged||0)===(e.runs||0)?`ok`:(e.parked||0)>0?`warn`:`info`})]},t)),r>0&&Z(`li`,{className:`pulse-item`,children:[Z(`span`,{className:`pulse-name`,children:`Parked, awaiting you`}),Z(Q,{text:String(r),kind:`warn`})]})]})]})}}let k=null;if(c){let e=c?.tokens_by_day||[],t=e.reduce((e,t)=>e+(t.tokens||0),0);if(!e.length)k=Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:Z(`h2`,{className:`card-title`,children:`Token outlook`})}),Z(dt,{title:`Nothing spent yet`,detail:`Usage appears here once Archie runs its first task.`})]});else{let n=t/e.length,r=Math.round(n*30),i=e.slice(-7).reduce((e,t)=>e+(t.tokens||0),0);k=Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Token outlook`}),Z(`p`,{className:`card-sub`,children:`Next 30 days at the current rate`})]})}),Z(`div`,{className:`forecast-value`,children:De(r)}),Z(`div`,{className:`forecast-note`,children:[`Based on `,De(Math.round(n)),` per day over `,e.length,` days`]}),Z(lt,{segments:[{label:`Last 7 days (${De(i)})`,value:i,kind:`info`},{label:`Earlier (${De(t-i)})`,value:Math.max(t-i,0),kind:`idle`}]})]})}}return Z(S,{children:[Z(`div`,{className:`hero`,children:[Z(`div`,{children:[Z(`h1`,{className:`hero-title`,children:x}),Z(`p`,{className:`hero-sub`,children:`Your agent's control room — what it is working on, what needs you, and what it is spending.`})]}),Z(`div`,{className:`hero-actions`,children:Z(`div`,{className:`hero-actions-inner`,children:C})})]}),Z(`div`,{className:`dash-section`,children:[Z(`div`,{className:`dash-section-head`,children:Z(`h2`,{className:`dash-section-title`,children:`Health`})}),Z(`div`,{className:`dash-top ${D?`dash-top-standalone`:``}`,children:[Z(`div`,{children:T}),Z(`div`,{children:O})]})]}),Z(`div`,{className:`dash-section`,children:[Z(`div`,{className:`dash-section-head`,children:[Z(`h2`,{className:`dash-section-title`,children:`Throughput`}),Z(`span`,{className:`dash-section-note`,children:`Across all repositories`})]}),Z(`div`,{className:`grid grid-4`,children:w})]}),Z(`div`,{className:`dash-section`,children:[Z(`div`,{className:`dash-section-head`,children:Z(`h2`,{className:`dash-section-title`,children:`Right now`})}),Z(`div`,{className:`dash-split`,children:[Z(`div`,{children:k}),Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`Live activity`}),Z(`p`,{className:`card-sub`,children:`Last 50, newest first`})]}),Z(Q,{text:n,kind:i})]}),Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Event`}),Z(`th`,{children:`Task`}),Z(`th`,{children:`Detail`}),Z(`th`,{children:`When`})]})}),Z(`tbody`,{children:e.length?e.map((e,t)=>{let n=ft(e,o),r=n>0,i=()=>{r&&(location.hash=`#/tasks?task=${encodeURIComponent(n)}`)};return Z(`tr`,{className:r?`activity-row`:``,role:r?`link`:void 0,tabIndex:r?`0`:void 0,title:r?`Open task details`:void 0,onClick:r?i:void 0,onKeyDown:r?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),i())}:void 0,children:[Z(`td`,{className:`strong`,children:Z(`span`,{children:e.kind||e.type||`event`})}),Z(`td`,{className:`mono`,children:r?`#${n}`:`—`}),Z(`td`,{children:e.detail||e.message||``}),Z(`td`,{children:Ee(e.at||Date.now())})]},t)}):Z(`tr`,{children:Z(`td`,{colSpan:`4`,children:Z(dt,{title:`Waiting for activity`,detail:`Events appear here as Archie works.`})})})})]})})]})]})]})]})}function gt(){return Z(ht,{})}function _t(e,t){let n=e.title||`untitled task`;return{"aria-expanded":String(t),"aria-controls":`task-timeline-${e.id}`,"aria-label":`${t?`Collapse`:`Expand`} timeline for ${n}`}}var vt=Se(),yt=new Set([`needs_you`,...xe()]);function bt(e){let t=e?.get?.(`status`)||``;return yt.has(t)?t:``}function xt(e,t){return t?t===`needs_you`?vt.has(e.status):e.status===t:!0}function St(e){return String(e||`event`).replaceAll(`_`,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Ct(e){let t=Number(e);if(!Number.isFinite(t)||t<0)return``;if(t<1e3)return`${Math.round(t)} ms`;let n=t/1e3;if(n<60)return`${n.toFixed(+(n<10))} s`;let r=Math.round(n),i=Math.floor(r/60),a=r%60;if(i<60)return a===0?`${i} min`:`${i} min ${a} s`;let o=Math.floor(i/60),s=i-o*60;return s===0?`${o} h`:`${o} h ${s} min`}function wt(e){let t=Number(e);return!Number.isFinite(t)||t<=0?``:t.toLocaleString(`en-US`)}function Tt(e={}){let t=e.data||{},n=e.stage||`unknown stage`,r=e.workflow?`${e.workflow} workflow`:``;if(e.kind===`stage_start`)return{title:`Started stage: ${n}`,detail:r};if(e.kind===`stage_finish`){let e=Ct(t.duration_ms),i=[r,e&&`ran for ${e}`].filter(Boolean).join(` · `);return{title:t.interrupted?`Stage interrupted: ${n}`:t.error?`Stage failed: ${n}`:`Finished stage: ${n}`,detail:[i,t.error].filter(Boolean).join(` — `)}}if(e.kind===`task_retried`){let n=Number(t.retry_count);return{title:Number.isFinite(n)&&n>0?`Retry ${n}`:`Retry requested`,detail:[t.previous_stage&&`after ${t.previous_stage}`,t.previous_reason].filter(Boolean).join(`: `)||e.detail||``}}if(e.kind===`agent_finish`){let r=wt(t.iterations),i=wt(t.tokens),a=Number(t.cached_tokens)||0,o=wt((Number(t.prompt_tokens)||0)-a),s=wt(t.completion_tokens),c=wt(t.cached_tokens),l=[r&&`${r} iterations`,i&&`${i} tokens`,o&&`${o} fresh prompt`,s&&`${s} completion`,c&&`${c} cached`,t.model].filter(Boolean);return{title:`Agent ${t.status||`finished`}: ${n}`,detail:l.join(` · `)||e.detail||``}}if(e.kind===`config_captured`)return{title:`Configuration captured`,detail:`The effective task-runtime configuration for this run.`};if(e.kind===`changes_captured`){let e=Number(t.totals?.files);return{title:`Change capture recorded`,detail:[Number.isFinite(e)&&e>0?`${e} file${e===1?``:`s`} changed`:``,t.captured_after?`captured after ${t.captured_after}`:``].filter(Boolean).join(` · `)}}return{title:St(e.kind||e.type),detail:e.detail||``}}var Et=[{value:``,label:`All levels`},{value:`ERROR`,label:`Errors`},{value:`WARN,ERROR`,label:`Warnings and errors`},{value:`INFO,WARN,ERROR`,label:`Info and above`},{value:`DEBUG`,label:`Debug only`}];function Dt(e){switch((e||``).toUpperCase()){case`ERROR`:return`danger`;case`WARN`:return`warn`;case`DEBUG`:return`idle`;default:return`info`}}function Ot(e){let t=e.fields||{};return W(`div.log-row.log-${Dt(e.level)}`,W(`span.log-time.mono`,At(e.time)),W(`span.log-level`,(e.level||`info`).toUpperCase()),W(`span.log-body`,W(`span.log-msg`,e.message||e.msg||``),...Object.entries(t).map(([e,t])=>W(`span.log-field`,W(`span.log-field-key`,e),String(kt(t))))))}function kt(e){return e==null?``:typeof e==`object`?JSON.stringify(e):e}function At(e){let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?`--:--:--`:t.toTimeString().slice(0,8)}function jt({entry:e}){let t=X(null);return Y(()=>{t.current&&t.current.replaceChildren(Ot(e))},[e]),Z(`div`,{ref:t,style:{display:`contents`}})}function Mt(e,t){return`/api/tasks/${e}/logs/download`+(t==null?``:`?attempt=${t}`)}var Nt={level:``,stage:``};function Pt(e,t,n=Nt){let r=n||Nt;return[e,Number(t)||0,r.level||``,r.stage||``].join(`|`)}function Ft({filters:e,onFilterChange:t,stages:n,attempt:r}){let i=n=>t?.({...e,...n}),a=Number(r)||0;return Z(`div`,{className:`log-filters task-log-filters`,children:[Z(`span`,{className:`task-log-attempt`,children:a>0?`Attempt ${a}`:`Current attempt`}),t?Z(S,{children:[Z(`label`,{className:`task-log-filter`,children:[Z(`span`,{className:`task-log-filter-label`,children:`Level`}),Z(`select`,{className:`task-filter`,value:e.level,"aria-label":`Filter log entries by level`,onChange:e=>i({level:e.target.value}),children:Et.map(e=>Z(`option`,{value:e.value,children:e.label},e.value))})]}),Z(`label`,{className:`task-log-filter`,children:[Z(`span`,{className:`task-log-filter-label`,children:`Stage`}),Z(`select`,{className:`task-filter`,value:e.stage,"aria-label":`Filter log entries by stage`,onChange:e=>i({stage:e.target.value}),children:[Z(`option`,{value:``,children:`All stages`}),(n||[]).map(e=>Z(`option`,{value:e,children:e},e))]})]}),e.stage?Z(`p`,{className:`task-log-filter-note`,children:`A stage filter matches only log lines that record a stage. Agent and tool output carries none, so it is not shown while this filter is set.`}):null,!e.stage&&!(n||[]).length?Z(`p`,{className:`task-log-filter-note`,children:`This attempt recorded no stage names, so the stage filter has nothing to match.`}):null]}):null]})}function It({text:e}){return Z(`p`,{className:`visually-hidden`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:e})}function Lt({state:e,onRetry:t,taskId:n,attempt:r,filters:i=Nt,onFilterChange:a,stages:o=[]}){let s=Number(r)||Number(e?.attempt)||0,c,l;if(e===void 0)c=`Loading this attempt's log`,l=Z(`div`,{className:`task-log-loading`,children:`Loading attempt log…`});else if(e===null)c=`This attempt's log could not be loaded`,l=Z(`div`,{className:`task-log-error`,children:[Z(`div`,{className:`task-timeline-detail`,children:`Could not load this attempt's log.`}),Z(`button`,{className:`btn`,onClick:t,children:`Retry`})]});else if(e.found===!1&&!e.disabled)c=`No log recorded for this attempt`,l=Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`No log recorded for this attempt`}),Z(`div`,{children:`This attempt produced no output, or it has not started writing yet.`})]});else if(e.disabled)c=`This dashboard cannot read task logs`,l=Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`No persisted log for this attempt`}),Z(`div`,{children:`This dashboard cannot read task logs. The service that owns the log files is not reporting a log reader.`})]});else{let t=e.entries||[],r=n==null?null:Mt(n,s||null),i=r?Z(`a`,{className:`btn btn-small task-log-download`,href:r,download:!0,children:`Download log`}):null;t.length?(c=`${t.length} log entr${t.length===1?`y`:`ies`} shown`,l=Z(S,{children:[Z(`div`,{className:`log-list task-log-list`,children:t.map((e,t)=>Z(jt,{entry:e},t))}),i]})):(c=`This attempt's log has no entries matching the current filter`,l=Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`Nothing recorded`}),Z(`div`,{children:`This attempt's log file has no entries matching the current filter.`}),i]}))}return Z(S,{children:[Z(Ft,{filters:i,onFilterChange:a,stages:o,attempt:s}),Z(It,{text:c}),l]})}function Rt(){return typeof window<`u`&&window.matchMedia?.(`(prefers-reduced-motion: reduce)`)?.matches===!0}function zt(){return Rt()?`auto`:`smooth`}function Bt(e){let t=X(null);return Y(()=>{t.current&&t.current.replaceChildren(Xe(e))},[e]),Z(`div`,{ref:t,style:{display:`contents`}})}function Vt({kind:e,message:t}){return e===`session-expired`?Z(`span`,{className:`task-action-error task-action-error-session`,children:[`Your session has expired.`,` `,Z(`button`,{className:`button btn btn-small`,type:`button`,onClick:()=>window.location.reload(),children:`Reload to sign in`})]}):e===`refused`?Z(`span`,{className:`task-action-error task-action-error-refused`,children:[t,` — you can't do that.`]}):Z(`span`,{className:`task-action-error task-action-error-broken`,children:[t,` — try again, or check the daemon.`]})}function Ht({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Ut({taskId:e,attempt:t,state:n,onLoad:r,onRetry:i}){let a=X(r);return a.current=r,Y(()=>{n===void 0&&a.current()},[n]),Z(Lt,{state:n,taskId:e,attempt:t,onRetry:i})}function Wt({query:e}){let[t,n]=J(null),[r,i]=J(null),[a,o]=J(()=>bt(e)),[s,c]=J(``),l=Number(e.get(`task`)),u=Number.isFinite(l)&&l>0?l:null,[d,f]=J(u),[p,m]=J(u!==null),[h,g]=J(new Map),[_,v]=J(new Map),y=X(new Set),[b,x]=J(new Set),[C,w]=J(new Map),[T,E]=J(new Set),D=async()=>{try{i(null);let e=await U.tasks();return n(e),d&&e.some(e=>String(e.id)===String(d))&&(h.has(d)||O(d)),e}catch(e){return i(String(e.message||e)),n(null),null}};Y(()=>{D()},[]);let O=async e=>{try{let t=await U.task(e);g(n=>new Map(n).set(e,t||[]))}catch{g(t=>new Map(t).set(e,null))}},k=async(e,t,{force:n=!1}={})=>{let r=Pt(e,t);if(!(y.current.has(r)&&!n)){y.current.add(r),n&&v(e=>{let t=new Map(e);return t.delete(r),t});try{let n=await U.taskLogs(e,{attempt:t||void 0,limit:500});v(e=>new Map(e).set(r,n))}catch{v(e=>new Map(e).set(r,null))}}},A=e=>{g(t=>{let n=new Map(t);return n.delete(e),n})},j=async(e,t)=>{w(t=>{let n=new Map(t);return n.delete(e),n}),E(t=>new Set(t).add(e));try{await U.taskAction(e,t),E(t=>{let n=new Set(t);return n.delete(e),n}),t===`archive`&&f(null),A(e);let n=await D();Array.isArray(n)&&n.find(t=>String(t.id)===String(e))&&d===e&&O(e)}catch(t){E(t=>{let n=new Set(t);return n.delete(e),n}),w(n=>new Map(n).set(e,ce(t)))}};Y(()=>{p&&d&&t&&(m(!1),requestAnimationFrame(()=>{let e=document.getElementById(`task-row-${d}`);e&&(e.focus({preventScroll:!0}),e.scrollIntoView?.({block:`center`,behavior:zt()}))}))},[p,d,t]);let M=(e,t)=>{t&&t.stopPropagation();let n=d!==e;f(n?e:null),n&&O(e)},N=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=()=>{if(!t)return null;let e=t.length,n={};for(let e of t)n[e.status]=(n[e.status]||0)+1;let r=n.running||0,i=(n.waiting_human||0)+(n.parked||0),a=(n.merged||0)+(n.pr_open||0);return Z(`div`,{className:`grid grid-4 task-summary`,children:[Z(Bt,{label:`Total tasks`,value:e,compare:e?`Everything archied has ever picked up`:`No tasks yet`}),Z(Bt,{label:`Working now`,value:r,compare:e?`${r} of ${e} in progress`:`Nothing running`}),Z(Bt,{label:`Needs you`,value:i,compare:i?`Parked or awaiting a reply`:`Nothing is blocked`,goodDirection:`down`}),Z(Bt,{label:`Delivered`,value:a,compare:e?`${Math.round(a/e*100)}% of all tasks`:`No tasks yet`})]})},F=e=>{let t=C.get(e.id),n=t?Vt(t):null,r=T.has(e.id),i=e=>e===`quiet`?`btn-quiet`:e===`danger`?`btn-danger`:``,a=(e.actions||[]).map(t=>{let n=Ce(t);if(!n)return null;let a=e.title||`this task`,o=n.confirm?n.confirm.replaceAll(`{title}`,a):void 0,s=[`button`,`btn`,`btn-small`,i(n.kind)].filter(Boolean).join(` `);if(n.kind===`link`){if(t===`open_pr`)return I(e,`pull_request`,e.pr_number,n.label);if(t===`open_issue`)return I(e,`issue`,e.issue_number,n.label)}return Z(`button`,{className:s,type:`button`,disabled:r,onClick:n=>{n.stopPropagation(),!(o&&!window.confirm(o))&&j(e.id,t)},children:n.label},t)}).filter(Boolean);return!a.length&&!n?`—`:Z(`div`,{className:`task-actions`,children:[n,a]})},I=(e,t,n,r)=>{let i=t===`issue`?e.issue_url:e.pr_url;return!i||!n||t===`issue`&&e.source===`chat`?Z(`button`,{className:`btn btn-small`,type:`button`,disabled:!0,title:`${r} is unavailable`,children:r}):Z(`a`,{className:`btn btn-small`,href:i,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:r})},ee=e=>{let t=e.repo_url;return t?Z(`a`,{className:`task-source-link`,href:t,target:`_blank`,rel:`noreferrer`,title:`Open ${e.owner}/${e.repo} on the forge`,onClick:e=>e.stopPropagation(),children:[e.owner,`/`,e.repo]}):null},te=e=>{let t=e.issue_url;return e.source===`chat`||!t||!e.issue_number?null:Z(`a`,{className:`task-source-link`,href:t,target:`_blank`,rel:`noreferrer`,title:`Open issue #${e.issue_number} on the forge`,onClick:e=>e.stopPropagation(),children:[`#`,e.issue_number]})},L=e=>{let t=Pt(e.id,e.attempt),n=h.get(e.id),r=b.has(e.id);return Z(`tr`,{className:`task-timeline-row`,id:`task-timeline-${e.id}`,children:Z(`td`,{colSpan:8,children:[Z(`div`,{className:`task-detail-actions`,children:[Z(`div`,{className:`task-decision-title`,children:`Available actions`}),F(e)]}),e.status===`waiting_human`&&e.plan&&Z(`div`,{className:`task-decision`,children:[Z(`div`,{className:`task-decision-title`,children:`Decision required`}),Z(`div`,{className:`task-decision-plan`,children:e.plan})]}),e.status===`parked`&&e.park_reason&&Z(`div`,{className:`task-decision`,children:[Z(`div`,{className:`task-decision-title`,children:`Park reason`}),Z(`div`,{className:`task-decision-plan`,children:e.park_reason})]}),n===void 0?Z(`div`,{className:`task-timeline-loading`,children:`Loading timeline…`}):n===null?Z(`div`,{className:`task-timeline-error`,children:[Z(`div`,{className:`task-timeline-title`,children:`Could not load timeline`}),Z(`div`,{className:`task-timeline-detail`,children:`archied did not answer for this task's events. It may be restarting — retry, or check the daemon.`}),Z(`button`,{className:`btn`,onClick:()=>O(e.id),children:`Retry`})]}):n.length?Z(`ul`,{className:`task-timeline`,children:n.map((e,t)=>{let n=Tt(e);return Z(`li`,{className:`task-timeline-entry`,children:[Z(`span`,{className:`task-timeline-dot`}),Z(`div`,{children:[Z(`div`,{className:`task-timeline-kind`,children:n.title}),n.detail&&Z(`div`,{className:`task-timeline-detail`,children:n.detail}),Z(`div`,{className:`task-timeline-when`,children:Ee(e.at)})]})]},t)})}):Z(Ht,{title:`No events yet`,detail:`This task has not recorded any transitions.`}),Z(`div`,{className:`task-logs-section`,children:[Z(`div`,{className:`task-decision-title`,children:[`Attempt log`,Z(`button`,{className:`btn btn-small`,onClick:()=>N(e.id),style:{marginLeft:`10px`},children:r?`Hide`:`Show`})]}),r&&Z(Ut,{taskId:e.id,attempt:e.attempt,state:_.has(t)?_.get(t):void 0,onLoad:()=>k(e.id,e.attempt),onRetry:()=>k(e.id,e.attempt,{force:!0})})]})]})})};return Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Tasks`}),Z(`p`,{className:`page-sub`,children:`Every issue archied has picked up, and where it stands.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:D,children:`Refresh`})})]}),r?Z(`div`,{className:`grid grid-4 task-summary`,children:Z(`div`,{className:`card`,children:Z(Ht,{title:`Cannot reach archied`,detail:r})})}):P(),Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:`All tasks`}),Z(`p`,{className:`card-sub`,children:`Click a row for its timeline`})]}),Z(`div`,{className:`task-filters`,children:[Z(`input`,{className:`task-search`,type:`search`,placeholder:`Search by title or repo…`,value:s,onInput:e=>c(e.target.value.trim().toLowerCase())}),Z(`select`,{className:`task-filter`,value:a,onChange:e=>o(e.target.value),children:[Z(`option`,{value:``,children:`All statuses`}),Z(`option`,{value:`needs_you`,children:`Needs you`}),xe().map(e=>Z(`option`,{value:e,children:ye(e)},e))]})]})]}),Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[`Repo`,`Issue`,`Title`,`Status`,`Workflow`,`Stage`,`Last activity`,`Action`].map(e=>Z(`th`,{children:e},e))})}),Z(`tbody`,{children:(()=>{if(r)return Z(`tr`,{children:Z(`td`,{colSpan:8,children:Z(Ht,{title:`Cannot reach archied`,detail:r})})});if(!t)return Z(`tr`,{children:Z(`td`,{colSpan:8,children:Z(`div`,{className:`task-timeline-loading`,children:`Loading tasks...`})})});if(!t.length)return Z(`tr`,{children:Z(`td`,{colSpan:8,children:Z(Ht,{title:`No tasks yet`,detail:`Tasks appear here once archied picks up an issue to work.`})})});let e=t.filter(e=>xt(e,a)?!s||`${e.title} ${e.repo}`.toLowerCase().includes(s):!1);return e.length?e.map(e=>{let t=d===e.id,n=`task-timeline-${e.id}`;return Z(S,{children:[Z(`tr`,{className:`task-row`,id:`task-row-${e.id}`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),M(e.id,t))},onClick:t=>M(e.id,t),..._t(e,t),children:[Z(`td`,{className:`mono`,"data-label":`Repository`,children:[Z(`button`,{className:`task-expand`,type:`button`,"aria-expanded":String(t),"aria-controls":n,"aria-label":`${t?`Collapse`:`Expand`} timeline for ${e.title||`untitled task`}`,onClick:t=>M(e.id,t),children:t?`−`:`+`}),ee(e)??`${e.owner}/${e.repo}`]}),Z(`td`,{className:`mono`,"data-label":`Issue`,children:te(e)??`#${e.issue_number}`}),Z(`td`,{className:`strong`,"data-label":`Title`,children:Z(`a`,{className:`task-detail-link`,href:`#/tasks/${e.id}`,title:`Open the run detail for this task`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:e.title||`(untitled)`})}),Z(`td`,{"data-label":`Status`,children:Z(Q,{text:ye(e.status),kind:be(e.status)})}),Z(`td`,{"data-label":`Workflow`,children:e.workflow||`—`}),Z(`td`,{"data-label":`Stage`,children:e.stage||`—`}),Z(`td`,{"data-label":`Last activity`,title:e.created_at?`Created ${Ee(e.created_at)}`:``,children:Ee(e.updated_at)}),Z(`td`,{"data-label":`Actions`,children:F(e)})]}),t&&L(e)]},e.id)}):Z(`tr`,{children:Z(`td`,{colSpan:8,children:Z(Ht,{title:`No matching tasks`,detail:`Try a different search or status filter.`})})})})()})]})})]})]})}function Gt(e){return Z(Wt,{query:e})}function Kt(e,t){return`${e}-tab-${t}`}function qt(e,t){return`${e}-panel-${t}`}function Jt({tabs:e,active:t,onSelect:n,prefix:r=`run`,label:i=`Run detail views`}){let a=X([]),o=t=>{let r=e[t];r&&(n?.(r.id),a.current[t]?.focus?.())};return Z(`div`,{className:`tab-bar`,role:`tablist`,"aria-label":i,onKeyDown:n=>{let r=e.findIndex(e=>e.id===t);if(r<0)return;let i;if(n.key===`ArrowRight`)i=(r+1)%e.length;else if(n.key===`ArrowLeft`)i=(r-1+e.length)%e.length;else if(n.key===`Home`)i=0;else if(n.key===`End`)i=e.length-1;else return;n.preventDefault(),o(i)},children:e.map((e,i)=>{let o=e.id===t;return Z(`button`,{ref:e=>{a.current[i]=e},id:Kt(r,e.id),className:`tab${o?` is-selected`:``}`,type:`button`,role:`tab`,"aria-selected":o,"aria-controls":qt(r,e.id),tabIndex:o?0:-1,onClick:()=>n?.(e.id),children:e.label},e.id)})})}var Yt={ok:{label:`ok`,kind:`ok`},failed:{label:`failed`,kind:`danger`},interrupted:{label:`interrupted`,kind:`warn`},running:{label:`running`,kind:`info`},unknown:{label:`unknown`,kind:`idle`}};function Xt(e){return Yt[e]||{label:e||`unknown`,kind:`idle`}}function Zt(e,t,n){return(e||[]).filter(e=>e&&e.kind===`agent_finish`&&Number(e.attempt)===Number(t)&&(e.stage||``)===(n||``)).map(e=>Tt(e))}function Qt(e){let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?`start time not recorded`:`started ${t.toISOString().replace(`T`,` `).slice(0,16)} UTC`}function $t({stage:e,attemptNumber:t,events:n}){let r=Xt(e.status),i=Ct(e.duration_ms),a=Zt(n,t,e.name);return Z(`li`,{className:`run-stage`,"data-status":e.status||`unknown`,children:[Z(`span`,{className:`run-stage-node`,"aria-hidden":`true`}),Z(`div`,{className:`run-stage-body`,children:[Z(`div`,{className:`run-stage-head`,children:[Z(`span`,{className:`run-stage-name mono`,children:e.name||`(unnamed stage)`}),Z(Q,{text:r.label,kind:r.kind}),Z(`span`,{className:`run-stage-duration`,children:i?`ran for ${i}`:`duration not recorded`})]}),e.error?Z(`div`,{className:`run-stage-error`,children:e.error}):null,a.map((e,t)=>Z(`div`,{className:`run-agent-report`,children:[Z(`span`,{className:`run-agent-report-label`,children:`Agent's own report, not verified by archie: `}),[e.title,e.detail].filter(Boolean).join(` · `)]},t))]})]})}function en({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function tn({count:e}){let t=Number(e)||0;return t?Z(`p`,{className:`run-rail-note`,children:[t,` event`,t===1?``:`s`,` on this task predate attempt attribution and cannot be assigned to a run.`]}):null}function nn({state:e,attemptNumber:t,events:n,onRetry:r}){if(e===void 0)return Z(`div`,{className:`run-loading`,children:`Loading this task's attempts…`});if(e===null)return Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load this task's attempts`}),Z(`div`,{className:`run-error-detail`,children:`archied did not answer for this task's run history. It may be restarting — retry, or check the daemon.`}),r?Z(`button`,{className:`btn`,type:`button`,onClick:r,children:`Retry`}):null]});let i=e?.attempts||[];if(!i.length)return Z(S,{children:[Z(en,{title:`No attempts recorded`,detail:`This task has no recorded run. An attempt is written when a stage event is emitted, and none exist here.`}),Z(tn,{count:e?.unattributed_events})]});let a=i.find(e=>Number(e.attempt)===Number(t));if(!a)return Z(S,{children:[Z(en,{title:`Attempt ${t} is not recorded for this task`,detail:`This task recorded attempt ${i.map(e=>e.attempt).join(`, `)}.`}),Z(tn,{count:e?.unattributed_events})]});let o=a.stages||[],s=Xt(a.status);return Z(`div`,{className:`run-rail`,children:[Z(`div`,{className:`run-rail-head`,children:[Z(`span`,{className:`run-rail-attempt`,children:[`Attempt `,a.attempt]}),Z(Q,{text:s.label,kind:s.kind}),Z(`span`,{className:`run-rail-when`,children:Qt(a.started_at)})]}),o.length?Z(`ol`,{className:`run-stages`,"aria-label":`Stages recorded in attempt ${a.attempt}`,children:o.map((e,t)=>Z($t,{stage:e,attemptNumber:a.attempt,events:n},`${e.seq??t}:${e.name}`))}):Z(en,{title:`No stages recorded for this attempt`,detail:`The attempt exists, but nothing recorded a stage for it.`}),Z(`p`,{className:`run-rail-legend`,children:[Z(`strong`,{children:`ok`}),` means the stage returned without error. Archie records no exit code and does not verify that the work was correct, so this is a progress status, not a check result.`]}),Z(tn,{count:e?.unattributed_events})]})}var rn={added:`Added`,modified:`Modified`,deleted:`Deleted`,renamed:`Renamed`,typechange:`Type changed`};function an(e){return rn[e]||e||`unknown`}function on(e,t){let n=e?.repo_url||t?.repo_url||``,r=t&&String(t.pr_number??``)!==``&&String(t.pr_number)===String(e?.pr_number??``);return{repo:n,pr:e?.pr_url||r&&t.pr_url||``}}function sn(e={}){let t=Number(e.files)||0,n=[`${t} file${t===1?``:`s`}`];return e.additions&&n.push(`+${e.additions}`),e.deletions&&n.push(`−${e.deletions}`),n.join(` · `)}function cn({capture:e}){let t=e.files||[],n=Number(e.totals?.files)||t.length;return t.length?Z(S,{children:[Z(`table`,{className:`table run-changes-table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Path`}),Z(`th`,{children:`Change`}),Z(`th`,{className:`run-changes-count`,children:`Added`}),Z(`th`,{className:`run-changes-count`,children:`Deleted`})]})}),Z(`tbody`,{children:t.map((e,t)=>Z(`tr`,{children:[Z(`td`,{className:`mono run-changes-path`,children:[e.old_path?Z(`span`,{className:`run-changes-old`,children:[e.old_path,` → `]}):null,e.path]}),Z(`td`,{children:[an(e.status),e.binary?Z(`span`,{className:`run-changes-hint`,children:`no textual hunks`}):null]}),Z(`td`,{className:`run-changes-count mono`,children:e.additions?`+${e.additions}`:`—`}),Z(`td`,{className:`run-changes-count mono`,children:e.deletions?`−${e.deletions}`:`—`})]},`${e.path}:${t}`))})]}),e.truncated?Z(`p`,{className:`run-changes-note`,children:[`Showing the first `,t.length,` of `,n,` files. The totals above cover every file in this capture.`]}):null]}):Z(`div`,{className:`run-changes-empty`,children:[`This capture recorded no file entries`,n?`, though its totals cover ${n} file${n===1?``:`s`}`:``,`.`]})}function ln({capture:e,task:t}){let n=on(e,t),r=e.pr_number;return Z(`section`,{className:`run-capture`,children:[Z(`div`,{className:`run-capture-head`,children:[Z(`span`,{className:`run-capture-when`,children:[e.captured_after?`Captured after ${e.captured_after}`:`Captured`,e.stage?` in stage ${e.stage}`:``]}),Z(`span`,{className:`run-capture-at`,children:e.captured_at?Ee(e.captured_at):``})]}),Z(`div`,{className:`run-capture-meta`,children:[Z(`span`,{className:`mono`,children:n.repo?Z(`a`,{className:`run-capture-link`,href:n.repo,target:`_blank`,rel:`noreferrer`,children:[e.owner,`/`,e.repo]}):`${e.owner||``}/${e.repo||``}`}),e.branch?Z(`span`,{className:`mono run-capture-branch`,children:[e.branch,e.base?` → ${e.base}`:``]}):null,e.head_sha?Z(`span`,{className:`mono run-capture-sha`,children:String(e.head_sha).slice(0,8)}):null,r?n.pr?Z(`a`,{className:`run-capture-link`,href:n.pr,target:`_blank`,rel:`noreferrer`,children:[`PR #`,r]}):Z(`span`,{className:`mono`,children:[`PR #`,r]}):null,Z(`span`,{className:`run-capture-totals`,children:sn(e.totals)})]}),Z(cn,{capture:e})]})}function un({state:e,task:t,onRetry:n}){if(e===void 0)return Z(`div`,{className:`run-loading`,children:`Loading changed files…`});if(e===null)return Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load this attempt's changed files`}),Z(`div`,{className:`run-error-detail`,children:`archied did not answer for this attempt. It may be restarting — retry, or check the daemon.`}),n?Z(`button`,{className:`btn`,type:`button`,onClick:n,children:`Retry`}):null]});let r=e.captures||[];return e.found===!0&&!r.length?Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`A change capture was recorded but could not be read`}),Z(`div`,{children:`This attempt has a change capture event, but this dashboard could not decode its payload. That is a read failure, not a statement about what the attempt changed.`})]}):!e.found||!r.length?Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`No change capture was recorded for this attempt`}),Z(`div`,{children:`Archie records what an attempt changed when it commits or pushes that work. Nothing was recorded here — the attempt may predate capture, or it produced no commit. This is not the same as "no files changed".`})]}):Z(`div`,{className:`run-changes`,children:r.map((e,n)=>Z(ln,{capture:e,task:t},`${e.captured_at||``}:${n}`))})}function dn(e,t){return(e||[]).find(e=>e&&e.kind===`config_captured`&&Number(e.attempt)===Number(t))||null}function fn({events:e,attempt:t,onRetry:n}){if(e===void 0)return Z(`div`,{className:`run-loading`,children:`Loading this task's events…`});if(e===null)return Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load this task's events`}),Z(`div`,{className:`run-error-detail`,children:`The configuration is recorded as an event on the task, so it cannot be shown while the event stream is unreadable. archied did not answer — retry, or check the daemon.`}),n?Z(`button`,{className:`btn`,type:`button`,onClick:n,children:`Retry`}):null]});let r=dn(e,t);if(!r)return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:`Not captured for this run`}),Z(`div`,{children:[`Archie records the effective configuration when it dispatches an attempt. Attempt `,t,` `,`has no such record — it predates the record, or the capture did not run. Nothing here says the run used the defaults.`]})]});let i=r.data||{},a=i.schema||``,o=i.document;return Z(`div`,{className:`run-config`,children:[Z(`p`,{className:`run-config-scope`,children:[`This is attempt `,r.attempt,`'s effective task-runtime configuration: a non-secret subset covering bot identity, models, limits, budgets, dispatch, diff cap, notifications, forge host and tool policy. It is not the dashboard configuration view — providers, repositories, identities, credentials and lock state are not part of it.`]}),Z(`div`,{className:`run-config-when`,children:[`Captured `,r.at||`at an unrecorded time`,r.stage?` in stage ${r.stage}`:``]}),a===`archie/task-config@1`?Z(`pre`,{className:`run-json`,children:JSON.stringify(o??{},null,2)}):Z(S,{children:[Z(`div`,{className:`run-config-unknown`,children:[`Recorded in an unknown schema`,a?` (${a})`:``,`. The raw payload is shown verbatim; nothing here reinterprets it.`]}),Z(`pre`,{className:`run-json`,children:JSON.stringify(i,null,2)})]})]})}function pn({state:e,attempt:t,onRetry:n}){return e===void 0?Z(`div`,{className:`run-loading`,children:`Loading the stored record…`}):e===null?Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load the stored record`}),Z(`div`,{className:`run-error-detail`,children:`archied did not answer for this task's debug view. It may be restarting — retry, or check the daemon.`}),n?Z(`button`,{className:`btn`,type:`button`,onClick:n,children:`Retry`}):null]}):Z(`div`,{className:`run-debug`,children:[Z(`p`,{className:`run-debug-note`,children:[`The stored task record and its events, verbatim. Events are unfiltered on purpose: this is every event the task has, and each one carries the attempt it belongs to. Attempt `,t,` `,`is the one selected above.`]}),Z(`pre`,{className:`run-json`,children:JSON.stringify(e,null,2)})]})}var mn=[{id:`stages`,label:`Stages`},{id:`log`,label:`Log`},{id:`changes`,label:`Changed files`},{id:`config`,label:`Configuration`},{id:`debug`,label:`Debug`}],hn=`run`,gn=new Set(mn.map(e=>e.id));function _n(e){let t=String(e??``).trim();if(!/^\d+$/.test(t))return null;let n=Number(t);return Number.isSafeInteger(n)&&n>0?n:null}function vn(e){let t=e?.get?.(`tab`)||``;return gn.has(t)?t:mn[0].id}function yn(e){let t=e?.get?.(`attempt`);if(t==null||t===``)return null;let n=Number(t);return Number.isInteger(n)&&n>0?n:null}function bn(e,t,n){let r=new URLSearchParams;return r.set(`tab`,t||mn[0].id),n&&r.set(`attempt`,String(n)),`#/tasks/${e}?${r.toString()}`}function xn(e,t,n){try{window.history.replaceState(null,``,`${location.pathname}${location.search}${bn(e,t,n)}`)}catch{}}function Sn(e,t){return`${e}|${Number(t)||0}`}function Cn({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function wn({id:e}){return Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Task not found`}),Z(`p`,{className:`page-sub`,children:[`No task with id `,e,` in this deployment.`]})]}),Z(`div`,{className:`page-actions`,children:Z(`a`,{className:`btn`,href:`#/tasks`,children:`Back to tasks`})})]}),Z(`div`,{className:`card`,children:Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:[`Nothing is recorded for task `,e]}),Z(`div`,{children:`archied answered that this task does not exist, so there is no run history to show.`})]})})]})}function Tn({raw:e}){return Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Not a task id`}),Z(`p`,{className:`page-sub`,children:`The run view addresses one task by its id: #/tasks/42`})]}),Z(`div`,{className:`page-actions`,children:Z(`a`,{className:`btn`,href:`#/tasks`,children:`Back to tasks`})})]}),Z(`div`,{className:`card`,children:Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:[`“`,e,`” is not a task id`]}),Z(`div`,{children:`A task id is a positive whole number. Nothing was requested.`})]})})]})}function En({attempts:e,selected:t,onSelect:n}){let r=e?.attempts||[];return r.length?Z(`div`,{className:`run-attempts`,role:`group`,"aria-label":`Attempts of this task`,children:r.map(e=>{let r=Xt(e.status),i=Number(e.attempt)===Number(t);return Z(`button`,{type:`button`,className:`run-attempt${i?` is-selected`:``}`,"aria-pressed":i,onClick:()=>n(e.attempt),children:[Z(`span`,{className:`run-attempt-id`,children:[`Attempt `,e.attempt]}),Z(Q,{text:r.label,kind:r.kind}),Z(`span`,{className:`run-attempt-meta`,children:[(e.stages||[]).length,` stage`,(e.stages||[]).length===1?``:`s`]})]},e.attempt)})}):null}function Dn({id:e,query:t}){let[n,r]=J(()=>vn(t)),[i,a]=J(()=>yn(t)),[o,s]=J(void 0),[c,l]=J(void 0),[u,d]=J(!1),[f,p]=J(void 0),[m,h]=J(Nt),[g,_]=J(new Map),[v,y]=J(new Map),[b,x]=J(new Map),[S,C]=J(!1),[w,T]=J(null),[E,D]=J(0),O=X(new Set),k=Array.isArray(o)&&o.find(t=>String(t.id)===String(e))||null,A=Number(c?.current_attempt)>0?Number(c.current_attempt):null,j=i??A,M=(c?.attempts||[]).find(e=>Number(e.attempt)===Number(j)),N=[...new Set((M?.stages||[]).map(e=>e.name).filter(Boolean))],P=(e,t,n,{force:r=!1}={})=>{O.current.has(e)&&!r||(O.current.add(e),n(t=>new Map(t).set(e,void 0)),t().then(t=>n(n=>new Map(n).set(e,t))).catch(()=>n(t=>new Map(t).set(e,null))))},F=()=>{s(void 0),U.tasks().then(e=>s(e)).catch(()=>s(null))},I=()=>{l(void 0),d(!1),U.taskAttempts(e).then(e=>l(e)).catch(e=>{e?.status===404&&d(!0),l(null)})},ee=()=>{p(void 0),U.task(e).then(e=>p(e||[])).catch(()=>p(null))},te=(t,n)=>P(Pt(e,t,m),()=>U.taskLogs(e,{attempt:t||void 0,level:m.level,stage:m.stage,limit:500}),_,n),L=(t,n)=>P(Sn(e,t),()=>U.taskChanges(e,{attempt:t}),y,n),R=(t,n)=>P(Sn(e,t),()=>U.taskDebug(e,{attempt:t}),x,n),ne=()=>{O.current=new Set,_(new Map),y(new Map),x(new Map),F(),I(),ee(),D(e=>e+1)};Y(()=>{F(),I(),ee()},[]),Y(()=>{j!=null&&(n===`log`?te(j):n===`changes`?L(j):n===`debug`&&R(j))},[n,j,m,E]),Y(()=>{xn(e,n,j)},[e,n,j]);let z=async()=>{let t=k?.title||`task ${e}`;if(window.confirm(`Start a new run for "${t}"? This is a new attempt, and the previous attempt's commits are discarded.`)){T(null),C(!0);try{await U.taskAction(e,`retry`),O.current=new Set,_(new Map),y(new Map),x(new Map),a(null),F(),I(),ee(),D(e=>e+1)}catch(e){T(ce(e))}finally{C(!1)}}};if(u)return Z(wn,{id:e});let B=j==null?null:Pt(e,j,m),re=Sn(e,j),ie=Sn(e,j),ae=()=>{if(n===`stages`)return Z(nn,{state:c,attemptNumber:j,events:f,onRetry:I});if(c===void 0)return Z(`div`,{className:`run-loading`,children:`Loading this task's attempts…`});if(c===null)return Z(`div`,{className:`run-error`,children:[Z(`div`,{className:`run-error-title`,children:`Could not load this task's attempts`}),Z(`div`,{className:`run-error-detail`,children:`This panel reads one attempt, and the task's run history could not be read.`}),Z(`button`,{className:`btn`,type:`button`,onClick:I,children:`Retry`})]});if(j==null)return Z(Cn,{title:`No attempt recorded`,detail:`This task has no recorded run, so there is nothing to read for an attempt.`});switch(n){case`log`:return Z(Lt,{state:B&&g.has(B)?g.get(B):void 0,attempt:j,stages:N,filters:m,onFilterChange:h,taskId:e,onRetry:()=>te(j,{force:!0})});case`changes`:return Z(un,{state:v.has(re)?v.get(re):void 0,task:k,onRetry:()=>L(j,{force:!0})});case`config`:return Z(fn,{events:f,attempt:j,onRetry:ee});case`debug`:return Z(pn,{state:b.has(ie)?b.get(ie):void 0,attempt:j,onRetry:()=>R(j,{force:!0})});default:return Z(nn,{state:c,attemptNumber:j,events:f,onRetry:I})}},V=Ce(`retry`),oe=!!(V&&(k?.actions||[]).includes(`retry`));return Z(`div`,{className:`run-page`,children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:k?.title||`Task #${e}`}),Z(`p`,{className:`page-sub`,children:[`One run of task `,e,k?.workflow?` · ${k.workflow} workflow`:``,k?.repo?` · ${k.owner}/${k.repo}`:``]})]}),Z(`div`,{className:`page-actions`,children:[Z(`a`,{className:`btn`,href:`#/tasks`,children:`Back to tasks`}),Z(`button`,{className:`btn`,type:`button`,onClick:ne,children:`Refresh`})]})]}),Z(`div`,{className:`run-meta`,children:[Z(`span`,{className:`run-meta-item`,children:[Z(`span`,{className:`run-meta-label`,children:`Task status`}),o===void 0?Z(`span`,{className:`run-meta-muted`,children:`loading…`}):k?Z(Q,{text:ye(k.status),kind:be(k.status)}):Z(`span`,{className:`run-meta-muted`,children:`not read`})]}),Z(`span`,{className:`run-meta-item`,children:[Z(`span`,{className:`run-meta-label`,children:`Attempt`}),Z(`span`,{className:`run-meta-value`,children:c===null?`run history unreadable`:c===void 0?`loading…`:j==null?`none recorded`:`attempt ${j} of ${A??j}`})]}),k?.repo_url?Z(`a`,{className:`run-meta-link`,href:k.repo_url,target:`_blank`,rel:`noreferrer`,children:[k.owner,`/`,k.repo]}):null,k?.issue_url&&k.issue_number?Z(`a`,{className:`run-meta-link`,href:k.issue_url,target:`_blank`,rel:`noreferrer`,children:[`Issue #`,k.issue_number]}):null,k?.pr_url&&k.pr_number?Z(`a`,{className:`run-meta-link`,href:k.pr_url,target:`_blank`,rel:`noreferrer`,children:[`PR #`,k.pr_number]}):null]}),o===null?Z(`p`,{className:`run-note`,children:`The task list could not be read, so this page cannot show the task's current status or its operator controls. The run history below comes from the task's own endpoints.`}):null,Array.isArray(o)&&!k?Z(`p`,{className:`run-note`,children:[`Task `,e,` is not among the tasks this dashboard lists (the list covers the 100 most recently updated). Its recorded attempts are shown below; the Debug tab holds the stored record verbatim.`]}):null,Z(`section`,{className:`run-restart`,"aria-label":`Start a new run`,children:[Z(`button`,{className:`btn ${V?.kind===`primary`?`btn-primary`:``}`,type:`button`,disabled:!oe||S,title:`Retry this task as a new run`,onClick:z,children:S?`Starting…`:`Start a new run`}),Z(`p`,{className:`run-restart-copy`,children:`Starts a new attempt for this task: a fresh worktree reset onto the base branch. The previous attempt's commits are discarded — they are not carried into the new run.`}),!oe&&o!==void 0?Z(`p`,{className:`run-restart-unavailable`,children:k?`A new run can only start from a parked task. This task is ${ye(k.status)}.`:`This task's operator controls could not be read, so a new run cannot be started from here.`}):null,w?Z(`p`,{className:`run-restart-error run-restart-error-${w.kind}`,children:w.kind===`session-expired`?`Your session has expired. Reload to sign in.`:w.kind===`refused`?`${w.message} — this run cannot be restarted from here.`:`${w.message} — try again, or check the daemon.`}):null]}),Z(En,{attempts:c,selected:j,onSelect:e=>a(e)}),Z(`div`,{className:`card run-card`,children:[Z(Jt,{tabs:mn,active:n,onSelect:r,prefix:hn}),Z(`div`,{className:`run-panel`,role:`tabpanel`,id:qt(hn,n),"aria-labelledby":Kt(hn,n),tabIndex:0,children:ae()})]})]})}function On(e,t){let n=t?.id,r=_n(n);return r===null?Z(Tn,{raw:n??``}):Z(Dn,{id:r,query:e})}function kn({title:e,detail:t}){return Z(`div`,{class:`empty`,children:[Z(`div`,{class:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function An(e){return Z(jn,{query:e})}function jn(){let[e,t]=J([]),[n,r]=J(``),[i,a]=J(null),o=async()=>{try{let e=await U.skills();t(e?.skills||[]),a(null)}catch(e){t([]),a(String(e.message||e))}};Y(()=>{o()},[]);let s=(e,t)=>!t||`${e.name} ${e.description}`.toLowerCase().includes(t),c=He(()=>e.filter(e=>s(e,n)),[e,n]);return Z(`div`,{children:[Z(`div`,{class:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{class:`page-title`,children:`Skills`}),Z(`p`,{class:`page-sub`,children:`What Archie can do, in plain language.`})]}),Z(`div`,{class:`page-actions`,children:Z(`button`,{class:`btn`,onClick:o,children:`Refresh`})})]}),Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Catalogue`}),Z(`p`,{class:`card-sub`,children:`Project, shared, and user-global skills`})]}),Z(`input`,{class:`skill-search`,type:`search`,placeholder:`Search skills…`,onInput:e=>r(e.target.value.trim().toLowerCase())})]}),Z(`div`,{class:`grid grid-2`,children:i?Z(kn,{title:`Cannot reach archied`,detail:i}):e.length?c.length?c.map(e=>Z(`div`,{class:`card skill-card`,children:[Z(`div`,{class:`card-head`,children:[Z(`h3`,{class:`card-title`,children:e.name||`Untitled skill`}),e.workflow&&Z(Q,{text:e.workflow,kind:`info`})]}),Z(`p`,{class:`skill-desc`,children:e.description||`No description provided.`}),Z(`div`,{class:`skill-source`,children:e.source||`Unknown source`})]},e.name)):Z(kn,{title:`No skills match`,detail:`Nothing found for "${n}".`}):Z(kn,{title:`No skills discovered yet`,detail:`Skills live as SKILL.md files under project, shared, or user-global .agents/skills/<name>/ directories. Add one and refresh to make it available.`})})]})]})}var Mn={bootstrap:`Bootstrap`,implement:`Implement`,tdd:`TDD`,feasibility:`Feasibility check`};function Nn(e){return Mn[e]?Mn[e]:e?e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g,` `):`Unknown`}function Pn(e,t){return t?Math.round(e/t*100):0}function Fn(e){if(!e)return`—`;if(e<1e3)return`${e} ms`;let t=e/1e3;return t<60?`${t.toFixed(1)} s`:`${(t/60).toFixed(1)} min`}function In({title:e,detail:t}){return Z(`div`,{class:`empty`,children:[Z(`div`,{class:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Ln({fraction:e,kind:t=`ok`}){let n=Math.min(100,Math.max(0,e));return Z(`div`,{class:`wf-bar`,children:Z(`div`,{class:`wf-bar-fill wf-bar-${t}`,style:{width:`${n}%`}})})}function Rn(e){return Z(zn,{query:e})}function zn(){let[e,t]=J([]),[n,r]=J([]),[i,a]=J([]),[o,s]=J(null),c=async()=>{try{let e=await U.workflows();t(e?.definitions||[]),r(e?.workflows||[]),a(e?.stages||[]),s(null)}catch(e){s(String(e.message||e))}};return Y(()=>{c()},[]),Z(`div`,{children:[Z(`div`,{class:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{class:`page-title`,children:`Workflows`}),Z(`p`,{class:`page-sub`,children:`Run outcomes and spend per workflow, and where stages get stuck.`})]}),Z(`div`,{class:`page-actions`,children:Z(`button`,{class:`btn`,onClick:c,children:`Refresh`})})]}),Z(Bn,{definitions:e}),o?Z(`div`,{class:`card`,children:Z(In,{title:`Cannot reach archied`,detail:o})}):Z(S,{children:[Z(Vn,{workflows:n,definitions:e}),Z(Hn,{stages:i})]})]})}function Bn({definitions:e}){if(!e.length)return null;let t=e.filter(e=>e.enabled)[0]?.id||``,[n,r]=J(``),[i,a]=J(``),[o,s]=J(t),[c,l]=J(``),[u,d]=J(``),[f,p]=J(!1),[m,h]=J(``);return Y(()=>{!o&&t&&s(t)},[t,o]),Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Start work`}),Z(`p`,{class:`card-sub`,children:`This enters Archie’s normal admitted task queue.`})]})}),Z(`form`,{class:`wf-form`,onSubmit:async e=>{e.preventDefault(),p(!0),h(``);try{let e=await U.workRequest({identity:n,repository:i,workflow:o,title:c,instructions:u});h(`Queued task #${e.task_id}.`),r(``),a(``),s(t),l(``),d(``)}catch(e){h(String(e.message||e))}finally{p(!1)}},children:[Z(`input`,{placeholder:`Identity`,required:!0,value:n,onInput:e=>r(e.target.value)}),Z(`input`,{placeholder:`owner/repository`,required:!0,value:i,onInput:e=>a(e.target.value)}),Z(`select`,{required:!0,value:o,onInput:e=>s(e.target.value),children:e.filter(e=>e.enabled).map(e=>Z(`option`,{value:e.id,children:Nn(e.name||e.id)},e.id))}),Z(`input`,{placeholder:`Short task title`,required:!0,value:c,onInput:e=>l(e.target.value)}),Z(`textarea`,{placeholder:`Instructions for the work`,required:!0,rows:3,value:u,onInput:e=>d(e.target.value)}),Z(`button`,{class:`btn`,type:`submit`,disabled:f,children:`Start work`}),m&&Z(`p`,{class:`card-sub`,children:m})]})]})}function Vn({workflows:e,definitions:t}){let n=new Map(e.map(e=>[e.workflow,e])),r=t.map(e=>({...e,...n.get(e.id)||{workflow:e.id,runs:0,merged:0}}));return r.length?Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Per workflow`}),Z(`p`,{class:`card-sub`,children:`Success rate is merged tasks over all runs`})]})}),Z(`div`,{class:`table-scroll`,children:Z(`table`,{class:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Workflow`}),Z(`th`,{children:`Origin`}),Z(`th`,{children:`Runs`}),Z(`th`,{children:`Success rate`}),Z(`th`,{children:`Avg tokens`}),Z(`th`,{children:`Avg steps`})]})}),Z(`tbody`,{children:r.map(e=>{let t=Pn(e.merged,e.runs);return Z(`tr`,{children:[Z(`td`,{class:`strong`,children:Nn(e.workflow)}),Z(`td`,{class:`mono`,children:e.origin||`registry`}),Z(`td`,{children:`${e.runs} run${e.runs===1?``:`s`}`}),Z(`td`,{children:[Z(`div`,{class:`wf-rate`,children:[t,`%`,Z(`span`,{class:`wf-rate-sub`,children:[e.merged,` of `,e.runs,` merged`]})]}),Z(Ln,{fraction:t,kind:t>=50?`ok`:`warn`})]}),Z(`td`,{class:`mono`,children:e.avg_tokens?e.avg_tokens.toLocaleString():`—`}),Z(`td`,{class:`mono`,children:e.avg_steps?e.avg_steps.toFixed(1):`—`})]},e.workflow)})})]})})]}):Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:Z(`h2`,{class:`card-title`,children:`Per workflow`})})}),Z(In,{title:`No workflow runs yet`,detail:`Stats appear here once a task has run through a workflow.`})]})}function Hn({stages:e}){if(!e.length)return Z(`div`,{class:`card wf-stage-card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:Z(`h2`,{class:`card-title`,children:`Per stage`})})}),Z(In,{title:`No stage data yet`,detail:`Stage timing and failures appear here once workflows have run.`})]});let t=Math.max(...e.map(e=>e.avg_ms||0),1),n=[...e].sort((e,t)=>(t.avg_ms||0)-(e.avg_ms||0)),r=[...e].filter(e=>e.errors>0).sort((e,t)=>t.errors-e.errors);return Z(`div`,{class:`grid grid-2 wf-stage-card`,children:[Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Slowest stages`}),Z(`p`,{class:`card-sub`,children:`Average duration, this workflow's stages`})]})}),Z(`div`,{class:`table-scroll`,children:Z(`table`,{class:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Workflow`}),Z(`th`,{children:`Stage`}),Z(`th`,{children:`Runs`}),Z(`th`,{children:`Avg duration`})]})}),Z(`tbody`,{children:n.map((e,n)=>Z(`tr`,{children:[Z(`td`,{children:Nn(e.workflow)}),Z(`td`,{class:`strong`,children:e.stage}),Z(`td`,{children:e.runs}),Z(`td`,{children:[Z(`div`,{class:`wf-rate`,children:Fn(e.avg_ms)}),Z(Ln,{fraction:Pn(e.avg_ms,t),kind:`info`})]})]},n))})]})})]}),Z(`div`,{class:`card`,children:[Z(`div`,{class:`card-head`,children:Z(`div`,{children:[Z(`h2`,{class:`card-title`,children:`Most failures`}),Z(`p`,{class:`card-sub`,children:`Stages that error out, over their runs`})]})}),r.length?Z(`div`,{class:`table-scroll`,children:Z(`table`,{class:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Workflow`}),Z(`th`,{children:`Stage`}),Z(`th`,{children:`Failures`})]})}),Z(`tbody`,{children:r.map((e,t)=>Z(`tr`,{children:[Z(`td`,{children:Nn(e.workflow)}),Z(`td`,{class:`strong`,children:e.stage}),Z(`td`,{children:[Z(`div`,{class:`wf-rate`,children:[e.errors,` of `,e.runs]}),Z(Ln,{fraction:Pn(e.errors,e.runs),kind:`danger`})]})]},t))})]})}):Z(In,{title:`No failures recorded`,detail:`Every stage has completed cleanly so far.`})]})]})}function Un({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Wn(e,t){return e===`running`?`ok`:e===`failed`||e===`degraded`?`warn`:`idle`}function Gn(){let[e,t]=J([]),[n,r]=J(null),i=async()=>{try{let e=await U.channels();t(e?.channels||[]),r(null)}catch(e){r(String(e.message||e))}};return Y(()=>{i()},[]),Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Channels`}),Z(`p`,{className:`page-sub`,children:`The conversational front-ends Archie can be reached through.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:i,children:`Refresh`})})]}),Z(`div`,{className:`grid grid-2`,children:n?Z(Un,{title:`Cannot reach archied`,detail:n}):e.length===0?Z(Un,{title:`No channels configured`,detail:`Configure [chat.telegram] or [chat.webhook_addr] in config.toml to talk to Archie outside the dashboard.`}):e.map(e=>Z(`div`,{className:`card channel-card`,children:[Z(`div`,{className:`card-head`,children:[Z(`h3`,{className:`card-title`,children:e.name}),Z(Q,{text:e.state||(e.configured?`configured`:`stopped`),kind:Wn(e.state,e.configured)})]}),Z(`p`,{className:`channel-desc`,children:e.description}),Z(`p`,{className:`channel-detail`,children:e.detail}),e.reload_supported?Z(`button`,{className:`btn`,onClick:async t=>{t.currentTarget.disabled=!0;try{await U.channelReload(e.id||e.name.toLowerCase()),await i()}catch{}finally{t.currentTarget&&(t.currentTarget.disabled=!1)}},children:`Reload`}):Z(`p`,{className:`channel-detail`,children:`Reload requires a daemon restart for this adapter.`})]},e.id||e.name))})]})}function Kn(e){return Z(Gn,{query:e})}function qn({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Jn(e){return Z(Yn,{query:e})}function Yn({query:e}){let[t,n]=J([]),[r,i]=J(null),a=async()=>{try{let e=await U.curators();n(e?.curators||[]),i(null)}catch(e){i(String(e.message||e))}};return Y(()=>{a()},[]),Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Curators`}),Z(`p`,{className:`page-sub`,children:`Background agents that maintain memory and skills: what ran, and why.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:a,children:`Refresh`})})]}),Z(`div`,{className:`grid grid-2`,children:r?Z(qn,{title:`Cannot reach archied`,detail:r}):t.length?t.map(e=>Z(Zn,{curator:e},e.name)):Z(qn,{title:`No curators registered`,detail:`Curators are background agent loops that maintain memory and skills. None are registered on this daemon.`})})]})}function Xn(e){switch(e){case`healthy`:return`ok`;case`degraded`:return`warn`;case`unhealthy`:return`danger`;default:return`idle`}}function Zn({curator:e}){let t=e.recent_actions||[];return Z(`div`,{className:`card curator-card`,children:[Z(`div`,{className:`card-head`,children:[Z(`h3`,{className:`card-title`,children:e.name}),Z(Q,{text:e.health?.status||`unknown`,kind:Xn(e.health?.status)})]}),e.health?.message&&Z(`p`,{className:`curator-health-message`,children:e.health.message}),Z(`p`,{className:`curator-meta`,children:e.last_run_at?`Last ran ${Ee(e.last_run_at)} · ${e.last_run_actions} action${e.last_run_actions===1?``:`s`}`:`Has not run yet`}),t.length?Z(`ul`,{className:`curator-actions`,children:t.map((e,t)=>Z(`li`,{className:`curator-action`,children:[Z(`div`,{className:`curator-action-head`,children:[Z(`span`,{className:`curator-action-type`,children:e.type||`action`}),Z(`span`,{className:`curator-action-time`,children:Ee(e.at)})]}),e.detail&&Z(`p`,{className:`curator-action-detail`,children:e.detail}),e.reason&&Z(`p`,{className:`curator-action-reason`,children:[`Why: `,e.reason]})]},t))}):Z(`p`,{className:`curator-meta`,children:`No recorded activity yet.`})]})}function Qn(e){return e==null||e===``?`—`:String(e)}function $n({label:e,value:t,opts:n}){let r=Qn(t),[i,a]=J(!1),[o,s]=J(``),[c,l]=J(null),[u,d]=J(!1),[f,p]=J(!1),m=n?.key;if(!m)return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,title:n?.hint,children:e}),Z(`span`,{className:`kv-value mono ${r===`—`?`is-empty`:``}`,title:r,children:r})]});let h=n.locked?.[m];if(h)return Z(`div`,{className:`kv is-locked`,children:[Z(`span`,{className:`kv-label`,title:n.hint,children:e}),Z(`span`,{className:`kv-value mono ${r===`—`?`is-empty`:``}`,title:r,children:r}),Z(`span`,{className:`kv-note`,children:h})]});if(n.editable===!1)return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,title:n.hint,children:e}),Z(`span`,{className:`kv-value mono ${r===`—`?`is-empty`:``}`,title:r,children:r})]});let g=n.overridden?.includes(m),_=()=>{s(String(n.raw??``)),l(null),a(!0)},v=async()=>{p(!0),l(null);try{await U.configReset(m),n.onSaved?.()}catch(e){l(String(e.message||e))}finally{p(!1)}},y=async()=>{let e=er(n.type,o);if(e.error){l(e.error);return}d(!0),l(null);try{await(n.save||(e=>U.configUpdate({[m]:e})))(e.value),a(!1),n.onSaved?.()}catch(e){l(String(e.message||e))}finally{d(!1)}};if(i){let t=X(null);Y(()=>{t.current&&t.current.focus()},[]);let r=e=>{e.key===`Enter`&&(e.preventDefault(),y()),e.key===`Escape`&&a(!1)},i;return i=n.type===`bool`?Z(`select`,{className:`kv-input`,value:o,onChange:e=>s(e.target.value),onKeyDown:r,ref:t,children:[Z(`option`,{value:`true`,children:`true`}),Z(`option`,{value:`false`,children:`false`})]}):n.type===`enum`?Z(`select`,{className:`kv-input`,value:o,onChange:e=>s(e.target.value),onKeyDown:r,ref:t,children:(n.options||[]).map(e=>Z(`option`,{value:e,children:e},e))}):Z(`input`,{className:`kv-input`,type:`text`,value:o,onInput:e=>s(e.target.value),onKeyDown:r,ref:t}),Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,title:n.hint,children:e}),i,Z(`div`,{className:`kv-actions`,children:[Z(`button`,{className:`kv-save`,type:`button`,onClick:y,disabled:u,children:`Save`}),Z(`button`,{className:`kv-cancel`,type:`button`,onClick:()=>a(!1),disabled:u,children:`Cancel`})]}),c&&Z(`span`,{className:`kv-note is-error`,children:c})]})}return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,title:n.hint,children:e}),Z(`span`,{className:`kv-value mono ${r===`—`?`is-empty`:``}`,title:r,children:r}),Z(`div`,{className:`kv-actions`,children:[g&&Z(`span`,{className:`kv-flag`,title:`Set from the dashboard; this shadows the value in the config file`,children:`overridden`}),Z(`button`,{className:`kv-btn`,type:`button`,title:`Edit ${e}`,onClick:_,children:`Edit`}),g&&Z(`button`,{className:`kv-btn`,type:`button`,title:`Discard the dashboard value and fall back to the config file`,onClick:v,disabled:f,children:`Reset`})]}),c&&Z(`span`,{className:`kv-note is-error`,children:c})]})}function er(e,t){switch(e){case`int`:{let e=parseInt(t,10);return Number.isNaN(e)?{error:`Enter a whole number`}:{value:e}}case`bool`:return{value:t===`true`};default:return{value:t}}}function tr({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function nr({sub:e,title:t,children:n}){return Z(`div`,{className:`card cfg-section`,children:[Z(`div`,{className:`card-head`,children:Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:t||`Update status`}),Z(`p`,{className:`card-sub`,children:e})]})}),n]})}var rr={ok:`OK`,update_available:`Update available`,drift:`Drift`,unknown:`Unknown`},ir={ok:`ok`,update_available:`info`,drift:`danger`,unknown:`idle`};function ar({components:e}){return!e||!e.length?Z(nr,{sub:`How each component is deployed, and whether what's running matches what's installed.`,children:Z(tr,{title:`No components reported`,detail:`The configured update-check command returned nothing.`})}):Z(nr,{sub:`How each component is deployed, and whether what's running matches what's installed. Hover a row for the exact versions compared.`,children:Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Component`}),Z(`th`,{children:`Install type`}),Z(`th`,{children:`Running`}),Z(`th`,{children:`Latest available`}),Z(`th`,{children:`Status`})]})}),Z(`tbody`,{children:e.map(e=>Z(`tr`,{title:[`Installed claim: ${e.installed_claim||`unknown`}`,`Running: ${e.running_version||`not observed`}`,e.reference?`Reference: ${e.reference}`:null].filter(Boolean).join(`
|
||
`),children:[Z(`td`,{className:`strong`,children:e.label||e.id}),Z(`td`,{className:`mono`,children:e.install_type||`—`}),Z(`td`,{className:`mono`,children:e.running_version||`—`}),Z(`td`,{className:`mono`,children:e.latest_available||`—`}),Z(`td`,{children:Z(Q,{text:rr[e.status]||e.status,kind:ir[e.status]||`idle`})})]},e.id||e.label))})]})})})}function $({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function or({title:e,sub:t,children:n}){return Z(`div`,{className:`card cfg-section`,children:[Z(`div`,{className:`card-head`,children:Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:e}),Z(`p`,{className:`card-sub`,children:t})]})}),n]})}function sr({origins:e}){return e?.length?Z(or,{title:`Configuration sources`,sub:`Applied from top to bottom; later entries take precedence over earlier ones.`,children:Z(`div`,{className:`kv-list`,children:e.map((e,t)=>Z($n,{label:`${e.layer} ${e.role}${e.feature?` (${e.feature})`:``}`,value:e.path},t))})}):Z(or,{title:`Configuration sources`,sub:`The files that supplied the running configuration.`,children:Z($,{title:`Source provenance is unavailable.`})})}function cr(e){return e===`quiet`?`btn-quiet`:e===`danger`?`btn-danger`:``}function lr({data:e,error:t}){if(t)return Z(or,{title:`Work lifecycle`,sub:`The task statuses and operator actions archied ships.`,children:Z($,{title:`Lifecycle unavailable`,detail:t})});let n=e?.statuses||[],r=e?.actions||[];return Z(or,{title:`Work lifecycle`,sub:`The task statuses and operator actions archied ships. Add one on the backend and it appears here without a frontend change.`,children:[Z(`h3`,{className:`cfg-subhead`,children:`Statuses`}),n.length?Z(`div`,{className:`kv-list`,children:n.map(e=>{let t=e.label??ye(e.id),n=e.kind??be(e.id);return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,children:e.id}),Z(`span`,{className:`kv-value`,children:Z(Q,{text:t,kind:n})})]},e.id)})}):Z($,{title:`No statuses reported`,detail:`The server did not return any lifecycle statuses.`}),Z(`h3`,{className:`cfg-subhead`,children:`Actions`}),r.length?Z(`div`,{className:`kv-list`,children:r.map(e=>{let t=e.label??e.id,n=cr(e.kind);return Z(`div`,{className:`kv`,children:[Z(`span`,{className:`kv-label`,children:e.id}),Z(`span`,{className:`kv-value`,children:Z(`button`,{className:`btn btn-small ${n}`,type:`button`,disabled:!0,children:t})})]},e.id)})}):Z($,{title:`No actions reported`,detail:`The server did not return any operator actions.`})]})}function ur({r:e,field:t,onSaved:n,editable:r=!0}){let[i,a]=J(!1),[o,s]=J(null),[c,l]=J(!!e[t]);return r?Z(`td`,{children:[Z(`input`,{className:`repo-field-checkbox`,type:`checkbox`,checked:c,onChange:async r=>{let i=r.target.checked;l(i),a(!0),s(null);try{await U.configRepoUpdate(e.owner,e.name,t,i),n?.()}catch(e){l(!i),s(String(e.message||e))}finally{a(!1)}},disabled:i}),o&&Z(`span`,{className:`kv-note is-error`,children:o})]}):Z(`td`,{children:c?`yes`:`no`})}function dr({r:e,field:t,onSaved:n,editable:r=!0}){let[i,a]=J(String(e[t]??0)),[o,s]=J(null),[c,l]=J(!1);return r?Z(`td`,{children:[Z(`input`,{className:`kv-input`,type:`text`,value:i,onChange:e=>a(e.target.value),onBlur:async()=>{let r=parseInt(i,10);if(Number.isNaN(r)){s(`Enter a whole number`);return}l(!0),s(null);try{await U.configRepoUpdate(e.owner,e.name,t,r),n?.()}catch(e){s(String(e.message||e))}finally{l(!1)}},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.target.blur())},disabled:c}),o&&Z(`span`,{className:`kv-note is-error`,children:o})]}):Z(`td`,{className:`mono`,children:i})}function fr({repos:e,onSaved:t,editable:n=!0}){if(!e?.length)return Z(or,{title:`Repositories`,sub:`The repositories Archie polls for work.`,children:Z($,{title:`No repositories configured`,detail:`Add a [[repos]] entry in config.toml so Archie has somewhere to work.`})});let r=e=>e?.length?e.map(e=>e.join(` `)).join(` → `):`—`;return Z(or,{title:`Repositories`,sub:`Each repository Archie polls, and the quality gate a change must pass before it opens a pull request. Concurrent tasks, retries, and self-review are per-repository overrides -- PATCH /api/config/repos/{owner}/{name}, not the file config.toml directly.`,children:Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Repository`}),Z(`th`,{children:`Base branch`}),Z(`th`,{children:`Ecosystem`}),Z(`th`,{children:`Quality gate`}),Z(`th`,{children:`Protected paths`}),Z(`th`,{children:`Concurrent`}),Z(`th`,{children:`Max retries`}),Z(`th`,{children:`Self-review`})]})}),Z(`tbody`,{children:e.map((e,i)=>Z(`tr`,{children:[Z(`td`,{className:`strong`,children:[e.owner,`/`,e.name]}),Z(`td`,{className:`mono`,children:e.base}),Z(`td`,{children:e.ecosystem||`go`}),Z(`td`,{className:`mono`,children:r(e.gate)}),Z(`td`,{className:`mono`,children:e.protect?.length?e.protect.join(`, `):`—`}),Z(ur,{r:e,field:`allow_concurrent`,onSaved:t,editable:n}),Z(dr,{r:e,field:`max_retries`,onSaved:t,editable:n}),Z(ur,{r:e,field:`review_enabled`,onSaved:t,editable:n})]},i))})]})})})}function pr(e){return e?e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g,` `):`Unknown role`}function mr({models:e,providers:t}){let n=Object.entries(e||{}),r=Object.entries(t||{});return Z(or,{title:`Models & providers`,sub:`Which model handles each stage of work, and which LLM providers are wired up. Only the environment variable NAME is shown, never its value.`,children:[Z(`h3`,{className:`cfg-subhead`,children:`Model roles`}),n.length?Z(`div`,{className:`kv-list`,children:n.map(([e,t])=>Z($n,{label:pr(e),value:t},e))}):Z($,{title:`No model roles configured`,detail:`Assign a model to at least one role (e.g. "builder") in [models].`}),Z(`h3`,{className:`cfg-subhead`,children:`Providers`}),r.length?Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[Z(`th`,{children:`Provider`}),Z(`th`,{children:`Class`}),Z(`th`,{children:`Base URL`}),Z(`th`,{children:`API key env var`}),Z(`th`,{children:`Status`})]})}),Z(`tbody`,{children:r.map(([e,t])=>Z(`tr`,{children:[Z(`td`,{className:`strong`,children:e}),Z(`td`,{children:t.class}),Z(`td`,{className:`mono`,children:t.base_url||`default`}),Z(`td`,{className:`mono`,children:t.api_key_env||`—`}),Z(`td`,{children:t.configured?Z(Q,{text:`configured`,kind:`ok`}):Z(Q,{text:`missing credentials`,kind:`warn`})})]},e))})]})}):Z($,{title:`No providers configured`,detail:`Add a [providers.<name>] entry so a model role above has something to run on.`})]})}function hr(){let[e,t]=J(null),[n,r]=J(null),[i,a]=J(null),[o,s]=J(null),[c,l]=J(!1),[u,d]=J(null),[f,p]=J(null),m=()=>{h(),g(),_()},h=async()=>{try{let e=await U.config();t(e),r(null)}catch(e){r(String(e.message||e))}},g=async()=>{try{let e=await U.version();a(e?.components||[]),s(null),l(!1)}catch(e){e?.status===501?l(!0):s(String(e.message||e))}},_=async()=>{try{let e=await U.taskMeta();d(e),p(null)}catch(e){p(String(e.message||e))}};return Y(()=>{m()},[]),Z(`div`,{className:`cfg-page`,children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Configuration`}),Z(`p`,{className:`page-sub`,children:`What archied is actually running with right now.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:m,children:`Refresh`})})]}),Z(`div`,{children:!c&&(o?Z(`div`,{className:`card`,children:Z($,{title:`Update status unavailable`,detail:o})}):i?Z(ar,{components:i}):null)}),Z(`div`,{children:Z(lr,{data:u,error:f})}),Z(`div`,{children:n?Z(`div`,{className:`card`,children:Z($,{title:`Cannot reach archied`,detail:n})}):!e||Object.keys(e).length===0?Z(`div`,{className:`card`,children:Z($,{title:`No configuration loaded`,detail:`archied is running without a config file wired into the dashboard, so there is nothing to show.`})}):Z(S,{children:[e.reload?.overlay_unavailable&&Z(`div`,{className:`card cfg-notice`,children:Z(`p`,{children:[`The runtime config overlay is not in effect: `,e.reload.overlay_unavailable]})}),e.reload?.last_error&&Z(`div`,{className:`card cfg-notice`,children:Z(`p`,{children:[`The last config reload failed; the running config is unchanged: `,e.reload.last_error]})}),(e.schema||[]).map((t,n)=>{let r=t.fields.filter(e=>e.type!==`structured`);return r.length?Z(or,{title:t.label,sub:t.description,children:Z(`div`,{className:`kv-list`,children:r.map(t=>Z($n,{label:t.label,value:t.value,opts:{key:t.key,type:t.type,options:t.options,raw:t.value,hint:t.description,editable:t.editable&&e.editable!==!1,locked:e.locked||{},overridden:e.overridden||[],onSaved:h}},t.key))})},n):null}),Z(fr,{repos:e.repositories,onSaved:h,editable:e.editable!==!1}),Z(mr,{models:e.models,providers:e.providers}),Z(sr,{origins:e.provenance})]})})]})}function gr(e){return Z(hr,{query:e})}function _r({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function vr(e){switch((e||``).toUpperCase()){case`ERROR`:return`danger`;case`WARN`:return`warn`;case`DEBUG`:return`idle`;default:return`info`}}function yr(e){return e==null?``:typeof e==`object`?JSON.stringify(e):e}function br(e){let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?`--:--:--`:t.toTimeString().slice(0,8)}function xr({entry:e}){let t=e.fields||{};return Z(`div`,{className:`log-row log-${vr(e.level)}`,children:[Z(`span`,{className:`log-time mono`,children:br(e.time)}),Z(`span`,{className:`log-level`,children:(e.level||`info`).toUpperCase()}),Z(`span`,{className:`log-body`,children:[Z(`span`,{className:`log-msg`,children:e.message||e.msg||``}),Object.entries(t).map(([e,t])=>Z(`span`,{className:`log-field`,children:[Z(`span`,{className:`log-field-key`,children:e}),String(yr(t))]},e))]})]})}function Sr(e){return`${e.time||``}|${e.level||``}|${e.message||e.msg||``}|${JSON.stringify(e.fields||{})}`}function Cr(){let[e,t]=J({level:``,component:``,q:``}),[n,r]=J(!1),[i,a]=J([]),[o,s]=J([]),c=X(new Map),[l,u]=J(0),[d,f]=J(!1),[p,m]=J(`connecting`),[h,g]=J(`Refreshing…`),_=X(null),v=X(null),y=async()=>{g(`Refreshing…`);try{let t=await U.logs({level:e.level,component:e.component,q:e.q,limit:500});a(e=>{let n=t.components||[];return e.length===n.length&&e.every((e,t)=>e===n[t])?e:n}),f(!!t.disabled);let n=t.disabled?`Durable history unavailable; live daemon logs continue.`:t.truncated?`showing the most recent matches from ${t.file}`:t.file||``;g(n),s(t.entries||[])}catch{g(`Cannot read logs`)}};Y(()=>{y()},[e]),Y(()=>{let e=de(e=>{if(b.current)return;let t=e;S.current(t)&&(c.current.set(Sr(t),t),t.fields?.component&&a(e=>e.includes(t.fields.component)?e:[...e,t.fields.component]),u(e=>e+1))},e=>{m(e)});return()=>e()},[]);let b=X(n);b.current=n;let x=t=>{if(e.level&&!e.level.split(`,`).includes((t.level||``).toUpperCase())||e.component&&t.fields?.component!==e.component)return!1;if(e.q){let n=e.q.toLowerCase();if(!`${t.message||t.msg||``} ${JSON.stringify(t.fields||{})}`.toLowerCase().includes(n))return!1}return!0},S=X(x);S.current=x;let C=He(()=>{let e=new Map;for(let t of o)e.set(Sr(t),t);for(let[t,n]of c.current)e.set(t,n);return[...e.values()].filter(x).slice(-1e3)},[o,l,e]);return Y(()=>{_.current&&(_.current.scrollTop=_.current.scrollHeight)},[C]),Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Logs`}),Z(`p`,{className:`page-sub`,children:`What Archie has been doing, newest last.`})]}),Z(`div`,{className:`page-actions`,children:[Z(`button`,{className:`btn ${n?`btn-primary`:``}`,onClick:()=>r(!n),children:n?`Resume`:`Pause`}),Z(`button`,{className:`btn`,onClick:y,children:`Refresh`})]})]}),Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{className:`log-filters`,children:[Z(`select`,{className:`log-select`,value:e.level,onChange:e=>t(t=>({...t,level:e.target.value})),children:Et.map(e=>Z(`option`,{value:e.value,children:e.label},e.value))}),Z(`select`,{className:`log-select`,value:e.component,onChange:e=>t(t=>({...t,component:e.target.value})),children:[Z(`option`,{value:``,children:`All components`}),i.map(e=>Z(`option`,{value:e,children:e},e))]}),Z(`input`,{className:`log-search`,type:`search`,placeholder:`Search messages and fields…`,onInput:e=>{let n=e.target.value;v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{t(e=>({...e,q:n}))},250)}})]}),Z(`div`,{className:`log-status`,children:[Z(`span`,{className:`log-meta`,children:h}),Z(Q,{text:p,kind:p===`live`?`ok`:`warn`})]})]}),Z(`div`,{className:`log-list`,ref:_,children:h===`Cannot read logs`?Z(_r,{title:`Cannot read logs`}):C.length?C.map(e=>Z(xr,{entry:e},Sr(e))):Z(_r,{title:d?`Durable history unavailable`:`Nothing matches`,detail:d?`Live daemon logs will appear here while this page is open.`:`Try a wider level or clear the search.`})})]})]})}function wr(e){return Z(Cr,{query:e})}function Tr({capture:e,expanded:t,onToggle:n}){return Z(S,{children:[Z(`tr`,{className:`capture-row`,tabIndex:`0`,"aria-expanded":String(t),onClick:n,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),n(e))},children:[Z(`td`,{className:`mono`,children:e.source||`(unknown)`}),Z(`td`,{title:e.received_at||``,children:Ee(e.received_at)}),Z(`td`,{children:Z(Q,{text:`Unbound`,kind:`idle`})}),Z(`td`,{className:`mono`,children:e.content_type||`—`}),Z(`td`,{children:Z(`button`,{className:`btn btn-small`,type:`button`,children:t?`Hide`:`View`})})]}),t&&Z(Er,{capture:e})]})}function Er({capture:e}){return Z(`tr`,{className:`capture-detail-row`,children:Z(`td`,{colSpan:`5`,children:Z(`div`,{className:`capture-detail`,children:[Z(`div`,{className:`capture-detail-section`,children:[Z(`div`,{className:`capture-detail-title`,children:`Payload`}),Z(Dr,{raw:e.body})]}),Z(`div`,{className:`capture-detail-section`,children:[Z(`div`,{className:`capture-detail-title`,children:`Headers`}),Z(Dr,{raw:e.headers})]})]})})})}function Dr({raw:e}){return e?Z(`pre`,{className:`capture-payload`,children:Or(e)}):Z(`div`,{className:`capture-empty`,children:`(empty)`})}function Or(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function kr({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Ar(e){return Z(jr,{query:e})}function jr({query:e}){let[t,n]=J([]),[r,i]=J(null),[a,o]=J(null),[s,c]=J(!0),[l,u]=J({text:`connecting`,kind:`idle`}),d=async()=>{try{let e=await U.captures(100);c(e.enabled!==!1),n(e.captures||[]),o(null)}catch(e){o(String(e.message||e))}};return Y(()=>{d();let e=ue(e=>{e.kind===`capture`&&d()},e=>{u({text:e,kind:e===`live`?`ok`:`warn`})});return()=>e()},[]),Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Event inspector`}),Z(`p`,{className:`page-sub`,children:`Real inbound payloads archie has captured, most recent first.`})]}),Z(`div`,{className:`page-actions`,children:[Z(Q,{text:l.text,kind:l.kind}),Z(`button`,{className:`btn`,onClick:d,children:`Refresh`})]})]}),Z(`div`,{className:`card`,children:a?Z(kr,{title:`Cannot reach archied`,detail:a}):s?t.length?Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[`Source`,`Received`,`Binding`,`Content type`,``].map((e,t)=>Z(`th`,{children:e},t))})}),Z(`tbody`,{children:t.map(e=>Z(Tr,{capture:e,expanded:r===e.id,onToggle:()=>i(r===e.id?null:e.id)},e.id))})]})}):Z(kr,{title:`No captures yet`,detail:`Point a webhook at /webhooks/capture/<source> and it will show up here.`}):Z(kr,{title:`Capture is not configured`,detail:`This deployment has no capture storage wired up.`})})]})}var Mr=[`string`,`number`,`bool`,`object`,`array`,`any`];function Nr(e){if(e==null)return`any`;if(Array.isArray(e))return`array`;switch(typeof e){case`string`:return`string`;case`number`:return`number`;case`boolean`:return`bool`;case`object`:return`object`;default:return`any`}}function Pr(e,t){return e?`${e}.${t}`:t}function Fr(e,t){return`${e}[${t}]`}function Ir({value:e,path:t=``,name:n=``,onPick:r}){return typeof e==`object`&&e?Z(`ul`,{className:`mapping-tree-list`,children:(Array.isArray(e)?e.map((e,n)=>[String(n),e,Fr(t,n)]):Object.entries(e).map(([e,n])=>[e,n,Pr(t,e)])).map(([e,t,n])=>Z(`li`,{className:`mapping-tree-item`,children:[Z(`span`,{className:`mapping-tree-key`,onClick:i=>{i.stopPropagation(),r&&r({path:n,type:Nr(t),name:e})},children:e}),Z(Ir,{value:t,path:n,name:e,onPick:r})]},n))}):Z(`span`,{className:`mapping-tree-value`,onClick:i=>{i.stopPropagation(),r&&r({path:t,type:Nr(e),name:n})},children:JSON.stringify(e)})}function Lr({fields:e,preview:t,onRemove:n,onNameChange:r,onTypeChange:i,onRequiredChange:a}){if(!e.length)return Z(`div`,{className:`mapping-empty-fields`,children:`Click a value in the payload to bind a field.`});let o=new Map((t?.failures||[]).map(e=>[e.field_name,e]));return Z(`table`,{className:`table mapping-fields-table`,children:[Z(`thead`,{children:Z(`tr`,{children:[`Field name`,`Path`,`Type`,`Required`,`Preview`,``].map((e,t)=>Z(`th`,{children:e},t))})}),Z(`tbody`,{children:e.map((e,s)=>Z(`tr`,{children:[Z(`td`,{children:Z(`input`,{className:`mapping-input`,value:e.name,onInput:e=>r?.(s,e.target.value)})}),Z(`td`,{className:`mono`,children:e.path}),Z(`td`,{children:Z(`select`,{className:`mapping-select`,value:e.type,onChange:e=>i?.(s,e.target.value),children:Mr.map(e=>Z(`option`,{value:e,children:e},e))})}),Z(`td`,{children:Z(`input`,{type:`checkbox`,checked:e.required,onChange:e=>a?.(s,e.target.checked)})}),Z(`td`,{children:Z(Rr,{field:e,preview:t,failureByField:o})}),Z(`td`,{children:Z(`button`,{className:`btn btn-small`,type:`button`,onClick:()=>n?.(s),children:`Remove`})})]},s))})]})}function Rr({field:e,preview:t,failureByField:n}){if(!t)return Z(Q,{text:`not previewed`,kind:`idle`});let r=n.get(e.name);return r?Z(Q,{text:r.reason,kind:`danger`}):Object.prototype.hasOwnProperty.call(t.values||{},e.name)?Z(Q,{text:JSON.stringify(t.values[e.name]),kind:`ok`}):Z(Q,{text:`skipped (optional)`,kind:`idle`})}function zr({mapping:e,onEdit:t,onDelete:n}){return Z(`tr`,{children:[Z(`td`,{children:e.name}),Z(`td`,{className:`mono`,children:e.source_hint||`—`}),Z(`td`,{children:String(e.fields?.length??0)}),Z(`td`,{children:[Z(`button`,{className:`btn btn-small`,type:`button`,onClick:()=>t?.(e),children:`Edit`}),Z(`button`,{className:`btn btn-small`,type:`button`,onClick:()=>n?.(e),children:`Delete`})]})]})}function Br({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Vr(e){return Z(Hr,{query:e})}function Hr({query:e}){let[t,n]=J([]),[r,i]=J([]),[a,o]=J(null),[s,c]=J(null),l=async()=>{try{let[e,t]=await Promise.all([U.mappings(),U.captures(100)]);n(e.mappings||[]),i(t.captures||[]),o(null)}catch(e){o(String(e.message||e))}};Y(()=>{l()},[]);let u=()=>{c({id:null,name:``,sourceHint:``,fields:[],captureId:null,payload:null,payloadError:null,preview:null,actionError:null})},d=e=>{c({id:e.id,name:e.name,sourceHint:e.source_hint||``,fields:(e.fields||[]).map(e=>({...e})),captureId:null,payload:null,payloadError:null,preview:null,actionError:null})},f=async e=>{if(window.confirm(`Delete mapping "${e.name}"?`))try{await U.mappingDelete(e.id),await l()}catch(e){o(String(e.message||e))}},p=e=>{let t=r.find(t=>String(t.id)===String(e));c(e=>{let n={...e,captureId:t?t.id:null,preview:null};if(!t)n.payload=null,n.payloadError=null;else try{n.payload=JSON.parse(t.body),n.payloadError=null}catch{n.payload=null,n.payloadError=`This capture's body is not valid JSON, so its fields cannot be mapped by path.`}return n})},m=({path:e,type:t,name:n})=>{c(r=>{let i=new Set(r.fields.map(e=>e.name)),a=n||`field`,o=1;for(;i.has(a);)a=`${n||`field`}_${++o}`;let s=[...r.fields,{name:a,path:e,type:t,required:!0}];return{...r,fields:s,preview:null}})},h=e=>{c(t=>{let n=t.fields.slice();return n.splice(e,1),{...t,fields:n,preview:null}})},g=(e,t)=>{c(n=>{let r=n.fields.slice();return r[e]={...r[e],...t},{...n,fields:r,preview:null}})};return s?Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:Z(`h1`,{className:`page-title`,children:s.id?`Edit mapping`:`New mapping`})}),Z(`div`,{className:`page-actions`,children:[Z(`button`,{className:`btn`,type:`button`,onClick:()=>{c(null)},children:`Cancel`}),Z(`button`,{className:`btn btn-primary`,type:`button`,onClick:async()=>{let e={name:s.name,source_hint:s.sourceHint,fields:s.fields};try{s.id?await U.mappingUpdate(s.id,e):await U.mappingCreate(e),c(null),await l()}catch(e){c(t=>({...t,actionError:String(e.message||e)}))}},children:`Save`})]})]}),s.actionError&&Z(`div`,{className:`mapping-error`,children:s.actionError}),Z(`div`,{className:`card mapping-form`,children:[Z(`label`,{className:`mapping-form-row`,children:[`Name`,Z(`input`,{className:`mapping-input`,value:s.name,onInput:e=>c(t=>({...t,name:e.target.value}))})]}),Z(`label`,{className:`mapping-form-row`,children:[`Source hint (organisational only)`,Z(`input`,{className:`mapping-input`,value:s.sourceHint,onInput:e=>c(t=>({...t,sourceHint:e.target.value}))})]}),Z(`label`,{className:`mapping-form-row`,children:[`Preview against captured event`,Z(`select`,{className:`mapping-select`,value:s.captureId||``,onChange:e=>p(e.target.value),children:[Z(`option`,{value:``,children:`— pick a captured event —`}),r.map(e=>Z(`option`,{value:e.id,children:[e.source||`(unknown)`,` — `,e.received_at||``]},e.id))]})]})]}),Z(`div`,{className:`card mapping-fields`,children:[Z(`div`,{className:`mapping-section-title`,children:`Bound fields`}),Z(Lr,{fields:s.fields,preview:s.preview,onRemove:h,onNameChange:(e,t)=>g(e,{name:t}),onTypeChange:(e,t)=>g(e,{type:t}),onRequiredChange:(e,t)=>g(e,{required:t})}),Z(`button`,{className:`btn`,type:`button`,onClick:async()=>{if(!s.captureId){c(e=>({...e,actionError:`Pick a captured event to preview against.`}));return}try{let e=await U.mappingPreview(s.captureId,s.fields);c(t=>({...t,preview:e,actionError:null}))}catch(e){c(t=>({...t,actionError:String(e.message||e)}))}},children:`Preview`})]}),Z(`div`,{className:`card mapping-payload`,children:[Z(`div`,{className:`mapping-section-title`,children:`Payload — click a value to bind it`}),s.payloadError?Z(`div`,{className:`mapping-error`,children:s.payloadError}):s.payload===null?Z(`div`,{className:`mapping-empty-fields`,children:`Pick a captured event above to see its payload.`}):Z(Ir,{value:s.payload,onPick:m})]})]}):Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Field mappings`}),Z(`p`,{className:`page-sub`,children:`Bind named fields to JSON paths from a real captured event, ready for a playbook binding.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn btn-primary`,type:`button`,onClick:u,children:`New mapping`})})]}),a?Z(Br,{title:`Cannot reach archied`,detail:a}):t.length?Z(`div`,{className:`card`,children:Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[`Name`,`Source hint`,`Fields`,``].map((e,t)=>Z(`th`,{children:e},t))})}),Z(`tbody`,{children:t.map(e=>Z(zr,{mapping:e,onEdit:()=>d(e),onDelete:()=>f(e)},e.id))})]})})}):Z(Br,{title:`No mappings yet`,detail:`Create one from a captured event to reuse fields in a future playbook binding.`})]})}var Ur={draft:`draft`,pending_approval:`pending approval`,armed:`armed`},Wr={draft:`idle`,pending_approval:`warn`,armed:`ok`};function Gr({status:e}){return Z(Q,{text:Ur[e]||e,kind:Wr[e]||`idle`})}function Kr({binding:e,onEdit:t,onApprove:n,onDelete:r}){let i=e.owner&&e.repo?`${e.owner}/${e.repo}`:`—`;return Z(`tr`,{children:[Z(`td`,{children:e.name}),Z(`td`,{className:`mono`,children:e.matcher?.source||`—`}),Z(`td`,{children:e.workflow}),Z(`td`,{className:`mono`,children:i}),Z(`td`,{children:Z(Gr,{status:e.status})}),Z(`td`,{children:[Z(`button`,{className:`btn btn-small`,type:`button`,onClick:()=>t?.(e),children:`Edit`}),e.status===`pending_approval`&&Z(`button`,{className:`btn btn-small btn-primary`,type:`button`,onClick:()=>n?.(e),children:`Approve`}),Z(`button`,{className:`btn btn-small`,type:`button`,onClick:()=>r?.(e),children:`Delete`})]})]})}function qr({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Jr(e){return Z(Xr,{query:e})}function Yr(){return{id:null,name:``,source:``,mappingId:``,workflow:``,owner:``,repo:``,secret:``,actionError:null}}function Xr({query:e}){let[t,n]=J([]),[r,i]=J([]),[a,o]=J([]),[s,c]=J(null),[l,u]=J(null),d=async()=>{try{let[e,t,r]=await Promise.all([U.bindings(),U.mappings(),U.workflows()]);n(e.bindings||[]),i(t.mappings||[]),o((r.definitions||[]).filter(e=>e.enabled)),c(null)}catch(e){c(String(e.message||e))}};Y(()=>{d()},[]);let f=()=>{u(Yr())},p=e=>{u({id:e.id,name:e.name,source:e.matcher?.source||``,mappingId:e.mapping_id?String(e.mapping_id):``,workflow:e.workflow||``,owner:e.owner||``,repo:e.repo||``,secret:``,actionError:null})},m=()=>u(null),h=async()=>{let e={name:l.name,matcher:{source:l.source},mapping_id:Number(l.mappingId)||0,workflow:l.workflow,owner:l.owner,repo:l.repo,secret:l.secret};try{l.id?await U.bindingUpdate(l.id,e):await U.bindingCreate(e),u(null),await d()}catch(e){u(t=>({...t,actionError:String(e.message||e)}))}},g=async e=>{try{await U.bindingApprove(e.id),await d()}catch(e){c(String(e.message||e))}},_=async e=>{if(window.confirm(`Delete binding "${e.name}"?`))try{await U.bindingDelete(e.id),await d()}catch(e){c(String(e.message||e))}};return l?Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:Z(`h1`,{className:`page-title`,children:l.id?`Edit binding`:`New binding`})}),Z(`div`,{className:`page-actions`,children:[Z(`button`,{className:`btn`,type:`button`,onClick:m,children:`Cancel`}),Z(`button`,{className:`btn btn-primary`,type:`button`,onClick:h,children:`Save`})]})]}),l.actionError&&Z(`div`,{className:`binding-error`,children:l.actionError}),Z(`div`,{className:`card binding-form`,children:[Z(`label`,{className:`binding-form-row`,children:[`Name`,Z(`input`,{className:`binding-input`,value:l.name,onInput:e=>u(t=>({...t,name:e.target.value}))})]}),Z(`label`,{className:`binding-form-row`,children:[`Source (the path segment senders POST to, e.g. "sentry")`,Z(`input`,{className:`binding-input`,value:l.source,onInput:e=>u(t=>({...t,source:e.target.value}))})]}),Z(`label`,{className:`binding-form-row`,children:[`Field mapping`,Z(`select`,{className:`binding-select`,value:l.mappingId,onChange:e=>u(t=>({...t,mappingId:e.target.value})),children:[Z(`option`,{value:``,children:`— pick a saved mapping —`}),r.map(e=>Z(`option`,{value:e.id,children:e.name},e.id))]})]}),Z(`label`,{className:`binding-form-row`,children:[`Workflow`,Z(`select`,{className:`binding-select`,value:l.workflow,onChange:e=>u(t=>({...t,workflow:e.target.value})),children:[Z(`option`,{value:``,children:`— pick a workflow —`}),a.map(e=>Z(`option`,{value:e.id,children:e.name},e.id))]})]}),Z(`label`,{className:`binding-form-row`,children:[`Repo pin -- owner (optional; leave both blank for the single-configured-repo default)`,Z(`input`,{className:`binding-input`,value:l.owner,onInput:e=>u(t=>({...t,owner:e.target.value}))})]}),Z(`label`,{className:`binding-form-row`,children:[`Repo pin -- repo`,Z(`input`,{className:`binding-input`,value:l.repo,onInput:e=>u(t=>({...t,repo:e.target.value}))})]}),Z(`label`,{className:`binding-form-row`,children:[`Shared secret (`,l.id?`leave blank to keep the current secret`:`senders sign with this via HMAC-SHA256`,`)`,Z(`input`,{className:`binding-input`,type:`password`,value:l.secret,onInput:e=>u(t=>({...t,secret:e.target.value}))})]})]})]}):Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Playbook bindings`}),Z(`p`,{className:`page-sub`,children:`Tie a matcher, a field mapping, and a workflow together. New and edited bindings need explicit approval before they can fire.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn btn-primary`,type:`button`,onClick:f,children:`New binding`})})]}),s?Z(qr,{title:`Cannot reach archied`,detail:s}):t.length?Z(`div`,{className:`card`,children:Z(`div`,{className:`table-scroll`,children:Z(`table`,{className:`table`,children:[Z(`thead`,{children:Z(`tr`,{children:[`Name`,`Source`,`Workflow`,`Repo pin`,`Status`,``].map((e,t)=>Z(`th`,{children:e},t))})}),Z(`tbody`,{children:t.map(e=>Z(Kr,{binding:e,onEdit:()=>p(e),onApprove:()=>g(e),onDelete:()=>_(e)},e.id))})]})})}):Z(qr,{title:`No bindings yet`,detail:`Create one from a saved field mapping to turn a captured webhook into a workflow.`})]})}function Zr({title:e,detail:t}){return Z(`div`,{className:`empty`,children:[Z(`div`,{className:`empty-title`,children:e}),t&&Z(`div`,{children:t})]})}function Qr(e){return e===`external`?`Added by you — an external store Archie was given`:`Built in — always available to Archie`}function $r({provider:e}){let t=e.tools||[];return Z(`div`,{className:`card`,children:[Z(`div`,{className:`card-head`,children:[Z(`div`,{children:[Z(`h2`,{className:`card-title`,children:e.name||`provider`}),Z(`p`,{className:`card-sub`,children:Qr(e.role)})]}),e.available?Z(Q,{text:`ready`,kind:`ok`}):Z(Q,{text:`unavailable`,kind:`danger`})]}),!e.available&&Z(`p`,{className:`mem-warning`,children:`Configured but not usable right now — a required binary or connection may be missing.`}),t.length?Z(`ul`,{className:`mem-tools`,children:t.map((e,t)=>Z(`li`,{className:`mem-tool`,children:[Z(`div`,{className:`mem-tool-name mono`,children:e.name}),e.description&&Z(`div`,{className:`mem-tool-desc`,children:e.description})]},t))}):Z(`p`,{className:`mem-warning`,children:`This provider exposes no tools, so the agent cannot use it.`})]})}function ei(){let[e,t]=J(null),[n,r]=J(!0),[i,a]=J(null),[o,s]=J(!0),c=async()=>{s(!0),a(null);try{let e=await U.memory();r(!!e.enabled),t(e.providers||[])}catch(e){a(String(e.message||e))}finally{s(!1)}};return Y(()=>{c()},[]),Z(`div`,{children:[Z(`div`,{className:`page-head`,children:[Z(`div`,{children:[Z(`h1`,{className:`page-title`,children:`Memory`}),Z(`p`,{className:`page-sub`,children:`What Archie can recall between conversations, and the tools it uses to do it.`})]}),Z(`div`,{className:`page-actions`,children:Z(`button`,{className:`btn`,onClick:c,children:`Refresh`})})]}),Z(`div`,{children:o?Z(`div`,{className:`card`,children:Z(`div`,{className:`mem-loading`,children:`Loading…`})}):i?Z(`div`,{className:`card`,children:Z(Zr,{title:`Cannot read memory providers`,detail:i})}):!n||!e.length?Z(`div`,{className:`card`,children:Z(Zr,{title:`Memory is not configured`,detail:`Without a provider, Archie starts every conversation with no recollection of earlier ones.`})}):Z(`div`,{className:`grid grid-2`,children:e.map((e,t)=>Z($r,{provider:e},t))})})]})}function ti(e){return Z(ei,{query:e})}function ni(e){let t=document.createDocumentFragment(),n=/(!\[[^\]]*\]\((?:https?:\/\/[^\s)]+|data:image\/[^\s)]+|\/[^\s)]+)\)|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\((?:https?:\/\/[^\s)]+|\/[^\s)]+)\)|\*[^*]+\*|_[^_]+_)/g,r=0;for(let i of e.matchAll(n)){i.index>r&&t.append(document.createTextNode(e.slice(r,i.index)));let n=i[0];if(n.startsWith(`![`)){let e=n.match(/^!\[([^\]]*)\]\((.+)\)$/);e&&t.append(W(`img.chat-media-img`,{src:e[2],alt:e[1]||`Image`,loading:`lazy`}))}else if(n.startsWith(`~~`))t.append(W(`del`,n.slice(2,-2)));else if(n.startsWith(`**`)||n.startsWith(`__`))t.append(W(`strong`,n.slice(2,-2)));else if(n.startsWith("`"))t.append(W(`code`,n.slice(1,-1)));else if(n.startsWith(`[`)){let e=n.match(/^\[([^\]]+)\]\((https?:\/\/[^\s)]+|\/[^\s)]+)\)$/);t.append(W(`a`,{href:e[2],target:`_blank`,rel:`noreferrer`},e[1]))}else t.append(W(`em`,n.slice(1,-1)));r=i.index+n.length}return r<e.length&&t.append(document.createTextNode(e.slice(r))),t}function ri(e){let t=W(`div.chat-bubble-text`),n=String(e||``).split(`
|
||
`),r=[],i=null,a=null,o=()=>{r.length&&(t.append(W(`p`,ni(r.join(` `)))),r=[])},s=()=>{i&&t.append(i),i=null};for(let e=0;e<n.length;e++){let c=n[e];if(c.startsWith("```")){o(),s(),a?(t.append(W(`pre`,W(`code`,a.join(`
|
||
`)))),a=null):a=[];continue}if(a){a.push(c);continue}let l=ii(c),u=e+1<n.length?ii(n[e+1]):null;if(l&&u&&ai(u)&&l.length===u.length){o(),s();let r=[];for(e+=2;e<n.length;e++){let t=ii(n[e]);if(!t||t.length!==l.length){e--;break}r.push(t)}let i=W(`tbody`);for(let e of r)i.append(W(`tr`,...e.map(e=>W(`td`,ni(e)))));t.append(W(`table`,W(`thead`,W(`tr`,...l.map(e=>W(`th`,ni(e))))),i));continue}if(!c.trim()){o(),s();continue}let d=c.match(/^(#{1,3})\s+(.+)$/);if(d){o(),s(),t.append(W(`h${d[1].length}`,ni(d[2])));continue}let f=c.match(/^\s*[-*]\s+(.+)$/),p=c.match(/^\s*\d+[.)]\s+(.+)$/);if(f||p){o();let e=p?`ol`:`ul`;(!i||i.tagName.toLowerCase()!==e)&&(s(),i=W(e)),i.append(W(`li`,ni((f||p)[1])));continue}if(c.startsWith(`>`)){o(),s(),t.append(W(`blockquote`,ni(c.replace(/^>\s?/,``))));continue}r.push(c)}return o(),s(),a&&t.append(W(`pre`,W(`code`,a.join(`
|
||
`)))),t}function ii(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 ai(e){return e.every(e=>/^:?-{3,}:?$/.test(e))}var oi=`archie.web.chat.channel`;function si(){let e=localStorage.getItem(oi);return e||(e=ie(),localStorage.setItem(oi,e)),e}function ci(e){return{text:e,sourceID:ie()}}function li(e){return{...e}}function ui(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?li(e.turn):ci(r),isRetry:n}}function di(e){return e.title||e.branch_name||`Conversation ${e.session_id.slice(0,8)}`}function fi(e){return e?.status===501?null:`Could not check for updates.`}function pi(){return location.hash.slice(1)||`/`}function mi({text:e}){let t=X(null);return Y(()=>{t.current&&t.current.replaceChildren(ri(e||``))},[e]),Z(`div`,{ref:t,style:{display:`contents`}})}function hi(){let[e,t]=J([]),[n,r]=J(``),[i,a]=J([]),[o,s]=J(``),[c,l]=J(`Ready`),[u,d]=J(!1),[f,p]=J({}),[m,h]=J(``),[g,_]=J(``),[v,y]=J(``),[b,x]=J([]),[C,w]=J([]),[T,E]=J(0),[D,O]=J(!1),[k,A]=J(null),[j,M]=J(null),[N,P]=J(null),[F,I]=J(``),[ee,te]=J(``),[L,R]=J(null),ne=X(null),z=X(null),B=X(null),re=X(null),ie=X(null),ae=X(u);ae.current=u,Y(()=>{ne.current&&(ne.current.scrollTop=ne.current.scrollHeight)},[i,L]),Y(()=>{ue().catch(e=>{l(e.message||`Chat unavailable`)}),V();let e=()=>{B.current?.abort()};return window.addEventListener(`archie:teardown`,e),()=>{window.removeEventListener(`archie:teardown`,e),B.current?.abort()}},[]);async function V(){try{let e=await U.chatUpdate();M(e?.snapshot||null),A(e)}catch(e){let t=fi(e);A(t?{error:t}:null)}}async function oe(){if(j)try{await U.chatUpdateDefer(j),A({snapshot:{deferred:!0},available:[]}),l(`Update deferred`)}catch(e){l(e.message||`Could not defer update`)}}async function se(){if(j)try{l(`Installing…`);let e=await U.chatUpdateInstall(j);M(null),A({snapshot:{},available:[]}),l(e?.result?.restart_requested?`Update installed; restart queued`:`Update complete`)}catch(e){l(e.message||`Update install failed`)}}async function ce(){try{let e=await U.chatDangerous();P(e)}catch(e){P({error:e.message||`Dangerous actions unavailable`})}}async function le(e,t){if(t)try{await U.chatDangerousRequest(e,t),l(`Approval requested`),await ce()}catch(e){l(e.message||`Could not request action`)}}async function H(e,t){try{await U.chatDangerousDecision(e,t),l(t===`deny`?`Action denied`:`Action approved`),await ce()}catch(e){l(e.message||`Approval failed`)}}async function ue(){let e=await U.chatSessions(),r=e.sessions||[];t(r),p(e),h(e.active_persona||``);let i=e.providers||[],a=e.active_provider||i[0]||``;_(a),y(e.active_model||``);let o=(e.commands||[]).map(e=>typeof e==`string`?{command:e,usage:e,description:``}:e);x(o),e.dangerous_available&&await ce(),!n&&r[0]&&await de(r[0].session_id,e,r)}async function de(e,t,n){let i=t||f;r(e),a([]),R(null);let o=i.active_personas?.[e]||i.active_persona||``;h(o);try{await U.chatMessage(si(),`/resume ${e}`);let[t,n]=await Promise.all([U.chatMessages(e),U.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});a(i)}catch(e){l(e.message||`Could not load session messages`)}}async function fe(e){if(n)try{l(`Working…`);let t=await U.chatMessage(si(),e);t.session_id&&r(t.session_id),l(t.reply||`Session updated`),await ue(),(t.session_id||n)&&await de(t.session_id||n),re.current&&(re.current.open=!1)}catch(e){l(e.message||`Session action failed`)}}function pe(e,t){let n=window.prompt(t);n?.trim()&&fe(`${e} ${n.trim()}`)}function me(e){let t=e.target.value;h(t),!(!n||!t)&&U.chatPersona(n,t).then(()=>{p(e=>({...e,active_personas:{...e.active_personas||{},[n]:t}})),l(`Personality: ${t}`)}).catch(e=>{l(e.message||`Failed to set personality`)})}async function he(e){let t=e.target.value;if(_(t),t)try{let e=await U.chatMessage(si(),`/model --provider ${t}`);l(e.reply||`Provider updated`),await ue()}catch(e){l(`Provider update failed: ${e.message||e}`)}}async function ge(e){let t=e.target.value;if(y(t),t)try{let e=await U.chatMessage(si(),`/model ${t}`);l(e.reply||`Model updated`),await ue()}catch(e){l(`Model update failed: ${e.message||e}`)}}function _e(){window.confirm(`Reload the Telegram chat adapter?`)&&(s(`/restart`),Se({textOverride:`/restart`}))}function ve(){s(`/new`),Se({textOverride:`/new`})}function ye(e){let t=e.target.value;s(t);let n=t.slice(0,e.target.selectionStart).match(/(?:^|\s)\/([^\s]*)$/);if(n){let e=n[1].toLowerCase(),t=b.filter(t=>`${t.command} ${t.description}`.toLowerCase().includes(e)).slice(0,8);if(t.length){w(t),E(0),O(!0);return}}O(!1),w([])}function be(e){let t=C[e];if(!t||!z.current)return;let n=z.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]===` `),c=`${r.slice(0,o)}${t.command} ${i}`;s(c),O(!1);let l=o+t.command.length+1;setTimeout(()=>{n.focus(),n.setSelectionRange(l,l)},0)}function xe(e){if(D&&C.length){if(e.key===`Enter`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&C.some(e=>e.command===o.trim())){e.preventDefault(),O(!1),Se();return}if(e.key===`ArrowDown`){e.preventDefault(),E(e=>(e+1)%C.length);return}if(e.key===`ArrowUp`){e.preventDefault(),E(e=>(e+C.length-1)%C.length);return}if(e.key===`Enter`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey){e.preventDefault(),be(T);return}if(e.key===`Escape`){e.preventDefault(),O(!1);return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Se())}async function Se(e=null){let t=e?.textOverride,{text:n,turn:i,isRetry:c}=ui(e,t===void 0?o:t);if(!n||ae.current)return;O(!1),d(!0),l(c?`Retrying…`:`Thinking…`),c||(a(e=>[...e,{from:`web`,text:n}]),s(``));let u=[];R({text:``,tools:[],isError:!1,turn:i,isRetry:c});let f=``,p=!1,m=!1,h=null;try{let e=new AbortController;B.current=e,h=setTimeout(()=>{m=!0,e.abort()},12e4);let t=(await U.chatStream({channel_id:si(),source_id:i.sourceID,text:i.text,page:pi()},{signal:e.signal})).body.getReader(),n=new TextDecoder,o=``;for(;;){let{value:e,done:i}=await t.read();o+=n.decode(e||new Uint8Array,{stream:!i});let a=o.split(`
|
||
|
||
`);o=a.pop()||``;for(let e of a){let t=e.split(`
|
||
`).find(e=>e.startsWith(`data: `));if(!t)continue;let n=JSON.parse(t.slice(6));if(n.session_id&&r(n.session_id),n.type===`delta`&&(f+=n.text,R(e=>e?{...e,text:f}:null)),n.type===`tool`&&(u=[...u,n],R(e=>e?{...e,tools:u}:null)),n.type===`navigate`&&(u=[...u,n],R(e=>e?{...e,tools:u}:null)),n.type===`done`&&(p=!0,f||=n.text),n.type===`error`)throw Error(n.text)}if(i)break}if(!p)throw Error(`chat stream ended before completion`);a(e=>[...e,{from:`assistant`,text:f,tool_calls:u}]),R(null),l(`Ready`),await ue()}catch(e){if(e.name===`AbortError`&&!m)R({text:`Turn stopped.`,tools:u,isError:!1,turn:i,isRetry:c}),l(`Stopped`);else{let t=`Unable to complete that turn: ${e.message||e}`;R({text:t,tools:u,isError:!0,turn:li(i),isRetry:c}),l(`Error — retry available`)}}finally{clearTimeout(h),B.current=null,d(!1),z.current&&z.current.focus()}}function Ce(){l(`Stopping…`),n&&U.chatCancel(n).catch(()=>{}),B.current?.abort()}let W=f.models_by_provider||{},we=g&&W[g]?W[g]:f.models||[];return Z(`div`,{className:`chat-page-content`,children:[Z(`header`,{className:`chat-topbar`,children:[Z(`div`,{children:[Z(`span`,{className:`chat-kicker`,children:`ARCHIE WORKSPACE`}),Z(`h1`,{className:`page-title`,children:`Chat`})]}),Z(`div`,{className:`chat-topbar-actions`,children:[Z(`span`,{className:`chat-status`,children:c}),f.restart_available&&Z(`button`,{className:`btn`,type:`button`,onClick:_e,children:`Reload Telegram`}),Z(`button`,{className:`btn`,type:`button`,onClick:V,children:`Check updates`}),Z(`select`,{className:`chat-select`,"aria-label":`Personality`,value:m,onChange:me,children:[Z(`option`,{value:``,children:`Personality`}),(f.personas||[]).map(e=>Z(`option`,{value:e,children:e},e))]}),(f.providers||[]).length>0&&Z(`select`,{className:`chat-select`,"aria-label":`Provider`,value:g,onChange:he,children:[Z(`option`,{value:``,children:`Provider`}),(f.providers||[]).map(e=>Z(`option`,{value:e,children:e},e))]}),Z(`select`,{className:`chat-select`,"aria-label":`Model`,value:v,onChange:ge,children:[Z(`option`,{value:``,children:`Model`}),we.map(e=>Z(`option`,{value:e,children:e},e))]})]})]}),k&&Z(`div`,{className:`chat-update-panel`,children:k.error?Z(`span`,{children:k.error}):k.available?.length?Z(S,{children:[Z(`div`,{children:[Z(`strong`,{children:`Update available`}),Z(`span`,{children:k.available.map(e=>`${e.Label||e.label}: ${e.Available||e.available}`).join(` · `)})]}),Z(`div`,{className:`chat-update-actions`,children:[Z(`button`,{className:`btn`,type:`button`,onClick:oe,children:`Defer`}),k.can_install&&Z(`button`,{className:`btn btn-primary`,type:`button`,onClick:se,children:`Install update`})]})]}):Z(`span`,{children:k.snapshot?.deferred?`Update deferred.`:`Archie is up to date.`})}),f.dangerous_available&&N&&Z(`div`,{className:`chat-dangerous-panel`,children:[Z(`div`,{className:`chat-dangerous-head`,children:[Z(`strong`,{children:`Dangerous actions`}),Z(`span`,{className:`chat-hint`,children:`Every action requires approval.`})]}),Z(`div`,{className:`chat-dangerous-controls`,children:[Z(`div`,{children:[Z(`select`,{className:`chat-select`,"aria-label":`Checkpoint`,value:F,onChange:e=>I(e.target.value),children:[Z(`option`,{value:``,children:`Select checkpoint`}),(N.checkpoints||[]).map(e=>Z(`option`,{value:e.Number??e.number,children:[e.Number??e.number,` — `,e.Label??e.label??`checkpoint`]},e.Number??e.number))]}),Z(`button`,{className:`btn`,type:`button`,onClick:()=>le(`rollback`,F),children:`Request rollback`})]}),Z(`div`,{children:[Z(`input`,{className:`chat-dangerous-input`,placeholder:`Process name or id`,"aria-label":`Process name or id`,value:ee,onInput:e=>te(e.target.value)}),Z(`button`,{className:`btn`,type:`button`,onClick:()=>le(`stop`,ee),children:`Request stop`})]})]}),Z(`div`,{className:`chat-dangerous-pending-list`,children:(N.pending||[]).length?N.pending.map(e=>Z(`div`,{className:`chat-dangerous-pending`,children:[Z(`span`,{children:e.description}),Z(`div`,{className:`chat-update-actions`,children:[Z(`button`,{className:`btn`,type:`button`,onClick:()=>H(e.id,`approve`),children:`Approve`}),Z(`button`,{className:`btn`,type:`button`,onClick:()=>H(e.id,`permanent`),children:`Approve for 24h`}),Z(`button`,{className:`btn`,type:`button`,onClick:()=>H(e.id,`deny`),children:`Deny`})]})]},e.id)):Z(`span`,{className:`chat-hint`,children:`No pending dangerous actions.`})})]}),Z(`div`,{className:`chat-layout`,children:[Z(`aside`,{className:`chat-sidebar`,children:[Z(`div`,{className:`chat-sidebar-head`,children:[Z(`strong`,{children:`Conversations`}),Z(`button`,{className:`btn btn-primary`,type:`button`,onClick:ve,children:`+ New chat`})]}),Z(`div`,{className:`chat-session-list`,children:e.length?e.map(e=>Z(`button`,{className:`chat-session ${n===e.session_id?`active`:``}`,type:`button`,onClick:()=>de(e.session_id),children:[Z(`strong`,{children:di(e)}),Z(`span`,{children:new Date(e.last_active_at).toLocaleString()})]},e.session_id)):Z(`div`,{className:`chat-empty`,children:`Your conversations will appear here.`})})]}),Z(`section`,{className:`chat-workspace`,children:[Z(`div`,{className:`chat-workspace-head`,children:[Z(`span`,{className:`chat-workspace-label`,children:`PERSONAL ASSISTANT`}),Z(`details`,{className:`chat-command-help`,children:[Z(`summary`,{children:[`Available commands (`,b.length,`)`]}),Z(`div`,{className:`chat-command-list`,children:b.length?b.map(e=>Z(`div`,{className:`chat-command-item`,children:[Z(`code`,{children:e.usage||e.command}),Z(`span`,{children:e.description||``})]},e.command)):Z(`span`,{children:`Send a message to begin.`})})]}),Z(`details`,{className:`chat-session-tools`,ref:re,hidden:!n,children:[Z(`summary`,{children:`Session actions`}),Z(`div`,{className:`chat-session-tool-list`,children:[Z(`button`,{className:`btn`,type:`button`,onClick:()=>fe(`/retry`),children:`Retry`}),Z(`button`,{className:`btn`,type:`button`,onClick:()=>fe(`/undo`),children:`Undo`}),Z(`button`,{className:`btn`,type:`button`,onClick:()=>pe(`/title`,`Session title`),children:`Rename`}),Z(`button`,{className:`btn`,type:`button`,onClick:()=>pe(`/branch`,`Branch name (optional)`),children:`Branch`}),Z(`button`,{className:`btn`,type:`button`,onClick:()=>fe(`/compress --preview`),children:`Preview compression`})]})]})]}),Z(`div`,{className:`chat-transcript`,ref:ne,children:!i.length&&!L?Z(`div`,{className:`chat-empty-state`,children:[Z(`span`,{className:`chat-empty-mark`,children:`A`}),Z(`h2`,{children:`What are we working on?`}),Z(`p`,{children:`Ask Archie anything, or start with one of these prompts.`}),Z(`div`,{className:`chat-prompt-grid`,children:[Z(`button`,{className:`chat-prompt`,type:`button`,onClick:()=>{s(`Summarise active tasks`),z.current?.focus()},children:`Summarise active tasks`}),Z(`button`,{className:`chat-prompt`,type:`button`,onClick:()=>{s(`Show running agents`),z.current?.focus()},children:`Show running agents`}),Z(`button`,{className:`chat-prompt`,type:`button`,onClick:()=>{s(`Check system status`),z.current?.focus()},children:`Check system status`})]})]}):Z(S,{children:[i.map((e,t)=>{let n=e.from??e.From??``,r=e.text??e.Text??``,i=n!==`web`,a=e.tool_calls||e.ToolCalls||[];return Z(`div`,{className:`chat-bubble-row ${i?`assistant`:`user`}`,children:Z(`div`,{className:`chat-bubble`,children:[Z(`div`,{className:`chat-bubble-meta`,children:i?`Archie`:`You`}),i?Z(S,{children:[a.length>0&&Z(`div`,{className:`chat-tools`,children:a.map((e,t)=>{if(e.path)return Z(`a`,{className:`chat-nav-chip`,href:`#${e.path}`,title:`Go to ${e.label||e.path}`,children:[Z(`span`,{className:`chat-nav-chip-icon`,"aria-hidden":`true`,children:`↗`}),Z(`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||`done`;return Z(`div`,{className:`chat-tool ${e.err||e.Err||e.failed?`failed`:``}`,children:[Z(`span`,{className:`chat-tool-icon`,children:`🔧`}),Z(`span`,{className:`chat-tool-name`,children:n}),r&&Z(`code`,{className:`chat-tool-parameters`,children:r}),Z(`span`,{className:`chat-tool-summary`,children:i})]},t)})}),Z(mi,{text:r})]}):Z(`div`,{className:`chat-bubble-text`,children:r})]})},t)}),L&&Z(`div`,{className:`chat-bubble-row assistant`,children:Z(`div`,{className:`chat-bubble`,children:[Z(`div`,{className:`chat-bubble-meta`,children:`Archie`}),L.tools?.length>0&&Z(`div`,{className:`chat-tools`,children:L.tools.map((e,t)=>{if(e.path)return Z(`a`,{className:`chat-nav-chip`,href:`#${e.path}`,title:`Go to ${e.label||e.path}`,children:[Z(`span`,{className:`chat-nav-chip-icon`,"aria-hidden":`true`,children:`↗`}),Z(`span`,{className:`chat-nav-chip-label`,children:e.label||e.path})]},t);let n=e.name||e.tool||`tool`,r=e.parameters||``,i=e.summary||e.text||(e.failed?`failed`:`running…`);return Z(`div`,{className:`chat-tool ${e.failed?`failed`:``}`,children:[Z(`span`,{className:`chat-tool-icon`,children:`🔧`}),Z(`span`,{className:`chat-tool-name`,children:n}),r&&Z(`code`,{className:`chat-tool-parameters`,children:r}),Z(`span`,{className:`chat-tool-summary`,children:i})]},t)})}),Z(mi,{text:L.text||`…`}),L.isError&&Z(`button`,{className:`btn chat-retry`,type:`button`,onClick:()=>Se({turn:L.turn}),children:`Retry`})]})})]})}),Z(`div`,{className:`chat-compose`,children:Z(`div`,{className:`chat-composer-shell`,children:[Z(`textarea`,{ref:z,className:`chat-composer`,rows:3,placeholder:`Message Archie… (commands like /status and /new work here)`,"aria-label":`Message Archie`,disabled:u,value:o,onInput:ye,onKeyDown:xe}),D&&C.length>0&&Z(`div`,{className:`chat-command-menu`,ref:ie,role:`listbox`,"aria-label":`Commands`,children:C.map((e,t)=>Z(`button`,{type:`button`,role:`option`,"aria-selected":String(t===T),className:`chat-command-option`,onMouseDown:e=>e.preventDefault(),onClick:()=>be(t),children:[Z(`code`,{children:e.command}),Z(`span`,{children:e.description||e.usage||``})]},e.command))}),Z(`div`,{className:`chat-compose-actions`,children:[Z(`span`,{className:`chat-hint`,children:`Enter to send · Shift+Enter for a new line`}),Z(`button`,{className:`btn`,type:`button`,disabled:!u,onClick:Ce,children:`Stop`}),Z(`button`,{className:`btn btn-primary`,type:`button`,disabled:u||!o.trim(),onClick:()=>Se(),children:`Send`})]})]})})]})]})]})}function gi(){let e=document.createElement(`div`);return e.className=`chat-page`,re(Z(hi,{}),e),e}function _i(e,t){let n=yi(t);for(let t of e){let e=bi(t.path,n);if(e)return{route:t,params:e}}return null}function vi(e){return e?.navPath||e?.path||`/`}function yi(e){let t=String(e??`/`).split(`?`,1)[0].split(`#`,1)[0];return t?t.length>1&&t.endsWith(`/`)?t.slice(0,-1):t:`/`}function bi(e,t){let n=String(e).split(`/`),r=String(t).split(`/`);if(n.length!==r.length)return null;let i={};for(let e=0;e<n.length;e+=1){let t=n[e];if(t.startsWith(`:`)){if(!r[e])return null;i[t.slice(1)]=decodeURIComponent(r[e]);continue}if(t!==r[e])return null}return i}var xi=[{path:`/`,label:`Dashboard`,icon:`dashboard`,view:gt},{path:`/chat`,label:`Chat`,icon:`chat`,view:gi,section:`chat`},{path:`/tasks`,label:`Tasks`,icon:`tasks`,view:Gt},{path:`/tasks/:id`,label:`Task run`,view:On,nav:!1,navPath:`/tasks`},{path:`/logs`,label:`Logs`,icon:`logs`,view:wr,section:`logs`},{path:`/captures`,label:`Event inspector`,icon:`captures`,view:Ar,section:`captures`},{path:`/mappings`,label:`Field mappings`,icon:`mappings`,view:Vr,section:`mappings`},{path:`/bindings`,label:`Playbook bindings`,icon:`bindings`,view:Jr,section:`bindings`},{path:`/skills`,label:`Skills`,icon:`skills`,view:An,section:`skills`},{path:`/workflows`,label:`Workflows`,icon:`workflows`,view:Rn,section:`workflows`},{path:`/memory`,label:`Memory`,icon:`memory`,view:ti,section:`memory`},{path:`/curators`,label:`Curators`,icon:`curators`,view:Jn,section:`curators`},{path:`/channels`,label:`Channels`,icon:`channels`,view:Kn,section:`channels`},{path:`/settings`,label:`Configuration`,icon:`settings`,view:gr,section:`settings`}],Si=`archie.theme`;function Ci(e){document.documentElement.dataset.theme=e,localStorage.setItem(Si,e)}function wi(){return localStorage.getItem(Si)||`dark`}function Ti(e,t){let n=new Map,r=W(`nav.nav`,...[null].flatMap(()=>[...xi.filter(e=>e.nav!==!1).map(t=>{let r=W(`a.nav-item`,{href:`#${t.path}`,onclick:n=>{t.soon?n.preventDefault():e(t.path)},"aria-disabled":t.soon||void 0,title:t.soon?`Coming soon`:void 0},G(t.icon),W(`span.nav-label`,t.label),t.soon&&W(`span.nav-soon`,`soon`));return n.set(t.path,r),r})])),i=W(`button.icon-btn`,{title:`Toggle light and dark`,"aria-label":`Toggle light and dark`,onclick:()=>{Ci(wi()===`dark`?`light`:`dark`),Te(i,G(wi()===`dark`?`moon`:`sun`))}});Te(i,G(wi()===`dark`?`moon`:`sun`));let a,o=()=>{a?.classList.remove(`is-open`),s.setAttribute(`aria-expanded`,`false`)},s=W(`button.icon-btn.mobile-search-toggle`,{type:`button`,"aria-label":`Open Jump to navigation`,"aria-expanded":`false`,onclick:()=>{a.classList.add(`is-open`),s.setAttribute(`aria-expanded`,`true`),c.focus()}},G(`search`,{size:15})),c=W(`input`,{type:`search`,placeholder:`Jump to…`,"aria-label":`Jump to a section`,onkeydown:t=>{if(t.key===`Escape`){t.preventDefault(),o(),t.target.blur();return}if(t.key!==`Enter`)return;let n=t.target.value.trim().toLowerCase(),r=xi.find(e=>e.nav!==!1&&!e.soon&&e.label.toLowerCase().startsWith(n));r&&(e(r.path),t.target.value=``,t.target.blur(),o())}});return a=W(`div.topbar-search`,W(`span.topbar-search-icon`,{"aria-hidden":`true`},G(`search`,{size:15})),s,c),{node:W(`header.topbar`,W(`div.brand`,W(`span.brand-mark`,`A`),`Archie`),r,W(`div.topbar-end`,a,W(`button.icon-btn.icon-btn-chat`,{"aria-label":`Open chat`,title:`Chat with Archie`,"aria-expanded":`false`,onclick:()=>t?.()},G(`chat`)),W(`button.icon-btn`,{title:`Documentation`,"aria-label":`Documentation`},G(`help`)),i,W(`div.avatar`,{title:`Signed in locally`},`A`))),highlight(e){for(let[t,r]of n)t===e?r.setAttribute(`aria-current`,`page`):r.removeAttribute(`aria-current`)},hide(e){for(let t of e)n.get(t)?.remove()}}}function Ei(){Ci(wi());let e=W(`main.main`),t=W(`aside.chat-drawer`,{"aria-label":`Chat with Archie`}),n=W(`button.icon-btn.chat-drawer-close`,{"aria-label":`Close chat`,title:`Close chat`,onclick:()=>o(!1)},G(`close`)),r=W(`div.chat-drawer-head`,W(`strong`,`Archie`),n);t.append(W(`div.chat-drawer-panel`,r,gi()),W(`div.chat-scrim`,{onclick:()=>o(!1)}));let i=Ti(s,()=>o());U.capabilities().then(e=>i.hide(fe(e?.sections,xi))).catch(()=>{});let a=W(`div.shell`,i.node,e,t);Te(document.getElementById(`app`),a);function o(e){let n=e===void 0?!t.classList.contains(`is-open`):e;t.classList.toggle(`is-open`,n),document.body.classList.toggle(`chat-open`,n);let r=a.querySelector(`.icon-btn-chat`);r&&r.setAttribute(`aria-expanded`,String(n))}window.__archieToggleChat=o;function s(e){location.hash===`#`+e?c(e):location.hash=e}function c(t){e.firstElementChild?.dispatchEvent(new CustomEvent(`archie:teardown`));let[n,r=``]=t.split(`?`,2),a=_i(xi,n),s=a?.route||xi[0];if(i.highlight(vi(s)),s.path===`/chat`){Te(e),o(!0);return}let c=s.view?s.view(new URLSearchParams(r),a?.params||{}):Di(s);c instanceof Node?Te(e,c):re(c,e),o(!1)}window.addEventListener(`hashchange`,()=>c(location.hash.slice(1)||`/`)),window.addEventListener(`keydown`,e=>{e.defaultPrevented||e.key===`Escape`&&t.classList.contains(`is-open`)&&o(!1)}),c(location.hash.slice(1)||`/`)}function Di(e){return W(`div`,W(`div.page-head`,W(`div`,W(`h1.page-title`,e.label))),W(`div.card`,W(`div.empty`,W(`div.empty-title`,`${e.label} is not built yet`),W(`div`,`This section is next up. Nothing is broken.`))))}Ei(); |