@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,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
+ };