@evident-ai/cli 3.1.1-dev.e69750c → 3.1.1-dev.f24491c

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
@@ -645,7 +645,11 @@ var EventTypes = {
645
645
  // CLI lifecycle
646
646
  CLI_STARTED: "cli.started",
647
647
  CLI_COMMAND: "cli.command",
648
- CLI_ERROR: "cli.error"
648
+ CLI_ERROR: "cli.error",
649
+ // Deprecation telemetry (#412) — usage of the old `--agent`/`EVIDENT_AGENT_KEY`
650
+ // names instead of the preferred `--runner`/`EVIDENT_RUNNER_KEY` (#409).
651
+ DEPRECATED_AGENT_FLAG_USED: "cli.deprecated_agent_flag_used",
652
+ DEPRECATED_AGENT_KEY_ENV_USED: "cli.deprecated_agent_key_env_used"
649
653
  };
650
654
 
651
655
  // src/lib/auth.ts
@@ -656,11 +660,12 @@ async function getAuthCredentials() {
656
660
  return {
657
661
  token: runnerKey,
658
662
  authType: "agent_key",
663
+ keySource: "runner_key",
659
664
  notice: agentKey ? "Both EVIDENT_RUNNER_KEY and EVIDENT_AGENT_KEY are set; using EVIDENT_RUNNER_KEY." : void 0
660
665
  };
661
666
  }
662
667
  if (agentKey) {
663
- return { token: agentKey, authType: "agent_key" };
668
+ return { token: agentKey, authType: "agent_key", keySource: "agent_key" };
664
669
  }
665
670
  const userToken = process.env.EVIDENT_TOKEN;
