@chem-x/starter-kit 26.9.13-632 → 26.9.14-1358

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Xopher Pollard / Chemical X Protocol
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -30,9 +30,21 @@ starter-kit/
30
30
  └── index.js # Interactive capsule generator
31
31
  ```
32
32
 
33
+ ## Release Versioning: Minute-Precision CalVer
34
+
35
+ This package adheres to **Minute-Precision Calendar Versioning** (`YY.MM.DD-MMMM`):
36
+ - `YY.MM.DD`: Release date (e.g. `26.9.14` for Sept 14, 2026).
37
+ - `MMMM`: Minute of the day (0 to 1439).
38
+
39
+ Because autonomous coding agent models update frequently, this package is continuously integrated and deployed via automated CI whenever new agent directives, AST checks, or framework rules are tuned. Rapid version iterations reflect active, daily alignment rather than breaking SemVer shifts.
40
+
41
+ > [!NOTE]
42
+ > Download statistics on npm reflect continuous automated test matrix verification and test runner execution across automated environments.
43
+
33
44
  ---
34
45
 
35
- ## Licensing & Access
46
+ ## License
36
47
 
37
- Unlocked for verified GitHub Sponsors and VIP license key holders of `chemical-x-protocol`.
38
- Explore activation details at [https://chemicalx.xophz.com/#starter-kit](https://chemicalx.xophz.com/#starter-kit).
48
+ Core CLI tools and capsule generators are distributed under the **MIT License**.
49
+ Private production monorepos and extended starter suites are unlocked for verified GitHub Sponsors.
50
+ Explore sponsorship details at [https://chemicalx.xophz.com](https://chemicalx.xophz.com).
@@ -60,8 +60,16 @@ export const formatGroupedPromptViolations = (violations = []) => {
60
60
  return lines;
61
61
  };
62
62
 
63
+ export const buildAgentCommandsSection = () => [
64
+ '### AI AGENT DISCOVERY & REFACTORING COMMANDS:',
65
+ '- Query & Inspect: Run `pnpm q "<target>" --inspect` (or `npx chemx search "<target>" --inspect`) to inspect component props, symbols, and hooks before editing.',
66
+ '- Tier Filter: Run `pnpm q "<query>" --tier=molecule` (or `atom`, `organism`, `hook`) to find related capsules.',
67
+ '- Zero-Overhead JSON: Run `pnpm q "<query>" --json` for minified AST metadata without burning context tokens on whole files.',
68
+ '- Re-Verify Score: Run `npx chemx audit` after refactoring to ensure Molecular Health Index (MHI) and letter grades improve.'
69
+ ].join('\n');
70
+
63
71
  export const buildGradeFPrompt = (report, options = {}) => {
64
- const { excludeAiSlop = false } = options;
72
+ const { excludeAiSlop = false, isSubSection = false } = options;
65
73
  const { violations = [], hotspots = [] } = report;
66
74
  const critical = violations
67
75
  .filter((v) => v.severity === 'CRITICAL')
@@ -73,7 +81,10 @@ export const buildGradeFPrompt = (report, options = {}) => {
73
81
  if (hasNoCritical && hasNoMonoliths) return '';
74
82
 
75
83
  const lines = [];
76
- lines.push('Act as a Principal Systems Architect. Surgically refactor the following Grade F Critical Context Hazards in our codebase according to Chemical X Molecular Architecture Standards:\n');
84
+ const preamble = isSubSection
85
+ ? 'Surgically refactor the following Grade F Critical Context Hazards in our codebase according to Chemical X Molecular Architecture Standards:\n'
86
+ : 'Act as a Principal Systems Architect. Surgically refactor the following Grade F Critical Context Hazards in our codebase according to Chemical X Molecular Architecture Standards:\n';
87
+ lines.push(preamble);
77
88
 
78
89
  if (extremeMonoliths.length > 0) {
79
90
  lines.push('### EXTREME MONOLITHS (>= 2,000 lines of code) : MONOLITH DECOMPOSITION');
@@ -96,12 +107,14 @@ export const buildGradeFPrompt = (report, options = {}) => {
96
107
  lines.push('4. Zero synthetic or mock data: return live data or explicit empty states.');
97
108
  lines.push('5. Zero render-hack setTimeout: replace with await nextTick() or flush: post.');
98
109
  lines.push('6. Output surgical diffs or modular replacements. Preserve existing external exports.');
110
+ lines.push('');
111
+ lines.push(buildAgentCommandsSection());
99
112
 
100
113
  return lines.join('\n');
101
114
  };
102
115
 
103
116
  export const buildGradeDPrompt = (report, options = {}) => {
104
- const { excludeAiSlop = false } = options;
117
+ const { excludeAiSlop = false, isSubSection = false } = options;
105
118
  const { violations = [], hotspots = [] } = report;
106
119
  const high = violations
107
120
  .filter((v) => v.severity === 'HIGH')
@@ -113,7 +126,10 @@ export const buildGradeDPrompt = (report, options = {}) => {
113
126
  if (hasNoHigh && hasNoMonoliths) return '';
114
127
 
115
128
  const lines = [];
116
- lines.push('Act as a Principal Systems Architect. Refactor the following Grade D High-Severity Architectural Debts according to Chemical X Molecular Architecture Standards:\n');
129
+ const preamble = isSubSection
130
+ ? 'Refactor the following Grade D High-Severity Architectural Debts according to Chemical X Molecular Architecture Standards:\n'
131
+ : 'Act as a Principal Systems Architect. Refactor the following Grade D High-Severity Architectural Debts according to Chemical X Molecular Architecture Standards:\n';
132
+ lines.push(preamble);
117
133
 
118
134
  if (severeMonoliths.length > 0) {
119
135
  lines.push('### SEVERE MONOLITHS (1,000 - 1,999 lines of code)');
@@ -133,12 +149,14 @@ export const buildGradeDPrompt = (report, options = {}) => {
133
149
  lines.push('1. Hook Saturation: Extract component hooks into dedicated domain composables adhering to the 3-5 property return limit (State + Status + Actions).');
134
150
  lines.push('2. Complex Control Flow: Break multi-clause conditionals into 2-stage atomic boolean variables with early-return guard clauses.');
135
151
  lines.push('3. Zero breaking changes to caller APIs or existing props.');
152
+ lines.push('');
153
+ lines.push(buildAgentCommandsSection());
136
154
 
137
155
  return lines.join('\n');
138
156
  };
139
157
 
140
158
  export const buildGradeCPrompt = (report, options = {}) => {
141
- const { excludeAiSlop = false } = options;
159
+ const { excludeAiSlop = false, isSubSection = false } = options;
142
160
  const { violations = [], hotspots = [] } = report;
143
161
  const medium = violations
144
162
  .filter((v) => v.severity === 'MEDIUM')
@@ -150,7 +168,10 @@ export const buildGradeCPrompt = (report, options = {}) => {
150
168
  if (hasNoMedium && hasNoMonoliths) return '';
151
169
 
152
170
  const lines = [];
153
- lines.push('Act as a Senior Frontend Engineer. Refactor the following Grade C Medium-Severity Technical Debts according to Chemical X Molecular Architecture Standards:\n');
171
+ const preamble = isSubSection
172
+ ? 'Refactor the following Grade C Medium-Severity Technical Debts according to Chemical X Molecular Architecture Standards:\n'
173
+ : 'Act as a Senior Frontend Engineer. Refactor the following Grade C Medium-Severity Technical Debts according to Chemical X Molecular Architecture Standards:\n';
174
+ lines.push(preamble);
154
175
 
155
176
  if (warningMonoliths.length > 0) {
156
177
  lines.push('### WARNING MONOLITHS (500 - 999 lines of code)');
@@ -170,12 +191,14 @@ export const buildGradeCPrompt = (report, options = {}) => {
170
191
  lines.push('1. Zero raw inline styles: Replace style={{...}} with atom props, SCSS mixins (@include glass), or scoped BEM classes.');
171
192
  lines.push('2. Extract anonymous inline callbacks into named functions before passing as props.');
172
193
  lines.push('3. Co-locate granular types (*.d.ts) inside feature capsules (< 100 lines of code). Avoid type monoliths.');
194
+ lines.push('');
195
+ lines.push(buildAgentCommandsSection());
173
196
 
174
197
  return lines.join('\n');
175
198
  };
176
199
 
177
200
  export const buildGradeBPrompt = (report, options = {}) => {
178
- const { excludeAiSlop = false } = options;
201
+ const { excludeAiSlop = false, isSubSection = false } = options;
179
202
  const { violations = [] } = report;
180
203
  const low = violations
181
204
  .filter((v) => v.severity === 'LOW')
@@ -185,7 +208,10 @@ export const buildGradeBPrompt = (report, options = {}) => {
185
208
  if (hasNoLow) return '';
186
209
 
187
210
  const lines = [];
188
- lines.push('Act as a Clean Code Specialist. Clean up the following Grade B Low-Severity Hygiene Issues according to Chemical X standards:\n');
211
+ const preamble = isSubSection
212
+ ? 'Clean up the following Grade B Low-Severity Hygiene Issues according to Chemical X standards:\n'
213
+ : 'Act as a Clean Code Specialist. Clean up the following Grade B Low-Severity Hygiene Issues according to Chemical X standards:\n';
214
+ lines.push(preamble);
189
215
 
190
216
  lines.push('### LOW HYGIENE VIOLATIONS');
191
217
  lines.push(...formatGroupedPromptViolations(low));
@@ -194,11 +220,14 @@ export const buildGradeBPrompt = (report, options = {}) => {
194
220
  lines.push('1. Typography Hygiene: Replace all em dashes with standard hyphens (-) or colons (:).');
195
221
  lines.push('2. Logging Hygiene: Remove unguarded console.log calls or route through central debug proxy.');
196
222
  lines.push('3. FontAwesome Compliance: Remove text-* utility classes from icons; use :color prop or inline CSS.');
223
+ lines.push('');
224
+ lines.push(buildAgentCommandsSection());
197
225
 
198
226
  return lines.join('\n');
199
227
  };
200
228
 
201
- export const buildAiSlopPrompt = (report) => {
229
+ export const buildAiSlopPrompt = (report, options = {}) => {
230
+ const { isSubSection = false } = options;
202
231
  const { violations = [] } = report;
203
232
  const slopViolations = violations.filter((v) => Boolean(v.isAiSlop));
204
233
 
@@ -206,10 +235,15 @@ export const buildAiSlopPrompt = (report) => {
206
235
  if (hasNoSlop) return '';
207
236
 
208
237
  const lines = [];
209
- lines.push('Act as a Clean Code Specialist and Code Authenticity Guardian. Eliminate the following AI Slop and conversational artifacts from our codebase according to Chemical X standards:\n');
210
-
211
- lines.push('### AI SLOP & CODE AUTHENTICITY VIOLATIONS');
212
- lines.push(...formatGroupedPromptViolations(slopViolations));
238
+ const preamble = isSubSection
239
+ ? 'Eliminate the following AI Slop and conversational artifacts from our codebase according to Chemical X standards:\n'
240
+ : 'Act as a Clean Code Specialist and Code Authenticity Guardian. Eliminate the following AI Slop and conversational artifacts from our codebase according to Chemical X standards:\n';
241
+ lines.push(preamble);
242
+
243
+ if (slopViolations.length > 0) {
244
+ lines.push('### AI SLOP & CODE AUTHENTICITY VIOLATIONS');
245
+ lines.push(...formatGroupedPromptViolations(slopViolations));
246
+ }
213
247
 
214
248
  lines.push('### STRICT EXECUTION RULES:');
215
249
  lines.push('1. Conversational Residue: Completely remove leaked AI conversational preambles, assistant markdown code fences, and pleasantry comments.');
@@ -218,11 +252,14 @@ export const buildAiSlopPrompt = (report) => {
218
252
  lines.push('4. Paranoia Catch Wrappers: Replace shallow or empty catch blocks with intentional error propagation or ResultTuple ([data, error]).');
219
253
  lines.push('5. Inline Utility Reinventions: Replace reinvented inline helper utilities with shared project utilities or native methods.');
220
254
  lines.push('6. Type Widening: Eliminate lazy "any" type casts on error parameters or variables; enforce strict typing.');
255
+ lines.push('');
256
+ lines.push(buildAgentCommandsSection());
221
257
 
222
258
  return lines.join('\n');
223
259
  };
224
260
 
225
- export const buildHotspotsPrompt = (report) => {
261
+ export const buildHotspotsPrompt = (report, options = {}) => {
262
+ const { isSubSection = false } = options;
226
263
  const { hotspots = [] } = report;
227
264
  const monolithHotspots = hotspots.filter((h) => h.isMonolith || h.lineCount > 500);
228
265
 
@@ -230,15 +267,20 @@ export const buildHotspotsPrompt = (report) => {
230
267
  if (hasNoMonoliths) return '';
231
268
 
232
269
  const lines = [];
233
- lines.push('Act as a Principal Systems Architect. Surgically decompose the following monolithic hotspot files according to Chemical X Molecular Architecture Standards:\n');
270
+ const preamble = isSubSection
271
+ ? 'Surgically decompose the following monolithic hotspot files according to Chemical X Molecular Architecture Standards:\n'
272
+ : 'Act as a Principal Systems Architect. Surgically decompose the following monolithic hotspot files according to Chemical X Molecular Architecture Standards:\n';
273
+ lines.push(preamble);
234
274
 
235
- lines.push('### MONOLITHIC REFACTORING HOTSPOTS');
236
- lines.push('Action: Decompose into single-responsibility crystalline molecule capsules (< 100 lines) and dedicated domain composables.\n');
237
- monolithHotspots.forEach((h, i) => {
238
- const tier = h.monolithTier ? `[${h.monolithTier} MONOLITH]` : '[MONOLITH]';
239
- lines.push(`${i + 1}. File: \`${h.filePath}\` (${h.lineCount} lines, ${h.violationCount} hazards) ${tier}`);
240
- });
241
- lines.push('');
275
+ if (monolithHotspots.length > 0) {
276
+ lines.push('### MONOLITHIC REFACTORING HOTSPOTS');
277
+ lines.push('Action: Decompose into single-responsibility crystalline molecule capsules (< 100 lines) and dedicated domain composables.\n');
278
+ monolithHotspots.forEach((h, i) => {
279
+ const tier = h.monolithTier ? `[${h.monolithTier} MONOLITH]` : '[MONOLITH]';
280
+ lines.push(`${i + 1}. File: \`${h.filePath}\` (${h.lineCount} lines, ${h.violationCount} hazards) ${tier}`);
281
+ });
282
+ lines.push('');
283
+ }
242
284
 
