@code-partner/codepipe 0.1.130-dev.29.g6db2c45 → 0.1.130-dev.30.gc16bf93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var ce="0.1.130-dev.
|
|
2
|
+
var ce="0.1.130-dev.30.gc16bf93",me="https://hub.dev.codepipe.dev";var ge=2,Fc=1;function mr(t){return typeof t!="number"||!Number.isFinite(t)?!1:t>=Fc&&t<=ge}var ve=".devpipe-context.yaml",Sn=[{version:1,summary:"ADR section: adr/ scaffold (README, template, derived INDEX) + the format-version stamp itself",addedPaths:["adr/README.md","adr/0000-template.md","adr/INDEX.md",ve]}];function gr(t=1){return`# CodePipe Context Repo format version.
|
|
3
3
|
# Bumped by the scaffold / the format-migration PR \u2014 do not edit by hand.
|
|
4
4
|
template_version: ${t}
|
|
5
5
|
`}function Cn(t){if(!t)return 0;let e=/^\s*template_version:\s*(\d+)\s*$/m.exec(t),r=e?parseInt(e[1]??"",10):NaN;return Number.isFinite(r)&&r>=0?r:0}function Tn(t,e=Sn){let r=[];for(let o of e)if(!(o.version<=t))for(let n of o.addedPaths)r.includes(n)||r.push(n);return r}function Rn(t,e=Sn){return e.filter(r=>r.version>t)}function hr(){return{inputTokens:0,outputTokens:0,cacheReadInputTokens:0,cacheCreationInputTokens:0,totalCostUsd:0,model:"",numTurns:0,durationMs:0}}var Je=/^[a-z][a-z0-9-]{1,30}$/,Hc="-codepipe-ctx";function Se(t){return`${t}${Hc}`}var Gt={github:"github.com",gitlab:"gitlab.com",bitbucket:"bitbucket.org"};function ut(t){let e=t.match(/^git@([^:/]+):/);if(e)return e[1]??null;let r=t.match(/^ssh:\/\/(?:[^@/]+@)?([^/:]+)/);if(r)return r[1]??null;let o=t.match(/^https?:\/\/(?:[^@/]+@)?([^/:]+)/);return o?o[1]??null:null}var ze="x-bitbucket-api-token-auth";function yr(t){switch(t){case Gt.gitlab:return"oauth2";case Gt.bitbucket:return"x-token-auth";default:return"x-access-token"}}var In=20;function O(t){return process.env[`CODEPIPE_${t}`]??process.env[`DEVPIPE_${t}`]}import{Command as sm}from"commander";import{homedir as _n}from"node:os";import{mkdirSync as Zc,readFileSync as el,writeFileSync as tl,existsSync as wo}from"node:fs";import{dirname as Nn,join as kr,resolve as rl}from"node:path";import{fileURLToPath as ol}from"node:url";import{existsSync as wr,readFileSync as jn,readdirSync as Wc,writeFileSync as qc}from"node:fs";import{dirname as Yc,join as Ae}from"node:path";import{parse as Vc}from"yaml";import{existsSync as Pn,renameSync as Kc}from"node:fs";function Xe(t,e,r=o=>console.error(o)){if(Pn(e)||!Pn(t))return!1;try{return Kc(t,e),r(`migrated ${t} \u2192 ${e} (DevPipe \u2192 CodePipe)`),!0}catch(o){return r(`failed to migrate ${t} \u2192 ${e}: ${o instanceof Error?o.message:String(o)} \u2014 continuing with the legacy path untouched`),!1}}var he=".codepipe",yo=".devpipe";function Jc(t=process.cwd()){let e=t;for(;;){if(wr(Ae(e,he,"project.yaml")))return e;if(wr(Ae(e,yo,"project.yaml")))return Xe(Ae(e,yo),Ae(e,he))&&Xc(e),e;let r=Yc(e);if(r===e)return null;e=r}}function zc(t){let e=Ae(t,he);return wr(e)?e:Ae(t,yo)}function Xc(t){let e=Ae(t,".gitignore");if(!wr(e))return;let r=jn(e,"utf-8"),o=r.split(/\r?\n/).map(n=>{let i=n.trim();return i===".devpipe"||i===".devpipe/"||i==="/.devpipe"||i==="/.devpipe/"?n.replace(".devpipe",".codepipe"):n}).join(`
|
|
@@ -514,7 +514,7 @@ ${r?`
|
|
|
514
514
|
`)+`
|
|
515
515
|
`,{mode:384}),ra(n,`[credential]
|
|
516
516
|
helper = store --file=${o}
|
|
517
|
-
`+e.join(""),{mode:384}),{env:{...process.env,GIT_CONFIG_GLOBAL:n,GIT_TERMINAL_PROMPT:"0"},cleanup:()=>{try{Xp(r,{recursive:!0,force:!0})}catch{}}}}function Yo(t){let e=[],r=[];return t.github?.token&&(e.push(`https://x-access-token:${t.github.token}@github.com`),r.push(Zp)),t.bitbucket?.apiToken&&(e.push(`https://${ze}:${encodeURIComponent(t.bitbucket.apiToken)}@bitbucket.org`),r.push(ed)),t.gitlab?.token&&(e.push(`https://oauth2:${t.gitlab.token}@gitlab.com`),r.push(td)),oa(e,r)}function na(t,e){if(t.contextWrite?.token){let r=ut(e)??"github.com",o=yr(r);return oa([`https://${o}:${t.contextWrite.token}@${r}`],[Jr(r)])}return Yo(t)}import{spawn as sa}from"node:child_process";import{existsSync as zr,mkdirSync as Xr,readFileSync as rd,rmSync as Vo,symlinkSync as od}from"node:fs";import{homedir as nd}from"node:os";import{dirname as Qr,join as it}from"node:path";function aa(){return it(nd(),".codepipe-sandbox","repos")}function ia(t){let e=t instanceof Error?t.message:String(t);return/couldn't find remote ref/i.test(e)||/Remote branch .* not found/i.test(e)||/unknown revision/i.test(e)}async function ca(t,e,r,o,n){if(zr(it(t,".git"))){let i=async s=>{await z(t,["fetch","--depth=1","origin",`+refs/heads/${s}:refs/remotes/origin/${s}`],n),await z(t,["reset","--hard",`origin/${s}`],n),await z(t,["clean","-fdx"],n)};try{return await i(r),r}catch(s){if(!o||o===r||!ia(s))throw s;return console.log(`[git] ref ${r} gone upstream \u2014 falling back to ${o}`),await i(o),o}}zr(t)&&Vo(t,{recursive:!0,force:!0}),Xr(Qr(t),{recursive:!0});try{return await z(void 0,["clone","--depth=1","--single-branch","--branch",r,e,t],n),r}catch(i){if(!o||o===r||!ia(i))throw i;return console.log(`[git] branch ${r} not found on clone \u2014 falling back to ${o}`),zr(t)&&Vo(t,{recursive:!0,force:!0}),Xr(Qr(t),{recursive:!0}),await z(void 0,["clone","--depth=1","--single-branch","--branch",o,e,t],n),o}}async function la(t){await z(t.workspacePath,["reset","--hard",t.baseSha]),await z(t.workspacePath,["clean","-fdx"])}var Zr="CodePipe Agent",eo="codepipe@codepartner.ee";async function ua(t,e){let r=t.workspacePath;await z(r,["add","-A"]);let o=(await $e(r,["write-tree"])).trim(),n=(await $e(r,["rev-parse",`${t.baseSha}^{tree}`])).trim();if(o===n)return null;let i={...process.env,GIT_AUTHOR_NAME:Zr,GIT_AUTHOR_EMAIL:eo,GIT_COMMITTER_NAME:Zr,GIT_COMMITTER_EMAIL:eo};return(await $e(r,["commit-tree",o,"-m",e],i)).trim()}async function pa(t,e,r,o,n){try{await z(t.workspacePath,["push","--force",o,`${e}:refs/heads/${r}`],n)}catch(i){let s=i instanceof Error?i.message:String(i);throw ut(o)==="github.com"&&/without `?workflow`? scope|workflow.*scope/i.test(s)?new Error("delivery push rejected: the Context-Repo push token needs the `workflow` scope (the delivery includes .github/workflows/*). Set secrets.contextWrite.token to a fine-grained PAT on the Context Repo with Contents: write + Workflows: write (or add `workflow` to the project token).\n"+s):i}}async function da(t,e){return $e(t.workspacePath,["diff","--binary",t.baseSha,e])}async function fa(t,e,r,o,n){await z(t.workspacePath,["fetch",o,`+refs/heads/${e}:refs/codepipe-build-delivery`],n),await z(t.workspacePath,["checkout","--force",r])}async function Jo(t,e,r){let o=t.workspacePath,n={...r??process.env,GIT_AUTHOR_NAME:Zr,GIT_AUTHOR_EMAIL:eo,GIT_COMMITTER_NAME:Zr,GIT_COMMITTER_EMAIL:eo};(await $e(o,["rev-parse","--is-shallow-repository"])).trim()==="true"&&await z(o,["fetch","--unshallow","origin",`+refs/heads/${t.ref}:refs/remotes/origin/${t.ref}`],r).catch(l=>{console.warn(`[git] resolve-conflict: --unshallow ${t.ref} failed: ${String(l)}`)}),await z(o,["fetch","origin",`+refs/heads/${e}:refs/remotes/origin/${e}`],r);let s=null;try{await z(o,["merge","--no-commit","--no-ff",`origin/${e}`],n)}catch(l){s=l instanceof Error?l.message:String(l)}let a=(await $e(o,["diff","--name-only","--diff-filter=U"])).split(`
|
|
517
|
+
`+e.join(""),{mode:384}),{env:{...process.env,GIT_CONFIG_GLOBAL:n,GIT_CONFIG_SYSTEM:"/dev/null",GIT_CONFIG_NOSYSTEM:"1",GIT_TERMINAL_PROMPT:"0"},cleanup:()=>{try{Xp(r,{recursive:!0,force:!0})}catch{}}}}function Yo(t){let e=[],r=[];return t.github?.token&&(e.push(`https://x-access-token:${t.github.token}@github.com`),r.push(Zp)),t.bitbucket?.apiToken&&(e.push(`https://${ze}:${encodeURIComponent(t.bitbucket.apiToken)}@bitbucket.org`),r.push(ed)),t.gitlab?.token&&(e.push(`https://oauth2:${t.gitlab.token}@gitlab.com`),r.push(td)),oa(e,r)}function na(t,e){if(t.contextWrite?.token){let r=ut(e)??"github.com",o=yr(r);return oa([`https://${o}:${t.contextWrite.token}@${r}`],[Jr(r)])}return Yo(t)}import{spawn as sa}from"node:child_process";import{existsSync as zr,mkdirSync as Xr,readFileSync as rd,rmSync as Vo,symlinkSync as od}from"node:fs";import{homedir as nd}from"node:os";import{dirname as Qr,join as it}from"node:path";function aa(){return it(nd(),".codepipe-sandbox","repos")}function ia(t){let e=t instanceof Error?t.message:String(t);return/couldn't find remote ref/i.test(e)||/Remote branch .* not found/i.test(e)||/unknown revision/i.test(e)}async function ca(t,e,r,o,n){if(zr(it(t,".git"))){let i=async s=>{await z(t,["fetch","--depth=1","origin",`+refs/heads/${s}:refs/remotes/origin/${s}`],n),await z(t,["reset","--hard",`origin/${s}`],n),await z(t,["clean","-fdx"],n)};try{return await i(r),r}catch(s){if(!o||o===r||!ia(s))throw s;return console.log(`[git] ref ${r} gone upstream \u2014 falling back to ${o}`),await i(o),o}}zr(t)&&Vo(t,{recursive:!0,force:!0}),Xr(Qr(t),{recursive:!0});try{return await z(void 0,["clone","--depth=1","--single-branch","--branch",r,e,t],n),r}catch(i){if(!o||o===r||!ia(i))throw i;return console.log(`[git] branch ${r} not found on clone \u2014 falling back to ${o}`),zr(t)&&Vo(t,{recursive:!0,force:!0}),Xr(Qr(t),{recursive:!0}),await z(void 0,["clone","--depth=1","--single-branch","--branch",o,e,t],n),o}}async function la(t){await z(t.workspacePath,["reset","--hard",t.baseSha]),await z(t.workspacePath,["clean","-fdx"])}var Zr="CodePipe Agent",eo="codepipe@codepartner.ee";async function ua(t,e){let r=t.workspacePath;await z(r,["add","-A"]);let o=(await $e(r,["write-tree"])).trim(),n=(await $e(r,["rev-parse",`${t.baseSha}^{tree}`])).trim();if(o===n)return null;let i={...process.env,GIT_AUTHOR_NAME:Zr,GIT_AUTHOR_EMAIL:eo,GIT_COMMITTER_NAME:Zr,GIT_COMMITTER_EMAIL:eo};return(await $e(r,["commit-tree",o,"-m",e],i)).trim()}async function pa(t,e,r,o,n){try{await z(t.workspacePath,["push","--force",o,`${e}:refs/heads/${r}`],n)}catch(i){let s=i instanceof Error?i.message:String(i);throw ut(o)==="github.com"&&/without `?workflow`? scope|workflow.*scope/i.test(s)?new Error("delivery push rejected: the Context-Repo push token needs the `workflow` scope (the delivery includes .github/workflows/*). Set secrets.contextWrite.token to a fine-grained PAT on the Context Repo with Contents: write + Workflows: write (or add `workflow` to the project token).\n"+s):i}}async function da(t,e){return $e(t.workspacePath,["diff","--binary",t.baseSha,e])}async function fa(t,e,r,o,n){await z(t.workspacePath,["fetch",o,`+refs/heads/${e}:refs/codepipe-build-delivery`],n),await z(t.workspacePath,["checkout","--force",r])}async function Jo(t,e,r){let o=t.workspacePath,n={...r??process.env,GIT_AUTHOR_NAME:Zr,GIT_AUTHOR_EMAIL:eo,GIT_COMMITTER_NAME:Zr,GIT_COMMITTER_EMAIL:eo};(await $e(o,["rev-parse","--is-shallow-repository"])).trim()==="true"&&await z(o,["fetch","--unshallow","origin",`+refs/heads/${t.ref}:refs/remotes/origin/${t.ref}`],r).catch(l=>{console.warn(`[git] resolve-conflict: --unshallow ${t.ref} failed: ${String(l)}`)}),await z(o,["fetch","origin",`+refs/heads/${e}:refs/remotes/origin/${e}`],r);let s=null;try{await z(o,["merge","--no-commit","--no-ff",`origin/${e}`],n)}catch(l){s=l instanceof Error?l.message:String(l)}let a=(await $e(o,["diff","--name-only","--diff-filter=U"])).split(`
|
|
518
518
|
`).map(l=>l.trim()).filter(l=>l.length>0),c=await $e(o,["rev-parse","-q","--verify","MERGE_HEAD"]).then(()=>!0).catch(()=>!1);if(s&&!c&&a.length===0)throw new Error(`resolve-conflict: merge of ${e} into ${t.ref} failed: ${s}`);return a}function z(t,e,r){return new Promise((o,n)=>{let i=sa("git",e,{cwd:t,stdio:["ignore","pipe","pipe"],env:r??{...process.env}}),s=[];i.stderr.setEncoding("utf-8"),i.stderr.on("data",a=>s.push(a)),i.on("error",n),i.on("close",a=>{if(a===0)return o();n(new Error(`git ${e[0]} failed (exit ${a}):
|
|
519
519
|
${s.join("").trim()||"(no stderr)"}`))})})}function $e(t,e,r){return new Promise((o,n)=>{let i=sa("git",e,{cwd:t,stdio:["ignore","pipe","pipe"],env:r??{...process.env}}),s=[],a=[];i.stdout.setEncoding("utf-8"),i.stderr.setEncoding("utf-8"),i.stdout.on("data",c=>s.push(c)),i.stderr.on("data",c=>a.push(c)),i.on("error",n),i.on("close",c=>{if(c===0)return o(s.join(""));n(new Error(`git ${e[0]} failed (exit ${c}):
|
|
520
520
|
${a.join("").trim()||"(no stderr)"}`))})})}function ma(t,e){zr(t)&&Vo(t,{recursive:!0,force:!0}),Xr(Qr(t),{recursive:!0}),od(e,t,"dir")}async function ga(t,e,r){await z(t,["worktree","prune"]).catch(()=>{}),Xr(Qr(r),{recursive:!0}),await z(t,["worktree","add","--detach",r,`origin/${e}`])}async function ha(t,e,r,o="worktree",n){if(r.length===0)return[];let i=[];for(let s of r){let a=it(aa(),e,s.name);console.log(`[git] code: ensure ${s.cloneUrl} @ ${s.ref} \u2192 ${a}`);let c;try{c=await ca(a,s.cloneUrl,s.ref,s.defaultBranch,n)}catch(f){throw new Error(`failed to materialize project repo "${s.name}" (${s.cloneUrl}): `+(f instanceof Error?f.message:String(f)))}let l=(await $e(a,["rev-parse","HEAD"])).trim(),p=it(t,"code",s.name);o==="direct"?(ma(p,a),console.log(`[git] code: linked ${p} \u2192 ${a} @ ${l.slice(0,10)}`)):(await ga(a,c,p),console.log(`[git] code: worktree ${p} \u2190 ${a} @ ${l.slice(0,10)}`)),i.push({name:s.name,workspacePath:p,cachePath:a,ref:c,baseSha:l})}return i}async function ya(t,e,r,o="worktree",n){if(!r||!r.cloneUrl)return null;let i=it(aa(),e,"_context");console.log(`[git] context: ensure ${r.cloneUrl} @ ${r.ref} \u2192 ${i}`);try{await ca(i,r.cloneUrl,r.ref,void 0,n)}catch(c){throw new Error(`failed to materialize context repo (${r.cloneUrl}): `+(c instanceof Error?c.message:String(c)))}let s=it(t,"context");o==="direct"?(ma(s,i),console.log(`[git] context: linked ${s} \u2192 ${i}`)):(await ga(i,r.ref,s),console.log(`[git] context: worktree ${s} \u2190 ${i}`));let a=(await $e(i,["rev-parse","HEAD"])).trim();return{workspacePath:s,cachePath:i,baseSha:a}}async function wa(t,e=[]){let r=t.workspacePath,o=["knowledge",...e];await z(r,["add","-A",...o]).catch(()=>{});let n;try{n=await $e(r,["diff","--cached","--name-only","--diff-filter=d",t.baseSha,"--",...o])}catch{return[]}let i=n.split(`
|