@nerviq/cli 1.20.1 → 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 (181) hide show
  1. package/LICENSE +23 -23
  2. package/README.md +2 -2
  3. package/package.json +1 -1
  4. package/src/activity.js +1039 -1039
  5. package/src/adoption-advisor.js +299 -299
  6. package/src/aider/config-parser.js +166 -166
  7. package/src/aider/context.js +4 -1
  8. package/src/aider/deep-review.js +316 -316
  9. package/src/aider/domain-packs.js +303 -303
  10. package/src/aider/freshness.js +93 -93
  11. package/src/aider/governance.js +253 -253
  12. package/src/aider/interactive.js +334 -334
  13. package/src/aider/mcp-packs.js +329 -329
  14. package/src/aider/patch.js +214 -214
  15. package/src/aider/plans.js +186 -186
  16. package/src/aider/premium.js +360 -360
  17. package/src/aider/setup.js +404 -404
  18. package/src/aider/techniques.js +312 -67
  19. package/src/analyze.js +951 -951
  20. package/src/anti-patterns.js +485 -485
  21. package/src/audit/instruction-files.js +180 -180
  22. package/src/audit/recommendations.js +577 -577
  23. package/src/auto-suggest.js +154 -154
  24. package/src/badge.js +13 -13
  25. package/src/behavioral-drift.js +801 -801
  26. package/src/benchmark.js +67 -67
  27. package/src/catalog.js +103 -103
  28. package/src/certification.js +128 -128
  29. package/src/codex/config-parser.js +183 -183
  30. package/src/codex/context.js +223 -223
  31. package/src/codex/deep-review.js +493 -493
  32. package/src/codex/domain-packs.js +394 -394
  33. package/src/codex/freshness.js +84 -84
  34. package/src/codex/governance.js +192 -192
  35. package/src/codex/interactive.js +618 -618
  36. package/src/codex/mcp-packs.js +914 -914
  37. package/src/codex/patch.js +209 -209
  38. package/src/codex/plans.js +251 -251
  39. package/src/codex/premium.js +614 -614
  40. package/src/codex/setup.js +591 -591
  41. package/src/continuous-ops.js +681 -681
  42. package/src/copilot/activity.js +309 -309
  43. package/src/copilot/deep-review.js +346 -346
  44. package/src/copilot/domain-packs.js +372 -372
  45. package/src/copilot/freshness.js +57 -57
  46. package/src/copilot/governance.js +222 -222
  47. package/src/copilot/interactive.js +406 -406
  48. package/src/copilot/mcp-packs.js +826 -826
  49. package/src/copilot/plans.js +253 -253
  50. package/src/copilot/premium.js +451 -451
  51. package/src/copilot/setup.js +488 -488
  52. package/src/cost-tracking.js +61 -61
  53. package/src/cursor/activity.js +301 -301
  54. package/src/cursor/config-parser.js +265 -265
  55. package/src/cursor/context.js +256 -256
  56. package/src/cursor/deep-review.js +334 -334
  57. package/src/cursor/domain-packs.js +368 -368
  58. package/src/cursor/freshness.js +65 -65
  59. package/src/cursor/governance.js +229 -229
  60. package/src/cursor/interactive.js +391 -391
  61. package/src/cursor/mcp-packs.js +828 -828
  62. package/src/cursor/plans.js +254 -254
  63. package/src/cursor/premium.js +469 -469
  64. package/src/cursor/setup.js +488 -488
  65. package/src/dashboard.js +493 -493
  66. package/src/deep-review.js +428 -428
  67. package/src/deprecation.js +98 -98
  68. package/src/diff-only.js +280 -280
  69. package/src/doctor.js +119 -119
  70. package/src/domain-pack-expansion.js +1033 -1033
  71. package/src/domain-packs.js +387 -387
  72. package/src/feedback.js +178 -178
  73. package/src/fix-engine.js +783 -783
  74. package/src/fix-prompts.js +122 -122
  75. package/src/formatters/sarif.js +115 -115
  76. package/src/freshness.js +74 -74
  77. package/src/gemini/config-parser.js +275 -275
  78. package/src/gemini/deep-review.js +559 -559
  79. package/src/gemini/domain-packs.js +393 -393
  80. package/src/gemini/freshness.js +66 -66
  81. package/src/gemini/governance.js +201 -201
  82. package/src/gemini/interactive.js +860 -860
  83. package/src/gemini/mcp-packs.js +915 -915
  84. package/src/gemini/plans.js +269 -269
  85. package/src/gemini/premium.js +760 -760
  86. package/src/gemini/setup.js +692 -692
  87. package/src/governance.js +72 -72
  88. package/src/harmony/add.js +68 -68
  89. package/src/harmony/advisor.js +333 -333
  90. package/src/harmony/canon.js +565 -565
  91. package/src/harmony/cli.js +591 -591
  92. package/src/harmony/drift.js +401 -401
  93. package/src/harmony/governance.js +313 -313
  94. package/src/harmony/memory.js +239 -239
  95. package/src/harmony/sync.js +475 -475
  96. package/src/harmony/watch.js +370 -370
  97. package/src/hook-validation.js +342 -342
  98. package/src/index.js +271 -271
  99. package/src/init.js +184 -184
  100. package/src/instruction-surfaces.js +185 -185
  101. package/src/integrations.js +144 -144
  102. package/src/interactive.js +118 -118
  103. package/src/locales/en.json +1 -1
  104. package/src/locales/es.json +1 -1
  105. package/src/mcp-packs.js +830 -830
  106. package/src/mcp-server.js +726 -726
  107. package/src/mcp-validation.js +337 -337
  108. package/src/nerviq-sync.json +7 -7
  109. package/src/opencode/config-parser.js +109 -109
  110. package/src/opencode/context.js +247 -247
  111. package/src/opencode/deep-review.js +313 -313
  112. package/src/opencode/domain-packs.js +262 -262
  113. package/src/opencode/freshness.js +66 -66
  114. package/src/opencode/governance.js +159 -159
  115. package/src/opencode/interactive.js +392 -392
  116. package/src/opencode/mcp-packs.js +705 -705
  117. package/src/opencode/patch.js +184 -184
  118. package/src/opencode/plans.js +231 -231
  119. package/src/opencode/premium.js +413 -413
  120. package/src/opencode/setup.js +449 -449
  121. package/src/opencode/techniques.js +27 -27
  122. package/src/operating-profile.js +574 -574
  123. package/src/org.js +152 -152
  124. package/src/permission-rules.js +218 -218
  125. package/src/plans.js +839 -839
  126. package/src/platform-change-manifest.js +86 -86
  127. package/src/plugins.js +110 -110
  128. package/src/policy-layers.js +210 -210
  129. package/src/profiles.js +124 -124
  130. package/src/prompt-injection.js +74 -74
  131. package/src/public-api.js +173 -173
  132. package/src/recommendation-rules.js +84 -84
  133. package/src/repo-archetype.js +386 -386
  134. package/src/secret-patterns.js +39 -39
  135. package/src/server.js +527 -527
  136. package/src/setup/analysis.js +607 -607
  137. package/src/setup/runtime.js +172 -172
  138. package/src/setup.js +677 -677
  139. package/src/shared/capabilities.js +194 -194
  140. package/src/source-urls.js +132 -132
  141. package/src/stack-checks.js +565 -565
  142. package/src/supplemental-checks.js +13 -13
  143. package/src/synergy/adaptive.js +261 -261
  144. package/src/synergy/compensation.js +137 -137
  145. package/src/synergy/evidence.js +193 -193
  146. package/src/synergy/learning.js +199 -199
  147. package/src/synergy/patterns.js +227 -227
  148. package/src/synergy/ranking.js +83 -83
  149. package/src/synergy/report.js +165 -165
  150. package/src/synergy/routing.js +146 -146
  151. package/src/techniques/api.js +407 -407
  152. package/src/techniques/automation.js +316 -316
  153. package/src/techniques/compliance.js +257 -257
  154. package/src/techniques/hygiene.js +294 -294
  155. package/src/techniques/instructions.js +243 -243
  156. package/src/techniques/observability.js +226 -226
  157. package/src/techniques/optimization.js +142 -142
  158. package/src/techniques/quality.js +318 -318
  159. package/src/techniques/security.js +237 -237
  160. package/src/techniques/shared.js +443 -443
  161. package/src/techniques/stacks.js +2294 -2294
  162. package/src/techniques/tools.js +106 -106
  163. package/src/techniques/workflow.js +413 -413
  164. package/src/techniques.js +81 -81
  165. package/src/terminology.js +73 -73
  166. package/src/token-estimate.js +35 -35
  167. package/src/usage-patterns.js +99 -99
  168. package/src/verification-metadata.js +145 -145
  169. package/src/watch.js +247 -247
  170. package/src/windsurf/activity.js +302 -302
  171. package/src/windsurf/config-parser.js +267 -267
  172. package/src/windsurf/deep-review.js +337 -337
  173. package/src/windsurf/domain-packs.js +370 -370
  174. package/src/windsurf/freshness.js +36 -36
  175. package/src/windsurf/governance.js +231 -231
  176. package/src/windsurf/interactive.js +388 -388
  177. package/src/windsurf/mcp-packs.js +792 -792
  178. package/src/windsurf/plans.js +247 -247
  179. package/src/windsurf/premium.js +468 -468
  180. package/src/windsurf/setup.js +471 -471
  181. package/src/workspace.js +375 -375
