@code-partner/codepipe 0.3.7-dev.115.g1aafcb3 → 0.3.8
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 +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var he="0.3.
|
|
2
|
+
var he="0.3.8",je="https://hub.codepipe.dev";var Ee=4,Qu=4;function Hr(t){return typeof t!="number"||!Number.isFinite(t)?!1:t>=Qu&&t<=Ee}var Pe=".codepipe-context.yaml",mr=".devpipe-context.yaml",bi=[{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",Pe]},{version:2,summary:"Rename the format-version stamp .devpipe-context.yaml \u2192 .codepipe-context.yaml (drop the devpipe-brand leftover)",addedPaths:[Pe]},{version:3,summary:"Custom project actions (the RUN tab): actions/ scaffold with the format README",addedPaths:["actions/README.md"]}];function Kr(t=3){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 ki(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 $i(t,e=bi){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=bi){return e.filter(r=>r.version>t)}var Zu=[{id:"intake",label:"\u041F\u0440\u0438\u0451\u043C\u043A\u0430",phases:["INTAKE"]},{id:"analysis",label:"\u0410\u043D\u0430\u043B\u0438\u0437",phases:["ANALYZING","ESTIMATING"]},{id:"ready",label:"\u0413\u043E\u0442\u043E\u0432\u0430 \u043A \u0440\u0430\u0431\u043E\u0442\u0435",phases:["READY"]},{id:"implementation",label:"\u0420\u0435\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u044F",phases:["IMPLEMENTING","BUILD"]},{id:"delivery",label:"\u0414\u043E\u0441\u0442\u0430\u0432\u043A\u0430",phases:["READY_TO_APPLY","APPLYING"]}],Zy=Zu.flatMap(t=>t.phases);var xi=["estimate","analyze","implement","resolve-conflict","rework","draft","build","index","backfill","analysis","chat"];function gt(){return{inputTokens:0,outputTokens:0,cacheReadInputTokens:0,cacheCreationInputTokens:0,totalCostUsd:0,model:"",numTurns:0,durationMs:0}}var Ge="opus",Wr="sonnet",ep="haiku",Zn=[Ge,Wr,ep],Si={analyze:Ge,implement:Ge,"resolve-conflict":Ge,rework:Ge,estimate:Wr,build:Wr,draft:Wr,index:Ge,backfill:Ge,analysis:Ge,chat:Ge};var ye=/^[A-Z][A-Z0-9_]*$/,tp=new Set(["GH_TOKEN","GITHUB_TOKEN","GITLAB_TOKEN"]),rp=["BITBUCKET_","YOUTRACK_","CLAUDE_","INPUT_"];function ze(t){return tp.has(t)?!0:rp.some(e=>t.startsWith(e))}var Ii=600,Ri=/^[a-z0-9-]+$/,Ti=32,Ci=64;function qr(t,e){if(!t||typeof t!="object"||Array.isArray(t))throw new Error(`${e} must be a mapping`);return t}function ht(t,e){if(t!=null){if(typeof t!="string")throw new Error(`${e} must be a string`);return t}}function eo(t,e){if(t!=null){if(typeof t!="number"||!Number.isFinite(t))throw new Error(`${e} must be a number`);return t}}function ji(t,e){let r=qr(e,"action definition"),n=t.replace(/\.(yml|yaml)$/i,""),o=ht(r.id,"id")??n;if(!Ri.test(o))throw new Error(`id must match ${Ri} (got "${o}")`);if(o!==n)throw new Error(`id "${o}" must match the file name ("${n}")`);let i=ht(r.title,"title")?.trim()||o,s;if(r.env!==void 0&&r.env!==null){let d=qr(r.env,"env");s={};for(let[u,m]of Object.entries(d)){if(!ye.test(u))throw new Error(`env name "${u}" must match ${ye}`);if(typeof m!="string"&&typeof m!="number"&&typeof m!="boolean")throw new Error(`env.${u} must be a scalar`);s[u]=String(m)}}let a,c=r.params;if(c!=null){if(!Array.isArray(c))throw new Error("params must be a list");if(c.length>Ti)throw new Error(`too many params (max ${Ti})`);let d=new Set;a=c.map((u,m)=>np(u,m,d))}let l=r.steps;if(!Array.isArray(l)||l.length===0)throw new Error("steps must be a non-empty list");if(l.length>Ci)throw new Error(`too many steps (max ${Ci})`);let p=l.map((d,u)=>{let m=qr(d,`steps[${u}]`),f=ht(m.run,`steps[${u}].run`);if(!f||f.trim().length===0)throw new Error(`steps[${u}].run is required`);let y=ht(m.name,`steps[${u}].name`),w=eo(m.timeout_sec,`steps[${u}].timeout_sec`);if(w!==void 0&&(!Number.isInteger(w)||w<=0))throw new Error(`steps[${u}].timeout_sec must be a positive integer`);return{run:f,...y?{name:y}:{},...w!==void 0?{timeout_sec:w}:{}}});return{id:o,title:i,...s?{env:s}:{},...a?{params:a}:{},steps:p}}function np(t,e,r){let n=qr(t,`params[${e}]`),o=ht(n.name,`params[${e}].name`);if(!o||!ye.test(o))throw new Error(`params[${e}].name must match ${ye}`);if(r.has(o))throw new Error(`duplicate param "${o}"`);r.add(o);let i=n.type;if(i!=="string"&&i!=="enum"&&i!=="number"&&i!=="boolean")throw new Error(`params[${e}].type must be string | enum | number | boolean`);let s;if(i==="enum"){let m=n.enum;if(!Array.isArray(m)||m.length===0||!m.every(f=>typeof f=="string"))throw new Error(`params[${e}].enum must be a non-empty string list`);s=m}let a=ht(n.label,`params[${e}].label`),c=ht(n.help,`params[${e}].help`),l=n.required===!0,p=eo(n.min,`params[${e}].min`),d=eo(n.max,`params[${e}].max`),u=n.default;if(u!=null&&typeof u!="string"&&typeof u!="number"&&typeof u!="boolean")throw new Error(`params[${e}].default must be a scalar`);return{name:o,type:i,...a?{label:a}:{},...c?{help:c}:{},...l?{required:!0}:{},...s?{enum:s}:{},...p!==void 0?{min:p}:{},...d!==void 0?{max:d}:{},...u!=null?{default:u}:{}}}function Ei(t,e){let r=t.params??[],n=new Map(r.map(i=>[i.name,i]));for(let i of Object.keys(e))if(!n.has(i))return{ok:!1,error:`unknown param: ${i}`};let o={};for(let i of r){let s=e[i.name];if(s==null||typeof s=="string"&&s.trim()==="")if(i.default!==void 0)s=i.default;else{if(i.required)return{ok:!1,error:`${i.name} is required`};continue}switch(i.type){case"string":{if(typeof s!="string")return{ok:!1,error:`${i.name} must be a string`};o[i.name]=s;break}case"enum":{if(typeof s!="string"||!(i.enum??[]).includes(s))return{ok:!1,error:`${i.name} must be one of: ${(i.enum??[]).join(", ")}`};o[i.name]=s;break}case"number":{let a=typeof s=="number"?s:typeof s=="string"?Number(s):NaN;if(!Number.isFinite(a))return{ok:!1,error:`${i.name} must be a number`};if(i.min!==void 0&&a<i.min)return{ok:!1,error:`${i.name} must be \u2265 ${i.min}`};if(i.max!==void 0&&a>i.max)return{ok:!1,error:`${i.name} must be \u2264 ${i.max}`};o[i.name]=a;break}case"boolean":{let a=typeof s=="boolean"?s:s==="true"?!0:s==="false"?!1:null;if(a===null)return{ok:!1,error:`${i.name} must be a boolean`};o[i.name]=a;break}}}return{ok:!0,values:o}}var Pi=64,Ai=2e3,op=[{id:"branch",label:"Branch",help:"Task-branch naming.",fields:[{id:"branch.pattern",file:"project.yaml",path:["branch","pattern"],type:"string",label:"Task-branch pattern",nullable:!0,mustContain:"<TASK_ID>",help:"Template for the per-task branch name. Must contain the <TASK_ID> placeholder. Empty \u21D2 default codepipe/<TASK_ID>."}]},{id:"llm",label:"LLM",fields:[],groups:[{id:"llm.models",label:"Models by role",help:"Model per pipeline stage. Empty \u21D2 the role's recommended default applies.",fields:[{id:"llm.models.default",file:"regimen.yaml",path:["llm","models","default"],type:"model",label:"default (catch-all)",nullable:!0,suggestions:[...Zn],help:"Overrides the recommended defaults for every role not listed below."},...xi.map(t=>({id:`llm.models.${t}`,file:"regimen.yaml",path:["llm","models",t],type:"model",label:t,nullable:!0,suggestions:[...Zn],help:`recommended: ${Si[t]}`}))]}]},{id:"variables",label:"Variables",help:"Non-secret env vars for custom actions (RUN tab). Secrets go via the sealed Secrets form on the Tokens section instead.",fields:[{id:"variables",file:"project.yaml",path:["variables"],type:"string_map",label:"Variables",nullable:!0,help:"NAME=value pairs, one per line. Names are env-style (A-Z, 0-9, _); reserved credential names are refused."}]},{id:"gates",label:"Gates",help:"Approval gate before the pipeline starts (orthogonal to automation).",fields:[{id:"gates.require_approval",file:"regimen.yaml",path:["gates","require_approval"],type:"boolean",label:"Require approval before start",nullable:!1,help:"When on, a task taken from Develop waits in AWAITING_APPROVAL for a manual Approve before analysis starts. Off \u21D2 intake auto-starts the pipeline."}]},{id:"automation",label:"Automation",help:"How far the pipeline advances the G1\u2013G4 gates without a manual Run/Approve. Independent of the approval gate above.",fields:[{id:"automation.level",file:"regimen.yaml",path:["automation","level"],type:"enum",label:"Automation level",nullable:!1,suggestions:["assisted","full"],help:"assisted \u21D2 manual Run/Approve at each of G1\u2013G4; full \u21D2 gates auto-pass."}]}];function _i(t=op){let e=[];for(let r of t)e.push(...r.fields),r.groups&&e.push(..._i(r.groups));return e}function ip(t,e){let r=JSON.stringify(e);return _i().find(n=>n.file===t&&JSON.stringify(n.path)===r)}function Ni(t){let e=ip(t.file,t.path);if(!e)return{ok:!1,error:`unknown setting path: ${t.file}:${t.path.join(".")}`};let r=t.value,n=e.type==="model"||e.type==="enum"||e.type==="string";if(r===null||n&&typeof r=="string"&&r.trim().length===0)return e.nullable?{ok:!0,field:e,value:null}:{ok:!1,error:`${e.id} cannot be cleared`};switch(e.type){case"model":case"string":{if(typeof r!="string")return{ok:!1,error:`${e.id} must be a string`};let i=r.trim();return e.type==="string"&&e.mustContain&&!i.includes(e.mustContain)?{ok:!1,error:`${e.id} must contain "${e.mustContain}"`}:{ok:!0,field:e,value:i}}case"enum":{if(typeof r!="string")return{ok:!1,error:`${e.id} must be a string`};let i=r.trim();return e.suggestions?.includes(i)?{ok:!0,field:e,value:i}:{ok:!1,error:`${e.id} must be one of: ${(e.suggestions??[]).join(", ")}`}}case"number":return typeof r!="number"||!Number.isFinite(r)||!Number.isInteger(r)?{ok:!1,error:`${e.id} must be an integer`}:e.min!==void 0&&r<e.min?{ok:!1,error:`${e.id} must be \u2265 ${e.min}`}:e.max!==void 0&&r>e.max?{ok:!1,error:`${e.id} must be \u2264 ${e.max}`}:{ok:!0,field:e,value:r};case"boolean":return typeof r!="boolean"?{ok:!1,error:`${e.id} must be a boolean`}:{ok:!0,field:e,value:r};case"string_list":{if(!Array.isArray(r))return{ok:!1,error:`${e.id} must be a list`};let i=r.map(s=>typeof s=="string"?s.trim():"").filter(s=>s.length>0);return i.length===0?e.nullable?{ok:!0,field:e,value:null}:{ok:!1,error:`${e.id} must be a non-empty list`}:{ok:!0,field:e,value:i}}case"string_map":{if(typeof r!="object"||r===null||Array.isArray(r))return{ok:!1,error:`${e.id} must be a name\u2192value map`};let i=Object.entries(r);if(i.length===0)return e.nullable?{ok:!0,field:e,value:null}:{ok:!1,error:`${e.id} must be a non-empty map`};if(i.length>Pi)return{ok:!1,error:`${e.id} must have \u2264 ${Pi} entries`};let s={};for(let[a,c]of i){if(!ye.test(a))return{ok:!1,error:`${e.id}: name "${a}" must match ${ye}`};if(ze(a))return{ok:!1,error:`${e.id}: name "${a}" is reserved`};if(typeof c!="string")return{ok:!1,error:`${e.id}: value of "${a}" must be a string`};if(c.length>Ai)return{ok:!1,error:`${e.id}: value of "${a}" must be \u2264 ${Ai} chars`};s[a]=c}return{ok:!0,field:e,value:s}}}}function Oi(t){return!(!t||t.length>250||!/^[A-Za-z0-9._/-]+$/.test(t)||/^[-/.]/.test(t)||/[/.]$/.test(t)||t.endsWith(".lock")||t.includes("..")||t.includes("//")||t.includes("/."))}var yt=/^[a-z][a-z0-9-]{1,30}$/,sp="-codepipe-ctx";function Fe(t){return`${t}${sp}`}var ap=[{name:"rework",pattern:/^@(?:codepipe|devpipe)\s+rework:\s*(.+)$/im,description:"Send the task back to ANALYZING with a new instruction.",hasArg:!0},{name:"approve",pattern:/^@(?:codepipe|devpipe)\s+approve\s*$/im,description:"Merge every PR for this task (TRACKING only)."},{name:"reject",pattern:/^@(?:codepipe|devpipe)\s+reject(?::\s*(.+))?\s*$/im,description:"Abandon this task: close any open PR(s) and move it to DONE (reason rejected_and_closed). Valid from any non-terminal phase; from early phases it just skips the task.",hasArg:!0},{name:"merge",pattern:/^@(?:codepipe|devpipe)\s+merge\s*$/im,description:"Merge the task branch into the default branch without a PR (direct apply path, apply.pull_request=false; TRACKING only)."},{name:"rebase",pattern:/^@(?:codepipe|devpipe)\s+rebase\s*$/im,description:"Re-apply the patch on top of the latest base branch and force-push. Use after a PR merge conflict or APPLYING failure."},{name:"update",pattern:/^@(?:codepipe|devpipe)\s+update(?::\s*(.+))?\s*$/im,description:"Update a conflicting PR: resolve conflicts against the current base branch (TRACKING only). Optional `: <instruction>` is forwarded to the agent.",hasArg:!0},{name:"apply",pattern:/^@(?:codepipe|devpipe)\s+apply:\s*(local|auto)\s*$/im,description:"Override apply mode for this task: local (you apply by hand) or auto.",hasArg:!0}];function Yr(t){for(let e of ap){let r=t.match(e.pattern);if(r)return{name:e.name,args:(r[1]??"").trim()}}return null}var gr={github:"github.com",gitlab:"gitlab.com",bitbucket:"bitbucket.org"};function jt(t){let e=t.match(/^git@([^:/]+):/);if(e)return e[1]??null;let r=t.match(/^ssh:\/\/(?:[^@/]+@)?([^/:]+)/);if(r)return r[1]??null;let n=t.match(/^https?:\/\/(?:[^@/]+@)?([^/:]+)/);return n?n[1]??null:null}var wt="x-bitbucket-api-token-auth";function Vr(t){switch(t){case gr.gitlab:return"oauth2";case gr.bitbucket:return"x-token-auth";default:return"x-access-token"}}var Ui=20;function F(t){return process.env[`CODEPIPE_${t}`]??process.env[`DEVPIPE_${t}`]}import{Command as Ky}from"commander";import{homedir as Gi}from"node:os";import{mkdirSync as yp,readFileSync as wp,writeFileSync as bp,existsSync as ro}from"node:fs";import{dirname as Hi,join as Xr,resolve as kp}from"node:path";import{fileURLToPath as $p}from"node:url";import{existsSync as Jr,readFileSync as Li,readdirSync as lp,writeFileSync as up}from"node:fs";import{dirname as pp,join as Xe}from"node:path";import{parse as dp}from"yaml";import{existsSync as Di,renameSync as cp}from"node:fs";function bt(t,e,r=n=>console.error(n)){if(Di(e)||!Di(t))return!1;try{return cp(t,e),r(`migrated ${t} \u2192 ${e} (DevPipe \u2192 CodePipe)`),!0}catch(n){return r(`failed to migrate ${t} \u2192 ${e}: ${n instanceof Error?n.message:String(n)} \u2014 continuing with the legacy path untouched`),!1}}var Ae=".codepipe",to=".devpipe";function fp(t=process.cwd()){let e=t;for(;;){if(Jr(Xe(e,Ae,"project.yaml")))return e;if(Jr(Xe(e,to,"project.yaml")))return bt(Xe(e,to),Xe(e,Ae))&&gp(e),e;let r=pp(e);if(r===e)return null;e=r}}function mp(t){let e=Xe(t,Ae);return Jr(e)?e:Xe(t,to)}function gp(t){let e=Xe(t,".gitignore");if(!Jr(e))return;let r=Li(e,"utf-8"),n=r.split(/\r?\n/).map(o=>{let i=o.trim();return i===".devpipe"||i===".devpipe/"||i==="/.devpipe"||i==="/.devpipe/"?o.replace(".devpipe",".codepipe"):o}).join(`
|