@netlify/agent-runner-cli 0.0.2 → 0.0.3
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.js +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import Ve from"process";import
|
|
2
|
+
import Ve from"process";import Yt from"minimist";import{createRequire as $t}from"module";import Ut from"process";var de=e=>!!e.validateAgentWithBuild;import Xe from"crypto";import oe from"fs/promises";import H from"path";import v from"process";var X="netlify-agent-runner-context.md",V=".netlify",O="other",L="starter";var b="business",$="enterprise",U="free";var qe=e=>{let t=e?.constants||{};return{siteId:t.SITE_ID,accountId:v.env.NETLIFY_TEAM_ID,userId:v.env.NETLIFY_AGENT_RUNNER_USER_ID,siteSlug:v.env.SITE_NAME,localUrl:t.URL||v.env.URL||v.env.NETLIFY_LOCAL_DEV_URL,apiHost:t.NETLIFY_API_HOST,functionsDir:t.FUNCTIONS_DIST}},Ke=()=>{let e=Object.keys(v.env).sort();return{nodeVersion:v.version,envVars:e}},Je=10,We=async e=>{let{name:t,ext:n}=H.parse(e),r=e,o=H.join(v.cwd(),V,r),s=0;for(;await ze(o);){if(s>=Je)throw new Error("Failed to generate context file");r=`${t}-${Xe.randomUUID().slice(0,5)}${n}`,o=H.join(v.cwd(),V,r),s+=1}return r},ze=async e=>{try{return await oe.access(e),!0}catch{return!1}},pe=async({netlify:e,config:t})=>{let n=qe(e),r=Ke(),o=await We(X),s=H.join(v.cwd(),V);await oe.mkdir(s,{recursive:!0});let a=H.join(V,o),i=H.join(v.cwd(),a),c=`# Agent Context
|
|
3
3
|
|
|
4
4
|
In Netlify documentation and interfaces, the terms "site" and "project" refer to the same thing.
|
|
5
5
|
|
|
@@ -112,5 +112,5 @@ ${e.stdout}`),t.join(`
|
|
|
112
112
|
|
|
113
113
|
`)},Lt=e=>{let t=[];return t.push("Build validation failed. Here are the build errors you need to fix:"),e.forEach((n,r)=>{t.push(`Build attempt ${r+1}: ${Bt(n)}`)}),t.join(`
|
|
114
114
|
`)},Ye=async({cliPath:e,context:t,initialResult:n,runAgentCallback:r})=>{console.log("Starting post-execution build validation");let o=await Fe(e,t);if(o.success)return console.log("Build validation passed"),{...n,buildValidation:{attempts:0,finalBuildSuccess:!0,buildHistory:[o]}};console.log("Build validation failed, starting build-fix iteration process");let s=[o],a=[],i=0,c=n;for(let l=1;l<=3;l++){console.log(`Build fix attempt ${l}/3`);let d=Lt(s);console.log("Running agent to fix build errors"),c=await r({errorContext:d}),a=[...a,...c.steps||[]],i+=c.duration||0;let g=await Fe(e,t);if(s.push(g),g.success)return console.log(`Build fixed after ${l} attempts`),{...c,steps:a,duration:i,buildValidation:{attempts:l,finalBuildSuccess:!0,buildHistory:s}};console.log(`Build still failing after attempt ${l}`)}return console.log("Build validation failed after 3 attempts"),{...c,steps:a,duration:i,buildValidation:{attempts:3,finalBuildSuccess:!1,buildHistory:s,error:"Build validation failed - unable to fix build errors after 3 attempts"}}};import bt from"process";var Me=async({netlify:e,hasRepo:t,skipBuild:n,message:r="Agent Preview",deploySubdomain:o,cliPath:s})=>{try{let a=["deploy","--message",`"${r}"`,"--json"];t||(console.log("Deploy: Uploading source zip"),a.push("--upload-source-zip")),o&&a.push("--alias",o),n?(console.log("Deploy: Skipping build"),a.push("--no-build")):a.push("--context","deploy-preview");let i=s||"netlify";console.log(`Running: ${i} ${a.join(" ")}`);let c=await e.utils.run(i,a),l=JSON.parse(c.stdout.trim());console.log(`
|
|
115
|
-
Preview deploy created successfully:`,{deployId:l.deploy_id,deployUrl:l.deploy_url,siteId:l.site_id});let d={deployId:l.deploy_id,previewUrl:l.deploy_url,logsUrl:l.logs,siteId:l.site_id};return t||(d.sourceZipFilename=l.source_zip_filename),d}catch(a){throw console.error("Failed to create preview deploy via CLI:",a),a}};var je=async({cliPath:e,config:t,context:n,result:r,buildValidation:o})=>{let{diff:s,resultDiff:a,hasChanges:i}=await Pe({config:t,netlify:n});console.log("Preview deploy condition check:",{resultUndefined:r===void 0,resultType:typeof r,hasChanges:i,wouldCreatePreview:r!==void 0&&i});let c=null;if(r!==void 0&&i)try{let l;try{let d=await Ee(t.id,t.sessionId);d?.title&&(l=d.title)}catch(d){console.warn("Failed to fetch session title, using fallback message:",d.message)}c=await Me({cliPath:e,netlify:n,hasRepo:t.hasRepo,message:l,skipBuild:o?.finalBuildSuccess,deploySubdomain:Ne(t.id,bt.env.SITE_NAME)})}catch(l){console.warn("Failed to create preview deploy (continuing with agent run):",l)}return console.log("Git status",{diff:s,hasChanges:i}),{diff:s,resultDiff:a,hasChanges:i,previewInfo:c}};var Ge=async({config:e,diff:t,result:n,duration:r,resultDiff:o,previewInfo:s,cleanRunner:a})=>{let i={result_diff:t,result:n||"Done",duration:r};return s&&s.deployId&&(i.deploy_id=s.deployId),s&&s.sourceZipFilename&&(i.result_zip_file_name=s.sourceZipFilename),o?(console.log("Updating total agent result diff"),await J(e.id,{result_diff:o})):console.log("No total result diff, not updating"),await a?.(),console.log("Updated agent runner with result"),await W(e.id,e.sessionId,i),{sessionUpdate:i}};var
|
|
115
|
+
Preview deploy created successfully:`,{deployId:l.deploy_id,deployUrl:l.deploy_url,siteId:l.site_id});let d={deployId:l.deploy_id,previewUrl:l.deploy_url,logsUrl:l.logs,siteId:l.site_id};return t||(d.sourceZipFilename=l.source_zip_filename),d}catch(a){throw console.error("Failed to create preview deploy via CLI:",a),a}};var je=async({cliPath:e,config:t,context:n,result:r,buildValidation:o})=>{let{diff:s,resultDiff:a,hasChanges:i}=await Pe({config:t,netlify:n});console.log("Preview deploy condition check:",{resultUndefined:r===void 0,resultType:typeof r,hasChanges:i,wouldCreatePreview:r!==void 0&&i});let c=null;if(r!==void 0&&i)try{let l;try{let d=await Ee(t.id,t.sessionId);d?.title&&(l=d.title)}catch(d){console.warn("Failed to fetch session title, using fallback message:",d.message)}c=await Me({cliPath:e,netlify:n,hasRepo:t.hasRepo,message:l,skipBuild:o?.finalBuildSuccess,deploySubdomain:Ne(t.id,bt.env.SITE_NAME)})}catch(l){console.warn("Failed to create preview deploy (continuing with agent run):",l)}return console.log("Git status",{diff:s,hasChanges:i}),{diff:s,resultDiff:a,hasChanges:i,previewInfo:c}};var Ge=async({config:e,diff:t,result:n,duration:r,resultDiff:o,previewInfo:s,cleanRunner:a})=>{let i={result_diff:t,result:n||"Done",duration:r};return s&&s.deployId&&(i.deploy_id=s.deployId),s&&s.sourceZipFilename&&(i.result_zip_file_name=s.sourceZipFilename),o?(console.log("Updating total agent result diff"),await J(e.id,{result_diff:o})):console.log("No total result diff, not updating"),await a?.(),console.log("Updated agent runner with result"),await W(e.id,e.sessionId,i),{sessionUpdate:i}};var Dt=$t(import.meta.url),Ft=Dt("../package.json"),He=async({apiToken:e,cliPath:t="netlify",cwd:n}={})=>{console.log("Starting agent runner orchestrator",{cliPath:t,cwd:n,processCwd:Ut.cwd(),version:Ft.version});let{aiGateway:r,config:o,context:s,persistSteps:a,runner:i,stopDev:c}=await Ue({apiToken:e,cliPath:t,cwd:n}),{runnerResult:l}=await De({config:o,context:s,runner:i.runner,persistSteps:a,aiGateway:r});c();let d=l,g;if(de(o)){console.log("Build validation enabled, performing post-execution build validation");let x=await Ye({cliPath:t,config:o,context:s,initialResult:l,runAgentCallback:async({errorContext:C})=>{let{prompt:A}=await q({config:{...o,prompt:l.result},buildErrorContext:C,netlify:s});return i.runner({config:{...o,prompt:A},netlify:s,persistSteps:a,aiGateway:r})}});console.log("Build validation completed:",x.buildValidation),d=x,g=x.buildValidation}let _={ok:!0},h=d.result;if(o.validateAgent&&d.result){let x=ge(d.result);console.log("Validation result",x),x&&(_=x),h=he(d.result)}_.ok||console.log("Validation failed",_);let{diff:T,resultDiff:N,previewInfo:B}=await je({cliPath:t,config:o,context:s,result:h,buildValidation:g});await Ge({config:o,diff:T,result:h,duration:d.duration,resultDiff:N,previewInfo:B,cleanRunner:i.clean})};var ce=Yt(Ve.argv.slice(2),{string:["auth","cwd","cli-path"]});try{await He({apiToken:ce.auth,cwd:ce.cwd,cliPath:ce["cli-path"]})}catch(e){console.error("Error running agent pipeline:",e),Ve.exit(1)}
|
|
116
116
|
//# sourceMappingURL=bin.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as Bt}from"module";var ce=e=>!!e.validateAgentWithBuild;import Ge from"crypto";import oe from"fs/promises";import H from"path";import v from"process";var X="netlify-agent-runner-context.md",V=".netlify",O="other",L="starter";var b="business",$="enterprise",U="free";var He=e=>{let t=e?.constants||{};return{siteId:t.SITE_ID,accountId:v.env.NETLIFY_TEAM_ID,userId:v.env.NETLIFY_AGENT_RUNNER_USER_ID,siteSlug:v.env.SITE_NAME,localUrl:t.URL||v.env.URL||v.env.NETLIFY_LOCAL_DEV_URL,apiHost:t.NETLIFY_API_HOST,functionsDir:t.FUNCTIONS_DIST}},Ve=()=>{let e=Object.keys(v.env).sort();return{nodeVersion:v.version,envVars:e}},Xe=10,qe=async e=>{let{name:t,ext:n}=H.parse(e),r=e,o=H.join(v.cwd(),V,r),s=0;for(;await Ke(o);){if(s>=Xe)throw new Error("Failed to generate context file");r=`${t}-${Ge.randomUUID().slice(0,5)}${n}`,o=H.join(v.cwd(),V,r),s+=1}return r},Ke=async e=>{try{return await oe.access(e),!0}catch{return!1}},de=async({netlify:e,config:t})=>{let n=He(e),r=Ve(),o=await qe(X),s=H.join(v.cwd(),V);await oe.mkdir(s,{recursive:!0});let a=H.join(V,o),i=H.join(v.cwd(),a),c=`# Agent Context
|
|
1
|
+
import{createRequire as Bt}from"module";import Lt from"process";var ce=e=>!!e.validateAgentWithBuild;import Ge from"crypto";import oe from"fs/promises";import H from"path";import v from"process";var X="netlify-agent-runner-context.md",V=".netlify",O="other",L="starter";var b="business",$="enterprise",U="free";var He=e=>{let t=e?.constants||{};return{siteId:t.SITE_ID,accountId:v.env.NETLIFY_TEAM_ID,userId:v.env.NETLIFY_AGENT_RUNNER_USER_ID,siteSlug:v.env.SITE_NAME,localUrl:t.URL||v.env.URL||v.env.NETLIFY_LOCAL_DEV_URL,apiHost:t.NETLIFY_API_HOST,functionsDir:t.FUNCTIONS_DIST}},Ve=()=>{let e=Object.keys(v.env).sort();return{nodeVersion:v.version,envVars:e}},Xe=10,qe=async e=>{let{name:t,ext:n}=H.parse(e),r=e,o=H.join(v.cwd(),V,r),s=0;for(;await Ke(o);){if(s>=Xe)throw new Error("Failed to generate context file");r=`${t}-${Ge.randomUUID().slice(0,5)}${n}`,o=H.join(v.cwd(),V,r),s+=1}return r},Ke=async e=>{try{return await oe.access(e),!0}catch{return!1}},de=async({netlify:e,config:t})=>{let n=He(e),r=Ve(),o=await qe(X),s=H.join(v.cwd(),V);await oe.mkdir(s,{recursive:!0});let a=H.join(V,o),i=H.join(v.cwd(),a),c=`# Agent Context
|
|
2
2
|
|
|
3
3
|
In Netlify documentation and interfaces, the terms "site" and "project" refer to the same thing.
|
|
4
4
|
|
|
@@ -111,5 +111,5 @@ ${e.stdout}`),t.join(`
|
|
|
111
111
|
|
|
112
112
|
`)},kt=e=>{let t=[];return t.push("Build validation failed. Here are the build errors you need to fix:"),e.forEach((n,r)=>{t.push(`Build attempt ${r+1}: ${Pt(n)}`)}),t.join(`
|
|
113
113
|
`)},Fe=async({cliPath:e,context:t,initialResult:n,runAgentCallback:r})=>{console.log("Starting post-execution build validation");let o=await De(e,t);if(o.success)return console.log("Build validation passed"),{...n,buildValidation:{attempts:0,finalBuildSuccess:!0,buildHistory:[o]}};console.log("Build validation failed, starting build-fix iteration process");let s=[o],a=[],i=0,c=n;for(let l=1;l<=3;l++){console.log(`Build fix attempt ${l}/3`);let d=kt(s);console.log("Running agent to fix build errors"),c=await r({errorContext:d}),a=[...a,...c.steps||[]],i+=c.duration||0;let g=await De(e,t);if(s.push(g),g.success)return console.log(`Build fixed after ${l} attempts`),{...c,steps:a,duration:i,buildValidation:{attempts:l,finalBuildSuccess:!0,buildHistory:s}};console.log(`Build still failing after attempt ${l}`)}return console.log("Build validation failed after 3 attempts"),{...c,steps:a,duration:i,buildValidation:{attempts:3,finalBuildSuccess:!1,buildHistory:s,error:"Build validation failed - unable to fix build errors after 3 attempts"}}};import Ot from"process";var Ye=async({netlify:e,hasRepo:t,skipBuild:n,message:r="Agent Preview",deploySubdomain:o,cliPath:s})=>{try{let a=["deploy","--message",`"${r}"`,"--json"];t||(console.log("Deploy: Uploading source zip"),a.push("--upload-source-zip")),o&&a.push("--alias",o),n?(console.log("Deploy: Skipping build"),a.push("--no-build")):a.push("--context","deploy-preview");let i=s||"netlify";console.log(`Running: ${i} ${a.join(" ")}`);let c=await e.utils.run(i,a),l=JSON.parse(c.stdout.trim());console.log(`
|
|
114
|
-
Preview deploy created successfully:`,{deployId:l.deploy_id,deployUrl:l.deploy_url,siteId:l.site_id});let d={deployId:l.deploy_id,previewUrl:l.deploy_url,logsUrl:l.logs,siteId:l.site_id};return t||(d.sourceZipFilename=l.source_zip_filename),d}catch(a){throw console.error("Failed to create preview deploy via CLI:",a),a}};var Me=async({cliPath:e,config:t,context:n,result:r,buildValidation:o})=>{let{diff:s,resultDiff:a,hasChanges:i}=await ve({config:t,netlify:n});console.log("Preview deploy condition check:",{resultUndefined:r===void 0,resultType:typeof r,hasChanges:i,wouldCreatePreview:r!==void 0&&i});let c=null;if(r!==void 0&&i)try{let l;try{let d=await Te(t.id,t.sessionId);d?.title&&(l=d.title)}catch(d){console.warn("Failed to fetch session title, using fallback message:",d.message)}c=await Ye({cliPath:e,netlify:n,hasRepo:t.hasRepo,message:l,skipBuild:o?.finalBuildSuccess,deploySubdomain:Ie(t.id,Ot.env.SITE_NAME)})}catch(l){console.warn("Failed to create preview deploy (continuing with agent run):",l)}return console.log("Git status",{diff:s,hasChanges:i}),{diff:s,resultDiff:a,hasChanges:i,previewInfo:c}};var je=async({config:e,diff:t,result:n,duration:r,resultDiff:o,previewInfo:s,cleanRunner:a})=>{let i={result_diff:t,result:n||"Done",duration:r};return s&&s.deployId&&(i.deploy_id=s.deployId),s&&s.sourceZipFilename&&(i.result_zip_file_name=s.sourceZipFilename),o?(console.log("Updating total agent result diff"),await J(e.id,{result_diff:o})):console.log("No total result diff, not updating"),await a?.(),console.log("Updated agent runner with result"),await W(e.id,e.sessionId,i),{sessionUpdate:i}};var
|
|
114
|
+
Preview deploy created successfully:`,{deployId:l.deploy_id,deployUrl:l.deploy_url,siteId:l.site_id});let d={deployId:l.deploy_id,previewUrl:l.deploy_url,logsUrl:l.logs,siteId:l.site_id};return t||(d.sourceZipFilename=l.source_zip_filename),d}catch(a){throw console.error("Failed to create preview deploy via CLI:",a),a}};var Me=async({cliPath:e,config:t,context:n,result:r,buildValidation:o})=>{let{diff:s,resultDiff:a,hasChanges:i}=await ve({config:t,netlify:n});console.log("Preview deploy condition check:",{resultUndefined:r===void 0,resultType:typeof r,hasChanges:i,wouldCreatePreview:r!==void 0&&i});let c=null;if(r!==void 0&&i)try{let l;try{let d=await Te(t.id,t.sessionId);d?.title&&(l=d.title)}catch(d){console.warn("Failed to fetch session title, using fallback message:",d.message)}c=await Ye({cliPath:e,netlify:n,hasRepo:t.hasRepo,message:l,skipBuild:o?.finalBuildSuccess,deploySubdomain:Ie(t.id,Ot.env.SITE_NAME)})}catch(l){console.warn("Failed to create preview deploy (continuing with agent run):",l)}return console.log("Git status",{diff:s,hasChanges:i}),{diff:s,resultDiff:a,hasChanges:i,previewInfo:c}};var je=async({config:e,diff:t,result:n,duration:r,resultDiff:o,previewInfo:s,cleanRunner:a})=>{let i={result_diff:t,result:n||"Done",duration:r};return s&&s.deployId&&(i.deploy_id=s.deployId),s&&s.sourceZipFilename&&(i.result_zip_file_name=s.sourceZipFilename),o?(console.log("Updating total agent result diff"),await J(e.id,{result_diff:o})):console.log("No total result diff, not updating"),await a?.(),console.log("Updated agent runner with result"),await W(e.id,e.sessionId,i),{sessionUpdate:i}};var bt=Bt(import.meta.url),$t=bt("../package.json"),fn=async({apiToken:e,cliPath:t="netlify",cwd:n}={})=>{console.log("Starting agent runner orchestrator",{cliPath:t,cwd:n,processCwd:Lt.cwd(),version:$t.version});let{aiGateway:r,config:o,context:s,persistSteps:a,runner:i,stopDev:c}=await $e({apiToken:e,cliPath:t,cwd:n}),{runnerResult:l}=await Ue({config:o,context:s,runner:i.runner,persistSteps:a,aiGateway:r});c();let d=l,g;if(ce(o)){console.log("Build validation enabled, performing post-execution build validation");let x=await Fe({cliPath:t,config:o,context:s,initialResult:l,runAgentCallback:async({errorContext:C})=>{let{prompt:A}=await q({config:{...o,prompt:l.result},buildErrorContext:C,netlify:s});return i.runner({config:{...o,prompt:A},netlify:s,persistSteps:a,aiGateway:r})}});console.log("Build validation completed:",x.buildValidation),d=x,g=x.buildValidation}let _={ok:!0},h=d.result;if(o.validateAgent&&d.result){let x=me(d.result);console.log("Validation result",x),x&&(_=x),h=ge(d.result)}_.ok||console.log("Validation failed",_);let{diff:T,resultDiff:N,previewInfo:B}=await Me({cliPath:t,config:o,context:s,result:h,buildValidation:g});await je({config:o,diff:T,result:h,duration:d.duration,resultDiff:N,previewInfo:B,cleanRunner:i.clean})};export{fn as runPipeline};
|
|
115
115
|
//# sourceMappingURL=index.js.map
|