wave-code 1.0.10 → 1.1.1
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/bin/wave-code.js +8 -2
- package/dist/bundle/wave.mjs +3231 -0
- package/package.json +24 -25
- package/src/cli.tsx +6 -1
- package/src/commands/update.ts +2 -7
- package/src/components/App.tsx +3 -7
- package/src/components/BtwDisplay.tsx +10 -1
- package/src/components/ChatInterface.tsx +21 -52
- package/src/components/ConfirmationDetails.tsx +144 -37
- package/src/components/DiffDisplay.tsx +335 -301
- package/src/components/InputBox.tsx +17 -2
- package/src/components/LoadingIndicator.tsx +16 -2
- package/src/components/MessageBlockItem.tsx +2 -4
- package/src/components/MessageList.tsx +75 -14
- package/src/components/ReasoningDisplay.tsx +2 -4
- package/src/components/SessionSelector.tsx +82 -11
- package/src/components/SkillsManager.tsx +312 -0
- package/src/components/StatusCommand.tsx +2 -9
- package/src/components/ToolDisplay.tsx +2 -4
- package/src/constants/commands.ts +6 -0
- package/src/contexts/useChat.tsx +245 -301
- package/src/daemon/commands.ts +57 -27
- package/src/daemon/jsonRpcClient.ts +1 -1
- package/src/daemon/socketClient.ts +2 -2
- package/src/hooks/useInputManager.ts +7 -1
- package/src/index.ts +57 -10
- package/src/managers/inputHandlers.ts +2 -0
- package/src/managers/inputReducer.ts +195 -104
- package/src/print-cli.ts +25 -17
- package/src/reducers/selectorReducer.ts +10 -0
- package/src/reducers/skillsManagerReducer.ts +91 -0
- package/src/session-selector-cli.tsx +269 -28
- package/src/stdio/agentBridge.ts +30 -21
- package/src/stdio/daemonServer.ts +3 -1
- package/src/stdio/protocol.ts +2 -0
- package/src/utils/clipboard.ts +21 -0
- package/src/utils/highlightUtils.ts +46 -1
- package/src/utils/readPackageJson.ts +29 -0
- package/src/utils/streamingText.ts +11 -0
- package/src/utils/worktree.ts +191 -43
- package/dist/cli.d.ts +0 -6
- package/dist/cli.js +0 -53
- package/dist/commands/plugin/disable.d.ts +0 -5
- package/dist/commands/plugin/disable.js +0 -15
- package/dist/commands/plugin/enable.d.ts +0 -5
- package/dist/commands/plugin/enable.js +0 -15
- package/dist/commands/plugin/install.d.ts +0 -5
- package/dist/commands/plugin/install.js +0 -21
- package/dist/commands/plugin/list.d.ts +0 -1
- package/dist/commands/plugin/list.js +0 -31
- package/dist/commands/plugin/marketplace.d.ts +0 -10
- package/dist/commands/plugin/marketplace.js +0 -90
- package/dist/commands/plugin/uninstall.d.ts +0 -3
- package/dist/commands/plugin/uninstall.js +0 -16
- package/dist/commands/plugin/update.d.ts +0 -3
- package/dist/commands/plugin/update.js +0 -15
- package/dist/commands/update.d.ts +0 -1
- package/dist/commands/update.js +0 -97
- package/dist/components/AgentsManager.d.ts +0 -7
- package/dist/components/AgentsManager.js +0 -109
- package/dist/components/App.d.ts +0 -9
- package/dist/components/App.js +0 -76
- package/dist/components/BackgroundTaskManager.d.ts +0 -5
- package/dist/components/BackgroundTaskManager.js +0 -99
- package/dist/components/BangDisplay.d.ts +0 -8
- package/dist/components/BangDisplay.js +0 -17
- package/dist/components/BtwDisplay.d.ts +0 -7
- package/dist/components/BtwDisplay.js +0 -19
- package/dist/components/ChatInterface.d.ts +0 -2
- package/dist/components/ChatInterface.js +0 -61
- package/dist/components/CommandSelector.d.ts +0 -10
- package/dist/components/CommandSelector.js +0 -66
- package/dist/components/CompactDisplay.d.ts +0 -8
- package/dist/components/CompactDisplay.js +0 -13
- package/dist/components/ConfirmationDetails.d.ts +0 -9
- package/dist/components/ConfirmationDetails.js +0 -45
- package/dist/components/ConfirmationSelector.d.ts +0 -13
- package/dist/components/ConfirmationSelector.js +0 -127
- package/dist/components/DiffDisplay.d.ts +0 -8
- package/dist/components/DiffDisplay.js +0 -201
- package/dist/components/DiscoverView.d.ts +0 -2
- package/dist/components/DiscoverView.js +0 -37
- package/dist/components/FileSelector.d.ts +0 -11
- package/dist/components/FileSelector.js +0 -50
- package/dist/components/HelpView.d.ts +0 -7
- package/dist/components/HelpView.js +0 -74
- package/dist/components/HistorySearch.d.ts +0 -8
- package/dist/components/HistorySearch.js +0 -66
- package/dist/components/InputBox.d.ts +0 -24
- package/dist/components/InputBox.js +0 -149
- package/dist/components/InstalledView.d.ts +0 -2
- package/dist/components/InstalledView.js +0 -45
- package/dist/components/LoadingIndicator.d.ts +0 -10
- package/dist/components/LoadingIndicator.js +0 -6
- package/dist/components/LoginCommand.d.ts +0 -5
- package/dist/components/LoginCommand.js +0 -153
- package/dist/components/Markdown.d.ts +0 -5
- package/dist/components/Markdown.js +0 -127
- package/dist/components/MarketplaceAddForm.d.ts +0 -2
- package/dist/components/MarketplaceAddForm.js +0 -55
- package/dist/components/MarketplaceDetail.d.ts +0 -2
- package/dist/components/MarketplaceDetail.js +0 -74
- package/dist/components/MarketplaceList.d.ts +0 -8
- package/dist/components/MarketplaceList.js +0 -17
- package/dist/components/MarketplaceView.d.ts +0 -2
- package/dist/components/MarketplaceView.js +0 -41
- package/dist/components/McpManager.d.ts +0 -9
- package/dist/components/McpManager.js +0 -88
- package/dist/components/MessageBlockItem.d.ts +0 -8
- package/dist/components/MessageBlockItem.js +0 -15
- package/dist/components/MessageList.d.ts +0 -10
- package/dist/components/MessageList.js +0 -80
- package/dist/components/ModelSelector.d.ts +0 -8
- package/dist/components/ModelSelector.js +0 -45
- package/dist/components/Notifications.d.ts +0 -7
- package/dist/components/Notifications.js +0 -9
- package/dist/components/PlanDisplay.d.ts +0 -7
- package/dist/components/PlanDisplay.js +0 -6
- package/dist/components/PluginDetail.d.ts +0 -2
- package/dist/components/PluginDetail.js +0 -87
- package/dist/components/PluginList.d.ts +0 -13
- package/dist/components/PluginList.js +0 -15
- package/dist/components/PluginManagerShell.d.ts +0 -6
- package/dist/components/PluginManagerShell.js +0 -92
- package/dist/components/PluginManagerTypes.d.ts +0 -35
- package/dist/components/PluginManagerTypes.js +0 -1
- package/dist/components/QueuedMessageList.d.ts +0 -2
- package/dist/components/QueuedMessageList.js +0 -18
- package/dist/components/ReasoningDisplay.d.ts +0 -8
- package/dist/components/ReasoningDisplay.js +0 -13
- package/dist/components/RewindCommand.d.ts +0 -12
- package/dist/components/RewindCommand.js +0 -78
- package/dist/components/SessionSelector.d.ts +0 -12
- package/dist/components/SessionSelector.js +0 -47
- package/dist/components/StatusCommand.d.ts +0 -5
- package/dist/components/StatusCommand.js +0 -28
- package/dist/components/StatusLine.d.ts +0 -6
- package/dist/components/StatusLine.js +0 -9
- package/dist/components/TaskList.d.ts +0 -5
- package/dist/components/TaskList.js +0 -197
- package/dist/components/TaskNotificationMessage.d.ts +0 -5
- package/dist/components/TaskNotificationMessage.js +0 -12
- package/dist/components/ToolDisplay.d.ts +0 -9
- package/dist/components/ToolDisplay.js +0 -55
- package/dist/components/WorkflowManager.d.ts +0 -5
- package/dist/components/WorkflowManager.js +0 -102
- package/dist/components/WorktreeExitPrompt.d.ts +0 -12
- package/dist/components/WorktreeExitPrompt.js +0 -35
- package/dist/constants/commands.d.ts +0 -2
- package/dist/constants/commands.js +0 -92
- package/dist/contexts/PluginManagerContext.d.ts +0 -3
- package/dist/contexts/PluginManagerContext.js +0 -9
- package/dist/contexts/useAppConfig.d.ts +0 -10
- package/dist/contexts/useAppConfig.js +0 -13
- package/dist/contexts/useChat.d.ts +0 -101
- package/dist/contexts/useChat.js +0 -993
- package/dist/contracts/status.d.ts +0 -7
- package/dist/contracts/status.js +0 -1
- package/dist/daemon/commands.d.ts +0 -49
- package/dist/daemon/commands.js +0 -341
- package/dist/daemon/jsonRpcClient.d.ts +0 -38
- package/dist/daemon/jsonRpcClient.js +0 -129
- package/dist/daemon/socketClient.d.ts +0 -13
- package/dist/daemon/socketClient.js +0 -26
- package/dist/daemon-cli.d.ts +0 -10
- package/dist/daemon-cli.js +0 -15
- package/dist/hooks/useInputManager.d.ts +0 -75
- package/dist/hooks/useInputManager.js +0 -583
- package/dist/hooks/usePluginManager.d.ts +0 -4
- package/dist/hooks/usePluginManager.js +0 -265
- package/dist/hooks/useTasks.d.ts +0 -1
- package/dist/hooks/useTasks.js +0 -5
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -447
- package/dist/managers/inputHandlers.d.ts +0 -30
- package/dist/managers/inputHandlers.js +0 -625
- package/dist/managers/inputReducer.d.ts +0 -271
- package/dist/managers/inputReducer.js +0 -1121
- package/dist/plugin-manager-cli.d.ts +0 -5
- package/dist/plugin-manager-cli.js +0 -12
- package/dist/print-cli.d.ts +0 -10
- package/dist/print-cli.js +0 -209
- package/dist/reducers/agentsManagerReducer.d.ts +0 -26
- package/dist/reducers/agentsManagerReducer.js +0 -54
- package/dist/reducers/backgroundTaskManagerReducer.d.ts +0 -62
- package/dist/reducers/backgroundTaskManagerReducer.js +0 -106
- package/dist/reducers/confirmationReducer.d.ts +0 -37
- package/dist/reducers/confirmationReducer.js +0 -193
- package/dist/reducers/helpSelectorReducer.d.ts +0 -25
- package/dist/reducers/helpSelectorReducer.js +0 -52
- package/dist/reducers/marketplaceAddFormReducer.d.ts +0 -24
- package/dist/reducers/marketplaceAddFormReducer.js +0 -58
- package/dist/reducers/mcpManagerReducer.d.ts +0 -37
- package/dist/reducers/mcpManagerReducer.js +0 -74
- package/dist/reducers/pluginDetailReducer.d.ts +0 -32
- package/dist/reducers/pluginDetailReducer.js +0 -70
- package/dist/reducers/questionReducer.d.ts +0 -82
- package/dist/reducers/questionReducer.js +0 -375
- package/dist/reducers/rewindSelectorReducer.d.ts +0 -21
- package/dist/reducers/rewindSelectorReducer.js +0 -37
- package/dist/reducers/selectorReducer.d.ts +0 -23
- package/dist/reducers/selectorReducer.js +0 -42
- package/dist/reducers/workflowManagerReducer.d.ts +0 -40
- package/dist/reducers/workflowManagerReducer.js +0 -100
- package/dist/session-selector-cli.d.ts +0 -3
- package/dist/session-selector-cli.js +0 -25
- package/dist/stdio/agentBridge.d.ts +0 -139
- package/dist/stdio/agentBridge.js +0 -999
- package/dist/stdio/daemonServer.d.ts +0 -67
- package/dist/stdio/daemonServer.js +0 -191
- package/dist/stdio/index.d.ts +0 -5
- package/dist/stdio/index.js +0 -5
- package/dist/stdio/jsonRpcConnection.d.ts +0 -39
- package/dist/stdio/jsonRpcConnection.js +0 -135
- package/dist/stdio/protocol.d.ts +0 -41
- package/dist/stdio/protocol.js +0 -26
- package/dist/stdio/stdioServer.d.ts +0 -36
- package/dist/stdio/stdioServer.js +0 -51
- package/dist/stdio-cli.d.ts +0 -8
- package/dist/stdio-cli.js +0 -15
- package/dist/types.d.ts +0 -20
- package/dist/types.js +0 -1
- package/dist/utils/bracketedPaste.d.ts +0 -39
- package/dist/utils/bracketedPaste.js +0 -122
- package/dist/utils/clipboard.d.ts +0 -21
- package/dist/utils/clipboard.js +0 -347
- package/dist/utils/constants.d.ts +0 -16
- package/dist/utils/constants.js +0 -18
- package/dist/utils/highlightUtils.d.ts +0 -1
- package/dist/utils/highlightUtils.js +0 -93
- package/dist/utils/inputUtils.d.ts +0 -17
- package/dist/utils/inputUtils.js +0 -67
- package/dist/utils/logger.d.ts +0 -71
- package/dist/utils/logger.js +0 -259
- package/dist/utils/markdownTable.d.ts +0 -34
- package/dist/utils/markdownTable.js +0 -302
- package/dist/utils/rewindCheckpoints.d.ts +0 -8
- package/dist/utils/rewindCheckpoints.js +0 -17
- package/dist/utils/throttle.d.ts +0 -14
- package/dist/utils/throttle.js +0 -55
- package/dist/utils/toolParameterTransforms.d.ts +0 -18
- package/dist/utils/toolParameterTransforms.js +0 -73
- package/dist/utils/usageSummary.d.ts +0 -28
- package/dist/utils/usageSummary.js +0 -121
- package/dist/utils/version.d.ts +0 -1
- package/dist/utils/version.js +0 -4
- package/dist/utils/worktree.d.ts +0 -35
- package/dist/utils/worktree.js +0 -219
package/dist/utils/worktree.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export interface WorktreeSession {
|
|
2
|
-
name: string;
|
|
3
|
-
path: string;
|
|
4
|
-
branch: string;
|
|
5
|
-
repoRoot: string;
|
|
6
|
-
hasUncommittedChanges: boolean;
|
|
7
|
-
hasNewCommits: boolean;
|
|
8
|
-
isNew: boolean;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Validate a worktree name before any side effects. Names are slash-separated
|
|
12
|
-
* slugs: every segment must be non-empty and contain only letters, digits,
|
|
13
|
-
* dots, underscores, and dashes. The total length is capped at 64 characters
|
|
14
|
-
* and "." / ".." segments are rejected (path traversal protection).
|
|
15
|
-
* @throws {Error} When the name is not a valid slug
|
|
16
|
-
*/
|
|
17
|
-
export declare function validateWorktreeSlug(name: string): void;
|
|
18
|
-
/**
|
|
19
|
-
* Create a new git worktree
|
|
20
|
-
* @param name Worktree name
|
|
21
|
-
* @param cwd Current working directory
|
|
22
|
-
* @param options Optional creation options
|
|
23
|
-
* @param options.baseRef "fresh" (default, origin/<default-branch>) | "head" (local HEAD)
|
|
24
|
-
* @param options.baseBranch Explicit base branch (overrides baseRef)
|
|
25
|
-
* @returns Worktree session details
|
|
26
|
-
*/
|
|
27
|
-
export declare function createWorktree(name: string, cwd: string, options?: {
|
|
28
|
-
baseRef?: "fresh" | "head";
|
|
29
|
-
baseBranch?: string;
|
|
30
|
-
}): Promise<WorktreeSession>;
|
|
31
|
-
/**
|
|
32
|
-
* Remove a git worktree and its associated branch
|
|
33
|
-
* @param session Worktree session details
|
|
34
|
-
*/
|
|
35
|
-
export declare function removeWorktree(session: WorktreeSession): Promise<void>;
|
package/dist/utils/worktree.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
import { promisify } from "node:util";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import * as fs from "node:fs";
|
|
5
|
-
import { getDefaultRemoteBranch, getGitMainRepoRoot, performPostCreationSetup, } from "wave-agent-sdk";
|
|
6
|
-
// Never use execFileSync here: the shared `wave --stdio` process handles all
|
|
7
|
-
// desktop sessions, so a synchronous git call (especially a multi-second
|
|
8
|
-
// recursive worktree delete or a network fetch) freezes every session.
|
|
9
|
-
const execFileAsync = promisify(execFile);
|
|
10
|
-
// --- Worktree name validation ------------------------------------------------
|
|
11
|
-
const VALID_WORKTREE_SLUG_SEGMENT = /^[a-zA-Z0-9._-]+$/;
|
|
12
|
-
const MAX_WORKTREE_SLUG_LENGTH = 64;
|
|
13
|
-
/**
|
|
14
|
-
* Validate a worktree name before any side effects. Names are slash-separated
|
|
15
|
-
* slugs: every segment must be non-empty and contain only letters, digits,
|
|
16
|
-
* dots, underscores, and dashes. The total length is capped at 64 characters
|
|
17
|
-
* and "." / ".." segments are rejected (path traversal protection).
|
|
18
|
-
* @throws {Error} When the name is not a valid slug
|
|
19
|
-
*/
|
|
20
|
-
export function validateWorktreeSlug(name) {
|
|
21
|
-
if (name.length > MAX_WORKTREE_SLUG_LENGTH) {
|
|
22
|
-
throw new Error(`Invalid worktree name: "${name}" must be ${MAX_WORKTREE_SLUG_LENGTH} characters or fewer (got ${name.length})`);
|
|
23
|
-
}
|
|
24
|
-
for (const segment of name.split("/")) {
|
|
25
|
-
if (segment === "." || segment === "..") {
|
|
26
|
-
throw new Error(`Invalid worktree name: "${name}" must not contain "." or ".." path segments`);
|
|
27
|
-
}
|
|
28
|
-
if (segment.length === 0 || !VALID_WORKTREE_SLUG_SEGMENT.test(segment)) {
|
|
29
|
-
throw new Error(`Invalid worktree name: "${name}" each "/"-separated segment must be non-empty and contain only letters, digits, dots, underscores, and dashes`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Create a new git worktree
|
|
35
|
-
* @param name Worktree name
|
|
36
|
-
* @param cwd Current working directory
|
|
37
|
-
* @param options Optional creation options
|
|
38
|
-
* @param options.baseRef "fresh" (default, origin/<default-branch>) | "head" (local HEAD)
|
|
39
|
-
* @param options.baseBranch Explicit base branch (overrides baseRef)
|
|
40
|
-
* @returns Worktree session details
|
|
41
|
-
*/
|
|
42
|
-
export async function createWorktree(name, cwd, options) {
|
|
43
|
-
validateWorktreeSlug(name);
|
|
44
|
-
const session = await createWorktreeInternal(name, cwd, options);
|
|
45
|
-
if (session.isNew) {
|
|
46
|
-
await performPostCreationSetup(session.path, session.repoRoot);
|
|
47
|
-
}
|
|
48
|
-
return session;
|
|
49
|
-
}
|
|
50
|
-
async function createWorktreeInternal(name, cwd, options) {
|
|
51
|
-
const repoRoot = getGitMainRepoRoot(cwd);
|
|
52
|
-
const worktreePath = path.join(repoRoot, ".wave", "worktrees", name);
|
|
53
|
-
const branchName = `worktree-${name}`;
|
|
54
|
-
const useHead = options?.baseRef === "head";
|
|
55
|
-
const resolvedBaseBranch = options?.baseBranch ?? (useHead ? "HEAD" : getDefaultRemoteBranch(cwd));
|
|
56
|
-
// Ensure parent directory exists
|
|
57
|
-
const parentDir = path.dirname(worktreePath);
|
|
58
|
-
if (!fs.existsSync(parentDir)) {
|
|
59
|
-
fs.mkdirSync(parentDir, { recursive: true });
|
|
60
|
-
}
|
|
61
|
-
// Check if worktree already exists
|
|
62
|
-
if (fs.existsSync(worktreePath)) {
|
|
63
|
-
// If it exists, we assume it's already set up correctly
|
|
64
|
-
return {
|
|
65
|
-
name,
|
|
66
|
-
path: worktreePath,
|
|
67
|
-
branch: branchName,
|
|
68
|
-
repoRoot,
|
|
69
|
-
hasUncommittedChanges: false,
|
|
70
|
-
hasNewCommits: false,
|
|
71
|
-
isNew: false,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
// Create worktree and branch
|
|
76
|
-
await execFileAsync("git", ["worktree", "add", "-b", branchName, worktreePath, resolvedBaseBranch], {
|
|
77
|
-
cwd: repoRoot,
|
|
78
|
-
});
|
|
79
|
-
return {
|
|
80
|
-
name,
|
|
81
|
-
path: worktreePath,
|
|
82
|
-
branch: branchName,
|
|
83
|
-
repoRoot,
|
|
84
|
-
hasUncommittedChanges: false,
|
|
85
|
-
hasNewCommits: false,
|
|
86
|
-
isNew: true,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
const stderr = error.stderr?.toString() || "";
|
|
91
|
-
if (stderr.includes("already exists")) {
|
|
92
|
-
// If branch already exists, try to add worktree without -b
|
|
93
|
-
try {
|
|
94
|
-
await execFileAsync("git", ["worktree", "add", worktreePath, branchName], {
|
|
95
|
-
cwd: repoRoot,
|
|
96
|
-
});
|
|
97
|
-
return {
|
|
98
|
-
name,
|
|
99
|
-
path: worktreePath,
|
|
100
|
-
branch: branchName,
|
|
101
|
-
repoRoot,
|
|
102
|
-
hasUncommittedChanges: false,
|
|
103
|
-
hasNewCommits: false,
|
|
104
|
-
isNew: true,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
catch (innerError) {
|
|
108
|
-
throw new Error(`Failed to add existing worktree branch: ${innerError.message}`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (!useHead &&
|
|
112
|
-
(stderr.includes("not a valid object name") ||
|
|
113
|
-
stderr.includes("unknown revision"))) {
|
|
114
|
-
// Base branch not fetched yet — try fetching then retrying
|
|
115
|
-
const branchNameOnly = resolvedBaseBranch.split("/").pop();
|
|
116
|
-
try {
|
|
117
|
-
await execFileAsync("git", ["fetch", "origin", branchNameOnly], {
|
|
118
|
-
cwd: repoRoot,
|
|
119
|
-
});
|
|
120
|
-
await execFileAsync("git", [
|
|
121
|
-
"worktree",
|
|
122
|
-
"add",
|
|
123
|
-
"-b",
|
|
124
|
-
branchName,
|
|
125
|
-
worktreePath,
|
|
126
|
-
resolvedBaseBranch,
|
|
127
|
-
], {
|
|
128
|
-
cwd: repoRoot,
|
|
129
|
-
});
|
|
130
|
-
return {
|
|
131
|
-
name,
|
|
132
|
-
path: worktreePath,
|
|
133
|
-
branch: branchName,
|
|
134
|
-
repoRoot,
|
|
135
|
-
hasUncommittedChanges: false,
|
|
136
|
-
hasNewCommits: false,
|
|
137
|
-
isNew: true,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
catch {
|
|
141
|
-
// Fetch or retry failed — fall back to HEAD
|
|
142
|
-
try {
|
|
143
|
-
await execFileAsync("git", ["worktree", "add", "-b", branchName, worktreePath, "HEAD"], {
|
|
144
|
-
cwd: repoRoot,
|
|
145
|
-
});
|
|
146
|
-
return {
|
|
147
|
-
name,
|
|
148
|
-
path: worktreePath,
|
|
149
|
-
branch: branchName,
|
|
150
|
-
repoRoot,
|
|
151
|
-
hasUncommittedChanges: false,
|
|
152
|
-
hasNewCommits: false,
|
|
153
|
-
isNew: true,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
catch {
|
|
157
|
-
throw new Error(`Failed to create worktree: ${error.message}\n${stderr}`);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
throw new Error(`Failed to create worktree: ${error.message}\n${stderr}`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Remove a git worktree and its associated branch
|
|
166
|
-
* @param session Worktree session details
|
|
167
|
-
*/
|
|
168
|
-
export async function removeWorktree(session) {
|
|
169
|
-
const repoRoot = session.repoRoot;
|
|
170
|
-
try {
|
|
171
|
-
// Get current branch in worktree before removing it
|
|
172
|
-
let currentBranch;
|
|
173
|
-
try {
|
|
174
|
-
const { stdout } = await execFileAsync("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
|
|
175
|
-
cwd: session.path,
|
|
176
|
-
encoding: "utf8",
|
|
177
|
-
});
|
|
178
|
-
currentBranch = stdout.trim();
|
|
179
|
-
}
|
|
180
|
-
catch {
|
|
181
|
-
// Ignore errors getting current branch
|
|
182
|
-
}
|
|
183
|
-
// Remove worktree
|
|
184
|
-
await execFileAsync("git", ["worktree", "remove", "--force", session.path], {
|
|
185
|
-
cwd: repoRoot,
|
|
186
|
-
});
|
|
187
|
-
// Delete original branch
|
|
188
|
-
try {
|
|
189
|
-
await execFileAsync("git", ["branch", "-D", session.branch], {
|
|
190
|
-
cwd: repoRoot,
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
catch {
|
|
194
|
-
// Ignore errors deleting original branch
|
|
195
|
-
}
|
|
196
|
-
// Delete current branch if it's different and not a protected branch
|
|
197
|
-
if (currentBranch &&
|
|
198
|
-
currentBranch !== session.branch &&
|
|
199
|
-
currentBranch !== "HEAD") {
|
|
200
|
-
const defaultRemoteBranch = getDefaultRemoteBranch(repoRoot);
|
|
201
|
-
const defaultBranchName = defaultRemoteBranch.split("/").pop();
|
|
202
|
-
if (currentBranch !== defaultBranchName &&
|
|
203
|
-
currentBranch !== "main" &&
|
|
204
|
-
currentBranch !== "master") {
|
|
205
|
-
try {
|
|
206
|
-
await execFileAsync("git", ["branch", "-D", currentBranch], {
|
|
207
|
-
cwd: repoRoot,
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
catch {
|
|
211
|
-
// Ignore errors deleting current branch
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
console.error(`Failed to remove worktree or branch: ${error.message}`);
|
|
218
|
-
}
|
|
219
|
-
}
|