coding-agents-sdk 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +74 -9
  2. package/dist/Agent-BjaeRtLk.mjs +4 -0
  3. package/dist/adapters/claude-code-cli/index.d.mts +2 -2
  4. package/dist/adapters/claude-code-cli/index.mjs +1 -1
  5. package/dist/adapters/claude-code-cli-pty/index.d.mts +2 -2
  6. package/dist/adapters/claude-code-cli-pty/index.mjs +2 -2
  7. package/dist/adapters/claude-code-sdk/index.d.mts +1 -1
  8. package/dist/adapters/claude-code-sdk/index.mjs +1 -1
  9. package/dist/adapters/codex-cli/index.d.mts +2 -2
  10. package/dist/adapters/codex-cli/index.mjs +2 -2
  11. package/dist/adapters/codex-sdk/index.d.mts +1 -1
  12. package/dist/adapters/cursor-cli/index.d.mts +1 -1
  13. package/dist/adapters/cursor-cli/index.mjs +1 -1
  14. package/dist/adapters/cursor-sdk/index.d.mts +1 -1
  15. package/dist/adapters/gemini-cli/index.d.mts +1 -1
  16. package/dist/adapters/gemini-cli/index.mjs +1 -1
  17. package/dist/adapters/opencode-cli/index.d.mts +1 -1
  18. package/dist/adapters/opencode-cli/index.mjs +1 -1
  19. package/dist/adapters/pi-cli/index.d.mts +1 -1
  20. package/dist/adapters/pi-cli/index.mjs +1 -1
  21. package/dist/container/index.d.mts +1 -1
  22. package/dist/container/index.mjs +1 -1
  23. package/dist/{container-B2i85Vkf.mjs → container-Bdb90GJb.mjs} +1 -1
  24. package/dist/{container-Dk4QgU9G.mjs → container-DMFxf-kn.mjs} +1 -1
  25. package/dist/{container-CbvaYn8K.mjs → container-Dvr-p53c.mjs} +1 -1
  26. package/dist/{container-BwDinlQ1.mjs → container-dCRMBvQw.mjs} +1 -1
  27. package/dist/container-w0rl1QMH.mjs +1 -0
  28. package/dist/core/process/index.d.mts +3 -0
  29. package/dist/core/process/index.mjs +1 -0
  30. package/dist/diff-Dqyk2cdt.mjs +1 -0
  31. package/dist/errors-aYGbvsaq.mjs +1 -0
  32. package/dist/index-65Dv7ed0.d.mts +415 -0
  33. package/dist/{index-gtpzhLCF.d.mts → index-BbZPkmE-.d.mts} +4 -3
  34. package/dist/{index-C09YdI2A.d.mts → index-Bi9Dh34t.d.mts} +4 -4
  35. package/dist/{index-D3yvIIre.d.mts → index-BiUoRRsR.d.mts} +4 -3
  36. package/dist/{index-CT-rhJzK.d.mts → index-CN0WGc9T.d.mts} +3 -2
  37. package/dist/{index-BXgvYZSv.d.mts → index-CQzF8Cli.d.mts} +1 -1
  38. package/dist/{index-CGGPY1qE.d.mts → index-CZbgTv8P.d.mts} +1 -1
  39. package/dist/{index-Dm9HCmWK.d.mts → index-CjjUmMwQ.d.mts} +1 -1
  40. package/dist/{index-DGY0wFGC.d.mts → index-CyIiBK-O.d.mts} +130 -4
  41. package/dist/{index-D_qqPXPO.d.mts → index-DmpVdnKm.d.mts} +4 -3
  42. package/dist/index-DvwVRB7K.d.mts +10 -0
  43. package/dist/{index-WaVqMCYN.d.mts → index-kXfBtyJn.d.mts} +2 -1
  44. package/dist/{index-BkIhoEPd.d.mts → index-m5Pqs8Jz.d.mts} +4 -3
  45. package/dist/index.d.mts +16 -14
  46. package/dist/index.mjs +1 -1
  47. package/dist/oci-DTNwW-WH.mjs +1 -0
  48. package/dist/{parser-15-5gbtk.mjs → parser-C1kvDtRD.mjs} +1 -1
  49. package/dist/sandbox/index.d.mts +1 -1
  50. package/dist/sandbox/index.mjs +1 -1
  51. package/dist/{sandbox-CoV-gBuM.mjs → sandbox-CYA69miM.mjs} +1 -1
  52. package/dist/spawner-CgfyvnR4.mjs +1 -0
  53. package/dist/{types-CeIQCAFV.d.mts → types-Ba2NYJOB.d.mts} +10 -57
  54. package/dist/types-COmjfh8B.d.mts +57 -0
  55. package/package.json +15 -11
  56. package/dist/Agent-mSH_-Sf8.mjs +0 -4
  57. package/dist/container-DfDs2Bmh.mjs +0 -1
  58. package/dist/diff-C60ujrU_.mjs +0 -1
  59. package/dist/index-fZiuDQFa.d.mts +0 -154
  60. package/dist/oci-BvdPJQRS.mjs +0 -1
  61. package/dist/spawner-BE2hAC0w.mjs +0 -1
