@chemx/starter-kit 26.9.9-786 → 26.9.11-481

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 (45) hide show
  1. package/cli/audit/ast-visitors.js +243 -0
  2. package/cli/audit/discussion-store.js +39 -0
  3. package/cli/audit/history.d.ts +69 -0
  4. package/cli/audit/history.js +397 -0
  5. package/cli/audit/metrics.js +179 -0
  6. package/cli/audit/prompts.js +174 -0
  7. package/cli/audit/reporter-ascii.d.ts +4 -0
  8. package/cli/audit/reporter-ascii.js +99 -0
  9. package/cli/audit/reporter-grades.js +275 -0
  10. package/cli/audit/reporter-markdown.js +137 -0
  11. package/cli/audit/reporter-utils.js +125 -0
  12. package/cli/audit/reporter.js +497 -0
  13. package/cli/audit/rules-helpers.js +109 -0
  14. package/cli/audit/rules-registry.js +97 -0
  15. package/cli/audit/rules.js +123 -0
  16. package/cli/audit/social-constants.js +4 -0
  17. package/cli/audit/social-gh.js +126 -0
  18. package/cli/audit/social-git.js +214 -0
  19. package/cli/audit/social-http.js +222 -0
  20. package/cli/audit/social-publisher.js +193 -0
  21. package/cli/audit/social.d.ts +69 -0
  22. package/cli/audit/social.js +303 -0
  23. package/cli/audit/types.d.ts +140 -0
  24. package/cli/audit.d.ts +3 -24
  25. package/cli/audit.js +207 -210
  26. package/cli/help.d.ts +1 -0
  27. package/cli/help.js +136 -0
  28. package/cli/index.js +128 -566
  29. package/cli/installer-templates.js +91 -0
  30. package/cli/installer.d.ts +21 -0
  31. package/cli/installer.js +104 -0
  32. package/cli/license.js +320 -0
  33. package/cli/navigator-actions.js +274 -0
  34. package/cli/navigator-banner.js +98 -0
  35. package/cli/navigator-conversion.js +100 -0
  36. package/cli/navigator-grades.js +87 -0
  37. package/cli/navigator-menu.js +127 -0
  38. package/cli/navigator-paged.js +86 -0
  39. package/cli/navigator-share.js +129 -0
  40. package/cli/navigator.d.ts +43 -0
  41. package/cli/navigator.js +126 -0
  42. package/cli/scaffold.js +148 -0
  43. package/cli/terminal.js +126 -0
  44. package/docs/CHANGELOG.md +101 -0
  45. package/package.json +11 -10
