@commonlyai/cli 0.1.411 → 0.1.412

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.411",
3
+ "version": "0.1.412",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -53,6 +53,7 @@ import {
53
53
  wasEventHandled,
54
54
  recordHandledEvent,
55
55
  noticeDue,
56
+ noticeRecordedAt,
56
57
  recordNotice,
57
58
  } from '../lib/session-store.js';
58
59
  import {
@@ -184,6 +185,8 @@ import {
184
185
  CLAUDE_SIGNED_OUT_FIX,
185
186
  CUT_OFF_NOTICE,
186
187
  cantAnswerNotice,
188
+ cantAnswerNoticeDue,
189
+ newestMessageAt,
187
190
  claudeSignedOutResult,
188
191
  isClaudeSignedOut,
189
192
  spawnFailureReason,
@@ -3075,23 +3078,34 @@ export const performRun = ({
3075
3078
 
3076
3079
  // A failure only a person can fix, or only time can, leaves a mention
3077
3080
  // unanswered for as long as it lasts, so each pod with someone waiting is told
3078
- // why, at most once per cause per pod per hour (persisted, so a restart does
3079
- // not re-post). A later pod the failed turn stopped before reaching is told
3080
- // too: a key or an allowance fails every pod alike, and its own turn could be
3081
- // 45 minutes away. A notice that fails to post is logged and tried at the next
3082
- // failure; the retry goes ahead either way.
3081
+ // why, once per cause per pod per hour (persisted, so a restart does not
3082
+ // re-post), and again when a person writes after the last line (F689: one
3083
+ // "retry" met with silence was the end of a first try). A later pod the
3084
+ // failed turn stopped before reaching is told too: a key or an allowance
3085
+ // fails every pod alike, and its own turn could be 45 minutes away. A notice
3086
+ // that fails to post is logged and tried at the next failure; the retry goes
3087
+ // ahead either way.
3083
3088
  const noticeCantAnswer = async (error, waitingEvents) => {
3084
3089
  const notice = cantAnswerNotice(error);
3085
3090
  if (!notice || modelUnavailableFailure(error)) return;
3086
- const waitingPods = new Set(waitingEvents
3087
- .filter(someoneIsWaiting)
3091
+ const waiting = waitingEvents.filter(someoneIsWaiting);
3092
+ const waitingPods = new Set(waiting
3088
3093
  .map((event) => event.podId || podId)
3089
3094
  .filter(Boolean));
3090
3095
  for (const waitingPod of waitingPods) {
3091
3096
  const key = `cant-answer:${notice.cause}:${waitingPod}`;
3097
+ const seenKey = `${key}:seen`;
3098
+ const inPod = waiting.filter((event) => (event.podId || podId) === waitingPod);
3092
3099
  try {
3100
+ // Only an agent's or the kernel's own event is left out of the repeat:
3101
+ // an author the seat can't place may be a person (F689).
3102
+ const due = cantAnswerNoticeDue({
3103
+ lastNoticeAt: noticeRecordedAt(stateKey, key),
3104
+ seenThrough: noticeRecordedAt(stateKey, seenKey),
3105
+ waiting: inPod.filter((event) => !['agent', 'kernel'].includes(classifyTrigger(event))),
3106
+ });
3093
3107
  // eslint-disable-next-line no-continue
3094
- if (!noticeDue(stateKey, key, CANT_ANSWER_NOTICE_WINDOW_MS)) continue;
3108
+ if (!due) continue;
3095
3109
  // eslint-disable-next-line no-await-in-loop
3096
3110
  const delivery = await deliverChatReply({
3097
3111
  client,
@@ -3107,6 +3121,10 @@ export const performRun = ({
3107
3121
  + `${delivery.reason || 'the notice was not posted'}`);
3108
3122
  } else {
3109
3123
  recordNotice(stateKey, key);
3124
+ // The newest message this line was posted over, on the server's
3125
+ // clock, so the next "is anything new" never mixes the two clocks.
3126
+ const seenThrough = Math.max(...inPod.map(newestMessageAt).filter(Number.isFinite));
3127
+ if (Number.isFinite(seenThrough)) recordNotice(stateKey, seenKey, seenThrough);
3110
3128
  log(`[inbox.batch] told pod ${waitingPod} why this agent can't answer (${notice.cause})`);
3111
3129
  }
3112
3130
  } catch (noticeError) {
@@ -3884,7 +3902,7 @@ export const performRun = ({
3884
3902
  // log and the event ack; the kernel records the class.
3885
3903
  if (!delivered && upstream) {
3886
3904
  // pi exits 0 on a refused route, so no failure reaches the retry path.
3887
- await noticeCantAnswer(new Error(describeUpstreamRefusal(upstream)), [event]);
3905
+ await noticeCantAnswer(new Error(describeUpstreamRefusal(upstream)), event.turnEvents || [event]);
3888
3906
  return {
3889
3907
  outcome: 'no_action',
3890
3908
  refused: {
@@ -4752,6 +4770,9 @@ export const performRun = ({
4752
4770
  _id: `batch-${actionEntries[0].event._id}`,
4753
4771
  type: 'inbox.batch',
4754
4772
  commentTarget: commentTargetOf(actionEntries[0].event),
4773
+ // The events this turn carries, for a line that must judge each one: the
4774
+ // batch row borrows its first item's time (F689).
4775
+ turnEvents: entries.filter(inThisTurn).map((entry) => entry.event),
4755
4776
  payload: {
4756
4777
  ...actionEntries[0].event.payload,
4757
4778
  batchEventIds: entries.filter(inThisTurn).map((entry) => String(entry.event._id)),
@@ -6425,12 +6446,17 @@ Docs:
6425
6446
  // (and reported a missing one); it stops on a signed-out one too, and the
6426
6447
  // instance hears why, so the page and the pod can say it. A seat with a
6427
6448
  // saved record only warns: a probe that reads it wrong must not stop it.
6449
+ // F689: a first run also stops on a harness below the version its turns
6450
+ // need, which it used to start, then refuse every turn. A saved seat's
6451
+ // adapter warns at start instead, and its turns say so in the pod.
6428
6452
  const harnessProblems = await harnessFindings({
6429
6453
  adapterName: record.adapter,
6430
6454
  adapter: getAdapter(record.adapter),
6431
6455
  environment: record.environment,
6432
6456
  agentName: record.agentName,
6433
6457
  checkInstalled: !bootstrapped,
6458
+ checkVersion: bootstrapped,
6459
+ unconfined: opts.unsandboxed === true,
6434
6460
  });
6435
6461
  const harnessOutcome = preflightOutcome(harnessProblems, { firstRun: bootstrapped });
6436
6462
  for (const line of harnessOutcome.lines) console.error(`${stamp()} [${name}] ${line}`);
@@ -99,7 +99,7 @@ import {
99
99
  } from '../sandbox/guest-home.js';
100
100
  import {
101
101
  GUEST_CODEX, GUEST_HOME, GUEST_PATH, GUEST_WORKSPACE, buildMicrovmRunArgs, checkMicrovmAttach,
102
- ensureNoSeatVm, guestProxyBaseUrl, microvmSeatHome, microvmSeatLabel, msbHostEnv, prepareMicrovmHost,
102
+ ensureNoSeatVm, guestProxyBaseUrl, microvmFlagOn, microvmSeatHome, microvmSeatLabel, msbHostEnv, prepareMicrovmHost,
103
103
  refuseMicrovmMcpDeclarations,
104
104
  probeWhp, startMicrovmTurn, stopOrphanSeatMsb, withSeatLock, writeMicrovmTurn,
105
105
  } from '../sandbox/microsandbox.js';
@@ -2090,6 +2090,28 @@ export default {
2090
2090
  // exactly as spawn does. A Codex that can't be launched gives no notice here;
2091
2091
  // the run's detect() has already refused that. The probe is cached, so the
2092
2092
  // first turn doesn't ask again. `opts` carries spawn's version test seams.
2093
+ // F689: the version a first run's preflight stops on: one it read, below the
2094
+ // floor, for a seat the turn would refuse. Null for a tested version, for no
2095
+ // Codex at all (detect() refuses that run), and for a version it couldn't
2096
+ // read, which is left to the turn: a Codex that prints its version some new
2097
+ // way must not stop every first run before it starts. A Windows computer with
2098
+ // the microVM on runs a public seat on the guest's own Codex, and the first
2099
+ // run doesn't know yet whether its pod is public, so it isn't floored there.
2100
+ async versionShortfall({
2101
+ env = process.env, unconfined = false, platform = process.platform, ...opts
2102
+ } = {}) {
2103
+ if (unconfined || codexTrustedPerimeter(env)) return null;
2104
+ if (platform === 'win32' && microvmFlagOn(env)) return null;
2105
+ let version;
2106
+ try {
2107
+ version = await readCodexVersion(opts, env);
2108
+ } catch {
2109
+ return null;
2110
+ }
2111
+ if (!version || meetsMinimumVersion(version, PUBLIC_CODEX_MIN_VERSION)) return null;
2112
+ return { found: version, required: PUBLIC_CODEX_MIN_VERSION };
2113
+ },
2114
+
2093
2115
  async startNotice({ env = process.env, unconfined = false, ...opts } = {}) {
2094
2116
  if (unconfined || codexTrustedPerimeter(env)) return null;
2095
2117
  let version;
@@ -17,6 +17,9 @@ export const missingHarnessHint = (name) => {
17
17
  return `Install ${known.label} (${known.command}), sign in once by running ${known.signIn}, then run this line again.`;
18
18
  };
19
19
 
20
+ /** The install command, which also updates an installed harness; null when we have none. */
21
+ export const harnessUpdateCommand = (name) => INSTALL[name]?.command || null;
22
+
20
23
  /**
21
24
  * Tell the instance what this run looked for (a harness id, or null for none
22
25
  * of the ones it probes). Best effort: an older instance without the route, or
@@ -14,14 +14,14 @@ import { readFileSync } from 'fs';
14
14
 
15
15
  import { checkNode, FAIL } from './doctor.js';
16
16
  import { loginState } from './adapter-login.js';
17
- import { missingHarnessHint } from './missing-harness.js';
17
+ import { harnessUpdateCommand, missingHarnessHint } from './missing-harness.js';
18
18
  import { claudeLoginProbeLaunch, withClaudePath } from './adapters/claude.js';
19
19
  import { resolveWindowsCommandWithReason } from './windows-command.js';
20
20
 
21
21
  // The reason codes the instance accepts (POST /api/agents/runtime/listen-blocked).
22
22
  // A code, never text: nothing from this computer but the code is sent.
23
23
  export const LISTEN_BLOCKED_REASONS = [
24
- 'node-too-old', 'harness-signed-out', 'sandbox-unavailable', 'unsandboxed-refused',
24
+ 'node-too-old', 'harness-signed-out', 'sandbox-unavailable', 'unsandboxed-refused', 'harness-too-old',
25
25
  ];
26
26
 
27
27
  // F571: the two sandbox stops `agent run` makes once it has read the record,
@@ -119,11 +119,17 @@ export const runHarnessLoginStatus = async (name, args, {
119
119
  };
120
120
 
121
121
  /**
122
- * The harness findings for one adapter: not installed, or installed and not
123
- * signed in. `checkInstalled` is false where the caller has already looked (a
124
- * first run's bootstrap does, and reports it on its own route). A seat that
125
- * runs on its own provider block needs no harness login, and a key in the
126
- * environment is skipped by loginState itself.
122
+ * The harness findings for one adapter: not installed, below the version its
123
+ * turns need, or installed and not signed in. `checkInstalled` is false where
124
+ * the caller has already looked (a first run's bootstrap does, and reports it
125
+ * on its own route). A seat that runs on its own provider block needs no
126
+ * harness login, and a key in the environment is skipped by loginState itself.
127
+ *
128
+ * F689: a version floor binds every seat the turn would refuse, provider block
129
+ * or not, so it is read first. `unconfined` is a run typed --unsandboxed, which
130
+ * the adapter may not floor; it decides, and a probe that throws is no verdict.
131
+ * `checkVersion` is false for a seat with a saved record, whose adapter already
132
+ * warns at start (startNotice), so the warning isn't printed twice.
127
133
  */
128
134
  export const harnessFindings = async ({
129
135
  adapterName,
@@ -133,6 +139,8 @@ export const harnessFindings = async ({
133
139
  agentName = null,
134
140
  checkInstalled = true,
135
141
  env = process.env,
142
+ unconfined = false,
143
+ checkVersion = true,
136
144
  runStatus = (name, args) => runHarnessLoginStatus(name, args, { env, environment, agentName }),
137
145
  }) => {
138
146
  if (!adapter || !adapterName) return [];
@@ -147,10 +155,29 @@ export const harnessFindings = async ({
147
155
  }];
148
156
  }
149
157
  }
150
- if (environment?.provider !== undefined || !LABEL[adapterName]) return [];
158
+ const findings = [];
159
+ let shortfall = null;
160
+ try {
161
+ shortfall = checkVersion && typeof adapter.versionShortfall === 'function'
162
+ ? await adapter.versionShortfall({ env, unconfined })
163
+ : null;
164
+ } catch {
165
+ shortfall = null;
166
+ }
167
+ if (shortfall?.found && shortfall?.required) {
168
+ const label = LABEL[adapterName] || adapterName;
169
+ const update = harnessUpdateCommand(adapterName);
170
+ findings.push({
171
+ reason: 'harness-too-old',
172
+ harness: adapterName,
173
+ line: `This computer has ${label} ${shortfall.found}, and this agent needs ${label} ${shortfall.required} or later. `
174
+ + `Update it${update ? ` (${update})` : ''}, then run this line again.`,
175
+ });
176
+ }
177
+ if (environment?.provider !== undefined || !LABEL[adapterName]) return findings;
151
178
  const signedIn = await loginState(adapterName, { runStatus, env });
152
- if (signedIn !== false) return [];
153
- return [{
179
+ if (signedIn !== false) return findings;
180
+ return [...findings, {
154
181
  reason: 'harness-signed-out',
155
182
  harness: adapterName,
156
183
  line: `${LABEL[adapterName]} is installed but not signed in on this computer. `
@@ -186,6 +186,12 @@ export const noticeDue = (agentName, key, windowMs, now = Date.now()) => {
186
186
  return !Number.isFinite(last) || now - last >= windowMs || last > now;
187
187
  };
188
188
 
189
+ /** When `key` was last recorded, in ms; NaN when never. */
190
+ export const noticeRecordedAt = (agentName, key) => {
191
+ if (!agentName || !key) return NaN;
192
+ return Date.parse(readNotices(agentName)[key]);
193
+ };
194
+
189
195
  export const recordNotice = (agentName, key, now = Date.now()) => {
190
196
  if (!agentName || !key) return;
191
197
  const state = readNotices(agentName);
@@ -23,6 +23,46 @@ import { modelUnavailableFailure } from './model-unavailable.js';
23
23
  /** How long one cause stays posted in a pod before the seat may post it again. */
24
24
  export const CANT_ANSWER_NOTICE_WINDOW_MS = 60 * 60 * 1000;
25
25
 
26
+ /** Inside that hour, the least time between two posts for people who wrote again. */
27
+ export const CANT_ANSWER_REPEAT_MIN_MS = 2 * 60 * 1000;
28
+
29
+ /**
30
+ * The newest message an event carries, in ms on the server's clock: the row's
31
+ * own time, its message's, and any message the kernel joined to it later
32
+ * (`payload.coalesced`), which leaves the row's time alone. NaN when none reads.
33
+ */
34
+ export const newestMessageAt = (event) => {
35
+ const times = [event?.createdAt, event?.payload?.createdAt]
36
+ .concat((Array.isArray(event?.payload?.coalesced) ? event.payload.coalesced : []).map((entry) => entry?.createdAt))
37
+ .map((value) => Date.parse(value))
38
+ .filter(Number.isFinite);
39
+ return times.length ? Math.max(...times) : NaN;
40
+ };
41
+
42
+ /**
43
+ * F689: whether a pod is owed the can't-answer line now. Once an hour as
44
+ * before, and also when a person wrote again after the last line (`waiting`
45
+ * is that pod's events a person may have written), so a "retry" isn't met
46
+ * with silence. A retry of the same held messages isn't new, and a burst
47
+ * right after the line waits out the spacing, which runs on the seat's clock.
48
+ * "New" runs on the server's: after `seenThrough`, the newest message the
49
+ * last line was posted over, or after the line's own time on a record from
50
+ * before that was kept. An event whose time can't be read counts as new.
51
+ * `lastNoticeAt` is NaN when never told.
52
+ */
53
+ export const cantAnswerNoticeDue = ({
54
+ lastNoticeAt, seenThrough = NaN, now = Date.now(), waiting = [],
55
+ }) => {
56
+ if (!Number.isFinite(lastNoticeAt) || lastNoticeAt > now) return true;
57
+ if (now - lastNoticeAt >= CANT_ANSWER_NOTICE_WINDOW_MS) return true;
58
+ if (now - lastNoticeAt < CANT_ANSWER_REPEAT_MIN_MS) return false;
59
+ const boundary = Number.isFinite(seenThrough) ? seenThrough : lastNoticeAt;
60
+ return waiting.some((event) => {
61
+ const at = newestMessageAt(event);
62
+ return !Number.isFinite(at) || at > boundary;
63
+ });
64
+ };
65
+
26
66
  const LOGIN_FAILED_WORDINGS = [
27
67
  // Not `(upstream 401)` alone: adapterFailure writes that for any "status 401"
28
68
  // in a tail, including a tool's stderr. A failed Codex turn is its own report.