agileflow 2.94.1 → 2.95.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 (74) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +3 -3
  3. package/lib/colors.generated.js +117 -0
  4. package/lib/colors.js +59 -109
  5. package/lib/generator-factory.js +333 -0
  6. package/lib/path-utils.js +49 -0
  7. package/lib/session-registry.js +25 -15
  8. package/lib/smart-json-file.js +40 -32
  9. package/lib/state-machine.js +286 -0
  10. package/package.json +1 -1
  11. package/scripts/agileflow-configure.js +7 -6
  12. package/scripts/archive-completed-stories.sh +86 -11
  13. package/scripts/babysit-context-restore.js +89 -0
  14. package/scripts/claude-tmux.sh +111 -5
  15. package/scripts/damage-control/bash-tool-damage-control.js +11 -247
  16. package/scripts/damage-control/edit-tool-damage-control.js +9 -249
  17. package/scripts/damage-control/write-tool-damage-control.js +9 -244
  18. package/scripts/generate-colors.js +314 -0
  19. package/scripts/lib/colors.generated.sh +82 -0
  20. package/scripts/lib/colors.sh +10 -70
  21. package/scripts/lib/configure-features.js +401 -0
  22. package/scripts/lib/context-loader.js +181 -52
  23. package/scripts/precompact-context.sh +54 -17
  24. package/scripts/session-coordinator.sh +2 -2
  25. package/scripts/session-manager.js +653 -10
  26. package/src/core/commands/audit.md +93 -0
  27. package/src/core/commands/auto.md +73 -0
  28. package/src/core/commands/babysit.md +169 -13
  29. package/src/core/commands/baseline.md +73 -0
  30. package/src/core/commands/batch.md +64 -0
  31. package/src/core/commands/blockers.md +60 -0
  32. package/src/core/commands/board.md +66 -0
  33. package/src/core/commands/choose.md +77 -0
  34. package/src/core/commands/ci.md +77 -0
  35. package/src/core/commands/compress.md +27 -1
  36. package/src/core/commands/configure.md +126 -10
  37. package/src/core/commands/council.md +74 -0
  38. package/src/core/commands/debt.md +72 -0
  39. package/src/core/commands/deploy.md +73 -0
  40. package/src/core/commands/deps.md +68 -0
  41. package/src/core/commands/docs.md +60 -0
  42. package/src/core/commands/feedback.md +68 -0
  43. package/src/core/commands/ideate.md +74 -0
  44. package/src/core/commands/impact.md +74 -0
  45. package/src/core/commands/install.md +529 -0
  46. package/src/core/commands/maintain.md +558 -0
  47. package/src/core/commands/metrics.md +75 -0
  48. package/src/core/commands/multi-expert.md +74 -0
  49. package/src/core/commands/packages.md +69 -0
  50. package/src/core/commands/readme-sync.md +64 -0
  51. package/src/core/commands/research/analyze.md +285 -121
  52. package/src/core/commands/research/import.md +281 -109
  53. package/src/core/commands/retro.md +76 -0
  54. package/src/core/commands/review.md +72 -0
  55. package/src/core/commands/rlm.md +83 -0
  56. package/src/core/commands/rpi.md +90 -0
  57. package/src/core/commands/session/cleanup.md +214 -12
  58. package/src/core/commands/session/end.md +155 -17
  59. package/src/core/commands/sprint.md +72 -0
  60. package/src/core/commands/story-validate.md +68 -0
  61. package/src/core/commands/template.md +69 -0
  62. package/src/core/commands/tests.md +83 -0
  63. package/src/core/commands/update.md +59 -0
  64. package/src/core/commands/validate-expertise.md +76 -0
  65. package/src/core/commands/velocity.md +74 -0
  66. package/src/core/commands/verify.md +91 -0
  67. package/src/core/commands/whats-new.md +69 -0
  68. package/src/core/commands/workflow.md +88 -0
  69. package/src/core/templates/command-documentation.md +187 -0
  70. package/tools/cli/commands/session.js +1171 -0
  71. package/tools/cli/commands/setup.js +2 -81
  72. package/tools/cli/installers/core/installer.js +0 -5
  73. package/tools/cli/installers/ide/claude-code.js +6 -0
  74. package/tools/cli/lib/config-manager.js +42 -5
