@evident-ai/cli 3.6.1-dev.547a214 → 3.6.1-dev.57b3e59
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 +580 -64
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1178,11 +1178,9 @@ async function claudeUsage() {
|
|
|
1178
1178
|
}
|
|
1179
1179
|
}
|
|
1180
1180
|
|
|
1181
|
-
// src/commands/
|
|
1182
|
-
import {
|
|
1183
|
-
import
|
|
1184
|
-
import { isAbsolute as isAbsolute6, join as join17, parse, resolve as resolvePath2 } from "node:path";
|
|
1185
|
-
import chalk7 from "chalk";
|
|
1181
|
+
// src/commands/mcp-authorize.ts
|
|
1182
|
+
import { createServer } from "node:http";
|
|
1183
|
+
import open2 from "open";
|
|
1186
1184
|
|
|
1187
1185
|
// ../../packages/types/src/agents/index.ts
|
|
1188
1186
|
var MICROVM_MAX_LIFETIME_MS = 8 * 60 * 6e4;
|
|
@@ -1443,6 +1441,14 @@ function buildCredentialProxyNativeConfig({
|
|
|
1443
1441
|
};
|
|
1444
1442
|
}
|
|
1445
1443
|
|
|
1444
|
+
// ../../packages/types/src/mcp-proxies.ts
|
|
1445
|
+
var MCP_LOOPBACK_REDIRECT_POLICY = {
|
|
1446
|
+
scheme: "http",
|
|
1447
|
+
host: "127.0.0.1",
|
|
1448
|
+
path: "/callback",
|
|
1449
|
+
preferred_port: 18443
|
|
1450
|
+
};
|
|
1451
|
+
|
|
1446
1452
|
// ../../packages/types/src/logging/index.ts
|
|
1447
1453
|
var CORRELATION_ID_HEADER = "x-evident-correlation-id";
|
|
1448
1454
|
var FORWARD_FAILURE_REASON_HEADER = "X-Evident-Failure-Reason";
|
|
@@ -1477,12 +1483,506 @@ function stripQuery(url) {
|
|
|
1477
1483
|
}
|
|
1478
1484
|
}
|
|
1479
1485
|
|
|
1486
|
+
// src/commands/mcp-authorize.ts
|
|
1487
|
+
var API_TIMEOUT_MS = 1e4;
|
|
1488
|
+
var CALLBACK_OK_HTML = '<!doctype html><html><head><meta charset="utf-8"><title>Sign-in received</title></head><body><p>Sign-in response received. You can close this window.</p></body></html>';
|
|
1489
|
+
var CALLBACK_REJECTED_HTML = '<!doctype html><html><head><meta charset="utf-8"><title>Invalid response</title></head><body><p>This sign-in response was not accepted.</p></body></html>';
|
|
1490
|
+
var ApiHttpError = class extends Error {
|
|
1491
|
+
constructor(status2) {
|
|
1492
|
+
super(`Evident API returned HTTP ${status2}`);
|
|
1493
|
+
this.status = status2;
|
|
1494
|
+
}
|
|
1495
|
+
};
|
|
1496
|
+
var CallbackExpiredError = class extends Error {
|
|
1497
|
+
constructor() {
|
|
1498
|
+
super("The local sign-in attempt expired before the provider returned.");
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
var InterruptedError = class extends Error {
|
|
1502
|
+
constructor() {
|
|
1503
|
+
super("Authorization was interrupted.");
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
function apiPath(proxyId, connectionId, suffix) {
|
|
1507
|
+
const path = `/mcp-proxies/${encodeURIComponent(proxyId)}`;
|
|
1508
|
+
if (!connectionId) return path + "/connections";
|
|
1509
|
+
return `${path}/connections/${encodeURIComponent(connectionId)}/local-authorization/${suffix}`;
|
|
1510
|
+
}
|
|
1511
|
+
async function requestJson(path, credentials2, cancelSignal, operation, body) {
|
|
1512
|
+
const method = body === void 0 ? "GET" : "POST";
|
|
1513
|
+
const requestController = new AbortController();
|
|
1514
|
+
const onCancel = () => requestController.abort();
|
|
1515
|
+
const timeout = setTimeout(() => requestController.abort(), API_TIMEOUT_MS);
|
|
1516
|
+
cancelSignal.addEventListener("abort", onCancel, { once: true });
|
|
1517
|
+
if (cancelSignal.aborted) onCancel();
|
|
1518
|
+
try {
|
|
1519
|
+
let response;
|
|
1520
|
+
try {
|
|
1521
|
+
response = await fetch(`${getApiUrlConfig()}${path}`, {
|
|
1522
|
+
method,
|
|
1523
|
+
headers: {
|
|
1524
|
+
Authorization: getAuthHeader(credentials2),
|
|
1525
|
+
...body === void 0 ? {} : { "Content-Type": "application/json" }
|
|
1526
|
+
},
|
|
1527
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
1528
|
+
signal: requestController.signal
|
|
1529
|
+
});
|
|
1530
|
+
} catch (error2) {
|
|
1531
|
+
if (cancelSignal.aborted) throw new InterruptedError();
|
|
1532
|
+
if (requestController.signal.aborted) {
|
|
1533
|
+
throw new Error(`Evident timed out while ${operation} after ${API_TIMEOUT_MS}ms.`);
|
|
1534
|
+
}
|
|
1535
|
+
const detail = error2 instanceof Error ? error2.message : String(error2);
|
|
1536
|
+
throw new Error(
|
|
1537
|
+
`Could not reach Evident while ${operation}: ${detail}. Check --endpoint or EVIDENT_API_URL and retry.`
|
|
1538
|
+
);
|
|
1539
|
+
}
|
|
1540
|
+
if (!response.ok) throw new ApiHttpError(response.status);
|
|
1541
|
+
try {
|
|
1542
|
+
return await response.json();
|
|
1543
|
+
} catch (error2) {
|
|
1544
|
+
if (cancelSignal.aborted) throw new InterruptedError();
|
|
1545
|
+
if (requestController.signal.aborted) {
|
|
1546
|
+
throw new Error(`Evident timed out while ${operation} after ${API_TIMEOUT_MS}ms.`);
|
|
1547
|
+
}
|
|
1548
|
+
const detail = error2 instanceof Error ? error2.message : String(error2);
|
|
1549
|
+
throw new Error(`Evident returned an invalid response while ${operation}: ${detail}`);
|
|
1550
|
+
}
|
|
1551
|
+
} finally {
|
|
1552
|
+
clearTimeout(timeout);
|
|
1553
|
+
cancelSignal.removeEventListener("abort", onCancel);
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
function callbackResponse(response, status2, html) {
|
|
1557
|
+
response.writeHead(status2, {
|
|
1558
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
1559
|
+
"Cache-Control": "no-store",
|
|
1560
|
+
"Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'",
|
|
1561
|
+
"X-Content-Type-Options": "nosniff"
|
|
1562
|
+
});
|
|
1563
|
+
response.end(html);
|
|
1564
|
+
}
|
|
1565
|
+
function parseCallbackRequest(request3) {
|
|
1566
|
+
if (request3.method !== "GET" || !request3.url || !request3.url.startsWith("/") || request3.url.length > 16384) {
|
|
1567
|
+
return void 0;
|
|
1568
|
+
}
|
|
1569
|
+
if (request3.headers["transfer-encoding"] || Number(request3.headers["content-length"] ?? 0) > 0) {
|
|
1570
|
+
return void 0;
|
|
1571
|
+
}
|
|
1572
|
+
const callbackBase = `http://${MCP_LOOPBACK_REDIRECT_POLICY.host}`;
|
|
1573
|
+
if (!URL.canParse(request3.url, callbackBase)) return void 0;
|
|
1574
|
+
const url = new URL(request3.url, callbackBase);
|
|
1575
|
+
if (url.pathname !== MCP_LOOPBACK_REDIRECT_POLICY.path || url.hash) return void 0;
|
|
1576
|
+
const allowedParams = /* @__PURE__ */ new Set(["state", "code", "error", "error_description"]);
|
|
1577
|
+
for (const [key] of url.searchParams) {
|
|
1578
|
+
if (!allowedParams.has(key) || url.searchParams.getAll(key).length !== 1) return void 0;
|
|
1579
|
+
}
|
|
1580
|
+
const state = url.searchParams.get("state");
|
|
1581
|
+
const code = url.searchParams.get("code");
|
|
1582
|
+
const error2 = url.searchParams.get("error");
|
|
1583
|
+
const errorDescription = url.searchParams.get("error_description");
|
|
1584
|
+
if (!state || state.length > 2048 || Boolean(code) === Boolean(error2) || code !== null && (!code || code.length > 8192) || error2 !== null && (!error2 || error2.length > 256) || errorDescription !== null && (!error2 || errorDescription.length > 2048)) {
|
|
1585
|
+
return void 0;
|
|
1586
|
+
}
|
|
1587
|
+
return {
|
|
1588
|
+
state,
|
|
1589
|
+
...code === null ? {} : { code },
|
|
1590
|
+
...error2 === null ? {} : { error: error2 },
|
|
1591
|
+
...errorDescription === null ? {} : { error_description: errorDescription }
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
function handleCallbackRequest(request3, response, waiter) {
|
|
1595
|
+
if (!request3.url || !request3.url.startsWith("/") || !URL.canParse(request3.url, `http://${MCP_LOOPBACK_REDIRECT_POLICY.host}`)) {
|
|
1596
|
+
callbackResponse(response, 400, CALLBACK_REJECTED_HTML);
|
|
1597
|
+
return;
|
|
1598
|
+
}
|
|
1599
|
+
const pathname = new URL(request3.url, `http://${MCP_LOOPBACK_REDIRECT_POLICY.host}`).pathname;
|
|
1600
|
+
if (pathname !== MCP_LOOPBACK_REDIRECT_POLICY.path) {
|
|
1601
|
+
callbackResponse(response, 404, CALLBACK_REJECTED_HTML);
|
|
1602
|
+
return;
|
|
1603
|
+
}
|
|
1604
|
+
if (request3.method !== "GET") {
|
|
1605
|
+
response.setHeader("Allow", "GET");
|
|
1606
|
+
callbackResponse(response, 405, CALLBACK_REJECTED_HTML);
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
if (waiter.accepted) {
|
|
1610
|
+
callbackResponse(response, 409, CALLBACK_REJECTED_HTML);
|
|
1611
|
+
return;
|
|
1612
|
+
}
|
|
1613
|
+
const callback = parseCallbackRequest(request3);
|
|
1614
|
+
if (!callback || !waiter.expectedState || !waiter.expiresAtMs || Date.now() >= waiter.expiresAtMs || callback.state !== waiter.expectedState) {
|
|
1615
|
+
callbackResponse(response, 400, CALLBACK_REJECTED_HTML);
|
|
1616
|
+
return;
|
|
1617
|
+
}
|
|
1618
|
+
waiter.accepted = true;
|
|
1619
|
+
response.writeHead(200, {
|
|
1620
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
1621
|
+
"Cache-Control": "no-store",
|
|
1622
|
+
"Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'",
|
|
1623
|
+
"X-Content-Type-Options": "nosniff"
|
|
1624
|
+
});
|
|
1625
|
+
response.end(CALLBACK_OK_HTML, () => waiter.resolve?.(callback));
|
|
1626
|
+
}
|
|
1627
|
+
function listen(server, port) {
|
|
1628
|
+
return new Promise((resolve6, reject) => {
|
|
1629
|
+
const onError = (error2) => reject(error2);
|
|
1630
|
+
server.once("error", onError);
|
|
1631
|
+
server.listen(port, MCP_LOOPBACK_REDIRECT_POLICY.host, () => {
|
|
1632
|
+
server.removeListener("error", onError);
|
|
1633
|
+
const address = server.address();
|
|
1634
|
+
if (!address || typeof address === "string") {
|
|
1635
|
+
reject(new Error("The local callback listener did not report a TCP port."));
|
|
1636
|
+
return;
|
|
1637
|
+
}
|
|
1638
|
+
resolve6(address.port);
|
|
1639
|
+
});
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
function isAddressInUse(error2) {
|
|
1643
|
+
return typeof error2 === "object" && error2 !== null && "code" in error2 && error2.code === "EADDRINUSE";
|
|
1644
|
+
}
|
|
1645
|
+
async function bindCallbackListener(waiter) {
|
|
1646
|
+
const createListener = () => createServer((request3, response) => handleCallbackRequest(request3, response, waiter));
|
|
1647
|
+
try {
|
|
1648
|
+
const server2 = createListener();
|
|
1649
|
+
return { server: server2, port: await listen(server2, MCP_LOOPBACK_REDIRECT_POLICY.preferred_port) };
|
|
1650
|
+
} catch (error2) {
|
|
1651
|
+
if (!isAddressInUse(error2)) {
|
|
1652
|
+
throw new Error(
|
|
1653
|
+
`Could not listen on 127.0.0.1:${MCP_LOOPBACK_REDIRECT_POLICY.preferred_port}: ${error2 instanceof Error ? error2.message : String(error2)}`
|
|
1654
|
+
);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
const server = createListener();
|
|
1658
|
+
try {
|
|
1659
|
+
return { server, port: await listen(server, 0) };
|
|
1660
|
+
} catch (error2) {
|
|
1661
|
+
throw new Error(
|
|
1662
|
+
`Could not bind the local callback listener on preferred port ${MCP_LOOPBACK_REDIRECT_POLICY.preferred_port} or an ephemeral port: ${error2 instanceof Error ? error2.message : String(error2)}`
|
|
1663
|
+
);
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
function waitForCallback(waiter, expiresAtMs, signal) {
|
|
1667
|
+
return new Promise((resolve6, reject) => {
|
|
1668
|
+
const remainingMs = expiresAtMs - Date.now();
|
|
1669
|
+
if (remainingMs <= 0) {
|
|
1670
|
+
reject(new CallbackExpiredError());
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
if (signal.aborted) {
|
|
1674
|
+
reject(new InterruptedError());
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
let settled = false;
|
|
1678
|
+
function settle(callback, error2) {
|
|
1679
|
+
if (settled) return;
|
|
1680
|
+
settled = true;
|
|
1681
|
+
clearTimeout(timer);
|
|
1682
|
+
signal.removeEventListener("abort", onAbort);
|
|
1683
|
+
waiter.resolve = void 0;
|
|
1684
|
+
if (error2) reject(error2);
|
|
1685
|
+
else resolve6(callback);
|
|
1686
|
+
}
|
|
1687
|
+
const onAbort = () => settle(void 0, new InterruptedError());
|
|
1688
|
+
const timer = setTimeout(() => settle(void 0, new CallbackExpiredError()), remainingMs);
|
|
1689
|
+
waiter.expiresAtMs = expiresAtMs;
|
|
1690
|
+
waiter.resolve = (callback) => settle(callback);
|
|
1691
|
+
timer.unref?.();
|
|
1692
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1693
|
+
if (signal.aborted) onAbort();
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
function authorizationState(authorizationUrl) {
|
|
1697
|
+
let url;
|
|
1698
|
+
try {
|
|
1699
|
+
url = new URL(authorizationUrl);
|
|
1700
|
+
} catch (error2) {
|
|
1701
|
+
throw new Error(
|
|
1702
|
+
`Evident returned an invalid authorization URL: ${error2 instanceof Error ? error2.message : String(error2)}`
|
|
1703
|
+
);
|
|
1704
|
+
}
|
|
1705
|
+
const states = url.searchParams.getAll("state");
|
|
1706
|
+
if (url.protocol !== "https:" || url.username || url.password || url.hash || states.length !== 1 || !states[0]) {
|
|
1707
|
+
throw new Error("Evident returned an unsafe or incomplete authorization URL.");
|
|
1708
|
+
}
|
|
1709
|
+
return { url, state: states[0] };
|
|
1710
|
+
}
|
|
1711
|
+
function apiFailureMessage(error2) {
|
|
1712
|
+
switch (error2.status) {
|
|
1713
|
+
case 400:
|
|
1714
|
+
return "Evident rejected the local sign-in response. Retry the command; if it continues, update the CLI and try again.";
|
|
1715
|
+
case 401:
|
|
1716
|
+
return "Your Evident user session is missing or expired. If EVIDENT_TOKEN is set, update or unset it; otherwise run `evident login` for the selected endpoint, then retry.";
|
|
1717
|
+
case 403:
|
|
1718
|
+
return "Only workspace owners and admins can authorize MCP connections. Ask a workspace admin for access.";
|
|
1719
|
+
case 404:
|
|
1720
|
+
return "The MCP proxy or connection was not found. Check both IDs and try again.";
|
|
1721
|
+
case 409:
|
|
1722
|
+
return "This connection does not support local sign-in. Use its hosted authorization flow in Evident.";
|
|
1723
|
+
case 502:
|
|
1724
|
+
case 503:
|
|
1725
|
+
return "The Evident MCP authorization service is unavailable. Retry shortly or contact your workspace admin.";
|
|
1726
|
+
default:
|
|
1727
|
+
return `Evident rejected the request with HTTP ${error2.status}. Check your endpoint and retry.`;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
function completionFailureMessage(reason) {
|
|
1731
|
+
switch (reason) {
|
|
1732
|
+
case "state_unknown":
|
|
1733
|
+
return "This sign-in was started by another user or could not be found. Start a new authorization from the same user account.";
|
|
1734
|
+
case "state_consumed":
|
|
1735
|
+
return "This sign-in was already used. Start a new authorization.";
|
|
1736
|
+
case "state_expired":
|
|
1737
|
+
return "This sign-in attempt expired. Start a new authorization.";
|
|
1738
|
+
case "provider_denied":
|
|
1739
|
+
return "The provider denied the sign-in. Retry and approve the requested access.";
|
|
1740
|
+
case "provider_error":
|
|
1741
|
+
return "The provider could not complete sign-in. Retry, or contact the provider if it continues.";
|
|
1742
|
+
case "exchange_failed":
|
|
1743
|
+
return "The provider sign-in completed, but Evident could not exchange the authorization. Retry or contact support.";
|
|
1744
|
+
case "reconcile_failed":
|
|
1745
|
+
case "tools_pending":
|
|
1746
|
+
return "Sign-in completed, but Evident could not finish setting up this connection. Retry or contact support.";
|
|
1747
|
+
case "not_configured":
|
|
1748
|
+
return "Local authorization is not configured for this Evident environment. Contact your workspace admin.";
|
|
1749
|
+
default:
|
|
1750
|
+
return "Evident could not complete this sign-in. Start a new authorization and try again.";
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
function printLink(options, url, reason) {
|
|
1754
|
+
if (options.json) {
|
|
1755
|
+
console.error(JSON.stringify({ event: "authorization_required", authorization_url: url.href }));
|
|
1756
|
+
return;
|
|
1757
|
+
}
|
|
1758
|
+
printWarning(reason ?? "Open this authorization URL in your browser:");
|
|
1759
|
+
console.log(url.href);
|
|
1760
|
+
}
|
|
1761
|
+
function printResult(options, proxyId, connectionId, error2) {
|
|
1762
|
+
if (options.json) {
|
|
1763
|
+
console.log(
|
|
1764
|
+
JSON.stringify({
|
|
1765
|
+
ok: !error2,
|
|
1766
|
+
proxy_id: proxyId,
|
|
1767
|
+
connection_id: connectionId,
|
|
1768
|
+
...error2 ? { error: error2 } : {}
|
|
1769
|
+
})
|
|
1770
|
+
);
|
|
1771
|
+
} else if (error2) {
|
|
1772
|
+
printError(error2);
|
|
1773
|
+
} else {
|
|
1774
|
+
printSuccess("MCP connection authorized.");
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
function errorMessage(error2) {
|
|
1778
|
+
if (error2 instanceof ApiHttpError) return apiFailureMessage(error2);
|
|
1779
|
+
if (error2 instanceof CallbackExpiredError) {
|
|
1780
|
+
return "The sign-in attempt expired before the provider returned. Run the command again.";
|
|
1781
|
+
}
|
|
1782
|
+
if (error2 instanceof InterruptedError) return "Authorization was interrupted.";
|
|
1783
|
+
if (error2 instanceof Error) return error2.message;
|
|
1784
|
+
return `Authorization failed: ${String(error2)}`;
|
|
1785
|
+
}
|
|
1786
|
+
function requestFailed(reason) {
|
|
1787
|
+
if (reason instanceof Error) throw reason;
|
|
1788
|
+
throw new Error(`Authorization failed: ${String(reason)}`);
|
|
1789
|
+
}
|
|
1790
|
+
function validateConnectionList(value) {
|
|
1791
|
+
if (!value || !Array.isArray(value.mcp_proxy_connections)) {
|
|
1792
|
+
throw new Error("Evident returned an invalid MCP connection list. Update the CLI and retry.");
|
|
1793
|
+
}
|
|
1794
|
+
return value.mcp_proxy_connections;
|
|
1795
|
+
}
|
|
1796
|
+
function validateBeginResponse(value) {
|
|
1797
|
+
if (!value || typeof value.authorization_url !== "string" || typeof value.expires_at !== "string" || !Number.isFinite(Date.parse(value.expires_at))) {
|
|
1798
|
+
throw new Error(
|
|
1799
|
+
"Evident returned an invalid local authorization attempt. Update the CLI and retry."
|
|
1800
|
+
);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
function closeServer(server, force) {
|
|
1804
|
+
if (!server.listening) return Promise.resolve();
|
|
1805
|
+
return new Promise((resolve6, reject) => {
|
|
1806
|
+
server.close((error2) => error2 ? reject(error2) : resolve6());
|
|
1807
|
+
if (force) server.closeAllConnections();
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1810
|
+
async function authorizeMcpConnection(proxyId, connectionId, options = {}) {
|
|
1811
|
+
let credentials2;
|
|
1812
|
+
try {
|
|
1813
|
+
credentials2 = await getAuthCredentials();
|
|
1814
|
+
} catch (error2) {
|
|
1815
|
+
const kind = error2 instanceof Error ? error2.name : "unknown error";
|
|
1816
|
+
printResult(
|
|
1817
|
+
options,
|
|
1818
|
+
proxyId,
|
|
1819
|
+
connectionId,
|
|
1820
|
+
`Could not read the saved Evident credentials (${kind}). Check keychain access or run evident login again.`
|
|
1821
|
+
);
|
|
1822
|
+
process.exitCode = 1;
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
if (!credentials2) {
|
|
1826
|
+
printResult(
|
|
1827
|
+
options,
|
|
1828
|
+
proxyId,
|
|
1829
|
+
connectionId,
|
|
1830
|
+
"No credentials found. Run `evident login` and retry."
|
|
1831
|
+
);
|
|
1832
|
+
process.exitCode = 1;
|
|
1833
|
+
return;
|
|
1834
|
+
}
|
|
1835
|
+
if (credentials2.authType !== "bearer") {
|
|
1836
|
+
printResult(
|
|
1837
|
+
options,
|
|
1838
|
+
proxyId,
|
|
1839
|
+
connectionId,
|
|
1840
|
+
"MCP authorization requires a user login, not a runner key. Unset EVIDENT_RUNNER_KEY/EVIDENT_AGENT_KEY, then run `evident login`."
|
|
1841
|
+
);
|
|
1842
|
+
process.exitCode = 1;
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1845
|
+
const waiter = { accepted: false };
|
|
1846
|
+
let server;
|
|
1847
|
+
let closePromise;
|
|
1848
|
+
let closeFailureLogged = false;
|
|
1849
|
+
let failure;
|
|
1850
|
+
const cancelController = new AbortController();
|
|
1851
|
+
const closeListener = (force = false) => {
|
|
1852
|
+
if (!server || closePromise) return closePromise ?? Promise.resolve();
|
|
1853
|
+
closePromise = closeServer(server, force);
|
|
1854
|
+
return closePromise;
|
|
1855
|
+
};
|
|
1856
|
+
const onSigint = () => {
|
|
1857
|
+
cancelController.abort();
|
|
1858
|
+
void closeListener(true).catch((error2) => {
|
|
1859
|
+
closeFailureLogged = true;
|
|
1860
|
+
console.error(
|
|
1861
|
+
`[mcp authorize] listener shutdown failed for proxy_id=${JSON.stringify(proxyId)} connection_id=${JSON.stringify(connectionId)}: ${error2 instanceof Error ? error2.message : String(error2)}`
|
|
1862
|
+
);
|
|
1863
|
+
});
|
|
1864
|
+
};
|
|
1865
|
+
try {
|
|
1866
|
+
const listener = await bindCallbackListener(waiter);
|
|
1867
|
+
server = listener.server;
|
|
1868
|
+
process.once("SIGINT", onSigint);
|
|
1869
|
+
if (listener.port !== MCP_LOOPBACK_REDIRECT_POLICY.preferred_port) {
|
|
1870
|
+
const notice = `Port ${MCP_LOOPBACK_REDIRECT_POLICY.preferred_port} is busy; using an ephemeral local port.`;
|
|
1871
|
+
if (options.json)
|
|
1872
|
+
console.error(JSON.stringify({ event: "listener_fallback", message: notice }));
|
|
1873
|
+
else printWarning(notice);
|
|
1874
|
+
}
|
|
1875
|
+
const connectionList = await requestJson(
|
|
1876
|
+
apiPath(proxyId),
|
|
1877
|
+
credentials2,
|
|
1878
|
+
cancelController.signal,
|
|
1879
|
+
"checking the MCP connection"
|
|
1880
|
+
);
|
|
1881
|
+
const connection = validateConnectionList(connectionList).find(
|
|
1882
|
+
(candidate) => candidate.connection_id === connectionId
|
|
1883
|
+
);
|
|
1884
|
+
if (!connection)
|
|
1885
|
+
throw new Error("The MCP connection was not found. Check the connection ID and try again.");
|
|
1886
|
+
if (connection.authorization_mode !== "local") {
|
|
1887
|
+
throw new Error("This connection uses hosted sign-in. Authorize it from Evident instead.");
|
|
1888
|
+
}
|
|
1889
|
+
if (connection.auth_kind !== "oauth2") {
|
|
1890
|
+
throw new Error("This MCP connection does not support OAuth authorization.");
|
|
1891
|
+
}
|
|
1892
|
+
const redirectUri = `${MCP_LOOPBACK_REDIRECT_POLICY.scheme}://${MCP_LOOPBACK_REDIRECT_POLICY.host}:${listener.port}${MCP_LOOPBACK_REDIRECT_POLICY.path}`;
|
|
1893
|
+
const begin = await requestJson(
|
|
1894
|
+
apiPath(proxyId, connectionId, "begin"),
|
|
1895
|
+
credentials2,
|
|
1896
|
+
cancelController.signal,
|
|
1897
|
+
"starting local authorization",
|
|
1898
|
+
{ redirect_uri: redirectUri }
|
|
1899
|
+
);
|
|
1900
|
+
validateBeginResponse(begin);
|
|
1901
|
+
const { url: authorizationUrl, state } = authorizationState(begin.authorization_url);
|
|
1902
|
+
waiter.expectedState = state;
|
|
1903
|
+
const expiresAtMs = Date.parse(begin.expires_at);
|
|
1904
|
+
if (expiresAtMs <= Date.now()) throw new CallbackExpiredError();
|
|
1905
|
+
waiter.expiresAtMs = expiresAtMs;
|
|
1906
|
+
const callbackOutcome = waitForCallback(waiter, expiresAtMs, cancelController.signal).then(
|
|
1907
|
+
(callback2) => ({ ok: true, callback: callback2 }),
|
|
1908
|
+
(error2) => ({ ok: false, error: error2 })
|
|
1909
|
+
);
|
|
1910
|
+
let callback;
|
|
1911
|
+
if (options.noBrowser) {
|
|
1912
|
+
printLink(options, authorizationUrl);
|
|
1913
|
+
const outcome = await callbackOutcome;
|
|
1914
|
+
if (!outcome.ok) requestFailed(outcome.error);
|
|
1915
|
+
callback = outcome.callback;
|
|
1916
|
+
} else {
|
|
1917
|
+
const browserOutcome = open2(authorizationUrl.href).then(
|
|
1918
|
+
() => ({ ok: true }),
|
|
1919
|
+
(error2) => ({ ok: false, error: error2 })
|
|
1920
|
+
);
|
|
1921
|
+
const first = await Promise.race([
|
|
1922
|
+
browserOutcome.then((outcome) => ({ kind: "browser", outcome })),
|
|
1923
|
+
callbackOutcome.then((outcome) => ({ kind: "callback", outcome }))
|
|
1924
|
+
]);
|
|
1925
|
+
if (first.kind === "callback") {
|
|
1926
|
+
if (!first.outcome.ok) requestFailed(first.outcome.error);
|
|
1927
|
+
callback = first.outcome.callback;
|
|
1928
|
+
} else {
|
|
1929
|
+
if (!first.outcome.ok) {
|
|
1930
|
+
const detail = first.outcome.error instanceof Error ? ` (${first.outcome.error.message})` : "";
|
|
1931
|
+
printLink(
|
|
1932
|
+
options,
|
|
1933
|
+
authorizationUrl,
|
|
1934
|
+
`Could not open the browser automatically${detail}. Open this URL:`
|
|
1935
|
+
);
|
|
1936
|
+
}
|
|
1937
|
+
const outcome = await callbackOutcome;
|
|
1938
|
+
if (!outcome.ok) requestFailed(outcome.error);
|
|
1939
|
+
callback = outcome.callback;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
const completionBody = {
|
|
1943
|
+
state: callback.state,
|
|
1944
|
+
...callback.code === void 0 ? {} : { code: callback.code },
|
|
1945
|
+
...callback.error === void 0 ? {} : { error: callback.error },
|
|
1946
|
+
...callback.error_description === void 0 ? {} : { error_description: callback.error_description }
|
|
1947
|
+
};
|
|
1948
|
+
const completion = await requestJson(
|
|
1949
|
+
apiPath(proxyId, connectionId, "complete"),
|
|
1950
|
+
credentials2,
|
|
1951
|
+
cancelController.signal,
|
|
1952
|
+
"completing local authorization",
|
|
1953
|
+
completionBody
|
|
1954
|
+
);
|
|
1955
|
+
if (completion.outcome !== "success") failure = completionFailureMessage(completion.reason);
|
|
1956
|
+
} catch (error2) {
|
|
1957
|
+
failure = errorMessage(error2);
|
|
1958
|
+
} finally {
|
|
1959
|
+
process.removeListener("SIGINT", onSigint);
|
|
1960
|
+
try {
|
|
1961
|
+
await closeListener();
|
|
1962
|
+
} catch (error2) {
|
|
1963
|
+
const detail = error2 instanceof Error ? error2.message : String(error2);
|
|
1964
|
+
if (!closeFailureLogged) {
|
|
1965
|
+
console.error(
|
|
1966
|
+
`[mcp authorize] listener teardown failed for proxy_id=${JSON.stringify(proxyId)} connection_id=${JSON.stringify(connectionId)}: ${detail}`
|
|
1967
|
+
);
|
|
1968
|
+
}
|
|
1969
|
+
failure ??= "The local callback listener could not be closed cleanly. Check for a lingering process and retry.";
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
printResult(options, proxyId, connectionId, failure);
|
|
1973
|
+
if (failure) process.exitCode = cancelController.signal.aborted ? 130 : 1;
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1480
1976
|
// src/commands/run.ts
|
|
1977
|
+
import { chmodSync as chmodSync3, existsSync as existsSync3, readFileSync as readFileSync12, writeFileSync as writeFileSync9 } from "node:fs";
|
|
1978
|
+
import { homedir as homedir9 } from "node:os";
|
|
1979
|
+
import { isAbsolute as isAbsolute6, join as join17, parse, resolve as resolvePath2 } from "node:path";
|
|
1980
|
+
import chalk7 from "chalk";
|
|
1481
1981
|
import ora4 from "ora";
|
|
1482
1982
|
import { select as select4 } from "@inquirer/prompts";
|
|
1483
1983
|
|
|
1484
1984
|
// src/lib/telemetry.ts
|
|
1485
|
-
var CLI_VERSION = (true ? "3.6.1-dev.
|
|
1985
|
+
var CLI_VERSION = (true ? "3.6.1-dev.57b3e59" : void 0) ?? process.env.npm_package_version ?? "unknown";
|
|
1486
1986
|
function getCliVersion() {
|
|
1487
1987
|
return CLI_VERSION;
|
|
1488
1988
|
}
|
|
@@ -1679,7 +2179,7 @@ var SESSION_DB_RECLAIM_CHUNK_PAGES = 100;
|
|
|
1679
2179
|
var SESSION_DB_RECLAIM_TIME_BUDGET_MS = 500;
|
|
1680
2180
|
var SESSION_DB_RECLAIM_PAGE_CEILING = 4e4;
|
|
1681
2181
|
var SESSION_DB_RECLAIM_BUSY_TIMEOUT_MS = 5e3;
|
|
1682
|
-
function
|
|
2182
|
+
function errorMessage2(error2) {
|
|
1683
2183
|
if (!(error2 instanceof Error)) return String(error2);
|
|
1684
2184
|
return error2.cause instanceof Error ? error2.cause.message : error2.message;
|
|
1685
2185
|
}
|
|
@@ -1813,7 +2313,7 @@ async function probeReclaimAvailability(input) {
|
|
|
1813
2313
|
try {
|
|
1814
2314
|
sqlite = await import("node:sqlite");
|
|
1815
2315
|
} catch (err) {
|
|
1816
|
-
const detail = `Node ${process.version}: ${
|
|
2316
|
+
const detail = `Node ${process.version}: ${errorMessage2(err)}`;
|
|
1817
2317
|
console.warn(`[probeReclaimAvailability] node:sqlite unavailable for ${dbPath}: ` + detail);
|
|
1818
2318
|
return { reason: "sqlite-unavailable", detail };
|
|
1819
2319
|
}
|
|
@@ -1848,7 +2348,7 @@ async function reclaimSessionDbSpace(input) {
|
|
|
1848
2348
|
try {
|
|
1849
2349
|
sqlite = await import("node:sqlite");
|
|
1850
2350
|
} catch (err) {
|
|
1851
|
-
const detail = `Node ${process.version}: ${
|
|
2351
|
+
const detail = `Node ${process.version}: ${errorMessage2(err)}`;
|
|
1852
2352
|
console.warn(
|
|
1853
2353
|
`[reclaimSessionDbSpace] node:sqlite unavailable (need Node >=22.5, >=22.13 unflagged) for ${dbPath}: ${detail}`
|
|
1854
2354
|
);
|
|
@@ -1959,11 +2459,11 @@ async function reclaimSessionDbSpace(input) {
|
|
|
1959
2459
|
);
|
|
1960
2460
|
return { ok: false, skipped: "auto-vacuum-not-applicable" };
|
|
1961
2461
|
} catch (err) {
|
|
1962
|
-
console.error(`[reclaimSessionDbSpace] reclaim failed for ${dbPath}: ` +
|
|
2462
|
+
console.error(`[reclaimSessionDbSpace] reclaim failed for ${dbPath}: ` + errorMessage2(err));
|
|
1963
2463
|
return {
|
|
1964
2464
|
ok: false,
|
|
1965
2465
|
skipped: isSessionStoreWriteFailure(err) ? "disk-exhaustion" : "reclaim-error",
|
|
1966
|
-
detail:
|
|
2466
|
+
detail: errorMessage2(err)
|
|
1967
2467
|
};
|
|
1968
2468
|
} finally {
|
|
1969
2469
|
db?.close();
|
|
@@ -3115,7 +3615,7 @@ function buildSessionArchive(input) {
|
|
|
3115
3615
|
function isRecord2(value) {
|
|
3116
3616
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3117
3617
|
}
|
|
3118
|
-
function
|
|
3618
|
+
function errorMessage3(error2) {
|
|
3119
3619
|
return error2 instanceof Error ? error2.message : String(error2);
|
|
3120
3620
|
}
|
|
3121
3621
|
function invalidResponse(version2, sessionId, path, reason) {
|
|
@@ -3133,7 +3633,7 @@ async function requestPage(client, sessionId, path, signal) {
|
|
|
3133
3633
|
} catch (error2) {
|
|
3134
3634
|
throw new SessionArchiveExportError(
|
|
3135
3635
|
"request-failed",
|
|
3136
|
-
`OpenCode ${client.version} session ${sessionId} request GET ${path} failed: ${
|
|
3636
|
+
`OpenCode ${client.version} session ${sessionId} request GET ${path} failed: ${errorMessage3(error2)}`
|
|
3137
3637
|
);
|
|
3138
3638
|
}
|
|
3139
3639
|
if (response.status === 404) {
|
|
@@ -3154,7 +3654,7 @@ async function requestPage(client, sessionId, path, signal) {
|
|
|
3154
3654
|
} catch (error2) {
|
|
3155
3655
|
throw new SessionArchiveExportError(
|
|
3156
3656
|
"request-failed",
|
|
3157
|
-
`OpenCode ${client.version} session ${sessionId} response body from GET ${path} could not be read: ${
|
|
3657
|
+
`OpenCode ${client.version} session ${sessionId} response body from GET ${path} could not be read: ${errorMessage3(error2)}`
|
|
3158
3658
|
);
|
|
3159
3659
|
}
|
|
3160
3660
|
try {
|
|
@@ -3189,7 +3689,7 @@ function v1NextCursor(response, sessionId, path) {
|
|
|
3189
3689
|
} catch (error2) {
|
|
3190
3690
|
throw new SessionArchiveExportError(
|
|
3191
3691
|
"pagination-failed",
|
|
3192
|
-
`OpenCode v1 session ${sessionId} returned an invalid next Link for GET ${path}: ${
|
|
3692
|
+
`OpenCode v1 session ${sessionId} returned an invalid next Link for GET ${path}: ${errorMessage3(error2)}`
|
|
3193
3693
|
);
|
|
3194
3694
|
}
|
|
3195
3695
|
}
|
|
@@ -5713,8 +6213,8 @@ function classifyReplyAuthError(reply) {
|
|
|
5713
6213
|
};
|
|
5714
6214
|
}
|
|
5715
6215
|
}
|
|
5716
|
-
const
|
|
5717
|
-
if (
|
|
6216
|
+
const errorMessage5 = typeof data?.message === "string" ? data.message : typeof e.message === "string" ? e.message : null;
|
|
6217
|
+
if (errorMessage5 !== null && CLAUDE_AUTH_EXPIRY_MESSAGES.some((knownMessage) => errorMessage5.includes(knownMessage))) {
|
|
5718
6218
|
return {
|
|
5719
6219
|
kind: "model_auth",
|
|
5720
6220
|
providerId: typeof data?.providerID === "string" && data.providerID || replyProviderId,
|
|
@@ -5769,7 +6269,7 @@ function hasRunningAssistantExcept(messages, exceptUserMessageId) {
|
|
|
5769
6269
|
(m) => roleOf2(m) === "assistant" && parentIdOf2(m) !== exceptUserMessageId && isAssistantInFlight(m)
|
|
5770
6270
|
);
|
|
5771
6271
|
}
|
|
5772
|
-
function hasLaterSiblingTurnStarted(messages, userMessageId, siblingUserMessageIds) {
|
|
6272
|
+
function hasLaterSiblingTurnStarted(messages, userMessageId, siblingUserMessageIds, apiVersion) {
|
|
5773
6273
|
if (!messages || messages.length === 0) return false;
|
|
5774
6274
|
const userIndex = messages.findIndex((message) => idOf2(message) === userMessageId);
|
|
5775
6275
|
if (userIndex === -1) return false;
|
|
@@ -5783,7 +6283,7 @@ function hasLaterSiblingTurnStarted(messages, userMessageId, siblingUserMessageI
|
|
|
5783
6283
|
if (laterUserMessageId === void 0 || !siblingUserMessageIds.has(laterUserMessageId)) {
|
|
5784
6284
|
return false;
|
|
5785
6285
|
}
|
|
5786
|
-
if (messages.some(
|
|
6286
|
+
if (apiVersion === "v2" || messages.some(
|
|
5787
6287
|
(candidate) => roleOf2(candidate) === "assistant" && parentIdOf2(candidate) === laterUserMessageId
|
|
5788
6288
|
)) {
|
|
5789
6289
|
hasStartedLaterUser = true;
|
|
@@ -7671,7 +8171,7 @@ function buildSessionStoreSizeWarning(input) {
|
|
|
7671
8171
|
import { statSync as statSync5 } from "node:fs";
|
|
7672
8172
|
import { homedir as homedir5 } from "node:os";
|
|
7673
8173
|
import { join as join11 } from "node:path";
|
|
7674
|
-
import { open as
|
|
8174
|
+
import { open as open3, stat } from "node:fs/promises";
|
|
7675
8175
|
var DEFAULT_POLL_INTERVAL_MS = 1e3;
|
|
7676
8176
|
function resolveOpenCodeLogPath(homeDir = homedir5(), env = process.env) {
|
|
7677
8177
|
const dataDir = env.XDG_DATA_HOME || join11(homeDir, ".local", "share");
|
|
@@ -7725,7 +8225,7 @@ function tailOpenCodeLogFile(logPath, onChunk, opts = {}) {
|
|
|
7725
8225
|
inode = current.ino;
|
|
7726
8226
|
if (current.size === offset) return;
|
|
7727
8227
|
const length = current.size - offset;
|
|
7728
|
-
const fh = await
|
|
8228
|
+
const fh = await open3(logPath, "r");
|
|
7729
8229
|
try {
|
|
7730
8230
|
const buf = Buffer.alloc(length);
|
|
7731
8231
|
const { bytesRead } = await fh.read(buf, 0, length, offset);
|
|
@@ -7758,7 +8258,7 @@ import WebSocket from "ws";
|
|
|
7758
8258
|
|
|
7759
8259
|
// src/lib/file-read.ts
|
|
7760
8260
|
import { constants } from "node:fs";
|
|
7761
|
-
import { open as
|
|
8261
|
+
import { open as open4, realpath as realpath2, stat as stat2 } from "node:fs/promises";
|
|
7762
8262
|
import { extname, isAbsolute as isAbsolute3, resolve as resolve4 } from "node:path";
|
|
7763
8263
|
import { homedir as homedir6 } from "node:os";
|
|
7764
8264
|
|
|
@@ -7808,7 +8308,7 @@ var FILE_MIME_TYPES = {
|
|
|
7808
8308
|
".mp4": "video/mp4",
|
|
7809
8309
|
".mov": "video/quicktime"
|
|
7810
8310
|
};
|
|
7811
|
-
async function readProjectFile(projectRoot, method, requestedPath, openFile =
|
|
8311
|
+
async function readProjectFile(projectRoot, method, requestedPath, openFile = open4) {
|
|
7812
8312
|
if (method !== "GET") return refuse(405, "method_not_allowed");
|
|
7813
8313
|
if (!projectRoot || !isAbsolute3(projectRoot)) return refuse(503, "project_root_unavailable");
|
|
7814
8314
|
if (!requestedPath || requestedPath.length > 4096 || requestedPath.includes("\0")) {
|
|
@@ -8381,8 +8881,8 @@ function connectTunnel(options) {
|
|
|
8381
8881
|
}
|
|
8382
8882
|
forwarder.handleBinaryBodyFrame(frame.sid, frame.payload);
|
|
8383
8883
|
} catch (error2) {
|
|
8384
|
-
const
|
|
8385
|
-
onError?.(`Failed to handle binary message: ${
|
|
8884
|
+
const errorMessage5 = error2 instanceof Error ? error2.message : "Unknown error";
|
|
8885
|
+
onError?.(`Failed to handle binary message: ${errorMessage5}`);
|
|
8386
8886
|
}
|
|
8387
8887
|
return;
|
|
8388
8888
|
}
|
|
@@ -8390,8 +8890,8 @@ function connectTunnel(options) {
|
|
|
8390
8890
|
try {
|
|
8391
8891
|
message = JSON.parse(data.toString());
|
|
8392
8892
|
} catch (error2) {
|
|
8393
|
-
const
|
|
8394
|
-
onError?.(`Failed to handle message: ${
|
|
8893
|
+
const errorMessage5 = error2 instanceof Error ? error2.message : "Unknown error";
|
|
8894
|
+
onError?.(`Failed to handle message: ${errorMessage5}`);
|
|
8395
8895
|
return;
|
|
8396
8896
|
}
|
|
8397
8897
|
if (isStreamFrame(message)) {
|
|
@@ -8970,7 +9470,7 @@ import { join as join14 } from "node:path";
|
|
|
8970
9470
|
|
|
8971
9471
|
// src/lib/file-push.ts
|
|
8972
9472
|
import { randomUUID } from "node:crypto";
|
|
8973
|
-
import { chmod, mkdir, open as
|
|
9473
|
+
import { chmod, mkdir, open as open5, realpath as realpath3, rename, unlink } from "node:fs/promises";
|
|
8974
9474
|
import { basename as basename3, dirname as dirname10, isAbsolute as isAbsolute4, join as join13 } from "node:path";
|
|
8975
9475
|
var FILE_MODE = 384;
|
|
8976
9476
|
var DIRECTORY_MODE = 448;
|
|
@@ -9103,7 +9603,7 @@ async function writeAtomically(realTarget, content) {
|
|
|
9103
9603
|
const temporaryPath = join13(dirname10(realTarget), `.evident-push-${randomUUID()}.tmp`);
|
|
9104
9604
|
let handle;
|
|
9105
9605
|
try {
|
|
9106
|
-
handle = await
|
|
9606
|
+
handle = await open5(temporaryPath, "wx", FILE_MODE);
|
|
9107
9607
|
await handle.writeFile(content);
|
|
9108
9608
|
await handle.chmod(FILE_MODE);
|
|
9109
9609
|
await handle.close();
|
|
@@ -10304,12 +10804,12 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
10304
10804
|
this.sessions.delete(conversationId);
|
|
10305
10805
|
this.supersede(conversationId, sessionId);
|
|
10306
10806
|
const dispatchDescription = source === "readopt" ? "re-dispatched message" : "message";
|
|
10307
|
-
const
|
|
10308
|
-
this.untrackableAck.set(messageId,
|
|
10807
|
+
const errorMessage5 = `OpenCode accepted this ${dispatchDescription} once, but its assigned id was never confirmed after ${attempts} attempts to match it up \u2014 the message was deliberately not sent again, so no duplicate turn was created; session ${sessionId.slice(0, 8)} was abandoned; a fresh one is used for further messages.`;
|
|
10808
|
+
this.untrackableAck.set(messageId, errorMessage5);
|
|
10309
10809
|
this.untrackableAckSessionIds.set(messageId, null);
|
|
10310
10810
|
this.log({
|
|
10311
10811
|
level: "error",
|
|
10312
|
-
message:
|
|
10812
|
+
message: errorMessage5,
|
|
10313
10813
|
conversation_id: conversationId,
|
|
10314
10814
|
message_id: messageId
|
|
10315
10815
|
});
|
|
@@ -10317,7 +10817,7 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
10317
10817
|
conversationId,
|
|
10318
10818
|
messageId,
|
|
10319
10819
|
null,
|
|
10320
|
-
|
|
10820
|
+
errorMessage5
|
|
10321
10821
|
);
|
|
10322
10822
|
if (reportError !== null) {
|
|
10323
10823
|
this.log({
|
|
@@ -10498,12 +10998,12 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
10498
10998
|
conversation_id: conv.id,
|
|
10499
10999
|
message_id: message.id
|
|
10500
11000
|
});
|
|
10501
|
-
const
|
|
11001
|
+
const errorMessage5 = this.untrackableAck.get(message.id);
|
|
10502
11002
|
const reportError = await this.reportUntrackableAck(
|
|
10503
11003
|
conv.id,
|
|
10504
11004
|
message.id,
|
|
10505
11005
|
null,
|
|
10506
|
-
|
|
11006
|
+
errorMessage5
|
|
10507
11007
|
);
|
|
10508
11008
|
if (reportError === null) {
|
|
10509
11009
|
continue;
|
|
@@ -10591,7 +11091,7 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
10591
11091
|
const hasProviderAndModel = dispatchedModel !== null && separator > 0 && separator < dispatchedModel.length - 1;
|
|
10592
11092
|
const providerId = hasProviderAndModel ? dispatchedModel.slice(0, separator) : null;
|
|
10593
11093
|
const modelId = hasProviderAndModel ? dispatchedModel.slice(separator + 1) : null;
|
|
10594
|
-
const
|
|
11094
|
+
const errorMessage5 = `Provider namespace not loaded on this runner: ${message.opencode_model}. Refused before dispatch; no turn was started.`;
|
|
10595
11095
|
this.log({
|
|
10596
11096
|
level: "error",
|
|
10597
11097
|
message: `Refusing message ${message.id.slice(0, 8)} in conversation ${conv.id.slice(0, 8)}: provider namespace ${providerId ?? "(unknown)"} is not loaded; no turn was started`,
|
|
@@ -10599,7 +11099,7 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
10599
11099
|
message_id: message.id
|
|
10600
11100
|
});
|
|
10601
11101
|
try {
|
|
10602
|
-
await this.markFailed(conv.id, message.id, sessionId,
|
|
11102
|
+
await this.markFailed(conv.id, message.id, sessionId, errorMessage5, void 0, {
|
|
10603
11103
|
classification: {
|
|
10604
11104
|
kind: "model_auth",
|
|
10605
11105
|
providerId,
|
|
@@ -10677,12 +11177,12 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
10677
11177
|
} catch (err) {
|
|
10678
11178
|
if (err instanceof ChannelAuthError) throw err;
|
|
10679
11179
|
if (this.isV2 && err instanceof OpenCodeV2PromptAckError) {
|
|
10680
|
-
const
|
|
10681
|
-
this.untrackableAck.set(message.id,
|
|
11180
|
+
const errorMessage6 = err instanceof Error ? err.message : String(err);
|
|
11181
|
+
this.untrackableAck.set(message.id, errorMessage6);
|
|
10682
11182
|
this.untrackableAckSessionIds.set(message.id, null);
|
|
10683
11183
|
this.log({
|
|
10684
11184
|
level: "error",
|
|
10685
|
-
message: `V2 prompt dispatch for message ${message.id.slice(0, 8)} failed after a positive ack with no usable id: ${
|
|
11185
|
+
message: `V2 prompt dispatch for message ${message.id.slice(0, 8)} failed after a positive ack with no usable id: ${errorMessage6}`,
|
|
10686
11186
|
conversation_id: conv.id,
|
|
10687
11187
|
message_id: message.id
|
|
10688
11188
|
});
|
|
@@ -10690,7 +11190,7 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
10690
11190
|
conv.id,
|
|
10691
11191
|
message.id,
|
|
10692
11192
|
null,
|
|
10693
|
-
|
|
11193
|
+
errorMessage6
|
|
10694
11194
|
);
|
|
10695
11195
|
if (markError !== null) {
|
|
10696
11196
|
this.log({
|
|
@@ -10729,7 +11229,7 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
10729
11229
|
await this.failV2ModelSwitch(conv, message, sessionId, err);
|
|
10730
11230
|
break;
|
|
10731
11231
|
}
|
|
10732
|
-
const
|
|
11232
|
+
const errorMessage5 = err instanceof Error ? err.message : String(err);
|
|
10733
11233
|
this.sessions.delete(conv.id);
|
|
10734
11234
|
this.supersede(conv.id, sessionId);
|
|
10735
11235
|
this.log({
|
|
@@ -10738,7 +11238,7 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
10738
11238
|
conversation_id: conv.id,
|
|
10739
11239
|
message_id: message.id
|
|
10740
11240
|
});
|
|
10741
|
-
await this.markFailed(conv.id, message.id, null,
|
|
11241
|
+
await this.markFailed(conv.id, message.id, null, errorMessage5).catch((markErr) => {
|
|
10742
11242
|
this.log({
|
|
10743
11243
|
level: "warn",
|
|
10744
11244
|
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)}`,
|
|
@@ -10749,7 +11249,7 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
10749
11249
|
});
|
|
10750
11250
|
this.log({
|
|
10751
11251
|
level: "error",
|
|
10752
|
-
message: `Message ${message.id.slice(0, 8)} dispatch failed: ${
|
|
11252
|
+
message: `Message ${message.id.slice(0, 8)} dispatch failed: ${errorMessage5}`,
|
|
10753
11253
|
conversation_id: conv.id,
|
|
10754
11254
|
message_id: message.id
|
|
10755
11255
|
});
|
|
@@ -11034,7 +11534,12 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
11034
11534
|
this.watchers.get(sessionId),
|
|
11035
11535
|
message.id
|
|
11036
11536
|
);
|
|
11037
|
-
if (hasLaterSiblingTurnStarted(
|
|
11537
|
+
if (hasLaterSiblingTurnStarted(
|
|
11538
|
+
messages,
|
|
11539
|
+
ocId ?? "",
|
|
11540
|
+
siblingOcIds,
|
|
11541
|
+
this.openCodeClient.version
|
|
11542
|
+
)) {
|
|
11038
11543
|
this.log({
|
|
11039
11544
|
level: "warn",
|
|
11040
11545
|
message: `Re-drive: OpenCode already served a later, different Evident message's turn in session ${sessionId.slice(0, 8)} while message ${message.id.slice(0, 8)} produced no reply \u2014 re-dispatching instead of reattaching to someone else's turn`,
|
|
@@ -12673,7 +13178,12 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
12673
13178
|
return;
|
|
12674
13179
|
}
|
|
12675
13180
|
const siblingOcIds = this.siblingOpencodeMessageIds(watcher, inFlight.evidentMessageId);
|
|
12676
|
-
const skippedByOpencode = state === "queued" && hasLaterSiblingTurnStarted(
|
|
13181
|
+
const skippedByOpencode = state === "queued" && hasLaterSiblingTurnStarted(
|
|
13182
|
+
messages,
|
|
13183
|
+
inFlight.opencodeMessageId,
|
|
13184
|
+
siblingOcIds,
|
|
13185
|
+
this.openCodeClient.version
|
|
13186
|
+
);
|
|
12677
13187
|
const pastStuckBound = this.now() - inFlight.dispatchedAt >= this.stuckQueuedMs;
|
|
12678
13188
|
const sessionIdle = state === "queued" && !hasRunningAssistantExcept(messages, inFlight.opencodeMessageId);
|
|
12679
13189
|
if (state === "queued" && pastStuckBound && (sessionIdle || skippedByOpencode) && !inFlight.stuckReported) {
|
|
@@ -13684,12 +14194,12 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
13684
14194
|
conversation_id: row.conversation_id,
|
|
13685
14195
|
message_id: row.id
|
|
13686
14196
|
});
|
|
13687
|
-
const
|
|
14197
|
+
const errorMessage5 = this.untrackableAck.get(row.id);
|
|
13688
14198
|
const reportError = await this.reportUntrackableAck(
|
|
13689
14199
|
row.conversation_id,
|
|
13690
14200
|
row.id,
|
|
13691
14201
|
this.untrackableAckSessionIds.get(row.id) ?? null,
|
|
13692
|
-
|
|
14202
|
+
errorMessage5
|
|
13693
14203
|
);
|
|
13694
14204
|
if (reportError !== null) {
|
|
13695
14205
|
this.log({
|
|
@@ -14008,14 +14518,14 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
14008
14518
|
this.awaitingReadopt.delete(row.id);
|
|
14009
14519
|
if (err instanceof ChannelAuthError) throw err;
|
|
14010
14520
|
if (this.isV2) {
|
|
14011
|
-
const
|
|
14521
|
+
const errorMessage5 = err instanceof Error ? err.message : String(err);
|
|
14012
14522
|
const invalidPromptAck = err instanceof OpenCodeV2PromptAckError;
|
|
14013
14523
|
if (!invalidPromptAck) {
|
|
14014
14524
|
const exists = await this.sessionExists(sessionId);
|
|
14015
14525
|
if (exists === false) {
|
|
14016
14526
|
this.log({
|
|
14017
14527
|
level: "warn",
|
|
14018
|
-
message: `Re-adopt: message ${row.id.slice(0, 8)} dispatch hit a session (${sessionId.slice(0, 8)}) that was deleted mid-dispatch \u2014 deferring to the next drain: ${
|
|
14528
|
+
message: `Re-adopt: message ${row.id.slice(0, 8)} dispatch hit a session (${sessionId.slice(0, 8)}) that was deleted mid-dispatch \u2014 deferring to the next drain: ${errorMessage5}`,
|
|
14019
14529
|
conversation_id: row.conversation_id,
|
|
14020
14530
|
message_id: row.id
|
|
14021
14531
|
});
|
|
@@ -14025,7 +14535,7 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
14025
14535
|
if (exists === null) {
|
|
14026
14536
|
this.log({
|
|
14027
14537
|
level: "warn",
|
|
14028
|
-
message: `Re-adopt: message ${row.id.slice(0, 8)} dispatch failed and session (${sessionId.slice(0, 8)}) existence could not be confirmed \u2014 deferring to the next drain: ${
|
|
14538
|
+
message: `Re-adopt: message ${row.id.slice(0, 8)} dispatch failed and session (${sessionId.slice(0, 8)}) existence could not be confirmed \u2014 deferring to the next drain: ${errorMessage5}`,
|
|
14029
14539
|
conversation_id: row.conversation_id,
|
|
14030
14540
|
message_id: row.id
|
|
14031
14541
|
});
|
|
@@ -14033,7 +14543,7 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
14033
14543
|
return;
|
|
14034
14544
|
}
|
|
14035
14545
|
} else {
|
|
14036
|
-
this.untrackableAck.set(row.id,
|
|
14546
|
+
this.untrackableAck.set(row.id, errorMessage5);
|
|
14037
14547
|
this.untrackableAckSessionIds.set(row.id, sessionId);
|
|
14038
14548
|
}
|
|
14039
14549
|
if (err instanceof OpenCodeV2ModelSwitchError) {
|
|
@@ -14042,7 +14552,7 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
14042
14552
|
}
|
|
14043
14553
|
this.log({
|
|
14044
14554
|
level: "error",
|
|
14045
|
-
message: `V2 re-adopt dispatch for message ${row.id.slice(0, 8)} failed: ${
|
|
14555
|
+
message: `V2 re-adopt dispatch for message ${row.id.slice(0, 8)} failed: ${errorMessage5}`,
|
|
14046
14556
|
conversation_id: row.conversation_id,
|
|
14047
14557
|
message_id: row.id
|
|
14048
14558
|
});
|
|
@@ -14051,7 +14561,7 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
14051
14561
|
row.conversation_id,
|
|
14052
14562
|
row.id,
|
|
14053
14563
|
sessionId,
|
|
14054
|
-
|
|
14564
|
+
errorMessage5
|
|
14055
14565
|
);
|
|
14056
14566
|
if (markError !== null) {
|
|
14057
14567
|
this.log({
|
|
@@ -14062,7 +14572,7 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
14062
14572
|
});
|
|
14063
14573
|
}
|
|
14064
14574
|
} else {
|
|
14065
|
-
await this.markFailed(row.conversation_id, row.id, sessionId,
|
|
14575
|
+
await this.markFailed(row.conversation_id, row.id, sessionId, errorMessage5).catch(
|
|
14066
14576
|
(markErr) => {
|
|
14067
14577
|
this.log({
|
|
14068
14578
|
level: "warn",
|
|
@@ -15046,9 +15556,9 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
15046
15556
|
* trackable. Callers use the returned error to keep their path-specific logging
|
|
15047
15557
|
* while the same report payload can be retried on a later drain.
|
|
15048
15558
|
*/
|
|
15049
|
-
async reportUntrackableAck(conversationId, messageId, sessionId,
|
|
15559
|
+
async reportUntrackableAck(conversationId, messageId, sessionId, errorMessage5) {
|
|
15050
15560
|
try {
|
|
15051
|
-
await this.markFailed(conversationId, messageId, sessionId,
|
|
15561
|
+
await this.markFailed(conversationId, messageId, sessionId, errorMessage5);
|
|
15052
15562
|
return null;
|
|
15053
15563
|
} catch (err) {
|
|
15054
15564
|
this.signalUntrackableAck(conversationId, messageId);
|
|
@@ -16212,7 +16722,7 @@ var MAX_FLUSH_PASSES = 2;
|
|
|
16212
16722
|
function outcomesWith(outcome) {
|
|
16213
16723
|
return { claude: outcome, opencode: outcome };
|
|
16214
16724
|
}
|
|
16215
|
-
function
|
|
16725
|
+
function errorMessage4(error2) {
|
|
16216
16726
|
return error2 instanceof Error ? error2.message : String(error2);
|
|
16217
16727
|
}
|
|
16218
16728
|
function waitForSettlement(promise, timeoutMs) {
|
|
@@ -16239,7 +16749,7 @@ function writeMarker(markerPath, outcomes, log3) {
|
|
|
16239
16749
|
writeFileSync8(temporaryPath, body, { mode: 384 });
|
|
16240
16750
|
renameSync(temporaryPath, markerPath);
|
|
16241
16751
|
} catch (error2) {
|
|
16242
|
-
log3(`CREDENTIAL-FLUSH-MARKER-UNWRITABLE: ${markerPath}: ${
|
|
16752
|
+
log3(`CREDENTIAL-FLUSH-MARKER-UNWRITABLE: ${markerPath}: ${errorMessage4(error2)}`, "warn");
|
|
16243
16753
|
}
|
|
16244
16754
|
}
|
|
16245
16755
|
function intervalSeconds(env, log3) {
|
|
@@ -16271,7 +16781,7 @@ async function runFlushStore(store, env, synchroniserRunner, log3, deadlineAt) {
|
|
|
16271
16781
|
},
|
|
16272
16782
|
(error2) => {
|
|
16273
16783
|
failed = true;
|
|
16274
|
-
log3(`CREDENTIAL-FLUSH-ERROR: ${store}: ${
|
|
16784
|
+
log3(`CREDENTIAL-FLUSH-ERROR: ${store}: ${errorMessage4(error2)}`, "warn");
|
|
16275
16785
|
}
|
|
16276
16786
|
);
|
|
16277
16787
|
const abortTimer = setTimeout(() => controller.abort(), remainingMs);
|
|
@@ -16331,7 +16841,7 @@ function createCredentialSync({
|
|
|
16331
16841
|
outcomes[store] = !result.timedOut && result.code === 0 ? "ok" : "failed";
|
|
16332
16842
|
} catch (error2) {
|
|
16333
16843
|
outcomes[store] = "failed";
|
|
16334
|
-
log3(`CREDENTIAL-SYNC-TICK-ERROR: ${store}: ${
|
|
16844
|
+
log3(`CREDENTIAL-SYNC-TICK-ERROR: ${store}: ${errorMessage4(error2)}`, "debug");
|
|
16335
16845
|
}
|
|
16336
16846
|
}
|
|
16337
16847
|
const failed = STORES.some((store) => outcomes[store] === "failed");
|
|
@@ -17336,8 +17846,8 @@ async function driveChannels(state, driver) {
|
|
|
17336
17846
|
state.running = false;
|
|
17337
17847
|
break;
|
|
17338
17848
|
}
|
|
17339
|
-
const
|
|
17340
|
-
logActivity(state, { type: "error", error: `Channel processing error: ${
|
|
17849
|
+
const errorMessage5 = error2 instanceof Error ? error2.message : String(error2);
|
|
17850
|
+
logActivity(state, { type: "error", error: `Channel processing error: ${errorMessage5}` });
|
|
17341
17851
|
if (state.interactive) displayStatus(state);
|
|
17342
17852
|
if (driver.hasInFlightWatchers()) {
|
|
17343
17853
|
consecutiveDrainFailures = 0;
|
|
@@ -19630,7 +20140,7 @@ program.name("evident").description("Run OpenCode locally and connect it to Evid
|
|
|
19630
20140
|
"--endpoint <url>",
|
|
19631
20141
|
"Evident API base URL (default: production; e.g. http://localhost:3001)"
|
|
19632
20142
|
).option("--tunnel <url>", "Tunnel WebSocket URL (default: production; e.g. ws://localhost:8787)").hook("preAction", (thisCommand) => {
|
|
19633
|
-
const { endpoint: endpoint2, tunnel } = thisCommand.
|
|
20143
|
+
const { endpoint: endpoint2, tunnel } = thisCommand.optsWithGlobals();
|
|
19634
20144
|
if (endpoint2) {
|
|
19635
20145
|
setEndpoint(endpoint2);
|
|
19636
20146
|
}
|
|
@@ -19641,6 +20151,12 @@ program.name("evident").description("Run OpenCode locally and connect it to Evid
|
|
|
19641
20151
|
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);
|
|
19642
20152
|
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 }));
|
|
19643
20153
|
program.command("whoami").description("Show the currently logged in user").action(whoami);
|
|
20154
|
+
program.command("mcp").description("Manage MCP proxy connections").command("authorize").description("Authorize an MCP proxy connection using your local browser").argument("<proxy-id>", "MCP proxy ID").argument("<connection-id>", "MCP connection ID").option("--no-browser", "Do not open the browser automatically").option("--json", "Output the result as JSON").action(
|
|
20155
|
+
(proxyId, connectionId, options) => authorizeMcpConnection(proxyId, connectionId, {
|
|
20156
|
+
noBrowser: options.browser === false,
|
|
20157
|
+
json: options.json
|
|
20158
|
+
})
|
|
20159
|
+
);
|
|
19644
20160
|
program.command("status").description("Check whether the configured credentials can reach Evident").option("--json", "Output in JSON format").action((options) => status({ json: options.json }));
|
|
19645
20161
|
program.command("credential-vault-env").description("Print the shell assignment a runner image evals before starting the synchroniser").action(credentialVaultEnv);
|
|
19646
20162
|
program.command("claude-usage").description("[spike] Show Claude subscription usage (requires a local `claude login`)").action(claudeUsage);
|