@nerviq/cli 1.17.3 → 1.19.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 (190) hide show
  1. package/LICENSE +23 -23
  2. package/README.md +4 -4
  3. package/bin/cli.js +61 -274
  4. package/package.json +60 -60
  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/config-parser.js +280 -226
  46. package/src/copilot/context.js +218 -197
  47. package/src/copilot/deep-review.js +346 -346
  48. package/src/copilot/domain-packs.js +372 -372
  49. package/src/copilot/freshness.js +57 -57
  50. package/src/copilot/governance.js +222 -222
  51. package/src/copilot/interactive.js +406 -406
  52. package/src/copilot/mcp-packs.js +826 -826
  53. package/src/copilot/plans.js +253 -253
  54. package/src/copilot/premium.js +451 -451
  55. package/src/copilot/setup.js +488 -488
  56. package/src/copilot/techniques.js +219 -78
  57. package/src/cost-tracking.js +61 -61
  58. package/src/cursor/activity.js +301 -301
  59. package/src/cursor/config-parser.js +265 -265
  60. package/src/cursor/context.js +256 -256
  61. package/src/cursor/deep-review.js +334 -334
  62. package/src/cursor/domain-packs.js +368 -368
  63. package/src/cursor/freshness.js +65 -65
  64. package/src/cursor/governance.js +229 -229
  65. package/src/cursor/interactive.js +391 -391
  66. package/src/cursor/mcp-packs.js +828 -828
  67. package/src/cursor/plans.js +254 -254
  68. package/src/cursor/premium.js +469 -469
  69. package/src/cursor/setup.js +488 -488
  70. package/src/dashboard.js +493 -493
  71. package/src/deep-review.js +428 -428
  72. package/src/deprecation.js +98 -98
  73. package/src/diff-only.js +280 -280
  74. package/src/doctor.js +119 -119
  75. package/src/domain-pack-expansion.js +1033 -1033
  76. package/src/domain-packs.js +387 -387
  77. package/src/feedback.js +178 -178
  78. package/src/fix-engine.js +783 -0
  79. package/src/fix-prompts.js +122 -122
  80. package/src/formatters/sarif.js +115 -115
  81. package/src/freshness.js +74 -74
  82. package/src/gemini/config-parser.js +275 -275
  83. package/src/gemini/context.js +221 -221
  84. package/src/gemini/deep-review.js +559 -559
  85. package/src/gemini/domain-packs.js +393 -393
  86. package/src/gemini/freshness.js +66 -66
  87. package/src/gemini/governance.js +201 -201
  88. package/src/gemini/interactive.js +860 -860
  89. package/src/gemini/mcp-packs.js +915 -915
  90. package/src/gemini/plans.js +269 -269
  91. package/src/gemini/premium.js +760 -760
  92. package/src/gemini/setup.js +692 -692
  93. package/src/gemini/techniques.js +14 -14
  94. package/src/governance.js +72 -72
  95. package/src/harmony/add.js +68 -68
  96. package/src/harmony/advisor.js +333 -333
  97. package/src/harmony/canon.js +565 -565
  98. package/src/harmony/cli.js +591 -591
  99. package/src/harmony/drift.js +401 -401
  100. package/src/harmony/governance.js +313 -313
  101. package/src/harmony/memory.js +239 -239
  102. package/src/harmony/sync.js +475 -475
  103. package/src/harmony/watch.js +370 -370
  104. package/src/hook-validation.js +342 -342
  105. package/src/index.js +271 -271
  106. package/src/init.js +184 -184
  107. package/src/instruction-surfaces.js +185 -185
  108. package/src/integrations.js +144 -144
  109. package/src/interactive.js +118 -118
  110. package/src/locales/en.json +1 -1
  111. package/src/locales/es.json +1 -1
  112. package/src/mcp-packs.js +830 -830
  113. package/src/mcp-server.js +726 -726
  114. package/src/mcp-validation.js +337 -337
  115. package/src/nerviq-sync.json +7 -7
  116. package/src/opencode/config-parser.js +109 -109
  117. package/src/opencode/context.js +247 -247
  118. package/src/opencode/deep-review.js +313 -313
  119. package/src/opencode/domain-packs.js +262 -262
  120. package/src/opencode/freshness.js +66 -66
  121. package/src/opencode/governance.js +159 -159
  122. package/src/opencode/interactive.js +392 -392
  123. package/src/opencode/mcp-packs.js +705 -705
  124. package/src/opencode/patch.js +184 -184
  125. package/src/opencode/plans.js +231 -231
  126. package/src/opencode/premium.js +413 -413
  127. package/src/opencode/setup.js +449 -449
  128. package/src/opencode/techniques.js +27 -27
  129. package/src/operating-profile.js +574 -574
  130. package/src/org.js +152 -152
  131. package/src/permission-rules.js +218 -218
  132. package/src/plans.js +839 -839
  133. package/src/platform-change-manifest.js +86 -86
  134. package/src/plugins.js +110 -110
  135. package/src/policy-layers.js +210 -210
  136. package/src/profiles.js +124 -124
  137. package/src/prompt-injection.js +74 -74
  138. package/src/public-api.js +173 -173
  139. package/src/recommendation-rules.js +84 -84
  140. package/src/repo-archetype.js +386 -386
  141. package/src/secret-patterns.js +39 -39
  142. package/src/server.js +527 -527
  143. package/src/setup/analysis.js +607 -607
  144. package/src/setup/runtime.js +172 -172
  145. package/src/setup.js +677 -677
  146. package/src/shared/capabilities.js +194 -194
  147. package/src/source-urls.js +132 -132
  148. package/src/stack-checks.js +565 -565
  149. package/src/supplemental-checks.js +13 -13
  150. package/src/synergy/adaptive.js +261 -261
  151. package/src/synergy/compensation.js +137 -137
  152. package/src/synergy/evidence.js +193 -193
  153. package/src/synergy/learning.js +199 -199
  154. package/src/synergy/patterns.js +227 -227
  155. package/src/synergy/ranking.js +83 -83
  156. package/src/synergy/report.js +165 -165
  157. package/src/synergy/routing.js +146 -146
  158. package/src/techniques/api.js +407 -407
  159. package/src/techniques/automation.js +316 -316
  160. package/src/techniques/compliance.js +257 -257
  161. package/src/techniques/hygiene.js +294 -294
  162. package/src/techniques/instructions.js +243 -243
  163. package/src/techniques/observability.js +226 -226
  164. package/src/techniques/optimization.js +142 -142
  165. package/src/techniques/quality.js +318 -318
  166. package/src/techniques/security.js +237 -237
  167. package/src/techniques/shared.js +443 -443
  168. package/src/techniques/stacks.js +2294 -2294
  169. package/src/techniques/tools.js +106 -106
  170. package/src/techniques/workflow.js +413 -413
  171. package/src/techniques.js +81 -81
  172. package/src/terminology.js +73 -73
  173. package/src/token-estimate.js +35 -35
  174. package/src/usage-patterns.js +99 -99
  175. package/src/verification-metadata.js +145 -145
  176. package/src/watch.js +247 -247
  177. package/src/windsurf/activity.js +302 -302
  178. package/src/windsurf/config-parser.js +267 -267
  179. package/src/windsurf/context.js +249 -249
  180. package/src/windsurf/deep-review.js +337 -337
  181. package/src/windsurf/domain-packs.js +370 -370
  182. package/src/windsurf/freshness.js +36 -36
  183. package/src/windsurf/governance.js +231 -231
  184. package/src/windsurf/interactive.js +388 -388
  185. package/src/windsurf/mcp-packs.js +792 -792
  186. package/src/windsurf/plans.js +247 -247
  187. package/src/windsurf/premium.js +468 -468
  188. package/src/windsurf/setup.js +471 -471
  189. package/src/windsurf/techniques.js +17 -17
  190. package/src/workspace.js +375 -375
