@tryarcanist/cli 0.1.195 → 0.1.196

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 +45 -51
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -17,6 +17,36 @@ function normalizeBaseUrl(url) {
17
17
  return url.replace(/\/+$/, "");
18
18
  }
19
19
 
20
+ // src/utils/api-error.ts
21
+ function parseApiErrorBody(body) {
22
+ try {
23
+ const parsed = JSON.parse(body);
24
+ if (!parsed || typeof parsed !== "object") return null;
25
+ const record = parsed;
26
+ const topLevelMessage = typeof record.message === "string" && record.message ? record.message : void 0;
27
+ if (typeof record.error === "string" && record.error) {
28
+ return {
29
+ serverCode: typeof record.code === "string" && record.code ? record.code : record.error,
30
+ rawError: record.error,
31
+ message: topLevelMessage ?? record.error
32
+ };
33
+ }
34
+ if (record.error && typeof record.error === "object") {
35
+ const error = record.error;
36
+ const message = typeof error.message === "string" && error.message ? error.message : topLevelMessage;
37
+ const serverCode = typeof error.code === "string" && error.code ? error.code : void 0;
38
+ return message || serverCode ? {
39
+ ...message ? { message } : {},
40
+ ...serverCode ? { serverCode } : {},
41
+ ...serverCode ? { rawError: serverCode } : {}
42
+ } : null;
43
+ }
44
+ return topLevelMessage ? { message: topLevelMessage } : null;
45
+ } catch {
46
+ return null;
47
+ }
48
+ }
49
+
20
50
  // src/errors.ts
21
51
  var EXIT_CODE_INTERRUPTED = 130;
