@evident-ai/cli 3.1.1-dev.186f6ef → 3.1.1-dev.1997a8e

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
  }
@@ -2011,6 +2062,7 @@ var DEFAULT_STUCK_QUEUED_MS = 6e4;
2011
2062
  var HEARTBEAT_MS = 6e4;
2012
2063
  var ABSOLUTE_MAX_PROCESSING_MS = 6 * 60 * 60 * 1e3;
2013
2064
  var POLL_MISS_GRACE_MS = HEARTBEAT_MS;
2065
+ var MAX_SUPERSEDED_CONVERSATIONS = 256;
2014
2066
  var ChannelAuthError = class extends Error {
2015
2067
  constructor(message) {
2016
2068
  super(message);
@@ -2033,7 +2085,7 @@ function backoffDelay(attempt, policy) {
2033
2085
  function isRetryableStatus(status) {
2034
2086
  return status === 429 || status >= 500 && status <= 599;
2035
2087
  }
2036
- var ChannelDriver = class {
2088
+ var ChannelDriver = class _ChannelDriver {
2037
2089
  agentId;
2038
2090
  port;
2039
2091
  apiUrl;
@@ -2049,6 +2101,34 @@ var ChannelDriver = class {
2049
2101
  now;
2050
2102
  /** Cache of conversationId → opencode sessionId. */
2051
2103
  sessions = /* @__PURE__ */ new Map();
2104
+ /**
2105
+ * conversationId → the opencode session this runner has ABANDONED as that
2106
+ * conversation's binding (#553), after a genuine (`sessionExists === true`)
2107
+ * dispatch failure: the session still exists but is wedged, so #485's self-heal
2108
+ * must bind a fresh one.
2109
+ *
2110
+ * Dropping the local binding + clearing the server row is not enough on its own:
2111
+ * a SIBLING message dispatched earlier in the same drain is still in-flight under
2112
+ * the same session, and its watcher's routine status writes carry
2113
+ * `opencode_session_id`, RESURRECTING the wedged id server-side after the clear —
2114
+ * and `ensureSession`'s persisted-id fallback then reuses it, defeating the
2115
+ * self-heal. This map makes the runner authoritative instead of racing those
2116
+ * writes: *`ensureSession` never reuses an abandoned id for that conversation,
2117
+ * whatever the server row says* — which holds even when the resurrecting write
2118
+ * is one we deliberately keep (see `markDone`).
2119
+ *
2120
+ * Bounded by construction, on both axes: keyed by CONVERSATION, so N failures on
2121
+ * one conversation hold ONE entry (the newest abandonment replaces the older), and
2122
+ * hard-capped at `MAX_SUPERSEDED_CONVERSATIONS` with FIFO eviction. Only the
2123
+ * NEWEST abandoned id per conversation is guarded: after a second abandonment a
2124
+ * late sibling of the FIRST session can write that id back and `ensureSession`
2125
+ * will reuse it — costing ONE repeat failure, which re-supersedes it. Deliberately
2126
+ * NOT dropped when the session's watcher tears down: `markDone` still writes the
2127
+ * abandoned id back (it must, or the reply is lost), so the guard has to outlive
2128
+ * the turn that resurrects it. In-memory only — a restart forgets it, at the same
2129
+ * bounded cost.
2130
+ */
2131
+ supersededSessions = /* @__PURE__ */ new Map();
2052
2132
  /**
2053
2133
  * Per-opencode-session dispatch lock (Task 2.1a). `sendPromptAsync` is no
2054
2134
  * longer idempotent (no caller-supplied `messageID`), and its read-back picks
@@ -2158,9 +2238,12 @@ var ChannelDriver = class {
2158
2238
  sessionParents = /* @__PURE__ */ new Map();
2159
2239
  /**
2160
2240
  * 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
2241
+ * NON-EMPTY, non-placeholder name is stored (terminal — a real session name
2242
+ * won't later un-name), so we do NOT re-GET `/session/:id` every tick. "Non-empty"
2243
+ * excludes OpenCode's synchronous default title (see
2244
+ * `OPENCODE_DEFAULT_TITLE_PREFIX`, #549) — that placeholder is treated the same
2245
+ * as an empty title so it never latches. A missing entry = not yet resolved OR
2246
+ * resolved-but-still-empty/placeholder → re-fetch on next need, since OpenCode
2164
2247
  * names sessions asynchronously mid-turn. Driver-level (not per-watcher) so both
2165
2248
  * the watcher completion path AND the restart-recovery re-adopt path (which has
2166
2249
  * no watcher) can resolve the title.
@@ -2354,10 +2437,15 @@ var ChannelDriver = class {
2354
2437
  * @returns the count of messages NEWLY dispatched (not already in-flight).
2355
2438
  */
2356
2439
  async processConversation(conv) {
2357
- const sessionId = await this.ensureSession(conv);
2440
+ const { sessionId, refusedSessionId } = await this.ensureSession(conv);
2358
2441
  const messages = await this.getPendingMessages(conv.id);
2359
2442
  let dispatched = 0;
2360
2443
  let skippedAlreadyDispatched = 0;
2444
+ if (refusedSessionId && messages.length > 0) {
2445
+ void this.postSignal(conv.id, messages[0].id, "session_superseded", {
2446
+ superseded_session_id: refusedSessionId
2447
+ });
2448
+ }
2361
2449
  for (const message of messages) {
2362
2450
  if (this.stopped) break;
2363
2451
  if (this.dispatched.has(message.id)) {
@@ -2384,7 +2472,8 @@ var ChannelDriver = class {
2384
2472
  } catch (err) {
2385
2473
  if (err instanceof ChannelAuthError) throw err;
2386
2474
  this.dispatched.delete(message.id);
2387
- if (await sessionExists(this.port, sessionId) === false) {
2475
+ const exists = await sessionExists(this.port, sessionId);
2476
+ if (exists === false) {
2388
2477
  this.sessions.delete(conv.id);
2389
2478
  this.log({
2390
2479
  level: "warn",
@@ -2394,15 +2483,39 @@ var ChannelDriver = class {
2394
2483
  });
2395
2484
  break;
2396
2485
  }
2397
- await this.markFailed(conv.id, message.id).catch(() => {
2486
+ if (exists === null) {
2487
+ this.log({
2488
+ level: "warn",
2489
+ 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.`,
2490
+ conversation_id: conv.id,
2491
+ message_id: message.id
2492
+ });
2493
+ break;
2494
+ }
2495
+ const errorMessage = err instanceof Error ? err.message : String(err);
2496
+ this.sessions.delete(conv.id);
2497
+ this.supersede(conv.id, sessionId);
2498
+ this.log({
2499
+ level: "warn",
2500
+ message: `Abandoning OpenCode session ${sessionId.slice(0, 8)} as the binding for conversation ${conv.id.slice(0, 8)} (it exists but failed to run a turn) \u2014 a fresh session is created on the next tick, whatever the persisted binding says by then.`,
2501
+ conversation_id: conv.id,
2502
+ message_id: message.id
2503
+ });
2504
+ await this.markFailed(conv.id, message.id, null, errorMessage).catch((markErr) => {
2505
+ this.log({
2506
+ level: "warn",
2507
+ 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)}`,
2508
+ conversation_id: conv.id,
2509
+ message_id: message.id
2510
+ });
2398
2511
  });
2399
2512
  this.log({
2400
2513
  level: "error",
2401
- message: `Message ${message.id.slice(0, 8)} dispatch failed: ${err instanceof Error ? err.message : String(err)}`,
2514
+ message: `Message ${message.id.slice(0, 8)} dispatch failed: ${errorMessage}`,
2402
2515
  conversation_id: conv.id,
2403
2516
  message_id: message.id
2404
2517
  });
2405
- continue;
2518
+ break;
2406
2519
  }
2407
2520
  if (opencodeMessageId === null) {
2408
2521
  this.log({
@@ -2428,8 +2541,42 @@ var ChannelDriver = class {
2428
2541
  this.ensureWatcherRunning(sessionId);
2429
2542
  return dispatched;
2430
2543
  }
2544
+ /**
2545
+ * Record that `sessionId` is no longer a valid binding for `conversationId`
2546
+ * (#553). Keyed by conversation and hard-capped, so it cannot grow with the
2547
+ * number of failures — see the `supersededSessions` field doc.
2548
+ */
2549
+ supersede(conversationId, sessionId) {
2550
+ this.supersededSessions.delete(conversationId);
2551
+ this.supersededSessions.set(conversationId, sessionId);
2552
+ while (this.supersededSessions.size > MAX_SUPERSEDED_CONVERSATIONS) {
2553
+ const oldest = this.supersededSessions.keys().next().value;
2554
+ if (oldest === void 0) return;
2555
+ this.supersededSessions.delete(oldest);
2556
+ }
2557
+ }
2558
+ /** Whether `sessionId` is the session this conversation has abandoned (#553). */
2559
+ isSuperseded(conversationId, sessionId) {
2560
+ return this.supersededSessions.get(conversationId) === sessionId;
2561
+ }
2562
+ /**
2563
+ * Resolve the opencode session to run this conversation's turns in.
2564
+ *
2565
+ * `refusedSessionId` is set when the #553 guard fired — i.e. the persisted
2566
+ * binding was an id this runner had abandoned, so a resurrection genuinely
2567
+ * happened and a fresh session was bound instead. The caller reports it.
2568
+ */
2431
2569
  async ensureSession(conv) {
2432
2570
  const bound = this.sessions.get(conv.id) ?? conv.opencode_session_id ?? null;
2571
+ if (bound && this.isSuperseded(conv.id, bound)) {
2572
+ this.log({
2573
+ level: "warn",
2574
+ message: `OpenCode session ${bound.slice(0, 8)} was abandoned for conversation ${conv.id.slice(0, 8)} after a failed dispatch but is still bound to it (the persisted id was written back by a turn already in flight) \u2014 ignoring it and binding a fresh session.`,
2575
+ conversation_id: conv.id
2576
+ });
2577
+ this.sessions.delete(conv.id);
2578
+ return { sessionId: await this.createAndBindSession(conv.id), refusedSessionId: bound };
2579
+ }
2433
2580
  if (bound) {
2434
2581
  const exists = await sessionExists(this.port, bound);
2435
2582
  if (exists === false) {
@@ -2439,12 +2586,12 @@ var ChannelDriver = class {
2439
2586
  conversation_id: conv.id
2440
2587
  });
2441
2588
  this.sessions.delete(conv.id);
2442
- return this.createAndBindSession(conv.id);
2589
+ return { sessionId: await this.createAndBindSession(conv.id) };
2443
2590
  }
2444
2591
  this.sessions.set(conv.id, bound);
2445
- return bound;
2592
+ return { sessionId: bound };
2446
2593
  }
2447
- return this.createAndBindSession(conv.id);
2594
+ return { sessionId: await this.createAndBindSession(conv.id) };
2448
2595
  }
2449
2596
  /**
2450
2597
  * Create a fresh OpenCode session for a conversation, cache the binding, and
@@ -2532,7 +2679,11 @@ var ChannelDriver = class {
2532
2679
  * (not-owned / out-of-range / deleted-at-source / workspace gone) / 413
2533
2680
  * (over-cap). On ANY non-2xx or thrown failure we return `null` so the caller
2534
2681
  * OMITS that one image and the text turn still sends — NEVER throws the turn.
2535
- * Failures are logged with context (no silent swallow).
2682
+ * A 404 body carrying `{ reason: 'needs_reauth' }` (#547 the server CONFIRMED
2683
+ * a Slack `files:read` scope problem via `files.info`) instead resolves the
2684
+ * `AttachmentFetchNeedsReauth` sentinel, so the in-thread note can steer the
2685
+ * user to reconnect Slack instead of a generic "unavailable". Failures are
2686
+ * logged with context (no silent swallow).
2536
2687
  */
2537
2688
  async fetchAttachmentDataUrl(messageId, index, mime) {
2538
2689
  try {
@@ -2541,6 +2692,25 @@ var ChannelDriver = class {
2541
2692
  { headers: { Authorization: this.getAuthHeader() } }
2542
2693
  );
2543
2694
  if (!res.ok) {
2695
+ let reason;
2696
+ try {
2697
+ const body = await res.json();
2698
+ if (body && typeof body.reason === "string") reason = body.reason;
2699
+ } catch (parseErr) {
2700
+ this.log({
2701
+ level: "debug",
2702
+ 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`,
2703
+ message_id: messageId
2704
+ });
2705
+ }
2706
+ if (reason === "needs_reauth") {
2707
+ this.log({
2708
+ level: "error",
2709
+ 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)`,
2710
+ message_id: messageId
2711
+ });
2712
+ return { needsReauth: true };
2713
+ }
2544
2714
  this.log({
2545
2715
  level: "error",
2546
2716
  message: `Attachment fetch for message ${messageId.slice(0, 8)} index ${index} returned HTTP ${res.status} \u2014 omitting this image (text turn proceeds)`,
@@ -2580,6 +2750,9 @@ var ChannelDriver = class {
2580
2750
  if (this.attachmentsSkippedSignalled.has(messageId)) return;
2581
2751
  this.attachmentsSkippedSignalled.add(messageId);
2582
2752
  const skippedReason = capabilityUnknown ? "unknown" : "unsupported";
2753
+ const failedReason = outcomes.some(
2754
+ (o) => o.status === "failed" && o.reason === "needs_reauth"
2755
+ ) ? "needs_reauth" : void 0;
2583
2756
  this.log({
2584
2757
  level: "info",
2585
2758
  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 +2762,8 @@ var ChannelDriver = class {
2589
2762
  void this.postSignal(conversationId, messageId, "attachments_skipped", {
2590
2763
  skipped,
2591
2764
  failed,
2592
- ...skipped > 0 ? { skipped_reason: skippedReason } : {}
2765
+ ...skipped > 0 ? { skipped_reason: skippedReason } : {},
2766
+ ...failedReason ? { failed_reason: failedReason } : {}
2593
2767
  });
2594
2768
  }
2595
2769
  /** Register a freshly-dispatched message with its session's watcher state. */
@@ -3628,19 +3802,36 @@ var ChannelDriver = class {
3628
3802
  if (parent !== void 0) this.sessionParents.set(sessionId, parent);
3629
3803
  return parent;
3630
3804
  }
3805
+ /**
3806
+ * OpenCode's synchronous default session title (e.g.
3807
+ * `"New session - 1737800000000"`), assigned immediately when a session is
3808
+ * created — before OpenCode's async LLM-based auto-titling later renames it
3809
+ * mid-turn (#549). Matched by this literal, case-sensitive prefix only; the
3810
+ * timestamp suffix's exact format is deliberately NOT matched, since the prefix
3811
+ * alone is the stable, cheap signal and over-anchoring on the timestamp
3812
+ * representation risks silently breaking if OpenCode ever changes it. Accepted
3813
+ * trade-off: a genuine LLM-assigned title that happens to literally start with
3814
+ * this prefix would also fail to latch (see `resolveSessionTitle`) —
3815
+ * vanishingly unlikely in practice, and deliberately not engineered around.
3816
+ */
3817
+ static OPENCODE_DEFAULT_TITLE_PREFIX = /^New session - /;
3631
3818
  /**
3632
3819
  * Resolve (and cache in `sessionTitles`) the OpenCode session TITLE (#310) so the
3633
3820
  * status PATCH can carry it into the "Live sessions" list. Driver-level cache so
3634
3821
  * BOTH the watcher completion path and the restart-recovery re-adopt path (which
3635
3822
  * has no watcher) can use it. `conversationId` is passed only for log context.
3636
3823
  * Best-effort:
3637
- * - a resolved NON-EMPTY title is cached and terminal (a real session name
3824
+ * - a resolved NON-EMPTY title that does NOT match
3825
+ * `OPENCODE_DEFAULT_TITLE_PREFIX` is cached and terminal (a real session name
3638
3826
  * 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;
3827
+ * - while the title is still absent, empty, or matches the OpenCode
3828
+ * placeholder prefix (#549) we do NOT latch it OpenCode names sessions
3829
+ * asynchronously mid-turn, so an early call (e.g. at `processing`) must leave
3830
+ * the cache unresolved and re-fetch on the next need so a later call (e.g. at
3831
+ * `done`) picks up the name assigned in the meantime. Such a call returns
3832
+ * `null` (omit the title on THIS PATCH) without caching. If a session is
3833
+ * never renamed, the title is omitted forever rather than ever persisting
3834
+ * the placeholder as a last resort;
3644
3835
  * - a failed request likewise leaves the cache unresolved (retry next need)
3645
3836
  * and returns `null` — it must NEVER throw or block completion.
3646
3837
  * A failure is logged with agent/session context (no silent catch).
@@ -3653,7 +3844,7 @@ var ChannelDriver = class {
3653
3844
  if (res.ok) {
3654
3845
  const body = await res.json();
3655
3846
  const title = body && typeof body.title === "string" ? body.title.trim() : "";
3656
- if (title.length > 0) {
3847
+ if (title.length > 0 && !_ChannelDriver.OPENCODE_DEFAULT_TITLE_PREFIX.test(title)) {
3657
3848
  this.sessionTitles.set(sessionId, title);
3658
3849
  return title;
3659
3850
  }
@@ -3859,6 +4050,32 @@ var ChannelDriver = class {
3859
4050
  }
3860
4051
  return messages;
3861
4052
  }
4053
+ /**
4054
+ * The `opencode_session_id` fragment of a status PATCH body — `{}` when this
4055
+ * conversation has ABANDONED that session (#553). The field is optional
4056
+ * server-side and an absent one leaves the persisted binding untouched, so
4057
+ * omitting it is how a routine status write stops resurrecting it.
4058
+ *
4059
+ * ONLY for writes whose sole cost is a lost deep link. The `processing` notice
4060
+ * degrades to no "View in Evident" link (the reaction swap still fires) and the
4061
+ * turn-failure notice is built from the PATCH's own `error` text with a link off
4062
+ * the persisted row — neither loses content the user came for. `markDone`
4063
+ * deliberately does NOT use this helper: the server fetches the reply text
4064
+ * THROUGH the session id it is given, so suppressing there would replace the
4065
+ * agent's answer with a bare "✅ Done!" (the #183/#187 failure). The
4066
+ * `ensureSession` guard, not this suppression, is what makes the self-heal
4067
+ * stick.
4068
+ */
4069
+ sessionIdBody(sessionId, conversationId, messageId, status) {
4070
+ if (!this.isSuperseded(conversationId, sessionId)) return { opencode_session_id: sessionId };
4071
+ this.log({
4072
+ level: "debug",
4073
+ message: `Omitting the abandoned OpenCode session ${sessionId.slice(0, 8)} from the '${status}' update for message ${messageId.slice(0, 8)} so it is not re-bound to conversation ${conversationId.slice(0, 8)}`,
4074
+ conversation_id: conversationId,
4075
+ message_id: messageId
4076
+ });
4077
+ return {};
4078
+ }
3862
4079
  /**
3863
4080
  * EXISTING combinedAuth route — now fired by the watcher on queued→running
3864
4081
  * (Task 3.3), NOT at dispatch/claim time. `{status:'processing',
@@ -3888,7 +4105,7 @@ var ChannelDriver = class {
3888
4105
  headers: { Authorization: this.getAuthHeader(), "Content-Type": "application/json" },
3889
4106
  body: JSON.stringify({
3890
4107
  status: "processing",
3891
- opencode_session_id: sessionId,
4108
+ ...this.sessionIdBody(sessionId, conversationId, messageId, "processing"),
3892
4109
  ...opencodeMessageId ? { opencode_message_id: opencodeMessageId } : {},
3893
4110
  ...title ? { title } : {}
3894
4111
  })
@@ -3937,6 +4154,11 @@ var ChannelDriver = class {
3937
4154
  headers: { Authorization: this.getAuthHeader(), "Content-Type": "application/json" },
3938
4155
  body: JSON.stringify({
3939
4156
  status: "done",
4157
+ // ALWAYS sent, even for a session this conversation has abandoned
4158
+ // (#553): the server reads the reply text back out of THIS session id
4159
+ // to deliver it. Omitting it would leave the user with "✅ Done!"
4160
+ // instead of the answer — a worse regression than the resurrection it
4161
+ // would prevent, which `ensureSession`'s guard handles anyway.
3940
4162
  opencode_session_id: sessionId,
3941
4163
  ...opencodeMessageId ? { opencode_message_id: opencodeMessageId } : {},
3942
4164
  ...title ? { title } : {},
@@ -3953,14 +4175,23 @@ var ChannelDriver = class {
3953
4175
  }
3954
4176
  /**
3955
4177
  * 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.
4178
+ * when provided (issue #182). Three states for `sessionId`:
4179
+ * - omitted (`undefined`) → don't send the field, leave the persisted
4180
+ * session untouched (unused today; kept for API symmetry).
4181
+ * - a real id (`string`) → send it, update the persisted session (the
4182
+ * turn-failure call sites: an errored OpenCode turn).
4183
+ * - explicit `null` → send it, CLEAR the persisted session (issue
4184
+ * #485's dispatch-handoff-failure call site: the session id still
4185
+ * exists but is wedged, so the next attempt must get a fresh one
4186
+ * instead of reusing it — see WI-1's server-side null-clearing PATCH).
3960
4187
  */
3961
4188
  async markFailed(conversationId, messageId, sessionId, error2, usage) {
3962
4189
  const body = { status: "failed" };
3963
- if (sessionId !== void 0) body.opencode_session_id = sessionId;
4190
+ if (sessionId === null) {
4191
+ body.opencode_session_id = null;
4192
+ } else if (sessionId !== void 0) {
4193
+ Object.assign(body, this.sessionIdBody(sessionId, conversationId, messageId, "failed"));
4194
+ }
3964
4195
  if (error2 !== void 0) body.error = error2;
3965
4196
  if (usage) Object.assign(body, usage);
3966
4197
  await this.callWithRetry(
@@ -4726,6 +4957,11 @@ async function run(options) {
4726
4957
  { command: "run" },
4727
4958
  state.agentId
4728
4959
  );
4960
+ const agentFlagNotice = "--agent is deprecated, use --runner instead; will be removed in a future release.";
4961
+ log2(state, agentFlagNotice, "warn");
4962
+ if (state.interactive && !state.json) {
4963
+ logActivity(state, { type: "info", level: "warn", message: agentFlagNotice });
4964
+ }
4729
4965
  }
4730
4966
  if (state.idleTimeout === null && (process.env.GITHUB_ACTIONS || process.env.CI)) {
4731
4967
  log2(
@@ -4784,6 +5020,11 @@ async function run(options) {
4784
5020
  { command: "run" },
4785
5021
  state.agentId
4786
5022
  );
5023
+ const agentKeyNotice = "EVIDENT_AGENT_KEY is deprecated, use EVIDENT_RUNNER_KEY instead; will be removed in a future release.";
5024
+ log2(state, agentKeyNotice, "warn");
5025
+ if (state.interactive && !state.json) {
5026
+ logActivity(state, { type: "info", level: "warn", message: agentKeyNotice });
5027
+ }
4787
5028
  }
4788
5029
  if (!state.agentId) {
4789
5030
  if (credentials2.authType === "agent_key") {
@@ -4874,6 +5115,21 @@ async function run(options) {
4874
5115
  logActivity(state, { type: "info", level: "warn", message: versionWarning });
4875
5116
  }
4876
5117
  }
5118
+ const noProviderWarning = buildNoProviderWarning(await hasAnyConfiguredProvider(state.port));
5119
+ if (noProviderWarning) {
5120
+ log2(state, noProviderWarning, "warn");
5121
+ if (state.interactive && !state.json) {
5122
+ logActivity(state, { type: "info", level: "warn", message: noProviderWarning });
5123
+ blank();
5124
+ console.log(chalk6.yellow("\u26A0 No OpenCode model provider is configured."));
5125
+ console.log(
5126
+ chalk6.dim(
5127
+ `Run ${chalk6.cyan("opencode auth login")} to set one up \u2014 messages will fail until then.`
5128
+ )
5129
+ );
5130
+ blank();
5131
+ }
5132
+ }
4877
5133
  } catch (error2) {
4878
5134
  ocSpinner?.fail(error2.message);
4879
5135
  throw error2;