-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
1978 lines (1730 loc) · 80.8 KB
/
Copy pathinstall.js
File metadata and controls
1978 lines (1730 loc) · 80.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
/**
* ██████╗ ██╗ █████╗ ███╗ ██╗██████╗ ██████╗ ██████╗ ██████╗ ███████╗
* ██╔══██╗██║ ██╔══██╗████╗ ██║╚════██╗██╔════╝██╔═══██╗██╔══██╗██╔════╝
* ██████╔╝██║ ███████║██╔██╗ ██║ █████╔╝██║ ██║ ██║██║ ██║█████╗
* ██╔═══╝ ██║ ██╔══██║██║╚██╗██║██╔═══╝ ██║ ██║ ██║██║ ██║██╔══╝
* ██║ ███████╗██║ ██║██║ ╚████║███████╗╚██████╗╚██████╔╝██████╔╝███████╗
* ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
*
* GLOBAL INSTALLATION SYSTEM
*
* DESCRIPTION:
* Install Plan2Code skills globally or into the current project via skills.sh.
* Builds the committed skills/ artifact from source prompts in src/.
* Supports non-interactive --build-skills and --verify-skills maintenance hooks.
*/
const fs = require('fs');
const path = require('path');
const os = require('os');
const readline = require('readline');
// Load project version metadata
let projectVersion = { name: 'Plan2Code', version: 'unknown' };
try {
const versionPath = path.join(__dirname, 'version.json');
if (fs.existsSync(versionPath)) {
const versionData = JSON.parse(fs.readFileSync(versionPath, 'utf8'));
projectVersion = { name: versionData.name, version: versionData.version };
}
} catch (err) {
// Silently continue with default version if file is not found or invalid
}
// Color codes for display (ANSI escape sequences)
// Use these in console.log() for colored output
const COLORS = {
RESET: '\x1b[0m',
BRIGHT: '\x1b[1m',
DIM: '\x1b[2m',
// Colors
GREEN: '\x1b[32m', // Success
YELLOW: '\x1b[33m', // Warning
RED: '\x1b[31m', // Error
CYAN: '\x1b[36m', // Info/Headers
BLUE: '\x1b[34m', // Data/Paths
MAGENTA: '\x1b[35m', // Special/Highlight
// Background colors
BG_BLACK: '\x1b[40m',
BG_GREEN: '\x1b[42m',
BG_YELLOW: '\x1b[43m',
BG_RED: '\x1b[41m',
};
// Symbols for status reporting
const SYMBOLS = {
SUCCESS: '▰▰▰', // Success
ACTIVE: '►►►', // Active/In Progress
WARNING: '⚠ ⚠ ⚠', // Warning
ERROR: '✖✖✖', // Error
INFO: '◆', // Info
SELECT: '◉', // Selection marker
COMPLETE: '█', // Complete
PENDING: '░', // Pending
DIVIDER: '═', // Divider
CORNER_TL: '╔', // Box corners
CORNER_TR: '╗',
CORNER_BL: '╚',
CORNER_BR: '╝',
HORIZONTAL: '═',
VERTICAL: '║',
TEE_RIGHT: '╠',
TEE_LEFT: '╣',
};
// Plan2Code Mascot - appears during user interactions
const MASCOT = {
// Full mascot for headers
full: [
' ╭───╮ ',
' │ ● │ ',
' │ ◡ │ ',
' ╰───╯ ',
],
// Mini mascot for inline use
mini: '(◉‿◉)',
// Waving mascot for greetings
wave: [
' ╭───╮ ',
' │ ● │ /',
' │ ◡ │ ',
' ╰───╯ ',
],
// Thinking mascot for prompts
thinking: [
' ╭───╮ ',
' │ ● │ ?',
' │ ~ │ ',
' ╰───╯ ',
],
};
// Generated skills directory — the committed, canonical Agent Skills build of src/.
// `skills add` consumes this directory; nothing else is platform-specific any more.
const SKILLS_DIR_NAME = 'skills';
const SKILLS_DIR = path.join(__dirname, SKILLS_DIR_NAME);
// Source prompts directory
const SRC_DIR = path.join(__dirname, 'src');
// ============================================================================
// SYNC PROMPTS CONFIGURATION (merged from sync-prompts.js)
// ============================================================================
// Configuration for source prompts
const SOURCE_PROMPTS = [
{
source: 'plan2code-init.md',
stepNumber: 'init',
name: 'init',
displayName: 'Init Mode',
description: 'Generate AGENTS.md file for project-specific guidance',
isUtility: true
},
{
source: 'plan2code-init-update.md',
stepNumber: 'update',
name: 'init-update',
displayName: 'Init Update Mode',
description: 'Update existing AGENTS.md with new learnings',
isUtility: true
},
{
source: 'plan2code-0-pathfinder.md',
stepNumber: '0',
name: 'pathfinder',
displayName: 'Pathfinder Mode',
description: 'charting of a foggy idea as a map of decision questions, cleared one at a time'
},
{
source: 'plan2code-quick-task.md',
stepNumber: 'quick',
name: 'quick-task',
displayName: 'Quick Task Mode',
description: 'Lightweight planning for small tasks',
isUtility: true
},
{
source: 'plan2code-1-plan.md',
stepNumber: 1,
name: 'plan',
displayName: 'Planning Mode',
description: 'Requirements analysis and architecture design'
},
{
source: 'plan2code-1b-revise-plan.md',
stepNumber: '1b',
name: 'revise-plan',
displayName: 'Revision Mode',
description: 'Modify specs mid-implementation when requirements change'
},
{
source: 'plan2code-2-document.md',
stepNumber: 2,
name: 'document',
displayName: 'Documentation Mode',
description: 'Transform planning output into structured implementation docs'
},
{
source: 'plan2code-3-implement.md',
stepNumber: 3,
name: 'implement',
displayName: 'Implementation Mode',
description: 'Execute implementation phase by phase'
},
{
source: 'plan2code-review.md',
stepNumber: 'review',
name: 'review',
displayName: 'Review Mode',
description: 'Comprehensive post-implementation review with spec compliance checking',
isUtility: true
},
{
source: 'plan2code-4-finalize.md',
stepNumber: 4,
name: 'finalize',
displayName: 'Finalization Mode',
description: 'Validate, summarize, and archive completed work'
},
{
source: 'plan2code-handoff.md',
stepNumber: 'handoff',
name: 'handoff',
displayName: 'Handoff Mode',
description: 'Compact the conversation into a self-contained handoff document for a fresh session',
isUtility: true
}
];
// Helper function to generate destination filename based on stepNumber
function generateFilename(prompt, extension = '.md') {
if (prompt.isUtility || prompt.stepNumber === 0 || prompt.stepNumber === 'init') {
return `plan2code-${prompt.name}${extension}`;
}
return `plan2code-${prompt.stepNumber}-${prompt.name}${extension}`;
}
// Helper function to generate skill name (normalizes double hyphens to single)
function generateSkillName(prompt) {
return generateFilename(prompt, '').replace(/--+/g, '-');
}
// Helper function to generate step label for descriptions
function generateStepLabel(prompt) {
if (prompt.stepNumber === 'init') return 'Init';
if (prompt.stepNumber === 'update') return 'Update';
if (prompt.stepNumber === 'review') return 'Review';
if (prompt.stepNumber === 'handoff') return 'Handoff';
if (prompt.stepNumber === 'quick') return 'Quick Task';
return `Step ${prompt.stepNumber}`;
}
// Helper function to generate YAML frontmatter for SKILL.md files
function generateSkillHeader(prompt, disableModelInvocation = false) {
const lines = [
'---',
`name: ${generateSkillName(prompt)}`,
`description: "Plan2Code ${generateStepLabel(prompt)}: ${prompt.displayName} - user-initiated workflow step. Do not invoke autonomously."`,
];
if (disableModelInvocation) lines.push('disable-model-invocation: true');
lines.push('---');
return lines.join('\n');
}
// Helper function to get VS Code Copilot prompts directory based on platform
function getVSCodeCopilotDir() {
const platform = process.platform;
if (platform === 'win32') {
// Windows: %APPDATA%\Code\User\prompts
return path.join(process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming'), 'Code', 'User', 'prompts');
} else if (platform === 'darwin') {
// macOS: ~/Library/Application Support/Code/User/prompts
return path.join(os.homedir(), 'Library', 'Application Support', 'Code', 'User', 'prompts');
} else {
// Linux: ~/.config/Code/User/prompts
return path.join(os.homedir(), '.config', 'Code', 'User', 'prompts');
}
}
// Helper function to get Crush skills directory based on platform
function getCrushSkillsDir() {
const homedir = os.homedir();
if (process.platform === 'win32') {
const localAppData = process.env.LOCALAPPDATA || path.join(homedir, 'AppData', 'Local');
return path.join(localAppData, 'crush', 'skills');
}
return path.join(homedir, '.config', 'crush', 'skills');
}
// Helper function to pad strings with ANSI codes correctly
function stripAnsi(str) {
return str.replace(/\x1b\[[0-9;]*m/g, '');
}
function padEndVisible(str, length, char = ' ') {
const visibleLength = stripAnsi(str).length;
const paddingNeeded = Math.max(0, length - visibleLength);
return str + char.repeat(paddingNeeded);
}
// Legacy install paths — directories that pre-2.2 installs wrote Plan2Code files into.
// 2.2.0 delegates all distribution to the `skills` CLI, so these are cleanup-only: install and
// uninstall both sweep them so files from earlier versions don't linger and shadow the new
// skills. Do NOT add entries here as install targets; the `skills` CLI owns installation.
//
// `dir` is either a path relative to the home directory or a function returning an absolute path.
// `type: 'skill'` entries are directories (removed recursively); the rest are flat files.
const LEGACY_PATHS = [
// Claude Code — pre-v2 slash commands
{ name: 'Claude Code commands', dir: '.claude/commands', filePattern: /^plan2code-.*\.md$/ },
// Copilot CLI agents
{ name: 'Copilot CLI agents', dir: '.copilot/agents', filePattern: /^plan2code-.*\.md$/ },
// Cursor slash commands
{ name: 'Cursor commands', dir: '.cursor/commands', filePattern: /^plan2code-.*\.md$/ },
// Continue prompts
{ name: 'Continue prompts', dir: '.continue/prompts', filePattern: /^plan2code-.*\.prompt\.md$/ },
// Windsurf global workflows
{ name: 'Windsurf workflows', dir: '.codeium/windsurf/global_workflows', filePattern: /^plan2code-.*\.md$/ },
// Codeium (IntelliJ) global workflows
{ name: 'Codeium workflows', dir: '.codeium/global_workflows', filePattern: /^plan2code-.*\.md$/ },
// Pi prompts
{ name: 'Pi prompts', dir: '.pi/agent/prompts', filePattern: /^plan2code-.*\.md$/ },
// Gemini CLI — removed as a target in v2.0.0, still cleaned up
{ name: 'Gemini CLI commands', dir: '.gemini/commands', filePattern: /^plan2code-.*\.toml$/ },
// VS Code Copilot prompts (platform-specific location)
{ name: 'VS Code Copilot prompts', dir: getVSCodeCopilotDir, filePattern: /^plan2code-.*\.prompt\.md$/ },
// Skill directories that pre-2.2 installs wrote as real copies. The skills CLI owns these
// paths now (~/.agents/skills is its store; the rest are links into it), but it won't
// recognize hand-copied directories from an earlier version, so sweep them too. Safe to run
// before `skills add`, which recreates whatever it needs.
{ name: 'Crush skills', dir: getCrushSkillsDir, filePattern: /^plan2code-/, type: 'skill' },
{ name: 'Claude Code skills', dir: '.claude/skills', filePattern: /^plan2code-/, type: 'skill' },
{ name: 'Agent skills store', dir: '.agents/skills', filePattern: /^plan2code-/, type: 'skill' },
];
// Reference directories that flat-file targets received as siblings (e.g. plan2code-review-references/).
const LEGACY_REFERENCE_DIR = /^plan2code-.*-references$/;
// ============================================================================
// DISPLAY FUNCTIONS
// ============================================================================
/**
* Display mascot with optional message
*/
function displayMascot(variant = 'full', message = '') {
const mascotLines = MASCOT[variant] || MASCOT.full;
console.log('');
mascotLines.forEach(line => {
console.log(`${COLORS.MAGENTA}${line}${COLORS.RESET}`);
});
if (message) {
console.log(`${COLORS.CYAN}${message}${COLORS.RESET}`);
}
console.log('');
}
/**
* Display header
*/
function displayHeader() {
console.log('');
console.log(`${COLORS.CYAN}${COLORS.BRIGHT}`);
console.log('╔═════════════════════════════════════════════════════════╗');
console.log('║ ╭───╮ ║');
console.log('║ │ ● │ Hi! I\'m Planny! ║');
console.log('║ │ ◡ │ Nice to meet you ║');
console.log('║ ╰───╯ Welcome to Plan2Code! ║');
console.log('║ ║');
console.log('║ G L O B A L I N S T A L L A T I O N S Y S T E M ║');
console.log('║ https://github.com/jparkerweb/plan2code ║');
console.log('║ ║');
console.log('╚═════════════════════════════════════════════════════════╝');
console.log(COLORS.RESET);
console.log('');
}
/**
* Display section header with border
*/
function displaySectionHeader(title, mode = '') {
const innerWidth = 75;
// Center the title with ═ padding
const titleContent = `[ ${title} ]`;
const titlePadTotal = innerWidth - titleContent.length;
const titlePadLeft = Math.floor(titlePadTotal / 2);
const titlePadRight = titlePadTotal - titlePadLeft;
const titleLine = '═'.repeat(titlePadLeft) + titleContent + '═'.repeat(titlePadRight);
console.log(`${COLORS.CYAN}${COLORS.BRIGHT}`);
console.log('╔═══════════════════════════════════════════════════════════════════════════╗');
console.log(`║${' '.repeat(innerWidth)}║`);
console.log(`║${titleLine}║`);
if (mode) {
// Center the mode text with space padding
const modePadTotal = innerWidth - mode.length;
const modePadLeft = Math.floor(modePadTotal / 2);
const modePadRight = modePadTotal - modePadLeft;
console.log(`║${' '.repeat(modePadLeft)}${mode}${' '.repeat(modePadRight)}║`);
}
console.log(`║${' '.repeat(75)}║`);
console.log('╚═══════════════════════════════════════════════════════════════════════════╝');
console.log(COLORS.RESET);
}
/**
* Display operation status box
*/
function displayStatusBox(title, lines) {
console.log(`${COLORS.BLUE}`);
console.log('┌─────────────────────────────────────────────────────────────────────────┐');
console.log(`│ ${COLORS.BRIGHT}${title}${COLORS.RESET}${COLORS.BLUE}${' '.repeat(72 - title.length)}│`);
console.log('├─────────────────────────────────────────────────────────────────────────┤');
lines.forEach(line => {
const cleanLine = line.replace(/\x1b\[[0-9;]*m/g, ''); // Remove color codes for length calc
const padding = ' '.repeat(Math.max(0, 72 - cleanLine.length));
console.log(`│ ${line}${padding}│`);
});
console.log('└─────────────────────────────────────────────────────────────────────────┘');
console.log(COLORS.RESET);
}
/**
* Display progress indicator
*/
function displayProgress(current, total, label) {
const barLength = 30;
const filled = Math.floor((current / total) * barLength);
const empty = barLength - filled;
const percent = Math.floor((current / total) * 100);
const bar = `${COLORS.GREEN}${'█'.repeat(filled)}${COLORS.DIM}${'░'.repeat(empty)}${COLORS.RESET}`;
process.stdout.write(`\r${COLORS.CYAN}[${bar}${COLORS.CYAN}]${COLORS.RESET} ${percent}% ${label}`);
}
// ============================================================================
// SYNC PROMPTS FUNCTIONS
// ============================================================================
/**
* Helper function to recursively delete directories
*/
function deleteDirectory(dirPath) {
if (!fs.existsSync(dirPath)) {
return;
}
try {
fs.rmSync(dirPath, { recursive: true, force: true });
} catch (err) {
console.error(` ${COLORS.RED}${SYMBOLS.ERROR}${COLORS.RESET} Could not delete directory ${dirPath}: ${err.message}`);
}
}
// ============================================================================
// SKILLS BUILD (src/ -> skills/)
// ============================================================================
function listFilesRecursive(dir, prefix = '') {
const out = [];
for (const entry of fs.readdirSync(dir)) {
const abs = path.join(dir, entry);
const rel = prefix ? path.join(prefix, entry) : entry;
if (fs.statSync(abs).isDirectory()) out.push(...listFilesRecursive(abs, rel));
else out.push(rel);
}
return out;
}
function computeExpectedSkills() {
const expected = new Map();
const errors = [];
for (const prompt of SOURCE_PROMPTS) {
const sourcePath = path.join(SRC_DIR, prompt.source);
let sourceContent;
try {
sourceContent = fs.readFileSync(sourcePath, 'utf8');
} catch (err) {
errors.push(`Could not read src/${prompt.source}: ${err.message}`);
continue;
}
const skillName = generateSkillName(prompt);
expected.set(
`${SKILLS_DIR_NAME}/${skillName}/SKILL.md`,
generateSkillHeader(prompt, true) + '\n\n' + sourceContent
);
const srcRefDir = path.join(SRC_DIR, prompt.source.replace(/\.md$/, '-references'));
if (!fs.existsSync(srcRefDir)) continue;
for (const relPath of listFilesRecursive(srcRefDir)) {
expected.set(
`${SKILLS_DIR_NAME}/${skillName}/references/${relPath.split(path.sep).join('/')}`,
fs.readFileSync(path.join(srcRefDir, relPath), 'utf8')
);
}
}
return { expected, errors };
}
function buildSkills(quiet = false) {
const { expected, errors } = computeExpectedSkills();
const stats = { written: 0, unchanged: 0, pruned: 0, errors: errors.length };
for (const message of errors) console.error(` ${COLORS.RED}${SYMBOLS.ERROR}${COLORS.RESET} ${message}`);
if (!quiet) console.log(`${COLORS.CYAN}${SYMBOLS.ACTIVE} BUILDING SKILLS${COLORS.RESET} ${COLORS.DIM}src/ -> ${SKILLS_DIR_NAME}/${COLORS.RESET}\n`);
const expectedSkillNames = new Set(SOURCE_PROMPTS.map(generateSkillName));
if (fs.existsSync(SKILLS_DIR)) {
for (const entry of fs.readdirSync(SKILLS_DIR)) {
const entryPath = path.join(SKILLS_DIR, entry);
if (!fs.statSync(entryPath).isDirectory() || expectedSkillNames.has(entry)) continue;
deleteDirectory(entryPath);
stats.pruned++;
if (!quiet) console.log(` ${COLORS.YELLOW}░░░${COLORS.RESET} Pruned: ${entry}/`);
}
}
for (const skillName of expectedSkillNames) {
const skillDir = path.join(SKILLS_DIR, skillName);
if (!fs.existsSync(skillDir)) continue;
for (const relPath of listFilesRecursive(skillDir)) {
const key = `${SKILLS_DIR_NAME}/${skillName}/${relPath.split(path.sep).join('/')}`;
if (expected.has(key)) continue;
fs.rmSync(path.join(skillDir, relPath), { force: true });
stats.pruned++;
if (!quiet) console.log(` ${COLORS.YELLOW}░░░${COLORS.RESET} Pruned: ${key}`);
}
}
for (const [relPath, content] of expected) {
const absPath = path.join(__dirname, relPath.split('/').join(path.sep));
let current = null;
if (fs.existsSync(absPath)) {
try { current = fs.readFileSync(absPath, 'utf8'); } catch {}
}
if (current === content) {
stats.unchanged++;
continue;
}
try {
fs.mkdirSync(path.dirname(absPath), { recursive: true });
fs.writeFileSync(absPath, content, 'utf8');
stats.written++;
if (!quiet) console.log(` ${COLORS.GREEN}▰▰▰${COLORS.RESET} ${relPath}`);
} catch (err) {
console.error(` ${COLORS.RED}✖✖✖${COLORS.RESET} ${relPath}: ${err.message}`);
stats.errors++;
}
}
if (!quiet) {
console.log(`\n ${COLORS.GREEN}${SYMBOLS.SUCCESS}${COLORS.RESET} ${SOURCE_PROMPTS.length} skill(s): ${stats.written} written, ${stats.unchanged} unchanged, ${stats.pruned} pruned`);
if (stats.errors > 0) console.log(` ${COLORS.RED}${SYMBOLS.ERROR}${COLORS.RESET} ${stats.errors} error(s)`);
console.log('');
}
return stats.errors === 0;
}
function verifySkillsSync() {
const { expected, errors } = computeExpectedSkills();
const problems = [...errors];
for (const [relPath, content] of expected) {
const absPath = path.join(__dirname, relPath.split('/').join(path.sep));
if (!fs.existsSync(absPath)) problems.push(`missing: ${relPath}`);
else if (fs.readFileSync(absPath, 'utf8') !== content) problems.push(`out of date: ${relPath}`);
}
if (fs.existsSync(SKILLS_DIR)) {
for (const relPath of listFilesRecursive(SKILLS_DIR)) {
const key = `${SKILLS_DIR_NAME}/${relPath.split(path.sep).join('/')}`;
if (!expected.has(key)) problems.push(`unexpected: ${key}`);
}
}
if (problems.length > 0) {
console.error(`${SKILLS_DIR_NAME}/ is out of sync with src/:\n`);
for (const problem of problems) console.error(` ${problem}`);
console.error(`\n${problems.length} problem(s). Run 'npm run build:skills' and commit the result.`);
return false;
}
console.log(`${SKILLS_DIR_NAME}/ matches src/ — ${expected.size} file(s) across ${SOURCE_PROMPTS.length} skill(s) ✓`);
return true;
}
function cleanLegacyPaths(quiet = false) {
const stats = { removed: 0, errors: 0 };
for (const legacy of LEGACY_PATHS) {
const dir = typeof legacy.dir === 'function' ? legacy.dir() : path.join(os.homedir(), legacy.dir);
if (!fs.existsSync(dir)) continue;
let entries;
try { entries = fs.readdirSync(dir); } catch { continue; }
for (const entry of entries) {
const isMatch = legacy.filePattern.test(entry);
const isReferenceDir = LEGACY_REFERENCE_DIR.test(entry);
if (!isMatch && !isReferenceDir) continue;
try {
const entryPath = path.join(dir, entry);
if (isReferenceDir || legacy.type === 'skill' || fs.statSync(entryPath).isDirectory()) {
fs.rmSync(entryPath, { recursive: true, force: true });
} else {
fs.unlinkSync(entryPath);
}
stats.removed++;
if (!quiet) console.log(` ${COLORS.YELLOW}░░░${COLORS.RESET} ${legacy.name}: removed ${entry}`);
} catch (err) {
stats.errors++;
if (!quiet) console.log(` ${COLORS.RED}✖✖✖${COLORS.RESET} ${legacy.name}: could not remove ${entry} — ${err.message}`);
}
}
}
return stats;
}
// ============================================================================
// SKILLS CLI DELEGATION
// ============================================================================
const SKILLS_CLI = 'npx --yes skills';
const BENIGN_SKILLS_FAILURE = /does not support (global|project) skill installation/i;
function execSkillsCli(args) {
const options = {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'pipe'],
env: { ...process.env, npm_config_loglevel: 'error' },
};
try {
return { ok: true, output: String(execSync(`${SKILLS_CLI} ${args}`, options)).trim() };
} catch (err) {
return { ok: false, output: `${err.stdout || ''}\n${err.stderr || ''}`.trim() };
}
}
function runSkillsCli(args) {
const result = execSkillsCli(args);
return result.ok ? result.output : null;
}
function skillNameArgs() {
return `-s ${SOURCE_PROMPTS.map(generateSkillName).join(' ')}`;
}
function extractSkillsFailures(output) {
const failures = [];
for (const rawLine of stripAnsi(output).split('\n')) {
if (!rawLine.includes('✗')) continue;
const message = rawLine.slice(rawLine.indexOf('✗') + 1).trim();
if (message && !BENIGN_SKILLS_FAILURE.test(message)) failures.push(message);
}
return failures;
}
function reportSkillsOutput(result) {
if (!result.ok) {
console.log(`\n${stripAnsi(result.output)}`);
return;
}
for (const failure of extractSkillsFailures(result.output)) {
console.log(` ${COLORS.YELLOW}${SYMBOLS.WARNING}${COLORS.RESET} ${failure}`);
}
}
function ensureSkillsCli() {
const version = runSkillsCli('--version');
if (version !== null) {
console.log(` ${COLORS.GREEN}${SYMBOLS.SUCCESS}${COLORS.RESET} skills CLI ${COLORS.DIM}${version.split('\n').pop()}${COLORS.RESET}`);
return true;
}
console.log(` ${COLORS.RED}${SYMBOLS.ERROR}${COLORS.RESET} Could not run the ${COLORS.BRIGHT}skills${COLORS.RESET} CLI.`);
console.log(`\n ${COLORS.DIM}Plan2Code installs through skills.sh, which needs Node 18+ and network access.${COLORS.RESET}`);
console.log(` ${COLORS.DIM}Check that this works, then re-run the installer:${COLORS.RESET}`);
console.log(` ${COLORS.CYAN}npx --yes skills --version${COLORS.RESET}\n`);
return false;
}
function listInstalledSkills(scope) {
const json = runSkillsCli(`list ${scope === 'global' ? '-g' : ''} --json`.trim());
if (!json) return [];
try {
const parsed = JSON.parse(json);
if (!Array.isArray(parsed)) return [];
return parsed.map(skill => skill && skill.name)
.filter(name => typeof name === 'string' && name.startsWith('plan2code-'));
} catch {
return [];
}
}
function removeInstalledSkills(scope, { quiet = false } = {}) {
const installed = listInstalledSkills(scope);
if (installed.length === 0) {
if (!quiet) console.log(` ${COLORS.DIM}${SYMBOLS.INFO} No Plan2Code skills currently installed${COLORS.RESET}`);
return 0;
}
const scopeFlag = scope === 'global' ? '-g ' : '';
let removed = 0;
for (const name of installed) {
if (runSkillsCli(`remove ${name} ${scopeFlag}-y`) === null) {
if (!quiet) console.log(` ${COLORS.RED}✖✖✖${COLORS.RESET} Could not remove ${name}`);
continue;
}
removed++;
if (!quiet) console.log(` ${COLORS.YELLOW}░░░${COLORS.RESET} Removed: ${name}`);
}
return removed;
}
// ============================================================================
// INSTALLATION
// ============================================================================
/**
* Execute installation
*/
async function install() {
displaySectionHeader(' INSTALLING SKILLS ');
if (!buildSkills(true)) {
console.log(`${COLORS.RED}${SYMBOLS.ERROR} Failed to build ${SKILLS_DIR_NAME}/ from src/${COLORS.RESET}`);
return 1;
}
console.log(`${COLORS.GREEN}${SYMBOLS.SUCCESS} Built ${SOURCE_PROMPTS.length} skills from src/${COLORS.RESET}`);
if (!ensureSkillsCli()) return 1;
console.log('');
displayStatusBox('PARAMETERS', [
`${COLORS.CYAN}Source:${COLORS.RESET} ${SKILLS_DIR_NAME}/`,
`${COLORS.CYAN}Skills:${COLORS.RESET} ${SOURCE_PROMPTS.length}`,
`${COLORS.CYAN}Scope:${COLORS.RESET} GLOBAL ${COLORS.DIM}(skills.sh default agent set)${COLORS.RESET}`,
`${COLORS.CYAN}Store:${COLORS.RESET} ${path.join(os.homedir(), '.agents', 'skills')}`,
`${COLORS.CYAN}Mode:${COLORS.RESET} INSTALL`,
]);
console.log(`\n${COLORS.YELLOW}${SYMBOLS.ACTIVE} CLEANING PREVIOUS INSTALLS (PLEASE WAIT ⌛)${COLORS.RESET}\n`);
removeInstalledSkills('global');
const legacy = cleanLegacyPaths();
if (legacy.removed > 0) console.log(` ${COLORS.GREEN}${SYMBOLS.SUCCESS}${COLORS.RESET} Cleaned ${legacy.removed} legacy file(s) from pre-2.2 installs`);
console.log(`\n${COLORS.YELLOW}${SYMBOLS.ACTIVE} INSTALLING VIA SKILLS.SH${COLORS.RESET}\n`);
console.log(` ${COLORS.DIM}Installing ${SOURCE_PROMPTS.length} skills...${COLORS.RESET}`);
const result = execSkillsCli(`add "${SKILLS_DIR}" -g ${skillNameArgs()} -y`);
reportSkillsOutput(result);
const failed = !result.ok;
console.log(`\n${COLORS.CYAN}╔═══════════════════════════════════════════════════════════════════════════╗${COLORS.RESET}`);
console.log(`${COLORS.CYAN}║${COLORS.RESET}${' '.repeat(75)}${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}║${COLORS.RESET}${' '.repeat(31)}${COLORS.BRIGHT}S U M M A R Y${COLORS.RESET}${' '.repeat(31)}${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}║${COLORS.RESET}${' '.repeat(75)}${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}╠═══════════════════════════════════════════════════════════════════════════╣${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.GREEN}Mode:${COLORS.RESET} INSTALL`, 76) + `${COLORS.CYAN}║${COLORS.RESET}`);
const statusColor = failed ? COLORS.RED : COLORS.GREEN;
const statusText = failed ? 'FAILED' : 'SUCCESS';
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${statusColor}Status:${COLORS.RESET} ${statusColor}${statusText}${COLORS.RESET}`, 76) + `${COLORS.CYAN}║${COLORS.RESET}`);
const installedNames = failed ? [] : listInstalledSkills('global');
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} Skills Installed: ${COLORS.GREEN}${installedNames.length}${COLORS.RESET}`, 76) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}║${COLORS.RESET}${' '.repeat(75)}${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}╚═══════════════════════════════════════════════════════════════════════════╝${COLORS.RESET}\n`);
if (failed) {
console.log(`${COLORS.RED}${SYMBOLS.ERROR} skills add failed. Re-run, or install by hand:${COLORS.RESET}`);
console.log(` ${COLORS.CYAN}npx --yes skills add "${SKILLS_DIR}" -g ${skillNameArgs()} -y${COLORS.RESET}\n`);
return 1;
}
console.log(`${COLORS.GREEN} ╭───╮${COLORS.RESET} ${COLORS.BRIGHT}All done! Happy coding!${COLORS.RESET}`);
console.log(`${COLORS.GREEN} │ ${COLORS.CYAN}★${COLORS.GREEN} │${COLORS.RESET} ${COLORS.BRIGHT}If this is your first time using Plan2Code, read the docs here:${COLORS.RESET}`);
console.log(`${COLORS.GREEN} │ ${COLORS.BRIGHT}◡${COLORS.GREEN} │${COLORS.RESET} ${COLORS.BRIGHT}https://github.com/jparkerweb/plan2code${COLORS.RESET}`);
console.log(`${COLORS.GREEN} ╰───╯${COLORS.RESET}`);
console.log(`\n${COLORS.DIM} Update later with:${COLORS.RESET} ${COLORS.CYAN}npx skills update -g${COLORS.RESET}\n`);
return 0;
}
// ============================================================================
// UNINSTALLATION
// ============================================================================
/**
* Execute uninstallation
*/
function uninstallSkills() {
displaySectionHeader('UNINSTALLATION', '[ REMOVING SKILLS ]');
console.log('');
displayStatusBox('PARAMETERS', [
`${COLORS.CYAN}Home Directory:${COLORS.RESET} ${os.homedir()}`,
`${COLORS.CYAN}Scope:${COLORS.RESET} GLOBAL`,
`${COLORS.CYAN}Mode:${COLORS.RESET} UNINSTALL`,
]);
let removed = 0;
let errors = 0;
if (ensureSkillsCli()) {
console.log(`\n${COLORS.YELLOW}${SYMBOLS.ACTIVE} REMOVING SKILLS${COLORS.RESET}\n`);
removed += removeInstalledSkills('global');
} else {
errors++;
}
console.log(`\n${COLORS.YELLOW}${SYMBOLS.ACTIVE} CLEANING LEGACY PATHS${COLORS.RESET}\n`);
const legacy = cleanLegacyPaths();
if (legacy.removed === 0) console.log(` ${COLORS.DIM}${SYMBOLS.INFO} Nothing left over from earlier versions${COLORS.RESET}`);
removed += legacy.removed;
errors += legacy.errors;
console.log(`\n${COLORS.CYAN}╔═══════════════════════════════════════════════════════════════════════════╗${COLORS.RESET}`);
console.log(`${COLORS.CYAN}║${COLORS.RESET}${' '.repeat(75)}${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}║${COLORS.RESET}${' '.repeat(31)}${COLORS.BRIGHT}S U M M A R Y${COLORS.RESET}${' '.repeat(31)}${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}║${COLORS.RESET}${' '.repeat(75)}${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}╠═══════════════════════════════════════════════════════════════════════════╣${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.GREEN}Mode:${COLORS.RESET} UNINSTALL`, 76) + `${COLORS.CYAN}║${COLORS.RESET}`);
const statusColor = errors > 0 ? COLORS.RED : COLORS.GREEN;
const statusText = errors > 0 ? 'COMPLETED WITH ERRORS' : 'SUCCESS';
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${statusColor}Status:${COLORS.RESET} ${statusColor}${statusText}${COLORS.RESET}`, 76) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} Items Removed: ${COLORS.GREEN}${removed}${COLORS.RESET}`, 76) + `${COLORS.CYAN}║${COLORS.RESET}`);
if (errors > 0) console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} Errors: ${COLORS.RED}${errors}${COLORS.RESET}`, 76) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}║${COLORS.RESET}${' '.repeat(75)}${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}╚═══════════════════════════════════════════════════════════════════════════╝${COLORS.RESET}\n`);
return errors > 0 ? 1 : 0;
}
// ============================================================================
// PROJECT INSTALLATION
// ============================================================================
/**
* Install skills into the current project instead of globally.
*/
function installProjectSkills() {
const projectDir = process.cwd();
displaySectionHeader('PROJECT INSTALLATION', '[ CURRENT DIRECTORY ]');
if (!buildSkills(true)) {
console.log(`${COLORS.RED}${SYMBOLS.ERROR} Failed to build ${SKILLS_DIR_NAME}/ from src/${COLORS.RESET}`);
return 1;
}
console.log(`${COLORS.GREEN}${SYMBOLS.SUCCESS} Built ${SOURCE_PROMPTS.length} skills from src/${COLORS.RESET}`);
if (!ensureSkillsCli()) return 1;
console.log('');
displayStatusBox('OVERVIEW', [
`Installs into ${COLORS.BRIGHT}this project${COLORS.RESET} rather than your home directory, so the`,
`skills travel with the repo and are visible to everyone who clones it.`,
'',
`${COLORS.CYAN}Project:${COLORS.RESET} ${projectDir}`,
`${COLORS.CYAN}Skills:${COLORS.RESET} ${SOURCE_PROMPTS.length}`,
]);
console.log('');
if (projectDir === __dirname) {
console.log(` ${COLORS.YELLOW}${SYMBOLS.WARNING}${COLORS.RESET} This is the Plan2Code repo itself — installing here is rarely what you want.\n`);
}
console.log(`${COLORS.YELLOW}${SYMBOLS.ACTIVE} INSTALLING VIA SKILLS.SH${COLORS.RESET}\n`);
console.log(` ${COLORS.DIM}Installing ${SOURCE_PROMPTS.length} skills...${COLORS.RESET}`);
const result = execSkillsCli(`add "${SKILLS_DIR}" ${skillNameArgs()} -y`);
reportSkillsOutput(result);
console.log('');
if (!result.ok) {
console.log(`${COLORS.RED}${SYMBOLS.ERROR} skills add failed. Run it by hand from your project root:${COLORS.RESET}`);
console.log(` ${COLORS.CYAN}npx --yes skills add "${SKILLS_DIR}" ${skillNameArgs()} -y${COLORS.RESET}\n`);
return 1;
}
console.log(`${COLORS.GREEN}${SYMBOLS.SUCCESS} Installed into ${projectDir}${COLORS.RESET}\n`);
console.log(`${COLORS.DIM} Check the new directories aren't gitignored, or your agents won't see them.${COLORS.RESET}\n`);
return 0;
}
// ============================================================================
// INTERACTIVE MENU
// ============================================================================
/**
* Run interactive menu interface
*/
function runInteractive() {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const question = (prompt) => new Promise(resolve => rl.question(prompt, resolve));
async function main() {
// Main menu display
displayHeader();
console.log(`${COLORS.BLUE}${COLORS.BRIGHT}Version Info:${COLORS.RESET} ${projectVersion.name} ${projectVersion.version}`);
console.log('');
console.log(`${COLORS.CYAN}╔═════════════════════════════════════════════════════════╗${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}INSTALL PLAN2CODE${COLORS.RESET}`, 58) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}╠═════════════════════════════════════════════════════════╣${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}I.${COLORS.RESET} ${COLORS.GREEN}INSTALL${COLORS.RESET} Install Plan2Code skills everywhere`, 58) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}A.${COLORS.RESET} ${COLORS.MAGENTA}ALL${COLORS.RESET} Install Plan2Code + dev tools`, 58) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}U.${COLORS.RESET} ${COLORS.RED}UNINSTALL${COLORS.RESET} Remove Plan2Code skills and dev tools`, 58) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}C.${COLORS.RESET} ${COLORS.BLUE}CUSTOM${COLORS.RESET} Advanced options`, 58) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}Q.${COLORS.RESET} ${COLORS.DIM}QUIT${COLORS.RESET} Exit`, 58) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}╚═════════════════════════════════════════════════════════╝${COLORS.RESET}`);
console.log('');
// Input prompt
console.log('');
const answer = await question(`${COLORS.CYAN}${SYMBOLS.SELECT} SELECT OPTION${COLORS.RESET} (I, A, U, C, Q) [I]: `);
const input = answer.trim().toUpperCase() || 'I';
// I path — skills only. The loop remains optional via A or Custom → O.
if (input === 'I') {
rl.close();
process.exit(await install());
}
// A path — Install Everything (skills + loop + bot + metrics + Claude status line)
if (input === 'A') {
rl.close();
const loopResult = installPlan2CodeLoop();
console.log('');
const botResult = installPlan2CodeBot();
console.log('');
const metricsResult = installPlan2CodeMetrics();
console.log('');
const statusLineResult = await installStatusLine();
console.log('');
const installResult = await install();
const exitCode = loopResult !== 0 ? loopResult : botResult !== 0 ? botResult : metricsResult !== 0 ? metricsResult : statusLineResult !== 0 ? statusLineResult : installResult;
process.exit(exitCode);
}
// U path — Uninstall All
if (input === 'U') {
console.log('');
console.log(`${COLORS.RED} ╭───╮${COLORS.RESET}`);
console.log(`${COLORS.RED} │ ${COLORS.YELLOW}○${COLORS.RED} │${COLORS.RESET} ${COLORS.YELLOW}!${COLORS.RESET}`);
console.log(`${COLORS.RED} │ ${COLORS.YELLOW}~${COLORS.RED} │${COLORS.RESET} ${COLORS.DIM}Are you sure? This will remove Plan2Code from all platforms.${COLORS.RESET}`);
console.log(`${COLORS.RED} ╰───╯${COLORS.RESET}`);
console.log('');
const confirmAnswer = await question(`${COLORS.RED}${SYMBOLS.SELECT} CONFIRM UNINSTALL${COLORS.RESET} (Y/N) [N]: `);
const confirmInput = confirmAnswer.trim().toUpperCase() || 'N';
if (confirmInput === 'Y') {
rl.close();
const uninstallResult = uninstallSkills();
const loopResult = uninstallPlan2CodeLoop();
const metricsResult = uninstallPlan2CodeMetrics();
const botResult = uninstallPlan2CodeBot();
const statusLineResult = uninstallStatusLine();
const exitCode = uninstallResult !== 0 ? uninstallResult : loopResult !== 0 ? loopResult : metricsResult !== 0 ? metricsResult : botResult !== 0 ? botResult : statusLineResult;
process.exit(exitCode);
} else {
console.log(`\n${COLORS.YELLOW}${SYMBOLS.WARNING} CANCELLED${COLORS.RESET}\n`);
rl.close();
process.exit(0);
}
}
// C path — CUSTOM sub-menu
if (input === 'C') {
console.log('');
console.log(`${COLORS.CYAN}╔════════════════════════════════════════════════════════════════╗${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}CUSTOM OPTIONS${COLORS.RESET}`, 65) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}╠════════════════════════════════════════════════════════════════╣${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}L.${COLORS.RESET} ${COLORS.BLUE}LOCAL${COLORS.RESET} Install skills into the current project only`, 65) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}O.${COLORS.RESET} ${COLORS.GREEN}LOOP CLI${COLORS.RESET} Install plan2code-loop CLI only`, 65) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}M.${COLORS.RESET} ${COLORS.GREEN}METRICS${COLORS.RESET} Install plan2code-metrics CLI only`, 65) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}S.${COLORS.RESET} ${COLORS.GREEN}STATUS${COLORS.RESET} Install Claude Code status line`, 65) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}B.${COLORS.RESET} ${COLORS.GREEN}BOT${COLORS.RESET} Install plan2code-bot CLI only`, 65) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(padEndVisible(`${COLORS.CYAN}║${COLORS.RESET} ${COLORS.BRIGHT}Q.${COLORS.RESET} ${COLORS.DIM}BACK${COLORS.RESET} Return to main menu`, 65) + `${COLORS.CYAN}║${COLORS.RESET}`);
console.log(`${COLORS.CYAN}╚════════════════════════════════════════════════════════════════╝${COLORS.RESET}`);
console.log('');
const customAnswer = await question(`${COLORS.CYAN}${SYMBOLS.SELECT} SELECT OPTION${COLORS.RESET} (L, O, M, S, B, Q) [Q]: `);
const customInput = customAnswer.trim().toUpperCase() || 'Q';
// C > L — install skills into the current project
if (customInput === 'L') {
rl.close();
process.exit(installProjectSkills());
}
// C > O — install loop CLI only
if (customInput === 'O') {
rl.close();
const result = installPlan2CodeLoop();
process.exit(result);
}
// C > M — install metrics CLI only
if (customInput === 'M') {
rl.close();
const result = installPlan2CodeMetrics();
process.exit(result);
}
// C > S — install status line
if (customInput === 'S') {
rl.close();
const result = await installStatusLine();
process.exit(result);
}
// C > B — install bot CLI only
if (customInput === 'B') {
rl.close();
const result = installPlan2CodeBot();
process.exit(result);
}
// C > Q — back to main menu
return main();
}
// Q — exit
if (input === 'Q') {
console.log(`\n${COLORS.YELLOW}${SYMBOLS.WARNING} CANCELLED${COLORS.RESET}\n`);
rl.close();
process.exit(0);
}
// Invalid input — loop back
console.log(`\n${COLORS.RED}${SYMBOLS.ERROR} Invalid option. Please choose I, A, U, C, or Q.${COLORS.RESET}\n`);
return main();
}
main().catch(err => {
console.error(`${COLORS.RED}${SYMBOLS.ERROR} ERROR:${COLORS.RESET}`, err.message);
rl.close();
process.exit(1);
});
}