@evident-ai/cli 0.1.0

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 ADDED
@@ -0,0 +1,176 @@
1
+ # @connected/cli
2
+
3
+ Run OpenCode locally and connect it to the Connected platform.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g @connected/cli
9
+ ```
10
+
11
+ Or run directly with npx:
12
+
13
+ ```bash
14
+ npx @connected/cli <command>
15
+ ```
16
+
17
+ ## Commands
18
+
19
+ ### `connected login`
20
+
21
+ Authenticate with Connected using your browser.
22
+
23
+ ```bash
24
+ connected login
25
+ ```
26
+
27
+ Options:
28
+
29
+ - `--no-browser` - Don't open the browser automatically (copy the URL manually)
30
+ - `--token` - Use token-based authentication (for CI/CD environments)
31
+
32
+ ### `connected logout`
33
+
34
+ Remove stored credentials from your machine.
35
+
36
+ ```bash
37
+ connected logout
38
+ ```
39
+
40
+ ### `connected whoami`
41
+
42
+ Show the currently authenticated user.
43
+
44
+ ```bash
45
+ connected whoami
46
+ ```
47
+
48
+ ### `connected tunnel`
49
+
50
+ Establish a tunnel from your local OpenCode instance to Connected.
51
+
52
+ ```bash
53
+ connected tunnel
54
+ ```
55
+
56
+ Options:
57
+
58
+ - `-s, --sandbox <id>` - Connect to a specific sandbox ID
59
+ - `-p, --port <port>` - OpenCode port (default: 4096)
60
+
61
+ ## Getting Started
62
+
63
+ ### 1. Install and run OpenCode locally
64
+
65
+ First, install OpenCode and start it in your project directory:
66
+
67
+ ```bash
68
+ # Install OpenCode
69
+ npm install -g @opencode/cli
70
+
71
+ # Start OpenCode server in your project
72
+ cd ~/projects/my-app
73
+ opencode serve --port 4096
74
+ ```
75
+
76
+ ### 2. Create a Local Mode sandbox
77
+
78
+ In the Connected web app (https://app.connected.run):
79
+
80
+ 1. Click "New Sandbox"
81
+ 2. Select "Local Mode"
82
+ 3. Click "Create Sandbox"
83
+
84
+ Note the sandbox ID from the URL or dashboard.
85
+
86
+ ### 3. Connect via the CLI
87
+
88
+ ```bash
89
+ # Authenticate (first time only)
90
+ connected login
91
+
92
+ # Start the tunnel
93
+ connected tunnel --sandbox <sandbox-id>
94
+ ```
95
+
96
+ The tunnel will connect your local OpenCode to the Connected platform, enabling:
97
+
98
+ - Chat through the web interface
99
+ - WhatsApp and Slack integration
100
+ - Session history and management
101
+
102
+ ## How It Works
103
+
104
+ ```
105
+ +-------------------+ +-------------------+ +-------------------+
106
+ | Your Machine | | Cloudflare Edge | | Connected API |
107
+ | | | | | |
108
+ | OpenCode (4096) <-+---->| Tunnel Relay (DO) |<--->| Cloud Run |
109
+ | | | | | |
110
+ | connected tunnel |---->| WebSocket | | Neon DB |
111
+ +-------------------+ +-------------------+ +-------------------+
112
+ ```
113
+
114
+ 1. The CLI connects to OpenCode running on localhost
115
+ 2. Establishes a WebSocket connection to the tunnel relay
116
+ 3. Connected routes messages through the tunnel to your local OpenCode
117
+ 4. Responses flow back through the same path
118
+
119
+ ## Troubleshooting
120
+
121
+ ### "OpenCode not found on port 4096"
122
+
123
+ Make sure OpenCode is running:
124
+
125
+ ```bash
126
+ opencode serve --port 4096
127
+ ```
128
+
129
+ ### "Authentication failed"
130
+
131
+ Re-authenticate:
132
+
133
+ ```bash
134
+ connected logout
135
+ connected login
136
+ ```
137
+
138
+ ### "Tunnel disconnected"
139
+
140
+ The CLI will automatically reconnect. If issues persist:
141
+
142
+ 1. Check your internet connection
143
+ 2. Verify OpenCode is still running
144
+ 3. Try restarting the tunnel
145
+
146
+ ## Configuration
147
+
148
+ Credentials are stored in:
149
+
150
+ - macOS/Linux: `~/.config/connected/`
151
+ - Windows: `%APPDATA%\connected\`
152
+
153
+ Environment variables:
154
+
155
+ - `CONNECTED_API_URL` - Override the API URL (for development)
156
+ - `CONNECTED_TUNNEL_URL` - Override the tunnel relay URL (for development)
157
+
158
+ ## Development
159
+
160
+ ```bash
161
+ # Install dependencies
162
+ pnpm install
163
+
164
+ # Build
165
+ pnpm build
166
+
167
+ # Run locally
168
+ pnpm start <command>
169
+
170
+ # Type check
171
+ pnpm typecheck
172
+ ```
173
+
174
+ ## License
175
+
176
+ MIT
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/index.js ADDED
@@ -0,0 +1,607 @@
1
+ #!/usr/bin/env node
2
+ #!/usr/bin/env node
3
+
4
+ // src/index.ts
5
+ import { Command } from "commander";
6
+
7
+ // src/commands/login.ts
8
+ import open from "open";
9
+ import ora from "ora";
10
+ import chalk2 from "chalk";
11
+
12
+ // src/lib/config.ts
13
+ import Conf from "conf";
14
+ import { homedir } from "os";
15
+ import { join } from "path";
16
+ var environmentPresets = {
17
+ local: {
18
+ apiUrl: "http://localhost:3000",
19
+ tunnelUrl: "ws://localhost:8787"
20
+ },
21
+ dev: {
22
+ apiUrl: "https://api.dev.evident.run",
23
+ tunnelUrl: "wss://tunnel.dev.evident.run"
24
+ },
25
+ production: {
26
+ // Production URLs also have aliases: api.evident.run, tunnel.evident.run
27
+ apiUrl: "https://api.production.evident.run",
28
+ tunnelUrl: "wss://tunnel.production.evident.run"
29
+ }
30
+ };
31
+ var defaults = environmentPresets.production;
32
+ var currentEnvironment = "production";
33
+ function setEnvironment(env) {
34
+ currentEnvironment = env;
35
+ }
36
+ function getEnvironment() {
37
+ const envVar = process.env.EVIDENT_ENV;
38
+ if (envVar && environmentPresets[envVar]) {
39
+ return envVar;
40
+ }
41
+ return currentEnvironment;
42
+ }
43
+ function getEnvConfig() {
44
+ return environmentPresets[getEnvironment()];
45
+ }
46
+ function getApiUrl() {
47
+ return process.env.EVIDENT_API_URL ?? getEnvConfig().apiUrl;
48
+ }
49
+ function getTunnelUrl() {
50
+ return process.env.EVIDENT_TUNNEL_URL ?? getEnvConfig().tunnelUrl;
51
+ }
52
+ var config = new Conf({
53
+ projectName: "evident",
54
+ projectSuffix: "",
55
+ defaults
56
+ });
57
+ var credentials = new Conf({
58
+ projectName: "evident",
59
+ projectSuffix: "",
60
+ configName: "credentials",
61
+ defaults: {}
62
+ });
63
+ function getApiUrlConfig() {
64
+ return getApiUrl();
65
+ }
66
+ function getTunnelUrlConfig() {
67
+ return getTunnelUrl();
68
+ }
69
+ function getCredentials() {
70
+ return {
71
+ token: credentials.get("token"),
72
+ user: credentials.get("user"),
73
+ expiresAt: credentials.get("expiresAt")
74
+ };
75
+ }
76
+ function setCredentials(creds) {
77
+ if (creds.token) credentials.set("token", creds.token);
78
+ if (creds.user) credentials.set("user", creds.user);
79
+ if (creds.expiresAt) credentials.set("expiresAt", creds.expiresAt);
80
+ }
81
+ function clearCredentials() {
82
+ credentials.clear();
83
+ }
84
+
85
+ // src/lib/api.ts
86
+ var ApiClient = class {
87
+ baseUrl;
88
+ constructor(baseUrl) {
89
+ this.baseUrl = baseUrl ?? getApiUrlConfig();
90
+ }
91
+ /**
92
+ * Make an API request
93
+ */
94
+ async request(path, options = {}) {
95
+ const { method = "GET", body, headers = {}, authenticated = false } = options;
96
+ const url = `${this.baseUrl}${path}`;
97
+ const requestHeaders = {
98
+ "Content-Type": "application/json",
99
+ ...headers
100
+ };
101
+ if (authenticated) {
102
+ const creds = getCredentials();
103
+ if (!creds.token) {
104
+ throw new Error("Not authenticated. Run `evident login` first.");
105
+ }
106
+ requestHeaders["Authorization"] = `Bearer ${creds.token}`;
107
+ }
108
+ const response = await fetch(url, {
109
+ method,
110
+ headers: requestHeaders,
111
+ body: body ? JSON.stringify(body) : void 0
112
+ });
113
+ if (!response.ok) {
114
+ let errorData;
115
+ try {
116
+ errorData = await response.json();
117
+ } catch {
118
+ errorData = {
119
+ message: response.statusText,
120
+ statusCode: response.status
121
+ };
122
+ }
123
+ const error2 = new Error(errorData.message);
124
+ error2.statusCode = response.status;
125
+ throw error2;
126
+ }
127
+ const contentType = response.headers.get("Content-Type");
128
+ if (!contentType?.includes("application/json")) {
129
+ return {};
130
+ }
131
+ return response.json();
132
+ }
133
+ /**
134
+ * GET request
135
+ */
136
+ async get(path, options = {}) {
137
+ return this.request(path, { ...options, method: "GET" });
138
+ }
139
+ /**
140
+ * POST request
141
+ */
142
+ async post(path, body, options = {}) {
143
+ return this.request(path, { ...options, method: "POST", body });
144
+ }
145
+ /**
146
+ * PUT request
147
+ */
148
+ async put(path, body, options = {}) {
149
+ return this.request(path, { ...options, method: "PUT", body });
150
+ }
151
+ /**
152
+ * DELETE request
153
+ */
154
+ async delete(path, options = {}) {
155
+ return this.request(path, { ...options, method: "DELETE" });
156
+ }
157
+ };
158
+ var api = new ApiClient();
159
+
160
+ // src/lib/keychain.ts
161
+ var SERVICE_NAME = "evident-cli";
162
+ var ACCOUNT_NAME = "default";
163
+ async function getKeytar() {
164
+ try {
165
+ return await import("keytar");
166
+ } catch {
167
+ return null;
168
+ }
169
+ }
170
+ async function storeToken(credentials2) {
171
+ const keytar = await getKeytar();
172
+ if (keytar) {
173
+ await keytar.setPassword(SERVICE_NAME, ACCOUNT_NAME, JSON.stringify(credentials2));
174
+ } else {
175
+ setCredentials({
176
+ token: credentials2.token,
177
+ user: credentials2.user,
178
+ expiresAt: credentials2.expiresAt
179
+ });
180
+ }
181
+ }
182
+ async function getToken() {
183
+ const keytar = await getKeytar();
184
+ if (keytar) {
185
+ const stored = await keytar.getPassword(SERVICE_NAME, ACCOUNT_NAME);
186
+ if (stored) {
187
+ try {
188
+ return JSON.parse(stored);
189
+ } catch {
190
+ await keytar.deletePassword(SERVICE_NAME, ACCOUNT_NAME);
191
+ return null;
192
+ }
193
+ }
194
+ }
195
+ const creds = getCredentials();
196
+ if (creds.token && creds.user) {
197
+ return {
198
+ token: creds.token,
199
+ user: creds.user,
200
+ expiresAt: creds.expiresAt
201
+ };
202
+ }
203
+ return null;
204
+ }
205
+ async function deleteToken() {
206
+ const keytar = await getKeytar();
207
+ if (keytar) {
208
+ await keytar.deletePassword(SERVICE_NAME, ACCOUNT_NAME);
209
+ }
210
+ clearCredentials();
211
+ }
212
+
213
+ // src/utils/ui.ts
214
+ import chalk from "chalk";
215
+ function success(message) {
216
+ return `${chalk.green("\u2713")} ${message}`;
217
+ }
218
+ function error(message) {
219
+ return `${chalk.red("\u2717")} ${message}`;
220
+ }
221
+ function warning(message) {
222
+ return `${chalk.yellow("!")} ${message}`;
223
+ }
224
+ function printSuccess(message) {
225
+ console.log(success(message));
226
+ }
227
+ function printError(message) {
228
+ console.error(error(message));
229
+ }
230
+ function printWarning(message) {
231
+ console.log(warning(message));
232
+ }
233
+ function keyValue(key, value) {
234
+ return `${chalk.dim(key + ":")} ${value}`;
235
+ }
236
+ function blank() {
237
+ console.log();
238
+ }
239
+ function waitForEnter(prompt = "Press Enter to continue...") {
240
+ return new Promise((resolve) => {
241
+ process.stdout.write(chalk.dim(prompt));
242
+ const handler = () => {
243
+ process.stdin.removeListener("data", handler);
244
+ process.stdin.setRawMode?.(false);
245
+ process.stdin.pause();
246
+ console.log();
247
+ resolve();
248
+ };
249
+ if (process.stdin.isTTY) {
250
+ process.stdin.setRawMode?.(true);
251
+ }
252
+ process.stdin.resume();
253
+ process.stdin.once("data", handler);
254
+ });
255
+ }
256
+ function sleep(ms) {
257
+ return new Promise((resolve) => setTimeout(resolve, ms));
258
+ }
259
+
260
+ // src/commands/login.ts
261
+ async function deviceFlowLogin(options) {
262
+ let deviceAuth;
263
+ try {
264
+ deviceAuth = await api.post("/auth/device");
265
+ } catch (error2) {
266
+ const message = error2 instanceof Error ? error2.message : "Unknown error";
267
+ printError(`Failed to start authentication: ${message}`);
268
+ process.exit(1);
269
+ }
270
+ const { device_code, user_code, verification_uri, interval } = deviceAuth;
271
+ blank();
272
+ console.log(chalk2.bold("To authenticate, visit:"));
273
+ console.log();
274
+ console.log(` ${chalk2.cyan(verification_uri)}`);
275
+ console.log();
276
+ console.log(chalk2.bold("And enter this code:"));
277
+ console.log();
278
+ console.log(` ${chalk2.yellow.bold(user_code)}`);
279
+ blank();
280
+ if (!options.noBrowser) {
281
+ await waitForEnter("Press Enter to open the browser...");
282
+ try {
283
+ await open(verification_uri);
284
+ } catch {
285
+ console.log(chalk2.dim("Could not open browser. Please visit the URL manually."));
286
+ }
287
+ }
288
+ const spinner = ora("Waiting for authentication...").start();
289
+ const pollIntervalMs = (interval || 5) * 1e3;
290
+ const maxAttempts = 60;
291
+ let attempts = 0;
292
+ while (attempts < maxAttempts) {
293
+ await sleep(pollIntervalMs);
294
+ attempts++;
295
+ try {
296
+ const result = await api.post("/auth/device/token", {
297
+ device_code
298
+ });
299
+ if (result.status === "complete" && result.access_token && result.user) {
300
+ await storeToken({
301
+ token: result.access_token,
302
+ user: result.user,
303
+ expiresAt: result.expires_at
304
+ });
305
+ spinner.stop();
306
+ blank();
307
+ printSuccess(`Logged in as ${chalk2.bold(result.user.email)}`);
308
+ return;
309
+ }
310
+ if (result.status === "expired") {
311
+ spinner.stop();
312
+ blank();
313
+ printError("Authentication expired. Please try again.");
314
+ process.exit(1);
315
+ }
316
+ } catch (error2) {
317
+ const message = error2 instanceof Error ? error2.message : "Unknown error";
318
+ spinner.text = `Waiting for authentication... (${message})`;
319
+ }
320
+ }
321
+ spinner.stop();
322
+ blank();
323
+ printError("Authentication timed out. Please try again.");
324
+ process.exit(1);
325
+ }
326
+ async function tokenLogin() {
327
+ console.log("Token login mode.");
328
+ console.log("Visit your Evident dashboard to generate a CLI token.");
329
+ blank();
330
+ process.stdout.write("Paste token: ");
331
+ const token = await new Promise((resolve) => {
332
+ let data = "";
333
+ process.stdin.setEncoding("utf8");
334
+ process.stdin.on("data", (chunk) => {
335
+ data += chunk;
336
+ });
337
+ process.stdin.on("end", () => {
338
+ resolve(data.trim());
339
+ });
340
+ if (process.stdin.isTTY) {
341
+ process.stdin.once("data", (chunk) => {
342
+ process.stdin.pause();
343
+ resolve(chunk.toString().trim());
344
+ });
345
+ process.stdin.resume();
346
+ }
347
+ });
348
+ if (!token) {
349
+ printError("No token provided.");
350
+ process.exit(1);
351
+ }
352
+ const spinner = ora("Validating token...").start();
353
+ try {
354
+ const result = await api.post("/auth/token/validate", { token });
355
+ await storeToken({
356
+ token,
357
+ user: result.user,
358
+ expiresAt: result.expires_at
359
+ });
360
+ spinner.stop();
361
+ printSuccess(`Logged in as ${chalk2.bold(result.user.email)}`);
362
+ } catch (error2) {
363
+ spinner.stop();
364
+ const message = error2 instanceof Error ? error2.message : "Invalid token";
365
+ printError(`Authentication failed: ${message}`);
366
+ process.exit(1);
367
+ }
368
+ }
369
+ async function login(options) {
370
+ if (options.token) {
371
+ await tokenLogin();
372
+ } else {
373
+ await deviceFlowLogin(options);
374
+ }
375
+ }
376
+
377
+ // src/commands/logout.ts
378
+ async function logout() {
379
+ const credentials2 = await getToken();
380
+ if (!credentials2) {
381
+ printWarning("You are not logged in.");
382
+ return;
383
+ }
384
+ await deleteToken();
385
+ printSuccess("Logged out successfully.");
386
+ }
387
+
388
+ // src/commands/whoami.ts
389
+ import chalk3 from "chalk";
390
+ async function whoami() {
391
+ const credentials2 = await getToken();
392
+ if (!credentials2) {
393
+ printError("Not logged in. Run `evident login` to authenticate.");
394
+ process.exit(1);
395
+ }
396
+ blank();
397
+ console.log(keyValue("User", chalk3.bold(credentials2.user.email)));
398
+ console.log(keyValue("User ID", credentials2.user.id));
399
+ if (credentials2.expiresAt) {
400
+ const expiresAt = new Date(credentials2.expiresAt);
401
+ const now = /* @__PURE__ */ new Date();
402
+ if (expiresAt < now) {
403
+ console.log(keyValue("Status", chalk3.red("Token expired")));
404
+ } else {
405
+ const daysRemaining = Math.ceil(
406
+ (expiresAt.getTime() - now.getTime()) / (1e3 * 60 * 60 * 24)
407
+ );
408
+ console.log(keyValue("Expires", `${daysRemaining} days`));
409
+ }
410
+ }
411
+ blank();
412
+ }
413
+
414
+ // src/commands/tunnel.ts
415
+ import WebSocket from "ws";
416
+ import chalk4 from "chalk";
417
+ import ora2 from "ora";
418
+ var MAX_RECONNECT_DELAY = 3e4;
419
+ var BASE_RECONNECT_DELAY = 500;
420
+ function getReconnectDelay(attempt) {
421
+ const exponentialDelay = BASE_RECONNECT_DELAY * Math.pow(2, attempt);
422
+ const jitter = Math.random() * 1e3;
423
+ return Math.min(exponentialDelay + jitter, MAX_RECONNECT_DELAY);
424
+ }
425
+ function displayStatus(state) {
426
+ console.clear();
427
+ console.log(chalk4.bold("Evident Tunnel"));
428
+ console.log(chalk4.dim("\u2500".repeat(50)));
429
+ blank();
430
+ if (state.connected) {
431
+ console.log(` ${chalk4.green("\u25CF")} Status: ${chalk4.green("Online")}`);
432
+ console.log(` Sandbox: ${state.sandboxId ?? "Unknown"}`);
433
+ console.log(` Last activity: ${state.lastActivity.toLocaleTimeString()}`);
434
+ } else {
435
+ console.log(` ${chalk4.yellow("\u25CB")} Status: ${chalk4.yellow("Reconnecting...")}`);
436
+ if (state.reconnectAttempt > 0) {
437
+ console.log(` Attempt: ${state.reconnectAttempt}`);
438
+ }
439
+ }
440
+ blank();
441
+ console.log(chalk4.dim("Press Ctrl+C to disconnect"));
442
+ }
443
+ async function forwardToOpenCode(port, request) {
444
+ const url = `http://localhost:${port}${request.path}`;
445
+ try {
446
+ const response = await fetch(url, {
447
+ method: request.method,
448
+ headers: {
449
+ "Content-Type": "application/json",
450
+ ...request.headers
451
+ },
452
+ body: request.body ? JSON.stringify(request.body) : void 0
453
+ });
454
+ let body;
455
+ const contentType = response.headers.get("Content-Type");
456
+ if (contentType?.includes("application/json")) {
457
+ body = await response.json();
458
+ } else {
459
+ body = await response.text();
460
+ }
461
+ return {
462
+ status: response.status,
463
+ body
464
+ };
465
+ } catch (error2) {
466
+ const message = error2 instanceof Error ? error2.message : "Unknown error";
467
+ return {
468
+ status: 502,
469
+ body: { error: "Failed to connect to OpenCode", message }
470
+ };
471
+ }
472
+ }
473
+ async function connect(token, sandboxId, port, state) {
474
+ const tunnelUrl = getTunnelUrlConfig();
475
+ const url = sandboxId ? `${tunnelUrl}/tunnel/${sandboxId}/connect` : `${tunnelUrl}/tunnel/default/connect`;
476
+ return new Promise((resolve, reject) => {
477
+ const ws = new WebSocket(url, {
478
+ headers: {
479
+ Authorization: `Bearer ${token}`
480
+ }
481
+ });
482
+ ws.on("open", () => {
483
+ state.connected = true;
484
+ state.reconnectAttempt = 0;
485
+ state.lastActivity = /* @__PURE__ */ new Date();
486
+ displayStatus(state);
487
+ });
488
+ ws.on("message", async (data) => {
489
+ try {
490
+ const message = JSON.parse(data.toString());
491
+ state.lastActivity = /* @__PURE__ */ new Date();
492
+ switch (message.type) {
493
+ case "connected":
494
+ state.sandboxId = message.sandbox_id ?? null;
495
+ displayStatus(state);
496
+ break;
497
+ case "error":
498
+ printError(`Tunnel error: ${message.message}`);
499
+ if (message.code === "unauthorized") {
500
+ ws.close();
501
+ reject(new Error("Unauthorized"));
502
+ }
503
+ break;
504
+ case "ping":
505
+ ws.send(JSON.stringify({ type: "pong" }));
506
+ break;
507
+ case "request":
508
+ if (message.id && message.payload) {
509
+ const response = await forwardToOpenCode(port, message.payload);
510
+ ws.send(
511
+ JSON.stringify({
512
+ type: "response",
513
+ id: message.id,
514
+ payload: response
515
+ })
516
+ );
517
+ displayStatus(state);
518
+ }
519
+ break;
520
+ }
521
+ } catch (error2) {
522
+ console.error("Failed to handle message:", error2);
523
+ }
524
+ });
525
+ ws.on("close", () => {
526
+ state.connected = false;
527
+ displayStatus(state);
528
+ resolve();
529
+ });
530
+ ws.on("error", (error2) => {
531
+ state.connected = false;
532
+ displayStatus(state);
533
+ console.error(chalk4.dim(`Connection error: ${error2.message}`));
534
+ });
535
+ const cleanup = () => {
536
+ ws.close();
537
+ process.exit(0);
538
+ };
539
+ process.on("SIGINT", cleanup);
540
+ process.on("SIGTERM", cleanup);
541
+ });
542
+ }
543
+ async function tunnel(options) {
544
+ const credentials2 = await getToken();
545
+ if (!credentials2) {
546
+ printError("Not logged in. Run `evident login` first.");
547
+ process.exit(1);
548
+ }
549
+ const port = options.port ?? 4096;
550
+ const sandboxId = options.sandbox;
551
+ const spinner = ora2("Checking OpenCode connection...").start();
552
+ try {
553
+ const response = await fetch(`http://localhost:${port}/health`);
554
+ if (!response.ok) {
555
+ throw new Error("Health check failed");
556
+ }
557
+ spinner.succeed(`OpenCode detected on port ${port}`);
558
+ } catch {
559
+ spinner.warn(`Could not connect to OpenCode on port ${port}`);
560
+ printWarning("Make sure OpenCode is running before starting the tunnel.");
561
+ blank();
562
+ }
563
+ const state = {
564
+ connected: false,
565
+ sandboxId: null,
566
+ reconnectAttempt: 0,
567
+ lastActivity: /* @__PURE__ */ new Date()
568
+ };
569
+ while (true) {
570
+ try {
571
+ await connect(credentials2.token, sandboxId, port, state);
572
+ state.reconnectAttempt++;
573
+ const delay = getReconnectDelay(state.reconnectAttempt);
574
+ displayStatus(state);
575
+ await sleep(delay);
576
+ } catch (error2) {
577
+ const message = error2 instanceof Error ? error2.message : "Unknown error";
578
+ if (message === "Unauthorized") {
579
+ printError("Authentication failed. Please run `evident login` again.");
580
+ process.exit(1);
581
+ }
582
+ state.reconnectAttempt++;
583
+ const delay = getReconnectDelay(state.reconnectAttempt);
584
+ await sleep(delay);
585
+ }
586
+ }
587
+ }
588
+
589
+ // src/index.ts
590
+ var program = new Command();
591
+ program.name("evident").description("Run OpenCode locally and connect it to Evident").version("0.1.0").option("-e, --env <environment>", "Environment to use (local, dev, production)", "production").hook("preAction", (thisCommand) => {
592
+ const env = thisCommand.opts().env;
593
+ if (env) {
594
+ setEnvironment(env);
595
+ }
596
+ });
597
+ 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);
598
+ program.command("logout").description("Remove stored credentials").action(logout);
599
+ program.command("whoami").description("Show the currently logged in user").action(whoami);
600
+ program.command("tunnel").description("Establish a tunnel to Evident for Local Mode").option("-s, --sandbox <id>", "Sandbox ID to connect to").option("-p, --port <port>", "OpenCode port (default: 4096)", "4096").action((options) => {
601
+ tunnel({
602
+ sandbox: options.sandbox,
603
+ port: parseInt(options.port, 10)
604
+ });
605
+ });
606
+ program.parse();
607
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/commands/login.ts","../src/lib/config.ts","../src/lib/api.ts","../src/lib/keychain.ts","../src/utils/ui.ts","../src/commands/logout.ts","../src/commands/whoami.ts","../src/commands/tunnel.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * Evident CLI\n *\n * Run OpenCode locally and connect it to the Evident platform.\n */\n\nimport { Command } from 'commander';\nimport { login } from './commands/login.js';\nimport { logout } from './commands/logout.js';\nimport { whoami } from './commands/whoami.js';\nimport { tunnel } from './commands/tunnel.js';\nimport { setEnvironment, type Environment } from './lib/config.js';\n\nconst program = new Command();\n\nprogram\n .name('evident')\n .description('Run OpenCode locally and connect it to Evident')\n .version('0.1.0')\n .option('-e, --env <environment>', 'Environment to use (local, dev, production)', 'production')\n .hook('preAction', (thisCommand) => {\n const env = thisCommand.opts().env as Environment;\n if (env) {\n setEnvironment(env);\n }\n });\n\n// Login command\nprogram\n .command('login')\n .description('Authenticate with Evident')\n .option('--token', 'Use token-based authentication (for CI/CD)')\n .option('--no-browser', 'Do not open the browser automatically')\n .action(login);\n\n// Logout command\nprogram.command('logout').description('Remove stored credentials').action(logout);\n\n// Whoami command\nprogram.command('whoami').description('Show the currently logged in user').action(whoami);\n\n// Tunnel command\nprogram\n .command('tunnel')\n .description('Establish a tunnel to Evident for Local Mode')\n .option('-s, --sandbox <id>', 'Sandbox ID to connect to')\n .option('-p, --port <port>', 'OpenCode port (default: 4096)', '4096')\n .action((options: { sandbox?: string; port: string }) => {\n tunnel({\n sandbox: options.sandbox,\n port: parseInt(options.port, 10),\n });\n });\n\n// Parse arguments\nprogram.parse();\n","/**\n * Login Command\n *\n * Authenticates the user using OAuth Device Flow.\n * See ADR-0018 for details.\n */\n\nimport open from 'open';\nimport ora from 'ora';\nimport chalk from 'chalk';\nimport { api } from '../lib/api.js';\nimport { storeToken } from '../lib/keychain.js';\nimport { printSuccess, printError, blank, waitForEnter, sleep } from '../utils/ui.js';\n\ninterface DeviceAuthResponse {\n device_code: string;\n user_code: string;\n verification_uri: string;\n expires_in: number;\n interval: number;\n}\n\ninterface TokenPollResponse {\n status: 'pending' | 'complete' | 'expired';\n access_token?: string;\n expires_at?: string;\n user?: {\n id: string;\n email: string;\n };\n}\n\ninterface LoginOptions {\n token?: boolean;\n noBrowser?: boolean;\n}\n\n/**\n * Start device flow authentication\n */\nasync function deviceFlowLogin(options: LoginOptions): Promise<void> {\n // Step 1: Request device code\n let deviceAuth: DeviceAuthResponse;\n try {\n deviceAuth = await api.post<DeviceAuthResponse>('/auth/device');\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n printError(`Failed to start authentication: ${message}`);\n process.exit(1);\n }\n\n const { device_code, user_code, verification_uri, interval } = deviceAuth;\n\n // Step 2: Display instructions\n blank();\n console.log(chalk.bold('To authenticate, visit:'));\n console.log();\n console.log(` ${chalk.cyan(verification_uri)}`);\n console.log();\n console.log(chalk.bold('And enter this code:'));\n console.log();\n console.log(` ${chalk.yellow.bold(user_code)}`);\n blank();\n\n // Step 3: Open browser (unless --no-browser)\n if (!options.noBrowser) {\n await waitForEnter('Press Enter to open the browser...');\n try {\n await open(verification_uri);\n } catch {\n console.log(chalk.dim('Could not open browser. Please visit the URL manually.'));\n }\n }\n\n // Step 4: Poll for completion\n const spinner = ora('Waiting for authentication...').start();\n\n const pollIntervalMs = (interval || 5) * 1000;\n const maxAttempts = 60; // 5 minutes max at 5s intervals\n let attempts = 0;\n\n while (attempts < maxAttempts) {\n await sleep(pollIntervalMs);\n attempts++;\n\n try {\n const result = await api.post<TokenPollResponse>('/auth/device/token', {\n device_code,\n });\n\n if (result.status === 'complete' && result.access_token && result.user) {\n // Success! Store the token\n await storeToken({\n token: result.access_token,\n user: result.user,\n expiresAt: result.expires_at,\n });\n\n spinner.stop();\n blank();\n printSuccess(`Logged in as ${chalk.bold(result.user.email)}`);\n return;\n }\n\n if (result.status === 'expired') {\n spinner.stop();\n blank();\n printError('Authentication expired. Please try again.');\n process.exit(1);\n }\n\n // Still pending, continue polling\n } catch (error) {\n // Network error, continue polling\n const message = error instanceof Error ? error.message : 'Unknown error';\n spinner.text = `Waiting for authentication... (${message})`;\n }\n }\n\n spinner.stop();\n blank();\n printError('Authentication timed out. Please try again.');\n process.exit(1);\n}\n\n/**\n * Token-based login (for CI/CD)\n */\nasync function tokenLogin(): Promise<void> {\n console.log('Token login mode.');\n console.log('Visit your Evident dashboard to generate a CLI token.');\n blank();\n\n // Read token from stdin\n process.stdout.write('Paste token: ');\n\n const token = await new Promise<string>((resolve) => {\n let data = '';\n process.stdin.setEncoding('utf8');\n process.stdin.on('data', (chunk) => {\n data += chunk;\n });\n process.stdin.on('end', () => {\n resolve(data.trim());\n });\n // For TTY, read a single line\n if (process.stdin.isTTY) {\n process.stdin.once('data', (chunk) => {\n process.stdin.pause();\n resolve(chunk.toString().trim());\n });\n process.stdin.resume();\n }\n });\n\n if (!token) {\n printError('No token provided.');\n process.exit(1);\n }\n\n // Validate the token\n const spinner = ora('Validating token...').start();\n\n try {\n interface ValidateResponse {\n user: { id: string; email: string };\n expires_at?: string;\n }\n\n const result = await api.post<ValidateResponse>('/auth/token/validate', { token });\n\n await storeToken({\n token,\n user: result.user,\n expiresAt: result.expires_at,\n });\n\n spinner.stop();\n printSuccess(`Logged in as ${chalk.bold(result.user.email)}`);\n } catch (error) {\n spinner.stop();\n const message = error instanceof Error ? error.message : 'Invalid token';\n printError(`Authentication failed: ${message}`);\n process.exit(1);\n }\n}\n\n/**\n * Login command handler\n */\nexport async function login(options: LoginOptions): Promise<void> {\n if (options.token) {\n await tokenLogin();\n } else {\n await deviceFlowLogin(options);\n }\n}\n","/**\n * CLI Configuration\n *\n * Manages configuration values and file-based credential storage.\n * Supports multiple environments: local, dev, production\n */\n\nimport Conf from 'conf';\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\n\n// Supported environments\nexport type Environment = 'local' | 'dev' | 'production';\n\n// Configuration schema\ninterface ConfigSchema {\n apiUrl: string;\n tunnelUrl: string;\n}\n\n// Credentials schema (stored separately with stricter permissions)\ninterface CredentialsSchema {\n token?: string;\n user?: {\n id: string;\n email: string;\n };\n expiresAt?: string;\n}\n\n// Environment presets\n// Domain format: {service}.{env}.evident.run (with aliases for production)\nconst environmentPresets: Record<Environment, ConfigSchema> = {\n local: {\n apiUrl: 'http://localhost:3000',\n tunnelUrl: 'ws://localhost:8787',\n },\n dev: {\n apiUrl: 'https://api.dev.evident.run',\n tunnelUrl: 'wss://tunnel.dev.evident.run',\n },\n production: {\n // Production URLs also have aliases: api.evident.run, tunnel.evident.run\n apiUrl: 'https://api.production.evident.run',\n tunnelUrl: 'wss://tunnel.production.evident.run',\n },\n};\n\n// Default to production\nconst defaults: ConfigSchema = environmentPresets.production;\n\n// Current environment (can be set via --env flag or EVIDENT_ENV)\nlet currentEnvironment: Environment = 'production';\n\n/**\n * Set the current environment\n */\nexport function setEnvironment(env: Environment): void {\n currentEnvironment = env;\n}\n\n/**\n * Get the current environment\n */\nexport function getEnvironment(): Environment {\n // Environment variable takes precedence\n const envVar = process.env.EVIDENT_ENV as Environment | undefined;\n if (envVar && environmentPresets[envVar]) {\n return envVar;\n }\n return currentEnvironment;\n}\n\n/**\n * Get configuration for current environment\n */\nfunction getEnvConfig(): ConfigSchema {\n return environmentPresets[getEnvironment()];\n}\n\n// Environment overrides (env vars take highest precedence)\nfunction getApiUrl(): string {\n return process.env.EVIDENT_API_URL ?? getEnvConfig().apiUrl;\n}\n\nfunction getTunnelUrl(): string {\n return process.env.EVIDENT_TUNNEL_URL ?? getEnvConfig().tunnelUrl;\n}\n\n// Configuration store\nconst config = new Conf<ConfigSchema>({\n projectName: 'evident',\n projectSuffix: '',\n defaults,\n});\n\n// Credentials store (separate file with restricted access)\nconst credentials = new Conf<CredentialsSchema>({\n projectName: 'evident',\n projectSuffix: '',\n configName: 'credentials',\n defaults: {},\n});\n\n/**\n * Get the configuration directory path\n */\nexport function getConfigDir(): string {\n // XDG_CONFIG_HOME on Linux, ~/.config on others\n const xdgConfig = process.env.XDG_CONFIG_HOME;\n if (xdgConfig) {\n return join(xdgConfig, 'evident');\n }\n return join(homedir(), '.config', 'evident');\n}\n\n/**\n * Get the API URL\n */\nexport function getApiUrlConfig(): string {\n return getApiUrl();\n}\n\n/**\n * Get the tunnel WebSocket URL\n */\nexport function getTunnelUrlConfig(): string {\n return getTunnelUrl();\n}\n\n/**\n * Get stored credentials\n */\nexport function getCredentials(): CredentialsSchema {\n return {\n token: credentials.get('token'),\n user: credentials.get('user'),\n expiresAt: credentials.get('expiresAt'),\n };\n}\n\n/**\n * Store credentials\n */\nexport function setCredentials(creds: CredentialsSchema): void {\n if (creds.token) credentials.set('token', creds.token);\n if (creds.user) credentials.set('user', creds.user);\n if (creds.expiresAt) credentials.set('expiresAt', creds.expiresAt);\n}\n\n/**\n * Clear stored credentials\n */\nexport function clearCredentials(): void {\n credentials.clear();\n}\n\n/**\n * Check if we have valid credentials\n */\nexport function hasValidCredentials(): boolean {\n const creds = getCredentials();\n\n if (!creds.token) {\n return false;\n }\n\n if (creds.expiresAt) {\n const expiresAt = new Date(creds.expiresAt);\n if (expiresAt < new Date()) {\n return false;\n }\n }\n\n return true;\n}\n\nexport { config, credentials };\n","/**\n * API Client\n *\n * Handles HTTP requests to the Evident backend API.\n */\n\nimport { getApiUrlConfig, getCredentials } from './config.js';\n\ninterface ApiRequestOptions {\n method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n body?: unknown;\n headers?: Record<string, string>;\n authenticated?: boolean;\n}\n\ninterface ApiError {\n message: string;\n statusCode: number;\n error?: string;\n}\n\nexport class ApiClient {\n private baseUrl: string;\n\n constructor(baseUrl?: string) {\n this.baseUrl = baseUrl ?? getApiUrlConfig();\n }\n\n /**\n * Make an API request\n */\n async request<T>(path: string, options: ApiRequestOptions = {}): Promise<T> {\n const { method = 'GET', body, headers = {}, authenticated = false } = options;\n\n const url = `${this.baseUrl}${path}`;\n\n const requestHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...headers,\n };\n\n // Add authentication header if requested\n if (authenticated) {\n const creds = getCredentials();\n if (!creds.token) {\n throw new Error('Not authenticated. Run `evident login` first.');\n }\n requestHeaders['Authorization'] = `Bearer ${creds.token}`;\n }\n\n const response = await fetch(url, {\n method,\n headers: requestHeaders,\n body: body ? JSON.stringify(body) : undefined,\n });\n\n // Handle errors\n if (!response.ok) {\n let errorData: ApiError;\n try {\n errorData = (await response.json()) as ApiError;\n } catch {\n errorData = {\n message: response.statusText,\n statusCode: response.status,\n };\n }\n\n const error = new Error(errorData.message) as Error & { statusCode: number };\n error.statusCode = response.status;\n throw error;\n }\n\n // Handle empty responses\n const contentType = response.headers.get('Content-Type');\n if (!contentType?.includes('application/json')) {\n return {} as T;\n }\n\n return response.json() as Promise<T>;\n }\n\n /**\n * GET request\n */\n async get<T>(path: string, options: Omit<ApiRequestOptions, 'method' | 'body'> = {}): Promise<T> {\n return this.request<T>(path, { ...options, method: 'GET' });\n }\n\n /**\n * POST request\n */\n async post<T>(\n path: string,\n body?: unknown,\n options: Omit<ApiRequestOptions, 'method'> = {},\n ): Promise<T> {\n return this.request<T>(path, { ...options, method: 'POST', body });\n }\n\n /**\n * PUT request\n */\n async put<T>(\n path: string,\n body?: unknown,\n options: Omit<ApiRequestOptions, 'method'> = {},\n ): Promise<T> {\n return this.request<T>(path, { ...options, method: 'PUT', body });\n }\n\n /**\n * DELETE request\n */\n async delete<T>(\n path: string,\n options: Omit<ApiRequestOptions, 'method' | 'body'> = {},\n ): Promise<T> {\n return this.request<T>(path, { ...options, method: 'DELETE' });\n }\n}\n\n// Default API client instance\nexport const api = new ApiClient();\n","/**\n * Keychain Storage\n *\n * Provides secure credential storage using the system keychain.\n * Falls back to file-based storage if keychain is unavailable.\n */\n\nimport { getCredentials, setCredentials, clearCredentials } from './config.js';\n\nconst SERVICE_NAME = 'evident-cli';\nconst ACCOUNT_NAME = 'default';\n\n// Dynamic import for keytar (optional dependency)\nasync function getKeytar(): Promise<typeof import('keytar') | null> {\n try {\n return await import('keytar');\n } catch {\n // keytar not available (e.g., missing native dependencies)\n return null;\n }\n}\n\nexport interface StoredCredentials {\n token: string;\n user: {\n id: string;\n email: string;\n };\n expiresAt?: string;\n}\n\n/**\n * Store credentials in the system keychain\n */\nexport async function storeToken(credentials: StoredCredentials): Promise<void> {\n const keytar = await getKeytar();\n\n if (keytar) {\n // Store in system keychain\n await keytar.setPassword(SERVICE_NAME, ACCOUNT_NAME, JSON.stringify(credentials));\n } else {\n // Fallback to file-based storage\n setCredentials({\n token: credentials.token,\n user: credentials.user,\n expiresAt: credentials.expiresAt,\n });\n }\n}\n\n/**\n * Retrieve credentials from the system keychain\n */\nexport async function getToken(): Promise<StoredCredentials | null> {\n const keytar = await getKeytar();\n\n if (keytar) {\n // Try system keychain first\n const stored = await keytar.getPassword(SERVICE_NAME, ACCOUNT_NAME);\n if (stored) {\n try {\n return JSON.parse(stored) as StoredCredentials;\n } catch {\n // Invalid JSON, clear it\n await keytar.deletePassword(SERVICE_NAME, ACCOUNT_NAME);\n return null;\n }\n }\n }\n\n // Fallback to file-based storage\n const creds = getCredentials();\n if (creds.token && creds.user) {\n return {\n token: creds.token,\n user: creds.user,\n expiresAt: creds.expiresAt,\n };\n }\n\n return null;\n}\n\n/**\n * Delete credentials from the system keychain\n */\nexport async function deleteToken(): Promise<void> {\n const keytar = await getKeytar();\n\n if (keytar) {\n await keytar.deletePassword(SERVICE_NAME, ACCOUNT_NAME);\n }\n\n // Always clear file-based storage too\n clearCredentials();\n}\n\n/**\n * Check if credentials are valid (not expired)\n */\nexport async function hasValidToken(): Promise<boolean> {\n const credentials = await getToken();\n\n if (!credentials) {\n return false;\n }\n\n if (credentials.expiresAt) {\n const expiresAt = new Date(credentials.expiresAt);\n if (expiresAt < new Date()) {\n return false;\n }\n }\n\n return true;\n}\n","/**\n * CLI UI Utilities\n *\n * Common formatting and display functions.\n */\n\nimport chalk from 'chalk';\n\n/**\n * Format success message\n */\nexport function success(message: string): string {\n return `${chalk.green('✓')} ${message}`;\n}\n\n/**\n * Format error message\n */\nexport function error(message: string): string {\n return `${chalk.red('✗')} ${message}`;\n}\n\n/**\n * Format warning message\n */\nexport function warning(message: string): string {\n return `${chalk.yellow('!')} ${message}`;\n}\n\n/**\n * Format info message\n */\nexport function info(message: string): string {\n return `${chalk.blue('i')} ${message}`;\n}\n\n/**\n * Print success message\n */\nexport function printSuccess(message: string): void {\n console.log(success(message));\n}\n\n/**\n * Print error message\n */\nexport function printError(message: string): void {\n console.error(error(message));\n}\n\n/**\n * Print warning message\n */\nexport function printWarning(message: string): void {\n console.log(warning(message));\n}\n\n/**\n * Print info message\n */\nexport function printInfo(message: string): void {\n console.log(info(message));\n}\n\n/**\n * Format a key-value pair for display\n */\nexport function keyValue(key: string, value: string): string {\n return `${chalk.dim(key + ':')} ${value}`;\n}\n\n/**\n * Print a blank line\n */\nexport function blank(): void {\n console.log();\n}\n\n/**\n * Wait for user to press Enter\n */\nexport function waitForEnter(prompt = 'Press Enter to continue...'): Promise<void> {\n return new Promise((resolve) => {\n process.stdout.write(chalk.dim(prompt));\n\n const handler = (): void => {\n process.stdin.removeListener('data', handler);\n process.stdin.setRawMode?.(false);\n process.stdin.pause();\n console.log();\n resolve();\n };\n\n if (process.stdin.isTTY) {\n process.stdin.setRawMode?.(true);\n }\n process.stdin.resume();\n process.stdin.once('data', handler);\n });\n}\n\n/**\n * Sleep for a given number of milliseconds\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","/**\n * Logout Command\n *\n * Removes stored credentials.\n */\n\nimport { deleteToken, getToken } from '../lib/keychain.js';\nimport { printSuccess, printWarning } from '../utils/ui.js';\n\n/**\n * Logout command handler\n */\nexport async function logout(): Promise<void> {\n const credentials = await getToken();\n\n if (!credentials) {\n printWarning('You are not logged in.');\n return;\n }\n\n await deleteToken();\n printSuccess('Logged out successfully.');\n}\n","/**\n * Whoami Command\n *\n * Displays the currently logged in user.\n */\n\nimport chalk from 'chalk';\nimport { getToken } from '../lib/keychain.js';\nimport { printError, keyValue, blank } from '../utils/ui.js';\n\n/**\n * Whoami command handler\n */\nexport async function whoami(): Promise<void> {\n const credentials = await getToken();\n\n if (!credentials) {\n printError('Not logged in. Run `evident login` to authenticate.');\n process.exit(1);\n }\n\n blank();\n console.log(keyValue('User', chalk.bold(credentials.user.email)));\n console.log(keyValue('User ID', credentials.user.id));\n\n if (credentials.expiresAt) {\n const expiresAt = new Date(credentials.expiresAt);\n const now = new Date();\n\n if (expiresAt < now) {\n console.log(keyValue('Status', chalk.red('Token expired')));\n } else {\n const daysRemaining = Math.ceil(\n (expiresAt.getTime() - now.getTime()) / (1000 * 60 * 60 * 24),\n );\n console.log(keyValue('Expires', `${daysRemaining} days`));\n }\n }\n\n blank();\n}\n","/**\n * Tunnel Command\n *\n * Establishes a WebSocket tunnel to Evident for Local Mode.\n * See ADR-0020 for architecture details.\n */\n\nimport WebSocket from 'ws';\nimport chalk from 'chalk';\nimport ora from 'ora';\nimport { getToken } from '../lib/keychain.js';\nimport { getTunnelUrlConfig } from '../lib/config.js';\nimport { printError, printWarning, blank, sleep } from '../utils/ui.js';\n\ninterface TunnelOptions {\n sandbox?: string;\n port?: number;\n}\n\ninterface RelayMessage {\n type: 'connected' | 'error' | 'ping' | 'request';\n sandbox_id?: string;\n code?: string;\n message?: string;\n id?: string;\n payload?: {\n method: string;\n path: string;\n headers?: Record<string, string>;\n body?: unknown;\n };\n}\n\ninterface TunnelState {\n connected: boolean;\n sandboxId: string | null;\n reconnectAttempt: number;\n lastActivity: Date;\n}\n\nconst MAX_RECONNECT_DELAY = 30000; // 30 seconds\nconst BASE_RECONNECT_DELAY = 500; // 0.5 seconds\n\n/**\n * Calculate reconnect delay with exponential backoff and jitter\n */\nfunction getReconnectDelay(attempt: number): number {\n const exponentialDelay = BASE_RECONNECT_DELAY * Math.pow(2, attempt);\n const jitter = Math.random() * 1000;\n return Math.min(exponentialDelay + jitter, MAX_RECONNECT_DELAY);\n}\n\n/**\n * Display tunnel status\n */\nfunction displayStatus(state: TunnelState): void {\n console.clear();\n console.log(chalk.bold('Evident Tunnel'));\n console.log(chalk.dim('─'.repeat(50)));\n blank();\n\n if (state.connected) {\n console.log(` ${chalk.green('●')} Status: ${chalk.green('Online')}`);\n console.log(` Sandbox: ${state.sandboxId ?? 'Unknown'}`);\n console.log(` Last activity: ${state.lastActivity.toLocaleTimeString()}`);\n } else {\n console.log(` ${chalk.yellow('○')} Status: ${chalk.yellow('Reconnecting...')}`);\n if (state.reconnectAttempt > 0) {\n console.log(` Attempt: ${state.reconnectAttempt}`);\n }\n }\n\n blank();\n console.log(chalk.dim('Press Ctrl+C to disconnect'));\n}\n\n/**\n * Forward request to local OpenCode instance\n */\nasync function forwardToOpenCode(\n port: number,\n request: { method: string; path: string; headers?: Record<string, string>; body?: unknown },\n): Promise<{ status: number; headers?: Record<string, string>; body?: unknown }> {\n const url = `http://localhost:${port}${request.path}`;\n\n try {\n const response = await fetch(url, {\n method: request.method,\n headers: {\n 'Content-Type': 'application/json',\n ...request.headers,\n },\n body: request.body ? JSON.stringify(request.body) : undefined,\n });\n\n let body: unknown;\n const contentType = response.headers.get('Content-Type');\n if (contentType?.includes('application/json')) {\n body = await response.json();\n } else {\n body = await response.text();\n }\n\n return {\n status: response.status,\n body,\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n return {\n status: 502,\n body: { error: 'Failed to connect to OpenCode', message },\n };\n }\n}\n\n/**\n * Establish tunnel connection\n */\nasync function connect(\n token: string,\n sandboxId: string | undefined,\n port: number,\n state: TunnelState,\n): Promise<void> {\n const tunnelUrl = getTunnelUrlConfig();\n const url = sandboxId\n ? `${tunnelUrl}/tunnel/${sandboxId}/connect`\n : `${tunnelUrl}/tunnel/default/connect`;\n\n return new Promise((resolve, reject) => {\n const ws = new WebSocket(url, {\n headers: {\n Authorization: `Bearer ${token}`,\n },\n });\n\n ws.on('open', () => {\n state.connected = true;\n state.reconnectAttempt = 0;\n state.lastActivity = new Date();\n displayStatus(state);\n });\n\n ws.on('message', async (data: WebSocket.RawData) => {\n try {\n const message: RelayMessage = JSON.parse(data.toString());\n state.lastActivity = new Date();\n\n switch (message.type) {\n case 'connected':\n state.sandboxId = message.sandbox_id ?? null;\n displayStatus(state);\n break;\n\n case 'error':\n printError(`Tunnel error: ${message.message}`);\n if (message.code === 'unauthorized') {\n ws.close();\n reject(new Error('Unauthorized'));\n }\n break;\n\n case 'ping':\n ws.send(JSON.stringify({ type: 'pong' }));\n break;\n\n case 'request':\n if (message.id && message.payload) {\n const response = await forwardToOpenCode(port, message.payload);\n ws.send(\n JSON.stringify({\n type: 'response',\n id: message.id,\n payload: response,\n }),\n );\n displayStatus(state);\n }\n break;\n }\n } catch (error) {\n console.error('Failed to handle message:', error);\n }\n });\n\n ws.on('close', () => {\n state.connected = false;\n displayStatus(state);\n resolve();\n });\n\n ws.on('error', (error: Error) => {\n state.connected = false;\n displayStatus(state);\n // Don't reject on connection errors, let it reconnect\n console.error(chalk.dim(`Connection error: ${error.message}`));\n });\n\n // Handle Ctrl+C\n const cleanup = (): void => {\n ws.close();\n process.exit(0);\n };\n process.on('SIGINT', cleanup);\n process.on('SIGTERM', cleanup);\n });\n}\n\n/**\n * Tunnel command handler\n */\nexport async function tunnel(options: TunnelOptions): Promise<void> {\n // Get credentials\n const credentials = await getToken();\n if (!credentials) {\n printError('Not logged in. Run `evident login` first.');\n process.exit(1);\n }\n\n const port = options.port ?? 4096;\n const sandboxId = options.sandbox;\n\n // Check if OpenCode is running\n const spinner = ora('Checking OpenCode connection...').start();\n\n try {\n const response = await fetch(`http://localhost:${port}/health`);\n if (!response.ok) {\n throw new Error('Health check failed');\n }\n spinner.succeed(`OpenCode detected on port ${port}`);\n } catch {\n spinner.warn(`Could not connect to OpenCode on port ${port}`);\n printWarning('Make sure OpenCode is running before starting the tunnel.');\n blank();\n }\n\n // Connection state\n const state: TunnelState = {\n connected: false,\n sandboxId: null,\n reconnectAttempt: 0,\n lastActivity: new Date(),\n };\n\n // Reconnection loop\n while (true) {\n try {\n await connect(credentials.token, sandboxId, port, state);\n\n // Connection closed, attempt reconnect\n state.reconnectAttempt++;\n const delay = getReconnectDelay(state.reconnectAttempt);\n\n displayStatus(state);\n await sleep(delay);\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n\n if (message === 'Unauthorized') {\n printError('Authentication failed. Please run `evident login` again.');\n process.exit(1);\n }\n\n state.reconnectAttempt++;\n const delay = getReconnectDelay(state.reconnectAttempt);\n await sleep(delay);\n }\n }\n}\n"],"mappings":";;;;AAOA,SAAS,eAAe;;;ACAxB,OAAO,UAAU;AACjB,OAAO,SAAS;AAChB,OAAOA,YAAW;;;ACFlB,OAAO,UAAU;AACjB,SAAS,eAAe;AACxB,SAAS,YAAY;AAuBrB,IAAM,qBAAwD;AAAA,EAC5D,OAAO;AAAA,IACL,QAAQ;AAAA,IACR,WAAW;AAAA,EACb;AAAA,EACA,KAAK;AAAA,IACH,QAAQ;AAAA,IACR,WAAW;AAAA,EACb;AAAA,EACA,YAAY;AAAA;AAAA,IAEV,QAAQ;AAAA,IACR,WAAW;AAAA,EACb;AACF;AAGA,IAAM,WAAyB,mBAAmB;AAGlD,IAAI,qBAAkC;AAK/B,SAAS,eAAe,KAAwB;AACrD,uBAAqB;AACvB;AAKO,SAAS,iBAA8B;AAE5C,QAAM,SAAS,QAAQ,IAAI;AAC3B,MAAI,UAAU,mBAAmB,MAAM,GAAG;AACxC,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAKA,SAAS,eAA6B;AACpC,SAAO,mBAAmB,eAAe,CAAC;AAC5C;AAGA,SAAS,YAAoB;AAC3B,SAAO,QAAQ,IAAI,mBAAmB,aAAa,EAAE;AACvD;AAEA,SAAS,eAAuB;AAC9B,SAAO,QAAQ,IAAI,sBAAsB,aAAa,EAAE;AAC1D;AAGA,IAAM,SAAS,IAAI,KAAmB;AAAA,EACpC,aAAa;AAAA,EACb,eAAe;AAAA,EACf;AACF,CAAC;AAGD,IAAM,cAAc,IAAI,KAAwB;AAAA,EAC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;","names":["chalk","error","credentials","error","chalk","credentials","chalk","credentials","chalk","chalk","ora","chalk","error","credentials","ora"]}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@evident-ai/cli",
3
+ "version": "0.1.0",
4
+ "description": "Evident CLI - Run OpenCode locally and connect to Evident",
5
+ "type": "module",
6
+ "bin": {
7
+ "evident": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsup",
14
+ "dev": "tsup --watch",
15
+ "start": "node dist/index.js",
16
+ "start:local": "EVIDENT_ENV=local node dist/index.js",
17
+ "start:dev": "EVIDENT_ENV=dev node dist/index.js",
18
+ "typecheck": "tsc --noEmit",
19
+ "lint": "eslint src"
20
+ },
21
+ "dependencies": {
22
+ "chalk": "^5.4.1",
23
+ "commander": "^13.1.0",
24
+ "conf": "^13.1.0",
25
+ "keytar": "^7.9.0",
26
+ "open": "^10.1.0",
27
+ "ora": "^8.1.1",
28
+ "ws": "^8.18.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^22.10.5",
32
+ "@types/ws": "^8.5.13",
33
+ "tsup": "^8.3.5",
34
+ "typescript": "^5.7.2"
35
+ },
36
+ "engines": {
37
+ "node": ">=20"
38
+ },
39
+ "keywords": [
40
+ "evident",
41
+ "opencode",
42
+ "cli",
43
+ "ai",
44
+ "coding-assistant"
45
+ ],
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/sroze/connected.git",
49
+ "directory": "apps/cli"
50
+ },
51
+ "homepage": "https://evident.run",
52
+ "author": "Evident <hello@evident.run>",
53
+ "license": "MIT"
54
+ }