@commonlyai/cli 0.1.295 → 0.1.296

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.
@@ -145,6 +145,11 @@ export const keptRefusalDetail = (raw, { credentials = [] } = {}) => {
145
145
  * the ladder has finished — so it wins over the per-attempt `message_end`
146
146
  * events that precede it. A run that refused on its first attempt and never
147
147
  * retried still reports through `message_end`.
148
+ *
149
+ * A retry that answered ends the refusal. pi prints `auto_retry_end` with
150
+ * `success: true` once a retried call answers (agent-session.js, pi 0.84.1), so
151
+ * a refusal before it is one pi recovered from. Kept, it would name the cause
152
+ * of a later failure that has none of its own, such as `fetch failed` (F320).
148
153
  */
149
154
  export const readUpstreamRefusal = (stdout, { credentials = [] } = {}) => {
150
155
  let status = null;
@@ -159,6 +164,16 @@ export const readUpstreamRefusal = (stdout, { credentials = [] } = {}) => {
159
164
  continue;
160
165
  }
161
166
 
167
+ // A compaction that continues the turn is pi recovering from an overflow,
168
+ // so a refusal before it is one pi recovered from too. The turn's own cause
169
+ // comes after (agent-session.js `compaction_end`, pi 0.84.1).
170
+ if ((event?.type === 'auto_retry_end' && event.success === true)
171
+ || (event?.type === 'compaction_end' && event.aborted === false && event.willRetry === true)) {
172
+ status = null;
173
+ raw = null;
174
+ continue;
175
+ }
176
+
162
177
  if (event?.type === 'auto_retry_end' && event.success === false) {
163
178
  const candidate = event.finalError ?? event.errorMessage;
164
179
  const attemptStatus = statusFromError(candidate);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.295",
3
+ "version": "0.1.296",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -533,12 +533,16 @@ export const buildArgs = ({
533
533
  * after an assistant message that stopped with `stop`. An overflow's `agent_end`
534
534
  * says `willRetry: false` and then pi compacts and continues, so `agent_end` after
535
535
  * an `error` or `length` stop doesn't count; the continuation's message decides.
536
+ * `lastError` is that last message's `errorMessage`, pi's cause for an `error`
537
+ * stop (`Provider finish_reason: content_filter`, `fetch failed`). It is raw
538
+ * provider text, so only adapterFailure's scrub may carry it anywhere.
536
539
  */
537
540
  export const extractReply = (stdout) => {
538
541
  let text = '';
539
542
  let sawAssistant = false;
540
543
  let finished = false;
541
544
  let lastStop = null;
545
+ let lastError;
542
546
  const errors = [];
543
547
  for (const line of String(stdout).split('\n')) {
544
548
  if (!line.trim()) continue;
@@ -548,12 +552,15 @@ export const extractReply = (stdout) => {
548
552
  const parts = (event.message.content || []).filter((c) => c?.type === 'text').map((c) => c.text || '');
549
553
  if (parts.length) { text = parts.join('\n').trim(); sawAssistant = true; }
550
554
  lastStop = event.message.stopReason;
555
+ lastError = typeof event.message.errorMessage === 'string' ? event.message.errorMessage : undefined;
551
556
  finished = false;
552
557
  }
553
558
  if (event?.type === 'agent_end') finished = event.willRetry !== true && lastStop === 'stop';
554
559
  if (event?.type === 'error') errors.push(String(event.message || event.error || 'error'));
555
560
  }
556
- return { text, sawAssistant, finished, lastStop, errors };
561
+ return {
562
+ text, sawAssistant, finished, lastStop, lastError, errors,
563
+ };
557
564
  };
558
565
 
559
566
  // A turn that printed an interim message and then ended without finishing. A
@@ -562,6 +569,10 @@ export const extractReply = (stdout) => {
562
569
  // holds pi's startup warnings, and a refusal on the stream may be one pi was
563
570
  // recovering from, like an overflow's 400. A clean exit that ended on an error
564
571
  // has only the stream: its stderr is those warnings too, and the refusal stands.
572
+ // A stop with no status still has the cause pi gave it, and without it a content
573
+ // filter's stop classes as a runtime fault and is retried in seconds (F320).
574
+ // The status is pi's on a clean exit, not one the kept detail mentions: that
575
+ // detail is the provider's prose, and "proxy said status 503" on a 429 is 429.
565
576
  const stoppedTurnFailure = (reply, {
566
577
  code, signal, stderr, credentials,
567
578
  }) => {
@@ -574,10 +585,12 @@ const stoppedTurnFailure = (reply, {
574
585
  || (cleanExit ? describeUpstreamRefusal(upstream) : '')
575
586
  || (killed || cleanExit ? '' : stderr.trim().slice(-600))
576
587
  || upstream?.detail
588
+ || (killed || reply.lastStop !== 'error' ? '' : reply.lastError)
577
589
  || 'the turn stopped before it finished',
578
590
  { credentials, exitCode: code, limit: 600 },
579
591
  );
580
- if (upstream) failure.status ??= upstream.status;
592
+ if (upstream && cleanExit) failure.status = upstream.status;
593
+ else if (upstream) failure.status ??= upstream.status;
581
594
  return failure;
582
595
  };
583
596
 
@@ -75,6 +75,11 @@ export const SPAWN_RETRY_JITTER_MAX_RATIO = 0.2;
75
75
  // nothing else until the kernel retired the event. Only the refusal wordings
76
76
  // themselves are matched, so an ordinary failure that mentions a flag is not.
77
77
  const CONTENT_REFUSED_RE = /(?:flagged for possible cybersecurity risk|this content was flagged|content[_ ]policy[_ ]violation|cyber[_ ]policy)/i;
78
+ // pi writes its own line for a provider's content stop (pi-ai 0.84.1:
79
+ // openai-completions.js, anthropic-messages.js) as the whole errorMessage, so
80
+ // only the pi failure that IS that line matches. Anywhere else the wording is
81
+ // text someone wrote, such as a seat quoting this file, and a match is terminal.
82
+ const PI_CONTENT_STOP_RE = /^pi exited with code \d+(?: \(upstream \d+\))?: Provider (?:finish_reason: content_filter|stopped with: sensitive)$/;
78
83
  // The third miss is why there is now a PHRASE as well as a word list, and it is
79
84
  // a different failure from the first two. Measured across the fleet's logs on
80
85
  // 2026-08-25: 283 failures reading "You've hit your weekly limit", 55 reading
@@ -153,7 +158,9 @@ export const classifySpawnFailure = (error) => {
153
158
  if (error?.code === PUBLIC_CODEX_VERSION_CODE) return SPAWN_FAILURE_CLASS.CONFIGURATION;
154
159
  // First: the refusal text carries none of the words below today, but a
155
160
  // refusal must never be read as a transient condition and retried.
156
- if (CONTENT_REFUSED_RE.test(text)) return SPAWN_FAILURE_CLASS.CONTENT_REFUSED;
161
+ if (CONTENT_REFUSED_RE.test(text) || PI_CONTENT_STOP_RE.test(String(error?.message || '').trim())) {
162
+ return SPAWN_FAILURE_CLASS.CONTENT_REFUSED;
163
+ }
157
164
  if (error?.code === 'spawn_stalled') return SPAWN_FAILURE_CLASS.STALLED;
158
165
  // Provider APIs commonly report an exhausted account quota as HTTP 429.
159
166
  // Prefer the more specific body/message over the generic status code so a
@@ -42,9 +42,11 @@ const WONT_START_WORDINGS = [
42
42
  // The vendors' credit wordings open at the adapter's own label or the claude
43
43
  // adapter's stderr | stdout join, because any `: ` or status number can open a
44
44
  // log line. An unknown label stays silent. `upstream refused` is the line the run
45
- // loop builds for pi. The transports are how a CLI wraps a refusal it keeps whole.
45
+ // loop builds for pi, and the pi adapter puts its label before it when a refused
46
+ // turn exits 0 after an interim message (F320). The transports are how a CLI
47
+ // wraps a refusal it keeps whole.
46
48
  const ADAPTER_LABEL = String.raw`(?:claude|codex|pi|opencode|goose|qwen|dsh|Hermes)(?: turn failed)?(?: exited(?: with code)? \d+)?(?: \(upstream \d{3}\))?`;
47
- const OWN_LEAD = String.raw`(?:^(?:${ADAPTER_LABEL}|upstream refused \d{3}): | \| )`;
49
+ const OWN_LEAD = String.raw`(?:^(?:${ADAPTER_LABEL}(?:: upstream refused \d{3})?|upstream refused \d{3}): | \| )`;
48
50
  const TRANSPORT = String.raw`(?:unexpected status \d{3}[^:\n]*: |API Error: \d{3} |Error code: \d{3} - |Error running remote compact task: )*`;
49
51
  const OPENAI_CODE = '(?:insufficient_quota|credit_balance_exhausted)';
50
52
  const ownWording = (wording) => new RegExp(`${OWN_LEAD}${TRANSPORT}${wording}`);