openclaw-code-agent 4.7.7 → 4.7.8

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{$ as Yo,A as de,Aa as Ft,B as Pr,C as wr,D as br,E as Pt,F as wt,G as bt,H as Rt,I as Uo,J as Go,K as C,L as D,M as z,N as jo,O as At,P as zo,Pa as Bt,Q as Rr,R as F,S as It,T as Je,U as Tt,V as Ho,W as Qo,X as Ee,Y as oe,Z as Xe,_ as xt,a as Te,aa as H,b as xe,ba as Ar,c as vr,ca as Ir,d as Fo,da as Ze,e as Ce,ea as et,f as ue,fa as B,g as Z,ga as Ct,h as le,ha as Jo,i as Ye,ia as tt,j as Bo,ja as ie,k as _,ka as Ne,l as Ko,la as Xo,m as Y,ma as Mt,n as Me,na as nt,o as St,oa as _t,p as pe,pa as Dt,q as _e,qa as Oe,r as kt,ra as $t,s as vt,sa as Zo,t as qo,ta as Et,u as De,ua as Nt,v as $e,va as ei,w as Vo,wa as Ot,x as c,xa as Wt,y as S,ya as Lt,z as $,za as Se}from"./chunks/chunk.js";import{readdirSync as ff,statSync as gf,rmSync as hf}from"fs";import{execFileSync as yf}from"child_process";import{join as Wo}from"path";var ti={name:"openclaw-code-agent",version:"4.7.7",type:"module",packageManager:"pnpm@11.15.1",main:"dist/index.js",scripts:{"audit:prod":"pnpm audit --prod",build:"esbuild index.ts --bundle --splitting --platform=node --target=node22 --format=esm --outdir=dist --entry-names=index --chunk-names=chunks/[name] --minify --charset=utf8 --pure:console.log --pure:console.warn --pure:console.info --pure:console.debug --external:@anthropic-ai/claude-agent-sdk --external:openclaw/plugin-sdk/plugin-entry","check-static-guardrails":"node scripts/check-static-guardrails.mjs && node scripts/check-release-age-exceptions.mjs","check-plugin-security":"node scripts/check-plugin-security.mjs",test:"node scripts/run-tests.mjs","test:integ:crabbox":"node scripts/run-tests.mjs tests/oca-codex-crabbox-integ.test.ts tests/oca-plugin-workflows-integ.test.ts tests/oca-codex-telegram-proof.test.ts tests/oca-codex-proof-app-server.test.ts tests/oca-codex-proof-workflow.test.ts","test:serial":"node scripts/run-tests.mjs","test:file":"node scripts/run-tests.mjs","smoke:backend":"node scripts/run-tests.mjs tests/codex-harness.test.ts tests/plan-mode-e2e.test.ts tests/session-restore-service.test.ts","smoke:backend-parity":"node scripts/run-tests.mjs tests/backend-contract-smoke.test.ts tests/codex-harness.test.ts tests/harness-registry.test.ts","smoke:codex-worktrees":"node scripts/run-tests.mjs tests/codex-harness.test.ts tests/session-bootstrap.test.ts tests/session-restore-service.test.ts","smoke:codex-live":"OPENCLAW_RUN_LIVE_CODEX_SMOKE=1 node scripts/run-tests.mjs tests/live-codex-app-server-smoke.test.ts","proof:codex-doctor":"node --import tsx scripts/e2e/oca-codex-telegram-proof.ts doctor","proof:codex-local":"node --import tsx scripts/e2e/oca-codex-telegram-proof.ts local-smoke","proof:codex-telegram":"node scripts/e2e/run-oca-codex-telegram-proof.mjs","smoke:codex-release":"OPENCLAW_RUN_LIVE_CODEX_RELEASE_SMOKE=1 node scripts/run-tests.mjs tests/live-codex-app-server-smoke.test.ts","smoke:opencode-live":"OPENCLAW_RUN_LIVE_OPENCODE_SMOKE=1 node scripts/run-tests.mjs tests/live-opencode-server-smoke.test.ts",typecheck:"tsc -p tsconfig.typecheck.json --noEmit","validate:release-metadata":"node scripts/validate-release-metadata.mjs",verify:"pnpm check-static-guardrails && pnpm typecheck && pnpm build && pnpm test"},openclaw:{extensions:["./dist/index.js"],install:{npmSpec:"openclaw-code-agent",defaultChoice:"npm",minHostVersion:">=2026.7.1-2"},compat:{pluginApi:">=2026.7.1-2",minGatewayVersion:"2026.7.1-2"},build:{openclawVersion:"2026.7.1-2",pluginSdkVersion:"2026.7.1-2"}},files:["dist/","skills/","openclaw.plugin.json","README.md","LICENSE"],dependencies:{"@anthropic-ai/claude-agent-sdk":"^0.3.216"},devDependencies:{"@types/node":"^26.0.1",esbuild:"^0.28.1",nanoid:"^6.0.0",openclaw:"2026.7.1-2",tsx:"^4.21.0",typescript:"^7.0.2"},keywords:["openclaw","plugin","claude","claude-code","opencode","coding-agent","codex","ai","anthropic","agent","code-generation","automation","cli","background-process","developer-tools"],repository:{type:"git",url:"git+https://github.com/goldmar/openclaw-code-agent.git"},homepage:"https://github.com/goldmar/openclaw-code-agent#readme",bugs:{url:"https://github.com/goldmar/openclaw-code-agent/issues"},license:"MIT",author:"Mark Goldenstein",publishConfig:{access:"public",provenance:!0},description:"An OpenClaw plugin that orchestrates coding agent sessions as managed background processes. Launch, monitor, and control coding agents (Claude Code, Codex, experimental OpenCode, and more) directly from your AI gateway.",peerDependencies:{openclaw:">=2026.7.1-2"},overrides:{"basic-ftp":"5.3.1","fast-xml-builder@<1.1.7":"1.1.7","fast-uri@<3.1.5":"3.1.5","hono@<4.12.34":"4.12.34","ip-address@<10.3.1":"10.3.1"}};import{execFile as wl}from"node:child_process";import{mkdirSync as bl,readFileSync as Rl,renameSync as Al,writeFileSync as Il}from"node:fs";import{dirname as Tl,join as xl}from"node:path";import{promisify as Cl}from"node:util";import*as di from"child_process";import{createHash as ll}from"crypto";var W="code-agent";var dl=new Set(["1","true","yes","on"]);function xr(){let n=process.env.OPENCLAW_CODE_AGENT_BUTTON_DIAGNOSTICS?.trim().toLowerCase();return!!(n&&dl.has(n))}function K(n){if(!(typeof n!="string"||n.length===0))return ll("sha256").update(n).digest("hex").slice(0,12)}function ni(n){return typeof n.callbackData=="string"?n.callbackData:typeof n.value=="string"?n.value:void 0}function E(n){let e=(n??[]).filter(r=>Array.isArray(r)&&r.length>0),t=e.flat();return{buttonRows:e.length||void 0,buttonCount:t.length||void 0,buttonLabels:t.length>0?t.map(r=>typeof r.label=="string"?r.label:void 0):void 0,callbackByteLengths:t.length>0?t.map(r=>{let o=ni(r);return o?Buffer.byteLength(o,"utf8"):void 0}):void 0,callbackHashes:t.length>0?t.map(r=>K(ni(r))):void 0,buttonStyles:t.length>0?t.map(r=>typeof r.style=="string"?r.style:void 0):void 0}}function ce(n){return n&&typeof n=="object"&&!Array.isArray(n)?n:void 0}function oi(n){let e=ce(n),t=Array.isArray(e?.blocks)?e.blocks:void 0;if(t)return t.map(r=>ce(r)?.type).filter(r=>typeof r=="string"&&r.length>0)}function ii(n){let e=ce(n),t=Array.isArray(e?.blocks)?e.blocks:void 0;if(!t)return;let r=t.map(o=>{let i=ce(o);return i?.type!=="buttons"||!Array.isArray(i.buttons)?[]:i.buttons}).filter(o=>o.length>0);return r.length>0?r:void 0}function Cr(n){let e=ii(n);return{presentationBlockTypes:oi(n),...E(e)}}function Mr(n){let e=ce(n),t=e?.interactive,r=ce(e?.channelData),o=ce(r?.telegram),i=Array.isArray(o?.buttons)?o.buttons:void 0;return{renderedPayloadKeys:e?Object.keys(e).sort():void 0,interactiveBlockTypes:oi(t),...ri("interactive",E(ii(t))),...ri("telegramChannelData",E(i)),hasPresentation:!!e?.presentation,hasInteractive:!!t,hasTelegramChannelDataButtons:!!i?.some(s=>s.length>0)}}function si(n){let e=ce(n);return e?{sendResultKeys:Object.keys(e).sort(),messageId:Tr(e.messageId),chatId:Tr(e.chatId),telegramThreadId:Tr(e.messageThreadId??e.threadId),channel:typeof e.channel=="string"?e.channel:void 0}:{sendResultType:typeof n}}function Tr(n){return typeof n=="string"||typeof n=="number"?n:void 0}function ri(n,e){let t={};for(let[r,o]of Object.entries(e))o!==void 0&&(t[`${n}${r.charAt(0).toUpperCase()}${r.slice(1)}`]=o);return t}function M(n,e){if(!xr())return;let t=Object.fromEntries(Object.entries(e).filter(([,r])=>r!==void 0));`${JSON.stringify({event:n,callbackNamespace:W,...t})}`}var ai=5e3,ui=64,ul={primary:"primary",success:"success",positive:"success",danger:"danger",destructive:"danger",negative:"danger"},pl={execFile:di.execFile},me=class extends Error{constructor(e){super(e),this.name="MissingRuntimeDirectNotificationCapabilityError"}},We=class{constructor(e=pl.execFile){this.execFile=e}execFile;async send(e,t,r){M("direct_send_started",{...J(e),messageTextLength:t.length,...E(r)});try{await this.sendViaRuntime(e,t,r),M("direct_send_succeeded",{...J(e),deliveryPath:"runtime",...E(r)});return}catch(o){if(!(o instanceof me))throw M("direct_send_failed",{...J(e),deliveryPath:"runtime",...E(r),error:_r(o)}),o;M("direct_send_runtime_capability_missing",{...J(e),deliveryPath:"runtime",...E(r),reason:o.message}),await this.sendViaBoundedCliFallback(e,t,r,o.message),M("direct_send_succeeded",{...J(e),deliveryPath:"cli-fallback",...E(r)})}}async sendViaRuntime(e,t,r){let o=xe(),i=Fo(),s=o?.channel?.outbound?.loadAdapter;if(!o)throw new me("OpenClaw plugin runtime is unavailable for direct notification delivery");if(i==null)throw new me("OpenClaw runtime config snapshot is unavailable for direct notification delivery");if(!o.channel)throw new me(`OpenClaw plugin runtime channel surface is unavailable for direct notification delivery (runtimeVersion=${Dr(o)})`);if(!o.channel.outbound)throw new me(`OpenClaw plugin runtime channel outbound surface is unavailable for direct notification delivery (runtimeVersion=${Dr(o)})`);if(!s)throw new me(`OpenClaw plugin runtime channel outbound loadAdapter is unavailable for direct notification delivery (runtimeVersion=${Dr(o)})`);let a=await s(e.channel);if(!a)throw new Error(`OpenClaw outbound adapter for channel "${e.channel}" is unavailable`);let l=Vt(r);if(M("runtime_adapter_loaded",{...J(e),adapterHasRenderPresentation:typeof a.renderPresentation=="function",adapterHasSendPayload:typeof a.sendPayload=="function",adapterHasSendText:typeof a.sendText=="function",...E(r),...l?Cr(l):{}}),l){await this.sendPresentation(a,i,e,t,l);return}if(!a.sendText)throw new Error(`OpenClaw outbound adapter for channel "${e.channel}" cannot send text`);await a.sendText({cfg:i,to:e.target,text:t,accountId:e.accountId,threadId:e.threadId})}async sendPresentation(e,t,r,o,i){let s=ml(i),a={text:o,presentation:i,interactive:s};M("presentation_render_started",{...J(r),messageTextLength:o.length,adapterHasRenderPresentation:typeof e.renderPresentation=="function",adapterHasSendPayload:typeof e.sendPayload=="function",...Cr(i)});let l={cfg:t,to:r.target,text:o,payload:a,accountId:r.accountId,threadId:r.threadId},d=e.renderPresentation?await e.renderPresentation({payload:a,presentation:i,ctx:l}):a,u=gl(d,s,r.channel);if(M("presentation_render_completed",{...J(r),adapterHasRenderPresentation:typeof e.renderPresentation=="function",adapterHasSendPayload:typeof e.sendPayload=="function",...Mr(u)}),!u||typeof u!="object"||!e.sendPayload)throw new Error(`OpenClaw outbound adapter for channel "${r.channel}" cannot preserve interactive presentation`);let f=await e.sendPayload({...l,payload:u});M("presentation_send_payload_completed",{...J(r),...Mr(u),...si(f)})}sendViaBoundedCliFallback(e,t,r,o){return new Promise((i,s)=>{let a=cl(e,t,r);M("direct_send_cli_fallback_started",{...J(e),deliveryPath:"cli-fallback",reason:o,messageTextLength:t.length,...E(r)}),this.execFile("openclaw",a,{timeout:ai,killSignal:"SIGKILL"},(l,d,u)=>{if(!l){M("direct_send_cli_fallback_completed",{...J(e),deliveryPath:"cli-fallback",...E(r)}),i();return}let f=u?.trim()?` | stderr: ${u.trim()}`:"";M("direct_send_cli_fallback_failed",{...J(e),deliveryPath:"cli-fallback",...E(r),error:_r(l),stderrLength:u?.length}),s(new Error(`${o}; bounded openclaw message send fallback failed within ${ai}ms timeout: ${_r(l)}${f}`))})})}};function J(n){return{channel:n.channel,target:n.target,accountId:n.accountId,threadId:n.threadId,sessionKey:n.sessionKey}}function cl(n,e,t){let r=Vt(t),o=["message","send","--channel",n.channel,"--target",n.target,"--message",e];return n.accountId&&o.push("--account",n.accountId),n.threadId&&o.push("--thread-id",n.threadId),r&&o.push("--presentation",JSON.stringify(r)),o}function _r(n){return n instanceof Error?n.message:String(n)}function Dr(n){if(!n||typeof n!="object")return"unknown";let e=n.version;return typeof e=="string"&&e.trim()?e:"unknown"}function Vt(n){let e=(n??[]).filter(t=>Array.isArray(t)&&t.length>0).map(t=>({type:"buttons",buttons:t.map(r=>({label:r.label,value:Pl(r.callbackData),...r.style?{style:r.style}:{}}))}));return e.length>0?{blocks:e}:void 0}function ml(n){let e=n.blocks.filter(t=>t.type==="buttons"&&t.buttons.length>0).map(t=>({type:"buttons",buttons:t.buttons.map(r=>({label:r.label,value:r.value,...r.style?{style:r.style}:{}}))}));return e.length>0?{blocks:e}:void 0}function fl(n){if(!n||typeof n!="object"||Array.isArray(n))return!1;let e=n.interactive;if(!e||typeof e!="object"||Array.isArray(e))return!1;let t=e.blocks;return Array.isArray(t)&&t.some(r=>{if(!r||typeof r!="object"||Array.isArray(r))return!1;let o=r;return o.type==="buttons"&&Array.isArray(o.buttons)&&o.buttons.length>0})}function gl(n,e,t){if(!e)return n;let r=fl(n)?n:hl(n,e);return t!=="telegram"?r:yl(r,e)}function hl(n,e){return!n||typeof n!="object"||Array.isArray(n)?n:{...n,interactive:e}}function yl(n,e){if(!n||typeof n!="object"||Array.isArray(n))return n;let t=n,r=Le(t.channelData),o=Le(r?.telegram),i=kl(o?.buttons);if(i)return{...t,channelData:{...r??{},telegram:{...o??{},buttons:i}}};let s=Sl(e);return s?{...t,channelData:{...r??{},telegram:{...o??{},buttons:s}}}:n}function Sl(n){let e=n.blocks.filter(t=>t.type==="buttons"&&t.buttons.length>0).map(t=>t.buttons.filter(r=>typeof r.value=="string"&&r.value.trim().length>0&&Buffer.byteLength(r.value,"utf8")<=ui).map(r=>({text:r.label,callback_data:r.value,...pi(r.style)}))).filter(t=>t.length>0);return e.length>0?e:void 0}function kl(n){if(!Array.isArray(n))return;let e=n.map(t=>Array.isArray(t)?t.map(r=>{if(!r||typeof r!="object"||Array.isArray(r))return;let{style:o,...i}=r;if(!(typeof i.text!="string"||i.text.trim().length===0)&&!(i.callback_data!==void 0&&(typeof i.callback_data!="string"||i.callback_data.trim().length===0||Buffer.byteLength(i.callback_data,"utf8")>ui))&&vl(i))return{...i,...pi(o)}}).filter(r=>!!r):[]).filter(t=>t.length>0);return e.length>0?e:void 0}function vl(n){return qt(n.callback_data)||qt(n.url)||Kt(n.web_app)||Kt(n.webApp)||Kt(n.login_url)||Kt(n.loginUrl)||typeof n.switch_inline_query=="string"||typeof n.switch_inline_query_current_chat=="string"||Le(n.switch_inline_query_chosen_chat)!==void 0||Le(n.callback_game)!==void 0||n.pay===!0||li(n.copy_text)||li(n.copyText)}function qt(n){return typeof n=="string"&&n.trim().length>0}function Kt(n){let e=Le(n);return qt(e?.url)}function li(n){let e=Le(n);return qt(e?.text)}function pi(n){if(typeof n!="string")return{};let e=n.trim().toLowerCase(),t=ul[e];return t?{style:t}:{}}function Le(n){return n&&typeof n=="object"&&!Array.isArray(n)?n:void 0}function Pl(n){return n.startsWith(`${W}:`)?n:`${W}:${n}`}var Ml=Cl(wl),rt="openclaw-code-agent",_l=`https://registry.npmjs.org/${encodeURIComponent(rt)}/latest`,Dl="openclaw-code-agent-auto-update.json",gi=1440*60*1e3,$l=7*gi,El=1e4,Fe="plugin:auto-update";function fe(n){return!!n&&typeof n=="object"&&!Array.isArray(n)}function $r(n){return n instanceof Error?n.message:String(n)}function te(n){return n?.trim().replace(/^v/i,"")||void 0}function ee(n,e){let t=n[e];return typeof t=="string"&&t.trim()?t.trim():void 0}function ci(n){let e=n?.trim().replace(/^npm:/,"");if(!e)return;if(e.startsWith("@")){let r=e.indexOf("@",1);return r===-1?e:e.slice(0,r)}let t=e.indexOf("@");return t===-1?e:e.slice(0,t)}function Er(n){let e=`${n.stdout}
1
+ import{$ as Yo,A as de,Aa as Ft,B as Pr,C as wr,D as br,E as Pt,F as wt,G as bt,H as Rt,I as Uo,J as Go,K as C,L as D,M as z,N as jo,O as At,P as zo,Pa as Bt,Q as Rr,R as F,S as It,T as Je,U as Tt,V as Ho,W as Qo,X as Ee,Y as oe,Z as Xe,_ as xt,a as Te,aa as H,b as xe,ba as Ar,c as vr,ca as Ir,d as Fo,da as Ze,e as Ce,ea as et,f as ue,fa as B,g as Z,ga as Ct,h as le,ha as Jo,i as Ye,ia as tt,j as Bo,ja as ie,k as _,ka as Ne,l as Ko,la as Xo,m as Y,ma as Mt,n as Me,na as nt,o as St,oa as _t,p as pe,pa as Dt,q as _e,qa as Oe,r as kt,ra as $t,s as vt,sa as Zo,t as qo,ta as Et,u as De,ua as Nt,v as $e,va as ei,w as Vo,wa as Ot,x as c,xa as Wt,y as S,ya as Lt,z as $,za as Se}from"./chunks/chunk.js";import{readdirSync as ff,statSync as gf,rmSync as hf}from"fs";import{execFileSync as yf}from"child_process";import{join as Wo}from"path";var ti={name:"openclaw-code-agent",version:"4.7.8",type:"module",packageManager:"pnpm@11.15.1",main:"dist/index.js",scripts:{"audit:prod":"pnpm audit --prod",build:"esbuild index.ts --bundle --splitting --platform=node --target=node22 --format=esm --outdir=dist --entry-names=index --chunk-names=chunks/[name] --minify --charset=utf8 --pure:console.log --pure:console.warn --pure:console.info --pure:console.debug --external:@anthropic-ai/claude-agent-sdk --external:openclaw/plugin-sdk/plugin-entry","generate:npm-shrinkwrap":"node scripts/generate-npm-shrinkwrap.mjs","check-static-guardrails":"node scripts/check-static-guardrails.mjs && node scripts/check-release-age-exceptions.mjs && node scripts/check-npm-shrinkwrap.mjs","check-plugin-security":"node scripts/check-plugin-security.mjs",test:"node scripts/run-tests.mjs","test:integ:crabbox":"node scripts/run-tests.mjs tests/oca-codex-crabbox-integ.test.ts tests/oca-plugin-workflows-integ.test.ts tests/oca-codex-telegram-proof.test.ts tests/oca-codex-proof-app-server.test.ts tests/oca-codex-proof-workflow.test.ts","test:serial":"node scripts/run-tests.mjs","test:file":"node scripts/run-tests.mjs","smoke:backend":"node scripts/run-tests.mjs tests/codex-harness.test.ts tests/plan-mode-e2e.test.ts tests/session-restore-service.test.ts","smoke:backend-parity":"node scripts/run-tests.mjs tests/backend-contract-smoke.test.ts tests/codex-harness.test.ts tests/harness-registry.test.ts","smoke:codex-worktrees":"node scripts/run-tests.mjs tests/codex-harness.test.ts tests/session-bootstrap.test.ts tests/session-restore-service.test.ts","smoke:codex-live":"OPENCLAW_RUN_LIVE_CODEX_SMOKE=1 node scripts/run-tests.mjs tests/live-codex-app-server-smoke.test.ts","proof:codex-doctor":"node --import tsx scripts/e2e/oca-codex-telegram-proof.ts doctor","proof:codex-local":"node --import tsx scripts/e2e/oca-codex-telegram-proof.ts local-smoke","proof:codex-telegram":"node scripts/e2e/run-oca-codex-telegram-proof.mjs","smoke:codex-release":"OPENCLAW_RUN_LIVE_CODEX_RELEASE_SMOKE=1 node scripts/run-tests.mjs tests/live-codex-app-server-smoke.test.ts","smoke:opencode-live":"OPENCLAW_RUN_LIVE_OPENCODE_SMOKE=1 node scripts/run-tests.mjs tests/live-opencode-server-smoke.test.ts",typecheck:"tsc -p tsconfig.typecheck.json --noEmit","validate:release-metadata":"node scripts/validate-release-metadata.mjs","verify:npm-consumer":"node scripts/check-npm-shrinkwrap-release-age.mjs && node scripts/verify-npm-consumer-install.mjs",verify:"pnpm check-static-guardrails && pnpm typecheck && pnpm build && pnpm test"},openclaw:{extensions:["./dist/index.js"],install:{npmSpec:"openclaw-code-agent",defaultChoice:"npm",minHostVersion:">=2026.7.1-2"},compat:{pluginApi:">=2026.7.1-2",minGatewayVersion:"2026.7.1-2"},build:{openclawVersion:"2026.7.1-2",pluginSdkVersion:"2026.7.1-2"}},files:["dist/","skills/","openclaw.plugin.json","npm-shrinkwrap.json","README.md","LICENSE"],dependencies:{"@anthropic-ai/claude-agent-sdk":"0.3.220","@anthropic-ai/sdk":"0.109.1","@hono/node-server":"2.0.10","@modelcontextprotocol/sdk":"1.30.0","express-rate-limit":"8.6.1","fast-uri":"3.1.5",hono:"4.12.34","ip-address":"10.3.1",zod:"4.4.3"},devDependencies:{"@types/node":"^26.0.1",esbuild:"^0.28.1",nanoid:"^6.0.0",openclaw:"2026.7.1-2",tsx:"^4.21.0",typescript:"^7.0.2"},keywords:["openclaw","plugin","claude","claude-code","opencode","coding-agent","codex","ai","anthropic","agent","code-generation","automation","cli","background-process","developer-tools"],repository:{type:"git",url:"git+https://github.com/goldmar/openclaw-code-agent.git"},homepage:"https://github.com/goldmar/openclaw-code-agent#readme",bugs:{url:"https://github.com/goldmar/openclaw-code-agent/issues"},license:"MIT",author:"Mark Goldenstein",publishConfig:{access:"public",provenance:!0},description:"An OpenClaw plugin that orchestrates coding agent sessions as managed background processes. Launch, monitor, and control coding agents (Claude Code, Codex, experimental OpenCode, and more) directly from your AI gateway.",peerDependencies:{openclaw:">=2026.7.1-2"}};import{execFile as wl}from"node:child_process";import{mkdirSync as bl,readFileSync as Rl,renameSync as Al,writeFileSync as Il}from"node:fs";import{dirname as Tl,join as xl}from"node:path";import{promisify as Cl}from"node:util";import*as di from"child_process";import{createHash as ll}from"crypto";var W="code-agent";var dl=new Set(["1","true","yes","on"]);function xr(){let n=process.env.OPENCLAW_CODE_AGENT_BUTTON_DIAGNOSTICS?.trim().toLowerCase();return!!(n&&dl.has(n))}function K(n){if(!(typeof n!="string"||n.length===0))return ll("sha256").update(n).digest("hex").slice(0,12)}function ni(n){return typeof n.callbackData=="string"?n.callbackData:typeof n.value=="string"?n.value:void 0}function E(n){let e=(n??[]).filter(r=>Array.isArray(r)&&r.length>0),t=e.flat();return{buttonRows:e.length||void 0,buttonCount:t.length||void 0,buttonLabels:t.length>0?t.map(r=>typeof r.label=="string"?r.label:void 0):void 0,callbackByteLengths:t.length>0?t.map(r=>{let o=ni(r);return o?Buffer.byteLength(o,"utf8"):void 0}):void 0,callbackHashes:t.length>0?t.map(r=>K(ni(r))):void 0,buttonStyles:t.length>0?t.map(r=>typeof r.style=="string"?r.style:void 0):void 0}}function ce(n){return n&&typeof n=="object"&&!Array.isArray(n)?n:void 0}function oi(n){let e=ce(n),t=Array.isArray(e?.blocks)?e.blocks:void 0;if(t)return t.map(r=>ce(r)?.type).filter(r=>typeof r=="string"&&r.length>0)}function ii(n){let e=ce(n),t=Array.isArray(e?.blocks)?e.blocks:void 0;if(!t)return;let r=t.map(o=>{let i=ce(o);return i?.type!=="buttons"||!Array.isArray(i.buttons)?[]:i.buttons}).filter(o=>o.length>0);return r.length>0?r:void 0}function Cr(n){let e=ii(n);return{presentationBlockTypes:oi(n),...E(e)}}function Mr(n){let e=ce(n),t=e?.interactive,r=ce(e?.channelData),o=ce(r?.telegram),i=Array.isArray(o?.buttons)?o.buttons:void 0;return{renderedPayloadKeys:e?Object.keys(e).sort():void 0,interactiveBlockTypes:oi(t),...ri("interactive",E(ii(t))),...ri("telegramChannelData",E(i)),hasPresentation:!!e?.presentation,hasInteractive:!!t,hasTelegramChannelDataButtons:!!i?.some(s=>s.length>0)}}function si(n){let e=ce(n);return e?{sendResultKeys:Object.keys(e).sort(),messageId:Tr(e.messageId),chatId:Tr(e.chatId),telegramThreadId:Tr(e.messageThreadId??e.threadId),channel:typeof e.channel=="string"?e.channel:void 0}:{sendResultType:typeof n}}function Tr(n){return typeof n=="string"||typeof n=="number"?n:void 0}function ri(n,e){let t={};for(let[r,o]of Object.entries(e))o!==void 0&&(t[`${n}${r.charAt(0).toUpperCase()}${r.slice(1)}`]=o);return t}function M(n,e){if(!xr())return;let t=Object.fromEntries(Object.entries(e).filter(([,r])=>r!==void 0));`${JSON.stringify({event:n,callbackNamespace:W,...t})}`}var ai=5e3,ui=64,ul={primary:"primary",success:"success",positive:"success",danger:"danger",destructive:"danger",negative:"danger"},pl={execFile:di.execFile},me=class extends Error{constructor(e){super(e),this.name="MissingRuntimeDirectNotificationCapabilityError"}},We=class{constructor(e=pl.execFile){this.execFile=e}execFile;async send(e,t,r){M("direct_send_started",{...J(e),messageTextLength:t.length,...E(r)});try{await this.sendViaRuntime(e,t,r),M("direct_send_succeeded",{...J(e),deliveryPath:"runtime",...E(r)});return}catch(o){if(!(o instanceof me))throw M("direct_send_failed",{...J(e),deliveryPath:"runtime",...E(r),error:_r(o)}),o;M("direct_send_runtime_capability_missing",{...J(e),deliveryPath:"runtime",...E(r),reason:o.message}),await this.sendViaBoundedCliFallback(e,t,r,o.message),M("direct_send_succeeded",{...J(e),deliveryPath:"cli-fallback",...E(r)})}}async sendViaRuntime(e,t,r){let o=xe(),i=Fo(),s=o?.channel?.outbound?.loadAdapter;if(!o)throw new me("OpenClaw plugin runtime is unavailable for direct notification delivery");if(i==null)throw new me("OpenClaw runtime config snapshot is unavailable for direct notification delivery");if(!o.channel)throw new me(`OpenClaw plugin runtime channel surface is unavailable for direct notification delivery (runtimeVersion=${Dr(o)})`);if(!o.channel.outbound)throw new me(`OpenClaw plugin runtime channel outbound surface is unavailable for direct notification delivery (runtimeVersion=${Dr(o)})`);if(!s)throw new me(`OpenClaw plugin runtime channel outbound loadAdapter is unavailable for direct notification delivery (runtimeVersion=${Dr(o)})`);let a=await s(e.channel);if(!a)throw new Error(`OpenClaw outbound adapter for channel "${e.channel}" is unavailable`);let l=Vt(r);if(M("runtime_adapter_loaded",{...J(e),adapterHasRenderPresentation:typeof a.renderPresentation=="function",adapterHasSendPayload:typeof a.sendPayload=="function",adapterHasSendText:typeof a.sendText=="function",...E(r),...l?Cr(l):{}}),l){await this.sendPresentation(a,i,e,t,l);return}if(!a.sendText)throw new Error(`OpenClaw outbound adapter for channel "${e.channel}" cannot send text`);await a.sendText({cfg:i,to:e.target,text:t,accountId:e.accountId,threadId:e.threadId})}async sendPresentation(e,t,r,o,i){let s=ml(i),a={text:o,presentation:i,interactive:s};M("presentation_render_started",{...J(r),messageTextLength:o.length,adapterHasRenderPresentation:typeof e.renderPresentation=="function",adapterHasSendPayload:typeof e.sendPayload=="function",...Cr(i)});let l={cfg:t,to:r.target,text:o,payload:a,accountId:r.accountId,threadId:r.threadId},d=e.renderPresentation?await e.renderPresentation({payload:a,presentation:i,ctx:l}):a,u=gl(d,s,r.channel);if(M("presentation_render_completed",{...J(r),adapterHasRenderPresentation:typeof e.renderPresentation=="function",adapterHasSendPayload:typeof e.sendPayload=="function",...Mr(u)}),!u||typeof u!="object"||!e.sendPayload)throw new Error(`OpenClaw outbound adapter for channel "${r.channel}" cannot preserve interactive presentation`);let f=await e.sendPayload({...l,payload:u});M("presentation_send_payload_completed",{...J(r),...Mr(u),...si(f)})}sendViaBoundedCliFallback(e,t,r,o){return new Promise((i,s)=>{let a=cl(e,t,r);M("direct_send_cli_fallback_started",{...J(e),deliveryPath:"cli-fallback",reason:o,messageTextLength:t.length,...E(r)}),this.execFile("openclaw",a,{timeout:ai,killSignal:"SIGKILL"},(l,d,u)=>{if(!l){M("direct_send_cli_fallback_completed",{...J(e),deliveryPath:"cli-fallback",...E(r)}),i();return}let f=u?.trim()?` | stderr: ${u.trim()}`:"";M("direct_send_cli_fallback_failed",{...J(e),deliveryPath:"cli-fallback",...E(r),error:_r(l),stderrLength:u?.length}),s(new Error(`${o}; bounded openclaw message send fallback failed within ${ai}ms timeout: ${_r(l)}${f}`))})})}};function J(n){return{channel:n.channel,target:n.target,accountId:n.accountId,threadId:n.threadId,sessionKey:n.sessionKey}}function cl(n,e,t){let r=Vt(t),o=["message","send","--channel",n.channel,"--target",n.target,"--message",e];return n.accountId&&o.push("--account",n.accountId),n.threadId&&o.push("--thread-id",n.threadId),r&&o.push("--presentation",JSON.stringify(r)),o}function _r(n){return n instanceof Error?n.message:String(n)}function Dr(n){if(!n||typeof n!="object")return"unknown";let e=n.version;return typeof e=="string"&&e.trim()?e:"unknown"}function Vt(n){let e=(n??[]).filter(t=>Array.isArray(t)&&t.length>0).map(t=>({type:"buttons",buttons:t.map(r=>({label:r.label,value:Pl(r.callbackData),...r.style?{style:r.style}:{}}))}));return e.length>0?{blocks:e}:void 0}function ml(n){let e=n.blocks.filter(t=>t.type==="buttons"&&t.buttons.length>0).map(t=>({type:"buttons",buttons:t.buttons.map(r=>({label:r.label,value:r.value,...r.style?{style:r.style}:{}}))}));return e.length>0?{blocks:e}:void 0}function fl(n){if(!n||typeof n!="object"||Array.isArray(n))return!1;let e=n.interactive;if(!e||typeof e!="object"||Array.isArray(e))return!1;let t=e.blocks;return Array.isArray(t)&&t.some(r=>{if(!r||typeof r!="object"||Array.isArray(r))return!1;let o=r;return o.type==="buttons"&&Array.isArray(o.buttons)&&o.buttons.length>0})}function gl(n,e,t){if(!e)return n;let r=fl(n)?n:hl(n,e);return t!=="telegram"?r:yl(r,e)}function hl(n,e){return!n||typeof n!="object"||Array.isArray(n)?n:{...n,interactive:e}}function yl(n,e){if(!n||typeof n!="object"||Array.isArray(n))return n;let t=n,r=Le(t.channelData),o=Le(r?.telegram),i=kl(o?.buttons);if(i)return{...t,channelData:{...r??{},telegram:{...o??{},buttons:i}}};let s=Sl(e);return s?{...t,channelData:{...r??{},telegram:{...o??{},buttons:s}}}:n}function Sl(n){let e=n.blocks.filter(t=>t.type==="buttons"&&t.buttons.length>0).map(t=>t.buttons.filter(r=>typeof r.value=="string"&&r.value.trim().length>0&&Buffer.byteLength(r.value,"utf8")<=ui).map(r=>({text:r.label,callback_data:r.value,...pi(r.style)}))).filter(t=>t.length>0);return e.length>0?e:void 0}function kl(n){if(!Array.isArray(n))return;let e=n.map(t=>Array.isArray(t)?t.map(r=>{if(!r||typeof r!="object"||Array.isArray(r))return;let{style:o,...i}=r;if(!(typeof i.text!="string"||i.text.trim().length===0)&&!(i.callback_data!==void 0&&(typeof i.callback_data!="string"||i.callback_data.trim().length===0||Buffer.byteLength(i.callback_data,"utf8")>ui))&&vl(i))return{...i,...pi(o)}}).filter(r=>!!r):[]).filter(t=>t.length>0);return e.length>0?e:void 0}function vl(n){return qt(n.callback_data)||qt(n.url)||Kt(n.web_app)||Kt(n.webApp)||Kt(n.login_url)||Kt(n.loginUrl)||typeof n.switch_inline_query=="string"||typeof n.switch_inline_query_current_chat=="string"||Le(n.switch_inline_query_chosen_chat)!==void 0||Le(n.callback_game)!==void 0||n.pay===!0||li(n.copy_text)||li(n.copyText)}function qt(n){return typeof n=="string"&&n.trim().length>0}function Kt(n){let e=Le(n);return qt(e?.url)}function li(n){let e=Le(n);return qt(e?.text)}function pi(n){if(typeof n!="string")return{};let e=n.trim().toLowerCase(),t=ul[e];return t?{style:t}:{}}function Le(n){return n&&typeof n=="object"&&!Array.isArray(n)?n:void 0}function Pl(n){return n.startsWith(`${W}:`)?n:`${W}:${n}`}var Ml=Cl(wl),rt="openclaw-code-agent",_l=`https://registry.npmjs.org/${encodeURIComponent(rt)}/latest`,Dl="openclaw-code-agent-auto-update.json",gi=1440*60*1e3,$l=7*gi,El=1e4,Fe="plugin:auto-update";function fe(n){return!!n&&typeof n=="object"&&!Array.isArray(n)}function $r(n){return n instanceof Error?n.message:String(n)}function te(n){return n?.trim().replace(/^v/i,"")||void 0}function ee(n,e){let t=n[e];return typeof t=="string"&&t.trim()?t.trim():void 0}function ci(n){let e=n?.trim().replace(/^npm:/,"");if(!e)return;if(e.startsWith("@")){let r=e.indexOf("@",1);return r===-1?e:e.slice(0,r)}let t=e.indexOf("@");return t===-1?e:e.slice(0,t)}function Er(n){let e=`${n.stdout}
2
2
  ${n.stderr}`;if(/No install record/i.test(e))throw new Error("OpenClaw reported no managed install record for OpenClaw Code Agent.");let t;try{t=JSON.parse(n.stdout)}catch{throw new Error("OpenClaw returned invalid JSON while inspecting the OpenClaw Code Agent install.")}if(!fe(t)||!fe(t.plugin)||!fe(t.install))throw new Error("OpenClaw inspection did not include the OpenClaw Code Agent plugin and managed install record.");let r=ee(t.plugin,"id"),o=te(ee(t.plugin,"version"));if(r!==rt||!o)throw new Error("OpenClaw inspection returned an unexpected OpenClaw Code Agent plugin identity or version.");let i=ee(t.install,"source"),s=te(ee(t.install,"version")),a=te(ee(t.install,"resolvedVersion"));if(i==="npm"){let l=ee(t.install,"resolvedName")??ci(ee(t.install,"spec"))??ci(ee(t.install,"resolvedSpec"));if(!l)throw new Error("The OpenClaw Code Agent npm install record does not identify its package.");return{pluginVersion:o,install:{source:i,packageName:l,recordedVersion:s,resolvedVersion:a}}}if(i==="clawhub"){let l=ee(t.install,"clawhubPackage");if(!l)throw new Error("The OpenClaw Code Agent ClawHub install record does not identify its package.");return{pluginVersion:o,install:{source:i,packageName:l,recordedVersion:s,resolvedVersion:a}}}throw new Error(`OpenClaw Code Agent self-update does not support managed install source ${i??"unknown"}.`)}function Nl(n,e){return["plugins","install",n.source==="npm"?`${n.packageName}@${e}`:`clawhub:${n.packageName}@${e}`,"--force"]}function Ol(n,e,t){if(e.install.source!==n.install.source||e.install.packageName!==n.install.packageName)throw new Error("OpenClaw Code Agent update verification found that the managed install source or package changed.");if(e.pluginVersion!==t)throw new Error(`OpenClaw Code Agent update verification found installed plugin version ${e.pluginVersion}, expected ${t}.`);let r=[e.install.recordedVersion,e.install.resolvedVersion].filter(o=>!!o);if(r.length===0||r.some(o=>o!==t))throw new Error(`OpenClaw Code Agent update verification found managed install version ${r.join("/")||"unknown"}, expected ${t}.`)}function Nr(n){let t=te(n)?.match(/^((?:0|[1-9]\d*))\.((?:0|[1-9]\d*))\.((?:0|[1-9]\d*))$/);if(!t?.[1]||!t[2]||!t[3])return;let r=[Number(t[1]),Number(t[2]),Number(t[3])];return r.every(Number.isSafeInteger)?r:void 0}function Wl(n,e){let t=Nr(n),r=Nr(e);if(!t||!r)return!1;for(let o=0;o<3;o+=1){if(t[o]>r[o])return!0;if(t[o]<r[o])return!1}return!1}function Ll(n){if(!fe(n))return{};let e={};for(let t of["lastCheckedAt","latestVersion","promptedVersion","lastPromptedAt","dismissedVersion","lastDismissedAt","updateInstalledVersion","restartPromptedVersion","lastError"]){let r=n[t];typeof r=="string"&&r.trim()&&(e[t]=r)}return e}function mi(n){if(!(!n?.provider||!n.target||n.provider==="system"||n.target==="system"))return{channel:n.provider,target:n.target,accountId:n.accountId,threadId:n.threadId,sessionKey:n.sessionKey}}function fi(){if(_.fallbackChannel)return ue(_.fallbackChannel)}async function Fl(){let{fetchNpmReleaseMetadata:n}=await import("./chunks/npm-release-client.js"),e=await n(_l,El),t=fe(e)&&typeof e.version=="string"?te(e.version):void 0;return t?{version:t}:void 0}async function Bl(n,e){let t=await n("openclaw",["plugins","search",e,"--limit","100","--json"]),r;try{r=JSON.parse(t.stdout)}catch{throw new Error("OpenClaw returned invalid JSON while checking ClawHub for OpenClaw Code Agent updates.")}let o=fe(r)&&Array.isArray(r.results)?r.results:[];for(let i of o){if(!fe(i)||!fe(i.package)||ee(i.package,"name")!==e)continue;let s=te(ee(i.package,"latestVersion"));return s?{version:s}:void 0}}async function Kl(n){let e=Er(await n("openclaw",["plugins","inspect",rt,"--json"]));return e.install.source==="npm"?Fl():Bl(n,e.install.packageName)}async function ql(n,e){let t=await Ml(n,e,{timeout:12e4,maxBuffer:1048576});return{stdout:t.stdout?.toString()??"",stderr:t.stderr?.toString()??""}}var Ut=class{constructor(e){this.options=e;this.statePath=xl(e.stateDir,Dl),this.notifier=e.notifier??new We,this.runCommand=e.runCommand??ql,this.fetchLatestRelease=e.fetchLatestRelease??(()=>Kl(this.runCommand)),this.now=e.now??Date.now}options;statePath;notifier;fetchLatestRelease;runCommand;now;checkInFlight;maybeCheckForUpdate(e={}){this.checkInFlight||(this.checkInFlight=this.checkForUpdate(e).catch(t=>{`${$r(t)}`}).finally(()=>{this.checkInFlight=void 0}))}async waitForIdle(){await this.checkInFlight}async installConfirmed(e,t){let r=te(e);if(!r||!Nr(r))return"Could not determine which stable OpenClaw Code Agent version to update to.";let o=Er(await this.runCommand("openclaw",["plugins","inspect",rt,"--json"])),i=await this.runCommand("openclaw",Nl(o.install,r));if(/No install record/i.test(`${i.stdout}
3
3
  ${i.stderr}`))throw new Error("OpenClaw reported no managed install record while updating OpenClaw Code Agent.");let s=Er(await this.runCommand("openclaw",["plugins","inspect",rt,"--json"]));Ol(o,s,r);let a=this.readState();this.writeState({...a,updateInstalledVersion:r});let l=mi(t?.route??fi());if(l)try{return await this.sendRestartPrompt(l,r),`OpenClaw Code Agent ${r} installation was verified. Restart confirmation was sent.`}catch(d){`${r}${$r(d)}`}return[`OpenClaw Code Agent ${r} installation was verified.`,"Restart the Gateway explicitly to load it: openclaw gateway restart"].join(`
4
4
  `)}async restartConfirmed(e){let t=te(e);return await this.runCommand("openclaw",["gateway","restart"]),t?`Gateway restart requested for OpenClaw Code Agent ${t}.`:"Gateway restart requested."}dismiss(e){return this.postpone(e,"Dismissed")}remindLater(e){return this.postpone(e,"Will remind later about")}postpone(e,t){let r=te(e),o=this.readState();return this.writeState({...o,...r?{dismissedVersion:r,lastDismissedAt:new Date(this.now()).toISOString()}:{}}),r?`${t} OpenClaw Code Agent ${r} update reminder.`:`${t} OpenClaw Code Agent update reminder.`}async checkForUpdate(e){let t=this.readState(),r=t.lastCheckedAt?Date.parse(t.lastCheckedAt):Number.NaN;if(Number.isFinite(r)&&this.now()-r<gi){await this.promptFromState(t,e);return}let o=new Date(this.now()).toISOString(),i={...t,lastCheckedAt:o};delete i.lastError,this.writeState(i);try{let s=await this.fetchLatestRelease(),a=te(s?.version),l={...this.readState(),latestVersion:a};delete l.lastError,this.writeState(l),await this.promptFromState(l,e)}catch(s){throw this.writeState({...this.readState(),lastError:$r(s)}),s}}async promptFromState(e,t){let r=te(e.latestVersion);if(!Wl(r,this.options.currentVersion)||!this.shouldPromptForVersion(e,r))return;let o=mi(t.route??fi());o&&(await this.sendUpdatePrompt(o,r),this.writeState({...this.readState(),latestVersion:r,promptedVersion:r,lastPromptedAt:new Date(this.now()).toISOString()}))}async sendUpdatePrompt(e,t){await this.notifier.send(e,[`OpenClaw Code Agent update available: ${this.options.currentVersion} -> ${t}.`,"","Update now will reinstall the exact approved version from OpenClaw Code Agent's recorded npm or ClawHub source, then verify it.","If the update succeeds, OpenClaw Code Agent will ask separately before restarting the Gateway."].join(`