@evident-ai/cli 3.1.1-dev.4159d3a → 3.1.1-dev.5101e0f
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 +115 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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;
|
|
@@ -1267,6 +1273,16 @@ async function buildFileParts(attachments, capable) {
|
|
|
1267
1273
|
);
|
|
1268
1274
|
dataUrl = null;
|
|
1269
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
|
+
}
|
|
1270
1286
|
if (dataUrl == null) {
|
|
1271
1287
|
outcomes.push({ index: a.index, mime: a.mime, filename: a.filename, status: "failed" });
|
|
1272
1288
|
continue;
|
|
@@ -1684,10 +1700,11 @@ var StreamForwarder = class {
|
|
|
1684
1700
|
* Abort every in-flight stream (e.g. on WebSocket close).
|
|
1685
1701
|
*/
|
|
1686
1702
|
abortAll() {
|
|
1687
|
-
for (const stream of this.inflight.
|
|
1703
|
+
for (const [sid, stream] of this.inflight.entries()) {
|
|
1688
1704
|
try {
|
|
1689
1705
|
stream.abort();
|
|
1690
|
-
} catch {
|
|
1706
|
+
} catch (err) {
|
|
1707
|
+
log("error", "forwarder_abort_failed", { sid, ...errorFields(err) });
|
|
1691
1708
|
}
|
|
1692
1709
|
}
|
|
1693
1710
|
this.inflight.clear();
|
|
@@ -1960,7 +1977,11 @@ var RunnerConnection = class {
|
|
|
1960
1977
|
if (this.connection) {
|
|
1961
1978
|
try {
|
|
1962
1979
|
this.connection.close();
|
|
1963
|
-
} catch {
|
|
1980
|
+
} catch (err) {
|
|
1981
|
+
log("error", "runner_connection_close_failed", {
|
|
1982
|
+
agent_id: this.resolvedAgentId,
|
|
1983
|
+
...errorFields(err)
|
|
1984
|
+
});
|
|
1964
1985
|
}
|
|
1965
1986
|
this.connection = null;
|
|
1966
1987
|
}
|
|
@@ -2063,7 +2084,7 @@ function backoffDelay(attempt, policy) {
|
|
|
2063
2084
|
function isRetryableStatus(status) {
|
|
2064
2085
|
return status === 429 || status >= 500 && status <= 599;
|
|
2065
2086
|
}
|
|
2066
|
-
var ChannelDriver = class {
|
|
2087
|
+
var ChannelDriver = class _ChannelDriver {
|
|
2067
2088
|
agentId;
|
|
2068
2089
|
port;
|
|
2069
2090
|
apiUrl;
|
|
@@ -2188,9 +2209,12 @@ var ChannelDriver = class {
|
|
|
2188
2209
|
sessionParents = /* @__PURE__ */ new Map();
|
|
2189
2210
|
/**
|
|
2190
2211
|
* Per-session OpenCode title cache (#310), keyed by sessionId. Only a resolved
|
|
2191
|
-
* NON-EMPTY name is stored (terminal — a real session name
|
|
2192
|
-
* so we do NOT re-GET `/session/:id` every tick.
|
|
2193
|
-
*
|
|
2212
|
+
* NON-EMPTY, non-placeholder name is stored (terminal — a real session name
|
|
2213
|
+
* won't later un-name), so we do NOT re-GET `/session/:id` every tick. "Non-empty"
|
|
2214
|
+
* excludes OpenCode's synchronous default title (see
|
|
2215
|
+
* `OPENCODE_DEFAULT_TITLE_PREFIX`, #549) — that placeholder is treated the same
|
|
2216
|
+
* as an empty title so it never latches. A missing entry = not yet resolved OR
|
|
2217
|
+
* resolved-but-still-empty/placeholder → re-fetch on next need, since OpenCode
|
|
2194
2218
|
* names sessions asynchronously mid-turn. Driver-level (not per-watcher) so both
|
|
2195
2219
|
* the watcher completion path AND the restart-recovery re-adopt path (which has
|
|
2196
2220
|
* no watcher) can resolve the title.
|
|
@@ -2414,7 +2438,8 @@ var ChannelDriver = class {
|
|
|
2414
2438
|
} catch (err) {
|
|
2415
2439
|
if (err instanceof ChannelAuthError) throw err;
|
|
2416
2440
|
this.dispatched.delete(message.id);
|
|
2417
|
-
|
|
2441
|
+
const exists = await sessionExists(this.port, sessionId);
|
|
2442
|
+
if (exists === false) {
|
|
2418
2443
|
this.sessions.delete(conv.id);
|
|
2419
2444
|
this.log({
|
|
2420
2445
|
level: "warn",
|
|
@@ -2424,15 +2449,32 @@ var ChannelDriver = class {
|
|
|
2424
2449
|
});
|
|
2425
2450
|
break;
|
|
2426
2451
|
}
|
|
2427
|
-
|
|
2452
|
+
if (exists === null) {
|
|
2453
|
+
this.log({
|
|
2454
|
+
level: "warn",
|
|
2455
|
+
message: `Message ${message.id.slice(0, 8)} dispatch failed and session (${sessionId.slice(0, 8)}) existence could not be confirmed (opencode momentarily unreachable) \u2014 deferring this and later messages for conversation ${conv.id.slice(0, 8)} to the next tick rather than treating it as a genuine failure.`,
|
|
2456
|
+
conversation_id: conv.id,
|
|
2457
|
+
message_id: message.id
|
|
2458
|
+
});
|
|
2459
|
+
break;
|
|
2460
|
+
}
|
|
2461
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
2462
|
+
this.sessions.delete(conv.id);
|
|
2463
|
+
await this.markFailed(conv.id, message.id, null, errorMessage).catch((markErr) => {
|
|
2464
|
+
this.log({
|
|
2465
|
+
level: "warn",
|
|
2466
|
+
message: `markFailed PATCH for message ${message.id.slice(0, 8)} (conversation ${conv.id.slice(0, 8)}) failed (best-effort, not retried): ${markErr instanceof Error ? markErr.message : String(markErr)}`,
|
|
2467
|
+
conversation_id: conv.id,
|
|
2468
|
+
message_id: message.id
|
|
2469
|
+
});
|
|
2428
2470
|
});
|
|
2429
2471
|
this.log({
|
|
2430
2472
|
level: "error",
|
|
2431
|
-
message: `Message ${message.id.slice(0, 8)} dispatch failed: ${
|
|
2473
|
+
message: `Message ${message.id.slice(0, 8)} dispatch failed: ${errorMessage}`,
|
|
2432
2474
|
conversation_id: conv.id,
|
|
2433
2475
|
message_id: message.id
|
|
2434
2476
|
});
|
|
2435
|
-
|
|
2477
|
+
break;
|
|
2436
2478
|
}
|
|
2437
2479
|
if (opencodeMessageId === null) {
|
|
2438
2480
|
this.log({
|
|
@@ -2562,7 +2604,11 @@ var ChannelDriver = class {
|
|
|
2562
2604
|
* (not-owned / out-of-range / deleted-at-source / workspace gone) / 413
|
|
2563
2605
|
* (over-cap). On ANY non-2xx or thrown failure we return `null` so the caller
|
|
2564
2606
|
* OMITS that one image and the text turn still sends — NEVER throws the turn.
|
|
2565
|
-
*
|
|
2607
|
+
* A 404 body carrying `{ reason: 'needs_reauth' }` (#547 — the server CONFIRMED
|
|
2608
|
+
* a Slack `files:read` scope problem via `files.info`) instead resolves the
|
|
2609
|
+
* `AttachmentFetchNeedsReauth` sentinel, so the in-thread note can steer the
|
|
2610
|
+
* user to reconnect Slack instead of a generic "unavailable". Failures are
|
|
2611
|
+
* logged with context (no silent swallow).
|
|
2566
2612
|
*/
|
|
2567
2613
|
async fetchAttachmentDataUrl(messageId, index, mime) {
|
|
2568
2614
|
try {
|
|
@@ -2571,6 +2617,25 @@ var ChannelDriver = class {
|
|
|
2571
2617
|
{ headers: { Authorization: this.getAuthHeader() } }
|
|
2572
2618
|
);
|
|
2573
2619
|
if (!res.ok) {
|
|
2620
|
+
let reason;
|
|
2621
|
+
try {
|
|
2622
|
+
const body = await res.json();
|
|
2623
|
+
if (body && typeof body.reason === "string") reason = body.reason;
|
|
2624
|
+
} catch (parseErr) {
|
|
2625
|
+
this.log({
|
|
2626
|
+
level: "debug",
|
|
2627
|
+
message: `Attachment fetch for message ${messageId.slice(0, 8)} index ${index}: error body was not JSON (${parseErr instanceof Error ? parseErr.message : String(parseErr)}) \u2014 treating as a plain failure`,
|
|
2628
|
+
message_id: messageId
|
|
2629
|
+
});
|
|
2630
|
+
}
|
|
2631
|
+
if (reason === "needs_reauth") {
|
|
2632
|
+
this.log({
|
|
2633
|
+
level: "error",
|
|
2634
|
+
message: `Attachment fetch for message ${messageId.slice(0, 8)} index ${index} returned HTTP ${res.status} \u2014 server confirmed a Slack reauth/scope problem \u2014 omitting this image (text turn proceeds)`,
|
|
2635
|
+
message_id: messageId
|
|
2636
|
+
});
|
|
2637
|
+
return { needsReauth: true };
|
|
2638
|
+
}
|
|
2574
2639
|
this.log({
|
|
2575
2640
|
level: "error",
|
|
2576
2641
|
message: `Attachment fetch for message ${messageId.slice(0, 8)} index ${index} returned HTTP ${res.status} \u2014 omitting this image (text turn proceeds)`,
|
|
@@ -2610,6 +2675,9 @@ var ChannelDriver = class {
|
|
|
2610
2675
|
if (this.attachmentsSkippedSignalled.has(messageId)) return;
|
|
2611
2676
|
this.attachmentsSkippedSignalled.add(messageId);
|
|
2612
2677
|
const skippedReason = capabilityUnknown ? "unknown" : "unsupported";
|
|
2678
|
+
const failedReason = outcomes.some(
|
|
2679
|
+
(o) => o.status === "failed" && o.reason === "needs_reauth"
|
|
2680
|
+
) ? "needs_reauth" : void 0;
|
|
2613
2681
|
this.log({
|
|
2614
2682
|
level: "info",
|
|
2615
2683
|
message: `Message ${messageId.slice(0, 8)}: ${skipped} image(s) skipped (${capabilityUnknown ? "capability was unreadable \u2014 failed open to text-only" : "model not attachment-capable"}), ${failed} image(s) unavailable (deleted-at-source or fetch failure) \u2014 noting to Evident`,
|
|
@@ -2619,7 +2687,8 @@ var ChannelDriver = class {
|
|
|
2619
2687
|
void this.postSignal(conversationId, messageId, "attachments_skipped", {
|
|
2620
2688
|
skipped,
|
|
2621
2689
|
failed,
|
|
2622
|
-
...skipped > 0 ? { skipped_reason: skippedReason } : {}
|
|
2690
|
+
...skipped > 0 ? { skipped_reason: skippedReason } : {},
|
|
2691
|
+
...failedReason ? { failed_reason: failedReason } : {}
|
|
2623
2692
|
});
|
|
2624
2693
|
}
|
|
2625
2694
|
/** Register a freshly-dispatched message with its session's watcher state. */
|
|
@@ -3658,19 +3727,36 @@ var ChannelDriver = class {
|
|
|
3658
3727
|
if (parent !== void 0) this.sessionParents.set(sessionId, parent);
|
|
3659
3728
|
return parent;
|
|
3660
3729
|
}
|
|
3730
|
+
/**
|
|
3731
|
+
* OpenCode's synchronous default session title (e.g.
|
|
3732
|
+
* `"New session - 1737800000000"`), assigned immediately when a session is
|
|
3733
|
+
* created — before OpenCode's async LLM-based auto-titling later renames it
|
|
3734
|
+
* mid-turn (#549). Matched by this literal, case-sensitive prefix only; the
|
|
3735
|
+
* timestamp suffix's exact format is deliberately NOT matched, since the prefix
|
|
3736
|
+
* alone is the stable, cheap signal and over-anchoring on the timestamp
|
|
3737
|
+
* representation risks silently breaking if OpenCode ever changes it. Accepted
|
|
3738
|
+
* trade-off: a genuine LLM-assigned title that happens to literally start with
|
|
3739
|
+
* this prefix would also fail to latch (see `resolveSessionTitle`) —
|
|
3740
|
+
* vanishingly unlikely in practice, and deliberately not engineered around.
|
|
3741
|
+
*/
|
|
3742
|
+
static OPENCODE_DEFAULT_TITLE_PREFIX = /^New session - /;
|
|
3661
3743
|
/**
|
|
3662
3744
|
* Resolve (and cache in `sessionTitles`) the OpenCode session TITLE (#310) so the
|
|
3663
3745
|
* status PATCH can carry it into the "Live sessions" list. Driver-level cache so
|
|
3664
3746
|
* BOTH the watcher completion path and the restart-recovery re-adopt path (which
|
|
3665
3747
|
* has no watcher) can use it. `conversationId` is passed only for log context.
|
|
3666
3748
|
* Best-effort:
|
|
3667
|
-
* - a resolved NON-EMPTY title
|
|
3749
|
+
* - a resolved NON-EMPTY title that does NOT match
|
|
3750
|
+
* `OPENCODE_DEFAULT_TITLE_PREFIX` is cached and terminal (a real session name
|
|
3668
3751
|
* won't later un-name), so we do NOT re-GET `/session/:id` every tick;
|
|
3669
|
-
* - while the title is still absent
|
|
3670
|
-
*
|
|
3671
|
-
*
|
|
3672
|
-
*
|
|
3673
|
-
*
|
|
3752
|
+
* - while the title is still absent, empty, or matches the OpenCode
|
|
3753
|
+
* placeholder prefix (#549) we do NOT latch it — OpenCode names sessions
|
|
3754
|
+
* asynchronously mid-turn, so an early call (e.g. at `processing`) must leave
|
|
3755
|
+
* the cache unresolved and re-fetch on the next need so a later call (e.g. at
|
|
3756
|
+
* `done`) picks up the name assigned in the meantime. Such a call returns
|
|
3757
|
+
* `null` (omit the title on THIS PATCH) without caching. If a session is
|
|
3758
|
+
* never renamed, the title is omitted forever rather than ever persisting
|
|
3759
|
+
* the placeholder as a last resort;
|
|
3674
3760
|
* - a failed request likewise leaves the cache unresolved (retry next need)
|
|
3675
3761
|
* and returns `null` — it must NEVER throw or block completion.
|
|
3676
3762
|
* A failure is logged with agent/session context (no silent catch).
|
|
@@ -3683,7 +3769,7 @@ var ChannelDriver = class {
|
|
|
3683
3769
|
if (res.ok) {
|
|
3684
3770
|
const body = await res.json();
|
|
3685
3771
|
const title = body && typeof body.title === "string" ? body.title.trim() : "";
|
|
3686
|
-
if (title.length > 0) {
|
|
3772
|
+
if (title.length > 0 && !_ChannelDriver.OPENCODE_DEFAULT_TITLE_PREFIX.test(title)) {
|
|
3687
3773
|
this.sessionTitles.set(sessionId, title);
|
|
3688
3774
|
return title;
|
|
3689
3775
|
}
|
|
@@ -3983,10 +4069,15 @@ var ChannelDriver = class {
|
|
|
3983
4069
|
}
|
|
3984
4070
|
/**
|
|
3985
4071
|
* Mark a message `failed`. `sessionId` / `error` are threaded to the API ONLY
|
|
3986
|
-
* when provided (issue #182)
|
|
3987
|
-
* `
|
|
3988
|
-
*
|
|
3989
|
-
*
|
|
4072
|
+
* when provided (issue #182). Three states for `sessionId`:
|
|
4073
|
+
* - omitted (`undefined`) → don't send the field, leave the persisted
|
|
4074
|
+
* session untouched (unused today; kept for API symmetry).
|
|
4075
|
+
* - a real id (`string`) → send it, update the persisted session (the
|
|
4076
|
+
* turn-failure call sites: an errored OpenCode turn).
|
|
4077
|
+
* - explicit `null` → send it, CLEAR the persisted session (issue
|
|
4078
|
+
* #485's dispatch-handoff-failure call site: the session id still
|
|
4079
|
+
* exists but is wedged, so the next attempt must get a fresh one
|
|
4080
|
+
* instead of reusing it — see WI-1's server-side null-clearing PATCH).
|
|
3990
4081
|
*/
|
|
3991
4082
|
async markFailed(conversationId, messageId, sessionId, error2, usage) {
|
|
3992
4083
|
const body = { status: "failed" };
|