@nerviq/cli 1.18.0 → 1.20.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 (187) hide show
  1. package/LICENSE +23 -23
  2. package/README.md +2 -2
  3. package/bin/cli.js +131 -130
  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 +158 -158
  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 +16 -16
  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 +320 -320
  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/context.js +290 -221
  81. package/src/gemini/deep-review.js +559 -559
  82. package/src/gemini/domain-packs.js +393 -393
  83. package/src/gemini/freshness.js +66 -66
  84. package/src/gemini/governance.js +201 -201
  85. package/src/gemini/interactive.js +860 -860
  86. package/src/gemini/mcp-packs.js +915 -915
  87. package/src/gemini/plans.js +269 -269
  88. package/src/gemini/premium.js +760 -760
  89. package/src/gemini/setup.js +692 -692
  90. package/src/gemini/techniques.js +105 -33
  91. package/src/governance.js +72 -72
  92. package/src/harmony/add.js +68 -68
  93. package/src/harmony/advisor.js +333 -333
  94. package/src/harmony/canon.js +565 -565
  95. package/src/harmony/cli.js +591 -591
  96. package/src/harmony/drift.js +401 -401
  97. package/src/harmony/governance.js +313 -313
  98. package/src/harmony/memory.js +239 -239
  99. package/src/harmony/sync.js +475 -475
  100. package/src/harmony/watch.js +370 -370
  101. package/src/hook-validation.js +342 -342
  102. package/src/index.js +271 -271
  103. package/src/init.js +184 -184
  104. package/src/instruction-surfaces.js +185 -185
  105. package/src/integrations.js +144 -144
  106. package/src/interactive.js +118 -118
  107. package/src/locales/en.json +1 -1
  108. package/src/locales/es.json +1 -1
  109. package/src/mcp-packs.js +830 -830
  110. package/src/mcp-server.js +726 -726
  111. package/src/mcp-validation.js +337 -337
  112. package/src/nerviq-sync.json +7 -7
  113. package/src/opencode/config-parser.js +109 -109
  114. package/src/opencode/context.js +247 -247
  115. package/src/opencode/deep-review.js +313 -313
  116. package/src/opencode/domain-packs.js +262 -262
  117. package/src/opencode/freshness.js +66 -66
  118. package/src/opencode/governance.js +159 -159
  119. package/src/opencode/interactive.js +392 -392
  120. package/src/opencode/mcp-packs.js +705 -705
  121. package/src/opencode/patch.js +184 -184
  122. package/src/opencode/plans.js +231 -231
  123. package/src/opencode/premium.js +413 -413
  124. package/src/opencode/setup.js +449 -449
  125. package/src/opencode/techniques.js +27 -27
  126. package/src/operating-profile.js +574 -574
  127. package/src/org.js +152 -152
  128. package/src/permission-rules.js +218 -218
  129. package/src/plans.js +839 -839
  130. package/src/platform-change-manifest.js +86 -86
  131. package/src/plugins.js +110 -110
  132. package/src/policy-layers.js +210 -210
  133. package/src/profiles.js +124 -124
  134. package/src/prompt-injection.js +74 -74
  135. package/src/public-api.js +173 -173
  136. package/src/recommendation-rules.js +84 -84
  137. package/src/repo-archetype.js +386 -386
  138. package/src/secret-patterns.js +39 -39
  139. package/src/server.js +527 -527
  140. package/src/setup/analysis.js +607 -607
  141. package/src/setup/runtime.js +172 -172
  142. package/src/setup.js +677 -677
  143. package/src/shared/capabilities.js +194 -194
  144. package/src/source-urls.js +132 -132
  145. package/src/stack-checks.js +565 -565
  146. package/src/supplemental-checks.js +13 -13
  147. package/src/synergy/adaptive.js +261 -261
  148. package/src/synergy/compensation.js +137 -137
  149. package/src/synergy/evidence.js +193 -193
  150. package/src/synergy/learning.js +199 -199
  151. package/src/synergy/patterns.js +227 -227
  152. package/src/synergy/ranking.js +83 -83
  153. package/src/synergy/report.js +165 -165
  154. package/src/synergy/routing.js +146 -146
  155. package/src/techniques/api.js +407 -407
  156. package/src/techniques/automation.js +316 -316
  157. package/src/techniques/compliance.js +257 -257
  158. package/src/techniques/hygiene.js +294 -294
  159. package/src/techniques/instructions.js +243 -243
  160. package/src/techniques/observability.js +226 -226
  161. package/src/techniques/optimization.js +142 -142
  162. package/src/techniques/quality.js +318 -318
  163. package/src/techniques/security.js +237 -237
  164. package/src/techniques/shared.js +443 -443
  165. package/src/techniques/stacks.js +2294 -2294
  166. package/src/techniques/tools.js +106 -106
  167. package/src/techniques/workflow.js +413 -413
  168. package/src/techniques.js +81 -81
  169. package/src/terminology.js +73 -73
  170. package/src/token-estimate.js +35 -35
  171. package/src/usage-patterns.js +99 -99
  172. package/src/verification-metadata.js +145 -145
  173. package/src/watch.js +247 -247
  174. package/src/windsurf/activity.js +302 -302
  175. package/src/windsurf/config-parser.js +267 -267
  176. package/src/windsurf/context.js +249 -249
  177. package/src/windsurf/deep-review.js +337 -337
  178. package/src/windsurf/domain-packs.js +370 -370
  179. package/src/windsurf/freshness.js +36 -36
  180. package/src/windsurf/governance.js +231 -231
  181. package/src/windsurf/interactive.js +388 -388
  182. package/src/windsurf/mcp-packs.js +792 -792
  183. package/src/windsurf/plans.js +247 -247
  184. package/src/windsurf/premium.js +468 -468
  185. package/src/windsurf/setup.js +471 -471
  186. package/src/windsurf/techniques.js +17 -17
  187. package/src/workspace.js +375 -375
