episoda 0.2.123 → 0.2.125

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.
@@ -2815,7 +2815,7 @@ var require_package = __commonJS({
2815
2815
  "package.json"(exports2, module2) {
2816
2816
  module2.exports = {
2817
2817
  name: "episoda",
2818
- version: "0.2.122",
2818
+ version: "0.2.124",
2819
2819
  description: "CLI tool for Episoda local development workflow orchestration",
2820
2820
  main: "dist/index.js",
2821
2821
  types: "dist/index.d.ts",
@@ -4210,6 +4210,7 @@ var WorktreeManager = class _WorktreeManager {
4210
4210
  };
4211
4211
  }
4212
4212
  const worktreePath = path7.join(this.projectRoot, moduleUid);
4213
+ const normalizedWorktreePath = path7.resolve(worktreePath);
4213
4214
  const lockAcquired = await this.acquireLock();
4214
4215
  if (!lockAcquired) {
4215
4216
  return {
@@ -4226,6 +4227,47 @@ var WorktreeManager = class _WorktreeManager {
4226
4227
  worktreeInfo: existing
4227
4228
  };
4228
4229
  }
4230
+ if (fs6.existsSync(worktreePath)) {
4231
+ const listResult = await this.gitExecutor.execute({
4232
+ action: "worktree_list"
4233
+ }, { cwd: this.bareRepoPath });
4234
+ const worktrees = listResult.details?.worktrees || [];
4235
+ const matching = worktrees.find((w) => path7.resolve(w.path) === normalizedWorktreePath);
4236
+ if (matching) {
4237
+ const adoptedWorktree = {
4238
+ moduleUid,
4239
+ branchName: matching.branch && matching.branch !== "unknown" ? matching.branch : branchName,
4240
+ worktreePath,
4241
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4242
+ lastAccessed: (/* @__PURE__ */ new Date()).toISOString()
4243
+ };
4244
+ const config2 = this.readConfig();
4245
+ if (config2) {
4246
+ config2.worktrees = config2.worktrees.filter((w) => w.moduleUid !== moduleUid);
4247
+ config2.worktrees.push(adoptedWorktree);
4248
+ this.writeConfig(config2);
4249
+ }
4250
+ return {
4251
+ success: true,
4252
+ worktreePath: adoptedWorktree.worktreePath,
4253
+ worktreeInfo: adoptedWorktree
4254
+ };
4255
+ }
4256
+ if (process.env.EPISODA_MODE !== "cloud") {
4257
+ return {
4258
+ success: false,
4259
+ error: `Worktree already exists at path: ${worktreePath}`
4260
+ };
4261
+ }
4262
+ console.warn(`[WorktreeManager] EP1265: Removing stale worktree path at ${worktreePath}`);
4263
+ fs6.rmSync(worktreePath, { recursive: true, force: true });
4264
+ const pruneResult = await this.gitExecutor.execute({
4265
+ action: "worktree_prune"
4266
+ }, { cwd: this.bareRepoPath });
4267
+ if (!pruneResult.success) {
4268
+ console.warn("[WorktreeManager] EP1265: Failed to prune worktrees (continuing):", pruneResult.output);
4269
+ }
4270
+ }
4229
4271
  const fetchResult = await this.gitExecutor.execute({
4230
4272
  action: "fetch",
4231
4273
  remote: "origin",
@@ -7535,6 +7577,7 @@ async function handleWorktreeCreate(request2) {
7535
7577
  try {
7536
7578
  const projectPath = getProjectPath(workspaceSlug, projectSlug);
7537
7579
  const bareRepoPath = path16.join(projectPath, ".bare");
7580
+ const gitEnv = projectId ? { ...process.env, EPISODA_PROJECT_ID: projectId } : process.env;
7538
7581
  if (!fs15.existsSync(bareRepoPath)) {
7539
7582
  console.log(`[Worktree] K1273: Project not found, cloning lazily...`);
7540
7583
  console.log(`[Worktree] Repo URL: ${repoUrl.replace(/\/\/[^@]*@/, "//***@")}`);
@@ -7542,9 +7585,9 @@ async function handleWorktreeCreate(request2) {
7542
7585
  fs15.mkdirSync(episodaDir, { recursive: true });
7543
7586
  try {
7544
7587
  console.log(`[Worktree] K1273: Starting git clone...`);
7545
- await execAsync(`git clone --bare "${repoUrl}" "${bareRepoPath}"`);
7588
+ await execAsync(`git clone --bare "${repoUrl}" "${bareRepoPath}"`, { env: gitEnv });
7546
7589
  console.log(`[Worktree] K1273: Clone successful`);
7547
- await execAsync(`git -C "${bareRepoPath}" config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"`);
7590
+ await execAsync(`git -C "${bareRepoPath}" config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"`, { env: gitEnv });
7548
7591
  const configPath = path16.join(episodaDir, "config.json");
7549
7592
  const config2 = {
7550
7593
  projectId,
@@ -7566,7 +7609,7 @@ async function handleWorktreeCreate(request2) {
7566
7609
  } else {
7567
7610
  console.log(`[Worktree] K1273: Project exists, fetching latest...`);
7568
7611
  try {
7569
- await execAsync(`git -C "${bareRepoPath}" fetch origin --prune`);
7612
+ await execAsync(`git -C "${bareRepoPath}" fetch origin --prune`, { env: gitEnv });
7570
7613
  } catch (fetchError) {
7571
7614
  console.warn(`[Worktree] K1273: Fetch failed (continuing anyway): ${fetchError.message}`);
7572
7615
  }