@@ -1,413 +1,413 @@
1
- /**
2
- * OpenCode Premium Operator UX
3
- *
4
- * Three subsystems:
5
- * 1. Multi-Pack Composition Engine — merge domain + MCP packs with dedup, conflict resolution
6
- * 2. CI Template Library — 5 GitHub Actions workflow templates for OpenCode automation
7
- * 3. Adoption Signal Gate — activate features based on local usage telemetry
8
- */
9
-
10
- const path = require('path');
11
- const { OPENCODE_DOMAIN_PACKS } = require('./domain-packs');
12
- const { OPENCODE_MCP_PACKS } = require('./mcp-packs');
13
- const { getOpenCodeHistory } = 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 OPENCODE_DOMAIN_PACKS.find(p => p.key === key) || null;
41
- }
42
-
43
- function lookupMcpPack(key) {
44
- return OPENCODE_MCP_PACKS.find(p => p.key === key) || null;
45
- }
46
-
47
- function composePacks(domainPackKeys = [], mcpPackKeys = [], options = {}) {
48
- const sizeBudget = options.sizeBudget || DEFAULT_SIZE_BUDGET;
49
- const warnings = [];
50
-
51
- // Resolve domain packs
52
- const seenDomainKeys = new Set();
53
- const rawDomainPacks = [];
54
- for (const key of domainPackKeys) {
55
- if (seenDomainKeys.has(key)) continue;
56
- seenDomainKeys.add(key);
57
- const pack = lookupDomainPack(key);
58
- if (!pack) { warnings.push(`Domain pack "${key}" not found, skipped.`); continue; }
59
- rawDomainPacks.push(pack);
60
- }
61
-
62
- rawDomainPacks.sort((a, b) => {
63
- const orderA = PACK_DEPENDENCY_ORDER.indexOf(a.key);
64
- const orderB = PACK_DEPENDENCY_ORDER.indexOf(b.key);
65
- return (orderA === -1 ? 99 : orderA) - (orderB === -1 ? 99 : orderB);
66
- });
67
-
68
- const moduleOwner = new Map();
69
- for (const pack of rawDomainPacks) {
70
- const specificity = PACK_SPECIFICITY[pack.key] ?? 1;
71
- for (const mod of pack.recommendedModules || []) {
72
- const existing = moduleOwner.get(mod);
73
- if (!existing || specificity > existing.specificity) {
74
- moduleOwner.set(mod, { key: pack.key, specificity });
75
- }
76
- }
77
- }
78
-
79
- const allSurfaces = new Set();
80
- for (const pack of rawDomainPacks) {
81
- for (const surface of pack.recommendedSurfaces || []) allSurfaces.add(surface);
82
- }
83
-
84
- const allProposalFamilies = new Set();
85
- for (const pack of rawDomainPacks) {
86
- for (const family of pack.recommendedProposalFamilies || []) allProposalFamilies.add(family);
87
- }
88
-
89
- // Resolve MCP packs
90
- const seenMcpKeys = new Set();
91
- const resolvedMcpPacks = [];
92
- for (const key of mcpPackKeys) {
93
- if (seenMcpKeys.has(key)) continue;
94
- seenMcpKeys.add(key);
95
- const pack = lookupMcpPack(key);
96
- if (!pack) { warnings.push(`MCP pack "${key}" not found, skipped.`); continue; }
97
- resolvedMcpPacks.push(pack);
98
- }
99
-
100
- const mergedEnabledTools = new Set();
101
- for (const pack of resolvedMcpPacks) {
102
- for (const tool of pack.enabledTools || []) mergedEnabledTools.add(tool);
103
- }
104
-
105
- const mergedRequiredAuth = new Set();
106
- for (const pack of resolvedMcpPacks) {
107
- for (const auth of pack.requiredAuth || []) mergedRequiredAuth.add(auth);
108
- }
109
-
110
- const estimatedSize = estimateCompositionSize(rawDomainPacks, resolvedMcpPacks);
111
- const overBudget = estimatedSize > sizeBudget;
112
- if (overBudget) {
113
- warnings.push(`Combined size (~${estimatedSize} chars) exceeds budget (${sizeBudget}). Consider removing lower-priority packs.`);
114
- }
115
-
116
- return {
117
- domainPacks: rawDomainPacks.map(p => ({
118
- key: p.key,
119
- label: p.label,
120
- modulesOwned: [...moduleOwner.entries()].filter(([, owner]) => owner.key === p.key).map(([mod]) => mod),
121
- })),
122
- mcpPacks: resolvedMcpPacks.map(p => ({
123
- key: p.key,
124
- label: p.label,
125
- serverName: p.serverName,
126
- trustLevel: p.trustLevel,
127
- })),
128
- merged: {
129
- surfaces: [...allSurfaces],
130
- proposalFamilies: [...allProposalFamilies],
131
- modules: [...moduleOwner.entries()].map(([mod, owner]) => ({ module: mod, owner: owner.key })),
132
- enabledTools: [...mergedEnabledTools].sort(),
133
- requiredAuth: [...mergedRequiredAuth].sort(),
134
- },
135
- budget: { estimatedSize, limit: sizeBudget, overBudget, utilization: Math.round((estimatedSize / sizeBudget) * 100) },
136
- warnings,
137
- };
138
- }
139
-
140
- function estimateCompositionSize(domainPacks, mcpPacks) {
141
- let size = 0;
142
- for (const pack of domainPacks) {
143
- size += (pack.label || '').length + (pack.useWhen || '').length + (pack.adoption || '').length;
144
- size += JSON.stringify(pack.recommendedModules || []).length;
145
- size += JSON.stringify(pack.benchmarkFocus || []).length;
146
- }
147
- for (const pack of mcpPacks) {
148
- size += (pack.label || '').length + (pack.description || '').length;
149
- size += JSON.stringify(pack.jsoncProjection || {}).length;
150
- size += JSON.stringify(pack.enabledTools || []).length;
151
- }
152
- return size;
153
- }
154
-
155
- // ---------------------------------------------------------------------------
156
- // 2. CI Template Library
157
- // ---------------------------------------------------------------------------
158
-
159
- const CI_TEMPLATES = [
160
- {
161
- key: 'opencode-pr-review',
162
- label: 'OpenCode PR Review',
163
- filename: 'opencode-pr-review.yml',
164
- description: 'Runs OpenCode review on pull request diffs.',
165
- trigger: 'pull_request',
166
- },
167
- {
168
- key: 'opencode-issue-triage',
169
- label: 'OpenCode Issue Triage',
170
- filename: 'opencode-issue-triage.yml',
171
- description: 'Classifies and labels new issues using OpenCode.',
172
- trigger: 'issues.opened',
173
- },
174
- {
175
- key: 'opencode-scheduled-audit',
176
- label: 'OpenCode Scheduled Audit',
177
- filename: 'opencode-scheduled-audit.yml',
178
- description: 'Weekly deep review of the codebase with OpenCode.',
179
- trigger: 'schedule (cron)',
180
- },
181
- {
182
- key: 'opencode-test-gen',
183
- label: 'OpenCode Test Generation',
184
- filename: 'opencode-test-gen.yml',
185
- description: 'Generates test stubs for newly added files.',
186
- trigger: 'pull_request',
187
- },
188
- {
189
- key: 'opencode-docs-sync',
190
- label: 'OpenCode Docs Sync',
191
- filename: 'opencode-docs-sync.yml',
192
- description: 'Checks for documentation staleness.',
193
- trigger: 'schedule (cron)',
194
- },
195
- ];
196
-
197
- const TEMPLATE_CONTENT = {
198
- 'opencode-pr-review': `# OpenCode PR Review — generated by nerviq
199
- name: OpenCode PR Review
200
-
201
- on:
202
- pull_request:
203
- types: [opened, synchronize]
204
-
205
- permissions:
206
- contents: read
207
- pull-requests: write
208
-
209
- env:
210
- OPENCODE_DISABLE_AUTOUPDATE: "1"
211
-
212
- jobs:
213
- opencode-review:
214
- runs-on: ubuntu-latest
215
- timeout-minutes: 15
216
- env:
217
- ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
218
- steps:
219
- - uses: actions/checkout@v4
220
- with:
221
- fetch-depth: 0
222
- - name: Install OpenCode
223
- run: npm install -g opencode
224
- - name: Run Review
225
- run: |
226
- DIFF=$(git diff \${{ github.event.pull_request.base.sha }}..\${{ github.sha }})
227
- echo "$DIFF" | opencode run --format json "Review this diff"
228
- `,
229
-
230
- 'opencode-issue-triage': `# OpenCode Issue Triage — generated by nerviq
231
- name: OpenCode Issue Triage
232
-
233
- on:
234
- issues:
235
- types: [opened]
236
-
237
- permissions:
238
- issues: write
239
-
240
- env:
241
- OPENCODE_DISABLE_AUTOUPDATE: "1"
242
-
243
- jobs:
244
- triage:
245
- runs-on: ubuntu-latest
246
- timeout-minutes: 5
247
- env:
248
- ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
249
- steps:
250
- - uses: actions/checkout@v4
251
- - name: Install OpenCode
252
- run: npm install -g opencode
253
- - name: Classify Issue
254
- run: |
255
- opencode run --format json "Classify this issue: \${{ github.event.issue.title }}"
256
- `,
257
-
258
- 'opencode-scheduled-audit': `# OpenCode Scheduled Audit — generated by nerviq
259
- name: OpenCode Scheduled Audit
260
-
261
- on:
262
- schedule:
263
- - cron: '0 9 * * 1'
264
- workflow_dispatch: {}
265
-
266
- permissions:
267
- contents: read
268
- issues: write
269
-
270
- env:
271
- OPENCODE_DISABLE_AUTOUPDATE: "1"
272
-
273
- jobs:
274
- audit:
275
- runs-on: ubuntu-latest
276
- timeout-minutes: 30
277
- env:
278
- ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
279
- steps:
280
- - uses: actions/checkout@v4
281
- with:
282
- fetch-depth: 0
283
- - name: Install OpenCode
284
- run: npm install -g opencode
285
- - name: Run Audit
286
- run: opencode run --format json "Run a deep code quality audit"
287
- `,
288
-
289
- 'opencode-test-gen': `# OpenCode Test Generation — generated by nerviq
290
- name: OpenCode Test Generation
291
-
292
- on:
293
- pull_request:
294
- types: [opened, synchronize]
295
-
296
- permissions:
297
- contents: read
298
- pull-requests: write
299
-
300
- env:
301
- OPENCODE_DISABLE_AUTOUPDATE: "1"
302
-
303
- jobs:
304
- test-gen:
305
- runs-on: ubuntu-latest
306
- timeout-minutes: 10
307
- env:
308
- ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
309
- steps:
310
- - uses: actions/checkout@v4
311
- with:
312
- fetch-depth: 0
313
- - name: Install OpenCode
314
- run: npm install -g opencode
315
- - name: Generate Tests
316
- run: |
317
- FILES=$(git diff --name-only --diff-filter=A \${{ github.event.pull_request.base.sha }}..\${{ github.sha }})
318
- for file in $FILES; do
319
- opencode run --format json "Generate tests for $file"
320
- done
321
- `,
322
-
323
- 'opencode-docs-sync': `# OpenCode Docs Sync — generated by nerviq
324
- name: OpenCode Docs Sync
325
-
326
- on:
327
- schedule:
328
- - cron: '0 10 * * 3'
329
- workflow_dispatch: {}
330
-
331
- permissions:
332
- contents: read
333
- issues: write
334
-
335
- env:
336
- OPENCODE_DISABLE_AUTOUPDATE: "1"
337
-
338
- jobs:
339
- docs-check:
340
- runs-on: ubuntu-latest
341
- timeout-minutes: 10
342
- env:
343
- ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
344
- steps:
345
- - uses: actions/checkout@v4
346
- with:
347
- fetch-depth: 0
348
- - name: Install OpenCode
349
- run: npm install -g opencode
350
- - name: Check Staleness
351
- run: opencode run --format json "Check documentation freshness for README.md and docs/"
352
- `,
353
- };
354
-
355
- function getCiTemplate(templateKey) {
356
- const meta = CI_TEMPLATES.find(t => t.key === templateKey);
357
- if (!meta) return null;
358
- return TEMPLATE_CONTENT[templateKey] || null;
359
- }
360
-
361
- // ---------------------------------------------------------------------------
362
- // 3. Adoption Signal Gate
363
- // ---------------------------------------------------------------------------
364
-
365
- const GATE_THRESHOLDS = {
366
- 'ci-templates': { metric: 'auditCount', threshold: 3, description: 'Activate CI templates after 3+ audits.' },
367
- 'mcp-advanced': { metric: 'auditCount', threshold: 5, description: 'Activate advanced MCP packs after 5+ audits.' },
368
- 'multi-pack': { metric: 'auditCount', threshold: 2, description: 'Activate multi-pack composition after 2+ audits.' },
369
- 'trend-reports': { metric: 'auditCount', threshold: 3, description: 'Activate trend reports after 3+ snapshots.' },
370
- 'governance-upgrade': { metric: 'averageScore', threshold: 70, description: 'Suggest governance upgrade when average score > 70.' },
371
- };
372
-
373
- function checkAdoptionGate(gateKey, dir) {
374
- const gate = GATE_THRESHOLDS[gateKey];
375
- if (!gate) {
376
- return { activated: false, current: 0, threshold: 0, gate: gateKey, description: `Unknown gate "${gateKey}".` };
377
- }
378
-
379
- const history = getOpenCodeHistory(dir, 100);
380
- let current = 0;
381
-
382
- switch (gate.metric) {
383
- case 'auditCount':
384
- current = history.length;
385
- break;
386
- case 'averageScore': {
387
- const scores = history.map(e => e.summary?.score).filter(s => typeof s === 'number');
388
- current = scores.length > 0 ? Math.round(scores.reduce((a, b) => a + b, 0) / scores.length) : 0;
389
- break;
390
- }
391
- default:
392
- current = 0;
393
- }
394
-
395
- return {
396
- activated: current >= gate.threshold,
397
- current,
398
- threshold: gate.threshold,
399
- gate: gateKey,
400
- description: gate.description,
401
- };
402
- }
403
-
404
- module.exports = {
405
- composePacks,
406
- getCiTemplate,
407
- CI_TEMPLATES,
408
- checkAdoptionGate,
409
- GATE_THRESHOLDS,
410
- PACK_DEPENDENCY_ORDER,
411
- PACK_SPECIFICITY,
412
- DEFAULT_SIZE_BUDGET,
413
- };
1
+ /**
2
+ * OpenCode Premium Operator UX
3
+ *
4
+ * Three subsystems:
5
+ * 1. Multi-Pack Composition Engine — merge domain + MCP packs with dedup, conflict resolution
6
+ * 2. CI Template Library — 5 GitHub Actions workflow templates for OpenCode automation
7
+ * 3. Adoption Signal Gate — activate features based on local usage telemetry
8
+ */
9
+
10
+ const path = require('path');
11
+ const { OPENCODE_DOMAIN_PACKS } = require('./domain-packs');
12
+ const { OPENCODE_MCP_PACKS } = require('./mcp-packs');
13
+ const { getOpenCodeHistory } = 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 OPENCODE_DOMAIN_PACKS.find(p => p.key === key) || null;
41
+ }
42
+
43
+ function lookupMcpPack(key) {
44
+ return OPENCODE_MCP_PACKS.find(p => p.key === key) || null;
45
+ }
46
+
47
+ function composePacks(domainPackKeys = [], mcpPackKeys = [], options = {}) {
48
+ const sizeBudget = options.sizeBudget || DEFAULT_SIZE_BUDGET;
49
+ const warnings = [];
50
+
51
+ // Resolve domain packs
52
+ const seenDomainKeys = new Set();
53
+ const rawDomainPacks = [];
54
+ for (const key of domainPackKeys) {
55
+ if (seenDomainKeys.has(key)) continue;
56
+ seenDomainKeys.add(key);
57
+ const pack = lookupDomainPack(key);
58
+ if (!pack) { warnings.push(`Domain pack "${key}" not found, skipped.`); continue; }
59
+ rawDomainPacks.push(pack);
60
+ }
61
+
62
+ rawDomainPacks.sort((a, b) => {
63
+ const orderA = PACK_DEPENDENCY_ORDER.indexOf(a.key);
64
+ const orderB = PACK_DEPENDENCY_ORDER.indexOf(b.key);
65
+ return (orderA === -1 ? 99 : orderA) - (orderB === -1 ? 99 : orderB);
66
+ });
67
+
68
+ const moduleOwner = new Map();
69
+ for (const pack of rawDomainPacks) {
70
+ const specificity = PACK_SPECIFICITY[pack.key] ?? 1;
71
+ for (const mod of pack.recommendedModules || []) {
72
+ const existing = moduleOwner.get(mod);
73
+ if (!existing || specificity > existing.specificity) {
74
+ moduleOwner.set(mod, { key: pack.key, specificity });
75
+ }
76
+ }
77
+ }
78
+
79
+ const allSurfaces = new Set();
80
+ for (const pack of rawDomainPacks) {
81
+ for (const surface of pack.recommendedSurfaces || []) allSurfaces.add(surface);
82
+ }
83
+
84
+ const allProposalFamilies = new Set();
85
+ for (const pack of rawDomainPacks) {
86
+ for (const family of pack.recommendedProposalFamilies || []) allProposalFamilies.add(family);
87
+ }
88
+
89
+ // Resolve MCP packs
90
+ const seenMcpKeys = new Set();
91
+ const resolvedMcpPacks = [];
92
+ for (const key of mcpPackKeys) {
93
+ if (seenMcpKeys.has(key)) continue;
94
+ seenMcpKeys.add(key);
95
+ const pack = lookupMcpPack(key);
96
+ if (!pack) { warnings.push(`MCP pack "${key}" not found, skipped.`); continue; }
97
+ resolvedMcpPacks.push(pack);
98
+ }
99
+
100
+ const mergedEnabledTools = new Set();
101
+ for (const pack of resolvedMcpPacks) {
102
+ for (const tool of pack.enabledTools || []) mergedEnabledTools.add(tool);
103
+ }
104
+
105
+ const mergedRequiredAuth = new Set();
106
+ for (const pack of resolvedMcpPacks) {
107
+ for (const auth of pack.requiredAuth || []) mergedRequiredAuth.add(auth);
108
+ }
109
+
110
+ const estimatedSize = estimateCompositionSize(rawDomainPacks, resolvedMcpPacks);
111
+ const overBudget = estimatedSize > sizeBudget;
112
+ if (overBudget) {
113
+ warnings.push(`Combined size (~${estimatedSize} chars) exceeds budget (${sizeBudget}). Consider removing lower-priority packs.`);
114
+ }
115
+
116
+ return {
117
+ domainPacks: rawDomainPacks.map(p => ({
118
+ key: p.key,
119
+ label: p.label,
120
+ modulesOwned: [...moduleOwner.entries()].filter(([, owner]) => owner.key === p.key).map(([mod]) => mod),
121
+ })),
122
+ mcpPacks: resolvedMcpPacks.map(p => ({
123
+ key: p.key,
124
+ label: p.label,
125
+ serverName: p.serverName,
126
+ trustLevel: p.trustLevel,
127
+ })),
128
+ merged: {
129
+ surfaces: [...allSurfaces],
130
+ proposalFamilies: [...allProposalFamilies],
131
+ modules: [...moduleOwner.entries()].map(([mod, owner]) => ({ module: mod, owner: owner.key })),
132
+ enabledTools: [...mergedEnabledTools].sort(),
133
+ requiredAuth: [...mergedRequiredAuth].sort(),
134
+ },
135
+ budget: { estimatedSize, limit: sizeBudget, overBudget, utilization: Math.round((estimatedSize / sizeBudget) * 100) },
136
+ warnings,
137
+ };
138
+ }
139
+
140
+ function estimateCompositionSize(domainPacks, mcpPacks) {
141
+ let size = 0;
142
+ for (const pack of domainPacks) {
143
+ size += (pack.label || '').length + (pack.useWhen || '').length + (pack.adoption || '').length;
144
+ size += JSON.stringify(pack.recommendedModules || []).length;
145
+ size += JSON.stringify(pack.benchmarkFocus || []).length;
146
+ }
147
+ for (const pack of mcpPacks) {
148
+ size += (pack.label || '').length + (pack.description || '').length;
149
+ size += JSON.stringify(pack.jsoncProjection || {}).length;
150
+ size += JSON.stringify(pack.enabledTools || []).length;
151
+ }
152
+ return size;
153
+ }
154
+
155
+ // ---------------------------------------------------------------------------
156
+ // 2. CI Template Library
157
+ // ---------------------------------------------------------------------------
158
+
159
+ const CI_TEMPLATES = [
160
+ {
161
+ key: 'opencode-pr-review',
162
+ label: 'OpenCode PR Review',
163
+ filename: 'opencode-pr-review.yml',
164
+ description: 'Runs OpenCode review on pull request diffs.',
165
+ trigger: 'pull_request',
166
+ },
167
+ {
168
+ key: 'opencode-issue-triage',
169
+ label: 'OpenCode Issue Triage',
170
+ filename: 'opencode-issue-triage.yml',
171
+ description: 'Classifies and labels new issues using OpenCode.',
172
+ trigger: 'issues.opened',
173
+ },
174
+ {
175
+ key: 'opencode-scheduled-audit',
176
+ label: 'OpenCode Scheduled Audit',
177
+ filename: 'opencode-scheduled-audit.yml',
178
+ description: 'Weekly deep review of the codebase with OpenCode.',
179
+ trigger: 'schedule (cron)',
180
+ },
181
+ {
182
+ key: 'opencode-test-gen',
183
+ label: 'OpenCode Test Generation',
184
+ filename: 'opencode-test-gen.yml',
185
+ description: 'Generates test stubs for newly added files.',
186
+ trigger: 'pull_request',
187
+ },
188
+ {
189
+ key: 'opencode-docs-sync',
190
+ label: 'OpenCode Docs Sync',
191
+ filename: 'opencode-docs-sync.yml',
192
+ description: 'Checks for documentation staleness.',
193
+ trigger: 'schedule (cron)',
194
+ },
195
+ ];
196
+
197
+ const TEMPLATE_CONTENT = {
198
+ 'opencode-pr-review': `# OpenCode PR Review — generated by nerviq
199
+ name: OpenCode PR Review
200
+
201
+ on:
202
+ pull_request:
203
+ types: [opened, synchronize]
204
+
205
+ permissions:
206
+ contents: read
207
+ pull-requests: write
208
+
209
+ env:
210
+ OPENCODE_DISABLE_AUTOUPDATE: "1"
211
+
212
+ jobs:
213
+ opencode-review:
214
+ runs-on: ubuntu-latest
215
+ timeout-minutes: 15
216
+ env:
217
+ ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
218
+ steps:
219
+ - uses: actions/checkout@v4
220
+ with:
221
+ fetch-depth: 0
222
+ - name: Install OpenCode
223
+ run: npm install -g opencode
224
+ - name: Run Review
225
+ run: |
226
+ DIFF=$(git diff \${{ github.event.pull_request.base.sha }}..\${{ github.sha }})
227
+ echo "$DIFF" | opencode run --format json "Review this diff"
228
+ `,
229
+
230
+ 'opencode-issue-triage': `# OpenCode Issue Triage — generated by nerviq
231
+ name: OpenCode Issue Triage
232
+
233
+ on:
234
+ issues:
235
+ types: [opened]
236
+
237
+ permissions:
238
+ issues: write
239
+
240
+ env:
241
+ OPENCODE_DISABLE_AUTOUPDATE: "1"
242
+
243
+ jobs:
244
+ triage:
245
+ runs-on: ubuntu-latest
246
+ timeout-minutes: 5
247
+ env:
248
+ ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
249
+ steps:
250
+ - uses: actions/checkout@v4
251
+ - name: Install OpenCode
252
+ run: npm install -g opencode
253
+ - name: Classify Issue
254
+ run: |
255
+ opencode run --format json "Classify this issue: \${{ github.event.issue.title }}"
256
+ `,
257
+
258
+ 'opencode-scheduled-audit': `# OpenCode Scheduled Audit — generated by nerviq
259
+ name: OpenCode Scheduled Audit
260
+
261
+ on:
262
+ schedule:
263
+ - cron: '0 9 * * 1'
264
+ workflow_dispatch: {}
265
+
266
+ permissions:
267
+ contents: read
268
+ issues: write
269
+
270
+ env:
271
+ OPENCODE_DISABLE_AUTOUPDATE: "1"
272
+
273
+ jobs:
274
+ audit:
275
+ runs-on: ubuntu-latest
276
+ timeout-minutes: 30
277
+ env:
278
+ ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
279
+ steps:
280
+ - uses: actions/checkout@v4
281
+ with:
282
+ fetch-depth: 0
283
+ - name: Install OpenCode
284
+ run: npm install -g opencode
285
+ - name: Run Audit
286
+ run: opencode run --format json "Run a deep code quality audit"
287
+ `,
288
+
289
+ 'opencode-test-gen': `# OpenCode Test Generation — generated by nerviq
290
+ name: OpenCode Test Generation
291
+
292
+ on:
293
+ pull_request:
294
+ types: [opened, synchronize]
295
+
296
+ permissions:
297
+ contents: read
298
+ pull-requests: write
299
+
300
+ env:
301
+ OPENCODE_DISABLE_AUTOUPDATE: "1"
302
+
303
+ jobs:
304
+ test-gen:
305
+ runs-on: ubuntu-latest
306
+ timeout-minutes: 10
307
+ env:
308
+ ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
309
+ steps:
310
+ - uses: actions/checkout@v4
311
+ with:
312
+ fetch-depth: 0
313
+ - name: Install OpenCode
314
+ run: npm install -g opencode
315
+ - name: Generate Tests
316
+ run: |
317
+ FILES=$(git diff --name-only --diff-filter=A \${{ github.event.pull_request.base.sha }}..\${{ github.sha }})
318
+ for file in $FILES; do
319
+ opencode run --format json "Generate tests for $file"
320
+ done
321
+ `,
322
+
323
+ 'opencode-docs-sync': `# OpenCode Docs Sync — generated by nerviq
324
+ name: OpenCode Docs Sync
325
+
326
+ on:
327
+ schedule:
328
+ - cron: '0 10 * * 3'
329
+ workflow_dispatch: {}
330
+
331
+ permissions:
332
+ contents: read
333
+ issues: write
334
+
335
+ env:
336
+ OPENCODE_DISABLE_AUTOUPDATE: "1"
337
+
338
+ jobs:
339
+ docs-check:
340
+ runs-on: ubuntu-latest
341
+ timeout-minutes: 10
342
+ env:
343
+ ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
344
+ steps:
345
+ - uses: actions/checkout@v4
346
+ with:
347
+ fetch-depth: 0
348
+ - name: Install OpenCode
349
+ run: npm install -g opencode
350
+ - name: Check Staleness
351
+ run: opencode run --format json "Check documentation freshness for README.md and docs/"
352
+ `,
353
+ };
354
+
355
+ function getCiTemplate(templateKey) {
356
+ const meta = CI_TEMPLATES.find(t => t.key === templateKey);
357
+ if (!meta) return null;
358
+ return TEMPLATE_CONTENT[templateKey] || null;
359
+ }
360
+
361
+ // ---------------------------------------------------------------------------
362
+ // 3. Adoption Signal Gate
363
+ // ---------------------------------------------------------------------------
364
+
365
+ const GATE_THRESHOLDS = {
366
+ 'ci-templates': { metric: 'auditCount', threshold: 3, description: 'Activate CI templates after 3+ audits.' },
367
+ 'mcp-advanced': { metric: 'auditCount', threshold: 5, description: 'Activate advanced MCP packs after 5+ audits.' },
368
+ 'multi-pack': { metric: 'auditCount', threshold: 2, description: 'Activate multi-pack composition after 2+ audits.' },
369
+ 'trend-reports': { metric: 'auditCount', threshold: 3, description: 'Activate trend reports after 3+ snapshots.' },
370
+ 'governance-upgrade': { metric: 'averageScore', threshold: 70, description: 'Suggest governance upgrade when average score > 70.' },
371
+ };
372
+
373
+ function checkAdoptionGate(gateKey, dir) {
374
+ const gate = GATE_THRESHOLDS[gateKey];
375
+ if (!gate) {
376
+ return { activated: false, current: 0, threshold: 0, gate: gateKey, description: `Unknown gate "${gateKey}".` };
377
+ }
378
+
379
+ const history = getOpenCodeHistory(dir, 100);
380
+ let current = 0;
381
+
382
+ switch (gate.metric) {
383
+ case 'auditCount':
384
+ current = history.length;
385
+ break;
386
+ case 'averageScore': {
387
+ const scores = history.map(e => e.summary?.score).filter(s => typeof s === 'number');
388
+ current = scores.length > 0 ? Math.round(scores.reduce((a, b) => a + b, 0) / scores.length) : 0;
389
+ break;
390
+ }
391
+ default:
392
+ current = 0;
393
+ }
394
+
395
+ return {
396
+ activated: current >= gate.threshold,
397
+ current,
398
+ threshold: gate.threshold,
399
+ gate: gateKey,
400
+ description: gate.description,
401
+ };
402
+ }
403
+
404
+ module.exports = {
405
+ composePacks,
406
+ getCiTemplate,
407
+ CI_TEMPLATES,
408
+ checkAdoptionGate,
409
+ GATE_THRESHOLDS,
410
+ PACK_DEPENDENCY_ORDER,
411
+ PACK_SPECIFICITY,
412
+ DEFAULT_SIZE_BUDGET,
413
+ };