22
52
  var CliError = class extends Error {
@@ -82,33 +112,6 @@ function messageForApiError(status, body, parsed = parseApiErrorBody(body)) {
82
112
  if (parsed?.serverCode) return parsed.serverCode;
83
113
  return body ? `API error ${status}: ${body}` : `API error ${status}`;
84
114
  }
85
- function parseApiErrorBody(body) {
86
- try {
87
- const parsed = JSON.parse(body);
88
- if (!parsed || typeof parsed !== "object") return null;
89
- const error = parsed.error;
90
- if (typeof error === "string" && error.length > 0) {
91
- const message2 = parsed.message;
92
- const code = parsed.code;
93
- return {
94
- serverCode: typeof code === "string" && code ? code : error,
95
- ...typeof message2 === "string" && message2 ? { message: message2 } : { message: error }
96
- };
97
- }
98
- if (error && typeof error === "object") {
99
- const code = error.code;
100
- const message2 = error.message;
101
- return {
102
- ...typeof message2 === "string" && message2 ? { message: message2 } : {},
103
- ...typeof code === "string" && code ? { serverCode: code } : {}
104
- };
105
- }
106
- const message = parsed.message;
107
- return typeof message === "string" && message.length > 0 ? { message } : null;
108
- } catch {
109
- return null;
110
- }
111
- }
112
115
  function hintForHttpStatus(status, resourceNoun) {
113
116
  if (status === 401 || status === 403) return "Run `arcanist auth login` or set `ARCANIST_TOKEN`.";
114
117
  if (status === 404) {
@@ -1206,27 +1209,14 @@ function mapAutomationApiError(err) {
1206
1209
  if (!(err instanceof ApiError)) {
1207
1210
  return err instanceof CliError ? err : new CliError("server", stringifyError(err));
1208
1211
  }
1209
- const parsed = parseApiErrorBody2(err.body);
1210
- const serverCode = parsed?.error;
1212
+ const parsed = parseApiErrorBody(err.body);
1213
+ const serverCode = parsed?.rawError ?? parsed?.serverCode;
1211
1214
  return new CliError(codeForHttpStatus(err.status), parsed?.message || serverCode || err.message, {
1212
1215
  exitCode: err.exitCode,
1213
1216
  hint: serverCode ? AUTOMATION_ERROR_HINTS[serverCode] : void 0,
1214
1217
  requestId: err.requestId
1215
1218
  });
1216
1219
  }
1217
- function parseApiErrorBody2(body) {
1218
- try {
1219
- const parsed = JSON.parse(body);
1220
- if (!parsed || typeof parsed !== "object") return null;
1221
- const record = parsed;
1222
- return {
1223
- error: typeof record.error === "string" ? record.error : void 0,
1224
- message: typeof record.message === "string" ? record.message : void 0
1225
- };
1226
- } catch {
1227
- return null;
1228
- }
1229
- }
1230
1220
  function printAutomationRule(rule) {
1231
1221
  console.log(`ID: ${rule.id}`);
1232
1222
  console.log(`Repo: ${rule.repoOwner}/${rule.repoName}`);
@@ -1578,6 +1568,11 @@ function normalizeUploadedFileOptions(files) {
1578
1568
  return Array.isArray(files) ? files : [files];
1579
1569
  }
1580
1570
 
1571
+ // src/utils/poll-interval.ts
1572
+ function clampPollInterval(ms, minimum) {
1573
+ return Math.max(ms, minimum);
1574
+ }
1575
+
1581
1576
  // ../../shared/session/no-change-outcome.ts
1582
1577
  function isNoChangesPromptResult(result) {
1583
1578
  return typeof result === "object" && result !== null && "noChanges" in result && result.noChanges === true;
@@ -3003,6 +2998,11 @@ function renderWatchEvent(event, state) {
3003
2998
  }
3004
2999
  }
3005
3000
 
3001
+ // src/utils/session-payload.ts
3002
+ function unwrapSessionState(payload) {
3003
+ return payload.session && typeof payload.session === "object" ? payload.session : payload;
3004
+ }
3005
+
3006
3006
  // src/commands/model-options.ts
3007
3007
  function resolveModelAndBackend(options) {
3008
3008
  let agentRuntimeBackend = CODEX_AGENT_RUNTIME_BACKEND;
@@ -3246,7 +3246,7 @@ async function fetchCreatedPromptStatus(config, sessionId, promptId) {
3246
3246
  return selectCreatedPrompt(promptList.prompts, promptId);
3247
3247
  }
3248
3248
  async function waitForCreatedPromptToSettle(config, sessionId, promptId, pollIntervalMs) {
3249
- const effectivePollIntervalMs = Math.max(pollIntervalMs, MIN_WATCH_POLL_INTERVAL_MS);
3249
+ const effectivePollIntervalMs = clampPollInterval(pollIntervalMs, MIN_WATCH_POLL_INTERVAL_MS);
3250
3250
  while (true) {
3251
3251
  const createdPrompt = await fetchCreatedPromptStatus(config, sessionId, promptId);
3252
3252
  if (createdPrompt && PROMPT_TERMINAL_STATUSES.has(createdPrompt.status)) {
@@ -3288,15 +3288,12 @@ async function waitForCreatedPrompt(sessionId, promptId, sessionUrl, pollInterva
3288
3288
  );
3289
3289
  }
3290
3290
  }
3291
- function unwrapSessionState(payload) {
3292
- return payload.session && typeof payload.session === "object" ? payload.session : payload;
3293
- }
3294
3291
  async function fetchSessionResultFields(config, sessionId) {
3295
3292
  const sessionPayload = await apiFetch(config, `/api/sessions/${sessionId}`);
3296
3293
  return extractSessionResultFields(unwrapSessionState(sessionPayload));
3297
3294
  }
3298
3295
  async function fetchSettledSessionResultFields(config, sessionId, pollIntervalMs) {
3299
- const effectivePollIntervalMs = Math.max(pollIntervalMs, MIN_WATCH_POLL_INTERVAL_MS);
3296
+ const effectivePollIntervalMs = clampPollInterval(pollIntervalMs, MIN_WATCH_POLL_INTERVAL_MS);
3300
3297
  let latest = {};
3301
3298
  for (let attempt = 0; attempt < RESULT_FETCH_ATTEMPTS; attempt++) {
3302
3299
  latest = await fetchSessionResultFields(config, sessionId);
@@ -3607,9 +3604,6 @@ async function loginCommand(options, command) {
3607
3604
  }
3608
3605
 
3609
3606
  // src/commands/message.ts
3610
- function unwrapSessionState2(payload) {
3611
- return payload.session && typeof payload.session === "object" ? payload.session : payload;
3612
- }
3613
3607
  async function messageCommand(sessionId, promptArg, options = {}, command) {
3614
3608
  const runtime = getRuntimeOptions(command, options);
3615
3609
  assertArcanistSessionMutationAllowed("send");
@@ -3641,7 +3635,7 @@ async function messageCommand(sessionId, promptArg, options = {}, command) {
3641
3635
  }
3642
3636
  try {
3643
3637
  const sessionPayload = await apiFetch(config, `/api/sessions/${sessionId}`);
3644
- const resultLine = formatSessionResult(unwrapSessionState2(sessionPayload));
3638
+ const resultLine = formatSessionResult(unwrapSessionState(sessionPayload));
3645
3639
  if (resultLine) console.log(resultLine);
3646
3640
  } catch {
3647
3641
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryarcanist/cli",
3
- "version": "0.1.195",
3
+ "version": "0.1.196",
4
4
  "description": "CLI for Arcanist — create and manage coding agent sessions",
5
5
  "type": "module",
6
6
  "bin": {