@tryarcanist/cli 0.1.468 → 0.1.470

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 +3 -3
  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 ub=Object.defineProperty;var Ge=(e,t)=>{for(var r in t)ub(e,r,{get:t[r],enumerable:!0})};import{Command as wR,Option as SR}from"commander";var Wp=["idle","running","review_starting","waiting_for_input","finalizing","review_listening","completed","superseded","needs_you","blocked","failed","stopped","archived"];var Cn=["completed","superseded","needs_you","blocked","failed","stopped","archived"],cb=new Set(Cn),AR=new Set(Cn.filter(e=>e!=="completed")),RR=Cn.filter(e=>e!=="archived"&&e!=="needs_you"&&e!=="blocked"&&e!=="stopped");function Hp(e,t){return cb.has(e)}function Kp(e){let t=e.createHelp().visibleGlobalOptions(e).map(Yp);return{...Jp(e),...t.length>0?{globalOptions:t}:{}}}function Jp(e){let t=lb(e);return{path:Ca(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(Yp),...t?{notes:t}:{},subcommands:e.commands.map(Jp)}}function Yp(e){return{flags:e.flags,description:e.description,required:e.mandatory,...e.defaultValue===void 0?{}:{defaultValue:e.defaultValue}}}function Ca(e){let t=[];for(let r=e;r;r=r.parent)t.unshift(r.name());return t.join(" ")}function lb(e){let t="";return e.emit("afterHelp",{error:!1,command:e,write:r=>t+=r}),t.trim()}import{existsSync as Xb,mkdirSync as Qb,writeFileSync as ew}from"node:fs";import{basename as tw,join as gm,resolve as nw}from"node:path";var db="en-US";function Xp(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 $e(e,t=""){return(e instanceof Error?e.message:String(e))||t}function Jr(e){return new Promise(t=>setTimeout(t,e))}var pb=/\/+$/;function tt(e){return e.replace(pb,"")}var Qp="Setup and reviews are paused for this workspace. Contact team@tryarcanist.com to resume them.";function em(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 Oa(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=em(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 mb=/^error: /,fb=/^\((.*)\)$/,Ne=130,Na=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??tm(t),this.hint=o.hint,this.requestId=o.requestId,this.data=o.data}},jt=class extends y{},ce=class extends y{status;body;constructor(t,r,o,n){let i=nm(t),a=Oa(r);super(i,hb(t,r,a),{exitCode:gb(t),hint:vb(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 tm(e){switch(e){case"auth":return 2;case"not_found":return 3;case"conflict":return 4;case"server":return 10;default:return 1}}function nm(e){return e===401||e===403?"auth":e===404?"not_found":e===409?"conflict":e>=500?"server":"user"}function gb(e){return tm(nm(e))}function hb(e,t,r=Oa(t)){return r?.message?r.message:r?.serverCode?r.serverCode:t?`API error ${e}: ${t}`:`API error ${e}`}function vb(e,t,r){if(e===401)return"Run `arcanist auth login` or set `ARCANIST_TOKEN`.";if(!(e===403&&r?.message===Qp)){if(e===403&&r?.serverCode==="github_not_connected")return"This user has not connected GitHub. Open `/auth/github/connect` on the Arcanist app and approve, then retry. `arcanist onboard <owner/repo>` prints that link.";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 _b="Run `arcanist help <command>` for usage, or `arcanist help --json` for the full command tree.";function yb(e){if(!("code"in e)||typeof e.code!="string"||!e.code.startsWith("commander."))return null;let[t="",r]=e.message.replace(mb,"").split(`
5
- `);return new y("user",t,{hint:r?r.replace(fb,"$1"):_b})}function rm(e){if(e instanceof y)return e;if(e instanceof Error){let t=yb(e);if(t)return t}return e instanceof Error?new y("user",e.message):new y("user",String(e))}function Yr(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 im={name:"@tryarcanist/cli",version:"0.1.468",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","eventsource-parser":"3.1.1","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 nt=`${im.version}`;var wb=/^\d+$/,Sb=`arcanist-cli/${nt}`,xb=3e4,$b=1e3,Eb=6e5,Xr="ARCANIST_HTTP_TIMEOUT_MS";function Ib(e=process.env){let t=e[Xr];if(!t)return xb;if(!wb.test(t))throw new y("user",`${Xr} must be a positive integer between 1000 and 600000.`);let r=Number(t);if(r<$b||r>Eb)throw new y("user",`${Xr} must be between 1000 and 600000 milliseconds.`);return r}function Da(e){return e instanceof DOMException&&e.name==="AbortError"}function kb(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 Ua(e){return new jt("server",`Network timeout after ${e}ms.`,{hint:`Increase ${Xr} for slow links, or check the API connection.`})}function Tb(e){let t=Ib();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 za(e,t,r,o){let{fetchInit:n,timeoutMs:i}=Tb(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",Sb),e.token&&u.set("Authorization",`Bearer ${e.token}`);let c=await fetch(`${tt(e.apiUrl)}${t}`,{...n,headers:u,signal:a.signal}).catch(l=>{throw Da(l)?Ua(i):new jt("server",`Network error: could not reach ${tt(e.apiUrl)} (${kb(l)??$e(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(Da(d))throw Ua(i);return""});throw new ce(c.status,l,c.headers.get("x-request-id")??void 0,Ab(t))}return await o(c)}catch(u){throw u instanceof y?u:Da(u)?Ua(i):u instanceof TypeError?new jt("server",`The API response could not be read: ${$e(u)}`):new y("server",`The API response could not be read: ${$e(u)}`)}finally{clearTimeout(s)}}function Ab(e){if(e.startsWith("/api/repos"))return"repo";if(e.startsWith("/api/sessions"))return"session"}async function R(e,t,r){return za(e,t,r,o=>o.json())}async function om(e,t,r){return za(e,t,r,o=>o.text())}async function am(e,t,r){return za(e,t,r,async o=>new Uint8Array(await o.arrayBuffer()))}var Rb=/:([A-Za-z]+)/g,B={getCurrentUser:{method:"GET",pattern:"/api/auth/whoami"},exchangeCliLogin:{method:"POST",pattern:"/api/cli-login/exchange"},getGithubInstallation:{method:"GET",pattern:"/api/onboarding/github-installation"},answerOnboardingQuestion:{method:"POST",pattern:"/api/settings/repositories/:owner/:repo/onboarding/question"},answerEnvironmentSecretRequest:{method:"POST",pattern:"/api/environments/:id/secret-requests/:requestId"},listRepositories:{method:"GET",pattern:"/api/repos"},listSessions:{method:"GET",pattern:"/api/sessions"},getSession:{method:"GET",pattern:"/api/sessions/:sessionId"},getSessionView:{method:"GET",pattern:"/api/sessions/:sessionId/view"},getSessionPrompts:{method:"GET",pattern:"/api/sessions/:sessionId/prompts"},getSessionEvents:{method:"GET",pattern:"/api/sessions/:sessionId/events"},getSessionEventHistory:{method:"GET",pattern:"/api/sessions/:sessionId/events/history"},exportSession:{method:"GET",pattern:"/api/sessions/:sessionId/export"},listSessionArtifacts:{method:"GET",pattern:"/api/sessions/:sessionId/artifacts/list"},viewSessionArtifact:{method:"GET",pattern:"/api/sessions/:sessionId/artifacts/:artifactId/view"},createReview:{method:"POST",pattern:"/api/pr-reviews"},getReviewRequest:{method:"GET",pattern:"/api/pr-reviews/requests/:requestId"},getReviewRequestStatuses:{method:"POST",pattern:"/api/pr-reviews/requests/status-batch"},createLocalReview:{method:"POST",pattern:"/api/local-reviews"},getLocalReview:{method:"GET",pattern:"/api/local-reviews/:requestId"},getRepositoryOnboarding:{method:"GET",pattern:"/api/settings/repositories/onboarding"},prepareRepository:{method:"POST",pattern:"/api/settings/repositories/onboarding"},retryRepositoryOnboarding:{method:"POST",pattern:"/api/settings/repositories/:owner/:repo/onboarding/retry"},listEnvironments:{method:"GET",pattern:"/api/environments"},getEnvironment:{method:"GET",pattern:"/api/environments/:id"},updateEnvironment:{method:"PUT",pattern:"/api/environments/:id"},createEnvironment:{method:"POST",pattern:"/api/environments"},getEnvironmentBrowserState:{method:"GET",pattern:"/api/environments/:id/browser-state"},setEnvironmentBrowserState:{method:"PUT",pattern:"/api/environments/:id/browser-state"},deleteEnvironmentBrowserState:{method:"DELETE",pattern:"/api/environments/:id/browser-state"}};function A(e,t={}){return sm(e,t)}function sm(e,t){return e.replace(Rb,(r,o)=>{let n=t[o];if(n===void 0)throw new Error(`apiPath(${e}) is missing the ${o} parameter`);return encodeURIComponent(n)})}var lP=[{...B.getCurrentUser,command:"auth whoami"},{...B.exchangeCliLogin,command:"auth login",public:!0},{...B.getGithubInstallation,command:"onboard"},{...B.answerOnboardingQuestion,command:"environments answer"},{...B.answerEnvironmentSecretRequest,command:"environments secrets"},{...B.listRepositories,command:"repos list"},{...B.listSessions,command:"sessions list"},{...B.getSession,command:"sessions get"},{...B.getSessionView,command:"sessions view"},{...B.getSessionPrompts,command:"sessions events --follow"},{...B.getSessionEvents,command:"sessions events --follow"},{...B.getSessionEventHistory,command:"sessions events"},{...B.exportSession,command:"sessions transcript"},{...B.listSessionArtifacts,command:"sessions artifacts"},{...B.viewSessionArtifact,command:"sessions artifacts get"},{...B.createReview,command:"review <pr-url>"},{...B.getReviewRequest,command:"review <pr-url>"},{...B.getReviewRequest,command:"reviews get"},{...B.getReviewRequestStatuses,command:"reviews get"},{...B.createLocalReview,command:"review"},{...B.getLocalReview,command:"review --request"},{...B.getRepositoryOnboarding,command:"environments status"},{...B.prepareRepository,command:"environments prepare"},{...B.retryRepositoryOnboarding,command:"environments retry"},{...B.listEnvironments,command:"environments login"},{...B.getEnvironment,command:"environments login"},{...B.updateEnvironment,command:"environments login --validate-path"},{...B.listEnvironments,command:"environments export"},{...B.getEnvironment,command:"environments export"},{...B.listEnvironments,command:"environments import"},{...B.getEnvironment,command:"environments import"},{...B.updateEnvironment,command:"environments import"},{...B.createEnvironment,command:"environments import --create"},{...B.getEnvironmentBrowserState,command:"environments login"},{...B.setEnvironmentBrowserState,command:"environments login"},{...B.deleteEnvironmentBrowserState,command:"environments login --clear"}];import{createHash as cm}from"node:crypto";import{existsSync as On,mkdirSync as Db,readFileSync as La,statSync as Ub}from"node:fs";import{homedir as zb}from"node:os";import{dirname as lm,join as yt,resolve as Lb}from"node:path";import{randomUUID as Pb}from"node:crypto";import{renameSync as Cb,rmSync as Ob,writeFileSync as Nb}from"node:fs";function _t(e,t){let r=`${e}.${Pb()}.tmp`;try{Nb(r,JSON.stringify(t,null,2)+`
5
+ `);return new y("user",t,{hint:r?r.replace(fb,"$1"):_b})}function rm(e){if(e instanceof y)return e;if(e instanceof Error){let t=yb(e);if(t)return t}return e instanceof Error?new y("user",e.message):new y("user",String(e))}function Yr(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 im={name:"@tryarcanist/cli",version:"0.1.470",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","eventsource-parser":"3.1.1","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 nt=`${im.version}`;var wb=/^\d+$/,Sb=`arcanist-cli/${nt}`,xb=3e4,$b=1e3,Eb=6e5,Xr="ARCANIST_HTTP_TIMEOUT_MS";function Ib(e=process.env){let t=e[Xr];if(!t)return xb;if(!wb.test(t))throw new y("user",`${Xr} must be a positive integer between 1000 and 600000.`);let r=Number(t);if(r<$b||r>Eb)throw new y("user",`${Xr} must be between 1000 and 600000 milliseconds.`);return r}function Da(e){return e instanceof DOMException&&e.name==="AbortError"}function kb(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 Ua(e){return new jt("server",`Network timeout after ${e}ms.`,{hint:`Increase ${Xr} for slow links, or check the API connection.`})}function Tb(e){let t=Ib();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 za(e,t,r,o){let{fetchInit:n,timeoutMs:i}=Tb(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",Sb),e.token&&u.set("Authorization",`Bearer ${e.token}`);let c=await fetch(`${tt(e.apiUrl)}${t}`,{...n,headers:u,signal:a.signal}).catch(l=>{throw Da(l)?Ua(i):new jt("server",`Network error: could not reach ${tt(e.apiUrl)} (${kb(l)??$e(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(Da(d))throw Ua(i);return""});throw new ce(c.status,l,c.headers.get("x-request-id")??void 0,Ab(t))}return await o(c)}catch(u){throw u instanceof y?u:Da(u)?Ua(i):u instanceof TypeError?new jt("server",`The API response could not be read: ${$e(u)}`):new y("server",`The API response could not be read: ${$e(u)}`)}finally{clearTimeout(s)}}function Ab(e){if(e.startsWith("/api/repos"))return"repo";if(e.startsWith("/api/sessions"))return"session"}async function R(e,t,r){return za(e,t,r,o=>o.json())}async function om(e,t,r){return za(e,t,r,o=>o.text())}async function am(e,t,r){return za(e,t,r,async o=>new Uint8Array(await o.arrayBuffer()))}var Rb=/:([A-Za-z]+)/g,B={getCurrentUser:{method:"GET",pattern:"/api/auth/whoami"},exchangeCliLogin:{method:"POST",pattern:"/api/cli-login/exchange"},getGithubInstallation:{method:"GET",pattern:"/api/onboarding/github-installation"},answerOnboardingQuestion:{method:"POST",pattern:"/api/settings/repositories/:owner/:repo/onboarding/question"},answerEnvironmentSecretRequest:{method:"POST",pattern:"/api/environments/:id/secret-requests/:requestId"},listRepositories:{method:"GET",pattern:"/api/repos"},listSessions:{method:"GET",pattern:"/api/sessions"},getSession:{method:"GET",pattern:"/api/sessions/:sessionId"},getSessionView:{method:"GET",pattern:"/api/sessions/:sessionId/view"},getSessionPrompts:{method:"GET",pattern:"/api/sessions/:sessionId/prompts"},getSessionEvents:{method:"GET",pattern:"/api/sessions/:sessionId/events"},getSessionEventHistory:{method:"GET",pattern:"/api/sessions/:sessionId/events/history"},exportSession:{method:"GET",pattern:"/api/sessions/:sessionId/export"},listSessionArtifacts:{method:"GET",pattern:"/api/sessions/:sessionId/artifacts/list"},viewSessionArtifact:{method:"GET",pattern:"/api/sessions/:sessionId/artifacts/:artifactId/view"},createReview:{method:"POST",pattern:"/api/pr-reviews"},getReviewRequest:{method:"GET",pattern:"/api/pr-reviews/requests/:requestId"},getReviewRequestStatuses:{method:"POST",pattern:"/api/pr-reviews/requests/status-batch"},createLocalReview:{method:"POST",pattern:"/api/local-reviews"},getLocalReview:{method:"GET",pattern:"/api/local-reviews/:requestId"},getRepositoryOnboarding:{method:"GET",pattern:"/api/settings/repositories/onboarding"},prepareRepository:{method:"POST",pattern:"/api/settings/repositories/onboarding"},retryRepositoryOnboarding:{method:"POST",pattern:"/api/settings/repositories/:owner/:repo/onboarding/retry"},listEnvironments:{method:"GET",pattern:"/api/environments"},getEnvironment:{method:"GET",pattern:"/api/environments/:id"},updateEnvironment:{method:"PUT",pattern:"/api/environments/:id"},createEnvironment:{method:"POST",pattern:"/api/environments"},getEnvironmentBrowserState:{method:"GET",pattern:"/api/environments/:id/browser-state"},setEnvironmentBrowserState:{method:"PUT",pattern:"/api/environments/:id/browser-state"},deleteEnvironmentBrowserState:{method:"DELETE",pattern:"/api/environments/:id/browser-state"}};function A(e,t={}){return sm(e,t)}function sm(e,t){return e.replace(Rb,(r,o)=>{let n=t[o];if(n===void 0)throw new Error(`apiPath(${e}) is missing the ${o} parameter`);return encodeURIComponent(n)})}var lP=[{...B.getCurrentUser,command:"auth whoami"},{...B.exchangeCliLogin,command:"auth login",public:!0},{...B.getGithubInstallation,command:"onboard"},{...B.answerOnboardingQuestion,command:"environments answer"},{...B.answerEnvironmentSecretRequest,command:"environments secrets"},{...B.listRepositories,command:"repos list"},{...B.listSessions,command:"sessions list"},{...B.getSession,command:"sessions get"},{...B.getSessionView,command:"sessions view"},{...B.getSessionPrompts,command:"sessions events --follow"},{...B.getSessionEvents,command:"sessions events --follow"},{...B.getSessionEventHistory,command:"sessions events"},{...B.exportSession,command:"sessions transcript"},{...B.listSessionArtifacts,command:"sessions artifacts"},{...B.viewSessionArtifact,command:"sessions artifacts get"},{...B.createReview,command:"review <pr-url>"},{...B.getReviewRequest,command:"review <pr-url>"},{...B.getReviewRequest,command:"reviews get"},{...B.getReviewRequestStatuses,command:"reviews get"},{...B.createLocalReview,command:"review"},{...B.getLocalReview,command:"review --request"},{...B.getRepositoryOnboarding,command:"environments status"},{...B.prepareRepository,command:"environments prepare"},{...B.retryRepositoryOnboarding,command:"environments retry"},{...B.listEnvironments,command:"environments login"},{...B.getEnvironment,command:"environments login"},{...B.updateEnvironment,command:"environments login --validate-path"},{...B.listEnvironments,command:"environments export"},{...B.getEnvironment,command:"environments export"},{...B.listEnvironments,command:"environments import"},{...B.getEnvironment,command:"environments import"},{...B.updateEnvironment,command:"environments import"},{...B.createEnvironment,command:"environments import --create"},{...B.getEnvironmentBrowserState,command:"environments login"},{...B.setEnvironmentBrowserState,command:"environments login"},{...B.deleteEnvironmentBrowserState,command:"environments login --clear"}];import{createHash as cm}from"node:crypto";import{existsSync as On,mkdirSync as Db,readFileSync as La,statSync as Ub}from"node:fs";import{homedir as zb}from"node:os";import{dirname as lm,join as yt,resolve as Lb}from"node:path";import{randomUUID as Pb}from"node:crypto";import{renameSync as Cb,rmSync as Ob,writeFileSync as Nb}from"node:fs";function _t(e,t){let r=`${e}.${Pb()}.tmp`;try{Nb(r,JSON.stringify(t,null,2)+`
6
6
  `,{mode:384,flag:"wx"}),Cb(r,e)}finally{Ob(r,{force:!0})}}var Mb=/\r?\n/,jb=/^\[|\]$/g,dm=yt(zb(),".arcanist"),pm=yt(dm,"config.json"),rt=".arcanist-cli.json",Zb="https://app.tryarcanist.com";function Ma(){try{return JSON.parse(La(pm,"utf-8"))}catch{return null}}function Nn(e={}){let t=Fb(e);if(t)return um(t);let r=ja(),o=Za(e,r!==null),n=Ma(),i=o?.apiUrl??r?.apiUrl??n?.apiUrl,a=r&&n?.apiUrl===r.apiUrl&&n.token&&n.supersededProjectTokenHash===cm("sha256").update(r.token).digest("hex")?n.token:r?.token,s=o?.token??a??n?.token;if(!i||!s)return null;let u=um({apiUrl:i,token:s});return r&&!o&&!e.json&&process.stderr.write(`using ${rt} -> ${u.apiUrl}
7
7
  `),u}function Qr(e,t){let r=ti(e.apiUrl);if(r)throw new y("user",r);Db(dm,{recursive:!0,mode:448});let o=tt(e.apiUrl),n=Ma(),i=t?cm("sha256").update(t).digest("hex"):n?.apiUrl===o?n.supersededProjectTokenHash:void 0,a={...e,apiUrl:o,...i?{supersededProjectTokenHash:i}:{}};_t(pm,a)}function _e(e){let t=Nn(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??Ma()?.apiUrl??Zb,r=ti(t);if(r)throw new y("user",r);return tt(t)}function ja(e=process.cwd()){let t=Bb(e);if(!t)return null;let r=e;for(;;){let o=yt(r,rt);if(On(o))return qb(o);if(r===t)return null;let n=lm(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:"&&!mm(t)?"API URL must use HTTPS for non-local hosts":null}function Za(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",`${rt} 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 Fb(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 um(e){let t=ti(e.apiUrl);if(t)throw new y("user",t);return{apiUrl:tt(e.apiUrl),token:e.token}}function Bb(e){let t=e;for(;;){if(Vb(t))return t;let r=lm(t);if(r===t)return null;t=r}}function Vb(e){let t=yt(e,".git");if(!On(t))return!1;try{let r=Ub(t);if(r.isDirectory())return On(yt(t,"HEAD"))&&On(yt(t,"config"));if(!r.isFile())return!1;let o=Gb(t);return o?On(yt(Lb(e,o),"HEAD")):!1}catch{return!1}}function Gb(e){let t=La(e,"utf-8").split(Mb).find(o=>o.startsWith("gitdir:"));return t&&t.slice(7).trim()||null}function qb(e){let t;try{t=JSON.parse(La(e,"utf-8"))}catch{throw new y("user",`${rt} is not valid JSON.`)}if(!t||typeof t!="object")throw new y("user",`${rt} 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",`${rt} must contain both apiUrl and token.`);let o;try{o=new URL(r.apiUrl)}catch{throw new y("user",`${rt} apiUrl must be a valid URL.`)}if(!mm(o))throw new y("user",`${rt} apiUrl must be a loopback host.`);let n=ti(r.apiUrl);if(n)throw new y("user",n);return{apiUrl:tt(r.apiUrl),token:r.token}}function mm(e){let t=e.hostname.replace(jb,"");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 Ee(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(Ee(e,t)){qe(r);return}o(r)}function X(e,t={}){let r=ee(e,t);return{runtime:r,config:_e(r)}}async function Wb(){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 Dn(){return(await Wb()).trim()}function fm(e){(e.noColor===!0||!process.stdout.isTTY)&&(process.env.NO_COLOR="1")}var Hb=/\u001b\][^\u0007]*(?:\u0007|\u001b\\)/g,Kb=/\u001b\[[0-?]*[ -\/]*[@-~]/g,Jb=/[\u0000-\u001f\u007f]/g,Yb=/\r?\n/;function O(e){return e.replace(Hb,"").replace(Kb,"").replace(Jb,"")}function De(e){return e.split(Yb).map(O).join(`
@@ -125,7 +125,7 @@ ${e.answer?`**Answer:** ${e.answer}
125
125
  `);continue}let Ae=ka(ne,f);if(Ae){if(Ae.kind==="text"){if(!Ae.text)continue;_||(process.stdout.write("assistant> "),_=!0),process.stdout.write(Ae.text);continue}_&&(process.stdout.write(`
126
126
  `),_=!1),console.log(Ae.line)}}if(F){Kr(c);continue}if(j.status?.phase&&d_(j.status.phase)){!l&&j.status.phase==="completed"&&(_&&(process.stdout.write(`
127
127
  `),_=!1),await lR(n,e));break}Kr(c);let Q=Jy(c);await Jr(Q===void 0?i:Math.min(i,Q)),Kr(c)}}finally{_&&process.stdout.write(`
128
- `)}}async function Xy(e,t){let r=ee(t,e),o=_e(r),{items:n,nextCursor:i}=await Uy("sessions list --all",e.all===!0,e.cursor,async s=>{let u=new URLSearchParams;e.status&&u.set("status",e.status),e.scope&&u.set("scope",e.scope),e.search&&u.set("q",e.search),e.repo&&u.set("repo",e.repo),e.limit&&u.set("limit",e.limit),s&&u.set("cursor",s);let c=await R(o,`${A("/api/sessions")}${u.size?`?${u.toString()}`:""}`);return{items:c.sessions,nextCursor:c.nextCursor}}),a={sessions:n,nextCursor:i};if(Ee(t,e)){qe(a);return}if(a.sessions.length===0){console.log("No sessions found.");return}for(let s of a.sessions){let u=O(String(s.id??s.sessionId??"")),c=O(String(s.status??"")),l=typeof s.title=="string"?` ${O(s.title)}`:"";console.log(`${u} ${c}${l}`)}a.nextCursor&&console.log(`Next cursor: ${O(a.nextCursor)}`)}async function Qy(e,t,r){let o=ee(r,t),n=_e(o),i=await R(n,A("/api/sessions/:sessionId",{sessionId:e}));if(Ee(r,t)){qe(i);return}let a=i.session&&typeof i.session=="object"&&!Array.isArray(i.session)?i.session:i;console.log(`Session: ${O(String(a.sessionId??a.id??e))}`),console.log(`Status: ${O(String(a.phase??a.status??"unknown"))}`),a.repoUrl&&console.log(`Repo: ${O(String(a.repoUrl))}`),a.title&&console.log(`Title: ${O(String(a.title))}`);let s=Vy(a);s&&console.log(O(s))}async function eb(e,t,r){let o=ee(r,t),n=_e(o),i=await R(n,`${A("/api/sessions/:sessionId/view",{sessionId:e})}?promptLimit=1`);U(r,o,i,a=>{o.quiet||console.log(De(JSON.stringify(a,null,2)))})}async function tb(e,t,r){let o=t.afterSequence,n=t.beforeSequence;if(t.follow){if(n)throw new y("user","--before-sequence cannot be used with --follow.");if(t.promptId)throw new y("user","--prompt-id cannot be used with --follow because the follow endpoint does not support prompt filtering.");await Yy(e,{...t,pollInterval:t.pollInterval,afterSequence:o,limit:t.limit},r);return}let i=ee(r,t),a=_e(i),s=new URLSearchParams;o&&s.set("after_sequence",o),n&&s.set("before_sequence",n),t.promptId&&s.set("prompt_id",t.promptId),t.limit&&s.set("limit",t.limit);let u=await R(a,`${A("/api/sessions/:sessionId/events/history",{sessionId:e})}${s.size?`?${s.toString()}`:""}`);if(Ee(r,t)){qe(u);return}let l={promptLabels:await Vp(a,e).catch(f=>(console.error(`Warning: failed to fetch prompt labels for session ${e}: ${$e(f)}`),new Map)),toolCalls:new Map},d=!1;for(let f of u.events){let p=ka({type:Pn(f),data:Lp(f)??{}},l);p?.kind==="line"&&(d&&(process.stdout.write(`
128
+ `)}}async function Xy(e,t){let r=ee(t,e),o=_e(r),{items:n,nextCursor:i}=await Uy("sessions list --all",e.all===!0,e.cursor,async s=>{let u=new URLSearchParams;e.status&&u.set("status",e.status),e.scope&&u.set("scope",e.scope),e.scope==="business"&&u.set("includeSelf","true"),e.search&&u.set("q",e.search),e.repo&&u.set("repo",e.repo),e.limit&&u.set("limit",e.limit),s&&u.set("cursor",s);let c=await R(o,`${A("/api/sessions")}${u.size?`?${u.toString()}`:""}`);return{items:c.sessions,nextCursor:c.nextCursor}}),a={sessions:n,nextCursor:i};if(Ee(t,e)){qe(a);return}if(a.sessions.length===0){console.log("No sessions found.");return}for(let s of a.sessions){let u=O(String(s.id??s.sessionId??"")),c=O(String(s.status??"")),l=typeof s.title=="string"?` ${O(s.title)}`:"";console.log(`${u} ${c}${l}`)}a.nextCursor&&console.log(`Next cursor: ${O(a.nextCursor)}`)}async function Qy(e,t,r){let o=ee(r,t),n=_e(o),i=await R(n,A("/api/sessions/:sessionId",{sessionId:e}));if(Ee(r,t)){qe(i);return}let a=i.session&&typeof i.session=="object"&&!Array.isArray(i.session)?i.session:i;console.log(`Session: ${O(String(a.sessionId??a.id??e))}`),console.log(`Status: ${O(String(a.phase??a.status??"unknown"))}`),a.repoUrl&&console.log(`Repo: ${O(String(a.repoUrl))}`),a.title&&console.log(`Title: ${O(String(a.title))}`);let s=Vy(a);s&&console.log(O(s))}async function eb(e,t,r){let o=ee(r,t),n=_e(o),i=await R(n,`${A("/api/sessions/:sessionId/view",{sessionId:e})}?promptLimit=1`);U(r,o,i,a=>{o.quiet||console.log(De(JSON.stringify(a,null,2)))})}async function tb(e,t,r){let o=t.afterSequence,n=t.beforeSequence;if(t.follow){if(n)throw new y("user","--before-sequence cannot be used with --follow.");if(t.promptId)throw new y("user","--prompt-id cannot be used with --follow because the follow endpoint does not support prompt filtering.");await Yy(e,{...t,pollInterval:t.pollInterval,afterSequence:o,limit:t.limit},r);return}let i=ee(r,t),a=_e(i),s=new URLSearchParams;o&&s.set("after_sequence",o),n&&s.set("before_sequence",n),t.promptId&&s.set("prompt_id",t.promptId),t.limit&&s.set("limit",t.limit);let u=await R(a,`${A("/api/sessions/:sessionId/events/history",{sessionId:e})}${s.size?`?${s.toString()}`:""}`);if(Ee(r,t)){qe(u);return}let l={promptLabels:await Vp(a,e).catch(f=>(console.error(`Warning: failed to fetch prompt labels for session ${e}: ${$e(f)}`),new Map)),toolCalls:new Map},d=!1;for(let f of u.events){let p=ka({type:Pn(f),data:Lp(f)??{}},l);p?.kind==="line"&&(d&&(process.stdout.write(`
129
129
  `),d=!1),console.log(p.line)),p?.kind==="text"&&p.text&&(process.stdout.write(p.text),d=!0)}d&&process.stdout.write(`
130
130
  `)}import{execFile as dR}from"node:child_process";import{constants as pR}from"node:fs";import{access as mR}from"node:fs/promises";import{basename as fR,delimiter as gR,join as Gp,resolve as Ta}from"node:path";import{promisify as hR}from"node:util";var Aa=hR(dR);async function nb(e,t,r){let o=ee(r,t),n=process.env.npm_execpath,i=n&&fR(n)==="npm-cli.js"?process.execPath:"npm",a=i===process.execPath?[n]:[],s={shell:process.platform==="win32"&&i==="npm"},u=`@tryarcanist/cli@${nt}`,c;try{c=(await Aa(i,[...a,"prefix","--global"],s)).stdout.trim()}catch{throw new y("user","Could not find npm's global install directory.",{hint:"Install Node.js 22 or newer with npm, then run setup again."})}let l=process.platform==="win32",d=Gp(c,...l?[]:["lib"],"node_modules/@tryarcanist/cli/dist/index.js"),f;try{f=(await Aa(process.execPath,[d,"--version"])).stdout.trim()}catch{}if(f!==nt){!o.json&&!o.quiet&&process.stderr.write(`Installing Arcanist for future reviews\u2026
131
131
  `);try{await Aa(i,[...a,"install","--global",u,"--no-fund","--no-audit"],s)}catch{throw new y("user","Could not install the Arcanist CLI globally.",{hint:`Run npm install --global ${u} to see npm's error. Use a writable npm prefix, then run setup again.`})}try{f=(await Aa(process.execPath,[d,"--version"])).stdout.trim()}catch{throw new y("user","Arcanist was installed, but the installed command could not start.",{hint:`Run npm install --global ${u}, then run setup again.`})}if(f!==nt)throw new y("user","The installed Arcanist version does not match this setup command.",{hint:`Run npm install --global ${u}, then run setup again.`})}let p=l?c:Gp(c,"bin");try{await mR(Gp(p,l?"arcanist.cmd":"arcanist"),pR.X_OK)}catch{throw new y("user","Arcanist is installed, but npm did not create an executable command.",{hint:`Run npm install --global ${u} --bin-links, then run setup again.`})}if(!((l?process.env.Path??process.env.PATH:process.env.PATH)??"").split(gR).some(_=>l?Ta(_).toLowerCase()===Ta(p).toLowerCase():Ta(_)===Ta(p)))throw new y("user","Arcanist is installed, but its directory is not on PATH.",{hint:l?`Add ${p} to your user PATH, open a new terminal, then run arcanist onboard.`:`Run export PATH=${Qe(p)}:"$PATH", add it to your shell profile, then run arcanist onboard.`});!o.json&&!o.quiet&&process.stderr.write(`Arcanist is installed. After setup, run arcanist review.
@@ -214,7 +214,7 @@ Examples:
214
214
 
215
215
  JSON: the complete existing session-view envelope, including runtime, review, and credential metadata.
216
216
  Prompts form the first page only (promptLimit=1). Use sessions transcript for full activity and sessions artifacts for files.
217
- `).action((s,u,c)=>eb(s,u,c)),r.command("list").description("List sessions").option("--status <status>","Filter by session status").option("--scope <scope>","Session scope: mine or business").option("--search <query>","Search session titles and repo metadata").option("--repo <repo>","Filter by repo metadata").option("--limit <n>","Maximum sessions to return").option("--cursor <cursor>","Pagination cursor").option("--all","Fetch all pages").addHelpText("after",`
217
+ `).action((s,u,c)=>eb(s,u,c)),r.command("list").description("List sessions").option("--status <status>","Filter by session status").option("--scope <scope>","Session scope: mine (default) or business (every session in your workspace, yours included)").option("--search <query>","Search session titles and repo metadata").option("--repo <repo>","Filter by repo metadata").option("--limit <n>","Maximum sessions to return").option("--cursor <cursor>","Pagination cursor").option("--all","Fetch all pages").addHelpText("after",`
218
218
  Examples:
219
219
  arcanist sessions list
220
220
  arcanist sessions list --status idle --json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryarcanist/cli",
3
- "version": "0.1.468",
3
+ "version": "0.1.470",
4
4
  "description": "Command-line interface for Arcanist: inspect sessions, prepare Arcanist environments, and trigger reviews",
5
5
  "type": "module",
6
6
  "bin": {