@evident-ai/cli 3.1.1-dev.0d69ecc → 3.1.1-dev.134003c
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/README.md +4 -0
- package/dist/index.js +248 -51
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -94,6 +94,10 @@ Options:
|
|
|
94
94
|
- `-c, --conversation <id>` — Process only this specific conversation.
|
|
95
95
|
- `--idle-timeout <seconds>` — Exit after N seconds with no pending work (useful
|
|
96
96
|
in CI to avoid polling indefinitely).
|
|
97
|
+
- `--opencode-start-timeout <seconds>` — How long to wait for OpenCode to become
|
|
98
|
+
healthy when the runner starts it itself (default: `180`). On expiry the runner
|
|
99
|
+
warns and comes online anyway rather than failing. Env:
|
|
100
|
+
`EVIDENT_OPENCODE_START_TIMEOUT` (seconds).
|
|
97
101
|
- `--json` — Output in JSON format (forces non-interactive mode).
|
|
98
102
|
|
|
99
103
|
## Global flags
|
package/dist/index.js
CHANGED
|
@@ -267,16 +267,28 @@ async function getToken() {
|
|
|
267
267
|
}
|
|
268
268
|
return null;
|
|
269
269
|
}
|
|
270
|
+
function toError(err) {
|
|
271
|
+
return err instanceof Error ? err : new Error(String(err));
|
|
272
|
+
}
|
|
270
273
|
async function deleteToken(options = {}) {
|
|
271
274
|
const keytar = await getKeytar();
|
|
275
|
+
const failures = [];
|
|
272
276
|
if (keytar) {
|
|
273
277
|
if (options.all) {
|
|
274
|
-
|
|
278
|
+
let accounts = [];
|
|
279
|
+
try {
|
|
280
|
+
accounts = await keytar.findCredentials(SERVICE_NAME);
|
|
281
|
+
} catch (err) {
|
|
282
|
+
failures.push({ type: "enumerate", error: toError(err) });
|
|
283
|
+
}
|
|
275
284
|
await Promise.all(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
285
|
+
accounts.map(async (entry) => {
|
|
286
|
+
try {
|
|
287
|
+
await keytar.deletePassword(SERVICE_NAME, entry.account);
|
|
288
|
+
} catch (err) {
|
|
289
|
+
failures.push({ type: "delete", account: entry.account, error: toError(err) });
|
|
290
|
+
}
|
|
291
|
+
})
|
|
280
292
|
);
|
|
281
293
|
} else {
|
|
282
294
|
await keytar.deletePassword(SERVICE_NAME, keychainAccount());
|
|
@@ -287,6 +299,7 @@ async function deleteToken(options = {}) {
|
|
|
287
299
|
} else {
|
|
288
300
|
clearCredentials();
|
|
289
301
|
}
|
|
302
|
+
return { failures };
|
|
290
303
|
}
|
|
291
304
|
|
|
292
305
|
// src/utils/ui.ts
|
|
@@ -404,8 +417,10 @@ async function deviceFlowLogin(options) {
|
|
|
404
417
|
}
|
|
405
418
|
async function tokenLogin() {
|
|
406
419
|
console.log("Token login mode.");
|
|
407
|
-
console.log("
|
|
408
|
-
console.log(
|
|
420
|
+
console.log("Create a token under Settings \u2192 CLI tokens in the dashboard, then paste it below.");
|
|
421
|
+
console.log(
|
|
422
|
+
"(Alternatively, run `evident login` on a machine with a browser, or set EVIDENT_TOKEN for CI.)"
|
|
423
|
+
);
|
|
409
424
|
blank();
|
|
410
425
|
process.stdout.write("Paste token: ");
|
|
411
426
|
const token = await new Promise((resolve3) => {
|
|
@@ -429,13 +444,22 @@ async function tokenLogin() {
|
|
|
429
444
|
printError("No token provided.");
|
|
430
445
|
process.exit(1);
|
|
431
446
|
}
|
|
447
|
+
await validateAndStoreToken(token);
|
|
448
|
+
}
|
|
449
|
+
async function validateAndStoreToken(token) {
|
|
432
450
|
const spinner = ora("Validating token...").start();
|
|
433
451
|
try {
|
|
434
|
-
const result = await api.
|
|
452
|
+
const result = await api.get("/me", {
|
|
453
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
454
|
+
});
|
|
455
|
+
if (!result.user) {
|
|
456
|
+
throw new Error(
|
|
457
|
+
"This token is not a user login (e.g. a runner key). Paste a CLI token instead."
|
|
458
|
+
);
|
|
459
|
+
}
|
|
435
460
|
await storeToken({
|
|
436
461
|
token,
|
|
437
|
-
user: result.user
|
|
438
|
-
expiresAt: result.expires_at
|
|
462
|
+
user: { email: result.user.email }
|
|
439
463
|
});
|
|
440
464
|
spinner.stop();
|
|
441
465
|
printSuccess(`Logged in as ${chalk2.bold(result.user.email)}`);
|
|
@@ -455,9 +479,22 @@ async function login(options) {
|
|
|
455
479
|
}
|
|
456
480
|
|
|
457
481
|
// src/commands/logout.ts
|
|
482
|
+
function describeFailure(failure) {
|
|
483
|
+
if (failure.type === "enumerate") {
|
|
484
|
+
return `could not list stored keychain entries (${failure.error.message})`;
|
|
485
|
+
}
|
|
486
|
+
return `${failure.account} (${failure.error.message})`;
|
|
487
|
+
}
|
|
458
488
|
async function logout(options = {}) {
|
|
459
489
|
if (options.all) {
|
|
460
|
-
await deleteToken({ all: true });
|
|
490
|
+
const result = await deleteToken({ all: true });
|
|
491
|
+
if (result.failures.length > 0) {
|
|
492
|
+
printError(
|
|
493
|
+
`Failed to fully clear your keychain: ${result.failures.map(describeFailure).join("; ")}. Your local credentials file was cleared, but stale keychain entries may remain \u2014 run \`evident logout --all\` again, or remove them manually from your OS keychain / credential manager.`
|
|
494
|
+
);
|
|
495
|
+
process.exitCode = 1;
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
461
498
|
printSuccess("Logged out of all endpoints.");
|
|
462
499
|
return;
|
|
463
500
|
}
|
|
@@ -482,7 +519,9 @@ async function whoami() {
|
|
|
482
519
|
blank();
|
|
483
520
|
console.log(keyValue("Endpoint", apiUrl));
|
|
484
521
|
console.log(keyValue("User", chalk3.bold(credentials2.user.email)));
|
|
485
|
-
|
|
522
|
+
if (credentials2.user.id) {
|
|
523
|
+
console.log(keyValue("User ID", credentials2.user.id));
|
|
524
|
+
}
|
|
486
525
|
if (credentials2.expiresAt) {
|
|
487
526
|
const expiresAt = new Date(credentials2.expiresAt);
|
|
488
527
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -510,7 +549,10 @@ var TelemetryEventTypes = {
|
|
|
510
549
|
AGENT_DISCONNECTED: "agent.disconnected",
|
|
511
550
|
AGENT_MESSAGE_PROCESSING: "agent.message_processing",
|
|
512
551
|
AGENT_MESSAGE_DONE: "agent.message_done",
|
|
513
|
-
AGENT_MESSAGE_FAILED: "agent.message_failed"
|
|
552
|
+
AGENT_MESSAGE_FAILED: "agent.message_failed",
|
|
553
|
+
// A `warn`/`error` runner-side log line forwarded server-side for
|
|
554
|
+
// observability (issue #916) — see `apps/cli/src/lib/runner-activity-telemetry.ts`.
|
|
555
|
+
RUNNER_ACTIVITY: "runner.activity"
|
|
514
556
|
};
|
|
515
557
|
|
|
516
558
|
// ../../packages/types/src/tunnel/index.ts
|
|
@@ -565,6 +607,13 @@ var isShuttingDown = false;
|
|
|
565
607
|
var FLUSH_INTERVAL_MS = 5e3;
|
|
566
608
|
var MAX_BUFFER_SIZE = 50;
|
|
567
609
|
var FLUSH_TIMEOUT_MS = 3e3;
|
|
610
|
+
var authProvider = null;
|
|
611
|
+
function setTelemetryAuthProvider(provider) {
|
|
612
|
+
authProvider = provider;
|
|
613
|
+
}
|
|
614
|
+
var FLUSH_FAILURE_LOG_INTERVAL_MS = 6e4;
|
|
615
|
+
var lastFlushFailureLoggedAt = 0;
|
|
616
|
+
var suppressedFlushFailureCount = 0;
|
|
568
617
|
function logEvent(eventType, options = {}) {
|
|
569
618
|
const event = {
|
|
570
619
|
event_type: eventType,
|
|
@@ -599,9 +648,16 @@ async function flushEvents() {
|
|
|
599
648
|
flushTimeout = null;
|
|
600
649
|
}
|
|
601
650
|
try {
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
|
|
651
|
+
const providerContext = authProvider?.();
|
|
652
|
+
let authHeader;
|
|
653
|
+
if (providerContext?.authHeader) {
|
|
654
|
+
authHeader = providerContext.authHeader;
|
|
655
|
+
} else {
|
|
656
|
+
const credentials2 = await getToken();
|
|
657
|
+
if (!credentials2) {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
authHeader = `Bearer ${credentials2.token}`;
|
|
605
661
|
}
|
|
606
662
|
const apiUrl = getApiUrlConfig();
|
|
607
663
|
const controller = new AbortController();
|
|
@@ -616,7 +672,7 @@ async function flushEvents() {
|
|
|
616
672
|
method: "POST",
|
|
617
673
|
headers: {
|
|
618
674
|
"Content-Type": "application/json",
|
|
619
|
-
Authorization:
|
|
675
|
+
Authorization: authHeader
|
|
620
676
|
},
|
|
621
677
|
body: JSON.stringify(request),
|
|
622
678
|
signal: controller.signal
|
|
@@ -628,8 +684,15 @@ async function flushEvents() {
|
|
|
628
684
|
clearTimeout(timeout);
|
|
629
685
|
}
|
|
630
686
|
} catch (error2) {
|
|
631
|
-
|
|
632
|
-
|
|
687
|
+
const now = Date.now();
|
|
688
|
+
if (now - lastFlushFailureLoggedAt >= FLUSH_FAILURE_LOG_INTERVAL_MS) {
|
|
689
|
+
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
690
|
+
const suffix = suppressedFlushFailureCount > 0 ? ` (${suppressedFlushFailureCount} more suppressed in the last ${FLUSH_FAILURE_LOG_INTERVAL_MS / 1e3}s)` : "";
|
|
691
|
+
console.error(`Telemetry flush error: ${message}${suffix}`);
|
|
692
|
+
lastFlushFailureLoggedAt = now;
|
|
693
|
+
suppressedFlushFailureCount = 0;
|
|
694
|
+
} else {
|
|
695
|
+
suppressedFlushFailureCount++;
|
|
633
696
|
}
|
|
634
697
|
}
|
|
635
698
|
}
|
|
@@ -698,6 +761,69 @@ var EventTypes = {
|
|
|
698
761
|
DEPRECATED_AGENT_KEY_ENV_USED: "cli.deprecated_agent_key_env_used"
|
|
699
762
|
};
|
|
700
763
|
|
|
764
|
+
// src/lib/runner-activity-telemetry.ts
|
|
765
|
+
var FORWARDED_LEVELS = /* @__PURE__ */ new Set(["warn", "error"]);
|
|
766
|
+
var SEVERITY_BY_LEVEL = {
|
|
767
|
+
warn: "warning",
|
|
768
|
+
error: "error"
|
|
769
|
+
};
|
|
770
|
+
var MAX_MESSAGE_LENGTH = 500;
|
|
771
|
+
var TRUNCATION_MARKER = "\u2026";
|
|
772
|
+
function redact(message) {
|
|
773
|
+
return message.replace(/esk_[A-Za-z0-9_-]+/g, "esk_***").replace(/ct_[A-Za-z0-9_-]+/g, "ct_***").replace(/https?:\/\/\S+/g, "<url>");
|
|
774
|
+
}
|
|
775
|
+
function truncate(message) {
|
|
776
|
+
if (message.length <= MAX_MESSAGE_LENGTH) return message;
|
|
777
|
+
return message.slice(0, MAX_MESSAGE_LENGTH - TRUNCATION_MARKER.length) + TRUNCATION_MARKER;
|
|
778
|
+
}
|
|
779
|
+
var RATE_LIMIT_WINDOW_MS = 6e4;
|
|
780
|
+
var RATE_LIMIT_MAX_EVENTS = 30;
|
|
781
|
+
var windowStartedAt = 0;
|
|
782
|
+
var windowCount = 0;
|
|
783
|
+
var windowDroppedCount = 0;
|
|
784
|
+
function admitUnderRateLimit(now) {
|
|
785
|
+
if (now - windowStartedAt >= RATE_LIMIT_WINDOW_MS) {
|
|
786
|
+
if (windowDroppedCount > 0) {
|
|
787
|
+
console.error(
|
|
788
|
+
`[runner-activity-telemetry] rate cap reached: dropped ${windowDroppedCount} ${windowDroppedCount === 1 ? "entry" : "entries"} in the last ${RATE_LIMIT_WINDOW_MS / 1e3}s (cap ${RATE_LIMIT_MAX_EVENTS}/min)`
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
windowStartedAt = now;
|
|
792
|
+
windowCount = 0;
|
|
793
|
+
windowDroppedCount = 0;
|
|
794
|
+
}
|
|
795
|
+
if (windowCount >= RATE_LIMIT_MAX_EVENTS) {
|
|
796
|
+
windowDroppedCount++;
|
|
797
|
+
if (windowDroppedCount === 1) {
|
|
798
|
+
console.error(
|
|
799
|
+
`[runner-activity-telemetry] rate cap reached (${RATE_LIMIT_MAX_EVENTS} per ${RATE_LIMIT_WINDOW_MS / 1e3}s) \u2014 dropping further entries this window`
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
return false;
|
|
803
|
+
}
|
|
804
|
+
windowCount++;
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
807
|
+
function forwardRunnerActivity(entry, context) {
|
|
808
|
+
try {
|
|
809
|
+
if (!FORWARDED_LEVELS.has(entry.level)) return;
|
|
810
|
+
if (!context.agentId || !context.authHeader) return;
|
|
811
|
+
if (!admitUnderRateLimit(Date.now())) return;
|
|
812
|
+
const rawMessage = entry.error ?? entry.message ?? "";
|
|
813
|
+
const message = truncate(redact(rawMessage));
|
|
814
|
+
logEvent(TelemetryEventTypes.RUNNER_ACTIVITY, {
|
|
815
|
+
severity: SEVERITY_BY_LEVEL[entry.level],
|
|
816
|
+
message,
|
|
817
|
+
metadata: { source: "cli.run" },
|
|
818
|
+
agentId: context.agentId
|
|
819
|
+
});
|
|
820
|
+
} catch (err) {
|
|
821
|
+
console.error(
|
|
822
|
+
`[runner-activity-telemetry] failed to forward runner activity: ${err instanceof Error ? err.message : String(err)}`
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
701
827
|
// src/lib/auth.ts
|
|
702
828
|
async function getAuthCredentials() {
|
|
703
829
|
const runnerKey = process.env.EVIDENT_RUNNER_KEY;
|
|
@@ -3178,7 +3304,12 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
3178
3304
|
const directory = await this.resolveOpenCodeDirectory();
|
|
3179
3305
|
const sessionId = await createOpenCodeSession(this.port, directory);
|
|
3180
3306
|
this.sessions.set(conversationId, sessionId);
|
|
3181
|
-
await this.persistSession(conversationId, sessionId).catch(() => {
|
|
3307
|
+
await this.persistSession(conversationId, sessionId).catch((err) => {
|
|
3308
|
+
this.log({
|
|
3309
|
+
level: "warn",
|
|
3310
|
+
message: `Persisting the OpenCode session binding ${sessionId.slice(0, 8)} for conversation ${conversationId.slice(0, 8)} failed (best-effort, not retried) \u2014 the completion PATCH also carries opencode_session_id, so the binding is repaired when the turn finishes: ${err instanceof Error ? err.message : String(err)}`,
|
|
3311
|
+
conversation_id: conversationId
|
|
3312
|
+
});
|
|
3182
3313
|
});
|
|
3183
3314
|
return sessionId;
|
|
3184
3315
|
}
|
|
@@ -5212,10 +5343,16 @@ var ChannelDriver = class _ChannelDriver {
|
|
|
5212
5343
|
import chalk5 from "chalk";
|
|
5213
5344
|
import ora2 from "ora";
|
|
5214
5345
|
import { select as select2 } from "@inquirer/prompts";
|
|
5346
|
+
var INTERACTIVE_START_TIMEOUT_MS = 3e4;
|
|
5215
5347
|
async function ensureOpenCodeRunning(ctx) {
|
|
5216
5348
|
const healthCheck = await checkOpenCodeHealth(ctx.port);
|
|
5217
5349
|
if (healthCheck.healthy) {
|
|
5218
|
-
return {
|
|
5350
|
+
return {
|
|
5351
|
+
port: ctx.port,
|
|
5352
|
+
process: null,
|
|
5353
|
+
version: healthCheck.version ?? null,
|
|
5354
|
+
notReadyReason: null
|
|
5355
|
+
};
|
|
5219
5356
|
}
|
|
5220
5357
|
const runningInstances = await findHealthyOpenCodeInstances();
|
|
5221
5358
|
if (runningInstances.length > 0) {
|
|
@@ -5256,14 +5393,22 @@ async function ensureOpenCodeRunning(ctx) {
|
|
|
5256
5393
|
if (!ctx.interactive) {
|
|
5257
5394
|
ctx.log(`OpenCode is not running on port ${ctx.port}. Starting it automatically...`);
|
|
5258
5395
|
const proc = await startOpenCode(ctx.port);
|
|
5259
|
-
const health = await waitForOpenCodeHealth(ctx.port,
|
|
5396
|
+
const health = await waitForOpenCodeHealth(ctx.port, ctx.startTimeoutMs);
|
|
5260
5397
|
if (!health.healthy) {
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5398
|
+
return {
|
|
5399
|
+
port: ctx.port,
|
|
5400
|
+
process: proc,
|
|
5401
|
+
version: null,
|
|
5402
|
+
notReadyReason: `it did not become healthy within ${Math.round(ctx.startTimeoutMs / 1e3)}s`
|
|
5403
|
+
};
|
|
5264
5404
|
}
|
|
5265
5405
|
ctx.log(`OpenCode started on port ${ctx.port}${health.version ? ` (v${health.version})` : ""}`);
|
|
5266
|
-
return {
|
|
5406
|
+
return {
|
|
5407
|
+
port: ctx.port,
|
|
5408
|
+
process: proc,
|
|
5409
|
+
version: health.version ?? null,
|
|
5410
|
+
notReadyReason: null
|
|
5411
|
+
};
|
|
5267
5412
|
}
|
|
5268
5413
|
let port = ctx.port;
|
|
5269
5414
|
if (isPortInUse(port)) {
|
|
@@ -5316,15 +5461,15 @@ Port ${port} is already in use.`));
|
|
|
5316
5461
|
if (action === "start") {
|
|
5317
5462
|
const spinner = ora2("Starting OpenCode...").start();
|
|
5318
5463
|
const proc = await startOpenCode(port);
|
|
5319
|
-
const health = await waitForOpenCodeHealth(port,
|
|
5464
|
+
const health = await waitForOpenCodeHealth(port, INTERACTIVE_START_TIMEOUT_MS);
|
|
5320
5465
|
if (!health.healthy) {
|
|
5321
5466
|
spinner.fail("Failed to start OpenCode");
|
|
5322
5467
|
throw new Error("OpenCode failed to start");
|
|
5323
5468
|
}
|
|
5324
5469
|
spinner.stop();
|
|
5325
|
-
return { port, process: proc, version: health.version ?? null };
|
|
5470
|
+
return { port, process: proc, version: health.version ?? null, notReadyReason: null };
|
|
5326
5471
|
}
|
|
5327
|
-
return { port, process: null, version: null };
|
|
5472
|
+
return { port, process: null, version: null, notReadyReason: "you chose to continue without it" };
|
|
5328
5473
|
}
|
|
5329
5474
|
|
|
5330
5475
|
// src/commands/agent-lookup.ts
|
|
@@ -5521,6 +5666,35 @@ function resolveFileSyncDirectories(raw, homeDir) {
|
|
|
5521
5666
|
}
|
|
5522
5667
|
return directories;
|
|
5523
5668
|
}
|
|
5669
|
+
var DEFAULT_OPENCODE_START_TIMEOUT_SECONDS = 180;
|
|
5670
|
+
var MAX_OPENCODE_START_TIMEOUT_SECONDS = 3600;
|
|
5671
|
+
var OPENCODE_START_TIMEOUT_ENV = "EVIDENT_OPENCODE_START_TIMEOUT";
|
|
5672
|
+
function resolveOpenCodeStartTimeoutMs(options, env = process.env) {
|
|
5673
|
+
const defaultMs = DEFAULT_OPENCODE_START_TIMEOUT_SECONDS * 1e3;
|
|
5674
|
+
let raw;
|
|
5675
|
+
let source;
|
|
5676
|
+
if (options.opencodeStartTimeout !== void 0) {
|
|
5677
|
+
raw = options.opencodeStartTimeout;
|
|
5678
|
+
source = "--opencode-start-timeout";
|
|
5679
|
+
} else if (env[OPENCODE_START_TIMEOUT_ENV] !== void 0 && env[OPENCODE_START_TIMEOUT_ENV] !== "") {
|
|
5680
|
+
raw = env[OPENCODE_START_TIMEOUT_ENV];
|
|
5681
|
+
source = OPENCODE_START_TIMEOUT_ENV;
|
|
5682
|
+
} else {
|
|
5683
|
+
return { timeoutMs: defaultMs, warnings: [] };
|
|
5684
|
+
}
|
|
5685
|
+
const trimmed = raw.trim();
|
|
5686
|
+
const seconds = Number(trimmed);
|
|
5687
|
+
const isPositiveInteger = /^\d+$/.test(trimmed) && Number.isInteger(seconds) && seconds > 0;
|
|
5688
|
+
if (!isPositiveInteger || seconds > MAX_OPENCODE_START_TIMEOUT_SECONDS) {
|
|
5689
|
+
return {
|
|
5690
|
+
timeoutMs: defaultMs,
|
|
5691
|
+
warnings: [
|
|
5692
|
+
`Ignoring invalid ${source} "${raw}": expected a positive integer number of seconds (at most ${MAX_OPENCODE_START_TIMEOUT_SECONDS}); using the default ${DEFAULT_OPENCODE_START_TIMEOUT_SECONDS}s`
|
|
5693
|
+
]
|
|
5694
|
+
};
|
|
5695
|
+
}
|
|
5696
|
+
return { timeoutMs: seconds * 1e3, warnings: [] };
|
|
5697
|
+
}
|
|
5524
5698
|
function meetsThreshold(state, level) {
|
|
5525
5699
|
return LOG_LEVELS[level] >= LOG_LEVELS[state.logLevel];
|
|
5526
5700
|
}
|
|
@@ -5542,6 +5716,10 @@ function log2(state, message, level = "info") {
|
|
|
5542
5716
|
function logActivity(state, entry) {
|
|
5543
5717
|
const level = entry.level ?? (entry.type === "error" ? "error" : "info");
|
|
5544
5718
|
if (!meetsThreshold(state, level)) return;
|
|
5719
|
+
forwardRunnerActivity(
|
|
5720
|
+
{ level, message: entry.message, error: entry.error },
|
|
5721
|
+
{ agentId: state.agentId, authHeader: state.authHeader }
|
|
5722
|
+
);
|
|
5545
5723
|
const fullEntry = {
|
|
5546
5724
|
...entry,
|
|
5547
5725
|
level,
|
|
@@ -5896,6 +6074,7 @@ async function run(options) {
|
|
|
5896
6074
|
sessionCleanupTimers: [],
|
|
5897
6075
|
authHeader: ""
|
|
5898
6076
|
};
|
|
6077
|
+
setTelemetryAuthProvider(() => ({ authHeader: state.authHeader, agentId: state.agentId }));
|
|
5899
6078
|
if (fileSyncDirectories.length > 0) {
|
|
5900
6079
|
log2(state, `File sync enabled for: ${fileSyncDirectories.join(", ")}`);
|
|
5901
6080
|
} else {
|
|
@@ -6084,40 +6263,52 @@ async function run(options) {
|
|
|
6084
6263
|
} else {
|
|
6085
6264
|
log2(state, "Not running in a MicroVM (MICROVM_ID unset) \u2014 nothing to report", "debug");
|
|
6086
6265
|
}
|
|
6266
|
+
const { timeoutMs: opencodeStartTimeoutMs, warnings: opencodeStartTimeoutWarnings } = resolveOpenCodeStartTimeoutMs(options, process.env);
|
|
6267
|
+
for (const warning2 of opencodeStartTimeoutWarnings) {
|
|
6268
|
+
logActivity(state, { type: "info", level: "warn", message: warning2 });
|
|
6269
|
+
}
|
|
6087
6270
|
const ocSpinner = interactive && !state.json ? ora3("Checking OpenCode...").start() : null;
|
|
6088
6271
|
try {
|
|
6089
6272
|
const oc = await ensureOpenCodeRunning({
|
|
6090
6273
|
port: state.port,
|
|
6091
6274
|
interactive: state.interactive,
|
|
6092
6275
|
agentId: state.agentId,
|
|
6093
|
-
log: (message) => log2(state, message)
|
|
6276
|
+
log: (message) => log2(state, message),
|
|
6277
|
+
startTimeoutMs: opencodeStartTimeoutMs
|
|
6094
6278
|
});
|
|
6095
6279
|
state.port = oc.port;
|
|
6096
6280
|
state.opencodeProcess = oc.process;
|
|
6097
6281
|
state.opencodeVersion = oc.version;
|
|
6098
|
-
state.opencodeConnected = oc.
|
|
6282
|
+
state.opencodeConnected = oc.notReadyReason === null;
|
|
6099
6283
|
const version2 = state.opencodeVersion ? ` (v${state.opencodeVersion})` : "";
|
|
6100
6284
|
ocSpinner?.succeed(`OpenCode running on port ${state.port}${version2}`);
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6285
|
+
if (!state.interactive && oc.notReadyReason !== null) {
|
|
6286
|
+
const message = `OpenCode is not ready on port ${state.port}: ${oc.notReadyReason}. The runner will still come online, but messages will fail until opencode answers \u2014 raise the wait with --opencode-start-timeout <seconds> (env ${OPENCODE_START_TIMEOUT_ENV}).`;
|
|
6287
|
+
logActivity(state, { type: "info", level: "warn", message });
|
|
6288
|
+
} else {
|
|
6289
|
+
const versionWarning = buildOpenCodeVersionWarning(state.opencodeVersion);
|
|
6290
|
+
if (versionWarning) {
|
|
6291
|
+
log2(state, versionWarning, "warn");
|
|
6292
|
+
if (state.interactive && !state.json) {
|
|
6293
|
+
logActivity(state, { type: "info", level: "warn", message: versionWarning });
|
|
6294
|
+
}
|
|
6106
6295
|
}
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6296
|
+
const noProviderWarning = buildNoProviderWarning(
|
|
6297
|
+
await hasAnyConfiguredProvider(state.port)
|
|
6298
|
+
);
|
|
6299
|
+
if (noProviderWarning) {
|
|
6300
|
+
log2(state, noProviderWarning, "warn");
|
|
6301
|
+
if (state.interactive && !state.json) {
|
|
6302
|
+
logActivity(state, { type: "info", level: "warn", message: noProviderWarning });
|
|
6303
|
+
blank();
|
|
6304
|
+
console.log(chalk6.yellow("\u26A0 No OpenCode model provider is configured."));
|
|
6305
|
+
console.log(
|
|
6306
|
+
chalk6.dim(
|
|
6307
|
+
`Run ${chalk6.cyan("opencode auth login")} to set one up \u2014 messages will fail until then.`
|
|
6308
|
+
)
|
|
6309
|
+
);
|
|
6310
|
+
blank();
|
|
6311
|
+
}
|
|
6121
6312
|
}
|
|
6122
6313
|
}
|
|
6123
6314
|
} catch (error2) {
|
|
@@ -6324,7 +6515,10 @@ program.command("run").description("Connect to Evident and process messages").op
|
|
|
6324
6515
|
).option("-p, --port <port>", "OpenCode port (default: 4096)", "4096").option(
|
|
6325
6516
|
"--log-level <level>",
|
|
6326
6517
|
"Log verbosity: debug | info | warn | error (default: info). Env: EVIDENT_LOG_LEVEL"
|
|
6327
|
-
).option("-v, --verbose", "Alias for --log-level debug (ignored if --log-level is set)").option("-c, --conversation <id>", "Process only this specific conversation").option("--idle-timeout <seconds>", "Exit after N seconds idle").option(
|
|
6518
|
+
).option("-v, --verbose", "Alias for --log-level debug (ignored if --log-level is set)").option("-c, --conversation <id>", "Process only this specific conversation").option("--idle-timeout <seconds>", "Exit after N seconds idle").option(
|
|
6519
|
+
"--opencode-start-timeout <seconds>",
|
|
6520
|
+
"Seconds to wait for OpenCode to become healthy when the runner starts it (default: 180). Env: EVIDENT_OPENCODE_START_TIMEOUT"
|
|
6521
|
+
).option("--json", "Output in JSON format").option(
|
|
6328
6522
|
"--session-cleanup-max-age <duration>",
|
|
6329
6523
|
"Delete OpenCode sessions idle longer than this (e.g. 7d, 24h). Enables cleanup. Env: EVIDENT_SESSION_CLEANUP_MAX_AGE"
|
|
6330
6524
|
).option(
|
|
@@ -6353,6 +6547,9 @@ program.command("run").description("Connect to Evident and process messages").op
|
|
|
6353
6547
|
verbose: options.verbose,
|
|
6354
6548
|
conversation: options.conversation,
|
|
6355
6549
|
idleTimeout: options.idleTimeout ? parseInt(options.idleTimeout, 10) : void 0,
|
|
6550
|
+
// Raw string — validation/precedence is single-sourced in run.ts's
|
|
6551
|
+
// resolveOpenCodeStartTimeoutMs (flag > EVIDENT_OPENCODE_START_TIMEOUT > 180s default).
|
|
6552
|
+
opencodeStartTimeout: options.opencodeStartTimeout,
|
|
6356
6553
|
json: options.json,
|
|
6357
6554
|
// Raw strings — the resolver in run.ts single-sources parsing (M1).
|
|
6358
6555
|
sessionCleanupMaxAge: options.sessionCleanupMaxAge,
|