@evident-ai/cli 3.1.1-dev.186f6ef → 3.1.1-dev.2f78b33

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
@@ -499,6 +499,12 @@ function log(level, event, fields) {
499
499
  );
500
500
  }
501
501
  }
502
+ function errorFields(err) {
503
+ if (err instanceof Error) {
504
+ return { error: err.message, error_name: err.name };
505
+ }
506
+ return { error: String(err) };
507
+ }
502
508
  function stripQuery(url) {
503
509
  try {
504
510
  return new URL(url).pathname;
@@ -734,7 +740,7 @@ function buildOpenCodeVersionWarning(version2) {
734
740
  if (isQueueValidatedVersion(version2)) return null;
735
741
  const detected = version2 ? `v${version2}` : "unknown";
736
742
  const validated = QUEUE_VALIDATED_OPENCODE_VERSIONS.map((v) => `v${v}`).join(", ");
737
- return `Warning: opencode ${detected} is not a queue-validated version (validated: ${validated}). Native message queuing \u2014 which channel (Slack/WhatsApp) message handling relies on \u2014 is unverified on this version; queued/follow-up messages may behave unexpectedly. Continuing anyway. Bumping the validated set requires re-running the queue validation.`;
743
+ return `Warning: opencode ${detected} is not a queue-validated version (validated: ${validated}). Native message queuing \u2014 which channel (Slack) message handling relies on \u2014 is unverified on this version; queued/follow-up messages may behave unexpectedly. Continuing anyway. Bumping the validated set requires re-running the queue validation.`;
738
744
  }
739
745
 
740
746
  // src/lib/opencode/process.ts
@@ -1026,6 +1032,12 @@ async function promptOpenCodeInstall(interactive) {
1026
1032
  return action;
1027
1033
  }
1028
1034
 
1035
+ // src/lib/opencode/provider-check.ts
1036
+ function buildNoProviderWarning(hasProvider) {
1037
+ if (hasProvider !== false) return null;
1038
+ return "Warning: opencode has no authenticated model provider configured, so it won't be able to answer prompts. Run `opencode auth login` to set one up (see https://opencode.ai for details).";
1039
+ }
1040
+
1029
1041
  // src/lib/opencode/session.ts
1030
1042
  function opencodeBase(port) {
1031
1043
  return `http://127.0.0.1:${port}`;
@@ -1228,6 +1240,11 @@ async function getModelAttachmentCapability(port, model) {
1228
1240
  }
1229
1241
  const entry = provider.models[modelId];
1230
1242
  if (!entry || typeof entry !== "object") return null;
1243
+ if (entry.capabilities && typeof entry.capabilities === "object") {
1244
+ if (typeof entry.capabilities.attachment === "boolean") {
1245
+ return entry.capabilities.attachment;
1246
+ }
1247
+ }
1231
1248
  return typeof entry.attachment === "boolean" ? entry.attachment : null;
1232
1249
  } catch (err) {
1233
1250
  console.error(
@@ -1256,6 +1273,16 @@ async function buildFileParts(attachments, capable) {
1256
1273
  );
1257
1274
  dataUrl = null;
1258
1275
  }
1276
+ if (dataUrl !== null && typeof dataUrl === "object") {
1277
+ outcomes.push({
1278
+ index: a.index,
1279
+ mime: a.mime,
1280
+ filename: a.filename,
1281
+ status: "failed",
1282
+ reason: "needs_reauth"
1283
+ });
1284
+ continue;
1285
+ }
1259
1286
  if (dataUrl == null) {
1260
1287
  outcomes.push({ index: a.index, mime: a.mime, filename: a.filename, status: "failed" });
1261
1288
  continue;
@@ -1484,6 +1511,37 @@ function hasRunningAssistantExcept(messages, exceptUserMessageId) {
1484
1511
  (m) => roleOf(m) === "assistant" && parentIdOf(m) !== exceptUserMessageId && isAssistantInFlight(m)
1485
1512
  );
1486
1513
  }
1514
+ async function hasAnyConfiguredProvider(port) {
1515
+ try {
1516
+ const res = await fetch(`${opencodeBase(port)}/config/providers`);
1517
+ if (!res.ok) {
1518
+ console.error(
1519
+ `[hasAnyConfiguredProvider] GET /config/providers returned HTTP ${res.status} (port ${port})`
1520
+ );
1521
+ return null;
1522
+ }
1523
+ const body = await res.json();
1524
+ if (!body || typeof body !== "object" || Array.isArray(body)) {
1525
+ console.error(
1526
+ `[hasAnyConfiguredProvider] GET /config/providers body was not a plain object (port ${port})`
1527
+ );
1528
+ return null;
1529
+ }
1530
+ const defaults2 = body.default;
1531
+ if (!defaults2 || typeof defaults2 !== "object" || Array.isArray(defaults2)) {
1532
+ console.error(
1533
+ `[hasAnyConfiguredProvider] GET /config/providers body had no \`default\` object (port ${port})`
1534
+ );
1535
+ return null;
1536
+ }
1537
+ return Object.keys(defaults2).length > 0;
1538
+ } catch (err) {
1539
+ console.error(
1540
+ `[hasAnyConfiguredProvider] GET /config/providers failed (port ${port}): ${err instanceof Error ? err.message : String(err)}`
1541
+ );
1542
+ return null;
1543
+ }
1544
+ }
1487
1545
 
1488
1546
  // src/lib/opencode/session-cleanup.ts
1489
1547
  var DURATION_UNIT_MS = {
@@ -1642,10 +1700,11 @@ var StreamForwarder = class {
1642
1700
  * Abort every in-flight stream (e.g. on WebSocket close).
1643
1701
  */
1644
1702
  abortAll() {
1645
- for (const stream of this.inflight.values()) {
1703
+ for (const [sid, stream] of this.inflight.entries()) {
1646
1704
  try {
1647
1705
  stream.abort();
1648
- } catch {
1706
+ } catch (err) {
1707
+ log("error", "forwarder_abort_failed", { sid, ...errorFields(err) });
1649
1708
  }
1650
1709
  }
1651
1710
  this.inflight.clear();
@@ -1795,7 +1854,6 @@ function connectTunnel(options) {
1795
1854
  onConnected,
1796
1855
  onDisconnected,
1797
1856
  onError,
1798
- onRequest,
1799
1857
  onResponse,
1800
1858
  onInfo,
1801
1859
  onDrainPing
@@ -1808,18 +1866,8 @@ function connectTunnel(options) {
1808
1866
  Authorization: authHeader
1809
1867
  }
1810
1868
  });
1811
- const streamStartTimes = /* @__PURE__ */ new Map();
1812
1869
  const forwarder = new StreamForwarder(ws, port, {
1813
- onOpen: (sid, method, path) => {
1814
- if (path === TUNNEL_DRAIN_PING_PATH) return;
1815
- streamStartTimes.set(sid, Date.now());
1816
- onRequest?.(method, path, sid);
1817
- },
1818
- onHead: (sid, status) => {
1819
- const startedAt = streamStartTimes.get(sid);
1820
- streamStartTimes.delete(sid);
1821
- onResponse?.(status, startedAt ? Date.now() - startedAt : 0, sid);
1822
- },
1870
+ onHead: () => onResponse?.(),
1823
1871
  onDrainPing: () => onDrainPing?.()
1824
1872
  });
1825
1873
  const connectionTimeout = setTimeout(() => {
@@ -1895,7 +1943,6 @@ function connectTunnel(options) {
1895
1943
  ws.on("close", (code, reason) => {
1896
1944
  const reasonStr = reason.toString() || upgradeRejection || (code === 1006 ? "abnormal closure" : "No reason provided");
1897
1945
  forwarder.abortAll();
1898
- streamStartTimes.clear();
1899
1946
  onDisconnected?.(code, reasonStr);
1900
1947
  });
1901
1948
  });
@@ -1930,7 +1977,11 @@ var RunnerConnection = class {
1930
1977
  if (this.connection) {
1931
1978
  try {
1932
1979
  this.connection.close();
1933
- } catch {
1980
+ } catch (err) {
1981
+ log("error", "runner_connection_close_failed", {
1982
+ agent_id: this.resolvedAgentId,
1983
+ ...errorFields(err)
1984
+ });
1934
1985
  }
1935
1986
  this.connection = null;
1936
1987
  }
@@ -2033,7 +2084,7 @@ function backoffDelay(attempt, policy) {
2033
2084
  function isRetryableStatus(status) {
2034
2085
  return status === 429 || status >= 500 && status <= 599;
2035
2086
  }
2036
- var ChannelDriver = class {
2087
+ var ChannelDriver = class _ChannelDriver {
2037
2088
  agentId;
2038
2089
  port;
2039
2090
  apiUrl;
@@ -2158,9 +2209,12 @@ var ChannelDriver = class {
2158
2209
  sessionParents = /* @__PURE__ */ new Map();
2159
2210
  /**
2160
2211
  * Per-session OpenCode title cache (#310), keyed by sessionId. Only a resolved
2161
- * NON-EMPTY name is stored (terminal — a real session name won't later un-name),
2162
- * so we do NOT re-GET `/session/:id` every tick. A missing entry = not yet
2163
- * resolved OR resolved-but-still-empty re-fetch on next need, since OpenCode
2212
+ * NON-EMPTY, non-placeholder name is stored (terminal — a real session name
2213
+ * won't later un-name), so we do NOT re-GET `/session/:id` every tick. "Non-empty"
2214
+ * excludes OpenCode's synchronous default title (see
2215
+ * `OPENCODE_DEFAULT_TITLE_PREFIX`, #549) — that placeholder is treated the same
2216
+ * as an empty title so it never latches. A missing entry = not yet resolved OR
2217
+ * resolved-but-still-empty/placeholder → re-fetch on next need, since OpenCode
2164
2218
  * names sessions asynchronously mid-turn. Driver-level (not per-watcher) so both
2165
2219
  * the watcher completion path AND the restart-recovery re-adopt path (which has
2166
2220
  * no watcher) can resolve the title.
@@ -2384,7 +2438,8 @@ var ChannelDriver = class {
2384
2438
  } catch (err) {
2385
2439
  if (err instanceof ChannelAuthError) throw err;
2386
2440
  this.dispatched.delete(message.id);
2387
- if (await sessionExists(this.port, sessionId) === false) {
2441
+ const exists = await sessionExists(this.port, sessionId);
2442
+ if (exists === false) {
2388
2443
  this.sessions.delete(conv.id);
2389
2444
  this.log({
2390
2445
  level: "warn",
@@ -2394,15 +2449,32 @@ var ChannelDriver = class {
2394
2449
  });
2395
2450
  break;
2396
2451
  }
2397
- await this.markFailed(conv.id, message.id).catch(() => {
2452
+ if (exists === null) {
2453
+ this.log({
2454
+ level: "warn",
2455
+ message: `Message ${message.id.slice(0, 8)} dispatch failed and session (${sessionId.slice(0, 8)}) existence could not be confirmed (opencode momentarily unreachable) \u2014 deferring this and later messages for conversation ${conv.id.slice(0, 8)} to the next tick rather than treating it as a genuine failure.`,
2456
+ conversation_id: conv.id,
2457
+ message_id: message.id
2458
+ });
2459
+ break;
2460
+ }
2461
+ const errorMessage = err instanceof Error ? err.message : String(err);
2462
+ this.sessions.delete(conv.id);
2463
+ await this.markFailed(conv.id, message.id, null, errorMessage).catch((markErr) => {
2464
+ this.log({
2465
+ level: "warn",
2466
+ message: `markFailed PATCH for message ${message.id.slice(0, 8)} (conversation ${conv.id.slice(0, 8)}) failed (best-effort, not retried): ${markErr instanceof Error ? markErr.message : String(markErr)}`,
2467
+ conversation_id: conv.id,
2468
+ message_id: message.id
2469
+ });
2398
2470
  });
2399
2471
  this.log({
2400
2472
  level: "error",
2401
- message: `Message ${message.id.slice(0, 8)} dispatch failed: ${err instanceof Error ? err.message : String(err)}`,
2473
+ message: `Message ${message.id.slice(0, 8)} dispatch failed: ${errorMessage}`,
2402
2474
  conversation_id: conv.id,
2403
2475
  message_id: message.id
2404
2476
  });
2405
- continue;
2477
+ break;
2406
2478
  }
2407
2479
  if (opencodeMessageId === null) {
2408
2480
  this.log({
@@ -2532,7 +2604,11 @@ var ChannelDriver = class {
2532
2604
  * (not-owned / out-of-range / deleted-at-source / workspace gone) / 413
2533
2605
  * (over-cap). On ANY non-2xx or thrown failure we return `null` so the caller
2534
2606
  * OMITS that one image and the text turn still sends — NEVER throws the turn.
2535
- * Failures are logged with context (no silent swallow).
2607
+ * A 404 body carrying `{ reason: 'needs_reauth' }` (#547 the server CONFIRMED
2608
+ * a Slack `files:read` scope problem via `files.info`) instead resolves the
2609
+ * `AttachmentFetchNeedsReauth` sentinel, so the in-thread note can steer the
2610
+ * user to reconnect Slack instead of a generic "unavailable". Failures are
2611
+ * logged with context (no silent swallow).
2536
2612
  */
2537
2613
  async fetchAttachmentDataUrl(messageId, index, mime) {
2538
2614
  try {
@@ -2541,6 +2617,25 @@ var ChannelDriver = class {
2541
2617
  { headers: { Authorization: this.getAuthHeader() } }
2542
2618
  );
2543
2619
  if (!res.ok) {
2620
+ let reason;
2621
+ try {
2622
+ const body = await res.json();
2623
+ if (body && typeof body.reason === "string") reason = body.reason;
2624
+ } catch (parseErr) {
2625
+ this.log({
2626
+ level: "debug",
2627
+ message: `Attachment fetch for message ${messageId.slice(0, 8)} index ${index}: error body was not JSON (${parseErr instanceof Error ? parseErr.message : String(parseErr)}) \u2014 treating as a plain failure`,
2628
+ message_id: messageId
2629
+ });
2630
+ }
2631
+ if (reason === "needs_reauth") {
2632
+ this.log({
2633
+ level: "error",
2634
+ message: `Attachment fetch for message ${messageId.slice(0, 8)} index ${index} returned HTTP ${res.status} \u2014 server confirmed a Slack reauth/scope problem \u2014 omitting this image (text turn proceeds)`,
2635
+ message_id: messageId
2636
+ });
2637
+ return { needsReauth: true };
2638
+ }
2544
2639
  this.log({
2545
2640
  level: "error",
2546
2641
  message: `Attachment fetch for message ${messageId.slice(0, 8)} index ${index} returned HTTP ${res.status} \u2014 omitting this image (text turn proceeds)`,
@@ -2580,6 +2675,9 @@ var ChannelDriver = class {
2580
2675
  if (this.attachmentsSkippedSignalled.has(messageId)) return;
2581
2676
  this.attachmentsSkippedSignalled.add(messageId);
2582
2677
  const skippedReason = capabilityUnknown ? "unknown" : "unsupported";
2678
+ const failedReason = outcomes.some(
2679
+ (o) => o.status === "failed" && o.reason === "needs_reauth"
2680
+ ) ? "needs_reauth" : void 0;
2583
2681
  this.log({
2584
2682
  level: "info",
2585
2683
  message: `Message ${messageId.slice(0, 8)}: ${skipped} image(s) skipped (${capabilityUnknown ? "capability was unreadable \u2014 failed open to text-only" : "model not attachment-capable"}), ${failed} image(s) unavailable (deleted-at-source or fetch failure) \u2014 noting to Evident`,
@@ -2589,7 +2687,8 @@ var ChannelDriver = class {
2589
2687
  void this.postSignal(conversationId, messageId, "attachments_skipped", {
2590
2688
  skipped,
2591
2689
  failed,
2592
- ...skipped > 0 ? { skipped_reason: skippedReason } : {}
2690
+ ...skipped > 0 ? { skipped_reason: skippedReason } : {},
2691
+ ...failedReason ? { failed_reason: failedReason } : {}
2593
2692
  });
2594
2693
  }
2595
2694
  /** Register a freshly-dispatched message with its session's watcher state. */
@@ -3628,19 +3727,36 @@ var ChannelDriver = class {
3628
3727
  if (parent !== void 0) this.sessionParents.set(sessionId, parent);
3629
3728
  return parent;
3630
3729
  }
3730
+ /**
3731
+ * OpenCode's synchronous default session title (e.g.
3732
+ * `"New session - 1737800000000"`), assigned immediately when a session is
3733
+ * created — before OpenCode's async LLM-based auto-titling later renames it
3734
+ * mid-turn (#549). Matched by this literal, case-sensitive prefix only; the
3735
+ * timestamp suffix's exact format is deliberately NOT matched, since the prefix
3736
+ * alone is the stable, cheap signal and over-anchoring on the timestamp
3737
+ * representation risks silently breaking if OpenCode ever changes it. Accepted
3738
+ * trade-off: a genuine LLM-assigned title that happens to literally start with
3739
+ * this prefix would also fail to latch (see `resolveSessionTitle`) —
3740
+ * vanishingly unlikely in practice, and deliberately not engineered around.
3741
+ */
3742
+ static OPENCODE_DEFAULT_TITLE_PREFIX = /^New session - /;
3631
3743
  /**
3632
3744
  * Resolve (and cache in `sessionTitles`) the OpenCode session TITLE (#310) so the
3633
3745
  * status PATCH can carry it into the "Live sessions" list. Driver-level cache so
3634
3746
  * BOTH the watcher completion path and the restart-recovery re-adopt path (which
3635
3747
  * has no watcher) can use it. `conversationId` is passed only for log context.
3636
3748
  * Best-effort:
3637
- * - a resolved NON-EMPTY title is cached and terminal (a real session name
3749
+ * - a resolved NON-EMPTY title that does NOT match
3750
+ * `OPENCODE_DEFAULT_TITLE_PREFIX` is cached and terminal (a real session name
3638
3751
  * won't later un-name), so we do NOT re-GET `/session/:id` every tick;
3639
- * - while the title is still absent/empty we do NOT latch it — OpenCode names
3640
- * sessions asynchronously mid-turn, so an early call (e.g. at `processing`)
3641
- * must leave the cache unresolved and re-fetch on the next need so a later
3642
- * call (e.g. at `done`) picks up the name assigned in the meantime. Such a
3643
- * call returns `null` (omit the title on THIS PATCH) without caching;
3752
+ * - while the title is still absent, empty, or matches the OpenCode
3753
+ * placeholder prefix (#549) we do NOT latch it OpenCode names sessions
3754
+ * asynchronously mid-turn, so an early call (e.g. at `processing`) must leave
3755
+ * the cache unresolved and re-fetch on the next need so a later call (e.g. at
3756
+ * `done`) picks up the name assigned in the meantime. Such a call returns
3757
+ * `null` (omit the title on THIS PATCH) without caching. If a session is
3758
+ * never renamed, the title is omitted forever rather than ever persisting
3759
+ * the placeholder as a last resort;
3644
3760
  * - a failed request likewise leaves the cache unresolved (retry next need)
3645
3761
  * and returns `null` — it must NEVER throw or block completion.
3646
3762
  * A failure is logged with agent/session context (no silent catch).
@@ -3653,7 +3769,7 @@ var ChannelDriver = class {
3653
3769
  if (res.ok) {
3654
3770
  const body = await res.json();
3655
3771
  const title = body && typeof body.title === "string" ? body.title.trim() : "";
3656
- if (title.length > 0) {
3772
+ if (title.length > 0 && !_ChannelDriver.OPENCODE_DEFAULT_TITLE_PREFIX.test(title)) {
3657
3773
  this.sessionTitles.set(sessionId, title);
3658
3774
  return title;
3659
3775
  }
@@ -3953,10 +4069,15 @@ var ChannelDriver = class {
3953
4069
  }
3954
4070
  /**
3955
4071
  * Mark a message `failed`. `sessionId` / `error` are threaded to the API ONLY
3956
- * when provided (issue #182): a bare `markFailed(conv, msg)` sends
3957
- * `{status:'failed'}` unchanged (the dispatch-failure path), while an errored
3958
- * OpenCode turn sends `{status:'failed', opencode_session_id, error}` so the
3959
- * failure reason reaches the channel.
4072
+ * when provided (issue #182). Three states for `sessionId`:
4073
+ * - omitted (`undefined`) → don't send the field, leave the persisted
4074
+ * session untouched (unused today; kept for API symmetry).
4075
+ * - a real id (`string`) → send it, update the persisted session (the
4076
+ * turn-failure call sites: an errored OpenCode turn).
4077
+ * - explicit `null` → send it, CLEAR the persisted session (issue
4078
+ * #485's dispatch-handoff-failure call site: the session id still
4079
+ * exists but is wedged, so the next attempt must get a fresh one
4080
+ * instead of reusing it — see WI-1's server-side null-clearing PATCH).
3960
4081
  */
3961
4082
  async markFailed(conversationId, messageId, sessionId, error2, usage) {
3962
4083
  const body = { status: "failed" };
@@ -4726,6 +4847,11 @@ async function run(options) {
4726
4847
  { command: "run" },
4727
4848
  state.agentId
4728
4849
  );
4850
+ const agentFlagNotice = "--agent is deprecated, use --runner instead; will be removed in a future release.";
4851
+ log2(state, agentFlagNotice, "warn");
4852
+ if (state.interactive && !state.json) {
4853
+ logActivity(state, { type: "info", level: "warn", message: agentFlagNotice });
4854
+ }
4729
4855
  }
4730
4856
  if (state.idleTimeout === null && (process.env.GITHUB_ACTIONS || process.env.CI)) {
4731
4857
  log2(
@@ -4784,6 +4910,11 @@ async function run(options) {
4784
4910
  { command: "run" },
4785
4911
  state.agentId
4786
4912
  );
4913
+ const agentKeyNotice = "EVIDENT_AGENT_KEY is deprecated, use EVIDENT_RUNNER_KEY instead; will be removed in a future release.";
4914
+ log2(state, agentKeyNotice, "warn");
4915
+ if (state.interactive && !state.json) {
4916
+ logActivity(state, { type: "info", level: "warn", message: agentKeyNotice });
4917
+ }
4787
4918
  }
4788
4919
  if (!state.agentId) {
4789
4920
  if (credentials2.authType === "agent_key") {
@@ -4874,6 +5005,21 @@ async function run(options) {
4874
5005
  logActivity(state, { type: "info", level: "warn", message: versionWarning });
4875
5006
  }
4876
5007
  }
5008
+ const noProviderWarning = buildNoProviderWarning(await hasAnyConfiguredProvider(state.port));
5009
+ if (noProviderWarning) {
5010
+ log2(state, noProviderWarning, "warn");
5011
+ if (state.interactive && !state.json) {
5012
+ logActivity(state, { type: "info", level: "warn", message: noProviderWarning });
5013
+ blank();
5014
+ console.log(chalk6.yellow("\u26A0 No OpenCode model provider is configured."));
5015
+ console.log(
5016
+ chalk6.dim(
5017
+ `Run ${chalk6.cyan("opencode auth login")} to set one up \u2014 messages will fail until then.`
5018
+ )
5019
+ );
5020
+ blank();
5021
+ }
5022
+ }
4877
5023
  } catch (error2) {
4878
5024
  ocSpinner?.fail(error2.message);
4879
5025
  throw error2;