@wular/coder 0.1.18 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
- var T$=Object.defineProperty;var G1=($,W)=>{for(var q in W)T$($,q,{get:W[q],enumerable:!0,configurable:!0,set:(Z)=>W[q]=()=>Z})};import E from"node:fs";import e$ from"node:net";import r from"node:path";import x from"node:process";function e($,W={}){let q=new Set(W.valueOptions??[]),Z=new Set(W.booleanOptions??[]),G=W.aliasMap??{},Y={},Q=[],H=!1;for(let X=0;X<$.length;X+=1){let y=$[X];if(H){Q.push(y);continue}if(y==="--"){H=!0;continue}if(!y.startsWith("-")||y==="-"){Q.push(y);continue}if(y.startsWith("--")){let[O,_]=y.slice(2).split("=",2),f=G[O]??O;if(Z.has(f)){Y[f]=_===void 0?!0:_!=="false";continue}if(q.has(f)){let S=_??$[X+1];if(S===void 0)throw Error(`Missing value for --${O}`);if(Y[f]=S,_===void 0)X+=1;continue}throw Error(`Unknown option --${O} (use -- to pass literal text starting with -)`)}let N=y.slice(1),J=G[N]??N;if(Z.has(J)){Y[J]=!0;continue}if(q.has(J)){let O=$[X+1];if(O===void 0)throw Error(`Missing value for -${N}`);Y[J]=O,X+=1;continue}throw Error(`Unknown option -${N} (use -- to pass literal text starting with -)`)}return{options:Y,positionals:Q}}import i$ from"node:net";import I from"node:process";import{spawn as d$}from"node:child_process";import r$ from"node:readline";import $$ from"node:path";import x$ from"node:process";function A$($){return String($??"").replace(/[^A-Za-z0-9._-]/g,"-").replace(/^-+|-+$/g,"")}function W$($,W=x$.platform){if(W==="win32")return`pipe:\\\\.\\pipe\\${A$(`${$$.win32.basename($)}-codex-app-server`)}`;return`unix:${$$.join($,"broker.sock")}`}function R($){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 M from"node:fs";import S$ from"node:net";import k$ from"node:os";import B from"node:path";import c from"node:process";import{spawn as F$}from"node:child_process";import{fileURLToPath as v$}from"node:url";import{createHash as _$}from"node:crypto";import{execFileSync as Z$}from"node:child_process";import V from"node:fs";import f$ from"node:os";import T from"node:path";var q$=["completed","failed","cancelled"],y1=["queued","running"];var R$="CODER_HOME";function P$(){return T.resolve(process.env[R$]||T.join(f$.homedir(),".coder"))}function B$($){try{return Z$("git",["rev-parse","--show-toplevel"],{cwd:$,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return $}}function v($){let W=B$($),q=W;try{q=V.realpathSync.native(W)}catch{q=W}let G=(T.basename(W)||"workspace").replace(/[^a-zA-Z0-9._-]+/g,"-").replace(/^-+|-+$/g,"")||"workspace",Y=_$("sha256").update(q).digest("hex").slice(0,12);return T.join(P$(),"state",`${G}-${Y}`)}function G$($){return T.join(v($),"jobs")}function u($,W){return T.join(G$($),W)}function L1(){let $=Math.random().toString(36).slice(2,8);return`coder-${Date.now().toString(36)}-${$}`}function C$($,W,q){let Z=u($,W);V.mkdirSync(Z,{recursive:!0});let G=T.join(Z,"job.json"),Q={...g($,W)??{id:W,createdAt:new Date().toISOString(),status:"queued"},...q,updatedAt:new Date().toISOString()};return V.writeFileSync(G,`${JSON.stringify(Q,null,2)}
3
- `,"utf8"),Q}function g($,W){let q=T.join(u($,W),"job.json");if(!V.existsSync(q))return null;try{return JSON.parse(V.readFileSync(q,"utf8"))}catch{return null}}function T1($,W){let q=u($,W);if(!V.existsSync(q))return!1;return V.rmSync(q,{recursive:!0,force:!0}),!0}function E$($){if(!$)return!1;try{return process.kill($,0),!0}catch(W){return W.code==="EPERM"}}function h$($){try{let W=Z$("ps",["-o","lstart=","-p",String($)],{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim(),q=W?Date.parse(W):NaN;return Number.isFinite(q)?q:null}catch{return null}}function u$($,W){if(!E$($))return!1;let q=h$($),Z=Date.parse(W.createdAt??"");if(q===null||!Number.isFinite(Z))return!0;return q<=Z+60000}var D$=60000;function K$($,W){if(W.status!=="running"&&W.status!=="queued")return W;let q;if(W.pid)q=!u$(W.pid,W);else{let Z=Date.parse(W.updatedAt??W.createdAt??"");q=Number.isFinite(Z)&&Date.now()-Z>D$}if(q)return C$($,W.id,{status:"failed",error:"worker exited without finishing",completedAt:new Date().toISOString()});return W}function I$($){let W=G$($);if(!V.existsSync(W))return[];return V.readdirSync(W).map((q)=>g($,q)).filter((q)=>q!==null).map((q)=>K$($,q)).sort((q,Z)=>String(Z.updatedAt??"").localeCompare(String(q.updatedAt??"")))}function x1($,W){let q=I$($);if(!W)return q[0]??null;let Z=q.find((Y)=>Y.id===W);if(Z)return Z;let G=q.filter((Y)=>Y.id.startsWith(W));if(G.length===1)return G[0];if(G.length>1)throw Error(`Job reference "${W}" is ambiguous. Use a longer id.`);return null}async function A1($,W,q=400){let Z=W;while(!q$.includes(Z.status))await new Promise((G)=>setTimeout(G,q)),Z=K$($,g($,Z.id)??Z);return Z}function _1($,W,q){let Z=u($,W);V.mkdirSync(Z,{recursive:!0}),V.appendFileSync(T.join(Z,"log.jsonl"),`${JSON.stringify({at:new Date().toISOString(),...q})}
4
- `,"utf8")}function f1($,W,q=40){let Z=T.join(u($,W),"log.jsonl");if(!V.existsSync(Z))return[];return V.readFileSync(Z,"utf8").split(/\r?\n/).filter(Boolean).slice(-q).map((Y)=>{try{return JSON.parse(Y)}catch{return{message:Y}}})}import m from"node:fs";import{fileURLToPath as p}from"node:url";var C1=p(import.meta.url);function Q$(){try{return JSON.parse(m.readFileSync(p(new URL("../package.json",import.meta.url)),"utf8")).version??"unknown"}catch{return"unknown"}}function E1($){try{return JSON.parse(m.readFileSync($,"utf8")).version??null}catch{return null}}function h1(){return p(new URL("..",import.meta.url))}var w$="broker.json";function j$($="coder-"){return M.mkdtempSync(B.join(k$.tmpdir(),$))}function b$($){let W=R($);return S$.createConnection({path:W.path})}async function z$($,W=2000){let q=Date.now();while(Date.now()-q<W){if(await new Promise((G)=>{let Y=b$($);Y.on("connect",()=>{Y.end(),G(!0)}),Y.on("error",()=>G(!1))}))return!0;await new Promise((G)=>setTimeout(G,50))}return!1}function g$({scriptPath:$,cwd:W,endpoint:q,pidFile:Z,logFile:G,env:Y=c.env}){let Q=M.openSync(G,"a"),H=F$(c.execPath,[$,"serve","--endpoint",q,"--cwd",W,"--pid-file",Z],{cwd:W,env:Y,detached:!0,stdio:["ignore",Q,Q]});return H.unref(),M.closeSync(Q),H}function m$(){let $=[new URL("./lib/broker.js",import.meta.url),new URL("./broker.js",import.meta.url)];for(let W of $){let q=v$(W);if(M.existsSync(q))return q}throw Error("Coder broker script not found next to the runtime. Rebuild with `bun run build`.")}function n($){return B.join(v($),w$)}function a($){let W=n($);if(!M.existsSync(W))return null;try{return JSON.parse(M.readFileSync(W,"utf8"))}catch{return null}}function p$($,W){let q=v($);M.mkdirSync(q,{recursive:!0}),M.writeFileSync(n($),`${JSON.stringify(W,null,2)}
5
- `,"utf8")}function c$($){let W=n($);if(M.existsSync(W))M.unlinkSync(W)}async function n$($){if(!$)return!1;try{return await z$($,150)}catch{return!1}}async function X$($,W={}){let q=W.scriptPath??m$(),Z=Q$(),G=a($),Y=G?.version===Z&&G?.scriptPath===q;if(G&&Y&&await n$(G.endpoint))return G;if(G)Y$({endpoint:G.endpoint??null,pidFile:G.pidFile??null,logFile:G.logFile??null,sessionDir:G.sessionDir??null,pid:G.pid??null,killProcess:W.killProcess??null}),c$($);let Q=j$(),X=(W.createBrokerEndpoint??W$)(Q,W.platform),y=B.join(Q,"broker.pid"),N=B.join(Q,"broker.log"),J=g$({scriptPath:q,cwd:$,endpoint:X,pidFile:y,logFile:N,env:W.env??c.env});if(!await z$(X,W.timeoutMs??2000))return Y$({endpoint:X,pidFile:y,logFile:N,sessionDir:Q,pid:J.pid??null,killProcess:W.killProcess??null}),null;let _={endpoint:X,pidFile:y,logFile:N,sessionDir:Q,pid:J.pid??null,version:Z,scriptPath:q};return p$($,_),_}function Y$({endpoint:$=null,pidFile:W,logFile:q,sessionDir:Z=null,pid:G=null,killProcess:Y=null}){if(Number.isFinite(G)&&Y)try{Y(G)}catch{}if(W&&M.existsSync(W))M.unlinkSync(W);if(q&&M.existsSync(q))M.unlinkSync(q);if($)try{let H=R($);if(H.kind==="unix"&&M.existsSync(H.path))M.unlinkSync(H.path)}catch{}let Q=Z??(W?B.dirname(W):q?B.dirname(q):null);if(Q&&M.existsSync(Q))try{M.rmdirSync(Q)}catch{}}import{spawnSync as a$}from"node:child_process";import D from"node:process";function w($,W=[],q={}){let Z=a$($,W,{cwd:q.cwd,env:q.env,encoding:"utf8",input:q.input,maxBuffer:q.maxBuffer,stdio:q.stdio??"pipe",shell:D.platform==="win32"?D.env.SHELL||!0:!1,windowsHide:!0});return{command:$,args:W,status:Z.status??0,signal:Z.signal??null,stdout:Z.stdout??"",stderr:Z.stderr??"",error:Z.error??null}}function n1($,W=["--version"],q={}){let Z=w($,W,q);if(Z.error&&Z.error.code==="ENOENT")return{available:!1,detail:"not found"};if(Z.error)return{available:!1,detail:Z.error.message};if(Z.status!==0)return{available:!1,detail:Z.stderr.trim()||Z.stdout.trim()||`exit ${Z.status}`};return{available:!0,detail:Z.stdout.trim()||Z.stderr.trim()||"ok"}}function l$($){return/not found|no running instance|cannot find|does not exist|no such process/i.test($)}function y$($,W={}){if(!Number.isFinite($))return{attempted:!1,delivered:!1,method:null};let q=$,Z=W.platform??D.platform,G=W.runCommandImpl??w,Y=W.killImpl??D.kill.bind(D);if(Z==="win32"){let Q=G("taskkill",["/PID",String(q),"/T","/F"],{cwd:W.cwd,env:W.env});if(!Q.error&&Q.status===0)return{attempted:!0,delivered:!0,method:"taskkill",result:Q};let H=`${Q.stderr}
6
- ${Q.stdout}`.trim();if(!Q.error&&l$(H))return{attempted:!0,delivered:!1,method:"taskkill",result:Q};if(Q.error?.code==="ENOENT")try{return Y(q),{attempted:!0,delivered:!0,method:"kill"}}catch(X){if(X?.code==="ESRCH")return{attempted:!0,delivered:!1,method:"kill"};throw X}if(Q.error)throw Q.error;throw Error(t$(Q))}try{return Y(-q,"SIGTERM"),{attempted:!0,delivered:!0,method:"process-group"}}catch(Q){if(Q?.code!=="ESRCH")try{return Y(q,"SIGTERM"),{attempted:!0,delivered:!0,method:"process"}}catch(H){if(H?.code==="ESRCH")return{attempted:!0,delivered:!1,method:"process"};throw H}return{attempted:!0,delivered:!1,method:"process-group"}}}function t$($){let W=[`${$.command} ${$.args.join(" ")}`.trim()];if($.signal)W.push(`signal=${$.signal}`);else W.push(`exit=${$.status}`);let q=($.stderr||"").trim(),Z=($.stdout||"").trim();if(q)W.push(q);else if(Z)W.push(Z);return W.join(": ")}var H$="CODER_APP_SERVER_ENDPOINT",M$=-32001,o$="0.144.1",l;function s$(){if(l===void 0){let $=w("codex",["--version"]),W=/(\d+\.\d+\.\d+(?:-[\w.]+)?)/.exec(`${$.stdout} ${$.stderr}`);l=W?W[1]:o$}return l}function N$(){return{title:"Coder",name:"coder",version:s$()}}var O$={experimentalApi:!1,requestAttestation:!1,optOutNotificationMethods:["item/agentMessage/delta","item/reasoning/summaryTextDelta","item/reasoning/summaryPartAdded","item/reasoning/textDelta"]};function U$($,W,q){return q===void 0?{code:$,message:W}:{code:$,message:W,data:q}}function t($,W){let q=Error($);if(q.data=W,W?.code!==void 0)q.rpcCode=W.code;return q}class i{cwd;options;pending;nextId;stderr;closed;exitError;notificationHandler;serverRequestHandler;lineBuffer;transport;exitPromise;exitResolved;resolveExit;handleServerRequest;constructor($,W={}){this.cwd=$,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($){this.notificationHandler=$}setServerRequestHandler($){this.serverRequestHandler=$}request($,W){if(this.closed)throw Error("codex app-server client is closed.");let q=this.nextId;return this.nextId+=1,new Promise((Z,G)=>{this.pending.set(q,{resolve:Z,reject:G,method:$}),this.sendMessage({id:q,method:$,params:W})})}notify($,W={}){if(this.closed)return;this.sendMessage({method:$,params:W})}handleChunk($){this.lineBuffer+=$;let W=this.lineBuffer.indexOf(`
2
+ var J$=Object.defineProperty;var G1=($,W)=>{for(var q in W)J$($,q,{get:W[q],enumerable:!0,configurable:!0,set:(Z)=>W[q]=()=>Z})};import E from"node:fs";import e$ from"node:net";import d from"node:path";import x from"node:process";function s($,W={}){let q=new Set(W.valueOptions??[]),Z=new Set(W.booleanOptions??[]),G=W.aliasMap??{},Y={},Q=[],H=!1;for(let X=0;X<$.length;X+=1){let y=$[X];if(H){Q.push(y);continue}if(y==="--"){H=!0;continue}if(!y.startsWith("-")||y==="-"){Q.push(y);continue}if(y.startsWith("--")){let[O,_]=y.slice(2).split("=",2),f=G[O]??O;if(Z.has(f)){Y[f]=_===void 0?!0:_!=="false";continue}if(q.has(f)){let S=_??$[X+1];if(S===void 0)throw Error(`Missing value for --${O}`);if(Y[f]=S,_===void 0)X+=1;continue}throw Error(`Unknown option --${O} (use -- to pass literal text starting with -)`)}let N=y.slice(1),J=G[N]??N;if(Z.has(J)){Y[J]=!0;continue}if(q.has(J)){let O=$[X+1];if(O===void 0)throw Error(`Missing value for -${N}`);Y[J]=O,X+=1;continue}throw Error(`Unknown option -${N} (use -- to pass literal text starting with -)`)}return{options:Y,positionals:Q}}import i$ from"node:net";import I from"node:process";import{spawn as d$}from"node:child_process";import r$ from"node:readline";import e from"node:path";import L$ from"node:process";function T$($){return String($??"").replace(/[^A-Za-z0-9._-]/g,"-").replace(/^-+|-+$/g,"")}function $$($,W=L$.platform){if(W==="win32")return`pipe:\\\\.\\pipe\\${T$(`${e.win32.basename($)}-codex-app-server`)}`;return`unix:${e.join($,"broker.sock")}`}function R($){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 M from"node:fs";import S$ from"node:net";import k$ from"node:os";import B from"node:path";import p from"node:process";import{spawn as F$}from"node:child_process";import{fileURLToPath as v$}from"node:url";import{createHash as A$}from"node:crypto";import{execFileSync as W$}from"node:child_process";import V from"node:fs";import _$ from"node:os";import T from"node:path";var x$=["completed","failed","cancelled"],y1=["queued","running"];var f$="CODER_HOME";function R$(){return T.resolve(process.env[f$]||T.join(_$.homedir(),".coder"))}function P$($){try{return W$("git",["rev-parse","--show-toplevel"],{cwd:$,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return $}}function v($){let W=P$($),q=W;try{q=V.realpathSync.native(W)}catch{q=W}let G=(T.basename(W)||"workspace").replace(/[^a-zA-Z0-9._-]+/g,"-").replace(/^-+|-+$/g,"")||"workspace",Y=A$("sha256").update(q).digest("hex").slice(0,12);return T.join(R$(),"state",`${G}-${Y}`)}function q$($){return T.join(v($),"jobs")}function u($,W){return T.join(q$($),W)}function L1(){let $=Math.random().toString(36).slice(2,8);return`coder-${Date.now().toString(36)}-${$}`}function B$($,W,q){let Z=u($,W);V.mkdirSync(Z,{recursive:!0});let G=T.join(Z,"job.json"),Q={...Z$($,W)??{id:W,createdAt:new Date().toISOString(),status:"queued"},...q,updatedAt:new Date().toISOString()};return V.writeFileSync(G,`${JSON.stringify(Q,null,2)}
3
+ `,"utf8"),Q}function Z$($,W){let q=T.join(u($,W),"job.json");if(!V.existsSync(q))return null;try{return JSON.parse(V.readFileSync(q,"utf8"))}catch{return null}}function T1($,W){let q=u($,W);if(!V.existsSync(q))return!1;return V.rmSync(q,{recursive:!0,force:!0}),!0}function C$($){if(!$)return!1;try{return process.kill($,0),!0}catch(W){return W.code==="EPERM"}}function E$($){try{let W=W$("ps",["-o","lstart=","-p",String($)],{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim(),q=W?Date.parse(W):NaN;return Number.isFinite(q)?q:null}catch{return null}}function h$($,W){if(!C$($))return!1;let q=E$($),Z=Date.parse(W.createdAt??"");if(q===null||!Number.isFinite(Z))return!0;return q<=Z+60000}var u$=60000;function D$($,W){if(W.status!=="running"&&W.status!=="queued")return W;let q;if(W.pid)q=!h$(W.pid,W);else{let Z=Date.parse(W.updatedAt??W.createdAt??"");q=Number.isFinite(Z)&&Date.now()-Z>u$}if(q)return B$($,W.id,{status:"failed",error:"worker exited without finishing",completedAt:new Date().toISOString()});return W}function I$($){let W=q$($);if(!V.existsSync(W))return[];return V.readdirSync(W).map((q)=>Z$($,q)).filter((q)=>q!==null).map((q)=>D$($,q)).sort((q,Z)=>String(Z.updatedAt??"").localeCompare(String(q.updatedAt??"")))}function x1($,W){let q=I$($);if(!W)return q[0]??null;let Z=q.find((Y)=>Y.id===W);if(Z)return Z;let G=q.filter((Y)=>Y.id.startsWith(W));if(G.length===1)return G[0];if(G.length>1)throw Error(`Job reference "${W}" is ambiguous. Use a longer id.`);return null}function A1($,W,q){let Z=u($,W);V.mkdirSync(Z,{recursive:!0}),V.appendFileSync(T.join(Z,"log.jsonl"),`${JSON.stringify({at:new Date().toISOString(),...q})}
4
+ `,"utf8")}function _1($,W,q=40){let Z=T.join(u($,W),"log.jsonl");if(!V.existsSync(Z))return[];return V.readFileSync(Z,"utf8").split(/\r?\n/).filter(Boolean).slice(-q).map((Y)=>{try{return JSON.parse(Y)}catch{return{message:Y}}})}import g from"node:fs";import{fileURLToPath as m}from"node:url";var B1=m(import.meta.url);function G$(){try{return JSON.parse(g.readFileSync(m(new URL("../package.json",import.meta.url)),"utf8")).version??"unknown"}catch{return"unknown"}}function C1($){try{return JSON.parse(g.readFileSync($,"utf8")).version??null}catch{return null}}function E1(){return m(new URL("..",import.meta.url))}var w$="broker.json";function j$($="coder-"){return M.mkdtempSync(B.join(k$.tmpdir(),$))}function b$($){let W=R($);return S$.createConnection({path:W.path})}async function Q$($,W=2000){let q=Date.now();while(Date.now()-q<W){if(await new Promise((G)=>{let Y=b$($);Y.on("connect",()=>{Y.end(),G(!0)}),Y.on("error",()=>G(!1))}))return!0;await new Promise((G)=>setTimeout(G,50))}return!1}function g$({scriptPath:$,cwd:W,endpoint:q,pidFile:Z,logFile:G,env:Y=p.env}){let Q=M.openSync(G,"a"),H=F$(p.execPath,[$,"serve","--endpoint",q,"--cwd",W,"--pid-file",Z],{cwd:W,env:Y,detached:!0,stdio:["ignore",Q,Q]});return H.unref(),M.closeSync(Q),H}function m$(){let $=[new URL("./lib/broker.js",import.meta.url),new URL("./broker.js",import.meta.url)];for(let W of $){let q=v$(W);if(M.existsSync(q))return q}throw Error("Coder broker script not found next to the runtime. Rebuild with `bun run build`.")}function c($){return B.join(v($),w$)}function n($){let W=c($);if(!M.existsSync(W))return null;try{return JSON.parse(M.readFileSync(W,"utf8"))}catch{return null}}function p$($,W){let q=v($);M.mkdirSync(q,{recursive:!0}),M.writeFileSync(c($),`${JSON.stringify(W,null,2)}
5
+ `,"utf8")}function c$($){let W=c($);if(M.existsSync(W))M.unlinkSync(W)}async function n$($){if(!$)return!1;try{return await Q$($,150)}catch{return!1}}async function Y$($,W={}){let q=W.scriptPath??m$(),Z=G$(),G=n($),Y=G?.version===Z&&G?.scriptPath===q;if(G&&Y&&await n$(G.endpoint))return G;if(G)K$({endpoint:G.endpoint??null,pidFile:G.pidFile??null,logFile:G.logFile??null,sessionDir:G.sessionDir??null,pid:G.pid??null,killProcess:W.killProcess??null}),c$($);let Q=j$(),X=(W.createBrokerEndpoint??$$)(Q,W.platform),y=B.join(Q,"broker.pid"),N=B.join(Q,"broker.log"),J=g$({scriptPath:q,cwd:$,endpoint:X,pidFile:y,logFile:N,env:W.env??p.env});if(!await Q$(X,W.timeoutMs??2000))return K$({endpoint:X,pidFile:y,logFile:N,sessionDir:Q,pid:J.pid??null,killProcess:W.killProcess??null}),null;let _={endpoint:X,pidFile:y,logFile:N,sessionDir:Q,pid:J.pid??null,version:Z,scriptPath:q};return p$($,_),_}function K$({endpoint:$=null,pidFile:W,logFile:q,sessionDir:Z=null,pid:G=null,killProcess:Y=null}){if(Number.isFinite(G)&&Y)try{Y(G)}catch{}if(W&&M.existsSync(W))M.unlinkSync(W);if(q&&M.existsSync(q))M.unlinkSync(q);if($)try{let H=R($);if(H.kind==="unix"&&M.existsSync(H.path))M.unlinkSync(H.path)}catch{}let Q=Z??(W?B.dirname(W):q?B.dirname(q):null);if(Q&&M.existsSync(Q))try{M.rmdirSync(Q)}catch{}}import{spawnSync as a$}from"node:child_process";import D from"node:process";function w($,W=[],q={}){let Z=a$($,W,{cwd:q.cwd,env:q.env,encoding:"utf8",input:q.input,maxBuffer:q.maxBuffer,stdio:q.stdio??"pipe",shell:D.platform==="win32"?D.env.SHELL||!0:!1,windowsHide:!0});return{command:$,args:W,status:Z.status??0,signal:Z.signal??null,stdout:Z.stdout??"",stderr:Z.stderr??"",error:Z.error??null}}function c1($,W=["--version"],q={}){let Z=w($,W,q);if(Z.error&&Z.error.code==="ENOENT")return{available:!1,detail:"not found"};if(Z.error)return{available:!1,detail:Z.error.message};if(Z.status!==0)return{available:!1,detail:Z.stderr.trim()||Z.stdout.trim()||`exit ${Z.status}`};return{available:!0,detail:Z.stdout.trim()||Z.stderr.trim()||"ok"}}function l$($){return/not found|no running instance|cannot find|does not exist|no such process/i.test($)}function z$($,W={}){if(!Number.isFinite($))return{attempted:!1,delivered:!1,method:null};let q=$,Z=W.platform??D.platform,G=W.runCommandImpl??w,Y=W.killImpl??D.kill.bind(D);if(Z==="win32"){let Q=G("taskkill",["/PID",String(q),"/T","/F"],{cwd:W.cwd,env:W.env});if(!Q.error&&Q.status===0)return{attempted:!0,delivered:!0,method:"taskkill",result:Q};let H=`${Q.stderr}
6
+ ${Q.stdout}`.trim();if(!Q.error&&l$(H))return{attempted:!0,delivered:!1,method:"taskkill",result:Q};if(Q.error?.code==="ENOENT")try{return Y(q),{attempted:!0,delivered:!0,method:"kill"}}catch(X){if(X?.code==="ESRCH")return{attempted:!0,delivered:!1,method:"kill"};throw X}if(Q.error)throw Q.error;throw Error(t$(Q))}try{return Y(-q,"SIGTERM"),{attempted:!0,delivered:!0,method:"process-group"}}catch(Q){if(Q?.code!=="ESRCH")try{return Y(q,"SIGTERM"),{attempted:!0,delivered:!0,method:"process"}}catch(H){if(H?.code==="ESRCH")return{attempted:!0,delivered:!1,method:"process"};throw H}return{attempted:!0,delivered:!1,method:"process-group"}}}function t$($){let W=[`${$.command} ${$.args.join(" ")}`.trim()];if($.signal)W.push(`signal=${$.signal}`);else W.push(`exit=${$.status}`);let q=($.stderr||"").trim(),Z=($.stdout||"").trim();if(q)W.push(q);else if(Z)W.push(Z);return W.join(": ")}var X$="CODER_APP_SERVER_ENDPOINT",H$=-32001,o$="0.144.1",a;function s$(){if(a===void 0){let $=w("codex",["--version"]),W=/(\d+\.\d+\.\d+(?:-[\w.]+)?)/.exec(`${$.stdout} ${$.stderr}`);a=W?W[1]:o$}return a}function U$(){return{title:"Coder",name:"coder",version:s$()}}var M$={experimentalApi:!1,requestAttestation:!1,optOutNotificationMethods:["item/agentMessage/delta","item/reasoning/summaryTextDelta","item/reasoning/summaryPartAdded","item/reasoning/textDelta"]};function y$($,W,q){return q===void 0?{code:$,message:W}:{code:$,message:W,data:q}}function l($,W){let q=Error($);if(q.data=W,W?.code!==void 0)q.rpcCode=W.code;return q}class t{cwd;options;pending;nextId;stderr;closed;exitError;notificationHandler;serverRequestHandler;lineBuffer;transport;exitPromise;exitResolved;resolveExit;handleServerRequest;constructor($,W={}){this.cwd=$,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($){this.notificationHandler=$}setServerRequestHandler($){this.serverRequestHandler=$}request($,W){if(this.closed)throw Error("codex app-server client is closed.");let q=this.nextId;return this.nextId+=1,new Promise((Z,G)=>{this.pending.set(q,{resolve:Z,reject:G,method:$}),this.sendMessage({id:q,method:$,params:W})})}notify($,W={}){if(this.closed)return;this.sendMessage({method:$,params:W})}handleChunk($){this.lineBuffer+=$;let W=this.lineBuffer.indexOf(`
7
7
  `);while(W!==-1){let q=this.lineBuffer.slice(0,W);this.lineBuffer=this.lineBuffer.slice(W+1),this.handleLine(q),W=this.lineBuffer.indexOf(`
8
- `)}}handleLine($){if(!$.trim())return;let W;try{W=JSON.parse($)}catch(q){this.handleExit(t(`Failed to parse codex app-server JSONL: ${q instanceof Error?q.message:String(q)}`,{line:$}));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(t(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($){let W=this.serverRequestHandler;if(!W){this.sendMessage({id:$.id,error:U$(-32601,`Unsupported server request: ${$.method}`)});return}Promise.resolve().then(()=>W($.method,$.params??{})).then((q)=>{this.sendMessage({id:$.id,result:q??{}})}).catch((q)=>{this.sendMessage({id:$.id,error:U$(-32000,q instanceof Error?q.message:String(q))})})}handleExit($){if(this.exitResolved)return;this.exitResolved=!0,this.exitError=$??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($){throw Error("sendMessage must be implemented by subclasses.")}}class V$ extends i{proc;readline;constructor($,W={}){super($,W);this.transport="direct"}async initialize(){this.proc=d$("codex",["app-server","--disable","plugins"],{cwd:this.cwd,env:this.options.env??I.env,stdio:["pipe","pipe","pipe"],shell:I.platform==="win32"?I.env.SHELL||!0:!1,windowsHide:!0});let $=this.proc.stdout,W=this.proc.stderr;if(!$||!W)throw Error("codex app-server did not expose stdio streams.");$.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,Z)=>{let G=this.stderr.trim(),Y=q===0?null:t(`codex app-server exited unexpectedly (${Z?`signal ${Z}`:`exit ${q}`}).${G?`
9
- ${G}`:""}`);this.handleExit(Y)}),this.readline=r$.createInterface({input:$}),this.readline.on("line",(q)=>{this.handleLine(q)}),await this.request("initialize",{clientInfo:this.options.clientInfo??N$(),capabilities:this.options.capabilities??O$}),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(I.platform==="win32")try{y$(this.proc.pid)}catch{}else this.proc.kill("SIGTERM")},50).unref?.();await this.exitPromise}sendMessage($){let W=`${JSON.stringify($)}
10
- `,q=this.proc?.stdin;if(!q)throw Error("codex app-server stdin is not available.");q.write(W)}}class J$ extends i{endpoint;socket;constructor($,W={}){super($,W);this.transport="broker",this.endpoint=W.brokerEndpoint}async initialize(){await new Promise(($,W)=>{let q=R(this.endpoint);this.socket=i$.createConnection({path:q.path}),this.socket.setEncoding("utf8"),this.socket.on("connect",$),this.socket.on("data",(Z)=>{this.handleChunk(Z)}),this.socket.on("error",(Z)=>{if(!this.exitResolved)W(Z);this.handleExit(Z)}),this.socket.on("close",()=>{this.handleExit(this.exitError)})}),await this.request("initialize",{clientInfo:this.options.clientInfo??N$(),capabilities:this.options.capabilities??O$}),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($){let W=`${JSON.stringify($)}
11
- `,q=this.socket;if(!q)throw Error("codex app-server broker connection is not connected.");q.write(W)}}class d{static async connect($,W={}){let q=null;if(!W.disableBroker){if(q=W.brokerEndpoint??W.env?.[H$]??I.env[H$]??null,!q&&W.reuseExistingBroker)q=a($)?.endpoint??null;if(!q&&!W.reuseExistingBroker)q=(await X$($,{env:W.env}))?.endpoint??null}let Z=q?new J$($,{...W,brokerEndpoint:q}):new V$($,W);return await Z.initialize(),Z}}var $1=new Set(["turn/start","review/start","thread/compact/start"]);function L$($,W,q){let Z=new Set;if(W?.threadId)Z.add(W.threadId);if($==="review/start"&&q?.reviewThreadId)Z.add(q.reviewThreadId);return Z}function C($,W,q){return q===void 0?{code:$,message:W}:{code:$,message:W,data:q}}function A($,W){if($.destroyed)return;$.write(`${JSON.stringify(W)}
12
- `)}function W1($){return $?.method==="turn/interrupt"}function q1($){if(!$)return;E.mkdirSync(r.dirname($),{recursive:!0}),E.writeFileSync($,`${x.pid}
13
- `,"utf8")}async function Z1(){let[$,...W]=x.argv.slice(2);if($!=="serve")throw Error("Usage: node src/lib/broker.mjs serve --endpoint <value> [--cwd <path>] [--pid-file <path>]");let{options:q}=e(W,{valueOptions:["cwd","pid-file","endpoint"]});if(!q.endpoint)throw Error("Missing required --endpoint.");let Z=q.cwd?r.resolve(x.cwd(),q.cwd):x.cwd(),G=String(q.endpoint),Y=R(G),Q=q["pid-file"]?r.resolve(q["pid-file"]):null;q1(Q);let H=await d.connect(Z,{disableBroker:!0}),X=null,y=null,N=null,J=new Set,O=new Map;function _(K){for(let[U,P]of O)if(P===K)O.delete(U),H.sendMessage({id:U,error:C(-32000,"Broker client disconnected before answering the server request.")})}function f(K){if(_(K),X===K)X=null;if(y===K)y=null,N=null}function S(K){let U=X??y;if(!U)return;if(A(U,K),K.method==="turn/completed"&&y===U){let P=K.params?.threadId??null;if(!P||!N||N.has(P)){if(y=null,N=null,X===U)X=null}}}async function j(K){for(let U of J)U.end();if(await H.close().catch(()=>{}),await new Promise((U)=>K.close(U)),Y.kind==="unix"&&E.existsSync(Y.path))E.unlinkSync(Y.path);if(Q&&E.existsSync(Q))E.unlinkSync(Q)}H.setNotificationHandler(S),H.handleServerRequest=(K)=>{let U=y??X;if(!U||U.destroyed){H.sendMessage({id:K.id,error:C(-32601,`No broker client available to answer ${K.method}.`)});return}O.set(K.id,U),A(U,K)};let k=e$.createServer((K)=>{J.add(K),K.setEncoding("utf8");let U="";K.on("data",async(P)=>{U+=P;let F=U.indexOf(`
14
- `);while(F!==-1){let o=U.slice(0,F);if(U=U.slice(F+1),F=U.indexOf(`
15
- `),!o.trim())continue;let z;try{z=JSON.parse(o)}catch(L){A(K,{id:null,error:C(-32700,`Invalid JSON: ${L instanceof Error?L.message:String(L)}`)});continue}if(z.id!==void 0&&!z.method&&O.has(z.id)){O.delete(z.id),H.sendMessage(z);continue}if(z.id!==void 0&&z.method==="initialize"){A(K,{id:z.id,result:{userAgent:"coder-broker"}});continue}if(z.method==="initialized"&&z.id===void 0)continue;if(z.id!==void 0&&z.method==="broker/shutdown")A(K,{id:z.id,result:{}}),await j(k),x.exit(0);if(z.id===void 0||!z.method)continue;let s=W1(z)&&y&&y!==K&&!X;if((X&&X!==K||y&&y!==K)&&!s){A(K,{id:z.id,error:C(M$,"Shared Codex broker is busy.")});continue}if(s){try{let L=await H.request(z.method,z.params??{});A(K,{id:z.id,result:L})}catch(L){let h=L;A(K,{id:z.id,error:C(h.rpcCode??-32000,h.message)})}continue}let b=$1.has(z.method);if(X=K,b)y=K,N=L$(z.method,z.params??{},null);try{let L=await H.request(z.method,z.params??{});if(A(K,{id:z.id,result:L}),b)N=L$(z.method,z.params??{},L);if(X===K)X=null}catch(L){let h=L;if(A(K,{id:z.id,error:C(h.rpcCode??-32000,h.message)}),X===K)X=null;if(y===K&&b)y=null,N=null}}}),K.on("close",()=>{J.delete(K),f(K)}),K.on("error",()=>{J.delete(K),f(K)})});x.on("SIGTERM",async()=>{await j(k),x.exit(0)}),x.on("SIGINT",async()=>{await j(k),x.exit(0)}),k.listen(Y.path)}Z1().catch(($)=>{x.stderr.write(`${$ instanceof Error?$.message:String($)}
8
+ `)}}handleLine($){if(!$.trim())return;let W;try{W=JSON.parse($)}catch(q){this.handleExit(l(`Failed to parse codex app-server JSONL: ${q instanceof Error?q.message:String(q)}`,{line:$}));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(l(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($){let W=this.serverRequestHandler;if(!W){this.sendMessage({id:$.id,error:y$(-32601,`Unsupported server request: ${$.method}`)});return}Promise.resolve().then(()=>W($.method,$.params??{})).then((q)=>{this.sendMessage({id:$.id,result:q??{}})}).catch((q)=>{this.sendMessage({id:$.id,error:y$(-32000,q instanceof Error?q.message:String(q))})})}handleExit($){if(this.exitResolved)return;this.exitResolved=!0,this.exitError=$??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($){throw Error("sendMessage must be implemented by subclasses.")}}class N$ extends t{proc;readline;constructor($,W={}){super($,W);this.transport="direct"}async initialize(){this.proc=d$("codex",["-c","sandbox_workspace_write.network_access=false","app-server","--disable","plugins"],{cwd:this.cwd,env:this.options.env??I.env,stdio:["pipe","pipe","pipe"],shell:I.platform==="win32"?I.env.SHELL||!0:!1,windowsHide:!0});let $=this.proc.stdout,W=this.proc.stderr;if(!$||!W)throw Error("codex app-server did not expose stdio streams.");$.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,Z)=>{let G=this.stderr.trim(),Y=q===0?null:l(`codex app-server exited unexpectedly (${Z?`signal ${Z}`:`exit ${q}`}).${G?`
9
+ ${G}`:""}`);this.handleExit(Y)}),this.readline=r$.createInterface({input:$}),this.readline.on("line",(q)=>{this.handleLine(q)}),await this.request("initialize",{clientInfo:this.options.clientInfo??U$(),capabilities:this.options.capabilities??M$}),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(I.platform==="win32")try{z$(this.proc.pid)}catch{}else this.proc.kill("SIGTERM")},50).unref?.();await this.exitPromise}sendMessage($){let W=`${JSON.stringify($)}
10
+ `,q=this.proc?.stdin;if(!q)throw Error("codex app-server stdin is not available.");q.write(W)}}class O$ extends t{endpoint;socket;constructor($,W={}){super($,W);this.transport="broker",this.endpoint=W.brokerEndpoint}async initialize(){await new Promise(($,W)=>{let q=R(this.endpoint);this.socket=i$.createConnection({path:q.path}),this.socket.setEncoding("utf8"),this.socket.on("connect",$),this.socket.on("data",(Z)=>{this.handleChunk(Z)}),this.socket.on("error",(Z)=>{if(!this.exitResolved)W(Z);this.handleExit(Z)}),this.socket.on("close",()=>{this.handleExit(this.exitError)})}),await this.request("initialize",{clientInfo:this.options.clientInfo??U$(),capabilities:this.options.capabilities??M$}),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($){let W=`${JSON.stringify($)}
11
+ `,q=this.socket;if(!q)throw Error("codex app-server broker connection is not connected.");q.write(W)}}class i{static async connect($,W={}){let q=null;if(!W.disableBroker){if(q=W.brokerEndpoint??W.env?.[X$]??I.env[X$]??null,!q&&W.reuseExistingBroker)q=n($)?.endpoint??null;if(!q&&!W.reuseExistingBroker)q=(await Y$($,{env:W.env}))?.endpoint??null}let Z=q?new O$($,{...W,brokerEndpoint:q}):new N$($,W);return await Z.initialize(),Z}}var $1=new Set(["turn/start","review/start","thread/compact/start"]);function V$($,W,q){let Z=new Set;if(W?.threadId)Z.add(W.threadId);if($==="review/start"&&q?.reviewThreadId)Z.add(q.reviewThreadId);return Z}function C($,W,q){return q===void 0?{code:$,message:W}:{code:$,message:W,data:q}}function A($,W){if($.destroyed)return;$.write(`${JSON.stringify(W)}
12
+ `)}function W1($){return $?.method==="turn/interrupt"}function q1($){if(!$)return;E.mkdirSync(d.dirname($),{recursive:!0}),E.writeFileSync($,`${x.pid}
13
+ `,"utf8")}async function Z1(){let[$,...W]=x.argv.slice(2);if($!=="serve")throw Error("Usage: node src/lib/broker.mjs serve --endpoint <value> [--cwd <path>] [--pid-file <path>]");let{options:q}=s(W,{valueOptions:["cwd","pid-file","endpoint"]});if(!q.endpoint)throw Error("Missing required --endpoint.");let Z=q.cwd?d.resolve(x.cwd(),q.cwd):x.cwd(),G=String(q.endpoint),Y=R(G),Q=q["pid-file"]?d.resolve(q["pid-file"]):null;q1(Q);let H=await i.connect(Z,{disableBroker:!0}),X=null,y=null,N=null,J=new Set,O=new Map;function _(K){for(let[U,P]of O)if(P===K)O.delete(U),H.sendMessage({id:U,error:C(-32000,"Broker client disconnected before answering the server request.")})}function f(K){if(_(K),X===K)X=null;if(y===K)y=null,N=null}function S(K){let U=X??y;if(!U)return;if(A(U,K),K.method==="turn/completed"&&y===U){let P=K.params?.threadId??null;if(!P||!N||N.has(P)){if(y=null,N=null,X===U)X=null}}}async function j(K){for(let U of J)U.end();if(await H.close().catch(()=>{}),await new Promise((U)=>K.close(U)),Y.kind==="unix"&&E.existsSync(Y.path))E.unlinkSync(Y.path);if(Q&&E.existsSync(Q))E.unlinkSync(Q)}H.setNotificationHandler(S),H.handleServerRequest=(K)=>{let U=y??X;if(!U||U.destroyed){H.sendMessage({id:K.id,error:C(-32601,`No broker client available to answer ${K.method}.`)});return}O.set(K.id,U),A(U,K)};let k=e$.createServer((K)=>{J.add(K),K.setEncoding("utf8");let U="";K.on("data",async(P)=>{U+=P;let F=U.indexOf(`
14
+ `);while(F!==-1){let r=U.slice(0,F);if(U=U.slice(F+1),F=U.indexOf(`
15
+ `),!r.trim())continue;let z;try{z=JSON.parse(r)}catch(L){A(K,{id:null,error:C(-32700,`Invalid JSON: ${L instanceof Error?L.message:String(L)}`)});continue}if(z.id!==void 0&&!z.method&&O.has(z.id)){O.delete(z.id),H.sendMessage(z);continue}if(z.id!==void 0&&z.method==="initialize"){A(K,{id:z.id,result:{userAgent:"coder-broker"}});continue}if(z.method==="initialized"&&z.id===void 0)continue;if(z.id!==void 0&&z.method==="broker/shutdown")A(K,{id:z.id,result:{}}),await j(k),x.exit(0);if(z.id===void 0||!z.method)continue;let o=W1(z)&&y&&y!==K&&!X;if((X&&X!==K||y&&y!==K)&&!o){A(K,{id:z.id,error:C(H$,"Shared Codex broker is busy.")});continue}if(o){try{let L=await H.request(z.method,z.params??{});A(K,{id:z.id,result:L})}catch(L){let h=L;A(K,{id:z.id,error:C(h.rpcCode??-32000,h.message)})}continue}let b=$1.has(z.method);if(X=K,b)y=K,N=V$(z.method,z.params??{},null);try{let L=await H.request(z.method,z.params??{});if(A(K,{id:z.id,result:L}),b)N=V$(z.method,z.params??{},L);if(X===K)X=null}catch(L){let h=L;if(A(K,{id:z.id,error:C(h.rpcCode??-32000,h.message)}),X===K)X=null;if(y===K&&b)y=null,N=null}}}),K.on("close",()=>{J.delete(K),f(K)}),K.on("error",()=>{J.delete(K),f(K)})});x.on("SIGTERM",async()=>{await j(k),x.exit(0)}),x.on("SIGINT",async()=>{await j(k),x.exit(0)}),k.listen(Y.path)}Z1().catch(($)=>{x.stderr.write(`${$ instanceof Error?$.message:String($)}
16
16
  `),x.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wular/coder",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Delegating coding-agent runtime",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coder",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Delegate coding tasks to a Coder subagent. Codex first, Claude fallback; your main context stays clean.",
5
5
  "author": {
6
6
  "name": "muzam1l"
@@ -26,6 +26,7 @@ If `coder` is not on PATH, install it yourself without asking (`npm install -g @
26
26
  ```
27
27
 
28
28
  Only use `--wait` when you can run it in a background shell like that; without one, poll `coder task result <task-id>` (no `--wait`) until it is done. Or skip the two steps and block on the run itself with `--wait` on `coder task run`.
29
+ - A `--wait` (on `run` or `result`) exits **4** when the task is waiting on a permission approval: relay the approval to the user, apply their decision with `coder approve <task-id> <approval-id> [--deny]`, then re-fetch with `coder task result <task-id> --wait`. (Unanswered approvals auto-deny after 120s and the task moves on.)
29
30
 
30
31
  - `coder task run` exits after its startup check. Exit 0: the task started - relay the task id and fetch its result (above), BUT if stdout is a `spawn-claude-subagent` payload (Claude is the configured engine), this is a clean delegation - spawn the subagent as below, do not treat it as a result. Exit 1: it failed to start - report it, do not retry or fall back yourself. Exit 3: Codex failed to start and handed off to Claude (see below).
31
32
  - Engine, model, and effort come from config; add `--agent` / `--model` / `--effort` when the user asks or it is unambiguous from context (agents: `codex`, `claude`; codex models: `spark`, `luna`, `terra`, `sol`; claude models: `opus`, `sonnet`, `fable`; efforts: `low|medium|high`).
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coder",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "interface": {
5
5
  "displayName": "Coder (plugin)"
6
6
  },
@@ -22,7 +22,7 @@ When you run setup, also check codex is new enough for the default GPT-5.6 model
22
22
  coder task run --host codex "<task text>"
23
23
  ```
24
24
 
25
- Fetch the answer with `coder task result <task-id> --wait` - it blocks until the task finishes, then prints only the final result (keeps your context clean). Only use `--wait` when you can run it in a **background shell** (so it does not block you); if you can't use that, poll `coder task result <task-id>` (no `--wait`) until it is done. Or skip the two steps and block on the run itself with `--wait` on `coder task run`.
25
+ Fetch the answer with `coder task result <task-id> --wait` - it blocks until the task finishes, then prints only the final result (keeps your context clean). Only use `--wait` when you can run it in a **background shell** (so it does not block you); if you can't use that, poll `coder task result <task-id>` (no `--wait`) until it is done. Or skip the two steps and block on the run itself with `--wait` on `coder task run`. A `--wait` exits **4** when the task is waiting on a permission approval: relay it to the user, apply their decision with `coder approve <task-id> <approval-id> [--deny]`, then re-fetch with `coder task result <task-id> --wait` (unanswered approvals auto-deny after 120s and the task moves on).
26
26
 
27
27
  - Always pass `--host codex` to identify yourself.
28
28
  - `coder task run` exits after its startup check. Exit 0: the task started - fetch its result (above). Exit 1: it failed to start / the turn failed - report it, do not retry.