@wular/coder 0.2.10 → 0.2.11
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/dist/lib/broker.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var D$=Object.defineProperty;var P1=($,W)=>{for(var Z in W)D$($,Z,{get:W[Z],enumerable:!0,configurable:!0,set:(q)=>W[Z]=()=>q})};import k from"node:fs";import U1 from"node:net";import W$ from"node:path";import T from"node:process";function K$($,W={}){let Z=new Set(W.valueOptions??[]),q=new Set(W.booleanOptions??[]),K=W.aliasMap??{},X={},Y=[],G=!1;for(let H=0;H<$.length;H+=1){let M=$[H];if(G){Y.push(M);continue}if(M==="--"){G=!0;continue}if(!M.startsWith("-")||M==="-"){Y.push(M);continue}if(M.startsWith("--")){let[y,_]=M.slice(2).split("=",2),A=K[y]??y;if(q.has(A)){X[A]=_===void 0?!0:_!=="false";continue}if(Z.has(A)){let D=_??$[H+1];if(D===void 0)throw Error(`Missing value for --${y}`);if(X[A]=D,_===void 0)H+=1;continue}throw Error(`Unknown option --${y} (use -- to pass literal text starting with -)`)}let R=M.slice(1),x=K[R]??R;if(q.has(x)){X[x]=!0;continue}if(Z.has(x)){let y=$[H+1];if(y===void 0)throw Error(`Missing value for -${R}`);X[x]=y,H+=1;continue}throw Error(`Unknown option -${R} (use -- to pass literal text starting with -)`)}return{options:X,positionals:Y}}import G1 from"node:net";import F from"node:process";import{spawn as M1}from"node:child_process";import N1 from"node:readline";import Y$ from"node:path";import h$ from"node:process";function v$($){return String($??"").replace(/[^A-Za-z0-9._-]/g,"-").replace(/^-+|-+$/g,"")}function X$($,W=h$.platform){if(W==="win32")return`pipe:\\\\.\\pipe\\${v$(`${Y$.win32.basename($)}-codex-app-server`)}`;return`unix:${Y$.join($,"broker.sock")}`}function J($){if(typeof $!=="string"||$.length===0)throw Error("Missing broker endpoint.");if($.startsWith("pipe:")){let W=$.slice(5);if(!W)throw Error("Broker pipe endpoint is missing its path.");return{kind:"pipe",path:W}}if($.startsWith("unix:")){let W=$.slice(5);if(!W)throw Error("Broker Unix socket endpoint is missing its path.");return{kind:"unix",path:W}}throw Error(`Unsupported broker endpoint: ${$}`)}import U from"node:fs";import d$ from"node:net";import r$ from"node:os";import u from"node:path";import i from"node:process";import{spawn as s$}from"node:child_process";import{fileURLToPath as o$}from"node:url";import{execFileSync as N$}from"node:child_process";import V from"node:fs";import m$ from"node:os";import N from"node:path";import{spawn as Q$,spawnSync as w$}from"node:child_process";import g$ from"node:fs";import j$ from"node:os";import z$ from"node:path";function H$($){try{let W=Q$("codex",["archive",$],{detached:!0,stdio:"ignore"});W.on("error",()=>{}),W.unref()}catch{}}function S1($){let W=z$.join(process.env.CODEX_HOME||z$.join(j$.homedir(),".codex"),"archived_sessions");try{return g$.readdirSync(W).some((Z)=>Z.endsWith(`-${$}.jsonl`))}catch{return!1}}function I1($){return new Promise((W)=>{try{let Z=Q$("codex",["unarchive",$],{stdio:"ignore"});Z.on("error",()=>W(!1)),Z.on("close",(q)=>W(q===0))}catch{W(!1)}})}function F1($){return w$("codex",["delete","--force",$],{encoding:"utf8"}).status===0}var G$=["completed","failed","cancelled"],h1=["queued","running"];var b$="CODER_HOME";function V$(){return N.resolve(process.env[b$]||N.join(m$.homedir(),".coder"))}var M$=new Map;function n1($){let W=M$.get($);if(W!==void 0)return W;let Z;try{Z=N$("git",["rev-parse","--show-toplevel"],{cwd:$,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim()}catch{Z=$}return M$.set($,Z),Z}var O$="global";function S($){return N.join(V$(),"state",O$)}var w=null;function n(){if(w)return w;let $=N.join(V$(),"state"),W=[];try{W=V.readdirSync($,{withFileTypes:!0})}catch{}return w=W.filter((Z)=>Z.isDirectory()&&Z.name!==O$).map((Z)=>N.join($,Z.name)),w}function c($){return N.join(S($),"jobs")}function g($){return N.join(S($),"archive")}function P($,W){let Z=N.join(c($),W);if(V.existsSync(N.join(Z,"job.json")))return Z;let q=N.join(g($),W);if(V.existsSync(N.join(q,"job.json")))return q;for(let K of n()){let X=N.join(K,"jobs",W);if(V.existsSync(N.join(X,"job.json")))return X}return Z}function p$($,W){return W.archived?W:R$($,W.id,{archived:!0,archivedAt:new Date().toISOString()})}function U$($,W){let Z=p$($,W);if(W.engine==="codex"&&W.threadId)H$(W.threadId);let q=P($,W.id),K=N.join(g($),W.id);if(q!==K)try{V.mkdirSync(g($),{recursive:!0}),V.renameSync(q,K)}catch{}return Z}function c1(){let $=Math.random().toString(36).slice(2,8);return`coder-${Date.now().toString(36)}-${$}`}function R$($,W,Z){let q=P($,W);V.mkdirSync(q,{recursive:!0});let K=N.join(q,"job.json"),Y={...x$($,W)??{id:W,createdAt:new Date().toISOString(),status:"queued"},...Z,updatedAt:new Date().toISOString()};return V.writeFileSync(K,`${JSON.stringify(Y,null,2)}
|
|
3
|
-
`,"utf8"),
|
|
4
|
-
`,"utf8")}function
|
|
5
|
-
`,"utf8")}function
|
|
6
|
-
`,"utf8")}function
|
|
7
|
-
${
|
|
8
|
-
`);while(W!==-1){let
|
|
9
|
-
`)}}handleLine(
|
|
10
|
-
${
|
|
11
|
-
`,
|
|
12
|
-
`,
|
|
13
|
-
`)}var
|
|
14
|
-
`,"utf8")}async function
|
|
15
|
-
`);while(
|
|
16
|
-
`),!
|
|
17
|
-
`),
|
|
2
|
+
var IY=Object.defineProperty;var b2=(Y,W)=>{for(var Q in W)IY(Y,Q,{get:W[Q],enumerable:!0,configurable:!0,set:(X)=>W[Q]=()=>X})};import r from"node:fs";import T2 from"node:net";import m0 from"node:path";import S from"node:process";var f0;function L(Y,W,Q){function X(K,z){if(!K._zod)Object.defineProperty(K,"_zod",{value:{def:z,constr:G,traits:new Set},enumerable:!1});if(K._zod.traits.has(Y))return;K._zod.traits.add(Y),W(K,z);let J=G.prototype,N=Object.keys(J);for(let U=0;U<N.length;U++){let B=N[U];if(!(B in K))K[B]=J[B].bind(K)}}let q=Q?.Parent??Object;class H extends q{}Object.defineProperty(H,"name",{value:Y});function G(K){var z;let J=Q?.Parent?new H:this;X(J,K),(z=J._zod).deferred??(z.deferred=[]);for(let N of J._zod.deferred)N();return J}return Object.defineProperty(G,"init",{value:X}),Object.defineProperty(G,Symbol.hasInstance,{value:(K)=>{if(Q?.Parent&&K instanceof Q.Parent)return!0;return K?._zod?.traits?.has(Y)}}),Object.defineProperty(G,"name",{value:Y}),G}var g2=Symbol("zod_brand");class v extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}(f0=globalThis).__zod_globalConfig??(f0.__zod_globalConfig={});var A0=globalThis.__zod_globalConfig;function _(Y){if(Y)Object.assign(A0,Y);return A0}function p0(Y){let W=Object.values(Y).filter((X)=>typeof X==="number");return Object.entries(Y).filter(([X,q])=>W.indexOf(+X)===-1).map(([X,q])=>q)}function l0(Y,W){if(typeof W==="bigint")return W.toString();return W}function o0(Y){return{get value(){{let Q=Y();return Object.defineProperty(this,"value",{value:Q}),Q}throw Error("cached value already set")}}}function n0(Y){return Y===null||Y===void 0}function V0(Y){let W=Y.startsWith("^")?1:0,Q=Y.endsWith("$")?Y.length-1:Y.length;return Y.slice(W,Q)}var r0=Symbol("evaluating");function M(Y,W,Q){let X=void 0;Object.defineProperty(Y,W,{get(){if(X===r0)return;if(X===void 0)X=r0,X=Q();return X},set(q){Object.defineProperty(Y,W,{value:q})},configurable:!0})}function d0(Y,W,Q){Object.defineProperty(Y,W,{value:Q,writable:!0,enumerable:!0,configurable:!0})}function i0(...Y){let W={};for(let Q of Y){let X=Object.getOwnPropertyDescriptors(Q);Object.assign(W,X)}return Object.defineProperties({},W)}var P0="captureStackTrace"in Error?Error.captureStackTrace:(...Y)=>{};function X0(Y){return typeof Y==="object"&&Y!==null&&!Array.isArray(Y)}function $0(Y){if(X0(Y)===!1)return!1;let W=Y.constructor;if(W===void 0)return!0;if(typeof W!=="function")return!0;let Q=W.prototype;if(X0(Q)===!1)return!1;if(Object.prototype.hasOwnProperty.call(Q,"isPrototypeOf")===!1)return!1;return!0}var t0=new Set(["string","number","symbol"]);function l(Y){return Y.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function o(Y,W,Q){let X=new Y._zod.constr(W??Y._zod.def);if(!W||Q?.parent)X._zod.parent=Y;return X}function O(Y){let W=Y;if(!W)return{};if(typeof W==="string")return{error:()=>W};if(W?.message!==void 0){if(W?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");W.error=W.message}if(delete W.message,typeof W.error==="string")return{...W,error:()=>W.error};return W}function s0(Y){return Object.keys(Y).filter((W)=>{return Y[W]._zod.optin==="optional"&&Y[W]._zod.optout==="optional"})}var a0={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function e0(Y,W){if(!$0(W))throw Error("Invalid input to extend: expected a plain object");let Q=Y._zod.def.checks;if(Q&&Q.length>0){let H=Y._zod.def.shape;for(let G in W)if(Object.getOwnPropertyDescriptor(H,G)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}let q=i0(Y._zod.def,{get shape(){let H={...Y._zod.def.shape,...W};return d0(this,"shape",H),H}});return o(Y,q)}function Y3(Y,W,Q){let q=W._zod.def.checks;if(q&&q.length>0)throw Error(".partial() cannot be used on object schemas containing refinements");let G=i0(W._zod.def,{get shape(){let K=W._zod.def.shape,z={...K};if(Q)for(let J in Q){if(!(J in K))throw Error(`Unrecognized key: "${J}"`);if(!Q[J])continue;z[J]=Y?new Y({type:"optional",innerType:K[J]}):K[J]}else for(let J in K)z[J]=Y?new Y({type:"optional",innerType:K[J]}):K[J];return d0(this,"shape",z),z},checks:[]});return o(W,G)}function m(Y,W=0){if(Y.aborted===!0)return!0;for(let Q=W;Q<Y.issues.length;Q++)if(Y.issues[Q]?.continue!==!0)return!0;return!1}function W3(Y,W=0){if(Y.aborted===!0)return!0;for(let Q=W;Q<Y.issues.length;Q++)if(Y.issues[Q]?.continue===!1)return!0;return!1}function x(Y,W){return W.map((Q)=>{var X;return(X=Q).path??(X.path=[]),Q.path.unshift(Y),Q})}function Q0(Y){return typeof Y==="string"?Y:Y?.message}function C(Y,W,Q){let X=Y.message?Y.message:Q0(Y.inst?._zod.def?.error?.(Y))??Q0(W?.error?.(Y))??Q0(Q.customError?.(Y))??Q0(Q.localeError?.(Y))??"Invalid input",{inst:q,continue:H,input:G,...K}=Y;if(K.path??(K.path=[]),K.message=X,W?.reportInput)K.input=G;return K}function Q3(Y){if(Array.isArray(Y))return"array";if(typeof Y==="string")return"string";return"unknown"}var X3=(Y,W)=>{Y.name="$ZodError",Object.defineProperty(Y,"_zod",{value:Y._zod,enumerable:!1}),Object.defineProperty(Y,"issues",{value:W,enumerable:!1}),Y.message=JSON.stringify(W,l0,2),Object.defineProperty(Y,"toString",{value:()=>Y.message,enumerable:!1})},q3=L("$ZodError",X3),n=L("$ZodError",X3,{Parent:Error});var wY=(Y)=>(W,Q,X,q)=>{let H=X?{...X,async:!1}:{async:!1},G=W._zod.run({value:Q,issues:[]},H);if(G instanceof Promise)throw new v;if(G.issues.length){let K=new(q?.Err??Y)(G.issues.map((z)=>C(z,H,_())));throw P0(K,q?.callee),K}return G.value},q0=wY(n),FY=(Y)=>async(W,Q,X,q)=>{let H=X?{...X,async:!0}:{async:!0},G=W._zod.run({value:Q,issues:[]},H);if(G instanceof Promise)G=await G;if(G.issues.length){let K=new(q?.Err??Y)(G.issues.map((z)=>C(z,H,_())));throw P0(K,q?.callee),K}return G.value},G0=FY(n),RY=(Y)=>(W,Q,X)=>{let q=X?{...X,async:!1}:{async:!1},H=W._zod.run({value:Q,issues:[]},q);if(H instanceof Promise)throw new v;return H.issues.length?{success:!1,error:new(Y??q3)(H.issues.map((G)=>C(G,q,_())))}:{success:!0,data:H.value}},d=RY(n),MY=(Y)=>async(W,Q,X)=>{let q=X?{...X,async:!0}:{async:!0},H=W._zod.run({value:Q,issues:[]},q);if(H instanceof Promise)H=await H;return H.issues.length?{success:!1,error:new Y(H.issues.map((G)=>C(G,q,_())))}:{success:!0,data:H.value}},i=MY(n);var G3=/^https?$/;var SY="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",jY=new RegExp(`^${SY}$`);var H3=(Y)=>{let W=Y?`[\\s\\S]{${Y?.minimum??0},${Y?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${W}$`)},K3=/^-?\d+n?$/,z3=/^-?\d+$/,H0=/^-?\d+(?:\.\d+)?$/,J3=/^(?:true|false)$/i;var k=L("$ZodCheck",(Y,W)=>{var Q;Y._zod??(Y._zod={}),Y._zod.def=W,(Q=Y._zod).onattach??(Q.onattach=[])}),TY={number:"number",bigint:"bigint",object:"date"};var O0=L("$ZodCheckGreaterThan",(Y,W)=>{k.init(Y,W);let Q=TY[typeof W.value];Y._zod.onattach.push((X)=>{let q=X._zod.bag,H=(W.inclusive?q.minimum:q.exclusiveMinimum)??Number.NEGATIVE_INFINITY;if(W.value>H)if(W.inclusive)q.minimum=W.value;else q.exclusiveMinimum=W.value}),Y._zod.check=(X)=>{if(W.inclusive?X.value>=W.value:X.value>W.value)return;X.issues.push({origin:Q,code:"too_small",minimum:typeof W.value==="object"?W.value.getTime():W.value,input:X.value,inclusive:W.inclusive,inst:Y,continue:!W.abort})}});var N3=L("$ZodCheckNumberFormat",(Y,W)=>{k.init(Y,W),W.format=W.format||"float64";let Q=W.format?.includes("int"),X=Q?"int":"number",[q,H]=a0[W.format];Y._zod.onattach.push((G)=>{let K=G._zod.bag;if(K.format=W.format,K.minimum=q,K.maximum=H,Q)K.pattern=z3}),Y._zod.check=(G)=>{let K=G.value;if(Q){if(!Number.isInteger(K)){G.issues.push({expected:X,format:W.format,code:"invalid_type",continue:!1,input:K,inst:Y});return}if(!Number.isSafeInteger(K)){if(K>0)G.issues.push({input:K,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:Y,origin:X,inclusive:!0,continue:!W.abort});else G.issues.push({input:K,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:Y,origin:X,inclusive:!0,continue:!W.abort});return}}if(K<q)G.issues.push({origin:"number",input:K,code:"too_small",minimum:q,inclusive:!0,inst:Y,continue:!W.abort});if(K>H)G.issues.push({origin:"number",input:K,code:"too_big",maximum:H,inclusive:!0,inst:Y,continue:!W.abort})}});var L3=L("$ZodCheckMinLength",(Y,W)=>{var Q;k.init(Y,W),(Q=Y._zod.def).when??(Q.when=(X)=>{let q=X.value;return!n0(q)&&q.length!==void 0}),Y._zod.onattach.push((X)=>{let q=X._zod.bag.minimum??Number.NEGATIVE_INFINITY;if(W.minimum>q)X._zod.bag.minimum=W.minimum}),Y._zod.check=(X)=>{let q=X.value;if(q.length>=W.minimum)return;let G=Q3(q);X.issues.push({origin:G,code:"too_small",minimum:W.minimum,inclusive:!0,input:q,inst:Y,continue:!W.abort})}});var I0=L("$ZodCheckStringFormat",(Y,W)=>{var Q,X;if(k.init(Y,W),Y._zod.onattach.push((q)=>{let H=q._zod.bag;if(H.format=W.format,W.pattern)H.patterns??(H.patterns=new Set),H.patterns.add(W.pattern)}),W.pattern)(Q=Y._zod).check??(Q.check=(q)=>{if(W.pattern.lastIndex=0,W.pattern.test(q.value))return;q.issues.push({origin:"string",code:"invalid_format",format:W.format,input:q.value,...W.pattern?{pattern:W.pattern.toString()}:{},inst:Y,continue:!W.abort})});else(X=Y._zod).check??(X.check=()=>{})}),U3=L("$ZodCheckRegex",(Y,W)=>{I0.init(Y,W),Y._zod.check=(Q)=>{if(W.pattern.lastIndex=0,W.pattern.test(Q.value))return;Q.issues.push({origin:"string",code:"invalid_format",format:"regex",input:Q.value,pattern:W.pattern.toString(),inst:Y,continue:!W.abort})}});var B3={major:4,minor:4,patch:3};var w=L("$ZodType",(Y,W)=>{var Q;Y??(Y={}),Y._zod.def=W,Y._zod.bag=Y._zod.bag||{},Y._zod.version=B3;let X=[...Y._zod.def.checks??[]];if(Y._zod.traits.has("$ZodCheck"))X.unshift(Y);for(let q of X)for(let H of q._zod.onattach)H(Y);if(X.length===0)(Q=Y._zod).deferred??(Q.deferred=[]),Y._zod.deferred?.push(()=>{Y._zod.run=Y._zod.parse});else{let q=(G,K,z)=>{let J=m(G),N;for(let U of K){if(U._zod.def.when){if(W3(G))continue;if(!U._zod.def.when(G))continue}else if(J)continue;let B=G.issues.length,E=U._zod.check(G);if(E instanceof Promise&&z?.async===!1)throw new v;if(N||E instanceof Promise)N=(N??Promise.resolve()).then(async()=>{if(await E,G.issues.length===B)return;if(!J)J=m(G,B)});else{if(G.issues.length===B)continue;if(!J)J=m(G,B)}}if(N)return N.then(()=>{return G});return G},H=(G,K,z)=>{if(m(G))return G.aborted=!0,G;let J=q(K,X,z);if(J instanceof Promise){if(z.async===!1)throw new v;return J.then((N)=>Y._zod.parse(N,z))}return Y._zod.parse(J,z)};Y._zod.run=(G,K)=>{if(K.skipChecks)return Y._zod.parse(G,K);if(K.direction==="backward"){let J=Y._zod.parse({value:G.value,issues:[]},{...K,skipChecks:!0});if(J instanceof Promise)return J.then((N)=>{return H(N,G,K)});return H(J,G,K)}let z=Y._zod.parse(G,K);if(z instanceof Promise){if(K.async===!1)throw new v;return z.then((J)=>q(J,X,K))}return q(z,X,K)}}M(Y,"~standard",()=>({validate:(q)=>{try{let H=d(Y,q);return H.success?{value:H.data}:{issues:H.error?.issues}}catch(H){return i(Y,q).then((G)=>G.success?{value:G.data}:{issues:G.error?.issues})}},vendor:"zod",version:1}))}),D0=L("$ZodString",(Y,W)=>{w.init(Y,W),Y._zod.pattern=[...Y?._zod.bag?.patterns??[]].pop()??H3(Y._zod.bag),Y._zod.parse=(Q,X)=>{if(W.coerce)try{Q.value=String(Q.value)}catch(q){}if(typeof Q.value==="string")return Q;return Q.issues.push({expected:"string",code:"invalid_type",input:Q.value,inst:Y}),Q}}),w0=L("$ZodStringFormat",(Y,W)=>{I0.init(Y,W),D0.init(Y,W)});var E3=L("$ZodURL",(Y,W)=>{w0.init(Y,W),Y._zod.check=(Q)=>{try{let X=Q.value.trim();if(!W.normalize&&W.protocol?.source===G3.source){if(!/^https?:\/\//i.test(X)){Q.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:Q.value,inst:Y,continue:!W.abort});return}}let q=new URL(X);if(W.hostname){if(W.hostname.lastIndex=0,!W.hostname.test(q.hostname))Q.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:W.hostname.source,input:Q.value,inst:Y,continue:!W.abort})}if(W.protocol){if(W.protocol.lastIndex=0,!W.protocol.test(q.protocol.endsWith(":")?q.protocol.slice(0,-1):q.protocol))Q.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:W.protocol.source,input:Q.value,inst:Y,continue:!W.abort})}if(W.normalize)Q.value=q.href;else Q.value=X;return}catch(X){Q.issues.push({code:"invalid_format",format:"url",input:Q.value,inst:Y,continue:!W.abort})}}});var F0=L("$ZodNumber",(Y,W)=>{w.init(Y,W),Y._zod.pattern=Y._zod.bag.pattern??H0,Y._zod.parse=(Q,X)=>{if(W.coerce)try{Q.value=Number(Q.value)}catch(G){}let q=Q.value;if(typeof q==="number"&&!Number.isNaN(q)&&Number.isFinite(q))return Q;let H=typeof q==="number"?Number.isNaN(q)?"NaN":!Number.isFinite(q)?"Infinity":void 0:void 0;return Q.issues.push({expected:"number",code:"invalid_type",input:q,inst:Y,...H?{received:H}:{}}),Q}}),O3=L("$ZodNumberFormat",(Y,W)=>{N3.init(Y,W),F0.init(Y,W)}),I3=L("$ZodBoolean",(Y,W)=>{w.init(Y,W),Y._zod.pattern=J3,Y._zod.parse=(Q,X)=>{if(W.coerce)try{Q.value=Boolean(Q.value)}catch(H){}let q=Q.value;if(typeof q==="boolean")return Q;return Q.issues.push({expected:"boolean",code:"invalid_type",input:q,inst:Y}),Q}}),D3=L("$ZodBigInt",(Y,W)=>{w.init(Y,W),Y._zod.pattern=K3,Y._zod.parse=(Q,X)=>{if(W.coerce)try{Q.value=BigInt(Q.value)}catch(q){}if(typeof Q.value==="bigint")return Q;return Q.issues.push({expected:"bigint",code:"invalid_type",input:Q.value,inst:Y}),Q}});var w3=L("$ZodNever",(Y,W)=>{w.init(Y,W),Y._zod.parse=(Q,X)=>{return Q.issues.push({expected:"never",code:"invalid_type",input:Q.value,inst:Y}),Q}});var F3=L("$ZodDate",(Y,W)=>{w.init(Y,W),Y._zod.parse=(Q,X)=>{if(W.coerce)try{Q.value=new Date(Q.value)}catch(K){}let q=Q.value,H=q instanceof Date;if(H&&!Number.isNaN(q.getTime()))return Q;return Q.issues.push({expected:"date",code:"invalid_type",input:q,...H?{received:"Invalid Date"}:{},inst:Y}),Q}});function V3(Y,W,Q){if(Y.issues.length)W.issues.push(...x(Q,Y.issues));W.value[Q]=Y.value}var R3=L("$ZodArray",(Y,W)=>{w.init(Y,W),Y._zod.parse=(Q,X)=>{let q=Q.value;if(!Array.isArray(q))return Q.issues.push({expected:"array",code:"invalid_type",input:q,inst:Y}),Q;Q.value=Array(q.length);let H=[];for(let G=0;G<q.length;G++){let K=q[G],z=W.element._zod.run({value:K,issues:[]},X);if(z instanceof Promise)H.push(z.then((J)=>V3(J,Q,G)));else V3(z,Q,G)}if(H.length)return Promise.all(H).then(()=>Q);return Q}});function K0(Y,W,Q,X,q,H){let G=Q in X;if(Y.issues.length){if(q&&H&&!G)return;W.issues.push(...x(Q,Y.issues))}if(!G&&!q){if(!Y.issues.length)W.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[Q]});return}if(Y.value===void 0){if(G)W.value[Q]=void 0}else W.value[Q]=Y.value}function _Y(Y){let W=Object.keys(Y.shape);for(let X of W)if(!Y.shape?.[X]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${X}": expected a Zod schema`);let Q=s0(Y.shape);return{...Y,keys:W,keySet:new Set(W),numKeys:W.length,optionalKeys:new Set(Q)}}function CY(Y,W,Q,X,q,H){let G=[],K=q.keySet,z=q.catchall._zod,J=z.def.type,N=z.optin==="optional",U=z.optout==="optional";for(let B in W){if(B==="__proto__")continue;if(K.has(B))continue;if(J==="never"){G.push(B);continue}let E=z.run({value:W[B],issues:[]},X);if(E instanceof Promise)Y.push(E.then((j)=>K0(j,Q,B,W,N,U)));else K0(E,Q,B,W,N,U)}if(G.length)Q.issues.push({code:"unrecognized_keys",keys:G,input:W,inst:H});if(!Y.length)return Q;return Promise.all(Y).then(()=>{return Q})}var M3=L("$ZodObject",(Y,W)=>{if(w.init(Y,W),!Object.getOwnPropertyDescriptor(W,"shape")?.get){let K=W.shape;Object.defineProperty(W,"shape",{get:()=>{let z={...K};return Object.defineProperty(W,"shape",{value:z}),z}})}let X=o0(()=>_Y(W));M(Y._zod,"propValues",()=>{let K=W.shape,z={};for(let J in K){let N=K[J]._zod;if(N.values){z[J]??(z[J]=new Set);for(let U of N.values)z[J].add(U)}}return z});let q=X0,H=W.catchall,G;Y._zod.parse=(K,z)=>{G??(G=X.value);let J=K.value;if(!q(J))return K.issues.push({expected:"object",code:"invalid_type",input:J,inst:Y}),K;K.value={};let N=[],U=G.shape;for(let B of G.keys){let E=U[B],j=E._zod.optin==="optional",Y0=E._zod.optout==="optional",b=E._zod.run({value:J[B],issues:[]},z);if(b instanceof Promise)N.push(b.then((h)=>K0(h,K,B,J,j,Y0)));else K0(b,K,B,J,j,Y0)}if(!H)return N.length?Promise.all(N).then(()=>K):K;return CY(N,J,K,z,X.value,Y)}});function P3(Y,W,Q,X){for(let H of Y)if(H.issues.length===0)return W.value=H.value,W;let q=Y.filter((H)=>!m(H));if(q.length===1)return W.value=q[0].value,q[0];return W.issues.push({code:"invalid_union",input:W.value,inst:Q,errors:Y.map((H)=>H.issues.map((G)=>C(G,X,_())))}),W}var S3=L("$ZodUnion",(Y,W)=>{w.init(Y,W),M(Y._zod,"optin",()=>W.options.some((X)=>X._zod.optin==="optional")?"optional":void 0),M(Y._zod,"optout",()=>W.options.some((X)=>X._zod.optout==="optional")?"optional":void 0),M(Y._zod,"values",()=>{if(W.options.every((X)=>X._zod.values))return new Set(W.options.flatMap((X)=>Array.from(X._zod.values)));return}),M(Y._zod,"pattern",()=>{if(W.options.every((X)=>X._zod.pattern)){let X=W.options.map((q)=>q._zod.pattern);return new RegExp(`^(${X.map((q)=>V0(q.source)).join("|")})$`)}return});let Q=W.options.length===1?W.options[0]._zod.run:null;Y._zod.parse=(X,q)=>{if(Q)return Q(X,q);let H=!1,G=[];for(let K of W.options){let z=K._zod.run({value:X.value,issues:[]},q);if(z instanceof Promise)G.push(z),H=!0;else{if(z.issues.length===0)return z;G.push(z)}}if(!H)return P3(G,X,Y,q);return Promise.all(G).then((K)=>{return P3(K,X,Y,q)})}});var j3=L("$ZodRecord",(Y,W)=>{w.init(Y,W),Y._zod.parse=(Q,X)=>{let q=Q.value;if(!$0(q))return Q.issues.push({expected:"record",code:"invalid_type",input:q,inst:Y}),Q;let H=[],G=W.keyType._zod.values;if(G){Q.value={};let K=new Set;for(let J of G)if(typeof J==="string"||typeof J==="number"||typeof J==="symbol"){K.add(typeof J==="number"?J.toString():J);let N=W.keyType._zod.run({value:J,issues:[]},X);if(N instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(N.issues.length){Q.issues.push({code:"invalid_key",origin:"record",issues:N.issues.map((E)=>C(E,X,_())),input:J,path:[J],inst:Y});continue}let U=N.value,B=W.valueType._zod.run({value:q[J],issues:[]},X);if(B instanceof Promise)H.push(B.then((E)=>{if(E.issues.length)Q.issues.push(...x(J,E.issues));Q.value[U]=E.value}));else{if(B.issues.length)Q.issues.push(...x(J,B.issues));Q.value[U]=B.value}}let z;for(let J in q)if(!K.has(J))z=z??[],z.push(J);if(z&&z.length>0)Q.issues.push({code:"unrecognized_keys",input:q,inst:Y,keys:z})}else{Q.value={};for(let K of Reflect.ownKeys(q)){if(K==="__proto__")continue;if(!Object.prototype.propertyIsEnumerable.call(q,K))continue;let z=W.keyType._zod.run({value:K,issues:[]},X);if(z instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(typeof K==="string"&&H0.test(K)&&z.issues.length){let U=W.keyType._zod.run({value:Number(K),issues:[]},X);if(U instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(U.issues.length===0)z=U}if(z.issues.length){if(W.mode==="loose")Q.value[K]=q[K];else Q.issues.push({code:"invalid_key",origin:"record",issues:z.issues.map((U)=>C(U,X,_())),input:K,path:[K],inst:Y});continue}let N=W.valueType._zod.run({value:q[K],issues:[]},X);if(N instanceof Promise)H.push(N.then((U)=>{if(U.issues.length)Q.issues.push(...x(K,U.issues));Q.value[z.value]=U.value}));else{if(N.issues.length)Q.issues.push(...x(K,N.issues));Q.value[z.value]=N.value}}}if(H.length)return Promise.all(H).then(()=>Q);return Q}});var T3=L("$ZodEnum",(Y,W)=>{w.init(Y,W);let Q=p0(W.entries),X=new Set(Q);Y._zod.values=X,Y._zod.pattern=new RegExp(`^(${Q.filter((q)=>t0.has(typeof q)).map((q)=>typeof q==="string"?l(q):q.toString()).join("|")})$`),Y._zod.parse=(q,H)=>{let G=q.value;if(X.has(G))return q;return q.issues.push({code:"invalid_value",values:Q,input:G,inst:Y}),q}}),Z3=L("$ZodLiteral",(Y,W)=>{if(w.init(Y,W),W.values.length===0)throw Error("Cannot create literal schema with no valid values");let Q=new Set(W.values);Y._zod.values=Q,Y._zod.pattern=new RegExp(`^(${W.values.map((X)=>typeof X==="string"?l(X):X?l(X.toString()):String(X)).join("|")})$`),Y._zod.parse=(X,q)=>{let H=X.value;if(Q.has(H))return X;return X.issues.push({code:"invalid_value",values:W.values,input:H,inst:Y}),X}});function $3(Y,W){if(W===void 0&&(Y.issues.length||Y.fallback))return{issues:[],value:void 0};return Y}var _3=L("$ZodOptional",(Y,W)=>{w.init(Y,W),Y._zod.optin="optional",Y._zod.optout="optional",M(Y._zod,"values",()=>{return W.innerType._zod.values?new Set([...W.innerType._zod.values,void 0]):void 0}),M(Y._zod,"pattern",()=>{let Q=W.innerType._zod.pattern;return Q?new RegExp(`^(${V0(Q.source)})?$`):void 0}),Y._zod.parse=(Q,X)=>{if(W.innerType._zod.optin==="optional"){let q=Q.value,H=W.innerType._zod.run(Q,X);if(H instanceof Promise)return H.then((G)=>$3(G,q));return $3(H,q)}if(Q.value===void 0)return Q;return W.innerType._zod.run(Q,X)}});function C3(Y,W){return new Y({type:"string",...O(W)})}function m4(Y,W){return new Y({type:"string",coerce:!0,...O(W)})}function v3(Y,W){return new Y({type:"string",format:"url",check:"string_format",abort:!1,...O(W)})}function x3(Y,W){return new Y({type:"number",checks:[],...O(W)})}function u4(Y,W){return new Y({type:"number",coerce:!0,checks:[],...O(W)})}function b3(Y,W){return new Y({type:"number",check:"number_format",abort:!1,format:"safeint",...O(W)})}function k3(Y,W){return new Y({type:"boolean",...O(W)})}function y4(Y,W){return new Y({type:"boolean",coerce:!0,...O(W)})}function f4(Y,W){return new Y({type:"bigint",coerce:!0,...O(W)})}function g3(Y,W){return new Y({type:"never",...O(W)})}function r4(Y,W){return new Y({type:"date",coerce:!0,...O(W)})}function xY(Y,W){return new O0({check:"greater_than",...O(W),value:Y,inclusive:!1})}function bY(Y,W){return new O0({check:"greater_than",...O(W),value:Y,inclusive:!0})}function p4(Y){return xY(0,Y)}function l4(Y){return bY(0,Y)}function o4(Y,W){return new L3({check:"min_length",...O(W),minimum:Y})}function n4(Y,W){return new U3({check:"string_format",format:"regex",...O(W),pattern:Y})}var F=L("ZodMiniType",(Y,W)=>{if(!Y._zod)throw Error("Uninitialized schema in ZodMiniType.");w.init(Y,W),Y.def=W,Y.type=W.type,Y.parse=(Q,X)=>q0(Y,Q,X,{callee:Y.parse}),Y.safeParse=(Q,X)=>d(Y,Q,X),Y.parseAsync=async(Q,X)=>G0(Y,Q,X,{callee:Y.parseAsync}),Y.safeParseAsync=async(Q,X)=>i(Y,Q,X),Y.check=(...Q)=>{return Y.clone({...W,checks:[...W.checks??[],...Q.map((X)=>typeof X==="function"?{_zod:{check:X,def:{check:"custom"},onattach:[]}}:X)]},{parent:!0})},Y.with=Y.check,Y.clone=(Q,X)=>o(Y,Q,X),Y.brand=()=>Y,Y.register=(Q,X)=>{return Q.add(Y,X),Y},Y.apply=(Q)=>Q(Y)}),c3=L("ZodMiniString",(Y,W)=>{D0.init(Y,W),F.init(Y,W)});function t(Y){return C3(c3,Y)}var gY=L("ZodMiniStringFormat",(Y,W)=>{w0.init(Y,W),c3.init(Y,W)});var hY=L("ZodMiniURL",(Y,W)=>{E3.init(Y,W),gY.init(Y,W)});function s9(Y){return v3(hY,Y)}var m3=L("ZodMiniNumber",(Y,W)=>{F0.init(Y,W),F.init(Y,W)});function a9(Y){return x3(m3,Y)}var cY=L("ZodMiniNumberFormat",(Y,W)=>{O3.init(Y,W),m3.init(Y,W)});function e9(Y){return b3(cY,Y)}var mY=L("ZodMiniBoolean",(Y,W)=>{I3.init(Y,W),F.init(Y,W)});function u3(Y){return k3(mY,Y)}var YQ=L("ZodMiniBigInt",(Y,W)=>{D3.init(Y,W),F.init(Y,W)});var uY=L("ZodMiniNever",(Y,W)=>{w3.init(Y,W),F.init(Y,W)});function yY(Y){return g3(uY,Y)}var WQ=L("ZodMiniDate",(Y,W)=>{F3.init(Y,W),F.init(Y,W)});var fY=L("ZodMiniArray",(Y,W)=>{R3.init(Y,W),F.init(Y,W)});function QQ(Y,W){return new fY({type:"array",element:Y,...O(W)})}var y3=L("ZodMiniObject",(Y,W)=>{M3.init(Y,W),F.init(Y,W),M(Y,"shape",()=>W.shape)});function f3(Y,W){let Q={type:"object",shape:Y??{},...O(W)};return new y3(Q)}function XQ(Y,W){return new y3({type:"object",shape:Y,catchall:yY(),...O(W)})}function qQ(Y,W){return e0(Y,W)}function GQ(Y,W){return Y3(r3,Y,W)}var rY=L("ZodMiniUnion",(Y,W)=>{S3.init(Y,W),F.init(Y,W)});function HQ(Y,W){return new rY({type:"union",options:Y,...O(W)})}var h3=L("ZodMiniRecord",(Y,W)=>{j3.init(Y,W),F.init(Y,W)});function KQ(Y,W,Q){if(!W||!W._zod)return new h3({type:"record",keyType:t(),valueType:Y,...O(W)});return new h3({type:"record",keyType:Y,valueType:W,...O(Q)})}var pY=L("ZodMiniEnum",(Y,W)=>{T3.init(Y,W),F.init(Y,W),Y.options=Object.values(W.entries)});function zQ(Y,W){let Q=Array.isArray(Y)?Object.fromEntries(Y.map((X)=>[X,X])):Y;return new pY({type:"enum",entries:Q,...O(W)})}var lY=L("ZodMiniLiteral",(Y,W)=>{Z3.init(Y,W),F.init(Y,W)});function JQ(Y,W){return new lY({type:"literal",values:Array.isArray(Y)?Y:[Y],...O(W)})}var r3=L("ZodMiniOptional",(Y,W)=>{_3.init(Y,W),F.init(Y,W)});function R0(Y){return new r3({type:"optional",innerType:Y})}var nY=R0(u3()),z0=R0(t()),LQ={cwd:z0,json:nY};function M0(Y){let W=Y.def;while(W){if(W.type==="boolean")return!0;let Q=W.innerType??W.in;W=Q?Q.def:void 0}return!1}function p3(Y,W){let Q=W.shape,X={},q=[],H=!1,G=(z,J,N,U)=>{let B=Q[J],E=U?"-":"--";if(!B)throw Error(`Unknown option ${E}${z} (use -- to pass literal text starting with -)`);if(M0(B))return X[J]=N===void 0?!0:N!=="false",0;if(N===void 0)throw Error(`Missing value for ${E}${z}`);return X[J]=N,1};for(let z=0;z<Y.length;z+=1){let J=Y[z];if(H){q.push(J);continue}if(J==="--"){H=!0;continue}if(!J.startsWith("-")||J==="-"){q.push(J);continue}if(J.startsWith("--")){let[U,B]=J.slice(2).split("=",2);if(B===void 0&&Q[U]&&!M0(Q[U]))z+=G(U,U,Y[z+1],!1);else G(U,U,B,!1);continue}let N=J.slice(1);if(Q[N]&&!M0(Q[N]))z+=G(N,N,Y[z+1],!0);else G(N,N,void 0,!0)}let K=W.safeParse(X);if(!K.success){let z=K.error.issues[0],J=String(z.path[0]??""),N=X[J];throw Error(N===void 0?`Missing required --${J}.`:`Invalid --${J} value ${JSON.stringify(N)}: ${z.message}`)}return{options:K.data,positionals:q}}import F2 from"node:net";import e from"node:process";import{spawn as R2}from"node:child_process";import M2 from"node:readline";import l3 from"node:path";import dY from"node:process";function iY(Y){return String(Y??"").replace(/[^A-Za-z0-9._-]/g,"-").replace(/^-+|-+$/g,"")}function o3(Y,W=dY.platform){if(W==="win32")return`pipe:\\\\.\\pipe\\${iY(`${l3.win32.basename(Y)}-codex-app-server`)}`;return`unix:${l3.join(Y,"broker.sock")}`}function g(Y){if(typeof Y!=="string"||Y.length===0)throw Error("Missing broker endpoint.");if(Y.startsWith("pipe:")){let W=Y.slice(5);if(!W)throw Error("Broker pipe endpoint is missing its path.");return{kind:"pipe",path:W}}if(Y.startsWith("unix:")){let W=Y.slice(5);if(!W)throw Error("Broker Unix socket endpoint is missing its path.");return{kind:"unix",path:W}}throw Error(`Unsupported broker endpoint: ${Y}`)}import D from"node:fs";import z2 from"node:net";import J2 from"node:os";import y from"node:path";import v0 from"node:process";import{spawn as N2}from"node:child_process";import{fileURLToPath as L2}from"node:url";import{execFileSync as a3}from"node:child_process";import $ from"node:fs";import eY from"node:os";import P from"node:path";import{spawn as d3,spawnSync as tY}from"node:child_process";import sY from"node:fs";import aY from"node:os";import n3 from"node:path";function i3(Y){try{let W=d3("codex",["archive",Y],{detached:!0,stdio:"ignore"});W.on("error",()=>{}),W.unref()}catch{}}function IQ(Y){let W=n3.join(process.env.CODEX_HOME||n3.join(aY.homedir(),".codex"),"archived_sessions");try{return sY.readdirSync(W).some((Q)=>Q.endsWith(`-${Y}.jsonl`))}catch{return!1}}function DQ(Y){return new Promise((W)=>{try{let Q=d3("codex",["unarchive",Y],{stdio:"ignore"});Q.on("error",()=>W(!1)),Q.on("close",(X)=>W(X===0))}catch{W(!1)}})}function wQ(Y){return tY("codex",["delete","--force",Y],{encoding:"utf8"}).status===0}var t3=["completed","failed","cancelled"],RQ=["queued","running"];var Y2="CODER_HOME";function e3(){return P.resolve(process.env[Y2]||P.join(eY.homedir(),".coder"))}var s3=new Map;function vQ(Y){let W=s3.get(Y);if(W!==void 0)return W;let Q;try{Q=a3("git",["rev-parse","--show-toplevel"],{cwd:Y,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim()}catch{Q=Y}return s3.set(Y,Q),Q}var YY="global";function s(Y){return P.join(e3(),"state",YY)}var J0=null;function j0(){if(J0)return J0;let Y=P.join(e3(),"state"),W=[];try{W=$.readdirSync(Y,{withFileTypes:!0})}catch{}return J0=W.filter((Q)=>Q.isDirectory()&&Q.name!==YY).map((Q)=>P.join(Y,Q.name)),J0}function T0(Y){return P.join(s(Y),"jobs")}function N0(Y){return P.join(s(Y),"archive")}function T(Y,W){let Q=P.join(T0(Y),W);if($.existsSync(P.join(Q,"job.json")))return Q;let X=P.join(N0(Y),W);if($.existsSync(P.join(X,"job.json")))return X;for(let q of j0()){let H=P.join(q,"jobs",W);if($.existsSync(P.join(H,"job.json")))return H}return Q}function W2(Y,W){return W.archived?W:QY(Y,W.id,{archived:!0,archivedAt:new Date().toISOString()})}function WY(Y,W){let Q=W2(Y,W);if(W.engine==="codex"&&W.threadId)i3(W.threadId);let X=T(Y,W.id),q=P.join(N0(Y),W.id);if(X!==q)try{$.mkdirSync(N0(Y),{recursive:!0}),$.renameSync(X,q)}catch{}return Q}function xQ(){let Y=Math.random().toString(36).slice(2,8);return`coder-${Date.now().toString(36)}-${Y}`}function QY(Y,W,Q){let X=T(Y,W);$.mkdirSync(X,{recursive:!0});let q=P.join(X,"job.json"),G={...qY(Y,W)??{id:W,createdAt:new Date().toISOString(),status:"queued"},...Q,updatedAt:new Date().toISOString()};return $.writeFileSync(q,`${JSON.stringify(G,null,2)}
|
|
3
|
+
`,"utf8"),G}function XY(Y){if(!Y.engine&&(Y.agent==="codex"||Y.agent==="claude"))Y.engine=Y.agent;return Y}function qY(Y,W){let Q=P.join(T(Y,W),"job.json");if(!$.existsSync(Q))return null;try{return XY(JSON.parse($.readFileSync(Q,"utf8")))}catch{return null}}function bQ(Y,W){let Q=T(Y,W);if(!$.existsSync(Q))return!1;return $.rmSync(Q,{recursive:!0,force:!0}),!0}function Q2(Y){if(!Y)return!1;try{return process.kill(Y,0),!0}catch(W){return W.code==="EPERM"}}function X2(Y){try{let W=a3("ps",["-o","lstart=","-p",String(Y)],{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim(),Q=W?Date.parse(W):NaN;return Number.isFinite(Q)?Q:null}catch{return null}}function q2(Y,W){if(!Q2(Y))return!1;let Q=X2(Y),X=Date.parse(W.createdAt??"");if(Q===null||!Number.isFinite(X))return!0;return Q<=X+60000}var G2=60000;function GY(Y,W){if(W.status!=="running"&&W.status!=="queued")return W;let Q;if(W.pid)Q=!q2(W.pid,W);else{let X=Date.parse(W.updatedAt??W.createdAt??"");Q=Number.isFinite(X)&&Date.now()-X>G2}if(Q)return QY(Y,W.id,{status:"failed",error:"worker exited without finishing",completedAt:new Date().toISOString()});return W}function S0(Y,W){let Q=[];for(let X of Y){let q=[];try{q=$.readdirSync(X)}catch{continue}for(let H of q){if(W.has(H))continue;let G=P.join(X,H,"job.json");try{let K=XY(JSON.parse($.readFileSync(G,"utf8")));W.add(H),Q.push(K)}catch{}}}return Q}var Z0=(Y,W)=>String(W.updatedAt??"").localeCompare(String(Y.updatedAt??""));function H2(Y){let W=[T0(Y),...j0().map((X)=>P.join(X,"jobs"))],Q=[];for(let X of S0(W,new Set))if(X.archived)WY(Y,X);else Q.push(GY(Y,X));return Q.sort(Z0)}function K2(Y,W){let Q=W?.migrate??!0,X=new Set,q=S0([N0(Y)],X),H=[T0(Y),...j0().map((G)=>P.join(G,"jobs"))];for(let G of S0(H,X))if(G.archived)q.push(Q?WY(Y,G):G);return q.sort(Z0)}function kQ(Y,W){let Q=[...H2(Y),...K2(Y)].sort(Z0);if(!W)return Q[0]??null;let X=Q.find((H)=>H.id===W);if(X)return X;let q=Q.filter((H)=>H.id.startsWith(W));if(q.length===1)return q[0];if(q.length>1)throw Error(`Job reference "${W}" is ambiguous. Use a longer id.`);return null}function gQ(Y,W){let Q=T(Y,W);try{$.mkdirSync(Q,{recursive:!0}),$.writeFileSync(P.join(Q,"heartbeat"),"","utf8")}catch{}}function hQ(Y,W){let Q=T(Y,W.id),X=Date.parse(W.updatedAt??"")||0;for(let q of["log.jsonl","heartbeat"])try{X=Math.max(X,$.statSync(P.join(Q,q)).mtimeMs)}catch{}return X?new Date(X).toISOString():void 0}async function cQ(Y,W,Q=400){let X=W;while(!t3.includes(X.status))await new Promise((q)=>setTimeout(q,Q)),X=GY(Y,qY(Y,X.id)??X);return X}var HY="steer-queue.jsonl";function mQ(Y,W,Q){let X=T(Y,W);$.mkdirSync(X,{recursive:!0}),$.appendFileSync(P.join(X,HY),`${JSON.stringify({at:new Date().toISOString(),text:Q})}
|
|
4
|
+
`,"utf8")}function uQ(Y,W){let Q=T(Y,W),X=P.join(Q,HY),q=P.join(Q,`steer-claim-${process.pid}-${Date.now()}.tmp`);try{$.renameSync(X,q)}catch{return[]}try{return $.readFileSync(q,"utf8").split(/\r?\n/).filter(Boolean).map((H)=>{try{return String(JSON.parse(H).text??"")}catch{return""}}).filter(Boolean)}finally{try{$.unlinkSync(q)}catch{}}}function yQ(Y,W,Q){let X=T(Y,W);$.mkdirSync(X,{recursive:!0}),$.appendFileSync(P.join(X,"log.jsonl"),`${JSON.stringify({at:new Date().toISOString(),...Q})}
|
|
5
|
+
`,"utf8")}function fQ(Y,W,Q=40){let X=P.join(T(Y,W),"log.jsonl");if(!$.existsSync(X))return[];return $.readFileSync(X,"utf8").split(/\r?\n/).filter(Boolean).slice(-Q).map((H)=>{try{return JSON.parse(H)}catch{return{message:H}}})}import _0 from"node:fs";import{fileURLToPath as C0}from"node:url";var oQ=C0(import.meta.url);function KY(){try{return JSON.parse(_0.readFileSync(C0(new URL("../package.json",import.meta.url)),"utf8")).version??"unknown"}catch{return"unknown"}}function nQ(Y){try{return JSON.parse(_0.readFileSync(Y,"utf8")).version??null}catch{return null}}function dQ(){return C0(new URL("..",import.meta.url))}var U2="broker.json";function A2(Y="coder-"){return D.mkdtempSync(y.join(J2.tmpdir(),Y))}function B2(Y){let W=g(Y);return z2.createConnection({path:W.path})}async function JY(Y,W=2000){let Q=Date.now();while(Date.now()-Q<W){if(await new Promise((q)=>{let H=B2(Y);H.on("connect",()=>{H.end(),q(!0)}),H.on("error",()=>q(!1))}))return!0;await new Promise((q)=>setTimeout(q,50))}return!1}function V2({scriptPath:Y,cwd:W,endpoint:Q,pidFile:X,logFile:q,env:H=v0.env}){let G=D.openSync(q,"a"),K=N2(v0.execPath,[Y,"serve","--endpoint",Q,"--cwd",W,"--pid-file",X],{cwd:W,env:H,detached:!0,stdio:["ignore",G,G]});return K.unref(),D.closeSync(G),K}function P2(){let Y=[new URL("./lib/broker.js",import.meta.url),new URL("./broker.js",import.meta.url)];for(let W of Y){let Q=L2(W);if(D.existsSync(Q))return Q}throw Error("Coder broker script not found next to the runtime. Rebuild with `bun run build`.")}function x0(Y){return y.join(s(Y),U2)}function b0(Y){let W=x0(Y);if(!D.existsSync(W))return null;try{return JSON.parse(D.readFileSync(W,"utf8"))}catch{return null}}function $2(Y,W){let Q=s(Y);D.mkdirSync(Q,{recursive:!0}),D.writeFileSync(x0(Y),`${JSON.stringify(W,null,2)}
|
|
6
|
+
`,"utf8")}function E2(Y){let W=x0(Y);if(D.existsSync(W))D.unlinkSync(W)}async function O2(Y){if(!Y)return!1;try{return await JY(Y,150)}catch{return!1}}async function NY(Y,W={}){let Q=W.scriptPath??P2(),X=KY(),q=b0(Y),H=q?.version===X&&q?.scriptPath===Q;if(q&&H&&await O2(q.endpoint))return q;if(q)zY({endpoint:q.endpoint??null,pidFile:q.pidFile??null,logFile:q.logFile??null,sessionDir:q.sessionDir??null,pid:q.pid??null,killProcess:W.killProcess??null}),E2(Y);let G=A2(),z=(W.createBrokerEndpoint??o3)(G,W.platform),J=y.join(G,"broker.pid"),N=y.join(G,"broker.log"),U=V2({scriptPath:Q,cwd:Y,endpoint:z,pidFile:J,logFile:N,env:W.env??v0.env});if(!await JY(z,W.timeoutMs??2000))return zY({endpoint:z,pidFile:J,logFile:N,sessionDir:G,pid:U.pid??null,killProcess:W.killProcess??null}),null;let E={endpoint:z,pidFile:J,logFile:N,sessionDir:G,pid:U.pid??null,version:X,scriptPath:Q};return $2(Y,E),E}function zY({endpoint:Y=null,pidFile:W,logFile:Q,sessionDir:X=null,pid:q=null,killProcess:H=null}){if(Number.isFinite(q)&&H)try{H(q)}catch{}if(W&&D.existsSync(W))D.unlinkSync(W);if(Q&&D.existsSync(Q))D.unlinkSync(Q);if(Y)try{let K=g(Y);if(K.kind==="unix"&&D.existsSync(K.path))D.unlinkSync(K.path)}catch{}let G=X??(W?y.dirname(W):Q?y.dirname(Q):null);if(G&&D.existsSync(G))try{D.rmdirSync(G)}catch{}}import{spawnSync as I2}from"node:child_process";import a from"node:process";function L0(Y,W=[],Q={}){let X=I2(Y,W,{cwd:Q.cwd,env:Q.env,encoding:"utf8",input:Q.input,maxBuffer:Q.maxBuffer,stdio:Q.stdio??"pipe",shell:a.platform==="win32"?a.env.SHELL||!0:!1,windowsHide:!0});return{command:Y,args:W,status:X.status??0,signal:X.signal??null,stdout:X.stdout??"",stderr:X.stderr??"",error:X.error??null}}function J1(Y,W=["--version"],Q={}){let X=L0(Y,W,Q);if(X.error&&X.error.code==="ENOENT")return{available:!1,detail:"not found"};if(X.error)return{available:!1,detail:X.error.message};if(X.status!==0)return{available:!1,detail:X.stderr.trim()||X.stdout.trim()||`exit ${X.status}`};return{available:!0,detail:X.stdout.trim()||X.stderr.trim()||"ok"}}function D2(Y){return/not found|no running instance|cannot find|does not exist|no such process/i.test(Y)}function LY(Y,W={}){if(!Number.isFinite(Y))return{attempted:!1,delivered:!1,method:null};let Q=Y,X=W.platform??a.platform,q=W.runCommandImpl??L0,H=W.killImpl??a.kill.bind(a);if(X==="win32"){let G=q("taskkill",["/PID",String(Q),"/T","/F"],{cwd:W.cwd,env:W.env});if(!G.error&&G.status===0)return{attempted:!0,delivered:!0,method:"taskkill",result:G};let K=`${G.stderr}
|
|
7
|
+
${G.stdout}`.trim();if(!G.error&&D2(K))return{attempted:!0,delivered:!1,method:"taskkill",result:G};if(G.error?.code==="ENOENT")try{return H(Q),{attempted:!0,delivered:!0,method:"kill"}}catch(z){if(z?.code==="ESRCH")return{attempted:!0,delivered:!1,method:"kill"};throw z}if(G.error)throw G.error;throw Error(w2(G))}try{return H(-Q,"SIGTERM"),{attempted:!0,delivered:!0,method:"process-group"}}catch(G){if(G?.code!=="ESRCH")try{return H(Q,"SIGTERM"),{attempted:!0,delivered:!0,method:"process"}}catch(K){if(K?.code==="ESRCH")return{attempted:!0,delivered:!1,method:"process"};throw K}return{attempted:!0,delivered:!1,method:"process-group"}}}function w2(Y){let W=[`${Y.command} ${Y.args.join(" ")}`.trim()];if(Y.signal)W.push(`signal=${Y.signal}`);else W.push(`exit=${Y.status}`);let Q=(Y.stderr||"").trim(),X=(Y.stdout||"").trim();if(Q)W.push(Q);else if(X)W.push(X);return W.join(": ")}var UY="CODER_APP_SERVER_ENDPOINT",BY=-32001,S2="0.144.1",k0;function j2(){if(k0===void 0){let Y=L0("codex",["--version"]),W=/(\d+\.\d+\.\d+(?:-[\w.]+)?)/.exec(`${Y.stdout} ${Y.stderr}`);k0=W?W[1]:S2}return k0}function VY(){return{title:"Coder",name:"coder",version:j2()}}var PY={experimentalApi:!1,requestAttestation:!1,optOutNotificationMethods:["item/agentMessage/delta","item/reasoning/summaryTextDelta","item/reasoning/summaryPartAdded","item/reasoning/textDelta"]};function AY(Y,W,Q){return Q===void 0?{code:Y,message:W}:{code:Y,message:W,data:Q}}function g0(Y,W){let Q=Error(Y);if(Q.data=W,W?.code!==void 0)Q.rpcCode=W.code;return Q}class h0{cwd;options;pending;nextId;stderr;closed;exitError;notificationHandler;serverRequestHandler;lineBuffer;transport;exitPromise;exitResolved;resolveExit;handleServerRequest;constructor(Y,W={}){this.cwd=Y,this.options=W,this.pending=new Map,this.nextId=1,this.stderr="",this.closed=!1,this.exitError=null,this.notificationHandler=null,this.serverRequestHandler=null,this.lineBuffer="",this.transport="unknown",this.handleServerRequest=(Q)=>this.defaultHandleServerRequest(Q),this.exitPromise=new Promise((Q)=>{this.resolveExit=Q})}setNotificationHandler(Y){this.notificationHandler=Y}setServerRequestHandler(Y){this.serverRequestHandler=Y}request(Y,W){if(this.closed)throw Error("codex app-server client is closed.");let Q=this.nextId;return this.nextId+=1,new Promise((X,q)=>{this.pending.set(Q,{resolve:X,reject:q,method:Y}),this.sendMessage({id:Q,method:Y,params:W})})}notify(Y,W={}){if(this.closed)return;this.sendMessage({method:Y,params:W})}handleChunk(Y){this.lineBuffer+=Y;let W=this.lineBuffer.indexOf(`
|
|
8
|
+
`);while(W!==-1){let Q=this.lineBuffer.slice(0,W);this.lineBuffer=this.lineBuffer.slice(W+1),this.handleLine(Q),W=this.lineBuffer.indexOf(`
|
|
9
|
+
`)}}handleLine(Y){if(!Y.trim())return;let W;try{W=JSON.parse(Y)}catch(Q){this.handleExit(g0(`Failed to parse codex app-server JSONL: ${Q instanceof Error?Q.message:String(Q)}`,{line:Y}));return}if(W.id!==void 0&&W.method){this.handleServerRequest(W);return}if(W.id!==void 0){let Q=this.pending.get(W.id);if(!Q)return;if(this.pending.delete(W.id),W.error)Q.reject(g0(W.error.message??`codex app-server ${Q.method} failed.`,W.error));else Q.resolve(W.result??{});return}if(W.method&&this.notificationHandler)this.notificationHandler(W)}defaultHandleServerRequest(Y){let W=this.serverRequestHandler;if(!W){this.sendMessage({id:Y.id,error:AY(-32601,`Unsupported server request: ${Y.method}`)});return}Promise.resolve().then(()=>W(Y.method,Y.params??{})).then((Q)=>{this.sendMessage({id:Y.id,result:Q??{}})}).catch((Q)=>{this.sendMessage({id:Y.id,error:AY(-32000,Q instanceof Error?Q.message:String(Q))})})}handleExit(Y){if(this.exitResolved)return;this.exitResolved=!0,this.exitError=Y??null;for(let W of this.pending.values())W.reject(this.exitError??Error("codex app-server connection closed."));this.pending.clear(),this.resolveExit(void 0)}sendMessage(Y){throw Error("sendMessage must be implemented by subclasses.")}}class $Y extends h0{proc;readline;constructor(Y,W={}){super(Y,W);this.transport="direct"}async initialize(){this.proc=R2("codex",["-c","sandbox_workspace_write.network_access=false","app-server","--disable","plugins"],{cwd:this.cwd,env:this.options.env??e.env,stdio:["pipe","pipe","pipe"],shell:e.platform==="win32"?e.env.SHELL||!0:!1,windowsHide:!0});let Y=this.proc.stdout,W=this.proc.stderr;if(!Y||!W)throw Error("codex app-server did not expose stdio streams.");Y.setEncoding("utf8"),W.setEncoding("utf8"),W.on("data",(Q)=>{this.stderr+=Q}),this.proc.on("error",(Q)=>{this.handleExit(Q)}),this.proc.on("exit",(Q,X)=>{let q=this.stderr.trim(),H=Q===0?null:g0(`codex app-server exited unexpectedly (${X?`signal ${X}`:`exit ${Q}`}).${q?`
|
|
10
|
+
${q}`:""}`);this.handleExit(H)}),this.readline=M2.createInterface({input:Y}),this.readline.on("line",(Q)=>{this.handleLine(Q)}),await this.request("initialize",{clientInfo:this.options.clientInfo??VY(),capabilities:this.options.capabilities??PY}),this.notify("initialized",{})}async close(){if(this.closed){await this.exitPromise;return}if(this.closed=!0,this.readline)this.readline.close();if(this.proc&&!this.proc.killed)this.proc.stdin?.end(),setTimeout(()=>{if(this.proc&&!this.proc.killed&&this.proc.exitCode===null)if(e.platform==="win32")try{LY(this.proc.pid)}catch{}else this.proc.kill("SIGTERM")},50).unref?.();await this.exitPromise}sendMessage(Y){let W=`${JSON.stringify(Y)}
|
|
11
|
+
`,Q=this.proc?.stdin;if(!Q)throw Error("codex app-server stdin is not available.");Q.write(W)}}class EY extends h0{endpoint;socket;constructor(Y,W={}){super(Y,W);this.transport="broker",this.endpoint=W.brokerEndpoint}async initialize(){await new Promise((Y,W)=>{let Q=g(this.endpoint);this.socket=F2.createConnection({path:Q.path}),this.socket.setEncoding("utf8"),this.socket.on("connect",Y),this.socket.on("data",(X)=>{this.handleChunk(X)}),this.socket.on("error",(X)=>{if(!this.exitResolved)W(X);this.handleExit(X)}),this.socket.on("close",()=>{this.handleExit(this.exitError)})}),await this.request("initialize",{clientInfo:this.options.clientInfo??VY(),capabilities:this.options.capabilities??PY}),this.notify("initialized",{})}async close(){if(this.closed){await this.exitPromise;return}if(this.closed=!0,this.socket)this.socket.end();await this.exitPromise}sendMessage(Y){let W=`${JSON.stringify(Y)}
|
|
12
|
+
`,Q=this.socket;if(!Q)throw Error("codex app-server broker connection is not connected.");Q.write(W)}}class c0{static async connect(Y,W={}){let Q=null;if(!W.disableBroker){if(Q=W.brokerEndpoint??W.env?.[UY]??e.env[UY]??null,!Q&&W.reuseExistingBroker)Q=b0(Y)?.endpoint??null;if(!Q&&!W.reuseExistingBroker)Q=(await NY(Y,{env:W.env}))?.endpoint??null}let X=Q?new EY(Y,{...W,brokerEndpoint:Q}):new $Y(Y,W);return await X.initialize(),X}}var Z2=new Set(["turn/start","review/start","thread/compact/start"]);function OY(Y,W,Q){let X=new Set;if(W?.threadId)X.add(W.threadId);if(Y==="review/start"&&Q?.reviewThreadId)X.add(Q.reviewThreadId);return X}function f(Y,W,Q){return Q===void 0?{code:Y,message:W}:{code:Y,message:W,data:Q}}function Z(Y,W){if(Y.destroyed)return;Y.write(`${JSON.stringify(W)}
|
|
13
|
+
`)}var _2=new Set(["turn/interrupt","turn/steer"]);function C2(Y){return typeof Y?.method==="string"&&_2.has(Y.method)}function v2(Y){if(!Y)return;r.mkdirSync(m0.dirname(Y),{recursive:!0}),r.writeFileSync(Y,`${S.pid}
|
|
14
|
+
`,"utf8")}async function x2(){let[Y,...W]=S.argv.slice(2);if(Y!=="serve")throw Error("Usage: node src/lib/broker.mjs serve --endpoint <value> [--cwd <path>] [--pid-file <path>]");let{options:Q}=p3(W,f3({cwd:z0,"pid-file":z0,endpoint:t()})),X=Q.cwd?m0.resolve(S.cwd(),Q.cwd):S.cwd(),q=String(Q.endpoint),H=g(q),G=Q["pid-file"]?m0.resolve(Q["pid-file"]):null;v2(G);let K=await c0.connect(X,{disableBroker:!0}),z=null,J=null,N=null,U=new Set,B=new Map;function E(A){for(let[I,c]of B)if(c===A)B.delete(I),K.sendMessage({id:I,error:f(-32000,"Broker client disconnected before answering the server request.")})}function j(A){if(E(A),z===A)z=null;if(J===A)J=null,N=null}function Y0(A){let I=z??J;if(!I)return;if(Z(I,A),A.method==="turn/completed"&&J===I){let c=A.params?.threadId??null;if(!c||!N||N.has(c)){if(J=null,N=null,z===I)z=null}}}async function b(A){for(let I of U)I.end();if(await K.close().catch(()=>{}),await new Promise((I)=>A.close(I)),H.kind==="unix"&&r.existsSync(H.path))r.unlinkSync(H.path);if(G&&r.existsSync(G))r.unlinkSync(G)}K.setNotificationHandler(Y0),K.handleServerRequest=(A)=>{let I=J??z;if(!I||I.destroyed){K.sendMessage({id:A.id,error:f(-32601,`No broker client available to answer ${A.method}.`)});return}B.set(A.id,I),Z(I,A)};let h=T2.createServer((A)=>{U.add(A),A.setEncoding("utf8");let I="";A.on("data",async(c)=>{I+=c;let W0=I.indexOf(`
|
|
15
|
+
`);while(W0!==-1){let u0=I.slice(0,W0);if(I=I.slice(W0+1),W0=I.indexOf(`
|
|
16
|
+
`),!u0.trim())continue;let V;try{V=JSON.parse(u0)}catch(R){Z(A,{id:null,error:f(-32700,`Invalid JSON: ${R instanceof Error?R.message:String(R)}`)});continue}if(V.id!==void 0&&!V.method&&B.has(V.id)){B.delete(V.id),K.sendMessage(V);continue}if(V.id!==void 0&&V.method==="initialize"){Z(A,{id:V.id,result:{userAgent:"coder-broker"}});continue}if(V.method==="initialized"&&V.id===void 0)continue;if(V.id!==void 0&&V.method==="broker/shutdown")Z(A,{id:V.id,result:{}}),await b(h),S.exit(0);if(V.id===void 0||!V.method)continue;let y0=C2(V)&&J&&J!==A&&!z;if((z&&z!==A||J&&J!==A)&&!y0){Z(A,{id:V.id,error:f(BY,"Shared Codex broker is busy.")});continue}if(y0){try{let R=await K.request(V.method,V.params??{});Z(A,{id:V.id,result:R})}catch(R){let p=R;Z(A,{id:V.id,error:f(p.rpcCode??-32000,p.message)})}continue}let U0=Z2.has(V.method);if(z=A,U0)J=A,N=OY(V.method,V.params??{},null);try{let R=await K.request(V.method,V.params??{});if(Z(A,{id:V.id,result:R}),U0)N=OY(V.method,V.params??{},R);if(z===A)z=null}catch(R){let p=R;if(Z(A,{id:V.id,error:f(p.rpcCode??-32000,p.message)}),z===A)z=null;if(J===A&&U0)J=null,N=null}}}),A.on("close",()=>{U.delete(A),j(A)}),A.on("error",()=>{U.delete(A),j(A)})});S.on("SIGTERM",async()=>{await b(h),S.exit(0)}),S.on("SIGINT",async()=>{await b(h),S.exit(0)}),h.listen(H.path)}x2().catch((Y)=>{S.stderr.write(`${Y instanceof Error?Y.message:String(Y)}
|
|
17
|
+
`),S.exit(1)});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coder",
|
|
3
3
|
"displayName": "Coder",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.11",
|
|
5
5
|
"description": "Delegate coding tasks to supervised Coder subagents running on Codex, Claude, or any OpenAI-compatible model. Your main context stays clean.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "muzam1l"
|