@chemx/starter-kit 26.9.21-8 → 26.9.23-1269

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 (130) hide show
  1. package/cli/audit/ast-visitors.js +10 -17
  2. package/cli/audit/autofix.js +17 -2
  3. package/cli/audit/clone-detector.js +64 -0
  4. package/cli/audit/clone-detector.spec.js +46 -0
  5. package/cli/audit/hook-shape-validator.js +312 -0
  6. package/cli/audit/prompts.js +1 -1
  7. package/cli/audit/reporter-clones.js +33 -0
  8. package/cli/audit/reporter-hotspot-graph.js +34 -0
  9. package/cli/audit/rules-registry.js +6 -1
  10. package/cli/audit/rules.js +10 -2
  11. package/cli/audit/rules.spec.js +129 -0
  12. package/cli/audit-stages.spec.js +30 -0
  13. package/cli/audit.js +12 -3
  14. package/cli/commands/cmd-audit.js +43 -3
  15. package/cli/commands/cmd-project.js +100 -0
  16. package/cli/commands/cmd-router.js +34 -2
  17. package/cli/commands-schema.js +14 -0
  18. package/cli/create.spec.js +2 -2
  19. package/cli/exploder.js +258 -0
  20. package/cli/exploder.spec.js +99 -0
  21. package/cli/generator-compact.spec.js +104 -0
  22. package/cli/generator-framework.spec.js +72 -0
  23. package/cli/generator-templates/archetypes/collection-archetypes.js +9 -9
  24. package/cli/generator-templates/archetypes/index.js +34 -4
  25. package/cli/generator-templates/archetypes/input-archetypes.js +2 -2
  26. package/cli/generator-templates/archetypes/layout-archetypes.js +2 -2
  27. package/cli/generator-templates/archetypes/minimal-archetypes.js +131 -0
  28. package/cli/generator-templates/archetypes/status-archetypes.js +4 -4
  29. package/cli/generator-templates/archetypes/vector-matcher.js +50 -0
  30. package/cli/generator-templates/archetypes/vector-matcher.spec.js +25 -0
  31. package/cli/generator-templates/compact.js +130 -0
  32. package/cli/generator-templates/controller-converters.js +93 -0
  33. package/cli/generator-templates/controller.js +2 -64
  34. package/cli/generator-templates/react.js +1 -1
  35. package/cli/generator-templates/svelte.js +1 -1
  36. package/cli/generator-templates/types.js +2 -2
  37. package/cli/generator-templates/vue.js +1 -1
  38. package/cli/generator-templates.js +1 -0
  39. package/cli/generator-templates.spec.js +6 -1
  40. package/cli/generator.js +94 -7
  41. package/cli/help.js +1 -1
  42. package/cli/index.js +21 -8
  43. package/cli/installer-templates.js +1 -1
  44. package/cli/mcp/antigravity.js +3 -2
  45. package/cli/mcp/installer.js +7 -7
  46. package/cli/mcp/installer.spec.js +3 -3
  47. package/cli/mcp/manifests.js +3 -2
  48. package/cli/mcp/prompts.js +1 -1
  49. package/cli/mcp/server.js +2 -0
  50. package/cli/mcp/tools-audit.js +95 -0
  51. package/cli/mcp/tools-generate.js +62 -0
  52. package/cli/mcp/tools-patch.js +72 -0
  53. package/cli/mcp/tools-patterns.js +71 -0
  54. package/cli/mcp/tools-project.js +75 -0
  55. package/cli/mcp/tools-project.spec.js +51 -0
  56. package/cli/mcp/tools-q-modes.js +69 -0
  57. package/cli/mcp/tools-q.js +58 -0
  58. package/cli/mcp/tools-read.js +69 -0
  59. package/cli/mcp/tools-search-util.js +35 -0
  60. package/cli/mcp/tools-search.js +15 -294
  61. package/cli/mcp/tools-team-feed.js +57 -0
  62. package/cli/mcp/tools-team-locks.js +63 -0
  63. package/cli/mcp/tools-team-mailbox.js +32 -0
  64. package/cli/mcp/tools-team-tasks.js +84 -0
  65. package/cli/mcp/tools-team.js +37 -183
  66. package/cli/mcp/tools-verify.js +47 -0
  67. package/cli/mcp/tools-write.js +33 -0
  68. package/cli/mcp/tools.js +72 -376
  69. package/cli/mutators.js +10 -23
  70. package/cli/pillars-schema.js +3 -3
  71. package/cli/project-detector.js +47 -0
  72. package/cli/reader-shorthand.spec.js +60 -0
  73. package/cli/reader.js +67 -24
  74. package/cli/search-bulletproof.spec.js +104 -0
  75. package/cli/search-db.js +33 -5
  76. package/cli/search-queries-hotspot-graph.js +65 -0
  77. package/cli/search-queries-hotspot-graph.spec.js +66 -0
  78. package/cli/search-queries-similar.js +84 -0
  79. package/cli/search-queries-similar.spec.js +43 -0
  80. package/cli/search-schema.js +30 -10
  81. package/cli/search.js +9 -2
  82. package/cli/team/index.js +9 -0
  83. package/cli/team/team-commands.js +104 -64
  84. package/cli/team/team-concurrency-stress.spec.js +95 -0
  85. package/cli/team/team-db-mailbox.js +86 -0
  86. package/cli/team/team-db-task-helpers.js +30 -28
  87. package/cli/team/team-db-tasks.js +13 -5
  88. package/cli/team/team-flags.js +69 -0
  89. package/cli/team/team-format.js +87 -46
  90. package/cli/team/team-mailbox-empirical.spec.js +191 -0
  91. package/cli/team/team-mailbox.spec.js +93 -0
  92. package/cli/team/team-memory.js +84 -0
  93. package/cli/team/team-memory.spec.js +74 -0
  94. package/cli/team/team-projects-coordinator.js +100 -0
  95. package/cli/team/team-projects-format.js +45 -0
  96. package/cli/team/team-projects-memory.js +70 -0
  97. package/cli/team/team-projects.js +94 -0
  98. package/cli/team/team-projects.spec.js +116 -0
  99. package/cli/team/team-schema-memory.js +25 -0
  100. package/cli/team/team-schema-projects.js +50 -0
  101. package/cli/team/team-schema.js +33 -14
  102. package/cli/team/team-tasks-hierarchy.spec.js +80 -0
  103. package/cli/team/team-tokens.js +95 -0
  104. package/cli/team/team-triage.js +159 -12
  105. package/cli/team/team-verification-gate.spec.js +253 -0
  106. package/cli/team/team.spec.js +1 -1
  107. package/cli/trend.js +84 -0
  108. package/cli/trend.spec.js +51 -0
  109. package/cli/ui-actions-tasks.js +13 -5
  110. package/cli/ui-actions.js +10 -2
  111. package/cli/ui-client-api.js +2 -2
  112. package/cli/ui-client-script.js +12 -15
  113. package/cli/ui-e2e-verification.spec.js +13 -3
  114. package/cli/ui-filetree.spec.js +5 -5
  115. package/cli/ui-handlers.js +10 -2
  116. package/cli/ui-html.js +26 -34
  117. package/cli/ui-index.html +905 -0
  118. package/cli/ui-kanban.spec.js +12 -12
  119. package/cli/ui-server.js +7 -0
  120. package/cli/ui-sse.js +57 -0
  121. package/cli/ui-sse.spec.js +74 -0
  122. package/cli/ui-styles.js +195 -81
  123. package/cli/ui-template-kanban.js +15 -1
  124. package/cli/ui-vbulletin.spec.js +12 -13
  125. package/cli/ui.spec.js +12 -5
  126. package/cli/verify.js +19 -8
  127. package/package.json +3 -1
  128. package/scripts/check-framework-generation.mjs +195 -0
  129. package/scripts/pre-commit.sh +2 -7
  130. package/scripts/publish-both.mjs +4 -0
