ccmanager 3.4.0 → 3.5.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.
Files changed (89) hide show
  1. package/README.md +11 -5
  2. package/dist/components/App.js +17 -3
  3. package/dist/components/App.test.js +5 -5
  4. package/dist/components/Configuration.d.ts +2 -0
  5. package/dist/components/Configuration.js +6 -2
  6. package/dist/components/ConfigureCommand.js +34 -11
  7. package/dist/components/ConfigureOther.js +18 -4
  8. package/dist/components/ConfigureOther.test.js +48 -12
  9. package/dist/components/ConfigureShortcuts.js +27 -85
  10. package/dist/components/ConfigureStatusHooks.js +19 -4
  11. package/dist/components/ConfigureStatusHooks.test.js +46 -12
  12. package/dist/components/ConfigureWorktree.js +18 -4
  13. package/dist/components/ConfigureWorktreeHooks.js +19 -4
  14. package/dist/components/ConfigureWorktreeHooks.test.js +49 -14
  15. package/dist/components/Menu.js +72 -14
  16. package/dist/components/NewWorktree.js +2 -2
  17. package/dist/components/NewWorktree.test.js +6 -6
  18. package/dist/components/PresetSelector.js +2 -2
  19. package/dist/constants/statusIcons.d.ts +2 -1
  20. package/dist/constants/statusIcons.js +13 -4
  21. package/dist/constants/statusIcons.test.js +41 -11
  22. package/dist/contexts/ConfigEditorContext.d.ts +21 -0
  23. package/dist/contexts/ConfigEditorContext.js +25 -0
  24. package/dist/services/autoApprovalVerifier.js +3 -3
  25. package/dist/services/autoApprovalVerifier.test.js +2 -2
  26. package/dist/services/config/configEditor.d.ts +46 -0
  27. package/dist/services/{configurationManager.effect.test.js → config/configEditor.effect.test.js} +46 -49
  28. package/dist/services/config/configEditor.js +101 -0
  29. package/dist/services/{configurationManager.selectPresetOnStart.test.js → config/configEditor.selectPresetOnStart.test.js} +27 -19
  30. package/dist/services/{configurationManager.test.js → config/configEditor.test.js} +60 -132
  31. package/dist/services/config/configReader.d.ts +28 -0
  32. package/dist/services/config/configReader.js +95 -0
  33. package/dist/services/config/configReader.multiProject.test.d.ts +1 -0
  34. package/dist/services/config/configReader.multiProject.test.js +136 -0
  35. package/dist/services/config/globalConfigManager.d.ts +30 -0
  36. package/dist/services/config/globalConfigManager.js +216 -0
  37. package/dist/services/config/index.d.ts +13 -0
  38. package/dist/services/config/index.js +13 -0
  39. package/dist/services/config/projectConfigManager.d.ts +41 -0
  40. package/dist/services/config/projectConfigManager.js +181 -0
  41. package/dist/services/config/projectConfigManager.test.d.ts +1 -0
  42. package/dist/services/config/projectConfigManager.test.js +105 -0
  43. package/dist/services/config/testUtils.d.ts +81 -0
  44. package/dist/services/config/testUtils.js +351 -0
  45. package/dist/services/sessionManager.autoApproval.test.js +5 -5
  46. package/dist/services/sessionManager.d.ts +1 -1
  47. package/dist/services/sessionManager.effect.test.js +27 -18
  48. package/dist/services/sessionManager.js +26 -44
  49. package/dist/services/sessionManager.statePersistence.test.js +5 -4
  50. package/dist/services/sessionManager.test.js +91 -50
  51. package/dist/services/shortcutManager.d.ts +0 -1
  52. package/dist/services/shortcutManager.js +5 -16
  53. package/dist/services/shortcutManager.test.js +2 -2
  54. package/dist/services/stateDetector/base.d.ts +1 -1
  55. package/dist/services/stateDetector/claude.d.ts +1 -1
  56. package/dist/services/stateDetector/claude.js +11 -4
  57. package/dist/services/stateDetector/claude.test.js +47 -24
  58. package/dist/services/stateDetector/cline.d.ts +1 -1
  59. package/dist/services/stateDetector/cline.js +1 -1
  60. package/dist/services/stateDetector/codex.d.ts +1 -1
  61. package/dist/services/stateDetector/codex.js +1 -1
  62. package/dist/services/stateDetector/cursor.d.ts +1 -1
  63. package/dist/services/stateDetector/cursor.js +1 -1
  64. package/dist/services/stateDetector/gemini.d.ts +1 -1
  65. package/dist/services/stateDetector/gemini.js +1 -1
  66. package/dist/services/stateDetector/github-copilot.d.ts +1 -1
  67. package/dist/services/stateDetector/github-copilot.js +1 -1
  68. package/dist/services/stateDetector/opencode.d.ts +1 -1
  69. package/dist/services/stateDetector/opencode.js +1 -1
  70. package/dist/services/stateDetector/types.d.ts +1 -1
  71. package/dist/services/worktreeService.d.ts +12 -0
  72. package/dist/services/worktreeService.js +24 -4
  73. package/dist/services/worktreeService.sort.test.js +105 -109
  74. package/dist/services/worktreeService.test.js +5 -5
  75. package/dist/types/index.d.ts +41 -7
  76. package/dist/utils/gitUtils.d.ts +8 -0
  77. package/dist/utils/gitUtils.js +32 -0
  78. package/dist/utils/hookExecutor.js +2 -2
  79. package/dist/utils/hookExecutor.test.js +8 -12
  80. package/dist/utils/mutex.d.ts +1 -1
  81. package/dist/utils/mutex.js +1 -1
  82. package/dist/utils/worktreeUtils.js +1 -1
  83. package/dist/utils/worktreeUtils.test.js +0 -1
  84. package/package.json +7 -7
  85. package/dist/services/configurationManager.d.ts +0 -121
  86. package/dist/services/configurationManager.js +0 -597
  87. /package/dist/services/{configurationManager.effect.test.d.ts → config/configEditor.effect.test.d.ts} +0 -0
  88. /package/dist/services/{configurationManager.selectPresetOnStart.test.d.ts → config/configEditor.selectPresetOnStart.test.d.ts} +0 -0
  89. /package/dist/services/{configurationManager.test.d.ts → config/configEditor.test.d.ts} +0 -0