666
671
  if (userToken) {
@@ -729,7 +734,7 @@ function buildOpenCodeVersionWarning(version2) {
729
734
  if (isQueueValidatedVersion(version2)) return null;
730
735
  const detected = version2 ? `v${version2}` : "unknown";
731
736
  const validated = QUEUE_VALIDATED_OPENCODE_VERSIONS.map((v) => `v${v}`).join(", ");
732
- 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.`;
733
738
  }
734
739
 
735
740
  // src/lib/opencode/process.ts
@@ -1021,6 +1026,12 @@ async function promptOpenCodeInstall(interactive) {
1021
1026
  return action;
1022
1027
  }
1023
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
+
1024
1035
  // src/lib/opencode/session.ts
1025
1036
  function opencodeBase(port) {
1026
1037
  return `http://127.0.0.1:${port}`;
@@ -1223,6 +1234,11 @@ async function getModelAttachmentCapability(port, model) {
1223
1234
  }
1224
1235
  const entry = provider.models[modelId];
1225
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
+ }
1226
1242
  return typeof entry.attachment === "boolean" ? entry.attachment : null;
1227
1243
  } catch (err) {
1228
1244
  console.error(
@@ -1251,6 +1267,16 @@ async function buildFileParts(attachments, capable) {
1251
1267
  );
1252
1268
  dataUrl = null;
1253
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
+ }
1254
1280
  if (dataUrl == null) {
1255
1281
  outcomes.push({ index: a.index, mime: a.mime, filename: a.filename, status: "failed" });
1256
1282
  continue;
@@ -1479,6 +1505,37 @@ function hasRunningAssistantExcept(messages, exceptUserMessageId) {
1479
1505
  (m) => roleOf(m) === "assistant" && parentIdOf(m) !== exceptUserMessageId && isAssistantInFlight(m)
1480
1506
  );
1481
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
+ }
1482
1539
 
1483
1540
  // src/lib/opencode/session-cleanup.ts
1484
1541
  var DURATION_UNIT_MS = {
@@ -1790,7 +1847,6 @@ function connectTunnel(options) {
1790
1847
  onConnected,
1791
1848
  onDisconnected,
1792
1849
  onError,
1793
- onRequest,
1794
1850
  onResponse,
1795
1851
  onInfo,
1796
1852
  onDrainPing
@@ -1803,18 +1859,8 @@ function connectTunnel(options) {
1803
1859
  Authorization: authHeader
1804
1860
  }
1805
1861
  });
1806
- const streamStartTimes = /* @__PURE__ */ new Map();
1807
1862
  const forwarder = new StreamForwarder(ws, port, {
1808
- onOpen: (sid, method, path) => {
1809
- if (path === TUNNEL_DRAIN_PING_PATH) return;
1810
- streamStartTimes.set(sid, Date.now());
1811
- onRequest?.(method, path, sid);
1812
- },
1813
- onHead: (sid, status) => {
1814
- const startedAt = streamStartTimes.get(sid);
1815
- streamStartTimes.delete(sid);
1816
- onResponse?.(status, startedAt ? Date.now() - startedAt : 0, sid);
1817
- },
1863
+ onHead: () => onResponse?.(),
1818
1864
  onDrainPing: () => onDrainPing?.()
1819
1865
  });
1820
1866
  const connectionTimeout = setTimeout(() => {
@@ -1890,7 +1936,6 @@ function connectTunnel(options) {
1890
1936
  ws.on("close", (code, reason) => {
1891
1937
  const reasonStr = reason.toString() || upgradeRejection || (code === 1006 ? "abnormal closure" : "No reason provided");
1892
1938
  forwarder.abortAll();
1893
- streamStartTimes.clear();
1894
1939
  onDisconnected?.(code, reasonStr);
1895
1940
  });
1896
1941
  });
@@ -2028,7 +2073,7 @@ function backoffDelay(attempt, policy) {
2028
2073
  function isRetryableStatus(status) {
2029
2074
  return status === 429 || status >= 500 && status <= 599;
2030
2075
  }
2031
- var ChannelDriver = class {
2076
+ var ChannelDriver = class _ChannelDriver {
2032
2077
  agentId;
2033
2078
  port;
2034
2079
  apiUrl;
@@ -2153,9 +2198,12 @@ var ChannelDriver = class {
2153
2198
  sessionParents = /* @__PURE__ */ new Map();
2154
2199
  /**
2155
2200
  * Per-session OpenCode title cache (#310), keyed by sessionId. Only a resolved
2156
- * NON-EMPTY name is stored (terminal — a real session name won't later un-name),
2157
- * so we do NOT re-GET `/session/:id` every tick. A missing entry = not yet
2158
- * 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
2159
2207
  * names sessions asynchronously mid-turn. Driver-level (not per-watcher) so both
2160
2208
  * the watcher completion path AND the restart-recovery re-adopt path (which has
2161
2209
  * no watcher) can resolve the title.
@@ -2527,7 +2575,11 @@ var ChannelDriver = class {
2527
2575
  * (not-owned / out-of-range / deleted-at-source / workspace gone) / 413
2528
2576
  * (over-cap). On ANY non-2xx or thrown failure we return `null` so the caller
2529
2577
  * OMITS that one image and the text turn still sends — NEVER throws the turn.
2530
- * Failures are logged with context (no silent swallow).
2578
+ * A 404 body carrying `{ reason: 'needs_reauth' }` (#547 the server CONFIRMED
2579
+ * a Slack `files:read` scope problem via `files.info`) instead resolves the
2580
+ * `AttachmentFetchNeedsReauth` sentinel, so the in-thread note can steer the
2581
+ * user to reconnect Slack instead of a generic "unavailable". Failures are
2582
+ * logged with context (no silent swallow).
2531
2583
  */
2532
2584
  async fetchAttachmentDataUrl(messageId, index, mime) {
2533
2585
  try {
@@ -2536,6 +2588,25 @@ var ChannelDriver = class {
2536
2588
  { headers: { Authorization: this.getAuthHeader() } }
2537
2589
  );
2538
2590
  if (!res.ok) {
2591
+ let reason;
2592
+ try {
2593
+ const body = await res.json();
2594
+ if (body && typeof body.reason === "string") reason = body.reason;
2595
+ } catch (parseErr) {
2596
+ this.log({
2597
+ level: "debug",
2598
+ 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`,
2599
+ message_id: messageId
2600
+ });
2601
+ }
2602
+ if (reason === "needs_reauth") {
2603
+ this.log({
2604
+ level: "error",
2605
+ 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)`,
2606
+ message_id: messageId
2607
+ });
2608
+ return { needsReauth: true };
2609
+ }
2539
2610
  this.log({
2540
2611
  level: "error",
2541
2612
  message: `Attachment fetch for message ${messageId.slice(0, 8)} index ${index} returned HTTP ${res.status} \u2014 omitting this image (text turn proceeds)`,
@@ -2575,6 +2646,9 @@ var ChannelDriver = class {
2575
2646
  if (this.attachmentsSkippedSignalled.has(messageId)) return;
2576
2647
  this.attachmentsSkippedSignalled.add(messageId);
2577
2648
  const skippedReason = capabilityUnknown ? "unknown" : "unsupported";
2649
+ const failedReason = outcomes.some(
2650
+ (o) => o.status === "failed" && o.reason === "needs_reauth"
2651
+ ) ? "needs_reauth" : void 0;
2578
2652
  this.log({
2579
2653
  level: "info",
2580
2654
  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`,
@@ -2584,7 +2658,8 @@ var ChannelDriver = class {
2584
2658
  void this.postSignal(conversationId, messageId, "attachments_skipped", {
2585
2659
  skipped,
2586
2660
  failed,
2587
- ...skipped > 0 ? { skipped_reason: skippedReason } : {}
2661
+ ...skipped > 0 ? { skipped_reason: skippedReason } : {},
2662
+ ...failedReason ? { failed_reason: failedReason } : {}
2588
2663
  });
2589
2664
  }
2590
2665
  /** Register a freshly-dispatched message with its session's watcher state. */
@@ -3623,19 +3698,36 @@ var ChannelDriver = class {
3623
3698
  if (parent !== void 0) this.sessionParents.set(sessionId, parent);
3624
3699
  return parent;
3625
3700
  }
3701
+ /**
3702
+ * OpenCode's synchronous default session title (e.g.
3703
+ * `"New session - 1737800000000"`), assigned immediately when a session is
3704
+ * created — before OpenCode's async LLM-based auto-titling later renames it
3705
+ * mid-turn (#549). Matched by this literal, case-sensitive prefix only; the
3706
+ * timestamp suffix's exact format is deliberately NOT matched, since the prefix
3707
+ * alone is the stable, cheap signal and over-anchoring on the timestamp
3708
+ * representation risks silently breaking if OpenCode ever changes it. Accepted
3709
+ * trade-off: a genuine LLM-assigned title that happens to literally start with
3710
+ * this prefix would also fail to latch (see `resolveSessionTitle`) —
3711
+ * vanishingly unlikely in practice, and deliberately not engineered around.
3712
+ */
3713
+ static OPENCODE_DEFAULT_TITLE_PREFIX = /^New session - /;
3626
3714
  /**
3627
3715
  * Resolve (and cache in `sessionTitles`) the OpenCode session TITLE (#310) so the
3628
3716
  * status PATCH can carry it into the "Live sessions" list. Driver-level cache so
3629
3717
  * BOTH the watcher completion path and the restart-recovery re-adopt path (which
3630
3718
  * has no watcher) can use it. `conversationId` is passed only for log context.
3631
3719
  * Best-effort:
3632
- * - a resolved NON-EMPTY title is cached and terminal (a real session name
3720
+ * - a resolved NON-EMPTY title that does NOT match
3721
+ * `OPENCODE_DEFAULT_TITLE_PREFIX` is cached and terminal (a real session name
3633
3722
  * won't later un-name), so we do NOT re-GET `/session/:id` every tick;
3634
- * - while the title is still absent/empty we do NOT latch it — OpenCode names
3635
- * sessions asynchronously mid-turn, so an early call (e.g. at `processing`)
3636
- * must leave the cache unresolved and re-fetch on the next need so a later
3637
- * call (e.g. at `done`) picks up the name assigned in the meantime. Such a
3638
- * call returns `null` (omit the title on THIS PATCH) without caching;
3723
+ * - while the title is still absent, empty, or matches the OpenCode
3724
+ * placeholder prefix (#549) we do NOT latch it OpenCode names sessions
3725
+ * asynchronously mid-turn, so an early call (e.g. at `processing`) must leave
3726
+ * the cache unresolved and re-fetch on the next need so a later call (e.g. at
3727
+ * `done`) picks up the name assigned in the meantime. Such a call returns
3728
+ * `null` (omit the title on THIS PATCH) without caching. If a session is
3729
+ * never renamed, the title is omitted forever rather than ever persisting
3730
+ * the placeholder as a last resort;
3639
3731
  * - a failed request likewise leaves the cache unresolved (retry next need)
3640
3732
  * and returns `null` — it must NEVER throw or block completion.
3641
3733
  * A failure is logged with agent/session context (no silent catch).
@@ -3648,7 +3740,7 @@ var ChannelDriver = class {
3648
3740
  if (res.ok) {
3649
3741
  const body = await res.json();
3650
3742
  const title = body && typeof body.title === "string" ? body.title.trim() : "";
3651
- if (title.length > 0) {
3743
+ if (title.length > 0 && !_ChannelDriver.OPENCODE_DEFAULT_TITLE_PREFIX.test(title)) {
3652
3744
  this.sessionTitles.set(sessionId, title);
3653
3745
  return title;
3654
3746
  }
@@ -4714,6 +4806,19 @@ async function run(options) {
4714
4806
  sessionCleanupTimers: [],
4715
4807
  authHeader: ""
4716
4808
  };
4809
+ if (!options.runner && options.agent) {
4810
+ telemetry.info(
4811
+ EventTypes.DEPRECATED_AGENT_FLAG_USED,
4812
+ "Deprecated --agent flag used instead of --runner",
4813
+ { command: "run" },
4814
+ state.agentId
4815
+ );
4816
+ const agentFlagNotice = "--agent is deprecated, use --runner instead; will be removed in a future release.";
4817
+ log2(state, agentFlagNotice, "warn");
4818
+ if (state.interactive && !state.json) {
4819
+ logActivity(state, { type: "info", level: "warn", message: agentFlagNotice });
4820
+ }
4821
+ }
4717
4822
  if (state.idleTimeout === null && (process.env.GITHUB_ACTIONS || process.env.CI)) {
4718
4823
  log2(
4719
4824
  state,
@@ -4764,6 +4869,19 @@ async function run(options) {
4764
4869
  logActivity(state, { type: "info", level: "warn", message: credentials2.notice });
4765
4870
  }
4766
4871
  }
4872
+ if (credentials2.keySource === "agent_key") {
4873
+ telemetry.info(
4874
+ EventTypes.DEPRECATED_AGENT_KEY_ENV_USED,
4875
+ "Deprecated EVIDENT_AGENT_KEY env var used instead of EVIDENT_RUNNER_KEY",
4876
+ { command: "run" },
4877
+ state.agentId
4878
+ );
4879
+ const agentKeyNotice = "EVIDENT_AGENT_KEY is deprecated, use EVIDENT_RUNNER_KEY instead; will be removed in a future release.";
4880
+ log2(state, agentKeyNotice, "warn");
4881
+ if (state.interactive && !state.json) {
4882
+ logActivity(state, { type: "info", level: "warn", message: agentKeyNotice });
4883
+ }
4884
+ }
4767
4885
  if (!state.agentId) {
4768
4886
  if (credentials2.authType === "agent_key") {
4769
4887
  const resolved = await resolveAgentIdFromKey(state.authHeader);
@@ -4853,6 +4971,21 @@ async function run(options) {
4853
4971
  logActivity(state, { type: "info", level: "warn", message: versionWarning });
4854
4972
  }
4855
4973
  }
4974
+ const noProviderWarning = buildNoProviderWarning(await hasAnyConfiguredProvider(state.port));
4975
+ if (noProviderWarning) {
4976
+ log2(state, noProviderWarning, "warn");
4977
+ if (state.interactive && !state.json) {
4978
+ logActivity(state, { type: "info", level: "warn", message: noProviderWarning });
4979
+ blank();
4980
+ console.log(chalk6.yellow("\u26A0 No OpenCode model provider is configured."));
4981
+ console.log(
4982
+ chalk6.dim(
4983
+ `Run ${chalk6.cyan("opencode auth login")} to set one up \u2014 messages will fail until then.`
4984
+ )
4985
+ );
4986
+ blank();
4987
+ }
4988
+ }
4856
4989
  } catch (error2) {
4857
4990
  ocSpinner?.fail(error2.message);
4858
4991
  throw error2;