@@ -0,0 +1,1171 @@
1
+ /**
2
+ * AgileFlow CLI - Session Command
3
+ *
4
+ * Manage parallel Claude Code sessions via CLI.
5
+ * Provides shell-accessible session management without requiring Claude Code.
6
+ */
7
+
8
+ const chalk = require('chalk');
9
+ const path = require('node:path');
10
+ const inquirer = require('inquirer');
11
+ const ora = require('ora');
12
+ const { displayLogo, displaySection, success, warning, error, info } = require('../lib/ui');
13
+ const { ErrorHandler } = require('../lib/error-handler');
14
+
15
+ // Session manager provides all session operations
16
+ const sessionManager = require('../../../scripts/session-manager');
17
+ const { hasTmux, spawnInTmux, buildClaudeCommand } = require('../../../scripts/spawn-parallel');
18
+
19
+ module.exports = {
20
+ name: 'session',
21
+ description: 'Manage parallel Claude Code sessions',
22
+ arguments: [
23
+ ['<subcommand>', 'Subcommand: list, new, switch, end, spawn, status, history'],
24
+ ['[idOrNickname]', 'Session ID or nickname (for switch/end/status)'],
25
+ ],
26
+ options: [
27
+ ['-d, --directory <path>', 'Project directory (default: current directory)'],
28
+ ['-y, --yes', 'Skip prompts, use defaults'],
29
+ ['--json', 'Output as JSON'],
30
+ ['--branch <name>', 'Branch name for new session'],
31
+ ['--nickname <name>', 'Nickname for new session'],
32
+ ['--merge', 'Merge session before ending'],
33
+ ['--strategy <type>', 'Merge strategy: squash|merge (default: squash)'],
34
+ ['--echo-cd', 'Output only the path (for cd $(agileflow session switch <id> --echo-cd))'],
35
+ ['--kanban', 'Show Kanban-style board view (for list)'],
36
+ ['--count <n>', 'Number of sessions to spawn (for spawn)'],
37
+ ['--branches <list>', 'Comma-separated branch names (for spawn)'],
38
+ ['--from-epic <id>', 'Create sessions from ready stories in epic (for spawn)'],
39
+ ['--no-tmux', 'Output commands without spawning in tmux (for spawn)'],
40
+ ['--no-claude', 'Create worktrees but do not start Claude (for spawn)'],
41
+ ['--dangerous', 'Use --dangerously-skip-permissions for Claude (for spawn)'],
42
+ ['--prompt <text>', 'Initial prompt to send to each Claude instance (for spawn)'],
43
+ ['--limit <n>', 'Number of history entries to show (default: 20)'],
44
+ ],
45
+ action: async (subcommand, idOrNickname, options) => {
46
+ const handler = new ErrorHandler('session');
47
+
48
+ try {
49
+ switch (subcommand) {
50
+ case 'list':
51
+ await handleList(options);
52
+ break;
53
+
54
+ case 'new':
55
+ await handleNew(options);
56
+ break;
57
+
58
+ case 'switch':
59
+ await handleSwitch(idOrNickname, options, handler);
60
+ break;
61
+
62
+ case 'end':
63
+ await handleEnd(idOrNickname, options, handler);
64
+ break;
65
+
66
+ case 'spawn':
67
+ await handleSpawn(options, handler);
68
+ break;
69
+
70
+ case 'status':
71
+ await handleStatus(idOrNickname, options, handler);
72
+ break;
73
+
74
+ case 'history':
75
+ await handleHistory(options);
76
+ break;
77
+
78
+ default:
79
+ displayLogo();
80
+ showHelp();
81
+ process.exit(0);
82
+ }
83
+
84
+ process.exit(0);
85
+ } catch (err) {
86
+ handler.critical(
87
+ 'Session operation failed',
88
+ 'Check session manager functionality',
89
+ 'npx agileflow doctor',
90
+ err
91
+ );
92
+ }
93
+ },
94
+ };
95
+
96
+ /**
97
+ * Show help for session subcommands
98
+ */
99
+ function showHelp() {
100
+ console.log(chalk.bold('Usage:\n'));
101
+ console.log(' npx agileflow session list List all sessions');
102
+ console.log(' npx agileflow session new Create a new session (interactive)');
103
+ console.log(' npx agileflow session switch <id> Switch active session context');
104
+ console.log(' npx agileflow session end <id> End session (optional merge)');
105
+ console.log(' npx agileflow session spawn Spawn multiple parallel sessions');
106
+ console.log(' npx agileflow session status <id> Detailed view of a session');
107
+ console.log(' npx agileflow session history View merge history\n');
108
+ console.log(chalk.bold('Options:\n'));
109
+ console.log(' --json Output as JSON');
110
+ console.log(' --kanban Show Kanban-style board view (for list)');
111
+ console.log(' --yes, -y Skip prompts, use defaults');
112
+ console.log(' --branch <name> Branch name for new session');
113
+ console.log(' --nickname <name> Nickname for new session');
114
+ console.log(' --merge Merge session before ending');
115
+ console.log(' --strategy <type> Merge strategy: squash|merge');
116
+ console.log(' --echo-cd Output only path (for shell substitution)\n');
117
+ console.log(chalk.bold('Spawn Options:\n'));
118
+ console.log(' --count <n> Number of sessions to spawn');
119
+ console.log(' --branches <list> Comma-separated branch names');
120
+ console.log(' --from-epic <id> Create sessions from ready stories in epic');
121
+ console.log(' --no-tmux Output commands without spawning in tmux');
122
+ console.log(' --no-claude Create worktrees but do not start Claude');
123
+ console.log(' --dangerous Use --dangerously-skip-permissions');
124
+ console.log(' --prompt <text> Initial prompt for each Claude instance\n');
125
+ console.log(chalk.bold('History Options:\n'));
126
+ console.log(' --limit <n> Number of history entries to show (default: 20)\n');
127
+ console.log(chalk.bold('Examples:\n'));
128
+ console.log(' npx agileflow session list');
129
+ console.log(' npx agileflow session list --json');
130
+ console.log(' npx agileflow session list --kanban');
131
+ console.log(' npx agileflow session new');
132
+ console.log(' npx agileflow session new --branch feat-auth --nickname auth --yes');
133
+ console.log(' npx agileflow session switch 2');
134
+ console.log(' cd $(npx agileflow session switch 2 --echo-cd)');
135
+ console.log(' npx agileflow session end 2');
136
+ console.log(' npx agileflow session end 2 --merge --strategy squash');
137
+ console.log(' npx agileflow session spawn --count 4');
138
+ console.log(' npx agileflow session spawn --branches auth,dashboard,api');
139
+ console.log(' npx agileflow session spawn --from-epic EP-0001');
140
+ console.log(' npx agileflow session spawn --count 2 --no-tmux');
141
+ console.log(' npx agileflow session status 2');
142
+ console.log(' npx agileflow session status auth --json');
143
+ console.log(' npx agileflow session history');
144
+ console.log(' npx agileflow session history --limit 10');
145
+ console.log(' npx agileflow session history --json\n');
146
+ }
147
+
148
+ /**
149
+ * Handle list subcommand - display all sessions
150
+ */
151
+ async function handleList(options) {
152
+ const { sessions, cleaned, cleanedSessions } = sessionManager.getSessions();
153
+
154
+ // JSON output mode
155
+ if (options.json) {
156
+ console.log(
157
+ JSON.stringify(
158
+ {
159
+ sessions,
160
+ cleaned,
161
+ cleanedSessions: cleanedSessions || [],
162
+ },
163
+ null,
164
+ 2
165
+ )
166
+ );
167
+ return;
168
+ }
169
+
170
+ // Kanban view mode
171
+ if (options.kanban) {
172
+ displayLogo();
173
+ console.log(sessionManager.renderKanbanBoard(sessions));
174
+ if (cleaned > 0) {
175
+ console.log(chalk.dim(`\nCleaned ${cleaned} stale lock(s)`));
176
+ }
177
+ return;
178
+ }
179
+
180
+ // Standard table view
181
+ displayLogo();
182
+ displaySection('Sessions', `${sessions.length} session(s) registered`);
183
+
184
+ if (sessions.length === 0) {
185
+ info('No sessions registered.');
186
+ console.log();
187
+ info('Create a new session with:');
188
+ console.log(chalk.cyan(' npx agileflow session new'));
189
+ return;
190
+ }
191
+
192
+ // Display table header
193
+ const cols = {
194
+ id: 4,
195
+ status: 8,
196
+ nickname: 20,
197
+ branch: 25,
198
+ path: 40,
199
+ };
200
+
201
+ console.log(
202
+ chalk.bold(
203
+ `${'ID'.padEnd(cols.id)} ${'Status'.padEnd(cols.status)} ${'Nickname'.padEnd(cols.nickname)} ${'Branch'.padEnd(cols.branch)} Path`
204
+ )
205
+ );
206
+ console.log(chalk.dim('─'.repeat(100)));
207
+
208
+ for (const session of sessions) {
209
+ const statusIcon = session.active ? chalk.green('● active') : chalk.dim('○ idle');
210
+ const currentTag = session.current ? chalk.yellow(' (current)') : '';
211
+ const nickname = session.nickname || chalk.dim('-');
212
+ const mainTag = session.is_main ? chalk.blue(' [main]') : '';
213
+
214
+ console.log(
215
+ `${chalk.cyan(session.id.padEnd(cols.id))} ${statusIcon.padEnd(cols.status + 10)} ${(nickname + mainTag + currentTag).padEnd(cols.nickname + 20)} ${chalk.dim(session.branch.padEnd(cols.branch))} ${chalk.dim(truncatePath(session.path, cols.path))}`
216
+ );
217
+ }
218
+
219
+ console.log(chalk.dim('─'.repeat(100)));
220
+
221
+ // Summary
222
+ const activeCount = sessions.filter(s => s.active).length;
223
+ const parallelCount = sessions.filter(s => !s.is_main).length;
224
+
225
+ console.log();
226
+ console.log(
227
+ chalk.dim(`Active: ${activeCount} │ Parallel: ${parallelCount} │ Total: ${sessions.length}`)
228
+ );
229
+
230
+ if (cleaned > 0) {
231
+ console.log(chalk.dim(`Cleaned ${cleaned} stale lock(s)`));
232
+ }
233
+
234
+ console.log();
235
+ }
236
+
237
+ /**
238
+ * Handle new subcommand - create a new session
239
+ */
240
+ async function handleNew(options) {
241
+ displayLogo();
242
+
243
+ // Check tmux availability early
244
+ const inTmux = hasTmux() && process.env.TMUX;
245
+
246
+ let branchName = options.branch;
247
+ let nickname = options.nickname;
248
+
249
+ // Interactive mode
250
+ if (!options.yes) {
251
+ displaySection('Create New Session');
252
+
253
+ const answers = await inquirer.prompt([
254
+ {
255
+ type: 'input',
256
+ name: 'branch',
257
+ message: 'Branch name:',
258
+ default: options.branch || `session-${Date.now()}`,
259
+ validate: input => {
260
+ if (!/^[a-zA-Z0-9._/-]+$/.test(input)) {
261
+ return 'Branch name can only contain letters, numbers, dots, underscores, hyphens, and forward slashes';
262
+ }
263
+ return true;
264
+ },
265
+ },
266
+ {
267
+ type: 'input',
268
+ name: 'nickname',
269
+ message: 'Nickname (optional, for easy reference):',
270
+ default: options.nickname || '',
271
+ validate: input => {
272
+ if (input && !/^[a-zA-Z0-9_-]+$/.test(input)) {
273
+ return 'Nickname can only contain letters, numbers, underscores, and hyphens';
274
+ }
275
+ return true;
276
+ },
277
+ },
278
+ ]);
279
+
280
+ branchName = answers.branch;
281
+ nickname = answers.nickname || null;
282
+ } else {
283
+ // Non-interactive - use defaults if not provided
284
+ branchName = branchName || `session-${Date.now()}`;
285
+ }
286
+
287
+ // Create the session
288
+ const spinner = ora('Creating session...').start();
289
+
290
+ try {
291
+ const result = await sessionManager.createSession({
292
+ branch: branchName,
293
+ nickname: nickname || undefined,
294
+ });
295
+
296
+ if (!result.success) {
297
+ spinner.fail('Failed to create session');
298
+ error(result.error);
299
+ process.exit(1);
300
+ }
301
+
302
+ spinner.succeed('Session created');
303
+
304
+ // Display result
305
+ console.log();
306
+ success(`Session ${chalk.cyan(result.sessionId)} created successfully`);
307
+ console.log();
308
+ console.log(chalk.bold('Session Details:'));
309
+ console.log(` ${chalk.dim('ID:')} ${chalk.cyan(result.sessionId)}`);
310
+ console.log(` ${chalk.dim('Branch:')} ${result.branch}`);
311
+ if (nickname) {
312
+ console.log(` ${chalk.dim('Nickname:')} ${nickname}`);
313
+ }
314
+ console.log(` ${chalk.dim('Path:')} ${result.path}`);
315
+
316
+ // Show what was copied
317
+ const copied = [...(result.envFilesCopied || []), ...(result.foldersCopied || [])];
318
+ const symlinked = result.foldersSymlinked || [];
319
+ if (copied.length > 0 || symlinked.length > 0) {
320
+ console.log();
321
+ if (copied.length > 0) {
322
+ console.log(chalk.dim(` Copied: ${copied.join(', ')}`));
323
+ }
324
+ if (symlinked.length > 0) {
325
+ console.log(chalk.dim(` Symlinked: ${symlinked.join(', ')}`));
326
+ }
327
+ }
328
+
329
+ // Navigation instructions
330
+ console.log();
331
+ console.log(chalk.bold('Next Steps:'));
332
+ if (inTmux) {
333
+ info('You are in tmux. You can switch windows using Alt+<number>');
334
+ }
335
+ console.log(` ${chalk.cyan(`cd "${result.path}"`)} ${chalk.dim('- Navigate to session')}`);
336
+ console.log(` ${chalk.cyan('claude')} ${chalk.dim('- Start Claude Code in session')}`);
337
+ console.log();
338
+ console.log(chalk.dim('Or use the full command:'));
339
+ console.log(` ${chalk.cyan(result.command)}`);
340
+ console.log();
341
+ } catch (err) {
342
+ spinner.fail('Session creation failed');
343
+ throw err;
344
+ }
345
+ }
346
+
347
+ /**
348
+ * Handle switch subcommand - switch active session context
349
+ */
350
+ async function handleSwitch(idOrNickname, options, handler) {
351
+ if (!idOrNickname) {
352
+ handler.warning(
353
+ 'Session ID or nickname required',
354
+ 'Provide a session identifier',
355
+ 'npx agileflow session switch <id>'
356
+ );
357
+ }
358
+
359
+ const result = sessionManager.switchSession(idOrNickname);
360
+
361
+ if (!result.success) {
362
+ if (options.echoCd) {
363
+ // Silent failure for shell substitution - output nothing
364
+ process.exit(1);
365
+ }
366
+ handler.warning(result.error, 'Check session ID or nickname', 'npx agileflow session list');
367
+ }
368
+
369
+ // Echo-cd mode: just output the path for shell substitution
370
+ if (options.echoCd) {
371
+ console.log(result.path);
372
+ return;
373
+ }
374
+
375
+ // Normal mode: show full output
376
+ displayLogo();
377
+ displaySection('Session Switched');
378
+
379
+ success(`Switched to session ${chalk.cyan(result.session.id)}`);
380
+ console.log();
381
+ console.log(chalk.bold('Session Details:'));
382
+ console.log(` ${chalk.dim('ID:')} ${chalk.cyan(result.session.id)}`);
383
+ if (result.session.nickname) {
384
+ console.log(` ${chalk.dim('Nickname:')} ${result.session.nickname}`);
385
+ }
386
+ console.log(` ${chalk.dim('Branch:')} ${result.session.branch}`);
387
+ console.log(` ${chalk.dim('Path:')} ${result.session.path}`);
388
+ console.log();
389
+
390
+ info('The session context has been updated in session-state.json');
391
+ console.log();
392
+ console.log(chalk.bold('To change directories:'));
393
+ console.log(` ${chalk.cyan(`cd "${result.path}"`)}`);
394
+ console.log();
395
+ console.log(chalk.dim('Tip: Use shell substitution to switch and cd in one command:'));
396
+ console.log(chalk.dim(` cd $(npx agileflow session switch ${idOrNickname} --echo-cd)`));
397
+ console.log();
398
+ }
399
+
400
+ /**
401
+ * Handle end subcommand - end a session (optionally merge)
402
+ */
403
+ async function handleEnd(idOrNickname, options, handler) {
404
+ if (!idOrNickname) {
405
+ handler.warning(
406
+ 'Session ID or nickname required',
407
+ 'Provide a session identifier',
408
+ 'npx agileflow session end <id>'
409
+ );
410
+ }
411
+
412
+ // Get session first to show details
413
+ const session = sessionManager.getSession(idOrNickname);
414
+
415
+ if (!session) {
416
+ handler.warning(
417
+ `Session "${idOrNickname}" not found`,
418
+ 'Check the session ID or nickname',
419
+ 'npx agileflow session list'
420
+ );
421
+ }
422
+
423
+ if (session.is_main) {
424
+ handler.warning(
425
+ 'Cannot end main session',
426
+ 'Only parallel sessions can be ended',
427
+ 'npx agileflow session list'
428
+ );
429
+ }
430
+
431
+ displayLogo();
432
+ displaySection('End Session');
433
+
434
+ console.log(chalk.bold('Session to end:'));
435
+ console.log(` ${chalk.dim('ID:')} ${chalk.cyan(session.id)}`);
436
+ if (session.nickname) {
437
+ console.log(` ${chalk.dim('Nickname:')} ${session.nickname}`);
438
+ }
439
+ console.log(` ${chalk.dim('Branch:')} ${session.branch}`);
440
+ console.log(` ${chalk.dim('Path:')} ${session.path}`);
441
+ console.log();
442
+
443
+ // If merge is requested
444
+ if (options.merge) {
445
+ const spinner = ora('Checking merge status...').start();
446
+
447
+ const mergeCheck = sessionManager.checkMergeability(idOrNickname);
448
+
449
+ if (!mergeCheck.success) {
450
+ spinner.fail('Merge check failed');
451
+ error(mergeCheck.error);
452
+ process.exit(1);
453
+ }
454
+
455
+ if (!mergeCheck.mergeable) {
456
+ spinner.warn('Session is not mergeable');
457
+ console.log();
458
+ warning(`Cannot merge: ${mergeCheck.reason}`);
459
+
460
+ if (mergeCheck.reason === 'uncommitted_changes') {
461
+ console.log();
462
+ info('The session has uncommitted changes:');
463
+ console.log(chalk.dim(mergeCheck.details));
464
+ console.log();
465
+ info('Commit or discard changes before merging');
466
+ } else if (mergeCheck.reason === 'no_changes') {
467
+ console.log();
468
+ info('The branch has no commits ahead of main');
469
+ }
470
+ process.exit(1);
471
+ }
472
+
473
+ spinner.succeed('Session is mergeable');
474
+
475
+ // Show merge preview
476
+ const preview = sessionManager.getMergePreview(idOrNickname);
477
+ if (preview.success && preview.commitCount > 0) {
478
+ console.log();
479
+ console.log(chalk.bold('Commits to merge:'));
480
+ for (const commit of preview.commits.slice(0, 5)) {
481
+ console.log(` ${chalk.dim('•')} ${commit}`);
482
+ }
483
+ if (preview.commits.length > 5) {
484
+ console.log(chalk.dim(` ... and ${preview.commits.length - 5} more`));
485
+ }
486
+ console.log();
487
+ console.log(chalk.bold('Files changed:'), preview.fileCount);
488
+ }
489
+
490
+ // Confirm if not using --yes
491
+ if (!options.yes) {
492
+ console.log();
493
+ const { confirmed } = await inquirer.prompt([
494
+ {
495
+ type: 'confirm',
496
+ name: 'confirmed',
497
+ message: `Merge and end session ${session.id}?`,
498
+ default: true,
499
+ },
500
+ ]);
501
+
502
+ if (!confirmed) {
503
+ info('Operation cancelled');
504
+ process.exit(0);
505
+ }
506
+ }
507
+
508
+ // Perform merge
509
+ const strategy = options.strategy || 'squash';
510
+ const mergeSpinner = ora(`Merging session (${strategy})...`).start();
511
+
512
+ const mergeResult = sessionManager.integrateSession(idOrNickname, {
513
+ strategy,
514
+ deleteBranch: true,
515
+ deleteWorktree: true,
516
+ });
517
+
518
+ if (!mergeResult.success) {
519
+ mergeSpinner.fail('Merge failed');
520
+ error(mergeResult.error);
521
+ if (mergeResult.hasConflicts) {
522
+ console.log();
523
+ info('The merge has conflicts that need manual resolution');
524
+ info('Try using /agileflow:session:end in Claude Code for guided resolution');
525
+ }
526
+ process.exit(1);
527
+ }
528
+
529
+ mergeSpinner.succeed('Session merged and cleaned up');
530
+
531
+ console.log();
532
+ success(`Session ${chalk.cyan(session.id)} has been merged to ${mergeResult.mainBranch}`);
533
+ if (mergeResult.branchDeleted) {
534
+ info(`Branch ${session.branch} deleted`);
535
+ }
536
+ if (mergeResult.worktreeDeleted) {
537
+ info('Worktree removed');
538
+ }
539
+ console.log();
540
+ info(`Changes are now on ${chalk.cyan(mergeResult.mainBranch)} in:`);
541
+ console.log(` ${chalk.cyan(mergeResult.mainPath)}`);
542
+ console.log();
543
+ } else {
544
+ // End without merge - just delete
545
+ if (!options.yes) {
546
+ console.log();
547
+ warning('This will delete the session WITHOUT merging changes');
548
+ const { confirmed } = await inquirer.prompt([
549
+ {
550
+ type: 'confirm',
551
+ name: 'confirmed',
552
+ message: `End session ${session.id} without merging?`,
553
+ default: false,
554
+ },
555
+ ]);
556
+
557
+ if (!confirmed) {
558
+ info('Operation cancelled');
559
+ info('Use --merge to merge changes before ending');
560
+ process.exit(0);
561
+ }
562
+ }
563
+
564
+ const spinner = ora('Ending session...').start();
565
+
566
+ const deleteResult = sessionManager.deleteSession(idOrNickname, true);
567
+
568
+ if (!deleteResult.success) {
569
+ spinner.fail('Failed to end session');
570
+ error(deleteResult.error);
571
+ process.exit(1);
572
+ }
573
+
574
+ spinner.succeed('Session ended');
575
+
576
+ console.log();
577
+ success(`Session ${chalk.cyan(session.id)} has been removed`);
578
+ info('Worktree and session registry entry deleted');
579
+ console.log();
580
+ warning('Any uncommitted changes have been discarded');
581
+ console.log();
582
+ }
583
+ }
584
+
585
+ /**
586
+ * Handle spawn subcommand - spawn multiple parallel sessions
587
+ */
588
+ async function handleSpawn(options, handler) {
589
+ const count = options.count ? parseInt(options.count, 10) : null;
590
+ const branches = options.branches ? options.branches.split(',').map(b => b.trim()) : null;
591
+ const fromEpic = options.fromEpic;
592
+ // Commander.js converts --no-X to options.X = false
593
+ const noTmux = options.tmux === false;
594
+ const noClaude = options.claude === false;
595
+ const dangerous = options.dangerous;
596
+ const prompt = options.prompt;
597
+
598
+ // Validate: need at least one of count, branches, or fromEpic
599
+ if (!count && !branches && !fromEpic) {
600
+ handler.warning(
601
+ 'Must specify --count, --branches, or --from-epic',
602
+ 'Provide number of sessions or branch names',
603
+ 'npx agileflow session spawn --count 4'
604
+ );
605
+ }
606
+
607
+ displayLogo();
608
+ displaySection('Spawn Parallel Sessions');
609
+
610
+ // Build the list of sessions to create
611
+ const sessionsToCreate = [];
612
+
613
+ if (fromEpic) {
614
+ // Get ready stories from epic via status.json
615
+ const statusPath = sessionManager.getStatusPath
616
+ ? sessionManager.getStatusPath()
617
+ : 'docs/09-agents/status.json';
618
+ let status;
619
+ try {
620
+ const fs = require('fs-extra');
621
+ if (fs.existsSync(statusPath)) {
622
+ status = fs.readJsonSync(statusPath);
623
+ } else {
624
+ handler.warning(
625
+ `Status file not found: ${statusPath}`,
626
+ 'Ensure AgileFlow is installed in this project',
627
+ 'npx agileflow setup'
628
+ );
629
+ }
630
+ } catch {
631
+ handler.warning(
632
+ 'Could not read status.json',
633
+ 'Check file permissions',
634
+ `ls -la ${statusPath}`
635
+ );
636
+ }
637
+
638
+ const epic = status?.epics?.[fromEpic];
639
+ if (!epic) {
640
+ handler.warning(`Epic ${fromEpic} not found`, 'Check epic ID', 'npx agileflow session list');
641
+ }
642
+
643
+ const storyIds = epic.stories || [];
644
+ const readyStories = storyIds
645
+ .map(id => status?.stories?.[id])
646
+ .filter(s => s && s.status === 'ready');
647
+
648
+ if (readyStories.length === 0) {
649
+ info(`No ready stories found in epic ${fromEpic}`);
650
+ console.log();
651
+ info('Stories must have status: ready to be spawned');
652
+ process.exit(0);
653
+ }
654
+
655
+ console.log(chalk.bold(`Epic: ${epic.title || fromEpic}`));
656
+ console.log(`Found ${chalk.cyan(readyStories.length)} ready stories\n`);
657
+
658
+ for (const story of readyStories) {
659
+ sessionsToCreate.push({
660
+ nickname: story.id?.toLowerCase() || `story-${Date.now()}`,
661
+ branch: `feature/${story.id?.toLowerCase() || `story-${Date.now()}`}`,
662
+ story: story.id,
663
+ });
664
+ }
665
+ } else if (branches) {
666
+ for (const branch of branches) {
667
+ sessionsToCreate.push({
668
+ nickname: branch,
669
+ branch: `feature/${branch}`,
670
+ });
671
+ }
672
+ } else if (count) {
673
+ for (let i = 1; i <= count; i++) {
674
+ sessionsToCreate.push({
675
+ nickname: `parallel-${i}`,
676
+ branch: `parallel-${i}`,
677
+ });
678
+ }
679
+ }
680
+
681
+ console.log(chalk.bold(`Creating ${sessionsToCreate.length} parallel session(s)...\n`));
682
+
683
+ // Create the sessions
684
+ const createdSessions = [];
685
+ for (const sessionSpec of sessionsToCreate) {
686
+ const spinner = ora(`Creating ${sessionSpec.nickname}...`).start();
687
+
688
+ try {
689
+ const result = await sessionManager.createSession({
690
+ nickname: sessionSpec.nickname,
691
+ branch: sessionSpec.branch,
692
+ });
693
+
694
+ if (!result.success) {
695
+ spinner.fail(`Failed: ${sessionSpec.nickname}`);
696
+ error(` ${result.error}`);
697
+ continue;
698
+ }
699
+
700
+ createdSessions.push({
701
+ sessionId: result.sessionId,
702
+ path: result.path,
703
+ branch: result.branch,
704
+ nickname: sessionSpec.nickname,
705
+ envFilesCopied: result.envFilesCopied || [],
706
+ foldersCopied: result.foldersCopied || [],
707
+ });
708
+
709
+ const copied = [...(result.envFilesCopied || []), ...(result.foldersCopied || [])];
710
+ const copyInfo = copied.length ? chalk.dim(` (copied: ${copied.join(', ')})`) : '';
711
+ spinner.succeed(
712
+ `Session ${chalk.cyan(result.sessionId)}: ${sessionSpec.nickname}${copyInfo}`
713
+ );
714
+ } catch (err) {
715
+ spinner.fail(`Error: ${sessionSpec.nickname}`);
716
+ error(` ${err.message}`);
717
+ }
718
+ }
719
+
720
+ if (createdSessions.length === 0) {
721
+ console.log();
722
+ error('No sessions were created');
723
+ process.exit(1);
724
+ }
725
+
726
+ console.log();
727
+
728
+ // Spawn in tmux or output commands
729
+ if (noTmux) {
730
+ outputSpawnCommands(createdSessions, { dangerous, prompt, noClaude });
731
+ } else if (hasTmux()) {
732
+ const tmuxResult = spawnInTmux(createdSessions, {
733
+ dangerous,
734
+ prompt,
735
+ noClaude,
736
+ });
737
+
738
+ if (tmuxResult.success) {
739
+ success(`Tmux session created: ${chalk.cyan(tmuxResult.sessionName)}`);
740
+ console.log(`${tmuxResult.windowCount} windows ready\n`);
741
+
742
+ console.log(chalk.bold('Controls:'));
743
+ console.log(
744
+ ` ${chalk.cyan(`tmux attach -t ${tmuxResult.sessionName}`)} ${chalk.dim('- Attach to session')}`
745
+ );
746
+ console.log(` ${chalk.dim('Alt+1/2/3')} ${chalk.dim('- Switch to window 1, 2, 3')}`);
747
+ console.log(` ${chalk.dim('q')} ${chalk.dim('- Detach (sessions keep running)')}`);
748
+ console.log();
749
+ } else {
750
+ warning('Failed to create tmux session');
751
+ outputSpawnCommands(createdSessions, { dangerous, prompt, noClaude });
752
+ }
753
+ } else {
754
+ console.log();
755
+ warning('tmux is not installed');
756
+ console.log();
757
+ console.log(chalk.bold('Install tmux:'));
758
+ console.log(` ${chalk.cyan('macOS:')} brew install tmux`);
759
+ console.log(` ${chalk.cyan('Ubuntu/Debian:')} sudo apt install tmux`);
760
+ console.log(` ${chalk.cyan('Fedora/RHEL:')} sudo dnf install tmux`);
761
+ console.log();
762
+ outputSpawnCommands(createdSessions, { dangerous, prompt, noClaude });
763
+ }
764
+
765
+ // Summary table
766
+ console.log(chalk.bold('Session Summary:'));
767
+ console.log(chalk.dim('─'.repeat(60)));
768
+ for (const session of createdSessions) {
769
+ console.log(
770
+ ` ${chalk.cyan(session.sessionId.padEnd(4))} │ ${session.nickname.padEnd(20)} │ ${chalk.dim(session.branch)}`
771
+ );
772
+ }
773
+ console.log(chalk.dim('─'.repeat(60)));
774
+ console.log();
775
+ info('Use: npx agileflow session list to view all sessions');
776
+ info('Use: npx agileflow session end <id> to end a session');
777
+ console.log();
778
+ }
779
+
780
+ /**
781
+ * Output spawn commands for manual execution (no tmux)
782
+ */
783
+ function outputSpawnCommands(sessions, options = {}) {
784
+ console.log(chalk.bold('Commands to run manually:\n'));
785
+
786
+ for (const session of sessions) {
787
+ const cmd = buildClaudeCommand(session.path, options);
788
+ console.log(chalk.dim(`# Session ${session.sessionId} (${session.nickname})`));
789
+ console.log(` ${chalk.cyan(cmd)}`);
790
+ console.log();
791
+ }
792
+
793
+ console.log(chalk.dim('Copy these commands to separate terminals to run in parallel.\n'));
794
+ }
795
+
796
+ /**
797
+ * Handle status subcommand - detailed view of a single session
798
+ */
799
+ async function handleStatus(idOrNickname, options, handler) {
800
+ if (!idOrNickname) {
801
+ handler.warning(
802
+ 'Session ID or nickname required',
803
+ 'Provide a session identifier',
804
+ 'npx agileflow session status <id>'
805
+ );
806
+ }
807
+
808
+ const session = sessionManager.getSession(idOrNickname);
809
+
810
+ if (!session) {
811
+ handler.warning(
812
+ `Session "${idOrNickname}" not found`,
813
+ 'Check the session ID or nickname',
814
+ 'npx agileflow session list'
815
+ );
816
+ }
817
+
818
+ // Gather git information from the session's worktree
819
+ const gitInfo = getSessionGitInfo(session.path);
820
+
821
+ // Build status data object
822
+ const statusData = {
823
+ id: session.id,
824
+ nickname: session.nickname || null,
825
+ branch: session.branch,
826
+ path: session.path,
827
+ created: session.created,
828
+ lastActive: session.last_active,
829
+ isMain: session.is_main,
830
+ active: session.active,
831
+ current: session.current,
832
+ git: gitInfo,
833
+ };
834
+
835
+ // JSON output
836
+ if (options.json) {
837
+ console.log(JSON.stringify(statusData, null, 2));
838
+ return;
839
+ }
840
+
841
+ // Rich display
842
+ displayLogo();
843
+ displaySection('Session Status', `Session ${session.id}`);
844
+
845
+ // Basic info
846
+ console.log(chalk.bold('Session Information'));
847
+ console.log(chalk.dim('─'.repeat(50)));
848
+ console.log(` ${chalk.dim('ID:')} ${chalk.cyan(session.id)}`);
849
+ if (session.nickname) {
850
+ console.log(` ${chalk.dim('Nickname:')} ${session.nickname}`);
851
+ }
852
+ console.log(` ${chalk.dim('Branch:')} ${session.branch}`);
853
+ console.log(` ${chalk.dim('Path:')} ${session.path}`);
854
+ console.log(` ${chalk.dim('Created:')} ${formatDate(session.created)}`);
855
+ console.log(` ${chalk.dim('Last Active:')} ${formatDate(session.last_active)}`);
856
+
857
+ // Status badges
858
+ const badges = [];
859
+ if (session.is_main) badges.push(chalk.blue('[main]'));
860
+ if (session.current) badges.push(chalk.yellow('[current]'));
861
+ if (session.active) badges.push(chalk.green('[active]'));
862
+ if (badges.length > 0) {
863
+ console.log(` ${chalk.dim('Status:')} ${badges.join(' ')}`);
864
+ }
865
+ console.log();
866
+
867
+ // Git status
868
+ console.log(chalk.bold('Git Status'));
869
+ console.log(chalk.dim('─'.repeat(50)));
870
+
871
+ if (gitInfo.error) {
872
+ warning(`Could not get git info: ${gitInfo.error}`);
873
+ } else {
874
+ // Branch and tracking
875
+ console.log(` ${chalk.dim('Branch:')} ${gitInfo.branch}`);
876
+ if (gitInfo.upstream) {
877
+ console.log(` ${chalk.dim('Tracking:')} ${gitInfo.upstream}`);
878
+ }
879
+
880
+ // Ahead/behind
881
+ if (gitInfo.ahead > 0 || gitInfo.behind > 0) {
882
+ const aheadBehind = [];
883
+ if (gitInfo.ahead > 0) {
884
+ aheadBehind.push(chalk.green(`↑${gitInfo.ahead} ahead`));
885
+ }
886
+ if (gitInfo.behind > 0) {
887
+ aheadBehind.push(chalk.yellow(`↓${gitInfo.behind} behind`));
888
+ }
889
+ console.log(` ${chalk.dim('Sync:')} ${aheadBehind.join(', ')}`);
890
+ } else if (gitInfo.upstream) {
891
+ console.log(` ${chalk.dim('Sync:')} ${chalk.green('✓ up to date')}`);
892
+ }
893
+
894
+ // Uncommitted changes
895
+ if (gitInfo.uncommitted > 0) {
896
+ console.log(
897
+ ` ${chalk.dim('Changes:')} ${chalk.yellow(`${gitInfo.uncommitted} uncommitted file(s)`)}`
898
+ );
899
+ // Show first few changed files
900
+ if (gitInfo.changedFiles && gitInfo.changedFiles.length > 0) {
901
+ const filesToShow = gitInfo.changedFiles.slice(0, 5);
902
+ for (const file of filesToShow) {
903
+ console.log(` ${chalk.dim(file)}`);
904
+ }
905
+ if (gitInfo.changedFiles.length > 5) {
906
+ console.log(chalk.dim(` ... and ${gitInfo.changedFiles.length - 5} more`));
907
+ }
908
+ }
909
+ } else {
910
+ console.log(` ${chalk.dim('Changes:')} ${chalk.green('✓ clean working tree')}`);
911
+ }
912
+
913
+ // Recent commits
914
+ if (gitInfo.recentCommits && gitInfo.recentCommits.length > 0) {
915
+ console.log();
916
+ console.log(chalk.bold('Recent Commits'));
917
+ console.log(chalk.dim('─'.repeat(50)));
918
+ for (const commit of gitInfo.recentCommits.slice(0, 5)) {
919
+ console.log(` ${chalk.dim('•')} ${commit}`);
920
+ }
921
+ }
922
+ }
923
+
924
+ console.log();
925
+
926
+ // Navigation help
927
+ console.log(chalk.bold('Actions'));
928
+ console.log(chalk.dim('─'.repeat(50)));
929
+ console.log(` ${chalk.cyan(`cd "${session.path}"`)} ${chalk.dim('- Navigate to session')}`);
930
+ if (!session.is_main) {
931
+ console.log(
932
+ ` ${chalk.cyan(`npx agileflow session end ${session.id}`)} ${chalk.dim('- End session')}`
933
+ );
934
+ console.log(
935
+ ` ${chalk.cyan(`npx agileflow session end ${session.id} --merge`)} ${chalk.dim('- Merge and end')}`
936
+ );
937
+ }
938
+ console.log();
939
+ }
940
+
941
+ /**
942
+ * Get git information for a session path
943
+ */
944
+ function getSessionGitInfo(sessionPath) {
945
+ const { execSync } = require('child_process');
946
+ const fs = require('fs-extra');
947
+
948
+ if (!fs.existsSync(sessionPath)) {
949
+ return { error: 'Path does not exist' };
950
+ }
951
+
952
+ const execOpts = { cwd: sessionPath, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] };
953
+
954
+ try {
955
+ // Get current branch
956
+ let branch = '';
957
+ try {
958
+ branch = execSync('git rev-parse --abbrev-ref HEAD', execOpts).trim();
959
+ } catch {
960
+ return { error: 'Not a git repository' };
961
+ }
962
+
963
+ // Get upstream tracking branch
964
+ let upstream = '';
965
+ try {
966
+ upstream = execSync(`git rev-parse --abbrev-ref ${branch}@{upstream}`, execOpts).trim();
967
+ } catch {
968
+ // No upstream configured
969
+ }
970
+
971
+ // Get ahead/behind counts
972
+ let ahead = 0;
973
+ let behind = 0;
974
+ if (upstream) {
975
+ try {
976
+ const counts = execSync(
977
+ `git rev-list --left-right --count ${branch}...${upstream}`,
978
+ execOpts
979
+ )
980
+ .trim()
981
+ .split('\t');
982
+ ahead = parseInt(counts[0], 10) || 0;
983
+ behind = parseInt(counts[1], 10) || 0;
984
+ } catch {
985
+ // Ignore errors
986
+ }
987
+ }
988
+
989
+ // Get uncommitted changes count
990
+ let uncommitted = 0;
991
+ let changedFiles = [];
992
+ try {
993
+ const status = execSync('git status --porcelain', execOpts);
994
+ // Split by newline, preserving line format (don't trim whole output)
995
+ // Git porcelain format: XY filename (where XY is 2 chars + space = 3 chars prefix)
996
+ const lines = status.split('\n').filter(line => line.length >= 3);
997
+ if (lines.length > 0) {
998
+ changedFiles = lines.map(line => line.slice(3));
999
+ uncommitted = changedFiles.length;
1000
+ }
1001
+ } catch {
1002
+ // Ignore errors
1003
+ }
1004
+
1005
+ // Get recent commits
1006
+ let recentCommits = [];
1007
+ try {
1008
+ const log = execSync('git log --oneline -5', execOpts).trim();
1009
+ if (log) {
1010
+ recentCommits = log.split('\n');
1011
+ }
1012
+ } catch {
1013
+ // Ignore errors
1014
+ }
1015
+
1016
+ return {
1017
+ branch,
1018
+ upstream,
1019
+ ahead,
1020
+ behind,
1021
+ uncommitted,
1022
+ changedFiles,
1023
+ recentCommits,
1024
+ };
1025
+ } catch (err) {
1026
+ return { error: err.message };
1027
+ }
1028
+ }
1029
+
1030
+ /**
1031
+ * Handle history subcommand - display merge history
1032
+ */
1033
+ async function handleHistory(options) {
1034
+ const limit = parseInt(options.limit) || 20;
1035
+
1036
+ // Get merge history from session manager
1037
+ const historyResult = sessionManager.getMergeHistory();
1038
+
1039
+ if (!historyResult.success) {
1040
+ if (options.json) {
1041
+ console.log(JSON.stringify({ success: false, error: historyResult.error }));
1042
+ return;
1043
+ }
1044
+ error(`Failed to read history: ${historyResult.error}`);
1045
+ return;
1046
+ }
1047
+
1048
+ const merges = historyResult.merges || [];
1049
+
1050
+ // JSON output mode
1051
+ if (options.json) {
1052
+ console.log(
1053
+ JSON.stringify(
1054
+ {
1055
+ success: true,
1056
+ total: merges.length,
1057
+ showing: Math.min(limit, merges.length),
1058
+ merges: merges.slice(0, limit),
1059
+ },
1060
+ null,
1061
+ 2
1062
+ )
1063
+ );
1064
+ return;
1065
+ }
1066
+
1067
+ // Standard display
1068
+ displayLogo();
1069
+ displaySection('Session History', `${merges.length} merge(s) recorded`);
1070
+
1071
+ if (merges.length === 0) {
1072
+ info('No merge history recorded yet.');
1073
+ console.log();
1074
+ info('Merge history is created when sessions are integrated into main.');
1075
+ console.log(chalk.dim(' Use: npx agileflow session end <id> --merge'));
1076
+ return;
1077
+ }
1078
+
1079
+ // Display merges (most recent first)
1080
+ const toShow = merges.slice(-limit).reverse();
1081
+
1082
+ console.log();
1083
+ for (const merge of toShow) {
1084
+ const timestamp = merge.timestamp ? formatDate(merge.timestamp) : 'unknown';
1085
+ const strategy = merge.strategy || 'unknown';
1086
+ const commits = merge.commitsCount || merge.commits?.length || 0;
1087
+
1088
+ // Session info line
1089
+ console.log(
1090
+ chalk.bold(`Session ${merge.sessionId || 'unknown'}`) +
1091
+ chalk.dim(` (${merge.nickname || 'no nickname'})`)
1092
+ );
1093
+
1094
+ // Branch info
1095
+ console.log(
1096
+ chalk.dim(' Branch: ') +
1097
+ chalk.cyan(merge.branch || 'unknown') +
1098
+ chalk.dim(' → ') +
1099
+ chalk.green(merge.targetBranch || 'main')
1100
+ );
1101
+
1102
+ // Merge details
1103
+ console.log(
1104
+ chalk.dim(' Strategy: ') +
1105
+ chalk.yellow(strategy) +
1106
+ chalk.dim(' | Commits: ') +
1107
+ chalk.white(commits) +
1108
+ chalk.dim(' | ') +
1109
+ timestamp
1110
+ );
1111
+
1112
+ // Result status
1113
+ if (merge.success === false) {
1114
+ console.log(chalk.red(' ✗ Failed: ') + chalk.dim(merge.error || 'Unknown error'));
1115
+ } else {
1116
+ console.log(chalk.green(' ✓ Merged successfully'));
1117
+ }
1118
+
1119
+ console.log();
1120
+ }
1121
+
1122
+ if (merges.length > limit) {
1123
+ info(`Showing ${limit} of ${merges.length} merges. Use --limit to see more.`);
1124
+ }
1125
+ }
1126
+
1127
+ /**
1128
+ * Format a date for display
1129
+ */
1130
+ function formatDate(dateStr) {
1131
+ if (!dateStr) return chalk.dim('unknown');
1132
+ try {
1133
+ const date = new Date(dateStr);
1134
+ const now = new Date();
1135
+ const diffMs = now - date;
1136
+ const diffMins = Math.floor(diffMs / 60000);
1137
+ const diffHours = Math.floor(diffMs / 3600000);
1138
+ const diffDays = Math.floor(diffMs / 86400000);
1139
+
1140
+ if (diffMins < 1) return 'just now';
1141
+ if (diffMins < 60) return `${diffMins} minute${diffMins > 1 ? 's' : ''} ago`;
1142
+ if (diffHours < 24) return `${diffHours} hour${diffHours > 1 ? 's' : ''} ago`;
1143
+ if (diffDays < 7) return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`;
1144
+
1145
+ return date.toLocaleDateString();
1146
+ } catch {
1147
+ return chalk.dim(dateStr);
1148
+ }
1149
+ }
1150
+
1151
+ /**
1152
+ * Truncate a path for display
1153
+ */
1154
+ function truncatePath(filePath, maxLen) {
1155
+ if (filePath.length <= maxLen) {
1156
+ return filePath;
1157
+ }
1158
+ const parts = filePath.split(path.sep);
1159
+ let result = parts.pop();
1160
+
1161
+ while (parts.length > 0 && result.length < maxLen - 4) {
1162
+ const next = parts.pop();
1163
+ if ((next + path.sep + result).length < maxLen - 4) {
1164
+ result = next + path.sep + result;
1165
+ } else {
1166
+ break;
1167
+ }
1168
+ }
1169
+
1170
+ return '...' + path.sep + result;
1171
+ }