@@ -1,360 +1,360 @@
1
- /**
2
- * Aider Premium Operator UX
3
- *
4
- * Three subsystems:
5
- * 1. Multi-Pack Composition Engine — merge domain packs with dedup and conflict resolution
6
- * 2. CI Template Library — GitHub Actions workflow templates for Aider automation
7
- * 3. Adoption Signal Gate — activate features based on local usage telemetry
8
- */
9
-
10
- const path = require('path');
11
- const { AIDER_DOMAIN_PACKS } = require('./domain-packs');
12
- const { AIDER_MCP_PACKS } = require('./mcp-packs');
13
- const { getAiderHistory } = require('./activity');
14
-
15
- // ---------------------------------------------------------------------------
16
- // 1. Multi-Pack Composition Engine
17
- // ---------------------------------------------------------------------------
18
-
19
- const PACK_DEPENDENCY_ORDER = [
20
- 'baseline-general',
21
- 'backend-api',
22
- 'frontend-ui',
23
- 'infra-platform',
24
- 'monorepo',
25
- 'enterprise-governed',
26
- ];
27
-
28
- const PACK_SPECIFICITY = {
29
- 'baseline-general': 0,
30
- 'backend-api': 2,
31
- 'frontend-ui': 2,
32
- 'infra-platform': 3,
33
- 'monorepo': 3,
34
- 'enterprise-governed': 4,
35
- };
36
-
37
- const DEFAULT_SIZE_BUDGET = 16000;
38
-
39
- function lookupDomainPack(key) {
40
- return AIDER_DOMAIN_PACKS.find(p => p.key === key) || null;
41
- }
42
-
43
- function lookupMcpPack(key) {
44
- return AIDER_MCP_PACKS.find(p => p.key === key) || null;
45
- }
46
-
47
- /**
48
- * Compose domain packs into a unified, deduplicated, ordered result.
49
- */
50
- function composePacks(domainPackKeys = [], mcpPackKeys = [], options = {}) {
51
- const sizeBudget = options.sizeBudget || DEFAULT_SIZE_BUDGET;
52
- const warnings = [];
53
-
54
- // Resolve domain packs
55
- const seenDomainKeys = new Set();
56
- const rawDomainPacks = [];
57
- for (const key of domainPackKeys) {
58
- if (seenDomainKeys.has(key)) continue;
59
- seenDomainKeys.add(key);
60
- const pack = lookupDomainPack(key);
61
- if (!pack) {
62
- warnings.push(`Domain pack "${key}" not found, skipped.`);
63
- continue;
64
- }
65
- rawDomainPacks.push(pack);
66
- }
67
-
68
- // Order by dependency
69
- rawDomainPacks.sort((a, b) => {
70
- const orderA = PACK_DEPENDENCY_ORDER.indexOf(a.key);
71
- const orderB = PACK_DEPENDENCY_ORDER.indexOf(b.key);
72
- return (orderA === -1 ? 99 : orderA) - (orderB === -1 ? 99 : orderB);
73
- });
74
-
75
- // Deduplicate recommended modules
76
- const seenModules = new Set();
77
- const mergedModules = [];
78
- for (const pack of rawDomainPacks) {
79
- for (const mod of pack.recommendedModules || []) {
80
- if (!seenModules.has(mod)) {
81
- seenModules.add(mod);
82
- mergedModules.push(mod);
83
- }
84
- }
85
- }
86
-
87
- // Deduplicate recommended surfaces
88
- const seenSurfaces = new Set();
89
- const mergedSurfaces = [];
90
- for (const pack of rawDomainPacks) {
91
- for (const surface of pack.recommendedSurfaces || []) {
92
- if (!seenSurfaces.has(surface)) {
93
- seenSurfaces.add(surface);
94
- mergedSurfaces.push(surface);
95
- }
96
- }
97
- }
98
-
99
- // Deduplicate proposal families
100
- const seenFamilies = new Set();
101
- const mergedFamilies = [];
102
- for (const pack of rawDomainPacks) {
103
- for (const family of pack.recommendedProposalFamilies || []) {
104
- if (!seenFamilies.has(family)) {
105
- seenFamilies.add(family);
106
- mergedFamilies.push(family);
107
- }
108
- }
109
- }
110
-
111
- // MCP packs (minimal for Aider)
112
- const resolvedMcpPacks = mcpPackKeys
113
- .map(key => lookupMcpPack(key))
114
- .filter(Boolean);
115
-
116
- // Size check
117
- const estimatedSize = mergedModules.join('\n').length + mergedSurfaces.join('\n').length;
118
- if (estimatedSize > sizeBudget) {
119
- warnings.push(`Combined content (~${estimatedSize} chars) exceeds budget of ${sizeBudget}.`);
120
- }
121
-
122
- return {
123
- domainPacks: rawDomainPacks.map(p => p.key),
124
- mcpPacks: resolvedMcpPacks.map(p => p.key),
125
- mergedModules,
126
- mergedSurfaces,
127
- mergedFamilies,
128
- warnings,
129
- estimatedSize,
130
- withinBudget: estimatedSize <= sizeBudget,
131
- };
132
- }
133
-
134
- // ---------------------------------------------------------------------------
135
- // 2. CI Template Library
136
- // ---------------------------------------------------------------------------
137
-
138
- const CI_TEMPLATES = {
139
- 'aider-lint-test': {
140
- key: 'aider-lint-test',
141
- label: 'Lint & Test on PR',
142
- description: 'Run lint and test checks on Aider-generated PRs.',
143
- template: `name: Aider PR Checks
144
- on:
145
- pull_request:
146
- branches: [main]
147
-
148
- jobs:
149
- check:
150
- runs-on: ubuntu-latest
151
- steps:
152
- - uses: actions/checkout@v4
153
- - name: Setup
154
- run: npm ci
155
- - name: Lint
156
- run: npm run lint
157
- - name: Test
158
- run: npm test
159
- `,
160
- },
161
-
162
- 'aider-auto-pr': {
163
- key: 'aider-auto-pr',
164
- label: 'Aider Auto PR',
165
- description: 'Run Aider in CI to generate PRs from issues.',
166
- template: `name: Aider Auto PR
167
- on:
168
- issues:
169
- types: [labeled]
170
-
171
- jobs:
172
- aider-fix:
173
- if: contains(github.event.label.name, 'aider')
174
- runs-on: ubuntu-latest
175
- steps:
176
- - uses: actions/checkout@v4
177
- - name: Install Aider
178
- run: pip install aider-chat
179
- - name: Run Aider
180
- env:
181
- ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
182
- run: |
183
- aider --yes --message "Fix issue #\${{ github.event.issue.number }}: \${{ github.event.issue.title }}"
184
- - name: Create PR
185
- uses: peter-evans/create-pull-request@v6
186
- with:
187
- title: "aider: Fix #\${{ github.event.issue.number }}"
188
- branch: aider/fix-\${{ github.event.issue.number }}
189
- commit-message: "aider: address issue #\${{ github.event.issue.number }}"
190
- `,
191
- },
192
-
193
- 'aider-review-gate': {
194
- key: 'aider-review-gate',
195
- label: 'Aider Review Gate',
196
- description: 'Require reviews on AI-authored PRs (detected by commit prefix).',
197
- template: `name: Aider Review Gate
198
- on:
199
- pull_request:
200
- branches: [main]
201
-
202
- jobs:
203
- check-ai-authored:
204
- runs-on: ubuntu-latest
205
- steps:
206
- - uses: actions/checkout@v4
207
- with:
208
- fetch-depth: 0
209
- - name: Check for AI commits
210
- id: ai-check
211
- run: |
212
- AI_COMMITS=\$(git log --format='%s' origin/main..HEAD | grep -c '^aider:' || true)
213
- echo "ai_commits=\$AI_COMMITS" >> \$GITHUB_OUTPUT
214
- - name: Require review for AI commits
215
- if: steps.ai-check.outputs.ai_commits > 0
216
- run: |
217
- echo "This PR contains \${{ steps.ai-check.outputs.ai_commits }} AI-authored commit(s)."
218
- echo "Manual review required before merge."
219
- `,
220
- },
221
-
222
- 'aider-audit': {
223
- key: 'aider-audit',
224
- label: 'Aider Setup Audit',
225
- description: 'Run nerviq audit on Aider config in CI.',
226
- template: `name: Aider Config Audit
227
- on:
228
- push:
229
- paths:
230
- - '.aider.conf.yml'
231
- - 'CONVENTIONS.md'
232
- - '.aiderignore'
233
- pull_request:
234
- paths:
235
- - '.aider.conf.yml'
236
- - 'CONVENTIONS.md'
237
- - '.aiderignore'
238
-
239
- jobs:
240
- audit:
241
- runs-on: ubuntu-latest
242
- steps:
243
- - uses: actions/checkout@v4
244
- - name: Run Aider Audit
245
- run: npx nerviq --platform aider --ci
246
- `,
247
- },
248
-
249
- 'aider-scheduled': {
250
- key: 'aider-scheduled',
251
- label: 'Scheduled Aider Tasks',
252
- description: 'Run Aider on a schedule for maintenance tasks.',
253
- template: `name: Scheduled Aider Maintenance
254
- on:
255
- schedule:
256
- - cron: '0 6 * * 1' # Every Monday at 6am UTC
257
-
258
- jobs:
259
- maintenance:
260
- runs-on: ubuntu-latest
261
- steps:
262
- - uses: actions/checkout@v4
263
- - name: Install Aider
264
- run: pip install aider-chat
265
- - name: Run maintenance
266
- env:
267
- ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
268
- run: |
269
- aider --yes --message "Run weekly dependency update and lint fixes"
270
- - name: Create PR
271
- uses: peter-evans/create-pull-request@v6
272
- with:
273
- title: "aider: Weekly maintenance"
274
- branch: aider/weekly-maintenance
275
- `,
276
- },
277
- };
278
-
279
- function getCiTemplate(key) {
280
- return CI_TEMPLATES[key] || null;
281
- }
282
-
283
- // ---------------------------------------------------------------------------
284
- // 3. Adoption Signal Gate
285
- // ---------------------------------------------------------------------------
286
-
287
- const GATE_THRESHOLDS = {
288
- 'deep-review': {
289
- threshold: 3,
290
- description: 'Activate deep review after 3 audit snapshots.',
291
- metric: 'snapshotCount',
292
- },
293
- 'ci-templates': {
294
- threshold: 5,
295
- description: 'Suggest CI templates after 5 audits with score > 50.',
296
- metric: 'qualifyingAudits',
297
- },
298
- 'composition': {
299
- threshold: 2,
300
- description: 'Enable pack composition after using 2+ domain packs.',
301
- metric: 'domainPackCount',
302
- },
303
- 'trend-export': {
304
- threshold: 5,
305
- description: 'Enable trend export after 5 snapshots.',
306
- metric: 'snapshotCount',
307
- },
308
- };
309
-
310
- function checkAdoptionGate(dir, gateKey) {
311
- const gate = GATE_THRESHOLDS[gateKey];
312
- if (!gate) return { activated: false, current: 0, threshold: 0, gate: gateKey, description: 'Unknown gate' };
313
-
314
- const history = getAiderHistory(dir, 50);
315
- let current = 0;
316
-
317
- switch (gate.metric) {
318
- case 'snapshotCount':
319
- current = history.length;
320
- break;
321
- case 'qualifyingAudits':
322
- current = history.filter(e => (e.summary?.score ?? 0) > 50).length;
323
- break;
324
- case 'domainPackCount': {
325
- const packs = new Set();
326
- for (const entry of history) {
327
- for (const pack of (entry.summary?.domainPacks || [])) {
328
- packs.add(pack);
329
- }
330
- }
331
- current = packs.size;
332
- break;
333
- }
334
- default:
335
- current = 0;
336
- }
337
-
338
- return {
339
- activated: current >= gate.threshold,
340
- current,
341
- threshold: gate.threshold,
342
- gate: gateKey,
343
- description: gate.description,
344
- };
345
- }
346
-
347
- // ---------------------------------------------------------------------------
348
- // Exports
349
- // ---------------------------------------------------------------------------
350
-
351
- module.exports = {
352
- composePacks,
353
- getCiTemplate,
354
- CI_TEMPLATES,
355
- checkAdoptionGate,
356
- GATE_THRESHOLDS,
357
- PACK_DEPENDENCY_ORDER,
358
- PACK_SPECIFICITY,
359
- DEFAULT_SIZE_BUDGET,
360
- };
1
+ /**
2
+ * Aider Premium Operator UX
3
+ *
4
+ * Three subsystems:
5
+ * 1. Multi-Pack Composition Engine — merge domain packs with dedup and conflict resolution
6
+ * 2. CI Template Library — GitHub Actions workflow templates for Aider automation
7
+ * 3. Adoption Signal Gate — activate features based on local usage telemetry
8
+ */
9
+
10
+ const path = require('path');
11
+ const { AIDER_DOMAIN_PACKS } = require('./domain-packs');
12
+ const { AIDER_MCP_PACKS } = require('./mcp-packs');
13
+ const { getAiderHistory } = require('./activity');
14
+
15
+ // ---------------------------------------------------------------------------
16
+ // 1. Multi-Pack Composition Engine
17
+ // ---------------------------------------------------------------------------
18
+
19
+ const PACK_DEPENDENCY_ORDER = [
20
+ 'baseline-general',
21
+ 'backend-api',
22
+ 'frontend-ui',
23
+ 'infra-platform',
24
+ 'monorepo',
25
+ 'enterprise-governed',
26
+ ];
27
+
28
+ const PACK_SPECIFICITY = {
29
+ 'baseline-general': 0,
30
+ 'backend-api': 2,
31
+ 'frontend-ui': 2,
32
+ 'infra-platform': 3,
33
+ 'monorepo': 3,
34
+ 'enterprise-governed': 4,
35
+ };
36
+
37
+ const DEFAULT_SIZE_BUDGET = 16000;
38
+
39
+ function lookupDomainPack(key) {
40
+ return AIDER_DOMAIN_PACKS.find(p => p.key === key) || null;
41
+ }
42
+
43
+ function lookupMcpPack(key) {
44
+ return AIDER_MCP_PACKS.find(p => p.key === key) || null;
45
+ }
46
+
47
+ /**
48
+ * Compose domain packs into a unified, deduplicated, ordered result.
49
+ */
50
+ function composePacks(domainPackKeys = [], mcpPackKeys = [], options = {}) {
51
+ const sizeBudget = options.sizeBudget || DEFAULT_SIZE_BUDGET;
52
+ const warnings = [];
53
+
54
+ // Resolve domain packs
55
+ const seenDomainKeys = new Set();
56
+ const rawDomainPacks = [];
57
+ for (const key of domainPackKeys) {
58
+ if (seenDomainKeys.has(key)) continue;
59
+ seenDomainKeys.add(key);
60
+ const pack = lookupDomainPack(key);
61
+ if (!pack) {
62
+ warnings.push(`Domain pack "${key}" not found, skipped.`);
63
+ continue;
64
+ }
65
+ rawDomainPacks.push(pack);
66
+ }
67
+
68
+ // Order by dependency
69
+ rawDomainPacks.sort((a, b) => {
70
+ const orderA = PACK_DEPENDENCY_ORDER.indexOf(a.key);
71
+ const orderB = PACK_DEPENDENCY_ORDER.indexOf(b.key);
72
+ return (orderA === -1 ? 99 : orderA) - (orderB === -1 ? 99 : orderB);
73
+ });
74
+
75
+ // Deduplicate recommended modules
76
+ const seenModules = new Set();
77
+ const mergedModules = [];
78
+ for (const pack of rawDomainPacks) {
79
+ for (const mod of pack.recommendedModules || []) {
80
+ if (!seenModules.has(mod)) {
81
+ seenModules.add(mod);
82
+ mergedModules.push(mod);
83
+ }
84
+ }
85
+ }
86
+
87
+ // Deduplicate recommended surfaces
88
+ const seenSurfaces = new Set();
89
+ const mergedSurfaces = [];
90
+ for (const pack of rawDomainPacks) {
91
+ for (const surface of pack.recommendedSurfaces || []) {
92
+ if (!seenSurfaces.has(surface)) {
93
+ seenSurfaces.add(surface);
94
+ mergedSurfaces.push(surface);
95
+ }
96
+ }
97
+ }
98
+
99
+ // Deduplicate proposal families
100
+ const seenFamilies = new Set();
101
+ const mergedFamilies = [];
102
+ for (const pack of rawDomainPacks) {
103
+ for (const family of pack.recommendedProposalFamilies || []) {
104
+ if (!seenFamilies.has(family)) {
105
+ seenFamilies.add(family);
106
+ mergedFamilies.push(family);
107
+ }
108
+ }
109
+ }
110
+
111
+ // MCP packs (minimal for Aider)
112
+ const resolvedMcpPacks = mcpPackKeys
113
+ .map(key => lookupMcpPack(key))
114
+ .filter(Boolean);
115
+
116
+ // Size check
117
+ const estimatedSize = mergedModules.join('\n').length + mergedSurfaces.join('\n').length;
118
+ if (estimatedSize > sizeBudget) {
119
+ warnings.push(`Combined content (~${estimatedSize} chars) exceeds budget of ${sizeBudget}.`);
120
+ }
121
+
122
+ return {
123
+ domainPacks: rawDomainPacks.map(p => p.key),
124
+ mcpPacks: resolvedMcpPacks.map(p => p.key),
125
+ mergedModules,
126
+ mergedSurfaces,
127
+ mergedFamilies,
128
+ warnings,
129
+ estimatedSize,
130
+ withinBudget: estimatedSize <= sizeBudget,
131
+ };
132
+ }
133
+
134
+ // ---------------------------------------------------------------------------
135
+ // 2. CI Template Library
136
+ // ---------------------------------------------------------------------------
137
+
138
+ const CI_TEMPLATES = {
139
+ 'aider-lint-test': {
140
+ key: 'aider-lint-test',
141
+ label: 'Lint & Test on PR',
142
+ description: 'Run lint and test checks on Aider-generated PRs.',
143
+ template: `name: Aider PR Checks
144
+ on:
145
+ pull_request:
146
+ branches: [main]
147
+
148
+ jobs:
149
+ check:
150
+ runs-on: ubuntu-latest
151
+ steps:
152
+ - uses: actions/checkout@v4
153
+ - name: Setup
154
+ run: npm ci
155
+ - name: Lint
156
+ run: npm run lint
157
+ - name: Test
158
+ run: npm test
159
+ `,
160
+ },
161
+
162
+ 'aider-auto-pr': {
163
+ key: 'aider-auto-pr',
164
+ label: 'Aider Auto PR',
165
+ description: 'Run Aider in CI to generate PRs from issues.',
166
+ template: `name: Aider Auto PR
167
+ on:
168
+ issues:
169
+ types: [labeled]
170
+
171
+ jobs:
172
+ aider-fix:
173
+ if: contains(github.event.label.name, 'aider')
174
+ runs-on: ubuntu-latest
175
+ steps:
176
+ - uses: actions/checkout@v4
177
+ - name: Install Aider
178
+ run: pip install aider-chat
179
+ - name: Run Aider
180
+ env:
181
+ ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
182
+ run: |
183
+ aider --yes --message "Fix issue #\${{ github.event.issue.number }}: \${{ github.event.issue.title }}"
184
+ - name: Create PR
185
+ uses: peter-evans/create-pull-request@v6
186
+ with:
187
+ title: "aider: Fix #\${{ github.event.issue.number }}"
188
+ branch: aider/fix-\${{ github.event.issue.number }}
189
+ commit-message: "aider: address issue #\${{ github.event.issue.number }}"
190
+ `,
191
+ },
192
+
193
+ 'aider-review-gate': {
194
+ key: 'aider-review-gate',
195
+ label: 'Aider Review Gate',
196
+ description: 'Require reviews on AI-authored PRs (detected by commit prefix).',
197
+ template: `name: Aider Review Gate
198
+ on:
199
+ pull_request:
200
+ branches: [main]
201
+
202
+ jobs:
203
+ check-ai-authored:
204
+ runs-on: ubuntu-latest
205
+ steps:
206
+ - uses: actions/checkout@v4
207
+ with:
208
+ fetch-depth: 0
209
+ - name: Check for AI commits
210
+ id: ai-check
211
+ run: |
212
+ AI_COMMITS=\$(git log --format='%s' origin/main..HEAD | grep -c '^aider:' || true)
213
+ echo "ai_commits=\$AI_COMMITS" >> \$GITHUB_OUTPUT
214
+ - name: Require review for AI commits
215
+ if: steps.ai-check.outputs.ai_commits > 0
216
+ run: |
217
+ echo "This PR contains \${{ steps.ai-check.outputs.ai_commits }} AI-authored commit(s)."
218
+ echo "Manual review required before merge."
219
+ `,
220
+ },
221
+
222
+ 'aider-audit': {
223
+ key: 'aider-audit',
224
+ label: 'Aider Setup Audit',
225
+ description: 'Run nerviq audit on Aider config in CI.',
226
+ template: `name: Aider Config Audit
227
+ on:
228
+ push:
229
+ paths:
230
+ - '.aider.conf.yml'
231
+ - 'CONVENTIONS.md'
232
+ - '.aiderignore'
233
+ pull_request:
234
+ paths:
235
+ - '.aider.conf.yml'
236
+ - 'CONVENTIONS.md'
237
+ - '.aiderignore'
238
+
239
+ jobs:
240
+ audit:
241
+ runs-on: ubuntu-latest
242
+ steps:
243
+ - uses: actions/checkout@v4
244
+ - name: Run Aider Audit
245
+ run: npx nerviq --platform aider --ci
246
+ `,
247
+ },
248
+
249
+ 'aider-scheduled': {
250
+ key: 'aider-scheduled',
251
+ label: 'Scheduled Aider Tasks',
252
+ description: 'Run Aider on a schedule for maintenance tasks.',
253
+ template: `name: Scheduled Aider Maintenance
254
+ on:
255
+ schedule:
256
+ - cron: '0 6 * * 1' # Every Monday at 6am UTC
257
+
258
+ jobs:
259
+ maintenance:
260
+ runs-on: ubuntu-latest
261
+ steps:
262
+ - uses: actions/checkout@v4
263
+ - name: Install Aider
264
+ run: pip install aider-chat
265
+ - name: Run maintenance
266
+ env:
267
+ ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
268
+ run: |
269
+ aider --yes --message "Run weekly dependency update and lint fixes"
270
+ - name: Create PR
271
+ uses: peter-evans/create-pull-request@v6
272
+ with:
273
+ title: "aider: Weekly maintenance"
274
+ branch: aider/weekly-maintenance
275
+ `,
276
+ },
277
+ };
278
+
279
+ function getCiTemplate(key) {
280
+ return CI_TEMPLATES[key] || null;
281
+ }
282
+
283
+ // ---------------------------------------------------------------------------
284
+ // 3. Adoption Signal Gate
285
+ // ---------------------------------------------------------------------------
286
+
287
+ const GATE_THRESHOLDS = {
288
+ 'deep-review': {
289
+ threshold: 3,
290
+ description: 'Activate deep review after 3 audit snapshots.',
291
+ metric: 'snapshotCount',
292
+ },
293
+ 'ci-templates': {
294
+ threshold: 5,
295
+ description: 'Suggest CI templates after 5 audits with score > 50.',
296
+ metric: 'qualifyingAudits',
297
+ },
298
+ 'composition': {
299
+ threshold: 2,
300
+ description: 'Enable pack composition after using 2+ domain packs.',
301
+ metric: 'domainPackCount',
302
+ },
303
+ 'trend-export': {
304
+ threshold: 5,
305
+ description: 'Enable trend export after 5 snapshots.',
306
+ metric: 'snapshotCount',
307
+ },
308
+ };
309
+
310
+ function checkAdoptionGate(dir, gateKey) {
311
+ const gate = GATE_THRESHOLDS[gateKey];
312
+ if (!gate) return { activated: false, current: 0, threshold: 0, gate: gateKey, description: 'Unknown gate' };
313
+
314
+ const history = getAiderHistory(dir, 50);
315
+ let current = 0;
316
+
317
+ switch (gate.metric) {
318
+ case 'snapshotCount':
319
+ current = history.length;
320
+ break;
321
+ case 'qualifyingAudits':
322
+ current = history.filter(e => (e.summary?.score ?? 0) > 50).length;
323
+ break;
324
+ case 'domainPackCount': {
325
+ const packs = new Set();
326
+ for (const entry of history) {
327
+ for (const pack of (entry.summary?.domainPacks || [])) {
328
+ packs.add(pack);
329
+ }
330
+ }
331
+ current = packs.size;
332
+ break;
333
+ }
334
+ default:
335
+ current = 0;
336
+ }
337
+
338
+ return {
339
+ activated: current >= gate.threshold,
340
+ current,
341
+ threshold: gate.threshold,
342
+ gate: gateKey,
343
+ description: gate.description,
344
+ };
345
+ }
346
+
347
+ // ---------------------------------------------------------------------------
348
+ // Exports
349
+ // ---------------------------------------------------------------------------
350
+
351
+ module.exports = {
352
+ composePacks,
353
+ getCiTemplate,
354
+ CI_TEMPLATES,
355
+ checkAdoptionGate,
356
+ GATE_THRESHOLDS,
357
+ PACK_DEPENDENCY_ORDER,
358
+ PACK_SPECIFICITY,
359
+ DEFAULT_SIZE_BUDGET,
360
+ };