@commonlyai/cli 0.1.159 → 0.1.160

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.159",
3
+ "version": "0.1.160",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -1206,6 +1206,9 @@ export const performRun = ({
1206
1206
  setTimeoutImpl = setTimeout,
1207
1207
  setIntervalImpl = setInterval,
1208
1208
  clearIntervalImpl = clearInterval,
1209
+ setDeadlineTimeoutImpl = setTimeout,
1210
+ clearDeadlineTimeoutImpl = clearTimeout,
1211
+ turnTimeoutMs,
1209
1212
  retryJitterRatio,
1210
1213
  claimLeaseSeconds = 90,
1211
1214
  // Undefined means "not overridden" — resolveCascadeSettings falls back to
@@ -1235,6 +1238,9 @@ export const performRun = ({
1235
1238
  if (environment?.provider !== undefined && !adapter?.supportsProvider) {
1236
1239
  throw new Error('environment.provider requires a provider-capable adapter');
1237
1240
  }
1241
+ const requestedTurnTimeout = Number(turnTimeoutMs ?? process.env.COMMONLY_AGENT_RUN_TIMEOUT_MS);
1242
+ const effectiveTurnTimeoutMs = Number.isFinite(requestedTurnTimeout) && requestedTurnTimeout > 0
1243
+ ? Math.min(requestedTurnTimeout, 2_147_483_647) : 15 * 60 * 1000;
1238
1244
  const client = createClient({ instance: instanceUrl, token });
1239
1245
  const handoffAgent = sanitizeHandoffAgent(refusalHandoff);
1240
1246
  if (refusalHandoff && !handoffAgent) {
@@ -1742,6 +1748,7 @@ export const performRun = ({
1742
1748
  });
1743
1749
  }
1744
1750
  result = await adapter.spawn(frameDecisionForkRule(promptForSpawn), {
1751
+ timeoutMs: effectiveTurnTimeoutMs,
1745
1752
  sessionId,
1746
1753
  cwd: agentCwd,
1747
1754
  env: commitAttribution?.env || process.env,
@@ -2076,7 +2083,13 @@ export const performRun = ({
2076
2083
  + '[This item is read-only context: a peer won its binding claim. Do not act on it.]\n'
2077
2084
  : (entry.peerFrame ? `${entry.peerFrame}\n` : '');
2078
2085
  const body = entry.prompt || '[No usable prompt was delivered for this item.]';
2079
- return `${prefix}\n${claimContext}${body}`;
2086
+ const deliveryId = entry.event.payload?.deliveryId;
2087
+ const checkpoint = typeof deliveryId === 'string' && deliveryId
2088
+ ? `\n[After completed tool-side work or intentional NO_REPLY for only this item, call commonly_checkpoint_event(${JSON.stringify({
2089
+ eventId: String(entry.event._id), deliveryId,
2090
+ })}). Checkpoint metadata is private runtime data; never post it in chat.]`
2091
+ : '';
2092
+ return `${prefix}\n${claimContext}${body}${checkpoint}`;
2080
2093
  });
2081
2094
  const rollup = wakeEntries.find((entry) => entry.event.payload?.digestRollup)?.event.payload?.digestRollup;
2082
2095
  const digestFrame = formatDigestFrame(digestEntries.map((entry) => entry.event), rollup);
@@ -2084,6 +2097,11 @@ export const performRun = ({
2084
2097
  return [
2085
2098
  `[Inbox batch: ${inboxCount} new event${inboxCount === 1 ? '' : 's'} in this pod. `
2086
2099
  + 'This is one turn: read the included items together, then decide what needs YOU.]',
2100
+ 'After tool-side work is committed (including any reply posted through a tool), or an intentional NO_REPLY, checkpoint that item with its supplied IDs. '
2101
+ + 'Release any held message claim first with the correct completed/declined outcome. '
2102
+ + 'Do not checkpoint a reply you are holding for final CLI output: the wrapper must post it before acknowledging that item. '
2103
+ + 'Never checkpoint unfinished work. Only a successful checkpoint prevents replay after timeout. '
2104
+ + 'If the tool is unavailable, continue normally; completion will acknowledge the batch.',
2087
2105
  ...bodies,
2088
2106
  ...(digestFrame ? [digestFrame] : []),
2089
2107
  ...(omitted > 0
@@ -2170,7 +2188,7 @@ export const performRun = ({
2170
2188
  let heldGreeting = [];
2171
2189
  let greetingHoldSpent = false;
2172
2190
 
2173
- const processEventBatch = async (events, inboxCount = events.length) => {
2191
+ const handleEventBatch = async (events, inboxCount = events.length) => {
2174
2192
  const eventPodId = events[0]?.podId || podId;
2175
2193
  if (!eventPodId || events.some((event) => (event.podId || podId) !== eventPodId)) {
2176
2194
  throw new Error('Inbox batch crossed pod boundaries; refusing to mix private pod context');
@@ -2427,6 +2445,44 @@ export const performRun = ({
2427
2445
  }
2428
2446
  };
2429
2447
 
2448
+ const processEventBatch = async (events, inboxCount = events.length) => {
2449
+ const deliveries = events.filter((event) => typeof event.payload?.deliveryId === 'string' && event.payload.deliveryId)
2450
+ .map((event) => ({ eventId: String(event._id), deliveryId: event.payload.deliveryId }));
2451
+ let renewing = false;
2452
+ let renewalStopped = false;
2453
+ const renew = async () => {
2454
+ if (renewalStopped || renewing || deliveries.length === 0) return;
2455
+ renewing = true;
2456
+ try {
2457
+ for (let offset = 0; offset < deliveries.length && !renewalStopped; offset += 50) {
2458
+ await client.post('/api/agents/runtime/events/renew', {
2459
+ events: deliveries.slice(offset, offset + 50),
2460
+ });
2461
+ }
2462
+ } catch (error) {
2463
+ // An older server may lack this route. Never reinterpret a failed
2464
+ // renewal as an ack: stale checkpoint nonces still fail closed.
2465
+ log(`[inbox.batch] delivery renewal failed: ${error.message}`);
2466
+ } finally { renewing = false; }
2467
+ };
2468
+ const timer = deliveries.length ? setIntervalImpl(renew, 60_000) : null;
2469
+ const stopRenewal = () => {
2470
+ renewalStopped = true;
2471
+ if (timer !== null) clearIntervalImpl(timer);
2472
+ };
2473
+ // Independent of adapter settlement: SIGTERM can be ignored, so awaiting
2474
+ // spawn in finally is not a bound on the event's delivery lease.
2475
+ const deadlineTimer = deliveries.length ? setDeadlineTimeoutImpl(() => {
2476
+ stopRenewal();
2477
+ log('[inbox.batch] turn deadline reached; delivery renewal stopped for GC recovery');
2478
+ }, effectiveTurnTimeoutMs) : null;
2479
+ try { return await handleEventBatch(events, inboxCount); }
2480
+ finally {
2481
+ stopRenewal();
2482
+ if (deadlineTimer !== null) clearDeadlineTimeoutImpl(deadlineTimer);
2483
+ }
2484
+ };
2485
+
2430
2486
  const tick = async () => {
2431
2487
  if (!running) return;
2432
2488
  let nextPollDelayMs = intervalMs;