cc4pm 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/.claude-plugin/README.md +17 -0
  2. package/.claude-plugin/plugin.json +25 -0
  3. package/LICENSE +21 -0
  4. package/README.md +157 -0
  5. package/README.zh-CN.md +134 -0
  6. package/contexts/dev.md +20 -0
  7. package/contexts/research.md +26 -0
  8. package/contexts/review.md +22 -0
  9. package/examples/CLAUDE.md +100 -0
  10. package/examples/statusline.json +19 -0
  11. package/examples/user-CLAUDE.md +109 -0
  12. package/install.sh +17 -0
  13. package/manifests/install-components.json +173 -0
  14. package/manifests/install-modules.json +335 -0
  15. package/manifests/install-profiles.json +75 -0
  16. package/package.json +117 -0
  17. package/schemas/ecc-install-config.schema.json +58 -0
  18. package/schemas/hooks.schema.json +197 -0
  19. package/schemas/install-components.schema.json +56 -0
  20. package/schemas/install-modules.schema.json +105 -0
  21. package/schemas/install-profiles.schema.json +45 -0
  22. package/schemas/install-state.schema.json +210 -0
  23. package/schemas/package-manager.schema.json +23 -0
  24. package/schemas/plugin.schema.json +58 -0
  25. package/scripts/ci/catalog.js +83 -0
  26. package/scripts/ci/validate-agents.js +81 -0
  27. package/scripts/ci/validate-commands.js +135 -0
  28. package/scripts/ci/validate-hooks.js +239 -0
  29. package/scripts/ci/validate-install-manifests.js +211 -0
  30. package/scripts/ci/validate-no-personal-paths.js +63 -0
  31. package/scripts/ci/validate-rules.js +81 -0
  32. package/scripts/ci/validate-skills.js +54 -0
  33. package/scripts/claw.js +468 -0
  34. package/scripts/doctor.js +110 -0
  35. package/scripts/ecc.js +194 -0
  36. package/scripts/hooks/auto-tmux-dev.js +88 -0
  37. package/scripts/hooks/check-console-log.js +71 -0
  38. package/scripts/hooks/check-hook-enabled.js +12 -0
  39. package/scripts/hooks/cost-tracker.js +78 -0
  40. package/scripts/hooks/doc-file-warning.js +63 -0
  41. package/scripts/hooks/evaluate-session.js +100 -0
  42. package/scripts/hooks/insaits-security-monitor.py +269 -0
  43. package/scripts/hooks/insaits-security-wrapper.js +88 -0
  44. package/scripts/hooks/post-bash-build-complete.js +27 -0
  45. package/scripts/hooks/post-bash-pr-created.js +36 -0
  46. package/scripts/hooks/post-edit-console-warn.js +54 -0
  47. package/scripts/hooks/post-edit-format.js +109 -0
  48. package/scripts/hooks/post-edit-typecheck.js +96 -0
  49. package/scripts/hooks/pre-bash-dev-server-block.js +187 -0
  50. package/scripts/hooks/pre-bash-git-push-reminder.js +28 -0
  51. package/scripts/hooks/pre-bash-tmux-reminder.js +33 -0
  52. package/scripts/hooks/pre-compact.js +48 -0
  53. package/scripts/hooks/pre-write-doc-warn.js +9 -0
  54. package/scripts/hooks/quality-gate.js +168 -0
  55. package/scripts/hooks/run-with-flags-shell.sh +32 -0
  56. package/scripts/hooks/run-with-flags.js +120 -0
  57. package/scripts/hooks/session-end-marker.js +15 -0
  58. package/scripts/hooks/session-end.js +299 -0
  59. package/scripts/hooks/session-start.js +97 -0
  60. package/scripts/hooks/suggest-compact.js +80 -0
  61. package/scripts/install-apply.js +137 -0
  62. package/scripts/install-plan.js +254 -0
  63. package/scripts/lib/hook-flags.js +74 -0
  64. package/scripts/lib/install/apply.js +23 -0
  65. package/scripts/lib/install/config.js +82 -0
  66. package/scripts/lib/install/request.js +113 -0
  67. package/scripts/lib/install/runtime.js +42 -0
  68. package/scripts/lib/install-executor.js +605 -0
  69. package/scripts/lib/install-lifecycle.js +763 -0
  70. package/scripts/lib/install-manifests.js +305 -0
  71. package/scripts/lib/install-state.js +120 -0
  72. package/scripts/lib/install-targets/antigravity-project.js +9 -0
  73. package/scripts/lib/install-targets/claude-home.js +10 -0
  74. package/scripts/lib/install-targets/codex-home.js +10 -0
  75. package/scripts/lib/install-targets/cursor-project.js +10 -0
  76. package/scripts/lib/install-targets/helpers.js +89 -0
  77. package/scripts/lib/install-targets/opencode-home.js +10 -0
  78. package/scripts/lib/install-targets/registry.js +64 -0
  79. package/scripts/lib/orchestration-session.js +299 -0
  80. package/scripts/lib/package-manager.d.ts +119 -0
  81. package/scripts/lib/package-manager.js +431 -0
  82. package/scripts/lib/project-detect.js +428 -0
  83. package/scripts/lib/resolve-formatter.js +185 -0
  84. package/scripts/lib/session-adapters/canonical-session.js +138 -0
  85. package/scripts/lib/session-adapters/claude-history.js +149 -0
  86. package/scripts/lib/session-adapters/dmux-tmux.js +80 -0
  87. package/scripts/lib/session-adapters/registry.js +111 -0
  88. package/scripts/lib/session-aliases.d.ts +136 -0
  89. package/scripts/lib/session-aliases.js +481 -0
  90. package/scripts/lib/session-manager.d.ts +131 -0
  91. package/scripts/lib/session-manager.js +464 -0
  92. package/scripts/lib/shell-split.js +86 -0
  93. package/scripts/lib/skill-improvement/amendify.js +89 -0
  94. package/scripts/lib/skill-improvement/evaluate.js +59 -0
  95. package/scripts/lib/skill-improvement/health.js +118 -0
  96. package/scripts/lib/skill-improvement/observations.js +108 -0
  97. package/scripts/lib/tmux-worktree-orchestrator.js +491 -0
  98. package/scripts/lib/utils.d.ts +183 -0
  99. package/scripts/lib/utils.js +543 -0
  100. package/scripts/list-installed.js +90 -0
  101. package/scripts/orchestrate-codex-worker.sh +92 -0
  102. package/scripts/orchestrate-worktrees.js +108 -0
  103. package/scripts/orchestration-status.js +62 -0
  104. package/scripts/repair.js +97 -0
  105. package/scripts/session-inspect.js +150 -0
  106. package/scripts/setup-package-manager.js +204 -0
  107. package/scripts/skill-create-output.js +244 -0
  108. package/scripts/uninstall.js +96 -0
