@evident-ai/cli 3.5.2-dev.4912967 → 3.5.2-dev.659ea21
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 +195 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { createRequire as createRequire2 } from "module";
|
|
5
4
|
import { Command } from "commander";
|
|
6
5
|
|
|
7
6
|
// src/commands/login.ts
|
|
@@ -1158,7 +1157,7 @@ import ora4 from "ora";
|
|
|
1158
1157
|
import { select as select4 } from "@inquirer/prompts";
|
|
1159
1158
|
|
|
1160
1159
|
// src/lib/telemetry.ts
|
|
1161
|
-
var CLI_VERSION = (true ? "3.5.2-dev.
|
|
1160
|
+
var CLI_VERSION = (true ? "3.5.2-dev.659ea21" : void 0) ?? process.env.npm_package_version ?? "unknown";
|
|
1162
1161
|
function getCliVersion() {
|
|
1163
1162
|
return CLI_VERSION;
|
|
1164
1163
|
}
|
|
@@ -1172,6 +1171,23 @@ var authProvider = null;
|
|
|
1172
1171
|
function setTelemetryAuthProvider(provider) {
|
|
1173
1172
|
authProvider = provider;
|
|
1174
1173
|
}
|
|
1174
|
+
var diagnosticsReporter = null;
|
|
1175
|
+
function setTelemetryDiagnosticsReporter(reporter) {
|
|
1176
|
+
diagnosticsReporter = reporter;
|
|
1177
|
+
}
|
|
1178
|
+
function reportTelemetryDiagnostic(message) {
|
|
1179
|
+
if (!diagnosticsReporter) {
|
|
1180
|
+
console.error(message);
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
try {
|
|
1184
|
+
diagnosticsReporter(message);
|
|
1185
|
+
} catch (error2) {
|
|
1186
|
+
console.error(
|
|
1187
|
+
`Telemetry diagnostics reporter failed: ${error2 instanceof Error ? error2.message : String(error2)}; original diagnostic: ${message}`
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1175
1191
|
var FLUSH_FAILURE_LOG_INTERVAL_MS = 6e4;
|
|
1176
1192
|
var lastFlushFailureLoggedAt = 0;
|
|
1177
1193
|
var suppressedFlushFailureCount = 0;
|
|
@@ -1237,7 +1253,9 @@ async function flushEvents() {
|
|
|
1237
1253
|
signal: controller.signal
|
|
1238
1254
|
});
|
|
1239
1255
|
if (!response.ok) {
|
|
1240
|
-
|
|
1256
|
+
reportTelemetryDiagnostic(
|
|
1257
|
+
`Telemetry could not send events (HTTP ${response.status}); runner and OpenCode are unaffected`
|
|
1258
|
+
);
|
|
1241
1259
|
}
|
|
1242
1260
|
} finally {
|
|
1243
1261
|
clearTimeout(timeout);
|
|
@@ -1247,7 +1265,9 @@ async function flushEvents() {
|
|
|
1247
1265
|
if (now - lastFlushFailureLoggedAt >= FLUSH_FAILURE_LOG_INTERVAL_MS) {
|
|
1248
1266
|
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
1249
1267
|
const suffix = suppressedFlushFailureCount > 0 ? ` (${suppressedFlushFailureCount} more suppressed in the last ${FLUSH_FAILURE_LOG_INTERVAL_MS / 1e3}s)` : "";
|
|
1250
|
-
|
|
1268
|
+
reportTelemetryDiagnostic(
|
|
1269
|
+
`Telemetry flush failed: ${message}; runner and OpenCode are unaffected${suffix}`
|
|
1270
|
+
);
|
|
1251
1271
|
lastFlushFailureLoggedAt = now;
|
|
1252
1272
|
suppressedFlushFailureCount = 0;
|
|
1253
1273
|
} else {
|
|
@@ -1317,25 +1337,72 @@ function parseOpenCodeLogLine(line) {
|
|
|
1317
1337
|
const level = levelMatch[1].toUpperCase();
|
|
1318
1338
|
if (level !== "WARN" && level !== "ERROR") return null;
|
|
1319
1339
|
const sessionMatch = normalisedLine.match(/(?:^|\s)sessionID=(\S+)/);
|
|
1320
|
-
|
|
1340
|
+
const messageMatch = normalisedLine.match(/(?:^|\s)message=(?:"((?:\\.|[^"])*)"|(\S+))/);
|
|
1341
|
+
const parsed = {
|
|
1342
|
+
level: level === "WARN" ? "warn" : "error",
|
|
1343
|
+
sessionID: sessionMatch?.[1]
|
|
1344
|
+
};
|
|
1345
|
+
const message = messageMatch?.[1] ?? messageMatch?.[2];
|
|
1346
|
+
if (message !== void 0) parsed.message = message;
|
|
1347
|
+
return parsed;
|
|
1321
1348
|
}
|
|
1322
1349
|
var MAX_LINE_BUFFER_BYTES = 16 * 1024;
|
|
1350
|
+
var REPEAT_SUPPRESSION_WINDOW_MS = 6e4;
|
|
1323
1351
|
function createOpenCodeActivityForwarder(getContext) {
|
|
1324
1352
|
let buffer = Buffer.alloc(0);
|
|
1325
|
-
const
|
|
1326
|
-
|
|
1327
|
-
|
|
1353
|
+
const repeatStates = /* @__PURE__ */ new Map();
|
|
1354
|
+
const forwardLine = (line, parsed, repeatsSuppressed = 0) => {
|
|
1355
|
+
const metadata = {
|
|
1356
|
+
...parsed.sessionID ? { sessionID: parsed.sessionID } : {},
|
|
1357
|
+
...repeatsSuppressed > 0 ? { repeats_suppressed: repeatsSuppressed } : {}
|
|
1358
|
+
};
|
|
1328
1359
|
forwardRunnerActivity(
|
|
1329
1360
|
{
|
|
1330
1361
|
level: parsed.level,
|
|
1331
1362
|
error: line,
|
|
1332
|
-
metadata:
|
|
1363
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : void 0,
|
|
1333
1364
|
source: "opencode"
|
|
1334
1365
|
},
|
|
1335
1366
|
getContext()
|
|
1336
1367
|
);
|
|
1337
1368
|
};
|
|
1338
|
-
|
|
1369
|
+
const expireRepeatStates = (now, currentKey) => {
|
|
1370
|
+
for (const [key, state] of repeatStates) {
|
|
1371
|
+
if (key === currentKey || now - state.lastForwardedAt < REPEAT_SUPPRESSION_WINDOW_MS) {
|
|
1372
|
+
continue;
|
|
1373
|
+
}
|
|
1374
|
+
if (state.repeatsSuppressed > 0) {
|
|
1375
|
+
forwardLine(state.line, state.parsed, state.repeatsSuppressed);
|
|
1376
|
+
}
|
|
1377
|
+
repeatStates.delete(key);
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
const flushLine = (line) => {
|
|
1381
|
+
const parsed = parseOpenCodeLogLine(line);
|
|
1382
|
+
if (!parsed) return;
|
|
1383
|
+
const now = Date.now();
|
|
1384
|
+
const key = parsed.message === void 0 ? void 0 : `${parsed.level}\0${parsed.message}`;
|
|
1385
|
+
expireRepeatStates(now, key);
|
|
1386
|
+
if (key === void 0) {
|
|
1387
|
+
forwardLine(line, parsed);
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
const previous = repeatStates.get(key);
|
|
1391
|
+
if (!previous || now - previous.lastForwardedAt >= REPEAT_SUPPRESSION_WINDOW_MS) {
|
|
1392
|
+
forwardLine(line, parsed, previous?.repeatsSuppressed ?? 0);
|
|
1393
|
+
repeatStates.set(key, {
|
|
1394
|
+
line,
|
|
1395
|
+
parsed,
|
|
1396
|
+
lastForwardedAt: now,
|
|
1397
|
+
repeatsSuppressed: 0
|
|
1398
|
+
});
|
|
1399
|
+
return;
|
|
1400
|
+
}
|
|
1401
|
+
previous.line = line;
|
|
1402
|
+
previous.parsed = parsed;
|
|
1403
|
+
previous.repeatsSuppressed++;
|
|
1404
|
+
};
|
|
1405
|
+
const forward = ((chunk) => {
|
|
1339
1406
|
buffer = Buffer.concat([buffer, Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, "utf-8")]);
|
|
1340
1407
|
let newlineIndex;
|
|
1341
1408
|
while ((newlineIndex = buffer.indexOf(10)) !== -1) {
|
|
@@ -1346,7 +1413,16 @@ function createOpenCodeActivityForwarder(getContext) {
|
|
|
1346
1413
|
flushLine(buffer.toString("utf-8"));
|
|
1347
1414
|
buffer = Buffer.alloc(0);
|
|
1348
1415
|
}
|
|
1416
|
+
});
|
|
1417
|
+
forward.flush = () => {
|
|
1418
|
+
for (const state of repeatStates.values()) {
|
|
1419
|
+
if (state.repeatsSuppressed > 0) {
|
|
1420
|
+
forwardLine(state.line, state.parsed, state.repeatsSuppressed);
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
repeatStates.clear();
|
|
1349
1424
|
};
|
|
1425
|
+
return forward;
|
|
1350
1426
|
}
|
|
1351
1427
|
var MAX_MESSAGE_LENGTH = 500;
|
|
1352
1428
|
var MAX_METADATA_VALUE_LENGTH = 200;
|
|
@@ -1372,7 +1448,7 @@ function redactHomeDirectory(message) {
|
|
|
1372
1448
|
}
|
|
1373
1449
|
return result + message.slice(searchFrom);
|
|
1374
1450
|
}
|
|
1375
|
-
function
|
|
1451
|
+
function redactDiagnosticText(message) {
|
|
1376
1452
|
const redacted = message.replace(/esk_[A-Za-z0-9_-]+/g, "esk_***").replace(/ct_[A-Za-z0-9_-]+/g, "ct_***").replace(/(?<![A-Za-z0-9_-])sk-ant-[A-Za-z0-9_-]{20,}(?![A-Za-z0-9_-])/g, "sk-ant-***").replace(/(?<![A-Za-z0-9_-])sk-proj-[A-Za-z0-9_-]{20,}(?![A-Za-z0-9_-])/g, "sk-proj-***").replace(/(?<![A-Za-z0-9_-])sk-[A-Za-z0-9]{20,}(?![A-Za-z0-9_-])/g, "sk-***").replace(/(?<![A-Za-z0-9_-])(gh[oprsu])_[A-Za-z0-9]{20,}(?![A-Za-z0-9_-])/g, "$1_***").replace(/(?<![A-Za-z0-9_-])github_pat_[A-Za-z0-9_]{20,}(?![A-Za-z0-9_-])/g, "github_pat_***").replace(/https?:\/\/\S+/g, "<url>");
|
|
1377
1453
|
return redactHomeDirectory(redacted);
|
|
1378
1454
|
}
|
|
@@ -1384,14 +1460,17 @@ function sanitiseMetadata(metadata) {
|
|
|
1384
1460
|
if (!metadata) return {};
|
|
1385
1461
|
const entries = Object.entries(metadata).slice(0, MAX_METADATA_ENTRIES);
|
|
1386
1462
|
if (Object.keys(metadata).length > entries.length) {
|
|
1387
|
-
|
|
1388
|
-
`
|
|
1463
|
+
reportTelemetryDiagnostic(
|
|
1464
|
+
`Runner activity telemetry dropped ${Object.keys(metadata).length - entries.length} metadata entries; those entries were not sent`
|
|
1389
1465
|
);
|
|
1390
1466
|
}
|
|
1391
1467
|
const sanitised = [];
|
|
1392
1468
|
for (const [key, value] of entries) {
|
|
1393
1469
|
if (typeof value === "string") {
|
|
1394
|
-
sanitised.push([
|
|
1470
|
+
sanitised.push([
|
|
1471
|
+
key,
|
|
1472
|
+
truncate(redactDiagnosticText(value).slice(0, MAX_METADATA_VALUE_LENGTH))
|
|
1473
|
+
]);
|
|
1395
1474
|
} else if (value === null || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value)) {
|
|
1396
1475
|
sanitised.push([key, value]);
|
|
1397
1476
|
}
|
|
@@ -1409,8 +1488,8 @@ function admitUnderRateLimit(source, now) {
|
|
|
1409
1488
|
}
|
|
1410
1489
|
if (now - window.windowStartedAt >= RATE_LIMIT_WINDOW_MS) {
|
|
1411
1490
|
if (window.windowDroppedCount > 0) {
|
|
1412
|
-
|
|
1413
|
-
`
|
|
1491
|
+
reportTelemetryDiagnostic(
|
|
1492
|
+
`Runner activity telemetry rate cap reached: dropped ${window.windowDroppedCount} ${window.windowDroppedCount === 1 ? "entry" : "entries"} in the last ${RATE_LIMIT_WINDOW_MS / 1e3}s (limit ${RATE_LIMIT_MAX_EVENTS}/min); those entries were not sent for source "${source}"`
|
|
1414
1493
|
);
|
|
1415
1494
|
}
|
|
1416
1495
|
window.windowStartedAt = now;
|
|
@@ -1420,8 +1499,8 @@ function admitUnderRateLimit(source, now) {
|
|
|
1420
1499
|
if (window.windowCount >= RATE_LIMIT_MAX_EVENTS) {
|
|
1421
1500
|
window.windowDroppedCount++;
|
|
1422
1501
|
if (window.windowDroppedCount === 1) {
|
|
1423
|
-
|
|
1424
|
-
`
|
|
1502
|
+
reportTelemetryDiagnostic(
|
|
1503
|
+
`Runner activity telemetry rate cap reached (${RATE_LIMIT_MAX_EVENTS} entries per ${RATE_LIMIT_WINDOW_MS / 1e3}s limit; further entries were not sent for source "${source}"`
|
|
1425
1504
|
);
|
|
1426
1505
|
}
|
|
1427
1506
|
return false;
|
|
@@ -1436,7 +1515,7 @@ function forwardRunnerActivity(entry, context) {
|
|
|
1436
1515
|
if (!context.agentId || !context.authHeader) return;
|
|
1437
1516
|
if (!admitUnderRateLimit(source, Date.now())) return;
|
|
1438
1517
|
const rawMessage = entry.error ?? entry.message ?? "";
|
|
1439
|
-
const message = truncate(
|
|
1518
|
+
const message = truncate(redactDiagnosticText(rawMessage));
|
|
1440
1519
|
logEvent(TelemetryEventTypes.RUNNER_ACTIVITY, {
|
|
1441
1520
|
severity: SEVERITY_BY_LEVEL[entry.level],
|
|
1442
1521
|
message,
|
|
@@ -1444,8 +1523,8 @@ function forwardRunnerActivity(entry, context) {
|
|
|
1444
1523
|
agentId: context.agentId
|
|
1445
1524
|
});
|
|
1446
1525
|
} catch (err) {
|
|
1447
|
-
|
|
1448
|
-
`
|
|
1526
|
+
reportTelemetryDiagnostic(
|
|
1527
|
+
`Runner activity telemetry failed to forward runner activity: ${err instanceof Error ? err.message : String(err)}`
|
|
1449
1528
|
);
|
|
1450
1529
|
}
|
|
1451
1530
|
}
|
|
@@ -1735,8 +1814,46 @@ async function waitForOpenCode2Health(port, password, timeoutMs = 3e4) {
|
|
|
1735
1814
|
|
|
1736
1815
|
// src/lib/http-timeout.ts
|
|
1737
1816
|
var REQUEST_TIMEOUT_MS = 6e4;
|
|
1817
|
+
var RequestTimeoutError = class extends Error {
|
|
1818
|
+
constructor(operation, timeoutMs, elapsedMs) {
|
|
1819
|
+
super(`${operation} timed out after ${elapsedMs}ms (limit ${timeoutMs}ms)`);
|
|
1820
|
+
this.operation = operation;
|
|
1821
|
+
this.timeoutMs = timeoutMs;
|
|
1822
|
+
this.elapsedMs = elapsedMs;
|
|
1823
|
+
this.name = "TimeoutError";
|
|
1824
|
+
}
|
|
1825
|
+
};
|
|
1826
|
+
function describeRequestOperation(input, init) {
|
|
1827
|
+
const method = (init?.method ?? input.method ?? "GET").toUpperCase();
|
|
1828
|
+
const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
1829
|
+
let path;
|
|
1830
|
+
try {
|
|
1831
|
+
path = new URL(rawUrl).pathname;
|
|
1832
|
+
} catch (error2) {
|
|
1833
|
+
if (!(error2 instanceof TypeError)) throw error2;
|
|
1834
|
+
path = rawUrl.split(/[?#]/, 1)[0];
|
|
1835
|
+
}
|
|
1836
|
+
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1837
|
+
const prefixedIdentifier = /^[a-z]+_[A-Za-z0-9_-]{10,}$/;
|
|
1838
|
+
const maskedPath = path.split("/").map((segment) => uuid.test(segment) || prefixedIdentifier.test(segment) ? ":id" : segment).join("/");
|
|
1839
|
+
return `${method} ${maskedPath}`;
|
|
1840
|
+
}
|
|
1738
1841
|
function withRequestTimeout(fetchImpl, timeoutMs) {
|
|
1739
|
-
return ((input, init) =>
|
|
1842
|
+
return (async (input, init) => {
|
|
1843
|
+
const startedAt = Date.now();
|
|
1844
|
+
try {
|
|
1845
|
+
return await fetchImpl(input, { ...init, signal: AbortSignal.timeout(timeoutMs) });
|
|
1846
|
+
} catch (error2) {
|
|
1847
|
+
if (error2?.name === "TimeoutError") {
|
|
1848
|
+
throw new RequestTimeoutError(
|
|
1849
|
+
describeRequestOperation(input, init),
|
|
1850
|
+
timeoutMs,
|
|
1851
|
+
Date.now() - startedAt
|
|
1852
|
+
);
|
|
1853
|
+
}
|
|
1854
|
+
throw error2;
|
|
1855
|
+
}
|
|
1856
|
+
});
|
|
1740
1857
|
}
|
|
1741
1858
|
|
|
1742
1859
|
// src/lib/opencode/client.ts
|
|
@@ -3397,16 +3514,17 @@ function hasPrimaryHeaders(headers) {
|
|
|
3397
3514
|
].some((name) => headers.has(name));
|
|
3398
3515
|
}
|
|
3399
3516
|
async function getOpenAiUsage(port, client) {
|
|
3517
|
+
const openCodeVersion = client?.version ?? "v1";
|
|
3400
3518
|
const credentials2 = readOpenCodeChatGptCredentials();
|
|
3401
3519
|
if (!credentials2) {
|
|
3402
3520
|
throw new OpenAiUsageError(
|
|
3403
|
-
"No ChatGPT login found. Connect a ChatGPT account to this runner, or run `opencode auth login`.",
|
|
3521
|
+
openCodeVersion === "v2" ? "OpenAI usage reporting is not available on OpenCode V2 because V2 keeps a connected ChatGPT login in a store Evident cannot read." : "No ChatGPT login found. Connect a ChatGPT account to this runner, or run `opencode auth login`.",
|
|
3404
3522
|
"no_credentials"
|
|
3405
3523
|
);
|
|
3406
3524
|
}
|
|
3407
3525
|
if (credentials2.expiresAt < Date.now()) {
|
|
3408
3526
|
throw new OpenAiUsageError(
|
|
3409
|
-
"ChatGPT credentials have expired. Run `opencode auth login` to refresh them.",
|
|
3527
|
+
openCodeVersion === "v2" ? "The delivered ChatGPT login has expired. OpenCode V2 cannot be given a replacement by file; connect the account again from the runner's page in Evident." : "ChatGPT credentials have expired. Run `opencode auth login` to refresh them.",
|
|
3410
3528
|
"credentials_expired"
|
|
3411
3529
|
);
|
|
3412
3530
|
}
|
|
@@ -5392,6 +5510,8 @@ var StreamForwarder = class {
|
|
|
5392
5510
|
if (done) break;
|
|
5393
5511
|
const chunk = Buffer.from(value);
|
|
5394
5512
|
for (let i = 0; i < chunk.length; i += MAX_FRAME_BYTES) {
|
|
5513
|
+
await stream.pausePromise;
|
|
5514
|
+
if (ac.signal.aborted) break;
|
|
5395
5515
|
const slice = chunk.subarray(i, i + MAX_FRAME_BYTES);
|
|
5396
5516
|
if (this.binaryFramesSupported) {
|
|
5397
5517
|
if (this.ws.readyState === WebSocket.OPEN) {
|
|
@@ -5617,6 +5737,7 @@ function connectTunnel(options) {
|
|
|
5617
5737
|
var RunnerConnection = class {
|
|
5618
5738
|
opts;
|
|
5619
5739
|
sleep;
|
|
5740
|
+
now;
|
|
5620
5741
|
connection = null;
|
|
5621
5742
|
resolvedAgentId;
|
|
5622
5743
|
/** True while a (re)connect loop is in flight. */
|
|
@@ -5625,10 +5746,13 @@ var RunnerConnection = class {
|
|
|
5625
5746
|
reconnectPromise = null;
|
|
5626
5747
|
/** 1-based count of the current reconnect attempt streak. */
|
|
5627
5748
|
reconnectAttempt = 0;
|
|
5749
|
+
generation = 0;
|
|
5750
|
+
disconnectedAtMs = null;
|
|
5628
5751
|
constructor(opts) {
|
|
5629
5752
|
this.opts = opts;
|
|
5630
5753
|
this.resolvedAgentId = opts.agentId;
|
|
5631
5754
|
this.sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
5755
|
+
this.now = opts.now ?? Date.now;
|
|
5632
5756
|
}
|
|
5633
5757
|
get agentId() {
|
|
5634
5758
|
return this.resolvedAgentId;
|
|
@@ -5664,13 +5788,22 @@ var RunnerConnection = class {
|
|
|
5664
5788
|
port: this.opts.port,
|
|
5665
5789
|
openCodePassword: this.opts.openCodePassword,
|
|
5666
5790
|
onConnected: (agentId) => {
|
|
5791
|
+
const attempt = this.reconnectAttempt + 1;
|
|
5667
5792
|
this.reconnectAttempt = 0;
|
|
5668
5793
|
this.reconnecting = false;
|
|
5669
5794
|
this.resolvedAgentId = agentId;
|
|
5670
|
-
|
|
5795
|
+
this.generation++;
|
|
5796
|
+
const downtimeMs = this.disconnectedAtMs === null ? null : this.now() - this.disconnectedAtMs;
|
|
5797
|
+
this.disconnectedAtMs = null;
|
|
5798
|
+
events.onConnected(agentId, isReconnect, {
|
|
5799
|
+
generation: this.generation,
|
|
5800
|
+
attempt,
|
|
5801
|
+
downtimeMs
|
|
5802
|
+
});
|
|
5671
5803
|
},
|
|
5672
5804
|
onDisconnected: (code, reason) => {
|
|
5673
|
-
|
|
5805
|
+
this.disconnectedAtMs = this.now();
|
|
5806
|
+
events.onDisconnected(code, reason, { generation: this.generation });
|
|
5674
5807
|
if (this.opts.isRunning() && code !== 1e3 && !this.reconnecting) {
|
|
5675
5808
|
this.reconnectPromise = this.connectWithRetry(true).catch((err) => {
|
|
5676
5809
|
events.onError?.(`Reconnection failed: ${err.message}`);
|
|
@@ -12147,6 +12280,7 @@ function createCredentialSync({
|
|
|
12147
12280
|
|
|
12148
12281
|
// src/commands/run.ts
|
|
12149
12282
|
var MAX_ACTIVITY_LOG_ENTRIES = 10;
|
|
12283
|
+
var MAX_DISCONNECT_REASON_LENGTH = 200;
|
|
12150
12284
|
var CHANNEL_POLL_INTERVAL_MS = Number(process.env.EVIDENT_CHANNEL_POLL_INTERVAL_MS) || 2e3;
|
|
12151
12285
|
var CHANNEL_STUCK_QUEUED_MS = Number(process.env.EVIDENT_STUCK_QUEUED_MS) || void 0;
|
|
12152
12286
|
var SHUTDOWN_DRAIN_TIMEOUT_MS = Number(process.env.EVIDENT_SHUTDOWN_DRAIN_MS) || 25e3;
|
|
@@ -12365,7 +12499,9 @@ function displayStatus(state) {
|
|
|
12365
12499
|
const opencode = state.opencodeConnected ? chalk7.green(`opencode: :${state.port}`) : chalk7.red(`opencode: :${state.port} (down)`);
|
|
12366
12500
|
const messages = state.messageCount > 0 ? chalk7.dim(` \xB7 ${state.messageCount} processed`) : "";
|
|
12367
12501
|
const last = state.activityLog[state.activityLog.length - 1];
|
|
12368
|
-
const detail = last ? chalk7.dim(
|
|
12502
|
+
const detail = last ? chalk7.dim(
|
|
12503
|
+
` \xB7 ${last.timestamp.toISOString()} ${last.type === "error" ? last.error ?? "" : last.message ?? ""}`
|
|
12504
|
+
) : "";
|
|
12369
12505
|
const agent = state.agentName ?? state.agentId;
|
|
12370
12506
|
console.log(
|
|
12371
12507
|
`${chalk7.bold("Evident")} ${chalk7.dim(agent)} ${tunnel} ${opencode}${messages}${detail}`
|
|
@@ -12384,7 +12520,7 @@ function reportOpenCodeV2CredentialImport(state, result) {
|
|
|
12384
12520
|
logActivity(state, {
|
|
12385
12521
|
type: "info",
|
|
12386
12522
|
level: "warn",
|
|
12387
|
-
message: `OpenCode V2 saved login(s) for ${integrationIds} on this machine, but OpenCode V2 will not use them.
|
|
12523
|
+
message: `OpenCode V2 saved login(s) for ${integrationIds} on this machine, but OpenCode V2 will not use them. Connect the provider again from the runner's page in Evident; no shell on this machine is needed.`
|
|
12388
12524
|
});
|
|
12389
12525
|
}
|
|
12390
12526
|
if (result.imported.length === 0 && result.unsupported.length === 0 && result.failed.length === 0) {
|
|
@@ -13280,6 +13416,7 @@ async function run(options) {
|
|
|
13280
13416
|
authHeader: ""
|
|
13281
13417
|
};
|
|
13282
13418
|
setTelemetryAuthProvider(() => ({ authHeader: state.authHeader, agentId: state.agentId }));
|
|
13419
|
+
setTelemetryDiagnosticsReporter((message) => log2(state, message, "warn"));
|
|
13283
13420
|
if (options.credentialSyncMarker) {
|
|
13284
13421
|
state.credentialSync = createCredentialSync({
|
|
13285
13422
|
markerPath: options.credentialSyncMarker,
|
|
@@ -13465,13 +13602,18 @@ async function run(options) {
|
|
|
13465
13602
|
if (githubTokenPopulated) await configureGitHubAccess(credentialContext);
|
|
13466
13603
|
}
|
|
13467
13604
|
state.credentialSync?.arm();
|
|
13468
|
-
|
|
13605
|
+
const openCodeActivityForwarder = createOpenCodeActivityForwarder(() => ({
|
|
13606
|
+
agentId: state.agentId,
|
|
13607
|
+
authHeader: state.authHeader
|
|
13608
|
+
}));
|
|
13609
|
+
const openCodeLogTail = tailOpenCodeLogFile(
|
|
13469
13610
|
resolveOpenCodeLogPath(homedir7(), process.env),
|
|
13470
|
-
|
|
13471
|
-
|
|
13472
|
-
|
|
13473
|
-
|
|
13474
|
-
|
|
13611
|
+
openCodeActivityForwarder
|
|
13612
|
+
);
|
|
13613
|
+
state.stopOpenCodeLogTail = () => {
|
|
13614
|
+
openCodeActivityForwarder.flush();
|
|
13615
|
+
openCodeLogTail.stop();
|
|
13616
|
+
};
|
|
13475
13617
|
let sessionDbVerifyFatal = false;
|
|
13476
13618
|
if (!options.restoreSessionDb) {
|
|
13477
13619
|
log2(state, "Skipping session-DB restore: --restore-session-db was not passed", "debug");
|
|
@@ -13780,12 +13922,13 @@ async function run(options) {
|
|
|
13780
13922
|
openCodePassword: state.opencodePassword,
|
|
13781
13923
|
isRunning: () => state.running,
|
|
13782
13924
|
events: {
|
|
13783
|
-
onConnected: (agentId, isReconnect) => {
|
|
13925
|
+
onConnected: (agentId, isReconnect, transition) => {
|
|
13784
13926
|
state.connected = true;
|
|
13785
13927
|
state.agentId = agentId;
|
|
13928
|
+
const connectionMessage = isReconnect ? `Tunnel reconnected (runner: ${agentId}, generation: ${transition.generation}, attempt: ${transition.attempt}, offline for ${transition.downtimeMs}ms)` : `Tunnel connected (runner: ${agentId}, generation: ${transition.generation})`;
|
|
13786
13929
|
logActivity(state, {
|
|
13787
13930
|
type: "info",
|
|
13788
|
-
message:
|
|
13931
|
+
message: connectionMessage
|
|
13789
13932
|
});
|
|
13790
13933
|
if (options.tunnelReadyFile) {
|
|
13791
13934
|
const marker = writeTunnelReadyMarker(options.tunnelReadyFile, agentId);
|
|
@@ -13806,7 +13949,12 @@ async function run(options) {
|
|
|
13806
13949
|
version: state.opencodeVersion,
|
|
13807
13950
|
major: state.opencodeApiVersion,
|
|
13808
13951
|
connected: state.opencodeConnected
|
|
13809
|
-
})
|
|
13952
|
+
}),
|
|
13953
|
+
connection_generation: transition.generation,
|
|
13954
|
+
...isReconnect && transition.downtimeMs !== null ? {
|
|
13955
|
+
reconnect_attempt: transition.attempt,
|
|
13956
|
+
downtime_ms: transition.downtimeMs
|
|
13957
|
+
} : {}
|
|
13810
13958
|
});
|
|
13811
13959
|
if (!isReconnect) tunnelSpinner?.succeed("Tunnel connected");
|
|
13812
13960
|
if (state.interactive) displayStatus(state);
|
|
@@ -13828,13 +13976,18 @@ async function run(options) {
|
|
|
13828
13976
|
if (state.interactive) displayStatus(state);
|
|
13829
13977
|
});
|
|
13830
13978
|
},
|
|
13831
|
-
onDisconnected: (code, reason) => {
|
|
13979
|
+
onDisconnected: (code, reason, transition) => {
|
|
13832
13980
|
state.connected = false;
|
|
13981
|
+
const safeReason = redactDiagnosticText(reason).slice(0, MAX_DISCONNECT_REASON_LENGTH);
|
|
13833
13982
|
logActivity(state, {
|
|
13834
13983
|
type: "info",
|
|
13835
|
-
message: `Tunnel disconnected (code: ${code}, reason: ${
|
|
13984
|
+
message: `Tunnel disconnected (generation: ${transition.generation}, code: ${code}, reason: ${safeReason})`
|
|
13985
|
+
});
|
|
13986
|
+
emitAgentDisconnected(state.agentId, {
|
|
13987
|
+
code,
|
|
13988
|
+
reason: safeReason,
|
|
13989
|
+
connection_generation: transition.generation
|
|
13836
13990
|
});
|
|
13837
|
-
emitAgentDisconnected(state.agentId, { code, reason });
|
|
13838
13991
|
if (state.interactive) displayStatus(state);
|
|
13839
13992
|
},
|
|
13840
13993
|
onError: (error2) => {
|
|
@@ -13934,7 +14087,7 @@ async function run(options) {
|
|
|
13934
14087
|
},
|
|
13935
14088
|
report: (usage) => reportOpenAiUsage(state.agentId, state.authHeader, usage),
|
|
13936
14089
|
isLocalCredentialProblem: isLocalCredentialProblem2,
|
|
13937
|
-
forcedOnHint: "connect a ChatGPT account to this runner, or run `opencode auth login`",
|
|
14090
|
+
forcedOnHint: state.opencodeApiVersion === "v2" ? "OpenCode V2 keeps its connected ChatGPT login in a store Evident cannot read" : "connect a ChatGPT account to this runner, or run `opencode auth login`",
|
|
13938
14091
|
firstDelayMs: firstReportDelayMs,
|
|
13939
14092
|
nextDelayMs: usageReportDelayMs,
|
|
13940
14093
|
failureLogLevel: usageReportFailureLogLevel
|
|
@@ -13977,7 +14130,7 @@ async function run(options) {
|
|
|
13977
14130
|
}
|
|
13978
14131
|
|
|
13979
14132
|
// src/index.ts
|
|
13980
|
-
var
|
|
14133
|
+
var version = getCliVersion();
|
|
13981
14134
|
var program = new Command();
|
|
13982
14135
|
program.name("evident").description("Run OpenCode locally and connect it to Evident").version(version).option(
|
|
13983
14136
|
"--endpoint <url>",
|