@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,386 +1,386 @@
1
- 'use strict';
2
-
3
- function unique(values) {
4
- return [...new Set((values || []).filter(Boolean))];
5
- }
6
-
7
- function hasAny(set, values) {
8
- return values.some((value) => set.has(value));
9
- }
10
-
11
- function humanizeMaturity(maturity) {
12
- const labels = {
13
- none: 'No governed baseline yet',
14
- starter: 'Starter baseline',
15
- developing: 'Developing baseline',
16
- mature: 'Mature governed baseline',
17
- };
18
- return labels[maturity] || maturity;
19
- }
20
-
21
- function detectTopology(ctx, pkg) {
22
- const signals = [];
23
- const hasPackageWorkspaces = Array.isArray(pkg.workspaces) ||
24
- Boolean(pkg.workspaces && Array.isArray(pkg.workspaces.packages));
25
-
26
- if (hasPackageWorkspaces) signals.push('package.json workspaces');
27
- if (ctx.fileContent('pnpm-workspace.yaml')) signals.push('pnpm-workspace.yaml');
28
- if (ctx.fileContent('nx.json')) signals.push('nx.json');
29
- if (ctx.fileContent('turbo.json')) signals.push('turbo.json');
30
- if (ctx.fileContent('lerna.json')) signals.push('lerna.json');
31
- if (ctx.hasDir('packages')) signals.push('packages/');
32
- if (ctx.hasDir('apps')) signals.push('apps/');
33
-
34
- if (signals.length > 0) {
35
- return {
36
- key: 'monorepo',
37
- label: 'Monorepo',
38
- rationale: 'Workspace or multi-package signals indicate a shared-root repo topology.',
39
- signals,
40
- };
41
- }
42
-
43
- const multiSurfaceSignals = [];
44
- if (ctx.hasDir('app')) multiSurfaceSignals.push('app/');
45
- if (ctx.hasDir('api')) multiSurfaceSignals.push('api/');
46
- if (ctx.hasDir('services')) multiSurfaceSignals.push('services/');
47
- if (ctx.hasDir('workers')) multiSurfaceSignals.push('workers/');
48
-
49
- if (multiSurfaceSignals.length >= 2) {
50
- return {
51
- key: 'multi-surface',
52
- label: 'Multi-surface repo',
53
- rationale: 'Several product/service surfaces live in one repository even without formal workspace tooling.',
54
- signals: multiSurfaceSignals,
55
- };
56
- }
57
-
58
- return {
59
- key: 'single-repo',
60
- label: 'Single-repo',
61
- rationale: 'No workspace or multi-package signals detected.',
62
- signals: [],
63
- };
64
- }
65
-
66
- function detectStackFamily(stackKeys, domainKeys, ctx) {
67
- if (hasAny(stackKeys, ['flutter', 'swift', 'kotlin']) || domainKeys.has('mobile')) {
68
- return { key: 'mobile', label: 'Mobile', rationale: 'Native or mobile-platform stacks dominate the repo.' };
69
- }
70
- if (domainKeys.has('infra-platform') || domainKeys.has('devops-cicd') || hasAny(stackKeys, ['terraform', 'kubernetes', 'docker'])) {
71
- return { key: 'infra', label: 'Infrastructure / platform', rationale: 'Deployment, infrastructure, or CI surfaces are central.' };
72
- }
73
- if (domainKeys.has('ai-ml') || domainKeys.has('data-pipeline') || ctx.hasDir('experiments') || ctx.hasDir('notebooks')) {
74
- return { key: 'data-ml', label: 'Data / AI / ML', rationale: 'Pipeline, experiment, or model workflow signals are present.' };
75
- }
76
- const hasFrontend = hasAny(stackKeys, ['react', 'nextjs', 'vue', 'angular', 'svelte']) || ctx.hasDir('components');
77
- const hasBackend = hasAny(stackKeys, ['node', 'python', 'django', 'fastapi', 'go', 'rust', 'java', 'ruby', 'php', 'dotnet']) || ctx.hasDir('api') || ctx.hasDir('services');
78
- if (hasFrontend && hasBackend) {
79
- return { key: 'fullstack', label: 'Full-stack application', rationale: 'Both UI and service-layer signals are present.' };
80
- }
81
- if (hasFrontend) {
82
- return { key: 'frontend', label: 'Frontend application', rationale: 'UI and component signals dominate the repo.' };
83
- }
84
- if (hasBackend) {
85
- return { key: 'backend', label: 'Backend service', rationale: 'Service, API, or backend stack signals dominate the repo.' };
86
- }
87
- if (domainKeys.has('docs-content')) {
88
- return { key: 'docs', label: 'Docs / content', rationale: 'Documentation and content workflow signals dominate the repo.' };
89
- }
90
- return { key: 'general', label: 'General codebase', rationale: 'No strong stack family dominates yet.' };
91
- }
92
-
93
- function detectRepoClass({ ctx, pkg, domainKeys, stackKeys, topology }) {
94
- const signals = [];
95
- const hasFrontend = hasAny(stackKeys, ['react', 'nextjs', 'vue', 'angular', 'svelte']) || ctx.hasDir('components') || ctx.hasDir('pages');
96
- const hasBackend = hasAny(stackKeys, ['node', 'python', 'django', 'fastapi', 'go', 'rust', 'java', 'ruby', 'php', 'dotnet']) || ctx.hasDir('api') || ctx.hasDir('services') || ctx.hasDir('routes');
97
- const isInfra = domainKeys.has('infra-platform') || domainKeys.has('devops-cicd') || hasAny(stackKeys, ['terraform', 'kubernetes', 'docker']) || ctx.hasDir('infra') || ctx.hasDir('deploy') || ctx.hasDir('helm');
98
- const isMl = domainKeys.has('ai-ml') || domainKeys.has('data-pipeline') || ctx.hasDir('experiments') || ctx.hasDir('datasets') || ctx.hasDir('notebooks');
99
- const isMobile = hasAny(stackKeys, ['flutter', 'swift', 'kotlin']) || domainKeys.has('mobile') || ctx.hasDir('ios') || ctx.hasDir('android');
100
- const isLibrary = domainKeys.has('oss-library') || ((!hasFrontend && !hasBackend) && Boolean(pkg.main || pkg.module || pkg.exports || pkg.types));
101
- const isCli = domainKeys.has('cli-tool') || Boolean(pkg.bin) || ctx.hasDir('bin');
102
-
103
- if (topology.key === 'monorepo' && isInfra) {
104
- signals.push('workspace topology', 'infra / deploy signals');
105
- return {
106
- key: 'platform-monorepo',
107
- label: 'Platform monorepo',
108
- rationale: 'Shared-root workspace plus infrastructure signals indicate a platform-style repo.',
109
- signals,
110
- };
111
- }
112
-
113
- if (topology.key === 'monorepo' && (hasFrontend || hasBackend)) {
114
- signals.push('workspace topology', hasFrontend ? 'frontend signals' : null, hasBackend ? 'backend signals' : null);
115
- return {
116
- key: 'application-monorepo',
117
- label: 'Application monorepo',
118
- rationale: 'Multiple app/service surfaces share one governed root.',
119
- signals: unique(signals),
120
- };
121
- }
122
-
123
- if (isInfra) {
124
- signals.push('infra / deploy signals');
125
- return {
126
- key: 'infra-platform',
127
- label: 'Infrastructure / platform repo',
128
- rationale: 'Infrastructure or release-engineering surfaces define the repo.',
129
- signals,
130
- };
131
- }
132
-
133
- if (isMobile) {
134
- signals.push('mobile stack signals');
135
- return {
136
- key: 'mobile-app',
137
- label: 'Mobile application',
138
- rationale: 'Mobile-native directories or stacks define the repo.',
139
- signals,
140
- };
141
- }
142
-
143
- if (isMl) {
144
- signals.push('data / ML workflow signals');
145
- return {
146
- key: 'data-ml-system',
147
- label: 'Data / AI system',
148
- rationale: 'Pipelines, experiments, or model workflows are central.',
149
- signals,
150
- };
151
- }
152
-
153
- if (isCli) {
154
- signals.push('CLI distribution surface');
155
- return {
156
- key: 'developer-tool',
157
- label: 'Developer tool',
158
- rationale: 'Command-line packaging or tool UX is part of the product contract.',
159
- signals,
160
- };
161
- }
162
-
163
- if (isLibrary) {
164
- signals.push('package export surface');
165
- return {
166
- key: 'library-sdk',
167
- label: 'Library / SDK',
168
- rationale: 'The repo behaves like a reusable package rather than a deployed application.',
169
- signals,
170
- };
171
- }
172
-
173
- if (hasFrontend && hasBackend) {
174
- signals.push('frontend signals', 'backend signals');
175
- return {
176
- key: 'fullstack-product',
177
- label: 'Full-stack product',
178
- rationale: 'UI and service layers coexist as one application surface.',
179
- signals,
180
- };
181
- }
182
-
183
- if (hasFrontend) {
184
- signals.push('frontend signals');
185
- return {
186
- key: 'frontend-product',
187
- label: 'Frontend product',
188
- rationale: 'UI and component workflows dominate the repo.',
189
- signals,
190
- };
191
- }
192
-
193
- if (hasBackend) {
194
- signals.push('backend signals');
195
- return {
196
- key: 'backend-service',
197
- label: 'Backend service',
198
- rationale: 'API or service workflows dominate the repo.',
199
- signals,
200
- };
201
- }
202
-
203
- return {
204
- key: 'general-codebase',
205
- label: 'General codebase',
206
- rationale: 'No stronger repo class dominates yet.',
207
- signals: [],
208
- };
209
- }
210
-
211
- function detectWorkflowTraits({ ctx, platform, assets, maturity, topology, domainKeys, recommendedMcpPacks = [] }) {
212
- const traits = [];
213
- const hasCi = ctx.hasDir('.github/workflows') || ctx.hasDir('.circleci') || Boolean(ctx.fileContent('.gitlab-ci.yml')) || Boolean(ctx.fileContent('Jenkinsfile'));
214
- const hasMcp = (assets && assets.counts && assets.counts.mcpServers > 0) || (recommendedMcpPacks || []).length > 0;
215
- const hasGovernanceSignals = domainKeys.has('enterprise-governed') || domainKeys.has('regulated-lite') || domainKeys.has('security-focused');
216
-
217
- if (hasGovernanceSignals && hasCi) {
218
- traits.push({
219
- key: 'governed-rollout',
220
- label: 'Governed rollout',
221
- rationale: 'CI plus governance/regulatory signals suggest reviewable rollout discipline.',
222
- signals: unique([
223
- domainKeys.has('enterprise-governed') ? 'enterprise-governed pack' : null,
224
- domainKeys.has('regulated-lite') ? 'regulated-lite pack' : null,
225
- domainKeys.has('security-focused') ? 'security-focused pack' : null,
226
- hasCi ? 'CI workflows' : null,
227
- ]),
228
- });
229
- }
230
-
231
- if (topology.key === 'monorepo') {
232
- traits.push({
233
- key: 'workspace-coordinated',
234
- label: 'Workspace-coordinated',
235
- rationale: 'The repo needs path-aware and package-aware workflow coordination.',
236
- signals: ['workspace topology'],
237
- });
238
- }
239
-
240
- if (hasCi) {
241
- traits.push({
242
- key: 'ci-driven',
243
- label: 'CI-driven',
244
- rationale: 'Automated CI surfaces are part of the normal engineering loop.',
245
- signals: ['CI workflows'],
246
- });
247
- }
248
-
249
- if (hasMcp) {
250
- traits.push({
251
- key: 'tool-enriched',
252
- label: 'Tool-enriched',
253
- rationale: 'Live MCP or external-context tooling is part of the intended workflow.',
254
- signals: unique([
255
- assets && assets.counts && assets.counts.mcpServers > 0 ? 'declared MCP servers' : null,
256
- recommendedMcpPacks.length > 0 ? 'recommended MCP packs' : null,
257
- ]),
258
- });
259
- }
260
-
261
- if (maturity === 'mature' || maturity === 'developing') {
262
- traits.push({
263
- key: 'managed',
264
- label: 'Managed baseline',
265
- rationale: 'The repo already has enough governance assets that Nerviq should extend, not replace, the current baseline.',
266
- signals: [humanizeMaturity(maturity)],
267
- });
268
- }
269
-
270
- if (traits.length === 0) {
271
- traits.push({
272
- key: 'bootstrap-local',
273
- label: 'Bootstrap local workflow',
274
- rationale: 'The repo still looks early-stage and should start from a simple local baseline.',
275
- signals: [humanizeMaturity(maturity)],
276
- });
277
- }
278
-
279
- return traits;
280
- }
281
-
282
- function detectRiskProfile({ ctx, platform, assets, domainKeys, maturity }) {
283
- const reasons = [];
284
-
285
- if (domainKeys.has('regulated-lite')) reasons.push('regulated-lite pack');
286
- if (domainKeys.has('security-focused')) reasons.push('security-focused pack');
287
- if (ctx.files.includes('SECURITY.md')) reasons.push('SECURITY.md');
288
- if (ctx.files.includes('COMPLIANCE.md') || ctx.hasDir('compliance') || ctx.hasDir('policies')) reasons.push('compliance surface');
289
-
290
- if (platform === 'codex' && assets && assets.trust) {
291
- if (assets.trust.approvalPolicy === 'never') reasons.push('approval_policy=never');
292
- if (assets.trust.sandboxMode === 'danger-full-access') reasons.push('sandbox_mode=danger-full-access');
293
- }
294
-
295
- if (platform !== 'codex' && assets && assets.permissions) {
296
- if (assets.permissions.defaultMode === 'bypassPermissions') reasons.push('bypassPermissions');
297
- if (!assets.permissions.hasDenyRules) reasons.push('missing deny rules');
298
- }
299
-
300
- if (domainKeys.has('enterprise-governed')) reasons.push('enterprise-governed pack');
301
-
302
- let key = 'standard';
303
- let label = 'Standard';
304
- let level = 'medium';
305
- let rationale = 'No strong regulatory or unusually permissive-risk posture dominates the repo.';
306
-
307
- if (reasons.some((reason) => /regulated|compliance|SECURITY|security-focused/i.test(reason))) {
308
- key = 'regulated';
309
- label = 'Regulated / security-sensitive';
310
- level = 'high';
311
- rationale = 'Compliance or security-sensitive signals mean recommendations should skew toward traceability and review.';
312
- } else if (reasons.some((reason) => /bypassPermissions|danger-full-access|approval_policy=never/i.test(reason))) {
313
- key = 'elevated';
314
- label = 'Elevated operational risk';
315
- level = 'high';
316
- rationale = 'The repo is configured with permissive runtime posture that increases blast radius.';
317
- } else if (maturity === 'none' || maturity === 'starter') {
318
- key = 'bootstrap';
319
- label = 'Bootstrap risk';
320
- level = 'medium';
321
- rationale = 'The main risk is missing baseline governance, not over-permissive automation.';
322
- }
323
-
324
- return {
325
- key,
326
- label,
327
- level,
328
- rationale,
329
- reasons: unique(reasons),
330
- };
331
- }
332
-
333
- function buildRepoArchetypeProfile(options) {
334
- const {
335
- ctx,
336
- platform,
337
- stacks = [],
338
- assets,
339
- recommendedDomainPacks = [],
340
- recommendedMcpPacks = [],
341
- maturity = 'none',
342
- } = options || {};
343
-
344
- const pkg = ctx && typeof ctx.jsonFile === 'function' ? (ctx.jsonFile('package.json') || {}) : {};
345
- const stackKeys = new Set((stacks || []).map((stack) => stack.key));
346
- const domainKeys = new Set((recommendedDomainPacks || []).map((pack) => pack.key));
347
-
348
- const topology = detectTopology(ctx, pkg);
349
- const stackFamily = detectStackFamily(stackKeys, domainKeys, ctx);
350
- const repoClass = detectRepoClass({ ctx, pkg, domainKeys, stackKeys, topology });
351
- const workflowTraits = detectWorkflowTraits({ ctx, platform, assets, maturity, topology, domainKeys, recommendedMcpPacks });
352
- const primaryWorkflow = workflowTraits[0];
353
- const riskProfile = detectRiskProfile({ ctx, platform, assets, domainKeys, maturity });
354
- const signals = unique([
355
- stackFamily.label,
356
- ...topology.signals,
357
- ...repoClass.signals,
358
- ...workflowTraits.flatMap((trait) => trait.signals || []),
359
- ...riskProfile.reasons,
360
- ...recommendedDomainPacks.slice(0, 3).map((pack) => pack.key),
361
- ]);
362
-
363
- const confidence = signals.length >= 6 ? 'high' : signals.length >= 3 ? 'medium' : 'low';
364
-
365
- return {
366
- key: `${topology.key}:${repoClass.key}`,
367
- label: repoClass.label,
368
- summary: `${repoClass.label} with ${topology.label.toLowerCase()} topology, ${primaryWorkflow.label.toLowerCase()} workflow, and ${riskProfile.label.toLowerCase()} posture.`,
369
- confidence,
370
- stackFamily,
371
- topology,
372
- maturity: {
373
- key: maturity,
374
- label: humanizeMaturity(maturity),
375
- },
376
- repoClass,
377
- primaryWorkflow,
378
- workflowTraits,
379
- riskProfile,
380
- signals: signals.slice(0, 8),
381
- };
382
- }
383
-
384
- module.exports = {
385
- buildRepoArchetypeProfile,
386
- };
1
+ 'use strict';
2
+
3
+ function unique(values) {
4
+ return [...new Set((values || []).filter(Boolean))];
5
+ }
6
+
7
+ function hasAny(set, values) {
8
+ return values.some((value) => set.has(value));
9
+ }
10
+
11
+ function humanizeMaturity(maturity) {
12
+ const labels = {
13
+ none: 'No governed baseline yet',
14
+ starter: 'Starter baseline',
15
+ developing: 'Developing baseline',
16
+ mature: 'Mature governed baseline',
17
+ };
18
+ return labels[maturity] || maturity;
19
+ }
20
+
21
+ function detectTopology(ctx, pkg) {
22
+ const signals = [];
23
+ const hasPackageWorkspaces = Array.isArray(pkg.workspaces) ||
24
+ Boolean(pkg.workspaces && Array.isArray(pkg.workspaces.packages));
25
+
26
+ if (hasPackageWorkspaces) signals.push('package.json workspaces');
27
+ if (ctx.fileContent('pnpm-workspace.yaml')) signals.push('pnpm-workspace.yaml');
28
+ if (ctx.fileContent('nx.json')) signals.push('nx.json');
29
+ if (ctx.fileContent('turbo.json')) signals.push('turbo.json');
30
+ if (ctx.fileContent('lerna.json')) signals.push('lerna.json');
31
+ if (ctx.hasDir('packages')) signals.push('packages/');
32
+ if (ctx.hasDir('apps')) signals.push('apps/');
33
+
34
+ if (signals.length > 0) {
35
+ return {
36
+ key: 'monorepo',
37
+ label: 'Monorepo',
38
+ rationale: 'Workspace or multi-package signals indicate a shared-root repo topology.',
39
+ signals,
40
+ };
41
+ }
42
+
43
+ const multiSurfaceSignals = [];
44
+ if (ctx.hasDir('app')) multiSurfaceSignals.push('app/');
45
+ if (ctx.hasDir('api')) multiSurfaceSignals.push('api/');
46
+ if (ctx.hasDir('services')) multiSurfaceSignals.push('services/');
47
+ if (ctx.hasDir('workers')) multiSurfaceSignals.push('workers/');
48
+
49
+ if (multiSurfaceSignals.length >= 2) {
50
+ return {
51
+ key: 'multi-surface',
52
+ label: 'Multi-surface repo',
53
+ rationale: 'Several product/service surfaces live in one repository even without formal workspace tooling.',
54
+ signals: multiSurfaceSignals,
55
+ };
56
+ }
57
+
58
+ return {
59
+ key: 'single-repo',
60
+ label: 'Single-repo',
61
+ rationale: 'No workspace or multi-package signals detected.',
62
+ signals: [],
63
+ };
64
+ }
65
+
66
+ function detectStackFamily(stackKeys, domainKeys, ctx) {
67
+ if (hasAny(stackKeys, ['flutter', 'swift', 'kotlin']) || domainKeys.has('mobile')) {
68
+ return { key: 'mobile', label: 'Mobile', rationale: 'Native or mobile-platform stacks dominate the repo.' };
69
+ }
70
+ if (domainKeys.has('infra-platform') || domainKeys.has('devops-cicd') || hasAny(stackKeys, ['terraform', 'kubernetes', 'docker'])) {
71
+ return { key: 'infra', label: 'Infrastructure / platform', rationale: 'Deployment, infrastructure, or CI surfaces are central.' };
72
+ }
73
+ if (domainKeys.has('ai-ml') || domainKeys.has('data-pipeline') || ctx.hasDir('experiments') || ctx.hasDir('notebooks')) {
74
+ return { key: 'data-ml', label: 'Data / AI / ML', rationale: 'Pipeline, experiment, or model workflow signals are present.' };
75
+ }
76
+ const hasFrontend = hasAny(stackKeys, ['react', 'nextjs', 'vue', 'angular', 'svelte']) || ctx.hasDir('components');
77
+ const hasBackend = hasAny(stackKeys, ['node', 'python', 'django', 'fastapi', 'go', 'rust', 'java', 'ruby', 'php', 'dotnet']) || ctx.hasDir('api') || ctx.hasDir('services');
78
+ if (hasFrontend && hasBackend) {
79
+ return { key: 'fullstack', label: 'Full-stack application', rationale: 'Both UI and service-layer signals are present.' };
80
+ }
81
+ if (hasFrontend) {
82
+ return { key: 'frontend', label: 'Frontend application', rationale: 'UI and component signals dominate the repo.' };
83
+ }
84
+ if (hasBackend) {
85
+ return { key: 'backend', label: 'Backend service', rationale: 'Service, API, or backend stack signals dominate the repo.' };
86
+ }
87
+ if (domainKeys.has('docs-content')) {
88
+ return { key: 'docs', label: 'Docs / content', rationale: 'Documentation and content workflow signals dominate the repo.' };
89
+ }
90
+ return { key: 'general', label: 'General codebase', rationale: 'No strong stack family dominates yet.' };
91
+ }
92
+
93
+ function detectRepoClass({ ctx, pkg, domainKeys, stackKeys, topology }) {
94
+ const signals = [];
95
+ const hasFrontend = hasAny(stackKeys, ['react', 'nextjs', 'vue', 'angular', 'svelte']) || ctx.hasDir('components') || ctx.hasDir('pages');
96
+ const hasBackend = hasAny(stackKeys, ['node', 'python', 'django', 'fastapi', 'go', 'rust', 'java', 'ruby', 'php', 'dotnet']) || ctx.hasDir('api') || ctx.hasDir('services') || ctx.hasDir('routes');
97
+ const isInfra = domainKeys.has('infra-platform') || domainKeys.has('devops-cicd') || hasAny(stackKeys, ['terraform', 'kubernetes', 'docker']) || ctx.hasDir('infra') || ctx.hasDir('deploy') || ctx.hasDir('helm');
98
+ const isMl = domainKeys.has('ai-ml') || domainKeys.has('data-pipeline') || ctx.hasDir('experiments') || ctx.hasDir('datasets') || ctx.hasDir('notebooks');
99
+ const isMobile = hasAny(stackKeys, ['flutter', 'swift', 'kotlin']) || domainKeys.has('mobile') || ctx.hasDir('ios') || ctx.hasDir('android');
100
+ const isLibrary = domainKeys.has('oss-library') || ((!hasFrontend && !hasBackend) && Boolean(pkg.main || pkg.module || pkg.exports || pkg.types));
101
+ const isCli = domainKeys.has('cli-tool') || Boolean(pkg.bin) || ctx.hasDir('bin');
102
+
103
+ if (topology.key === 'monorepo' && isInfra) {
104
+ signals.push('workspace topology', 'infra / deploy signals');
105
+ return {
106
+ key: 'platform-monorepo',
107
+ label: 'Platform monorepo',
108
+ rationale: 'Shared-root workspace plus infrastructure signals indicate a platform-style repo.',
109
+ signals,
110
+ };
111
+ }
112
+
113
+ if (topology.key === 'monorepo' && (hasFrontend || hasBackend)) {
114
+ signals.push('workspace topology', hasFrontend ? 'frontend signals' : null, hasBackend ? 'backend signals' : null);
115
+ return {
116
+ key: 'application-monorepo',
117
+ label: 'Application monorepo',
118
+ rationale: 'Multiple app/service surfaces share one governed root.',
119
+ signals: unique(signals),
120
+ };
121
+ }
122
+
123
+ if (isInfra) {
124
+ signals.push('infra / deploy signals');
125
+ return {
126
+ key: 'infra-platform',
127
+ label: 'Infrastructure / platform repo',
128
+ rationale: 'Infrastructure or release-engineering surfaces define the repo.',
129
+ signals,
130
+ };
131
+ }
132
+
133
+ if (isMobile) {
134
+ signals.push('mobile stack signals');
135
+ return {
136
+ key: 'mobile-app',
137
+ label: 'Mobile application',
138
+ rationale: 'Mobile-native directories or stacks define the repo.',
139
+ signals,
140
+ };
141
+ }
142
+
143
+ if (isMl) {
144
+ signals.push('data / ML workflow signals');
145
+ return {
146
+ key: 'data-ml-system',
147
+ label: 'Data / AI system',
148
+ rationale: 'Pipelines, experiments, or model workflows are central.',
149
+ signals,
150
+ };
151
+ }
152
+
153
+ if (isCli) {
154
+ signals.push('CLI distribution surface');
155
+ return {
156
+ key: 'developer-tool',
157
+ label: 'Developer tool',
158
+ rationale: 'Command-line packaging or tool UX is part of the product contract.',
159
+ signals,
160
+ };
161
+ }
162
+
163
+ if (isLibrary) {
164
+ signals.push('package export surface');
165
+ return {
166
+ key: 'library-sdk',
167
+ label: 'Library / SDK',
168
+ rationale: 'The repo behaves like a reusable package rather than a deployed application.',
169
+ signals,
170
+ };
171
+ }
172
+
173
+ if (hasFrontend && hasBackend) {
174
+ signals.push('frontend signals', 'backend signals');
175
+ return {
176
+ key: 'fullstack-product',
177
+ label: 'Full-stack product',
178
+ rationale: 'UI and service layers coexist as one application surface.',
179
+ signals,
180
+ };
181
+ }
182
+
183
+ if (hasFrontend) {
184
+ signals.push('frontend signals');
185
+ return {
186
+ key: 'frontend-product',
187
+ label: 'Frontend product',
188
+ rationale: 'UI and component workflows dominate the repo.',
189
+ signals,
190
+ };
191
+ }
192
+
193
+ if (hasBackend) {
194
+ signals.push('backend signals');
195
+ return {
196
+ key: 'backend-service',
197
+ label: 'Backend service',
198
+ rationale: 'API or service workflows dominate the repo.',
199
+ signals,
200
+ };
201
+ }
202
+
203
+ return {
204
+ key: 'general-codebase',
205
+ label: 'General codebase',
206
+ rationale: 'No stronger repo class dominates yet.',
207
+ signals: [],
208
+ };
209
+ }
210
+
211
+ function detectWorkflowTraits({ ctx, platform, assets, maturity, topology, domainKeys, recommendedMcpPacks = [] }) {
212
+ const traits = [];
213
+ const hasCi = ctx.hasDir('.github/workflows') || ctx.hasDir('.circleci') || Boolean(ctx.fileContent('.gitlab-ci.yml')) || Boolean(ctx.fileContent('Jenkinsfile'));
214
+ const hasMcp = (assets && assets.counts && assets.counts.mcpServers > 0) || (recommendedMcpPacks || []).length > 0;
215
+ const hasGovernanceSignals = domainKeys.has('enterprise-governed') || domainKeys.has('regulated-lite') || domainKeys.has('security-focused');
216
+
217
+ if (hasGovernanceSignals && hasCi) {
218
+ traits.push({
219
+ key: 'governed-rollout',
220
+ label: 'Governed rollout',
221
+ rationale: 'CI plus governance/regulatory signals suggest reviewable rollout discipline.',
222
+ signals: unique([
223
+ domainKeys.has('enterprise-governed') ? 'enterprise-governed pack' : null,
224
+ domainKeys.has('regulated-lite') ? 'regulated-lite pack' : null,
225
+ domainKeys.has('security-focused') ? 'security-focused pack' : null,
226
+ hasCi ? 'CI workflows' : null,
227
+ ]),
228
+ });
229
+ }
230
+
231
+ if (topology.key === 'monorepo') {
232
+ traits.push({
233
+ key: 'workspace-coordinated',
234
+ label: 'Workspace-coordinated',
235
+ rationale: 'The repo needs path-aware and package-aware workflow coordination.',
236
+ signals: ['workspace topology'],
237
+ });
238
+ }
239
+
240
+ if (hasCi) {
241
+ traits.push({
242
+ key: 'ci-driven',
243
+ label: 'CI-driven',
244
+ rationale: 'Automated CI surfaces are part of the normal engineering loop.',
245
+ signals: ['CI workflows'],
246
+ });
247
+ }
248
+
249
+ if (hasMcp) {
250
+ traits.push({
251
+ key: 'tool-enriched',
252
+ label: 'Tool-enriched',
253
+ rationale: 'Live MCP or external-context tooling is part of the intended workflow.',
254
+ signals: unique([
255
+ assets && assets.counts && assets.counts.mcpServers > 0 ? 'declared MCP servers' : null,
256
+ recommendedMcpPacks.length > 0 ? 'recommended MCP packs' : null,
257
+ ]),
258
+ });
259
+ }
260
+
261
+ if (maturity === 'mature' || maturity === 'developing') {
262
+ traits.push({
263
+ key: 'managed',
264
+ label: 'Managed baseline',
265
+ rationale: 'The repo already has enough governance assets that Nerviq should extend, not replace, the current baseline.',
266
+ signals: [humanizeMaturity(maturity)],
267
+ });
268
+ }
269
+
270
+ if (traits.length === 0) {
271
+ traits.push({
272
+ key: 'bootstrap-local',
273
+ label: 'Bootstrap local workflow',
274
+ rationale: 'The repo still looks early-stage and should start from a simple local baseline.',
275
+ signals: [humanizeMaturity(maturity)],
276
+ });
277
+ }
278
+
279
+ return traits;
280
+ }
281
+
282
+ function detectRiskProfile({ ctx, platform, assets, domainKeys, maturity }) {
283
+ const reasons = [];
284
+
285
+ if (domainKeys.has('regulated-lite')) reasons.push('regulated-lite pack');
286
+ if (domainKeys.has('security-focused')) reasons.push('security-focused pack');
287
+ if (ctx.files.includes('SECURITY.md')) reasons.push('SECURITY.md');
288
+ if (ctx.files.includes('COMPLIANCE.md') || ctx.hasDir('compliance') || ctx.hasDir('policies')) reasons.push('compliance surface');
289
+
290
+ if (platform === 'codex' && assets && assets.trust) {
291
+ if (assets.trust.approvalPolicy === 'never') reasons.push('approval_policy=never');
292
+ if (assets.trust.sandboxMode === 'danger-full-access') reasons.push('sandbox_mode=danger-full-access');
293
+ }
294
+
295
+ if (platform !== 'codex' && assets && assets.permissions) {
296
+ if (assets.permissions.defaultMode === 'bypassPermissions') reasons.push('bypassPermissions');
297
+ if (!assets.permissions.hasDenyRules) reasons.push('missing deny rules');
298
+ }
299
+
300
+ if (domainKeys.has('enterprise-governed')) reasons.push('enterprise-governed pack');
301
+
302
+ let key = 'standard';
303
+ let label = 'Standard';
304
+ let level = 'medium';
305
+ let rationale = 'No strong regulatory or unusually permissive-risk posture dominates the repo.';
306
+
307
+ if (reasons.some((reason) => /regulated|compliance|SECURITY|security-focused/i.test(reason))) {
308
+ key = 'regulated';
309
+ label = 'Regulated / security-sensitive';
310
+ level = 'high';
311
+ rationale = 'Compliance or security-sensitive signals mean recommendations should skew toward traceability and review.';
312
+ } else if (reasons.some((reason) => /bypassPermissions|danger-full-access|approval_policy=never/i.test(reason))) {
313
+ key = 'elevated';
314
+ label = 'Elevated operational risk';
315
+ level = 'high';
316
+ rationale = 'The repo is configured with permissive runtime posture that increases blast radius.';
317
+ } else if (maturity === 'none' || maturity === 'starter') {
318
+ key = 'bootstrap';
319
+ label = 'Bootstrap risk';
320
+ level = 'medium';
321
+ rationale = 'The main risk is missing baseline governance, not over-permissive automation.';
322
+ }
323
+
324
+ return {
325
+ key,
326
+ label,
327
+ level,
328
+ rationale,
329
+ reasons: unique(reasons),
330
+ };
331
+ }
332
+
333
+ function buildRepoArchetypeProfile(options) {
334
+ const {
335
+ ctx,
336
+ platform,
337
+ stacks = [],
338
+ assets,
339
+ recommendedDomainPacks = [],
340
+ recommendedMcpPacks = [],
341
+ maturity = 'none',
342
+ } = options || {};
343
+
344
+ const pkg = ctx && typeof ctx.jsonFile === 'function' ? (ctx.jsonFile('package.json') || {}) : {};
345
+ const stackKeys = new Set((stacks || []).map((stack) => stack.key));
346
+ const domainKeys = new Set((recommendedDomainPacks || []).map((pack) => pack.key));
347
+
348
+ const topology = detectTopology(ctx, pkg);
349
+ const stackFamily = detectStackFamily(stackKeys, domainKeys, ctx);
350
+ const repoClass = detectRepoClass({ ctx, pkg, domainKeys, stackKeys, topology });
351
+ const workflowTraits = detectWorkflowTraits({ ctx, platform, assets, maturity, topology, domainKeys, recommendedMcpPacks });
352
+ const primaryWorkflow = workflowTraits[0];
353
+ const riskProfile = detectRiskProfile({ ctx, platform, assets, domainKeys, maturity });
354
+ const signals = unique([
355
+ stackFamily.label,
356
+ ...topology.signals,
357
+ ...repoClass.signals,
358
+ ...workflowTraits.flatMap((trait) => trait.signals || []),
359
+ ...riskProfile.reasons,
360
+ ...recommendedDomainPacks.slice(0, 3).map((pack) => pack.key),
361
+ ]);
362
+
363
+ const confidence = signals.length >= 6 ? 'high' : signals.length >= 3 ? 'medium' : 'low';
364
+
365
+ return {
366
+ key: `${topology.key}:${repoClass.key}`,
367
+ label: repoClass.label,
368
+ summary: `${repoClass.label} with ${topology.label.toLowerCase()} topology, ${primaryWorkflow.label.toLowerCase()} workflow, and ${riskProfile.label.toLowerCase()} posture.`,
369
+ confidence,
370
+ stackFamily,
371
+ topology,
372
+ maturity: {
373
+ key: maturity,
374
+ label: humanizeMaturity(maturity),
375
+ },
376
+ repoClass,
377
+ primaryWorkflow,
378
+ workflowTraits,
379
+ riskProfile,
380
+ signals: signals.slice(0, 8),
381
+ };
382
+ }
383
+
384
+ module.exports = {
385
+ buildRepoArchetypeProfile,
386
+ };