@evident-ai/cli 3.1.1-dev.3a785a9 → 3.1.1-dev.3b3c960
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 +167 -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;
|
|
@@ -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}`;
|
|
@@ -1261,6 +1273,16 @@ async function buildFileParts(attachments, capable) {
|
|
|
1261
1273
|
);
|
|
1262
1274
|
dataUrl = null;
|
|
1263
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
|
+
}
|
|
1264
1286
|
if (dataUrl == null) {
|
|
1265
1287
|
outcomes.push({ index: a.index, mime: a.mime, filename: a.filename, status: "failed" });
|
|
1266
1288
|
continue;
|
|
@@ -1489,6 +1511,37 @@ function hasRunningAssistantExcept(messages, exceptUserMessageId) {
|
|
|
1489
1511
|
(m) => roleOf(m) === "assistant" && parentIdOf(m) !== exceptUserMessageId && isAssistantInFlight(m)
|
|
1490
1512
|
);
|
|
1491
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
|
+
}
|
|
1492
1545
|
|
|
1493
1546
|
// src/lib/opencode/session-cleanup.ts
|
|
1494
1547
|
var DURATION_UNIT_MS = {
|
|
@@ -1647,10 +1700,11 @@ var StreamForwarder = class {
|
|
|
1647
1700
|
* Abort every in-flight stream (e.g. on WebSocket close).
|
|
1648
1701
|
*/
|
|
1649
1702
|
abortAll() {
|
|
1650
|
-
for (const stream of this.inflight.
|
|
1703
|
+
for (const [sid, stream] of this.inflight.entries()) {
|
|
1651
1704
|
try {
|
|
1652
1705
|
stream.abort();
|
|
1653
|
-
} catch {
|
|
1706
|
+
} catch (err) {
|
|
1707
|
+
log("error", "forwarder_abort_failed", { sid, ...errorFields(err) });
|
|
1654
1708
|
}
|
|
1655
1709
|
}
|
|
1656
1710
|
this.inflight.clear();
|
|
@@ -1923,7 +1977,11 @@ var RunnerConnection = class {
|
|
|
1923
1977
|
if (this.connection) {
|
|
1924
1978
|
try {
|
|
1925
1979
|
this.connection.close();
|
|
1926
|
-
} catch {
|
|
1980
|
+
} catch (err) {
|
|
1981
|
+
log("error", "runner_connection_close_failed", {
|
|
1982
|
+
agent_id: this.resolvedAgentId,
|
|
1983
|
+
...errorFields(err)
|
|
1984
|
+
});
|
|
1927
1985
|
}
|
|
1928
1986
|
this.connection = null;
|
|
1929
1987
|
}
|
|
@@ -2026,7 +2084,7 @@ function backoffDelay(attempt, policy) {
|
|
|
2026
2084
|
function isRetryableStatus(status) {
|
|
2027
2085
|
return status === 429 || status >= 500 && status <= 599;
|
|
2028
2086
|
}
|
|
2029
|
-
var ChannelDriver = class {
|
|
2087
|
+
var ChannelDriver = class _ChannelDriver {
|
|
2030
2088
|
agentId;
|
|
2031
2089
|
port;
|
|
2032
2090
|
apiUrl;
|
|
@@ -2151,9 +2209,12 @@ var ChannelDriver = class {
|
|
|
2151
2209
|
sessionParents = /* @__PURE__ */ new Map();
|
|
2152
2210
|
/**
|
|
2153
2211
|
* Per-session OpenCode title cache (#310), keyed by sessionId. Only a resolved
|
|
2154
|
-
* NON-EMPTY name is stored (terminal — a real session name
|
|
2155
|
-
* so we do NOT re-GET `/session/:id` every tick.
|
|
2156
|
-
*
|
|
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
|
|
2157
2218
|
* names sessions asynchronously mid-turn. Driver-level (not per-watcher) so both
|
|
2158
2219
|
* the watcher completion path AND the restart-recovery re-adopt path (which has
|
|
2159
2220
|
* no watcher) can resolve the title.
|
|
@@ -2377,7 +2438,8 @@ var ChannelDriver = class {
|
|
|
2377
2438
|
} catch (err) {
|
|
2378
2439
|
if (err instanceof ChannelAuthError) throw err;
|
|
2379
2440
|
this.dispatched.delete(message.id);
|
|
2380
|
-
|
|
2441
|
+
const exists = await sessionExists(this.port, sessionId);
|
|
2442
|
+
if (exists === false) {
|
|
2381
2443
|
this.sessions.delete(conv.id);
|
|
2382
2444
|
this.log({
|
|
2383
2445
|
level: "warn",
|
|
@@ -2387,15 +2449,32 @@ var ChannelDriver = class {
|
|
|
2387
2449
|
});
|
|
2388
2450
|
break;
|
|
2389
2451
|
}
|
|
2390
|
-
|
|
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
|
+
});
|
|
2391
2470
|
});
|
|
2392
2471
|
this.log({
|
|
2393
2472
|
level: "error",
|
|
2394
|
-
message: `Message ${message.id.slice(0, 8)} dispatch failed: ${
|
|
2473
|
+
message: `Message ${message.id.slice(0, 8)} dispatch failed: ${errorMessage}`,
|
|
2395
2474
|
conversation_id: conv.id,
|
|
2396
2475
|
message_id: message.id
|
|
2397
2476
|
});
|
|
2398
|
-
|
|
2477
|
+
break;
|
|
2399
2478
|
}
|
|
2400
2479
|
if (opencodeMessageId === null) {
|
|
2401
2480
|
this.log({
|
|
@@ -2525,7 +2604,11 @@ var ChannelDriver = class {
|
|
|
2525
2604
|
* (not-owned / out-of-range / deleted-at-source / workspace gone) / 413
|
|
2526
2605
|
* (over-cap). On ANY non-2xx or thrown failure we return `null` so the caller
|
|
2527
2606
|
* OMITS that one image and the text turn still sends — NEVER throws the turn.
|
|
2528
|
-
*
|
|
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).
|
|
2529
2612
|
*/
|
|
2530
2613
|
async fetchAttachmentDataUrl(messageId, index, mime) {
|
|
2531
2614
|
try {
|
|
@@ -2534,6 +2617,25 @@ var ChannelDriver = class {
|
|
|
2534
2617
|
{ headers: { Authorization: this.getAuthHeader() } }
|
|
2535
2618
|
);
|
|
2536
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
|
+
}
|
|
2537
2639
|
this.log({
|
|
2538
2640
|
level: "error",
|
|
2539
2641
|
message: `Attachment fetch for message ${messageId.slice(0, 8)} index ${index} returned HTTP ${res.status} \u2014 omitting this image (text turn proceeds)`,
|
|
@@ -2573,6 +2675,9 @@ var ChannelDriver = class {
|
|
|
2573
2675
|
if (this.attachmentsSkippedSignalled.has(messageId)) return;
|
|
2574
2676
|
this.attachmentsSkippedSignalled.add(messageId);
|
|
2575
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;
|
|
2576
2681
|
this.log({
|
|
2577
2682
|
level: "info",
|
|
2578
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`,
|
|
@@ -2582,7 +2687,8 @@ var ChannelDriver = class {
|
|
|
2582
2687
|
void this.postSignal(conversationId, messageId, "attachments_skipped", {
|
|
2583
2688
|
skipped,
|
|
2584
2689
|
failed,
|
|
2585
|
-
...skipped > 0 ? { skipped_reason: skippedReason } : {}
|
|
2690
|
+
...skipped > 0 ? { skipped_reason: skippedReason } : {},
|
|
2691
|
+
...failedReason ? { failed_reason: failedReason } : {}
|
|
2586
2692
|
});
|
|
2587
2693
|
}
|
|
2588
2694
|
/** Register a freshly-dispatched message with its session's watcher state. */
|
|
@@ -3621,19 +3727,36 @@ var ChannelDriver = class {
|
|
|
3621
3727
|
if (parent !== void 0) this.sessionParents.set(sessionId, parent);
|
|
3622
3728
|
return parent;
|
|
3623
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 - /;
|
|
3624
3743
|
/**
|
|
3625
3744
|
* Resolve (and cache in `sessionTitles`) the OpenCode session TITLE (#310) so the
|
|
3626
3745
|
* status PATCH can carry it into the "Live sessions" list. Driver-level cache so
|
|
3627
3746
|
* BOTH the watcher completion path and the restart-recovery re-adopt path (which
|
|
3628
3747
|
* has no watcher) can use it. `conversationId` is passed only for log context.
|
|
3629
3748
|
* Best-effort:
|
|
3630
|
-
* - 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
|
|
3631
3751
|
* won't later un-name), so we do NOT re-GET `/session/:id` every tick;
|
|
3632
|
-
* - while the title is still absent
|
|
3633
|
-
*
|
|
3634
|
-
*
|
|
3635
|
-
*
|
|
3636
|
-
*
|
|
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;
|
|
3637
3760
|
* - a failed request likewise leaves the cache unresolved (retry next need)
|
|
3638
3761
|
* and returns `null` — it must NEVER throw or block completion.
|
|
3639
3762
|
* A failure is logged with agent/session context (no silent catch).
|
|
@@ -3646,7 +3769,7 @@ var ChannelDriver = class {
|
|
|
3646
3769
|
if (res.ok) {
|
|
3647
3770
|
const body = await res.json();
|
|
3648
3771
|
const title = body && typeof body.title === "string" ? body.title.trim() : "";
|
|
3649
|
-
if (title.length > 0) {
|
|
3772
|
+
if (title.length > 0 && !_ChannelDriver.OPENCODE_DEFAULT_TITLE_PREFIX.test(title)) {
|
|
3650
3773
|
this.sessionTitles.set(sessionId, title);
|
|
3651
3774
|
return title;
|
|
3652
3775
|
}
|
|
@@ -3946,10 +4069,15 @@ var ChannelDriver = class {
|
|
|
3946
4069
|
}
|
|
3947
4070
|
/**
|
|
3948
4071
|
* Mark a message `failed`. `sessionId` / `error` are threaded to the API ONLY
|
|
3949
|
-
* when provided (issue #182)
|
|
3950
|
-
* `
|
|
3951
|
-
*
|
|
3952
|
-
*
|
|
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).
|
|
3953
4081
|
*/
|
|
3954
4082
|
async markFailed(conversationId, messageId, sessionId, error2, usage) {
|
|
3955
4083
|
const body = { status: "failed" };
|
|
@@ -4877,6 +5005,21 @@ async function run(options) {
|
|
|
4877
5005
|
logActivity(state, { type: "info", level: "warn", message: versionWarning });
|
|
4878
5006
|
}
|
|
4879
5007
|
}
|
|
5008
|
+
const noProviderWarning = buildNoProviderWarning(await hasAnyConfiguredProvider(state.port));
|
|
5009
|
+
if (noProviderWarning) {
|
|
5010
|
+
log2(state, noProviderWarning, "warn");
|
|
5011
|
+
if (state.interactive && !state.json) {
|
|
5012
|
+
logActivity(state, { type: "info", level: "warn", message: noProviderWarning });
|
|
5013
|
+
blank();
|
|
5014
|
+
console.log(chalk6.yellow("\u26A0 No OpenCode model provider is configured."));
|
|
5015
|
+
console.log(
|
|
5016
|
+
chalk6.dim(
|
|
5017
|
+
`Run ${chalk6.cyan("opencode auth login")} to set one up \u2014 messages will fail until then.`
|
|
5018
|
+
)
|
|
5019
|
+
);
|
|
5020
|
+
blank();
|
|
5021
|
+
}
|
|
5022
|
+
}
|
|
4880
5023
|
} catch (error2) {
|
|
4881
5024
|
ocSpinner?.fail(error2.message);
|
|
4882
5025
|
throw error2;
|