@@ -1,334 +1,334 @@
1
- /**
2
- * Aider Interactive Wizard — 8-stage guided setup
3
- *
4
- * Simpler than IDE wizards — no hooks/MCP stages.
5
- * Uses Node.js readline (zero dependencies).
6
- *
7
- * Stages:
8
- * 1. Project Detection
9
- * 2. Git Safety Posture
10
- * 3. Model Configuration
11
- * 4. Convention File
12
- * 5. Domain Pack Selection
13
- * 6. Verification Loop
14
- * 7. CI Integration
15
- * 8. Review & Generate
16
- */
17
-
18
- const fs = require('fs');
19
- const path = require('path');
20
- const readline = require('readline');
21
- const { STACKS } = require('../techniques');
22
- const { AiderProjectContext } = require('./context');
23
- const { AIDER_TECHNIQUES } = require('./techniques');
24
- const { AIDER_DOMAIN_PACKS, detectAiderDomainPacks } = require('./domain-packs');
25
- const { recommendAiderMcpPacks, AIDER_MCP_PACKS } = require('./mcp-packs');
26
- const { setupAider } = require('./setup');
27
-
28
- const COLORS = {
29
- reset: '\x1b[0m', bold: '\x1b[1m', dim: '\x1b[2m',
30
- red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m',
31
- blue: '\x1b[36m', magenta: '\x1b[35m',
32
- };
33
- const c = (text, color) => `${COLORS[color] || ''}${text}${COLORS.reset}`;
34
-
35
- function ask(rl, question) {
36
- return new Promise(resolve => rl.question(question, resolve));
37
- }
38
-
39
- function isTTY() {
40
- return Boolean(process.stdin.isTTY && process.stdout.isTTY);
41
- }
42
-
43
- const STAGE_NAMES = [
44
- 'Project Detection',
45
- 'Git Safety Posture',
46
- 'Model Configuration',
47
- 'Convention File',
48
- 'Domain Pack Selection',
49
- 'Verification Loop',
50
- 'CI Integration',
51
- 'Review & Generate',
52
- ];
53
-
54
- function printStageHeader(index) {
55
- const num = index + 1;
56
- const total = STAGE_NAMES.length;
57
- console.log('');
58
- console.log(c(` ── Stage ${num}/${total}: ${STAGE_NAMES[index]} ──`, 'magenta'));
59
- console.log('');
60
- }
61
-
62
- // --- Stage 1: Project Detection ---
63
-
64
- function runProjectDetection(ctx) {
65
- const stacks = ctx.detectStacks(STACKS);
66
- const hasGit = ctx.hasGitRepo();
67
- const hasConfYml = Boolean(ctx.configContent());
68
- const hasConventions = ctx.conventionFiles().length > 0;
69
-
70
- return {
71
- stacks,
72
- hasGit,
73
- hasConfYml,
74
- hasConventions,
75
- projectName: path.basename(ctx.dir),
76
- };
77
- }
78
-
79
- // --- Stage 2: Git Safety Posture ---
80
-
81
- async function runGitSafety(rl, state) {
82
- console.log(' Aider uses git as its ONLY safety mechanism.');
83
- console.log(' Auto-commits create an undo trail for every change.');
84
- console.log('');
85
-
86
- const autoCommits = await ask(rl, c(' Enable auto-commits? (Y/n): ', 'blue'));
87
- state.autoCommits = autoCommits.trim().toLowerCase() !== 'n';
88
-
89
- const attribution = await ask(rl, c(' Enable commit attribution for AI traceability? (Y/n): ', 'blue'));
90
- state.attribution = attribution.trim().toLowerCase() !== 'n';
91
-
92
- const commitPrefix = await ask(rl, c(' Commit prefix for AI commits (default: "aider: "): ', 'blue'));
93
- state.commitPrefix = commitPrefix.trim() || 'aider: ';
94
-
95
- return 'next';
96
- }
97
-
98
- // --- Stage 3: Model Configuration ---
99
-
100
- async function runModelConfig(rl, state) {
101
- console.log(' Aider has 3 model roles:');
102
- console.log(' - main: does the coding');
103
- console.log(' - editor: applies edits to files');
104
- console.log(' - weak: generates commit messages (cheapest)');
105
- console.log('');
106
-
107
- const mainModel = await ask(rl, c(' Main model (e.g., claude-sonnet-4-20250514, gpt-4o, leave blank for default): ', 'blue'));
108
- state.mainModel = mainModel.trim() || null;
109
-
110
- const architect = await ask(rl, c(' Enable architect mode (2-model planning + editing)? (y/N): ', 'blue'));
111
- state.architect = architect.trim().toLowerCase() === 'y';
112
-
113
- const cachePrompts = await ask(rl, c(' Enable prompt caching for cost savings? (Y/n): ', 'blue'));
114
- state.cachePrompts = cachePrompts.trim().toLowerCase() !== 'n';
115
-
116
- return 'next';
117
- }
118
-
119
- // --- Stage 4: Convention File ---
120
-
121
- async function runConventions(rl, state, ctx) {
122
- const existing = ctx.conventionFiles();
123
- if (existing.length > 0) {
124
- console.log(` Found existing convention files: ${existing.join(', ')}`);
125
- const keep = await ask(rl, c(' Keep existing convention files? (Y/n): ', 'blue'));
126
- if (keep.trim().toLowerCase() !== 'n') {
127
- state.generateConventions = false;
128
- return 'next';
129
- }
130
- }
131
-
132
- console.log(' Aider has NO auto-discovery — convention files must be explicitly passed via read:');
133
- const generate = await ask(rl, c(' Generate CONVENTIONS.md? (Y/n): ', 'blue'));
134
- state.generateConventions = generate.trim().toLowerCase() !== 'n';
135
-
136
- return 'next';
137
- }
138
-
139
- // --- Stage 5: Domain Pack Selection ---
140
-
141
- async function runDomainPacks(rl, state, ctx) {
142
- const detected = detectAiderDomainPacks(ctx);
143
- console.log(' Detected domain packs:');
144
- for (const pack of detected) {
145
- console.log(` - ${pack.label}: ${pack.matchReasons[0] || pack.useWhen}`);
146
- }
147
- console.log('');
148
-
149
- const accept = await ask(rl, c(' Accept detected domain packs? (Y/n): ', 'blue'));
150
- if (accept.trim().toLowerCase() !== 'n') {
151
- state.domainPacks = detected.map(p => p.key);
152
- } else {
153
- console.log(' Available packs:');
154
- AIDER_DOMAIN_PACKS.forEach((p, i) => {
155
- console.log(` ${i + 1}. ${p.label} — ${p.useWhen.slice(0, 60)}`);
156
- });
157
- const choices = await ask(rl, c(' Enter pack numbers (comma-separated): ', 'blue'));
158
- const indices = choices.split(',').map(s => parseInt(s.trim(), 10) - 1).filter(i => i >= 0 && i < AIDER_DOMAIN_PACKS.length);
159
- state.domainPacks = indices.map(i => AIDER_DOMAIN_PACKS[i].key);
160
- }
161
-
162
- return 'next';
163
- }
164
-
165
- // --- Stage 6: Verification Loop ---
166
-
167
- async function runVerificationLoop(rl, state) {
168
- console.log(' Aider can auto-fix lint and test failures after edits.');
169
- console.log('');
170
-
171
- const lintCmd = await ask(rl, c(' Lint command (leave blank to skip): ', 'blue'));
172
- state.lintCmd = lintCmd.trim() || null;
173
-
174
- if (state.lintCmd) {
175
- const autoLint = await ask(rl, c(' Enable auto-lint (auto-fix after edits)? (Y/n): ', 'blue'));
176
- state.autoLint = autoLint.trim().toLowerCase() !== 'n';
177
- }
178
-
179
- const testCmd = await ask(rl, c(' Test command (leave blank to skip): ', 'blue'));
180
- state.testCmd = testCmd.trim() || null;
181
-
182
- if (state.testCmd) {
183
- const autoTest = await ask(rl, c(' Enable auto-test (run tests after edits)? (Y/n): ', 'blue'));
184
- state.autoTest = autoTest.trim().toLowerCase() !== 'n';
185
- }
186
-
187
- return 'next';
188
- }
189
-
190
- // --- Stage 7: CI Integration ---
191
-
192
- async function runCiIntegration(rl, state) {
193
- console.log(' CI integration ensures Aider-generated code passes quality gates.');
194
- console.log('');
195
-
196
- const wantCi = await ask(rl, c(' Set up CI workflow for Aider PRs? (y/N): ', 'blue'));
197
- state.wantCi = wantCi.trim().toLowerCase() === 'y';
198
-
199
- return 'next';
200
- }
201
-
202
- // --- Stage 8: Review & Generate ---
203
-
204
- async function runReviewGenerate(rl, state, dir) {
205
- console.log(' Summary:');
206
- console.log(` Auto-commits: ${state.autoCommits ? 'yes' : 'no'}`);
207
- console.log(` Attribution: ${state.attribution ? 'yes' : 'no'}`);
208
- console.log(` Commit prefix: "${state.commitPrefix}"`);
209
- console.log(` Main model: ${state.mainModel || 'default'}`);
210
- console.log(` Architect mode: ${state.architect ? 'yes' : 'no'}`);
211
- console.log(` Prompt caching: ${state.cachePrompts ? 'yes' : 'no'}`);
212
- console.log(` Generate conventions: ${state.generateConventions ? 'yes' : 'no'}`);
213
- console.log(` Domain packs: ${(state.domainPacks || []).join(', ') || 'none'}`);
214
- console.log(` Lint: ${state.lintCmd || 'none'} (auto: ${state.autoLint ? 'yes' : 'no'})`);
215
- console.log(` Test: ${state.testCmd || 'none'} (auto: ${state.autoTest ? 'yes' : 'no'})`);
216
- console.log(` CI workflow: ${state.wantCi ? 'yes' : 'no'}`);
217
- console.log('');
218
-
219
- const confirm = await ask(rl, c(' Generate files? (Y/n): ', 'blue'));
220
- if (confirm.trim().toLowerCase() === 'n') {
221
- return 'back';
222
- }
223
-
224
- setupAider({ dir, log: console.log });
225
- return 'done';
226
- }
227
-
228
- // --- Main wizard ---
229
-
230
- async function aiderInteractive(dir) {
231
- if (!isTTY()) {
232
- console.log('Interactive mode requires a TTY. Use --setup instead.');
233
- process.exit(1);
234
- }
235
-
236
- const rl = readline.createInterface({
237
- input: process.stdin,
238
- output: process.stdout,
239
- });
240
-
241
- console.log('');
242
- console.log(c(' ╔══════════════════════════════════════╗', 'magenta'));
243
- console.log(c(' ║ Aider Interactive Setup ║', 'magenta'));
244
- console.log(c(' ║ powered by nerviq ║', 'magenta'));
245
- console.log(c(' ╚══════════════════════════════════════╝', 'magenta'));
246
-
247
- const ctx = new AiderProjectContext(dir);
248
- const state = {
249
- autoCommits: true,
250
- attribution: true,
251
- commitPrefix: 'aider: ',
252
- mainModel: null,
253
- architect: false,
254
- cachePrompts: true,
255
- generateConventions: true,
256
- domainPacks: [],
257
- lintCmd: null,
258
- autoLint: false,
259
- testCmd: null,
260
- autoTest: false,
261
- wantCi: false,
262
- };
263
-
264
- const stages = [
265
- // Stage 1 — auto, no interaction
266
- async () => {
267
- printStageHeader(0);
268
- const detection = runProjectDetection(ctx);
269
- console.log(` Project: ${detection.projectName}`);
270
- console.log(` Git repo: ${detection.hasGit ? c('yes', 'green') : c('NO — required!', 'red')}`);
271
- console.log(` .aider.conf.yml: ${detection.hasConfYml ? 'exists' : 'missing'}`);
272
- console.log(` Convention files: ${detection.hasConventions ? 'found' : 'none'}`);
273
- console.log(` Stacks: ${detection.stacks.map(s => s.key).join(', ') || 'none detected'}`);
274
-
275
- if (!detection.hasGit) {
276
- console.log('');
277
- console.log(c(' Warning: Aider requires a git repo. Run `git init` first.', 'red'));
278
- }
279
-
280
- return 'next';
281
- },
282
- // Stage 2
283
- async () => { printStageHeader(1); return runGitSafety(rl, state); },
284
- // Stage 3
285
- async () => { printStageHeader(2); return runModelConfig(rl, state); },
286
- // Stage 4
287
- async () => { printStageHeader(3); return runConventions(rl, state, ctx); },
288
- // Stage 5
289
- async () => { printStageHeader(4); return runDomainPacks(rl, state, ctx); },
290
- // Stage 6
291
- async () => { printStageHeader(5); return runVerificationLoop(rl, state); },
292
- // Stage 7
293
- async () => { printStageHeader(6); return runCiIntegration(rl, state); },
294
- // Stage 8
295
- async () => { printStageHeader(7); return runReviewGenerate(rl, state, dir); },
296
- ];
297
-
298
- let stageIndex = 0;
299
-
300
- while (stageIndex < stages.length) {
301
- const result = await stages[stageIndex]();
302
-
303
- if (result === 'quit' || result === 'exit') {
304
- rl.close();
305
- console.log(c(' Setup cancelled.', 'yellow'));
306
- return { cancelled: true };
307
- }
308
-
309
- if (result === 'back') {
310
- if (stageIndex > 0) {
311
- stageIndex--;
312
- } else {
313
- console.log(c(' Already at the first stage.', 'dim'));
314
- }
315
- continue;
316
- }
317
-
318
- if (result === 'done') {
319
- break;
320
- }
321
-
322
- stageIndex++;
323
- }
324
-
325
- rl.close();
326
-
327
- console.log('');
328
- console.log(c(' Done! Run `npx nerviq --platform aider` to audit your setup.', 'green'));
329
- console.log('');
330
-
331
- return { cancelled: false, state };
332
- }
333
-
334
- module.exports = { aiderInteractive };
1
+ /**
2
+ * Aider Interactive Wizard — 8-stage guided setup
3
+ *
4
+ * Simpler than IDE wizards — no hooks/MCP stages.
5
+ * Uses Node.js readline (zero dependencies).
6
+ *
7
+ * Stages:
8
+ * 1. Project Detection
9
+ * 2. Git Safety Posture
10
+ * 3. Model Configuration
11
+ * 4. Convention File
12
+ * 5. Domain Pack Selection
13
+ * 6. Verification Loop
14
+ * 7. CI Integration
15
+ * 8. Review & Generate
16
+ */
17
+
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+ const readline = require('readline');
21
+ const { STACKS } = require('../techniques');
22
+ const { AiderProjectContext } = require('./context');
23
+ const { AIDER_TECHNIQUES } = require('./techniques');
24
+ const { AIDER_DOMAIN_PACKS, detectAiderDomainPacks } = require('./domain-packs');
25
+ const { recommendAiderMcpPacks, AIDER_MCP_PACKS } = require('./mcp-packs');
26
+ const { setupAider } = require('./setup');
27
+
28
+ const COLORS = {
29
+ reset: '\x1b[0m', bold: '\x1b[1m', dim: '\x1b[2m',
30
+ red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m',
31
+ blue: '\x1b[36m', magenta: '\x1b[35m',
32
+ };
33
+ const c = (text, color) => `${COLORS[color] || ''}${text}${COLORS.reset}`;
34
+
35
+ function ask(rl, question) {
36
+ return new Promise(resolve => rl.question(question, resolve));
37
+ }
38
+
39
+ function isTTY() {
40
+ return Boolean(process.stdin.isTTY && process.stdout.isTTY);
41
+ }
42
+
43
+ const STAGE_NAMES = [
44
+ 'Project Detection',
45
+ 'Git Safety Posture',
46
+ 'Model Configuration',
47
+ 'Convention File',
48
+ 'Domain Pack Selection',
49
+ 'Verification Loop',
50
+ 'CI Integration',
51
+ 'Review & Generate',
52
+ ];
53
+
54
+ function printStageHeader(index) {
55
+ const num = index + 1;
56
+ const total = STAGE_NAMES.length;
57
+ console.log('');
58
+ console.log(c(` ── Stage ${num}/${total}: ${STAGE_NAMES[index]} ──`, 'magenta'));
59
+ console.log('');
60
+ }
61
+
62
+ // --- Stage 1: Project Detection ---
63
+
64
+ function runProjectDetection(ctx) {
65
+ const stacks = ctx.detectStacks(STACKS);
66
+ const hasGit = ctx.hasGitRepo();
67
+ const hasConfYml = Boolean(ctx.configContent());
68
+ const hasConventions = ctx.conventionFiles().length > 0;
69
+
70
+ return {
71
+ stacks,
72
+ hasGit,
73
+ hasConfYml,
74
+ hasConventions,
75
+ projectName: path.basename(ctx.dir),
76
+ };
77
+ }
78
+
79
+ // --- Stage 2: Git Safety Posture ---
80
+
81
+ async function runGitSafety(rl, state) {
82
+ console.log(' Aider uses git as its ONLY safety mechanism.');
83
+ console.log(' Auto-commits create an undo trail for every change.');
84
+ console.log('');
85
+
86
+ const autoCommits = await ask(rl, c(' Enable auto-commits? (Y/n): ', 'blue'));
87
+ state.autoCommits = autoCommits.trim().toLowerCase() !== 'n';
88
+
89
+ const attribution = await ask(rl, c(' Enable commit attribution for AI traceability? (Y/n): ', 'blue'));
90
+ state.attribution = attribution.trim().toLowerCase() !== 'n';
91
+
92
+ const commitPrefix = await ask(rl, c(' Commit prefix for AI commits (default: "aider: "): ', 'blue'));
93
+ state.commitPrefix = commitPrefix.trim() || 'aider: ';
94
+
95
+ return 'next';
96
+ }
97
+
98
+ // --- Stage 3: Model Configuration ---
99
+
100
+ async function runModelConfig(rl, state) {
101
+ console.log(' Aider has 3 model roles:');
102
+ console.log(' - main: does the coding');
103
+ console.log(' - editor: applies edits to files');
104
+ console.log(' - weak: generates commit messages (cheapest)');
105
+ console.log('');
106
+
107
+ const mainModel = await ask(rl, c(' Main model (e.g., claude-sonnet-4-20250514, gpt-4o, leave blank for default): ', 'blue'));
108
+ state.mainModel = mainModel.trim() || null;
109
+
110
+ const architect = await ask(rl, c(' Enable architect mode (2-model planning + editing)? (y/N): ', 'blue'));
111
+ state.architect = architect.trim().toLowerCase() === 'y';
112
+
113
+ const cachePrompts = await ask(rl, c(' Enable prompt caching for cost savings? (Y/n): ', 'blue'));
114
+ state.cachePrompts = cachePrompts.trim().toLowerCase() !== 'n';
115
+
116
+ return 'next';
117
+ }
118
+
119
+ // --- Stage 4: Convention File ---
120
+
121
+ async function runConventions(rl, state, ctx) {
122
+ const existing = ctx.conventionFiles();
123
+ if (existing.length > 0) {
124
+ console.log(` Found existing convention files: ${existing.join(', ')}`);
125
+ const keep = await ask(rl, c(' Keep existing convention files? (Y/n): ', 'blue'));
126
+ if (keep.trim().toLowerCase() !== 'n') {
127
+ state.generateConventions = false;
128
+ return 'next';
129
+ }
130
+ }
131
+
132
+ console.log(' Aider has NO auto-discovery — convention files must be explicitly passed via read:');
133
+ const generate = await ask(rl, c(' Generate CONVENTIONS.md? (Y/n): ', 'blue'));
134
+ state.generateConventions = generate.trim().toLowerCase() !== 'n';
135
+
136
+ return 'next';
137
+ }
138
+
139
+ // --- Stage 5: Domain Pack Selection ---
140
+
141
+ async function runDomainPacks(rl, state, ctx) {
142
+ const detected = detectAiderDomainPacks(ctx);
143
+ console.log(' Detected domain packs:');
144
+ for (const pack of detected) {
145
+ console.log(` - ${pack.label}: ${pack.matchReasons[0] || pack.useWhen}`);
146
+ }
147
+ console.log('');
148
+
149
+ const accept = await ask(rl, c(' Accept detected domain packs? (Y/n): ', 'blue'));
150
+ if (accept.trim().toLowerCase() !== 'n') {
151
+ state.domainPacks = detected.map(p => p.key);
152
+ } else {
153
+ console.log(' Available packs:');
154
+ AIDER_DOMAIN_PACKS.forEach((p, i) => {
155
+ console.log(` ${i + 1}. ${p.label} — ${p.useWhen.slice(0, 60)}`);
156
+ });
157
+ const choices = await ask(rl, c(' Enter pack numbers (comma-separated): ', 'blue'));
158
+ const indices = choices.split(',').map(s => parseInt(s.trim(), 10) - 1).filter(i => i >= 0 && i < AIDER_DOMAIN_PACKS.length);
159
+ state.domainPacks = indices.map(i => AIDER_DOMAIN_PACKS[i].key);
160
+ }
161
+
162
+ return 'next';
163
+ }
164
+
165
+ // --- Stage 6: Verification Loop ---
166
+
167
+ async function runVerificationLoop(rl, state) {
168
+ console.log(' Aider can auto-fix lint and test failures after edits.');
169
+ console.log('');
170
+
171
+ const lintCmd = await ask(rl, c(' Lint command (leave blank to skip): ', 'blue'));
172
+ state.lintCmd = lintCmd.trim() || null;
173
+
174
+ if (state.lintCmd) {
175
+ const autoLint = await ask(rl, c(' Enable auto-lint (auto-fix after edits)? (Y/n): ', 'blue'));
176
+ state.autoLint = autoLint.trim().toLowerCase() !== 'n';
177
+ }
178
+
179
+ const testCmd = await ask(rl, c(' Test command (leave blank to skip): ', 'blue'));
180
+ state.testCmd = testCmd.trim() || null;
181
+
182
+ if (state.testCmd) {
183
+ const autoTest = await ask(rl, c(' Enable auto-test (run tests after edits)? (Y/n): ', 'blue'));
184
+ state.autoTest = autoTest.trim().toLowerCase() !== 'n';
185
+ }
186
+
187
+ return 'next';
188
+ }
189
+
190
+ // --- Stage 7: CI Integration ---
191
+
192
+ async function runCiIntegration(rl, state) {
193
+ console.log(' CI integration ensures Aider-generated code passes quality gates.');
194
+ console.log('');
195
+
196
+ const wantCi = await ask(rl, c(' Set up CI workflow for Aider PRs? (y/N): ', 'blue'));
197
+ state.wantCi = wantCi.trim().toLowerCase() === 'y';
198
+
199
+ return 'next';
200
+ }
201
+
202
+ // --- Stage 8: Review & Generate ---
203
+
204
+ async function runReviewGenerate(rl, state, dir) {
205
+ console.log(' Summary:');
206
+ console.log(` Auto-commits: ${state.autoCommits ? 'yes' : 'no'}`);
207
+ console.log(` Attribution: ${state.attribution ? 'yes' : 'no'}`);
208
+ console.log(` Commit prefix: "${state.commitPrefix}"`);
209
+ console.log(` Main model: ${state.mainModel || 'default'}`);
210
+ console.log(` Architect mode: ${state.architect ? 'yes' : 'no'}`);
211
+ console.log(` Prompt caching: ${state.cachePrompts ? 'yes' : 'no'}`);
212
+ console.log(` Generate conventions: ${state.generateConventions ? 'yes' : 'no'}`);
213
+ console.log(` Domain packs: ${(state.domainPacks || []).join(', ') || 'none'}`);
214
+ console.log(` Lint: ${state.lintCmd || 'none'} (auto: ${state.autoLint ? 'yes' : 'no'})`);
215
+ console.log(` Test: ${state.testCmd || 'none'} (auto: ${state.autoTest ? 'yes' : 'no'})`);
216
+ console.log(` CI workflow: ${state.wantCi ? 'yes' : 'no'}`);
217
+ console.log('');
218
+
219
+ const confirm = await ask(rl, c(' Generate files? (Y/n): ', 'blue'));
220
+ if (confirm.trim().toLowerCase() === 'n') {
221
+ return 'back';
222
+ }
223
+
224
+ setupAider({ dir, log: console.log });
225
+ return 'done';
226
+ }
227
+
228
+ // --- Main wizard ---
229
+
230
+ async function aiderInteractive(dir) {
231
+ if (!isTTY()) {
232
+ console.log('Interactive mode requires a TTY. Use --setup instead.');
233
+ process.exit(1);
234
+ }
235
+
236
+ const rl = readline.createInterface({
237
+ input: process.stdin,
238
+ output: process.stdout,
239
+ });
240
+
241
+ console.log('');
242
+ console.log(c(' ╔══════════════════════════════════════╗', 'magenta'));
243
+ console.log(c(' ║ Aider Interactive Setup ║', 'magenta'));
244
+ console.log(c(' ║ powered by nerviq ║', 'magenta'));
245
+ console.log(c(' ╚══════════════════════════════════════╝', 'magenta'));
246
+
247
+ const ctx = new AiderProjectContext(dir);
248
+ const state = {
249
+ autoCommits: true,
250
+ attribution: true,
251
+ commitPrefix: 'aider: ',
252
+ mainModel: null,
253
+ architect: false,
254
+ cachePrompts: true,
255
+ generateConventions: true,
256
+ domainPacks: [],
257
+ lintCmd: null,
258
+ autoLint: false,
259
+ testCmd: null,
260
+ autoTest: false,
261
+ wantCi: false,
262
+ };
263
+
264
+ const stages = [
265
+ // Stage 1 — auto, no interaction
266
+ async () => {
267
+ printStageHeader(0);
268
+ const detection = runProjectDetection(ctx);
269
+ console.log(` Project: ${detection.projectName}`);
270
+ console.log(` Git repo: ${detection.hasGit ? c('yes', 'green') : c('NO — required!', 'red')}`);
271
+ console.log(` .aider.conf.yml: ${detection.hasConfYml ? 'exists' : 'missing'}`);
272
+ console.log(` Convention files: ${detection.hasConventions ? 'found' : 'none'}`);
273
+ console.log(` Stacks: ${detection.stacks.map(s => s.key).join(', ') || 'none detected'}`);
274
+
275
+ if (!detection.hasGit) {
276
+ console.log('');
277
+ console.log(c(' Warning: Aider requires a git repo. Run `git init` first.', 'red'));
278
+ }
279
+
280
+ return 'next';
281
+ },
282
+ // Stage 2
283
+ async () => { printStageHeader(1); return runGitSafety(rl, state); },
284
+ // Stage 3
285
+ async () => { printStageHeader(2); return runModelConfig(rl, state); },
286
+ // Stage 4
287
+ async () => { printStageHeader(3); return runConventions(rl, state, ctx); },
288
+ // Stage 5
289
+ async () => { printStageHeader(4); return runDomainPacks(rl, state, ctx); },
290
+ // Stage 6
291
+ async () => { printStageHeader(5); return runVerificationLoop(rl, state); },
292
+ // Stage 7
293
+ async () => { printStageHeader(6); return runCiIntegration(rl, state); },
294
+ // Stage 8
295
+ async () => { printStageHeader(7); return runReviewGenerate(rl, state, dir); },
296
+ ];
297
+
298
+ let stageIndex = 0;
299
+
300
+ while (stageIndex < stages.length) {
301
+ const result = await stages[stageIndex]();
302
+
303
+ if (result === 'quit' || result === 'exit') {
304
+ rl.close();
305
+ console.log(c(' Setup cancelled.', 'yellow'));
306
+ return { cancelled: true };
307
+ }
308
+
309
+ if (result === 'back') {
310
+ if (stageIndex > 0) {
311
+ stageIndex--;
312
+ } else {
313
+ console.log(c(' Already at the first stage.', 'dim'));
314
+ }
315
+ continue;
316
+ }
317
+
318
+ if (result === 'done') {
319
+ break;
320
+ }
321
+
322
+ stageIndex++;
323
+ }
324
+
325
+ rl.close();
326
+
327
+ console.log('');
328
+ console.log(c(' Done! Run `npx nerviq --platform aider` to audit your setup.', 'green'));
329
+ console.log('');
330
+
331
+ return { cancelled: false, state };
332
+ }
333
+
334
+ module.exports = { aiderInteractive };