@@ -3,16 +3,17 @@ import { EventEmitter } from 'events';
3
3
  import pkg from '@xterm/headless';
4
4
  import { exec } from 'child_process';
5
5
  import { promisify } from 'util';
6
- import { configurationManager } from './configurationManager.js';
6
+ import { configReader } from './config/configReader.js';
7
+ import { setWorktreeLastOpened } from './worktreeService.js';
7
8
  import { executeStatusHook } from '../utils/hookExecutor.js';
8
9
  import { createStateDetector } from './stateDetector/index.js';
9
10
  import { STATE_PERSISTENCE_DURATION_MS, STATE_CHECK_INTERVAL_MS, } from '../constants/statePersistence.js';
10
- import { Effect } from 'effect';
11
+ import { Effect, Either } from 'effect';
11
12
  import { ProcessError, ConfigError } from '../types/errors.js';
12
13
  import { autoApprovalVerifier } from './autoApprovalVerifier.js';
13
14
  import { logger } from '../utils/logger.js';
14
15
  import { Mutex, createInitialSessionStateData } from '../utils/mutex.js';
15
- import { STATUS_TAGS } from '../constants/statusIcons.js';
16
+ import { getBackgroundTaskTag } from '../constants/statusIcons.js';
16
17
  import { getTerminalScreenContent } from '../utils/screenCapture.js';
17
18
  const { Terminal } = pkg;
18
19
  const execAsync = promisify(exec);
@@ -33,7 +34,7 @@ export class SessionManager extends EventEmitter {
33
34
  const detectedState = session.stateDetector.detectState(session.terminal, stateData.state);
34
35
  // If auto-approval is enabled and state is waiting_input, convert to pending_auto_approval
35
36
  if (detectedState === 'waiting_input' &&
36
- configurationManager.isAutoApprovalEnabled() &&
37
+ configReader.isAutoApprovalEnabled() &&
37
38
  !stateData.autoApprovalFailed) {
38
39
  return 'pending_auto_approval';
39
40
  }
@@ -188,7 +189,7 @@ export class SessionManager extends EventEmitter {
188
189
  logLevel: 'off',
189
190
  });
190
191
  }
