@iloom/cli 0.3.4 → 0.4.0
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/README.md +13 -3
- package/dist/{BranchNamingService-A77VI6AI.js → BranchNamingService-TOM2KAUT.js} +4 -3
- package/dist/ClaudeContextManager-VEGJTS5E.js +16 -0
- package/dist/ClaudeService-ICSHJMQ5.js +15 -0
- package/dist/GitHubService-RPM27GWD.js +12 -0
- package/dist/{LoomLauncher-ZV3ZZIBA.js → LoomLauncher-SJBZFZXE.js} +25 -22
- package/dist/LoomLauncher-SJBZFZXE.js.map +1 -0
- package/dist/PromptTemplateManager-2TDZAUC6.js +9 -0
- package/dist/README.md +13 -3
- package/dist/{SettingsManager-I2LRCW2A.js → SettingsManager-FJFU6JJD.js} +7 -3
- package/dist/SettingsMigrationManager-EH3J2TCN.js +10 -0
- package/dist/{chunk-UJL4HI2R.js → chunk-3NFBZRPR.js} +2 -2
- package/dist/chunk-6UIGZD2N.js +20 -0
- package/dist/chunk-6UIGZD2N.js.map +1 -0
- package/dist/{chunk-RIEO2WML.js → chunk-74VMN2KC.js} +26 -2
- package/dist/chunk-74VMN2KC.js.map +1 -0
- package/dist/{chunk-OYF4VIFI.js → chunk-75B2HZZ5.js} +147 -22
- package/dist/chunk-75B2HZZ5.js.map +1 -0
- package/dist/{chunk-PGPI5LR4.js → chunk-ADDNFQJ4.js} +7 -21
- package/dist/chunk-ADDNFQJ4.js.map +1 -0
- package/dist/{chunk-AKUJXDNW.js → chunk-F4J6KEL6.js} +3 -3
- package/dist/{chunk-DLHA5VQ3.js → chunk-HD5SUKI2.js} +36 -179
- package/dist/chunk-HD5SUKI2.js.map +1 -0
- package/dist/chunk-HHDSIE72.js +667 -0
- package/dist/chunk-HHDSIE72.js.map +1 -0
- package/dist/{chunk-OXAM2WVC.js → chunk-HVGQP44L.js} +21 -1
- package/dist/chunk-HVGQP44L.js.map +1 -0
- package/dist/{chunk-RW54ZMBM.js → chunk-JJUPY5MM.js} +2 -2
- package/dist/{chunk-UAN4A3YU.js → chunk-KM3W7YQX.js} +11 -11
- package/dist/{chunk-3RUPPQRG.js → chunk-KO2FOMHL.js} +43 -2
- package/dist/{chunk-3RUPPQRG.js.map → chunk-KO2FOMHL.js.map} +1 -1
- package/dist/{chunk-2MAIX45J.js → chunk-LTNDJMTH.js} +104 -43
- package/dist/chunk-LTNDJMTH.js.map +1 -0
- package/dist/{chunk-2CXREBLZ.js → chunk-M5XUCTTJ.js} +8 -6
- package/dist/chunk-M5XUCTTJ.js.map +1 -0
- package/dist/{chunk-4XIDC3NF.js → chunk-MD6HA5IK.js} +2 -2
- package/dist/chunk-MLS5FAV7.js +189 -0
- package/dist/chunk-MLS5FAV7.js.map +1 -0
- package/dist/{chunk-2IJEMXOB.js → chunk-NFVFVYAP.js} +419 -427
- package/dist/chunk-NFVFVYAP.js.map +1 -0
- package/dist/{chunk-OC4H6HJD.js → chunk-O7WHXLCB.js} +2 -2
- package/dist/{chunk-M7JJCX53.js → chunk-OEGECBFS.js} +20 -20
- package/dist/chunk-OEGECBFS.js.map +1 -0
- package/dist/{chunk-MKWYLDFK.js → chunk-OF7BNW4D.js} +43 -3
- package/dist/chunk-OF7BNW4D.js.map +1 -0
- package/dist/{chunk-SUOXY5WJ.js → chunk-P2WZIDF3.js} +5 -5
- package/dist/chunk-P2WZIDF3.js.map +1 -0
- package/dist/{chunk-PA6Q6AWM.js → chunk-PSFVTBM7.js} +2 -2
- package/dist/chunk-QHA67Q7A.js +281 -0
- package/dist/chunk-QHA67Q7A.js.map +1 -0
- package/dist/{chunk-ZM3CFL5L.js → chunk-QRBOPFAA.js} +3 -3
- package/dist/{chunk-IFB4Z76W.js → chunk-S44CHE3G.js} +13 -12
- package/dist/chunk-S44CHE3G.js.map +1 -0
- package/dist/{chunk-CE26YH2U.js → chunk-SJ2GZ6RF.js} +48 -50
- package/dist/chunk-SJ2GZ6RF.js.map +1 -0
- package/dist/{chunk-SSCQCCJ7.js → chunk-THF25ICZ.js} +2 -2
- package/dist/{chunk-5Q3NDNNV.js → chunk-TR5MC2U6.js} +153 -6
- package/dist/chunk-TR5MC2U6.js.map +1 -0
- package/dist/{chunk-5VK4NRSF.js → chunk-UNXRACJ7.js} +35 -36
- package/dist/chunk-UNXRACJ7.js.map +1 -0
- package/dist/{chunk-GEHQXLEI.js → chunk-UYVWLISQ.js} +18 -35
- package/dist/chunk-UYVWLISQ.js.map +1 -0
- package/dist/{chunk-OSCLCMDG.js → chunk-UYWAESOT.js} +3 -3
- package/dist/{chunk-ZT3YZB4K.js → chunk-VBFDVGAE.js} +12 -12
- package/dist/chunk-VBFDVGAE.js.map +1 -0
- package/dist/{chunk-CDZERT7Z.js → chunk-VWNS6DH5.js} +48 -4
- package/dist/chunk-VWNS6DH5.js.map +1 -0
- package/dist/{chunk-CFFQ2Z7A.js → chunk-WUQQNE63.js} +2 -2
- package/dist/{claude-W52VKI6L.js → claude-X7EBJRB2.js} +8 -5
- package/dist/{cleanup-H4VXU3C3.js → cleanup-7QVPYBJJ.js} +133 -122
- package/dist/cleanup-7QVPYBJJ.js.map +1 -0
- package/dist/cli.js +901 -425
- package/dist/cli.js.map +1 -1
- package/dist/{color-F7RU6B6Z.js → color-ZPIIUADB.js} +3 -3
- package/dist/{contribute-Y7IQV5QY.js → contribute-RZYCYUDX.js} +8 -6
- package/dist/{contribute-Y7IQV5QY.js.map → contribute-RZYCYUDX.js.map} +1 -1
- package/dist/dev-server-LOY7YWCP.js +298 -0
- package/dist/dev-server-LOY7YWCP.js.map +1 -0
- package/dist/{feedback-XTUCKJNT.js → feedback-562KPG5U.js} +13 -12
- package/dist/{feedback-XTUCKJNT.js.map → feedback-562KPG5U.js.map} +1 -1
- package/dist/{git-IYA53VIC.js → git-OXJACVAU.js} +16 -4
- package/dist/hooks/iloom-hook.js +258 -0
- package/dist/{ignite-T74RYXCA.js → ignite-VSIPGKKG.js} +245 -39
- package/dist/ignite-VSIPGKKG.js.map +1 -0
- package/dist/index.d.ts +459 -124
- package/dist/index.js +740 -210
- package/dist/index.js.map +1 -1
- package/dist/init-SCR2LQ4A.js +21 -0
- package/dist/{installation-detector-VARGFFRZ.js → installation-detector-6R6YOFVZ.js} +3 -3
- package/dist/mcp/issue-management-server.js +2 -1
- package/dist/mcp/issue-management-server.js.map +1 -1
- package/dist/neon-helpers-L5CXQ5CT.js +11 -0
- package/dist/{open-UMXANW5S.js → open-CX7HUE26.js} +12 -10
- package/dist/{open-UMXANW5S.js.map → open-CX7HUE26.js.map} +1 -1
- package/dist/projects-6DTNDVLH.js +73 -0
- package/dist/projects-6DTNDVLH.js.map +1 -0
- package/dist/{prompt-QALMYTVC.js → prompt-A7GGRHSY.js} +3 -3
- package/dist/prompts/init-prompt.txt +49 -0
- package/dist/prompts/issue-prompt.txt +110 -8
- package/dist/prompts/regular-prompt.txt +90 -0
- package/dist/prompts/session-summary-prompt.txt +82 -0
- package/dist/{rebase-VJ2VKR6R.js → rebase-55URTXZC.js} +11 -9
- package/dist/{rebase-VJ2VKR6R.js.map → rebase-55URTXZC.js.map} +1 -1
- package/dist/{remote-VUNCQZ6J.js → remote-73TZ2ADI.js} +3 -3
- package/dist/{run-MJYY4PUT.js → run-DP2U2CA2.js} +12 -10
- package/dist/{run-MJYY4PUT.js.map → run-DP2U2CA2.js.map} +1 -1
- package/dist/schema/settings.schema.json +49 -0
- package/dist/summary-J3CJSM7L.js +244 -0
- package/dist/summary-J3CJSM7L.js.map +1 -0
- package/dist/{test-git-IT5EWQ5C.js → test-git-QLAIBJLX.js} +6 -4
- package/dist/{test-git-IT5EWQ5C.js.map → test-git-QLAIBJLX.js.map} +1 -1
- package/dist/{test-prefix-NPWDPUUH.js → test-prefix-6YM2ZOON.js} +6 -4
- package/dist/{test-prefix-NPWDPUUH.js.map → test-prefix-6YM2ZOON.js.map} +1 -1
- package/dist/{test-tabs-PRMRSHKI.js → test-tabs-JGO3VOXJ.js} +4 -4
- package/dist/{test-webserver-DAHONWCS.js → test-webserver-VPNLAFZ3.js} +2 -2
- package/dist/{update-4TDDUR5K.js → update-LETF5ASC.js} +4 -4
- package/dist/{update-notifier-QEX3CJHA.js → update-notifier-H55ZK7NU.js} +3 -3
- package/package.json +6 -6
- package/dist/ClaudeContextManager-BN7RE5ZQ.js +0 -15
- package/dist/ClaudeService-DLYLJUPA.js +0 -14
- package/dist/GitHubService-FZHHBOFG.js +0 -11
- package/dist/LoomLauncher-ZV3ZZIBA.js.map +0 -1
- package/dist/PromptTemplateManager-6HH3PVXV.js +0 -9
- package/dist/SettingsMigrationManager-TJ7UWZG5.js +0 -10
- package/dist/chunk-2CXREBLZ.js.map +0 -1
- package/dist/chunk-2IJEMXOB.js.map +0 -1
- package/dist/chunk-2MAIX45J.js.map +0 -1
- package/dist/chunk-5Q3NDNNV.js.map +0 -1
- package/dist/chunk-5VK4NRSF.js.map +0 -1
- package/dist/chunk-CDZERT7Z.js.map +0 -1
- package/dist/chunk-CE26YH2U.js.map +0 -1
- package/dist/chunk-DLHA5VQ3.js.map +0 -1
- package/dist/chunk-GEHQXLEI.js.map +0 -1
- package/dist/chunk-IFB4Z76W.js.map +0 -1
- package/dist/chunk-M7JJCX53.js.map +0 -1
- package/dist/chunk-MKWYLDFK.js.map +0 -1
- package/dist/chunk-OXAM2WVC.js.map +0 -1
- package/dist/chunk-OYF4VIFI.js.map +0 -1
- package/dist/chunk-PGPI5LR4.js.map +0 -1
- package/dist/chunk-RIEO2WML.js.map +0 -1
- package/dist/chunk-SUOXY5WJ.js.map +0 -1
- package/dist/chunk-ZT3YZB4K.js.map +0 -1
- package/dist/cleanup-H4VXU3C3.js.map +0 -1
- package/dist/ignite-T74RYXCA.js.map +0 -1
- package/dist/init-4FHTAM3F.js +0 -19
- package/dist/logger-MKYH4UDV.js +0 -12
- package/dist/neon-helpers-77PBPGJ5.js +0 -10
- package/dist/update-notifier-QEX3CJHA.js.map +0 -1
- /package/dist/{BranchNamingService-A77VI6AI.js.map → BranchNamingService-TOM2KAUT.js.map} +0 -0
- /package/dist/{ClaudeContextManager-BN7RE5ZQ.js.map → ClaudeContextManager-VEGJTS5E.js.map} +0 -0
- /package/dist/{ClaudeService-DLYLJUPA.js.map → ClaudeService-ICSHJMQ5.js.map} +0 -0
- /package/dist/{GitHubService-FZHHBOFG.js.map → GitHubService-RPM27GWD.js.map} +0 -0
- /package/dist/{PromptTemplateManager-6HH3PVXV.js.map → PromptTemplateManager-2TDZAUC6.js.map} +0 -0
- /package/dist/{SettingsManager-I2LRCW2A.js.map → SettingsManager-FJFU6JJD.js.map} +0 -0
- /package/dist/{SettingsMigrationManager-TJ7UWZG5.js.map → SettingsMigrationManager-EH3J2TCN.js.map} +0 -0
- /package/dist/{chunk-UJL4HI2R.js.map → chunk-3NFBZRPR.js.map} +0 -0
- /package/dist/{chunk-AKUJXDNW.js.map → chunk-F4J6KEL6.js.map} +0 -0
- /package/dist/{chunk-RW54ZMBM.js.map → chunk-JJUPY5MM.js.map} +0 -0
- /package/dist/{chunk-UAN4A3YU.js.map → chunk-KM3W7YQX.js.map} +0 -0
- /package/dist/{chunk-4XIDC3NF.js.map → chunk-MD6HA5IK.js.map} +0 -0
- /package/dist/{chunk-OC4H6HJD.js.map → chunk-O7WHXLCB.js.map} +0 -0
- /package/dist/{chunk-PA6Q6AWM.js.map → chunk-PSFVTBM7.js.map} +0 -0
- /package/dist/{chunk-ZM3CFL5L.js.map → chunk-QRBOPFAA.js.map} +0 -0
- /package/dist/{chunk-SSCQCCJ7.js.map → chunk-THF25ICZ.js.map} +0 -0
- /package/dist/{chunk-OSCLCMDG.js.map → chunk-UYWAESOT.js.map} +0 -0
- /package/dist/{chunk-CFFQ2Z7A.js.map → chunk-WUQQNE63.js.map} +0 -0
- /package/dist/{claude-W52VKI6L.js.map → claude-X7EBJRB2.js.map} +0 -0
- /package/dist/{color-F7RU6B6Z.js.map → color-ZPIIUADB.js.map} +0 -0
- /package/dist/{git-IYA53VIC.js.map → git-OXJACVAU.js.map} +0 -0
- /package/dist/{init-4FHTAM3F.js.map → init-SCR2LQ4A.js.map} +0 -0
- /package/dist/{installation-detector-VARGFFRZ.js.map → installation-detector-6R6YOFVZ.js.map} +0 -0
- /package/dist/{logger-MKYH4UDV.js.map → neon-helpers-L5CXQ5CT.js.map} +0 -0
- /package/dist/{neon-helpers-77PBPGJ5.js.map → prompt-A7GGRHSY.js.map} +0 -0
- /package/dist/{prompt-QALMYTVC.js.map → remote-73TZ2ADI.js.map} +0 -0
- /package/dist/{test-tabs-PRMRSHKI.js.map → test-tabs-JGO3VOXJ.js.map} +0 -0
- /package/dist/{test-webserver-DAHONWCS.js.map → test-webserver-VPNLAFZ3.js.map} +0 -0
- /package/dist/{update-4TDDUR5K.js.map → update-LETF5ASC.js.map} +0 -0
- /package/dist/{remote-VUNCQZ6J.js.map → update-notifier-H55ZK7NU.js.map} +0 -0
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
executeGitCommand,
|
|
4
|
-
findMainWorktreePathWithSettings
|
|
5
|
-
|
|
4
|
+
findMainWorktreePathWithSettings,
|
|
5
|
+
findWorktreeForBranch,
|
|
6
|
+
getMergeTargetBranch
|
|
7
|
+
} from "./chunk-TR5MC2U6.js";
|
|
8
|
+
import {
|
|
9
|
+
MetadataManager
|
|
10
|
+
} from "./chunk-MLS5FAV7.js";
|
|
6
11
|
import {
|
|
7
12
|
SettingsManager
|
|
8
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-VWNS6DH5.js";
|
|
9
14
|
import {
|
|
10
15
|
detectClaudeCli,
|
|
11
16
|
launchClaude
|
|
12
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-75B2HZZ5.js";
|
|
13
18
|
import {
|
|
14
|
-
|
|
15
|
-
} from "./chunk-
|
|
19
|
+
getLogger
|
|
20
|
+
} from "./chunk-6UIGZD2N.js";
|
|
16
21
|
|
|
17
22
|
// src/lib/MergeManager.ts
|
|
18
23
|
var MergeManager = class {
|
|
19
|
-
constructor(settingsManager) {
|
|
24
|
+
constructor(settingsManager, metadataManager) {
|
|
20
25
|
this.settingsManager = settingsManager ?? new SettingsManager();
|
|
26
|
+
this.metadataManager = metadataManager ?? new MetadataManager();
|
|
21
27
|
}
|
|
22
28
|
/**
|
|
23
|
-
* Get the
|
|
24
|
-
*
|
|
29
|
+
* Get the merge target branch for a loom
|
|
30
|
+
* Priority: parent loom metadata > configured main branch > 'main'
|
|
31
|
+
* @param worktreePath - Optional path to load settings/metadata from (defaults to process.cwd())
|
|
25
32
|
* @private
|
|
26
33
|
*/
|
|
27
34
|
async getMainBranch(worktreePath) {
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
return getMergeTargetBranch(worktreePath ?? process.cwd(), {
|
|
36
|
+
settingsManager: this.settingsManager,
|
|
37
|
+
metadataManager: this.metadataManager
|
|
38
|
+
});
|
|
30
39
|
}
|
|
31
40
|
/**
|
|
32
41
|
* Rebase current branch on main with fail-fast on conflicts
|
|
@@ -39,7 +48,7 @@ var MergeManager = class {
|
|
|
39
48
|
async rebaseOnMain(worktreePath, options = {}) {
|
|
40
49
|
const { dryRun = false, force = false } = options;
|
|
41
50
|
const mainBranch = await this.getMainBranch(worktreePath);
|
|
42
|
-
|
|
51
|
+
getLogger().info(`Starting rebase on ${mainBranch} branch...`);
|
|
43
52
|
try {
|
|
44
53
|
await executeGitCommand(["show-ref", "--verify", "--quiet", `refs/heads/${mainBranch}`], {
|
|
45
54
|
cwd: worktreePath
|
|
@@ -53,10 +62,11 @@ Ensure the repository has a "${mainBranch}" branch or create it first.`
|
|
|
53
62
|
const statusOutput = await executeGitCommand(["status", "--porcelain"], {
|
|
54
63
|
cwd: worktreePath
|
|
55
64
|
});
|
|
65
|
+
let wipCommitHash = null;
|
|
56
66
|
if (statusOutput.trim()) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
);
|
|
67
|
+
getLogger().info("Uncommitted changes detected, creating temporary WIP commit...");
|
|
68
|
+
wipCommitHash = await this.createWipCommit(worktreePath);
|
|
69
|
+
getLogger().debug(`Created WIP commit: ${wipCommitHash}`);
|
|
60
70
|
}
|
|
61
71
|
const mergeBase = await executeGitCommand(["merge-base", mainBranch, "HEAD"], {
|
|
62
72
|
cwd: worktreePath
|
|
@@ -67,7 +77,7 @@ Ensure the repository has a "${mainBranch}" branch or create it first.`
|
|
|
67
77
|
const mergeBaseTrimmed = mergeBase.trim();
|
|
68
78
|
const mainHeadTrimmed = mainHead.trim();
|
|
69
79
|
if (mergeBaseTrimmed === mainHeadTrimmed) {
|
|
70
|
-
|
|
80
|
+
getLogger().success(`Branch is already up to date with ${mainBranch}. No rebase needed.`);
|
|
71
81
|
return;
|
|
72
82
|
}
|
|
73
83
|
const commitsOutput = await executeGitCommand(["log", "--oneline", `${mainBranch}..HEAD`], {
|
|
@@ -76,34 +86,40 @@ Ensure the repository has a "${mainBranch}" branch or create it first.`
|
|
|
76
86
|
const commits = commitsOutput.trim();
|
|
77
87
|
const commitLines = commits ? commits.split("\n") : [];
|
|
78
88
|
if (commits) {
|
|
79
|
-
|
|
80
|
-
commitLines.forEach((commit) =>
|
|
89
|
+
getLogger().info(`Found ${commitLines.length} commit(s) to rebase:`);
|
|
90
|
+
commitLines.forEach((commit) => getLogger().info(` ${commit}`));
|
|
81
91
|
} else {
|
|
82
|
-
|
|
92
|
+
getLogger().info(`${mainBranch} branch has moved forward. Rebasing to update branch...`);
|
|
83
93
|
}
|
|
84
94
|
if (!force && !dryRun) {
|
|
85
|
-
|
|
95
|
+
getLogger().info("Proceeding with rebase... (use --force to skip confirmations)");
|
|
86
96
|
}
|
|
87
97
|
if (dryRun) {
|
|
88
|
-
|
|
98
|
+
getLogger().info(`[DRY RUN] Would execute: git rebase ${mainBranch}`);
|
|
89
99
|
if (commitLines.length > 0) {
|
|
90
|
-
|
|
100
|
+
getLogger().info(`[DRY RUN] This would rebase ${commitLines.length} commit(s)`);
|
|
91
101
|
}
|
|
92
102
|
return;
|
|
93
103
|
}
|
|
94
104
|
try {
|
|
95
105
|
await executeGitCommand(["rebase", mainBranch], { cwd: worktreePath });
|
|
96
|
-
|
|
106
|
+
getLogger().success("Rebase completed successfully!");
|
|
107
|
+
if (wipCommitHash) {
|
|
108
|
+
await this.restoreWipCommit(worktreePath, wipCommitHash);
|
|
109
|
+
}
|
|
97
110
|
} catch (error) {
|
|
98
111
|
const conflictedFiles = await this.detectConflictedFiles(worktreePath);
|
|
99
112
|
if (conflictedFiles.length > 0) {
|
|
100
|
-
|
|
113
|
+
getLogger().info("Merge conflicts detected, attempting Claude-assisted resolution...");
|
|
101
114
|
const resolved = await this.attemptClaudeConflictResolution(
|
|
102
115
|
worktreePath,
|
|
103
116
|
conflictedFiles
|
|
104
117
|
);
|
|
105
118
|
if (resolved) {
|
|
106
|
-
|
|
119
|
+
getLogger().success("Conflicts resolved with Claude assistance, rebase completed");
|
|
120
|
+
if (wipCommitHash) {
|
|
121
|
+
await this.restoreWipCommit(worktreePath, wipCommitHash);
|
|
122
|
+
}
|
|
107
123
|
return;
|
|
108
124
|
}
|
|
109
125
|
const conflictError = this.formatConflictError(conflictedFiles);
|
|
@@ -158,10 +174,20 @@ To fix this:
|
|
|
158
174
|
*/
|
|
159
175
|
async performFastForwardMerge(branchName, worktreePath, options = {}) {
|
|
160
176
|
const { dryRun = false, force = false } = options;
|
|
161
|
-
|
|
162
|
-
const mainWorktreePath = options.repoRoot ?? await findMainWorktreePathWithSettings(worktreePath, this.settingsManager);
|
|
177
|
+
getLogger().info("Starting fast-forward merge...");
|
|
163
178
|
const mainBranch = await this.getMainBranch(worktreePath);
|
|
164
|
-
|
|
179
|
+
let mainWorktreePath;
|
|
180
|
+
if (options.repoRoot) {
|
|
181
|
+
mainWorktreePath = options.repoRoot;
|
|
182
|
+
} else {
|
|
183
|
+
try {
|
|
184
|
+
mainWorktreePath = await findWorktreeForBranch(mainBranch, worktreePath);
|
|
185
|
+
} catch {
|
|
186
|
+
getLogger().debug(`No worktree found for branch '${mainBranch}', falling back to settings-based lookup`);
|
|
187
|
+
mainWorktreePath = await findMainWorktreePathWithSettings(worktreePath, this.settingsManager);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
getLogger().debug(`Using ${mainBranch} branch location: ${mainWorktreePath}`);
|
|
165
191
|
const currentBranch = await executeGitCommand(["branch", "--show-current"], {
|
|
166
192
|
cwd: mainWorktreePath
|
|
167
193
|
});
|
|
@@ -178,24 +204,24 @@ This indicates the main worktree detection failed.`
|
|
|
178
204
|
});
|
|
179
205
|
const commits = commitsOutput.trim();
|
|
180
206
|
if (!commits) {
|
|
181
|
-
|
|
207
|
+
getLogger().success(`Branch has no commits ahead of ${mainBranch}. No merge needed.`);
|
|
182
208
|
return;
|
|
183
209
|
}
|
|
184
210
|
const commitLines = commits.split("\n");
|
|
185
|
-
|
|
186
|
-
commitLines.forEach((commit) =>
|
|
211
|
+
getLogger().info(`Found ${commitLines.length} commit(s) to merge:`);
|
|
212
|
+
commitLines.forEach((commit) => getLogger().info(` ${commit}`));
|
|
187
213
|
if (!force && !dryRun) {
|
|
188
|
-
|
|
214
|
+
getLogger().info("Proceeding with fast-forward merge... (use --force to skip confirmations)");
|
|
189
215
|
}
|
|
190
216
|
if (dryRun) {
|
|
191
|
-
|
|
192
|
-
|
|
217
|
+
getLogger().info(`[DRY RUN] Would execute: git merge --ff-only ${branchName}`);
|
|
218
|
+
getLogger().info(`[DRY RUN] This would merge ${commitLines.length} commit(s)`);
|
|
193
219
|
return;
|
|
194
220
|
}
|
|
195
221
|
try {
|
|
196
|
-
|
|
222
|
+
getLogger().debug(`Executing fast-forward merge of ${branchName} into ${mainBranch} using cwd: ${mainWorktreePath}...`);
|
|
197
223
|
await executeGitCommand(["merge", "--ff-only", branchName], { cwd: mainWorktreePath });
|
|
198
|
-
|
|
224
|
+
getLogger().success(`Fast-forward merge completed! Merged ${commitLines.length} commit(s).`);
|
|
199
225
|
} catch (error) {
|
|
200
226
|
throw new Error(
|
|
201
227
|
`Fast-forward merge failed: ${error instanceof Error ? error.message : String(error)}
|
|
@@ -222,6 +248,39 @@ To recover:
|
|
|
222
248
|
return [];
|
|
223
249
|
}
|
|
224
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Create a temporary WIP commit to preserve uncommitted changes during rebase
|
|
253
|
+
* Stages all changes (tracked, untracked) using git add -A
|
|
254
|
+
* @param worktreePath - Path to the worktree
|
|
255
|
+
* @returns The commit hash of the WIP commit
|
|
256
|
+
* @private
|
|
257
|
+
*/
|
|
258
|
+
async createWipCommit(worktreePath) {
|
|
259
|
+
await executeGitCommand(["add", "-A"], { cwd: worktreePath });
|
|
260
|
+
await executeGitCommand(["commit", "-m", "WIP: Auto-stash for rebase"], { cwd: worktreePath });
|
|
261
|
+
const hash = await executeGitCommand(["rev-parse", "HEAD"], { cwd: worktreePath });
|
|
262
|
+
return hash.trim();
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Restore uncommitted changes from WIP commit via soft reset
|
|
266
|
+
* Logs warning but does not fail if soft reset fails (changes are safe in commit history)
|
|
267
|
+
* @param worktreePath - Path to the worktree
|
|
268
|
+
* @param wipCommitHash - Original WIP commit hash for verification logging
|
|
269
|
+
* @private
|
|
270
|
+
*/
|
|
271
|
+
async restoreWipCommit(worktreePath, wipCommitHash) {
|
|
272
|
+
getLogger().info("Restoring uncommitted changes from WIP commit...");
|
|
273
|
+
try {
|
|
274
|
+
await executeGitCommand(["reset", "--soft", "HEAD~1"], { cwd: worktreePath });
|
|
275
|
+
await executeGitCommand(["reset", "HEAD"], { cwd: worktreePath });
|
|
276
|
+
getLogger().success("Restored uncommitted changes from WIP commit");
|
|
277
|
+
} catch (error) {
|
|
278
|
+
getLogger().warn(
|
|
279
|
+
`Failed to restore WIP commit (${wipCommitHash}). Your changes are safe in the commit history. Manual recovery: git reset --soft HEAD~1`,
|
|
280
|
+
{ error: error instanceof Error ? error.message : String(error) }
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
225
284
|
/**
|
|
226
285
|
* Helper: Format conflict error message with manual resolution steps
|
|
227
286
|
* @private
|
|
@@ -242,32 +301,34 @@ To recover:
|
|
|
242
301
|
async attemptClaudeConflictResolution(worktreePath, conflictedFiles) {
|
|
243
302
|
const isClaudeAvailable = await detectClaudeCli();
|
|
244
303
|
if (!isClaudeAvailable) {
|
|
245
|
-
|
|
304
|
+
getLogger().debug("Claude CLI not available, skipping conflict resolution");
|
|
246
305
|
return false;
|
|
247
306
|
}
|
|
248
|
-
|
|
249
|
-
const
|
|
307
|
+
getLogger().info(`Launching Claude to resolve conflicts in ${conflictedFiles.length} file(s)...`);
|
|
308
|
+
const systemPrompt = `Please help resolve the git rebase conflicts in this repository. Analyze the conflicted files, understand the changes from both branches, fix the conflicts, then run 'git add .' to stage the resolved files, and finally run 'git rebase --continue' to continue the rebase process. Once the issue is resolved, tell the user they can use /exit to continue with the process.`;
|
|
309
|
+
const prompt = `Help me with this rebase please.`;
|
|
250
310
|
try {
|
|
251
311
|
await launchClaude(prompt, {
|
|
312
|
+
appendSystemPrompt: systemPrompt,
|
|
252
313
|
addDir: worktreePath,
|
|
253
314
|
headless: false
|
|
254
315
|
// Interactive - runs in current terminal with stdio: inherit
|
|
255
316
|
});
|
|
256
317
|
const remainingConflicts = await this.detectConflictedFiles(worktreePath);
|
|
257
318
|
if (remainingConflicts.length > 0) {
|
|
258
|
-
|
|
319
|
+
getLogger().warn(
|
|
259
320
|
`Conflicts still exist in ${remainingConflicts.length} file(s) after Claude assistance`
|
|
260
321
|
);
|
|
261
322
|
return false;
|
|
262
323
|
}
|
|
263
324
|
const rebaseInProgress = await this.isRebaseInProgress(worktreePath);
|
|
264
325
|
if (rebaseInProgress) {
|
|
265
|
-
|
|
326
|
+
getLogger().warn("Rebase still in progress after Claude assistance");
|
|
266
327
|
return false;
|
|
267
328
|
}
|
|
268
329
|
return true;
|
|
269
330
|
} catch (error) {
|
|
270
|
-
|
|
331
|
+
getLogger().warn("Claude conflict resolution failed", {
|
|
271
332
|
error: error instanceof Error ? error.message : String(error)
|
|
272
333
|
});
|
|
273
334
|
return false;
|
|
@@ -304,4 +365,4 @@ To recover:
|
|
|
304
365
|
export {
|
|
305
366
|
MergeManager
|
|
306
367
|
};
|
|
307
|
-
//# sourceMappingURL=chunk-
|
|
368
|
+
//# sourceMappingURL=chunk-LTNDJMTH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/MergeManager.ts"],"sourcesContent":["import { executeGitCommand, findMainWorktreePathWithSettings, findWorktreeForBranch, getMergeTargetBranch } from '../utils/git.js'\nimport { getLogger } from '../utils/logger-context.js'\nimport { detectClaudeCli, launchClaude } from '../utils/claude.js'\nimport { SettingsManager } from './SettingsManager.js'\nimport { MetadataManager } from './MetadataManager.js'\nimport type { MergeOptions } from '../types/index.js'\n\n/**\n * MergeManager handles Git rebase and fast-forward merge operations\n * Implements fail-fast behavior for conflicts (Phase 1 - no Claude assistance)\n *\n * Ports bash/merge-and-clean.sh lines 781-1090\n */\nexport class MergeManager {\n\tprivate settingsManager: SettingsManager\n\tprivate metadataManager: MetadataManager\n\n\tconstructor(settingsManager?: SettingsManager, metadataManager?: MetadataManager) {\n\t\tthis.settingsManager = settingsManager ?? new SettingsManager()\n\t\tthis.metadataManager = metadataManager ?? new MetadataManager()\n\t}\n\n\t/**\n\t * Get the merge target branch for a loom\n\t * Priority: parent loom metadata > configured main branch > 'main'\n\t * @param worktreePath - Optional path to load settings/metadata from (defaults to process.cwd())\n\t * @private\n\t */\n\tprivate async getMainBranch(worktreePath?: string): Promise<string> {\n\t\t// Delegate to shared utility function\n\t\treturn getMergeTargetBranch(worktreePath ?? process.cwd(), {\n\t\t\tsettingsManager: this.settingsManager,\n\t\t\tmetadataManager: this.metadataManager,\n\t\t})\n\t}\n\n\t/**\n\t * Rebase current branch on main with fail-fast on conflicts\n\t * Ports bash/merge-and-clean.sh lines 781-913\n\t *\n\t * @param worktreePath - Path to the worktree\n\t * @param options - Merge options (dryRun, force)\n\t * @throws Error if main branch doesn't exist, uncommitted changes exist, or conflicts occur\n\t */\n\tasync rebaseOnMain(worktreePath: string, options: MergeOptions = {}): Promise<void> {\n\t\tconst { dryRun = false, force = false } = options\n\t\tconst mainBranch = await this.getMainBranch(worktreePath)\n\n\t\tgetLogger().info(`Starting rebase on ${mainBranch} branch...`)\n\n\t\t// Step 1: Check if main branch exists\n\t\ttry {\n\t\t\tawait executeGitCommand(['show-ref', '--verify', '--quiet', `refs/heads/${mainBranch}`], {\n\t\t\t\tcwd: worktreePath,\n\t\t\t})\n\t\t} catch {\n\t\t\tthrow new Error(\n\t\t\t\t`Main branch \"${mainBranch}\" does not exist. Cannot rebase.\\n` +\n\t\t\t\t\t`Ensure the repository has a \"${mainBranch}\" branch or create it first.`\n\t\t\t)\n\t\t}\n\n\t\t// Step 2: Check for uncommitted changes and create WIP commit if needed\n\t\tconst statusOutput = await executeGitCommand(['status', '--porcelain'], {\n\t\t\tcwd: worktreePath,\n\t\t})\n\n\t\tlet wipCommitHash: string | null = null\n\t\tif (statusOutput.trim()) {\n\t\t\tgetLogger().info('Uncommitted changes detected, creating temporary WIP commit...')\n\t\t\twipCommitHash = await this.createWipCommit(worktreePath)\n\t\t\tgetLogger().debug(`Created WIP commit: ${wipCommitHash}`)\n\t\t}\n\n\t\t// Step 3: Check if rebase is needed by comparing merge-base with main HEAD\n\t\tconst mergeBase = await executeGitCommand(['merge-base', mainBranch, 'HEAD'], {\n\t\t\tcwd: worktreePath,\n\t\t})\n\n\t\tconst mainHead = await executeGitCommand(['rev-parse', mainBranch], {\n\t\t\tcwd: worktreePath,\n\t\t})\n\n\t\tconst mergeBaseTrimmed = mergeBase.trim()\n\t\tconst mainHeadTrimmed = mainHead.trim()\n\n\t\t// If merge-base matches main HEAD, branch is already up to date\n\t\tif (mergeBaseTrimmed === mainHeadTrimmed) {\n\t\t\tgetLogger().success(`Branch is already up to date with ${mainBranch}. No rebase needed.`)\n\t\t\treturn\n\t\t}\n\n\t\t// Step 4: Show commits to be rebased (for informational purposes)\n\t\tconst commitsOutput = await executeGitCommand(['log', '--oneline', `${mainBranch}..HEAD`], {\n\t\t\tcwd: worktreePath,\n\t\t})\n\n\t\tconst commits = commitsOutput.trim()\n\t\tconst commitLines = commits ? commits.split('\\n') : []\n\n\t\tif (commits) {\n\t\t\t// Show commits that will be rebased\n\t\t\tgetLogger().info(`Found ${commitLines.length} commit(s) to rebase:`)\n\t\t\tcommitLines.forEach((commit) => getLogger().info(` ${commit}`))\n\t\t} else {\n\t\t\t// Main has moved forward but branch has no new commits\n\t\t\tgetLogger().info(`${mainBranch} branch has moved forward. Rebasing to update branch...`)\n\t\t}\n\n\t\t// Step 5: User confirmation (unless force mode or dry-run)\n\t\tif (!force && !dryRun) {\n\t\t\t// TODO: Implement interactive prompt for confirmation\n\t\t\t// For now, proceeding automatically (use --force to skip this message)\n\t\t\tgetLogger().info('Proceeding with rebase... (use --force to skip confirmations)')\n\t\t}\n\n\t\t// Step 6: Execute rebase (unless dry-run)\n\t\tif (dryRun) {\n\t\t\tgetLogger().info(`[DRY RUN] Would execute: git rebase ${mainBranch}`)\n\t\t\tif (commitLines.length > 0) {\n\t\t\t\tgetLogger().info(`[DRY RUN] This would rebase ${commitLines.length} commit(s)`)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\t// Execute rebase\n\t\ttry {\n\t\t\tawait executeGitCommand(['rebase', mainBranch], { cwd: worktreePath })\n\t\t\tgetLogger().success('Rebase completed successfully!')\n\n\t\t\t// Restore WIP commit if created\n\t\t\tif (wipCommitHash) {\n\t\t\t\tawait this.restoreWipCommit(worktreePath, wipCommitHash)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// Detect conflicts\n\t\t\tconst conflictedFiles = await this.detectConflictedFiles(worktreePath)\n\n\t\t\tif (conflictedFiles.length > 0) {\n\t\t\t\t// Try Claude-assisted resolution first\n\t\t\t\tgetLogger().info('Merge conflicts detected, attempting Claude-assisted resolution...')\n\n\t\t\t\tconst resolved = await this.attemptClaudeConflictResolution(\n\t\t\t\t\tworktreePath,\n\t\t\t\t\tconflictedFiles\n\t\t\t\t)\n\n\t\t\t\tif (resolved) {\n\t\t\t\t\tgetLogger().success('Conflicts resolved with Claude assistance, rebase completed')\n\n\t\t\t\t\t// Restore WIP commit if created\n\t\t\t\t\tif (wipCommitHash) {\n\t\t\t\t\t\tawait this.restoreWipCommit(worktreePath, wipCommitHash)\n\t\t\t\t\t}\n\t\t\t\t\treturn // Continue with successful rebase\n\t\t\t\t}\n\n\t\t\t\t// Claude couldn't resolve or not available - fail fast\n\t\t\t\tconst conflictError = this.formatConflictError(conflictedFiles)\n\t\t\t\tthrow new Error(conflictError)\n\t\t\t}\n\n\t\t\t// If not a conflict, re-throw the original error\n\t\t\tthrow new Error(\n\t\t\t\t`Rebase failed: ${error instanceof Error ? error.message : String(error)}\\n` +\n\t\t\t\t\t'Run: git status for more details\\n' +\n\t\t\t\t\t'Or: git rebase --abort to cancel the rebase'\n\t\t\t)\n\t\t}\n\t}\n\n\t/**\n\t * Validate that fast-forward merge is possible\n\t * Ports bash/merge-and-clean.sh lines 957-968\n\t *\n\t * @param branchName - Name of the branch to merge\n\t * @param mainWorktreePath - Path where main branch is checked out\n\t * @throws Error if fast-forward is not possible\n\t */\n\tasync validateFastForwardPossible(mainBranch: string, branchName: string, mainWorktreePath: string): Promise<void> {\n\n\t\t// Step 1: Get merge-base between main and branch\n\t\tconst mergeBase = await executeGitCommand(['merge-base', mainBranch, branchName], {\n\t\t\tcwd: mainWorktreePath,\n\t\t})\n\n\t\t// Step 2: Get current HEAD of main\n\t\tconst mainHead = await executeGitCommand(['rev-parse', mainBranch], {\n\t\t\tcwd: mainWorktreePath,\n\t\t})\n\n\t\t// Step 3: Compare - they must match for fast-forward\n\t\tconst mergeBaseTrimmed = mergeBase.trim()\n\t\tconst mainHeadTrimmed = mainHead.trim()\n\n\t\tif (mergeBaseTrimmed !== mainHeadTrimmed) {\n\t\t\tthrow new Error(\n\t\t\t\t'Cannot perform fast-forward merge.\\n' +\n\t\t\t\t\t`The ${mainBranch} branch has moved forward since this branch was created.\\n` +\n\t\t\t\t\t`Merge base: ${mergeBaseTrimmed}\\n` +\n\t\t\t\t\t`Main HEAD: ${mainHeadTrimmed}\\n\\n` +\n\t\t\t\t\t'To fix this:\\n' +\n\t\t\t\t\t` 1. Rebase the branch on ${mainBranch}: git rebase ${mainBranch}\\n` +\n\t\t\t\t\t` 2. Or use: il finish to automatically rebase and merge\\n`\n\t\t\t)\n\t\t}\n\t}\n\n\t/**\n\t * Perform fast-forward only merge\n\t * Ports bash/merge-and-clean.sh lines 938-994\n\t *\n\t * @param branchName - Name of the branch to merge\n\t * @param worktreePath - Path to the worktree\n\t * @param options - Merge options (dryRun, force)\n\t * @throws Error if checkout, validation, or merge fails\n\t */\n\tasync performFastForwardMerge(\n\t\tbranchName: string,\n\t\tworktreePath: string,\n\t\toptions: MergeOptions = {}\n\t): Promise<void> {\n\t\tconst { dryRun = false, force = false } = options\n\n\t\tgetLogger().info('Starting fast-forward merge...')\n\n\t\t// Step 1: Get the merge target branch FIRST\n\t\t// For child looms, this will be the parent branch from metadata\n\t\t// For regular looms, this falls back to settings.mainBranch or 'main'\n\t\tconst mainBranch = await this.getMainBranch(worktreePath)\n\n\t\t// Step 2: Find where the merge target branch is checked out\n\t\t// CRITICAL: We must find the worktree for the MERGE TARGET, not settings.mainBranch\n\t\t// This fixes the child loom bug where we'd find the 'main' worktree instead of the parent branch worktree\n\t\tlet mainWorktreePath: string\n\t\tif (options.repoRoot) {\n\t\t\tmainWorktreePath = options.repoRoot\n\t\t} else {\n\t\t\ttry {\n\t\t\t\t// First try to find worktree with the exact merge target branch checked out\n\t\t\t\tmainWorktreePath = await findWorktreeForBranch(mainBranch, worktreePath)\n\t\t\t} catch {\n\t\t\t\t// Fallback: if no worktree has the branch checked out, use settings-based lookup\n\t\t\t\t// This handles edge cases like bare repos or detached HEAD states\n\t\t\t\tgetLogger().debug(`No worktree found for branch '${mainBranch}', falling back to settings-based lookup`)\n\t\t\t\tmainWorktreePath = await findMainWorktreePathWithSettings(worktreePath, this.settingsManager)\n\t\t\t}\n\t\t}\n\n\t\t// Step 3: No need to checkout - the merge target branch is already checked out in mainWorktreePath\n\t\tgetLogger().debug(`Using ${mainBranch} branch location: ${mainWorktreePath}`)\n\n\t\t// Step 4: Verify we're on the correct branch\n\t\tconst currentBranch = await executeGitCommand(['branch', '--show-current'], {\n\t\t\tcwd: mainWorktreePath,\n\t\t})\n\n\t\tif (currentBranch.trim() !== mainBranch) {\n\t\t\tthrow new Error(\n\t\t\t\t`Expected ${mainBranch} branch but found: ${currentBranch.trim()}\\n` +\n\t\t\t\t\t`At location: ${mainWorktreePath}\\n` +\n\t\t\t\t\t'This indicates the main worktree detection failed.'\n\t\t\t)\n\t\t}\n\n\t\t// Step 5: Validate fast-forward is possible\n\t\tawait this.validateFastForwardPossible(mainBranch, branchName, mainWorktreePath)\n\n\t\t// Step 6: Show commits to be merged\n\t\tconst commitsOutput = await executeGitCommand(['log', '--oneline', `${mainBranch}..${branchName}`], {\n\t\t\tcwd: mainWorktreePath,\n\t\t})\n\n\t\tconst commits = commitsOutput.trim()\n\n\t\t// If no commits, branch has no changes ahead of main\n\t\tif (!commits) {\n\t\t\tgetLogger().success(`Branch has no commits ahead of ${mainBranch}. No merge needed.`)\n\t\t\treturn\n\t\t}\n\n\t\t// Show commits that will be merged\n\t\tconst commitLines = commits.split('\\n')\n\t\tgetLogger().info(`Found ${commitLines.length} commit(s) to merge:`)\n\t\tcommitLines.forEach((commit) => getLogger().info(` ${commit}`))\n\n\t\t// Step 7: User confirmation (unless force mode or dry-run)\n\t\tif (!force && !dryRun) {\n\t\t\t// TODO: Implement interactive prompt for confirmation\n\t\t\t// For now, proceeding automatically (use --force to skip this message)\n\t\t\tgetLogger().info('Proceeding with fast-forward merge... (use --force to skip confirmations)')\n\t\t}\n\n\t\t// Step 8: Execute merge (unless dry-run)\n\t\tif (dryRun) {\n\t\t\tgetLogger().info(`[DRY RUN] Would execute: git merge --ff-only ${branchName}`)\n\t\t\tgetLogger().info(`[DRY RUN] This would merge ${commitLines.length} commit(s)`)\n\t\t\treturn\n\t\t}\n\n\t\t// Execute fast-forward merge\n\t\ttry {\n\t\t\tgetLogger().debug(`Executing fast-forward merge of ${branchName} into ${mainBranch} using cwd: ${mainWorktreePath}...`)\n\t\t\tawait executeGitCommand(['merge', '--ff-only', branchName], { cwd: mainWorktreePath })\n\t\t\tgetLogger().success(`Fast-forward merge completed! Merged ${commitLines.length} commit(s).`)\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Fast-forward merge failed: ${error instanceof Error ? error.message : String(error)}\\n\\n` +\n\t\t\t\t\t'To recover:\\n' +\n\t\t\t\t\t' 1. Check merge status: git status\\n' +\n\t\t\t\t\t' 2. Abort merge if needed: git merge --abort\\n' +\n\t\t\t\t\t' 3. Verify branch is rebased: git rebase main\\n' +\n\t\t\t\t\t' 4. Try merge again: il finish'\n\t\t\t)\n\t\t}\n\t}\n\n\t/**\n\t * Helper: Detect conflicted files after failed rebase\n\t * @private\n\t */\n\tprivate async detectConflictedFiles(worktreePath: string): Promise<string[]> {\n\t\ttry {\n\t\t\tconst output = await executeGitCommand(['diff', '--name-only', '--diff-filter=U'], {\n\t\t\t\tcwd: worktreePath,\n\t\t\t})\n\n\t\t\treturn output\n\t\t\t\t.trim()\n\t\t\t\t.split('\\n')\n\t\t\t\t.filter((file) => file.length > 0)\n\t\t} catch {\n\t\t\t// If command fails, return empty array (might not be a conflict)\n\t\t\treturn []\n\t\t}\n\t}\n\n\t/**\n\t * Create a temporary WIP commit to preserve uncommitted changes during rebase\n\t * Stages all changes (tracked, untracked) using git add -A\n\t * @param worktreePath - Path to the worktree\n\t * @returns The commit hash of the WIP commit\n\t * @private\n\t */\n\tprivate async createWipCommit(worktreePath: string): Promise<string> {\n\t\t// Stage all changes including untracked files\n\t\tawait executeGitCommand(['add', '-A'], { cwd: worktreePath })\n\n\t\t// Create WIP commit with distinctive message\n\t\tawait executeGitCommand(['commit', '-m', 'WIP: Auto-stash for rebase'], { cwd: worktreePath })\n\n\t\t// Get and return the commit hash\n\t\tconst hash = await executeGitCommand(['rev-parse', 'HEAD'], { cwd: worktreePath })\n\t\treturn hash.trim()\n\t}\n\n\t/**\n\t * Restore uncommitted changes from WIP commit via soft reset\n\t * Logs warning but does not fail if soft reset fails (changes are safe in commit history)\n\t * @param worktreePath - Path to the worktree\n\t * @param wipCommitHash - Original WIP commit hash for verification logging\n\t * @private\n\t */\n\tprivate async restoreWipCommit(worktreePath: string, wipCommitHash: string): Promise<void> {\n\t\tgetLogger().info('Restoring uncommitted changes from WIP commit...')\n\n\t\ttry {\n\t\t\t// Soft reset to parent - changes become staged\n\t\t\tawait executeGitCommand(['reset', '--soft', 'HEAD~1'], { cwd: worktreePath })\n\n\t\t\t// Unstage files to restore to original working directory state\n\t\t\tawait executeGitCommand(['reset', 'HEAD'], { cwd: worktreePath })\n\n\t\t\tgetLogger().success('Restored uncommitted changes from WIP commit')\n\t\t} catch (error) {\n\t\t\t// Log warning but consider rebase successful - work is not lost\n\t\t\tgetLogger().warn(\n\t\t\t\t`Failed to restore WIP commit (${wipCommitHash}). ` +\n\t\t\t\t\t`Your changes are safe in the commit history. ` +\n\t\t\t\t\t`Manual recovery: git reset --soft HEAD~1`,\n\t\t\t\t{ error: error instanceof Error ? error.message : String(error) }\n\t\t\t)\n\t\t}\n\t}\n\n\t/**\n\t * Helper: Format conflict error message with manual resolution steps\n\t * @private\n\t */\n\tprivate formatConflictError(conflictedFiles: string[]): string {\n\t\tconst fileList = conflictedFiles.map((file) => ` • ${file}`).join('\\n')\n\n\t\treturn (\n\t\t\t'Rebase failed - merge conflicts detected in:\\n' +\n\t\t\tfileList +\n\t\t\t'\\n\\n' +\n\t\t\t'To resolve manually:\\n' +\n\t\t\t' 1. Fix conflicts in the files above\\n' +\n\t\t\t' 2. Stage resolved files: git add <files>\\n' +\n\t\t\t' 3. Continue rebase: git rebase --continue\\n' +\n\t\t\t' 4. Or abort rebase: git rebase --abort\\n' +\n\t\t\t' 5. Then re-run: il finish <issue-number>'\n\t\t)\n\t}\n\n\t/**\n\t * Attempt to resolve conflicts using Claude\n\t * Ports bash/merge-and-clean.sh lines 839-894\n\t *\n\t * @param worktreePath - Path to the worktree\n\t * @param conflictedFiles - List of files with conflicts\n\t * @returns true if conflicts resolved, false otherwise\n\t * @private\n\t */\n\tprivate async attemptClaudeConflictResolution(\n\t\tworktreePath: string,\n\t\tconflictedFiles: string[]\n\t): Promise<boolean> {\n\t\t// Check if Claude CLI is available\n\t\tconst isClaudeAvailable = await detectClaudeCli()\n\t\tif (!isClaudeAvailable) {\n\t\t\tgetLogger().debug('Claude CLI not available, skipping conflict resolution')\n\t\t\treturn false\n\t\t}\n\n\t\tgetLogger().info(`Launching Claude to resolve conflicts in ${conflictedFiles.length} file(s)...`)\n\n\t\t// Hard-coded prompt matching bash script line 844\n\t\t// No templates, no complexity - just the essential instruction\n\t\tconst systemPrompt =\n\t\t\t`Please help resolve the git rebase conflicts in this repository. ` +\n\t\t\t`Analyze the conflicted files, understand the changes from both branches, ` +\n\t\t\t`fix the conflicts, then run 'git add .' to stage the resolved files, ` +\n\t\t\t`and finally run 'git rebase --continue' to continue the rebase process. ` +\n\t\t\t`Once the issue is resolved, tell the user they can use /exit to continue with the process.`\n\n\t\tconst prompt =\n\t\t\t`Help me with this rebase please.`\n\n\t\ttry {\n\t\t\t// Launch Claude interactively in current terminal\n\t\t\t// User will interact directly with Claude to resolve conflicts\n\t\t\tawait launchClaude(prompt, {\n\t\t\t\tappendSystemPrompt: systemPrompt,\n\t\t\t\taddDir: worktreePath,\n\t\t\t\theadless: false, // Interactive - runs in current terminal with stdio: inherit\n\t\t\t})\n\n\t\t\t// After Claude interaction completes, check if conflicts resolved\n\t\t\tconst remainingConflicts = await this.detectConflictedFiles(worktreePath)\n\n\t\t\tif (remainingConflicts.length > 0) {\n\t\t\t\tgetLogger().warn(\n\t\t\t\t\t`Conflicts still exist in ${remainingConflicts.length} file(s) after Claude assistance`\n\t\t\t\t)\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\t// Check if rebase completed or still in progress\n\t\t\tconst rebaseInProgress = await this.isRebaseInProgress(worktreePath)\n\n\t\t\tif (rebaseInProgress) {\n\t\t\t\tgetLogger().warn('Rebase still in progress after Claude assistance')\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\treturn true\n\t\t} catch (error) {\n\t\t\tgetLogger().warn('Claude conflict resolution failed', {\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t})\n\t\t\treturn false\n\t\t}\n\t}\n\n\t/**\n\t * Check if a git rebase is currently in progress\n\t * Checks for .git/rebase-merge or .git/rebase-apply directories\n\t * Ports bash script logic from lines 853-856\n\t *\n\t * @param worktreePath - Path to the worktree\n\t * @returns true if rebase in progress, false otherwise\n\t * @private\n\t */\n\tprivate async isRebaseInProgress(worktreePath: string): Promise<boolean> {\n\t\tconst fs = await import('node:fs/promises')\n\t\tconst path = await import('node:path')\n\n\t\tconst rebaseMergePath = path.join(worktreePath, '.git', 'rebase-merge')\n\t\tconst rebaseApplyPath = path.join(worktreePath, '.git', 'rebase-apply')\n\n\t\t// Check for rebase-merge directory\n\t\ttry {\n\t\t\tawait fs.access(rebaseMergePath)\n\t\t\treturn true\n\t\t} catch {\n\t\t\t// Directory doesn't exist, continue checking\n\t\t}\n\n\t\t// Check for rebase-apply directory\n\t\ttry {\n\t\t\tawait fs.access(rebaseApplyPath)\n\t\t\treturn true\n\t\t} catch {\n\t\t\t// Directory doesn't exist\n\t\t}\n\n\t\treturn false\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAaO,IAAM,eAAN,MAAmB;AAAA,EAIzB,YAAY,iBAAmC,iBAAmC;AACjF,SAAK,kBAAkB,mBAAmB,IAAI,gBAAgB;AAC9D,SAAK,kBAAkB,mBAAmB,IAAI,gBAAgB;AAAA,EAC/D;AAAA;AAAA;AA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;AACxE,UAAM,KAAK,MAAM,OAAO,aAAkB;AAC1C,UAAM,OAAO,MAAM,OAAO,MAAW;AAErC,UAAM,kBAAkB,KAAK,KAAK,cAAc,QAAQ,cAAc;AACtE,UAAM,kBAAkB,KAAK,KAAK,cAAc,QAAQ,cAAc;AAGtE,QAAI;AACH,YAAM,GAAG,OAAO,eAAe;AAC/B,aAAO;AAAA,IACR,QAAQ;AAAA,IAER;AAGA,QAAI;AACH,YAAM,GAAG,OAAO,eAAe;AAC/B,aAAO;AAAA,IACR,QAAQ;AAAA,IAER;AAEA,WAAO;AAAA,EACR;AACD;","names":[]}
|
|
@@ -11,7 +11,10 @@ import {
|
|
|
11
11
|
isPRBranch,
|
|
12
12
|
isValidGitRepo,
|
|
13
13
|
parseWorktreeList
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-TR5MC2U6.js";
|
|
15
|
+
import {
|
|
16
|
+
getLogger
|
|
17
|
+
} from "./chunk-6UIGZD2N.js";
|
|
15
18
|
|
|
16
19
|
// src/lib/GitWorktreeManager.ts
|
|
17
20
|
import path from "path";
|
|
@@ -113,11 +116,10 @@ var GitWorktreeManager = class {
|
|
|
113
116
|
const worktrees = await this.listWorktrees({ porcelain: true });
|
|
114
117
|
const worktree = worktrees.find((wt) => wt.path === worktreePath);
|
|
115
118
|
if (!worktree) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
logger.debug(`Found ${worktrees.length} worktrees:`);
|
|
119
|
+
getLogger().debug(`Looking for worktree path: ${worktreePath}`);
|
|
120
|
+
getLogger().debug(`Found ${worktrees.length} worktrees:`);
|
|
119
121
|
worktrees.forEach((wt, i) => {
|
|
120
|
-
|
|
122
|
+
getLogger().debug(` ${i}: path="${wt.path}", branch="${wt.branch}"`);
|
|
121
123
|
});
|
|
122
124
|
throw new Error(`Worktree not found: ${worktreePath}`);
|
|
123
125
|
}
|
|
@@ -386,4 +388,4 @@ var GitWorktreeManager = class {
|
|
|
386
388
|
export {
|
|
387
389
|
GitWorktreeManager
|
|
388
390
|
};
|
|
389
|
-
//# sourceMappingURL=chunk-
|
|
391
|
+
//# sourceMappingURL=chunk-M5XUCTTJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/GitWorktreeManager.ts"],"sourcesContent":["import path from 'path'\nimport fs from 'fs-extra'\nimport {\n type GitWorktree,\n type WorktreeCreateOptions,\n type WorktreeListOptions,\n type WorktreeValidation,\n type WorktreeStatus,\n type WorktreeCleanupOptions,\n} from '../types/worktree.js'\nimport {\n executeGitCommand,\n parseWorktreeList,\n isPRBranch,\n extractPRNumber,\n generateWorktreePath,\n isValidGitRepo,\n getCurrentBranch,\n getRepoRoot,\n hasUncommittedChanges,\n getDefaultBranch,\n findMainWorktreePathWithSettings,\n} from '../utils/git.js'\nimport { getLogger } from '../utils/logger-context.js'\nimport type { SettingsManager } from './SettingsManager.js'\n\n/**\n * Manages Git worktrees for the iloom CLI\n * Ports functionality from bash scripts into TypeScript\n */\nexport class GitWorktreeManager {\n private readonly _workingDirectory: string\n\n constructor(workingDirectory: string = process.cwd()) {\n this._workingDirectory = workingDirectory\n }\n\n /**\n * Get the working directory for git operations (main worktree path)\n */\n get workingDirectory(): string {\n return this._workingDirectory\n }\n\n /**\n * List all worktrees in the repository\n * Defaults to porcelain format for reliable machine parsing\n * Equivalent to: git worktree list --porcelain\n */\n async listWorktrees(options: WorktreeListOptions = {}): Promise<GitWorktree[]> {\n const args = ['worktree', 'list']\n // Default to porcelain format for consistent parsing (can be disabled with porcelain: false)\n if (options.porcelain !== false) args.push('--porcelain')\n if (options.verbose) args.push('-v')\n\n const output = await executeGitCommand(args, { cwd: this._workingDirectory })\n return parseWorktreeList(output)\n }\n\n /**\n * Find worktree for a specific branch\n * Ports: find_worktree_for_branch() from find-worktree-for-branch.sh\n */\n async findWorktreeForBranch(branchName: string): Promise<GitWorktree | null> {\n const worktrees = await this.listWorktrees()\n return worktrees.find(wt => wt.branch === branchName) ?? null\n }\n\n /**\n * Check if a worktree is the main repository worktree\n * Uses findMainWorktreePathWithSettings to determine the main worktree based on settings.\n *\n * @param worktree - The worktree to check\n * @param settingsManager - SettingsManager instance for loading settings\n * @returns true if the worktree is the main worktree\n */\n async isMainWorktree(worktree: GitWorktree, settingsManager: SettingsManager): Promise<boolean> {\n const mainWorktreePath = await findMainWorktreePathWithSettings(worktree.path, settingsManager)\n return worktree.path === mainWorktreePath\n }\n\n /**\n * Check if a worktree is a PR worktree based on naming patterns\n * Ports: is_pr_worktree() from worktree-utils.sh\n */\n isPRWorktree(worktree: GitWorktree): boolean {\n return isPRBranch(worktree.branch)\n }\n\n /**\n * Get PR number from worktree branch name\n * Ports: get_pr_number_from_worktree() from worktree-utils.sh\n */\n getPRNumberFromWorktree(worktree: GitWorktree): number | null {\n return extractPRNumber(worktree.branch)\n }\n\n /**\n * Create a new worktree\n * Ports worktree creation logic from new-branch-workflow.sh\n * @returns The absolute path to the created worktree\n */\n async createWorktree(options: WorktreeCreateOptions): Promise<string> {\n // Validate inputs\n if (!options.branch) {\n throw new Error('Branch name is required')\n }\n\n // Ensure path is absolute\n const absolutePath = path.resolve(options.path)\n\n // Check if path already exists and handle force flag\n if (await fs.pathExists(absolutePath)) {\n if (!options.force) {\n throw new Error(`Path already exists: ${absolutePath}`)\n }\n // Remove existing directory if force is true\n await fs.remove(absolutePath)\n }\n\n // Build git worktree add command\n const args = ['worktree', 'add']\n\n if (options.createBranch) {\n args.push('-b', options.branch)\n }\n\n if (options.force) {\n args.push('--force')\n }\n\n args.push(absolutePath)\n\n // Add branch name if not creating new branch\n if (!options.createBranch) {\n args.push(options.branch)\n } else if (options.baseBranch) {\n args.push(options.baseBranch)\n }\n\n await executeGitCommand(args, { cwd: this._workingDirectory })\n return absolutePath\n }\n\n /**\n * Remove a worktree and optionally clean up associated files\n * Ports worktree removal logic from cleanup-worktree.sh\n * @returns A message describing what was done (for dry-run mode)\n */\n async removeWorktree(\n worktreePath: string,\n options: WorktreeCleanupOptions = {}\n ): Promise<string | void> {\n // Validate worktree exists - use porcelain format for consistent parsing\n const worktrees = await this.listWorktrees({ porcelain: true })\n const worktree = worktrees.find(wt => wt.path === worktreePath)\n\n if (!worktree) {\n // Add debug logging to help diagnose the issue\n getLogger().debug(`Looking for worktree path: ${worktreePath}`)\n getLogger().debug(`Found ${worktrees.length} worktrees:`)\n worktrees.forEach((wt, i) => {\n getLogger().debug(` ${i}: path=\"${wt.path}\", branch=\"${wt.branch}\"`)\n })\n throw new Error(`Worktree not found: ${worktreePath}`)\n }\n\n // Check for uncommitted changes unless force is specified\n if (!options.force && !options.dryRun) {\n const hasChanges = await hasUncommittedChanges(worktreePath)\n if (hasChanges) {\n throw new Error(`Worktree has uncommitted changes: ${worktreePath}. Use --force to override.`)\n }\n }\n\n if (options.dryRun) {\n const actions = ['Remove worktree registration']\n if (options.removeDirectory) actions.push('Remove directory from disk')\n if (options.removeBranch) actions.push(`Remove branch: ${worktree.branch}`)\n\n return `Would perform: ${actions.join(', ')}`\n }\n\n // Remove worktree registration\n const args = ['worktree', 'remove']\n if (options.force) args.push('--force')\n args.push(worktreePath)\n\n await executeGitCommand(args, { cwd: this._workingDirectory })\n\n // Remove directory if requested\n if (options.removeDirectory && (await fs.pathExists(worktreePath))) {\n await fs.remove(worktreePath)\n }\n\n // Remove branch if requested and safe to do so\n if (options.removeBranch && !worktree.bare) {\n try {\n await executeGitCommand(['branch', '-D', worktree.branch], {\n cwd: this._workingDirectory,\n })\n } catch (error) {\n // Don't fail the whole operation if branch deletion fails\n // Just log a warning (caller can handle this)\n throw new Error(\n `Worktree removed but failed to delete branch ${worktree.branch}: ${error instanceof Error ? error.message : 'Unknown error'}`\n )\n }\n }\n }\n\n /**\n * Validate worktree state and integrity\n */\n async validateWorktree(worktreePath: string): Promise<WorktreeValidation> {\n const issues: string[] = []\n let existsOnDisk = false\n let isValidRepo = false\n let hasValidBranch = false\n\n try {\n // Check if path exists on disk\n existsOnDisk = await fs.pathExists(worktreePath)\n if (!existsOnDisk) {\n issues.push('Worktree directory does not exist on disk')\n }\n\n // Check if it's a valid Git repository\n if (existsOnDisk) {\n isValidRepo = await isValidGitRepo(worktreePath)\n if (!isValidRepo) {\n issues.push('Directory is not a valid Git repository')\n }\n }\n\n // Check if branch reference is valid\n if (isValidRepo) {\n const currentBranch = await getCurrentBranch(worktreePath)\n hasValidBranch = currentBranch !== null\n if (!hasValidBranch) {\n issues.push('Could not determine current branch')\n }\n }\n\n // Check if worktree is registered with Git\n const worktrees = await this.listWorktrees()\n const isRegistered = worktrees.some(wt => wt.path === worktreePath)\n if (!isRegistered) {\n issues.push('Worktree is not registered with Git')\n }\n } catch (error) {\n issues.push(`Validation error: ${error instanceof Error ? error.message : 'Unknown error'}`)\n }\n\n return {\n isValid: issues.length === 0,\n issues,\n existsOnDisk,\n isValidRepo,\n hasValidBranch,\n }\n }\n\n /**\n * Get detailed status information for a worktree\n */\n async getWorktreeStatus(worktreePath: string): Promise<WorktreeStatus> {\n const statusOutput = await executeGitCommand(['status', '--porcelain=v1'], {\n cwd: worktreePath,\n })\n\n let modified = 0\n let staged = 0\n let deleted = 0\n let untracked = 0\n\n const lines = statusOutput.trim().split('\\n').filter(Boolean)\n for (const line of lines) {\n const status = line.substring(0, 2)\n if (status[0] === 'M' || status[1] === 'M') modified++\n if (status[0] === 'A' || status[0] === 'D' || status[0] === 'R') staged++\n if (status[0] === 'D' || status[1] === 'D') deleted++\n if (status === '??') untracked++\n }\n\n const currentBranch = (await getCurrentBranch(worktreePath)) ?? 'unknown'\n const detached = currentBranch === 'unknown'\n\n // Get ahead/behind information\n let ahead = 0\n let behind = 0\n try {\n const aheadBehindOutput = await executeGitCommand(\n ['rev-list', '--left-right', '--count', `origin/${currentBranch}...HEAD`],\n { cwd: worktreePath }\n )\n const parts = aheadBehindOutput.trim().split('\\t')\n const behindStr = parts[0]\n const aheadStr = parts[1]\n behind = behindStr ? parseInt(behindStr, 10) || 0 : 0\n ahead = aheadStr ? parseInt(aheadStr, 10) || 0 : 0\n } catch {\n // Ignore errors for ahead/behind calculation\n }\n\n return {\n modified,\n staged,\n deleted,\n untracked,\n hasChanges: modified + staged + deleted + untracked > 0,\n branch: currentBranch,\n detached,\n ahead,\n behind,\n }\n }\n\n /**\n * Generate a suggested worktree path for a branch\n */\n generateWorktreePath(\n branchName: string,\n customRoot?: string,\n options?: { isPR?: boolean; prNumber?: number; prefix?: string }\n ): string {\n const root = customRoot ?? this._workingDirectory\n return generateWorktreePath(branchName, root, options)\n }\n\n /**\n * Sanitize a branch name for use as a directory name\n * Replaces slashes with dashes and removes invalid filesystem characters\n * Ports logic from bash script line 593: ${BRANCH_NAME//\\\\//-}\n */\n sanitizeBranchName(branchName: string): string {\n return branchName\n .replace(/\\//g, '-') // Replace slashes with dashes\n .replace(/[^a-zA-Z0-9-]/g, '-') // Replace invalid chars (including underscores) with dashes\n .replace(/-+/g, '-') // Collapse multiple dashes\n .replace(/^-|-$/g, '') // Remove leading/trailing dashes\n .toLowerCase()\n }\n\n /**\n * Check if repository is in a valid state for worktree operations\n */\n async isRepoReady(): Promise<boolean> {\n try {\n const repoRoot = await getRepoRoot(this._workingDirectory)\n return repoRoot !== null\n } catch {\n return false\n }\n }\n\n /**\n * Get repository information\n */\n async getRepoInfo(): Promise<{\n root: string | null\n defaultBranch: string\n currentBranch: string | null\n }> {\n const root = await getRepoRoot(this._workingDirectory)\n const defaultBranch = await getDefaultBranch(this._workingDirectory)\n const currentBranch = await getCurrentBranch(this._workingDirectory)\n\n return {\n root,\n defaultBranch,\n currentBranch,\n }\n }\n\n /**\n * Prune stale worktree entries (worktrees that no longer exist on disk)\n */\n async pruneWorktrees(): Promise<void> {\n await executeGitCommand(['worktree', 'prune', '-v'], { cwd: this._workingDirectory })\n }\n\n /**\n * Lock a worktree to prevent it from being pruned or moved\n */\n async lockWorktree(worktreePath: string, reason?: string): Promise<void> {\n const args = ['worktree', 'lock', worktreePath]\n if (reason) args.push('--reason', reason)\n\n await executeGitCommand(args, { cwd: this._workingDirectory })\n }\n\n /**\n * Unlock a previously locked worktree\n */\n async unlockWorktree(worktreePath: string): Promise<void> {\n await executeGitCommand(['worktree', 'unlock', worktreePath], { cwd: this._workingDirectory })\n }\n\n /**\n * Find worktrees matching an identifier (branch name, path, or PR number)\n */\n async findWorktreesByIdentifier(identifier: string): Promise<GitWorktree[]> {\n const worktrees = await this.listWorktrees({ porcelain: true })\n return worktrees.filter(\n wt =>\n wt.branch.includes(identifier) ||\n wt.path.includes(identifier) ||\n this.getPRNumberFromWorktree(wt)?.toString() === identifier\n )\n }\n\n /**\n * Find worktree for a specific issue number using exact pattern matching\n * Matches: issue-{N} at start OR after /, -, _ (but NOT issue-{N}X where X is a digit)\n * Supports patterns like: issue-44, feat/issue-44-feature, feat-issue-44, bugfix_issue-44, etc.\n * Avoids false matches like: tissue-44, myissue-44\n * Ports: find_existing_worktree() from bash script lines 131-165\n */\n async findWorktreeForIssue(issueNumber: string | number): Promise<GitWorktree | null> {\n const worktrees = await this.listWorktrees({ porcelain: true })\n\n // Pattern: starts with 'issue-{N}' OR has '/issue-{N}', '-issue-{N}', '_issue-{N}' but not 'issue-{N}{digit}'\n // Case-insensitive to handle Linear IDs (MARK-1 vs mark-1)\n const pattern = new RegExp(`(?:^|[/_-])issue-${issueNumber}(?:-|__|$)`, 'i')\n\n return worktrees.find(wt => pattern.test(wt.branch)) ?? null\n }\n\n /**\n * Find worktree for a specific PR by branch name\n * Ports: find_existing_worktree() for PR type from bash script lines 149-160\n */\n async findWorktreeForPR(prNumber: number, branchName: string): Promise<GitWorktree | null> {\n const worktrees = await this.listWorktrees({ porcelain: true })\n\n // Find by exact branch name match (prioritized)\n const byBranch = worktrees.find(wt => wt.branch === branchName)\n if (byBranch) return byBranch\n\n // Also check directory name pattern: *_pr_{N}\n const pathPattern = new RegExp(`_pr_${prNumber}$`)\n return worktrees.find(wt => pathPattern.test(wt.path)) ?? null\n }\n\n /**\n * Remove multiple worktrees\n * Returns a summary of successes and failures\n * Automatically filters out the main worktree\n *\n * @param worktrees - Array of worktrees to remove\n * @param settingsManager - SettingsManager instance for determining main worktree\n * @param options - Cleanup options\n */\n async removeWorktrees(\n worktrees: GitWorktree[],\n settingsManager: SettingsManager,\n options: WorktreeCleanupOptions = {}\n ): Promise<{\n successes: Array<{ worktree: GitWorktree }>\n failures: Array<{ worktree: GitWorktree; error: string }>\n skipped: Array<{ worktree: GitWorktree; reason: string }>\n }> {\n const successes: Array<{ worktree: GitWorktree }> = []\n const failures: Array<{ worktree: GitWorktree; error: string }> = []\n const skipped: Array<{ worktree: GitWorktree; reason: string }> = []\n\n for (const worktree of worktrees) {\n // Skip main worktree\n if (await this.isMainWorktree(worktree, settingsManager)) {\n skipped.push({ worktree, reason: 'Cannot remove main worktree' })\n continue\n }\n\n try {\n await this.removeWorktree(worktree.path, {\n ...options,\n removeDirectory: true,\n })\n successes.push({ worktree })\n } catch (error) {\n failures.push({\n worktree,\n error: error instanceof Error ? error.message : 'Unknown error',\n })\n }\n }\n\n return { successes, failures, skipped }\n }\n\n /**\n * Format worktree information for display\n */\n formatWorktree(worktree: GitWorktree): {\n title: string\n path: string\n commit: string\n } {\n const prNumber = this.getPRNumberFromWorktree(worktree)\n const prLabel = prNumber ? ` (PR #${prNumber})` : ''\n const bareLabel = worktree.bare ? ' [main]' : ''\n\n return {\n title: `${worktree.branch}${prLabel}${bareLabel}`,\n path: worktree.path,\n commit: worktree.commit.substring(0, 7),\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AA6BR,IAAM,qBAAN,MAAyB;AAAA,EAG9B,YAAY,mBAA2B,QAAQ,IAAI,GAAG;AACpD,SAAK,oBAAoB;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,mBAA2B;AAC7B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,cAAc,UAA+B,CAAC,GAA2B;AAC7E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AA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,gBACJ,WACA,iBACA,UAAkC,CAAC,GAKlC;AACD,UAAM,YAA8C,CAAC;AACrD,UAAM,WAA4D,CAAC;AACnE,UAAM,UAA4D,CAAC;AAEnE,eAAW,YAAY,WAAW;AAEhC,UAAI,MAAM,KAAK,eAAe,UAAU,eAAe,GAAG;AACxD,gBAAQ,KAAK,EAAE,UAAU,QAAQ,8BAA8B,CAAC;AAChE;AAAA,MACF;AAEA,UAAI;AACF,cAAM,KAAK,eAAe,SAAS,MAAM;AAAA,UACvC,GAAG;AAAA,UACH,iBAAiB;AAAA,QACnB,CAAC;AACD,kBAAU,KAAK,EAAE,SAAS,CAAC;AAAA,MAC7B,SAAS,OAAO;AACd,iBAAS,KAAK;AAAA,UACZ;AAAA,UACA,OAAO,iBAAiB,QAAQ,MAAM,UAAU;AAAA,QAClD,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO,EAAE,WAAW,UAAU,QAAQ;AAAA,EACxC;AAAA;AAAA;AAAA;AAAA,EAKA,eAAe,UAIb;AACA,UAAM,WAAW,KAAK,wBAAwB,QAAQ;AACtD,UAAM,UAAU,WAAW,SAAS,QAAQ,MAAM;AAClD,UAAM,YAAY,SAAS,OAAO,YAAY;AAE9C,WAAO;AAAA,MACL,OAAO,GAAG,SAAS,MAAM,GAAG,OAAO,GAAG,SAAS;AAAA,MAC/C,MAAM,SAAS;AAAA,MACf,QAAQ,SAAS,OAAO,UAAU,GAAG,CAAC;AAAA,IACxC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
logger
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-UYVWLISQ.js";
|
|
5
5
|
|
|
6
6
|
// src/utils/update-notifier.ts
|
|
7
7
|
import os from "os";
|
|
@@ -200,4 +200,4 @@ export {
|
|
|
200
200
|
UpdateNotifier,
|
|
201
201
|
checkAndNotifyUpdate
|
|
202
202
|
};
|
|
203
|
-
//# sourceMappingURL=chunk-
|
|
203
|
+
//# sourceMappingURL=chunk-MD6HA5IK.js.map
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
getLogger
|
|
4
|
+
} from "./chunk-6UIGZD2N.js";
|
|
5
|
+
|
|
6
|
+
// src/lib/MetadataManager.ts
|
|
7
|
+
import path from "path";
|
|
8
|
+
import os from "os";
|
|
9
|
+
import fs from "fs-extra";
|
|
10
|
+
var MetadataManager = class {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.loomsDir = path.join(os.homedir(), ".config", "iloom-ai", "looms");
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Convert worktree path to filename slug per spec section 2.2
|
|
16
|
+
*
|
|
17
|
+
* Algorithm:
|
|
18
|
+
* 1. Trim trailing slashes
|
|
19
|
+
* 2. Replace all path separators (/ or \) with __ (double underscore)
|
|
20
|
+
* 3. Replace any other non-alphanumeric characters (except _ and -) with -
|
|
21
|
+
* 4. Append .json
|
|
22
|
+
*
|
|
23
|
+
* Example:
|
|
24
|
+
* - Worktree: /Users/jane/dev/repo
|
|
25
|
+
* - Filename: _Users__jane__dev__repo.json
|
|
26
|
+
*/
|
|
27
|
+
slugifyPath(worktreePath) {
|
|
28
|
+
let slug = worktreePath.replace(/[/\\]+$/, "");
|
|
29
|
+
slug = slug.replace(/[/\\]/g, "___");
|
|
30
|
+
slug = slug.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
31
|
+
return `${slug}.json`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get the full path to the metadata file for a worktree
|
|
35
|
+
*/
|
|
36
|
+
getFilePath(worktreePath) {
|
|
37
|
+
const filename = this.slugifyPath(worktreePath);
|
|
38
|
+
return path.join(this.loomsDir, filename);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Write metadata for a worktree (spec section 3.1)
|
|
42
|
+
*
|
|
43
|
+
* @param worktreePath - Absolute path to the worktree (used for file naming)
|
|
44
|
+
* @param input - Metadata to write (description plus additional fields)
|
|
45
|
+
*/
|
|
46
|
+
async writeMetadata(worktreePath, input) {
|
|
47
|
+
try {
|
|
48
|
+
await fs.ensureDir(this.loomsDir, { mode: 493 });
|
|
49
|
+
const content = {
|
|
50
|
+
description: input.description,
|
|
51
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
52
|
+
version: 1,
|
|
53
|
+
branchName: input.branchName,
|
|
54
|
+
worktreePath: input.worktreePath,
|
|
55
|
+
issueType: input.issueType,
|
|
56
|
+
issue_numbers: input.issue_numbers,
|
|
57
|
+
pr_numbers: input.pr_numbers,
|
|
58
|
+
issueTracker: input.issueTracker,
|
|
59
|
+
colorHex: input.colorHex,
|
|
60
|
+
sessionId: input.sessionId,
|
|
61
|
+
...input.parentLoom && { parentLoom: input.parentLoom }
|
|
62
|
+
};
|
|
63
|
+
const filePath = this.getFilePath(worktreePath);
|
|
64
|
+
await fs.writeFile(filePath, JSON.stringify(content, null, 2), { mode: 420 });
|
|
65
|
+
getLogger().debug(`Metadata written for worktree: ${worktreePath}`);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
getLogger().warn(
|
|
68
|
+
`Failed to write metadata for worktree: ${error instanceof Error ? error.message : String(error)}`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Read metadata for a worktree (spec section 3.2)
|
|
74
|
+
*
|
|
75
|
+
* @param worktreePath - Absolute path to the worktree
|
|
76
|
+
* @returns The metadata object with all fields, or null if not found/invalid
|
|
77
|
+
*/
|
|
78
|
+
async readMetadata(worktreePath) {
|
|
79
|
+
try {
|
|
80
|
+
const filePath = this.getFilePath(worktreePath);
|
|
81
|
+
if (!await fs.pathExists(filePath)) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const content = await fs.readFile(filePath, "utf8");
|
|
85
|
+
const data = JSON.parse(content);
|
|
86
|
+
if (!data.description) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
description: data.description,
|
|
91
|
+
created_at: data.created_at ?? null,
|
|
92
|
+
branchName: data.branchName ?? null,
|
|
93
|
+
worktreePath: data.worktreePath ?? null,
|
|
94
|
+
issueType: data.issueType ?? null,
|
|
95
|
+
issue_numbers: data.issue_numbers ?? [],
|
|
96
|
+
pr_numbers: data.pr_numbers ?? [],
|
|
97
|
+
issueTracker: data.issueTracker ?? null,
|
|
98
|
+
colorHex: data.colorHex ?? null,
|
|
99
|
+
sessionId: data.sessionId ?? null,
|
|
100
|
+
parentLoom: data.parentLoom ?? null
|
|
101
|
+
};
|
|
102
|
+
} catch (error) {
|
|
103
|
+
getLogger().debug(
|
|
104
|
+
`Could not read metadata for worktree ${worktreePath}: ${error instanceof Error ? error.message : String(error)}`
|
|
105
|
+
);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* List all stored loom metadata files
|
|
111
|
+
*
|
|
112
|
+
* Returns an array of LoomMetadata objects for all valid metadata files
|
|
113
|
+
* in the looms directory. Invalid or unreadable files are skipped.
|
|
114
|
+
*
|
|
115
|
+
* @returns Array of LoomMetadata objects from all stored files
|
|
116
|
+
*/
|
|
117
|
+
async listAllMetadata() {
|
|
118
|
+
const results = [];
|
|
119
|
+
try {
|
|
120
|
+
if (!await fs.pathExists(this.loomsDir)) {
|
|
121
|
+
return results;
|
|
122
|
+
}
|
|
123
|
+
const files = await fs.readdir(this.loomsDir);
|
|
124
|
+
for (const file of files) {
|
|
125
|
+
if (!file.endsWith(".json")) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
const filePath = path.join(this.loomsDir, file);
|
|
130
|
+
const content = await fs.readFile(filePath, "utf8");
|
|
131
|
+
const data = JSON.parse(content);
|
|
132
|
+
if (!data.description) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
results.push({
|
|
136
|
+
description: data.description,
|
|
137
|
+
created_at: data.created_at ?? null,
|
|
138
|
+
branchName: data.branchName ?? null,
|
|
139
|
+
worktreePath: data.worktreePath ?? null,
|
|
140
|
+
issueType: data.issueType ?? null,
|
|
141
|
+
issue_numbers: data.issue_numbers ?? [],
|
|
142
|
+
pr_numbers: data.pr_numbers ?? [],
|
|
143
|
+
issueTracker: data.issueTracker ?? null,
|
|
144
|
+
colorHex: data.colorHex ?? null,
|
|
145
|
+
sessionId: data.sessionId ?? null,
|
|
146
|
+
parentLoom: data.parentLoom ?? null
|
|
147
|
+
});
|
|
148
|
+
} catch (error) {
|
|
149
|
+
getLogger().debug(
|
|
150
|
+
`Skipping metadata file ${file}: ${error instanceof Error ? error.message : String(error)}`
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
getLogger().debug(
|
|
156
|
+
`Could not list metadata files: ${error instanceof Error ? error.message : String(error)}`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
return results;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Delete metadata for a worktree (spec section 3.3)
|
|
163
|
+
*
|
|
164
|
+
* Idempotent: silently succeeds if file doesn't exist
|
|
165
|
+
* Non-fatal: logs warning on permission errors but doesn't throw
|
|
166
|
+
*
|
|
167
|
+
* @param worktreePath - Absolute path to the worktree
|
|
168
|
+
*/
|
|
169
|
+
async deleteMetadata(worktreePath) {
|
|
170
|
+
try {
|
|
171
|
+
const filePath = this.getFilePath(worktreePath);
|
|
172
|
+
if (!await fs.pathExists(filePath)) {
|
|
173
|
+
getLogger().debug(`No metadata file to delete for worktree: ${worktreePath}`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
await fs.unlink(filePath);
|
|
177
|
+
getLogger().debug(`Metadata deleted for worktree: ${worktreePath}`);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
getLogger().warn(
|
|
180
|
+
`Failed to delete metadata for worktree: ${error instanceof Error ? error.message : String(error)}`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export {
|
|
187
|
+
MetadataManager
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=chunk-MLS5FAV7.js.map
|