@evident-ai/cli 3.1.1-dev.3b9fb81 → 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 +173 -25
- 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;
|
|
@@ -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
|
|
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.
|
|
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
|
}
|
|
@@ -2021,7 +2084,7 @@ function backoffDelay(attempt, policy) {
|
|
|
2021
2084
|
function isRetryableStatus(status) {
|
|
2022
2085
|
return status === 429 || status >= 500 && status <= 599;
|
|
2023
2086
|
}
|
|
2024
|
-
var ChannelDriver = class {
|
|
2087
|
+
var ChannelDriver = class _ChannelDriver {
|
|
2025
2088
|
agentId;
|
|
2026
2089
|
port;
|
|
2027
2090
|
apiUrl;
|
|
@@ -2146,9 +2209,12 @@ var ChannelDriver = class {
|
|
|
2146
2209
|
sessionParents = /* @__PURE__ */ new Map();
|
|
2147
2210
|
/**
|
|
2148
2211
|
* 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
|
-
*
|
|
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
|
|
2152
2218
|
* names sessions asynchronously mid-turn. Driver-level (not per-watcher) so both
|
|
2153
2219
|
* the watcher completion path AND the restart-recovery re-adopt path (which has
|
|
2154
2220
|
* no watcher) can resolve the title.
|
|
@@ -2372,7 +2438,8 @@ var ChannelDriver = class {
|
|
|
2372
2438
|
} catch (err) {
|
|
2373
2439
|
if (err instanceof ChannelAuthError) throw err;
|
|
2374
2440
|
this.dispatched.delete(message.id);
|
|
2375
|
-
|
|
2441
|
+
const exists = await sessionExists(this.port, sessionId);
|
|
2442
|
+
if (exists === false) {
|
|
2376
2443
|
this.sessions.delete(conv.id);
|
|
2377
2444
|
this.log({
|
|
2378
2445
|
level: "warn",
|
|
@@ -2382,15 +2449,32 @@ var ChannelDriver = class {
|
|
|
2382
2449
|
});
|
|
2383
2450
|
break;
|
|
2384
2451
|
}
|
|
2385
|
-
|
|
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
|
+
});
|
|
2386
2470
|
});
|
|
2387
2471
|
this.log({
|
|
2388
2472
|
level: "error",
|
|
2389
|
-
message: `Message ${message.id.slice(0, 8)} dispatch failed: ${
|
|
2473
|
+
message: `Message ${message.id.slice(0, 8)} dispatch failed: ${errorMessage}`,
|
|
2390
2474
|
conversation_id: conv.id,
|
|
2391
2475
|
message_id: message.id
|
|
2392
2476
|
});
|
|
2393
|
-
|
|
2477
|
+
break;
|
|
2394
2478
|
}
|
|
2395
2479
|
if (opencodeMessageId === null) {
|
|
2396
2480
|
this.log({
|
|
@@ -2520,7 +2604,11 @@ var ChannelDriver = class {
|
|
|
2520
2604
|
* (not-owned / out-of-range / deleted-at-source / workspace gone) / 413
|
|
2521
2605
|
* (over-cap). On ANY non-2xx or thrown failure we return `null` so the caller
|
|
2522
2606
|
* OMITS that one image and the text turn still sends — NEVER throws the turn.
|
|
2523
|
-
*
|
|
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).
|
|
2524
2612
|
*/
|
|
2525
2613
|
async fetchAttachmentDataUrl(messageId, index, mime) {
|
|
2526
2614
|
try {
|
|
@@ -2529,6 +2617,25 @@ var ChannelDriver = class {
|
|
|
2529
2617
|
{ headers: { Authorization: this.getAuthHeader() } }
|
|
2530
2618
|
);
|
|
2531
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
|
+
}
|
|
2532
2639
|
this.log({
|
|
2533
2640
|
level: "error",
|
|
2534
2641
|
message: `Attachment fetch for message ${messageId.slice(0, 8)} index ${index} returned HTTP ${res.status} \u2014 omitting this image (text turn proceeds)`,
|
|
@@ -2568,6 +2675,9 @@ var ChannelDriver = class {
|
|
|
2568
2675
|
if (this.attachmentsSkippedSignalled.has(messageId)) return;
|
|
2569
2676
|
this.attachmentsSkippedSignalled.add(messageId);
|
|
2570
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;
|
|
2571
2681
|
this.log({
|
|
2572
2682
|
level: "info",
|
|
2573
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`,
|
|
@@ -2577,7 +2687,8 @@ var ChannelDriver = class {
|
|
|
2577
2687
|
void this.postSignal(conversationId, messageId, "attachments_skipped", {
|
|
2578
2688
|
skipped,
|
|
2579
2689
|
failed,
|
|
2580
|
-
...skipped > 0 ? { skipped_reason: skippedReason } : {}
|
|
2690
|
+
...skipped > 0 ? { skipped_reason: skippedReason } : {},
|
|
2691
|
+
...failedReason ? { failed_reason: failedReason } : {}
|
|
2581
2692
|
});
|
|
2582
2693
|
}
|
|
2583
2694
|
/** Register a freshly-dispatched message with its session's watcher state. */
|
|
@@ -3616,19 +3727,36 @@ var ChannelDriver = class {
|
|
|
3616
3727
|
if (parent !== void 0) this.sessionParents.set(sessionId, parent);
|
|
3617
3728
|
return parent;
|
|
3618
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 - /;
|
|
3619
3743
|
/**
|
|
3620
3744
|
* Resolve (and cache in `sessionTitles`) the OpenCode session TITLE (#310) so the
|
|
3621
3745
|
* status PATCH can carry it into the "Live sessions" list. Driver-level cache so
|
|
3622
3746
|
* BOTH the watcher completion path and the restart-recovery re-adopt path (which
|
|
3623
3747
|
* has no watcher) can use it. `conversationId` is passed only for log context.
|
|
3624
3748
|
* Best-effort:
|
|
3625
|
-
* - 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
|
|
3626
3751
|
* 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
|
-
*
|
|
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;
|
|
3632
3760
|
* - a failed request likewise leaves the cache unresolved (retry next need)
|
|
3633
3761
|
* and returns `null` — it must NEVER throw or block completion.
|
|
3634
3762
|
* A failure is logged with agent/session context (no silent catch).
|
|
@@ -3641,7 +3769,7 @@ var ChannelDriver = class {
|
|
|
3641
3769
|
if (res.ok) {
|
|
3642
3770
|
const body = await res.json();
|
|
3643
3771
|
const title = body && typeof body.title === "string" ? body.title.trim() : "";
|
|
3644
|
-
if (title.length > 0) {
|
|
3772
|
+
if (title.length > 0 && !_ChannelDriver.OPENCODE_DEFAULT_TITLE_PREFIX.test(title)) {
|
|
3645
3773
|
this.sessionTitles.set(sessionId, title);
|
|
3646
3774
|
return title;
|
|
3647
3775
|
}
|
|
@@ -3941,10 +4069,15 @@ var ChannelDriver = class {
|
|
|
3941
4069
|
}
|
|
3942
4070
|
/**
|
|
3943
4071
|
* Mark a message `failed`. `sessionId` / `error` are threaded to the API ONLY
|
|
3944
|
-
* when provided (issue #182)
|
|
3945
|
-
* `
|
|
3946
|
-
*
|
|
3947
|
-
*
|
|
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).
|
|
3948
4081
|
*/
|
|
3949
4082
|
async markFailed(conversationId, messageId, sessionId, error2, usage) {
|
|
3950
4083
|
const body = { status: "failed" };
|
|
@@ -4872,6 +5005,21 @@ async function run(options) {
|
|
|
4872
5005
|
logActivity(state, { type: "info", level: "warn", message: versionWarning });
|
|
4873
5006
|
}
|
|
4874
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
|
+
}
|
|
4875
5023
|
} catch (error2) {
|
|
4876
5024
|
ocSpinner?.fail(error2.message);
|
|
4877
5025
|
throw error2;
|