191
- async createSessionInternal(worktreePath, ptyProcess, commandConfig, options = {}) {
192
+ async createSessionInternal(worktreePath, ptyProcess, options = {}) {
192
193
  const id = this.createSessionId();
193
194
  const terminal = this.createTerminal();
194
195
  const detectionStrategy = options.detectionStrategy ?? 'claude';
@@ -204,7 +205,6 @@ export class SessionManager extends EventEmitter {
204
205
  terminal,
205
206
  stateCheckInterval: undefined, // Will be set in setupBackgroundHandler
206
207
  isPrimaryCommand: options.isPrimaryCommand ?? true,
207
- commandConfig,
208
208
  detectionStrategy,
209
209
  devcontainerConfig: options.devcontainerConfig ?? undefined,
210
210
  stateMutex: new Mutex(createInitialSessionStateData()),
@@ -214,7 +214,7 @@ export class SessionManager extends EventEmitter {
214
214
  this.setupBackgroundHandler(session);
215
215
  this.sessions.set(worktreePath, session);
216
216
  // Record the timestamp when this worktree was opened
217
- configurationManager.setWorktreeLastOpened(worktreePath, Date.now());
217
+ setWorktreeLastOpened(worktreePath, Date.now());
218
218
  this.emit('sessionCreated', session);
219
219
  return session;
220
220
  }
@@ -244,12 +244,12 @@ export class SessionManager extends EventEmitter {
244
244
  if (existing) {
245
245
  return existing;
246
246
  }
247
- // Get preset configuration
247
+ // Get preset configuration using Either-based lookup
248
248
  let preset = presetId
249
- ? configurationManager.getPresetById(presetId)
249
+ ? Either.getOrElse(configReader.getPresetByIdEffect(presetId), () => null)
250
250
  : null;
251
251
  if (!preset) {
252
- preset = configurationManager.getDefaultPreset();
252
+ preset = configReader.getDefaultPreset();
253
253
  }
254
254
  // Validate preset exists
255
255
  if (!preset) {
@@ -263,14 +263,9 @@ export class SessionManager extends EventEmitter {
263
263
  }
264
264
  const command = preset.command;
265
265
  const args = preset.args || [];
266
- const commandConfig = {
267
- command: preset.command,
268
- args: preset.args,
269
- fallbackArgs: preset.fallbackArgs,
270
- };
271
266
  // Spawn the process - fallback will be handled by setupExitHandler
272
267
  const ptyProcess = await this.spawn(command, args, worktreePath);
273
- return this.createSessionInternal(worktreePath, ptyProcess, commandConfig, {
268
+ return this.createSessionInternal(worktreePath, ptyProcess, {
274
269
  isPrimaryCommand: true,
275
270
  detectionStrategy: preset.detectionStrategy,
276
271
  });
@@ -329,8 +324,6 @@ export class SessionManager extends EventEmitter {
329
324
  if (e.exitCode === 1 && !e.signal && session.isPrimaryCommand) {
330
325
  try {
331
326
  let fallbackProcess;
332
- // Use fallback args if available, otherwise use empty args
333
- const fallbackArgs = session.commandConfig?.fallbackArgs || [];
334
327
  // Check if we're in a devcontainer session
335
328
  if (session.devcontainerConfig) {
336
329
  // Parse the exec command to extract arguments
@@ -338,17 +331,12 @@ export class SessionManager extends EventEmitter {
338
331
  const devcontainerCmd = execParts[0] || 'devcontainer';
339
332
  const execArgs = execParts.slice(1);
340
333
  // Build fallback command for devcontainer
341
- const fallbackFullArgs = [
342
- ...execArgs,
343
- '--',
344
- session.commandConfig?.command || 'claude',
345
- ...fallbackArgs,
346
- ];
334
+ const fallbackFullArgs = [...execArgs, '--', 'claude'];
347
335
  fallbackProcess = await this.spawn(devcontainerCmd, fallbackFullArgs, session.worktreePath);
348
336
  }
349
337
  else {
350
338
  // Regular fallback without devcontainer
351
- fallbackProcess = await this.spawn(session.commandConfig?.command || 'claude', fallbackArgs, session.worktreePath);
339
+ fallbackProcess = await this.spawn('claude', [], session.worktreePath);
352
340
  }
353
341
  // Replace the process
354
342
  session.process = fallbackProcess;
@@ -430,12 +418,12 @@ export class SessionManager extends EventEmitter {
430
418
  !currentStateData.autoApprovalAbortController) {
431
419
  this.handleAutoApproval(session);
432
420
  }
433
- // Detect and update background task flag
434
- const hasBackgroundTask = this.detectBackgroundTask(session);
435
- if (currentStateData.hasBackgroundTask !== hasBackgroundTask) {
421
+ // Detect and update background task count
422
+ const backgroundTaskCount = this.detectBackgroundTask(session);
423
+ if (currentStateData.backgroundTaskCount !== backgroundTaskCount) {
436
424
  void session.stateMutex.update(data => ({
437
425
  ...data,
438
- hasBackgroundTask,
426
+ backgroundTaskCount,
439
427
  }));
440
428
  }
441
429
  }, STATE_CHECK_INTERVAL_MS);
@@ -466,7 +454,7 @@ export class SessionManager extends EventEmitter {
466
454
  session.isActive = active;
467
455
  // If becoming active, record the timestamp when this worktree was opened
468
456
  if (active) {
469
- configurationManager.setWorktreeLastOpened(worktreePath, Date.now());
457
+ setWorktreeLastOpened(worktreePath, Date.now());
470
458
  // Emit a restore event with the output history if available
471
459
  if (session.outputHistory.length > 0) {
472
460
  this.emit('sessionRestore', session);
@@ -620,12 +608,12 @@ export class SessionManager extends EventEmitter {
620
608
  message: `Failed to start devcontainer: ${error instanceof Error ? error.message : String(error)}`,
621
609
  });
622
610
  }
623
- // Get preset configuration
611
+ // Get preset configuration using Either-based lookup
624
612
  let preset = presetId
625
- ? configurationManager.getPresetById(presetId)
613
+ ? Either.getOrElse(configReader.getPresetByIdEffect(presetId), () => null)
626
614
  : null;
627
615
  if (!preset) {
628
- preset = configurationManager.getDefaultPreset();
616
+ preset = configReader.getDefaultPreset();
629
617
  }
630
618
  // Validate preset exists
631
619
  if (!preset) {
@@ -650,12 +638,7 @@ export class SessionManager extends EventEmitter {
650
638
  ];
651
639
  // Spawn the process within devcontainer
652
640
  const ptyProcess = await this.spawn(devcontainerCmd, fullArgs, worktreePath);
653
- const commandConfig = {
654
- command: preset.command,
655
- args: preset.args,
656
- fallbackArgs: preset.fallbackArgs,
657
- };
658
- return this.createSessionInternal(worktreePath, ptyProcess, commandConfig, {
641
+ return this.createSessionInternal(worktreePath, ptyProcess, {
659
642
  isPrimaryCommand: true,
660
643
  detectionStrategy: preset.detectionStrategy,
661
644
  devcontainerConfig,
@@ -707,9 +690,7 @@ export class SessionManager extends EventEmitter {
707
690
  counts.pending_auto_approval++;
708
691
  break;
709
692
  }
710
- if (stateData.hasBackgroundTask) {
711
- counts.backgroundTasks++;
712
- }
693
+ counts.backgroundTasks += stateData.backgroundTaskCount;
713
694
  });
714
695
  return counts;
715
696
  }
@@ -730,7 +711,8 @@ export class SessionManager extends EventEmitter {
730
711
  if (parts.length === 0) {
731
712
  return '';
732
713
  }
733
- const bgTag = counts.backgroundTasks > 0 ? ` ${STATUS_TAGS.BACKGROUND_TASK}` : '';
734
- return ` (${parts.join(' / ')}${bgTag})`;
714
+ const bgTag = getBackgroundTaskTag(counts.backgroundTasks);
715
+ const bgSuffix = bgTag ? ` ${bgTag}` : '';
716
+ return ` (${parts.join(' / ')}${bgSuffix})`;
735
717
  }
736
718
  }
@@ -1,4 +1,5 @@
1
1
  import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
2
+ import { Either } from 'effect';
2
3
  import { SessionManager } from './sessionManager.js';
3
4
  import { spawn } from './bunTerminal.js';
4
5
  import { EventEmitter } from 'events';
@@ -8,8 +9,8 @@ vi.mock('./bunTerminal.js', () => ({
8
9
  return null;
9
10
  }),
10
11
  }));
11
- vi.mock('./configurationManager.js', () => ({
12
- configurationManager: {
12
+ vi.mock('./config/configReader.js', () => ({
13
+ configReader: {
13
14
  getConfig: vi.fn().mockReturnValue({
14
15
  commands: [
15
16
  {
@@ -21,12 +22,12 @@ vi.mock('./configurationManager.js', () => ({
21
22
  ],
22
23
  defaultCommandId: 'test',
23
24
  }),
24
- getPresetById: vi.fn().mockReturnValue({
25
+ getPresetByIdEffect: vi.fn().mockReturnValue(Either.right({
25
26
  id: 'test',
26
27
  name: 'Test',
27
28
  command: 'test',
28
29
  args: [],
29
- }),
30
+ })),
30
31
  getDefaultPreset: vi.fn().mockReturnValue({
31
32
  id: 'test',
32
33
  name: 'Test',
@@ -1,5 +1,6 @@
1
1
  import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
2
- import { Effect } from 'effect';
2
+ import { Effect, Either } from 'effect';
3
+ import { ValidationError } from '../types/errors.js';
3
4
  import { spawn } from './bunTerminal.js';
4
5
  import { EventEmitter } from 'events';
5
6
  import { exec } from 'child_process';
@@ -19,12 +20,11 @@ vi.mock('child_process', () => ({
19
20
  }),
20
21
  }));
21
22
  // Mock configuration manager
22
- vi.mock('./configurationManager.js', () => ({
23
- configurationManager: {
24
- getCommandConfig: vi.fn(),
23
+ vi.mock('./config/configReader.js', () => ({
24
+ configReader: {
25
25
  getStatusHooks: vi.fn(() => ({})),
26
26
  getDefaultPreset: vi.fn(),
27
- getPresetById: vi.fn(),
27
+ getPresetByIdEffect: vi.fn(),
28
28
  setWorktreeLastOpened: vi.fn(),
29
29
  getWorktreeLastOpenedTime: vi.fn(),
30
30
  getWorktreeLastOpened: vi.fn(() => ({})),
@@ -57,6 +57,9 @@ vi.mock('./worktreeService.js', () => ({
57
57
  WorktreeService: vi.fn(function () {
58
58
  return {};
59
59
  }),
60
+ setWorktreeLastOpened: vi.fn(),
61
+ getWorktreeLastOpened: vi.fn(() => ({})),
62
+ getWorktreeLastOpenedTime: vi.fn(),
60
63
  }));
61
64
  // Create a mock IPty class
62
65
  class MockPty extends EventEmitter {
@@ -102,14 +105,14 @@ describe('SessionManager', () => {
102
105
  let sessionManager;
103
106
  let mockPty;
104
107
  let SessionManager;
105
- let configurationManager;
108
+ let configReader;
106
109
  beforeEach(async () => {
107
110
  vi.clearAllMocks();
108
111
  // Dynamically import after mocks are set up
109
112
  const sessionManagerModule = await import('./sessionManager.js');
110
- const configManagerModule = await import('./configurationManager.js');
113
+ const configManagerModule = await import('./config/configReader.js');
111
114
  SessionManager = sessionManagerModule.SessionManager;
112
- configurationManager = configManagerModule.configurationManager;
115
+ configReader = configManagerModule.configReader;
113
116
  sessionManager = new SessionManager();
114
117
  mockPty = new MockPty();
115
118
  });
@@ -119,7 +122,7 @@ describe('SessionManager', () => {
119
122
  describe('createSessionWithPresetEffect', () => {
120
123
  it('should use default preset when no preset ID specified', async () => {
121
124
  // Setup mock preset
122
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
125
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
123
126
  id: '1',
124
127
  name: 'Main',
125
128
  command: 'claude',
@@ -140,19 +143,19 @@ describe('SessionManager', () => {
140
143
  });
141
144
  it('should use specific preset when ID provided', async () => {
142
145
  // Setup mock preset
143
- vi.mocked(configurationManager.getPresetById).mockReturnValue({
146
+ vi.mocked(configReader.getPresetByIdEffect).mockReturnValue(Either.right({
144
147
  id: '2',
145
148
  name: 'Development',
146
149
  command: 'claude',
147
150
  args: ['--resume', '--dev'],
148
151
  fallbackArgs: ['--no-mcp'],
149
- });
152
+ }));
150
153
  // Setup spawn mock
151
154
  vi.mocked(spawn).mockReturnValue(mockPty);
152
155
  // Create session with specific preset
153
156
  await Effect.runPromise(sessionManager.createSessionWithPresetEffect('/test/worktree', '2'));
154
- // Verify getPresetById was called with correct ID
155
- expect(configurationManager.getPresetById).toHaveBeenCalledWith('2');
157
+ // Verify getPresetByIdEffect was called with correct ID
158
+ expect(configReader.getPresetByIdEffect).toHaveBeenCalledWith('2');
156
159
  // Verify spawn was called with preset config
157
160
  expect(spawn).toHaveBeenCalledWith('claude', ['--resume', '--dev'], {
158
161
  name: 'xterm-256color',
@@ -164,8 +167,12 @@ describe('SessionManager', () => {
164
167
  });
165
168
  it('should fall back to default preset if specified preset not found', async () => {
166
169
  // Setup mocks
167
- vi.mocked(configurationManager.getPresetById).mockReturnValue(undefined);
168
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
170
+ vi.mocked(configReader.getPresetByIdEffect).mockReturnValue(Either.left(new ValidationError({
171
+ field: 'presetId',
172
+ constraint: 'Preset not found',
173
+ receivedValue: 'invalid',
174
+ })));
175
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
169
176
  id: '1',
170
177
  name: 'Main',
171
178
  command: 'claude',
@@ -175,12 +182,12 @@ describe('SessionManager', () => {
175
182
  // Create session with non-existent preset
176
183
  await Effect.runPromise(sessionManager.createSessionWithPresetEffect('/test/worktree', 'invalid'));
177
184
  // Verify fallback to default preset
178
- expect(configurationManager.getDefaultPreset).toHaveBeenCalled();
185
+ expect(configReader.getDefaultPreset).toHaveBeenCalled();
179
186
  expect(spawn).toHaveBeenCalledWith('claude', [], expect.any(Object));
180
187
  });
181
188
  it('should throw error when spawn fails with preset', async () => {
182
189
  // Setup mock preset with fallback
183
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
190
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
184
191
  id: '1',
185
192
  name: 'Main',
186
193
  command: 'claude',
@@ -199,7 +206,7 @@ describe('SessionManager', () => {
199
206
  });
200
207
  it('should return existing session if already created', async () => {
201
208
  // Setup mock preset
202
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
209
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
203
210
  id: '1',
204
211
  name: 'Main',
205
212
  command: 'claude',
@@ -216,7 +223,7 @@ describe('SessionManager', () => {
216
223
  });
217
224
  it('should throw error when spawn fails with fallback args', async () => {
218
225
  // Setup mock preset with fallback
219
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
226
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
220
227
  id: '1',
221
228
  name: 'Main',
222
229
  command: 'nonexistent-command',
@@ -230,14 +237,13 @@ describe('SessionManager', () => {
230
237
  // Expect createSessionWithPresetEffect to throw the original error
231
238
  await expect(Effect.runPromise(sessionManager.createSessionWithPresetEffect('/test/worktree'))).rejects.toThrow('Command not found');
232
239
  });
233
- it('should use fallback args when main command exits with code 1', async () => {
234
- // Setup mock preset with fallback
235
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
240
+ it('should fallback to default command when main command exits with code 1', async () => {
241
+ // Setup mock preset with args
242
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
236
243
  id: '1',
237
244
  name: 'Main',
238
245
  command: 'claude',
239
246
  args: ['--invalid-flag'],
240
- fallbackArgs: ['--resume'],
241
247
  });
242
248
  // First spawn attempt - will exit with code 1
243
249
  const firstMockPty = new MockPty();
@@ -255,16 +261,16 @@ describe('SessionManager', () => {
255
261
  firstMockPty.emit('exit', { exitCode: 1 });
256
262
  // Wait for fallback to occur
257
263
  await new Promise(resolve => setTimeout(resolve, 50));
258
- // Verify fallback spawn was called
264
+ // Verify fallback spawn was called (with no args since commandConfig was removed)
259
265
  expect(spawn).toHaveBeenCalledTimes(2);
260
- expect(spawn).toHaveBeenNthCalledWith(2, 'claude', ['--resume'], expect.objectContaining({ cwd: '/test/worktree' }));
266
+ expect(spawn).toHaveBeenNthCalledWith(2, 'claude', [], expect.objectContaining({ cwd: '/test/worktree' }));
261
267
  // Verify session process was replaced
262
268
  expect(session.process).toBe(secondMockPty);
263
269
  expect(session.isPrimaryCommand).toBe(false);
264
270
  });
265
271
  it('should not use fallback if main command succeeds', async () => {
266
272
  // Setup mock preset with fallback
267
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
273
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
268
274
  id: '1',
269
275
  name: 'Main',
270
276
  command: 'claude',
@@ -283,7 +289,7 @@ describe('SessionManager', () => {
283
289
  });
284
290
  it('should use empty args as fallback when no fallback args specified', async () => {
285
291
  // Setup mock preset without fallback args
286
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
292
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
287
293
  id: '1',
288
294
  name: 'Main',
289
295
  command: 'claude',
@@ -316,7 +322,7 @@ describe('SessionManager', () => {
316
322
  });
317
323
  it('should handle custom command configuration', async () => {
318
324
  // Setup mock preset with custom command
319
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
325
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
320
326
  id: '1',
321
327
  name: 'Main',
322
328
  command: 'my-custom-claude',
@@ -333,7 +339,7 @@ describe('SessionManager', () => {
333
339
  });
334
340
  it('should throw error when spawn fails and no fallback configured', async () => {
335
341
  // Setup mock preset without fallback
336
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
342
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
337
343
  id: '1',
338
344
  name: 'Main',
339
345
  command: 'claude',
@@ -350,7 +356,7 @@ describe('SessionManager', () => {
350
356
  describe('session lifecycle', () => {
351
357
  it('should destroy session and clean up resources', async () => {
352
358
  // Setup
353
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
359
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
354
360
  id: '1',
355
361
  name: 'Main',
356
362
  command: 'claude',
@@ -365,7 +371,7 @@ describe('SessionManager', () => {
365
371
  });
366
372
  it('should handle session exit event', async () => {
367
373
  // Setup
368
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
374
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
369
375
  id: '1',
370
376
  name: 'Main',
371
377
  command: 'claude',
@@ -411,7 +417,7 @@ describe('SessionManager', () => {
411
417
  });
412
418
  it('should execute devcontainer up command before creating session', async () => {
413
419
  // Setup mock preset
414
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
420
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
415
421
  id: '1',
416
422
  name: 'Main',
417
423
  command: 'claude',
@@ -431,12 +437,12 @@ describe('SessionManager', () => {
431
437
  });
432
438
  it('should use specific preset when ID provided', async () => {
433
439
  // Setup mock preset
434
- vi.mocked(configurationManager.getPresetById).mockReturnValue({
440
+ vi.mocked(configReader.getPresetByIdEffect).mockReturnValue(Either.right({
435
441
  id: '2',
436
442
  name: 'Development',
437
443
  command: 'claude',
438
444
  args: ['--resume', '--dev'],
439
- });
445
+ }));
440
446
  // Setup spawn mock
441
447
  vi.mocked(spawn).mockReturnValue(mockPty);
442
448
  // Create session with devcontainer and specific preset
@@ -446,7 +452,7 @@ describe('SessionManager', () => {
446
452
  };
447
453
  await Effect.runPromise(sessionManager.createSessionWithDevcontainerEffect('/test/worktree', devcontainerConfig, '2'));
448
454
  // Verify correct preset was used
449
- expect(configurationManager.getPresetById).toHaveBeenCalledWith('2');
455
+ expect(configReader.getPresetByIdEffect).toHaveBeenCalledWith('2');
450
456
  expect(spawn).toHaveBeenCalledWith('devcontainer', ['exec', '--', 'claude', '--resume', '--dev'], expect.any(Object));
451
457
  });
452
458
  it('should throw error when devcontainer up fails', async () => {
@@ -462,7 +468,7 @@ describe('SessionManager', () => {
462
468
  });
463
469
  it('should return existing session if already created', async () => {
464
470
  // Setup mock preset
465
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
471
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
466
472
  id: '1',
467
473
  name: 'Main',
468
474
  command: 'claude',
@@ -483,7 +489,7 @@ describe('SessionManager', () => {
483
489
  });
484
490
  it('should handle complex exec commands with multiple arguments', async () => {
485
491
  // Setup mock preset
486
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
492
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
487
493
  id: '1',
488
494
  name: 'Main',
489
495
  command: 'claude',
@@ -514,7 +520,7 @@ describe('SessionManager', () => {
514
520
  // Create a new session manager and reset mocks
515
521
  vi.clearAllMocks();
516
522
  sessionManager = new SessionManager();
517
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
523
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
518
524
  id: '1',
519
525
  name: 'Main',
520
526
  command: 'claude',
@@ -605,12 +611,12 @@ describe('SessionManager', () => {
605
611
  }
606
612
  return {};
607
613
  });
608
- vi.mocked(configurationManager.getPresetById).mockReturnValue({
614
+ vi.mocked(configReader.getPresetByIdEffect).mockReturnValue(Either.right({
609
615
  id: 'claude-with-args',
610
616
  name: 'Claude with Args',
611
617
  command: 'claude',
612
618
  args: ['-m', 'claude-3-opus'],
613
- });
619
+ }));
614
620
  await Effect.runPromise(sessionManager.createSessionWithDevcontainerEffect('/test/worktree', {
615
621
  upCommand: 'devcontainer up --workspace-folder .',
616
622
  execCommand: 'devcontainer exec --workspace-folder .',
@@ -638,7 +644,7 @@ describe('SessionManager', () => {
638
644
  return {};
639
645
  });
640
646
  // Setup preset without fallback args
641
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
647
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
642
648
  id: '1',
643
649
  name: 'Main',
644
650
  command: 'claude',
@@ -671,7 +677,7 @@ describe('SessionManager', () => {
671
677
  expect(session.process).toBe(secondMockPty);
672
678
  expect(session.isPrimaryCommand).toBe(false);
673
679
  });
674
- it('should use fallback args in devcontainer when primary command exits with code 1', async () => {
680
+ it('should fallback to default command in devcontainer when primary command exits with code 1', async () => {
675
681
  const mockExec = vi.mocked(exec);
676
682
  mockExec.mockImplementation((cmd, options, callback) => {
677
683
  if (typeof options === 'function') {
@@ -683,13 +689,12 @@ describe('SessionManager', () => {
683
689
  }
684
690
  return {};
685
691
  });
686
- // Setup preset with fallback
687
- vi.mocked(configurationManager.getDefaultPreset).mockReturnValue({
692
+ // Setup preset with args
693
+ vi.mocked(configReader.getDefaultPreset).mockReturnValue({
688
694
  id: '1',
689
695
  name: 'Main',
690
696
  command: 'claude',
691
697
  args: ['--bad-flag'],
692
- fallbackArgs: ['--good-flag'],
693
698
  });
694
699
  // First spawn attempt - will exit with code 1
695
700
  const firstMockPty = new MockPty();
@@ -709,9 +714,9 @@ describe('SessionManager', () => {
709
714
  firstMockPty.emit('exit', { exitCode: 1 });
710
715
  // Wait for fallback to occur
711
716
  await new Promise(resolve => setTimeout(resolve, 50));
712
- // Verify fallback spawn was called
717
+ // Verify fallback spawn was called (with no args since commandConfig was removed)
713
718
  expect(spawn).toHaveBeenCalledTimes(2);
714
- expect(spawn).toHaveBeenNthCalledWith(2, 'devcontainer', ['exec', '--workspace-folder', '.', '--', 'claude', '--good-flag'], expect.objectContaining({ cwd: '/test/worktree' }));
719
+ expect(spawn).toHaveBeenNthCalledWith(2, 'devcontainer', ['exec', '--workspace-folder', '.', '--', 'claude'], expect.objectContaining({ cwd: '/test/worktree' }));
715
720
  // Verify session process was replaced
716
721
  expect(session.process).toBe(secondMockPty);
717
722
  expect(session.isPrimaryCommand).toBe(false);
@@ -720,10 +725,10 @@ describe('SessionManager', () => {
720
725
  describe('static methods', () => {
721
726
  describe('getSessionCounts', () => {
722
727
  // Helper to create mock session with stateMutex
723
- const createMockSession = (id, state, hasBackgroundTask = false) => ({
728
+ const createMockSession = (id, state, backgroundTaskCount = 0) => ({
724
729
  id,
725
730
  stateMutex: {
726
- getSnapshot: () => ({ state, hasBackgroundTask }),
731
+ getSnapshot: () => ({ state, backgroundTaskCount }),
727
732
  },
728
733
  });
729
734
  it('should count sessions by state', () => {
@@ -759,6 +764,16 @@ describe('SessionManager', () => {
759
764
  expect(counts.waiting_input).toBe(0);
760
765
  expect(counts.total).toBe(3);
761
766
  });
767
+ it('should sum background task counts across sessions', () => {
768
+ const sessions = [
769
+ createMockSession('1', 'idle', 0),
770
+ createMockSession('2', 'busy', 2),
771
+ createMockSession('3', 'busy', 3),
772
+ createMockSession('4', 'waiting_input', 1),
773
+ ];
774
+ const counts = SessionManager.getSessionCounts(sessions);
775
+ expect(counts.backgroundTasks).toBe(6);
776
+ });
762
777
  });
763
778
  describe('formatSessionCounts', () => {
764
779
  it('should format counts with all states', () => {
@@ -809,7 +824,7 @@ describe('SessionManager', () => {
809
824
  const formatted = SessionManager.formatSessionCounts(counts);
810
825
  expect(formatted).toBe('');
811
826
  });
812
- it('should append [BG] tag when background tasks exist', () => {
827
+ it('should append [BG] tag when backgroundTasks is 1', () => {
813
828
  const counts = {
814
829
  idle: 1,
815
830
  busy: 1,
@@ -822,6 +837,32 @@ describe('SessionManager', () => {
822
837
  expect(formatted).toContain('[BG]');
823
838
  expect(formatted).toBe(' (1 Idle / 1 Busy \x1b[2m[BG]\x1b[0m)');
824
839
  });
840
+ it('should append [BG:N] tag when backgroundTasks is 2+', () => {
841
+ const counts = {
842
+ idle: 1,
843
+ busy: 1,
844
+ waiting_input: 0,
845
+ pending_auto_approval: 0,
846
+ total: 2,
847
+ backgroundTasks: 5,
848
+ };
849
+ const formatted = SessionManager.formatSessionCounts(counts);
850
+ expect(formatted).toContain('[BG:5]');
851
+ expect(formatted).toBe(' (1 Idle / 1 Busy \x1b[2m[BG:5]\x1b[0m)');
852
+ });
853
+ it('should not append BG tag when backgroundTasks is 0', () => {
854
+ const counts = {
855
+ idle: 1,
856
+ busy: 1,
857
+ waiting_input: 0,
858
+ pending_auto_approval: 0,
859
+ total: 2,
860
+ backgroundTasks: 0,
861
+ };
862
+ const formatted = SessionManager.formatSessionCounts(counts);
863
+ expect(formatted).not.toContain('[BG');
864
+ expect(formatted).toBe(' (1 Idle / 1 Busy)');
865
+ });
825
866
  });
826
867
  });
827
868
  });
@@ -5,7 +5,6 @@ export declare class ShortcutManager {
5
5
  constructor();
6
6
  private validateShortcut;
7
7
  private isReservedKey;
8
- saveShortcuts(shortcuts: ShortcutConfig): boolean;
9
8
  getShortcuts(): ShortcutConfig;
10
9
  private getRawShortcutCodes;
11
10
  matchesShortcut(shortcutName: keyof ShortcutConfig, input: string, key: Key): boolean;