@@ -1 +0,0 @@
1
- import{t as e}from"./util-B4HTdOSc.mjs";import{c as t,i as n,n as r,r as i,s as a}from"./container-Dk4QgU9G.mjs";import{t as o}from"./shell-DvWFuFKb.mjs";import{n as s}from"./diff-C60ujrU_.mjs";import{basename as c,dirname as l,join as u,posix as d}from"node:path";import{mkdir as f,readFile as p,readdir as m,stat as h,writeFile as g}from"node:fs/promises";import{CommandExitError as _,FileType as v,Sandbox as y}from"e2b";const b=(e,t)=>[e,...t].map(o).join(` `),x=e=>e.user,S=(e,t)=>{let n={...e.env,...t};return Object.keys(n).length>0?n:void 0},C=(e,t)=>t??e.workdir,w=new TextEncoder,T=e=>e instanceof Error?e:Error(String(e)),E=e=>typeof e==`string`?e:`SIGKILL`,D=(e,t)=>{let n=e?.stdio?.[t];return n===`ignore`||n===`inherit`||n===`pipe`?n:n===void 0?`pipe`:`ignore`},O=()=>{let e=[],t=[],n=!1,r,i=()=>{for(;t.length>0&&e.length>0;)t.shift().resolve({done:!1,value:e.shift()});if(r){for(;t.length>0;)t.shift().reject(r);return}if(n)for(;t.length>0;)t.shift().resolve({done:!0,value:void 0})};return{iterable:{async*[Symbol.asyncIterator](){for(;;){if(e.length>0){yield e.shift();continue}if(r)throw T(r);if(n)return;let i=await new Promise((e,n)=>{t.push({resolve:e,reject:n})});if(i.done)return;yield i.value}}},push(t){t.length===0||n||r||(e.push(w.encode(t)),i())},end(){n||r||(n=!0,i())},fail(e){n||r||(r=e,i())}}},k=(e,t)=>({spawn:(n,r,i={})=>{let a=D(i,0),o=D(i,1),s=D(i,2),c=o===`pipe`?O():void 0,l=s===`pipe`?O():void 0,u=null,d={background:!0,stdin:a===`pipe`,cwd:C(t,i.cwd),envs:S(t,i.env),user:x(t),requestTimeoutMs:t.requestTimeoutMs,onStdout:e=>{if(o===`inherit`){process.stdout.write(e);return}c?.push(e)},onStderr:e=>{if(s===`inherit`){process.stderr.write(e);return}l?.push(e)}},f=e.commands.run(b(n,r),d);return f.catch(e=>{c?.fail(e),l?.fail(e)}),{stdout:c?.iterable??null,stderr:l?.iterable??null,stdin:a===`pipe`?{write:n=>{f.then(r=>{e.commands.sendStdin(r.pid,n,{requestTimeoutMs:t.requestTimeoutMs})}).catch(()=>{})},end:()=>{f.then(n=>{e.commands.closeStdin(n.pid,{requestTimeoutMs:t.requestTimeoutMs})}).catch(()=>{})}}:null,kill:e=>{u=E(e),f.then(e=>e.kill()).catch(()=>{})},wait:async()=>{try{let e=await(await f).wait();return c?.end(),l?.end(),u?{exitCode:null,signal:u}:{exitCode:e.exitCode,signal:null}}catch(e){if(c?.end(),l?.end(),e instanceof _)return u?{exitCode:null,signal:u}:{exitCode:e.exitCode,signal:null};throw e}}}}}),A=e=>({apiKey:e.apiKey,domain:e.domain,requestTimeoutMs:e.requestTimeoutMs,apiHeaders:e.headers}),j=e=>`sandboxId`in e&&typeof e.sandboxId==`string`,M=e=>{let t=A(e);return j(e)?t:{...t,envs:e.env,timeoutMs:e.timeoutMs,metadata:e.metadata,secure:e.secure,allowInternetAccess:e.allowInternetAccess,network:e.network,lifecycle:e.lifecycle}},N=async(e,t)=>{await e.files.makeDir(t.workdir,{user:x(t)})},P=e=>e instanceof Error&&e.name===`AbortError`,F=e=>Uint8Array.from(e).buffer,I=e=>{let t=e.endsWith(`/`)&&e!==`/`?e.slice(0,-1):e;return d.basename(t)},L=async e=>{try{return await h(e)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}},R=async(e,t,n)=>{if(await e.files.exists(t,{user:n}))return e.files.getInfo(t,{user:n})},z=async(e,t,n,r)=>(await R(e,n,r))?.type===v.DIR?d.join(n,c(t)):n,B=async(e,t)=>(await L(t))?.isDirectory()?u(t,I(e)):t,V=async(e,t,n,r)=>{let i=await h(t);if(i.isDirectory()){await e.files.makeDir(n,{user:r});let i=await m(t);await Promise.all(i.map(i=>V(e,u(t,i),d.join(n,i),r)));return}if(!i.isFile())throw Error(`Unsupported local filesystem entry at ${t}.`);let a=await p(t);await e.files.write(n,F(a),{user:r})},H=async(e,t,n,r)=>{if((await e.files.getInfo(t,{user:r})).type===v.DIR){await f(n,{recursive:!0});let i=await e.files.list(t,{user:r});await Promise.all(i.map(t=>H(e,t.path,u(n,t.name),r)));return}let i=await e.files.read(t,{format:`bytes`,user:r});await f(l(n),{recursive:!0}),await g(n,i)},U=async e=>{if(j(e))return y.connect(e.sandboxId,A(e));let t=M(e);return e.template?y.create(e.template,t):y.create(t)},W=async(e,t)=>e.connect(A(t)),G=async(e,t)=>{let n=t.signal;if(n?.aborted){let e=n.reason;throw e instanceof Error?e:new DOMException(`The operation was aborted.`,`AbortError`)}let r=!1,i=()=>{r=!0,e.kill()};n?.addEventListener(`abort`,i,{once:!0});try{let t=await e.wait();if(r)throw new DOMException(`The operation was aborted.`,`AbortError`);return{exitCode:t.exitCode,stdout:t.stdout,stderr:t.stderr}}catch(e){if(r||P(e))throw new DOMException(`The operation was aborted.`,`AbortError`);if(e instanceof _)return{exitCode:e.exitCode,stdout:e.stdout,stderr:e.stderr};throw e}finally{n?.removeEventListener(`abort`,i)}},K=async o=>{let c;try{c=await U(o),await N(c,o)}catch(t){throw new r(`E2B create failed: ${e(t)}`)}let l=o.name??c.sandboxId,d=`running`,p=k(c,o),m={},h=()=>{if(d===`disposed`)throw new n},g=()=>{if(h(),d!==`running`)throw new a},_=s({owner:m,workdir:o.workdir,materialize:async(e,t)=>{g();let n=x(o),r=await R(c,e,n);if(!r)throw new i(`Target path does not exist: ${e}`);if(r.type!==v.DIR)throw new i(`Target path is not a directory: ${e}`);await f(t,{recursive:!0});for(let r of await c.files.list(e,{user:n}))await H(c,r.path,u(t,r.name),n)}}),y={get type(){return`e2b`},get id(){return c.sandboxId},get name(){return l},get config(){return o},get status(){return d},get workdir(){return o.workdir},get spawner(){return p},async start(){if(h(),d!==`running`)try{c=await W(c,o),await N(c,o),p=k(c,o),d=`running`}catch(n){throw new t(`E2B start failed: ${e(n)}`)}},async stop(){h(),d===`running`&&(await c.pause({requestTimeoutMs:o.requestTimeoutMs}),d=`stopped`)},async dispose(){if(d!==`disposed`){try{await c.kill({requestTimeoutMs:o.requestTimeoutMs})}catch{}await _.disposeSnapshots().catch(()=>{}),d=`disposed`}},async exec(e,t,n={}){g();let r={background:!0,cwd:C(o,n.cwd),envs:S(o,n.env),user:x(o),timeoutMs:n.timeoutMs,requestTimeoutMs:o.requestTimeoutMs},i=await c.commands.run(b(e,t),r);return G(i,n)},async copyTo(e,t){g();let n=await z(c,e,t,x(o));await V(c,e,n,x(o))},async copyFrom(e,t){g();let n=await B(e,t);await H(c,e,n,x(o))},async writeFile(e,t){g(),await c.files.write(e,typeof t==`string`?t:F(t),{user:x(o)})},async readFile(e){return g(),c.files.read(e,{format:`text`,user:x(o)})},async fileExists(e){return g(),c.files.exists(e,{user:x(o)})},async mkdir(e){g(),await c.files.makeDir(e,{user:x(o)})},async execShell(e,t={}){return y.exec(`sh`,[`-c`,e],t)},async logs(){return``},async syncStatus(){return d},async snapshotWorkdir(e={}){return _.snapshotWorkdir(e)},async diffWorkdir(e){return _.diffWorkdir(e)},async releaseWorkdirSnapshot(e){return _.releaseWorkdirSnapshot(e)},getHost(e){return g(),c.getHost(e)},[Symbol.asyncDispose](){return y.dispose()}};return y};export{K as createE2BContainer};
@@ -1 +0,0 @@
1
- import{t as e}from"./util-B4HTdOSc.mjs";import{i as t,r as n,s as r}from"./container-Dk4QgU9G.mjs";import{execFile as i}from"node:child_process";import{dirname as a,isAbsolute as o,join as s,posix as c,relative as l,sep as u}from"node:path";import{promisify as d}from"node:util";import{createReadStream as f}from"node:fs";import{tmpdir as p}from"node:os";import{copyFile as m,lstat as h,mkdir as g,mkdtemp as _,readdir as v,readlink as y,rm as b,stat as x,symlink as S}from"node:fs/promises";import{createHash as C}from"node:crypto";import{pipeline as w}from"node:stream/promises";const T=e=>e instanceof Error&&`code`in e&&(`stdout`in e||`stderr`in e),E=d(i),D=e=>e!==`..`&&!e.startsWith(`..${u}`)&&!o(e),O=(e,t)=>{let n=l(e,t);if(D(n))return n.split(u).join(c.sep)},k=(e,t,r)=>{let i=O(t,e);if(i!==void 0)return i;let a=O(r,e);if(a!==void 0)return a;throw new n(`Git diff produced a path outside the materialized trees: ${e}`)},A=e=>e.sort((e,t)=>e.path===t.path?(e.previousPath??``).localeCompare(t.previousPath??``):e.path.localeCompare(t.path)),j=async e=>{let t=await v(e,{withFileTypes:!0});for(let n of t){let t=s(e,n.name);if(n.name===`.git`){await b(t,{recursive:!0,force:!0});continue}n.isDirectory()&&await j(t)}},M=()=>_(s(p(),`cw-workdir-diff-`)),N=async e=>{e&&await b(e,{recursive:!0,force:!0}).catch(()=>{})},P=(e,t)=>{let n={cwd:e.cwd,createdAt:/* @__PURE__ */ new Date};return t.set(n,e),n},F=(e,t,r)=>{if(typeof t!=`object`||!t)throw new n(`Invalid workdir snapshot.`);let i=r.get(t);if(!i)throw new n(`Invalid workdir snapshot.`);if(i.owner!==e)throw new n(`Workdir snapshot was created by a different container instance.`);return i},I=(e,t)=>{if(!t.has(e))throw new n(`Workdir snapshot has been released.`)},L=e=>C(`sha256`).update(e).digest(`hex`),R=e=>Buffer.isBuffer(e)?e:Buffer.from(e,`utf8`),z=async e=>{let t=C(`sha256`);return await w(f(e),t),t.digest(`hex`)},B=async(e,t,r)=>{let i=`${e}:${t}`;if(r.has(i))return r.get(i);let a=s(e,...t.split(c.sep));try{let e=await h(a),t,o;if(e.isSymbolicLink()){let e=Buffer.from(await y(a));t=L(e),o=e.byteLength}else if(e.isFile())t=await z(a),o=e.size;else throw new n(`Unsupported filesystem entry in diff metadata: ${a}`);let s={hash:t,size:o};return r.set(i,s),s}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`){r.set(i,void 0);return}throw e}},V=(e,t,r)=>{if(e.byteLength===0)return[];let i=e.toString(`utf8`).split(`\0`);i[i.length-1]===``&&i.pop();let a=[];for(let e=0;e<i.length;){let o=i[e++];if(!o)continue;if(o.startsWith(`R`)){let o=i[e++],s=i[e++];if(!o||!s)throw new n(`Failed to parse git rename entry.`);a.push({kind:`renamed`,previousPath:k(o,t,r),path:k(s,t,r)});continue}let s=i[e++];if(!s)throw new n(`Failed to parse git diff entry.`);switch(o){case`A`:a.push({kind:`added`,path:k(s,t,r)});break;case`D`:a.push({kind:`deleted`,path:k(s,t,r)});break;case`M`:a.push({kind:`modified`,path:k(s,t,r)});break;case`T`:a.push({kind:`modified`,path:k(s,t,r)});break;default:throw new n(`Unsupported git diff change kind: ${o}`)}}return a},H=async(t,r)=>{try{let e=await E(`git`,[`diff`,`--no-index`,`-z`,`--name-status`,`-M`,`--find-renames=100%`,t,r],{cwd:p(),encoding:`buffer`,maxBuffer:52428800});return V(R(e.stdout),t,r)}catch(i){if(!T(i))throw new n(`Failed to run git diff: ${e(i)}`);let a=i.code??1,o=Buffer.isBuffer(i.stdout)?i.stdout:Buffer.from(String(i.stdout??``),`utf8`),s=Buffer.isBuffer(i.stderr)?i.stderr:Buffer.from(String(i.stderr??``),`utf8`);if(a===0||a===1)return V(o,t,r);let c=s.toString(`utf8`).trim()||o.toString(`utf8`).trim()||`exit code ${a}`;throw new n(`Failed to run git diff: ${c}`)}},U=async(e,t,n)=>{let r=/* @__PURE__ */ new Map,i=await Promise.all(e.map(async e=>{let i;i=e.kind===`added`?void 0:e.kind===`renamed`?e.previousPath:e.path;let a=e.kind===`deleted`?void 0:e.path,[o,s]=await Promise.all([i===void 0?void 0:B(t,i,r),a===void 0?void 0:B(n,a,r)]);return{path:e.path,previousPath:e.previousPath,kind:e.kind,beforeHash:o?.hash,afterHash:s?.hash,beforeSize:o?.size,afterSize:s?.size}}));return A(i)},W=e=>{let t=/* @__PURE__ */ new Set;for(let n of e)t.add(n.path),n.kind===`renamed`&&n.previousPath&&t.add(n.previousPath);return[...t].sort((e,t)=>e.localeCompare(t))},G=(i,a)=>{throw a instanceof n||a instanceof t||a instanceof r?a:new n(`${i}: ${e(a)}`)},K=async(e,t)=>{if(!(await x(e)).isDirectory())throw new n(`Target path is not a directory: ${e}`);await g(t,{recursive:!0});let r=await v(e,{withFileTypes:!0});await Promise.all(r.filter(e=>e.name!==`.git`).map(async r=>{let i=s(e,r.name),o=s(t,r.name);if(r.isDirectory()){await K(i,o);return}if(r.isSymbolicLink()){await g(a(o),{recursive:!0}),await S(await y(i),o);return}if(r.isFile()){await g(a(o),{recursive:!0}),await m(i,o);return}throw new n(`Unsupported filesystem entry in workdir diff: ${i}`)}))},q=e=>{let t=/* @__PURE__ */ new Set,n=/* @__PURE__ */ new WeakMap,r=async(r={})=>{let i=r.cwd??e.workdir,a;try{a=await M(),await e.materialize(i,a),await j(a);let r={owner:e.owner,tempDir:a,cwd:i,inFlightDiffs:0,released:!1};return t.add(r),a=void 0,P(r,n)}catch(e){return await N(a),G(`Failed to materialize workdir snapshot`,e)}},i=async r=>{let i=Date.now(),a=F(e.owner,r,n);I(a,t),a.inFlightDiffs++;let o;try{o=await M(),await e.materialize(a.cwd,o),await j(o);let t=await H(a.tempDir,o),n=await U(t,a.tempDir,o),r=W(n);return{cwd:a.cwd,changedFiles:r,fileChanges:n,stats:{durationMs:Date.now()-i,filesCompared:r.length}}}catch(e){return G(`Failed to diff workdir snapshot`,e)}finally{a.inFlightDiffs--,a.inFlightDiffs===0&&(a.resolveIdle?.(),a.resolveIdle=void 0),await N(o)}},a=e=>{let n=e;return n.releasePromise?n.releasePromise:(n.released=!0,t.delete(n),n.releasePromise=(async()=>{n.inFlightDiffs>0&&await new Promise(e=>{n.resolveIdle=e}),await N(n.tempDir)})(),n.releasePromise)};return{snapshotWorkdir:r,diffWorkdir:i,releaseWorkdirSnapshot:async t=>{let r=F(e.owner,t,n);await a(r)},disposeSnapshots:async()=>{await Promise.all(Array.from(t).map(a))}}};export{q as n,T as r,K as t};
@@ -1,154 +0,0 @@
1
- import { S as McpServerConfig } from "./events-BxEB6zHt.mjs";
2
- import { f as EnsureDisjoint, k as ProcessSpawner, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-CeIQCAFV.mjs";
3
- import { t as Container } from "./index-WaVqMCYN.mjs";
4
- import { l as Sandbox } from "./index-CT-rhJzK.mjs";
5
- import { z } from "zod/v4";
6
- //#region src/adapters/codex-cli/events/schemas.d.ts
7
- /**
8
- * Permissive shape for any raw event Codex CLI emits — `{ type: string }`
9
- * plus arbitrary additional fields. Narrow on `event.type` against the
10
- * specific exported event types (`CodexThreadStartedEvent`,
11
- * `CodexTurnCompletedEvent`, `CodexItemStartedEvent`, etc.) when you need
12
- * field-level access.
13
- */
14
- declare const codexEventSchema: z.ZodObject<{
15
- type: z.ZodString;
16
- }, z.core.$loose>;
17
- type CodexEvent = z.infer<typeof codexEventSchema>;
18
- declare const codexThreadStartedEventSchema: z.ZodObject<{
19
- type: z.ZodLiteral<"thread.started">;
20
- thread_id: z.ZodString;
21
- }, z.core.$loose>;
22
- type CodexThreadStartedEvent = z.infer<typeof codexThreadStartedEventSchema>;
23
- declare const codexTurnCompletedEventSchema: z.ZodObject<{
24
- type: z.ZodLiteral<"turn.completed">;
25
- usage: z.ZodOptional<z.ZodObject<{
26
- input_tokens: z.ZodOptional<z.ZodNumber>;
27
- cached_input_tokens: z.ZodOptional<z.ZodNumber>;
28
- cache_write_input_tokens: z.ZodOptional<z.ZodNumber>;
29
- output_tokens: z.ZodOptional<z.ZodNumber>;
30
- reasoning_output_tokens: z.ZodOptional<z.ZodNumber>;
31
- total_tokens: z.ZodOptional<z.ZodNumber>;
32
- }, z.core.$loose>>;
33
- last_agent_message: z.ZodOptional<z.ZodString>;
34
- duration_ms: z.ZodOptional<z.ZodNumber>;
35
- num_turns: z.ZodOptional<z.ZodNumber>;
36
- }, z.core.$loose>;
37
- type CodexTurnCompletedEvent = z.infer<typeof codexTurnCompletedEventSchema>;
38
- declare const codexTurnFailedEventSchema: z.ZodObject<{
39
- type: z.ZodLiteral<"turn.failed">;
40
- usage: z.ZodOptional<z.ZodObject<{
41
- input_tokens: z.ZodOptional<z.ZodNumber>;
42
- cached_input_tokens: z.ZodOptional<z.ZodNumber>;
43
- cache_write_input_tokens: z.ZodOptional<z.ZodNumber>;
44
- output_tokens: z.ZodOptional<z.ZodNumber>;
45
- reasoning_output_tokens: z.ZodOptional<z.ZodNumber>;
46
- total_tokens: z.ZodOptional<z.ZodNumber>;
47
- }, z.core.$loose>>;
48
- last_agent_message: z.ZodOptional<z.ZodString>;
49
- duration_ms: z.ZodOptional<z.ZodNumber>;
50
- num_turns: z.ZodOptional<z.ZodNumber>;
51
- message: z.ZodOptional<z.ZodString>;
52
- error: z.ZodOptional<z.ZodUnknown>;
53
- }, z.core.$loose>;
54
- type CodexTurnFailedEvent = z.infer<typeof codexTurnFailedEventSchema>;
55
- declare const codexItemStartedEventSchema: z.ZodObject<{
56
- type: z.ZodLiteral<"item.started">;
57
- item: z.ZodObject<{
58
- id: z.ZodString;
59
- type: z.ZodString;
60
- }, z.core.$loose>;
61
- }, z.core.$loose>;
62
- type CodexItemStartedEvent = z.infer<typeof codexItemStartedEventSchema>;
63
- declare const codexItemUpdatedEventSchema: z.ZodObject<{
64
- type: z.ZodLiteral<"item.updated">;
65
- item: z.ZodObject<{
66
- id: z.ZodString;
67
- type: z.ZodString;
68
- }, z.core.$loose>;
69
- }, z.core.$loose>;
70
- type CodexItemUpdatedEvent = z.infer<typeof codexItemUpdatedEventSchema>;
71
- declare const codexItemCompletedEventSchema: z.ZodObject<{
72
- type: z.ZodLiteral<"item.completed">;
73
- item: z.ZodObject<{
74
- id: z.ZodString;
75
- type: z.ZodString;
76
- }, z.core.$loose>;
77
- }, z.core.$loose>;
78
- type CodexItemCompletedEvent = z.infer<typeof codexItemCompletedEventSchema>;
79
- declare const codexErrorEventSchema: z.ZodObject<{
80
- type: z.ZodLiteral<"error">;
81
- message: z.ZodOptional<z.ZodString>;
82
- error: z.ZodOptional<z.ZodUnknown>;
83
- }, z.core.$loose>;
84
- type CodexErrorEvent = z.infer<typeof codexErrorEventSchema>;
85
- //#endregion
86
- //#region src/adapters/codex-cli/types.d.ts
87
- /**
88
- * Filesystem sandbox policy for Codex CLI.
89
- * - `"read-only"`: tools cannot write.
90
- * - `"workspace-write"`: writes allowed inside `cwd` only.
91
- * - `"danger-full-access"`: no filesystem restrictions.
92
- */
93
- type CodexCliSandboxMode = "danger-full-access" | "read-only" | "workspace-write";
94
- /**
95
- * How Codex CLI handles approval prompts.
96
- * - `"default"`: leave Codex CLI's own default approval behavior in place (this adapter does not bridge approvals to a permission handler).
97
- * - `"auto-approve"`: pass `--approve-for-me`; Codex uses automatic review in the `workspace-write` sandbox.
98
- * - `"bypass-sandbox"`: pass `--dangerously-bypass-approvals-and-sandbox`; disable approvals and Codex's sandbox for externally isolated execution.
99
- */
100
- type CodexCliPermissionMode = "auto-approve" | "bypass-sandbox" | "default";
101
- /** Per-run options for the `codex-cli` adapter. */
102
- interface CodexCliRunOptions {
103
- /**
104
- * Filesystem sandbox policy for the default approval strategy.
105
- * Other permission modes select their own sandbox behavior.
106
- */
107
- sandboxMode?: CodexCliSandboxMode;
108
- /** Extra directories outside `cwd` writable under `workspace-write`. */
109
- additionalDirectories?: string[];
110
- /** Suppress Codex's "not a git repo" confirmation prompt (`--skip-git-repo-check`). */
111
- skipGitRepoCheck?: boolean;
112
- /** Approval prompt strategy. */
113
- permissionMode?: CodexCliPermissionMode;
114
- /** When `true`, Codex does not persist this run's history. */
115
- ephemeral?: boolean;
116
- /** Path to an MCP config file passed via `--mcp-config`. */
117
- mcpConfig?: string;
118
- /** Inline MCP server config map. */
119
- mcpServers?: Record<string, McpServerConfig>;
120
- /** Extra CLI flags appended verbatim. */
121
- extraArgs?: string[];
122
- /** Not supported — Codex manages its own system prompt. */
123
- systemPrompt?: never;
124
- }
125
- /** Constructor options for `createAgent("codex-cli", ...)`. */
126
- type CodexCliAgentOptions = CodexCliRunOptions & ExclusiveExecutionTargetOptions<Container, Sandbox> & {
127
- /** Path or argv to the `codex` binary. */
128
- command?: string[] | string;
129
- /** Working directory the agent operates against. */
130
- cwd?: string;
131
- /** Environment variables for the subprocess. Layered on top of host env when `propagateEnv` is `true` (default). */
132
- env?: Record<string, string>;
133
- /** Default `true`: `process.env` is inherited and `env` overlays it. Set `false` to suppress host-env propagation. */
134
- propagateEnv?: boolean;
135
- /** Existing Codex thread ID to resume via `codex resume`. */
136
- sessionId?: string;
137
- /** Codex model identifier. */
138
- model?: string;
139
- /** File path to write the raw CLI log to (useful for debugging). */
140
- logPath?: string;
141
- /** Custom process spawner; set by `createContainer`/`createSandbox`, rarely needed manually. */
142
- spawner?: ProcessSpawner;
143
- /** Convenience: equivalent to calling `agent.onEvent(handler)` post-construction. */
144
- onEvent?: AgentEventHandler;
145
- };
146
- /** Agent instance returned by `createAgent("codex-cli", ...)`. */
147
- interface CodexCliAgent extends BaseAgent<EnsureDisjoint<CodexCliRunOptions>> {
148
- readonly type: "codex-cli";
149
- }
150
- //#endregion
151
- //#region src/adapters/codex-cli/adapter.d.ts
152
- declare const createCodexCliAgent: (options?: CodexCliAgentOptions) => CodexCliAgent;
153
- //#endregion
154
- export { CodexCliRunOptions as a, CodexEvent as c, CodexItemUpdatedEvent as d, CodexThreadStartedEvent as f, CodexCliPermissionMode as i, CodexItemCompletedEvent as l, CodexTurnFailedEvent as m, CodexCliAgent as n, CodexCliSandboxMode as o, CodexTurnCompletedEvent as p, CodexCliAgentOptions as r, CodexErrorEvent as s, createCodexCliAgent as t, CodexItemStartedEvent as u };
@@ -1 +0,0 @@
1
- import{t as e}from"./util-B4HTdOSc.mjs";import{c as t,i as n,l as r,n as i,o as a,r as o,s}from"./container-Dk4QgU9G.mjs";import{n as c}from"./env-Cb8MIvH7.mjs";import{t as l}from"./spawner-BE2hAC0w.mjs";import{t as u}from"./shell-DvWFuFKb.mjs";import{n as d,r as f,t as p}from"./diff-C60ujrU_.mjs";import{execFile as m}from"node:child_process";import{isAbsolute as h,join as g,posix as _,resolve as v}from"node:path";import{promisify as y}from"node:util";import{existsSync as b}from"node:fs";import{tmpdir as x}from"node:os";import{mkdtemp as S,rm as C,writeFile as w}from"node:fs/promises";import{randomBytes as T}from"node:crypto";const E=(e,t)=>{let n=_.relative(e,t);return n===``||!n.startsWith(`..`)&&!_.isAbsolute(n)},D=(e,t)=>{if(!e||e.length===0)return;let n=_.normalize(t),r;for(let t of e){if(!h(t.source))continue;let e=_.normalize(t.target);E(e,n)&&(!r||e.length>_.normalize(r.target).length)&&(r=t)}if(!r)return;let i=_.relative(_.normalize(r.target),n);return i===``?r.source:_.join(r.source,...i.split(`/`))},O=(e,t)=>{let n=h(e.source)?e.source:v(t.cwd,e.source);if(!b(n))throw new r(`Mount source does not exist: ${n}`);return{...e,source:n}},k=y(m),A=()=>`cw-${T(6).toString(`hex`)}`,j=(e,t)=>e.baseArgs?[...e.baseArgs,...t]:t,M=e=>{if(e.env)return{...c(),...e.env}},N=async(e,t,n)=>{let r=await k(e.binary,j(e,t),{encoding:`utf8`,env:M(e),timeout:n?.timeoutMs,signal:n?.signal,maxBuffer:52428800});return{stdout:r.stdout,stderr:r.stderr}},P=async(t,n)=>{let r=n.tag??`cw-build-${T(4).toString(`hex`)}`,a=[`build`,`-t`,r];if(n.args)for(let[e,t]of Object.entries(n.args))a.push(`--build-arg`,`${e}=${t}`);`dockerfile`in n&&n.dockerfile&&(a.push(`-f`,n.dockerfile),a.push(n.context??`.`));let o;if(`content`in n&&n.content){o=await S(g(x(),`cw-oci-build-`));let e=g(o,`Dockerfile`);await w(e,n.content,{encoding:`utf8`,mode:384}),a.push(`-f`,e),a.push(n.context??o)}try{await N(t,a)}catch(t){throw new i(`Image build failed: ${e(t)}`)}finally{o&&await C(o,{recursive:!0,force:!0}).catch(()=>{})}return r},F=async(e,t,n)=>{let r=await Promise.all(n.map(async n=>{try{let{container:r,protocol:i=`tcp`}=n,{stdout:a}=await N(e,[`port`,t,`${r}/${i}`]),o=/:(\d+)$/m.exec(a.trim());if(o?.[1])return[r,Number(o[1])]}catch{}})),i=/* @__PURE__ */ new Map;for(let e of r)e&&i.set(e[0],e[1]);return i},I=(e,t)=>({spawn:(n,r,i={})=>{let a=[`exec`,`-i`];if(i.cwd&&a.push(`-w`,i.cwd),i.env)for(let[e,t]of Object.entries(i.env))a.push(`-e`,`${e}=${t}`);return a.push(e,n,...r),l.spawn(t.binary,j(t,a),{env:M(t),stdio:i.stdio})}}),L=async(r,c,m)=>{let{commandContext:h,builtImage:g,containerName:v,workdir:y,user:b,network:x,platform:S,env:C,ports:w,mounts:T,mountCwd:E,extraArgs:k,image:P}=c,L=v??A(),R=T?.map(e=>O(e,{cwd:E??process.cwd()})),z=[`create`,`--name`,L];if(b&&z.push(`--user`,b),x&&z.push(`--network`,x),S&&z.push(`--platform`,S),C)for(let[e,t]of Object.entries(C))z.push(`-e`,`${e}=${t}`);if(w)for(let e of w){let{host:t,container:n,protocol:r=`tcp`}=e;z.push(`-p`,`${t??``}:${n}/${r}`)}if(R)for(let e of R){let{readonly:t,source:n,target:r}=e,i=t?`ro`:`rw`;z.push(`-v`,`${n}:${r}:${i}`)}k&&z.push(...k),z.push(P,`sleep`,`infinity`);let B;try{let{stdout:e}=await N(h,z);B=e.trim()}catch(t){throw new i(`Container create failed: ${e(t)}`)}let V=`created`,H=/* @__PURE__ */ new Map,U=()=>{if(V===`disposed`)throw new n},W=()=>{if(U(),V!==`running`)throw new s},G=I(B,h),K=d({owner:{},workdir:y,materialize:async(t,n)=>{U();let r=D(R,t);if(r){await p(r,n);return}W();try{await N(h,[`exec`,B,`sh`,`-c`,`test -d ${u(t)}`])}catch{throw new o(`Target path is not a directory: ${t}`)}try{await N(h,[`cp`,`${B}:${t}/.`,n])}catch(n){throw new o(`Failed to materialize container path ${t}: ${e(n)}`)}}}),q={get type(){return r},get id(){return B},get name(){return L},get config(){return m},get status(){return V},get workdir(){return y},get spawner(){return G},async start(){if(U(),V!==`running`){try{await N(h,[`start`,B])}catch(n){throw new t(`Container start failed: ${e(n)}`)}try{await N(h,[`exec`,B,`mkdir`,`-p`,y])}catch(n){try{await N(h,[`stop`,`-t`,`0`,B]),V=`stopped`}catch{try{let{stdout:e}=await N(h,[`inspect`,`--format`,`{{.State.Status}}`,B]);V=e.trim()===`running`?`running`:`stopped`}catch{V=`disposed`}}throw new t(`Container start failed: ${e(n)}`)}V=`running`,w?.length&&(H=await F(h,B,w))}},async stop(){if(U(),V===`running`){try{await N(h,[`stop`,`-t`,`2`,B])}catch{try{let{stdout:e}=await N(h,[`inspect`,`--format`,`{{.State.Status}}`,B]);if(e.trim()===`running`)return}catch{V=`disposed`;return}}V=`stopped`}},async dispose(){if(V!==`disposed`){try{await N(h,[`stop`,`-t`,`0`,B])}catch{}try{await N(h,[`rm`,`-f`,B])}catch{}g&&await N(h,[`rmi`,P]).catch(()=>{}),await K.disposeSnapshots().catch(()=>{}),V=`disposed`}},async exec(e,t,n={}){W();let r=[`exec`];if(n.cwd&&r.push(`-w`,n.cwd),n.env)for(let[e,t]of Object.entries(n.env))r.push(`-e`,`${e}=${t}`);r.push(B,e,...t);try{let{stdout:e,stderr:t}=await N(h,r,{timeoutMs:n.timeoutMs,signal:n.signal});return{exitCode:0,stdout:e,stderr:t}}catch(e){if(f(e))return{exitCode:typeof e.code==`number`?e.code:-1,stdout:String(e.stdout??``),stderr:String(e.stderr??``)};throw e}},async copyTo(e,t){W(),await N(h,[`cp`,e,`${B}:${t}`])},async copyFrom(e,t){W(),await N(h,[`cp`,`${B}:${e}`,t])},async writeFile(t,n){W();let r=_.isAbsolute(t)?t:_.resolve(y,t),i=_.dirname(r),o=typeof n==`string`?Buffer.from(n,`utf8`):n,s=[`exec`,`-i`];b&&s.push(`--user`,b),s.push(B,`sh`,`-c`,`mkdir -p ${u(i)} && cat > ${u(r)}`);let c=l.spawn(h.binary,j(h,s),{env:M(h),stdio:[`pipe`,`ignore`,`ignore`]});try{c.stdin?.write?.(o),c.stdin?.end()}catch(t){throw c.kill(),c.wait().catch(()=>{}),new a(`writeFile failed for ${r}: ${e(t)}`)}let d=await c.wait();if(d.exitCode!==0)throw new a(`writeFile failed for ${r} (exit ${d.exitCode})`)},async readFile(e){W();let t=_.isAbsolute(e)?e:_.resolve(y,e),{stdout:n}=await N(h,[`exec`,B,`cat`,t]);return n},async fileExists(e){W();let t=_.isAbsolute(e)?e:_.resolve(y,e);try{return await N(h,[`exec`,B,`test`,`-e`,t]),!0}catch{return!1}},async mkdir(e){W();let t=_.isAbsolute(e)?e:_.resolve(y,e);await N(h,[`exec`,B,`mkdir`,`-p`,t])},async execShell(e,t={}){return q.exec(`sh`,[`-c`,e],t)},async logs(e={}){U();let t=[`logs`];e.tail!==void 0&&t.push(`--tail`,String(e.tail)),t.push(B);let{stdout:n}=await N(h,t);return n},async syncStatus(){U();try{let{stdout:e}=await N(h,[`inspect`,`--format`,`{{.State.Status}}`,B]),t=e.trim();V=t===`running`?`running`:t===`created`?`created`:`stopped`}catch{V=`disposed`}return V},async snapshotWorkdir(e={}){return K.snapshotWorkdir(e)},async diffWorkdir(e){return K.diffWorkdir(e)},async releaseWorkdirSnapshot(e){return K.releaseWorkdirSnapshot(e)},getMappedPort(e){return H.get(e)},[Symbol.asyncDispose](){return q.dispose()}};return q},R=async(e,t)=>{if(t.image)return t.image;if(t.build)return P(e,t.build);throw new i(`Either image or build must be provided.`)};export{R as n,L as t};
@@ -1 +0,0 @@
1
- import{spawn as e}from"node:child_process";const t=e=>({async*[Symbol.asyncIterator](){for await(let t of e){if(t instanceof Buffer){yield new Uint8Array(t);continue}if(typeof t==`string`){yield new TextEncoder().encode(t);continue}if(t instanceof Uint8Array){yield t;continue}throw Error(`Unsupported stdout/stderr chunk type: ${typeof t}`)}}}),n={spawn:(n,r,i={})=>{let a=e(n,r,{cwd:i.cwd,env:i.env,stdio:i.stdio,detached:!0});a.stdin?.on(`error`,()=>{});let o=new Promise((e,t)=>{let n=(t,n)=>{a.removeListener(`error`,r),e({exitCode:t,signal:n})},r=e=>{a.removeListener(`close`,n),t(e)};a.once(`error`,r),a.once(`close`,n)});return{stdout:a.stdout?t(a.stdout):null,stderr:a.stderr?t(a.stderr):null,stdin:a.stdin?{write:e=>a.stdin?.write(e),end:()=>a.stdin?.end()}:null,kill:e=>{if(a.pid===void 0){a.kill(e);return}try{process.kill(-a.pid,e??`SIGTERM`)}catch{a.kill(e)}},wait:()=>o}}};export{n as t};