@evident-ai/cli 3.1.1-dev.bedbd30 → 3.1.1-dev.c0fca20

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/dist/index.js CHANGED
@@ -267,16 +267,28 @@ async function getToken() {
267
267
  }
268
268
  return null;
269
269
  }
270
+ function toError(err) {
271
+ return err instanceof Error ? err : new Error(String(err));
272
+ }
270
273
  async function deleteToken(options = {}) {
271
274
  const keytar = await getKeytar();
275
+ const failures = [];
272
276
  if (keytar) {
273
277
  if (options.all) {
274
- const all = await keytar.findCredentials(SERVICE_NAME).catch(() => []);
278
+ let accounts = [];
279
+ try {
280
+ accounts = await keytar.findCredentials(SERVICE_NAME);
281
+ } catch (err) {
282
+ failures.push({ type: "enumerate", error: toError(err) });
283
+ }
275
284
  await Promise.all(
276
- all.map(
277
- (entry) => keytar.deletePassword(SERVICE_NAME, entry.account).catch(() => {
278
- })
279
- )
285
+ accounts.map(async (entry) => {
286
+ try {
287
+ await keytar.deletePassword(SERVICE_NAME, entry.account);
288
+ } catch (err) {
289
+ failures.push({ type: "delete", account: entry.account, error: toError(err) });
290
+ }
291
+ })
280
292
  );
281
293
  } else {
282
294
  await keytar.deletePassword(SERVICE_NAME, keychainAccount());
@@ -287,6 +299,7 @@ async function deleteToken(options = {}) {
287
299
  } else {
288
300
  clearCredentials();
289
301
  }
302
+ return { failures };
290
303
  }
291
304
 
292
305
  // src/utils/ui.ts
@@ -455,9 +468,22 @@ async function login(options) {
455
468
  }
456
469
 
457
470
  // src/commands/logout.ts
471
+ function describeFailure(failure) {
472
+ if (failure.type === "enumerate") {
473
+ return `could not list stored keychain entries (${failure.error.message})`;
474
+ }
475
+ return `${failure.account} (${failure.error.message})`;
476
+ }
458
477
  async function logout(options = {}) {
459
478
  if (options.all) {
460
- await deleteToken({ all: true });
479
+ const result = await deleteToken({ all: true });
480
+ if (result.failures.length > 0) {
481
+ printError(
482
+ `Failed to fully clear your keychain: ${result.failures.map(describeFailure).join("; ")}. Your local credentials file was cleared, but stale keychain entries may remain \u2014 run \`evident logout --all\` again, or remove them manually from your OS keychain / credential manager.`
483
+ );
484
+ process.exitCode = 1;
485
+ return;
486
+ }
461
487
  printSuccess("Logged out of all endpoints.");
462
488
  return;
463
489
  }
@@ -510,7 +536,10 @@ var TelemetryEventTypes = {
510
536
  AGENT_DISCONNECTED: "agent.disconnected",
511
537
  AGENT_MESSAGE_PROCESSING: "agent.message_processing",
512
538
  AGENT_MESSAGE_DONE: "agent.message_done",
513
- AGENT_MESSAGE_FAILED: "agent.message_failed"
539
+ AGENT_MESSAGE_FAILED: "agent.message_failed",
540
+ // A `warn`/`error` runner-side log line forwarded server-side for
541
+ // observability (issue #916) — see `apps/cli/src/lib/runner-activity-telemetry.ts`.
542
+ RUNNER_ACTIVITY: "runner.activity"
514
543
  };
515
544
 
516
545
  // ../../packages/types/src/tunnel/index.ts
@@ -565,6 +594,13 @@ var isShuttingDown = false;
565
594
  var FLUSH_INTERVAL_MS = 5e3;
566
595
  var MAX_BUFFER_SIZE = 50;
567
596
  var FLUSH_TIMEOUT_MS = 3e3;
597
+ var authProvider = null;
598
+ function setTelemetryAuthProvider(provider) {
599
+ authProvider = provider;
600
+ }
601
+ var FLUSH_FAILURE_LOG_INTERVAL_MS = 6e4;
602
+ var lastFlushFailureLoggedAt = 0;
603
+ var suppressedFlushFailureCount = 0;
568
604
  function logEvent(eventType, options = {}) {
569
605
  const event = {
570
606
  event_type: eventType,
@@ -599,9 +635,16 @@ async function flushEvents() {
599
635
  flushTimeout = null;
600
636
  }
601
637
  try {
602
- const credentials2 = await getToken();
603
- if (!credentials2) {
604
- return;
638
+ const providerContext = authProvider?.();
639
+ let authHeader;
640
+ if (providerContext?.authHeader) {
641
+ authHeader = providerContext.authHeader;
642
+ } else {
643
+ const credentials2 = await getToken();
644
+ if (!credentials2) {
645
+ return;
646
+ }
647
+ authHeader = `Bearer ${credentials2.token}`;
605
648
  }
606
649
  const apiUrl = getApiUrlConfig();
607
650
  const controller = new AbortController();
@@ -616,7 +659,7 @@ async function flushEvents() {
616
659
  method: "POST",
617
660
  headers: {
618
661
  "Content-Type": "application/json",
619
- Authorization: `Bearer ${credentials2.token}`
662
+ Authorization: authHeader
620
663
  },
621
664
  body: JSON.stringify(request),
622
665
  signal: controller.signal
@@ -628,8 +671,15 @@ async function flushEvents() {
628
671
  clearTimeout(timeout);
629
672
  }
630
673
  } catch (error2) {
631
- if (process.env.DEBUG) {
632
- console.error("Telemetry error:", error2);
674
+ const now = Date.now();
675
+ if (now - lastFlushFailureLoggedAt >= FLUSH_FAILURE_LOG_INTERVAL_MS) {
676
+ const message = error2 instanceof Error ? error2.message : String(error2);
677
+ const suffix = suppressedFlushFailureCount > 0 ? ` (${suppressedFlushFailureCount} more suppressed in the last ${FLUSH_FAILURE_LOG_INTERVAL_MS / 1e3}s)` : "";
678
+ console.error(`Telemetry flush error: ${message}${suffix}`);
679
+ lastFlushFailureLoggedAt = now;
680
+ suppressedFlushFailureCount = 0;
681
+ } else {
682
+ suppressedFlushFailureCount++;
633
683
  }
634
684
  }
635
685
  }
@@ -698,6 +748,69 @@ var EventTypes = {
698
748
  DEPRECATED_AGENT_KEY_ENV_USED: "cli.deprecated_agent_key_env_used"
699
749
  };
700
750
 
751
+ // src/lib/runner-activity-telemetry.ts
752
+ var FORWARDED_LEVELS = /* @__PURE__ */ new Set(["warn", "error"]);
753
+ var SEVERITY_BY_LEVEL = {
754
+ warn: "warning",
755
+ error: "error"
756
+ };
757
+ var MAX_MESSAGE_LENGTH = 500;
758
+ var TRUNCATION_MARKER = "\u2026";
759
+ function redact(message) {
760
+ return message.replace(/esk_[A-Za-z0-9_-]+/g, "esk_***").replace(/ct_[A-Za-z0-9_-]+/g, "ct_***").replace(/https?:\/\/\S+/g, "<url>");
761
+ }
762
+ function truncate(message) {
763
+ if (message.length <= MAX_MESSAGE_LENGTH) return message;
764
+ return message.slice(0, MAX_MESSAGE_LENGTH - TRUNCATION_MARKER.length) + TRUNCATION_MARKER;
765
+ }
766
+ var RATE_LIMIT_WINDOW_MS = 6e4;
767
+ var RATE_LIMIT_MAX_EVENTS = 30;
768
+ var windowStartedAt = 0;
769
+ var windowCount = 0;
770
+ var windowDroppedCount = 0;
771
+ function admitUnderRateLimit(now) {
772
+ if (now - windowStartedAt >= RATE_LIMIT_WINDOW_MS) {
773
+ if (windowDroppedCount > 0) {
774
+ console.error(
775
+ `[runner-activity-telemetry] rate cap reached: dropped ${windowDroppedCount} ${windowDroppedCount === 1 ? "entry" : "entries"} in the last ${RATE_LIMIT_WINDOW_MS / 1e3}s (cap ${RATE_LIMIT_MAX_EVENTS}/min)`
776
+ );
777
+ }
778
+ windowStartedAt = now;
779
+ windowCount = 0;
780
+ windowDroppedCount = 0;
781
+ }
782
+ if (windowCount >= RATE_LIMIT_MAX_EVENTS) {
783
+ windowDroppedCount++;
784
+ if (windowDroppedCount === 1) {
785
+ console.error(
786
+ `[runner-activity-telemetry] rate cap reached (${RATE_LIMIT_MAX_EVENTS} per ${RATE_LIMIT_WINDOW_MS / 1e3}s) \u2014 dropping further entries this window`
787
+ );
788
+ }
789
+ return false;
790
+ }
791
+ windowCount++;
792
+ return true;
793
+ }
794
+ function forwardRunnerActivity(entry, context) {
795
+ try {
796
+ if (!FORWARDED_LEVELS.has(entry.level)) return;
797
+ if (!context.agentId || !context.authHeader) return;
798
+ if (!admitUnderRateLimit(Date.now())) return;
799
+ const rawMessage = entry.error ?? entry.message ?? "";
800
+ const message = truncate(redact(rawMessage));
801
+ logEvent(TelemetryEventTypes.RUNNER_ACTIVITY, {
802
+ severity: SEVERITY_BY_LEVEL[entry.level],
803
+ message,
804
+ metadata: { source: "cli.run" },
805
+ agentId: context.agentId
806
+ });
807
+ } catch (err) {
808
+ console.error(
809
+ `[runner-activity-telemetry] failed to forward runner activity: ${err instanceof Error ? err.message : String(err)}`
810
+ );
811
+ }
812
+ }
813
+
701
814
  // src/lib/auth.ts
702
815
  async function getAuthCredentials() {
703
816
  const runnerKey = process.env.EVIDENT_RUNNER_KEY;
@@ -1532,6 +1645,9 @@ function isPreamblePinnedRunning(messages, userMessageId) {
1532
1645
  const reply = findLastAssistantReplyFor(messages, userMessageId);
1533
1646
  return completedOf(reply) != null && finishOf(reply) === "tool-calls";
1534
1647
  }
1648
+ function isB2AbandonmentConfirmed(params) {
1649
+ return params.pinnedForMs >= params.minPinnedMs && params.descendantOngoing === false;
1650
+ }
1535
1651
  function messageError(messages, userMessageId) {
1536
1652
  const reply = findLastAssistantReplyFor(messages, userMessageId);
1537
1653
  const error2 = errorOf(reply);
@@ -1545,6 +1661,42 @@ function messageError(messages, userMessageId) {
1545
1661
  }
1546
1662
  return "The agent run failed.";
1547
1663
  }
1664
+ function messageFailure(messages, userMessageId) {
1665
+ const reply = findLastAssistantReplyFor(messages, userMessageId);
1666
+ const error2 = errorOf(reply);
1667
+ if (error2 == null || typeof error2 !== "object") return null;
1668
+ const e = error2;
1669
+ const replyProviderId = reply?.info?.providerID ?? null;
1670
+ const replyModelId = reply?.info?.modelID ?? null;
1671
+ if (e.name === "ProviderAuthError") {
1672
+ const data = e.data;
1673
+ const providerId = typeof data?.providerID === "string" && data.providerID || replyProviderId;
1674
+ return { kind: "model_auth", providerId, modelId: replyModelId, reason: "missing" };
1675
+ }
1676
+ if (e.name === "APIError") {
1677
+ const data = e.data;
1678
+ const statusCode = data?.statusCode;
1679
+ if (statusCode === 401 || statusCode === 403) {
1680
+ return {
1681
+ kind: "model_auth",
1682
+ providerId: replyProviderId,
1683
+ modelId: replyModelId,
1684
+ reason: "rejected"
1685
+ };
1686
+ }
1687
+ }
1688
+ return null;
1689
+ }
1690
+ function applyZeroProviderFallback(classified, hasConfiguredProvider, replyProviderId, replyModelId = null) {
1691
+ if (classified != null) return classified;
1692
+ if (hasConfiguredProvider !== false) return null;
1693
+ return {
1694
+ kind: "model_auth",
1695
+ providerId: replyProviderId,
1696
+ modelId: replyModelId,
1697
+ reason: "missing"
1698
+ };
1699
+ }
1548
1700
  function hasRunningAssistantExcept(messages, exceptUserMessageId) {
1549
1701
  if (!messages || messages.length === 0) return false;
1550
1702
  return messages.some(
@@ -2073,6 +2225,18 @@ var RunnerConnection = class {
2073
2225
  }
2074
2226
  };
2075
2227
 
2228
+ // src/lib/tunnel/ready-marker.ts
2229
+ import { writeFileSync } from "fs";
2230
+ function writeTunnelReadyMarker(path, agentId) {
2231
+ try {
2232
+ writeFileSync(path, `${agentId}
2233
+ `);
2234
+ return { ok: true };
2235
+ } catch (error2) {
2236
+ return { ok: false, error: error2 instanceof Error ? error2.message : String(error2) };
2237
+ }
2238
+ }
2239
+
2076
2240
  // src/lib/channels/driver.ts
2077
2241
  import { homedir } from "os";
2078
2242
 
@@ -2499,6 +2663,8 @@ var DEFAULT_PAUSED_MAX_WAIT_MS = 10 * 60 * 1e3;
2499
2663
  var DEFAULT_STUCK_QUEUED_MS = 6e4;
2500
2664
  var HEARTBEAT_MS = 6e4;
2501
2665
  var ABSOLUTE_MAX_PROCESSING_MS = 6 * 60 * 60 * 1e3;
2666
+ var B2_ABANDONMENT_MIN_PINNED_MS = 3 * 6e4;
2667
+ var B2_ABANDONMENT_RECHECK_MS = HEARTBEAT_MS;
2502
2668
  var POLL_MISS_GRACE_MS = HEARTBEAT_MS;
2503
2669
  var MAX_SUPERSEDED_CONVERSATIONS = 256;
2504
2670
  var ChannelAuthError = class extends Error {
@@ -3324,7 +3490,10 @@ var ChannelDriver = class _ChannelDriver {
3324
3490
  pausedOnPermission: false,
3325
3491
  pausedClearConfirmed: false,
3326
3492
  pausedInFlight: false,
3327
- deliveryDeadlineAnchored: false
3493
+ deliveryDeadlineAnchored: false,
3494
+ b2PinnedSinceMs: 0,
3495
+ b2LastDescendantCheckMs: 0,
3496
+ b2AbandonedSignalled: false
3328
3497
  });
3329
3498
  }
3330
3499
  /**
@@ -3399,7 +3568,10 @@ var ChannelDriver = class _ChannelDriver {
3399
3568
  pausedOnPermission: false,
3400
3569
  pausedClearConfirmed: false,
3401
3570
  pausedInFlight: false,
3402
- deliveryDeadlineAnchored: false
3571
+ deliveryDeadlineAnchored: false,
3572
+ b2PinnedSinceMs: 0,
3573
+ b2LastDescendantCheckMs: 0,
3574
+ b2AbandonedSignalled: false
3403
3575
  });
3404
3576
  }
3405
3577
  /**
@@ -3561,58 +3733,7 @@ var ChannelDriver = class _ChannelDriver {
3561
3733
  }
3562
3734
  }
3563
3735
  if (state === "done") {
3564
- this.anchorDeliveryDeadline(inFlight);
3565
- if (!inFlight.done) {
3566
- this.log({
3567
- level: "info",
3568
- message: `Message ${inFlight.evidentMessageId.slice(0, 8)} completed \u2014 marking done`,
3569
- conversation_id: conv.id,
3570
- message_id: inFlight.evidentMessageId
3571
- });
3572
- const title = await this.resolveSessionTitle(sessionId, watcher.conv.id);
3573
- const usage = messageUsage(messages, inFlight.opencodeMessageId);
3574
- try {
3575
- await this.markDone(
3576
- conv.id,
3577
- inFlight.evidentMessageId,
3578
- sessionId,
3579
- inFlight.opencodeMessageId,
3580
- title,
3581
- usage
3582
- );
3583
- } catch (err) {
3584
- if (err instanceof ChannelAuthError) throw err;
3585
- if (err instanceof ChannelTerminalError) {
3586
- this.log({
3587
- level: "warn",
3588
- message: `Failed to mark message ${inFlight.evidentMessageId.slice(0, 8)} done (terminal HTTP ${err.status}) \u2014 leaving for the cron safety net: ${err.message}`,
3589
- conversation_id: conv.id,
3590
- message_id: inFlight.evidentMessageId
3591
- });
3592
- this.removeInFlight(watcher, inFlight.evidentMessageId);
3593
- return;
3594
- }
3595
- if (this.now() >= inFlight.deadline) {
3596
- this.log({
3597
- level: "warn",
3598
- message: `Failed to mark message ${inFlight.evidentMessageId.slice(0, 8)} done within the watch window \u2014 leaving for the cron safety net: ${err instanceof Error ? err.message : String(err)}`,
3599
- conversation_id: conv.id,
3600
- message_id: inFlight.evidentMessageId
3601
- });
3602
- this.removeInFlight(watcher, inFlight.evidentMessageId);
3603
- return;
3604
- }
3605
- this.log({
3606
- level: "warn",
3607
- message: `Failed to mark message ${inFlight.evidentMessageId.slice(0, 8)} done (will retry next tick): ${err instanceof Error ? err.message : String(err)}`,
3608
- conversation_id: conv.id,
3609
- message_id: inFlight.evidentMessageId
3610
- });
3611
- return;
3612
- }
3613
- inFlight.done = true;
3614
- }
3615
- this.removeInFlight(watcher, inFlight.evidentMessageId);
3736
+ await this.settleMessageDone(sessionId, watcher, inFlight, messages);
3616
3737
  return;
3617
3738
  }
3618
3739
  if (state === "failed") {
@@ -3626,8 +3747,16 @@ var ChannelDriver = class _ChannelDriver {
3626
3747
  message_id: inFlight.evidentMessageId
3627
3748
  });
3628
3749
  const usage = messageUsage(messages, inFlight.opencodeMessageId);
3750
+ const failure = await this.classifyModelAuthFailure(messages, inFlight.opencodeMessageId);
3629
3751
  try {
3630
- await this.markFailed(conv.id, inFlight.evidentMessageId, sessionId, error2, usage);
3752
+ await this.markFailed(
3753
+ conv.id,
3754
+ inFlight.evidentMessageId,
3755
+ sessionId,
3756
+ error2,
3757
+ usage,
3758
+ failure
3759
+ );
3631
3760
  } catch (err) {
3632
3761
  if (err instanceof ChannelAuthError) throw err;
3633
3762
  if (err instanceof ChannelTerminalError) {
@@ -3672,6 +3801,44 @@ var ChannelDriver = class _ChannelDriver {
3672
3801
  });
3673
3802
  }
3674
3803
  const activelyRunning = state === "running" && !awaitingHuman;
3804
+ const pinnedNow = activelyRunning && isPreamblePinnedRunning(messages, inFlight.opencodeMessageId);
3805
+ const snapshotReadable = messages != null && messages.length > 0;
3806
+ if (!pinnedNow) {
3807
+ if (snapshotReadable) {
3808
+ inFlight.b2PinnedSinceMs = 0;
3809
+ inFlight.b2LastDescendantCheckMs = 0;
3810
+ inFlight.b2AbandonedSignalled = false;
3811
+ }
3812
+ } else {
3813
+ if (inFlight.b2AbandonedSignalled) {
3814
+ await this.settleMessageDone(sessionId, watcher, inFlight, messages);
3815
+ return;
3816
+ }
3817
+ if (inFlight.b2PinnedSinceMs === 0) inFlight.b2PinnedSinceMs = this.now();
3818
+ const pinnedForMs = this.now() - inFlight.b2PinnedSinceMs;
3819
+ if (pinnedForMs >= B2_ABANDONMENT_MIN_PINNED_MS && this.now() - inFlight.b2LastDescendantCheckMs >= B2_ABANDONMENT_RECHECK_MS) {
3820
+ inFlight.b2LastDescendantCheckMs = this.now();
3821
+ const descendantOngoing = await this.isAnyDescendantSessionOngoing(sessionId);
3822
+ if (isB2AbandonmentConfirmed({
3823
+ pinnedForMs,
3824
+ minPinnedMs: B2_ABANDONMENT_MIN_PINNED_MS,
3825
+ descendantOngoing
3826
+ })) {
3827
+ inFlight.b2AbandonedSignalled = true;
3828
+ this.log({
3829
+ level: "warn",
3830
+ message: `Message ${id.slice(0, 8)} b2-pinned for ${Math.round(pinnedForMs / 1e3)}s with no ongoing descendant sub-agent session (status-map confirmed) \u2014 treating the delegated/tool turn as abandoned, resolving done`,
3831
+ conversation_id: conv.id,
3832
+ message_id: id
3833
+ });
3834
+ void this.postSignal(conv.id, id, "b2_abandoned_resolved", {
3835
+ watched_for_ms: pinnedForMs
3836
+ });
3837
+ await this.settleMessageDone(sessionId, watcher, inFlight, messages);
3838
+ return;
3839
+ }
3840
+ }
3841
+ }
3675
3842
  if (activelyRunning && this.now() - inFlight.processingAnchorMs >= ABSOLUTE_MAX_PROCESSING_MS) {
3676
3843
  this.log({
3677
3844
  level: "warn",
@@ -3740,6 +3907,70 @@ var ChannelDriver = class _ChannelDriver {
3740
3907
  this.removeInFlight(watcher, inFlight.evidentMessageId);
3741
3908
  }
3742
3909
  }
3910
+ /**
3911
+ * Settle a message whose run-state has resolved `'done'` — extracted verbatim
3912
+ * (pure refactor, no behavior change) from `serviceInFlightMessage`'s former
3913
+ * inline `state === 'done'` branch body, so a SECOND caller (the #721
3914
+ * b2-abandonment resolution) can reach the exact same completion behavior
3915
+ * (delivery-deadline anchoring, title resolution, usage extraction, and
3916
+ * `markDone`'s auth/terminal/transient-retry discipline) without duplicating it
3917
+ * and risking the two copies silently drifting apart.
3918
+ */
3919
+ async settleMessageDone(sessionId, watcher, inFlight, messages) {
3920
+ const conv = watcher.conv;
3921
+ this.anchorDeliveryDeadline(inFlight);
3922
+ if (!inFlight.done) {
3923
+ this.log({
3924
+ level: "info",
3925
+ message: `Message ${inFlight.evidentMessageId.slice(0, 8)} completed \u2014 marking done`,
3926
+ conversation_id: conv.id,
3927
+ message_id: inFlight.evidentMessageId
3928
+ });
3929
+ const title = await this.resolveSessionTitle(sessionId, watcher.conv.id);
3930
+ const usage = messageUsage(messages, inFlight.opencodeMessageId);
3931
+ try {
3932
+ await this.markDone(
3933
+ conv.id,
3934
+ inFlight.evidentMessageId,
3935
+ sessionId,
3936
+ inFlight.opencodeMessageId,
3937
+ title,
3938
+ usage
3939
+ );
3940
+ } catch (err) {
3941
+ if (err instanceof ChannelAuthError) throw err;
3942
+ if (err instanceof ChannelTerminalError) {
3943
+ this.log({
3944
+ level: "warn",
3945
+ message: `Failed to mark message ${inFlight.evidentMessageId.slice(0, 8)} done (terminal HTTP ${err.status}) \u2014 leaving for the cron safety net: ${err.message}`,
3946
+ conversation_id: conv.id,
3947
+ message_id: inFlight.evidentMessageId
3948
+ });
3949
+ this.removeInFlight(watcher, inFlight.evidentMessageId);
3950
+ return;
3951
+ }
3952
+ if (this.now() >= inFlight.deadline) {
3953
+ this.log({
3954
+ level: "warn",
3955
+ message: `Failed to mark message ${inFlight.evidentMessageId.slice(0, 8)} done within the watch window \u2014 leaving for the cron safety net: ${err instanceof Error ? err.message : String(err)}`,
3956
+ conversation_id: conv.id,
3957
+ message_id: inFlight.evidentMessageId
3958
+ });
3959
+ this.removeInFlight(watcher, inFlight.evidentMessageId);
3960
+ return;
3961
+ }
3962
+ this.log({
3963
+ level: "warn",
3964
+ message: `Failed to mark message ${inFlight.evidentMessageId.slice(0, 8)} done (will retry next tick): ${err instanceof Error ? err.message : String(err)}`,
3965
+ conversation_id: conv.id,
3966
+ message_id: inFlight.evidentMessageId
3967
+ });
3968
+ return;
3969
+ }
3970
+ inFlight.done = true;
3971
+ }
3972
+ this.removeInFlight(watcher, inFlight.evidentMessageId);
3973
+ }
3743
3974
  // Restart recovery: re-adopt `processing` messages (ADR-0046, WI-3/4/5)
3744
3975
  /**
3745
3976
  * Re-adopt this agent's `processing` messages on drain (ADR-0046 Decision §1).
@@ -3906,6 +4137,7 @@ var ChannelDriver = class _ChannelDriver {
3906
4137
  if (state === "failed") {
3907
4138
  const error2 = messageError(messages, ocId ?? "") ?? void 0;
3908
4139
  const usage = messageUsage(messages, ocId ?? "");
4140
+ const failure = await this.classifyModelAuthFailure(messages, ocId ?? "");
3909
4141
  this.log({
3910
4142
  level: "error",
3911
4143
  message: `Re-adopt: message ${row.id.slice(0, 8)} errored while unwatched \u2014 marking failed: ${error2 ?? "(no error text)"}`,
@@ -3913,7 +4145,7 @@ var ChannelDriver = class _ChannelDriver {
3913
4145
  message_id: row.id
3914
4146
  });
3915
4147
  try {
3916
- await this.markFailed(row.conversation_id, row.id, sessionId, error2, usage);
4148
+ await this.markFailed(row.conversation_id, row.id, sessionId, error2, usage, failure);
3917
4149
  } catch (err) {
3918
4150
  if (err instanceof ChannelAuthError) throw err;
3919
4151
  if (err instanceof ChannelTerminalError) {
@@ -4319,6 +4551,47 @@ var ChannelDriver = class _ChannelDriver {
4319
4551
  }
4320
4552
  return false;
4321
4553
  }
4554
+ /**
4555
+ * Tri-state variant of the upward parentID membership walk (#721), used ONLY
4556
+ * by `isAnyDescendantSessionOngoing`. Walks the SAME cached
4557
+ * `resolveSessionParent` chain `sessionBelongsTo` uses above, but — unlike
4558
+ * `sessionBelongsTo`, which deliberately collapses "confirmed not a
4559
+ * descendant" and "the walk's fetch failed" into the same `false` (safe for
4560
+ * its OTHER callers: interaction attribution and the recovery-path
4561
+ * `isAnyDescendantSessionAlive`, both of which just retry next tick with no
4562
+ * safety consequence either way) — this variant keeps those two outcomes
4563
+ * SEPARATE, because `isAnyDescendantSessionOngoing`'s caller
4564
+ * (`isB2AbandonmentConfirmed`) must never treat "couldn't tell" as "confirmed
4565
+ * not ongoing".
4566
+ *
4567
+ * Return contract:
4568
+ * - `true` → the walk reached `rootSessionId` — `sessionId` IS a descendant.
4569
+ * - `false` → the walk reached a definitive, parent-less root session
4570
+ * WITHOUT ever matching `rootSessionId` — `sessionId` is
4571
+ * CONFIRMED NOT a descendant of it.
4572
+ * - `null` → INDETERMINATE: a `GET /session/:id` fetch failed partway
4573
+ * through the walk (`resolveSessionParent` returned `undefined`),
4574
+ * or the depth cap (32) was hit without a definitive answer (a
4575
+ * pathological/cyclic chain proves nothing either way). NEVER
4576
+ * treat this the same as `false` — see `sessionBelongsTo`'s own
4577
+ * doc comment above for why that collapse is safe THERE but not
4578
+ * here.
4579
+ *
4580
+ * `sessionBelongsTo` itself is UNCHANGED — this is an additive helper scoped
4581
+ * to the live-path descendant check, not a modification of shared code used
4582
+ * by interaction attribution or the recovery path.
4583
+ */
4584
+ async resolveSessionMembership(sessionId, rootSessionId) {
4585
+ let current = sessionId;
4586
+ for (let depth = 0; current && depth < 32; depth++) {
4587
+ if (current === rootSessionId) return true;
4588
+ const parent = await this.resolveSessionParent(current);
4589
+ if (parent === void 0) return null;
4590
+ if (parent === null) return false;
4591
+ current = parent;
4592
+ }
4593
+ return null;
4594
+ }
4322
4595
  /**
4323
4596
  * Resolve (and cache) a session's `parentID` via `GET /session/:id`. Returns
4324
4597
  * `null` for a root session (no parent) and `undefined` when opencode is
@@ -4509,6 +4782,84 @@ var ChannelDriver = class _ChannelDriver {
4509
4782
  }
4510
4783
  return false;
4511
4784
  }
4785
+ /**
4786
+ * LIVE-PATH descendant-liveness check (#721): is any descendant (`task`
4787
+ * sub-agent) session under `rootSessionId` currently ONGOING per OpenCode's own
4788
+ * in-memory status map (`isSessionOngoing` — `busy`/`retry`)?
4789
+ *
4790
+ * Deliberately NOT `isAnyDescendantSessionAlive` (the RECOVERY-path
4791
+ * cross-check above): that method judges liveness from the child's OWN
4792
+ * TRANSCRIPT (`isSessionActivelyGenerating`), which is the right (only) option
4793
+ * on the recovery path because a restart WIPES `SessionStatus`. On the LIVE
4794
+ * path the local opencode server IS running, so its in-memory status map is
4795
+ * live and authoritative — and per ADR-0047 §4a ("the child has its own entry
4796
+ * [in the map]"), a `task` descendant's OWN busy/retry entry reflects its
4797
+ * ENTIRE turn (including any tool call it is itself executing), not a
4798
+ * per-message transcript snapshot. This sidesteps the "child's own tool is
4799
+ * executing, between its step's completion and the next generation step"
4800
+ * transcript gap that a transcript-based check would need a second,
4801
+ * sustained-window bound to guard against — it is simply not derived from
4802
+ * message timestamps at all.
4803
+ *
4804
+ * Why not just check `isSessionOngoing(port, rootSessionId)` (the ROOT's own
4805
+ * status, as the recovery path does per §4a)? Because on the LIVE path the
4806
+ * root session can be shared: a SECOND, unrelated user message can land on the
4807
+ * SAME session (issue #721's own root cause) and keep the root `busy` for a
4808
+ * reason that has nothing to do with THIS message's delegation. A `task`
4809
+ * descendant session is spawned for exactly one delegated turn and never
4810
+ * reused, so its OWN status-map entry is unambiguous evidence about that one
4811
+ * delegation — which the root's status is not.
4812
+ *
4813
+ * Why membership is checked via `resolveSessionMembership`, NOT
4814
+ * `sessionBelongsTo`: `sessionBelongsTo` collapses a transient
4815
+ * `GET /session/:id` fetch failure into "not a descendant", which would
4816
+ * silently drop a genuinely-live candidate from consideration on the one
4817
+ * unlucky tick its membership-walk fetch hiccups (#721).
4818
+ * `resolveSessionMembership` keeps that failure mode as a distinct `null`
4819
+ * (indeterminate) so it is folded into THIS method's own `indeterminate` flag
4820
+ * instead.
4821
+ *
4822
+ * Return contract (note the DIFFERENT judge vs. `isAnyDescendantSessionAlive`):
4823
+ * - `true` → some descendant session is `busy`/`retry` (genuinely ongoing).
4824
+ * - `false` → enumeration succeeded, EVERY candidate's MEMBERSHIP was
4825
+ * confirmed either way (`resolveSessionMembership` never
4826
+ * returned `null`), and every CONFIRMED descendant's status read
4827
+ * succeeded and is not ongoing (includes "no descendant session
4828
+ * exists at all" — e.g. a plain, non-`task` tool call).
4829
+ * - `null` → INDETERMINATE: `listSessions` failed, OR at least one
4830
+ * candidate's MEMBERSHIP could not be confirmed
4831
+ * (`resolveSessionMembership` returned `null` — a fetch failure
4832
+ * or pathological chain partway through the parent walk), OR at
4833
+ * least one CONFIRMED descendant's `isSessionOngoing` read
4834
+ * failed — and no OTHER candidate was already confirmed `true`.
4835
+ * The caller MUST NOT treat `null` the same as `false` here
4836
+ * (unlike the recovery cross-check's contract) — see
4837
+ * `isB2AbandonmentConfirmed`.
4838
+ */
4839
+ async isAnyDescendantSessionOngoing(rootSessionId) {
4840
+ const sessions = await listSessions(this.port);
4841
+ if (!sessions) {
4842
+ this.log({
4843
+ level: "warn",
4844
+ message: `Could not enumerate sessions to check descendant liveness for root ${rootSessionId} (listSessions failed) \u2014 treating descendant liveness as indeterminate`
4845
+ });
4846
+ return null;
4847
+ }
4848
+ let indeterminate = false;
4849
+ for (const candidate of sessions) {
4850
+ if (!candidate?.id || candidate.id === rootSessionId) continue;
4851
+ const membership = await this.resolveSessionMembership(candidate.id, rootSessionId);
4852
+ if (membership === null) {
4853
+ indeterminate = true;
4854
+ continue;
4855
+ }
4856
+ if (membership === false) continue;
4857
+ const ongoing = await isSessionOngoing(this.port, candidate.id);
4858
+ if (ongoing === true) return true;
4859
+ if (ongoing === null) indeterminate = true;
4860
+ }
4861
+ return indeterminate ? null : false;
4862
+ }
4512
4863
  /**
4513
4864
  * Cheap decision-telemetry label for a running row's LAST correlated reply
4514
4865
  * (WI-2 Task 2.2): which running SHAPE it is, for the status-gated recovery log.
@@ -4772,7 +5123,7 @@ var ChannelDriver = class _ChannelDriver {
4772
5123
  * exists but is wedged, so the next attempt must get a fresh one
4773
5124
  * instead of reusing it — see WI-1's server-side null-clearing PATCH).
4774
5125
  */
4775
- async markFailed(conversationId, messageId, sessionId, error2, usage) {
5126
+ async markFailed(conversationId, messageId, sessionId, error2, usage, failure) {
4776
5127
  const body = { status: "failed" };
4777
5128
  if (sessionId === null) {
4778
5129
  body.opencode_session_id = null;
@@ -4781,6 +5132,12 @@ var ChannelDriver = class _ChannelDriver {
4781
5132
  }
4782
5133
  if (error2 !== void 0) body.error = error2;
4783
5134
  if (usage) Object.assign(body, usage);
5135
+ if (failure) {
5136
+ body.failure_kind = failure.kind;
5137
+ body.failure_provider_id = failure.providerId;
5138
+ body.failure_model_id = failure.modelId;
5139
+ body.failure_reason = failure.reason;
5140
+ }
4784
5141
  await this.callWithRetry(
4785
5142
  "marking message as failed",
4786
5143
  () => this.fetchImpl(
@@ -4793,6 +5150,29 @@ var ChannelDriver = class _ChannelDriver {
4793
5150
  )
4794
5151
  );
4795
5152
  }
5153
+ /**
5154
+ * Classify an errored turn as a model-auth failure (#736 P1-4), for `markFailed`.
5155
+ *
5156
+ * `messageFailure` alone (structured OpenCode error → `model_auth`) covers
5157
+ * most cases; when it returns `null` on this ALREADY-FAILED turn, fall back
5158
+ * to the P1-2b zero-provider check — one extra loopback call to
5159
+ * `hasAnyConfiguredProvider`, only reached when the structured classifier
5160
+ * couldn't place it. Fails open (never throws): a fallback probe failure
5161
+ * (`null`/indeterminate) leaves the classification `null`, which produces
5162
+ * today's byte-identical PATCH body via `markFailed`'s `if (failure)` guard.
5163
+ */
5164
+ async classifyModelAuthFailure(messages, userMessageId) {
5165
+ const classified = messageFailure(messages, userMessageId);
5166
+ if (classified != null) return classified;
5167
+ const reply = findLastAssistantReplyFor(messages, userMessageId);
5168
+ const hasProvider = await hasAnyConfiguredProvider(this.port);
5169
+ return applyZeroProviderFallback(
5170
+ classified,
5171
+ hasProvider,
5172
+ reply?.info?.providerID ?? null,
5173
+ reply?.info?.modelID ?? null
5174
+ );
5175
+ }
4796
5176
  /**
4797
5177
  * Best-effort, SINGLE-ATTEMPT runner→server telemetry ping
4798
5178
  * (queued-followup-redrive). `POST .../messages/:id/signal {signal, ...extra}`
@@ -4945,10 +5325,16 @@ var ChannelDriver = class _ChannelDriver {
4945
5325
  import chalk5 from "chalk";
4946
5326
  import ora2 from "ora";
4947
5327
  import { select as select2 } from "@inquirer/prompts";
5328
+ var INTERACTIVE_START_TIMEOUT_MS = 3e4;
4948
5329
  async function ensureOpenCodeRunning(ctx) {
4949
5330
  const healthCheck = await checkOpenCodeHealth(ctx.port);
4950
5331
  if (healthCheck.healthy) {
4951
- return { port: ctx.port, process: null, version: healthCheck.version ?? null };
5332
+ return {
5333
+ port: ctx.port,
5334
+ process: null,
5335
+ version: healthCheck.version ?? null,
5336
+ notReadyReason: null
5337
+ };
4952
5338
  }
4953
5339
  const runningInstances = await findHealthyOpenCodeInstances();
4954
5340
  if (runningInstances.length > 0) {
@@ -4969,7 +5355,7 @@ async function ensureOpenCodeRunning(ctx) {
4969
5355
  console.log(chalk5.yellow("Tip: Run with the correct port:"));
4970
5356
  console.log(
4971
5357
  chalk5.dim(
4972
- ` ${getCliName()} run --agent ${ctx.agentId} --port ${runningInstances[0].port}`
5358
+ ` ${getCliName()} run --runner ${ctx.agentId} --port ${runningInstances[0].port}`
4973
5359
  )
4974
5360
  );
4975
5361
  }
@@ -4989,14 +5375,22 @@ async function ensureOpenCodeRunning(ctx) {
4989
5375
  if (!ctx.interactive) {
4990
5376
  ctx.log(`OpenCode is not running on port ${ctx.port}. Starting it automatically...`);
4991
5377
  const proc = await startOpenCode(ctx.port);
4992
- const health = await waitForOpenCodeHealth(ctx.port, 3e4);
5378
+ const health = await waitForOpenCodeHealth(ctx.port, ctx.startTimeoutMs);
4993
5379
  if (!health.healthy) {
4994
- throw new Error(
4995
- `OpenCode failed to start on port ${ctx.port}. Install with: npm install -g opencode-ai`
4996
- );
5380
+ return {
5381
+ port: ctx.port,
5382
+ process: proc,
5383
+ version: null,
5384
+ notReadyReason: `it did not become healthy within ${Math.round(ctx.startTimeoutMs / 1e3)}s`
5385
+ };
4997
5386
  }
4998
5387
  ctx.log(`OpenCode started on port ${ctx.port}${health.version ? ` (v${health.version})` : ""}`);
4999
- return { port: ctx.port, process: proc, version: health.version ?? null };
5388
+ return {
5389
+ port: ctx.port,
5390
+ process: proc,
5391
+ version: health.version ?? null,
5392
+ notReadyReason: null
5393
+ };
5000
5394
  }
5001
5395
  let port = ctx.port;
5002
5396
  if (isPortInUse(port)) {
@@ -5049,15 +5443,15 @@ Port ${port} is already in use.`));
5049
5443
  if (action === "start") {
5050
5444
  const spinner = ora2("Starting OpenCode...").start();
5051
5445
  const proc = await startOpenCode(port);
5052
- const health = await waitForOpenCodeHealth(port, 3e4);
5446
+ const health = await waitForOpenCodeHealth(port, INTERACTIVE_START_TIMEOUT_MS);
5053
5447
  if (!health.healthy) {
5054
5448
  spinner.fail("Failed to start OpenCode");
5055
5449
  throw new Error("OpenCode failed to start");
5056
5450
  }
5057
5451
  spinner.stop();
5058
- return { port, process: proc, version: health.version ?? null };
5452
+ return { port, process: proc, version: health.version ?? null, notReadyReason: null };
5059
5453
  }
5060
- return { port, process: null, version: null };
5454
+ return { port, process: null, version: null, notReadyReason: "you chose to continue without it" };
5061
5455
  }
5062
5456
 
5063
5457
  // src/commands/agent-lookup.ts
@@ -5099,7 +5493,7 @@ async function resolveAgentIdFromKey(authHeader) {
5099
5493
  return { agent_id: data.agent_id };
5100
5494
  }
5101
5495
  return {
5102
- error: "Cannot resolve runner ID: auth type is not agent_key. Please provide --agent explicitly."
5496
+ error: "Cannot resolve runner ID: auth type is not agent_key. Please provide --runner explicitly."
5103
5497
  };
5104
5498
  } catch (error2) {
5105
5499
  const message = error2 instanceof Error ? error2.message : "Unknown error";
@@ -5254,6 +5648,35 @@ function resolveFileSyncDirectories(raw, homeDir) {
5254
5648
  }
5255
5649
  return directories;
5256
5650
  }
5651
+ var DEFAULT_OPENCODE_START_TIMEOUT_SECONDS = 180;
5652
+ var MAX_OPENCODE_START_TIMEOUT_SECONDS = 3600;
5653
+ var OPENCODE_START_TIMEOUT_ENV = "EVIDENT_OPENCODE_START_TIMEOUT";
5654
+ function resolveOpenCodeStartTimeoutMs(options, env = process.env) {
5655
+ const defaultMs = DEFAULT_OPENCODE_START_TIMEOUT_SECONDS * 1e3;
5656
+ let raw;
5657
+ let source;
5658
+ if (options.opencodeStartTimeout !== void 0) {
5659
+ raw = options.opencodeStartTimeout;
5660
+ source = "--opencode-start-timeout";
5661
+ } else if (env[OPENCODE_START_TIMEOUT_ENV] !== void 0 && env[OPENCODE_START_TIMEOUT_ENV] !== "") {
5662
+ raw = env[OPENCODE_START_TIMEOUT_ENV];
5663
+ source = OPENCODE_START_TIMEOUT_ENV;
5664
+ } else {
5665
+ return { timeoutMs: defaultMs, warnings: [] };
5666
+ }
5667
+ const trimmed = raw.trim();
5668
+ const seconds = Number(trimmed);
5669
+ const isPositiveInteger = /^\d+$/.test(trimmed) && Number.isInteger(seconds) && seconds > 0;
5670
+ if (!isPositiveInteger || seconds > MAX_OPENCODE_START_TIMEOUT_SECONDS) {
5671
+ return {
5672
+ timeoutMs: defaultMs,
5673
+ warnings: [
5674
+ `Ignoring invalid ${source} "${raw}": expected a positive integer number of seconds (at most ${MAX_OPENCODE_START_TIMEOUT_SECONDS}); using the default ${DEFAULT_OPENCODE_START_TIMEOUT_SECONDS}s`
5675
+ ]
5676
+ };
5677
+ }
5678
+ return { timeoutMs: seconds * 1e3, warnings: [] };
5679
+ }
5257
5680
  function meetsThreshold(state, level) {
5258
5681
  return LOG_LEVELS[level] >= LOG_LEVELS[state.logLevel];
5259
5682
  }
@@ -5275,6 +5698,10 @@ function log2(state, message, level = "info") {
5275
5698
  function logActivity(state, entry) {
5276
5699
  const level = entry.level ?? (entry.type === "error" ? "error" : "info");
5277
5700
  if (!meetsThreshold(state, level)) return;
5701
+ forwardRunnerActivity(
5702
+ { level, message: entry.message, error: entry.error },
5703
+ { agentId: state.agentId, authHeader: state.authHeader }
5704
+ );
5278
5705
  const fullEntry = {
5279
5706
  ...entry,
5280
5707
  level,
@@ -5629,6 +6056,7 @@ async function run(options) {
5629
6056
  sessionCleanupTimers: [],
5630
6057
  authHeader: ""
5631
6058
  };
6059
+ setTelemetryAuthProvider(() => ({ authHeader: state.authHeader, agentId: state.agentId }));
5632
6060
  if (fileSyncDirectories.length > 0) {
5633
6061
  log2(state, `File sync enabled for: ${fileSyncDirectories.join(", ")}`);
5634
6062
  } else {
@@ -5817,40 +6245,52 @@ async function run(options) {
5817
6245
  } else {
5818
6246
  log2(state, "Not running in a MicroVM (MICROVM_ID unset) \u2014 nothing to report", "debug");
5819
6247
  }
6248
+ const { timeoutMs: opencodeStartTimeoutMs, warnings: opencodeStartTimeoutWarnings } = resolveOpenCodeStartTimeoutMs(options, process.env);
6249
+ for (const warning2 of opencodeStartTimeoutWarnings) {
6250
+ logActivity(state, { type: "info", level: "warn", message: warning2 });
6251
+ }
5820
6252
  const ocSpinner = interactive && !state.json ? ora3("Checking OpenCode...").start() : null;
5821
6253
  try {
5822
6254
  const oc = await ensureOpenCodeRunning({
5823
6255
  port: state.port,
5824
6256
  interactive: state.interactive,
5825
6257
  agentId: state.agentId,
5826
- log: (message) => log2(state, message)
6258
+ log: (message) => log2(state, message),
6259
+ startTimeoutMs: opencodeStartTimeoutMs
5827
6260
  });
5828
6261
  state.port = oc.port;
5829
6262
  state.opencodeProcess = oc.process;
5830
6263
  state.opencodeVersion = oc.version;
5831
- state.opencodeConnected = oc.process !== null || oc.version !== null;
6264
+ state.opencodeConnected = oc.notReadyReason === null;
5832
6265
  const version2 = state.opencodeVersion ? ` (v${state.opencodeVersion})` : "";
5833
6266
  ocSpinner?.succeed(`OpenCode running on port ${state.port}${version2}`);
5834
- const versionWarning = buildOpenCodeVersionWarning(state.opencodeVersion);
5835
- if (versionWarning) {
5836
- log2(state, versionWarning, "warn");
5837
- if (state.interactive && !state.json) {
5838
- logActivity(state, { type: "info", level: "warn", message: versionWarning });
6267
+ if (!state.interactive && oc.notReadyReason !== null) {
6268
+ const message = `OpenCode is not ready on port ${state.port}: ${oc.notReadyReason}. The runner will still come online, but messages will fail until opencode answers \u2014 raise the wait with --opencode-start-timeout <seconds> (env ${OPENCODE_START_TIMEOUT_ENV}).`;
6269
+ logActivity(state, { type: "info", level: "warn", message });
6270
+ } else {
6271
+ const versionWarning = buildOpenCodeVersionWarning(state.opencodeVersion);
6272
+ if (versionWarning) {
6273
+ log2(state, versionWarning, "warn");
6274
+ if (state.interactive && !state.json) {
6275
+ logActivity(state, { type: "info", level: "warn", message: versionWarning });
6276
+ }
5839
6277
  }
5840
- }
5841
- const noProviderWarning = buildNoProviderWarning(await hasAnyConfiguredProvider(state.port));
5842
- if (noProviderWarning) {
5843
- log2(state, noProviderWarning, "warn");
5844
- if (state.interactive && !state.json) {
5845
- logActivity(state, { type: "info", level: "warn", message: noProviderWarning });
5846
- blank();
5847
- console.log(chalk6.yellow("\u26A0 No OpenCode model provider is configured."));
5848
- console.log(
5849
- chalk6.dim(
5850
- `Run ${chalk6.cyan("opencode auth login")} to set one up \u2014 messages will fail until then.`
5851
- )
5852
- );
5853
- blank();
6278
+ const noProviderWarning = buildNoProviderWarning(
6279
+ await hasAnyConfiguredProvider(state.port)
6280
+ );
6281
+ if (noProviderWarning) {
6282
+ log2(state, noProviderWarning, "warn");
6283
+ if (state.interactive && !state.json) {
6284
+ logActivity(state, { type: "info", level: "warn", message: noProviderWarning });
6285
+ blank();
6286
+ console.log(chalk6.yellow("\u26A0 No OpenCode model provider is configured."));
6287
+ console.log(
6288
+ chalk6.dim(
6289
+ `Run ${chalk6.cyan("opencode auth login")} to set one up \u2014 messages will fail until then.`
6290
+ )
6291
+ );
6292
+ blank();
6293
+ }
5854
6294
  }
5855
6295
  }
5856
6296
  } catch (error2) {
@@ -5895,6 +6335,18 @@ async function run(options) {
5895
6335
  type: "info",
5896
6336
  message: `Tunnel ${isReconnect ? "reconnected" : "connected"} (runner: ${agentId})`
5897
6337
  });
6338
+ if (options.tunnelReadyFile) {
6339
+ const marker = writeTunnelReadyMarker(options.tunnelReadyFile, agentId);
6340
+ if (marker.ok) {
6341
+ log2(state, `Wrote tunnel readiness marker to ${options.tunnelReadyFile}`, "debug");
6342
+ } else {
6343
+ log2(
6344
+ state,
6345
+ `Failed to write tunnel readiness marker to ${options.tunnelReadyFile}: ${marker.error}`,
6346
+ "error"
6347
+ );
6348
+ }
6349
+ }
5898
6350
  emitAgentConnected(state.agentId, {
5899
6351
  port: state.port,
5900
6352
  cli_version: getCliVersion(),
@@ -6045,7 +6497,10 @@ program.command("run").description("Connect to Evident and process messages").op
6045
6497
  ).option("-p, --port <port>", "OpenCode port (default: 4096)", "4096").option(
6046
6498
  "--log-level <level>",
6047
6499
  "Log verbosity: debug | info | warn | error (default: info). Env: EVIDENT_LOG_LEVEL"
6048
- ).option("-v, --verbose", "Alias for --log-level debug (ignored if --log-level is set)").option("-c, --conversation <id>", "Process only this specific conversation").option("--idle-timeout <seconds>", "Exit after N seconds idle").option("--json", "Output in JSON format").option(
6500
+ ).option("-v, --verbose", "Alias for --log-level debug (ignored if --log-level is set)").option("-c, --conversation <id>", "Process only this specific conversation").option("--idle-timeout <seconds>", "Exit after N seconds idle").option(
6501
+ "--opencode-start-timeout <seconds>",
6502
+ "Seconds to wait for OpenCode to become healthy when the runner starts it (default: 180). Env: EVIDENT_OPENCODE_START_TIMEOUT"
6503
+ ).option("--json", "Output in JSON format").option(
6049
6504
  "--session-cleanup-max-age <duration>",
6050
6505
  "Delete OpenCode sessions idle longer than this (e.g. 7d, 24h). Enables cleanup. Env: EVIDENT_SESSION_CLEANUP_MAX_AGE"
6051
6506
  ).option(
@@ -6059,6 +6514,9 @@ program.command("run").description("Connect to Evident and process messages").op
6059
6514
  "Allow Evident to write files into this directory (repeatable). Omit to disable file sync entirely.",
6060
6515
  (value, previous) => previous.concat([value]),
6061
6516
  []
6517
+ ).option(
6518
+ "--tunnel-ready-file <path>",
6519
+ "Path to write once the tunnel is connected (set by the MicroVM hooks; unused on a developer machine)"
6062
6520
  ).action(
6063
6521
  (options) => {
6064
6522
  run({
@@ -6071,6 +6529,9 @@ program.command("run").description("Connect to Evident and process messages").op
6071
6529
  verbose: options.verbose,
6072
6530
  conversation: options.conversation,
6073
6531
  idleTimeout: options.idleTimeout ? parseInt(options.idleTimeout, 10) : void 0,
6532
+ // Raw string — validation/precedence is single-sourced in run.ts's
6533
+ // resolveOpenCodeStartTimeoutMs (flag > EVIDENT_OPENCODE_START_TIMEOUT > 180s default).
6534
+ opencodeStartTimeout: options.opencodeStartTimeout,
6074
6535
  json: options.json,
6075
6536
  // Raw strings — the resolver in run.ts single-sources parsing (M1).
6076
6537
  sessionCleanupMaxAge: options.sessionCleanupMaxAge,
@@ -6078,7 +6539,8 @@ program.command("run").description("Connect to Evident and process messages").op
6078
6539
  sessionCleanupInterval: options.sessionCleanupInterval,
6079
6540
  // Raw values — expansion/validation is single-sourced in run.ts's
6080
6541
  // resolveFileSyncDirectories.
6081
- enableFileSyncTo: options.enableFileSyncTo
6542
+ enableFileSyncTo: options.enableFileSyncTo,
6543
+ tunnelReadyFile: options.tunnelReadyFile
6082
6544
  });
6083
6545
  }
6084
6546
  );