@netlify/agent-runner-cli 1.93.1 → 1.93.2
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/bin-local.js +2 -2
- package/dist/bin.js +2 -2
- package/dist/index.js +2 -2
- package/package.json +2 -2
package/dist/bin-local.js
CHANGED
|
@@ -5,7 +5,7 @@ import G from"process";import Zr from"path";import Qr from"fs";import Oi from"mi
|
|
|
5
5
|
${s}
|
|
6
6
|
</extracted_error_chunk>`).join(`
|
|
7
7
|
|
|
8
|
-
`);return o.length>e.length*.8?e:o}import{execSync as ei}from"child_process";import Pr from"fs/promises";import ti from"path";import _e from"process";import{getTracer as ri}from"@netlify/otel";import Oe from"process";var te=class extends Error{constructor(r,i,n,o=!1){super(r);this.statusCode=i;this.userMessage=n;this.isCreditLimitExceeded=o;this.name="GracefulShutdownError"}},We=e=>e instanceof te;var Ke=Oe.env.NETLIFY_API_URL,Je=Oe.env.NETLIFY_API_TOKEN,W=I("api"),Te=()=>Oe.env.NETLIFY_LOCAL_MODE==="true",ue=async(e,t={})=>{if(!Ke||!Je)throw new Error("No API URL or token");let r=new URL(e,Ke),i={...t,headers:{...t.headers,Authorization:`Bearer ${Je}`}};Oe.env.AGENT_RUNNERS_DEBUG==="true"&&(i.headers["x-nf-debug-logging"]="true"),t.json&&(i.headers||={},i.headers["Content-Type"]="application/json",i.body=JSON.stringify(t.json));let n=await fetch(r,i),o=n.ok&&n.status<=299;if(Oe.env.AGENT_RUNNERS_DEBUG==="true")W.log(`Response headers for ${r}:`),n.headers.forEach((a,l)=>{W.log(` ${l}: ${a}`)});else{let a=n.headers.get("x-request-id")||n.headers.get("x-nf-request-id");W.log(`Request ID for ${r}: ${a||"N/A"}`)}if(o||W.error(`Got status ${n.status} for request ${r}`),t.raw){if(!o)throw new Error(`API request failed: ${n.status} ${n.statusText}`);return n}let s=await(n.headers.get("content-type")?.includes("application/json")?n.json():n.text());if(!o){let a=typeof s=="string"?s:JSON.stringify(s);throw n.status===404?new te(`API request failed: 404 - ${a}`,404,"The site associated with this agent run no longer exists."):n.status===503&&t.gracefulOn503&&a.toLowerCase().includes("usage exceeded")?new te(`API request failed: 503 - ${a}`,503,"Credit limit reached. Please add more credits to continue using Agent Runners.",!0):new Error(`API request failed: ${n.status} - ${a}`)}return s},Kt=e=>{W.log("Setting details for api",{apiUrl:e?.constants?.NETLIFY_API_HOST,token:!!e?.constants?.NETLIFY_API_TOKEN}),e?.constants?.NETLIFY_API_HOST&&(Ke=`https://${e.constants.NETLIFY_API_HOST}`),e?.constants?.NETLIFY_API_TOKEN&&(Je=e.constants.NETLIFY_API_TOKEN)},Jt=()=>({apiUrl:Ke,token:Je}),Fe=async(e,t)=>Te()?(W.log("Mock API: updateRunner called",{runnerId:e,data:t}),{id:e,...t}):ue(`/api/v1/agent_runners/${e}`,{method:"PUT",json:t}),K=async(e,t,r)=>Te()?(W.log("Mock API: updateRunnerSession called",JSON.stringify({runnerId:e,sessionId:t,data:r},null,2)),{id:e,sessionId:t,...r}):ue(`/api/v1/agent_runners/${e}/sessions/${t}`,{method:"PUT",json:r});var Vt=async e=>Te()?(W.log("Mock API: getSite called",{siteId:e}),{id:e,published_deploy:{id:"id"}}):ue(`/api/v1/sites/${e}`),zt=async(e,t)=>Te()?(W.log("Mock API: getRunnerSession called",{runnerId:e,sessionId:t}),{id:t,runnerId:e,state:"running"}):ue(`/api/v1/agent_runners/${e}/sessions/${t}`),Xt=(e,t,r)=>ue(`/api/v1/accounts/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r},gracefulOn503:!0}),Zt=(e,t,r)=>ue(`/api/v1/sites/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r},gracefulOn503:!0}),Qt=async(e,t)=>Te()?(W.log("Mock API: getDiffUploadUrls called",{runnerId:e,sessionId:t}),{result:{upload_url:"https://s3.mock.com/mock-upload-url-result",s3_key:"mock-s3-key-result"},cumulative:{upload_url:"https://s3.mock.com/mock-upload-url-cumulative",s3_key:"mock-s3-key-cumulative"}}):ue(`/api/v1/agent_runners/${e}/sessions/${t}/diff/upload_urls`,{method:"POST"}),er=async(e,t)=>Te()?(W.log("Mock API: updateSessionUsage called",{runnerId:e,sessionId:t}),{id:t,runnerId:e,usage:0}):ue(`/api/v1/agent_runners/${e}/sessions/${t}/update_usage`,{method:"POST"}),mt=async(e,t,{maxRetries:r=3,baseDelayMs:i=500}={})=>{W.log(`Uploading diff to S3: ${e.substring(0,50)}...`);for(let n=1;n<=r;n++)try{let o=await fetch(e,{method:"PUT",body:t,headers:{"Content-Type":"text/plain"}});if(!o.ok)throw new Error(`S3 upload failed with status ${o.status}`);return o}catch(o){if(n===r)throw o;let s=i*2**(n-1);W.warn(`S3 upload attempt ${n}/${r} failed: ${o.message}. Retrying in ${s}ms...`),await new Promise(a=>setTimeout(a,s))}};var Ie=I("ai_gateway"),gt=null;var Ve=async()=>{if(gt)return gt;Ie.log("Fetching available AI gateway providers");let e=await fetch(`${Jt().apiUrl}/api/v1/ai-gateway/providers`);if(!e.ok)throw new Error(`Failed to fetch AI gateway providers: ${e.statusText}`);let t=await e.json();return gt=t,Ie.log("Cached AI gateway providers",{providerCount:Object.keys(t.providers).length}),t},ln=async(e,t)=>{let i=(await Ve()).providers[e];if(!i)return Ie.log(`Provider '${e}' not found`),!1;let n=i.models.includes(t);return Ie.log(`Model validation for ${e}/${t}`,{isAvailable:n}),n},tr=async({config:e})=>{let t,r,i,n,o=!e.site?.published_deploy;if(!(o?e.accountId:e.siteId))throw new Error(`No entity id for ${o?"account":"site"}`);let a=async()=>{clearTimeout(i),Ie.log("Requesting AI gateway information");let c=await(o?Xt(e.accountId,e.id,e.sessionId):Zt(e.siteId,e.id,e.sessionId));if({token:t,url:n}=c,r=c.expires_at?c.expires_at*1e3:void 0,Ie.log("Got AI gateway information",{token:!!t,expiresAt:r,url:n}),r){let u=r-Date.now()-6e4;u>0&&(i=setTimeout(()=>{a()},u))}};return await Promise.all([a(),Ve()]),{get url(){return n},get token(){return t},isModelAvailableForProvider:ln}};import ne from"process";import se from"path";import Ze from"fs";import{fileURLToPath as hn}from"url";import{createRequire as yn}from"module";import{execa as wn,execaCommand as go}from"execa";import{Transform as cn}from"stream";function un(){let e=process.env.NETLIFY_SENSITIVE_ENV_KEYS;return e?e.split(",").map(t=>t.trim()).filter(Boolean):[]}function dn(e){let t=e.toLowerCase();return t==="true"||t==="false"?!0:e.trim().length<4}function pn(){let t=un().map(r=>process.env[r]).filter(r=>!(!r||dn(r)));return[...new Set(t)].sort((r,i)=>i.length-r.length)}function oe(e){if(typeof e!="string")return e;let t=pn();if(t.length===0)return e;let r=e;return t.forEach(i=>{let n=new RegExp(mn(i),"g");r=r.replace(n,"******")}),r}function mn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Se=class extends cn{constructor(t={}){super({...t,objectMode:!1})}_transform(t,r,i){let n=t.toString(),o=oe(n);i(null,o)}};function rr(){if(!(process.env.NETLIFY_MASK_LOGS!=="false"))return;let t=process.stdout.write.bind(process.stdout),r=process.stderr.write.bind(process.stderr);process.stdout.write=function(i,n,o){let s=typeof i=="string"?oe(i):i;return typeof n=="function"?t(s,n):t(s,n,o)},process.stderr.write=function(i,n,o){let s=typeof i=="string"?oe(i):i;return typeof n=="function"?r(s,n):r(s,n,o)}}var Le=null,nr=e=>(Le&&Le.destroy(),Le=new de({totalAllowedTime:e}),Le),ir=()=>Le;var de=class{constructor({totalAllowedTime:t}){this.withStageTimer=async(t,r,i)=>{if(this.isTimeExpired())throw new Error(`${t} stage did not complete in the allowed time. Time has already expired.`);let n=this.onTimesUp(()=>{throw new Error(`${t} stage did not complete in the allowed time.`)}),o=null,s=null;i!==void 0&&(s=new Promise((a,l)=>{o=setTimeout(()=>{l(new Error(`${t} stage exceeded its maximum duration of ${i}ms`))},i)}));try{return s?await Promise.race([r(),s]):await r()}finally{n(),o&&clearTimeout(o)}};this.startTime=Date.now(),this.totalAllowedTime=t,this.globalTimeoutId=null,this.subscribers=[],this.hasTimedOut=!1,this.setupGlobalTimeout()}getElapsedTime(){return Date.now()-this.startTime}getRemainingTime(){let t=this.getElapsedTime(),r=this.totalAllowedTime-t;return Math.max(0,r)}isTimeExpired(){return this.getRemainingTime()===0||this.hasTimedOut}setupGlobalTimeout(){this.globalTimeoutId&&clearTimeout(this.globalTimeoutId),this.globalTimeoutId=setTimeout(()=>{this.notifyTimeUp()},this.totalAllowedTime)}notifyTimeUp(){this.hasTimedOut=!0;for(let t=this.subscribers.length-1;t>=0;t--)try{this.subscribers[t]()}catch(r){console.error("TimeKeeper: Error in time up callback:",r)}}onTimesUp(t){if(this.subscribers.push(t),this.hasTimedOut)try{t()}catch(r){console.error("TimeKeeper: Error in time up callback:",r)}return()=>{let r=this.subscribers.indexOf(t);r>-1&&this.subscribers.splice(r,1)}}off(t){let r=this.subscribers.indexOf(t);r>-1&&this.subscribers.splice(r,1)}clearSubscribers(){this.subscribers.length=0}getSubscriberCount(){return this.subscribers.length}destroy(){this.globalTimeoutId&&(clearTimeout(this.globalTimeoutId),this.globalTimeoutId=null),this.clearSubscribers()}static{this.timeUnits={seconds:t=>t*1e3,minutes:t=>t*60*1e3,hours:t=>t*60*60*1e3}}};var or="netlify-agent-runner-context.md",ft="task-history",re=".netlify",fe="results.md",ht="assets";var sr="free";var he=1800*1e3,gn=["\\.claude","\\.gemini","\\.codex","\\.agents"],ze=new RegExp(`(^|/)(${gn.join("|")})/skills/`),Xe=/(^|\/)((CLAUDE|AGENTS|GEMINI)(\.local)?\.md)$/,f={Environment:"environment",UserMessage:"user-message",AgentMessage:"agent-message",Task:"task",RunCommand:"run-command",Explore:"explore",Plan:"plan",FileRead:"file-read",FileWrite:"file-write",Notebook:"notebook",Web:"web",Todo:"todo",Reasoning:"reasoning",Skill:"skill",Memorize:"memorize",Deployment:"deployment",SiteGeneration:"site-generation"};var ar={name:"@netlify/agent-runner-cli",type:"module",version:"1.93.1",description:"CLI tool for running Netlify agents",main:"./dist/index.js",types:"./dist/index.d.ts",exports:"./dist/index.js",bin:{"agent-runner-cli":"./dist/bin.js","agent-runner-cli-local":"./dist/bin-local.js"},files:["dist/**/*.js","dist/**/*.d.ts","dist/skills/**","patches","scripts"],scripts:{build:"tsup",dev:"tsup --watch",prepare:"husky install node_modules/@netlify/eslint-config-node/.husky/",prepublishOnly:"npm ci && npm test",prepack:"npm run build",test:"run-s build format test:dev",format:"run-s build format:check-fix:*","format:ci":"run-s build format:check:*","format:check-fix:lint":"run-e format:check:lint format:fix:lint","format:check:lint":"cross-env-shell eslint $npm_package_config_eslint","format:fix:lint":"cross-env-shell eslint --fix $npm_package_config_eslint","format:check-fix:prettier":"run-e format:check:prettier format:fix:prettier","format:check:prettier":"cross-env-shell prettier --check $npm_package_config_prettier","format:fix:prettier":"cross-env-shell prettier --write $npm_package_config_prettier","test:dev":"run-s build test:dev:*","test:ci":"run-s build test:ci:*","test:dev:vitest":"LOG=0 vitest --exclude '**/integration/**'","test:ci:vitest":"LOG=0 c8 -r lcovonly -r text -r json vitest --exclude '**/integration/**'","test:integration":"vitest run test/integration/","test:integration:codex":"vitest run test/integration/codex.test.ts","test:integration:claude":"vitest run test/integration/claude.test.ts","test:integration:gemini":"vitest run test/integration/gemini.test.ts","test:integration:create-stage":"vitest run test/integration/create.test.ts","test:integration:skill-invocation":"vitest run test/integration/skill-invocation.test.ts","check:types":"tsc --noEmit",postinstall:"node scripts/postinstall.js"},config:{eslint:'--cache --format=codeframe --max-warnings=0 "{src,scripts,test,.github}/**/*.{js,ts,md,html}"',prettier:'--ignore-path .gitignore --loglevel=warn "{src,scripts,test,.github}/**/*.{js,ts,md,yml,json,html}" "*.{js,ts,yml,json,html}" ".*.{js,ts,yml,json,html}" "!**/package-lock.json" "!package-lock.json" "!src/skills/**/*.md"'},keywords:[],license:"MIT",repository:"netlify/agent-runner-cli",bugs:{url:"https://github.com/netlify/agent-runner-cli/issues"},author:"Netlify Inc.",directories:{test:"test"},devDependencies:{"@commitlint/cli":"^20.0.0","@commitlint/config-conventional":"^20.0.0","@eslint/compat":"^2.0.0","@eslint/js":"^9.35.0","@netlify/eslint-config-node":"^7.0.1","@types/node":"^24.5.0","@typescript-eslint/eslint-plugin":"^8.0.0","@typescript-eslint/parser":"^8.0.0","@vitest/eslint-plugin":"^1.6.6",c8:"^10.0.0","eslint-config-prettier":"^10.1.8","eslint-plugin-n":"^17.0.0",husky:"^9.0.0","patch-package":"^8.0.0",tsup:"^8.5.0",typescript:"^5.0.0","typescript-eslint":"^8.44.0",vitest:"^4.0.16"},dependencies:{"@anthropic-ai/claude-code":"2.1.81","@anthropic-ai/sdk":"0.78.0","@google/gemini-cli":"0.31.0","@netlify/otel":"^5.1.5","@netlify/ts-cli":"^1.0.3","@openai/codex":"0.115.0","@opentelemetry/exporter-trace-otlp-grpc":"0.57.2",execa:"^9.6.1",minimist:"^1.2.8",openai:"6.26.0"}};var _n=hn(import.meta.url),En=se.dirname(_n),xn=yn(import.meta.url),ve=I("shell"),yt=new Set,Tn={preferLocal:!0},P=(e,t,r)=>{let[i,n]=In(t,r),o={...Tn,...n},s=wn(e,i,o);Sn(s,o),bn(s);let a=r?.idleTimeout;return a&&a>0&&vn(s,a),s};var In=function(e,t){return Array.isArray(e)?[e,t]:typeof e=="object"&&e!==null?[[],e]:[[],void 0]},Sn=(e,t)=>{if(t.stdio!==void 0||t.stdout!==void 0||t.stderr!==void 0)return;if(ne.env.NETLIFY_MASK_LOGS!=="false"){e.all?.pipe(new Se).pipe(ne.stdout),e.stdout?.pipe(new Se).pipe(ne.stdout),e.stderr?.pipe(new Se).pipe(ne.stderr);return}e.stdout?.pipe(ne.stdout),e.stderr?.pipe(ne.stderr)},wt=(e,t="SIGTERM")=>{try{return e.pid&&!e.killed?(ne.kill(-e.pid,t),ve.log(`Killed process ${e.pid} with signal ${t}`),!0):!1}catch(r){return ve.error("Error killing process:",r),!1}},lr=e=>wt(e,"SIGKILL"),vn=(e,t)=>{let r=null,i=()=>{ve.log(`Process ${e.pid} killed due to idle timeout (no output for ${t}ms)`),wt(e,"SIGTERM"),setTimeout(()=>{e.pid&&!e.killed&&(ve.log(`Force killing idle process ${e.pid}`),lr(e))},5e3)},n=()=>{r&&clearTimeout(r),r=setTimeout(i,t)};n(),e.stdout?.on("data",n),e.stderr?.on("data",n);let o=()=>{r&&(clearTimeout(r),r=null)};e.on("exit",o),e.on("error",o)},bn=e=>{yt.add(e);let t=ir();if(t){let r=t.onTimesUp(()=>{ve.log(`Global timer expired, killing process ${e.pid}`),wt(e,"SIGTERM"),setTimeout(()=>{e.pid&&!e.killed&&(ve.log(`Force killing process ${e.pid} after timeout`),lr(e))},5e3)});e.on("exit",()=>{yt.delete(e),r()}),e.on("error",()=>{yt.delete(e),r()})}};function Qe(e,t){return!!ae(e,t)}function ae(e,t){if(!ne.env.NETLIFY_LOCAL_MODE)try{let n=xn.resolve(ar.name),o=se.dirname(n);for(;o!==se.dirname(o);){let s=se.dirname(o);if(se.basename(s)==="node_modules"){let a=se.join(s,".bin",t);if(Ze.existsSync(a))return a;break}o=s}}catch(n){console.error("Could not resolve package.json",n)}if(ne.env.NODE_PATH){let n=se.join(ne.env.NODE_PATH,".bin",t);if(Ze.existsSync(n))return n}let r=se.join(e,"node_modules",".bin",t);if(Ze.existsSync(r))return r;let i=se.join(En,"..","node_modules",".bin",t);if(Ze.existsSync(i))return i}var Rn=I("utils"),An=e=>new Promise(t=>{setTimeout(t,e)}),et=(e,t=3e3)=>{let r=!1,i=null,n=[],o=null,s=(...a)=>{if(r)return i=a,new Promise(u=>{n.push(u)});r=!0;let l,c=new Promise(u=>{l=u});return o=(async()=>{await Promise.resolve();let u=await e(...a);for(l(u);;){if(await An(t),!i)return r=!1,o=null,u;let d=i,p=n;i=null,n=[],u=await e(...d),p.forEach(g=>{g(u)})}})(),c};return s.flush=async()=>{if((r||i)&&o)return await o,s.flush()},s},be=(e,t,r=!1)=>{let i=null,n=null,o=null,s=function(...a){n=a,o=this;let l=r&&!i;clearTimeout(i),i=setTimeout(()=>{i=null,r||(e.apply(o,n),n=null,o=null)},t),l&&(e.apply(o,n),n=null,o=null)};return s.cancel=()=>{clearTimeout(i),i=null,n=null,o=null},s.flush=()=>{if(i){clearTimeout(i);let a=n,l=o;i=null,n=null,o=null,e.apply(l,a)}},s},cr=(e,t=!0,r)=>{if(e)try{return JSON.parse(e)}catch(i){t&&(r?.error?r.error("Could not parse JSON",i):Rn.error("Could not parse JSON",i))}},_t=e=>e.charAt(0).toUpperCase()+e.slice(1),pe=e=>e.split("-").map(t=>t.length===2?t.toUpperCase():_t(t)).join(" ");function ye(e,t){t&&e.log(`Skill invoked: ${t}`)}var ur=e=>Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0)),dr=(e,t)=>{let n=".netlify.app",o="agent-";if(!t)return`${o}${e.slice(0,6)}`;let a=`--${t}${n}`;if(a.length>55)return"";let l=60-a.length;if(l<=0)return"";if(l>=o.length+6){let c=Math.min(l-o.length,e.length);return`${o}${e.slice(0,c)}`}return e.slice(0,l)};var Cn=1e4,Et=(e,t=Cn)=>{if(!e||typeof e!="string"||e.length<=t)return e;let i=e.startsWith("```")?"\n... [truncated]\n```":"... [truncated]";return e.slice(0,t)+i};import{Buffer as pr}from"buffer";import kn from"path";var mr=I("repo"),fr=async({config:e,isRetry:t,cwd:r=process.cwd()})=>{mr.info("Getting runner diffs");let i=await Nn(r),{hasChanges:n}=i,{status:o}=i;if(!n)return{hasChanges:!1};if(!t){let _=On(o);await Fn(_,r)}mr.info("Changes after processing"),await Tt(r);let s=await It(o,r);if(await xt(s,r),n=await $n(r),!n)return{hasChanges:!1,ignored:s};process.env.NETLIFY_INTERNAL_GIT="1";try{await P("git",["commit","-m","Agent runner"],{cwd:r})}finally{process.env.NETLIFY_INTERNAL_GIT="0"}let a={stdio:["ignore","pipe","pipe"],cwd:r},l=await P("git",["diff",e.runSha,"HEAD"],a),c=String(l.stdout??"");if(n=!!c,!n)return await gr(r),{hasChanges:!1,ignored:s};let u=await P("git",["diff",e.runSha,"HEAD","--binary"],a),d=String(u.stdout??""),p,g;if(e.sha){let _=await P("git",["diff",e.sha,"HEAD"],a);p=String(_.stdout??"");let T=await P("git",["diff",e.sha,"HEAD","--binary"],a),w=String(T.stdout??"");p!==w&&(g=pr.from(w).toString("base64"))}await gr(r);let x={hasChanges:!0,diff:c,resultDiff:p,ignored:s};return c!==d&&(x.diffBinary=pr.from(d).toString("base64")),g&&(x.resultDiffBinary=g),x},gr=async(e=process.cwd())=>{process.env.NETLIFY_LOCAL_MODE&&await P("git",["reset","--soft","HEAD~1"],{cwd:e})},xt=async(e=[],t=process.cwd())=>{process.env.NETLIFY_INTERNAL_GIT="1";try{await P("git",["add",".",...e],{cwd:t})}finally{process.env.NETLIFY_INTERNAL_GIT="0"}},Tt=async(e=process.cwd())=>{let t=await P("git",["status","-s"],{cwd:e});return String(t.stdout??"")},hr=/.. (.+)?\.log$/,Pn=[hr],Nn=async(e=process.cwd())=>{let t=await Tt(e);return{hasChanges:(t.trim().length===0?[]:t.split(`
|
|
8
|
+
`);return o.length>e.length*.8?e:o}import{execSync as ei}from"child_process";import Pr from"fs/promises";import ti from"path";import _e from"process";import{getTracer as ri}from"@netlify/otel";import Oe from"process";var te=class extends Error{constructor(r,i,n,o=!1){super(r);this.statusCode=i;this.userMessage=n;this.isCreditLimitExceeded=o;this.name="GracefulShutdownError"}},We=e=>e instanceof te;var Ke=Oe.env.NETLIFY_API_URL,Je=Oe.env.NETLIFY_API_TOKEN,W=I("api"),Te=()=>Oe.env.NETLIFY_LOCAL_MODE==="true",ue=async(e,t={})=>{if(!Ke||!Je)throw new Error("No API URL or token");let r=new URL(e,Ke),i={...t,headers:{...t.headers,Authorization:`Bearer ${Je}`}};Oe.env.AGENT_RUNNERS_DEBUG==="true"&&(i.headers["x-nf-debug-logging"]="true"),t.json&&(i.headers||={},i.headers["Content-Type"]="application/json",i.body=JSON.stringify(t.json));let n=await fetch(r,i),o=n.ok&&n.status<=299;if(Oe.env.AGENT_RUNNERS_DEBUG==="true")W.log(`Response headers for ${r}:`),n.headers.forEach((a,l)=>{W.log(` ${l}: ${a}`)});else{let a=n.headers.get("x-request-id")||n.headers.get("x-nf-request-id");W.log(`Request ID for ${r}: ${a||"N/A"}`)}if(o||W.error(`Got status ${n.status} for request ${r}`),t.raw){if(!o)throw new Error(`API request failed: ${n.status} ${n.statusText}`);return n}let s=await(n.headers.get("content-type")?.includes("application/json")?n.json():n.text());if(!o){let a=typeof s=="string"?s:JSON.stringify(s);throw n.status===404?new te(`API request failed: 404 - ${a}`,404,"The site associated with this agent run no longer exists."):n.status===503&&t.gracefulOn503&&a.toLowerCase().includes("usage exceeded")?new te(`API request failed: 503 - ${a}`,503,"Credit limit reached. Please add more credits to continue using Agent Runners.",!0):new Error(`API request failed: ${n.status} - ${a}`)}return s},Kt=e=>{W.log("Setting details for api",{apiUrl:e?.constants?.NETLIFY_API_HOST,token:!!e?.constants?.NETLIFY_API_TOKEN}),e?.constants?.NETLIFY_API_HOST&&(Ke=`https://${e.constants.NETLIFY_API_HOST}`),e?.constants?.NETLIFY_API_TOKEN&&(Je=e.constants.NETLIFY_API_TOKEN)},Jt=()=>({apiUrl:Ke,token:Je}),Fe=async(e,t)=>Te()?(W.log("Mock API: updateRunner called",{runnerId:e,data:t}),{id:e,...t}):ue(`/api/v1/agent_runners/${e}`,{method:"PUT",json:t}),K=async(e,t,r)=>Te()?(W.log("Mock API: updateRunnerSession called",JSON.stringify({runnerId:e,sessionId:t,data:r},null,2)),{id:e,sessionId:t,...r}):ue(`/api/v1/agent_runners/${e}/sessions/${t}`,{method:"PUT",json:r});var Vt=async e=>Te()?(W.log("Mock API: getSite called",{siteId:e}),{id:e,published_deploy:{id:"id"}}):ue(`/api/v1/sites/${e}`),zt=async(e,t)=>Te()?(W.log("Mock API: getRunnerSession called",{runnerId:e,sessionId:t}),{id:t,runnerId:e,state:"running"}):ue(`/api/v1/agent_runners/${e}/sessions/${t}`),Xt=(e,t,r)=>ue(`/api/v1/accounts/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r},gracefulOn503:!0}),Zt=(e,t,r)=>ue(`/api/v1/sites/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r},gracefulOn503:!0}),Qt=async(e,t)=>Te()?(W.log("Mock API: getDiffUploadUrls called",{runnerId:e,sessionId:t}),{result:{upload_url:"https://s3.mock.com/mock-upload-url-result",s3_key:"mock-s3-key-result"},cumulative:{upload_url:"https://s3.mock.com/mock-upload-url-cumulative",s3_key:"mock-s3-key-cumulative"}}):ue(`/api/v1/agent_runners/${e}/sessions/${t}/diff/upload_urls`,{method:"POST"}),er=async(e,t)=>Te()?(W.log("Mock API: updateSessionUsage called",{runnerId:e,sessionId:t}),{id:t,runnerId:e,usage:0}):ue(`/api/v1/agent_runners/${e}/sessions/${t}/update_usage`,{method:"POST"}),mt=async(e,t,{maxRetries:r=3,baseDelayMs:i=500}={})=>{W.log(`Uploading diff to S3: ${e.substring(0,50)}...`);for(let n=1;n<=r;n++)try{let o=await fetch(e,{method:"PUT",body:t,headers:{"Content-Type":"text/plain"}});if(!o.ok)throw new Error(`S3 upload failed with status ${o.status}`);return o}catch(o){if(n===r)throw o;let s=i*2**(n-1);W.warn(`S3 upload attempt ${n}/${r} failed: ${o.message}. Retrying in ${s}ms...`),await new Promise(a=>setTimeout(a,s))}};var Ie=I("ai_gateway"),gt=null;var Ve=async()=>{if(gt)return gt;Ie.log("Fetching available AI gateway providers");let e=await fetch(`${Jt().apiUrl}/api/v1/ai-gateway/providers`);if(!e.ok)throw new Error(`Failed to fetch AI gateway providers: ${e.statusText}`);let t=await e.json();return gt=t,Ie.log("Cached AI gateway providers",{providerCount:Object.keys(t.providers).length}),t},ln=async(e,t)=>{let i=(await Ve()).providers[e];if(!i)return Ie.log(`Provider '${e}' not found`),!1;let n=i.models.includes(t);return Ie.log(`Model validation for ${e}/${t}`,{isAvailable:n}),n},tr=async({config:e})=>{let t,r,i,n,o=!e.site?.published_deploy;if(!(o?e.accountId:e.siteId))throw new Error(`No entity id for ${o?"account":"site"}`);let a=async()=>{clearTimeout(i),Ie.log("Requesting AI gateway information");let c=await(o?Xt(e.accountId,e.id,e.sessionId):Zt(e.siteId,e.id,e.sessionId));if({token:t,url:n}=c,r=c.expires_at?c.expires_at*1e3:void 0,Ie.log("Got AI gateway information",{token:!!t,expiresAt:r,url:n}),r){let u=r-Date.now()-6e4;u>0&&(i=setTimeout(()=>{a()},u))}};return await Promise.all([a(),Ve()]),{get url(){return n},get token(){return t},isModelAvailableForProvider:ln}};import ne from"process";import se from"path";import Ze from"fs";import{fileURLToPath as hn}from"url";import{createRequire as yn}from"module";import{execa as wn,execaCommand as go}from"execa";import{Transform as cn}from"stream";function un(){let e=process.env.NETLIFY_SENSITIVE_ENV_KEYS;return e?e.split(",").map(t=>t.trim()).filter(Boolean):[]}function dn(e){let t=e.toLowerCase();return t==="true"||t==="false"?!0:e.trim().length<4}function pn(){let t=un().map(r=>process.env[r]).filter(r=>!(!r||dn(r)));return[...new Set(t)].sort((r,i)=>i.length-r.length)}function oe(e){if(typeof e!="string")return e;let t=pn();if(t.length===0)return e;let r=e;return t.forEach(i=>{let n=new RegExp(mn(i),"g");r=r.replace(n,"******")}),r}function mn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Se=class extends cn{constructor(t={}){super({...t,objectMode:!1})}_transform(t,r,i){let n=t.toString(),o=oe(n);i(null,o)}};function rr(){if(!(process.env.NETLIFY_MASK_LOGS!=="false"))return;let t=process.stdout.write.bind(process.stdout),r=process.stderr.write.bind(process.stderr);process.stdout.write=function(i,n,o){let s=typeof i=="string"?oe(i):i;return typeof n=="function"?t(s,n):t(s,n,o)},process.stderr.write=function(i,n,o){let s=typeof i=="string"?oe(i):i;return typeof n=="function"?r(s,n):r(s,n,o)}}var Le=null,nr=e=>(Le&&Le.destroy(),Le=new de({totalAllowedTime:e}),Le),ir=()=>Le;var de=class{constructor({totalAllowedTime:t}){this.withStageTimer=async(t,r,i)=>{if(this.isTimeExpired())throw new Error(`${t} stage did not complete in the allowed time. Time has already expired.`);let n=this.onTimesUp(()=>{throw new Error(`${t} stage did not complete in the allowed time.`)}),o=null,s=null;i!==void 0&&(s=new Promise((a,l)=>{o=setTimeout(()=>{l(new Error(`${t} stage exceeded its maximum duration of ${i}ms`))},i)}));try{return s?await Promise.race([r(),s]):await r()}finally{n(),o&&clearTimeout(o)}};this.startTime=Date.now(),this.totalAllowedTime=t,this.globalTimeoutId=null,this.subscribers=[],this.hasTimedOut=!1,this.setupGlobalTimeout()}getElapsedTime(){return Date.now()-this.startTime}getRemainingTime(){let t=this.getElapsedTime(),r=this.totalAllowedTime-t;return Math.max(0,r)}isTimeExpired(){return this.getRemainingTime()===0||this.hasTimedOut}setupGlobalTimeout(){this.globalTimeoutId&&clearTimeout(this.globalTimeoutId),this.globalTimeoutId=setTimeout(()=>{this.notifyTimeUp()},this.totalAllowedTime)}notifyTimeUp(){this.hasTimedOut=!0;for(let t=this.subscribers.length-1;t>=0;t--)try{this.subscribers[t]()}catch(r){console.error("TimeKeeper: Error in time up callback:",r)}}onTimesUp(t){if(this.subscribers.push(t),this.hasTimedOut)try{t()}catch(r){console.error("TimeKeeper: Error in time up callback:",r)}return()=>{let r=this.subscribers.indexOf(t);r>-1&&this.subscribers.splice(r,1)}}off(t){let r=this.subscribers.indexOf(t);r>-1&&this.subscribers.splice(r,1)}clearSubscribers(){this.subscribers.length=0}getSubscriberCount(){return this.subscribers.length}destroy(){this.globalTimeoutId&&(clearTimeout(this.globalTimeoutId),this.globalTimeoutId=null),this.clearSubscribers()}static{this.timeUnits={seconds:t=>t*1e3,minutes:t=>t*60*1e3,hours:t=>t*60*60*1e3}}};var or="netlify-agent-runner-context.md",ft="task-history",re=".netlify",fe="results.md",ht="assets";var sr="free";var he=1800*1e3,gn=["\\.claude","\\.gemini","\\.codex","\\.agents"],ze=new RegExp(`(^|/)(${gn.join("|")})/skills/`),Xe=/(^|\/)((CLAUDE|AGENTS|GEMINI)(\.local)?\.md)$/,f={Environment:"environment",UserMessage:"user-message",AgentMessage:"agent-message",Task:"task",RunCommand:"run-command",Explore:"explore",Plan:"plan",FileRead:"file-read",FileWrite:"file-write",Notebook:"notebook",Web:"web",Todo:"todo",Reasoning:"reasoning",Skill:"skill",Memorize:"memorize",Deployment:"deployment",SiteGeneration:"site-generation"};var ar={name:"@netlify/agent-runner-cli",type:"module",version:"1.93.2",description:"CLI tool for running Netlify agents",main:"./dist/index.js",types:"./dist/index.d.ts",exports:"./dist/index.js",bin:{"agent-runner-cli":"./dist/bin.js","agent-runner-cli-local":"./dist/bin-local.js"},files:["dist/**/*.js","dist/**/*.d.ts","dist/skills/**","patches","scripts"],scripts:{build:"tsup",dev:"tsup --watch",prepare:"husky install node_modules/@netlify/eslint-config-node/.husky/",prepublishOnly:"npm ci && npm test",prepack:"npm run build",test:"run-s build format test:dev",format:"run-s build format:check-fix:*","format:ci":"run-s build format:check:*","format:check-fix:lint":"run-e format:check:lint format:fix:lint","format:check:lint":"cross-env-shell eslint $npm_package_config_eslint","format:fix:lint":"cross-env-shell eslint --fix $npm_package_config_eslint","format:check-fix:prettier":"run-e format:check:prettier format:fix:prettier","format:check:prettier":"cross-env-shell prettier --check $npm_package_config_prettier","format:fix:prettier":"cross-env-shell prettier --write $npm_package_config_prettier","test:dev":"run-s build test:dev:*","test:ci":"run-s build test:ci:*","test:dev:vitest":"LOG=0 vitest --exclude '**/integration/**'","test:ci:vitest":"LOG=0 c8 -r lcovonly -r text -r json vitest --exclude '**/integration/**'","test:integration":"vitest run test/integration/","test:integration:codex":"vitest run test/integration/codex.test.ts","test:integration:claude":"vitest run test/integration/claude.test.ts","test:integration:gemini":"vitest run test/integration/gemini.test.ts","test:integration:create-stage":"vitest run test/integration/create.test.ts","test:integration:skill-invocation":"vitest run test/integration/skill-invocation.test.ts","check:types":"tsc --noEmit",postinstall:"node scripts/postinstall.js"},config:{eslint:'--cache --format=codeframe --max-warnings=0 "{src,scripts,test,.github}/**/*.{js,ts,md,html}"',prettier:'--ignore-path .gitignore --loglevel=warn "{src,scripts,test,.github}/**/*.{js,ts,md,yml,json,html}" "*.{js,ts,yml,json,html}" ".*.{js,ts,yml,json,html}" "!**/package-lock.json" "!package-lock.json" "!src/skills/**/*.md"'},keywords:[],license:"MIT",repository:"netlify/agent-runner-cli",bugs:{url:"https://github.com/netlify/agent-runner-cli/issues"},author:"Netlify Inc.",directories:{test:"test"},devDependencies:{"@commitlint/cli":"^20.0.0","@commitlint/config-conventional":"^20.0.0","@eslint/compat":"^2.0.0","@eslint/js":"^9.35.0","@netlify/eslint-config-node":"^7.0.1","@types/node":"^24.5.0","@typescript-eslint/eslint-plugin":"^8.0.0","@typescript-eslint/parser":"^8.0.0","@vitest/eslint-plugin":"^1.6.6",c8:"^10.0.0","eslint-config-prettier":"^10.1.8","eslint-plugin-n":"^17.0.0",husky:"^9.0.0","patch-package":"^8.0.0",tsup:"^8.5.0",typescript:"^5.0.0","typescript-eslint":"^8.44.0",vitest:"^4.0.16"},dependencies:{"@anthropic-ai/claude-code":"2.1.81","@anthropic-ai/sdk":"0.78.0","@google/gemini-cli":"0.31.0","@netlify/otel":"^5.1.5","@netlify/ts-cli":"^1.0.4","@openai/codex":"0.115.0","@opentelemetry/exporter-trace-otlp-grpc":"0.57.2",execa:"^9.6.1",minimist:"^1.2.8",openai:"6.26.0"}};var _n=hn(import.meta.url),En=se.dirname(_n),xn=yn(import.meta.url),ve=I("shell"),yt=new Set,Tn={preferLocal:!0},P=(e,t,r)=>{let[i,n]=In(t,r),o={...Tn,...n},s=wn(e,i,o);Sn(s,o),bn(s);let a=r?.idleTimeout;return a&&a>0&&vn(s,a),s};var In=function(e,t){return Array.isArray(e)?[e,t]:typeof e=="object"&&e!==null?[[],e]:[[],void 0]},Sn=(e,t)=>{if(t.stdio!==void 0||t.stdout!==void 0||t.stderr!==void 0)return;if(ne.env.NETLIFY_MASK_LOGS!=="false"){e.all?.pipe(new Se).pipe(ne.stdout),e.stdout?.pipe(new Se).pipe(ne.stdout),e.stderr?.pipe(new Se).pipe(ne.stderr);return}e.stdout?.pipe(ne.stdout),e.stderr?.pipe(ne.stderr)},wt=(e,t="SIGTERM")=>{try{return e.pid&&!e.killed?(ne.kill(-e.pid,t),ve.log(`Killed process ${e.pid} with signal ${t}`),!0):!1}catch(r){return ve.error("Error killing process:",r),!1}},lr=e=>wt(e,"SIGKILL"),vn=(e,t)=>{let r=null,i=()=>{ve.log(`Process ${e.pid} killed due to idle timeout (no output for ${t}ms)`),wt(e,"SIGTERM"),setTimeout(()=>{e.pid&&!e.killed&&(ve.log(`Force killing idle process ${e.pid}`),lr(e))},5e3)},n=()=>{r&&clearTimeout(r),r=setTimeout(i,t)};n(),e.stdout?.on("data",n),e.stderr?.on("data",n);let o=()=>{r&&(clearTimeout(r),r=null)};e.on("exit",o),e.on("error",o)},bn=e=>{yt.add(e);let t=ir();if(t){let r=t.onTimesUp(()=>{ve.log(`Global timer expired, killing process ${e.pid}`),wt(e,"SIGTERM"),setTimeout(()=>{e.pid&&!e.killed&&(ve.log(`Force killing process ${e.pid} after timeout`),lr(e))},5e3)});e.on("exit",()=>{yt.delete(e),r()}),e.on("error",()=>{yt.delete(e),r()})}};function Qe(e,t){return!!ae(e,t)}function ae(e,t){if(!ne.env.NETLIFY_LOCAL_MODE)try{let n=xn.resolve(ar.name),o=se.dirname(n);for(;o!==se.dirname(o);){let s=se.dirname(o);if(se.basename(s)==="node_modules"){let a=se.join(s,".bin",t);if(Ze.existsSync(a))return a;break}o=s}}catch(n){console.error("Could not resolve package.json",n)}if(ne.env.NODE_PATH){let n=se.join(ne.env.NODE_PATH,".bin",t);if(Ze.existsSync(n))return n}let r=se.join(e,"node_modules",".bin",t);if(Ze.existsSync(r))return r;let i=se.join(En,"..","node_modules",".bin",t);if(Ze.existsSync(i))return i}var Rn=I("utils"),An=e=>new Promise(t=>{setTimeout(t,e)}),et=(e,t=3e3)=>{let r=!1,i=null,n=[],o=null,s=(...a)=>{if(r)return i=a,new Promise(u=>{n.push(u)});r=!0;let l,c=new Promise(u=>{l=u});return o=(async()=>{await Promise.resolve();let u=await e(...a);for(l(u);;){if(await An(t),!i)return r=!1,o=null,u;let d=i,p=n;i=null,n=[],u=await e(...d),p.forEach(g=>{g(u)})}})(),c};return s.flush=async()=>{if((r||i)&&o)return await o,s.flush()},s},be=(e,t,r=!1)=>{let i=null,n=null,o=null,s=function(...a){n=a,o=this;let l=r&&!i;clearTimeout(i),i=setTimeout(()=>{i=null,r||(e.apply(o,n),n=null,o=null)},t),l&&(e.apply(o,n),n=null,o=null)};return s.cancel=()=>{clearTimeout(i),i=null,n=null,o=null},s.flush=()=>{if(i){clearTimeout(i);let a=n,l=o;i=null,n=null,o=null,e.apply(l,a)}},s},cr=(e,t=!0,r)=>{if(e)try{return JSON.parse(e)}catch(i){t&&(r?.error?r.error("Could not parse JSON",i):Rn.error("Could not parse JSON",i))}},_t=e=>e.charAt(0).toUpperCase()+e.slice(1),pe=e=>e.split("-").map(t=>t.length===2?t.toUpperCase():_t(t)).join(" ");function ye(e,t){t&&e.log(`Skill invoked: ${t}`)}var ur=e=>Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0)),dr=(e,t)=>{let n=".netlify.app",o="agent-";if(!t)return`${o}${e.slice(0,6)}`;let a=`--${t}${n}`;if(a.length>55)return"";let l=60-a.length;if(l<=0)return"";if(l>=o.length+6){let c=Math.min(l-o.length,e.length);return`${o}${e.slice(0,c)}`}return e.slice(0,l)};var Cn=1e4,Et=(e,t=Cn)=>{if(!e||typeof e!="string"||e.length<=t)return e;let i=e.startsWith("```")?"\n... [truncated]\n```":"... [truncated]";return e.slice(0,t)+i};import{Buffer as pr}from"buffer";import kn from"path";var mr=I("repo"),fr=async({config:e,isRetry:t,cwd:r=process.cwd()})=>{mr.info("Getting runner diffs");let i=await Nn(r),{hasChanges:n}=i,{status:o}=i;if(!n)return{hasChanges:!1};if(!t){let _=On(o);await Fn(_,r)}mr.info("Changes after processing"),await Tt(r);let s=await It(o,r);if(await xt(s,r),n=await $n(r),!n)return{hasChanges:!1,ignored:s};process.env.NETLIFY_INTERNAL_GIT="1";try{await P("git",["commit","-m","Agent runner"],{cwd:r})}finally{process.env.NETLIFY_INTERNAL_GIT="0"}let a={stdio:["ignore","pipe","pipe"],cwd:r},l=await P("git",["diff",e.runSha,"HEAD"],a),c=String(l.stdout??"");if(n=!!c,!n)return await gr(r),{hasChanges:!1,ignored:s};let u=await P("git",["diff",e.runSha,"HEAD","--binary"],a),d=String(u.stdout??""),p,g;if(e.sha){let _=await P("git",["diff",e.sha,"HEAD"],a);p=String(_.stdout??"");let T=await P("git",["diff",e.sha,"HEAD","--binary"],a),w=String(T.stdout??"");p!==w&&(g=pr.from(w).toString("base64"))}await gr(r);let x={hasChanges:!0,diff:c,resultDiff:p,ignored:s};return c!==d&&(x.diffBinary=pr.from(d).toString("base64")),g&&(x.resultDiffBinary=g),x},gr=async(e=process.cwd())=>{process.env.NETLIFY_LOCAL_MODE&&await P("git",["reset","--soft","HEAD~1"],{cwd:e})},xt=async(e=[],t=process.cwd())=>{process.env.NETLIFY_INTERNAL_GIT="1";try{await P("git",["add",".",...e],{cwd:t})}finally{process.env.NETLIFY_INTERNAL_GIT="0"}},Tt=async(e=process.cwd())=>{let t=await P("git",["status","-s"],{cwd:e});return String(t.stdout??"")},hr=/.. (.+)?\.log$/,Pn=[hr],Nn=async(e=process.cwd())=>{let t=await Tt(e);return{hasChanges:(t.trim().length===0?[]:t.split(`
|
|
9
9
|
`).filter(n=>Pn.some(s=>s instanceof RegExp?s.test(n):n===s)?!1:n[1]?.trim()!=="")).length!==0,status:t}},$n=async(e=process.cwd())=>{try{return await P("git",["diff","--staged","--quiet"],{cwd:e}),!1}catch{return!0}},De=async(e=process.cwd())=>{let{stdout:t}=await P("git",["rev-parse","HEAD"],{cwd:e});return String(t??"").trim()},yr=async(e=process.cwd())=>{let{stdout:t}=await P("git",["rev-list","--max-parents=0","HEAD"],{cwd:e});return String(t??"").trim()},It=async(e,t=process.cwd())=>{e||=await Tt(t);let r=[".netlify","node_modules","dist",".next","out",".nuxt",".output",".cache",".turbo",".parcel-cache","coverage",".nyc_output","storybook-static","public/build","CLAUDE.local.md"],i=[];return e.split(`
|
|
10
10
|
`).forEach(n=>{r.forEach(s=>{let a=n===`?? ${s}`,l=n.startsWith(`?? ${s}/`)||n.startsWith(`?? ${s}${kn.sep}`);(a||l)&&i.push(`:!${s}`)});let o=n.match(hr)?.[1];o&&i.push(`:!${o}.log`)}),i},St=async(e=process.cwd())=>{await P("git",["reset","--hard","HEAD"],{cwd:e})},On=e=>{let t=e.split(`
|
|
11
11
|
`).reduce((r,i)=>{if(!i)return r;let[n,o,,...s]=i,a=s.join(""),l=n.trim(),c=o.trim();return r[a]?r[a].change=c:r[a]={filePath:a,stage:l,change:c},r},{});return Object.values(t)},Fn=async(e,t=process.cwd())=>{let r=e.filter(i=>i.stage&&!i.change).map(i=>i.filePath);r.length!==0&&await P("git",["restore","--staged","--worktree","--pathspec-from-file=-"],{cwd:t,input:r.join(`
|
|
@@ -188,7 +188,7 @@ Each item of \`templates array\` has properties:
|
|
|
188
188
|
|
|
189
189
|
Result Rules:
|
|
190
190
|
- only 1 \`template\` can be picked; do not change it's value or casing.
|
|
191
|
-
- \`newPrompt\` should
|
|
191
|
+
- \`newPrompt\` should contain: Based on this template, <user prompt>
|
|
192
192
|
- \`packageManager\` should be the preferred package manager if mentioned in the user input (npm, yarn, pnpm), if it's not provided - empty string.
|
|
193
193
|
- \`framework\` should be the name of the framework (e.g. react) if user explicitly provided it, otherwise empty string. Lowercased.
|
|
194
194
|
- should NEVER include any additional text, explanations, labels or extra text.
|
package/dist/bin.js
CHANGED
|
@@ -5,7 +5,7 @@ import Bt from"process";import Vo from"minimist";import{createRequire as Do}from
|
|
|
5
5
|
${s}
|
|
6
6
|
</extracted_error_chunk>`).join(`
|
|
7
7
|
|
|
8
|
-
`);return i.length>e.length*.8?e:i}import{execSync as io}from"child_process";import Dr from"fs/promises";import so from"path";import ye from"process";import{getTracer as ao}from"@netlify/otel";import Oe from"process";var Q=class extends Error{constructor(r,o,n,i=!1){super(r);this.statusCode=o;this.userMessage=n;this.isCreditLimitExceeded=i;this.name="GracefulShutdownError"}},He=e=>e instanceof Q;var We=Oe.env.NETLIFY_API_URL,Ke=Oe.env.NETLIFY_API_TOKEN,H=S("api"),we=()=>Oe.env.NETLIFY_LOCAL_MODE==="true",ae=async(e,t={})=>{if(!We||!Ke)throw new Error("No API URL or token");let r=new URL(e,We),o={...t,headers:{...t.headers,Authorization:`Bearer ${Ke}`}};Oe.env.AGENT_RUNNERS_DEBUG==="true"&&(o.headers["x-nf-debug-logging"]="true"),t.json&&(o.headers||={},o.headers["Content-Type"]="application/json",o.body=JSON.stringify(t.json));let n=await fetch(r,o),i=n.ok&&n.status<=299;if(Oe.env.AGENT_RUNNERS_DEBUG==="true")H.log(`Response headers for ${r}:`),n.headers.forEach((a,l)=>{H.log(` ${l}: ${a}`)});else{let a=n.headers.get("x-request-id")||n.headers.get("x-nf-request-id");H.log(`Request ID for ${r}: ${a||"N/A"}`)}if(i||H.error(`Got status ${n.status} for request ${r}`),t.raw){if(!i)throw new Error(`API request failed: ${n.status} ${n.statusText}`);return n}let s=await(n.headers.get("content-type")?.includes("application/json")?n.json():n.text());if(!i){let a=typeof s=="string"?s:JSON.stringify(s);throw n.status===404?new Q(`API request failed: 404 - ${a}`,404,"The site associated with this agent run no longer exists."):n.status===503&&t.gracefulOn503&&a.toLowerCase().includes("usage exceeded")?new Q(`API request failed: 503 - ${a}`,503,"Credit limit reached. Please add more credits to continue using Agent Runners.",!0):new Error(`API request failed: ${n.status} - ${a}`)}return s},zt=e=>{H.log("Setting details for api",{apiUrl:e?.constants?.NETLIFY_API_HOST,token:!!e?.constants?.NETLIFY_API_TOKEN}),e?.constants?.NETLIFY_API_HOST&&(We=`https://${e.constants.NETLIFY_API_HOST}`),e?.constants?.NETLIFY_API_TOKEN&&(Ke=e.constants.NETLIFY_API_TOKEN)},Xt=()=>({apiUrl:We,token:Ke}),$e=async(e,t)=>we()?(H.log("Mock API: updateRunner called",{runnerId:e,data:t}),{id:e,...t}):ae(`/api/v1/agent_runners/${e}`,{method:"PUT",json:t}),W=async(e,t,r)=>we()?(H.log("Mock API: updateRunnerSession called",JSON.stringify({runnerId:e,sessionId:t,data:r},null,2)),{id:e,sessionId:t,...r}):ae(`/api/v1/agent_runners/${e}/sessions/${t}`,{method:"PUT",json:r});var Zt=async e=>we()?(H.log("Mock API: getSite called",{siteId:e}),{id:e,published_deploy:{id:"id"}}):ae(`/api/v1/sites/${e}`),Qt=async(e,t)=>we()?(H.log("Mock API: getRunnerSession called",{runnerId:e,sessionId:t}),{id:t,runnerId:e,state:"running"}):ae(`/api/v1/agent_runners/${e}/sessions/${t}`),er=(e,t,r)=>ae(`/api/v1/accounts/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r},gracefulOn503:!0}),tr=(e,t,r)=>ae(`/api/v1/sites/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r},gracefulOn503:!0}),rr=async(e,t)=>we()?(H.log("Mock API: getDiffUploadUrls called",{runnerId:e,sessionId:t}),{result:{upload_url:"https://s3.mock.com/mock-upload-url-result",s3_key:"mock-s3-key-result"},cumulative:{upload_url:"https://s3.mock.com/mock-upload-url-cumulative",s3_key:"mock-s3-key-cumulative"}}):ae(`/api/v1/agent_runners/${e}/sessions/${t}/diff/upload_urls`,{method:"POST"}),nr=async(e,t)=>we()?(H.log("Mock API: updateSessionUsage called",{runnerId:e,sessionId:t}),{id:t,runnerId:e,usage:0}):ae(`/api/v1/agent_runners/${e}/sessions/${t}/update_usage`,{method:"POST"}),pt=async(e,t,{maxRetries:r=3,baseDelayMs:o=500}={})=>{H.log(`Uploading diff to S3: ${e.substring(0,50)}...`);for(let n=1;n<=r;n++)try{let i=await fetch(e,{method:"PUT",body:t,headers:{"Content-Type":"text/plain"}});if(!i.ok)throw new Error(`S3 upload failed with status ${i.status}`);return i}catch(i){if(n===r)throw i;let s=o*2**(n-1);H.warn(`S3 upload attempt ${n}/${r} failed: ${i.message}. Retrying in ${s}ms...`),await new Promise(a=>setTimeout(a,s))}};var Te=S("ai_gateway"),mt=null;var Ve=async()=>{if(mt)return mt;Te.log("Fetching available AI gateway providers");let e=await fetch(`${Xt().apiUrl}/api/v1/ai-gateway/providers`);if(!e.ok)throw new Error(`Failed to fetch AI gateway providers: ${e.statusText}`);let t=await e.json();return mt=t,Te.log("Cached AI gateway providers",{providerCount:Object.keys(t.providers).length}),t},mn=async(e,t)=>{let o=(await Ve()).providers[e];if(!o)return Te.log(`Provider '${e}' not found`),!1;let n=o.models.includes(t);return Te.log(`Model validation for ${e}/${t}`,{isAvailable:n}),n},or=async({config:e})=>{let t,r,o,n,i=!e.site?.published_deploy;if(!(i?e.accountId:e.siteId))throw new Error(`No entity id for ${i?"account":"site"}`);let a=async()=>{clearTimeout(o),Te.log("Requesting AI gateway information");let c=await(i?er(e.accountId,e.id,e.sessionId):tr(e.siteId,e.id,e.sessionId));if({token:t,url:n}=c,r=c.expires_at?c.expires_at*1e3:void 0,Te.log("Got AI gateway information",{token:!!t,expiresAt:r,url:n}),r){let d=r-Date.now()-6e4;d>0&&(o=setTimeout(()=>{a()},d))}};return await Promise.all([a(),Ve()]),{get url(){return n},get token(){return t},isModelAvailableForProvider:mn}};import te from"process";import oe from"path";import Xe from"fs";import{fileURLToPath as Tn}from"url";import{createRequire as xn}from"module";import{execa as In,execaCommand as Ri}from"execa";import{Transform as gn}from"stream";function fn(){let e=process.env.NETLIFY_SENSITIVE_ENV_KEYS;return e?e.split(",").map(t=>t.trim()).filter(Boolean):[]}function hn(e){let t=e.toLowerCase();return t==="true"||t==="false"?!0:e.trim().length<4}function yn(){let t=fn().map(r=>process.env[r]).filter(r=>!(!r||hn(r)));return[...new Set(t)].sort((r,o)=>o.length-r.length)}function ne(e){if(typeof e!="string")return e;let t=yn();if(t.length===0)return e;let r=e;return t.forEach(o=>{let n=new RegExp(_n(o),"g");r=r.replace(n,"******")}),r}function _n(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var xe=class extends gn{constructor(t={}){super({...t,objectMode:!1})}_transform(t,r,o){let n=t.toString(),i=ne(n);o(null,i)}};function ir(){if(!(process.env.NETLIFY_MASK_LOGS!=="false"))return;let t=process.stdout.write.bind(process.stdout),r=process.stderr.write.bind(process.stderr);process.stdout.write=function(o,n,i){let s=typeof o=="string"?ne(o):o;return typeof n=="function"?t(s,n):t(s,n,i)},process.stderr.write=function(o,n,i){let s=typeof o=="string"?ne(o):o;return typeof n=="function"?r(s,n):r(s,n,i)}}var Fe=null,sr=e=>(Fe&&Fe.destroy(),Fe=new le({totalAllowedTime:e}),Fe),ar=()=>Fe;var le=class{constructor({totalAllowedTime:t}){this.withStageTimer=async(t,r,o)=>{if(this.isTimeExpired())throw new Error(`${t} stage did not complete in the allowed time. Time has already expired.`);let n=this.onTimesUp(()=>{throw new Error(`${t} stage did not complete in the allowed time.`)}),i=null,s=null;o!==void 0&&(s=new Promise((a,l)=>{i=setTimeout(()=>{l(new Error(`${t} stage exceeded its maximum duration of ${o}ms`))},o)}));try{return s?await Promise.race([r(),s]):await r()}finally{n(),i&&clearTimeout(i)}};this.startTime=Date.now(),this.totalAllowedTime=t,this.globalTimeoutId=null,this.subscribers=[],this.hasTimedOut=!1,this.setupGlobalTimeout()}getElapsedTime(){return Date.now()-this.startTime}getRemainingTime(){let t=this.getElapsedTime(),r=this.totalAllowedTime-t;return Math.max(0,r)}isTimeExpired(){return this.getRemainingTime()===0||this.hasTimedOut}setupGlobalTimeout(){this.globalTimeoutId&&clearTimeout(this.globalTimeoutId),this.globalTimeoutId=setTimeout(()=>{this.notifyTimeUp()},this.totalAllowedTime)}notifyTimeUp(){this.hasTimedOut=!0;for(let t=this.subscribers.length-1;t>=0;t--)try{this.subscribers[t]()}catch(r){console.error("TimeKeeper: Error in time up callback:",r)}}onTimesUp(t){if(this.subscribers.push(t),this.hasTimedOut)try{t()}catch(r){console.error("TimeKeeper: Error in time up callback:",r)}return()=>{let r=this.subscribers.indexOf(t);r>-1&&this.subscribers.splice(r,1)}}off(t){let r=this.subscribers.indexOf(t);r>-1&&this.subscribers.splice(r,1)}clearSubscribers(){this.subscribers.length=0}getSubscriberCount(){return this.subscribers.length}destroy(){this.globalTimeoutId&&(clearTimeout(this.globalTimeoutId),this.globalTimeoutId=null),this.clearSubscribers()}static{this.timeUnits={seconds:t=>t*1e3,minutes:t=>t*60*1e3,hours:t=>t*60*60*1e3}}};var lr="netlify-agent-runner-context.md",gt="task-history",ee=".netlify",me="results.md",ft="assets",ht="other",yt="personal";var _t="enterprise",Le="free",cr=[yt,"pro",_t,Le],ur=["normal","redeploy","create","ask","dtn-prod-iteration","rebase"],dr="The production deploy has changed since you started working. Please reapply the changes to the current codebase, resolving any conflicts that arise. Use the attached diff file if present, otherwise review the previous session context to reproduce the changes.",ge=1800*1e3,En=["\\.claude","\\.gemini","\\.codex","\\.agents"],Je=new RegExp(`(^|/)(${En.join("|")})/skills/`),ze=/(^|\/)((CLAUDE|AGENTS|GEMINI)(\.local)?\.md)$/,f={Environment:"environment",UserMessage:"user-message",AgentMessage:"agent-message",Task:"task",RunCommand:"run-command",Explore:"explore",Plan:"plan",FileRead:"file-read",FileWrite:"file-write",Notebook:"notebook",Web:"web",Todo:"todo",Reasoning:"reasoning",Skill:"skill",Memorize:"memorize",Deployment:"deployment",SiteGeneration:"site-generation"};var pr={name:"@netlify/agent-runner-cli",type:"module",version:"1.93.1",description:"CLI tool for running Netlify agents",main:"./dist/index.js",types:"./dist/index.d.ts",exports:"./dist/index.js",bin:{"agent-runner-cli":"./dist/bin.js","agent-runner-cli-local":"./dist/bin-local.js"},files:["dist/**/*.js","dist/**/*.d.ts","dist/skills/**","patches","scripts"],scripts:{build:"tsup",dev:"tsup --watch",prepare:"husky install node_modules/@netlify/eslint-config-node/.husky/",prepublishOnly:"npm ci && npm test",prepack:"npm run build",test:"run-s build format test:dev",format:"run-s build format:check-fix:*","format:ci":"run-s build format:check:*","format:check-fix:lint":"run-e format:check:lint format:fix:lint","format:check:lint":"cross-env-shell eslint $npm_package_config_eslint","format:fix:lint":"cross-env-shell eslint --fix $npm_package_config_eslint","format:check-fix:prettier":"run-e format:check:prettier format:fix:prettier","format:check:prettier":"cross-env-shell prettier --check $npm_package_config_prettier","format:fix:prettier":"cross-env-shell prettier --write $npm_package_config_prettier","test:dev":"run-s build test:dev:*","test:ci":"run-s build test:ci:*","test:dev:vitest":"LOG=0 vitest --exclude '**/integration/**'","test:ci:vitest":"LOG=0 c8 -r lcovonly -r text -r json vitest --exclude '**/integration/**'","test:integration":"vitest run test/integration/","test:integration:codex":"vitest run test/integration/codex.test.ts","test:integration:claude":"vitest run test/integration/claude.test.ts","test:integration:gemini":"vitest run test/integration/gemini.test.ts","test:integration:create-stage":"vitest run test/integration/create.test.ts","test:integration:skill-invocation":"vitest run test/integration/skill-invocation.test.ts","check:types":"tsc --noEmit",postinstall:"node scripts/postinstall.js"},config:{eslint:'--cache --format=codeframe --max-warnings=0 "{src,scripts,test,.github}/**/*.{js,ts,md,html}"',prettier:'--ignore-path .gitignore --loglevel=warn "{src,scripts,test,.github}/**/*.{js,ts,md,yml,json,html}" "*.{js,ts,yml,json,html}" ".*.{js,ts,yml,json,html}" "!**/package-lock.json" "!package-lock.json" "!src/skills/**/*.md"'},keywords:[],license:"MIT",repository:"netlify/agent-runner-cli",bugs:{url:"https://github.com/netlify/agent-runner-cli/issues"},author:"Netlify Inc.",directories:{test:"test"},devDependencies:{"@commitlint/cli":"^20.0.0","@commitlint/config-conventional":"^20.0.0","@eslint/compat":"^2.0.0","@eslint/js":"^9.35.0","@netlify/eslint-config-node":"^7.0.1","@types/node":"^24.5.0","@typescript-eslint/eslint-plugin":"^8.0.0","@typescript-eslint/parser":"^8.0.0","@vitest/eslint-plugin":"^1.6.6",c8:"^10.0.0","eslint-config-prettier":"^10.1.8","eslint-plugin-n":"^17.0.0",husky:"^9.0.0","patch-package":"^8.0.0",tsup:"^8.5.0",typescript:"^5.0.0","typescript-eslint":"^8.44.0",vitest:"^4.0.16"},dependencies:{"@anthropic-ai/claude-code":"2.1.81","@anthropic-ai/sdk":"0.78.0","@google/gemini-cli":"0.31.0","@netlify/otel":"^5.1.5","@netlify/ts-cli":"^1.0.3","@openai/codex":"0.115.0","@opentelemetry/exporter-trace-otlp-grpc":"0.57.2",execa:"^9.6.1",minimist:"^1.2.8",openai:"6.26.0"}};var Sn=Tn(import.meta.url),vn=oe.dirname(Sn),Rn=xn(import.meta.url),Ie=S("shell"),Et=new Set,An={preferLocal:!0},O=(e,t,r)=>{let[o,n]=bn(t,r),i={...An,...n},s=In(e,o,i);Cn(s,i),Nn(s);let a=r?.idleTimeout;return a&&a>0&&Pn(s,a),s};var bn=function(e,t){return Array.isArray(e)?[e,t]:typeof e=="object"&&e!==null?[[],e]:[[],void 0]},Cn=(e,t)=>{if(t.stdio!==void 0||t.stdout!==void 0||t.stderr!==void 0)return;if(te.env.NETLIFY_MASK_LOGS!=="false"){e.all?.pipe(new xe).pipe(te.stdout),e.stdout?.pipe(new xe).pipe(te.stdout),e.stderr?.pipe(new xe).pipe(te.stderr);return}e.stdout?.pipe(te.stdout),e.stderr?.pipe(te.stderr)},wt=(e,t="SIGTERM")=>{try{return e.pid&&!e.killed?(te.kill(-e.pid,t),Ie.log(`Killed process ${e.pid} with signal ${t}`),!0):!1}catch(r){return Ie.error("Error killing process:",r),!1}},mr=e=>wt(e,"SIGKILL"),Pn=(e,t)=>{let r=null,o=()=>{Ie.log(`Process ${e.pid} killed due to idle timeout (no output for ${t}ms)`),wt(e,"SIGTERM"),setTimeout(()=>{e.pid&&!e.killed&&(Ie.log(`Force killing idle process ${e.pid}`),mr(e))},5e3)},n=()=>{r&&clearTimeout(r),r=setTimeout(o,t)};n(),e.stdout?.on("data",n),e.stderr?.on("data",n);let i=()=>{r&&(clearTimeout(r),r=null)};e.on("exit",i),e.on("error",i)},Nn=e=>{Et.add(e);let t=ar();if(t){let r=t.onTimesUp(()=>{Ie.log(`Global timer expired, killing process ${e.pid}`),wt(e,"SIGTERM"),setTimeout(()=>{e.pid&&!e.killed&&(Ie.log(`Force killing process ${e.pid} after timeout`),mr(e))},5e3)});e.on("exit",()=>{Et.delete(e),r()}),e.on("error",()=>{Et.delete(e),r()})}};function ce(e,t){if(!te.env.NETLIFY_LOCAL_MODE)try{let n=Rn.resolve(pr.name),i=oe.dirname(n);for(;i!==oe.dirname(i);){let s=oe.dirname(i);if(oe.basename(s)==="node_modules"){let a=oe.join(s,".bin",t);if(Xe.existsSync(a))return a;break}i=s}}catch(n){console.error("Could not resolve package.json",n)}if(te.env.NODE_PATH){let n=oe.join(te.env.NODE_PATH,".bin",t);if(Xe.existsSync(n))return n}let r=oe.join(e,"node_modules",".bin",t);if(Xe.existsSync(r))return r;let o=oe.join(vn,"..","node_modules",".bin",t);if(Xe.existsSync(o))return o}var gr=S("utils"),kn=e=>new Promise(t=>{setTimeout(t,e)}),Ze=(e,t=3e3)=>{let r=!1,o=null,n=[],i=null,s=(...a)=>{if(r)return o=a,new Promise(d=>{n.push(d)});r=!0;let l,c=new Promise(d=>{l=d});return i=(async()=>{await Promise.resolve();let d=await e(...a);for(l(d);;){if(await kn(t),!o)return r=!1,i=null,d;let u=o,p=n;o=null,n=[],d=await e(...u),p.forEach(g=>{g(d)})}})(),c};return s.flush=async()=>{if((r||o)&&i)return await i,s.flush()},s},Se=(e,t,r=!1)=>{let o=null,n=null,i=null,s=function(...a){n=a,i=this;let l=r&&!o;clearTimeout(o),o=setTimeout(()=>{o=null,r||(e.apply(i,n),n=null,i=null)},t),l&&(e.apply(i,n),n=null,i=null)};return s.cancel=()=>{clearTimeout(o),o=null,n=null,i=null},s.flush=()=>{if(o){clearTimeout(o);let a=n,l=i;o=null,n=null,i=null,e.apply(l,a)}},s},Qe=(e,t=!0,r)=>{if(e)try{return JSON.parse(e)}catch(o){t&&(r?.error?r.error("Could not parse JSON",o):gr.error("Could not parse JSON",o))}},Tt=e=>e.charAt(0).toUpperCase()+e.slice(1),ue=e=>e.split("-").map(t=>t.length===2?t.toUpperCase():Tt(t)).join(" ");function fe(e,t){t&&e.log(`Skill invoked: ${t}`)}var fr=e=>Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0)),hr=(e,t)=>{let n=".netlify.app",i="agent-";if(!t)return`${i}${e.slice(0,6)}`;let a=`--${t}${n}`;if(a.length>55)return"";let l=60-a.length;if(l<=0)return"";if(l>=i.length+6){let c=Math.min(l-i.length,e.length);return`${i}${e.slice(0,c)}`}return e.slice(0,l)},On=e=>!e||typeof e!="object"||Array.isArray(e)||Object.keys(e).length===0?!1:!!cr.some(t=>t in e),yr=()=>{let e={},t={codex:process.env.NETLIFY_FF_AGENT_RUNNER_CODEX_VERSION,claude:process.env.NETLIFY_FF_AGENT_RUNNER_CLAUDE_VERSION,gemini:process.env.NETLIFY_FF_AGENT_RUNNER_GEMINI_VERSION};return Object.entries(t).forEach(([r,o])=>{if(o){let n=`NETLIFY_FF_AGENT_RUNNER_${r.toUpperCase()}_VERSION`;try{let i=JSON.parse(o);On(i)&&(e[r]=i)}catch(i){let a=i instanceof SyntaxError?"Invalid JSON":i.message;gr.error(`Could not parse ${r} model version override from ${n}: ${a}`)}}}),e},$n=1e4,xt=(e,t=$n)=>{if(!e||typeof e!="string"||e.length<=t)return e;let o=e.startsWith("```")?"\n... [truncated]\n```":"... [truncated]";return e.slice(0,t)+o};import{Buffer as _r}from"buffer";import Fn from"path";var Er=S("repo"),Tr=async({config:e,isRetry:t,cwd:r=process.cwd()})=>{Er.info("Getting runner diffs");let o=await Dn(r),{hasChanges:n}=o,{status:i}=o;if(!n)return{hasChanges:!1};if(!t){let E=Un(i);await Gn(E,r)}Er.info("Changes after processing"),await St(r);let s=await Rt(i,r);if(await It(s,r),n=await Mn(r),!n)return{hasChanges:!1,ignored:s};process.env.NETLIFY_INTERNAL_GIT="1";try{await O("git",["commit","-m","Agent runner"],{cwd:r})}finally{process.env.NETLIFY_INTERNAL_GIT="0"}let a={stdio:["ignore","pipe","pipe"],cwd:r},l=await O("git",["diff",e.runSha,"HEAD"],a),c=String(l.stdout??"");if(n=!!c,!n)return await wr(r),{hasChanges:!1,ignored:s};let d=await O("git",["diff",e.runSha,"HEAD","--binary"],a),u=String(d.stdout??""),p,g;if(e.sha){let E=await O("git",["diff",e.sha,"HEAD"],a);p=String(E.stdout??"");let x=await O("git",["diff",e.sha,"HEAD","--binary"],a),y=String(x.stdout??"");p!==y&&(g=_r.from(y).toString("base64"))}await wr(r);let T={hasChanges:!0,diff:c,resultDiff:p,ignored:s};return c!==u&&(T.diffBinary=_r.from(u).toString("base64")),g&&(T.resultDiffBinary=g),T},wr=async(e=process.cwd())=>{process.env.NETLIFY_LOCAL_MODE&&await O("git",["reset","--soft","HEAD~1"],{cwd:e})},It=async(e=[],t=process.cwd())=>{process.env.NETLIFY_INTERNAL_GIT="1";try{await O("git",["add",".",...e],{cwd:t})}finally{process.env.NETLIFY_INTERNAL_GIT="0"}},St=async(e=process.cwd())=>{let t=await O("git",["status","-s"],{cwd:e});return String(t.stdout??"")},xr=/.. (.+)?\.log$/,Ln=[xr],Dn=async(e=process.cwd())=>{let t=await St(e);return{hasChanges:(t.trim().length===0?[]:t.split(`
|
|
8
|
+
`);return i.length>e.length*.8?e:i}import{execSync as io}from"child_process";import Dr from"fs/promises";import so from"path";import ye from"process";import{getTracer as ao}from"@netlify/otel";import Oe from"process";var Q=class extends Error{constructor(r,o,n,i=!1){super(r);this.statusCode=o;this.userMessage=n;this.isCreditLimitExceeded=i;this.name="GracefulShutdownError"}},He=e=>e instanceof Q;var We=Oe.env.NETLIFY_API_URL,Ke=Oe.env.NETLIFY_API_TOKEN,H=S("api"),we=()=>Oe.env.NETLIFY_LOCAL_MODE==="true",ae=async(e,t={})=>{if(!We||!Ke)throw new Error("No API URL or token");let r=new URL(e,We),o={...t,headers:{...t.headers,Authorization:`Bearer ${Ke}`}};Oe.env.AGENT_RUNNERS_DEBUG==="true"&&(o.headers["x-nf-debug-logging"]="true"),t.json&&(o.headers||={},o.headers["Content-Type"]="application/json",o.body=JSON.stringify(t.json));let n=await fetch(r,o),i=n.ok&&n.status<=299;if(Oe.env.AGENT_RUNNERS_DEBUG==="true")H.log(`Response headers for ${r}:`),n.headers.forEach((a,l)=>{H.log(` ${l}: ${a}`)});else{let a=n.headers.get("x-request-id")||n.headers.get("x-nf-request-id");H.log(`Request ID for ${r}: ${a||"N/A"}`)}if(i||H.error(`Got status ${n.status} for request ${r}`),t.raw){if(!i)throw new Error(`API request failed: ${n.status} ${n.statusText}`);return n}let s=await(n.headers.get("content-type")?.includes("application/json")?n.json():n.text());if(!i){let a=typeof s=="string"?s:JSON.stringify(s);throw n.status===404?new Q(`API request failed: 404 - ${a}`,404,"The site associated with this agent run no longer exists."):n.status===503&&t.gracefulOn503&&a.toLowerCase().includes("usage exceeded")?new Q(`API request failed: 503 - ${a}`,503,"Credit limit reached. Please add more credits to continue using Agent Runners.",!0):new Error(`API request failed: ${n.status} - ${a}`)}return s},zt=e=>{H.log("Setting details for api",{apiUrl:e?.constants?.NETLIFY_API_HOST,token:!!e?.constants?.NETLIFY_API_TOKEN}),e?.constants?.NETLIFY_API_HOST&&(We=`https://${e.constants.NETLIFY_API_HOST}`),e?.constants?.NETLIFY_API_TOKEN&&(Ke=e.constants.NETLIFY_API_TOKEN)},Xt=()=>({apiUrl:We,token:Ke}),$e=async(e,t)=>we()?(H.log("Mock API: updateRunner called",{runnerId:e,data:t}),{id:e,...t}):ae(`/api/v1/agent_runners/${e}`,{method:"PUT",json:t}),W=async(e,t,r)=>we()?(H.log("Mock API: updateRunnerSession called",JSON.stringify({runnerId:e,sessionId:t,data:r},null,2)),{id:e,sessionId:t,...r}):ae(`/api/v1/agent_runners/${e}/sessions/${t}`,{method:"PUT",json:r});var Zt=async e=>we()?(H.log("Mock API: getSite called",{siteId:e}),{id:e,published_deploy:{id:"id"}}):ae(`/api/v1/sites/${e}`),Qt=async(e,t)=>we()?(H.log("Mock API: getRunnerSession called",{runnerId:e,sessionId:t}),{id:t,runnerId:e,state:"running"}):ae(`/api/v1/agent_runners/${e}/sessions/${t}`),er=(e,t,r)=>ae(`/api/v1/accounts/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r},gracefulOn503:!0}),tr=(e,t,r)=>ae(`/api/v1/sites/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r},gracefulOn503:!0}),rr=async(e,t)=>we()?(H.log("Mock API: getDiffUploadUrls called",{runnerId:e,sessionId:t}),{result:{upload_url:"https://s3.mock.com/mock-upload-url-result",s3_key:"mock-s3-key-result"},cumulative:{upload_url:"https://s3.mock.com/mock-upload-url-cumulative",s3_key:"mock-s3-key-cumulative"}}):ae(`/api/v1/agent_runners/${e}/sessions/${t}/diff/upload_urls`,{method:"POST"}),nr=async(e,t)=>we()?(H.log("Mock API: updateSessionUsage called",{runnerId:e,sessionId:t}),{id:t,runnerId:e,usage:0}):ae(`/api/v1/agent_runners/${e}/sessions/${t}/update_usage`,{method:"POST"}),pt=async(e,t,{maxRetries:r=3,baseDelayMs:o=500}={})=>{H.log(`Uploading diff to S3: ${e.substring(0,50)}...`);for(let n=1;n<=r;n++)try{let i=await fetch(e,{method:"PUT",body:t,headers:{"Content-Type":"text/plain"}});if(!i.ok)throw new Error(`S3 upload failed with status ${i.status}`);return i}catch(i){if(n===r)throw i;let s=o*2**(n-1);H.warn(`S3 upload attempt ${n}/${r} failed: ${i.message}. Retrying in ${s}ms...`),await new Promise(a=>setTimeout(a,s))}};var Te=S("ai_gateway"),mt=null;var Ve=async()=>{if(mt)return mt;Te.log("Fetching available AI gateway providers");let e=await fetch(`${Xt().apiUrl}/api/v1/ai-gateway/providers`);if(!e.ok)throw new Error(`Failed to fetch AI gateway providers: ${e.statusText}`);let t=await e.json();return mt=t,Te.log("Cached AI gateway providers",{providerCount:Object.keys(t.providers).length}),t},mn=async(e,t)=>{let o=(await Ve()).providers[e];if(!o)return Te.log(`Provider '${e}' not found`),!1;let n=o.models.includes(t);return Te.log(`Model validation for ${e}/${t}`,{isAvailable:n}),n},or=async({config:e})=>{let t,r,o,n,i=!e.site?.published_deploy;if(!(i?e.accountId:e.siteId))throw new Error(`No entity id for ${i?"account":"site"}`);let a=async()=>{clearTimeout(o),Te.log("Requesting AI gateway information");let c=await(i?er(e.accountId,e.id,e.sessionId):tr(e.siteId,e.id,e.sessionId));if({token:t,url:n}=c,r=c.expires_at?c.expires_at*1e3:void 0,Te.log("Got AI gateway information",{token:!!t,expiresAt:r,url:n}),r){let d=r-Date.now()-6e4;d>0&&(o=setTimeout(()=>{a()},d))}};return await Promise.all([a(),Ve()]),{get url(){return n},get token(){return t},isModelAvailableForProvider:mn}};import te from"process";import oe from"path";import Xe from"fs";import{fileURLToPath as Tn}from"url";import{createRequire as xn}from"module";import{execa as In,execaCommand as Ri}from"execa";import{Transform as gn}from"stream";function fn(){let e=process.env.NETLIFY_SENSITIVE_ENV_KEYS;return e?e.split(",").map(t=>t.trim()).filter(Boolean):[]}function hn(e){let t=e.toLowerCase();return t==="true"||t==="false"?!0:e.trim().length<4}function yn(){let t=fn().map(r=>process.env[r]).filter(r=>!(!r||hn(r)));return[...new Set(t)].sort((r,o)=>o.length-r.length)}function ne(e){if(typeof e!="string")return e;let t=yn();if(t.length===0)return e;let r=e;return t.forEach(o=>{let n=new RegExp(_n(o),"g");r=r.replace(n,"******")}),r}function _n(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var xe=class extends gn{constructor(t={}){super({...t,objectMode:!1})}_transform(t,r,o){let n=t.toString(),i=ne(n);o(null,i)}};function ir(){if(!(process.env.NETLIFY_MASK_LOGS!=="false"))return;let t=process.stdout.write.bind(process.stdout),r=process.stderr.write.bind(process.stderr);process.stdout.write=function(o,n,i){let s=typeof o=="string"?ne(o):o;return typeof n=="function"?t(s,n):t(s,n,i)},process.stderr.write=function(o,n,i){let s=typeof o=="string"?ne(o):o;return typeof n=="function"?r(s,n):r(s,n,i)}}var Fe=null,sr=e=>(Fe&&Fe.destroy(),Fe=new le({totalAllowedTime:e}),Fe),ar=()=>Fe;var le=class{constructor({totalAllowedTime:t}){this.withStageTimer=async(t,r,o)=>{if(this.isTimeExpired())throw new Error(`${t} stage did not complete in the allowed time. Time has already expired.`);let n=this.onTimesUp(()=>{throw new Error(`${t} stage did not complete in the allowed time.`)}),i=null,s=null;o!==void 0&&(s=new Promise((a,l)=>{i=setTimeout(()=>{l(new Error(`${t} stage exceeded its maximum duration of ${o}ms`))},o)}));try{return s?await Promise.race([r(),s]):await r()}finally{n(),i&&clearTimeout(i)}};this.startTime=Date.now(),this.totalAllowedTime=t,this.globalTimeoutId=null,this.subscribers=[],this.hasTimedOut=!1,this.setupGlobalTimeout()}getElapsedTime(){return Date.now()-this.startTime}getRemainingTime(){let t=this.getElapsedTime(),r=this.totalAllowedTime-t;return Math.max(0,r)}isTimeExpired(){return this.getRemainingTime()===0||this.hasTimedOut}setupGlobalTimeout(){this.globalTimeoutId&&clearTimeout(this.globalTimeoutId),this.globalTimeoutId=setTimeout(()=>{this.notifyTimeUp()},this.totalAllowedTime)}notifyTimeUp(){this.hasTimedOut=!0;for(let t=this.subscribers.length-1;t>=0;t--)try{this.subscribers[t]()}catch(r){console.error("TimeKeeper: Error in time up callback:",r)}}onTimesUp(t){if(this.subscribers.push(t),this.hasTimedOut)try{t()}catch(r){console.error("TimeKeeper: Error in time up callback:",r)}return()=>{let r=this.subscribers.indexOf(t);r>-1&&this.subscribers.splice(r,1)}}off(t){let r=this.subscribers.indexOf(t);r>-1&&this.subscribers.splice(r,1)}clearSubscribers(){this.subscribers.length=0}getSubscriberCount(){return this.subscribers.length}destroy(){this.globalTimeoutId&&(clearTimeout(this.globalTimeoutId),this.globalTimeoutId=null),this.clearSubscribers()}static{this.timeUnits={seconds:t=>t*1e3,minutes:t=>t*60*1e3,hours:t=>t*60*60*1e3}}};var lr="netlify-agent-runner-context.md",gt="task-history",ee=".netlify",me="results.md",ft="assets",ht="other",yt="personal";var _t="enterprise",Le="free",cr=[yt,"pro",_t,Le],ur=["normal","redeploy","create","ask","dtn-prod-iteration","rebase"],dr="The production deploy has changed since you started working. Please reapply the changes to the current codebase, resolving any conflicts that arise. Use the attached diff file if present, otherwise review the previous session context to reproduce the changes.",ge=1800*1e3,En=["\\.claude","\\.gemini","\\.codex","\\.agents"],Je=new RegExp(`(^|/)(${En.join("|")})/skills/`),ze=/(^|\/)((CLAUDE|AGENTS|GEMINI)(\.local)?\.md)$/,f={Environment:"environment",UserMessage:"user-message",AgentMessage:"agent-message",Task:"task",RunCommand:"run-command",Explore:"explore",Plan:"plan",FileRead:"file-read",FileWrite:"file-write",Notebook:"notebook",Web:"web",Todo:"todo",Reasoning:"reasoning",Skill:"skill",Memorize:"memorize",Deployment:"deployment",SiteGeneration:"site-generation"};var pr={name:"@netlify/agent-runner-cli",type:"module",version:"1.93.2",description:"CLI tool for running Netlify agents",main:"./dist/index.js",types:"./dist/index.d.ts",exports:"./dist/index.js",bin:{"agent-runner-cli":"./dist/bin.js","agent-runner-cli-local":"./dist/bin-local.js"},files:["dist/**/*.js","dist/**/*.d.ts","dist/skills/**","patches","scripts"],scripts:{build:"tsup",dev:"tsup --watch",prepare:"husky install node_modules/@netlify/eslint-config-node/.husky/",prepublishOnly:"npm ci && npm test",prepack:"npm run build",test:"run-s build format test:dev",format:"run-s build format:check-fix:*","format:ci":"run-s build format:check:*","format:check-fix:lint":"run-e format:check:lint format:fix:lint","format:check:lint":"cross-env-shell eslint $npm_package_config_eslint","format:fix:lint":"cross-env-shell eslint --fix $npm_package_config_eslint","format:check-fix:prettier":"run-e format:check:prettier format:fix:prettier","format:check:prettier":"cross-env-shell prettier --check $npm_package_config_prettier","format:fix:prettier":"cross-env-shell prettier --write $npm_package_config_prettier","test:dev":"run-s build test:dev:*","test:ci":"run-s build test:ci:*","test:dev:vitest":"LOG=0 vitest --exclude '**/integration/**'","test:ci:vitest":"LOG=0 c8 -r lcovonly -r text -r json vitest --exclude '**/integration/**'","test:integration":"vitest run test/integration/","test:integration:codex":"vitest run test/integration/codex.test.ts","test:integration:claude":"vitest run test/integration/claude.test.ts","test:integration:gemini":"vitest run test/integration/gemini.test.ts","test:integration:create-stage":"vitest run test/integration/create.test.ts","test:integration:skill-invocation":"vitest run test/integration/skill-invocation.test.ts","check:types":"tsc --noEmit",postinstall:"node scripts/postinstall.js"},config:{eslint:'--cache --format=codeframe --max-warnings=0 "{src,scripts,test,.github}/**/*.{js,ts,md,html}"',prettier:'--ignore-path .gitignore --loglevel=warn "{src,scripts,test,.github}/**/*.{js,ts,md,yml,json,html}" "*.{js,ts,yml,json,html}" ".*.{js,ts,yml,json,html}" "!**/package-lock.json" "!package-lock.json" "!src/skills/**/*.md"'},keywords:[],license:"MIT",repository:"netlify/agent-runner-cli",bugs:{url:"https://github.com/netlify/agent-runner-cli/issues"},author:"Netlify Inc.",directories:{test:"test"},devDependencies:{"@commitlint/cli":"^20.0.0","@commitlint/config-conventional":"^20.0.0","@eslint/compat":"^2.0.0","@eslint/js":"^9.35.0","@netlify/eslint-config-node":"^7.0.1","@types/node":"^24.5.0","@typescript-eslint/eslint-plugin":"^8.0.0","@typescript-eslint/parser":"^8.0.0","@vitest/eslint-plugin":"^1.6.6",c8:"^10.0.0","eslint-config-prettier":"^10.1.8","eslint-plugin-n":"^17.0.0",husky:"^9.0.0","patch-package":"^8.0.0",tsup:"^8.5.0",typescript:"^5.0.0","typescript-eslint":"^8.44.0",vitest:"^4.0.16"},dependencies:{"@anthropic-ai/claude-code":"2.1.81","@anthropic-ai/sdk":"0.78.0","@google/gemini-cli":"0.31.0","@netlify/otel":"^5.1.5","@netlify/ts-cli":"^1.0.4","@openai/codex":"0.115.0","@opentelemetry/exporter-trace-otlp-grpc":"0.57.2",execa:"^9.6.1",minimist:"^1.2.8",openai:"6.26.0"}};var Sn=Tn(import.meta.url),vn=oe.dirname(Sn),Rn=xn(import.meta.url),Ie=S("shell"),Et=new Set,An={preferLocal:!0},O=(e,t,r)=>{let[o,n]=bn(t,r),i={...An,...n},s=In(e,o,i);Cn(s,i),Nn(s);let a=r?.idleTimeout;return a&&a>0&&Pn(s,a),s};var bn=function(e,t){return Array.isArray(e)?[e,t]:typeof e=="object"&&e!==null?[[],e]:[[],void 0]},Cn=(e,t)=>{if(t.stdio!==void 0||t.stdout!==void 0||t.stderr!==void 0)return;if(te.env.NETLIFY_MASK_LOGS!=="false"){e.all?.pipe(new xe).pipe(te.stdout),e.stdout?.pipe(new xe).pipe(te.stdout),e.stderr?.pipe(new xe).pipe(te.stderr);return}e.stdout?.pipe(te.stdout),e.stderr?.pipe(te.stderr)},wt=(e,t="SIGTERM")=>{try{return e.pid&&!e.killed?(te.kill(-e.pid,t),Ie.log(`Killed process ${e.pid} with signal ${t}`),!0):!1}catch(r){return Ie.error("Error killing process:",r),!1}},mr=e=>wt(e,"SIGKILL"),Pn=(e,t)=>{let r=null,o=()=>{Ie.log(`Process ${e.pid} killed due to idle timeout (no output for ${t}ms)`),wt(e,"SIGTERM"),setTimeout(()=>{e.pid&&!e.killed&&(Ie.log(`Force killing idle process ${e.pid}`),mr(e))},5e3)},n=()=>{r&&clearTimeout(r),r=setTimeout(o,t)};n(),e.stdout?.on("data",n),e.stderr?.on("data",n);let i=()=>{r&&(clearTimeout(r),r=null)};e.on("exit",i),e.on("error",i)},Nn=e=>{Et.add(e);let t=ar();if(t){let r=t.onTimesUp(()=>{Ie.log(`Global timer expired, killing process ${e.pid}`),wt(e,"SIGTERM"),setTimeout(()=>{e.pid&&!e.killed&&(Ie.log(`Force killing process ${e.pid} after timeout`),mr(e))},5e3)});e.on("exit",()=>{Et.delete(e),r()}),e.on("error",()=>{Et.delete(e),r()})}};function ce(e,t){if(!te.env.NETLIFY_LOCAL_MODE)try{let n=Rn.resolve(pr.name),i=oe.dirname(n);for(;i!==oe.dirname(i);){let s=oe.dirname(i);if(oe.basename(s)==="node_modules"){let a=oe.join(s,".bin",t);if(Xe.existsSync(a))return a;break}i=s}}catch(n){console.error("Could not resolve package.json",n)}if(te.env.NODE_PATH){let n=oe.join(te.env.NODE_PATH,".bin",t);if(Xe.existsSync(n))return n}let r=oe.join(e,"node_modules",".bin",t);if(Xe.existsSync(r))return r;let o=oe.join(vn,"..","node_modules",".bin",t);if(Xe.existsSync(o))return o}var gr=S("utils"),kn=e=>new Promise(t=>{setTimeout(t,e)}),Ze=(e,t=3e3)=>{let r=!1,o=null,n=[],i=null,s=(...a)=>{if(r)return o=a,new Promise(d=>{n.push(d)});r=!0;let l,c=new Promise(d=>{l=d});return i=(async()=>{await Promise.resolve();let d=await e(...a);for(l(d);;){if(await kn(t),!o)return r=!1,i=null,d;let u=o,p=n;o=null,n=[],d=await e(...u),p.forEach(g=>{g(d)})}})(),c};return s.flush=async()=>{if((r||o)&&i)return await i,s.flush()},s},Se=(e,t,r=!1)=>{let o=null,n=null,i=null,s=function(...a){n=a,i=this;let l=r&&!o;clearTimeout(o),o=setTimeout(()=>{o=null,r||(e.apply(i,n),n=null,i=null)},t),l&&(e.apply(i,n),n=null,i=null)};return s.cancel=()=>{clearTimeout(o),o=null,n=null,i=null},s.flush=()=>{if(o){clearTimeout(o);let a=n,l=i;o=null,n=null,i=null,e.apply(l,a)}},s},Qe=(e,t=!0,r)=>{if(e)try{return JSON.parse(e)}catch(o){t&&(r?.error?r.error("Could not parse JSON",o):gr.error("Could not parse JSON",o))}},Tt=e=>e.charAt(0).toUpperCase()+e.slice(1),ue=e=>e.split("-").map(t=>t.length===2?t.toUpperCase():Tt(t)).join(" ");function fe(e,t){t&&e.log(`Skill invoked: ${t}`)}var fr=e=>Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0)),hr=(e,t)=>{let n=".netlify.app",i="agent-";if(!t)return`${i}${e.slice(0,6)}`;let a=`--${t}${n}`;if(a.length>55)return"";let l=60-a.length;if(l<=0)return"";if(l>=i.length+6){let c=Math.min(l-i.length,e.length);return`${i}${e.slice(0,c)}`}return e.slice(0,l)},On=e=>!e||typeof e!="object"||Array.isArray(e)||Object.keys(e).length===0?!1:!!cr.some(t=>t in e),yr=()=>{let e={},t={codex:process.env.NETLIFY_FF_AGENT_RUNNER_CODEX_VERSION,claude:process.env.NETLIFY_FF_AGENT_RUNNER_CLAUDE_VERSION,gemini:process.env.NETLIFY_FF_AGENT_RUNNER_GEMINI_VERSION};return Object.entries(t).forEach(([r,o])=>{if(o){let n=`NETLIFY_FF_AGENT_RUNNER_${r.toUpperCase()}_VERSION`;try{let i=JSON.parse(o);On(i)&&(e[r]=i)}catch(i){let a=i instanceof SyntaxError?"Invalid JSON":i.message;gr.error(`Could not parse ${r} model version override from ${n}: ${a}`)}}}),e},$n=1e4,xt=(e,t=$n)=>{if(!e||typeof e!="string"||e.length<=t)return e;let o=e.startsWith("```")?"\n... [truncated]\n```":"... [truncated]";return e.slice(0,t)+o};import{Buffer as _r}from"buffer";import Fn from"path";var Er=S("repo"),Tr=async({config:e,isRetry:t,cwd:r=process.cwd()})=>{Er.info("Getting runner diffs");let o=await Dn(r),{hasChanges:n}=o,{status:i}=o;if(!n)return{hasChanges:!1};if(!t){let E=Un(i);await Gn(E,r)}Er.info("Changes after processing"),await St(r);let s=await Rt(i,r);if(await It(s,r),n=await Mn(r),!n)return{hasChanges:!1,ignored:s};process.env.NETLIFY_INTERNAL_GIT="1";try{await O("git",["commit","-m","Agent runner"],{cwd:r})}finally{process.env.NETLIFY_INTERNAL_GIT="0"}let a={stdio:["ignore","pipe","pipe"],cwd:r},l=await O("git",["diff",e.runSha,"HEAD"],a),c=String(l.stdout??"");if(n=!!c,!n)return await wr(r),{hasChanges:!1,ignored:s};let d=await O("git",["diff",e.runSha,"HEAD","--binary"],a),u=String(d.stdout??""),p,g;if(e.sha){let E=await O("git",["diff",e.sha,"HEAD"],a);p=String(E.stdout??"");let x=await O("git",["diff",e.sha,"HEAD","--binary"],a),y=String(x.stdout??"");p!==y&&(g=_r.from(y).toString("base64"))}await wr(r);let T={hasChanges:!0,diff:c,resultDiff:p,ignored:s};return c!==u&&(T.diffBinary=_r.from(u).toString("base64")),g&&(T.resultDiffBinary=g),T},wr=async(e=process.cwd())=>{process.env.NETLIFY_LOCAL_MODE&&await O("git",["reset","--soft","HEAD~1"],{cwd:e})},It=async(e=[],t=process.cwd())=>{process.env.NETLIFY_INTERNAL_GIT="1";try{await O("git",["add",".",...e],{cwd:t})}finally{process.env.NETLIFY_INTERNAL_GIT="0"}},St=async(e=process.cwd())=>{let t=await O("git",["status","-s"],{cwd:e});return String(t.stdout??"")},xr=/.. (.+)?\.log$/,Ln=[xr],Dn=async(e=process.cwd())=>{let t=await St(e);return{hasChanges:(t.trim().length===0?[]:t.split(`
|
|
9
9
|
`).filter(n=>Ln.some(s=>s instanceof RegExp?s.test(n):n===s)?!1:n[1]?.trim()!=="")).length!==0,status:t}},Mn=async(e=process.cwd())=>{try{return await O("git",["diff","--staged","--quiet"],{cwd:e}),!1}catch{return!0}},vt=async(e=process.cwd())=>{let{stdout:t}=await O("git",["rev-parse","HEAD"],{cwd:e});return String(t??"").trim()},Ir=async(e=process.cwd())=>{let{stdout:t}=await O("git",["rev-list","--max-parents=0","HEAD"],{cwd:e});return String(t??"").trim()},Rt=async(e,t=process.cwd())=>{e||=await St(t);let r=[".netlify","node_modules","dist",".next","out",".nuxt",".output",".cache",".turbo",".parcel-cache","coverage",".nyc_output","storybook-static","public/build","CLAUDE.local.md"],o=[];return e.split(`
|
|
10
10
|
`).forEach(n=>{r.forEach(s=>{let a=n===`?? ${s}`,l=n.startsWith(`?? ${s}/`)||n.startsWith(`?? ${s}${Fn.sep}`);(a||l)&&o.push(`:!${s}`)});let i=n.match(xr)?.[1];i&&o.push(`:!${i}.log`)}),o},At=async(e=process.cwd())=>{await O("git",["reset","--hard","HEAD"],{cwd:e})},Un=e=>{let t=e.split(`
|
|
11
11
|
`).reduce((r,o)=>{if(!o)return r;let[n,i,,...s]=o,a=s.join(""),l=n.trim(),c=i.trim();return r[a]?r[a].change=c:r[a]={filePath:a,stage:l,change:c},r},{});return Object.values(t)},Gn=async(e,t=process.cwd())=>{let r=e.filter(o=>o.stage&&!o.change).map(o=>o.filePath);r.length!==0&&await O("git",["restore","--staged","--worktree","--pathspec-from-file=-"],{cwd:t,input:r.join(`
|
|
@@ -188,7 +188,7 @@ Each item of \`templates array\` has properties:
|
|
|
188
188
|
|
|
189
189
|
Result Rules:
|
|
190
190
|
- only 1 \`template\` can be picked; do not change it's value or casing.
|
|
191
|
-
- \`newPrompt\` should
|
|
191
|
+
- \`newPrompt\` should contain: Based on this template, <user prompt>
|
|
192
192
|
- \`packageManager\` should be the preferred package manager if mentioned in the user input (npm, yarn, pnpm), if it's not provided - empty string.
|
|
193
193
|
- \`framework\` should be the name of the framework (e.g. react) if user explicitly provided it, otherwise empty string. Lowercased.
|
|
194
194
|
- should NEVER include any additional text, explanations, labels or extra text.
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import{createRequire as xi}from"module";import{createTracerProvider as Hr}from"@
|
|
|
4
4
|
${s}
|
|
5
5
|
</extracted_error_chunk>`).join(`
|
|
6
6
|
|
|
7
|
-
`);return o.length>e.length*.8?e:o}import{execSync as Bn}from"child_process";import vr from"fs/promises";import Hn from"path";import he from"process";import{getTracer as Wn}from"@netlify/otel";import Pe from"process";var Z=class extends Error{constructor(r,i,n,o=!1){super(r);this.statusCode=i;this.userMessage=n;this.isCreditLimitExceeded=o;this.name="GracefulShutdownError"}},Ye=e=>e instanceof Z;var qe=Pe.env.NETLIFY_API_URL,Be=Pe.env.NETLIFY_API_TOKEN,B=I("api"),_e=()=>Pe.env.NETLIFY_LOCAL_MODE==="true",se=async(e,t={})=>{if(!qe||!Be)throw new Error("No API URL or token");let r=new URL(e,qe),i={...t,headers:{...t.headers,Authorization:`Bearer ${Be}`}};Pe.env.AGENT_RUNNERS_DEBUG==="true"&&(i.headers["x-nf-debug-logging"]="true"),t.json&&(i.headers||={},i.headers["Content-Type"]="application/json",i.body=JSON.stringify(t.json));let n=await fetch(r,i),o=n.ok&&n.status<=299;if(Pe.env.AGENT_RUNNERS_DEBUG==="true")B.log(`Response headers for ${r}:`),n.headers.forEach((a,l)=>{B.log(` ${l}: ${a}`)});else{let a=n.headers.get("x-request-id")||n.headers.get("x-nf-request-id");B.log(`Request ID for ${r}: ${a||"N/A"}`)}if(o||B.error(`Got status ${n.status} for request ${r}`),t.raw){if(!o)throw new Error(`API request failed: ${n.status} ${n.statusText}`);return n}let s=await(n.headers.get("content-type")?.includes("application/json")?n.json():n.text());if(!o){let a=typeof s=="string"?s:JSON.stringify(s);throw n.status===404?new Z(`API request failed: 404 - ${a}`,404,"The site associated with this agent run no longer exists."):n.status===503&&t.gracefulOn503&&a.toLowerCase().includes("usage exceeded")?new Z(`API request failed: 503 - ${a}`,503,"Credit limit reached. Please add more credits to continue using Agent Runners.",!0):new Error(`API request failed: ${n.status} - ${a}`)}return s},jt=e=>{B.log("Setting details for api",{apiUrl:e?.constants?.NETLIFY_API_HOST,token:!!e?.constants?.NETLIFY_API_TOKEN}),e?.constants?.NETLIFY_API_HOST&&(qe=`https://${e.constants.NETLIFY_API_HOST}`),e?.constants?.NETLIFY_API_TOKEN&&(Be=e.constants.NETLIFY_API_TOKEN)},Yt=()=>({apiUrl:qe,token:Be}),Ne=async(e,t)=>_e()?(B.log("Mock API: updateRunner called",{runnerId:e,data:t}),{id:e,...t}):se(`/api/v1/agent_runners/${e}`,{method:"PUT",json:t}),H=async(e,t,r)=>_e()?(B.log("Mock API: updateRunnerSession called",JSON.stringify({runnerId:e,sessionId:t,data:r},null,2)),{id:e,sessionId:t,...r}):se(`/api/v1/agent_runners/${e}/sessions/${t}`,{method:"PUT",json:r});var qt=async e=>_e()?(B.log("Mock API: getSite called",{siteId:e}),{id:e,published_deploy:{id:"id"}}):se(`/api/v1/sites/${e}`),Bt=async(e,t)=>_e()?(B.log("Mock API: getRunnerSession called",{runnerId:e,sessionId:t}),{id:t,runnerId:e,state:"running"}):se(`/api/v1/agent_runners/${e}/sessions/${t}`),Ht=(e,t,r)=>se(`/api/v1/accounts/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r},gracefulOn503:!0}),Wt=(e,t,r)=>se(`/api/v1/sites/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r},gracefulOn503:!0}),Kt=async(e,t)=>_e()?(B.log("Mock API: getDiffUploadUrls called",{runnerId:e,sessionId:t}),{result:{upload_url:"https://s3.mock.com/mock-upload-url-result",s3_key:"mock-s3-key-result"},cumulative:{upload_url:"https://s3.mock.com/mock-upload-url-cumulative",s3_key:"mock-s3-key-cumulative"}}):se(`/api/v1/agent_runners/${e}/sessions/${t}/diff/upload_urls`,{method:"POST"}),Jt=async(e,t)=>_e()?(B.log("Mock API: updateSessionUsage called",{runnerId:e,sessionId:t}),{id:t,runnerId:e,usage:0}):se(`/api/v1/agent_runners/${e}/sessions/${t}/update_usage`,{method:"POST"}),lt=async(e,t,{maxRetries:r=3,baseDelayMs:i=500}={})=>{B.log(`Uploading diff to S3: ${e.substring(0,50)}...`);for(let n=1;n<=r;n++)try{let o=await fetch(e,{method:"PUT",body:t,headers:{"Content-Type":"text/plain"}});if(!o.ok)throw new Error(`S3 upload failed with status ${o.status}`);return o}catch(o){if(n===r)throw o;let s=i*2**(n-1);B.warn(`S3 upload attempt ${n}/${r} failed: ${o.message}. Retrying in ${s}ms...`),await new Promise(a=>setTimeout(a,s))}};var Ee=I("ai_gateway"),ct=null;var He=async()=>{if(ct)return ct;Ee.log("Fetching available AI gateway providers");let e=await fetch(`${Yt().apiUrl}/api/v1/ai-gateway/providers`);if(!e.ok)throw new Error(`Failed to fetch AI gateway providers: ${e.statusText}`);let t=await e.json();return ct=t,Ee.log("Cached AI gateway providers",{providerCount:Object.keys(t.providers).length}),t},Xr=async(e,t)=>{let i=(await He()).providers[e];if(!i)return Ee.log(`Provider '${e}' not found`),!1;let n=i.models.includes(t);return Ee.log(`Model validation for ${e}/${t}`,{isAvailable:n}),n},Vt=async({config:e})=>{let t,r,i,n,o=!e.site?.published_deploy;if(!(o?e.accountId:e.siteId))throw new Error(`No entity id for ${o?"account":"site"}`);let a=async()=>{clearTimeout(i),Ee.log("Requesting AI gateway information");let c=await(o?Ht(e.accountId,e.id,e.sessionId):Wt(e.siteId,e.id,e.sessionId));if({token:t,url:n}=c,r=c.expires_at?c.expires_at*1e3:void 0,Ee.log("Got AI gateway information",{token:!!t,expiresAt:r,url:n}),r){let d=r-Date.now()-6e4;d>0&&(i=setTimeout(()=>{a()},d))}};return await Promise.all([a(),He()]),{get url(){return n},get token(){return t},isModelAvailableForProvider:Xr}};import ee from"process";import ne from"path";import Je from"fs";import{fileURLToPath as sn}from"url";import{createRequire as an}from"module";import{execa as ln,execaCommand as to}from"execa";import{Transform as Zr}from"stream";function Qr(){let e=process.env.NETLIFY_SENSITIVE_ENV_KEYS;return e?e.split(",").map(t=>t.trim()).filter(Boolean):[]}function en(e){let t=e.toLowerCase();return t==="true"||t==="false"?!0:e.trim().length<4}function tn(){let t=Qr().map(r=>process.env[r]).filter(r=>!(!r||en(r)));return[...new Set(t)].sort((r,i)=>i.length-r.length)}function re(e){if(typeof e!="string")return e;let t=tn();if(t.length===0)return e;let r=e;return t.forEach(i=>{let n=new RegExp(rn(i),"g");r=r.replace(n,"******")}),r}function rn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var xe=class extends Zr{constructor(t={}){super({...t,objectMode:!1})}_transform(t,r,i){let n=t.toString(),o=re(n);i(null,o)}};function zt(){if(!(process.env.NETLIFY_MASK_LOGS!=="false"))return;let t=process.stdout.write.bind(process.stdout),r=process.stderr.write.bind(process.stderr);process.stdout.write=function(i,n,o){let s=typeof i=="string"?re(i):i;return typeof n=="function"?t(s,n):t(s,n,o)},process.stderr.write=function(i,n,o){let s=typeof i=="string"?re(i):i;return typeof n=="function"?r(s,n):r(s,n,o)}}var $e=null,Xt=e=>($e&&$e.destroy(),$e=new ae({totalAllowedTime:e}),$e),Zt=()=>$e;var ae=class{constructor({totalAllowedTime:t}){this.withStageTimer=async(t,r,i)=>{if(this.isTimeExpired())throw new Error(`${t} stage did not complete in the allowed time. Time has already expired.`);let n=this.onTimesUp(()=>{throw new Error(`${t} stage did not complete in the allowed time.`)}),o=null,s=null;i!==void 0&&(s=new Promise((a,l)=>{o=setTimeout(()=>{l(new Error(`${t} stage exceeded its maximum duration of ${i}ms`))},i)}));try{return s?await Promise.race([r(),s]):await r()}finally{n(),o&&clearTimeout(o)}};this.startTime=Date.now(),this.totalAllowedTime=t,this.globalTimeoutId=null,this.subscribers=[],this.hasTimedOut=!1,this.setupGlobalTimeout()}getElapsedTime(){return Date.now()-this.startTime}getRemainingTime(){let t=this.getElapsedTime(),r=this.totalAllowedTime-t;return Math.max(0,r)}isTimeExpired(){return this.getRemainingTime()===0||this.hasTimedOut}setupGlobalTimeout(){this.globalTimeoutId&&clearTimeout(this.globalTimeoutId),this.globalTimeoutId=setTimeout(()=>{this.notifyTimeUp()},this.totalAllowedTime)}notifyTimeUp(){this.hasTimedOut=!0;for(let t=this.subscribers.length-1;t>=0;t--)try{this.subscribers[t]()}catch(r){console.error("TimeKeeper: Error in time up callback:",r)}}onTimesUp(t){if(this.subscribers.push(t),this.hasTimedOut)try{t()}catch(r){console.error("TimeKeeper: Error in time up callback:",r)}return()=>{let r=this.subscribers.indexOf(t);r>-1&&this.subscribers.splice(r,1)}}off(t){let r=this.subscribers.indexOf(t);r>-1&&this.subscribers.splice(r,1)}clearSubscribers(){this.subscribers.length=0}getSubscriberCount(){return this.subscribers.length}destroy(){this.globalTimeoutId&&(clearTimeout(this.globalTimeoutId),this.globalTimeoutId=null),this.clearSubscribers()}static{this.timeUnits={seconds:t=>t*1e3,minutes:t=>t*60*1e3,hours:t=>t*60*60*1e3}}};var Qt="netlify-agent-runner-context.md",ut="task-history",Q=".netlify",pe="results.md",dt="assets";var er="free";var me=1800*1e3,nn=["\\.claude","\\.gemini","\\.codex","\\.agents"],We=new RegExp(`(^|/)(${nn.join("|")})/skills/`),Ke=/(^|\/)((CLAUDE|AGENTS|GEMINI)(\.local)?\.md)$/,f={Environment:"environment",UserMessage:"user-message",AgentMessage:"agent-message",Task:"task",RunCommand:"run-command",Explore:"explore",Plan:"plan",FileRead:"file-read",FileWrite:"file-write",Notebook:"notebook",Web:"web",Todo:"todo",Reasoning:"reasoning",Skill:"skill",Memorize:"memorize",Deployment:"deployment",SiteGeneration:"site-generation"};var tr={name:"@netlify/agent-runner-cli",type:"module",version:"1.93.1",description:"CLI tool for running Netlify agents",main:"./dist/index.js",types:"./dist/index.d.ts",exports:"./dist/index.js",bin:{"agent-runner-cli":"./dist/bin.js","agent-runner-cli-local":"./dist/bin-local.js"},files:["dist/**/*.js","dist/**/*.d.ts","dist/skills/**","patches","scripts"],scripts:{build:"tsup",dev:"tsup --watch",prepare:"husky install node_modules/@netlify/eslint-config-node/.husky/",prepublishOnly:"npm ci && npm test",prepack:"npm run build",test:"run-s build format test:dev",format:"run-s build format:check-fix:*","format:ci":"run-s build format:check:*","format:check-fix:lint":"run-e format:check:lint format:fix:lint","format:check:lint":"cross-env-shell eslint $npm_package_config_eslint","format:fix:lint":"cross-env-shell eslint --fix $npm_package_config_eslint","format:check-fix:prettier":"run-e format:check:prettier format:fix:prettier","format:check:prettier":"cross-env-shell prettier --check $npm_package_config_prettier","format:fix:prettier":"cross-env-shell prettier --write $npm_package_config_prettier","test:dev":"run-s build test:dev:*","test:ci":"run-s build test:ci:*","test:dev:vitest":"LOG=0 vitest --exclude '**/integration/**'","test:ci:vitest":"LOG=0 c8 -r lcovonly -r text -r json vitest --exclude '**/integration/**'","test:integration":"vitest run test/integration/","test:integration:codex":"vitest run test/integration/codex.test.ts","test:integration:claude":"vitest run test/integration/claude.test.ts","test:integration:gemini":"vitest run test/integration/gemini.test.ts","test:integration:create-stage":"vitest run test/integration/create.test.ts","test:integration:skill-invocation":"vitest run test/integration/skill-invocation.test.ts","check:types":"tsc --noEmit",postinstall:"node scripts/postinstall.js"},config:{eslint:'--cache --format=codeframe --max-warnings=0 "{src,scripts,test,.github}/**/*.{js,ts,md,html}"',prettier:'--ignore-path .gitignore --loglevel=warn "{src,scripts,test,.github}/**/*.{js,ts,md,yml,json,html}" "*.{js,ts,yml,json,html}" ".*.{js,ts,yml,json,html}" "!**/package-lock.json" "!package-lock.json" "!src/skills/**/*.md"'},keywords:[],license:"MIT",repository:"netlify/agent-runner-cli",bugs:{url:"https://github.com/netlify/agent-runner-cli/issues"},author:"Netlify Inc.",directories:{test:"test"},devDependencies:{"@commitlint/cli":"^20.0.0","@commitlint/config-conventional":"^20.0.0","@eslint/compat":"^2.0.0","@eslint/js":"^9.35.0","@netlify/eslint-config-node":"^7.0.1","@types/node":"^24.5.0","@typescript-eslint/eslint-plugin":"^8.0.0","@typescript-eslint/parser":"^8.0.0","@vitest/eslint-plugin":"^1.6.6",c8:"^10.0.0","eslint-config-prettier":"^10.1.8","eslint-plugin-n":"^17.0.0",husky:"^9.0.0","patch-package":"^8.0.0",tsup:"^8.5.0",typescript:"^5.0.0","typescript-eslint":"^8.44.0",vitest:"^4.0.16"},dependencies:{"@anthropic-ai/claude-code":"2.1.81","@anthropic-ai/sdk":"0.78.0","@google/gemini-cli":"0.31.0","@netlify/otel":"^5.1.5","@netlify/ts-cli":"^1.0.3","@openai/codex":"0.115.0","@opentelemetry/exporter-trace-otlp-grpc":"0.57.2",execa:"^9.6.1",minimist:"^1.2.8",openai:"6.26.0"}};var cn=sn(import.meta.url),un=ne.dirname(cn),dn=an(import.meta.url),Te=I("shell"),pt=new Set,pn={preferLocal:!0},$=(e,t,r)=>{let[i,n]=mn(t,r),o={...pn,...n},s=ln(e,i,o);gn(s,o),hn(s);let a=r?.idleTimeout;return a&&a>0&&fn(s,a),s};var mn=function(e,t){return Array.isArray(e)?[e,t]:typeof e=="object"&&e!==null?[[],e]:[[],void 0]},gn=(e,t)=>{if(t.stdio!==void 0||t.stdout!==void 0||t.stderr!==void 0)return;if(ee.env.NETLIFY_MASK_LOGS!=="false"){e.all?.pipe(new xe).pipe(ee.stdout),e.stdout?.pipe(new xe).pipe(ee.stdout),e.stderr?.pipe(new xe).pipe(ee.stderr);return}e.stdout?.pipe(ee.stdout),e.stderr?.pipe(ee.stderr)},mt=(e,t="SIGTERM")=>{try{return e.pid&&!e.killed?(ee.kill(-e.pid,t),Te.log(`Killed process ${e.pid} with signal ${t}`),!0):!1}catch(r){return Te.error("Error killing process:",r),!1}},rr=e=>mt(e,"SIGKILL"),fn=(e,t)=>{let r=null,i=()=>{Te.log(`Process ${e.pid} killed due to idle timeout (no output for ${t}ms)`),mt(e,"SIGTERM"),setTimeout(()=>{e.pid&&!e.killed&&(Te.log(`Force killing idle process ${e.pid}`),rr(e))},5e3)},n=()=>{r&&clearTimeout(r),r=setTimeout(i,t)};n(),e.stdout?.on("data",n),e.stderr?.on("data",n);let o=()=>{r&&(clearTimeout(r),r=null)};e.on("exit",o),e.on("error",o)},hn=e=>{pt.add(e);let t=Zt();if(t){let r=t.onTimesUp(()=>{Te.log(`Global timer expired, killing process ${e.pid}`),mt(e,"SIGTERM"),setTimeout(()=>{e.pid&&!e.killed&&(Te.log(`Force killing process ${e.pid} after timeout`),rr(e))},5e3)});e.on("exit",()=>{pt.delete(e),r()}),e.on("error",()=>{pt.delete(e),r()})}};function le(e,t){if(!ee.env.NETLIFY_LOCAL_MODE)try{let n=dn.resolve(tr.name),o=ne.dirname(n);for(;o!==ne.dirname(o);){let s=ne.dirname(o);if(ne.basename(s)==="node_modules"){let a=ne.join(s,".bin",t);if(Je.existsSync(a))return a;break}o=s}}catch(n){console.error("Could not resolve package.json",n)}if(ee.env.NODE_PATH){let n=ne.join(ee.env.NODE_PATH,".bin",t);if(Je.existsSync(n))return n}let r=ne.join(e,"node_modules",".bin",t);if(Je.existsSync(r))return r;let i=ne.join(un,"..","node_modules",".bin",t);if(Je.existsSync(i))return i}var yn=I("utils"),wn=e=>new Promise(t=>{setTimeout(t,e)}),Ve=(e,t=3e3)=>{let r=!1,i=null,n=[],o=null,s=(...a)=>{if(r)return i=a,new Promise(d=>{n.push(d)});r=!0;let l,c=new Promise(d=>{l=d});return o=(async()=>{await Promise.resolve();let d=await e(...a);for(l(d);;){if(await wn(t),!i)return r=!1,o=null,d;let u=i,p=n;i=null,n=[],d=await e(...u),p.forEach(g=>{g(d)})}})(),c};return s.flush=async()=>{if((r||i)&&o)return await o,s.flush()},s},Se=(e,t,r=!1)=>{let i=null,n=null,o=null,s=function(...a){n=a,o=this;let l=r&&!i;clearTimeout(i),i=setTimeout(()=>{i=null,r||(e.apply(o,n),n=null,o=null)},t),l&&(e.apply(o,n),n=null,o=null)};return s.cancel=()=>{clearTimeout(i),i=null,n=null,o=null},s.flush=()=>{if(i){clearTimeout(i);let a=n,l=o;i=null,n=null,o=null,e.apply(l,a)}},s},nr=(e,t=!0,r)=>{if(e)try{return JSON.parse(e)}catch(i){t&&(r?.error?r.error("Could not parse JSON",i):yn.error("Could not parse JSON",i))}},gt=e=>e.charAt(0).toUpperCase()+e.slice(1),ce=e=>e.split("-").map(t=>t.length===2?t.toUpperCase():gt(t)).join(" ");function ge(e,t){t&&e.log(`Skill invoked: ${t}`)}var ir=e=>Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0)),or=(e,t)=>{let n=".netlify.app",o="agent-";if(!t)return`${o}${e.slice(0,6)}`;let a=`--${t}${n}`;if(a.length>55)return"";let l=60-a.length;if(l<=0)return"";if(l>=o.length+6){let c=Math.min(l-o.length,e.length);return`${o}${e.slice(0,c)}`}return e.slice(0,l)};var _n=1e4,ft=(e,t=_n)=>{if(!e||typeof e!="string"||e.length<=t)return e;let i=e.startsWith("```")?"\n... [truncated]\n```":"... [truncated]";return e.slice(0,t)+i};import{Buffer as sr}from"buffer";import En from"path";var ar=I("repo"),cr=async({config:e,isRetry:t,cwd:r=process.cwd()})=>{ar.info("Getting runner diffs");let i=await Tn(r),{hasChanges:n}=i,{status:o}=i;if(!n)return{hasChanges:!1};if(!t){let _=In(o);await vn(_,r)}ar.info("Changes after processing"),await yt(r);let s=await _t(o,r);if(await ht(s,r),n=await Sn(r),!n)return{hasChanges:!1,ignored:s};process.env.NETLIFY_INTERNAL_GIT="1";try{await $("git",["commit","-m","Agent runner"],{cwd:r})}finally{process.env.NETLIFY_INTERNAL_GIT="0"}let a={stdio:["ignore","pipe","pipe"],cwd:r},l=await $("git",["diff",e.runSha,"HEAD"],a),c=String(l.stdout??"");if(n=!!c,!n)return await lr(r),{hasChanges:!1,ignored:s};let d=await $("git",["diff",e.runSha,"HEAD","--binary"],a),u=String(d.stdout??""),p,g;if(e.sha){let _=await $("git",["diff",e.sha,"HEAD"],a);p=String(_.stdout??"");let T=await $("git",["diff",e.sha,"HEAD","--binary"],a),w=String(T.stdout??"");p!==w&&(g=sr.from(w).toString("base64"))}await lr(r);let x={hasChanges:!0,diff:c,resultDiff:p,ignored:s};return c!==u&&(x.diffBinary=sr.from(u).toString("base64")),g&&(x.resultDiffBinary=g),x},lr=async(e=process.cwd())=>{process.env.NETLIFY_LOCAL_MODE&&await $("git",["reset","--soft","HEAD~1"],{cwd:e})},ht=async(e=[],t=process.cwd())=>{process.env.NETLIFY_INTERNAL_GIT="1";try{await $("git",["add",".",...e],{cwd:t})}finally{process.env.NETLIFY_INTERNAL_GIT="0"}},yt=async(e=process.cwd())=>{let t=await $("git",["status","-s"],{cwd:e});return String(t.stdout??"")},ur=/.. (.+)?\.log$/,xn=[ur],Tn=async(e=process.cwd())=>{let t=await yt(e);return{hasChanges:(t.trim().length===0?[]:t.split(`
|
|
7
|
+
`);return o.length>e.length*.8?e:o}import{execSync as Bn}from"child_process";import vr from"fs/promises";import Hn from"path";import he from"process";import{getTracer as Wn}from"@netlify/otel";import Pe from"process";var Z=class extends Error{constructor(r,i,n,o=!1){super(r);this.statusCode=i;this.userMessage=n;this.isCreditLimitExceeded=o;this.name="GracefulShutdownError"}},Ye=e=>e instanceof Z;var qe=Pe.env.NETLIFY_API_URL,Be=Pe.env.NETLIFY_API_TOKEN,B=I("api"),_e=()=>Pe.env.NETLIFY_LOCAL_MODE==="true",se=async(e,t={})=>{if(!qe||!Be)throw new Error("No API URL or token");let r=new URL(e,qe),i={...t,headers:{...t.headers,Authorization:`Bearer ${Be}`}};Pe.env.AGENT_RUNNERS_DEBUG==="true"&&(i.headers["x-nf-debug-logging"]="true"),t.json&&(i.headers||={},i.headers["Content-Type"]="application/json",i.body=JSON.stringify(t.json));let n=await fetch(r,i),o=n.ok&&n.status<=299;if(Pe.env.AGENT_RUNNERS_DEBUG==="true")B.log(`Response headers for ${r}:`),n.headers.forEach((a,l)=>{B.log(` ${l}: ${a}`)});else{let a=n.headers.get("x-request-id")||n.headers.get("x-nf-request-id");B.log(`Request ID for ${r}: ${a||"N/A"}`)}if(o||B.error(`Got status ${n.status} for request ${r}`),t.raw){if(!o)throw new Error(`API request failed: ${n.status} ${n.statusText}`);return n}let s=await(n.headers.get("content-type")?.includes("application/json")?n.json():n.text());if(!o){let a=typeof s=="string"?s:JSON.stringify(s);throw n.status===404?new Z(`API request failed: 404 - ${a}`,404,"The site associated with this agent run no longer exists."):n.status===503&&t.gracefulOn503&&a.toLowerCase().includes("usage exceeded")?new Z(`API request failed: 503 - ${a}`,503,"Credit limit reached. Please add more credits to continue using Agent Runners.",!0):new Error(`API request failed: ${n.status} - ${a}`)}return s},jt=e=>{B.log("Setting details for api",{apiUrl:e?.constants?.NETLIFY_API_HOST,token:!!e?.constants?.NETLIFY_API_TOKEN}),e?.constants?.NETLIFY_API_HOST&&(qe=`https://${e.constants.NETLIFY_API_HOST}`),e?.constants?.NETLIFY_API_TOKEN&&(Be=e.constants.NETLIFY_API_TOKEN)},Yt=()=>({apiUrl:qe,token:Be}),Ne=async(e,t)=>_e()?(B.log("Mock API: updateRunner called",{runnerId:e,data:t}),{id:e,...t}):se(`/api/v1/agent_runners/${e}`,{method:"PUT",json:t}),H=async(e,t,r)=>_e()?(B.log("Mock API: updateRunnerSession called",JSON.stringify({runnerId:e,sessionId:t,data:r},null,2)),{id:e,sessionId:t,...r}):se(`/api/v1/agent_runners/${e}/sessions/${t}`,{method:"PUT",json:r});var qt=async e=>_e()?(B.log("Mock API: getSite called",{siteId:e}),{id:e,published_deploy:{id:"id"}}):se(`/api/v1/sites/${e}`),Bt=async(e,t)=>_e()?(B.log("Mock API: getRunnerSession called",{runnerId:e,sessionId:t}),{id:t,runnerId:e,state:"running"}):se(`/api/v1/agent_runners/${e}/sessions/${t}`),Ht=(e,t,r)=>se(`/api/v1/accounts/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r},gracefulOn503:!0}),Wt=(e,t,r)=>se(`/api/v1/sites/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r},gracefulOn503:!0}),Kt=async(e,t)=>_e()?(B.log("Mock API: getDiffUploadUrls called",{runnerId:e,sessionId:t}),{result:{upload_url:"https://s3.mock.com/mock-upload-url-result",s3_key:"mock-s3-key-result"},cumulative:{upload_url:"https://s3.mock.com/mock-upload-url-cumulative",s3_key:"mock-s3-key-cumulative"}}):se(`/api/v1/agent_runners/${e}/sessions/${t}/diff/upload_urls`,{method:"POST"}),Jt=async(e,t)=>_e()?(B.log("Mock API: updateSessionUsage called",{runnerId:e,sessionId:t}),{id:t,runnerId:e,usage:0}):se(`/api/v1/agent_runners/${e}/sessions/${t}/update_usage`,{method:"POST"}),lt=async(e,t,{maxRetries:r=3,baseDelayMs:i=500}={})=>{B.log(`Uploading diff to S3: ${e.substring(0,50)}...`);for(let n=1;n<=r;n++)try{let o=await fetch(e,{method:"PUT",body:t,headers:{"Content-Type":"text/plain"}});if(!o.ok)throw new Error(`S3 upload failed with status ${o.status}`);return o}catch(o){if(n===r)throw o;let s=i*2**(n-1);B.warn(`S3 upload attempt ${n}/${r} failed: ${o.message}. Retrying in ${s}ms...`),await new Promise(a=>setTimeout(a,s))}};var Ee=I("ai_gateway"),ct=null;var He=async()=>{if(ct)return ct;Ee.log("Fetching available AI gateway providers");let e=await fetch(`${Yt().apiUrl}/api/v1/ai-gateway/providers`);if(!e.ok)throw new Error(`Failed to fetch AI gateway providers: ${e.statusText}`);let t=await e.json();return ct=t,Ee.log("Cached AI gateway providers",{providerCount:Object.keys(t.providers).length}),t},Xr=async(e,t)=>{let i=(await He()).providers[e];if(!i)return Ee.log(`Provider '${e}' not found`),!1;let n=i.models.includes(t);return Ee.log(`Model validation for ${e}/${t}`,{isAvailable:n}),n},Vt=async({config:e})=>{let t,r,i,n,o=!e.site?.published_deploy;if(!(o?e.accountId:e.siteId))throw new Error(`No entity id for ${o?"account":"site"}`);let a=async()=>{clearTimeout(i),Ee.log("Requesting AI gateway information");let c=await(o?Ht(e.accountId,e.id,e.sessionId):Wt(e.siteId,e.id,e.sessionId));if({token:t,url:n}=c,r=c.expires_at?c.expires_at*1e3:void 0,Ee.log("Got AI gateway information",{token:!!t,expiresAt:r,url:n}),r){let d=r-Date.now()-6e4;d>0&&(i=setTimeout(()=>{a()},d))}};return await Promise.all([a(),He()]),{get url(){return n},get token(){return t},isModelAvailableForProvider:Xr}};import ee from"process";import ne from"path";import Je from"fs";import{fileURLToPath as sn}from"url";import{createRequire as an}from"module";import{execa as ln,execaCommand as to}from"execa";import{Transform as Zr}from"stream";function Qr(){let e=process.env.NETLIFY_SENSITIVE_ENV_KEYS;return e?e.split(",").map(t=>t.trim()).filter(Boolean):[]}function en(e){let t=e.toLowerCase();return t==="true"||t==="false"?!0:e.trim().length<4}function tn(){let t=Qr().map(r=>process.env[r]).filter(r=>!(!r||en(r)));return[...new Set(t)].sort((r,i)=>i.length-r.length)}function re(e){if(typeof e!="string")return e;let t=tn();if(t.length===0)return e;let r=e;return t.forEach(i=>{let n=new RegExp(rn(i),"g");r=r.replace(n,"******")}),r}function rn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var xe=class extends Zr{constructor(t={}){super({...t,objectMode:!1})}_transform(t,r,i){let n=t.toString(),o=re(n);i(null,o)}};function zt(){if(!(process.env.NETLIFY_MASK_LOGS!=="false"))return;let t=process.stdout.write.bind(process.stdout),r=process.stderr.write.bind(process.stderr);process.stdout.write=function(i,n,o){let s=typeof i=="string"?re(i):i;return typeof n=="function"?t(s,n):t(s,n,o)},process.stderr.write=function(i,n,o){let s=typeof i=="string"?re(i):i;return typeof n=="function"?r(s,n):r(s,n,o)}}var $e=null,Xt=e=>($e&&$e.destroy(),$e=new ae({totalAllowedTime:e}),$e),Zt=()=>$e;var ae=class{constructor({totalAllowedTime:t}){this.withStageTimer=async(t,r,i)=>{if(this.isTimeExpired())throw new Error(`${t} stage did not complete in the allowed time. Time has already expired.`);let n=this.onTimesUp(()=>{throw new Error(`${t} stage did not complete in the allowed time.`)}),o=null,s=null;i!==void 0&&(s=new Promise((a,l)=>{o=setTimeout(()=>{l(new Error(`${t} stage exceeded its maximum duration of ${i}ms`))},i)}));try{return s?await Promise.race([r(),s]):await r()}finally{n(),o&&clearTimeout(o)}};this.startTime=Date.now(),this.totalAllowedTime=t,this.globalTimeoutId=null,this.subscribers=[],this.hasTimedOut=!1,this.setupGlobalTimeout()}getElapsedTime(){return Date.now()-this.startTime}getRemainingTime(){let t=this.getElapsedTime(),r=this.totalAllowedTime-t;return Math.max(0,r)}isTimeExpired(){return this.getRemainingTime()===0||this.hasTimedOut}setupGlobalTimeout(){this.globalTimeoutId&&clearTimeout(this.globalTimeoutId),this.globalTimeoutId=setTimeout(()=>{this.notifyTimeUp()},this.totalAllowedTime)}notifyTimeUp(){this.hasTimedOut=!0;for(let t=this.subscribers.length-1;t>=0;t--)try{this.subscribers[t]()}catch(r){console.error("TimeKeeper: Error in time up callback:",r)}}onTimesUp(t){if(this.subscribers.push(t),this.hasTimedOut)try{t()}catch(r){console.error("TimeKeeper: Error in time up callback:",r)}return()=>{let r=this.subscribers.indexOf(t);r>-1&&this.subscribers.splice(r,1)}}off(t){let r=this.subscribers.indexOf(t);r>-1&&this.subscribers.splice(r,1)}clearSubscribers(){this.subscribers.length=0}getSubscriberCount(){return this.subscribers.length}destroy(){this.globalTimeoutId&&(clearTimeout(this.globalTimeoutId),this.globalTimeoutId=null),this.clearSubscribers()}static{this.timeUnits={seconds:t=>t*1e3,minutes:t=>t*60*1e3,hours:t=>t*60*60*1e3}}};var Qt="netlify-agent-runner-context.md",ut="task-history",Q=".netlify",pe="results.md",dt="assets";var er="free";var me=1800*1e3,nn=["\\.claude","\\.gemini","\\.codex","\\.agents"],We=new RegExp(`(^|/)(${nn.join("|")})/skills/`),Ke=/(^|\/)((CLAUDE|AGENTS|GEMINI)(\.local)?\.md)$/,f={Environment:"environment",UserMessage:"user-message",AgentMessage:"agent-message",Task:"task",RunCommand:"run-command",Explore:"explore",Plan:"plan",FileRead:"file-read",FileWrite:"file-write",Notebook:"notebook",Web:"web",Todo:"todo",Reasoning:"reasoning",Skill:"skill",Memorize:"memorize",Deployment:"deployment",SiteGeneration:"site-generation"};var tr={name:"@netlify/agent-runner-cli",type:"module",version:"1.93.2",description:"CLI tool for running Netlify agents",main:"./dist/index.js",types:"./dist/index.d.ts",exports:"./dist/index.js",bin:{"agent-runner-cli":"./dist/bin.js","agent-runner-cli-local":"./dist/bin-local.js"},files:["dist/**/*.js","dist/**/*.d.ts","dist/skills/**","patches","scripts"],scripts:{build:"tsup",dev:"tsup --watch",prepare:"husky install node_modules/@netlify/eslint-config-node/.husky/",prepublishOnly:"npm ci && npm test",prepack:"npm run build",test:"run-s build format test:dev",format:"run-s build format:check-fix:*","format:ci":"run-s build format:check:*","format:check-fix:lint":"run-e format:check:lint format:fix:lint","format:check:lint":"cross-env-shell eslint $npm_package_config_eslint","format:fix:lint":"cross-env-shell eslint --fix $npm_package_config_eslint","format:check-fix:prettier":"run-e format:check:prettier format:fix:prettier","format:check:prettier":"cross-env-shell prettier --check $npm_package_config_prettier","format:fix:prettier":"cross-env-shell prettier --write $npm_package_config_prettier","test:dev":"run-s build test:dev:*","test:ci":"run-s build test:ci:*","test:dev:vitest":"LOG=0 vitest --exclude '**/integration/**'","test:ci:vitest":"LOG=0 c8 -r lcovonly -r text -r json vitest --exclude '**/integration/**'","test:integration":"vitest run test/integration/","test:integration:codex":"vitest run test/integration/codex.test.ts","test:integration:claude":"vitest run test/integration/claude.test.ts","test:integration:gemini":"vitest run test/integration/gemini.test.ts","test:integration:create-stage":"vitest run test/integration/create.test.ts","test:integration:skill-invocation":"vitest run test/integration/skill-invocation.test.ts","check:types":"tsc --noEmit",postinstall:"node scripts/postinstall.js"},config:{eslint:'--cache --format=codeframe --max-warnings=0 "{src,scripts,test,.github}/**/*.{js,ts,md,html}"',prettier:'--ignore-path .gitignore --loglevel=warn "{src,scripts,test,.github}/**/*.{js,ts,md,yml,json,html}" "*.{js,ts,yml,json,html}" ".*.{js,ts,yml,json,html}" "!**/package-lock.json" "!package-lock.json" "!src/skills/**/*.md"'},keywords:[],license:"MIT",repository:"netlify/agent-runner-cli",bugs:{url:"https://github.com/netlify/agent-runner-cli/issues"},author:"Netlify Inc.",directories:{test:"test"},devDependencies:{"@commitlint/cli":"^20.0.0","@commitlint/config-conventional":"^20.0.0","@eslint/compat":"^2.0.0","@eslint/js":"^9.35.0","@netlify/eslint-config-node":"^7.0.1","@types/node":"^24.5.0","@typescript-eslint/eslint-plugin":"^8.0.0","@typescript-eslint/parser":"^8.0.0","@vitest/eslint-plugin":"^1.6.6",c8:"^10.0.0","eslint-config-prettier":"^10.1.8","eslint-plugin-n":"^17.0.0",husky:"^9.0.0","patch-package":"^8.0.0",tsup:"^8.5.0",typescript:"^5.0.0","typescript-eslint":"^8.44.0",vitest:"^4.0.16"},dependencies:{"@anthropic-ai/claude-code":"2.1.81","@anthropic-ai/sdk":"0.78.0","@google/gemini-cli":"0.31.0","@netlify/otel":"^5.1.5","@netlify/ts-cli":"^1.0.4","@openai/codex":"0.115.0","@opentelemetry/exporter-trace-otlp-grpc":"0.57.2",execa:"^9.6.1",minimist:"^1.2.8",openai:"6.26.0"}};var cn=sn(import.meta.url),un=ne.dirname(cn),dn=an(import.meta.url),Te=I("shell"),pt=new Set,pn={preferLocal:!0},$=(e,t,r)=>{let[i,n]=mn(t,r),o={...pn,...n},s=ln(e,i,o);gn(s,o),hn(s);let a=r?.idleTimeout;return a&&a>0&&fn(s,a),s};var mn=function(e,t){return Array.isArray(e)?[e,t]:typeof e=="object"&&e!==null?[[],e]:[[],void 0]},gn=(e,t)=>{if(t.stdio!==void 0||t.stdout!==void 0||t.stderr!==void 0)return;if(ee.env.NETLIFY_MASK_LOGS!=="false"){e.all?.pipe(new xe).pipe(ee.stdout),e.stdout?.pipe(new xe).pipe(ee.stdout),e.stderr?.pipe(new xe).pipe(ee.stderr);return}e.stdout?.pipe(ee.stdout),e.stderr?.pipe(ee.stderr)},mt=(e,t="SIGTERM")=>{try{return e.pid&&!e.killed?(ee.kill(-e.pid,t),Te.log(`Killed process ${e.pid} with signal ${t}`),!0):!1}catch(r){return Te.error("Error killing process:",r),!1}},rr=e=>mt(e,"SIGKILL"),fn=(e,t)=>{let r=null,i=()=>{Te.log(`Process ${e.pid} killed due to idle timeout (no output for ${t}ms)`),mt(e,"SIGTERM"),setTimeout(()=>{e.pid&&!e.killed&&(Te.log(`Force killing idle process ${e.pid}`),rr(e))},5e3)},n=()=>{r&&clearTimeout(r),r=setTimeout(i,t)};n(),e.stdout?.on("data",n),e.stderr?.on("data",n);let o=()=>{r&&(clearTimeout(r),r=null)};e.on("exit",o),e.on("error",o)},hn=e=>{pt.add(e);let t=Zt();if(t){let r=t.onTimesUp(()=>{Te.log(`Global timer expired, killing process ${e.pid}`),mt(e,"SIGTERM"),setTimeout(()=>{e.pid&&!e.killed&&(Te.log(`Force killing process ${e.pid} after timeout`),rr(e))},5e3)});e.on("exit",()=>{pt.delete(e),r()}),e.on("error",()=>{pt.delete(e),r()})}};function le(e,t){if(!ee.env.NETLIFY_LOCAL_MODE)try{let n=dn.resolve(tr.name),o=ne.dirname(n);for(;o!==ne.dirname(o);){let s=ne.dirname(o);if(ne.basename(s)==="node_modules"){let a=ne.join(s,".bin",t);if(Je.existsSync(a))return a;break}o=s}}catch(n){console.error("Could not resolve package.json",n)}if(ee.env.NODE_PATH){let n=ne.join(ee.env.NODE_PATH,".bin",t);if(Je.existsSync(n))return n}let r=ne.join(e,"node_modules",".bin",t);if(Je.existsSync(r))return r;let i=ne.join(un,"..","node_modules",".bin",t);if(Je.existsSync(i))return i}var yn=I("utils"),wn=e=>new Promise(t=>{setTimeout(t,e)}),Ve=(e,t=3e3)=>{let r=!1,i=null,n=[],o=null,s=(...a)=>{if(r)return i=a,new Promise(d=>{n.push(d)});r=!0;let l,c=new Promise(d=>{l=d});return o=(async()=>{await Promise.resolve();let d=await e(...a);for(l(d);;){if(await wn(t),!i)return r=!1,o=null,d;let u=i,p=n;i=null,n=[],d=await e(...u),p.forEach(g=>{g(d)})}})(),c};return s.flush=async()=>{if((r||i)&&o)return await o,s.flush()},s},Se=(e,t,r=!1)=>{let i=null,n=null,o=null,s=function(...a){n=a,o=this;let l=r&&!i;clearTimeout(i),i=setTimeout(()=>{i=null,r||(e.apply(o,n),n=null,o=null)},t),l&&(e.apply(o,n),n=null,o=null)};return s.cancel=()=>{clearTimeout(i),i=null,n=null,o=null},s.flush=()=>{if(i){clearTimeout(i);let a=n,l=o;i=null,n=null,o=null,e.apply(l,a)}},s},nr=(e,t=!0,r)=>{if(e)try{return JSON.parse(e)}catch(i){t&&(r?.error?r.error("Could not parse JSON",i):yn.error("Could not parse JSON",i))}},gt=e=>e.charAt(0).toUpperCase()+e.slice(1),ce=e=>e.split("-").map(t=>t.length===2?t.toUpperCase():gt(t)).join(" ");function ge(e,t){t&&e.log(`Skill invoked: ${t}`)}var ir=e=>Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0)),or=(e,t)=>{let n=".netlify.app",o="agent-";if(!t)return`${o}${e.slice(0,6)}`;let a=`--${t}${n}`;if(a.length>55)return"";let l=60-a.length;if(l<=0)return"";if(l>=o.length+6){let c=Math.min(l-o.length,e.length);return`${o}${e.slice(0,c)}`}return e.slice(0,l)};var _n=1e4,ft=(e,t=_n)=>{if(!e||typeof e!="string"||e.length<=t)return e;let i=e.startsWith("```")?"\n... [truncated]\n```":"... [truncated]";return e.slice(0,t)+i};import{Buffer as sr}from"buffer";import En from"path";var ar=I("repo"),cr=async({config:e,isRetry:t,cwd:r=process.cwd()})=>{ar.info("Getting runner diffs");let i=await Tn(r),{hasChanges:n}=i,{status:o}=i;if(!n)return{hasChanges:!1};if(!t){let _=In(o);await vn(_,r)}ar.info("Changes after processing"),await yt(r);let s=await _t(o,r);if(await ht(s,r),n=await Sn(r),!n)return{hasChanges:!1,ignored:s};process.env.NETLIFY_INTERNAL_GIT="1";try{await $("git",["commit","-m","Agent runner"],{cwd:r})}finally{process.env.NETLIFY_INTERNAL_GIT="0"}let a={stdio:["ignore","pipe","pipe"],cwd:r},l=await $("git",["diff",e.runSha,"HEAD"],a),c=String(l.stdout??"");if(n=!!c,!n)return await lr(r),{hasChanges:!1,ignored:s};let d=await $("git",["diff",e.runSha,"HEAD","--binary"],a),u=String(d.stdout??""),p,g;if(e.sha){let _=await $("git",["diff",e.sha,"HEAD"],a);p=String(_.stdout??"");let T=await $("git",["diff",e.sha,"HEAD","--binary"],a),w=String(T.stdout??"");p!==w&&(g=sr.from(w).toString("base64"))}await lr(r);let x={hasChanges:!0,diff:c,resultDiff:p,ignored:s};return c!==u&&(x.diffBinary=sr.from(u).toString("base64")),g&&(x.resultDiffBinary=g),x},lr=async(e=process.cwd())=>{process.env.NETLIFY_LOCAL_MODE&&await $("git",["reset","--soft","HEAD~1"],{cwd:e})},ht=async(e=[],t=process.cwd())=>{process.env.NETLIFY_INTERNAL_GIT="1";try{await $("git",["add",".",...e],{cwd:t})}finally{process.env.NETLIFY_INTERNAL_GIT="0"}},yt=async(e=process.cwd())=>{let t=await $("git",["status","-s"],{cwd:e});return String(t.stdout??"")},ur=/.. (.+)?\.log$/,xn=[ur],Tn=async(e=process.cwd())=>{let t=await yt(e);return{hasChanges:(t.trim().length===0?[]:t.split(`
|
|
8
8
|
`).filter(n=>xn.some(s=>s instanceof RegExp?s.test(n):n===s)?!1:n[1]?.trim()!=="")).length!==0,status:t}},Sn=async(e=process.cwd())=>{try{return await $("git",["diff","--staged","--quiet"],{cwd:e}),!1}catch{return!0}},wt=async(e=process.cwd())=>{let{stdout:t}=await $("git",["rev-parse","HEAD"],{cwd:e});return String(t??"").trim()},dr=async(e=process.cwd())=>{let{stdout:t}=await $("git",["rev-list","--max-parents=0","HEAD"],{cwd:e});return String(t??"").trim()},_t=async(e,t=process.cwd())=>{e||=await yt(t);let r=[".netlify","node_modules","dist",".next","out",".nuxt",".output",".cache",".turbo",".parcel-cache","coverage",".nyc_output","storybook-static","public/build","CLAUDE.local.md"],i=[];return e.split(`
|
|
9
9
|
`).forEach(n=>{r.forEach(s=>{let a=n===`?? ${s}`,l=n.startsWith(`?? ${s}/`)||n.startsWith(`?? ${s}${En.sep}`);(a||l)&&i.push(`:!${s}`)});let o=n.match(ur)?.[1];o&&i.push(`:!${o}.log`)}),i},Et=async(e=process.cwd())=>{await $("git",["reset","--hard","HEAD"],{cwd:e})},In=e=>{let t=e.split(`
|
|
10
10
|
`).reduce((r,i)=>{if(!i)return r;let[n,o,,...s]=i,a=s.join(""),l=n.trim(),c=o.trim();return r[a]?r[a].change=c:r[a]={filePath:a,stage:l,change:c},r},{});return Object.values(t)},vn=async(e,t=process.cwd())=>{let r=e.filter(i=>i.stage&&!i.change).map(i=>i.filePath);r.length!==0&&await $("git",["restore","--staged","--worktree","--pathspec-from-file=-"],{cwd:t,input:r.join(`
|
|
@@ -187,7 +187,7 @@ Each item of \`templates array\` has properties:
|
|
|
187
187
|
|
|
188
188
|
Result Rules:
|
|
189
189
|
- only 1 \`template\` can be picked; do not change it's value or casing.
|
|
190
|
-
- \`newPrompt\` should
|
|
190
|
+
- \`newPrompt\` should contain: Based on this template, <user prompt>
|
|
191
191
|
- \`packageManager\` should be the preferred package manager if mentioned in the user input (npm, yarn, pnpm), if it's not provided - empty string.
|
|
192
192
|
- \`framework\` should be the name of the framework (e.g. react) if user explicitly provided it, otherwise empty string. Lowercased.
|
|
193
193
|
- should NEVER include any additional text, explanations, labels or extra text.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/agent-runner-cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.93.
|
|
4
|
+
"version": "1.93.2",
|
|
5
5
|
"description": "CLI tool for running Netlify agents",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"@anthropic-ai/sdk": "0.78.0",
|
|
85
85
|
"@google/gemini-cli": "0.31.0",
|
|
86
86
|
"@netlify/otel": "^5.1.5",
|
|
87
|
-
"@netlify/ts-cli": "^1.0.
|
|
87
|
+
"@netlify/ts-cli": "^1.0.4",
|
|
88
88
|
"@openai/codex": "0.115.0",
|
|
89
89
|
"@opentelemetry/exporter-trace-otlp-grpc": "0.57.2",
|
|
90
90
|
"execa": "^9.6.1",
|