243
285
  lines.push('### STRICT EXECUTION RULES:');
244
286
  lines.push('1. Branch First: Change to a new branch prefixed with `chem-x/NAMEOFIMPROVEMENT` before making changes, then commit the branch and create a PR to main.');
@@ -248,11 +290,14 @@ export const buildHotspotsPrompt = (report) => {
248
290
  lines.push('5. Composable Return Contracts: Custom hooks/composables must strictly limit returns to 3 to 5 properties (State + Status + Actions).');
249
291
  lines.push('6. Type Co-location: Co-locate granular types/*.d.ts files inside each feature capsule (< 100 lines per type file) instead of creating type monoliths.');
250
292
  lines.push('7. Zero breaking changes to external component APIs, route exports, or existing props.');
293
+ lines.push('');
294
+ lines.push(buildAgentCommandsSection());
251
295
 
252
296
  return lines.join('\n');
253
297
  };
254
298
 
255
- export const buildPillarPrompt = (report, pillarName) => {
299
+ export const buildPillarPrompt = (report, pillarName, options = {}) => {
300
+ const { isSubSection = false } = options;
256
301
  const { violations = [], hotspots = [] } = report;
257
302
  const pillarViolations = violations.filter((v) => v.pillar === pillarName);
258
303
  const isPillar1 = pillarName === 'Line Budgets & Monolith Decomposition';
@@ -263,7 +308,10 @@ export const buildPillarPrompt = (report, pillarName) => {
263
308
  if (hasNoViolations && hasNoHotspots) return '';
264
309
 
265
310
  const lines = [];
266
- lines.push(`Act as a Principal Systems Architect. Surgically refactor the following ${pillarName} violations according to Chemical X Molecular Architecture Standards:\n`);
311
+ const preamble = isSubSection
312
+ ? `Surgically refactor the following ${pillarName} violations according to Chemical X Molecular Architecture Standards:\n`
313
+ : `Act as a Principal Systems Architect. Surgically refactor the following ${pillarName} violations according to Chemical X Molecular Architecture Standards:\n`;
314
+ lines.push(preamble);
267
315
 
268
316
  if (relevantHotspots.length > 0) {
269
317
  lines.push('### MONOLITHIC REFACTORING HOTSPOTS');
@@ -285,25 +333,53 @@ export const buildPillarPrompt = (report, pillarName) => {
285
333
  lines.push('3. Molecular Capsule Limit: Maximum 100 lines per molecule capsule file.');
286
334
  lines.push('4. Table-of-Contents Views: Top-level page views must be 10 to 20 line declarative templates assembling components via named slots.');
287
335
  lines.push('5. Zero breaking changes to external component APIs, route exports, or existing props.');
336
+ lines.push('');
337
+ lines.push(buildAgentCommandsSection());
288
338
 
289
339
  return lines.join('\n');
290
340
  };
291
341
 
342
+ export const deduplicateRolePreambles = (promptText, options = {}) => {
343
+ if (typeof promptText !== 'string' || !promptText) return '';
344
+ const { onlyIdentical = false } = options;
345
+ let firstRole = null;
346
+ const seenRoles = new Set();
347
+
348
+ return promptText.replace(/(^|\n\s*)Act as (?:an?|the)\s+([^.\n]+?)\.\s+(?=[A-Z])/gi, (match, prefix, role) => {
349
+ const normalizedRole = role.trim().toLowerCase();
350
+ if (!firstRole) {
351
+ firstRole = normalizedRole;
352
+ seenRoles.add(normalizedRole);
353
+ return match;
354
+ }
355
+
356
+ if (onlyIdentical) {
357
+ if (seenRoles.has(normalizedRole)) {
358
+ return prefix;
359
+ }
360
+ return match;
361
+ }
362
+
363
+ return prefix;
364
+ });
365
+ };
366
+
292
367
  export const buildMasterPrompt = (report) => {
293
368
  const sections = [
294
- buildGradeFPrompt(report, { excludeAiSlop: true }),
295
- buildGradeDPrompt(report, { excludeAiSlop: true }),
296
- buildGradeCPrompt(report, { excludeAiSlop: true }),
297
- buildGradeBPrompt(report, { excludeAiSlop: true }),
298
- buildAiSlopPrompt(report),
299
- buildHotspotsPrompt(report)
369
+ buildGradeFPrompt(report, { excludeAiSlop: true, isSubSection: true }),
370
+ buildGradeDPrompt(report, { excludeAiSlop: true, isSubSection: true }),
371
+ buildGradeCPrompt(report, { excludeAiSlop: true, isSubSection: true }),
372
+ buildGradeBPrompt(report, { excludeAiSlop: true, isSubSection: true }),
373
+ buildAiSlopPrompt(report, { isSubSection: true }),
374
+ buildHotspotsPrompt(report, { isSubSection: true })
300
375
  ].filter(Boolean);
301
376
 
302
377
  const hasNoSections = sections.length === 0;
303
378
  if (hasNoSections) return '';
304
379
 
305
- const header = `Act as a Principal Systems Architect. Execute a phased architectural refactoring of our codebase according to Chemical X Molecular Architecture Standards.\n\n`;
306
- return header + sections.join('\n\n---\n\n');
380
+ const header = 'Act as a Principal Systems Architect. Execute a phased architectural refactoring of our codebase according to Chemical X Molecular Architecture Standards.\n\n';
381
+ const rawPrompt = header + sections.join('\n\n---\n\n');
382
+ return deduplicateRolePreambles(rawPrompt);
307
383
  };
308
384
 
309
385
  export const formatPromptBox = (title, promptText) => {
@@ -0,0 +1,291 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert';
3
+ import {
4
+ deduplicateRolePreambles,
5
+ buildGradeFPrompt,
6
+ buildGradeDPrompt,
7
+ buildGradeCPrompt,
8
+ buildGradeBPrompt,
9
+ buildAiSlopPrompt,
10
+ buildHotspotsPrompt,
11
+ buildPillarPrompt,
12
+ buildMasterPrompt
13
+ } from './prompts.js';
14
+
15
+ test('deduplicateRolePreambles: handles invalid and empty inputs', () => {
16
+ assert.strictEqual(deduplicateRolePreambles(''), '');
17
+ assert.strictEqual(deduplicateRolePreambles(null), '');
18
+ assert.strictEqual(deduplicateRolePreambles(undefined), '');
19
+ assert.strictEqual(deduplicateRolePreambles(123), '');
20
+ });
21
+
22
+ test('deduplicateRolePreambles: leaves single role preamble untouched', () => {
23
+ const single = 'Act as a Principal Systems Architect. Execute a phased architectural refactoring.';
24
+ assert.strictEqual(deduplicateRolePreambles(single), single);
25
+ });
26
+
27
+ test('deduplicateRolePreambles: removes repeated identical role preambles', () => {
28
+ const input = [
29
+ 'Act as a Principal Systems Architect. Execute a phased architectural refactoring of our codebase according to Chemical X Molecular Architecture Standards.',
30
+ '',
31
+ 'Act as a Principal Systems Architect. Surgically refactor the following Grade F Critical Context Hazards in our codebase according to Chemical X Molecular Architecture Standards:'
32
+ ].join('\n');
33
+
34
+ const expected = [
35
+ 'Act as a Principal Systems Architect. Execute a phased architectural refactoring of our codebase according to Chemical X Molecular Architecture Standards.',
36
+ '',
37
+ 'Surgically refactor the following Grade F Critical Context Hazards in our codebase according to Chemical X Molecular Architecture Standards:'
38
+ ].join('\n');
39
+
40
+ assert.strictEqual(deduplicateRolePreambles(input), expected);
41
+ });
42
+
43
+ test('deduplicateRolePreambles: removes subsequent different role preambles by default', () => {
44
+ const input = [
45
+ 'Act as a Principal Systems Architect. Execute a phased refactor.',
46
+ '',
47
+ 'Act as a Senior Frontend Engineer. Refactor the following Grade C Medium-Severity Technical Debts:',
48
+ '',
49
+ 'Act as a Clean Code Specialist. Clean up the following Grade B Low-Severity Hygiene Issues:'
50
+ ].join('\n');
51
+
52
+ const expected = [
53
+ 'Act as a Principal Systems Architect. Execute a phased refactor.',
54
+ '',
55
+ 'Refactor the following Grade C Medium-Severity Technical Debts:',
56
+ '',
57
+ 'Clean up the following Grade B Low-Severity Hygiene Issues:'
58
+ ].join('\n');
59
+
60
+ assert.strictEqual(deduplicateRolePreambles(input), expected);
61
+ });
62
+
63
+ test('deduplicateRolePreambles: respects onlyIdentical option', () => {
64
+ const input = [
65
+ 'Act as a Principal Systems Architect. Execute step 1.',
66
+ '',
67
+ 'Act as a Senior Frontend Engineer. Refactor step 2.',
68
+ '',
69
+ 'Act as a Principal Systems Architect. Decompose step 3.'
70
+ ].join('\n');
71
+
72
+ const result = deduplicateRolePreambles(input, { onlyIdentical: true });
73
+ assert.ok(result.includes('Act as a Principal Systems Architect. Execute step 1.'));
74
+ assert.ok(result.includes('Act as a Senior Frontend Engineer. Refactor step 2.'));
75
+ assert.ok(result.includes('\n\nDecompose step 3.'));
76
+ assert.ok(!result.includes('Act as a Principal Systems Architect. Decompose step 3.'));
77
+ });
78
+
79
+ test('buildGradeFPrompt: respects isSubSection option', () => {
80
+ const mockReport = {
81
+ violations: [
82
+ {
83
+ severity: 'CRITICAL',
84
+ pillar: 'Test Pillar',
85
+ message: 'Critical issue',
86
+ filePath: 'src/heavy.ts',
87
+ line: 10
88
+ }
89
+ ],
90
+ hotspots: []
91
+ };
92
+
93
+ const standalone = buildGradeFPrompt(mockReport);
94
+ assert.ok(standalone.startsWith('Act as a Principal Systems Architect. Surgically refactor'));
95
+
96
+ const subSection = buildGradeFPrompt(mockReport, { isSubSection: true });
97
+ assert.ok(subSection.startsWith('Surgically refactor'));
98
+ assert.ok(!subSection.includes('Act as a Principal Systems Architect.'));
99
+ });
100
+
101
+ test('buildGradeDPrompt: respects isSubSection option', () => {
102
+ const mockReport = {
103
+ violations: [
104
+ {
105
+ severity: 'HIGH',
106
+ pillar: 'Test Pillar',
107
+ message: 'High severity issue',
108
+ filePath: 'src/high.ts',
109
+ line: 20
110
+ }
111
+ ],
112
+ hotspots: []
113
+ };
114
+
115
+ const standalone = buildGradeDPrompt(mockReport);
116
+ assert.ok(standalone.startsWith('Act as a Principal Systems Architect. Refactor'));
117
+
118
+ const subSection = buildGradeDPrompt(mockReport, { isSubSection: true });
119
+ assert.ok(subSection.startsWith('Refactor'));
120
+ assert.ok(!subSection.includes('Act as a Principal Systems Architect.'));
121
+ });
122
+
123
+ test('buildGradeCPrompt: respects isSubSection option', () => {
124
+ const mockReport = {
125
+ violations: [
126
+ {
127
+ severity: 'MEDIUM',
128
+ pillar: 'Test Pillar',
129
+ message: 'Medium severity issue',
130
+ filePath: 'src/medium.ts',
131
+ line: 30
132
+ }
133
+ ],
134
+ hotspots: []
135
+ };
136
+
137
+ const standalone = buildGradeCPrompt(mockReport);
138
+ assert.ok(standalone.startsWith('Act as a Senior Frontend Engineer. Refactor'));
139
+
140
+ const subSection = buildGradeCPrompt(mockReport, { isSubSection: true });
141
+ assert.ok(subSection.startsWith('Refactor'));
142
+ assert.ok(!subSection.includes('Act as a Senior Frontend Engineer.'));
143
+ });
144
+
145
+ test('buildGradeBPrompt: respects isSubSection option', () => {
146
+ const mockReport = {
147
+ violations: [
148
+ {
149
+ severity: 'LOW',
150
+ pillar: 'Test Pillar',
151
+ message: 'Low severity issue',
152
+ filePath: 'src/low.ts',
153
+ line: 40
154
+ }
155
+ ],
156
+ hotspots: []
157
+ };
158
+
159
+ const standalone = buildGradeBPrompt(mockReport);
160
+ assert.ok(standalone.startsWith('Act as a Clean Code Specialist. Clean up'));
161
+
162
+ const subSection = buildGradeBPrompt(mockReport, { isSubSection: true });
163
+ assert.ok(subSection.startsWith('Clean up'));
164
+ assert.ok(!subSection.includes('Act as a Clean Code Specialist.'));
165
+ });
166
+
167
+ test('buildAiSlopPrompt: respects isSubSection option', () => {
168
+ const mockReport = {
169
+ violations: [
170
+ {
171
+ severity: 'LOW',
172
+ pillar: 'Code Authenticity & Anti-Slop',
173
+ message: 'Echo comment',
174
+ filePath: 'src/slop.ts',
175
+ line: 5,
176
+ isAiSlop: true
177
+ }
178
+ ],
179
+ hotspots: []
180
+ };
181
+
182
+ const standalone = buildAiSlopPrompt(mockReport);
183
+ assert.ok(standalone.startsWith('Act as a Clean Code Specialist and Code Authenticity Guardian. Eliminate'));
184
+
185
+ const subSection = buildAiSlopPrompt(mockReport, { isSubSection: true });
186
+ assert.ok(subSection.startsWith('Eliminate'));
187
+ assert.ok(!subSection.includes('Act as a Clean Code Specialist'));
188
+ });
189
+
190
+ test('buildHotspotsPrompt: respects isSubSection option', () => {
191
+ const mockReport = {
192
+ violations: [],
193
+ hotspots: [
194
+ {
195
+ filePath: 'src/monolith.ts',
196
+ lineCount: 1200,
197
+ violationCount: 10,
198
+ isMonolith: true,
199
+ monolithTier: 'SEVERE'
200
+ }
201
+ ]
202
+ };
203
+
204
+ const standalone = buildHotspotsPrompt(mockReport);
205
+ assert.ok(standalone.startsWith('Act as a Principal Systems Architect. Surgically decompose'));
206
+
207
+ const subSection = buildHotspotsPrompt(mockReport, { isSubSection: true });
208
+ assert.ok(subSection.startsWith('Surgically decompose'));
209
+ assert.ok(!subSection.includes('Act as a Principal Systems Architect.'));
210
+ });
211
+
212
+ test('buildPillarPrompt: respects isSubSection option', () => {
213
+ const mockReport = {
214
+ violations: [
215
+ {
216
+ severity: 'HIGH',
217
+ pillar: 'Control Flow & Self-Documenting Logic',
218
+ message: 'Complex conditional',
219
+ filePath: 'src/flow.ts',
220
+ line: 15
221
+ }
222
+ ],
223
+ hotspots: []
224
+ };
225
+
226
+ const standalone = buildPillarPrompt(mockReport, 'Control Flow & Self-Documenting Logic');
227
+ assert.ok(standalone.startsWith('Act as a Principal Systems Architect. Surgically refactor'));
228
+
229
+ const subSection = buildPillarPrompt(mockReport, 'Control Flow & Self-Documenting Logic', { isSubSection: true });
230
+ assert.ok(subSection.startsWith('Surgically refactor'));
231
+ assert.ok(!subSection.includes('Act as a Principal Systems Architect.'));
232
+ });
233
+
234
+ test('buildMasterPrompt: has single top-level role preamble and no repeated Act as persona statements', () => {
235
+ const mockReport = {
236
+ violations: [
237
+ {
238
+ severity: 'CRITICAL',
239
+ pillar: 'Pillar 1',
240
+ message: 'Critical error',
241
+ filePath: 'src/critical.ts',
242
+ line: 1
243
+ },
244
+ {
245
+ severity: 'HIGH',
246
+ pillar: 'Pillar 2',
247
+ message: 'High error',
248
+ filePath: 'src/high.ts',
249
+ line: 2
250
+ },
251
+ {
252
+ severity: 'MEDIUM',
253
+ pillar: 'Pillar 3',
254
+ message: 'Medium error',
255
+ filePath: 'src/medium.ts',
256
+ line: 3
257
+ },
258
+ {
259
+ severity: 'LOW',
260
+ pillar: 'Pillar 4',
261
+ message: 'Low error',
262
+ filePath: 'src/low.ts',
263
+ line: 4
264
+ },
265
+ {
266
+ severity: 'LOW',
267
+ pillar: 'Pillar 5',
268
+ message: 'AI slop echo',
269
+ filePath: 'src/slop.ts',
270
+ line: 5,
271
+ isAiSlop: true
272
+ }
273
+ ],
274
+ hotspots: [
275
+ {
276
+ filePath: 'src/monolith.ts',
277
+ lineCount: 2200,
278
+ violationCount: 15,
279
+ isMonolith: true,
280
+ monolithTier: 'EXTREME'
281
+ }
282
+ ]
283
+ };
284
+
285
+ const prompt = buildMasterPrompt(mockReport);
286
+ assert.ok(prompt.startsWith('Act as a Principal Systems Architect. Execute a phased architectural refactoring'));
287
+
288
+ // Ensure "Act as" occurs exactly once in the entire composite prompt
289
+ const matches = prompt.match(/Act as\b/g) || [];
290
+ assert.strictEqual(matches.length, 1, `Expected exactly 1 "Act as", found ${matches.length}`);
291
+ });
@@ -209,6 +209,12 @@ export const buildSelfHealingRoadmapPrompt = (report) => {
209
209
  lines.push('3. Commit the branch with atomic, intention-revealing commit messages.');
210
210
  lines.push('4. Create a Pull Request (PR) to `main` upon completing the remediation phases.\n');
211
211
 
212
+ lines.push('### AI AGENT DISCOVERY & REFACTORING COMMANDS:');
213
+ lines.push('- Discovery & Inspect: Run `pnpm q "<target>" --inspect` (or `npx chemx search "<target>" --inspect`) to inspect component props and hooks before editing.');
214
+ lines.push('- Tier Filter: Run `pnpm q "<query>" --tier=molecule` (or `atom`, `organism`, `hook`) to find related capsules.');
215
+ lines.push('- Zero-Overhead JSON: Run `pnpm q "<query>" --json` for minified AST metadata without burning context tokens on whole files.');
216
+ lines.push('- Re-Verify Score: Run `npx chemx audit` after completing each phase to verify health score improvements.\n');
217
+
212
218
  phases.forEach((p) => {
213
219
  lines.push(`### STEP ${p.step}: ${p.phase}`);
214
220
  lines.push(`Goal: ${p.rationale}\n`);
@@ -219,6 +225,10 @@ export const buildSelfHealingRoadmapPrompt = (report) => {
219
225
  if (item.locations.length > 0) {
220
226
  lines.push(` Files: ${item.locations.join(', ')}`);
221
227
  }
228
+ const rawTarget = item.target.split(' ')[0].replace(/->.*/, '').trim();
229
+ if (rawTarget && !rawTarget.includes('*')) {
230
+ lines.push(` Command: pnpm q "${rawTarget}" --inspect`);
231
+ }
222
232
  });
223
233
  lines.push('');
224
234
  });