@exaudeus/workrail 3.74.0 → 3.74.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,4 +25,4 @@ Error generating stack: `+e.message+`
25
25
  `});++r<e.length;)r&&n.push({type:`text`,value:`
26
26
  `}),n.push(e[r]);return t&&e.length>0&&n.push({type:`text`,value:`
27
27
  `}),n}function WT(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function GT(e,t){let n=zT(e,t),r=n.one(e,void 0),i=wT(n),a=Array.isArray(r)?{type:`root`,children:r}:r||{type:`root`,children:[]};return i&&(`children`in a,a.children.push({type:`text`,value:`
28
- `},i)),a}function KT(e,t){return e&&`run`in e?async function(n,r){let i=GT(n,{file:r,...t});await e.run(i,r)}:function(n,r){return GT(n,{file:r,...e||t})}}function qT(e){if(e)throw e}var JT=o(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});f<p;++f)if(t=arguments[f],t!=null)for(n in t)r=l(d,n),i=l(t,n),d!==i&&(m&&i&&(s(i)||(a=o(i)))?(a?(a=!1,u=r&&o(r)?r:[]):u=r&&s(r)?r:{},c(d,{name:n,newValue:e(m,u,i)})):i!==void 0&&c(d,{name:n,newValue:i}));return d}}));function YT(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function XT(){let e=[],t={run:n,use:r};return t;function n(...t){let n=-1,r=t.pop();if(typeof r!=`function`)throw TypeError(`Expected function as last argument, not `+r);i(null,...t);function i(a,...o){let s=e[++n],c=-1;if(a){r(a);return}for(;++c<t.length;)(o[c]===null||o[c]===void 0)&&(o[c]=t[c]);t=o,s?ZT(s,i)(...o):r(null,...o)}}function r(n){if(typeof n!=`function`)throw TypeError("Expected `middelware` to be a function, not "+n);return e.push(n),t}}function ZT(e,t){let n;return r;function r(...t){let r=e.length>t.length,o;r&&t.push(i);try{o=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return i(t)}r||(o&&o.then&&typeof o.then==`function`?o.then(a,i):o instanceof Error?i(o):a(o))}function i(e,...r){n||(n=!0,t(e,...r))}function a(e){i(null,e)}}var QT={basename:$T,dirname:eE,extname:tE,join:nE,sep:`/`};function $T(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);aE(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function eE(e){if(aE(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function tE(e){aE(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function nE(...e){let t=-1,n;for(;++t<e.length;)aE(e[t]),e[t]&&(n=n===void 0?e[t]:n+`/`+e[t]);return n===void 0?`.`:rE(n)}function rE(e){aE(e);let t=e.codePointAt(0)===47,n=iE(e,!t);return n.length===0&&!t&&(n=`.`),n.length>0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function iE(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o<e.length)s=e.codePointAt(o);else if(s===47)break;else s=47;if(s===47){if(!(i===o-1||a===1))if(i!==o-1&&a===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function aE(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}var oE={cwd:sE};function sE(){return`/`}function cE(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function lE(e){if(typeof e==`string`)e=new URL(e);else if(!cE(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return uE(e)}function uE(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){let e=t.codePointAt(n+2);if(e===70||e===102){let e=TypeError(`File URL path must not include encoded / characters`);throw e.code=`ERR_INVALID_FILE_URL_PATH`,e}}return decodeURIComponent(t)}var dE=[`history`,`path`,`basename`,`stem`,`extname`,`dirname`],fE=class{constructor(e){let t;t=e?cE(e)?{path:e}:typeof e==`string`||gE(e)?{value:e}:e:{},this.cwd=`cwd`in t?``:oE.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let n=-1;for(;++n<dE.length;){let e=dE[n];e in t&&t[e]!==void 0&&t[e]!==null&&(this[e]=e===`history`?[...t[e]]:t[e])}let r;for(r in t)dE.includes(r)||(this[r]=t[r])}get basename(){return typeof this.path==`string`?QT.basename(this.path):void 0}set basename(e){mE(e,`basename`),pE(e,`basename`),this.path=QT.join(this.dirname||``,e)}get dirname(){return typeof this.path==`string`?QT.dirname(this.path):void 0}set dirname(e){hE(this.basename,`dirname`),this.path=QT.join(e||``,this.basename)}get extname(){return typeof this.path==`string`?QT.extname(this.path):void 0}set extname(e){if(pE(e,`extname`),hE(this.dirname,`extname`),e){if(e.codePointAt(0)!==46)throw Error("`extname` must start with `.`");if(e.includes(`.`,1))throw Error("`extname` cannot contain multiple dots")}this.path=QT.join(this.dirname,this.stem+(e||``))}get path(){return this.history[this.history.length-1]}set path(e){cE(e)&&(e=lE(e)),mE(e,`path`),this.path!==e&&this.history.push(e)}get stem(){return typeof this.path==`string`?QT.basename(this.path,this.extname):void 0}set stem(e){mE(e,`stem`),pE(e,`stem`),this.path=QT.join(this.dirname||``,e+(this.extname||``))}fail(e,t,n){let r=this.message(e,t,n);throw r.fatal=!0,r}info(e,t,n){let r=this.message(e,t,n);return r.fatal=void 0,r}message(e,t,n){let r=new tx(e,t,n);return this.path&&(r.name=this.path+`:`+r.name,r.file=this.path),r.fatal=!1,this.messages.push(r),r}toString(e){return this.value===void 0?``:typeof this.value==`string`?this.value:new TextDecoder(e||void 0).decode(this.value)}};function pE(e,t){if(e&&e.includes(QT.sep))throw Error("`"+t+"` cannot be a path: did not expect `"+QT.sep+"`")}function mE(e,t){if(!e)throw Error("`"+t+"` cannot be empty")}function hE(e,t){if(!e)throw Error("Setting `"+t+"` requires `path` to be set too")}function gE(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var _E=(function(e){let t=this.constructor.prototype,n=t[e],r=function(){return n.apply(r,arguments)};return Object.setPrototypeOf(r,t),r}),vE=l(JT(),1),yE={}.hasOwnProperty,bE=new class e extends _E{constructor(){super(`copy`),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=XT()}copy(){let t=new e,n=-1;for(;++n<this.attachers.length;){let e=this.attachers[n];t.use(...e)}return t.data((0,vE.default)(!0,{},this.namespace)),t}data(e,t){return typeof e==`string`?arguments.length===2?(CE(`data`,this.frozen),this.namespace[e]=t,this):yE.call(this.namespace,e)&&this.namespace[e]||void 0:e?(CE(`data`,this.frozen),this.namespace=e,this):this.namespace}freeze(){if(this.frozen)return this;let e=this;for(;++this.freezeIndex<this.attachers.length;){let[t,...n]=this.attachers[this.freezeIndex];if(n[0]===!1)continue;n[0]===!0&&(n[0]=void 0);let r=t.call(e,...n);typeof r==`function`&&this.transformers.use(r)}return this.frozen=!0,this.freezeIndex=1/0,this}parse(e){this.freeze();let t=EE(e),n=this.parser||this.Parser;return xE(`parse`,n),n(String(t),t)}process(e,t){let n=this;return this.freeze(),xE(`process`,this.parser||this.Parser),SE(`process`,this.compiler||this.Compiler),t?r(void 0,t):new Promise(r);function r(r,i){let a=EE(e),o=n.parse(a);n.run(o,a,function(e,t,r){if(e||!t||!r)return s(e);let i=t,a=n.stringify(i,r);OE(a)?r.value=a:r.result=a,s(e,r)});function s(e,n){e||!n?i(e):r?r(n):t(void 0,n)}}}processSync(e){let t=!1,n;return this.freeze(),xE(`processSync`,this.parser||this.Parser),SE(`processSync`,this.compiler||this.Compiler),this.process(e,r),TE(`processSync`,`process`,t),n;function r(e,r){t=!0,qT(e),n=r}}run(e,t,n){wE(e),this.freeze();let r=this.transformers;return!n&&typeof t==`function`&&(n=t,t=void 0),n?i(void 0,n):new Promise(i);function i(i,a){let o=EE(t);r.run(e,o,s);function s(t,r,o){let s=r||e;t?a(t):i?i(s):n(void 0,s,o)}}}runSync(e,t){let n=!1,r;return this.run(e,t,i),TE(`runSync`,`run`,n),r;function i(e,t){qT(e),r=t,n=!0}}stringify(e,t){this.freeze();let n=EE(t),r=this.compiler||this.Compiler;return SE(`stringify`,r),wE(e),r(e,n)}use(e,...t){let n=this.attachers,r=this.namespace;if(CE(`use`,this.frozen),e!=null)if(typeof e==`function`)s(e,t);else if(typeof e==`object`)Array.isArray(e)?o(e):a(e);else throw TypeError("Expected usable value, not `"+e+"`");return this;function i(e){if(typeof e==`function`)s(e,[]);else if(typeof e==`object`)if(Array.isArray(e)){let[t,...n]=e;s(t,n)}else a(e);else throw TypeError("Expected usable value, not `"+e+"`")}function a(e){if(!(`plugins`in e)&&!(`settings`in e))throw Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");o(e.plugins),e.settings&&(r.settings=(0,vE.default)(!0,r.settings,e.settings))}function o(e){let t=-1;if(e!=null)if(Array.isArray(e))for(;++t<e.length;){let n=e[t];i(n)}else throw TypeError("Expected a list of plugins, not `"+e+"`")}function s(e,t){let r=-1,i=-1;for(;++r<n.length;)if(n[r][0]===e){i=r;break}if(i===-1)n.push([e,...t]);else if(t.length>0){let[r,...a]=t,o=n[i][1];YT(o)&&YT(r)&&(r=(0,vE.default)(!0,o,r)),n[i]=[e,r,...a]}}}}().freeze();function xE(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function SE(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function CE(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function wE(e){if(!YT(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function TE(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function EE(e){return DE(e)?e:new fE(e)}function DE(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function OE(e){return typeof e==`string`||kE(e)}function kE(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var AE=[],jE={allowDangerousHtml:!0},ME=/^(https?|ircs?|mailto|xmpp)$/i,NE=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`className`,id:`remove-classname`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function PE(e){let t=FE(e),n=IE(e);return LE(t.runSync(t.parse(n),n),e)}function FE(e){let t=e.rehypePlugins||AE,n=e.remarkPlugins||AE,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...jE}:jE;return bE().use(Mw).use(n).use(KT,r).use(t)}function IE(e){let t=e.children||``,n=new fE;return typeof t==`string`?n.value=t:``+t,n}function LE(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||RE;for(let e of NE)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return IT(e,l),lx(e,{Fragment:H.Fragment,components:i,ignoreInvalidStyle:!0,jsx:H.jsx,jsxs:H.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in jx)if(Object.hasOwn(jx,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=jx[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function RE(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||ME.test(e.slice(0,t))?e:``}function zE({children:e,className:t}){return(0,H.jsx)(`div`,{className:`markdown-view ${t??``}`,children:(0,H.jsx)(PE,{children:e})})}function BE({sessionId:e,nodeId:t,runStatus:n=`complete`,currentNodeId:r=null,executionTraceSummary:i=null}){let{data:a,isLoading:o,error:s}=Ky(e,t);return t?(0,H.jsxs)(`div`,{children:[(0,H.jsx)(VE,{stepLabel:a?.stepLabel??null,nodeId:t}),(0,H.jsxs)(`div`,{className:`p-4 space-y-4`,children:[o&&(0,H.jsx)(`div`,{className:`text-[var(--text-secondary)] text-sm`,children:`Loading...`}),s&&(0,H.jsx)(`div`,{className:`text-[var(--error)] text-sm bg-[var(--bg-primary)] border border-[var(--border)] px-4 py-3`,children:s.message}),a&&(0,H.jsx)(KE,{detail:a,runStatus:n,currentNodeId:r,executionTraceSummary:i})]})]}):(0,H.jsx)(`div`,{className:`px-5 py-8 text-sm text-[var(--text-secondary)]`,children:`Select a node in the lineage to inspect its recap, validations, gaps, and artifacts.`})}function VE({stepLabel:e,nodeId:t}){return(0,H.jsxs)(`div`,{className:`px-5 py-4 border-b border-[var(--border)] console-blueprint-grid`,children:[(0,H.jsx)(`div`,{className:`text-base font-semibold text-[var(--text-primary)] leading-tight`,children:e??`Untitled node`}),(0,H.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-[var(--text-muted)] truncate`,children:t})]})}function HE({item:e}){return(0,H.jsxs)(`div`,{className:`flex items-start gap-2 text-xs py-1`,children:[(0,H.jsx)(`span`,{className:`flex-1 text-[var(--text-secondary)] leading-relaxed`,children:e.summary}),(0,H.jsxs)(`span`,{className:`font-mono text-[10px] text-[var(--text-muted)] shrink-0`,children:[`#`,e.recordedAtEventIndex]})]})}function UE({nodeId:e,nodeKind:t,executionTraceSummary:n}){let{whySelected:r,conditions:i,loops:a,divergences:o,forks:s}=py(n,e);return n.items.some(t=>t.kind!==`context_fact`&&t.refs.some(t=>t.kind===`node_id`&&t.value===e))?(0,H.jsx)(sD,{title:`Routing context`,children:(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(r.length>0||t===`blocked_attempt`)&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-1.5 flex items-center gap-2`,children:(0,H.jsx)(Py,{label:`WHY SELECTED`,color:`var(--accent)`,bgColor:`rgba(244,196,48,0.10)`})}),r.length>0?(0,H.jsx)(`div`,{className:`space-y-1 pl-2 border-l border-[var(--border)]`,children:r.map((e,t)=>(0,H.jsx)(HE,{item:e},t))}):t===`blocked_attempt`?(0,H.jsx)(`div`,{className:`pl-2 border-l border-[var(--border)]`,children:(0,H.jsx)(`span`,{className:`text-xs text-[var(--text-muted)]`,children:`This step was attempted but not selected as the preferred path.`})}):null]}),i.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-1.5`,children:(0,H.jsx)(Py,{label:`CONDITIONS EVALUATED`,color:`var(--text-secondary)`,bgColor:`rgba(168,159,140,0.10)`})}),(0,H.jsx)(`div`,{className:`space-y-1 pl-2 border-l border-[var(--border)]`,children:[...i.filter(e=>!sy(e)),...i.filter(e=>sy(e))].map((e,t)=>{let n=sy(e);return(0,H.jsxs)(`div`,{className:`flex items-start gap-2 text-xs py-0.5`,children:[(0,H.jsx)(Py,{label:n?`PASS`:`SKIP`,color:n?`var(--success)`:`var(--warning)`,bgColor:n?`rgba(34,197,94,0.10)`:`rgba(251,191,36,0.10)`}),(0,H.jsx)(`span`,{className:`flex-1 text-[var(--text-secondary)] leading-relaxed`,children:e.summary})]},t)})})]}),a.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-1.5`,children:(0,H.jsx)(Py,{label:`LOOP`,color:`var(--accent-strong)`,bgColor:`rgba(0,240,255,0.10)`})}),(0,H.jsx)(`div`,{className:`space-y-1 pl-2 border-l border-[var(--border)]`,children:a.map((e,t)=>(0,H.jsx)(HE,{item:e},t))})]}),o.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-1.5`,children:(0,H.jsx)(Py,{label:`DIVERGENCE`,color:`var(--error)`,bgColor:`rgba(255,107,107,0.10)`})}),(0,H.jsx)(`div`,{className:`space-y-1 pl-2 border-l border-[var(--border)]`,children:o.map((e,t)=>(0,H.jsx)(HE,{item:e},t))})]}),s.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-1.5`,children:(0,H.jsx)(Py,{label:`FORK`,color:`var(--warning)`,bgColor:`rgba(251,191,36,0.10)`})}),(0,H.jsx)(`div`,{className:`space-y-1 pl-2 border-l border-[var(--border)]`,children:s.map((e,t)=>(0,H.jsx)(HE,{item:e},t))})]})]})}):(0,H.jsx)(sD,{title:`Routing context`,children:t===`blocked_attempt`&&r.length===0?(0,H.jsxs)(`div`,{className:`flex items-start gap-2 py-1`,children:[(0,H.jsx)(Py,{label:`WHY SELECTED`,color:`var(--text-muted)`,bgColor:`rgba(123,141,167,0.08)`}),(0,H.jsx)(`span`,{className:`text-xs text-[var(--text-muted)] leading-relaxed`,children:`This step was attempted but not selected as the preferred path.`})]}):(0,H.jsx)(`span`,{className:`font-mono text-xs text-[var(--text-muted)]`,children:`// no routing trace for this node`})})}function WE({items:e}){let[t,n]=(0,V.useState)(!1);return(0,H.jsx)(sD,{title:`Run routing`,children:(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`button`,{type:`button`,"aria-expanded":t,onClick:()=>n(e=>!e),className:`flex items-center gap-2 font-mono text-[10px] uppercase tracking-[0.20em] text-[var(--text-muted)] hover:text-[var(--text-secondary)] transition-colors`,children:[(0,H.jsx)(Py,{label:`RUN ROUTING`,color:`var(--text-muted)`,bgColor:`rgba(123,141,167,0.08)`}),(0,H.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[`// `,e.length,` ambient items`]}),(0,H.jsx)(`span`,{children:t?`[-]`:`[+]`})]}),t&&(0,H.jsx)(`div`,{className:`mt-2 space-y-1 pl-2 border-l border-[var(--border)]`,children:e.map((e,t)=>(0,H.jsxs)(`div`,{className:`flex items-start gap-2 text-xs py-0.5`,children:[(0,H.jsx)(`span`,{className:`shrink-0 inline-flex items-center px-2 py-0.5 font-mono text-[10px] uppercase tracking-[0.16em]`,style:{color:`var(--text-muted)`,backgroundColor:`rgba(123,141,167,0.08)`,border:`1px solid rgba(123,141,167,0.20)`},children:e.kind.replace(/_/g,` `).toUpperCase()}),(0,H.jsx)(`span`,{className:`flex-1 text-[var(--text-secondary)] leading-relaxed`,children:e.summary}),(0,H.jsxs)(`span`,{className:`font-mono text-[10px] text-[var(--text-muted)] shrink-0`,children:[`#`,e.recordedAtEventIndex]})]},t))})]})})}var GE=[{id:`routing`,column:`primary`,render:({detail:e,executionTraceSummary:t})=>t===null?null:(0,H.jsx)(UE,{nodeId:e.nodeId,nodeKind:e.nodeKind,executionTraceSummary:t},`routing`)},{id:`run_routing`,column:`primary`,render:({executionTraceSummary:e})=>{if(e===null)return null;let t=e.items.filter(e=>!e.refs.some(e=>e.kind===`node_id`));return t.length===0?null:(0,H.jsx)(WE,{items:t},`run_routing`)}},{id:`recap`,column:`primary`,render:({detail:e,runStatus:t,currentNodeId:n})=>e.recapMarkdown?(0,H.jsx)(QE,{markdown:e.recapMarkdown},`recap`):t===`in_progress`&&e.nodeId===n&&!e.recapMarkdown?(0,H.jsx)(qE,{detail:e},`recap-in-progress`):null},{id:`validations`,column:`primary`,render:({detail:e})=>e.validations.length>0?(0,H.jsx)(eD,{validations:e.validations},`validations`):null},{id:`gaps`,column:`primary`,render:({detail:e})=>e.gaps.length>0?(0,H.jsx)(nD,{gaps:e.gaps},`gaps`):null},{id:`advance-outcome`,column:`primary`,render:({detail:e})=>e.advanceOutcome?(0,H.jsx)($E,{outcome:e.advanceOutcome},`advance-outcome`):null},{id:`artifacts`,column:`primary`,render:({detail:e})=>e.artifacts.length>0?(0,H.jsx)(oD,{artifacts:e.artifacts},`artifacts`):null},{id:`node-meta`,column:`primary`,render:({detail:e})=>(0,H.jsx)(ZE,{detail:e},`node-meta`)}];function KE(e){return(0,H.jsx)(`div`,{className:`space-y-4`,children:GE.map(t=>t.render(e))})}function qE({detail:e}){return(0,H.jsx)(sD,{title:`Recap`,children:(0,H.jsxs)(`div`,{className:`space-y-4 text-sm text-[var(--text-secondary)]`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(JE,{children:`In progress`}),(0,H.jsxs)(`span`,{className:`font-mono text-xs text-[var(--text-muted)]`,children:[`event #`,e.createdAtEventIndex]})]}),(0,H.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-2 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]`,children:[(0,H.jsx)(YE,{label:`Current focus`,value:e.stepLabel??`Current workflow step`,supportingText:`This step is still running, so the recap will appear once execution finishes.`}),(0,H.jsx)(YE,{label:`Current state`,value:`Waiting for step completion`,supportingText:`The node has been created and selected as the current workflow position.`,mono:!0})]}),(0,H.jsxs)(`div`,{className:`bg-[var(--bg-primary)] border border-[var(--border)] overflow-hidden`,children:[(0,H.jsx)(`div`,{className:`px-4 py-3 border-b border-[var(--border)]`,children:(0,H.jsx)(Go,{children:`What lands here next`})}),(0,H.jsxs)(`div`,{className:`p-4 grid gap-3 md:grid-cols-3`,children:[(0,H.jsx)(XE,{title:`Recap`,description:`A step summary is written when this node completes.`}),(0,H.jsx)(XE,{title:`Validations`,description:`Validation results appear if this step records contract checks.`}),(0,H.jsx)(XE,{title:`Artifacts`,description:`Generated outputs show up here after the step produces them.`})]})]})]})})}function JE({children:e}){return(0,H.jsx)(`span`,{className:`inline-flex items-center px-2 py-1 font-medium text-xs`,style:{backgroundColor:`rgba(0, 219, 233, 0.12)`,color:`var(--accent-strong)`},children:e})}function YE({label:e,value:t,supportingText:n,mono:r=!1}){return(0,H.jsxs)(`div`,{className:`bg-[var(--bg-primary)] border border-[var(--border)] px-4 py-3 space-y-2`,children:[(0,H.jsx)(Go,{children:e}),(0,H.jsx)(`div`,{className:r?`font-mono text-sm text-[var(--text-primary)]`:`text-[var(--text-primary)]`,children:t}),(0,H.jsx)(`div`,{className:`text-xs text-[var(--text-muted)] leading-relaxed`,children:n})]})}function XE({title:e,description:t}){return(0,H.jsxs)(`div`,{className:`border border-[var(--border)] bg-[rgba(255,255,255,0.02)] px-3 py-3 space-y-2`,children:[(0,H.jsx)(Go,{color:`var(--text-secondary)`,children:e}),(0,H.jsx)(`div`,{className:`text-xs text-[var(--text-muted)] leading-relaxed`,children:t})]})}function ZE({detail:e}){return(0,H.jsx)(sD,{title:`Node details`,children:(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(0,H.jsx)(cD,{label:`Kind`,value:(0,H.jsx)(uD,{kind:e.nodeKind})}),(0,H.jsx)(cD,{label:`Event index`,value:String(e.createdAtEventIndex),mono:!0}),(0,H.jsx)(cD,{label:`Parent`,value:e.parentNodeId??`Root`,mono:!0}),(0,H.jsx)(cD,{label:`Tip state`,value:e.isTip?e.isPreferredTip?`Preferred tip`:`Tip`:`Historical`})]})})}function QE({markdown:e}){return(0,H.jsx)(sD,{title:`Recap`,children:(0,H.jsx)(zE,{children:e})})}function $E({outcome:e}){let t=e.kind===`advanced`;return(0,H.jsx)(sD,{title:`Advance outcome`,children:(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-xs`,children:[(0,H.jsx)(`span`,{className:`inline-flex items-center px-2 py-1 font-medium`,style:{backgroundColor:t?`var(--success)20`:`var(--blocked)20`,color:t?`var(--success)`:`var(--blocked)`},children:t?`Advanced`:`Blocked`}),(0,H.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[`attempt `,e.attemptId.slice(-8),` at event #`,e.recordedAtEventIndex]})]})})}function eD({validations:e}){return(0,H.jsx)(sD,{title:`Validations (${e.length})`,children:(0,H.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,H.jsx)(tD,{validation:e},e.validationId))})})}function tD({validation:e}){let t=e.outcome===`pass`;return(0,H.jsxs)(`div`,{className:`bg-[var(--bg-primary)] border border-[var(--border)] px-4 py-3 text-xs space-y-2`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`inline-flex items-center px-2 py-1 font-medium`,style:{backgroundColor:t?`var(--success)20`:`var(--error)20`,color:t?`var(--success)`:`var(--error)`},children:t?`Pass`:`Fail`}),(0,H.jsx)(`span`,{className:`text-[var(--text-muted)] font-mono`,children:e.contractRef})]}),e.issues.length>0&&(0,H.jsxs)(`div`,{className:`space-y-1`,children:[(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] mb-1`,children:`Issues`}),(0,H.jsx)(`ul`,{className:`list-disc list-inside text-[var(--error)] space-y-0.5`,children:e.issues.map((e,t)=>(0,H.jsx)(`li`,{children:e},t))})]}),e.suggestions.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] mb-1`,children:`Suggestions`}),(0,H.jsx)(`ul`,{className:`list-disc list-inside text-[var(--text-secondary)] space-y-0.5`,children:e.suggestions.map((e,t)=>(0,H.jsx)(`li`,{children:e},t))})]})]})}function nD({gaps:e}){return(0,H.jsx)(sD,{title:`Gaps (${e.length})`,children:(0,H.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,H.jsxs)(`div`,{className:`flex items-start gap-3 text-xs bg-[var(--bg-primary)] border border-[var(--border)] px-3 py-3`,children:[(0,H.jsx)(`span`,{className:`shrink-0 inline-flex items-center px-2 py-1 font-medium`,style:{backgroundColor:e.isResolved?`var(--success)20`:e.severity===`critical`?`var(--error)20`:`var(--warning)20`,color:e.isResolved?`var(--success)`:e.severity===`critical`?`var(--error)`:`var(--warning)`},children:e.isResolved?`Resolved`:e.severity===`critical`?`Critical`:`Non-critical`}),(0,H.jsx)(`span`,{className:`text-[var(--text-secondary)] leading-relaxed`,children:e.summary})]},e.gapId))})})}var rD=1e5,iD=[{prefix:`text/`,render:e=>(0,H.jsx)(`pre`,{className:`text-[var(--text-secondary)] whitespace-pre-wrap break-words font-mono max-h-40 overflow-y-auto`,children:typeof e==`string`?e:String(e)})},{prefix:`application/json`,render:e=>(0,H.jsx)(`pre`,{className:`text-[var(--text-secondary)] whitespace-pre-wrap break-words font-mono max-h-40 overflow-y-auto`,children:typeof e==`string`?e:JSON.stringify(e,null,2)})}];function aD(e){if(e.byteLength>rD)return(0,H.jsxs)(`div`,{className:`text-[var(--text-muted)] italic`,children:[`Content too large to display (`,dD(e.byteLength),` -- limit `,dD(rD),`)`]});let t=iD.find(t=>e.contentType.startsWith(t.prefix));return t?t.render(e.content):(0,H.jsx)(`pre`,{className:`text-[var(--text-secondary)] whitespace-pre-wrap break-words font-mono max-h-40 overflow-y-auto`,children:typeof e.content==`string`?e.content:JSON.stringify(e.content,null,2)})}function oD({artifacts:e}){return(0,H.jsx)(sD,{title:`Artifacts (${e.length})`,children:(0,H.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,H.jsxs)(`div`,{className:`bg-[var(--bg-primary)] border border-[var(--border)] px-4 py-3 text-xs space-y-2`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[var(--text-muted)]`,children:[(0,H.jsx)(`span`,{children:e.contentType}),(0,H.jsx)(`span`,{children:`//`}),(0,H.jsx)(`span`,{children:dD(e.byteLength)})]}),aD(e)]},e.sha256))})})}function sD({title:e,children:t}){return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-2`,children:(0,H.jsx)(Go,{children:e})}),t]})}function cD({label:e,value:t,mono:n=!1}){return(0,H.jsxs)(`div`,{className:`bg-[var(--bg-primary)] border border-[var(--border)] px-4 py-3`,children:[(0,H.jsx)(Go,{children:e}),(0,H.jsx)(`div`,{className:n?`mt-2 font-mono text-sm text-[var(--text-secondary)] truncate`:`mt-2 text-sm text-[var(--text-primary)]`,children:t})]})}var lD={step:{label:`Step`,color:`var(--accent)`},checkpoint:{label:`Checkpoint`,color:`var(--success)`},blocked_attempt:{label:`Blocked`,color:`var(--error)`}};function uD({kind:e}){let t=lD[e];return(0,H.jsx)(`span`,{className:`inline-flex items-center px-2 py-1 font-medium`,style:{backgroundColor:`${t.color}20`,color:t.color},children:t.label})}function dD(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function fD(e){return e.length>16?`\u2026${e.slice(-16)}`:e}function pD({data:e}){let t=e.runs[0]??null,n=t?.workflowName??t?.workflowId??`--`,r=t?.workflowHash?.slice(0,12)??`--`;return(0,H.jsxs)(`div`,{className:`bg-[var(--bg-card)] border border-[var(--border)] px-5 py-4 corner-brackets`,style:{backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`},children:[e.sessionTitle&&(0,H.jsx)(`h2`,{className:`text-base font-medium text-[var(--text-primary)] mb-3`,children:e.sessionTitle}),(0,H.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-8 gap-y-2`,children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)] self-center`,children:`Session`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)] self-center`,children:fD(e.sessionId)}),(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)] self-center`,children:`Workflow`}),(0,H.jsx)(`dd`,{className:`text-sm text-[var(--text-primary)] self-center`,children:n}),(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)] self-center`,children:`Hash`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)] self-center`,children:r}),(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)] self-center`,children:`Status`}),(0,H.jsxs)(`dd`,{className:`self-center flex items-center gap-2`,children:[(0,H.jsx)(io,{health:e.health}),e.health===`healthy`&&(0,H.jsx)(`span`,{className:`text-sm text-[var(--text-primary)]`,children:`Healthy`})]}),(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)] self-center`,children:`Runs`}),(0,H.jsxs)(`dd`,{className:`text-sm text-[var(--text-primary)] self-center`,children:[e.runs.length,` run`,e.runs.length===1?``:`s`]})]})]})}function mD(e){if(e<6e4)return`${Math.round(e/1e3)}s`;let t=Math.floor(e/6e4),n=Math.round(e%6e4/1e3);return n>0?`${t}m ${n}s`:`${t}m`}function hD({sessionId:e,metrics:t}){let[n,r]=(0,V.useState)({kind:`idle`}),i=qy(e,!1),a=t.startGitSha!==null&&t.endGitSha!==null,o=async()=>{r({kind:`loading`});try{let e=await i.refetch();e.isSuccess&&e.data?r({kind:`loaded`,linesAdded:e.data.linesAdded,linesRemoved:e.data.linesRemoved,filesChanged:e.data.filesChanged}):r({kind:`error`,message:e.error instanceof Error?e.error.message:`Diff computation failed`})}catch(e){r({kind:`error`,message:e instanceof Error?e.message:`Diff computation failed`})}};return(0,H.jsxs)(`div`,{className:`bg-[var(--bg-card)] border border-[var(--border)] px-5 py-4 corner-brackets space-y-4`,style:{backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`},children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)]`,children:`Session Metrics`}),(0,H.jsx)(`span`,{className:`font-mono text-[10px] text-[var(--text-muted)]`,children:`Session-level totals across all runs.`})]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[t.outcome!==null&&(0,H.jsx)(`span`,{className:`px-2 py-1 text-xs font-mono border border-[var(--border)] text-[var(--text-secondary)] bg-[var(--bg-card)]`,children:t.outcome}),t.durationMs!==void 0&&(0,H.jsx)(`span`,{className:`px-2 py-1 text-xs font-mono border border-[var(--border)] text-[var(--text-secondary)] bg-[var(--bg-card)]`,children:mD(t.durationMs)}),t.filesChanged!==null&&(0,H.jsxs)(`span`,{className:`px-2 py-1 text-xs font-mono border border-[var(--border)] text-[var(--text-secondary)] bg-[var(--bg-card)]`,children:[t.filesChanged,` file`,t.filesChanged===1?``:`s`,` changed`]}),t.captureConfidence!==`none`&&(0,H.jsxs)(`span`,{className:`px-2 py-1 text-xs font-mono border border-[var(--border)] text-[var(--text-muted)] bg-[var(--bg-card)]`,children:[t.captureConfidence,` confidence`]})]}),(0,H.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-8 gap-y-2`,children:[t.gitBranch!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Git Branch`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)] self-center`,children:t.gitBranch})]}),t.startGitSha!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Start SHA`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)] self-center`,children:t.startGitSha.slice(0,12)})]}),t.endGitSha!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`End SHA`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)] self-center`,children:t.endGitSha.slice(0,12)})]}),t.durationMs!==void 0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Duration`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)] self-center`,children:mD(t.durationMs)})]}),t.agentCommitShas.length>0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-start`,children:`Commits`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)]`,children:t.agentCommitShas.map(e=>(0,H.jsx)(`div`,{children:e.slice(0,12)},e))})]}),t.outcome!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Outcome`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[t.outcome,` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(agent-reported)`})]})]}),t.filesChanged!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Files Changed`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[t.filesChanged,` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(agent-reported)`})]})]}),t.linesAdded!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Lines Added`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[t.linesAdded,` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(agent-reported)`})]})]}),t.linesRemoved!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Lines Removed`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[t.linesRemoved,` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(agent-reported)`})]})]}),t.prNumbers.length>0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`PRs`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[t.prNumbers.join(`, `),` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(agent-reported)`})]})]}),n.kind===`loaded`&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`LOC Added`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[n.linesAdded,` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(git diff)`})]}),(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`LOC Removed`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[n.linesRemoved,` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(git diff)`})]})]})]}),a&&n.kind!==`loaded`&&(0,H.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[n.kind===`idle`&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>{o()},className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] hover:text-[var(--text-primary)] border border-[var(--border)] px-3 py-1.5 transition-colors`,children:`Load diff`}),n.kind===`loading`&&(0,H.jsx)(`span`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)]`,children:`Computing...`}),n.kind===`error`&&(0,H.jsxs)(`span`,{className:`text-xs text-[var(--error)]`,children:[n.message,` `,(0,H.jsx)(`button`,{type:`button`,onClick:()=>{o()},className:`underline text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors`,children:`Retry`})]})]})]})}function gD({runs:e}){let t=e.some(e=>e.preferredTipNodeId!==null),n=e.some(e=>e.executionTraceSummary!==null);return(0,H.jsxs)(`div`,{className:`border border-[var(--border)] px-4 py-3 text-xs text-[var(--text-muted)] space-y-1`,children:[(0,H.jsx)(`p`,{children:t?`Nodes with a gold border are the current execution tips — click any node to inspect its execution detail.`:`Click any node in the DAG to inspect its execution detail.`}),n&&(0,H.jsxs)(`p`,{children:[`This run has execution trace data. Click`,` `,(0,H.jsx)(`span`,{className:`font-mono uppercase tracking-[0.16em]`,children:`[ TRACE ]`}),` `,`to see why certain steps ran, were skipped, or repeated.`]})]})}function _D({viewModel:e}){let{state:t,onSelectNode:n,onCloseNode:r}=e;if(t.kind===`loading`)return(0,H.jsx)(`div`,{className:`text-[var(--text-secondary)]`,children:`Loading session...`});if(t.kind===`error`)return(0,H.jsxs)(`div`,{className:`text-[var(--error)] bg-[var(--bg-card)] rounded-lg p-4`,children:[`Failed to load session: `,t.message]});let{sessionId:i,data:a,selectedNode:o,selectedRun:s}=t;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsx)(pD,{data:a}),a.metrics!==null&&(0,H.jsx)(hD,{sessionId:i,metrics:a.metrics}),a.runs.length===0?(0,H.jsx)(`div`,{className:`text-center py-16 text-[var(--text-secondary)]`,children:`No runs in this session`}):(0,H.jsxs)(H.Fragment,{children:[o===null&&(0,H.jsx)(gD,{runs:a.runs}),(0,H.jsx)(`div`,{className:`space-y-6`,children:a.runs.map(e=>(0,H.jsx)(vD,{run:e,selectedNodeId:o?.runId===e.runId?o.nodeId:null,onNodeClick:n},e.runId))})]})]}),(0,H.jsxs)(co,{cut:18,borderColor:`rgba(244, 196, 48, 0.35)`,background:`rgba(27, 31, 44, 0.78)`,dropShadow:`drop-shadow(0 16px 48px rgba(0,0,0,0.9)) drop-shadow(0 2px 12px rgba(244,196,48,0.15))`,backdropFilter:`blur(16px)`,className:`fixed top-3 right-3 bottom-3 w-[560px] max-w-[calc(92vw-12px)] transition-transform duration-200 ease-out`,style:{zIndex:40,transform:o?`translateX(0)`:`translateX(calc(100% + 12px))`},children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-[var(--border)] shrink-0 console-blueprint-grid`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)]`,children:`Node detail`}),(0,H.jsx)(`button`,{onClick:r,className:`text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors text-xl leading-none px-1`,"aria-label":`Close`,children:`×`})]}),(0,H.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,H.jsx)(BE,{sessionId:i,nodeId:o?.nodeId??null,runStatus:s?.status??`complete`,currentNodeId:s?.preferredTipNodeId??null,executionTraceSummary:s?.executionTraceSummary??null})})]})]})}function vD({run:e,selectedNodeId:t,onNodeClick:n}){let r=e.executionTraceSummary!==null,[i,a]=(0,V.useState)(`dag`);return(0,H.jsxs)(co,{cut:10,background:`rgba(27, 31, 44, 0.72)`,backdropFilter:`blur(8px)`,className:`relative`,style:{height:r?`542px`:`506px`},children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-[var(--border)] shrink-0`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-[var(--text-primary)]`,children:e.workflowName??e.workflowId??`Run`}),(0,H.jsx)(`span`,{className:`font-mono text-xs text-[var(--text-muted)]`,children:e.runId}),(0,H.jsxs)(`span`,{className:`font-mono text-xs text-[var(--text-muted)]`,children:[e.nodes.length,` nodes · `,e.tipNodeIds.length,` tip`,e.tipNodeIds.length===1?``:`s`]})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.hasUnresolvedCriticalGaps&&(0,H.jsx)(`span`,{className:`text-xs text-[var(--warning)]`,children:`Critical gaps`}),(0,H.jsx)(ro,{status:e.status})]})]}),r&&(0,H.jsxs)(`div`,{role:`tablist`,"aria-label":`Run view mode`,className:`flex items-center border-b border-[var(--border)] shrink-0 h-9 px-2 gap-0.5`,onKeyDown:e=>{e.key===`ArrowRight`&&(e.preventDefault(),a(`trace`)),e.key===`ArrowLeft`&&(e.preventDefault(),a(`dag`))},children:[(0,H.jsxs)(`button`,{type:`button`,id:`tab-dag`,role:`tab`,tabIndex:i===`dag`?0:-1,"aria-selected":i===`dag`,onClick:()=>a(`dag`),className:[`tab-btn px-3 py-1.5 font-mono text-[10px] uppercase tracking-[0.25em] transition-colors duration-150`,i===`dag`?`tab-btn--active text-[var(--accent)]`:`text-[var(--text-secondary)] hover:text-[var(--text-primary)]`].join(` `),style:i===`dag`?{backgroundColor:`rgba(244, 196, 48, 0.06)`}:void 0,children:[(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tr`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--bl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--br`,"aria-hidden":`true`}),`DAG`]}),(0,H.jsxs)(`button`,{type:`button`,id:`tab-trace`,role:`tab`,tabIndex:i===`trace`?0:-1,"aria-selected":i===`trace`,onClick:()=>a(`trace`),className:[`tab-btn px-3 py-1.5 font-mono text-[10px] uppercase tracking-[0.25em] transition-colors duration-150`,i===`trace`?`tab-btn--active text-[var(--accent)]`:`text-[var(--text-secondary)] hover:text-[var(--text-primary)]`].join(` `),style:i===`trace`?{backgroundColor:`rgba(244, 196, 48, 0.06)`}:void 0,children:[(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tr`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--bl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--br`,"aria-hidden":`true`}),`TRACE`]})]}),(0,H.jsx)(`div`,{role:`tabpanel`,"aria-labelledby":i===`dag`?`tab-dag`:`tab-trace`,className:`flex-1`,children:i===`trace`&&e.executionTraceSummary!==null?(0,H.jsx)(By,{summary:e.executionTraceSummary,runStatus:e.status}):(0,H.jsx)(my,{run:e,selectedNodeId:t,onNodeClick:t=>n(e.runId,t)})})]})}function yD(){let[e,t]=(0,V.useState)(0),[n,r]=(0,V.useState)(0),[i,a]=(0,V.useState)(38),[o,s]=(0,V.useState)(62),[c,l]=(0,V.useState)(3),[u,d]=(0,V.useState)(2),[f,p]=(0,V.useState)(``),[m,h]=(0,V.useState)(!1),g=(0,V.useRef)(!1),_=(0,V.useRef)(null),v=(0,V.useRef)(null),y=(0,V.useRef)(null),b=(e,n,i,o,c,u)=>{g.current=!0,h(!0),t(e=>e+1),r(Math.floor(Math.random()*4)),a(5+Math.floor(Math.random()*80)),s(5+Math.floor(Math.random()*80)),l(2+Math.floor(Math.random()*40)),d(2+Math.floor(Math.random()*25)),p(i===`horizontal`?n===`next`?`modal-content--exit-h-next`:`modal-content--exit-h-prev`:n===`next`?`modal-content--exit-v-next`:`modal-content--exit-v-prev`),c.current&&(c.current.scrollTop=0);let f=u[e].id;setTimeout(()=>{o(f),p(i===`horizontal`?n===`next`?`modal-content--enter-h-next`:`modal-content--enter-h-prev`:n===`next`?`modal-content--enter-v-next`:`modal-content--enter-v-prev`),h(!1)},80),setTimeout(()=>{if(p(``),g.current=!1,_.current!==null){let e=_.current;_.current=null;let t=e>u.findIndex(e=>e.id===v.current)?`next`:`prev`;y.current?.(e,t,`horizontal`,o,c,u)}},240)};return y.current=b,{state:{isAnimating:g.current,contentAnimClass:f,borderFlashing:m,scanline:e>0?{key:e,crtOffset:n,glitchY:i,glitchY2:o,glitchW:c,glitchW2:u}:null},startTransition:b,navigate:(e,t,n,r,i,a)=>{if(t.length<=1)return;let o=t.findIndex(t=>t.id===e);if(o===-1)return;let s=n===`next`?(o+1)%t.length:(o-1+t.length)%t.length;if(g.current){_.current=s;return}b(s,n,r,i,a,t)},selectedWorkflowIdRef:v}}var bD=[{id:`coding`,label:`Coding`},{id:`review_audit`,label:`Review & Audit`},{id:`investigation`,label:`Investigation`},{id:`design`,label:`Design`},{id:`documentation`,label:`Documentation`},{id:`tickets`,label:`Tickets`},{id:`learning`,label:`Learning`},{id:`authoring`,label:`Workflow Authoring`}],xD=Object.fromEntries(bD.map(e=>[e.id,e.label]));function SD({label:e,count:t,countLabel:n=`workflow`,showRule:r=!0,separator:i=`//`}){return(0,H.jsxs)(`div`,{className:`flex items-center gap-3 mb-3 mt-2`,children:[(0,H.jsxs)(`span`,{className:`font-mono text-[11px] uppercase tracking-[0.30em] text-[var(--text-secondary)] shrink-0`,children:[e,t==null?``:` ${i} ${t} ${n}${t===1?``:`s`}`]}),r&&(0,H.jsx)(`div`,{className:`flex-1 h-px bg-[var(--border)]`})]})}function CD({segments:e,className:t=``}){return(0,H.jsx)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-0 ${t}`,children:e.map((t,n)=>{let r=n===e.length-1,i=!!t.onClick;return(0,H.jsxs)(`span`,{className:`flex items-center`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[10px] tracking-[0.25em] text-[var(--text-muted)] mx-1`,children:`//`}),i?(0,H.jsx)(`button`,{type:`button`,onClick:t.onClick,className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] hover:text-[var(--accent)] transition-colors cursor-pointer`,children:t.label.toUpperCase()}):(0,H.jsx)(`span`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] ${r?`text-[var(--text-secondary)]`:`text-[var(--text-muted)]`}`,"aria-current":r?`page`:void 0,children:t.label.toUpperCase()})]},n)})})}function wD({viewModel:e}){let{state:t}=e;if(t.kind===`not_found`)return(0,H.jsx)(`div`,{className:`space-y-5 max-w-3xl`,children:(0,H.jsx)(AD,{message:``,is404:!0,onRetry:()=>void 0,onBack:t.onBack})});if(t.kind===`error`)return(0,H.jsx)(`div`,{className:`space-y-5 max-w-3xl`,children:(0,H.jsx)(AD,{message:t.message,is404:!1,onRetry:t.onRetry,onBack:t.onBack})});if(t.kind===`loading`){let{cached:e,activeTagLabel:n,onBack:r}=t;return(0,H.jsxs)(`div`,{className:`space-y-5 max-w-3xl`,children:[(0,H.jsx)(CD,{segments:n?[{label:`Workflows`,onClick:r},{label:n}]:[{label:`Workflows`,onClick:r}]}),e?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(TD,{name:e.name,description:e.description,tags:e.tags,source:e.source,stepCount:void 0}),(0,H.jsx)(`div`,{className:`space-y-4`,children:(0,H.jsx)(OD,{})})]}):(0,H.jsx)(kD,{})]})}let{workflow:n,name:r,description:i,tags:a,source:o,activeTagLabel:s,onPrev:c,onNext:l,onBack:u}=t;return(0,H.jsxs)(`div`,{className:`space-y-5 max-w-3xl`,children:[(0,H.jsx)(CD,{segments:s?[{label:`Workflows`,onClick:u},{label:s}]:[{label:`Workflows`,onClick:u}]}),(0,H.jsx)(TD,{name:r,description:i,tags:a,source:o,stepCount:n.stepCount}),(c??l)&&(0,H.jsxs)(`div`,{className:`flex items-center gap-4`,children:[c&&(0,H.jsxs)(`button`,{type:`button`,onClick:c,className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] hover:text-[var(--accent)] transition-colors`,children:[`<`,` PREV`]}),l&&(0,H.jsxs)(`button`,{type:`button`,onClick:l,className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] hover:text-[var(--accent)] transition-colors`,children:[`NEXT `,`>`]})]}),(0,H.jsx)(ED,{detail:n,name:r}),(0,H.jsx)(CD,{segments:[{label:`Workflows`,onClick:u}]})]})}function TD({name:e,description:t,tags:n,source:r,stepCount:i}){return(0,H.jsxs)(`div`,{className:`border border-[var(--border)] px-5 py-5 console-blueprint-grid`,children:[(0,H.jsx)(`p`,{className:`font-mono text-[10px] uppercase tracking-[0.35em] text-[var(--text-muted)] mb-2`,children:`// Workflow`}),(0,H.jsx)(`h2`,{className:`font-mono text-xl font-bold uppercase tracking-[0.08em] leading-tight mb-3`,style:{color:`var(--accent)`,textShadow:`0 0 24px rgba(244,196,48,0.45), 0 0 48px rgba(244,196,48,0.15)`},children:e}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i!=null&&i>0&&(0,H.jsxs)(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 border border-[var(--border)] text-[var(--text-secondary)]`,children:[i,` step`,i===1?``:`s`]}),n.filter(e=>e!==`routines`).map(e=>(0,H.jsx)(`span`,{"aria-hidden":`true`,className:`font-mono text-[10px] px-1.5 py-0.5 bg-[var(--bg-secondary)] text-[var(--text-muted)]`,children:e},e)),r&&(0,H.jsxs)(`span`,{"aria-hidden":`true`,className:`font-mono text-[10px] px-1.5 py-0.5 border border-[var(--border)] text-[var(--text-muted)]`,children:[`src: `,r.displayName]})]}),t&&(0,H.jsx)(`p`,{className:`text-sm text-[var(--text-secondary)] leading-relaxed mt-3`,children:t})]})}function ED({detail:e,name:t}){let n=e.about!==void 0&&e.about.length>0,r=e.examples!==void 0&&e.examples.length>0,i=e.preconditions!==void 0&&e.preconditions.length>0;return n||r||i?(0,H.jsxs)(`div`,{className:`space-y-6`,children:[n&&(0,H.jsxs)(`section`,{children:[(0,H.jsx)(`h3`,{className:`text-xs font-semibold text-[var(--text-muted)] uppercase tracking-wider mb-3`,children:`About`}),(0,H.jsx)(zE,{children:e.about})]}),r&&(0,H.jsxs)(`section`,{children:[(0,H.jsx)(`h3`,{className:`text-xs font-semibold text-[var(--text-muted)] uppercase tracking-wider mb-3`,children:`Try it with:`}),(0,H.jsx)(`ul`,{className:`space-y-2`,children:e.examples.map(e=>(0,H.jsxs)(`li`,{className:`flex items-start gap-3 bg-[var(--bg-card)] border border-[var(--border)] rounded-none px-4 py-3`,children:[(0,H.jsx)(`div`,{"aria-hidden":`true`,className:`w-0.5 shrink-0 self-stretch rounded-full`,style:{backgroundColor:`var(--accent)`}}),(0,H.jsxs)(`span`,{className:`text-sm text-[var(--text-secondary)] leading-relaxed`,children:[`"`,e,`"`]})]},e))})]}),i&&(0,H.jsxs)(`section`,{children:[(0,H.jsx)(`h3`,{className:`text-xs font-semibold text-[var(--text-muted)] uppercase tracking-wider mb-3`,children:`Before you start:`}),(0,H.jsx)(`ul`,{className:`space-y-1.5`,children:e.preconditions.map(e=>(0,H.jsxs)(`li`,{className:`flex items-start gap-2 text-sm text-[var(--text-secondary)]`,children:[(0,H.jsx)(`span`,{className:`shrink-0 text-[var(--text-muted)] mt-0.5`,children:`•`}),(0,H.jsx)(`span`,{children:e})]},e))})]}),(0,H.jsx)(DD,{name:t})]}):(0,H.jsx)(`p`,{className:`text-sm text-[var(--text-muted)] italic`,children:`No additional documentation available.`})}function DD({name:e}){let[t,n]=(0,V.useState)(!1),r=`Use the ${e} to [your goal]`;return(0,H.jsxs)(`section`,{children:[(0,H.jsx)(`h3`,{className:`text-xs font-semibold text-[var(--text-muted)] uppercase tracking-wider mb-3`,children:`Start with this prompt`}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3 border border-[var(--border)] px-4 py-3`,children:[(0,H.jsxs)(`span`,{className:`flex-1 text-sm text-[var(--text-secondary)] font-mono truncate`,children:[`"`,r,`"`]}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>{navigator.clipboard.writeText(r).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},className:`shrink-0 text-xs font-mono text-[var(--accent)] hover:text-[var(--text-primary)] transition-colors`,children:t?`Copied!`:`Copy`})]})]})}function OD(){return(0,H.jsxs)(`div`,{className:`space-y-3 motion-safe:animate-pulse`,children:[(0,H.jsx)(`div`,{className:`h-3 w-16 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-4 w-full rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-4 w-5/6 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-4 w-4/6 rounded bg-[var(--bg-tertiary)]`})]})}function kD(){return(0,H.jsxs)(`div`,{className:`space-y-6 motion-safe:animate-pulse`,children:[(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(`div`,{className:`h-6 w-1/2 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsx)(`div`,{className:`h-5 w-16 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-5 w-24 rounded bg-[var(--bg-tertiary)]`})]}),(0,H.jsx)(`div`,{className:`h-4 w-full rounded bg-[var(--bg-tertiary)]`})]}),(0,H.jsx)(OD,{})]})}function AD({message:e,is404:t,onRetry:n,onBack:r}){return(0,H.jsxs)(`div`,{className:`space-y-4 bg-[var(--bg-card)] border border-[var(--border)] p-4`,children:[(0,H.jsx)(`p`,{className:`text-sm text-[var(--error)]`,children:t?`Workflow not found.`:e}),(0,H.jsxs)(`div`,{className:`flex gap-3`,children:[!t&&(0,H.jsx)(`button`,{type:`button`,onClick:n,className:`text-sm text-[var(--accent)] hover:text-[var(--accent-hover)] transition-colors`,children:`Try again`}),(0,H.jsxs)(`button`,{type:`button`,onClick:r,"aria-label":`Back to workflows list`,className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] hover:text-[var(--accent)] transition-colors`,children:[`<`,` WORKFLOWS`]})]})]})}function jD(e){if(e.size<2)return 1;let t=new Set;for(let n of e.values())t.add(Math.round(n.getBoundingClientRect().top));if(t.size<2){let t=Math.round(e.get(0)?.getBoundingClientRect().top??0),n=0;for(let r of e.values())Math.round(r.getBoundingClientRect().top)===t&&n++;return Math.max(1,n)}let n=Math.round(e.get(0)?.getBoundingClientRect().top??0),r=0;for(let t of e.values())Math.round(t.getBoundingClientRect().top)===n&&r++;return Math.max(1,r)}function MD(e,t,n,r){if(n===0)return 0;let i=(e??(t>0?-1:n))+t;return r?(i%n+n)%n:Math.max(0,Math.min(n-1,i))}function ND(e,t,n,r,i){if(n===0)return 0;let a=e??0,o=a%r,s=Math.floor(a/r),c=Math.ceil(n/r),l=s+t;l=i?(l%c+c)%c:Math.max(0,Math.min(c-1,l));let u=l*r+o;return Math.min(u,n-1)}function PD({count:e,cols:t=`auto`,onActivate:n,loop:r=!0}){let[i,a]=(0,V.useState)(null),o=(0,V.useRef)(new Map),s=(0,V.useCallback)(e=>{a(e),e!==null&&o.current.get(e)?.focus()},[]),c=(0,V.useCallback)(()=>t===`auto`?jD(o.current):Math.max(1,t),[t]);return{focusedIndex:i,setFocusedIndex:s,getItemProps:(0,V.useCallback)(t=>({tabIndex:i===null?t===0?0:-1:i===t?0:-1,onFocus:()=>{a(t)},onKeyDown:i=>{let a=c(),o=null;switch(i.key){case`ArrowRight`:case`d`:case`D`:o=MD(t,1,e,r);break;case`ArrowLeft`:case`a`:case`A`:o=MD(t,-1,e,r);break;case`ArrowDown`:case`s`:case`S`:o=ND(t,1,e,a,r);break;case`ArrowUp`:case`w`:case`W`:o=ND(t,-1,e,a,r);break;case`Home`:o=0;break;case`End`:o=e-1;break;case`Enter`:case` `:i.preventDefault(),n?.(t);return;default:return}o!==null&&(i.preventDefault(),s(o))},ref:e=>{e?o.current.set(t,e):o.current.delete(t)}}),[i,e,r,c,n,s]),containerProps:{role:`grid`}}}function FD(e){let t=Zy(e),n=()=>{t.refetch()};return t.isLoading?{kind:`loading`}:t.error?t.error instanceof Hy&&t.error.status===404?{kind:`not_found`}:{kind:`error`,message:t.error instanceof Error?t.error.message:`Could not load workflow details.`,refetch:n}:t.data?{kind:`ready`,detail:t.data,refetch:n}:{kind:`loading`}}function ID(){let e=Yy();return{workflows:e.data?.workflows.filter(e=>!e.tags.includes(`routines`)),isLoading:e.isLoading,error:e.error instanceof Error?e.error:null,refetch:e.refetch}}function LD(e,t){if(!e)return{prevWorkflow:null,nextWorkflow:null};let n=t.findIndex(t=>t.id===e);return n===-1?{prevWorkflow:null,nextWorkflow:null}:{prevWorkflow:n>0?t[n-1]??null:null,nextWorkflow:n<t.length-1?t[n+1]??null:null}}function RD({workflowId:e,activeTag:t,onBack:n,onNavigateToWorkflow:r}){let i=FD(e),a=ID().workflows,o=(0,V.useRef)(null),s=(0,V.useRef)(null),c=(0,V.useRef)(r);c.current=r;let l=a??[],{prevWorkflow:u,nextWorkflow:d}=(0,V.useMemo)(()=>LD(e,l),[e,l]),f=u?()=>c.current(u.id):null,p=d?()=>c.current(d.id):null;o.current=f,s.current=p;let m=i.kind===`ready`;return(0,V.useEffect)(()=>{if(!m)return;function e(e){e.metaKey||e.ctrlKey||e.altKey||(e.key===`ArrowLeft`?(e.preventDefault(),o.current?.()):e.key===`ArrowRight`&&(e.preventDefault(),s.current?.()))}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[m]),{state:(0,V.useMemo)(()=>{let r=a?.find(t=>t.id===e)??void 0,o=t?xD[t]??t:null;if(i.kind===`not_found`)return{kind:`not_found`,onBack:n};if(i.kind===`error`)return{kind:`error`,message:i.message,onBack:n,onRetry:i.refetch};if(i.kind===`ready`){let t=i.detail;return{kind:`ready`,workflow:t,name:t.name??r?.name??e??``,description:t.description??r?.description??null,tags:t.tags??r?.tags??[],source:t.source??r?.source??null,activeTagLabel:o,adjacentWorkflows:l,onPrev:f,onNext:p,onBack:n}}return{kind:`loading`,cached:r??null,activeTagLabel:o,onBack:n}},[i,a,e,t,l,f,p,n])}}function zD(e){let t=new Set(bD.map(e=>e.id)),n=new Map,r=[];for(let i of e){let e=i.tags.find(e=>e!==`routines`&&t.has(e));if(e){let t=n.get(e)??[];t.push(i),n.set(e,t)}else r.push(i)}let i=bD.filter(e=>n.has(e.id)).map(e=>({tagId:e.id,label:e.label,workflows:n.get(e.id)}));return r.length>0&&i.push({tagId:null,label:`Other`,workflows:r}),i}function BD({viewModel:e}){let{state:t,dispatch:n,triggerRef:r,onCardSelect:i}=e,a=(0,V.useRef)(null),o=(0,V.useRef)(null),s=yD(),c=t.kind===`ready`?t.selectedWorkflowId:null;if((0,V.useEffect)(()=>{if(c){let e=requestAnimationFrame(()=>a.current?.focus());return()=>cancelAnimationFrame(e)}},[c]),t.kind===`loading`)return(0,H.jsx)(WD,{});if(t.kind===`error`)return(0,H.jsx)(GD,{message:t.message,onRetry:t.onRetry});let{selectedTag:l,selectedSource:u,hintVisible:d,filteredWorkflows:f,flatWorkflows:p,availableSources:m,sourceFilteredWorkflows:h,tagFilteredWorkflows:g}=t,_=new Set(bD.map(e=>e.id)),v=new Set(h.flatMap(e=>e.tags)),y=new Map(bD.map(e=>[e.id,h.filter(t=>t.tags.includes(e.id)).length])),b=h.filter(e=>!e.tags.some(e=>e!==`routines`&&_.has(e))).length,x=h.length,S=g.length;return(0,H.jsx)(VD,{selectedWorkflowId:c,selectedTag:l,selectedSource:u,hintVisible:d,filteredWorkflows:f,flatWorkflows:p,availableSources:m,tagsWithWorkflows:v,countByTag:y,otherCount:b,allTagCount:x,allSourceCount:S,countBySource:new Map(m.map(e=>[e.displayName,g.filter(t=>t.source.displayName===e.displayName).length])),currentIndex:p.findIndex(e=>e.id===c),dispatch:n,onCardSelect:i,triggerRef:r,modalPanelRef:a,scrollRef:o,modalTransition:s})}function VD({selectedWorkflowId:e,selectedTag:t,selectedSource:n,hintVisible:r,filteredWorkflows:i,flatWorkflows:a,availableSources:o,tagsWithWorkflows:s,countByTag:c,otherCount:l,allTagCount:u,allSourceCount:d,countBySource:f,currentIndex:p,dispatch:m,onCardSelect:h,modalPanelRef:g,scrollRef:_,modalTransition:v}){let y=RD({workflowId:e,activeTag:t,onBack:()=>m({type:`modal_closed`}),onNavigateToWorkflow:e=>m({type:`workflow_selected`,id:e})}),b=(0,V.useCallback)((t,n)=>{v.navigate(e,a,t,n,e=>{m({type:`workflow_selected`,id:e}),v.selectedWorkflowIdRef.current=e},_)},[a,e,v,m,_]);(0,V.useEffect)(()=>{if(!e)return;let t=[`ArrowLeft`,`ArrowRight`,`a`,`A`,`d`,`D`],n=[`ArrowUp`,`ArrowDown`,`w`,`W`,`s`,`S`],r=e=>{if(n.includes(e.key)){e.preventDefault(),e.stopPropagation();return}t.includes(e.key)&&(e.preventDefault(),e.stopPropagation(),b([`ArrowLeft`,`a`,`A`].includes(e.key)?`prev`:`next`,`horizontal`))};return document.addEventListener(`keydown`,r,{capture:!0}),()=>{document.removeEventListener(`keydown`,r,{capture:!0})}},[e,b]);let{getItemProps:x,containerProps:S}=PD({count:a.length,cols:`auto`,onActivate:(0,V.useCallback)(e=>{let t=a[e];if(!t)return;let n=document.activeElement;n instanceof HTMLButtonElement&&h(t.id,n)},[a,h])});return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h1`,{className:`font-mono text-2xl font-bold uppercase tracking-[0.12em] leading-none`,style:{color:`var(--accent)`,textShadow:`0 0 28px rgba(244,196,48,0.35)`},children:`Workflows`}),(0,H.jsxs)(`p`,{className:`font-mono text-[10px] tracking-[0.25em] text-[var(--text-muted)] mt-1.5`,children:[`// `,i.length,` available`]})]}),(0,H.jsxs)(`div`,{role:`group`,"aria-label":`Filter workflows by category`,className:`flex flex-wrap gap-1.5`,children:[(0,H.jsx)(HD,{label:`All`,count:u,isActive:t===null,disabled:!1,onClick:()=>m({type:`tag_changed`,tag:null})}),bD.filter(e=>s.has(e.id)).map(e=>(0,H.jsx)(HD,{label:e.label,count:c.get(e.id)??0,isActive:t===e.id,disabled:!1,onClick:()=>m({type:`tag_changed`,tag:t===e.id?null:e.id})},e.id)),l>0&&(0,H.jsx)(HD,{label:`Other`,count:l,isActive:t===`__other__`,disabled:!1,onClick:()=>m({type:`tag_changed`,tag:t===`__other__`?null:`__other__`})})]}),o.length>1&&(0,H.jsxs)(`div`,{role:`group`,"aria-label":`Filter workflows by source`,className:`flex flex-wrap gap-1.5`,children:[(0,H.jsx)(HD,{label:`All Sources`,count:d,isActive:n===null,disabled:!1,onClick:()=>m({type:`source_changed`,source:null})}),o.map(e=>(0,H.jsx)(HD,{label:e.displayName,count:f.get(e.displayName)??0,isActive:n===e.displayName,disabled:!1,onClick:()=>m({type:`source_changed`,source:n===e.displayName?null:e.displayName})},e.id))]}),i.length===0?(0,H.jsxs)(`div`,{className:`py-8 text-center space-y-3`,children:[(0,H.jsx)(`p`,{className:`text-sm text-[var(--text-muted)]`,children:`No workflows in this category.`}),t!==null&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>m({type:`tag_changed`,tag:null}),className:`text-sm text-[var(--accent)] hover:text-[var(--accent-hover)] transition-colors`,children:`Clear filter`})]}):t===null?(0,H.jsx)(`div`,{className:`space-y-6`,children:(()=>{let t=0;return zD(i).map(n=>(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(SD,{label:n.label,count:n.workflows.length,showRule:!0}),(0,H.jsx)(`div`,{...S,className:`grid grid-cols-2 lg:grid-cols-3 gap-3`,children:n.workflows.map(n=>(0,H.jsx)(UD,{workflow:n,onSelect:e=>h(n.id,e),navProps:x(t++),isActive:n.id===e},n.id))})]},n.tagId??`__other__`))})()}):(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(SD,{label:t===`__other__`?`Other`:xD[t]??t,count:i.length,showRule:!0}),(0,H.jsx)(`div`,{...S,className:`grid grid-cols-2 lg:grid-cols-3 gap-3`,children:i.map((t,n)=>(0,H.jsx)(UD,{workflow:t,onSelect:e=>h(t.id,e),navProps:x(n),isActive:t.id===e},t.id))})]}),(0,H.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-end justify-center p-4 pointer-events-none`,"aria-hidden":!e,children:[e&&(0,H.jsx)(`div`,{className:`absolute inset-0 pointer-events-auto`,style:{background:`rgba(0,0,0,0.22)`,backdropFilter:`blur(2px)`},onClick:()=>m({type:`modal_closed`})}),(0,H.jsx)(`div`,{ref:g,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":`Workflow detail${e?`: ${a.find(t=>t.id===e)?.name??``}`:``}`,className:`relative w-full max-w-3xl ${e?`pointer-events-auto`:`pointer-events-none`}${v.state.borderFlashing?` modal-border-flashing`:``}`,style:{height:`85vh`,transform:e?`translateY(0) scale(1)`:`translateY(24px) scale(0.97)`,opacity:+!!e,transition:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`opacity 150ms ease-out`:`transform 250ms ease-out, opacity 250ms ease-out`,backdropFilter:`blur(2px)`,WebkitBackdropFilter:`blur(2px)`},children:(0,H.jsxs)(co,{cut:20,borderColor:`rgba(244, 196, 48, 0.45)`,background:`rgba(15, 19, 31, 0.50)`,dropShadow:`drop-shadow(0 4px 24px rgba(244,196,48,0.15))`,className:`h-full flex flex-col`,children:[v.state.scanline!==null&&(0,H.jsx)(`div`,{className:`modal-scanline`,"aria-hidden":`true`,style:{"--crt-offset":`${v.state.scanline.crtOffset}px`,"--glitch-y":`${v.state.scanline.glitchY}%`,"--glitch-y2":`${v.state.scanline.glitchY2}%`,"--glitch-w":`${v.state.scanline.glitchW}px`,"--glitch-w2":`${v.state.scanline.glitchW2}px`,clipPath:so(20)}},v.state.scanline.key),(0,H.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-[var(--border)] shrink-0 console-blueprint-grid`,style:{background:`rgba(15, 19, 31, 0.55)`},children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-secondary)]`,children:`Workflow`}),p>=0&&(0,H.jsxs)(`span`,{className:`font-mono text-[10px] tracking-[0.20em] text-[var(--text-secondary)]`,children:[`[ `,p+1,` / `,a.length,` ]`]}),(0,H.jsx)(`span`,{className:`font-mono text-[9px] tracking-[0.15em] text-[var(--text-secondary)] transition-opacity duration-600`,style:{opacity:r?.5:0},"aria-hidden":`true`,children:`[ A / D ] NAV`})]}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>m({type:`modal_closed`}),className:`text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors text-xl leading-none`,"aria-label":`Close`,children:`×`})]}),(0,H.jsxs)(`div`,{ref:_,className:`flex-1 overflow-auto overscroll-contain px-6 py-5 ${v.state.contentAnimClass}`,style:{"--text-muted":`var(--text-secondary)`},children:[(0,H.jsx)(`div`,{"aria-live":`polite`,"aria-atomic":`true`,className:`sr-only`,children:a.find(t=>t.id===e)?.name??``}),e&&(0,H.jsx)(wD,{viewModel:y})]})]})})]})]})}function HD({label:e,count:t,isActive:n,disabled:r,onClick:i}){return(0,H.jsxs)(`button`,{type:`button`,onClick:i,disabled:r,"aria-pressed":n,className:[`px-3 py-2 min-w-[44px] min-h-[44px] rounded-none text-xs font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--accent)] focus-visible:ring-offset-2`,`disabled:opacity-50 disabled:cursor-not-allowed`,n?`border border-[var(--accent)] text-[var(--accent)] bg-transparent`:`text-[var(--text-muted)] hover:text-[var(--text-secondary)] hover:bg-[var(--bg-card)]`].join(` `),children:[e,` · `,t,n&&(0,H.jsx)(`span`,{className:`sr-only`,children:`(selected)`})]})}function UD({workflow:e,onSelect:t,navProps:n,isActive:r}){let i=e.tags.filter(e=>e!==`routines`).map(e=>xD[e]??e);return(0,H.jsx)(W,{variant:`grid`,onClick:e=>t(e.currentTarget),"aria-label":[e.name,e.description,i.length>0?`Tag: ${i.join(`, `)}`:null,`Source: ${e.source.displayName}`].filter(Boolean).join(`. `),style:r?{borderColor:`var(--accent)`,boxShadow:`0 0 0 1px rgba(244,196,48,0.4), 0 0 16px rgba(244,196,48,0.12)`}:void 0,...n,children:(0,H.jsxs)(`div`,{className:`flex flex-col flex-1 p-4 gap-2 min-w-0`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-[var(--text-primary)] group-hover:text-[var(--accent)] transition-colors leading-snug line-clamp-2`,children:e.name}),(0,H.jsx)(`p`,{className:`text-xs text-[var(--text-secondary)] line-clamp-3 leading-relaxed flex-1`,children:e.description}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mt-auto pt-2 border-t border-[var(--border)]`,children:[(0,H.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:i.slice(0,1).map(e=>(0,H.jsx)(`span`,{className:`font-mono text-[9px] px-1.5 py-0.5 bg-[var(--bg-secondary)] text-[var(--text-muted)]`,children:e},e))}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.stepCount!=null&&e.stepCount>0&&(0,H.jsxs)(`span`,{className:`font-mono text-[9px] text-[var(--text-muted)]`,children:[e.stepCount,`s`]}),(0,H.jsxs)(`span`,{className:`font-mono text-[9px] text-[var(--text-muted)] max-w-[80px] truncate`,children:[`src: `,e.source.displayName]})]})]})]})})}function WD(){return(0,H.jsx)(`div`,{className:`space-y-6 motion-safe:animate-pulse`,children:[0,1].map(e=>(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(`div`,{className:`h-3 w-24 bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`flex-1 h-px bg-[var(--bg-tertiary)]`})]}),(0,H.jsx)(`div`,{className:`grid grid-cols-2 lg:grid-cols-3 gap-3`,children:[0,1,2,3,4,5].map(e=>(0,H.jsxs)(`div`,{className:`min-h-[160px] bg-[var(--bg-card)] border border-[var(--border)] flex flex-col`,children:[(0,H.jsx)(`div`,{className:`h-[3px] bg-[var(--bg-tertiary)]`}),(0,H.jsxs)(`div`,{className:`p-4 flex flex-col gap-2 flex-1`,children:[(0,H.jsx)(`div`,{className:`h-4 w-3/4 bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-3 w-full bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-3 w-5/6 bg-[var(--bg-tertiary)]`}),(0,H.jsxs)(`div`,{className:`mt-auto pt-2 border-t border-[var(--border)] flex justify-between`,children:[(0,H.jsx)(`div`,{className:`h-3 w-12 bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-3 w-16 bg-[var(--bg-tertiary)]`})]})]})]},e))})]},e))})}function GD({message:e,onRetry:t}){return(0,H.jsxs)(`div`,{className:`space-y-3 py-8 text-center`,children:[(0,H.jsx)(`p`,{className:`text-sm text-[var(--error)]`,children:e}),(0,H.jsx)(`button`,{type:`button`,onClick:t,className:`text-sm text-[var(--accent)] hover:text-[var(--accent-hover)] transition-colors`,children:`Try again`})]})}var KD=[{value:`recent`,label:`Recent first`,compareFn:(e,t)=>t.startedAtMs-e.startedAtMs},{value:`slowest`,label:`Slowest first`,compareFn:(e,t)=>t.durationMs-e.durationMs}],qD={success:{color:`var(--success)`,label:`OK`,isError:!1},error:{color:`var(--error)`,label:`Error`,isError:!0},unknown_tool:{color:`var(--warning)`,label:`Unknown`,isError:!0}};function JD(e,t){let n=KD.find(e=>e.value===t);return[...e].sort(n.compareFn)}function YD(e){return e.reduce((e,t)=>Math.max(e,t.durationMs),0)}function XD(e){return e.filter(e=>qD[e.outcome].isError).length}function ZD(e){return e.length===0?null:Math.round(e.reduce((e,t)=>e+t.durationMs,0)/e.length)}function QD(e){return e.length===0?null:e.reduce((e,t)=>Math.max(e,t.startedAtMs),0)}function $D(e,t){return t>0?Math.round(e/t*120):0}function eO(e){return`${e} recorded`}var tO=[{key:`tool`,label:`Tool`,minWidth:`180px`},{key:`duration`,label:`Duration`,width:`220px`},{key:`started`,label:`Started`,width:`100px`},{key:`outcome`,label:`Outcome`}];function nO({viewModel:e}){let{state:t}=e;if(t.kind===`loading`)return(0,H.jsx)(oO,{});if(t.kind===`devModeOff`)return(0,H.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,H.jsx)(`p`,{className:`text-sm text-[var(--text-muted)] text-center`,children:`nothing to see here`})});if(t.kind===`error`)return(0,H.jsxs)(`div`,{className:`space-y-3 py-8 text-center`,children:[(0,H.jsx)(`p`,{className:`text-sm text-[var(--error)]`,children:t.message}),(0,H.jsx)(`button`,{type:`button`,onClick:t.retry,className:`text-sm text-[var(--accent)] hover:text-[var(--accent-hover)] transition-colors`,children:`Try again`})]});let{sorted:n,maxDuration:r,errorCount:i,avgMs:a,lastCallMs:o,countLabel:s,sortOrder:c,onSortChange:l}=t;return(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(0,H.jsxs)(`p`,{className:`text-sm text-[var(--text-secondary)]`,children:[s,` | `,(0,H.jsxs)(`span`,{style:{color:i>0?`var(--error)`:`var(--text-muted)`},children:[i,` errors`]}),` | `,`avg `,a===null?`--`:`${a}ms`,` | `,`last call `,o===null?`no calls yet`:uo(o)]}),(0,H.jsx)(`div`,{role:`radiogroup`,"aria-label":`Sort order`,className:`flex items-center gap-1`,children:KD.map(e=>(0,H.jsx)(aO,{label:e.label,isActive:c===e.value,onClick:()=>l(e.value)},e.value))}),(0,H.jsxs)(`table`,{className:`w-full text-sm border-collapse`,children:[(0,H.jsx)(`thead`,{children:(0,H.jsx)(`tr`,{className:`text-xs text-[var(--text-muted)] border-b border-[var(--border)]`,children:tO.map(e=>(0,H.jsx)(`th`,{scope:`col`,className:`text-left py-2 pr-4 font-medium`,style:{width:e.width,minWidth:e.minWidth},children:e.label},e.key))})}),(0,H.jsx)(`tbody`,{children:n.length===0?(0,H.jsx)(`tr`,{children:(0,H.jsx)(`td`,{colSpan:tO.length,className:`py-8 text-center text-sm text-[var(--text-muted)]`,children:`No tool calls recorded yet. Run a workflow to see timing data.`})}):n.map((e,t)=>(0,H.jsx)(rO,{obs:e,maxDuration:r},`${e.startedAtMs}-${e.toolName}-${t}`))})]})]})}function rO({obs:e,maxDuration:t}){let n=qD[e.outcome].isError,r=$D(e.durationMs,t);return(0,H.jsxs)(`tr`,{className:`border-b border-[var(--border)] hover:bg-[var(--bg-card)] transition-colors`,style:{borderLeft:n?`2px solid var(--error)`:`2px solid transparent`},children:[(0,H.jsx)(`td`,{className:`py-2 pr-4 font-mono text-[var(--text-primary)] overflow-hidden text-ellipsis`,title:e.toolName,style:{minWidth:`180px`,maxWidth:`240px`},children:(0,H.jsx)(`span`,{className:`block truncate`,children:e.toolName})}),(0,H.jsxs)(`td`,{className:`py-2 pr-4`,style:{width:`220px`},children:[(0,H.jsxs)(`span`,{className:`font-mono text-[var(--text-primary)]`,children:[e.durationMs,`ms`]}),(0,H.jsx)(`div`,{"aria-hidden":`true`,className:`h-1 rounded mt-1`,style:{backgroundColor:`var(--accent)`,width:`${r}px`,maxWidth:`120px`}})]}),(0,H.jsx)(`td`,{className:`py-2 pr-4 text-[var(--text-secondary)]`,style:{width:`100px`},children:uo(e.startedAtMs)}),(0,H.jsx)(`td`,{className:`py-2`,children:(0,H.jsx)(iO,{outcome:e.outcome})})]})}function iO({outcome:e}){let t=qD[e];return(0,H.jsx)(`span`,{className:`inline-block px-2 py-0.5 rounded text-xs font-medium`,style:{color:t.color,backgroundColor:`color-mix(in srgb, ${t.color} 12%, transparent)`},children:t.label})}function aO({label:e,isActive:t,onClick:n}){return(0,H.jsx)(`button`,{type:`button`,role:`radio`,onClick:n,"aria-checked":t,className:[`px-3 py-2 rounded text-xs font-medium min-w-[44px] transition-colors`,t?`text-[var(--text-primary)]`:`text-[var(--text-muted)] hover:text-[var(--text-secondary)]`].join(` `),children:e})}function oO(){return(0,H.jsxs)(`div`,{className:`space-y-3 animate-pulse`,"aria-busy":`true`,"aria-label":`Loading performance data`,children:[(0,H.jsx)(`div`,{className:`h-4 w-64 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsxs)(`div`,{className:`flex gap-1`,children:[(0,H.jsx)(`div`,{className:`h-8 w-24 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-8 w-24 rounded bg-[var(--bg-tertiary)]`})]}),(0,H.jsxs)(`div`,{className:`flex gap-4 border-b border-[var(--border)] pb-2`,children:[(0,H.jsx)(`div`,{className:`h-3 w-20 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-3 w-16 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-3 w-14 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-3 w-14 rounded bg-[var(--bg-tertiary)]`})]}),Array.from({length:8}).map((e,t)=>(0,H.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[(0,H.jsx)(`div`,{className:`h-4 rounded bg-[var(--bg-tertiary)]`,style:{minWidth:`180px`,width:`180px`}}),(0,H.jsxs)(`div`,{className:`space-y-1`,style:{width:`220px`},children:[(0,H.jsx)(`div`,{className:`h-4 w-16 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-1 w-20 rounded bg-[var(--bg-tertiary)]`})]}),(0,H.jsx)(`div`,{className:`h-4 w-16 rounded bg-[var(--bg-tertiary)]`,style:{width:`100px`}}),(0,H.jsx)(`div`,{className:`h-5 w-12 rounded bg-[var(--bg-tertiary)]`})]},t))]})}var sO=`workrail:auto:mru-workflow`;function cO(){try{return localStorage.getItem(sO)}catch{return null}}function lO(e){try{localStorage.setItem(sO,e)}catch{}}function uO(){let e=Yy(),t=Qy(),n=e.data?.workflows??[],r=t.data?.triggers??[],[i,a]=(0,V.useState)(()=>cO()??``),[o,s]=(0,V.useState)(``),[c,l]=(0,V.useState)(``),[u,d]=(0,V.useState)(!1),[f,p]=(0,V.useState)(null),[m,h]=(0,V.useState)(!1),[g,_]=(0,V.useState)(!0),v=(0,V.useRef)(null);(0,V.useEffect)(()=>{!i&&n.length>0&&a(n[0]?.id??``)},[i,n]);let y=e=>{a(e),lO(e)},b=async()=>{if(!(!i||!c.trim()||!o.trim())){d(!0),p(null),h(!1);try{await $y({workflowId:i,goal:c.trim(),workspacePath:o.trim()}),h(!0),l(``),setTimeout(()=>v.current?.focus(),100)}catch(e){p(e instanceof Error?e.message:`Dispatch failed`)}finally{d(!1)}}},x=!!i&&!!c.trim()&&!!o.trim()&&!u;return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,H.jsx)(Go,{color:`var(--accent)`,children:`Dispatch`})}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Go,{children:`Workflow`}),e.isLoading?(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] text-xs`,children:`Loading workflows...`}):n.length===0?(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] text-xs`,children:`No workflows available`}):(0,H.jsx)(`select`,{value:i,onChange:e=>y(e.target.value),className:`w-full bg-[var(--bg-secondary)] border border-[var(--border)] rounded-md px-3 py-2 text-sm text-[var(--text-primary)] focus:outline-none focus:border-[var(--accent)] cursor-pointer`,children:n.map(e=>(0,H.jsx)(`option`,{value:e.id,children:e.name??e.id},e.id))})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Go,{children:`Workspace path`}),(0,H.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`/path/to/repo`,className:`w-full bg-[var(--bg-secondary)] border border-[var(--border)] rounded-md px-3 py-2 text-sm font-mono text-[var(--text-primary)] placeholder-[var(--text-muted)] focus:outline-none focus:border-[var(--accent)]`})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Go,{children:`Goal`}),(0,H.jsx)(`textarea`,{ref:v,value:c,onChange:e=>l(e.target.value),placeholder:`// describe the task...`,rows:4,className:`w-full bg-[var(--bg-secondary)] border border-[var(--border)] rounded-md px-3 py-2 text-sm font-mono text-[var(--text-primary)] placeholder-[var(--text-muted)] focus:outline-none focus:border-[var(--accent)] resize-y`,onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&e.key===`Enter`&&x&&(e.preventDefault(),b())}})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`button`,{onClick:()=>void b(),disabled:!x,className:`self-start disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer`,children:(0,H.jsx)(to,{label:u?`RUNNING...`:`RUN`,color:x?`var(--accent)`:void 0,pulse:u})}),m&&(0,H.jsx)(`div`,{className:`text-[var(--success)] font-mono text-[10px] uppercase tracking-[0.20em]`,children:`Dispatched -- check Queue pane`}),f&&(0,H.jsx)(`div`,{className:`text-[var(--error)] text-xs font-mono`,children:f})]}),(0,H.jsxs)(`div`,{className:`border-t border-[var(--border)] pt-4`,children:[(0,H.jsxs)(`button`,{onClick:()=>_(!g),className:`flex items-center gap-2 mb-2 cursor-pointer group`,children:[(0,H.jsx)(`span`,{className:`text-[var(--text-muted)] text-xs transition-transform duration-150`,style:{transform:g?`rotate(-90deg)`:`rotate(0deg)`},children:`▼`}),(0,H.jsx)(to,{label:`TRIGGERS`,color:`var(--text-secondary)`}),r.length>0&&(0,H.jsxs)(`span`,{className:`text-xs text-[var(--text-muted)]`,children:[`(`,r.length,`)`]})]}),!g&&(0,H.jsx)(`div`,{className:`space-y-2`,children:t.isLoading?(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] text-xs pl-4`,children:`Loading triggers...`}):r.length===0?(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] text-xs pl-4`,children:`No triggers configured. Set WORKRAIL_TRIGGERS_ENABLED=true and create triggers.yml.`}):r.map(e=>(0,H.jsxs)(`div`,{className:`pl-4 border-l-2 border-[var(--border)] text-xs space-y-0.5`,children:[(0,H.jsx)(`div`,{className:`font-mono text-[var(--text-primary)] text-[11px]`,children:e.id}),(0,H.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:e.workflowId}),(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] truncate`,children:e.goal})]},e.id))})]})]})}function dO(e){let t=0,n=0,r=0;for(let i of e)i.status===`in_progress`?t++:i.status===`blocked`?n++:(i.status===`complete`||i.status===`complete_with_gaps`)&&r++;return{running:t,blocked:n,completed:r}}function fO(){let{data:e,isLoading:t,isError:n}=Wy(),r=(e?.sessions??[]).filter(e=>e.isAutonomous),{running:i,blocked:a,completed:o}=dO(r);return t?(0,H.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,H.jsx)(`div`,{className:`text-[var(--text-secondary)] text-sm`,children:`Loading sessions...`})}):n?(0,H.jsx)(`div`,{className:`text-[var(--error)] bg-[var(--bg-card)] rounded-lg p-4 text-sm`,children:`Failed to load sessions`}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,H.jsx)(Go,{color:`var(--accent)`,children:`Queue`})}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,H.jsx)(pO,{count:i,label:`RUNNING`,color:`var(--accent)`,pulse:!0}),(0,H.jsx)(pO,{count:a,label:`BLOCKED`,color:`var(--blocked)`}),(0,H.jsx)(pO,{count:o,label:`COMPLETED`,color:`var(--success)`})]}),r.length===0?(0,H.jsxs)(`div`,{className:`text-center py-16`,children:[(0,H.jsx)(`p`,{className:`text-[var(--text-secondary)] text-sm`,children:`No autonomous sessions yet`}),(0,H.jsx)(`p`,{className:`text-[var(--text-muted)] text-xs mt-1`,children:`Dispatch a workflow from the left pane to start.`})]}):(0,H.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,H.jsx)(mO,{session:e},e.sessionId))})]})}function pO({count:e,label:t,color:n,pulse:r}){return(0,H.jsx)(to,{label:`${e} ${t}`,color:e>0?n:`var(--text-muted)`,pulse:r&&e>0})}function mO({session:e}){let[t,n]=(0,V.useState)(!1),r=Ci(),i=e.sessionTitle??e.workflowName??e.workflowId??`Unnamed session`,a=uo(e.lastModifiedMs);return(0,H.jsxs)(`div`,{className:`bg-[var(--bg-card)] border border-[var(--border)] rounded-lg overflow-hidden`,children:[(0,H.jsxs)(`button`,{onClick:()=>n(!t),className:`w-full px-4 py-3 flex items-center gap-3 text-left cursor-pointer hover:bg-[var(--bg-secondary)] transition-colors group`,children:[(0,H.jsx)(`span`,{className:`text-[var(--text-muted)] text-xs transition-transform duration-150 shrink-0`,style:{transform:t?`rotate(90deg)`:`rotate(0deg)`},children:`▶`}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-[var(--text-primary)] truncate group-hover:text-[var(--accent)] transition-colors`,children:i}),(0,H.jsx)(`div`,{className:`font-mono text-[10px] text-[var(--text-muted)] opacity-60 truncate`,children:e.sessionId})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,H.jsx)(`span`,{className:`text-[10px] text-[var(--text-muted)] tabular-nums`,children:a}),e.isLive&&(0,H.jsx)(to,{label:`LIVE`,pulse:!0,color:`var(--accent)`,"aria-label":`Actively running`}),(0,H.jsx)(ro,{status:e.status})]})]}),t&&(0,H.jsxs)(`div`,{className:`px-4 pb-4 border-t border-[var(--border)] pt-3 space-y-3`,children:[e.recapSnippet?(0,H.jsx)(`div`,{className:`text-xs text-[var(--text-secondary)] font-mono whitespace-pre-wrap leading-relaxed`,children:e.recapSnippet}):(0,H.jsx)(`div`,{className:`text-xs text-[var(--text-muted)]`,children:`No recap available yet.`}),(0,H.jsx)(`button`,{onClick:()=>void r({to:`/session/$sessionId`,params:{sessionId:e.sessionId}}),className:`cursor-pointer`,children:(0,H.jsx)(to,{label:`OPEN IN DAG`,color:`var(--accent)`})})]})]})}function hO(){return(0,H.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-6`,children:[(0,H.jsx)(`div`,{className:`w-full md:w-2/5 shrink-0`,children:(0,H.jsx)(uO,{})}),(0,H.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,H.jsx)(fO,{})})]})}function gO(){let e=Wy(),t=Jy();eb();let n=e.data?.sessions;return{sessions:n,worktreeRepos:t.data?.repos??[],isLoading:e.isLoading,error:e.error instanceof Error?e.error:null,refetch:e.refetch,worktreesFetching:t.isFetching,liveCount:n?.filter(e=>e.status===`in_progress`).length??0,blockedCount:n?.filter(e=>e.status===`blocked`).length??0}}var _O={scope:`active`,focusedIndex:-1,archive:null};function vO(e){throw Error(`Unhandled WorkspaceEvent type: ${String(e.type)}`)}function yO(e,t){switch(t.type){case`scope_changed`:return{...e,scope:t.scope,focusedIndex:-1};case`focus_moved`:return{...e,focusedIndex:t.index};case`archive_opened`:return{...e,archive:{repoName:t.repoName}};case`archive_closed`:return{...e,archive:null};default:return vO(t)}}var bO=720*60*60*1e3,xO={in_progress:0,dormant:0,blocked:1,complete_with_gaps:2,complete:3};function SO(e){if(e.length!==0)return[...e].sort((e,t)=>{let n=xO[e.status]-xO[t.status];return n===0?t.lastModifiedMs-e.lastModifiedMs:n})[0]}function CO(e,t,n){let r=e.primarySession?.status;if(r===`in_progress`||r===`blocked`)return`visible`;let i=(e.worktree?.changedCount??0)>0,a=(e.worktree?.aheadCount??0)>0;return i||a?`visible`:r===`dormant`?t===`all`?`visible`:`hidden`:n-e.activityMs<bO||t===`all`?`visible`:`hidden`}function wO(e){switch(e.primarySession?.status){case`in_progress`:return 0;case`blocked`:return 1;case`dormant`:return 2;default:return(e.worktree?.changedCount??0)>0||(e.worktree?.aheadCount??0)>0?3:4}}function TO(e,t,n){return[...e].filter(e=>CO(e,t,n)===`visible`).sort((e,t)=>{let n=wO(e)-wO(t);return n===0?t.activityMs-e.activityMs:n})}function EO(e,t){let n=new Map;for(let e of t)for(let t of e.worktrees)t.branch!==null&&n.set(`${t.branch}\0${e.repoRoot}`,{wt:t,repoName:e.repoName,repoRoot:e.repoRoot});let r=new Map;for(let[e,t]of n){let[n]=e.split(`\0`),i=r.get(n)??[];i.push(t),r.set(n,i)}let i=new Map;for(let t of e){if(t.gitBranch===null)continue;let e=r.get(t.gitBranch)??[];if(e.length===0){if(!t.repoRoot)continue;let e=`${t.gitBranch}\0${t.repoRoot}`,r=i.get(e);if(r?r.push(t):i.set(e,[t]),!n.has(e)){let r=t.repoRoot.split(`/`).at(-1)??t.repoRoot;n.set(e,{wt:void 0,repoName:r,repoRoot:t.repoRoot})}continue}let a=e;if(t.repoRoot!==null){let n=e.filter(e=>e.repoRoot===t.repoRoot);n.length>0&&(a=n)}for(let e of a){let n=`${t.gitBranch}\0${e.repoRoot}`,r=i.get(n);r?r.push(t):i.set(n,[t])}}let a=[],o=new Set;for(let[e,t]of i){let[r,i]=e.split(`\0`),s=n.get(e),c=SO(t),l=Math.max(c?.lastModifiedMs??0,s?.wt?.headTimestampMs??0),u=s?.repoName??i.split(`/`).at(-1)??i;a.push({branch:r,repoRoot:i,repoName:u,worktree:s?.wt,primarySession:c,allSessions:t,activityMs:l}),o.add(e)}for(let[e,{wt:t,repoName:r,repoRoot:i}]of n){if(o.has(e))continue;let[n]=e.split(`\0`);a.push({branch:n,repoRoot:i,repoName:r,worktree:t,primarySession:void 0,allSessions:[],activityMs:t?.headTimestampMs??0})}return a}function DO(e,t,n,r){let i=EO(e,t),a=new Map;for(let e of i)a.has(e.repoRoot)||a.set(e.repoRoot,e.repoName);let o=new Map;for(let e of i){let t=o.get(e.repoRoot)??[];t.push(e),o.set(e.repoRoot,t)}let s=[...o.entries()].map(([e,t])=>({repoRoot:e,repoName:t[0].repoName,sortedItems:TO(t,n,r)})).filter(e=>e.sortedItems.length>0).sort((e,t)=>{let n=+!e.sortedItems.some(e=>e.primarySession?.status===`in_progress`||e.primarySession?.status===`blocked`),r=+!t.sortedItems.some(e=>e.primarySession?.status===`in_progress`||e.primarySession?.status===`blocked`);return n===r?e.repoName.localeCompare(t.repoName):n-r}),c=s.flatMap(e=>e.sortedItems),l=n===`active`?i.filter(e=>e.primarySession?.status===`dormant`&&(e.worktree?.changedCount??0)===0&&(e.worktree?.aheadCount??0)===0).length:0;return{repoGroups:s,orderedItems:c,archiveRepos:[...a.entries()].map(([e,t])=>[e,t]),dormantHiddenCount:l}}function OO({items:e,focusedIndex:t,scope:n,archive:r,dispatch:i,onSelectSession:a,onRefetch:o,disabled:s}){let c=(0,V.useRef)(e);c.current=e;let l=(0,V.useRef)(t);l.current=t;let u=(0,V.useRef)(n);u.current=n;let d=(0,V.useRef)(r);d.current=r;let f=(0,V.useRef)(s);f.current=s;let p=(0,V.useRef)(i);p.current=i;let m=(0,V.useRef)(a);m.current=a;let h=(0,V.useRef)(o);h.current=o,(0,V.useEffect)(()=>{function e(e){if(f.current||e.metaKey||e.ctrlKey||e.altKey)return;let t=document.activeElement;if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)return;let n=c.current,r=l.current;switch(e.key){case`j`:case`ArrowDown`:e.preventDefault(),p.current({type:`focus_moved`,index:Math.min(r+1,n.length-1)});break;case`k`:case`ArrowUp`:e.preventDefault(),p.current({type:`focus_moved`,index:Math.max(r-1,0)});break;case`Enter`:case` `:if(e.preventDefault(),r>=0&&r<n.length){let e=n[r]?.primarySession?.sessionId;e&&m.current(e)}break;case`Escape`:d.current!==null&&p.current({type:`archive_closed`});break;case`/`:e.preventDefault(),p.current({type:`archive_opened`,repoName:void 0});break;case`r`:e.preventDefault(),h.current();break;case`a`:e.preventDefault(),p.current({type:`scope_changed`,scope:u.current===`active`?`all`:`active`});break}}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[])}function kO(e=!1){let t=Ci(),n=gO(),[r,i]=(0,V.useReducer)(yO,_O),a=(0,V.useRef)(0),o=(0,V.useCallback)(e=>{a.current=window.scrollY,t({to:`/session/$sessionId`,params:{sessionId:e}})},[t]),s=i,c=(0,V.useMemo)(()=>n.sessions?DO(n.sessions,n.worktreeRepos,r.scope,Date.now()):null,[n.sessions,n.worktreeRepos,r.scope]);OO({items:c?.orderedItems??[],focusedIndex:r.focusedIndex,scope:r.scope,archive:r.archive,dispatch:s,onSelectSession:o,onRefetch:n.refetch,disabled:e});let{isLoading:l,error:u,worktreesFetching:d,sessions:f,liveCount:p,blockedCount:m}=n;return{state:(0,V.useMemo)(()=>l?{kind:`loading`}:u?{kind:`error`,message:u.message}:c?{kind:`ready`,scope:r.scope,focusedIndex:r.focusedIndex,archive:r.archive,repoGroups:c.repoGroups,orderedItems:c.orderedItems,archiveRepos:c.archiveRepos,dormantHiddenCount:c.dormantHiddenCount,worktreesFetching:d,hasAnySessions:(f?.length??0)>0,liveCount:p,blockedCount:m}:{kind:`loading`},[l,u,d,f,c,r,p,m]),dispatch:s,scrollYRef:a,onSelectSession:o}}function AO(){let e=Wy();return{sessions:e.data?.sessions,isLoading:e.isLoading,error:e.error instanceof Error?e.error:null}}function jO(e=``){return{rawSearch:e,sort:`recent`,groupBy:`none`,statusFilter:`all`,page:0,viewMode:`flat`}}function MO(e){throw Error(`Unhandled SessionListEvent type: ${String(e.type)}`)}function NO(e,t){switch(t.type){case`search_changed`:return{...e,rawSearch:t.value,page:0};case`sort_changed`:return{...e,sort:t.sort,page:0};case`group_changed`:return{...e,groupBy:t.groupBy,page:0};case`status_changed`:return{...e,statusFilter:t.statusFilter,page:0};case`page_changed`:return{...e,page:t.page};case`view_mode_changed`:return t.viewMode===`tree`?{...e,viewMode:`tree`,rawSearch:``,statusFilter:`all`,page:0}:{...e,viewMode:`flat`,page:0};default:return MO(t)}}var PO={in_progress:0,blocked:1,dormant:2,complete_with_gaps:3,complete:4},FO=[{value:`recent`,label:`Recent`,compareFn:(e,t)=>t.lastModifiedMs-e.lastModifiedMs},{value:`status`,label:`Status`,compareFn:(e,t)=>PO[e.status]-PO[t.status]||t.lastModifiedMs-e.lastModifiedMs},{value:`workflow`,label:`Workflow`,compareFn:(e,t)=>(e.workflowName??e.workflowId??``).localeCompare(t.workflowName??t.workflowId??``)||t.lastModifiedMs-e.lastModifiedMs},{value:`nodes`,label:`Node count`,compareFn:(e,t)=>t.nodeCount-e.nodeCount||t.lastModifiedMs-e.lastModifiedMs}],IO=[{value:`none`,label:`No grouping`,keyFn:null},{value:`workflow`,label:`Workflow`,keyFn:e=>e.workflowName??e.workflowId??`Unknown workflow`},{value:`status`,label:`Status`,keyFn:e=>e.status,groupCompareFn:(e,t)=>(PO[e]??99)-(PO[t]??99)},{value:`branch`,label:`Branch`,keyFn:e=>e.gitBranch??`No branch`}],LO=[{value:`all`,label:`All`},{value:`in_progress`,label:`In Progress`},{value:`dormant`,label:`Dormant`},{value:`complete`,label:`Complete`},{value:`complete_with_gaps`,label:`Gaps`},{value:`blocked`,label:`Blocked`}];function RO(e,t,n){let r=e;if(n!==`all`&&(r=r.filter(e=>e.status===n)),t.trim()){let e=t.toLowerCase();r=r.filter(t=>(t.sessionTitle??``).toLowerCase().includes(e)||(t.workflowName??``).toLowerCase().includes(e)||(t.workflowId??``).toLowerCase().includes(e)||t.sessionId.toLowerCase().includes(e)||(t.gitBranch??``).toLowerCase().includes(e))}return r}function zO(e,t){let n=FO.find(e=>e.value===t)??FO[0];return[...e].sort(n.compareFn)}function BO(e,t){let n=IO.find(e=>e.value===t)??IO[0];if(!n.keyFn)return[{label:``,sessions:e}];let r=new Map;for(let t of e){let e=n.keyFn(t),i=r.get(e)??[];i.push(t),r.set(e,i)}let i=n.groupCompareFn??((e,t)=>e.localeCompare(t));return Array.from(r.entries()).sort(([e],[t])=>i(e,t)).map(([e,t])=>({label:e,sessions:t}))}function VO(e){let t={all:e.length};for(let n of e)t[n.status]=(t[n.status]??0)+1;return t}function HO(e){let t=new Set(e.map(e=>e.sessionId)),n=new Map,r=new Set,i=new Set;for(let a of e){let e=a.parentSessionId;if(!e||e===a.sessionId)continue;if(!t.has(e)){r.add(a.sessionId);continue}i.add(a.sessionId);let o=n.get(e)??[];o.push(a),n.set(e,o)}let a=[];for(let t of e)i.has(t.sessionId)||a.push({session:t,children:n.get(t.sessionId)??[]});return{roots:a,orphanChildIds:r}}function UO(e,t){let[n,r]=(0,V.useState)(e),i=(0,V.useRef)(null);return(0,V.useEffect)(()=>(i.current!==null&&clearTimeout(i.current),i.current=setTimeout(()=>r(e),t),()=>{i.current!==null&&clearTimeout(i.current)}),[e,t]),n}function WO({onSelectSession:e,initialSearch:t=``}){let n=AO(),[r,i]=(0,V.useReducer)(NO,void 0,()=>jO(t)),a=UO(r.rawSearch,200),o=(0,V.useRef)([]),s=(0,V.useCallback)(t=>{let n=o.current[t];n&&e(n.sessionId)},[e]),{sessions:c,isLoading:l,error:u}=n,d=(0,V.useMemo)(()=>c?VO(c):{},[c]),f=(0,V.useMemo)(()=>{if(!c)return null;let e=RO(c,a,r.statusFilter);return{groups:BO(zO(e,r.sort),r.groupBy),total:c.length,filtered:e.length}},[c,a,r.statusFilter,r.sort,r.groupBy]),p=(0,V.useMemo)(()=>HO(c||[]),[c]),m=r.groupBy!==`none`,h=f?Math.ceil(f.filtered/25):0,g=r.page*25,_=g+25,v=(0,V.useMemo)(()=>!f||m?[]:f.groups[0]?.sessions.slice(g,_)??[],[f,m,g,_]);o.current=v;let{getItemProps:y,containerProps:b}=PD({count:v.length,cols:1,onActivate:s});return{state:(0,V.useMemo)(()=>l?{kind:`loading`}:u?{kind:`error`,message:u.message}:f?{kind:`ready`,rawSearch:r.rawSearch,sort:r.sort,groupBy:r.groupBy,statusFilter:r.statusFilter,page:r.page,totalPages:h,isGrouped:m,processed:f,statusCounts:d,flatPageSessions:v,getSessionNavProps:y,sessionContainerProps:b,sortAxes:FO,groupAxes:IO,statusFilterOptions:LO,viewMode:r.viewMode,sessionTree:p}:{kind:`loading`},[l,u,f,r,h,m,d,v,y,b,p]),dispatch:i,onSelectSession:e}}var GO={selectedWorkflowId:null,selectedTag:null,selectedSource:null,hintVisible:!1};function KO(e){throw Error(`Unhandled WorkflowsEvent type: ${String(e.type)}`)}function qO(e,t){switch(t.type){case`workflow_selected`:return{...e,selectedWorkflowId:t.id,hintVisible:t.id!==null};case`tag_changed`:return{...e,selectedTag:t.tag,selectedWorkflowId:null,hintVisible:!1};case`source_changed`:return{...e,selectedSource:t.source,selectedWorkflowId:null,hintVisible:!1};case`modal_closed`:return{...e,selectedWorkflowId:null,hintVisible:!1};case`hint_dismissed`:return{...e,hintVisible:!1};default:return KO(t)}}function JO(e){let t=new Set;for(let n of e)for(let e of n.tags)e!==`routines`&&t.add(e);let n=bD.map(e=>e.id).filter(e=>t.has(e)),r=[...t].filter(e=>!bD.some(t=>t.id===e)).sort();return[...n,...r]}function YO(e){let t=new Map;for(let n of e)t.has(n.source.kind)||t.set(n.source.kind,{id:n.source.kind,displayName:n.source.displayName});return[...t.values()]}function XO(e,t,n){let r=new Set(bD.map(e=>e.id)),i=e;return t!==null&&(i=t===`__other__`?i.filter(e=>!e.tags.some(e=>e!==`routines`&&r.has(e))):i.filter(e=>e.tags.includes(t))),n!==null&&(i=i.filter(e=>e.source.displayName===n)),i}function ZO(e,t){if(t!==null)return e;let n=new Set(bD.map(e=>e.id)),r=new Map,i=[];for(let t of e){let e=t.tags.find(e=>e!==`routines`&&n.has(e));if(e){let n=r.get(e)??[];n.push(t),r.set(e,n)}else i.push(t)}let a=[];for(let{id:e}of bD){let t=r.get(e);t&&a.push(...t)}return a.push(...i),a}function QO({initialTag:e,onSelectTag:t}){let n=ID(),[r,i]=(0,V.useReducer)(qO,{...GO,selectedTag:e});(0,V.useEffect)(()=>{e!==r.selectedTag&&i({type:`tag_changed`,tag:e})},[e]);let a=(0,V.useRef)(null),o=(0,V.useCallback)((e,t)=>{a.current=t,t.blur(),i({type:`workflow_selected`,id:e})},[]);(0,V.useEffect)(()=>{if(!r.selectedWorkflowId&&a.current){let e=a.current;a.current=null,e.focus()}},[r.selectedWorkflowId]),(0,V.useEffect)(()=>{if(!r.selectedWorkflowId)return;let e=window.scrollY;return document.body.style.overflow=`hidden`,document.body.style.position=`fixed`,document.body.style.top=`-${e}px`,document.body.style.width=`100%`,()=>{document.body.style.overflow=``,document.body.style.position=``,document.body.style.top=``,document.body.style.width=``,window.scrollTo(0,e)}},[r.selectedWorkflowId]),(0,V.useEffect)(()=>{if(!r.selectedWorkflowId)return;let e=e=>{e.key===`Escape`&&i({type:`modal_closed`})};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[r.selectedWorkflowId]);let{isLoading:s,error:c,workflows:l}=n,u=(0,V.useMemo)(()=>{if(s)return{kind:`loading`};if(c)return{kind:`error`,message:c.message,onRetry:n.refetch};if(!l)return{kind:`loading`};let e=JO(l),t=YO(l),i=XO(l,r.selectedTag,r.selectedSource),a=ZO(i,r.selectedTag),o=XO(l,null,r.selectedSource),u=XO(l,r.selectedTag,null);return{kind:`ready`,selectedWorkflowId:r.selectedWorkflowId,selectedTag:r.selectedTag,selectedSource:r.selectedSource,hintVisible:r.hintVisible,availableTags:e,availableSources:t,filteredWorkflows:i,flatWorkflows:a,sourceFilteredWorkflows:o,tagFilteredWorkflows:u}},[s,c,l,r,n.refetch]),d=u.kind===`ready`?u.flatWorkflows.length:0;return(0,V.useEffect)(()=>{if(!r.selectedWorkflowId||d<=1)return;let e=setTimeout(()=>i({type:`hint_dismissed`}),3e3);return()=>clearTimeout(e)},[r.selectedWorkflowId,d]),{state:u,dispatch:(0,V.useCallback)(e=>{e.type===`tag_changed`&&t(e.tag),i(e)},[t]),triggerRef:a,onCardSelect:o}}function $O(){let e=Xy();switch(e.state){case`loading`:return{kind:`loading`};case`devModeOff`:return{kind:`devModeOff`};case`error`:return{kind:`error`,message:e.message,retry:e.retry};case`data`:return{kind:`ready`,observations:e.data.observations}}}function ek(){let e=$O(),[t,n]=(0,V.useState)(`recent`);return{state:(0,V.useMemo)(()=>{if(e.kind===`loading`)return{kind:`loading`};if(e.kind===`devModeOff`)return{kind:`devModeOff`};if(e.kind===`error`)return{kind:`error`,message:e.message,retry:e.retry};let{observations:r}=e,i=JD(r,t);return{kind:`ready`,sorted:i,maxDuration:YD(i),errorCount:XD(r),avgMs:ZD(r),lastCallMs:QD(r),countLabel:eO(r.length),sortOrder:t,onSortChange:n}},[e,t])}}function tk(e){let t=Gy(e);return{data:t.data,isLoading:t.isLoading,error:t.error instanceof Error?t.error:null}}function nk(e){let t=tk(e),[n,r]=(0,V.useState)(null),i=(0,V.useCallback)((e,t)=>{r(n=>n?.runId===e&&n?.nodeId===t?null:{runId:e,nodeId:t})},[]),a=(0,V.useCallback)(()=>{r(null)},[]),{isLoading:o,error:s,data:c}=t,l=(0,V.useMemo)(()=>!c||!n?null:c.runs.find(e=>e.runId===n.runId)??null,[c,n]);return{state:(0,V.useMemo)(()=>o?{kind:`loading`}:s?{kind:`error`,message:s.message}:c?{kind:`ready`,sessionId:e,data:c,selectedNode:n,selectedRun:l}:{kind:`loading`},[o,s,c,e,n,l]),onSelectNode:i,onCloseNode:a}}var rk=[{id:`workspace`,path:`/`},{id:`workflows`,path:`/workflows`},{id:`auto`,path:`/auto`},{id:`perf`,path:`/perf`}];function ik(){let e=Ci(),t=ea(),{location:n}=oa(),r=t({to:`/session/$sessionId`}),i=t({to:`/workflows`}),a=t({to:`/workflows/$workflowId`}),o=t({to:`/perf`}),s=t({to:`/auto`}),c=i!==!1||a!==!1?`workflows`:o===!1?s===!1?`workspace`:`auto`:`perf`,l=r!==!1,u=a!==!1,d=l?r.sessionId:null,f=u?a.workflowId:null,p=new URLSearchParams(n.search).get(`tag`),m=kO(l),h=WO({onSelectSession:m.onSelectSession}),g=m.state.kind===`ready`?m.state.liveCount:0,_=m.state.kind===`ready`?m.state.blockedCount:0,v=(0,V.useCallback)(()=>{e({to:`/`})},[e]),y=(0,V.useCallback)(t=>{e({to:`/workflows`,search:{tag:t??void 0}})},[e]),b=(0,V.useCallback)(()=>{e({to:`/workflows`,search:{tag:p??void 0}})},[e,p]),x=(0,V.useCallback)(t=>{e({to:`/workflows/$workflowId`,params:{workflowId:t},search:{tag:p??void 0}})},[e,p]),S=QO({initialTag:p,onSelectTag:y}),C=RD({workflowId:f,activeTag:p,onBack:b,onNavigateToWorkflow:x}),w=nk(d??``),T=ek(),[E,D]=(0,V.useState)(null),O=(0,V.useCallback)((e,t)=>{t(),D(e),setTimeout(()=>D(null),200)},[]),k=(0,V.useRef)(null);return(0,V.useEffect)(()=>{let t=k.current;if(!t)return;function n(t){if(t.key===`ArrowLeft`||t.key===`ArrowRight`){t.preventDefault();let n=rk.findIndex(e=>e.id===c),r=rk[t.key===`ArrowRight`?(n+1)%rk.length:(n-1+rk.length)%rk.length];e({to:r.path,...r.path===`/workflows`?{search:{tag:void 0}}:{}})}}return t.addEventListener(`keydown`,n),()=>t.removeEventListener(`keydown`,n)},[c,e]),(0,H.jsxs)(`div`,{className:`min-h-screen`,style:{"--app-header-height":`56px`},children:[(0,H.jsxs)(`header`,{style:{background:`rgba(23, 27, 40, 0.92)`,backdropFilter:`blur(24px)`,WebkitBackdropFilter:`blur(24px)`,borderBottom:`1px solid rgba(244, 196, 48, 0.25)`,boxShadow:`0 4px 24px rgba(0,0,0,0.4)`},className:`fixed top-0 w-full z-50 flex items-center h-14 px-4 gap-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,H.jsx)(co,{cut:8,borderColor:`rgba(244, 196, 48, 0.5)`,background:`rgba(27, 31, 44, 0.8)`,className:`relative w-10 h-10`,children:(0,H.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,H.jsx)(`span`,{className:`font-mono text-[11px] font-bold text-[var(--accent)] tracking-widest`,children:`WR`})})}),(0,H.jsxs)(`div`,{className:`hidden sm:flex flex-col leading-none`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[11px] font-bold text-[var(--text-primary)] tracking-[0.25em] uppercase`,children:`WR_CONSOLE`}),(0,H.jsxs)(`span`,{className:`font-mono text-[9px] text-[var(--text-muted)] tracking-[0.15em]`,children:[`// V`,`3.73.2`]})]})]}),l&&d?(0,H.jsx)(`nav`,{className:`flex items-center flex-1 justify-center`,children:(0,H.jsx)(CD,{segments:[{label:`Workspace`,onClick:v},{label:d?.slice(-12)??``}]})}):(0,H.jsxs)(`div`,{role:`tablist`,"aria-label":`Console sections`,ref:k,className:`flex items-center gap-1 flex-1 justify-center`,children:[(0,H.jsxs)(`button`,{role:`tab`,id:`tab-workspace`,"aria-selected":c===`workspace`,"aria-controls":`panel-workspace`,tabIndex:c===`workspace`?0:-1,onClick:()=>O(`workspace`,()=>void e({to:`/`})),className:[`tab-btn px-4 py-2.5 font-mono text-[10px] uppercase tracking-[0.30em] transition-colors duration-150`,`focus-visible:ring-2 focus-visible:ring-[var(--accent)] focus-visible:ring-offset-1 focus-visible:outline-none`,c===`workspace`?`tab-btn--active text-[var(--accent)] text-glow-amber`:`text-[var(--text-secondary)] hover:text-[var(--text-primary)]`,E===`workspace`?`tab-activating`:``].join(` `),style:c===`workspace`?{backgroundColor:`rgba(244, 196, 48, 0.06)`}:void 0,children:[(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tr`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--bl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--br`,"aria-hidden":`true`}),`Workspace`]}),(0,H.jsxs)(`button`,{role:`tab`,id:`tab-workflows`,"aria-selected":c===`workflows`,"aria-controls":`panel-workflows`,tabIndex:c===`workflows`?0:-1,onClick:()=>O(`workflows`,()=>void e({to:`/workflows`,search:{tag:void 0}})),className:[`tab-btn px-4 py-2.5 font-mono text-[10px] uppercase tracking-[0.30em] transition-colors duration-150`,`focus-visible:ring-2 focus-visible:ring-[var(--accent)] focus-visible:ring-offset-1 focus-visible:outline-none`,c===`workflows`?`tab-btn--active text-[var(--accent)] text-glow-amber`:`text-[var(--text-secondary)] hover:text-[var(--text-primary)]`,E===`workflows`?`tab-activating`:``].join(` `),style:c===`workflows`?{backgroundColor:`rgba(244, 196, 48, 0.06)`}:void 0,children:[(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tr`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--bl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--br`,"aria-hidden":`true`}),`Workflows`]}),(0,H.jsxs)(`button`,{role:`tab`,id:`tab-auto`,"aria-selected":c===`auto`,"aria-controls":`panel-auto`,tabIndex:c===`auto`?0:-1,onClick:()=>O(`auto`,()=>void e({to:`/auto`})),className:[`tab-btn px-4 py-2.5 font-mono text-[10px] uppercase tracking-[0.30em] transition-colors duration-150`,`focus-visible:ring-2 focus-visible:ring-[var(--accent)] focus-visible:ring-offset-1 focus-visible:outline-none`,c===`auto`?`tab-btn--active text-[var(--accent)] text-glow-amber`:`text-[var(--text-secondary)] hover:text-[var(--text-primary)]`,E===`auto`?`tab-activating`:``].join(` `),style:c===`auto`?{backgroundColor:`rgba(244, 196, 48, 0.06)`}:void 0,children:[(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tr`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--bl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--br`,"aria-hidden":`true`}),`Auto`]}),(0,H.jsxs)(`button`,{role:`tab`,id:`tab-perf`,"aria-selected":c===`perf`,"aria-controls":`panel-perf`,tabIndex:c===`perf`?0:-1,onClick:()=>O(`perf`,()=>void e({to:`/perf`})),className:[`tab-btn px-4 py-2.5 font-mono text-[10px] uppercase tracking-[0.30em] transition-colors duration-150`,`focus-visible:ring-2 focus-visible:ring-[var(--accent)] focus-visible:ring-offset-1 focus-visible:outline-none`,c===`perf`?`tab-btn--active text-[var(--accent)] text-glow-amber`:`text-[var(--text-secondary)] hover:text-[var(--text-primary)]`,E===`perf`?`tab-activating`:``].join(` `),style:c===`perf`?{backgroundColor:`rgba(244, 196, 48, 0.06)`}:void 0,children:[(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tr`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--bl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--br`,"aria-hidden":`true`}),`Performance`]})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[g>0&&(0,H.jsx)(to,{label:`${Math.min(g,9)}${g>9?`+`:``} LIVE`,color:`var(--accent-strong)`,pulse:!0,role:`status`,"aria-label":`${g} live session${g===1?``:`s`}`}),_>0&&(0,H.jsx)(to,{label:`${Math.min(_,9)}${_>9?`+`:``} BLOCKED`,color:`var(--blocked)`,role:`status`,"aria-label":`${_} blocked session${_===1?``:`s`}`})]})]}),(0,H.jsxs)(`main`,{className:`p-6`,style:{paddingTop:`calc(56px + 1.5rem)`},children:[(0,H.jsxs)(`div`,{id:`panel-workspace`,role:`tabpanel`,"aria-labelledby":`tab-workspace`,hidden:c===`workflows`||c===`perf`||c===`auto`,children:[(0,H.jsx)(Eo,{viewModel:m,sessionListViewModel:h,hidden:l}),l&&d&&(0,H.jsx)(_D,{viewModel:w})]}),c===`workflows`&&(0,H.jsx)(`div`,{id:`panel-workflows`,role:`tabpanel`,"aria-labelledby":`tab-workflows`,children:u&&f?(0,H.jsx)(wD,{viewModel:C}):(0,H.jsx)(BD,{viewModel:S})}),c===`auto`&&(0,H.jsx)(`div`,{id:`panel-auto`,role:`tabpanel`,"aria-labelledby":`tab-auto`,children:(0,H.jsx)(hO,{})}),c===`perf`&&(0,H.jsx)(`div`,{id:`panel-perf`,role:`tabpanel`,"aria-labelledby":`tab-perf`,children:(0,H.jsx)(nO,{viewModel:T})})]})]})}var ak=Vi({component:ik}),ok=zi({getParentRoute:()=>ak,path:`/`,component:()=>null}),sk=zi({getParentRoute:()=>ak,path:`/session/$sessionId`,component:()=>null}),ck=zi({getParentRoute:()=>ak,path:`/workflows`,validateSearch:e=>({tag:typeof e.tag==`string`?e.tag:void 0}),component:()=>null}),lk=zi({getParentRoute:()=>ak,path:`/workflows/$workflowId`,validateSearch:e=>({tag:typeof e.tag==`string`?e.tag:void 0}),component:()=>null}),uk=zi({getParentRoute:()=>ak,path:`/perf`,component:()=>null}),dk=zi({getParentRoute:()=>ak,path:`/auto`,component:()=>null}),fk=na({routeTree:ak.addChildren([ok,sk,ck,lk,uk,dk]),history:_r()}),pk=new Re({defaultOptions:{queries:{refetchInterval:5e3,staleTime:2e3}}});(0,sa.createRoot)(document.getElementById(`root`)).render((0,H.jsx)(V.StrictMode,{children:(0,H.jsx)(Ue,{client:pk,children:(0,H.jsx)(aa,{router:fk})})}));
28
+ `},i)),a}function KT(e,t){return e&&`run`in e?async function(n,r){let i=GT(n,{file:r,...t});await e.run(i,r)}:function(n,r){return GT(n,{file:r,...e||t})}}function qT(e){if(e)throw e}var JT=o(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});f<p;++f)if(t=arguments[f],t!=null)for(n in t)r=l(d,n),i=l(t,n),d!==i&&(m&&i&&(s(i)||(a=o(i)))?(a?(a=!1,u=r&&o(r)?r:[]):u=r&&s(r)?r:{},c(d,{name:n,newValue:e(m,u,i)})):i!==void 0&&c(d,{name:n,newValue:i}));return d}}));function YT(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function XT(){let e=[],t={run:n,use:r};return t;function n(...t){let n=-1,r=t.pop();if(typeof r!=`function`)throw TypeError(`Expected function as last argument, not `+r);i(null,...t);function i(a,...o){let s=e[++n],c=-1;if(a){r(a);return}for(;++c<t.length;)(o[c]===null||o[c]===void 0)&&(o[c]=t[c]);t=o,s?ZT(s,i)(...o):r(null,...o)}}function r(n){if(typeof n!=`function`)throw TypeError("Expected `middelware` to be a function, not "+n);return e.push(n),t}}function ZT(e,t){let n;return r;function r(...t){let r=e.length>t.length,o;r&&t.push(i);try{o=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return i(t)}r||(o&&o.then&&typeof o.then==`function`?o.then(a,i):o instanceof Error?i(o):a(o))}function i(e,...r){n||(n=!0,t(e,...r))}function a(e){i(null,e)}}var QT={basename:$T,dirname:eE,extname:tE,join:nE,sep:`/`};function $T(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);aE(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function eE(e){if(aE(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function tE(e){aE(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function nE(...e){let t=-1,n;for(;++t<e.length;)aE(e[t]),e[t]&&(n=n===void 0?e[t]:n+`/`+e[t]);return n===void 0?`.`:rE(n)}function rE(e){aE(e);let t=e.codePointAt(0)===47,n=iE(e,!t);return n.length===0&&!t&&(n=`.`),n.length>0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function iE(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o<e.length)s=e.codePointAt(o);else if(s===47)break;else s=47;if(s===47){if(!(i===o-1||a===1))if(i!==o-1&&a===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function aE(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}var oE={cwd:sE};function sE(){return`/`}function cE(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function lE(e){if(typeof e==`string`)e=new URL(e);else if(!cE(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return uE(e)}function uE(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){let e=t.codePointAt(n+2);if(e===70||e===102){let e=TypeError(`File URL path must not include encoded / characters`);throw e.code=`ERR_INVALID_FILE_URL_PATH`,e}}return decodeURIComponent(t)}var dE=[`history`,`path`,`basename`,`stem`,`extname`,`dirname`],fE=class{constructor(e){let t;t=e?cE(e)?{path:e}:typeof e==`string`||gE(e)?{value:e}:e:{},this.cwd=`cwd`in t?``:oE.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let n=-1;for(;++n<dE.length;){let e=dE[n];e in t&&t[e]!==void 0&&t[e]!==null&&(this[e]=e===`history`?[...t[e]]:t[e])}let r;for(r in t)dE.includes(r)||(this[r]=t[r])}get basename(){return typeof this.path==`string`?QT.basename(this.path):void 0}set basename(e){mE(e,`basename`),pE(e,`basename`),this.path=QT.join(this.dirname||``,e)}get dirname(){return typeof this.path==`string`?QT.dirname(this.path):void 0}set dirname(e){hE(this.basename,`dirname`),this.path=QT.join(e||``,this.basename)}get extname(){return typeof this.path==`string`?QT.extname(this.path):void 0}set extname(e){if(pE(e,`extname`),hE(this.dirname,`extname`),e){if(e.codePointAt(0)!==46)throw Error("`extname` must start with `.`");if(e.includes(`.`,1))throw Error("`extname` cannot contain multiple dots")}this.path=QT.join(this.dirname,this.stem+(e||``))}get path(){return this.history[this.history.length-1]}set path(e){cE(e)&&(e=lE(e)),mE(e,`path`),this.path!==e&&this.history.push(e)}get stem(){return typeof this.path==`string`?QT.basename(this.path,this.extname):void 0}set stem(e){mE(e,`stem`),pE(e,`stem`),this.path=QT.join(this.dirname||``,e+(this.extname||``))}fail(e,t,n){let r=this.message(e,t,n);throw r.fatal=!0,r}info(e,t,n){let r=this.message(e,t,n);return r.fatal=void 0,r}message(e,t,n){let r=new tx(e,t,n);return this.path&&(r.name=this.path+`:`+r.name,r.file=this.path),r.fatal=!1,this.messages.push(r),r}toString(e){return this.value===void 0?``:typeof this.value==`string`?this.value:new TextDecoder(e||void 0).decode(this.value)}};function pE(e,t){if(e&&e.includes(QT.sep))throw Error("`"+t+"` cannot be a path: did not expect `"+QT.sep+"`")}function mE(e,t){if(!e)throw Error("`"+t+"` cannot be empty")}function hE(e,t){if(!e)throw Error("Setting `"+t+"` requires `path` to be set too")}function gE(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var _E=(function(e){let t=this.constructor.prototype,n=t[e],r=function(){return n.apply(r,arguments)};return Object.setPrototypeOf(r,t),r}),vE=l(JT(),1),yE={}.hasOwnProperty,bE=new class e extends _E{constructor(){super(`copy`),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=XT()}copy(){let t=new e,n=-1;for(;++n<this.attachers.length;){let e=this.attachers[n];t.use(...e)}return t.data((0,vE.default)(!0,{},this.namespace)),t}data(e,t){return typeof e==`string`?arguments.length===2?(CE(`data`,this.frozen),this.namespace[e]=t,this):yE.call(this.namespace,e)&&this.namespace[e]||void 0:e?(CE(`data`,this.frozen),this.namespace=e,this):this.namespace}freeze(){if(this.frozen)return this;let e=this;for(;++this.freezeIndex<this.attachers.length;){let[t,...n]=this.attachers[this.freezeIndex];if(n[0]===!1)continue;n[0]===!0&&(n[0]=void 0);let r=t.call(e,...n);typeof r==`function`&&this.transformers.use(r)}return this.frozen=!0,this.freezeIndex=1/0,this}parse(e){this.freeze();let t=EE(e),n=this.parser||this.Parser;return xE(`parse`,n),n(String(t),t)}process(e,t){let n=this;return this.freeze(),xE(`process`,this.parser||this.Parser),SE(`process`,this.compiler||this.Compiler),t?r(void 0,t):new Promise(r);function r(r,i){let a=EE(e),o=n.parse(a);n.run(o,a,function(e,t,r){if(e||!t||!r)return s(e);let i=t,a=n.stringify(i,r);OE(a)?r.value=a:r.result=a,s(e,r)});function s(e,n){e||!n?i(e):r?r(n):t(void 0,n)}}}processSync(e){let t=!1,n;return this.freeze(),xE(`processSync`,this.parser||this.Parser),SE(`processSync`,this.compiler||this.Compiler),this.process(e,r),TE(`processSync`,`process`,t),n;function r(e,r){t=!0,qT(e),n=r}}run(e,t,n){wE(e),this.freeze();let r=this.transformers;return!n&&typeof t==`function`&&(n=t,t=void 0),n?i(void 0,n):new Promise(i);function i(i,a){let o=EE(t);r.run(e,o,s);function s(t,r,o){let s=r||e;t?a(t):i?i(s):n(void 0,s,o)}}}runSync(e,t){let n=!1,r;return this.run(e,t,i),TE(`runSync`,`run`,n),r;function i(e,t){qT(e),r=t,n=!0}}stringify(e,t){this.freeze();let n=EE(t),r=this.compiler||this.Compiler;return SE(`stringify`,r),wE(e),r(e,n)}use(e,...t){let n=this.attachers,r=this.namespace;if(CE(`use`,this.frozen),e!=null)if(typeof e==`function`)s(e,t);else if(typeof e==`object`)Array.isArray(e)?o(e):a(e);else throw TypeError("Expected usable value, not `"+e+"`");return this;function i(e){if(typeof e==`function`)s(e,[]);else if(typeof e==`object`)if(Array.isArray(e)){let[t,...n]=e;s(t,n)}else a(e);else throw TypeError("Expected usable value, not `"+e+"`")}function a(e){if(!(`plugins`in e)&&!(`settings`in e))throw Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");o(e.plugins),e.settings&&(r.settings=(0,vE.default)(!0,r.settings,e.settings))}function o(e){let t=-1;if(e!=null)if(Array.isArray(e))for(;++t<e.length;){let n=e[t];i(n)}else throw TypeError("Expected a list of plugins, not `"+e+"`")}function s(e,t){let r=-1,i=-1;for(;++r<n.length;)if(n[r][0]===e){i=r;break}if(i===-1)n.push([e,...t]);else if(t.length>0){let[r,...a]=t,o=n[i][1];YT(o)&&YT(r)&&(r=(0,vE.default)(!0,o,r)),n[i]=[e,r,...a]}}}}().freeze();function xE(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function SE(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function CE(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function wE(e){if(!YT(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function TE(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function EE(e){return DE(e)?e:new fE(e)}function DE(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function OE(e){return typeof e==`string`||kE(e)}function kE(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var AE=[],jE={allowDangerousHtml:!0},ME=/^(https?|ircs?|mailto|xmpp)$/i,NE=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`className`,id:`remove-classname`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function PE(e){let t=FE(e),n=IE(e);return LE(t.runSync(t.parse(n),n),e)}function FE(e){let t=e.rehypePlugins||AE,n=e.remarkPlugins||AE,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...jE}:jE;return bE().use(Mw).use(n).use(KT,r).use(t)}function IE(e){let t=e.children||``,n=new fE;return typeof t==`string`?n.value=t:``+t,n}function LE(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||RE;for(let e of NE)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return IT(e,l),lx(e,{Fragment:H.Fragment,components:i,ignoreInvalidStyle:!0,jsx:H.jsx,jsxs:H.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in jx)if(Object.hasOwn(jx,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=jx[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function RE(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||ME.test(e.slice(0,t))?e:``}function zE({children:e,className:t}){return(0,H.jsx)(`div`,{className:`markdown-view ${t??``}`,children:(0,H.jsx)(PE,{children:e})})}function BE({sessionId:e,nodeId:t,runStatus:n=`complete`,currentNodeId:r=null,executionTraceSummary:i=null}){let{data:a,isLoading:o,error:s}=Ky(e,t);return t?(0,H.jsxs)(`div`,{children:[(0,H.jsx)(VE,{stepLabel:a?.stepLabel??null,nodeId:t}),(0,H.jsxs)(`div`,{className:`p-4 space-y-4`,children:[o&&(0,H.jsx)(`div`,{className:`text-[var(--text-secondary)] text-sm`,children:`Loading...`}),s&&(0,H.jsx)(`div`,{className:`text-[var(--error)] text-sm bg-[var(--bg-primary)] border border-[var(--border)] px-4 py-3`,children:s.message}),a&&(0,H.jsx)(KE,{detail:a,runStatus:n,currentNodeId:r,executionTraceSummary:i})]})]}):(0,H.jsx)(`div`,{className:`px-5 py-8 text-sm text-[var(--text-secondary)]`,children:`Select a node in the lineage to inspect its recap, validations, gaps, and artifacts.`})}function VE({stepLabel:e,nodeId:t}){return(0,H.jsxs)(`div`,{className:`px-5 py-4 border-b border-[var(--border)] console-blueprint-grid`,children:[(0,H.jsx)(`div`,{className:`text-base font-semibold text-[var(--text-primary)] leading-tight`,children:e??`Untitled node`}),(0,H.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-[var(--text-muted)] truncate`,children:t})]})}function HE({item:e}){return(0,H.jsxs)(`div`,{className:`flex items-start gap-2 text-xs py-1`,children:[(0,H.jsx)(`span`,{className:`flex-1 text-[var(--text-secondary)] leading-relaxed`,children:e.summary}),(0,H.jsxs)(`span`,{className:`font-mono text-[10px] text-[var(--text-muted)] shrink-0`,children:[`#`,e.recordedAtEventIndex]})]})}function UE({nodeId:e,nodeKind:t,executionTraceSummary:n}){let{whySelected:r,conditions:i,loops:a,divergences:o,forks:s}=py(n,e);return n.items.some(t=>t.kind!==`context_fact`&&t.refs.some(t=>t.kind===`node_id`&&t.value===e))?(0,H.jsx)(sD,{title:`Routing context`,children:(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(r.length>0||t===`blocked_attempt`)&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-1.5 flex items-center gap-2`,children:(0,H.jsx)(Py,{label:`WHY SELECTED`,color:`var(--accent)`,bgColor:`rgba(244,196,48,0.10)`})}),r.length>0?(0,H.jsx)(`div`,{className:`space-y-1 pl-2 border-l border-[var(--border)]`,children:r.map((e,t)=>(0,H.jsx)(HE,{item:e},t))}):t===`blocked_attempt`?(0,H.jsx)(`div`,{className:`pl-2 border-l border-[var(--border)]`,children:(0,H.jsx)(`span`,{className:`text-xs text-[var(--text-muted)]`,children:`This step was attempted but not selected as the preferred path.`})}):null]}),i.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-1.5`,children:(0,H.jsx)(Py,{label:`CONDITIONS EVALUATED`,color:`var(--text-secondary)`,bgColor:`rgba(168,159,140,0.10)`})}),(0,H.jsx)(`div`,{className:`space-y-1 pl-2 border-l border-[var(--border)]`,children:[...i.filter(e=>!sy(e)),...i.filter(e=>sy(e))].map((e,t)=>{let n=sy(e);return(0,H.jsxs)(`div`,{className:`flex items-start gap-2 text-xs py-0.5`,children:[(0,H.jsx)(Py,{label:n?`PASS`:`SKIP`,color:n?`var(--success)`:`var(--warning)`,bgColor:n?`rgba(34,197,94,0.10)`:`rgba(251,191,36,0.10)`}),(0,H.jsx)(`span`,{className:`flex-1 text-[var(--text-secondary)] leading-relaxed`,children:e.summary})]},t)})})]}),a.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-1.5`,children:(0,H.jsx)(Py,{label:`LOOP`,color:`var(--accent-strong)`,bgColor:`rgba(0,240,255,0.10)`})}),(0,H.jsx)(`div`,{className:`space-y-1 pl-2 border-l border-[var(--border)]`,children:a.map((e,t)=>(0,H.jsx)(HE,{item:e},t))})]}),o.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-1.5`,children:(0,H.jsx)(Py,{label:`DIVERGENCE`,color:`var(--error)`,bgColor:`rgba(255,107,107,0.10)`})}),(0,H.jsx)(`div`,{className:`space-y-1 pl-2 border-l border-[var(--border)]`,children:o.map((e,t)=>(0,H.jsx)(HE,{item:e},t))})]}),s.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-1.5`,children:(0,H.jsx)(Py,{label:`FORK`,color:`var(--warning)`,bgColor:`rgba(251,191,36,0.10)`})}),(0,H.jsx)(`div`,{className:`space-y-1 pl-2 border-l border-[var(--border)]`,children:s.map((e,t)=>(0,H.jsx)(HE,{item:e},t))})]})]})}):(0,H.jsx)(sD,{title:`Routing context`,children:t===`blocked_attempt`&&r.length===0?(0,H.jsxs)(`div`,{className:`flex items-start gap-2 py-1`,children:[(0,H.jsx)(Py,{label:`WHY SELECTED`,color:`var(--text-muted)`,bgColor:`rgba(123,141,167,0.08)`}),(0,H.jsx)(`span`,{className:`text-xs text-[var(--text-muted)] leading-relaxed`,children:`This step was attempted but not selected as the preferred path.`})]}):(0,H.jsx)(`span`,{className:`font-mono text-xs text-[var(--text-muted)]`,children:`// no routing trace for this node`})})}function WE({items:e}){let[t,n]=(0,V.useState)(!1);return(0,H.jsx)(sD,{title:`Run routing`,children:(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`button`,{type:`button`,"aria-expanded":t,onClick:()=>n(e=>!e),className:`flex items-center gap-2 font-mono text-[10px] uppercase tracking-[0.20em] text-[var(--text-muted)] hover:text-[var(--text-secondary)] transition-colors`,children:[(0,H.jsx)(Py,{label:`RUN ROUTING`,color:`var(--text-muted)`,bgColor:`rgba(123,141,167,0.08)`}),(0,H.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[`// `,e.length,` ambient items`]}),(0,H.jsx)(`span`,{children:t?`[-]`:`[+]`})]}),t&&(0,H.jsx)(`div`,{className:`mt-2 space-y-1 pl-2 border-l border-[var(--border)]`,children:e.map((e,t)=>(0,H.jsxs)(`div`,{className:`flex items-start gap-2 text-xs py-0.5`,children:[(0,H.jsx)(`span`,{className:`shrink-0 inline-flex items-center px-2 py-0.5 font-mono text-[10px] uppercase tracking-[0.16em]`,style:{color:`var(--text-muted)`,backgroundColor:`rgba(123,141,167,0.08)`,border:`1px solid rgba(123,141,167,0.20)`},children:e.kind.replace(/_/g,` `).toUpperCase()}),(0,H.jsx)(`span`,{className:`flex-1 text-[var(--text-secondary)] leading-relaxed`,children:e.summary}),(0,H.jsxs)(`span`,{className:`font-mono text-[10px] text-[var(--text-muted)] shrink-0`,children:[`#`,e.recordedAtEventIndex]})]},t))})]})})}var GE=[{id:`routing`,column:`primary`,render:({detail:e,executionTraceSummary:t})=>t===null?null:(0,H.jsx)(UE,{nodeId:e.nodeId,nodeKind:e.nodeKind,executionTraceSummary:t},`routing`)},{id:`run_routing`,column:`primary`,render:({executionTraceSummary:e})=>{if(e===null)return null;let t=e.items.filter(e=>!e.refs.some(e=>e.kind===`node_id`));return t.length===0?null:(0,H.jsx)(WE,{items:t},`run_routing`)}},{id:`recap`,column:`primary`,render:({detail:e,runStatus:t,currentNodeId:n})=>e.recapMarkdown?(0,H.jsx)(QE,{markdown:e.recapMarkdown},`recap`):t===`in_progress`&&e.nodeId===n&&!e.recapMarkdown?(0,H.jsx)(qE,{detail:e},`recap-in-progress`):null},{id:`validations`,column:`primary`,render:({detail:e})=>e.validations.length>0?(0,H.jsx)(eD,{validations:e.validations},`validations`):null},{id:`gaps`,column:`primary`,render:({detail:e})=>e.gaps.length>0?(0,H.jsx)(nD,{gaps:e.gaps},`gaps`):null},{id:`advance-outcome`,column:`primary`,render:({detail:e})=>e.advanceOutcome?(0,H.jsx)($E,{outcome:e.advanceOutcome},`advance-outcome`):null},{id:`artifacts`,column:`primary`,render:({detail:e})=>e.artifacts.length>0?(0,H.jsx)(oD,{artifacts:e.artifacts},`artifacts`):null},{id:`node-meta`,column:`primary`,render:({detail:e})=>(0,H.jsx)(ZE,{detail:e},`node-meta`)}];function KE(e){return(0,H.jsx)(`div`,{className:`space-y-4`,children:GE.map(t=>t.render(e))})}function qE({detail:e}){return(0,H.jsx)(sD,{title:`Recap`,children:(0,H.jsxs)(`div`,{className:`space-y-4 text-sm text-[var(--text-secondary)]`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(JE,{children:`In progress`}),(0,H.jsxs)(`span`,{className:`font-mono text-xs text-[var(--text-muted)]`,children:[`event #`,e.createdAtEventIndex]})]}),(0,H.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-2 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]`,children:[(0,H.jsx)(YE,{label:`Current focus`,value:e.stepLabel??`Current workflow step`,supportingText:`This step is still running, so the recap will appear once execution finishes.`}),(0,H.jsx)(YE,{label:`Current state`,value:`Waiting for step completion`,supportingText:`The node has been created and selected as the current workflow position.`,mono:!0})]}),(0,H.jsxs)(`div`,{className:`bg-[var(--bg-primary)] border border-[var(--border)] overflow-hidden`,children:[(0,H.jsx)(`div`,{className:`px-4 py-3 border-b border-[var(--border)]`,children:(0,H.jsx)(Go,{children:`What lands here next`})}),(0,H.jsxs)(`div`,{className:`p-4 grid gap-3 md:grid-cols-3`,children:[(0,H.jsx)(XE,{title:`Recap`,description:`A step summary is written when this node completes.`}),(0,H.jsx)(XE,{title:`Validations`,description:`Validation results appear if this step records contract checks.`}),(0,H.jsx)(XE,{title:`Artifacts`,description:`Generated outputs show up here after the step produces them.`})]})]})]})})}function JE({children:e}){return(0,H.jsx)(`span`,{className:`inline-flex items-center px-2 py-1 font-medium text-xs`,style:{backgroundColor:`rgba(0, 219, 233, 0.12)`,color:`var(--accent-strong)`},children:e})}function YE({label:e,value:t,supportingText:n,mono:r=!1}){return(0,H.jsxs)(`div`,{className:`bg-[var(--bg-primary)] border border-[var(--border)] px-4 py-3 space-y-2`,children:[(0,H.jsx)(Go,{children:e}),(0,H.jsx)(`div`,{className:r?`font-mono text-sm text-[var(--text-primary)]`:`text-[var(--text-primary)]`,children:t}),(0,H.jsx)(`div`,{className:`text-xs text-[var(--text-muted)] leading-relaxed`,children:n})]})}function XE({title:e,description:t}){return(0,H.jsxs)(`div`,{className:`border border-[var(--border)] bg-[rgba(255,255,255,0.02)] px-3 py-3 space-y-2`,children:[(0,H.jsx)(Go,{color:`var(--text-secondary)`,children:e}),(0,H.jsx)(`div`,{className:`text-xs text-[var(--text-muted)] leading-relaxed`,children:t})]})}function ZE({detail:e}){return(0,H.jsx)(sD,{title:`Node details`,children:(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(0,H.jsx)(cD,{label:`Kind`,value:(0,H.jsx)(uD,{kind:e.nodeKind})}),(0,H.jsx)(cD,{label:`Event index`,value:String(e.createdAtEventIndex),mono:!0}),(0,H.jsx)(cD,{label:`Parent`,value:e.parentNodeId??`Root`,mono:!0}),(0,H.jsx)(cD,{label:`Tip state`,value:e.isTip?e.isPreferredTip?`Preferred tip`:`Tip`:`Historical`})]})})}function QE({markdown:e}){return(0,H.jsx)(sD,{title:`Recap`,children:(0,H.jsx)(zE,{children:e})})}function $E({outcome:e}){let t=e.kind===`advanced`;return(0,H.jsx)(sD,{title:`Advance outcome`,children:(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-xs`,children:[(0,H.jsx)(`span`,{className:`inline-flex items-center px-2 py-1 font-medium`,style:{backgroundColor:t?`var(--success)20`:`var(--blocked)20`,color:t?`var(--success)`:`var(--blocked)`},children:t?`Advanced`:`Blocked`}),(0,H.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[`attempt `,e.attemptId.slice(-8),` at event #`,e.recordedAtEventIndex]})]})})}function eD({validations:e}){return(0,H.jsx)(sD,{title:`Validations (${e.length})`,children:(0,H.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,H.jsx)(tD,{validation:e},e.validationId))})})}function tD({validation:e}){let t=e.outcome===`pass`;return(0,H.jsxs)(`div`,{className:`bg-[var(--bg-primary)] border border-[var(--border)] px-4 py-3 text-xs space-y-2`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`inline-flex items-center px-2 py-1 font-medium`,style:{backgroundColor:t?`var(--success)20`:`var(--error)20`,color:t?`var(--success)`:`var(--error)`},children:t?`Pass`:`Fail`}),(0,H.jsx)(`span`,{className:`text-[var(--text-muted)] font-mono`,children:e.contractRef})]}),e.issues.length>0&&(0,H.jsxs)(`div`,{className:`space-y-1`,children:[(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] mb-1`,children:`Issues`}),(0,H.jsx)(`ul`,{className:`list-disc list-inside text-[var(--error)] space-y-0.5`,children:e.issues.map((e,t)=>(0,H.jsx)(`li`,{children:e},t))})]}),e.suggestions.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] mb-1`,children:`Suggestions`}),(0,H.jsx)(`ul`,{className:`list-disc list-inside text-[var(--text-secondary)] space-y-0.5`,children:e.suggestions.map((e,t)=>(0,H.jsx)(`li`,{children:e},t))})]})]})}function nD({gaps:e}){return(0,H.jsx)(sD,{title:`Gaps (${e.length})`,children:(0,H.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,H.jsxs)(`div`,{className:`flex items-start gap-3 text-xs bg-[var(--bg-primary)] border border-[var(--border)] px-3 py-3`,children:[(0,H.jsx)(`span`,{className:`shrink-0 inline-flex items-center px-2 py-1 font-medium`,style:{backgroundColor:e.isResolved?`var(--success)20`:e.severity===`critical`?`var(--error)20`:`var(--warning)20`,color:e.isResolved?`var(--success)`:e.severity===`critical`?`var(--error)`:`var(--warning)`},children:e.isResolved?`Resolved`:e.severity===`critical`?`Critical`:`Non-critical`}),(0,H.jsx)(`span`,{className:`text-[var(--text-secondary)] leading-relaxed`,children:e.summary})]},e.gapId))})})}var rD=1e5,iD=[{prefix:`text/`,render:e=>(0,H.jsx)(`pre`,{className:`text-[var(--text-secondary)] whitespace-pre-wrap break-words font-mono max-h-40 overflow-y-auto`,children:typeof e==`string`?e:String(e)})},{prefix:`application/json`,render:e=>(0,H.jsx)(`pre`,{className:`text-[var(--text-secondary)] whitespace-pre-wrap break-words font-mono max-h-40 overflow-y-auto`,children:typeof e==`string`?e:JSON.stringify(e,null,2)})}];function aD(e){if(e.byteLength>rD)return(0,H.jsxs)(`div`,{className:`text-[var(--text-muted)] italic`,children:[`Content too large to display (`,dD(e.byteLength),` -- limit `,dD(rD),`)`]});let t=iD.find(t=>e.contentType.startsWith(t.prefix));return t?t.render(e.content):(0,H.jsx)(`pre`,{className:`text-[var(--text-secondary)] whitespace-pre-wrap break-words font-mono max-h-40 overflow-y-auto`,children:typeof e.content==`string`?e.content:JSON.stringify(e.content,null,2)})}function oD({artifacts:e}){return(0,H.jsx)(sD,{title:`Artifacts (${e.length})`,children:(0,H.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,H.jsxs)(`div`,{className:`bg-[var(--bg-primary)] border border-[var(--border)] px-4 py-3 text-xs space-y-2`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[var(--text-muted)]`,children:[(0,H.jsx)(`span`,{children:e.contentType}),(0,H.jsx)(`span`,{children:`//`}),(0,H.jsx)(`span`,{children:dD(e.byteLength)})]}),aD(e)]},e.sha256))})})}function sD({title:e,children:t}){return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-2`,children:(0,H.jsx)(Go,{children:e})}),t]})}function cD({label:e,value:t,mono:n=!1}){return(0,H.jsxs)(`div`,{className:`bg-[var(--bg-primary)] border border-[var(--border)] px-4 py-3`,children:[(0,H.jsx)(Go,{children:e}),(0,H.jsx)(`div`,{className:n?`mt-2 font-mono text-sm text-[var(--text-secondary)] truncate`:`mt-2 text-sm text-[var(--text-primary)]`,children:t})]})}var lD={step:{label:`Step`,color:`var(--accent)`},checkpoint:{label:`Checkpoint`,color:`var(--success)`},blocked_attempt:{label:`Blocked`,color:`var(--error)`}};function uD({kind:e}){let t=lD[e];return(0,H.jsx)(`span`,{className:`inline-flex items-center px-2 py-1 font-medium`,style:{backgroundColor:`${t.color}20`,color:t.color},children:t.label})}function dD(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function fD(e){return e.length>16?`\u2026${e.slice(-16)}`:e}function pD({data:e}){let t=e.runs[0]??null,n=t?.workflowName??t?.workflowId??`--`,r=t?.workflowHash?.slice(0,12)??`--`;return(0,H.jsxs)(`div`,{className:`bg-[var(--bg-card)] border border-[var(--border)] px-5 py-4 corner-brackets`,style:{backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`},children:[e.sessionTitle&&(0,H.jsx)(`h2`,{className:`text-base font-medium text-[var(--text-primary)] mb-3`,children:e.sessionTitle}),(0,H.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-8 gap-y-2`,children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)] self-center`,children:`Session`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)] self-center`,children:fD(e.sessionId)}),(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)] self-center`,children:`Workflow`}),(0,H.jsx)(`dd`,{className:`text-sm text-[var(--text-primary)] self-center`,children:n}),(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)] self-center`,children:`Hash`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)] self-center`,children:r}),(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)] self-center`,children:`Status`}),(0,H.jsxs)(`dd`,{className:`self-center flex items-center gap-2`,children:[(0,H.jsx)(io,{health:e.health}),e.health===`healthy`&&(0,H.jsx)(`span`,{className:`text-sm text-[var(--text-primary)]`,children:`Healthy`})]}),(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)] self-center`,children:`Runs`}),(0,H.jsxs)(`dd`,{className:`text-sm text-[var(--text-primary)] self-center`,children:[e.runs.length,` run`,e.runs.length===1?``:`s`]})]})]})}function mD(e){if(e<6e4)return`${Math.round(e/1e3)}s`;let t=Math.floor(e/6e4),n=Math.round(e%6e4/1e3);return n>0?`${t}m ${n}s`:`${t}m`}function hD({sessionId:e,metrics:t}){let[n,r]=(0,V.useState)({kind:`idle`}),i=qy(e,!1),a=t.startGitSha!==null&&t.endGitSha!==null,o=async()=>{r({kind:`loading`});try{let e=await i.refetch();e.isSuccess&&e.data?r({kind:`loaded`,linesAdded:e.data.linesAdded,linesRemoved:e.data.linesRemoved,filesChanged:e.data.filesChanged}):r({kind:`error`,message:e.error instanceof Error?e.error.message:`Diff computation failed`})}catch(e){r({kind:`error`,message:e instanceof Error?e.message:`Diff computation failed`})}};return(0,H.jsxs)(`div`,{className:`bg-[var(--bg-card)] border border-[var(--border)] px-5 py-4 corner-brackets space-y-4`,style:{backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`},children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)]`,children:`Session Metrics`}),(0,H.jsx)(`span`,{className:`font-mono text-[10px] text-[var(--text-muted)]`,children:`Session-level totals across all runs.`})]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[t.outcome!==null&&(0,H.jsx)(`span`,{className:`px-2 py-1 text-xs font-mono border border-[var(--border)] text-[var(--text-secondary)] bg-[var(--bg-card)]`,children:t.outcome}),t.durationMs!==void 0&&(0,H.jsx)(`span`,{className:`px-2 py-1 text-xs font-mono border border-[var(--border)] text-[var(--text-secondary)] bg-[var(--bg-card)]`,children:mD(t.durationMs)}),t.filesChanged!==null&&(0,H.jsxs)(`span`,{className:`px-2 py-1 text-xs font-mono border border-[var(--border)] text-[var(--text-secondary)] bg-[var(--bg-card)]`,children:[t.filesChanged,` file`,t.filesChanged===1?``:`s`,` changed`]}),t.captureConfidence!==`none`&&(0,H.jsxs)(`span`,{className:`px-2 py-1 text-xs font-mono border border-[var(--border)] text-[var(--text-muted)] bg-[var(--bg-card)]`,children:[t.captureConfidence,` confidence`]})]}),(0,H.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-8 gap-y-2`,children:[t.gitBranch!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Git Branch`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)] self-center`,children:t.gitBranch})]}),t.startGitSha!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Start SHA`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)] self-center`,children:t.startGitSha.slice(0,12)})]}),t.endGitSha!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`End SHA`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)] self-center`,children:t.endGitSha.slice(0,12)})]}),t.durationMs!==void 0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Duration`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)] self-center`,children:mD(t.durationMs)})]}),t.agentCommitShas.length>0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-start`,children:`Commits`}),(0,H.jsx)(`dd`,{className:`font-mono text-xs text-[var(--text-secondary)]`,children:t.agentCommitShas.map(e=>(0,H.jsx)(`div`,{children:e.slice(0,12)},e))})]}),t.outcome!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Outcome`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[t.outcome,` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(agent-reported)`})]})]}),t.filesChanged!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Files Changed`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[t.filesChanged,` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(agent-reported)`})]})]}),t.linesAdded!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Lines Added`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[t.linesAdded,` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(agent-reported)`})]})]}),t.linesRemoved!==null&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`Lines Removed`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[t.linesRemoved,` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(agent-reported)`})]})]}),t.prNumbers.length>0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`PRs`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[t.prNumbers.join(`, `),` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(agent-reported)`})]})]}),n.kind===`loaded`&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`LOC Added`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[n.linesAdded,` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(git diff)`})]}),(0,H.jsx)(`dt`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] self-center`,children:`LOC Removed`}),(0,H.jsxs)(`dd`,{className:`text-xs text-[var(--text-secondary)] self-center`,children:[n.linesRemoved,` `,(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`(git diff)`})]})]})]}),a&&n.kind!==`loaded`&&(0,H.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[n.kind===`idle`&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>{o()},className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] hover:text-[var(--text-primary)] border border-[var(--border)] px-3 py-1.5 transition-colors`,children:`Load diff`}),n.kind===`loading`&&(0,H.jsx)(`span`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)]`,children:`Computing...`}),n.kind===`error`&&(0,H.jsxs)(`span`,{className:`text-xs text-[var(--error)]`,children:[n.message,` `,(0,H.jsx)(`button`,{type:`button`,onClick:()=>{o()},className:`underline text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors`,children:`Retry`})]})]})]})}function gD({runs:e}){let t=e.some(e=>e.preferredTipNodeId!==null),n=e.some(e=>e.executionTraceSummary!==null);return(0,H.jsxs)(`div`,{className:`border border-[var(--border)] px-4 py-3 text-xs text-[var(--text-muted)] space-y-1`,children:[(0,H.jsx)(`p`,{children:t?`Nodes with a gold border are the current execution tips — click any node to inspect its execution detail.`:`Click any node in the DAG to inspect its execution detail.`}),n&&(0,H.jsxs)(`p`,{children:[`This run has execution trace data. Click`,` `,(0,H.jsx)(`span`,{className:`font-mono uppercase tracking-[0.16em]`,children:`[ TRACE ]`}),` `,`to see why certain steps ran, were skipped, or repeated.`]})]})}function _D({viewModel:e}){let{state:t,onSelectNode:n,onCloseNode:r}=e;if(t.kind===`loading`)return(0,H.jsx)(`div`,{className:`text-[var(--text-secondary)]`,children:`Loading session...`});if(t.kind===`error`)return(0,H.jsxs)(`div`,{className:`text-[var(--error)] bg-[var(--bg-card)] rounded-lg p-4`,children:[`Failed to load session: `,t.message]});let{sessionId:i,data:a,selectedNode:o,selectedRun:s}=t;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsx)(pD,{data:a}),a.metrics!==null&&(0,H.jsx)(hD,{sessionId:i,metrics:a.metrics}),a.runs.length===0?(0,H.jsx)(`div`,{className:`text-center py-16 text-[var(--text-secondary)]`,children:`No runs in this session`}):(0,H.jsxs)(H.Fragment,{children:[o===null&&(0,H.jsx)(gD,{runs:a.runs}),(0,H.jsx)(`div`,{className:`space-y-6`,children:a.runs.map(e=>(0,H.jsx)(vD,{run:e,selectedNodeId:o?.runId===e.runId?o.nodeId:null,onNodeClick:n},e.runId))})]})]}),(0,H.jsxs)(co,{cut:18,borderColor:`rgba(244, 196, 48, 0.35)`,background:`rgba(27, 31, 44, 0.78)`,dropShadow:`drop-shadow(0 16px 48px rgba(0,0,0,0.9)) drop-shadow(0 2px 12px rgba(244,196,48,0.15))`,backdropFilter:`blur(16px)`,className:`fixed top-3 right-3 bottom-3 w-[560px] max-w-[calc(92vw-12px)] transition-transform duration-200 ease-out`,style:{zIndex:40,transform:o?`translateX(0)`:`translateX(calc(100% + 12px))`},children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-[var(--border)] shrink-0 console-blueprint-grid`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-muted)]`,children:`Node detail`}),(0,H.jsx)(`button`,{onClick:r,className:`text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors text-xl leading-none px-1`,"aria-label":`Close`,children:`×`})]}),(0,H.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,H.jsx)(BE,{sessionId:i,nodeId:o?.nodeId??null,runStatus:s?.status??`complete`,currentNodeId:s?.preferredTipNodeId??null,executionTraceSummary:s?.executionTraceSummary??null})})]})]})}function vD({run:e,selectedNodeId:t,onNodeClick:n}){let r=e.executionTraceSummary!==null,[i,a]=(0,V.useState)(`dag`);return(0,H.jsxs)(co,{cut:10,background:`rgba(27, 31, 44, 0.72)`,backdropFilter:`blur(8px)`,className:`relative`,style:{height:r?`542px`:`506px`},children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-[var(--border)] shrink-0`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-[var(--text-primary)]`,children:e.workflowName??e.workflowId??`Run`}),(0,H.jsx)(`span`,{className:`font-mono text-xs text-[var(--text-muted)]`,children:e.runId}),(0,H.jsxs)(`span`,{className:`font-mono text-xs text-[var(--text-muted)]`,children:[e.nodes.length,` nodes · `,e.tipNodeIds.length,` tip`,e.tipNodeIds.length===1?``:`s`]})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.hasUnresolvedCriticalGaps&&(0,H.jsx)(`span`,{className:`text-xs text-[var(--warning)]`,children:`Critical gaps`}),(0,H.jsx)(ro,{status:e.status})]})]}),r&&(0,H.jsxs)(`div`,{role:`tablist`,"aria-label":`Run view mode`,className:`flex items-center border-b border-[var(--border)] shrink-0 h-9 px-2 gap-0.5`,onKeyDown:e=>{e.key===`ArrowRight`&&(e.preventDefault(),a(`trace`)),e.key===`ArrowLeft`&&(e.preventDefault(),a(`dag`))},children:[(0,H.jsxs)(`button`,{type:`button`,id:`tab-dag`,role:`tab`,tabIndex:i===`dag`?0:-1,"aria-selected":i===`dag`,onClick:()=>a(`dag`),className:[`tab-btn px-3 py-1.5 font-mono text-[10px] uppercase tracking-[0.25em] transition-colors duration-150`,i===`dag`?`tab-btn--active text-[var(--accent)]`:`text-[var(--text-secondary)] hover:text-[var(--text-primary)]`].join(` `),style:i===`dag`?{backgroundColor:`rgba(244, 196, 48, 0.06)`}:void 0,children:[(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tr`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--bl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--br`,"aria-hidden":`true`}),`DAG`]}),(0,H.jsxs)(`button`,{type:`button`,id:`tab-trace`,role:`tab`,tabIndex:i===`trace`?0:-1,"aria-selected":i===`trace`,onClick:()=>a(`trace`),className:[`tab-btn px-3 py-1.5 font-mono text-[10px] uppercase tracking-[0.25em] transition-colors duration-150`,i===`trace`?`tab-btn--active text-[var(--accent)]`:`text-[var(--text-secondary)] hover:text-[var(--text-primary)]`].join(` `),style:i===`trace`?{backgroundColor:`rgba(244, 196, 48, 0.06)`}:void 0,children:[(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tr`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--bl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--br`,"aria-hidden":`true`}),`TRACE`]})]}),(0,H.jsx)(`div`,{role:`tabpanel`,"aria-labelledby":i===`dag`?`tab-dag`:`tab-trace`,className:`flex-1`,children:i===`trace`&&e.executionTraceSummary!==null?(0,H.jsx)(By,{summary:e.executionTraceSummary,runStatus:e.status}):(0,H.jsx)(my,{run:e,selectedNodeId:t,onNodeClick:t=>n(e.runId,t)})})]})}function yD(){let[e,t]=(0,V.useState)(0),[n,r]=(0,V.useState)(0),[i,a]=(0,V.useState)(38),[o,s]=(0,V.useState)(62),[c,l]=(0,V.useState)(3),[u,d]=(0,V.useState)(2),[f,p]=(0,V.useState)(``),[m,h]=(0,V.useState)(!1),g=(0,V.useRef)(!1),_=(0,V.useRef)(null),v=(0,V.useRef)(null),y=(0,V.useRef)(null),b=(e,n,i,o,c,u)=>{g.current=!0,h(!0),t(e=>e+1),r(Math.floor(Math.random()*4)),a(5+Math.floor(Math.random()*80)),s(5+Math.floor(Math.random()*80)),l(2+Math.floor(Math.random()*40)),d(2+Math.floor(Math.random()*25)),p(i===`horizontal`?n===`next`?`modal-content--exit-h-next`:`modal-content--exit-h-prev`:n===`next`?`modal-content--exit-v-next`:`modal-content--exit-v-prev`),c.current&&(c.current.scrollTop=0);let f=u[e].id;setTimeout(()=>{o(f),p(i===`horizontal`?n===`next`?`modal-content--enter-h-next`:`modal-content--enter-h-prev`:n===`next`?`modal-content--enter-v-next`:`modal-content--enter-v-prev`),h(!1)},80),setTimeout(()=>{if(p(``),g.current=!1,_.current!==null){let e=_.current;_.current=null;let t=e>u.findIndex(e=>e.id===v.current)?`next`:`prev`;y.current?.(e,t,`horizontal`,o,c,u)}},240)};return y.current=b,{state:{isAnimating:g.current,contentAnimClass:f,borderFlashing:m,scanline:e>0?{key:e,crtOffset:n,glitchY:i,glitchY2:o,glitchW:c,glitchW2:u}:null},startTransition:b,navigate:(e,t,n,r,i,a)=>{if(t.length<=1)return;let o=t.findIndex(t=>t.id===e);if(o===-1)return;let s=n===`next`?(o+1)%t.length:(o-1+t.length)%t.length;if(g.current){_.current=s;return}b(s,n,r,i,a,t)},selectedWorkflowIdRef:v}}var bD=[{id:`coding`,label:`Coding`},{id:`review_audit`,label:`Review & Audit`},{id:`investigation`,label:`Investigation`},{id:`design`,label:`Design`},{id:`documentation`,label:`Documentation`},{id:`tickets`,label:`Tickets`},{id:`learning`,label:`Learning`},{id:`authoring`,label:`Workflow Authoring`}],xD=Object.fromEntries(bD.map(e=>[e.id,e.label]));function SD({label:e,count:t,countLabel:n=`workflow`,showRule:r=!0,separator:i=`//`}){return(0,H.jsxs)(`div`,{className:`flex items-center gap-3 mb-3 mt-2`,children:[(0,H.jsxs)(`span`,{className:`font-mono text-[11px] uppercase tracking-[0.30em] text-[var(--text-secondary)] shrink-0`,children:[e,t==null?``:` ${i} ${t} ${n}${t===1?``:`s`}`]}),r&&(0,H.jsx)(`div`,{className:`flex-1 h-px bg-[var(--border)]`})]})}function CD({segments:e,className:t=``}){return(0,H.jsx)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-0 ${t}`,children:e.map((t,n)=>{let r=n===e.length-1,i=!!t.onClick;return(0,H.jsxs)(`span`,{className:`flex items-center`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[10px] tracking-[0.25em] text-[var(--text-muted)] mx-1`,children:`//`}),i?(0,H.jsx)(`button`,{type:`button`,onClick:t.onClick,className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] hover:text-[var(--accent)] transition-colors cursor-pointer`,children:t.label.toUpperCase()}):(0,H.jsx)(`span`,{className:`font-mono text-[10px] uppercase tracking-[0.25em] ${r?`text-[var(--text-secondary)]`:`text-[var(--text-muted)]`}`,"aria-current":r?`page`:void 0,children:t.label.toUpperCase()})]},n)})})}function wD({viewModel:e}){let{state:t}=e;if(t.kind===`not_found`)return(0,H.jsx)(`div`,{className:`space-y-5 max-w-3xl`,children:(0,H.jsx)(AD,{message:``,is404:!0,onRetry:()=>void 0,onBack:t.onBack})});if(t.kind===`error`)return(0,H.jsx)(`div`,{className:`space-y-5 max-w-3xl`,children:(0,H.jsx)(AD,{message:t.message,is404:!1,onRetry:t.onRetry,onBack:t.onBack})});if(t.kind===`loading`){let{cached:e,activeTagLabel:n,onBack:r}=t;return(0,H.jsxs)(`div`,{className:`space-y-5 max-w-3xl`,children:[(0,H.jsx)(CD,{segments:n?[{label:`Workflows`,onClick:r},{label:n}]:[{label:`Workflows`,onClick:r}]}),e?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(TD,{name:e.name,description:e.description,tags:e.tags,source:e.source,stepCount:void 0}),(0,H.jsx)(`div`,{className:`space-y-4`,children:(0,H.jsx)(OD,{})})]}):(0,H.jsx)(kD,{})]})}let{workflow:n,name:r,description:i,tags:a,source:o,activeTagLabel:s,onPrev:c,onNext:l,onBack:u}=t;return(0,H.jsxs)(`div`,{className:`space-y-5 max-w-3xl`,children:[(0,H.jsx)(CD,{segments:s?[{label:`Workflows`,onClick:u},{label:s}]:[{label:`Workflows`,onClick:u}]}),(0,H.jsx)(TD,{name:r,description:i,tags:a,source:o,stepCount:n.stepCount}),(c??l)&&(0,H.jsxs)(`div`,{className:`flex items-center gap-4`,children:[c&&(0,H.jsxs)(`button`,{type:`button`,onClick:c,className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] hover:text-[var(--accent)] transition-colors`,children:[`<`,` PREV`]}),l&&(0,H.jsxs)(`button`,{type:`button`,onClick:l,className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] hover:text-[var(--accent)] transition-colors`,children:[`NEXT `,`>`]})]}),(0,H.jsx)(ED,{detail:n,name:r}),(0,H.jsx)(CD,{segments:[{label:`Workflows`,onClick:u}]})]})}function TD({name:e,description:t,tags:n,source:r,stepCount:i}){return(0,H.jsxs)(`div`,{className:`border border-[var(--border)] px-5 py-5 console-blueprint-grid`,children:[(0,H.jsx)(`p`,{className:`font-mono text-[10px] uppercase tracking-[0.35em] text-[var(--text-muted)] mb-2`,children:`// Workflow`}),(0,H.jsx)(`h2`,{className:`font-mono text-xl font-bold uppercase tracking-[0.08em] leading-tight mb-3`,style:{color:`var(--accent)`,textShadow:`0 0 24px rgba(244,196,48,0.45), 0 0 48px rgba(244,196,48,0.15)`},children:e}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i!=null&&i>0&&(0,H.jsxs)(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 border border-[var(--border)] text-[var(--text-secondary)]`,children:[i,` step`,i===1?``:`s`]}),n.filter(e=>e!==`routines`).map(e=>(0,H.jsx)(`span`,{"aria-hidden":`true`,className:`font-mono text-[10px] px-1.5 py-0.5 bg-[var(--bg-secondary)] text-[var(--text-muted)]`,children:e},e)),r&&(0,H.jsxs)(`span`,{"aria-hidden":`true`,className:`font-mono text-[10px] px-1.5 py-0.5 border border-[var(--border)] text-[var(--text-muted)]`,children:[`src: `,r.displayName]})]}),t&&(0,H.jsx)(`p`,{className:`text-sm text-[var(--text-secondary)] leading-relaxed mt-3`,children:t})]})}function ED({detail:e,name:t}){let n=e.about!==void 0&&e.about.length>0,r=e.examples!==void 0&&e.examples.length>0,i=e.preconditions!==void 0&&e.preconditions.length>0;return n||r||i?(0,H.jsxs)(`div`,{className:`space-y-6`,children:[n&&(0,H.jsxs)(`section`,{children:[(0,H.jsx)(`h3`,{className:`text-xs font-semibold text-[var(--text-muted)] uppercase tracking-wider mb-3`,children:`About`}),(0,H.jsx)(zE,{children:e.about})]}),r&&(0,H.jsxs)(`section`,{children:[(0,H.jsx)(`h3`,{className:`text-xs font-semibold text-[var(--text-muted)] uppercase tracking-wider mb-3`,children:`Try it with:`}),(0,H.jsx)(`ul`,{className:`space-y-2`,children:e.examples.map(e=>(0,H.jsxs)(`li`,{className:`flex items-start gap-3 bg-[var(--bg-card)] border border-[var(--border)] rounded-none px-4 py-3`,children:[(0,H.jsx)(`div`,{"aria-hidden":`true`,className:`w-0.5 shrink-0 self-stretch rounded-full`,style:{backgroundColor:`var(--accent)`}}),(0,H.jsxs)(`span`,{className:`text-sm text-[var(--text-secondary)] leading-relaxed`,children:[`"`,e,`"`]})]},e))})]}),i&&(0,H.jsxs)(`section`,{children:[(0,H.jsx)(`h3`,{className:`text-xs font-semibold text-[var(--text-muted)] uppercase tracking-wider mb-3`,children:`Before you start:`}),(0,H.jsx)(`ul`,{className:`space-y-1.5`,children:e.preconditions.map(e=>(0,H.jsxs)(`li`,{className:`flex items-start gap-2 text-sm text-[var(--text-secondary)]`,children:[(0,H.jsx)(`span`,{className:`shrink-0 text-[var(--text-muted)] mt-0.5`,children:`•`}),(0,H.jsx)(`span`,{children:e})]},e))})]}),(0,H.jsx)(DD,{name:t})]}):(0,H.jsx)(`p`,{className:`text-sm text-[var(--text-muted)] italic`,children:`No additional documentation available.`})}function DD({name:e}){let[t,n]=(0,V.useState)(!1),r=`Use the ${e} to [your goal]`;return(0,H.jsxs)(`section`,{children:[(0,H.jsx)(`h3`,{className:`text-xs font-semibold text-[var(--text-muted)] uppercase tracking-wider mb-3`,children:`Start with this prompt`}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3 border border-[var(--border)] px-4 py-3`,children:[(0,H.jsxs)(`span`,{className:`flex-1 text-sm text-[var(--text-secondary)] font-mono truncate`,children:[`"`,r,`"`]}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>{navigator.clipboard.writeText(r).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},className:`shrink-0 text-xs font-mono text-[var(--accent)] hover:text-[var(--text-primary)] transition-colors`,children:t?`Copied!`:`Copy`})]})]})}function OD(){return(0,H.jsxs)(`div`,{className:`space-y-3 motion-safe:animate-pulse`,children:[(0,H.jsx)(`div`,{className:`h-3 w-16 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-4 w-full rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-4 w-5/6 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-4 w-4/6 rounded bg-[var(--bg-tertiary)]`})]})}function kD(){return(0,H.jsxs)(`div`,{className:`space-y-6 motion-safe:animate-pulse`,children:[(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(`div`,{className:`h-6 w-1/2 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsx)(`div`,{className:`h-5 w-16 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-5 w-24 rounded bg-[var(--bg-tertiary)]`})]}),(0,H.jsx)(`div`,{className:`h-4 w-full rounded bg-[var(--bg-tertiary)]`})]}),(0,H.jsx)(OD,{})]})}function AD({message:e,is404:t,onRetry:n,onBack:r}){return(0,H.jsxs)(`div`,{className:`space-y-4 bg-[var(--bg-card)] border border-[var(--border)] p-4`,children:[(0,H.jsx)(`p`,{className:`text-sm text-[var(--error)]`,children:t?`Workflow not found.`:e}),(0,H.jsxs)(`div`,{className:`flex gap-3`,children:[!t&&(0,H.jsx)(`button`,{type:`button`,onClick:n,className:`text-sm text-[var(--accent)] hover:text-[var(--accent-hover)] transition-colors`,children:`Try again`}),(0,H.jsxs)(`button`,{type:`button`,onClick:r,"aria-label":`Back to workflows list`,className:`font-mono text-[10px] uppercase tracking-[0.25em] text-[var(--text-muted)] hover:text-[var(--accent)] transition-colors`,children:[`<`,` WORKFLOWS`]})]})]})}function jD(e){if(e.size<2)return 1;let t=new Set;for(let n of e.values())t.add(Math.round(n.getBoundingClientRect().top));if(t.size<2){let t=Math.round(e.get(0)?.getBoundingClientRect().top??0),n=0;for(let r of e.values())Math.round(r.getBoundingClientRect().top)===t&&n++;return Math.max(1,n)}let n=Math.round(e.get(0)?.getBoundingClientRect().top??0),r=0;for(let t of e.values())Math.round(t.getBoundingClientRect().top)===n&&r++;return Math.max(1,r)}function MD(e,t,n,r){if(n===0)return 0;let i=(e??(t>0?-1:n))+t;return r?(i%n+n)%n:Math.max(0,Math.min(n-1,i))}function ND(e,t,n,r,i){if(n===0)return 0;let a=e??0,o=a%r,s=Math.floor(a/r),c=Math.ceil(n/r),l=s+t;l=i?(l%c+c)%c:Math.max(0,Math.min(c-1,l));let u=l*r+o;return Math.min(u,n-1)}function PD({count:e,cols:t=`auto`,onActivate:n,loop:r=!0}){let[i,a]=(0,V.useState)(null),o=(0,V.useRef)(new Map),s=(0,V.useCallback)(e=>{a(e),e!==null&&o.current.get(e)?.focus()},[]),c=(0,V.useCallback)(()=>t===`auto`?jD(o.current):Math.max(1,t),[t]);return{focusedIndex:i,setFocusedIndex:s,getItemProps:(0,V.useCallback)(t=>({tabIndex:i===null?t===0?0:-1:i===t?0:-1,onFocus:()=>{a(t)},onKeyDown:i=>{let a=c(),o=null;switch(i.key){case`ArrowRight`:case`d`:case`D`:o=MD(t,1,e,r);break;case`ArrowLeft`:case`a`:case`A`:o=MD(t,-1,e,r);break;case`ArrowDown`:case`s`:case`S`:o=ND(t,1,e,a,r);break;case`ArrowUp`:case`w`:case`W`:o=ND(t,-1,e,a,r);break;case`Home`:o=0;break;case`End`:o=e-1;break;case`Enter`:case` `:i.preventDefault(),n?.(t);return;default:return}o!==null&&(i.preventDefault(),s(o))},ref:e=>{e?o.current.set(t,e):o.current.delete(t)}}),[i,e,r,c,n,s]),containerProps:{role:`grid`}}}function FD(e){let t=Zy(e),n=()=>{t.refetch()};return t.isLoading?{kind:`loading`}:t.error?t.error instanceof Hy&&t.error.status===404?{kind:`not_found`}:{kind:`error`,message:t.error instanceof Error?t.error.message:`Could not load workflow details.`,refetch:n}:t.data?{kind:`ready`,detail:t.data,refetch:n}:{kind:`loading`}}function ID(){let e=Yy();return{workflows:e.data?.workflows.filter(e=>!e.tags.includes(`routines`)),isLoading:e.isLoading,error:e.error instanceof Error?e.error:null,refetch:e.refetch}}function LD(e,t){if(!e)return{prevWorkflow:null,nextWorkflow:null};let n=t.findIndex(t=>t.id===e);return n===-1?{prevWorkflow:null,nextWorkflow:null}:{prevWorkflow:n>0?t[n-1]??null:null,nextWorkflow:n<t.length-1?t[n+1]??null:null}}function RD({workflowId:e,activeTag:t,onBack:n,onNavigateToWorkflow:r}){let i=FD(e),a=ID().workflows,o=(0,V.useRef)(null),s=(0,V.useRef)(null),c=(0,V.useRef)(r);c.current=r;let l=a??[],{prevWorkflow:u,nextWorkflow:d}=(0,V.useMemo)(()=>LD(e,l),[e,l]),f=u?()=>c.current(u.id):null,p=d?()=>c.current(d.id):null;o.current=f,s.current=p;let m=i.kind===`ready`;return(0,V.useEffect)(()=>{if(!m)return;function e(e){e.metaKey||e.ctrlKey||e.altKey||(e.key===`ArrowLeft`?(e.preventDefault(),o.current?.()):e.key===`ArrowRight`&&(e.preventDefault(),s.current?.()))}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[m]),{state:(0,V.useMemo)(()=>{let r=a?.find(t=>t.id===e)??void 0,o=t?xD[t]??t:null;if(i.kind===`not_found`)return{kind:`not_found`,onBack:n};if(i.kind===`error`)return{kind:`error`,message:i.message,onBack:n,onRetry:i.refetch};if(i.kind===`ready`){let t=i.detail;return{kind:`ready`,workflow:t,name:t.name??r?.name??e??``,description:t.description??r?.description??null,tags:t.tags??r?.tags??[],source:t.source??r?.source??null,activeTagLabel:o,adjacentWorkflows:l,onPrev:f,onNext:p,onBack:n}}return{kind:`loading`,cached:r??null,activeTagLabel:o,onBack:n}},[i,a,e,t,l,f,p,n])}}function zD(e){let t=new Set(bD.map(e=>e.id)),n=new Map,r=[];for(let i of e){let e=i.tags.find(e=>e!==`routines`&&t.has(e));if(e){let t=n.get(e)??[];t.push(i),n.set(e,t)}else r.push(i)}let i=bD.filter(e=>n.has(e.id)).map(e=>({tagId:e.id,label:e.label,workflows:n.get(e.id)}));return r.length>0&&i.push({tagId:null,label:`Other`,workflows:r}),i}function BD({viewModel:e}){let{state:t,dispatch:n,triggerRef:r,onCardSelect:i}=e,a=(0,V.useRef)(null),o=(0,V.useRef)(null),s=yD(),c=t.kind===`ready`?t.selectedWorkflowId:null;if((0,V.useEffect)(()=>{if(c){let e=requestAnimationFrame(()=>a.current?.focus());return()=>cancelAnimationFrame(e)}},[c]),t.kind===`loading`)return(0,H.jsx)(WD,{});if(t.kind===`error`)return(0,H.jsx)(GD,{message:t.message,onRetry:t.onRetry});let{selectedTag:l,selectedSource:u,hintVisible:d,filteredWorkflows:f,flatWorkflows:p,availableSources:m,sourceFilteredWorkflows:h,tagFilteredWorkflows:g}=t,_=new Set(bD.map(e=>e.id)),v=new Set(h.flatMap(e=>e.tags)),y=new Map(bD.map(e=>[e.id,h.filter(t=>t.tags.includes(e.id)).length])),b=h.filter(e=>!e.tags.some(e=>e!==`routines`&&_.has(e))).length,x=h.length,S=g.length;return(0,H.jsx)(VD,{selectedWorkflowId:c,selectedTag:l,selectedSource:u,hintVisible:d,filteredWorkflows:f,flatWorkflows:p,availableSources:m,tagsWithWorkflows:v,countByTag:y,otherCount:b,allTagCount:x,allSourceCount:S,countBySource:new Map(m.map(e=>[e.displayName,g.filter(t=>t.source.displayName===e.displayName).length])),currentIndex:p.findIndex(e=>e.id===c),dispatch:n,onCardSelect:i,triggerRef:r,modalPanelRef:a,scrollRef:o,modalTransition:s})}function VD({selectedWorkflowId:e,selectedTag:t,selectedSource:n,hintVisible:r,filteredWorkflows:i,flatWorkflows:a,availableSources:o,tagsWithWorkflows:s,countByTag:c,otherCount:l,allTagCount:u,allSourceCount:d,countBySource:f,currentIndex:p,dispatch:m,onCardSelect:h,modalPanelRef:g,scrollRef:_,modalTransition:v}){let y=RD({workflowId:e,activeTag:t,onBack:()=>m({type:`modal_closed`}),onNavigateToWorkflow:e=>m({type:`workflow_selected`,id:e})}),b=(0,V.useCallback)((t,n)=>{v.navigate(e,a,t,n,e=>{m({type:`workflow_selected`,id:e}),v.selectedWorkflowIdRef.current=e},_)},[a,e,v,m,_]);(0,V.useEffect)(()=>{if(!e)return;let t=[`ArrowLeft`,`ArrowRight`,`a`,`A`,`d`,`D`],n=[`ArrowUp`,`ArrowDown`,`w`,`W`,`s`,`S`],r=e=>{if(n.includes(e.key)){e.preventDefault(),e.stopPropagation();return}t.includes(e.key)&&(e.preventDefault(),e.stopPropagation(),b([`ArrowLeft`,`a`,`A`].includes(e.key)?`prev`:`next`,`horizontal`))};return document.addEventListener(`keydown`,r,{capture:!0}),()=>{document.removeEventListener(`keydown`,r,{capture:!0})}},[e,b]);let{getItemProps:x,containerProps:S}=PD({count:a.length,cols:`auto`,onActivate:(0,V.useCallback)(e=>{let t=a[e];if(!t)return;let n=document.activeElement;n instanceof HTMLButtonElement&&h(t.id,n)},[a,h])});return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h1`,{className:`font-mono text-2xl font-bold uppercase tracking-[0.12em] leading-none`,style:{color:`var(--accent)`,textShadow:`0 0 28px rgba(244,196,48,0.35)`},children:`Workflows`}),(0,H.jsxs)(`p`,{className:`font-mono text-[10px] tracking-[0.25em] text-[var(--text-muted)] mt-1.5`,children:[`// `,i.length,` available`]})]}),(0,H.jsxs)(`div`,{role:`group`,"aria-label":`Filter workflows by category`,className:`flex flex-wrap gap-1.5`,children:[(0,H.jsx)(HD,{label:`All`,count:u,isActive:t===null,disabled:!1,onClick:()=>m({type:`tag_changed`,tag:null})}),bD.filter(e=>s.has(e.id)).map(e=>(0,H.jsx)(HD,{label:e.label,count:c.get(e.id)??0,isActive:t===e.id,disabled:!1,onClick:()=>m({type:`tag_changed`,tag:t===e.id?null:e.id})},e.id)),l>0&&(0,H.jsx)(HD,{label:`Other`,count:l,isActive:t===`__other__`,disabled:!1,onClick:()=>m({type:`tag_changed`,tag:t===`__other__`?null:`__other__`})})]}),o.length>1&&(0,H.jsxs)(`div`,{role:`group`,"aria-label":`Filter workflows by source`,className:`flex flex-wrap gap-1.5`,children:[(0,H.jsx)(HD,{label:`All Sources`,count:d,isActive:n===null,disabled:!1,onClick:()=>m({type:`source_changed`,source:null})}),o.map(e=>(0,H.jsx)(HD,{label:e.displayName,count:f.get(e.displayName)??0,isActive:n===e.displayName,disabled:!1,onClick:()=>m({type:`source_changed`,source:n===e.displayName?null:e.displayName})},e.id))]}),i.length===0?(0,H.jsxs)(`div`,{className:`py-8 text-center space-y-3`,children:[(0,H.jsx)(`p`,{className:`text-sm text-[var(--text-muted)]`,children:`No workflows in this category.`}),t!==null&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>m({type:`tag_changed`,tag:null}),className:`text-sm text-[var(--accent)] hover:text-[var(--accent-hover)] transition-colors`,children:`Clear filter`})]}):t===null?(0,H.jsx)(`div`,{className:`space-y-6`,children:(()=>{let t=0;return zD(i).map(n=>(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(SD,{label:n.label,count:n.workflows.length,showRule:!0}),(0,H.jsx)(`div`,{...S,className:`grid grid-cols-2 lg:grid-cols-3 gap-3`,children:n.workflows.map(n=>(0,H.jsx)(UD,{workflow:n,onSelect:e=>h(n.id,e),navProps:x(t++),isActive:n.id===e},n.id))})]},n.tagId??`__other__`))})()}):(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(SD,{label:t===`__other__`?`Other`:xD[t]??t,count:i.length,showRule:!0}),(0,H.jsx)(`div`,{...S,className:`grid grid-cols-2 lg:grid-cols-3 gap-3`,children:i.map((t,n)=>(0,H.jsx)(UD,{workflow:t,onSelect:e=>h(t.id,e),navProps:x(n),isActive:t.id===e},t.id))})]}),(0,H.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-end justify-center p-4 pointer-events-none`,"aria-hidden":!e,children:[e&&(0,H.jsx)(`div`,{className:`absolute inset-0 pointer-events-auto`,style:{background:`rgba(0,0,0,0.22)`,backdropFilter:`blur(2px)`},onClick:()=>m({type:`modal_closed`})}),(0,H.jsx)(`div`,{ref:g,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":`Workflow detail${e?`: ${a.find(t=>t.id===e)?.name??``}`:``}`,className:`relative w-full max-w-3xl ${e?`pointer-events-auto`:`pointer-events-none`}${v.state.borderFlashing?` modal-border-flashing`:``}`,style:{height:`85vh`,transform:e?`translateY(0) scale(1)`:`translateY(24px) scale(0.97)`,opacity:+!!e,transition:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`opacity 150ms ease-out`:`transform 250ms ease-out, opacity 250ms ease-out`,backdropFilter:`blur(2px)`,WebkitBackdropFilter:`blur(2px)`},children:(0,H.jsxs)(co,{cut:20,borderColor:`rgba(244, 196, 48, 0.45)`,background:`rgba(15, 19, 31, 0.50)`,dropShadow:`drop-shadow(0 4px 24px rgba(244,196,48,0.15))`,className:`h-full flex flex-col`,children:[v.state.scanline!==null&&(0,H.jsx)(`div`,{className:`modal-scanline`,"aria-hidden":`true`,style:{"--crt-offset":`${v.state.scanline.crtOffset}px`,"--glitch-y":`${v.state.scanline.glitchY}%`,"--glitch-y2":`${v.state.scanline.glitchY2}%`,"--glitch-w":`${v.state.scanline.glitchW}px`,"--glitch-w2":`${v.state.scanline.glitchW2}px`,clipPath:so(20)}},v.state.scanline.key),(0,H.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-[var(--border)] shrink-0 console-blueprint-grid`,style:{background:`rgba(15, 19, 31, 0.55)`},children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[10px] uppercase tracking-[0.30em] text-[var(--text-secondary)]`,children:`Workflow`}),p>=0&&(0,H.jsxs)(`span`,{className:`font-mono text-[10px] tracking-[0.20em] text-[var(--text-secondary)]`,children:[`[ `,p+1,` / `,a.length,` ]`]}),(0,H.jsx)(`span`,{className:`font-mono text-[9px] tracking-[0.15em] text-[var(--text-secondary)] transition-opacity duration-600`,style:{opacity:r?.5:0},"aria-hidden":`true`,children:`[ A / D ] NAV`})]}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>m({type:`modal_closed`}),className:`text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors text-xl leading-none`,"aria-label":`Close`,children:`×`})]}),(0,H.jsxs)(`div`,{ref:_,className:`flex-1 overflow-auto overscroll-contain px-6 py-5 ${v.state.contentAnimClass}`,style:{"--text-muted":`var(--text-secondary)`},children:[(0,H.jsx)(`div`,{"aria-live":`polite`,"aria-atomic":`true`,className:`sr-only`,children:a.find(t=>t.id===e)?.name??``}),e&&(0,H.jsx)(wD,{viewModel:y})]})]})})]})]})}function HD({label:e,count:t,isActive:n,disabled:r,onClick:i}){return(0,H.jsxs)(`button`,{type:`button`,onClick:i,disabled:r,"aria-pressed":n,className:[`px-3 py-2 min-w-[44px] min-h-[44px] rounded-none text-xs font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--accent)] focus-visible:ring-offset-2`,`disabled:opacity-50 disabled:cursor-not-allowed`,n?`border border-[var(--accent)] text-[var(--accent)] bg-transparent`:`text-[var(--text-muted)] hover:text-[var(--text-secondary)] hover:bg-[var(--bg-card)]`].join(` `),children:[e,` · `,t,n&&(0,H.jsx)(`span`,{className:`sr-only`,children:`(selected)`})]})}function UD({workflow:e,onSelect:t,navProps:n,isActive:r}){let i=e.tags.filter(e=>e!==`routines`).map(e=>xD[e]??e);return(0,H.jsx)(W,{variant:`grid`,onClick:e=>t(e.currentTarget),"aria-label":[e.name,e.description,i.length>0?`Tag: ${i.join(`, `)}`:null,`Source: ${e.source.displayName}`].filter(Boolean).join(`. `),style:r?{borderColor:`var(--accent)`,boxShadow:`0 0 0 1px rgba(244,196,48,0.4), 0 0 16px rgba(244,196,48,0.12)`}:void 0,...n,children:(0,H.jsxs)(`div`,{className:`flex flex-col flex-1 p-4 gap-2 min-w-0`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-[var(--text-primary)] group-hover:text-[var(--accent)] transition-colors leading-snug line-clamp-2`,children:e.name}),(0,H.jsx)(`p`,{className:`text-xs text-[var(--text-secondary)] line-clamp-3 leading-relaxed flex-1`,children:e.description}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mt-auto pt-2 border-t border-[var(--border)]`,children:[(0,H.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:i.slice(0,1).map(e=>(0,H.jsx)(`span`,{className:`font-mono text-[9px] px-1.5 py-0.5 bg-[var(--bg-secondary)] text-[var(--text-muted)]`,children:e},e))}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.stepCount!=null&&e.stepCount>0&&(0,H.jsxs)(`span`,{className:`font-mono text-[9px] text-[var(--text-muted)]`,children:[e.stepCount,`s`]}),(0,H.jsxs)(`span`,{className:`font-mono text-[9px] text-[var(--text-muted)] max-w-[80px] truncate`,children:[`src: `,e.source.displayName]})]})]})]})})}function WD(){return(0,H.jsx)(`div`,{className:`space-y-6 motion-safe:animate-pulse`,children:[0,1].map(e=>(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(`div`,{className:`h-3 w-24 bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`flex-1 h-px bg-[var(--bg-tertiary)]`})]}),(0,H.jsx)(`div`,{className:`grid grid-cols-2 lg:grid-cols-3 gap-3`,children:[0,1,2,3,4,5].map(e=>(0,H.jsxs)(`div`,{className:`min-h-[160px] bg-[var(--bg-card)] border border-[var(--border)] flex flex-col`,children:[(0,H.jsx)(`div`,{className:`h-[3px] bg-[var(--bg-tertiary)]`}),(0,H.jsxs)(`div`,{className:`p-4 flex flex-col gap-2 flex-1`,children:[(0,H.jsx)(`div`,{className:`h-4 w-3/4 bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-3 w-full bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-3 w-5/6 bg-[var(--bg-tertiary)]`}),(0,H.jsxs)(`div`,{className:`mt-auto pt-2 border-t border-[var(--border)] flex justify-between`,children:[(0,H.jsx)(`div`,{className:`h-3 w-12 bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-3 w-16 bg-[var(--bg-tertiary)]`})]})]})]},e))})]},e))})}function GD({message:e,onRetry:t}){return(0,H.jsxs)(`div`,{className:`space-y-3 py-8 text-center`,children:[(0,H.jsx)(`p`,{className:`text-sm text-[var(--error)]`,children:e}),(0,H.jsx)(`button`,{type:`button`,onClick:t,className:`text-sm text-[var(--accent)] hover:text-[var(--accent-hover)] transition-colors`,children:`Try again`})]})}var KD=[{value:`recent`,label:`Recent first`,compareFn:(e,t)=>t.startedAtMs-e.startedAtMs},{value:`slowest`,label:`Slowest first`,compareFn:(e,t)=>t.durationMs-e.durationMs}],qD={success:{color:`var(--success)`,label:`OK`,isError:!1},error:{color:`var(--error)`,label:`Error`,isError:!0},unknown_tool:{color:`var(--warning)`,label:`Unknown`,isError:!0}};function JD(e,t){let n=KD.find(e=>e.value===t);return[...e].sort(n.compareFn)}function YD(e){return e.reduce((e,t)=>Math.max(e,t.durationMs),0)}function XD(e){return e.filter(e=>qD[e.outcome].isError).length}function ZD(e){return e.length===0?null:Math.round(e.reduce((e,t)=>e+t.durationMs,0)/e.length)}function QD(e){return e.length===0?null:e.reduce((e,t)=>Math.max(e,t.startedAtMs),0)}function $D(e,t){return t>0?Math.round(e/t*120):0}function eO(e){return`${e} recorded`}var tO=[{key:`tool`,label:`Tool`,minWidth:`180px`},{key:`duration`,label:`Duration`,width:`220px`},{key:`started`,label:`Started`,width:`100px`},{key:`outcome`,label:`Outcome`}];function nO({viewModel:e}){let{state:t}=e;if(t.kind===`loading`)return(0,H.jsx)(oO,{});if(t.kind===`devModeOff`)return(0,H.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,H.jsx)(`p`,{className:`text-sm text-[var(--text-muted)] text-center`,children:`nothing to see here`})});if(t.kind===`error`)return(0,H.jsxs)(`div`,{className:`space-y-3 py-8 text-center`,children:[(0,H.jsx)(`p`,{className:`text-sm text-[var(--error)]`,children:t.message}),(0,H.jsx)(`button`,{type:`button`,onClick:t.retry,className:`text-sm text-[var(--accent)] hover:text-[var(--accent-hover)] transition-colors`,children:`Try again`})]});let{sorted:n,maxDuration:r,errorCount:i,avgMs:a,lastCallMs:o,countLabel:s,sortOrder:c,onSortChange:l}=t;return(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(0,H.jsxs)(`p`,{className:`text-sm text-[var(--text-secondary)]`,children:[s,` | `,(0,H.jsxs)(`span`,{style:{color:i>0?`var(--error)`:`var(--text-muted)`},children:[i,` errors`]}),` | `,`avg `,a===null?`--`:`${a}ms`,` | `,`last call `,o===null?`no calls yet`:uo(o)]}),(0,H.jsx)(`div`,{role:`radiogroup`,"aria-label":`Sort order`,className:`flex items-center gap-1`,children:KD.map(e=>(0,H.jsx)(aO,{label:e.label,isActive:c===e.value,onClick:()=>l(e.value)},e.value))}),(0,H.jsxs)(`table`,{className:`w-full text-sm border-collapse`,children:[(0,H.jsx)(`thead`,{children:(0,H.jsx)(`tr`,{className:`text-xs text-[var(--text-muted)] border-b border-[var(--border)]`,children:tO.map(e=>(0,H.jsx)(`th`,{scope:`col`,className:`text-left py-2 pr-4 font-medium`,style:{width:e.width,minWidth:e.minWidth},children:e.label},e.key))})}),(0,H.jsx)(`tbody`,{children:n.length===0?(0,H.jsx)(`tr`,{children:(0,H.jsx)(`td`,{colSpan:tO.length,className:`py-8 text-center text-sm text-[var(--text-muted)]`,children:`No tool calls recorded yet. Run a workflow to see timing data.`})}):n.map((e,t)=>(0,H.jsx)(rO,{obs:e,maxDuration:r},`${e.startedAtMs}-${e.toolName}-${t}`))})]})]})}function rO({obs:e,maxDuration:t}){let n=qD[e.outcome].isError,r=$D(e.durationMs,t);return(0,H.jsxs)(`tr`,{className:`border-b border-[var(--border)] hover:bg-[var(--bg-card)] transition-colors`,style:{borderLeft:n?`2px solid var(--error)`:`2px solid transparent`},children:[(0,H.jsx)(`td`,{className:`py-2 pr-4 font-mono text-[var(--text-primary)] overflow-hidden text-ellipsis`,title:e.toolName,style:{minWidth:`180px`,maxWidth:`240px`},children:(0,H.jsx)(`span`,{className:`block truncate`,children:e.toolName})}),(0,H.jsxs)(`td`,{className:`py-2 pr-4`,style:{width:`220px`},children:[(0,H.jsxs)(`span`,{className:`font-mono text-[var(--text-primary)]`,children:[e.durationMs,`ms`]}),(0,H.jsx)(`div`,{"aria-hidden":`true`,className:`h-1 rounded mt-1`,style:{backgroundColor:`var(--accent)`,width:`${r}px`,maxWidth:`120px`}})]}),(0,H.jsx)(`td`,{className:`py-2 pr-4 text-[var(--text-secondary)]`,style:{width:`100px`},children:uo(e.startedAtMs)}),(0,H.jsx)(`td`,{className:`py-2`,children:(0,H.jsx)(iO,{outcome:e.outcome})})]})}function iO({outcome:e}){let t=qD[e];return(0,H.jsx)(`span`,{className:`inline-block px-2 py-0.5 rounded text-xs font-medium`,style:{color:t.color,backgroundColor:`color-mix(in srgb, ${t.color} 12%, transparent)`},children:t.label})}function aO({label:e,isActive:t,onClick:n}){return(0,H.jsx)(`button`,{type:`button`,role:`radio`,onClick:n,"aria-checked":t,className:[`px-3 py-2 rounded text-xs font-medium min-w-[44px] transition-colors`,t?`text-[var(--text-primary)]`:`text-[var(--text-muted)] hover:text-[var(--text-secondary)]`].join(` `),children:e})}function oO(){return(0,H.jsxs)(`div`,{className:`space-y-3 animate-pulse`,"aria-busy":`true`,"aria-label":`Loading performance data`,children:[(0,H.jsx)(`div`,{className:`h-4 w-64 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsxs)(`div`,{className:`flex gap-1`,children:[(0,H.jsx)(`div`,{className:`h-8 w-24 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-8 w-24 rounded bg-[var(--bg-tertiary)]`})]}),(0,H.jsxs)(`div`,{className:`flex gap-4 border-b border-[var(--border)] pb-2`,children:[(0,H.jsx)(`div`,{className:`h-3 w-20 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-3 w-16 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-3 w-14 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-3 w-14 rounded bg-[var(--bg-tertiary)]`})]}),Array.from({length:8}).map((e,t)=>(0,H.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[(0,H.jsx)(`div`,{className:`h-4 rounded bg-[var(--bg-tertiary)]`,style:{minWidth:`180px`,width:`180px`}}),(0,H.jsxs)(`div`,{className:`space-y-1`,style:{width:`220px`},children:[(0,H.jsx)(`div`,{className:`h-4 w-16 rounded bg-[var(--bg-tertiary)]`}),(0,H.jsx)(`div`,{className:`h-1 w-20 rounded bg-[var(--bg-tertiary)]`})]}),(0,H.jsx)(`div`,{className:`h-4 w-16 rounded bg-[var(--bg-tertiary)]`,style:{width:`100px`}}),(0,H.jsx)(`div`,{className:`h-5 w-12 rounded bg-[var(--bg-tertiary)]`})]},t))]})}var sO=`workrail:auto:mru-workflow`;function cO(){try{return localStorage.getItem(sO)}catch{return null}}function lO(e){try{localStorage.setItem(sO,e)}catch{}}function uO(){let e=Yy(),t=Qy(),n=e.data?.workflows??[],r=t.data?.triggers??[],[i,a]=(0,V.useState)(()=>cO()??``),[o,s]=(0,V.useState)(``),[c,l]=(0,V.useState)(``),[u,d]=(0,V.useState)(!1),[f,p]=(0,V.useState)(null),[m,h]=(0,V.useState)(!1),[g,_]=(0,V.useState)(!0),v=(0,V.useRef)(null);(0,V.useEffect)(()=>{!i&&n.length>0&&a(n[0]?.id??``)},[i,n]);let y=e=>{a(e),lO(e)},b=async()=>{if(!(!i||!c.trim()||!o.trim())){d(!0),p(null),h(!1);try{await $y({workflowId:i,goal:c.trim(),workspacePath:o.trim()}),h(!0),l(``),setTimeout(()=>v.current?.focus(),100)}catch(e){p(e instanceof Error?e.message:`Dispatch failed`)}finally{d(!1)}}},x=!!i&&!!c.trim()&&!!o.trim()&&!u;return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,H.jsx)(Go,{color:`var(--accent)`,children:`Dispatch`})}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Go,{children:`Workflow`}),e.isLoading?(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] text-xs`,children:`Loading workflows...`}):n.length===0?(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] text-xs`,children:`No workflows available`}):(0,H.jsx)(`select`,{value:i,onChange:e=>y(e.target.value),className:`w-full bg-[var(--bg-secondary)] border border-[var(--border)] rounded-md px-3 py-2 text-sm text-[var(--text-primary)] focus:outline-none focus:border-[var(--accent)] cursor-pointer`,children:n.map(e=>(0,H.jsx)(`option`,{value:e.id,children:e.name??e.id},e.id))})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Go,{children:`Workspace path`}),(0,H.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`/path/to/repo`,className:`w-full bg-[var(--bg-secondary)] border border-[var(--border)] rounded-md px-3 py-2 text-sm font-mono text-[var(--text-primary)] placeholder-[var(--text-muted)] focus:outline-none focus:border-[var(--accent)]`})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Go,{children:`Goal`}),(0,H.jsx)(`textarea`,{ref:v,value:c,onChange:e=>l(e.target.value),placeholder:`// describe the task...`,rows:4,className:`w-full bg-[var(--bg-secondary)] border border-[var(--border)] rounded-md px-3 py-2 text-sm font-mono text-[var(--text-primary)] placeholder-[var(--text-muted)] focus:outline-none focus:border-[var(--accent)] resize-y`,onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&e.key===`Enter`&&x&&(e.preventDefault(),b())}})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`button`,{onClick:()=>void b(),disabled:!x,className:`self-start disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer`,children:(0,H.jsx)(to,{label:u?`RUNNING...`:`RUN`,color:x?`var(--accent)`:void 0,pulse:u})}),m&&(0,H.jsx)(`div`,{className:`text-[var(--success)] font-mono text-[10px] uppercase tracking-[0.20em]`,children:`Dispatched -- check Queue pane`}),f&&(0,H.jsx)(`div`,{className:`text-[var(--error)] text-xs font-mono`,children:f})]}),(0,H.jsxs)(`div`,{className:`border-t border-[var(--border)] pt-4`,children:[(0,H.jsxs)(`button`,{onClick:()=>_(!g),className:`flex items-center gap-2 mb-2 cursor-pointer group`,children:[(0,H.jsx)(`span`,{className:`text-[var(--text-muted)] text-xs transition-transform duration-150`,style:{transform:g?`rotate(-90deg)`:`rotate(0deg)`},children:`▼`}),(0,H.jsx)(to,{label:`TRIGGERS`,color:`var(--text-secondary)`}),r.length>0&&(0,H.jsxs)(`span`,{className:`text-xs text-[var(--text-muted)]`,children:[`(`,r.length,`)`]})]}),!g&&(0,H.jsx)(`div`,{className:`space-y-2`,children:t.isLoading?(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] text-xs pl-4`,children:`Loading triggers...`}):r.length===0?(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] text-xs pl-4`,children:`No triggers configured. Set WORKRAIL_TRIGGERS_ENABLED=true and create triggers.yml.`}):r.map(e=>(0,H.jsxs)(`div`,{className:`pl-4 border-l-2 border-[var(--border)] text-xs space-y-0.5`,children:[(0,H.jsx)(`div`,{className:`font-mono text-[var(--text-primary)] text-[11px]`,children:e.id}),(0,H.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:e.workflowId}),(0,H.jsx)(`div`,{className:`text-[var(--text-muted)] truncate`,children:e.goal})]},e.id))})]})]})}function dO(e){let t=0,n=0,r=0;for(let i of e)i.status===`in_progress`?t++:i.status===`blocked`?n++:(i.status===`complete`||i.status===`complete_with_gaps`)&&r++;return{running:t,blocked:n,completed:r}}function fO(){let{data:e,isLoading:t,isError:n}=Wy(),r=(e?.sessions??[]).filter(e=>e.isAutonomous),{running:i,blocked:a,completed:o}=dO(r);return t?(0,H.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,H.jsx)(`div`,{className:`text-[var(--text-secondary)] text-sm`,children:`Loading sessions...`})}):n?(0,H.jsx)(`div`,{className:`text-[var(--error)] bg-[var(--bg-card)] rounded-lg p-4 text-sm`,children:`Failed to load sessions`}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,H.jsx)(Go,{color:`var(--accent)`,children:`Queue`})}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,H.jsx)(pO,{count:i,label:`RUNNING`,color:`var(--accent)`,pulse:!0}),(0,H.jsx)(pO,{count:a,label:`BLOCKED`,color:`var(--blocked)`}),(0,H.jsx)(pO,{count:o,label:`COMPLETED`,color:`var(--success)`})]}),r.length===0?(0,H.jsxs)(`div`,{className:`text-center py-16`,children:[(0,H.jsx)(`p`,{className:`text-[var(--text-secondary)] text-sm`,children:`No autonomous sessions yet`}),(0,H.jsx)(`p`,{className:`text-[var(--text-muted)] text-xs mt-1`,children:`Dispatch a workflow from the left pane to start.`})]}):(0,H.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,H.jsx)(mO,{session:e},e.sessionId))})]})}function pO({count:e,label:t,color:n,pulse:r}){return(0,H.jsx)(to,{label:`${e} ${t}`,color:e>0?n:`var(--text-muted)`,pulse:r&&e>0})}function mO({session:e}){let[t,n]=(0,V.useState)(!1),r=Ci(),i=e.sessionTitle??e.workflowName??e.workflowId??`Unnamed session`,a=uo(e.lastModifiedMs);return(0,H.jsxs)(`div`,{className:`bg-[var(--bg-card)] border border-[var(--border)] rounded-lg overflow-hidden`,children:[(0,H.jsxs)(`button`,{onClick:()=>n(!t),className:`w-full px-4 py-3 flex items-center gap-3 text-left cursor-pointer hover:bg-[var(--bg-secondary)] transition-colors group`,children:[(0,H.jsx)(`span`,{className:`text-[var(--text-muted)] text-xs transition-transform duration-150 shrink-0`,style:{transform:t?`rotate(90deg)`:`rotate(0deg)`},children:`▶`}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-[var(--text-primary)] truncate group-hover:text-[var(--accent)] transition-colors`,children:i}),(0,H.jsx)(`div`,{className:`font-mono text-[10px] text-[var(--text-muted)] opacity-60 truncate`,children:e.sessionId})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,H.jsx)(`span`,{className:`text-[10px] text-[var(--text-muted)] tabular-nums`,children:a}),e.isLive&&(0,H.jsx)(to,{label:`LIVE`,pulse:!0,color:`var(--accent)`,"aria-label":`Actively running`}),(0,H.jsx)(ro,{status:e.status})]})]}),t&&(0,H.jsxs)(`div`,{className:`px-4 pb-4 border-t border-[var(--border)] pt-3 space-y-3`,children:[e.recapSnippet?(0,H.jsx)(`div`,{className:`text-xs text-[var(--text-secondary)] font-mono whitespace-pre-wrap leading-relaxed`,children:e.recapSnippet}):(0,H.jsx)(`div`,{className:`text-xs text-[var(--text-muted)]`,children:`No recap available yet.`}),(0,H.jsx)(`button`,{onClick:()=>void r({to:`/session/$sessionId`,params:{sessionId:e.sessionId}}),className:`cursor-pointer`,children:(0,H.jsx)(to,{label:`OPEN IN DAG`,color:`var(--accent)`})})]})]})}function hO(){return(0,H.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-6`,children:[(0,H.jsx)(`div`,{className:`w-full md:w-2/5 shrink-0`,children:(0,H.jsx)(uO,{})}),(0,H.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,H.jsx)(fO,{})})]})}function gO(){let e=Wy(),t=Jy();eb();let n=e.data?.sessions;return{sessions:n,worktreeRepos:t.data?.repos??[],isLoading:e.isLoading,error:e.error instanceof Error?e.error:null,refetch:e.refetch,worktreesFetching:t.isFetching,liveCount:n?.filter(e=>e.status===`in_progress`).length??0,blockedCount:n?.filter(e=>e.status===`blocked`).length??0}}var _O={scope:`active`,focusedIndex:-1,archive:null};function vO(e){throw Error(`Unhandled WorkspaceEvent type: ${String(e.type)}`)}function yO(e,t){switch(t.type){case`scope_changed`:return{...e,scope:t.scope,focusedIndex:-1};case`focus_moved`:return{...e,focusedIndex:t.index};case`archive_opened`:return{...e,archive:{repoName:t.repoName}};case`archive_closed`:return{...e,archive:null};default:return vO(t)}}var bO=720*60*60*1e3,xO={in_progress:0,dormant:0,blocked:1,complete_with_gaps:2,complete:3};function SO(e){if(e.length!==0)return[...e].sort((e,t)=>{let n=xO[e.status]-xO[t.status];return n===0?t.lastModifiedMs-e.lastModifiedMs:n})[0]}function CO(e,t,n){let r=e.primarySession?.status;if(r===`in_progress`||r===`blocked`)return`visible`;let i=(e.worktree?.changedCount??0)>0,a=(e.worktree?.aheadCount??0)>0;return i||a?`visible`:r===`dormant`?t===`all`?`visible`:`hidden`:n-e.activityMs<bO||t===`all`?`visible`:`hidden`}function wO(e){switch(e.primarySession?.status){case`in_progress`:return 0;case`blocked`:return 1;case`dormant`:return 2;default:return(e.worktree?.changedCount??0)>0||(e.worktree?.aheadCount??0)>0?3:4}}function TO(e,t,n){return[...e].filter(e=>CO(e,t,n)===`visible`).sort((e,t)=>{let n=wO(e)-wO(t);return n===0?t.activityMs-e.activityMs:n})}function EO(e,t){let n=new Map;for(let e of t)for(let t of e.worktrees)t.branch!==null&&n.set(`${t.branch}\0${e.repoRoot}`,{wt:t,repoName:e.repoName,repoRoot:e.repoRoot});let r=new Map;for(let[e,t]of n){let[n]=e.split(`\0`),i=r.get(n)??[];i.push(t),r.set(n,i)}let i=new Map;for(let t of e){if(t.gitBranch===null)continue;let e=r.get(t.gitBranch)??[];if(e.length===0){if(!t.repoRoot)continue;let e=`${t.gitBranch}\0${t.repoRoot}`,r=i.get(e);if(r?r.push(t):i.set(e,[t]),!n.has(e)){let r=t.repoRoot.split(`/`).at(-1)??t.repoRoot;n.set(e,{wt:void 0,repoName:r,repoRoot:t.repoRoot})}continue}let a=e;if(t.repoRoot!==null){let n=e.filter(e=>e.repoRoot===t.repoRoot);n.length>0&&(a=n)}for(let e of a){let n=`${t.gitBranch}\0${e.repoRoot}`,r=i.get(n);r?r.push(t):i.set(n,[t])}}let a=[],o=new Set;for(let[e,t]of i){let[r,i]=e.split(`\0`),s=n.get(e),c=SO(t),l=Math.max(c?.lastModifiedMs??0,s?.wt?.headTimestampMs??0),u=s?.repoName??i.split(`/`).at(-1)??i;a.push({branch:r,repoRoot:i,repoName:u,worktree:s?.wt,primarySession:c,allSessions:t,activityMs:l}),o.add(e)}for(let[e,{wt:t,repoName:r,repoRoot:i}]of n){if(o.has(e))continue;let[n]=e.split(`\0`);a.push({branch:n,repoRoot:i,repoName:r,worktree:t,primarySession:void 0,allSessions:[],activityMs:t?.headTimestampMs??0})}return a}function DO(e,t,n,r){let i=EO(e,t),a=new Map;for(let e of i)a.has(e.repoRoot)||a.set(e.repoRoot,e.repoName);let o=new Map;for(let e of i){let t=o.get(e.repoRoot)??[];t.push(e),o.set(e.repoRoot,t)}let s=[...o.entries()].map(([e,t])=>({repoRoot:e,repoName:t[0].repoName,sortedItems:TO(t,n,r)})).filter(e=>e.sortedItems.length>0).sort((e,t)=>{let n=+!e.sortedItems.some(e=>e.primarySession?.status===`in_progress`||e.primarySession?.status===`blocked`),r=+!t.sortedItems.some(e=>e.primarySession?.status===`in_progress`||e.primarySession?.status===`blocked`);return n===r?e.repoName.localeCompare(t.repoName):n-r}),c=s.flatMap(e=>e.sortedItems),l=n===`active`?i.filter(e=>e.primarySession?.status===`dormant`&&(e.worktree?.changedCount??0)===0&&(e.worktree?.aheadCount??0)===0).length:0;return{repoGroups:s,orderedItems:c,archiveRepos:[...a.entries()].map(([e,t])=>[e,t]),dormantHiddenCount:l}}function OO({items:e,focusedIndex:t,scope:n,archive:r,dispatch:i,onSelectSession:a,onRefetch:o,disabled:s}){let c=(0,V.useRef)(e);c.current=e;let l=(0,V.useRef)(t);l.current=t;let u=(0,V.useRef)(n);u.current=n;let d=(0,V.useRef)(r);d.current=r;let f=(0,V.useRef)(s);f.current=s;let p=(0,V.useRef)(i);p.current=i;let m=(0,V.useRef)(a);m.current=a;let h=(0,V.useRef)(o);h.current=o,(0,V.useEffect)(()=>{function e(e){if(f.current||e.metaKey||e.ctrlKey||e.altKey)return;let t=document.activeElement;if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)return;let n=c.current,r=l.current;switch(e.key){case`j`:case`ArrowDown`:e.preventDefault(),p.current({type:`focus_moved`,index:Math.min(r+1,n.length-1)});break;case`k`:case`ArrowUp`:e.preventDefault(),p.current({type:`focus_moved`,index:Math.max(r-1,0)});break;case`Enter`:case` `:if(e.preventDefault(),r>=0&&r<n.length){let e=n[r]?.primarySession?.sessionId;e&&m.current(e)}break;case`Escape`:d.current!==null&&p.current({type:`archive_closed`});break;case`/`:e.preventDefault(),p.current({type:`archive_opened`,repoName:void 0});break;case`r`:e.preventDefault(),h.current();break;case`a`:e.preventDefault(),p.current({type:`scope_changed`,scope:u.current===`active`?`all`:`active`});break}}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[])}function kO(e=!1){let t=Ci(),n=gO(),[r,i]=(0,V.useReducer)(yO,_O),a=(0,V.useRef)(0),o=(0,V.useCallback)(e=>{a.current=window.scrollY,t({to:`/session/$sessionId`,params:{sessionId:e}})},[t]),s=i,c=(0,V.useMemo)(()=>n.sessions?DO(n.sessions,n.worktreeRepos,r.scope,Date.now()):null,[n.sessions,n.worktreeRepos,r.scope]);OO({items:c?.orderedItems??[],focusedIndex:r.focusedIndex,scope:r.scope,archive:r.archive,dispatch:s,onSelectSession:o,onRefetch:n.refetch,disabled:e});let{isLoading:l,error:u,worktreesFetching:d,sessions:f,liveCount:p,blockedCount:m}=n;return{state:(0,V.useMemo)(()=>l?{kind:`loading`}:u?{kind:`error`,message:u.message}:c?{kind:`ready`,scope:r.scope,focusedIndex:r.focusedIndex,archive:r.archive,repoGroups:c.repoGroups,orderedItems:c.orderedItems,archiveRepos:c.archiveRepos,dormantHiddenCount:c.dormantHiddenCount,worktreesFetching:d,hasAnySessions:(f?.length??0)>0,liveCount:p,blockedCount:m}:{kind:`loading`},[l,u,d,f,c,r,p,m]),dispatch:s,scrollYRef:a,onSelectSession:o}}function AO(){let e=Wy();return{sessions:e.data?.sessions,isLoading:e.isLoading,error:e.error instanceof Error?e.error:null}}function jO(e=``){return{rawSearch:e,sort:`recent`,groupBy:`none`,statusFilter:`all`,page:0,viewMode:`flat`}}function MO(e){throw Error(`Unhandled SessionListEvent type: ${String(e.type)}`)}function NO(e,t){switch(t.type){case`search_changed`:return{...e,rawSearch:t.value,page:0};case`sort_changed`:return{...e,sort:t.sort,page:0};case`group_changed`:return{...e,groupBy:t.groupBy,page:0};case`status_changed`:return{...e,statusFilter:t.statusFilter,page:0};case`page_changed`:return{...e,page:t.page};case`view_mode_changed`:return t.viewMode===`tree`?{...e,viewMode:`tree`,rawSearch:``,statusFilter:`all`,page:0}:{...e,viewMode:`flat`,page:0};default:return MO(t)}}var PO={in_progress:0,blocked:1,dormant:2,complete_with_gaps:3,complete:4},FO=[{value:`recent`,label:`Recent`,compareFn:(e,t)=>t.lastModifiedMs-e.lastModifiedMs},{value:`status`,label:`Status`,compareFn:(e,t)=>PO[e.status]-PO[t.status]||t.lastModifiedMs-e.lastModifiedMs},{value:`workflow`,label:`Workflow`,compareFn:(e,t)=>(e.workflowName??e.workflowId??``).localeCompare(t.workflowName??t.workflowId??``)||t.lastModifiedMs-e.lastModifiedMs},{value:`nodes`,label:`Node count`,compareFn:(e,t)=>t.nodeCount-e.nodeCount||t.lastModifiedMs-e.lastModifiedMs}],IO=[{value:`none`,label:`No grouping`,keyFn:null},{value:`workflow`,label:`Workflow`,keyFn:e=>e.workflowName??e.workflowId??`Unknown workflow`},{value:`status`,label:`Status`,keyFn:e=>e.status,groupCompareFn:(e,t)=>(PO[e]??99)-(PO[t]??99)},{value:`branch`,label:`Branch`,keyFn:e=>e.gitBranch??`No branch`}],LO=[{value:`all`,label:`All`},{value:`in_progress`,label:`In Progress`},{value:`dormant`,label:`Dormant`},{value:`complete`,label:`Complete`},{value:`complete_with_gaps`,label:`Gaps`},{value:`blocked`,label:`Blocked`}];function RO(e,t,n){let r=e;if(n!==`all`&&(r=r.filter(e=>e.status===n)),t.trim()){let e=t.toLowerCase();r=r.filter(t=>(t.sessionTitle??``).toLowerCase().includes(e)||(t.workflowName??``).toLowerCase().includes(e)||(t.workflowId??``).toLowerCase().includes(e)||t.sessionId.toLowerCase().includes(e)||(t.gitBranch??``).toLowerCase().includes(e))}return r}function zO(e,t){let n=FO.find(e=>e.value===t)??FO[0];return[...e].sort(n.compareFn)}function BO(e,t){let n=IO.find(e=>e.value===t)??IO[0];if(!n.keyFn)return[{label:``,sessions:e}];let r=new Map;for(let t of e){let e=n.keyFn(t),i=r.get(e)??[];i.push(t),r.set(e,i)}let i=n.groupCompareFn??((e,t)=>e.localeCompare(t));return Array.from(r.entries()).sort(([e],[t])=>i(e,t)).map(([e,t])=>({label:e,sessions:t}))}function VO(e){let t={all:e.length};for(let n of e)t[n.status]=(t[n.status]??0)+1;return t}function HO(e){let t=new Set(e.map(e=>e.sessionId)),n=new Map,r=new Set,i=new Set;for(let a of e){let e=a.parentSessionId;if(!e||e===a.sessionId)continue;if(!t.has(e)){r.add(a.sessionId);continue}i.add(a.sessionId);let o=n.get(e)??[];o.push(a),n.set(e,o)}let a=[];for(let t of e)i.has(t.sessionId)||a.push({session:t,children:n.get(t.sessionId)??[]});return{roots:a,orphanChildIds:r}}function UO(e,t){let[n,r]=(0,V.useState)(e),i=(0,V.useRef)(null);return(0,V.useEffect)(()=>(i.current!==null&&clearTimeout(i.current),i.current=setTimeout(()=>r(e),t),()=>{i.current!==null&&clearTimeout(i.current)}),[e,t]),n}function WO({onSelectSession:e,initialSearch:t=``}){let n=AO(),[r,i]=(0,V.useReducer)(NO,void 0,()=>jO(t)),a=UO(r.rawSearch,200),o=(0,V.useRef)([]),s=(0,V.useCallback)(t=>{let n=o.current[t];n&&e(n.sessionId)},[e]),{sessions:c,isLoading:l,error:u}=n,d=(0,V.useMemo)(()=>c?VO(c):{},[c]),f=(0,V.useMemo)(()=>{if(!c)return null;let e=RO(c,a,r.statusFilter);return{groups:BO(zO(e,r.sort),r.groupBy),total:c.length,filtered:e.length}},[c,a,r.statusFilter,r.sort,r.groupBy]),p=(0,V.useMemo)(()=>HO(c||[]),[c]),m=r.groupBy!==`none`,h=f?Math.ceil(f.filtered/25):0,g=r.page*25,_=g+25,v=(0,V.useMemo)(()=>!f||m?[]:f.groups[0]?.sessions.slice(g,_)??[],[f,m,g,_]);o.current=v;let{getItemProps:y,containerProps:b}=PD({count:v.length,cols:1,onActivate:s});return{state:(0,V.useMemo)(()=>l?{kind:`loading`}:u?{kind:`error`,message:u.message}:f?{kind:`ready`,rawSearch:r.rawSearch,sort:r.sort,groupBy:r.groupBy,statusFilter:r.statusFilter,page:r.page,totalPages:h,isGrouped:m,processed:f,statusCounts:d,flatPageSessions:v,getSessionNavProps:y,sessionContainerProps:b,sortAxes:FO,groupAxes:IO,statusFilterOptions:LO,viewMode:r.viewMode,sessionTree:p}:{kind:`loading`},[l,u,f,r,h,m,d,v,y,b,p]),dispatch:i,onSelectSession:e}}var GO={selectedWorkflowId:null,selectedTag:null,selectedSource:null,hintVisible:!1};function KO(e){throw Error(`Unhandled WorkflowsEvent type: ${String(e.type)}`)}function qO(e,t){switch(t.type){case`workflow_selected`:return{...e,selectedWorkflowId:t.id,hintVisible:t.id!==null};case`tag_changed`:return{...e,selectedTag:t.tag,selectedWorkflowId:null,hintVisible:!1};case`source_changed`:return{...e,selectedSource:t.source,selectedWorkflowId:null,hintVisible:!1};case`modal_closed`:return{...e,selectedWorkflowId:null,hintVisible:!1};case`hint_dismissed`:return{...e,hintVisible:!1};default:return KO(t)}}function JO(e){let t=new Set;for(let n of e)for(let e of n.tags)e!==`routines`&&t.add(e);let n=bD.map(e=>e.id).filter(e=>t.has(e)),r=[...t].filter(e=>!bD.some(t=>t.id===e)).sort();return[...n,...r]}function YO(e){let t=new Map;for(let n of e)t.has(n.source.kind)||t.set(n.source.kind,{id:n.source.kind,displayName:n.source.displayName});return[...t.values()]}function XO(e,t,n){let r=new Set(bD.map(e=>e.id)),i=e;return t!==null&&(i=t===`__other__`?i.filter(e=>!e.tags.some(e=>e!==`routines`&&r.has(e))):i.filter(e=>e.tags.includes(t))),n!==null&&(i=i.filter(e=>e.source.displayName===n)),i}function ZO(e,t){if(t!==null)return e;let n=new Set(bD.map(e=>e.id)),r=new Map,i=[];for(let t of e){let e=t.tags.find(e=>e!==`routines`&&n.has(e));if(e){let n=r.get(e)??[];n.push(t),r.set(e,n)}else i.push(t)}let a=[];for(let{id:e}of bD){let t=r.get(e);t&&a.push(...t)}return a.push(...i),a}function QO({initialTag:e,onSelectTag:t}){let n=ID(),[r,i]=(0,V.useReducer)(qO,{...GO,selectedTag:e});(0,V.useEffect)(()=>{e!==r.selectedTag&&i({type:`tag_changed`,tag:e})},[e]);let a=(0,V.useRef)(null),o=(0,V.useCallback)((e,t)=>{a.current=t,t.blur(),i({type:`workflow_selected`,id:e})},[]);(0,V.useEffect)(()=>{if(!r.selectedWorkflowId&&a.current){let e=a.current;a.current=null,e.focus()}},[r.selectedWorkflowId]),(0,V.useEffect)(()=>{if(!r.selectedWorkflowId)return;let e=window.scrollY;return document.body.style.overflow=`hidden`,document.body.style.position=`fixed`,document.body.style.top=`-${e}px`,document.body.style.width=`100%`,()=>{document.body.style.overflow=``,document.body.style.position=``,document.body.style.top=``,document.body.style.width=``,window.scrollTo(0,e)}},[r.selectedWorkflowId]),(0,V.useEffect)(()=>{if(!r.selectedWorkflowId)return;let e=e=>{e.key===`Escape`&&i({type:`modal_closed`})};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[r.selectedWorkflowId]);let{isLoading:s,error:c,workflows:l}=n,u=(0,V.useMemo)(()=>{if(s)return{kind:`loading`};if(c)return{kind:`error`,message:c.message,onRetry:n.refetch};if(!l)return{kind:`loading`};let e=JO(l),t=YO(l),i=XO(l,r.selectedTag,r.selectedSource),a=ZO(i,r.selectedTag),o=XO(l,null,r.selectedSource),u=XO(l,r.selectedTag,null);return{kind:`ready`,selectedWorkflowId:r.selectedWorkflowId,selectedTag:r.selectedTag,selectedSource:r.selectedSource,hintVisible:r.hintVisible,availableTags:e,availableSources:t,filteredWorkflows:i,flatWorkflows:a,sourceFilteredWorkflows:o,tagFilteredWorkflows:u}},[s,c,l,r,n.refetch]),d=u.kind===`ready`?u.flatWorkflows.length:0;return(0,V.useEffect)(()=>{if(!r.selectedWorkflowId||d<=1)return;let e=setTimeout(()=>i({type:`hint_dismissed`}),3e3);return()=>clearTimeout(e)},[r.selectedWorkflowId,d]),{state:u,dispatch:(0,V.useCallback)(e=>{e.type===`tag_changed`&&t(e.tag),i(e)},[t]),triggerRef:a,onCardSelect:o}}function $O(){let e=Xy();switch(e.state){case`loading`:return{kind:`loading`};case`devModeOff`:return{kind:`devModeOff`};case`error`:return{kind:`error`,message:e.message,retry:e.retry};case`data`:return{kind:`ready`,observations:e.data.observations}}}function ek(){let e=$O(),[t,n]=(0,V.useState)(`recent`);return{state:(0,V.useMemo)(()=>{if(e.kind===`loading`)return{kind:`loading`};if(e.kind===`devModeOff`)return{kind:`devModeOff`};if(e.kind===`error`)return{kind:`error`,message:e.message,retry:e.retry};let{observations:r}=e,i=JD(r,t);return{kind:`ready`,sorted:i,maxDuration:YD(i),errorCount:XD(r),avgMs:ZD(r),lastCallMs:QD(r),countLabel:eO(r.length),sortOrder:t,onSortChange:n}},[e,t])}}function tk(e){let t=Gy(e);return{data:t.data,isLoading:t.isLoading,error:t.error instanceof Error?t.error:null}}function nk(e){let t=tk(e),[n,r]=(0,V.useState)(null),i=(0,V.useCallback)((e,t)=>{r(n=>n?.runId===e&&n?.nodeId===t?null:{runId:e,nodeId:t})},[]),a=(0,V.useCallback)(()=>{r(null)},[]),{isLoading:o,error:s,data:c}=t,l=(0,V.useMemo)(()=>!c||!n?null:c.runs.find(e=>e.runId===n.runId)??null,[c,n]);return{state:(0,V.useMemo)(()=>o?{kind:`loading`}:s?{kind:`error`,message:s.message}:c?{kind:`ready`,sessionId:e,data:c,selectedNode:n,selectedRun:l}:{kind:`loading`},[o,s,c,e,n,l]),onSelectNode:i,onCloseNode:a}}var rk=[{id:`workspace`,path:`/`},{id:`workflows`,path:`/workflows`},{id:`auto`,path:`/auto`},{id:`perf`,path:`/perf`}];function ik(){let e=Ci(),t=ea(),{location:n}=oa(),r=t({to:`/session/$sessionId`}),i=t({to:`/workflows`}),a=t({to:`/workflows/$workflowId`}),o=t({to:`/perf`}),s=t({to:`/auto`}),c=i!==!1||a!==!1?`workflows`:o===!1?s===!1?`workspace`:`auto`:`perf`,l=r!==!1,u=a!==!1,d=l?r.sessionId:null,f=u?a.workflowId:null,p=new URLSearchParams(n.search).get(`tag`),m=kO(l),h=WO({onSelectSession:m.onSelectSession}),g=m.state.kind===`ready`?m.state.liveCount:0,_=m.state.kind===`ready`?m.state.blockedCount:0,v=(0,V.useCallback)(()=>{e({to:`/`})},[e]),y=(0,V.useCallback)(t=>{e({to:`/workflows`,search:{tag:t??void 0}})},[e]),b=(0,V.useCallback)(()=>{e({to:`/workflows`,search:{tag:p??void 0}})},[e,p]),x=(0,V.useCallback)(t=>{e({to:`/workflows/$workflowId`,params:{workflowId:t},search:{tag:p??void 0}})},[e,p]),S=QO({initialTag:p,onSelectTag:y}),C=RD({workflowId:f,activeTag:p,onBack:b,onNavigateToWorkflow:x}),w=nk(d??``),T=ek(),[E,D]=(0,V.useState)(null),O=(0,V.useCallback)((e,t)=>{t(),D(e),setTimeout(()=>D(null),200)},[]),k=(0,V.useRef)(null);return(0,V.useEffect)(()=>{let t=k.current;if(!t)return;function n(t){if(t.key===`ArrowLeft`||t.key===`ArrowRight`){t.preventDefault();let n=rk.findIndex(e=>e.id===c),r=rk[t.key===`ArrowRight`?(n+1)%rk.length:(n-1+rk.length)%rk.length];e({to:r.path,...r.path===`/workflows`?{search:{tag:void 0}}:{}})}}return t.addEventListener(`keydown`,n),()=>t.removeEventListener(`keydown`,n)},[c,e]),(0,H.jsxs)(`div`,{className:`min-h-screen`,style:{"--app-header-height":`56px`},children:[(0,H.jsxs)(`header`,{style:{background:`rgba(23, 27, 40, 0.92)`,backdropFilter:`blur(24px)`,WebkitBackdropFilter:`blur(24px)`,borderBottom:`1px solid rgba(244, 196, 48, 0.25)`,boxShadow:`0 4px 24px rgba(0,0,0,0.4)`},className:`fixed top-0 w-full z-50 flex items-center h-14 px-4 gap-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,H.jsx)(co,{cut:8,borderColor:`rgba(244, 196, 48, 0.5)`,background:`rgba(27, 31, 44, 0.8)`,className:`relative w-10 h-10`,children:(0,H.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,H.jsx)(`span`,{className:`font-mono text-[11px] font-bold text-[var(--accent)] tracking-widest`,children:`WR`})})}),(0,H.jsxs)(`div`,{className:`hidden sm:flex flex-col leading-none`,children:[(0,H.jsx)(`span`,{className:`font-mono text-[11px] font-bold text-[var(--text-primary)] tracking-[0.25em] uppercase`,children:`WR_CONSOLE`}),(0,H.jsxs)(`span`,{className:`font-mono text-[9px] text-[var(--text-muted)] tracking-[0.15em]`,children:[`// V`,`3.74.0`]})]})]}),l&&d?(0,H.jsx)(`nav`,{className:`flex items-center flex-1 justify-center`,children:(0,H.jsx)(CD,{segments:[{label:`Workspace`,onClick:v},{label:d?.slice(-12)??``}]})}):(0,H.jsxs)(`div`,{role:`tablist`,"aria-label":`Console sections`,ref:k,className:`flex items-center gap-1 flex-1 justify-center`,children:[(0,H.jsxs)(`button`,{role:`tab`,id:`tab-workspace`,"aria-selected":c===`workspace`,"aria-controls":`panel-workspace`,tabIndex:c===`workspace`?0:-1,onClick:()=>O(`workspace`,()=>void e({to:`/`})),className:[`tab-btn px-4 py-2.5 font-mono text-[10px] uppercase tracking-[0.30em] transition-colors duration-150`,`focus-visible:ring-2 focus-visible:ring-[var(--accent)] focus-visible:ring-offset-1 focus-visible:outline-none`,c===`workspace`?`tab-btn--active text-[var(--accent)] text-glow-amber`:`text-[var(--text-secondary)] hover:text-[var(--text-primary)]`,E===`workspace`?`tab-activating`:``].join(` `),style:c===`workspace`?{backgroundColor:`rgba(244, 196, 48, 0.06)`}:void 0,children:[(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tr`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--bl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--br`,"aria-hidden":`true`}),`Workspace`]}),(0,H.jsxs)(`button`,{role:`tab`,id:`tab-workflows`,"aria-selected":c===`workflows`,"aria-controls":`panel-workflows`,tabIndex:c===`workflows`?0:-1,onClick:()=>O(`workflows`,()=>void e({to:`/workflows`,search:{tag:void 0}})),className:[`tab-btn px-4 py-2.5 font-mono text-[10px] uppercase tracking-[0.30em] transition-colors duration-150`,`focus-visible:ring-2 focus-visible:ring-[var(--accent)] focus-visible:ring-offset-1 focus-visible:outline-none`,c===`workflows`?`tab-btn--active text-[var(--accent)] text-glow-amber`:`text-[var(--text-secondary)] hover:text-[var(--text-primary)]`,E===`workflows`?`tab-activating`:``].join(` `),style:c===`workflows`?{backgroundColor:`rgba(244, 196, 48, 0.06)`}:void 0,children:[(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tr`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--bl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--br`,"aria-hidden":`true`}),`Workflows`]}),(0,H.jsxs)(`button`,{role:`tab`,id:`tab-auto`,"aria-selected":c===`auto`,"aria-controls":`panel-auto`,tabIndex:c===`auto`?0:-1,onClick:()=>O(`auto`,()=>void e({to:`/auto`})),className:[`tab-btn px-4 py-2.5 font-mono text-[10px] uppercase tracking-[0.30em] transition-colors duration-150`,`focus-visible:ring-2 focus-visible:ring-[var(--accent)] focus-visible:ring-offset-1 focus-visible:outline-none`,c===`auto`?`tab-btn--active text-[var(--accent)] text-glow-amber`:`text-[var(--text-secondary)] hover:text-[var(--text-primary)]`,E===`auto`?`tab-activating`:``].join(` `),style:c===`auto`?{backgroundColor:`rgba(244, 196, 48, 0.06)`}:void 0,children:[(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tr`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--bl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--br`,"aria-hidden":`true`}),`Auto`]}),(0,H.jsxs)(`button`,{role:`tab`,id:`tab-perf`,"aria-selected":c===`perf`,"aria-controls":`panel-perf`,tabIndex:c===`perf`?0:-1,onClick:()=>O(`perf`,()=>void e({to:`/perf`})),className:[`tab-btn px-4 py-2.5 font-mono text-[10px] uppercase tracking-[0.30em] transition-colors duration-150`,`focus-visible:ring-2 focus-visible:ring-[var(--accent)] focus-visible:ring-offset-1 focus-visible:outline-none`,c===`perf`?`tab-btn--active text-[var(--accent)] text-glow-amber`:`text-[var(--text-secondary)] hover:text-[var(--text-primary)]`,E===`perf`?`tab-activating`:``].join(` `),style:c===`perf`?{backgroundColor:`rgba(244, 196, 48, 0.06)`}:void 0,children:[(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--tr`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--bl`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`tab-corner tab-corner--br`,"aria-hidden":`true`}),`Performance`]})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[g>0&&(0,H.jsx)(to,{label:`${Math.min(g,9)}${g>9?`+`:``} LIVE`,color:`var(--accent-strong)`,pulse:!0,role:`status`,"aria-label":`${g} live session${g===1?``:`s`}`}),_>0&&(0,H.jsx)(to,{label:`${Math.min(_,9)}${_>9?`+`:``} BLOCKED`,color:`var(--blocked)`,role:`status`,"aria-label":`${_} blocked session${_===1?``:`s`}`})]})]}),(0,H.jsxs)(`main`,{className:`p-6`,style:{paddingTop:`calc(56px + 1.5rem)`},children:[(0,H.jsxs)(`div`,{id:`panel-workspace`,role:`tabpanel`,"aria-labelledby":`tab-workspace`,hidden:c===`workflows`||c===`perf`||c===`auto`,children:[(0,H.jsx)(Eo,{viewModel:m,sessionListViewModel:h,hidden:l}),l&&d&&(0,H.jsx)(_D,{viewModel:w})]}),c===`workflows`&&(0,H.jsx)(`div`,{id:`panel-workflows`,role:`tabpanel`,"aria-labelledby":`tab-workflows`,children:u&&f?(0,H.jsx)(wD,{viewModel:C}):(0,H.jsx)(BD,{viewModel:S})}),c===`auto`&&(0,H.jsx)(`div`,{id:`panel-auto`,role:`tabpanel`,"aria-labelledby":`tab-auto`,children:(0,H.jsx)(hO,{})}),c===`perf`&&(0,H.jsx)(`div`,{id:`panel-perf`,role:`tabpanel`,"aria-labelledby":`tab-perf`,children:(0,H.jsx)(nO,{viewModel:T})})]})]})}var ak=Vi({component:ik}),ok=zi({getParentRoute:()=>ak,path:`/`,component:()=>null}),sk=zi({getParentRoute:()=>ak,path:`/session/$sessionId`,component:()=>null}),ck=zi({getParentRoute:()=>ak,path:`/workflows`,validateSearch:e=>({tag:typeof e.tag==`string`?e.tag:void 0}),component:()=>null}),lk=zi({getParentRoute:()=>ak,path:`/workflows/$workflowId`,validateSearch:e=>({tag:typeof e.tag==`string`?e.tag:void 0}),component:()=>null}),uk=zi({getParentRoute:()=>ak,path:`/perf`,component:()=>null}),dk=zi({getParentRoute:()=>ak,path:`/auto`,component:()=>null}),fk=na({routeTree:ak.addChildren([ok,sk,ck,lk,uk,dk]),history:_r()}),pk=new Re({defaultOptions:{queries:{refetchInterval:5e3,staleTime:2e3}}});(0,sa.createRoot)(document.getElementById(`root`)).render((0,H.jsx)(V.StrictMode,{children:(0,H.jsx)(Ue,{client:pk,children:(0,H.jsx)(aa,{router:fk})})}));
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>WorkRail Console</title>
7
- <script type="module" crossorigin src="/console/assets/index-CfU3va8H.js"></script>
7
+ <script type="module" crossorigin src="/console/assets/index-BmDxs-a5.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/console/assets/index-DHrKiMCf.css">
9
9
  </head>
