@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,468 +1,468 @@
1
- /**
2
- * Windsurf 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 Windsurf
7
- * 3. Adoption Signal Gate — activate features based on local usage telemetry (5 gates)
8
- */
9
-
10
- const path = require('path');
11
- const { WINDSURF_DOMAIN_PACKS } = require('./domain-packs');
12
- const { WINDSURF_MCP_PACKS } = require('./mcp-packs');
13
- const { resolveProjectStateReadPath } = require('../state-paths');
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 = 10000; // Windsurf 10K char limit per rule
38
-
39
- function lookupDomainPack(key) {
40
- return WINDSURF_DOMAIN_PACKS.find(p => p.key === key) || null;
41
- }
42
-
43
- function lookupMcpPack(key) {
44
- return WINDSURF_MCP_PACKS.find(p => p.key === key) || null;
45
- }
46
-
47
- /**
48
- * Compose domain packs and MCP packs into a unified, deduplicated, ordered result.
49
- * Windsurf-specific: tracks 10K char limit and rule type distribution.
50
- */
51
- function composePacks(domainPackKeys = [], mcpPackKeys = [], options = {}) {
52
- const sizeBudget = options.sizeBudget || DEFAULT_SIZE_BUDGET;
53
- const warnings = [];
54
-
55
- // --- Resolve domain packs ---
56
- const seenDomainKeys = new Set();
57
- const rawDomainPacks = [];
58
- for (const key of domainPackKeys) {
59
- if (seenDomainKeys.has(key)) continue;
60
- seenDomainKeys.add(key);
61
- const pack = lookupDomainPack(key);
62
- if (!pack) { warnings.push(`Domain pack "${key}" not found, skipped.`); continue; }
63
- rawDomainPacks.push(pack);
64
- }
65
-
66
- rawDomainPacks.sort((a, b) => {
67
- const orderA = PACK_DEPENDENCY_ORDER.indexOf(a.key);
68
- const orderB = PACK_DEPENDENCY_ORDER.indexOf(b.key);
69
- return (orderA === -1 ? 99 : orderA) - (orderB === -1 ? 99 : orderB);
70
- });
71
-
72
- const moduleOwner = new Map();
73
- for (const pack of rawDomainPacks) {
74
- const specificity = PACK_SPECIFICITY[pack.key] ?? 1;
75
- for (const mod of pack.recommendedModules || []) {
76
- const existing = moduleOwner.get(mod);
77
- if (!existing || specificity > existing.specificity) {
78
- moduleOwner.set(mod, { key: pack.key, specificity });
79
- }
80
- }
81
- }
82
-
83
- const allSurfaces = new Set();
84
- for (const pack of rawDomainPacks) {
85
- for (const surface of pack.recommendedSurfaces || []) allSurfaces.add(surface);
86
- }
87
-
88
- const allProposalFamilies = new Set();
89
- for (const pack of rawDomainPacks) {
90
- for (const family of pack.recommendedProposalFamilies || []) allProposalFamilies.add(family);
91
- }
92
-
93
- // --- Resolve MCP packs ---
94
- const seenMcpKeys = new Set();
95
- const resolvedMcpPacks = [];
96
- for (const key of mcpPackKeys) {
97
- if (seenMcpKeys.has(key)) continue;
98
- seenMcpKeys.add(key);
99
- const pack = lookupMcpPack(key);
100
- if (!pack) { warnings.push(`MCP pack "${key}" not found, skipped.`); continue; }
101
- resolvedMcpPacks.push(pack);
102
- }
103
-
104
- const mergedExcludeTools = new Set();
105
- for (const pack of resolvedMcpPacks) {
106
- for (const tool of pack.excludeTools || []) mergedExcludeTools.add(tool);
107
- }
108
-
109
- const mergedRequiredAuth = new Set();
110
- for (const pack of resolvedMcpPacks) {
111
- for (const auth of pack.requiredAuth || []) mergedRequiredAuth.add(auth);
112
- }
113
-
114
- const estimatedSize = estimateCompositionSize(rawDomainPacks, resolvedMcpPacks);
115
- const overBudget = estimatedSize > sizeBudget;
116
- if (overBudget) {
117
- warnings.push(`Combined instruction size (~${estimatedSize} chars) exceeds Windsurf 10K char budget (${sizeBudget}).`);
118
- }
119
-
120
- // Windsurf-specific: recommend rule type distribution
121
- const ruleGuidance = {
122
- alwaysCount: 1, // Core rules only
123
- autoCount: rawDomainPacks.length > 1 ? rawDomainPacks.length : 1,
124
- agentRequestedCount: rawDomainPacks.some(p => p.key === 'enterprise-governed') ? 2 : 0,
125
- recommendation: 'Keep trigger: always to 1-2 rules. Use trigger: auto for stack-specific rules. Agent-Requested for optional guides.',
126
- charLimitNote: 'Each rule file must be under 10,000 characters.',
127
- };
128
-
129
- return {
130
- domainPacks: rawDomainPacks.map(p => ({
131
- key: p.key,
132
- label: p.label,
133
- modulesOwned: [...moduleOwner.entries()].filter(([, owner]) => owner.key === p.key).map(([mod]) => mod),
134
- })),
135
- mcpPacks: resolvedMcpPacks.map(p => ({
136
- key: p.key,
137
- label: p.label,
138
- serverName: p.serverName,
139
- trustLevel: p.trustLevel,
140
- })),
141
- merged: {
142
- surfaces: [...allSurfaces],
143
- proposalFamilies: [...allProposalFamilies],
144
- modules: [...moduleOwner.entries()].map(([mod, owner]) => ({ module: mod, owner: owner.key })),
145
- excludeTools: [...mergedExcludeTools].sort(),
146
- requiredAuth: [...mergedRequiredAuth].sort(),
147
- },
148
- budget: {
149
- estimatedSize,
150
- limit: sizeBudget,
151
- overBudget,
152
- utilization: Math.round((estimatedSize / sizeBudget) * 100),
153
- },
154
- ruleGuidance,
155
- warnings,
156
- };
157
- }
158
-
159
- function estimateCompositionSize(domainPacks, mcpPacks) {
160
- let size = 0;
161
- for (const pack of domainPacks) {
162
- size += (pack.label || '').length + (pack.useWhen || '').length + (pack.adoption || '').length;
163
- size += JSON.stringify(pack.recommendedModules || []).length;
164
- size += JSON.stringify(pack.benchmarkFocus || []).length;
165
- }
166
- for (const pack of mcpPacks) {
167
- size += (pack.label || '').length + (pack.description || '').length;
168
- size += JSON.stringify(pack.jsonProjection || {}).length;
169
- size += JSON.stringify(pack.excludeTools || []).length;
170
- }
171
- return size;
172
- }
173
-
174
- // ---------------------------------------------------------------------------
175
- // 2. CI Template Library (5 templates)
176
- // ---------------------------------------------------------------------------
177
-
178
- const CI_TEMPLATES = [
179
- {
180
- key: 'windsurf-pr-audit',
181
- label: 'Windsurf PR Audit',
182
- filename: 'windsurf-pr-audit.yml',
183
- description: 'Runs nerviq audit on pull request diffs.',
184
- trigger: 'pull_request',
185
- },
186
- {
187
- key: 'windsurf-cascade-review',
188
- label: 'Windsurf Cascade Review',
189
- filename: 'windsurf-cascade-review.yml',
190
- description: 'Validates Cascade configuration on pull requests.',
191
- trigger: 'pull_request',
192
- },
193
- {
194
- key: 'windsurf-scheduled-audit',
195
- label: 'Windsurf Scheduled Audit',
196
- filename: 'windsurf-scheduled-audit.yml',
197
- description: 'Weekly Windsurf audit of configuration health.',
198
- trigger: 'schedule (cron)',
199
- },
200
- {
201
- key: 'windsurf-rules-lint',
202
- label: 'Windsurf Rules Lint',
203
- filename: 'windsurf-rules-lint.yml',
204
- description: 'Validates YAML frontmatter in .windsurf/rules/ on change.',
205
- trigger: 'push (path filter)',
206
- },
207
- {
208
- key: 'windsurf-mcp-security',
209
- label: 'Windsurf MCP Security Check',
210
- filename: 'windsurf-mcp-security.yml',
211
- description: 'Checks MCP config for hardcoded secrets.',
212
- trigger: 'push (path filter)',
213
- },
214
- ];
215
-
216
- const TEMPLATE_CONTENT = {
217
- 'windsurf-pr-audit': `# Windsurf PR Audit — generated by nerviq
218
- name: Windsurf PR Audit
219
-
220
- on:
221
- pull_request:
222
- types: [opened, synchronize]
223
-
224
- permissions:
225
- contents: read
226
- pull-requests: write
227
-
228
- jobs:
229
- windsurf-audit:
230
- runs-on: ubuntu-latest
231
- timeout-minutes: 15
232
- steps:
233
- - uses: actions/checkout@v4
234
- - name: Run nerviq Windsurf audit
235
- run: npx nerviq --platform windsurf --json > audit-report.json
236
- - uses: actions/upload-artifact@v4
237
- with:
238
- name: windsurf-audit-report
239
- path: audit-report.json
240
- retention-days: 30
241
- `,
242
-
243
- 'windsurf-cascade-review': `# Windsurf Cascade Review — generated by nerviq
244
- name: Windsurf Cascade Review
245
-
246
- on:
247
- pull_request:
248
- types: [opened, synchronize]
249
-
250
- permissions:
251
- contents: read
252
-
253
- jobs:
254
- cascade-check:
255
- runs-on: ubuntu-latest
256
- steps:
257
- - uses: actions/checkout@v4
258
- - name: Verify Windsurf Configuration
259
- run: |
260
- echo "Checking Windsurf configuration..."
261
- if [ -f .windsurfrules ]; then
262
- echo "WARNING: .windsurfrules is legacy format. Migrate to .windsurf/rules/*.md"
263
- fi
264
- for file in .windsurf/rules/*.md; do
265
- [ ! -f "$file" ] && continue
266
- CHARS=$(wc -c < "$file")
267
- if [ "$CHARS" -gt 10000 ]; then
268
- echo "ERROR: $file exceeds 10K char limit ($CHARS chars)"
269
- exit 1
270
- fi
271
- done
272
- echo "Windsurf configuration check passed."
273
- `,
274
-
275
- 'windsurf-scheduled-audit': `# Windsurf Scheduled Audit — generated by nerviq
276
- name: Windsurf Scheduled Audit
277
-
278
- on:
279
- schedule:
280
- - cron: '0 9 * * 1'
281
- workflow_dispatch:
282
-
283
- permissions:
284
- contents: read
285
- issues: write
286
-
287
- jobs:
288
- audit:
289
- runs-on: ubuntu-latest
290
- timeout-minutes: 30
291
- steps:
292
- - uses: actions/checkout@v4
293
- - name: Run nerviq audit
294
- run: npx nerviq --platform windsurf --json > audit-report.json
295
- - uses: actions/upload-artifact@v4
296
- with:
297
- name: windsurf-audit-report
298
- path: audit-report.json
299
- retention-days: 30
300
- `,
301
-
302
- 'windsurf-rules-lint': `# Windsurf Rules Lint — generated by nerviq
303
- name: Windsurf Rules Lint
304
-
305
- on:
306
- push:
307
- paths:
308
- - '.windsurf/rules/**'
309
- - '.windsurfrules'
310
-
311
- permissions:
312
- contents: read
313
-
314
- jobs:
315
- lint-rules:
316
- runs-on: ubuntu-latest
317
- steps:
318
- - uses: actions/checkout@v4
319
- - name: Check YAML frontmatter and char limits
320
- run: |
321
- ERRORS=0
322
- for file in .windsurf/rules/*.md; do
323
- [ ! -f "$file" ] && continue
324
- if ! head -1 "$file" | grep -q "^---"; then
325
- echo "ERROR: $file missing YAML frontmatter (---)"
326
- ERRORS=$((ERRORS + 1))
327
- fi
328
- CHARS=$(wc -c < "$file")
329
- if [ "$CHARS" -gt 10000 ]; then
330
- echo "ERROR: $file exceeds 10K char limit ($CHARS chars)"
331
- ERRORS=$((ERRORS + 1))
332
- fi
333
- done
334
- if [ -f .windsurfrules ]; then
335
- echo "WARNING: .windsurfrules exists — this is the legacy format!"
336
- echo "Migrate to .windsurf/rules/*.md with proper YAML frontmatter."
337
- fi
338
- exit $ERRORS
339
- `,
340
-
341
- 'windsurf-mcp-security': `# Windsurf MCP Security Check — generated by nerviq
342
- name: Windsurf MCP Security Check
343
-
344
- on:
345
- push:
346
- paths:
347
- - '.windsurf/mcp.json'
348
-
349
- permissions:
350
- contents: read
351
-
352
- jobs:
353
- mcp-check:
354
- runs-on: ubuntu-latest
355
- steps:
356
- - uses: actions/checkout@v4
357
- - name: Check for hardcoded secrets
358
- run: |
359
- if [ ! -f .windsurf/mcp.json ]; then exit 0; fi
360
- if grep -P '"(key|token|secret|password|api)"\\s*:\\s*"(?!\\$\\{env:)' .windsurf/mcp.json; then
361
- echo "ERROR: Hardcoded secrets detected in .windsurf/mcp.json"
362
- echo "Use environment variables instead."
363
- exit 1
364
- fi
365
- echo "MCP config security check passed."
366
- `,
367
- };
368
-
369
- function getCiTemplate(templateKey) {
370
- const meta = CI_TEMPLATES.find(t => t.key === templateKey);
371
- if (!meta) return null;
372
- return TEMPLATE_CONTENT[templateKey] || null;
373
- }
374
-
375
- // ---------------------------------------------------------------------------
376
- // 3. Adoption Signal Gate (5 gates)
377
- // ---------------------------------------------------------------------------
378
-
379
- const GATE_THRESHOLDS = {
380
- 'ci-templates': {
381
- metric: 'auditCount',
382
- threshold: 3,
383
- description: 'Activate CI templates after 3+ successful audits.',
384
- },
385
- 'team-sync': {
386
- metric: 'auditCount',
387
- threshold: 2,
388
- description: 'Activate team sync features after 2+ audits.',
389
- },
390
- 'multi-pack': {
391
- metric: 'auditCount',
392
- threshold: 2,
393
- description: 'Activate multi-pack composition after 2+ audits.',
394
- },
395
- 'workflows': {
396
- metric: 'auditCount',
397
- threshold: 3,
398
- description: 'Activate workflow templates after 3+ audits.',
399
- },
400
- 'governance-upgrade': {
401
- metric: 'averageScore',
402
- threshold: 70,
403
- description: 'Suggest governance upgrade when average score exceeds 70.',
404
- },
405
- };
406
-
407
- function getWindsurfHistory(dir, limit = 20) {
408
- const fs = require('fs');
409
- const snapshotDir = resolveProjectStateReadPath(dir, 'snapshots');
410
- try {
411
- const files = fs.readdirSync(snapshotDir)
412
- .filter(f => f.endsWith('.json'))
413
- .sort()
414
- .slice(-limit);
415
-
416
- return files.map(f => {
417
- try {
418
- const data = JSON.parse(fs.readFileSync(path.join(snapshotDir, f), 'utf8'));
419
- if (data.platform === 'windsurf' || data.summary?.platform === 'windsurf') return data;
420
- return null;
421
- } catch { return null; }
422
- }).filter(Boolean);
423
- } catch {
424
- return [];
425
- }
426
- }
427
-
428
- function checkAdoptionGate(gateKey, dir) {
429
- const gate = GATE_THRESHOLDS[gateKey];
430
- if (!gate) {
431
- return { activated: false, current: 0, threshold: 0, gate: gateKey, description: `Unknown gate "${gateKey}".` };
432
- }
433
-
434
- const history = getWindsurfHistory(dir, 100);
435
- let current = 0;
436
-
437
- switch (gate.metric) {
438
- case 'auditCount':
439
- current = history.length;
440
- break;
441
- case 'averageScore': {
442
- const scores = history.map(e => e.summary?.score).filter(s => typeof s === 'number');
443
- current = scores.length > 0 ? Math.round(scores.reduce((a, b) => a + b, 0) / scores.length) : 0;
444
- break;
445
- }
446
- default:
447
- current = 0;
448
- }
449
-
450
- return {
451
- activated: current >= gate.threshold,
452
- current,
453
- threshold: gate.threshold,
454
- gate: gateKey,
455
- description: gate.description,
456
- };
457
- }
458
-
459
- module.exports = {
460
- composePacks,
461
- getCiTemplate,
462
- CI_TEMPLATES,
463
- checkAdoptionGate,
464
- GATE_THRESHOLDS,
465
- PACK_DEPENDENCY_ORDER,
466
- PACK_SPECIFICITY,
467
- DEFAULT_SIZE_BUDGET,
468
- };
1
+ /**
2
+ * Windsurf 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 Windsurf
7
+ * 3. Adoption Signal Gate — activate features based on local usage telemetry (5 gates)
8
+ */
9
+
10
+ const path = require('path');
11
+ const { WINDSURF_DOMAIN_PACKS } = require('./domain-packs');
12
+ const { WINDSURF_MCP_PACKS } = require('./mcp-packs');
13
+ const { resolveProjectStateReadPath } = require('../state-paths');
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 = 10000; // Windsurf 10K char limit per rule
38
+
39
+ function lookupDomainPack(key) {
40
+ return WINDSURF_DOMAIN_PACKS.find(p => p.key === key) || null;
41
+ }
42
+
43
+ function lookupMcpPack(key) {
44
+ return WINDSURF_MCP_PACKS.find(p => p.key === key) || null;
45
+ }
46
+
47
+ /**
48
+ * Compose domain packs and MCP packs into a unified, deduplicated, ordered result.
49
+ * Windsurf-specific: tracks 10K char limit and rule type distribution.
50
+ */
51
+ function composePacks(domainPackKeys = [], mcpPackKeys = [], options = {}) {
52
+ const sizeBudget = options.sizeBudget || DEFAULT_SIZE_BUDGET;
53
+ const warnings = [];
54
+
55
+ // --- Resolve domain packs ---
56
+ const seenDomainKeys = new Set();
57
+ const rawDomainPacks = [];
58
+ for (const key of domainPackKeys) {
59
+ if (seenDomainKeys.has(key)) continue;
60
+ seenDomainKeys.add(key);
61
+ const pack = lookupDomainPack(key);
62
+ if (!pack) { warnings.push(`Domain pack "${key}" not found, skipped.`); continue; }
63
+ rawDomainPacks.push(pack);
64
+ }
65
+
66
+ rawDomainPacks.sort((a, b) => {
67
+ const orderA = PACK_DEPENDENCY_ORDER.indexOf(a.key);
68
+ const orderB = PACK_DEPENDENCY_ORDER.indexOf(b.key);
69
+ return (orderA === -1 ? 99 : orderA) - (orderB === -1 ? 99 : orderB);
70
+ });
71
+
72
+ const moduleOwner = new Map();
73
+ for (const pack of rawDomainPacks) {
74
+ const specificity = PACK_SPECIFICITY[pack.key] ?? 1;
75
+ for (const mod of pack.recommendedModules || []) {
76
+ const existing = moduleOwner.get(mod);
77
+ if (!existing || specificity > existing.specificity) {
78
+ moduleOwner.set(mod, { key: pack.key, specificity });
79
+ }
80
+ }
81
+ }
82
+
83
+ const allSurfaces = new Set();
84
+ for (const pack of rawDomainPacks) {
85
+ for (const surface of pack.recommendedSurfaces || []) allSurfaces.add(surface);
86
+ }
87
+
88
+ const allProposalFamilies = new Set();
89
+ for (const pack of rawDomainPacks) {
90
+ for (const family of pack.recommendedProposalFamilies || []) allProposalFamilies.add(family);
91
+ }
92
+
93
+ // --- Resolve MCP packs ---
94
+ const seenMcpKeys = new Set();
95
+ const resolvedMcpPacks = [];
96
+ for (const key of mcpPackKeys) {
97
+ if (seenMcpKeys.has(key)) continue;
98
+ seenMcpKeys.add(key);
99
+ const pack = lookupMcpPack(key);
100
+ if (!pack) { warnings.push(`MCP pack "${key}" not found, skipped.`); continue; }
101
+ resolvedMcpPacks.push(pack);
102
+ }
103
+
104
+ const mergedExcludeTools = new Set();
105
+ for (const pack of resolvedMcpPacks) {
106
+ for (const tool of pack.excludeTools || []) mergedExcludeTools.add(tool);
107
+ }
108
+
109
+ const mergedRequiredAuth = new Set();
110
+ for (const pack of resolvedMcpPacks) {
111
+ for (const auth of pack.requiredAuth || []) mergedRequiredAuth.add(auth);
112
+ }
113
+
114
+ const estimatedSize = estimateCompositionSize(rawDomainPacks, resolvedMcpPacks);
115
+ const overBudget = estimatedSize > sizeBudget;
116
+ if (overBudget) {
117
+ warnings.push(`Combined instruction size (~${estimatedSize} chars) exceeds Windsurf 10K char budget (${sizeBudget}).`);
118
+ }
119
+
120
+ // Windsurf-specific: recommend rule type distribution
121
+ const ruleGuidance = {
122
+ alwaysCount: 1, // Core rules only
123
+ autoCount: rawDomainPacks.length > 1 ? rawDomainPacks.length : 1,
124
+ agentRequestedCount: rawDomainPacks.some(p => p.key === 'enterprise-governed') ? 2 : 0,
125
+ recommendation: 'Keep trigger: always to 1-2 rules. Use trigger: auto for stack-specific rules. Agent-Requested for optional guides.',
126
+ charLimitNote: 'Each rule file must be under 10,000 characters.',
127
+ };
128
+
129
+ return {
130
+ domainPacks: rawDomainPacks.map(p => ({
131
+ key: p.key,
132
+ label: p.label,
133
+ modulesOwned: [...moduleOwner.entries()].filter(([, owner]) => owner.key === p.key).map(([mod]) => mod),
134
+ })),
135
+ mcpPacks: resolvedMcpPacks.map(p => ({
136
+ key: p.key,
137
+ label: p.label,
138
+ serverName: p.serverName,
139
+ trustLevel: p.trustLevel,
140
+ })),
141
+ merged: {
142
+ surfaces: [...allSurfaces],
143
+ proposalFamilies: [...allProposalFamilies],
144
+ modules: [...moduleOwner.entries()].map(([mod, owner]) => ({ module: mod, owner: owner.key })),
145
+ excludeTools: [...mergedExcludeTools].sort(),
146
+ requiredAuth: [...mergedRequiredAuth].sort(),
147
+ },
148
+ budget: {
149
+ estimatedSize,
150
+ limit: sizeBudget,
151
+ overBudget,
152
+ utilization: Math.round((estimatedSize / sizeBudget) * 100),
153
+ },
154
+ ruleGuidance,
155
+ warnings,
156
+ };
157
+ }
158
+
159
+ function estimateCompositionSize(domainPacks, mcpPacks) {
160
+ let size = 0;
161
+ for (const pack of domainPacks) {
162
+ size += (pack.label || '').length + (pack.useWhen || '').length + (pack.adoption || '').length;
163
+ size += JSON.stringify(pack.recommendedModules || []).length;
164
+ size += JSON.stringify(pack.benchmarkFocus || []).length;
165
+ }
166
+ for (const pack of mcpPacks) {
167
+ size += (pack.label || '').length + (pack.description || '').length;
168
+ size += JSON.stringify(pack.jsonProjection || {}).length;
169
+ size += JSON.stringify(pack.excludeTools || []).length;
170
+ }
171
+ return size;
172
+ }
173
+
174
+ // ---------------------------------------------------------------------------
175
+ // 2. CI Template Library (5 templates)
176
+ // ---------------------------------------------------------------------------
177
+
178
+ const CI_TEMPLATES = [
179
+ {
180
+ key: 'windsurf-pr-audit',
181
+ label: 'Windsurf PR Audit',
182
+ filename: 'windsurf-pr-audit.yml',
183
+ description: 'Runs nerviq audit on pull request diffs.',
184
+ trigger: 'pull_request',
185
+ },
186
+ {
187
+ key: 'windsurf-cascade-review',
188
+ label: 'Windsurf Cascade Review',
189
+ filename: 'windsurf-cascade-review.yml',
190
+ description: 'Validates Cascade configuration on pull requests.',
191
+ trigger: 'pull_request',
192
+ },
193
+ {
194
+ key: 'windsurf-scheduled-audit',
195
+ label: 'Windsurf Scheduled Audit',
196
+ filename: 'windsurf-scheduled-audit.yml',
197
+ description: 'Weekly Windsurf audit of configuration health.',
198
+ trigger: 'schedule (cron)',
199
+ },
200
+ {
201
+ key: 'windsurf-rules-lint',
202
+ label: 'Windsurf Rules Lint',
203
+ filename: 'windsurf-rules-lint.yml',
204
+ description: 'Validates YAML frontmatter in .windsurf/rules/ on change.',
205
+ trigger: 'push (path filter)',
206
+ },
207
+ {
208
+ key: 'windsurf-mcp-security',
209
+ label: 'Windsurf MCP Security Check',
210
+ filename: 'windsurf-mcp-security.yml',
211
+ description: 'Checks MCP config for hardcoded secrets.',
212
+ trigger: 'push (path filter)',
213
+ },
214
+ ];
215
+
216
+ const TEMPLATE_CONTENT = {
217
+ 'windsurf-pr-audit': `# Windsurf PR Audit — generated by nerviq
218
+ name: Windsurf PR Audit
219
+
220
+ on:
221
+ pull_request:
222
+ types: [opened, synchronize]
223
+
224
+ permissions:
225
+ contents: read
226
+ pull-requests: write
227
+
228
+ jobs:
229
+ windsurf-audit:
230
+ runs-on: ubuntu-latest
231
+ timeout-minutes: 15
232
+ steps:
233
+ - uses: actions/checkout@v4
234
+ - name: Run nerviq Windsurf audit
235
+ run: npx nerviq --platform windsurf --json > audit-report.json
236
+ - uses: actions/upload-artifact@v4
237
+ with:
238
+ name: windsurf-audit-report
239
+ path: audit-report.json
240
+ retention-days: 30
241
+ `,
242
+
243
+ 'windsurf-cascade-review': `# Windsurf Cascade Review — generated by nerviq
244
+ name: Windsurf Cascade Review
245
+
246
+ on:
247
+ pull_request:
248
+ types: [opened, synchronize]
249
+
250
+ permissions:
251
+ contents: read
252
+
253
+ jobs:
254
+ cascade-check:
255
+ runs-on: ubuntu-latest
256
+ steps:
257
+ - uses: actions/checkout@v4
258
+ - name: Verify Windsurf Configuration
259
+ run: |
260
+ echo "Checking Windsurf configuration..."
261
+ if [ -f .windsurfrules ]; then
262
+ echo "WARNING: .windsurfrules is legacy format. Migrate to .windsurf/rules/*.md"
263
+ fi
264
+ for file in .windsurf/rules/*.md; do
265
+ [ ! -f "$file" ] && continue
266
+ CHARS=$(wc -c < "$file")
267
+ if [ "$CHARS" -gt 10000 ]; then
268
+ echo "ERROR: $file exceeds 10K char limit ($CHARS chars)"
269
+ exit 1
270
+ fi
271
+ done
272
+ echo "Windsurf configuration check passed."
273
+ `,
274
+
275
+ 'windsurf-scheduled-audit': `# Windsurf Scheduled Audit — generated by nerviq
276
+ name: Windsurf Scheduled Audit
277
+
278
+ on:
279
+ schedule:
280
+ - cron: '0 9 * * 1'
281
+ workflow_dispatch:
282
+
283
+ permissions:
284
+ contents: read
285
+ issues: write
286
+
287
+ jobs:
288
+ audit:
289
+ runs-on: ubuntu-latest
290
+ timeout-minutes: 30
291
+ steps:
292
+ - uses: actions/checkout@v4
293
+ - name: Run nerviq audit
294
+ run: npx nerviq --platform windsurf --json > audit-report.json
295
+ - uses: actions/upload-artifact@v4
296
+ with:
297
+ name: windsurf-audit-report
298
+ path: audit-report.json
299
+ retention-days: 30
300
+ `,
301
+
302
+ 'windsurf-rules-lint': `# Windsurf Rules Lint — generated by nerviq
303
+ name: Windsurf Rules Lint
304
+
305
+ on:
306
+ push:
307
+ paths:
308
+ - '.windsurf/rules/**'
309
+ - '.windsurfrules'
310
+
311
+ permissions:
312
+ contents: read
313
+
314
+ jobs:
315
+ lint-rules:
316
+ runs-on: ubuntu-latest
317
+ steps:
318
+ - uses: actions/checkout@v4
319
+ - name: Check YAML frontmatter and char limits
320
+ run: |
321
+ ERRORS=0
322
+ for file in .windsurf/rules/*.md; do
323
+ [ ! -f "$file" ] && continue
324
+ if ! head -1 "$file" | grep -q "^---"; then
325
+ echo "ERROR: $file missing YAML frontmatter (---)"
326
+ ERRORS=$((ERRORS + 1))
327
+ fi
328
+ CHARS=$(wc -c < "$file")
329
+ if [ "$CHARS" -gt 10000 ]; then
330
+ echo "ERROR: $file exceeds 10K char limit ($CHARS chars)"
331
+ ERRORS=$((ERRORS + 1))
332
+ fi
333
+ done
334
+ if [ -f .windsurfrules ]; then
335
+ echo "WARNING: .windsurfrules exists — this is the legacy format!"
336
+ echo "Migrate to .windsurf/rules/*.md with proper YAML frontmatter."
337
+ fi
338
+ exit $ERRORS
339
+ `,
340
+
341
+ 'windsurf-mcp-security': `# Windsurf MCP Security Check — generated by nerviq
342
+ name: Windsurf MCP Security Check
343
+
344
+ on:
345
+ push:
346
+ paths:
347
+ - '.windsurf/mcp.json'
348
+
349
+ permissions:
350
+ contents: read
351
+
352
+ jobs:
353
+ mcp-check:
354
+ runs-on: ubuntu-latest
355
+ steps:
356
+ - uses: actions/checkout@v4
357
+ - name: Check for hardcoded secrets
358
+ run: |
359
+ if [ ! -f .windsurf/mcp.json ]; then exit 0; fi
360
+ if grep -P '"(key|token|secret|password|api)"\\s*:\\s*"(?!\\$\\{env:)' .windsurf/mcp.json; then
361
+ echo "ERROR: Hardcoded secrets detected in .windsurf/mcp.json"
362
+ echo "Use environment variables instead."
363
+ exit 1
364
+ fi
365
+ echo "MCP config security check passed."
366
+ `,
367
+ };
368
+
369
+ function getCiTemplate(templateKey) {
370
+ const meta = CI_TEMPLATES.find(t => t.key === templateKey);
371
+ if (!meta) return null;
372
+ return TEMPLATE_CONTENT[templateKey] || null;
373
+ }
374
+
375
+ // ---------------------------------------------------------------------------
376
+ // 3. Adoption Signal Gate (5 gates)
377
+ // ---------------------------------------------------------------------------
378
+
379
+ const GATE_THRESHOLDS = {
380
+ 'ci-templates': {
381
+ metric: 'auditCount',
382
+ threshold: 3,
383
+ description: 'Activate CI templates after 3+ successful audits.',
384
+ },
385
+ 'team-sync': {
386
+ metric: 'auditCount',
387
+ threshold: 2,
388
+ description: 'Activate team sync features after 2+ audits.',
389
+ },
390
+ 'multi-pack': {
391
+ metric: 'auditCount',
392
+ threshold: 2,
393
+ description: 'Activate multi-pack composition after 2+ audits.',
394
+ },
395
+ 'workflows': {
396
+ metric: 'auditCount',
397
+ threshold: 3,
398
+ description: 'Activate workflow templates after 3+ audits.',
399
+ },
400
+ 'governance-upgrade': {
401
+ metric: 'averageScore',
402
+ threshold: 70,
403
+ description: 'Suggest governance upgrade when average score exceeds 70.',
404
+ },
405
+ };
406
+
407
+ function getWindsurfHistory(dir, limit = 20) {
408
+ const fs = require('fs');
409
+ const snapshotDir = resolveProjectStateReadPath(dir, 'snapshots');
410
+ try {
411
+ const files = fs.readdirSync(snapshotDir)
412
+ .filter(f => f.endsWith('.json'))
413
+ .sort()
414
+ .slice(-limit);
415
+
416
+ return files.map(f => {
417
+ try {
418
+ const data = JSON.parse(fs.readFileSync(path.join(snapshotDir, f), 'utf8'));
419
+ if (data.platform === 'windsurf' || data.summary?.platform === 'windsurf') return data;
420
+ return null;
421
+ } catch { return null; }
422
+ }).filter(Boolean);
423
+ } catch {
424
+ return [];
425
+ }
426
+ }
427
+
428
+ function checkAdoptionGate(gateKey, dir) {
429
+ const gate = GATE_THRESHOLDS[gateKey];
430
+ if (!gate) {
431
+ return { activated: false, current: 0, threshold: 0, gate: gateKey, description: `Unknown gate "${gateKey}".` };
432
+ }
433
+
434
+ const history = getWindsurfHistory(dir, 100);
435
+ let current = 0;
436
+
437
+ switch (gate.metric) {
438
+ case 'auditCount':
439
+ current = history.length;
440
+ break;
441
+ case 'averageScore': {
442
+ const scores = history.map(e => e.summary?.score).filter(s => typeof s === 'number');
443
+ current = scores.length > 0 ? Math.round(scores.reduce((a, b) => a + b, 0) / scores.length) : 0;
444
+ break;
445
+ }
446
+ default:
447
+ current = 0;
448
+ }
449
+
450
+ return {
451
+ activated: current >= gate.threshold,
452
+ current,
453
+ threshold: gate.threshold,
454
+ gate: gateKey,
455
+ description: gate.description,
456
+ };
457
+ }
458
+
459
+ module.exports = {
460
+ composePacks,
461
+ getCiTemplate,
462
+ CI_TEMPLATES,
463
+ checkAdoptionGate,
464
+ GATE_THRESHOLDS,
465
+ PACK_DEPENDENCY_ORDER,
466
+ PACK_SPECIFICITY,
467
+ DEFAULT_SIZE_BUDGET,
468
+ };