@nerviq/cli 1.20.0 → 1.21.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 (185) hide show
  1. package/LICENSE +23 -23
  2. package/README.md +2 -2
  3. package/bin/cli.js +1 -0
  4. package/package.json +2 -1
  5. package/src/activity.js +1039 -1039
  6. package/src/adoption-advisor.js +299 -299
  7. package/src/aider/config-parser.js +166 -166
  8. package/src/aider/context.js +6 -2
  9. package/src/aider/deep-review.js +316 -316
  10. package/src/aider/domain-packs.js +303 -303
  11. package/src/aider/freshness.js +93 -93
  12. package/src/aider/governance.js +253 -253
  13. package/src/aider/interactive.js +334 -334
  14. package/src/aider/mcp-packs.js +329 -329
  15. package/src/aider/patch.js +214 -214
  16. package/src/aider/plans.js +186 -186
  17. package/src/aider/premium.js +360 -360
  18. package/src/aider/setup.js +404 -404
  19. package/src/aider/techniques.js +312 -67
  20. package/src/analyze.js +951 -951
  21. package/src/anti-patterns.js +485 -485
  22. package/src/audit/instruction-files.js +180 -180
  23. package/src/audit/recommendations.js +577 -577
  24. package/src/auto-suggest.js +154 -154
  25. package/src/badge.js +13 -13
  26. package/src/behavioral-drift.js +801 -801
  27. package/src/benchmark.js +67 -67
  28. package/src/catalog.js +103 -103
  29. package/src/certification.js +128 -128
  30. package/src/codex/config-parser.js +183 -183
  31. package/src/codex/context.js +223 -223
  32. package/src/codex/deep-review.js +493 -493
  33. package/src/codex/domain-packs.js +394 -394
  34. package/src/codex/freshness.js +84 -84
  35. package/src/codex/governance.js +192 -192
  36. package/src/codex/interactive.js +618 -618
  37. package/src/codex/mcp-packs.js +914 -914
  38. package/src/codex/patch.js +209 -209
  39. package/src/codex/plans.js +251 -251
  40. package/src/codex/premium.js +614 -614
  41. package/src/codex/setup.js +591 -591
  42. package/src/context.js +10 -4
  43. package/src/continuous-ops.js +681 -681
  44. package/src/copilot/activity.js +309 -309
  45. package/src/copilot/deep-review.js +346 -346
  46. package/src/copilot/domain-packs.js +372 -372
  47. package/src/copilot/freshness.js +57 -57
  48. package/src/copilot/governance.js +222 -222
  49. package/src/copilot/interactive.js +406 -406
  50. package/src/copilot/mcp-packs.js +826 -826
  51. package/src/copilot/plans.js +253 -253
  52. package/src/copilot/premium.js +451 -451
  53. package/src/copilot/setup.js +488 -488
  54. package/src/cost-tracking.js +61 -61
  55. package/src/cursor/activity.js +301 -301
  56. package/src/cursor/config-parser.js +265 -265
  57. package/src/cursor/context.js +256 -256
  58. package/src/cursor/deep-review.js +334 -334
  59. package/src/cursor/domain-packs.js +368 -368
  60. package/src/cursor/freshness.js +65 -65
  61. package/src/cursor/governance.js +229 -229
  62. package/src/cursor/interactive.js +391 -391
  63. package/src/cursor/mcp-packs.js +828 -828
  64. package/src/cursor/plans.js +254 -254
  65. package/src/cursor/premium.js +469 -469
  66. package/src/cursor/setup.js +488 -488
  67. package/src/dashboard.js +493 -493
  68. package/src/deep-review.js +428 -428
  69. package/src/deprecation.js +98 -98
  70. package/src/diff-only.js +280 -280
  71. package/src/doctor.js +119 -119
  72. package/src/domain-pack-expansion.js +1033 -1033
  73. package/src/domain-packs.js +387 -387
  74. package/src/feedback.js +178 -178
  75. package/src/fix-engine.js +783 -783
  76. package/src/fix-prompts.js +122 -122
  77. package/src/formatters/sarif.js +115 -115
  78. package/src/freshness.js +74 -74
  79. package/src/gemini/config-parser.js +275 -275
  80. package/src/gemini/deep-review.js +559 -559
  81. package/src/gemini/domain-packs.js +393 -393
  82. package/src/gemini/freshness.js +66 -66
  83. package/src/gemini/governance.js +201 -201
  84. package/src/gemini/interactive.js +860 -860
  85. package/src/gemini/mcp-packs.js +915 -915
  86. package/src/gemini/plans.js +269 -269
  87. package/src/gemini/premium.js +760 -760
  88. package/src/gemini/setup.js +692 -692
  89. package/src/governance.js +72 -72
  90. package/src/harmony/add.js +68 -68
  91. package/src/harmony/advisor.js +333 -333
  92. package/src/harmony/canon.js +565 -565
  93. package/src/harmony/cli.js +591 -591
  94. package/src/harmony/drift.js +401 -401
  95. package/src/harmony/governance.js +313 -313
  96. package/src/harmony/memory.js +239 -239
  97. package/src/harmony/sync.js +475 -475
  98. package/src/harmony/watch.js +370 -370
  99. package/src/hook-validation.js +342 -342
  100. package/src/index.js +271 -271
  101. package/src/init.js +184 -184
  102. package/src/instruction-surfaces.js +185 -185
  103. package/src/integrations.js +144 -144
  104. package/src/interactive.js +118 -118
  105. package/src/locales/en.json +1 -1
  106. package/src/locales/es.json +1 -1
  107. package/src/mcp-packs.js +830 -830
  108. package/src/mcp-server.js +726 -726
  109. package/src/mcp-validation.js +337 -337
  110. package/src/nerviq-sync.json +7 -7
  111. package/src/opencode/config-parser.js +109 -109
  112. package/src/opencode/context.js +247 -247
  113. package/src/opencode/deep-review.js +313 -313
  114. package/src/opencode/domain-packs.js +262 -262
  115. package/src/opencode/freshness.js +66 -66
  116. package/src/opencode/governance.js +159 -159
  117. package/src/opencode/interactive.js +392 -392
  118. package/src/opencode/mcp-packs.js +705 -705
  119. package/src/opencode/patch.js +184 -184
  120. package/src/opencode/plans.js +231 -231
  121. package/src/opencode/premium.js +413 -413
  122. package/src/opencode/setup.js +449 -449
  123. package/src/opencode/techniques.js +27 -27
  124. package/src/operating-profile.js +574 -574
  125. package/src/org.js +152 -152
  126. package/src/permission-rules.js +218 -218
  127. package/src/plans.js +839 -839
  128. package/src/platform-change-manifest.js +86 -86
  129. package/src/plugins.js +110 -110
  130. package/src/policy-layers.js +210 -210
  131. package/src/profiles.js +124 -124
  132. package/src/prompt-injection.js +74 -74
  133. package/src/public-api.js +173 -173
  134. package/src/recommendation-rules.js +84 -84
  135. package/src/repo-archetype.js +386 -386
  136. package/src/secret-patterns.js +39 -39
  137. package/src/server.js +527 -527
  138. package/src/setup/analysis.js +607 -607
  139. package/src/setup/runtime.js +172 -172
  140. package/src/setup.js +677 -677
  141. package/src/shared/capabilities.js +194 -194
  142. package/src/source-urls.js +132 -132
  143. package/src/stack-checks.js +565 -565
  144. package/src/supplemental-checks.js +13 -13
  145. package/src/synergy/adaptive.js +261 -261
  146. package/src/synergy/compensation.js +137 -137
  147. package/src/synergy/evidence.js +193 -193
  148. package/src/synergy/learning.js +199 -199
  149. package/src/synergy/patterns.js +227 -227
  150. package/src/synergy/ranking.js +83 -83
  151. package/src/synergy/report.js +165 -165
  152. package/src/synergy/routing.js +146 -146
  153. package/src/techniques/api.js +407 -407
  154. package/src/techniques/automation.js +316 -316
  155. package/src/techniques/compliance.js +257 -257
  156. package/src/techniques/hygiene.js +294 -294
  157. package/src/techniques/instructions.js +243 -243
  158. package/src/techniques/observability.js +226 -226
  159. package/src/techniques/optimization.js +142 -142
  160. package/src/techniques/quality.js +318 -318
  161. package/src/techniques/security.js +237 -237
  162. package/src/techniques/shared.js +443 -443
  163. package/src/techniques/stacks.js +2294 -2294
  164. package/src/techniques/tools.js +106 -106
  165. package/src/techniques/workflow.js +413 -413
  166. package/src/techniques.js +81 -81
  167. package/src/terminology.js +73 -73
  168. package/src/token-estimate.js +35 -35
  169. package/src/usage-patterns.js +99 -99
  170. package/src/verification-metadata.js +145 -145
  171. package/src/watch.js +247 -247
  172. package/src/windsurf/activity.js +302 -302
  173. package/src/windsurf/config-parser.js +267 -267
  174. package/src/windsurf/context.js +120 -10
  175. package/src/windsurf/deep-review.js +337 -337
  176. package/src/windsurf/domain-packs.js +370 -370
  177. package/src/windsurf/freshness.js +36 -36
  178. package/src/windsurf/governance.js +231 -231
  179. package/src/windsurf/interactive.js +388 -388
  180. package/src/windsurf/mcp-packs.js +792 -792
  181. package/src/windsurf/plans.js +247 -247
  182. package/src/windsurf/premium.js +468 -468
  183. package/src/windsurf/setup.js +471 -471
  184. package/src/windsurf/techniques.js +155 -33
  185. package/src/workspace.js +375 -375