@@ -0,0 +1,543 @@
1
+ /**
2
+ * Cross-platform utility functions for Claude Code hooks and scripts
3
+ * Works on Windows, macOS, and Linux
4
+ */
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const os = require('os');
9
+ const { execSync, spawnSync } = require('child_process');
10
+
11
+ // Platform detection
12
+ const isWindows = process.platform === 'win32';
13
+ const isMacOS = process.platform === 'darwin';
14
+ const isLinux = process.platform === 'linux';
15
+
16
+ /**
17
+ * Get the user's home directory (cross-platform)
18
+ */
19
+ function getHomeDir() {
20
+ return os.homedir();
21
+ }
22
+
23
+ /**
24
+ * Get the Claude config directory
25
+ */
26
+ function getClaudeDir() {
27
+ return path.join(getHomeDir(), '.claude');
28
+ }
29
+
30
+ /**
31
+ * Get the sessions directory
32
+ */
33
+ function getSessionsDir() {
34
+ return path.join(getClaudeDir(), 'sessions');
35
+ }
36
+
37
+ /**
38
+ * Get the learned skills directory
39
+ */
40
+ function getLearnedSkillsDir() {
41
+ return path.join(getClaudeDir(), 'skills', 'learned');
42
+ }
43
+
44
+ /**
45
+ * Get the temp directory (cross-platform)
46
+ */
47
+ function getTempDir() {
48
+ return os.tmpdir();
49
+ }
50
+
51
+ /**
52
+ * Ensure a directory exists (create if not)
53
+ * @param {string} dirPath - Directory path to create
54
+ * @returns {string} The directory path
55
+ * @throws {Error} If directory cannot be created (e.g., permission denied)
56
+ */
57
+ function ensureDir(dirPath) {
58
+ try {
59
+ if (!fs.existsSync(dirPath)) {
60
+ fs.mkdirSync(dirPath, { recursive: true });
61
+ }
62
+ } catch (err) {
63
+ // EEXIST is fine (race condition with another process creating it)
64
+ if (err.code !== 'EEXIST') {
65
+ throw new Error(`Failed to create directory '${dirPath}': ${err.message}`);
66
+ }
67
+ }
68
+ return dirPath;
69
+ }
70
+
71
+ /**
72
+ * Get current date in YYYY-MM-DD format
73
+ */
74
+ function getDateString() {
75
+ const now = new Date();
76
+ const year = now.getFullYear();
77
+ const month = String(now.getMonth() + 1).padStart(2, '0');
78
+ const day = String(now.getDate()).padStart(2, '0');
79
+ return `${year}-${month}-${day}`;
80
+ }
81
+
82
+ /**
83
+ * Get current time in HH:MM format
84
+ */
85
+ function getTimeString() {
86
+ const now = new Date();
87
+ const hours = String(now.getHours()).padStart(2, '0');
88
+ const minutes = String(now.getMinutes()).padStart(2, '0');
89
+ return `${hours}:${minutes}`;
90
+ }
91
+
92
+ /**
93
+ * Get the git repository name
94
+ */
95
+ function getGitRepoName() {
96
+ const result = runCommand('git rev-parse --show-toplevel');
97
+ if (!result.success) return null;
98
+ return path.basename(result.output);
99
+ }
100
+
101
+ /**
102
+ * Get project name from git repo or current directory
103
+ */
104
+ function getProjectName() {
105
+ const repoName = getGitRepoName();
106
+ if (repoName) return repoName;
107
+ return path.basename(process.cwd()) || null;
108
+ }
109
+
110
+ /**
111
+ * Get short session ID from CLAUDE_SESSION_ID environment variable
112
+ * Returns last 8 characters, falls back to project name then 'default'
113
+ */
114
+ function getSessionIdShort(fallback = 'default') {
115
+ const sessionId = process.env.CLAUDE_SESSION_ID;
116
+ if (sessionId && sessionId.length > 0) {
117
+ return sessionId.slice(-8);
118
+ }
119
+ return getProjectName() || fallback;
120
+ }
121
+
122
+ /**
123
+ * Get current datetime in YYYY-MM-DD HH:MM:SS format
124
+ */
125
+ function getDateTimeString() {
126
+ const now = new Date();
127
+ const year = now.getFullYear();
128
+ const month = String(now.getMonth() + 1).padStart(2, '0');
129
+ const day = String(now.getDate()).padStart(2, '0');
130
+ const hours = String(now.getHours()).padStart(2, '0');
131
+ const minutes = String(now.getMinutes()).padStart(2, '0');
132
+ const seconds = String(now.getSeconds()).padStart(2, '0');
133
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
134
+ }
135
+
136
+ /**
137
+ * Find files matching a pattern in a directory (cross-platform alternative to find)
138
+ * @param {string} dir - Directory to search
139
+ * @param {string} pattern - File pattern (e.g., "*.tmp", "*.md")
140
+ * @param {object} options - Options { maxAge: days, recursive: boolean }
141
+ */
142
+ function findFiles(dir, pattern, options = {}) {
143
+ if (!dir || typeof dir !== 'string') return [];
144
+ if (!pattern || typeof pattern !== 'string') return [];
145
+
146
+ const { maxAge = null, recursive = false } = options;
147
+ const results = [];
148
+
149
+ if (!fs.existsSync(dir)) {
150
+ return results;
151
+ }
152
+
153
+ // Escape all regex special characters, then convert glob wildcards.
154
+ // Order matters: escape specials first, then convert * and ? to regex equivalents.
155
+ const regexPattern = pattern
156
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&')
157
+ .replace(/\*/g, '.*')
158
+ .replace(/\?/g, '.');
159
+ const regex = new RegExp(`^${regexPattern}$`);
160
+
161
+ function searchDir(currentDir) {
162
+ try {
163
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
164
+
165
+ for (const entry of entries) {
166
+ const fullPath = path.join(currentDir, entry.name);
167
+
168
+ if (entry.isFile() && regex.test(entry.name)) {
169
+ let stats;
170
+ try {
171
+ stats = fs.statSync(fullPath);
172
+ } catch {
173
+ continue; // File deleted between readdir and stat
174
+ }
175
+
176
+ if (maxAge !== null) {
177
+ const ageInDays = (Date.now() - stats.mtimeMs) / (1000 * 60 * 60 * 24);
178
+ if (ageInDays <= maxAge) {
179
+ results.push({ path: fullPath, mtime: stats.mtimeMs });
180
+ }
181
+ } else {
182
+ results.push({ path: fullPath, mtime: stats.mtimeMs });
183
+ }
184
+ } else if (entry.isDirectory() && recursive) {
185
+ searchDir(fullPath);
186
+ }
187
+ }
188
+ } catch (_err) {
189
+ // Ignore permission errors
190
+ }
191
+ }
192
+
193
+ searchDir(dir);
194
+
195
+ // Sort by modification time (newest first)
196
+ results.sort((a, b) => b.mtime - a.mtime);
197
+
198
+ return results;
199
+ }
200
+
201
+ /**
202
+ * Read JSON from stdin (for hook input)
203
+ * @param {object} options - Options
204
+ * @param {number} options.timeoutMs - Timeout in milliseconds (default: 5000).
205
+ * Prevents hooks from hanging indefinitely if stdin never closes.
206
+ * @returns {Promise<object>} Parsed JSON object, or empty object if stdin is empty
207
+ */
208
+ async function readStdinJson(options = {}) {
209
+ const { timeoutMs = 5000, maxSize = 1024 * 1024 } = options;
210
+
211
+ return new Promise((resolve) => {
212
+ let data = '';
213
+ let settled = false;
214
+
215
+ const timer = setTimeout(() => {
216
+ if (!settled) {
217
+ settled = true;
218
+ // Clean up stdin listeners so the event loop can exit
219
+ process.stdin.removeAllListeners('data');
220
+ process.stdin.removeAllListeners('end');
221
+ process.stdin.removeAllListeners('error');
222
+ if (process.stdin.unref) process.stdin.unref();
223
+ // Resolve with whatever we have so far rather than hanging
224
+ try {
225
+ resolve(data.trim() ? JSON.parse(data) : {});
226
+ } catch {
227
+ resolve({});
228
+ }
229
+ }
230
+ }, timeoutMs);
231
+
232
+ process.stdin.setEncoding('utf8');
233
+ process.stdin.on('data', chunk => {
234
+ if (data.length < maxSize) {
235
+ data += chunk;
236
+ }
237
+ });
238
+
239
+ process.stdin.on('end', () => {
240
+ if (settled) return;
241
+ settled = true;
242
+ clearTimeout(timer);
243
+ try {
244
+ resolve(data.trim() ? JSON.parse(data) : {});
245
+ } catch {
246
+ // Consistent with timeout path: resolve with empty object
247
+ // so hooks don't crash on malformed input
248
+ resolve({});
249
+ }
250
+ });
251
+
252
+ process.stdin.on('error', () => {
253
+ if (settled) return;
254
+ settled = true;
255
+ clearTimeout(timer);
256
+ // Resolve with empty object so hooks don't crash on stdin errors
257
+ resolve({});
258
+ });
259
+ });
260
+ }
261
+
262
+ /**
263
+ * Log to stderr (visible to user in Claude Code)
264
+ */
265
+ function log(message) {
266
+ console.error(message);
267
+ }
268
+
269
+ /**
270
+ * Output to stdout (returned to Claude)
271
+ */
272
+ function output(data) {
273
+ if (typeof data === 'object') {
274
+ console.log(JSON.stringify(data));
275
+ } else {
276
+ console.log(data);
277
+ }
278
+ }
279
+
280
+ /**
281
+ * Read a text file safely
282
+ */
283
+ function readFile(filePath) {
284
+ try {
285
+ return fs.readFileSync(filePath, 'utf8');
286
+ } catch {
287
+ return null;
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Write a text file
293
+ */
294
+ function writeFile(filePath, content) {
295
+ ensureDir(path.dirname(filePath));
296
+ fs.writeFileSync(filePath, content, 'utf8');
297
+ }
298
+
299
+ /**
300
+ * Append to a text file
301
+ */
302
+ function appendFile(filePath, content) {
303
+ ensureDir(path.dirname(filePath));
304
+ fs.appendFileSync(filePath, content, 'utf8');
305
+ }
306
+
307
+ /**
308
+ * Check if a command exists in PATH
309
+ * Uses execFileSync to prevent command injection
310
+ */
311
+ function commandExists(cmd) {
312
+ // Validate command name - only allow alphanumeric, dash, underscore, dot
313
+ if (!/^[a-zA-Z0-9_.-]+$/.test(cmd)) {
314
+ return false;
315
+ }
316
+
317
+ try {
318
+ if (isWindows) {
319
+ // Use spawnSync to avoid shell interpolation
320
+ const result = spawnSync('where', [cmd], { stdio: 'pipe' });
321
+ return result.status === 0;
322
+ } else {
323
+ const result = spawnSync('which', [cmd], { stdio: 'pipe' });
324
+ return result.status === 0;
325
+ }
326
+ } catch {
327
+ return false;
328
+ }
329
+ }
330
+
331
+ /**
332
+ * Run a command and return output
333
+ *
334
+ * SECURITY NOTE: This function executes shell commands. Only use with
335
+ * trusted, hardcoded commands. Never pass user-controlled input directly.
336
+ * For user input, use spawnSync with argument arrays instead.
337
+ *
338
+ * @param {string} cmd - Command to execute (should be trusted/hardcoded)
339
+ * @param {object} options - execSync options
340
+ */
341
+ function runCommand(cmd, options = {}) {
342
+ // Allowlist: only permit known-safe command prefixes
343
+ const allowedPrefixes = ['git ', 'node ', 'npx ', 'which ', 'where '];
344
+ if (!allowedPrefixes.some(prefix => cmd.startsWith(prefix))) {
345
+ return { success: false, output: 'runCommand blocked: unrecognized command prefix' };
346
+ }
347
+
348
+ // Reject shell metacharacters. $() and backticks are evaluated inside
349
+ // double quotes, so block $ and ` anywhere in cmd. Other operators
350
+ // (;|&) are literal inside quotes, so only check unquoted portions.
351
+ const unquoted = cmd.replace(/"[^"]*"/g, '').replace(/'[^']*'/g, '');
352
+ if (/[;|&\n]/.test(unquoted) || /[`$]/.test(cmd)) {
353
+ return { success: false, output: 'runCommand blocked: shell metacharacters not allowed' };
354
+ }
355
+
356
+ try {
357
+ const result = execSync(cmd, {
358
+ encoding: 'utf8',
359
+ stdio: ['pipe', 'pipe', 'pipe'],
360
+ ...options
361
+ });
362
+ return { success: true, output: result.trim() };
363
+ } catch (err) {
364
+ return { success: false, output: err.stderr || err.message };
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Check if current directory is a git repository
370
+ */
371
+ function isGitRepo() {
372
+ return runCommand('git rev-parse --git-dir').success;
373
+ }
374
+
375
+ /**
376
+ * Get git modified files, optionally filtered by regex patterns
377
+ * @param {string[]} patterns - Array of regex pattern strings to filter files.
378
+ * Invalid patterns are silently skipped.
379
+ * @returns {string[]} Array of modified file paths
380
+ */
381
+ function getGitModifiedFiles(patterns = []) {
382
+ if (!isGitRepo()) return [];
383
+
384
+ const result = runCommand('git diff --name-only HEAD');
385
+ if (!result.success) return [];
386
+
387
+ let files = result.output.split('\n').filter(Boolean);
388
+
389
+ if (patterns.length > 0) {
390
+ // Pre-compile patterns, skipping invalid ones
391
+ const compiled = [];
392
+ for (const pattern of patterns) {
393
+ if (typeof pattern !== 'string' || pattern.length === 0) continue;
394
+ try {
395
+ compiled.push(new RegExp(pattern));
396
+ } catch {
397
+ // Skip invalid regex patterns
398
+ }
399
+ }
400
+ if (compiled.length > 0) {
401
+ files = files.filter(file => compiled.some(regex => regex.test(file)));
402
+ }
403
+ }
404
+
405
+ return files;
406
+ }
407
+
408
+ /**
409
+ * Replace text in a file (cross-platform sed alternative)
410
+ * @param {string} filePath - Path to the file
411
+ * @param {string|RegExp} search - Pattern to search for. String patterns replace
412
+ * the FIRST occurrence only; use a RegExp with the `g` flag for global replacement.
413
+ * @param {string} replace - Replacement string
414
+ * @param {object} options - Options
415
+ * @param {boolean} options.all - When true and search is a string, replaces ALL
416
+ * occurrences (uses String.replaceAll). Ignored for RegExp patterns.
417
+ * @returns {boolean} true if file was written, false on error
418
+ */
419
+ function replaceInFile(filePath, search, replace, options = {}) {
420
+ const content = readFile(filePath);
421
+ if (content === null) return false;
422
+
423
+ try {
424
+ let newContent;
425
+ if (options.all && typeof search === 'string') {
426
+ newContent = content.replaceAll(search, replace);
427
+ } else {
428
+ newContent = content.replace(search, replace);
429
+ }
430
+ writeFile(filePath, newContent);
431
+ return true;
432
+ } catch (err) {
433
+ log(`[Utils] replaceInFile failed for ${filePath}: ${err.message}`);
434
+ return false;
435
+ }
436
+ }
437
+
438
+ /**
439
+ * Count occurrences of a pattern in a file
440
+ * @param {string} filePath - Path to the file
441
+ * @param {string|RegExp} pattern - Pattern to count. Strings are treated as
442
+ * global regex patterns. RegExp instances are used as-is but the global
443
+ * flag is enforced to ensure correct counting.
444
+ * @returns {number} Number of matches found
445
+ */
446
+ function countInFile(filePath, pattern) {
447
+ const content = readFile(filePath);
448
+ if (content === null) return 0;
449
+
450
+ let regex;
451
+ try {
452
+ if (pattern instanceof RegExp) {
453
+ // Always create new RegExp to avoid shared lastIndex state; ensure global flag
454
+ regex = new RegExp(pattern.source, pattern.flags.includes('g') ? pattern.flags : pattern.flags + 'g');
455
+ } else if (typeof pattern === 'string') {
456
+ regex = new RegExp(pattern, 'g');
457
+ } else {
458
+ return 0;
459
+ }
460
+ } catch {
461
+ return 0; // Invalid regex pattern
462
+ }
463
+ const matches = content.match(regex);
464
+ return matches ? matches.length : 0;
465
+ }
466
+
467
+ /**
468
+ * Search for pattern in file and return matching lines with line numbers
469
+ */
470
+ function grepFile(filePath, pattern) {
471
+ const content = readFile(filePath);
472
+ if (content === null) return [];
473
+
474
+ let regex;
475
+ try {
476
+ if (pattern instanceof RegExp) {
477
+ // Always create a new RegExp without the 'g' flag to prevent lastIndex
478
+ // state issues when using .test() in a loop (g flag makes .test() stateful,
479
+ // causing alternating match/miss on consecutive matching lines)
480
+ const flags = pattern.flags.replace('g', '');
481
+ regex = new RegExp(pattern.source, flags);
482
+ } else {
483
+ regex = new RegExp(pattern);
484
+ }
485
+ } catch {
486
+ return []; // Invalid regex pattern
487
+ }
488
+ const lines = content.split('\n');
489
+ const results = [];
490
+
491
+ lines.forEach((line, index) => {
492
+ if (regex.test(line)) {
493
+ results.push({ lineNumber: index + 1, content: line });
494
+ }
495
+ });
496
+
497
+ return results;
498
+ }
499
+
500
+ module.exports = {
501
+ // Platform info
502
+ isWindows,
503
+ isMacOS,
504
+ isLinux,
505
+
506
+ // Directories
507
+ getHomeDir,
508
+ getClaudeDir,
509
+ getSessionsDir,
510
+ getLearnedSkillsDir,
511
+ getTempDir,
512
+ ensureDir,
513
+
514
+ // Date/Time
515
+ getDateString,
516
+ getTimeString,
517
+ getDateTimeString,
518
+
519
+ // Session/Project
520
+ getSessionIdShort,
521
+ getGitRepoName,
522
+ getProjectName,
523
+
524
+ // File operations
525
+ findFiles,
526
+ readFile,
527
+ writeFile,
528
+ appendFile,
529
+ replaceInFile,
530
+ countInFile,
531
+ grepFile,
532
+
533
+ // Hook I/O
534
+ readStdinJson,
535
+ log,
536
+ output,
537
+
538
+ // System
539
+ commandExists,
540
+ runCommand,
541
+ isGitRepo,
542
+ getGitModifiedFiles
543
+ };
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { discoverInstalledStates } = require('./lib/install-lifecycle');
4
+ const { SUPPORTED_INSTALL_TARGETS } = require('./lib/install-manifests');
5
+
6
+ function showHelp(exitCode = 0) {
7
+ console.log(`
8
+ Usage: node scripts/list-installed.js [--target <${SUPPORTED_INSTALL_TARGETS.join('|')}>] [--json]
9
+
10
+ Inspect cc4pm install-state files for the current home/project context.
11
+ `);
12
+ process.exit(exitCode);
13
+ }
14
+
15
+ function parseArgs(argv) {
16
+ const args = argv.slice(2);
17
+ const parsed = {
18
+ targets: [],
19
+ json: false,
20
+ help: false,
21
+ };
22
+
23
+ for (let index = 0; index < args.length; index += 1) {
24
+ const arg = args[index];
25
+
26
+ if (arg === '--target') {
27
+ parsed.targets.push(args[index + 1] || null);
28
+ index += 1;
29
+ } else if (arg === '--json') {
30
+ parsed.json = true;
31
+ } else if (arg === '--help' || arg === '-h') {
32
+ parsed.help = true;
33
+ } else {
34
+ throw new Error(`Unknown argument: ${arg}`);
35
+ }
36
+ }
37
+
38
+ return parsed;
39
+ }
40
+
41
+ function printHuman(records) {
42
+ if (records.length === 0) {
43
+ console.log('No cc4pm install-state files found for the current home/project context.');
44
+ return;
45
+ }
46
+
47
+ console.log('Installed cc4pm targets:\n');
48
+ for (const record of records) {
49
+ if (record.error) {
50
+ console.log(`- ${record.adapter.id}: INVALID (${record.error})`);
51
+ continue;
52
+ }
53
+
54
+ const state = record.state;
55
+ console.log(`- ${record.adapter.id}`);
56
+ console.log(` Root: ${state.target.root}`);
57
+ console.log(` Installed: ${state.installedAt}`);
58
+ console.log(` Profile: ${state.request.profile || '(legacy/custom)'}`);
59
+ console.log(` Modules: ${(state.resolution.selectedModules || []).join(', ') || '(none)'}`);
60
+ console.log(` Legacy languages: ${(state.request.legacyLanguages || []).join(', ') || '(none)'}`);
61
+ console.log(` Source version: ${state.source.repoVersion || '(unknown)'}`);
62
+ }
63
+ }
64
+
65
+ function main() {
66
+ try {
67
+ const options = parseArgs(process.argv);
68
+ if (options.help) {
69
+ showHelp(0);
70
+ }
71
+
72
+ const records = discoverInstalledStates({
73
+ homeDir: process.env.HOME,
74
+ projectRoot: process.cwd(),
75
+ targets: options.targets,
76
+ }).filter(record => record.exists);
77
+
78
+ if (options.json) {
79
+ console.log(JSON.stringify({ records }, null, 2));
80
+ return;
81
+ }
82
+
83
+ printHuman(records);
84
+ } catch (error) {
85
+ console.error(`Error: ${error.message}`);
86
+ process.exit(1);
87
+ }
88
+ }
89
+
90
+ main();