episoda 0.2.20 → 0.2.21

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/dist/index.js CHANGED
@@ -2468,7 +2468,7 @@ var require_auth = __commonJS({
2468
2468
  exports2.getConfigDir = getConfigDir5;
2469
2469
  exports2.getConfigPath = getConfigPath4;
2470
2470
  exports2.loadConfig = loadConfig7;
2471
- exports2.saveConfig = saveConfig4;
2471
+ exports2.saveConfig = saveConfig5;
2472
2472
  exports2.validateToken = validateToken;
2473
2473
  var fs12 = __importStar(require("fs"));
2474
2474
  var path14 = __importStar(require("path"));
@@ -2518,7 +2518,7 @@ var require_auth = __commonJS({
2518
2518
  return null;
2519
2519
  }
2520
2520
  }
2521
- async function saveConfig4(config, configPath) {
2521
+ async function saveConfig5(config, configPath) {
2522
2522
  const fullPath = getConfigPath4(configPath);
2523
2523
  ensureConfigDir(fullPath);
2524
2524
  try {
@@ -3768,9 +3768,12 @@ async function migrateCommand(options = {}) {
3768
3768
  }
3769
3769
  });
3770
3770
  if (response.ok) {
3771
- const projectData = await response.json();
3772
- workspaceSlug = projectData.workspace_slug || workspaceSlug;
3773
- projectSlug = projectData.slug || projectSlug;
3771
+ const responseData = await response.json();
3772
+ const projectData = responseData.data?.project;
3773
+ if (projectData) {
3774
+ workspaceSlug = projectData.workspace_slug || workspaceSlug;
3775
+ projectSlug = projectData.slug || projectSlug;
3776
+ }
3774
3777
  }
3775
3778
  } catch {
3776
3779
  }
@@ -3793,6 +3796,7 @@ async function migrateCommand(options = {}) {
3793
3796
  if (hasUncommitted) {
3794
3797
  status.info(`Found ${uncommittedFiles.length} uncommitted file(s) to preserve...`);
3795
3798
  }
3799
+ const targetExistedBefore = fs5.existsSync(targetPath);
3796
3800
  try {
3797
3801
  status.info("Creating target directory...");
3798
3802
  const episodaRoot = getEpisodaRoot();
@@ -3884,6 +3888,40 @@ async function migrateCommand(options = {}) {
3884
3888
  bareRepoPath
3885
3889
  });
3886
3890
  status.success("\u2713 Project registered with daemon");
3891
+ try {
3892
+ const apiUrl = config.api_url || "https://episoda.dev";
3893
+ const settingsResponse = await fetch(`${apiUrl}/api/projects/${projectId}/settings`, {
3894
+ method: "PATCH",
3895
+ headers: {
3896
+ "Authorization": `Bearer ${config.access_token}`,
3897
+ "Content-Type": "application/json"
3898
+ },
3899
+ body: JSON.stringify({
3900
+ local_project_path: worktreePath
3901
+ })
3902
+ });
3903
+ if (settingsResponse.ok) {
3904
+ status.success("\u2713 Project settings updated");
3905
+ } else {
3906
+ status.warning("Could not update project settings in database");
3907
+ }
3908
+ } catch {
3909
+ status.warning("Could not update project settings in database");
3910
+ }
3911
+ try {
3912
+ const updatedConfig = {
3913
+ ...config,
3914
+ project_settings: {
3915
+ ...config.project_settings,
3916
+ local_project_path: worktreePath,
3917
+ cached_at: Date.now()
3918
+ }
3919
+ };
3920
+ await (0, import_core5.saveConfig)(updatedConfig);
3921
+ status.success("\u2713 Local config updated");
3922
+ } catch {
3923
+ status.warning("Could not update local config cache");
3924
+ }
3887
3925
  status.info("");
3888
3926
  status.success("Migration complete!");
3889
3927
  status.info("");
@@ -3905,12 +3943,39 @@ async function migrateCommand(options = {}) {
3905
3943
  status.info("");
3906
3944
  } catch (error) {
3907
3945
  status.error("Migration failed, cleaning up...");
3908
- if (fs5.existsSync(targetPath)) {
3946
+ if (!targetExistedBefore && fs5.existsSync(targetPath)) {
3909
3947
  try {
3910
3948
  fs5.rmSync(targetPath, { recursive: true, force: true });
3949
+ status.info(`Removed ${targetPath}`);
3911
3950
  } catch {
3912
3951
  status.warning(`Could not remove ${targetPath}`);
3913
3952
  }
3953
+ } else if (targetExistedBefore) {
3954
+ status.info("Target directory existed before migration, only removing migration artifacts...");
3955
+ const bareRepoPath = path6.join(targetPath, ".bare");
3956
+ const episodaDir = path6.join(targetPath, ".episoda");
3957
+ if (fs5.existsSync(bareRepoPath)) {
3958
+ try {
3959
+ fs5.rmSync(bareRepoPath, { recursive: true, force: true });
3960
+ status.info("Removed .bare directory");
3961
+ } catch {
3962
+ status.warning("Could not remove .bare directory");
3963
+ }
3964
+ }
3965
+ if (fs5.existsSync(episodaDir)) {
3966
+ try {
3967
+ const configPath = path6.join(episodaDir, "config.json");
3968
+ if (fs5.existsSync(configPath)) {
3969
+ const config2 = JSON.parse(fs5.readFileSync(configPath, "utf-8"));
3970
+ if (config2.worktreeMode) {
3971
+ fs5.rmSync(episodaDir, { recursive: true, force: true });
3972
+ status.info("Removed .episoda directory");
3973
+ }
3974
+ }
3975
+ } catch {
3976
+ status.warning("Could not remove .episoda directory");
3977
+ }
3978
+ }
3914
3979
  }
3915
3980
  throw error;
3916
3981
  }