var he=globalThis,Ce=he.ShadowRoot&&(he.ShadyCSS===void 0||he.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,rt=Symbol(),nt=new WeakMap;class at{constructor(e,t,s){if(this._$cssResult$=!0,s!==rt)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this._strings=t}get styleSheet(){let e=this._styleSheet,t=this._strings;if(Ce&&e===void 0){let s=t!==void 0&&t.length===1;if(s)e=nt.get(t);if(e===void 0){if((this._styleSheet=e=new CSSStyleSheet).replaceSync(this.cssText),s)nt.set(t,e)}}return e}toString(){return this.cssText}}var ds=(e)=>new at(typeof e==="string"?e:String(e),void 0,rt);var ot=(e,t)=>{if(Ce)e.adoptedStyleSheets=t.map((s)=>s instanceof CSSStyleSheet?s:s.styleSheet);else for(let s of t){let i=document.createElement("style"),r=he.litNonce;if(r!==void 0)i.setAttribute("nonce",r);i.textContent=s.cssText,e.appendChild(i)}},cs=(e)=>{let t="";for(let s of e.cssRules)t+=s.cssText;return ds(t)},Re=Ce?(e)=>e:(e)=>e instanceof CSSStyleSheet?cs(e):e;var{is:ps,defineProperty:hs,getOwnPropertyDescriptor:lt,getOwnPropertyNames:us,getOwnPropertySymbols:ms,getPrototypeOf:dt}=Object,gs=!1,S=globalThis;if(gs)S.customElements??=customElements;var x=!0,M,ct=S.trustedTypes,fs=ct?ct.emptyScript:"",ht=x?S.reactiveElementPolyfillSupportDevMode:S.reactiveElementPolyfillSupport;if(x)S.litIssuedWarnings??=new Set,M=(e,t)=>{if(t+=` See https://lit.dev/msg/${e} for more information.`,!S.litIssuedWarnings.has(t)&&!S.litIssuedWarnings.has(e))console.warn(t),S.litIssuedWarnings.add(t)},queueMicrotask(()=>{if(M("dev-mode","Lit is in dev mode. Not recommended for production!"),S.ShadyDOM?.inUse&&ht===void 0)M("polyfill-support-missing","Shadow DOM is being polyfilled via `ShadyDOM` but the `polyfill-support` module has not been loaded.")});var vs=x?(e)=>{if(!S.emitLitDebugLogEvents)return;S.dispatchEvent(new CustomEvent("lit-debug",{detail:e}))}:void 0,Y=(e,t)=>e,Me={toAttribute(e,t){switch(t){case Boolean:e=e?fs:null;break;case Object:case Array:e=e==null?e:JSON.stringify(e);break}return e},fromAttribute(e,t){let s=e;switch(t){case Boolean:s=e!==null;break;case Number:s=e===null?null:Number(e);break;case Object:case Array:try{s=JSON.parse(e)}catch(i){s=null}break}return s}},ut=(e,t)=>!ps(e,t),pt={attribute:!0,type:String,converter:Me,reflect:!1,useDefault:!1,hasChanged:ut};Symbol.metadata??=Symbol("metadata");S.litPropertyMetadata??=new WeakMap;class P extends HTMLElement{static addInitializer(e){this.__prepare(),(this._initializers??=[]).push(e)}static get observedAttributes(){return this.finalize(),this.__attributeToPropertyMap&&[...this.__attributeToPropertyMap.keys()]}static createProperty(e,t=pt){if(t.state)t.attribute=!1;if(this.__prepare(),this.prototype.hasOwnProperty(e))t=Object.create(t),t.wrapped=!0;if(this.elementProperties.set(e,t),!t.noAccessor){let s=x?Symbol.for(`${String(e)} (@property() cache)`):Symbol(),i=this.getPropertyDescriptor(e,s,t);if(i!==void 0)hs(this.prototype,e,i)}}static getPropertyDescriptor(e,t,s){let{get:i,set:r}=lt(this.prototype,e)??{get(){return this[t]},set(a){this[t]=a}};if(x&&i==null){if("value"in(lt(this.prototype,e)??{}))throw Error(`Field ${JSON.stringify(String(e))} on ${this.name} was declared as a reactive property but it's actually declared as a value on the prototype. Usually this is due to using @property or @state on a method.`);M("reactive-property-without-getter",`Field ${JSON.stringify(String(e))} on ${this.name} was declared as a reactive property but it does not have a getter. This will be an error in a future version of Lit.`)}return{get:i,set(a){let l=i?.call(this);r?.call(this,a),this.requestUpdate(e,l,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??pt}static __prepare(){if(this.hasOwnProperty(Y("elementProperties",this)))return;let e=dt(this);if(e.finalize(),e._initializers!==void 0)this._initializers=[...e._initializers];this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(Y("finalized",this)))return;if(this.finalized=!0,this.__prepare(),this.hasOwnProperty(Y("properties",this))){let t=this.properties,s=[...us(t),...ms(t)];for(let i of s)this.createProperty(i,t[i])}let e=this[Symbol.metadata];if(e!==null){let t=litPropertyMetadata.get(e);if(t!==void 0)for(let[s,i]of t)this.elementProperties.set(s,i)}this.__attributeToPropertyMap=new Map;for(let[t,s]of this.elementProperties){let i=this.__attributeNameForProperty(t,s);if(i!==void 0)this.__attributeToPropertyMap.set(i,t)}if(this.elementStyles=this.finalizeStyles(this.styles),x){if(this.hasOwnProperty("createProperty"))M("no-override-create-property","Overriding ReactiveElement.createProperty() is deprecated. The override will not be called with standard decorators");if(this.hasOwnProperty("getPropertyDescriptor"))M("no-override-get-property-descriptor","Overriding ReactiveElement.getPropertyDescriptor() is deprecated. The override will not be called with standard decorators")}}static finalizeStyles(e){let t=[];if(Array.isArray(e)){let s=new Set(e.flat(1/0).reverse());for(let i of s)t.unshift(Re(i))}else if(e!==void 0)t.push(Re(e));return t}static __attributeNameForProperty(e,t){let s=t.attribute;return s===!1?void 0:typeof s==="string"?s:typeof e==="string"?e.toLowerCase():void 0}constructor(){super();this.__instanceProperties=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this.__reflectingProperty=null,this.__initialize()}__initialize(){this.__updatePromise=new Promise((e)=>this.enableUpdating=e),this._$changedProperties=new Map,this.__saveInstanceProperties(),this.requestUpdate(),this.constructor._initializers?.forEach((e)=>e(this))}addController(e){if((this.__controllers??=new Set).add(e),this.renderRoot!==void 0&&this.isConnected)e.hostConnected?.()}removeController(e){this.__controllers?.delete(e)}__saveInstanceProperties(){let e=new Map,t=this.constructor.elementProperties;for(let s of t.keys())if(this.hasOwnProperty(s))e.set(s,this[s]),delete this[s];if(e.size>0)this.__instanceProperties=e}createRenderRoot(){let e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return ot(e,this.constructor.elementStyles),e}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this.__controllers?.forEach((e)=>e.hostConnected?.())}enableUpdating(e){}disconnectedCallback(){this.__controllers?.forEach((e)=>e.hostDisconnected?.())}attributeChangedCallback(e,t,s){this._$attributeToProperty(e,s)}__propertyToAttribute(e,t){let i=this.constructor.elementProperties.get(e),r=this.constructor.__attributeNameForProperty(e,i);if(r!==void 0&&i.reflect===!0){let l=(i.converter?.toAttribute!==void 0?i.converter:Me).toAttribute(t,i.type);if(x&&this.constructor.enabledWarnings.includes("migration")&&l===void 0)M("undefined-attribute-value",`The attribute value for the ${e} property is undefined on element ${this.localName}. The attribute will be removed, but in the previous version of \`ReactiveElement\`, the attribute would not have changed.`);if(this.__reflectingProperty=e,l==null)this.removeAttribute(r);else this.setAttribute(r,l);this.__reflectingProperty=null}}_$attributeToProperty(e,t){let s=this.constructor,i=s.__attributeToPropertyMap.get(e);if(i!==void 0&&this.__reflectingProperty!==i){let r=s.getPropertyOptions(i),a=typeof r.converter==="function"?{fromAttribute:r.converter}:r.converter?.fromAttribute!==void 0?r.converter:Me;this.__reflectingProperty=i;let l=a.fromAttribute(t,r.type);this[i]=l??this.__defaultValues?.get(i)??l,this.__reflectingProperty=null}}requestUpdate(e,t,s,i=!1,r){if(e!==void 0){if(x&&e instanceof Event)M("","The requestUpdate() method was called with an Event as the property name. This is probably a mistake caused by binding this.requestUpdate as an event listener. Instead bind a function that will call it with no arguments: () => this.requestUpdate()");let a=this.constructor;if(i===!1)r=this[e];if(s??=a.getPropertyOptions(e),(s.hasChanged??ut)(r,t)||s.useDefault&&s.reflect&&r===this.__defaultValues?.get(e)&&!this.hasAttribute(a.__attributeNameForProperty(e,s)))this._$changeProperty(e,t,s);else return}if(this.isUpdatePending===!1)this.__updatePromise=this.__enqueueUpdate()}_$changeProperty(e,t,{useDefault:s,reflect:i,wrapped:r},a){if(s&&!(this.__defaultValues??=new Map).has(e)){if(this.__defaultValues.set(e,a??t??this[e]),r!==!0||a!==void 0)return}if(!this._$changedProperties.has(e)){if(!this.hasUpdated&&!s)t=void 0;this._$changedProperties.set(e,t)}if(i===!0&&this.__reflectingProperty!==e)(this.__reflectingProperties??=new Set).add(e)}async __enqueueUpdate(){this.isUpdatePending=!0;try{await this.__updatePromise}catch(t){Promise.reject(t)}let e=this.scheduleUpdate();if(e!=null)await e;return!this.isUpdatePending}scheduleUpdate(){let e=this.performUpdate();if(x&&this.constructor.enabledWarnings.includes("async-perform-update")&&typeof e?.then==="function")M("async-perform-update",`Element ${this.localName} returned a Promise from performUpdate(). This behavior is deprecated and will be removed in a future version of ReactiveElement.`);return e}performUpdate(){if(!this.isUpdatePending)return;if(vs?.({kind:"update"}),!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),x){let r=[...this.constructor.elementProperties.keys()].filter((a)=>this.hasOwnProperty(a)&&(a in dt(this)));if(r.length)throw Error(`The following properties on element ${this.localName} will not trigger updates as expected because they are set using class fields: ${r.join(", ")}. Native class fields and some compiled output will overwrite accessors used for detecting changes. See https://lit.dev/msg/class-field-shadowing for more information.`)}if(this.__instanceProperties){for(let[i,r]of this.__instanceProperties)this[i]=r;this.__instanceProperties=void 0}let s=this.constructor.elementProperties;if(s.size>0)for(let[i,r]of s){let{wrapped:a}=r,l=this[i];if(a===!0&&!this._$changedProperties.has(i)&&l!==void 0)this._$changeProperty(i,void 0,r,l)}}let e=!1,t=this._$changedProperties;try{if(e=this.shouldUpdate(t),e)this.willUpdate(t),this.__controllers?.forEach((s)=>s.hostUpdate?.()),this.update(t);else this.__markUpdated()}catch(s){throw e=!1,this.__markUpdated(),s}if(e)this._$didUpdate(t)}willUpdate(e){}_$didUpdate(e){if(this.__controllers?.forEach((t)=>t.hostUpdated?.()),!this.hasUpdated)this.hasUpdated=!0,this.firstUpdated(e);if(this.updated(e),x&&this.isUpdatePending&&this.constructor.enabledWarnings.includes("change-in-update"))M("change-in-update",`Element ${this.localName} scheduled an update (generally because a property was set) after an update completed, causing a new update to be scheduled. This is inefficient and should be avoided unless the next update can only be scheduled as a side effect of the previous update.`)}__markUpdated(){this._$changedProperties=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this.__updatePromise}shouldUpdate(e){return!0}update(e){this.__reflectingProperties&&=this.__reflectingProperties.forEach((t)=>this.__propertyToAttribute(t,this[t])),this.__markUpdated()}updated(e){}firstUpdated(e){}}P.elementStyles=[];P.shadowRootOptions={mode:"open"};P[Y("elementProperties",P)]=new Map;P[Y("finalized",P)]=new Map;ht?.({ReactiveElement:P});if(x){P.enabledWarnings=["change-in-update","async-perform-update"];let e=function(t){if(!t.hasOwnProperty(Y("enabledWarnings",t)))t.enabledWarnings=t.enabledWarnings.slice()};P.enableWarning=function(t){if(e(this),!this.enabledWarnings.includes(t))this.enabledWarnings.push(t)},P.disableWarning=function(t){e(this);let s=this.enabledWarnings.indexOf(t);if(s>=0)this.enabledWarnings.splice(s,1)}}(S.reactiveElementVersions??=[]).push("2.1.2");if(x&&S.reactiveElementVersions.length>1)queueMicrotask(()=>{M("multiple-versions","Multiple versions of Lit loaded. Loading multiple versions is not recommended.")});var C=globalThis,g=(e)=>{if(!C.emitLitDebugLogEvents)return;C.dispatchEvent(new CustomEvent("lit-debug",{detail:e}))},bs=0,ie;C.litIssuedWarnings??=new Set,ie=(e,t)=>{if(t+=e?` See https://lit.dev/msg/${e} for more information.`:"",!C.litIssuedWarnings.has(t)&&!C.litIssuedWarnings.has(e))console.warn(t),C.litIssuedWarnings.add(t)},queueMicrotask(()=>{ie("dev-mode","Lit is in dev mode. Not recommended for production!")});var D=C.ShadyDOM?.inUse&&C.ShadyDOM?.noPatch===!0?C.ShadyDOM.wrap:(e)=>e,ue=C.trustedTypes,mt=ue?ue.createPolicy("lit-html",{createHTML:(e)=>e}):void 0,$s=(e)=>e,ve=(e,t,s)=>$s,ys=(e)=>{if(K!==ve)throw Error("Attempted to overwrite existing lit-html security policy. setSanitizeDOMValueFactory should be called at most once.");K=e},ws=()=>{K=ve},Oe=(e,t,s)=>K(e,t,s),Ie="$lit$",H=`lit$${Math.random().toFixed(9).slice(2)}$`,He="?"+H,_s=`<${He}>`,W=document,ne=()=>W.createComment(""),re=(e)=>e===null||typeof e!="object"&&typeof e!="function",je=Array.isArray,wt=(e)=>je(e)||typeof e?.[Symbol.iterator]==="function",De=`[
\f\r]`,ks=`[^
\f\r"'\`<>=]`,Es=`[^\\s"'>=/]`,te=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,gt=1,Le=2,Ss=3,ft=/-->/g,vt=/>/g,U=new RegExp(`>|${De}(?:(${Es}+)(${De}*=${De}*(?:${ks}|("|')|))|$)`,"g"),Ts=0,bt=1,xs=2,$t=3,Ae=/'/g,Ne=/"/g,_t=/^(?:script|style|textarea|title)$/i,kt=1,me=2,ge=3,Ve=1,fe=2,Ps=3,Cs=4,Rs=5,Ue=6,Ms=7,Be=(e)=>(t,...s)=>{if(t.some((i)=>i===void 0))console.warn(`Some template strings are undefined.
This is probably caused by illegal octal escape sequences.`);if(s.some((i)=>i?._$litStatic$))ie("",`Static values 'literal' or 'unsafeStatic' cannot be used as values to non-static templates.
Please use the static 'html' tag function. See https://lit.dev/docs/templates/expressions/#static-expressions`);return{["_$litType$"]:e,strings:t,values:s}},n=Be(kt),ii=Be(me),ni=Be(ge),z=Symbol.for("lit-noChange"),o=Symbol.for("lit-nothing"),yt=new WeakMap,F=W.createTreeWalker(W,129),K=ve;function Et(e,t){if(!je(e)||!e.hasOwnProperty("raw")){let s="invalid template strings array";throw s=`
Internal Error: expected template strings to be an array
with a 'raw' field. Faking a template strings array by
calling html or svg like an ordinary function is effectively
the same as calling unsafeHtml and can lead to major security
issues, e.g. opening your code up to XSS attacks.
If you're using the html or svg tagged template functions normally
and still seeing this error, please file a bug at
https://github.com/lit/lit/issues/new?template=bug_report.md
and include information about your build tooling, if any.
`.trim().replace(/\n */g,`
`),Error(s)}return mt!==void 0?mt.createHTML(t):t}var St=(e,t)=>{let s=e.length-1,i=[],r=t===me?"<svg>":t===ge?"<math>":"",a,l=te;for(let h=0;h<s;h++){let c=e[h],p=-1,m,_=0,f;while(_<c.length){if(l.lastIndex=_,f=l.exec(c),f===null)break;if(_=l.lastIndex,l===te){if(f[gt]==="!--")l=ft;else if(f[gt]!==void 0)l=vt;else if(f[Le]!==void 0){if(_t.test(f[Le]))a=new RegExp(`</${f[Le]}`,"g");l=U}else if(f[Ss]!==void 0)throw Error("Bindings in tag names are not supported. Please use static templates instead. See https://lit.dev/docs/templates/expressions/#static-expressions")}else if(l===U)if(f[Ts]===">")l=a??te,p=-1;else if(f[bt]===void 0)p=-2;else p=l.lastIndex-f[xs].length,m=f[bt],l=f[$t]===void 0?U:f[$t]==='"'?Ne:Ae;else if(l===Ne||l===Ae)l=U;else if(l===ft||l===vt)l=te;else l=U,a=void 0}console.assert(p===-1||l===U||l===Ae||l===Ne,"unexpected parse state B");let R=l===U&&e[h+1].startsWith("/>")?" ":"";r+=l===te?c+_s:p>=0?(i.push(m),c.slice(0,p)+Ie+c.slice(p))+H+R:c+H+(p===-2?h:R)}let d=r+(e[s]||"<?>")+(t===me?"</svg>":t===ge?"</math>":"");return[Et(e,d),i]};class ae{constructor({strings:e,["_$litType$"]:t},s){this.parts=[];let i,r=0,a=0,l=e.length-1,d=this.parts,[h,c]=St(e,t);if(this.el=ae.createElement(h,s),F.currentNode=this.el.content,t===me||t===ge){let p=this.el.content.firstChild;p.replaceWith(...p.childNodes)}while((i=F.nextNode())!==null&&d.length<l){if(i.nodeType===1){{let p=i.localName;if(/^(?:textarea|template)$/i.test(p)&&i.innerHTML.includes(H)){let m=`Expressions are not supported inside \`${p}\` elements. See https://lit.dev/msg/expression-in-${p} for more information.`;if(p==="template")throw Error(m);else ie("",m)}}if(i.hasAttributes()){for(let p of i.getAttributeNames())if(p.endsWith(Ie)){let m=c[a++],f=i.getAttribute(p).split(H),R=/([.?@])?(.*)/.exec(m);d.push({type:Ve,index:r,name:R[2],strings:f,ctor:R[1]==="."?We:R[1]==="?"?ze:R[1]==="@"?Ke:J}),i.removeAttribute(p)}else if(p.startsWith(H))d.push({type:Ue,index:r}),i.removeAttribute(p)}if(_t.test(i.tagName)){let p=i.textContent.split(H),m=p.length-1;if(m>0){i.textContent=ue?ue.emptyScript:"";for(let _=0;_<m;_++)i.append(p[_],ne()),F.nextNode(),d.push({type:fe,index:++r});i.append(p[m],ne())}}}else if(i.nodeType===8)if(i.data===He)d.push({type:fe,index:r});else{let m=-1;while((m=i.data.indexOf(H,m+1))!==-1)d.push({type:Ms,index:r}),m+=H.length-1}r++}if(c.length!==a)throw Error('Detected duplicate attribute bindings. This occurs if your template has duplicate attributes on an element tag. For example "<input ?disabled=${true} ?disabled=${false}>" contains a duplicate "disabled" attribute. The error was detected in the following template: \n`'+e.join("${...}")+"`");g&&g({kind:"template prep",template:this,clonableTemplate:this.el,parts:this.parts,strings:e})}static createElement(e,t){let s=W.createElement("template");return s.innerHTML=e,s}}function q(e,t,s=e,i){if(t===z)return t;let r=i!==void 0?s.__directives?.[i]:s.__directive,a=re(t)?void 0:t._$litDirective$;if(r?.constructor!==a){if(r?._$notifyDirectiveConnectionChanged?.(!1),a===void 0)r=void 0;else r=new a(e),r._$initialize(e,s,i);if(i!==void 0)(s.__directives??=[])[i]=r;else s.__directive=r}if(r!==void 0)t=q(e,r._$resolve(e,t.values),r,i);return t}class Fe{constructor(e,t){this._$parts=[],this._$disconnectableChildren=void 0,this._$template=e,this._$parent=t}get parentNode(){return this._$parent.parentNode}get _$isConnected(){return this._$parent._$isConnected}_clone(e){let{el:{content:t},parts:s}=this._$template,i=(e?.creationScope??W).importNode(t,!0);F.currentNode=i;let r=F.nextNode(),a=0,l=0,d=s[0];while(d!==void 0){if(a===d.index){let h;if(d.type===fe)h=new X(r,r.nextSibling,this,e);else if(d.type===Ve)h=new d.ctor(r,d.name,d.strings,this,e);else if(d.type===Ue)h=new qe(r,this,e);this._$parts.push(h),d=s[++l]}if(a!==d?.index)r=F.nextNode(),a++}return F.currentNode=W,i}_update(e){let t=0;for(let s of this._$parts){if(s!==void 0)if(g&&g({kind:"set part",part:s,value:e[t],valueIndex:t,values:e,templateInstance:this}),s.strings!==void 0)s._$setValue(e,s,t),t+=s.strings.length-2;else s._$setValue(e[t]);t++}}}class X{get _$isConnected(){return this._$parent?._$isConnected??this.__isConnected}constructor(e,t,s,i){this.type=fe,this._$committedValue=o,this._$disconnectableChildren=void 0,this._$startNode=e,this._$endNode=t,this._$parent=s,this.options=i,this.__isConnected=i?.isConnected??!0,this._textSanitizer=void 0}get parentNode(){let e=D(this._$startNode).parentNode,t=this._$parent;if(t!==void 0&&e?.nodeType===11)e=t.parentNode;return e}get startNode(){return this._$startNode}get endNode(){return this._$endNode}_$setValue(e,t=this){if(this.parentNode===null)throw Error("This `ChildPart` has no `parentNode` and therefore cannot accept a value. This likely means the element containing the part was manipulated in an unsupported way outside of Lit's control such that the part's marker nodes were ejected from DOM. For example, setting the element's `innerHTML` or `textContent` can do this.");if(e=q(this,e,t),re(e)){if(e===o||e==null||e===""){if(this._$committedValue!==o)g&&g({kind:"commit nothing to child",start:this._$startNode,end:this._$endNode,parent:this._$parent,options:this.options}),this._$clear();this._$committedValue=o}else if(e!==this._$committedValue&&e!==z)this._commitText(e)}else if(e._$litType$!==void 0)this._commitTemplateResult(e);else if(e.nodeType!==void 0){if(this.options?.host===e){this._commitText("[probable mistake: rendered a template's host in itself (commonly caused by writing ${this} in a template]"),console.warn("Attempted to render the template host",e,"inside itself. This is almost always a mistake, and in dev mode ","we render some warning text. In production however, we'll ","render it, which will usually result in an error, and sometimes ","in the element disappearing from the DOM.");return}this._commitNode(e)}else if(wt(e))this._commitIterable(e);else this._commitText(e)}_insert(e){return D(D(this._$startNode).parentNode).insertBefore(e,this._$endNode)}_commitNode(e){if(this._$committedValue!==e){if(this._$clear(),K!==ve){let t=this._$startNode.parentNode?.nodeName;if(t==="STYLE"||t==="SCRIPT"){let s="Forbidden";if(t==="STYLE")s="Lit does not support binding inside style nodes. This is a security risk, as style injection attacks can exfiltrate data and spoof UIs. Consider instead using css`...` literals to compose styles, and do dynamic styling with css custom properties, ::parts, <slot>s, and by mutating the DOM rather than stylesheets.";else s="Lit does not support binding inside script nodes. This is a security risk, as it could allow arbitrary code execution.";throw Error(s)}}g&&g({kind:"commit node",start:this._$startNode,parent:this._$parent,value:e,options:this.options}),this._$committedValue=this._insert(e)}}_commitText(e){if(this._$committedValue!==o&&re(this._$committedValue)){let t=D(this._$startNode).nextSibling;if(this._textSanitizer===void 0)this._textSanitizer=Oe(t,"data","property");e=this._textSanitizer(e),g&&g({kind:"commit text",node:t,value:e,options:this.options}),t.data=e}else{let t=W.createTextNode("");if(this._commitNode(t),this._textSanitizer===void 0)this._textSanitizer=Oe(t,"data","property");e=this._textSanitizer(e),g&&g({kind:"commit text",node:t,value:e,options:this.options}),t.data=e}this._$committedValue=e}_commitTemplateResult(e){let{values:t,["_$litType$"]:s}=e,i=typeof s==="number"?this._$getTemplate(e):(s.el===void 0&&(s.el=ae.createElement(Et(s.h,s.h[0]),this.options)),s);if(this._$committedValue?._$template===i)g&&g({kind:"template updating",template:i,instance:this._$committedValue,parts:this._$committedValue._$parts,options:this.options,values:t}),this._$committedValue._update(t);else{let r=new Fe(i,this),a=r._clone(this.options);g&&g({kind:"template instantiated",template:i,instance:r,parts:r._$parts,options:this.options,fragment:a,values:t}),r._update(t),g&&g({kind:"template instantiated and updated",template:i,instance:r,parts:r._$parts,options:this.options,fragment:a,values:t}),this._commitNode(a),this._$committedValue=r}}_$getTemplate(e){let t=yt.get(e.strings);if(t===void 0)yt.set(e.strings,t=new ae(e));return t}_commitIterable(e){if(!je(this._$committedValue))this._$committedValue=[],this._$clear();let t=this._$committedValue,s=0,i;for(let r of e){if(s===t.length)t.push(i=new X(this._insert(ne()),this._insert(ne()),this,this.options));else i=t[s];i._$setValue(r),s++}if(s<t.length)this._$clear(i&&D(i._$endNode).nextSibling,s),t.length=s}_$clear(e=D(this._$startNode).nextSibling,t){this._$notifyConnectionChanged?.(!1,!0,t);while(e!==this._$endNode){let s=D(e).nextSibling;D(e).remove(),e=s}}setConnected(e){if(this._$parent===void 0)this.__isConnected=e,this._$notifyConnectionChanged?.(e);else throw Error("part.setConnected() may only be called on a RootPart returned from render().")}}class J{get tagName(){return this.element.tagName}get _$isConnected(){return this._$parent._$isConnected}constructor(e,t,s,i,r){if(this.type=Ve,this._$committedValue=o,this._$disconnectableChildren=void 0,this.element=e,this.name=t,this._$parent=i,this.options=r,s.length>2||s[0]!==""||s[1]!=="")this._$committedValue=Array(s.length-1).fill(new String),this.strings=s;else this._$committedValue=o;this._sanitizer=void 0}_$setValue(e,t=this,s,i){let r=this.strings,a=!1;if(r===void 0){if(e=q(this,e,t,0),a=!re(e)||e!==this._$committedValue&&e!==z,a)this._$committedValue=e}else{let l=e;e=r[0];let d,h;for(d=0;d<r.length-1;d++){if(h=q(this,l[s+d],t,d),h===z)h=this._$committedValue[d];if(a||=!re(h)||h!==this._$committedValue[d],h===o)e=o;else if(e!==o)e+=(h??"")+r[d+1];this._$committedValue[d]=h}}if(a&&!i)this._commitValue(e)}_commitValue(e){if(e===o)D(this.element).removeAttribute(this.name);else{if(this._sanitizer===void 0)this._sanitizer=K(this.element,this.name,"attribute");e=this._sanitizer(e??""),g&&g({kind:"commit attribute",element:this.element,name:this.name,value:e,options:this.options}),D(this.element).setAttribute(this.name,e??"")}}}class We extends J{constructor(){super(...arguments);this.type=Ps}_commitValue(e){if(this._sanitizer===void 0)this._sanitizer=K(this.element,this.name,"property");e=this._sanitizer(e),g&&g({kind:"commit property",element:this.element,name:this.name,value:e,options:this.options}),this.element[this.name]=e===o?void 0:e}}class ze extends J{constructor(){super(...arguments);this.type=Cs}_commitValue(e){g&&g({kind:"commit boolean attribute",element:this.element,name:this.name,value:!!(e&&e!==o),options:this.options}),D(this.element).toggleAttribute(this.name,!!e&&e!==o)}}class Ke extends J{constructor(e,t,s,i,r){super(e,t,s,i,r);if(this.type=Rs,this.strings!==void 0)throw Error(`A \`<${e.localName}>\` has a \`@${t}=...\` listener with invalid content. Event listeners in templates must have exactly one expression and no surrounding text.`)}_$setValue(e,t=this){if(e=q(this,e,t,0)??o,e===z)return;let s=this._$committedValue,i=e===o&&s!==o||e.capture!==s.capture||e.once!==s.once||e.passive!==s.passive,r=e!==o&&(s===o||i);if(g&&g({kind:"commit event listener",element:this.element,name:this.name,value:e,options:this.options,removeListener:i,addListener:r,oldListener:s}),i)this.element.removeEventListener(this.name,this,s);if(r)this.element.addEventListener(this.name,this,e);this._$committedValue=e}handleEvent(e){if(typeof this._$committedValue==="function")this._$committedValue.call(this.options?.host??this.element,e);else this._$committedValue.handleEvent(e)}}class qe{constructor(e,t,s){this.element=e,this.type=Ue,this._$disconnectableChildren=void 0,this._$parent=t,this.options=s}get _$isConnected(){return this._$parent._$isConnected}_$setValue(e){g&&g({kind:"commit to element binding",element:this.element,value:e,options:this.options}),q(this,e)}}var Tt={_boundAttributeSuffix:Ie,_marker:H,_markerMatch:He,_HTML_RESULT:kt,_getTemplateHtml:St,_TemplateInstance:Fe,_isIterable:wt,_resolveDirective:q,_ChildPart:X,_AttributePart:J,_BooleanAttributePart:ze,_EventPart:Ke,_PropertyPart:We,_ElementPart:qe},Ds=C.litHtmlPolyfillSupportDevMode;Ds?.(ae,X);(C.litHtmlVersions??=[]).push("3.3.3");if(C.litHtmlVersions.length>1)queueMicrotask(()=>{ie("multiple-versions","Multiple versions of Lit loaded. Loading multiple versions is not recommended.")});var se=(e,t,s)=>{if(t==null)throw TypeError(`The container to render into may not be ${t}`);let i=bs++,r=s?.renderBefore??t,a=r._$litPart$;if(g&&g({kind:"begin render",id:i,value:e,container:t,options:s,part:a}),a===void 0){let l=s?.renderBefore??null;r._$litPart$=a=new X(t.insertBefore(ne(),l),l,void 0,s??{})}return a._$setValue(e),g&&g({kind:"end render",id:i,value:e,container:t,options:s,part:a}),a};se.setSanitizer=ys,se.createSanitizer=Oe,se._testOnlyClearSanitizerFactoryDoNotCallOrElse=ws;var Ls=(e,t)=>e,Ge=!0,V=globalThis,xt;if(Ge)V.litIssuedWarnings??=new Set,xt=(e,t)=>{if(t+=` See https://lit.dev/msg/${e} for more information.`,!V.litIssuedWarnings.has(t)&&!V.litIssuedWarnings.has(e))console.warn(t),V.litIssuedWarnings.add(t)};class v extends P{constructor(){super(...arguments);this.renderOptions={host:this},this.__childPart=void 0}createRenderRoot(){let e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){let t=this.render();if(!this.hasUpdated)this.renderOptions.isConnected=this.isConnected;super.update(e),this.__childPart=se(t,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this.__childPart?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this.__childPart?.setConnected(!1)}render(){return z}}v._$litElement$=!0;v[Ls("finalized",v)]=!0;V.litElementHydrateSupport?.({LitElement:v});var As=Ge?V.litElementPolyfillSupportDevMode:V.litElementPolyfillSupport;As?.({LitElement:v});(V.litElementVersions??=[]).push("4.2.2");if(Ge&&V.litElementVersions.length>1)queueMicrotask(()=>{xt("multiple-versions","Multiple versions of Lit loaded. Loading multiple versions is not recommended.")});async function k(e){let t=await fetch(e,{headers:{Accept:"application/json"}});if(!t.ok)throw Error(`${t.status} ${await t.text()}`);return await t.json()}var L=encodeURIComponent;async function Q(e,t,s){let i=await fetch(t,{method:e,headers:{"Content-Type":"application/json"},body:s===void 0?null:JSON.stringify(s)});if(!i.ok)throw Error(await i.text());return await i.json()}var u={projects:()=>k("/api/projects"),tasks:(e)=>k(`/api/tasks?repo=${L(e)}`),running:()=>k("/api/running"),inbox:(e="")=>k(`/api/inbox?repo=${L(e)}`),pr:async(e)=>{let t=await fetch(`/api/pr?id=${e}`);if(t.status===204)return null;if(!t.ok)throw Error(`GitHub: ${await t.text()}`);return await t.json()},usage:()=>k("/api/usage"),agents:()=>k("/api/agents"),plan:(e)=>k(`/api/plan?repo=${L(e)}`),planSay:(e,t)=>Q("POST","/api/plan/message",{repo:e,message:t}),planPreview:(e,t)=>Q("POST","/api/plan/preview",{repo:e,name:t}),planImport:(e,t)=>Q("POST","/api/plan/import",{repo:e,name:t}),planClear:async(e)=>{let t=await fetch("/api/plan/clear",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({repo:e})});if(!t.ok)throw Error(await t.text())},createTask:(e)=>Q("POST","/api/tasks/new",e),setup:()=>k("/api/setup"),loginState:()=>k("/api/setup/login"),login:()=>Q("POST","/api/setup/login"),setupRepos:()=>k("/api/setup/repos"),owners:()=>k("/api/setup/owners"),dirs:(e="")=>k(`/api/setup/dirs?path=${L(e)}`),addProject:(e)=>Q("POST","/api/projects/add",e),stats:(e)=>k(`/api/stats?days=${e}`),day:(e,t,s="")=>k(`/api/day?from=${L(e.toISOString())}&to=${L(t.toISOString())}&repo=${L(s)}`),task:(e)=>k(`/api/task?id=${e}`),config:(e)=>k(`/api/config?repo=${L(e)}`),async saveConfig(e,t,s){let i=await fetch("/api/config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({repo:e,text:t,version:s})});if(!i.ok)throw Error(await i.text());return await i.json()},chat:(e)=>k(`/api/chat?repo=${L(e)}`),async send(e,t){let s=await fetch("/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({repo:e,message:t})});if(!s.ok)throw Error(`${s.status} ${await s.text()}`);return await s.json()},events:(e)=>new EventSource(`/api/events?repo=${L(e)}`),output:(e)=>new EventSource(`/api/output?id=${e}`),logs:()=>new EventSource("/api/logs"),activity:(e)=>new EventSource(`/api/activity?repo=${L(e)}`)};var Z=["new","routed","in_progress","needs_review","in_review","approved","done"],Ye=["blocked","waiting"],Pt=[...Ye,...Z],Ns={new:"New",routed:"Routed",in_progress:"In progress",needs_review:"Needs review",in_review:"In review",approved:"Approved",done:"Done",blocked:"Blocked",waiting:"Waiting"};function b(e){return Ns[e]??e}function Xe(e){if(!e)return Number.NaN;let t=e.includes("T")?e:e.replace(" ","T");return Date.parse(/[zZ]|[+-]\d\d:?\d\d$/u.test(t)?t:`${t}Z`)}function j(e){let t=Xe(e);if(Number.isNaN(t))return"";let s=Math.max(0,(Date.now()-t)/1000);if(s<60)return"now";if(s<3600)return`${Math.floor(s/60)}m`;if(s<86400)return`${Math.floor(s/3600)}h`;return`${Math.floor(s/86400)}d`}function A(e){let t=Xe(e);if(Number.isNaN(t))return e;return new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}var Os=new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*[A-Za-z]`,"gu");function be(e){return e.replace(Os,"")}function oe(e){return(e.split("/").pop()??e).slice(0,2).toUpperCase()}function N(e){return Xe(e)}function E(e){if(!Number.isFinite(e)||e<0)return"";if(e<60)return`${Math.round(e)}s`;if(e<3600)return`${Math.round(e/60)}m`;if(e<86400){let i=Math.floor(e/3600),r=Math.round(e%3600/60);return r?`${i}h ${r}m`:`${i}h`}let t=Math.floor(e/86400),s=Math.round(e%86400/3600);return s?`${t}d ${s}h`:`${t}d`}function $e(e,t){if(e.length===0)return Number.NaN;let s=Math.min(e.length-1,Math.floor(t*e.length));return e[s]??Number.NaN}function le(e,t){return t?`${Math.round(e/t*100)}%`:"–"}var ye="orch:close-add",we="orch:added";class Ct extends v{static properties={mode:{type:String},repos:{state:!0},owners:{state:!0},filter:{state:!0},picked:{state:!0},path:{state:!0},owner:{state:!0},name:{state:!0},description:{state:!0},isPrivate:{state:!0},browsing:{state:!0},dirs:{state:!0},saving:{state:!0},error:{state:!0}};constructor(){super();this.mode="clone",this.repos=null,this.owners=[],this.filter="",this.picked=null,this.path="",this.owner="",this.name="",this.description="",this.isPrivate=!0,this.browsing=!1,this.dirs=null,this.saving=!1,this.error=""}createRenderRoot(){return this}updated(e){if(e.has("mode"))this.error="",this.browsing=!1,this.load()}async load(){try{if(this.mode==="clone"&&!this.repos)this.repos=await u.setupRepos();if(this.mode==="create"&&this.owners.length===0)this.owners=await u.owners(),this.owner=this.owners[0]??""}catch(e){this.error=e instanceof Error?e.message:String(e)}}close(){window.dispatchEvent(new Event(ye))}request(){switch(this.mode){case"clone":return this.picked?{kind:"clone",repo:this.picked.repo,path:this.path}:null;case"existing":return this.path.trim()?{kind:"existing",path:this.path}:null;case"create":return this.owner&&this.name.trim()?{kind:"create",owner:this.owner,name:this.name.trim(),description:this.description,private:this.isPrivate}:null}}async submit(){let e=this.request();if(!e||this.saving)return;this.saving=!0,this.error="";try{let t=await u.addProject(e);window.dispatchEvent(new CustomEvent(we,{detail:t.repo}))}catch(t){this.error=t instanceof Error?t.message:String(t)}this.saving=!1}async browse(e=""){this.browsing=!0;try{this.dirs=await u.dirs(e||this.path)}catch{this.dirs=await u.dirs("")}}pick(e){this.picked=e,this.path=e.checkout??""}renderClone(){let e=this.filter.trim().toLowerCase(),t=(this.repos?.github??[]).filter((i)=>!e||i.repo.toLowerCase().includes(e)),s=[...new Set(t.map((i)=>i.repo.split("/")[0]))];return n`
<input class="filter" placeholder="Filter your repositories" .value=${this.filter}
@input=${(i)=>{this.filter=i.target.value}} />
<div class="repo-list">
${this.repos?t.length>0?s.map((i)=>n`<div class="repo-owner muted">${i}</div>
${t.filter((r)=>r.repo.startsWith(`${i}/`)).map((r)=>n`<button class="repo-row ${this.picked?.repo===r.repo?"on":""}" ?disabled=${r.added}
@click=${()=>this.pick(r)} @dblclick=${()=>void this.submit()}>
<span class="repo-name">${r.repo.split("/")[1]}</span>
${r.private?n`<span class="chip">private</span>`:o}
${r.added?n`<span class="chip chip-ok">added</span>`:r.checkout?n`<span class="chip" title=${r.checkout}>on this computer</span>`:o}
<span class="topbar-spacer"></span>
<span class="muted">${r.pushed_at?j(r.pushed_at):""}</span>
</button>`)}`):n`<p class="block-empty">No repository matches.</p>`:n`<p class="block-empty">Loading your repositories…</p>`}
</div>
${this.renderPath("Local path","Leave empty and orch keeps its own copy")}
`}renderPath(e,t){return n`
<label class="field-label">${e}</label>
<div class="path-row">
<input class="filter" placeholder=${t} .value=${this.path}
@input=${(s)=>{this.path=s.target.value}} />
<button class="tool" @click=${()=>void this.browse()}>Choose…</button>
</div>
${this.browsing?this.renderBrowser():o}
`}renderBrowser(){let e=this.dirs;if(!e)return n`<div class="browser"><p class="block-empty">Loading…</p></div>`;return n`<div class="browser">
<div class="browser-head">
<button class="icon" title="Up" ?disabled=${!e.parent} @click=${()=>void this.browse(e.parent??"")}>↑</button>
<span class="mono browser-path" title=${e.path}>${e.path}</span>
<span class="topbar-spacer"></span>
<button class="tool primary" @click=${()=>{this.path=e.path,this.browsing=!1}}>Use this folder</button>
</div>
<div class="browser-list">
${e.dirs.map((t)=>n`<button class="browser-row" @click=${()=>void this.browse(t.path)}>
<span>📁</span><span>${t.name}</span>
${t.repo?n`<span class="chip">${t.repo}</span>`:o}
</button>`)}
${e.dirs.length>0?o:n`<p class="block-empty">No folders here.</p>`}
</div>
</div>`}renderCreate(){return n`
<label class="field-label">Owner</label>
<select class="filter" .value=${this.owner} @change=${(e)=>{this.owner=e.target.value}}>
${this.owners.map((e)=>n`<option value=${e} ?selected=${e===this.owner}>${e}</option>`)}
</select>
<label class="field-label">Name</label>
<input class="filter" placeholder="my-app" .value=${this.name} @input=${(e)=>{this.name=e.target.value.replace(/\s+/gu,"-")}} />
<label class="field-label">Description</label>
<input class="filter" placeholder="Optional" .value=${this.description} @input=${(e)=>{this.description=e.target.value}} />
<label class="choice"><input type="checkbox" .checked=${this.isPrivate} @change=${(e)=>{this.isPrivate=e.target.checked}} /><span><b>Private</b><span class="muted">only you and people you add can see it</span></span></label>
<p class="muted">orch creates the repository on GitHub with a README and keeps its own copy. Then write a plan or add a first task.</p>
`}render(){let e={clone:["Clone a repository","Clone"],create:["Create a new repository","Create repository"],existing:["Add a local repository","Add repository"]},[t,s]=e[this.mode];return n`
<div class="scrim" @click=${()=>this.close()}></div>
<div class="dialog" role="dialog" aria-label=${t}>
<header class="dialog-head"><h2>${t}</h2><span class="topbar-spacer"></span>
<button class="icon" title="Close" @click=${()=>this.close()}>✕</button></header>
<div class="dialog-body">
${this.mode==="clone"?this.renderClone():o}
${this.mode==="create"?this.renderCreate():o}
${this.mode==="existing"?this.renderPath("Local path","A folder that is a git checkout of a GitHub repository"):o}
${this.error?n`<div class="task-error">${this.error}</div>`:o}
</div>
<footer class="dialog-foot">
<button class="tool" @click=${()=>this.close()}>Cancel</button>
<button class="tool primary" ?disabled=${!this.request()||this.saving} @click=${()=>void this.submit()}>
${this.saving?"Working…":s}
</button>
</footer>
</div>
`}}customElements.define("orch-add",Ct);var{_ChildPart:Ei}=Tt,Is=!0,Si=Is&&window.ShadyDOM?.inUse&&window.ShadyDOM?.noPatch===!0?window.ShadyDOM.wrap:(e)=>e;var Rt=(e)=>e.strings===void 0;var Mt={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},Dt=(e)=>(...t)=>({["_$litDirective$"]:e,values:t});class Je{constructor(e){}get _$isConnected(){return this._$parent._$isConnected}_$initialize(e,t,s){this.__part=e,this._$parent=t,this.__attributeIndex=s}_$resolve(e,t){return this.update(e,t)}update(e,t){return this.render(...t)}}var Hs=!0,de=(e,t)=>{let s=e._$disconnectableChildren;if(s===void 0)return!1;for(let i of s)i._$notifyDirectiveConnectionChanged?.(t,!1),de(i,t);return!0},_e=(e)=>{let t,s;do{if((t=e._$parent)===void 0)break;s=t._$disconnectableChildren,s.delete(e),e=t}while(s?.size===0)},Lt=(e)=>{for(let t;t=e._$parent;e=t){let s=t._$disconnectableChildren;if(s===void 0)t._$disconnectableChildren=s=new Set;else if(s.has(e))break;s.add(e),Us(t)}};function js(e){if(this._$disconnectableChildren!==void 0)_e(this),this._$parent=e,Lt(this);else this._$parent=e}function Vs(e,t=!1,s=0){let i=this._$committedValue,r=this._$disconnectableChildren;if(r===void 0||r.size===0)return;if(t){if(Array.isArray(i))for(let a=s;a<i.length;a++)de(i[a],!1),_e(i[a]);else if(i!=null)de(i,!1),_e(i)}else de(this,e)}var Us=(e)=>{if(e.type==Mt.CHILD)e._$notifyConnectionChanged??=Vs,e._$reparentDisconnectables??=js};class Qe extends Je{constructor(){super(...arguments);this._$disconnectableChildren=void 0}_$initialize(e,t,s){super._$initialize(e,t,s),Lt(this),this.isConnected=e._$isConnected}["_$notifyDirectiveConnectionChanged"](e,t=!0){if(e!==this.isConnected)if(this.isConnected=e,e)this.reconnected?.();else this.disconnected?.();if(t)de(this,e),_e(this)}setValue(e){if(Rt(this.__part))this.__part._$setValue(e,this);else{if(Hs&&this.__attributeIndex===void 0)throw Error("Expected this.__attributeIndex to be a number");let t=[...this.__part._$committedValue];t[this.__attributeIndex]=e,this.__part._$setValue(t,this,0)}}disconnected(){}reconnected(){}}var Ze=new WeakMap;class At extends Qe{render(e){return o}update(e,[t]){let s=t!==this._ref;if(s)this._updateRefValue(void 0);if(s||this._lastElementForRef!==this._element)this._ref=t,this._context=e.options?.host,this._updateRefValue(this._element=e.element);return o}_updateRefValue(e){if(this._ref===void 0)return;if(!this.isConnected)e=void 0;if(typeof this._ref==="function"){let t=this._context??globalThis,s=Ze.get(t);if(s===void 0)s=new WeakMap,Ze.set(t,s);if(s.get(this._ref)!==void 0)this._ref.call(this._context,void 0);if(s.set(this._ref,e),e!==void 0)this._ref.call(this._context,e)}else this._ref.value=e}get _lastElementForRef(){return typeof this._ref==="function"?Ze.get(this._context??globalThis)?.get(this._ref):this._ref?.value}disconnected(){if(this._lastElementForRef===this._element)this._updateRefValue(void 0)}reconnected(){this._updateRefValue(this._element)}}var Nt=Dt(At);var ce="orch:refresh";function T(e){return e.split("/")[1]??e}function et(e){return`#/${e.repo}/${e.id}`}function ee(e){return e.number?`#${e.number}`:`T-${e.id}`}function Ot(e){return e.status==="in_progress"||e.status==="in_review"}function B(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function pe(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t)}function ke(e){let t=(r)=>e.find(([a])=>a===r)?.[1]??0,s=["blocked",...Z.filter((r)=>r!=="done")];if(!s.reduce((r,a)=>r+t(a),0))return n`<div class="stagebar stagebar-empty"></div>`;return n`<div class="stagebar" title=${s.filter((r)=>t(r)).map((r)=>`${b(r)} ${t(r)}`).join(" · ")}>
${s.filter((r)=>t(r)).map((r)=>n`<span class="seg-${r}" ${I({flex:String(t(r))})}></span>`)}
</div>`}function It(e){let t=(i)=>e.find(([r])=>r===i)?.[1]??0,s=["blocked",...Z];return n`<div class="legend">
${s.filter((i)=>t(i)).map((i)=>n`<span><span class="dot dot-${i}"></span>${t(i)} ${b(i).toLowerCase()}</span>`)}
</div>`}function O(e,t={}){let s=e.block_reason||e.last_error;return n`
<a class="tline" href=${et(e)}>
<span class="dot dot-${e.status}" title=${b(e.status)}></span>
${t.repo?n`<span class="tline-repo muted">${T(e.repo)}</span>`:o}
<span class="tline-ref mono muted">${ee(e)}</span>
<span class="tline-main">
<span class="tline-title">${e.title}</span>
${t.reason&&s?n`<span class="tline-reason">${s}</span>`:o}
</span>
${e.agent?n`<span class="chip">${e.agent}</span>`:o}
${e.pr_number?n`<span class="chip chip-pr">PR #${e.pr_number}</span>`:o}
<span class="tline-time muted" title=${A(t.at??e.updated_at)}>${j(t.at??e.updated_at)}</span>
</a>
`}var Ee="orch:menu";function y(){return n`<button class="icon menu-btn" title="Menu" @click=${()=>window.dispatchEvent(new Event(Ee))}>☰</button>`}function I(e){return Nt((t)=>{if(t instanceof HTMLElement)for(let[s,i]of Object.entries(e))t.style.setProperty(s,i)})}class w extends v{static properties={error:{state:!0},loaded:{state:!0}};constructor(){super();this.onRefresh=()=>{this.reload()};this.error="",this.loaded=!1}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),window.addEventListener(ce,this.onRefresh),this.reload()}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener(ce,this.onRefresh)}async reload(){try{await this.load(),this.error=""}catch(e){this.error=e instanceof Error?e.message:String(e)}this.loaded=!0}}var Se="orch:open-add";function G(e){window.dispatchEvent(new CustomEvent(Se,{detail:e}))}var Bs={claude:"Run claude in a terminal and type /login",codex:"Run codex login",opencode:"Run opencode auth login",grok:"Run grok in a terminal and log in"};class Ht extends w{static properties={...w.properties,setup:{state:!0},login:{state:!0},copied:{state:!0}};constructor(){super();this.poll=0;this.setup=null,this.login=null,this.copied=!1}disconnectedCallback(){super.disconnectedCallback(),window.clearInterval(this.poll)}async load(){this.setup=await u.setup()}async signIn(){try{this.login=await u.login()}catch(e){this.error=e instanceof Error?e.message:String(e);return}window.clearInterval(this.poll),this.poll=window.setInterval(()=>void this.checkLogin(),2000)}async checkLogin(){if(this.login=await u.loginState(),this.login.state!=="waiting")window.clearInterval(this.poll),await this.reload()}async copyAndOpen(){if(this.login?.code)await navigator.clipboard.writeText(this.login.code).catch(()=>{return}),this.copied=!0;window.open(this.login?.url??"https://github.com/login/device","_blank","noopener")}renderGitHub(e){if(e.gh==="ready")return n`<div class="step-row"><span class="check-mark is-ok">✓</span>
<span>Signed in to GitHub${e.login?n` as <b>${e.login}</b>`:o}</span></div>`;if(e.gh==="missing")return n`<div class="step-row"><span class="check-mark is-bad">✕</span>
<span>orch talks to GitHub through the GitHub CLI, and it is not installed. Install it, then check again:
<code class="copy-line">brew install gh</code></span></div>`;let t=this.login;if(t?.state==="waiting"&&t.code)return n`<div class="device">
<p>Enter this code on GitHub to sign in:</p>
<div class="device-code mono">${t.code}</div>
<button class="tool primary" @click=${()=>void this.copyAndOpen()}>${this.copied?"Copied · open GitHub again":"Copy code and open GitHub"}</button>
<p class="muted">This page moves on by itself once GitHub confirms.</p>
</div>`;return n`<div class="step-row"><span class="check-mark is-wait">…</span>
<span>orch needs GitHub to read issues and open pull requests.</span>
<span class="topbar-spacer"></span>
<button class="tool primary" ?disabled=${t?.state==="waiting"} @click=${()=>void this.signIn()}>
${t?.state==="waiting"?"Starting…":"Sign in with GitHub"}
</button>
</div>
${t?.state==="failed"?n`<div class="task-error">${t.error??"Sign-in failed, try again"}</div>`:o}`}render(){let e=this.setup,t=e?.agents.filter(([,s])=>s==="ready")??[];return n`
<header class="pane-head">${y()}<h1>Welcome to orch</h1></header>
<div class="page welcome">
<p class="welcome-lede">Write the plan, orch builds it. Three steps and the first agent can start.</p>
${this.error?n`<div class="error-bar">${this.error}</div>`:o}
${e?n`
<section class="block onboard ${e.gh==="ready"?"done":""}">
<header class="block-head"><span class="onboard-n">1</span><h2>GitHub</h2></header>
${this.renderGitHub(e)}
</section>
<section class="block onboard ${t.length>0?"done":""}">
<header class="block-head"><span class="onboard-n">2</span><h2>Coding agents</h2>
<span class="topbar-spacer"></span><button class="tool" @click=${()=>void this.reload()}>Check again</button></header>
<p class="block-note muted">orch runs the agent CLIs you already use. One logged-in agent is enough.</p>
${e.agents.map(([s,i])=>n`<div class="step-row">
<span class="check-mark ${i==="ready"?"is-ok":"is-wait"}">${i==="ready"?"✓":"…"}</span>
<b class="agent-name">${s}</b>
<span class="muted">${i==="ready"?"ready":i==="missing"?"not installed":Bs[s]??`Log in to ${s}`}</span>
</div>`)}
</section>
<section class="block onboard">
<header class="block-head"><span class="onboard-n">3</span><h2>Add a project</h2></header>
<p class="block-note muted">A project is a GitHub repository. orch works on its issues in worktrees of its own, so a copy on this computer is optional.</p>
<div class="add-options">
<button class="add-option" ?disabled=${e.gh!=="ready"} @click=${()=>G("clone")}>
<b>Clone a repository</b><span class="muted">Pick one of your GitHub repositories</span></button>
<button class="add-option" ?disabled=${e.gh!=="ready"} @click=${()=>G("create")}>
<b>Create a new repository</b><span class="muted">Start from an empty repo and a plan</span></button>
<button class="add-option" @click=${()=>G("existing")}>
<b>Add an existing repository</b><span class="muted">A checkout already on this computer</span></button>
<button class="add-option" disabled title="Comes with multi-node">
<b>Watch only</b><span class="muted">Follow a project another machine runs. Comes with multi-node</span></button>
</div>
</section>
`:n`<p class="block-empty">Checking GitHub and your agents…</p>`}
</div>
`}}customElements.define("orch-welcome",Ht);var Fs=8;class jt extends v{static properties={repo:{type:String},agents:{state:!0},tasks:{state:!0},title:{state:!0},body:{state:!0},agent:{state:!0},deps:{state:!0},search:{state:!0},saving:{state:!0},error:{state:!0}};constructor(){super();this.repo="",this.agents=[],this.tasks=[],this.title="",this.body="",this.agent="router",this.deps=[],this.search="",this.saving=!1,this.error=""}createRenderRoot(){return this}updated(e){if(e.has("repo")&&this.repo)this.load()}firstUpdated(){this.querySelector(".compose-title")?.focus()}async load(){try{[this.agents,this.tasks]=await Promise.all([u.agents(),u.tasks(this.repo)])}catch(e){this.error=e instanceof Error?e.message:String(e)}}found(){let e=this.search.trim().toLowerCase().replace(/^#/u,"");if(!e)return[];let t=new Set(this.deps.map((s)=>s.id));return this.tasks.filter((s)=>!t.has(s.id)).filter((s)=>s.title.toLowerCase().includes(e)||(s.number??"").startsWith(e)||String(s.id)===e).sort((s,i)=>Number(s.status==="done")-Number(i.status==="done")).slice(0,Fs)}addDep(e){this.deps=[...this.deps,e],this.search="",this.querySelector(".dep-search")?.focus()}cancel(){location.hash=`#/${this.repo}`}async submit(){if(!this.title.trim()||this.saving)return;this.saving=!0,this.error="";try{let e=await u.createTask({repo:this.repo,title:this.title.trim(),body:this.body,agent:this.agent==="router"?null:this.agent,depends_on:this.deps.map((t)=>t.id)});location.hash=`#/${this.repo}/${e.id}`}catch(e){this.error=e instanceof Error?e.message:String(e),this.saving=!1}}onKey(e){if(e.key==="Enter"&&(e.metaKey||e.ctrlKey))e.preventDefault(),this.submit()}render(){let e=this.found(),t=this.deps.some((s)=>s.status!=="done");return n`
<header class="pane-head">${y()}<h1>New task</h1>
<span class="muted">in ${T(this.repo)}</span></header>
<div class="page compose" @keydown=${(s)=>this.onKey(s)}>
<div class="compose-main">
<input class="compose-title" placeholder="Title" .value=${this.title}
@input=${(s)=>{this.title=s.target.value}} />
<textarea class="compose-body" placeholder="What should happen, and how will you know it is done? Markdown works, as on GitHub."
.value=${this.body}
@input=${(s)=>{this.body=s.target.value}}></textarea>
${this.error?n`<div class="task-error">${this.error}</div>`:o}
<div class="compose-actions">
<span class="muted">⌘Enter to create</span>
<span class="topbar-spacer"></span>
<button class="tool" @click=${()=>this.cancel()}>Cancel</button>
<button class="tool primary" ?disabled=${!this.title.trim()||this.saving} @click=${()=>void this.submit()}>
${this.saving?"Creating…":"Create task"}
</button>
</div>
</div>
<aside class="compose-side">
<section>
<h3>Agent</h3>
<label class="choice"><input type="radio" name="agent" .checked=${this.agent==="router"} @change=${()=>{this.agent="router"}} /><span><b>Let the router pick</b><span class="muted">orch chooses the agent and the model</span></span></label>
${this.agents.map((s)=>n`<label class="choice"><input type="radio" name="agent" .checked=${this.agent===s} @change=${()=>{this.agent=s}} /><span><b>${s}</b><span class="muted">skips the router</span></span></label>`)}
<label class="choice"><input type="radio" name="agent" .checked=${this.agent==="none"} @change=${()=>{this.agent="none"}} /><span><b>No agent</b><span class="muted">waits for you, labelled <code>no-agent</code></span></span></label>
</section>
<section>
<h3>Depends on</h3>
${this.deps.map((s)=>n`<div class="dep">
<span class="dot dot-${s.status}" title=${b(s.status)}></span>
<span class="mono muted">${ee(s)}</span>
<span class="dep-title">${s.title}</span>
<button class="icon" title="Remove" @click=${()=>{this.deps=this.deps.filter((i)=>i.id!==s.id)}}>✕</button>
</div>`)}
<input class="filter dep-search" placeholder="Search by title or #number" .value=${this.search}
@input=${(s)=>{this.search=s.target.value}}
@keydown=${(s)=>{let i=e[0];if(s.key==="Enter"&&i)s.preventDefault(),this.addDep(i)}} />
${e.length>0?n`<div class="picker">${e.map((s)=>n`<button class="picker-row" @click=${()=>this.addDep(s)}>
<span class="dot dot-${s.status}"></span><span class="mono muted">${ee(s)}</span><span class="dep-title">${s.title}</span>
</button>`)}</div>`:o}
<p class="muted compose-note">${t?"This task waits until every task above is done.":"A task with an open dependency waits until that task is done."}</p>
</section>
</aside>
</div>
`}}customElements.define("orch-compose",jt);function Ws(e){let t=[],s=[],i=[],r=()=>{if(i.length>0)t.push(n`<p>${i.join(" ")}</p>`),i=[];if(s.length>0){let a=s;t.push(n`<ul>${a.map((l)=>n`<li>${l}</li>`)}</ul>`),s=[]}};for(let a of e.split(`
`)){let l=a.trimEnd(),d=/^(#{1,4})\s+(.*)$/u.exec(l),h=/^\s*[-*]\s+(.*)$/u.exec(l)??/^\s*\d+\.\s+(.*)$/u.exec(l);if(d){r();let c=(d[1]??"").length;t.push(c===1?n`<h1>${d[2]}</h1>`:c===2?n`<h2>${d[2]}</h2>`:n`<h3>${d[2]}</h3>`)}else if(h){if(i.length>0)r();s.push(h[1]??"")}else if(l.trim()){if(s.length>0)r();i.push(l.trim())}else r()}return r(),t}class Vt extends v{static properties={repo:{type:String},state:{state:!0},thinking:{state:!0},error:{state:!0},preview:{state:!0},previewing:{state:!0},importing:{state:!0},imported:{state:!0},name:{state:!0}};constructor(){super();this.draft="";this.repo="",this.state=null,this.thinking=!1,this.error="",this.preview=null,this.previewing=!1,this.importing=!1,this.imported="",this.name=""}createRenderRoot(){return this}updated(e){if(e.has("repo")&&this.repo)this.load()}async load(){try{this.state=await u.plan(this.repo),this.name=this.state.name,this.scrollLog()}catch(e){this.error=e instanceof Error?e.message:String(e)}}scrollLog(){this.updateComplete.then(()=>{let e=this.querySelector(".plan-log");if(e)e.scrollTop=e.scrollHeight})}async say(){let e=this.draft.trim();if(!e||this.thinking||!this.state)return;this.thinking=!0,this.error="",this.state={...this.state,messages:[...this.state.messages,{role:"user",content:e,created_at:""}]},this.draft="";let t=this.querySelector(".plan-input");if(t)t.value="";this.scrollLog();try{let s=await u.planSay(this.repo,e);this.state={...this.state,draft:s.draft,messages:[...this.state.messages,{role:"assistant",content:s.reply,created_at:""}]},this.preview=null}catch(s){this.error=s instanceof Error?s.message:String(s)}this.thinking=!1,this.scrollLog()}async showPreview(){this.previewing=!0,this.error="";try{this.preview=await u.planPreview(this.repo,this.name)}catch(e){this.error=e instanceof Error?e.message:String(e)}this.previewing=!1}async runImport(){this.importing=!0,this.error="";try{let e=await u.planImport(this.repo,this.name);this.imported=e.report,this.preview=null,await this.load()}catch(e){this.error=e instanceof Error?e.message:String(e)}this.importing=!1}async startOver(){if(!confirm("Start a new plan? The conversation and the draft go, imported issues stay."))return;await u.planClear(this.repo),this.imported="",this.preview=null,await this.load()}renderPreview(e){return n`
<div class="scrim" @click=${()=>{this.preview=null}}></div>
<div class="dialog dialog-wide" role="dialog" aria-label="Import the plan">
<header class="dialog-head"><h2>Import as tasks</h2><span class="topbar-spacer"></span>
<button class="icon" @click=${()=>{this.preview=null}}>✕</button></header>
<div class="dialog-body">
<p class="muted">orch commits the plan to <code>${e.path}</code> on the default branch, then creates one issue per task below. A task waits for the tasks it depends on.</p>
<pre class="code">${e.outline}</pre>
<pre class="code">${e.report}</pre>
</div>
<footer class="dialog-foot">
<button class="tool" @click=${()=>{this.preview=null}}>Cancel</button>
<button class="tool primary" ?disabled=${this.importing} @click=${()=>void this.runImport()}>
${this.importing?"Creating issues…":"Commit and create issues"}
</button>
</footer>
</div>
`}render(){let e=this.state;if(!e)return n`<div class="empty">${this.error||"Loading…"}</div>`;let t=e.draft.trim().length>0;return n`
<div class="plan">
<section class="plan-chat">
<div class="plan-log">
${e.messages.length>0?e.messages.map((s)=>n`<div class="msg msg-${s.role}">
<div class="msg-who">${s.role==="user"?"You":"Planner"}</div>
<div class="msg-text">${s.content}</div>
</div>`):n`<div class="plan-intro">
<h2>What should orch build?</h2>
<p class="muted">Describe the goal in a few sentences. The planner asks what it needs to know, writes the plan on the right, and changes it as you talk. When it looks right, import it and orch creates the tasks in order.</p>
</div>`}
${this.thinking?n`<div class="msg msg-assistant"><div class="msg-who">Planner</div><div class="msg-text muted">Thinking…</div></div>`:o}
</div>
${this.error?n`<div class="task-error">${this.error}</div>`:o}
<div class="chat-compose">
<textarea class="chat-input plan-input" rows="3" placeholder=${e.messages.length>0?"Answer, or ask for a change. ⌘Enter to send":"I want to build… ⌘Enter to send"}
@input=${(s)=>{this.draft=s.target.value}}
@keydown=${(s)=>{if(s.key==="Enter"&&(s.metaKey||s.ctrlKey))s.preventDefault(),this.say()}}></textarea>
<div class="compose-actions">
${e.messages.length>0?n`<button class="tool" @click=${()=>void this.startOver()}>Start over</button>`:o}
<span class="topbar-spacer"></span>
<button class="tool primary" ?disabled=${this.thinking} @click=${()=>void this.say()}>Send</button>
</div>
</div>
</section>
<section class="plan-draft">
<header class="plan-draft-head">
<h3>Plan</h3>
<span class="topbar-spacer"></span>
${t?n`<input class="filter plan-name" title="File name under docs/plans/" .value=${this.name}
@input=${(s)=>{this.name=s.target.value}} />
<button class="tool primary" ?disabled=${this.previewing||this.thinking} @click=${()=>void this.showPreview()}>
${this.previewing?"Drafting the tasks…":"Import as tasks"}
</button>`:o}
</header>
<div class="plan-doc">
${this.imported?n`<div class="imported"><b>Imported.</b><pre class="code">${this.imported}</pre></div>`:o}
${t?Ws(e.draft):n`<p class="block-empty">The plan appears here as the planner writes it.</p>`}
</div>
</section>
</div>
${this.preview?this.renderPreview(this.preview):o}
`}}customElements.define("orch-plan",Vt);class Ut extends v{static properties={repo:{type:String},file:{state:!0},text:{state:!0},saving:{state:!0},message:{state:!0},failed:{state:!0}};constructor(){super();this.repo="",this.file=null,this.text="",this.saving=!1,this.message="",this.failed=!1}createRenderRoot(){return this}updated(e){if(e.has("repo"))this.load()}async load(){this.message="";try{this.file=await u.config(this.repo),this.text=this.file.text}catch(e){this.failed=!0,this.message=e instanceof Error?e.message:String(e)}}async save(){if(!this.file)return;this.saving=!0;try{this.file=await u.saveConfig(this.repo,this.text,this.file.version),this.text=this.file.text,this.failed=!1,this.message="Saved. orch reloads the file on its own, the old copy is in ~/.orch/state/config-backups"}catch(e){this.failed=!0,this.message=e instanceof Error?e.message:String(e)}this.saving=!1}onKey(e){if(e.key==="s"&&(e.metaKey||e.ctrlKey))e.preventDefault(),this.save()}render(){if(!this.file)return n`<div class="empty">${this.message||"Loading…"}</div>`;let e=this.text!==this.file.text;return n`
<div class="config">
<div class="config-head">
<span class="mono muted config-path" title=${this.file.path}>${this.file.path}</span>
${e?n`<span class="chip">edited</span>`:o}
</div>
<textarea class="config-text" spellcheck="false" .value=${this.text}
@input=${(t)=>{this.text=t.target.value}}
@keydown=${(t)=>this.onKey(t)}></textarea>
<div class="config-actions">
<span class="config-message ${this.failed?"is-error":""}">${this.message}</span>
<button class="tool" ?disabled=${!e||this.saving} @click=${()=>{this.text=this.file?.text??"",this.message=""}}>Revert</button>
<button class="tool primary" ?disabled=${!e||this.saving} @click=${()=>void this.save()}>
${this.saving?"Saving…":"Save ⌘S"}
</button>
</div>
</div>
`}}customElements.define("orch-config",Ut);class Bt extends w{static properties={...w.properties,day:{state:!0},landed:{state:!0},blocked:{state:!0}};constructor(){super();this.day=B(new Date),this.landed=[],this.blocked=[]}async load(){let e=await u.day(this.day,pe(this.day,1));this.landed=e.landed,this.blocked=e.blocked}go(e){this.day=e===0?B(new Date):pe(this.day,e),this.loaded=!1,this.reload()}row(e){let t=e.card,s=(N(e.at)-N(t.created_at))/1000;return n`<div class="day-row">
${O(t,{at:e.at})}
<div class="day-row-meta muted">
${s>0?n`<span title="From the issue to the merge">${E(s)} to merge</span>`:o}
<span>${t.review_cycles?`${t.review_cycles} review ${t.review_cycles===1?"round":"rounds"}`:"approved on the first review"}</span>
${t.attempts>1?n`<span>${t.attempts} attempts</span>`:o}
${t.model?n`<span>${t.model}</span>`:o}
</div>
</div>`}render(){let e=this.day.getTime()===B(new Date).getTime(),t=new Map;for(let i of this.landed)t.set(i.card.repo,[...t.get(i.card.repo)??[],i]);let s=new Map;for(let i of this.landed){let r=i.card.agent??"no agent";s.set(r,(s.get(r)??0)+1)}return n`
<header class="pane-head">${y()}<h1>Day report</h1>
<span class="muted">${this.day.toLocaleDateString(void 0,{weekday:"long",month:"long",day:"numeric",year:"numeric"})}</span>
<span class="topbar-spacer"></span>
<div class="seg">
<button title="Previous day" @click=${()=>this.go(-1)}>←</button>
<button class=${e?"on":""} @click=${()=>this.go(0)}>Today</button>
<button title="Next day" ?disabled=${e} @click=${()=>this.go(1)}>→</button>
</div>
</header>
<div class="page">
${this.error?n`<div class="error-bar">${this.error}</div>`:o}
<div class="day-summary">
<span><b>${this.landed.length}</b> merged</span>
<span><b>${t.size}</b> ${t.size===1?"project":"projects"}</span>
<span><b>${this.blocked.length}</b> blocked</span>
${[...s].sort((i,r)=>r[1]-i[1]).map(([i,r])=>n`<span class="chip">${i} ${r}</span>`)}
</div>
${this.loaded?this.landed.length>0?[...t].map(([i,r])=>n`<section class="block">
<header class="block-head"><h2>${T(i)}</h2><span class="count">${r.length}</span></header>
${r.map((a)=>this.row(a))}
</section>`):n`<p class="block-empty">Nothing merged ${e?"yet today":"on this day"}.</p>`:n`<p class="block-empty">Loading…</p>`}
${this.blocked.length>0?n`<section class="block">
<header class="block-head"><span class="dot dot-blocked"></span><h2>Got stuck</h2><span class="count">${this.blocked.length}</span></header>
<p class="block-note muted">Tasks that blocked on this day. The ones still blocked are in the Inbox.</p>
${this.blocked.map((i)=>O(i.card,{repo:!0,reason:!0,at:i.at}))}
</section>`:o}
</div>
`}}customElements.define("orch-day",Bt);var Ft=6;function Te(e,t){return e.counts.find(([s])=>s===t)?.[1]??0}function Wt(e){return e.counts.filter(([t])=>t!=="done").reduce((t,[,s])=>t+s,0)}class zt extends w{static properties={...w.properties,projects:{state:!0},running:{state:!0},inbox:{state:!0},landed:{state:!0}};constructor(){super();this.projects=[],this.running=[],this.inbox={blocked:[],human:[]},this.landed=[]}async load(){let e=B(new Date);[this.projects,this.running,this.inbox,this.landed]=await Promise.all([u.projects(),u.running(),u.inbox(),u.day(e,pe(e,1)).then((t)=>t.landed)])}render(){let e=this.inbox.blocked.length+this.inbox.human.length,t=this.projects.reduce((s,i)=>s+Wt(i),0);return n`
<header class="pane-head">${y()}<h1>Home</h1>
<span class="muted">${new Date().toLocaleDateString(void 0,{weekday:"long",month:"long",day:"numeric"})}</span>
</header>
<div class="page">
${this.error?n`<div class="error-bar">${this.error}</div>`:o}
<div class="tiles">
<div class="tile">
<span class="tile-n ${this.running.length>0?"tile-working":""}">${this.running.length}</span>
<span class="tile-l">${this.running.length===1?"agent working":"agents working"}</span>
</div>
<a class="tile ${e?"tile-alert":""}" href="#/inbox">
<span class="tile-n">${e}</span>
<span class="tile-l">need you</span>
</a>
<a class="tile" href="#/day">
<span class="tile-n">${this.landed.length}</span>
<span class="tile-l">merged today</span>
</a>
<div class="tile">
<span class="tile-n">${t}</span>
<span class="tile-l">open tasks in ${this.projects.length} ${this.projects.length===1?"project":"projects"}</span>
</div>
</div>
<div class="home-grid">
<section class="block">
<header class="block-head"><h2>Working now</h2><span class="count">${this.running.length}</span></header>
${this.running.length>0?n`<div class="working-list">${this.running.map((s)=>this.renderWorking(s))}</div>`:n`<p class="block-empty">No agent is working. Tasks start as soon as an agent is free.</p>`}
</section>
<section class="block">
<header class="block-head"><h2>Needs you</h2><span class="count">${e}</span>
<span class="topbar-spacer"></span><a class="block-link" href="#/inbox">Inbox →</a></header>
${e?n`${[...this.inbox.blocked,...this.inbox.human].slice(0,Ft).map((s)=>O(s,{repo:!0,reason:!0,at:s.since??void 0}))}`:n`<p class="block-empty">Nothing waits on you.</p>`}
</section>
</div>
<section class="block">
<header class="block-head"><h2>Projects</h2><span class="count">${this.projects.length}</span></header>
<div class="project-grid">${this.projects.map((s)=>this.renderProject(s))}</div>
</section>
<section class="block">
<header class="block-head"><h2>Merged today</h2><span class="count">${this.landed.length}</span>
<span class="topbar-spacer"></span><a class="block-link" href="#/day">Day report →</a></header>
${this.landed.length>0?this.landed.slice(0,Ft).map((s)=>O(s.card,{repo:!0,at:s.at})):n`<p class="block-empty">Nothing merged yet today.</p>`}
</section>
</div>
`}renderWorking(e){return n`
<a class="working-card" href=${et(e)}>
<div class="working-top">
<span class="spinner"></span>
<span class="working-agent">${e.agent??"agent"}${e.model?n`<span class="muted"> · ${e.model}</span>`:o}</span>
<span class="topbar-spacer"></span>
<span class="muted" title="Time in this status">${j(e.since??e.updated_at)}</span>
</div>
<div class="working-title">${e.title}</div>
<div class="muted working-meta">${T(e.repo)} ${ee(e)} · ${Ot(e)&&e.status==="in_review"?"reviewing":b(e.status).toLowerCase()}</div>
</a>
`}renderProject(e){let t=Te(e,"blocked"),s=Te(e,"in_progress")+Te(e,"in_review");return n`
<a class="project-card" href="#/${e.repo}">
<div class="project-card-head">
<span class="project-icon">${oe(e.repo)}</span>
<span class="project-card-name">${T(e.repo)}</span>
<span class="muted">${e.repo.split("/")[0]}</span>
</div>
${ke(e.counts)}
<div class="project-card-stats">
<span><b>${Wt(e)}</b> open</span>
<span class=${s?"is-working":""}><b>${s}</b> working</span>
<span class=${t?"is-blocked":""}><b>${t}</b> blocked</span>
<span><b>${Te(e,"done")}</b> done</span>
</div>
</a>
`}}customElements.define("orch-home",zt);class Kt extends w{static properties={...w.properties,inbox:{state:!0},repo:{state:!0}};constructor(){super();this.inbox={blocked:[],human:[]},this.repo=""}async load(){this.inbox=await u.inbox()}only(e){return this.repo?e.filter((t)=>t.repo===this.repo):e}render(){let e=[...new Set([...this.inbox.blocked,...this.inbox.human].map((i)=>i.repo))].sort(),t=this.only(this.inbox.blocked),s=this.only(this.inbox.human);return n`
<header class="pane-head">${y()}<h1>Inbox</h1>
<span class="muted">${t.length+s.length} waiting on you</span>
<span class="topbar-spacer"></span>
${e.length>1?n`<div class="seg">
<button class=${this.repo?"":"on"} @click=${()=>{this.repo=""}}>All</button>
${e.map((i)=>n`<button class=${this.repo===i?"on":""} @click=${()=>{this.repo=i}}>${T(i)}</button>`)}
</div>`:o}
</header>
<div class="page">
${this.error?n`<div class="error-bar">${this.error}</div>`:o}
${this.loaded?t.length+s.length===0?n`<div class="inbox-zero"><span class="inbox-zero-mark">✓</span><p>Nothing waits on you. orch keeps working on the rest.</p></div>`:o:n`<p class="block-empty">Loading…</p>`}
${t.length>0?n`<section class="block">
<header class="block-head"><span class="dot dot-blocked"></span><h2>Blocked</h2><span class="count">${t.length}</span></header>
<p class="block-note muted">orch stopped on these, longest wait first. Fix what the reason names, then run <code>orch task unblock</code> or <code>orch task retry</code>.</p>
${t.map((i)=>O(i,{repo:!0,reason:!0,at:i.since??void 0}))}
</section>`:o}
${s.length>0?n`<section class="block">
<header class="block-head"><span class="dot dot-waiting"></span><h2>For you to do</h2><span class="count">${s.length}</span></header>
<p class="block-note muted">Marked <code>no-agent</code> or <code>owner:human</code>, so no agent picks them up.</p>
${s.map((i)=>O(i,{repo:!0,at:i.since??void 0}))}
</section>`:o}
</div>
`}}customElements.define("orch-inbox",Kt);var zs=[[1,"24 hours"],[7,"7 days"],[30,"30 days"],[90,"90 days"]],tt=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];function qt(e){return(N(e.at)-N(e.created_at))/1000}function st(e){return e.attempts<=1&&e.review_cycles===0}class Gt extends w{static properties={...w.properties,days:{state:!0},stats:{state:!0}};constructor(){super();this.days=Number(localStorage.getItem("orch.statsDays"))||7,this.stats=null}async load(){this.stats=await u.stats(this.days)}pick(e){this.days=e,localStorage.setItem("orch.statsDays",String(e)),this.reload()}series(e){let t=this.days===1,s=Date.now(),i=t?24:this.days,r=t?3600000:86400000,a=t?s-24*r:B(new Date(s-(i-1)*r)).getTime(),l=Array.from({length:i},(d,h)=>{let c=new Date(a+h*r);return{label:t?c.toLocaleTimeString(void 0,{hour:"2-digit"}):c.toLocaleDateString(void 0,{month:"short",day:"numeric"}),n:0}});for(let d of e){let h=Math.floor((N(d)-a)/r),c=l[h];if(h>=0&&h<i&&c)c.n+=1}return l}chart(e,t,s){let i=this.series(t),r=Math.max(1,...i.map((a)=>a.n));return n`<section class="block">
<header class="block-head"><h2>${e}</h2><span class="count">${t.length}</span></header>
<div class="bars bars-${s}">
${i.map((a)=>n`<span class="bar" ${I({height:`${a.n/r*100}%`})} title="${a.label}: ${a.n}"></span>`)}
</div>
<div class="bars-axis muted"><span>${i[0]?.label}</span><span>${i.at(-1)?.label}</span></div>
</section>`}heatmap(e){let t=Array.from({length:7},()=>Array(24).fill(0));for(let r of e){let a=new Date(N(r.at)),l=t[(a.getDay()+6)%7];if(l)l[a.getHours()]=(l[a.getHours()]??0)+1}let s=Math.max(1,...t.flat()),i=[0,0,0];for(let[r,a]of t.entries())for(let[l,d]of a.entries())if(d>i[2])i=[r,l,d];return n`<section class="block">
<header class="block-head"><h2>When work lands</h2></header>
<div class="heat">
${t.map((r,a)=>n`<span class="heat-day muted">${tt[a]}</span>${r.map((l,d)=>n`<span class="heat-cell" ${I({opacity:String(l?0.2+0.8*l/s:1)})} data-on=${l>0} title="${tt[a]} ${d}:00 · ${l} merged"></span>`)}`)}
</div>
${i[2]?n`<p class="block-note muted">The busiest hour is ${tt[i[0]]} ${i[1]}:00, with ${i[2]} merged.</p>`:o}
</section>`}render(){let e=this.stats,t=e?.merged??[],s=t.map(qt).filter((c)=>c>=0).sort((c,p)=>c-p),i=t.filter(st).length,r=t.reduce((c,p)=>c+p.review_cycles,0),a=(e?.runs??[]).filter((c)=>c.run_type==="agent"),l=a.filter((c)=>c.outcome&&c.outcome!=="success").length,d=new Map;for(let c of t)d.set(c.agent??"no agent",[...d.get(c.agent??"no agent")??[],c]);let h=new Map;for(let c of a){let p=c.outcome||"running";h.set(p,(h.get(p)??0)+1)}return n`
<header class="pane-head">${y()}<h1>Statistics</h1>
<span class="topbar-spacer"></span>
<div class="seg">
${zs.map(([c,p])=>n`<button class=${this.days===c?"on":""} @click=${()=>this.pick(c)}>${p}</button>`)}
</div>
</header>
<div class="page">
${this.error?n`<div class="error-bar">${this.error}</div>`:o}
<div class="tiles">
<div class="tile"><span class="tile-n">${t.length}</span><span class="tile-l">merged</span></div>
<div class="tile"><span class="tile-n">${E($e(s,0.5)||0)||"–"}</span>
<span class="tile-l">issue to merge, p50 · p90 ${E($e(s,0.9)||0)||"–"}</span></div>
<div class="tile"><span class="tile-n">${le(i,t.length)}</span>
<span class="tile-l">first try · ${i}/${t.length}</span></div>
<div class="tile"><span class="tile-n">${t.length>0?(r/t.length).toFixed(1):"–"}</span>
<span class="tile-l">review rounds per merge</span></div>
<div class="tile ${e?.blocked.length?"tile-alert":""}"><span class="tile-n">${e?.blocked.length??0}</span>
<span class="tile-l">times a task blocked</span></div>
<div class="tile"><span class="tile-n">${le(l,a.length)}</span>
<span class="tile-l">runs that failed · ${l}/${a.length}</span></div>
</div>
<div class="home-grid">
${this.chart("Merged",t.map((c)=>c.at),"merged")}
${this.chart("Blocked",(e?.blocked??[]).map((c)=>c.at),"blocked")}
</div>
${this.heatmap(t)}
<div class="home-grid">
<section class="block">
<header class="block-head"><h2>By agent</h2></header>
<table class="table">
<thead><tr><th>Agent</th><th>Merged</th><th>First try</th><th>p50 to merge</th><th>Review rounds</th></tr></thead>
<tbody>
${[...d].sort((c,p)=>p[1].length-c[1].length).map(([c,p])=>{let m=p.map(qt).filter((f)=>f>=0).sort((f,R)=>f-R),_=p.filter(st).length;return n`<tr><td>${c}</td><td>${p.length}</td><td>${le(_,p.length)} <span class="muted">${_}/${p.length}</span></td>
<td>${E($e(m,0.5)||0)||"–"}</td><td>${(p.reduce((f,R)=>f+R.review_cycles,0)/p.length).toFixed(1)}</td></tr>`})}
</tbody>
</table>
</section>
<section class="block">
<header class="block-head"><h2>How agent runs ended</h2><span class="count">${a.length}</span></header>
${[...h].sort((c,p)=>p[1]-c[1]).map(([c,p])=>n`<div class="hbar"><span class="hbar-label">${c.replace(/_/gu," ")}</span>
<span class="hbar-track hbar-${c==="success"?"ok":"bad"}"><span ${I({width:`${p/Math.max(1,a.length)*100}%`})}></span></span>
<span class="hbar-n mono">${p}</span></div>`)}
</section>
</div>
<section class="block">
<header class="block-head"><h2>By project</h2></header>
<table class="table">
<thead><tr><th>Project</th><th>Merged</th><th>First try</th><th>Blocked</th></tr></thead>
<tbody>
${[...new Set([...t.map((c)=>c.repo),...(e?.blocked??[]).map((c)=>c.repo)])].map((c)=>{let p=t.filter((_)=>_.repo===c),m=p.filter(st).length;return n`<tr><td><a href="#/${c}">${T(c)}</a></td><td>${p.length}</td>
<td>${le(m,p.length)} <span class="muted">${m}/${p.length}</span></td>
<td>${(e?.blocked??[]).filter((_)=>_.repo===c).length}</td></tr>`})}
</tbody>
</table>
</section>
</div>
`}}customElements.define("orch-stats",Gt);function Yt(e){let t=/(\d+|one|five|seven)_(hour|day)/u.exec(e);if(!t)return null;let s={one:1,five:5,seven:7},i=t[1]??"";return(s[i]??Number(i))*(t[2]==="hour"?3600:86400)}function Ks(e){let t=Yt(e),s=e.replace(/^(\d+|one|five|seven)_(hour|day)_?/u,"").replace(/_/gu," "),i=t===18000?"5-hour":t===604800?"Week":e.replace(/_/gu," ");return s&&t?`${i} · ${s}`:i}function qs(e){if(!e)return"";let t=e-Date.now()/1000;if(t<=0)return"reset";let s=new Date(e*1000).toLocaleString(void 0,{weekday:"short",hour:"2-digit",minute:"2-digit"});return`resets in ${E(t)}, ${s}`}class Xt extends w{static properties={...w.properties,usage:{state:!0},week:{state:!0}};constructor(){super();this.usage={windows:[],cooldowns:[]},this.week=null}async load(){[this.usage,this.week]=await Promise.all([u.usage(),u.stats(7)])}renderWindow(e){let t=e.utilization===null?null:Math.min(1,Math.max(0,e.utilization)),s=Yt(e.window),i=s&&e.resets_at?1-Math.max(0,e.resets_at-Date.now()/1000)/s:null,r=t!==null&&i!==null&&i>0.03&&t>i+0.05,a=e.status==="rejected"?"full":t!==null&&t>=0.8?"high":"ok";return n`
<div class="window">
<div class="window-head">
<span>${Ks(e.window)}</span>
${e.status==="allowed"?o:n`<span class="chip chip-${e.status==="rejected"?"bad":"warn"}">${e.status.replace(/_/gu," ")}</span>`}
<span class="topbar-spacer"></span>
<b>${t===null?"–":`${Math.round(t*100)}%`}</b>
</div>
<div class="meter meter-${a}">
<span ${I({width:`${(t??0)*100}%`})}></span>
${i!==null&&i>0&&i<1?n`<i ${I({left:`${i*100}%`})} title="Time passed in this window"></i>`:o}
</div>
<div class="window-foot muted">
<span>${qs(e.resets_at)}</span>
${r?n`<span class="warn-text">ahead of pace, may run out before the reset</span>`:o}
</div>
</div>
`}render(){let e=Date.now()/1000,t=[...new Set([...this.usage.windows.map((d)=>d.agent),...this.usage.cooldowns.map((d)=>d.key.split(":")[0]),...(this.week?.runs??[]).map((d)=>d.agent??"").filter(Boolean)])].sort(),s=this.week?.runs??[],i=new Map,r=new Map;for(let d of s)i.set(d.agent??"unknown",(i.get(d.agent??"unknown")??0)+d.duration_secs),r.set(d.repo,(r.get(d.repo)??0)+d.duration_secs);let a=Math.max(1,...r.values(),...i.values()),l=(d,h)=>[...d].sort((c,p)=>p[1]-c[1]).map(([c,p])=>n`<div class="hbar"><span class="hbar-label">${h(c)}</span>
<span class="hbar-track"><span ${I({width:`${p/a*100}%`})}></span></span>
<span class="hbar-n mono">${E(p)}</span></div>`);return n`
<header class="pane-head">${y()}<h1>Usage</h1>
<span class="muted">plan limits as each agent last reported them</span></header>
<div class="page">
${this.error?n`<div class="error-bar">${this.error}</div>`:o}
${t.length>0?n`<div class="usage-grid">
${t.map((d)=>{let h=this.usage.windows.filter((p)=>p.agent===d),c=this.usage.cooldowns.filter((p)=>p.key===d||p.key.startsWith(`${d}:`));return n`<section class="block usage-card">
<header class="block-head"><h2>${d}</h2>
<span class="topbar-spacer"></span>
${c.length>0?n`<span class="chip chip-bad">cooling down</span>`:n`<span class="chip chip-ok">routable</span>`}
</header>
${h.length>0?h.map((p)=>this.renderWindow(p)):n`<p class="block-empty">This agent reports no plan limits to orch.</p>`}
${c.map((p)=>n`<div class="cooldown">
<span class="mono">${p.key}</span>
<span class="muted">${p.reason.replace(/_/gu," ")}</span>
<span class="topbar-spacer"></span>
<span>${E(p.until-e)} left</span>
</div>`)}
</section>`})}
</div>`:n`<p class="block-empty">No agent has reported a plan window, and none is cooling down.</p>`}
<div class="home-grid">
<section class="block">
<header class="block-head"><h2>Agent time this week, by project</h2></header>
${r.size>0?l(r,T):n`<p class="block-empty">No runs in the last 7 days.</p>`}
</section>
<section class="block">
<header class="block-head"><h2>By agent</h2></header>
${i.size>0?l(i,(d)=>d):n`<p class="block-empty">No runs in the last 7 days.</p>`}
</section>
</div>
</div>
`}}customElements.define("orch-usage",Xt);var xe=[{label:"Queued",statuses:["new"]},{label:"Routed",statuses:["routed"]},{label:"Building",statuses:["in_progress"]},{label:"Review",statuses:["needs_review","in_review"]},{label:"Approved",statuses:["approved"]},{label:"Merged",statuses:["done"]}];function Gs(e,t){let s=new Set([e.status,...t.flatMap((a)=>[a.from_status??"",a.to_status??""])]);if(e.status==="done")return xe.length-1;let i=xe.findIndex((a)=>a.statuses.includes(e.status));if(i>=0)return i;let r=0;return xe.forEach((a,l)=>{if(a.statuses.some((d)=>s.has(d)))r=l}),r}function Jt(e){let t=e.card,s=Gs(t,e.activity),i=t.status==="blocked"||t.status==="waiting";return n`<ol class="stepper">
${xe.map((r,a)=>n`<li class="step ${a<s||t.status==="done"?"step-done":""} ${a===s&&t.status!=="done"?i?"step-stuck":"step-now":""}">
<span class="step-bar"></span>
<span class="step-label">${r.label}</span>
${a===s&&i?n`<span class="step-note">${b(t.status)}</span>`:o}
</li>`)}
</ol>`}function Ys(e){let t=e.activity.filter((r)=>r.to_status),s=0,i=0;return t.forEach((r,a)=>{let l=N(r.timestamp),d=t[a+1],h=d?N(d.timestamp):e.card.status==="done"?l:Date.now(),c=Math.max(0,(h-l)/1000);if(r.to_status==="in_progress"||r.to_status==="in_review")s+=c;else if(r.to_status!=="done")i+=c}),{working:s,waiting:i,total:s+i}}function Qt(e,t,s){if(!e.pr_number)return o;if(t===void 0)return n`<div class="checklist muted">${s||"Reading the PR from GitHub…"}</div>`;if(t===null)return o;let i=t.checks.filter((m)=>m.status==="completed"),r=i.filter((m)=>!["success","neutral","skipped"].includes(m.conclusion??"")),a=t.checks.length-i.length,l=t.reviews.some((m)=>m.state==="APPROVED")||e.status==="approved"||e.status==="done",d=t.reviews.some((m)=>m.state==="CHANGES_REQUESTED"),h=t.mergeable_state??"",c=[t.checks.length===0?{ok:null,label:"CI",detail:"No checks on this PR. orch reviews after 15 minutes without one"}:r.length>0?{ok:!1,label:"CI",detail:`${r.length} of ${t.checks.length} failed · orch sends the task back to its agent`}:a?{ok:null,label:"CI",detail:`${i.length} of ${t.checks.length} done · orch waits for the rest`}:{ok:!0,label:"CI",detail:`${t.checks.length} of ${t.checks.length} green`},d?{ok:!1,label:"Review",detail:`Changes requested · round ${e.review_cycles}, the agent fixes them on this PR`}:l?{ok:!0,label:"Review",detail:"Approved"}:{ok:null,label:"Review",detail:e.status==="in_review"?"The review agent is reading the PR":"Waits for green CI, then a review agent reads the PR"},t.mergeable===!1?{ok:!1,label:"Mergeable",detail:"Conflicts with the base · orch rebases in the worktree, or the agent solves it"}:h==="behind"?{ok:null,label:"Mergeable",detail:"Behind the base · orch rebases before it merges"}:t.mergeable===null?{ok:null,label:"Mergeable",detail:"GitHub is still working it out"}:{ok:!0,label:"Mergeable",detail:`Merges cleanly into ${t.base}`}],p=c.every((m)=>m.ok);return n`<div class="checklist">
<div class="checklist-head">${t.merged?"Merged":p?"Ready to merge · orch merges it on the next pass":"Before it merges"}</div>
${c.map((m)=>n`<div class="check-row">
<span class="check-mark ${m.ok===!0?"is-ok":m.ok===!1?"is-bad":"is-wait"}">${m.ok===!0?"✓":m.ok===!1?"✕":"…"}</span>
<span class="check-label">${m.label}</span>
<span class="check-detail muted">${m.detail}</span>
</div>`)}
</div>`}function Zt(e){if(!e)return o;let t=e.merged?"merged":e.state;return n`<section class="pr-card">
<div class="pr-head">
<span class="chip chip-${t==="merged"?"merged":t==="open"?"ok":"bad"}">${t}</span>
<a href=${e.html_url} target="_blank" rel="noopener" class="pr-title">#${e.number} ${e.title}</a>
</div>
<div class="muted mono pr-branch">${e.head} → ${e.base}</div>
${e.checks.length>0?n`<ul class="pr-checks">
${e.checks.map((s)=>{let i=s.status==="completed"&&["success","neutral","skipped"].includes(s.conclusion??""),r=s.status==="completed"&&!i;return n`<li><span class="check-mark ${i?"is-ok":r?"is-bad":"is-wait"}">${i?"✓":r?"✕":"…"}</span>
<span>${s.name}</span><span class="muted">${s.conclusion??s.status.replace(/_/gu," ")}</span></li>`})}
</ul>`:o}
${e.reviews.length>0?n`<div class="pr-reviews">${e.reviews.map((s)=>n`<span class="chip">${s.login} · ${s.state.toLowerCase().replace(/_/gu," ")}</span>`)}</div>`:o}
</section>`}function es(e){let t=e.card,s=Ys(e),i=[["Agent",t.agent??"not routed yet"],["Model",t.model??"the agent's default"],["Complexity",t.complexity||"–"],["Branch",e.branch?n`<span class="mono">${e.branch}</span>`:"–"],["Attempts",String(t.attempts)],["Review rounds",String(t.review_cycles)],["Created",A(t.created_at)]];return n`<div class="details">
${s.total?n`<div class="time-split">
<div class="time-split-head"><b>${E(s.total)}</b><span class="muted">total</span></div>
<div class="meter meter-split"><span ${I({width:`${s.working/s.total*100}%`})}></span></div>
<div class="time-split-foot muted"><span>${E(s.working)} working</span><span>${E(s.waiting)} waiting</span></div>
</div>`:o}
<dl>${i.map(([r,a])=>n`<dt>${r}</dt><dd>${a}</dd>`)}</dl>
</div>`}function ts(e){if(e.runs.length===0)return o;return n`<h3>Runs</h3>
<table class="table runs">
<thead><tr><th>#</th><th>Kind</th><th>Agent</th><th>Ended</th><th>Took</th></tr></thead>
<tbody>
${e.runs.map((t)=>n`<tr title=${t.error}>
<td>${t.attempt}</td><td>${t.run_type}</td>
<td>${t.agent}${t.model?n`<span class="muted"> · ${t.model}</span>`:o}</td>
<td class=${t.outcome&&t.outcome!=="success"?"is-bad-text":""}>${t.outcome||(t.completed_at?"–":"running")}</td>
<td>${E(t.duration_secs)}</td>
</tr>`)}
</tbody>
</table>`}var ss=400;class is extends v{static properties={repo:{type:String},showRepo:{type:Boolean},items:{state:!0}};constructor(){super();this.source=null;this.follow=!0;this.repo="",this.showRepo=!1,this.items=[]}createRenderRoot(){return this}disconnectedCallback(){super.disconnectedCallback(),this.source?.close(),this.source=null}updated(e){if(e.has("repo"))this.open();if(this.follow){let t=this.querySelector(".feed");if(t)t.scrollTop=t.scrollHeight}}open(){this.source?.close(),this.items=[];let e=u.activity(this.repo);e.addEventListener("item",(t)=>{let s=JSON.parse(t.data),i=[...this.items,s];this.items=i.length>ss?i.slice(-ss):i}),this.source=e}onScroll(e){let t=e.target;this.follow=t.scrollHeight-t.scrollTop-t.clientHeight<40}ref(e){let t=e.number?`#${e.number}`:e.task===null?"":`T-${e.task}`,s=n`${this.showRepo?n`<span class="muted">${e.repo.split("/")[1]??e.repo} </span>`:o}${t}`;return e.task===null?n`<span class="feed-ref mono">${s}</span>`:n`<a class="feed-ref mono" href="#/${e.repo}/${e.task}" title=${e.title}>${s}</a>`}render(){return n`
<ol class="feed" @scroll=${this.onScroll}>
${this.items.length>0?this.items.map((e)=>e.kind==="status"?n`<li class="feed-item feed-status">
<span class="feed-time muted">${A(e.timestamp)}</span>
${this.ref(e)}
<span class="dot dot-${e.to??"new"}"></span>
<span class="feed-text">
${e.from?n`<span class="muted">${b(e.from)} →</span> `:o}${b(e.to??"")}
<span class="muted">· ${e.title}</span>
${e.text?n`<span class="feed-error">${e.text}</span>`:o}
</span>
</li>`:n`<li class="feed-item feed-output">
<span class="feed-time muted">${A(e.timestamp)}</span>
${this.ref(e)}
<span class="feed-text mono">${be(e.text)}</span>
</li>`):n`<li class="empty">Waiting for activity…</li>`}
</ol>
`}}customElements.define("orch-feed",is);var ns=3000;class rs extends v{static properties={src:{type:String},filter:{type:String},lines:{state:!0},connected:{state:!0}};constructor(){super();this.source=null;this.follow=!0;this.src="",this.filter="",this.lines=[],this.connected=!1}createRenderRoot(){return this}disconnectedCallback(){super.disconnectedCallback(),this.close()}updated(e){if(e.has("src"))this.open();if(this.follow){let t=this.querySelector("pre");if(t)t.scrollTop=t.scrollHeight}}close(){this.source?.close(),this.source=null}open(){if(this.close(),this.lines=[],!this.src)return;let e=new EventSource(this.src);e.onopen=()=>{this.connected=!0},e.onerror=()=>{this.connected=!1},e.addEventListener("attempt",()=>{if(this.lines.length>0)this.push("── new attempt ──")}),e.addEventListener("line",(t)=>{this.push(be(t.data))}),this.source=e}push(e){let t=this.lines.concat(e.split(`
`));this.lines=t.length>ns?t.slice(-ns):t}onScroll(e){let t=e.target;this.follow=t.scrollHeight-t.scrollTop-t.clientHeight<40}render(){let e=this.filter.toLowerCase(),t=e?this.lines.filter((s)=>s.toLowerCase().includes(e)):this.lines;return n`<pre class="tail" @scroll=${this.onScroll}>${t.length>0?t.join(`
`):this.connected?"Waiting for output…":"Connecting…"}</pre>`}}customElements.define("orch-tail",rs);var Xs=["home","inbox","day","usage","stats","logs","activity","settings"];function as(){let e=location.hash.replace(/^#\/?/u,"").split("/").filter(Boolean);if(Xs.includes(e[0]))return{repo:null,task:null,page:e[0]};if(e.length===0)return{repo:null,task:null,page:"home"};let t=e.length>=2?`${e[0]}/${e[1]}`:null;if(t&&e[2]==="new")return{repo:t,task:null,page:null,compose:!0};let s=e.length>=3?Number(e[2]):null;return{repo:t,task:s!==null&&Number.isFinite(s)?s:null,page:null}}function it(e,t){return`#/${e}/${t}`}function Js(e,t){return e.counts.find(([s])=>s===t)?.[1]??0}function Pe(e){return e.split("/")[1]??e}function os(e){if(e==="system")document.documentElement.removeAttribute("data-theme");else document.documentElement.setAttribute("data-theme",e)}function Qs(e,t){if(!t)return!0;return[e.title,e.number?`#${e.number}`:"",e.agent??"",e.model??"",...e.labels].join(" ").toLowerCase().includes(t)}class ls extends v{static properties={projects:{state:!0},running:{state:!0},route:{state:!0},cards:{state:!0},view:{state:!0},side:{state:!0},taskTab:{state:!0},detail:{state:!0},pr:{state:!0},prError:{state:!0},needsYou:{state:!0},addMode:{state:!0},addMenu:{state:!0},projectsLoaded:{state:!0},messages:{state:!0},sending:{state:!0},error:{state:!0},live:{state:!0},filter:{state:!0},logFilter:{state:!0},theme:{state:!0},navOpen:{state:!0}};constructor(){super();this.prFor=0;this.prAt=0;this.events=null;this.refetch=0;this.ticker=0;this.draft="";this.onOpenAdd=(e)=>{this.addMenu=!1,this.addMode=e.detail};this.onCloseAdd=()=>{this.addMode=null};this.onAdded=(e)=>{this.addMode=null;let t=e.detail;this.loadProjects().then(()=>{location.hash=`#/${t}`})};this.onMenu=()=>{this.navOpen=!0};this.onKey=(e)=>{if(e.key!=="Escape")return;if(this.navOpen)this.navOpen=!1;else if(this.route.task!==null)this.closeTask();else if(this.side)this.side=null};this.onRoute=()=>{let e=this.route;if(this.route=as(),this.navOpen=!1,this.route.repo!==e.repo||this.cards.length===0){if(this.cards=[],this.messages=[],this.filter="",this.route.repo){if(this.loadTasks(),this.side)this.loadSide(this.side)}}if(this.route.task===null)this.detail=null;else{if(e.task!==this.route.task)this.taskTab="overview",this.detail=null;this.loadDetail(this.route.task)}};this.projects=[],this.running=[],this.route=as(),this.cards=[],this.view=localStorage.getItem("orch.view")||"overview",this.side=null,this.taskTab="overview",this.detail=null,this.pr=void 0,this.prError="",this.needsYou=0,this.addMode=null,this.addMenu=!1,this.projectsLoaded=!1,this.messages=[],this.sending=!1,this.error="",this.live=!1,this.filter="",this.logFilter="",this.theme=localStorage.getItem("orch.theme")||"system",this.navOpen=!1,os(this.theme)}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),window.addEventListener("hashchange",this.onRoute),window.addEventListener("keydown",this.onKey),window.addEventListener(Ee,this.onMenu),window.addEventListener(Se,this.onOpenAdd),window.addEventListener(ye,this.onCloseAdd),window.addEventListener(we,this.onAdded),this.watch(),this.ticker=window.setInterval(()=>this.requestUpdate(),60000),Promise.all([this.loadProjects(),this.loadRunning(),this.loadNeedsYou()]).then(()=>this.onRoute())}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("hashchange",this.onRoute),window.removeEventListener("keydown",this.onKey),window.removeEventListener(Ee,this.onMenu),window.removeEventListener(Se,this.onOpenAdd),window.removeEventListener(ye,this.onCloseAdd),window.removeEventListener(we,this.onAdded),window.clearInterval(this.ticker),this.events?.close()}watch(){let e=u.events("");e.onopen=()=>{this.live=!0},e.onerror=()=>{this.live=!1};let t=()=>this.scheduleRefresh();e.addEventListener("task",t),e.addEventListener("lagged",t),this.events=e}scheduleRefresh(){window.clearTimeout(this.refetch),this.refetch=window.setTimeout(()=>{if(this.loadProjects(),this.loadRunning(),this.loadNeedsYou(),window.dispatchEvent(new Event(ce)),this.route.repo)this.loadTasks();if(this.route.task!==null)this.loadDetail(this.route.task)},300)}async run(e){try{let t=await e();return this.error="",t}catch(t){this.error=t instanceof Error?t.message:String(t);return}}async loadProjects(){let e=await this.run(()=>u.projects());if(e)this.projects=e,this.projectsLoaded=!0}async loadRunning(){let e=await this.run(()=>u.running());if(e)this.running=e}async loadTasks(){let e=this.route.repo;if(!e)return;let t=await this.run(()=>u.tasks(e));if(t&&e===this.route.repo)this.cards=t}async loadDetail(e){let t=await this.run(()=>u.task(e));if(t&&this.route.task===e)this.detail=t,this.loadPr(t)}async loadNeedsYou(){let e=await this.run(()=>u.inbox());if(e)this.needsYou=e.blocked.length+e.human.length}async loadPr(e){let t=e.card.id;if(!e.card.pr_number){this.pr=null;return}if(this.prFor===t&&Date.now()-this.prAt<20000)return;if(this.prFor!==t)this.pr=void 0;this.prFor=t,this.prAt=Date.now();try{let s=await u.pr(t);if(this.route.task===t)this.pr=s,this.prError=""}catch(s){this.prError=s instanceof Error?s.message:String(s)}}async loadSide(e){let t=this.route.repo;if(!t)return;if(e==="chat")this.messages=await this.run(()=>u.chat(t))??[],this.scrollChat()}toggleSide(e){if(this.side===e&&this.route.task===null){this.side=null;return}if(this.side=e,this.route.task!==null)this.closeTask();this.loadSide(e)}closeTask(){if(this.route.repo)location.hash=`#/${this.route.repo}`}askAbout(e){let t=e.card.number?`#${e.card.number}`:`internal task ${e.card.id}`;this.draft=`About ${t} "${e.card.title}": `,this.side="chat",this.closeTask(),this.loadSide("chat").then(()=>this.updateComplete.then(()=>{let s=this.querySelector(".chat-input");if(s)s.value=this.draft,s.focus()}))}setView(e){this.view=e,localStorage.setItem("orch.view",e)}setTheme(e){this.theme=e,localStorage.setItem("orch.theme",e),os(e)}scrollChat(){this.updateComplete.then(()=>{let e=this.querySelector(".chat-log");if(e)e.scrollTop=e.scrollHeight})}async sendChat(){let e=this.route.repo,t=this.draft.trim();if(!(e&&t)||this.sending)return;this.sending=!0,this.messages=[...this.messages,{role:"user",content:t,agent:null,model:null,created_at:""}],this.draft="";let s=this.querySelector(".chat-input");if(s)s.value="";this.scrollChat();let i=await this.run(()=>u.send(e,t));if(this.sending=!1,i&&e===this.route.repo)this.messages=[...this.messages,i],this.scrollChat()}onChatKey(e){if(e.key==="Enter"&&(e.metaKey||e.ctrlKey))e.preventDefault(),this.sendChat()}render(){let e=this.route.task!==null||this.side!==null;return n`
<div class="shell ${this.navOpen?"nav-open":""}">
${this.renderSidebar()}
<div class="nav-scrim" @click=${()=>{this.navOpen=!1}}></div>
<div class="workspace">
<div class="panes ${e?"with-side":""} ${this.route.task===null?"":"side-wide"}">
<main class="pane">${this.renderMain()}</main>
${e&&!this.route.page?n`<aside class="pane side">${this.renderSide()}</aside>`:o}
</div>
${this.renderStatusbar()}
</div>
${this.addMode?n`<orch-add .mode=${this.addMode}></orch-add>`:o}
</div>
`}renderMain(){switch(this.route.page){case"home":return this.projectsLoaded&&this.projects.length===0?n`<orch-welcome class="page-host"></orch-welcome>`:n`<orch-home class="page-host"></orch-home>`;case"inbox":return n`<orch-inbox class="page-host"></orch-inbox>`;case"day":return n`<orch-day class="page-host"></orch-day>`;case"usage":return n`<orch-usage class="page-host"></orch-usage>`;case"stats":return n`<orch-stats class="page-host"></orch-stats>`;case"logs":return this.renderLogs();case"activity":return n`
<header class="pane-head">${y()}<span class="nav-glyph">◷</span><h1>Activity</h1>
<span class="muted">every project</span></header>
<orch-feed class="feed-fill" .repo=${""} .showRepo=${!0}></orch-feed>
`;case"settings":return this.renderSettingsPage();default:return this.route.compose&&this.route.repo?n`<orch-compose class="page-host" .repo=${this.route.repo}></orch-compose>`:this.renderProject()}}navLink(e,t,s,i=0){return n`<a class="nav-item ${this.route.page===e?"active":""}" href="#/${e}">
<span class="nav-glyph">${t}</span><span class="nav-name">${s}</span>
${i?n`<span class="badge badge-blocked">${i}</span>`:o}
</a>`}renderSidebar(){return n`
<nav class="sidebar">
<div class="brand"><span class="brand-mark">◆</span> orch</div>
${this.navLink("home","⌂","Home")}
${this.navLink("inbox","◉","Inbox",this.needsYou)}
${this.navLink("day","☰","Day report")}
${this.navLink("activity","◷","Activity")}
${this.navLink("stats","▤","Statistics")}
${this.navLink("usage","◔","Usage")}
<div class="side-section">
<div class="side-label side-label-row">Projects
<button class="icon add-btn" title="Add a project" @click=${()=>{this.addMenu=!this.addMenu}}>+</button>
</div>
${this.addMenu?n`<div class="add-menu">
<button @click=${()=>G("clone")}>Clone a repository…</button>
<button @click=${()=>G("create")}>Create a new repository…</button>
<button @click=${()=>G("existing")}>Add an existing repository…</button>
<button disabled title="Follow a project another machine runs, with nothing on this one">
Watch only…<span class="add-menu-note">comes with multi-node</span></button>
</div>`:o}
${this.projects.length>0?this.projects.map((e)=>{let t=Js(e,"blocked"),s=e.repo===this.route.repo;return n`
<a class="nav-item ${s?"active":""}" href="#/${e.repo}" title=${e.repo}>
<span class="project-icon">${oe(e.repo)}</span>
<span class="nav-name">${Pe(e.repo)}</span>
${t?n`<span class="badge badge-blocked" title="${t} blocked">${t}</span>`:o}
</a>
`}):n`<p class="side-empty">No projects yet. Use + to add one.</p>`}
</div>
<div class="side-spacer"></div>
<div class="side-section side-agents">
<div class="side-label">${this.running.length>0?n`<span class="working">Working ${this.running.length}</span>`:"Agents"}</div>
${this.running.length>0?this.running.map((e)=>n`<a class="agent-row ${this.route.task===e.id?"active":""}" href=${it(e.repo,e.id)} title=${e.title}>
<span class="spinner"></span>
<span class="nav-name"><b>${e.agent??"agent"}</b> <span class="muted">· ${Pe(e.repo)} ${e.number?`#${e.number}`:`T-${e.id}`}</span></span>
<span class="muted mono">${j(e.since??e.updated_at)}</span>
</a>`):n`<p class="side-empty">No agent is working.</p>`}
</div>
${this.navLink("logs","≡","Service log")}
${this.navLink("settings","⚙","Settings")}
</nav>
`}renderStatusbar(){let e=this.projects.find((s)=>s.repo===this.route.repo),t=e?e.counts.filter(([s])=>s!=="done").reduce((s,[,i])=>s+i,0):0;return n`
<footer class="statusbar">
<span class="status-item" title=${this.live?"Receiving live events from the orch service":"Not connected to the orch service"}>
<span class="dot ${this.live?"dot-live":"dot-off"}"></span>${this.live?"Live":"Offline"}
</span>
<span class="status-item wide-only">This computer</span>
<span class="status-item">${this.running.length} ${this.running.length===1?"agent":"agents"} working</span>
${e?n`<span class="status-item">${Pe(e.repo)} · ${t} open</span>`:o}
<span class="topbar-spacer"></span>
${this.error?n`<span class="status-item status-error" title=${this.error}>${this.error}</span>`:o}
</footer>
`}renderSettingsPage(){let e=[["system","System"],["light","Light"],["dark","Dark"]];return n`
<header class="pane-head">${y()}<span class="nav-glyph">⚙</span><h1>Settings</h1></header>
<div class="settings-page">
<section class="settings-section">
<h2>Appearance</h2>
<div class="pref-row">
<span>Theme</span>
<div class="seg">
${e.map(([t,s])=>n`<button class=${this.theme===t?"on":""} @click=${()=>this.setTheme(t)}>${s}</button>`)}
</div>
</div>
</section>
<section class="settings-section">
<h2>orch config</h2>
<p class="muted">The global config every project starts from. A project's own settings are under Config on its page.</p>
<orch-config class="config-tall" .repo=${""}></orch-config>
</section>
<section class="settings-section">
<h2>Nodes</h2>
<p class="muted">This computer runs every task. Settings for more machines come here with multi-node.</p>
</section>
</div>
`}renderProject(){let e=this.route.repo;if(!e)return n`<div class="empty">Pick a project.</div>`;let t=this.filter.trim().toLowerCase(),s=this.cards.filter((i)=>Qs(i,t));return n`
<header class="pane-head project-head">
${y()}
<span class="project-icon">${oe(e)}</span>
<h1>${Pe(e)}</h1>
<span class="muted owner">${e.split("/")[0]}</span>
<div class="seg">
<button class=${this.view==="overview"?"on":""} @click=${()=>this.setView("overview")}>Overview</button>
<button class=${this.view==="board"?"on":""} @click=${()=>this.setView("board")}>Board</button>
<button class=${this.view==="list"?"on":""} @click=${()=>this.setView("list")}>List</button>
<button class=${this.view==="plan"?"on":""} @click=${()=>this.setView("plan")}>Plan</button>
</div>
<div class="topbar-spacer"></div>
<div class="head-tools">
<a class="tool primary" href="#/${e}/new">New task</a>
<button class="tool ${this.side==="chat"&&this.route.task===null?"on":""}" @click=${()=>this.toggleSide("chat")}>Chat</button>
<button class="tool ${this.side==="activity"&&this.route.task===null?"on":""}" @click=${()=>this.toggleSide("activity")}>Activity</button>
<button class="tool ${this.side==="config"&&this.route.task===null?"on":""}" @click=${()=>this.toggleSide("config")}>Config</button>
</div>
</header>
${this.view==="plan"?o:n`<div class="filter-row">
<input class="filter" type="search" placeholder="Filter by title, #, agent, label" .value=${this.filter}
@input=${(i)=>{this.filter=i.target.value}} />
</div>`}
${this.view==="plan"?n`<orch-plan class="plan-host" .repo=${e}></orch-plan>`:this.cards.length>0?this.view==="overview"?this.renderProjectOverview(e,s):this.view==="board"?this.renderBoard(e,s):this.renderList(e,s):n`<div class="empty">No tasks yet. <a class="link" href="#/${e}" @click=${()=>this.setView("plan")}>Plan what to build</a> with an agent, <a class="link" href="#/${e}/new">create a task</a>, or label an issue on GitHub.</div>`}
`}renderProjectOverview(e,t){let s=this.projects.find((h)=>h.repo===e),i=t.filter((h)=>h.status==="blocked"||h.status!=="done"&&h.labels.some((c)=>c==="no-agent"||c==="owner:human")),r=t.filter((h)=>["in_progress","needs_review","in_review","approved"].includes(h.status)),a=t.filter((h)=>["routed","new","waiting"].includes(h.status)&&!i.includes(h)),l=t.filter((h)=>h.status==="done").slice(0,8),d=(h,c,p,m={})=>n`<section class="block">
<header class="block-head"><h2>${h}</h2><span class="count">${c.length}</span></header>
${c.length>0?c.map((_)=>O(_,m)):n`<p class="block-empty">${p}</p>`}
</section>`;return n`<div class="page">
${s?n`<div class="overview-bar">${ke(s.counts)}${It(s.counts)}</div>`:o}
${i.length>0?d("Needs you",i,"",{reason:!0}):o}
<div class="home-grid">
${d("In motion",r,"Nothing is being built or reviewed.")}
${d("Up next",a,"The queue is empty.")}
</div>
${d("Recently landed",l,"Nothing merged yet.")}
</div>`}group(e){let t=new Map;for(let s of e){let i=t.get(s.status)??[];i.push(s),t.set(s.status,i)}return t}renderBoard(e,t){let s=this.group(t),i=Ye.flatMap((r)=>s.get(r)??[]);return n`
<div class="board-wrap">
${i.length>0?n`<section class="attention">
<div class="attention-title"><span class="dot dot-blocked"></span>Needs attention <span class="count">${i.length}</span></div>
<div class="attention-row">${i.map((r)=>this.renderCard(e,r))}</div>
</section>`:o}
<div class="board">
${Z.map((r)=>{let a=s.get(r)??[];return n`
<section class="column ${a.length>0?"":"column-empty"}">
<header class="column-head">
<span class="dot dot-${r}"></span>
<span class="column-name">${b(r)}</span>
<span class="count">${a.length}</span>
</header>
<div class="column-body">${a.map((l)=>this.renderCard(e,l))}</div>
</section>
`})}
</div>
</div>
`}renderLinks(e){return n`
${e.pr_url?n`<a class="chip chip-pr" href=${e.pr_url} target="_blank" rel="noopener">PR #${e.pr_number}</a>`:o}
`}renderTag(e){let t=e.number?`#${e.number}`:`T-${e.id}`;return e.url&&e.number?n`<a class="tag mono tag-link" href=${e.url} target="_blank" rel="noopener" title="Open the issue on GitHub">${t}</a>`:n`<span class="tag mono">${t}</span>`}renderCard(e,t){let s=this.route.task===t.id,i=t.status==="in_progress"||t.status==="in_review";return n`
<article class="card ${s?"selected":""} card-${t.status}">
<div class="card-top">
${this.renderTag(t)}
${i?n`<span class="state-running"><span class="pulse"></span>${t.status==="in_review"?"reviewing":"running"}</span>`:o}
<span class="card-spacer"></span>
<span class="muted" title=${A(t.updated_at)}>${j(t.updated_at)}</span>
</div>
<a class="card-title" href=${it(e,t.id)}>${t.title}</a>
${t.status==="blocked"&&(t.block_reason||t.last_error)?n`<div class="card-error">${t.block_reason||t.last_error}</div>`:o}
<div class="card-meta">
${t.agent?n`<span class="chip">${t.agent}${t.model?n` · ${t.model}`:o}</span>`:o}
${this.renderLinks(t)}
${t.review_cycles?n`<span class="chip" title="Review cycles">↻ ${t.review_cycles}</span>`:o}
</div>
</article>
`}renderList(e,t){let s=this.group(t);return n`
<div class="list">
${Pt.filter((i)=>s.has(i)).map((i)=>{let r=s.get(i)??[];return n`
<section class="list-group">
<header class="list-head">
<span class="dot dot-${i}"></span>${b(i)}<span class="count">${r.length}</span>
</header>
${r.map((a)=>n`
<div class="row ${this.route.task===a.id?"selected":""}">
${this.renderTag(a)}
${a.status==="in_progress"||a.status==="in_review"?n`<span class="pulse"></span>`:o}
<a class="row-title" href=${it(e,a.id)}>${a.title}</a>
<span class="row-meta">
${a.agent?n`<span class="chip">${a.agent}</span>`:o}
${this.renderLinks(a)}
<span class="muted row-time" title=${A(a.updated_at)}>${j(a.updated_at)}</span>
</span>
</div>
`)}
</section>
`})}
</div>
`}renderSide(){if(this.route.task!==null)return this.renderTask();return n`
<header class="side-head">
<div class="seg">
${[["chat","Chat"],["activity","Activity"],["config","Config"]].map(([t,s])=>n`<button class=${this.side===t?"on":""} @click=${()=>{this.side=t,this.loadSide(t)}}>${s}</button>`)}
</div>
<span class="topbar-spacer"></span>
<button class="icon" title="Close (Esc)" @click=${()=>{this.side=null}}>✕</button>
</header>
<div class="side-body">${this.renderSideBody()}</div>
`}renderTask(){let e=this.detail;if(!e||e.card.id!==this.route.task)return n`<div class="empty">Loading…</div>`;let t=e.card,s=[["overview","Overview"],["output","Agent output"],["timeline","Timeline"]],i=t.status==="in_progress"||t.status==="in_review";return n`
<header class="side-head">
<button class="tool" @click=${()=>this.closeTask()}>← Back</button>
<span class="topbar-spacer"></span>
<button class="tool" @click=${()=>this.askAbout(e)}>✦ Ask in chat</button>
${t.pr_url||t.url?n`<a class="tool primary" href=${t.pr_url??t.url} target="_blank" rel="noopener">GitHub ↗</a>`:o}
</header>
<div class="task-head">
<div class="muted">${t.repo}${t.number?` #${t.number}`:` T-${t.id}`}</div>
<h2>${t.title}</h2>
<div class="task-status">
<span class="dot dot-${t.status}"></span>${b(t.status)}
${t.agent?n`<span class="muted">· ${t.agent}${t.model?` · ${t.model}`:""}</span>`:o}
<span class="muted">· attempt ${t.attempts}</span>
</div>
</div>
<nav class="tabs">
${s.map(([r,a])=>n`<button class="tab ${this.taskTab===r?"on":""}" @click=${()=>{this.taskTab=r}}>${a}${r==="output"&&i?n` <span class="pulse"></span>`:o}</button>`)}
</nav>
<div class="side-body">
${this.taskTab==="overview"?this.renderOverview(e):o}
${this.taskTab==="output"?n`<orch-tail class="tail-fill" .src=${`/api/output?id=${t.id}`}></orch-tail>`:o}
${this.taskTab==="timeline"?this.renderTimeline(e):o}
</div>
`}renderOverview(e){let t=e.card;return n`
<div class="section">
${Jt(e)}
${t.block_reason||t.last_error?n`<div class="task-error">${t.block_reason||t.last_error}</div>`:o}
${Qt(t,this.pr,this.prError)}
${Zt(this.pr)}
${es(e)}
${ts(e)}
<h3>Labels</h3>
<div class="card-meta">
${this.renderLinks(t)}
${e.branch?n`<span class="chip mono">${e.branch}</span>`:o}
${t.complexity?n`<span class="chip">${t.complexity}</span>`:o}
${t.labels.map((s)=>n`<span class="chip">${s}</span>`)}
</div>
${e.summary?n`<h3>Summary</h3><p class="prose">${e.summary}</p>`:o}
${e.body?n`<h3>Description</h3><pre class="prose">${e.body}</pre>`:o}
</div>
`}renderTimeline(e){return n`
<ol class="timeline section">
${e.activity.slice().reverse().map((t)=>n`<li>
<span class="muted" title=${t.timestamp}>${A(t.timestamp)}</span>
<span>${t.to_status?n`${t.from_status?`${b(t.from_status)} → `:""}${b(t.to_status)}`:t.event_type}</span>
${t.agent?n`<span class="muted">${t.agent}</span>`:o}
</li>`)}
</ol>
`}renderChat(){return n`
<div class="chat">
<div class="chat-log">
${this.messages.length>0?this.messages.map((e)=>n`<div class="msg msg-${e.role}">
<div class="msg-who">${e.role==="user"?"You":e.agent??"orch"}</div>
<div class="msg-text">${e.content}</div>
</div>`):n`<p class="muted chat-empty">Ask about ${this.route.repo}: what is blocked, why a task failed, or what to work on next.</p>`}
${this.sending?n`<div class="msg msg-assistant"><div class="msg-who">orch</div><div class="msg-text muted">Thinking…</div></div>`:o}
</div>
<div class="chat-compose">
<textarea class="chat-input" rows="3" placeholder="Message about this project. ⌘Enter to send"
@input=${(e)=>{this.draft=e.target.value}}
@keydown=${(e)=>this.onChatKey(e)}></textarea>
<button class="tool primary send" ?disabled=${this.sending} @click=${()=>void this.sendChat()}>Send</button>
</div>
</div>
`}renderSideBody(){let e=this.route.repo??"";switch(this.side){case"activity":return n`<orch-feed class="feed-fill" .repo=${e}></orch-feed>`;case"config":return n`<orch-config class="config-fill" .repo=${e}></orch-config>`;default:return this.renderChat()}}renderLogs(){return n`
<header class="pane-head">
${y()}
<span class="nav-glyph">≡</span>
<h1>Service log</h1>
<div class="topbar-spacer"></div>
<input class="filter filter-small" type="search" placeholder="Filter" .value=${this.logFilter}
@input=${(e)=>{this.logFilter=e.target.value}} />
</header>
<orch-tail class="tail-fill" .src=${"/api/logs"} .filter=${this.logFilter}></orch-tail>
`}}customElements.define("orch-app",ls);export{ls as OrchApp};