@tryarcanist/cli 0.1.385 → 0.1.386

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 Cb=Object.defineProperty;var He=(e,t)=>{for(var r in t)Cb(e,r,{get:t[r],enumerable:!0})};import{Command as wP,Option as xP}from"commander";var im=["idle","running","review_starting","waiting_for_input","finalizing","review_listening","completed","superseded","needs_you","blocked","failed","stopped","archived"];var Zt=["completed","superseded","needs_you","blocked","failed","stopped","archived"],Ob=new Set(Zt),CP=new Set(Zt.filter(e=>e!=="completed")),OP=new Set(Zt.filter(e=>e!=="stopped")),NP=Zt.filter(e=>e!=="archived"&&e!=="needs_you"&&e!=="blocked"&&e!=="stopped");function om(e,t){return Ob.has(e)}function am(e){let t=e.createHelp().visibleGlobalOptions(e).map(um);return{...sm(e),...t.length>0?{globalOptions:t}:{}}}function sm(e){let t=Nb(e);return{path:ja(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(um),...t?{notes:t}:{},subcommands:e.commands.map(sm)}}function um(e){return{flags:e.flags,description:e.description,required:e.mandatory,...e.defaultValue===void 0?{}:{defaultValue:e.defaultValue}}}function ja(e){let t=[];for(let r=e;r;r=r.parent)t.unshift(r.name());return t.join(" ")}function Nb(e){let t="";return e.emit("afterHelp",{error:!1,command:e,write:r=>t+=r}),t.trim()}import{existsSync as wS,mkdirSync as xS,writeFileSync as $S}from"node:fs";import{basename as IS,join as Am,resolve as ES}from"node:path";var Db="en-US";function cm(e,t){let r=new Intl.DateTimeFormat(Db,{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 Ie(e,t=""){return(e instanceof Error?e.message:String(e))||t}function ti(e){return new Promise(t=>setTimeout(t,e))}function lm(e,t){return new Promise(r=>{let o=!1,n=()=>{o||(o=!0,clearTimeout(i),t?.removeEventListener("abort",n),r())},i=setTimeout(()=>{o=!0,t?.removeEventListener("abort",n),r()},e);if(t?.aborted){clearTimeout(i),o=!0,r();return}t?.addEventListener("abort",n)})}var Lb=.2,jb=new Set([408,429,500,502,503,504]);function Mb(e){let{retry:t,baseMs:r,maxMs:o=Number.POSITIVE_INFINITY,jitter:n,random:i=Math.random}=e,a=n[0]+i()*(n[1]-n[0]);return Math.min(o,Math.max(0,Math.round(r*2**Math.max(0,t-1)*a)))}function Zb(e,t){let r=t?.includeDefaults!==!1&&jb.has(e)||t?.includeServerErrors===!0&&e>=500;return t?.remove?.includes(e)?!1:r||t?.add?.includes(e)===!0}var Ma=class extends Error{constructor(t="Provider retry aborted"){super(t),this.name="ProviderRetryAbortError"}};function Fb(e){if(!(!e||typeof e!="object"||!("status"in e)))return typeof e.status=="number"?e.status:void 0}function Bb(e){if(!e||typeof e!="object"||!("headers"in e))return;let t=e.headers;if(!(!t||typeof t!="object"||!("get"in t)))return typeof t.get=="function"?t:void 0}function Vb(e){if(e instanceof TypeError||e instanceof Error&&e.name==="TimeoutError")return!0;let t=Fb(e);return typeof t=="number"&&Zb(t,{add:[409],includeServerErrors:!0})}function Gb(e,t=Date.now()){let r=e.get("retry-after-ms");if(r){let a=Number(r);if(Number.isFinite(a)&&a>=0)return a}let o=e.get("retry-after");if(!o)return null;let n=Number(o);if(Number.isFinite(n))return n>=0?n*1e3:null;let i=Date.parse(o);return Number.isNaN(i)?null:Math.max(0,i-t)}function Wb(e){let t=Bb(e);return t?Gb(t):null}function dm(e,t){if(!(!e||typeof e!="object"))try{Object.defineProperty(e,"__retryAttempts",{value:t,enumerable:!1,configurable:!0,writable:!0})}catch{}}function qb(e,t){if(!t)return e;let r=AbortSignal.timeout(t);return e?AbortSignal.any([e,r]):r}async function pm(e){if(!Number.isInteger(e.maxAttempts)||e.maxAttempts<1)throw new RangeError("maxAttempts must be at least 1");let t=e.sleep??lm,r=e.random??Math.random,o=e.perAttemptTimeoutMs??6e5,n=e.isTransient??Vb,i=e.getRetryAfterMs??Wb,a=e.abortErrorFactory??(()=>new Ma),s=e.now??Date.now,u=e.jitterFactor??Lb,c=[1-u,1+u],l=0,p;for(;l<e.maxAttempts;){if(e.callerSignal?.aborted)throw a(l);if(e.deadlineMs!==void 0&&s()>=e.deadlineMs)throw p!==void 0?p:a(l);l+=1;let f=o>0&&e.deadlineMs!==void 0?Math.min(o,Math.max(1,e.deadlineMs-s())):o,m=qb(e.callerSignal,f);try{return{value:await e.op(m??new AbortController().signal),attempts:l}}catch(g){if(e.callerSignal?.aborted)throw a(l,g);if(!n(g)||l>=e.maxAttempts)throw dm(g,l),g;let h=Math.max(i(g)??0,Mb({retry:l,baseMs:e.baseMs??250,jitter:c,random:r}));if(dm(g,l),p=g,e.deadlineMs!==void 0&&s()+h>=e.deadlineMs)throw g;try{e.onRetry?.({attempt:l+1,maxAttempts:e.maxAttempts,delayMs:h,error:g})}catch{}if(await t(h,e.callerSignal??new AbortController().signal),e.callerSignal?.aborted)throw a(l)}}throw new Error("Provider retry loop exited without a result")}function et(e){return e.replace(/\/+$/,"")}function mm(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 Za(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=mm(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 Ee=130,Fa=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??fm(t),this.hint=o.hint,this.requestId=o.requestId,this.data=o.data}},_t=class extends y{},ze=class extends y{status;body;constructor(t,r,o,n){let i=gm(t),a=Za(r);super(i,Kb(t,r,a),{exitCode:Hb(t),hint:Jb(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 fm(e){switch(e){case"auth":return 2;case"not_found":return 3;case"conflict":return 4;case"server":return 10;default:return 1}}function gm(e){return e===401||e===403?"auth":e===404?"not_found":e===409?"conflict":e>=500?"server":"user"}function Hb(e){return fm(gm(e))}function Kb(e,t,r=Za(t)){return r?.message?r.message:r?.serverCode?r.serverCode:t?`API error ${e}: ${t}`:`API error ${e}`}function Jb(e,t,r){if(e===401)return"Run `arcanist auth login` or set `ARCANIST_TOKEN`.";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 Yb="Run `arcanist help <command>` for usage, or `arcanist help --json` for the full command tree.";function Xb(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"):Yb})}function hm(e){if(e instanceof y)return e;if(e instanceof Error){let t=Xb(e);if(t)return t}return e instanceof Error?new y("user",e.message):new y("user",String(e))}function ni(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 vm={name:"@tryarcanist/cli",version:"0.1.385",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"},devDependencies:{tsup:"^8.0.0",typescript:"^5.9.3"}};var ri=`${vm.version}`;var eS=`arcanist-cli/${ri}`,tS=3e4,nS=1e3,rS=6e5,ii="ARCANIST_HTTP_TIMEOUT_MS";function iS(e=process.env){let t=e[ii];if(!t)return tS;if(!/^\d+$/.test(t))throw new y("user",`${ii} must be a positive integer between 1000 and 600000.`);let r=Number(t);if(r<nS||r>rS)throw new y("user",`${ii} must be between 1000 and 600000 milliseconds.`);return r}function Ba(e){return e instanceof DOMException&&e.name==="AbortError"}function oS(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 Va(e){return new _t("server",`Network timeout after ${e}ms.`,{hint:`Increase ${ii} for slow links, or check the API connection.`})}function aS(e){let t=iS();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 Ga(e,t,r,o){let{fetchInit:n,timeoutMs:i}=aS(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",eS),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 Ba(l)?Va(i):new _t("server",`Network error: could not reach ${et(e.apiUrl)} (${oS(l)??Ie(l)}).`,{hint:"Check the network and `ARCANIST_API_URL` or `--api-url`, then retry."})});if(!c.ok){let l=await c.text().catch(p=>{if(Ba(p))throw Va(i);return""});throw new ze(c.status,l,c.headers.get("x-request-id")??void 0,sS(t))}return await o(c)}catch(u){throw u instanceof y?u:Ba(u)?Va(i):u instanceof TypeError?new _t("server",`The API response could not be read: ${Ie(u)}`):new y("server",`The API response could not be read: ${Ie(u)}`)}finally{clearTimeout(s)}}function sS(e){if(e.startsWith("/api/repos"))return"repo";if(e.startsWith("/api/sessions"))return"session"}async function P(e,t,r){return Ga(e,t,r,o=>o.json())}async function _m(e,t,r){return Ga(e,t,r,o=>o.text())}async function ym(e,t,r){return Ga(e,t,r,async o=>new Uint8Array(await o.arrayBuffer()))}async function Un(e,t){let{value:r}=await pm({op:()=>P(e,t),maxAttempts:3,perAttemptTimeoutMs:0,isTransient:o=>o instanceof _t,onRetry:({attempt:o,maxAttempts:n,delayMs:i})=>{process.stderr.write(`Retrying archive GET ${t} (${o}/${n}) in ${i}ms.
5
+ `);return new y("user",t,{hint:r?r.replace(/^\((.*)\)$/,"$1"):Yb})}function hm(e){if(e instanceof y)return e;if(e instanceof Error){let t=Xb(e);if(t)return t}return e instanceof Error?new y("user",e.message):new y("user",String(e))}function ni(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 vm={name:"@tryarcanist/cli",version:"0.1.386",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"},devDependencies:{tsup:"^8.0.0",typescript:"^5.9.3"}};var ri=`${vm.version}`;var eS=`arcanist-cli/${ri}`,tS=3e4,nS=1e3,rS=6e5,ii="ARCANIST_HTTP_TIMEOUT_MS";function iS(e=process.env){let t=e[ii];if(!t)return tS;if(!/^\d+$/.test(t))throw new y("user",`${ii} must be a positive integer between 1000 and 600000.`);let r=Number(t);if(r<nS||r>rS)throw new y("user",`${ii} must be between 1000 and 600000 milliseconds.`);return r}function Ba(e){return e instanceof DOMException&&e.name==="AbortError"}function oS(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 Va(e){return new _t("server",`Network timeout after ${e}ms.`,{hint:`Increase ${ii} for slow links, or check the API connection.`})}function aS(e){let t=iS();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 Ga(e,t,r,o){let{fetchInit:n,timeoutMs:i}=aS(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",eS),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 Ba(l)?Va(i):new _t("server",`Network error: could not reach ${et(e.apiUrl)} (${oS(l)??Ie(l)}).`,{hint:"Check the network and `ARCANIST_API_URL` or `--api-url`, then retry."})});if(!c.ok){let l=await c.text().catch(p=>{if(Ba(p))throw Va(i);return""});throw new ze(c.status,l,c.headers.get("x-request-id")??void 0,sS(t))}return await o(c)}catch(u){throw u instanceof y?u:Ba(u)?Va(i):u instanceof TypeError?new _t("server",`The API response could not be read: ${Ie(u)}`):new y("server",`The API response could not be read: ${Ie(u)}`)}finally{clearTimeout(s)}}function sS(e){if(e.startsWith("/api/repos"))return"repo";if(e.startsWith("/api/sessions"))return"session"}async function P(e,t,r){return Ga(e,t,r,o=>o.json())}async function _m(e,t,r){return Ga(e,t,r,o=>o.text())}async function ym(e,t,r){return Ga(e,t,r,async o=>new Uint8Array(await o.arrayBuffer()))}async function Un(e,t){let{value:r}=await pm({op:()=>P(e,t),maxAttempts:3,perAttemptTimeoutMs:0,isTransient:o=>o instanceof _t,onRetry:({attempt:o,maxAttempts:n,delayMs:i})=>{process.stderr.write(`Retrying archive GET ${t} (${o}/${n}) in ${i}ms.
6
6
  `)}});return r}function A(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{existsSync as Ln,mkdirSync as uS,readFileSync as Wa,statSync as cS,writeFileSync as lS}from"node:fs";import{homedir as dS}from"node:os";import{dirname as Sm,join as yt,resolve as pS}from"node:path";var wm=yt(dS(),".arcanist"),xm=yt(wm,"config.json"),tt=".arcanist-cli.json",mS="https://app.tryarcanist.com";function $m(){try{return JSON.parse(Wa(xm,"utf-8"))}catch{return null}}function fS(e={}){let t=hS(e);if(t)return bm(t);let r=gS(),o=qa(e,r!==null),n=$m(),i=o?.apiUrl??r?.apiUrl??n?.apiUrl,a=o?.token??r?.token??n?.token;if(!i||!a)return null;let s=bm({apiUrl:i,token:a});return r&&!o&&!e.json&&process.stderr.write(`using ${tt} -> ${s.apiUrl}
7
7
  `),s}function Im(e){let t=oi(e.apiUrl);if(t)throw new y("user",t);uS(wm,{recursive:!0,mode:448}),lS(xm,JSON.stringify({...e,apiUrl:et(e.apiUrl)},null,2)+`
8
8
  `,{mode:384})}function te(e){let t=fS(e);if(!t)throw new y("auth","Not logged in.",{hint:"Run `arcanist auth login` or set `ARCANIST_TOKEN`."});return t}function Em(e){let t=e??process.env.ARCANIST_API_URL??$m()?.apiUrl??mS,r=oi(t);if(r)throw new y("user",r);return et(t)}function gS(e=process.cwd()){let t=vS(e);if(!t)return null;let r=e;for(;;){let o=yt(r,tt);if(Ln(o))return bS(o);if(r===t)return null;let n=Sm(r);if(n===r)return null;r=n}}function oi(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:"&&!km(t)?"API URL must use HTTPS for non-local hosts":null}function qa(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 hS(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 bm(e){let t=oi(e.apiUrl);if(t)throw new y("user",t);return{apiUrl:et(e.apiUrl),token:e.token}}function vS(e){let t=e;for(;;){if(_S(t))return t;let r=Sm(t);if(r===t)return null;t=r}}function _S(e){let t=yt(e,".git");if(!Ln(t))return!1;try{let r=cS(t);if(r.isDirectory())return Ln(yt(t,"HEAD"))&&Ln(yt(t,"config"));if(!r.isFile())return!1;let o=yS(t);return o?Ln(yt(pS(e,o),"HEAD")):!1}catch{return!1}}function yS(e){let t=Wa(e,"utf-8").split(/\r?\n/).find(o=>o.startsWith("gitdir:"));return t&&t.slice(7).trim()||null}function bS(e){let t;try{t=JSON.parse(Wa(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(!km(o))throw new y("user",`${tt} apiUrl must be a loopback host.`);let n=oi(r.apiUrl);if(n)throw new y("user",n);return{apiUrl:et(r.apiUrl),token:r.token}}function km(e){let t=e.hostname.replace(/^\[|\]$/g,"");return t==="localhost"||t==="127.0.0.1"||t==="::1"}function Y(e,t={}){let o={...e?.optsWithGlobals?.(),...t};return{...o,noColor:o.noColor===!0||o.color===!1}}function ke(e,t={}){return Y(e,t).json===!0}function Ue(e){process.stdout.write(`${JSON.stringify(e)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryarcanist/cli",
3
- "version": "0.1.385",
3
+ "version": "0.1.386",
4
4
  "description": "Command-line interface for Arcanist: inspect sessions, prepare Arcanist environments, and trigger reviews",
5
5
  "type": "module",
6
6
  "bin": {