@code-partner/codepipe 0.1.128-dev.15.gc7ae329 → 0.1.128-dev.16.gb8c07b2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +2 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- var ae="0.1.128-dev.15.gc7ae329",de="https://hub.dev.codepipe.dev";var fe=2,Ic=1;function lr(t){return typeof t!="number"||!Number.isFinite(t)?!1:t>=Ic&&t<=fe}var $e=".devpipe-context.yaml",fn=[{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",$e]}];function ur(t=1){return`# CodePipe Context Repo format version.
2
+ var ae="0.1.128-dev.16.gb8c07b2",de="https://hub.dev.codepipe.dev";var fe=2,Ic=1;function lr(t){return typeof t!="number"||!Number.isFinite(t)?!1:t>=Ic&&t<=fe}var $e=".devpipe-context.yaml",fn=[{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",$e]}];function ur(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 mn(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 gn(t,e=fn){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 hn(t,e=fn){return e.filter(r=>r.version>t)}function pr(){return{inputTokens:0,outputTokens:0,cacheReadInputTokens:0,cacheCreationInputTokens:0,totalCostUsd:0,model:"",numTurns:0,durationMs:0}}var He=/^[a-z][a-z0-9-]{1,30}$/,Pc="-codepipe-ctx";function xe(t){return`${t}${Pc}`}var Dt={github:"github.com",gitlab:"gitlab.com",bitbucket:"bitbucket.org"};function ot(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 nt="x-bitbucket-api-token-auth";function dr(t){switch(t){case Dt.gitlab:return"oauth2";case Dt.bitbucket:return"x-token-auth";default:return"x-access-token"}}var wn=20;function _(t){return process.env[`CODEPIPE_${t}`]??process.env[`DEVPIPE_${t}`]}import{Command as qf}from"commander";import{homedir as xn}from"node:os";import{mkdirSync as Bc,readFileSync as Gc,writeFileSync as Mc,existsSync as uo}from"node:fs";import{dirname as Sn,join as gr,resolve as Hc}from"node:path";import{fileURLToPath as Fc}from"node:url";import{existsSync as fr,readFileSync as bn,readdirSync as jc,writeFileSync as Ac}from"node:fs";import{dirname as _c,join as Pe}from"node:path";import{parse as Nc}from"yaml";import{existsSync as yn,renameSync as Ec}from"node:fs";function Fe(t,e,r=o=>console.error(o)){if(yn(e)||!yn(t))return!1;try{return Ec(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 me=".codepipe",lo=".devpipe";function Oc(t=process.cwd()){let e=t;for(;;){if(fr(Pe(e,me,"project.yaml")))return e;if(fr(Pe(e,lo,"project.yaml")))return Fe(Pe(e,lo),Pe(e,me))&&Uc(e),e;let r=_c(e);if(r===e)return null;e=r}}function Lc(t){let e=Pe(t,me);return fr(e)?e:Pe(t,lo)}function Uc(t){let e=Pe(t,".gitignore");if(!fr(e))return;let r=bn(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(`
@@ -13,7 +13,7 @@ template_version: ${t}
13
13
  `;return lt(e,r+i+fl.join(`
14
14
  `)+`
15
15
  `),!0}async function qn(t,e){try{if(!je(ge(t,".git")))return;let r=dl(t),o=(await r.raw(["ls-files","--",...ut])).split(`
16
- `).map(n=>n.trim()).filter(Boolean);if(o.length===0)return;pt(t),await r.raw(["rm","--cached","--quiet","--",...o]),await r.add([".gitignore"]),await r.commit("chore(context): move project config out of the Context Repo"),await bo(t),e.info(`[config] migrated ${o.join(", ")} out of the Context Repo \u2014 the local copies are now the config`)}catch(r){e.warn(`[config] context-config migration failed (will retry on next start): ${r instanceof Error?r.message:String(r)}`)}}function wo(t){let e=new Map;for(let r of ut){let o=ge(t,r);je(o)&&e.set(r,ho(o))}return e}function yo(t,e){Wn(t,{recursive:!0});for(let[r,o]of e){let n=ge(t,r);je(n)||lt(n,o)}}var Vn=3,yl=new Set(["knowledge/INDEX.md","adr/INDEX.md","adr/SOURCES.md"]);async function vr(t,e,r){if(!ml(zn(t,".git")))throw new Error(`context repo clone not found at ${t}`);for(let i of e){let s=kl(t,i.path);gl(hl(s),{recursive:!0}),i.encoding==="base64"?Yn(s,Buffer.from(i.content,"base64")):Yn(s,i.content)}let o=Jn(t);await o.add(["-A","--",".",...ut.map(i=>`:(exclude)${i}`)]),(await o.raw(["diff","--cached","--name-only"])).trim()&&(await o.commit(r),await bo(t))}async function bo(t){let e=Jn(t,{unsafe:{allowUnsafeEditor:!0}}),r;for(let o=0;o<=Vn;o++){try{await e.push();return}catch(i){r=i}await e.fetch().catch(()=>{});let n=(await e.revparse(["--abbrev-ref","HEAD"])).trim();try{await e.rebase([`origin/${n}`])}catch{let i=await bl(e);if(i.length>0&&i.every(s=>yl.has(s)))await e.raw(["checkout","--theirs","--",...i]),await e.add(i),await e.raw(["-c","core.editor=true","rebase","--continue"]);else throw await e.rebase(["--abort"]).catch(()=>{}),new Error(`context push: rebase conflict in ${i.join(", ")||"unknown files"} \u2014 concurrent writers edited the same entry; resolve manually in the Context Repo`)}}throw new Error(`context push failed after ${Vn} rebase retries: ${r instanceof Error?r.message:String(r)}`)}async function bl(t){return(await t.raw(["diff","--name-only","--diff-filter=U"]).catch(()=>"")).split(`
16
+ `).map(n=>n.trim()).filter(Boolean);if(o.length===0)return;pt(t),await r.raw(["rm","--cached","--quiet","--",...o]),await r.add([".gitignore"]),await r.commit("chore(context): move project config out of the Context Repo"),await bo(t),e.info(`[config] migrated ${o.join(", ")} out of the Context Repo \u2014 the local copies are now the config`)}catch(r){e.warn(`[config] context-config migration failed (will retry on next start): ${r instanceof Error?r.message:String(r)}`)}}function wo(t){let e=new Map;for(let r of ut){let o=ge(t,r);je(o)&&e.set(r,ho(o))}return e}function yo(t,e){Wn(t,{recursive:!0});for(let[r,o]of e){let n=ge(t,r);je(n)||lt(n,o)}}var Vn=3,yl=new Set(["knowledge/INDEX.md","adr/INDEX.md","adr/SOURCES.md"]);async function vr(t,e,r){if(!ml(zn(t,".git")))throw new Error(`context repo clone not found at ${t}`);for(let i of e){let s=kl(t,i.path);gl(hl(s),{recursive:!0}),i.encoding==="base64"?Yn(s,Buffer.from(i.content,"base64")):Yn(s,i.content)}let o=Jn(t);await o.add(["-A","--","."]),await o.raw(["reset","-q","--",...ut]).catch(()=>{}),(await o.raw(["diff","--cached","--name-only"])).trim()&&(await o.commit(r),await bo(t))}async function bo(t){let e=Jn(t,{unsafe:{allowUnsafeEditor:!0}}),r;for(let o=0;o<=Vn;o++){try{await e.push();return}catch(i){r=i}await e.fetch().catch(()=>{});let n=(await e.revparse(["--abbrev-ref","HEAD"])).trim();try{await e.rebase([`origin/${n}`])}catch{let i=await bl(e);if(i.length>0&&i.every(s=>yl.has(s)))await e.raw(["checkout","--theirs","--",...i]),await e.add(i),await e.raw(["-c","core.editor=true","rebase","--continue"]);else throw await e.rebase(["--abort"]).catch(()=>{}),new Error(`context push: rebase conflict in ${i.join(", ")||"unknown files"} \u2014 concurrent writers edited the same entry; resolve manually in the Context Repo`)}}throw new Error(`context push failed after ${Vn} rebase retries: ${r instanceof Error?r.message:String(r)}`)}async function bl(t){return(await t.raw(["diff","--name-only","--diff-filter=U"]).catch(()=>"")).split(`
17
17
  `).map(r=>r.trim()).filter(Boolean)}function kl(t,e){if(wl(e))throw new Error(`context_write: absolute path rejected: ${e}`);let r=ko(zn(t,e)),o=ko(t+"/");if(r!==ko(t)&&!r.startsWith(o))throw new Error(`context_write: path escapes context repo: ${e}`);return r}var Cl=/^(\d{4})-(.+)\.md$/,Rl="0000-template.md";function Tl(t){let e=t.split(`
18
18
  `),r=e.find(i=>i.startsWith("# ")),o=r?r.replace(/^#\s*(ADR-[\w?]+\s*:\s*)?/i,"").trim():"",n=i=>{let s=new RegExp(`^-\\s*\\*\\*${i}:\\*\\*\\s*(.*)$`,"i");for(let a of e){let c=s.exec(a.trim());if(c)return(c[1]??"").trim()}return""};return{title:o,status:n("Status"),date:n("Date")}}function Il(t,e,r,o,n){let i=String(e).padStart(4,"0"),s=t.split(`
19
19
  `),a=s.findIndex(S=>S.startsWith("# ")),c=a>=0&&(s[a]??"").replace(/^#\s*(ADR-[\w?]+\s*:\s*)?/i,"").trim()||r,l=new Set(["status","date","tasks"]),p=[],m="",u=null,d=a>=0?a+1:0;for(let S=d;S<s.length;S++){let v=(s[S]??"").trim();if(v===""){d=S+1;continue}let T=/^-\s*\*\*([\w ]+):\*\*\s*(.*)$/.exec(v);if(!T)break;let j=(T[1]??"").trim().toLowerCase(),L=(T[2]??"").trim(),C=/supersedes?\b.*?ADR-(\d{1,4})/i.exec(v);C&&(u=parseInt(C[1]??"",10)),j==="tasks"&&(m=L),l.has(j)||p.push(v),d=S+1}let g=m?m.includes(o)?m:`${m}, ${o}`:o,w=s.slice(d).join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-partner/codepipe",
3
- "version": "0.1.128-dev.15.gc7ae329",
3
+ "version": "0.1.128-dev.16.gb8c07b2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {