ccmanager 2.2.4 → 2.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.
@@ -277,7 +277,7 @@ const App = ({ devcontainerConfig, multiProject }) => {
277
277
  React.createElement(Text, { color: "red" },
278
278
  "Error: ",
279
279
  error))),
280
- React.createElement(NewWorktree, { onComplete: handleCreateWorktree, onCancel: handleCancelNewWorktree })));
280
+ React.createElement(NewWorktree, { projectPath: selectedProject?.path || process.cwd(), onComplete: handleCreateWorktree, onCancel: handleCancelNewWorktree })));
281
281
  }
282
282
  if (view === 'creating-worktree') {
283
283
  return (React.createElement(Box, { flexDirection: "column" },
@@ -4,6 +4,7 @@ import SelectInput from 'ink-select-input';
4
4
  import TextInputWrapper from './TextInputWrapper.js';
5
5
  import { configurationManager } from '../services/configurationManager.js';
6
6
  import { shortcutManager } from '../services/shortcutManager.js';
7
+ import { generateWorktreeDirectory } from '../utils/worktreeUtils.js';
7
8
  const ConfigureWorktree = ({ onComplete }) => {
8
9
  const worktreeConfig = configurationManager.getWorktreeConfig();
9
10
  const [autoDirectory, setAutoDirectory] = useState(worktreeConfig.autoDirectory);
@@ -11,6 +12,9 @@ const ConfigureWorktree = ({ onComplete }) => {
11
12
  const [copySessionData, setCopySessionData] = useState(worktreeConfig.copySessionData ?? true);
12
13
  const [editMode, setEditMode] = useState('menu');
13
14
  const [tempPattern, setTempPattern] = useState(pattern);
15
+ // Example values for preview
16
+ const exampleProjectPath = '/home/user/src/myproject';
17
+ const exampleBranchName = 'feature/my-feature';
14
18
  useInput((input, key) => {
15
19
  if (editMode === 'menu' &&
16
20
  shortcutManager.matchesShortcut('cancel', input, key)) {
@@ -81,7 +85,10 @@ const ConfigureWorktree = ({ onComplete }) => {
81
85
  React.createElement(Text, { dimColor: true },
82
86
  "Available placeholders: ",
83
87
  '{branch}',
84
- " - full branch name")),
88
+ " - full branch name,",
89
+ ' ',
90
+ '{project}',
91
+ " - repository name")),
85
92
  React.createElement(Box, null,
86
93
  React.createElement(Text, { color: "cyan" }, '> '),
87
94
  React.createElement(TextInputWrapper, { value: tempPattern, onChange: setTempPattern, onSubmit: handlePatternSubmit, placeholder: "../{branch}" })),
@@ -95,8 +102,12 @@ const ConfigureWorktree = ({ onComplete }) => {
95
102
  React.createElement(Text, { dimColor: true }, "Configure worktree creation settings")),
96
103
  autoDirectory && (React.createElement(Box, { marginBottom: 1 },
97
104
  React.createElement(Text, null,
98
- "Example: branch \"feature/my-feature\" \u2192 directory \"",
99
- pattern.replace('{branch}', 'feature-my-feature'),
105
+ "Example: project \"",
106
+ exampleProjectPath,
107
+ "\", branch \"",
108
+ exampleBranchName,
109
+ "\" \u2192 directory \"",
110
+ generateWorktreeDirectory(exampleProjectPath, exampleBranchName, pattern),
100
111
  "\""))),
101
112
  React.createElement(SelectInput, { items: menuItems, onSelect: handleMenuSelect, isFocused: true }),
102
113
  React.createElement(Box, { marginTop: 1 },
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  interface NewWorktreeProps {
3
+ projectPath?: string;
3
4
  onComplete: (path: string, branch: string, baseBranch: string, copySessionData: boolean, copyClaudeDirectory: boolean) => void;
4
5
  onCancel: () => void;
5
6
  }
@@ -7,7 +7,7 @@ import { configurationManager } from '../services/configurationManager.js';
7
7
  import { generateWorktreeDirectory } from '../utils/worktreeUtils.js';
8
8
  import { WorktreeService } from '../services/worktreeService.js';
9
9
  import { useSearchMode } from '../hooks/useSearchMode.js';
10
- const NewWorktree = ({ onComplete, onCancel }) => {
10
+ const NewWorktree = ({ projectPath, onComplete, onCancel, }) => {
11
11
  const worktreeConfig = configurationManager.getWorktreeConfig();
12
12
  const isAutoDirectory = worktreeConfig.autoDirectory;
13
13
  const limit = 10;
@@ -81,7 +81,7 @@ const NewWorktree = ({ onComplete, onCancel }) => {
81
81
  setCopySessionData(shouldCopy);
82
82
  if (isAutoDirectory) {
83
83
  // Generate path from branch name
84
- const autoPath = generateWorktreeDirectory(branch, worktreeConfig.autoDirectoryPattern);
84
+ const autoPath = generateWorktreeDirectory(projectPath || process.cwd(), branch, worktreeConfig.autoDirectoryPattern);
85
85
  onComplete(autoPath, branch, baseBranch, shouldCopy, copyClaudeDirectory);
86
86
  }
87
87
  else {
@@ -91,9 +91,14 @@ const NewWorktree = ({ onComplete, onCancel }) => {
91
91
  // Calculate generated path for preview (memoized to avoid expensive recalculations)
92
92
  const generatedPath = useMemo(() => {
93
93
  return isAutoDirectory && branch
94
- ? generateWorktreeDirectory(branch, worktreeConfig.autoDirectoryPattern)
94
+ ? generateWorktreeDirectory(projectPath || process.cwd(), branch, worktreeConfig.autoDirectoryPattern)
95
95
  : '';
96
- }, [isAutoDirectory, branch, worktreeConfig.autoDirectoryPattern]);
96
+ }, [
97
+ isAutoDirectory,
98
+ branch,
99
+ worktreeConfig.autoDirectoryPattern,
100
+ projectPath,
101
+ ]);
97
102
  return (React.createElement(Box, { flexDirection: "column" },
98
103
  React.createElement(Box, { marginBottom: 1 },
99
104
  React.createElement(Text, { bold: true, color: "green" }, "Create New Worktree")),
@@ -76,13 +76,13 @@ export class CodexStateDetector extends BaseStateDetector {
76
76
  const content = this.getTerminalContent(terminal);
77
77
  const lowerContent = content.toLowerCase();
78
78
  // Check for waiting prompts
79
- if (content.includes('│Allow') ||
80
- content.includes('[y/N]') ||
81
- content.includes('Press any key')) {
79
+ if (lowerContent.includes('allow command?') ||
80
+ lowerContent.includes('[y/n]') ||
81
+ lowerContent.includes('yes (y)')) {
82
82
  return 'waiting_input';
83
83
  }
84
84
  // Check for busy state
85
- if (lowerContent.includes('press esc')) {
85
+ if (/esc.*interrupt/i.test(lowerContent)) {
86
86
  return 'busy';
87
87
  }
88
88
  // Otherwise idle
@@ -295,38 +295,38 @@ describe('CodexStateDetector', () => {
295
295
  beforeEach(() => {
296
296
  detector = new CodexStateDetector();
297
297
  });
298
- it('should detect waiting_input state for Allow pattern', () => {
298
+ it('should detect waiting_input state for Allow command? pattern', () => {
299
299
  // Arrange
300
- terminal = createMockTerminal(['Some output', 'Allow execution?', '│ > ']);
300
+ terminal = createMockTerminal(['Some output', 'Allow command?', '│ > ']);
301
301
  // Act
302
302
  const state = detector.detectState(terminal, 'idle');
303
303
  // Assert
304
304
  expect(state).toBe('waiting_input');
305
305
  });
306
- it('should detect waiting_input state for [y/N] pattern', () => {
306
+ it('should detect waiting_input state for [y/n] pattern', () => {
307
307
  // Arrange
308
- terminal = createMockTerminal(['Some output', 'Continue? [y/N]', '> ']);
308
+ terminal = createMockTerminal(['Some output', 'Continue? [y/n]', '> ']);
309
309
  // Act
310
310
  const state = detector.detectState(terminal, 'idle');
311
311
  // Assert
312
312
  expect(state).toBe('waiting_input');
313
313
  });
314
- it('should detect waiting_input state for Press any key pattern', () => {
314
+ it('should detect waiting_input state for yes (y) pattern', () => {
315
315
  // Arrange
316
316
  terminal = createMockTerminal([
317
317
  'Some output',
318
- 'Press any key to continue...',
318
+ 'Apply changes? yes (y) / no (n)',
319
319
  ]);
320
320
  // Act
321
321
  const state = detector.detectState(terminal, 'idle');
322
322
  // Assert
323
323
  expect(state).toBe('waiting_input');
324
324
  });
325
- it('should detect busy state for press esc pattern', () => {
325
+ it('should detect busy state for Esc to interrupt pattern', () => {
326
326
  // Arrange
327
327
  terminal = createMockTerminal([
328
328
  'Processing...',
329
- 'press esc to cancel',
329
+ 'Esc to interrupt',
330
330
  'Working...',
331
331
  ]);
332
332
  // Act
@@ -334,11 +334,11 @@ describe('CodexStateDetector', () => {
334
334
  // Assert
335
335
  expect(state).toBe('busy');
336
336
  });
337
- it('should detect busy state for PRESS ESC (uppercase)', () => {
337
+ it('should detect busy state for ESC INTERRUPT (uppercase)', () => {
338
338
  // Arrange
339
339
  terminal = createMockTerminal([
340
340
  'Processing...',
341
- 'PRESS ESC to stop',
341
+ 'PRESS ESC TO INTERRUPT',
342
342
  'Working...',
343
343
  ]);
344
344
  // Act
@@ -356,7 +356,7 @@ describe('CodexStateDetector', () => {
356
356
  });
357
357
  it('should prioritize waiting_input over busy', () => {
358
358
  // Arrange
359
- terminal = createMockTerminal(['press esc to cancel', '[y/N]']);
359
+ terminal = createMockTerminal(['press esc to interrupt', '[y/n]']);
360
360
  // Act
361
361
  const state = detector.detectState(terminal, 'idle');
362
362
  // Assert
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect, vi } from 'vitest';
2
2
  import { executeHook, executeWorktreePostCreationHook, executeStatusHook, } from './hookExecutor.js';
3
- import { mkdtemp, rm, readFile } from 'fs/promises';
3
+ import { mkdtemp, rm, readFile, realpath } from 'fs/promises';
4
4
  import { tmpdir } from 'os';
5
5
  import { join } from 'path';
6
6
  import { configurationManager } from '../services/configurationManager.js';
@@ -137,7 +137,9 @@ describe('hookExecutor Integration Tests', () => {
137
137
  const { readFile } = await import('fs/promises');
138
138
  const output = await readFile(outputFile, 'utf-8');
139
139
  // Assert - should be executed in tmpDir
140
- expect(output.trim()).toBe(tmpDir);
140
+ const expectedPath = await realpath(tmpDir);
141
+ const actualPath = await realpath(output.trim());
142
+ expect(actualPath).toBe(expectedPath);
141
143
  }
142
144
  finally {
143
145
  // Cleanup
@@ -182,7 +184,10 @@ describe('hookExecutor Integration Tests', () => {
182
184
  const { readFile } = await import('fs/promises');
183
185
  const output = await readFile(outputFile, 'utf-8');
184
186
  // Assert - should be executed in worktree path, not git root
185
- expect(output.trim()).toBe(tmpDir);
187
+ const expectedPath = await realpath(tmpDir);
188
+ const actualPath = await realpath(output.trim());
189
+ expect(actualPath).toBe(expectedPath);
190
+ // Also verify it's not the git root path
186
191
  expect(output.trim()).not.toBe(gitRoot);
187
192
  }
188
193
  finally {
@@ -18,7 +18,7 @@ interface WorktreeItem {
18
18
  };
19
19
  }
20
20
  export declare function truncateString(str: string, maxLength: number): string;
21
- export declare function generateWorktreeDirectory(branchName: string, pattern?: string): string;
21
+ export declare function generateWorktreeDirectory(projectPath: string, branchName: string, pattern?: string): string;
22
22
  export declare function extractBranchParts(branchName: string): {
23
23
  prefix?: string;
24
24
  name: string;
@@ -1,4 +1,5 @@
1
1
  import path from 'path';
2
+ import { execSync } from 'child_process';
2
3
  import stripAnsi from 'strip-ansi';
3
4
  import { getStatusDisplay } from '../constants/statusIcons.js';
4
5
  import { formatGitFileChanges, formatGitAheadBehind, formatParentBranch, } from './gitStatus.js';
@@ -11,21 +12,46 @@ export function truncateString(str, maxLength) {
11
12
  return str;
12
13
  return str.substring(0, maxLength - 3) + '...';
13
14
  }
14
- export function generateWorktreeDirectory(branchName, pattern) {
15
+ function getGitRepositoryName(projectPath) {
16
+ try {
17
+ const gitCommonDir = execSync('git rev-parse --git-common-dir', {
18
+ cwd: projectPath,
19
+ encoding: 'utf8',
20
+ }).trim();
21
+ const absoluteGitCommonDir = path.isAbsolute(gitCommonDir)
22
+ ? gitCommonDir
23
+ : path.resolve(projectPath, gitCommonDir);
24
+ const mainWorkingDir = path.dirname(absoluteGitCommonDir);
25
+ return path.basename(mainWorkingDir);
26
+ }
27
+ catch {
28
+ return path.basename(projectPath);
29
+ }
30
+ }
31
+ export function generateWorktreeDirectory(projectPath, branchName, pattern) {
15
32
  // Default pattern if not specified
16
33
  const defaultPattern = '../{branch}';
17
34
  const activePattern = pattern || defaultPattern;
18
- // Sanitize branch name for filesystem
19
- // Replace slashes with dashes, remove special characters
20
- const sanitizedBranch = branchName
21
- .replace(/\//g, '-') // Replace forward slashes with dashes
22
- .replace(/[^a-zA-Z0-9-_.]/g, '') // Remove special characters except dash, dot, underscore
23
- .replace(/^-+|-+$/g, '') // Remove leading/trailing dashes
24
- .toLowerCase(); // Convert to lowercase for consistency
25
- // Replace placeholders in pattern
26
- const directory = activePattern
27
- .replace('{branch}', sanitizedBranch)
28
- .replace('{branch-name}', sanitizedBranch);
35
+ let sanitizedBranch;
36
+ let projectName;
37
+ const directory = activePattern.replace(/{(\w+)}/g, (placeholder, name) => {
38
+ switch (name) {
39
+ case 'branch':
40
+ case 'branch-name':
41
+ // Sanitize branch name for filesystem
42
+ sanitizedBranch ?? (sanitizedBranch = branchName
43
+ .replace(/\//g, '-') // Replace forward slashes with dashes
44
+ .replace(/[^a-zA-Z0-9-_.]+/g, '') // Remove special characters except dash, dot, underscore
45
+ .replace(/^-+|-+$/g, '') // Remove leading/trailing dashes
46
+ .toLowerCase()); // Convert to lowercase for consistency
47
+ return sanitizedBranch;
48
+ case 'project':
49
+ projectName ?? (projectName = getGitRepositoryName(projectPath));
50
+ return projectName;
51
+ default:
52
+ return placeholder;
53
+ }
54
+ });
29
55
  // Ensure the path is relative to the repository root
30
56
  return path.normalize(directory);
31
57
  }
@@ -1,39 +1,62 @@
1
- import { describe, it, expect } from 'vitest';
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
2
  import { generateWorktreeDirectory, extractBranchParts, truncateString, prepareWorktreeItems, calculateColumnPositions, assembleWorktreeLabel, } from './worktreeUtils.js';
3
+ import { execSync } from 'child_process';
4
+ // Mock child_process module
5
+ vi.mock('child_process');
3
6
  describe('generateWorktreeDirectory', () => {
7
+ const mockedExecSync = vi.mocked(execSync);
8
+ const projectPath = '/home/user/src/myproject';
9
+ beforeEach(() => {
10
+ vi.clearAllMocks();
11
+ });
4
12
  describe('with default pattern', () => {
5
13
  it('should generate directory with sanitized branch name', () => {
6
- expect(generateWorktreeDirectory('feature/my-feature')).toBe('../feature-my-feature');
7
- expect(generateWorktreeDirectory('bugfix/fix-123')).toBe('../bugfix-fix-123');
8
- expect(generateWorktreeDirectory('release/v1.0.0')).toBe('../release-v1.0.0');
14
+ expect(generateWorktreeDirectory(projectPath, 'feature/my-feature')).toBe('../feature-my-feature');
15
+ expect(generateWorktreeDirectory(projectPath, 'bugfix/fix-123')).toBe('../bugfix-fix-123');
16
+ expect(generateWorktreeDirectory(projectPath, 'release/v1.0.0')).toBe('../release-v1.0.0');
9
17
  });
10
18
  it('should handle branch names without slashes', () => {
11
- expect(generateWorktreeDirectory('main')).toBe('../main');
12
- expect(generateWorktreeDirectory('develop')).toBe('../develop');
13
- expect(generateWorktreeDirectory('my-feature')).toBe('../my-feature');
19
+ expect(generateWorktreeDirectory(projectPath, 'main')).toBe('../main');
20
+ expect(generateWorktreeDirectory(projectPath, 'develop')).toBe('../develop');
21
+ expect(generateWorktreeDirectory(projectPath, 'my-feature')).toBe('../my-feature');
14
22
  });
15
23
  it('should remove special characters', () => {
16
- expect(generateWorktreeDirectory('feature/my@feature!')).toBe('../feature-myfeature');
17
- expect(generateWorktreeDirectory('bugfix/#123')).toBe('../bugfix-123');
18
- expect(generateWorktreeDirectory('release/v1.0.0-beta')).toBe('../release-v1.0.0-beta');
24
+ expect(generateWorktreeDirectory(projectPath, 'feature/my@feature!')).toBe('../feature-myfeature');
25
+ expect(generateWorktreeDirectory(projectPath, 'bugfix/#123')).toBe('../bugfix-123');
26
+ expect(generateWorktreeDirectory(projectPath, 'release/v1.0.0-beta')).toBe('../release-v1.0.0-beta');
19
27
  });
20
28
  it('should handle edge cases', () => {
21
- expect(generateWorktreeDirectory('//feature//')).toBe('../feature');
22
- expect(generateWorktreeDirectory('-feature-')).toBe('../feature');
23
- expect(generateWorktreeDirectory('FEATURE/UPPERCASE')).toBe('../feature-uppercase');
29
+ expect(generateWorktreeDirectory(projectPath, '//feature//')).toBe('../feature');
30
+ expect(generateWorktreeDirectory(projectPath, '-feature-')).toBe('../feature');
31
+ expect(generateWorktreeDirectory(projectPath, 'FEATURE/UPPERCASE')).toBe('../feature-uppercase');
24
32
  });
25
33
  });
26
34
  describe('with custom patterns', () => {
27
35
  it('should use custom pattern with {branch} placeholder', () => {
28
- expect(generateWorktreeDirectory('feature/my-feature', '../worktrees/{branch}')).toBe('../worktrees/feature-my-feature');
29
- expect(generateWorktreeDirectory('bugfix/123', '/tmp/{branch}-wt')).toBe('/tmp/bugfix-123-wt');
36
+ expect(generateWorktreeDirectory(projectPath, 'feature/my-feature', '../worktrees/{branch}')).toBe('../worktrees/feature-my-feature');
37
+ expect(generateWorktreeDirectory(projectPath, 'bugfix/123', '/tmp/{branch}-wt')).toBe('/tmp/bugfix-123-wt');
38
+ });
39
+ it('should use git repository name when in main working directory', () => {
40
+ mockedExecSync.mockReturnValue('.git');
41
+ expect(generateWorktreeDirectory('/home/user/src/main-repo', 'feature/test', '../worktrees/{project}-{branch}')).toBe('../worktrees/main-repo-feature-test');
42
+ });
43
+ it('should use git repository name when git command succeeds (worktree case)', () => {
44
+ mockedExecSync.mockReturnValue('/home/user/src/main-repo/.git');
45
+ expect(generateWorktreeDirectory('/home/user/src/worktree-branch', 'feature/test', '../worktrees/{project}-{branch}')).toBe('../worktrees/main-repo-feature-test');
46
+ });
47
+ it('should use custom pattern with {project} placeholder (fallback case)', () => {
48
+ mockedExecSync.mockImplementation(() => {
49
+ throw new Error('fatal: not a git repository (or any of the parent directories): .git');
50
+ });
51
+ expect(generateWorktreeDirectory('/home/user/src/myproject', 'feature/test', '../worktrees/{project}-{branch}')).toBe('../worktrees/myproject-feature-test');
52
+ expect(generateWorktreeDirectory('/home/user/src/foo', 'main', '/tmp/{project}')).toBe('/tmp/foo');
30
53
  });
31
54
  it('should handle patterns without placeholders', () => {
32
- expect(generateWorktreeDirectory('feature/test', '../fixed-directory')).toBe('../fixed-directory');
55
+ expect(generateWorktreeDirectory(projectPath, 'feature/test', '../fixed-directory')).toBe('../fixed-directory');
33
56
  });
34
57
  it('should normalize paths', () => {
35
- expect(generateWorktreeDirectory('feature/test', '../foo/../bar/{branch}')).toBe('../bar/feature-test');
36
- expect(generateWorktreeDirectory('feature/test', './worktrees/{branch}')).toBe('worktrees/feature-test');
58
+ expect(generateWorktreeDirectory(projectPath, 'feature/test', '../foo/../bar/{branch}')).toBe('../bar/feature-test');
59
+ expect(generateWorktreeDirectory(projectPath, 'feature/test', './worktrees/{branch}')).toBe('worktrees/feature-test');
37
60
  });
38
61
  });
39
62
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccmanager",
3
- "version": "2.2.4",
3
+ "version": "2.4.0",
4
4
  "description": "TUI application for managing multiple Claude Code sessions across Git worktrees",
5
5
  "license": "MIT",
6
6
  "author": "Kodai Kabasawa",