episoda 0.2.57 → 0.2.59

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.
@@ -2726,7 +2726,7 @@ var require_package = __commonJS({
2726
2726
  "package.json"(exports2, module2) {
2727
2727
  module2.exports = {
2728
2728
  name: "episoda",
2729
- version: "0.2.57",
2729
+ version: "0.2.59",
2730
2730
  description: "CLI tool for Episoda local development workflow orchestration",
2731
2731
  main: "dist/index.js",
2732
2732
  types: "dist/index.d.ts",
@@ -2798,6 +2798,10 @@ function isValidUUID(str) {
2798
2798
  return uuidRegex.test(str);
2799
2799
  }
2800
2800
  async function getMachineId() {
2801
+ const envMachineId = process.env.EPISODA_MACHINE_ID;
2802
+ if (envMachineId) {
2803
+ return envMachineId;
2804
+ }
2801
2805
  const machineIdPath = path.join((0, import_core.getConfigDir)(), "machine-id");
2802
2806
  try {
2803
2807
  if (fs.existsSync(machineIdPath)) {
@@ -9261,73 +9265,81 @@ var Daemon = class _Daemon {
9261
9265
  let response;
9262
9266
  try {
9263
9267
  response = await fetchWithAuth(
9264
- `${apiUrl}/api/cli/cleanup-queue?machine_id=${this.deviceId}`,
9268
+ `${apiUrl}/api/cli/background-ops?machine_id=${this.deviceId}`,
9265
9269
  { signal: controller.signal }
9266
9270
  );
9267
9271
  } finally {
9268
9272
  clearTimeout(timeoutId);
9269
9273
  }
9270
9274
  if (!response.ok) {
9271
- console.warn(`[Daemon] EP1047: Failed to fetch cleanup tasks: ${response.status}`);
9275
+ console.warn(`[Daemon] EP1051: Failed to fetch background operations: ${response.status}`);
9272
9276
  return;
9273
9277
  }
9274
9278
  const data = await response.json();
9275
9279
  const tasks = data.data?.tasks || [];
9276
9280
  if (tasks.length === 0) {
9277
- console.log("[Daemon] EP1047: No pending cleanup tasks");
9281
+ console.log("[Daemon] EP1051: No pending background operations");
9278
9282
  return;
9279
9283
  }
9280
- console.log(`[Daemon] EP1047: Processing ${tasks.length} pending cleanup task(s)`);
9284
+ console.log(`[Daemon] EP1051: Processing ${tasks.length} pending operation(s)`);
9281
9285
  const projectRoot = await findProjectRoot(projectPath);
9282
9286
  if (!projectRoot) {
9283
- console.warn("[Daemon] EP1047: Could not find project root, skipping cleanup reconciliation");
9287
+ console.warn("[Daemon] EP1051: Could not find project root, skipping operation reconciliation");
9284
9288
  return;
9285
9289
  }
9286
9290
  const worktreeManager = new WorktreeManager(projectRoot);
9287
9291
  if (!await worktreeManager.initialize()) {
9288
- console.warn("[Daemon] EP1047: Failed to initialize worktree manager");
9292
+ console.warn("[Daemon] EP1051: Failed to initialize worktree manager");
9289
9293
  return;
9290
9294
  }
9291
9295
  for (const task of tasks) {
9292
9296
  const moduleUid = task.payload.module_uid || task.target_id;
9293
- console.log(`[Daemon] EP1047: Processing cleanup for ${moduleUid} (task ${task.id})`);
9297
+ console.log(`[Daemon] EP1051: Processing ${task.operation_type} for ${moduleUid} (task ${task.id})`);
9294
9298
  try {
9295
- const result = await worktreeManager.removeWorktree(moduleUid, true);
9296
- if (result.success) {
9297
- console.log(`[Daemon] EP1047: Successfully cleaned up worktree for ${moduleUid}`);
9298
- await this.reportCleanupResult(apiUrl, task.id, "complete");
9299
- } else {
9300
- if (result.error?.includes("not found") || result.error?.includes("No worktree found")) {
9301
- console.log(`[Daemon] EP1047: Worktree ${moduleUid} already removed, marking complete`);
9302
- await this.reportCleanupResult(apiUrl, task.id, "complete");
9299
+ if (task.operation_type === "worktree_cleanup") {
9300
+ const result = await worktreeManager.removeWorktree(moduleUid, true);
9301
+ if (result.success) {
9302
+ console.log(`[Daemon] EP1051: Successfully cleaned up worktree for ${moduleUid}`);
9303
+ await this.reportOperationResult(apiUrl, task.id, "complete");
9303
9304
  } else {
9304
- console.warn(`[Daemon] EP1047: Cleanup failed for ${moduleUid}: ${result.error}`);
9305
- await this.reportCleanupResult(apiUrl, task.id, "retry", {
9306
- code: "CLEANUP_ERROR",
9307
- message: result.error || "Unknown error"
9308
- });
9305
+ if (result.error?.includes("not found") || result.error?.includes("No worktree found")) {
9306
+ console.log(`[Daemon] EP1051: Worktree ${moduleUid} already removed, marking complete`);
9307
+ await this.reportOperationResult(apiUrl, task.id, "complete");
9308
+ } else {
9309
+ console.warn(`[Daemon] EP1051: Cleanup failed for ${moduleUid}: ${result.error}`);
9310
+ await this.reportOperationResult(apiUrl, task.id, "retry", {
9311
+ code: "OPERATION_ERROR",
9312
+ message: result.error || "Unknown error"
9313
+ });
9314
+ }
9309
9315
  }
9316
+ } else {
9317
+ console.warn(`[Daemon] EP1051: Unknown operation type: ${task.operation_type}`);
9318
+ await this.reportOperationResult(apiUrl, task.id, "fail", {
9319
+ code: "UNKNOWN_OPERATION_TYPE",
9320
+ message: `Daemon cannot process operation type: ${task.operation_type}`
9321
+ });
9310
9322
  }
9311
9323
  } catch (error) {
9312
- console.error(`[Daemon] EP1047: Error processing cleanup for ${moduleUid}:`, error.message);
9313
- await this.reportCleanupResult(apiUrl, task.id, "retry", {
9314
- code: "CLEANUP_EXCEPTION",
9324
+ console.error(`[Daemon] EP1051: Error processing operation for ${moduleUid}:`, error.message);
9325
+ await this.reportOperationResult(apiUrl, task.id, "retry", {
9326
+ code: "OPERATION_EXCEPTION",
9315
9327
  message: error.message
9316
9328
  });
9317
9329
  }
9318
9330
  }
9319
- console.log("[Daemon] EP1047: Cleanup reconciliation complete");
9331
+ console.log("[Daemon] EP1051: Operation reconciliation complete");
9320
9332
  } catch (error) {
9321
- console.error("[Daemon] EP1047: Cleanup reconciliation error:", error instanceof Error ? error.message : error);
9333
+ console.error("[Daemon] EP1051: Operation reconciliation error:", error instanceof Error ? error.message : error);
9322
9334
  throw error;
9323
9335
  }
9324
9336
  }
9325
9337
  /**
9326
- * EP1047: Report cleanup task result to server
9338
+ * EP1051: Report background operation result to server
9327
9339
  */
9328
- async reportCleanupResult(apiUrl, taskId, action, error) {
9340
+ async reportOperationResult(apiUrl, taskId, action, error) {
9329
9341
  try {
9330
- const response = await fetchWithAuth(`${apiUrl}/api/cli/cleanup-queue`, {
9342
+ const response = await fetchWithAuth(`${apiUrl}/api/cli/background-ops`, {
9331
9343
  method: "POST",
9332
9344
  headers: { "Content-Type": "application/json" },
9333
9345
  body: JSON.stringify({
@@ -9337,10 +9349,10 @@ var Daemon = class _Daemon {
9337
9349
  })
9338
9350
  });
9339
9351
  if (!response.ok) {
9340
- console.warn(`[Daemon] EP1047: Failed to report cleanup result: ${response.status}`);
9352
+ console.warn(`[Daemon] EP1051: Failed to report operation result: ${response.status}`);
9341
9353
  }
9342
9354
  } catch (err) {
9343
- console.warn(`[Daemon] EP1047: Error reporting cleanup result: ${err.message}`);
9355
+ console.warn(`[Daemon] EP1051: Error reporting operation result: ${err.message}`);
9344
9356
  }
9345
9357
  }
9346
9358
  /**