@tryarcanist/cli 0.1.416 → 0.1.417

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 +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createRequire as __arcanistCreateRequire } from "node:module";
3
3
  const require = __arcanistCreateRequire(import.meta.url);
4
4
  var Xy=Object.defineProperty;var Ge=(e,t)=>{for(var r in t)Xy(e,r,{get:t[r],enumerable:!0})};import{Command as SA,Option as xA}from"commander";var Bp=["idle","running","review_starting","waiting_for_input","finalizing","review_listening","completed","superseded","needs_you","blocked","failed","stopped","archived"];var jt=["completed","superseded","needs_you","blocked","failed","stopped","archived"],Qy=new Set(jt),RA=new Set(jt.filter(e=>e!=="completed")),PA=new Set(jt.filter(e=>e!=="stopped")),CA=jt.filter(e=>e!=="archived"&&e!=="needs_you"&&e!=="blocked"&&e!=="stopped");function Vp(e,t){return Qy.has(e)}function Gp(e){let t=e.createHelp().visibleGlobalOptions(e).map(Wp);return{...qp(e),...t.length>0?{globalOptions:t}:{}}}function qp(e){let t=eb(e);return{path:Aa(e),description:e.description(),aliases:e.aliases(),arguments:e.registeredArguments.map(r=>({name:r.name(),description:r.description,required:r.required,variadic:r.variadic})),options:e.createHelp().visibleOptions(e).map(Wp),...t?{notes:t}:{},subcommands:e.commands.map(qp)}}function Wp(e){return{flags:e.flags,description:e.description,required:e.mandatory,...e.defaultValue===void 0?{}:{defaultValue:e.defaultValue}}}function Aa(e){let t=[];for(let r=e;r;r=r.parent)t.unshift(r.name());return t.join(" ")}function eb(e){let t="";return e.emit("afterHelp",{error:!1,command:e,write:r=>t+=r}),t.trim()}import{existsSync as Cb,mkdirSync as Ob,writeFileSync as Nb}from"node:fs";import{basename as Db,join as lm,resolve as Ub}from"node:path";var tb="en-US";function Hp(e,t){let r=new Intl.DateTimeFormat(tb,{timeZone:t,month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit",hour12:!0,timeZoneName:"short"}).formatToParts(e),o=n=>r.find(i=>i.type===n)?.value??"";return`${o("month")} ${o("day")}, ${o("year")}, ${o("hour")}:${o("minute")} ${o("dayPeriod")} ${o("timeZoneName")}`}function xe(e,t=""){return(e instanceof Error?e.message:String(e))||t}function Kr(e){return new Promise(t=>setTimeout(t,e))}function et(e){return e.replace(/\/+$/,"")}var Kp="Setup and reviews are paused for this workspace. Contact team@tryarcanist.com to resume them.";function Jp(e){if(!e||typeof e!="object")return null;let t=e,r=typeof t.code=="string"&&t.code?t.code:null,o=typeof t.message=="string"&&t.message?t.message:null;if(typeof t.error=="string"&&t.error)return{code:r??t.error,message:o??t.error,raw:t.error};if(t.error&&typeof t.error=="object"){let n=t.error,i=typeof n.code=="string"&&n.code?n.code:r,a=typeof n.message=="string"&&n.message?n.message:o;return i||a?{code:i,message:a,raw:t.error}:null}return r||o?{code:r,message:o,raw:e}:null}function Ra(e){try{let t=JSON.parse(e);if(!t||typeof t!="object")return null;let r=t,o={...typeof r.repository=="string"?{repository:r.repository}:{},...typeof r.environmentsUrl=="string"?{environmentsUrl:r.environmentsUrl}:{},...typeof r.billingUrl=="string"?{billingUrl:r.billingUrl}:{}},n=Jp(t);return n?typeof n.raw=="string"&&n.raw?{...n.code?{serverCode:n.code}:{},rawError:n.raw,...n.message?{message:n.message}:{},...o}:n.message||n.code?{...n.message?{message:n.message}:{},...n.code?{serverCode:n.code,rawError:n.code}:{},...o}:null:null}catch{return null}}var Oe=130,Pa=5,y=class extends Error{code;exitCode;hint;requestId;data;constructor(t,r,o={}){super(r),this.name="CliError",this.code=t,this.exitCode=o.exitCode??Yp(t),this.hint=o.hint,this.requestId=o.requestId,this.data=o.data}},Mt=class extends y{},ue=class extends y{status;body;constructor(t,r,o,n){let i=Xp(t),a=Ra(r);super(i,rb(t,r,a),{exitCode:nb(t),hint:ib(t,n,a),requestId:o,data:a?.serverCode||a?.repository||a?.environmentsUrl||a?.billingUrl?{...a.serverCode?{serverCode:a.serverCode}:{},...a.repository?{repository:a.repository}:{},...a.environmentsUrl?{environmentsUrl:a.environmentsUrl}:{},...a.billingUrl?{billingUrl:a.billingUrl}:{}}:void 0}),this.name="ApiError",this.status=t,this.body=r}};function Yp(e){switch(e){case"auth":return 2;case"not_found":return 3;case"conflict":return 4;case"server":return 10;default:return 1}}function Xp(e){return e===401||e===403?"auth":e===404?"not_found":e===409?"conflict":e>=500?"server":"user"}function nb(e){return Yp(Xp(e))}function rb(e,t,r=Ra(t)){return r?.message?r.message:r?.serverCode?r.serverCode:t?`API error ${e}: ${t}`:`API error ${e}`}function ib(e,t,r){if(e===401)return"Run `arcanist auth login` or set `ARCANIST_TOKEN`.";if(!(e===403&&r?.message===Kp)){if(e===403)return"This token is not allowed to do that. `arcanist auth whoami --json` shows its tokenScope and your businessRole: a change needs a write-scope token (mint one in Settings > CLI), and a workspace-wide change also needs the admin role.";if(e===404)return t==="repo"?"Check accessible repositories with `arcanist repos list`.":t==="session"?"List sessions with `arcanist sessions list`.":void 0;if(e===409&&r?.repository){if(r.serverCode==="environment_required")return`Run \`arcanist environments prepare ${r.repository} --wait\`, then retry the review.`;if(r.serverCode==="environment_preparing"||r.serverCode==="environment_needs_attention")return`Run \`arcanist environments status ${r.repository} --wait\` for the latest setup state.`}if(e===409)return"Check the current resource state and retry the command when it is ready.";if(e>=500)return"Retry later or check the control-plane logs."}}var ob="Run `arcanist help <command>` for usage, or `arcanist help --json` for the full command tree.";function ab(e){if(!("code"in e)||typeof e.code!="string"||!e.code.startsWith("commander."))return null;let[t="",r]=e.message.replace(/^error: /,"").split(`
5
- `);return new y("user",t,{hint:r?r.replace(/^\((.*)\)$/,"$1"):ob})}function Qp(e){if(e instanceof y)return e;if(e instanceof Error){let t=ab(e);if(t)return t}return e instanceof Error?new y("user",e.message):new y("user",String(e))}function Jr(e){return JSON.stringify({error:{code:e.code,message:e.message,...e.hint?{hint:e.hint}:{},...e.requestId?{requestId:e.requestId}:{},...e.data?{data:e.data}:{}}})}var em={name:"@tryarcanist/cli",version:"0.1.416",description:"Command-line interface for Arcanist: inspect sessions, prepare Arcanist environments, and trigger reviews",type:"module",bin:{arcanist:"dist/index.js"},engines:{node:">=22"},files:["dist/index.js"],scripts:{build:"tsup",typecheck:"node ../../node_modules/tsrs/bin/tsrs --noEmit",prepublishOnly:"npm --prefix ../.. run guard:cli-bundle"},publishConfig:{access:"public"},repository:{type:"git",url:"git+https://github.com/tryarcanist/arcanist.git",directory:"apps/cli"},homepage:"https://www.tryarcanist.com",license:"MIT",dependencies:{commander:"^12.1.0","playwright-core":"^1.61.1","proper-lockfile":"4.1.2"},devDependencies:{"@types/proper-lockfile":"^4.1.4",tsup:"^9.0.0",typescript:"^5.9.3"}};var Yr=`${em.version}`;var ub=`arcanist-cli/${Yr}`,cb=3e4,lb=1e3,db=6e5,Xr="ARCANIST_HTTP_TIMEOUT_MS";function pb(e=process.env){let t=e[Xr];if(!t)return cb;if(!/^\d+$/.test(t))throw new y("user",`${Xr} must be a positive integer between 1000 and 600000.`);let r=Number(t);if(r<lb||r>db)throw new y("user",`${Xr} must be between 1000 and 600000 milliseconds.`);return r}function Ca(e){return e instanceof DOMException&&e.name==="AbortError"}function mb(e){let t=e instanceof Error?e.cause:null;return t&&typeof t=="object"&&"code"in t&&typeof t.code=="string"?t.code:null}function Oa(e){return new Mt("server",`Network timeout after ${e}ms.`,{hint:`Increase ${Xr} for slow links, or check the API connection.`})}function fb(e){let t=pb();if(!e)return{fetchInit:void 0,timeoutMs:t};let{timeoutMs:r,...o}=e;return r===void 0?{fetchInit:o,timeoutMs:t}:!Number.isFinite(r)||r<=0?{fetchInit:o,timeoutMs:1}:{fetchInit:o,timeoutMs:Math.max(1,Math.min(t,r))}}async function Na(e,t,r,o){let{fetchInit:n,timeoutMs:i}=fb(r),a=new AbortController,s=setTimeout(()=>a.abort(),i);try{let u=new Headers(n?.headers);u.set("Content-Type","application/json"),u.set("User-Agent",ub),e.token&&u.set("Authorization",`Bearer ${e.token}`);let c=await fetch(`${et(e.apiUrl)}${t}`,{...n,headers:u,signal:a.signal}).catch(l=>{throw Ca(l)?Oa(i):new Mt("server",`Network error: could not reach ${et(e.apiUrl)} (${mb(l)??xe(l)}).`,{hint:"Check the network and `ARCANIST_API_URL` or `--api-url`, then retry."})});if(!c.ok){let l=await c.text().catch(d=>{if(Ca(d))throw Oa(i);return""});throw new ue(c.status,l,c.headers.get("x-request-id")??void 0,gb(t))}return await o(c)}catch(u){throw u instanceof y?u:Ca(u)?Oa(i):u instanceof TypeError?new Mt("server",`The API response could not be read: ${xe(u)}`):new y("server",`The API response could not be read: ${xe(u)}`)}finally{clearTimeout(s)}}function gb(e){if(e.startsWith("/api/repos"))return"repo";if(e.startsWith("/api/sessions"))return"session"}async function R(e,t,r){return Na(e,t,r,o=>o.json())}async function tm(e,t,r){return Na(e,t,r,o=>o.text())}async function nm(e,t,r){return Na(e,t,r,async o=>new Uint8Array(await o.arrayBuffer()))}function A(e,t={}){return hb(e,t)}function hb(e,t){return e.replace(/:([A-Za-z]+)/g,(r,o)=>{let n=t[o];if(n===void 0)throw new Error(`apiPath(${e}) is missing the ${o} parameter`);return encodeURIComponent(n)})}import{createHash as im}from"node:crypto";import{existsSync as Cn,mkdirSync as wb,readFileSync as Da,statSync as Sb}from"node:fs";import{homedir as xb}from"node:os";import{dirname as om,join as vt,resolve as $b}from"node:path";import{randomUUID as vb}from"node:crypto";import{renameSync as _b,rmSync as yb,writeFileSync as bb}from"node:fs";function ht(e,t){let r=`${e}.${vb()}.tmp`;try{bb(r,JSON.stringify(t,null,2)+`
5
+ `);return new y("user",t,{hint:r?r.replace(/^\((.*)\)$/,"$1"):ob})}function Qp(e){if(e instanceof y)return e;if(e instanceof Error){let t=ab(e);if(t)return t}return e instanceof Error?new y("user",e.message):new y("user",String(e))}function Jr(e){return JSON.stringify({error:{code:e.code,message:e.message,...e.hint?{hint:e.hint}:{},...e.requestId?{requestId:e.requestId}:{},...e.data?{data:e.data}:{}}})}var em={name:"@tryarcanist/cli",version:"0.1.417",description:"Command-line interface for Arcanist: inspect sessions, prepare Arcanist environments, and trigger reviews",type:"module",bin:{arcanist:"dist/index.js"},engines:{node:">=22"},files:["dist/index.js"],scripts:{build:"tsup",typecheck:"node ../../node_modules/tsrs/bin/tsrs --noEmit",prepublishOnly:"npm --prefix ../.. run guard:cli-bundle"},publishConfig:{access:"public"},repository:{type:"git",url:"git+https://github.com/tryarcanist/arcanist.git",directory:"apps/cli"},homepage:"https://www.tryarcanist.com",license:"MIT",dependencies:{commander:"^12.1.0","playwright-core":"^1.61.1","proper-lockfile":"4.1.2"},devDependencies:{"@types/proper-lockfile":"^4.1.4",tsup:"^9.0.0",typescript:"^5.9.3"}};var Yr=`${em.version}`;var ub=`arcanist-cli/${Yr}`,cb=3e4,lb=1e3,db=6e5,Xr="ARCANIST_HTTP_TIMEOUT_MS";function pb(e=process.env){let t=e[Xr];if(!t)return cb;if(!/^\d+$/.test(t))throw new y("user",`${Xr} must be a positive integer between 1000 and 600000.`);let r=Number(t);if(r<lb||r>db)throw new y("user",`${Xr} must be between 1000 and 600000 milliseconds.`);return r}function Ca(e){return e instanceof DOMException&&e.name==="AbortError"}function mb(e){let t=e instanceof Error?e.cause:null;return t&&typeof t=="object"&&"code"in t&&typeof t.code=="string"?t.code:null}function Oa(e){return new Mt("server",`Network timeout after ${e}ms.`,{hint:`Increase ${Xr} for slow links, or check the API connection.`})}function fb(e){let t=pb();if(!e)return{fetchInit:void 0,timeoutMs:t};let{timeoutMs:r,...o}=e;return r===void 0?{fetchInit:o,timeoutMs:t}:!Number.isFinite(r)||r<=0?{fetchInit:o,timeoutMs:1}:{fetchInit:o,timeoutMs:Math.max(1,Math.min(t,r))}}async function Na(e,t,r,o){let{fetchInit:n,timeoutMs:i}=fb(r),a=new AbortController,s=setTimeout(()=>a.abort(),i);try{let u=new Headers(n?.headers);u.set("Content-Type","application/json"),u.set("User-Agent",ub),e.token&&u.set("Authorization",`Bearer ${e.token}`);let c=await fetch(`${et(e.apiUrl)}${t}`,{...n,headers:u,signal:a.signal}).catch(l=>{throw Ca(l)?Oa(i):new Mt("server",`Network error: could not reach ${et(e.apiUrl)} (${mb(l)??xe(l)}).`,{hint:"Check the network and `ARCANIST_API_URL` or `--api-url`, then retry."})});if(!c.ok){let l=await c.text().catch(d=>{if(Ca(d))throw Oa(i);return""});throw new ue(c.status,l,c.headers.get("x-request-id")??void 0,gb(t))}return await o(c)}catch(u){throw u instanceof y?u:Ca(u)?Oa(i):u instanceof TypeError?new Mt("server",`The API response could not be read: ${xe(u)}`):new y("server",`The API response could not be read: ${xe(u)}`)}finally{clearTimeout(s)}}function gb(e){if(e.startsWith("/api/repos"))return"repo";if(e.startsWith("/api/sessions"))return"session"}async function R(e,t,r){return Na(e,t,r,o=>o.json())}async function tm(e,t,r){return Na(e,t,r,o=>o.text())}async function nm(e,t,r){return Na(e,t,r,async o=>new Uint8Array(await o.arrayBuffer()))}function A(e,t={}){return hb(e,t)}function hb(e,t){return e.replace(/:([A-Za-z]+)/g,(r,o)=>{let n=t[o];if(n===void 0)throw new Error(`apiPath(${e}) is missing the ${o} parameter`);return encodeURIComponent(n)})}import{createHash as im}from"node:crypto";import{existsSync as Cn,mkdirSync as wb,readFileSync as Da,statSync as Sb}from"node:fs";import{homedir as xb}from"node:os";import{dirname as om,join as vt,resolve as $b}from"node:path";import{randomUUID as vb}from"node:crypto";import{renameSync as _b,rmSync as yb,writeFileSync as bb}from"node:fs";function ht(e,t){let r=`${e}.${vb()}.tmp`;try{bb(r,JSON.stringify(t,null,2)+`
6
6
  `,{mode:384,flag:"wx"}),_b(r,e)}finally{yb(r,{force:!0})}}var am=vt(xb(),".arcanist"),sm=vt(am,"config.json"),tt=".arcanist-cli.json",Ib="https://app.tryarcanist.com";function Ua(){try{return JSON.parse(Da(sm,"utf-8"))}catch{return null}}function On(e={}){let t=Eb(e);if(t)return rm(t);let r=za(),o=La(e,r!==null),n=Ua(),i=o?.apiUrl??r?.apiUrl??n?.apiUrl,a=r&&n?.apiUrl===r.apiUrl&&n.token&&n.supersededProjectTokenHash===im("sha256").update(r.token).digest("hex")?n.token:r?.token,s=o?.token??a??n?.token;if(!i||!s)return null;let u=rm({apiUrl:i,token:s});return r&&!o&&!e.json&&process.stderr.write(`using ${tt} -> ${u.apiUrl}
7
7
  `),u}function Qr(e,t){let r=ti(e.apiUrl);if(r)throw new y("user",r);wb(am,{recursive:!0,mode:448});let o=et(e.apiUrl),n=Ua(),i=t?im("sha256").update(t).digest("hex"):n?.apiUrl===o?n.supersededProjectTokenHash:void 0,a={...e,apiUrl:o,...i?{supersededProjectTokenHash:i}:{}};ht(sm,a)}function ve(e){let t=On(e);if(!t)throw new y("auth","Not logged in.",{hint:"Run `arcanist auth login` or set `ARCANIST_TOKEN`."});return t}function ei(e){let t=e??process.env.ARCANIST_API_URL??Ua()?.apiUrl??Ib,r=ti(t);if(r)throw new y("user",r);return et(t)}function za(e=process.cwd()){let t=kb(e);if(!t)return null;let r=e;for(;;){let o=vt(r,tt);if(Cn(o))return Rb(o);if(r===t)return null;let n=om(r);if(n===r)return null;r=n}}function ti(e){let t;try{t=new URL(e)}catch{return"Invalid URL format"}return t.username||t.password?"API URL must not include embedded credentials. Use --token or ARCANIST_TOKEN to authenticate.":t.protocol!=="https:"&&!um(t)?"API URL must use HTTPS for non-local hosts":null}function La(e,t){let r=e.apiUrl??process.env.ARCANIST_API_URL,o=e.token??process.env.ARCANIST_TOKEN;if(!t)return!r&&!o?null:{apiUrl:r,token:o};if(r&&!o||!r&&o)throw new y("user",`${tt} is active; set both ARCANIST_API_URL and ARCANIST_TOKEN, pass both --api-url and --token, or set neither.`);return!r||!o?null:{apiUrl:r,token:o}}function Eb(e){let t=e.apiUrl??process.env.ARCANIST_API_URL,r=e.token??process.env.ARCANIST_TOKEN;return!t||!r?null:{apiUrl:t,token:r}}function rm(e){let t=ti(e.apiUrl);if(t)throw new y("user",t);return{apiUrl:et(e.apiUrl),token:e.token}}function kb(e){let t=e;for(;;){if(Tb(t))return t;let r=om(t);if(r===t)return null;t=r}}function Tb(e){let t=vt(e,".git");if(!Cn(t))return!1;try{let r=Sb(t);if(r.isDirectory())return Cn(vt(t,"HEAD"))&&Cn(vt(t,"config"));if(!r.isFile())return!1;let o=Ab(t);return o?Cn(vt($b(e,o),"HEAD")):!1}catch{return!1}}function Ab(e){let t=Da(e,"utf-8").split(/\r?\n/).find(o=>o.startsWith("gitdir:"));return t&&t.slice(7).trim()||null}function Rb(e){let t;try{t=JSON.parse(Da(e,"utf-8"))}catch{throw new y("user",`${tt} is not valid JSON.`)}if(!t||typeof t!="object")throw new y("user",`${tt} must contain both apiUrl and token.`);let r=t;if(typeof r.apiUrl!="string"||typeof r.token!="string"||!r.apiUrl||!r.token)throw new y("user",`${tt} must contain both apiUrl and token.`);let o;try{o=new URL(r.apiUrl)}catch{throw new y("user",`${tt} apiUrl must be a valid URL.`)}if(!um(o))throw new y("user",`${tt} apiUrl must be a loopback host.`);let n=ti(r.apiUrl);if(n)throw new y("user",n);return{apiUrl:et(r.apiUrl),token:r.token}}function um(e){let t=e.hostname.replace(/^\[|\]$/g,"");return t==="localhost"||t==="127.0.0.1"||t==="::1"}function ee(e,t={}){let o={...e?.optsWithGlobals?.(),...t};return{...o,noColor:o.noColor===!0||o.color===!1}}function $e(e,t={}){return ee(e,t).json===!0}function qe(e){process.stdout.write(`${JSON.stringify(e)}
8
8
  `)}function U(e,t,r,o){if($e(e,t)){qe(r);return}o(r)}function Y(e,t={}){let r=ee(e,t);return{runtime:r,config:ve(r)}}async function Pb(){let e=[];for await(let t of process.stdin)e.push(Buffer.isBuffer(t)?t:Buffer.from(String(t)));return Buffer.concat(e).toString()}async function Nn(){return(await Pb()).trim()}function cm(e){(e.noColor===!0||!process.stdout.isTTY)&&(process.env.NO_COLOR="1")}function O(e){return e.replace(/\u001b\][^\u0007]*(?:\u0007|\u001b\\)/g,"").replace(/\u001b\[[0-?]*[ -\/]*[@-~]/g,"").replace(/[\u0000-\u001f\u007f]/g,"")}function Ne(e){return e.split(/\r?\n/).map(O).join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryarcanist/cli",
3
- "version": "0.1.416",
3
+ "version": "0.1.417",
4
4
  "description": "Command-line interface for Arcanist: inspect sessions, prepare Arcanist environments, and trigger reviews",
5
5
  "type": "module",
6
6
  "bin": {