@whoz-oss/coday-server 0.149.0 → 0.151.0
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.
- package/package.json +1 -1
- package/server.js +1 -1
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -1544,7 +1544,7 @@ ${m.join(`
|
|
|
1544
1544
|
`;d.forEach(m=>{p+=m}),e.fail(p)}};let c={};a.conflicts=function(f,d){Xe("<string|object> [array|string]",[f,d],arguments.length),typeof f=="object"?Object.keys(f).forEach(p=>{a.conflicts(p,f[p])}):(r.global(f),c[f]||(c[f]=[]),Array.isArray(d)?d.forEach(p=>a.conflicts(f,p)):c[f].push(d))},a.getConflicting=()=>c,a.conflicting=function(f){Object.keys(f).forEach(d=>{c[d]&&c[d].forEach(p=>{p&&f[d]!==void 0&&f[p]!==void 0&&e.fail(n("Arguments %s and %s are mutually exclusive",d,p))})}),r.getInternalMethods().getParserConfiguration()["strip-dashed"]&&Object.keys(c).forEach(d=>{c[d].forEach(p=>{p&&f[t.Parser.camelCase(d)]!==void 0&&f[t.Parser.camelCase(p)]!==void 0&&e.fail(n("Arguments %s and %s are mutually exclusive",d,p))})})},a.recommendCommands=function(f,d){d=d.sort((g,v)=>v.length-g.length);let m=null,h=1/0;for(let g=0,v;(v=d[g])!==void 0;g++){let y=Ywe(f,v);y<=3&&y<h&&(h=y,m=v)}m&&e.fail(n("Did you mean %s?",m))},a.reset=function(f){return o=Jf(o,d=>!f[d]),c=Jf(c,d=>!f[d]),a};let u=[];return a.freeze=function(){u.push({implied:o,conflicting:c})},a.unfreeze=function(){let f=u.pop();Ba(f,void 0,t),{implied:o,conflicting:c}=f},a}var yY=[],W7;function V7(r,e,t,n){W7=n;let i={};if(Object.prototype.hasOwnProperty.call(r,"extends")){if(typeof r.extends!="string")return i;let a=/\.json|\..*rc$/.test(r.extends),o=null;if(a)o=Xwt(e,r.extends);else try{o=import.meta.resolve(r.extends)}catch{return r}Ywt(o),yY.push(o),i=a?JSON.parse(W7.readFileSync(o,"utf8")):n.require(r.extends),delete r.extends,i=V7(i,W7.path.dirname(o),t,W7)}return yY=[],t?e_e(i,r):Object.assign({},i,r)}function Ywt(r){if(yY.indexOf(r)>-1)throw new Xn(`Circular extended configurations: '${r}'.`)}function Xwt(r,e){return W7.path.resolve(r,e)}function e_e(r,e){let t={};function n(i){return i&&typeof i=="object"&&!Array.isArray(i)}Object.assign(t,r);for(let i of Object.keys(e))n(e[i])&&n(t[i])?t[i]=e_e(r[i],e[i]):t[i]=e[i];return t}var Qe=function(r,e,t,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(r,t):i?i.value=t:e.set(r,t),t},z=function(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)},Qn,I3,G7,wo,Xo,gI,Yf,D3,vI,Ds,yI,Os,Au,Qo,$s,bI,O3,ji,ot,xI,wI,es,$3,H4,R3,Xf,_I,kt,j3,N3,M3,Ft,SI,Tu,qn;function x_e(r){return(e=[],t=r.process.cwd(),n)=>{let i=new PY(e,t,n,r);return Object.defineProperty(i,"argv",{get:()=>i.parse(),enumerable:!0}),i.help(),i.version(),i}}var t_e=Symbol("copyDoubleDash"),r_e=Symbol("copyDoubleDash"),bY=Symbol("deleteFromParserHintObject"),n_e=Symbol("emitWarning"),i_e=Symbol("freeze"),a_e=Symbol("getDollarZero"),F3=Symbol("getParserConfiguration"),o_e=Symbol("getUsageConfiguration"),xY=Symbol("guessLocale"),s_e=Symbol("guessVersion"),c_e=Symbol("parsePositionalNumbers"),wY=Symbol("pkgUp"),Qf=Symbol("populateParserHintArray"),W4=Symbol("populateParserHintSingleValueDictionary"),_Y=Symbol("populateParserHintArrayDictionary"),SY=Symbol("populateParserHintDictionary"),EY=Symbol("sanitizeKey"),kY=Symbol("setKey"),CY=Symbol("unfreeze"),u_e=Symbol("validateAsync"),l_e=Symbol("getCommandInstance"),f_e=Symbol("getContext"),d_e=Symbol("getHasOutput"),p_e=Symbol("getLoggerInstance"),h_e=Symbol("getParseContext"),m_e=Symbol("getUsageInstance"),g_e=Symbol("getValidationInstance"),EI=Symbol("hasParseCallback"),v_e=Symbol("isGlobalContext"),L3=Symbol("postProcess"),y_e=Symbol("rebase"),AY=Symbol("reset"),Z7=Symbol("runYargsParserAndExecuteCommands"),TY=Symbol("runValidation"),b_e=Symbol("setHasOutput"),q3=Symbol("kTrackManuallySetKeys"),Qwt="en_US",PY=class{constructor(e=[],t,n,i){this.customScriptName=!1,this.parsed=!1,Qn.set(this,void 0),I3.set(this,void 0),G7.set(this,{commands:[],fullCommands:[]}),wo.set(this,null),Xo.set(this,null),gI.set(this,"show-hidden"),Yf.set(this,null),D3.set(this,!0),vI.set(this,{}),Ds.set(this,!0),yI.set(this,[]),Os.set(this,void 0),Au.set(this,{}),Qo.set(this,!1),$s.set(this,null),bI.set(this,!0),O3.set(this,void 0),ji.set(this,""),ot.set(this,void 0),xI.set(this,void 0),wI.set(this,{}),es.set(this,null),$3.set(this,null),H4.set(this,{}),R3.set(this,{}),Xf.set(this,void 0),_I.set(this,!1),kt.set(this,void 0),j3.set(this,!1),N3.set(this,!1),M3.set(this,!1),Ft.set(this,void 0),SI.set(this,{}),Tu.set(this,null),qn.set(this,void 0),Qe(this,kt,i,"f"),Qe(this,Xf,e,"f"),Qe(this,I3,t,"f"),Qe(this,xI,n,"f"),Qe(this,Os,new pI(this),"f"),this.$0=this[a_e](),this[AY](),Qe(this,Qn,z(this,Qn,"f"),"f"),Qe(this,Ft,z(this,Ft,"f"),"f"),Qe(this,qn,z(this,qn,"f"),"f"),Qe(this,ot,z(this,ot,"f"),"f"),z(this,ot,"f").showHiddenOpt=z(this,gI,"f"),Qe(this,O3,this[r_e](),"f"),z(this,kt,"f").y18n.setLocale(Qwt)}addHelpOpt(e,t){let n="help";return Xe("[string|boolean] [string]",[e,t],arguments.length),z(this,$s,"f")&&(this[bY](z(this,$s,"f")),Qe(this,$s,null,"f")),e===!1&&t===void 0?this:(Qe(this,$s,typeof e=="string"?e:n,"f"),this.boolean(z(this,$s,"f")),this.describe(z(this,$s,"f"),t||z(this,Ft,"f").deferY18nLookup("Show help")),this)}help(e,t){return this.addHelpOpt(e,t)}addShowHiddenOpt(e,t){if(Xe("[string|boolean] [string]",[e,t],arguments.length),e===!1&&t===void 0)return this;let n=typeof e=="string"?e:z(this,gI,"f");return this.boolean(n),this.describe(n,t||z(this,Ft,"f").deferY18nLookup("Show hidden options")),z(this,ot,"f").showHiddenOpt=n,this}showHidden(e,t){return this.addShowHiddenOpt(e,t)}alias(e,t){return Xe("<object|string|array> [string|array]",[e,t],arguments.length),this[_Y](this.alias.bind(this),"alias",e,t),this}array(e){return Xe("<array|string>",[e],arguments.length),this[Qf]("array",e),this[q3](e),this}boolean(e){return Xe("<array|string>",[e],arguments.length),this[Qf]("boolean",e),this[q3](e),this}check(e,t){return Xe("<function> [boolean]",[e,t],arguments.length),this.middleware((n,i)=>P3(()=>e(n,i.getOptions()),a=>(a?(typeof a=="string"||a instanceof Error)&&z(this,Ft,"f").fail(a.toString(),a):z(this,Ft,"f").fail(z(this,kt,"f").y18n.__("Argument check failed: %s",e.toString())),n),a=>(z(this,Ft,"f").fail(a.message?a.message:a.toString(),a),n)),!1,t),this}choices(e,t){return Xe("<object|string|array> [string|array]",[e,t],arguments.length),this[_Y](this.choices.bind(this),"choices",e,t),this}coerce(e,t){if(Xe("<object|string|array> [function]",[e,t],arguments.length),Array.isArray(e)){if(!t)throw new Xn("coerce callback must be provided");for(let i of e)this.coerce(i,t);return this}else if(typeof e=="object"){for(let i of Object.keys(e))this.coerce(i,e[i]);return this}if(!t)throw new Xn("coerce callback must be provided");let n=e;return z(this,ot,"f").key[n]=!0,z(this,Os,"f").addCoerceMiddleware((i,a)=>{var o;let s=(o=a.getAliases()[n])!==null&&o!==void 0?o:[],c=[n,...s].filter(u=>Object.prototype.hasOwnProperty.call(i,u));return c.length===0?i:P3(()=>t(i[c[0]]),u=>(c.forEach(l=>{i[l]=u}),i),u=>{throw new Xn(u.message)})},n),this}conflicts(e,t){return Xe("<string|object> [string|array]",[e,t],arguments.length),z(this,qn,"f").conflicts(e,t),this}config(e="config",t,n){return Xe("[object|string] [string|function] [function]",[e,t,n],arguments.length),typeof e=="object"&&!Array.isArray(e)?(e=V7(e,z(this,I3,"f"),this[F3]()["deep-merge-config"]||!1,z(this,kt,"f")),z(this,ot,"f").configObjects=(z(this,ot,"f").configObjects||[]).concat(e),this):(typeof t=="function"&&(n=t,t=void 0),this.describe(e,t||z(this,Ft,"f").deferY18nLookup("Path to JSON config file")),(Array.isArray(e)?e:[e]).forEach(i=>{z(this,ot,"f").config[i]=n||!0}),this)}completion(e,t,n){return Xe("[string] [string|boolean|function] [function]",[e,t,n],arguments.length),typeof t=="function"&&(n=t,t=void 0),Qe(this,Xo,e||z(this,Xo,"f")||"completion","f"),!t&&t!==!1&&(t="generate completion script"),this.command(z(this,Xo,"f"),t),n&&z(this,wo,"f").registerFunction(n),this}command(e,t,n,i,a,o){return Xe("<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]",[e,t,n,i,a,o],arguments.length),z(this,Qn,"f").addHandler(e,t,n,i,a,o),this}commands(e,t,n,i,a,o){return this.command(e,t,n,i,a,o)}commandDir(e,t){Xe("<string> [object]",[e,t],arguments.length);let n=z(this,xI,"f")||z(this,kt,"f").require;return z(this,Qn,"f").addDirectory(e,n,z(this,kt,"f").getCallerFile(),t),this}count(e){return Xe("<array|string>",[e],arguments.length),this[Qf]("count",e),this[q3](e),this}default(e,t,n){return Xe("<object|string|array> [*] [string]",[e,t,n],arguments.length),n&&(hY(e,z(this,kt,"f")),z(this,ot,"f").defaultDescription[e]=n),typeof t=="function"&&(hY(e,z(this,kt,"f")),z(this,ot,"f").defaultDescription[e]||(z(this,ot,"f").defaultDescription[e]=z(this,Ft,"f").functionDescription(t)),t=t.call()),this[W4](this.default.bind(this),"default",e,t),this}defaults(e,t,n){return this.default(e,t,n)}demandCommand(e=1,t,n,i){return Xe("[number] [number|string] [string|null|undefined] [string|null|undefined]",[e,t,n,i],arguments.length),typeof t!="number"&&(n=t,t=1/0),this.global("_",!1),z(this,ot,"f").demandedCommands._={min:e,max:t,minMsg:n,maxMsg:i},this}demand(e,t,n){return Array.isArray(t)?(t.forEach(i=>{Ba(n,!0,z(this,kt,"f")),this.demandOption(i,n)}),t=1/0):typeof t!="number"&&(n=t,t=1/0),typeof e=="number"?(Ba(n,!0,z(this,kt,"f")),this.demandCommand(e,t,n,n)):Array.isArray(e)?e.forEach(i=>{Ba(n,!0,z(this,kt,"f")),this.demandOption(i,n)}):typeof n=="string"?this.demandOption(e,n):(n===!0||typeof n>"u")&&this.demandOption(e),this}demandOption(e,t){return Xe("<object|string|array> [string]",[e,t],arguments.length),this[W4](this.demandOption.bind(this),"demandedOptions",e,t),this}deprecateOption(e,t){return Xe("<string> [string|boolean]",[e,t],arguments.length),z(this,ot,"f").deprecatedOptions[e]=t,this}describe(e,t){return Xe("<object|string|array> [string]",[e,t],arguments.length),this[kY](e,!0),z(this,Ft,"f").describe(e,t),this}detectLocale(e){return Xe("<boolean>",[e],arguments.length),Qe(this,D3,e,"f"),this}env(e){return Xe("[string|boolean]",[e],arguments.length),e===!1?delete z(this,ot,"f").envPrefix:z(this,ot,"f").envPrefix=e||"",this}epilogue(e){return Xe("<string>",[e],arguments.length),z(this,Ft,"f").epilog(e),this}epilog(e){return this.epilogue(e)}example(e,t){return Xe("<string|array> [string]",[e,t],arguments.length),Array.isArray(e)?e.forEach(n=>this.example(...n)):z(this,Ft,"f").example(e,t),this}exit(e,t){Qe(this,Qo,!0,"f"),Qe(this,Yf,t,"f"),z(this,Ds,"f")&&z(this,kt,"f").process.exit(e)}exitProcess(e=!0){return Xe("[boolean]",[e],arguments.length),Qe(this,Ds,e,"f"),this}fail(e){if(Xe("<function|boolean>",[e],arguments.length),typeof e=="boolean"&&e!==!1)throw new Xn("Invalid first argument. Expected function or boolean 'false'");return z(this,Ft,"f").failFn(e),this}getAliases(){return this.parsed?this.parsed.aliases:{}}async getCompletion(e,t){return Xe("<array> [function]",[e,t],arguments.length),t?z(this,wo,"f").getCompletion(e,t):new Promise((n,i)=>{z(this,wo,"f").getCompletion(e,(a,o)=>{a?i(a):n(o)})})}getDemandedOptions(){return Xe([],0),z(this,ot,"f").demandedOptions}getDemandedCommands(){return Xe([],0),z(this,ot,"f").demandedCommands}getDeprecatedOptions(){return Xe([],0),z(this,ot,"f").deprecatedOptions}getDetectLocale(){return z(this,D3,"f")}getExitProcess(){return z(this,Ds,"f")}getGroups(){return Object.assign({},z(this,Au,"f"),z(this,R3,"f"))}getHelp(){if(Qe(this,Qo,!0,"f"),!z(this,Ft,"f").hasCachedHelpMessage()){if(!this.parsed){let t=this[Z7](z(this,Xf,"f"),void 0,void 0,0,!0);if(mn(t))return t.then(()=>z(this,Ft,"f").help())}let e=z(this,Qn,"f").runDefaultBuilderOn(this);if(mn(e))return e.then(()=>z(this,Ft,"f").help())}return Promise.resolve(z(this,Ft,"f").help())}getOptions(){return z(this,ot,"f")}getStrict(){return z(this,j3,"f")}getStrictCommands(){return z(this,N3,"f")}getStrictOptions(){return z(this,M3,"f")}global(e,t){return Xe("<string|array> [boolean]",[e,t],arguments.length),e=[].concat(e),t!==!1?z(this,ot,"f").local=z(this,ot,"f").local.filter(n=>e.indexOf(n)===-1):e.forEach(n=>{z(this,ot,"f").local.includes(n)||z(this,ot,"f").local.push(n)}),this}group(e,t){Xe("<string|array> <string>",[e,t],arguments.length);let n=z(this,R3,"f")[t]||z(this,Au,"f")[t];z(this,R3,"f")[t]&&delete z(this,R3,"f")[t];let i={};return z(this,Au,"f")[t]=(n||[]).concat(e).filter(a=>i[a]?!1:i[a]=!0),this}hide(e){return Xe("<string>",[e],arguments.length),z(this,ot,"f").hiddenOptions.push(e),this}implies(e,t){return Xe("<string|object> [number|string|array]",[e,t],arguments.length),z(this,qn,"f").implies(e,t),this}locale(e){return Xe("[string]",[e],arguments.length),e===void 0?(this[xY](),z(this,kt,"f").y18n.getLocale()):(Qe(this,D3,!1,"f"),z(this,kt,"f").y18n.setLocale(e),this)}middleware(e,t,n){return z(this,Os,"f").addMiddleware(e,!!t,n)}nargs(e,t){return Xe("<string|object|array> [number]",[e,t],arguments.length),this[W4](this.nargs.bind(this),"narg",e,t),this}normalize(e){return Xe("<array|string>",[e],arguments.length),this[Qf]("normalize",e),this}number(e){return Xe("<array|string>",[e],arguments.length),this[Qf]("number",e),this[q3](e),this}option(e,t){if(Xe("<string|object> [object]",[e,t],arguments.length),typeof e=="object")Object.keys(e).forEach(n=>{this.options(n,e[n])});else{typeof t!="object"&&(t={}),this[q3](e),z(this,Tu,"f")&&(e==="version"||t?.alias==="version")&&this[n_e](['"version" is a reserved word.',"Please do one of the following:",'- Disable version with `yargs.version(false)` if using "version" as an option',"- Use the built-in `yargs.version` method instead (if applicable)","- Use a different option key","https://yargs.js.org/docs/#api-reference-version"].join(`
|
|
1545
1545
|
`),void 0,"versionWarning"),z(this,ot,"f").key[e]=!0,t.alias&&this.alias(e,t.alias);let n=t.deprecate||t.deprecated;n&&this.deprecateOption(e,n);let i=t.demand||t.required||t.require;i&&this.demand(e,i),t.demandOption&&this.demandOption(e,typeof t.demandOption=="string"?t.demandOption:void 0),t.conflicts&&this.conflicts(e,t.conflicts),"default"in t&&this.default(e,t.default),t.implies!==void 0&&this.implies(e,t.implies),t.nargs!==void 0&&this.nargs(e,t.nargs),t.config&&this.config(e,t.configParser),t.normalize&&this.normalize(e),t.choices&&this.choices(e,t.choices),t.coerce&&this.coerce(e,t.coerce),t.group&&this.group(e,t.group),(t.boolean||t.type==="boolean")&&(this.boolean(e),t.alias&&this.boolean(t.alias)),(t.array||t.type==="array")&&(this.array(e),t.alias&&this.array(t.alias)),(t.number||t.type==="number")&&(this.number(e),t.alias&&this.number(t.alias)),(t.string||t.type==="string")&&(this.string(e),t.alias&&this.string(t.alias)),(t.count||t.type==="count")&&this.count(e),typeof t.global=="boolean"&&this.global(e,t.global),t.defaultDescription&&(z(this,ot,"f").defaultDescription[e]=t.defaultDescription),t.skipValidation&&this.skipValidation(e);let a=t.describe||t.description||t.desc,o=z(this,Ft,"f").getDescriptions();(!Object.prototype.hasOwnProperty.call(o,e)||typeof a=="string")&&this.describe(e,a),t.hidden&&this.hide(e),t.requiresArg&&this.requiresArg(e)}return this}options(e,t){return this.option(e,t)}parse(e,t,n){Xe("[string|array] [function|boolean|object] [function]",[e,t,n],arguments.length),this[i_e](),typeof e>"u"&&(e=z(this,Xf,"f")),typeof t=="object"&&(Qe(this,$3,t,"f"),t=n),typeof t=="function"&&(Qe(this,es,t,"f"),t=!1),t||Qe(this,Xf,e,"f"),z(this,es,"f")&&Qe(this,Ds,!1,"f");let i=this[Z7](e,!!t),a=this.parsed;return z(this,wo,"f").setParsed(this.parsed),mn(i)?i.then(o=>(z(this,es,"f")&&z(this,es,"f").call(this,z(this,Yf,"f"),o,z(this,ji,"f")),o)).catch(o=>{throw z(this,es,"f")&&z(this,es,"f")(o,this.parsed.argv,z(this,ji,"f")),o}).finally(()=>{this[CY](),this.parsed=a}):(z(this,es,"f")&&z(this,es,"f").call(this,z(this,Yf,"f"),i,z(this,ji,"f")),this[CY](),this.parsed=a,i)}parseAsync(e,t,n){let i=this.parse(e,t,n);return mn(i)?i:Promise.resolve(i)}parseSync(e,t,n){let i=this.parse(e,t,n);if(mn(i))throw new Xn(".parseSync() must not be used with asynchronous builders, handlers, or middleware");return i}parserConfiguration(e){return Xe("<object>",[e],arguments.length),Qe(this,wI,e,"f"),this}pkgConf(e,t){Xe("<string> [string]",[e,t],arguments.length);let n=null,i=this[wY](t||z(this,I3,"f"));return i[e]&&typeof i[e]=="object"&&(n=V7(i[e],t||z(this,I3,"f"),this[F3]()["deep-merge-config"]||!1,z(this,kt,"f")),z(this,ot,"f").configObjects=(z(this,ot,"f").configObjects||[]).concat(n)),this}positional(e,t){Xe("<string> <object>",[e,t],arguments.length);let n=["default","defaultDescription","implies","normalize","choices","conflicts","coerce","type","describe","desc","description","alias"];t=Jf(t,(o,s)=>o==="type"&&!["string","number","boolean"].includes(s)?!1:n.includes(o));let i=z(this,G7,"f").fullCommands[z(this,G7,"f").fullCommands.length-1],a=i?z(this,Qn,"f").cmdToParseOptions(i):{array:[],alias:{},default:{},demand:{}};return z4(a).forEach(o=>{let s=a[o];Array.isArray(s)?s.indexOf(e)!==-1&&(t[o]=!0):s[e]&&!(o in t)&&(t[o]=s[e])}),this.group(e,z(this,Ft,"f").getPositionalGroupName()),this.option(e,t)}recommendCommands(e=!0){return Xe("[boolean]",[e],arguments.length),Qe(this,_I,e,"f"),this}required(e,t,n){return this.demand(e,t,n)}require(e,t,n){return this.demand(e,t,n)}requiresArg(e){return Xe("<array|string|object> [number]",[e],arguments.length),typeof e=="string"&&z(this,ot,"f").narg[e]?this:(this[W4](this.requiresArg.bind(this),"narg",e,NaN),this)}showCompletionScript(e,t){return Xe("[string] [string]",[e,t],arguments.length),e=e||this.$0,z(this,O3,"f").log(z(this,wo,"f").generateCompletionScript(e,t||z(this,Xo,"f")||"completion")),this}showHelp(e){if(Xe("[string|function]",[e],arguments.length),Qe(this,Qo,!0,"f"),!z(this,Ft,"f").hasCachedHelpMessage()){if(!this.parsed){let n=this[Z7](z(this,Xf,"f"),void 0,void 0,0,!0);if(mn(n))return n.then(()=>{z(this,Ft,"f").showHelp(e)}),this}let t=z(this,Qn,"f").runDefaultBuilderOn(this);if(mn(t))return t.then(()=>{z(this,Ft,"f").showHelp(e)}),this}return z(this,Ft,"f").showHelp(e),this}scriptName(e){return this.customScriptName=!0,this.$0=e,this}showHelpOnFail(e,t){return Xe("[boolean|string] [string]",[e,t],arguments.length),z(this,Ft,"f").showHelpOnFail(e,t),this}showVersion(e){return Xe("[string|function]",[e],arguments.length),z(this,Ft,"f").showVersion(e),this}skipValidation(e){return Xe("<array|string>",[e],arguments.length),this[Qf]("skipValidation",e),this}strict(e){return Xe("[boolean]",[e],arguments.length),Qe(this,j3,e!==!1,"f"),this}strictCommands(e){return Xe("[boolean]",[e],arguments.length),Qe(this,N3,e!==!1,"f"),this}strictOptions(e){return Xe("[boolean]",[e],arguments.length),Qe(this,M3,e!==!1,"f"),this}string(e){return Xe("<array|string>",[e],arguments.length),this[Qf]("string",e),this[q3](e),this}terminalWidth(){return Xe([],0),z(this,kt,"f").process.stdColumns}updateLocale(e){return this.updateStrings(e)}updateStrings(e){return Xe("<object>",[e],arguments.length),Qe(this,D3,!1,"f"),z(this,kt,"f").y18n.updateLocale(e),this}usage(e,t,n,i){if(Xe("<string|null|undefined> [string|boolean] [function|object] [function]",[e,t,n,i],arguments.length),t!==void 0){if(Ba(e,null,z(this,kt,"f")),(e||"").match(/^\$0( |$)/))return this.command(e,t,n,i);throw new Xn(".usage() description must start with $0 if being used as alias for .command()")}else return z(this,Ft,"f").usage(e),this}usageConfiguration(e){return Xe("<object>",[e],arguments.length),Qe(this,SI,e,"f"),this}version(e,t,n){let i="version";if(Xe("[boolean|string] [string] [string]",[e,t,n],arguments.length),z(this,Tu,"f")&&(this[bY](z(this,Tu,"f")),z(this,Ft,"f").version(void 0),Qe(this,Tu,null,"f")),arguments.length===0)n=this[s_e](),e=i;else if(arguments.length===1){if(e===!1)return this;n=e,e=i}else arguments.length===2&&(n=t,t=void 0);return Qe(this,Tu,typeof e=="string"?e:i,"f"),t=t||z(this,Ft,"f").deferY18nLookup("Show version number"),z(this,Ft,"f").version(n||void 0),this.boolean(z(this,Tu,"f")),this.describe(z(this,Tu,"f"),t),this}wrap(e){return Xe("<number|null|undefined>",[e],arguments.length),z(this,Ft,"f").wrap(e),this}[(Qn=new WeakMap,I3=new WeakMap,G7=new WeakMap,wo=new WeakMap,Xo=new WeakMap,gI=new WeakMap,Yf=new WeakMap,D3=new WeakMap,vI=new WeakMap,Ds=new WeakMap,yI=new WeakMap,Os=new WeakMap,Au=new WeakMap,Qo=new WeakMap,$s=new WeakMap,bI=new WeakMap,O3=new WeakMap,ji=new WeakMap,ot=new WeakMap,xI=new WeakMap,wI=new WeakMap,es=new WeakMap,$3=new WeakMap,H4=new WeakMap,R3=new WeakMap,Xf=new WeakMap,_I=new WeakMap,kt=new WeakMap,j3=new WeakMap,N3=new WeakMap,M3=new WeakMap,Ft=new WeakMap,SI=new WeakMap,Tu=new WeakMap,qn=new WeakMap,t_e)](e){if(!e._||!e["--"])return e;e._.push.apply(e._,e["--"]);try{delete e["--"]}catch{}return e}[r_e](){return{log:(...e)=>{this[EI]()||console.log(...e),Qe(this,Qo,!0,"f"),z(this,ji,"f").length&&Qe(this,ji,z(this,ji,"f")+`
|
|
1546
1546
|
`,"f"),Qe(this,ji,z(this,ji,"f")+e.join(" "),"f")},error:(...e)=>{this[EI]()||console.error(...e),Qe(this,Qo,!0,"f"),z(this,ji,"f").length&&Qe(this,ji,z(this,ji,"f")+`
|
|
1547
|
-
`,"f"),Qe(this,ji,z(this,ji,"f")+e.join(" "),"f")}}}[bY](e){z4(z(this,ot,"f")).forEach(t=>{if((i=>i==="configObjects")(t))return;let n=z(this,ot,"f")[t];Array.isArray(n)?n.includes(e)&&n.splice(n.indexOf(e),1):typeof n=="object"&&delete n[e]}),delete z(this,Ft,"f").getDescriptions()[e]}[n_e](e,t,n){z(this,vI,"f")[n]||(z(this,kt,"f").process.emitWarning(e,t),z(this,vI,"f")[n]=!0)}[i_e](){z(this,yI,"f").push({options:z(this,ot,"f"),configObjects:z(this,ot,"f").configObjects.slice(0),exitProcess:z(this,Ds,"f"),groups:z(this,Au,"f"),strict:z(this,j3,"f"),strictCommands:z(this,N3,"f"),strictOptions:z(this,M3,"f"),completionCommand:z(this,Xo,"f"),output:z(this,ji,"f"),exitError:z(this,Yf,"f"),hasOutput:z(this,Qo,"f"),parsed:this.parsed,parseFn:z(this,es,"f"),parseContext:z(this,$3,"f")}),z(this,Ft,"f").freeze(),z(this,qn,"f").freeze(),z(this,Qn,"f").freeze(),z(this,Os,"f").freeze()}[a_e](){let e="",t;return/\b(node|iojs|electron)(\.exe)?$/.test(z(this,kt,"f").process.argv()[0])?t=z(this,kt,"f").process.argv().slice(1,2):t=z(this,kt,"f").process.argv().slice(0,1),e=t.map(n=>{let i=this[y_e](z(this,I3,"f"),n);return n.match(/^(\/|([a-zA-Z]:)?\\)/)&&i.length<n.length?i:n}).join(" ").trim(),z(this,kt,"f").getEnv("_")&&z(this,kt,"f").getProcessArgvBin()===z(this,kt,"f").getEnv("_")&&(e=z(this,kt,"f").getEnv("_").replace(`${z(this,kt,"f").path.dirname(z(this,kt,"f").process.execPath())}/`,"")),e}[F3](){return z(this,wI,"f")}[o_e](){return z(this,SI,"f")}[xY](){if(!z(this,D3,"f"))return;let e=z(this,kt,"f").getEnv("LC_ALL")||z(this,kt,"f").getEnv("LC_MESSAGES")||z(this,kt,"f").getEnv("LANG")||z(this,kt,"f").getEnv("LANGUAGE")||"en_US";this.locale(e.replace(/[.:].*/,""))}[s_e](){return this[wY]().version||"unknown"}[c_e](e){let t=e["--"]?e["--"]:e._;for(let n=0,i;(i=t[n])!==void 0;n++)z(this,kt,"f").Parser.looksLikeNumber(i)&&Number.isSafeInteger(Math.floor(parseFloat(`${i}`)))&&(t[n]=Number(i));return e}[wY](e){let t=e||"*";if(z(this,H4,"f")[t])return z(this,H4,"f")[t];let n={};try{let i=e||z(this,kt,"f").mainFilename;z(this,kt,"f").path.extname(i)&&(i=z(this,kt,"f").path.dirname(i));let a=z(this,kt,"f").findUp(i,(o,s)=>{if(s.includes("package.json"))return"package.json"});Ba(a,void 0,z(this,kt,"f")),n=JSON.parse(z(this,kt,"f").readFileSync(a,"utf8"))}catch{}return z(this,H4,"f")[t]=n||{},z(this,H4,"f")[t]}[Qf](e,t){t=[].concat(t),t.forEach(n=>{n=this[EY](n),z(this,ot,"f")[e].push(n)})}[W4](e,t,n,i){this[SY](e,t,n,i,(a,o,s)=>{z(this,ot,"f")[a][o]=s})}[_Y](e,t,n,i){this[SY](e,t,n,i,(a,o,s)=>{z(this,ot,"f")[a][o]=(z(this,ot,"f")[a][o]||[]).concat(s)})}[SY](e,t,n,i,a){if(Array.isArray(n))n.forEach(o=>{e(o,i)});else if((o=>typeof o=="object")(n))for(let o of z4(n))e(o,n[o]);else a(t,this[EY](n),i)}[EY](e){return e==="__proto__"?"___proto___":e}[kY](e,t){return this[W4](this[kY].bind(this),"key",e,t),this}[CY](){var e,t,n,i,a,o,s,c,u,l,f,d;let p=z(this,yI,"f").pop();Ba(p,void 0,z(this,kt,"f"));let m;e=this,t=this,n=this,i=this,a=this,o=this,s=this,c=this,u=this,l=this,f=this,d=this,{options:{set value(h){Qe(e,ot,h,"f")}}.value,configObjects:m,exitProcess:{set value(h){Qe(t,Ds,h,"f")}}.value,groups:{set value(h){Qe(n,Au,h,"f")}}.value,output:{set value(h){Qe(i,ji,h,"f")}}.value,exitError:{set value(h){Qe(a,Yf,h,"f")}}.value,hasOutput:{set value(h){Qe(o,Qo,h,"f")}}.value,parsed:this.parsed,strict:{set value(h){Qe(s,j3,h,"f")}}.value,strictCommands:{set value(h){Qe(c,N3,h,"f")}}.value,strictOptions:{set value(h){Qe(u,M3,h,"f")}}.value,completionCommand:{set value(h){Qe(l,Xo,h,"f")}}.value,parseFn:{set value(h){Qe(f,es,h,"f")}}.value,parseContext:{set value(h){Qe(d,$3,h,"f")}}.value}=p,z(this,ot,"f").configObjects=m,z(this,Ft,"f").unfreeze(),z(this,qn,"f").unfreeze(),z(this,Qn,"f").unfreeze(),z(this,Os,"f").unfreeze()}[u_e](e,t){return P3(t,n=>(e(n),n))}getInternalMethods(){return{getCommandInstance:this[l_e].bind(this),getContext:this[f_e].bind(this),getHasOutput:this[d_e].bind(this),getLoggerInstance:this[p_e].bind(this),getParseContext:this[h_e].bind(this),getParserConfiguration:this[F3].bind(this),getUsageConfiguration:this[o_e].bind(this),getUsageInstance:this[m_e].bind(this),getValidationInstance:this[g_e].bind(this),hasParseCallback:this[EI].bind(this),isGlobalContext:this[v_e].bind(this),postProcess:this[L3].bind(this),reset:this[AY].bind(this),runValidation:this[TY].bind(this),runYargsParserAndExecuteCommands:this[Z7].bind(this),setHasOutput:this[b_e].bind(this)}}[l_e](){return z(this,Qn,"f")}[f_e](){return z(this,G7,"f")}[d_e](){return z(this,Qo,"f")}[p_e](){return z(this,O3,"f")}[h_e](){return z(this,$3,"f")||{}}[m_e](){return z(this,Ft,"f")}[g_e](){return z(this,qn,"f")}[EI](){return!!z(this,es,"f")}[v_e](){return z(this,bI,"f")}[L3](e,t,n,i){return n||mn(e)||(t||(e=this[t_e](e)),(this[F3]()["parse-positional-numbers"]||this[F3]()["parse-positional-numbers"]===void 0)&&(e=this[c_e](e)),i&&(e=T3(e,this,z(this,Os,"f").getMiddleware(),!1))),e}[AY](e={}){Qe(this,ot,z(this,ot,"f")||{},"f");let t={};t.local=z(this,ot,"f").local||[],t.configObjects=z(this,ot,"f").configObjects||[];let n={};t.local.forEach(o=>{n[o]=!0,(e[o]||[]).forEach(s=>{n[s]=!0})}),Object.assign(z(this,R3,"f"),Object.keys(z(this,Au,"f")).reduce((o,s)=>{let c=z(this,Au,"f")[s].filter(u=>!(u in n));return c.length>0&&(o[s]=c),o},{})),Qe(this,Au,{},"f");let i=["array","boolean","string","skipValidation","count","normalize","number","hiddenOptions"],a=["narg","key","alias","default","defaultDescription","config","choices","demandedOptions","demandedCommands","deprecatedOptions"];return i.forEach(o=>{t[o]=(z(this,ot,"f")[o]||[]).filter(s=>!n[s])}),a.forEach(o=>{t[o]=Jf(z(this,ot,"f")[o],s=>!n[s])}),t.envPrefix=z(this,ot,"f").envPrefix,Qe(this,ot,t,"f"),Qe(this,Ft,z(this,Ft,"f")?z(this,Ft,"f").reset(n):Gwe(this,z(this,kt,"f")),"f"),Qe(this,qn,z(this,qn,"f")?z(this,qn,"f").reset(n):Qwe(this,z(this,Ft,"f"),z(this,kt,"f")),"f"),Qe(this,Qn,z(this,Qn,"f")?z(this,Qn,"f").reset():Hwe(z(this,Ft,"f"),z(this,qn,"f"),z(this,Os,"f"),z(this,kt,"f")),"f"),z(this,wo,"f")||Qe(this,wo,Kwe(this,z(this,Ft,"f"),z(this,Qn,"f"),z(this,kt,"f")),"f"),z(this,Os,"f").reset(),Qe(this,Xo,null,"f"),Qe(this,ji,"","f"),Qe(this,Yf,null,"f"),Qe(this,Qo,!1,"f"),this.parsed=!1,this}[y_e](e,t){return z(this,kt,"f").path.relative(e,t)}[Z7](e,t,n,i=0,a=!1){var o,s,c,u;let l=!!n||a;e=e||z(this,Xf,"f"),z(this,ot,"f").__=z(this,kt,"f").y18n.__,z(this,ot,"f").configuration=this[F3]();let f=!!z(this,ot,"f").configuration["populate--"],d=Object.assign({},z(this,ot,"f").configuration,{"populate--":!0}),p=z(this,kt,"f").Parser.detailed(e,Object.assign({},z(this,ot,"f"),{configuration:{"parse-positional-numbers":!1,...d}})),m=Object.assign(p.argv,z(this,$3,"f")),h,g=p.aliases,v=!1,y=!1;Object.keys(m).forEach(x=>{x===z(this,$s,"f")&&m[x]?v=!0:x===z(this,Tu,"f")&&m[x]&&(y=!0)}),m.$0=this.$0,this.parsed=p,i===0&&z(this,Ft,"f").clearCachedHelpMessage();try{if(this[xY](),t)return this[L3](m,f,!!n,!1);z(this,$s,"f")&&[z(this,$s,"f")].concat(g[z(this,$s,"f")]||[]).filter($=>$.length>1).includes(""+m._[m._.length-1])&&(m._.pop(),v=!0),Qe(this,bI,!1,"f");let x=z(this,Qn,"f").getCommands(),_=!((o=z(this,wo,"f"))===null||o===void 0)&&o.completionKey?[(s=z(this,wo,"f"))===null||s===void 0?void 0:s.completionKey,...(u=this.getAliases()[(c=z(this,wo,"f"))===null||c===void 0?void 0:c.completionKey])!==null&&u!==void 0?u:[]].some(C=>Object.prototype.hasOwnProperty.call(m,C)):!1,S=v||_||a;if(m._.length){if(x.length){let C;for(let $=i||0,O;m._[$]!==void 0;$++)if(O=String(m._[$]),x.includes(O)&&O!==z(this,Xo,"f")){let w=z(this,Qn,"f").runCommand(O,this,p,$+1,a,v||y||a);return this[L3](w,f,!!n,!1)}else if(!C&&O!==z(this,Xo,"f")){C=O;break}!z(this,Qn,"f").hasDefaultCommand()&&z(this,_I,"f")&&C&&!S&&z(this,qn,"f").recommendCommands(C,x)}z(this,Xo,"f")&&m._.includes(z(this,Xo,"f"))&&!_&&(z(this,Ds,"f")&&Kf(!0),this.showCompletionScript(),this.exit(0))}if(z(this,Qn,"f").hasDefaultCommand()&&!S){let C=z(this,Qn,"f").runCommand(null,this,p,0,a,v||y||a);return this[L3](C,f,!!n,!1)}if(_){z(this,Ds,"f")&&Kf(!0),e=[].concat(e);let C=e.slice(e.indexOf(`--${z(this,wo,"f").completionKey}`)+1);return z(this,wo,"f").getCompletion(C,($,O)=>{if($)throw new Xn($.message);(O||[]).forEach(w=>{z(this,O3,"f").log(w)}),this.exit(0)}),this[L3](m,!f,!!n,!1)}if(z(this,Qo,"f")||(v?(z(this,Ds,"f")&&Kf(!0),l=!0,this.showHelp(C=>{z(this,O3,"f").log(C),this.exit(0)})):y&&(z(this,Ds,"f")&&Kf(!0),l=!0,z(this,Ft,"f").showVersion("log"),this.exit(0))),!l&&z(this,ot,"f").skipValidation.length>0&&(l=Object.keys(m).some(C=>z(this,ot,"f").skipValidation.indexOf(C)>=0&&m[C]===!0)),!l){if(p.error)throw new Xn(p.error.message);if(!_){let C=this[TY](g,{},p.error);n||(h=T3(m,this,z(this,Os,"f").getMiddleware(),!0)),h=this[u_e](C,h??m),mn(h)&&!n&&(h=h.then(()=>T3(m,this,z(this,Os,"f").getMiddleware(),!1)))}}}catch(x){if(x instanceof Xn)z(this,Ft,"f").fail(x.message,x);else throw x}return this[L3](h??m,f,!!n,!0)}[TY](e,t,n,i){let a={...this.getDemandedOptions()};return o=>{if(n)throw new Xn(n.message);z(this,qn,"f").nonOptionCount(o),z(this,qn,"f").requiredArguments(o,a);let s=!1;z(this,N3,"f")&&(s=z(this,qn,"f").unknownCommands(o)),z(this,j3,"f")&&!s?z(this,qn,"f").unknownArguments(o,e,t,!!i):z(this,M3,"f")&&z(this,qn,"f").unknownArguments(o,e,{},!1,!1),z(this,qn,"f").limitedChoices(o),z(this,qn,"f").implications(o),z(this,qn,"f").conflicting(o)}}[b_e](){Qe(this,Qo,!0,"f")}[q3](e){if(typeof e=="string")z(this,ot,"f").key[e]=!0;else for(let t of e)z(this,ot,"f").key[t]=!0}};function Wwe(r){return!!r&&typeof r.getInternalMethods=="function"}var e_t=x_e(pY),w_e=e_t;import t_t from"node:os";function __e(){let r=lY(process.argv),e=w_e(r).option("coday_project",{type:"string",description:"Project name"}).option("prompt",{type:"array",description:"Prompt(s) to execute"}).option("oneshot",{type:"boolean",description:"Run in one-shot mode (non-interactive)"}).option("auth",{type:"boolean",description:"Enables web auth check (expects x-forwarded-email header from auth proxy)"}).option("local",{type:"boolean",description:"Use current directory as sole project (restricted mode)"}).option("multi",{type:"boolean",description:"Multi-project mode: show project list without default selection"}).option("fileReadOnly",{type:"boolean",description:"Run in read-only mode for files (no write/delete operations)"}).option("configDir",{type:"string",description:"Path to the local .coday config dir"}).option("agentFolders",{type:"array",description:"Additional folders where agent definitions can be found",alias:"af"}).option("log",{type:"boolean",description:"Enable logging (use --no-log to disable)",default:!0}).option("log-folder",{type:"string",description:"Custom folder for log files (defaults to ~/.coday/logs)"}).option("debug",{type:"boolean",description:"Sets debug right at startup"}).option("base-url",{type:"string",description:"Base URL for generating absolute links (default: auto-detected from server port)"}).help().argv,t,n,i=e.prompt||e._.slice(1),a=!!e.oneshot,o=!!e.fileReadOnly,s=IY.join(t_t.homedir(),".coday"),c=e.coday_config_dir||s,u=!!e.auth,l=!!e.debug,f=!e.log,d=e.log_folder;return e.coday_project?(t=e.coday_project,n=!0,console.log(`Project mode: restricting to project '${t}'`)):e.local?(t=IY.basename(process.cwd()),n=!0,console.log(`Local mode: restricting to project '${t}'`)):e.multi?(t="",n=!1,console.log("Multi-project mode: no default project selection")):(t=IY.basename(process.cwd()),n=!1,console.log(`Default mode: using '${t}' as default project`)),{oneshot:a,debug:l,project:t,prompts:i,fileReadOnly:o,configDir:c,auth:u,agentFolders:e.agentFolders||[],noLog:f,logFolder:d,forcedProject:n,baseUrl:e.base_url}}var WEe=dr(xX(),1);import*as zEe from"node:os";var skt="cf-access-jwt-assertion",ckt="x-forwarded-email";function ukt(r){if(!r)return null;let e=r.split(".");if(e.length!==3)return null;try{let t=e[1].replace(/-/g,"+").replace(/_/g,"/"),n=Buffer.from(t,"base64").toString("utf8"),a=JSON.parse(n)?.email;return typeof a=="string"&&a.length>0?a:null}catch{return null}}function BEe(r,e){if(!e)return zEe.userInfo().username;let t=r[skt],n=ukt(t);if(n)return n;let i=r[ckt];if(i&&i.length>0)return i;throw new Error("Authentication required but no valid identity header found. Expected either a CF_Authorization JWT (Cloudflare Access) or an x-forwarded-email header from the upstream auth proxy.")}var xi=(0,QI.default)(),lkt=process.env.PORT?parseInt(process.env.PORT):process.env.BUILD_ENV==="development"?4100:3e3,HEe=!!process.env.PORT,VEe=Fxe(lkt,HEe?0:10,HEe),Xr=__e();oe("INIT","Coday options:",Xr);var GEe=!Xr.noLog,X4=new gS(GEe,Xr.logFolder);oe("INIT",`Usage logging ${GEe?"enabled":"disabled"} ${Xr.logFolder?`(custom folder: ${Xr.logFolder})`:""}`);oe("INIT","Webhook service initialized (will be initialized with prompt execution service)");var G3,eD,fkt=process.env.AGENTOS_PORT?parseInt(process.env.AGENTOS_PORT):8123,dkt=process.env.AGENTOS_HOSTNAME??"localhost",ZEe=`http://${dkt}:${fkt}`;xi.use("/api/agentos",(r,e,t)=>{console.log(`[AGENTOS PROXY] ${r.method} ${r.path}`),t()},(0,WEe.createProxyMiddleware)({target:ZEe,changeOrigin:!0,pathRewrite:{"^/api/agentos":""}}));oe("INIT",`AgentOS proxy configured: /api/agentos \u2192 ${ZEe}`);xi.use(QI.default.json({limit:"20mb"}));if(process.env.BUILD_ENV==="development"){let e=`http://localhost:${process.env.ANGULAR_CLIENT_PORT??"4200"}`;oe("INIT",`Development mode: proxying to Angular dev server at ${e}`),Promise.resolve().then(()=>dr(xX(),1)).then(({createProxyMiddleware:t})=>{let n=t({target:e,changeOrigin:!0,ws:!0});xi.use("/",(i,a,o)=>{i.path.startsWith("/api")||i.path.startsWith("/events")?o():n(i,a,o)}),oe("INIT","Proxy middleware configured successfully")}).catch(t=>{console.error("Failed to load http-proxy-middleware:",t)})}else{let r=process.env.CODAY_CLIENT_PATH?Jl.resolve(process.env.CODAY_CLIENT_PATH):Jl.resolve(__dirname,"../coday-client/browser");if(oe("INIT",`Production mode: serving static files from ${r}`),process.env.CODAY_CLIENT_PATH&&oe("INIT","Using client path from CODAY_CLIENT_PATH environment variable"),!ZI.existsSync(r))console.error(`ERROR: Client path does not exist: ${r}`),console.error("Please build the client first with: pnpm nx run client:build");else{let e=Jl.join(r,"index.html");ZI.existsSync(e)?oe("INIT",`Verified index.html exists at ${e}`):(console.error(`ERROR: index.html not found at: ${e}`),console.error("Client build may be incomplete. Try rebuilding with: pnpm nx run client:build"))}xi.use(QI.default.static(r))}var JI=new Pk(Xr.configDir),iv=Xr.project;if(iv&&!Xr.forcedProject){let r=process.cwd(),e=Jl.basename(r);if(JI.exists(e)){let t=JI.getConfig(e);if(t&&t.path===r&&!t.volatile)oe("INIT",`Default mode: found existing non-volatile project '${e}' for current directory`),iv=e;else{let n=n1.generateProjectId(r);oe("INIT",`Default mode: existing project '${e}' doesn't match path, using volatile ID ${n}`),iv=n}}else{let t=n1.generateProjectId(r);oe("INIT",`Default mode: no existing project found, using volatile ID ${t}`),iv=t}}var Q4=new n1(JI,iv,Xr.forcedProject);G3=new Ck(Xr.configDir,Q4);G3.registerNativeHandler({id:"handler-delegate",name:"delegate",description:"Delegate a task to a specific agent in an isolated sub-thread",source:"builtin",webhookEnabled:!1,createdBy:"system",createdAt:new Date("2024-01-01").toISOString(),parameterFormat:"@AgentName <task>"});oe("INIT","Prompt service initialized");eD=new Ak(G3);oe("INIT","Prompt execution service initialized (will be initialized with dependencies after thread manager)");var JEe=Jl.join(Xr.configDir,"projects"),KEe=new $k(JEe),av=new Dk(JI,JEe,KEe),pkt=new l1;oe("INIT","MCP instance pool initialized");var Y4=new XP(X4,Q4,av,G3,pkt);eD.initialize(Y4,av,Xr,X4);oe("INIT","Prompt execution service initialized");oe("INIT","Webhook service initialized with prompt execution delegation");var hkt=new Bc("config-api"),wX=new _k(Xr.configDir,hkt),mkt=["root","admin","administrator","system","daemon","nobody","node","app","service","docker","www-data","nginx","apache","ansible"];function kc(r){let e=BEe(r.headers,!!Xr.auth);if(mkt.includes(e.toLowerCase()))throw new Error(`Security error: Cannot run with username "${e}". This appears to be a system or service account. When running locally, ensure you are running as a regular user account. When running in production, ensure authentication is properly configured with --auth flag.`);return e}Wxe(xi,kc,Xr.configDir,!!Xr.auth);Lxe(xi,wX,kc);twe(xi,wX,kc);Gxe(xi,G3,kc);Jxe(xi,eD,kc);Uxe(xi,Q4,Y4.projectEventManager,av,kc,Y4,Xr);ewe(xi,Q4);zxe(xi,av,KEe,Y4,kc,Xr,wX);Bxe(xi,Y4,kc);var gkt=new xk(Xr.configDir,Q4);Vxe(xi,Q4,kc,Xr.configDir,X4,G3,av,gkt,Xr);var KI=new Tk(X4,G3,Xr.configDir);Zxe(xi,KI,kc);Xxe(xi,X4,kc,Xr.auth);if(process.env.BUILD_ENV!=="development"){let r=process.env.CODAY_CLIENT_PATH?Jl.resolve(process.env.CODAY_CLIENT_PATH):Jl.resolve(__dirname,"../coday-client/browser"),e=Jl.resolve(r,"index.html");oe("INIT",`Catch-all route will serve: ${e}`),xi.use((t,n,i)=>{if(t.path.startsWith("/api")||t.path.startsWith("/events")){n.status(404).send("Not found");return}oe("ROUTER",`Serving index.html for client route: ${t.path}`),ZI.readFile(e,"utf8",(a,o)=>{a?(oe("ERROR",`Failed to read index.html from ${e}:`,a),oe("ERROR",`File exists check: ${ZI.existsSync(e)}`),i(a)):n.type("html").send(o)})})}var YI=null;xi.use((r,e,t,n)=>{oe("ERROR",`Request error on ${e.method} ${e.path}:`,r.message),console.error(r.stack),process.env.BUILD_ENV==="development"?t.status(500).json({error:"Internal Server Error",message:r.message,stack:r.stack}):t.status(500).send("Something went wrong!")});VEe.then(async r=>{Xr.baseUrl?oe("INIT",`Using configured base URL: ${Xr.baseUrl}`):(Xr.baseUrl=`http://localhost:${r}`,oe("INIT",`Base URL set to: ${Xr.baseUrl}`)),xi.listen(r,()=>{console.log(`Server is running on http://localhost:${r}`)});try{oe("CLEANUP","Starting thread cleanup service...");let e=Jl.join(Xr.configDir,"projects");YI=new Ok(e,X4),await YI.start(),oe("CLEANUP","Thread cleanup service started successfully")}catch(e){console.error("Failed to start thread cleanup service:",e)}try{oe("SCHEDULER","Initializing scheduler service..."),await KI.initialize(),KI.initializeExecution(eD),oe("SCHEDULER","Scheduler service initialized successfully")}catch(e){console.error("Failed to initialize scheduler service:",e)}}).catch(r=>{console.error("Failed to start server:",r),process.exit(1)});VEe.catch(r=>{r instanceof Error&&r.message.includes("already in use")&&process.stderr.write(`PORT_IN_USE: ${r.message}
|
|
1547
|
+
`,"f"),Qe(this,ji,z(this,ji,"f")+e.join(" "),"f")}}}[bY](e){z4(z(this,ot,"f")).forEach(t=>{if((i=>i==="configObjects")(t))return;let n=z(this,ot,"f")[t];Array.isArray(n)?n.includes(e)&&n.splice(n.indexOf(e),1):typeof n=="object"&&delete n[e]}),delete z(this,Ft,"f").getDescriptions()[e]}[n_e](e,t,n){z(this,vI,"f")[n]||(z(this,kt,"f").process.emitWarning(e,t),z(this,vI,"f")[n]=!0)}[i_e](){z(this,yI,"f").push({options:z(this,ot,"f"),configObjects:z(this,ot,"f").configObjects.slice(0),exitProcess:z(this,Ds,"f"),groups:z(this,Au,"f"),strict:z(this,j3,"f"),strictCommands:z(this,N3,"f"),strictOptions:z(this,M3,"f"),completionCommand:z(this,Xo,"f"),output:z(this,ji,"f"),exitError:z(this,Yf,"f"),hasOutput:z(this,Qo,"f"),parsed:this.parsed,parseFn:z(this,es,"f"),parseContext:z(this,$3,"f")}),z(this,Ft,"f").freeze(),z(this,qn,"f").freeze(),z(this,Qn,"f").freeze(),z(this,Os,"f").freeze()}[a_e](){let e="",t;return/\b(node|iojs|electron)(\.exe)?$/.test(z(this,kt,"f").process.argv()[0])?t=z(this,kt,"f").process.argv().slice(1,2):t=z(this,kt,"f").process.argv().slice(0,1),e=t.map(n=>{let i=this[y_e](z(this,I3,"f"),n);return n.match(/^(\/|([a-zA-Z]:)?\\)/)&&i.length<n.length?i:n}).join(" ").trim(),z(this,kt,"f").getEnv("_")&&z(this,kt,"f").getProcessArgvBin()===z(this,kt,"f").getEnv("_")&&(e=z(this,kt,"f").getEnv("_").replace(`${z(this,kt,"f").path.dirname(z(this,kt,"f").process.execPath())}/`,"")),e}[F3](){return z(this,wI,"f")}[o_e](){return z(this,SI,"f")}[xY](){if(!z(this,D3,"f"))return;let e=z(this,kt,"f").getEnv("LC_ALL")||z(this,kt,"f").getEnv("LC_MESSAGES")||z(this,kt,"f").getEnv("LANG")||z(this,kt,"f").getEnv("LANGUAGE")||"en_US";this.locale(e.replace(/[.:].*/,""))}[s_e](){return this[wY]().version||"unknown"}[c_e](e){let t=e["--"]?e["--"]:e._;for(let n=0,i;(i=t[n])!==void 0;n++)z(this,kt,"f").Parser.looksLikeNumber(i)&&Number.isSafeInteger(Math.floor(parseFloat(`${i}`)))&&(t[n]=Number(i));return e}[wY](e){let t=e||"*";if(z(this,H4,"f")[t])return z(this,H4,"f")[t];let n={};try{let i=e||z(this,kt,"f").mainFilename;z(this,kt,"f").path.extname(i)&&(i=z(this,kt,"f").path.dirname(i));let a=z(this,kt,"f").findUp(i,(o,s)=>{if(s.includes("package.json"))return"package.json"});Ba(a,void 0,z(this,kt,"f")),n=JSON.parse(z(this,kt,"f").readFileSync(a,"utf8"))}catch{}return z(this,H4,"f")[t]=n||{},z(this,H4,"f")[t]}[Qf](e,t){t=[].concat(t),t.forEach(n=>{n=this[EY](n),z(this,ot,"f")[e].push(n)})}[W4](e,t,n,i){this[SY](e,t,n,i,(a,o,s)=>{z(this,ot,"f")[a][o]=s})}[_Y](e,t,n,i){this[SY](e,t,n,i,(a,o,s)=>{z(this,ot,"f")[a][o]=(z(this,ot,"f")[a][o]||[]).concat(s)})}[SY](e,t,n,i,a){if(Array.isArray(n))n.forEach(o=>{e(o,i)});else if((o=>typeof o=="object")(n))for(let o of z4(n))e(o,n[o]);else a(t,this[EY](n),i)}[EY](e){return e==="__proto__"?"___proto___":e}[kY](e,t){return this[W4](this[kY].bind(this),"key",e,t),this}[CY](){var e,t,n,i,a,o,s,c,u,l,f,d;let p=z(this,yI,"f").pop();Ba(p,void 0,z(this,kt,"f"));let m;e=this,t=this,n=this,i=this,a=this,o=this,s=this,c=this,u=this,l=this,f=this,d=this,{options:{set value(h){Qe(e,ot,h,"f")}}.value,configObjects:m,exitProcess:{set value(h){Qe(t,Ds,h,"f")}}.value,groups:{set value(h){Qe(n,Au,h,"f")}}.value,output:{set value(h){Qe(i,ji,h,"f")}}.value,exitError:{set value(h){Qe(a,Yf,h,"f")}}.value,hasOutput:{set value(h){Qe(o,Qo,h,"f")}}.value,parsed:this.parsed,strict:{set value(h){Qe(s,j3,h,"f")}}.value,strictCommands:{set value(h){Qe(c,N3,h,"f")}}.value,strictOptions:{set value(h){Qe(u,M3,h,"f")}}.value,completionCommand:{set value(h){Qe(l,Xo,h,"f")}}.value,parseFn:{set value(h){Qe(f,es,h,"f")}}.value,parseContext:{set value(h){Qe(d,$3,h,"f")}}.value}=p,z(this,ot,"f").configObjects=m,z(this,Ft,"f").unfreeze(),z(this,qn,"f").unfreeze(),z(this,Qn,"f").unfreeze(),z(this,Os,"f").unfreeze()}[u_e](e,t){return P3(t,n=>(e(n),n))}getInternalMethods(){return{getCommandInstance:this[l_e].bind(this),getContext:this[f_e].bind(this),getHasOutput:this[d_e].bind(this),getLoggerInstance:this[p_e].bind(this),getParseContext:this[h_e].bind(this),getParserConfiguration:this[F3].bind(this),getUsageConfiguration:this[o_e].bind(this),getUsageInstance:this[m_e].bind(this),getValidationInstance:this[g_e].bind(this),hasParseCallback:this[EI].bind(this),isGlobalContext:this[v_e].bind(this),postProcess:this[L3].bind(this),reset:this[AY].bind(this),runValidation:this[TY].bind(this),runYargsParserAndExecuteCommands:this[Z7].bind(this),setHasOutput:this[b_e].bind(this)}}[l_e](){return z(this,Qn,"f")}[f_e](){return z(this,G7,"f")}[d_e](){return z(this,Qo,"f")}[p_e](){return z(this,O3,"f")}[h_e](){return z(this,$3,"f")||{}}[m_e](){return z(this,Ft,"f")}[g_e](){return z(this,qn,"f")}[EI](){return!!z(this,es,"f")}[v_e](){return z(this,bI,"f")}[L3](e,t,n,i){return n||mn(e)||(t||(e=this[t_e](e)),(this[F3]()["parse-positional-numbers"]||this[F3]()["parse-positional-numbers"]===void 0)&&(e=this[c_e](e)),i&&(e=T3(e,this,z(this,Os,"f").getMiddleware(),!1))),e}[AY](e={}){Qe(this,ot,z(this,ot,"f")||{},"f");let t={};t.local=z(this,ot,"f").local||[],t.configObjects=z(this,ot,"f").configObjects||[];let n={};t.local.forEach(o=>{n[o]=!0,(e[o]||[]).forEach(s=>{n[s]=!0})}),Object.assign(z(this,R3,"f"),Object.keys(z(this,Au,"f")).reduce((o,s)=>{let c=z(this,Au,"f")[s].filter(u=>!(u in n));return c.length>0&&(o[s]=c),o},{})),Qe(this,Au,{},"f");let i=["array","boolean","string","skipValidation","count","normalize","number","hiddenOptions"],a=["narg","key","alias","default","defaultDescription","config","choices","demandedOptions","demandedCommands","deprecatedOptions"];return i.forEach(o=>{t[o]=(z(this,ot,"f")[o]||[]).filter(s=>!n[s])}),a.forEach(o=>{t[o]=Jf(z(this,ot,"f")[o],s=>!n[s])}),t.envPrefix=z(this,ot,"f").envPrefix,Qe(this,ot,t,"f"),Qe(this,Ft,z(this,Ft,"f")?z(this,Ft,"f").reset(n):Gwe(this,z(this,kt,"f")),"f"),Qe(this,qn,z(this,qn,"f")?z(this,qn,"f").reset(n):Qwe(this,z(this,Ft,"f"),z(this,kt,"f")),"f"),Qe(this,Qn,z(this,Qn,"f")?z(this,Qn,"f").reset():Hwe(z(this,Ft,"f"),z(this,qn,"f"),z(this,Os,"f"),z(this,kt,"f")),"f"),z(this,wo,"f")||Qe(this,wo,Kwe(this,z(this,Ft,"f"),z(this,Qn,"f"),z(this,kt,"f")),"f"),z(this,Os,"f").reset(),Qe(this,Xo,null,"f"),Qe(this,ji,"","f"),Qe(this,Yf,null,"f"),Qe(this,Qo,!1,"f"),this.parsed=!1,this}[y_e](e,t){return z(this,kt,"f").path.relative(e,t)}[Z7](e,t,n,i=0,a=!1){var o,s,c,u;let l=!!n||a;e=e||z(this,Xf,"f"),z(this,ot,"f").__=z(this,kt,"f").y18n.__,z(this,ot,"f").configuration=this[F3]();let f=!!z(this,ot,"f").configuration["populate--"],d=Object.assign({},z(this,ot,"f").configuration,{"populate--":!0}),p=z(this,kt,"f").Parser.detailed(e,Object.assign({},z(this,ot,"f"),{configuration:{"parse-positional-numbers":!1,...d}})),m=Object.assign(p.argv,z(this,$3,"f")),h,g=p.aliases,v=!1,y=!1;Object.keys(m).forEach(x=>{x===z(this,$s,"f")&&m[x]?v=!0:x===z(this,Tu,"f")&&m[x]&&(y=!0)}),m.$0=this.$0,this.parsed=p,i===0&&z(this,Ft,"f").clearCachedHelpMessage();try{if(this[xY](),t)return this[L3](m,f,!!n,!1);z(this,$s,"f")&&[z(this,$s,"f")].concat(g[z(this,$s,"f")]||[]).filter($=>$.length>1).includes(""+m._[m._.length-1])&&(m._.pop(),v=!0),Qe(this,bI,!1,"f");let x=z(this,Qn,"f").getCommands(),_=!((o=z(this,wo,"f"))===null||o===void 0)&&o.completionKey?[(s=z(this,wo,"f"))===null||s===void 0?void 0:s.completionKey,...(u=this.getAliases()[(c=z(this,wo,"f"))===null||c===void 0?void 0:c.completionKey])!==null&&u!==void 0?u:[]].some(C=>Object.prototype.hasOwnProperty.call(m,C)):!1,S=v||_||a;if(m._.length){if(x.length){let C;for(let $=i||0,O;m._[$]!==void 0;$++)if(O=String(m._[$]),x.includes(O)&&O!==z(this,Xo,"f")){let w=z(this,Qn,"f").runCommand(O,this,p,$+1,a,v||y||a);return this[L3](w,f,!!n,!1)}else if(!C&&O!==z(this,Xo,"f")){C=O;break}!z(this,Qn,"f").hasDefaultCommand()&&z(this,_I,"f")&&C&&!S&&z(this,qn,"f").recommendCommands(C,x)}z(this,Xo,"f")&&m._.includes(z(this,Xo,"f"))&&!_&&(z(this,Ds,"f")&&Kf(!0),this.showCompletionScript(),this.exit(0))}if(z(this,Qn,"f").hasDefaultCommand()&&!S){let C=z(this,Qn,"f").runCommand(null,this,p,0,a,v||y||a);return this[L3](C,f,!!n,!1)}if(_){z(this,Ds,"f")&&Kf(!0),e=[].concat(e);let C=e.slice(e.indexOf(`--${z(this,wo,"f").completionKey}`)+1);return z(this,wo,"f").getCompletion(C,($,O)=>{if($)throw new Xn($.message);(O||[]).forEach(w=>{z(this,O3,"f").log(w)}),this.exit(0)}),this[L3](m,!f,!!n,!1)}if(z(this,Qo,"f")||(v?(z(this,Ds,"f")&&Kf(!0),l=!0,this.showHelp(C=>{z(this,O3,"f").log(C),this.exit(0)})):y&&(z(this,Ds,"f")&&Kf(!0),l=!0,z(this,Ft,"f").showVersion("log"),this.exit(0))),!l&&z(this,ot,"f").skipValidation.length>0&&(l=Object.keys(m).some(C=>z(this,ot,"f").skipValidation.indexOf(C)>=0&&m[C]===!0)),!l){if(p.error)throw new Xn(p.error.message);if(!_){let C=this[TY](g,{},p.error);n||(h=T3(m,this,z(this,Os,"f").getMiddleware(),!0)),h=this[u_e](C,h??m),mn(h)&&!n&&(h=h.then(()=>T3(m,this,z(this,Os,"f").getMiddleware(),!1)))}}}catch(x){if(x instanceof Xn)z(this,Ft,"f").fail(x.message,x);else throw x}return this[L3](h??m,f,!!n,!0)}[TY](e,t,n,i){let a={...this.getDemandedOptions()};return o=>{if(n)throw new Xn(n.message);z(this,qn,"f").nonOptionCount(o),z(this,qn,"f").requiredArguments(o,a);let s=!1;z(this,N3,"f")&&(s=z(this,qn,"f").unknownCommands(o)),z(this,j3,"f")&&!s?z(this,qn,"f").unknownArguments(o,e,t,!!i):z(this,M3,"f")&&z(this,qn,"f").unknownArguments(o,e,{},!1,!1),z(this,qn,"f").limitedChoices(o),z(this,qn,"f").implications(o),z(this,qn,"f").conflicting(o)}}[b_e](){Qe(this,Qo,!0,"f")}[q3](e){if(typeof e=="string")z(this,ot,"f").key[e]=!0;else for(let t of e)z(this,ot,"f").key[t]=!0}};function Wwe(r){return!!r&&typeof r.getInternalMethods=="function"}var e_t=x_e(pY),w_e=e_t;import t_t from"node:os";function __e(){let r=lY(process.argv),e=w_e(r).option("coday_project",{type:"string",description:"Project name"}).option("prompt",{type:"array",description:"Prompt(s) to execute"}).option("oneshot",{type:"boolean",description:"Run in one-shot mode (non-interactive)"}).option("auth",{type:"boolean",description:"Enables web auth check (expects x-forwarded-email header from auth proxy)"}).option("local",{type:"boolean",description:"Use current directory as sole project (restricted mode)"}).option("multi",{type:"boolean",description:"Multi-project mode: show project list without default selection"}).option("fileReadOnly",{type:"boolean",description:"Run in read-only mode for files (no write/delete operations)"}).option("configDir",{type:"string",description:"Path to the local .coday config dir"}).option("agentFolders",{type:"array",description:"Additional folders where agent definitions can be found",alias:"af"}).option("log",{type:"boolean",description:"Enable logging (use --no-log to disable)",default:!0}).option("log-folder",{type:"string",description:"Custom folder for log files (defaults to ~/.coday/logs)"}).option("debug",{type:"boolean",description:"Sets debug right at startup"}).option("base-url",{type:"string",description:"Base URL for generating absolute links (default: auto-detected from server port)"}).help().argv,t,n,i=e.prompt||e._.slice(1),a=!!e.oneshot,o=!!e.fileReadOnly,s=IY.join(t_t.homedir(),".coday"),c=e.coday_config_dir||s,u=!!e.auth,l=!!e.debug,f=!e.log,d=e.log_folder;return e.coday_project?(t=e.coday_project,n=!0,console.log(`Project mode: restricting to project '${t}'`)):e.local?(t=IY.basename(process.cwd()),n=!0,console.log(`Local mode: restricting to project '${t}'`)):e.multi?(t="",n=!1,console.log("Multi-project mode: no default project selection")):(t=IY.basename(process.cwd()),n=!1,console.log(`Default mode: using '${t}' as default project`)),{oneshot:a,debug:l,project:t,prompts:i,fileReadOnly:o,configDir:c,auth:u,agentFolders:e.agentFolders||[],noLog:f,logFolder:d,forcedProject:n,baseUrl:e.base_url}}var WEe=dr(xX(),1);import*as zEe from"node:os";var skt="cf-access-jwt-assertion",ckt="x-forwarded-email";function ukt(r){if(!r)return null;let e=r.split(".");if(e.length!==3)return null;try{let t=e[1].replace(/-/g,"+").replace(/_/g,"/"),n=Buffer.from(t,"base64").toString("utf8"),a=JSON.parse(n)?.email;return typeof a=="string"&&a.length>0?a:null}catch{return null}}function BEe(r,e){if(!e)return zEe.userInfo().username;let t=r[skt],n=ukt(t);if(n)return n;let i=r[ckt];if(i&&i.length>0)return i;throw new Error("Authentication required but no valid identity header found. Expected either a CF_Authorization JWT (Cloudflare Access) or an x-forwarded-email header from the upstream auth proxy.")}var xi=(0,QI.default)(),lkt=process.env.PORT?parseInt(process.env.PORT):process.env.BUILD_ENV==="development"?4100:3e3,HEe=!!process.env.PORT,VEe=Fxe(lkt,HEe?0:10,HEe),Xr=__e();oe("INIT","Coday options:",Xr);var GEe=!Xr.noLog,X4=new gS(GEe,Xr.logFolder);oe("INIT",`Usage logging ${GEe?"enabled":"disabled"} ${Xr.logFolder?`(custom folder: ${Xr.logFolder})`:""}`);oe("INIT","Webhook service initialized (will be initialized with prompt execution service)");var G3,eD,fkt=process.env.AGENTOS_PORT?parseInt(process.env.AGENTOS_PORT):8124,dkt=process.env.AGENTOS_HOSTNAME??"localhost",ZEe=`http://${dkt}:${fkt}`;xi.use("/api/agentos",(r,e,t)=>{console.log(`[AGENTOS PROXY] ${r.method} ${r.path}`),t()},(0,WEe.createProxyMiddleware)({target:ZEe,changeOrigin:!0,pathRewrite:{"^/api/agentos":""}}));oe("INIT",`AgentOS proxy configured: /api/agentos \u2192 ${ZEe}`);xi.use(QI.default.json({limit:"20mb"}));if(process.env.BUILD_ENV==="development"){let e=`http://localhost:${process.env.ANGULAR_CLIENT_PORT??"4200"}`;oe("INIT",`Development mode: proxying to Angular dev server at ${e}`),Promise.resolve().then(()=>dr(xX(),1)).then(({createProxyMiddleware:t})=>{let n=t({target:e,changeOrigin:!0,ws:!0});xi.use("/",(i,a,o)=>{i.path.startsWith("/api")||i.path.startsWith("/events")?o():n(i,a,o)}),oe("INIT","Proxy middleware configured successfully")}).catch(t=>{console.error("Failed to load http-proxy-middleware:",t)})}else{let r=process.env.CODAY_CLIENT_PATH?Jl.resolve(process.env.CODAY_CLIENT_PATH):Jl.resolve(__dirname,"../coday-client/browser");if(oe("INIT",`Production mode: serving static files from ${r}`),process.env.CODAY_CLIENT_PATH&&oe("INIT","Using client path from CODAY_CLIENT_PATH environment variable"),!ZI.existsSync(r))console.error(`ERROR: Client path does not exist: ${r}`),console.error("Please build the client first with: pnpm nx run client:build");else{let e=Jl.join(r,"index.html");ZI.existsSync(e)?oe("INIT",`Verified index.html exists at ${e}`):(console.error(`ERROR: index.html not found at: ${e}`),console.error("Client build may be incomplete. Try rebuilding with: pnpm nx run client:build"))}xi.use(QI.default.static(r))}var JI=new Pk(Xr.configDir),iv=Xr.project;if(iv&&!Xr.forcedProject){let r=process.cwd(),e=Jl.basename(r);if(JI.exists(e)){let t=JI.getConfig(e);if(t&&t.path===r&&!t.volatile)oe("INIT",`Default mode: found existing non-volatile project '${e}' for current directory`),iv=e;else{let n=n1.generateProjectId(r);oe("INIT",`Default mode: existing project '${e}' doesn't match path, using volatile ID ${n}`),iv=n}}else{let t=n1.generateProjectId(r);oe("INIT",`Default mode: no existing project found, using volatile ID ${t}`),iv=t}}var Q4=new n1(JI,iv,Xr.forcedProject);G3=new Ck(Xr.configDir,Q4);G3.registerNativeHandler({id:"handler-delegate",name:"delegate",description:"Delegate a task to a specific agent in an isolated sub-thread",source:"builtin",webhookEnabled:!1,createdBy:"system",createdAt:new Date("2024-01-01").toISOString(),parameterFormat:"@AgentName <task>"});oe("INIT","Prompt service initialized");eD=new Ak(G3);oe("INIT","Prompt execution service initialized (will be initialized with dependencies after thread manager)");var JEe=Jl.join(Xr.configDir,"projects"),KEe=new $k(JEe),av=new Dk(JI,JEe,KEe),pkt=new l1;oe("INIT","MCP instance pool initialized");var Y4=new XP(X4,Q4,av,G3,pkt);eD.initialize(Y4,av,Xr,X4);oe("INIT","Prompt execution service initialized");oe("INIT","Webhook service initialized with prompt execution delegation");var hkt=new Bc("config-api"),wX=new _k(Xr.configDir,hkt),mkt=["root","admin","administrator","system","daemon","nobody","node","app","service","docker","www-data","nginx","apache","ansible"];function kc(r){let e=BEe(r.headers,!!Xr.auth);if(mkt.includes(e.toLowerCase()))throw new Error(`Security error: Cannot run with username "${e}". This appears to be a system or service account. When running locally, ensure you are running as a regular user account. When running in production, ensure authentication is properly configured with --auth flag.`);return e}Wxe(xi,kc,Xr.configDir,!!Xr.auth);Lxe(xi,wX,kc);twe(xi,wX,kc);Gxe(xi,G3,kc);Jxe(xi,eD,kc);Uxe(xi,Q4,Y4.projectEventManager,av,kc,Y4,Xr);ewe(xi,Q4);zxe(xi,av,KEe,Y4,kc,Xr,wX);Bxe(xi,Y4,kc);var gkt=new xk(Xr.configDir,Q4);Vxe(xi,Q4,kc,Xr.configDir,X4,G3,av,gkt,Xr);var KI=new Tk(X4,G3,Xr.configDir);Zxe(xi,KI,kc);Xxe(xi,X4,kc,Xr.auth);if(process.env.BUILD_ENV!=="development"){let r=process.env.CODAY_CLIENT_PATH?Jl.resolve(process.env.CODAY_CLIENT_PATH):Jl.resolve(__dirname,"../coday-client/browser"),e=Jl.resolve(r,"index.html");oe("INIT",`Catch-all route will serve: ${e}`),xi.use((t,n,i)=>{if(t.path.startsWith("/api")||t.path.startsWith("/events")){n.status(404).send("Not found");return}oe("ROUTER",`Serving index.html for client route: ${t.path}`),ZI.readFile(e,"utf8",(a,o)=>{a?(oe("ERROR",`Failed to read index.html from ${e}:`,a),oe("ERROR",`File exists check: ${ZI.existsSync(e)}`),i(a)):n.type("html").send(o)})})}var YI=null;xi.use((r,e,t,n)=>{oe("ERROR",`Request error on ${e.method} ${e.path}:`,r.message),console.error(r.stack),process.env.BUILD_ENV==="development"?t.status(500).json({error:"Internal Server Error",message:r.message,stack:r.stack}):t.status(500).send("Something went wrong!")});VEe.then(async r=>{Xr.baseUrl?oe("INIT",`Using configured base URL: ${Xr.baseUrl}`):(Xr.baseUrl=`http://localhost:${r}`,oe("INIT",`Base URL set to: ${Xr.baseUrl}`)),xi.listen(r,()=>{console.log(`Server is running on http://localhost:${r}`)});try{oe("CLEANUP","Starting thread cleanup service...");let e=Jl.join(Xr.configDir,"projects");YI=new Ok(e,X4),await YI.start(),oe("CLEANUP","Thread cleanup service started successfully")}catch(e){console.error("Failed to start thread cleanup service:",e)}try{oe("SCHEDULER","Initializing scheduler service..."),await KI.initialize(),KI.initializeExecution(eD),oe("SCHEDULER","Scheduler service initialized successfully")}catch(e){console.error("Failed to initialize scheduler service:",e)}}).catch(r=>{console.error("Failed to start server:",r),process.exit(1)});VEe.catch(r=>{r instanceof Error&&r.message.includes("already in use")&&process.stderr.write(`PORT_IN_USE: ${r.message}
|
|
1548
1548
|
`)});var XI=!1;async function e5(r){XI&&(console.log(`Received ${r} during shutdown, forcing exit...`),process.exit(1)),XI=!0,console.log(`Received ${r}, shutting down gracefully...`);try{console.log("Stopping scheduler service..."),KI.stop(),YI&&(console.log("Stopping thread cleanup service..."),await YI.stop()),console.log("Cleaning up thread Coday instances..."),await Y4.shutdown(),console.log("Graceful shutdown completed"),process.exit(0)}catch(e){console.error("Error during graceful shutdown:",e),process.exit(1)}}process.on("SIGTERM",()=>e5("SIGTERM"));process.on("SIGINT",()=>e5("SIGINT"));process.on("SIGUSR2",()=>e5("SIGUSR2"));process.on("SIGHUP",()=>e5("SIGHUP"));process.on("uncaughtException",r=>{if(console.error("Uncaught exception:",r),r.message==="no elements in sequence"||r.constructor.name==="EmptyErrorImpl"){console.log("Detected RxJS EmptyError during system sleep - this is expected behavior"),console.log("Process will continue normally after system wake");return}XI||e5("uncaughtException")});process.on("unhandledRejection",(r,e)=>{if(console.error("Unhandled rejection at:",e,"reason:",r),r&&typeof r=="object"){let t=r;if(t.message==="no elements in sequence"||t.constructor?.name==="EmptyErrorImpl"){console.log("Detected RxJS EmptyError rejection during system sleep - this is expected behavior");return}if(t.name==="TimeoutError"||t.message?.includes("timeout")){console.log("Detected timeout error - handling gracefully without shutdown");return}if(t.name==="AbortError"||t.message?.includes("aborted")){console.log("Detected abort error - handling gracefully without shutdown");return}}console.error("Critical unhandled rejection detected"),XI||e5("unhandledRejection")});
|
|
1549
1549
|
/*! Bundled license information:
|
|
1550
1550
|
|