@netnodeag/kraftwerk 0.58.0 → 0.58.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.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-BkGiMzB_.js","assets/dist-CYzOYk_e.js","assets/dist-CHSqB1rM.js","assets/dist-BXQtebmM.js","assets/dist-B2o7tVdJ.js","assets/dist-BdZ5cNRp.js","assets/editor-CZMrhTTL.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-C6eZc_Cr.js","assets/dist-CYzOYk_e.js","assets/dist-CL5nzsfs.js","assets/dist-D9EqytQ1.js","assets/dist-HArst0KY.js","assets/dist-BdZ5cNRp.js","assets/editor-CZMrhTTL.css"])))=>i.map(i=>d[i]);
2
2
  var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,o)=>(o=n==null?{}:e(i(n)),c(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var u=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.for(`react.view_transition`),m=Symbol.iterator;function h(e){return typeof e!=`object`||!e?null:(e=m&&e[m]||e[`@@iterator`],typeof e==`function`?e:null)}var g={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},_=Object.assign,v={};function y(e,t,n){this.props=e,this.context=t,this.refs=v,this.updater=n||g}y.prototype.isReactComponent={},y.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},y.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function b(){}b.prototype=y.prototype;function x(e,t,n){this.props=e,this.context=t,this.refs=v,this.updater=n||g}var S=x.prototype=new b;S.constructor=x,_(S,y.prototype),S.isPureReactComponent=!0;var C=Array.isArray;function w(){}var T={H:null,A:null,T:null,S:null},E=Object.prototype.hasOwnProperty;function D(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function O(e,t){return D(e.type,t,e.props)}function k(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function ee(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function te(e,t){return typeof e==`object`&&e&&e.key!=null?ee(``+e.key):t.toString(36)}function ne(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(w,w):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function re(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,re(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+te(e,0):a,C(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),re(o,r,i,``,function(e){return e})):o!=null&&(k(o)&&(o=O(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(C(e))for(var u=0;u<e.length;u++)a=e[u],s=l+te(a,u),c+=re(a,r,i,s,o);else if(u=h(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+te(a,u++),c+=re(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return re(ne(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function j(e,t,n){if(e==null)return e;var r=[],i=0;return re(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function ie(e){if(e._status===-1){var t=e._result,n=t();n.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t,n.status===void 0&&(n.status=`fulfilled`,n.value=t))},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t,n.status===void 0&&(n.status=`rejected`,n.reason=t))}),e._status===-1&&(e._status=0,e._result=n)}if(e._status===1)return e._result.default;throw e._result}var M=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)};function ae(e){var t=T.T,n={};n.types=t===null?null:t.types,T.T=n;try{var r=e(),i=T.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(w,M)}catch(e){M(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),T.T=t}}function N(e){var t=T.T;if(t!==null){var n=t.types;n===null?t.types=[e]:n.indexOf(e)===-1&&n.push(e)}else ae(N.bind(null,e))}var P={map:j,forEach:function(e,t,n){j(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return j(e,function(){t++}),t},toArray:function(e){return j(e,function(e){return e})||[]},only:function(e){if(!k(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=P,e.Component=y,e.Fragment=r,e.Profiler=a,e.PureComponent=x,e.StrictMode=i,e.Suspense=l,e.ViewTransition=p,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=T,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return T.H.useMemoCache(e)}},e.addTransitionType=N,e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=_({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!E.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return D(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)E.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return D(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=k,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:ie}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=ae,e.unstable_useCacheRefresh=function(){return T.H.useCacheRefresh()},e.use=function(e){return T.H.use(e)},e.useActionState=function(e,t,n){return T.H.useActionState(e,t,n)},e.useCallback=function(e,t){return T.H.useCallback(e,t)},e.useContext=function(e){return T.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return T.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return T.H.useEffect(e,t)},e.useEffectEvent=function(e){return T.H.useEffectEvent(e)},e.useId=function(){return T.H.useId()},e.useImperativeHandle=function(e,t,n){return T.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return T.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return T.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return T.H.useMemo(e,t)},e.useOptimistic=function(e,t){return T.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return T.H.useReducer(e,t,n)},e.useRef=function(e){return T.H.useRef(e)},e.useState=function(e){return T.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return T.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return T.H.useTransition()},e.version=`19.3.0`})),d=o(((e,t)=>{t.exports=u()})),f=o((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&A(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&A(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,ee=k.port2;k.port1.onmessage=D,O=function(){ee.postMessage(null)}}else O=function(){_(D,0)};function A(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,A(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),p=o(((e,t)=>{t.exports=f()})),m=o((e=>{var t=d();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`),o=Symbol.for(`react.recoverable`),s=Symbol.for(`react.optimistic_key`);function c(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:r===s?s:``+r,children:e,containerInfo:t,implementation:n}}var l=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function u(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.browser=function(e){return{$$typeof:o,_reason:e}},e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return c(e,t,null,r)},e.flushSync=function(e){var t=l.T,n=i.p;try{if(l.T=null,i.p=2,e)return e()}finally{l.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=u(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}}else t??i.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=u(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}else i.d.m(e)}},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return l.H.useFormState(e,t,n)},e.useFormStatus=function(){return l.H.useHostTransitionStatus()},e.version=`19.3.0`})),h=o(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=m()})),g=o((e=>{var t=p(),n=d(),r=h();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){for(var t=e,n=t;n&&!n.alternate;)t=n,t.flags&4098&&(e=t.return),n=t.return;for(;t.return;)t=t.return;return t.tag===3?e:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function f(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=f(e),t!==null)return t;e=e.sibling}return null}function m(e,t,n,r,i,a){for(;e!==null;){if((e.tag===5||e.tag===27||e.tag===6)&&n(e,r,i,a)||(e.tag!==22||e.memoizedState===null)&&(t||e.tag!==5&&e.tag!==27)&&m(e.child,t,n,r,i,a))return!0;e=e.sibling}return!1}function g(e){for(e=e.return;e!==null;){if(e.tag===3||e.tag===5||e.tag===27)return e;e=e.return}return null}function _(e){var t=!1;for(e=e.return;e!==null&&(e.tag===4&&(t=!0),e.tag!==3&&e.tag!==5&&e.tag!==27);)e=e.return;return t}function v(e){var t=[null,null],n=g(e);return n===null||y(t,e,n.child,{foundSelf:!1}),t}function y(e,t,n,r){for(;n!==null;){if(n===t)r.foundSelf=!0;else if(n.tag===5||n.tag===27||n.tag===6){if(r.foundSelf)return e[1]=n,!0;e[0]=n}else if((n.tag!==22||n.memoizedState===null)&&y(e,t,n.child,r))return!0;n=n.sibling}return!1}function b(e){switch(e.tag){case 5:case 27:case 6:return e.stateNode;case 3:return e.stateNode.containerInfo;default:throw Error(i(559))}}var x=null,S=null;function C(e,t,n){return e===n||e===t&&(x=e,!0)}function w(e,t,n){return e===n?(S=e,!1):e===t&&(S!==null&&(x=e),!0)}function T(e){if(e===null)return null;do e=e===null?null:e.return;while(e&&e.tag!==5&&e.tag!==27&&e.tag!==3);return e||null}function E(e,t,n){for(var r=0,i=e;i;i=n(i))r++;i=0;for(var a=t;a;a=n(a))i++;for(;0<r-i;)e=n(e),r--;for(;0<i-r;)t=n(t),i--;for(;r--;){if(e===t||t!==null&&e===t.alternate)return e;e=n(e),t=n(t)}return null}var D=Object.assign,O=Symbol.for(`react.element`),k=Symbol.for(`react.transitional.element`),ee=Symbol.for(`react.portal`),A=Symbol.for(`react.fragment`),te=Symbol.for(`react.strict_mode`),ne=Symbol.for(`react.profiler`),re=Symbol.for(`react.consumer`),j=Symbol.for(`react.context`),ie=Symbol.for(`react.forward_ref`),M=Symbol.for(`react.suspense`),ae=Symbol.for(`react.suspense_list`),N=Symbol.for(`react.memo`),P=Symbol.for(`react.lazy`),oe=Symbol.for(`react.activity`),se=Symbol.for(`react.legacy_hidden`),ce=Symbol.for(`react.memo_cache_sentinel`),le=Symbol.for(`react.view_transition`),ue=Symbol.for(`react.recoverable`),de=Symbol.iterator;function fe(e){return typeof e!=`object`||!e?null:(e=de&&e[de]||e[`@@iterator`],typeof e==`function`?e:null)}var pe=Symbol.for(`react.client.reference`);function me(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===pe?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case A:return`Fragment`;case ne:return`Profiler`;case te:return`StrictMode`;case M:return`Suspense`;case ae:return`SuspenseList`;case oe:return`Activity`;case le:return`ViewTransition`}if(typeof e==`object`)switch(e.$$typeof){case ee:return`Portal`;case j:return e.displayName||`Context`;case re:return(e._context.displayName||`Context`)+`.Consumer`;case ie:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case N:return t=e.displayName||null,t===null?me(e.type)||`Memo`:t;case P:t=e._payload,e=e._init;try{return me(e(t))}catch{}}return null}var he=Array.isArray,F=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,I=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ge={pending:!1,data:null,method:null,action:null},_e=[],ve=-1;function ye(e){return{current:e}}function be(e){0>ve||(e.current=_e[ve],_e[ve]=null,ve--)}function L(e,t){ve++,_e[ve]=e.current,e.current=t}var xe=ye(null),Se=ye(null),Ce=ye(null),we=ye(null);function Te(e,t){switch(L(Ce,t),L(Se,e),L(xe,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?up(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=up(t),e=dp(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}be(xe),L(xe,e)}function Ee(){be(xe),be(Se),be(Ce)}function De(e){var t=e.memoizedState;t!==null&&(sh._currentValue=t.memoizedState,L(we,e)),t=xe.current;var n=dp(t,e.type);t!==n&&(L(Se,e),L(xe,n))}function R(e){Se.current===e&&(be(xe),be(Se)),we.current===e&&(be(we),sh._currentValue=ge)}var Oe,ke;function Ae(e){if(Oe===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);Oe=t&&t[1]||``,ke=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+Oe+e+ke}var je=!1;function Me(e,t){if(!e||je)return``;je=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}n=!1;try{var i=Object.getOwnPropertyDescriptor(e.prototype,`props`);Object.defineProperty(e.prototype,"props",{configurable:!0,set:function(){throw Error()}}),n=!0,new e}finally{n&&(i===void 0?delete e.prototype.props:Object.defineProperty(e.prototype,"props",i))}}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
@@ -212,7 +212,7 @@ description: What this skill is for (one line)
212
212
 
213
213
  Instructions this agent follows when the skill applies or is invoked with /<name>.
214
214
  `;function _s({slug:e}){let t=R(`/api/agents/${encodeURIComponent(e)}/skills`,!1)?.skills??[],[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``);async function c(t){s(``);let n=await fetch(`/api/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}`),i=await n.json().catch(()=>null);if(!n.ok||!i||i.error)return void s(i?.error??`could not load skill`);r({name:t,content:i.content??``,isNew:!1})}async function l(){if(!n)return;a(!0),s(``);let t=await(await fetch(`/api/agents/${encodeURIComponent(e)}/skills`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n.name,content:n.content})})).json().catch(()=>({error:`save failed`}));a(!1),t.error?s(t.error):r(null)}async function u(t){window.confirm(`Move skill "/${t}" of this agent to the trash?`)&&(await fetch(`/api/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}`,{method:`DELETE`}).catch(()=>{}),n?.name===t&&r(null))}return(0,C.jsxs)(K,{title:`own skills — only this agent`,actions:!n&&(0,C.jsx)(z,{size:`sm`,icon:`add`,onClick:()=>{r({name:``,content:gs,isNew:!0}),s(``)},children:`new skill`}),children:[t.length===0&&!n&&(0,C.jsxs)(U,{className:`px-[18px] py-3 text-xs`,children:[`none — skills in `,(0,C.jsxs)(`code`,{children:[`agents/`,e,`/skills/`]}),` are private to this agent; skills for every agent live in the workspace skills folder.`]}),t.length>0&&!n&&(0,C.jsx)(Xe,{children:t.map(e=>(0,C.jsx)(Ye,{icon:`extension`,title:`/${e.name}`,action:(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(z,{size:`sm`,icon:`edit`,onClick:()=>void c(e.name),children:`edit`}),(0,C.jsx)(B,{icon:`delete`,label:`delete /${e.name}`,variant:`danger`,size:`sm`,onClick:()=>void u(e.name)})]}),children:(0,C.jsx)(`span`,{className:Xo,children:e.description||(0,C.jsx)(`code`,{children:`SKILL.md`})})},e.name))}),n&&(0,C.jsxs)(ot,{className:`max-w-[680px]`,children:[(0,C.jsx)(Y,{label:`name — invoked as /<name>`,children:(0,C.jsx)(J,{className:`font-mono`,value:n.name,placeholder:`e.g. report-html`,disabled:!n.isNew,onChange:e=>r({...n,name:e.target.value})})}),(0,C.jsx)(Y,{label:`SKILL.md — frontmatter (description) + the instructions`,children:(0,C.jsx)(it,{className:$o,rows:Math.min(28,Math.max(12,n.content.split(`
215
- `).length+2)),value:n.content,spellCheck:!1,onChange:e=>r({...n,content:e.target.value})})}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,C.jsx)(z,{variant:`primary`,busy:i,disabled:!n.name.trim(),onClick:()=>void l(),children:i?`saving…`:`save`}),(0,C.jsx)(z,{variant:`quiet`,disabled:i,onClick:()=>r(null),children:`cancel`})]})]}),o&&(0,C.jsx)(`div`,{className:`px-[18px] pb-3`,children:(0,C.jsx)(G,{tone:`bad`,children:o})})]})}function vs({slug:e}){let t=R(`/api/agents/${encodeURIComponent(e)}/routines`,!1)?.routines??[],[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``);async function c(t){a(``);let n=await(await fetch(`/api/agents/${encodeURIComponent(e)}/routines`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})).json();return!n.error||(a(n.error),!1)}async function l(t){s(t),a(``);let n=await(await fetch(`/api/agents/${encodeURIComponent(e)}/routines/${encodeURIComponent(t)}/run`,{method:`POST`})).json();s(``),n.error?a(n.error):n.chatId&&M(`/agents/${encodeURIComponent(e)}/chat/${n.chatId}`)}async function u(t){window.confirm(`Delete the scheduled prompt "${t}"?`)&&await fetch(`/api/agents/${encodeURIComponent(e)}/routines/${encodeURIComponent(t)}`,{method:`DELETE`}).catch(()=>{})}return(0,C.jsxs)(K,{title:`schedule — prompts that run on their own`,actions:!n&&(0,C.jsx)(z,{size:`sm`,icon:`add`,onClick:()=>r({name:``,schedule:`0 9 * * 1-5`,prompt:``,enabled:!0}),children:`schedule a prompt`}),children:[t.length===0&&!n&&(0,C.jsx)(U,{className:`px-[18px] py-3 text-xs`,children:`none — a routine messages this agent on a schedule (cron, server local time) and each run opens a new session with the result.`}),t.length>0&&(0,C.jsx)(Xe,{children:t.map(t=>(0,C.jsx)(Ye,{icon:`schedule`,title:(0,C.jsxs)(C.Fragment,{children:[t.name,t.lastError&&(0,C.jsx)(`span`,{title:t.lastError,children:(0,C.jsx)(H,{tone:`bad`,children:`error`})}),t.awaitingApproval&&t.lastChatId&&(0,C.jsx)(H,{href:`/agents/${encodeURIComponent(e)}/chat/${t.lastChatId}`,tone:`bad`,title:`the last run asked for a permission nobody has answered yet`,children:`needs approval`})]}),action:(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(z,{size:`sm`,icon:`play_arrow`,busy:o===t.id,onClick:()=>l(t.id),children:o===t.id?`starting…`:`run`}),(0,C.jsx)(z,{size:`sm`,variant:`quiet`,onClick:()=>r({id:t.id,name:t.name,schedule:t.schedule,prompt:t.prompt,enabled:t.enabled}),children:`edit`}),(0,C.jsx)(z,{size:`sm`,variant:`danger`,onClick:()=>void u(t.id),children:`delete`}),(0,C.jsx)(ut,{checked:t.enabled,label:t.enabled?`enabled — click to pause`:`paused — click to enable`,onChange:()=>void c({id:t.id,name:t.name,schedule:t.schedule,prompt:t.prompt,enabled:!t.enabled})})]}),children:(0,C.jsxs)(`span`,{className:Xo,children:[(0,C.jsx)(`code`,{children:t.schedule}),t.enabled?t.nextRunAt?` · next ${Me(t.nextRunAt)}`:``:` · paused`,` · `,t.lastChatId?(0,C.jsxs)(P,{href:`/agents/${encodeURIComponent(e)}/chat/${t.lastChatId}`,children:[`last run `,Me(t.lastRunAt)]}):`never ran`]})},t.id))}),n&&(0,C.jsxs)(ot,{className:`max-w-[680px]`,children:[(0,C.jsxs)(st,{children:[(0,C.jsx)(Y,{label:`name`,className:`flex-1`,children:(0,C.jsx)(J,{value:n.name,placeholder:`e.g. Morning report`,onChange:e=>r({...n,name:e.target.value})})}),(0,C.jsx)(Y,{label:`schedule (cron)`,className:`w-[200px] max-[900px]:w-auto`,children:(0,C.jsx)(J,{className:`font-mono`,value:n.schedule,placeholder:`0 9 * * 1-5`,onChange:e=>r({...n,schedule:e.target.value})})}),(0,C.jsxs)(`label`,{className:`flex h-9 cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,C.jsx)(`input`,{type:`checkbox`,className:`accent-accent`,checked:n.enabled,onChange:e=>r({...n,enabled:e.target.checked})}),`enabled`]})]}),(0,C.jsx)(Y,{label:`prompt — what to ask this agent on each run`,children:(0,C.jsx)(it,{rows:5,value:n.prompt,placeholder:`Check ... and summarize what changed.`,onChange:e=>r({...n,prompt:e.target.value})})}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,C.jsx)(z,{variant:`primary`,disabled:!n.name.trim()||!n.prompt.trim(),onClick:async()=>{await c(n)&&r(null)},children:n.id?`save`:`add to the schedule`}),(0,C.jsx)(z,{variant:`quiet`,onClick:()=>(r(null),a(``)),children:`cancel`})]})]}),i&&(0,C.jsx)(`div`,{className:`px-[18px] pb-3`,children:(0,C.jsx)(G,{tone:`bad`,children:i})})]})}function ys({slug:e}){let[t,n]=(0,v.useState)(e?null:f()),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1),s=R(`/api/workflows`,!1)?.workflows??[],c=R(`/api/knowledge`,!1)?.bundles??[],l=me(),u=R(l.vibeables?`/api/vibeables`:``,!1)?.vibeables??[],d=R(`/api/skills`,!1)?.skills??[];(0,v.useEffect)(()=>{e&&fetch(`/api/agents/${encodeURIComponent(e)}`).then(e=>e.ok?e.json():Promise.reject()).then(e=>n({name:e.name,emoji:e.emoji,description:e.description??``,harness:e.harness,model:e.model??``,effort:e.effort??``,group:e.group??``,system:e.system,workflows:e.workflows,knowledge:e.knowledge??[],vibeables:e.vibeables??[],skillsAll:e.skills===void 0,skills:e.skills??[]})).catch(()=>i(`agent not found`))},[e]);function f(){return{name:``,emoji:`🤖`,description:``,harness:`claude`,model:``,effort:``,group:``,system:``,workflows:[],knowledge:[],vibeables:[],skillsAll:!0,skills:[]}}async function p(){if(!t)return;o(!0),i(``);let n=await(await fetch(e?`/api/agents/${encodeURIComponent(e)}`:`/api/agents`,{method:e?`PUT`:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({...t,skills:t.skillsAll?void 0:t.skills})})).json();o(!1),n.error?i(n.error):M(`/agents/${encodeURIComponent(n.slug)}/info`)}async function m(){e&&window.confirm(`Move agent "${e}" to the trash?`)&&(await fetch(`/api/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(()=>{}),M(`/agents`))}if(!t)return(0,C.jsx)(W,{children:r||`loading…`});let h=e=>n({...t,...e}),g=(e,n,r)=>h({[e]:r?[...t[e],n]:t[e].filter(e=>e!==n)});return(0,C.jsxs)(Ke,{width:`narrow`,children:[(0,C.jsx)(We,{children:e?`edit ${e}`:`new agent`}),(0,C.jsx)(K,{children:(0,C.jsxs)(ot,{className:`max-w-[680px]`,children:[(0,C.jsxs)(st,{children:[(0,C.jsx)(Y,{label:`name`,className:`flex-1`,children:(0,C.jsx)(J,{value:t.name,placeholder:`e.g. Max`,onChange:e=>h({name:e.target.value})})}),(0,C.jsx)(Y,{label:`emoji`,className:`w-[90px] max-[900px]:w-auto`,children:(0,C.jsx)(J,{value:t.emoji,onChange:e=>h({emoji:e.target.value})})})]}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Yo.map(e=>(0,C.jsx)(`button`,{type:`button`,"aria-pressed":t.emoji===e,className:b(`cursor-pointer rounded-xl border px-2.5 py-1.5 text-base transition-colors`,t.emoji===e?`border-transparent bg-accent-soft`:`border-line bg-transparent hover:bg-surface-2`),onClick:()=>h({emoji:e}),children:e},e))}),(0,C.jsxs)(st,{children:[(0,C.jsx)(Y,{label:`description`,className:`flex-1`,children:(0,C.jsx)(J,{value:t.description,placeholder:`one line: what this agent is for`,onChange:e=>h({description:e.target.value})})}),(0,C.jsx)(Y,{label:`group`,className:`w-[180px] max-[900px]:w-auto`,children:(0,C.jsx)(J,{value:t.group,placeholder:`none`,onChange:e=>h({group:e.target.value})})})]}),(0,C.jsxs)(st,{children:[(0,C.jsx)(Y,{label:`harness`,className:`w-[140px] max-[900px]:w-auto`,children:(0,C.jsxs)(at,{value:t.harness,onChange:e=>h({harness:e.target.value}),children:[(0,C.jsx)(`option`,{value:`claude`,children:`claude`}),(0,C.jsx)(`option`,{value:`codex`,children:`codex`}),(0,C.jsx)(`option`,{value:`pi`,children:`pi`})]})}),(0,C.jsx)(Y,{label:`model`,className:`flex-1`,children:(0,C.jsx)(J,{className:`font-mono`,value:t.model,placeholder:`harness default — e.g. sonnet, gpt-5.6-sol`,onChange:e=>h({model:e.target.value})})}),(0,C.jsx)(Y,{label:`effort`,className:`w-[140px] max-[900px]:w-auto`,children:(0,C.jsx)(at,{value:t.effort,onChange:e=>h({effort:e.target.value}),children:Fe.map(e=>(0,C.jsx)(`option`,{value:e,children:e||`default`},e))})})]}),(0,C.jsx)(Y,{label:`system prompt — the agent's role`,children:(0,C.jsx)(it,{className:$o,rows:10,value:t.system,placeholder:`You are the ... for this project. Your job is ...`,onChange:e=>h({system:e.target.value})})}),(0,C.jsxs)(bs,{label:`connected workflows — autoloaded into the agent's context; it can run them`,children:[s.map(e=>(0,C.jsx)(ct,{checked:t.workflows.includes(e.slug),onChange:t=>g(`workflows`,e.slug,t),hint:e.description,mono:!0,children:e.slug},e.slug)),s.length===0&&(0,C.jsx)(U,{className:`py-1.5 px-0`,children:`no workflows in this project`})]}),(0,C.jsxs)(bs,{label:`connected knowledge — OKF bundles the agent consults and maintains`,children:[c.map(e=>(0,C.jsx)(ct,{checked:t.knowledge.includes(e.name),onChange:t=>g(`knowledge`,e.name,t),hint:`${e.concepts} concepts`,mono:!0,children:e.name},e.name)),c.length===0&&(0,C.jsx)(U,{className:`py-1.5 px-0`,children:`no knowledge bundles in this project`})]}),(l.vibeables||t.vibeables.length>0)&&(0,C.jsxs)(bs,{label:`apps — small apps the agent builds and maintains`,linkKind:`vibeables`,children:[u.map(e=>(0,C.jsx)(ct,{checked:t.vibeables.includes(e.slug),onChange:t=>g(`vibeables`,e.slug,t),hint:e.dev?`dev`:`static`,mono:!0,children:e.slug},e.slug)),t.vibeables.filter(e=>!u.some(t=>t.slug===e)).map(e=>(0,C.jsx)(ct,{checked:!0,onChange:()=>g(`vibeables`,e,!1),hint:`not found in this workspace`,mono:!0,children:e},e)),!l.vibeables&&(0,C.jsx)(U,{className:`py-1.5 px-0`,children:`vibeables are off in this workspace's settings`}),l.vibeables&&u.length===0&&(0,C.jsx)(U,{className:`py-1.5 px-0`,children:`no vibeables in this workspace yet`})]}),(0,C.jsxs)(bs,{label:`connected skills — workspace skill packages (see the skills tab); invoked with /name in sessions`,children:[(0,C.jsx)(ct,{checked:t.skillsAll,onChange:e=>h({skillsAll:e}),hint:`every discovered skill, including future ones`,mono:!0,children:`all skills`}),!t.skillsAll&&d.map(e=>(0,C.jsx)(ct,{checked:t.skills.includes(e.name),onChange:t=>g(`skills`,e.name,t),hint:e.description,mono:!0,children:`/${e.name}`},e.name)),!t.skillsAll&&d.length===0&&(0,C.jsx)(U,{className:`py-1.5 px-0`,children:`no skills found (.claude/skills, project or user)`})]}),r&&(0,C.jsx)(G,{tone:`bad`,children:r}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,C.jsx)(z,{variant:`primary`,busy:a,disabled:!t.name.trim(),onClick:p,children:a?`saving…`:e?`save`:`create`}),(0,C.jsx)(`span`,{className:`flex-1`}),e&&(0,C.jsx)(z,{variant:`danger`,icon:`delete`,onClick:m,children:`delete agent`})]})]})})]})}function bs({label:e,linkKind:t,children:n}){return(0,C.jsxs)(`div`,{className:`flex flex-col gap-1.5`,"data-link-kind":t,children:[(0,C.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e}),(0,C.jsx)(Qo,{children:n})]})}function xs(e){if(!ie(e))return null;let t=e.split(`/`).filter(Boolean),n=decodeURIComponent(t[1]),r=t[0]===`agents`||t[0]===`team`;return n===`new`?t[0]===`projects`?(0,C.jsx)(Q,{},`new-project`):r?(0,C.jsx)(ys,{},`new-agent`):(0,C.jsx)(Sa,{},`new-channel`):t[0]===`projects`&&t[2]===`info`?(0,C.jsx)(Ro,{slug:n,onChanged:async()=>{}},n):r&&t[2]===`info`?(0,C.jsx)(hs,{slug:n},n):r&&t[2]===`edit`?(0,C.jsx)(ys,{slug:n},n):t[0]===`channels`&&t[2]===`edit`?(0,C.jsx)(Sa,{slug:n},n):null}function Ss({back:e,children:t}){let n=()=>M(e);return(0,v.useEffect)(()=>{let e=e=>{e.key!==`Escape`||e.defaultPrevented||document.querySelector(`.palette-backdrop`)||(e.preventDefault(),n())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}),(0,C.jsx)(`div`,{className:`fixed inset-0 z-40 flex animate-fade items-start justify-center bg-black/38 px-4 pt-[6vh] pb-4 max-[800px]:p-0`,onMouseDown:n,children:(0,C.jsxs)(`div`,{className:`edit-modal relative max-h-[88dvh] w-[min(960px,100%)] animate-modal overflow-y-auto rounded-card border border-line bg-surface shadow-modal max-[800px]:max-h-dvh max-[800px]:rounded-none`,role:`dialog`,"aria-label":`edit`,onMouseDown:e=>e.stopPropagation(),children:[(0,C.jsx)(B,{icon:`close`,label:`close (esc)`,className:`absolute top-3 right-3 z-1 rounded-full`,onClick:n}),(0,C.jsx)(`div`,{className:`runs-main min-w-0 pt-[18px] pr-12 pb-10 pl-6`,children:t})]})})}function Cs({runId:e,decision:t}){let{request:n,answer:r}=t,[i,a]=(0,v.useState)(n.options.length===1?n.options[0].value:null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(null),f=e=>n.options.find(t=>t.value===e)?.label??e;if(r)return(0,C.jsx)(`section`,{className:b(ws,`decision-panel is-decided`),"aria-label":`decision`,children:(0,C.jsxs)(`div`,{className:`flex flex-col gap-3 px-5 py-4`,children:[(0,C.jsx)(`div`,{className:Ts,children:n.title??`Decision`}),(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-base`,children:[(0,C.jsx)(H,{tone:`ok`,children:f(r.decision)}),r.note&&(0,C.jsxs)(`span`,{className:`text-fg-2`,children:[`“`,r.note,`”`]}),r.decidedAt&&(0,C.jsx)(`span`,{className:`text-xs tabular-nums text-fg-2`,children:Me(r.decidedAt)})]})]})});let p=!!i&&!c&&(n.note!==`required`||!!o.trim());async function m(){if(!p)return;l(!0),d(null);let t=await fetch(`/api/runs/${encodeURIComponent(e)}/decision`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({decision:i,note:o.trim()})}).catch(()=>null);t?.ok||(d((await t?.json().catch(()=>null))?.error??`could not save the decision`),l(!1))}return(0,C.jsx)(`section`,{className:b(ws,`decision-panel`),"aria-label":`decision needed`,children:(0,C.jsxs)(`div`,{className:`flex flex-col gap-3 px-5 py-4`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,C.jsx)(V,{tone:`working`}),(0,C.jsx)(`div`,{className:Ts,children:n.title??`This run needs your decision`})]}),n.prompt&&(0,C.jsx)(`p`,{className:`m-0 max-w-[80ch] text-base text-fg-2`,children:n.prompt}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-2 self-start`,role:`radiogroup`,"aria-label":`options`,children:n.options.map(e=>(0,C.jsx)(z,{role:`radio`,"aria-checked":i===e.value,variant:i===e.value?`primary`:`secondary`,onClick:()=>a(e.value),children:e.label??e.value},e.value))}),n.note!==!1&&(0,C.jsx)(J,{value:o,placeholder:n.note===`required`?`Note (required)`:`Note`,"aria-label":`note`,className:`max-w-[60ch]`,onChange:e=>s(e.target.value),onKeyDown:e=>e.key===`Enter`&&m()}),u&&(0,C.jsx)(G,{tone:`bad`,children:u}),(0,C.jsx)(`div`,{className:`flex gap-2`,children:(0,C.jsx)(z,{variant:`primary`,onClick:m,disabled:!p,busy:c,children:c?`Saving…`:`Submit decision`})})]})})}var ws=`mb-[18px] overflow-hidden rounded-card border border-line bg-surface`,Ts=`text-[16px] font-medium text-fg`;function Es(e){return e===`ok`?`ok`:e===`running`?`working`:e===`failed`||e===`blocked`?`bad`:`idle`}function Ds({status:e}){return(0,C.jsx)(`span`,{"data-ui":`status`,"data-status":e,className:`inline-flex`,children:(0,C.jsx)(H,{tone:e===`ok`?`ok`:e===`failed`||e===`blocked`?`bad`:e===`running`?`accent`:`neutral`,children:e})})}function Os(){return(0,C.jsx)(`span`,{"data-ui":`decision`,className:`inline-flex`,children:(0,C.jsx)(H,{tone:`accent`,children:`decision needed`})})}function ks({label:e,children:t,className:n}){return(0,C.jsxs)(`div`,{className:n,children:[(0,C.jsx)(He,{className:`mb-px block`,children:e}),(0,C.jsx)(`div`,{className:`font-mono text-md font-medium tabular-nums text-fg`,children:t})]})}var As=`mb-[22px] flex flex-wrap gap-[26px]`;function js({id:e,workflow:t}){let n=R(`/api/runs`,!0),r=n?.runs??[],[i,a]=(0,v.useState)(t??``),o=(0,v.useMemo)(()=>{let e=i.trim().toLowerCase();return e?r.filter(t=>[t.workflow,t.request,t.id].some(t=>t?.toLowerCase().includes(e))):r},[r,i]);return(0,C.jsxs)(`div`,{className:`runs-screen`,children:[(0,C.jsxs)(`aside`,{className:`runs-side`,children:[(0,C.jsx)(ft,{title:`runs`,back:{href:`/workflows`,label:`back to workflows`},count:i?`${o.length} / ${r.length}`:r.length}),(0,C.jsx)(pt,{icon:`filter_list`,value:i,placeholder:`filter by workflow or request`,"aria-label":`filter runs`,onChange:e=>a(e.target.value)}),(0,C.jsxs)(mt,{label:`runs list`,children:[o.map(t=>(0,C.jsx)(Ms,{r:t,active:t.id===e},t.id)),n&&r.length===0&&(0,C.jsx)(ht,{children:`no runs yet`}),r.length>0&&o.length===0&&(0,C.jsxs)(ht,{children:[`no run matches “`,i,`”`]})]})]}),(0,C.jsx)(`div`,{className:`runs-main`,children:(0,C.jsx)(Ns,{id:e},e)})]})}function Ms({r:e,active:t}){return(0,C.jsx)(q,{href:`/runs/${e.id}`,active:t,size:`sm`,leading:(0,C.jsx)(V,{tone:Es(e.status),title:e.status}),title:e.workflow??`unknown`,meta:Me(e.startedAt),sub:(0,C.jsxs)(`span`,{className:`flex gap-2`,children:[(0,C.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.request,children:e.status===`running`&&e.currentPhase?`${e.currentPhase}`:e.request??``}),(0,C.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:e.status===`running`?(0,C.jsx)(Pe,{since:e.startedAt}):Oe(e.durationMs)})]})})}function Ns({id:e}){let t=R(`/api/runs/${e}`,!0),n=t?.status===`running`,[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(null),l=ue();if(!t)return(0,C.jsx)(W,{children:`loading…`});let u=t.files.some(e=>e.name===`runner.json`),d=r??(n?`run`:`artifacts`),f=l?t.files.length:t.files.filter(e=>!Bs(e.name)).length;async function p(){o(!0),c(null);let t=await fetch(`/api/runs/${e}/stop`,{method:`POST`}).catch(()=>null);t?.ok||(o(!1),c((await t?.json().catch(()=>null))?.error??`stop failed`))}async function m(){if(!window.confirm(`Move run ${e} to the trash?`))return;c(null);let n=await fetch(`/api/runs/${e}`,{method:`DELETE`}).catch(()=>null);if(n?.ok){M(t?.workflow?`/workflows/${encodeURIComponent(t.workflow)}`:`/workflows`);return}c((await n?.json().catch(()=>null))?.error??`remove failed`)}return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`header`,{className:`mb-1.5 flex flex-wrap items-center gap-x-4 gap-y-2.5`,children:[(0,C.jsx)(V,{tone:Es(t.status),title:t.status}),(0,C.jsx)(We,{size:`lg`,children:t.workflow?(0,C.jsx)(P,{href:`/workflows/${encodeURIComponent(t.workflow)}`,title:`open workflow`,className:`text-inherit no-underline hover:text-accent`,children:t.workflow}):`unknown workflow`}),(0,C.jsx)(Ds,{status:t.status}),u&&(0,C.jsxs)(H,{children:[(0,C.jsx)(w,{name:`science`,className:`ms-sm mr-1`}),` sandbox`]}),(0,C.jsx)(`span`,{className:`font-mono text-xs text-fg-2`,children:e.replace(/^run-/,``)}),n?(0,C.jsx)(z,{size:`sm`,variant:`danger`,icon:`stop`,busy:a,onClick:p,children:a?`stopping…`:`stop`}):(0,C.jsx)(z,{size:`sm`,variant:`danger`,icon:`delete`,onClick:m,title:`delete this run's folder`,children:`remove`}),s&&(0,C.jsx)(`span`,{className:`text-xs text-bad`,children:s}),(0,C.jsx)(`span`,{className:`flex-1`}),(0,C.jsx)(z,{size:`sm`,variant:`quiet`,title:`chat with an agent about this run`,onClick:()=>void Ma(`claude`,{kind:`run`,runId:e}),children:`⌬ discuss`}),(0,C.jsx)(et,{className:`border-b-0 px-0`,label:`run sections`,value:d,onChange:i,items:[{id:`run`,label:`run`},{id:`artifacts`,label:`artifacts`,count:f}]})]}),t.request&&(0,C.jsx)(`p`,{className:`mb-5 max-w-[90ch] text-base text-fg-2`,children:t.request}),d===`run`?(0,C.jsx)(Ps,{run:t,live:n}):(0,C.jsx)(Hs,{id:e,files:t.files,live:n})]})}function Ps({run:e,live:t}){return(0,C.jsxs)(`div`,{className:`max-w-[1080px]`,children:[e.decision&&(0,C.jsx)(Cs,{runId:e.id,decision:e.decision}),(0,C.jsxs)(`div`,{className:As,children:[(0,C.jsxs)(ks,{label:`phases`,children:[e.phasesDone,e.phasesTotal==null?``:` / ${e.phasesTotal}`]}),(0,C.jsx)(ks,{label:`duration`,children:t?(0,C.jsx)(Pe,{since:e.startedAt}):Oe(e.durationMs)}),(0,C.jsx)(ks,{label:`cost`,children:ke(e.costUsd??Is(e.phases))}),(0,C.jsxs)(ks,{label:`tokens in / out`,children:[Ae(Fs(e.phases,`tokensIn`)),` / `,Ae(Fs(e.phases,`tokensOut`))]})]}),(0,C.jsx)(K,{title:`phase timeline`,actions:t&&(0,C.jsxs)(`span`,{className:`inline-flex items-center gap-[7px] text-2xs text-fg-2`,children:[(0,C.jsx)(V,{tone:`working`}),` live · polling`]}),children:(0,C.jsx)(`div`,{className:`py-1.5`,children:e.phases.map(e=>(0,C.jsx)(Rs,{p:e},e.phase))})})]})}function Fs(e,t){return e.reduce((e,n)=>e+(n[t]??0),0)}function Is(e){return e.reduce((e,t)=>e+(t.costUsd??0),0)}var Ls=`relative border-line/55 [&+&]:border-t before:absolute before:top-0 before:bottom-0 before:w-px before:bg-line last:before:bottom-auto`;function Rs({p:e}){let t=e.gates.filter(e=>!e.passed);return(0,C.jsxs)(`div`,{className:b(Ls,`py-2.5 pr-[18px] pl-[42px] before:left-[23px] first:before:top-4 last:before:h-4`),children:[(0,C.jsx)(`span`,{className:`absolute top-4 left-[19px] z-1 grid`,children:(0,C.jsx)(V,{tone:Es(e.status),title:e.status})}),(0,C.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2.5`,children:[(0,C.jsx)(`span`,{className:`text-base font-medium text-fg`,children:e.phase}),e.kind===`agent`?(0,C.jsxs)(H,{tone:`accent`,children:[e.agent,e.model?` · ${e.model}`:``,e.protocol?` · ${e.protocol}`:``]}):(0,C.jsx)(H,{children:`script`}),e.status===`skipped`&&(0,C.jsx)(Ds,{status:`skipped`}),(0,C.jsxs)(`span`,{className:`ml-auto flex gap-3.5 font-mono text-[11.5px] tabular-nums text-fg-2`,children:[e.attempts>1&&(0,C.jsxs)(`span`,{children:[`att `,e.attempts]}),e.status===`running`?(0,C.jsx)(Pe,{since:e.startedAt}):e.durationMs!=null&&(0,C.jsx)(`span`,{children:Oe(e.durationMs)}),e.kind===`agent`&&e.tokensIn!=null&&(0,C.jsxs)(`span`,{children:[Ae(e.tokensIn),` / `,Ae(e.tokensOut)]}),e.costUsd!=null&&e.costUsd>0&&(0,C.jsx)(`span`,{children:ke(e.costUsd)})]})]}),e.status===`running`&&e.lastActivity&&(0,C.jsxs)(`div`,{className:`mt-[3px] font-mono text-[11.5px] text-accent`,children:[`▸ `,e.lastActivity]}),e.summary&&e.status!==`running`&&(0,C.jsx)(`div`,{className:`mt-[3px] max-w-[72ch] text-[12.5px] text-fg-2`,children:e.summary}),e.gates.length>0&&(0,C.jsx)(`div`,{className:`mt-[5px] flex flex-wrap gap-1.5`,children:e.gates.map(e=>(0,C.jsxs)(`span`,{className:b(`inline-flex items-center gap-[5px] rounded-lg px-2.5 py-0.5 font-mono text-2xs`,e.passed?`bg-ok-soft text-ok`:`bg-bad-soft text-on-bad-soft`),title:e.failure??``,children:[(0,C.jsx)(w,{name:e.passed?`check`:`close`,className:`ms-sm`}),` `,e.gate]},e.gate))}),t.map(e=>(0,C.jsx)(`div`,{className:`mt-1 text-xs text-bad`,children:e.failure},e.gate))]})}var zs=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`]);function Bs(e){return e===`runner.json`||e.endsWith(`.jsonl`)||e.endsWith(`.log`)}function Vs(e){let t=[`report.html`,`recommendation.md`].find(t=>e.some(e=>e.name===t));if(t)return t;let n=e=>{let t=e.split(`.`).pop()?.toLowerCase()??``;return[`html`,`md`,`markdown`,`pdf`].includes(t)||zs.has(t)?0:Bs(e)?2:1},r=null;for(let t of e)(!r||n(t.name)<n(r.name))&&(r=t);return r?.name??null}function Hs({id:e,files:t,live:n}){let[r,i]=(0,v.useState)(null),a=ue(),o=(0,v.useMemo)(()=>a?t:t.filter(e=>!Bs(e.name)),[t,a]);return(0,v.useEffect)(()=>{!a&&r&&Bs(r)&&i(null)},[a,r]),(0,v.useEffect)(()=>{r||o.length===0||i(Vs(o))},[o,r]),(0,C.jsxs)(`div`,{className:`grid h-[calc(100vh-172px)] min-h-[420px] grid-cols-[280px_minmax(0,1fr)] gap-3.5 max-[940px]:h-auto max-[940px]:grid-cols-1`,children:[(0,C.jsx)(K,{title:(0,C.jsxs)(C.Fragment,{children:[`files `,(0,C.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,o.length,`)`]})]}),className:`flex min-h-0 flex-col`,children:(0,C.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto max-[940px]:max-h-60`,children:[o.map(e=>(0,C.jsxs)(`button`,{type:`button`,className:b(`flex w-full cursor-pointer items-center gap-2.5 border-0 border-b border-line/55 px-[18px] py-2 text-left font-mono text-[12.5px] transition-colors last:border-b-0`,r===e.name?`bg-accent-soft text-on-accent-soft`:`bg-transparent text-fg-2 hover:bg-surface-2 hover:text-fg`),onClick:()=>i(e.name),children:[(0,C.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,C.jsx)(`span`,{className:`text-2xs tabular-nums text-fg-2`,children:je(e.size)})]},e.name)),o.length===0&&(0,C.jsx)(U,{className:`px-[18px] py-3`,children:t.length>0?`no result files — raw run files live in expert mode`:`no files yet`})]})}),(0,C.jsx)(K,{title:r??`viewer`,className:`flex min-h-0 flex-col`,actions:r&&(0,C.jsx)(`a`,{className:Us,href:`/api/runs/${e}/file?name=${encodeURIComponent(r)}&raw=1`,target:`_blank`,children:`open raw ↗`}),children:r?(0,C.jsx)(Js,{id:e,name:r,live:n}):(0,C.jsx)(W,{className:`flex-1 justify-center`,children:`select a file`})})]})}var Us=`inline-flex h-7 items-center rounded-control px-2.5 text-sm font-medium text-fg-2 no-underline transition-colors hover:bg-surface-2 hover:text-fg`,Ws=`flex min-h-0 flex-1 flex-col`,Gs=`min-h-0 flex-1`,Ks=`m-0 h-full overflow-auto px-[18px] py-3.5 text-xs leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,qs=`block h-full min-h-[560px] w-full border-0 bg-white`;function Js({id:e,name:t,live:n}){let r=t.split(`.`).pop()?.toLowerCase()??``,i=`/api/runs/${e}/file?name=${encodeURIComponent(t)}&raw=1`;return r===`html`?(0,C.jsx)(`div`,{className:Ws,children:(0,C.jsx)(`div`,{className:Gs,children:(0,C.jsx)(`iframe`,{className:qs,src:i,sandbox:`allow-scripts`,allow:`clipboard-write`,title:t})})}):r===`pdf`?(0,C.jsx)(`div`,{className:Ws,children:(0,C.jsx)(`div`,{className:Gs,children:(0,C.jsx)(`iframe`,{className:qs,src:i,title:t})})}):zs.has(r)?(0,C.jsx)(`div`,{className:Ws,children:(0,C.jsx)(`div`,{className:Gs,children:(0,C.jsx)(`img`,{className:`block max-h-full max-w-full object-contain px-[18px] py-3.5`,src:i,alt:t})})}):r===`md`||r===`markdown`?(0,C.jsx)(Xs,{id:e,name:t,live:n}):(0,C.jsx)(Zs,{id:e,name:t,live:n})}var Ys=`flex items-center gap-3 border-b border-line/55 px-[18px] py-1.5 text-2xs text-fg-2`;function Xs({id:e,name:t,live:n}){let[r,i]=(0,v.useState)(`rendered`),a=R(`/api/runs/${e}/file?name=${encodeURIComponent(t)}`,n),o=(0,v.useMemo)(()=>a?Qi.sanitize(Cr.parse(a.content,{async:!1})):``,[a?.content]);return(0,C.jsxs)(`div`,{className:Ws,children:[(0,C.jsxs)(`div`,{className:Ys,children:[(0,C.jsx)(et,{className:`border-b-0 px-0`,label:`markdown view`,value:r,onChange:i,items:[{id:`rendered`,label:`rendered`},{id:`source`,label:`source`}]}),a?.truncated&&(0,C.jsxs)(`span`,{children:[`large file — showing the last `,je(4e5)]})]}),(0,C.jsx)(`div`,{className:b(Gs,`overflow-auto`),children:a?r===`rendered`?(0,C.jsx)(`div`,{className:`md-body`,dangerouslySetInnerHTML:{__html:o}}):(0,C.jsx)(`pre`,{className:Ks,children:a.content||`(empty)`}):(0,C.jsx)(`pre`,{className:Ks,children:`loading…`})})]})}function Zs({id:e,name:t,live:n}){let r=R(`/api/runs/${e}/file?name=${encodeURIComponent(t)}`,n);return(0,C.jsxs)(`div`,{className:Ws,children:[r?.truncated&&(0,C.jsxs)(`div`,{className:Ys,children:[`large file — showing the last `,je(4e5)]}),(0,C.jsx)(`div`,{className:Gs,children:(0,C.jsx)(`pre`,{className:Ks,children:r?r.content||`(empty)`:`loading…`})})]})}function Qs(){return R(`/api/workflows/any/run`,!1,15e3)}var $s=e=>!!e?.available&&!!e?.image;function ec(e){return e?e.available?e.image?`isolated container per run`:"image missing — run `kraftwerk runner build`":`Docker is not running`:``}async function tc(e,t){let n=await fetch(`/api/workflows/${encodeURIComponent(e)}/run`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);return r.runId}function nc(e,t,n,r){let[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(!0),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null),m=Qs();(0,v.useEffect)(()=>{!i&&n&&a(n)},[n]),(0,v.useEffect)(()=>{m&&!$s(m)&&s(!1)},[m]);let h=!u&&(!t||!!i.trim())&&(!o||$s(m));async function g(){if(h){d(!0),p(null);try{let t=await tc(e,{request:i.trim(),sandbox:o,ssh:c});r?(r(t),d(!1)):M(`/runs/${t}`)}catch(e){p(e.message),d(!1)}}}return{request:i,setRequest:a,sandbox:o,setSandbox:s,ssh:c,setSsh:l,busy:u,error:f,docker:m,canRun:h,launch:g}}function rc({slug:e,usesRequest:t,initialRequest:n,onLaunched:r}){let i=nc(e,t,n,r);return(0,C.jsxs)(`div`,{className:`flex flex-col gap-1 px-5 pt-4 pb-2`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-4 max-[700px]:flex-wrap`,children:[t?(0,C.jsx)(J,{className:`h-11 min-w-0 flex-1 text-md`,value:i.request,placeholder:`Request`,"aria-label":`request`,onChange:e=>i.setRequest(e.target.value),onKeyDown:e=>e.key===`Enter`&&i.launch()}):(0,C.jsx)(`span`,{className:`flex-1 text-base text-fg-2`,children:`This workflow takes no request.`}),(0,C.jsx)(z,{variant:`primary`,icon:`play_arrow`,className:`h-11 px-5 max-[700px]:w-full`,busy:i.busy,onClick:i.launch,disabled:!i.canRun,children:i.busy?`Starting…`:`Run`})]}),(0,C.jsxs)(`div`,{className:`-mx-2 mt-1 flex flex-wrap gap-x-2`,children:[(0,C.jsx)(dt,{label:`Docker sandbox`,hint:ec(i.docker),checked:i.sandbox,onChange:i.setSandbox}),i.sandbox&&(0,C.jsx)(dt,{label:`Forward SSH agent`,hint:`keys and known hosts from this machine`,checked:i.ssh,onChange:i.setSsh})]}),i.error&&(0,C.jsx)(G,{tone:`bad`,children:i.error})]})}var ic=`\0done`,ac=5;function oc(e,t){return e.status===`ok`?ic:e.currentPhase&&t.includes(e.currentPhase)?e.currentPhase:t[0]??ic}var sc=[`var(--accent)`,`#4fb8a8`,`#a78bfa`,`#e5793b`];function cc(e){return e==null?`var(--text-2)`:sc[e%sc.length]}function lc({colour:e,children:t,small:n}){return(0,C.jsx)(`span`,{style:{"--aid":e},className:b(`relative z-1 grid flex-none place-items-center rounded-full border font-mono font-bold tabular-nums`,`border-[color-mix(in_srgb,var(--aid)_55%,var(--line))] bg-[color-mix(in_srgb,var(--aid)_18%,var(--surface-1))] text-[var(--aid)]`,n?`size-[22px] text-2xs`:`mt-px size-[26px] text-[11.5px]`),children:t})}function uc({wf:e,runs:t,agentIdx:n,runsHref:r}){let i=e.steps.map(e=>e.name),a=new Map([...i,ic].map(e=>[e,[]]));for(let e of t)a.get(oc(e,i)).push(e);let o=a.get(ic)??[];return(0,C.jsxs)(`div`,{className:`board flex items-start gap-3 overflow-x-auto px-[18px] pt-3.5 pb-[18px]`,children:[e.steps.map((e,t)=>{let i=a.get(e.name)??[];return(0,C.jsx)(dc,{step:e.name,index:(0,C.jsx)(lc,{small:!0,colour:cc(e.agent?n.get(e.agent)??0:null),children:t+1}),count:i.length,children:(0,C.jsx)(fc,{cards:i,moreHref:r})},e.name)}),(0,C.jsx)(dc,{step:`done`,name:`done`,done:!0,index:(0,C.jsx)(lc,{small:!0,colour:`var(--ok)`,children:`✓`}),count:o.length,children:(0,C.jsx)(fc,{cards:o,moreHref:r})})]})}function dc({step:e,name:t,done:n,index:r,count:i,children:a}){return(0,C.jsxs)(`div`,{className:b(`board-col flex min-w-60 flex-[0_0_240px] flex-col gap-1.5`,n&&`is-done`),"data-step":e,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 px-0.5 pt-0.5 pb-1`,children:[r,(0,C.jsx)(`span`,{className:`board-col-name min-w-0 truncate text-[13.5px] font-medium text-fg`,title:t??e,children:t??e}),(0,C.jsx)(`span`,{className:`board-col-count ml-auto font-mono text-[11.5px] tabular-nums text-fg-2`,children:i})]}),a]})}function fc({cards:e,moreHref:t}){return(0,C.jsxs)(`div`,{className:`flex min-h-14 flex-col gap-2 rounded-xl bg-surface-2/60 p-2`,children:[e.slice(0,ac).map(e=>(0,C.jsx)(pc,{r:e},e.id)),e.length===0&&(0,C.jsx)(`div`,{className:`board-col-empty py-3.5 text-center text-xs text-fg-2`,children:`—`}),e.length>ac&&(0,C.jsxs)(P,{href:t,className:`board-more block p-1.5 text-center text-xs text-fg-2 no-underline hover:text-accent`,children:[`+ `,e.length-ac,` more ↗`]})]})}function pc({r:e}){let t=e.request??e.id.replace(/^run-/,``);return(0,C.jsxs)(P,{href:`/runs/${e.id}`,className:`board-card block rounded-xl border border-line bg-surface px-3 py-2.5 text-inherit no-underline transition-colors hover:bg-surface-2`,children:[(0,C.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,C.jsx)(V,{tone:Es(e.status),title:e.status}),(0,C.jsx)(`span`,{className:`min-w-0 truncate text-[13.5px] font-medium text-fg`,title:t,children:t})]}),(0,C.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2.5 font-mono text-[11.5px] tabular-nums text-fg-2`,children:[(0,C.jsx)(`span`,{children:Me(e.startedAt)}),(0,C.jsx)(`span`,{children:e.status===`running`?(0,C.jsx)(Pe,{since:e.startedAt}):Oe(e.durationMs)}),e.costUsd!=null&&e.costUsd>0&&(0,C.jsx)(`span`,{children:ke(e.costUsd)})]}),(e.awaitingDecision||e.status===`failed`||e.status===`aborted`)&&(0,C.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:[e.awaitingDecision&&(0,C.jsx)(Os,{}),(e.status===`failed`||e.status===`aborted`)&&(0,C.jsx)(Ds,{status:e.status})]})]})}function mc({slug:e,tab:t}){let n=R(`/api/workflows/${encodeURIComponent(e)}`,!1),[r,i]=(0,v.useState)(0),[a,o]=(0,v.useState)(0),s=R(`/api/runs`,a>0||Date.now()-r<2e4);if(!n)return(0,C.jsx)(W,{children:`loading…`});if(n.error)return(0,C.jsxs)(W,{children:[(0,C.jsx)(H,{tone:`bad`,children:`broken workflow`}),(0,C.jsx)(`pre`,{className:`mt-3 text-left`,children:n.error})]});let c=new Map(n.agents.map((e,t)=>[e.id,t%4])),l=(s?.runs??[]).filter(e=>e.workflow===n.name||e.workflow===n.slug),u=`/workflows/${encodeURIComponent(n.slug)}`,d=l.filter(e=>e.status===`running`).length;return d!==a&&o(d),(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`header`,{className:`mb-1.5 flex flex-wrap items-center gap-x-4 gap-y-2.5 in-[.ctx-embed]:mb-3 in-[.ctx-embed]:gap-y-2`,children:[(0,C.jsx)(We,{size:`lg`,className:`in-[.ctx-embed]:text-xl`,children:n.name??n.slug}),(0,C.jsx)(`span`,{className:`min-w-0 font-mono text-xs [overflow-wrap:anywhere] text-fg-2 in-[.ctx-embed]:hidden`,children:n.dir}),(0,C.jsx)(`span`,{className:`flex-1`}),(0,C.jsx)(et,{bare:!0,label:`workflow sections`,value:t,items:[{id:`overview`,href:u,label:`overview`},{id:`details`,href:`${u}/details`,label:`details`},{id:`runs`,href:`${u}/runs`,label:(0,C.jsxs)(C.Fragment,{children:[`runs `,(0,C.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,l.length,`)`]})]})}]})]}),n.description&&(0,C.jsx)(`p`,{className:`mb-5 max-w-[90ch] text-base text-fg-2`,children:n.description}),t===`overview`&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(K,{className:`run-panel mb-[18px]`,children:(0,C.jsx)(rc,{slug:n.slug,usesRequest:n.usesRequest,initialRequest:l[0]?.request,onLaunched:()=>i(Date.now())})}),(0,C.jsx)(K,{title:(0,C.jsxs)(C.Fragment,{children:[`board`,` `,(0,C.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,l.length,` runs`,d>0?`, ${d} live`:``,`)`]})]}),actions:l[0]&&(0,C.jsx)(z,{size:`sm`,variant:`quiet`,href:`${u}/runs`,className:`in-[.ctx-embed]:hidden`,children:`all runs ↗`}),children:(0,C.jsx)(uc,{wf:n,runs:l,agentIdx:c,runsHref:`${u}/runs`})})]}),t===`details`&&(0,C.jsx)(hc,{wf:n,agentIdx:c}),t===`runs`&&(0,C.jsx)(gc,{runs:l})]})}function hc({wf:e,agentIdx:t}){return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:As,children:[(0,C.jsx)(ks,{label:`agents`,children:e.agents.length}),(0,C.jsxs)(ks,{label:`steps`,children:[e.steps.length,` `,(0,C.jsxs)(`span`,{className:`font-normal text-fg-2`,children:[`(`,e.steps.filter(e=>e.kind===`agent`).length,` agent · `,e.steps.filter(e=>e.kind===`script`).length,` script)`]})]}),e.workspace&&(0,C.jsx)(ks,{label:`workspace`,className:`max-w-[420px]`,children:(0,C.jsx)(`span`,{className:`text-[11.5px] font-normal whitespace-pre-wrap text-fg-2`,children:e.workspace})})]}),(0,C.jsx)(K,{title:`agents`,className:`mb-[18px]`,children:(0,C.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(280px,1fr))]`,children:[e.agents.map(e=>(0,C.jsx)(vc,{a:e,idx:t.get(e.id)??0},e.id)),e.agents.length===0&&(0,C.jsx)(U,{className:`px-[18px] py-3`,children:`no agents — script-only workflow`})]})}),(0,C.jsxs)(`div`,{className:`grid items-start gap-[18px] grid-cols-[minmax(430px,5fr)_minmax(360px,4fr)] max-[1100px]:grid-cols-1 in-[.ctx-embed]:grid-cols-1`,children:[(0,C.jsx)(K,{title:`pipeline`,children:(0,C.jsx)(`div`,{className:`pipeline py-2`,children:e.steps.map((e,n)=>(0,C.jsx)(yc,{s:e,i:n,idx:e.agent?t.get(e.agent)??0:null},e.name))})}),(0,C.jsx)(K,{title:(0,C.jsxs)(C.Fragment,{children:[`folder `,(0,C.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,e.files.length,` files)`]})]}),children:(0,C.jsx)(`div`,{className:`max-h-[300px] overflow-auto`,children:e.files.map(e=>(0,C.jsx)(`div`,{className:`truncate border-b border-line/55 px-[18px] py-2 font-mono text-[12.5px] text-fg-2 last:border-b-0`,children:e},e))})})]})]})}function gc({runs:e}){return e.length===0?(0,C.jsx)(W,{children:`no runs of this workflow yet`}):(0,C.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map(e=>{let t=e.phasesTotal??0,n=t>0?Math.round(e.phasesDone/t*100):e.status===`ok`?100:0;return(0,C.jsxs)(P,{href:`/runs/${e.id}`,className:`run-card grid grid-cols-[12px_200px_1fr_auto] items-center gap-x-4 gap-y-2 rounded-card border border-line bg-surface px-5 py-3.5 text-inherit no-underline transition-colors hover:bg-surface-2 max-[900px]:grid-cols-[12px_1fr]`,children:[(0,C.jsx)(V,{tone:Es(e.status),title:e.status}),(0,C.jsx)(`span`,{className:`font-mono text-[12.5px] text-fg-2`,children:e.id.replace(/^run-/,``)}),(0,C.jsx)(`span`,{className:`min-w-0 truncate text-fg`,title:e.request,children:e.status===`running`&&e.currentPhase?e.currentPhase:e.request??``}),(0,C.jsxs)(`span`,{className:`flex items-center gap-3.5 font-mono text-xs tabular-nums text-fg-2 max-[900px]:col-span-2`,children:[e.awaitingDecision&&(0,C.jsx)(Os,{}),(0,C.jsx)(Ds,{status:e.status}),(0,C.jsx)(`span`,{className:`h-1 w-[90px] overflow-hidden rounded-full bg-surface-2`,title:`${e.phasesDone}${t?` / ${t}`:``} steps`,children:(0,C.jsx)(`i`,{className:b(`block h-full rounded-full`,e.status===`ok`?`bg-ok`:e.status===`failed`?`bg-bad`:`bg-accent`),style:{width:`${n}%`}})}),(0,C.jsx)(`span`,{children:e.status===`running`?(0,C.jsx)(Pe,{since:e.startedAt}):Oe(e.durationMs)}),(0,C.jsx)(`span`,{children:ke(e.costUsd)}),(0,C.jsx)(`span`,{children:Me(e.startedAt)})]})]},e.id)})})}var _c=`border-line/55`;function vc({a:e,idx:t}){return(0,C.jsxs)(`div`,{className:b(`agent-card border-r border-b px-[18px] py-3.5`,_c),children:[(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,C.jsx)(`span`,{className:`size-2.5 rounded-full`,style:{background:cc(t)}}),(0,C.jsx)(`b`,{className:`text-base font-medium text-fg`,children:e.name??e.id}),(0,C.jsxs)(`code`,{className:`text-2xs text-fg-2`,children:[`[`,e.id,`]`]}),(0,C.jsx)(`span`,{className:`flex-1`}),(0,C.jsxs)(H,{children:[e.model??`default`,e.effort?` · ${e.effort}`:``,e.protocol===`acp`?` · acp`:``]})]}),e.tools.length>0&&(0,C.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-[5px]`,children:e.tools.map(e=>(0,C.jsx)(`span`,{className:`rounded-md bg-surface-2 px-2 py-px font-mono text-2xs text-fg-2`,children:e},e))}),e.persona&&(0,C.jsx)(`p`,{className:`mt-2 mb-0 text-xs leading-[1.55] whitespace-pre-wrap text-fg-2`,children:e.persona})]})}function yc({s:e,i:t,idx:n}){let r=e.kind===`script`?e.script:e.prompt;return(0,C.jsxs)(`div`,{className:b(`step-node flex gap-3.5 px-[18px] py-3 first:before:top-[18px] last:before:h-[18px] before:left-[31px]`,Ls),children:[(0,C.jsx)(lc,{colour:cc(n),children:t+1}),(0,C.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,C.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2.5`,children:[(0,C.jsx)(`span`,{className:`text-base font-medium text-fg`,children:e.name}),e.kind===`agent`?(0,C.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded-full border px-2 text-2xs font-semibold`,style:{color:cc(n??0),borderColor:`color-mix(in srgb, ${cc(n??0)} 50%, var(--line))`},children:[`agent · `,e.agent]}):(0,C.jsxs)(H,{children:[`script`,e.sourceRef?` · ${e.sourceRef}`:``]})]}),r&&(0,C.jsxs)(`details`,{className:`mt-1.5`,children:[(0,C.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-fg-2 select-none hover:text-accent`,children:e.kind===`agent`?`prompt`:`script`}),(0,C.jsx)(`pre`,{className:`mt-1.5 max-h-[360px] overflow-auto rounded-xl bg-surface-2 px-3 py-2.5 text-[11.5px] leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,children:r})]}),e.gates.length>0&&(0,C.jsx)(`div`,{className:`mt-[5px] flex flex-wrap gap-1.5`,children:e.gates.map(e=>(0,C.jsxs)(`span`,{className:`inline-flex items-center gap-[5px] rounded-lg bg-surface-2 px-2.5 py-0.5 font-mono text-2xs text-fg-2`,children:[`⛨ `,e]},e))})]})]})}function bc(e,t){let n=e.filter(e=>e.workflow===(t.name??t.slug));return{count:n.length,last:n[0]}}function xc(e,t){return`/runs/${e.id}?workflow=${encodeURIComponent(t.name??t.slug)}`}function Sc({slug:e,tab:t}){let n=R(`/api/workflows`,!1),r=R(`/api/runs`,!1),[i,a]=(0,v.useState)(``),o=n?.workflows??[],s=r?.runs??[],c=(0,v.useMemo)(()=>{let e=i.trim().toLowerCase();return e?o.filter(t=>[t.name,t.slug,t.description].some(t=>t?.toLowerCase().includes(e))):o},[o,i]),l=(0,v.useMemo)(()=>{if(o.length!==0)return(o.map(e=>({w:e,last:bc(s,e).last})).filter(e=>!!e.last).sort((e,t)=>(t.last.updatedAt??``).localeCompare(e.last.updatedAt??``))[0]?.w??o[0]).slug},[o,s]),u=!!r;return(0,v.useEffect)(()=>{!e&&l&&u&&M(`/workflows/${encodeURIComponent(l)}`,{replace:!0})},[e,l,u]),(0,C.jsxs)(`div`,{className:`runs-screen workflows-screen`,children:[(0,C.jsxs)(`aside`,{className:`runs-side`,children:[(0,C.jsx)(ft,{title:`workflows`,count:n?o.length:void 0,action:(0,C.jsxs)(z,{size:`sm`,variant:`quiet`,icon:`history`,href:`/runs`,title:`every run of every workflow, newest first`,children:[`runs `,(0,C.jsx)(`span`,{className:`tabular-nums`,children:s.length})]})}),o.length>0&&(0,C.jsx)(pt,{icon:`search`,value:i,placeholder:`search workflows`,"aria-label":`search workflows`,onChange:e=>a(e.target.value)}),(0,C.jsxs)(mt,{children:[c.map(t=>{let n=bc(s,t);return(0,C.jsx)(q,{className:`wf-row`,href:`/workflows/${encodeURIComponent(t.slug)}`,active:t.slug===e,leading:(0,C.jsx)(V,{tone:Es(n.last?.status),title:n.last?.status??`no runs yet`}),title:t.name??t.slug,titleExtra:t.error&&(0,C.jsx)(H,{tone:`bad`,children:`broken`}),meta:n.last&&Ne(n.last.updatedAt),sub:(0,C.jsx)(`span`,{title:t.error??t.description??``,children:t.error??t.description??`${t.agents} agents · ${t.steps} steps`}),subTone:t.error?`bad`:`plain`,actionsAlways:!0,actions:n.last?(0,C.jsxs)(`button`,{type:`button`,className:`wf-runs inline-flex cursor-pointer items-center gap-1 rounded-control border-0 bg-transparent px-1.5 py-0.5 text-2xs tabular-nums text-fg-2 transition-colors hover:bg-surface-2 hover:text-fg`,title:`show the runs of this workflow`,onClick:()=>M(xc(n.last,t)),children:[n.count,` `,n.count===1?`run`:`runs`,` · `,(0,C.jsx)(Ds,{status:n.last.status})]}):(0,C.jsx)(`span`,{className:`wf-runs px-1.5 text-2xs text-fg-2 opacity-80`,children:`no runs yet`})},t.slug)}),n&&o.length>0&&c.length===0&&(0,C.jsxs)(ht,{className:`wf-nomatch`,children:[`no workflow matches “`,i,`”`]}),n&&o.length===0&&(0,C.jsx)(ht,{children:`no workflows yet`})]})]}),(0,C.jsx)(`div`,{className:`runs-main`,children:e?(0,C.jsx)(mc,{slug:e,tab:t},e):n&&o.length===0?(0,C.jsxs)(W,{icon:`account_tree`,children:[`No workflows found — expected `,(0,C.jsx)(`code`,{children:`src/workflows/`}),` or `,(0,C.jsx)(`code`,{children:`workflows/`}),` next to the output folder.`]}):(0,C.jsx)(W,{children:`loading…`})})]})}var Cc=e=>e===`ok`?`ok`:e===`running`?`running`:e===`aborted`?`aborted`:`failed`,wc=e=>e===`ok`?`done`:e===`running`?`working`:e===`aborted`?`stopped`:`failed`;function Tc(e){return e.scope.kind===`channel`?`/channels/${e.scope.slug}`:e.scope.kind===`project`?`/projects/${e.scope.slug}/chat/${e.id}`:e.scope.kind===`agent`?`/agents/${e.scope.slug}/chat/${e.id}`:`/agents/chats/${e.id}`}function Ec(e,t,n){switch(e.scope.kind){case`agent`:{let n=e.scope.slug,r=t.find(e=>e.slug===n);return r?`${r.emoji||`🤖`} ${r.name}`:n}case`project`:return`📁 ${n(e.scope.slug)}`;case`channel`:return e.project?`📁 ${n(e.project)} · #${e.scope.slug}`:`#${e.scope.slug}`;case`run`:return`⚙️ run ${e.scope.runId}`;case`knowledge`:return e.scope.bundle?`📚 ${e.scope.bundle}`:`📚 knowledge`;default:return`🎩 Ralv`}}function Dc(e){return e.length>64?`${e.slice(0,46)}…${e.slice(-14)}`:e}function Oc(){let e=R(`/api/runs`,!1),t=R(`/api/chats`,!1),n=R(`/api/knowledge`,!1),r=R(`/api/agents`,!1),i=R(`/api/workflows`,!1),a=R(`/api/skills`,!1),[o,s]=(0,v.useState)(`all`),c=ue(),l=R(`/api/projects`,!1,3e4),u=e=>l?.projects.find(t=>t.slug===e)?.title??e,d=e?.runs??[],f=t?.chats??[],p=n?.bundles??[],m=(a?.skills??[]).filter(e=>e.source===`workspace`),h=[[i?.workflows.length,`workflows`,`/workflows`],[e?d.length:void 0,`runs`,`/runs`],[n?p.length:void 0,`bundles`,`/knowledge`],[a?m.length:void 0,`skills`,`/skills`],[t?f.length:void 0,`chats`,`/agents/chats`]],g=d.filter(e=>e.status===`failed`&&Date.now()-Date.parse(e.updatedAt)<864e5);return(0,C.jsxs)(`div`,{className:`w-full px-7 pt-6 pb-10`,children:[(0,C.jsx)(Ic,{runs:d,chats:f,bundles:p,agents:r?.agents??[],workflows:i?.workflows??[],projectTitle:u,loaded:!!e&&!!t}),c&&(0,C.jsx)(`div`,{className:`mx-0.5 mt-3.5 mb-3 flex flex-wrap justify-end gap-[18px] text-xs text-fg-2`,children:h.map(([e,t,n])=>(0,C.jsxs)(P,{href:n,className:`group/mini text-inherit no-underline hover:text-accent hover:underline`,children:[(0,C.jsx)(`b`,{className:`font-semibold tabular-nums text-fg group-hover/mini:text-accent`,children:e??`…`}),` `,t]},t))}),c&&g.length>0&&o!==`failed`&&(0,C.jsxs)(`button`,{type:`button`,className:`mb-3.5 flex w-full cursor-pointer items-center gap-2 rounded-xl border border-bad/40 bg-bad-soft px-3.5 py-[9px] text-left text-[12.5px] text-on-bad-soft hover:brightness-104`,onClick:()=>s(`failed`),children:[`⚠ `,g.length,` run`,g.length===1?``:`s`,` failed in the last 24 h — review`]}),c&&(0,C.jsx)(jc,{projectTitle:u,runs:d,chats:f,bundles:p,agents:r?.agents??[],workflows:i?.workflows??[],filter:o,setFilter:s})]})}function kc(e){if(e.lamp===`running`)return`now`;let t=new Date(e.at),n=new Date;if(t.toDateString()===n.toDateString())return`today`;let r=new Date(n);return r.setDate(r.getDate()-1),t.toDateString()===r.toDateString()?`yesterday`:`earlier`}var Ac=[[`all`,`all`],[`run`,`runs`],[`session`,`chats`],[`knowledge`,`knowledge`]];function jc({projectTitle:e,runs:t,chats:n,bundles:r,agents:i,workflows:a,filter:o,setFilter:s}){let c=ue(),l=(0,v.useMemo)(()=>{let s=[],l=e=>e?a.find(t=>t.slug===e)?.name??e:void 0;for(let e of t)s.push({at:e.updatedAt,kind:`run`,emoji:`⚙️`,title:l(e.workflow)??e.id,sub:e.request??``,href:`/runs/${e.id}`,lamp:Cc(e.status),status:wc(e.status)});for(let t of n){let n=t.scope.kind===`agent`?i.find(e=>t.scope.kind===`agent`&&e.slug===t.scope.slug):void 0;s.push({at:t.updatedAt,kind:`session`,emoji:n?n.emoji||`🤖`:`💬`,title:n?n.name:t.title||`new chat`,sub:n?`${t.title||`new chat`}${c?` · ${t.agent}`:``}`:c?`${t.agent} · ${Ec(t,i,e)}`:Ec(t,i,e),href:Tc(t),lamp:t.awaitingApproval?`blocked`:t.busy?`running`:`ok`,status:t.awaitingApproval?`needs approval`:t.busy?`working`:void 0})}for(let e of r)e.updatedAt&&s.push({at:e.updatedAt,kind:`knowledge`,emoji:`📚`,title:e.name,sub:`${e.concepts} concepts`,href:`/knowledge/${encodeURIComponent(e.name)}`,lamp:`ok`});return(o===`all`?s:o===`failed`?s.filter(e=>e.kind===`run`&&e.lamp===`failed`):s.filter(e=>e.kind===o)).sort((e,t)=>{let n=Number(t.lamp===`running`)-Number(e.lamp===`running`);return n===0?t.at.localeCompare(e.at):n}).slice(0,15)},[t,n,r,i,c,o]),u=``,d=(e,t)=>b(`inline-flex cursor-pointer items-center gap-0.5 rounded-lg border px-2.5 py-0.5 text-2xs transition-colors`,e?b(`border-transparent`,t?`bg-bad-soft text-on-bad-soft`:`bg-accent-soft text-on-accent-soft`):`border-line bg-transparent text-fg-2 hover:text-fg`);return(0,C.jsx)(K,{className:`animate-rise`,title:`all activity`,actions:(0,C.jsxs)(`span`,{className:`flex gap-1.5`,children:[Ac.map(([e,t])=>(0,C.jsx)(`button`,{type:`button`,className:d(o===e),"aria-pressed":o===e,onClick:()=>s(e),children:t},e)),o===`failed`&&(0,C.jsxs)(`button`,{type:`button`,className:d(!0,!0),onClick:()=>s(`all`),children:[`failed `,(0,C.jsx)(w,{name:`close`,className:`ms-sm`})]})]}),children:l.length===0?(0,C.jsx)(`div`,{className:`px-[18px] py-4 text-sm text-fg-2`,children:o===`all`?`nothing yet — run a workflow or start a chat`:`nothing here for this filter`}):(0,C.jsx)(`div`,{className:`flex flex-col p-1.5`,children:l.map(e=>{let t=kc(e),n=t===u?null:t;return u=t,(0,C.jsxs)(`div`,{children:[n&&(0,C.jsx)(He,{className:`block px-2.5 pt-3 pb-1`,children:n}),(0,C.jsx)(q,{href:e.href,leading:(0,C.jsxs)(`span`,{className:`relative text-[18px] leading-none`,children:[(0,C.jsx)(`span`,{"aria-hidden":!0,children:e.emoji}),e.lamp===`running`&&(0,C.jsx)(`span`,{className:`absolute -right-1 -bottom-1 grid rounded-full bg-surface p-px`,children:(0,C.jsx)(V,{tone:`working`})})]}),title:Dc(e.title),titleExtra:(0,C.jsx)(H,{tone:Mc[e.kind],children:e.kind===`session`?`chat`:e.kind}),sub:e.sub&&Dc(e.sub),meta:(0,C.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.status&&(0,C.jsx)(H,{tone:Nc[e.lamp]??`neutral`,children:e.status}),(0,C.jsx)(`span`,{title:new Date(e.at).toLocaleString(),children:Ne(e.at)}),(0,C.jsx)(w,{name:`chevron_right`,className:`ms-sm`})]})})]},`${e.kind}:${e.href}:${e.at}`)})})})}var Mc={run:`accent`,session:`ask`,knowledge:`ok`},Nc={ok:`ok`,failed:`bad`,blocked:`bad`,running:`accent`,aborted:`neutral`};function Pc(e){if(!e)return``;let t=Math.max(0,Math.round((Date.now()-Date.parse(e))/6e4));return t<1?`just started`:t<60?`${t} min`:`${Math.floor(t/60)} h ${t%60} min`}var Fc=e=>new Date(e).toDateString()===new Date().toDateString();function Ic({runs:e,chats:t,bundles:n,agents:r,workflows:i,projectTitle:a,loaded:o}){let s=Ct()??[],c=T(),l=R(`/api/agent-status`,!1,5e3),u=e=>e?i.find(t=>t.slug===e)?.name??e:`workflow`,d=new Map;for(let e of Object.values(l??{}))for(let t of e.working)t.since&&d.set(t.chatId,t.since);let f=[...t.filter(e=>e.busy&&!e.awaitingApproval).map(e=>({key:`c:${e.id}`,owner:Ec(e,r,a),title:Dc(e.title||`new chat`),meta:`working${d.get(e.id)?` · ${Pc(d.get(e.id))}`:``}`,href:Tc(e),tone:`working`})),...e.filter(e=>e.status===`running`).map(e=>({key:`r:${e.id}`,owner:`⚙️ ${u(e.workflow)}`,title:Dc(e.request??``),meta:`running`,href:`/runs/${e.id}`,tone:`working`}))],p=[...t.filter(e=>!e.busy&&!e.awaitingApproval&&Fc(e.updatedAt)&&e.title).map(e=>({key:`c:${e.id}`,at:e.updatedAt,owner:Ec(e,r,a),title:Dc(e.title),meta:Ne(e.updatedAt),href:Tc(e)})),...e.filter(e=>e.status!==`running`&&Fc(e.updatedAt)).map(e=>({key:`r:${e.id}`,at:e.updatedAt,owner:`⚙️ ${u(e.workflow)}`,title:Dc(e.request??``),meta:`${e.status===`ok`?`done`:e.status===`aborted`?`stopped`:`failed`} · ${Ne(e.updatedAt)}`,href:`/runs/${e.id}`})),...n.filter(e=>e.updatedAt&&Fc(e.updatedAt)).map(e=>({key:`k:${e.name}`,at:e.updatedAt,owner:`📚 ${e.name}`,title:`knowledge updated`,meta:Ne(e.updatedAt),href:`/knowledge/${encodeURIComponent(e.name)}`}))].sort((e,t)=>t.at.localeCompare(e.at)).slice(0,12),m=Ot(s,c),h=o&&s.length===0&&f.length===0;return(0,C.jsxs)(`div`,{className:`today flex flex-col gap-3.5`,children:[(0,C.jsxs)(K,{className:`today-section`,title:`needs you`,count:s.length,actions:m&&(0,C.jsxs)(z,{variant:`primary`,size:`sm`,onClick:()=>kt(m),className:`bg-bad text-on-bad hover:bg-bad`,children:[`start `,(0,C.jsx)(w,{name:`arrow_forward`,className:`ms-sm`})]}),children:[s.length===0?(0,C.jsx)(`p`,{className:`m-0 px-[18px] py-4 text-sm text-fg-2`,children:h?`Nothing waiting, nothing running.`:`Nothing is waiting for you.`}):(0,C.jsx)(`div`,{className:`p-1.5`,children:s.map(e=>(0,C.jsx)(q,{className:`today-row waiting`,onClick:()=>kt(e),over:Tt(e.owner),title:e.title,meta:(0,C.jsxs)(`span`,{className:`font-semibold text-bad`,children:[e.kind===`approval`?`needs approval`:e.kind===`question`?`asks you`:`failed`,` · `,Ne(e.since)]})},e.id))}),h&&(0,C.jsx)(`div`,{className:`px-[18px] pb-4`,children:(0,C.jsx)(z,{variant:`primary`,icon:`chat`,href:`/agents/chats`,children:`chat with Ralv`})})]}),f.length>0&&(0,C.jsx)(K,{className:`today-section`,title:`in progress`,children:(0,C.jsx)(`div`,{className:`p-1.5`,children:f.map(e=>(0,C.jsx)(Lc,{r:e},e.key))})}),(0,C.jsx)(K,{className:`today-section`,title:`done today`,children:p.length===0?(0,C.jsx)(`p`,{className:`m-0 px-[18px] py-4 text-sm text-fg-2`,children:`Nothing finished yet today.`}):(0,C.jsx)(`div`,{className:`p-1.5`,children:p.map(e=>(0,C.jsx)(Lc,{r:e},e.key))})})]})}function Lc({r:e}){return(0,C.jsx)(q,{className:`today-row`,href:e.href,over:e.owner,title:e.title,meta:(0,C.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[e.tone===`working`&&(0,C.jsx)(V,{tone:`working`}),e.meta]})})}var Rc=`modulepreload`,zc=function(e){return`/`+e},Bc={},Vc=function(e){return e.pathname.endsWith(`.css`)},Hc=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=zc(t,n);let r=s(t);if(r.href in Bc)return;Bc[r.href]=!0;let i=Vc(r);if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let o=document.createElement(`link`);if(o.rel=i?`stylesheet`:Rc,i||(o.as=`script`),o.crossOrigin=``,o.href=r.href,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),i)return new Promise((e,t)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>t(Error(`Unable to preload CSS for ${r}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Uc=(0,v.lazy)(()=>Hc(()=>import(`./editor-BkGiMzB_.js`).then(e=>({default:e.DocEditor})),__vite__mapDeps([0,1,2,3,4,5,6]))),Wc=()=>Hc(()=>import(`./editor-BkGiMzB_.js`),__vite__mapDeps([0,1,2,3,4,5,6]));function Gc({bundle:e,conceptId:t}){let n=R(`/api/knowledge`,!1),[r,i]=(0,v.useState)([]);(0,v.useEffect)(()=>{n&&i(e=>e.filter(e=>n.bundles.some(t=>t.name===e)))},[n]);let a=(n?.bundles??[]).filter(e=>!r.includes(e.name)),o=e===`new`,s=a.reduce((e,t)=>!e||(t.updatedAt??``)>(e.updatedAt??``)?t:e,void 0);return(0,v.useEffect)(()=>{!e&&s&&M(`/knowledge/${encodeURIComponent(s.name)}`,{replace:!0})},[e,s?.name]),(0,C.jsxs)(`div`,{className:`runs-screen`,children:[(0,C.jsxs)(`aside`,{className:`runs-side`,children:[(0,C.jsx)(ft,{title:`bundles`,action:(0,C.jsx)(z,{size:`sm`,variant:`quiet`,icon:`add`,href:`/knowledge/new`,children:`new`})}),(0,C.jsxs)(mt,{children:[a.map(t=>(0,C.jsx)(q,{href:`/knowledge/${encodeURIComponent(t.name)}`,active:t.name===e,size:`sm`,leading:(0,C.jsx)(V,{tone:`ok`}),title:t.name,meta:t.concepts,sub:`${t.okfVersion?`okf ${t.okfVersion}`:`okf`}${t.updatedAt?` · ${t.updatedAt.slice(0,10)}`:``}`},t.name)),n&&a.length===0&&(0,C.jsx)(ht,{children:`no bundles yet`})]})]}),(0,C.jsx)(`div`,{className:`runs-main`,children:e&&!o?(0,C.jsx)(Qc,{name:e,conceptId:t,onRemoved:()=>{i(t=>[...t,e]),M(`/knowledge`,{replace:!0})}},e):o||n&&!s?(0,C.jsx)(Kc,{}):(0,C.jsx)(W,{children:`loading…`})})]})}function Kc(){let[e,t]=(0,v.useState)(``),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(!1);async function o(){let t=e.trim();if(!t)return;a(!0),r(``);let n=await(await fetch(`/api/knowledge`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t})})).json();a(!1),n.error?r(n.error):M(`/knowledge/${encodeURIComponent(t)}`)}return(0,C.jsxs)(`div`,{className:`empty-action flex flex-col items-center gap-3 px-4 py-16`,children:[(0,C.jsxs)(`div`,{className:`flex w-full max-w-[520px] gap-2.5`,children:[(0,C.jsx)(J,{className:`flex-1 font-mono text-sm`,value:e,placeholder:`bundle name, e.g. customer-support`,"aria-label":`bundle name`,onChange:e=>t(e.target.value),onKeyDown:e=>e.key===`Enter`&&void o(),autoFocus:!0}),(0,C.jsx)(z,{variant:`primary`,icon:`add`,busy:i,disabled:!e.trim(),onClick:o,children:i?`creating…`:`new bundle`})]}),n&&(0,C.jsx)(G,{tone:`bad`,children:n})]})}function qc({tier:e}){return(0,C.jsx)(H,{tone:e===`human-reviewed`?`ok`:e===`machine-confirmed`?`accent`:`neutral`,children:e})}var Jc=e=>e===`deprecated`||e===`stale`?`bad`:e===`draft`?`accent`:`neutral`,Yc=()=>(0,v.useContext)(N)!==null,Xc=`m-0 max-h-[560px] overflow-auto px-[18px] py-3.5 font-mono text-xs leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,Zc=`@activity`;function Qc({name:e,conceptId:t,onRemoved:n}){let r=R(`/api/knowledge/${encodeURIComponent(e)}`,!1),i=Yc(),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``);async function l(){let t=await fetch(`/api/knowledge/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(()=>null),r=await t?.json().catch(()=>({}));if(!t?.ok){c(r?.error??`delete failed`),o(!1);return}n?n():M(`/knowledge`,{replace:!0})}if(!r)return(0,C.jsx)(W,{children:`loading…`});if(`error`in r)return(0,C.jsx)(W,{icon:`menu_book`,children:`bundle not found`});let u=t===Zc?`activity`:`pages`,d=r.concepts,f=u===`pages`?t&&d.some(e=>e.id===t)?t:d[0]?.id:void 0,p=`/knowledge/${encodeURIComponent(e)}`;return(0,C.jsxs)(`div`,{className:b(`agent-view @container flex flex-col`,i?`gap-2.5`:`gap-4`),children:[(0,C.jsxs)(`div`,{className:b(`flex flex-wrap items-center gap-x-4 gap-y-2`,i?`mb-0.5`:`mx-0.5 mt-1 mb-2`),children:[(0,C.jsx)(We,{size:i?`md`:`lg`,children:e}),(0,C.jsxs)(`span`,{className:b(`text-fg-2`,i?`text-[12.5px]`:`text-base`),children:[d.length,` pages`]}),(0,C.jsx)(et,{bare:!0,className:`self-end`,label:`bundle views`,value:u,items:[{id:`pages`,href:p,label:`pages`},{id:`activity`,href:`${p}/${Zc}`,label:`activity`}]}),(0,C.jsx)(`span`,{className:`flex-1`}),!i&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(z,{size:`sm`,variant:`quiet`,icon:`picture_as_pdf`,onClick:()=>void Wo(e),children:`export PDF`}),a?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(z,{size:`sm`,variant:`danger`,icon:`delete`,onClick:()=>void l(),children:`move to trash`}),(0,C.jsx)(z,{size:`sm`,variant:`quiet`,onClick:()=>o(!1),children:`cancel`})]}):(0,C.jsx)(z,{size:`sm`,variant:`quiet`,icon:`delete`,onClick:()=>o(!0),title:`Move the bundle to the trash`,children:`delete`}),(0,C.jsx)(z,{variant:`primary`,onClick:()=>void Ma(`claude`,{kind:`knowledge`,bundle:e}),children:`curate in chat`})]})]}),s&&(0,C.jsx)(G,{tone:`bad`,children:s}),u===`activity`?r.log?(0,C.jsx)(tl,{name:e,log:r.log}):(0,C.jsx)(K,{children:(0,C.jsx)(`p`,{className:`m-0 px-[18px] py-3 text-sm text-fg-2`,children:`no activity yet`})}):d.length===0?(0,C.jsx)(K,{children:(0,C.jsxs)(`p`,{className:`m-0 px-[18px] py-3 text-sm text-fg-2`,children:[`No pages yet — start a chat to author some, or write one with`,` `,(0,C.jsxs)(`code`,{children:[`kraftwerk knowledge put `,e,`/<path>`]}),`.`]})}):(0,C.jsxs)(`div`,{className:b(`grid items-start`,i?`grid-cols-[170px_minmax(0,1fr)] gap-3.5 @max-[560px]:grid-cols-1`:`grid-cols-[260px_minmax(0,1fr)] gap-6 max-[1100px]:grid-cols-1`),children:[(0,C.jsx)(`aside`,{className:b(`flex flex-col gap-0.5 overflow-y-auto border-r border-line`,i?`sticky top-0 max-h-[calc(100vh-var(--topbar-h)-160px)] pr-2 pb-1.5 @max-[560px]:static @max-[560px]:max-h-[200px] @max-[560px]:border-r-0 @max-[560px]:pr-0`:`sticky top-[calc(var(--topbar-h)+18px)] max-h-[calc(100vh-var(--topbar-h)-36px)] py-1.5 pr-3 max-[1100px]:static max-[1100px]:max-h-none max-[1100px]:border-r-0 max-[1100px]:pr-0`),children:(0,C.jsx)(rl,{concepts:d,base:p,selected:f})}),(0,C.jsx)(`div`,{className:`min-w-0`,children:f&&(0,C.jsx)(al,{bundle:e,conceptId:f},f)})]})]})}function $c(e){let t=[];for(let n of e.split(`
215
+ `).length+2)),value:n.content,spellCheck:!1,onChange:e=>r({...n,content:e.target.value})})}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,C.jsx)(z,{variant:`primary`,busy:i,disabled:!n.name.trim(),onClick:()=>void l(),children:i?`saving…`:`save`}),(0,C.jsx)(z,{variant:`quiet`,disabled:i,onClick:()=>r(null),children:`cancel`})]})]}),o&&(0,C.jsx)(`div`,{className:`px-[18px] pb-3`,children:(0,C.jsx)(G,{tone:`bad`,children:o})})]})}function vs({slug:e}){let t=R(`/api/agents/${encodeURIComponent(e)}/routines`,!1)?.routines??[],[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``);async function c(t){a(``);let n=await(await fetch(`/api/agents/${encodeURIComponent(e)}/routines`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})).json();return!n.error||(a(n.error),!1)}async function l(t){s(t),a(``);let n=await(await fetch(`/api/agents/${encodeURIComponent(e)}/routines/${encodeURIComponent(t)}/run`,{method:`POST`})).json();s(``),n.error?a(n.error):n.chatId&&M(`/agents/${encodeURIComponent(e)}/chat/${n.chatId}`)}async function u(t){window.confirm(`Delete the scheduled prompt "${t}"?`)&&await fetch(`/api/agents/${encodeURIComponent(e)}/routines/${encodeURIComponent(t)}`,{method:`DELETE`}).catch(()=>{})}return(0,C.jsxs)(K,{title:`schedule — prompts that run on their own`,actions:!n&&(0,C.jsx)(z,{size:`sm`,icon:`add`,onClick:()=>r({name:``,schedule:`0 9 * * 1-5`,prompt:``,enabled:!0}),children:`schedule a prompt`}),children:[t.length===0&&!n&&(0,C.jsx)(U,{className:`px-[18px] py-3 text-xs`,children:`none — a routine messages this agent on a schedule (cron, server local time) and each run opens a new session with the result.`}),t.length>0&&(0,C.jsx)(Xe,{children:t.map(t=>(0,C.jsx)(Ye,{icon:`schedule`,title:(0,C.jsxs)(C.Fragment,{children:[t.name,t.lastError&&(0,C.jsx)(`span`,{title:t.lastError,children:(0,C.jsx)(H,{tone:`bad`,children:`error`})}),t.awaitingApproval&&t.lastChatId&&(0,C.jsx)(H,{href:`/agents/${encodeURIComponent(e)}/chat/${t.lastChatId}`,tone:`bad`,title:`the last run asked for a permission nobody has answered yet`,children:`needs approval`})]}),action:(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(z,{size:`sm`,icon:`play_arrow`,busy:o===t.id,onClick:()=>l(t.id),children:o===t.id?`starting…`:`run`}),(0,C.jsx)(z,{size:`sm`,variant:`quiet`,onClick:()=>r({id:t.id,name:t.name,schedule:t.schedule,prompt:t.prompt,enabled:t.enabled}),children:`edit`}),(0,C.jsx)(z,{size:`sm`,variant:`danger`,onClick:()=>void u(t.id),children:`delete`}),(0,C.jsx)(ut,{checked:t.enabled,label:t.enabled?`enabled — click to pause`:`paused — click to enable`,onChange:()=>void c({id:t.id,name:t.name,schedule:t.schedule,prompt:t.prompt,enabled:!t.enabled})})]}),children:(0,C.jsxs)(`span`,{className:Xo,children:[(0,C.jsx)(`code`,{children:t.schedule}),t.enabled?t.nextRunAt?` · next ${Me(t.nextRunAt)}`:``:` · paused`,` · `,t.lastChatId?(0,C.jsxs)(P,{href:`/agents/${encodeURIComponent(e)}/chat/${t.lastChatId}`,children:[`last run `,Me(t.lastRunAt)]}):`never ran`]})},t.id))}),n&&(0,C.jsxs)(ot,{className:`max-w-[680px]`,children:[(0,C.jsxs)(st,{children:[(0,C.jsx)(Y,{label:`name`,className:`flex-1`,children:(0,C.jsx)(J,{value:n.name,placeholder:`e.g. Morning report`,onChange:e=>r({...n,name:e.target.value})})}),(0,C.jsx)(Y,{label:`schedule (cron)`,className:`w-[200px] max-[900px]:w-auto`,children:(0,C.jsx)(J,{className:`font-mono`,value:n.schedule,placeholder:`0 9 * * 1-5`,onChange:e=>r({...n,schedule:e.target.value})})}),(0,C.jsxs)(`label`,{className:`flex h-9 cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,C.jsx)(`input`,{type:`checkbox`,className:`accent-accent`,checked:n.enabled,onChange:e=>r({...n,enabled:e.target.checked})}),`enabled`]})]}),(0,C.jsx)(Y,{label:`prompt — what to ask this agent on each run`,children:(0,C.jsx)(it,{rows:5,value:n.prompt,placeholder:`Check ... and summarize what changed.`,onChange:e=>r({...n,prompt:e.target.value})})}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,C.jsx)(z,{variant:`primary`,disabled:!n.name.trim()||!n.prompt.trim(),onClick:async()=>{await c(n)&&r(null)},children:n.id?`save`:`add to the schedule`}),(0,C.jsx)(z,{variant:`quiet`,onClick:()=>(r(null),a(``)),children:`cancel`})]})]}),i&&(0,C.jsx)(`div`,{className:`px-[18px] pb-3`,children:(0,C.jsx)(G,{tone:`bad`,children:i})})]})}function ys({slug:e}){let[t,n]=(0,v.useState)(e?null:f()),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1),s=R(`/api/workflows`,!1)?.workflows??[],c=R(`/api/knowledge`,!1)?.bundles??[],l=me(),u=R(l.vibeables?`/api/vibeables`:``,!1)?.vibeables??[],d=R(`/api/skills`,!1)?.skills??[];(0,v.useEffect)(()=>{e&&fetch(`/api/agents/${encodeURIComponent(e)}`).then(e=>e.ok?e.json():Promise.reject()).then(e=>n({name:e.name,emoji:e.emoji,description:e.description??``,harness:e.harness,model:e.model??``,effort:e.effort??``,group:e.group??``,system:e.system,workflows:e.workflows,knowledge:e.knowledge??[],vibeables:e.vibeables??[],skillsAll:e.skills===void 0,skills:e.skills??[]})).catch(()=>i(`agent not found`))},[e]);function f(){return{name:``,emoji:`🤖`,description:``,harness:`claude`,model:``,effort:``,group:``,system:``,workflows:[],knowledge:[],vibeables:[],skillsAll:!0,skills:[]}}async function p(){if(!t)return;o(!0),i(``);let n=await(await fetch(e?`/api/agents/${encodeURIComponent(e)}`:`/api/agents`,{method:e?`PUT`:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({...t,skills:t.skillsAll?void 0:t.skills})})).json();o(!1),n.error?i(n.error):M(`/agents/${encodeURIComponent(n.slug)}/info`)}async function m(){e&&window.confirm(`Move agent "${e}" to the trash?`)&&(await fetch(`/api/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(()=>{}),M(`/agents`))}if(!t)return(0,C.jsx)(W,{children:r||`loading…`});let h=e=>n({...t,...e}),g=(e,n,r)=>h({[e]:r?[...t[e],n]:t[e].filter(e=>e!==n)});return(0,C.jsxs)(Ke,{width:`narrow`,children:[(0,C.jsx)(We,{children:e?`edit ${e}`:`new agent`}),(0,C.jsx)(K,{children:(0,C.jsxs)(ot,{className:`max-w-[680px]`,children:[(0,C.jsxs)(st,{children:[(0,C.jsx)(Y,{label:`name`,className:`flex-1`,children:(0,C.jsx)(J,{value:t.name,placeholder:`e.g. Max`,onChange:e=>h({name:e.target.value})})}),(0,C.jsx)(Y,{label:`emoji`,className:`w-[90px] max-[900px]:w-auto`,children:(0,C.jsx)(J,{value:t.emoji,onChange:e=>h({emoji:e.target.value})})})]}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Yo.map(e=>(0,C.jsx)(`button`,{type:`button`,"aria-pressed":t.emoji===e,className:b(`cursor-pointer rounded-xl border px-2.5 py-1.5 text-base transition-colors`,t.emoji===e?`border-transparent bg-accent-soft`:`border-line bg-transparent hover:bg-surface-2`),onClick:()=>h({emoji:e}),children:e},e))}),(0,C.jsxs)(st,{children:[(0,C.jsx)(Y,{label:`description`,className:`flex-1`,children:(0,C.jsx)(J,{value:t.description,placeholder:`one line: what this agent is for`,onChange:e=>h({description:e.target.value})})}),(0,C.jsx)(Y,{label:`group`,className:`w-[180px] max-[900px]:w-auto`,children:(0,C.jsx)(J,{value:t.group,placeholder:`none`,onChange:e=>h({group:e.target.value})})})]}),(0,C.jsxs)(st,{children:[(0,C.jsx)(Y,{label:`harness`,className:`w-[140px] max-[900px]:w-auto`,children:(0,C.jsxs)(at,{value:t.harness,onChange:e=>h({harness:e.target.value}),children:[(0,C.jsx)(`option`,{value:`claude`,children:`claude`}),(0,C.jsx)(`option`,{value:`codex`,children:`codex`}),(0,C.jsx)(`option`,{value:`pi`,children:`pi`})]})}),(0,C.jsx)(Y,{label:`model`,className:`flex-1`,children:(0,C.jsx)(J,{className:`font-mono`,value:t.model,placeholder:`harness default — e.g. sonnet, gpt-5.6-sol`,onChange:e=>h({model:e.target.value})})}),(0,C.jsx)(Y,{label:`effort`,className:`w-[140px] max-[900px]:w-auto`,children:(0,C.jsx)(at,{value:t.effort,onChange:e=>h({effort:e.target.value}),children:Fe.map(e=>(0,C.jsx)(`option`,{value:e,children:e||`default`},e))})})]}),(0,C.jsx)(Y,{label:`system prompt — the agent's role`,children:(0,C.jsx)(it,{className:$o,rows:10,value:t.system,placeholder:`You are the ... for this project. Your job is ...`,onChange:e=>h({system:e.target.value})})}),(0,C.jsxs)(bs,{label:`connected workflows — autoloaded into the agent's context; it can run them`,children:[s.map(e=>(0,C.jsx)(ct,{checked:t.workflows.includes(e.slug),onChange:t=>g(`workflows`,e.slug,t),hint:e.description,mono:!0,children:e.slug},e.slug)),s.length===0&&(0,C.jsx)(U,{className:`py-1.5 px-0`,children:`no workflows in this project`})]}),(0,C.jsxs)(bs,{label:`connected knowledge — OKF bundles the agent consults and maintains`,children:[c.map(e=>(0,C.jsx)(ct,{checked:t.knowledge.includes(e.name),onChange:t=>g(`knowledge`,e.name,t),hint:`${e.concepts} concepts`,mono:!0,children:e.name},e.name)),c.length===0&&(0,C.jsx)(U,{className:`py-1.5 px-0`,children:`no knowledge bundles in this project`})]}),(l.vibeables||t.vibeables.length>0)&&(0,C.jsxs)(bs,{label:`apps — small apps the agent builds and maintains`,linkKind:`vibeables`,children:[u.map(e=>(0,C.jsx)(ct,{checked:t.vibeables.includes(e.slug),onChange:t=>g(`vibeables`,e.slug,t),hint:e.dev?`dev`:`static`,mono:!0,children:e.slug},e.slug)),t.vibeables.filter(e=>!u.some(t=>t.slug===e)).map(e=>(0,C.jsx)(ct,{checked:!0,onChange:()=>g(`vibeables`,e,!1),hint:`not found in this workspace`,mono:!0,children:e},e)),!l.vibeables&&(0,C.jsx)(U,{className:`py-1.5 px-0`,children:`vibeables are off in this workspace's settings`}),l.vibeables&&u.length===0&&(0,C.jsx)(U,{className:`py-1.5 px-0`,children:`no vibeables in this workspace yet`})]}),(0,C.jsxs)(bs,{label:`connected skills — workspace skill packages (see the skills tab); invoked with /name in sessions`,children:[(0,C.jsx)(ct,{checked:t.skillsAll,onChange:e=>h({skillsAll:e}),hint:`every discovered skill, including future ones`,mono:!0,children:`all skills`}),!t.skillsAll&&d.map(e=>(0,C.jsx)(ct,{checked:t.skills.includes(e.name),onChange:t=>g(`skills`,e.name,t),hint:e.description,mono:!0,children:`/${e.name}`},e.name)),!t.skillsAll&&d.length===0&&(0,C.jsx)(U,{className:`py-1.5 px-0`,children:`no skills found (.claude/skills, project or user)`})]}),r&&(0,C.jsx)(G,{tone:`bad`,children:r}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,C.jsx)(z,{variant:`primary`,busy:a,disabled:!t.name.trim(),onClick:p,children:a?`saving…`:e?`save`:`create`}),(0,C.jsx)(`span`,{className:`flex-1`}),e&&(0,C.jsx)(z,{variant:`danger`,icon:`delete`,onClick:m,children:`delete agent`})]})]})})]})}function bs({label:e,linkKind:t,children:n}){return(0,C.jsxs)(`div`,{className:`flex flex-col gap-1.5`,"data-link-kind":t,children:[(0,C.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e}),(0,C.jsx)(Qo,{children:n})]})}function xs(e){if(!ie(e))return null;let t=e.split(`/`).filter(Boolean),n=decodeURIComponent(t[1]),r=t[0]===`agents`||t[0]===`team`;return n===`new`?t[0]===`projects`?(0,C.jsx)(Q,{},`new-project`):r?(0,C.jsx)(ys,{},`new-agent`):(0,C.jsx)(Sa,{},`new-channel`):t[0]===`projects`&&t[2]===`info`?(0,C.jsx)(Ro,{slug:n,onChanged:async()=>{}},n):r&&t[2]===`info`?(0,C.jsx)(hs,{slug:n},n):r&&t[2]===`edit`?(0,C.jsx)(ys,{slug:n},n):t[0]===`channels`&&t[2]===`edit`?(0,C.jsx)(Sa,{slug:n},n):null}function Ss({back:e,children:t}){let n=()=>M(e);return(0,v.useEffect)(()=>{let e=e=>{e.key!==`Escape`||e.defaultPrevented||document.querySelector(`.palette-backdrop`)||(e.preventDefault(),n())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}),(0,C.jsx)(`div`,{className:`fixed inset-0 z-40 flex animate-fade items-start justify-center bg-black/38 px-4 pt-[6vh] pb-4 max-[800px]:p-0`,onMouseDown:n,children:(0,C.jsxs)(`div`,{className:`edit-modal relative max-h-[88dvh] w-[min(960px,100%)] animate-modal overflow-y-auto rounded-card border border-line bg-surface shadow-modal max-[800px]:max-h-dvh max-[800px]:rounded-none`,role:`dialog`,"aria-label":`edit`,onMouseDown:e=>e.stopPropagation(),children:[(0,C.jsx)(B,{icon:`close`,label:`close (esc)`,className:`absolute top-3 right-3 z-1 rounded-full`,onClick:n}),(0,C.jsx)(`div`,{className:`runs-main min-w-0 pt-[18px] pr-12 pb-10 pl-6`,children:t})]})})}function Cs({runId:e,decision:t}){let{request:n,answer:r}=t,[i,a]=(0,v.useState)(n.options.length===1?n.options[0].value:null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(null),f=e=>n.options.find(t=>t.value===e)?.label??e;if(r)return(0,C.jsx)(`section`,{className:b(ws,`decision-panel is-decided`),"aria-label":`decision`,children:(0,C.jsxs)(`div`,{className:`flex flex-col gap-3 px-5 py-4`,children:[(0,C.jsx)(`div`,{className:Ts,children:n.title??`Decision`}),(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-base`,children:[(0,C.jsx)(H,{tone:`ok`,children:f(r.decision)}),r.note&&(0,C.jsxs)(`span`,{className:`text-fg-2`,children:[`“`,r.note,`”`]}),r.decidedAt&&(0,C.jsx)(`span`,{className:`text-xs tabular-nums text-fg-2`,children:Me(r.decidedAt)})]})]})});let p=!!i&&!c&&(n.note!==`required`||!!o.trim());async function m(){if(!p)return;l(!0),d(null);let t=await fetch(`/api/runs/${encodeURIComponent(e)}/decision`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({decision:i,note:o.trim()})}).catch(()=>null);t?.ok||(d((await t?.json().catch(()=>null))?.error??`could not save the decision`),l(!1))}return(0,C.jsx)(`section`,{className:b(ws,`decision-panel`),"aria-label":`decision needed`,children:(0,C.jsxs)(`div`,{className:`flex flex-col gap-3 px-5 py-4`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,C.jsx)(V,{tone:`working`}),(0,C.jsx)(`div`,{className:Ts,children:n.title??`This run needs your decision`})]}),n.prompt&&(0,C.jsx)(`p`,{className:`m-0 max-w-[80ch] text-base text-fg-2`,children:n.prompt}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-2 self-start`,role:`radiogroup`,"aria-label":`options`,children:n.options.map(e=>(0,C.jsx)(z,{role:`radio`,"aria-checked":i===e.value,variant:i===e.value?`primary`:`secondary`,onClick:()=>a(e.value),children:e.label??e.value},e.value))}),n.note!==!1&&(0,C.jsx)(J,{value:o,placeholder:n.note===`required`?`Note (required)`:`Note`,"aria-label":`note`,className:`max-w-[60ch]`,onChange:e=>s(e.target.value),onKeyDown:e=>e.key===`Enter`&&m()}),u&&(0,C.jsx)(G,{tone:`bad`,children:u}),(0,C.jsx)(`div`,{className:`flex gap-2`,children:(0,C.jsx)(z,{variant:`primary`,onClick:m,disabled:!p,busy:c,children:c?`Saving…`:`Submit decision`})})]})})}var ws=`mb-[18px] overflow-hidden rounded-card border border-line bg-surface`,Ts=`text-[16px] font-medium text-fg`;function Es(e){return e===`ok`?`ok`:e===`running`?`working`:e===`failed`||e===`blocked`?`bad`:`idle`}function Ds({status:e}){return(0,C.jsx)(`span`,{"data-ui":`status`,"data-status":e,className:`inline-flex`,children:(0,C.jsx)(H,{tone:e===`ok`?`ok`:e===`failed`||e===`blocked`?`bad`:e===`running`?`accent`:`neutral`,children:e})})}function Os(){return(0,C.jsx)(`span`,{"data-ui":`decision`,className:`inline-flex`,children:(0,C.jsx)(H,{tone:`accent`,children:`decision needed`})})}function ks({label:e,children:t,className:n}){return(0,C.jsxs)(`div`,{className:n,children:[(0,C.jsx)(He,{className:`mb-px block`,children:e}),(0,C.jsx)(`div`,{className:`font-mono text-md font-medium tabular-nums text-fg`,children:t})]})}var As=`mb-[22px] flex flex-wrap gap-[26px]`;function js({id:e,workflow:t}){let n=R(`/api/runs`,!0),r=n?.runs??[],[i,a]=(0,v.useState)(t??``),o=(0,v.useMemo)(()=>{let e=i.trim().toLowerCase();return e?r.filter(t=>[t.workflow,t.request,t.id].some(t=>t?.toLowerCase().includes(e))):r},[r,i]);return(0,C.jsxs)(`div`,{className:`runs-screen`,children:[(0,C.jsxs)(`aside`,{className:`runs-side`,children:[(0,C.jsx)(ft,{title:`runs`,back:{href:`/workflows`,label:`back to workflows`},count:i?`${o.length} / ${r.length}`:r.length}),(0,C.jsx)(pt,{icon:`filter_list`,value:i,placeholder:`filter by workflow or request`,"aria-label":`filter runs`,onChange:e=>a(e.target.value)}),(0,C.jsxs)(mt,{label:`runs list`,children:[o.map(t=>(0,C.jsx)(Ms,{r:t,active:t.id===e},t.id)),n&&r.length===0&&(0,C.jsx)(ht,{children:`no runs yet`}),r.length>0&&o.length===0&&(0,C.jsxs)(ht,{children:[`no run matches “`,i,`”`]})]})]}),(0,C.jsx)(`div`,{className:`runs-main`,children:(0,C.jsx)(Ns,{id:e},e)})]})}function Ms({r:e,active:t}){return(0,C.jsx)(q,{href:`/runs/${e.id}`,active:t,size:`sm`,leading:(0,C.jsx)(V,{tone:Es(e.status),title:e.status}),title:e.workflow??`unknown`,meta:Me(e.startedAt),sub:(0,C.jsxs)(`span`,{className:`flex gap-2`,children:[(0,C.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.request,children:e.status===`running`&&e.currentPhase?`${e.currentPhase}`:e.request??``}),(0,C.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:e.status===`running`?(0,C.jsx)(Pe,{since:e.startedAt}):Oe(e.durationMs)})]})})}function Ns({id:e}){let t=R(`/api/runs/${e}`,!0),n=t?.status===`running`,[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(null),l=ue();if(!t)return(0,C.jsx)(W,{children:`loading…`});let u=t.files.some(e=>e.name===`runner.json`),d=r??(n?`run`:`artifacts`),f=l?t.files.length:t.files.filter(e=>!Bs(e.name)).length;async function p(){o(!0),c(null);let t=await fetch(`/api/runs/${e}/stop`,{method:`POST`}).catch(()=>null);t?.ok||(o(!1),c((await t?.json().catch(()=>null))?.error??`stop failed`))}async function m(){if(!window.confirm(`Move run ${e} to the trash?`))return;c(null);let n=await fetch(`/api/runs/${e}`,{method:`DELETE`}).catch(()=>null);if(n?.ok){M(t?.workflow?`/workflows/${encodeURIComponent(t.workflow)}`:`/workflows`);return}c((await n?.json().catch(()=>null))?.error??`remove failed`)}return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`header`,{className:`mb-1.5 flex flex-wrap items-center gap-x-4 gap-y-2.5`,children:[(0,C.jsx)(V,{tone:Es(t.status),title:t.status}),(0,C.jsx)(We,{size:`lg`,children:t.workflow?(0,C.jsx)(P,{href:`/workflows/${encodeURIComponent(t.workflow)}`,title:`open workflow`,className:`text-inherit no-underline hover:text-accent`,children:t.workflow}):`unknown workflow`}),(0,C.jsx)(Ds,{status:t.status}),u&&(0,C.jsxs)(H,{children:[(0,C.jsx)(w,{name:`science`,className:`ms-sm mr-1`}),` sandbox`]}),(0,C.jsx)(`span`,{className:`font-mono text-xs text-fg-2`,children:e.replace(/^run-/,``)}),n?(0,C.jsx)(z,{size:`sm`,variant:`danger`,icon:`stop`,busy:a,onClick:p,children:a?`stopping…`:`stop`}):(0,C.jsx)(z,{size:`sm`,variant:`danger`,icon:`delete`,onClick:m,title:`delete this run's folder`,children:`remove`}),s&&(0,C.jsx)(`span`,{className:`text-xs text-bad`,children:s}),(0,C.jsx)(`span`,{className:`flex-1`}),(0,C.jsx)(z,{size:`sm`,variant:`quiet`,title:`chat with an agent about this run`,onClick:()=>void Ma(`claude`,{kind:`run`,runId:e}),children:`⌬ discuss`}),(0,C.jsx)(et,{className:`border-b-0 px-0`,label:`run sections`,value:d,onChange:i,items:[{id:`run`,label:`run`},{id:`artifacts`,label:`artifacts`,count:f}]})]}),t.request&&(0,C.jsx)(`p`,{className:`mb-5 max-w-[90ch] text-base text-fg-2`,children:t.request}),d===`run`?(0,C.jsx)(Ps,{run:t,live:n}):(0,C.jsx)(Hs,{id:e,files:t.files,live:n})]})}function Ps({run:e,live:t}){return(0,C.jsxs)(`div`,{className:`max-w-[1080px]`,children:[e.decision&&(0,C.jsx)(Cs,{runId:e.id,decision:e.decision}),(0,C.jsxs)(`div`,{className:As,children:[(0,C.jsxs)(ks,{label:`phases`,children:[e.phasesDone,e.phasesTotal==null?``:` / ${e.phasesTotal}`]}),(0,C.jsx)(ks,{label:`duration`,children:t?(0,C.jsx)(Pe,{since:e.startedAt}):Oe(e.durationMs)}),(0,C.jsx)(ks,{label:`cost`,children:ke(e.costUsd??Is(e.phases))}),(0,C.jsxs)(ks,{label:`tokens in / out`,children:[Ae(Fs(e.phases,`tokensIn`)),` / `,Ae(Fs(e.phases,`tokensOut`))]})]}),(0,C.jsx)(K,{title:`phase timeline`,actions:t&&(0,C.jsxs)(`span`,{className:`inline-flex items-center gap-[7px] text-2xs text-fg-2`,children:[(0,C.jsx)(V,{tone:`working`}),` live · polling`]}),children:(0,C.jsx)(`div`,{className:`py-1.5`,children:e.phases.map(e=>(0,C.jsx)(Rs,{p:e},e.phase))})})]})}function Fs(e,t){return e.reduce((e,n)=>e+(n[t]??0),0)}function Is(e){return e.reduce((e,t)=>e+(t.costUsd??0),0)}var Ls=`relative border-line/55 [&+&]:border-t before:absolute before:top-0 before:bottom-0 before:w-px before:bg-line last:before:bottom-auto`;function Rs({p:e}){let t=e.gates.filter(e=>!e.passed);return(0,C.jsxs)(`div`,{className:b(Ls,`py-2.5 pr-[18px] pl-[42px] before:left-[23px] first:before:top-4 last:before:h-4`),children:[(0,C.jsx)(`span`,{className:`absolute top-4 left-[19px] z-1 grid`,children:(0,C.jsx)(V,{tone:Es(e.status),title:e.status})}),(0,C.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2.5`,children:[(0,C.jsx)(`span`,{className:`text-base font-medium text-fg`,children:e.phase}),e.kind===`agent`?(0,C.jsxs)(H,{tone:`accent`,children:[e.agent,e.model?` · ${e.model}`:``,e.protocol?` · ${e.protocol}`:``]}):(0,C.jsx)(H,{children:`script`}),e.status===`skipped`&&(0,C.jsx)(Ds,{status:`skipped`}),(0,C.jsxs)(`span`,{className:`ml-auto flex gap-3.5 font-mono text-[11.5px] tabular-nums text-fg-2`,children:[e.attempts>1&&(0,C.jsxs)(`span`,{children:[`att `,e.attempts]}),e.status===`running`?(0,C.jsx)(Pe,{since:e.startedAt}):e.durationMs!=null&&(0,C.jsx)(`span`,{children:Oe(e.durationMs)}),e.kind===`agent`&&e.tokensIn!=null&&(0,C.jsxs)(`span`,{children:[Ae(e.tokensIn),` / `,Ae(e.tokensOut)]}),e.costUsd!=null&&e.costUsd>0&&(0,C.jsx)(`span`,{children:ke(e.costUsd)})]})]}),e.status===`running`&&e.lastActivity&&(0,C.jsxs)(`div`,{className:`mt-[3px] font-mono text-[11.5px] text-accent`,children:[`▸ `,e.lastActivity]}),e.summary&&e.status!==`running`&&(0,C.jsx)(`div`,{className:`mt-[3px] max-w-[72ch] text-[12.5px] text-fg-2`,children:e.summary}),e.gates.length>0&&(0,C.jsx)(`div`,{className:`mt-[5px] flex flex-wrap gap-1.5`,children:e.gates.map(e=>(0,C.jsxs)(`span`,{className:b(`inline-flex items-center gap-[5px] rounded-lg px-2.5 py-0.5 font-mono text-2xs`,e.passed?`bg-ok-soft text-ok`:`bg-bad-soft text-on-bad-soft`),title:e.failure??``,children:[(0,C.jsx)(w,{name:e.passed?`check`:`close`,className:`ms-sm`}),` `,e.gate]},e.gate))}),t.map(e=>(0,C.jsx)(`div`,{className:`mt-1 text-xs text-bad`,children:e.failure},e.gate))]})}var zs=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`]);function Bs(e){return e===`runner.json`||e.endsWith(`.jsonl`)||e.endsWith(`.log`)}function Vs(e){let t=[`report.html`,`recommendation.md`].find(t=>e.some(e=>e.name===t));if(t)return t;let n=e=>{let t=e.split(`.`).pop()?.toLowerCase()??``;return[`html`,`md`,`markdown`,`pdf`].includes(t)||zs.has(t)?0:Bs(e)?2:1},r=null;for(let t of e)(!r||n(t.name)<n(r.name))&&(r=t);return r?.name??null}function Hs({id:e,files:t,live:n}){let[r,i]=(0,v.useState)(null),a=ue(),o=(0,v.useMemo)(()=>a?t:t.filter(e=>!Bs(e.name)),[t,a]);return(0,v.useEffect)(()=>{!a&&r&&Bs(r)&&i(null)},[a,r]),(0,v.useEffect)(()=>{r||o.length===0||i(Vs(o))},[o,r]),(0,C.jsxs)(`div`,{className:`grid h-[calc(100vh-172px)] min-h-[420px] grid-cols-[280px_minmax(0,1fr)] gap-3.5 max-[940px]:h-auto max-[940px]:grid-cols-1`,children:[(0,C.jsx)(K,{title:(0,C.jsxs)(C.Fragment,{children:[`files `,(0,C.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,o.length,`)`]})]}),className:`flex min-h-0 flex-col`,children:(0,C.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto max-[940px]:max-h-60`,children:[o.map(e=>(0,C.jsxs)(`button`,{type:`button`,className:b(`flex w-full cursor-pointer items-center gap-2.5 border-0 border-b border-line/55 px-[18px] py-2 text-left font-mono text-[12.5px] transition-colors last:border-b-0`,r===e.name?`bg-accent-soft text-on-accent-soft`:`bg-transparent text-fg-2 hover:bg-surface-2 hover:text-fg`),onClick:()=>i(e.name),children:[(0,C.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,C.jsx)(`span`,{className:`text-2xs tabular-nums text-fg-2`,children:je(e.size)})]},e.name)),o.length===0&&(0,C.jsx)(U,{className:`px-[18px] py-3`,children:t.length>0?`no result files — raw run files live in expert mode`:`no files yet`})]})}),(0,C.jsx)(K,{title:r??`viewer`,className:`flex min-h-0 flex-col`,actions:r&&(0,C.jsx)(`a`,{className:Us,href:`/api/runs/${e}/file?name=${encodeURIComponent(r)}&raw=1`,target:`_blank`,children:`open raw ↗`}),children:r?(0,C.jsx)(Js,{id:e,name:r,live:n}):(0,C.jsx)(W,{className:`flex-1 justify-center`,children:`select a file`})})]})}var Us=`inline-flex h-7 items-center rounded-control px-2.5 text-sm font-medium text-fg-2 no-underline transition-colors hover:bg-surface-2 hover:text-fg`,Ws=`flex min-h-0 flex-1 flex-col`,Gs=`min-h-0 flex-1`,Ks=`m-0 h-full overflow-auto px-[18px] py-3.5 text-xs leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,qs=`block h-full min-h-[560px] w-full border-0 bg-white`;function Js({id:e,name:t,live:n}){let r=t.split(`.`).pop()?.toLowerCase()??``,i=`/api/runs/${e}/file?name=${encodeURIComponent(t)}&raw=1`;return r===`html`?(0,C.jsx)(`div`,{className:Ws,children:(0,C.jsx)(`div`,{className:Gs,children:(0,C.jsx)(`iframe`,{className:qs,src:i,sandbox:`allow-scripts`,allow:`clipboard-write`,title:t})})}):r===`pdf`?(0,C.jsx)(`div`,{className:Ws,children:(0,C.jsx)(`div`,{className:Gs,children:(0,C.jsx)(`iframe`,{className:qs,src:i,title:t})})}):zs.has(r)?(0,C.jsx)(`div`,{className:Ws,children:(0,C.jsx)(`div`,{className:Gs,children:(0,C.jsx)(`img`,{className:`block max-h-full max-w-full object-contain px-[18px] py-3.5`,src:i,alt:t})})}):r===`md`||r===`markdown`?(0,C.jsx)(Xs,{id:e,name:t,live:n}):(0,C.jsx)(Zs,{id:e,name:t,live:n})}var Ys=`flex items-center gap-3 border-b border-line/55 px-[18px] py-1.5 text-2xs text-fg-2`;function Xs({id:e,name:t,live:n}){let[r,i]=(0,v.useState)(`rendered`),a=R(`/api/runs/${e}/file?name=${encodeURIComponent(t)}`,n),o=(0,v.useMemo)(()=>a?Qi.sanitize(Cr.parse(a.content,{async:!1})):``,[a?.content]);return(0,C.jsxs)(`div`,{className:Ws,children:[(0,C.jsxs)(`div`,{className:Ys,children:[(0,C.jsx)(et,{className:`border-b-0 px-0`,label:`markdown view`,value:r,onChange:i,items:[{id:`rendered`,label:`rendered`},{id:`source`,label:`source`}]}),a?.truncated&&(0,C.jsxs)(`span`,{children:[`large file — showing the last `,je(4e5)]})]}),(0,C.jsx)(`div`,{className:b(Gs,`overflow-auto`),children:a?r===`rendered`?(0,C.jsx)(`div`,{className:`md-body`,dangerouslySetInnerHTML:{__html:o}}):(0,C.jsx)(`pre`,{className:Ks,children:a.content||`(empty)`}):(0,C.jsx)(`pre`,{className:Ks,children:`loading…`})})]})}function Zs({id:e,name:t,live:n}){let r=R(`/api/runs/${e}/file?name=${encodeURIComponent(t)}`,n);return(0,C.jsxs)(`div`,{className:Ws,children:[r?.truncated&&(0,C.jsxs)(`div`,{className:Ys,children:[`large file — showing the last `,je(4e5)]}),(0,C.jsx)(`div`,{className:Gs,children:(0,C.jsx)(`pre`,{className:Ks,children:r?r.content||`(empty)`:`loading…`})})]})}function Qs(){return R(`/api/workflows/any/run`,!1,15e3)}var $s=e=>!!e?.available&&!!e?.image;function ec(e){return e?e.available?e.image?`isolated container per run`:"image missing — run `kraftwerk runner build`":`Docker is not running`:``}async function tc(e,t){let n=await fetch(`/api/workflows/${encodeURIComponent(e)}/run`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);return r.runId}function nc(e,t,n,r){let[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(!0),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null),m=Qs();(0,v.useEffect)(()=>{!i&&n&&a(n)},[n]),(0,v.useEffect)(()=>{m&&!$s(m)&&s(!1)},[m]);let h=!u&&(!t||!!i.trim())&&(!o||$s(m));async function g(){if(h){d(!0),p(null);try{let t=await tc(e,{request:i.trim(),sandbox:o,ssh:c});r?(r(t),d(!1)):M(`/runs/${t}`)}catch(e){p(e.message),d(!1)}}}return{request:i,setRequest:a,sandbox:o,setSandbox:s,ssh:c,setSsh:l,busy:u,error:f,docker:m,canRun:h,launch:g}}function rc({slug:e,usesRequest:t,initialRequest:n,onLaunched:r}){let i=nc(e,t,n,r);return(0,C.jsxs)(`div`,{className:`flex flex-col gap-1 px-5 pt-4 pb-2`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-4 max-[700px]:flex-wrap`,children:[t?(0,C.jsx)(J,{className:`h-11 min-w-0 flex-1 text-md`,value:i.request,placeholder:`Request`,"aria-label":`request`,onChange:e=>i.setRequest(e.target.value),onKeyDown:e=>e.key===`Enter`&&i.launch()}):(0,C.jsx)(`span`,{className:`flex-1 text-base text-fg-2`,children:`This workflow takes no request.`}),(0,C.jsx)(z,{variant:`primary`,icon:`play_arrow`,className:`h-11 px-5 max-[700px]:w-full`,busy:i.busy,onClick:i.launch,disabled:!i.canRun,children:i.busy?`Starting…`:`Run`})]}),(0,C.jsxs)(`div`,{className:`-mx-2 mt-1 flex flex-wrap gap-x-2`,children:[(0,C.jsx)(dt,{label:`Docker sandbox`,hint:ec(i.docker),checked:i.sandbox,onChange:i.setSandbox}),i.sandbox&&(0,C.jsx)(dt,{label:`Forward SSH agent`,hint:`keys and known hosts from this machine`,checked:i.ssh,onChange:i.setSsh})]}),i.error&&(0,C.jsx)(G,{tone:`bad`,children:i.error})]})}var ic=`\0done`,ac=5;function oc(e,t){return e.status===`ok`?ic:e.currentPhase&&t.includes(e.currentPhase)?e.currentPhase:t[0]??ic}var sc=[`var(--accent)`,`#4fb8a8`,`#a78bfa`,`#e5793b`];function cc(e){return e==null?`var(--text-2)`:sc[e%sc.length]}function lc({colour:e,children:t,small:n}){return(0,C.jsx)(`span`,{style:{"--aid":e},className:b(`relative z-1 grid flex-none place-items-center rounded-full border font-mono font-bold tabular-nums`,`border-[color-mix(in_srgb,var(--aid)_55%,var(--line))] bg-[color-mix(in_srgb,var(--aid)_18%,var(--surface-1))] text-[var(--aid)]`,n?`size-[22px] text-2xs`:`mt-px size-[26px] text-[11.5px]`),children:t})}function uc({wf:e,runs:t,agentIdx:n,runsHref:r}){let i=e.steps.map(e=>e.name),a=new Map([...i,ic].map(e=>[e,[]]));for(let e of t)a.get(oc(e,i)).push(e);let o=a.get(ic)??[];return(0,C.jsxs)(`div`,{className:`board flex items-start gap-3 overflow-x-auto px-[18px] pt-3.5 pb-[18px]`,children:[e.steps.map((e,t)=>{let i=a.get(e.name)??[];return(0,C.jsx)(dc,{step:e.name,index:(0,C.jsx)(lc,{small:!0,colour:cc(e.agent?n.get(e.agent)??0:null),children:t+1}),count:i.length,children:(0,C.jsx)(fc,{cards:i,moreHref:r})},e.name)}),(0,C.jsx)(dc,{step:`done`,name:`done`,done:!0,index:(0,C.jsx)(lc,{small:!0,colour:`var(--ok)`,children:`✓`}),count:o.length,children:(0,C.jsx)(fc,{cards:o,moreHref:r})})]})}function dc({step:e,name:t,done:n,index:r,count:i,children:a}){return(0,C.jsxs)(`div`,{className:b(`board-col flex min-w-60 flex-[0_0_240px] flex-col gap-1.5`,n&&`is-done`),"data-step":e,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 px-0.5 pt-0.5 pb-1`,children:[r,(0,C.jsx)(`span`,{className:`board-col-name min-w-0 truncate text-[13.5px] font-medium text-fg`,title:t??e,children:t??e}),(0,C.jsx)(`span`,{className:`board-col-count ml-auto font-mono text-[11.5px] tabular-nums text-fg-2`,children:i})]}),a]})}function fc({cards:e,moreHref:t}){return(0,C.jsxs)(`div`,{className:`flex min-h-14 flex-col gap-2 rounded-xl bg-surface-2/60 p-2`,children:[e.slice(0,ac).map(e=>(0,C.jsx)(pc,{r:e},e.id)),e.length===0&&(0,C.jsx)(`div`,{className:`board-col-empty py-3.5 text-center text-xs text-fg-2`,children:`—`}),e.length>ac&&(0,C.jsxs)(P,{href:t,className:`board-more block p-1.5 text-center text-xs text-fg-2 no-underline hover:text-accent`,children:[`+ `,e.length-ac,` more ↗`]})]})}function pc({r:e}){let t=e.request??e.id.replace(/^run-/,``);return(0,C.jsxs)(P,{href:`/runs/${e.id}`,className:`board-card block rounded-xl border border-line bg-surface px-3 py-2.5 text-inherit no-underline transition-colors hover:bg-surface-2`,children:[(0,C.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,C.jsx)(V,{tone:Es(e.status),title:e.status}),(0,C.jsx)(`span`,{className:`min-w-0 truncate text-[13.5px] font-medium text-fg`,title:t,children:t})]}),(0,C.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2.5 font-mono text-[11.5px] tabular-nums text-fg-2`,children:[(0,C.jsx)(`span`,{children:Me(e.startedAt)}),(0,C.jsx)(`span`,{children:e.status===`running`?(0,C.jsx)(Pe,{since:e.startedAt}):Oe(e.durationMs)}),e.costUsd!=null&&e.costUsd>0&&(0,C.jsx)(`span`,{children:ke(e.costUsd)})]}),(e.awaitingDecision||e.status===`failed`||e.status===`aborted`)&&(0,C.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:[e.awaitingDecision&&(0,C.jsx)(Os,{}),(e.status===`failed`||e.status===`aborted`)&&(0,C.jsx)(Ds,{status:e.status})]})]})}function mc({slug:e,tab:t}){let n=R(`/api/workflows/${encodeURIComponent(e)}`,!1),[r,i]=(0,v.useState)(0),[a,o]=(0,v.useState)(0),s=R(`/api/runs`,a>0||Date.now()-r<2e4);if(!n)return(0,C.jsx)(W,{children:`loading…`});if(n.error)return(0,C.jsxs)(W,{children:[(0,C.jsx)(H,{tone:`bad`,children:`broken workflow`}),(0,C.jsx)(`pre`,{className:`mt-3 text-left`,children:n.error})]});let c=new Map(n.agents.map((e,t)=>[e.id,t%4])),l=(s?.runs??[]).filter(e=>e.workflow===n.name||e.workflow===n.slug),u=`/workflows/${encodeURIComponent(n.slug)}`,d=l.filter(e=>e.status===`running`).length;return d!==a&&o(d),(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`header`,{className:`mb-1.5 flex flex-wrap items-center gap-x-4 gap-y-2.5 in-[.ctx-embed]:mb-3 in-[.ctx-embed]:gap-y-2`,children:[(0,C.jsx)(We,{size:`lg`,className:`in-[.ctx-embed]:text-xl`,children:n.name??n.slug}),(0,C.jsx)(`span`,{className:`min-w-0 font-mono text-xs [overflow-wrap:anywhere] text-fg-2 in-[.ctx-embed]:hidden`,children:n.dir}),(0,C.jsx)(`span`,{className:`flex-1`}),(0,C.jsx)(et,{bare:!0,label:`workflow sections`,value:t,items:[{id:`overview`,href:u,label:`overview`},{id:`details`,href:`${u}/details`,label:`details`},{id:`runs`,href:`${u}/runs`,label:(0,C.jsxs)(C.Fragment,{children:[`runs `,(0,C.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,l.length,`)`]})]})}]})]}),n.description&&(0,C.jsx)(`p`,{className:`mb-5 max-w-[90ch] text-base text-fg-2`,children:n.description}),t===`overview`&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(K,{className:`run-panel mb-[18px]`,children:(0,C.jsx)(rc,{slug:n.slug,usesRequest:n.usesRequest,initialRequest:l[0]?.request,onLaunched:()=>i(Date.now())})}),(0,C.jsx)(K,{title:(0,C.jsxs)(C.Fragment,{children:[`board`,` `,(0,C.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,l.length,` runs`,d>0?`, ${d} live`:``,`)`]})]}),actions:l[0]&&(0,C.jsx)(z,{size:`sm`,variant:`quiet`,href:`${u}/runs`,className:`in-[.ctx-embed]:hidden`,children:`all runs ↗`}),children:(0,C.jsx)(uc,{wf:n,runs:l,agentIdx:c,runsHref:`${u}/runs`})})]}),t===`details`&&(0,C.jsx)(hc,{wf:n,agentIdx:c}),t===`runs`&&(0,C.jsx)(gc,{runs:l})]})}function hc({wf:e,agentIdx:t}){return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:As,children:[(0,C.jsx)(ks,{label:`agents`,children:e.agents.length}),(0,C.jsxs)(ks,{label:`steps`,children:[e.steps.length,` `,(0,C.jsxs)(`span`,{className:`font-normal text-fg-2`,children:[`(`,e.steps.filter(e=>e.kind===`agent`).length,` agent · `,e.steps.filter(e=>e.kind===`script`).length,` script)`]})]}),e.workspace&&(0,C.jsx)(ks,{label:`workspace`,className:`max-w-[420px]`,children:(0,C.jsx)(`span`,{className:`text-[11.5px] font-normal whitespace-pre-wrap text-fg-2`,children:e.workspace})})]}),(0,C.jsx)(K,{title:`agents`,className:`mb-[18px]`,children:(0,C.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(280px,1fr))]`,children:[e.agents.map(e=>(0,C.jsx)(vc,{a:e,idx:t.get(e.id)??0},e.id)),e.agents.length===0&&(0,C.jsx)(U,{className:`px-[18px] py-3`,children:`no agents — script-only workflow`})]})}),(0,C.jsxs)(`div`,{className:`grid items-start gap-[18px] grid-cols-[minmax(430px,5fr)_minmax(360px,4fr)] max-[1100px]:grid-cols-1 in-[.ctx-embed]:grid-cols-1`,children:[(0,C.jsx)(K,{title:`pipeline`,children:(0,C.jsx)(`div`,{className:`pipeline py-2`,children:e.steps.map((e,n)=>(0,C.jsx)(yc,{s:e,i:n,idx:e.agent?t.get(e.agent)??0:null},e.name))})}),(0,C.jsx)(K,{title:(0,C.jsxs)(C.Fragment,{children:[`folder `,(0,C.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,e.files.length,` files)`]})]}),children:(0,C.jsx)(`div`,{className:`max-h-[300px] overflow-auto`,children:e.files.map(e=>(0,C.jsx)(`div`,{className:`truncate border-b border-line/55 px-[18px] py-2 font-mono text-[12.5px] text-fg-2 last:border-b-0`,children:e},e))})})]})]})}function gc({runs:e}){return e.length===0?(0,C.jsx)(W,{children:`no runs of this workflow yet`}):(0,C.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map(e=>{let t=e.phasesTotal??0,n=t>0?Math.round(e.phasesDone/t*100):e.status===`ok`?100:0;return(0,C.jsxs)(P,{href:`/runs/${e.id}`,className:`run-card grid grid-cols-[12px_200px_1fr_auto] items-center gap-x-4 gap-y-2 rounded-card border border-line bg-surface px-5 py-3.5 text-inherit no-underline transition-colors hover:bg-surface-2 max-[900px]:grid-cols-[12px_1fr]`,children:[(0,C.jsx)(V,{tone:Es(e.status),title:e.status}),(0,C.jsx)(`span`,{className:`font-mono text-[12.5px] text-fg-2`,children:e.id.replace(/^run-/,``)}),(0,C.jsx)(`span`,{className:`min-w-0 truncate text-fg`,title:e.request,children:e.status===`running`&&e.currentPhase?e.currentPhase:e.request??``}),(0,C.jsxs)(`span`,{className:`flex items-center gap-3.5 font-mono text-xs tabular-nums text-fg-2 max-[900px]:col-span-2`,children:[e.awaitingDecision&&(0,C.jsx)(Os,{}),(0,C.jsx)(Ds,{status:e.status}),(0,C.jsx)(`span`,{className:`h-1 w-[90px] overflow-hidden rounded-full bg-surface-2`,title:`${e.phasesDone}${t?` / ${t}`:``} steps`,children:(0,C.jsx)(`i`,{className:b(`block h-full rounded-full`,e.status===`ok`?`bg-ok`:e.status===`failed`?`bg-bad`:`bg-accent`),style:{width:`${n}%`}})}),(0,C.jsx)(`span`,{children:e.status===`running`?(0,C.jsx)(Pe,{since:e.startedAt}):Oe(e.durationMs)}),(0,C.jsx)(`span`,{children:ke(e.costUsd)}),(0,C.jsx)(`span`,{children:Me(e.startedAt)})]})]},e.id)})})}var _c=`border-line/55`;function vc({a:e,idx:t}){return(0,C.jsxs)(`div`,{className:b(`agent-card border-r border-b px-[18px] py-3.5`,_c),children:[(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,C.jsx)(`span`,{className:`size-2.5 rounded-full`,style:{background:cc(t)}}),(0,C.jsx)(`b`,{className:`text-base font-medium text-fg`,children:e.name??e.id}),(0,C.jsxs)(`code`,{className:`text-2xs text-fg-2`,children:[`[`,e.id,`]`]}),(0,C.jsx)(`span`,{className:`flex-1`}),(0,C.jsxs)(H,{children:[e.model??`default`,e.effort?` · ${e.effort}`:``,e.protocol===`acp`?` · acp`:``]})]}),e.tools.length>0&&(0,C.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-[5px]`,children:e.tools.map(e=>(0,C.jsx)(`span`,{className:`rounded-md bg-surface-2 px-2 py-px font-mono text-2xs text-fg-2`,children:e},e))}),e.persona&&(0,C.jsx)(`p`,{className:`mt-2 mb-0 text-xs leading-[1.55] whitespace-pre-wrap text-fg-2`,children:e.persona})]})}function yc({s:e,i:t,idx:n}){let r=e.kind===`script`?e.script:e.prompt;return(0,C.jsxs)(`div`,{className:b(`step-node flex gap-3.5 px-[18px] py-3 first:before:top-[18px] last:before:h-[18px] before:left-[31px]`,Ls),children:[(0,C.jsx)(lc,{colour:cc(n),children:t+1}),(0,C.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,C.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2.5`,children:[(0,C.jsx)(`span`,{className:`text-base font-medium text-fg`,children:e.name}),e.kind===`agent`?(0,C.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded-full border px-2 text-2xs font-semibold`,style:{color:cc(n??0),borderColor:`color-mix(in srgb, ${cc(n??0)} 50%, var(--line))`},children:[`agent · `,e.agent]}):(0,C.jsxs)(H,{children:[`script`,e.sourceRef?` · ${e.sourceRef}`:``]})]}),r&&(0,C.jsxs)(`details`,{className:`mt-1.5`,children:[(0,C.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-fg-2 select-none hover:text-accent`,children:e.kind===`agent`?`prompt`:`script`}),(0,C.jsx)(`pre`,{className:`mt-1.5 max-h-[360px] overflow-auto rounded-xl bg-surface-2 px-3 py-2.5 text-[11.5px] leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,children:r})]}),e.gates.length>0&&(0,C.jsx)(`div`,{className:`mt-[5px] flex flex-wrap gap-1.5`,children:e.gates.map(e=>(0,C.jsxs)(`span`,{className:`inline-flex items-center gap-[5px] rounded-lg bg-surface-2 px-2.5 py-0.5 font-mono text-2xs text-fg-2`,children:[`⛨ `,e]},e))})]})]})}function bc(e,t){let n=e.filter(e=>e.workflow===(t.name??t.slug));return{count:n.length,last:n[0]}}function xc(e,t){return`/runs/${e.id}?workflow=${encodeURIComponent(t.name??t.slug)}`}function Sc({slug:e,tab:t}){let n=R(`/api/workflows`,!1),r=R(`/api/runs`,!1),[i,a]=(0,v.useState)(``),o=n?.workflows??[],s=r?.runs??[],c=(0,v.useMemo)(()=>{let e=i.trim().toLowerCase();return e?o.filter(t=>[t.name,t.slug,t.description].some(t=>t?.toLowerCase().includes(e))):o},[o,i]),l=(0,v.useMemo)(()=>{if(o.length!==0)return(o.map(e=>({w:e,last:bc(s,e).last})).filter(e=>!!e.last).sort((e,t)=>(t.last.updatedAt??``).localeCompare(e.last.updatedAt??``))[0]?.w??o[0]).slug},[o,s]),u=!!r;return(0,v.useEffect)(()=>{!e&&l&&u&&M(`/workflows/${encodeURIComponent(l)}`,{replace:!0})},[e,l,u]),(0,C.jsxs)(`div`,{className:`runs-screen workflows-screen`,children:[(0,C.jsxs)(`aside`,{className:`runs-side`,children:[(0,C.jsx)(ft,{title:`workflows`,count:n?o.length:void 0,action:(0,C.jsxs)(z,{size:`sm`,variant:`quiet`,icon:`history`,href:`/runs`,title:`every run of every workflow, newest first`,children:[`runs `,(0,C.jsx)(`span`,{className:`tabular-nums`,children:s.length})]})}),o.length>0&&(0,C.jsx)(pt,{icon:`search`,value:i,placeholder:`search workflows`,"aria-label":`search workflows`,onChange:e=>a(e.target.value)}),(0,C.jsxs)(mt,{children:[c.map(t=>{let n=bc(s,t);return(0,C.jsx)(q,{className:`wf-row`,href:`/workflows/${encodeURIComponent(t.slug)}`,active:t.slug===e,leading:(0,C.jsx)(V,{tone:Es(n.last?.status),title:n.last?.status??`no runs yet`}),title:t.name??t.slug,titleExtra:t.error&&(0,C.jsx)(H,{tone:`bad`,children:`broken`}),meta:n.last&&Ne(n.last.updatedAt),sub:(0,C.jsx)(`span`,{title:t.error??t.description??``,children:t.error??t.description??`${t.agents} agents · ${t.steps} steps`}),subTone:t.error?`bad`:`plain`,actionsAlways:!0,actions:n.last?(0,C.jsxs)(`button`,{type:`button`,className:`wf-runs inline-flex cursor-pointer items-center gap-1 rounded-control border-0 bg-transparent px-1.5 py-0.5 text-2xs tabular-nums text-fg-2 transition-colors hover:bg-surface-2 hover:text-fg`,title:`show the runs of this workflow`,onClick:()=>M(xc(n.last,t)),children:[n.count,` `,n.count===1?`run`:`runs`,` · `,(0,C.jsx)(Ds,{status:n.last.status})]}):(0,C.jsx)(`span`,{className:`wf-runs px-1.5 text-2xs text-fg-2 opacity-80`,children:`no runs yet`})},t.slug)}),n&&o.length>0&&c.length===0&&(0,C.jsxs)(ht,{className:`wf-nomatch`,children:[`no workflow matches “`,i,`”`]}),n&&o.length===0&&(0,C.jsx)(ht,{children:`no workflows yet`})]})]}),(0,C.jsx)(`div`,{className:`runs-main`,children:e?(0,C.jsx)(mc,{slug:e,tab:t},e):n&&o.length===0?(0,C.jsxs)(W,{icon:`account_tree`,children:[`No workflows found — expected `,(0,C.jsx)(`code`,{children:`src/workflows/`}),` or `,(0,C.jsx)(`code`,{children:`workflows/`}),` next to the output folder.`]}):(0,C.jsx)(W,{children:`loading…`})})]})}var Cc=e=>e===`ok`?`ok`:e===`running`?`running`:e===`aborted`?`aborted`:`failed`,wc=e=>e===`ok`?`done`:e===`running`?`working`:e===`aborted`?`stopped`:`failed`;function Tc(e){return e.scope.kind===`channel`?`/channels/${e.scope.slug}`:e.scope.kind===`project`?`/projects/${e.scope.slug}/chat/${e.id}`:e.scope.kind===`agent`?`/agents/${e.scope.slug}/chat/${e.id}`:`/agents/chats/${e.id}`}function Ec(e,t,n){switch(e.scope.kind){case`agent`:{let n=e.scope.slug,r=t.find(e=>e.slug===n);return r?`${r.emoji||`🤖`} ${r.name}`:n}case`project`:return`📁 ${n(e.scope.slug)}`;case`channel`:return e.project?`📁 ${n(e.project)} · #${e.scope.slug}`:`#${e.scope.slug}`;case`run`:return`⚙️ run ${e.scope.runId}`;case`knowledge`:return e.scope.bundle?`📚 ${e.scope.bundle}`:`📚 knowledge`;default:return`🎩 Ralv`}}function Dc(e){return e.length>64?`${e.slice(0,46)}…${e.slice(-14)}`:e}function Oc(){let e=R(`/api/runs`,!1),t=R(`/api/chats`,!1),n=R(`/api/knowledge`,!1),r=R(`/api/agents`,!1),i=R(`/api/workflows`,!1),a=R(`/api/skills`,!1),[o,s]=(0,v.useState)(`all`),c=ue(),l=R(`/api/projects`,!1,3e4),u=e=>l?.projects.find(t=>t.slug===e)?.title??e,d=e?.runs??[],f=t?.chats??[],p=n?.bundles??[],m=(a?.skills??[]).filter(e=>e.source===`workspace`),h=[[i?.workflows.length,`workflows`,`/workflows`],[e?d.length:void 0,`runs`,`/runs`],[n?p.length:void 0,`bundles`,`/knowledge`],[a?m.length:void 0,`skills`,`/skills`],[t?f.length:void 0,`chats`,`/agents/chats`]],g=d.filter(e=>e.status===`failed`&&Date.now()-Date.parse(e.updatedAt)<864e5);return(0,C.jsxs)(`div`,{className:`w-full px-7 pt-6 pb-10`,children:[(0,C.jsx)(Ic,{runs:d,chats:f,bundles:p,agents:r?.agents??[],workflows:i?.workflows??[],projectTitle:u,loaded:!!e&&!!t}),c&&(0,C.jsx)(`div`,{className:`mx-0.5 mt-3.5 mb-3 flex flex-wrap justify-end gap-[18px] text-xs text-fg-2`,children:h.map(([e,t,n])=>(0,C.jsxs)(P,{href:n,className:`group/mini text-inherit no-underline hover:text-accent hover:underline`,children:[(0,C.jsx)(`b`,{className:`font-semibold tabular-nums text-fg group-hover/mini:text-accent`,children:e??`…`}),` `,t]},t))}),c&&g.length>0&&o!==`failed`&&(0,C.jsxs)(`button`,{type:`button`,className:`mb-3.5 flex w-full cursor-pointer items-center gap-2 rounded-xl border border-bad/40 bg-bad-soft px-3.5 py-[9px] text-left text-[12.5px] text-on-bad-soft hover:brightness-104`,onClick:()=>s(`failed`),children:[`⚠ `,g.length,` run`,g.length===1?``:`s`,` failed in the last 24 h — review`]}),c&&(0,C.jsx)(jc,{projectTitle:u,runs:d,chats:f,bundles:p,agents:r?.agents??[],workflows:i?.workflows??[],filter:o,setFilter:s})]})}function kc(e){if(e.lamp===`running`)return`now`;let t=new Date(e.at),n=new Date;if(t.toDateString()===n.toDateString())return`today`;let r=new Date(n);return r.setDate(r.getDate()-1),t.toDateString()===r.toDateString()?`yesterday`:`earlier`}var Ac=[[`all`,`all`],[`run`,`runs`],[`session`,`chats`],[`knowledge`,`knowledge`]];function jc({projectTitle:e,runs:t,chats:n,bundles:r,agents:i,workflows:a,filter:o,setFilter:s}){let c=ue(),l=(0,v.useMemo)(()=>{let s=[],l=e=>e?a.find(t=>t.slug===e)?.name??e:void 0;for(let e of t)s.push({at:e.updatedAt,kind:`run`,emoji:`⚙️`,title:l(e.workflow)??e.id,sub:e.request??``,href:`/runs/${e.id}`,lamp:Cc(e.status),status:wc(e.status)});for(let t of n){let n=t.scope.kind===`agent`?i.find(e=>t.scope.kind===`agent`&&e.slug===t.scope.slug):void 0;s.push({at:t.updatedAt,kind:`session`,emoji:n?n.emoji||`🤖`:`💬`,title:n?n.name:t.title||`new chat`,sub:n?`${t.title||`new chat`}${c?` · ${t.agent}`:``}`:c?`${t.agent} · ${Ec(t,i,e)}`:Ec(t,i,e),href:Tc(t),lamp:t.awaitingApproval?`blocked`:t.busy?`running`:`ok`,status:t.awaitingApproval?`needs approval`:t.busy?`working`:void 0})}for(let e of r)e.updatedAt&&s.push({at:e.updatedAt,kind:`knowledge`,emoji:`📚`,title:e.name,sub:`${e.concepts} concepts`,href:`/knowledge/${encodeURIComponent(e.name)}`,lamp:`ok`});return(o===`all`?s:o===`failed`?s.filter(e=>e.kind===`run`&&e.lamp===`failed`):s.filter(e=>e.kind===o)).sort((e,t)=>{let n=Number(t.lamp===`running`)-Number(e.lamp===`running`);return n===0?t.at.localeCompare(e.at):n}).slice(0,15)},[t,n,r,i,c,o]),u=``,d=(e,t)=>b(`inline-flex cursor-pointer items-center gap-0.5 rounded-lg border px-2.5 py-0.5 text-2xs transition-colors`,e?b(`border-transparent`,t?`bg-bad-soft text-on-bad-soft`:`bg-accent-soft text-on-accent-soft`):`border-line bg-transparent text-fg-2 hover:text-fg`);return(0,C.jsx)(K,{className:`animate-rise`,title:`all activity`,actions:(0,C.jsxs)(`span`,{className:`flex gap-1.5`,children:[Ac.map(([e,t])=>(0,C.jsx)(`button`,{type:`button`,className:d(o===e),"aria-pressed":o===e,onClick:()=>s(e),children:t},e)),o===`failed`&&(0,C.jsxs)(`button`,{type:`button`,className:d(!0,!0),onClick:()=>s(`all`),children:[`failed `,(0,C.jsx)(w,{name:`close`,className:`ms-sm`})]})]}),children:l.length===0?(0,C.jsx)(`div`,{className:`px-[18px] py-4 text-sm text-fg-2`,children:o===`all`?`nothing yet — run a workflow or start a chat`:`nothing here for this filter`}):(0,C.jsx)(`div`,{className:`flex flex-col p-1.5`,children:l.map(e=>{let t=kc(e),n=t===u?null:t;return u=t,(0,C.jsxs)(`div`,{children:[n&&(0,C.jsx)(He,{className:`block px-2.5 pt-3 pb-1`,children:n}),(0,C.jsx)(q,{href:e.href,leading:(0,C.jsxs)(`span`,{className:`relative text-[18px] leading-none`,children:[(0,C.jsx)(`span`,{"aria-hidden":!0,children:e.emoji}),e.lamp===`running`&&(0,C.jsx)(`span`,{className:`absolute -right-1 -bottom-1 grid rounded-full bg-surface p-px`,children:(0,C.jsx)(V,{tone:`working`})})]}),title:Dc(e.title),titleExtra:(0,C.jsx)(H,{tone:Mc[e.kind],children:e.kind===`session`?`chat`:e.kind}),sub:e.sub&&Dc(e.sub),meta:(0,C.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.status&&(0,C.jsx)(H,{tone:Nc[e.lamp]??`neutral`,children:e.status}),(0,C.jsx)(`span`,{title:new Date(e.at).toLocaleString(),children:Ne(e.at)}),(0,C.jsx)(w,{name:`chevron_right`,className:`ms-sm`})]})})]},`${e.kind}:${e.href}:${e.at}`)})})})}var Mc={run:`accent`,session:`ask`,knowledge:`ok`},Nc={ok:`ok`,failed:`bad`,blocked:`bad`,running:`accent`,aborted:`neutral`};function Pc(e){if(!e)return``;let t=Math.max(0,Math.round((Date.now()-Date.parse(e))/6e4));return t<1?`just started`:t<60?`${t} min`:`${Math.floor(t/60)} h ${t%60} min`}var Fc=e=>new Date(e).toDateString()===new Date().toDateString();function Ic({runs:e,chats:t,bundles:n,agents:r,workflows:i,projectTitle:a,loaded:o}){let s=Ct()??[],c=T(),l=R(`/api/agent-status`,!1,5e3),u=e=>e?i.find(t=>t.slug===e)?.name??e:`workflow`,d=new Map;for(let e of Object.values(l??{}))for(let t of e.working)t.since&&d.set(t.chatId,t.since);let f=[...t.filter(e=>e.busy&&!e.awaitingApproval).map(e=>({key:`c:${e.id}`,owner:Ec(e,r,a),title:Dc(e.title||`new chat`),meta:`working${d.get(e.id)?` · ${Pc(d.get(e.id))}`:``}`,href:Tc(e),tone:`working`})),...e.filter(e=>e.status===`running`).map(e=>({key:`r:${e.id}`,owner:`⚙️ ${u(e.workflow)}`,title:Dc(e.request??``),meta:`running`,href:`/runs/${e.id}`,tone:`working`}))],p=[...t.filter(e=>!e.busy&&!e.awaitingApproval&&Fc(e.updatedAt)&&e.title).map(e=>({key:`c:${e.id}`,at:e.updatedAt,owner:Ec(e,r,a),title:Dc(e.title),meta:Ne(e.updatedAt),href:Tc(e)})),...e.filter(e=>e.status!==`running`&&Fc(e.updatedAt)).map(e=>({key:`r:${e.id}`,at:e.updatedAt,owner:`⚙️ ${u(e.workflow)}`,title:Dc(e.request??``),meta:`${e.status===`ok`?`done`:e.status===`aborted`?`stopped`:`failed`} · ${Ne(e.updatedAt)}`,href:`/runs/${e.id}`})),...n.filter(e=>e.updatedAt&&Fc(e.updatedAt)).map(e=>({key:`k:${e.name}`,at:e.updatedAt,owner:`📚 ${e.name}`,title:`knowledge updated`,meta:Ne(e.updatedAt),href:`/knowledge/${encodeURIComponent(e.name)}`}))].sort((e,t)=>t.at.localeCompare(e.at)).slice(0,12),m=Ot(s,c),h=o&&s.length===0&&f.length===0;return(0,C.jsxs)(`div`,{className:`today flex flex-col gap-3.5`,children:[(0,C.jsxs)(K,{className:`today-section`,title:`needs you`,count:s.length,actions:m&&(0,C.jsxs)(z,{variant:`primary`,size:`sm`,onClick:()=>kt(m),className:`bg-bad text-on-bad hover:bg-bad`,children:[`start `,(0,C.jsx)(w,{name:`arrow_forward`,className:`ms-sm`})]}),children:[s.length===0?(0,C.jsx)(`p`,{className:`m-0 px-[18px] py-4 text-sm text-fg-2`,children:h?`Nothing waiting, nothing running.`:`Nothing is waiting for you.`}):(0,C.jsx)(`div`,{className:`p-1.5`,children:s.map(e=>(0,C.jsx)(q,{className:`today-row waiting`,onClick:()=>kt(e),over:Tt(e.owner),title:e.title,meta:(0,C.jsxs)(`span`,{className:`font-semibold text-bad`,children:[e.kind===`approval`?`needs approval`:e.kind===`question`?`asks you`:`failed`,` · `,Ne(e.since)]})},e.id))}),h&&(0,C.jsx)(`div`,{className:`px-[18px] pb-4`,children:(0,C.jsx)(z,{variant:`primary`,icon:`chat`,href:`/agents/chats`,children:`chat with Ralv`})})]}),f.length>0&&(0,C.jsx)(K,{className:`today-section`,title:`in progress`,children:(0,C.jsx)(`div`,{className:`p-1.5`,children:f.map(e=>(0,C.jsx)(Lc,{r:e},e.key))})}),(0,C.jsx)(K,{className:`today-section`,title:`done today`,children:p.length===0?(0,C.jsx)(`p`,{className:`m-0 px-[18px] py-4 text-sm text-fg-2`,children:`Nothing finished yet today.`}):(0,C.jsx)(`div`,{className:`p-1.5`,children:p.map(e=>(0,C.jsx)(Lc,{r:e},e.key))})})]})}function Lc({r:e}){return(0,C.jsx)(q,{className:`today-row`,href:e.href,over:e.owner,title:e.title,meta:(0,C.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[e.tone===`working`&&(0,C.jsx)(V,{tone:`working`}),e.meta]})})}var Rc=`modulepreload`,zc=function(e){return`/`+e},Bc={},Vc=function(e){return e.pathname.endsWith(`.css`)},Hc=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=zc(t,n);let r=s(t);if(r.href in Bc)return;Bc[r.href]=!0;let i=Vc(r);if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let o=document.createElement(`link`);if(o.rel=i?`stylesheet`:Rc,i||(o.as=`script`),o.crossOrigin=``,o.href=r.href,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),i)return new Promise((e,t)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>t(Error(`Unable to preload CSS for ${r}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Uc=(0,v.lazy)(()=>Hc(()=>import(`./editor-C6eZc_Cr.js`).then(e=>({default:e.DocEditor})),__vite__mapDeps([0,1,2,3,4,5,6]))),Wc=()=>Hc(()=>import(`./editor-C6eZc_Cr.js`),__vite__mapDeps([0,1,2,3,4,5,6]));function Gc({bundle:e,conceptId:t}){let n=R(`/api/knowledge`,!1),[r,i]=(0,v.useState)([]);(0,v.useEffect)(()=>{n&&i(e=>e.filter(e=>n.bundles.some(t=>t.name===e)))},[n]);let a=(n?.bundles??[]).filter(e=>!r.includes(e.name)),o=e===`new`,s=a.reduce((e,t)=>!e||(t.updatedAt??``)>(e.updatedAt??``)?t:e,void 0);return(0,v.useEffect)(()=>{!e&&s&&M(`/knowledge/${encodeURIComponent(s.name)}`,{replace:!0})},[e,s?.name]),(0,C.jsxs)(`div`,{className:`runs-screen`,children:[(0,C.jsxs)(`aside`,{className:`runs-side`,children:[(0,C.jsx)(ft,{title:`bundles`,action:(0,C.jsx)(z,{size:`sm`,variant:`quiet`,icon:`add`,href:`/knowledge/new`,children:`new`})}),(0,C.jsxs)(mt,{children:[a.map(t=>(0,C.jsx)(q,{href:`/knowledge/${encodeURIComponent(t.name)}`,active:t.name===e,size:`sm`,leading:(0,C.jsx)(V,{tone:`ok`}),title:t.name,meta:t.concepts,sub:`${t.okfVersion?`okf ${t.okfVersion}`:`okf`}${t.updatedAt?` · ${t.updatedAt.slice(0,10)}`:``}`},t.name)),n&&a.length===0&&(0,C.jsx)(ht,{children:`no bundles yet`})]})]}),(0,C.jsx)(`div`,{className:`runs-main`,children:e&&!o?(0,C.jsx)(Qc,{name:e,conceptId:t,onRemoved:()=>{i(t=>[...t,e]),M(`/knowledge`,{replace:!0})}},e):o||n&&!s?(0,C.jsx)(Kc,{}):(0,C.jsx)(W,{children:`loading…`})})]})}function Kc(){let[e,t]=(0,v.useState)(``),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(!1);async function o(){let t=e.trim();if(!t)return;a(!0),r(``);let n=await(await fetch(`/api/knowledge`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t})})).json();a(!1),n.error?r(n.error):M(`/knowledge/${encodeURIComponent(t)}`)}return(0,C.jsxs)(`div`,{className:`empty-action flex flex-col items-center gap-3 px-4 py-16`,children:[(0,C.jsxs)(`div`,{className:`flex w-full max-w-[520px] gap-2.5`,children:[(0,C.jsx)(J,{className:`flex-1 font-mono text-sm`,value:e,placeholder:`bundle name, e.g. customer-support`,"aria-label":`bundle name`,onChange:e=>t(e.target.value),onKeyDown:e=>e.key===`Enter`&&void o(),autoFocus:!0}),(0,C.jsx)(z,{variant:`primary`,icon:`add`,busy:i,disabled:!e.trim(),onClick:o,children:i?`creating…`:`new bundle`})]}),n&&(0,C.jsx)(G,{tone:`bad`,children:n})]})}function qc({tier:e}){return(0,C.jsx)(H,{tone:e===`human-reviewed`?`ok`:e===`machine-confirmed`?`accent`:`neutral`,children:e})}var Jc=e=>e===`deprecated`||e===`stale`?`bad`:e===`draft`?`accent`:`neutral`,Yc=()=>(0,v.useContext)(N)!==null,Xc=`m-0 max-h-[560px] overflow-auto px-[18px] py-3.5 font-mono text-xs leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,Zc=`@activity`;function Qc({name:e,conceptId:t,onRemoved:n}){let r=R(`/api/knowledge/${encodeURIComponent(e)}`,!1),i=Yc(),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``);async function l(){let t=await fetch(`/api/knowledge/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(()=>null),r=await t?.json().catch(()=>({}));if(!t?.ok){c(r?.error??`delete failed`),o(!1);return}n?n():M(`/knowledge`,{replace:!0})}if(!r)return(0,C.jsx)(W,{children:`loading…`});if(`error`in r)return(0,C.jsx)(W,{icon:`menu_book`,children:`bundle not found`});let u=t===Zc?`activity`:`pages`,d=r.concepts,f=u===`pages`?t&&d.some(e=>e.id===t)?t:d[0]?.id:void 0,p=`/knowledge/${encodeURIComponent(e)}`;return(0,C.jsxs)(`div`,{className:b(`agent-view @container flex flex-col`,i?`gap-2.5`:`gap-4`),children:[(0,C.jsxs)(`div`,{className:b(`flex flex-wrap items-center gap-x-4 gap-y-2`,i?`mb-0.5`:`mx-0.5 mt-1 mb-2`),children:[(0,C.jsx)(We,{size:i?`md`:`lg`,children:e}),(0,C.jsxs)(`span`,{className:b(`text-fg-2`,i?`text-[12.5px]`:`text-base`),children:[d.length,` pages`]}),(0,C.jsx)(et,{bare:!0,className:`self-end`,label:`bundle views`,value:u,items:[{id:`pages`,href:p,label:`pages`},{id:`activity`,href:`${p}/${Zc}`,label:`activity`}]}),(0,C.jsx)(`span`,{className:`flex-1`}),!i&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(z,{size:`sm`,variant:`quiet`,icon:`picture_as_pdf`,onClick:()=>void Wo(e),children:`export PDF`}),a?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(z,{size:`sm`,variant:`danger`,icon:`delete`,onClick:()=>void l(),children:`move to trash`}),(0,C.jsx)(z,{size:`sm`,variant:`quiet`,onClick:()=>o(!1),children:`cancel`})]}):(0,C.jsx)(z,{size:`sm`,variant:`quiet`,icon:`delete`,onClick:()=>o(!0),title:`Move the bundle to the trash`,children:`delete`}),(0,C.jsx)(z,{variant:`primary`,onClick:()=>void Ma(`claude`,{kind:`knowledge`,bundle:e}),children:`curate in chat`})]})]}),s&&(0,C.jsx)(G,{tone:`bad`,children:s}),u===`activity`?r.log?(0,C.jsx)(tl,{name:e,log:r.log}):(0,C.jsx)(K,{children:(0,C.jsx)(`p`,{className:`m-0 px-[18px] py-3 text-sm text-fg-2`,children:`no activity yet`})}):d.length===0?(0,C.jsx)(K,{children:(0,C.jsxs)(`p`,{className:`m-0 px-[18px] py-3 text-sm text-fg-2`,children:[`No pages yet — start a chat to author some, or write one with`,` `,(0,C.jsxs)(`code`,{children:[`kraftwerk knowledge put `,e,`/<path>`]}),`.`]})}):(0,C.jsxs)(`div`,{className:b(`grid items-start`,i?`grid-cols-[170px_minmax(0,1fr)] gap-3.5 @max-[560px]:grid-cols-1`:`grid-cols-[260px_minmax(0,1fr)] gap-6 max-[1100px]:grid-cols-1`),children:[(0,C.jsx)(`aside`,{className:b(`flex flex-col gap-0.5 overflow-y-auto border-r border-line`,i?`sticky top-0 max-h-[calc(100vh-var(--topbar-h)-160px)] pr-2 pb-1.5 @max-[560px]:static @max-[560px]:max-h-[200px] @max-[560px]:border-r-0 @max-[560px]:pr-0`:`sticky top-[calc(var(--topbar-h)+18px)] max-h-[calc(100vh-var(--topbar-h)-36px)] py-1.5 pr-3 max-[1100px]:static max-[1100px]:max-h-none max-[1100px]:border-r-0 max-[1100px]:pr-0`),children:(0,C.jsx)(rl,{concepts:d,base:p,selected:f})}),(0,C.jsx)(`div`,{className:`min-w-0`,children:f&&(0,C.jsx)(al,{bundle:e,conceptId:f},f)})]})]})}function $c(e){let t=[];for(let n of e.split(`
216
216
  `)){let e=n.match(/^##\s+(\d{4}-\d{2}-\d{2})/);if(e){t.push({date:e[1],entries:[]});continue}let r=n.match(/^[*-]\s+\*\*([^*]+)\*\*:\s*(.*)$/);r&&t.length>0&&t[t.length-1].entries.push({kind:r[1].toLowerCase(),text:r[2]})}return t.filter(e=>e.entries.length>0)}function el(e,t){let n=[],r=/\[([^\]]+)\]\(\/?([^)]+?)\.md\)/g,i=0,a;for(;a=r.exec(t);)a.index>i&&n.push(t.slice(i,a.index)),n.push((0,C.jsx)(P,{href:`/knowledge/${encodeURIComponent(e)}/${a[2].replace(/^\//,``)}`,children:a[1]},a.index)),i=a.index+a[0].length;return i<t.length&&n.push(t.slice(i)),n}function tl({name:e,log:t}){let n=$c(t),[r,i]=(0,v.useState)(!1);return(0,C.jsx)(K,{title:`activity`,actions:(0,C.jsx)(z,{size:`sm`,variant:`quiet`,onClick:()=>i(!r),children:r?`timeline`:`raw log`}),children:r||n.length===0?(0,C.jsx)(`pre`,{className:Xc,children:t}):(0,C.jsx)(`div`,{className:`pt-0.5 pb-2.5`,children:n.map((t,n)=>(0,C.jsxs)(v.Fragment,{children:[(0,C.jsx)(`div`,{className:b(`px-[18px] pt-3.5 pb-1 font-mono text-2xs tracking-[0.05em] text-fg-2 tabular-nums`,n>0&&`mt-1 border-t border-line`),children:t.date}),t.entries.map((t,n)=>(0,C.jsxs)(`div`,{className:`flex items-baseline gap-2.5 px-[18px] py-1`,children:[(0,C.jsx)(H,{tone:t.kind===`verification`?`ok`:t.kind===`creation`||t.kind===`initialization`?`accent`:`neutral`,children:t.kind}),(0,C.jsx)(`span`,{className:`min-w-0 text-[12.5px] leading-[1.55] break-words text-fg-2 [&_a]:text-accent`,children:el(e,t.text)})]},n))]},t.date))})})}function nl(e){let t={name:``,path:``,folders:[],pages:[],total:0};for(let n of e){let e=n.id.split(`/`),r=t;r.total++;for(let t of e.slice(0,-1)){let e=r.folders.find(e=>e.name===t);e||(e={name:t,path:r.path?`${r.path}/${t}`:t,folders:[],pages:[],total:0},r.folders.push(e)),r=e,r.total++}r.pages.push(n)}let n=e=>{e.folders.sort((e,t)=>e.name.localeCompare(t.name)),e.pages.sort((e,t)=>e.title.localeCompare(t.title)),e.folders.forEach(n)};return n(t),t}function rl({concepts:e,base:t,selected:n}){let r=(0,v.useMemo)(()=>nl(e),[e]),[i,a]=(0,v.useState)(()=>new Set);(0,v.useEffect)(()=>{n&&n.includes(`/`)&&a(e=>{let t=new Set(e),r=n.split(`/`).slice(0,-1);for(let e=1;e<=r.length;e++)t.delete(r.slice(0,e).join(`/`));return t.size===e.size?e:t})},[n]);let o=e=>a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),s=Yc();return(0,C.jsx)(il,{folder:r,base:t,selected:n,closed:i,toggle:o,embedded:s})}function il({folder:e,base:t,selected:n,closed:r,toggle:i,embedded:a}){return(0,C.jsxs)(C.Fragment,{children:[e.pages.map(e=>{let r=e.id===n;return(0,C.jsxs)(P,{href:`${t}/${e.id}`,"aria-current":r?`page`:void 0,className:b(`wiki-page flex items-center gap-2 rounded-control px-2.5 py-1.5 leading-[1.35] no-underline transition-colors`,a?`text-[12.5px]`:`text-sm`,r?`active bg-accent-soft font-medium text-on-accent-soft`:`text-fg hover:bg-surface-2`),title:`${e.id}.md`,children:[(0,C.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.title}),(e.stale||e.error)&&(0,C.jsx)(`span`,{className:`size-1.5 flex-none rounded-full bg-bad`,title:e.error??`stale`})]},e.id)}),e.folders.map(e=>{let o=!r.has(e.path),s=!!n&&n.startsWith(`${e.path}/`)&&!o;return(0,C.jsxs)(v.Fragment,{children:[(0,C.jsxs)(`button`,{type:`button`,className:b(`wiki-folder mt-2.5 mb-0.5 flex w-full cursor-pointer items-center gap-1 rounded-control border-0 bg-transparent py-1 pr-2 pl-0.5 text-left`,`font-[inherit] text-2xs leading-[1.3] font-semibold tracking-[0.06em] uppercase transition-colors`,o&&`open`,s?`holds text-accent`:`text-fg-2 hover:text-fg`),onClick:()=>i(e.path),"aria-expanded":o,title:`${e.path}/`,children:[(0,C.jsx)(w,{name:`chevron_right`,className:b(`ms-sm flex-none text-[16px] transition-transform`,o&&`rotate-90`,!s&&`text-fg-2`)}),(0,C.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,C.jsx)(`span`,{className:`text-[10.5px] font-medium tracking-normal text-fg-2 tabular-nums opacity-70`,children:e.total})]}),o&&(0,C.jsx)(`div`,{className:`wiki-branch ml-[9px] flex flex-col gap-0.5 border-l border-line pl-1`,children:(0,C.jsx)(il,{folder:e,base:t,selected:n,closed:r,toggle:i,embedded:a})})]},e.path)})]})}function al({bundle:e,conceptId:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),c=Yc(),[l,u]=(0,v.useState)(`document`),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(``),[_,y]=(0,v.useState)(null),[x,S]=(0,v.useState)(`saved`),[w,T]=(0,v.useState)(``),E=(0,v.useRef)(``),D=(0,v.useRef)(null),O=(0,v.useRef)(!1),k=(0,v.useRef)(null),ee=(0,v.useRef)(null),A=(0,v.useRef)(null),te=`/api/knowledge/${encodeURIComponent(e)}/concept?id=${encodeURIComponent(t)}`,ne=()=>{fetch(te).then(e=>e.ok?e.json():Promise.reject()).then(r).catch(()=>a(!0))};(0,v.useEffect)(()=>{if(l===`markdown`)return;let e=!0,t,n=async()=>{try{let t=await fetch(te,{cache:`no-store`});if(t.ok){let n=await t.json();e&&(a(!1),r(e=>JSON.stringify(e)===JSON.stringify(n)?e:n))}else t.status===404&&e&&a(!0)}catch{}e&&(t=setTimeout(n,6e3))};return n(),()=>{e=!1,clearTimeout(t)}},[te,l]),(0,v.useEffect)(()=>{if(!n||n.raw===D.current||k.current!==null||A.current)return;let e=!0;return Wc().then(({splitFrontmatter:t,unwrapParagraphs:r})=>{if(!e)return;let{head:i,body:a}=t(n.raw);E.current=i,D.current=n.raw,O.current=!1,y(e=>({key:(e?.key??0)+1,body:r(a)}))}),()=>{e=!1}},[n]);async function re(){A.current&&await A.current;let n=k.current;if(n===null)return;k.current=null,S(`saving`);let i=(async()=>{try{let i=E.current,a=i?`${i}${i.endsWith(`
217
217
  `)?``:`
218
218
  `}${n.replace(/^\n+/,`
@@ -223,7 +223,7 @@ Instructions this agent follows when the skill applies or is invoked with /<name
223
223
  `).map((e,t)=>(0,C.jsxs)(`span`,{className:zl(e),children:[e||` `,`
224
224
  `]},t)),r&&(0,C.jsxs)(`span`,{className:`text-fg-2 opacity-80`,children:[`… diff truncated, see the rest in a terminal`,`
225
225
  `]})]}):(0,C.jsx)(`div`,{className:Hl,children:`no textual diff (binary or empty)`})}var Hl=`git-diff mt-1.5 mb-0.5 max-h-[420px] basis-full overflow-auto rounded-xl bg-surface-2 px-3 py-2.5 font-mono text-[11.5px] leading-[1.5] whitespace-pre`,Ul={modified:`text-accent`,added:`text-ok`,untracked:`text-ok`,deleted:`text-bad`,conflicted:`text-bad`};function Wl({status:e,muted:t}){return(0,C.jsx)(`span`,{className:b(`flex-none rounded-full border border-line px-2 py-0.5 text-[10.5px] font-semibold tracking-[0.4px] uppercase`,t?`text-fg-2`:Ul[e]??`text-fg-2`),children:e})}var Gl=`text-xs text-fg-2`,Kl=`m-0 p-[18px] text-sm text-fg-2`;function ql(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(new Set),[i,a]=(0,v.useState)(new Set),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),m=(0,v.useRef)(!0),h=(0,v.useCallback)(async()=>{try{let e=await fetch(m.current?`/api/git?fresh=1`:`/api/git`,{cache:`no-store`});m.current=!1,e.ok&&t(await e.json())}catch{}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await h(),e&&(t=setTimeout(n,6e3))};return n(),()=>{e=!1,clearTimeout(t)}},[h]),(0,v.useEffect)(()=>{if(!e?.files)return;let t=new Set(e.files.filter(e=>e.syncable).map(e=>e.path));r(e=>{let n=new Set([...e].filter(e=>t.has(e)));return n.size===e.size?e:n})},[e]);let g=async(e,t)=>{l(e),d(``),p(``);try{let n=await Ee(`/api/git/${e}`,t);n.ok?p(e===`push`?`pushed`:e===`pull`?`pulled`:`fetched`):d(n.error||`${e} failed`)}catch(t){d(t.message||`${e} failed`)}finally{l(``)}h()},_=async()=>{l(`commit`),d(``),p(``);try{let e=await Ee(`/api/git/commit`,{paths:[...n],message:o});e.ok?(p(`committed ${n.size} file${n.size===1?``:`s`}`),r(new Set),s(``)):d(e.error||`commit failed`)}catch(e){d(e.message||`commit failed`)}finally{l(``)}h()};if(!e)return(0,C.jsx)(W,{children:`loading…`});if(!e.enabled)return(0,C.jsxs)(Ke,{children:[(0,C.jsx)(Ge,{icon:`cloud_sync`,title:`Git sync`}),(0,C.jsx)(K,{children:(0,C.jsxs)(`p`,{className:Kl,children:[`Git sync is off. Turn it on in `,(0,C.jsx)(`a`,{href:`#/settings`,children:`settings`}),`, or add a `,(0,C.jsx)(`code`,{children:`git:`}),` block to kraftwerk.yml.`]})})]});let y=(e.files??[]).filter(e=>e.syncable),x=(e.files??[]).filter(e=>!e.syncable),S=(e,t)=>r(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r});return(0,C.jsxs)(Ke,{children:[(0,C.jsx)(Ge,{icon:`cloud_sync`,title:`Git sync`,actions:(0,C.jsxs)(C.Fragment,{children:[f&&(0,C.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-sm text-ok`,children:[(0,C.jsx)(w,{name:`check`,className:`ms-sm`}),` `,f]}),u&&(0,C.jsx)(G,{tone:`bad`,children:u})]})}),(0,C.jsx)(K,{title:`branch`,actions:(0,C.jsxs)(C.Fragment,{children:[e.lastFetch&&(0,C.jsxs)(`span`,{className:`text-xs text-fg-2`,title:e.lastFetch,children:[`fetched `,Ne(e.lastFetch)]}),e.lastError&&(0,C.jsxs)(`span`,{className:`inline-flex max-w-[46ch] items-center gap-1 truncate text-xs text-bad`,title:e.lastError,children:[(0,C.jsx)(w,{name:`cloud_off`,className:`ms-sm`}),` `,e.lastError.split(`
226
- `)[0]]})]}),children:e.error?(0,C.jsxs)(`div`,{className:`flex items-center gap-2 p-[18px] text-sm text-bad`,children:[(0,C.jsx)(w,{name:`error`,className:`ms-sm`}),` `,e.error]}):(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-[18px] py-3.5`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 text-base`,children:[(0,C.jsx)(w,{name:`account_tree`,className:`ms-sm`}),(0,C.jsx)(`strong`,{className:`font-mono`,children:e.branch}),(0,C.jsx)(`span`,{className:Gl,children:e.upstream?`tracking ${e.upstream}`:`no upstream yet, push sets one`})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2.5 text-[12.5px] font-semibold`,children:[e.diverged&&(0,C.jsx)(`span`,{className:`text-bad`,children:`diverged, resolve in a terminal`}),!!e.behind&&(0,C.jsxs)(`span`,{className:`text-accent`,children:[e.behind,` behind`]}),!!e.ahead&&(0,C.jsxs)(`span`,{className:`text-ok`,children:[e.ahead,` ahead`]}),!e.ahead&&!e.behind&&(0,C.jsx)(`span`,{className:b(`text-xs text-fg-2`,`font-normal`),children:`up to date`})]}),(0,C.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,C.jsx)(z,{size:`sm`,icon:`refresh`,busy:c===`fetch`,disabled:!!c,onClick:()=>void g(`fetch`),children:`fetch`}),(0,C.jsx)(z,{size:`sm`,icon:`download`,busy:c===`pull`,disabled:!!c||!e.behind||e.diverged,title:e.diverged?`Diverged. Resolve in a terminal.`:`Fast-forward to the remote`,onClick:()=>void g(`pull`),children:`pull`}),(0,C.jsx)(z,{size:`sm`,variant:`primary`,icon:`upload`,busy:c===`push`,disabled:!!c||!e.ahead&&!!e.upstream,title:e.upstream?`Push to the upstream`:`Push and set the upstream`,onClick:()=>void g(`push`),children:`push`})]})]})}),(0,C.jsxs)(K,{title:`changes`,actions:(0,C.jsx)(`span`,{className:Gl,children:y.length===0?`workspace clean`:`${n.size} of ${y.length} selected`}),children:[y.length===0&&x.length===0&&(0,C.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`Nothing changed under the workspace paths.`}),y.map(e=>(0,C.jsxs)(`div`,{className:b(`git-row px-[18px]`,Jl),children:[(0,C.jsx)(`input`,{type:`checkbox`,className:`accent-accent`,"aria-label":`select ${e.path}`,checked:n.has(e.path),onChange:t=>S(e.path,t.target.checked)}),(0,C.jsxs)(`button`,{type:`button`,className:`group/file flex min-w-0 flex-1 cursor-pointer items-center gap-2 border-0 bg-transparent px-0 py-0.5 text-left font-[inherit] text-fg`,onClick:()=>a(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),children:[(0,C.jsx)(w,{name:i.has(e.path)?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,C.jsx)(Wl,{status:e.status}),(0,C.jsx)(`span`,{className:b(Yl,`group-hover/file:underline`),children:e.path})]}),i.has(e.path)&&(0,C.jsx)(Bl,{file:e.path})]},e.path)),y.length>0&&(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5 border-t border-line bg-surface-2 px-[18px] py-3`,children:[(0,C.jsx)(J,{className:`min-w-[220px] flex-1 text-sm`,placeholder:`Commit message`,"aria-label":`commit message`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!c&&o.trim()&&n.size>0&&_()}}),(0,C.jsx)(z,{size:`sm`,disabled:n.size===y.length,onClick:()=>r(new Set(y.map(e=>e.path))),children:`select all`}),(0,C.jsxs)(z,{size:`sm`,variant:`primary`,icon:`check`,busy:c===`commit`,disabled:!!c||n.size===0||!o.trim(),onClick:()=>void _(),children:[`commit `,n.size||``]})]}),x.length>0&&(0,C.jsxs)(`details`,{className:`border-t border-line px-[18px] py-2.5`,children:[(0,C.jsxs)(`summary`,{className:`cursor-pointer text-[12.5px] text-fg-2`,children:[x.length,e.blockedHidden?`+`:``,` change`,x.length===1&&!e.blockedHidden?``:`s`,` outside the workspace paths`]}),x.map(e=>(0,C.jsxs)(`div`,{className:b(`git-row blocked opacity-60`,Jl),children:[(0,C.jsx)(Wl,{status:e.status,muted:!0}),(0,C.jsx)(`span`,{className:Yl,children:e.path}),(0,C.jsx)(`span`,{className:`text-xs text-fg-2`,children:e.reason})]},e.path)),!!e.blockedHidden&&(0,C.jsx)(`div`,{className:b(`git-row blocked opacity-60`,Jl),children:(0,C.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`and `,e.blockedHidden,` more, not listed`]})})]})]}),(0,C.jsxs)(`p`,{className:b(Gl,`m-0`),children:[`Synced paths: `,(e.scope??[]).map((e,t)=>(0,C.jsxs)(`span`,{children:[t>0&&`, `,(0,C.jsx)(`code`,{children:e})]},e)),`. Run artifacts and files like `,(0,C.jsx)(`code`,{children:`.env`}),` are never staged.`,` `,e.interval?`Fetches every ${Ll(e.interval)}${e.autosync===`pull`?` and fast-forwards when the working tree is clean`:``}. `:`Background fetching is off. `,`Commit and push are always manual.`]})]})}var Jl=`flex flex-wrap items-center gap-2.5 py-2 [&+&]:border-t [&+&]:border-line`,Yl=`truncate font-mono text-[12.5px]`,Xl=e=>e.replace(/^https?:\/\//,``).replace(/^git@([^:]+):/,`$1/`).replace(/\.git$/,``),Zl=e=>e.error?{label:`unreadable`,state:`unreadable`}:e.dirty?{label:`${e.dirty} changed`,state:`changed`}:e.ahead?{label:`${e.ahead} to push`,state:`clean`}:e.behind?{label:`${e.behind} behind`,state:`behind`}:{label:`clean`,state:`clean`};function Ql({label:e,state:t}){return(0,C.jsx)(`span`,{className:b(`inline-flex items-center text-2xs font-semibold tracking-[0.4px] uppercase`,t===`clean`?`text-ok`:t===`changed`?`text-ask`:t===`unreadable`?`text-bad`:`text-fg-2`),children:e})}var $l=`rounded-full border border-line px-[7px] py-px font-mono text-xs text-fg-2`,eu=`border-line px-[18px] py-2 [&+&]:border-t`,tu=`group/item flex w-full cursor-pointer items-center gap-2 border-0 bg-transparent px-0 py-0.5 text-left font-[inherit] text-fg`,nu=`min-w-0 truncate font-mono text-[12.5px] group-hover/item:underline`;function ru({title:e,children:t}){return(0,C.jsxs)(`header`,{className:`flex flex-wrap items-center gap-3`,children:[(0,C.jsx)(z,{size:`sm`,variant:`quiet`,icon:`arrow_back`,href:`/repos`,title:`all repositories`,children:`repositories`}),(0,C.jsx)(w,{name:`folder_data`,className:`text-[26px] text-fg-2`}),(0,C.jsx)(We,{children:e}),t]})}var iu=e=>!!(e.error||e.dirty||e.ahead===void 0||e.ahead);function au({slug:e}){return e?(0,C.jsx)(ou,{slug:e}):(0,C.jsx)(su,{})}function ou({slug:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(0),h=ue(),g=(0,v.useCallback)(async()=>{try{let t=await fetch(`/api/repos/${encodeURIComponent(e)}`,{cache:`no-store`}),r=await t.json();if(!t.ok)throw Error(r.error||`HTTP ${t.status}`);n(r),i(``)}catch(e){i(e.message||`could not load the repository`)}},[e]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await g(),e&&(t=setTimeout(n,5e3))};return n(),()=>{e=!1,clearTimeout(t)}},[g,p]);let _=async()=>{u(`update`),f(``);try{let t=await fetch(`/api/repos/${encodeURIComponent(e)}/update`,{method:`POST`}),n=await t.json();if(!t.ok||!n.ok)throw Error(n.error||`failed`);n.error&&f(n.error)}catch(e){f(e.message)}finally{u(``),m(e=>e+1)}};if(r&&!t)return(0,C.jsxs)(Ke,{className:`repo-page`,children:[(0,C.jsx)(ru,{title:e}),(0,C.jsx)(G,{tone:`bad`,children:r})]});if(!t)return(0,C.jsx)(W,{children:`loading…`});let y=Zl(t),x=t.commits.filter(e=>e.local).length;return(0,C.jsxs)(Ke,{className:`repo-page`,children:[(0,C.jsxs)(ru,{title:t.slug,children:[t.branch&&(0,C.jsx)(`span`,{className:$l,children:t.branch}),t.upstream&&(0,C.jsxs)(`span`,{className:`text-xs text-fg-2`,title:`upstream`,children:[`→ `,t.upstream]}),(0,C.jsx)(Ql,{...y}),(0,C.jsx)(`span`,{className:`flex-1`}),(0,C.jsx)(z,{size:`sm`,icon:`sync`,busy:l===`update`,disabled:!!l,onClick:()=>void _(),title:`git fetch, then fast-forward when clean`,children:l===`update`?`updating…`:`update`})]}),(0,C.jsxs)(`div`,{className:b(Gl,`flex flex-wrap gap-x-3.5 gap-y-1`),children:[t.url&&(0,C.jsx)(`span`,{title:t.url,children:Xl(t.url)}),h&&(0,C.jsx)(`span`,{title:t.path,children:t.path}),t.head&&(0,C.jsxs)(`span`,{children:[`at `,(0,C.jsx)(`code`,{children:t.head}),t.committedAt?` · ${Ne(t.committedAt)}`:``]}),!!t.ahead&&(0,C.jsxs)(`span`,{children:[t.ahead,` to push`]}),!!t.behind&&(0,C.jsxs)(`span`,{children:[t.behind,` behind`]}),t.updatedAt&&(0,C.jsxs)(`span`,{children:[`changed `,Ne(t.updatedAt)]})]}),(t.error||d||r)&&(0,C.jsx)(G,{tone:`bad`,children:t.error||d||r}),(0,C.jsxs)(K,{title:`changes · working tree against HEAD`,actions:(0,C.jsxs)(`span`,{className:Gl,children:[t.files.length,` file`,t.files.length===1?``:`s`,t.insertions||t.deletions?(0,C.jsxs)(C.Fragment,{children:[` · `,(0,C.jsxs)(`span`,{className:`text-ok`,children:[`+`,t.insertions]}),` `,(0,C.jsxs)(`span`,{className:`text-bad`,children:[`−`,t.deletions]})]}):null]}),children:[t.files.length===0&&(0,C.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`Clean — nothing changed since the last commit.`}),t.files.map(n=>(0,C.jsxs)(`div`,{className:b(`repo-file`,eu),"data-file":n.path,children:[(0,C.jsxs)(`button`,{type:`button`,className:tu,onClick:()=>o(a===n.path?null:n.path),children:[(0,C.jsx)(w,{name:a===n.path?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,C.jsx)(Wl,{status:n.status}),(0,C.jsx)(`span`,{className:nu,children:n.path})]}),a===n.path&&(0,C.jsx)(Vl,{url:`/api/repos/${encodeURIComponent(e)}/diff?path=${encodeURIComponent(n.path)}&v=${encodeURIComponent(t.updatedAt??``)}`})]},n.path))]}),(0,C.jsxs)(K,{title:`commits · newest first`,actions:(0,C.jsx)(`span`,{className:Gl,children:x?`${x} not pushed`:t.commits.length?`all pushed`:``}),children:[t.commits.length===0&&(0,C.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`No commits yet.`}),t.commits.map(t=>(0,C.jsxs)(`div`,{className:b(`repo-commit`,eu),"data-commit":t.short,children:[(0,C.jsxs)(`button`,{type:`button`,className:tu,onClick:()=>c(s===t.hash?null:t.hash),title:t.hash,children:[(0,C.jsx)(w,{name:s===t.hash?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,C.jsx)(`code`,{className:`text-xs`,children:t.short}),(0,C.jsx)(`span`,{className:`min-w-0 truncate text-sm group-hover/item:underline`,children:t.subject}),t.local&&(0,C.jsx)(H,{tone:`accent`,children:`not pushed`}),(0,C.jsxs)(`span`,{className:b(Gl,`ml-auto flex-none`),children:[t.author,` · `,Ne(t.committedAt)]})]}),s===t.hash&&(0,C.jsx)(Vl,{url:`/api/repos/${encodeURIComponent(e)}/commits/${t.hash}`})]},t.hash))]})]})}function su(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)({}),[o,s]=(0,v.useState)({}),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(!1),[y,x]=(0,v.useState)(``),S=ue(),T=(0,v.useCallback)(async()=>{try{let e=await fetch(`/api/repos`,{cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);t(await e.json()),r(``)}catch(e){r(e.message||`could not load repositories`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await T(),e&&(t=setTimeout(n,15e3))};return n(),()=>{e=!1,clearTimeout(t)}},[T]);let E=async(e,t,n=!1)=>{a(n=>({...n,[e]:t})),s(t=>({...t,[e]:``})),l(null);try{let r=t===`update`?await fetch(`/api/repos/${encodeURIComponent(e)}/update`,{method:`POST`}):await fetch(`/api/repos/${encodeURIComponent(e)}${n?`?force=1`:``}`,{method:`DELETE`}),i=await r.json();if(!r.ok||!i.ok)throw Error(i.error||`failed`);i.error&&s(t=>({...t,[e]:i.error}))}catch(t){s(n=>({...n,[e]:t.message}))}finally{a(t=>{let n={...t};return delete n[e],n}),T()}},D=async e=>{if(e.preventDefault(),u.trim()&&!g){_(!0),x(``);try{let e=await fetch(`/api/repos`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({url:u.trim(),name:f.trim()||void 0,branch:m.trim()||void 0})}),t=await e.json();if(!e.ok)throw Error(t.error||`clone failed`);d(``),p(``),h(``),await T()}catch(e){x(e.message)}finally{_(!1)}}},O=[...e?.repos??[]].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));return(0,C.jsxs)(Ke,{children:[(0,C.jsx)(Ge,{icon:`source`,title:`Repositories`,actions:(0,C.jsxs)(C.Fragment,{children:[e?.enabled&&(0,C.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[O.length,` cloned`]}),n&&(0,C.jsx)(G,{tone:`bad`,children:n})]})}),e&&!e.enabled&&(0,C.jsx)(K,{children:(0,C.jsx)(`div`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:e.error&&!/are off/.test(e.error)?(0,C.jsx)(G,{tone:`bad`,children:e.error}):(0,C.jsxs)(C.Fragment,{children:[`Repositories are off. Turn them on in `,(0,C.jsx)(`a`,{href:`#/settings`,children:`settings`}),` or add a `,(0,C.jsx)(`code`,{children:`repos:`}),` block to kraftwerk.yml.`]})})}),e?.enabled&&(0,C.jsx)(K,{title:`add a repository`,actions:(0,C.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`clones into `,(0,C.jsx)(`code`,{title:e.root,children:e.root})]}),children:(0,C.jsxs)(`form`,{className:`flex flex-col gap-2.5 p-[18px]`,onSubmit:e=>void D(e),children:[(0,C.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2.5`,children:[(0,C.jsx)(Y,{label:`url`,className:`min-w-[240px] flex-[2]`,children:(0,C.jsx)(J,{value:u,placeholder:`https://github.com/org/repo.git, git@host:org/repo.git or github:org/repo`,onChange:e=>d(e.target.value),autoFocus:!0})}),(0,C.jsx)(Y,{label:`name`,className:`min-w-[140px] flex-1`,children:(0,C.jsx)(J,{value:f,placeholder:`from the url`,onChange:e=>p(e.target.value)})}),(0,C.jsx)(Y,{label:`branch`,className:`w-[140px]`,children:(0,C.jsx)(J,{value:m,placeholder:`default`,onChange:e=>h(e.target.value)})}),(0,C.jsx)(z,{type:`submit`,variant:`primary`,icon:`download`,busy:g,disabled:!u.trim(),children:g?`cloning…`:`clone`})]}),y&&(0,C.jsx)(G,{tone:`bad`,children:y}),(0,C.jsxs)(`p`,{className:b(`text-xs text-fg-2`,`m-0`),children:[`Uses your own git credentials and never prompts: a private remote must already work from a terminal. Agents see every clone here and can add more with `,(0,C.jsx)(`code`,{children:`kraftwerk repos add`}),`.`]})]})}),e?.enabled&&(0,C.jsxs)(K,{title:`cloned repositories · newest change first`,children:[O.length===0&&(0,C.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`Nothing cloned yet.`}),O.map(e=>{let t=i[e.slug],n=Zl(e);return(0,C.jsxs)(`div`,{className:b(`repo-row grid grid-cols-[40px_minmax(0,1fr)_auto] items-start gap-3.5 border-line px-[18px] py-3.5 [&+&]:border-t`,n.state===`changed`&&`bg-ask-soft/40`),"data-repo":e.slug,children:[(0,C.jsx)(`span`,{className:b(`grid size-10 place-items-center rounded-full bg-surface-2 text-fg-2`,n.state===`unreadable`&&`opacity-45 grayscale`),children:(0,C.jsx)(w,{name:`folder_data`,className:`text-[22px]`})}),(0,C.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-[3px]`,children:[(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,C.jsx)(P,{href:`/repos/${encodeURIComponent(e.slug)}`,className:`text-md font-semibold text-fg no-underline hover:underline`,title:`changes and commits`,children:e.slug}),e.branch&&(0,C.jsx)(`span`,{className:$l,children:e.branch}),(0,C.jsx)(Ql,{...n}),e.updatedAt&&(0,C.jsxs)(`span`,{className:`text-xs text-fg-2`,title:e.updatedAt,children:[`changed `,Ne(e.updatedAt)]})]}),e.url&&(0,C.jsx)(`div`,{className:`font-mono text-xs [overflow-wrap:anywhere] text-fg-2`,title:e.url,children:Xl(e.url)}),S&&(0,C.jsx)(`div`,{className:`text-xs [overflow-wrap:anywhere] text-fg-2 opacity-70`,title:e.path,children:e.path}),(0,C.jsxs)(`div`,{className:b(`text-xs text-fg-2`,`flex flex-wrap gap-x-3.5 gap-y-1 [&_code]:text-[11.5px]`),children:[e.head&&(0,C.jsxs)(`span`,{title:e.committedAt,children:[(0,C.jsx)(`code`,{children:e.head}),` `,e.subject,e.committedAt?` · ${Ne(e.committedAt)}`:``]}),!!e.behind&&!!e.dirty&&(0,C.jsxs)(`span`,{children:[`behind by `,e.behind]}),e.error&&(0,C.jsx)(`span`,{className:`text-bad`,children:e.error})]}),o[e.slug]&&(0,C.jsx)(G,{tone:`bad`,children:o[e.slug]})]}),(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,C.jsx)(z,{size:`sm`,icon:`difference`,href:`/repos/${encodeURIComponent(e.slug)}`,title:`changed files with diffs, recent commits`,children:`changes`}),(0,C.jsx)(z,{size:`sm`,icon:`sync`,busy:t===`update`,disabled:!!t,onClick:()=>void E(e.slug,`update`),title:`git fetch, then fast-forward when clean`,children:t===`update`?`updating…`:`update`}),c!==e.slug&&(0,C.jsx)(z,{size:`sm`,icon:`delete`,disabled:!!t,onClick:()=>l(e.slug),title:`Move the clone to the trash`,children:`remove`}),c===e.slug&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(z,{size:`sm`,variant:`danger`,icon:`delete`,onClick:()=>void E(e.slug,`remove`,iu(e)),children:e.dirty||e.ahead?`delete with local changes`:iu(e)?`delete anyway`:`confirm remove`}),(0,C.jsx)(z,{size:`sm`,variant:`quiet`,onClick:()=>l(null),children:`cancel`})]})]})]},e.slug)})]})]})}var cu=40,lu=/Mac|iPhone|iPad/.test(navigator.platform),uu=null,du=e=>(e?.workspaces??[]).flatMap(e=>[...e.agents.map(t=>({kind:`agent`,agent:t,ws:e,key:`${e.url}|agent|${t.slug}`})),...(e.projects??[]).map(t=>({kind:`project`,project:t,ws:e,key:`${e.url}|project|${t.slug}`})),...(e.channels??[]).map(t=>({kind:`channel`,channel:t,ws:e,key:`${e.url}|channel|${t.slug}`}))]),fu=e=>e.kind===`agent`?e.agent.name:e.kind===`project`?e.project.title:e.channel.name,pu=e=>e.kind===`agent`?e.agent.description:e.kind===`project`?e.project.goal||(e.project.status===`active`?void 0:e.project.status):e.channel.purpose,mu=e=>e.kind===`agent`?`/agents/${encodeURIComponent(e.agent.slug)}`:e.kind===`project`?`/projects/${encodeURIComponent(e.project.slug)}`:`/channels/${encodeURIComponent(e.channel.slug)}`,hu={active:`📁`,paused:`⏸️`,done:`✅`,archived:`🗄️`},gu=e=>e.kind===`agent`?e.agent.emoji:e.kind===`project`?hu[e.project.status]:(0,C.jsx)(w,{name:`forum`,className:`text-[18px] text-fg-2`}),_u=`flex-none rounded-full border border-line px-1.5 py-px text-[10px] font-semibold tracking-[0.4px] uppercase`;function vu(e,t){let n=t.toLowerCase().split(/\s+/).filter(Boolean);if(n.length===0)return e;let r=[],i=new Map;for(let t of e){i.has(t.ws)||i.set(t.ws,i.size);let e=fu(t).toLowerCase(),a=[e,...t.kind===`agent`?[t.agent.slug,t.agent.description??``,t.agent.group??``,`agent`]:t.kind===`project`?[t.project.slug,t.project.goal??``,t.project.status,`project`]:[t.channel.slug,t.channel.purpose??``,`channel`],t.ws.name].join(` `).toLowerCase();if(!n.every(e=>a.includes(e)))continue;let o=e.startsWith(n[0])?0:e.includes(n[0])?1:2;r.push({hit:t,score:o,ws:i.get(t.ws)})}return r.sort((e,t)=>e.ws-t.ws||e.score-t.score).map(e=>e.hit)}function yu(e){let t=[];for(let n of e){let e=t.find(e=>e.ws===n.ws);e?e.hits.push(n):t.push({ws:n.ws,hits:[n]})}return t}async function bu(e){let t=mu(e);if(e.ws.current)return M(t);let n=e.ws.live||!e.ws.root?e.ws.url:await ae(e.ws.root);window.location.assign(`${n.replace(/\/+$/,``)}/#${t}`)}function xu(){let[e,t]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`k`&&(e.preventDefault(),t(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`button`,{type:`button`,className:`inline-flex flex-none cursor-pointer items-center gap-1.5 rounded-xl border-0 bg-transparent py-1 pr-2 pl-1.5 text-fg-2 transition-colors hover:bg-surface-2 hover:text-fg active:scale-96`,onClick:()=>t(!0),title:`jump to an agent, project or channel`,"aria-label":`search`,children:[(0,C.jsx)(w,{name:`search`}),(0,C.jsx)(Ve,{className:`max-[1100px]:hidden`,children:lu?`⌘K`:`Ctrl K`})]}),e&&(0,C.jsx)(Su,{onClose:()=>t(!1)})]})}function Su({onClose:e}){let[t,n]=(0,v.useState)(uu),[r,i]=(0,v.useState)(uu===null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(0),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(``),h=(0,v.useRef)(null);(0,v.useEffect)(()=>{let e=!0;return fetch(`/api/search/agents`,{cache:`no-store`}).then(e=>e.ok?e.json():Promise.reject(Error(String(e.status)))).then(t=>{uu=t,e&&n(t)}).catch(()=>e&&o(!0)).finally(()=>e&&i(!1)),()=>{e=!1}},[]);let g=(0,v.useMemo)(()=>du(t),[t]),_=(0,v.useMemo)(()=>vu(g,s).slice(0,cu),[g,s]),y=(0,v.useMemo)(()=>yu(_),[_]),x=Math.min(l,Math.max(_.length-1,0));(0,v.useEffect)(()=>{h.current?.querySelector(`[aria-selected="true"]`)?.scrollIntoView({block:`nearest`})},[x,_]);let S=t=>{if(!d){if(t.ws.current||t.ws.live){e(),bu(t);return}f(t.key),m(``),bu(t).catch(e=>{f(null),m(`${t.ws.name}: ${e.message}`)})}},T=t=>{if(t.key===`ArrowDown`)t.preventDefault(),u(_.length?(x+1)%_.length:0);else if(t.key===`ArrowUp`)t.preventDefault(),u(_.length?(x-1+_.length)%_.length:0);else if(t.key===`Enter`){t.preventDefault();let e=_[x];e&&S(e)}else t.key===`Escape`&&(t.preventDefault(),e())},E=`px-4 py-7 text-center text-sm text-fg-2 [&_a]:underline`,D;if(_.length>0){let e=-1;D=(0,C.jsx)(`ul`,{className:`m-0 list-none overflow-y-auto overscroll-contain p-1.5`,role:`listbox`,"aria-label":`agents, projects and channels`,ref:h,children:y.map(t=>(0,C.jsxs)(v.Fragment,{children:[(0,C.jsxs)(`li`,{className:`palette-group flex items-center gap-1.5 px-2.5 pt-3 pb-1 text-2xs font-semibold tracking-[0.4px] text-fg-2 uppercase first:pt-1.5`,role:`presentation`,title:t.ws.current?`this workspace`:t.ws.url,children:[t.ws.icon&&(0,C.jsx)(`span`,{"aria-hidden":!0,children:t.ws.icon}),(0,C.jsx)(`span`,{className:`truncate`,children:t.ws.name}),t.ws.current?(0,C.jsx)(`span`,{className:`font-normal tracking-normal normal-case`,children:`this workspace`}):t.ws.live?(0,C.jsx)(w,{name:`open_in_new`,className:`ms-sm`}):(0,C.jsx)(`span`,{className:_u,children:`stopped`})]}),t.hits.map(t=>{let n=++e;return(0,C.jsxs)(`li`,{role:`option`,"aria-selected":n===x,className:b(`flex cursor-pointer items-center gap-2.5 rounded-xl px-2.5 py-2`,n===x&&`bg-surface-2`),onMouseMove:()=>n!==x&&u(n),onClick:()=>S(t),children:[(0,C.jsx)(`span`,{className:`w-6 flex-none text-center text-[18px] leading-none`,"aria-hidden":!0,children:gu(t)}),(0,C.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,C.jsx)(`span`,{className:`truncate text-[13.5px] font-medium text-fg`,children:fu(t)}),pu(t)&&(0,C.jsx)(`span`,{className:`truncate text-xs text-fg-2`,children:pu(t)})]}),d===t.key?(0,C.jsx)(w,{name:`progress_activity`,className:`ms-sm`}):t.kind!==`agent`&&(0,C.jsx)(`span`,{className:b(_u,`text-fg-2`),children:t.kind})]},t.key)})]},t.ws.url||t.ws.name))})}else D=a?(0,C.jsx)(`div`,{className:E,children:`could not load the agents, projects and channels`}):r?(0,C.jsx)(`div`,{className:E,children:`looking for agents, projects and channels…`}):g.length===0?(0,C.jsxs)(`div`,{className:E,children:[`no agents yet — `,(0,C.jsx)(`a`,{href:`#/agents/new`,onClick:e,children:`create one`})]}):(0,C.jsxs)(`div`,{className:E,children:[`no agent, project or channel matches “`,s,`”`]});return(0,C.jsx)(`div`,{className:`palette-backdrop fixed inset-0 z-50 flex animate-fade items-start justify-center bg-black/35 px-4 pt-[12vh] pb-4`,onMouseDown:e,children:(0,C.jsxs)(`div`,{className:`flex max-h-[min(70dvh,560px)] w-[min(620px,100%)] animate-modal flex-col overflow-hidden rounded-2xl border border-line bg-surface shadow-modal`,role:`dialog`,"aria-label":`jump to an agent, project or channel`,onMouseDown:e=>e.stopPropagation(),onKeyDown:T,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2.5 border-b border-line px-4 py-3 text-fg-2`,children:[(0,C.jsx)(w,{name:`search`}),(0,C.jsx)(`input`,{autoFocus:!0,className:`min-w-0 flex-1 border-0 bg-transparent p-0 font-sans text-[16px] text-fg outline-none`,value:s,onChange:e=>{c(e.target.value),u(0)},placeholder:`jump to an agent, project or channel…`,"aria-label":`search`,autoComplete:`off`,spellCheck:!1}),r&&t&&(0,C.jsx)(w,{name:`progress_activity`,className:`ms-sm`}),(0,C.jsx)(Ve,{children:`esc`})]}),D,(0,C.jsxs)(`div`,{className:`flex items-center gap-3.5 border-t border-line px-3.5 py-2 text-2xs text-fg-2 [&>span]:inline-flex [&>span]:items-center [&>span]:gap-1`,children:[(0,C.jsxs)(`span`,{children:[(0,C.jsx)(Ve,{children:`↑`}),(0,C.jsx)(Ve,{children:`↓`}),` move`]}),(0,C.jsxs)(`span`,{children:[(0,C.jsx)(Ve,{children:`↵`}),` open`]}),d&&(0,C.jsxs)(`span`,{className:`ml-auto`,children:[(0,C.jsx)(w,{name:`progress_activity`,className:`ms-sm`}),` starting the workspace…`]}),p&&(0,C.jsxs)(`span`,{className:`ml-auto max-w-[60%] truncate text-bad`,title:p,children:[(0,C.jsx)(w,{name:`warning`,className:`ms-sm`}),` `,p]})]})]})})}var Cu=1296e5;function wu(e){if(e<6e4)return`just now`;let t=Math.floor(e/6e4);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h`:`${Math.floor(n/24)}d`}function Tu(e,t){let n=new Date(e),r=n.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),i=Math.round((new Date(n).setHours(0,0,0,0)-new Date(t).setHours(0,0,0,0))/864e5);return i<=0?r:i===1?`tomorrow ${r}`:`${n.toLocaleDateString([],{weekday:`short`})} ${r}`}function Eu(e,t=``,n=new Date){if(!e)return t?{text:t,tone:`plain`}:null;let r=e=>`${e[0].title||`a session`}${e.length>1?` +${e.length-1}`:``}`;if(e.waiting.length)return{text:`waiting for you · ${r(e.waiting)}`,tone:`waiting`};if(e.working.length){let t=e.working[0].since,i=t?wu(Math.max(0,n.getTime()-Date.parse(t))):``;return{text:`working · ${r(e.working)}${i&&i!==`just now`?` · ${i}`:``}`,tone:`working`}}if(e.nextRoutine&&Date.parse(e.nextRoutine.at)-n.getTime()<Cu)return{text:`next: ${e.nextRoutine.name} · ${Tu(e.nextRoutine.at,n)}`,tone:`plain`};if(e.lastActiveAt){let t=wu(Math.max(0,n.getTime()-Date.parse(e.lastActiveAt)));return{text:t===`just now`?`last active just now`:`last active ${t} ago`,tone:`plain`}}return{text:t||`no sessions yet`,tone:`plain`}}function Du({chatPath:e}){let t=me(),n=ue(),r=R(`/api/agents`,!1,15e3),i=R(`/api/channels`,!1,6e3),[a,o]=(0,v.useState)(0);(0,v.useEffect)(()=>{let e=()=>o(e=>e+1);return window.addEventListener(De,e),()=>window.removeEventListener(De,e)},[]);let s=R(t.projects?`/api/projects${a?`?rev=${a}`:``}`:``,!1,15e3),c=R(`/api/agent-status`,!1,5e3),l=R(t.vibeables?`/api/vibeables`:``,!1,15e3),u=new Set((l?.vibeables??[]).map(e=>e.slug)),d=e.split(`/`).filter(Boolean),f=(e,t)=>d[0]===e&&(t===void 0||(d[1]?decodeURIComponent(d[1]):void 0)===t),p=d[0]===`agents`&&d[1]===`chats`,[m,h]=Mu(),g=Ct()??[],_=new Map((r?.agents??[]).filter(e=>!e.archived).map(e=>[e.slug,e])),y=s?.projects??[];return(0,C.jsx)(`nav`,{className:`rail`,"aria-label":`Conversations`,children:(0,C.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-0.5 overflow-y-auto px-2 pt-2 pb-4`,children:[(0,C.jsx)(q,{href:`/`,active:e===`/`,leading:(0,C.jsx)(w,{name:`home`}),title:`Home`,sub:`Today: what needs you, what happened`}),(0,C.jsx)(q,{href:`/agents/chats`,active:p,leading:(0,C.jsx)(`span`,{"aria-hidden":!0,children:`🎩`}),title:`Ralv`,titleExtra:(0,C.jsx)(Be,{n:wt.general(g).length,title:`waiting for you`}),sub:`Chief of staff: knows the workspace, advises, launches things`}),t.projects&&(0,C.jsxs)(ku,{label:`projects`,href:`/projects`,add:s?.enabled?{href:`/projects/new`,label:`new project`}:void 0,badge:m.all?(0,C.jsx)(Be,{n:new Set(y.filter(e=>!f(`projects`,e.slug)).flatMap(e=>wt.project(g,e.slug,e.agents).map(e=>e.id))).size,title:`waiting in the projects folded away`}):void 0,fold:y.length>0?(0,C.jsx)(B,{size:`sm`,icon:m.all?`chevron_right`:`expand_more`,label:m.all?`show all projects`:`collapse projects`,"aria-expanded":!m.all,onClick:()=>h(e=>({...e,all:!e.all}))}):void 0,children:[y.filter(e=>!m.all||f(`projects`,e.slug)).map(e=>{let n=(e.agents??[]).map(e=>_.get(e)).filter(e=>!!e),r=t.vibeables?(e.vibeables??[]).filter(e=>u.has(e)):[],i=n.length+r.length>0,a=i&&(m.open[e.slug]??f(`projects`,e.slug)),o=n.map(e=>c?.[e.slug]).filter(e=>!!e),s=!a&&o.some(e=>e.working.length&&!e.waiting.length);return(0,C.jsxs)(v.Fragment,{children:[(0,C.jsx)(q,{href:`/projects/${encodeURIComponent(e.slug)}`,active:f(`projects`,e.slug),innerProps:{"data-project":e.slug},leading:(0,C.jsx)(`span`,{"aria-hidden":!0,children:e.status===`done`?`✅`:e.status===`paused`?`⏸️`:e.status===`archived`?`🗄️`:`📁`}),title:e.title,titleExtra:(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(Be,{n:wt.project(g,e.slug,e.agents).length,title:`waiting for you`}),s&&(0,C.jsx)(V,{tone:`working`,title:`an agent is working`})]}),sub:e.goal||(e.status===`active`?void 0:e.status),actionsAlways:!0,actions:i?(0,C.jsx)(B,{size:`sm`,icon:a?`expand_more`:`chevron_right`,label:`${a?`collapse`:`expand`} ${e.title}`,"aria-expanded":a,title:a?`hide its agents and apps`:`${n.length?`${n.length} agent${n.length===1?``:`s`}`:``}${n.length&&r.length?`, `:``}${r.length?`${r.length} app${r.length===1?``:`s`}`:``}`,onClick:()=>h(t=>({...t,open:{...t.open,[e.slug]:!a}}))}):void 0}),a&&n.map(e=>(0,C.jsx)(q,{className:Ou,size:`sm`,href:`/agents/${encodeURIComponent(e.slug)}`,active:f(`agents`,e.slug),innerProps:{title:e.description||e.name,"data-nested":`agent`},leading:(0,C.jsx)(`span`,{"aria-hidden":!0,children:e.emoji||`🤖`}),title:(0,C.jsx)(`span`,{className:`font-medium`,children:e.name}),titleExtra:(0,C.jsx)(Au,{n:wt.agent(g,e.slug).length,st:c?.[e.slug]})},e.slug)),a&&r.map(t=>(0,C.jsx)(q,{className:Ou,size:`sm`,href:`/projects/${encodeURIComponent(e.slug)}?app=${encodeURIComponent(t)}`,innerProps:{title:`open ${t} beside the project's chat`,"data-nested":`app`},leading:(0,C.jsx)(w,{name:`web`,className:`ms-sm`}),title:(0,C.jsx)(`span`,{className:`font-medium`,children:t})},`app:${t}`))]},e.slug)}),m.all&&y.length>0&&(0,C.jsxs)(z,{variant:`quiet`,size:`sm`,icon:`expand_more`,className:`justify-start`,onClick:()=>h(e=>({...e,all:!1})),children:[y.filter(e=>!f(`projects`,e.slug)).length,` more`]})]}),(0,C.jsx)(ku,{label:`agents`,href:`/agents`,add:n?{href:`/agents/new`,label:`new agent`}:void 0,children:(r?.agents??[]).filter(e=>!e.archived).map(e=>{let t=Eu(c?.[e.slug],e.description);return(0,C.jsx)(q,{href:`/agents/${encodeURIComponent(e.slug)}`,active:f(`agents`,e.slug)||f(`team`,e.slug),innerProps:{title:e.description||void 0},leading:(0,C.jsx)(`span`,{"aria-hidden":!0,children:e.emoji||`🤖`}),title:e.name,titleExtra:(0,C.jsx)(Au,{n:wt.agent(g,e.slug).length,st:c?.[e.slug]}),sub:t?(0,C.jsx)(`span`,{className:`rail-status${t.tone===`plain`?``:` ${t.tone}`}`,children:t.text}):void 0,subTone:t?.tone===`waiting`?`bad`:t?.tone===`working`?`accent`:`plain`},e.slug)})}),(0,C.jsx)(ku,{label:`channels`,href:`/channels`,add:{href:`/channels/new`,label:`new channel`},children:(i?.channels??[]).map(e=>(0,C.jsx)(q,{href:`/channels/${encodeURIComponent(e.slug)}`,active:f(`channels`,e.slug),leading:(0,C.jsx)(`span`,{"aria-hidden":!0,className:`font-semibold`,children:`#`}),title:e.name,titleExtra:(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(Be,{n:wt.channel(g,e.slug).length,title:`waiting for you`}),e.busy&&!e.awaitingApproval&&(0,C.jsx)(V,{tone:`working`,title:`an agent is working`})]}),sub:e.purpose||(e.members.length?`with ${e.members.map(e=>`@${e}`).join(` `)}`:`no agents yet`)},e.slug))})]})})}var Ou=`ml-5 rounded-l-none border-l border-line`;function ku({label:e,href:t,add:n,badge:r,fold:i,children:a}){return(0,C.jsxs)(`div`,{className:`mt-3 flex flex-col gap-0.5`,role:`group`,"aria-label":e[0].toUpperCase()+e.slice(1),children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-1 pl-2.5 pr-1`,children:[(0,C.jsx)(P,{href:t,className:`flex-1 px-0 py-1 text-2xs font-semibold uppercase tracking-[0.08em] text-accent no-underline hover:underline`,children:e}),r,n&&(0,C.jsx)(B,{size:`sm`,icon:`add`,label:n.label,href:n.href}),i]}),a]})}function Au({n:e,st:t}){return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(Be,{n:e,title:`waiting for you`}),!e&&t?.working.length&&!t.waiting.length?(0,C.jsx)(V,{tone:`working`,title:`working`}):null]})}var ju=`kw-rail-fold`;function Mu(){let[e,t]=(0,v.useState)(()=>{try{let e=JSON.parse(localStorage.getItem(ju)??`null`);return{all:!!e?.all,open:e?.open&&typeof e.open==`object`?e.open:{}}}catch{return{all:!1,open:{}}}});return[e,e=>t(t=>{let n=e(t);try{localStorage.setItem(ju,JSON.stringify(n))}catch{}return n})]}function Nu({path:e}){let t=ue(),n=me(),r=e.split(`/`).filter(Boolean)[0]??``;if(!t)return null;let i=[{id:`workflows`,href:`/workflows`,label:`workflows`,icon:`account_tree`},{id:`knowledge`,href:`/knowledge`,label:`knowledge`,icon:`menu_book`},{id:`files`,href:`/files`,label:`files`,icon:`folder_open`},...n.vibeables?[{id:`vibeables`,href:`/vibeables`,label:`apps`,icon:`web`}]:[],{id:`skills`,href:`/skills`,label:`skills`,icon:`extension`},...n.repos?[{id:`repos`,href:`/repos`,label:`repositories`,icon:`source`}]:[],...n.git?[{id:`git`,href:`/git`,label:`git`,icon:`cloud_sync`,badge:(0,C.jsx)(Pu,{})}]:[],{id:`workspaces`,href:`/workspaces`,label:`workspaces`,icon:`grid_view`},{id:`settings`,href:`/settings`,label:`settings`,icon:`settings`},{id:`trash`,href:`/trash`,label:`trash`,icon:`delete`}],a=e=>r===e||e===`workflows`&&r===`runs`;return(0,C.jsx)(`nav`,{className:`global-nav flex min-w-0 flex-[0_1_auto] justify-start gap-0.5 overflow-x-auto [scrollbar-width:none] max-[1199px]:[mask-image:linear-gradient(to_right,#000_calc(100%-24px),transparent)] max-[800px]:hidden`,"aria-label":`Workspace`,children:i.map(e=>{let t=a(e.id);return(0,C.jsxs)(`a`,{href:`#${e.href}`,className:b(`inline-flex flex-none items-center gap-1.5 rounded-full px-3 py-1.5 text-[13.5px] font-semibold no-underline transition-colors`,`[&_.ms]:text-[18px] max-[1520px]:gap-[5px] max-[1520px]:[&_.ms]:text-[17px]`,t?`bg-surface text-accent shadow-[inset_0_0_0_1px_var(--line)]`:`text-fg-2 hover:bg-surface-2 hover:text-fg`),"aria-current":t?`page`:void 0,children:[(0,C.jsx)(w,{name:e.icon,fill:t}),` `,e.label,e.badge]},e.id)})})}function Pu(){let e=R(`/api/git`,!1,15e3),t=e?.files?.filter(e=>e.syncable).length??0,n=`ml-[5px] rounded-full bg-surface-2 px-1.5 py-px text-[10.5px] font-semibold tabular-nums`;return(0,C.jsxs)(C.Fragment,{children:[!!e?.behind&&(0,C.jsxs)(`span`,{className:b(n,`text-accent`),children:[e.behind,`↓`]}),!!e?.ahead&&(0,C.jsxs)(`span`,{className:b(n,`text-ok`),children:[e.ahead,`↑`]}),!e?.ahead&&!e?.behind&&!!t&&(0,C.jsx)(`span`,{className:n,children:t})]})}var Fu=e=>e.replace(/^# .*\n+/,``).replace(/\(human:user\)/g,`(you)`),Iu=`flex flex-col gap-1.5 px-1.5 pb-6 pt-1`,Lu=`m-0 px-2.5 pb-0.5 pt-1.5 text-md leading-[1.45] text-fg`,Ru=`m-0 px-2.5 py-0.5 text-sm text-fg-2`,zu=`md-body px-2.5 text-sm leading-normal`,Bu=e=>Qi.sanitize(Cr.parse(Fu(e),{async:!1}));function Vu(e,t){let n=[],r=``;for(let i of e.split(`
226
+ `)[0]]})]}),children:e.error?(0,C.jsxs)(`div`,{className:`flex items-center gap-2 p-[18px] text-sm text-bad`,children:[(0,C.jsx)(w,{name:`error`,className:`ms-sm`}),` `,e.error]}):(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-[18px] py-3.5`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 text-base`,children:[(0,C.jsx)(w,{name:`account_tree`,className:`ms-sm`}),(0,C.jsx)(`strong`,{className:`font-mono`,children:e.branch}),(0,C.jsx)(`span`,{className:Gl,children:e.upstream?`tracking ${e.upstream}`:`no upstream yet, push sets one`})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2.5 text-[12.5px] font-semibold`,children:[e.diverged&&(0,C.jsx)(`span`,{className:`text-bad`,children:`diverged, resolve in a terminal`}),!!e.behind&&(0,C.jsxs)(`span`,{className:`text-accent`,children:[e.behind,` behind`]}),!!e.ahead&&(0,C.jsxs)(`span`,{className:`text-ok`,children:[e.ahead,` ahead`]}),!e.ahead&&!e.behind&&(0,C.jsx)(`span`,{className:b(`text-xs text-fg-2`,`font-normal`),children:`up to date`})]}),(0,C.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,C.jsx)(z,{size:`sm`,icon:`refresh`,busy:c===`fetch`,disabled:!!c,onClick:()=>void g(`fetch`),children:`fetch`}),(0,C.jsx)(z,{size:`sm`,icon:`download`,busy:c===`pull`,disabled:!!c||!e.behind||e.diverged,title:e.diverged?`Diverged. Resolve in a terminal.`:`Fast-forward to the remote`,onClick:()=>void g(`pull`),children:`pull`}),(0,C.jsx)(z,{size:`sm`,variant:`primary`,icon:`upload`,busy:c===`push`,disabled:!!c||!e.ahead&&!!e.upstream,title:e.upstream?`Push to the upstream`:`Push and set the upstream`,onClick:()=>void g(`push`),children:`push`})]})]})}),(0,C.jsxs)(K,{title:`changes`,actions:(0,C.jsx)(`span`,{className:Gl,children:y.length===0?`workspace clean`:`${n.size} of ${y.length} selected`}),children:[y.length===0&&x.length===0&&(0,C.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`Nothing changed under the workspace paths.`}),y.map(e=>(0,C.jsxs)(`div`,{className:b(`git-row px-[18px]`,Jl),children:[(0,C.jsx)(`input`,{type:`checkbox`,className:`accent-accent`,"aria-label":`select ${e.path}`,checked:n.has(e.path),onChange:t=>S(e.path,t.target.checked)}),(0,C.jsxs)(`button`,{type:`button`,className:`group/file flex min-w-0 flex-1 cursor-pointer items-center gap-2 border-0 bg-transparent px-0 py-0.5 text-left font-[inherit] text-fg`,onClick:()=>a(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),children:[(0,C.jsx)(w,{name:i.has(e.path)?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,C.jsx)(Wl,{status:e.status}),(0,C.jsx)(`span`,{className:b(Yl,`group-hover/file:underline`),children:e.path})]}),i.has(e.path)&&(0,C.jsx)(Bl,{file:e.path})]},e.path)),y.length>0&&(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5 border-t border-line bg-surface-2 px-[18px] py-3`,children:[(0,C.jsx)(J,{className:`min-w-[220px] flex-1 text-sm`,placeholder:`Commit message`,"aria-label":`commit message`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!c&&o.trim()&&n.size>0&&_()}}),(0,C.jsx)(z,{size:`sm`,disabled:n.size===y.length,onClick:()=>r(new Set(y.map(e=>e.path))),children:`select all`}),(0,C.jsxs)(z,{size:`sm`,variant:`primary`,icon:`check`,busy:c===`commit`,disabled:!!c||n.size===0||!o.trim(),onClick:()=>void _(),children:[`commit `,n.size||``]})]}),x.length>0&&(0,C.jsxs)(`details`,{className:`border-t border-line px-[18px] py-2.5`,children:[(0,C.jsxs)(`summary`,{className:`cursor-pointer text-[12.5px] text-fg-2`,children:[x.length,e.blockedHidden?`+`:``,` change`,x.length===1&&!e.blockedHidden?``:`s`,` outside the workspace paths`]}),x.map(e=>(0,C.jsxs)(`div`,{className:b(`git-row blocked opacity-60`,Jl),children:[(0,C.jsx)(Wl,{status:e.status,muted:!0}),(0,C.jsx)(`span`,{className:Yl,children:e.path}),(0,C.jsx)(`span`,{className:`text-xs text-fg-2`,children:e.reason})]},e.path)),!!e.blockedHidden&&(0,C.jsx)(`div`,{className:b(`git-row blocked opacity-60`,Jl),children:(0,C.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`and `,e.blockedHidden,` more, not listed`]})})]})]}),(0,C.jsxs)(`p`,{className:b(Gl,`m-0`),children:[`Synced paths: `,(e.scope??[]).map((e,t)=>(0,C.jsxs)(`span`,{children:[t>0&&`, `,(0,C.jsx)(`code`,{children:e})]},e)),`. Run artifacts and files like `,(0,C.jsx)(`code`,{children:`.env`}),` are never staged.`,` `,e.interval?`Fetches every ${Ll(e.interval)}${e.autosync===`pull`?` and fast-forwards when the working tree is clean`:``}. `:`Background fetching is off. `,`Commit and push are always manual.`]})]})}var Jl=`flex flex-wrap items-center gap-2.5 py-2 [&+&]:border-t [&+&]:border-line`,Yl=`truncate font-mono text-[12.5px]`,Xl=e=>e.replace(/^https?:\/\//,``).replace(/^git@([^:]+):/,`$1/`).replace(/\.git$/,``),Zl=e=>e.error?{label:`unreadable`,state:`unreadable`}:e.dirty?{label:`${e.dirty} changed`,state:`changed`}:e.ahead?{label:`${e.ahead} to push`,state:`clean`}:e.behind?{label:`${e.behind} behind`,state:`behind`}:{label:`clean`,state:`clean`};function Ql({label:e,state:t}){return(0,C.jsx)(`span`,{className:b(`inline-flex items-center text-2xs font-semibold tracking-[0.4px] uppercase`,t===`clean`?`text-ok`:t===`changed`?`text-ask`:t===`unreadable`?`text-bad`:`text-fg-2`),children:e})}var $l=`rounded-full border border-line px-[7px] py-px font-mono text-xs text-fg-2`,eu=`border-line px-[18px] py-2 [&+&]:border-t`,tu=`group/item flex w-full cursor-pointer items-center gap-2 border-0 bg-transparent px-0 py-0.5 text-left font-[inherit] text-fg`,nu=`min-w-0 truncate font-mono text-[12.5px] group-hover/item:underline`;function ru({title:e,children:t}){return(0,C.jsxs)(`header`,{className:`flex flex-wrap items-center gap-3`,children:[(0,C.jsx)(z,{size:`sm`,variant:`quiet`,icon:`arrow_back`,href:`/repos`,title:`all repositories`,children:`repositories`}),(0,C.jsx)(w,{name:`folder_data`,className:`text-[26px] text-fg-2`}),(0,C.jsx)(We,{children:e}),t]})}var iu=e=>!!(e.error||e.dirty||e.ahead===void 0||e.ahead);function au({slug:e}){return e?(0,C.jsx)(ou,{slug:e}):(0,C.jsx)(su,{})}function ou({slug:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(0),h=ue(),g=(0,v.useCallback)(async()=>{try{let t=await fetch(`/api/repos/${encodeURIComponent(e)}`,{cache:`no-store`}),r=await t.json();if(!t.ok)throw Error(r.error||`HTTP ${t.status}`);n(r),i(``)}catch(e){i(e.message||`could not load the repository`)}},[e]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await g(),e&&(t=setTimeout(n,5e3))};return n(),()=>{e=!1,clearTimeout(t)}},[g,p]);let _=async()=>{u(`update`),f(``);try{let t=await fetch(`/api/repos/${encodeURIComponent(e)}/update`,{method:`POST`}),n=await t.json();if(!t.ok||!n.ok)throw Error(n.error||`failed`);n.error&&f(n.error)}catch(e){f(e.message)}finally{u(``),m(e=>e+1)}};if(r&&!t)return(0,C.jsxs)(Ke,{className:`repo-page`,children:[(0,C.jsx)(ru,{title:e}),(0,C.jsx)(G,{tone:`bad`,children:r})]});if(!t)return(0,C.jsx)(W,{children:`loading…`});let y=Zl(t),x=t.commits.filter(e=>e.local).length;return(0,C.jsxs)(Ke,{className:`repo-page`,children:[(0,C.jsxs)(ru,{title:t.slug,children:[t.branch&&(0,C.jsx)(`span`,{className:$l,children:t.branch}),t.upstream&&(0,C.jsxs)(`span`,{className:`text-xs text-fg-2`,title:`upstream`,children:[`→ `,t.upstream]}),(0,C.jsx)(Ql,{...y}),(0,C.jsx)(`span`,{className:`flex-1`}),(0,C.jsx)(z,{size:`sm`,icon:`sync`,busy:l===`update`,disabled:!!l,onClick:()=>void _(),title:`git fetch, then fast-forward when clean`,children:l===`update`?`updating…`:`update`})]}),(0,C.jsxs)(`div`,{className:b(Gl,`flex flex-wrap gap-x-3.5 gap-y-1`),children:[t.url&&(0,C.jsx)(`span`,{title:t.url,children:Xl(t.url)}),h&&(0,C.jsx)(`span`,{title:t.path,children:t.path}),t.head&&(0,C.jsxs)(`span`,{children:[`at `,(0,C.jsx)(`code`,{children:t.head}),t.committedAt?` · ${Ne(t.committedAt)}`:``]}),!!t.ahead&&(0,C.jsxs)(`span`,{children:[t.ahead,` to push`]}),!!t.behind&&(0,C.jsxs)(`span`,{children:[t.behind,` behind`]}),t.updatedAt&&(0,C.jsxs)(`span`,{children:[`changed `,Ne(t.updatedAt)]})]}),(t.error||d||r)&&(0,C.jsx)(G,{tone:`bad`,children:t.error||d||r}),(0,C.jsxs)(K,{title:`changes · working tree against HEAD`,actions:(0,C.jsxs)(`span`,{className:Gl,children:[t.files.length,` file`,t.files.length===1?``:`s`,t.insertions||t.deletions?(0,C.jsxs)(C.Fragment,{children:[` · `,(0,C.jsxs)(`span`,{className:`text-ok`,children:[`+`,t.insertions]}),` `,(0,C.jsxs)(`span`,{className:`text-bad`,children:[`−`,t.deletions]})]}):null]}),children:[t.files.length===0&&(0,C.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`Clean — nothing changed since the last commit.`}),t.files.map(n=>(0,C.jsxs)(`div`,{className:b(`repo-file`,eu),"data-file":n.path,children:[(0,C.jsxs)(`button`,{type:`button`,className:tu,onClick:()=>o(a===n.path?null:n.path),children:[(0,C.jsx)(w,{name:a===n.path?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,C.jsx)(Wl,{status:n.status}),(0,C.jsx)(`span`,{className:nu,children:n.path})]}),a===n.path&&(0,C.jsx)(Vl,{url:`/api/repos/${encodeURIComponent(e)}/diff?path=${encodeURIComponent(n.path)}&v=${encodeURIComponent(t.updatedAt??``)}`})]},n.path))]}),(0,C.jsxs)(K,{title:`commits · newest first`,actions:(0,C.jsx)(`span`,{className:Gl,children:x?`${x} not pushed`:t.commits.length?`all pushed`:``}),children:[t.commits.length===0&&(0,C.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`No commits yet.`}),t.commits.map(t=>(0,C.jsxs)(`div`,{className:b(`repo-commit`,eu),"data-commit":t.short,children:[(0,C.jsxs)(`button`,{type:`button`,className:tu,onClick:()=>c(s===t.hash?null:t.hash),title:t.hash,children:[(0,C.jsx)(w,{name:s===t.hash?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,C.jsx)(`code`,{className:`text-xs`,children:t.short}),(0,C.jsx)(`span`,{className:`min-w-0 truncate text-sm group-hover/item:underline`,children:t.subject}),t.local&&(0,C.jsx)(H,{tone:`accent`,children:`not pushed`}),(0,C.jsxs)(`span`,{className:b(Gl,`ml-auto flex-none`),children:[t.author,` · `,Ne(t.committedAt)]})]}),s===t.hash&&(0,C.jsx)(Vl,{url:`/api/repos/${encodeURIComponent(e)}/commits/${t.hash}`})]},t.hash))]})]})}function su(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)({}),[o,s]=(0,v.useState)({}),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(!1),[y,x]=(0,v.useState)(``),S=ue(),T=(0,v.useCallback)(async()=>{try{let e=await fetch(`/api/repos`,{cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);t(await e.json()),r(``)}catch(e){r(e.message||`could not load repositories`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await T(),e&&(t=setTimeout(n,15e3))};return n(),()=>{e=!1,clearTimeout(t)}},[T]);let E=async(e,t,n=!1)=>{a(n=>({...n,[e]:t})),s(t=>({...t,[e]:``})),l(null);try{let r=t===`update`?await fetch(`/api/repos/${encodeURIComponent(e)}/update`,{method:`POST`}):await fetch(`/api/repos/${encodeURIComponent(e)}${n?`?force=1`:``}`,{method:`DELETE`}),i=await r.json();if(!r.ok||!i.ok)throw Error(i.error||`failed`);i.error&&s(t=>({...t,[e]:i.error}))}catch(t){s(n=>({...n,[e]:t.message}))}finally{a(t=>{let n={...t};return delete n[e],n}),T()}},D=async e=>{if(e.preventDefault(),u.trim()&&!g){_(!0),x(``);try{let e=await fetch(`/api/repos`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({url:u.trim(),name:f.trim()||void 0,branch:m.trim()||void 0})}),t=await e.json();if(!e.ok)throw Error(t.error||`clone failed`);d(``),p(``),h(``),await T()}catch(e){x(e.message)}finally{_(!1)}}},O=[...e?.repos??[]].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));return(0,C.jsxs)(Ke,{children:[(0,C.jsx)(Ge,{icon:`source`,title:`Repositories`,actions:(0,C.jsxs)(C.Fragment,{children:[e?.enabled&&(0,C.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[O.length,` cloned`]}),n&&(0,C.jsx)(G,{tone:`bad`,children:n})]})}),e&&!e.enabled&&(0,C.jsx)(K,{children:(0,C.jsx)(`div`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:e.error&&!/are off/.test(e.error)?(0,C.jsx)(G,{tone:`bad`,children:e.error}):(0,C.jsxs)(C.Fragment,{children:[`Repositories are off. Turn them on in `,(0,C.jsx)(`a`,{href:`#/settings`,children:`settings`}),` or add a `,(0,C.jsx)(`code`,{children:`repos:`}),` block to kraftwerk.yml.`]})})}),e?.enabled&&(0,C.jsx)(K,{title:`add a repository`,actions:(0,C.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`clones into `,(0,C.jsx)(`code`,{title:e.root,children:e.root})]}),children:(0,C.jsxs)(`form`,{className:`flex flex-col gap-2.5 p-[18px]`,onSubmit:e=>void D(e),children:[(0,C.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2.5`,children:[(0,C.jsx)(Y,{label:`url`,className:`min-w-[240px] flex-[2]`,children:(0,C.jsx)(J,{value:u,placeholder:`https://github.com/org/repo.git, git@host:org/repo.git or github:org/repo`,onChange:e=>d(e.target.value),autoFocus:!0})}),(0,C.jsx)(Y,{label:`name`,className:`min-w-[140px] flex-1`,children:(0,C.jsx)(J,{value:f,placeholder:`from the url`,onChange:e=>p(e.target.value)})}),(0,C.jsx)(Y,{label:`branch`,className:`w-[140px]`,children:(0,C.jsx)(J,{value:m,placeholder:`default`,onChange:e=>h(e.target.value)})}),(0,C.jsx)(z,{type:`submit`,variant:`primary`,icon:`download`,busy:g,disabled:!u.trim(),children:g?`cloning…`:`clone`})]}),y&&(0,C.jsx)(G,{tone:`bad`,children:y}),(0,C.jsxs)(`p`,{className:b(`text-xs text-fg-2`,`m-0`),children:[`Uses your own git credentials and never prompts: a private remote must already work from a terminal. Agents see every clone here and can add more with `,(0,C.jsx)(`code`,{children:`kraftwerk repos add`}),`.`]})]})}),e?.enabled&&(0,C.jsxs)(K,{title:`cloned repositories · newest change first`,children:[O.length===0&&(0,C.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`Nothing cloned yet.`}),O.map(e=>{let t=i[e.slug],n=Zl(e);return(0,C.jsxs)(`div`,{className:b(`repo-row grid grid-cols-[40px_minmax(0,1fr)_auto] items-start gap-3.5 border-line px-[18px] py-3.5 [&+&]:border-t`,n.state===`changed`&&`bg-ask-soft/40`),"data-repo":e.slug,children:[(0,C.jsx)(`span`,{className:b(`grid size-10 place-items-center rounded-full bg-surface-2 text-fg-2`,n.state===`unreadable`&&`opacity-45 grayscale`),children:(0,C.jsx)(w,{name:`folder_data`,className:`text-[22px]`})}),(0,C.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-[3px]`,children:[(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,C.jsx)(P,{href:`/repos/${encodeURIComponent(e.slug)}`,className:`text-md font-semibold text-fg no-underline hover:underline`,title:`changes and commits`,children:e.slug}),e.branch&&(0,C.jsx)(`span`,{className:$l,children:e.branch}),(0,C.jsx)(Ql,{...n}),e.updatedAt&&(0,C.jsxs)(`span`,{className:`text-xs text-fg-2`,title:e.updatedAt,children:[`changed `,Ne(e.updatedAt)]})]}),e.url&&(0,C.jsx)(`div`,{className:`font-mono text-xs [overflow-wrap:anywhere] text-fg-2`,title:e.url,children:Xl(e.url)}),S&&(0,C.jsx)(`div`,{className:`text-xs [overflow-wrap:anywhere] text-fg-2 opacity-70`,title:e.path,children:e.path}),(0,C.jsxs)(`div`,{className:b(`text-xs text-fg-2`,`flex flex-wrap gap-x-3.5 gap-y-1 [&_code]:text-[11.5px]`),children:[e.head&&(0,C.jsxs)(`span`,{title:e.committedAt,children:[(0,C.jsx)(`code`,{children:e.head}),` `,e.subject,e.committedAt?` · ${Ne(e.committedAt)}`:``]}),!!e.behind&&!!e.dirty&&(0,C.jsxs)(`span`,{children:[`behind by `,e.behind]}),e.error&&(0,C.jsx)(`span`,{className:`text-bad`,children:e.error})]}),o[e.slug]&&(0,C.jsx)(G,{tone:`bad`,children:o[e.slug]})]}),(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,C.jsx)(z,{size:`sm`,icon:`difference`,href:`/repos/${encodeURIComponent(e.slug)}`,title:`changed files with diffs, recent commits`,children:`changes`}),(0,C.jsx)(z,{size:`sm`,icon:`sync`,busy:t===`update`,disabled:!!t,onClick:()=>void E(e.slug,`update`),title:`git fetch, then fast-forward when clean`,children:t===`update`?`updating…`:`update`}),c!==e.slug&&(0,C.jsx)(z,{size:`sm`,icon:`delete`,disabled:!!t,onClick:()=>l(e.slug),title:`Move the clone to the trash`,children:`remove`}),c===e.slug&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(z,{size:`sm`,variant:`danger`,icon:`delete`,onClick:()=>void E(e.slug,`remove`,iu(e)),children:e.dirty||e.ahead?`delete with local changes`:iu(e)?`delete anyway`:`confirm remove`}),(0,C.jsx)(z,{size:`sm`,variant:`quiet`,onClick:()=>l(null),children:`cancel`})]})]})]},e.slug)})]})]})}var cu=40,lu=/Mac|iPhone|iPad/.test(navigator.platform),uu=null,du=e=>(e?.workspaces??[]).flatMap(e=>[...e.agents.map(t=>({kind:`agent`,agent:t,ws:e,key:`${e.url}|agent|${t.slug}`})),...(e.projects??[]).map(t=>({kind:`project`,project:t,ws:e,key:`${e.url}|project|${t.slug}`})),...(e.channels??[]).map(t=>({kind:`channel`,channel:t,ws:e,key:`${e.url}|channel|${t.slug}`}))]),fu=e=>e.kind===`agent`?e.agent.name:e.kind===`project`?e.project.title:e.channel.name,pu=e=>e.kind===`agent`?e.agent.description:e.kind===`project`?e.project.goal||(e.project.status===`active`?void 0:e.project.status):e.channel.purpose,mu=e=>e.kind===`agent`?`/agents/${encodeURIComponent(e.agent.slug)}`:e.kind===`project`?`/projects/${encodeURIComponent(e.project.slug)}`:`/channels/${encodeURIComponent(e.channel.slug)}`,hu={active:`📁`,paused:`⏸️`,done:`✅`,archived:`🗄️`},gu=e=>e.kind===`agent`?e.agent.emoji:e.kind===`project`?hu[e.project.status]:(0,C.jsx)(w,{name:`forum`,className:`text-[18px] text-fg-2`}),_u=`flex-none rounded-full border border-line px-1.5 py-px text-[10px] font-semibold tracking-[0.4px] uppercase`;function vu(e,t){let n=t.toLowerCase().split(/\s+/).filter(Boolean);if(n.length===0)return e;let r=[],i=new Map;for(let t of e){i.has(t.ws)||i.set(t.ws,i.size);let e=fu(t).toLowerCase(),a=[e,...t.kind===`agent`?[t.agent.slug,t.agent.description??``,t.agent.group??``,`agent`]:t.kind===`project`?[t.project.slug,t.project.goal??``,t.project.status,`project`]:[t.channel.slug,t.channel.purpose??``,`channel`],t.ws.name].join(` `).toLowerCase();if(!n.every(e=>a.includes(e)))continue;let o=e.startsWith(n[0])?0:e.includes(n[0])?1:2;r.push({hit:t,score:o,ws:i.get(t.ws)})}return r.sort((e,t)=>e.ws-t.ws||e.score-t.score).map(e=>e.hit)}function yu(e){let t=[];for(let n of e){let e=t.find(e=>e.ws===n.ws);e?e.hits.push(n):t.push({ws:n.ws,hits:[n]})}return t}async function bu(e){let t=mu(e);if(e.ws.current)return M(t);let n=e.ws.live||!e.ws.root?e.ws.url:await ae(e.ws.root);window.location.assign(`${n.replace(/\/+$/,``)}/#${t}`)}function xu(){let[e,t]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`k`&&(e.preventDefault(),t(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`button`,{type:`button`,className:`inline-flex flex-none cursor-pointer items-center gap-1.5 rounded-xl border-0 bg-transparent py-1 pr-2 pl-1.5 text-fg-2 transition-colors hover:bg-surface-2 hover:text-fg active:scale-96`,onClick:()=>t(!0),title:`jump to an agent, project or channel`,"aria-label":`search`,children:[(0,C.jsx)(w,{name:`search`}),(0,C.jsx)(Ve,{className:`max-[1100px]:hidden`,children:lu?`⌘K`:`Ctrl K`})]}),e&&(0,C.jsx)(Su,{onClose:()=>t(!1)})]})}function Su({onClose:e}){let[t,n]=(0,v.useState)(uu),[r,i]=(0,v.useState)(uu===null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(0),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(``),h=(0,v.useRef)(null);(0,v.useEffect)(()=>{let e=!0;return fetch(`/api/search/agents`,{cache:`no-store`}).then(e=>e.ok?e.json():Promise.reject(Error(String(e.status)))).then(t=>{uu=t,e&&n(t)}).catch(()=>e&&o(!0)).finally(()=>e&&i(!1)),()=>{e=!1}},[]);let g=(0,v.useMemo)(()=>du(t),[t]),_=(0,v.useMemo)(()=>vu(g,s).slice(0,cu),[g,s]),y=(0,v.useMemo)(()=>yu(_),[_]),x=Math.min(l,Math.max(_.length-1,0));(0,v.useEffect)(()=>{h.current?.querySelector(`[aria-selected="true"]`)?.scrollIntoView({block:`nearest`})},[x,_]);let S=t=>{if(!d){if(t.ws.current||t.ws.live){e(),bu(t);return}f(t.key),m(``),bu(t).catch(e=>{f(null),m(`${t.ws.name}: ${e.message}`)})}},T=t=>{if(t.key===`ArrowDown`)t.preventDefault(),u(_.length?(x+1)%_.length:0);else if(t.key===`ArrowUp`)t.preventDefault(),u(_.length?(x-1+_.length)%_.length:0);else if(t.key===`Enter`){t.preventDefault();let e=_[x];e&&S(e)}else t.key===`Escape`&&(t.preventDefault(),e())},E=`px-4 py-7 text-center text-sm text-fg-2 [&_a]:underline`,D;if(_.length>0){let e=-1;D=(0,C.jsx)(`ul`,{className:`m-0 list-none overflow-y-auto overscroll-contain p-1.5`,role:`listbox`,"aria-label":`agents, projects and channels`,ref:h,children:y.map(t=>(0,C.jsxs)(v.Fragment,{children:[(0,C.jsxs)(`li`,{className:`palette-group flex items-center gap-1.5 px-2.5 pt-3 pb-1 text-2xs font-semibold tracking-[0.4px] text-fg-2 uppercase first:pt-1.5`,role:`presentation`,title:t.ws.current?`this workspace`:t.ws.url,children:[t.ws.icon&&(0,C.jsx)(`span`,{"aria-hidden":!0,children:t.ws.icon}),(0,C.jsx)(`span`,{className:`truncate`,children:t.ws.name}),t.ws.current?(0,C.jsx)(`span`,{className:`font-normal tracking-normal normal-case`,children:`this workspace`}):t.ws.live?(0,C.jsx)(w,{name:`open_in_new`,className:`ms-sm`}):(0,C.jsx)(`span`,{className:_u,children:`stopped`})]}),t.hits.map(t=>{let n=++e;return(0,C.jsxs)(`li`,{role:`option`,"aria-selected":n===x,className:b(`flex cursor-pointer items-center gap-2.5 rounded-xl px-2.5 py-2`,n===x&&`bg-surface-2`),onMouseMove:()=>n!==x&&u(n),onClick:()=>S(t),children:[(0,C.jsx)(`span`,{className:`w-6 flex-none text-center text-[18px] leading-none`,"aria-hidden":!0,children:gu(t)}),(0,C.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,C.jsx)(`span`,{className:`truncate text-[13.5px] font-medium text-fg`,children:fu(t)}),pu(t)&&(0,C.jsx)(`span`,{className:`truncate text-xs text-fg-2`,children:pu(t)})]}),d===t.key?(0,C.jsx)(w,{name:`progress_activity`,className:`ms-sm`}):t.kind!==`agent`&&(0,C.jsx)(`span`,{className:b(_u,`text-fg-2`),children:t.kind})]},t.key)})]},t.ws.url||t.ws.name))})}else D=a?(0,C.jsx)(`div`,{className:E,children:`could not load the agents, projects and channels`}):r?(0,C.jsx)(`div`,{className:E,children:`looking for agents, projects and channels…`}):g.length===0?(0,C.jsxs)(`div`,{className:E,children:[`no agents yet — `,(0,C.jsx)(`a`,{href:`#/agents/new`,onClick:e,children:`create one`})]}):(0,C.jsxs)(`div`,{className:E,children:[`no agent, project or channel matches “`,s,`”`]});return(0,C.jsx)(`div`,{className:`palette-backdrop fixed inset-0 z-50 flex animate-fade items-start justify-center bg-black/35 px-4 pt-[12vh] pb-4`,onMouseDown:e,children:(0,C.jsxs)(`div`,{className:`flex max-h-[min(70dvh,560px)] w-[min(620px,100%)] animate-modal flex-col overflow-hidden rounded-2xl border border-line bg-surface shadow-modal`,role:`dialog`,"aria-label":`jump to an agent, project or channel`,onMouseDown:e=>e.stopPropagation(),onKeyDown:T,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2.5 border-b border-line px-4 py-3 text-fg-2`,children:[(0,C.jsx)(w,{name:`search`}),(0,C.jsx)(`input`,{autoFocus:!0,className:`min-w-0 flex-1 border-0 bg-transparent p-0 font-sans text-[16px] text-fg outline-none`,value:s,onChange:e=>{c(e.target.value),u(0)},placeholder:`jump to an agent, project or channel…`,"aria-label":`search`,autoComplete:`off`,spellCheck:!1}),r&&t&&(0,C.jsx)(w,{name:`progress_activity`,className:`ms-sm`}),(0,C.jsx)(Ve,{children:`esc`})]}),D,(0,C.jsxs)(`div`,{className:`flex items-center gap-3.5 border-t border-line px-3.5 py-2 text-2xs text-fg-2 [&>span]:inline-flex [&>span]:items-center [&>span]:gap-1`,children:[(0,C.jsxs)(`span`,{children:[(0,C.jsx)(Ve,{children:`↑`}),(0,C.jsx)(Ve,{children:`↓`}),` move`]}),(0,C.jsxs)(`span`,{children:[(0,C.jsx)(Ve,{children:`↵`}),` open`]}),d&&(0,C.jsxs)(`span`,{className:`ml-auto`,children:[(0,C.jsx)(w,{name:`progress_activity`,className:`ms-sm`}),` starting the workspace…`]}),p&&(0,C.jsxs)(`span`,{className:`ml-auto max-w-[60%] truncate text-bad`,title:p,children:[(0,C.jsx)(w,{name:`warning`,className:`ms-sm`}),` `,p]})]})]})})}var Cu=1296e5;function wu(e){if(e<6e4)return`just now`;let t=Math.floor(e/6e4);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h`:`${Math.floor(n/24)}d`}function Tu(e,t){let n=new Date(e),r=n.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),i=Math.round((new Date(n).setHours(0,0,0,0)-new Date(t).setHours(0,0,0,0))/864e5);return i<=0?r:i===1?`tomorrow ${r}`:`${n.toLocaleDateString([],{weekday:`short`})} ${r}`}function Eu(e,t=``,n=new Date){if(!e)return t?{text:t,tone:`plain`}:null;let r=e=>`${e[0].title||`a session`}${e.length>1?` +${e.length-1}`:``}`;if(e.waiting.length)return{text:`waiting for you · ${r(e.waiting)}`,tone:`waiting`};if(e.working.length){let t=e.working[0].since,i=t?wu(Math.max(0,n.getTime()-Date.parse(t))):``;return{text:`working · ${r(e.working)}${i&&i!==`just now`?` · ${i}`:``}`,tone:`working`}}if(e.nextRoutine&&Date.parse(e.nextRoutine.at)-n.getTime()<Cu)return{text:`next: ${e.nextRoutine.name} · ${Tu(e.nextRoutine.at,n)}`,tone:`plain`};if(e.lastActiveAt){let t=wu(Math.max(0,n.getTime()-Date.parse(e.lastActiveAt)));return{text:t===`just now`?`last active just now`:`last active ${t} ago`,tone:`plain`}}return{text:t||`no sessions yet`,tone:`plain`}}function Du({chatPath:e}){let t=me(),n=ue(),r=R(`/api/agents`,!1,15e3),i=R(`/api/channels`,!1,6e3),[a,o]=(0,v.useState)(0);(0,v.useEffect)(()=>{let e=()=>o(e=>e+1);return window.addEventListener(De,e),()=>window.removeEventListener(De,e)},[]);let s=R(t.projects?`/api/projects${a?`?rev=${a}`:``}`:``,!1,15e3),c=R(`/api/agent-status`,!1,5e3),l=R(t.vibeables?`/api/vibeables`:``,!1,15e3),u=new Set((l?.vibeables??[]).map(e=>e.slug)),d=e.split(`/`).filter(Boolean),f=(e,t)=>d[0]===e&&(t===void 0||(d[1]?decodeURIComponent(d[1]):void 0)===t),p=d[0]===`agents`&&d[1]===`chats`,[m,h]=Mu(),[g,_]=(0,v.useState)(),y=d[0]===`projects`&&d[1]&&d[1]!==`new`?decodeURIComponent(d[1]):void 0;(0,v.useEffect)(()=>{y&&_(y)},[y]);let b=Ct()??[],x=new Map((r?.agents??[]).filter(e=>!e.archived).map(e=>[e.slug,e])),S=s?.projects??[],T=e=>(e.agents??[]).map(e=>x.get(e)).filter(e=>!!e),E=e=>f(`projects`,e.slug)||e.slug===g&&T(e).some(e=>f(`agents`,e.slug));return(0,C.jsx)(`nav`,{className:`rail`,"aria-label":`Conversations`,children:(0,C.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-0.5 overflow-y-auto px-2 pt-2 pb-4`,children:[(0,C.jsx)(q,{href:`/`,active:e===`/`,leading:(0,C.jsx)(w,{name:`home`}),title:`Home`,sub:`Today: what needs you, what happened`}),(0,C.jsx)(q,{href:`/agents/chats`,active:p,leading:(0,C.jsx)(`span`,{"aria-hidden":!0,children:`🎩`}),title:`Ralv`,titleExtra:(0,C.jsx)(Be,{n:wt.general(b).length,title:`waiting for you`}),sub:`Chief of staff: knows the workspace, advises, launches things`}),t.projects&&(0,C.jsxs)(ku,{label:`projects`,href:`/projects`,add:s?.enabled?{href:`/projects/new`,label:`new project`}:void 0,badge:m.all?(0,C.jsx)(Be,{n:new Set(S.filter(e=>!E(e)).flatMap(e=>wt.project(b,e.slug,e.agents).map(e=>e.id))).size,title:`waiting in the projects folded away`}):void 0,fold:S.length>0?(0,C.jsx)(B,{size:`sm`,icon:m.all?`chevron_right`:`expand_more`,label:m.all?`show all projects`:`collapse projects`,"aria-expanded":!m.all,onClick:()=>h(e=>({...e,all:!e.all}))}):void 0,children:[S.filter(e=>!m.all||E(e)).map(e=>{let n=T(e),r=t.vibeables?(e.vibeables??[]).filter(e=>u.has(e)):[],i=n.length+r.length>0,a=i&&(m.open[e.slug]??e.slug===(y??g)),o=n.map(e=>c?.[e.slug]).filter(e=>!!e),s=!a&&o.some(e=>e.working.length&&!e.waiting.length);return(0,C.jsxs)(v.Fragment,{children:[(0,C.jsx)(q,{href:`/projects/${encodeURIComponent(e.slug)}`,active:f(`projects`,e.slug),innerProps:{"data-project":e.slug},leading:(0,C.jsx)(`span`,{"aria-hidden":!0,children:e.status===`done`?`✅`:e.status===`paused`?`⏸️`:e.status===`archived`?`🗄️`:`📁`}),title:e.title,titleExtra:(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(Be,{n:wt.project(b,e.slug,e.agents).length,title:`waiting for you`}),s&&(0,C.jsx)(V,{tone:`working`,title:`an agent is working`})]}),sub:e.goal||(e.status===`active`?void 0:e.status),actionsAlways:!0,actions:i?(0,C.jsx)(B,{size:`sm`,icon:a?`expand_more`:`chevron_right`,label:`${a?`collapse`:`expand`} ${e.title}`,"aria-expanded":a,title:a?`hide its agents and apps`:`${n.length?`${n.length} agent${n.length===1?``:`s`}`:``}${n.length&&r.length?`, `:``}${r.length?`${r.length} app${r.length===1?``:`s`}`:``}`,onClick:()=>h(t=>({...t,open:{...t.open,[e.slug]:!a}}))}):void 0}),a&&n.map(t=>(0,C.jsx)(q,{className:Ou,size:`sm`,href:`/agents/${encodeURIComponent(t.slug)}`,active:f(`agents`,t.slug),onClick:()=>_(e.slug),innerProps:{title:t.description||t.name,"data-nested":`agent`},leading:(0,C.jsx)(`span`,{"aria-hidden":!0,children:t.emoji||`🤖`}),title:(0,C.jsx)(`span`,{className:`font-medium`,children:t.name}),titleExtra:(0,C.jsx)(Au,{n:wt.agent(b,t.slug).length,st:c?.[t.slug]})},t.slug)),a&&r.map(t=>(0,C.jsx)(q,{className:Ou,size:`sm`,href:`/projects/${encodeURIComponent(e.slug)}?app=${encodeURIComponent(t)}`,onClick:()=>_(e.slug),innerProps:{title:`open ${t} beside the project's chat`,"data-nested":`app`},leading:(0,C.jsx)(w,{name:`web`,className:`ms-sm`}),title:(0,C.jsx)(`span`,{className:`font-medium`,children:t})},`app:${t}`))]},e.slug)}),m.all&&S.length>0&&(0,C.jsxs)(z,{variant:`quiet`,size:`sm`,icon:`expand_more`,className:`justify-start`,onClick:()=>h(e=>({...e,all:!1})),children:[S.filter(e=>!E(e)).length,` more`]})]}),(0,C.jsx)(ku,{label:`agents`,href:`/agents`,add:n?{href:`/agents/new`,label:`new agent`}:void 0,children:(r?.agents??[]).filter(e=>!e.archived).map(e=>{let t=Eu(c?.[e.slug],e.description);return(0,C.jsx)(q,{href:`/agents/${encodeURIComponent(e.slug)}`,active:f(`agents`,e.slug)||f(`team`,e.slug),innerProps:{title:e.description||void 0},leading:(0,C.jsx)(`span`,{"aria-hidden":!0,children:e.emoji||`🤖`}),title:e.name,titleExtra:(0,C.jsx)(Au,{n:wt.agent(b,e.slug).length,st:c?.[e.slug]}),sub:t?(0,C.jsx)(`span`,{className:`rail-status${t.tone===`plain`?``:` ${t.tone}`}`,children:t.text}):void 0,subTone:t?.tone===`waiting`?`bad`:t?.tone===`working`?`accent`:`plain`},e.slug)})}),(0,C.jsx)(ku,{label:`channels`,href:`/channels`,add:{href:`/channels/new`,label:`new channel`},children:(i?.channels??[]).map(e=>(0,C.jsx)(q,{href:`/channels/${encodeURIComponent(e.slug)}`,active:f(`channels`,e.slug),leading:(0,C.jsx)(`span`,{"aria-hidden":!0,className:`font-semibold`,children:`#`}),title:e.name,titleExtra:(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(Be,{n:wt.channel(b,e.slug).length,title:`waiting for you`}),e.busy&&!e.awaitingApproval&&(0,C.jsx)(V,{tone:`working`,title:`an agent is working`})]}),sub:e.purpose||(e.members.length?`with ${e.members.map(e=>`@${e}`).join(` `)}`:`no agents yet`)},e.slug))})]})})}var Ou=`ml-5 rounded-l-none border-l border-line`;function ku({label:e,href:t,add:n,badge:r,fold:i,children:a}){return(0,C.jsxs)(`div`,{className:`mt-3 flex flex-col gap-0.5`,role:`group`,"aria-label":e[0].toUpperCase()+e.slice(1),children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-1 pl-2.5 pr-1`,children:[(0,C.jsx)(P,{href:t,className:`flex-1 px-0 py-1 text-2xs font-semibold uppercase tracking-[0.08em] text-accent no-underline hover:underline`,children:e}),r,n&&(0,C.jsx)(B,{size:`sm`,icon:`add`,label:n.label,href:n.href}),i]}),a]})}function Au({n:e,st:t}){return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(Be,{n:e,title:`waiting for you`}),!e&&t?.working.length&&!t.waiting.length?(0,C.jsx)(V,{tone:`working`,title:`working`}):null]})}var ju=`kw-rail-fold`;function Mu(){let[e,t]=(0,v.useState)(()=>{try{let e=JSON.parse(localStorage.getItem(ju)??`null`);return{all:!!e?.all,open:e?.open&&typeof e.open==`object`?e.open:{}}}catch{return{all:!1,open:{}}}});return[e,e=>t(t=>{let n=e(t);try{localStorage.setItem(ju,JSON.stringify(n))}catch{}return n})]}function Nu({path:e}){let t=ue(),n=me(),r=e.split(`/`).filter(Boolean)[0]??``;if(!t)return null;let i=[{id:`workflows`,href:`/workflows`,label:`workflows`,icon:`account_tree`},{id:`knowledge`,href:`/knowledge`,label:`knowledge`,icon:`menu_book`},{id:`files`,href:`/files`,label:`files`,icon:`folder_open`},...n.vibeables?[{id:`vibeables`,href:`/vibeables`,label:`apps`,icon:`web`}]:[],{id:`skills`,href:`/skills`,label:`skills`,icon:`extension`},...n.repos?[{id:`repos`,href:`/repos`,label:`repositories`,icon:`source`}]:[],...n.git?[{id:`git`,href:`/git`,label:`git`,icon:`cloud_sync`,badge:(0,C.jsx)(Pu,{})}]:[],{id:`workspaces`,href:`/workspaces`,label:`workspaces`,icon:`grid_view`},{id:`settings`,href:`/settings`,label:`settings`,icon:`settings`},{id:`trash`,href:`/trash`,label:`trash`,icon:`delete`}],a=e=>r===e||e===`workflows`&&r===`runs`;return(0,C.jsx)(`nav`,{className:`global-nav flex min-w-0 flex-[0_1_auto] justify-start gap-0.5 overflow-x-auto [scrollbar-width:none] max-[1199px]:[mask-image:linear-gradient(to_right,#000_calc(100%-24px),transparent)] max-[800px]:hidden`,"aria-label":`Workspace`,children:i.map(e=>{let t=a(e.id);return(0,C.jsxs)(`a`,{href:`#${e.href}`,className:b(`inline-flex flex-none items-center gap-1.5 rounded-full px-3 py-1.5 text-[13.5px] font-semibold no-underline transition-colors`,`[&_.ms]:text-[18px] max-[1520px]:gap-[5px] max-[1520px]:[&_.ms]:text-[17px]`,t?`bg-surface text-accent shadow-[inset_0_0_0_1px_var(--line)]`:`text-fg-2 hover:bg-surface-2 hover:text-fg`),"aria-current":t?`page`:void 0,children:[(0,C.jsx)(w,{name:e.icon,fill:t}),` `,e.label,e.badge]},e.id)})})}function Pu(){let e=R(`/api/git`,!1,15e3),t=e?.files?.filter(e=>e.syncable).length??0,n=`ml-[5px] rounded-full bg-surface-2 px-1.5 py-px text-[10.5px] font-semibold tabular-nums`;return(0,C.jsxs)(C.Fragment,{children:[!!e?.behind&&(0,C.jsxs)(`span`,{className:b(n,`text-accent`),children:[e.behind,`↓`]}),!!e?.ahead&&(0,C.jsxs)(`span`,{className:b(n,`text-ok`),children:[e.ahead,`↑`]}),!e?.ahead&&!e?.behind&&!!t&&(0,C.jsx)(`span`,{className:n,children:t})]})}var Fu=e=>e.replace(/^# .*\n+/,``).replace(/\(human:user\)/g,`(you)`),Iu=`flex flex-col gap-1.5 px-1.5 pb-6 pt-1`,Lu=`m-0 px-2.5 pb-0.5 pt-1.5 text-md leading-[1.45] text-fg`,Ru=`m-0 px-2.5 py-0.5 text-sm text-fg-2`,zu=`md-body px-2.5 text-sm leading-normal`,Bu=e=>Qi.sanitize(Cr.parse(Fu(e),{async:!1}));function Vu(e,t){let n=[],r=``;for(let i of e.split(`
227
227
  `)){let e=/^## (.+)$/.exec(i.trim());if(e?r=e[1]:/^[-*] /.test(i)&&n.push({day:r,text:i.replace(/^[-*] /,``)}),n.length>=t)break}return n}function Hu({items:e}){return e.length===0?null:(0,C.jsx)(Ue,{title:`needs you`,count:e.length,children:e.map(e=>(0,C.jsx)(q,{onClick:()=>kt(e),leading:(0,C.jsx)(w,{name:e.kind===`approval`?`front_hand`:e.kind===`question`?`help`:`error`,className:`ms-sm text-bad`}),title:e.title,sub:`${e.owner.agent?`${e.owner.agent.emoji??``} ${e.owner.agent.name} · `:``}${e.kind===`approval`?`needs approval`:e.kind===`question`?`asks you`:`failed`} · ${Ne(e.since)}`},e.id))})}function Uu({slugs:e,agents:t,status:n,title:r=`team`}){let i=e.map(e=>t.find(t=>t.slug===e)).filter(e=>!!e);return i.length===0?null:(0,C.jsx)(Ue,{title:r,children:i.map(e=>{let t=Eu(n?.[e.slug],e.description);return(0,C.jsx)(q,{href:`/agents/${encodeURIComponent(e.slug)}`,leading:(0,C.jsx)(`span`,{"aria-hidden":!0,children:e.emoji||`🤖`}),title:e.name,sub:t?.text,subTone:t?.tone===`waiting`?`bad`:t?.tone===`working`?`accent`:`plain`},e.slug)})})}function Wu({scope:e}){let t=R(`/api/files/recent?scope=${encodeURIComponent(e)}`,!1,2e4);return!t||t.count===0?null:(0,C.jsx)(Ue,{title:`files`,count:t.count,action:(0,C.jsxs)(z,{variant:`quiet`,size:`sm`,href:Sl(e),children:[`all `,(0,C.jsx)(w,{name:`arrow_forward`,className:`ms-sm`})]}),children:t.recent.map(t=>{let n=t.path.includes(`/`)?t.path.slice(0,t.path.lastIndexOf(`/`)):``;return(0,C.jsx)(q,{href:Sl(e,n,t.path),leading:(0,C.jsx)(w,{name:`draft`,className:`ms-sm`}),title:t.path.split(`/`).pop(),sub:`${n?`${n}/ · `:``}${Ne(t.at)}`},t.path)})})}function Gu({of:e}){let t=Ct()??[],n=R(`/api/agents`,!1,15e3)?.agents??[],r=R(`/api/agent-status`,!1,5e3)??void 0;if(e.kind===`project`){let i=e.project,a=i.links.agents.map(e=>e.slug),o=Vu(i.log,5);return(0,C.jsxs)(`div`,{className:Iu,children:[(0,C.jsxs)(`p`,{className:Lu,children:[i.goal||(0,C.jsx)(`span`,{className:`text-fg-2`,children:`No goal written yet.`}),i.status!==`active`&&(0,C.jsxs)(`span`,{className:`text-fg-2`,children:[` · `,i.status]})]}),(0,C.jsx)(Hu,{items:wt.project(t,i.slug,a)}),(0,C.jsx)(Uu,{slugs:a,agents:n,status:r}),(0,C.jsx)(Ue,{title:`where it stands`,children:i.state.trim()?(0,C.jsx)(`div`,{className:zu,dangerouslySetInnerHTML:{__html:Bu(i.state)}}):(0,C.jsx)(`p`,{className:Ru,children:`Nothing recorded yet: the project's chat writes this down at the end of a session that changed something.`})}),o.length>0&&(0,C.jsx)(Ue,{title:`lately`,children:o.map((e,t)=>(0,C.jsxs)(`div`,{className:`grid grid-cols-[74px_minmax(0,1fr)] gap-2 px-2.5 py-1 text-sm`,children:[(0,C.jsx)(`span`,{className:`pt-px text-xs tabular-nums text-fg-2`,children:e.day}),(0,C.jsx)(`span`,{dangerouslySetInnerHTML:{__html:Qi.sanitize(Cr.parseInline(Fu(e.text),{async:!1}))}})]},t))}),(0,C.jsx)(Wu,{scope:`project:${i.slug}`}),i.records.length>0&&(0,C.jsx)(Ue,{title:`systems of record`,children:i.records.map((e,t)=>(0,C.jsx)(q,{onClick:()=>e.url&&window.open(e.url,`_blank`,`noopener`),leading:(0,C.jsx)(w,{name:`open_in_new`,className:`ms-sm`}),title:e.title||e.kind,sub:e.note},t))})]})}if(e.kind===`agent`)return(0,C.jsx)(Ku,{agent:e.agent,journal:e.journal,waiting:t,status:r});if(e.kind===`channel`){let i=e.channel;return(0,C.jsxs)(`div`,{className:Iu,children:[(0,C.jsx)(`p`,{className:Lu,children:i.purpose||(0,C.jsxs)(`span`,{className:`text-fg-2`,children:[`A group chat with `,i.members.length,` agent`,i.members.length===1?``:`s`,`.`]})}),(0,C.jsx)(Hu,{items:wt.channel(t,i.slug)}),(0,C.jsx)(Uu,{slugs:i.members,agents:n,status:r,title:`in this channel`})]})}return(0,C.jsx)(qu,{waiting:t,agents:n,status:r})}function Ku({agent:e,journal:t,waiting:n,status:r}){let i=R(`/api/projects`,!1,3e4)?.projects??[],a=R(`/api/agents/${encodeURIComponent(e.slug)}/routines`,!1,3e4)?.routines??[],[o,s]=(0,v.useState)(t);(0,v.useEffect)(()=>s(t),[t]);let c=Eu(r?.[e.slug],e.description),l=i.filter(t=>t.agents.includes(e.slug));return(0,C.jsxs)(`div`,{className:Iu,children:[(0,C.jsx)(`p`,{className:Lu,children:e.description||(0,C.jsx)(`span`,{className:`text-fg-2`,children:`No description yet.`})}),c&&c.text!==e.description&&(0,C.jsx)(`p`,{className:`m-0 px-2.5 text-sm ${c.tone===`waiting`?`text-bad`:c.tone===`working`?`text-accent`:`text-fg-2`}`,children:c.text}),(0,C.jsx)(Hu,{items:wt.agent(n,e.slug)}),l.length>0&&(0,C.jsx)(Ue,{title:`works on`,children:l.map(e=>(0,C.jsx)(q,{href:`/projects/${encodeURIComponent(e.slug)}`,leading:(0,C.jsx)(`span`,{"aria-hidden":!0,children:`📁`}),title:e.title,sub:e.goal||void 0},e.slug))}),a.length>0&&(0,C.jsx)(Ue,{title:`schedule`,children:a.map(e=>(0,C.jsx)(q,{leading:(0,C.jsx)(w,{name:`schedule`,className:`ms-sm`}),title:e.name,sub:`${e.enabled?e.nextRunAt?`next ${new Date(e.nextRunAt).toLocaleString([],{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}`:e.schedule:`paused`}${e.lastRunAt?` · last ${Ne(e.lastRunAt)}`:``}`},e.id))}),(0,C.jsxs)(Ue,{title:`journal`,children:[(0,C.jsx)(Ju,{slug:e.slug,onAdded:s}),(0,C.jsx)(`div`,{className:zu,dangerouslySetInnerHTML:{__html:Bu(Fu(o)||`_Nothing yet: the agent notes what it learns, decides and promises here, and reads it back at the start of every session._`)}})]})]})}function qu({waiting:e,agents:t,status:n}){let r=R(`/api/projects`,!1,3e4),i=(r?.projects??[]).filter(e=>e.status===`active`);return(0,C.jsxs)(`div`,{className:Iu,children:[(0,C.jsx)(Hu,{items:e}),r?.enabled&&(0,C.jsxs)(Ue,{title:`projects`,count:i.length,children:[i.length===0&&(0,C.jsx)(`p`,{className:Ru,children:`No active projects.`}),i.map(t=>{let n=wt.project(e,t.slug,t.agents).length;return(0,C.jsx)(q,{href:`/projects/${encodeURIComponent(t.slug)}`,leading:(0,C.jsx)(`span`,{"aria-hidden":!0,children:`📁`}),title:t.title,sub:n?`${n} waiting for you`:t.goal||`no goal yet`,subTone:n?`bad`:`plain`},t.slug)})]}),(0,C.jsx)(Uu,{slugs:t.filter(e=>!e.archived).map(e=>e.slug),agents:t,status:n,title:`agents`}),(0,C.jsx)(Wu,{scope:`workspace`})]})}function Ju({slug:e,onAdded:t}){let[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``),c=async()=>{if(!n.trim())return;a(!0),s(``);let i=await Ee(`/api/agents/${encodeURIComponent(e)}/journal`,{entry:n,kind:`note`}).catch(e=>({error:e.message,journal:void 0}));if(a(!1),i.error||i.journal===void 0)return s(i.error??`could not save`);r(``),t(i.journal)};return(0,C.jsxs)(`div`,{className:`px-2.5 pb-1.5 pt-0.5`,children:[(0,C.jsx)(J,{className:`h-8 text-sm`,value:n,placeholder:`add a note for the agent to remember`,onChange:e=>r(e.target.value),onKeyDown:e=>e.key===`Enter`&&void c(),disabled:i}),o&&(0,C.jsx)(G,{tone:`bad`,children:o})]})}function Yu(e){let t=e.split(`/`).filter(Boolean),n=t[1]?decodeURIComponent(t[1]):``;return t[0]===`projects`&&n&&n!==`new`?{kind:`project`,slug:n}:t[0]===`channels`&&n&&n!==`new`?{kind:`channel`,slug:n}:(t[0]===`agents`||t[0]===`team`)&&n&&n!==`new`&&n!==`chats`?{kind:`agent`,slug:n}:{kind:`general`}}async function $(e){try{let t=await fetch(e,{cache:`no-store`});return t.ok?await t.json():null}catch{return null}}var Xu=(e,t)=>e.map(e=>({slug:e,found:t.has(e)}));function Zu({chatPath:e,workspace:t}){let n=Yu(e),r=`${n.kind}:${`slug`in n?n.slug:``}`,i=me(),a=ue(),[o,s]=n.kind===`project`?[`/projects/${encodeURIComponent(n.slug)}/info`,`edit the project: brief, state, records, links`]:n.kind===`agent`?[`/agents/${encodeURIComponent(n.slug)}/info`,`edit the agent: profile and settings`]:n.kind===`channel`?[`/channels/${encodeURIComponent(n.slug)}/edit`,`edit the channel`]:a?[`/settings`,`workspace settings`]:[void 0,``],c=R(`/api/workflows`,!1,15e3),l=R(`/api/runs`,!1,6e3),u=R(`/api/knowledge`,!1,15e3),d=R(i.vibeables?`/api/vibeables`:``,!1,15e3),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(0),[g,_]=(0,v.useState)(()=>{try{return localStorage.getItem(`kw-ctx-tab`)||`overview`}catch{return`overview`}}),[y,x]=(0,v.useState)(0);(0,v.useEffect)(()=>{let e=()=>S(`browser`);return window.addEventListener(ea,e),()=>window.removeEventListener(ea,e)},[]);let S=e=>{_(e);try{localStorage.setItem(`kw-ctx-tab`,e)}catch{}},[E,D]=(0,v.useState)({});(0,v.useEffect)(()=>D(oe.current?{vibeables:`/vibeables/${encodeURIComponent(oe.current.slug)}`}:{}),[r]);let O=T(),k=n.kind===`project`?new URLSearchParams(O.split(`?`)[1]??``).get(`app`):null;(0,v.useEffect)(()=>{k&&(S(`vibeables`),D(e=>({...e,vibeables:`/vibeables/${encodeURIComponent(k)}`})))},[k,r]);let ee=e=>D(t=>({...t,[de]:e})),[A,te]=(0,v.useState)({dir:``});(0,v.useEffect)(()=>te({dir:``}),[r]);let ne=async(e,t,n)=>{let r=await Ee(`/api/projects/${encodeURIComponent(e)}/links`,{kind:`vibeables`,target:t,remove:n}).catch(()=>null);r&&!r.error&&(h(e=>e+1),window.dispatchEvent(new Event(De)))},re=()=>D(e=>({...e,[de]:null})),j=e=>t=>t.startsWith(e)?(D(e=>({...e,[de]:t})),!0):!1,[M,ae]=(0,v.useState)(null),oe=(0,v.useRef)(null);(0,v.useEffect)(()=>{let e=e=>{let t=e.detail;oe.current=t,ae(t),t?(S(`vibeables`),D(e=>({...e,vibeables:`/vibeables/${encodeURIComponent(t.slug)}`}))):D(e=>e.vibeables?.startsWith(`/vibeables/`)?{...e,vibeables:null}:e)};return window.addEventListener(ca,e),()=>window.removeEventListener(ca,e)},[]);let se=i.repos&&!!f?.repos,ce=n.kind===`project`?`project:${n.slug}`:f?.channel?.project?`project:${f.channel.project}`:`workspace`,le=[{id:`overview`,label:`overview`},{id:`files`,label:`files`,allHref:`/files/${encodeURIComponent(ce)}`},{id:`knowledge`,label:`knowledge`,count:f?.knowledge.length,allHref:`/knowledge`},...i.vibeables?[{id:`vibeables`,label:`apps`,count:f?.all?d?.vibeables.length:f?.vibeables?.length??0,allHref:`/vibeables`}]:[],{id:`workflows`,label:`workflows`,count:f?.workflows.length,allHref:`/workflows`},...a&&se?[{id:`repos`,label:`repositories`,count:f?.repos?.length,allHref:`/repos`}]:[],...y>0||g===`browser`?[{id:`browser`,label:`browser`,count:y}]:[]],de=le.some(e=>e.id===g)?g:`overview`,fe=le.find(e=>e.id===de),pe=E[de]??null,he=!!M&&de===`vibeables`&&pe===`/vibeables/${encodeURIComponent(M.slug)}`,F=e=>t=>{t.metaKey||t.ctrlKey||t.shiftKey||t.button!==0||(t.preventDefault(),ee(e))};(0,v.useEffect)(()=>{let e=setInterval(()=>h(e=>e+1),15e3);return()=>clearInterval(e)},[]);let I=ie(O),ge=(0,v.useRef)(I);(0,v.useEffect)(()=>{ge.current&&!I&&h(e=>e+1),ge.current=I},[I]),(0,v.useEffect)(()=>{let e=!0,r=new Set((c?.workflows??[]).map(e=>e.slug)),i=new Set((u?.bundles??[]).map(e=>e.name)),a=new Set((d?.vibeables??[]).map(e=>e.slug));return(async()=>{let o=null;if(n.kind===`agent`){let e=await $(`/api/agents/${encodeURIComponent(n.slug)}`);e&&(o={title:`${e.emoji?`${e.emoji} `:``}${e.name}`,agent:e,workflows:Xu(e.workflows,r),knowledge:Xu(e.knowledge,i),editHref:`/agents/${encodeURIComponent(n.slug)}/edit`},(e.vibeables??[]).length>0&&(o.vibeables=Xu(e.vibeables,a)),o.journal=(await $(`/api/agents/${encodeURIComponent(n.slug)}/journal`))?.journal??``)}else if(n.kind===`project`){let e=await $(`/api/projects/${encodeURIComponent(n.slug)}`);e&&(o={title:`📁 ${e.title}`,project:e,workflows:e.links.workflows,knowledge:e.links.knowledge,vibeables:e.links.vibeables,repos:e.links.repos,agents:e.links.agents,records:e.records,state:e.state,log:e.log,editHref:`/projects/${encodeURIComponent(n.slug)}/info`})}else if(n.kind===`channel`){let e=(await $(`/api/channels`))?.channels.find(e=>e.slug===n.slug);if(e){let t=(await Promise.all(e.members.map(e=>$(`/api/agents/${encodeURIComponent(e)}`)))).filter(e=>!!e),s=e=>[...new Set(t.flatMap(e))],c=s(e=>e.vibeables??[]);o={title:`#${e.slug}`,channel:e,workflows:Xu(s(e=>e.workflows),r),knowledge:Xu(s(e=>e.knowledge),i),...c.length>0?{vibeables:Xu(c,a)}:{},agents:e.members.map(e=>({slug:e,found:t.some(t=>t.slug===e),label:t.find(t=>t.slug===e)?.name})),editHref:`/channels/${encodeURIComponent(n.slug)}/edit`}}}else o={title:`${t.icon?`${t.icon} `:``}${t.name||`workspace`}`,workflows:Xu([...r],r),knowledge:Xu([...i],i),all:!0};e&&p(o)})(),()=>{e=!1}},[r,m,c,u,d,t.name,t.icon]);let _e=e=>c?.workflows.find(t=>t.slug===e),ve=e=>e?l?.runs.find(t=>t.workflow===(e.name??e.slug)||t.workflow===e.slug):void 0,ye=e=>u?.bundles.find(t=>t.name===e),be=e=>d?.vibeables.find(t=>t.slug===e),L=e=>(0,C.jsxs)(`p`,{className:`m-0 px-2.5 py-3 text-sm text-fg-2`,children:[f?.all?`No ${e} in this workspace yet.`:`No ${e} linked.`,f?.editHref&&a&&!f.all&&(0,C.jsxs)(C.Fragment,{children:[` `,(0,C.jsx)(P,{href:f.editHref,className:`text-accent`,children:`Edit the links`}),`.`]})]});return(0,C.jsxs)(`aside`,{className:`ctx`,"aria-label":`Context`,children:[(0,C.jsxs)(`div`,{className:b(`pointer-events-none absolute top-0 left-1/2 z-3 flex max-w-[calc(100%-48px)] [transform:translate(-50%,-50%)] items-center gap-3`,`rounded-full border border-line bg-surface px-[30px] py-3 shadow-[0_6px_24px_rgb(0_0_0/0.16)]`,`max-[800px]:static max-[800px]:mx-auto max-[800px]:mb-2 max-[800px]:max-w-none max-[800px]:[transform:none]`,f&&`animate-sign max-[800px]:animate-fade`),children:[(0,C.jsx)(`span`,{className:`min-w-0 truncate text-[26px] leading-[1.1] font-[750] tracking-[-0.015em] text-fg max-[800px]:text-lg`,title:f?.title,children:f?f.title:`…`}),o&&(0,C.jsx)(P,{href:o,className:`ctx-edit pointer-events-auto inline-grid size-7 place-items-center rounded-full text-fg-2 no-underline transition-colors hover:bg-surface-2 hover:text-accent active:scale-96 [&_.ms]:text-[18px]`,title:s,"aria-label":s,children:(0,C.jsx)(w,{name:`edit`,className:`ms-sm`})})]},f?.title??``),(0,C.jsx)(et,{className:`flex-none gap-y-0.5 pt-10`,label:`Categories`,items:le,value:de,onChange:S}),pe&&(0,C.jsxs)(`div`,{className:`flex items-center gap-2 px-3 pb-1 pt-2`,children:[(0,C.jsx)(z,{variant:`quiet`,size:`sm`,icon:`arrow_back`,onClick:re,"aria-label":`Back to the list`,children:fe?.label}),(0,C.jsx)(`span`,{className:`flex-1`}),(0,C.jsx)(z,{variant:`quiet`,size:`sm`,icon:`open_in_new`,href:pe,title:`Open as a page`,children:`page`})]}),pe&&de===`knowledge`&&(0,C.jsx)(`div`,{className:`ctx-body ctx-embed`,children:(0,C.jsx)(N.Provider,{value:j(`/knowledge/`),children:(()=>{let e=pe.split(`/`).filter(Boolean),t=decodeURIComponent(e[1]??``),n=e.length>2?e.slice(2).map(decodeURIComponent).join(`/`):void 0;return(0,C.jsx)(Qc,{name:t,conceptId:n},t)})()})}),pe&&de===`workflows`&&(0,C.jsx)(`div`,{className:`ctx-body ctx-embed`,children:(0,C.jsx)(N.Provider,{value:j(`/workflows/`),children:(()=>{let e=pe.split(`/`).filter(Boolean),t=e[2]===`details`||e[2]===`runs`?e[2]:`overview`;return(0,C.jsx)(mc,{slug:decodeURIComponent(e[1]??``),tab:t},e[1])})()})}),pe&&de===`vibeables`&&!he&&(0,C.jsx)(`div`,{className:`ctx-body ctx-embed ctx-embed-vibe`,children:(0,C.jsx)(fa,{slug:decodeURIComponent(pe.split(`/`).filter(Boolean)[1]??``)},pe)}),(0,C.jsx)(`div`,{id:la,className:`ctx-body ctx-embed ctx-embed-vibe`,hidden:!he}),(0,C.jsx)(`div`,{className:`ctx-body ctx-embed ctx-browser`,hidden:de!==`browser`,children:(0,C.jsx)(sa,{storeKey:r,onTabs:x},r)}),(0,C.jsxs)(`div`,{className:`ctx-body`,role:`tabpanel`,hidden:de===`browser`||!!pe&&[`knowledge`,`workflows`,`vibeables`].includes(de),children:[fe?.allHref&&(0,C.jsx)(`div`,{className:`flex justify-end px-1 pb-1`,children:(0,C.jsxs)(z,{variant:`quiet`,size:`sm`,href:fe.allHref,children:[`all `,fe.label,` `,(0,C.jsx)(w,{name:`arrow_forward`,className:`ms-sm`})]})}),de===`workflows`&&(0,C.jsxs)(C.Fragment,{children:[f&&f.workflows.length===0&&L(`workflows`),f?.workflows.map(({slug:e,found:t})=>{let n=_e(e),r=ve(n);return(0,C.jsx)(q,{href:`/workflows/${encodeURIComponent(e)}`,onClick:t?F(`/workflows/${encodeURIComponent(e)}`):void 0,dim:!t,leading:(0,C.jsx)(V,{tone:!t||n?.error?`bad`:$u(r?.status)}),title:n?.name??e,sub:t?n?.error?`broken`:r?`${r.status} · ${Ne(r.updatedAt)}`:n?.description??`no runs yet`:`not in this workspace`,meta:t&&!n?.error?(0,C.jsx)(w,{name:`chevron_right`,className:`ms-sm`}):void 0},e)})]}),de===`knowledge`&&(0,C.jsxs)(C.Fragment,{children:[f&&f.knowledge.length===0&&L(`knowledge`),f?.knowledge.map(({slug:e,found:t})=>{let n=ye(e);return(0,C.jsx)(q,{href:`/knowledge/${encodeURIComponent(e)}`,onClick:t?F(`/knowledge/${encodeURIComponent(e)}`):void 0,dim:!t,leading:(0,C.jsx)(w,{name:`menu_book`,className:`ms-sm`}),title:e,sub:t?n?`${n.concepts} ${n.concepts===1?`page`:`pages`}${n.updatedAt?` · ${Ne(n.updatedAt)}`:``}`:void 0:`not in this workspace`},e)})]}),de===`vibeables`&&f&&(0,C.jsxs)(C.Fragment,{children:[(f.all?(d?.vibeables??[]).map(e=>({slug:e.slug,found:!0})):f.vibeables??[]).map(({slug:e,found:t})=>{let r=be(e);return(0,C.jsx)(q,{href:`/vibeables/${encodeURIComponent(e)}`,onClick:t?F(`/vibeables/${encodeURIComponent(e)}`):void 0,dim:!t,leading:(0,C.jsx)(w,{name:`web`,className:`ms-sm`}),title:e,sub:t?r?.updatedAt?`changed ${Ne(r.updatedAt)}`:void 0:`not in this workspace`,actions:n.kind===`project`?(0,C.jsx)(B,{icon:`keep_off`,size:`sm`,label:`unpin ${e}`,onClick:()=>void ne(n.slug,e,!0)}):void 0},e)}),n.kind===`project`&&d&&(0,C.jsx)(Qu,{options:d.vibeables.map(e=>e.slug).filter(e=>!f.vibeables?.some(t=>t.slug===e)),onPin:e=>void ne(n.slug,e,!1)}),f.all&&d&&d.vibeables.length===0&&L(`vibeables`),!f.all&&f.vibeables?.length===0&&L(`vibeables`)]}),de===`repos`&&f?.repos&&(0,C.jsxs)(C.Fragment,{children:[f.repos.length===0&&L(`repositories`),f.repos.map(({slug:e,found:t})=>(0,C.jsx)(q,{href:`/repos/${encodeURIComponent(e)}`,dim:!t,leading:(0,C.jsx)(w,{name:`source`,className:`ms-sm`}),title:e,sub:t?void 0:`not in this workspace`},e))]}),de===`overview`&&f&&(0,C.jsx)(Gu,{of:f.project?{kind:`project`,project:f.project}:f.agent?{kind:`agent`,agent:f.agent,journal:f.journal??``}:f.channel?{kind:`channel`,channel:f.channel}:{kind:`workspace`}},r),de===`files`&&(0,C.jsx)(kl,{compact:!0,scope:ce,dir:A.dir,file:A.file,onOpen:(e,t)=>te({dir:e,file:t})},ce)]},de)]})}function Qu({options:e,onPin:t}){return e.length===0?null:(0,C.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-2 text-fg-2`,children:[(0,C.jsx)(w,{name:`keep`,className:`ms-sm`}),(0,C.jsxs)(at,{className:`h-8 text-sm`,value:``,onChange:e=>e.target.value&&t(e.target.value),"aria-label":`pin an app to this project`,children:[(0,C.jsx)(`option`,{value:``,children:`pin an app to this project…`}),e.map(e=>(0,C.jsx)(`option`,{value:e,children:e},e))]})]})}function $u(e){return e===`ok`?`ok`:e===`failed`?`bad`:e===`running`?`working`:`idle`}var ed=`kw-chat-path`,td=`kw-ctx-w`,nd=()=>{try{let e=Number(localStorage.getItem(td));return e>0?e:null}catch{return null}};function rd({onResize:e}){let[t,n]=(0,v.useState)(!1);return(0,C.jsx)(`div`,{className:`split-handle${t?` dragging`:``}`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`resize chat and context`,title:`drag to resize · double-click for half and half`,onPointerDown:t=>{if(t.button!==0)return;let r=t.currentTarget.closest(`.shell`);if(!r)return;t.preventDefault();let i=r.getBoundingClientRect().right-parseFloat(getComputedStyle(r).paddingRight),a=t=>e(Math.round(i-t.clientX)),o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),window.removeEventListener(`pointercancel`,o),document.body.classList.remove(`kw-resizing`),n(!1)};window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o),window.addEventListener(`pointercancel`,o),document.body.classList.add(`kw-resizing`),n(!0)},onDoubleClick:()=>e(null)})}var id=(e,t)=>{try{return sessionStorage.getItem(e)||t}catch{return t}},ad=(e,t)=>{try{sessionStorage.setItem(e,t)}catch{}};function od(){let e=T();Mt();let[t]=e.split(`?`),n=t.split(`/`).filter(Boolean),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(!0),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(``),[h,g]=(0,v.useState)([]),_=ne.has(n[0]??``),y=n.length===0,[b,x]=(0,v.useState)(()=>id(ed,`/agents/chats`)),S=_?xs(t):null,E=_&&!S?t:b,[D,O]=(0,v.useState)(`chat`),[k,ee]=(0,v.useState)(nd),te=e=>{ee(e);try{e===null?localStorage.removeItem(td):localStorage.setItem(td,String(e))}catch{}};(0,v.useEffect)(()=>{_&&!xs(t)&&(x(t),ad(ed,t))},[e]),(0,v.useEffect)(()=>{let e=e=>{let t=e.detail;re(t)===`chat`?(x(t),ad(ed,t)):window.location.replace(`#${t}`)};return window.addEventListener(j,e),()=>window.removeEventListener(j,e)},[]),(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{try{let t=await fetch(`/api/meta`,{cache:`no-store`}).then(e=>e.json());if(!e)return;i(t.projectName??``),o(t.projectIcon??``),c(t.projectColor??``),u(t.projectNamed!==!1),f(t.projectRootLabel??``),m(t.projectRoot??``),pe({git:!!t.git,repos:!!t.repos,vibeables:!!t.vibeables,projects:!!t.projects}),g(Array.isArray(t.switcher)?t.switcher:[])}catch{}e&&(t=setTimeout(n,3e4))};n();let r=()=>{clearTimeout(t),n()};return window.addEventListener(`kw-meta-refresh`,r),()=>{e=!1,clearTimeout(t),window.removeEventListener(`kw-meta-refresh`,r)}},[]),(0,v.useEffect)(()=>{if(A(r?`${r} — kraftwerk`:`kraftwerk inspector`),!a)return;let e=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y="0.9em" font-size="85">${a}</text></svg>`,t=document.querySelector(`link[rel="icon"]`);t||(t=document.createElement(`link`),t.rel=`icon`,document.head.appendChild(t)),t.href=`data:image/svg+xml,${encodeURIComponent(e)}`},[r,a]);let ie=E.split(`/`).filter(Boolean),M=new URLSearchParams(e.split(`?`)[1]??``).get(`workflow`)??void 0,ae;ae=ie[0]===`chats`?(0,C.jsx)(ns,{seg:ie}):ie[0]===`projects`?(0,C.jsx)(jo,{seg:ie.slice(1)}):ie[0]===`channels`?(0,C.jsx)(Ca,{seg:ie.slice(1)}):(0,C.jsx)(ns,{seg:ie.slice(1)});let N=null;return n[0]===`runs`&&n[1]?N=(0,C.jsx)(js,{id:n[1],workflow:M}):n[0]===`runs`?N=(0,C.jsx)(gd,{}):n[0]===`workflows`?N=(0,C.jsx)(Sc,{slug:n[1]?decodeURIComponent(n[1]):void 0,tab:n[2]===`details`||n[2]===`runs`?n[2]:`overview`}):n[0]===`vibeables`?N=(0,C.jsx)(xa,{slug:n[1]?decodeURIComponent(n[1]):void 0}):n[0]===`knowledge`?N=(0,C.jsx)(Gc,{bundle:n[1]?decodeURIComponent(n[1]):void 0,conceptId:n.length>2?n.slice(2).map(decodeURIComponent).join(`/`):void 0}):n[0]===`skills`?N=(0,C.jsx)(cl,{name:n[1]?decodeURIComponent(n[1]):void 0}):n[0]===`settings`?N=(0,C.jsx)(vl,{}):n[0]===`trash`?N=(0,C.jsx)(bl,{}):n[0]===`ui`?N=(0,C.jsx)(Ml,{}):n[0]===`files`?N=(0,C.jsx)(Dl,{scope:n[1]?decodeURIComponent(n[1]):`workspace`,dir:n.slice(2).map(decodeURIComponent).join(`/`),file:new URLSearchParams(e.split(`?`)[1]??``).get(`file`)??void 0}):n[0]===`workspaces`?N=(0,C.jsx)(Il,{}):n[0]===`git`?N=(0,C.jsx)(ql,{}):n[0]===`repos`&&(N=(0,C.jsx)(au,{slug:n[1]?decodeURIComponent(n[1]):void 0})),(0,v.useEffect)(()=>{let e=document.documentElement,t=p||r,n=t?Ce(F(s,t)):null;if(!n){delete e.dataset.wsAccent;return}for(let[t,r]of Object.entries(n))e.style.setProperty(t,r);e.dataset.wsAccent=``},[s,p,r]),(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`header`,{className:`topbar sticky top-0 z-10 flex h-[var(--topbar-h)] items-center gap-3.5 bg-bg px-5 shadow-[inset_0_-1px_0_var(--line)] max-[1520px]:gap-2.5 max-[800px]:gap-1.5 max-[800px]:px-3`,style:{"--ws-c":F(s,p||r)},children:[(0,C.jsxs)(`span`,{className:`flex min-w-0 flex-none items-center gap-2.5 max-[800px]:flex-[0_1_auto] max-[800px]:gap-1`,children:[(0,C.jsx)(`a`,{href:`#/`,className:`grid size-8 place-items-center rounded-full text-[15px] leading-none transition-shadow hover:shadow-[0_0_0_4px_color-mix(in_srgb,var(--ws-c,var(--text))_16%,transparent)]`,title:`Dashboard`,children:r?(0,C.jsx)(Te,{size:`sm`,icon:a,name:r,color:s,seed:p||r}):(0,C.jsx)(w,{name:`home`})}),r&&(0,C.jsx)(hd,{name:r,icon:a,color:s,named:l,root:d,seed:p||r,entries:h})]}),(0,C.jsx)(Nu,{path:t}),(0,C.jsx)(`span`,{className:`flex-[1_1_8px]`}),(0,C.jsx)(xu,{}),(0,C.jsx)(jt,{}),(0,C.jsx)(Cd,{}),(0,C.jsx)(yd,{})]}),N&&(0,C.jsx)(`main`,{className:`shell shell-global`,children:N}),(0,C.jsxs)(`main`,{className:`shell three${y?` home`:``}`,"data-focus":D,hidden:!!N,style:k?{"--ctx-w":`${k}px`}:void 0,children:[(0,C.jsx)(Du,{chatPath:y?`/`:E}),(0,C.jsxs)(`section`,{className:`col-chat`,"aria-label":y?`Dashboard`:`Conversation`,children:[y?(0,C.jsx)(Oc,{}):ae,(0,C.jsx)(rd,{onResize:te})]}),(0,C.jsx)(Zu,{chatPath:y?`/`:E,workspace:{name:r,icon:a}}),S&&(0,C.jsx)(Ss,{back:E,children:S})]}),!N&&(0,C.jsxs)(`nav`,{className:`places`,"aria-label":`Sections`,children:[(0,C.jsxs)(`button`,{className:D===`chat`?`active`:``,onClick:()=>O(`chat`),children:[(0,C.jsx)(w,{name:`forum`}),` chat`]}),(0,C.jsxs)(`button`,{className:D===`context`?`active`:``,onClick:()=>O(`context`),children:[(0,C.jsx)(w,{name:`account_tree`}),` context`]})]})]})}function sd(e){try{let t=new URL(e);return t.hostname===`localhost`||t.hostname===`127.0.0.1`?`:${t.port||(t.protocol===`https:`?443:80)}`:t.host}catch{return e.replace(/^https?:\/\//,``)}}var cd=`truncate text-sm text-fg-2 group-aria-[current=true]/ws:text-on-accent-soft group-aria-[current=true]/ws:opacity-80`,ld=`group/ws relative flex min-h-[60px] items-center gap-3.5 px-4 py-2.5 text-fg no-underline transition-colors`;function ud({label:e}){return e?(0,C.jsx)(`span`,{className:b(cd,`[direction:rtl] text-left`),title:e,children:(0,C.jsx)(`span`,{dir:`ltr`,className:`[unicode-bidi:isolate]`,children:e})}):null}function dd({name:e,named:t}){let n=t===!1;return(0,C.jsx)(`span`,{className:b(`truncate text-md tracking-[0.2px]`,n&&`italic text-fg-2`,`group-data-[missing]/ws:line-through group-data-[stopped]/ws:text-fg-2`),title:n?`${e} — folder name; set name: in kraftwerk.yml`:e,children:e})}function fd({entry:e,ambiguous:t}){let[n,r]=(0,v.useState)(`idle`),[i,a]=(0,v.useState)(``),o=e.exists===!1,s=async()=>{r(`starting`),a(``);try{window.location.assign(await ae(e.root))}catch(e){r(`error`),a(e.message)}};return(0,C.jsxs)(`span`,{className:b(ld,`cursor-default`),role:`menuitem`,"data-stopped":``,"data-missing":o?``:void 0,style:{"--ws-c":F(e.color,e.root??e.url)},children:[(0,C.jsx)(Te,{className:`opacity-60 grayscale-50`,icon:e.icon,name:e.name,color:e.color,seed:e.root??e.url,ambiguous:t}),(0,C.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,C.jsx)(dd,{name:e.name,named:e.named}),n===`error`?(0,C.jsx)(`span`,{className:b(cd,`text-bad`),title:i,children:i}):o?(0,C.jsx)(`span`,{className:cd,children:`folder missing`}):(0,C.jsx)(ud,{label:e.rootLabel})]}),(0,C.jsxs)(`span`,{className:`ml-auto inline-flex flex-none items-center gap-3`,children:[(0,C.jsx)(pd,{url:e.url}),(0,C.jsx)(z,{variant:`quiet`,size:`sm`,icon:`play_arrow`,busy:n===`starting`,className:`text-accent hover:text-accent`,disabled:o,title:o?`The project folder no longer exists`:`Start the UI for this project`,onClick:e=>{e.stopPropagation(),s()},children:n===`starting`?`starting`:`start`})]})]})}function pd({url:e,live:t}){return(0,C.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 whitespace-nowrap text-2xs font-medium tracking-[0.5px] text-fg-2`,children:[t&&(0,C.jsx)(V,{tone:`ok`,title:`running`}),sd(e)]})}function md({entry:e,ambiguous:t}){let n=e.root??e.url;return(0,C.jsxs)(`a`,{className:b(ld,`hover:bg-surface-2 active:bg-surface-2`),role:`menuitem`,href:e.url,style:{"--ws-c":F(e.color,n)},children:[(0,C.jsx)(Te,{icon:e.icon,name:e.name,color:e.color,seed:n,ambiguous:t}),(0,C.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,C.jsx)(dd,{name:e.name,named:e.named}),(0,C.jsx)(ud,{label:e.rootLabel??(e.root?void 0:e.url.replace(/^https?:\/\//,``))})]}),(0,C.jsx)(`span`,{className:`ml-auto inline-flex flex-none items-center gap-3`,children:(0,C.jsx)(pd,{url:e.url,live:e.live})})]})}function hd({name:e,icon:t,color:n,named:r,root:i,seed:a,entries:o}){let[s,c]=(0,v.useState)(!1),l=ue();(0,v.useEffect)(()=>{if(!s)return;let e=e=>{e.target.closest(`[data-switcher]`)||c(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]);let u=new Map;for(let e of[t,...o.map(e=>e.icon)])e&&u.set(e,(u.get(e)??0)+1);let d=e=>!!e&&(u.get(e)??0)>1,f=[{key:`running`,label:`running`,items:o.filter(e=>e.live===!0)},{key:`stopped`,label:`stopped`,items:o.filter(e=>e.live===!1)},{key:`linked`,label:`linked`,items:o.filter(e=>e.live===void 0)}].filter(e=>e.items.length>0),p=a||e;return(0,C.jsxs)(`span`,{className:`relative inline-flex min-w-0`,"data-switcher":``,children:[(0,C.jsxs)(`button`,{type:`button`,className:`env-switch inline-flex max-w-[220px] min-w-0 cursor-pointer items-center gap-[5px] rounded-xl border-0 bg-transparent px-2 py-1 font-[inherit] text-[15px] font-bold tracking-[0.02em] whitespace-nowrap text-fg transition-colors hover:bg-surface-2 max-[1520px]:max-w-[250px]`,title:i?`${i} — workspace menu`:`Workspace menu`,"aria-haspopup":`menu`,"aria-expanded":s,onClick:()=>c(e=>!e),children:[(0,C.jsx)(`span`,{className:`min-w-0 truncate`,children:e}),(0,C.jsx)(w,{name:`expand_more`,className:`flex-none opacity-55`})]}),s&&(0,C.jsxs)(`div`,{className:`absolute top-[calc(100%+8px)] left-0 z-20 max-h-[calc(100dvh-120px)] max-w-[min(480px,92vw)] min-w-[360px] max-[800px]:fixed max-[800px]:inset-x-2 max-[800px]:top-[calc(var(--topbar-h)-4px)] max-[800px]:max-w-none max-[800px]:min-w-0 overflow-y-auto overscroll-contain rounded-card border border-line bg-surface py-2 shadow-pop`,role:`menu`,children:[o.length>0&&(0,C.jsx)(He,{className:`block px-4 pt-1 pb-2`,children:`workspaces`}),(0,C.jsxs)(`span`,{className:b(ld,`cursor-default bg-accent-soft text-on-accent-soft`),"aria-current":`true`,style:{"--ws-c":F(n,p)},children:[(0,C.jsx)(Te,{icon:t,name:e,color:n,seed:p,ambiguous:d(t)}),(0,C.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,C.jsx)(dd,{name:e,named:r}),i?(0,C.jsx)(ud,{label:i}):(0,C.jsx)(`span`,{className:cd,children:`this workspace`})]}),(0,C.jsx)(`span`,{className:`ml-auto inline-flex flex-none items-center gap-3`,children:(0,C.jsx)(w,{name:`check`,className:`text-[24px] text-on-accent-soft`})})]}),f.map(e=>(0,C.jsxs)(`div`,{className:`mt-2 border-t border-line pt-1`,role:`group`,"aria-label":e.label,children:[(0,C.jsx)(He,{className:`block px-4 pt-2 pb-1`,children:e.label}),e.items.map(e=>e.live===!1&&e.root?(0,C.jsx)(fd,{entry:e,ambiguous:d(e.icon)},e.root):(0,C.jsx)(md,{entry:e,ambiguous:d(e.icon)},e.root??e.url))]},e.key)),l&&o.length>0&&(0,C.jsxs)(`a`,{className:`mt-2 flex min-h-12 items-center gap-4 border-t border-line px-4 text-md text-fg no-underline transition-colors hover:bg-surface-2`,href:`#/workspaces`,role:`menuitem`,onClick:()=>c(!1),children:[(0,C.jsx)(w,{name:`hub`,className:`text-[22px] text-fg-2`}),` manage workspaces`]}),(0,C.jsx)(Ed,{onClose:()=>c(!1)})]})]})}function gd(){let[e,t]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let e=!0;return fetch(`/api/runs`).then(e=>e.json()).then(n=>{e&&(n.runs.length>0?M(`/runs/${n.runs[0].id}`,{replace:!0}):t({outputDir:n.outputDir}))}).catch(()=>{}),()=>{e=!1}},[]),e?(0,C.jsxs)(W,{icon:`play_circle`,children:[`No runs found in `,(0,C.jsx)(`code`,{children:e.outputDir}),`. Start one from the`,` `,(0,C.jsx)(`a`,{href:`#/workflows`,className:`text-accent`,children:`workflows`}),` list or with `,(0,C.jsx)(`code`,{children:`kraftwerk run <workflow> [request]`}),`.`]}):(0,C.jsx)(W,{children:`loading…`})}async function _d(e){await fetch(`/api/restart`,{method:`POST`}).catch(()=>{});for(let t=0;t<60;t++){await new Promise(e=>setTimeout(e,500));try{if((await fetch(`/api/meta`,{cache:`no-store`}).then(e=>e.json())).version===e)break}catch{}}location.reload()}var vd=`kw-version-changed`;function yd(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let e=!0,n,r=async()=>{clearTimeout(n);try{let n=await fetch(`/api/meta`,{cache:`no-store`}).then(e=>e.json());e&&t(n)}catch{}e&&(n=setTimeout(r,3e4))};r();let i=()=>void r();return window.addEventListener(vd,i),()=>{e=!1,clearTimeout(n),window.removeEventListener(vd,i)}},[]);let i=e?.restartable&&e.diskVersion&&e.diskVersion!==e.version?e.diskVersion:null;async function a(){i&&(r(!0),await _d(i))}return!i&&!n?null:(0,C.jsx)(`button`,{type:`button`,className:`mr-2.5 inline-flex flex-none cursor-pointer items-center gap-1 rounded-full border border-accent bg-accent/10 px-3 py-1 font-[inherit] text-xs text-accent hover:bg-accent/18 disabled:cursor-default disabled:opacity-70`,disabled:n,title:`v${i} is installed on disk, the server still runs v${e?.version}. Click to relaunch with the new version.`,onClick:()=>void a(),children:n?`relaunching…`:(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(w,{name:`restart_alt`,className:`ms-sm`}),` v`,i,` ready — relaunch`]})})}function bd(){let e=ue();return(0,C.jsxs)(`button`,{type:`button`,className:b(`expert-toggle inline-flex cursor-pointer items-center gap-[7px] rounded-full border-0 bg-transparent px-2 py-1 font-mono text-2xs tracking-[0.5px] transition-colors hover:text-fg`,e?`text-fg`:`text-fg-2`),title:e?`Expert mode on — full detail`:`Expert mode off — simplified view`,"aria-pressed":e,onClick:()=>le(!e),children:[(0,C.jsx)(`span`,{className:b(`relative h-[15px] w-[26px] rounded-full transition-colors`,e?`bg-accent`:`bg-fg/14`),children:(0,C.jsx)(`span`,{className:b(`absolute top-0.5 size-[11px] rounded-full transition-[left,background-color]`,e?`left-[13px] bg-on-accent`:`left-0.5 bg-surface`)})}),`expert`]})}var xd={approval:`gavel`,routine_done:`schedule`,routine_failed:`schedule`,run_done:`account_tree`,run_failed:`account_tree`},Sd=`kw.notif.toast.dismissed`;function Cd(){let[e,t]=(0,v.useState)(!1),n=R(`/api/notifications`,!1,5e3),[r,i]=(0,v.useState)(()=>typeof Notification>`u`?`unsupported`:Notification.permission),[a,o]=(0,v.useState)(()=>{try{return localStorage.getItem(Sd)===`1`}catch{return!1}}),s=(0,v.useRef)(null),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(null);(0,v.useEffect)(()=>l(null),[n]);let f=(c??n)?.items??[],p=Ct()??[],m=new Set(p.map(e=>e.notificationId).filter(Boolean)),h=f.filter(e=>e.kind!==`approval`&&!m.has(e.id)),g=h.filter(e=>!e.readAt).length,_=p.length;(0,v.useEffect)(()=>ee(p.length),[p.length]),(0,v.useEffect)(()=>{if(n){if(!s.current){s.current=new Set(f.map(e=>e.id));return}for(let e of f)if(!s.current.has(e.id)&&(s.current.add(e.id),!(e.readAt||r!==`granted`)&&(document.hidden||location.hash!==`#${e.href}`)))try{let t=new Notification(e.title,{body:e.body,tag:e.id});t.onclick=()=>{window.focus(),x(e),t.close()}}catch{}}},[n]),(0,v.useEffect)(()=>{if(!e)return;let n=e=>{e.target.closest(`[data-bell]`)||t(!1)};return window.addEventListener(`mousedown`,n),()=>window.removeEventListener(`mousedown`,n)},[e]);async function y(e,t){try{let n=await fetch(e,{method:e.endsWith(`/notifications`)?`DELETE`:`POST`,headers:{"content-type":`application/json`},body:t===void 0?void 0:JSON.stringify(t)});if(!n.ok)return;let r=await n.json();l(`items`in r?r:{items:[],unread:0})}catch{}}function x(e){t(!1),e.readAt||y(`/api/notifications/read`,{ids:[e.id]}),M(e.href)}async function S(e){d(e.id);try{let n=await(await fetch(`/api/notifications/${encodeURIComponent(e.id)}/diagnose`,{method:`POST`})).json();n.href?(t(!1),M(n.href)):n.error&&alert(n.error)}catch{}d(null)}async function T(){typeof Notification<`u`&&i(await Notification.requestPermission())}function E(){o(!0);try{localStorage.setItem(Sd,`1`)}catch{}}let D=r==="default"&&!a;return(0,C.jsxs)(`span`,{className:`relative inline-flex`,"data-bell":``,children:[(0,C.jsxs)(`button`,{type:`button`,className:b(`relative grid size-8 cursor-pointer place-items-center rounded-full border-0 bg-transparent transition-colors hover:bg-surface-2 hover:text-fg`,_?`text-fg`:`text-fg-2`),title:_?`${_} thing${_===1?``:`s`} waiting for you`:g?`${g} update${g===1?``:`s`}`:`Notifications`,"aria-label":`Notifications`,onClick:()=>t(e=>!e),children:[(0,C.jsx)(w,{name:_?`notifications_active`:`notifications`}),g>0&&(0,C.jsx)(`span`,{className:`absolute top-1.5 right-1.5 size-[7px] rounded-full bg-accent`})]}),e&&(0,C.jsxs)(`div`,{className:`notif-pop absolute right-0 top-[calc(100%+8px)] z-50 flex max-h-[min(80dvh,640px)] w-[min(460px,92vw)] flex-col overflow-hidden rounded-card border border-line bg-surface shadow-pop`,role:`menu`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-line px-4 py-2`,children:[(0,C.jsx)(He,{className:`text-fg`,children:`notifications`}),(0,C.jsx)(`span`,{className:`flex-1`}),g>0&&(0,C.jsx)(z,{variant:`quiet`,size:`sm`,onClick:()=>void y(`/api/notifications/read`,{ids:h.filter(e=>!e.readAt).map(e=>e.id)}),children:`mark updates read`}),f.length>0&&(0,C.jsx)(z,{variant:`quiet`,size:`sm`,onClick:()=>void y(`/api/notifications`),children:`clear`})]}),(0,C.jsxs)(`div`,{className:`min-h-0 overflow-y-auto overscroll-contain pb-1.5`,children:[D&&(0,C.jsxs)(`div`,{className:`m-2 flex flex-col gap-2 rounded-control bg-surface-2 p-3 text-sm`,children:[(0,C.jsx)(`span`,{children:`Get a system notification when something needs you, even with this tab in the background.`}),(0,C.jsxs)(`span`,{className:`flex gap-2`,children:[(0,C.jsx)(z,{variant:`primary`,size:`sm`,onClick:()=>void T(),children:`enable`}),(0,C.jsx)(z,{variant:`quiet`,size:`sm`,onClick:E,children:`not now`})]})]}),r===`denied`&&(0,C.jsx)(`p`,{className:`m-0 px-4 pt-2 text-xs text-fg-2`,children:`Browser notifications are blocked for this site — allow them in the address bar to get system alerts.`}),(0,C.jsx)(Ue,{title:`needs you`,count:p.length||void 0,className:`px-1.5 pt-1.5`,children:p.length===0?(0,C.jsx)(`p`,{className:`m-0 px-2.5 py-2 text-sm text-fg-2`,children:`nothing is waiting for you`}):Td(p).map(([e,n])=>(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`div`,{className:`notif-owner px-2.5 pb-0.5 pt-2 text-xs font-semibold text-fg`,children:e}),n.map(e=>{let n=e.notificationId?f.find(t=>t.id===e.notificationId):void 0;return(0,C.jsx)(q,{className:`notif-row need`,onClick:()=>{t(!1),kt(e)},leading:(0,C.jsx)(w,{name:e.kind===`approval`?`front_hand`:e.kind===`question`?`help`:`error`,className:`ms-sm text-bad`}),title:e.title,sub:`${e.kind===`approval`?`needs approval`:e.kind===`question`?`asks you`:`failed`}${e.chatTitle?` · in ${e.chatTitle}`:``}`,meta:Ne(e.since),actionsAlways:!0,actions:n?.diagnose?(0,C.jsx)(wd,{busy:u===n.id,onClick:()=>void S(n)}):void 0},e.id)})]},e))}),(0,C.jsx)(Ue,{title:`updates`,className:`px-1.5 pt-1.5`,children:h.length===0?(0,C.jsx)(`p`,{className:`m-0 px-2.5 py-2 text-sm text-fg-2`,children:`no updates`}):h.slice(0,50).map(e=>(0,C.jsx)(q,{className:b(`notif-row`,!e.readAt&&`bg-accent/5`),onClick:()=>x(e),leading:(0,C.jsx)(w,{name:xd[e.kind],className:b(`ms-sm`,e.kind.endsWith(`failed`)?`text-bad`:e.kind.endsWith(`done`)?`text-ok`:``)}),title:e.title,sub:e.body,meta:Ne(e.at),actionsAlways:!0,actions:e.diagnose?(0,C.jsx)(wd,{busy:u===e.id,onClick:()=>void S(e)}):void 0},e.id))})]})]})]})}function wd({busy:e,onClick:t}){return(0,C.jsx)(z,{variant:`secondary`,size:`sm`,icon:`troubleshoot`,busy:e,title:`Open a chat that finds the cause and proposes the fix`,onClick:e=>{e.stopPropagation(),t()},children:e?`starting…`:`diagnose`})}function Td(e){let t=new Map;for(let n of e){let e=Tt(n.owner);t.set(e,[...t.get(e)??[],n])}return[...t.entries()]}function Ed({onClose:e}){let t=ue(),[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``);return(0,v.useEffect)(()=>{fetch(`/api/meta`).then(e=>e.json()).then(e=>s(e.version)).catch(()=>{}),t&&(fetch(`/api/runs`).then(e=>e.json()).then(r).catch(()=>{}),fetch(`/api/workflows`).then(e=>e.json()).then(a).catch(()=>{}))},[t]),(0,C.jsxs)(`div`,{className:`ws-menu mt-1.5 flex flex-col gap-0.5 border-t border-line px-1.5 pb-1 pt-2`,children:[(0,C.jsx)(Dd,{label:`Detail`,children:(0,C.jsx)(bd,{})}),(0,C.jsx)(Dd,{label:`Theme`,children:(0,C.jsx)(Md,{})}),(0,C.jsxs)(`div`,{className:`flex gap-1 px-1`,children:[(0,C.jsx)(z,{variant:`quiet`,size:`sm`,icon:`settings`,href:`/settings`,onClick:e,children:`settings`}),(0,C.jsx)(z,{variant:`quiet`,size:`sm`,icon:`delete`,href:`/trash`,onClick:e,children:`trash`})]}),t&&(0,C.jsxs)(`div`,{className:`flex flex-col gap-1 px-2.5 py-1.5 text-xs`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(He,{children:`Workflows`}),` `,i?`${i.workflows.length} discovered`:`…`,` `,(0,C.jsx)(`code`,{className:`block break-all text-2xs text-fg-2`,title:i?.root,children:i?.root??``})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(He,{children:`Runs`}),` `,n?`${n.runs.length} total`:`…`,` `,(0,C.jsx)(`code`,{className:`block break-all text-2xs text-fg-2`,title:n?.outputDir,children:n?.outputDir??``})]})]}),(0,C.jsx)(Dd,{label:(0,C.jsx)(`span`,{className:`font-mono`,children:o?`kraftwerk ${o}`:`…`}),children:(0,C.jsx)(kd,{})})]})}function Dd({label:e,children:t}){return(0,C.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-2.5 py-1.5`,children:[(0,C.jsx)(`span`,{className:`text-sm text-fg-2`,children:e}),t]})}function Od(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++)if((n[e]??0)!==(r[e]??0))return(n[e]??0)<(r[e]??0);return!1}function kd(){let[e,t]=(0,v.useState)(`idle`),[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1);async function u(){t(`busy`);try{let e=await fetch(`/api/update-check`,{cache:`no-store`}),n=await e.json();if(!e.ok||!n.latest)throw Error();r(n),t(`done`)}catch{t(`err`)}}let d=i?.state===`running`;(0,v.useEffect)(()=>{if(!d)return;let e=!0,t=setInterval(async()=>{try{let t=await fetch(`/api/update`,{cache:`no-store`}).then(e=>e.json());if(!e)return;a(t),t.state!==`running`&&window.dispatchEvent(new Event(vd))}catch{}},1e3);return()=>{e=!1,clearInterval(t)}},[d]);async function f(){if(!n)return;s(``);let e=await fetch(`/api/update`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({version:n.latest})}),t=await e.json();e.ok?a(t):s(t.error??`update refused`)}if(i&&i.state!==`idle`&&n){let e=i.log[i.log.length-1]??``;return i.state===`running`?(0,C.jsxs)(`span`,{className:b(Ad,`basis-full flex-wrap`),children:[(0,C.jsx)(w,{name:`progress_activity`,className:`ms-sm`}),` installing v`,n.latest,`…`,e&&(0,C.jsx)(`code`,{className:`max-w-full truncate text-2xs text-fg-2`,title:i.log.join(`
228
228
  `),children:e})]}):i.state===`done`?(0,C.jsxs)(`span`,{className:b(Ad,jd),children:[`v`,n.latest,` installed —`,` `,i.restartable?(0,C.jsx)(z,{size:`sm`,icon:`restart_alt`,busy:c,onClick:()=>{l(!0),_d(n.latest)},children:c?`relaunching…`:`relaunch`}):(0,C.jsxs)(C.Fragment,{children:[`restart `,(0,C.jsx)(`code`,{children:`kraftwerk ui`}),` to use it`]})]}):(0,C.jsxs)(`span`,{className:b(Ad,`basis-full flex-wrap text-bad`),title:i.log.join(`
229
229
  `),children:[(0,C.jsx)(w,{name:`error`,className:`ms-sm`}),` install failed`,e?` — ${e}`:``,` · `,(0,C.jsxs)(`code`,{children:[`npm i -g `,n.name,`@latest`]})]})}return e===`done`&&n?Od(n.current,n.latest)?(0,C.jsxs)(`span`,{className:b(Ad,jd),children:[`v`,n.latest,` available —`,` `,o?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`span`,{className:`font-normal text-fg-2`,title:o,children:o}),` · `,(0,C.jsxs)(`code`,{className:`text-2xs`,children:[`npm i -g `,n.name,`@latest`]})]}):(0,C.jsx)(z,{size:`sm`,icon:`download`,onClick:()=>void f(),children:`update now`})]}):(0,C.jsxs)(`span`,{className:Ad,children:[(0,C.jsx)(w,{name:`check`,className:`ms-sm text-ok`}),` up to date`]}):(0,C.jsx)(z,{size:`sm`,icon:e===`busy`||e===`err`?void 0:`sync`,disabled:e===`busy`,onClick:()=>void u(),children:e===`busy`?`checking…`:e===`err`?`npm unreachable — retry`:`check for updates`})}var Ad=`inline-flex items-center gap-[5px] text-xs text-fg-2`,jd=`basis-full flex-wrap font-medium text-accent`;function Md(){return(0,C.jsx)(z,{size:`sm`,icon:`contrast`,onClick:()=>{let e=document.documentElement,t=e.dataset.theme===`light`?`dark`:`light`;e.dataset.theme=t;try{localStorage.setItem(`kw-theme`,t)}catch{}},children:`day / night`})}(0,y.createRoot)(document.getElementById(`root`)).render((0,C.jsx)(v.StrictMode,{children:(0,C.jsx)(od,{})}));export{o as a,d as i,S as n,s as o,h as r,l as s,Hc as t};