@@ -1,74 +1,74 @@
1
- 'use strict';
2
-
3
- const PROMPT_INJECTION_PATTERNS = [
4
- /\bignore (?:all )?(?:previous|earlier|above) instructions?\b/i,
5
- /\boverride (?:the )?(?:system|developer|safety|previous) instructions?\b/i,
6
- /\breveal (?:your|the) (?:system|developer) prompt\b/i,
7
- /\bbypass (?:all )?(?:safety|guardrails|restrictions|protections)\b/i,
8
- /\bdisable (?:the )?(?:guardrails|safety checks?)\b/i,
9
- /\bact as (?:the )?(?:system|developer)\b/i,
10
- /\breport (?:that )?(?:everything is )?perfect(?: and score 100\/100)?\b/i,
11
- /\bscore 100\/100\b/i,
12
- /\bexfiltrate\b.*\b(?:secret|token|credential|password)\b/i,
13
- ];
14
-
15
- const TRUST_BOUNDARY_PATTERNS = [
16
- /\btreat(?: every| all)?(?: string| file| repo(?:sitory)?| external)?[\w\s,-]{0,80}\buntrusted\b/i,
17
- /\bnever follow instructions embedded in\b/i,
18
- /\b(?:repo(?:sitory)? files?|file contents?|web(?:site|page)? content|fetched content|external content|mcp responses?)\b[\w\s,-]{0,120}\b(?:data|quoted)\b[\w\s,-]{0,80}\bnot instructions\b/i,
19
- /\bmcp responses?\b[\w\s,-]{0,80}\buntrusted\b/i,
20
- /\bfile contents?\b[\w\s,-]{0,80}\buntrusted\b/i,
21
- /\bprompt injection\b[\w\s,-]{0,120}\b(?:defense|resistance|guard|boundary)\b/i,
22
- ];
23
-
24
- function containsPromptInjectionPattern(text) {
25
- const normalized = String(text || '');
26
- return PROMPT_INJECTION_PATTERNS.some((pattern) => {
27
- pattern.lastIndex = 0;
28
- return pattern.test(normalized);
29
- });
30
- }
31
-
32
- function hasPromptInjectionDefenseGuidance(text) {
33
- const normalized = String(text || '');
34
- if (!normalized.trim()) return false;
35
- return TRUST_BOUNDARY_PATTERNS.some((pattern) => {
36
- pattern.lastIndex = 0;
37
- return pattern.test(normalized);
38
- });
39
- }
40
-
41
- function hasMcpPromptInjectionDefenseGuidance(text) {
42
- const normalized = String(text || '');
43
- if (!/\bmcp\b/i.test(normalized)) return false;
44
- return hasPromptInjectionDefenseGuidance(normalized);
45
- }
46
-
47
- function collectHookBlocks(settings) {
48
- if (!settings || !settings.hooks || typeof settings.hooks !== 'object') return [];
49
- const blocks = [];
50
- for (const [eventName, entries] of Object.entries(settings.hooks)) {
51
- if (!Array.isArray(entries)) continue;
52
- for (const entry of entries) {
53
- blocks.push({ eventName, entry });
54
- }
55
- }
56
- return blocks;
57
- }
58
-
59
- function hasInjectionDefenseHookConfigured(settings) {
60
- return collectHookBlocks(settings).some(({ eventName, entry }) => {
61
- if (eventName !== 'PostToolUse') return false;
62
- const matcher = `${entry && entry.matcher ? entry.matcher : ''}`;
63
- if (!/WebFetch|WebSearch|Read|Grep|Glob|mcp__/i.test(matcher)) return false;
64
- const hooks = Array.isArray(entry && entry.hooks) ? entry.hooks : [];
65
- return hooks.some((hook) => /injection|prompt|sanitize|untrusted/i.test(`${hook && hook.command ? hook.command : ''}`));
66
- });
67
- }
68
-
69
- module.exports = {
70
- containsPromptInjectionPattern,
71
- hasPromptInjectionDefenseGuidance,
72
- hasMcpPromptInjectionDefenseGuidance,
73
- hasInjectionDefenseHookConfigured,
74
- };
1
+ 'use strict';
2
+
3
+ const PROMPT_INJECTION_PATTERNS = [
4
+ /\bignore (?:all )?(?:previous|earlier|above) instructions?\b/i,
5
+ /\boverride (?:the )?(?:system|developer|safety|previous) instructions?\b/i,
6
+ /\breveal (?:your|the) (?:system|developer) prompt\b/i,
7
+ /\bbypass (?:all )?(?:safety|guardrails|restrictions|protections)\b/i,
8
+ /\bdisable (?:the )?(?:guardrails|safety checks?)\b/i,
9
+ /\bact as (?:the )?(?:system|developer)\b/i,
10
+ /\breport (?:that )?(?:everything is )?perfect(?: and score 100\/100)?\b/i,
11
+ /\bscore 100\/100\b/i,
12
+ /\bexfiltrate\b.*\b(?:secret|token|credential|password)\b/i,
13
+ ];
14
+
15
+ const TRUST_BOUNDARY_PATTERNS = [
16
+ /\btreat(?: every| all)?(?: string| file| repo(?:sitory)?| external)?[\w\s,-]{0,80}\buntrusted\b/i,
17
+ /\bnever follow instructions embedded in\b/i,
18
+ /\b(?:repo(?:sitory)? files?|file contents?|web(?:site|page)? content|fetched content|external content|mcp responses?)\b[\w\s,-]{0,120}\b(?:data|quoted)\b[\w\s,-]{0,80}\bnot instructions\b/i,
19
+ /\bmcp responses?\b[\w\s,-]{0,80}\buntrusted\b/i,
20
+ /\bfile contents?\b[\w\s,-]{0,80}\buntrusted\b/i,
21
+ /\bprompt injection\b[\w\s,-]{0,120}\b(?:defense|resistance|guard|boundary)\b/i,
22
+ ];
23
+
24
+ function containsPromptInjectionPattern(text) {
25
+ const normalized = String(text || '');
26
+ return PROMPT_INJECTION_PATTERNS.some((pattern) => {
27
+ pattern.lastIndex = 0;
28
+ return pattern.test(normalized);
29
+ });
30
+ }
31
+
32
+ function hasPromptInjectionDefenseGuidance(text) {
33
+ const normalized = String(text || '');
34
+ if (!normalized.trim()) return false;
35
+ return TRUST_BOUNDARY_PATTERNS.some((pattern) => {
36
+ pattern.lastIndex = 0;
37
+ return pattern.test(normalized);
38
+ });
39
+ }
40
+
41
+ function hasMcpPromptInjectionDefenseGuidance(text) {
42
+ const normalized = String(text || '');
43
+ if (!/\bmcp\b/i.test(normalized)) return false;
44
+ return hasPromptInjectionDefenseGuidance(normalized);
45
+ }
46
+
47
+ function collectHookBlocks(settings) {
48
+ if (!settings || !settings.hooks || typeof settings.hooks !== 'object') return [];
49
+ const blocks = [];
50
+ for (const [eventName, entries] of Object.entries(settings.hooks)) {
51
+ if (!Array.isArray(entries)) continue;
52
+ for (const entry of entries) {
53
+ blocks.push({ eventName, entry });
54
+ }
55
+ }
56
+ return blocks;
57
+ }
58
+
59
+ function hasInjectionDefenseHookConfigured(settings) {
60
+ return collectHookBlocks(settings).some(({ eventName, entry }) => {
61
+ if (eventName !== 'PostToolUse') return false;
62
+ const matcher = `${entry && entry.matcher ? entry.matcher : ''}`;
63
+ if (!/WebFetch|WebSearch|Read|Grep|Glob|mcp__/i.test(matcher)) return false;
64
+ const hooks = Array.isArray(entry && entry.hooks) ? entry.hooks : [];
65
+ return hooks.some((hook) => /injection|prompt|sanitize|untrusted/i.test(`${hook && hook.command ? hook.command : ''}`));
66
+ });
67
+ }
68
+
69
+ module.exports = {
70
+ containsPromptInjectionPattern,
71
+ hasPromptInjectionDefenseGuidance,
72
+ hasMcpPromptInjectionDefenseGuidance,
73
+ hasInjectionDefenseHookConfigured,
74
+ };
package/src/public-api.js CHANGED
@@ -1,173 +1,173 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { audit } = require('./audit');
4
- const { harmonyAudit } = require('./harmony/audit');
5
- const { generateCatalog } = require('./catalog');
6
- const { compoundAudit, calculateAmplification } = require('./synergy/evidence');
7
- const { analyzeCompensation } = require('./synergy/compensation');
8
- const { discoverPatterns } = require('./synergy/patterns');
9
- const { rankRecommendations } = require('./synergy/ranking');
10
- const { generateSynergyReport } = require('./synergy/report');
11
- const { routeTask } = require('./synergy/routing');
12
- const { CodexProjectContext } = require('./codex/context');
13
- const { GeminiProjectContext } = require('./gemini/context');
14
- const { CopilotProjectContext } = require('./copilot/context');
15
- const { CursorProjectContext } = require('./cursor/context');
16
- const { WindsurfProjectContext } = require('./windsurf/context');
17
- const { AiderProjectContext } = require('./aider/context');
18
- const { OpenCodeProjectContext } = require('./opencode/context');
19
-
20
- const PLATFORM_ORDER = [
21
- 'claude',
22
- 'codex',
23
- 'gemini',
24
- 'copilot',
25
- 'cursor',
26
- 'windsurf',
27
- 'aider',
28
- 'opencode',
29
- ];
30
-
31
- const PLATFORM_DETECTORS = {
32
- claude: (dir) => exists(path.join(dir, 'CLAUDE.md')) || exists(path.join(dir, '.claude')),
33
- codex: (dir) => CodexProjectContext.isCodexRepo(dir),
34
- gemini: (dir) => GeminiProjectContext.isGeminiRepo(dir),
35
- copilot: (dir) => CopilotProjectContext.isCopilotRepo(dir),
36
- cursor: (dir) => CursorProjectContext.isCursorRepo(dir),
37
- windsurf: (dir) => WindsurfProjectContext.isWindsurfRepo(dir),
38
- aider: (dir) => AiderProjectContext.isAiderRepo(dir),
39
- opencode: (dir) => OpenCodeProjectContext.isOpenCodeRepo(dir),
40
- };
41
-
42
- const IMPACT_SCORES = {
43
- critical: 5,
44
- high: 4,
45
- medium: 3,
46
- low: 2,
47
- };
48
-
49
- function exists(targetPath) {
50
- try {
51
- return fs.existsSync(targetPath);
52
- } catch {
53
- return false;
54
- }
55
- }
56
-
57
- function resolveDir(dir) {
58
- return path.resolve(dir || '.');
59
- }
60
-
61
- function detectPlatforms(dir) {
62
- const resolvedDir = resolveDir(dir);
63
- return PLATFORM_ORDER.filter((platform) => {
64
- const detect = PLATFORM_DETECTORS[platform];
65
- return typeof detect === 'function' ? detect(resolvedDir) : false;
66
- });
67
- }
68
-
69
- function getCatalog() {
70
- return generateCatalog();
71
- }
72
-
73
- function buildPatternHistory(dir, platformAudits) {
74
- const timestamp = new Date().toISOString();
75
- return Object.entries(platformAudits).map(([platform, result]) => ({
76
- dir,
77
- platform,
78
- score: result.score,
79
- findings: result.results || [],
80
- timestamp,
81
- }));
82
- }
83
-
84
- function buildRecommendationPool(platformAudits, compensation) {
85
- const recommendations = [];
86
-
87
- for (const [platform, result] of Object.entries(platformAudits)) {
88
- const topActions = Array.isArray(result.topNextActions) ? result.topNextActions : [];
89
- for (const action of topActions) {
90
- recommendations.push({
91
- key: action.key,
92
- name: action.name,
93
- description: action.fix,
94
- impact: action.impact,
95
- sourcePlatform: platform,
96
- applicablePlatforms: [platform],
97
- validatedOn: [platform],
98
- baseScore: IMPACT_SCORES[action.impact] || 1,
99
- });
100
- }
101
- }
102
-
103
- for (const addition of compensation.recommendedAdditions || []) {
104
- recommendations.push({
105
- key: `add-${addition.platform}`,
106
- name: `Add ${addition.platform}`,
107
- description: `Covers ${addition.wouldCover.map((item) => item.label).join(', ')}`,
108
- impact: addition.wouldCover.length >= 2 ? 'high' : 'medium',
109
- sourcePlatform: addition.platform,
110
- applicablePlatforms: [addition.platform],
111
- validatedOn: [],
112
- fillsGap: true,
113
- baseScore: Math.max(2, Math.min(5, Math.round(addition.estimatedBenefit / Math.max(1, addition.wouldCover.length)))),
114
- });
115
- }
116
-
117
- return recommendations;
118
- }
119
-
120
- async function synergyReport(dir) {
121
- const resolvedDir = resolveDir(dir);
122
- const activePlatforms = detectPlatforms(resolvedDir);
123
- const platformAudits = {};
124
- const errors = [];
125
-
126
- for (const platform of activePlatforms) {
127
- try {
128
- platformAudits[platform] = await audit({
129
- dir: resolvedDir,
130
- platform,
131
- silent: true,
132
- });
133
- } catch (error) {
134
- errors.push({ platform, message: error.message });
135
- }
136
- }
137
-
138
- const compound = compoundAudit(platformAudits);
139
- const amplification = calculateAmplification(platformAudits);
140
- const compensation = analyzeCompensation(activePlatforms, platformAudits);
141
- const patterns = discoverPatterns(buildPatternHistory(resolvedDir, platformAudits)).patterns;
142
- const recommendations = rankRecommendations(
143
- buildRecommendationPool(platformAudits, compensation),
144
- activePlatforms
145
- );
146
- const report = generateSynergyReport({
147
- platformAudits,
148
- activePlatforms,
149
- recommendations,
150
- });
151
-
152
- return {
153
- dir: resolvedDir,
154
- activePlatforms,
155
- platformAudits,
156
- compound,
157
- amplification,
158
- compensation,
159
- patterns,
160
- recommendations,
161
- errors,
162
- report,
163
- };
164
- }
165
-
166
- module.exports = {
167
- audit,
168
- harmonyAudit,
169
- detectPlatforms,
170
- getCatalog,
171
- routeTask,
172
- synergyReport,
173
- };
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { audit } = require('./audit');
4
+ const { harmonyAudit } = require('./harmony/audit');
5
+ const { generateCatalog } = require('./catalog');
6
+ const { compoundAudit, calculateAmplification } = require('./synergy/evidence');
7
+ const { analyzeCompensation } = require('./synergy/compensation');
8
+ const { discoverPatterns } = require('./synergy/patterns');
9
+ const { rankRecommendations } = require('./synergy/ranking');
10
+ const { generateSynergyReport } = require('./synergy/report');
11
+ const { routeTask } = require('./synergy/routing');
12
+ const { CodexProjectContext } = require('./codex/context');
13
+ const { GeminiProjectContext } = require('./gemini/context');
14
+ const { CopilotProjectContext } = require('./copilot/context');
15
+ const { CursorProjectContext } = require('./cursor/context');
16
+ const { WindsurfProjectContext } = require('./windsurf/context');
17
+ const { AiderProjectContext } = require('./aider/context');
18
+ const { OpenCodeProjectContext } = require('./opencode/context');
19
+
20
+ const PLATFORM_ORDER = [
21
+ 'claude',
22
+ 'codex',
23
+ 'gemini',
24
+ 'copilot',
25
+ 'cursor',
26
+ 'windsurf',
27
+ 'aider',
28
+ 'opencode',
29
+ ];
30
+
31
+ const PLATFORM_DETECTORS = {
32
+ claude: (dir) => exists(path.join(dir, 'CLAUDE.md')) || exists(path.join(dir, '.claude')),
33
+ codex: (dir) => CodexProjectContext.isCodexRepo(dir),
34
+ gemini: (dir) => GeminiProjectContext.isGeminiRepo(dir),
35
+ copilot: (dir) => CopilotProjectContext.isCopilotRepo(dir),
36
+ cursor: (dir) => CursorProjectContext.isCursorRepo(dir),
37
+ windsurf: (dir) => WindsurfProjectContext.isWindsurfRepo(dir),
38
+ aider: (dir) => AiderProjectContext.isAiderRepo(dir),
39
+ opencode: (dir) => OpenCodeProjectContext.isOpenCodeRepo(dir),
40
+ };
41
+
42
+ const IMPACT_SCORES = {
43
+ critical: 5,
44
+ high: 4,
45
+ medium: 3,
46
+ low: 2,
47
+ };
48
+
49
+ function exists(targetPath) {
50
+ try {
51
+ return fs.existsSync(targetPath);
52
+ } catch {
53
+ return false;
54
+ }
55
+ }
56
+
57
+ function resolveDir(dir) {
58
+ return path.resolve(dir || '.');
59
+ }
60
+
61
+ function detectPlatforms(dir) {
62
+ const resolvedDir = resolveDir(dir);
63
+ return PLATFORM_ORDER.filter((platform) => {
64
+ const detect = PLATFORM_DETECTORS[platform];
65
+ return typeof detect === 'function' ? detect(resolvedDir) : false;
66
+ });
67
+ }
68
+
69
+ function getCatalog() {
70
+ return generateCatalog();
71
+ }
72
+
73
+ function buildPatternHistory(dir, platformAudits) {
74
+ const timestamp = new Date().toISOString();
75
+ return Object.entries(platformAudits).map(([platform, result]) => ({
76
+ dir,
77
+ platform,
78
+ score: result.score,
79
+ findings: result.results || [],
80
+ timestamp,
81
+ }));
82
+ }
83
+
84
+ function buildRecommendationPool(platformAudits, compensation) {
85
+ const recommendations = [];
86
+
87
+ for (const [platform, result] of Object.entries(platformAudits)) {
88
+ const topActions = Array.isArray(result.topNextActions) ? result.topNextActions : [];
89
+ for (const action of topActions) {
90
+ recommendations.push({
91
+ key: action.key,
92
+ name: action.name,
93
+ description: action.fix,
94
+ impact: action.impact,
95
+ sourcePlatform: platform,
96
+ applicablePlatforms: [platform],
97
+ validatedOn: [platform],
98
+ baseScore: IMPACT_SCORES[action.impact] || 1,
99
+ });
100
+ }
101
+ }
102
+
103
+ for (const addition of compensation.recommendedAdditions || []) {
104
+ recommendations.push({
105
+ key: `add-${addition.platform}`,
106
+ name: `Add ${addition.platform}`,
107
+ description: `Covers ${addition.wouldCover.map((item) => item.label).join(', ')}`,
108
+ impact: addition.wouldCover.length >= 2 ? 'high' : 'medium',
109
+ sourcePlatform: addition.platform,
110
+ applicablePlatforms: [addition.platform],
111
+ validatedOn: [],
112
+ fillsGap: true,
113
+ baseScore: Math.max(2, Math.min(5, Math.round(addition.estimatedBenefit / Math.max(1, addition.wouldCover.length)))),
114
+ });
115
+ }
116
+
117
+ return recommendations;
118
+ }
119
+
120
+ async function synergyReport(dir) {
121
+ const resolvedDir = resolveDir(dir);
122
+ const activePlatforms = detectPlatforms(resolvedDir);
123
+ const platformAudits = {};
124
+ const errors = [];
125
+
126
+ for (const platform of activePlatforms) {
127
+ try {
128
+ platformAudits[platform] = await audit({
129
+ dir: resolvedDir,
130
+ platform,
131
+ silent: true,
132
+ });
133
+ } catch (error) {
134
+ errors.push({ platform, message: error.message });
135
+ }
136
+ }
137
+
138
+ const compound = compoundAudit(platformAudits);
139
+ const amplification = calculateAmplification(platformAudits);
140
+ const compensation = analyzeCompensation(activePlatforms, platformAudits);
141
+ const patterns = discoverPatterns(buildPatternHistory(resolvedDir, platformAudits)).patterns;
142
+ const recommendations = rankRecommendations(
143
+ buildRecommendationPool(platformAudits, compensation),
144
+ activePlatforms
145
+ );
146
+ const report = generateSynergyReport({
147
+ platformAudits,
148
+ activePlatforms,
149
+ recommendations,
150
+ });
151
+
152
+ return {
153
+ dir: resolvedDir,
154
+ activePlatforms,
155
+ platformAudits,
156
+ compound,
157
+ amplification,
158
+ compensation,
159
+ patterns,
160
+ recommendations,
161
+ errors,
162
+ report,
163
+ };
164
+ }
165
+
166
+ module.exports = {
167
+ audit,
168
+ harmonyAudit,
169
+ detectPlatforms,
170
+ getCatalog,
171
+ routeTask,
172
+ synergyReport,
173
+ };
@@ -1,84 +1,84 @@
1
- /**
2
- * Recommendation Rules Export
3
- *
4
- * Reads all TECHNIQUES, groups by category, and generates
5
- * a structured JSON-serializable recommendation rules object.
6
- */
7
-
8
- const { TECHNIQUES } = require('./techniques');
9
- const { version } = require('../package.json');
10
-
11
- const IMPACT_ORDER = { critical: 4, high: 3, medium: 2, low: 1 };
12
-
13
- function impactLabel(avg) {
14
- if (avg >= 3.5) return 'critical';
15
- if (avg >= 2.5) return 'high';
16
- if (avg >= 1.5) return 'medium';
17
- return 'low';
18
- }
19
-
20
- function generateRecommendationRules(options) {
21
- const opts = options || {};
22
- const entries = Object.entries(TECHNIQUES);
23
-
24
- // Group by category
25
- const grouped = {};
26
- for (const [key, t] of entries) {
27
- const cat = t.category;
28
- if (!grouped[cat]) grouped[cat] = [];
29
- grouped[cat].push({ key, ...t });
30
- }
31
-
32
- // Build categories summary
33
- const categories = {};
34
- for (const [cat, checks] of Object.entries(grouped)) {
35
- const weights = checks.map(c => IMPACT_ORDER[c.impact] || 0);
36
- const avgWeight = weights.reduce((a, b) => a + b, 0) / weights.length;
37
-
38
- // Top 5 by impact weight (descending), then by rating (descending)
39
- const sorted = [...checks].sort((a, b) => {
40
- const impactDiff = (IMPACT_ORDER[b.impact] || 0) - (IMPACT_ORDER[a.impact] || 0);
41
- if (impactDiff !== 0) return impactDiff;
42
- return (b.rating || 0) - (a.rating || 0);
43
- });
44
-
45
- const topChecks = sorted.slice(0, 5).map(c => ({
46
- key: c.key,
47
- name: c.name,
48
- impact: c.impact,
49
- fix: c.fix,
50
- }));
51
-
52
- categories[cat] = {
53
- checkCount: checks.length,
54
- averageImpact: impactLabel(avgWeight),
55
- topChecks,
56
- };
57
- }
58
-
59
- const byRepoType = {
60
- frontend: ['security', 'design', 'performance-budget', 'accessibility'],
61
- backend: ['security', 'api-versioning', 'caching', 'rate-limiting', 'observability'],
62
- fullstack: ['security', 'quality', 'automation', 'observability'],
63
- mobile: ['flutter', 'swift', 'kotlin', 'security'],
64
- infrastructure: ['devops', 'supply-chain', 'monitoring'],
65
- library: ['docs-quality', 'quality', 'git'],
66
- };
67
-
68
- const byMaturity = {
69
- 'new-project': { focus: ['hygiene', 'security', 'quality'], skipCategories: ['quality-deep', 'enterprise'] },
70
- growing: { focus: ['automation', 'workflow', 'observability'], skipCategories: [] },
71
- mature: { focus: ['quality-deep', 'performance-budget', 'governance'], skipCategories: [] },
72
- };
73
-
74
- return {
75
- generatedAt: new Date().toISOString(),
76
- version,
77
- totalRules: entries.length,
78
- categories,
79
- byRepoType,
80
- byMaturity,
81
- };
82
- }
83
-
84
- module.exports = { generateRecommendationRules };
1
+ /**
2
+ * Recommendation Rules Export
3
+ *
4
+ * Reads all TECHNIQUES, groups by category, and generates
5
+ * a structured JSON-serializable recommendation rules object.
6
+ */
7
+
8
+ const { TECHNIQUES } = require('./techniques');
9
+ const { version } = require('../package.json');
10
+
11
+ const IMPACT_ORDER = { critical: 4, high: 3, medium: 2, low: 1 };
12
+
13
+ function impactLabel(avg) {
14
+ if (avg >= 3.5) return 'critical';
15
+ if (avg >= 2.5) return 'high';
16
+ if (avg >= 1.5) return 'medium';
17
+ return 'low';
18
+ }
19
+
20
+ function generateRecommendationRules(options) {
21
+ const opts = options || {};
22
+ const entries = Object.entries(TECHNIQUES);
23
+
24
+ // Group by category
25
+ const grouped = {};
26
+ for (const [key, t] of entries) {
27
+ const cat = t.category;
28
+ if (!grouped[cat]) grouped[cat] = [];
29
+ grouped[cat].push({ key, ...t });
30
+ }
31
+
32
+ // Build categories summary
33
+ const categories = {};
34
+ for (const [cat, checks] of Object.entries(grouped)) {
35
+ const weights = checks.map(c => IMPACT_ORDER[c.impact] || 0);
36
+ const avgWeight = weights.reduce((a, b) => a + b, 0) / weights.length;
37
+
38
+ // Top 5 by impact weight (descending), then by rating (descending)
39
+ const sorted = [...checks].sort((a, b) => {
40
+ const impactDiff = (IMPACT_ORDER[b.impact] || 0) - (IMPACT_ORDER[a.impact] || 0);
41
+ if (impactDiff !== 0) return impactDiff;
42
+ return (b.rating || 0) - (a.rating || 0);
43
+ });
44
+
45
+ const topChecks = sorted.slice(0, 5).map(c => ({
46
+ key: c.key,
47
+ name: c.name,
48
+ impact: c.impact,
49
+ fix: c.fix,
50
+ }));
51
+
52
+ categories[cat] = {
53
+ checkCount: checks.length,
54
+ averageImpact: impactLabel(avgWeight),
55
+ topChecks,
56
+ };
57
+ }
58
+
59
+ const byRepoType = {
60
+ frontend: ['security', 'design', 'performance-budget', 'accessibility'],
61
+ backend: ['security', 'api-versioning', 'caching', 'rate-limiting', 'observability'],
62
+ fullstack: ['security', 'quality', 'automation', 'observability'],
63
+ mobile: ['flutter', 'swift', 'kotlin', 'security'],
64
+ infrastructure: ['devops', 'supply-chain', 'monitoring'],
65
+ library: ['docs-quality', 'quality', 'git'],
66
+ };
67
+
68
+ const byMaturity = {
69
+ 'new-project': { focus: ['hygiene', 'security', 'quality'], skipCategories: ['quality-deep', 'enterprise'] },
70
+ growing: { focus: ['automation', 'workflow', 'observability'], skipCategories: [] },
71
+ mature: { focus: ['quality-deep', 'performance-budget', 'governance'], skipCategories: [] },
72
+ };
73
+
74
+ return {
75
+ generatedAt: new Date().toISOString(),
76
+ version,
77
+ totalRules: entries.length,
78
+ categories,
79
+ byRepoType,
80
+ byMaturity,
81
+ };
82
+ }
83
+
84
+ module.exports = { generateRecommendationRules };