package/cli/mcp/tools.js CHANGED
@@ -1,404 +1,100 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { runAudit as executeAstAudit, auditFile } from '../audit.js';
4
- import {
5
- buildMasterPrompt,
6
- buildGradeFPrompt,
7
- buildGradeDPrompt,
8
- buildGradeCPrompt,
9
- buildGradeBPrompt,
10
- buildAiSlopPrompt,
11
- buildHotspotsPrompt
12
- } from '../audit/prompts.js';
13
- import { createCapsuleFiles } from '../generator.js';
14
- import { runBuildAudit } from '../build.js';
15
- import { runAutofix } from '../audit/autofix.js';
16
- import { runTypecheckAudit, runTestAudit, runProjectVerify } from '../verify.js';
17
- import { syncSearchIndex, syncViolationsIndex, recordAuditSnapshot } from '../search.js';
18
1
  import { MCP_TOOLS, ALL_MCP_TOOLS } from './manifests.js';
19
- import {
20
- resolveTargetCwd,
21
- handleChemxQ,
22
- handleChemxRead,
23
- handleChemxPatch,
24
- handleChemxCheck,
25
- handleChemxWrite
26
- } from './tools-search.js';
27
- import {
28
- handleChemxTeamStatus,
29
- handleChemxTeamFeed,
30
- handleChemxTeamPost,
31
- handleChemxTeamTask,
32
- handleChemxTeamLock,
33
- handleChemxReportIssue
34
- } from './tools-team.js';
2
+ import { handleAudit, handleGetRefactorPrompt } from './tools-audit.js';
3
+ import { handleQueryPatterns, handleAutofix } from './tools-patterns.js';
4
+ import { handleAuditBuild, handleChemxTypecheck, handleChemxTest, handleChemxVerify } from './tools-verify.js';
5
+ import { handleGenerateCapsule, handleChemxTrend } from './tools-generate.js';
6
+ import { handleChemxQ, handleChemxRead, handleChemxPatch, handleChemxCheck, handleChemxWrite } from './tools-search.js';
7
+ import { handleChemxTeam, handleChemxTeamStatus, handleChemxTeamFeed, handleChemxTeamPost, handleChemxTeamTask, handleChemxTeamLock, handleChemxTeamInbox, handleChemxTeamDm, handleChemxReportIssue } from './tools-team.js';
8
+ import { handleChemxProject } from './tools-project.js';
35
9
 
