@evident-ai/cli 3.1.1-dev.bf45828 → 3.1.1-dev.c3aab2f

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
@@ -734,7 +734,7 @@ function buildOpenCodeVersionWarning(version2) {
734
734
  if (isQueueValidatedVersion(version2)) return null;
735
735
  const detected = version2 ? `v${version2}` : "unknown";
736
736
  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.`;
737
+ 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
738
  }
739
739
 
740
740
  // src/lib/opencode/process.ts
@@ -1026,6 +1026,12 @@ async function promptOpenCodeInstall(interactive) {
1026
1026
  return action;
1027
1027
  }
1028
1028
 
1029
+ // src/lib/opencode/provider-check.ts
1030
+ function buildNoProviderWarning(hasProvider) {
1031
+ if (hasProvider !== false) return null;
1032
+ 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).";
1033
+ }
1034
+
1029
1035
  // src/lib/opencode/session.ts
1030
1036
  function opencodeBase(port) {
1031
1037
  return `http://127.0.0.1:${port}`;
@@ -1228,6 +1234,11 @@ async function getModelAttachmentCapability(port, model) {
1228
1234
  }
1229
1235
  const entry = provider.models[modelId];
1230
1236
  if (!entry || typeof entry !== "object") return null;
1237
+ if (entry.capabilities && typeof entry.capabilities === "object") {
1238
+ if (typeof entry.capabilities.attachment === "boolean") {
1239
+ return entry.capabilities.attachment;
1240
+ }
1241
+ }
1231
1242
  return typeof entry.attachment === "boolean" ? entry.attachment : null;
1232
1243
  } catch (err) {
1233
1244
  console.error(
@@ -1256,6 +1267,16 @@ async function buildFileParts(attachments, capable) {
1256
1267
  );
1257
1268
  dataUrl = null;
1258
1269
  }
1270
+ if (dataUrl !== null && typeof dataUrl === "object") {
1271
+ outcomes.push({
1272
+ index: a.index,
1273
+ mime: a.mime,
1274
+ filename: a.filename,
1275
+ status: "failed",
1276
+ reason: "needs_reauth"
1277
+ });
1278
+ continue;
1279
+ }
1259
1280
  if (dataUrl == null) {
1260
1281
  outcomes.push({ index: a.index, mime: a.mime, filename: a.filename, status: "failed" });
1261
1282
  continue;
@@ -1484,6 +1505,37 @@ function hasRunningAssistantExcept(messages, exceptUserMessageId) {
1484
1505
  (m) => roleOf(m) === "assistant" && parentIdOf(m) !== exceptUserMessageId && isAssistantInFlight(m)
1485
1506
  );
1486
1507
  }
1508
+ async function hasAnyConfiguredProvider(port) {
1509
+ try {
1510
+ const res = await fetch(`${opencodeBase(port)}/config/providers`);
1511
+ if (!res.ok) {
1512
+ console.error(
1513
+ `[hasAnyConfiguredProvider] GET /config/providers returned HTTP ${res.status} (port ${port})`
1514
+ );
1515
+ return null;
1516
+ }
1517
+ const body = await res.json();
1518
+ if (!body || typeof body !== "object" || Array.isArray(body)) {
1519
+ console.error(
1520
+ `[hasAnyConfiguredProvider] GET /config/providers body was not a plain object (port ${port})`
1521
+ );
1522
+ return null;
1523
+ }
1524
+ const defaults2 = body.default;
1525
+ if (!defaults2 || typeof defaults2 !== "object" || Array.isArray(defaults2)) {
1526
+ console.error(
1527
+ `[hasAnyConfiguredProvider] GET /config/providers body had no \`default\` object (port ${port})`
1528
+ );
1529
+ return null;
1530
+ }
1531
+ return Object.keys(defaults2).length > 0;
1532
+ } catch (err) {
1533
+ console.error(
1534
+ `[hasAnyConfiguredProvider] GET /config/providers failed (port ${port}): ${err instanceof Error ? err.message : String(err)}`
1535
+ );
1536
+ return null;
1537
+ }
1538
+ }
1487
1539
 
1488
1540
  // src/lib/opencode/session-cleanup.ts
1489
1541
  var DURATION_UNIT_MS = {
@@ -2021,7 +2073,7 @@ function backoffDelay(attempt, policy) {
2021
2073
  function isRetryableStatus(status) {
2022
2074
  return status === 429 || status >= 500 && status <= 599;
2023
2075
  }
2024
- var ChannelDriver = class {
2076
+ var ChannelDriver = class _ChannelDriver {
2025
2077
  agentId;
2026
2078
  port;
2027
2079
  apiUrl;
@@ -2146,9 +2198,12 @@ var ChannelDriver = class {
2146
2198
  sessionParents = /* @__PURE__ */ new Map();
2147
2199
  /**
2148
2200
  * Per-session OpenCode title cache (#310), keyed by sessionId. Only a resolved
2149
- * NON-EMPTY name is stored (terminal — a real session name won't later un-name),
2150
- * so we do NOT re-GET `/session/:id` every tick. A missing entry = not yet
2151
- * resolved OR resolved-but-still-empty re-fetch on next need, since OpenCode
2201
+ * NON-EMPTY, non-placeholder name is stored (terminal — a real session name
2202
+ * won't later un-name), so we do NOT re-GET `/session/:id` every tick. "Non-empty"
2203
+ * excludes OpenCode's synchronous default title (see
2204
+ * `OPENCODE_DEFAULT_TITLE_PREFIX`, #549) — that placeholder is treated the same
2205
+ * as an empty title so it never latches. A missing entry = not yet resolved OR
2206
+ * resolved-but-still-empty/placeholder → re-fetch on next need, since OpenCode
2152
2207
  * names sessions asynchronously mid-turn. Driver-level (not per-watcher) so both
2153
2208
  * the watcher completion path AND the restart-recovery re-adopt path (which has
2154
2209
  * no watcher) can resolve the title.
@@ -2372,7 +2427,8 @@ var ChannelDriver = class {
2372
2427
  } catch (err) {
2373
2428
  if (err instanceof ChannelAuthError) throw err;
2374
2429
  this.dispatched.delete(message.id);
2375
- if (await sessionExists(this.port, sessionId) === false) {
2430
+ const exists = await sessionExists(this.port, sessionId);
2431
+ if (exists === false) {
2376
2432
  this.sessions.delete(conv.id);
2377
2433
  this.log({
2378
2434
  level: "warn",
@@ -2382,15 +2438,32 @@ var ChannelDriver = class {
2382
2438
  });
2383
2439
  break;
2384
2440
  }
2385
- await this.markFailed(conv.id, message.id).catch(() => {
2441
+ if (exists === null) {
2442
+ this.log({
2443
+ level: "warn",
2444
+ 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.`,
2445
+ conversation_id: conv.id,
2446
+ message_id: message.id
2447
+ });
2448
+ break;
2449
+ }
2450
+ const errorMessage = err instanceof Error ? err.message : String(err);
2451
+ this.sessions.delete(conv.id);
2452
+ await this.markFailed(conv.id, message.id, null, errorMessage).catch((markErr) => {
2453
+ this.log({
2454
+ level: "warn",
2455
+ 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)}`,
2456
+ conversation_id: conv.id,
2457
+ message_id: message.id
2458
+ });
2386
2459
  });
2387
2460
  this.log({
2388
2461
  level: "error",
2389
- message: `Message ${message.id.slice(0, 8)} dispatch failed: ${err instanceof Error ? err.message : String(err)}`,
2462
+ message: `Message ${message.id.slice(0, 8)} dispatch failed: ${errorMessage}`,
2390
2463
  conversation_id: conv.id,
2391
2464
  message_id: message.id
2392
2465
  });
2393
- continue;
2466
+ break;
2394
2467
  }
2395
2468
  if (opencodeMessageId === null) {
2396
2469
  this.log({
@@ -2520,7 +2593,11 @@ var ChannelDriver = class {
2520
2593
  * (not-owned / out-of-range / deleted-at-source / workspace gone) / 413
2521
2594
  * (over-cap). On ANY non-2xx or thrown failure we return `null` so the caller
2522
2595
  * OMITS that one image and the text turn still sends — NEVER throws the turn.
2523
- * Failures are logged with context (no silent swallow).
2596
+ * A 404 body carrying `{ reason: 'needs_reauth' }` (#547 the server CONFIRMED
2597
+ * a Slack `files:read` scope problem via `files.info`) instead resolves the
2598
+ * `AttachmentFetchNeedsReauth` sentinel, so the in-thread note can steer the
2599
+ * user to reconnect Slack instead of a generic "unavailable". Failures are
2600
+ * logged with context (no silent swallow).
2524
2601
  */
2525
2602
  async fetchAttachmentDataUrl(messageId, index, mime) {
2526
2603
  try {
@@ -2529,6 +2606,25 @@ var ChannelDriver = class {
2529
2606
  { headers: { Authorization: this.getAuthHeader() } }
2530
2607
  );
2531
2608
  if (!res.ok) {
2609
+ let reason;
2610
+ try {
2611
+ const body = await res.json();
2612
+ if (body && typeof body.reason === "string") reason = body.reason;
2613
+ } catch (parseErr) {
2614
+ this.log({
2615
+ level: "debug",
2616
+ 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`,
2617
+ message_id: messageId
2618
+ });
2619
+ }
2620
+ if (reason === "needs_reauth") {
2621
+ this.log({
2622
+ level: "error",
2623
+ 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)`,
2624
+ message_id: messageId
2625
+ });
2626
+ return { needsReauth: true };
2627
+ }
2532
2628
  this.log({
2533
2629
  level: "error",
2534
2630
  message: `Attachment fetch for message ${messageId.slice(0, 8)} index ${index} returned HTTP ${res.status} \u2014 omitting this image (text turn proceeds)`,
@@ -2568,6 +2664,9 @@ var ChannelDriver = class {
2568
2664
  if (this.attachmentsSkippedSignalled.has(messageId)) return;
2569
2665
  this.attachmentsSkippedSignalled.add(messageId);
2570
2666
  const skippedReason = capabilityUnknown ? "unknown" : "unsupported";
2667
+ const failedReason = outcomes.some(
2668
+ (o) => o.status === "failed" && o.reason === "needs_reauth"
2669
+ ) ? "needs_reauth" : void 0;
2571
2670
  this.log({
2572
2671
  level: "info",
2573
2672
  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`,
@@ -2577,7 +2676,8 @@ var ChannelDriver = class {
2577
2676
  void this.postSignal(conversationId, messageId, "attachments_skipped", {
2578
2677
  skipped,
2579
2678
  failed,
2580
- ...skipped > 0 ? { skipped_reason: skippedReason } : {}
2679
+ ...skipped > 0 ? { skipped_reason: skippedReason } : {},
2680
+ ...failedReason ? { failed_reason: failedReason } : {}
2581
2681
  });
2582
2682
  }
2583
2683
  /** Register a freshly-dispatched message with its session's watcher state. */
@@ -3616,19 +3716,36 @@ var ChannelDriver = class {
3616
3716
  if (parent !== void 0) this.sessionParents.set(sessionId, parent);
3617
3717
  return parent;
3618
3718
  }
3719
+ /**
3720
+ * OpenCode's synchronous default session title (e.g.
3721
+ * `"New session - 1737800000000"`), assigned immediately when a session is
3722
+ * created — before OpenCode's async LLM-based auto-titling later renames it
3723
+ * mid-turn (#549). Matched by this literal, case-sensitive prefix only; the
3724
+ * timestamp suffix's exact format is deliberately NOT matched, since the prefix
3725
+ * alone is the stable, cheap signal and over-anchoring on the timestamp
3726
+ * representation risks silently breaking if OpenCode ever changes it. Accepted
3727
+ * trade-off: a genuine LLM-assigned title that happens to literally start with
3728
+ * this prefix would also fail to latch (see `resolveSessionTitle`) —
3729
+ * vanishingly unlikely in practice, and deliberately not engineered around.
3730
+ */
3731
+ static OPENCODE_DEFAULT_TITLE_PREFIX = /^New session - /;
3619
3732
  /**
3620
3733
  * Resolve (and cache in `sessionTitles`) the OpenCode session TITLE (#310) so the
3621
3734
  * status PATCH can carry it into the "Live sessions" list. Driver-level cache so
3622
3735
  * BOTH the watcher completion path and the restart-recovery re-adopt path (which
3623
3736
  * has no watcher) can use it. `conversationId` is passed only for log context.
3624
3737
  * Best-effort:
3625
- * - a resolved NON-EMPTY title is cached and terminal (a real session name
3738
+ * - a resolved NON-EMPTY title that does NOT match
3739
+ * `OPENCODE_DEFAULT_TITLE_PREFIX` is cached and terminal (a real session name
3626
3740
  * won't later un-name), so we do NOT re-GET `/session/:id` every tick;
3627
- * - while the title is still absent/empty we do NOT latch it — OpenCode names
3628
- * sessions asynchronously mid-turn, so an early call (e.g. at `processing`)
3629
- * must leave the cache unresolved and re-fetch on the next need so a later
3630
- * call (e.g. at `done`) picks up the name assigned in the meantime. Such a
3631
- * call returns `null` (omit the title on THIS PATCH) without caching;
3741
+ * - while the title is still absent, empty, or matches the OpenCode
3742
+ * placeholder prefix (#549) we do NOT latch it OpenCode names sessions
3743
+ * asynchronously mid-turn, so an early call (e.g. at `processing`) must leave
3744
+ * the cache unresolved and re-fetch on the next need so a later call (e.g. at
3745
+ * `done`) picks up the name assigned in the meantime. Such a call returns
3746
+ * `null` (omit the title on THIS PATCH) without caching. If a session is
3747
+ * never renamed, the title is omitted forever rather than ever persisting
3748
+ * the placeholder as a last resort;
3632
3749
  * - a failed request likewise leaves the cache unresolved (retry next need)
3633
3750
  * and returns `null` — it must NEVER throw or block completion.
3634
3751
  * A failure is logged with agent/session context (no silent catch).
@@ -3641,7 +3758,7 @@ var ChannelDriver = class {
3641
3758
  if (res.ok) {
3642
3759
  const body = await res.json();
3643
3760
  const title = body && typeof body.title === "string" ? body.title.trim() : "";
3644
- if (title.length > 0) {
3761
+ if (title.length > 0 && !_ChannelDriver.OPENCODE_DEFAULT_TITLE_PREFIX.test(title)) {
3645
3762
  this.sessionTitles.set(sessionId, title);
3646
3763
  return title;
3647
3764
  }
@@ -3941,10 +4058,15 @@ var ChannelDriver = class {
3941
4058
  }
3942
4059
  /**
3943
4060
  * Mark a message `failed`. `sessionId` / `error` are threaded to the API ONLY
3944
- * when provided (issue #182): a bare `markFailed(conv, msg)` sends
3945
- * `{status:'failed'}` unchanged (the dispatch-failure path), while an errored
3946
- * OpenCode turn sends `{status:'failed', opencode_session_id, error}` so the
3947
- * failure reason reaches the channel.
4061
+ * when provided (issue #182). Three states for `sessionId`:
4062
+ * - omitted (`undefined`) → don't send the field, leave the persisted
4063
+ * session untouched (unused today; kept for API symmetry).
4064
+ * - a real id (`string`) → send it, update the persisted session (the
4065
+ * turn-failure call sites: an errored OpenCode turn).
4066
+ * - explicit `null` → send it, CLEAR the persisted session (issue
4067
+ * #485's dispatch-handoff-failure call site: the session id still
4068
+ * exists but is wedged, so the next attempt must get a fresh one
4069
+ * instead of reusing it — see WI-1's server-side null-clearing PATCH).
3948
4070
  */
3949
4071
  async markFailed(conversationId, messageId, sessionId, error2, usage) {
3950
4072
  const body = { status: "failed" };
@@ -4872,6 +4994,21 @@ async function run(options) {
4872
4994
  logActivity(state, { type: "info", level: "warn", message: versionWarning });
4873
4995
  }
4874
4996
  }
4997
+ const noProviderWarning = buildNoProviderWarning(await hasAnyConfiguredProvider(state.port));
4998
+ if (noProviderWarning) {
4999
+ log2(state, noProviderWarning, "warn");
5000
+ if (state.interactive && !state.json) {
5001
+ logActivity(state, { type: "info", level: "warn", message: noProviderWarning });
5002
+ blank();
5003
+ console.log(chalk6.yellow("\u26A0 No OpenCode model provider is configured."));
5004
+ console.log(
5005
+ chalk6.dim(
5006
+ `Run ${chalk6.cyan("opencode auth login")} to set one up \u2014 messages will fail until then.`
5007
+ )
5008
+ );
5009
+ blank();
5010
+ }
5011
+ }
4875
5012
  } catch (error2) {
4876
5013
  ocSpinner?.fail(error2.message);
4877
5014
  throw error2;