episoda 0.2.37 → 0.2.39

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
@@ -1863,6 +1863,11 @@ var require_git_executor = __commonJS({
1863
1863
  { timeout: options?.timeout || 12e4 }
1864
1864
  // 2 minutes for clone
1865
1865
  );
1866
+ try {
1867
+ await execAsync(`git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"`, { cwd: command.path, timeout: 5e3 });
1868
+ } catch (configError) {
1869
+ console.error("[git-executor] EP1014: Failed to configure fetch refspec:", configError);
1870
+ }
1866
1871
  return {
1867
1872
  success: true,
1868
1873
  output: `Cloned bare repository to ${command.path}`,
@@ -3224,11 +3229,43 @@ var WorktreeManager = class _WorktreeManager {
3224
3229
  }
3225
3230
  try {
3226
3231
  const config = this.readConfig();
3227
- return config !== null;
3232
+ if (config === null) {
3233
+ return false;
3234
+ }
3235
+ await this.ensureFetchRefspecConfigured();
3236
+ return true;
3228
3237
  } catch {
3229
3238
  return false;
3230
3239
  }
3231
3240
  }
3241
+ /**
3242
+ * EP1014: Ensure fetch refspec is configured in bare repo
3243
+ * Older bare repos may be missing this configuration, causing stale worktrees
3244
+ */
3245
+ async ensureFetchRefspecConfigured() {
3246
+ try {
3247
+ const { execSync: execSync9 } = require("child_process");
3248
+ let fetchRefspec = null;
3249
+ try {
3250
+ fetchRefspec = execSync9("git config --get remote.origin.fetch", {
3251
+ cwd: this.bareRepoPath,
3252
+ encoding: "utf-8",
3253
+ timeout: 5e3
3254
+ }).trim();
3255
+ } catch {
3256
+ }
3257
+ if (!fetchRefspec) {
3258
+ console.log("[WorktreeManager] EP1014: Configuring missing fetch refspec for bare repo");
3259
+ execSync9('git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', {
3260
+ cwd: this.bareRepoPath,
3261
+ timeout: 5e3
3262
+ });
3263
+ console.log("[WorktreeManager] EP1014: Fetch refspec configured successfully");
3264
+ }
3265
+ } catch (error) {
3266
+ console.warn("[WorktreeManager] EP1014: Failed to configure fetch refspec:", error);
3267
+ }
3268
+ }
3232
3269
  /**
3233
3270
  * Create a new worktree project from scratch
3234
3271
  */
@@ -3285,7 +3322,8 @@ var WorktreeManager = class _WorktreeManager {
3285
3322
  }
3286
3323
  const fetchResult = await this.gitExecutor.execute({
3287
3324
  action: "fetch",
3288
- remote: "origin"
3325
+ remote: "origin",
3326
+ branch: "+refs/heads/main:refs/remotes/origin/main"
3289
3327
  }, { cwd: this.bareRepoPath });
3290
3328
  if (!fetchResult.success && createBranch) {
3291
3329
  console.error("[worktree-manager] Failed to fetch from origin:", fetchResult.output);
@@ -4951,18 +4989,58 @@ async function checkForUpdates(currentVersion) {
4951
4989
  return { currentVersion, latestVersion: currentVersion, updateAvailable: false, offline: true };
4952
4990
  }
4953
4991
  }
4954
- function performBackgroundUpdate() {
4992
+ function performSyncUpdate() {
4993
+ try {
4994
+ (0, import_child_process7.execSync)(`npm update -g ${PACKAGE_NAME}`, {
4995
+ stdio: ["pipe", "pipe", "pipe"],
4996
+ timeout: 12e4
4997
+ // 2 minute timeout
4998
+ });
4999
+ return { success: true };
5000
+ } catch (error) {
5001
+ return {
5002
+ success: false,
5003
+ error: error instanceof Error ? error.message : String(error)
5004
+ };
5005
+ }
5006
+ }
5007
+ async function restartDaemon() {
4955
5008
  try {
4956
- const child = (0, import_child_process7.spawn)("npm", ["update", "-g", PACKAGE_NAME], {
5009
+ (0, import_child_process7.execSync)("episoda stop", {
5010
+ stdio: ["pipe", "pipe", "pipe"],
5011
+ timeout: 1e4
5012
+ });
5013
+ await new Promise((resolve5) => setTimeout(resolve5, 1e3));
5014
+ const child = (0, import_child_process7.spawn)("episoda", ["dev"], {
4957
5015
  detached: true,
4958
5016
  stdio: "ignore",
4959
- // Use shell on Windows for proper npm execution
4960
- shell: process.platform === "win32"
5017
+ shell: true
4961
5018
  });
4962
5019
  child.unref();
5020
+ return { success: true };
4963
5021
  } catch (error) {
5022
+ return {
5023
+ success: false,
5024
+ error: error instanceof Error ? error.message : String(error)
5025
+ };
4964
5026
  }
4965
5027
  }
5028
+ async function updateAndRestartDaemon() {
5029
+ const updateResult = performSyncUpdate();
5030
+ if (!updateResult.success) {
5031
+ return {
5032
+ updateSuccess: false,
5033
+ restartSuccess: false,
5034
+ error: `Update failed: ${updateResult.error}`
5035
+ };
5036
+ }
5037
+ const restartResult = await restartDaemon();
5038
+ return {
5039
+ updateSuccess: true,
5040
+ restartSuccess: restartResult.success,
5041
+ error: restartResult.success ? void 0 : `Restart failed: ${restartResult.error}`
5042
+ };
5043
+ }
4966
5044
  function getInstalledVersion() {
4967
5045
  try {
4968
5046
  const output = (0, import_child_process7.execSync)(`npm list -g ${PACKAGE_NAME} --json`, {
@@ -4998,8 +5076,15 @@ async function statusCommand(options = {}) {
4998
5076
  if (!options.skipUpdateCheck) {
4999
5077
  const updateResult = await checkForUpdates(import_core8.VERSION);
5000
5078
  if (updateResult.updateAvailable) {
5001
- status.info(` CLI Version: ${import_core8.VERSION} \u2B06 updating to ${updateResult.latestVersion}...`);
5002
- performBackgroundUpdate();
5079
+ status.info(` CLI Version: ${import_core8.VERSION} \u2192 ${updateResult.latestVersion} (updating...)`);
5080
+ const result = await updateAndRestartDaemon();
5081
+ if (result.updateSuccess && result.restartSuccess) {
5082
+ status.success(` CLI Version: ${updateResult.latestVersion} \u2713 (updated & daemon restarted)`);
5083
+ } else if (result.updateSuccess) {
5084
+ status.warning(` CLI Version: ${updateResult.latestVersion} (updated, restart manually with 'episoda dev')`);
5085
+ } else {
5086
+ status.warning(` CLI Version: ${import_core8.VERSION} (update failed: ${result.error})`);
5087
+ }
5003
5088
  } else {
5004
5089
  status.info(` CLI Version: ${import_core8.VERSION} \u2713`);
5005
5090
  }