@code-partner/codepipe 0.11.1-dev.228.g62386c4 → 0.11.1-dev.229.g86cd22a

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 +3 -3
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- var Kw=Object.defineProperty;var S=(t,e)=>()=>(t&&(e=t(t=0)),e);var Fe=(t,e)=>{for(var r in e)Kw(t,r,{get:e[r],enumerable:!0})};var Ke,at,Hi=S(()=>{"use strict";Ke="0.11.1-dev.228.g62386c4",at="https://hub.dev.codepipe.dev"});function Yn(t){return typeof t!="number"||!Number.isFinite(t)?!1:t>=mu&&t<=ct}var ct,mu,hu=S(()=>{"use strict";Hi();ct=4,mu=4});var gu=S(()=>{"use strict";Hi()});function Vn(t=6){return`# CodePipe Context Repo format version.
2
+ var Kw=Object.defineProperty;var S=(t,e)=>()=>(t&&(e=t(t=0)),e);var Fe=(t,e)=>{for(var r in e)Kw(t,r,{get:e[r],enumerable:!0})};var Ke,at,Hi=S(()=>{"use strict";Ke="0.11.1-dev.229.g86cd22a",at="https://hub.dev.codepipe.dev"});function Yn(t){return typeof t!="number"||!Number.isFinite(t)?!1:t>=mu&&t<=ct}var ct,mu,hu=S(()=>{"use strict";Hi();ct=4,mu=4});var gu=S(()=>{"use strict";Hi()});function Vn(t=6){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 qi(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 Yi(t,e=Wi){let r=[];for(let n of e)if(!(n.version<=t))for(let o of n.addedPaths)r.includes(o)||r.push(o);return r}function Vi(t,e=Wi){return e.filter(r=>r.version>t)}var yu,lt,Hr,Wi,ku=S(()=>{"use strict";yu=6,lt=".codepipe-context.yaml",Hr=".devpipe-context.yaml",Wi=[{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",lt]},{version:2,summary:"Rename the format-version stamp .devpipe-context.yaml \u2192 .codepipe-context.yaml (drop the devpipe-brand leftover)",addedPaths:[lt]},{version:3,summary:"Custom project actions (the RUN tab): actions/ scaffold with the format README",addedPaths:["actions/README.md"]},{version:4,summary:"Project map: model/ scaffold with the format README (facts/ vs derived/ layout)",addedPaths:["model/README.md"]},{version:5,summary:"Roles: roles/ scaffold with the format README (override a bundled critic by name, or add your own)",addedPaths:["roles/README.md"]},{version:6,summary:"Skills: skills/ scaffold with the format README (procedures the agent invokes instead of improvising)",addedPaths:["skills/README.md"]}]});function Xn(t){return`model/facts/identity/${t}.yaml`}function pr(t){return`model/facts/events/${t}.yaml`}function Ji(t){return`model/facts/annotations/${t}.md`}function Zi(t){return`model/derived/correlates/${t}.yaml`}function Qi(t){return`model/derived/touched/${t}.yaml`}function wu(t){return t===""?"root":t.replace(/\//g,"-")}function ea(t,e){return`model/derived/structure/${t}/${wu(e)}.yaml`}function Vo(t){return typeof t=="string"&&$u.test(t)}function re(t){if(typeof t!="string")return null;let e=t.indexOf(":");if(e<=0)return null;let r=t.indexOf(":",e+1);if(r<0)return null;let n=t.slice(0,e);if(!bu.includes(n))return null;let o=t.slice(e+1,r),s=t.slice(r+1);return o===""&&!Yw.includes(n)||s===""?null:{level:n,repo:o,path:s}}function ge(t){return`task::${t}`}function fe(t,e,r){return`${t}:${e}:${r}`}function Jn(t){let e=[];return kt(t)?(Xo(t.modelFormatVersion)||e.push("modelFormatVersion: missing or not a positive integer"),typeof t.repo!="string"&&e.push("repo: missing (empty string = cross-repo)"),typeof t.builtFromCommit!="string"&&e.push("builtFromCommit: missing"),Array.isArray(t.edges)?t.edges.forEach((r,n)=>{if(!kt(r)){e.push(`edges[${n}]: not an object`);return}ta.includes(r.kind)||e.push(`edges[${n}].kind: unknown "${String(r.kind)}"`),re(r.from)||e.push(`edges[${n}].from: malformed nodeKey`),re(r.to)||e.push(`edges[${n}].to: malformed nodeKey`),r.weight!==void 0&&!(typeof r.weight=="number"&&Number.isFinite(r.weight))&&e.push(`edges[${n}].weight: not a finite number`)}):e.push("edges: not an array"),e.length?{ok:!1,errors:e}:{ok:!0,value:t}):{ok:!1,errors:["edge sheet: not an object"]}}function vu(t){return{...t,edges:Wr(t.edges,e=>`${e.kind} ${e.from} ${e.to}`)}}function fr(t){return hr(vu(t))}function kt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Xo(t){return typeof t=="number"&&Number.isInteger(t)&&t>0}function ut(t){return typeof t=="string"&&t.length>0}function zw(t){return t.modelFormatVersion!==2}function Ct(t){let e=[];if(!kt(t))return{ok:!1,errors:["shard: not an object"]};Xo(t.modelFormatVersion)||e.push("modelFormatVersion: missing or not a positive integer"),ut(t.repo)||e.push("repo: missing or empty"),ut(t.builtFromCommit)||e.push("builtFromCommit: missing or empty");let r=typeof t.repo=="string"?t.repo:"",n=new Set;return Array.isArray(t.nodes)?t.nodes.forEach((o,s)=>{if(!kt(o)){e.push(`nodes[${s}]: not an object`);return}let i=re(o.key);if(!i){e.push(`nodes[${s}].key: malformed nodeKey (${JSON.stringify(o.key??null)})`);return}o.level!==i.level&&e.push(`nodes[${s}]: level "${String(o.level)}" does not match key prefix "${i.level}"`),r&&i.repo!==r&&e.push(`nodes[${s}].key: repo "${i.repo}" mixed into shard of repo "${r}"`);let a=o.key;n.has(a)&&e.push(`nodes[${s}].key: duplicate "${a}"`),n.add(a),o.entityId!==void 0&&!Vo(o.entityId)&&e.push(`nodes[${s}].entityId: malformed (${JSON.stringify(o.entityId)})`)}):e.push("nodes: not an array"),Array.isArray(t.edges)?t.edges.forEach((o,s)=>{if(!kt(o)){e.push(`edges[${s}]: not an object`);return}ta.includes(o.kind)||e.push(`edges[${s}].kind: unknown "${String(o.kind)}"`),(!ut(o.to)||!re(o.to))&&e.push(`edges[${s}].to: malformed nodeKey`),(!ut(o.from)||!n.has(o.from))&&e.push(`edges[${s}].from: "${String(o.from)}" is not a node of this shard`),o.weight!==void 0&&!(typeof o.weight=="number"&&Number.isFinite(o.weight))&&e.push(`edges[${s}].weight: not a finite number`)}):e.push("edges: not an array"),e.length?{ok:!1,errors:e}:{ok:!0,value:t}}function Zn(t){let e=[];if(!kt(t))return{ok:!1,errors:["identity: not an object"]};if(Xo(t.modelFormatVersion)||e.push("modelFormatVersion: missing or not a positive integer"),ut(t.repo)||e.push("repo: missing or empty"),t.builtFromCommit!==void 0&&!ut(t.builtFromCommit)&&e.push("builtFromCommit: not a non-empty string"),!Array.isArray(t.entities))e.push("entities: not an array");else{let r=new Set;t.entities.forEach((n,o)=>{if(!kt(n)){e.push(`entities[${o}]: not an object`);return}Vo(n.entityId)?r.has(n.entityId)?e.push(`entities[${o}].entityId: duplicate "${n.entityId}"`):r.add(n.entityId):e.push(`entities[${o}].entityId: malformed (${JSON.stringify(n.entityId??null)})`),re(n.currentKey)||e.push(`entities[${o}].currentKey: malformed nodeKey`),n.status!=="active"&&n.status!=="orphaned"&&e.push(`entities[${o}].status: expected active|orphaned`),ut(n.firstSeen)||e.push(`entities[${o}].firstSeen: missing`),ut(n.lastSeen)||e.push(`entities[${o}].lastSeen: missing`),n.aliases!==void 0&&(Array.isArray(n.aliases)?n.aliases.forEach((s,i)=>{(!kt(s)||!re(s.key)||!ut(s.until))&&e.push(`entities[${o}].aliases[${i}]: malformed`)}):e.push(`entities[${o}].aliases: not an array`))})}return e.length?{ok:!1,errors:e}:{ok:!0,value:t}}function At(t){let e=[];return kt(t)?(Xo(t.modelFormatVersion)||e.push("modelFormatVersion: missing or not a positive integer"),ut(t.taskKey)||e.push("taskKey: missing or empty"),t.origin!=="bootstrap"&&t.origin!=="pipeline"&&e.push("origin: expected bootstrap|pipeline"),t.date!==void 0&&!(typeof t.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.date))&&e.push("date: expected YYYY-MM-DD"),(!Array.isArray(t.commits)||t.commits.some(r=>!ut(r)))&&e.push("commits: not an array of non-empty strings"),Array.isArray(t.files)?t.files.forEach((r,n)=>{if(!kt(r)||!re(r.key)){e.push(`files[${n}].key: malformed nodeKey`);return}r.entityId!==void 0&&!Vo(r.entityId)&&e.push(`files[${n}].entityId: malformed`),r.churn!==void 0&&!(typeof r.churn=="number"&&r.churn>=0)&&e.push(`files[${n}].churn: not a non-negative number`)}):e.push("files: not an array"),e.length?{ok:!1,errors:e}:{ok:!0,value:t}):{ok:!1,errors:["event: not an object"]}}function Wr(t,e){return[...t].sort((r,n)=>e(r)<e(n)?-1:e(r)>e(n)?1:0)}function xu(t){return{...t,nodes:Wr(t.nodes,e=>e.key),edges:Wr(t.edges,e=>`${e.kind}\0${e.from}\0${e.to}`)}}function Su(t){return{...t,entities:Wr(t.entities,e=>e.entityId).map(e=>e.aliases?{...e,aliases:Wr(e.aliases,r=>`${r.key}\0${r.until}`)}:e)}}function Eu(t){let e=t.links?{...t.links,...t.links.adr?{adr:[...t.links.adr].sort()}:{},...t.links.tasks?{tasks:[...t.links.tasks].sort()}:{}}:void 0;return{...t,commits:[...t.commits].sort(),files:Wr(t.files,r=>r.key),...e?{links:e}:{}}}function zn(t){return Xw.test(t)?t:JSON.stringify(t)}function Ru(t){if(t===null)return"null";if(typeof t=="boolean")return t?"true":"false";if(typeof t=="number"){if(!Number.isFinite(t))throw new Error(`model yaml: non-finite number ${t}`);return JSON.stringify(t)}if(typeof t=="string")return JSON.stringify(t);throw new Error(`model yaml: unsupported scalar ${typeof t}`)}function Iu(t){return t===null||["boolean","number","string"].includes(typeof t)}function zi(t){return Object.entries(t).filter(([,e])=>e!==void 0).sort(([e],[r])=>e<r?-1:e>r?1:0)}function Tu(t,e,r){if(Array.isArray(t)){for(let n of t)if(Iu(n))r.push(`${e}- ${Ru(n)}`);else{if(Array.isArray(n))throw new Error("model yaml: nested arrays are not part of the model schema");{let o=zi(n);if(o.length===0){r.push(`${e}- {}`);continue}o.forEach(([s,i],a)=>{let c=a===0?`${e}- `:`${e} `;Xi(s,i,c,`${e} `,r)})}}return}for(let[n,o]of zi(t))Xi(n,o,e,e,r)}function Xi(t,e,r,n,o){if(Iu(e))o.push(`${r}${zn(t)}: ${Ru(e)}`);else if(Array.isArray(e))e.length===0?o.push(`${r}${zn(t)}: []`):(o.push(`${r}${zn(t)}:`),Tu(e,`${n} `,o));else{let s=zi(e);if(s.length===0)o.push(`${r}${zn(t)}: {}`);else{o.push(`${r}${zn(t)}:`);for(let[i,a]of s)Xi(i,a,`${n} `,`${n} `,o)}}}function hr(t){let e=[];return Tu(t,"",e),e.join(`
@@ -932,7 +932,7 @@ starting codepipe up \u2014 the CLI daemon and an agent worker, with their logs
932
932
  \u2014 write scopes do NOT include read: pick BOTH scopes of each pair
933
933
  (+ admin:repository:bitbucket if this token will provision the Context Repo).
934
934
  The token is shown ONCE \u2014 copy it right away.`);;){let n=ue(await we({message:"Atlassian account email (BITBUCKET_EMAIL) \u2014 clear to skip",initialValue:e??"",validate:s=>!s||!s.trim()||s.includes("@")?void 0:"must be an email"})).trim();if(!n)return;let o=ue(await Pi({message:"Bitbucket API token (BITBUCKET_API_TOKEN)"})).trim();if(!o){A.warn("the API token is required for Bitbucket \u2014 re-enter (or clear the email to skip).");continue}if(await ji("Bitbucket",async()=>{let s=await Wt(n,o,t);if(t&&r){let i=await fs(n,o,t,r);if(i)throw new Error(i)}return s}))return{email:n,apiToken:o};A.warn("re-enter the Atlassian email / API token (or clear the email to skip).")}}async function SC(){for(;;){let t=ue(await Pi({message:`GitLab PAT \u2014 blank to skip
935
- scopes: 'api' (or 'read_api' + 'write_repository') to create MRs and push.`})).trim();if(!t)return;if(await ji("GitLab",()=>qt(t))){let e=await Qd(t);return e&&A.warn(e),{token:t}}A.warn("re-enter the GitLab PAT (or leave blank to skip).")}}async function EC(){let t="__other__",e=async()=>ue(await we({message:"language name (in English, e.g. Ukrainian)",validate:i=>{let a=i.trim();if(a.length===0)return"required";if(a.length>40)return`\u2264 ${40} chars`}})).trim(),r=Ae(await yt({message:"project language",options:[...Vr.map(i=>({value:i,label:i==="English"?"English (default)":i})),{value:t,label:"other\u2026"}],initialValue:"English"})),n=r===t?await e():r;if(n==="English")return{primary:n,context:n,tasks:n,docs:n,code_comments:n,chat:ye};let o=[{key:"context",label:"context documents (knowledge, ADRs, task artifacts)",initial:n},{key:"tasks",label:"tracker issues the agent drafts",initial:n},{key:"docs",label:"documentation in the project repos",initial:n},{key:"code_comments",label:"code comments",initial:n},{key:"chat",label:"chat with the agent",initial:ye}],s={primary:n};for(let i of o){let a=new Set,c=[i.initial,n,"English",ye].filter(u=>a.has(u)?!1:(a.add(u),!0)).map(u=>({value:u,label:u===ye?"auto \u2014 mirror the language of the user's material":u}));c.push({value:t,label:"other\u2026"});let l=Ae(await yt({message:`language for ${i.label}`,options:c,initialValue:i.initial}));s[i.key]=l===t?await e():l}return s}async function nw(){for(;;){let t=ue(await we({message:"YouTrack URL (YOUTRACK_URL)",placeholder:"https://your.youtrack.cloud",validate:r=>{let n=r.trim();if(!n)return"required";if(!n.startsWith("http"))return"must start with http(s)://"}})).trim().replace(/\/$/,""),e=ue(await Pi({message:"YouTrack PAT (YOUTRACK_TOKEN)",validate:r=>r&&r.trim().length>0?void 0:"required"})).trim();if(await ji("YouTrack",()=>zt({baseUrl:t,token:e}))){let r=await fp({baseUrl:t,token:e});return{url:t,token:e,...r?{login:r}:{}}}A.warn("re-enter the YouTrack URL / token.")}}var Bk,Bo=S(()=>{"use strict";Le();F();ot();pk();hs();We();Lt();Pr();nn();$i();bl();vi();Yt();$r();xk();Te();Rk();Ck();ol();Ns();de();Si();bt();Bk=["# codepipe runtime \u2014 added by `codepipe init`","session.log","apply-queue.json"]});F();Le();We();import{Command as PA}from"commander";We();de();async function Wd(t){let e=t.profile??t.project;t.profile&&t.profile!==t.project&&(console.error(`--profile (${t.profile}) must equal --project (${t.project}). Profile id is the project id.`),process.exit(1));let r=dt(e);r&&!t.force&&(console.error(`already configured at ${Zr(e)} (hub=${r.hubUrl}).`),console.error("pass --force to overwrite."),process.exit(1));let n=t.hub.replace(/\/$/,"");jt({hubUrl:n,cliToken:t.token,projectId:t.project},e);let s={...q(t.project)??{},hubUrl:n,cliToken:t.token,projectId:t.project};se(s),console.log(`configured \u2192 hub=${n}, project=${t.project}, config=${Zr(e)}`)}Xa();We();import{homedir as vl}from"node:os";import{join as Po}from"node:path";Le();F();import{existsSync as Yh,rmSync as kE}from"node:fs";import{join as jr}from"node:path";import{simpleGit as wE}from"simple-git";import"ws";Le();de();import{createHash as f$}from"node:crypto";import{existsSync as m$,readFileSync as h$}from"node:fs";import{homedir as g$,hostname as Ja}from"node:os";import{join as y$}from"node:path";function zd(t){return f$("sha256").update(t).digest("hex").slice(0,12)}function k$(){let t=X("ACCOUNT_EMAIL")?.trim();if(t)return t.toLowerCase();try{let e=y$(g$(),".claude","credentials.json");if(!m$(e))return;let r=JSON.parse(h$(e,"utf-8")),n=[r.email,r.account?.email,r.user?.email];for(let o of n)if(typeof o=="string"&&o.includes("@"))return o.trim().toLowerCase()}catch{}}function Xd(t){let e=k$(),r=X("ACCOUNT_ID")?.trim(),n=X("ACCOUNT_LABEL")?.trim();if(r)return{accountId:r,label:n||r,...e?{email:e}:{}};let o=Qr(t);return o?{accountId:`acct-${zd(o)}`,label:n||Ja(),...e?{email:e}:{}}:{accountId:`acct-${zd(`host:${Ja()}`)}`,label:n||Ja(),...e?{email:e}:{}}}Le();nn();de();dc();async function Op(t,e,r,n,o){let s=c=>{e.readyState===e.OPEN&&e.send(JSON.stringify(c))},i=c=>s({type:"agent_login_url",requestId:r.requestId,projectId:t.projectId,error:c});if(X("ORIGIN")==="farm"||X("CLAUDE_AUTOLOGIN")==="0"){i("autologin_disabled");return}let a;try{a=await uc(ms())}catch(c){i(`listener failed: ${c instanceof Error?c.message:String(c)}`);return}s({type:"agent_login_url",requestId:r.requestId,projectId:t.projectId,authUrl:a.authUrl}),n.info(`[agent-auth] authorize Claude in a browser on THIS machine: ${a.authUrl}`),n.info(`[agent-auth] waiting for the redirect on ${a.redirectUri} \u2026`);try{let c=await a.waitForToken(),l=await Nt(c.oauthToken);if(l==="invalid"){s({type:"agent_login_result",projectId:t.projectId,ok:!1,detail:"token rejected (401) \u2014 previous token kept"}),n.warn("[agent-auth] new Claude token rejected (401) \u2014 previous token kept");return}let u=q(t.projectId);if(!u){s({type:"agent_login_result",projectId:t.projectId,ok:!1,detail:"no secrets file for this project on the CLI"}),n.warn("[agent-auth] no secrets file for this project \u2014 token not saved");return}u.claude={oauthToken:c.oauthToken},se(u),n.info(`[agent-auth] Claude token replaced (${c.oauthToken.slice(0,12)}\u2026, ${c.oauthToken.length} chars)`),s({type:"agent_login_result",projectId:t.projectId,ok:!0,...l==="inconclusive"?{detail:"saved (live check inconclusive)"}:{}}),o()}catch(c){let l=c instanceof Error?c.message:String(c);s({type:"agent_login_result",projectId:t.projectId,ok:!1,detail:l}),n.warn(`[agent-auth] browser authorization failed: ${l}`)}finally{a.close()}}Le();function Lp(t,e){let r=t.find(n=>n.kind==="claude");return r?.present===!0&&r.ok===!1?X("ORIGIN")==="farm"||X("CLAUDE_AUTOLOGIN")==="0"||e?"none":"open":r?.ok===!0?"rearm":"none"}function Dp(t,e){return`${t.replace(/\/$/,"")}/?project=${encodeURIComponent(e)}`}hs();Te();Rr();import{existsSync as xs,readFileSync as Z$,writeFileSync as Q$}from"node:fs";import{join as Tr}from"node:path";import{simpleGit as vs}from"simple-git";var lf=["-c","user.name=CodePipe","-c","user.email=codepipe@codepartner.ee"],ev="apply-queue.json";function uf(t){return Tr(t,ev)}function Cr(t){let e=uf(t);if(!xs(e))return{};try{return JSON.parse(Z$(e,"utf-8"))}catch{return{}}}function gc(t,e){Q$(uf(t),JSON.stringify(e,null,2)+`
935
+ scopes: 'api' (or 'read_api' + 'write_repository') to create MRs and push.`})).trim();if(!t)return;if(await ji("GitLab",()=>qt(t))){let e=await Qd(t);return e&&A.warn(e),{token:t}}A.warn("re-enter the GitLab PAT (or leave blank to skip).")}}async function EC(){let t="__other__",e=async()=>ue(await we({message:"language name (in English, e.g. Ukrainian)",validate:i=>{let a=i.trim();if(a.length===0)return"required";if(a.length>40)return`\u2264 ${40} chars`}})).trim(),r=Ae(await yt({message:"project language",options:[...Vr.map(i=>({value:i,label:i==="English"?"English (default)":i})),{value:t,label:"other\u2026"}],initialValue:"English"})),n=r===t?await e():r;if(n==="English")return{primary:n,context:n,tasks:n,docs:n,code_comments:n,chat:ye};let o=[{key:"context",label:"context documents (knowledge, ADRs, task artifacts)",initial:n},{key:"tasks",label:"tracker issues the agent drafts",initial:n},{key:"docs",label:"documentation in the project repos",initial:n},{key:"code_comments",label:"code comments",initial:n},{key:"chat",label:"chat with the agent",initial:ye}],s={primary:n};for(let i of o){let a=new Set,c=[i.initial,n,"English",ye].filter(u=>a.has(u)?!1:(a.add(u),!0)).map(u=>({value:u,label:u===ye?"auto \u2014 mirror the language of the user's material":u}));c.push({value:t,label:"other\u2026"});let l=Ae(await yt({message:`language for ${i.label}`,options:c,initialValue:i.initial}));s[i.key]=l===t?await e():l}return s}async function nw(){for(;;){let t=ue(await we({message:"YouTrack URL (YOUTRACK_URL)",placeholder:"https://your.youtrack.cloud",validate:r=>{let n=r.trim();if(!n)return"required";if(!n.startsWith("http"))return"must start with http(s)://"}})).trim().replace(/\/$/,""),e=ue(await Pi({message:"YouTrack PAT (YOUTRACK_TOKEN)",validate:r=>r&&r.trim().length>0?void 0:"required"})).trim();if(await ji("YouTrack",()=>zt({baseUrl:t,token:e}))){let r=await fp({baseUrl:t,token:e});return{url:t,token:e,...r?{login:r}:{}}}A.warn("re-enter the YouTrack URL / token.")}}var Bk,Bo=S(()=>{"use strict";Le();F();ot();pk();hs();We();Lt();Pr();nn();$i();bl();vi();Yt();$r();xk();Te();Rk();Ck();ol();Ns();de();Si();bt();Bk=["# codepipe runtime \u2014 added by `codepipe init`","session.log","apply-queue.json"]});F();Le();We();import{Command as PA}from"commander";We();de();async function Wd(t){let e=t.profile??t.project;t.profile&&t.profile!==t.project&&(console.error(`--profile (${t.profile}) must equal --project (${t.project}). Profile id is the project id.`),process.exit(1));let r=dt(e);r&&!t.force&&(console.error(`already configured at ${Zr(e)} (hub=${r.hubUrl}).`),console.error("pass --force to overwrite."),process.exit(1));let n=t.hub.replace(/\/$/,"");jt({hubUrl:n,cliToken:t.token,projectId:t.project},e);let s={...q(t.project)??{},hubUrl:n,cliToken:t.token,projectId:t.project};se(s),console.log(`configured \u2192 hub=${n}, project=${t.project}, config=${Zr(e)}`)}Xa();We();import{homedir as vl}from"node:os";import{join as Po}from"node:path";Le();F();import{existsSync as Yh,rmSync as kE}from"node:fs";import{join as jr}from"node:path";import{simpleGit as wE}from"simple-git";import"ws";Le();de();import{createHash as f$}from"node:crypto";import{existsSync as m$,readFileSync as h$}from"node:fs";import{homedir as g$,hostname as Ja}from"node:os";import{join as y$}from"node:path";function zd(t){return f$("sha256").update(t).digest("hex").slice(0,12)}function k$(){let t=X("ACCOUNT_EMAIL")?.trim();if(t)return t.toLowerCase();try{let e=y$(g$(),".claude","credentials.json");if(!m$(e))return;let r=JSON.parse(h$(e,"utf-8")),n=[r.email,r.account?.email,r.user?.email];for(let o of n)if(typeof o=="string"&&o.includes("@"))return o.trim().toLowerCase()}catch{}}function Xd(t){let e=k$(),r=X("ACCOUNT_ID")?.trim(),n=X("ACCOUNT_LABEL")?.trim();if(r)return{accountId:r,label:n||r,...e?{email:e}:{}};let o=Qr(t);return o?{accountId:`acct-${zd(o)}`,label:n||Ja(),...e?{email:e}:{}}:{accountId:`acct-${zd(`host:${Ja()}`)}`,label:n||Ja(),...e?{email:e}:{}}}Le();nn();de();dc();async function Op(t,e,r,n,o){let s=c=>{e.readyState===e.OPEN&&e.send(JSON.stringify(c))},i=c=>s({type:"agent_login_url",requestId:r.requestId,projectId:t.projectId,error:c});if(X("ORIGIN")==="farm"||X("CLAUDE_AUTOLOGIN")!=="1"){i("autologin_disabled");return}let a;try{a=await uc(ms())}catch(c){i(`listener failed: ${c instanceof Error?c.message:String(c)}`);return}s({type:"agent_login_url",requestId:r.requestId,projectId:t.projectId,authUrl:a.authUrl}),n.info(`[agent-auth] authorize Claude in a browser on THIS machine: ${a.authUrl}`),n.info(`[agent-auth] waiting for the redirect on ${a.redirectUri} \u2026`);try{let c=await a.waitForToken(),l=await Nt(c.oauthToken);if(l==="invalid"){s({type:"agent_login_result",projectId:t.projectId,ok:!1,detail:"token rejected (401) \u2014 previous token kept"}),n.warn("[agent-auth] new Claude token rejected (401) \u2014 previous token kept");return}let u=q(t.projectId);if(!u){s({type:"agent_login_result",projectId:t.projectId,ok:!1,detail:"no secrets file for this project on the CLI"}),n.warn("[agent-auth] no secrets file for this project \u2014 token not saved");return}u.claude={oauthToken:c.oauthToken},se(u),n.info(`[agent-auth] Claude token replaced (${c.oauthToken.slice(0,12)}\u2026, ${c.oauthToken.length} chars)`),s({type:"agent_login_result",projectId:t.projectId,ok:!0,...l==="inconclusive"?{detail:"saved (live check inconclusive)"}:{}}),o()}catch(c){let l=c instanceof Error?c.message:String(c);s({type:"agent_login_result",projectId:t.projectId,ok:!1,detail:l}),n.warn(`[agent-auth] browser authorization failed: ${l}`)}finally{a.close()}}Le();function Lp(t,e){let r=t.find(n=>n.kind==="claude");return r?.present===!0&&r.ok===!1?X("ORIGIN")==="farm"||X("CLAUDE_AUTOLOGIN")!=="1"||e?"none":"open":r?.ok===!0?"rearm":"none"}function Dp(t,e){return`${t.replace(/\/$/,"")}/?project=${encodeURIComponent(e)}`}hs();Te();Rr();import{existsSync as xs,readFileSync as Z$,writeFileSync as Q$}from"node:fs";import{join as Tr}from"node:path";import{simpleGit as vs}from"simple-git";var lf=["-c","user.name=CodePipe","-c","user.email=codepipe@codepartner.ee"],ev="apply-queue.json";function uf(t){return Tr(t,ev)}function Cr(t){let e=uf(t);if(!xs(e))return{};try{return JSON.parse(Z$(e,"utf-8"))}catch{return{}}}function gc(t,e){Q$(uf(t),JSON.stringify(e,null,2)+`
936
936
  `)}async function df(t,e,r,n,o){let s;try{s=await fc(e.hubUrl,e.cliToken,t.spec.projectId,r)}catch(d){return{ok:!1,message:`claim failed: ${d instanceof Error?d.message:String(d)}`}}let i=[];for(let d of s.repos){let m=t.spec.repos.find(w=>w.name===d.repoName);if(!m)return{ok:!1,message:`repo "${d.repoName}" not in project.yaml \u2014 run /sync`};let f=Tr(t.root,m.mountAs);if(!xs(Tr(f,".git")))return{ok:!1,message:`${m.mountAs}/ not cloned \u2014 run /sync first`};if(!(await vs(f).status()).isClean())return{ok:!1,message:`${m.mountAs}/ has uncommitted changes \u2014 commit or stash first`};i.push({claimRepo:d,spec:m,dir:f})}let a=[];for(let d of i){let m=vs(d.dir),f=await tv(m),g=d.claimRepo;try{await m.fetch()}catch(y){return await hc(a,o),{ok:!1,message:`fetch failed in ${d.spec.mountAs}: ${Ir(y)}`}}let h=`origin/${g.baseRef}`,w;try{w=await Er(m,{contextRepoCloneUrl:g.contextRepoCloneUrl,deliveryRef:g.deliveryRef,deliverySha:g.deliverySha,baseSha:g.baseSha,commitMessage:g.commitMessage})}catch(y){return await hc(a,o),{ok:!1,message:`fetch delivery failed in ${d.spec.mountAs}: ${Ir(y)}`}}a.push({git:m,dir:d.dir,mountAs:d.spec.mountAs,originalRef:f,branch:g.branchName,baseSha:h,deliveryCommit:w,startPoint:h})}let c=[];for(let d of a)try{if(n==="apply"){await d.git.checkout(["-B",d.branch,d.startPoint]),await d.git.raw([...lf,"cherry-pick",d.deliveryCommit]);let m=(await d.git.revparse(["HEAD"])).trim();c.push({mountAs:d.mountAs,branch:d.branch,baseSha:d.baseSha,appliedSha:m})}else await d.git.checkout(["--detach",d.startPoint]),await d.git.raw([...lf,"cherry-pick","--no-commit",d.deliveryCommit]),await d.git.raw(["cherry-pick","--quit"]).catch(()=>{}),c.push({mountAs:d.mountAs,branch:d.branch,baseSha:d.baseSha})}catch(m){return await d.git.raw(["cherry-pick","--abort"]).catch(()=>{}),await hc(a,o),{ok:!1,message:`apply failed in ${d.mountAs}: ${Ir(m)} (rolled back all repos)`}}let l=Cr(t.contextDir);l[r]={mode:n,claimedAt:new Date().toISOString(),repos:c},gc(t.contextDir,l);let u=c.map(d=>d.mountAs).join(", "),p=n==="apply"?`review, push branch '${s.repos[0]?.branchName}', then: /applied ${r} --pr <url>`:`review with 'git diff', commit & push yourself, then: /applied ${r} --pr <url>`;return{ok:!0,message:`${n==="apply"?"applied":"unstashed"} ${r} in ${u}
937
937
  ${p}
938
938
  or: /abort ${r} --reason "..."`}}async function pf(t,e,r){let n=[];for(let c of e.repos){let l=t.repos.find(p=>p.name===c.repoName);if(!l)return{ok:!1,message:`repo "${c.repoName}" not in project.yaml \u2014 run /sync`};let u=Tr(t.root,l.mountAs);if(!xs(Tr(u,".git")))return{ok:!1,message:`${l.mountAs}/ not cloned \u2014 run /sync first`};n.push({git:vs(u),dir:u,spec:l,cr:c})}let o=[],s=[];for(let c of n)try{let{commit:l}=await nf(c.git,c.dir,{contextRepoCloneUrl:c.cr.contextRepoCloneUrl,deliveryRef:c.cr.deliveryRef,deliverySha:c.cr.deliverySha,baseSha:c.cr.baseSha,baseRef:c.cr.baseRef,branchName:c.cr.branchName,commitMessage:c.cr.commitMessage,defaultBranch:c.spec.defaultBranch});r.info(`[apply] ${e.taskKey}: ${c.cr.branchName} \u2192 ${c.spec.mountAs} (${l.slice(0,10)})`),o.push({git:c.git,branch:c.cr.branchName}),s.push({mountAs:c.spec.mountAs,branch:c.cr.branchName,baseSha:`origin/${c.cr.baseRef}`,appliedSha:l})}catch(l){for(let u of o)await u.git.raw(["branch","-D",u.branch]).catch(()=>{});return{ok:!1,message:`auto-apply failed in ${c.spec.mountAs}: ${Ir(l)}`}}try{await fc(t.hubUrl,t.cliToken,t.projectId,e.taskKey)}catch(c){return{ok:!1,message:`branch created but claim failed: ${Ir(c)} \u2014 retried on the next reconnect`,branches:o.map(l=>l.branch)}}let i=Cr(t.contextDir);i[e.taskKey]={mode:"apply",claimedAt:new Date().toISOString(),repos:s},gc(t.contextDir,i);let a=s.map(c=>`${c.branch} (${c.mountAs})`).join(", ");return{ok:!0,branches:s.map(c=>c.branch),message:`branch created locally without touching your checkout: ${a}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-partner/codepipe",
3
- "version": "0.11.1-dev.228.g62386c4",
3
+ "version": "0.11.1-dev.229.g86cd22a",
4
4
  "description": "CodePipe turns tasks into reviewed pull requests: an AI agent analyzes, implements, and opens a PR under your control.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -29,8 +29,8 @@
29
29
  "@types/ws": "^8.5.13",
30
30
  "esbuild": "^0.21.5",
31
31
  "vitest": "2.1.9",
32
- "@codepipe/sandbox": "0.1.0",
33
- "@codepipe/shared": "0.0.0"
32
+ "@codepipe/shared": "0.0.0",
33
+ "@codepipe/sandbox": "0.1.0"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsc -p tsconfig.json && chmod +x dist/index.js",