ccmanager 3.10.0 → 3.11.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/dist/components/App.js +148 -42
- package/dist/components/App.test.js +92 -3
- package/dist/components/Menu.recent-projects.test.js +19 -19
- package/dist/components/NewWorktree.d.ts +20 -1
- package/dist/components/NewWorktree.js +103 -56
- package/dist/components/NewWorktree.test.js +17 -4
- package/dist/services/sessionManager.d.ts +3 -2
- package/dist/services/sessionManager.js +37 -40
- package/dist/services/sessionManager.test.js +38 -0
- package/dist/services/worktreeNameGenerator.d.ts +8 -0
- package/dist/services/worktreeNameGenerator.js +184 -0
- package/dist/services/worktreeNameGenerator.test.d.ts +1 -0
- package/dist/services/worktreeNameGenerator.test.js +35 -0
- package/dist/utils/presetPrompt.d.ts +11 -0
- package/dist/utils/presetPrompt.js +71 -0
- package/dist/utils/presetPrompt.test.d.ts +1 -0
- package/dist/utils/presetPrompt.test.js +167 -0
- package/package.json +6 -6
package/dist/components/App.js
CHANGED
|
@@ -14,11 +14,13 @@ import RemoteBranchSelector from './RemoteBranchSelector.js';
|
|
|
14
14
|
import LoadingSpinner from './LoadingSpinner.js';
|
|
15
15
|
import { globalSessionOrchestrator } from '../services/globalSessionOrchestrator.js';
|
|
16
16
|
import { WorktreeService } from '../services/worktreeService.js';
|
|
17
|
+
import { worktreeNameGenerator } from '../services/worktreeNameGenerator.js';
|
|
17
18
|
import { AmbiguousBranchError, } from '../types/index.js';
|
|
18
19
|
import { configReader } from '../services/config/configReader.js';
|
|
19
20
|
import { ENV_VARS } from '../constants/env.js';
|
|
20
21
|
import { MULTI_PROJECT_ERRORS } from '../constants/error.js';
|
|
21
22
|
import { projectManager } from '../services/projectManager.js';
|
|
23
|
+
import { generateWorktreeDirectory } from '../utils/worktreeUtils.js';
|
|
22
24
|
const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
23
25
|
const { exit } = useApp();
|
|
24
26
|
const [view, setView] = useState(multiProject ? 'project-list' : 'menu');
|
|
@@ -30,6 +32,7 @@ const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
|
30
32
|
const [selectedWorktree, setSelectedWorktree] = useState(null); // Store selected worktree for preset selection
|
|
31
33
|
const [selectedProject, setSelectedProject] = useState(null); // Store selected project in multi-project mode
|
|
32
34
|
const [configScope, setConfigScope] = useState('global'); // Store config scope for configuration view
|
|
35
|
+
const [pendingMenuSessionLaunch, setPendingMenuSessionLaunch] = useState(null);
|
|
33
36
|
// State for remote branch disambiguation
|
|
34
37
|
const [pendingWorktreeCreation, setPendingWorktreeCreation] = useState(null);
|
|
35
38
|
// State for loading context - track flags for message composition
|
|
@@ -50,10 +53,10 @@ const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
|
50
53
|
}
|
|
51
54
|
};
|
|
52
55
|
// Helper function to create session with Effect-based error handling
|
|
53
|
-
const createSessionWithEffect = async (worktreePath, presetId) => {
|
|
56
|
+
const createSessionWithEffect = async (worktreePath, presetId, initialPrompt) => {
|
|
54
57
|
const sessionEffect = devcontainerConfig
|
|
55
|
-
? sessionManager.createSessionWithDevcontainerEffect(worktreePath, devcontainerConfig, presetId)
|
|
56
|
-
: sessionManager.createSessionWithPresetEffect(worktreePath, presetId);
|
|
58
|
+
? sessionManager.createSessionWithDevcontainerEffect(worktreePath, devcontainerConfig, presetId, initialPrompt)
|
|
59
|
+
: sessionManager.createSessionWithPresetEffect(worktreePath, presetId, initialPrompt);
|
|
57
60
|
// Execute the Effect and handle both success and failure cases
|
|
58
61
|
const result = await Effect.runPromise(Effect.either(sessionEffect));
|
|
59
62
|
if (result._tag === 'Left') {
|
|
@@ -86,6 +89,33 @@ const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
|
86
89
|
callback();
|
|
87
90
|
}, 10); // Small delay to ensure screen clear is processed
|
|
88
91
|
}, []);
|
|
92
|
+
const navigateToSession = useCallback((session) => {
|
|
93
|
+
clearScreen();
|
|
94
|
+
setView('clearing');
|
|
95
|
+
setTimeout(() => {
|
|
96
|
+
setActiveSession(session);
|
|
97
|
+
setView('session');
|
|
98
|
+
}, 10);
|
|
99
|
+
}, []);
|
|
100
|
+
const startSessionForWorktree = useCallback(async (worktree, options) => {
|
|
101
|
+
let session = sessionManager.getSession(worktree.path);
|
|
102
|
+
if (!session) {
|
|
103
|
+
if (!options?.presetId && configReader.getSelectPresetOnStart()) {
|
|
104
|
+
setSelectedWorktree(worktree);
|
|
105
|
+
navigateWithClear('preset-selector');
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
setView(options?.presetId ? 'creating-session-preset' : 'creating-session');
|
|
109
|
+
const result = await createSessionWithEffect(worktree.path, options?.presetId, options?.initialPrompt);
|
|
110
|
+
if (!result.success) {
|
|
111
|
+
setError(result.errorMessage);
|
|
112
|
+
navigateWithClear('menu');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
session = result.session;
|
|
116
|
+
}
|
|
117
|
+
navigateToSession(session);
|
|
118
|
+
}, [sessionManager, navigateWithClear, navigateToSession]);
|
|
89
119
|
useEffect(() => {
|
|
90
120
|
// Listen for session exits to return to menu automatically
|
|
91
121
|
const handleSessionExit = (session) => {
|
|
@@ -115,6 +145,26 @@ const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
|
115
145
|
// Don't destroy sessions on unmount - they persist in memory
|
|
116
146
|
};
|
|
117
147
|
}, [sessionManager, multiProject, selectedProject, navigateWithClear]);
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
if (view !== 'menu' || !pendingMenuSessionLaunch) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
let cancelled = false;
|
|
153
|
+
void (async () => {
|
|
154
|
+
if (cancelled) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const launchRequest = pendingMenuSessionLaunch;
|
|
158
|
+
setPendingMenuSessionLaunch(null);
|
|
159
|
+
await startSessionForWorktree(launchRequest.worktree, {
|
|
160
|
+
presetId: launchRequest.presetId,
|
|
161
|
+
initialPrompt: launchRequest.initialPrompt,
|
|
162
|
+
});
|
|
163
|
+
})();
|
|
164
|
+
return () => {
|
|
165
|
+
cancelled = true;
|
|
166
|
+
};
|
|
167
|
+
}, [view, pendingMenuSessionLaunch, startSessionForWorktree]);
|
|
118
168
|
// Helper function to parse ambiguous branch error and create AmbiguousBranchError
|
|
119
169
|
const parseAmbiguousBranchError = (errorMessage) => {
|
|
120
170
|
const pattern = /Ambiguous branch '(.+?)' found in multiple remotes: (.+?)\. Please specify which remote to use\./;
|
|
@@ -141,6 +191,20 @@ const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
|
141
191
|
// Helper function to handle worktree creation results
|
|
142
192
|
const handleWorktreeCreationResult = (result, creationData) => {
|
|
143
193
|
if (result.success) {
|
|
194
|
+
if (creationData.presetId && creationData.initialPrompt) {
|
|
195
|
+
setPendingMenuSessionLaunch({
|
|
196
|
+
worktree: {
|
|
197
|
+
path: creationData.path,
|
|
198
|
+
branch: creationData.branch,
|
|
199
|
+
isMainWorktree: false,
|
|
200
|
+
hasSession: false,
|
|
201
|
+
},
|
|
202
|
+
presetId: creationData.presetId,
|
|
203
|
+
initialPrompt: creationData.initialPrompt,
|
|
204
|
+
});
|
|
205
|
+
handleReturnToMenu();
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
144
208
|
handleReturnToMenu();
|
|
145
209
|
return;
|
|
146
210
|
}
|
|
@@ -207,28 +271,7 @@ const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
|
207
271
|
}
|
|
208
272
|
return;
|
|
209
273
|
}
|
|
210
|
-
|
|
211
|
-
let session = sessionManager.getSession(worktree.path);
|
|
212
|
-
if (!session) {
|
|
213
|
-
// Check if we should show preset selector
|
|
214
|
-
if (configReader.getSelectPresetOnStart()) {
|
|
215
|
-
setSelectedWorktree(worktree);
|
|
216
|
-
navigateWithClear('preset-selector');
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
// Set loading state before async operation
|
|
220
|
-
setView('creating-session');
|
|
221
|
-
// Use Effect-based session creation with default preset
|
|
222
|
-
const result = await createSessionWithEffect(worktree.path);
|
|
223
|
-
if (!result.success) {
|
|
224
|
-
setError(result.errorMessage);
|
|
225
|
-
navigateWithClear('menu');
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
session = result.session;
|
|
229
|
-
}
|
|
230
|
-
setActiveSession(session);
|
|
231
|
-
navigateWithClear('session');
|
|
274
|
+
await startSessionForWorktree(worktree);
|
|
232
275
|
};
|
|
233
276
|
const handlePresetSelected = async (presetId) => {
|
|
234
277
|
if (!selectedWorktree)
|
|
@@ -244,8 +287,7 @@ const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
|
244
287
|
return;
|
|
245
288
|
}
|
|
246
289
|
// Success case
|
|
247
|
-
|
|
248
|
-
navigateWithClear('session');
|
|
290
|
+
navigateToSession(result.session);
|
|
249
291
|
setSelectedWorktree(null);
|
|
250
292
|
};
|
|
251
293
|
const handlePresetSelectorCancel = () => {
|
|
@@ -267,22 +309,69 @@ const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
|
267
309
|
// Ink's useInput in Menu will reconfigure stdin automatically
|
|
268
310
|
});
|
|
269
311
|
};
|
|
270
|
-
const handleCreateWorktree = async (
|
|
312
|
+
const handleCreateWorktree = async (request) => {
|
|
313
|
+
setError(null);
|
|
314
|
+
let branch = request.creationMode === 'manual' ? request.branch : '';
|
|
315
|
+
let targetPath = request.path;
|
|
316
|
+
if (request.creationMode === 'prompt') {
|
|
317
|
+
setLoadingContext({
|
|
318
|
+
copySessionData: request.copySessionData,
|
|
319
|
+
isPromptFlow: true,
|
|
320
|
+
stage: 'naming',
|
|
321
|
+
});
|
|
322
|
+
setView('creating-worktree');
|
|
323
|
+
const allBranches = await Effect.runPromise(Effect.either(worktreeService.getAllBranchesEffect()));
|
|
324
|
+
const existingBranches = allBranches._tag === 'Right' ? allBranches.right : [];
|
|
325
|
+
const generatedBranch = await Effect.runPromise(Effect.either(worktreeNameGenerator.generateBranchNameEffect(request.initialPrompt, request.baseBranch, existingBranches)));
|
|
326
|
+
if (generatedBranch._tag === 'Left') {
|
|
327
|
+
setError(formatErrorMessage(generatedBranch.left));
|
|
328
|
+
setView('new-worktree');
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
branch = generatedBranch.right;
|
|
332
|
+
if (request.autoDirectoryPattern) {
|
|
333
|
+
targetPath = generateWorktreeDirectory(request.projectPath, branch, request.autoDirectoryPattern);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
271
336
|
// Set loading context before showing loading view
|
|
272
|
-
setLoadingContext({
|
|
337
|
+
setLoadingContext({
|
|
338
|
+
copySessionData: request.copySessionData,
|
|
339
|
+
isPromptFlow: request.creationMode === 'prompt',
|
|
340
|
+
stage: 'creating',
|
|
341
|
+
});
|
|
273
342
|
setView('creating-worktree');
|
|
274
|
-
setError(null);
|
|
275
343
|
// Create the worktree using Effect
|
|
276
|
-
const result = await Effect.runPromise(Effect.either(worktreeService.createWorktreeEffect(
|
|
344
|
+
const result = await Effect.runPromise(Effect.either(worktreeService.createWorktreeEffect(targetPath, branch, request.baseBranch, request.copySessionData, request.copyClaudeDirectory)));
|
|
277
345
|
// Transform Effect result to legacy format for handleWorktreeCreationResult
|
|
278
346
|
if (result._tag === 'Left') {
|
|
279
347
|
// Handle error using pattern matching on _tag
|
|
280
348
|
const errorMessage = formatErrorMessage(result.left);
|
|
281
|
-
handleWorktreeCreationResult({ success: false, error: errorMessage }, {
|
|
349
|
+
handleWorktreeCreationResult({ success: false, error: errorMessage }, {
|
|
350
|
+
path: targetPath,
|
|
351
|
+
branch,
|
|
352
|
+
baseBranch: request.baseBranch,
|
|
353
|
+
copySessionData: request.copySessionData,
|
|
354
|
+
copyClaudeDirectory: request.copyClaudeDirectory,
|
|
355
|
+
presetId: request.creationMode === 'prompt' ? request.presetId : undefined,
|
|
356
|
+
initialPrompt: request.creationMode === 'prompt'
|
|
357
|
+
? request.initialPrompt
|
|
358
|
+
: undefined,
|
|
359
|
+
});
|
|
282
360
|
}
|
|
283
361
|
else {
|
|
284
362
|
// Success case
|
|
285
|
-
|
|
363
|
+
const createdWorktree = result.right;
|
|
364
|
+
handleWorktreeCreationResult({ success: true }, {
|
|
365
|
+
path: createdWorktree.path,
|
|
366
|
+
branch: createdWorktree.branch || branch,
|
|
367
|
+
baseBranch: request.baseBranch,
|
|
368
|
+
copySessionData: request.copySessionData,
|
|
369
|
+
copyClaudeDirectory: request.copyClaudeDirectory,
|
|
370
|
+
presetId: request.creationMode === 'prompt' ? request.presetId : undefined,
|
|
371
|
+
initialPrompt: request.creationMode === 'prompt'
|
|
372
|
+
? request.initialPrompt
|
|
373
|
+
: undefined,
|
|
374
|
+
});
|
|
286
375
|
}
|
|
287
376
|
};
|
|
288
377
|
const handleCancelNewWorktree = () => {
|
|
@@ -296,7 +385,11 @@ const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
|
296
385
|
setPendingWorktreeCreation(null);
|
|
297
386
|
// Retry worktree creation with the resolved base branch
|
|
298
387
|
// Set loading context before showing loading view
|
|
299
|
-
setLoadingContext({
|
|
388
|
+
setLoadingContext({
|
|
389
|
+
copySessionData: creationData.copySessionData,
|
|
390
|
+
isPromptFlow: Boolean(creationData.presetId && creationData.initialPrompt),
|
|
391
|
+
stage: 'creating',
|
|
392
|
+
});
|
|
300
393
|
setView('creating-worktree');
|
|
301
394
|
setError(null);
|
|
302
395
|
const result = await Effect.runPromise(Effect.either(worktreeService.createWorktreeEffect(creationData.path, creationData.branch, selectedRemoteRef, // Use the selected remote reference
|
|
@@ -308,8 +401,15 @@ const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
|
308
401
|
setView('new-worktree');
|
|
309
402
|
}
|
|
310
403
|
else {
|
|
311
|
-
|
|
312
|
-
|
|
404
|
+
handleWorktreeCreationResult({ success: true }, {
|
|
405
|
+
path: creationData.path,
|
|
406
|
+
branch: creationData.branch,
|
|
407
|
+
baseBranch: selectedRemoteRef,
|
|
408
|
+
copySessionData: creationData.copySessionData,
|
|
409
|
+
copyClaudeDirectory: creationData.copyClaudeDirectory,
|
|
410
|
+
presetId: creationData.presetId,
|
|
411
|
+
initialPrompt: creationData.initialPrompt,
|
|
412
|
+
});
|
|
313
413
|
}
|
|
314
414
|
};
|
|
315
415
|
const handleRemoteBranchSelectorCancel = () => {
|
|
@@ -400,9 +500,13 @@ const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
|
400
500
|
}
|
|
401
501
|
if (view === 'creating-worktree') {
|
|
402
502
|
// Compose message based on loading context
|
|
403
|
-
const message = loadingContext.
|
|
404
|
-
?
|
|
405
|
-
|
|
503
|
+
const message = loadingContext.isPromptFlow
|
|
504
|
+
? loadingContext.stage === 'naming'
|
|
505
|
+
? 'Generating branch name with Claude...'
|
|
506
|
+
: 'Creating worktree from generated branch name...'
|
|
507
|
+
: loadingContext.copySessionData
|
|
508
|
+
? 'Creating worktree and copying session data...'
|
|
509
|
+
: 'Creating worktree...';
|
|
406
510
|
return (_jsx(Box, { flexDirection: "column", children: _jsx(LoadingSpinner, { message: message, color: "cyan" }) }));
|
|
407
511
|
}
|
|
408
512
|
if (view === 'delete-worktree') {
|
|
@@ -441,9 +545,11 @@ const App = ({ devcontainerConfig, multiProject, version, }) => {
|
|
|
441
545
|
if (view === 'creating-session-preset') {
|
|
442
546
|
// Always display preset-specific message
|
|
443
547
|
// Devcontainer operations take >5 seconds, so indicate extended duration
|
|
444
|
-
const message =
|
|
445
|
-
? 'Creating session with preset
|
|
446
|
-
:
|
|
548
|
+
const message = loadingContext.isPromptFlow
|
|
549
|
+
? 'Creating session with preset and prompt...'
|
|
550
|
+
: devcontainerConfig
|
|
551
|
+
? 'Creating session with preset (this may take a moment)...'
|
|
552
|
+
: 'Creating session with preset...';
|
|
447
553
|
// Use yellow color for devcontainer, cyan for standard
|
|
448
554
|
const color = devcontainerConfig ? 'yellow' : 'cyan';
|
|
449
555
|
return (_jsx(Box, { flexDirection: "column", children: _jsx(LoadingSpinner, { message: message, color: color }) }));
|
|
@@ -33,6 +33,9 @@ const configReaderMock = {
|
|
|
33
33
|
const projectManagerMock = {
|
|
34
34
|
addRecentProject: vi.fn(),
|
|
35
35
|
};
|
|
36
|
+
const worktreeNameGeneratorMock = {
|
|
37
|
+
generateBranchNameEffect: vi.fn(() => Effect.succeed('fix/trim-worktree-name')),
|
|
38
|
+
};
|
|
36
39
|
function createInkMock(label, onRender) {
|
|
37
40
|
return async () => {
|
|
38
41
|
const ReactActual = await vi.importActual('react');
|
|
@@ -64,11 +67,15 @@ vi.mock('../services/projectManager.js', () => ({
|
|
|
64
67
|
vi.mock('../services/config/configReader.js', () => ({
|
|
65
68
|
configReader: configReaderMock,
|
|
66
69
|
}));
|
|
70
|
+
vi.mock('../services/worktreeNameGenerator.js', () => ({
|
|
71
|
+
worktreeNameGenerator: worktreeNameGeneratorMock,
|
|
72
|
+
}));
|
|
67
73
|
vi.mock('../services/worktreeService.js', () => ({
|
|
68
74
|
WorktreeService: vi.fn(function () {
|
|
69
75
|
return {
|
|
70
76
|
createWorktreeEffect: (...args) => createWorktreeEffectMock(...args),
|
|
71
77
|
deleteWorktreeEffect: (...args) => deleteWorktreeEffectMock(...args),
|
|
78
|
+
getAllBranchesEffect: () => Effect.succeed([]),
|
|
72
79
|
};
|
|
73
80
|
}),
|
|
74
81
|
}));
|
|
@@ -118,13 +125,20 @@ beforeEach(() => {
|
|
|
118
125
|
sessionProps = undefined;
|
|
119
126
|
createWorktreeEffectMock.mockReset();
|
|
120
127
|
deleteWorktreeEffectMock.mockReset();
|
|
121
|
-
createWorktreeEffectMock.mockImplementation(() => Effect.succeed(
|
|
128
|
+
createWorktreeEffectMock.mockImplementation((path, branch) => Effect.succeed({
|
|
129
|
+
path,
|
|
130
|
+
branch,
|
|
131
|
+
isMainWorktree: false,
|
|
132
|
+
hasSession: false,
|
|
133
|
+
}));
|
|
122
134
|
deleteWorktreeEffectMock.mockImplementation(() => Effect.succeed(undefined));
|
|
123
135
|
sessionManagers.length = 0;
|
|
124
136
|
getManagerForProjectMock.mockClear();
|
|
125
137
|
configReaderMock.getSelectPresetOnStart.mockReset();
|
|
126
138
|
configReaderMock.getSelectPresetOnStart.mockReturnValue(false);
|
|
127
139
|
projectManagerMock.addRecentProject.mockReset();
|
|
140
|
+
worktreeNameGeneratorMock.generateBranchNameEffect.mockReset();
|
|
141
|
+
worktreeNameGeneratorMock.generateBranchNameEffect.mockImplementation(() => Effect.succeed('fix/trim-worktree-name'));
|
|
128
142
|
});
|
|
129
143
|
afterEach(() => {
|
|
130
144
|
delete process.env[ENV_VARS.MULTI_PROJECT_ROOT];
|
|
@@ -153,7 +167,12 @@ describe('App component loading state machine', () => {
|
|
|
153
167
|
let resolveWorktree;
|
|
154
168
|
createWorktreeEffectMock.mockImplementation(() => Effect.tryPromise({
|
|
155
169
|
try: () => new Promise(resolve => {
|
|
156
|
-
resolveWorktree = resolve
|
|
170
|
+
resolveWorktree = () => resolve({
|
|
171
|
+
path: '/tmp/test',
|
|
172
|
+
branch: 'feature',
|
|
173
|
+
isMainWorktree: false,
|
|
174
|
+
hasSession: false,
|
|
175
|
+
});
|
|
157
176
|
}),
|
|
158
177
|
catch: (error) => error,
|
|
159
178
|
}));
|
|
@@ -168,7 +187,14 @@ describe('App component loading state machine', () => {
|
|
|
168
187
|
}));
|
|
169
188
|
await waitForCondition(() => Boolean(newWorktreeProps));
|
|
170
189
|
const newWorktree = newWorktreeProps;
|
|
171
|
-
const createPromise = Promise.resolve(newWorktree.onComplete(
|
|
190
|
+
const createPromise = Promise.resolve(newWorktree.onComplete({
|
|
191
|
+
creationMode: 'manual',
|
|
192
|
+
path: '/tmp/test',
|
|
193
|
+
branch: 'feature',
|
|
194
|
+
baseBranch: 'main',
|
|
195
|
+
copySessionData: true,
|
|
196
|
+
copyClaudeDirectory: false,
|
|
197
|
+
}));
|
|
172
198
|
await flush();
|
|
173
199
|
expect(lastFrame()).toContain('Creating worktree and copying session data...');
|
|
174
200
|
resolveWorktree?.();
|
|
@@ -178,6 +204,69 @@ describe('App component loading state machine', () => {
|
|
|
178
204
|
expect(lastFrame()).toContain('Menu View');
|
|
179
205
|
unmount();
|
|
180
206
|
});
|
|
207
|
+
it('auto-starts the prompt-first session with the created worktree path', async () => {
|
|
208
|
+
const { lastFrame, unmount } = render(_jsx(App, { version: "test" }));
|
|
209
|
+
await waitForCondition(() => Boolean(menuProps));
|
|
210
|
+
expect(sessionManagers).toHaveLength(1);
|
|
211
|
+
const sessionManager = sessionManagers[0];
|
|
212
|
+
const menu = menuProps;
|
|
213
|
+
await Promise.resolve(menu.onSelectWorktree({
|
|
214
|
+
path: '',
|
|
215
|
+
branch: '',
|
|
216
|
+
isMainWorktree: false,
|
|
217
|
+
hasSession: false,
|
|
218
|
+
}));
|
|
219
|
+
await waitForCondition(() => Boolean(newWorktreeProps));
|
|
220
|
+
await Promise.resolve(newWorktreeProps.onComplete({
|
|
221
|
+
creationMode: 'prompt',
|
|
222
|
+
path: '/tmp/project',
|
|
223
|
+
projectPath: '/tmp/project',
|
|
224
|
+
autoDirectoryPattern: '../{branch}',
|
|
225
|
+
baseBranch: 'main',
|
|
226
|
+
presetId: 'claude',
|
|
227
|
+
initialPrompt: 'trim worktree name output',
|
|
228
|
+
copySessionData: false,
|
|
229
|
+
copyClaudeDirectory: false,
|
|
230
|
+
}));
|
|
231
|
+
const createdPath = createWorktreeEffectMock.mock.calls[0]?.[0];
|
|
232
|
+
await waitForCondition(() => sessionManager.createSessionWithPresetEffect.mock.calls.length > 0, 200);
|
|
233
|
+
await waitForCondition(() => lastFrame()?.includes('Session View') ?? false);
|
|
234
|
+
expect(sessionManager.createSessionWithPresetEffect).toHaveBeenCalledWith(createdPath, 'claude', 'trim worktree name output');
|
|
235
|
+
expect(sessionProps?.session).toEqual(mockSession);
|
|
236
|
+
unmount();
|
|
237
|
+
});
|
|
238
|
+
it('uses the created worktree path when auto-starting a prompt-first session', async () => {
|
|
239
|
+
createWorktreeEffectMock.mockImplementation((_path, branch) => Effect.succeed({
|
|
240
|
+
path: '/tmp/resolved-worktree',
|
|
241
|
+
branch,
|
|
242
|
+
isMainWorktree: false,
|
|
243
|
+
hasSession: false,
|
|
244
|
+
}));
|
|
245
|
+
const { unmount } = render(_jsx(App, { version: "test" }));
|
|
246
|
+
await waitForCondition(() => Boolean(menuProps));
|
|
247
|
+
const sessionManager = sessionManagers[0];
|
|
248
|
+
await Promise.resolve(menuProps.onSelectWorktree({
|
|
249
|
+
path: '',
|
|
250
|
+
branch: '',
|
|
251
|
+
isMainWorktree: false,
|
|
252
|
+
hasSession: false,
|
|
253
|
+
}));
|
|
254
|
+
await waitForCondition(() => Boolean(newWorktreeProps));
|
|
255
|
+
await Promise.resolve(newWorktreeProps.onComplete({
|
|
256
|
+
creationMode: 'prompt',
|
|
257
|
+
path: '../relative-worktree',
|
|
258
|
+
projectPath: '/tmp/project',
|
|
259
|
+
autoDirectoryPattern: '../{branch}',
|
|
260
|
+
baseBranch: 'main',
|
|
261
|
+
presetId: 'claude',
|
|
262
|
+
initialPrompt: 'trim worktree name output',
|
|
263
|
+
copySessionData: false,
|
|
264
|
+
copyClaudeDirectory: false,
|
|
265
|
+
}));
|
|
266
|
+
await waitForCondition(() => sessionManager.createSessionWithPresetEffect.mock.calls.length > 0, 200);
|
|
267
|
+
expect(sessionManager.createSessionWithPresetEffect).toHaveBeenCalledWith('/tmp/resolved-worktree', 'claude', 'trim worktree name output');
|
|
268
|
+
unmount();
|
|
269
|
+
});
|
|
181
270
|
it('displays branch deletion message while deleting worktrees', async () => {
|
|
182
271
|
let resolveDelete;
|
|
183
272
|
deleteWorktreeEffectMock.mockImplementation(() => Effect.tryPromise({
|
|
@@ -132,12 +132,12 @@ describe('Menu - Recent Projects', () => {
|
|
|
132
132
|
const { lastFrame, rerender } = render(_jsx(Menu, { sessionManager: mockSessionManager, worktreeService: mockWorktreeService, onSelectWorktree: vi.fn(), onSelectRecentProject: vi.fn(), multiProject: true, version: "test" }));
|
|
133
133
|
// Force a rerender to ensure all effects have run
|
|
134
134
|
rerender(_jsx(Menu, { sessionManager: mockSessionManager, worktreeService: mockWorktreeService, onSelectWorktree: vi.fn(), onSelectRecentProject: vi.fn(), multiProject: true, version: "test" }));
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
await vi.waitFor(() => {
|
|
136
|
+
const output = lastFrame();
|
|
137
|
+
expect(output).toContain('─ Recent ─');
|
|
138
|
+
expect(output).toContain('Project 1');
|
|
139
|
+
expect(output).toContain('Project 2');
|
|
140
|
+
});
|
|
141
141
|
});
|
|
142
142
|
it('should not show recent projects section when no recent projects', () => {
|
|
143
143
|
vi.mocked(projectManager.getRecentProjects).mockReturnValue([]);
|
|
@@ -164,12 +164,12 @@ describe('Menu - Recent Projects', () => {
|
|
|
164
164
|
});
|
|
165
165
|
vi.spyOn(SessionManager, 'formatSessionCounts').mockReturnValue('');
|
|
166
166
|
const { lastFrame } = render(_jsx(Menu, { sessionManager: mockSessionManager, worktreeService: mockWorktreeService, onSelectWorktree: vi.fn(), onSelectRecentProject: vi.fn(), multiProject: true, version: "test" }));
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
await vi.waitFor(() => {
|
|
168
|
+
const output = lastFrame();
|
|
169
|
+
expect(output).toContain('─ Recent ─');
|
|
170
|
+
expect(output).toContain('Project 0');
|
|
171
|
+
expect(output).toContain('Project 4');
|
|
172
|
+
});
|
|
173
173
|
});
|
|
174
174
|
it('should filter out current project from recent projects', async () => {
|
|
175
175
|
// Setup the initial recent projects
|
|
@@ -186,13 +186,13 @@ describe('Menu - Recent Projects', () => {
|
|
|
186
186
|
const { lastFrame, rerender } = render(_jsx(Menu, { sessionManager: mockSessionManager, worktreeService: worktreeServiceWithGitRoot, onSelectWorktree: vi.fn(), onSelectRecentProject: vi.fn(), multiProject: true, version: "test" }));
|
|
187
187
|
// Force a rerender to ensure all effects have run
|
|
188
188
|
rerender(_jsx(Menu, { sessionManager: mockSessionManager, worktreeService: worktreeServiceWithGitRoot, onSelectWorktree: vi.fn(), onSelectRecentProject: vi.fn(), multiProject: true, version: "test" }));
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
189
|
+
await vi.waitFor(() => {
|
|
190
|
+
const output = lastFrame();
|
|
191
|
+
expect(output).toContain('─ Recent ─');
|
|
192
|
+
expect(output).not.toContain('Current Project');
|
|
193
|
+
expect(output).toContain('Project 1');
|
|
194
|
+
expect(output).toContain('Project 2');
|
|
195
|
+
});
|
|
196
196
|
});
|
|
197
197
|
it('should hide recent projects section when all projects are filtered out', () => {
|
|
198
198
|
vi.mocked(projectManager.getRecentProjects).mockReturnValue([
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
interface NewWorktreeProps {
|
|
3
3
|
projectPath?: string;
|
|
4
|
-
onComplete: (
|
|
4
|
+
onComplete: (request: NewWorktreeRequest) => void;
|
|
5
5
|
onCancel: () => void;
|
|
6
6
|
}
|
|
7
|
+
export type NewWorktreeRequest = {
|
|
8
|
+
creationMode: 'manual';
|
|
9
|
+
path: string;
|
|
10
|
+
branch: string;
|
|
11
|
+
baseBranch: string;
|
|
12
|
+
copySessionData: boolean;
|
|
13
|
+
copyClaudeDirectory: boolean;
|
|
14
|
+
} | {
|
|
15
|
+
creationMode: 'prompt';
|
|
16
|
+
path: string;
|
|
17
|
+
projectPath: string;
|
|
18
|
+
autoDirectoryPattern?: string;
|
|
19
|
+
baseBranch: string;
|
|
20
|
+
presetId: string;
|
|
21
|
+
initialPrompt: string;
|
|
22
|
+
copySessionData: boolean;
|
|
23
|
+
copyClaudeDirectory: boolean;
|
|
24
|
+
branch?: never;
|
|
25
|
+
};
|
|
7
26
|
declare const NewWorktree: React.FC<NewWorktreeProps>;
|
|
8
27
|
export default NewWorktree;
|