36
10
  export {
37
- MCP_TOOLS,
38
- ALL_MCP_TOOLS,
39
- handleChemxQ,
40
- handleChemxRead,
41
- handleChemxPatch,
42
- handleChemxCheck,
43
- handleChemxWrite,
44
- handleChemxTeamStatus,
45
- handleChemxTeamFeed,
46
- handleChemxTeamPost,
47
- handleChemxTeamTask,
48
- handleChemxTeamLock,
49
- handleChemxReportIssue
11
+ MCP_TOOLS, ALL_MCP_TOOLS, handleChemxQ, handleChemxRead, handleChemxPatch, handleChemxCheck, handleChemxWrite,
12
+ handleChemxTeamStatus, handleChemxTeamFeed, handleChemxTeamPost, handleChemxTeamTask, handleChemxTeamLock, handleChemxReportIssue, handleChemxProject
50
13
  };
51
14
 
52
- const handleQueryPatterns = (args = {}, cwd = process.cwd()) => {
53
- const targetDir = args.dir || (fs.existsSync(path.resolve(cwd, 'src')) ? 'src' : '.');
54
- const report = executeAstAudit(targetDir, {});
55
- const rawPatterns = report.patterns || [];
56
- const filterType = args.type || 'ALL';
57
- const minOccurrences = typeof args.minOccurrences === 'number' ? args.minOccurrences : 2;
58
- const isCompact = args.compact !== false;
59
-
60
- const matchesType = (p) => filterType === 'ALL' || p.type === filterType;
61
- const matchesCount = (p) => p.fileCount >= minOccurrences;
62
-
63
- const candidates = rawPatterns
64
- .filter((p) => matchesType(p) && matchesCount(p))
65
- .map((p) => {
66
- const base = {
67
- id: p.id,
68
- type: p.type,
69
- label: p.label,
70
- detail: p.detail,
71
- suggestedCapsule: p.suggestedCapsule,
72
- recommendation: p.recommendation,
73
- fileCount: p.fileCount,
74
- totalHits: p.totalHits,
75
- impactScore: p.impactScore
76
- };
77
-
78
- if (isCompact) {
79
- const sampleOccurrences = [];
80
- const seenSampleFiles = new Set();
81
- for (const occ of (p.occurrences || [])) {
82
- if (!seenSampleFiles.has(occ.filePath)) {
83
- seenSampleFiles.add(occ.filePath);
84
- sampleOccurrences.push({
85
- file: occ.filePath,
86
- line: occ.line
87
- });
88
- if (sampleOccurrences.length >= 3) break;
89
- }
90
- }
91
-
92
- return {
93
- ...base,
94
- files: p.uniqueFiles || Array.from(new Set((p.occurrences || []).map((o) => o.filePath))),
95
- sampleOccurrences
96
- };
97
- }
98
-
99
- return {
100
- ...base,
101
- occurrences: p.occurrences
102
- };
103
- });
104
-
105
- return {
106
- scannedDir: targetDir,
107
- totalCandidates: candidates.length,
108
- compact: isCompact,
109
- candidates
110
- };
111
- };
112
-
113
- const handleAudit = (args = {}, cwd = process.cwd()) => {
114
- const rawTarget = args.path || (fs.existsSync(path.resolve(cwd, 'src')) ? 'src' : '.');
115
- const resolvedTarget = path.resolve(cwd, rawTarget);
116
- const isFile = fs.existsSync(resolvedTarget) && fs.statSync(resolvedTarget).isFile();
117
-
118
- if (isFile) {
119
- const relPath = path.relative(cwd, resolvedTarget);
120
- const violations = auditFile(resolvedTarget, relPath);
121
- return {
122
- type: 'file',
123
- target: relPath,
124
- violationCount: violations.length,
125
- violations
126
- };
15
+ const parseCommand = (command, params) => {
16
+ const parts = command.trim().split(/\s+/);
17
+ const subCmd = parts[0];
18
+ if (subCmd === 'audit' || subCmd === 'check') return { action: subCmd, params: { path: parts[1] || 'src', ...params } };
19
+ if (subCmd === 'build') return { action: 'build', params: { dir: parts[1] || '.', ...params } };
20
+ if (['verify', 'typecheck', 'test'].includes(subCmd)) return { action: subCmd, params };
21
+ if (subCmd === 'read' || subCmd === 'r') {
22
+ const hasOutline = command.includes('--outline') || command.includes(' -o');
23
+ const symbolMatch = command.match(/(?:--symbol=|-s\s+|-s=)([^\s]+)/);
24
+ const lineMatch = parts[1]?.match(/^([^:]+):(\d+)(?:[-:](\d+))?$/);
25
+ const targetPath = lineMatch ? lineMatch[1] : parts[1];
26
+ const startLine = lineMatch ? parseInt(lineMatch[2], 10) : undefined;
27
+ const endLine = lineMatch && lineMatch[3] ? parseInt(lineMatch[3], 10) : undefined;
28
+ return { action: 'read', params: { path: targetPath, outline: hasOutline, symbol: symbolMatch ? symbolMatch[1] : undefined, startLine, endLine, ...params } };
127
29
  }
128
-
129
- const options = {
130
- model: args.model || 'blended',
131
- outputFile: null
132
- };
133
-
134
- const report = executeAstAudit(rawTarget, options);
135
-
136
- // Sync AST audit results to SQLite index database
137
- try {
138
- const syncRes = syncSearchIndex(rawTarget, cwd);
139
- if (syncRes?.db) {
140
- syncViolationsIndex(syncRes.db, report.violations);
141
- recordAuditSnapshot(syncRes.db, report);
142
- }
143
- } catch {
144
- // Continue if SQLite synchronization fails
30
+ if (subCmd === 'q' || subCmd === 'search') return { action: 'q', params: { query: parts.slice(1).join(' '), ...params } };
31
+ if (subCmd === 'team') {
32
+ const TEAM_ACTIONS = { status: 'team_status', feed: 'team_feed', task: 'team_task', lock: 'team_lock', inbox: 'team_inbox', dm: 'team_dm' };
33
+ return { action: TEAM_ACTIONS[parts[1] || 'status'] || 'team_task', params };
145
34
  }
146
-
147
- const isSevereViolation = (v) => {
148
- const isCritical = v.severity === 'CRITICAL';
149
- const isHigh = v.severity === 'HIGH';
150
- return isCritical || isHigh;
151
- };
152
-
153
- const hasCriticalOrHigh = report.violations.some(isSevereViolation);
154
- const hasViolations = report.violations.length > 0;
155
- const isStrictFail = Boolean(args.strict) && hasViolations;
156
- const hasMinScore = typeof args.minScore === 'number';
157
- const isScoreFail = hasMinScore && report.health.score < args.minScore;
158
-
159
- const hasFailingCondition = isStrictFail || isScoreFail || hasCriticalOrHigh;
160
- const isPassing = !hasFailingCondition;
161
-
162
- return {
163
- type: 'directory',
164
- target: rawTarget,
165
- health: report.health,
166
- metrics: report.metrics,
167
- aiSlop: report.aiSlop,
168
- hotspots: report.hotspots,
169
- totalViolations: report.totalViolations,
170
- violations: report.violations,
171
- contextAnalysis: report.contextAnalysis,
172
- isPassing
173
- };
174
- };
175
-
176
- const handleGenerateCapsule = (args = {}, cwd = process.cwd()) => {
177
- const { name, framework, tier = 'm', targetDir = null, lean = false, desc = '', description = '', dryRun = false } = args;
178
-
179
- const hasName = Boolean(name && name.trim());
180
- const hasValidFramework = Boolean(framework && ['react', 'vue', 'svelte'].includes(framework.toLowerCase()));
181
- const canGenerate = hasName && hasValidFramework;
182
-
183
- if (!canGenerate) {
184
- throw new Error('chemx_generate_capsule requires "name" and "framework" (react, vue, svelte).');
35
+ if (subCmd === 'project' || subCmd === 'coordinator') {
36
+ const subAction = parts[1] || 'status';
37
+ const rest = parts.slice(2).join(' ').replace(/^"|"$/g, '');
38
+ const extra = subAction === 'init' ? { goal: rest || params.goal } : { message: rest || params.message };
39
+ return { action: 'project', params: { subAction, ...extra, ...params } };
185
40
  }
186
-
187
- const result = createCapsuleFiles({
188
- name: name.trim(),
189
- framework: framework.toLowerCase(),
190
- tier: tier.toLowerCase(),
191
- targetParent: targetDir,
192
- isLean: Boolean(lean),
193
- cwd,
194
- desc: desc || description,
195
- dryRun: Boolean(dryRun)
196
- });
197
-
198
- return {
199
- success: true,
200
- dryRun: result.dryRun,
201
- capsuleName: result.capsuleName,
202
- pascalName: result.pascalName,
203
- framework: result.framework,
204
- tier: result.tier,
205
- targetDir: result.targetDir,
206
- relativeDir: result.relativeDir,
207
- filesCreated: result.filesCreated,
208
- previews: result.previews
209
- };
41
+ if (subCmd === 'autofix') return { action: 'autofix', params: { path: parts[1] || 'src', ...params } };
42
+ if (subCmd === 'trend' || subCmd === 'trends') return { action: 'trend', params };
43
+ return { action: subCmd, params };
210
44
  };
211
45
 
212
- const handleGetRefactorPrompt = (args = {}, cwd = process.cwd()) => {
213
- const targetDir = args.dir || (fs.existsSync(path.resolve(cwd, 'src')) ? 'src' : '.');
214
- const scope = args.scope || 'master';
215
- const report = executeAstAudit(targetDir, {});
216
-
217
- const PROMPT_BUILDERS = {
218
- 'grade-f': buildGradeFPrompt,
219
- 'grade-d': buildGradeDPrompt,
220
- 'grade-c': buildGradeCPrompt,
221
- 'grade-b': buildGradeBPrompt,
222
- 'ai-slop': buildAiSlopPrompt,
223
- 'hotspots': buildHotspotsPrompt,
224
- 'master': buildMasterPrompt
225
- };
226
-
227
- const builder = Object.prototype.hasOwnProperty.call(PROMPT_BUILDERS, scope)
228
- ? PROMPT_BUILDERS[scope]
229
- : buildMasterPrompt;
230
- const prompt = builder(report);
231
-
232
- return {
233
- targetDir,
234
- scope,
235
- prompt: prompt || 'No violations found for the requested scope.'
236
- };
237
- };
238
-
239
- const handleAuditBuild = async (args = {}, cwd = process.cwd()) => {
240
- const targetCwd = args.dir ? path.resolve(cwd, args.dir) : cwd;
241
- const rawArgs = ['--json'];
242
- if (args.command) {
243
- rawArgs.push('--', args.command);
244
- }
245
- return runBuildAudit(rawArgs, false, { print: false, cwd: targetCwd });
246
- };
247
-
248
- const handleAutofix = (args = {}, cwd = process.cwd()) => {
249
- return runAutofix(args.path, {
250
- dryRun: Boolean(args.dryRun),
251
- rules: args.rules,
252
- cwd
253
- });
254
- };
255
-
256
- const handleChemxTypecheck = async (args = {}, cwd = process.cwd()) => {
257
- const baseCwd = resolveTargetCwd(cwd);
258
- const targetCwd = args.dir ? path.resolve(baseCwd, args.dir) : baseCwd;
259
- return runTypecheckAudit([], false, {
260
- json: true,
261
- command: args.command,
262
- print: false,
263
- cwd: targetCwd
264
- });
265
- };
266
-
267
- const handleChemxTest = async (args = {}, cwd = process.cwd()) => {
268
- const baseCwd = resolveTargetCwd(cwd);
269
- const targetCwd = args.dir ? path.resolve(baseCwd, args.dir) : baseCwd;
270
- return runTestAudit([], false, {
271
- json: true,
272
- command: args.command,
273
- print: false,
274
- cwd: targetCwd
275
- });
276
- };
277
-
278
- const handleChemxVerify = async (args = {}, cwd = process.cwd()) => {
279
- const baseCwd = resolveTargetCwd(cwd);
280
- return runProjectVerify([], false, {
281
- json: true,
282
- targetDir: args.dir,
283
- includeBuild: Boolean(args.includeBuild),
284
- print: false,
285
- cwd: baseCwd
286
- });
46
+ const DISPATCHER = {
47
+ audit: handleAudit, trend: handleChemxTrend, build: handleAuditBuild, verify: handleChemxVerify,
48
+ typecheck: handleChemxTypecheck, test: handleChemxTest, check: handleChemxCheck,
49
+ patch: handleChemxPatch, write: handleChemxWrite, read: handleChemxRead, r: handleChemxRead,
50
+ team: handleChemxTeam, team_inbox: handleChemxTeamInbox, team_dm: handleChemxTeamDm,
51
+ team_status: handleChemxTeamStatus, team_feed: handleChemxTeamFeed, team_post: handleChemxTeamPost,
52
+ team_task: handleChemxTeamTask, team_lock: handleChemxTeamLock, q: handleChemxQ, search: handleChemxQ,
53
+ autofix: handleAutofix, generate: handleGenerateCapsule, patterns: handleQueryPatterns,
54
+ issue: handleChemxReportIssue, project: handleChemxProject, coordinator: handleChemxProject
287
55
  };
288
56
 
289
- const handleChemx = async (args = {}, cwd = process.cwd()) => {
290
- let action = args.action;
291
- let params = args.params || {};
292
-
57
+ export const handleChemx = async (args = {}, cwd = process.cwd()) => {
58
+ let { action, params = {} } = args;
293
59
  if (args.command && typeof args.command === 'string') {
294
- const parts = args.command.trim().split(/\s+/);
295
- const subCmd = parts[0];
296
- if (subCmd === 'audit') {
297
- action = 'audit';
298
- params = { path: parts[1] || 'src', ...params };
299
- } else if (subCmd === 'build') {
300
- action = 'build';
301
- params = { dir: parts[1] || '.', ...params };
302
- } else if (subCmd === 'verify') {
303
- action = 'verify';
304
- } else if (subCmd === 'typecheck') {
305
- action = 'typecheck';
306
- } else if (subCmd === 'test') {
307
- action = 'test';
308
- } else if (subCmd === 'check') {
309
- action = 'check';
310
- params = { path: parts[1] || 'src', ...params };
311
- } else if (subCmd === 'read') {
312
- action = 'read';
313
- const hasOutline = args.command.includes('--outline');
314
- const symbolMatch = args.command.match(/--symbol=([^\s]+)/);
315
- params = {
316
- path: parts[1],
317
- outline: hasOutline,
318
- symbol: symbolMatch ? symbolMatch[1] : undefined,
319
- ...params
320
- };
321
- } else if (subCmd === 'q' || subCmd === 'search') {
322
- action = 'q';
323
- params = { query: parts.slice(1).join(' '), ...params };
324
- } else if (subCmd === 'team') {
325
- const teamAction = parts[1] || 'status';
326
- if (teamAction === 'status') action = 'team_status';
327
- else if (teamAction === 'feed') action = 'team_feed';
328
- else if (teamAction === 'task') action = 'team_task';
329
- else if (teamAction === 'lock') action = 'team_lock';
330
- else action = 'team_task';
331
- } else if (subCmd === 'autofix') {
332
- action = 'autofix';
333
- params = { path: parts[1] || 'src', ...params };
334
- }
60
+ const parsed = parseCommand(args.command, params);
61
+ action = parsed.action;
62
+ params = parsed.params;
335
63
  }
336
-
337
- const DISPATCHER = {
338
- audit: handleAudit,
339
- build: handleAuditBuild,
340
- verify: handleChemxVerify,
341
- typecheck: handleChemxTypecheck,
342
- test: handleChemxTest,
343
- check: handleChemxCheck,
344
- patch: handleChemxPatch,
345
- write: handleChemxWrite,
346
- read: handleChemxRead,
347
- team: handleChemxTeamTask,
348
- team_status: handleChemxTeamStatus,
349
- team_feed: handleChemxTeamFeed,
350
- team_post: handleChemxTeamPost,
351
- team_task: handleChemxTeamTask,
352
- team_lock: handleChemxTeamLock,
353
- q: handleChemxQ,
354
- search: handleChemxQ,
355
- autofix: handleAutofix,
356
- generate: handleGenerateCapsule,
357
- patterns: handleQueryPatterns,
358
- issue: handleChemxReportIssue
359
- };
360
-
361
- const handler = Object.prototype.hasOwnProperty.call(DISPATCHER, action)
362
- ? DISPATCHER[action]
363
- : Tools[`chemx_${action}`];
364
-
64
+ const handler = Object.hasOwn(DISPATCHER, action) ? DISPATCHER[action] : Tools[`chemx_${action}`];
365
65
  if (!handler) {
366
66
  throw new Error(`Unknown Chemical X action: "${action}". Valid actions: ${Object.keys(DISPATCHER).join(', ')}`);
367
67
  }
368
-
369
68
  return handler(params, cwd);
370
69
  };
371
70
 
372
71
  export const Tools = {
373
- chemx: handleChemx,
374
- chemx_query_patterns: handleQueryPatterns,
375
- chemx_audit: handleAudit,
376
- chemx_generate_capsule: handleGenerateCapsule,
377
- chemx_get_refactor_prompt: handleGetRefactorPrompt,
378
- chemx_audit_build: handleAuditBuild,
379
- chemx_autofix: handleAutofix,
380
- chemx_q: handleChemxQ,
381
- chemx_read: handleChemxRead,
382
- chemx_patch: handleChemxPatch,
383
- chemx_write: handleChemxWrite,
384
- chemx_check: handleChemxCheck,
385
- chemx_typecheck: handleChemxTypecheck,
386
- chemx_test: handleChemxTest,
387
- chemx_verify: handleChemxVerify,
388
- chemx_team_status: handleChemxTeamStatus,
389
- chemx_team_feed: handleChemxTeamFeed,
390
- chemx_team_post: handleChemxTeamPost,
391
- chemx_team_task: handleChemxTeamTask,
392
- chemx_team_lock: handleChemxTeamLock,
72
+ chemx: handleChemx, chemx_query_patterns: handleQueryPatterns, chemx_audit: handleAudit,
73
+ chemx_generate_capsule: handleGenerateCapsule, chemx_get_refactor_prompt: handleGetRefactorPrompt,
74
+ chemx_audit_build: handleAuditBuild, chemx_autofix: handleAutofix, chemx_q: handleChemxQ,
75
+ chemx_read: handleChemxRead, chemx_patch: handleChemxPatch, chemx_write: handleChemxWrite,
76
+ chemx_check: handleChemxCheck, chemx_typecheck: handleChemxTypecheck, chemx_test: handleChemxTest,
77
+ chemx_verify: handleChemxVerify, chemx_team_status: handleChemxTeamStatus,
78
+ chemx_team_feed: handleChemxTeamFeed, chemx_team_post: handleChemxTeamPost,
79
+ chemx_team_task: handleChemxTeamTask, chemx_team_lock: handleChemxTeamLock,
393
80
  chemx_report_issue: handleChemxReportIssue
394
81
  };
395
82
 
83
+ const EXTENDED_TOOLS = {
84
+ chemx_team: handleChemxTeam,
85
+ chemx_team_inbox: handleChemxTeamInbox,
86
+ chemx_team_dm: handleChemxTeamDm
87
+ };
88
+
89
+ const resolveToolHandler = (name) => {
90
+ if (Object.hasOwn(Tools, name)) return Tools[name];
91
+ if (Object.hasOwn(EXTENDED_TOOLS, name)) return EXTENDED_TOOLS[name];
92
+ return null;
93
+ };
94
+
396
95
  export const executeMcpTool = async (name, args = {}, cwd = process.cwd()) => {
397
96
  const toolName = name === 'chemx_master' ? 'chemx' : name;
398
- const handle = Object.prototype.hasOwnProperty.call(Tools, toolName) ? Tools[toolName] : null;
399
- if (!handle) {
400
- throw new Error(`Unknown tool: ${name}`);
401
- }
97
+ const handle = resolveToolHandler(toolName);
98
+ if (!handle) throw new Error(`Unknown tool: ${name}`);
402
99
  return handle(args, cwd);
403
100
  };
404
-
package/cli/mutators.js CHANGED
@@ -2,6 +2,7 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { toPascalCase } from './generator-templates.js';
4
4
  import { ANSI } from './theme.js';
5
+ import { runAutofix } from './audit/autofix.js';
5
6
 
6
7
  export const resolveCapsuleFiles = (targetPath, cwd = process.cwd()) => {
7
8
  const abs = path.resolve(cwd, targetPath);
@@ -194,29 +195,17 @@ export const autoFixFile = (targetFile, options = {}) => {
194
195
  throw new Error(`File not found: ${targetFile}`);
195
196
  }
196
197
 
197
- let content = fs.readFileSync(absPath, 'utf-8');
198
- let replacementsCount = 0;
199
-
200
- if (content.includes('\u2014')) {
201
- const matches = content.match(/\u2014/g);
202
- replacementsCount += matches ? matches.length : 1;
203
- content = content.replace(/\u2014/g, ' - ');
204
- }
205
-
206
- const timeoutMatch = content.match(/setTimeout\(([^,]+),\s*0\)/g);
207
- if (timeoutMatch) {
208
- replacementsCount += timeoutMatch.length;
209
- content = content.replace(/setTimeout\(([^,]+),\s*0\)/g, 'queueMicrotask($1)');
210
- }
211
-
212
- if (replacementsCount > 0) {
213
- fs.writeFileSync(absPath, content, 'utf-8');
198
+ const stat = fs.statSync(absPath);
199
+ if (stat.isDirectory()) {
200
+ return runAutofix(absPath, options);
214
201
  }
215
202
 
203
+ const result = runAutofix(absPath, options);
216
204
  return {
217
205
  file: path.relative(process.cwd(), absPath),
218
- fixed: replacementsCount > 0,
219
- replacementsCount
206
+ fixed: result.filesChanged > 0,
207
+ replacementsCount: result.totalFixes,
208
+ fixes: result.fixes
220
209
  };
221
210
  };
222
211
 
@@ -258,10 +247,8 @@ export const runMutatorCli = async (rawArgs = [], isCli = true) => {
258
247
  }
259
248
  result = addActionToController(target, value, { dryRun: isDryRun });
260
249
  } else if (command === 'fix') {
261
- if (!target) {
262
- throw new Error('Usage: chemx fix <file-path>');
263
- }
264
- result = autoFixFile(target);
250
+ const fixTarget = target || 'src';
251
+ result = autoFixFile(fixTarget, { dryRun: isDryRun });
265
252
  } else {
266
253
  throw new Error(`Unknown mutator command "${command}". Available: add:prop, add:state, add:action, fix`);
267
254
  }
@@ -40,11 +40,11 @@ export const PILLARS = [
40
40
  id: 'p4_composables',
41
41
  key: 'composableContracts',
42
42
  title: 'Pillar 4: Molecular Composable Contracts',
43
- summary: '3 to 5 return properties max, safe destructuring, auto-cleanup.',
44
- cursorRule: 'Composables: return plain objects with refs, strictly 3-5 properties max, auto-cleanup on unmount.',
43
+ summary: 'Classified return shape (State, Status, flat verb-prefixed Actions), safe destructuring, auto-cleanup.',
44
+ cursorRule: 'Composables: return plain objects with refs, classify strictly into State/Status/Actions, auto-cleanup on unmount.',
45
45
  agentsDirective: `### Pillar 4: Molecular Composable Contracts
46
46
  - Safe Destructuring: Return plain objects containing individual refs, computeds, and pure functions. Never return raw reactive objects.
47
- - Return Limit: Strictly limit returns to State + Status + Actions (3 to 5 return properties maximum).
47
+ - Shape-Classification Contract: Structure return values strictly into three canonical buckets: State (domain data), Status (lifecycle/health info), and Actions (verb-prefixed functions flat at top level). No arbitrary property count ceiling applies. Nested action wrappers ('actions: {}') are strictly prohibited.
48
48
  - Lifecycle Teardown: Clean up listeners, timers, and observers automatically on scope disposal.`
49
49
  },
50
50
  {
@@ -184,3 +184,50 @@ export const detectTierBaseDir = (tier, cwd = process.cwd()) => {
184
184
 
185
185
  return '.';
186
186
  };
187
+
188
+ const TAILWIND_PACKAGES = [
189
+ 'tailwindcss',
190
+ '@tailwindcss/vite',
191
+ '@tailwindcss/postcss',
192
+ '@tailwindcss/cli'
193
+ ];
194
+
195
+ const SCSS_PACKAGES = ['sass', 'sass-embedded'];
196
+
197
+ const TAILWIND_CONFIG_NAMES = [
198
+ 'tailwind.config.js',
199
+ 'tailwind.config.ts',
200
+ 'tailwind.config.cjs',
201
+ 'tailwind.config.mjs'
202
+ ];
203
+
204
+ export const detectStylingStack = (cwd = process.cwd()) => {
205
+ const pkgPath = path.resolve(cwd, 'package.json');
206
+ let hasTailwind = false;
207
+ let hasScss = false;
208
+
209
+ if (fs.existsSync(pkgPath)) {
210
+ try {
211
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
212
+ const deps = { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) };
213
+
214
+ hasTailwind = TAILWIND_PACKAGES.some((pkgName) => Boolean(deps[pkgName]));
215
+ hasScss = SCSS_PACKAGES.some((pkgName) => Boolean(deps[pkgName]));
216
+ } catch {
217
+ // ignore parse errors
218
+ }
219
+ }
220
+
221
+ if (!hasTailwind) {
222
+ hasTailwind = TAILWIND_CONFIG_NAMES.some((cfg) => fs.existsSync(path.resolve(cwd, cfg)));
223
+ }
224
+
225
+ let styleFlavor = 'css';
226
+ if (hasTailwind) {
227
+ styleFlavor = 'tailwind';
228
+ } else if (hasScss) {
229
+ styleFlavor = 'scss';
230
+ }
231
+
232
+ return { hasTailwind, hasScss, styleFlavor };
233
+ };
@@ -0,0 +1,60 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { readTokenOptimized, runReaderCli } from './reader.js';
4
+ import { ALLOWED_COMMANDS } from './index.js';
5
+ import { handleChemx } from './mcp/tools.js';
6
+
7
+ describe('Reader Shorthand Syntax', () => {
8
+ it('includes r in ALLOWED_COMMANDS', () => {
9
+ assert.ok(ALLOWED_COMMANDS.has('r'), 'ALLOWED_COMMANDS should include "r"');
10
+ });
11
+
12
+ it('supports path:start-end line range in readTokenOptimized', () => {
13
+ const res = readTokenOptimized('package.json:1-5');
14
+ assert.equal(res.file, 'package.json');
15
+ assert.equal(res.startLine, 1);
16
+ assert.equal(res.endLine, 5);
17
+ assert.equal(res.lineCount, 5);
18
+ });
19
+
20
+ it('supports path:start:end line range in readTokenOptimized', () => {
21
+ const res = readTokenOptimized('package.json:2:6');
22
+ assert.equal(res.file, 'package.json');
23
+ assert.equal(res.startLine, 2);
24
+ assert.equal(res.endLine, 6);
25
+ });
26
+
27
+ it('supports runReaderCli with -o outline flag', () => {
28
+ const res = runReaderCli(['cli/commands/cmd-router.js', '-o'], false);
29
+ assert.ok(res);
30
+ assert.equal(res.mode, 'outline');
31
+ assert.ok(res.content.includes('export function dispatchCommand'));
32
+ });
33
+
34
+ it('supports runReaderCli with -s symbol flag', () => {
35
+ const res = runReaderCli(['cli/commands/cmd-router.js', '-s', 'dispatchCommand'], false);
36
+ assert.ok(res);
37
+ assert.equal(res.mode, 'symbol');
38
+ assert.equal(res.symbol, 'dispatchCommand');
39
+ });
40
+
41
+ it('supports runReaderCli with path:start-end colon range', () => {
42
+ const res = runReaderCli(['package.json:1-4'], false);
43
+ assert.ok(res);
44
+ assert.equal(res.startLine, 1);
45
+ assert.equal(res.endLine, 4);
46
+ assert.equal(res.lineCount, 4);
47
+ });
48
+
49
+ it('supports MCP chemx({ action: "r" })', async () => {
50
+ const output = await handleChemx({ action: 'r', params: { path: 'package.json:1-3' } });
51
+ assert.ok(output.includes('package.json'));
52
+ assert.ok(output.includes('"name": "@chemx/starter-kit"'));
53
+ });
54
+
55
+ it('supports MCP chemx({ command: "r path:1-3" })', async () => {
56
+ const output = await handleChemx({ command: 'r package.json:1-3' });
57
+ assert.ok(output.includes('package.json'));
58
+ assert.ok(output.includes('"name": "@chemx/starter-kit"'));
59
+ });
60
+ });