episoda 0.2.12 → 0.2.14

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.
@@ -1646,9 +1646,19 @@ var require_version = __commonJS({
1646
1646
  exports2.VERSION = void 0;
1647
1647
  var fs_1 = require("fs");
1648
1648
  var path_1 = require("path");
1649
- var packageJsonPath = (0, path_1.join)(__dirname, "..", "package.json");
1650
- var packageJson2 = JSON.parse((0, fs_1.readFileSync)(packageJsonPath, "utf-8"));
1651
- exports2.VERSION = packageJson2.version;
1649
+ var FALLBACK_VERSION = "0.1.11";
1650
+ function getVersion() {
1651
+ try {
1652
+ const packageJsonPath = (0, path_1.join)(__dirname, "..", "package.json");
1653
+ if ((0, fs_1.existsSync)(packageJsonPath)) {
1654
+ const packageJson2 = JSON.parse((0, fs_1.readFileSync)(packageJsonPath, "utf-8"));
1655
+ return packageJson2.version;
1656
+ }
1657
+ } catch {
1658
+ }
1659
+ return FALLBACK_VERSION;
1660
+ }
1661
+ exports2.VERSION = getVersion();
1652
1662
  }
1653
1663
  });
1654
1664
 
@@ -1817,6 +1827,32 @@ var require_websocket_client = __commonJS({
1817
1827
  }
1818
1828
  this.eventHandlers.get(event).push(handler);
1819
1829
  }
1830
+ /**
1831
+ * EP812: Register a one-time event handler (removes itself after first call)
1832
+ * @param event - Event type
1833
+ * @param handler - Handler function
1834
+ */
1835
+ once(event, handler) {
1836
+ const onceHandler = (message) => {
1837
+ this.off(event, onceHandler);
1838
+ handler(message);
1839
+ };
1840
+ this.on(event, onceHandler);
1841
+ }
1842
+ /**
1843
+ * EP812: Remove an event handler
1844
+ * @param event - Event type
1845
+ * @param handler - Handler function to remove
1846
+ */
1847
+ off(event, handler) {
1848
+ const handlers = this.eventHandlers.get(event);
1849
+ if (handlers) {
1850
+ const index = handlers.indexOf(handler);
1851
+ if (index !== -1) {
1852
+ handlers.splice(index, 1);
1853
+ }
1854
+ }
1855
+ }
1820
1856
  /**
1821
1857
  * Send a message to the server
1822
1858
  * @param message - Client message to send
@@ -2228,7 +2264,7 @@ var require_package = __commonJS({
2228
2264
  "package.json"(exports2, module2) {
2229
2265
  module2.exports = {
2230
2266
  name: "episoda",
2231
- version: "0.2.11",
2267
+ version: "0.2.13",
2232
2268
  description: "CLI tool for Episoda local development workflow orchestration",
2233
2269
  main: "dist/index.js",
2234
2270
  types: "dist/index.d.ts",
@@ -3437,6 +3473,23 @@ var Daemon = class {
3437
3473
  } catch (pidError) {
3438
3474
  console.warn(`[Daemon] Could not read daemon PID:`, pidError instanceof Error ? pidError.message : pidError);
3439
3475
  }
3476
+ const authSuccessPromise = new Promise((resolve2, reject) => {
3477
+ const AUTH_TIMEOUT = 1e4;
3478
+ const timeout = setTimeout(() => {
3479
+ reject(new Error("Authentication timeout - server did not respond with auth_success"));
3480
+ }, AUTH_TIMEOUT);
3481
+ const authHandler = () => {
3482
+ clearTimeout(timeout);
3483
+ resolve2();
3484
+ };
3485
+ client.once("auth_success", authHandler);
3486
+ const errorHandler = (message) => {
3487
+ clearTimeout(timeout);
3488
+ const errorMsg = message;
3489
+ reject(new Error(errorMsg.message || "Authentication failed"));
3490
+ };
3491
+ client.once("auth_error", errorHandler);
3492
+ });
3440
3493
  await client.connect(wsUrl, config.access_token, this.machineId, {
3441
3494
  hostname: os.hostname(),
3442
3495
  osPlatform: os.platform(),
@@ -3444,6 +3497,8 @@ var Daemon = class {
3444
3497
  daemonPid
3445
3498
  });
3446
3499
  console.log(`[Daemon] Successfully connected to project ${projectId}`);
3500
+ await authSuccessPromise;
3501
+ console.log(`[Daemon] Authentication complete for project ${projectId}`);
3447
3502
  } catch (error) {
3448
3503
  console.error(`[Daemon] Failed to connect to ${projectId}:`, error);
3449
3504
  this.connections.delete(projectPath);