episoda 0.2.13 → 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.
@@ -1827,6 +1827,32 @@ var require_websocket_client = __commonJS({
1827
1827
  }
1828
1828
  this.eventHandlers.get(event).push(handler);
1829
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
+ }
1830
1856
  /**
1831
1857
  * Send a message to the server
1832
1858
  * @param message - Client message to send
@@ -2238,7 +2264,7 @@ var require_package = __commonJS({
2238
2264
  "package.json"(exports2, module2) {
2239
2265
  module2.exports = {
2240
2266
  name: "episoda",
2241
- version: "0.2.12",
2267
+ version: "0.2.13",
2242
2268
  description: "CLI tool for Episoda local development workflow orchestration",
2243
2269
  main: "dist/index.js",
2244
2270
  types: "dist/index.d.ts",
@@ -3447,6 +3473,23 @@ var Daemon = class {
3447
3473
  } catch (pidError) {
3448
3474
  console.warn(`[Daemon] Could not read daemon PID:`, pidError instanceof Error ? pidError.message : pidError);
3449
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
+ });
3450
3493
  await client.connect(wsUrl, config.access_token, this.machineId, {
3451
3494
  hostname: os.hostname(),
3452
3495
  osPlatform: os.platform(),
@@ -3454,6 +3497,8 @@ var Daemon = class {
3454
3497
  daemonPid
3455
3498
  });
3456
3499
  console.log(`[Daemon] Successfully connected to project ${projectId}`);
3500
+ await authSuccessPromise;
3501
+ console.log(`[Daemon] Authentication complete for project ${projectId}`);
3457
3502
  } catch (error) {
3458
3503
  console.error(`[Daemon] Failed to connect to ${projectId}:`, error);
3459
3504
  this.connections.delete(projectPath);