ccmanager 3.6.1 → 3.6.4
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/Menu.recent-projects.test.js +3 -1
- package/dist/services/stateDetector/base.js +4 -15
- package/dist/services/stateDetector/claude.test.js +52 -0
- package/dist/services/stateDetector/testUtils.d.ts +6 -1
- package/dist/services/stateDetector/testUtils.js +9 -3
- package/dist/services/worktreeService.js +15 -0
- package/dist/services/worktreeService.submodule.test.d.ts +1 -0
- package/dist/services/worktreeService.submodule.test.js +82 -0
- package/dist/utils/gitUtils.d.ts +1 -0
- package/dist/utils/gitUtils.js +11 -0
- package/dist/utils/gitUtils.submodule.test.d.ts +1 -0
- package/dist/utils/gitUtils.submodule.test.js +66 -0
- package/dist/utils/screenCapture.js +6 -3
- package/dist/utils/worktreeUtils.js +9 -0
- package/dist/utils/worktreeUtils.submodule.test.d.ts +1 -0
- package/dist/utils/worktreeUtils.submodule.test.js +63 -0
- package/package.json +6 -6
|
@@ -126,7 +126,9 @@ describe('Menu - Recent Projects', () => {
|
|
|
126
126
|
backgroundTasks: 0,
|
|
127
127
|
});
|
|
128
128
|
vi.spyOn(SessionManager, 'formatSessionCounts').mockReturnValue('');
|
|
129
|
-
const { lastFrame } = render(_jsx(Menu, { sessionManager: mockSessionManager, worktreeService: mockWorktreeService, onSelectWorktree: vi.fn(), onSelectRecentProject: vi.fn(), multiProject: true, version: "test" }));
|
|
129
|
+
const { lastFrame, rerender } = render(_jsx(Menu, { sessionManager: mockSessionManager, worktreeService: mockWorktreeService, onSelectWorktree: vi.fn(), onSelectRecentProject: vi.fn(), multiProject: true, version: "test" }));
|
|
130
|
+
// Force a rerender to ensure all effects have run
|
|
131
|
+
rerender(_jsx(Menu, { sessionManager: mockSessionManager, worktreeService: mockWorktreeService, onSelectWorktree: vi.fn(), onSelectRecentProject: vi.fn(), multiProject: true, version: "test" }));
|
|
130
132
|
// Wait for Effect to execute
|
|
131
133
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
132
134
|
const output = lastFrame();
|
|
@@ -1,21 +1,10 @@
|
|
|
1
|
+
import { getTerminalScreenContent } from '../../utils/screenCapture.js';
|
|
1
2
|
export class BaseStateDetector {
|
|
2
3
|
getTerminalLines(terminal, maxLines = 30) {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
// Start from the bottom and work our way up
|
|
6
|
-
for (let i = buffer.length - 1; i >= 0 && lines.length < maxLines; i--) {
|
|
7
|
-
const line = buffer.getLine(i);
|
|
8
|
-
if (line) {
|
|
9
|
-
const text = line.translateToString(true);
|
|
10
|
-
// Skip empty lines at the bottom
|
|
11
|
-
if (lines.length > 0 || text.trim() !== '') {
|
|
12
|
-
lines.unshift(text);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return lines;
|
|
4
|
+
const content = getTerminalScreenContent(terminal, maxLines);
|
|
5
|
+
return content.split('\n');
|
|
17
6
|
}
|
|
18
7
|
getTerminalContent(terminal, maxLines = 30) {
|
|
19
|
-
return
|
|
8
|
+
return getTerminalScreenContent(terminal, maxLines);
|
|
20
9
|
}
|
|
21
10
|
}
|
|
@@ -221,6 +221,58 @@ describe('ClaudeStateDetector', () => {
|
|
|
221
221
|
// Assert
|
|
222
222
|
expect(state).toBe('waiting_input');
|
|
223
223
|
});
|
|
224
|
+
it('should detect idle when scrolled past old busy state (baseY > 0)', () => {
|
|
225
|
+
// Arrange - Simulate scrollback where "esc to interrupt" is in history
|
|
226
|
+
// but the current viewport (baseY=5, rows=3) shows idle content
|
|
227
|
+
// Buffer: [0]: "Old content", [1]: "esc to interrupt", [2]: "More busy output",
|
|
228
|
+
// [3]: "...", [4]: "...", [5]: "Ready", [6]: "Prompt >", [7]: "idle"
|
|
229
|
+
// Viewport shows lines 5-7 (baseY=5, rows=3)
|
|
230
|
+
terminal = createMockTerminal([
|
|
231
|
+
'Old content',
|
|
232
|
+
'Previous output with esc to interrupt marker',
|
|
233
|
+
'More old busy output',
|
|
234
|
+
'Transition content',
|
|
235
|
+
'Processing done',
|
|
236
|
+
'Ready for input',
|
|
237
|
+
'Prompt >',
|
|
238
|
+
'idle state here',
|
|
239
|
+
], { baseY: 5, rows: 3 });
|
|
240
|
+
// Act
|
|
241
|
+
const state = detector.detectState(terminal, 'busy');
|
|
242
|
+
// Assert - Should detect idle because viewport shows lines 5-7
|
|
243
|
+
expect(state).toBe('idle');
|
|
244
|
+
});
|
|
245
|
+
it('should detect busy when scrolled to busy state (baseY shows busy content)', () => {
|
|
246
|
+
// Arrange - Viewport shows busy content
|
|
247
|
+
// Buffer has old idle content at top, busy content in viewport
|
|
248
|
+
terminal = createMockTerminal([
|
|
249
|
+
'Old idle content',
|
|
250
|
+
'Previous prompt',
|
|
251
|
+
'User input',
|
|
252
|
+
'Processing request...',
|
|
253
|
+
'Press esc to interrupt',
|
|
254
|
+
'Working...',
|
|
255
|
+
], { baseY: 3, rows: 3 });
|
|
256
|
+
// Act
|
|
257
|
+
const state = detector.detectState(terminal, 'idle');
|
|
258
|
+
// Assert - Should detect busy because viewport shows lines 3-5
|
|
259
|
+
expect(state).toBe('busy');
|
|
260
|
+
});
|
|
261
|
+
it('should detect waiting_input when viewport shows prompt after scroll', () => {
|
|
262
|
+
// Arrange - Scrollback has busy markers, but viewport shows waiting prompt
|
|
263
|
+
terminal = createMockTerminal([
|
|
264
|
+
'Previous busy content',
|
|
265
|
+
'esc to interrupt was here',
|
|
266
|
+
'Old output',
|
|
267
|
+
'Do you want to continue?',
|
|
268
|
+
'❯ 1. Yes',
|
|
269
|
+
' 2. No',
|
|
270
|
+
], { baseY: 3, rows: 3 });
|
|
271
|
+
// Act
|
|
272
|
+
const state = detector.detectState(terminal, 'busy');
|
|
273
|
+
// Assert - Should detect waiting_input from viewport
|
|
274
|
+
expect(state).toBe('waiting_input');
|
|
275
|
+
});
|
|
224
276
|
});
|
|
225
277
|
describe('detectBackgroundTask', () => {
|
|
226
278
|
it('should return count 1 when "1 background task" is in status bar', () => {
|
|
@@ -2,6 +2,11 @@ import type { Terminal } from '../../types/index.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Creates a mock Terminal object for testing state detectors.
|
|
4
4
|
* @param lines - Array of strings representing terminal output lines
|
|
5
|
+
* @param options - Optional configuration for rows, cols, and baseY
|
|
5
6
|
* @returns Mock Terminal object with buffer interface
|
|
6
7
|
*/
|
|
7
|
-
export declare const createMockTerminal: (lines: string[]
|
|
8
|
+
export declare const createMockTerminal: (lines: string[], options?: {
|
|
9
|
+
rows?: number;
|
|
10
|
+
cols?: number;
|
|
11
|
+
baseY?: number;
|
|
12
|
+
}) => Terminal;
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates a mock Terminal object for testing state detectors.
|
|
3
3
|
* @param lines - Array of strings representing terminal output lines
|
|
4
|
+
* @param options - Optional configuration for rows, cols, and baseY
|
|
4
5
|
* @returns Mock Terminal object with buffer interface
|
|
5
6
|
*/
|
|
6
|
-
export const createMockTerminal = (lines) => {
|
|
7
|
+
export const createMockTerminal = (lines, options) => {
|
|
8
|
+
const rows = options?.rows ?? lines.length;
|
|
9
|
+
const cols = options?.cols ?? 80;
|
|
10
|
+
const baseY = options?.baseY ?? 0;
|
|
7
11
|
const buffer = {
|
|
8
12
|
length: lines.length,
|
|
9
13
|
active: {
|
|
14
|
+
type: 'normal',
|
|
10
15
|
length: lines.length,
|
|
16
|
+
baseY,
|
|
11
17
|
getLine: (index) => {
|
|
12
18
|
if (index >= 0 && index < lines.length) {
|
|
13
19
|
return {
|
|
14
|
-
translateToString: () => lines[index],
|
|
20
|
+
translateToString: (_trimRight, _startCol, _endCol) => lines[index],
|
|
15
21
|
};
|
|
16
22
|
}
|
|
17
23
|
return null;
|
|
18
24
|
},
|
|
19
25
|
},
|
|
20
26
|
};
|
|
21
|
-
return { buffer };
|
|
27
|
+
return { buffer, rows, cols };
|
|
22
28
|
};
|
|
@@ -72,6 +72,15 @@ export class WorktreeService {
|
|
|
72
72
|
const absoluteGitCommonDir = path.isAbsolute(gitCommonDir)
|
|
73
73
|
? gitCommonDir
|
|
74
74
|
: path.resolve(this.rootPath, gitCommonDir);
|
|
75
|
+
// Handle submodule paths: if path contains .git/modules, use --show-toplevel
|
|
76
|
+
// to get the submodule's actual working directory
|
|
77
|
+
if (absoluteGitCommonDir.includes('.git/modules')) {
|
|
78
|
+
const toplevel = execSync('git rev-parse --show-toplevel', {
|
|
79
|
+
cwd: this.rootPath,
|
|
80
|
+
encoding: 'utf8',
|
|
81
|
+
}).trim();
|
|
82
|
+
return toplevel;
|
|
83
|
+
}
|
|
75
84
|
// Handle worktree paths: if path contains .git/worktrees, we need to find the real .git parent
|
|
76
85
|
if (absoluteGitCommonDir.includes('.git/worktrees')) {
|
|
77
86
|
// Extract the path up to and including .git
|
|
@@ -647,6 +656,12 @@ export class WorktreeService {
|
|
|
647
656
|
if (worktrees.length > 0 && !worktrees.some(w => w.isMainWorktree)) {
|
|
648
657
|
worktrees[0].isMainWorktree = true;
|
|
649
658
|
}
|
|
659
|
+
// Handle submodule paths: if the main worktree path contains .git/modules,
|
|
660
|
+
// replace it with the actual working directory (self.gitRootPath)
|
|
661
|
+
const mainWorktree = worktrees.find(w => w.isMainWorktree);
|
|
662
|
+
if (mainWorktree && mainWorktree.path.includes('.git/modules')) {
|
|
663
|
+
mainWorktree.path = self.gitRootPath;
|
|
664
|
+
}
|
|
650
665
|
// Sort worktrees by last session if requested
|
|
651
666
|
if (sortByLastSession) {
|
|
652
667
|
worktrees.sort((a, b) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
2
|
+
import { execSync } from 'child_process';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import os from 'os';
|
|
6
|
+
import { Effect } from 'effect';
|
|
7
|
+
import { WorktreeService } from './worktreeService.js';
|
|
8
|
+
describe('WorktreeService with submodules', () => {
|
|
9
|
+
// Use os.tmpdir() and unique suffix to avoid conflicts with parallel tests
|
|
10
|
+
// Use realpathSync to resolve symlinks (e.g., /var -> /private/var on macOS)
|
|
11
|
+
const testDir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'ccmanager-ws-submodule-test-')));
|
|
12
|
+
const rootProjectDir = path.join(testDir, 'root-project');
|
|
13
|
+
const submodule1Dir = path.join(rootProjectDir, 'modules', 'submodule-1');
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
// Allow file:// protocol for local submodule cloning (needed for CI)
|
|
16
|
+
execSync('git config --global protocol.file.allow always');
|
|
17
|
+
// Clean up if exists
|
|
18
|
+
if (fs.existsSync(testDir)) {
|
|
19
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
20
|
+
}
|
|
21
|
+
// Create test directory structure
|
|
22
|
+
fs.mkdirSync(testDir, { recursive: true });
|
|
23
|
+
// Create submodule source repository
|
|
24
|
+
const submodule1Source = path.join(testDir, 'submodule-1-source');
|
|
25
|
+
fs.mkdirSync(submodule1Source, { recursive: true });
|
|
26
|
+
execSync('git init', { cwd: submodule1Source });
|
|
27
|
+
// Set git user for CI environment
|
|
28
|
+
execSync('git config user.email "test@test.com"', { cwd: submodule1Source });
|
|
29
|
+
execSync('git config user.name "Test User"', { cwd: submodule1Source });
|
|
30
|
+
fs.writeFileSync(path.join(submodule1Source, 'README.md'), '# Submodule 1');
|
|
31
|
+
execSync('git add README.md', { cwd: submodule1Source });
|
|
32
|
+
execSync('git commit -m "Initial commit"', { cwd: submodule1Source });
|
|
33
|
+
// Create root project
|
|
34
|
+
fs.mkdirSync(rootProjectDir, { recursive: true });
|
|
35
|
+
execSync('git init', { cwd: rootProjectDir });
|
|
36
|
+
// Set git user for CI environment
|
|
37
|
+
execSync('git config user.email "test@test.com"', { cwd: rootProjectDir });
|
|
38
|
+
execSync('git config user.name "Test User"', { cwd: rootProjectDir });
|
|
39
|
+
fs.writeFileSync(path.join(rootProjectDir, 'README.md'), '# Root Project');
|
|
40
|
+
execSync('git add README.md', { cwd: rootProjectDir });
|
|
41
|
+
execSync('git commit -m "Initial commit"', { cwd: rootProjectDir });
|
|
42
|
+
// Add submodule
|
|
43
|
+
execSync(`git submodule add ${submodule1Source} modules/submodule-1`, {
|
|
44
|
+
cwd: rootProjectDir,
|
|
45
|
+
});
|
|
46
|
+
execSync('git commit -m "Add submodule"', { cwd: rootProjectDir });
|
|
47
|
+
});
|
|
48
|
+
afterAll(() => {
|
|
49
|
+
// Clean up
|
|
50
|
+
if (fs.existsSync(testDir)) {
|
|
51
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
it('should return the submodule working directory from getGitRootPath()', () => {
|
|
55
|
+
const service = new WorktreeService(submodule1Dir);
|
|
56
|
+
const result = service.getGitRootPath();
|
|
57
|
+
// Should return the submodule's working directory
|
|
58
|
+
expect(result).toBe(submodule1Dir);
|
|
59
|
+
// Should NOT return a path containing .git/modules
|
|
60
|
+
expect(result).not.toContain('.git/modules');
|
|
61
|
+
});
|
|
62
|
+
it('should still work for regular repositories', () => {
|
|
63
|
+
const service = new WorktreeService(rootProjectDir);
|
|
64
|
+
const result = service.getGitRootPath();
|
|
65
|
+
expect(result).toBe(rootProjectDir);
|
|
66
|
+
expect(path.basename(result)).toBe('root-project');
|
|
67
|
+
});
|
|
68
|
+
it('should return worktrees with correct paths (not .git/modules paths) for submodules', async () => {
|
|
69
|
+
const service = new WorktreeService(submodule1Dir);
|
|
70
|
+
const worktrees = await Effect.runPromise(service.getWorktreesEffect());
|
|
71
|
+
// Should have at least one worktree
|
|
72
|
+
expect(worktrees.length).toBeGreaterThan(0);
|
|
73
|
+
// The main worktree path should be the submodule working directory
|
|
74
|
+
const mainWorktree = worktrees.find(wt => wt.isMainWorktree);
|
|
75
|
+
expect(mainWorktree).toBeDefined();
|
|
76
|
+
expect(mainWorktree.path).toBe(submodule1Dir);
|
|
77
|
+
// No worktree should have .git/modules in its path
|
|
78
|
+
for (const wt of worktrees) {
|
|
79
|
+
expect(wt.path).not.toContain('.git/modules');
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
package/dist/utils/gitUtils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Get the git repository root path from a given directory.
|
|
3
3
|
* For worktrees, this returns the main repository root (parent of .git).
|
|
4
|
+
* For submodules, this returns the submodule's working directory.
|
|
4
5
|
*
|
|
5
6
|
* @param cwd - The directory to start searching from
|
|
6
7
|
* @returns The absolute path to the git repository root, or null if not in a git repo
|
package/dist/utils/gitUtils.js
CHANGED
|
@@ -3,6 +3,7 @@ import { execSync } from 'child_process';
|
|
|
3
3
|
/**
|
|
4
4
|
* Get the git repository root path from a given directory.
|
|
5
5
|
* For worktrees, this returns the main repository root (parent of .git).
|
|
6
|
+
* For submodules, this returns the submodule's working directory.
|
|
6
7
|
*
|
|
7
8
|
* @param cwd - The directory to start searching from
|
|
8
9
|
* @returns The absolute path to the git repository root, or null if not in a git repo
|
|
@@ -17,6 +18,16 @@ export function getGitRepositoryRoot(cwd) {
|
|
|
17
18
|
const absoluteGitCommonDir = path.isAbsolute(gitCommonDir)
|
|
18
19
|
? gitCommonDir
|
|
19
20
|
: path.resolve(cwd, gitCommonDir);
|
|
21
|
+
// Handle submodule paths: if path contains .git/modules, use --show-toplevel
|
|
22
|
+
// to get the submodule's actual working directory
|
|
23
|
+
if (absoluteGitCommonDir.includes('.git/modules')) {
|
|
24
|
+
const toplevel = execSync('git rev-parse --show-toplevel', {
|
|
25
|
+
cwd,
|
|
26
|
+
encoding: 'utf8',
|
|
27
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
28
|
+
}).trim();
|
|
29
|
+
return toplevel;
|
|
30
|
+
}
|
|
20
31
|
// Handle worktree paths: if path contains .git/worktrees, find the real .git parent
|
|
21
32
|
if (absoluteGitCommonDir.includes('.git/worktrees')) {
|
|
22
33
|
const gitIndex = absoluteGitCommonDir.indexOf('.git');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
2
|
+
import { execSync } from 'child_process';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import os from 'os';
|
|
6
|
+
import { getGitRepositoryRoot } from './gitUtils.js';
|
|
7
|
+
describe('getGitRepositoryRoot with submodules', () => {
|
|
8
|
+
// Use os.tmpdir() and unique suffix to avoid conflicts with parallel tests
|
|
9
|
+
// Use realpathSync to resolve symlinks (e.g., /var -> /private/var on macOS)
|
|
10
|
+
const testDir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'ccmanager-submodule-test-')));
|
|
11
|
+
const rootProjectDir = path.join(testDir, 'root-project');
|
|
12
|
+
const submodule1Dir = path.join(rootProjectDir, 'modules', 'submodule-1');
|
|
13
|
+
beforeAll(() => {
|
|
14
|
+
// Allow file:// protocol for local submodule cloning (needed for CI)
|
|
15
|
+
execSync('git config --global protocol.file.allow always');
|
|
16
|
+
// Clean up if exists
|
|
17
|
+
if (fs.existsSync(testDir)) {
|
|
18
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
19
|
+
}
|
|
20
|
+
// Create test directory structure
|
|
21
|
+
fs.mkdirSync(testDir, { recursive: true });
|
|
22
|
+
// Create submodule source repository
|
|
23
|
+
const submodule1Source = path.join(testDir, 'submodule-1-source');
|
|
24
|
+
fs.mkdirSync(submodule1Source, { recursive: true });
|
|
25
|
+
execSync('git init', { cwd: submodule1Source });
|
|
26
|
+
// Set git user for CI environment
|
|
27
|
+
execSync('git config user.email "test@test.com"', { cwd: submodule1Source });
|
|
28
|
+
execSync('git config user.name "Test User"', { cwd: submodule1Source });
|
|
29
|
+
fs.writeFileSync(path.join(submodule1Source, 'README.md'), '# Submodule 1');
|
|
30
|
+
execSync('git add README.md', { cwd: submodule1Source });
|
|
31
|
+
execSync('git commit -m "Initial commit"', { cwd: submodule1Source });
|
|
32
|
+
// Create root project
|
|
33
|
+
fs.mkdirSync(rootProjectDir, { recursive: true });
|
|
34
|
+
execSync('git init', { cwd: rootProjectDir });
|
|
35
|
+
// Set git user for CI environment
|
|
36
|
+
execSync('git config user.email "test@test.com"', { cwd: rootProjectDir });
|
|
37
|
+
execSync('git config user.name "Test User"', { cwd: rootProjectDir });
|
|
38
|
+
fs.writeFileSync(path.join(rootProjectDir, 'README.md'), '# Root Project');
|
|
39
|
+
execSync('git add README.md', { cwd: rootProjectDir });
|
|
40
|
+
execSync('git commit -m "Initial commit"', { cwd: rootProjectDir });
|
|
41
|
+
// Add submodule
|
|
42
|
+
execSync(`git submodule add ${submodule1Source} modules/submodule-1`, {
|
|
43
|
+
cwd: rootProjectDir,
|
|
44
|
+
});
|
|
45
|
+
execSync('git commit -m "Add submodule"', { cwd: rootProjectDir });
|
|
46
|
+
});
|
|
47
|
+
afterAll(() => {
|
|
48
|
+
// Clean up
|
|
49
|
+
if (fs.existsSync(testDir)) {
|
|
50
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
it('should return the submodule working directory, not the parent .git/modules path', () => {
|
|
54
|
+
// When running from within a submodule
|
|
55
|
+
const result = getGitRepositoryRoot(submodule1Dir);
|
|
56
|
+
// Should return the submodule's working directory
|
|
57
|
+
expect(result).toBe(submodule1Dir);
|
|
58
|
+
// Should NOT return a path containing .git/modules
|
|
59
|
+
expect(result).not.toContain('.git/modules');
|
|
60
|
+
});
|
|
61
|
+
it('should still work for regular repositories', () => {
|
|
62
|
+
const result = getGitRepositoryRoot(rootProjectDir);
|
|
63
|
+
expect(result).toBe(rootProjectDir);
|
|
64
|
+
expect(path.basename(result)).toBe('root-project');
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -15,10 +15,13 @@ function lineToString(line, cols) {
|
|
|
15
15
|
export function captureScreen(terminal) {
|
|
16
16
|
const buffer = terminal.buffer.active;
|
|
17
17
|
const lines = [];
|
|
18
|
-
//
|
|
19
|
-
//
|
|
18
|
+
// baseY is the offset of the viewport within the buffer
|
|
19
|
+
// For alternate buffer: baseY is always 0
|
|
20
|
+
// For normal buffer: baseY indicates how much has been scrolled
|
|
21
|
+
const baseY = buffer.baseY;
|
|
22
|
+
// Capture the visible viewport (not the beginning of scrollback)
|
|
20
23
|
for (let y = 0; y < terminal.rows; y++) {
|
|
21
|
-
const line = buffer.getLine(y);
|
|
24
|
+
const line = buffer.getLine(baseY + y);
|
|
22
25
|
lines.push(lineToString(line, terminal.cols));
|
|
23
26
|
}
|
|
24
27
|
return {
|
|
@@ -21,6 +21,15 @@ function getGitRepositoryName(projectPath) {
|
|
|
21
21
|
const absoluteGitCommonDir = path.isAbsolute(gitCommonDir)
|
|
22
22
|
? gitCommonDir
|
|
23
23
|
: path.resolve(projectPath, gitCommonDir);
|
|
24
|
+
// Handle submodule paths: if path contains .git/modules, use --show-toplevel
|
|
25
|
+
// to get the submodule's actual working directory
|
|
26
|
+
if (absoluteGitCommonDir.includes('.git/modules')) {
|
|
27
|
+
const toplevel = execSync('git rev-parse --show-toplevel', {
|
|
28
|
+
cwd: projectPath,
|
|
29
|
+
encoding: 'utf8',
|
|
30
|
+
}).trim();
|
|
31
|
+
return path.basename(toplevel);
|
|
32
|
+
}
|
|
24
33
|
const mainWorkingDir = path.dirname(absoluteGitCommonDir);
|
|
25
34
|
return path.basename(mainWorkingDir);
|
|
26
35
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
2
|
+
import { execSync } from 'child_process';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import os from 'os';
|
|
6
|
+
import { generateWorktreeDirectory } from './worktreeUtils.js';
|
|
7
|
+
describe('generateWorktreeDirectory with submodules', () => {
|
|
8
|
+
// Use os.tmpdir() and unique suffix to avoid conflicts with parallel tests
|
|
9
|
+
// Use realpathSync to resolve symlinks (e.g., /var -> /private/var on macOS)
|
|
10
|
+
const testDir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'ccmanager-wt-submodule-test-')));
|
|
11
|
+
const rootProjectDir = path.join(testDir, 'root-project');
|
|
12
|
+
const submodule1Dir = path.join(rootProjectDir, 'modules', 'submodule-1');
|
|
13
|
+
beforeAll(() => {
|
|
14
|
+
// Allow file:// protocol for local submodule cloning (needed for CI)
|
|
15
|
+
execSync('git config --global protocol.file.allow always');
|
|
16
|
+
// Clean up if exists
|
|
17
|
+
if (fs.existsSync(testDir)) {
|
|
18
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
19
|
+
}
|
|
20
|
+
// Create test directory structure
|
|
21
|
+
fs.mkdirSync(testDir, { recursive: true });
|
|
22
|
+
// Create submodule source repository
|
|
23
|
+
const submodule1Source = path.join(testDir, 'submodule-1-source');
|
|
24
|
+
fs.mkdirSync(submodule1Source, { recursive: true });
|
|
25
|
+
execSync('git init', { cwd: submodule1Source });
|
|
26
|
+
// Set git user for CI environment
|
|
27
|
+
execSync('git config user.email "test@test.com"', { cwd: submodule1Source });
|
|
28
|
+
execSync('git config user.name "Test User"', { cwd: submodule1Source });
|
|
29
|
+
fs.writeFileSync(path.join(submodule1Source, 'README.md'), '# Submodule 1');
|
|
30
|
+
execSync('git add README.md', { cwd: submodule1Source });
|
|
31
|
+
execSync('git commit -m "Initial commit"', { cwd: submodule1Source });
|
|
32
|
+
// Create root project
|
|
33
|
+
fs.mkdirSync(rootProjectDir, { recursive: true });
|
|
34
|
+
execSync('git init', { cwd: rootProjectDir });
|
|
35
|
+
// Set git user for CI environment
|
|
36
|
+
execSync('git config user.email "test@test.com"', { cwd: rootProjectDir });
|
|
37
|
+
execSync('git config user.name "Test User"', { cwd: rootProjectDir });
|
|
38
|
+
fs.writeFileSync(path.join(rootProjectDir, 'README.md'), '# Root Project');
|
|
39
|
+
execSync('git add README.md', { cwd: rootProjectDir });
|
|
40
|
+
execSync('git commit -m "Initial commit"', { cwd: rootProjectDir });
|
|
41
|
+
// Add submodule
|
|
42
|
+
execSync(`git submodule add ${submodule1Source} modules/submodule-1`, {
|
|
43
|
+
cwd: rootProjectDir,
|
|
44
|
+
});
|
|
45
|
+
execSync('git commit -m "Add submodule"', { cwd: rootProjectDir });
|
|
46
|
+
});
|
|
47
|
+
afterAll(() => {
|
|
48
|
+
// Clean up
|
|
49
|
+
if (fs.existsSync(testDir)) {
|
|
50
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
it('should use submodule name (not "modules") in {project} placeholder', () => {
|
|
54
|
+
const result = generateWorktreeDirectory(submodule1Dir, 'feature/test', '../worktrees/{project}-{branch}');
|
|
55
|
+
// Should contain "submodule-1", not "modules"
|
|
56
|
+
expect(result).toContain('submodule-1');
|
|
57
|
+
expect(result).not.toContain('modules-');
|
|
58
|
+
});
|
|
59
|
+
it('should work correctly for regular repositories', () => {
|
|
60
|
+
const result = generateWorktreeDirectory(rootProjectDir, 'feature/test', '../worktrees/{project}-{branch}');
|
|
61
|
+
expect(result).toContain('root-project');
|
|
62
|
+
});
|
|
63
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ccmanager",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.4",
|
|
4
4
|
"description": "TUI application for managing multiple Claude Code sessions across Git worktrees",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Kodai Kabasawa",
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"bin"
|
|
42
42
|
],
|
|
43
43
|
"optionalDependencies": {
|
|
44
|
-
"@kodaikabasawa/ccmanager-darwin-arm64": "3.6.
|
|
45
|
-
"@kodaikabasawa/ccmanager-darwin-x64": "3.6.
|
|
46
|
-
"@kodaikabasawa/ccmanager-linux-arm64": "3.6.
|
|
47
|
-
"@kodaikabasawa/ccmanager-linux-x64": "3.6.
|
|
48
|
-
"@kodaikabasawa/ccmanager-win32-x64": "3.6.
|
|
44
|
+
"@kodaikabasawa/ccmanager-darwin-arm64": "3.6.4",
|
|
45
|
+
"@kodaikabasawa/ccmanager-darwin-x64": "3.6.4",
|
|
46
|
+
"@kodaikabasawa/ccmanager-linux-arm64": "3.6.4",
|
|
47
|
+
"@kodaikabasawa/ccmanager-linux-x64": "3.6.4",
|
|
48
|
+
"@kodaikabasawa/ccmanager-win32-x64": "3.6.4"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@eslint/js": "^9.28.0",
|