10
10
  <body>
@@ -4,7 +4,7 @@ export type ChildSessionResult = {
4
4
  readonly artifacts: readonly unknown[];
5
5
  } | {
6
6
  readonly kind: 'failed';
7
- readonly reason: 'error' | 'stuck' | 'delivery_failed';
7
+ readonly reason: 'error' | 'stuck';
8
8
  readonly message: string;
9
9
  } | {
10
10
  readonly kind: 'timed_out';
@@ -473,8 +473,8 @@
473
473
  "sha256": "5fe866e54f796975dec5d8ba9983aefd86074db212d3fccd64eed04bc9f0b3da",
474
474
  "bytes": 8011
475
475
  },
476
- "console-ui/assets/index-CfU3va8H.js": {
477
- "sha256": "7f7a29c1c312c2966f68131e1ade49ab0daf94ffd425c5c2d0b21add58c0028f",
476
+ "console-ui/assets/index-BmDxs-a5.js": {
477
+ "sha256": "8090617babfe49eb6f4b313ee45d13d862eba3ba8c9714ef805cda33918e4f08",
478
478
  "bytes": 768234
479
479
  },
480
480
  "console-ui/assets/index-DHrKiMCf.css": {
@@ -482,7 +482,7 @@
482
482
  "bytes": 60673
483
483
  },
484
484
  "console-ui/index.html": {
485
- "sha256": "3f08f8bf69e386e4ceca01a42720523c8e667635e7c5fbf2f3038540f29681e1",
485
+ "sha256": "d7ca1e4d2950572216e245c8a6a5130f8393ed3c961f067d2320202295b18183",
486
486
  "bytes": 417
487
487
  },
488
488
  "console/standalone-console.d.ts": {
@@ -590,8 +590,8 @@
590
590
  "bytes": 1815
591
591
  },
592
592
  "coordinators/types.d.ts": {
593
- "sha256": "913320eccf4737884fe73446e82ab0becbeeec55fa704c0613f19afe31a120aa",
594
- "bytes": 413
593
+ "sha256": "3043520258033bcdf5801ce8af81c8fa01c04573fc158a847addd8ec22f992e7",
594
+ "bytes": 393
595
595
  },
596
596
  "coordinators/types.js": {
597
597
  "sha256": "d43aa81f5bc89faa359e0f97c814ba25155591ff078fbb9bfd40f8c7c9683230",
@@ -3,6 +3,8 @@
3
3
  Workflow and feature ideas worth capturing but not yet planned or designed.
4
4
  For historical narrative and sprint journals, see `docs/history/worktrain-journal.md`.
5
5
 
6
+ **Before reading this backlog, read the vision:** `docs/vision.md` -- what WorkTrain is, what success looks like, and the principles every decision is held against. Every item in this backlog should serve that vision. If it doesn't, it shouldn't be here.
7
+
6
8
  **To see a sorted priority view, run:**
7
9
  ```bash
8
10
  npm run backlog # full list, grouped by blocked/unblocked
@@ -12,35 +14,77 @@ npm run backlog -- --help # all options
12
14
  ```
13
15
 
14
16
  Each item has a score line: `**Score: N** | Cor:N Cap:N Eff:N Lev:N Con:N | Blocked: ...`
15
- See the scoring rubric in the "Agent-assisted backlog prioritization" entry (WorkTrain Daemon section).
17
+
18
+ **When adding a new backlog item, score it using this rubric.** Five dimensions, each 1-3. Score = sum (max 15).
19
+
20
+ | Dimension | 3 | 2 | 1 |
21
+ |---|---|---|---|
22
+ | **Correctness** | Silent wrong output, crash, or skipped safety gate | Degraded behavior, misleading output, test coverage gap | No effect on correctness |
23
+ | **Capability** | Meaningfully expands what WorkTrain can do or who can use it | Reduces friction for an *active* use case today | Polish, internal quality, or nothing anyone is actively blocked by right now |
24
+ | **Effort** (inverted) | Hours to a day or two | A few days to a week | Weeks or longer, significant design work needed first |
25
+ | **Leverage** | Prerequisite for multiple other items | Enables one or two downstream items | Standalone, nothing depends on it |
26
+ | **Confidence** | Clear problem, clear direction, just needs implementation | Problem is clear, but has open questions to hash out first | Still needs discovery or design before work can begin |
27
+
28
+ **Blocked flag:** annotate with *what* the item is blocked by -- "Blocked: needs knowledge graph" vs "Blocked: needs dispatchCondition" carry very different timelines. Blocked items are listed separately regardless of score.
29
+
30
+ **Scoring notes:**
31
+ - Score the first actionable phase, not the full vision. Phase 1 = two days of work should not score Effort 1 just because Phase 3 is months away.
32
+ - Tiebreaker at equal score: prefer the item that makes the next item easier to execute.
33
+ - Capability 2 = reduces friction for an *active* use case today (not something hypothetical).
34
+
35
+ ---
36
+
37
+ **How to write a backlog item.** Every entry should follow this shape:
38
+
39
+ ```
40
+ ### Title (Date)
41
+
42
+ **Status: idea | bug | partial | done** | Priority: high/medium/low
43
+
44
+ **Score: N** | Cor:N Cap:N Eff:N Lev:N Con:N | Blocked: no / yes (blocked by X)
45
+
46
+ [2-4 sentences stating the problem plainly. What is wrong or missing? Why does it matter?
47
+ No proposed solutions here -- just the problem.]
48
+
49
+ **Things to hash out:**
50
+ - [Open question that needs a decision before design can begin]
51
+ - [Another open question -- constraint, tradeoff, interaction with other systems]
52
+ - [Keep these honest -- don't fill this section with questions you already know the answer to]
53
+ ```
54
+
55
+ **Rules for writing entries:**
56
+ - **State the problem, not the solution.** "There is no way to invoke a routine directly" not "We should add a `worktrain invoke` command."
57
+ - **No steering.** Don't tell future implementers how to build it. Capture what needs to exist, not how to make it exist.
58
+ - **Things to hash out = genuine open questions.** Only include questions that actually need to be answered before design can start. If you know the answer, state it in the problem description.
59
+ - **Relationships matter.** If this item depends on another, or would be superseded by another, name it explicitly.
60
+ - **Be specific about what "done" looks like** when it's not obvious -- e.g. "done means an operator can invoke any routine by name from the CLI without writing a workflow."
16
61
 
17
62
  ---
18
63
 
19
64
  ## P0 / Critical (blocks WorkTrain from working correctly)
20
65
 
21
- ### wr.coding-task implementation loop does not exit when slices complete (Apr 30, 2026)
66
+ ### wr.coding-task forEach loop exposes broken agent-facing state (Apr 30, 2026)
22
67
 
23
68
  **Status: bug** | Priority: high
24
69
 
25
70
  **Score: 13** | Cor:3 Cap:1 Eff:2 Lev:2 Con:3 | Blocked: no
26
71
 
27
- The `wr.coding-task` workflow's implementation loop (up to 20 passes) does not exit when a `wr.loop_control` stop artifact is emitted. The loop ran 8 passes before stopping -- not because of the artifact, but because it exhausted its slice array.
72
+ The `phase-6-implement-slices` loop (forEach over `slices`) ran correctly mechanically -- it iterated all 8 slices and stopped. But the agent-facing representation was broken in ways that violate WorkRail's promise of consistency and determinism:
28
73
 
29
- **Root cause (confirmed by investigation)**: `phase-6-implement-slices` is a `forEach` loop, not a `while`/`until` loop with `artifact_contract`. The `wr.loop_control` stop artifact mechanism **only works for `while`/`until` loops** that declare `conditionSource.kind = artifact_contract`. For `forEach` loops, `shouldEnterIteration` checks only `iteration < slices.length` -- artifacts passed to `interpreter.next()` are never consulted. Confirmed in `workflow-interpreter.ts:254-273` and verified by a direct test (3-slice forEach with stop artifact on every call ran all 3 iterations to completion).
74
+ 1. **`currentSlice.name` showed `[unset]`** -- the agent was inside a forEach loop over `slices` with `itemVar: "currentSlice"`, but the template variable wasn't being projected into sessionContext before rendering. The agent couldn't see which slice it was on. This is an engine rendering issue in `buildLoopRenderContext` / `prompt-renderer.ts`.
30
75
 
31
- **Why the loop stopped at pass 8**: the loop exhausted its `slices` array which had exactly 8 elements. `metrics_outcome = success` appearing at pass 8 was a coincidence.
76
+ 2. **Agent emitted `wr.loop_control` artifacts that had no effect** -- the forEach loop silently ignores these. The agent did useless work the engine discarded without signaling that this was happening. A correct system should either prevent the agent from emitting artifacts that can't affect the loop, or tell the agent explicitly that artifact-based exit isn't available in this loop type.
32
77
 
33
- **`currentSlice.name` showing `[unset]`**: secondary issue. `buildLoopRenderContext` in `prompt-renderer.ts:190-197` requires `sessionContext['slices']` to be an array at render time. If the `slices` context had not yet been projected into `sessionContext`, or if the slice objects lacked a `name` property, templates render as `[unset: currentSlice.name]`.
78
+ 3. **Loop presented as "Pass N of 20" not "Slice 3 of 8"** -- the framing confused the agent about what was happening. The agent should be told it's iterating over concrete slices, not burning through a budget.
34
79
 
35
- **Three fix directions:**
36
- 1. **Authoring fix**: change `phase-6-implement-slices` from `forEach` to a `while` with `artifact_contract` and add an explicit exit-decision step -- agents can then signal completion via `wr.loop_control`
37
- 2. **Engine feature**: add early-exit support to `forEach` loops when a `wr.loop_control` stop artifact is emitted
38
- 3. **Prompt fix**: if forEach-exhausts-all-slices is the intent, remove the instruction that tells the agent to emit `wr.loop_control` artifacts
80
+ The forEach loop *worked* but the agent experience was wrong. This matters because WorkRail's value is that agents should not be confused about their own loop state. An agent that emits useless artifacts, can't see its own iteration variable, and misunderstands whether the loop is progress-based or budget-based is not operating under the deterministic, correct framework WorkRail promises.
81
+
82
+ **GitHub issue:** https://github.com/EtienneBBeaulac/workrail/issues/920
39
83
 
40
84
  **Things to hash out:**
41
- - Which fix direction is correct depends on the intended behavior: should the agent be able to stop the loop early (fix 1 or 2), or should it always run all slices (fix 3)?
42
- - If fix 2 (engine feature), does early-exit from forEach affect the `currentSlice` render context in a way that could cause confusion?
43
- - Does fix 1 require re-authoring the workflow through `wr.workflow-for-workflows`, or is it a targeted JSON edit?
85
+ - Is `currentSlice.name = [unset]` a bug in `buildLoopRenderContext` (engine fix needed), or is it a workflow authoring issue (the slices array items don't have a `name` property)?
86
+ - Should the engine prevent agents from emitting `wr.loop_control` artifacts inside forEach loops, or simply document that they have no effect?
87
+ - Should forEach loops surface iteration progress ("slice 3 of 8") differently than while loops ("pass 3 of 20") in the step header text?
44
88
 
45
89
  ---
46
90
 
@@ -143,6 +187,8 @@ This is categorically different from bugs (the agent implemented the right thing
143
187
  - Agent makes a local fix when the user wanted an architectural change
144
188
  - Agent's implementation is technically correct but violates unstated invariants the user assumed were obvious
145
189
 
190
+ **Done looks like:** a WorkTrain session that receives an ambiguous or underspecified task either (a) states its interpretation explicitly before acting and the coordinator can gate on approval, or (b) has access to enough prior context (from the knowledge graph or living work context) that the interpretation is reliably correct. A session that builds the wrong thing well should be detectable before it merges, not after.
191
+
146
192
  **Things to hash out:**
147
193
  - Where in the workflow should intent validation happen? Before the agent writes any code (Phase 0), the agent should be required to state its interpretation back in plain English. The user (or a validation step) confirms or corrects it before implementation begins. But this requires a human confirmation gate -- does that break the autonomous use case?
148
194
  - For fully autonomous sessions (no human in the loop), is there a way to detect a likely intent gap before the agent commits? Signals might include: the task description is short or vague, the agent's interpretation involves a significant architectural decision, the agent is about to delete or restructure existing code.
@@ -173,6 +219,8 @@ This is exactly what happened with the commit SHA change: setting `agentCommitSh
173
219
  - Agent notes a downstream impact in session notes but does not block, escalate, or file a follow-up ticket
174
220
  - **Agent reframes a bug as "a key tradeoff to document."** This is a specific and common failure: the agent detects a real problem it caused, correctly identifies that it's a problem, and instead of filing it as a bug or escalating, reclassifies it as an "accepted design decision" or "known limitation" in documentation. The bug is real. Documenting it is not fixing it. This pattern actively buries bugs.
175
221
 
222
+ **Done looks like:** when an agent makes a change that degrades something outside its scope, it surfaces the degradation explicitly before the PR merges -- either by blocking (filing a follow-up issue as a condition of the current PR merging) or escalating to the coordinator for a decision. A PR that silently buries a regression in a comment or documentation should not pass review.
223
+
176
224
  **Things to hash out:**
177
225
  - How does an agent distinguish "acceptable tradeoff within scope" from "collateral damage that must be escalated"? The line is fuzzy and context-dependent. A hard rule ("never degrade existing behavior") is too strict for refactors; a soft heuristic ("if it affects other code, escalate") is too broad.
178
226
  - Should the agent be required to enumerate side effects as part of the verification phase, and should the coordinator review that list before merging? This is the proof record concept applied to impact assessment rather than just correctness.
@@ -283,6 +331,40 @@ Five dimensions, each scored 1-3. Score = sum (max 15). Items marked **Blocked**
283
331
 
284
332
  ---
285
333
 
334
+ ### `delivery_failed` unreachable in `getChildSessionResult` -- type promises more than code delivers (Apr 30, 2026)
335
+
336
+ **Status: bug** | Priority: medium
337
+
338
+ **Score: 10** | Cor:3 Cap:1 Eff:2 Lev:2 Con:2 | Blocked: no
339
+
340
+ `ChildSessionResult` has `reason: 'delivery_failed'` as a variant of `kind: 'failed'`. However `fetchChildSessionResult` in `coordinator-deps.ts` reads session status through `ConsoleService.getSessionDetail`, which returns statuses like `complete`/`blocked`/`in_progress` -- it never returns a `delivery_failed` status. `delivery_failed` is a `TriggerRouter`-level concept (callbackUrl POST failure) that is not stored as a session status in the event log. Child sessions spawned via `spawnSession`/`spawnAndAwait` have no `callbackUrl` and cannot produce it through this code path.
341
+
342
+ The result: coordinators using `getChildSessionResult` can never observe `reason: 'delivery_failed'`, even though the type says they might. This violates the "make illegal states unrepresentable" principle -- the type union promises a variant the implementation cannot produce on this path.
343
+
344
+ **Architectural fix (not a comment):** surface `delivery_failed` through session status. When `TriggerRouter` records a `delivery_failed` outcome, write a corresponding session event or status that `ConsoleService.getSessionDetail` returns. Then `fetchChildSessionResult` can map it correctly. This closes the gap between what the type promises and what the infrastructure delivers.
345
+
346
+ Alternative: if `spawnSession`/`spawnAndAwait` child sessions genuinely cannot have `delivery_failed` outcomes by design, remove `reason: 'delivery_failed'` from `ChildSessionResult` entirely and document that it only exists in `spawn_agent`'s direct outcome mapping.
347
+
348
+ **Things to hash out:**
349
+ - Should `delivery_failed` be surfaced through ConsoleService (requires touching session status storage), or removed from `ChildSessionResult` since the `spawnSession` path provably cannot produce it?
350
+ - If surfaced: what event or field in the session store carries this status, and how does ConsoleService project it?
351
+
352
+ ---
353
+
354
+ ### `spawnAndAwait` duplicates ~90 lines of polling logic from `awaitSessions` (Apr 30, 2026)
355
+
356
+ **Status: tech debt** | Priority: low
357
+
358
+ **Score: 8** | Cor:1 Cap:1 Eff:2 Lev:1 Con:3 | Blocked: no
359
+
360
+ `spawnAndAwait` in `coordinator-deps.ts` contains an inline polling loop (~90 lines) that duplicates the logic in `awaitSessions`. The WHY comment explains a real construction-time constraint: object literals cannot reference sibling methods by name during construction. But this constraint applies to methods on the returned object -- it does not apply to closure-level functions, which are already used for `fetchAgentResult` and `fetchChildSessionResult`.
361
+
362
+ **Fix:** extract a `pollUntilTerminal(handles: string[], timeoutMs: number): Promise<'completed' | 'timed_out' | 'degraded'>` closure-level function (before the `return {}` block). Have both `awaitSessions` and `spawnAndAwait` call it. This eliminates the duplication without violating the construction-time constraint.
363
+
364
+ **GitHub issue:** https://github.com/EtienneBBeaulac/workrail/issues/921
365
+
366
+ ---
367
+
286
368
  ### Daemon architecture: remaining migrations (Apr 29, 2026)
287
369
 
288
370
  **Status: partial** | A9 shipped Apr 29, 2026.
@@ -957,6 +1039,31 @@ Combined with the `DEFAULT_MAX_TURNS` cap, this provides defense-in-depth agains
957
1039
 
958
1040
  The durable session store, v2 engine, and workflow authoring features shared by all three systems.
959
1041
 
1042
+ ### WorkTrain as the canonical workflow author -- MCP as a derived runtime (Apr 30, 2026)
1043
+
1044
+ **Status: idea** | Priority: high
1045
+
1046
+ **Score: 13** | Cor:2 Cap:3 Eff:1 Lev:3 Con:2 | Blocked: no
1047
+
1048
+ Today workflows are authored once and expected to work identically in both runtimes: the WorkRail MCP server (human-in-the-loop, Claude Code) and the WorkTrain daemon (fully autonomous, coordinator-driven). In practice they don't -- a workflow authored for human use has `requireConfirmation` gates that block autonomous execution, step prompts that assume the human is reading them, and phase structures that assume a single continuous session. Conversely, a workflow good for autonomous use has no natural pause points, produces typed structured outputs that humans find hard to read mid-session, and chains phases that a human might want to interrupt.
1049
+
1050
+ The current response is to author separate "agentic variants" (`wr.coding-task` vs `coding-task-workflow.agentic.v2`). This is the wrong direction: it creates duplicate maintenance burden, improvements to one don't propagate to the other, and it means there is no single source of truth for what a workflow does.
1051
+
1052
+ There should be one version of each workflow, not two. Improvements to one should benefit the other automatically. The self-improvement loop WorkTrain runs on its own workflows should produce better workflows for everyone, not just daemon sessions. The question is how to structure authorship and any adaptation layer so this is possible without forcing workflows into an awkward compromise that works poorly in both contexts.
1053
+
1054
+ **What this enables:** WorkTrain can autonomously improve workflows using `wr.workflow-for-workflows`, and those improvements automatically benefit MCP users. The self-improvement loop produces better workflows for everyone, not just daemon sessions. Workflow quality compounds because there is only one version to improve.
1055
+
1056
+ **Relationship to existing entries:**
1057
+ - "Workflow runtime adapter: one spec, two runtimes" (Shared/Engine) is a narrower version of this idea focused on parallelism and `requireConfirmation` gates. This entry is about the authoring philosophy and source-of-truth question, not just the adapter mechanics.
1058
+ - `wr.workflow-for-workflows` is how WorkTrain improves workflows autonomously -- this entry determines what it improves toward.
1059
+
1060
+ **Things to hash out:**
1061
+ - What does the MCP conversion layer actually do? Adding pause points is straightforward. Adapting output formats (structured JSON → human-readable prose) may require active LLM translation, not just structural transformation.
1062
+ - Some workflow steps are genuinely different between runtimes -- a step that spawns parallel child sessions in the daemon doesn't have a clean MCP equivalent. Does the conversion layer skip those, simulate them sequentially, or require the author to declare a fallback?
1063
+ - If WorkTrain is the authoring target, existing workflows authored for MCP need migration. What is the migration path and who does it -- the author, WorkTrain itself, or a one-time script?
1064
+ - How do `requireConfirmation` gates fit? In the daemon they are removed or auto-satisfied by the coordinator. In MCP they pause for the human. Does the workflow declare them or does the conversion layer infer them?
1065
+ - Is the conversion layer purely structural (rearranging/omitting steps) or does it require understanding the semantic intent of each step?
1066
+
960
1067
 
961
1068
  ### Improve commit SHA gathering consistency in wr.coding-task
962
1069
 
@@ -1869,10 +1976,14 @@ A proof record contains: `prNumber`, `goal`, `verificationChain` (array of `{ ki
1869
1976
 
1870
1977
  ### Scripts-first coordinator: avoid the main agent wherever possible (Apr 15, 2026)
1871
1978
 
1872
- **Status: idea** | Priority: high
1979
+ **Status: partial** | Foundation shipped PR #908 (Apr 30, 2026)
1873
1980
 
1874
1981
  **Score: 12** | Cor:1 Cap:3 Eff:2 Lev:3 Con:3 | Blocked: no
1875
1982
 
1983
+ **What shipped:** `ChildSessionResult` discriminated union, `getChildSessionResult()`, `spawnAndAwait()`, `parentSessionId` threading, `wr.coordinator_result` artifact schema. The typed coordinator primitives that enable in-process coordinator scripts are now available.
1984
+
1985
+ **What's still needed:** the actual coordinator scripts (full development pipeline, bug-fix coordinator, grooming coordinator) and the `worktrain spawn`/`await` CLI commands that wrap these primitives for shell scripts.
1986
+
1876
1987
  **The insight:** In a coordinator workflow, the main agent spends most of its time on mechanical work -- reading PR lists, checking CI status, deciding whether findings are blocking, sequencing merges. That's all deterministic logic. An LLM is expensive, slow, and inconsistent for deterministic work.
1877
1988
 
1878
1989
  **The principle:** the scripts-over-agent rule applies at the coordinator level too. The coordinator's job is to drive a DAG of child sessions. The DAG structure, routing decisions, and termination conditions should be scripts, not LLM reasoning.
@@ -2038,7 +2149,7 @@ WorkTrain notices things without being asked. After a batch of work lands, it sc
2038
2149
 
2039
2150
  ### Native multi-agent orchestration: coordinator sessions + session DAG (Apr 15, 2026)
2040
2151
 
2041
- **Status: idea** | Priority: high
2152
+ **Status: partial** | Typed primitives shipped PR #908 (Apr 30, 2026)
2042
2153
 
2043
2154
  **Score: 10** | Cor:1 Cap:3 Eff:1 Lev:3 Con:2 | Blocked: no
2044
2155
 
@@ -2357,6 +2468,99 @@ A workflow that aggregates activity across git history, GitLab/GitHub MRs and re
2357
2468
 
2358
2469
  ## Platform Vision (longer-term)
2359
2470
 
2471
+ ### Move backlog to a dedicated worktrain-meta repo with version control (Apr 30, 2026)
2472
+
2473
+ **Status: idea** | Priority: high
2474
+
2475
+ **Score: 11** | Cor:2 Cap:2 Eff:2 Lev:3 Con:3 | Blocked: no
2476
+
2477
+ The backlog (`docs/ideas/backlog.md`) lives in the code repo. Every feature branch has its own version. Ideas added mid-session on a feature branch are held hostage until that PR merges. If two branches modify the backlog simultaneously, merge conflicts occur. There is no single authoritative place to capture an idea that immediately applies everywhere.
2478
+
2479
+ A dedicated `worktrain-meta` repo (e.g. `~/git/personal/worktrain-meta/`) would hold the backlog as the only concern. No feature branches -- ideas are committed directly to main. Full git history preserved. No code PR ever touches it.
2480
+
2481
+ Done means: an operator or agent can add a backlog idea from any branch or context, commit directly, and it is immediately visible on all other branches and in all other sessions.
2482
+
2483
+ **Note on format:** when this migration happens, one-file-per-item with YAML frontmatter becomes viable. Frontmatter makes scores, status, dates, and blocked-by machine-readable without prose parsing. The `npm run backlog` script would read frontmatter instead of regex-parsing Score lines. This is the right time to adopt that format -- in the current single-file structure frontmatter would require a custom delimiter scheme, but one-file-per-item makes it natural.
2484
+
2485
+ **Things to hash out:**
2486
+ - Should the worktrain-meta repo also hold the roadmap docs, now-next-later, open-work-inventory? Or just the backlog?
2487
+ - How do subagents spawned in a worktree find the backlog? They need a configured path, not relative to the code workspace.
2488
+ - When native structured backlog operations are built (SQLite), does the storage backend live in worktrain-meta (git-tracked history) or `~/.workrail/data/` (local queryable)? Both have merit.
2489
+
2490
+ ---
2491
+
2492
+ ### Invocable routines: dispatch an existing routine directly as a task (Apr 30, 2026)
2493
+
2494
+ **Status: idea** | Priority: high
2495
+
2496
+ **Score: 12** | Cor:1 Cap:3 Eff:2 Lev:3 Con:3 | Blocked: no
2497
+
2498
+ WorkRail has a routines system (`workflows/routines/`) for reusable workflow fragments. But routines can only be used embedded inside a larger workflow -- there is no way to invoke a routine directly as a standalone task. Many useful repeat tasks are process-shaped (same steps every time, structured output) and could be expressed as short 1-2 step workflows or existing routines. Today an operator who wants to run "context gathering" or "hypothesis challenge" on demand has to either build a wrapper workflow or do it manually.
2499
+
2500
+ There is no dispatch surface for standalone routine invocation. Done means: an operator can invoke any routine by name from the CLI or a trigger, and the result is durable in the session store.
2501
+
2502
+ **Relationship to existing ideas:** this is one half of the lightweight agents gap (the process-shaped half). The ad-hoc query half is a separate entry below.
2503
+
2504
+ **Things to hash out:**
2505
+ - Should this be a new CLI command (`worktrain invoke <routineId> --goal "..."`) or a trigger type, or both?
2506
+ - Do routines need output contracts defined before they can be invoked standalone, or is free-form output acceptable?
2507
+ - How does the session store record a routine-only run vs a full workflow run? Should they be distinguished?
2508
+
2509
+ ---
2510
+
2511
+ ### Ad-hoc query agents: answer questions about the workspace without a full workflow (Apr 30, 2026)
2512
+
2513
+ **Status: idea** | Priority: high
2514
+
2515
+ **Score: 11** | Cor:1 Cap:3 Eff:2 Lev:2 Con:2 | Blocked: yes (needs knowledge graph for efficient context)
2516
+
2517
+ There is a class of tasks that are question-shaped rather than process-shaped: "why does the session store use a manifest file?", "what would break if I changed this function?", "summarize what shipped this week." These don't have fixed steps, don't produce structured output contracts, and don't benefit from workflow phase gating. Running a full `wr.coding-task` session for them wastes 10 minutes on overhead. Not supporting them means the operator has to context-switch to Claude Code or do them manually.
2518
+
2519
+ These tasks need a capable agent with workspace context but no workflow structure. They are stateless, single-purpose, and short-lived.
2520
+
2521
+ Examples of what this enables:
2522
+ - `worktrain ask "why does the session store use a manifest file?"`
2523
+ - `worktrain explain pr/908`
2524
+ - `worktrain impact src/trigger/coordinator-deps.ts`
2525
+ - `worktrain diff-since "last week"`
2526
+
2527
+ Done means: an operator can ask a natural-language question about the workspace and get a grounded answer within seconds, without starting a full session.
2528
+
2529
+ **Relationship to existing ideas:** `worktrain talk` (interactive ideation) is the conversational, stateful version of this. Standup status generator is a scheduled instance of the same pattern. Invocable routines (entry above) are the process-shaped complement. This entry covers the unstructured query case.
2530
+
2531
+ **Things to hash out:**
2532
+ - Without the knowledge graph, these queries require full file-scanning on every invocation -- too slow to be useful. Is there a minimum viable version before the KG is built, or does this wait?
2533
+ - What is the boundary between "this is a quick query" and "this actually needs a full discovery session"? Who decides -- the operator, or WorkTrain itself?
2534
+ - Should outputs be ephemeral (printed to terminal, not stored) or durable (in session store)? Durability adds value for audit but adds overhead.
2535
+
2536
+ ---
2537
+
2538
+ ### Self-restart after shipping changes to itself (Apr 30, 2026)
2539
+
2540
+ **Status: idea** | Priority: medium
2541
+
2542
+ **Score: 11** | Cor:2 Cap:3 Eff:2 Lev:2 Con:2 | Blocked: yes (needs self-improvement loop operational)
2543
+
2544
+ If WorkTrain can build and ship changes to itself autonomously, the natural next step is that it also restarts itself with those changes. Today, after a WorkTrain daemon session ships a change to the workrail repo, the daemon continues running the old binary. The operator has to manually run `worktrain daemon --stop && worktrain daemon --start` to pick up the new version. In a self-improving system running overnight, this is a human intervention point that should not exist.
2545
+
2546
+ **What this requires:**
2547
+ 1. After a session that modifies WorkTrain itself merges to main, the daemon detects it was running on this repo
2548
+ 2. The daemon rebuilds (`npm run build`) and restarts itself cleanly -- completing any in-flight sessions first, then performing a graceful restart with the new binary
2549
+ 3. After restart, the daemon logs what changed so the operator can review
2550
+
2551
+ This is related to the "daemon binary stale after rebuild" P0 gap, but goes further: not just warning about staleness, but actually handling the upgrade cycle automatically.
2552
+
2553
+ **Why this matters for the self-improvement loop:** if WorkTrain ships 5 improvements to itself in a day but the operator has to manually restart it 5 times, the loop isn't truly autonomous. Full autonomy requires the restart to be part of the pipeline.
2554
+
2555
+ **Things to hash out:**
2556
+ - What triggers the restart check? After every merge to main that touches `src/`? After a successful `npm run build`? On a heartbeat that detects binary staleness?
2557
+ - How does the daemon ensure in-flight sessions complete before restarting? Does it drain the active session set or hard-stop?
2558
+ - What is the rollback path if the new binary fails to start (startup crash, broken build)? The daemon needs to detect this and either roll back or alert the operator.
2559
+ - Should the restart happen immediately or at a configurable "quiet period" (e.g. 2am) to avoid disrupting active sessions during the day?
2560
+ - Self-modification is inherently risky -- a buggy change to the daemon's restart logic could make the daemon unable to restart at all. What safeguards prevent this?
2561
+
2562
+ ---
2563
+
2360
2564
  ### WorkTrain as a first-class project participant: ideal backlog and planning capabilities (Apr 30, 2026)
2361
2565
 
2362
2566
  **Status: idea** | Priority: high (long-term)
@@ -54,9 +54,9 @@ Not every roadmap item must become a ticket immediately.
54
54
 
55
55
  ## Status ownership
56
56
 
57
- **Status lives in exactly two places**: `docs/roadmap/open-work-inventory.md` and `docs/roadmap/now-next-later.md`.
57
+ **Status lives in `docs/ideas/backlog.md`**. Each entry has a `Status:` line (idea / partial / done / bug). Use `npm run backlog` to see a scored, sorted view.
58
58
 
59
- Plan docs in `docs/plans/` describe **design and intent** -- not current status. When work ships, update the roadmap docs, not the plan doc. Plan docs that carry their own status blocks create a second source of truth that drifts.
59
+ Plan docs in `docs/plans/` describe **design and intent** -- not current status. When work ships, update the backlog entry status, not the plan doc.
60
60
 
61
61
  ## Rules of thumb
62
62
 
@@ -95,10 +95,7 @@ Existing feature-specific plans in `docs/plans/` still matter. Treat them as **f
95
95
 
96
96
  ## Starting points
97
97
 
98
- - `docs/ideas/backlog.md`
99
- - `docs/roadmap/now-next-later.md`
100
- - `docs/roadmap/open-work-inventory.md`
101
- - `docs/roadmap/legacy-planning-status.md`
102
- - `docs/planning/docs-taxonomy-and-migration-plan.md`
103
- - `docs/tickets/README.md`
104
- - `docs/tickets/next-up.md`
98
+ - `docs/vision.md` -- what WorkTrain is and where it's going (read this first)
99
+ - `docs/ideas/backlog.md` -- the backlog (`npm run backlog` for priority view)
100
+ - `docs/roadmap/legacy-planning-status.md` -- status map for older planning docs
101
+ - `docs/tickets/next-up.md` -- scratch space for near-term tickets
@@ -0,0 +1,8 @@
1
+ # Archive
2
+
3
+ These docs were superseded by `docs/ideas/backlog.md` + `npm run backlog`.
4
+
5
+ - `now-next-later.md` -- manual roadmap curation; replaced by backlog scoring and `npm run backlog`
6
+ - `open-work-inventory.md` -- normalized list of partial/unimplemented work; replaced by `Status: partial` entries in the backlog
7
+
8
+ Kept for historical reference only. Do not update.
@@ -1,6 +1,11 @@
1
1
  # Next Up
2
2
 
3
- Groomed near-term tickets. Check `docs/roadmap/now-next-later.md` first for the current priority ordering.
3
+ Scratch space for grooming near-term tickets before they become GitHub issues.
4
+ For the current priority ordering, run `npm run backlog -- --min-score 11 --unblocked-only` or see `docs/ideas/backlog.md`.
5
+
6
+ ---
7
+
8
+ > The tickets below are historical. Active work is tracked via GitHub issues and the backlog.
4
9
 
5
10
  ---
6
11
 
package/docs/vision.md ADDED
@@ -0,0 +1,115 @@
1
+ # WorkTrain Vision
2
+
3
+ ## What WorkTrain is
4
+
5
+ WorkTrain is an autonomous software development daemon. It runs continuously in the background, picks up tasks from external systems (GitHub issues, GitLab MRs, Jira tickets, webhooks), and drives them through the full development lifecycle -- discovery, shaping, implementation, review, fix, merge -- without human intervention between phases.
6
+
7
+ The operator's job is to configure what WorkTrain works on and what rules it follows. WorkTrain's job is to do the actual work, autonomously, reliably, and correctly.
8
+
9
+ ## The self-improvement loop
10
+
11
+ WorkTrain builds WorkTrain. This is not a metaphor -- it is the intended operating mode and the ultimate test of whether the system works.
12
+
13
+ WorkTrain runs the workrail repository as one of its own workspaces. It picks up tickets from the workrail GitHub issue queue, runs the full pipeline (discovery, shaping, coding, review, fix, merge), and ships improvements to itself. Every feature built into WorkTrain is a feature WorkTrain could have built using its own infrastructure. Every bug fixed in WorkTrain is a bug WorkTrain found in itself.
14
+
15
+ This creates a direct feedback loop: if WorkTrain's development pipeline is flawed, it will produce flawed changes to itself and catch them in review. If its context injection is thin, it will miss things in its own codebase that a well-briefed agent would catch. The quality of WorkTrain's output is the quality of WorkTrain.
16
+
17
+ The self-improvement loop is not fully operational today. The pieces -- coordinator session chaining, full development pipeline, spec as ground truth, living work context -- are being built. But it is the north star. If WorkTrain cannot build WorkTrain well, it cannot be trusted to build anything else.
18
+
19
+ ## What success looks like
20
+
21
+ An operator assigns a ticket to WorkTrain in the morning. By the time they check in, there is a merged PR, a closed ticket, and a summary of what was done and why. They did not intervene between phases. Nothing surprising happened that required their attention.
22
+
23
+ WorkTrain earns trust over time by doing this correctly, repeatedly, at scale -- not just for one-off tasks but as the default mode of software development. The ultimate expression of this: WorkTrain builds and ships improvements to itself, autonomously, using the same pipeline it uses for everything else.
24
+
25
+ ## What WorkTrain is not
26
+
27
+ - **Not a chatbot or copilot.** WorkTrain does not assist humans doing development. It does development. The human is the operator, not the pair programmer.
28
+ - **Not the WorkRail MCP server.** The WorkRail engine and MCP server are infrastructure WorkTrain uses. They are separate systems. Do not conflate them.
29
+ - **Not a replacement for judgment.** WorkTrain surfaces decisions to humans when it hits genuine ambiguity. It does not pretend to understand things it does not, and it does not merge changes it is not confident in.
30
+
31
+ ## How WorkTrain thinks about work
32
+
33
+ **Phases, not turns.** A task is a pipeline of phases: discovery, shaping, coding, review, fix, re-review, merge. Each phase is a session with a typed output contract. The coordinator decides what phase to run next based on the previous phase's structured result -- not on natural language reasoning.
34
+
35
+ **Zero LLM turns for routing.** Coordinator decisions -- what workflow to run next, whether findings are blocking, when to merge -- are deterministic TypeScript code. LLM turns are used for cognitive work: understanding code, writing code, evaluating findings. Never for deciding "what do I do next?".
36
+
37
+ **Structured outputs at every boundary.** Each phase produces a typed result. The next phase reads that result. Free-text scraping between phases is a design smell. `ChildSessionResult`, `wr.coordinator_result`, `wr.review_verdict` are the contracts that make phases composable without a main agent holding context.
38
+
39
+ **Correctness over speed.** WorkTrain does not merge changes it is not confident in. Review findings are addressed. Tests pass. The right next step is not always the fastest one.
40
+
41
+ ## What makes WorkTrain different from other autonomous coding agents
42
+
43
+ Most autonomous coding agents are single-session: they get a task, they work on it, they produce output. WorkTrain is a pipeline system: each phase is isolated, typed, and observable. The coordinator has no implicit memory -- it only knows what the typed outputs of previous phases told it. This makes pipelines:
44
+
45
+ - **Reproducible**: the same task run twice takes the same path
46
+ - **Observable**: every phase, every result, every decision is in the session store
47
+ - **Recoverable**: a crashed phase is retried with the same inputs
48
+ - **Auditable**: no black box; you can see exactly what each phase decided and why
49
+
50
+ ## Principles that guide every decision
51
+
52
+ 1. **Zero LLM turns for routing** -- coordinator logic is code, not reasoning
53
+ 2. **Typed contracts at phase boundaries** -- structured results, not free-text
54
+ 3. **The spec is the source of truth** -- every agent in a pipeline reads the same spec
55
+ 4. **Correctness over speed** -- do it right, not just done
56
+ 5. **Observable by default** -- every decision visible in the session store and console
57
+ 6. **Overnight-safe** -- the system must work while the operator is asleep
58
+
59
+ ## Quality standards WorkTrain holds itself to
60
+
61
+ WorkTrain does not ship work it is not confident in. Specifically:
62
+
63
+ - Review findings are addressed before merge -- no "I'll file a ticket for this later" on findings that block
64
+ - Tests pass. If tests were broken before the task started, that is noted explicitly, not silently ignored
65
+ - A PR that triggered the escalating review chain (Critical finding → re-review → re-review) never auto-merges without human approval
66
+ - If WorkTrain makes a change that degrades something outside its immediate scope, it surfaces that -- it does not document collateral damage as "a known tradeoff" and move on
67
+ - When WorkTrain is wrong about something, it acknowledges it explicitly in the session notes so the next session starts with accurate context
68
+
69
+ ## How WorkTrain handles uncertainty and mistakes
70
+
71
+ WorkTrain will make mistakes. The system is designed around this:
72
+
73
+ - When an agent is uncertain about the task intent, it states its interpretation explicitly before acting. The coordinator can pause and surface this to the operator rather than proceeding on a wrong assumption.
74
+ - Mistakes produce structured findings in the session store. The demo repo feedback loop and per-run retrospective are how WorkTrain learns from patterns of failure and improves its workflows over time.
75
+ - "That's out of scope for this task" is not a valid reason to proceed past something that is genuinely wrong. Scope is for routing work, not for suppressing correctness.
76
+
77
+ ## The operator relationship
78
+
79
+ The operator configures what WorkTrain works on (triggers, workflows, workspace rules) and sets the boundaries within which it operates. WorkTrain decides autonomously how to do the work.
80
+
81
+ WorkTrain pauses and surfaces to the operator when:
82
+ - It encounters genuine ambiguity about what the task is asking for
83
+ - A finding is Critical and requires explicit human approval before merging
84
+ - A child session fails in a way that exhausts automated retries
85
+ - Something unexpected happened that the coordinator's routing logic does not cover
86
+
87
+ WorkTrain does not pause for: implementation decisions within a well-specified task, routine review findings it can fix autonomously, or any decision that fits within the rules the operator already configured.
88
+
89
+ This boundary is still being tested and refined through real usage. Where exactly "genuine ambiguity" begins is an open question.
90
+
91
+ ## What is still being built
92
+
93
+ WorkTrain is not finished. The vision above is where it is going, not where it is today. Key pieces still in progress:
94
+
95
+ - **Living work context** -- shared knowledge store that accumulates across all phases so every agent starts informed (`docs/ideas/backlog.md`: "Living work context")
96
+ - **Coordinator pipeline templates** -- actual coordinator scripts for full development pipeline, bug-fix, grooming (`docs/ideas/backlog.md`: "Scripts-first coordinator")
97
+ - **`worktrain spawn`/`await` CLI** -- CLI surface for coordinator scripts
98
+ - **Knowledge graph** -- per-workspace structural understanding so agents skip discovery on repeated tasks
99
+ - **Spec as ground truth** -- wiring `wr.shaping` output into coordinator dispatch so coding/review agents work from the same spec
100
+
101
+ For the current prioritized list, see `npm run backlog` or `docs/ideas/backlog.md`.
102
+
103
+ ## Open questions
104
+
105
+ These are genuinely unresolved. Any agent operating in this system should know they exist and not assume they are answered.
106
+
107
+ - **Does WorkTrain need a main orchestrating agent?** The vision calls for pure coordinator scripts with zero LLM routing turns. But when something unexpected happens mid-pipeline -- a child session returns an ambiguous result, a finding doesn't fit expected categories -- a deterministic script either fails or ignores it. Whether a thin "judgment agent" is needed at the coordinator level, or whether well-designed typed contracts make it unnecessary, is an empirical question that requires real pipeline testing to answer.
108
+
109
+ - **Where exactly is the operator boundary?** The rules above are directionally right but have fuzzy edges. "Genuine ambiguity" is not yet precisely defined. This will sharpen through real usage and failure modes, not through upfront design.
110
+
111
+ - **How does WorkTrain know when it doesn't understand something?** An agent that mis-understands a task produces code that's correct for its interpretation but wrong for the operator's intent. Detecting this before implementation begins -- via explicit intent confirmation, pattern matching against prior sessions, or something else -- is an open problem. See `docs/ideas/backlog.md`: "Intent gap".
112
+
113
+ - **What is the right granularity of tasks?** WorkTrain is being designed for ticket-sized work. Whether it handles epics (by decomposing them), hotfixes (by moving fast and deferring thoroughness), and architectural changes (which may require multiple sessions across multiple days) the same way is untested.
114
+
115
+ - **Is "document" the right abstraction for the living work context?** A flat document implies agents read it linearly. Agents need to query it selectively -- the coding agent wants constraints relevant to a specific decision, the review agent wants what the coding agent said about a specific module. A structured knowledge store (typed facts, queryable by topic) may be more useful than a document. See `docs/ideas/backlog.md`: "Living work context".
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exaudeus/workrail",
3
- "version": "3.74.0",
3
+ "version": "3.74.1",
4
4
  "description": "Step-by-step workflow enforcement for AI agents via MCP",
5
5
  "license": "MIT",
6
6
  "repository": {