@@ -0,0 +1,137 @@
1
+ import { buildMasterPrompt } from './prompts.js';
2
+ import {
3
+ groupViolationsBySeverity,
4
+ resolveHealthHearts,
5
+ resolveMarkdownStatusIcon,
6
+ resolveMarkdownMonolithText,
7
+ PILLAR_EMOJIS,
8
+ NUMBER_EMOJIS
9
+ } from './reporter-utils.js';
10
+
11
+ export const generateMarkdownReport = (report) => {
12
+ const { metrics, health, pillars, contextAnalysis, hotspots, violations } = report;
13
+ const { critical, high, medium, low } = groupViolationsBySeverity(violations);
14
+ const lines = [];
15
+
16
+ lines.push('# Chemical X Protocol: Architectural Audit Report');
17
+ lines.push('');
18
+ lines.push('> *Comprehensive static analysis report enforcing Chemical X Molecular Architecture standards.*');
19
+ lines.push('');
20
+ lines.push('## 1. Executive Summary & Scorecard');
21
+ lines.push('');
22
+ lines.push('| Metric | Value | Status |');
23
+ lines.push('| :--- | :--- | :--- |');
24
+ const hearts = resolveHealthHearts(health?.grade, health?.score, false);
25
+ lines.push(`| **Life / Health Meter** | ${hearts} (Grade **${health.grade}**) | ${health.score} / 100 (${health.label}) |`);
26
+ lines.push(`| **Molecular Health Index** | **${health.score} / 100** | Grade: **${health.grade}** (${health.label}) |`);
27
+ lines.push(`| **Scanned Files** | ${metrics.scannedFiles} source files | Verified |`);
28
+ lines.push(`| **Total Lines of Code** | ${metrics.totalLoc} lines of code | Avg ${metrics.avgLoc} lines/file |`);
29
+ lines.push(`| **Largest File** | \`${metrics.largestFile.filePath || 'None'}\` | ${metrics.largestFile.lineCount} lines |`);
30
+ lines.push(`| **Context Token Overhead** | ~${contextAnalysis.estimatedTokens.toLocaleString()} tokens | Est. Bloat: ~${contextAnalysis.estimatedExcessTokens.toLocaleString()} tokens |`);
31
+ lines.push(`| **Token Reduction Target** | **${contextAnalysis.potentialSavingsPct}%** | Risk Level: **${contextAnalysis.riskLevel}** |`);
32
+ if (contextAnalysis.excessCostPerPass !== undefined) {
33
+ lines.push(`| **Monolith Cost per Turn** | **$${contextAnalysis.excessCostPerPass.toFixed(3)}** | Model: ${contextAnalysis.pricingModel} |`);
34
+ lines.push(`| **Projected Dev Context Tax** | **$${contextAnalysis.monthlyWastePerDev.toFixed(2)} / mo** | Est. $${contextAnalysis.weeklyWastePerDev.toFixed(2)} / week per engineer |`);
35
+ }
36
+ lines.push(`| **Total Hazards Flagged** | **${violations.length}** | Critical: ${critical.length}, High: ${high.length}, Med: ${medium.length}, Low: ${low.length} |`);
37
+ lines.push('');
38
+ lines.push('---');
39
+ lines.push('');
40
+ lines.push('## 2. 7-Pillar Architectural Compliance Matrix');
41
+ lines.push('');
42
+ lines.push('| Pillar | Status | Violations | Critical | High | Med | Low |');
43
+ lines.push('| :--- | :---: | :---: | :---: | :---: | :---: | :---: |');
44
+
45
+ for (const [pillarName, data] of Object.entries(pillars)) {
46
+ const icon = PILLAR_EMOJIS[pillarName] || '🏛️';
47
+ const statusIcon = resolveMarkdownStatusIcon(data.status);
48
+ const violationsText = data.violations === 0 ? '🟢 0' : `⚠️ **${data.violations}**`;
49
+ lines.push(`| ${icon} ${pillarName} | ${statusIcon} | ${violationsText} | ${data.critical} | ${data.high} | ${data.medium} | ${data.low} |`);
50
+ }
51
+
52
+ lines.push('');
53
+ lines.push('---');
54
+ lines.push('');
55
+ lines.push('## 3. Top Refactoring Hotspots');
56
+ lines.push('');
57
+ if (hotspots.length === 0) {
58
+ lines.push('No hotspot files identified. All analyzed files remain within architectural line budgets.');
59
+ } else {
60
+ lines.push('| Priority | File Path | Line Count | Violations | Monolith Hazard |');
61
+ lines.push('| :---: | :--- | :---: | :---: | :---: |');
62
+ hotspots.forEach((h, idx) => {
63
+ const monolithText = resolveMarkdownMonolithText(h.lineCount);
64
+ const priorityBadge = NUMBER_EMOJIS[idx] || `${idx + 1}`;
65
+ lines.push(`| ${priorityBadge} | \`${h.filePath}\` | ${h.lineCount} | ${h.violationCount} | ${monolithText} |`);
66
+ });
67
+ }
68
+
69
+ lines.push('');
70
+ lines.push('---');
71
+ lines.push('');
72
+ lines.push('## 4. Architectural Hazard Inventory (Grouped by Severity)');
73
+ lines.push('');
74
+
75
+ if (violations.length === 0) {
76
+ lines.push('Zero context hazard violations detected across all line budgets, hooks, and AST rules.');
77
+ } else {
78
+ if (critical.length > 0) {
79
+ lines.push('### Critical Hazards (Immediate Action Required)');
80
+ lines.push('');
81
+ lines.push('| Location | Rule | Hazard Description | Directive |');
82
+ lines.push('| :--- | :--- | :--- | :--- |');
83
+ for (const v of critical) {
84
+ lines.push(`| \`${v.filePath}:${v.line}:${v.column}\` | \`${v.rule}\` | ${v.hazard} | ${v.directive} |`);
85
+ }
86
+ lines.push('');
87
+ }
88
+
89
+ if (high.length > 0 || medium.length > 0) {
90
+ lines.push('### High & Medium Hazards (Architecture Debts)');
91
+ lines.push('');
92
+ lines.push('| Location | Severity | Rule | Hazard Description | Directive |');
93
+ lines.push('| :--- | :---: | :--- | :--- | :--- |');
94
+ for (const v of [...high, ...medium]) {
95
+ lines.push(`| \`${v.filePath}:${v.line}:${v.column}\` | ${v.severity} | \`${v.rule}\` | ${v.hazard} | ${v.directive} |`);
96
+ }
97
+ lines.push('');
98
+ }
99
+
100
+ if (low.length > 0) {
101
+ lines.push('### Low & Hygiene Issues (Typography & Logging)');
102
+ lines.push('');
103
+ lines.push('| Location | Rule | Hazard Description | Directive |');
104
+ lines.push('| :--- | :--- | :--- | :--- |');
105
+ for (const v of low) {
106
+ lines.push(`| \`${v.filePath}:${v.line}:${v.column}\` | \`${v.rule}\` | ${v.hazard} | ${v.directive} |`);
107
+ }
108
+ lines.push('');
109
+ }
110
+ }
111
+
112
+ lines.push('---');
113
+ lines.push('');
114
+ lines.push('## 5. Remediation Roadmap');
115
+ lines.push('');
116
+ lines.push('1. **Decompose Monoliths**: Break down any file exceeding 500 lines into single-responsibility capsules.');
117
+ lines.push('2. **Cap Molecule Size**: Ensure all molecule components (`m-*`) remain strictly under 100 lines.');
118
+ lines.push('3. **Two-Stage Boolean Logic**: Replace complex multi-clause expressions with atomic boolean variables.');
119
+ lines.push('4. **Lifecycle-Safe Timers**: Migrate raw `setInterval` and `setTimeout` calls to self-cleaning composables.');
120
+ lines.push('');
121
+
122
+ const masterPrompt = buildMasterPrompt(report);
123
+ if (masterPrompt) {
124
+ lines.push('---');
125
+ lines.push('');
126
+ lines.push('## 6. 🤖 Copy-Paste AI Agent Refactoring Directives');
127
+ lines.push('');
128
+ lines.push('Feed the prompt below directly into your AI coding agent (Cursor, Windsurf, Claude, Copilot, or Antigravity) to surgically refactor flagged hazards:');
129
+ lines.push('');
130
+ lines.push('```markdown');
131
+ lines.push(masterPrompt);
132
+ lines.push('```');
133
+ lines.push('');
134
+ }
135
+
136
+ return lines.join('\n');
137
+ };
@@ -0,0 +1,125 @@
1
+ export const CYAN = '\x1b[38;2;98;201;255m';
2
+ export const GREEN = '\x1b[32m';
3
+ export const YELLOW = '\x1b[33m';
4
+ export const RED = '\x1b[31m';
5
+ export const ORANGE = '\x1b[38;5;208m';
6
+ export const DIM = '\x1b[2m';
7
+ export const BOLD = '\x1b[1m';
8
+ export const RESET = '\x1b[0m';
9
+
10
+ export const groupViolationsBySeverity = (violations) => {
11
+ const critical = [];
12
+ const high = [];
13
+ const medium = [];
14
+ const low = [];
15
+
16
+ for (const v of violations) {
17
+ if (v.severity === 'CRITICAL') critical.push(v);
18
+ else if (v.severity === 'HIGH') high.push(v);
19
+ else if (v.severity === 'MEDIUM') medium.push(v);
20
+ else low.push(v);
21
+ }
22
+
23
+ return { critical, high, medium, low };
24
+ };
25
+
26
+ export const getSeverityBadge = (severity) => {
27
+ switch (severity) {
28
+ case 'CRITICAL':
29
+ return `${RED}[CRITICAL]${RESET}`;
30
+ case 'HIGH':
31
+ return `${ORANGE}[HIGH]${RESET}`;
32
+ case 'MEDIUM':
33
+ return `${ORANGE}[MEDIUM]${RESET}`;
34
+ case 'LOW':
35
+ return `${YELLOW}[LOW]${RESET}`;
36
+ default:
37
+ return `[${severity}]`;
38
+ }
39
+ };
40
+
41
+ export const getStatusBadge = (status) => {
42
+ switch (status) {
43
+ case 'PASSED':
44
+ return `${GREEN}✔ PASS${RESET}`;
45
+ case 'WARN':
46
+ return `${YELLOW}⚠ WARN${RESET}`;
47
+ case 'FAILED':
48
+ return `${RED}✕ FAIL${RESET}`;
49
+ default:
50
+ return status;
51
+ }
52
+ };
53
+
54
+ export const resolveGradeColor = (scoreOrGrade) => {
55
+ if (typeof scoreOrGrade === 'string') {
56
+ const g = scoreOrGrade.toUpperCase();
57
+ if (g.startsWith('A')) return GREEN;
58
+ if (g === 'B' || g === 'C') return YELLOW;
59
+ if (g === 'D') return ORANGE;
60
+ return RED;
61
+ }
62
+ if (scoreOrGrade >= 90) return GREEN;
63
+ if (scoreOrGrade >= 70) return YELLOW;
64
+ return RED;
65
+ };
66
+
67
+ export const resolveRiskColor = (riskLevel) => {
68
+ if (riskLevel === 'HIGH') return RED;
69
+ if (riskLevel === 'MODERATE') return YELLOW;
70
+ return GREEN;
71
+ };
72
+
73
+ export const resolveHotspotBadge = (lineCount) => {
74
+ if (lineCount >= 2000) return ` ${RED}[CRITICAL MONOLITH >= 2,000 lines of code]${RESET}`;
75
+ if (lineCount >= 1000) return ` ${ORANGE}[SEVERE MONOLITH >= 1,000 lines of code]${RESET}`;
76
+ if (lineCount > 500) return ` ${YELLOW}[MONOLITH WARNING > 500 lines of code]${RESET}`;
77
+ return '';
78
+ };
79
+
80
+ export const resolveHealthHearts = (grade, score = 0, isAnsi = true) => {
81
+ const g = String(grade || '').toUpperCase();
82
+ let filled = 1;
83
+ if (g.startsWith('A') || score >= 90) filled = 5;
84
+ else if (g.startsWith('B') || score >= 80) filled = 4;
85
+ else if (g.startsWith('C') || score >= 70) filled = 3;
86
+ else if (g.startsWith('D') || score >= 60) filled = 2;
87
+ else filled = score === 0 ? 0 : 1;
88
+
89
+ const empty = 5 - filled;
90
+ if (!isAnsi) {
91
+ return '❤︎'.repeat(filled) + '♡'.repeat(empty);
92
+ }
93
+ const redHearts = `${RED}${BOLD}` + '❤︎'.repeat(filled) + RESET;
94
+ const dimHearts = `${DIM}` + '♡'.repeat(empty) + RESET;
95
+ return `${redHearts}${dimHearts}`;
96
+ };
97
+
98
+ export const PILLAR_EMOJIS = {
99
+ 'Line Budgets & Monolith Decomposition': '📏',
100
+ 'Control Flow & Boolean Logic': '🔀',
101
+ 'Reactivity & Composable Contracts': '⚛️',
102
+ 'Type Architecture & Data Integrity': '🛡️',
103
+ 'Design System & Styling Hygiene': '🎨',
104
+ 'Timers & Macro-Task Discipline': '⏱️',
105
+ 'Global Hygiene & Typography': '🧹'
106
+ };
107
+
108
+ export const NUMBER_EMOJIS = ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣', '🔟'];
109
+
110
+ export const resolvePriorityBadge = (idx) => {
111
+ return NUMBER_EMOJIS[idx] || `${idx + 1}`;
112
+ };
113
+
114
+ export const resolveMarkdownStatusIcon = (status) => {
115
+ if (status === 'PASSED') return '🟢 **PASSED**';
116
+ if (status === 'WARN') return '🟡 **WARN**';
117
+ return '🔴 **FAILED**';
118
+ };
119
+
120
+ export const resolveMarkdownMonolithText = (lineCount) => {
121
+ if (lineCount >= 2000) return '🔴 **CRITICAL (>= 2,000 lines of code)**';
122
+ if (lineCount >= 1000) return '🟠 **SEVERE (>= 1,000 lines of code)**';
123
+ if (lineCount > 500) return '🟡 **WARNING (> 500 lines of code)**';
124
+ return '🟢 Compliant';
125
+ };