@evident-ai/cli 3.1.1-dev.621615f → 3.1.1-dev.691c8d0
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/README.md +15 -11
- package/dist/index.js +292 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,20 +72,21 @@ delivers any channel messages (e.g. Slack) to your local OpenCode.
|
|
|
72
72
|
|
|
73
73
|
```bash
|
|
74
74
|
# Interactive: connect a specific runner
|
|
75
|
-
evident run --
|
|
75
|
+
evident run --runner <runner-id>
|
|
76
76
|
|
|
77
77
|
# Drive a single conversation
|
|
78
|
-
evident run --
|
|
78
|
+
evident run --runner <runner-id> --conversation <conversation-id>
|
|
79
79
|
|
|
80
80
|
# CI: exit after 30s with no work
|
|
81
|
-
evident run --
|
|
81
|
+
evident run --runner <runner-id> --idle-timeout 30
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
Options:
|
|
85
85
|
|
|
86
|
-
-
|
|
86
|
+
- `--runner [id]` — Runner ID to connect to. Optional when `EVIDENT_RUNNER_KEY`
|
|
87
87
|
is set (the runner is then resolved automatically from the key).
|
|
88
|
-
-
|
|
88
|
+
- `-a, --agent [id]` — Deprecated alias for `--runner`. Still supported, but it
|
|
89
|
+
prints a deprecation warning; `--runner` wins if both are given.
|
|
89
90
|
- `-p, --port <port>` — OpenCode port (default: `4096`).
|
|
90
91
|
- `--log-level <level>` — Log verbosity: `debug | info | warn | error` (default:
|
|
91
92
|
`info`). Env: `EVIDENT_LOG_LEVEL`.
|
|
@@ -110,7 +111,9 @@ targets the **production** Evident platform by default.
|
|
|
110
111
|
that runner and resolves the runner ID automatically, so `--runner`/`--agent`
|
|
111
112
|
is not required. Ideal for CI/CD. Preferred name; wins over `EVIDENT_AGENT_KEY`
|
|
112
113
|
if both are set.
|
|
113
|
-
- `EVIDENT_AGENT_KEY` —
|
|
114
|
+
- `EVIDENT_AGENT_KEY` — Deprecated alias for `EVIDENT_RUNNER_KEY`. Still fully
|
|
115
|
+
supported, but `evident run` prints a deprecation warning when it is used
|
|
116
|
+
without `EVIDENT_RUNNER_KEY`.
|
|
114
117
|
- `EVIDENT_TOKEN` — A user token used for authentication (alternative to a
|
|
115
118
|
keychain login from `evident login`).
|
|
116
119
|
- `EVIDENT_API_URL` — Override the API base URL (equivalent to `--endpoint`).
|
|
@@ -141,20 +144,21 @@ ID.
|
|
|
141
144
|
From your project directory, start the runner:
|
|
142
145
|
|
|
143
146
|
```bash
|
|
144
|
-
evident run --
|
|
147
|
+
evident run --runner <runner-id>
|
|
145
148
|
```
|
|
146
149
|
|
|
147
150
|
`evident run` ensures `opencode serve` is running on `127.0.0.1:4096` (starting
|
|
148
151
|
it if needed) and connects the tunnel. Once connected, the web shows the runner as
|
|
149
152
|
online and you can open its chat.
|
|
150
153
|
|
|
151
|
-
For CI or unattended use, set `
|
|
154
|
+
For CI or unattended use, set `EVIDENT_RUNNER_KEY` and omit `--runner`:
|
|
152
155
|
|
|
153
156
|
```bash
|
|
154
|
-
|
|
157
|
+
EVIDENT_RUNNER_KEY=<runner-key> evident run --idle-timeout 30
|
|
155
158
|
```
|
|
156
159
|
|
|
157
|
-
(`
|
|
160
|
+
(`EVIDENT_AGENT_KEY` is a still-supported deprecated alias for
|
|
161
|
+
`EVIDENT_RUNNER_KEY`.)
|
|
158
162
|
|
|
159
163
|
## How it works
|
|
160
164
|
|
|
@@ -191,7 +195,7 @@ evident logout
|
|
|
191
195
|
evident login
|
|
192
196
|
```
|
|
193
197
|
|
|
194
|
-
In CI, make sure `
|
|
198
|
+
In CI, make sure `EVIDENT_RUNNER_KEY` (or `EVIDENT_TOKEN`) is set.
|
|
195
199
|
|
|
196
200
|
### OpenCode isn't reachable
|
|
197
201
|
|
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;
|
|
@@ -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.
|
|
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();
|
|
@@ -1918,7 +1977,11 @@ var RunnerConnection = class {
|
|
|
1918
1977
|
if (this.connection) {
|
|
1919
1978
|
try {
|
|
1920
1979
|
this.connection.close();
|
|
1921
|
-
} catch {
|
|
1980
|
+
} catch (err) {
|
|
1981
|
+
log("error", "runner_connection_close_failed", {
|
|
1982
|
+
agent_id: this.resolvedAgentId,
|
|
1983
|
+
...errorFields(err)
|
|
1984
|
+
});
|
|
1922
1985
|
}
|
|
1923
1986
|
this.connection = null;
|
|
1924
1987
|
}
|
|
@@ -1999,6 +2062,7 @@ var DEFAULT_STUCK_QUEUED_MS = 6e4;
|
|
|
1999
2062
|
var HEARTBEAT_MS = 6e4;
|
|
2000
2063
|
var ABSOLUTE_MAX_PROCESSING_MS = 6 * 60 * 60 * 1e3;
|
|
2001
2064
|
var POLL_MISS_GRACE_MS = HEARTBEAT_MS;
|
|
2065
|
+
var MAX_SUPERSEDED_CONVERSATIONS = 256;
|
|
2002
2066
|
var ChannelAuthError = class extends Error {
|
|
2003
2067
|
constructor(message) {
|
|
2004
2068
|
super(message);
|
|
@@ -2021,7 +2085,7 @@ function backoffDelay(attempt, policy) {
|
|
|
2021
2085
|
function isRetryableStatus(status) {
|
|
2022
2086
|
return status === 429 || status >= 500 && status <= 599;
|
|
2023
2087
|
}
|
|
2024
|
-
var ChannelDriver = class {
|
|
2088
|
+
var ChannelDriver = class _ChannelDriver {
|
|
2025
2089
|
agentId;
|
|
2026
2090
|
port;
|
|
2027
2091
|
apiUrl;
|
|
@@ -2037,6 +2101,34 @@ var ChannelDriver = class {
|
|
|
2037
2101
|
now;
|
|
2038
2102
|
/** Cache of conversationId → opencode sessionId. */
|
|
2039
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();
|
|
2040
2132
|
/**
|
|
2041
2133
|
* Per-opencode-session dispatch lock (Task 2.1a). `sendPromptAsync` is no
|
|
2042
2134
|
* longer idempotent (no caller-supplied `messageID`), and its read-back picks
|
|
@@ -2146,9 +2238,12 @@ var ChannelDriver = class {
|
|
|
2146
2238
|
sessionParents = /* @__PURE__ */ new Map();
|
|
2147
2239
|
/**
|
|
2148
2240
|
* Per-session OpenCode title cache (#310), keyed by sessionId. Only a resolved
|
|
2149
|
-
* NON-EMPTY name is stored (terminal — a real session name
|
|
2150
|
-
* so we do NOT re-GET `/session/:id` every tick.
|
|
2151
|
-
*
|
|
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
|
|
2152
2247
|
* names sessions asynchronously mid-turn. Driver-level (not per-watcher) so both
|
|
2153
2248
|
* the watcher completion path AND the restart-recovery re-adopt path (which has
|
|
2154
2249
|
* no watcher) can resolve the title.
|
|
@@ -2342,10 +2437,15 @@ var ChannelDriver = class {
|
|
|
2342
2437
|
* @returns the count of messages NEWLY dispatched (not already in-flight).
|
|
2343
2438
|
*/
|
|
2344
2439
|
async processConversation(conv) {
|
|
2345
|
-
const sessionId = await this.ensureSession(conv);
|
|
2440
|
+
const { sessionId, refusedSessionId } = await this.ensureSession(conv);
|
|
2346
2441
|
const messages = await this.getPendingMessages(conv.id);
|
|
2347
2442
|
let dispatched = 0;
|
|
2348
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
|
+
}
|
|
2349
2449
|
for (const message of messages) {
|
|
2350
2450
|
if (this.stopped) break;
|
|
2351
2451
|
if (this.dispatched.has(message.id)) {
|
|
@@ -2372,7 +2472,8 @@ var ChannelDriver = class {
|
|
|
2372
2472
|
} catch (err) {
|
|
2373
2473
|
if (err instanceof ChannelAuthError) throw err;
|
|
2374
2474
|
this.dispatched.delete(message.id);
|
|
2375
|
-
|
|
2475
|
+
const exists = await sessionExists(this.port, sessionId);
|
|
2476
|
+
if (exists === false) {
|
|
2376
2477
|
this.sessions.delete(conv.id);
|
|
2377
2478
|
this.log({
|
|
2378
2479
|
level: "warn",
|
|
@@ -2382,15 +2483,39 @@ var ChannelDriver = class {
|
|
|
2382
2483
|
});
|
|
2383
2484
|
break;
|
|
2384
2485
|
}
|
|
2385
|
-
|
|
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
|
+
});
|
|
2386
2511
|
});
|
|
2387
2512
|
this.log({
|
|
2388
2513
|
level: "error",
|
|
2389
|
-
message: `Message ${message.id.slice(0, 8)} dispatch failed: ${
|
|
2514
|
+
message: `Message ${message.id.slice(0, 8)} dispatch failed: ${errorMessage}`,
|
|
2390
2515
|
conversation_id: conv.id,
|
|
2391
2516
|
message_id: message.id
|
|
2392
2517
|
});
|
|
2393
|
-
|
|
2518
|
+
break;
|
|
2394
2519
|
}
|
|
2395
2520
|
if (opencodeMessageId === null) {
|
|
2396
2521
|
this.log({
|
|
@@ -2416,8 +2541,42 @@ var ChannelDriver = class {
|
|
|
2416
2541
|
this.ensureWatcherRunning(sessionId);
|
|
2417
2542
|
return dispatched;
|
|
2418
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
|
+
*/
|
|
2419
2569
|
async ensureSession(conv) {
|
|
2420
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
|
+
}
|
|
2421
2580
|
if (bound) {
|
|
2422
2581
|
const exists = await sessionExists(this.port, bound);
|
|
2423
2582
|
if (exists === false) {
|
|
@@ -2427,12 +2586,12 @@ var ChannelDriver = class {
|
|
|
2427
2586
|
conversation_id: conv.id
|
|
2428
2587
|
});
|
|
2429
2588
|
this.sessions.delete(conv.id);
|
|
2430
|
-
return this.createAndBindSession(conv.id);
|
|
2589
|
+
return { sessionId: await this.createAndBindSession(conv.id) };
|
|
2431
2590
|
}
|
|
2432
2591
|
this.sessions.set(conv.id, bound);
|
|
2433
|
-
return bound;
|
|
2592
|
+
return { sessionId: bound };
|
|
2434
2593
|
}
|
|
2435
|
-
return this.createAndBindSession(conv.id);
|
|
2594
|
+
return { sessionId: await this.createAndBindSession(conv.id) };
|
|
2436
2595
|
}
|
|
2437
2596
|
/**
|
|
2438
2597
|
* Create a fresh OpenCode session for a conversation, cache the binding, and
|
|
@@ -2520,7 +2679,11 @@ var ChannelDriver = class {
|
|
|
2520
2679
|
* (not-owned / out-of-range / deleted-at-source / workspace gone) / 413
|
|
2521
2680
|
* (over-cap). On ANY non-2xx or thrown failure we return `null` so the caller
|
|
2522
2681
|
* OMITS that one image and the text turn still sends — NEVER throws the turn.
|
|
2523
|
-
*
|
|
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).
|
|
2524
2687
|
*/
|
|
2525
2688
|
async fetchAttachmentDataUrl(messageId, index, mime) {
|
|
2526
2689
|
try {
|
|
@@ -2529,6 +2692,25 @@ var ChannelDriver = class {
|
|
|
2529
2692
|
{ headers: { Authorization: this.getAuthHeader() } }
|
|
2530
2693
|
);
|
|
2531
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
|
+
}
|
|
2532
2714
|
this.log({
|
|
2533
2715
|
level: "error",
|
|
2534
2716
|
message: `Attachment fetch for message ${messageId.slice(0, 8)} index ${index} returned HTTP ${res.status} \u2014 omitting this image (text turn proceeds)`,
|
|
@@ -2568,6 +2750,9 @@ var ChannelDriver = class {
|
|
|
2568
2750
|
if (this.attachmentsSkippedSignalled.has(messageId)) return;
|
|
2569
2751
|
this.attachmentsSkippedSignalled.add(messageId);
|
|
2570
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;
|
|
2571
2756
|
this.log({
|
|
2572
2757
|
level: "info",
|
|
2573
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`,
|
|
@@ -2577,7 +2762,8 @@ var ChannelDriver = class {
|
|
|
2577
2762
|
void this.postSignal(conversationId, messageId, "attachments_skipped", {
|
|
2578
2763
|
skipped,
|
|
2579
2764
|
failed,
|
|
2580
|
-
...skipped > 0 ? { skipped_reason: skippedReason } : {}
|
|
2765
|
+
...skipped > 0 ? { skipped_reason: skippedReason } : {},
|
|
2766
|
+
...failedReason ? { failed_reason: failedReason } : {}
|
|
2581
2767
|
});
|
|
2582
2768
|
}
|
|
2583
2769
|
/** Register a freshly-dispatched message with its session's watcher state. */
|
|
@@ -3616,19 +3802,36 @@ var ChannelDriver = class {
|
|
|
3616
3802
|
if (parent !== void 0) this.sessionParents.set(sessionId, parent);
|
|
3617
3803
|
return parent;
|
|
3618
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 - /;
|
|
3619
3818
|
/**
|
|
3620
3819
|
* Resolve (and cache in `sessionTitles`) the OpenCode session TITLE (#310) so the
|
|
3621
3820
|
* status PATCH can carry it into the "Live sessions" list. Driver-level cache so
|
|
3622
3821
|
* BOTH the watcher completion path and the restart-recovery re-adopt path (which
|
|
3623
3822
|
* has no watcher) can use it. `conversationId` is passed only for log context.
|
|
3624
3823
|
* Best-effort:
|
|
3625
|
-
* - a resolved NON-EMPTY title
|
|
3824
|
+
* - a resolved NON-EMPTY title that does NOT match
|
|
3825
|
+
* `OPENCODE_DEFAULT_TITLE_PREFIX` is cached and terminal (a real session name
|
|
3626
3826
|
* won't later un-name), so we do NOT re-GET `/session/:id` every tick;
|
|
3627
|
-
* - while the title is still absent
|
|
3628
|
-
*
|
|
3629
|
-
*
|
|
3630
|
-
*
|
|
3631
|
-
*
|
|
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;
|
|
3632
3835
|
* - a failed request likewise leaves the cache unresolved (retry next need)
|
|
3633
3836
|
* and returns `null` — it must NEVER throw or block completion.
|
|
3634
3837
|
* A failure is logged with agent/session context (no silent catch).
|
|
@@ -3641,7 +3844,7 @@ var ChannelDriver = class {
|
|
|
3641
3844
|
if (res.ok) {
|
|
3642
3845
|
const body = await res.json();
|
|
3643
3846
|
const title = body && typeof body.title === "string" ? body.title.trim() : "";
|
|
3644
|
-
if (title.length > 0) {
|
|
3847
|
+
if (title.length > 0 && !_ChannelDriver.OPENCODE_DEFAULT_TITLE_PREFIX.test(title)) {
|
|
3645
3848
|
this.sessionTitles.set(sessionId, title);
|
|
3646
3849
|
return title;
|
|
3647
3850
|
}
|
|
@@ -3847,6 +4050,32 @@ var ChannelDriver = class {
|
|
|
3847
4050
|
}
|
|
3848
4051
|
return messages;
|
|
3849
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
|
+
}
|
|
3850
4079
|
/**
|
|
3851
4080
|
* EXISTING combinedAuth route — now fired by the watcher on queued→running
|
|
3852
4081
|
* (Task 3.3), NOT at dispatch/claim time. `{status:'processing',
|
|
@@ -3876,7 +4105,7 @@ var ChannelDriver = class {
|
|
|
3876
4105
|
headers: { Authorization: this.getAuthHeader(), "Content-Type": "application/json" },
|
|
3877
4106
|
body: JSON.stringify({
|
|
3878
4107
|
status: "processing",
|
|
3879
|
-
|
|
4108
|
+
...this.sessionIdBody(sessionId, conversationId, messageId, "processing"),
|
|
3880
4109
|
...opencodeMessageId ? { opencode_message_id: opencodeMessageId } : {},
|
|
3881
4110
|
...title ? { title } : {}
|
|
3882
4111
|
})
|
|
@@ -3925,6 +4154,11 @@ var ChannelDriver = class {
|
|
|
3925
4154
|
headers: { Authorization: this.getAuthHeader(), "Content-Type": "application/json" },
|
|
3926
4155
|
body: JSON.stringify({
|
|
3927
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.
|
|
3928
4162
|
opencode_session_id: sessionId,
|
|
3929
4163
|
...opencodeMessageId ? { opencode_message_id: opencodeMessageId } : {},
|
|
3930
4164
|
...title ? { title } : {},
|
|
@@ -3941,14 +4175,23 @@ var ChannelDriver = class {
|
|
|
3941
4175
|
}
|
|
3942
4176
|
/**
|
|
3943
4177
|
* Mark a message `failed`. `sessionId` / `error` are threaded to the API ONLY
|
|
3944
|
-
* when provided (issue #182)
|
|
3945
|
-
* `
|
|
3946
|
-
*
|
|
3947
|
-
*
|
|
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).
|
|
3948
4187
|
*/
|
|
3949
4188
|
async markFailed(conversationId, messageId, sessionId, error2, usage) {
|
|
3950
4189
|
const body = { status: "failed" };
|
|
3951
|
-
if (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
|
+
}
|
|
3952
4195
|
if (error2 !== void 0) body.error = error2;
|
|
3953
4196
|
if (usage) Object.assign(body, usage);
|
|
3954
4197
|
await this.callWithRetry(
|
|
@@ -4872,6 +5115,21 @@ async function run(options) {
|
|
|
4872
5115
|
logActivity(state, { type: "info", level: "warn", message: versionWarning });
|
|
4873
5116
|
}
|
|
4874
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
|
+
}
|
|
4875
5133
|
} catch (error2) {
|
|
4876
5134
|
ocSpinner?.fail(error2.message);
|
|
4877
5135
|
throw error2;
|
|
@@ -5048,7 +5306,10 @@ program.name("evident").description("Run OpenCode locally and connect it to Evid
|
|
|
5048
5306
|
program.command("login").description("Authenticate with Evident").option("--token", "Use token-based authentication (for CI/CD)").option("--no-browser", "Do not open the browser automatically").action(login);
|
|
5049
5307
|
program.command("logout").description("Remove stored credentials for the current endpoint").option("--all", "Remove stored credentials for all endpoints").action((options) => logout({ all: options.all }));
|
|
5050
5308
|
program.command("whoami").description("Show the currently logged in user").action(whoami);
|
|
5051
|
-
program.command("run").description("Connect to Evident and process messages").option("
|
|
5309
|
+
program.command("run").description("Connect to Evident and process messages").option("--runner [id]", "Runner ID to connect to (optional when EVIDENT_RUNNER_KEY is set)").option(
|
|
5310
|
+
"-a, --agent [id]",
|
|
5311
|
+
"Deprecated alias for --runner (still supported; --runner wins if both are given)"
|
|
5312
|
+
).option("-p, --port <port>", "OpenCode port (default: 4096)", "4096").option(
|
|
5052
5313
|
"--log-level <level>",
|
|
5053
5314
|
"Log verbosity: debug | info | warn | error (default: info). Env: EVIDENT_LOG_LEVEL"
|
|
5054
5315
|
).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(
|